.UpdateLapTimers LDA raceStarted \ If bit 7 of raceStarted is clear then this is either BPL laps2 \ a practice or qualifying lap, so jump to laps2 to \ update the lap timers for qualifying \ If we get here then this is a race lap BIT updateDrivingInfo \ If bit 7 of updateDrivingInfo is clear then we do not BPL laps1 \ need to update the lap number, so jump to laps1 to \ skip straight to updating the driver positions LDA #%00000000 \ Clear bits 6 and 7 of updateDrivingInfo so we don't STA updateDrivingInfo \ update the number of laps again until the value of \ updateDrivingInfo changes to indicate that we should STA G \ Set G = 0 so the call to Print2DigitBCD below will \ print the second digit and will not print leading \ zeroes when printing the number of laps LDX currentPlayer \ Set X to the driver number of the current player LDA driverLapNumber,X \ Set A to the current lap number for the current player CMP #1 \ If A >= 1, set the C flag, otherwise clear it EOR #&FF \ Set A = numberOfLaps + ~A + C ADC numberOfLaps \ = numberOfLaps - A if A >= 1 \ = numberOfLaps - 1 if A = 0 PHP \ Store the resulting flags on the stack JSR ConvertNumberToBCD \ Convert the number in A into binary coded decimal \ (BCD), adding 1 in the process LDX #12 \ Print the number in A at column 12, pixel row 33, on LDY #33 \ the second text line at the top of the screen JSR Print2DigitBCD-6 PLP \ If the result of the above addition was positive, jump BPL laps1 \ to laps1 to skip printing the finished message LDX #53 \ Blank out the first text line at the top of the screen JSR PrintSecondLineGap \ and print token 53 on the second line, to give: \ \ " " \ " FINISHED " .laps1 LDA leaveTrackTimer \ If leaveTrackTimer is non-zero then the leave track BNE laps8 \ timer is counting down, so jump to laps8 to return \ from the subroutine without updating the text at the \ top of the screen JSR UpdatePositionInfo \ Otherwise update the position number and driver names \ at the top of the screen RTS \ Return from the subroutine .laps2 \ If we get here then this is a practice or qualifying \ lap LDX #1 \ Add time to the lap timer at (lapMinutes lapSeconds JSR AddTimeToTimer \ lapTenths), setting the C flag if the time has changed BIT updateDrivingInfo \ If bit 6 of updateDrivingInfo is set then we have BVS laps4 \ started the first lap, so jump to laps4 to skip the \ following and print the lap time only (we make the \ jump with the C flag indicating whether the timer has \ changed) BPL laps6 \ If bit 7 of updateDrivingInfo is clear then we do not \ need to update the lap time, so jump to laps6 to skip \ the following \ If we get here then we have started the first lap of \ practice or qualifying and we need to print the lap \ time LSR updateDrivingInfo \ Bit 7 of updateDrivingInfo is set and bit 6 is clear, \ so clear bit 7 and set bit 6 of updateDrivingInfo to \ indicate that we are now driving the first lap LDA #33 \ Set firstLapStarted = firstLapStarted + 33 CLC \ ADC firstLapStarted \ So if we have just started the first lap, then this STA firstLapStarted \ changes firstLapStarted from -33 to 0 BEQ laps3 \ If A = 0, then we just started the first qualifying or \ practice lap, so jump to laps3 to skip the following \ two instructions \ I am not sure if we ever get here, as the current lap \ time is never printed with tenths of a second LDA #%00100110 \ Print the current lap time at the top of the screen in JSR PrintLapTime+2 \ the following format: \ \ * %00 Minutes: No leading zeroes, print both digits \ * %10 Seconds: Leading zeroes, print both digits \ * %0 Tenths: Print tenths of a second \ * %11 Tenths: Leading zeroes, no second digit .laps3 LDX #1 \ Zero the lap timer JSR ZeroTimer BEQ laps6 \ Jump to laps6 (this BNE is effectively a JMP as the \ ZeroTimer routine sets the Z flag) .laps4 \ If we get here, then the C flag indicates whether the \ lap timer at (lapMinutes lapSeconds lapTenths) has \ changed LDA firstLapStarted \ If firstLapStarted = 0 then we are currently driving BEQ laps5 \ the first qualifying or practice lap, so jump to laps5 \ to print the current lap time, but not the best lap \ time (as we haven't completed a lap yet) \ \ We jump with the C flag indicating whether the timer \ has changed DEC firstLapStarted \ Decrement firstLapStarted BNE laps6 \ If firstLapStarted is non-zero, jump to laps6 to skip \ printing any lap times JSR PrintBestLapTime \ Print the best lap time and the current lap time at \ the top of the screen LDA #2 \ Print two spaces JSR PrintSpaces BEQ laps6 \ Jump to laps6 to skip the following (this BEQ is \ effectively a JMP, as PrintSpaces sets the Z flag) .laps5 \ If we get here, then the C flag indicates whether the \ lap timer at (lapMinutes lapSeconds lapTenths) has \ changed BCC laps6 \ If the C flag is clear then the timer has not changed, \ so jump to laps6 to skip the following instruction JSR PrintLapTime \ Print the current lap time at the top of the screen in \ the following format: \ \ * Minutes: No leading zeroes, print both digits \ * Seconds: Leading zeroes, print both digits \ * Tenths: Do not print tenths of a second .laps6 LDA qualifyingTime \ If bit 7 of qualifyingTime is set then this is a BMI laps8 \ practice lap (i.e. qualifyingTime = 255), so jump to \ laps8 to return from the subroutine \ If we get here then this is a qualifying lap, and the \ number of minutes of qualifying lap time is in A, as \ follows: \ \ * A = 4 indicates 5 minutes of qualifying time \ \ * A = 9 indicates 10 minutes of qualifying time \ \ * A = 25 indicates 26 minutes of qualifying time CMP clockMinutes \ If A < clockMinutes then we have reached the end of BCC laps7 \ qualifying time, so jump to laps7 to display the \ time-up message BNE laps8 \ If A <> clockMinutes, i.e. A > clockMinutes, then \ there is still some qualifying time left, so jump to \ laps8 to return from the subroutine BIT qualifyTimeEnding \ If bit 6 of qualifyTimeEnding is set, then we have BVS laps8 \ already displayed the one-minute warning, so jump to \ laps8 to return from the subroutine LDA #%01000000 \ Set bit 6 of qualifyTimeEnding to indicate that the STA qualifyTimeEnding \ one-minute warning has been displayed LDX #41 \ Print token 41 on the first text line at the top of JSR PrintFirstLine \ the screen, to give: \ \ " Less than one minute to go " RTS \ Return from the subroutine .laps7 LDA qualifyTimeEnding \ If bit 7 of qualifyTimeEnding is set, then we have BMI laps8 \ already displayed the time-up message, so jump to \ laps8 to return from the subroutine LDA #%11000000 \ Set bits of 6 and 7 of qualifyTimeEnding to indicate STA qualifyTimeEnding \ that we have displayed both the one-minute warning and \ the time-up message LDA #60 \ Set leaveTrackTimer = 60, so we leave the track in 60 STA leaveTrackTimer \ main loop iterations and return to the game menu LDX #42 \ Print token 42 on the first text line at the top of JSR PrintFirstLine \ the screen, to give: \ \ " YOUR TIME IS UP! " .laps8 RTS \ Return from the subroutineName: UpdateLapTimers [Show more] Type: Subroutine Category: Drivers Summary: Update the lap timers and display timer-related messages at the top of the screenContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls UpdateLapTimers
[X]
Subroutine AddTimeToTimer (category: Drivers)
Add time to the specified timer
[X]
Subroutine ConvertNumberToBCD (category: Maths (Arithmetic))
Convert a number into binary coded decimal (BCD), for printing
[X]
Entry point Print2DigitBCD-6 in subroutine Print2DigitBCD (category: Text)
Print the number at screen coordinate (X, Y), where X is the character column and Y is the pixel row of the bottom of the character
[X]
Subroutine PrintBestLapTime (category: Text)
Print the best lap time and the current lap time at the top of the screen
[X]
Subroutine PrintFirstLine (category: Text)
Prints a text token on the first text line at the top of the driving screen
[X]
Subroutine PrintLapTime (category: Text)
Print the current lap time at the top of the screen
[X]
Entry point PrintLapTime+2 in subroutine PrintLapTime (category: Text)
Format the lap time using the format value in A (see PrintTimer for details)
[X]
Subroutine PrintSecondLineGap (category: Text)
Prints a text token on the second text line at the top of the driving screen, with an empty gap on the line above
[X]
Subroutine PrintSpaces (category: Text)
Print the specified number of spaces
[X]
Subroutine UpdatePositionInfo (category: Text)
Apply any position changes and update the position information at the top of the screen
[X]
Subroutine ZeroTimer (category: Drivers)
Zero the specified timer
[X]
Variable clockMinutes in workspace Main variable workspace
Minutes for the clock timer
[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]
Variable firstLapStarted (category: Drivers)
Flag to keep track of whether we have started the first lap of practice or qualifying
[X]
Label laps1 is local to this routine
[X]
Label laps2 is local to this routine
[X]
Label laps3 is local to this routine
[X]
Label laps4 is local to this routine
[X]
Label laps5 is local to this routine
[X]
Label laps6 is local to this routine
[X]
Label laps7 is local to this routine
[X]
Label laps8 is local to this routine
[X]
Variable leaveTrackTimer in workspace Zero page
The leave track timer
[X]
Variable numberOfLaps in workspace Zero page
The number of laps in the race (5, 10 or 20)
[X]
Variable qualifyTimeEnding in workspace Zero page
Determines whether the time warnings have been shown at the end of the qualifying time
[X]
Variable qualifyingTime (category: Drivers)
The number of minutes of qualifying lap time
[X]
Variable raceStarted in workspace Zero page
Flag determining whether the race has started
[X]
Variable updateDrivingInfo in workspace Zero page
Determines which parts of the driving information should be updated at the top of the screen