Skip to navigation


Main loop: MainDrivingLoop (Part 3 of 5)

Name: MainDrivingLoop (Part 3 of 5) [Show more] Type: Subroutine Category: Main loop Summary: Main driving loop: Process rejoining the race or lap after a crash Deep dive: Program flow of the main game loop
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
LDA screenSection \ If screenSection is positive, jump to main6 to skip BPL main6 \ the following instruction INC screenSection \ If screenSection is negative, then we increment it \ \ This kickstarts the custom screen interrupt handler \ on the first time round the main driving loop, as the \ call to SetCustomScreen at the start of the routine \ sets screenSection to -2, and this increment bumps it \ up to -1, which makes the screen handler start \ applying the custom screen effect \ \ In other words, this displays the driving screen for \ the first time, after waiting for all the drawing \ routines in part 2 to finish, so we don't get to see \ the screen being drawn .main6 LDA crashedIntoFence \ If crashedIntoFence = 0 then we have not crashed into BEQ main10 \ the fence, so jump to main10 to continue with the main \ driving loop in part 5 INC crashedIntoFence \ Otherwise crashedIntoFence must be &FF, which means we \ have crashed into the fence, so increment it back to \ zero, to clear the "we have crashed" flag \ We now pause for a few seconds, before jumping back to \ the relevant starting point for the loop LDA #156 \ Set irqCounter = 156 STA irqCounter .main7 LDA irqCounter \ Fetch irqCounter, which gets incremented every time \ the IRQ routine reaches section 4 of the custom screen BMI main7 \ Loop back to main7 until irqCounter increments round \ to zero (so we wait for it to go from 156 to 0, which \ takes around three seconds at 50 ticks per second) .main8 LDA qualifyingTime \ If bit 7 of qualifyingTime is set then this is a BMI main1 \ practice lap (i.e. qualifyingTime = 255), so jump back \ to main1 LDA raceStarted \ If bit 7 of raceStarted is clear then this is either BPL main2 \ a practice or qualifying lap, but we didn't just jump \ to main1, so this must be qualifying, so jump back to \ main2 LDA raceClass \ If raceClass = 0 then this is a Novice race, so jump BEQ main3 \ back to main3 \ Otherwise this is an Amateur or a Professional race, \ and not a Novice race, practice or a qualifying lap