Comment PrintNum.

This commit is contained in:
yenatch 2014-06-04 16:21:10 -07:00
parent 55972bfb83
commit 61521f4458
1 changed files with 174 additions and 163 deletions

337
main.asm
View File

@ -8503,55 +8503,65 @@ SpecialTrainerHouse: ; 0xc4b9
ld [ScriptVar], a ld [ScriptVar], a
jp CloseSRAM jp CloseSRAM
_PrintNum:: ; c4c7
push bc
bit 5, b
jr z, .asm_c4d9
bit 7, b
jr nz, .asm_c4d4
bit 6, b
jr z, .asm_c4d9
.asm_c4d4 _PrintNum:: ; c4c7
; Print c digits of the b-byte value at hl.
; Allows 2 to 7 digits. For 1-digit numbers, add
; the value to char "0" instead of calling PrintNum.
; Some extra flags can be given in bits 5-7 of b.
push bc
bit 5, b
jr z, .main
bit 7, b
jr nz, .bit_7
bit 6, b
jr z, .main
.bit_7
ld a, $f0 ld a, $f0
ld [hli], a ld [hli], a
res 5, b res 5, b
.asm_c4d9 .main
xor a xor a
ld [hProduct], a ld [$ffb3], a
ld [hMultiplicand], a ld [$ffb4], a
ld [$ffb5], a ld [$ffb5], a
ld a, b ld a, b
and $f and $f
cp $1 cp 1
jr z, .asm_c501 jr z, .byte
cp $2 cp 2
jr z, .asm_c4f8 jr z, .word
.long
ld a, [de] ld a, [de]
ld [hMultiplicand], a ld [$ffb4], a
inc de inc de
ld a, [de] ld a, [de]
ld [$ffb5], a ld [$ffb5], a
inc de inc de
ld a, [de] ld a, [de]
ld [$ffb6], a ld [$ffb6], a
jr .asm_c504 jr .start
.asm_c4f8 .word
ld a, [de] ld a, [de]
ld [$ffb5], a ld [$ffb5], a
inc de inc de
ld a, [de] ld a, [de]
ld [$ffb6], a ld [$ffb6], a
jr .asm_c504 jr .start
.asm_c501 .byte
ld a, [de] ld a, [de]
ld [$ffb6], a ld [$ffb6], a
.asm_c504 .start
push de push de
ld d, b ld d, b
ld a, c ld a, c
swap a swap a
@ -8560,123 +8570,126 @@ _PrintNum:: ; c4c7
ld a, c ld a, c
and $f and $f
ld b, a ld b, a
ld c, $0 ld c, 0
cp $2 cp 2
jr z, .asm_c57c jr z, .two
cp $3 cp 3
jr z, .asm_c56c jr z, .three
cp $4 cp 4
jr z, .asm_c55b jr z, .four
cp $5 cp 5
jr z, .asm_c54a jr z, .five
cp $6 cp 6
jr z, .asm_c538 jr z, .six
ld a, $f
ld [hMultiplier], a
ld a, $42
ld [hMathBuffer], a
ld a, $40
ld [$ffb9], a
call Functionc5cb
call PrintNumber_AdvancePointer
.asm_c538 .seven
ld a, $1 ld a, 1000000 / $10000 % $100
ld [hMultiplier], a ld [$ffb7], a
ld a, $86 ld a, 1000000 / $100 % $100
ld [hMathBuffer], a ld [$ffb8], a
ld a, $a0 ld a, 1000000 % $100
ld [$ffb9], a ld [$ffb9], a
call Functionc5cb call .PrintDigit
call PrintNumber_AdvancePointer call .AdvancePointer
.asm_c54a .six
ld a, 100000 / $10000 % $100
ld [$ffb7], a
ld a, 100000 / $100 % $100
ld [$ffb8], a
ld a, 100000 % $100
ld [$ffb9], a
call .PrintDigit
call .AdvancePointer
.five
xor a xor a
ld [hMultiplier], a ld [$ffb7], a
ld a, $27 ld a, 10000 / $100
ld [hMathBuffer], a ld [$ffb8], a
ld a, $10 ld a, 10000 % $100
ld [$ffb9], a ld [$ffb9], a
call Functionc5cb call .PrintDigit
call PrintNumber_AdvancePointer call .AdvancePointer
.asm_c55b .four
xor a xor a
ld [hMultiplier], a ld [$ffb7], a
ld a, $3 ld a, 1000 / $100
ld [hMathBuffer], a ld [$ffb8], a
ld a, $e8 ld a, 1000 % $100
ld [$ffb9], a ld [$ffb9], a
call Functionc5cb call .PrintDigit
call PrintNumber_AdvancePointer call .AdvancePointer
.asm_c56c .three
xor a xor a
ld [hMultiplier], a ld [$ffb7], a
xor a xor a
ld [hMathBuffer], a ld [$ffb8], a
ld a, $64 ld a, 100
ld [$ffb9], a ld [$ffb9], a
call Functionc5cb call .PrintDigit
call PrintNumber_AdvancePointer call .AdvancePointer
.asm_c57c .two
dec e dec e
jr nz, .asm_c583 jr nz, .asm_c583
ld a, $f6 ld a, $f6
ld [hProduct], a ld [$ffb3], a
.asm_c583 .asm_c583
ld c, $0
ld a, [$ffb6]
.asm_c587
cp $a
jr c, .asm_c590
sub $a
inc c
jr .asm_c587
.asm_c590 ld c, 0
ld a, [$ffb6]
.mod_10
cp 10
jr c, .modded_10
sub 10
inc c
jr .mod_10
.modded_10
ld b, a ld b, a
ld a, [hProduct] ld a, [$ffb3]
or c or c
jr nz, .asm_c59b jr nz, .asm_c59b
call PrintNumber_PrintLeadingZero call .PrintLeadingZero
jr .asm_c5ad jr .asm_c5ad
.asm_c59b .asm_c59b
call Functionc5ba call .PrintYen
push af push af
ld a, $f6 ld a, "0"
add c add c
ld [hl], a ld [hl], a
pop af pop af
ld [hProduct], a ld [$ffb3], a
inc e inc e
dec e dec e
jr nz, .asm_c5ad jr nz, .asm_c5ad
inc hl inc hl
ld [hl], $f2 ld [hl], $f2 ; XXX
.asm_c5ad .asm_c5ad
call PrintNumber_AdvancePointer call .AdvancePointer
call Functionc5ba call .PrintYen
ld a, $f6 ld a, "0"
add b add b
ld [hli], a ld [hli], a
pop de pop de
pop bc pop bc
ret ret
; c5ba ; c5ba
Functionc5ba: ; c5ba .PrintYen: ; c5ba
push af push af
ld a, [hProduct] ld a, [$ffb3]
and a and a
jr nz, .asm_c5c9 jr nz, .asm_c5c9
bit 5, d bit 5, d
jr z, .asm_c5c9 jr z, .asm_c5c9
ld a, $f0 ld a, "¥"
ld [hli], a ld [hli], a
res 5, d res 5, d
@ -8685,76 +8698,72 @@ Functionc5ba: ; c5ba
ret ret
; c5cb ; c5cb
.PrintDigit: ; c5cb (3:45cb)
; known jump sources: c532 (3:4532), c544 (3:4544), c555 (3:4555), c566 (3:4566), c576 (3:4576)
Functionc5cb: ; c5cb (3:45cb)
dec e dec e
jr nz, PrintNumber_PrintDigit jr nz, .ok
ld a, $f6 ld a, $f6
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
.ok
; known jump sources: c5cc (3:45cc)
PrintNumber_PrintDigit: ; c5d2 (3:45d2)
ld c, $0 ld c, $0
.asm_c5d4 .asm_c5d4
ld a, [hDivisor] ; $ff00+$b7 (aliases: hMultiplier) ld a, [$ffb7]
ld b, a ld b, a
ld a, [hQuotient] ; $ff00+$b4 (aliases: hMultiplicand) ld a, [$ffb4]
ld [$FF00+$ba], a ld [$ffba], a
cp b cp b
jr c, .asm_c624 jr c, .asm_c624
sub b sub b
ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand) ld [$ffb4], a
ld a, [hMathBuffer] ; $ff00+$b8 ld a, [$ffb8]
ld b, a ld b, a
ld a, [$FF00+$b5] ld a, [$ffb5]
ld [$FF00+$bb], a ld [$ffbb], a
cp b cp b
jr nc, .asm_c5f6 jr nc, .asm_c5f6
ld a, [hQuotient] ; $ff00+$b4 (aliases: hMultiplicand) ld a, [$ffb4]
or $0 or $0
jr z, .asm_c620 jr z, .asm_c620
dec a dec a
ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand) ld [$ffb4], a
ld a, [$FF00+$b5] ld a, [$ffb5]
.asm_c5f6 .asm_c5f6
sub b sub b
ld [$FF00+$b5], a ld [$ffb5], a
ld a, [$FF00+$b9] ld a, [$ffb9]
ld b, a ld b, a
ld a, [$FF00+$b6] ld a, [$ffb6]
ld [$FF00+$bc], a ld [$ffbc], a
cp b cp b
jr nc, .asm_c616 jr nc, .asm_c616
ld a, [$FF00+$b5] ld a, [$ffb5]
and a and a
jr nz, .asm_c611 jr nz, .asm_c611
ld a, [hQuotient] ; $ff00+$b4 (aliases: hMultiplicand) ld a, [$ffb4]
and a and a
jr z, .asm_c61c jr z, .asm_c61c
dec a dec a
ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand) ld [$ffb4], a
xor a xor a
.asm_c611 .asm_c611
dec a dec a
ld [$FF00+$b5], a ld [$ffb5], a
ld a, [$FF00+$b6] ld a, [$ffb6]
.asm_c616 .asm_c616
sub b sub b
ld [$FF00+$b6], a ld [$ffb6], a
inc c inc c
jr .asm_c5d4 jr .asm_c5d4
.asm_c61c .asm_c61c
ld a, [$FF00+$bb] ld a, [$ffbb]
ld [$FF00+$b5], a ld [$ffb5], a
.asm_c620 .asm_c620
ld a, [$FF00+$ba] ld a, [$ffba]
ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand) ld [$ffb4], a
.asm_c624 .asm_c624
ld a, [hPastLeadingZeroes] ; $ff00+$b3 (aliases: hDividend, hProduct) ld a, [$ffb3]
or c or c
jr z, PrintNumber_PrintLeadingZero jr z, .PrintLeadingZero
ld a, [hPastLeadingZeroes] ; $ff00+$b3 (aliases: hDividend, hProduct) ld a, [$ffb3]
and a and a
jr nz, .asm_c637 jr nz, .asm_c637
bit 5, d bit 5, d
@ -8766,7 +8775,7 @@ PrintNumber_PrintDigit: ; c5d2 (3:45d2)
ld a, $f6 ld a, $f6
add c add c
ld [hl], a ld [hl], a
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
inc e inc e
dec e dec e
ret nz ret nz
@ -8774,49 +8783,51 @@ PrintNumber_PrintDigit: ; c5d2 (3:45d2)
ld [hl], $f2 ld [hl], $f2
ret ret
PrintNumber_PrintLeadingZero: ; c644 .PrintLeadingZero: ; c644
; prints a leading zero unless they are turned off in the flags ; prints a leading zero unless they are turned off in the flags
bit 7, d ; print leading zeroes? bit 7, d ; print leading zeroes?
ret z ret z
ld [hl], "0" ld [hl], "0"
ret ret
PrintNumber_AdvancePointer: ; c64a .AdvancePointer: ; c64a
; increments the pointer unless leading zeroes are not being printed, ; increments the pointer unless leading zeroes are not being printed,
; the number is left-aligned, and no nonzero digits have been printed yet ; the number is left-aligned, and no nonzero digits have been printed yet
bit 7, d ; print leading zeroes? bit 7, d ; print leading zeroes?
jr nz, .incrementPointer jr nz, .inc
bit 6, d ; left alignment or right alignment? bit 6, d ; left alignment or right alignment?
jr z, .incrementPointer jr z, .inc
ld a, [hPastLeadingZeroes] ld a, [$ffb3]
and a and a
ret z ret z
.incrementPointer .inc
inc hl inc hl
ret ret
; 0xc658 ; c658
Functionc658: ; c658 Functionc658: ; c658
xor a xor a
ld [CurPartyMon], a ld [CurPartyMon], a
ld hl, PartySpecies ld hl, PartySpecies
.asm_c65f .loop
ld a, [hli] ld a, [hli]
cp $ff cp $ff
jr z, .asm_c676 jr z, .done
cp $fd cp EGG
jr z, .asm_c66d jr z, .next
push hl push hl
call Functionc677 call Functionc677
pop hl pop hl
.asm_c66d .next
ld a, [CurPartyMon] ld a, [CurPartyMon]
inc a inc a
ld [CurPartyMon], a ld [CurPartyMon], a
jr .asm_c65f jr .loop
.asm_c676 .done
ret ret
; c677 ; c677
@ -44727,7 +44738,7 @@ Function3989d: ; 3989d
; known jump sources: 397d0 (e:57d0) ; known jump sources: 397d0 (e:57d0)
Function3991b: ; 3991b (e:591b) Function3991b: ; 3991b (e:591b)
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
xor a xor a
ld [hli], a ld [hli], a
ld [hli], a ld [hli], a
@ -51173,10 +51184,10 @@ Function48d4a: ; 48d4a (12:4d4a)
; known jump sources: 48d40 (12:4d40), 48d46 (12:4d46) ; known jump sources: 48d40 (12:4d40), 48d46 (12:4d46)
Function48d94: ; 48d94 (12:4d94) Function48d94: ; 48d94 (12:4d94)
xor a xor a
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand) ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand)
ld a, [hli] ld a, [hli]
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
ld a, [hl] ld a, [hl]
ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand) ld [hQuotient], a ; $ff00+$b4 (aliases: hMultiplicand)
ld a, 100 ld a, 100
@ -106119,7 +106130,7 @@ Function104a95: ; 104a95 (41:4a95)
ld a, [$FF00+$bb] ld a, [$FF00+$bb]
cp $2 cp $2
jr z, Function104b22 jr z, Function104b22
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d56 call Function104d56
jr nz, .asm_104ac8 jr nz, .asm_104ac8
@ -106197,7 +106208,7 @@ Function104b22: ; 104b22 (41:4b22)
; known jump sources: 104b04 (41:4b04), 104b2e (41:4b2e) ; known jump sources: 104b04 (41:4b04), 104b2e (41:4b2e)
Function104b40: ; 104b40 (41:4b40) Function104b40: ; 104b40 (41:4b40)
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d56 call Function104d56
ret nz ret nz
@ -106208,14 +106219,14 @@ Function104b49: ; 104b49 (41:4b49)
ld a, [$FF00+$bc] ld a, [$FF00+$bc]
cp $6c cp $6c
ret nz ret nz
ld a, [hPastLeadingZeroes] ; $ff00+$b3 (aliases: hDividend, hProduct) ld a, [$ffb3]
cp $96 cp $96
jp nz, Function104d32 jp nz, Function104d32
ld a, $90 ld a, $90
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
call Function104d38 call Function104d38
ret nz ret nz
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d4e call Function104d4e
ret nz ret nz
@ -106238,8 +106249,8 @@ Function104b49: ; 104b49 (41:4b49)
; known jump sources: 104b10 (41:4b10), 104b22 (41:4b22) ; known jump sources: 104b10 (41:4b10), 104b22 (41:4b22)
Function104b88: ; 104b88 (41:4b88) Function104b88: ; 104b88 (41:4b88)
ld a, $96 ld a, $96
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d4e call Function104d4e
ret nz ret nz
@ -106249,7 +106260,7 @@ Function104b88: ; 104b88 (41:4b88)
ret nz ret nz
call Function104d43 call Function104d43
ret nz ret nz
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d56 call Function104d56
ret nz ret nz
@ -106257,7 +106268,7 @@ Function104b88: ; 104b88 (41:4b88)
ld a, [$FF00+$bc] ld a, [$FF00+$bc]
cp $6c cp $6c
ret nz ret nz
ld a, [hPastLeadingZeroes] ; $ff00+$b3 (aliases: hDividend, hProduct) ld a, [$ffb3]
cp $90 cp $90
jp nz, Function104d32 jp nz, Function104d32
call Function104d38 call Function104d38
@ -106358,7 +106369,7 @@ Function104c2d: ; 104c2d (41:4c2d)
; known jump sources: 104c4e (41:4c4e), 104c78 (41:4c78) ; known jump sources: 104c4e (41:4c4e), 104c78 (41:4c78)
Function104c8a: ; 104c8a (41:4c8a) Function104c8a: ; 104c8a (41:4c8a)
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d56 call Function104d56
ret nz ret nz
@ -106366,14 +106377,14 @@ Function104c8a: ; 104c8a (41:4c8a)
ld a, [$FF00+$bc] ld a, [$FF00+$bc]
cp $6c cp $6c
ret nz ret nz
ld a, [hPastLeadingZeroes] ; $ff00+$b3 (aliases: hDividend, hProduct) ld a, [$ffb3]
cp $3c cp $3c
jp nz, Function104d32 jp nz, Function104d32
swap a swap a
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
call Function104d38 call Function104d38
ret nz ret nz
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d4e call Function104d4e
ret nz ret nz
@ -106396,8 +106407,8 @@ Function104c8a: ; 104c8a (41:4c8a)
; known jump sources: 104c5a (41:4c5a), 104c6c (41:4c6c) ; known jump sources: 104c5a (41:4c5a), 104c6c (41:4c6c)
Function104cd2: ; 104cd2 (41:4cd2) Function104cd2: ; 104cd2 (41:4cd2)
ld a, $3c ld a, $3c
ld [hPastLeadingZeroes], a ; $ff00+$b3 (aliases: hDividend, hProduct) ld [$ffb3], a
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d4e call Function104d4e
ret nz ret nz
@ -106407,7 +106418,7 @@ Function104cd2: ; 104cd2 (41:4cd2)
ret nz ret nz
call Function104d43 call Function104d43
ret nz ret nz
ld hl, hPastLeadingZeroes ; $ffb3 (aliases: hDividend, hProduct) ld hl, $ffb3
ld b, $1 ld b, $1
call Function104d56 call Function104d56
ret nz ret nz
@ -106415,7 +106426,7 @@ Function104cd2: ; 104cd2 (41:4cd2)
ld a, [$FF00+$bc] ld a, [$FF00+$bc]
cp $6c cp $6c
ret nz ret nz
ld a, [hPastLeadingZeroes] ; $ff00+$b3 (aliases: hDividend, hProduct) ld a, [$ffb3]
swap a swap a
cp $3c cp $3c
jp nz, Function104d32 jp nz, Function104d32