Prev: A3C8 Up: Map Next: A46A
A402: Convert a number into a list of digits charcodes
Computes the charcode of the number in HL and puts every digit charcode into $A0A6-$A0AA (in reverse order) $A0A6 units, $A0A7 tens, $A0A8 hundreds, $A0A9 thousands and $A0AA ten thousands Used by the routines at 99AB, 99BB, 99FA, 9C76 and A7CE.
Input
HL Number to convert
A402 PUSH IX Save IX
A404 LD ($A0A4),HL Save the number in $A0A4
A407 XOR A Set A=0
A408 LD ($A0AA),A Init the charcode buffer
A40B LD ($A0A9),A
A40E LD ($A0A8),A
A411 LD ($A0A7),A
A414 LD ($A0A6),A
A417 LD DE,$2710 Set DE=10.000
A41A CALL $A447 Computes the charcode for the digit in the ten thousands
A41D LD ($A0AA),A Set this charcode into $A0AA
A420 LD DE,$03E8 Set DE=1.000
A423 CALL $A447 Computes the charcode for the digit in the thousands
A426 LD ($A0A9),A Set this charcode into $A0A9
A429 LD DE,$0064 Set DE=100
A42C CALL $A447 Computes the charcode for the digit in the hundreds
A42F LD ($A0A8),A Set this charcode into $A0A8
A432 LD DE,$000A Set DE=10
A435 CALL $A447 Computes the charcode for the digit in the tens
A438 LD ($A0A7),A Set this charcode into $A0A7
A43B LD DE,$0001 Set DE=1
A43E CALL $A447 Computes the charcode for the digit in the units
A441 LD ($A0A6),A Set this charcode into $A0A6
A444 POP IX Restore IX
A446 RET
Computes the charcode for the digit in the units, tens, hundreds, thousands o ten toushands
A447 LD HL,($A0A4) Set HL to the number to convert
A44A LD IX,$0000 Set IX=0. The part of the number that has been converted [ x0.000, x.000, x00, x0 or x }
A44E LD B,$00 Set B=0. The digit number that we need to convert to charcode [x]
A450 AND A Reset carry bit
A451 SBC HL,DE Substract DE [10.000, 1.000, 100, 10 or 1] to HL
A453 JR C,$A45A Jump if the result in HL is a negative number (DE is greater than the number to convert)
A455 ADD IX,DE Add DE to IX
A457 INC B Increment the digit number
A458 JR $A450 Jump back and repeat the process until obtain the digit number
A45A PUSH IX Copy in DE the value of IX
A45C POP DE
A45D LD HL,($A0A4) Set HL to the number to convert
A460 AND A Reset carry bit
A461 SBC HL,DE Substract to the number to convert the part just converted
A463 LD ($A0A4),HL Set into $A0A4 the remaining number to convert
A466 LD A,B Copy into A the digit number to convert
A467 ADD A,$30 Set A to the charcode of the digit ($30 is the base charcode for digit, i.e. is the 0 digit charcode)
A469 RET
Prev: A3C8 Up: Map Next: A46A