Skip to navigation


Main loop: ProcessTime

Name: ProcessTime [Show more] Type: Subroutine Category: Main loop Summary: Increment the timers and the main loop counter Deep dive: Scheduling tasks in the main loop
Context: 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
.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 subroutine