Skip to navigation


Keyboard: ProcessDrivingKeys (Part 4 of 6)

Name: ProcessDrivingKeys (Part 4 of 6) [Show more] Type: Subroutine Category: Keyboard Summary: Process keyboard brake and throttle
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.keys15 LDX #&AE \ Scan the keyboard to see if "S" is being pressed (the JSR ScanKeyboard \ throttle key) BNE keys17 \ If "S" is not being pressed, jump to keys17 to check \ the next key LDX #1 \ Set X = 1 to store in throttleBrakeState below .keys16 LDA #255 \ Set A = 255 to store in throttleBrake below BNE keys20 \ Jump to keys20 (this BNE is effectively a JMP as A is \ never zero) .keys17 LDX #&BE \ Scan the keyboard to see if "A" is being pressed (the JSR ScanKeyboard \ brake key) BNE keys19 \ If "A" is not being pressed, jump to keys19 LDX #0 \ Set X = 0 to store in throttleBrakeState below .keys18 LDA #250 \ Set A = 250 to store in throttleBrake below BNE keys20 \ Jump to keys20 (this BNE is effectively a JMP as A is \ never zero) .keys19 \ If we get here then neither of the throttle keys are \ being pressed, or the joystick isn't being moved \ enough to register a change LDX #%10000000 \ Set bit 7 of X to store in throttleBrakeState below LDA revCount \ Set A = 5 + revCount / 4 LSR A \ LSR A \ to store in throttleBrake below CLC ADC #5 .keys20 STX throttleBrakeState \ Store X in throttleBrakeState STA throttleBrake \ Store A in throttleBrake \ By the time we get here, one of the following is true: \ \ * There is no brake or throttle action from keyboard \ or joystick: \ \ throttleBrakeState = bit 7 set \ throttleBrake = 5 + revCount / 4 \ \ * Joystick is enabled and 2.5 * y-axis < 250 (so \ joystick is in the zone around the centre) \ \ throttleBrakeState = 0 for joystick down, brake \ 1 for joystick up, throttle \ throttleBrake = 2.5 * y-axis \ \ * "S" (throttle) is being pressed (or joystick has \ 2.5 * y-axis >= 250): \ \ throttleBrakeState = 1 \ throttleBrake = 255 \ \ * "A" (brake) is being pressed (or joystick has \ 2.5 * y-axis >= 250) \ \ throttleBrakeState = 0 \ throttleBrake = 250