Skip to navigation

Revs on the BBC Micro

Text: Print2DigitBCD

Name: Print2DigitBCD [Show more] Type: Subroutine Category: Text Summary: Print a binary coded decimal (BCD) number in the specified format
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * Print4DigitBCD calls Print2DigitBCD * PrintDriverTable calls Print2DigitBCD * PrintTimer calls Print2DigitBCD * UpdateLapTimers calls entry point Print2DigitBCD-6 * UpdatePositionInfo calls entry point Print2DigitBCD-6

Arguments: A The number to print (in BCD) G Flags to control how the number is printed: * Bit 7: clear = do not print leading zeroes set = print leading zeroes * Bit 6: clear = print second digit set = do not print second digit Returns: G G is shifted left by two places, so bits 4 and 5 will be used to determine the printing style in the next call to Print2DigitBCD Other entry points: Print2DigitBCD-6 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
STX xCursor \ Set the cursor to (X, Y), so we print the number at STY yCursor \ the specified screen location .Print2DigitBCD PHA \ Store A on the stack so we can retrieve it later LSR A \ Shift the high nibble of A into bits 0-3, so A LSR A \ contains the first digit of the BCD number LSR A LSR A BNE pnum1 \ If the result is non-zero, jump to pnum1 to print the \ digit in A \ Otherwise the first digit is a zero, which we either \ print as a capital "O" (so it doesn't have a line \ through it), or as a space, depending on the setting \ in G, which controls whether or not to print leading \ zeroes LDA #'O'-'0' \ Set A so we print a capital "O" in pnum1 BIT G \ If bit 7 of G is set, jump to pnum1 to print a capital BMI pnum1 \ "O" LDA #LO(' '-'0') \ Otherwise bit 7 of G is clear and we do not print \ leading zeroes, so instead set A so we print a space \ in pnum1 .pnum1 CLC \ Print the high nibble in A as a digit (or, if the high ADC #'0' \ nibble is zero, print a capitel "O" or a space, as per JSR PrintCharacter \ the above) \ Now for the second digit ASL G \ Shift G to the left, so bit 6 is now in bit 7 PLA \ Retrieve the original value of A, which contains the \ BCD number to print ASL G \ If bit 7 of G is set (i.e. bit 6 of the original G), BCS pnum3 \ jump to pnum3 to skip printing the second digit, and \ return from the subroutine AND #%00001111 \ Extract the low nibble of the BCD number into A BNE pnum2 \ If the low nibble is non-zero, jump to pnum2 to skip \ the following instruction LDA #'O'-'0' \ Set A so we print a capital "O" in pnum2 .pnum2 CLC \ Print the low nibble in A as a digit (or, if the low ADC #'0' \ nibble is zero, print a capital "O") JSR PrintCharacter .pnum3 RTS \ Return from the subroutine EQUB &FF \ This byte appears to be unused