.MainTitleLoop LDX #&FF \ Set the stack pointer to &01FF, which is the standard TXS \ location for the 6502 stack, so this instruction \ effectively resets the stack \ \ This means that the JSR GenerateLandscape instruction \ below will put its return address onto the top of the \ stack, so we can manipulate the return address by \ modifying (&01FE &01FF) \ \ See the notes on the JSR GenerateLandscape instruction \ below for more details LDA #4 \ Set all four logical colours to physical colour 4 JSR SetColourPalette \ (blue), so this blanks the entire screen to blue JSR ResetVariables \ Reset all the game's main variables LDA #0 \ Call DrawTitleScreen with A = 0 to draw the title JSR DrawTitleScreen \ screen LDX #0 \ Print text token 0: Background colour blue, print JSR PrintTextToken \ "PRESS ANY KEY" at (64, 100), set text background to \ black LDA #&87 \ Set the palette to the second set of colours from the JSR SetColourPalette \ colourPalettes table, which contains the fixed palette \ for the title screens (blue, black, red, yellow) JSR ReadKeyboard \ Enable the keyboard, flush the keyboard buffer and \ read a character from it (so this waits for a key \ press) .main1 JSR ResetVariables \ Reset all the game's main variables LDX #1 \ Print text token 1: Print 13 spaces at (64, 100), JSR PrintTextToken \ print "LANDSCAPE NUMBER?" at (64, 768), switch to text \ cursor, move text cursor to (5, 27) LDA #4 \ Read a four-digit number from the keyboard into the JSR ReadNumber \ input buffer, showing the key presses on-screen and \ supporting the DELETE and RETURN keys JSR StringToNumber \ Convert the string of four ASCII digits in the input \ buffer into a BCD number in inputBuffer(1 0) LDY inputBuffer+1 \ Set (Y X) = inputBuffer(1 0) LDX inputBuffer \ \ So (Y X) is the entered landscape number in BCD JSR InitialiseSeeds \ Initialise the seed number generator to generate the \ sequence of seed numbers for the landscape number in \ (Y X) and set maxNumberOfEnemies and the landscapeZero \ flag accordingly LDA landscapeZero \ If the landscape number is not 0000, jump to main3 BNE main3 \ to ask for the landscape's secret entry code \ This is landscape 0000, so we don't ask for a secret \ entry code, but instead we copy the landscape's secret \ code from secretCode0000 into the input buffer, so \ it's as if the player has typed in the code themselves LDX #3 \ We are copying four bytes of secret code into the \ input buffer, so set a byte index in X .main2 LDA secretCode0000,X \ Copy the X-th byte of secretCode0000 to the X-th byte STA inputBuffer,X \ of the input buffer DEX \ Decrement the byte index BPL main2 \ Loop back until we have copied all four bytes BMI main4 \ Jump to main4 to skip asking the player to enter the \ code (this BMI is effectively a JMP as we just passed \ through a BPL) .main3 LDX #2 \ Print text token 2: Background colour blue, print JSR PrintTextToken \ "SECRET ENTRY CODE?" at (64, 768), switch to text \ cursor, move text cursor to (2, 27) LDA #8 \ Read an eight-digit number from the keyboard into the JSR ReadNumber \ input buffer, showing the key presses on-screen and \ supporting the DELETE and RETURN keys JSR StringToNumber \ Convert the string of eight ASCII digits in the input \ buffer into a BCD number in inputBuffer(3 2 1 0) .main4 \ The player has now chosen a landscape number and has \ entered the secret code (or, in the case of landscape \ 0000, we have entered the secret code for them) \ \ We also jump here if we are restarting a landscape \ after dying, so the player doesn't have to enter the \ landscape's secret code again LDA #4 \ Set all four logical colours to physical colour 4 JSR SetColourPalette \ (blue), so this blanks the entire screen to blue JSR GenerateLandscape \ Call GenerateLandscape to generate the landscape and \ play the game \ \ Calling this subroutine puts a return address of \ SecretCodeError on the stack (as that's the routine \ that follows directly after this JSR instruction), so \ running a normal RTS instruction at the end of the \ GenerateLandscape routine will return to the following \ code, which is what happens if the secret code entered \ doesn't match the landscape's secret code \ \ However, if the secret code does match the landscape, \ then the SmoothTileData routine that is called from \ GenerateLandscape alters the return address on the \ stack, so instead of returning here, the RTS at the \ end of the GenerateLandscape routine actually takes us \ to the PreviewLandscape routine \ \ Because we reset the position of the stack pointer \ with a TSX instruction at the start of this routine, \ we know that the JSR GenerateLandscape instruction \ will put its return address onto the top of the stack, \ so we can manipulate the return address in the \ SmoothTileData routine by modifying (&01FE &01FF) \ \ See the SmoothTileData routine for more detailsName: MainTitleLoop [Show more] Type: Subroutine Category: Main title loop Summary: The main title loop: display the title screen, fetch the landscape number/code, preview the landscape and jump to the main game loopContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ConfigureMachine calls MainTitleLoop * MainGameLoop calls MainTitleLoop * Absolute16Bit calls via MainTitleLoop-1 * SecretCodeError calls via main1 * MainGameLoop calls via main4
Other entry points: MainTitleLoop-1 Contains an RTS main1 The entry point for rejoining the main title loop after the player enters an incorrect secret code main4 The entry point for restarting a landscape after dying, so the player doesn't have to enter the landscape's secret code again
[X]
Subroutine DrawTitleScreen (category: Title screen)
Draw the title screen or the screen showing the secret code
[X]
Subroutine GenerateLandscape (category: Landscape)
Generate tile data for the landscape
[X]
Subroutine InitialiseSeeds (category: Landscape)
Initialise the seed number generator so it generates the sequence of seed numbers for a specific landscape number
[X]
Subroutine PrintTextToken (category: Text)
Print a recursive text token
[X]
Subroutine ReadKeyboard (category: Keyboard)
Enable the keyboard and read a character from it
[X]
Subroutine ReadNumber (category: Keyboard)
Read a number from the keyboard into the input buffer
[X]
Subroutine ResetVariables (category: Main title Loop)
Reset all the game's main variables
[X]
Subroutine SetColourPalette (category: Graphics)
Set the logical colours for each of the four physical colours in screen mode 5
[X]
Subroutine StringToNumber (category: Text)
Convert a string of ASCII digits in the input buffer in-place into a multi-byte BCD number
[X]
Variable inputBuffer in workspace Main variable workspace
The eight-byte keyboard input buffer
[X]
Variable landscapeZero in workspace Main variable workspace
A flag that is set depending on whether we are playing landscape 0000
[X]
Label main2 is local to this routine
[X]
Label main3 is local to this routine
[X]
Entry point main4 in subroutine MainTitleLoop (category: Main title loop)
The entry point for restarting a landscape after dying, so the player doesn't have to enter the landscape's secret code again
[X]
Variable secretCode0000 (category: Landscape)
The secret entry code for landscape 0000 (06045387)