Skip to navigation

Revs on the BBC Micro

Keyboard: ProcessDrivingKeys (Part 3 of 6)

Name: ProcessDrivingKeys (Part 3 of 6) [Show more] Type: Subroutine Category: Keyboard Summary: Process joystick brake and throttle
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.keys13 LDA leaveTrackTimer \ If leaveTrackTimer is non-zero then the leave track BNE keys19 \ timer is counting down, so jump to keys19 to skip the \ whole brake/throttle section BIT configJoystick \ If bit 7 of configJoystick is clear then the joystick BPL keys15 \ is not configured, so jump to keys15 to check for key \ presses for the brake/throttle LDX #2 \ Read the joystick y-axis into A and X, clearing the JSR GetADCChannel \ C flag if A < 10, setting A to the high byte, and \ setting X to 1 if the stick is up, or 0 if the stick \ is down BCC keys19 \ If A < 10 then the joystick is pretty close to the \ centre, so jump to keys19 so we don't register any \ throttle or brake activity STA T \ Set T = A / 2 LSR T ASL A \ Set A = A * 2 ADC T \ Set A = A + T \ = A * 2 + A / 2 \ = 2.5 * A BCS keys14 \ If the addition overflowed, then the joystick has \ moved a long way from the centre, so jump to keys14 to \ apply the brakes or throttle at full power CMP #250 \ If A < 250, jump to keys20 to store A in throttleBrake BCC keys20 \ and X in throttleBrakeState, so we store the amount of \ brakes or throttle to apply .keys14 CPX #0 \ If X = 0 then the joystick y-axis is positive (down), BEQ keys18 \ so jump to keys18 to apply the brakes BNE keys16 \ Otherwise the joystick y-axis is negative (up), so \ jump to keys16 to increase the throttle (this BNE is \ effectively a JMP as we already know X is non-zero)