Skip to navigation

Landscape: InitialiseSeeds

Name: InitialiseSeeds [Show more] Type: Subroutine Category: Landscape Summary: Initialise the seed number generator so it generates the sequence of seed numbers for a specific landscape number
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * FinishLandscape calls InitialiseSeeds * MainGameLoop calls InitialiseSeeds * MainTitleLoop calls InitialiseSeeds

Arguments: (Y X) A landscape number in BCD (0000 to 9999)
.InitialiseSeeds STY seedNumberLFSR+1 \ Initialise the seed number generator by setting bits STX seedNumberLFSR \ 0-15 of the five-byte linear feedback shift register \ to the landscape number \ \ This ensures that the GetNextSeedNumber routine (and \ related routines) will generate a unique sequence of \ pseudo-random numbers for this landscape, and which \ will be the exact same sequence every time we need to \ generate this landscape \ \ It also ensures that the third number to be generated \ by the shift register is the high byte of the \ landscape number that we put into seedNumberLFSR+1, as \ at this early stage of the process the EOR feedback \ does not affect this byte as it passes through the \ shift register, so after three 8-bit shifts the high \ byte reaches seedNumberLFSR+4 and is returned as the \ next seed number \ \ This fact is exploited by the anti-cracker code in the \ SetCrackerSeed routine STY landscapeNumberHi \ Set landscapeNumber(Hi Lo) = (Y X) STX landscapeNumberLo STY landscapeZero \ If the high byte of the landscape number is non-zero, TYA \ then set landscapeZero to this non-zero value (to BNE seed1 \ indicate that we are not playing landscape 0000) and \ jump to seed1 to set maxNumberOfEnemies to 8 TXA \ Set landscapeZero to the low byte of the landscape, STA landscapeZero \ so this sets landscapeZero to zero if we are playing \ landscape 0000, and it sets it to a non-zero value if \ we are not \ \ So landscapeZero is now correctly set to indicate \ whether or not we are playing landscape 0000 LSR A \ Set A to the high byte of the BCD landscape number LSR A \ plus 1, which is the same as saying: LSR A \ LSR A \ A = 1 + (landscapeNumber div 10) CLC \ ADC #1 \ Or A is 1 plus the "tens" digit of the landscape \ number CMP #9 \ If A < 9 then A is in the range 1 to 8, so jump to BCC seed2 \ seed2 to set maxNumberOfEnemies to this value \ Otherwise A is 9 or higher, so we now cap A to 8 as \ the maximum allowed value for maxNumberOfEnemies .seed1 LDA #8 \ Set A = 8 to use as the maximum number of enemies .seed2 STA maxNumberOfEnemies \ Set maxNumberOfEnemies to the value in A, so we get \ the following cap on the number of enemies: \ \ min(8, 1 + (landscapeNumber div 10)) \ \ So landscapes 0000 to 0009 have a maximum enemy count \ of 1, landscapes 0010 to 0019 have a maximum enemy \ count of 2, and so on up to landscapes 0070 and up, \ which have a maximum enemy count of 8 RTS \ Return from the subroutine