Skip to navigation

Revs on the BBC Micro

Driving model: CalcRevsNoTorque

Name: CalcRevsNoTorque [Show more] Type: Subroutine Category: Driving model Summary: Calculate the value of the rev counter according to the throttle being applied and zero the engine torque Deep dive: Modelling the engine
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyEngine calls CalcRevsNoTorque * ApplyEngine calls via CalcRevsNoTorque-2

Other entry points: CalcRevsNoTorque-2 Set clutchEngaged to A before running the routine
STA clutchEngaged \ Set clutchEngaged = A .CalcRevsNoTorque LDA revCount \ Set A to the current rev counter LDX throttleBrakeState \ If throttleBrakeState <> 1 then the throttle is not DEX \ being applied, so jump to urev1 BNE urev1 ADC #7 \ Set A = A + 7 \ = revCount + 7 CMP throttleBrake \ If A >= throttleBrake, then the rev counter is higher BCS urev1 \ than the amount of throttle being applied, so jump to \ urev1 CMP #140 \ If A < 140, jump to SetRevsNoTorque to set the rev BCC SetRevsNoTorque \ counter to the new amount and zero the engine torque, \ returning from the subroutine using a tail call .urev1 CMP #42 \ If A < 42, jump to urev2 to set A = 40, the idling BCC urev2 \ level of the rev counter SEC \ Set A = A - 12 SBC #12 BCS ThrobRevsNoTorque \ Jump to ThrobRevsNoTorque to set the rev counter to \ the new amount, with a random throb added, and zero \ the engine torque, returning from the subroutine using \ a tail call (this BCS is effectively a JMP, as we know \ the subtraction won't underflow as A >= 42) .urev2 LDA #40 \ Set A = 40 to set as the rev count \ Fall through into ThrobRevsNoTorque to set the rev \ counter to 40, with a random throb added