Prev: B5FA Up: Map Next: B72D
B6F5: Print a number
Used by the routines at B140 and B2D2.
Input
HL The screen address to print
A The number to print
B6F5 PUSH HL Remember this
B6F6 LD B,$08 8 bits to check
B6F8 LD HL,$0001 Set value to increment next bit to 1
B6FB LD DE,$0000 Set evaluated value to 0
B6FE LD C,A Put working copy of number in C
B6FF SRL C Get the next bit
B701 JR NC,$B70B Move on if it is not set
B703 LD A,L Get low value to increment by
B704 ADD A,E Add this to the current value
B705 DAA Adjust for base 10
B706 LD E,A Set it
B707 LD A,H Get high value to increment by
B708 ADC A,D Add this to the current value (including carry)
B709 DAA Adjust for base 10
B70A LD D,A Set it
B70B LD A,L Get low value to increment
B70C ADD A,L Double it so that next bit gets the appropriate value added
B70D DAA Adjust to base 10
B70E LD L,A Set it
B70F LD A,H Get low value to increment
B710 ADC A,H Double it (including carry)
B711 DAA Adjust to base 10
B712 LD H,A Set it
B713 DJNZ $B6FF Loop if there are more bits to do
B715 POP HL Restore HL
At this point, DE contains three digits of an 8-bit number in D, bits 4-7 of E and bits 0-3 of E
B716 LD A,D Get the high value
B717 AND A Is it > 0?
B718 CALL NZ,$B72B If it isn't, print digit
B71B LD A,E Get the low value
B71C AND $F0 Get the top bits
B71E CALL NZ,$B727 If any are set, print digit
B721 LD A,E Get the low value
B722 AND $0F Get the bottom bits
B724 JP $B72B This always needs printing, so do it
B727 RRCA Shift the top bits in the low value to match a printable number
B728 RRCA
B729 RRCA
B72A RRCA
B72B ADD A,$30 Convert number to ASCII - control then continues to B72D
Prev: B5FA Up: Map Next: B72D