.ProcessEngineStart \ The routine is called from ApplyEngine when the engine \ is not running LDX #&DC \ Scan the keyboard to see if "T" is being pressed JSR ScanKeyboard BEQ engs2 \ If "T" is being pressed, jump to engs2 LDY gearNumber \ If gearNumber = 1, then we are in neutral, so jump to DEY \ engs1 BEQ engs1 \ If we get here then we are still in gear LDA playerSpeedHi \ Set A = playerSpeedHi BNE engs3 \ If A <> 0 then we are moving, so jump to engs3 to \ start the engine and set the rev counter to \ playerSpeedHi, as the engine can be restarted after \ stalling if we are going fast enough (i.e. if \ playerSpeedHi > 0) .engs1 \ If we get here then we are either in neutral, or we \ are not in neutral but are not moving LDA #0 \ Set A = 0 to set as the value of the rev counter BEQ SetRevsNoTorque \ Jump to SetRevsNoTorque to zero the rev counter and \ engine torque (this BEQ is effectively a JMP as A is \ always zero) .engs2 \ If we get here then then the engine is not running and \ "T" is being pressed LDA VIA+&68 \ Read 6522 User VIA T1C-L timer 2 low-order counter \ (SHEILA &68), which decrements one million times a \ second and will therefore be pretty random AND oddsOfEngineStart \ Set A = A mod oddsOfEngineStart BNE ThrobRevsNoTorque \ If A is non-zero, jump to ThrobRevsNoTorque \ Otherwise keep going to start the engine (which has a \ chance of 1 in oddsOfEngineStart of happening) and set \ the revs to zero (as A is zero) .engs3 \ If we get here then the engine is not running, and we \ are either already moving, or "T" is being pressed and \ we passed through the above (a 1 in oddsOfEngineStart \ chance) LDX #7 \ Set oddsOfEngineStart = 7, to reset it back to the STX oddsOfEngineStart \ default chance of starting the engine LDX #&FF \ Set engineStatus = &FF to turn on the engine STX engineStatus BMI ThrobRevsNoTorque \ Jump to ThrobRevsNoTorque to set the rev counter to A \ with a random throb added (this BMI is effectively a \ JMP as X is always negative)Name: ProcessEngineStart [Show more] Type: Subroutine Category: Driving model Summary: Process the key press for starting the engine Deep dive: Modelling the engineContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyEngine calls ProcessEngineStart
[X]
Subroutine ScanKeyboard (category: Keyboard)
Scan the keyboard for a specific key press
[X]
Subroutine SetRevsNoTorque (category: Driving model)
Set the rev counter and zero the engine torque
[X]
Subroutine ThrobRevsNoTorque (category: Driving model)
Set the rev counter after adding a random throb and zero the engine torque
[X]
Configuration variable VIA = &FE00
Memory-mapped space for accessing internal hardware, such as the video ULA, 6845 CRTC and 6522 VIAs (also known as SHEILA)
[X]
Variable engineStatus in workspace Zero page
Whether or not the engine is on
[X]
Label engs1 is local to this routine
[X]
Label engs2 is local to this routine
[X]
Label engs3 is local to this routine
[X]
Variable gearNumber in workspace Zero page
The current gear number
[X]
Variable oddsOfEngineStart in workspace Zero page
The chances of the engine starting while revving the engine (the engine will start with a chance of 1 in oddsOfEngineStart)
[X]
Variable playerSpeedHi in workspace Zero page
High byte of the speed of the player's car along the track