.TT24 LDA QQ15+1 \ Fetch s0_hi and extract bits 0-2 to determine the AND #%00000111 \ system's economy, and store in QQ3 STA QQ3 LDA QQ15+2 \ Fetch s1_lo and extract bits 3-5 to determine the LSR A \ system's government, and store in QQ4 LSR A LSR A AND #%00000111 STA QQ4 LSR A \ If government isn't anarchy or feudal, skip to TT77, BNE TT77 \ as we need to fix the economy of anarchy and feudal \ systems so they can't be rich LDA QQ3 \ Set bit 1 of the economy in QQ3 to fix the economy ORA #%00000010 \ for anarchy and feudal governments STA QQ3 .TT77 LDA QQ3 \ Now to work out the tech level, which we do like this: EOR #%00000111 \ CLC \ flipped_economy + (s1_hi AND %11) + (government / 2) STA QQ5 \ \ or, in terms of memory locations: \ \ QQ5 = (QQ3 EOR %111) + (QQ15+3 AND %11) + (QQ4 / 2) \ \ We start by setting QQ5 = QQ3 EOR %111 LDA QQ15+3 \ We then take the first 2 bits of s1_hi (QQ15+3) and AND #%00000011 \ add it into QQ5 ADC QQ5 STA QQ5 LDA QQ4 \ And finally we add QQ4 / 2 and store the result in LSR A \ QQ5, using LSR then ADC to divide by 2, which rounds ADC QQ5 \ up the result for odd-numbered government types STA QQ5 ASL A \ Now to work out the population, like so: ASL A \ ADC QQ3 \ (tech level * 4) + economy + government + 1 ADC QQ4 \ ADC #1 \ or, in terms of memory locations: STA QQ6 \ \ QQ6 = (QQ5 * 4) + QQ3 + QQ4 + 1 LDA QQ3 \ Finally, we work out productivity, like this: EOR #%00000111 \ ADC #3 \ (flipped_economy + 3) * (government + 4) STA P \ * population LDA QQ4 \ * 8 ADC #4 \ STA Q \ or, in terms of memory locations: JSR MULTU \ \ QQ7 = (QQ3 EOR %111 + 3) * (QQ4 + 4) * QQ6 * 8 \ \ We do the first step by setting P to the first \ expression in brackets and Q to the second, and \ calling MULTU, so now (A P) = P * Q. The highest this \ can be is 10 * 11 (as the maximum values of economy \ and government are 7), so the high byte of the result \ will always be 0, so we actually have: \ \ P = P * Q \ = (flipped_economy + 3) * (government + 4) LDA QQ6 \ We now take the result in P and multiply by the STA Q \ population to get the productivity, by setting Q to JSR MULTU \ the population from QQ6 and calling MULTU again, so \ now we have: \ \ (A P) = P * population ASL P \ Next we multiply the result by 8, as a 16-bit number, ROL A \ so we shift both bytes to the left three times, using ASL P \ the C flag to carry bits from bit 7 of the low byte ROL A \ into bit 0 of the high byte ASL P ROL A STA QQ7+1 \ Finally, we store the productivity in two bytes, with LDA P \ the low byte in QQ7 and the high byte in QQ7+1 STA QQ7 RTS \ Return from the subroutineName: TT24 [Show more] Type: Subroutine Category: Universe Summary: Calculate system data from the system seeds Deep dive: Generating system data Galaxy and system seedsContext: See this subroutine in context in the source code References: This subroutine is called as follows: * TT111 calls TT24
Calculate system data from the seeds in QQ15 and store them in the relevant locations. Specifically, this routine calculates the following from the three 16-bit seeds in QQ15 (using only s0_hi, s1_hi and s1_lo): QQ3 = economy (0-7) QQ4 = government (0-7) QQ5 = technology level (0-14) QQ6 = population * 10 (1-71) QQ7 = productivity (96-62480) The ranges of the various values are shown in brackets. Note that the radius and type of inhabitant are calculated on-the-fly in the TT25 routine when the system data gets displayed, so they aren't calculated here.
Calculate (A P) = P * Q
Label TT77 is local to this routine