.MainGameLoop \ If we get here then we have either started a brand new \ game or we jumped here from part 2 when one of the \ following occurred: \ \ * The Sentinel has won \ \ * The player has moved to a new tile \ \ * The player has performed a U-turn \ \ * The player has pressed the quit game key JSR FlushSoundBuffers \ Flush all four sound channel buffers LDA quitGame \ If bit 7 of quitGame is clear then the player has not BPL game1 \ pressed function key f1 to quit the game, so jump to \ game 1 to keep playing the game JMP MainTitleLoop \ The player has pressed function key f1 to quit the \ game, so jump to MainTitleLoop to restart the game .game1 \ If we get here then we have either started a brand new \ landscape or we jumped to MainGameLoop from part 2 \ when one of the following occurred: \ \ * The Sentinel has won \ \ * The player has moved to a new tile \ \ * The player has performed a U-turn LDA sentinelHasWon \ If bit 7 of sentinelHasWon is set then the player has BMI game6 \ run out of energy either by trying to hyperspace or by \ being absorbed, so jump to game6 to restart the \ landscape \ If we get here then we have either started a brand new \ landscape or we jumped to MainGameLoop from part 2 \ when the player moved to a new tile or performed a \ U-turn \ \ In both cases we need to generate a brand new \ landscape view LDA #4 \ Set all four logical colours to physical colour 4 JSR SetColourPalette \ (blue), so this blanks the entire screen to blue LDA #0 \ Set screenOrBuffer = 0 to configure the drawing STA screenOrBuffer \ routines to draw directly onto the screen (as opposed \ to drawing into the screen buffer) STA lastPanKeyPressed \ Zero lastPanKeyPressed so that when we draw the whole \ landscape view onto the screen below, we draw it in \ character columns, working from left to right, in the \ same order as we would for a pan to the right (which \ is what a zero value of lastPanKeyPressed usually \ represents) STA sightsByteCount \ Set sightsByteCount to zero to reset the sights pixel \ byte stash STA sightsAreVisible \ Clear bit 7 of sightsAreVisible to indicate that the \ sights are not visible JSR SetScannerAndPause \ Set scannerUpdate to zero to prevent scanner updates \ \ This routine also performs a delay of 40 empty loops \ of 256 iterations each (i.e. 10,240 loops) LDA playerObject \ Set viewingObject to the object number of the player, STA viewingObject \ so the landscape view gets drawn from the perspective \ of the player BIT hyperspaceEndsGame \ If bit 7 of hyperspaceEndsGame is clear then the game BPL game2 \ has not ended because of a hyperspace, so jump to \ game2 to draw the landscape \ If we get here then the game has ended because the \ player performed a hyperspace BVS FinishLandscape \ If bit 6 of hyperspaceEndsGame is set then the game \ has ended because the player has hyperspaced from the \ Sentinel's tower, thus winning the game, so jump to \ FinishLandscape to process winning the landscape \ If we get here then bit 6 of hyperspaceEndsGame is \ clear and the player has run out of energy by trying \ to hyperspace without being able to create a robot \ into which they can hyperspace JSR ClearScreen \ Clear the screen JMP game4 \ Jump to game4 to skip drawing the landscape view, as \ the game has ended .game2 LDA uTurnStatus \ If bit 7 of uTurnStatus is set then we just performed BMI game3 \ a U-turn in the ProcessActionKeys routine, so jump to \ game3 to skip the following instruction, as we don't \ need to recalculate tile visibility if we are turning \ around (as the player hasn't moved) JSR GetTileVisibility \ For each tile in the landscape, calculate whether the \ player can see that tile, to speed up the process of \ drawing the landscape .game3 JSR ClearScreen \ Clear the screen JSR DrawLandscapeView \ Draw the landscape view JSR UpdateIconsScanner \ Update the icons in the top-left corner of the screen \ to show the player's current energy level and redraw \ the scanner box .game4 LDA #25 \ Set screenOrBuffer = 25 to configure the drawing STA screenOrBuffer \ routines to draw into the screen buffer (as opposed \ to drawing directly onto the screen) LDA #2 \ Call ConfigureBuffer with A = 2 to set up the screen JSR ConfigureBuffer \ buffer for use as a column buffer .game5 JSR ProcessSound \ Process any sounds or music that are being made in the \ background LDA musicCounter \ Loop back to keep calling ProcessSound until bit 7 of BPL game5 \ musicCounter is clear, so if any music is being \ played, we wait until it has finished LDA #&83 \ Set the palette to the first set of colours from the JSR SetColourPalette \ colourPalettes table, which the SpawnEnemies routine \ set to the correct palette for playing the game (so \ for landscape 0000 that would be blue, black, white \ and green, for example) LDA hyperspaceEndsGame \ Set A to the hyperspace status flag BPL game7 \ If bit 7 of hyperspaceEndsGame is clear then the game \ has not ended because of a hyperspace, so jump to \ part 2 to move on to the main game loop itself \ If we get here then the game has ended because of a \ hyperspace, and it must be because the player ran out \ of energy, as otherwise we would have taken the branch \ to part 2 above STA sentinelHasWon \ Set bit 7 of sentinelHasWon to indicate that the \ player has run out of energy and the Sentinel has won LDA #6 \ Set soundEffect = 6 so the sound is processed as the STA soundEffect \ game over sound LDA #5 \ The Sentinel has won, so display the game over screen JSR ShowGameOverScreen \ with A = 5, so we decay the screen to black with a \ mass of 5 * 2400 = 12,000 randomly placed black dots .game6 \ If we get here then we restart the landscape by \ resetting all the game variables, initialising the \ the seed number generator and jumping into the main \ title loop to preview the landscape and play the game JSR ResetVariables \ Reset all the game's main variables LDY landscapeNumberHi \ Set (Y X) = landscapeNumber(Hi Lo) LDX landscapeNumberLo 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 JMP main4 \ Jump to main4 in the main title loop to restart the \ landscape without having to enter the landscape's \ secret code againName: MainGameLoop (Part 1 of 2) [Show more] Type: Subroutine Category: Main game loop Summary: The main game loop for playing a landscape Deep dive: Program flow of the main game loopContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainGameLoop (Part 2 of 2) calls MainGameLoop
[X]
Subroutine ClearScreen (category: Graphics)
Clear the screen to a specified background
[X]
Subroutine ConfigureBuffer (category: Screen buffer)
Set up the variables required to configure the screen buffer to a specific buffer type
[X]
Subroutine DrawLandscapeView (Part 1 of 3) (category: Drawing the landscape)
Set up a number of variables for drawing the landscape view
[X]
Subroutine FinishLandscape (category: Main title loop)
Process the successful completion of a landscape by displaying the secret code for the next landscape and jumping to the title screen
[X]
Subroutine FlushSoundBuffers (category: Sound)
Flush all four sound channel buffers
[X]
Subroutine GetTileVisibility (category: Drawing the landscape)
For each tile in the landscape, calculate whether the player can see that tile, to speed up the process of drawing 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 MainTitleLoop (category: Main title loop)
The main title loop: display the title screen, fetch the landscape number/code, preview the landscape and jump to the main game loop
[X]
Subroutine ProcessSound (category: Sound)
Process any sound effects that have been configured so they play in the background (this is called regularly throughout gameplay)
[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 SetScannerAndPause (category: Main game loop)
Set the scanner update status and delay for 40 empty loops of 256 iterations each (i.e. 10,240 loops)
[X]
Subroutine ShowGameOverScreen (category: Title screen)
Display the game over screen
[X]
Subroutine UpdateIconsScanner (category: Scanner/energy row)
Update the icons in the top-left corner of the screen to show the player's current energy level and redraw the scanner box
[X]
Label game1 is local to this routine
[X]
Label game2 is local to this routine
[X]
Label game3 is local to this routine
[X]
Label game4 is local to this routine
[X]
Label game5 is local to this routine
[X]
Label game6 is local to this routine
[X]
Label game7 in subroutine MainGameLoop (Part 2 of 2)
[X]
Variable hyperspaceEndsGame in workspace Main variable workspace
Records whether the player performing a hyperspace has just ended the game
[X]
Variable landscapeNumberHi in workspace Main variable workspace
The high byte of the four-digit binary coded decimal landscape number (0000 to 9999)
[X]
Variable landscapeNumberLo in workspace Main variable workspace
The low byte of the four-digit binary coded decimal landscape number (0000 to 9999)
[X]
Variable lastPanKeyPressed in workspace Zero page
The direction of the last pan key that was pressed (which may not still be held down)
[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 musicCounter in workspace Main variable workspace
A counter for the music currently being made, which counts up in the ProcessMusic routine while the music is being played
[X]
Variable playerObject in workspace Zero page
The number of the player object
[X]
Variable quitGame in workspace Main variable workspace
A flag to record whether the player has pressed function key f1 to quit the game
[X]
Variable screenOrBuffer in workspace Zero page
Controls whether the graphics routines draw directly onto the screen, or into the screen buffer
[X]
Variable sentinelHasWon in workspace Main variable workspace
A flag to record when the player runs out of energy (i.e. the energy level goes negative), at which point the Sentinel wins
[X]
Variable sightsAreVisible in workspace Main variable workspace
Controls whether the sights are being shown
[X]
Variable sightsByteCount in workspace Main variable workspace
The number of screen bytes in the sights pixel byte stash that contain the contents of the screen behind the sights (so they can be restored to remove the sights)
[X]
Variable soundEffect in workspace Main variable workspace
Determines how the current sound is processed by the ProcessSound routine
[X]
Variable uTurnStatus in workspace Main variable workspace
A flag to record whether we are performing or have just performed a U-turn
[X]
Variable viewingObject in workspace Zero page
The number of the viewing object