Skip to navigation


Start and end: Entry

Name: Entry [Show more] Type: Subroutine Category: Start and end Summary: The main entry point for the game
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.Entry MOV R0, #22 \ Change to screen mode 15, which uses 160K SWI OS_WriteC \ of screen memory, the same amount that we MOV R0, #15 \ need for the game (though in the game we SWI OS_WriteC \ actually use two mode 13 screens, each of \ which is 80K) STR R13, stackPointerOnEntry \ Store the stack pointer from when the game \ started in stackPointerOnEntry, so we can \ retore it when we quit the game LDR R13, stackAddr \ Set the stack pointer in R13 to stackAddr, \ so the 512 bytes descending from stackAddr \ can be used as the game's stack LDR R11, workspaceAddr \ Set R11 to the address of the workspace, \ which is stored in workspaceAddr, so we \ can access workspace variables by applying \ an offset to R11 using [R11, #offset] STMFD R13!, {R14} \ R14 contains the address we should return \ to when quitting the game, so store it on \ the stack so we can retrieve it later LDR R0, memoryTestAddr \ Set R0 to the address in memoryTestAddr, \ which points to a byte that will be \ writable if there is enough free memory \ for running the game LDRB R1, [R0] \ Set R1 to the current contents of memory \ at R0, so we can restore it after running \ our memory tests MOV R2, #&AA \ Store the value &AA in our test memory STRB R2, [R0] \ location in R0, read it back, and if the LDRB R3, [R0] \ returned value is different to &AA, jump CMP R2, R3 \ to AbortWithMemoryError to abort the game, BNE AbortWithMemoryError \ as there isn't enough free memory MOV R2, #&55 \ Store the value &55 in our test memory STRB R2, [R0] \ location in R0, read it back, and if the LDRB R3, [R0] \ returned value is different to &55, jump CMP R2, R3 \ to AbortWithMemoryError to abort the game, BNE AbortWithMemoryError \ as there isn't enough free memory STRB R1, [R0] \ Restore the original contents of address \ R0 so it's unchanged by our memory tests MOV R0, #4 \ Call OS_Byte 4 to set the cursor keys to MOV R1, #1 \ return ASCII values, so they don't move MOV R2, #0 \ the cursor during the game SWI OS_Byte BL InitialiseParticleData \ Initialise the particle data buffer and \ associated variables MOV R0, #22 \ Change to screen mode 13 (320×256 pixels SWI OS_WriteC \ with 256 colours), which will display MOV R0, #13 \ screen bank 1 SWI OS_WriteC SWI OS_WriteS \ Write the game's title into the top line EQUS "Lander Demo/Practice " \ of the screen, where it remains for the EQUS "(C) D.J.Braben 1987" \ whole game EQUB 0 ALIGN BL SwitchScreenBank \ Switch screen bank, so VDU commands go to \ screen bank 2 MOV R0, #22 \ Change to screen mode 13 with shadow SWI OS_WriteC \ memory enabled (i.e. mode 128 + 13), which MOV R0, #128+13 \ creates two mode 13 screen banks SWI OS_WriteC \ MOV R0, #23 \ Start printing the following VDU command: SWI OS_WriteC \ MOV R0, #1 \ VDU 23, 1, 0, 0, 0, 0, 0, 0, 0, 0 SWI OS_WriteC \ \ which disables the cursor MOV R8, #8 \ We now want to print the eight zeroes in \ the above command, so set a loop counter \ in R8 .entr1 MOV R0, #0 \ This loop prints the eight zeroes in the SWI OS_WriteC \ above VDU command SUBS R8, R8, #1 \ Decrement the loop counter BNE entr1 \ Loop back until we have printed all eight \ zeroes SWI OS_WriteS \ Write the game's title into the top line EQUS "Lander Demo/Practice " \ of screen bank 2, so the same title EQUS "(C) D.J.Braben 1987" \ appears at the top of both screen banks EQUB 0 ALIGN LDR R0, initialScore \ Initialise currentScore to the score that STR R0, [R11, #currentScore] \ we start each game with, which is set in \ initialScore LDR R0, initialHighScore \ Initialise highScore to the high score STR R0, [R11, #highScore] \ that we start the game with, which is set \ in initialHighScore