Skip to navigation


Version analysis of Main game loop (Part 6 of 6)

This code appears in the following versions (click to see it in the source code):

Code variations between these versions are shown below.

Name: Main game loop (Part 6 of 6) Type: Subroutine Category: Main loop

Code variation 1 of 6A variation in the comments only

Tap on a block to expand it, and tap it again to revert.

Summary: Process non-flight key presses (red function keys, docked keys)
Summary: Process non-flight key presses (FUNC keys, docked keys)
Deep dive: Program flow of the main game loop
This is the second half of the minimal game loop, which we iterate when we are docked. This section covers the following:

Code variation 2 of 6A variation in the comments only

Tap on a block to expand it, and tap it again to revert.

* Process more key presses (red function keys, docked keys etc.)
* Process more key presses (FUNC keys, docked keys etc.)
It also supports joining the main loop with a key already "pressed", so we can jump into the main game loop to perform a specific action. In practice, this

Code variation 3 of 6A variation in the comments only

Tap on a block to expand it, and tap it again to revert.

is used when we enter the docking bay in BAY to display Status Mode (red key f8), and when we finish buying or selling cargo in BAY2 to jump to the Inventory (red key f9).
is used when we enter the docking bay in BAY to display Status Mode (FUNC-9), and when we finish buying or selling cargo in BAY2 to jump to the Inventory (FUNC-0).

Other entry points: FRCE The entry point for the main game loop if we want to jump straight to a specific screen, by pretending to "press" a key, in which case A contains the internal key number of the key we want to "press"

Code variation 4 of 6A variation in the comments only

This variation is blank in the Disc (flight), Disc (docked), 6502 Second Processor, Master and Electron versions.

tha Consider spawning a Thargoid (22% chance)
.FRCE JSR TT102 \ Call TT102 to process the key pressed in A

Code variation 5 of 6Minor and very low-impact

This variation is blank in the Disc (flight) version.

Tap on a block to expand it, and tap it again to revert.

LDA QQ12 \ Fetch the docked flag from QQ12 into A BNE MLOOP \ If we are docked, loop back up to MLOOP just above \ to restart the main loop, but skipping all the flight \ and spawning code in the top part of the main loop
LDA QQ12 \ Fetch the docked flag from QQ12 into A BEQ P%+5 \ If we are docked, loop back up to MLOOP just above JMP MLOOP \ to restart the main loop, but skipping all the flight \ and spawning code in the top part of the main loop
 JMP TT100              \ Otherwise jump to TT100 to restart the main loop from
                        \ the start

Code variation 6 of 6Specific to an individual platform

This variation is blank in the Disc (flight), Disc (docked), 6502 Second Processor, Master and Electron versions.

.tha JSR DORND \ Set A and X to random numbers CMP #200 \ If A < 200 (78% chance), skip the next instruction BCC P%+5 JSR GTHG \ Call GTHG to spawn a Thargoid ship and a Thargon \ companion JMP MLOOP \ Jump back into the main loop at MLOOP, which is just \ after the ship-spawning section