Skip to navigation


Main loop: MainLoop (Part 3 of 6)

Name: MainLoop (Part 3 of 6) [Show more] Type: Subroutine Category: Main loop Summary: The main game loop: qualifying laps 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

This part of the main loop gets the players' driver names, and heads to the track for their qualifying laps.
JSR ResetBestLapTimes \ Reset the best lap times to 10:00.0 for all drivers LDA #20 \ Set currentPlayer = 20, so the first human player will STA currentPlayer \ be number 19, the next one will be 18, and so on .game3 DEC currentPlayer \ Decrement currentPlayer so it points to the next human \ player LDX currentPlayer \ Set X to the new player number JSR ResetBestLapTime \ Reset the best lap time to 10:00.0 for the new player LDA competitionStarted \ If competitionStarted = 0, jump to game4 to ask for BEQ game4 \ the player's name, as the competition hasn't started \ yet and we are still running qualifying laps \ If we get here then the competition is in full swing, \ so we need to run qualifying laps for all the human \ players JSR PrintDriverPrompt \ Print the "DRIVER ->" prompt and the player's name JSR HeadToTrack \ Head to the track to choose the wing settings and \ drive the qualifying laps, returning here when the \ laps are finished LDA currentPlayer \ If currentPlayer <> lowestPlayerNumber, then we still CMP lowestPlayerNumber \ have more qualifying laps to get, so jump back to BNE game3 \ game3 for the next player's qualifying laps \ By this point we have all the qualifying times for the \ human players LDA #0 \ Sort the drivers by lap time, putting the results into JSR SortDrivers \ positionNumber and driversInOrder JMP game9 \ Jump down to game9 to print the driver table, showing \ the grid positions for the race .game4 \ If we get here then we need to get the player's name, \ as the competition has not yet started LDX #23 \ Print token 23, which shows the following prompt: JSR PrintToken \ \ ENTER NAME OF DRIVER \ \ and a text prompt: \ \ > \ ------------ JSR GetDriverName \ Fetch the player's name from the keyboard JSR HeadToTrack \ Head to the track to choose the wing settings and \ start the qualifying laps, returning here when the \ laps are finished LDX currentPlayer \ If currentPlayer = 0 then we have got as many players BEQ game5 \ as we can handle (20 of them), so jump to game5 to \ skip asking for another driver LDX #27 \ Print token 27, which shows a menu with the following JSR PrintToken \ options: \ \ 1 = ENTER ANOTHER DRIVER \ \ 2 = START RACE LDX #2 \ Fetch the menu choice into X (0 to 1) JSR GetMenuOption CPX #0 \ If X = 0, then the choice was to enter another driver, BEQ game3 \ so jump back to game3 to add the new player and head \ to the track for their qualifying laps