Skip to navigation

Elite on the BBC Micro and NES

Utility routines: DELAY

[Acorn Electron version]

Name: DELAY [Show more] Type: Subroutine Category: Utility routines Summary: Wait for a specified time
Context: See this subroutine in context in the source code Variations: See code variations for this subroutine in the different versions References: This subroutine is called as follows: * DKS3 calls DELAY * dn2 calls DELAY * DK4 calls via DEL8 * GTNME calls via DEL8 * Main game loop (Part 5 of 6) calls via DELAY-5

Loop round a convoluted loop-within-loop structure to pass the required amount of time.
Arguments: Y The number of delay loops to run
Other entry points: DEL8 Wait for 30 delay loops' worth of time DELAY-5 Wait for 1 delay loop's worth of time
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 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 by turning it into \ &2C &D0 &FD, or BIT &FDD0, which does nothing apart \ from affect the flags .DELY2 BNE DELY1 \ Loop back up as part of the chain of delay loops EQUB &2C \ Skip the following instruction by turning it into \ &2C &D0 &FB, or BIT &FBD0, which does nothing apart \ from affect the flags .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 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