Skip to navigation

Elite on the BBC Micro

Keyboard: TT17 [Electron version]

Name: TT17 [Show more] Type: Subroutine Category: Keyboard Summary: Scan the keyboard for cursor key movement
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: * Main game loop (Part 5 of 6) calls TT17

Scan the keyboard for cursor key movement, and return the result as deltas (changes) in x- and y-coordinates as follows: * X and Y are integers between -1 and +1 depending on which keys are pressed Returns: A The key pressed, if the arrow keys were used X Change in the x-coordinate according to the cursor keys being pressed, as an integer (see above) Y Change in the y-coordinate according to the cursor keys being pressed, as an integer (see above)
.TT17 JSR DOKEY \ Scan the keyboard for flight controls and pause keys, \ and update the key logger, setting KL to the key \ pressed LDX JSTK \ If the joystick is not configured, jump down to TJ1, BEQ TJ1 \ otherwise keep going... though as the DOKEY routine \ doesn't read the ADC channels in the Electron version, \ this doesn't actually work, but instead moves the \ crosshairs in an uncontrollable way, so this is \ presumably a bug LDA JSTX \ Fetch the joystick roll, ranging from 1 to 255 with \ 128 as the centre point EOR #&FF \ Flip the sign so A = -JSTX, because the joystick roll \ works in the opposite way to moving a cursor on-screen \ in terms of left and right JSR TJS1 \ Call TJS1 just below to set A to a value between -2 \ and +2 depending on the joystick roll value (moving \ the stick sideways) TYA \ Copy Y to A TAX \ Copy A to X, so X contains the joystick roll value LDA JSTY \ Fetch the joystick pitch, ranging from 1 to 255 with \ 128 as the centre point, and fall through into TJS1 to \ set Y to the joystick pitch value (moving the stick up \ and down) .TJS1 TAY \ Store A in Y LDA #0 \ Set the result, A = 0 CPY #16 \ If Y >= 16 set the C flag, so A = A - 1 SBC #0 CPY #64 \ If Y >= 64 set the C flag, so A = A - 1 SBC #0 CPY #192 \ If Y >= 192 set the C flag, so A = A + 1 ADC #0 CPY #224 \ If Y >= 224 set the C flag, so A = A + 1 ADC #0 TAY \ Copy the value of A into Y LDA KL \ Set A to the value of KL (the key pressed) RTS \ Return from the subroutine .TJ1 LDA KL \ Set A to the value of KL (the key pressed) LDY #0 \ Set the result, Y = 0 (and we know that X is 0 as well \ as we jumped to TJ1 from above following a LDX and a \ BEQ) CMP #&18 \ If left arrow was pressed, set X = X - 1 BNE P%+3 DEX CMP #&78 \ If right arrow was pressed, set X = X + 1 BNE P%+3 INX CMP #&39 \ If up arrow was pressed, set Y = Y + 1 BNE P%+3 INY CMP #&28 \ If down arrow was pressed, set Y = Y - 1 BNE P%+3 DEY RTS \ Return from the subroutine