Skip to navigation


Keyboard: ProcessDrivingKeys (Part 6 of 6)

Name: ProcessDrivingKeys (Part 6 of 6) [Show more] Type: Subroutine Category: Keyboard Summary: Process keyboard gear change
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.keys21 LDX #&9F \ Scan the keyboard to see if TAB is being pressed JSR ScanKeyboard BEQ keys23 \ If TAB is being pressed, jump to keys23 LDX #&EF \ Scan the keyboard to see if "Q" is being pressed JSR ScanKeyboard BEQ keys24 \ If "Q" is being pressed, jump to keys24 .keys22 \ If we get here then the gear is not being changed LDA #0 \ Set gearChange = 0 to indicate that we are not in the STA gearChange \ process of changing gear BEQ keys28 \ Jump to keys28 to return from the subroutine (this BEQ \ is effectively a JMP as A is always zero) .keys23 \ If we get here then either TAB is being pressed, or \ the joystick fire button is being pressed while the \ stick is in the "change down" part of the joystick \ range, so we need to change down a gear LDA #&FF \ Set A = -1 so we change down a gear BNE keys25 \ Jump to keys25 to change the gear .keys24 \ If we get here then either "Q" is being pressed, or \ the joystick fire button is being pressed while the \ stick is in the "change up" part of the joystick \ range, so we need to change up a gear LDA #1 \ Set A = 1 so we change up a gear .keys25 DEC gearChangeKey \ Set bit 7 of gearChangeKey (as we set gearChangeKey to \ zero above) LDX gearChange \ If gearChange is non-zero then we are already changing BNE keys28 \ gear, so jump to keys28 to return from the subroutine STA gearChange \ Set gearChange to -1 or 1 CLC \ Add A to the current gearNumber to get the number of ADC gearNumber \ the new gear, after the change CMP #&FF \ If the gear change will result in a gear of -1, jump BEQ keys26 \ to keys26 to set the gear number to 0 (the lowest gear \ number) CMP #7 \ If the new gear is not 7, jump to keys27 to change to BNE keys27 \ this gear LDA #6 \ Otherwise set A to 6, which is the highest gear number BNE keys27 \ allowed, and jump to keys27 to set this as the new \ gear number (this BNE is effectively a JMP as A is \ never zero) .keys26 LDA #0 \ If we get here then we just tried to change down too \ far, so set the number of the new gear to zero .keys27 STA gearNumber \ Store the new gear number in gearNumber JSR PrintGearNumber \ Print the new gear number on the gear stick .keys28 RTS \ Return from the subroutine