.game8 LDX raceClass \ Set X to the race class JSR GetSectionSteering \ Set up the optimum steering for each section for this \ race class, storing the results in sectionSteering LDX #26 \ Print token 26, which is a double-height header with JSR PrintToken \ the text "STANDARD OF RACE" JSR PrintRaceClass \ Print the race class JSR WaitForSpace \ Print a prompt and wait for SPACE to be pressed .game9 LDX #2 \ Print the driver table, showing lap times, under the LDA #0 \ heading "GRID POSITIONS", so this shows the drivers JSR PrintDriverTable \ in their starting positions on the grid \ We now make a copy of the driversInOrder list into \ driversInOrder2, so we can retrieve it below, and at \ the same time we set the correct grid row for any \ human players, depending on their starting position \ on the grid (there are two cars per grid row) LDY #19 \ Set up a counter in Y so we can work through the \ drivers in order, from the back of the grid to the \ front .game10 LDA driversInOrder,Y \ Copy the Y-th position from driversInOrder to STA driversInOrder2,Y \ driversInOrder2, setting A to the number of the driver \ in position Y CMP lowestPlayerNumber \ If A < lowestPlayerNumber, then driver A is one of the BCC game11 \ computer-controlled drivers, so jump to game11 to skip \ setting the grid number for the driver \ If we get here then driver A is a human player TAX \ Set X = the player's driver number LDA positionNumber,Y \ Set A = the position of the player on the grid LSR A \ Set the driver's grid row to A / 2, so the first two STA driverGridRow,X \ drivers are on grid row 0, then the next two are on \ grid row 1, and so on .game11 DEY \ Decrement the counter BPL game10 \ Loop back until we have saved all the positions LDA competitionStarted \ If competitionStarted <> 0, then the competition has BNE game12 \ already started, so jump to game12 to skip the lap \ selection process LDX #28 \ Print token 28, which shows a menu with the following JSR PrintToken \ options: \ \ Prompt = SELECT NUMBER OF LAPS \ \ 1 = 5 laps \ \ 2 = 10 laps \ \ 3 = 20 laps LDA #20 \ Set numberOfPlayers = 20 - lowestPlayerNumber SEC \ SBC lowestPlayerNumber \ so numberOfPlayers is 1 if there is one player, 2 if STA numberOfPlayers \ there are two players, and so on LDX #3 \ Fetch the menu choice into X (0 to 2) JSR GetMenuOption LDA lapsFromOption,X \ Convert the menu choice (0 to 2) into the number of STA numberOfLaps \ laps (5, 10, 20) using the lapsFromOption lookup, and \ store the result in numberOfLaps STX lapsMenuOption \ Store the menu choice (0 to 2) in lapsMenuOption .game12 LDA #20 \ We now work our way through the human players so each STA currentPlayer \ one can race in turn, so set currentPlayer to 20 so \ it gets decremented to 19 for the first player .game13 DEC currentPlayer \ Decrement currentPlayer to move on to the next player JSR PrintDriverPrompt \ Print the "DRIVER ->" prompt and the player's name LDX #19 \ We now restore the grid positions we saved above, so \ set a counter in X .game14 LDA driversInOrder2,X \ Restore the X-th position from driversInOrder2 to STA driversInOrder,X \ driversInOrder DEX \ Decrement the counter BPL game14 \ Loop back until we have restored all the positions JSR ResetBestLapTimes \ Reset the best lap times to 10:00.0 for all drivers LDA #%10000000 \ Head to the track to choose the wing settings and JSR HeadToTrack+2 \ start the race (as bit 7 of A is set), returning here \ when the race is finishedName: MainLoop (Part 5 of 6) [Show more] Type: Subroutine Category: Main loop Summary: The main game loop: the competition race Deep dive: Program flow of the main game loopContext: 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 heads to the track to run the actual race. We print the driver table showing the grid positions, and set the grid row for any human drivers. We then start a loop, running a race for each human player, and asking for the number of laps in the race for the first such race. The loop concludes in the next part of the main loop.
[X]
Subroutine GetSectionSteering (category: Tactics)
Calculate the optimum steering for each track section
[X]
Entry point HeadToTrack+2 in subroutine HeadToTrack (category: Main Loop)
Called with A = %10000000 to start a race, as opposed to practice or a qualifying lap
[X]
Subroutine PrintDriverPrompt (category: Text)
Print the "DRIVER ->" prompt and a driver's name, to show whose turn it is next when playing a multi-player game
[X]
Subroutine PrintDriverTable (category: Text)
Print the table of drivers
[X]
Subroutine PrintRaceClass (category: Text)
Print the race class
[X]
Subroutine PrintToken (category: Text)
Print a recursive token
[X]
Subroutine ResetBestLapTimes (category: Drivers)
Reset the best lap times to 10:00.0 for all drivers
[X]
Subroutine WaitForSpace (category: Keyboard)
Print a prompt, wait for the SPACE key to be released, and wait for SPACE to be pressed
[X]
Variable competitionStarted (category: Drivers)
A flag to indicate whether or not the competition has started
[X]
Variable currentPlayer in workspace Zero page
The number of the current player
[X]
Variable driverGridRow in workspace Main variable workspace
The grid row for each driver (0 to 9)
[X]
Variable driversInOrder in workspace Stack variables
A list of driver numbers in order
[X]
Variable driversInOrder2 in workspace Main variable workspace
Used to store a copy of the driversInOrder list
[X]
Label game10 is local to this routine
[X]
Label game11 is local to this routine
[X]
Label game12 is local to this routine
[X]
Label game14 is local to this routine
[X]
Variable lapsFromOption (category: Keyboard)
Table to convert from the option numbers in the laps menu to the actual number of laps
[X]
Variable lowestPlayerNumber (category: Drivers)
The number of the player with the lowest player number
[X]
Variable numberOfLaps in workspace Zero page
The number of laps in the race (5, 10 or 20)
[X]
Variable numberOfPlayers (category: Drivers)
The number of players
[X]
Variable positionNumber in workspace Stack variables
Position numbers to show in the first column of the driver table
[X]
Variable raceClass (category: Drivers)
The class of the current race