Skip to navigation

Revs on the BBC Micro

Main loop: MainLoop (Part 6 of 6)

Name: MainLoop (Part 6 of 6) [Show more] Type: Subroutine Category: Main loop Summary: The main game loop: race points and competition results 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 processes the points from the race and displays the driver tables, and loops back to the previous part if there are more human players in the race. When all the players have raced, we loop back to part 2 for the next race in the championship.
LDA #%10000000 \ Sort the drivers by total race time, putting the JSR SortDrivers \ results into positionNumber and driversInOrder LDX #5 \ We now award points to the top six drivers in the \ race, so set a counter in X .game15 JSR AwardRacePoints \ Award points to the driver in race position X DEX \ Decrement the counter BPL game15 \ Loop back until we have awarded points to the top six \ drivers LDA #0 \ Sort the drivers by best lap time, putting the results JSR SortDrivers \ into positionNumber and driversInOrder LDX #6 \ Award a point to the driver with the fastest lap JSR AwardRacePoints .game16 LDA #%10000000 \ Sort the drivers by total race time, putting the JSR SortDrivers \ results into positionNumber and driversInOrder LDX #1 \ Print the driver table, showing points awarded in the LDA #4 \ last race, under the heading "POINTS", so this shows JSR PrintDriverTable \ the best drivers from the last race, along with the \ points awarded to the fastest six drivers LDA #0 \ Sort the drivers by best lap time, putting the results JSR SortDrivers \ into positionNumber and driversInOrder LDX #6 \ Print the driver table, showing lap times, under the LDA #0 \ heading "BEST LAP TIMES", so this shows the lap times JSR PrintDriverTable \ from the race LDA #%01000000 \ Sort the drivers by accumulated points, putting the JSR SortDrivers \ results into positionNumber and driversInOrder LDX #3 \ Set competitionStarted = 3, which is non-zero, so this STX competitionStarted \ indicates that the competition has started (so we \ don't get asked to choose the number of laps or player \ names) LDA #&88 \ Print the driver table, showing accumulated points, JSR PrintDriverTable \ under the heading "ACCUMULATED POINTS", so this shows \ the cumulative results of all races BIT G \ If bit 7 of G is clear, then RETURN was pressed, so BPL game16 \ jump back to game16 to show the driver tables again LDA currentPlayer \ If currentPlayer <> lowestPlayerNumber, then we still CMP lowestPlayerNumber \ have more players to race, so jump back to game13 to BNE game13 \ start the next player's race JMP game2 \ Jump back to game2 to move on to the next race in the \ competition