Skip to navigation


Version analysis of TT217

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

Code variations between these versions are shown below.

Name: TT217 Type: Subroutine Category: Keyboard Summary: Scan the keyboard until a key is pressed
Scan the keyboard until a key is pressed, and return the key's ASCII code. If, on entry, a key is already being held down, then wait until that key is released first (so this routine detects the first key down event following the subroutine call).
Returns: X The ASCII code of the key that was pressed A Contains the same as X Y Y is preserved
Other entry points: out Contains an RTS

Code variation 1 of 7A variation in the comments only

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

t As TT217 but don't preserve Y, set it to YSAV instead
.TT217 STY YSAV \ Store Y in temporary storage, so we can restore it \ later .t

Code variation 2 of 7Specific to an individual platform

This variation is blank in the Electron version.

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

JSR DELAY-5 \ Wait for 8/50 of a second (0.16 seconds) to implement \ a simple keyboard debounce and prevent multiple key \ presses being recorded
LDY #2 \ Wait for 2/50 of a second (0.04 seconds) to implement JSR DELAY \ a simple keyboard debounce and prevent multiple key \ presses being recorded

Code variation 3 of 7Specific to an individual platform

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

JSR RDKEY \ Scan the keyboard for a key press and return the \ internal key number in A and X (or 0 for no key press) BNE t \ If a key was already being held down when we entered \ this routine, keep looping back up to t, until the \ key is released .t2
JSR RDKEY \ Scan the keyboard for a key press and return the \ ASCII code of the key pressed in X (or 0 for no key \ press) BNE t \ If a key was already being held down when we entered \ this routine, keep looping back up to t, until the \ key is released .t2
DEC KEYB \ Decrement KEYB, so it is now &FF, to indicate that we \ are reading from the keyboard using an OS command JSR OSRDCH \ Call OSRDCH to read a character from the keyboard INC KEYB \ Increment KEYB back to 0 to indicate we are done \ reading the keyboard

Code variation 4 of 7Specific to an individual platform

This variation is blank in the Electron version.

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

JSR RDKEY \ Any pre-existing key press is now gone, so we can \ start scanning the keyboard again, returning the \ internal key number in A and X (or 0 for no key press)
JSR RDKEY \ Any pre-existing key press is now gone, so we can \ start scanning the keyboard again, returning the \ ASCII code of the key pressed in X (or 0 for no key \ press)

Code variation 5 of 7Specific to an individual platform

This variation is blank in the Electron version.

BEQ t2 \ Keep looping up to t2 until a key is pressed

Code variation 6 of 7Related to Elite's use of the Tube

This variation is blank in the Master and Electron versions.

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

TAY \ Copy A to Y, so Y contains the internal key number \ of the key pressed LDA (TRTB%),Y \ The address in TRTB% points to the MOS key \ translation table, which is used to translate \ internal key numbers to ASCII, so this fetches the \ key's ASCII code into A
TAY \ Copy A to Y, so Y contains the internal key number \ of the key pressed LDA TRANTABLE,Y \ TRANTABLE points to the MOS key translation table, \ which is used to translate internal key numbers to \ ASCII, so this fetches the key's ASCII code into A

Code variation 7 of 7Specific to an individual platform

This variation is blank in the Electron version.

LDY YSAV \ Restore the original value of Y we stored above
 TAX                    \ Copy A into X

.out

 RTS                    \ Return from the subroutine