summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlibjet <libj3t@gmail.com>2020-02-20 01:24:55 +0000
committerlibjet <libj3t@gmail.com>2020-02-20 01:24:55 +0000
commit2d16b94ef14073ad21a77aa9b36250709f420f63 (patch)
tree9b37affe0a1ac14e689117e73eafebf8008e6e6d
parent53c4af7707e61efb9fcb2d881a450a7330b01024 (diff)
Add home/print_bcd.asm
-rw-r--r--constants/text_constants.asm4
-rw-r--r--home.asm65
-rwxr-xr-xhome/print_bcd.asm79
-rwxr-xr-xhome/print_level.asm2
4 files changed, 83 insertions, 67 deletions
diff --git a/constants/text_constants.asm b/constants/text_constants.asm
index ee558956..745fb52c 100644
--- a/constants/text_constants.asm
+++ b/constants/text_constants.asm
@@ -33,12 +33,12 @@ TEXTBOX_INNERY EQU TEXTBOX_Y + 2
; PrintNum bit flags
const_def 5
const PRINTNUM_MONEY_F ; 5
- const PRINTNUM_RIGHTALIGN_F ; 6
+ const PRINTNUM_LEFTALIGN_F ; 6
const PRINTNUM_LEADINGZEROS_F ; 7
; PrintNum arguments (see engine/math/print_num.asm)
PRINTNUM_MONEY EQU 1 << PRINTNUM_MONEY_F
-PRINTNUM_RIGHTALIGN EQU 1 << PRINTNUM_RIGHTALIGN_F
+PRINTNUM_LEFTALIGN EQU 1 << PRINTNUM_LEFTALIGN_F
PRINTNUM_LEADINGZEROS EQU 1 << PRINTNUM_LEADINGZEROS_F
; character sets (see charmap.asm)
diff --git a/home.asm b/home.asm
index f275dd3f..97b41248 100644
--- a/home.asm
+++ b/home.asm
@@ -264,70 +264,7 @@ INCLUDE "home/mon_stats.asm"
INCLUDE "home/cry.asm"
INCLUDE "home/print_level.asm"
INCLUDE "home/mon_data.asm"
-
-PrintBCDNumber:: ; 3ade (0:3ade)
- ld b, c
- res 7, c
- res 6, c
- res 5, c
- bit 5, b
- jr z, .asm_3af0
- bit 7, b
- jr nz, .asm_3af0
- ld [hl], $f0
- inc hl
-.asm_3af0
- ld a, [de]
- swap a
- call Function3b15
- ld a, [de]
- call Function3b15
- inc de
- dec c
- jr nz, .asm_3af0
- bit 7, b
- jr z, .asm_3b14
- bit 6, b
- jr nz, .asm_3b07
- dec hl
-.asm_3b07
- bit 5, b
- jr z, .asm_3b0e
- ld [hl], $f0
- inc hl
-.asm_3b0e
- ld [hl], $f6
- call PrintLetterDelay
- inc hl
-.asm_3b14
- ret
-
-Function3b15:: ; 3b15 (0:3b15)
- and $f
- and a
- jr z, .asm_3b2f
- bit 7, b
- jr z, .asm_3b29
- bit 5, b
- jr z, .asm_3b27
- ld [hl], $f0
- inc hl
- res 5, b
-.asm_3b27
- res 7, b
-.asm_3b29
- add $f6
- ld [hli], a
- jp PrintLetterDelay
-
-.asm_3b2f
- bit 7, b
- jr z, .asm_3b29
- bit 6, b
- ret nz
- ld a, $7f
- ld [hli], a
- ret
+INCLUDE "home/print_bcd.asm"
GetPartyParamLocation::
push bc
diff --git a/home/print_bcd.asm b/home/print_bcd.asm
new file mode 100755
index 00000000..9401b26f
--- /dev/null
+++ b/home/print_bcd.asm
@@ -0,0 +1,79 @@
+PrintBCDNumber::
+; 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 PRINTNUM_LEADINGZEROS_F, c
+ res PRINTNUM_LEFTALIGN_F, c
+ res PRINTNUM_MONEY_F, c ; c now holds the length
+ bit PRINTNUM_MONEY_F, b
+ jr z, .loop
+ bit PRINTNUM_LEADINGZEROS_F, b
+ 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
+ bit PRINTNUM_LEADINGZEROS_F, b
+ jr z, .done ; if so, we are done
+.numberEqualsZero ; if every digit of the BCD number is zero
+ bit PRINTNUM_LEFTALIGN_F, b
+ jr nz, .skipLeftAlignmentAdjustment
+ dec hl ; if the string is left-aligned, it needs to be moved back one space
+.skipLeftAlignmentAdjustment
+ bit PRINTNUM_MONEY_F, b
+ jr z, .skipCurrencySymbol
+ ld [hl], "¥" ; currency symbol
+ inc hl
+.skipCurrencySymbol
+ ld [hl], "0"
+ call PrintLetterDelay
+ inc hl
+.done
+ ret
+
+PrintBCDDigit::
+ and %00001111
+ and a
+ jr z, .zeroDigit
+.nonzeroDigit
+ bit PRINTNUM_LEADINGZEROS_F, b ; have any non-space characters been printed?
+ jr z, .outputDigit
+; if bit 7 is set, then no numbers have been printed yet
+ bit PRINTNUM_MONEY_F, b
+ jr z, .skipCurrencySymbol
+ ld [hl], "¥"
+ inc hl
+ res PRINTNUM_MONEY_F, b
+.skipCurrencySymbol
+ res PRINTNUM_LEADINGZEROS_F, b ; unset 7 to indicate that a nonzero digit has been reached
+.outputDigit
+ add "0"
+ ld [hli], a
+ jp PrintLetterDelay
+
+.zeroDigit
+ bit PRINTNUM_LEADINGZEROS_F, b ; either printing leading zeroes or already reached a nonzero digit?
+ jr z, .outputDigit ; if so, print a zero digit
+ bit PRINTNUM_LEFTALIGN_F, b
+ ret nz
+ ld a, " "
+ ld [hli], a ; if right-aligned, "print" a space by advancing the pointer
+ ret \ No newline at end of file
diff --git a/home/print_level.asm b/home/print_level.asm
index dbe14f74..9a7258ed 100755
--- a/home/print_level.asm
+++ b/home/print_level.asm
@@ -24,5 +24,5 @@ PrintLevel_Force3Digits::
Print8BitNumRightAlign::
ld [wDeciramBuffer], a
ld de, wDeciramBuffer
- ld b, PRINTNUM_RIGHTALIGN | 1
+ ld b, PRINTNUM_LEFTALIGN | 1
jp PrintNum \ No newline at end of file