2020-07-04 02:57:43 +00: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.
|
|
|
|
PrintBCDNumber::
|
|
|
|
ld b, c ; save flags in b
|
2024-09-24 03:51:44 +00:00
|
|
|
res BIT_LEADING_ZEROES, c
|
|
|
|
res BIT_LEFT_ALIGN, c
|
|
|
|
res BIT_MONEY_SIGN, c ; c now holds the length
|
|
|
|
bit BIT_MONEY_SIGN, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr z, .loop
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_LEADING_ZEROES, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr nz, .loop
|
|
|
|
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
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_LEADING_ZEROES, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr z, .done ; if so, we are done
|
|
|
|
.numberEqualsZero ; if every digit of the BCD number is zero
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_LEFT_ALIGN, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr nz, .skipRightAlignmentAdjustment
|
|
|
|
dec hl ; if the string is right-aligned, it needs to be moved back one space
|
|
|
|
.skipRightAlignmentAdjustment
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_MONEY_SIGN, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr z, .skipCurrencySymbol
|
|
|
|
ld [hl], "¥"
|
|
|
|
inc hl
|
|
|
|
.skipCurrencySymbol
|
|
|
|
ld [hl], "0"
|
|
|
|
call PrintLetterDelay
|
|
|
|
inc hl
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
|
|
|
|
PrintBCDDigit::
|
|
|
|
and $f
|
|
|
|
and a
|
|
|
|
jr z, .zeroDigit
|
|
|
|
.nonzeroDigit
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_LEADING_ZEROES, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr z, .outputDigit
|
|
|
|
; if bit 7 is set, then no numbers have been printed yet
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_MONEY_SIGN, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr z, .skipCurrencySymbol
|
|
|
|
ld [hl], "¥"
|
|
|
|
inc hl
|
2024-09-24 03:51:44 +00:00
|
|
|
res BIT_MONEY_SIGN, b
|
2020-07-04 02:57:43 +00:00
|
|
|
.skipCurrencySymbol
|
2024-09-24 03:51:44 +00:00
|
|
|
res BIT_LEADING_ZEROES, b
|
2020-07-04 02:57:43 +00:00
|
|
|
.outputDigit
|
|
|
|
add "0"
|
|
|
|
ld [hli], a
|
|
|
|
jp PrintLetterDelay
|
|
|
|
.zeroDigit
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_LEADING_ZEROES, b
|
2020-07-04 02:57:43 +00:00
|
|
|
jr z, .outputDigit ; if so, print a zero digit
|
2024-09-24 03:51:44 +00:00
|
|
|
bit BIT_LEFT_ALIGN, b
|
2020-07-04 02:57:43 +00:00
|
|
|
ret nz
|
|
|
|
inc hl ; if right-aligned, "print" a space by advancing the pointer
|
|
|
|
ret
|