Skip to navigation

Elite on the BBC Micro

Version analysis of Main flight loop (Part 11 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 11 of 16) Type: Subroutine Category: Main loop Summary: For each nearby ship: Process missile lock and firing our laser Deep dive: Program flow of the main game loop Flipping axes between space views
The main flight loop covers most of the flight-specific aspects of Elite. This section covers the following: * Continue looping through all the ships in the local bubble, and for each one: * If this is not the front space view, flip the axes of the ship's coordinates in INWK * Process missile lock * Process our laser firing
.MA26

Code variation 1 of 9Related to an enhanced feature

Ships that have docked or been scooped in the enhanced versions are hidden from the scanner.

This variation is blank in the Cassette and Electron versions.

Flight, 6502SP, Master

LDA NEWB \ If bit 7 of the ship's NEWB flags is clear, skip the BPL P%+5 \ following instruction JSR SCAN \ Bit 7 of the ship's NEWB flags is set, which means the \ ship has docked or been scooped, so we draw the ship \ on the scanner, which has the effect of removing it
 LDA QQ11               \ If this is not a space view, jump to MA15 to skip
 BNE MA15               \ missile and laser locking

Code variation 2 of 9Specific to an individual platform

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

Cassette, 6502SP, Master, Electron

Flight

JSR PLUT \ Call PLUT to update the geometric axes in INWK to \ match the view (front, rear, left, right)
LDX VIEW \ Load the current view into X BEQ P%+5 \ If the current view is the front view, skip the \ following instruction, as the geometry in INWK is \ already correct JSR PU1 \ Call PU1 to update the geometric axes in INWK to \ match the view (front, rear, left, right)
 JSR HITCH              \ Call HITCH to see if this ship is in the crosshairs,
 BCC MA8                \ in which case the C flag will be set (so if there is
                        \ no missile or laser lock, we jump to MA8 to skip the
                        \ following)

 LDA MSAR               \ We have missile lock, so check whether the leftmost
 BEQ MA47               \ missile is currently armed, and if not, jump to MA47
                        \ to process laser fire, as we can't lock an unarmed
                        \ missile

 JSR BEEP               \ We have missile lock and an armed missile, so call
                        \ the BEEP subroutine to make a short, high beep

Code variation 3 of 9Related 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

LDX XSAV \ Call ABORT2 to store the details of this missile LDY #&0E \ lock, with the targeted ship's slot number in X JSR ABORT2 \ (which we stored in XSAV at the start of this ship's \ loop at MAL1), and set the colour of the missile \ indicator to the colour in Y (red = &0E)
LDX XSAV \ Call ABORT2 to store the details of this missile LDY #RED2 \ lock, with the targeted ship's slot number in X JSR ABORT2 \ (which we stored in XSAV at the start of this ship's \ loop at MAL1), and set the colour of the missile \ indicator to the colour in Y (red = &0E)
LDX XSAV \ Call ABORT2 to store the details of this missile LDY #&11 \ lock, with the targeted ship's slot number in X JSR ABORT2 \ (which we stored in XSAV at the start of this ship's \ loop at MAL1), and set the shape of the missile \ indicator to the value in Y (black "T" in white \ square = &11)
.MA47

                        \ If we get here then the ship is in our sights, but
                        \ we didn't lock a missile, so let's see if we're
                        \ firing the laser

 LDA LAS                \ If we are firing the laser then LAS will contain the
 BEQ MA8                \ laser power (which we set in MA68 above), so if this
                        \ is zero, jump down to MA8 to skip the following

 LDX #15                \ We are firing our laser and the ship in INWK is in
 JSR EXNO               \ the crosshairs, so call EXNO to make the sound of
                        \ us making a laser strike on another ship

Code variation 4 of 9Related to an advanced feature

Only military lasers can harm the Cougar, and then they only inflict a quarter of the damage that military lasers inflict on normal ships.

This variation is blank in the Cassette and Electron versions.

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

Flight

6502SP, Master

LDA TYPE \ Did we just hit the space station? If so, jump to CMP #SST \ MA14+2 to make the station hostile, skipping the BEQ MA14+2 \ following as we can't destroy a space station CMP #CON \ If the ship we hit is not a Constrictor, jump to BURN BNE BURN \ to skip the following
LDA TYPE \ Did we just hit the space station? If so, jump to CMP #SST \ MA14+2 to make the station hostile, skipping the BEQ MA14+2 \ following as we can't destroy a space station CMP #CON \ If the ship we hit is less than #CON - i.e. it's not BCC BURN \ a Constrictor, Cougar, Dodo station or the Elite logo, \ jump to BURN to skip the following

Code variation 5 of 9Related to an enhanced feature

Only military lasers can harm the Constrictor in mission 1, and then they only inflict a quarter of the damage that military lasers inflict on normal ships.

This variation is blank in the Cassette and Electron versions.

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

Flight

6502SP, Master

LDA LAS \ Set A to the power of the laser we just used to hit \ the ship (i.e. the laser in the current view) CMP #(Armlas AND 127) \ If the laser is not a military laser, jump to MA8 BNE MA8 \ to skip the following, as only military lasers have \ any effect on the Constrictor LSR LAS \ Divide the laser power of the current view by 4, so LSR LAS \ the damage inflicted on the super-ship is a quarter of \ the damage our military lasers would inflict on a \ normal ship .BURN
LDA LAS \ Set A to the power of the laser we just used to hit \ the ship (i.e. the laser in the current view) CMP #(Armlas AND 127) \ If the laser is not a military laser, jump to MA14+2 BNE MA14+2 \ to skip the following, as only military lasers have \ any effect on the Constrictor or Cougar (or the Elite \ logo, should you ever bump into one of those out there \ in the black...) LSR LAS \ Divide the laser power of the current view by 4, so LSR LAS \ the damage inflicted on the super-ship is a quarter of \ the damage our military lasers would inflict on a \ normal ship .BURN
 LDA INWK+35            \ Fetch the hit ship's energy from byte #35 and subtract
 SEC                    \ our current laser power, and if the result is greater
 SBC LAS                \ than zero, the other ship has survived the hit, so
 BCS MA14               \ jump down to MA14 to make it angry

Code variation 6 of 9Specific to an individual platform

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

Cassette, Electron

LDA TYPE \ Did we just hit the space station? If so, jump to CMP #SST \ MA14+2 to make the station hostile, skipping the BEQ MA14+2 \ following as we can't destroy a space station LDA INWK+31 \ Set bit 7 of the enemy ship's byte #31, to indicate ORA #%10000000 \ that it has been killed STA INWK+31

Code variation 7 of 9A variation in the comments only

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

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

Cassette

Electron

BCS MA8 \ If the enemy ship type is >= SST (i.e. missile, \ asteroid, canister, Thargon or escape pod) then \ jump down to MA8
BCS MA8 \ If the enemy ship type is >= SST (i.e. missile, \ asteroid, canister or escape pod) then jump down \ to MA8

Code variation 8 of 9Related to an enhanced feature

Destroying an asteroid with mining lasers in the enhanced versions will randomly release scoopable splinters, and destroying ships will randomly release not only cargo canisters (as in the cassette version) but also alloy plates.

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

Cassette, Electron

Flight, 6502SP, Master

JSR DORND \ Fetch a random number, and jump to oh if it is BPL oh \ positive (50% chance) LDY #0 \ Fetch the first byte of the hit ship's blueprint, AND (XX0),Y \ which determines the maximum number of bits of \ debris shown when the ship is destroyed, and AND \ with the random number we just fetched STA CNT \ Store the result in CNT, so CNT contains a random \ number between 0 and the maximum number of bits of \ debris that this ship will release when destroyed .um BEQ oh \ We're going to go round a loop using CNT as a counter \ so this checks whether the counter is zero and jumps \ to oh when it gets there (which might be straight \ away) LDX #OIL \ Call SFS1 to spawn a cargo canister from the now LDA #0 \ deceased parent ship, giving the spawned canister an JSR SFS1 \ AI flag of 0 (no AI, no E.C.M., non-hostile) DEC CNT \ Decrease the loop counter BPL um \ Jump back up to um (this BPL is effectively a JMP as \ CNT will never be negative) .oh
ASL INWK+31 \ Set bit 7 of the ship byte #31 to indicate that it has SEC \ now been killed ROR INWK+31 LDA TYPE \ Did we just kill an asteroid? If not, jump to nosp, CMP #AST \ otherwise keep going BNE nosp LDA LAS \ Did we kill the asteroid using mining lasers? If not, CMP #Mlas \ jump to nosp, otherwise keep going BNE nosp JSR DORND \ Set A and X to random numbers LDX #SPL \ Set X to the ship type for a splinter AND #3 \ Reduce the random number in A to the range 0-3 JSR SPIN2 \ Call SPIN2 to spawn A items of type X (i.e. spawn \ 0-3 spliters) .nosp LDY #PLT \ Randomly spawn some alloy plates JSR SPIN LDY #OIL \ Randomly spawn some cargo canisters JSR SPIN

Code variation 9 of 9Related to the Master version

The Master version awards different kill points depending on the type of the ship that we kill, ranging from 0.03125 points for a splinter to 5.33203125 points for a Constrictor or Cougar.

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

Master

LDX TYPE \ Set X to the type of the ship that was killed so the \ following call to EXNO2 can award us the correct \ number of fractional kill points
 JSR EXNO2              \ Call EXNO2 to process the fact that we have killed a
                        \ ship (so increase the kill tally, make an explosion
                        \ sound and so on)

.MA14

 STA INWK+35            \ Store the hit ship's updated energy in ship byte #35

 LDA TYPE               \ Call ANGRY to make this ship hostile, now that we
 JSR ANGRY              \ have hit it

RSS Feed