summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluckytyphlosion <alan.rj.huang@gmail.com>2015-10-18 15:37:40 -0400
committerluckytyphlosion <alan.rj.huang@gmail.com>2015-10-18 15:37:40 -0400
commitbb97b63af1fbeca208cb30a41f8195b4408821dc (patch)
tree106b0bab693daa5335445b01c43a8cd4c851d231
parent35874024438c0a716ad3de8896207f02db56e7d1 (diff)
Complete documentation of bank3
Also: split out bcd predefs from yellow/main.asm, start removing traces of W_
-rw-r--r--.gitignore2
-rwxr-xr-xengine/battle/core.asm16
-rw-r--r--engine/battle/wild_encounters.asm2
-rw-r--r--engine/bcd.asm215
-rwxr-xr-xengine/cable_club.asm8
-rwxr-xr-xengine/give_pokemon.asm2
-rwxr-xr-xengine/hidden_object_functions3.asm72
-rwxr-xr-xengine/hp_bar.asm28
-rwxr-xr-xengine/items/items.asm22
-rwxr-xr-xengine/learn_move.asm12
-rw-r--r--engine/menu/bills_pc.asm10
-rwxr-xr-xengine/menu/main_menu.asm2
-rwxr-xr-xengine/menu/party_menu.asm8
-rwxr-xr-xengine/menu/start_sub_menus.asm2
-rwxr-xr-xengine/menu/status_screen.asm2
-rwxr-xr-xengine/overworld/cut.asm2
-rwxr-xr-xengine/overworld/doors.asm2
-rwxr-xr-xengine/overworld/ledges.asm2
-rwxr-xr-xengine/overworld/player_animations.asm2
-rwxr-xr-xengine/palettes.asm6
-rwxr-xr-xengine/save.asm4
-rw-r--r--home.asm2
-rw-r--r--home/overworld.asm22
-rw-r--r--hram.asm6
-rw-r--r--macros.asm4
-rwxr-xr-xmain.asm284
-rwxr-xr-xscripts/celadongym.asm2
-rwxr-xr-xscripts/ceruleangym.asm2
-rwxr-xr-xscripts/cinnabargym.asm2
-rwxr-xr-xscripts/fuchsiagym.asm2
-rwxr-xr-xscripts/pewtergym.asm2
-rwxr-xr-xscripts/rockethideout2.asm2
-rwxr-xr-xscripts/route22gate.asm2
-rwxr-xr-xscripts/route23.asm2
-rwxr-xr-xscripts/saffrongym.asm2
-rwxr-xr-xscripts/vermiliongym.asm2
-rwxr-xr-xscripts/viridiancity.asm4
-rwxr-xr-xscripts/viridiangym.asm2
-rwxr-xr-xwram.asm14
-rwxr-xr-xyellow/main.asm721
40 files changed, 1206 insertions, 294 deletions
diff --git a/.gitignore b/.gitignore
index 93a8c6eb..87145a25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,4 +53,4 @@ replace.sh
.lvimrc
# extras is a submodule, don't include
-extras/
+extras/ \ No newline at end of file
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index 8a46c705..e5fd98f8 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -2557,13 +2557,13 @@ MoveSelectionMenu: ; 3d219 (f:5219)
.writemoves
ld de, wMovesString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
set 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
call PlaceString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
res 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
ret
.regularmenu
@@ -2682,10 +2682,10 @@ SelectMenuItem: ; 3d2fe (f:52fe)
call AddNTimes
ld [hl], $ec
.select
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
bit 6, a
jp nz, CursorUp ; up
@@ -4053,7 +4053,7 @@ CheckForDisobedience: ; 3dc88 (f:5c88)
; it was traded
.monIsTraded
; what level might disobey?
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
bit 7, [hl]
ld a, 101
jr nz, .next
@@ -6660,7 +6660,7 @@ ApplyBadgeStatBoosts: ; 3ee19 (f:6e19)
ld a, [wLinkState]
cp LINK_STATE_BATTLING
ret z ; return if link battle
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
ld b, a
ld hl, wBattleMonAttack
ld c, $4
diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm
index 144234bb..908bd493 100644
--- a/engine/battle/wild_encounters.asm
+++ b/engine/battle/wild_encounters.asm
@@ -41,7 +41,7 @@ TryDoWildEncounter: ; 13870 (4:7870)
ld a, [W_CURMAP]
cp REDS_HOUSE_1F ; is this an indoor map?
jr c, .CantEncounter2
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp FOREST ; Viridian Forest/Safari Zone
jr z, .CantEncounter2
ld a, [W_GRASSRATE]
diff --git a/engine/bcd.asm b/engine/bcd.asm
new file mode 100644
index 00000000..a5322702
--- /dev/null
+++ b/engine/bcd.asm
@@ -0,0 +1,215 @@
+; divide hMoney by hDivideBCDDivisor
+; return output in hDivideBCDQuotient (same as hDivideBCDDivisor)
+; used only to halve player money upon losing a fight
+DivideBCDPredef:: ; f5a4 (3:75a4)
+DivideBCDPredef2::
+DivideBCDPredef3:: ; only used function
+DivideBCDPredef4::
+ call GetPredefRegisters
+
+DivideBCD:: ; f5a8 (3:75a8)
+ xor a
+ ld [hDivideBCDBuffer], a
+ ld [hDivideBCDBuffer + 1], a
+ ld [hDivideBCDBuffer + 2], a
+ ld d, $1
+.asm_f5b0
+ ld a, [hDivideBCDDivisor]
+ and $f0
+ jr nz, .asm_f5e1
+ inc d
+ ld a, [hDivideBCDDivisor]
+ swap a
+ and $f0
+ ld b, a
+ ld a, [hDivideBCDDivisor + 1]
+ swap a
+ ld [hDivideBCDDivisor + 1], a
+ and $f
+ or b
+ ld [hDivideBCDDivisor], a
+ ld a, [hDivideBCDDivisor + 1]
+ and $f0
+ ld b, a
+ ld a, [hDivideBCDDivisor + 2]
+ swap a
+ ld [hDivideBCDDivisor + 2], a
+ and $f
+ or b
+ ld [hDivideBCDDivisor + 1], a
+ ld a, [hDivideBCDDivisor + 2]
+ and $f0
+ ld [hDivideBCDDivisor + 2], a
+ jr .asm_f5b0
+.asm_f5e1
+ push de
+ push de
+ call DivideBCD_f686
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [hDivideBCDBuffer], a
+ dec d
+ jr z, .asm_f642
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, [hDivideBCDBuffer]
+ or b
+ ld [hDivideBCDBuffer], a
+ dec d
+ jr z, .asm_f642
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [hDivideBCDBuffer + 1], a
+ dec d
+ jr z, .asm_f642
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, [hDivideBCDBuffer + 1]
+ or b
+ ld [hDivideBCDBuffer + 1], a
+ dec d
+ jr z, .asm_f642
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [hDivideBCDBuffer + 2], a
+ dec d
+ jr z, .asm_f642
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, [hDivideBCDBuffer + 2]
+ or b
+ ld [hDivideBCDBuffer + 2], a
+.asm_f642
+ ld a, [hDivideBCDBuffer]
+ ld [hDivideBCDQuotient], a
+ ld a, [hDivideBCDBuffer + 1]
+ ld [hDivideBCDQuotient + 1], a
+ ld a, [hDivideBCDBuffer + 2]
+ ld [hDivideBCDQuotient + 2], a
+ pop de
+ ld a, $6
+ sub d
+ and a
+ ret z
+.asm_f654
+ push af
+ call DivideBCD_f65d
+ pop af
+ dec a
+ jr nz, .asm_f654
+ ret
+
+DivideBCD_f65d: ; f65d (3:765d)
+ ld a, [hDivideBCDDivisor + 2]
+ swap a
+ and $f
+ ld b, a
+ ld a, [hDivideBCDDivisor + 1]
+ swap a
+ ld [hDivideBCDDivisor + 1], a
+ and $f0
+ or b
+ ld [hDivideBCDDivisor + 2], a
+ ld a, [hDivideBCDDivisor + 1]
+ and $f
+ ld b, a
+ ld a, [hDivideBCDDivisor]
+ swap a
+ ld [hDivideBCDDivisor], a
+ and $f0
+ or b
+ ld [hDivideBCDDivisor + 1], a
+ ld a, [hDivideBCDDivisor]
+ and $f
+ ld [hDivideBCDDivisor], a
+ ret
+
+DivideBCD_f686: ; f686 (3:7686)
+ ld bc, $3
+.asm_f689
+ ld de, hMoney
+ ld hl, hDivideBCDDivisor
+ push bc
+ call StringCmp
+ pop bc
+ ret c
+ inc b
+ ld de, hMoney + 2
+ ld hl, hDivideBCDDivisor + 2
+ push bc
+ call SubBCD
+ pop bc
+ jr .asm_f689
+
+
+AddBCDPredef:: ; f6a3 (3:76a3)
+ call GetPredefRegisters
+
+AddBCD:: ; f6a6 (3:76a6)
+ and a
+ ld b, c
+.add
+ ld a, [de]
+ adc [hl]
+ daa
+ ld [de], a
+ dec de
+ dec hl
+ dec c
+ jr nz, .add
+ jr nc, .done
+ ld a, $99
+ inc de
+.fill
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .fill
+.done
+ ret
+
+
+SubBCDPredef:: ; f6bc (3:76bc)
+ call GetPredefRegisters
+
+SubBCD:: ; f6bf (3:76bf)
+ and a
+ ld b, c
+.sub
+ ld a, [de]
+ sbc [hl]
+ daa
+ ld [de], a
+ dec de
+ dec hl
+ dec c
+ jr nz, .sub
+ jr nc, .done
+ ld a, $00
+ inc de
+.fill
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .fill
+ scf
+.done
+ ret \ No newline at end of file
diff --git a/engine/cable_club.asm b/engine/cable_club.asm
index 465561ca..059b309a 100755
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -338,10 +338,10 @@ TradeCenter_SelectMon:
ld a, 1
ld [wTopMenuItemX], a
.enemyMonMenu_HandleInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
and a
jp z, .getNewInput
@@ -403,10 +403,10 @@ TradeCenter_SelectMon:
lb bc, 6, 1
call ClearScreenArea
.playerMonMenu_HandleInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
and a ; was anything pressed?
jr nz, .playerMonMenu_SomethingPressed
diff --git a/engine/give_pokemon.asm b/engine/give_pokemon.asm
index 410c9c33..7de90e55 100755
--- a/engine/give_pokemon.asm
+++ b/engine/give_pokemon.asm
@@ -7,7 +7,7 @@ _GivePokemon: ; f66fa (3d:66fa)
ld a, [wPartyCount]
cp PARTY_LENGTH
jr c, .addToParty
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
cp MONS_PER_BOX
jr nc, .boxFull
; add to box
diff --git a/engine/hidden_object_functions3.asm b/engine/hidden_object_functions3.asm
index 80251b94..ba6d1fd3 100755
--- a/engine/hidden_object_functions3.asm
+++ b/engine/hidden_object_functions3.asm
@@ -1,10 +1,10 @@
; prints text for bookshelves in buildings without sign events
-PrintBookshelfText: ; fb50 (3:7b50)
+PrintBookshelfText: ; f9de (3:79de)
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
cp SPRITE_FACING_UP
jr nz, .noMatch
; facing up
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld b, a
aCoord 8, 7
ld c, a
@@ -37,95 +37,95 @@ PrintBookshelfText: ; fb50 (3:7b50)
jpba PrintCardKeyText
; format: db tileset id, bookshelf tile id, text id
-BookshelfTileIDs: ; fb8b (3:7b8b)
+BookshelfTileIDs: ; fa19 (3:7a19)
db PLATEAU, $30
- db (IndigoPlateauStatues_id - TextPredefs) / 2 + 1
+ db_tx_pre IndigoPlateauStatues
db HOUSE, $3D
- db (TownMapText_id - TextPredefs) / 2 + 1
+ db_tx_pre TownMapText
db HOUSE, $1E
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db MANSION, $32
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db REDS_HOUSE_1, $32
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db LAB, $28
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db LOBBY, $16
- db (ElevatorText_id - TextPredefs) / 2 + 1
+ db_tx_pre ElevatorText
db GYM, $1D
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db DOJO, $1D
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db GATE, $22
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db MART, $54
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db MART, $55
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db POKECENTER, $54
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db POKECENTER, $55
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db LOBBY, $50
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db LOBBY, $52
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db SHIP, $36
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db $FF
-IndigoPlateauStatues: ; fbbf (3:7bbf)
+IndigoPlateauStatues: ; fa4d (3:7a4d)
TX_ASM
ld hl, IndigoPlateauStatuesText1
call PrintText
ld a, [W_XCOORD]
bit 0, a
ld hl, IndigoPlateauStatuesText2
- jr nz, .asm_fbd3
+ jr nz, .asm_fa61
ld hl, IndigoPlateauStatuesText3
-.asm_fbd3
+.asm_fa61
call PrintText
jp TextScriptEnd
-IndigoPlateauStatuesText1: ; fbd9 (3:7bd9)
+IndigoPlateauStatuesText1: ; fa67 (3:7a67)
TX_FAR _IndigoPlateauStatuesText1
db "@"
-IndigoPlateauStatuesText2: ; fbde (3:7bde)
+IndigoPlateauStatuesText2: ; fa6c (3:7a6c)
TX_FAR _IndigoPlateauStatuesText2
db "@"
-IndigoPlateauStatuesText3: ; fbe3 (3:7be3)
+IndigoPlateauStatuesText3: ; fa71 (3:7a71)
TX_FAR _IndigoPlateauStatuesText3
db "@"
-BookOrSculptureText: ; fbe8 (3:7be8)
+BookOrSculptureText: ; fa76 (3:7a76)
TX_ASM
ld hl, PokemonBooksText
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp MANSION ; Celadon Mansion tileset
- jr nz, .asm_fbfd
+ jr nz, .asm_fa8b
aCoord 8, 6
cp $38
- jr nz, .asm_fbfd
+ jr nz, .asm_fa8b
ld hl, DiglettSculptureText
-.asm_fbfd
+.asm_fa8b
call PrintText
jp TextScriptEnd
-PokemonBooksText: ; fc03 (3:7c03)
+PokemonBooksText: ; fa91 (3:7a91)
TX_FAR _PokemonBooksText
db "@"
-DiglettSculptureText: ; fc08 (3:7c08)
+DiglettSculptureText: ; fa96 (3:7a96)
TX_FAR _DiglettSculptureText
db "@"
-ElevatorText: ; fc0d (3:7c0d)
+ElevatorText: ; fa9b (3:7a9b)
TX_FAR _ElevatorText
db "@"
-TownMapText: ; fc12 (3:7c12)
+TownMapText: ; faa0 (3:7aa0)
TX_FAR _TownMapText
db $06
TX_ASM
@@ -148,6 +148,6 @@ TownMapText: ; fc12 (3:7c12)
push af
jp CloseTextDisplay
-PokemonStuffText: ; fc45 (3:7c45)
+PokemonStuffText: ; fad3 (3:7ad3)
TX_FAR _PokemonStuffText
db "@"
diff --git a/engine/hp_bar.asm b/engine/hp_bar.asm
index 792661ab..789f1bd7 100755
--- a/engine/hp_bar.asm
+++ b/engine/hp_bar.asm
@@ -1,9 +1,9 @@
-HPBarLength: ; f9dc (3:79dc)
+HPBarLength: ; f86c (3:786c)
call GetPredefRegisters
; calculates bc * 48 / de, the number of pixels the HP bar has
; the result is always at least 1
-GetHPBarLength: ; f9df (3:79df)
+GetHPBarLength: ; f86f (3:786f)
push hl
xor a
ld hl, H_MULTIPLICAND
@@ -45,7 +45,7 @@ GetHPBarLength: ; f9df (3:79df)
ret
; predef $48
-UpdateHPBar: ; fa1d (3:7a1d)
+UpdateHPBar: ; f8ad (3:78ad)
UpdateHPBar2:
push hl
ld hl, wHPBarOldHP
@@ -95,7 +95,7 @@ UpdateHPBar2:
call UpdateHPBar_CalcOldNewHPBarPixels
ld a, e
sub d ; calc pixel difference
- jr .asm_fa7e
+ jr .asm_f90e
.HPIncrease
inc bc ; add 1 HP
ld a, c
@@ -105,7 +105,7 @@ UpdateHPBar2:
call UpdateHPBar_CalcOldNewHPBarPixels
ld a, d
sub e ; calc pixel difference
-.asm_fa7e
+.asm_f90e
call UpdateHPBar_PrintHPNumber
and a
jr z, .noPixelDifference
@@ -136,7 +136,7 @@ UpdateHPBar2:
; animates the HP bar going up or down for (a) ticks (two waiting frames each)
; stops prematurely if bar is filled up
; e: current health (in pixels) to start with
-UpdateHPBar_AnimateHPBar: ; fab1 (3:7ab1)
+UpdateHPBar_AnimateHPBar: ; f941 (3:7941)
push hl
.barAnimationLoop
push af
@@ -162,7 +162,7 @@ UpdateHPBar_AnimateHPBar: ; fab1 (3:7ab1)
ret
; compares old HP and new HP and sets c and z flags accordingly
-UpdateHPBar_CompareNewHPToOldHP: ; fad1 (3:7ad1)
+UpdateHPBar_CompareNewHPToOldHP: ; f961 (3:7961)
ld a, d
sub b
ret nz
@@ -171,7 +171,7 @@ UpdateHPBar_CompareNewHPToOldHP: ; fad1 (3:7ad1)
ret
; calcs HP difference between bc and de (into de)
-UpdateHPBar_CalcHPDifference: ; fad7 (3:7ad7)
+UpdateHPBar_CalcHPDifference: ; f967 (3:7967)
ld a, d
sub b
jr c, .oldHPGreater
@@ -200,7 +200,7 @@ UpdateHPBar_CalcHPDifference: ; fad7 (3:7ad7)
ld de, $0
ret
-UpdateHPBar_PrintHPNumber: ; faf5 (3:7af5)
+UpdateHPBar_PrintHPNumber: ; f985 (3:7985)
push af
push de
ld a, [wHPBarType]
@@ -212,13 +212,11 @@ UpdateHPBar_PrintHPNumber: ; faf5 (3:7af5)
ld a, [wHPBarOldHP + 1]
ld [wHPBarTempHP], a
push hl
- ld a, [hFlags_0xFFF6]
+ ld de, $15
+ ld a, [hFlags_0xFFFA]
bit 0, a
- jr z, .asm_fb15
+ jr z, .next
ld de, $9
- jr .next
-.asm_fb15
- ld de, $15
.next
add hl, de
push hl
@@ -240,7 +238,7 @@ UpdateHPBar_PrintHPNumber: ; faf5 (3:7af5)
; calcs number of HP bar pixels for old and new HP value
; d: new pixels
; e: old pixels
-UpdateHPBar_CalcOldNewHPBarPixels: ; fb30 (3:7b30)
+UpdateHPBar_CalcOldNewHPBarPixels: ; f9be (3:79be)
push hl
ld hl, wHPBarMaxHP
ld a, [hli] ; max HP into de
diff --git a/engine/items/items.asm b/engine/items/items.asm
index 533da448..3afae425 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -114,7 +114,7 @@ ItemUseBall: ; d3ad (3:53ad)
ld a,[wPartyCount] ;is Party full?
cp a,PARTY_LENGTH
jr nz,.UseBall
- ld a,[W_NUMINBOX] ;is Box full?
+ ld a,[wNumInBox] ;is Box full?
cp a,MONS_PER_BOX
jp z,BoxFullCannotThrowBall
.UseBall
@@ -1483,7 +1483,7 @@ ItemUseEscapeRope: ; ddcf (3:5dcf)
jr z,.notUsable
cp a,POKEMON_FAN_CLUB
jr z,.notUsable
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld b,a
ld hl,EscapeRopeTilesets
.loop
@@ -2800,7 +2800,7 @@ IsKeyItem_: ; e6a8 (3:66a8)
INCLUDE "data/key_items.asm"
SendNewMonToBox: ; e6e8 (3:66e8)
- ld de, W_NUMINBOX
+ ld de, wNumInBox
ld a, [de]
inc a
ld [de], a
@@ -2819,7 +2819,7 @@ SendNewMonToBox: ; e6e8 (3:66e8)
call GetMonHeader
ld hl, wBoxMonOT
ld bc, NAME_LENGTH
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
dec a
jr z, .asm_e732
dec a
@@ -2830,7 +2830,7 @@ SendNewMonToBox: ; e6e8 (3:66e8)
ld d, h
ld e, l
pop hl
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
dec a
ld b, a
.asm_e71f
@@ -2851,7 +2851,7 @@ SendNewMonToBox: ; e6e8 (3:66e8)
ld de, wBoxMonOT
ld bc, NAME_LENGTH
call CopyData
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
dec a
jr z, .asm_e76e
ld hl, wBoxMonNicks
@@ -2864,7 +2864,7 @@ SendNewMonToBox: ; e6e8 (3:66e8)
ld d, h
ld e, l
pop hl
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
dec a
ld b, a
.asm_e75b
@@ -2885,7 +2885,7 @@ SendNewMonToBox: ; e6e8 (3:66e8)
ld a, NAME_MON_SCREEN
ld [wNamingScreenType], a
predef AskName
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
dec a
jr z, .asm_e7ab
ld hl, wBoxMons
@@ -2898,7 +2898,7 @@ SendNewMonToBox: ; e6e8 (3:66e8)
ld d, h
ld e, l
pop hl
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
dec a
ld b, a
.asm_e798
@@ -2975,13 +2975,13 @@ SendNewMonToBox: ; e6e8 (3:66e8)
; used for surfing and fishing
; unsets carry if it is, sets carry if not
IsNextTileShoreOrWater: ; e808 (3:6808)
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld hl, WaterTilesets
ld de,1
call IsInArray ; does the current map allow surfing?
ret nc ; if not, return
ld hl,WaterTile
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp SHIP_PORT ; Vermilion Dock tileset
jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset
cp GYM ; eastern shore tile in Safari Zone
diff --git a/engine/learn_move.asm b/engine/learn_move.asm
index c0ced4a0..ba96f29f 100755
--- a/engine/learn_move.asm
+++ b/engine/learn_move.asm
@@ -126,13 +126,13 @@ TryingToLearn: ; 6f07 (1:6f07)
call TextBoxBorder
coord hl, 6, 8
ld de, wMovesString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
set 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
call PlaceString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
res 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
ld hl, wTopMenuItemY
ld a, 8
ld [hli], a ; wTopMenuItemY
@@ -146,10 +146,10 @@ TryingToLearn: ; 6f07 (1:6f07)
ld a, A_BUTTON | B_BUTTON
ld [hli], a ; wMenuWatchedKeys
ld [hl], 0 ; wLastMenuItem
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
push af
call LoadScreenTilesFromBuffer1
diff --git a/engine/menu/bills_pc.asm b/engine/menu/bills_pc.asm
index 3f0db4ea..4a274871 100644
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -218,7 +218,7 @@ BillsPCDeposit: ; 2156d (8:556d)
call PrintText
jp BillsPCMenu
.partyLargeEnough
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
cp MONS_PER_BOX
jr nz, .boxNotFull
ld hl, BoxFullText
@@ -279,7 +279,7 @@ SleepingPikachuText2: ; 2160e (8:560e)
db "@"
BillsPCWithdraw: ; 21613 (8:5613)
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
and a
jr nz, .boxNotEmpty
ld hl, NoMonText
@@ -293,7 +293,7 @@ BillsPCWithdraw: ; 21613 (8:5613)
call PrintText
jp BillsPCMenu
.partyNotFull
- ld hl, W_NUMINBOX
+ ld hl, wNumInBox
call DisplayMonListMenu
jp c, BillsPCMenu
call DisplayDepositWithdrawMenu
@@ -322,14 +322,14 @@ BillsPCWithdraw: ; 21613 (8:5613)
jp BillsPCMenu
BillsPCRelease: ; 21690 (8:5690)
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
and a
jr nz, .loop
ld hl, NoMonText
call PrintText
jp BillsPCMenu
.loop
- ld hl, W_NUMINBOX
+ ld hl, wNumInBox
call DisplayMonListMenu
jp c, BillsPCMenu
callab Func_fce0d
diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm
index 6c109cec..98f1efdd 100755
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -392,7 +392,7 @@ PrintSaveScreenText: ; 5def (1:5def)
PrintNumBadges: ; 5e2f (1:5e2f)
push hl
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
ld b, $1
call CountSetBits
pop hl
diff --git a/engine/menu/party_menu.asm b/engine/menu/party_menu.asm
index f3e1a138..293ed255 100755
--- a/engine/menu/party_menu.asm
+++ b/engine/menu/party_menu.asm
@@ -88,14 +88,14 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
pop hl
push hl
ld bc,20 + 1 ; down 1 row and right 1 column
- ld a,[hFlags_0xFFF6]
+ ld a,[hFlags_0xFFFA]
set 0,a
- ld [hFlags_0xFFF6],a
+ ld [hFlags_0xFFFA],a
add hl,bc
predef DrawHP2 ; draw HP bar and prints current / max HP
- ld a,[hFlags_0xFFF6]
+ ld a,[hFlags_0xFFFA]
res 0,a
- ld [hFlags_0xFFF6],a
+ ld [hFlags_0xFFFA],a
call SetPartyMenuHPBarColor ; color the HP bar (on SGB)
pop hl
jr .printLevel
diff --git a/engine/menu/start_sub_menus.asm b/engine/menu/start_sub_menus.asm
index ab8c8756..dcbee277 100755
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -117,7 +117,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld a,[hli]
ld h,[hl]
ld l,a
- ld a,[W_OBTAINEDBADGES] ; badges obtained
+ ld a,[wObtainedBadges] ; badges obtained
jp [hl]
.outOfBattleMovePointers
dw .cut
diff --git a/engine/menu/status_screen.asm b/engine/menu/status_screen.asm
index c91d5eda..8775a8d9 100755
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -40,7 +40,7 @@ DrawHP_: ; 128fb (4:68fb)
push hl
call DrawHPBar
pop hl
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
bit 0, a
jr z, .printFractionBelowBar
ld bc, $9 ; right of bar
diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm
index 276ec93e..8c863bf2 100755
--- a/engine/overworld/cut.asm
+++ b/engine/overworld/cut.asm
@@ -1,7 +1,7 @@
UsedCut: ; edd1 (3:6dd1)
xor a
ld [wActionResultOrTookBattleTurn], a ; initialise to failure value
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; OVERWORLD
jr z, .overworld
cp GYM
diff --git a/engine/overworld/doors.asm b/engine/overworld/doors.asm
index 641c021f..6b0c0464 100755
--- a/engine/overworld/doors.asm
+++ b/engine/overworld/doors.asm
@@ -2,7 +2,7 @@
IsPlayerStandingOnDoorTile: ; 1a609 (6:6609)
push de
ld hl, DoorTileIDPointers
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld de, $3
call IsInArray
pop de
diff --git a/engine/overworld/ledges.asm b/engine/overworld/ledges.asm
index df4273fd..b04f6332 100755
--- a/engine/overworld/ledges.asm
+++ b/engine/overworld/ledges.asm
@@ -2,7 +2,7 @@ HandleLedges: ; 1a672 (6:6672)
ld a, [wd736]
bit 6, a ; already jumping down ledge
ret nz
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; OVERWORLD
ret nz
predef GetTileAndCoordsInFrontOfPlayer
diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm
index 6488eaac..ff579a04 100755
--- a/engine/overworld/player_animations.asm
+++ b/engine/overworld/player_animations.asm
@@ -357,7 +357,7 @@ GetPlayerTeleportAnimFrameDelay: ; 707df (1c:47df)
IsPlayerStandingOnWarpPadOrHole: ; 707e7 (1c:47e7)
ld b, 0
ld hl, .warpPadAndHoleData
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld c, a
.loop
ld a, [hli]
diff --git a/engine/palettes.asm b/engine/palettes.asm
index 8182315c..722b7804 100755
--- a/engine/palettes.asm
+++ b/engine/palettes.asm
@@ -147,7 +147,7 @@ SetPal_Overworld: ; 71fa5 (1c:5fa5)
ld de, wPalPacket
ld bc, $10
call CopyData
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp CEMETERY
jr z, .PokemonTowerOrAgatha
cp CAVERN
@@ -222,7 +222,7 @@ SetPal_TrainerCard: ; 72025 (1c:6025)
call CopyData
ld de, BadgeBlkDataLengths
ld hl, wTrainerCardBlkPacket + 2
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
ld c, 8
.badgeLoop
srl a
@@ -391,7 +391,7 @@ Func_720e3:: ; 720e3 (1c:60e3)
Func_7213b:: ; 7213b (1c:613b)
; similar to SetPal_Overworld
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp CEMETERY
jr z, .PokemonTowerOrAgatha
cp CAVERN
diff --git a/engine/save.asm b/engine/save.asm
index a75ec41c..bd557135 100755
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -61,7 +61,7 @@ LoadSAV0: ; 73994 (1c:7994)
ld de, wMainDataStart
ld bc, wMainDataEnd - wMainDataStart
call CopyData
- ld hl, W_CURMAPTILESET
+ ld hl, wCurMapTileset
set 7, [hl]
ld hl, sSpriteData
ld de, wSpriteDataStart
@@ -554,7 +554,7 @@ GetMonCountsForAllBoxes: ; 73a84 (1c:7a84)
ld c, a
ld b, 0
add hl, bc
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
ld [hl], a
ret
diff --git a/home.asm b/home.asm
index 6b802444..2ac9795b 100644
--- a/home.asm
+++ b/home.asm
@@ -4093,7 +4093,7 @@ AddEnemyMonToPlayerParty:: ; 3a48 (0:3a48)
ret
MoveMon:: ; 3a59 (0:3a59)
- homecall_sf Func_f3a4
+ homecall_sf _MoveMon
ret
; skips a text entries, each of size NAME_LENGTH (like trainer name, OT name, rival name, ...)
diff --git a/home/overworld.asm b/home/overworld.asm
index a36254ae..d851db7e 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -122,7 +122,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
; call SpecialWarpIn
; ld a,[W_CURMAP]
; call SwitchToMapRomBank ; switch to the ROM bank of the current map
-; ld hl,W_CURMAPTILESET
+; ld hl,wCurMapTileset
; set 7,[hl]
.checkForOpponent
ld a,[W_CUROPPONENT]
@@ -656,7 +656,7 @@ CheckMapConnections:: ; 05db (0:05db)
; function to play a sound when changing maps
PlayMapChangeSound:: ; 06ef (0:06ef)
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
cp FACILITY
jr z,.didNotGoThroughDoor
cp CEMETERY
@@ -677,7 +677,7 @@ PlayMapChangeSound:: ; 06ef (0:06ef)
CheckIfInOutsideMap:: ; 0712 (0:0712)
; If the player is in an outside map (a town or route), set the z flag
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; most towns/routes have tileset 0 (OVERWORLD)
ret z
cp PLATEAU ; Route 23 / Indigo Plateau
@@ -701,7 +701,7 @@ ExtraWarpCheck:: ; 071a (0:071a)
jr z, .useFunction2
cp ROCK_TUNNEL_1
jr z, .useFunction2
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
and a ; outside tileset (OVERWORLD)
jr z, .useFunction2
cp SHIP ; S.S. Anne tileset
@@ -829,7 +829,7 @@ IsBikeRidingAllowed:: ; 0805 (0:0805)
cp INDIGO_PLATEAU
jr z, .allowed
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld b, a
ld hl, BikeRidingTilesets
.loop
@@ -1289,7 +1289,7 @@ CheckForTilePairCollisions:: ; 0aa6 (0:0aa6)
ld a,[wTileInFrontOfPlayer]
ld c,a
.tilePairCollisionLoop
- ld a,[W_CURMAPTILESET] ; tileset number
+ ld a,[wCurMapTileset] ; tileset number
ld b,a
ld a,[hli]
cp a,$ff
@@ -1709,7 +1709,7 @@ CollisionCheckOnWater:: ; 0cca (0:0cca)
scf
jr .done
.checkIfVermilionDockTileset
- ld a, [W_CURMAPTILESET] ; tileset
+ ld a, [wCurMapTileset] ; tileset
cp SHIP_PORT ; Vermilion Dock tileset
jr nz, .noCollision ; keep surfing if it's not the boarding platform tile
jr .stopSurfing ; if it is the boarding platform tile, stop surfing
@@ -1814,20 +1814,20 @@ LoadMapHeader:: ; 0dab (0:0dab)
jr .asm_0dbd
callba Func_f0a55 ; 3c:4a55
.asm_0dbd
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld [wUnusedD119],a
ld a,[W_CURMAP]
call SwitchToMapRomBank
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld b,a
res 7,a
- ld [W_CURMAPTILESET],a
+ ld [wCurMapTileset],a
ld [hPreviousTileset],a
bit 7,b
ret nz
call GetMapHeaderPointer
; copy the first 10 bytes (the fixed area) of the map data to D367-D370
- ld de,W_CURMAPTILESET
+ ld de,wCurMapTileset
ld c,$0a
.copyFixedHeaderLoop
ld a,[hli]
diff --git a/hram.asm b/hram.asm
index 29d38ecb..37eaf029 100644
--- a/hram.asm
+++ b/hram.asm
@@ -155,6 +155,8 @@ hCoins EQU $FFA0 ; 2-byte BCD number
hDivideBCDDivisor EQU $FFA2 ; 3-byte BCD number
hDivideBCDQuotient EQU $FFA2 ; 3-byte BCD number
+hDivideBCDBuffer EQU $FFA5 ; 3 bytes
+
hSerialReceivedNewData EQU $FFA9
@@ -322,8 +324,6 @@ hReadJoypad EQU $FFF8 ; 0 to read joypad, anything else skips joypad check
; bit 0: draw HP fraction to the right of bar instead of below (for party menu)
; bit 1: menu is double spaced
-hFlags_0xFFF6 EQU $FFFA
-
hFlags_0xFFFA EQU $FFFA
-hGBC EQU $FFFE ; 0 if DMG, 1 if GBC
+hGBC EQU $FFFE ; 0 if DMG, != 0 if GBC
diff --git a/macros.asm b/macros.asm
index effe098c..64ac7e08 100644
--- a/macros.asm
+++ b/macros.asm
@@ -303,6 +303,10 @@ add_tx_pre: MACRO
\1_id:: dw \1
ENDM
+db_tx_pre: MACRO
+ db \1_id
+ENDM
+
tx_pre_id: MACRO
ld a, \1_id ; - TextPredefs) / 2 + 1
ENDM
diff --git a/main.asm b/main.asm
index 2b978922..1b29f91c 100755
--- a/main.asm
+++ b/main.asm
@@ -497,7 +497,7 @@ TestBattle:
; Don't mess around
; with obedience.
ld a, %10000000 ; EARTHBADGE
- ld [W_OBTAINEDBADGES], a
+ ld [wObtainedBadges], a
ld hl, W_FLAGS_D733
set 0, [hl]
@@ -616,7 +616,7 @@ LoadSpecialWarpData: ; 62ff (1:62ff)
dec c
jr nz, .copyWarpDataLoop
ld a, [hli]
- ld [W_CURMAPTILESET], a
+ ld [wCurMapTileset], a
xor a
jr .done
.notFirstMap
@@ -689,7 +689,7 @@ LoadSpecialWarpData: ; 62ff (1:62ff)
dec c
jr nz, .copyWarpDataLoop2
xor a ; OVERWORLD
- ld [W_CURMAPTILESET], a
+ ld [wCurMapTileset], a
.done
ld [wYOffsetSinceLastSpecialWarp], a
ld [wXOffsetSinceLastSpecialWarp], a
@@ -1883,7 +1883,7 @@ _RemovePokemon: ; 7b68 (1:7b68)
ld a, [wRemoveMonFromBox]
and a
jr z, .asm_7b74
- ld hl, W_NUMINBOX
+ ld hl, wNumInBox
.asm_7b74
ld a, [hl]
dec a
@@ -2232,7 +2232,7 @@ IsPlayerStandingOnDoorTileOrWarpTile: ; c1e6 (3:41e6)
push bc
callba IsPlayerStandingOnDoorTile ; 6:6785
jr c, .done
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
add a
ld c, a
ld b, $0
@@ -2630,7 +2630,7 @@ LoadTilesetHeader: ; c4f4 (3:44f4)
call GetPredefRegisters
push hl
ld d, 0
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
add a
add a
ld e, a
@@ -2646,7 +2646,7 @@ LoadTilesetHeader: ; c4f4 (3:44f4)
xor a
ld [$ffd8], a
pop hl
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
push hl
push de
ld hl, DungeonTilesets
@@ -2655,7 +2655,7 @@ LoadTilesetHeader: ; c4f4 (3:44f4)
pop de
pop hl
jr c, .notDungeonTileset
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld b, a
ld a, [hPreviousTileset]
cp b
@@ -2814,7 +2814,7 @@ DrawBadges: ; ea03 (3:6a03)
; Alter these based on owned badges.
ld de, wTempObtainedBadgesBooleans
ld hl, wBadgeOrFaceTiles
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
ld b, a
ld c, 8
.CheckBadge
@@ -3707,7 +3707,7 @@ _AddEnemyMonToPlayerParty: ; f49d (3:749d)
and a
ret ; return success
-_MoveMon: ; f51e (3:751e)
+_MoveMon: ; f3a4 (3:73a4)
ld a, [wMoveMonType]
and a
jr z, .checkPartyMonSlots
@@ -3716,7 +3716,7 @@ _MoveMon: ; f51e (3:751e)
cp PARTY_TO_DAYCARE
ld hl, wDayCareMon
jr z, .asm_f575
- ld hl, W_NUMINBOX
+ ld hl, wNumInBox
ld a, [hl]
cp MONS_PER_BOX
jr nz, .partyOrBoxNotFull
@@ -3738,9 +3738,9 @@ _MoveMon: ; f51e (3:751e)
ld a, [wMoveMonType]
cp DAYCARE_TO_PARTY
ld a, [wDayCareMon]
- jr z, .asm_f556
+ jr z, .asm_f3dc
ld a, [wcf91]
-.asm_f556
+.asm_f3dc
ld [hli], a ; write new mon ID
ld [hl], $ff ; write new sentinel
ld a, [wMoveMonType]
@@ -3751,11 +3751,11 @@ _MoveMon: ; f51e (3:751e)
jr nz, .skipToNewMonEntry
ld hl, wBoxMons
ld bc, wBoxMon2 - wBoxMon1 ; $21
- ld a, [W_NUMINBOX]
+ ld a, [wNumInBox]
.skipToNewMonEntry
dec a
call AddNTimes
-.asm_f575
+.asm_f3fb
push hl
ld e, l
ld d, h
@@ -3763,10 +3763,10 @@ _MoveMon: ; f51e (3:751e)
and a
ld hl, wBoxMons
ld bc, wBoxMon2 - wBoxMon1 ; $21
- jr z, .asm_f591
+ jr z, .asm_f417
cp DAYCARE_TO_PARTY
ld hl, wDayCareMon
- jr z, .asm_f597
+ jr z, .asm_f41d
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1 ; $2c
.asm_f591
@@ -3781,9 +3781,9 @@ _MoveMon: ; f51e (3:751e)
pop hl
ld a, [wMoveMonType]
and a
- jr z, .asm_f5b4
+ jr z, .asm_f43a
cp DAYCARE_TO_PARTY
- jr z, .asm_f5b4
+ jr z, .asm_f43a
ld bc, wBoxMon2 - wBoxMon1
add hl, bc
ld a, [hl]
@@ -3791,73 +3791,73 @@ _MoveMon: ; f51e (3:751e)
inc de
inc de
ld [de], a
-.asm_f5b4
+.asm_f439
ld a, [wMoveMonType]
cp PARTY_TO_DAYCARE
ld de, W_DAYCAREMONOT
- jr z, .asm_f5d3
+ jr z, .asm_f459
dec a
ld hl, wPartyMonOT
ld a, [wPartyCount]
- jr nz, .asm_f5cd
+ jr nz, .asm_f453
ld hl, wBoxMonOT
- ld a, [W_NUMINBOX]
-.asm_f5cd
+ ld a, [wNumInBox]
+.asm_f453
dec a
call SkipFixedLengthTextEntries
ld d, h
ld e, l
-.asm_f5d3
+.asm_f459
ld hl, wBoxMonOT
ld a, [wMoveMonType]
and a
- jr z, .asm_f5e6
+ jr z, .asm_f46c
ld hl, W_DAYCAREMONOT
cp DAYCARE_TO_PARTY
- jr z, .asm_f5ec
+ jr z, .asm_f472
ld hl, wPartyMonOT
-.asm_f5e6
+.asm_f46c
ld a, [wWhichPokemon]
call SkipFixedLengthTextEntries
-.asm_f5ec
+.asm_f472
ld bc, NAME_LENGTH
call CopyData
ld a, [wMoveMonType]
cp PARTY_TO_DAYCARE
ld de, W_DAYCAREMONNAME
- jr z, .asm_f611
+ jr z, .asm_f497
dec a
ld hl, wPartyMonNicks
ld a, [wPartyCount]
- jr nz, .asm_f60b
+ jr nz, .asm_f491
ld hl, wBoxMonNicks
- ld a, [W_NUMINBOX]
-.asm_f60b
+ ld a, [wNumInBox]
+.asm_f491
dec a
call SkipFixedLengthTextEntries
ld d, h
ld e, l
-.asm_f611
+.asm_f497
ld hl, wBoxMonNicks
ld a, [wMoveMonType]
and a
- jr z, .asm_f624
+ jr z, .asm_f4aa
ld hl, W_DAYCAREMONNAME
cp DAYCARE_TO_PARTY
- jr z, .asm_f62a
+ jr z, .asm_f4b0
ld hl, wPartyMonNicks
-.asm_f624
+.asm_f4aa
ld a, [wWhichPokemon]
call SkipFixedLengthTextEntries
-.asm_f62a
+.asm_f4b0
ld bc, NAME_LENGTH
call CopyData
pop hl
ld a, [wMoveMonType]
cp PARTY_TO_BOX
- jr z, .asm_f664
+ jr z, .asm_f4ea
cp PARTY_TO_DAYCARE
- jr z, .asm_f664
+ jr z, .asm_f4ea
push hl
srl a
add $2
@@ -3876,15 +3876,15 @@ _MoveMon: ; f51e (3:751e)
add hl, bc
ld b, $1
call CalcStats
-.asm_f664
+.asm_f4ea
and a
ret
-FlagActionPredef:
+FlagActionPredef: ; f4ec (3:74ec)
call GetPredefRegisters
-FlagAction:
+FlagAction: ; f4ef (3:74ef)
; Perform action b on bit c
; in the bitfield at hl.
; 0: reset
@@ -3956,7 +3956,7 @@ FlagAction:
ret
-HealParty:
+HealParty: ; f52b (3:752b)
; Restore HP and PP.
ld hl, wPartySpecies
@@ -4056,170 +4056,172 @@ HealParty:
jr nz, .ppup
ret
-
-DivideBCDPredef::
+; divide hMoney by hDivideBCDDivisor
+; return output in hDivideBCDQuotient (same as hDivideBCDDivisor)
+; used only to halve player money upon losing a fight
+DivideBCDPredef:: ; f5a4 (3:75a4)
DivideBCDPredef2::
-DivideBCDPredef3::
+DivideBCDPredef3:: ; only used function
DivideBCDPredef4::
call GetPredefRegisters
-DivideBCD::
+DivideBCD:: ; f5a8 (3:75a8)
xor a
- ld [$ffa5], a
- ld [$ffa6], a
- ld [$ffa7], a
+ ld [hDivideBCDBuffer], a
+ ld [hDivideBCDBuffer + 1], a
+ ld [hDivideBCDBuffer + 2], a
ld d, $1
-.asm_f72a
- ld a, [$ffa2]
+.asm_f5b0
+ ld a, [hDivideBCDDivisor]
and $f0
- jr nz, .asm_f75b
+ jr nz, .asm_f5e1
inc d
- ld a, [$ffa2]
+ ld a, [hDivideBCDDivisor]
swap a
and $f0
ld b, a
- ld a, [$ffa3]
+ ld a, [hDivideBCDDivisor + 1]
swap a
- ld [$ffa3], a
+ ld [hDivideBCDDivisor + 1], a
and $f
or b
- ld [$ffa2], a
- ld a, [$ffa3]
+ ld [hDivideBCDDivisor], a
+ ld a, [hDivideBCDDivisor + 1]
and $f0
ld b, a
- ld a, [$ffa4]
+ ld a, [hDivideBCDDivisor + 2]
swap a
- ld [$ffa4], a
+ ld [hDivideBCDDivisor + 2], a
and $f
or b
- ld [$ffa3], a
- ld a, [$ffa4]
+ ld [hDivideBCDDivisor + 1], a
+ ld a, [hDivideBCDDivisor + 2]
and $f0
- ld [$ffa4], a
- jr .asm_f72a
-.asm_f75b
+ ld [hDivideBCDDivisor + 2], a
+ jr .asm_f5b0
+.asm_f5e1
push de
push de
- call DivideBCD_f800
+ call DivideBCD_f686
pop de
ld a, b
swap a
and $f0
- ld [$ffa5], a
+ ld [hDivideBCDBuffer], a
dec d
- jr z, .asm_f7bc
+ jr z, .asm_f642
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_f65d
+ call DivideBCD_f686
pop de
- ld a, [$ffa5]
+ ld a, [hDivideBCDBuffer]
or b
- ld [$ffa5], a
+ ld [hDivideBCDBuffer], a
dec d
- jr z, .asm_f7bc
+ jr z, .asm_f642
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_f65d
+ call DivideBCD_f686
pop de
ld a, b
swap a
and $f0
- ld [$ffa6], a
+ ld [hDivideBCDBuffer + 1], a
dec d
- jr z, .asm_f7bc
+ jr z, .asm_f642
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_f65d
+ call DivideBCD_f686
pop de
- ld a, [$ffa6]
+ ld a, [hDivideBCDBuffer + 1]
or b
- ld [$ffa6], a
+ ld [hDivideBCDBuffer + 1], a
dec d
- jr z, .asm_f7bc
+ jr z, .asm_f642
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_f65d
+ call DivideBCD_f686
pop de
ld a, b
swap a
and $f0
- ld [$ffa7], a
+ ld [hDivideBCDBuffer + 2], a
dec d
- jr z, .asm_f7bc
+ jr z, .asm_f642
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_f65d
+ call DivideBCD_f686
pop de
- ld a, [$ffa7]
+ ld a, [hDivideBCDBuffer + 2]
or b
- ld [$ffa7], a
-.asm_f7bc
- ld a, [$ffa5]
- ld [$ffa2], a
- ld a, [$ffa6]
- ld [$ffa3], a
- ld a, [$ffa7]
- ld [$ffa4], a
+ ld [hDivideBCDBuffer + 2], a
+.asm_f642
+ ld a, [hDivideBCDBuffer]
+ ld [hDivideBCDQuotient], a
+ ld a, [hDivideBCDBuffer + 1]
+ ld [hDivideBCDQuotient + 1], a
+ ld a, [hDivideBCDBuffer + 2]
+ ld [hDivideBCDQuotient + 2], a
pop de
ld a, $6
sub d
and a
ret z
-.asm_f7ce
+.asm_f654
push af
- call DivideBCD_f7d7
+ call DivideBCD_f65d
pop af
dec a
- jr nz, .asm_f7ce
+ jr nz, .asm_f654
ret
-DivideBCD_f7d7: ; f7d7 (3:77d7)
- ld a, [$ffa4]
+DivideBCD_f65d: ; f65d (3:765d)
+ ld a, [hDivideBCDDivisor + 2]
swap a
and $f
ld b, a
- ld a, [$ffa3]
+ ld a, [hDivideBCDDivisor + 1]
swap a
- ld [$ffa3], a
+ ld [hDivideBCDDivisor + 1], a
and $f0
or b
- ld [$ffa4], a
- ld a, [$ffa3]
+ ld [hDivideBCDDivisor + 2], a
+ ld a, [hDivideBCDDivisor + 1]
and $f
ld b, a
- ld a, [$ffa2]
+ ld a, [hDivideBCDDivisor]
swap a
- ld [$ffa2], a
+ ld [hDivideBCDDivisor], a
and $f0
or b
- ld [$ffa3], a
- ld a, [$ffa2]
+ ld [hDivideBCDDivisor + 1], a
+ ld a, [hDivideBCDDivisor]
and $f
- ld [$ffa2], a
+ ld [hDivideBCDDivisor], a
ret
-DivideBCD_f800: ; f800 (3:7800)
+DivideBCD_f686: ; f686 (3:7686)
ld bc, $3
-.asm_f803
- ld de, $ff9f
- ld hl, $ffa2
+.asm_f689
+ ld de, hMoney
+ ld hl, hDivideBCDDivisor
push bc
call StringCmp
pop bc
ret c
inc b
- ld de, $ffa1
- ld hl, $ffa4
+ ld de, hMoney + 2
+ ld hl, hDivideBCDDivisor + 2
push bc
call SubBCD
pop bc
- jr .asm_f803
+ jr .asm_f689
-AddBCDPredef::
+AddBCDPredef:: ; f6a3 (3:76a3)
call GetPredefRegisters
-AddBCD::
+AddBCD:: ; f6a6 (3:76a6)
and a
ld b, c
.add
@@ -4243,10 +4245,10 @@ AddBCD::
ret
-SubBCDPredef::
+SubBCDPredef:: ; f6bc (3:76bc)
call GetPredefRegisters
-SubBCD::
+SubBCD:: ; f6bf (3:76bf)
and a
ld b, c
.sub
@@ -4271,7 +4273,7 @@ SubBCD::
ret
-InitPlayerData:
+InitPlayerData: ; f6d6 (3:76d6)
InitPlayerData2:
call Random
@@ -4284,10 +4286,12 @@ InitPlayerData2:
ld a, $ff
ld [wUnusedD71B], a
-
+
+ ld a, 90 ; initialize happiness to 90
+ ld [wPikachuHappiness], a
ld hl, wPartyCount
call InitializeEmptyList
- ld hl, W_NUMINBOX
+ ld hl, wNumInBox
call InitializeEmptyList
ld hl, wNumBagItems
call InitializeEmptyList
@@ -4305,7 +4309,7 @@ START_MONEY EQU $3000
ld [wMonDataLocation], a
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
ld [hli], a
ld [hl], a
@@ -4314,13 +4318,13 @@ START_MONEY EQU $3000
ld [hli], a
ld [hl], a
- ld hl, W_GAMEPROGRESSFLAGS
- ld bc, wGameProgressFlagsEnd - W_GAMEPROGRESSFLAGS
+ ld hl, wGameProgressFlags
+ ld bc, wGameProgressFlagsEnd - wGameProgressFlags
call FillMemory ; clear all game progress flags
jp InitializeMissableObjectsFlags
-InitializeEmptyList:
+InitializeEmptyList: ; f730 (3:7730)
xor a ; count
ld [hli], a
dec a ; terminator
@@ -4328,7 +4332,7 @@ InitializeEmptyList:
ret
-GetQuantityOfItemInBag: ; f8a5 (3:78a5)
+GetQuantityOfItemInBag: ; f735 (3:7735)
; In: b = item ID
; Out: b = how many of that item are in the bag
call GetPredefRegisters
@@ -4347,7 +4351,7 @@ GetQuantityOfItemInBag: ; f8a5 (3:78a5)
ld b, 0
ret
-FindPathToPlayer: ; f8ba (3:78ba)
+FindPathToPlayer: ; f74a (3:774a)
xor a
ld hl, hFindPathNumSteps
ld [hli], a ; hFindPathNumSteps
@@ -4363,22 +4367,22 @@ FindPathToPlayer: ; f8ba (3:78ba)
call CalcDifference
ld d, a
and a
- jr nz, .asm_f8da
+ jr nz, .asm_f76a
ld a, [hFindPathFlags]
set 0, a ; current end of path matches the player's Y coordinate
ld [hFindPathFlags], a
-.asm_f8da
+.asm_f76a
ld a, [hFindPathXProgress]
ld b, a
ld a, [hNPCPlayerXDistance] ; X distance in steps
call CalcDifference
ld e, a
and a
- jr nz, .asm_f8ec
+ jr nz, .asm_f77c
ld a, [hFindPathFlags]
set 1, a ; current end of path matches the player's X coordinate
ld [hFindPathFlags], a
-.asm_f8ec
+.asm_f77c
ld a, [hFindPathFlags]
cp $3 ; has the end of the path reached the player's position?
jr z, .done
@@ -4423,7 +4427,7 @@ FindPathToPlayer: ; f8ba (3:78ba)
ld [hl], $ff
ret
-CalcPositionOfPlayerRelativeToNPC: ; f929 (3:7929)
+CalcPositionOfPlayerRelativeToNPC: ; f7b9 (3:77b9)
xor a
ld [hNPCPlayerRelativePosFlags], a
ld a, [wSpriteStateData1 + 4] ; player's sprite screen Y position in pixels
@@ -4500,7 +4504,7 @@ CalcPositionOfPlayerRelativeToNPC: ; f929 (3:7929)
ld [hNPCPlayerRelativePosFlags], a
ret
-ConvertNPCMovementDirectionsToJoypadMasks: ; f9a0 (3:79a0)
+ConvertNPCMovementDirectionsToJoypadMasks: ; f830 (3:7830)
ld a, [hNPCMovementDirections2Index]
ld [wNPCMovementDirections2Index], a
dec a
@@ -4521,7 +4525,7 @@ ConvertNPCMovementDirectionsToJoypadMasks: ; f9a0 (3:79a0)
jr nz, .loop
ret
-ConvertNPCMovementDirectionToJoypadMask: ; f9bf (3:79bf)
+ConvertNPCMovementDirectionToJoypadMask: ; f84f (3:784f)
push hl
ld b, a
ld hl, NPCMovementDirectionsToJoypadMasksTable
@@ -4539,7 +4543,7 @@ ConvertNPCMovementDirectionToJoypadMask: ; f9bf (3:79bf)
pop hl
ret
-NPCMovementDirectionsToJoypadMasksTable: ; f9d2 (3:79d2)
+NPCMovementDirectionsToJoypadMasksTable: ; f862 (3:7862)
db NPC_MOVEMENT_UP, D_UP
db NPC_MOVEMENT_DOWN, D_DOWN
db NPC_MOVEMENT_LEFT, D_LEFT
diff --git a/scripts/celadongym.asm b/scripts/celadongym.asm
index 64e85ff7..459ba4b5 100755
--- a/scripts/celadongym.asm
+++ b/scripts/celadongym.asm
@@ -60,7 +60,7 @@ CeladonGymText_48963: ; 48963 (12:4963)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_4898c
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 3, [hl]
ld hl, wBeatGymFlags
set 3, [hl]
diff --git a/scripts/ceruleangym.asm b/scripts/ceruleangym.asm
index ca1c2c7d..0507a1d4 100755
--- a/scripts/ceruleangym.asm
+++ b/scripts/ceruleangym.asm
@@ -60,7 +60,7 @@ CeruleanGymScript_5c70d: ; 5c70d (17:470d)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_5c736
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 1, [hl]
ld hl, wBeatGymFlags
set 1, [hl]
diff --git a/scripts/cinnabargym.asm b/scripts/cinnabargym.asm
index 5bbb94a9..73aad423 100755
--- a/scripts/cinnabargym.asm
+++ b/scripts/cinnabargym.asm
@@ -157,7 +157,7 @@ CinnabarGymScript3_75857: ; 75857 (1d:5857)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_75880
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 6, [hl]
ld hl, wBeatGymFlags
set 6, [hl]
diff --git a/scripts/fuchsiagym.asm b/scripts/fuchsiagym.asm
index 3ec89256..e10f534e 100755
--- a/scripts/fuchsiagym.asm
+++ b/scripts/fuchsiagym.asm
@@ -60,7 +60,7 @@ FuchsiaGymScript3_75497: ; 75497 (1d:5497)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_754c0
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 4, [hl]
ld hl, wBeatGymFlags
set 4, [hl]
diff --git a/scripts/pewtergym.asm b/scripts/pewtergym.asm
index 831403bb..608fa4cd 100755
--- a/scripts/pewtergym.asm
+++ b/scripts/pewtergym.asm
@@ -60,7 +60,7 @@ PewterGymScript_5c3df: ; 5c3df (17:43df)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_5c408
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 0, [hl]
ld hl, wBeatGymFlags
set 0, [hl]
diff --git a/scripts/rockethideout2.asm b/scripts/rockethideout2.asm
index f269faef..ec4a536e 100755
--- a/scripts/rockethideout2.asm
+++ b/scripts/rockethideout2.asm
@@ -323,7 +323,7 @@ LoadSpinnerArrowTiles: ; 44fd7 (11:4fd7)
add hl, bc
ld a, [hl]
ld [wSpriteStateData1 + 2], a
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp FACILITY
ld hl, FacilitySpinnerArrows
jr z, .asm_44ff6
diff --git a/scripts/route22gate.asm b/scripts/route22gate.asm
index 95546a99..e17380f5 100755
--- a/scripts/route22gate.asm
+++ b/scripts/route22gate.asm
@@ -58,7 +58,7 @@ Route22GateTextPointers: ; 1e6df (7:66df)
Route22GateText1: ; 1e6e1 (7:66e1)
TX_ASM
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
bit 0, a
jr nz, .asm_1e6f6
ld hl, Route22GateText_1e704
diff --git a/scripts/route23.asm b/scripts/route23.asm
index 35f1b9cb..6462ec88 100755
--- a/scripts/route23.asm
+++ b/scripts/route23.asm
@@ -190,7 +190,7 @@ Route23Script_51346: ; 51346 (14:5346)
inc a
ld c, a
ld b, FLAG_TEST
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
predef FlagActionPredef
ld a, c
and a
diff --git a/scripts/saffrongym.asm b/scripts/saffrongym.asm
index 140b1130..567f79d8 100755
--- a/scripts/saffrongym.asm
+++ b/scripts/saffrongym.asm
@@ -60,7 +60,7 @@ SaffronGymText_5d068: ; 5d068 (17:5068)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_5d091
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 5, [hl]
ld hl, wBeatGymFlags
set 5, [hl]
diff --git a/scripts/vermiliongym.asm b/scripts/vermiliongym.asm
index 78a38aec..6dae0751 100755
--- a/scripts/vermiliongym.asm
+++ b/scripts/vermiliongym.asm
@@ -79,7 +79,7 @@ VermilionGymScript_5caaa: ; 5caaa (17:4aaa)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_5cad3
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 2, [hl]
ld hl, wBeatGymFlags
set 2, [hl]
diff --git a/scripts/viridiancity.asm b/scripts/viridiancity.asm
index 79ad444f..be7872e6 100755
--- a/scripts/viridiancity.asm
+++ b/scripts/viridiancity.asm
@@ -17,7 +17,7 @@ ViridianCityScript0: ; 19005 (6:5005)
ViridianCityScript_1900b: ; 1900b (6:500b)
CheckEvent EVENT_VIRIDIAN_GYM_OPEN
ret nz
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
cp %01111111
jr nz, .asm_1901e
SetEvent EVENT_VIRIDIAN_GYM_OPEN
@@ -147,7 +147,7 @@ ViridianCityText1: ; 19102 (6:5102)
ViridianCityText2: ; 19107 (6:5107)
TX_ASM
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
cp %01111111
ld hl, ViridianCityText_19127
jr z, .asm_ae9fe
diff --git a/scripts/viridiangym.asm b/scripts/viridiangym.asm
index 6cded55d..1848e5f0 100755
--- a/scripts/viridiangym.asm
+++ b/scripts/viridiangym.asm
@@ -154,7 +154,7 @@ ViridianGymScript3_74995: ; 74995 (1d:4995)
ld [hSpriteIndexOrTextID], a
call DisplayTextID
.asm_749be
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
set 7, [hl]
ld hl, wBeatGymFlags
set 7, [hl]
diff --git a/wram.asm b/wram.asm
index 62cb48a1..f63a96c1 100755
--- a/wram.asm
+++ b/wram.asm
@@ -2299,7 +2299,7 @@ W_OPTIONS:: ; d355
; 5: Slow
ds 1
-W_OBTAINEDBADGES:: ; d356
+wObtainedBadges:: ; d356
ds 1
ds 1
@@ -2352,7 +2352,7 @@ wLastMap:: ; d365
wUnusedD366:: ; d366
ds 1
-W_CURMAPTILESET:: ; d367
+wCurMapTileset:: ; d367
ds 1
W_CURMAPHEIGHT:: ; d368
@@ -2523,8 +2523,8 @@ wd44b:: ds 1
ds 36
-wPikachuHappiness:: ds 1
-wPikachuMood:: ds 1
+wPikachuHappiness:: ds 1 ; d46f
+wPikachuMood:: ds 1 ; d470
wd472:: ds 1
wd473:: ds 1
@@ -2666,7 +2666,7 @@ W_MISSABLEOBJECTLIST:: ; d5ce
; terminated with $FF
ds 17 * 2
-W_GAMEPROGRESSFLAGS:: ; d5f0
+wGameProgressFlags:: ; d5f0
; $c8 bytes
ds 0
@@ -2970,7 +2970,7 @@ wd728::
ds 1
wBeatGymFlags:: ; d72a
-; redundant because it matches W_OBTAINEDBADGES
+; redundant because it matches wObtainedBadges
; used to determine whether to show name on statue and in two NPC text scripts
ds 1
@@ -3279,7 +3279,7 @@ wMainDataEnd::
wBoxDataStart::
-W_NUMINBOX:: ds 1 ; da80
+wNumInBox:: ds 1 ; da80
wBoxSpecies:: ds MONS_PER_BOX + 1
wBoxMons::
diff --git a/yellow/main.asm b/yellow/main.asm
index f11a90e4..82198765 100755
--- a/yellow/main.asm
+++ b/yellow/main.asm
@@ -313,7 +313,7 @@ IsPlayerStandingOnDoorTileOrWarpTile: ; c1e6 (3:41e6)
push bc
callba IsPlayerStandingOnDoorTile ; 6:6785
jr c, .done
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
add a
ld c, a
ld b, $0
@@ -712,7 +712,7 @@ LoadTilesetHeader: ; c4f4 (3:44f4)
call GetPredefRegisters
push hl
ld d, 0
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
add a
add a
ld e, a
@@ -728,7 +728,7 @@ LoadTilesetHeader: ; c4f4 (3:44f4)
xor a
ld [$ffd8], a
pop hl
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
push hl
push de
ld hl, DungeonTilesets
@@ -737,7 +737,7 @@ LoadTilesetHeader: ; c4f4 (3:44f4)
pop de
pop hl
jr c, .notDungeonTileset
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld b, a
ld a, [hPreviousTileset]
cp b
@@ -839,7 +839,7 @@ DrawBadges: ; e880 (3:6880)
; Alter these based on owned badges.
ld de, wTempObtainedBadgesBooleans
ld hl, wBadgeOrFaceTiles
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
ld b, a
ld c, 8
.CheckBadge
@@ -1670,16 +1670,703 @@ AddPartyMon_WriteMovePP: ; f2fc (3:72fc)
jr nz, .pploop ; there are still moves to read
ret
+; adds enemy mon [wcf91] (at position [wWhichPokemon] in enemy list) to own party
+; used in the cable club trade center
_AddEnemyMonToPlayerParty: ; f323 (3:7323)
- dr $f323,$f3a4
-Func_f3a4: ; f3a4 (3:73a4)
- dr $f3a4,$f4ef
+ ld hl, wPartyCount
+ ld a, [hl]
+ cp PARTY_LENGTH
+ scf
+ ret z ; party full, return failure
+ inc a
+ ld [hl], a ; add 1 to party members
+ ld c, a
+ ld b, $0
+ add hl, bc
+ ld a, [wcf91]
+ ld [hli], a ; add mon as last list entry
+ ld [hl], $ff ; write new sentinel
+ ld hl, wPartyMons
+ ld a, [wPartyCount]
+ dec a
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld e, l
+ ld d, h
+ ld hl, wLoadedMon
+ call CopyData ; write new mon's data (from wLoadedMon)
+ ld hl, wPartyMonOT
+ ld a, [wPartyCount]
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+ ld hl, wEnemyMonOT
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld bc, NAME_LENGTH
+ call CopyData ; write new mon's OT name (from an enemy mon)
+ ld hl, wPartyMonNicks
+ ld a, [wPartyCount]
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+ ld hl, wEnemyMonNicks
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld bc, NAME_LENGTH
+ call CopyData ; write new mon's nickname (from an enemy mon)
+ ld a, [wcf91]
+ ld [wd11e], a
+ predef IndexToPokedex
+ ld a, [wd11e]
+ dec a
+ ld c, a
+ ld b, FLAG_SET
+ ld hl, wPokedexOwned
+ push bc
+ call FlagAction ; add to owned pokemon
+ pop bc
+ ld hl, wPokedexSeen
+ call FlagAction ; add to seen pokemon
+ and a
+ ret ; return success
+
+_MoveMon: ; f3a4 (3:73a4)
+ ld a, [wMoveMonType]
+ and a
+ jr z, .checkPartyMonSlots
+ cp DAYCARE_TO_PARTY
+ jr z, .checkPartyMonSlots
+ cp PARTY_TO_DAYCARE
+ ld hl, wDayCareMon
+ jr z, .asm_f3fb
+ ld hl, wNumInBox
+ ld a, [hl]
+ cp MONS_PER_BOX
+ jr nz, .partyOrBoxNotFull
+ jr .boxFull
+.checkPartyMonSlots
+ ld hl, wPartyCount
+ ld a, [hl]
+ cp PARTY_LENGTH
+ jr nz, .partyOrBoxNotFull
+.boxFull
+ scf
+ ret
+.partyOrBoxNotFull
+ inc a
+ ld [hl], a ; increment number of mons in party/box
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [wMoveMonType]
+ cp DAYCARE_TO_PARTY
+ ld a, [wDayCareMon]
+ jr z, .asm_f3dc
+ ld a, [wcf91]
+.asm_f3dc
+ ld [hli], a ; write new mon ID
+ ld [hl], $ff ; write new sentinel
+ ld a, [wMoveMonType]
+ dec a
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1 ; $2c
+ ld a, [wPartyCount]
+ jr nz, .skipToNewMonEntry
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1 ; $21
+ ld a, [wNumInBox]
+.skipToNewMonEntry
+ dec a
+ call AddNTimes
+.asm_f3fb
+ push hl
+ ld e, l
+ ld d, h
+ ld a, [wMoveMonType]
+ and a
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1 ; $21
+ jr z, .asm_f417
+ cp DAYCARE_TO_PARTY
+ ld hl, wDayCareMon
+ jr z, .asm_f41d
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1 ; $2c
+.asm_f417
+ ld a, [wWhichPokemon]
+ call AddNTimes
+.asm_f41d
+ push hl
+ push de
+ ld bc, wBoxMon2 - wBoxMon1
+ call CopyData
+ pop de
+ pop hl
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f43a
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f43a
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc
+ ld a, [hl]
+ inc de
+ inc de
+ inc de
+ ld [de], a
+.asm_f43a
+ ld a, [wMoveMonType]
+ cp PARTY_TO_DAYCARE
+ ld de, W_DAYCAREMONOT
+ jr z, .asm_f459
+ dec a
+ ld hl, wPartyMonOT
+ ld a, [wPartyCount]
+ jr nz, .asm_f453
+ ld hl, wBoxMonOT
+ ld a, [wNumInBox]
+.asm_f453
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+.asm_f459
+ ld hl, wBoxMonOT
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f46c
+ ld hl, W_DAYCAREMONOT
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f472
+ ld hl, wPartyMonOT
+.asm_f46c
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+.asm_f472
+ ld bc, NAME_LENGTH
+ call CopyData
+ ld a, [wMoveMonType]
+ cp PARTY_TO_DAYCARE
+ ld de, W_DAYCAREMONNAME
+ jr z, .asm_f497
+ dec a
+ ld hl, wPartyMonNicks
+ ld a, [wPartyCount]
+ jr nz, .asm_f491
+ ld hl, wBoxMonNicks
+ ld a, [wNumInBox]
+.asm_f491
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+.asm_f497
+ ld hl, wBoxMonNicks
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f4aa
+ ld hl, W_DAYCAREMONNAME
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f4b0
+ ld hl, wPartyMonNicks
+.asm_f4aa
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+.asm_f4b0
+ ld bc, NAME_LENGTH
+ call CopyData
+ pop hl
+ ld a, [wMoveMonType]
+ cp PARTY_TO_BOX
+ jr z, .asm_f4ea
+ cp PARTY_TO_DAYCARE
+ jr z, .asm_f4ea
+ push hl
+ srl a
+ add $2
+ ld [wMonDataLocation], a
+ call LoadMonData
+ callba CalcLevelFromExperience
+ ld a, d
+ ld [W_CURENEMYLVL], a
+ pop hl
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc
+ ld [hli], a
+ ld d, h
+ ld e, l
+ ld bc, -18
+ add hl, bc
+ ld b, $1
+ call CalcStats
+.asm_f4ea
+ and a
+ ret
+
+
+FlagActionPredef: ; f4ec (3:74ec)
+ call GetPredefRegisters
+
FlagAction: ; f4ef (3:74ef)
- dr $f4ef,$f9de
-PrintBookshelfText: ; f9de (3:79de)
- dr $f9de,$fad3
-PokemonStuffText: ; fad3 (3:7ad3)
- dr $fad3,$10000
+; Perform action b on bit c
+; in the bitfield at hl.
+; 0: reset
+; 1: set
+; 2: read
+; Return the result in c.
+
+ push hl
+ push de
+ push bc
+
+ ; bit
+ ld a, c
+ ld d, a
+ and 7
+ ld e, a
+
+ ; byte
+ ld a, d
+ srl a
+ srl a
+ srl a
+ add l
+ ld l, a
+ jr nc, .ok
+ inc h
+.ok
+
+ ; d = 1 << e (bitmask)
+ inc e
+ ld d, 1
+.shift
+ dec e
+ jr z, .shifted
+ sla d
+ jr .shift
+.shifted
+
+ ld a, b
+ and a
+ jr z, .reset
+ cp 2
+ jr z, .read
+
+.set
+ ld b, [hl]
+ ld a, d
+ or b
+ ld [hl], a
+ jr .done
+
+.reset
+ ld b, [hl]
+ ld a, d
+ xor $ff
+ and b
+ ld [hl], a
+ jr .done
+
+.read
+ ld b, [hl]
+ ld a, d
+ and b
+.done
+ pop bc
+ pop de
+ pop hl
+ ld c, a
+ ret
+
+HealParty: ; f52b (3:752b)
+; Restore HP and PP.
+
+ ld hl, wPartySpecies
+ ld de, wPartyMon1HP
+.healmon
+ ld a, [hli]
+ cp $ff
+ jr z, .done
+
+ push hl
+ push de
+
+ ld hl, wPartyMon1Status - wPartyMon1HP
+ add hl, de
+ xor a
+ ld [hl], a
+
+ push de
+ ld b, NUM_MOVES ; A Pokémon has 4 moves
+.pp
+ ld hl, wPartyMon1Moves - wPartyMon1HP
+ add hl, de
+
+ ld a, [hl]
+ and a
+ jr z, .nextmove
+
+ dec a
+ ld hl, wPartyMon1PP - wPartyMon1HP
+ add hl, de
+
+ push hl
+ push de
+ push bc
+
+ ld hl, Moves
+ ld bc, MoveEnd - Moves
+ call AddNTimes
+ ld de, wcd6d
+ ld a, BANK(Moves)
+ call FarCopyData
+ ld a, [wcd6d + 5] ; PP is byte 5 of move data
+
+ pop bc
+ pop de
+ pop hl
+
+ inc de
+ push bc
+ ld b, a
+ ld a, [hl]
+ and $c0
+ add b
+ ld [hl], a
+ pop bc
+
+.nextmove
+ dec b
+ jr nz, .pp
+ pop de
+
+ ld hl, wPartyMon1MaxHP - wPartyMon1HP
+ add hl, de
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
+
+ pop de
+ pop hl
+
+ push hl
+ ld bc, wPartyMon2 - wPartyMon1
+ ld h, d
+ ld l, e
+ add hl, bc
+ ld d, h
+ ld e, l
+ pop hl
+ jr .healmon
+
+.done
+ xor a
+ ld [wWhichPokemon], a
+ ld [wd11e], a
+
+ ld a, [wPartyCount]
+ ld b, a
+.ppup
+ push bc
+ call RestoreBonusPP
+ pop bc
+ ld hl, wWhichPokemon
+ inc [hl]
+ dec b
+ jr nz, .ppup
+ ret
+
+INCLUDE "engine/bcd.asm"
+
+InitPlayerData: ; f6d6 (3:76d6)
+InitPlayerData2:
+
+ call Random
+ ld a, [hRandomSub]
+ ld [wPlayerID], a
+
+ call Random
+ ld a, [hRandomAdd]
+ ld [wPlayerID + 1], a
+
+ ld a, $ff
+ ld [wUnusedD71B], a
+
+ ld a, 90 ; initialize happiness to 90
+ ld [wPikachuHappiness], a
+ ld a, $80
+ ld [wPikachuMood], a ; initialize mood
+
+ ld hl, wPartyCount
+ call InitializeEmptyList
+ ld hl, wNumInBox
+ call InitializeEmptyList
+ ld hl, wNumBagItems
+ call InitializeEmptyList
+ ld hl, wNumBoxItems
+ call InitializeEmptyList
+
+START_MONEY EQU $3000
+ ld hl, wPlayerMoney + 1
+ ld a, START_MONEY / $100
+ ld [hld], a
+ xor a
+ ld [hli], a
+ inc hl
+ ld [hl], a
+
+ ld [wMonDataLocation], a
+
+ ld hl, wObtainedBadges
+ ld [hli], a
+
+ ld [hl], a
+
+ ld hl, wPlayerCoins
+ ld [hli], a
+ ld [hl], a
+
+ ld hl, wGameProgressFlags
+ ld bc, wGameProgressFlagsEnd - wGameProgressFlags
+ call FillMemory ; clear all game progress flags
+
+ jp InitializeMissableObjectsFlags
+
+InitializeEmptyList: ; f730 (3:7730)
+ xor a ; count
+ ld [hli], a
+ dec a ; terminator
+ ld [hl], a
+ ret
+
+GetQuantityOfItemInBag: ; f735 (3:7735)
+; In: b = item ID
+; Out: b = how many of that item are in the bag
+ call GetPredefRegisters
+ ld hl, wNumBagItems
+.loop
+ inc hl
+ ld a, [hli]
+ cp $ff
+ jr z, .notInBag
+ cp b
+ jr nz, .loop
+ ld a, [hl]
+ ld b, a
+ ret
+.notInBag
+ ld b, 0
+ ret
+
+FindPathToPlayer: ; f74a (3:774a)
+ xor a
+ ld hl, hFindPathNumSteps
+ ld [hli], a ; hFindPathNumSteps
+ ld [hli], a ; hFindPathFlags
+ ld [hli], a ; hFindPathYProgress
+ ld [hl], a ; hFindPathXProgress
+ ld hl, wNPCMovementDirections2
+ ld de, $0
+.loop
+ ld a, [hFindPathYProgress]
+ ld b, a
+ ld a, [hNPCPlayerYDistance] ; Y distance in steps
+ call CalcDifference
+ ld d, a
+ and a
+ jr nz, .asm_f76a
+ ld a, [hFindPathFlags]
+ set 0, a ; current end of path matches the player's Y coordinate
+ ld [hFindPathFlags], a
+.asm_f76a
+ ld a, [hFindPathXProgress]
+ ld b, a
+ ld a, [hNPCPlayerXDistance] ; X distance in steps
+ call CalcDifference
+ ld e, a
+ and a
+ jr nz, .asm_f77c
+ ld a, [hFindPathFlags]
+ set 1, a ; current end of path matches the player's X coordinate
+ ld [hFindPathFlags], a
+.asm_f77c
+ ld a, [hFindPathFlags]
+ cp $3 ; has the end of the path reached the player's position?
+ jr z, .done
+; Compare whether the X distance between the player and the current of the path
+; is greater or if the Y distance is. Then, try to reduce whichever is greater.
+ ld a, e
+ cp d
+ jr c, .yDistanceGreater
+; x distance is greater
+ ld a, [hNPCPlayerRelativePosFlags]
+ bit 1, a
+ jr nz, .playerIsLeftOfNPC
+ ld d, NPC_MOVEMENT_RIGHT
+ jr .next1
+.playerIsLeftOfNPC
+ ld d, NPC_MOVEMENT_LEFT
+.next1
+ ld a, [hFindPathXProgress]
+ add 1
+ ld [hFindPathXProgress], a
+ jr .storeDirection
+.yDistanceGreater
+ ld a, [hNPCPlayerRelativePosFlags]
+ bit 0, a
+ jr nz, .playerIsAboveNPC
+ ld d, NPC_MOVEMENT_DOWN
+ jr .next2
+.playerIsAboveNPC
+ ld d, NPC_MOVEMENT_UP
+.next2
+ ld a, [hFindPathYProgress]
+ add 1
+ ld [hFindPathYProgress], a
+.storeDirection
+ ld a, d
+ ld [hli], a
+ ld a, [hFindPathNumSteps]
+ inc a
+ ld [hFindPathNumSteps], a
+ jp .loop
+.done
+ ld [hl], $ff
+ ret
+
+CalcPositionOfPlayerRelativeToNPC: ; f7b9 (3:77b9)
+ xor a
+ ld [hNPCPlayerRelativePosFlags], a
+ ld a, [wSpriteStateData1 + 4] ; player's sprite screen Y position in pixels
+ ld d, a
+ ld a, [wSpriteStateData1 + 6] ; player's sprite screen X position in pixels
+ ld e, a
+ ld hl, wSpriteStateData1
+ ld a, [hNPCSpriteOffset]
+ add l
+ add $4
+ ld l, a
+ jr nc, .noCarry
+ inc h
+.noCarry
+ ld a, d
+ ld b, a
+ ld a, [hli] ; NPC sprite screen Y position in pixels
+ call CalcDifference
+ jr nc, .NPCSouthOfOrAlignedWithPlayer
+.NPCNorthOfPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 0, [hl]
+ set 0, [hl]
+ pop hl
+ jr .divideYDistance
+.NPCSouthOfOrAlignedWithPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 0, [hl]
+ res 0, [hl]
+ pop hl
+.divideYDistance
+ push hl
+ ld hl, hDividend2
+ ld [hli], a
+ ld a, 16
+ ld [hli], a
+ call DivideBytes ; divide Y absolute distance by 16
+ ld a, [hl] ; quotient
+ ld [hNPCPlayerYDistance], a
+ pop hl
+ inc hl
+ ld b, e
+ ld a, [hl] ; NPC sprite screen X position in pixels
+ call CalcDifference
+ jr nc, .NPCEastOfOrAlignedWithPlayer
+.NPCWestOfPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 1, [hl]
+ set 1, [hl]
+ pop hl
+ jr .divideXDistance
+.NPCEastOfOrAlignedWithPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 1, [hl]
+ res 1, [hl]
+ pop hl
+.divideXDistance
+ ld [hDividend2], a
+ ld a, 16
+ ld [hDivisor2], a
+ call DivideBytes ; divide X absolute distance by 16
+ ld a, [hQuotient2]
+ ld [hNPCPlayerXDistance], a
+ ld a, [hNPCPlayerRelativePosPerspective]
+ and a
+ ret z
+ ld a, [hNPCPlayerRelativePosFlags]
+ cpl
+ and $3
+ ld [hNPCPlayerRelativePosFlags], a
+ ret
+
+ConvertNPCMovementDirectionsToJoypadMasks: ; f830 (3:7830)
+ ld a, [hNPCMovementDirections2Index]
+ ld [wNPCMovementDirections2Index], a
+ dec a
+ ld de, wSimulatedJoypadStatesEnd
+ ld hl, wNPCMovementDirections2
+ add l
+ ld l, a
+ jr nc, .loop
+ inc h
+.loop
+ ld a, [hld]
+ call ConvertNPCMovementDirectionToJoypadMask
+ ld [de], a
+ inc de
+ ld a, [hNPCMovementDirections2Index]
+ dec a
+ ld [hNPCMovementDirections2Index], a
+ jr nz, .loop
+ ret
+
+ConvertNPCMovementDirectionToJoypadMask: ; f84f (3:784f)
+ push hl
+ ld b, a
+ ld hl, NPCMovementDirectionsToJoypadMasksTable
+.loop
+ ld a, [hli]
+ cp $ff
+ jr z, .done
+ cp b
+ jr z, .loadJoypadMask
+ inc hl
+ jr .loop
+.loadJoypadMask
+ ld a, [hl]
+.done
+ pop hl
+ ret
+
+NPCMovementDirectionsToJoypadMasksTable: ; f862 (3:7862)
+ db NPC_MOVEMENT_UP, D_UP
+ db NPC_MOVEMENT_DOWN, D_DOWN
+ db NPC_MOVEMENT_LEFT, D_LEFT
+ db NPC_MOVEMENT_RIGHT, D_RIGHT
+ db $ff
+
+; unreferenced
+ ret
+
+INCLUDE "engine/hp_bar.asm"
+INCLUDE "engine/hidden_object_functions3.asm"
SECTION "Graphics", ROMX, BANK[GFX]
@@ -2344,7 +3031,9 @@ JessieJamesPic: INCBIN "pic/ytrainer/jessiejames.pic"
SECTION "bank14",ROMX,BANK[$14]
- dr $50000,$5267d
+ dr $50000,$525d8
+PrintCardKeyText: ; 525d8 (14:65d8)
+ dr $525d8,$5267d
CeladonPrizeMenu: ; 5267d (14:667d)
dr $5267d,$54000
@@ -2363,7 +3052,9 @@ TrainerWalkUpToPlayer: ; 567cd (15:67cd)
dr $567cd,$58000
SECTION "bank16",ROMX,BANK[$16]
- dr $58000,$58dc0
+ dr $58000,$58d99
+CalcLevelFromExperience: ; 58d99 (16:4d99)
+ dr $58d99,$58dc0
CalcExperience: ; 58dc0 (16:4dc0)
dr $58dc0,$58e8b
PrintStatusAilment: ; 58e8b (16:4e8b)