2018-06-24 07:09:41 -07:00
|
|
|
PrintBCDNumber::
|
2018-04-04 21:35:14 -07:00
|
|
|
; function to print a BCD (Binary-coded decimal) number
|
|
|
|
; de = address of BCD number
|
|
|
|
; hl = destination address
|
|
|
|
; c = flags and length
|
|
|
|
; bit 7: if set, do not print leading zeroes
|
|
|
|
; if unset, print leading zeroes
|
|
|
|
; bit 6: if set, left-align the string (do not pad empty digits with spaces)
|
|
|
|
; if unset, right-align the string
|
|
|
|
; bit 5: if set, print currency symbol at the beginning of the string
|
|
|
|
; if unset, do not print the currency symbol
|
|
|
|
; bits 0-4: length of BCD number in bytes
|
|
|
|
; Note that bits 5 and 7 are modified during execution. The above reflects
|
|
|
|
; their meaning at the beginning of the functions's execution.
|
|
|
|
ld b, c ; save flags in b
|
2019-11-03 17:17:04 -08:00
|
|
|
res PRINTNUM_LEADINGZEROS_F, c
|
|
|
|
res PRINTNUM_LEFTALIGN_F, c
|
|
|
|
res PRINTNUM_MONEY_F, c ; c now holds the length
|
|
|
|
bit PRINTNUM_MONEY_F, b
|
2018-04-04 21:35:14 -07:00
|
|
|
jr z, .loop
|
2019-11-03 17:17:04 -08:00
|
|
|
bit PRINTNUM_LEADINGZEROS_F, b
|
2018-04-04 21:35:14 -07:00
|
|
|
jr nz, .loop ; skip currency symbol
|
|
|
|
ld [hl], "¥"
|
|
|
|
inc hl
|
|
|
|
.loop
|
|
|
|
ld a, [de]
|
|
|
|
swap a
|
|
|
|
call PrintBCDDigit ; print upper digit
|
|
|
|
ld a, [de]
|
|
|
|
call PrintBCDDigit ; print lower digit
|
|
|
|
inc de
|
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
2019-11-03 17:17:04 -08:00
|
|
|
bit PRINTNUM_LEADINGZEROS_F, b
|
2018-04-04 21:35:14 -07:00
|
|
|
jr z, .done ; if so, we are done
|
2020-10-26 12:45:57 -07:00
|
|
|
; every digit of the BCD number is zero
|
2019-11-03 17:17:04 -08:00
|
|
|
bit PRINTNUM_LEFTALIGN_F, b
|
|
|
|
jr nz, .skipLeftAlignmentAdjustment
|
2020-10-26 12:45:57 -07:00
|
|
|
; the string is left-aligned; it needs to be moved back one space
|
|
|
|
dec hl
|
2019-11-03 17:17:04 -08:00
|
|
|
.skipLeftAlignmentAdjustment
|
|
|
|
bit PRINTNUM_MONEY_F, b
|
2018-04-04 21:35:14 -07:00
|
|
|
jr z, .skipCurrencySymbol
|
|
|
|
ld [hl], "¥" ; currency symbol
|
|
|
|
inc hl
|
|
|
|
.skipCurrencySymbol
|
|
|
|
ld [hl], "0"
|
|
|
|
call PrintLetterDelay
|
|
|
|
inc hl
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PrintBCDDigit::
|
2018-04-04 21:35:14 -07:00
|
|
|
and %00001111
|
|
|
|
and a
|
|
|
|
jr z, .zeroDigit
|
2020-10-26 12:45:57 -07:00
|
|
|
; nonzero digit
|
2019-11-03 17:17:04 -08:00
|
|
|
bit PRINTNUM_LEADINGZEROS_F, b ; have any non-space characters been printed?
|
2018-04-04 21:35:14 -07:00
|
|
|
jr z, .outputDigit
|
|
|
|
; if bit 7 is set, then no numbers have been printed yet
|
2019-11-03 17:17:04 -08:00
|
|
|
bit PRINTNUM_MONEY_F, b
|
2018-04-04 21:35:14 -07:00
|
|
|
jr z, .skipCurrencySymbol
|
|
|
|
ld [hl], "¥"
|
|
|
|
inc hl
|
2019-11-03 17:17:04 -08:00
|
|
|
res PRINTNUM_MONEY_F, b
|
2018-04-04 21:35:14 -07:00
|
|
|
.skipCurrencySymbol
|
2019-11-03 17:17:04 -08:00
|
|
|
res PRINTNUM_LEADINGZEROS_F, b ; unset 7 to indicate that a nonzero digit has been reached
|
2018-04-04 21:35:14 -07:00
|
|
|
.outputDigit
|
|
|
|
add "0"
|
|
|
|
ld [hli], a
|
|
|
|
jp PrintLetterDelay
|
|
|
|
|
|
|
|
.zeroDigit
|
2019-11-03 17:17:04 -08:00
|
|
|
bit PRINTNUM_LEADINGZEROS_F, b ; either printing leading zeroes or already reached a nonzero digit?
|
2018-04-04 21:35:14 -07:00
|
|
|
jr z, .outputDigit ; if so, print a zero digit
|
2019-11-03 17:17:04 -08:00
|
|
|
bit PRINTNUM_LEFTALIGN_F, b
|
2018-04-04 21:35:14 -07:00
|
|
|
ret nz
|
|
|
|
ld a, " "
|
|
|
|
ld [hli], a ; if right-aligned, "print" a space by advancing the pointer
|
|
|
|
ret
|