2018-06-24 07:09:41 -07:00
|
|
|
_PrintNum::
|
2016-03-27 09:47:28 -07:00
|
|
|
; Print c digits of the b-byte value from de to hl.
|
|
|
|
; Allows 2 to 7 digits. For 1-digit numbers, add
|
|
|
|
; the value to char "0" instead of calling PrintNum.
|
2019-06-09 08:46:06 -07:00
|
|
|
; The high nybble of the c register specifies how many of the total amount of
|
|
|
|
; digits will be in front of the decimal point.
|
2016-03-27 09:47:28 -07:00
|
|
|
; Some extra flags can be given in bits 5-7 of b.
|
2023-09-02 14:16:35 -07:00
|
|
|
; Bit 5: coins if set (unless left-aligned without leading zeros)
|
2019-11-03 11:47:06 -08:00
|
|
|
; Bit 6: left-aligned if set
|
2016-03-27 09:47:28 -07:00
|
|
|
; Bit 7: print leading zeros if set
|
|
|
|
|
|
|
|
push bc
|
|
|
|
|
|
|
|
bit 5, b
|
|
|
|
jr z, .main
|
|
|
|
bit 7, b
|
2023-09-02 14:16:35 -07:00
|
|
|
jr nz, .coinsflag
|
2016-03-27 09:47:28 -07:00
|
|
|
bit 6, b
|
|
|
|
jr z, .main
|
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
.coinsflag ; 101xxxxx or 011xxxxx
|
2023-09-02 09:54:27 -07:00
|
|
|
ld a, "<COIN>"
|
2016-03-27 09:47:28 -07:00
|
|
|
ld [hli], a
|
|
|
|
res 5, b ; 100xxxxx or 010xxxxx
|
|
|
|
|
|
|
|
.main
|
|
|
|
xor a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
|
|
|
ldh [hPrintNumBuffer + 1], a
|
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 09:47:28 -07:00
|
|
|
ld a, b
|
|
|
|
and $f
|
|
|
|
cp 1
|
|
|
|
jr z, .byte
|
|
|
|
cp 2
|
|
|
|
jr z, .word
|
|
|
|
; maximum 3 bytes
|
|
|
|
ld a, [de]
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
2016-03-27 09:47:28 -07:00
|
|
|
inc de
|
|
|
|
ld a, [de]
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 09:47:28 -07:00
|
|
|
inc de
|
|
|
|
ld a, [de]
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 09:47:28 -07:00
|
|
|
jr .start
|
|
|
|
|
|
|
|
.word
|
|
|
|
ld a, [de]
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 09:47:28 -07:00
|
|
|
inc de
|
|
|
|
ld a, [de]
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 09:47:28 -07:00
|
|
|
jr .start
|
|
|
|
|
|
|
|
.byte
|
|
|
|
ld a, [de]
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 09:47:28 -07:00
|
|
|
|
|
|
|
.start
|
|
|
|
push de
|
|
|
|
|
|
|
|
ld d, b
|
|
|
|
ld a, c
|
|
|
|
swap a
|
|
|
|
and $f
|
|
|
|
ld e, a
|
|
|
|
ld a, c
|
|
|
|
and $f
|
|
|
|
ld b, a
|
|
|
|
ld c, 0
|
|
|
|
cp 2
|
|
|
|
jr z, .two
|
|
|
|
cp 3
|
|
|
|
jr z, .three
|
|
|
|
cp 4
|
|
|
|
jr z, .four
|
|
|
|
cp 5
|
|
|
|
jr z, .five
|
|
|
|
cp 6
|
|
|
|
jr z, .six
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
; seven
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(1000000 >> 8)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(1000000) ; mid
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, LOW(1000000)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 09:47:28 -07:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.six
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(100000 >> 8)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(100000) ; mid
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, LOW(100000)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 09:47:28 -07:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.five
|
2017-12-25 10:40:10 -08:00
|
|
|
xor a ; HIGH(10000 >> 8)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(10000) ; mid
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, LOW(10000)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 09:47:28 -07:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.four
|
2017-12-25 10:40:10 -08:00
|
|
|
xor a ; HIGH(1000 >> 8)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, HIGH(1000) ; mid
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, LOW(1000)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 09:47:28 -07:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.three
|
2017-12-25 10:40:10 -08:00
|
|
|
xor a ; HIGH(100 >> 8)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 10:40:10 -08:00
|
|
|
xor a ; HIGH(100) ; mid
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 10:40:10 -08:00
|
|
|
ld a, LOW(100)
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 09:47:28 -07:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.two
|
|
|
|
dec e
|
|
|
|
jr nz, .two_skip
|
|
|
|
ld a, "0"
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 09:47:28 -07:00
|
|
|
.two_skip
|
|
|
|
|
|
|
|
ld c, 0
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 3]
|
2016-03-27 09:47:28 -07:00
|
|
|
.mod_10
|
|
|
|
cp 10
|
|
|
|
jr c, .modded_10
|
|
|
|
sub 10
|
|
|
|
inc c
|
|
|
|
jr .mod_10
|
|
|
|
.modded_10
|
|
|
|
|
|
|
|
ld b, a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 09:47:28 -07:00
|
|
|
or c
|
2023-09-02 14:16:35 -07:00
|
|
|
jr nz, .coins
|
2016-03-27 09:47:28 -07:00
|
|
|
call .PrintLeadingZero
|
2023-09-02 14:16:35 -07:00
|
|
|
jr .coins_leading_zero
|
2016-03-27 09:47:28 -07:00
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
.coins
|
2023-09-02 09:54:27 -07:00
|
|
|
call .PrintCoin
|
2016-03-27 09:47:28 -07:00
|
|
|
push af
|
|
|
|
ld a, "0"
|
|
|
|
add c
|
|
|
|
ld [hl], a
|
|
|
|
pop af
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 09:47:28 -07:00
|
|
|
inc e
|
|
|
|
dec e
|
2023-09-02 14:16:35 -07:00
|
|
|
jr nz, .coins_leading_zero
|
2016-03-27 09:47:28 -07:00
|
|
|
inc hl
|
2023-08-02 09:21:34 -07:00
|
|
|
ld [hl], "."
|
2016-03-27 09:47:28 -07:00
|
|
|
|
2023-09-02 14:16:35 -07:00
|
|
|
.coins_leading_zero
|
2016-03-27 09:47:28 -07:00
|
|
|
call .AdvancePointer
|
2023-09-02 09:54:27 -07:00
|
|
|
call .PrintCoin
|
2016-03-27 09:47:28 -07:00
|
|
|
ld a, "0"
|
|
|
|
add b
|
|
|
|
ld [hli], a
|
|
|
|
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2023-09-02 09:54:27 -07:00
|
|
|
.PrintCoin:
|
2016-03-27 09:47:28 -07:00
|
|
|
push af
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 09:47:28 -07:00
|
|
|
and a
|
|
|
|
jr nz, .stop
|
|
|
|
bit 5, d
|
|
|
|
jr z, .stop
|
2023-09-02 09:54:27 -07:00
|
|
|
ld a, "<COIN>"
|
2016-03-27 09:47:28 -07:00
|
|
|
ld [hli], a
|
|
|
|
res 5, d
|
|
|
|
|
|
|
|
.stop
|
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.PrintDigit:
|
2016-03-27 09:47:28 -07:00
|
|
|
dec e
|
|
|
|
jr nz, .ok
|
|
|
|
ld a, "0"
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 09:47:28 -07:00
|
|
|
.ok
|
|
|
|
ld c, 0
|
|
|
|
.loop
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 4]
|
2016-03-27 09:47:28 -07:00
|
|
|
ld b, a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 1]
|
|
|
|
ldh [hPrintNumBuffer + 7], a
|
2016-03-27 09:47:28 -07:00
|
|
|
cp b
|
|
|
|
jr c, .skip1
|
|
|
|
sub b
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
|
|
|
ldh a, [hPrintNumBuffer + 5]
|
2016-03-27 09:47:28 -07:00
|
|
|
ld b, a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 2]
|
|
|
|
ldh [hPrintNumBuffer + 8], a
|
2016-03-27 09:47:28 -07:00
|
|
|
cp b
|
|
|
|
jr nc, .skip2
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 1]
|
2016-03-27 09:47:28 -07:00
|
|
|
or 0
|
|
|
|
jr z, .skip3
|
|
|
|
dec a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
|
|
|
ldh a, [hPrintNumBuffer + 2]
|
2016-03-27 09:47:28 -07:00
|
|
|
.skip2
|
|
|
|
sub b
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
|
|
|
ldh a, [hPrintNumBuffer + 6]
|
2016-03-27 09:47:28 -07:00
|
|
|
ld b, a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 3]
|
|
|
|
ldh [hPrintNumBuffer + 9], a
|
2016-03-27 09:47:28 -07:00
|
|
|
cp b
|
|
|
|
jr nc, .skip4
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 2]
|
2016-03-27 09:47:28 -07:00
|
|
|
and a
|
|
|
|
jr nz, .skip5
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 1]
|
2016-03-27 09:47:28 -07:00
|
|
|
and a
|
|
|
|
jr z, .skip6
|
|
|
|
dec a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
2016-03-27 09:47:28 -07:00
|
|
|
xor a
|
|
|
|
.skip5
|
|
|
|
dec a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
|
|
|
ldh a, [hPrintNumBuffer + 3]
|
2016-03-27 09:47:28 -07:00
|
|
|
.skip4
|
|
|
|
sub b
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 09:47:28 -07:00
|
|
|
inc c
|
|
|
|
jr .loop
|
|
|
|
.skip6
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 8]
|
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 09:47:28 -07:00
|
|
|
.skip3
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 7]
|
|
|
|
ldh [hPrintNumBuffer + 1], a
|
2016-03-27 09:47:28 -07:00
|
|
|
.skip1
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 09:47:28 -07:00
|
|
|
or c
|
|
|
|
jr z, .PrintLeadingZero
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 09:47:28 -07:00
|
|
|
and a
|
|
|
|
jr nz, .done
|
|
|
|
bit 5, d
|
|
|
|
jr z, .done
|
2023-09-02 09:54:27 -07:00
|
|
|
ld a, "<COIN>"
|
2016-03-27 09:47:28 -07:00
|
|
|
ld [hli], a
|
|
|
|
res 5, d
|
|
|
|
.done
|
|
|
|
ld a, "0"
|
|
|
|
add c
|
|
|
|
ld [hl], a
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 09:47:28 -07:00
|
|
|
inc e
|
|
|
|
dec e
|
|
|
|
ret nz
|
|
|
|
inc hl
|
2023-08-02 09:21:34 -07:00
|
|
|
ld [hl], "."
|
2016-03-27 09:47:28 -07:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.PrintLeadingZero:
|
2016-03-27 09:47:28 -07:00
|
|
|
; prints a leading zero unless they are turned off in the flags
|
|
|
|
bit 7, d ; print leading zeroes?
|
|
|
|
ret z
|
|
|
|
ld [hl], "0"
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.AdvancePointer:
|
2016-03-27 09:47:28 -07:00
|
|
|
; increments the pointer unless leading zeroes are not being printed,
|
|
|
|
; the number is left-aligned, and no nonzero digits have been printed yet
|
|
|
|
bit 7, d ; print leading zeroes?
|
|
|
|
jr nz, .inc
|
|
|
|
bit 6, d ; left alignment or right alignment?
|
|
|
|
jr z, .inc
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 09:47:28 -07:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
.inc
|
|
|
|
inc hl
|
|
|
|
ret
|