.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 TAY \ Store A in Y so we can preserve it through the call to \ CAPSL below JSR CAPSL \ Call CAPSL to check whether CAPS LOCK is being pressed \ (if it is, the return value in A is the key number of \ CAPS LOCK, but with bit 7 set) PHP \ Retrieve the value of A we stored in Y, but making TYA \ sure the retrieval doesn't affect the flags PLP BPL P%+4 \ If the result of the call to CAPSL was positive, then \ CAPS LOCK isn't being pressed, so skip the next \ instruction ORA #%10000000 \ CAPS LOCK is being pressed, so set bit 7 of A TAX \ Copy A into X to return the key number of CAPS LOCK \ with bit 7 set RTS \ Return from the subroutineName: RDKEY [Show more] Type: Subroutine Category: Keyboard Summary: Scan the keyboard for key pressesContext: 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: * DK4 calls RDKEY * TITLE calls RDKEY
Scan the keyboard, starting with internal key number 16 ("Q") and working through the set of internal key numbers (see p.40 of the Electron 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.
Returns: X If a key is being pressed, X contains the internal key number, otherwise it contains 0 A Contains the same as X
[X]
Subroutine DKS4 (category: Keyboard)
Scan the keyboard to see if a specific key is being pressed
[X]
Label Rd1 is local to this routine
[X]
Label Rd2 is local to this routine