Skip to navigation

Elite on the BBC Micro and NES

Version analysis of U% / ZEKTRAN

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

Code variations between these versions are shown below.

Code variation 1 of 5A variation in the comments only

Tap on a block to expand it, and tap it again to revert.

Name: U%
Name: ZEKTRAN
Type: Subroutine Category: Keyboard Summary: Clear the key logger
Returns: A A is set to 0

Code variation 2 of 5A variation in the comments only

Tap on a block to expand it, and tap it again to revert.

Y Y is set to 0
X X is set to 0

Code variation 3 of 5A variation in the labels only

Tap on a block to expand it, and tap it again to revert.

.U%
.ZEKTRAN
 LDA #0                 \ Set A to 0, as this means "key not pressed" in the
                        \ key logger at KL

Code variation 4 of 5Related to an enhanced feature

Compared to the cassette version, the enhanced versions have an extra key in the key logger, for "P" (which turns off the docking computer).

Tap on a block to expand it, and tap it again to revert.

LDY #15 \ We want to clear the 15 key logger locations from \ KY1 to KY19, so set a counter in Y
LDY #16 \ We want to clear the 16 key logger locations from \ KY1 to KY20, so set a counter in Y
LDX #17 \ We want to clear the 17 key logger locations from \ KL to KY20, so set a counter in X

Code variation 5 of 5Specific to an individual platform

Tap on a block to expand it, and tap it again to revert.

.DKL3 STA KL,Y \ Store 0 in the Y-th byte of the key logger DEY \ Decrement the counter BNE DKL3 \ And loop back for the next key, until we have just \ KL+1. We don't want to clear the first key logger \ location at KL, as the keyboard table at KYTB starts \ with offset 1, not 0, so KL is not technically part of \ the key logger (it's actually used for logging keys \ that don't appear in the keyboard table, and which \ therefore don't use the key logger)
.ZEKLOOP STA JSTY,X \ Store 0 in the X-th byte of the key logger DEX \ Decrement the counter BNE ZEKLOOP \ And loop back for the next key, until we have just \ KL+1. We don't want to clear the first key logger \ location at KL, as the keyboard table at KYTB starts \ with offset 1, not 0, so KL is not technically part of \ the key logger (it's actually used for logging keys \ that don't appear in the keyboard table, and which \ therefore don't use the key logger)
 RTS                    \ Return from the subroutine