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 1 of 6) Type: Subroutine Category: Main loop
Deep dive: Program flow of the main game loop Ship data blocks
This is part of the main game loop. This is where the core loop of the game lives, and it's in two parts. The shorter loop (just parts 5 and 6) is iterated when we are docked, while the entire loop from part 1 to 6 iterates if we are in space. This section covers the following:
.MTT4
JSR DORND \ Set A and X to random numbers
LSR A \ Clear bit 7 of our random number in A and set the C \ flag to bit 0 of A, which is random STA INWK+32 \ Store this in the ship's AI flag, so this ship does \ not have AI STA INWK+29 \ Store A in the ship's roll counter, giving it a \ clockwise roll (as bit 7 is clear), and a 1 in 127 \ chance of it having no damping ROL INWK+31 \ Set bit 0 of the ship's missile count randomly (as the \ C flag was set), giving the ship either no missiles or \ one missile
Traders in the enhanced versions can spawn in docking mode, in which case they mind their own business.
This variation is blank in the Cassette and Electron versions.
JSR DORND \ Set A and X to random numbers, plus the C flag BMI nodo \ If A is negative (50% chance), jump to nodo to skip \ the following \ If we get here then we are going to spawn a ship that \ is minding its own business and trying to dock LDA INWK+32 \ Set bits 6 and 7 of the ship's AI flag, to make it ORA #%11000000 \ aggressive if attacked, and enable its AI STA INWK+32 LDX #%00010000 \ Set bit 4 of the ship's NEWB flags, to indicate that STX NEWB \ this ship is docking .nodo
Traders in the enhanced versions can be one of the following: Cobra Mk III, Python, Boa or Anaconda (in the cassette version, they are always Cobras).
Tap on a block to expand it, and tap it again to revert.
The advanced versions have rock hermits, which are classed as junk but can release ships if attacked.
This variation is blank in the Cassette, Disc (flight) and Electron versions.
CMP #HER \ If A is now the ship type of a rock hermit, jump to BEQ TT100 \ TT100 to skip the following instruction