Skip to navigation

Revs on the BBC Micro

Text: PrintDriverTable

Name: PrintDriverTable [Show more] Type: Subroutine Category: Text Summary: Print the table of drivers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 5 of 6) calls PrintDriverTable * MainLoop (Part 6 of 6) calls PrintDriverTable

The driver table consists of the following: * A header, as specified by the argument in X * A table with one row for each driver, showing a number, a driver name and a third column as specified by the argument in A * A "PRESS SPACE TO CONTINUE" prompt below the table If the table is being shown after practice or qualifying, the drivers are shown in driver order, from 1 to 20, but if it is shown after a race, the first column shows the numbers from the positionNumber table, the second column shows the drivers in the order that they appear in the driversInOrder list, and the race class is printed above the table. The routine also waits for SPACE or RETURN to be pressed before returning.
Arguments: X The number of the token to print as the header (see PrintHeader for more details): * 1 = "POINTS" * 2 = "GRID POSITIONS" * 3 = "ACCUMULATED POINTS" * 6 = "BEST LAP TIMES" A Defines what to show in the third column in the table: * 0 = lap times * 4 = points awarded in the last race * &88 = accumulated points positionNumber A list of position numbers (for race tables only), which contains the numbers 0 to 19 in sequence, with tied positions represented by shared position numbers
Returns: G Bit 7 is clear if RETURN was pressed, set if SPACE was pressed
.PrintDriverTable PHA \ Store the value of A on the stack so we can retrieve \ it below AND #%00001111 \ Set colourScheme to the lower nibble of A, which STA colourScheme \ contains the colour scheme to use for the table, so we \ can pass it to SetRowColours below JSR PrintHeader \ Print the header specified in X LDY #0 \ We are about to print a table containing 20 rows, one \ for each driver, so set a row counter in Y .dtab1 STY rowCounter \ Store the row counter in rowCounter LDA #%00000000 \ Set G = 0 so the call to Print2DigitBCD below will STA G \ print the second digit and will not print leading \ zeroes when printing the driver number JSR SetRowColours \ Set the colours in token 31 according to the colour \ scheme we stored in colourScheme above, so they can be \ used to set the colours of each table cell LDX #32 \ Print token 32, which prints two spaces and backspaces JSR PrintToken \ followed by token 31, so this sets up the colours for \ the first column LDY rowCounter \ Set Y to the table row number LDA positionNumber,Y \ Set A to the positionNumber for this row, to show in \ the first column BIT raceStarted \ If bit 7 of raceStarted is set, that means the results BMI dtab2 \ are from a finished race, so jump to dtab2 to skip the \ following instruction, so we print the numbers from \ positionNumber in the first column TYA \ Set A to the row number, so we print the row number in \ the first column (i.e. 1 to 20, as ) .dtab2 JSR ConvertNumberToBCD \ Convert the number in A into binary coded decimal \ (BCD), adding 1 in the process JSR Print2DigitBCD \ Print the binary coded decimal (BCD) number in A, and \ because we set G to 0 above, it will print the second \ digit and will not print leading zeroes LDX #31 \ Print token 31, which prints two spaces and sets the JSR PrintToken \ colours as configured above, so this inserts a black \ gap between the first and second table columns LDY rowCounter \ Set Y to the table row number JSR PrintPositionName \ Print the name of the driver in position Y, so row Y \ of the table contains the details of the driver in \ position Y, and set driverPrinted to the number of the \ driver that was printed LDX #31 \ Print token 31, which prints two spaces and sets the JSR PrintToken \ colours as configured above, so this inserts a black \ gap between the second and third table columns LDX driverPrinted \ Set X to the number of the driver we just printed, so \ the call to PrintTimer prints the lap time for driver \ X PLA \ If the value of A that we stored on the stack at the PHA \ start of the routine is non-zero, jump to dtab3 to BNE dtab3 \ skip the following \ If we get here then the value of A passed to the \ routine was 0, so we now print the third column \ containing the driver's best lap time LDA #%00100110 \ Print the lap time for driver X in the following JSR PrintTimer \ 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 JMP dtab6 \ Jump down to dtab6 to move on to the next table row .dtab3 \ If we get here then the value of A passed to the \ routine was non-zero (i.e. 4 or &88) BMI dtab4 \ If bit 7 of A is set (i.e. A = &88), jump to dtab4 \ If we get here then the value of A passed to the \ routine was 4, so we now print the third column \ containing the points awarded to the driver in the \ last race \ \ Only the top six drivers from each race get points, \ so we print a blank column for the other drivers LDA rowCounter \ Set A = rowCounter + 20 CLC ADC #20 CMP #26 \ Set X = A, and if A < 26 (so rowCounter is 0 to 5), TAX \ jump to dtab5 to print the race points BCC dtab5 LDA #7 \ A >= 26 (so rowCounter is 6 to 19), so print seven JSR PrintSpaces \ spaces in the last column BEQ dtab6 \ Jump to dtab6 to move on to the next table row (this \ BEQ is effectively a JMP, as PrintSpaces sets the Z \ flag) .dtab4 \ If we get here then the value of A passed to the \ routine had bit 7 set, so it must have been &88, so \ we now print the third column containing the driver's \ accumulated points LDA #%00101000 \ Set G, so the next three calls to Print2DigitBCD do STA G \ the following: \ \ * No leading zeroes, print second digit \ * Leading zeroes, print second digit \ * Leading zeroes, print second digit \ \ The second and third two calls to Print2DigitBCD are \ in the Print4DigitBCD routine below LDA totalPointsTop,X \ If the top byte of the driver's total points is zero, BEQ dtab5 \ jump to dtab5 JSR Print2DigitBCD \ Otherwise print the top byte of the driver's total \ points, which is a binary coded decimal (BCD) number LDA totalPointsHi,X \ Fetch the high byte of the driver's total points, to \ pass to Print4DigitBCD JSR Print4DigitBCD \ Print both the high and low bytes of the driver's \ total points in full, followed by a space JMP dtab6 \ Jump to dtab6 to move on to the next table row .dtab5 JSR Print234DigitBCD \ Print the high and low bytes of the driver's total \ points, replacing leading zeroes with spaces, and \ followed by a space .dtab6 \ If we get here then we have finished printing the \ current table row, so now we move on to the next row LDY rowCounter \ Set Y to the table row number INY \ Increment the table row number CPY #20 \ Loop back to print the next table row, until we have BNE dtab1 \ printed all 20 LDA #3 \ Print three spaces to pad out the final row JSR PrintSpaces LDA #156 \ Print ASCII 156 to switch to a black background JSR OSWRCH LDA raceStarted \ If bit 7 of raceStarted is clear, that means the BPL dtab7 \ results are from qualifying or practice, so jump to \ dtab7 to skip the following so we do not print the \ race class above the table \ We now print the race class and number of laps in the \ gap between the page header and the top of the table LDX #49 \ Print token 49, which moves the cursor to column 9, JSR PrintToken \ row 2 JSR PrintRaceClass \ Print the race class LDA lapsMenuOption \ Set the configurable token in token 50 to 218 plus the CLC \ figure in lapsMenuOption, to give 218, 219 or 220, ADC #218 \ which correspond to the tokens for " 5", "10" and "20" STA token50+3 LDX #50 \ Print token 50, which is "n laps", where n is the JSR PrintToken \ number of laps we just configured .dtab7 PLA \ Retrieve the value of A that we stored on the stack at \ the start of the routine JSR WaitForSpaceReturn \ Print a prompt and wait for SPACE or RETURN to be \ pressed, depending on bit 7 of A RTS \ Return from the subroutine