Skip to navigation

Elite on the BBC Micro

Version analysis of Main flight loop (Part 3 of 16)

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 flight loop (Part 3 of 16) Type: Subroutine Category: Main loop Summary: Scan for flight keys and process the results Deep dive: Program flow of the main game loop The key logger
The main flight loop covers most of the flight-specific aspects of Elite. This section covers the following: * Scan for flight keys and process the results Flight keys are logged in the key logger at location KY1 onwards, with a non-zero value in the relevant location indicating a key press. See the deep dive on "The key logger" for more details. The key presses that are processed are as follows: * Space and "?" to speed up and slow down * "U", "T" and "M" to disarm, arm and fire missiles

Code variation 1 of 16A variation in the comments only

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

* TAB to fire an energy bomb
* "-" to fire an energy bomb
* ESCAPE to launch an escape pod * "J" to initiate an in-system jump * "E" to deploy E.C.M. anti-missile countermeasures * "C" to use the docking computer * "A" to fire lasers

Code variation 2 of 16A variation in the labels only

This variation is blank in the Cassette and Electron versions.

Flight, 6502SP, Master

.BS2
 LDA KY2                \ If Space is being pressed, keep going, otherwise jump
 BEQ MA17               \ down to MA17 to skip the following

 LDA DELTA              \ The "go faster" key is being pressed, so first we
 CMP #40                \ fetch the current speed from DELTA into A, and if
 BCS MA17               \ A >= 40, we are already going at full pelt, so jump
                        \ down to MA17 to skip the following

 INC DELTA              \ We can go a bit faster, so increment the speed in
                        \ location DELTA

.MA17

 LDA KY1                \ If "?" is being pressed, keep going, otherwise jump
 BEQ MA4                \ down to MA4 to skip the following

 DEC DELTA              \ The "slow down" key is being pressed, so we decrement
                        \ the current ship speed in DELTA

 BNE MA4                \ If the speed is still greater than zero, jump to MA4

 INC DELTA              \ Otherwise we just braked a little too hard, so bump
                        \ the speed back up to the minimum value of 1

.MA4

 LDA KY15               \ If "U" is being pressed and the number of missiles
 AND NOMSL              \ in NOMSL is non-zero, keep going, otherwise jump down
 BEQ MA20               \ to MA20 to skip the following

Code variation 3 of 16Related to the screen mode

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight

6502SP, Master

Electron

LDY #&EE \ The "disarm missiles" key is being pressed, so call JSR ABORT \ ABORT to disarm the missile and update the missile \ indicators on the dashboard to green/cyan (Y = &EE)
LDY #GREEN2 \ The "disarm missiles" key is being pressed, so call JSR ABORT \ ABORT to disarm the missile and update the missile \ indicators on the dashboard to green (Y = &EE)
JSR ABORT-2 \ The "disarm missiles" key is being pressed, so call \ ABORT-2 to disarm the missile and update the missile \ indicators on the dashboard to white squares (Y = &09)

Code variation 4 of 16Related to the Master version

The Master version has a unique "low beep" sound that has more reverb than in the other versions.

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Electron

Master

LDA #40 \ Call the NOISE routine with A = 40 to make a low, JSR NOISE \ long beep to indicate the missile is now disarmed
JSR LOWBEEP \ Call the LOWBEEP routine to make a low, long beep to \ indicate the missile is now disarmed

Code variation 5 of 16A variation in the labels only

This variation is blank in the 6502 Second Processor and Master versions.

Cassette, Flight, Electron

.MA31
 LDA #0                 \ Set MSAR to 0 to indicate that no missiles are
 STA MSAR               \ currently armed

.MA20

 LDA MSTG               \ If MSTG is positive (i.e. it does not have bit 7 set),
 BPL MA25               \ then it indicates we already have a missile locked on
                        \ a target (in which case MSTG contains the ship number
                        \ of the target), so jump to MA25 to skip targeting. Or
                        \ to put it another way, if MSTG = &FF, which means
                        \ there is no current target lock, keep going

 LDA KY14               \ If "T" is being pressed, keep going, otherwise jump
 BEQ MA25               \ down to MA25 to skip the following

 LDX NOMSL              \ If the number of missiles in NOMSL is zero, jump down
 BEQ MA25               \ to MA25 to skip the following

 STA MSAR               \ The "target missile" key is being pressed and we have
                        \ at least one missile, so set MSAR = &FF to denote that
                        \ our missile is currently armed (we know A has the
                        \ value &FF, as we just loaded it from MSTG and checked
                        \ that it was negative)

Code variation 6 of 16Related to the screen mode

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight

6502SP, Master

Electron

LDY #&E0 \ Change the leftmost missile indicator to yellow/white JSR MSBAR \ on the missile bar (this call changes the leftmost \ indicator because we set X to the number of missiles \ in NOMSL above, and the indicators are numbered from \ right to left, so X is the number of the leftmost \ indicator)
LDY #YELLOW2 \ Change the leftmost missile indicator to yellow JSR MSBAR \ on the missile bar (this call changes the leftmost \ indicator because we set X to the number of missiles \ in NOMSL above, and the indicators are numbered from \ right to left, so X is the number of the leftmost \ indicator)
LDY #&0D \ Change the leftmost missile indicator to a black box JSR MSBAR \ in a white square on the missile bar (this call \ changes the leftmost indicator because we set X to the \ number of missiles in NOMSL above, and the indicators \ are numbered from right to left, so X is the number of \ the leftmost indicator)
.MA25

 LDA KY16               \ If "M" is being pressed, keep going, otherwise jump
 BEQ MA24               \ down to MA24 to skip the following

 LDA MSTG               \ If MSTG = &FF then there is no target lock, so jump to
 BMI MA64               \ MA64 to skip the following (also skipping the checks

Code variation 7 of 16A variation in the comments only

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

\ for TAB, ESCAPE, "J" and "E")
\ for "-", ESCAPE, "J" and "E")
 JSR FRMIS              \ The "fire missile" key is being pressed and we have
                        \ a missile lock, so call the FRMIS routine to fire
                        \ the missile

.MA24

Code variation 8 of 16A variation in the comments only

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Master

Electron

LDA KY12 \ If TAB is being pressed, keep going, otherwise jump BEQ MA76 \ jump down to MA76 to skip the following
LDA KY12 \ If "-" is being pressed, keep going, otherwise jump BEQ MA76 \ jump down to MA76 to skip the following

Code variation 9 of 16Specific to an individual platform

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

Master

LDA BOMB \ If we already set off our energy bomb, then BOMB is BMI MA76 \ negative, so this skips to MA76 if our energy bomb is \ already going off
 ASL BOMB               \ The "energy bomb" key is being pressed, so double
                        \ the value in BOMB. If we have an energy bomb fitted,
                        \ BOMB will contain &7F (%01111111) before this shift
                        \ and will contain &FE (%11111110) after the shift; if
                        \ we don't have an energy bomb fitted, BOMB will still
                        \ contain 0. The bomb explosion is dealt with in the
                        \ MAL1 routine below - this just registers the fact that
                        \ we've set the bomb ticking

Code variation 10 of 16Related to the Master version

The Master's energy bomb lightning bolt effect contains nine random zig-zag lines that are set up in the BOMBINIT routine.

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

Master

BEQ MA76 \ If BOMB now contains 0, then the bomb is not going off \ any more (or it never was), so skip the following \ instruction JSR BOMBINIT \ Call BOMBINIT to set up and display a new energy bomb \ zig-zag lightning bolt
.MA76

Code variation 11 of 16Related to an enhanced feature

In the enhanced versions, the main loop scans for "P" being pressed, which disables the docking computer.

This variation is blank in the Cassette and Electron versions.

Flight, 6502SP, Master

LDA KY20 \ If "P" is being pressed, keep going, otherwise skip BEQ MA78 \ the next two instructions LDA #0 \ The "cancel docking computer" key is bring pressed, STA auto \ so turn it off by setting auto to 0 .MA78

Code variation 12 of 16Minor and very low-impact

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Electron

Flight, 6502SP, Master

LDA KY13 \ If ESCAPE is being pressed and we have an escape pod AND ESCP \ fitted, keep going, otherwise skip the next BEQ P%+5 \ instruction
LDA KY13 \ If ESCAPE is being pressed and we have an escape pod AND ESCP \ fitted, keep going, otherwise jump to noescp to skip BEQ noescp \ the following instructions

Code variation 13 of 16Related to an advanced feature

In the original versions, you can launch your escape pod in witchspace (though it may be fatal, depending on the version). You can't even launch it in the advanced versions, as the launch key is disabled in witchspace.

This variation is blank in the Cassette, Disc (flight) and Electron versions.

6502SP, Master

LDA MJ \ If we are in witchspace, we can't launch our escape BNE noescp \ pod, so jump down to noescp
 JMP ESCAPE             \ The "launch escape pod" button is being pressed and
                        \ we have an escape pod fitted, so jump to ESCAPE to
                        \ launch it, and exit the main flight loop using a tail
                        \ call

Code variation 14 of 16A variation in the labels only

This variation is blank in the Cassette and Electron versions.

Flight, 6502SP, Master

.noescp
 LDA KY18               \ If "J" is being pressed, keep going, otherwise skip
 BEQ P%+5               \ the next instruction

 JSR WARP               \ Call the WARP routine to do an in-system jump

 LDA KY17               \ If "E" is being pressed and we have an E.C.M. fitted,
 AND ECM                \ keep going, otherwise jump down to MA64 to skip the
 BEQ MA64               \ following

 LDA ECMA               \ If ECMA is non-zero, that means an E.C.M. is already
 BNE MA64               \ operating and is counting down (this can be either
                        \ our E.C.M. or an opponent's), so jump down to MA64 to
                        \ skip the following (as we can't have two E.C.M.
                        \ systems operating at the same time)

 DEC ECMP               \ The "E.C.M." button is being pressed and nobody else
                        \ is operating their E.C.M., so decrease the value of
                        \ ECMP to make it non-zero, to denote that our E.C.M.
                        \ is now on

 JSR ECBLB2             \ Call ECBLB2 to light up the E.C.M. indicator bulb on
                        \ the dashboard, set the E.C.M. countdown timer to 32,
                        \ and start making the E.C.M. sound

.MA64

Code variation 15 of 16Related to an enhanced feature

If "C" is pressed during flight and we have a docking computer, then in the enhanced versions the docking computer takes control of the ship, unlike in the cassette version, which instantly docks when "C" is pressed.

Tap on a version to expand it, and tap it again to show to all variations.

Cassette

Flight, 6502SP, Master

Electron

LDA KY19 \ If "C" is being pressed, and we have a docking AND DKCMP \ computer fitted, and we are inside the space station's AND SSPR \ safe zone, keep going, otherwise jump down to MA68 to BEQ MA68 \ skip the following LDA K%+NI%+32 \ Fetch the AI counter (byte #32) of the second ship BMI MA68 \ from the ship data workspace at K%, which is reserved \ for the sun or the space station (in this case it's \ the latter as we are in the safe zone). If byte #32 is \ negative, meaning the station is hostile, then jump \ down to MA68 to skip the following (so we can't use \ the docking computer to dock at a station that has \ turned against us) JMP GOIN \ The "docking computer" button has been pressed and \ we are allowed to dock at the station, so jump to \ GOIN to dock (or "go in"), and exit the main flight \ loop using a tail call
LDA KY19 \ If "C" is being pressed, and we have a docking AND DKCMP \ computer fitted, keep going, otherwise jump down to BEQ MA68 \ MA68 to skip the following STA auto \ Set auto to the non-zero value of A, so the docking \ computer is activated
LDA KY19 \ If "C" is being pressed, and we have a docking AND DKCMP \ computer fitted, and we are inside the space station's AND SSPR \ safe zone, keep going, otherwise jump down to MA68 to BEQ MA68 \ skip the following LDA K%+NI%+32 \ Fetch the AI counter (byte #32) of the second ship BMI MA68 \ from the ship data workspace at K%, which is reserved \ for the space station. If byte #32 is negative, \ meaning the station is hostile, then jump down to \ MA68 to skip the following (so we can't use the \ docking computer to dock at a station that has turned \ against us) JMP GOIN \ The "docking computer" button has been pressed and \ we are allowed to dock at the station, so jump to \ GOIN to dock (or "go in"), and exit the main flight \ loop using a tail call
.MA68

 LDA #0                 \ Set LAS = 0, to switch the laser off while we do the
 STA LAS                \ following logic

 STA DELT4              \ Take the 16-bit value (DELTA 0) - i.e. a two-byte
 LDA DELTA              \ number with DELTA as the high byte and 0 as the low
 LSR A                  \ byte - and divide it by 4, storing the 16-bit result
 ROR DELT4              \ in DELT4(1 0). This has the effect of storing the
 LSR A                  \ current speed * 64 in the 16-bit location DELT4(1 0)
 ROR DELT4
 STA DELT4+1

 LDA LASCT              \ If LASCT is zero, keep going, otherwise the laser is
 BNE MA3                \ a pulse laser that is between pulses, so jump down to
                        \ MA3 to skip the following

 LDA KY7                \ If "A" is being pressed, keep going, otherwise jump
 BEQ MA3                \ down to MA3 to skip the following

 LDA GNTMP              \ If the laser temperature >= 242 then the laser has
 CMP #242               \ overheated, so jump down to MA3 to skip the following
 BCS MA3

 LDX VIEW               \ If the current space view has a laser fitted (i.e. the
 LDA LASER,X            \ laser power for this view is greater than zero), then
 BEQ MA3                \ keep going, otherwise jump down to MA3 to skip the
                        \ following

                        \ If we get here, then the "fire" button is being
                        \ pressed, our laser hasn't overheated and isn't already
                        \ being fired, and we actually have a laser fitted to
                        \ the current space view, so it's time to hit me with
                        \ those laser beams

 PHA                    \ Store the current view's laser power on the stack

 AND #%01111111         \ Set LAS and LAS2 to bits 0-6 of the laser power
 STA LAS
 STA LAS2

Code variation 16 of 16Related to the Master version

The Master version has a unique sound for when our laser is firing.

Tap on a version to expand it, and tap it again to show to all variations.

Cassette, Flight, 6502SP, Electron

Master

LDA #0 \ Call the NOISE routine with A = 0 to make the sound JSR NOISE \ of our laser firing
JSR NOISELASER \ Call the NOISELASER routine to make the sound of our \ laser firing
 JSR LASLI              \ Call LASLI to draw the laser lines

 PLA                    \ Restore the current view's laser power into A

 BPL ma1                \ If the laser power has bit 7 set, then it's an "always
                        \ on" laser rather than a pulsing laser, so keep going,
                        \ otherwise jump down to ma1 to skip the following
                        \ instruction

 LDA #0                 \ This is an "always on" laser (i.e. a beam laser,
                        \ as the cassette version of Elite doesn't have military
                        \ lasers), so set A = 0, which will be stored in LASCT
                        \ to denote that this is not a pulsing laser

.ma1

 AND #%11111010         \ LASCT will be set to 0 for beam lasers, and to the
 STA LASCT              \ laser power AND %11111010 for pulse lasers, which
                        \ comes to 10 (as pulse lasers have a power of 15). See
                        \ MA23 below for more on laser pulsing and LASCT

RSS Feed