Routines

27572: Derive decimal digits of value in DE


Used by routines at 29613 and 29716

DE Value (score/lines/hi-score)

27572 210BE3 LD HL,58123
27575 45 LD B,L B=11
27576 2D DEC L Clear 58112 to 58122
27577 3600 LD (HL),0
27579 10FB DJNZ 27576
27581 3E30 LD A,48 48 is the character code for '0'
27583 01F0D8 LD BC,55536 BC=–10000
27586 EB EX DE,HL
27587 09 ADD HL,BC Subtract 10000
27588 381E JR C,27620 Jump if it "went"
27590 ED42 SBC HL,BC Otherwise add the 10000 back
27592 0118FC LD BC,64536 BC=–1000
27595 09 ADD HL,BC Subtract 1000
27596 3823 JR C,27633 Jump if it "went"
27598 ED42 SBC HL,BC Otherwise add the 1000 back
27600 019CFF LD BC,65436 BC=–100
27603 09 ADD HL,BC Subtract 100
27604 3828 JR C,27646 Jump if it "went"
27606 ED42 SBC HL,BC Otherwise add the 100 back
27608 0EF6 LD C,246 BC=–10
27610 09 ADD HL,BC Subtract 10
27611 382D JR C,27658 Jump if it "went"
27613 ED42 SBC HL,BC Otherwise add the 10 back
27615 7D LD A,L A=units left
27616 A7 AND A Are there any?
27617 C8 RET Z Return if not
27618 182E JR 27666
27620 3C INC A Get the character code for the 10000s digit in A
27621 09 ADD HL,BC
27622 38FC JR C,27620
27624 ED42 SBC HL,BC
27626 0118FC LD BC,64536 BC=–1000
27629 12 LD (DE),A Place the 10000s digit in 58112
27630 3E2F LD A,47
27632 1C INC E DE=58113
27633 3C INC A Get the character code for the 1000s digit in A
27634 09 ADD HL,BC
27635 38FC JR C,27633
27637 ED42 SBC HL,BC
27639 019CFF LD BC,65436 BC=–100
27642 12 LD (DE),A Place the 1000s digit in 58113
27643 3E2F LD A,47
27645 1C INC E DE=58114
27646 3C INC A Get the character code for the 100s digit in A
27647 09 ADD HL,BC
27648 38FC JR C,27646
27650 ED42 SBC HL,BC
27652 12 LD (DE),A Place the 100s digit in 58114
27653 0EF6 LD C,246 BC=–10
27655 3E2F LD A,47
27657 1C INC E DE=58115
27658 3C INC A Get the character for the 10s digit in A
27659 09 ADD HL,BC
27660 38FC JR C,27658
27662 ED42 SBC HL,BC
27664 12 LD (DE),A Place the 10s digit in 58115
27665 1C INC E DE=58116
27666 7D LD A,L A=number of units left
27667 C630 ADD A,48 A=character code for number of units
27669 12 LD (DE),A Place this in 58116
27670 C9 RET