Skip to navigation


Main loop: MainLoop

Name: MainLoop [Show more] Type: Subroutine Category: Main loop Summary: The main game loop Deep dive: The main game loop
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.MainLoop MOV R0, #129 \ Call OS_Byte 129 to read the keyboard with MOV R1, #0 \ the time limit in R1 and R2 (so that's MOV R2, #0 \ with no time limit as R1 and R2 are zero), SWI OS_Byte \ returning the result in R2 TEQ R2, #&1B \ If R2 = &1B then an escape condition BEQ EndGame \ occurred during the keyboard scan (in \ other words, Escape was pressed), so jump \ to EndGame to acknowledge the escape \ condition and quit the game BL MoveAndDrawPlayer \ Move the player's ship and draw it into \ the graphics buffers \ We now set up the rotation matrix for the \ rocks, using the main loop counter to \ generate rotation angles that change along \ with the main loop (so the rocks spin at a \ nice steady speed) LDR R0, [R11, #mainLoopCount] \ Set R0 = mainLoopCount << 24 MOV R0, R0, LSL #24 MOV R1, R0, LSL #1 \ Set R1 = mainLoopCount << 25 BL CalculateRotationMatrix \ Calculate the rotation matrix from the \ "angles" given in R0 and R1, which we can \ apply to any rocks we draw in the \ MoveAndDrawParticles routine (as rocks are \ only rotating 3D objects apart from the \ player, and the player calculates its own \ rotation matrix) BL DropRocksFromTheSky \ If the score is 800 or more, then randomly \ drop rocks from the sky BL MoveAndDrawParticles \ Move and draw all the particles, such as \ smoke clouds and bullets, into the \ graphics buffers BL DrawObjects \ Draw all the objects, such as trees and \ buildings, into the graphics buffers BL AddTerminatorsToBuffers \ Add terminators to the ends of the \ graphics buffers so we know when to stop \ drawing BL DrawLandscapeAndBuffers \ Draw the landscape and the contents of the \ graphics buffers BL PrintCurrentScore \ Print the number of remaining bullets at \ the left end of the score bar BL DrawFuelLevel \ Draw the fuel bar BL SwitchScreenBank \ Switch screen banks and clear the newly \ hidden screen bank to black LDR R14, [R11, #mainLoopCount] \ Increment the main loop counter ADD R14, R14, #1 STR R14, [R11, #mainLoopCount] B MainLoop \ Loop back to repeat the main loop