| Routines

6BB4: Compute the decimal digits of a number

Used by the routines at 73AD and 7414. Computes the ASCII codes for the digits of the number held in DE, and stores them in the buffer at E300.
Input
DE | Number
6BB4 | LD HL,$E30B |
6BB7 | LD B,L | B=11
6BB8 | DEC L | Clear the buffer at E300, which will be used to store the ASCII codes of the digits
6BB9 | LD (HL),$00
6BBB | DJNZ $6BB8
6BBD | LD A,$30 | 0x30 is the code for '0'
Before inserting any ASCII codes into the buffer, we need to figure out whether the first digit is the 10000s, 1000s, 100s, 10s or units digit.
6BBF | LD BC,$D8F0 | BC=-10000
6BC2 | EX DE,HL | DE=E300
6BC3 | ADD HL,BC | Subtract 10000
6BC4 | JR C,$6BE4 | Jump if it 'went'
6BC6 | SBC HL,BC | Otherwise add the 10000 back
6BC8 | LD BC,$FC18 | BC=-1000
6BCB | ADD HL,BC | Subtract 1000
6BCC | JR C,$6BF1 | Jump if it 'went'
6BCE | SBC HL,BC | Otherwise add the 1000 back
6BD0 | LD BC,$FF9C | BC=-100
6BD3 | ADD HL,BC | Subtract 100
6BD4 | JR C,$6BFE | Jump if it 'went'
6BD6 | SBC HL,BC | Otherwise add the 100 back
6BD8 | LD C,$F6 | BC=-10
6BDA | ADD HL,BC | Subtract 10
6BDB | JR C,$6C0A | Jump if it 'went'
6BDD | SBC HL,BC | Otherwise add the 10 back
6BDF | LD A,L | A=units left
6BE0 | AND A | Are there any?
6BE1 | RET Z | Return if not (nothing to do)
6BE2 | JR $6C12 | Jump forward to place the units digit into the buffer
Compute and insert the 10000s digit.
6BE4 | INC A | Get the ASCII code for the 10000s digit in A
6BE5 | ADD HL,BC
6BE6 | JR C,$6BE4
6BE8 | SBC HL,BC |
6BEA | LD BC,$FC18 | BC=-1000
6BED | LD (DE),A | Place the 10000s digit into the buffer
6BEE | LD A,$2F |
6BF0 | INC E | Move DE along to the next slot in the buffer
Compute and insert the 1000s digit.
6BF1 | INC A | Get the ASCII code for the 1000s digit in A
6BF2 | ADD HL,BC
6BF3 | JR C,$6BF1
6BF5 | SBC HL,BC |
6BF7 | LD BC,$FF9C | BC=-100
6BFA | LD (DE),A | Place the 1000s digit into the buffer
6BFB | LD A,$2F |
6BFD | INC E | Move DE along to the next slot in the buffer
Compute and insert the 100s digit.
6BFE | INC A | Get the ASCII code for the 100s digit in A
6BFF | ADD HL,BC
6C00 | JR C,$6BFE
6C02 | SBC HL,BC |
6C04 | LD (DE),A | Place the 100s digit into the buffer
6C05 | LD C,$F6 | BC=-10
6C07 | LD A,$2F |
6C09 | INC E | Move DE along to the next slot in the buffer
Compute and insert the 10s digit.
6C0A | INC A | Get the ASCII code for the 10s digit in A
6C0B | ADD HL,BC
6C0C | JR C,$6C0A
6C0E | SBC HL,BC |
6C10 | LD (DE),A | Place the 10s digit into the buffer
6C11 | INC E | Move DE along to the next slot in the buffer
Compute and insert the units digit.
6C12 | LD A,L | A=number of units left
6C13 | ADD A,$30 | A=ASCII code for the units digit
6C15 | LD (DE),A | Place this into the buffer
6C16 | RET |