mirror of
https://github.com/pret/pokegold-spaceworld.git
synced 2026-09-08 08:56:24 -05:00
Addresses of sections will now be added to the linkerscript via `org`, and the section name will be the path/to/file. If there is more than one section in the file, then add a @SectionName after the path/to/file to describe the section.
63 lines
1.6 KiB
NASM
63 lines
1.6 KiB
NASM
INCLUDE "constants.asm"
|
||
|
||
; if DEBUG
|
||
SECTION "home/print_bcd.asm", ROM0
|
||
; else
|
||
; SECTION "BCD Functions", ROM0[$3A76]
|
||
; endc
|
||
|
||
; 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
|
||
; bits 0-5: 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:: ; 3ab2 (0:3ab2)
|
||
ld b, c ; save flags in b
|
||
res 7, c
|
||
res 6, c ; c now holds the length
|
||
.loop
|
||
ld a, [de]
|
||
swap a
|
||
call PrintBCDDigit
|
||
ld a, [de]
|
||
call PrintBCDDigit
|
||
inc de
|
||
dec c
|
||
jr nz, .loop
|
||
bit 7, b ; were any non-zero digits printed?
|
||
jr z, .done
|
||
.numberEqualsZero ; if every digit of the BCD number is zero
|
||
bit 6, b
|
||
jr nz, .skipRightAlignmentAdjustment
|
||
dec hl ; if the string is right-aligned, it needs
|
||
.skipRightAlignmentAdjustment ;to be moved back one space
|
||
ld [hl], "0"
|
||
call PrintLetterDelay
|
||
inc hl
|
||
.done
|
||
ret
|
||
|
||
PrintBCDDigit:: ; 3ad5 (0:3ad5)
|
||
and $0f
|
||
and a
|
||
jr z, .zeroDigit
|
||
res 7, b ; unset 7 to indicate that a nonzero
|
||
.outputDigit ; digit has been reached
|
||
add "0"
|
||
ld [hli], a
|
||
jp PrintLetterDelay
|
||
.zeroDigit
|
||
bit 7, b ; either printing leading zeroes or
|
||
jr z, .outputDigit ; already reached a nonzero digit?
|
||
bit 6, b
|
||
ret nz ; left-align, don't pad with space
|
||
ld a, " "
|
||
ld [hli], a
|
||
ret
|
||
; 0x3aed |