.ProcessTime \ First, we update the timerAdjust counter, which \ iterates from trackTimerAdjust down to zero and back \ round again, but only if trackTimerAdjust <> 255 \ \ The timerAdjust counter is used to control the speed \ of the timers in the AddTimeToTimer routine LDX timerAdjust \ If timerAdjust <> 0, jump to tick1 to decrement the BNE tick1 \ counter in timerAdjust, as it hasn't wrapped round yet \ If we get here then timerAdjust = 0, so we need to \ wrap round to trackTimerAdjust again LDX trackTimerAdjust \ Set X = trackTimerAdjust + 1 INX \ \ We add the 1 so we can decrement it back to \ trackTimerAdjust below (assuming timer adjustments are \ enabled) BEQ tick2 \ If X = 0, then trackTimerAdjust must be 255, in which \ case timer adjustments are disabled, so jump to tick2 \ to leave timerAdjust alone .tick1 DEX \ Set timerAdjust = X - 1 STX timerAdjust \ \ So the clock adjustment counter decrements on each \ iteration round the main loop .tick2 LDA raceStarting \ If bit 7 of raceStarting is set, then the race is in BMI tick3 \ the process of starting but hasn't started yet, so \ jump to tick3 to leave the clock timer alone LDX #0 \ Increment the clock timer JSR AddTimeToTimer .tick3 INC mainLoopCounterLo \ Increment the main loop counter in (mainLoopCounterHi \ mainLoopCounterLo), starting with the low byte BNE tick4 \ And then the high byte, if the low byte overflowed INC mainLoopCounterHi .tick4 LDA clockSeconds \ If clockSeconds = 0, skip the following BEQ tick5 LDA mainLoopCounterLo \ If mainLoopCounterLo mod 32 <> 0, which will be true AND #31 \ for 31 out of 32 iterations round the main loop, jump BNE tick6 \ to tick6 to return from the subroutine .tick5 \ We only get here when mainLoopCounterLo mod 31 = 0, \ which is once every 32 iterations of the main driving \ loop JSR SetDriverSpeed \ Set the speed for the driver number specified in \ setSpeedForDriver, and increment setSpeedForDriver so \ the next time we get here (in 32 iterations of the \ main loop) we set the speed for the next driver .tick6 RTS \ Return from the subroutineName: ProcessTime [Show more] Type: Subroutine Category: Main loop Summary: Increment the timers and the main loop counter Deep dive: Scheduling tasks in the main loopContext: See this subroutine in context in the source code References: This subroutine is called as follows: * FinishRace calls ProcessTime * MainDrivingLoop (Part 2 of 5) calls ProcessTime
[X]
Subroutine AddTimeToTimer (category: Drivers)
Add time to the specified timer
[X]
Subroutine SetDriverSpeed (category: Drivers)
Set the speed for a specific driver
[X]
Variable clockSeconds in workspace Main variable workspace
Seconds for the clock timer
[X]
Variable mainLoopCounterHi (category: Main loop)
High byte of the main loop counter, which increments on each iteration of the main driving loop
[X]
Variable mainLoopCounterLo in workspace Zero page
Low byte of the main loop counter, which increments on each iteration of the main driving loop
[X]
Variable raceStarting in workspace Zero page
The current stage of the starting lights at the start of the race
[X]
Label tick1 is local to this routine
[X]
Label tick2 is local to this routine
[X]
Label tick3 is local to this routine
[X]
Label tick4 is local to this routine
[X]
Label tick5 is local to this routine
[X]
Label tick6 is local to this routine
[X]
Variable timerAdjust in workspace Zero page
A counter for implementing the clock speed adjustment
[X]
Variable trackTimerAdjust in workspace trackData
Adjustment factor for the speed of the timers to allow for fine-tuning of time on a per-track basis