Skip to navigation

Revs on the BBC Micro

Main loop: MainLoop (Part 5 of 6)

Name: 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 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 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.
.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 finished