Skip to navigation

Elite on the BBC Micro

Version analysis of DELAY

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

Code variations between these versions are shown below.

Name: DELAY Type: Subroutine Category: Utility routines

Code variation 1 of 7A variation in the comments only

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

Cassette, Flight, Docked, 6502SP, Master

Electron

Summary: Wait for a specified time, in 1/50s of a second
Summary: Wait for a specified time

Code variation 2 of 7A variation in the comments only

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

Cassette, Flight, Docked, 6502SP, Master

Electron

Wait for the number of vertical syncs given in Y, so this effectively waits for Y/50 of a second (as the vertical sync occurs 50 times a second).
Loop round a convoluted loop-within-loop structure to pass the required amount of time.
Arguments:

Code variation 3 of 7A variation in the comments only

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

Cassette, Flight, Docked, 6502SP, Master

Electron

Y The number of vertical sync events to wait for
Y The number of delay loops to run

Code variation 4 of 7A variation in the comments only

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

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

Cassette

Electron

Other entry points: DEL8 Wait for 8/50 of a second (0.16 seconds) DELAY-5 Wait for 2/50 of a second (0.04 seconds)
Other entry points: DEL8 Wait for 30 delay loops' worth of time DELAY-5 Wait for 1 delay loop's worth of time

Code variation 5 of 7Related to the Electron version

On the BBC versions, delays are implemented by waiting for a specified number of vertical syncs. The Electron's video system is different, so it has its own dedicated delay routine that isn't based around the screen refresh, but instead wastes time using a convoluted loop-within-loop structure.

See below for more variations related to this code.

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

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

Cassette

Electron

LDY #2 \ Set Y to 2 vertical syncs EQUB &2C \ Skip the next instruction by turning it into \ &2C &A0 &08, or BIT &08A0, which does nothing apart \ from affect the flags .DEL8 LDY #8 \ Set Y to 8 vertical syncs and fall through into DELAY \ to wait for this long
LDY #1 \ Set Y to 1 so we run the delay loop once EQUB &2C \ Skip the next instruction by turning it into \ &2C &A0 &1E, or BIT &1EA0, which does nothing apart \ from affect the flags .DEL8 LDY #30 \ Set Y to 30 and fall through into DELAY so we run the \ delay loop 30 times
.DELAY

Code variation 6 of 7Related to the Electron version

See variation 5 above for details.

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

Cassette, Flight, Docked, 6502SP, Master

Electron

JSR WSCAN \ Call WSCAN to wait for the vertical sync, so the whole \ screen gets drawn
TXA \ Store X in A so we can retrieve it later \ The following loop does 256 iterations of a convoluted \ loop-back and pass-through sequence, which purely \ exists to implement a delay (and to make us go \ cross-eyed trying to follow the logic) LDX #0 \ Set X = 0 to act as a loop counter .DELY1 EQUB &2C \ Skip the following instruction .DELY2 BNE DELY1 \ Loop back up as part of the chain of delay loops EQUB &2C \ Skip the following instruction .DELY3 BNE DELY2 \ Loop back up as part of the chain of delay loops DEX \ Decrement the loop counter BNE DELY3 \ Loop back up as part of the chain of delay loops TAX \ retrieve X from A, so it gets preserved
 DEY                    \ Decrement the counter in Y

Code variation 7 of 7A variation in the comments only

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

Cassette, Flight, Docked, 6502SP, Master

Electron

BNE DELAY \ If Y isn't yet at zero, jump back to DELAY to wait \ for another vertical sync
BNE DELAY \ If Y isn't yet at zero, jump back to DELAY to wait \ for another iteration of the delay loop
 RTS                    \ Return from the subroutine

RSS Feed