From 7281681bcdc7eb851b7bfdefe76f3e4be507ea32 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Thu, 31 May 2012 00:50:43 -0500 Subject: [PATCH] copy in PrintBCDNumber from pokered --- main.asm | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/main.asm b/main.asm index f6b68cfbf..52ae27f82 100644 --- a/main.asm +++ b/main.asm @@ -365,7 +365,59 @@ CountSetBits: ; 0x335f ret ; 0x3376 -INCBIN "baserom.gbc",$3376,$38f2 - $3376 +INCBIN "baserom.gbc",$3376,$38bb - $3376 + +PrintBCDNumber: ; 38bb +; 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 + res 7, c + res 6, c + res 5, c ; c now holds the length + bit 5, b + jr z, .loop\@ + bit 7, b + 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\@ + bit 7, b ; were any non-zero digits printed? + jr z, .done\@ ; if so, we are done +.numberEqualsZero\@ ; if every digit of the BCD number is zero + bit 6, b ; left or right alignment? + jr nz, .skipRightAlignmentAdjustment\@ + dec hl ; if the string is right-aligned, it needs to be moved back one space +.skipRightAlignmentAdjustment\@ + bit 5, b + jr z, .skipCurrencySymbol\@ + ld [hl], "¥" ; currency symbol + inc hl +.skipCurrencySymbol\@ + ld [hl], "0" + call PrintLetterDelay + inc hl +.done\@ + ret +; 0x38f2 PrintBCDDigit: ; 38f2 and a, %00001111