| Routines

6E1A: Print a number

Used by the routines at 6E87, 6EB1 and 7058. Computes the ASCII codes for the digits of the number in HL, stores them in the buffer at 7FCA, and then prints them.
Input
DE | Display file address
HL | Number to print
6E1A | PUSH DE | Save the display file address
6E1B | EX DE,HL | Transfer the number to print to DE
6E1C | LD HL,$7FCF | Fill the number string buffer at 7FCA with space characters
6E1F | LD B,$05
6E21 | DEC L
6E22 | LD (HL),$20
6E24 | DJNZ $6E21
6E26 | LD A,$30 | 0x30 is the ASCII code for the digit '0'
6E28 | LD BC,$D8F0 | BC=-10000
6E2B | EX DE,HL | Transfer the number to print to HL
6E2C | ADD HL,BC | Is HL>=10000?
6E2D | JR C,$6E4B | Jump if so to compute and store the 10000s digit
6E2F | INC E | Point DE at the slot for the 1000s digit in the number string buffer
6E30 | SBC HL,BC | Add the 10000 back
6E32 | LD BC,$FC18 | BC=-1000
6E35 | ADD HL,BC | Is HL>=1000?
6E36 | JR C,$6E58 | Jump if so to compute and store the 1000s digit
6E38 | INC E | Point DE at the slot for the 100s digit in the number string buffer
6E39 | SBC HL,BC | Add the 1000 back
6E3B | LD BC,$FF9C | BC=-100
6E3E | ADD HL,BC | Is HL>=100?
6E3F | JR C,$6E65 | Jump if so to compute and store the 100s digit
6E41 | INC E | Point DE at the slot for the 10s digit in the number string buffer
6E42 | SBC HL,BC | Add the 100 back
6E44 | LD C,$F6 | BC=-10
6E46 | ADD HL,BC | Is HL>=10?
6E47 | JR C,$6E71 | Jump if so to compute and store the 10s digit
6E49 | JR $6E78 | Jump forward to compute and store the units digit
Compute and store the 10000s digit.
6E4B | INC A | Get the ASCII code for the 10000s digit in A
6E4C | ADD HL,BC
6E4D | JR C,$6E4B
6E4F | LD (DE),A | Place the 10000s digit into the number string buffer
6E50 | SBC HL,BC |
6E52 | INC E | Point DE at the slot for the 1000s digit
6E53 | LD A,$2F |
6E55 | LD BC,$FC18 | BC=-1000
Compute and store the 1000s digit.
6E58 | INC A | Get the ASCII code for the 1000s digit in A
6E59 | ADD HL,BC
6E5A | JR C,$6E58
6E5C | LD (DE),A | Place the 1000s digit into the number string buffer
6E5D | LD A,$2F |
6E5F | SBC HL,BC |
6E61 | LD BC,$FF9C | BC=-100
6E64 | INC E | Point DE at the slot for the 100s digit
Compute and store the 100s digit.
6E65 | INC A | Get the ASCII code for the 100s digit in A
6E66 | ADD HL,BC
6E67 | JR C,$6E65
6E69 | LD (DE),A | Place the 100s digit into the number string buffer
6E6A | LD A,$2F |
6E6C | SBC HL,BC |
6E6E | LD C,$F6 | BC=-10
6E70 | INC E | Point DE at the slot for the 10s digit
Compute and store the 10s digit.
6E71 | INC A | Get the ASCII code for the 10s digit in A
6E72 | ADD HL,BC
6E73 | JR C,$6E71
6E75 | LD (DE),A | Place the 10s digit into the number string buffer
6E76 | LD A,$30 |
Compute and store the units digit.
6E78 | SBC HL,BC |
6E7A | INC E | Point DE at the slot for the units digit
6E7B | ADD A,L | A=ASCII code for the units digit
6E7C | LD (DE),A | Place it into the number string buffer
The number string buffer is now ready.
6E7D | LD E,$CA | DE=7FCA (start of the number string buffer)
6E7F | POP HL | Restore the display file address to HL
6E80 | EX DE,HL | Transfer it to DE, and point HL at the number string buffer at 7FCA
6E81 | JP $6E00 | Print the number