Skip to navigation

Elite on the BBC Micro

Keyboard: RDKEY [Elite-A, I/O processor]

Name: RDKEY [Show more] Type: Subroutine Category: Keyboard Summary: Scan the keyboard for key presses
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * get_key calls RDKEY * scan_10in calls RDKEY

Scan the keyboard, starting with internal key number 16 ("Q") and working through the set of internal key numbers (see p.142 of the Advanced User Guide for a list of internal key numbers). This routine is effectively the same as OSBYTE 122, though the OSBYTE call preserves A, unlike this routine. If CTRL-P is pressed, then the routine calls the printer routine to print the screen, and returns 0 in A and X. Returns: X If a key is being pressed, X contains the internal key number, otherwise it contains 0
.RDKEY LDX #16 \ Start the scan with internal key number 16 ("Q") .Rd1 JSR DKS4 \ Scan the keyboard to see if the key in X is currently \ being pressed, returning the result in A and X BMI Rd2 \ Jump to Rd2 if this key is being pressed (in which \ case DKS4 will have returned the key number with bit \ 7 set, which is negative) INX \ Increment the key number, which was unchanged by the \ above call to DKS4 BPL Rd1 \ Loop back to test the next key, ending the loop when \ X is negative (i.e. 128) TXA \ If we get here, nothing is being pressed, so copy X \ into A so that X = A = 128 = %10000000 .Rd2 EOR #%10000000 \ EOR A with #%10000000 to flip bit 7, so A now contains \ 0 if no key has been pressed, or the internal key \ number if a key has been pressed CMP #&37 \ If "P" was not pressed, jump to scan_test to return BNE scan_test \ the key press LDX #1 \ Set X to the internal key number for CTRL JSR DKS4 \ Scan the keyboard to see if the key in X (i.e. CTRL) \ is currently pressed BPL scan_p \ If it is not being pressed, jump to scan_p to return \ "P" as the key press JSR printer \ CTRL-P was pressed, so call printer to output the \ screen to the printer LDA #0 \ Set A to 0 to return no key press from the routine, as \ we already acted on it RTS \ Return from the subroutine .scan_p LDA #&37 \ Set A to the internal key number for "P", to return as \ the result .scan_test TAX \ Copy the key value into X RTS \ Return from the subroutine