Skip to navigation

Revs on the BBC Micro

Drivers: UpdateLapTimers

Name: UpdateLapTimers [Show more] Type: Subroutine Category: Drivers Summary: Update the lap timers and display timer-related messages at the top of the screen
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls UpdateLapTimers
.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 subroutine