Skip to navigation

Revs on the BBC Micro

Driving model: ProcessEngineStart

Name: ProcessEngineStart [Show more] Type: Subroutine Category: Driving model Summary: Process the key press for starting the engine Deep dive: Modelling the engine
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyEngine calls ProcessEngineStart
.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)