shithub: pokered

Download patch

ref: 4be11293e5c7d6bf4a2fc374974545a21a5e3572
parent: bba84059925c25e04fdcef5e4f3e2192176faf2d
author: yenatch <yenatch@gmail.com>
date: Sun May 25 13:27:02 EDT 2014

Label BCD math predefs.

--- a/engine/battle/4_2.asm
+++ b/engine/battle/4_2.asm
@@ -36,8 +36,8 @@
 	jr z, .asm_1380a
 	ld de, wPlayerMoney + 2 ; $d349
 	ld c, $3
-	ld a, $b
-	call Predef ; indirect jump to Func_f81d (f81d (3:781d))
+	ld a, $b ; AddBCDPredef
+	call Predef
 	ld hl, PickUpPayDayMoneyText
 	call PrintText
 .asm_1380a
--- a/engine/battle/b_2.asm
+++ b/engine/battle/b_2.asm
@@ -120,7 +120,7 @@
 	ld [hl], a
 	ld de, $cce7
 	ld c, $3
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	ld hl, CoinsScatteredText ; $7f04
 	jp PrintText
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -996,8 +996,8 @@
 	ld de, wPlayerMoney + 2 ; $d349
 	ld hl, $d07b
 	ld c, $3
-	ld a, $b
-	jp Predef ; indirect jump to Func_f81d (f81d (3:781d))
+	ld a, $b ; AddBCDPredef
+	jp Predef
 
 MoneyForWinningText: ; 3c6e4 (f:46e4)
 	TX_FAR _MoneyForWinningText
--- a/engine/menu/vending_machine.asm
+++ b/engine/menu/vending_machine.asm
@@ -71,8 +71,8 @@
 	ld hl, $ffde
 	ld de, wPlayerMoney + 2 ; $d349
 	ld c, $3
-	ld a, $c
-	call Predef ; indirect jump to Func_f836 (f836 (3:7836))
+	ld a, $c ; SubtractBCDPredef
+	call Predef
 	ld a, $13
 	ld [$d125], a
 	jp DisplayTextBoxID
--- a/engine/overworld/hidden_items.asm
+++ b/engine/overworld/hidden_items.asm
@@ -104,7 +104,7 @@
 	ld de, $d5a5
 	ld hl, $ffa1
 	ld c, $2
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	ld hl, $d6fe
 	ld a, [$cd41]
--- a/engine/predefs.asm
+++ b/engine/predefs.asm
@@ -70,12 +70,13 @@
 	dbw BANK(HealParty),HealParty
 MoveAnimationPredef: ; 4fe91 (13:7e91)
 	dbw BANK(MoveAnimation),MoveAnimation; 08 play move animation
-	dbw BANK(Func_f71e),Func_f71e
-	dbw BANK(Func_f71e),Func_f71e
-	dbw BANK(Func_f81d),Func_f81d
-	dbw BANK(Func_f836),Func_f836
-	dbw BANK(Func_f71e),Func_f71e
-	dbw BANK(Func_f71e),Func_f71e
+	dbw BANK(DivideBCDPredef),DivideBCDPredef
+	dbw BANK(DivideBCDPredef),DivideBCDPredef
+	dbw BANK(AddBCDPredef),AddBCDPredef
+	db BANK(SubtractBCDPredef)
+	dw SubtractBCDPredef
+	dbw BANK(DivideBCDPredef),DivideBCDPredef
+	dbw BANK(DivideBCDPredef),DivideBCDPredef
 	db BANK(InitializePlayerData)
 	dw InitializePlayerData
 	dbw BANK(FlagActionPredef),FlagActionPredef
--- a/engine/slot_machine.asm
+++ b/engine/slot_machine.asm
@@ -618,7 +618,7 @@
 	ld [hli], a
 	ld de, $d5a5
 	ld c, $2
-	ld a, $c
+	ld a, $c ; SubtractBCDPredef
 	call Predef
 
 SlotMachine_37754: ; 37754 (d:7754)
@@ -660,7 +660,7 @@
 	ld hl, $cd47
 	ld de, $d5a5
 	ld c, $2
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	call SlotMachine_37754
 	call SlotMachine_3775f
--- a/home.asm
+++ b/home.asm
@@ -917,9 +917,9 @@
 	call StopMusic
 	ld hl, $d72e
 	res 5, [hl]
-	ld a, Bank(Func_40b0) ; Bank(Func_40b0) and Bank(Func_62ce) need to be equal.
+	ld a, Bank(Func_40b0) ; also Bank(Func_62ce) and Bank(Func_5d5f)
 	ld [H_LOADEDROMBANK], a
-	ld [$2000], a
+	ld [MBC3RomBank], a
 	call Func_40b0
 	call Func_62ce
 	call Func_2312
@@ -8302,23 +8302,23 @@
 	ld hl, GetTrainerName_
 	jp Bankswitch
 
-; tests if player's money are at least as much as [$ff9f]
-; sets carry flag if not enough money
-; sets zero flag if amounts match exactly
-HasEnoughMoney:: ; 35a6 (0:35a6)
-	ld de, wPlayerMoney ; $d347
+
+HasEnoughMoney::
+; Check if the player has at least as much
+; money as the 3-byte BCD value at $ff9f.
+	ld de, wPlayerMoney
 	ld hl, $ff9f
-	ld c, $3
+	ld c, 3
 	jp StringCmp
 
-; tests if player's game corner coins are at least as many as [$ffa0]
-; sets carry flag if not enough coins
-; sets zero flag if amounts match exactly
-HasEnoughCoins:: ; 35b1 (0:35b1)
+HasEnoughCoins::
+; Check if the player has at least as many
+; coins as the 2-byte BCD value at $ffa0.
 	ld de, wPlayerCoins
 	ld hl, $ffa0
-	ld c, $2
+	ld c, 2
 	jp StringCmp
+
 
 BankswitchHome:: ; 35bc (0:35bc)
 ; switches to bank # in a
--- a/main.asm
+++ b/main.asm
@@ -63,49 +63,55 @@
 	db $08,$08, OAMFLAG_VFLIPPED | OAMFLAG_CANBEMASKED
 	db $08,$00, OAMFLAG_VFLIPPED | OAMFLAG_CANBEMASKED | OAMFLAG_ENDOFDATA
 
-Func_40b0: ; 40b0 (1:40b0)
+
+Func_40b0::
+; Reset player status on blackout.
 	xor a
 	ld [$cf0b], a
 	ld [$d700], a
-	ld [W_ISINBATTLE], a ; $d057
+	ld [W_ISINBATTLE], a
 	ld [$d35d], a
 	ld [$cf10], a
 	ld [hJoyHeld], a
 	ld [$cc57], a
 	ld [wFlags_0xcd60], a
+
 	ld [$ff9f], a
-	ld [$ffa0], a
-	ld [$ffa1], a
+	ld [$ff9f + 1], a
+	ld [$ff9f + 2], a
 	call HasEnoughMoney
-	jr c, .asm_40ff
-	ld a, [wPlayerMoney] ; $d347
+	jr c, .lostmoney ; never happens
+
+	; Halve the player's money.
+	ld a, [wPlayerMoney]
 	ld [$ff9f], a
-	ld a, [wPlayerMoney + 1] ; $d348
-	ld [$ffa0], a
-	ld a, [wPlayerMoney + 2] ; $d349
-	ld [$ffa1], a
+	ld a, [wPlayerMoney + 1]
+	ld [$ff9f + 1], a
+	ld a, [wPlayerMoney + 2]
+	ld [$ff9f + 2], a
 	xor a
 	ld [$ffa2], a
 	ld [$ffa3], a
-	ld a, $2
+	ld a, 2
 	ld [$ffa4], a
-	ld a, $d
-	call Predef ; indirect jump to Func_f71e (f71e (3:771e))
+	ld a, $d ; DivideBCDPredef
+	call Predef
 	ld a, [$ffa2]
-	ld [wPlayerMoney], a ; $d347
-	ld a, [$ffa3]
-	ld [wPlayerMoney + 1], a ; $d348
-	ld a, [$ffa4]
-	ld [wPlayerMoney + 2], a ; $d349
-.asm_40ff
+	ld [wPlayerMoney], a
+	ld a, [$ffa2 + 1]
+	ld [wPlayerMoney + 1], a
+	ld a, [$ffa2 + 2]
+	ld [wPlayerMoney + 2], a
+
+.lostmoney
 	ld hl, $d732
 	set 2, [hl]
 	res 3, [hl]
 	set 6, [hl]
-	ld a, $ff
+	ld a, %11111111
 	ld [wJoyIgnore], a
-	ld a, $7
-	jp Predef ; indirect jump to HealParty (f6a5 (3:76a5))
+	ld a, $7 ; HealParty
+	jp Predef
 
 MewPicFront:: INCBIN "pic/bmon/mew.pic"
 MewPicBack::  INCBIN "pic/monback/mewb.pic"
@@ -5309,12 +5315,10 @@
 	ret
 
 
-; predef $9
-; predef $a
-; predef $d
-; predef $e
-Func_f71e: ; f71e (3:771e)
+DivideBCDPredef::
 	call GetPredefRegisters
+
+DivideBCD::
 	xor a
 	ld [$ffa5], a
 	ld [$ffa6], a
@@ -5462,15 +5466,18 @@
 	ld de, $ffa1
 	ld hl, $ffa4
 	push bc
-	call Func_f839
+	call SubtractBCD
 	pop bc
 	jr .asm_f803
 
-Func_f81d: ; f81d (3:781d)
+
+AddBCDPredef::
 	call GetPredefRegisters
+
+AddBCD::
 	and a
 	ld b, c
-.asm_f822
+.add
 	ld a, [de]
 	adc [hl]
 	daa
@@ -5478,25 +5485,26 @@
 	dec de
 	dec hl
 	dec c
-	jr nz, .asm_f822
-	jr nc, .asm_f835
+	jr nz, .add
+	jr nc, .done
 	ld a, $99
 	inc de
-.asm_f830
+.fill
 	ld [de], a
 	inc de
 	dec b
-	jr nz, .asm_f830
-.asm_f835
+	jr nz, .fill
+.done
 	ret
 
-Func_f836: ; f836 (3:7836)
+
+SubtractBCDPredef::
 	call GetPredefRegisters
 
-Func_f839: ; f839 (3:7839)
+SubtractBCD::
 	and a
 	ld b, c
-.asm_f83b
+.sub
 	ld a, [de]
 	sbc [hl]
 	daa
@@ -5504,17 +5512,17 @@
 	dec de
 	dec hl
 	dec c
-	jr nz, .asm_f83b
-	jr nc, .asm_f84f
-	ld a, $0
+	jr nz, .sub
+	jr nc, .done
+	ld a, $00
 	inc de
-.asm_f849
+.fill
 	ld [de], a
 	inc de
 	dec b
-	jr nz, .asm_f849
+	jr nz, .fill
 	scf
-.asm_f84f
+.done
 	ret
 
 
--- a/scripts/celadongamecorner.asm
+++ b/scripts/celadongamecorner.asm
@@ -157,7 +157,7 @@
 	ld hl, $ffa1
 	ld de, $d349
 	ld c, $3
-	ld a, $c
+	ld a, $c ; SubtractBCDPredef
 	call Predef
 	xor a
 	ldh [$9f], a
@@ -167,7 +167,7 @@
 	ld de, $d5a5
 	ld hl, $ffa1
 	ld c, $2
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	call CeladonGameCornerScript_48f1e
 	ld hl, CeladonGameCornerText_48d27
@@ -236,7 +236,7 @@
 	ld de, $d5a5
 	ld hl, $ffa1
 	ld c, $2
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	ld hl, $d77e
 	set 2, [hl]
@@ -319,7 +319,7 @@
 	ld de, $d5a5
 	ld hl, $ffa1
 	ld c, $2
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	ld hl, $d77e
 	set 4, [hl]
@@ -373,7 +373,7 @@
 	ld de, $d5a5
 	ld hl, $ffa1
 	ld c, $2
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	ld hl, $d77e
 	set 3, [hl]
--- a/scripts/daycarem.asm
+++ b/scripts/daycarem.asm
@@ -120,7 +120,7 @@
 	push hl
 	push de
 	push bc
-	ld a, $b
+	ld a, $b ; AddBCDPredef
 	call Predef
 	pop bc
 	pop de
@@ -156,7 +156,7 @@
 	inc hl
 	ld de, $d349
 	ld c, $3
-	ld a, $c
+	ld a, $c ; SubtractBCDPredef
 	call Predef
 	ld a, (SFX_02_5a - SFX_Headers_02) / 3
 	call PlaySoundWaitForCurrent
--- a/scripts/mtmoonpokecenter.asm
+++ b/scripts/mtmoonpokecenter.asm
@@ -55,7 +55,7 @@
 	ld hl, $cd3f
 	ld de, $d349
 	ld c, $3
-	ld a, $c
+	ld a, $c ; SubtractBCDPredef
 	call Predef
 	ld a, $13
 	ld [$d125], a
--- a/scripts/museum1f.asm
+++ b/scripts/museum1f.asm
@@ -103,7 +103,7 @@
 	ld hl, $cd3f
 	ld de, $d349
 	ld c, $3
-	ld a, $c
+	ld a, $c ; SubtractBCDPredef
 	call Predef
 	ld a, $13
 	ld [$d125], a
--- a/scripts/safarizoneentrance.asm
+++ b/scripts/safarizoneentrance.asm
@@ -176,7 +176,7 @@
 	ld hl, $cd3f
 	ld de, $d349
 	ld c, $3
-	ld a, $c
+	ld a, $c ; SubtractBCDPredef
 	call Predef
 	ld a, $13
 	ld [$d125], a