Skip to navigation

Keyboard: ScanKeyboard

Name: ScanKeyboard [Show more] Type: Subroutine Category: Keyboard Summary: Scan the keyboard for a specific key press
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * CheckForKeyPresses calls ScanKeyboard * ScanForGameKeys calls ScanKeyboard

This routine is from Revs, Geoff Crammond's previous game. There is only one minor difference: the value of Y is preserved.
Arguments: X The negative inkey value of the key to scan for (in the range &80 to &FF)
Returns: Z flag The result: * Set if the key in X is being pressed, in which case BEQ will branch * Clear if the key in X is not being pressed, in which case BNE will branch Y Y is preserved
.ScanKeyboard TYA \ Store Y on the stack so we can preserve it PHA LDA #129 \ Call OSBYTE with A = 129, Y = &FF and the inkey value LDY #&FF \ in X, to scan the keyboard for key X JSR OSBYTE PLA \ Retrieve Y from the stack so it is unchanged TAY CPX #&FF \ If the key in X is being pressed, the above call sets \ both X and Y to &FF, so this sets the Z flag depending \ on whether the key is being pressed (so a BEQ after \ the call will branch if the key in X is being pressed) RTS \ Return from the subroutine