.ProcessDrivingKeys LDA #0 \ Set V = 0, which we will use to indicate whether any STA V \ steering is being applied (0 indicates that none is \ being applied, which we may change later) STA T \ Set T = 0, which we will use to record whether SPACE \ is being pressed, which makes the steering wheel turn \ more quickly STA gearChangeKey \ Set gearChangeKey = 0, which we will use to indicate \ whether any gear change are being applied (0 indicates \ that no gear changes are being applied, which we may \ change later) IF _ACORNSOFT OR _4TRACKS BIT configJoystick \ If bit 7 of configJoystick is clear then the joystick BPL keys2 \ is not configured, so jump to keys2 to check for key \ presses for the steering LDX #&9D \ Scan the keyboard to see if SPACE is being pressed, as JSR ScanKeyboard \ this will affect the speed of any steering changes PHP \ Store the result of the scan on the stack ELIF _SUPERIOR OR _REVSPLUS LDX #&9D \ Scan the keyboard to see if SPACE is being pressed, as JSR ScanKeyboard \ this will affect the speed of any steering changes PHP \ Store the result of the scan on the stack BIT configJoystick \ If bit 7 of configJoystick is clear then the joystick BPL keys2 \ is not configured, so jump to keys2 to check for key \ presses for the steering ENDIF LDX #1 \ Read the joystick x-axis into A and X (A is set to the JSR GetADCChannel \ high byte of the channel, X is set to the sign of A \ where 1 = negative/left, 0 = positive/right) STA U \ Store the x-axis high byte in U JSR Multiply8x8 \ Set (A T) = A * U \ = A * A \ = A^2 \ = x-axis^2 PLP \ Retrieve the result of the keyboard scan above, when \ we scanned for SPACE BEQ keys1 \ If SPACE is being pressed, jump to keys1 so the value \ of (A T) will be four times higher LSR A \ Set (A T) = (A T) / 4 ROR T \ = x-axis^2 / 4 LSR A ROR T .keys1 IF _ACORNSOFT OR _4TRACKS PHA \ Store A on the stack so we can retrieve it later ELIF _SUPERIOR OR _REVSPLUS STA U \ Set (U T) = (A T) ENDIF LDA T \ Clear bit 0 of T AND #%11111110 STA T TXA \ Set bit 0 of T to the sign bit in X (1 = left, ORA T \ 0 = right), so this sets (A T) to the correct sign STA T \ for a steering measurement IF _ACORNSOFT OR _4TRACKS PLA \ Retrieve the value of A that we stored on the stack JMP keys11 \ Jump to the end of part 2 to update the steering value \ in (steeringHi steeringLo) to (A T) ELIF _SUPERIOR OR _REVSPLUS LDA U \ Set (A T) = (U T) \ \ so (A T) contains the joystick x-axis high byte, \ squared, divided by 4 if SPACE is not being pressed, \ and converted into a sign-magnitude number with the \ sign in bit 0 (1 = left, 0 = right) JMP AssistSteering \ Jump to AssistSteering to apply computer assisted \ steering (CAS), which in turn jumps back to keys7 or \ keys11 in part 2 NOP \ These instructions are unused, and are included to NOP \ pad out the code from when the CAS code was inserted \ into the original version ENDIFName: ProcessDrivingKeys (Part 1 of 6) [Show more] Type: Subroutine Category: Keyboard Summary: Process joystick steering Deep dive: Computer assisted steering (CAS)Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls ProcessDrivingKeys
This routine scans for key presses, or joystick (when configured), and updates the following variables accordingly: * Steering: (steeringHi steeringLo) * Brake/throttle: throttleBrakeState, throttleBrake * Gear changes: gearChangeKey, gearChange, gearNumber
[X]
Subroutine AssistSteering (category: Tactics)
Apply computer assisted steering (CAS) when configured
[X]
Subroutine GetADCChannel (category: Keyboard)
Read the value of an ADC channel (used to read the joystick)
[X]
Subroutine Multiply8x8 (category: Maths (Arithmetic))
Calculate (A T) = T * U
[X]
Subroutine ScanKeyboard (category: Keyboard)
Scan the keyboard for a specific key press
[X]
Variable configJoystick in workspace Main variable workspace
A key has been pressed to set joystick or keyboard
[X]
Variable gearChangeKey in workspace Zero page
Determines whether or not a gear change key has been pressed
[X]
Label keys1 is local to this routine
[X]
Entry point keys11 in subroutine ProcessDrivingKeys (Part 2 of 6) (category: Keyboard)
Re-entry point for the AssistSteering routine if CAS is not enabled or the car is facing backwards
[X]
Label keys2 in subroutine ProcessDrivingKeys (Part 2 of 6)