.FinishRace LDA #0 \ Set playerMoving = 0 to denote that the player's car STA playerMoving \ is stationary STA raceStarting \ Set raceStarting = 0 so the call to MoveCars below \ will move the cars round the track JSR HideAllCars \ Set all the cars to be hidden LDX currentPlayer \ Clear the current player's total race time if this is JSR ClearTotalRaceTime \ an incomplete race .fini1 JSR ProcessTime \ Increment the timers and the main loop counter, and \ set the speed for the next non-player driver LDY #0 \ Check for SHIFT and right arrow JSR ProcessShiftedKeys LDA configStop \ If bit 7 of configStop is set then we must be pressing BMI fini4 \ either SHIFT-f0 for a pit stop or SHIFT and right \ arrow to restart the game, so jump to fini4 to return \ from the subroutine \ If we get here then the race or qualifying lap has \ finished naturally, rather than being aborted, and \ this is not a pit stop \ \ So we now need to keep running the race or qualifying \ lap (albeit with everything hidden from the player) to \ get the final set of results for the whole pack JSR MoveCars \ Move the cars around the track, to keep the race going JSR ProcessOvertaking \ Process overtaking manoeuvres for the non-player \ drivers JSR SetPlayerPositions \ Set the current player's position, plus the position \ ahead and the position behind LDX #19 \ We now loop through the drivers, checking whether they \ have finished the race, so set a loop counter in X for \ the driver number LDA raceStarted \ If bit 7 of raceStarted is set then this is a race BMI fini2 \ rather than practice or qualifying, so jump to fini2 \ to work through the drivers and wait for them all to \ finish the race \ If we get here, then this is a qualifying lap CPX currentPlayer \ If the player is not driver 19, then jump to fini4 to BNE fini4 \ return from the subroutine, as there is more than one \ human player and this is not the first human to race, \ so we already have qualifying times for all the \ drivers \ If we get here, then this is a qualifying lap and the \ current player is driver 19, which means this is \ either the only human player, or the first human to \ race \ \ In any event, we need to make sure that we run the \ qualifying lap long enough to get lap times for all \ the other drivers, so we run the race for at least \ 14 * 256 main loop iterations \ \ This ensures we get lap times for all the drivers, \ even if the player decides to quit qualifying early LDA mainLoopCounterHi \ If the high byte main loop counter < 14, loop back to CMP #14 \ fini1 to keep running the race BCC fini1 RTS \ Return from the subroutine .fini2 \ If we get here, then this is a race rather than \ qualifying LDA objectStatus,X \ If bit 6 of driver X's objectStatus is set, then AND #%01000000 \ driver X has finished the race, so jump to fini3 BNE fini3 \ to check the next driver LDA numberOfLaps \ If numberOfLaps >= driver X's lap number, jump to CMP driverLapNumber,X \ fini1 to keep running the race, as driver X hasn't BCS fini1 \ finished the race yet .fini3 DEX \ Decrement the driver counter in X BPL fini2 \ Loop back until all the drivers have finished the race .fini4 RTS \ Return from the subroutineName: FinishRace [Show more] Type: Subroutine Category: Main loop Summary: Continue running the race until all the non-player drivers have finished and we have a resultContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 4 of 5) calls FinishRace
This routine is beavering away in the background when the game displays the "PLEASE WAIT" message, after we finish qualifying or racing. It keeps running the simulation in the background until all the other drivers have finished their race or qualifying laps.
[X]
Subroutine ClearTotalRaceTime (category: Drivers)
Clear a specified driver's total race time following the end of an incomplete race
[X]
Subroutine HideAllCars (category: Car geometry)
Set all the cars to hidden
[X]
Subroutine MoveCars (Part 1 of 2) (category: Car geometry)
Move the cars around the track
[X]
Subroutine ProcessOvertaking (Part 1 of 3) (category: Tactics)
Process all cars for overtaking manoeuvres, checking first to see if the car has just finished overtaking the car in front
[X]
Subroutine ProcessShiftedKeys (category: Keyboard)
Check for shifted keys (i.e. those that need SHIFT holding down to trigger) and process them accordingly
[X]
Subroutine ProcessTime (category: Main loop)
Increment the timers and the main loop counter
[X]
Subroutine SetPlayerPositions (category: Drivers)
Set the current player's position, plus the positions behind and in front
[X]
Variable configStop in workspace Main variable workspace
A key has been pressed that stops the race
[X]
Variable currentPlayer in workspace Zero page
The number of the current player
[X]
Variable driverLapNumber in workspace Main variable workspace
The current lap number for each driver
[X]
Label fini1 is local to this routine
[X]
Label fini2 is local to this routine
[X]
Label fini3 is local to this routine
[X]
Label fini4 is local to this routine
[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 numberOfLaps in workspace Zero page
The number of laps in the race (5, 10 or 20)
[X]
Variable objectStatus in workspace Stack variables
Various status flags for each object
[X]
Variable playerMoving in workspace Zero page
Flag to denote whether the player's car is moving
[X]
Variable raceStarted in workspace Zero page
Flag determining whether the race has started
[X]
Variable raceStarting in workspace Zero page
The current stage of the starting lights at the start of the race