ref: d6a4dada406f8ee010f08a16d24907bde50e1d6c
parent: bcc11712a578f1a0020fb0ab4543205324ec018d
author: JimB16 <f1@jimb.de>
date: Tue Sep 1 02:26:31 EDT 2015
added/renamed constants and labels
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -108,6 +108,7 @@
const MOM_ITEM
const MOM_DOLL
+BATTLETOWER_PKMNSTRUCTLENGTH EQU $30
BATTLETOWER_NROFPKMNS EQU 3
BATTLETOWER_TRAINERDATALENGTH EQU $24
BATTLETOWER_NROFTRAINERS EQU 7
--- a/data/battle_tower.asm
+++ b/data/battle_tower.asm
@@ -36,7 +36,7 @@
jr nc, .asm_1f8022
ld b, a
- ld a, BANK(sbe46)
+ ld a, BANK(sNrOfBeatenBattleTowerTrainers)
call GetSRAMBank
ld c, BATTLETOWER_NROFTRAINERS
@@ -49,12 +49,13 @@
jr nz, .asm_1f803a ; c <= 7 initialise all 7 trainers?
ld hl, sBTTrainers
- ld a, [sbe46]
+ ld a, [sNrOfBeatenBattleTowerTrainers]
ld c, a
ld a, b
ld b, 0
add hl, bc
ld [hl], a
+
call CloseSRAM
push af
@@ -82,10 +83,13 @@
ld a, b
or c
jr nz, .asm_1f8070
+
pop af
ld [rSVBK], a
+
ret
+
Function_LoadRandomBattleTowerPkmn: ; 1f8081
ld c, BATTLETOWER_NROFPKMNS
.loop
@@ -96,7 +100,7 @@
.FindARandomBattleTowerPkmn
; From Which LevelGroup are the Pkmn loaded
; a = 1..10
- ld a, [$d800]
+ ld a, [wBTChoiceOfLvlGroup] ; [$d800]
dec a
ld hl, BattleTowerMons
ld bc, BattleTowerMons2 - BattleTowerMons1
@@ -117,7 +121,7 @@
; Check if Pkmn was already loaded before
; Check current and the 2 previous teams
; includes check if item is double at the current team
- ld bc, $3b
+ ld bc, BATTLETOWER_PKMNSTRUCTLENGTH + $b
call AddNTimes
ld a, [hli]
ld b, a
@@ -160,17 +164,17 @@
cp b
jr z, .FindARandomBattleTowerPkmn
- ld bc, $3b
+ ld bc, BATTLETOWER_PKMNSTRUCTLENGTH + $b
call CopyBytes
ld a, [wd265]
push af
push de
- ld hl, -$3b
+ ld hl, - (BATTLETOWER_PKMNSTRUCTLENGTH + $b)
add hl, de
ld a, [hl]
ld [wd265], a
- ld bc, $0030
+ ld bc, BATTLETOWER_PKMNSTRUCTLENGTH
add hl, bc
push hl
call GetPokemonName
--- a/maps/BattleTowerBattleRoom.asm
+++ b/maps/BattleTowerBattleRoom.asm
@@ -34,8 +34,8 @@
special FadeBlackBGMap
reloadmap
if_not_equal $0, UnknownScript_0x9f4c2
- copybytetovar wcf64
- if_equal $7, Script_BeatenAllTrainers
+ copybytetovar wNrOfBeatenBattleTowerTrainers ; wcf64
+ if_equal BATTLETOWER_NROFTRAINERS, Script_BeatenAllTrainers
applymovement $2, MovementData_0x9e597
warpsound
disappear $2
--- a/maps/BattleTowerHallway.asm
+++ b/maps/BattleTowerHallway.asm
@@ -27,7 +27,7 @@
ld a, 3
ld [rSVBK], a
- ld a, [w3_d800]
+ ld a, [wBTChoiceOfLvlGroup]
ld [ScriptVar], a
pop af
--- a/misc/mobile_45.asm
+++ b/misc/mobile_45.asm
@@ -9728,13 +9728,13 @@
ld [wcd3c], a
call Function119ed8
jp Function119e2e
-; 11891c (46:491c)
+
Function11891c: ; 11891c
call Function118b42
jp Function119e2e
-; 118922
+
Function118922: ; 118922
ld a, [wcd38]
and a
@@ -9770,13 +9770,13 @@
ld a, [StatusFlags]
bit 6, a
jr nz, .asm_11896b
- ld hl, Strings_Ll0ToL40 ; Address to list of strings with the choosable levels
- ld a, 5 ; 4 levels to choose from, including 'Cancel'-option
+ ld hl, Strings_Ll0ToL40 ; Address to list of strings with the choosable levels
+ ld a, 5 ; 4 levels to choose from, including 'Cancel'-option
jr .asm_118970
.asm_11896b
- ld hl, Strings_L10ToL100 ; Address to list of strings with the choosable levels
- ld a, 11 ; 10 levels to choose from, including 'Cancel'-option
+ ld hl, Strings_L10ToL100 ; Address to list of strings with the choosable levels
+ ld a, 11 ; 10 levels to choose from, including 'Cancel'-option
.asm_118970
ld [wcd4a], a
@@ -9915,8 +9915,9 @@
ld a, $0
ld [wcd46], a
ret
-; 118a54
+
+
Function118a54: ; 118a54
ld a, [wcd55]
ld l, a
@@ -22852,13 +22853,13 @@
ld [ScriptVar], a
and a
jr nz, .asm_1702a9
- ld a, BANK(sbe46)
+ ld a, BANK(sNrOfBeatenBattleTowerTrainers)
call GetSRAMBank
- ld a, [sbe46]
- ld [wcf64], a
+ ld a, [sNrOfBeatenBattleTowerTrainers]
+ ld [wNrOfBeatenBattleTowerTrainers], a ; wcf64
call CloseSRAM
ld hl, StringBuffer3
- ld a, [wcf64]
+ ld a, [wNrOfBeatenBattleTowerTrainers] ; wcf64
add $f7
ld [hli], a
ld a, $50
@@ -22872,13 +22873,13 @@
ld a, $1
ld [wcf63], a
ret
-; 1702b7
+
; Initialise the BattleTower-Trainer and his Pkmn
Function1702b7: ; 1702b7
- call Function1704a2
+ call CopyBTTrainer_FromBT_OTrainer_TowBT_OTTempCopy
ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn1Name ; $c643
- ld c, $b
+ ld c, PKMN_NAME_LENGTH
callba Function17d073
jr nc, .asm_1702db
@@ -22893,7 +22894,7 @@
.asm_1702db
ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn2Name ; $c67e
- ld c, $b
+ ld c, PKMN_NAME_LENGTH
callba Function17d073
jr nc, .asm_1702fc
ld a, [wBT_OTTempCopy + wBT_OTTempCopy_Pkmn2] ; [$c64e]
@@ -22907,7 +22908,7 @@
.asm_1702fc
ld de, wBT_OTTempCopy + wBT_OTTempCopy_Pkmn3Name ; $c686 + 51 = $c6b9
- ld c, $b
+ ld c, PKMN_NAME_LENGTH
callba Function17d073
jr nc, .asm_17031d
ld a, [wBT_OTTempCopy + wBT_OTTempCopy_Pkmn3] ; [$c689]
@@ -22961,7 +22962,7 @@
ld [bc], a
inc bc
push bc
- ld bc, $0030
+ ld bc, BATTLETOWER_PKMNSTRUCTLENGTH
call CopyBytes
push de
ld a, [BGMapBuffer]
@@ -23167,16 +23168,18 @@
db $0f, $05, $14, $07
db $05, $05, $11, $0c
db $0c, $06, $06, $04
-; 1704a2
-Function1704a2: ; 1704a2
+
+CopyBTTrainer_FromBT_OTrainer_TowBT_OTTempCopy: ; 1704a2
+; copy the BattleTower-Trainer data that lies at 'BT_OTrainer' to 'wBT_OTTempCopy'
ld a, [rSVBK]
push af
ld a, $3
ld [rSVBK], a
- ld hl, $d100 ; this is NOT LYOverrides
- ld de, $c608
- ld bc, BT_OTrainerEnd - BT_OTrainer
+ ld hl, BT_OTrainer ; $d100
+ ld de, wBT_OTTempCopy ; $c608
+ ld bc, BT_OTrainerEnd - BT_OTrainer ; $e0 = $a + $1 + 3*$3b + $24
+ ; = $a + $1 + BATTLETOWER_NROFPKMNS * (BATTLETOWER_PKMNSTRUCTLENGTH + PKMN_NAME_LENGTH) + BATTLETOWER_TRAINERDATALENGTH
call CopyBytes
pop af
ld [rSVBK], a
@@ -23184,7 +23187,7 @@
call GetSRAMBank
ld a, $2
ld [s1_be45], a
- ld hl, sbe46
+ ld hl, sNrOfBeatenBattleTowerTrainers
inc [hl]
call CloseSRAM
Function1704c9:
@@ -23260,14 +23263,17 @@
Function170525: ; 170525
ld a, $5
call GetSRAMBank
+
ld hl, $a89c
ld de, StringBuffer3
ld bc, $0016
call CopyBytes
+
ld hl, $a8b2
ld de, $c608
ld bc, $0096
call CopyBytes
+
call CloseSRAM
hlcoord 1, 1
ld de, StringBuffer3
@@ -23285,10 +23291,12 @@
call Function1705f0
jr Function1705b2
+
Function170571:
call Function32f9
call Function1705b2
+
Function170577:
ld hl, hJoyPressed
ld a, [hl]
@@ -23530,7 +23538,7 @@
dw Function17081d ; 0x17
dw Function170ae8 ; 0x18
dw Function170b16 ; 0x19
- dw Function1706d6 ; 0x1a
+ dw ResetBattleTowerTrainersSRAM ; 0x1a
dw Function1706ee ; 0x1b
dw Function17071b ; 0x1c
dw Function170729 ; 0x1d
@@ -23539,21 +23547,26 @@
; Reset the save memory for BattleTower-Trainers (Counter and all 7 TrainerBytes)
-Function1706d6: ; 1706d6 (5c:46d6)
+ResetBattleTowerTrainersSRAM: ; 1706d6 (5c:46d6)
ld a, BANK(sBTTrainers)
call GetSRAMBank
+
ld a, $ff
ld hl, sBTTrainers
- ld bc, $7
+ ld bc, BATTLETOWER_NROFTRAINERS
call ByteFill
+
xor a
- ld [sbe46], a
+ ld [sNrOfBeatenBattleTowerTrainers], a
+
call CloseSRAM
+
ret
Function1706ee: ; 1706ee (5c:46ee)
ld a, BANK(sbe50)
call GetSRAMBank
+
ld a, [sbe50]
call CloseSRAM
ld [ScriptVar], a
--- a/wram.asm
+++ b/wram.asm
@@ -443,7 +443,7 @@
wMisc::
wBattle::
-wBT_OTTempCopy:: ; also used to copy the data of the BattleTower-Trainer and the 3 Pkmn
+wBT_OTTempCopy:: ; used to copy the data of the BattleTower-Trainer and the 3 Pkmn
wc608::
wEnemyMoveStruct:: ds MOVE_LENGTH ; c608
@@ -886,7 +886,7 @@
RSSET 0 ; Offsets for wBT_OTTempCopy:: @ $c608
-wBT_OTTempCopy_0 RB $a ; $c608
+wBT_OTTempCopy_0 RB $A ; $c608
wBT_OTTempCopy_TrainerClass RB $1 ; $c608 + $a = $c612
wBT_OTTempCopy_Pkmn1 RB $30 ; $c608 + $b = $c613
wBT_OTTempCopy_Pkmn1Name RB $A ; $c608 + $3b = $c643
@@ -897,7 +897,6 @@
wBT_OTTempCopy_Pkmn3 RB $30 ; $c608 + $81 = $c689
wBT_OTTempCopy_Pkmn3Name RB $A ; $c608 + $b1 = $c6b9
wBT_OTTempCopy_BB RB $1 ; $c608 + $bb = $c6c3
-;str_SIZEOF RB 0
GLOBAL wBT_OTTempCopy_TrainerClass, wBT_OTTempCopy_Pkmn1, wBT_OTTempCopy_Pkmn1Name, wBT_OTTempCopy_45, wBT_OTTempCopy_Pkmn2, wBT_OTTempCopy_Pkmn2Name, wBT_OTTempCopy_80, wBT_OTTempCopy_Pkmn3, wBT_OTTempCopy_Pkmn3Name, wBT_OTTempCopy_BB
@@ -1191,6 +1190,7 @@
wcf61:: ds 2
wcf63:: ds 1
+wNrOfBeatenBattleTowerTrainers::
wcf64:: ds 1
IF !DEF(CRYSTAL11)
wPokedexStatus::
@@ -2621,9 +2621,11 @@
ds $100
BT_OTrainer::
-w3_d100:: ; BattleTower OpponentTrainer-Data (lengt = 0xe0)
- ds $6
- ds $5
+w3_d100:: ; BattleTower OpponentTrainer-Data (length = 0xe0 = $a + $1 + 3*$3b + $24)
+BT_OTrainer_Name::
+ ds $A
+BT_OTrainer_TrainerClass::
+ ds $1
BT_OTPkmn1:: ; w3_d10b
ds $1
BT_OTPkmn1Item::
@@ -2642,6 +2644,7 @@
ds $620
+wBTChoiceOfLvlGroup::
w3_d800:: ds 1
@@ -2813,6 +2816,7 @@
; data of the BattleTower must be in SRAM because you can save and leave between battles
sBattleTower:: ; be46
+sNrOfBeatenBattleTowerTrainers::
sbe46:: ds 1
sbe47:: ds 1
; The 7 trainers of the BattleTower are saved here, so nobody appears more than once