2018-06-24 14:09:41 +00:00
|
|
|
_PrintNum::
|
2016-03-27 16:47:28 +00: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 15:46:06 +00: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 16:47:28 +00:00
|
|
|
; Some extra flags can be given in bits 5-7 of b.
|
|
|
|
; Bit 5: money if set (unless left-aligned without leading zeros)
|
2019-11-03 19:47:06 +00:00
|
|
|
; Bit 6: left-aligned if set
|
2016-03-27 16:47:28 +00:00
|
|
|
; Bit 7: print leading zeros if set
|
|
|
|
|
|
|
|
push bc
|
|
|
|
|
|
|
|
bit 5, b
|
|
|
|
jr z, .main
|
|
|
|
bit 7, b
|
|
|
|
jr nz, .moneyflag
|
|
|
|
bit 6, b
|
|
|
|
jr z, .main
|
|
|
|
|
|
|
|
.moneyflag ; 101xxxxx or 011xxxxx
|
|
|
|
ld a, "¥"
|
|
|
|
ld [hli], a
|
|
|
|
res 5, b ; 100xxxxx or 010xxxxx
|
|
|
|
|
|
|
|
.main
|
|
|
|
xor a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
|
|
|
ldh [hPrintNumBuffer + 1], a
|
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 16:47:28 +00:00
|
|
|
ld a, b
|
|
|
|
and $f
|
|
|
|
cp 1
|
|
|
|
jr z, .byte
|
|
|
|
cp 2
|
|
|
|
jr z, .word
|
|
|
|
; maximum 3 bytes
|
|
|
|
ld a, [de]
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
2016-03-27 16:47:28 +00:00
|
|
|
inc de
|
|
|
|
ld a, [de]
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 16:47:28 +00:00
|
|
|
inc de
|
|
|
|
ld a, [de]
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 16:47:28 +00:00
|
|
|
jr .start
|
|
|
|
|
|
|
|
.word
|
|
|
|
ld a, [de]
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 16:47:28 +00:00
|
|
|
inc de
|
|
|
|
ld a, [de]
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 16:47:28 +00:00
|
|
|
jr .start
|
|
|
|
|
|
|
|
.byte
|
|
|
|
ld a, [de]
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 16:47:28 +00: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 19:45:57 +00:00
|
|
|
; seven
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, HIGH(1000000 >> 8)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, HIGH(1000000) ; mid
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, LOW(1000000)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 16:47:28 +00:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.six
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, HIGH(100000 >> 8)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, HIGH(100000) ; mid
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, LOW(100000)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 16:47:28 +00:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.five
|
2017-12-25 18:40:10 +00:00
|
|
|
xor a ; HIGH(10000 >> 8)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, HIGH(10000) ; mid
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, LOW(10000)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 16:47:28 +00:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.four
|
2017-12-25 18:40:10 +00:00
|
|
|
xor a ; HIGH(1000 >> 8)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, HIGH(1000) ; mid
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, LOW(1000)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 16:47:28 +00:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.three
|
2017-12-25 18:40:10 +00:00
|
|
|
xor a ; HIGH(100 >> 8)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 4], a
|
2017-12-25 18:40:10 +00:00
|
|
|
xor a ; HIGH(100) ; mid
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 5], a
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, LOW(100)
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 6], a
|
2016-03-27 16:47:28 +00:00
|
|
|
call .PrintDigit
|
|
|
|
call .AdvancePointer
|
|
|
|
|
|
|
|
.two
|
|
|
|
dec e
|
|
|
|
jr nz, .two_skip
|
|
|
|
ld a, "0"
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 16:47:28 +00:00
|
|
|
.two_skip
|
|
|
|
|
|
|
|
ld c, 0
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 3]
|
2016-03-27 16:47:28 +00:00
|
|
|
.mod_10
|
|
|
|
cp 10
|
|
|
|
jr c, .modded_10
|
|
|
|
sub 10
|
|
|
|
inc c
|
|
|
|
jr .mod_10
|
|
|
|
.modded_10
|
|
|
|
|
|
|
|
ld b, a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 16:47:28 +00:00
|
|
|
or c
|
|
|
|
jr nz, .money
|
|
|
|
call .PrintLeadingZero
|
|
|
|
jr .money_leading_zero
|
|
|
|
|
|
|
|
.money
|
|
|
|
call .PrintYen
|
|
|
|
push af
|
|
|
|
ld a, "0"
|
|
|
|
add c
|
|
|
|
ld [hl], a
|
|
|
|
pop af
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 16:47:28 +00:00
|
|
|
inc e
|
|
|
|
dec e
|
|
|
|
jr nz, .money_leading_zero
|
|
|
|
inc hl
|
2018-01-02 12:24:05 +00:00
|
|
|
ld [hl], "<DOT>"
|
2016-03-27 16:47:28 +00:00
|
|
|
|
|
|
|
.money_leading_zero
|
|
|
|
call .AdvancePointer
|
|
|
|
call .PrintYen
|
|
|
|
ld a, "0"
|
|
|
|
add b
|
|
|
|
ld [hli], a
|
|
|
|
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.PrintYen:
|
2016-03-27 16:47:28 +00:00
|
|
|
push af
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 16:47:28 +00:00
|
|
|
and a
|
|
|
|
jr nz, .stop
|
|
|
|
bit 5, d
|
|
|
|
jr z, .stop
|
|
|
|
ld a, "¥"
|
|
|
|
ld [hli], a
|
|
|
|
res 5, d
|
|
|
|
|
|
|
|
.stop
|
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.PrintDigit:
|
2016-03-27 16:47:28 +00:00
|
|
|
dec e
|
|
|
|
jr nz, .ok
|
|
|
|
ld a, "0"
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 16:47:28 +00:00
|
|
|
.ok
|
|
|
|
ld c, 0
|
|
|
|
.loop
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 4]
|
2016-03-27 16:47:28 +00:00
|
|
|
ld b, a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 1]
|
|
|
|
ldh [hPrintNumBuffer + 7], a
|
2016-03-27 16:47:28 +00:00
|
|
|
cp b
|
|
|
|
jr c, .skip1
|
|
|
|
sub b
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
|
|
|
ldh a, [hPrintNumBuffer + 5]
|
2016-03-27 16:47:28 +00:00
|
|
|
ld b, a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 2]
|
|
|
|
ldh [hPrintNumBuffer + 8], a
|
2016-03-27 16:47:28 +00:00
|
|
|
cp b
|
|
|
|
jr nc, .skip2
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 1]
|
2016-03-27 16:47:28 +00:00
|
|
|
or 0
|
|
|
|
jr z, .skip3
|
|
|
|
dec a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
|
|
|
ldh a, [hPrintNumBuffer + 2]
|
2016-03-27 16:47:28 +00:00
|
|
|
.skip2
|
|
|
|
sub b
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
|
|
|
ldh a, [hPrintNumBuffer + 6]
|
2016-03-27 16:47:28 +00:00
|
|
|
ld b, a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 3]
|
|
|
|
ldh [hPrintNumBuffer + 9], a
|
2016-03-27 16:47:28 +00:00
|
|
|
cp b
|
|
|
|
jr nc, .skip4
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 2]
|
2016-03-27 16:47:28 +00:00
|
|
|
and a
|
|
|
|
jr nz, .skip5
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 1]
|
2016-03-27 16:47:28 +00:00
|
|
|
and a
|
|
|
|
jr z, .skip6
|
|
|
|
dec a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 1], a
|
2016-03-27 16:47:28 +00:00
|
|
|
xor a
|
|
|
|
.skip5
|
|
|
|
dec a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 2], a
|
|
|
|
ldh a, [hPrintNumBuffer + 3]
|
2016-03-27 16:47:28 +00:00
|
|
|
.skip4
|
|
|
|
sub b
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 3], a
|
2016-03-27 16:47:28 +00:00
|
|
|
inc c
|
|
|
|
jr .loop
|
|
|
|
.skip6
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 8]
|
|
|
|
ldh [hPrintNumBuffer + 2], a
|
2016-03-27 16:47:28 +00:00
|
|
|
.skip3
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 7]
|
|
|
|
ldh [hPrintNumBuffer + 1], a
|
2016-03-27 16:47:28 +00:00
|
|
|
.skip1
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 16:47:28 +00:00
|
|
|
or c
|
|
|
|
jr z, .PrintLeadingZero
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 16:47:28 +00:00
|
|
|
and a
|
|
|
|
jr nz, .done
|
|
|
|
bit 5, d
|
|
|
|
jr z, .done
|
|
|
|
ld a, "¥"
|
|
|
|
ld [hli], a
|
|
|
|
res 5, d
|
|
|
|
.done
|
|
|
|
ld a, "0"
|
|
|
|
add c
|
|
|
|
ld [hl], a
|
2018-08-26 01:49:26 +00:00
|
|
|
ldh [hPrintNumBuffer + 0], a
|
2016-03-27 16:47:28 +00:00
|
|
|
inc e
|
|
|
|
dec e
|
|
|
|
ret nz
|
|
|
|
inc hl
|
2017-12-10 00:41:03 +00:00
|
|
|
ld [hl], "<DOT>"
|
2016-03-27 16:47:28 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.PrintLeadingZero:
|
2016-03-27 16:47:28 +00: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 14:09:41 +00:00
|
|
|
.AdvancePointer:
|
2016-03-27 16:47:28 +00: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-26 01:49:26 +00:00
|
|
|
ldh a, [hPrintNumBuffer + 0]
|
2016-03-27 16:47:28 +00:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
.inc
|
|
|
|
inc hl
|
|
|
|
ret
|