Prev: C38D Up: Map Next: CB0A
CAB3: Print Numbers
Used by the routines at Print_HighScoreTable, Messaging_GameOver and Print_Bonus.
Input
B Number of characters to print
DE Screen buffer pointer
HL Pointer to end of number string data
PrintNumbers CAB3 LD A,$00 A=00.
CAB5 RLD Extract the first digit into A.
CAB7 PUSH AF Stash the result on the stack.
CAB8 CP $00 Jump to PrintNumbers_BigNumber if A is not 00.
CABA JR NZ,PrintNumbers_BigNumber
The highest digit is zero, so instead of printing an ASCII zero, print an ASCII space character instead.
CABC LD A,$20 A=ASCII "space" character (20).
CABE CALL PrintNumbers_Print Call PrintNumbers_Print.
Move onto the next digit extraction.
CAC1 POP AF Restore AF from the stack.
CAC2 RLD Extract the next digit into A.
CAC4 PUSH AF Stash the result on the stack.
CAC5 CP $00 Jump to PrintNumbers_LittleNumber if A is not 00.
CAC7 JR NZ,PrintNumbers_LittleNumber
The next digit is also zero, so again print an ASCII space character.
CAC9 LD A,$20 A=ASCII "space" character (20).
CACB CALL PrintNumbers_Print Call PrintNumbers_Print.
Housekeeping, and loop control.
CACE POP AF Restore AF from the stack.
CACF RLD Restore the original byte value back to *HL.
CAD1 DEC HL Decrease the string pointer by one - move to the next number character.
CAD2 DJNZ PrintNumbers Decrease the length counter by one and loop back to PrintNumbers until the counter is zero.
CAD4 RET Return.
Note; the above doesn't jump straight to this, as it's already processing the first RLD result.
PrintNumbers_Loop CAD5 LD A,$00 A=00.
CAD7 RLD Extract the first digit into A.
CAD9 PUSH AF Stash the result on the stack.
PrintNumbers_BigNumber CADA ADD A,$30 A contains the number character to be printed - add ASCII zero to it (30).
CADC CALL PrintNumbers_Print Call PrintNumbers_Print.
CADF POP AF Restore AF from the stack.
CAE0 RLD Extract the next digit into A.
CAE2 PUSH AF Stash the result on the stack.
PrintNumbers_LittleNumber CAE3 ADD A,$30 A contains the number character to be printed - add ASCII zero to it (30).
CAE5 CALL PrintNumbers_Print Call PrintNumbers_Print.
CAE8 POP AF Restore AF from the stack.
CAE9 RLD Restore the original byte value back to *HL.
CAEB DEC HL Decrease the string pointer by one - move to the next number character.
CAEC DJNZ PrintNumbers_Loop Decrease the length counter by one and loop back to PrintNumbers_Loop until the counter is zero.
CAEE RET Return.
This is similar in functionality to PrintString. It differs as it doesn't use a terminator rather the length is known.
PrintNumbers_Print CAEF PUSH HL Stash pointer to the string and the length counter on the stack.
CAF0 PUSH BC
Create an offset in HL using A - which contains the number value we want to print.
CAF1 LD L,A HL=A*$08 (as each font character is made up of 8 bytes).
CAF2 LD H,$00
CAF4 ADD HL,HL
CAF5 ADD HL,HL
CAF6 ADD HL,HL
CAF7 LD BC,$E417 BC=Font.
CAFA DEC B Decrease B by one.
CAFB ADD HL,BC HL+=BC.
CAFC PUSH DE Stash the current screen buffer pointer on the stack.
CAFD LD B,$08 B=08 (because each font character is 8 bytes).
PrintNumbers_Print_Loop CAFF LD A,(HL) Fetch a byte from the custom font.
CB00 LD (DE),A Write the byte to the screen buffer.
CB01 INC HL Move onto the next byte of the custom font.
CB02 INC D Adjust the screen buffer position down one row.
CB03 DJNZ PrintNumbers_Print_Loop Decrease the byte counter by one and loop back to PrintNumbers_Print_Loop until the counter is zero (all 8 bytes have been copied to the screen buffer).
CB05 POP DE Restore the original screen buffer pointer from the stack.
CB06 INC DE Move the screen buffer pointer right one character block ready for printing the next character.
CB07 POP BC Restore the length counter and pointer to the string from the stack.
CB08 POP HL
CB09 RET Return.
Prev: C38D Up: Map Next: CB0A