summaryrefslogtreecommitdiff
path: root/engine/overworld
diff options
context:
space:
mode:
Diffstat (limited to 'engine/overworld')
-rw-r--r--engine/overworld/decorations.asm398
-rw-r--r--engine/overworld/events.asm853
-rw-r--r--engine/overworld/events_2.asm650
-rw-r--r--engine/overworld/init_map.asm8
-rw-r--r--engine/overworld/landmarks.asm11
-rw-r--r--engine/overworld/load_map_part.asm2
-rw-r--r--engine/overworld/map_object_action.asm80
-rw-r--r--engine/overworld/map_objects.asm418
-rw-r--r--engine/overworld/map_objects_2.asm6
-rw-r--r--engine/overworld/map_setup.asm48
-rw-r--r--engine/overworld/movement.asm298
-rw-r--r--engine/overworld/npc_movement.asm98
-rw-r--r--engine/overworld/overworld.asm96
-rw-r--r--engine/overworld/player_movement.asm116
-rw-r--r--engine/overworld/player_object.asm64
-rw-r--r--engine/overworld/player_step.asm34
-rw-r--r--engine/overworld/scripting.asm15
-rw-r--r--engine/overworld/select_menu.asm41
-rw-r--r--engine/overworld/spawn_points.asm8
-rw-r--r--engine/overworld/tile_events.asm27
-rw-r--r--engine/overworld/time.asm117
-rw-r--r--engine/overworld/variables.asm32
-rw-r--r--engine/overworld/warp_connection.asm33
-rw-r--r--engine/overworld/wildmons.asm107
24 files changed, 1420 insertions, 2140 deletions
diff --git a/engine/overworld/decorations.asm b/engine/overworld/decorations.asm
index 33d0ca0cd..bea2e0cdb 100644
--- a/engine/overworld/decorations.asm
+++ b/engine/overworld/decorations.asm
@@ -1,11 +1,11 @@
-InitDecorations: ; 26751 (9:6751)
+InitDecorations:
ld a, DECO_FEATHERY_BED
ld [wDecoBed], a
ld a, DECO_TOWN_MAP
ld [wDecoPoster], a
ret
-_PlayerDecorationMenu: ; 0x2675c
+_PlayerDecorationMenu:
ld a, [wWhichIndexSet]
push af
ld hl, .MenuHeader
@@ -34,24 +34,21 @@ _PlayerDecorationMenu: ; 0x2675c
ld a, [wBuffer5]
ld c, a
ret
-; 0x2679a
-.MenuHeader: ; 0x2679a
+.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 5, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw .MenuData
db 1 ; default option
-; 0x267a2
-.MenuData: ; 0x267a2
+.MenuData:
db STATICMENU_CURSOR | STATICMENU_WRAP ; flags
db 0 ; items
dw wd002
dw PlaceNthMenuStrings
dw .pointers
-; 0x267aa
-.pointers ; 267aa
+.pointers
dw DecoBedMenu, .bed
dw DecoCarpetMenu, .carpet
dw DecoPlantMenu, .plant
@@ -69,9 +66,8 @@ _PlayerDecorationMenu: ; 0x2675c
.ornament db "ORNAMENT@"
.big_doll db "BIG DOLL@"
.exit db "EXIT@"
-; 26806
-.FindCategoriesWithOwnedDecos: ; 26806
+.FindCategoriesWithOwnedDecos:
xor a
ld [wWhichIndexSet], a
call .ClearStringBuffer2
@@ -84,7 +80,7 @@ _PlayerDecorationMenu: ; 0x2675c
call CopyBytes
ret
-.ClearStringBuffer2: ; 26822 (9:6822)
+.ClearStringBuffer2:
ld hl, wStringBuffer2
xor a
ld [hli], a
@@ -93,7 +89,7 @@ _PlayerDecorationMenu: ; 0x2675c
call ByteFill
ret
-.AppendToStringBuffer2: ; 26830 (9:6830)
+.AppendToStringBuffer2:
ld hl, wStringBuffer2
inc [hl]
ld e, [hl]
@@ -102,7 +98,7 @@ _PlayerDecorationMenu: ; 0x2675c
ld [hl], a
ret
-.FindOwndDecos: ; 2683a (9:683a)
+.FindOwndDecos:
ld hl, .dw
.loop
ld a, [hli]
@@ -124,9 +120,8 @@ _PlayerDecorationMenu: ; 0x2675c
jr .loop
.done
ret
-; 26855 (9:6855)
-.dw ; 26855
+.dw
dwb FindOwnedBeds, 0 ; bed
dwb FindOwnedCarpets, 1 ; carpet
dwb FindOwnedPlants, 2 ; plant
@@ -135,9 +130,8 @@ _PlayerDecorationMenu: ; 0x2675c
dwb FindOwnedOrnaments, 5 ; ornament
dwb FindOwnedBigDolls, 6 ; big doll
dw 0 ; end
-; 2686c
-Deco_FillTempWithMinusOne: ; 2686c
+Deco_FillTempWithMinusOne:
xor a
ld hl, wd002
ld [hli], a
@@ -145,9 +139,8 @@ Deco_FillTempWithMinusOne: ; 2686c
ld bc, $10
call ByteFill
ret
-; 2687a
-CheckAllDecorationFlags: ; 2687a
+CheckAllDecorationFlags:
.loop
ld a, [hli]
cp -1
@@ -166,9 +159,8 @@ CheckAllDecorationFlags: ; 2687a
.done
ret
-; 26891
-AppendDecoIndex: ; 26891
+AppendDecoIndex:
ld hl, wd002
inc [hl]
ld e, [hl]
@@ -176,9 +168,8 @@ AppendDecoIndex: ; 26891
add hl, de
ld [hl], a
ret
-; 2689b
-FindOwnedDecosInCategory: ; 2689b
+FindOwnedDecosInCategory:
push bc
push hl
call Deco_FillTempWithMinusOne
@@ -195,126 +186,108 @@ FindOwnedDecosInCategory: ; 2689b
call AppendDecoIndex
scf
ret
-; 268b5
-DecoBedMenu: ; 268b5
+DecoBedMenu:
call FindOwnedBeds
call PopulateDecoCategoryMenu
xor a
ret
-; 268bd
-FindOwnedBeds: ; 268bd
+FindOwnedBeds:
ld hl, .beds
ld c, BEDS
jp FindOwnedDecosInCategory
-; 268c5
-.beds ; 268c5
+.beds
db DECO_FEATHERY_BED ; 2
db DECO_PINK_BED ; 3
db DECO_POLKADOT_BED ; 4
db DECO_PIKACHU_BED ; 5
db -1
-; 268ca
-DecoCarpetMenu: ; 268ca
+DecoCarpetMenu:
call FindOwnedCarpets
call PopulateDecoCategoryMenu
xor a
ret
-; 268d2
-FindOwnedCarpets: ; 268d2
+FindOwnedCarpets:
ld hl, .carpets
ld c, CARPETS
jp FindOwnedDecosInCategory
-; 268da
-.carpets ; 268da
+.carpets
db DECO_RED_CARPET ; 7
db DECO_BLUE_CARPET ; 8
db DECO_YELLOW_CARPET ; 9
db DECO_GREEN_CARPET ; a
db -1
-; 268df
-DecoPlantMenu: ; 268df
+DecoPlantMenu:
call FindOwnedPlants
call PopulateDecoCategoryMenu
xor a
ret
-; 268e7
-FindOwnedPlants: ; 268e7
+FindOwnedPlants:
ld hl, .plants
ld c, PLANTS
jp FindOwnedDecosInCategory
-; 268ef
-.plants ; 268ef
+.plants
db DECO_MAGNAPLANT ; c
db DECO_TROPICPLANT ; d
db DECO_JUMBOPLANT ; e
db -1
-; 268f3
-DecoPosterMenu: ; 268f3
+DecoPosterMenu:
call FindOwnedPosters
call PopulateDecoCategoryMenu
xor a
ret
-; 268fb
-FindOwnedPosters: ; 268fb
+FindOwnedPosters:
ld hl, .posters
ld c, POSTERS
jp FindOwnedDecosInCategory
-; 26903
-.posters ; 26903
+.posters
db DECO_TOWN_MAP ; 10
db DECO_PIKACHU_POSTER ; 11
db DECO_CLEFAIRY_POSTER ; 12
db DECO_JIGGLYPUFF_POSTER ; 13
db -1
-; 26908
-DecoConsoleMenu: ; 26908
+DecoConsoleMenu:
call FindOwnedConsoles
call PopulateDecoCategoryMenu
xor a
ret
-; 26910
-FindOwnedConsoles: ; 26910
+FindOwnedConsoles:
ld hl, .consoles
ld c, CONSOLES
jp FindOwnedDecosInCategory
-; 26918
-.consoles ; 26918
+.consoles
db DECO_FAMICOM ; 15
db DECO_SNES ; 16
db DECO_N64 ; 17
db DECO_VIRTUAL_BOY ; 18
db -1
-; 2691d
-DecoOrnamentMenu: ; 2691d
+DecoOrnamentMenu:
call FindOwnedOrnaments
call PopulateDecoCategoryMenu
xor a
ret
-; 26925
-FindOwnedOrnaments: ; 26925
+FindOwnedOrnaments:
ld hl, .ornaments
ld c, DOLLS
jp FindOwnedDecosInCategory
-; 2692d
-.ornaments ; 2692d
+.ornaments
db DECO_PIKACHU_DOLL ; 1e
db DECO_SURF_PIKACHU_DOLL ; 1f
db DECO_CLEFAIRY_DOLL ; 20
@@ -339,34 +312,29 @@ FindOwnedOrnaments: ; 26925
db DECO_GOLD_TROPHY_DOLL ; 33
db DECO_SILVER_TROPHY_DOLL ; 34
db -1
-; 26945
-DecoBigDollMenu: ; 26945
+DecoBigDollMenu:
call FindOwnedBigDolls
call PopulateDecoCategoryMenu
xor a
ret
-; 2694d
-FindOwnedBigDolls: ; 2694d
+FindOwnedBigDolls:
ld hl, .big_dolls
ld c, BIG_DOLLS
jp FindOwnedDecosInCategory
-; 26955
-.big_dolls ; 26955
+.big_dolls
db DECO_BIG_SNORLAX_DOLL ; 1a
db DECO_BIG_ONIX_DOLL ; 1b
db DECO_BIG_LAPRAS_DOLL ; 1c
db -1
-; 26959
-DecoExitMenu: ; 26959
+DecoExitMenu:
scf
ret
-; 2695b
-PopulateDecoCategoryMenu: ; 2695b
+PopulateDecoCategoryMenu:
ld a, [wd002]
and a
jr z, .empty
@@ -413,37 +381,32 @@ PopulateDecoCategoryMenu: ; 2695b
ld hl, .Text_nothing_to_choose
call MenuTextBoxBackup
ret
-; 269b0
-.Text_nothing_to_choose: ; 0x269b0
+.Text_nothing_to_choose:
; There's nothing to choose.
text_jump UnknownText_0x1bc471
db "@"
-; 0x269b5
-.NonscrollingMenuHeader: ; 0x269b5
+.NonscrollingMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
dw .NonscrollingMenuData
db 1 ; default option
-; 0x269bd
-.NonscrollingMenuData: ; 0x269bd
+.NonscrollingMenuData:
db STATICMENU_CURSOR | STATICMENU_WRAP ; flags
db 0 ; items
dw wd002
dw DecorationMenuFunction
dw DecorationAttributes
-; 0x269c5
-.ScrollingMenuHeader: ; 0x269c5
+.ScrollingMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 1, 1, SCREEN_WIDTH - 2, SCREEN_HEIGHT - 2
dw .ScrollingMenuData
db 1 ; default option
-; 0x269cd
-.ScrollingMenuData: ; 0x269cd
+.ScrollingMenuData:
db SCROLLINGMENU_DISPLAY_ARROWS ; flags
db 8, 0 ; rows, columns
db 1 ; horizontal spacing
@@ -451,26 +414,22 @@ PopulateDecoCategoryMenu: ; 2695b
dba DecorationMenuFunction
dbw 0, 0
dbw 0, 0
-; 269dd
-
-GetDecorationData: ; 269dd
+GetDecorationData:
ld hl, DecorationAttributes
ld bc, 6
call AddNTimes
ret
-; 269e7
-GetDecorationName: ; 269e7
+GetDecorationName:
push hl
call GetDecorationData
call GetDecoName
pop hl
call CopyName2
ret
-; 269f3
-DecorationMenuFunction: ; 269f3
+DecorationMenuFunction:
ld a, [wMenuSelection]
push de
call GetDecorationData
@@ -478,9 +437,8 @@ DecorationMenuFunction: ; 269f3
pop hl
call PlaceString
ret
-; 26a02
-DoDecorationAction2: ; 26a02
+DoDecorationAction2:
ld a, [wMenuSelection]
call GetDecorationData
ld de, 2 ; function 2
@@ -489,9 +447,8 @@ DoDecorationAction2: ; 26a02
ld hl, .DecoActions
rst JumpTable
ret
-; 26a12
-.DecoActions: ; 26a12
+.DecoActions:
dw DecoAction_nothing
dw DecoAction_setupbed
dw DecoAction_putawaybed
@@ -507,10 +464,8 @@ DoDecorationAction2: ; 26a02
dw DecoAction_putawaybigdoll
dw DecoAction_setupornament
dw DecoAction_putawayornament
-; 26a30
-
-GetDecorationFlag: ; 26a30
+GetDecorationFlag:
call GetDecorationData
ld de, 3 ; event flag
add hl, de
@@ -518,17 +473,15 @@ GetDecorationFlag: ; 26a30
ld d, [hl]
ld e, a
ret
-; 26a3b
-DecorationFlagAction: ; 26a3b
+DecorationFlagAction:
push bc
call GetDecorationFlag
pop bc
call EventFlagAction
ret
-; 26a44
-GetDecorationSprite: ; 26a44
+GetDecorationSprite:
ld a, c
call GetDecorationData
ld de, 5 ; sprite
@@ -536,13 +489,12 @@ GetDecorationSprite: ; 26a44
ld a, [hl]
ld c, a
ret
-; 26a4f
INCLUDE "data/decorations/attributes.asm"
INCLUDE "data/decorations/names.asm"
-GetDecoName: ; 26c72
+GetDecoName:
ld a, [hli]
ld e, [hl]
ld bc, wStringBuffer2
@@ -551,9 +503,8 @@ GetDecoName: ; 26c72
rst JumpTable
pop de
ret
-; 26c7e
-.NameFunctions: ; 26c7e
+.NameFunctions:
dw .invalid
dw .plant
dw .bed
@@ -561,40 +512,37 @@ GetDecoName: ; 26c72
dw .poster
dw .doll
dw .bigdoll
-; 26c8c
-
-.invalid ; 26c8c
+.invalid
ret
-; 26c8d
-.plant ; 26c8d
+.plant
ld a, e
jr .getdeconame
-.bed ; 26c90
+.bed
call .plant
ld a, _BED
jr .getdeconame
-.carpet ; 26c97
+.carpet
call .plant
ld a, _CARPET
jr .getdeconame
-.poster ; 26c9e
+.poster
ld a, e
call .getpokename
ld a, _POSTER
jr .getdeconame
-.doll ; 26ca6
+.doll
ld a, e
call .getpokename
ld a, _DOLL
jr .getdeconame
-.bigdoll ; 26cae
+.bigdoll
push de
ld a, BIG_
call .getdeconame
@@ -602,25 +550,25 @@ GetDecoName: ; 26c72
ld a, e
jr .getpokename
-.unused ; 26cb8
+.unused
push de
call .getdeconame
pop de
ld a, e
jr .getdeconame
-.getpokename ; 26cc0
+.getpokename
push bc
ld [wd265], a
call GetPokemonName
pop bc
jr .copy
-.getdeconame ; 26cca
+.getdeconame
call ._getdeconame
jr .copy
-._getdeconame ; 26ccf
+._getdeconame
push bc
ld hl, DecorationNames
call GetNthString
@@ -629,7 +577,7 @@ GetDecoName: ; 26c72
pop bc
ret
-.copy ; 26cda
+.copy
ld h, b
ld l, c
call CopyName2
@@ -637,74 +585,60 @@ GetDecoName: ; 26c72
ld b, h
ld c, l
ret
-; 26ce3
-DecoAction_nothing: ; 26ce3
+DecoAction_nothing:
scf
ret
-; 26ce5
-DecoAction_setupbed: ; 26ce5
+DecoAction_setupbed:
ld hl, wDecoBed
jp DecoAction_TrySetItUp
-; 26ceb
-DecoAction_putawaybed: ; 26ceb
+DecoAction_putawaybed:
ld hl, wDecoBed
jp DecoAction_TryPutItAway
-; 26cf1
-DecoAction_setupcarpet: ; 26cf1
+DecoAction_setupcarpet:
ld hl, wDecoCarpet
jp DecoAction_TrySetItUp
-; 26cf7
-DecoAction_putawaycarpet: ; 26cf7
+DecoAction_putawaycarpet:
ld hl, wDecoCarpet
jp DecoAction_TryPutItAway
-; 26cfd
-DecoAction_setupplant: ; 26cfd
+DecoAction_setupplant:
ld hl, wDecoPlant
jp DecoAction_TrySetItUp
-; 26d03
-DecoAction_putawayplant: ; 26d03
+DecoAction_putawayplant:
ld hl, wDecoPlant
jp DecoAction_TryPutItAway
-; 26d09
-DecoAction_setupposter: ; 26d09
+DecoAction_setupposter:
ld hl, wDecoPoster
jp DecoAction_TrySetItUp
-; 26d0f
-DecoAction_putawayposter: ; 26d0f
+DecoAction_putawayposter:
ld hl, wDecoPoster
jp DecoAction_TryPutItAway
-; 26d15
-DecoAction_setupconsole: ; 26d15
+DecoAction_setupconsole:
ld hl, wDecoConsole
jp DecoAction_TrySetItUp
-; 26d1b
-DecoAction_putawayconsole: ; 26d1b
+DecoAction_putawayconsole:
ld hl, wDecoConsole
jp DecoAction_TryPutItAway
-; 26d21
-DecoAction_setupbigdoll: ; 26d21
+DecoAction_setupbigdoll:
ld hl, wDecoBigDoll
jp DecoAction_TrySetItUp
-; 26d27
-DecoAction_putawaybigdoll: ; 26d27
+DecoAction_putawaybigdoll:
ld hl, wDecoBigDoll
jp DecoAction_TryPutItAway
-; 26d2d
-DecoAction_TrySetItUp: ; 26d2d
+DecoAction_TrySetItUp:
ld a, [hl]
ld [wBuffer1], a
push hl
@@ -722,9 +656,8 @@ DecoAction_TrySetItUp: ; 26d2d
pop hl
xor a
ret
-; 26d46
-DecoAction_SetItUp: ; 26d46
+DecoAction_SetItUp:
; See if there's anything of the same type already out
ld a, [wBuffer1]
and a
@@ -760,9 +693,8 @@ DecoAction_SetItUp: ; 26d46
call MenuTextBoxBackup
scf
ret
-; 26d86
-DecoAction_TryPutItAway: ; 26d86
+DecoAction_TryPutItAway:
; If there is no item of that type already set, there is nothing to put away.
ld a, [hl]
ld [wBuffer1], a
@@ -788,9 +720,8 @@ DecoAction_TryPutItAway: ; 26d86
call MenuTextBoxBackup
xor a
ret
-; 26db3
-DecoAction_setupornament: ; 26db3
+DecoAction_setupornament:
ld hl, UnknownText_0x26e41
call DecoAction_AskWhichSide
jr c, .cancel
@@ -804,7 +735,7 @@ DecoAction_setupornament: ; 26db3
xor a
ret
-DecoAction_putawayornament: ; 26dc9
+DecoAction_putawayornament:
ld hl, DecoText_WhichSide
call DecoAction_AskWhichSide
jr nc, .incave
@@ -814,7 +745,7 @@ DecoAction_putawayornament: ; 26dc9
.incave
call DecoAction_PutItAway_Ornament
-DecoAction_FinishUp_Ornament: ; 26dd6
+DecoAction_FinishUp_Ornament:
call QueryWhichSide
ld a, [wSelectedDecoration]
ld [hl], a
@@ -822,9 +753,8 @@ DecoAction_FinishUp_Ornament: ; 26dd6
ld [de], a
xor a
ret
-; 26de3
-DecoAction_SetItUp_Ornament: ; 26de3
+DecoAction_SetItUp_Ornament:
ld a, [wSelectedDecoration]
and a
jr z, .nothingthere
@@ -863,9 +793,8 @@ DecoAction_SetItUp_Ornament: ; 26de3
call MenuTextBoxBackup
scf
ret
-; 26e33
-.getwhichside ; 26e33
+.getwhichside
ld a, [wMenuSelection]
ld b, a
ld a, [wOtherDecoration]
@@ -874,15 +803,13 @@ DecoAction_SetItUp_Ornament: ; 26de3
xor a
ld [wOtherDecoration], a
ret
-; 26e41
-UnknownText_0x26e41: ; 0x26e41
+UnknownText_0x26e41:
; Which side do you want to put it on?
text_jump UnknownText_0x1bc48c
db "@"
-; 0x26e46
-DecoAction_PutItAway_Ornament: ; 26e46
+DecoAction_PutItAway_Ornament:
ld a, [wSelectedDecoration]
and a
jr z, .nothingthere
@@ -902,15 +829,13 @@ DecoAction_PutItAway_Ornament: ; 26e46
call MenuTextBoxBackup
xor a
ret
-; 26e6b
-DecoText_WhichSide: ; 0x26e6b
+DecoText_WhichSide:
; Which side do you want to put away?
text_jump UnknownText_0x1bc4b2
db "@"
-; 0x26e70
-DecoAction_AskWhichSide: ; 26e70
+DecoAction_AskWhichSide:
call MenuTextBox
ld hl, MenuHeader_0x26eab
call GetMenu2
@@ -932,9 +857,8 @@ DecoAction_AskWhichSide: ; 26e70
.nope
scf
ret
-; 26e9a
-QueryWhichSide: ; 26e9a
+QueryWhichSide:
ld hl, wDecoRightOrnament
ld de, wDecoLeftOrnament
ld a, [wBuffer2]
@@ -945,68 +869,57 @@ QueryWhichSide: ; 26e9a
ld l, e
pop de
ret
-; 26eab
-MenuHeader_0x26eab: ; 0x26eab
+MenuHeader_0x26eab:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, 13, 7
dw MenuData_0x26eb3
db 1 ; default option
-; 0x26eb3
-MenuData_0x26eb3: ; 0x26eb3
+MenuData_0x26eb3:
db STATICMENU_CURSOR ; flags
db 3 ; items
db "RIGHT SIDE@"
db "LEFT SIDE@"
db "CANCEL@"
-; 0x26ed1
-DecoText_PutAwayTheDeco: ; 0x26ed1
+DecoText_PutAwayTheDeco:
; Put away the @ .
text_jump UnknownText_0x1bc4d7
db "@"
-; 0x26ed6
-DecoText_NothingToPutAway: ; 0x26ed6
+DecoText_NothingToPutAway:
; There's nothing to put away.
text_jump UnknownText_0x1bc4ec
db "@"
-; 0x26edb
-DecoText_SetUpTheDeco: ; 0x26edb
+DecoText_SetUpTheDeco:
; Set up the @ .
text_jump UnknownText_0x1bc509
db "@"
-; 0x26ee0
-DecoText_PutAwayAndSetUp: ; 0x26ee0
+DecoText_PutAwayAndSetUp:
; Put away the @ and set up the @ .
text_jump UnknownText_0x1bc51c
db "@"
-; 0x26ee5
-DecoText_AlreadySetUp: ; 0x26ee5
+DecoText_AlreadySetUp:
; That's already set up.
text_jump UnknownText_0x1bc546
db "@"
-; 0x26eea
-GetDecorationName_c_de: ; 26eea
+GetDecorationName_c_de:
ld a, c
ld h, d
ld l, e
call GetDecorationName
ret
-; 26ef1
-DecorationFlagAction_c: ; 26ef1
+DecorationFlagAction_c:
ld a, c
jp DecorationFlagAction
-; 26ef5
-
-GetDecorationName_c: ; 26ef5 (9:6ef5)
+GetDecorationName_c:
ld a, c
call GetDecorationID
ld hl, wStringBuffer1
@@ -1015,16 +928,14 @@ GetDecorationName_c: ; 26ef5 (9:6ef5)
pop de
ret
-
-SetSpecificDecorationFlag: ; 26f02
+SetSpecificDecorationFlag:
ld a, c
call GetDecorationID
ld b, SET_FLAG
call DecorationFlagAction
ret
-; 26f0c
-GetDecorationID: ; 26f0c
+GetDecorationID:
push hl
push de
ld e, a
@@ -1035,9 +946,8 @@ GetDecorationID: ; 26f0c
pop de
pop hl
ret
-; 26f19
-SetAllDecorationFlags: ; 26f19
+SetAllDecorationFlags:
ld hl, DecorationIDs
.loop
ld a, [hli]
@@ -1051,27 +961,24 @@ SetAllDecorationFlags: ; 26f19
.done
ret
-; 26f2b
INCLUDE "data/decorations/decorations.asm"
-DescribeDecoration:: ; 26f59
+DescribeDecoration::
ld a, b
ld hl, .JumpTable
rst JumpTable
ret
-; 26f5f
-.JumpTable: ; 26f5f
+.JumpTable:
; entries correspond to DECODESC_* constants
dw DecorationDesc_Poster
dw DecorationDesc_LeftOrnament
dw DecorationDesc_RightOrnament
dw DecorationDesc_GiantOrnament
dw DecorationDesc_Console
-; 26f69
-DecorationDesc_Poster: ; 26f69
+DecorationDesc_Poster:
ld a, [wDecoPoster]
ld hl, DecorationDesc_PosterPointers
ld de, 3
@@ -1088,124 +995,108 @@ DecorationDesc_Poster: ; 26f69
ld d, [hl]
ld e, a
ret
-; 26f84
-DecorationDesc_PosterPointers: ; 26f84
+DecorationDesc_PosterPointers:
dbw DECO_TOWN_MAP, DecorationDesc_TownMapPoster
dbw DECO_PIKACHU_POSTER, DecorationDesc_PikachuPoster
dbw DECO_CLEFAIRY_POSTER, DecorationDesc_ClefairyPoster
dbw DECO_JIGGLYPUFF_POSTER, DecorationDesc_JigglypuffPoster
db -1
-; 26f91
-DecorationDesc_TownMapPoster: ; 0x26f91
+DecorationDesc_TownMapPoster:
opentext
writetext .TownMapText
waitbutton
special OverworldTownMap
closetext
end
-; 0x26f9b
-.TownMapText: ; 0x26f9b
+.TownMapText:
; It's the TOWN MAP.
text_jump UnknownText_0x1bc55d
db "@"
-; 0x26fa0
-DecorationDesc_PikachuPoster: ; 0x26fa0
+DecorationDesc_PikachuPoster:
jumptext .PikaPosterText
-; 0x26fa3
-.PikaPosterText: ; 0x26fa3
+.PikaPosterText:
; It's a poster of a cute PIKACHU.
text_jump UnknownText_0x1bc570
db "@"
-; 0x26fa8
-DecorationDesc_ClefairyPoster: ; 0x26fa8
+DecorationDesc_ClefairyPoster:
jumptext .ClefairyPosterText
-; 0x26fab
-.ClefairyPosterText: ; 0x26fab
+.ClefairyPosterText:
; It's a poster of a cute CLEFAIRY.
text_jump UnknownText_0x1bc591
db "@"
-; 0x26fb0
-DecorationDesc_JigglypuffPoster: ; 0x26fb0
+DecorationDesc_JigglypuffPoster:
jumptext .JigglypuffPosterText
-; 0x26fb3
-.JigglypuffPosterText: ; 0x26fb3
+.JigglypuffPosterText:
; It's a poster of a cute JIGGLYPUFF.
text_jump UnknownText_0x1bc5b3
db "@"
-; 0x26fb8
-DecorationDesc_NullPoster: ; 26fb8
+DecorationDesc_NullPoster:
end
-; 26fb9
-DecorationDesc_LeftOrnament: ; 26fb9
+DecorationDesc_LeftOrnament:
ld a, [wDecoLeftOrnament]
jr DecorationDesc_OrnamentOrConsole
-DecorationDesc_RightOrnament: ; 26fbe
+DecorationDesc_RightOrnament:
ld a, [wDecoRightOrnament]
jr DecorationDesc_OrnamentOrConsole
-DecorationDesc_Console: ; 26fc3
+DecorationDesc_Console:
ld a, [wDecoConsole]
jr DecorationDesc_OrnamentOrConsole
-DecorationDesc_OrnamentOrConsole: ; 26fc8
+DecorationDesc_OrnamentOrConsole:
ld c, a
ld de, wStringBuffer3
call GetDecorationName_c_de
ld b, BANK(.OrnamentConsoleScript)
ld de, .OrnamentConsoleScript
ret
-; 26fd5
-.OrnamentConsoleScript: ; 26fd5
+.OrnamentConsoleScript:
jumptext .OrnamentConsoleText
-; 26fd8
-.OrnamentConsoleText: ; 0x26fd8
+.OrnamentConsoleText:
; It's an adorable @ .
text_jump UnknownText_0x1bc5d7
db "@"
-; 0x26fdd
-DecorationDesc_GiantOrnament: ; 26fdd
+DecorationDesc_GiantOrnament:
ld b, BANK(.BigDollScript)
ld de, .BigDollScript
ret
-; 26fe3
-.BigDollScript: ; 26fe3
+.BigDollScript:
jumptext .BigDollText
-; 26fe6
-.BigDollText: ; 0x26fe6
+.BigDollText:
; A giant doll! It's fluffy and cuddly.
text_jump UnknownText_0x1bc5ef
db "@"
-; 0x26feb
-ToggleMaptileDecorations: ; 26feb
- lb de, 0, 4
+ToggleMaptileDecorations:
+ ; tile coordinates work the same way as for changeblock
+ lb de, 0, 4 ; bed coordinates
ld a, [wDecoBed]
call SetDecorationTile
- lb de, 7, 4
+ lb de, 7, 4 ; plant coordinates
ld a, [wDecoPlant]
call SetDecorationTile
- lb de, 6, 0
+ lb de, 6, 0 ; poster coordinates
ld a, [wDecoPoster]
call SetDecorationTile
call SetPosterVisibility
- lb de, 0, 0
+ lb de, 0, 0 ; carpet top-left coordinates
call PadCoords_de
ld a, [wDecoCarpet]
and a
@@ -1213,19 +1104,18 @@ ToggleMaptileDecorations: ; 26feb
call _GetDecorationSprite
ld [hl], a
push af
- lb de, 0, 2
+ lb de, 0, 2 ; carpet bottom-left coordinates
call PadCoords_de
pop af
inc a
- ld [hli], a
+ ld [hli], a ; carpet bottom-left block
inc a
- ld [hli], a
+ ld [hli], a ; carpet bottom-middle block
dec a
- ld [hl], a
+ ld [hl], a ; carpet bottom-right block
ret
-; 27027
-SetPosterVisibility: ; 27027
+SetPosterVisibility:
ld b, SET_FLAG
ld a, [wDecoPoster]
and a
@@ -1235,9 +1125,8 @@ SetPosterVisibility: ; 27027
.ok
ld de, EVENT_PLAYERS_ROOM_POSTER
jp EventFlagAction
-; 27037
-SetDecorationTile: ; 27037
+SetDecorationTile:
push af
call PadCoords_de
pop af
@@ -1246,9 +1135,8 @@ SetDecorationTile: ; 27037
call _GetDecorationSprite
ld [hl], a
ret
-; 27043
-ToggleDecorationsVisibility: ; 27043
+ToggleDecorationsVisibility:
ld de, EVENT_PLAYERS_HOUSE_2F_CONSOLE
ld hl, wVariableSprites + SPRITE_CONSOLE - SPRITE_VARS
ld a, [wDecoConsole]
@@ -1266,9 +1154,8 @@ ToggleDecorationsVisibility: ; 27043
ld a, [wDecoBigDoll]
call ToggleDecorationVisibility
ret
-; 27074
-ToggleDecorationVisibility: ; 27074
+ToggleDecorationVisibility:
and a
jr z, .hide
call _GetDecorationSprite
@@ -1279,9 +1166,8 @@ ToggleDecorationVisibility: ; 27074
.hide
ld b, SET_FLAG
jp EventFlagAction
-; 27085
-_GetDecorationSprite: ; 27085
+_GetDecorationSprite:
ld c, a
push de
push hl
@@ -1290,9 +1176,9 @@ _GetDecorationSprite: ; 27085
pop de
ld a, c
ret
-; 27092
-PadCoords_de: ; 27092
+PadCoords_de:
+; adjusts coordinates, the same way as Script_changeblock
ld a, d
add 4
ld d, a
diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm
index cc2c8c574..e4defbc2b 100644
--- a/engine/overworld/events.asm
+++ b/engine/overworld/events.asm
@@ -3,7 +3,7 @@ INCLUDE "constants.asm"
SECTION "Events", ROMX
-OverworldLoop:: ; 966b0
+OverworldLoop::
xor a
ld [wMapStatus], a
.loop
@@ -21,99 +21,83 @@ OverworldLoop:: ; 966b0
dw EnterMap
dw HandleMap
dw .done
-; 966cb
-DisableEvents: ; 966cb
+DisableEvents:
xor a
ld [wScriptFlags3], a
ret
-; 966d0
-EnableEvents:: ; 966d0
+EnableEvents::
ld a, $ff
ld [wScriptFlags3], a
ret
-; 966d6
-CheckBit5_ScriptFlags3: ; 966d6
+CheckBit5_ScriptFlags3:
ld hl, wScriptFlags3
bit 5, [hl]
ret
-; 966dc
-DisableWarpsConnxns: ; 966dc
+DisableWarpsConnxns:
ld hl, wScriptFlags3
res 2, [hl]
ret
-; 966e2
-DisableCoordEvents: ; 966e2
+DisableCoordEvents:
ld hl, wScriptFlags3
res 1, [hl]
ret
-; 966e8
-DisableStepCount: ; 966e8
+DisableStepCount:
ld hl, wScriptFlags3
res 0, [hl]
ret
-; 966ee
-DisableWildEncounters: ; 966ee
+DisableWildEncounters:
ld hl, wScriptFlags3
res 4, [hl]
ret
-; 966f4
-EnableWarpsConnxns: ; 966f4
+EnableWarpsConnxns:
ld hl, wScriptFlags3
set 2, [hl]
ret
-; 966fa
-EnableCoordEvents: ; 966fa
+EnableCoordEvents:
ld hl, wScriptFlags3
set 1, [hl]
ret
-; 96700
-EnableStepCount: ; 96700
+EnableStepCount:
ld hl, wScriptFlags3
set 0, [hl]
ret
-; 96706
-EnableWildEncounters: ; 96706
+EnableWildEncounters:
ld hl, wScriptFlags3
set 4, [hl]
ret
-; 9670c
-CheckWarpConnxnScriptFlag: ; 9670c
+CheckWarpConnxnScriptFlag:
ld hl, wScriptFlags3
bit 2, [hl]
ret
-; 96712
-CheckCoordEventScriptFlag: ; 96712
+CheckCoordEventScriptFlag:
ld hl, wScriptFlags3
bit 1, [hl]
ret
-; 96718
-CheckStepCountScriptFlag: ; 96718
+CheckStepCountScriptFlag:
ld hl, wScriptFlags3
bit 0, [hl]
ret
-; 9671e
-CheckWildEncountersScriptFlag: ; 9671e
+CheckWildEncountersScriptFlag:
ld hl, wScriptFlags3
bit 4, [hl]
ret
-; 96724
-StartMap: ; 96724
+StartMap:
xor a
ld [wScriptVar], a
xor a
@@ -123,7 +107,7 @@ StartMap: ; 96724
call ByteFill
farcall InitCallReceiveDelay
call ClearJoypad
-EnterMap: ; 9673e
+EnterMap:
xor a
ld [wXYComparePointer], a
ld [wXYComparePointer + 1], a
@@ -149,15 +133,13 @@ EnterMap: ; 9673e
ld a, 2 ; HandleMap
ld [wMapStatus], a
ret
-; 9676d
-UnusedWait30Frames: ; 9676d
+UnusedWait30Frames:
ld c, 30
call DelayFrames
ret
-; 96773
-HandleMap: ; 96773
+HandleMap:
call ResetOverworldDelay
call HandleMapTimeAndJoypad
farcall HandleCmdQueue ; no need to farcall
@@ -173,9 +155,8 @@ HandleMap: ; 96773
call HandleMapBackground
call CheckPlayerState
ret
-; 96795
-MapEvents: ; 96795
+MapEvents:
ld a, [wMapEventStatus]
ld hl, .jumps
rst JumpTable
@@ -184,39 +165,33 @@ MapEvents: ; 96795
.jumps
dw .events
dw .no_events
-; 967a1
-.events ; 967a1
+.events
call PlayerEvents
call DisableEvents
farcall ScriptEvents
ret
-; 967ae
-.no_events ; 967ae
+.no_events
ret
-; 967af
-MaxOverworldDelay: ; 967af
+MaxOverworldDelay:
db 2
-; 967b0
-ResetOverworldDelay: ; 967b0
+ResetOverworldDelay:
ld a, [MaxOverworldDelay]
ld [wOverworldDelay], a
ret
-; 967b7
-NextOverworldFrame: ; 967b7
+NextOverworldFrame:
ld a, [wOverworldDelay]
and a
ret z
ld c, a
call DelayFrames
ret
-; 967c1
-HandleMapTimeAndJoypad: ; 967c1
+HandleMapTimeAndJoypad:
ld a, [wMapEventStatus]
cp 1 ; no events
ret z
@@ -225,23 +200,20 @@ HandleMapTimeAndJoypad: ; 967c1
call GetJoypad
call TimeOfDayPals
ret
-; 967d1
-HandleMapObjects: ; 967d1
+HandleMapObjects:
farcall HandleNPCStep ; engine/map_objects.asm
farcall _HandlePlayerStep
call _CheckObjectEnteringVisibleRange
ret
-; 967e1
-HandleMapBackground: ; 967e1
+HandleMapBackground:
farcall _UpdateSprites
farcall ScrollScreen
farcall PlaceMapNameSign
ret
-; 967f4
-CheckPlayerState: ; 967f4
+CheckPlayerState:
ld a, [wPlayerStepFlags]
bit 5, a ; in the middle of step
jr z, .events
@@ -259,17 +231,15 @@ CheckPlayerState: ; 967f4
ld a, 1 ; no events
ld [wMapEventStatus], a
ret
-; 96812
-_CheckObjectEnteringVisibleRange: ; 96812
+_CheckObjectEnteringVisibleRange:
ld hl, wPlayerStepFlags
bit 6, [hl]
ret z
farcall CheckObjectEnteringVisibleRange
ret
-; 9681f
-PlayerEvents: ; 9681f
+PlayerEvents:
xor a
; If there's already a player event, don't interrupt it.
ld a, [wScriptRunning]
@@ -318,9 +288,8 @@ PlayerEvents: ; 9681f
.ok2
scf
ret
-; 96867
-CheckTrainerBattle3: ; 96867
+CheckTrainerBattle3:
nop
nop
call CheckTrainerBattle2
@@ -333,9 +302,8 @@ CheckTrainerBattle3: ; 96867
.nope
xor a
ret
-; 96874
-CheckTileEvent: ; 96874
+CheckTileEvent:
; Check for warps, coord events, or wild battles.
call CheckWarpConnxnScriptFlag
@@ -399,9 +367,8 @@ CheckTileEvent: ; 96874
call GetMapScriptsBank
call CallScript
ret
-; 968c7
-CheckWildEncounterCooldown:: ; 968c7
+CheckWildEncounterCooldown::
ld hl, wWildEncounterCooldown
ld a, [hl]
and a
@@ -410,35 +377,30 @@ CheckWildEncounterCooldown:: ; 968c7
ret z
scf
ret
-; 968d1
-SetUpFiveStepWildEncounterCooldown: ; 968d1
+SetUpFiveStepWildEncounterCooldown:
ld a, 5
ld [wWildEncounterCooldown], a
ret
-; 968d7
-ret_968d7: ; 968d7
+ret_968d7:
ret
-;968d8
-SetMinTwoStepWildEncounterCooldown: ; 968d8
+SetMinTwoStepWildEncounterCooldown:
ld a, [wWildEncounterCooldown]
cp 2
ret nc
ld a, 2
ld [wWildEncounterCooldown], a
ret
-; 968e4
-Dummy_CheckScriptFlags3Bit5: ; 968e4
+Dummy_CheckScriptFlags3Bit5:
call CheckBit5_ScriptFlags3
ret z
call ret_2f3e
ret
-; 968ec
-RunSceneScript: ; 968ec
+RunSceneScript:
ld a, [wCurrMapSceneScriptCount]
and a
jr z, .nope
@@ -485,9 +447,8 @@ endr
.nope
xor a
ret
-; 9693a
-CheckTimeEvents: ; 9693a
+CheckTimeEvents:
ld a, [wLinkMode]
and a
jr nz, .nothing
@@ -517,16 +478,13 @@ CheckTimeEvents: ; 9693a
call CallScript
scf
ret
-; 96970
-.unused ; 96970
+.unused
ld a, 8
scf
ret
-; 96974
-
-OWPlayerInput: ; 96974
+OWPlayerInput:
call PlayerMovement
ret c
and a
@@ -552,9 +510,8 @@ OWPlayerInput: ; 96974
pop af
scf
ret
-; 96999
-CheckAPressOW: ; 96999
+CheckAPressOW:
ld a, [hJoyPressed]
and A_BUTTON
ret z
@@ -566,17 +523,15 @@ CheckAPressOW: ; 96999
ret c
xor a
ret
-; 969ac
-PlayTalkObject: ; 969ac
+PlayTalkObject:
push de
ld de, SFX_READ_TEXT_2
call PlaySFX
pop de
ret
-; 969b5
-TryObjectEvent: ; 969b5
+TryObjectEvent:
farcall CheckFacingObject
jr c, .IsObject
xor a
@@ -627,9 +582,8 @@ TryObjectEvent: ; 969b5
dbw OBJECTTYPE_5, .five
dbw OBJECTTYPE_6, .six
db -1
-; 96a04
-.script ; 96a04
+.script
ld hl, MAPOBJECT_SCRIPT_POINTER
add hl, bc
ld a, [hli]
@@ -638,9 +592,8 @@ TryObjectEvent: ; 969b5
call GetMapScriptsBank
call CallScript
ret
-; 96a12
-.itemball ; 96a12
+.itemball
ld hl, MAPOBJECT_SCRIPT_POINTER
add hl, bc
ld a, [hli]
@@ -653,36 +606,30 @@ TryObjectEvent: ; 969b5
ld a, PLAYEREVENT_ITEMBALL
scf
ret
-; 96a29
-.trainer ; 96a29
+.trainer
call TalkToTrainer
ld a, PLAYEREVENT_TALKTOTRAINER
scf
ret
-; 96a30
-.three ; 96a30
+.three
xor a
ret
-; 96a32
-.four ; 96a32
+.four
xor a
ret
-; 96a34
-.five ; 96a34
+.five
xor a
ret
-; 96a36
-.six ; 96a36
+.six
xor a
ret
-; 96a38
-TryBGEvent: ; 96a38
+TryBGEvent:
call CheckFacingBGEvent
jr c, .is_bg_event
xor a
@@ -704,7 +651,6 @@ TryBGEvent: ; 96a38
dw .ifnotset
dw .itemifset
dw .copy
-; 96a59
.up
ld b, OW_UP
@@ -784,9 +730,8 @@ TryBGEvent: ; 96a38
.dontread
xor a
ret
-; 96ad8
-CheckBGEventFlag: ; 96ad8
+CheckBGEventFlag:
ld hl, wEngineBuffer4
ld a, [hli]
ld h, [hl]
@@ -802,16 +747,14 @@ CheckBGEventFlag: ; 96ad8
and a
pop hl
ret
-; 96af0
-PlayerMovement: ; 96af0
+PlayerMovement:
farcall DoPlayerMovement
ld a, c
ld hl, .pointers
rst JumpTable
ld a, c
ret
-; 96afd
.pointers
dw .zero
@@ -824,34 +767,30 @@ PlayerMovement: ; 96af0
dw .seven
.zero
-.four ; 96b0d
+.four
xor a
ld c, a
ret
-; 96b10
-.seven ; 96b10
+.seven
call ret_968d7 ; mobile
xor a
ld c, a
ret
-; 96b16
-.one ; 96b16
+.one
ld a, 5
ld c, a
scf
ret
-; 96b1b
-.two ; 96b1b
+.two
ld a, 9
ld c, a
scf
ret
-; 96b20
-.three ; 96b20
+.three
; force the player to move in some direction
ld a, BANK(Script_ForcedMovement)
ld hl, Script_ForcedMovement
@@ -860,17 +799,15 @@ PlayerMovement: ; 96af0
ld c, a
scf
ret
-; 96b2b
.five
-.six ; 96b2b
+.six
ld a, -1
ld c, a
and a
ret
-; 96b30
-CheckMenuOW: ; 96b30
+CheckMenuOW:
xor a
ld [hMenuReturn], a
ld [hMenuReturn + 1], a
@@ -899,36 +836,30 @@ CheckMenuOW: ; 96b30
call CallScript
scf
ret
-; 96b58
-StartMenuScript: ; 96b58
+StartMenuScript:
callasm StartMenu
jump StartMenuCallback
-; 96b5f
-SelectMenuScript: ; 96b5f
+SelectMenuScript:
callasm SelectMenu
jump SelectMenuCallback
-; 96b66
StartMenuCallback:
-SelectMenuCallback: ; 96b66
+SelectMenuCallback:
copybytetovar hMenuReturn
ifequal HMENURETURN_SCRIPT, .Script
ifequal HMENURETURN_ASM, .Asm
end
-; 96b72
-.Script: ; 96b72
+.Script:
ptjump wQueuedScriptBank
-; 96b75
-.Asm: ; 96b75
+.Asm:
ptcallasm wQueuedScriptBank
end
-; 96b79
-CountStep: ; 96b79
+CountStep:
; Don't count steps in link communication rooms.
ld a, [wLinkMode]
and a
@@ -993,16 +924,14 @@ CountStep: ; 96b79
ld a, 8
scf
ret
-; 96bd3
; unused
-.unreferenced ; 96bd3
+.unreferenced
ld a, 7
scf
ret
-; 96bd7
-DoRepelStep: ; 96bd7
+DoRepelStep:
ld a, [wRepelEffect]
and a
ret z
@@ -1016,9 +945,8 @@ DoRepelStep: ; 96bd7
call CallScript
scf
ret
-; 96beb
-DoPlayerEvent: ; 96beb
+DoPlayerEvent:
ld a, [wScriptRunning]
and a
ret z
@@ -1042,9 +970,8 @@ DoPlayerEvent: ; 96beb
ld a, [hl]
ld [wScriptPos + 1], a
ret
-; 96c0c
-PlayerEventScriptPointers: ; 96c0c
+PlayerEventScriptPointers:
dba Invalid_0x96c2d ; 0
dba SeenByTrainerScript ; 1
dba TalkToTrainerScript ; 2
@@ -1056,56 +983,656 @@ PlayerEventScriptPointers: ; 96c0c
dba HatchEggScript ; 8
dba ChangeDirectionScript ; 9
dba Invalid_0x96c2d ; 10
-; 96c2d
-Invalid_0x96c2d: ; 96c2d
+Invalid_0x96c2d:
end
-; 96c2e
; unused
end
-; 96c2f
-HatchEggScript: ; 96c2f
+HatchEggScript:
callasm OverworldHatchEgg
end
-; 96c34
-WarpToNewMapScript: ; 96c34
+WarpToNewMapScript:
warpsound
newloadmap MAPSETUP_DOOR
end
-; 96c38
-FallIntoMapScript: ; 96c38
+FallIntoMapScript:
newloadmap MAPSETUP_FALL
playsound SFX_KINESIS
applymovement PLAYER, MovementData_0x96c48
playsound SFX_STRENGTH
scall LandAfterPitfallScript
end
-; 96c48
-MovementData_0x96c48: ; 96c48
+MovementData_0x96c48:
skyfall
step_end
-; 96c4a
-LandAfterPitfallScript: ; 96c4a
+LandAfterPitfallScript:
earthquake 16
end
-; 96c4d
EdgeWarpScript: ; 4
reloadandreturn MAPSETUP_CONNECTION
-; 96c4f
ChangeDirectionScript: ; 9
deactivatefacing 3
callasm EnableWildEncounters
end
-; 96c56
INCLUDE "engine/overworld/scripting.asm"
-INCLUDE "engine/overworld/events_2.asm"
+WarpToSpawnPoint::
+ ld hl, wStatusFlags2
+ res STATUSFLAGS2_SAFARI_GAME_F, [hl]
+ res STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
+ ret
+
+RunMemScript::
+; If there is no script here, we don't need to be here.
+ ld a, [wMapReentryScriptQueueFlag]
+ and a
+ ret z
+; Execute the script at (wMapReentryScriptBank):(wMapReentryScriptAddress).
+ ld hl, wMapReentryScriptAddress
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [wMapReentryScriptBank]
+ call CallScript
+ scf
+; Clear the buffer for the next script.
+ push af
+ xor a
+ ld hl, wMapReentryScriptQueueFlag
+ ld bc, 8
+ call ByteFill
+ pop af
+ ret
+
+LoadScriptBDE::
+; If there's already a script here, don't overwrite.
+ ld hl, wMapReentryScriptQueueFlag
+ ld a, [hl]
+ and a
+ ret nz
+; Set the flag
+ ld [hl], 1
+ inc hl
+; Load the script pointer b:de into (wMapReentryScriptBank):(wMapReentryScriptAddress)
+ ld [hl], b
+ inc hl
+ ld [hl], e
+ inc hl
+ ld [hl], d
+ scf
+ ret
+
+TryTileCollisionEvent::
+ call GetFacingTileCoord
+ ld [wEngineBuffer1], a
+ ld c, a
+ farcall CheckFacingTileForStdScript
+ jr c, .done
+
+ call CheckCutTreeTile
+ jr nz, .whirlpool
+ farcall TryCutOW
+ jr .done
+
+.whirlpool
+ ld a, [wEngineBuffer1]
+ call CheckWhirlpoolTile
+ jr nz, .waterfall
+ farcall TryWhirlpoolOW
+ jr .done
+
+.waterfall
+ ld a, [wEngineBuffer1]
+ call CheckWaterfallTile
+ jr nz, .headbutt
+ farcall TryWaterfallOW
+ jr .done
+
+.headbutt
+ ld a, [wEngineBuffer1]
+ call CheckHeadbuttTreeTile
+ jr nz, .surf
+ farcall TryHeadbuttOW
+ jr c, .done
+ jr .noevent
+
+.surf
+ farcall TrySurfOW
+ jr nc, .noevent
+ jr .done
+
+.noevent
+ xor a
+ ret
+
+.done
+ call PlayClickSFX
+ ld a, $ff
+ scf
+ ret
+
+RandomEncounter::
+; Random encounter
+
+ call CheckWildEncounterCooldown
+ jr c, .nope
+ call CanUseSweetScent
+ jr nc, .nope
+ ld hl, wStatusFlags2
+ bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
+ jr nz, .bug_contest
+ farcall TryWildEncounter
+ jr nz, .nope
+ jr .ok
+
+.bug_contest
+ call _TryWildEncounter_BugContest
+ jr nc, .nope
+ jr .ok_bug_contest
+
+.nope
+ ld a, 1
+ and a
+ ret
+
+.ok
+ ld a, BANK(WildBattleScript)
+ ld hl, WildBattleScript
+ jr .done
+
+.ok_bug_contest
+ ld a, BANK(BugCatchingContestBattleScript)
+ ld hl, BugCatchingContestBattleScript
+ jr .done
+
+.done
+ call CallScript
+ scf
+ ret
+
+WildBattleScript:
+ randomwildmon
+ startbattle
+ reloadmapafterbattle
+ end
+
+CanUseSweetScent::
+ ld hl, wStatusFlags
+ bit STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl]
+ jr nz, .no
+ ld a, [wEnvironment]
+ cp CAVE
+ jr z, .ice_check
+ cp DUNGEON
+ jr z, .ice_check
+ farcall CheckGrassCollision
+ jr nc, .no
+
+.ice_check
+ ld a, [wPlayerStandingTile]
+ call CheckIceTile
+ jr z, .no
+ scf
+ ret
+
+.no
+ and a
+ ret
+
+_TryWildEncounter_BugContest:
+ call TryWildEncounter_BugContest
+ ret nc
+ call ChooseWildEncounter_BugContest
+ farcall CheckRepelEffect
+ ret
+
+ChooseWildEncounter_BugContest::
+; Pick a random mon out of ContestMons.
+
+.loop
+ call Random
+ cp 100 << 1
+ jr nc, .loop
+ srl a
+
+ ld hl, ContestMons
+ ld de, 4
+.CheckMon:
+ sub [hl]
+ jr c, .GotMon
+ add hl, de
+ jr .CheckMon
+
+.GotMon:
+ inc hl
+
+; Species
+ ld a, [hli]
+ ld [wTempWildMonSpecies], a
+
+; Min level
+ ld a, [hli]
+ ld d, a
+
+; Max level
+ ld a, [hl]
+
+ sub d
+ jr nz, .RandomLevel
+
+; If min and max are the same.
+ ld a, d
+ jr .GotLevel
+
+.RandomLevel:
+; Get a random level between the min and max.
+ ld c, a
+ inc c
+ call Random
+ ld a, [hRandomAdd]
+ call SimpleDivide
+ add d
+
+.GotLevel:
+ ld [wCurPartyLevel], a
+
+ xor a
+ ret
+
+TryWildEncounter_BugContest:
+ ld a, [wPlayerStandingTile]
+ call CheckSuperTallGrassTile
+ ld b, 40 percent
+ jr z, .ok
+ ld b, 20 percent
+
+.ok
+ farcall ApplyMusicEffectOnEncounterRate
+ farcall ApplyCleanseTagEffectOnEncounterRate
+ call Random
+ ld a, [hRandomAdd]
+ cp b
+ ret c
+ ld a, 1
+ and a
+ ret
+
+INCLUDE "data/wild/bug_contest_mons.asm"
+
+DoBikeStep::
+ nop
+ nop
+ ; If the bike shop owner doesn't have our number, or
+ ; if we've already gotten the call, we don't have to
+ ; be here.
+ ld hl, wStatusFlags2
+ bit STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl]
+ jr z, .NoCall
+
+ ; If we're not on the bike, we don't have to be here.
+ ld a, [wPlayerState]
+ cp PLAYER_BIKE
+ jr nz, .NoCall
+
+ ; If we're not in an area of phone service, we don't
+ ; have to be here.
+ call GetMapPhoneService
+ and a
+ jr nz, .NoCall
+
+ ; Check the bike step count and check whether we've
+ ; taken 65536 of them yet.
+ ld hl, wBikeStep
+ ld a, [hli]
+ ld d, a
+ ld e, [hl]
+ cp 255
+ jr nz, .increment
+ ld a, e
+ cp 255
+ jr z, .dont_increment
+
+.increment
+ inc de
+ ld [hl], e
+ dec hl
+ ld [hl], d
+
+.dont_increment
+ ; If we've taken at least 1024 steps, have the bike
+ ; shop owner try to call us.
+ ld a, d
+ cp HIGH(1024)
+ jr c, .NoCall
+
+ ; If a call has already been queued, don't overwrite
+ ; that call.
+ ld a, [wSpecialPhoneCallID]
+ and a
+ jr nz, .NoCall
+
+ ; Queue the call.
+ ld a, SPECIALCALL_BIKESHOP
+ ld [wSpecialPhoneCallID], a
+ xor a
+ ld [wSpecialPhoneCallID + 1], a
+ ld hl, wStatusFlags2
+ res STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl]
+ scf
+ ret
+
+.NoCall:
+ xor a
+ ret
+
+ClearCmdQueue::
+ ld hl, wCmdQueue
+ ld de, CMDQUEUE_ENTRY_SIZE
+ ld c, CMDQUEUE_CAPACITY
+ xor a
+.loop
+ ld [hl], a
+ add hl, de
+ dec c
+ jr nz, .loop
+ ret
+
+HandleCmdQueue::
+ ld hl, wCmdQueue
+ xor a
+.loop
+ ld [hMapObjectIndexBuffer], a
+ ld a, [hl]
+ and a
+ jr z, .skip
+ push hl
+ ld b, h
+ ld c, l
+ call HandleQueuedCommand
+ pop hl
+
+.skip
+ ld de, CMDQUEUE_ENTRY_SIZE
+ add hl, de
+ ld a, [hMapObjectIndexBuffer]
+ inc a
+ cp CMDQUEUE_CAPACITY
+ jr nz, .loop
+ ret
+
+Unreferenced_GetNthCmdQueueEntry:
+ ld hl, wCmdQueue
+ ld bc, CMDQUEUE_ENTRY_SIZE
+ call AddNTimes
+ ld b, h
+ ld c, l
+ ret
+
+WriteCmdQueue::
+ push bc
+ push de
+ call .GetNextEmptyEntry
+ ld d, h
+ ld e, l
+ pop hl
+ pop bc
+ ret c
+ ld a, b
+ ld bc, CMDQUEUE_ENTRY_SIZE - 1
+ call FarCopyBytes
+ xor a
+ ld [hl], a
+ ret
+
+.GetNextEmptyEntry:
+ ld hl, wCmdQueue
+ ld de, CMDQUEUE_ENTRY_SIZE
+ ld c, CMDQUEUE_CAPACITY
+.loop
+ ld a, [hl]
+ and a
+ jr z, .done
+ add hl, de
+ dec c
+ jr nz, .loop
+ scf
+ ret
+
+.done
+ ld a, CMDQUEUE_CAPACITY
+ sub c
+ and a
+ ret
+
+DelCmdQueue::
+ ld hl, wCmdQueue
+ ld de, CMDQUEUE_ENTRY_SIZE
+ ld c, CMDQUEUE_CAPACITY
+.loop
+ ld a, [hl]
+ cp b
+ jr z, .done
+ add hl, de
+ dec c
+ jr nz, .loop
+ and a
+ ret
+
+.done
+ xor a
+ ld [hl], a
+ scf
+ ret
+
+_DelCmdQueue:
+ ld hl, CMDQUEUE_TYPE
+ add hl, bc
+ ld [hl], 0
+ ret
+
+HandleQueuedCommand:
+ ld hl, CMDQUEUE_TYPE
+ add hl, bc
+ ld a, [hl]
+ cp NUM_CMDQUEUE_TYPES
+ jr c, .okay
+ xor a
+
+.okay
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ push af
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop af
+ rst FarCall
+ ret
+
+.Jumptable:
+ dba CmdQueue_Null
+ dba CmdQueue_Null2
+ dba CmdQueue_StoneTable
+ dba CmdQueue_Type3
+ dba CmdQueue_Type4
+
+CmdQueueAnonymousJumptable:
+ ld hl, CMDQUEUE_05
+ add hl, bc
+ ld a, [hl]
+ pop hl
+ rst JumpTable
+ ret
+
+CmdQueueAnonJT_Increment:
+ ld hl, CMDQUEUE_05
+ add hl, bc
+ inc [hl]
+ ret
+
+CmdQueueAnonJT_Decrement:
+ ld hl, CMDQUEUE_05
+ add hl, bc
+ dec [hl]
+ ret
+
+CmdQueue_Null:
+ ret
+
+CmdQueue_Null2:
+ call ret_2f3e
+ ret
+
+CmdQueue_Type4:
+ call CmdQueueAnonymousJumptable
+ ; anonymous dw
+ dw .zero
+ dw .one
+
+.zero
+ ld a, [hSCY]
+ ld hl, 4
+ add hl, bc
+ ld [hl], a
+ call CmdQueueAnonJT_Increment
+.one
+ ld hl, 1
+ add hl, bc
+ ld a, [hl]
+ dec a
+ ld [hl], a
+ jr z, .finish
+ and $1
+ jr z, .add
+ ld hl, 2
+ add hl, bc
+ ld a, [hSCY]
+ sub [hl]
+ ld [hSCY], a
+ ret
+
+.add
+ ld hl, 2
+ add hl, bc
+ ld a, [hSCY]
+ add [hl]
+ ld [hSCY], a
+ ret
+
+.finish
+ ld hl, 4
+ add hl, bc
+ ld a, [hl]
+ ld [hSCY], a
+ call _DelCmdQueue
+ ret
+
+CmdQueue_Type3:
+ call CmdQueueAnonymousJumptable
+ ; anonymous dw
+ dw .zero
+ dw .one
+ dw .two
+
+.zero
+ call .IsPlayerFacingDown
+ jr z, .PlayerNotFacingDown
+ call CmdQueueAnonJT_Increment
+.one
+ call .IsPlayerFacingDown
+ jr z, .PlayerNotFacingDown
+ call CmdQueueAnonJT_Increment
+
+ ld hl, 2
+ add hl, bc
+ ld a, [hl]
+ ld [wd173], a
+ ret
+
+.two
+ call .IsPlayerFacingDown
+ jr z, .PlayerNotFacingDown
+ call CmdQueueAnonJT_Decrement
+
+ ld hl, 3
+ add hl, bc
+ ld a, [hl]
+ ld [wd173], a
+ ret
+
+.PlayerNotFacingDown:
+ ld a, $7f
+ ld [wd173], a
+ ld hl, 5
+ add hl, bc
+ ld [hl], 0
+ ret
+
+.IsPlayerFacingDown:
+ push bc
+ ld bc, wPlayerStruct
+ call GetSpriteDirection
+ and a
+ pop bc
+ ret
+
+CmdQueue_StoneTable:
+ ld de, wPlayerStruct
+ ld a, NUM_OBJECT_STRUCTS
+.loop
+ push af
+
+ ld hl, OBJECT_SPRITE
+ add hl, de
+ ld a, [hl]
+ and a
+ jr z, .next
+
+ ld hl, OBJECT_MOVEMENTTYPE
+ add hl, de
+ ld a, [hl]
+ cp SPRITEMOVEDATA_STRENGTH_BOULDER
+ jr nz, .next
+
+ ld hl, OBJECT_NEXT_TILE
+ add hl, de
+ ld a, [hl]
+ call CheckPitTile
+ jr nz, .next
+
+ ld hl, OBJECT_DIRECTION_WALKING
+ add hl, de
+ ld a, [hl]
+ cp STANDING
+ jr nz, .next
+ call HandleStoneQueue
+ jr c, .fall_down_hole
+
+.next
+ ld hl, OBJECT_STRUCT_LENGTH
+ add hl, de
+ ld d, h
+ ld e, l
+
+ pop af
+ dec a
+ jr nz, .loop
+ ret
+
+.fall_down_hole
+ pop af
+ ret
diff --git a/engine/overworld/events_2.asm b/engine/overworld/events_2.asm
deleted file mode 100644
index 6e106541a..000000000
--- a/engine/overworld/events_2.asm
+++ /dev/null
@@ -1,650 +0,0 @@
-; More overworld event handling.
-
-
-WarpToSpawnPoint:: ; 97c28
- ld hl, wStatusFlags2
- res STATUSFLAGS2_SAFARI_GAME_F, [hl]
- res STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
- ret
-; 97c30
-
-RunMemScript:: ; 97c30
-; If there is no script here, we don't need to be here.
- ld a, [wMapReentryScriptQueueFlag]
- and a
- ret z
-; Execute the script at (wMapReentryScriptBank):(wMapReentryScriptAddress).
- ld hl, wMapReentryScriptAddress
- ld a, [hli]
- ld h, [hl]
- ld l, a
- ld a, [wMapReentryScriptBank]
- call CallScript
- scf
-; Clear the buffer for the next script.
- push af
- xor a
- ld hl, wMapReentryScriptQueueFlag
- ld bc, 8
- call ByteFill
- pop af
- ret
-; 97c4f
-
-LoadScriptBDE:: ; 97c4f
-; If there's already a script here, don't overwrite.
- ld hl, wMapReentryScriptQueueFlag
- ld a, [hl]
- and a
- ret nz
-; Set the flag
- ld [hl], 1
- inc hl
-; Load the script pointer b:de into (wMapReentryScriptBank):(wMapReentryScriptAddress)
- ld [hl], b
- inc hl
- ld [hl], e
- inc hl
- ld [hl], d
- scf
- ret
-; 97c5f
-
-TryTileCollisionEvent:: ; 97c5f
- call GetFacingTileCoord
- ld [wEngineBuffer1], a
- ld c, a
- farcall CheckFacingTileForStdScript
- jr c, .done
-
- call CheckCutTreeTile
- jr nz, .whirlpool
- farcall TryCutOW
- jr .done
-
-.whirlpool
- ld a, [wEngineBuffer1]
- call CheckWhirlpoolTile
- jr nz, .waterfall
- farcall TryWhirlpoolOW
- jr .done
-
-.waterfall
- ld a, [wEngineBuffer1]
- call CheckWaterfallTile
- jr nz, .headbutt
- farcall TryWaterfallOW
- jr .done
-
-.headbutt
- ld a, [wEngineBuffer1]
- call CheckHeadbuttTreeTile
- jr nz, .surf
- farcall TryHeadbuttOW
- jr c, .done
- jr .noevent
-
-.surf
- farcall TrySurfOW
- jr nc, .noevent
- jr .done
-
-.noevent
- xor a
- ret
-
-.done
- call PlayClickSFX
- ld a, $ff
- scf
- ret
-; 97cc0
-
-
-RandomEncounter:: ; 97cc0
-; Random encounter
-
- call CheckWildEncounterCooldown
- jr c, .nope
- call CanUseSweetScent
- jr nc, .nope
- ld hl, wStatusFlags2
- bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
- jr nz, .bug_contest
- farcall TryWildEncounter
- jr nz, .nope
- jr .ok
-
-.bug_contest
- call _TryWildEncounter_BugContest
- jr nc, .nope
- jr .ok_bug_contest
-
-.nope
- ld a, 1
- and a
- ret
-
-.ok
- ld a, BANK(WildBattleScript)
- ld hl, WildBattleScript
- jr .done
-
-.ok_bug_contest
- ld a, BANK(BugCatchingContestBattleScript)
- ld hl, BugCatchingContestBattleScript
- jr .done
-
-.done
- call CallScript
- scf
- ret
-; 97cf9
-
-WildBattleScript: ; 97cf9
- randomwildmon
- startbattle
- reloadmapafterbattle
- end
-; 97cfd
-
-CanUseSweetScent:: ; 97cfd
- ld hl, wStatusFlags
- bit STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl]
- jr nz, .no
- ld a, [wEnvironment]
- cp CAVE
- jr z, .ice_check
- cp DUNGEON
- jr z, .ice_check
- farcall CheckGrassCollision
- jr nc, .no
-
-.ice_check
- ld a, [wPlayerStandingTile]
- call CheckIceTile
- jr z, .no
- scf
- ret
-
-.no
- and a
- ret
-; 97d23
-
-_TryWildEncounter_BugContest: ; 97d23
- call TryWildEncounter_BugContest
- ret nc
- call ChooseWildEncounter_BugContest
- farcall CheckRepelEffect
- ret
-; 97d31
-
-ChooseWildEncounter_BugContest:: ; 97d31
-; Pick a random mon out of ContestMons.
-
-.loop
- call Random
- cp 100 << 1
- jr nc, .loop
- srl a
-
- ld hl, ContestMons
- ld de, 4
-.CheckMon:
- sub [hl]
- jr c, .GotMon
- add hl, de
- jr .CheckMon
-
-.GotMon:
- inc hl
-
-; Species
- ld a, [hli]
- ld [wTempWildMonSpecies], a
-
-; Min level
- ld a, [hli]
- ld d, a
-
-; Max level
- ld a, [hl]
-
- sub d
- jr nz, .RandomLevel
-
-; If min and max are the same.
- ld a, d
- jr .GotLevel
-
-.RandomLevel:
-; Get a random level between the min and max.
- ld c, a
- inc c
- call Random
- ld a, [hRandomAdd]
- call SimpleDivide
- add d
-
-.GotLevel:
- ld [wCurPartyLevel], a
-
- xor a
- ret
-; 97d64
-
-TryWildEncounter_BugContest: ; 97d64
- ld a, [wPlayerStandingTile]
- call CheckSuperTallGrassTile
- ld b, 40 percent
- jr z, .ok
- ld b, 20 percent
-
-.ok
- farcall ApplyMusicEffectOnEncounterRate
- farcall ApplyCleanseTagEffectOnEncounterRate
- call Random
- ld a, [hRandomAdd]
- cp b
- ret c
- ld a, 1
- and a
- ret
-; 97d87
-
-
-INCLUDE "data/wild/bug_contest_mons.asm"
-
-
-DoBikeStep:: ; 97db3
- nop
- nop
- ; If the bike shop owner doesn't have our number, or
- ; if we've already gotten the call, we don't have to
- ; be here.
- ld hl, wStatusFlags2
- bit STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl]
- jr z, .NoCall
-
- ; If we're not on the bike, we don't have to be here.
- ld a, [wPlayerState]
- cp PLAYER_BIKE
- jr nz, .NoCall
-
- ; If we're not in an area of phone service, we don't
- ; have to be here.
- call GetMapPhoneService
- and a
- jr nz, .NoCall
-
- ; Check the bike step count and check whether we've
- ; taken 65536 of them yet.
- ld hl, wBikeStep
- ld a, [hli]
- ld d, a
- ld e, [hl]
- cp 255
- jr nz, .increment
- ld a, e
- cp 255
- jr z, .dont_increment
-
-.increment
- inc de
- ld [hl], e
- dec hl
- ld [hl], d
-
-.dont_increment
- ; If we've taken at least 1024 steps, have the bike
- ; shop owner try to call us.
- ld a, d
- cp HIGH(1024)
- jr c, .NoCall
-
- ; If a call has already been queued, don't overwrite
- ; that call.
- ld a, [wSpecialPhoneCallID]
- and a
- jr nz, .NoCall
-
- ; Queue the call.
- ld a, SPECIALCALL_BIKESHOP
- ld [wSpecialPhoneCallID], a
- xor a
- ld [wSpecialPhoneCallID + 1], a
- ld hl, wStatusFlags2
- res STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl]
- scf
- ret
-
-.NoCall:
- xor a
- ret
-; 97df9
-
-ClearCmdQueue:: ; 97df9
- ld hl, wCmdQueue
- ld de, 6
- ld c, 4
- xor a
-.loop
- ld [hl], a
- add hl, de
- dec c
- jr nz, .loop
- ret
-; 97e08
-
-HandleCmdQueue:: ; 97e08
- ld hl, wCmdQueue
- xor a
-.loop
- ld [hMapObjectIndexBuffer], a
- ld a, [hl]
- and a
- jr z, .skip
- push hl
- ld b, h
- ld c, l
- call HandleQueuedCommand
- pop hl
-
-.skip
- ld de, CMDQUEUE_ENTRY_SIZE
- add hl, de
- ld a, [hMapObjectIndexBuffer]
- inc a
- cp CMDQUEUE_CAPACITY
- jr nz, .loop
- ret
-; 97e25
-
-Unreferenced_GetNthCmdQueueEntry: ; 97e25
- ld hl, wCmdQueue
- ld bc, CMDQUEUE_ENTRY_SIZE
- call AddNTimes
- ld b, h
- ld c, l
- ret
-; 97e31
-
-WriteCmdQueue:: ; 97e31
- push bc
- push de
- call .GetNextEmptyEntry
- ld d, h
- ld e, l
- pop hl
- pop bc
- ret c
- ld a, b
- ld bc, CMDQUEUE_ENTRY_SIZE - 1
- call FarCopyBytes
- xor a
- ld [hl], a
- ret
-; 97e45
-
-.GetNextEmptyEntry: ; 97e45
- ld hl, wCmdQueue
- ld de, CMDQUEUE_ENTRY_SIZE
- ld c, CMDQUEUE_CAPACITY
-.loop
- ld a, [hl]
- and a
- jr z, .done
- add hl, de
- dec c
- jr nz, .loop
- scf
- ret
-
-.done
- ld a, CMDQUEUE_CAPACITY
- sub c
- and a
- ret
-; 97e5c
-
-DelCmdQueue:: ; 97e5c
- ld hl, wCmdQueue
- ld de, CMDQUEUE_ENTRY_SIZE
- ld c, CMDQUEUE_CAPACITY
-.loop
- ld a, [hl]
- cp b
- jr z, .done
- add hl, de
- dec c
- jr nz, .loop
- and a
- ret
-
-.done
- xor a
- ld [hl], a
- scf
- ret
-; 97e72
-
-_DelCmdQueue: ; 97e72
- ld hl, CMDQUEUE_TYPE
- add hl, bc
- ld [hl], 0
- ret
-; 97e79
-
-HandleQueuedCommand: ; 97e79
- ld hl, CMDQUEUE_TYPE
- add hl, bc
- ld a, [hl]
- cp 5
- jr c, .okay
- xor a
-
-.okay
- ld e, a
- ld d, 0
- ld hl, .Jumptable
- add hl, de
- add hl, de
- add hl, de
- ld a, [hli]
- push af
- ld a, [hli]
- ld h, [hl]
- ld l, a
- pop af
- rst FarCall
- ret
-; 97e94
-
-.Jumptable: ; 97e94
- dba CmdQueue_Null
- dba CmdQueue_Null2
- dba CmdQueue_StoneTable
- dba CmdQueue_Type3
- dba CmdQueue_Type4
-; 97ea3
-
-CmdQueueAnonymousJumptable: ; 97ea3
- ld hl, CMDQUEUE_05
- add hl, bc
- ld a, [hl]
- pop hl
- rst JumpTable
- ret
-; 97eab
-
-CmdQueueAnonJT_Increment: ; 97eab
- ld hl, CMDQUEUE_05
- add hl, bc
- inc [hl]
- ret
-; 97eb1
-
-CmdQueueAnonJT_Decrement: ; 97eb1
- ld hl, CMDQUEUE_05
- add hl, bc
- dec [hl]
- ret
-; 97eb7
-
-CmdQueue_Null: ; 97eb7
- ret
-; 97eb8
-
-CmdQueue_Null2: ; 97eb8
- call ret_2f3e
- ret
-; 97ebc
-
-CmdQueue_Type4: ; 97ebc
- call CmdQueueAnonymousJumptable
- ; anonymous dw
- dw .zero
- dw .one
-; 97ec3
-
-.zero ; 97ec3
- ld a, [hSCY]
- ld hl, 4
- add hl, bc
- ld [hl], a
- call CmdQueueAnonJT_Increment
-.one ; 97ecd
- ld hl, 1
- add hl, bc
- ld a, [hl]
- dec a
- ld [hl], a
- jr z, .finish
- and $1
- jr z, .add
- ld hl, 2
- add hl, bc
- ld a, [hSCY]
- sub [hl]
- ld [hSCY], a
- ret
-
-.add
- ld hl, 2
- add hl, bc
- ld a, [hSCY]
- add [hl]
- ld [hSCY], a
- ret
-
-.finish
- ld hl, 4
- add hl, bc
- ld a, [hl]
- ld [hSCY], a
- call _DelCmdQueue
- ret
-; 97ef9
-
-CmdQueue_Type3: ; 97ef9
- call CmdQueueAnonymousJumptable
- ; anonymous dw
- dw .zero
- dw .one
- dw .two
-; 97f02
-
-.zero ; 97f02
- call .IsPlayerFacingDown
- jr z, .PlayerNotFacingDown
- call CmdQueueAnonJT_Increment
-.one ; 97f0a
- call .IsPlayerFacingDown
- jr z, .PlayerNotFacingDown
- call CmdQueueAnonJT_Increment
-
- ld hl, 2
- add hl, bc
- ld a, [hl]
- ld [wd173], a
- ret
-; 97f1b
-
-.two ; 97f1b
- call .IsPlayerFacingDown
- jr z, .PlayerNotFacingDown
- call CmdQueueAnonJT_Decrement
-
- ld hl, 3
- add hl, bc
- ld a, [hl]
- ld [wd173], a
- ret
-; 97f2c
-
-.PlayerNotFacingDown: ; 97f2c
- ld a, $7f
- ld [wd173], a
- ld hl, 5
- add hl, bc
- ld [hl], 0
- ret
-; 97f38
-
-.IsPlayerFacingDown: ; 97f38
- push bc
- ld bc, wPlayerStruct
- call GetSpriteDirection
- and a
- pop bc
- ret
-; 97f42
-
-CmdQueue_StoneTable: ; 97f42
- ld de, wPlayerStruct
- ld a, NUM_OBJECT_STRUCTS
-.loop
- push af
-
- ld hl, OBJECT_SPRITE
- add hl, de
- ld a, [hl]
- and a
- jr z, .next
-
- ld hl, OBJECT_MOVEMENTTYPE
- add hl, de
- ld a, [hl]
- cp SPRITEMOVEDATA_STRENGTH_BOULDER
- jr nz, .next
-
- ld hl, OBJECT_NEXT_TILE
- add hl, de
- ld a, [hl]
- call CheckPitTile
- jr nz, .next
-
- ld hl, OBJECT_DIRECTION_WALKING
- add hl, de
- ld a, [hl]
- cp STANDING
- jr nz, .next
- call HandleStoneQueue
- jr c, .fall_down_hole
-
-.next
- ld hl, OBJECT_STRUCT_LENGTH
- add hl, de
- ld d, h
- ld e, l
-
- pop af
- dec a
- jr nz, .loop
- ret
-
-.fall_down_hole
- pop af
- ret
-; 97f7e
diff --git a/engine/overworld/init_map.asm b/engine/overworld/init_map.asm
index 2eb4998a6..ba1e74295 100644
--- a/engine/overworld/init_map.asm
+++ b/engine/overworld/init_map.asm
@@ -1,4 +1,4 @@
-ReanchorBGMap_NoOAMUpdate:: ; 6454
+ReanchorBGMap_NoOAMUpdate::
call DelayFrame
ld a, [hOAMUpdate]
push af
@@ -50,13 +50,13 @@ ReanchorBGMap_NoOAMUpdate:: ; 6454
call ApplyBGMapAnchorToObjects
ret
-.LoadBGMapAddrIntoHRAM: ; 64b9
+.LoadBGMapAddrIntoHRAM:
ld [hBGMapAddress + 1], a
xor a
ld [hBGMapAddress], a
ret
-LoadFonts_NoOAMUpdate:: ; 64bf
+LoadFonts_NoOAMUpdate::
ld a, [hOAMUpdate]
push af
ld a, $1
@@ -76,7 +76,7 @@ LoadFonts_NoOAMUpdate:: ; 64bf
call LoadStandardFont
ret
-HDMATransfer_FillBGMap0WithBlack: ; 64db
+HDMATransfer_FillBGMap0WithBlack:
ld a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
diff --git a/engine/overworld/landmarks.asm b/engine/overworld/landmarks.asm
index f16f48e67..9deafb8e6 100644
--- a/engine/overworld/landmarks.asm
+++ b/engine/overworld/landmarks.asm
@@ -1,4 +1,4 @@
-GetLandmarkCoords: ; 0x1ca896
+GetLandmarkCoords:
; Return coordinates (d, e) of landmark e.
push hl
ld l, e
@@ -12,10 +12,8 @@ GetLandmarkCoords: ; 0x1ca896
ld d, [hl]
pop hl
ret
-; 0x1ca8a5
-
-GetLandmarkName:: ; 0x1ca8a5
+GetLandmarkName::
; Copy the name of landmark e to wStringBuffer1.
push hl
push de
@@ -44,13 +42,10 @@ GetLandmarkName:: ; 0x1ca8a5
pop de
pop hl
ret
-; 0x1ca8c3
-
INCLUDE "data/maps/landmarks.asm"
-
-RegionCheck: ; 0x1caea1
+RegionCheck:
; Checks if the player is in Kanto or Johto.
; If in Johto, returns 0 in e.
; If in Kanto, returns 1 in e.
diff --git a/engine/overworld/load_map_part.asm b/engine/overworld/load_map_part.asm
index 9eeef7259..da1436406 100644
--- a/engine/overworld/load_map_part.asm
+++ b/engine/overworld/load_map_part.asm
@@ -1,4 +1,4 @@
-_LoadMapPart:: ; 4d15b
+_LoadMapPart::
ld hl, wSurroundingTiles
ld a, [wMetatileStandingY]
and a
diff --git a/engine/overworld/map_object_action.asm b/engine/overworld/map_object_action.asm
index c82cd80a2..2c4834a3d 100644
--- a/engine/overworld/map_object_action.asm
+++ b/engine/overworld/map_object_action.asm
@@ -1,4 +1,4 @@
-ObjectActionPairPointers: ; 445f
+ObjectActionPairPointers:
; entries correspond to OBJECT_ACTION_* constants
dw SetFacingStanding, SetFacingStanding
dw SetFacingStandAction, SetFacingCurrent
@@ -17,37 +17,33 @@ ObjectActionPairPointers: ; 445f
dw SetFacingBoulderDust, SetFacingStanding
dw SetFacingGrassShake, SetFacingStanding
dw SetFacingSkyfall, SetFacingCurrent
-; 44a3
-SetFacingStanding: ; 44a3
+SetFacingStanding:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], STANDING
ret
-; 44aa
-SetFacingCurrent: ; 44aa
+SetFacingCurrent:
call GetSpriteDirection
or FACING_STEP_DOWN_0 ; useless
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], a
ret
-; 44b5
-SetFacingStandAction: ; 44b5
+SetFacingStandAction:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld a, [hl]
and 1
jr nz, SetFacingStepAction
jp SetFacingCurrent
-; 44c1
-SetFacingStepAction: ; 44c1
+SetFacingStepAction:
ld hl, OBJECT_FLAGS1
add hl, bc
- bit SLIDING, [hl]
+ bit SLIDING_F, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
@@ -59,7 +55,7 @@ SetFacingStepAction: ; 44c1
rrca
rrca
- and %00000011
+ maskbits NUM_DIRECTIONS
ld d, a
call GetSpriteDirection
@@ -69,12 +65,11 @@ SetFacingStepAction: ; 44c1
add hl, bc
ld [hl], a
ret
-; 44e4
-SetFacingSkyfall: ; 44e4
+SetFacingSkyfall:
ld hl, OBJECT_FLAGS1
add hl, bc
- bit SLIDING, [hl]
+ bit SLIDING_F, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
@@ -86,7 +81,7 @@ SetFacingSkyfall: ; 44e4
rrca
rrca
- and %00000011
+ maskbits NUM_DIRECTIONS
ld d, a
call GetSpriteDirection
@@ -96,12 +91,11 @@ SetFacingSkyfall: ; 44e4
add hl, bc
ld [hl], a
ret
-; 4508
-SetFacingBumpAction: ; 4508
+SetFacingBumpAction:
ld hl, OBJECT_FLAGS1
add hl, bc
- bit SLIDING, [hl]
+ bit SLIDING_F, [hl]
jp nz, SetFacingCurrent
ld hl, OBJECT_STEP_FRAME
@@ -112,7 +106,7 @@ SetFacingBumpAction: ; 4508
rrca
rrca
rrca
- and %00000011
+ maskbits NUM_DIRECTIONS
ld d, a
call GetSpriteDirection
@@ -122,9 +116,8 @@ SetFacingBumpAction: ; 4508
add hl, bc
ld [hl], a
ret
-; 4529
-SetFacingCounterclockwiseSpin: ; 4529
+SetFacingCounterclockwiseSpin:
call CounterclockwiseSpinAction
ld hl, OBJECT_FACING
add hl, bc
@@ -134,14 +127,12 @@ SetFacingCounterclockwiseSpin: ; 4529
add hl, bc
ld [hl], a
ret
-; 4539
-SetFacingCounterclockwiseSpin2: ; 4539
+SetFacingCounterclockwiseSpin2:
call CounterclockwiseSpinAction
jp SetFacingStanding
-; 453f
-CounterclockwiseSpinAction: ; 453f
+CounterclockwiseSpinAction:
; Here, OBJECT_STEP_FRAME consists of two 2-bit components,
; using only bits 0,1 and 4,5.
; bits 0,1 is a timer (4 overworld frames)
@@ -179,13 +170,11 @@ CounterclockwiseSpinAction: ; 453f
add hl, bc
ld [hl], a
ret
-; 456a
-.Directions: ; 456a
+.Directions:
db OW_DOWN, OW_RIGHT, OW_UP, OW_LEFT
-; 456e
-SetFacingFish: ; 456e
+SetFacingFish:
call GetSpriteDirection
rrca
rrca
@@ -194,30 +183,26 @@ SetFacingFish: ; 456e
add hl, bc
ld [hl], a
ret
-; 457b
-SetFacingShadow: ; 457b
+SetFacingShadow:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_SHADOW
ret
-; 4582
-SetFacingEmote: ; 4582 emote
+SetFacingEmote:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_EMOTE
ret
-; 4589
-SetFacingBigDollSym: ; 4589
+SetFacingBigDollSym:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_BIG_DOLL_SYM
ret
-; 4590
-SetFacingBounce: ; 4590
+SetFacingBounce:
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
@@ -230,22 +215,20 @@ SetFacingBounce: ; 4590
add hl, bc
ld [hl], FACING_STEP_UP_0
ret
-; 45a4
-SetFacingFreezeBounce: ; 45a4
+SetFacingFreezeBounce:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_STEP_DOWN_0
ret
-; 45ab
-SetFacingWeirdTree: ; 45ab
+SetFacingWeirdTree:
ld hl, OBJECT_STEP_FRAME
add hl, bc
ld a, [hl]
inc a
ld [hl], a
- and %00001100
+ maskbits NUM_DIRECTIONS, 2
rrca
rrca
add FACING_WEIRD_TREE_0
@@ -253,16 +236,14 @@ SetFacingWeirdTree: ; 45ab
add hl, bc
ld [hl], a
ret
-; 45be
-SetFacingBigDollAsym: ; 45be
+SetFacingBigDollAsym:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], FACING_BIG_DOLL_ASYM
ret
-; 45c5
-SetFacingBigDoll: ; 45c5
+SetFacingBigDoll:
ld a, [wVariableSprites + SPRITE_BIG_DOLL - SPRITE_VARS]
ld d, FACING_BIG_DOLL_SYM ; symmetric
cp SPRITE_BIG_SNORLAX
@@ -276,9 +257,8 @@ SetFacingBigDoll: ; 45c5
add hl, bc
ld [hl], d
ret
-; 45da
-SetFacingBoulderDust: ; 45da
+SetFacingBoulderDust:
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
@@ -293,9 +273,8 @@ SetFacingBoulderDust: ; 45da
.ok
ld [hl], a
ret
-; 45ed
-SetFacingGrassShake: ; 45ed
+SetFacingGrassShake:
ld hl, OBJECT_STEP_FRAME
add hl, bc
inc [hl]
@@ -310,4 +289,3 @@ SetFacingGrassShake: ; 45ed
.ok
ld [hl], a
ret
-; 4600
diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm
index 1573a27b5..8c1171981 100644
--- a/engine/overworld/map_objects.asm
+++ b/engine/overworld/map_objects.asm
@@ -2,9 +2,7 @@ INCLUDE "data/sprites/facings.asm"
INCLUDE "data/sprites/map_objects.asm"
-
-; 4357
-DeleteMapObject:: ; 4357
+DeleteMapObject::
push bc
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, bc
@@ -27,9 +25,8 @@ DeleteMapObject:: ; 4357
.ok
pop bc
ret
-; 437b
-Function437b: ; 437b
+Function437b:
call .CheckObjectStillVisible
ret c
call .HandleStepType
@@ -93,7 +90,7 @@ Function437b: ; 437b
.ok2
ld hl, OBJECT_FLAGS1
add hl, bc
- bit 1, [hl]
+ bit WONT_DELETE_F, [hl]
jr nz, .yes2
call DeleteMapObject
scf
@@ -146,7 +143,7 @@ Function437b: ; 437b
.HandleObjectAction:
ld hl, OBJECT_FLAGS1
add hl, bc
- bit INVISIBLE, [hl]
+ bit INVISIBLE_F, [hl]
jr nz, SetFacingStanding
ld hl, OBJECT_FLAGS2
add hl, bc
@@ -156,17 +153,15 @@ Function437b: ; 437b
jr nz, asm_4448
ld de, ObjectActionPairPointers ; use first column
jr _HandleObjectAction
-; 4440
-Function4440: ; 4440
+Function4440:
ld hl, OBJECT_FLAGS1
add hl, bc
- bit INVISIBLE, [hl]
+ bit INVISIBLE_F, [hl]
jr nz, SetFacingStanding
asm_4448:
ld de, ObjectActionPairPointers + 2 ; use second column
jr _HandleObjectAction
-; 444d
_HandleObjectAction:
; call [4 * wObjectStructs[ObjInd, OBJECT_ACTION] + de]
@@ -183,11 +178,10 @@ _HandleObjectAction:
ld l, a
call _hl_
ret
-; 445f
INCLUDE "engine/overworld/map_object_action.asm"
-CopyNextCoordsTileToStandingCoordsTile: ; 4600
+CopyNextCoordsTileToStandingCoordsTile:
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
@@ -212,9 +206,8 @@ CopyNextCoordsTileToStandingCoordsTile: ; 4600
ld a, [hl]
call UselessAndA
ret
-; 462a
-Function462a: ; 462a
+Function462a:
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
@@ -228,12 +221,11 @@ Function462a: ; 462a
add hl, bc
ld [hl], a
ret
-; 463f
-UpdateTallGrassFlags: ; 463f
+UpdateTallGrassFlags:
ld hl, OBJECT_FLAGS2
add hl, bc
- bit OVERHEAD, [hl]
+ bit OVERHEAD_F, [hl]
jr z, .ok
ld hl, OBJECT_NEXT_TILE
add hl, bc
@@ -250,9 +242,8 @@ UpdateTallGrassFlags: ; 463f
ld a, [hl]
call UselessAndA
ret
-; 4661
-SetTallGrassFlags: ; 4661
+SetTallGrassFlags:
call CheckSuperTallGrassTile
jr z, .set
call CheckGrassTile
@@ -260,22 +251,20 @@ SetTallGrassFlags: ; 4661
.set
ld hl, OBJECT_FLAGS2
add hl, bc
- set OVERHEAD, [hl]
+ set OVERHEAD_F, [hl]
ret
.reset
ld hl, OBJECT_FLAGS2
add hl, bc
- res OVERHEAD, [hl]
+ res OVERHEAD_F, [hl]
ret
-; 4679
-UselessAndA: ; 4679
+UselessAndA:
and a
ret
-; 467b
-EndSpriteMovement: ; 467b
+EndSpriteMovement:
xor a
ld hl, OBJECT_STEP_FRAME
add hl, bc
@@ -290,15 +279,14 @@ EndSpriteMovement: ; 467b
add hl, bc
ld [hl], STANDING
ret
-; 4690
-InitStep: ; 4690
+InitStep:
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], a
ld hl, OBJECT_FLAGS1
add hl, bc
- bit FIXED_FACING, [hl]
+ bit FIXED_FACING_F, [hl]
jr nz, GetNextTile
add a
add a
@@ -306,7 +294,7 @@ InitStep: ; 4690
ld hl, OBJECT_FACING
add hl, bc
ld [hl], a
-GetNextTile: ; 46a6
+GetNextTile:
call GetStepVector
ld hl, OBJECT_STEP_DURATION
add hl, bc
@@ -336,9 +324,8 @@ GetNextTile: ; 46a6
add hl, bc
ld [hl], a
ret
-; 46d7
-AddStepVector: ; 46d7
+AddStepVector:
call GetStepVector
ld hl, OBJECT_SPRITE_X
add hl, bc
@@ -351,9 +338,8 @@ AddStepVector: ; 46d7
add e
ld [hl], a
ret
-; 46e9
-GetStepVector: ; 46e9
+GetStepVector:
; Return (x, y, duration, speed) in (d, e, a, h).
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
@@ -372,9 +358,8 @@ GetStepVector: ; 46e9
ld a, [hli]
ld h, [hl]
ret
-; 4700
-StepVectors: ; 4700
+StepVectors:
; x, y, duration, speed
; slow
db 0, 1, 16, 1
@@ -391,18 +376,16 @@ StepVectors: ; 4700
db 0, -4, 4, 4
db -4, 0, 4, 4
db 4, 0, 4, 4
-; 4730
-GetStepVectorSign: ; 4730
+GetStepVectorSign:
add a
ret z ; 0 or 128
ld a, 1
ret nc ; 1 - 127
ld a, -1
ret ; 129 - 255
-; 4738
-UpdatePlayerStep: ; 4738
+UpdatePlayerStep:
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
@@ -418,9 +401,8 @@ UpdatePlayerStep: ; 4738
ld hl, wPlayerStepFlags
set 5, [hl]
ret
-; 4759
-Unreferenced_Function4759: ; 4759
+Unreferenced_Function4759:
push bc
ld e, a
ld d, 0
@@ -432,9 +414,8 @@ Unreferenced_Function4759: ; 4759
ld a, [hl]
pop bc
ret
-; 4769
-RestoreDefaultMovement: ; 4769
+RestoreDefaultMovement:
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, bc
ld a, [hl]
@@ -451,76 +432,66 @@ RestoreDefaultMovement: ; 4769
.ok
ld a, SPRITEMOVEFN_STANDING
ret
-; 4780
-ClearObjectMovementByteIndex: ; 4780
+ClearObjectMovementByteIndex:
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld [hl], 0
ret
-; 4787
-IncrementObjectMovementByteIndex: ; 4787
+IncrementObjectMovementByteIndex:
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
inc [hl]
ret
-; 478d
-DecrementObjectMovementByteIndex: ; 478d
+DecrementObjectMovementByteIndex:
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
dec [hl]
ret
-; 4793
-MovementAnonymousJumptable: ; 4793
+MovementAnonymousJumptable:
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld a, [hl]
pop hl
rst JumpTable
ret
-; 479b
-ClearObjectStructField1c: ; 479b
+ClearObjectStructField1c:
ld hl, OBJECT_1C
add hl, bc
ld [hl], 0
ret
-; 47a2
-IncrementObjectStructField1c: ; 47a2
+IncrementObjectStructField1c:
ld hl, OBJECT_1C
add hl, bc
inc [hl]
ret
-; 47a8
-Field1cAnonymousJumptable: ; 47a8
+Field1cAnonymousJumptable:
ld hl, OBJECT_1C
add hl, bc
ld a, [hl]
pop hl
rst JumpTable
ret
-; 47b0
-GetValueObjectStructField1c: ; 47b0
+GetValueObjectStructField1c:
ld hl, OBJECT_1C
add hl, bc
ld a, [hl]
ret
-; 47b6
-SetValueObjectStructField1c: ; 47b6
+SetValueObjectStructField1c:
ld hl, OBJECT_1C
add hl, bc
ld [hl], a
ret
-; 47bc
-ObjectMovementReset: ; 47bc
+ObjectMovementReset:
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
@@ -539,9 +510,8 @@ ObjectMovementReset: ; 47bc
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 47dd
-MapObjectMovementPattern: ; 47dd
+MapObjectMovementPattern:
call ClearObjectStructField1c
call GetSpriteMovementFunction
ld a, [hl]
@@ -549,7 +519,7 @@ MapObjectMovementPattern: ; 47dd
rst JumpTable
ret
-.Pointers: ; 47e9
+.Pointers:
; entries correspond to SPRITEMOVEFN_* constants
dw .Null_00 ; 00
dw .RandomWalkY ; 01
@@ -696,7 +666,7 @@ MapObjectMovementPattern: ; 47dd
and %00000011
or 0
call InitStep
- call Function6ec1
+ call CanObjectMoveInDirection
jr c, .ok2
ld de, SFX_STRENGTH
call PlaySFX
@@ -848,7 +818,7 @@ MapObjectMovementPattern: ; 47dd
call .MovementSpinNextFacing
jr .MovementSpinCounterclockwise
-.DirectionData_Counterclockwise: ; 49c0
+.DirectionData_Counterclockwise:
db OW_RIGHT, OW_LEFT, OW_DOWN, OW_UP
.MovementSpinTurnRight:
@@ -856,7 +826,7 @@ MapObjectMovementPattern: ; 47dd
call .MovementSpinNextFacing
jr .MovementSpinClockwise
-.DirectionData_Clockwise: ; 49cc
+.DirectionData_Clockwise:
db OW_LEFT, OW_RIGHT, OW_UP, OW_DOWN
.MovementSpinNextFacing:
@@ -969,7 +939,7 @@ MapObjectMovementPattern: ; 47dd
ld [hl], STEP_TYPE_TRACKING_OBJECT
ret
-.data_4a81 ; 4a81
+.data_4a81
; x, y
db 0, -4
db 0, 8
@@ -1049,7 +1019,7 @@ MapObjectMovementPattern: ; 47dd
.RandomWalkContinue:
call InitStep
- call Function6ec1 ; check whether the object can move in that direction
+ call CanObjectMoveInDirection ; check whether the object can move in that direction
jr c, .NewDuration
call UpdateTallGrassFlags
ld hl, OBJECT_ACTION
@@ -1073,18 +1043,17 @@ MapObjectMovementPattern: ; 47dd
.NewDuration:
call EndSpriteMovement
call Function462a
-RandomStepDuration_Slow: ; 4b1d
+RandomStepDuration_Slow:
call Random
ld a, [hRandomAdd]
and %01111111
jr SetRandomStepDuration
-; 4b26
-RandomStepDuration_Fast: ; 4b26
+RandomStepDuration_Fast:
call Random
ld a, [hRandomAdd]
and %00011111
-SetRandomStepDuration: ; 4b2d
+SetRandomStepDuration:
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
@@ -1098,9 +1067,8 @@ SetRandomStepDuration: ; 4b2d
add hl, bc
ld [hl], STEP_TYPE_03
ret
-; 4b45
-StepTypesJumptable: ; 4b45
+StepTypesJumptable:
; entries correspond to STEP_TYPE_* constants
dw ObjectMovementReset ; 00
dw MapObjectMovementPattern ; 01
@@ -1128,9 +1096,8 @@ StepTypesJumptable: ; 4b45
dw StepType17 ; 17
dw StepType18 ; 18
dw SkyfallTop ; 19
-; 4b79
-WaitStep_InPlace: ; 4b79
+WaitStep_InPlace:
ld hl, OBJECT_STEP_DURATION
add hl, bc
dec [hl]
@@ -1139,9 +1106,8 @@ WaitStep_InPlace: ; 4b79
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4b86
-NPCJump: ; 4b86
+NPCJump:
call Field1cAnonymousJumptable
; anonymous dw
dw .Jump
@@ -1174,9 +1140,8 @@ NPCJump: ; 4b86
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4bbf
-PlayerJump: ; 4bbf
+PlayerJump:
call Field1cAnonymousJumptable
; anonymous dw
dw .initjump
@@ -1224,16 +1189,14 @@ PlayerJump: ; 4bbf
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4c18
-TeleportFrom: ; 4c18
+TeleportFrom:
call Field1cAnonymousJumptable
; anonymous dw
dw .InitSpin
dw .DoSpin
dw .InitSpinRise
dw .DoSpinRise
-; 4c23
.InitSpin:
ld hl, OBJECT_STEP_FRAME
@@ -1294,9 +1257,8 @@ TeleportFrom: ; 4c18
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4c89
-TeleportTo: ; 4c89
+TeleportTo:
call Field1cAnonymousJumptable
; anonymous dw
dw .InitWait
@@ -1306,7 +1268,6 @@ TeleportTo: ; 4c89
dw .InitFinalSpin
dw .DoFinalSpin
dw .FinishStep
-; 4c9a
.InitWait:
ld hl, OBJECT_ACTION
@@ -1317,7 +1278,6 @@ TeleportTo: ; 4c89
ld [hl], 16
call IncrementObjectStructField1c
ret
-; 4caa
.DoWait:
ld hl, OBJECT_STEP_DURATION
@@ -1337,7 +1297,6 @@ TeleportTo: ; 4c89
ld [hl], 16
call IncrementObjectStructField1c
ret
-; 4cc9
.DoDescent:
ld hl, OBJECT_ACTION
@@ -1365,7 +1324,6 @@ TeleportTo: ; 4c89
ld [hl], 16
call IncrementObjectStructField1c
ret
-; 4cf5
.DoFinalSpin:
ld hl, OBJECT_ACTION
@@ -1386,16 +1344,14 @@ TeleportTo: ; 4c89
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4d14
-Skyfall: ; 4d14
+Skyfall:
call Field1cAnonymousJumptable
; anonymous dw
dw .Init
dw .Step
dw .Fall
dw .Finish
-; 4d1f
.Init:
ld hl, OBJECT_ACTION
@@ -1451,14 +1407,12 @@ Skyfall: ; 4d14
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4d7e
-GotBiteStep: ; 4d7e
+GotBiteStep:
call Field1cAnonymousJumptable
; anonymous dw
dw .Init
dw .Run
-; 4d85
.Init:
ld hl, OBJECT_STEP_DURATION
@@ -1485,12 +1439,10 @@ GotBiteStep: ; 4d7e
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4daf
-RockSmashStep: ; 4daf
+RockSmashStep:
call .Step
jp WaitStep_InPlace
-; 4db5
.Step:
ld hl, OBJECT_STEP_DURATION
@@ -1505,9 +1457,8 @@ RockSmashStep: ; 4daf
add hl, bc
ld [hl], a
ret
-; 4dc8
-ReturnDigStep: ; 4dc8
+ReturnDigStep:
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld a, [hl]
@@ -1520,9 +1471,8 @@ ReturnDigStep: ; 4dc8
add hl, bc
ld [hl], a
jp WaitStep_InPlace
-; 4ddd
-StepType03: ; 4ddd
+StepType03:
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
@@ -1534,9 +1484,8 @@ StepType03: ; 4ddd
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4df0
-StepType18: ; 4df0
+StepType18:
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
@@ -1545,9 +1494,8 @@ StepType18: ; 4df0
dec [hl]
ret nz
jp DeleteMapObject
-; 4dff
-StepTypeBump: ; 4dff
+StepTypeBump:
ld hl, OBJECT_STEP_DURATION
add hl, bc
dec [hl]
@@ -1556,9 +1504,8 @@ StepTypeBump: ; 4dff
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4e0c
-StepType05: ; 4e0c
+StepType05:
call Field1cAnonymousJumptable
; anonymous dw
dw .Reset
@@ -1571,15 +1518,14 @@ StepType05: ; 4e0c
add hl, bc
ld [hl], a
call IncrementObjectStructField1c
-StepType04: ; 4e21
+StepType04:
call Stubbed_Function4fb2
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld [hl], STANDING
ret
-; 4e2b
-NPCStep: ; 4e2b
+NPCStep:
call Stubbed_Function4fb2
call AddStepVector
ld hl, OBJECT_STEP_DURATION
@@ -1594,9 +1540,8 @@ NPCStep: ; 4e2b
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4e47
-StepType07: ; 4e47
+StepType07:
call AddStepVector
ld hl, OBJECT_STEP_DURATION
add hl, bc
@@ -1604,9 +1549,8 @@ StepType07: ; 4e47
ret nz
call CopyNextCoordsTileToStandingCoordsTile
jp RandomStepDuration_Slow
-; 4e56
-PlayerStep: ; 4e56
+PlayerStep:
; AnimateStep?
call Field1cAnonymousJumptable
; anonymous dw
@@ -1633,9 +1577,8 @@ PlayerStep: ; 4e56
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4e83
-PlayerOrNPCTurnStep: ; 4e83
+PlayerOrNPCTurnStep:
call Field1cAnonymousJumptable
; anonymous dw
dw .init1
@@ -1681,9 +1624,8 @@ PlayerOrNPCTurnStep: ; 4e83
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4ecd
-StepType0f: ; 4ecd
+StepType0f:
call AddStepVector
ld hl, OBJECT_STEP_DURATION
add hl, bc
@@ -1713,9 +1655,8 @@ StepType0f: ; 4ecd
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4f04
-StepTypeTrackingObject: ; 4f04
+StepTypeTrackingObject:
ld hl, OBJECT_1D
add hl, bc
ld e, [hl]
@@ -1747,10 +1688,9 @@ StepTypeTrackingObject: ; 4f04
ret nz
.nope
jp DeleteMapObject
-; 4f33
-StepType14: ; 4f33
-StepType15: ; 4f33
+StepType14:
+StepType15:
call Field1cAnonymousJumptable
; anonymous dw
dw .Init
@@ -1797,21 +1737,18 @@ StepType15: ; 4f33
cpl
inc a
ret
-; 4f77
-StepType16: ; 4f77
+StepType16:
call Field1cAnonymousJumptable ; ????
-; 4f7a
-StepType17: ; 4f7a
+StepType17:
call Field1cAnonymousJumptable
; anonymous dw
dw .null
dw .null
dw .null
.null
-; 4f83
-SkyfallTop: ; 4f83
+SkyfallTop:
call Field1cAnonymousJumptable
; anonymous dw
dw .Init
@@ -1841,7 +1778,6 @@ SkyfallTop: ; 4f83
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 4fb2
Stubbed_Function4fb2:
ret
@@ -1862,10 +1798,9 @@ Stubbed_Function4fb2:
ld [hl], a
ret
-.y ; 4fcd
+.y
db 0, -1, -2, -3, -4, -3, -2, -1
-; 4fd5
-UpdateJumpPosition: ; 4fd5
+UpdateJumpPosition:
call GetStepVector
ld a, h
ld hl, OBJECT_1F
@@ -1884,10 +1819,9 @@ UpdateJumpPosition: ; 4fd5
ld [hl], a
ret
-.y ; 4ff0
+.y
db -4, -6, -8, -10, -11, -12, -12, -12
db -11, -10, -9, -8, -6, -4, 0, 0
-; 5000
Function5000: ; unscripted?
; copy [wPlayerNextMovement] to [wPlayerMovement]
ld a, [wPlayerNextMovement]
@@ -1899,15 +1833,13 @@ Function5000: ; unscripted?
; recover the previous value of [wPlayerNextMovement]
ld a, [hl]
ret
-; 500e
GetMovementByte:
ld hl, wMovementDataPointer
call _GetMovementByte
ret
-; 5015
-Function5015: ; 5015
+Function5015:
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld e, [hl]
@@ -1920,9 +1852,8 @@ Function5015: ; 5015
add hl, de
ld a, [hl]
ret
-; 5026
-Function5026: ; 5026
+Function5026:
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld e, [hl]
@@ -1935,19 +1866,16 @@ Function5026: ; 5026
add hl, de
ld a, [hl]
ret
-; 5037
-_GetMovementObject: ; 5037
+_GetMovementObject:
ld hl, GetMovementObject
jp HandleMovementData
-; 503d
-GetMovementObject: ; 503d
+GetMovementObject:
ld a, [wMovementObject]
ret
-; 5041
-HandleMovementData: ; 5041
+HandleMovementData:
call .StorePointer
.loop
xor a
@@ -1965,35 +1893,30 @@ HandleMovementData: ; 5041
ld a, h
ld [wMovementPointer + 1], a
ret
-; 505e
-JumpMovementPointer: ; 505e
+JumpMovementPointer:
ld hl, wMovementPointer
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
-; 5065
-ContinueReadingMovement: ; 5065
+ContinueReadingMovement:
ld a, 1
ld [wMovementByteWasControlSwitch], a
ret
-; 506b
-DoMovementFunction: ; 506b
+DoMovementFunction:
push af
call ApplyMovementToFollower
pop af
ld hl, MovementPointers
rst JumpTable
ret
-; 5075
INCLUDE "engine/overworld/movement.asm"
-; 54b8
-ApplyMovementToFollower: ; 54b8
+ApplyMovementToFollower:
ld e, a
ld a, [wObjectFollow_Follower]
cp -1
@@ -2024,9 +1947,8 @@ ApplyMovementToFollower: ; 54b8
pop af
ld [hl], a
ret
-; 54e6
-GetFollowerNextMovementByte: ; 54e6
+GetFollowerNextMovementByte:
ld hl, wFollowerMovementQueueLength
ld a, [hl]
and a
@@ -2075,9 +1997,8 @@ GetFollowerNextMovementByte: ; 54e6
ld a, movement_step_end
scf
ret
-; 5529
-SpawnShadow: ; 5529
+SpawnShadow:
push bc
ld de, .ShadowObject
call CopyTempObjectData
@@ -2088,9 +2009,8 @@ SpawnShadow: ; 5529
.ShadowObject:
; vtile, palette, movement
db $00, PAL_OW_SILVER, SPRITEMOVEDATA_SHADOW
-; 5538
-SpawnStrengthBoulderDust: ; 5538
+SpawnStrengthBoulderDust:
push bc
ld de, .BoulderDustObject
call CopyTempObjectData
@@ -2100,9 +2020,8 @@ SpawnStrengthBoulderDust: ; 5538
.BoulderDustObject:
db $00, PAL_OW_SILVER, SPRITEMOVEDATA_BOULDERDUST
-; 5547
-SpawnEmote: ; 5547
+SpawnEmote:
push bc
ld de, .EmoteObject
call CopyTempObjectData
@@ -2112,21 +2031,19 @@ SpawnEmote: ; 5547
.EmoteObject:
db $00, PAL_OW_SILVER, SPRITEMOVEDATA_EMOTE
-; 5556
-ShakeGrass: ; 5556
+ShakeGrass:
push bc
- ld de, .data_5562
+ ld de, .GrassObject
call CopyTempObjectData
call InitTempObject
pop bc
ret
-.data_5562
+.GrassObject
db $00, PAL_OW_TREE, SPRITEMOVEDATA_GRASS
-; 5565
-ShakeScreen: ; 5565
+ShakeScreen:
push bc
push af
ld de, .ScreenShakeObject
@@ -2139,8 +2056,8 @@ ShakeScreen: ; 5565
.ScreenShakeObject:
db $00, PAL_OW_SILVER, SPRITEMOVEDATA_SCREENSHAKE
-; 5579
-DespawnEmote: ; 5579
+
+DespawnEmote:
push bc
ld a, [hMapObjectIndexBuffer]
ld c, a
@@ -2155,7 +2072,7 @@ DespawnEmote: ; 5579
push af
ld hl, OBJECT_FLAGS1
add hl, de
- bit EMOTE_OBJECT, [hl]
+ bit EMOTE_OBJECT_F, [hl]
jr z, .next
ld hl, OBJECT_SPRITE
add hl, de
@@ -2176,18 +2093,16 @@ DespawnEmote: ; 5579
dec a
jr nz, .loop
ret
-; 55ac
-InitTempObject: ; 55ac
+InitTempObject:
call FindFirstEmptyObjectStruct
ret nc
ld d, h
ld e, l
farcall CopyTempObjectToObjectStruct
ret
-; 55b9
-CopyTempObjectData: ; 55b9
+CopyTempObjectData:
; load into wTempObjectCopy:
; -1, -1, [de], [de + 1], [de + 2], [hMapObjectIndexBuffer], [NextMapX], [NextMapY], -1
; This spawns the object at the same place as whichever object is loaded into bc.
@@ -2220,9 +2135,8 @@ CopyTempObjectData: ; 55b9
inc hl
ld [hl], -1
ret
-; 55e0
-Function55e0:: ; 55e0
+Function55e0::
ld a, [wVramState]
bit 0, a
ret z
@@ -2243,9 +2157,9 @@ Function55e0:: ; 55e0
cp NUM_OBJECT_STRUCTS
jr nz, .loop
ret
-; 5602
-Function5602: ; 5602, called at battle start
+Function5602:
+; called at battle start
call Function5645 ; clear sprites
ld a, PLAYER
call Function5629 ; respawn player
@@ -2259,17 +2173,15 @@ Function5602: ; 5602, called at battle start
.ok
call _UpdateSprites
ret
-; 561d
-Function561d: ; 561d
+Function561d:
call Function5645 ; clear sprites
ld a, PLAYER
call Function5629 ; respawn player
call _UpdateSprites
ret
-; 5629
-Function5629: ; 5629
+Function5629:
cp NUM_OBJECTS
ret nc
call GetMapObject
@@ -2285,9 +2197,8 @@ Function5629: ; 5629
ret z
call Function5673
ret
-; 5645
-Function5645: ; 5645
+Function5645:
xor a
ld bc, wObjectStructs
.loop
@@ -2302,9 +2213,8 @@ Function5645: ; 5645
cp NUM_OBJECT_STRUCTS
jr nz, .loop
ret
-; 565c
-Function565c: ; 565c
+Function565c:
push bc
call Function56cd
pop bc
@@ -2315,25 +2225,22 @@ Function565c: ; 565c
farcall Function4440
xor a
ret
-; 5673
-Function5673: ; 5673
+Function5673:
call Function56a3
jr c, SetFacing_Standing
farcall Function4440 ; no need to farcall
xor a
ret
-; 5680
-SetFacing_Standing: ; 5680
+SetFacing_Standing:
ld hl, OBJECT_FACING_STEP
add hl, bc
ld [hl], STANDING
scf
ret
-; 5688
-Function5688: ; 5688
+Function5688:
push bc
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
@@ -2348,9 +2255,8 @@ Function5688: ; 5688
ld [hl], a
farcall UpdateTallGrassFlags ; no need to farcall
ret
-; 56a3
-Function56a3: ; 56a3
+Function56a3:
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
@@ -2381,9 +2287,8 @@ Function56a3: ; 56a3
.nope
scf
ret
-; 56cd
-Function56cd: ; 56cd
+Function56cd:
ld a, [wPlayerBGMapOffsetX]
ld d, a
ld hl, OBJECT_SPRITE_X_OFFSET
@@ -2444,7 +2349,7 @@ Function56cd: ; 56cd
ld [hUsedSpriteTile], a
ld hl, OBJECT_PALETTE
add hl, bc
- bit 7, [hl]
+ bit BIG_OBJECT_F, [hl]
jr z, .ok7
ld a, d
add 2
@@ -2491,9 +2396,8 @@ Function56cd: ; 56cd
.nope
scf
ret
-; 576a
-HandleNPCStep:: ; 576a
+HandleNPCStep::
call .ResetStepVector
call .DoStepsForAllObjects
ret
@@ -2525,9 +2429,8 @@ HandleNPCStep:: ; 576a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
ret
-; 579d
-RefreshPlayerSprite: ; 579d
+RefreshPlayerSprite:
ld a, movement_step_sleep
ld [wPlayerNextMovement], a
ld [wPlayerMovement], a
@@ -2539,9 +2442,8 @@ RefreshPlayerSprite: ; 579d
call c, SpawnInFacingDown
call .SpawnInCustomFacing
ret
-; 57bc
-.TryResetPlayerAction: ; 57bc
+.TryResetPlayerAction:
ld hl, wPlayerSpriteSetupFlags
bit PLAYERSPRITESETUP_RESET_ACTION_F, [hl]
jr nz, .ok
@@ -2551,9 +2453,8 @@ RefreshPlayerSprite: ; 579d
ld a, OBJECT_ACTION_00
ld [wPlayerAction], a
ret
-; 57ca
-.SpawnInCustomFacing: ; 57ca
+.SpawnInCustomFacing:
ld hl, wPlayerSpriteSetupFlags
bit PLAYERSPRITESETUP_CUSTOM_FACING_F, [hl]
ret z
@@ -2562,19 +2463,17 @@ RefreshPlayerSprite: ; 579d
add a
add a
jr ContinueSpawnFacing
-; 57d9
-SpawnInFacingDown: ; 57d9
+SpawnInFacingDown:
ld a, 0
-ContinueSpawnFacing: ; 57db
+ContinueSpawnFacing:
ld bc, wPlayerStruct
call SetSpriteDirection
ret
-; 57e2
-_SetPlayerPalette: ; 57e2
+_SetPlayerPalette:
ld a, d
- and %10000000
+ and 1 << 7
ret z
ld bc, 0 ; debug?
ld hl, OBJECT_FACING
@@ -2584,19 +2483,18 @@ _SetPlayerPalette: ; 57e2
ld [hl], a
ld a, d
swap a
- and %00000111
+ and PALETTE_MASK
ld d, a
ld bc, wPlayerStruct
ld hl, OBJECT_PALETTE
add hl, bc
ld a, [hl]
- and %11111000
+ and $ff ^ PALETTE_MASK
or d
ld [hl], a
ret
-; 5803
-StartFollow:: ; 5803
+StartFollow::
push bc
ld a, b
call SetLeaderIfVisible
@@ -2606,29 +2504,25 @@ StartFollow:: ; 5803
call SetFollowerIfVisible
farcall QueueFollowerFirstStep
ret
-; 5815
-SetLeaderIfVisible: ; 5815
+SetLeaderIfVisible:
call CheckObjectVisibility
ret c
ld a, [hObjectStructIndexBuffer]
ld [wObjectFollow_Leader], a
ret
-; 581f
-StopFollow:: ; 581f
+StopFollow::
call ResetLeader
call ResetFollower
ret
-; 5826
-ResetLeader: ; 5826
+ResetLeader:
ld a, -1
ld [wObjectFollow_Leader], a
ret
-; 582c
-SetFollowerIfVisible: ; 582c
+SetFollowerIfVisible:
push af
call ResetFollower
pop af
@@ -2643,9 +2537,8 @@ SetFollowerIfVisible: ; 582c
ld a, [hObjectStructIndexBuffer]
ld [wObjectFollow_Follower], a
ret
-; 5847
-ResetFollower: ; 5847
+ResetFollower:
ld a, [wObjectFollow_Follower]
cp -1
ret z
@@ -2654,9 +2547,8 @@ ResetFollower: ; 5847
ld a, -1
ld [wObjectFollow_Follower], a
ret
-; 585c
-SetFlagsForMovement_1:: ; 585c
+SetFlagsForMovement_1::
ld a, c
call CheckObjectVisibility
ret c
@@ -2668,9 +2560,8 @@ SetFlagsForMovement_1:: ; 585c
res 5, [hl]
xor a
ret
-; 586e
-Function586e: ; 586e
+Function586e:
call CheckObjectVisibility
ret c
ld hl, OBJECT_FLAGS2
@@ -2678,9 +2569,8 @@ Function586e: ; 586e
set 5, [hl]
xor a
ret
-; 587a
-Function587a: ; 587a
+Function587a:
ld bc, wObjectStructs
xor a
.loop
@@ -2700,9 +2590,8 @@ Function587a: ; 587a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
ret
-; 5897
-_SetFlagsForMovement_2:: ; 5897
+_SetFlagsForMovement_2::
ld a, [wObjectFollow_Leader]
cp -1
ret z
@@ -2722,9 +2611,8 @@ _SetFlagsForMovement_2:: ; 5897
add hl, bc
res 5, [hl]
ret
-; 58b9
-Function58b9:: ; 58b9
+Function58b9::
push bc
ld bc, wObjectStructs
xor a
@@ -2746,18 +2634,16 @@ Function58b9:: ; 58b9
jr nz, .loop
pop bc
ret
-; 58d8
-Function58d8: ; 58d8
+Function58d8:
call CheckObjectVisibility
ret c
ld hl, OBJECT_FLAGS2
add hl, bc
res 5, [hl]
ret
-; 58e3
-Function58e3: ; 58e3
+Function58e3:
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, bc
ld a, [hl]
@@ -2776,9 +2662,8 @@ Function58e3: ; 58e3
add hl, bc
ld [hl], STEP_TYPE_00
ret
-; 5903
-Function5903: ; 5903
+Function5903:
call GetSpriteDirection
rrca
rrca
@@ -2800,9 +2685,8 @@ Function5903: ; 5903
db SPRITEMOVEDATA_STANDING_UP
db SPRITEMOVEDATA_STANDING_LEFT
db SPRITEMOVEDATA_STANDING_RIGHT
-; 5920
-_UpdateSprites:: ; 5920
+_UpdateSprites::
ld a, [wVramState]
bit 0, a
ret z
@@ -2839,9 +2723,8 @@ _UpdateSprites:: ; 5920
cp l
jr nz, .loop
ret
-; 5958
-ApplyBGMapAnchorToObjects: ; 5958
+ApplyBGMapAnchorToObjects:
push hl
push de
push bc
@@ -2880,14 +2763,12 @@ ApplyBGMapAnchorToObjects: ; 5958
pop de
pop hl
ret
-; 5991
-
PRIORITY_LOW EQU $10
PRIORITY_NORM EQU $20
PRIORITY_HIGH EQU $30
-InitSprites: ; 5991
+InitSprites:
call .DeterminePriorities
ld c, PRIORITY_HIGH
call .InitSpritesByPriority
@@ -2918,10 +2799,10 @@ InitSprites: ; 5991
ld e, PRIORITY_LOW
ld hl, OBJECT_FLAGS2
add hl, bc
- bit LOW_PRIORITY, [hl]
+ bit LOW_PRIORITY_F, [hl]
jr nz, .add
ld e, PRIORITY_NORM
- bit HIGH_PRIORITY, [hl]
+ bit HIGH_PRIORITY_F, [hl]
jr z, .add
ld e, PRIORITY_HIGH
jr .add
@@ -2973,35 +2854,35 @@ InitSprites: ; 5991
ld hl, OBJECT_SPRITE_TILE
add hl, bc
ld a, [hl]
- and %01111111
+ and $ff ^ (1 << 7)
ld [hFFC1], a
xor a
bit 7, [hl]
jr nz, .skip1
- or %00001000
+ or VRAM_BANK_1
.skip1
ld hl, OBJECT_FLAGS2
add hl, bc
ld e, [hl]
bit 7, e
jr z, .skip2
- or %10000000
+ or PRIORITY
.skip2
- bit 4, e
+ bit USE_OBP1_F, e
jr z, .skip3
- or %00010000
+ or OBP_NUM
.skip3
ld hl, OBJECT_PALETTE
add hl, bc
ld d, a
ld a, [hl]
- and %00000111
+ and PALETTE_MASK
or d
ld d, a
xor a
- bit 3, e
+ bit OVERHEAD_F, e
jr z, .skip4
- or %10000000
+ or PRIORITY
.skip4
ld [hFFC2], a
ld hl, OBJECT_SPRITE_X
@@ -3063,7 +2944,7 @@ InitSprites: ; 5991
ld e, [hl]
inc hl
ld a, [hFFC1]
- bit 2, e
+ bit ABSOLUTE_TILE_ID_F, e
jr z, .nope1
xor a
.nope1
@@ -3072,7 +2953,7 @@ InitSprites: ; 5991
ld [bc], a ; tile id
inc c
ld a, e
- bit 1, a
+ bit RELATIVE_ATTRIBUTES_F, a
jr z, .nope2
ld a, [hFFC2]
or e
@@ -3106,7 +2987,7 @@ InitSprites: ; 5991
ld b, [hl]
ret
-.Addresses: ; 5ace
+.Addresses:
dw wPlayerStruct
dw wObject1Struct
dw wObject2Struct
@@ -3120,4 +3001,3 @@ InitSprites: ; 5991
dw wObject10Struct
dw wObject11Struct
dw wObject12Struct
-; 5ae8
diff --git a/engine/overworld/map_objects_2.asm b/engine/overworld/map_objects_2.asm
index 038e2b49b..f055e0fd9 100644
--- a/engine/overworld/map_objects_2.asm
+++ b/engine/overworld/map_objects_2.asm
@@ -1,4 +1,4 @@
-LoadObjectMasks: ; 2454f
+LoadObjectMasks:
ld hl, wObjectMasks
xor a
ld bc, NUM_OBJECTS
@@ -29,7 +29,7 @@ LoadObjectMasks: ; 2454f
jr nz, .loop
ret
-CheckObjectFlag: ; 2457d (9:457d)
+CheckObjectFlag:
ld hl, MAPOBJECT_SPRITE
add hl, bc
ld a, [hl]
@@ -62,7 +62,7 @@ CheckObjectFlag: ; 2457d (9:457d)
scf
ret
-GetObjectTimeMask: ; 245a7 (9:45a7)
+GetObjectTimeMask:
call CheckObjectTime
ld a, -1
ret c
diff --git a/engine/overworld/map_setup.asm b/engine/overworld/map_setup.asm
index 268574de0..b09404240 100644
--- a/engine/overworld/map_setup.asm
+++ b/engine/overworld/map_setup.asm
@@ -1,4 +1,4 @@
-RunMapSetupScript:: ; 15363
+RunMapSetupScript::
ld a, [hMapEntryMethod]
and $f
dec a
@@ -12,11 +12,10 @@ RunMapSetupScript:: ; 15363
ld l, a
call ReadMapSetupScript
ret
-; 15377
INCLUDE "data/maps/setup_scripts.asm"
-ReadMapSetupScript: ; 1541d
+ReadMapSetupScript:
.loop
ld a, [hli]
cp -1
@@ -58,9 +57,8 @@ ReadMapSetupScript: ; 1541d
pop hl
jr .loop
-; 15440
-MapSetupCommands: ; 15440
+MapSetupCommands:
; entries correspond to command indexes in constants/map_setup_constants.asm
dba EnableLCD ; 00
dba DisableLCD ; 01
@@ -108,51 +106,43 @@ MapSetupCommands: ; 15440
dba RetainOldPalettes ; 2b
dba DontScrollText ; 2c
dba ReturnFromMapSetupScript ; 2d
-; 154ca
-
-DontScrollText: ; 154ca
+DontScrollText:
xor a
ld [wDisableTextAcceleration], a
ret
-; 154cf
-ActivateMapAnims: ; 154cf
+ActivateMapAnims:
ld a, $1
ld [hMapAnims], a
ret
-; 154d3
-SuspendMapAnims: ; 154d3
+SuspendMapAnims:
xor a
ld [hMapAnims], a
ret
-; 154d7
-LoadObjectsRunCallback_02: ; 154d7
+LoadObjectsRunCallback_02:
ld a, MAPCALLBACK_OBJECTS
call RunMapCallback
farcall LoadObjectMasks
farcall InitializeVisibleSprites
ret
-; 154ea (5:54ea)
; unused
ret
-; 154eb
-DelayClearingOldSprites: ; 154eb
+DelayClearingOldSprites:
ld hl, wPlayerSpriteSetupFlags
set PLAYERSPRITESETUP_RESET_ACTION_F, [hl]
ret
-; 154f1
-DelayLoadingNewSprites: ; 154f1
+DelayLoadingNewSprites:
ld hl, wPlayerSpriteSetupFlags
set PLAYERSPRITESETUP_SKIP_RELOAD_GFX_F, [hl]
ret
-CheckReplaceKrisSprite: ; 154f7
+CheckReplaceKrisSprite:
nop
call .CheckBiking
jr c, .ok
@@ -166,7 +156,7 @@ CheckReplaceKrisSprite: ; 154f7
call ReplaceKrisSprite
ret
-.CheckBiking: ; 1550c (5:550c)
+.CheckBiking:
and a
ld hl, wBikeFlags
bit BIKEFLAGS_ALWAYS_ON_BIKE_F, [hl]
@@ -176,7 +166,7 @@ CheckReplaceKrisSprite: ; 154f7
scf
ret
-.CheckSurfing2: ; 1551a (5:551a)
+.CheckSurfing2:
ld a, [wPlayerState]
cp PLAYER_NORMAL
jr z, .nope
@@ -208,7 +198,7 @@ CheckReplaceKrisSprite: ; 154f7
and a
ret
-.CheckSurfing: ; 1554e (5:554e)
+.CheckSurfing:
call CheckOnWater
jr nz, .ret_nc
ld a, [wPlayerState]
@@ -224,19 +214,17 @@ CheckReplaceKrisSprite: ; 154f7
.ret_nc
and a
ret
-; 15567
-FadeOldMapMusic: ; 15567
+FadeOldMapMusic:
ld a, 6
call SkipMusic
ret
-; 1556d
-RetainOldPalettes: ; 1556d
+RetainOldPalettes:
farcall _UpdateTimePals
ret
-RotatePalettesRightMapAndMusic: ; 15574
+RotatePalettesRightMapAndMusic:
ld e, 0
ld a, [wMusicFadeID]
ld d, 0
@@ -245,9 +233,8 @@ RotatePalettesRightMapAndMusic: ; 15574
ld [wMusicFade], a
call RotateThreePalettesRight
ret
-; 15587
-ForceMapMusic: ; 15587
+ForceMapMusic:
ld a, [wPlayerState]
cp PLAYER_BIKE
jr nz, .notbiking
@@ -257,4 +244,3 @@ ForceMapMusic: ; 15587
.notbiking
call TryRestartMapMusic
ret
-; 1559a
diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm
index 3dbb0b83a..f7054c680 100644
--- a/engine/overworld/movement.asm
+++ b/engine/overworld/movement.asm
@@ -1,4 +1,4 @@
-MovementPointers: ; 5075
+MovementPointers:
; entries correspond to macros/scripts/movement.asm enumeration
dw Movement_turn_head_down ; 00
dw Movement_turn_head_up ; 01
@@ -90,38 +90,32 @@ MovementPointers: ; 5075
dw Movement_rock_smash ; 57
dw Movement_return_dig ; 58
dw Movement_skyfall_top ; 59
-; 5129
-
-Movement_teleport_from: ; 5129
+Movement_teleport_from:
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TELEPORT_FROM
ret
-; 5130
-Movement_teleport_to: ; 5130
+Movement_teleport_to:
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_TELEPORT_TO
ret
-; 5137
-Movement_skyfall: ; 5137
+Movement_skyfall:
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_SKYFALL
ret
-; 513e
-Movement_skyfall_top: ; 513e
+Movement_skyfall_top:
ld hl, OBJECT_STEP_TYPE
add hl, bc
ld [hl], STEP_TYPE_SKYFALL_TOP
ret
-; 5145
-Movement_step_dig: ; 5145
+Movement_step_dig:
call GetSpriteDirection
rlca
rlca
@@ -142,9 +136,8 @@ Movement_step_dig: ; 5145
add hl, bc
ld [hl], STANDING
ret
-; 516a
-Movement_return_dig: ; 516a
+Movement_return_dig:
call GetSpriteDirection
rlca
rlca
@@ -162,9 +155,8 @@ Movement_return_dig: ; 516a
add hl, bc
ld [hl], STEP_TYPE_RETURN_DIG
ret
-; 5189
-Movement_fish_got_bite: ; 5189
+Movement_fish_got_bite:
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_FISHING
@@ -172,9 +164,8 @@ Movement_fish_got_bite: ; 5189
add hl, bc
ld [hl], STEP_TYPE_GOT_BITE
ret
-; 5196
-Movement_rock_smash: ; 5196
+Movement_rock_smash:
call JumpMovementPointer
ld hl, OBJECT_STEP_DURATION
add hl, bc
@@ -186,9 +177,8 @@ Movement_rock_smash: ; 5196
add hl, bc
ld [hl], STEP_TYPE_ROCK_SMASH
ret
-; 51ab
-Movement_fish_cast_rod: ; 51ab
+Movement_fish_cast_rod:
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_FISHING
@@ -196,16 +186,14 @@ Movement_fish_cast_rod: ; 51ab
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 51b8
-Movement_step_loop: ; 51b8
+Movement_step_loop:
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
add hl, bc
ld [hl], $0
jp ContinueReadingMovement
-; 51c1
-Movement_step_end: ; 51c1
+Movement_step_end:
call RestoreDefaultMovement
ld hl, OBJECT_MOVEMENTTYPE
add hl, bc
@@ -222,9 +210,8 @@ Movement_step_end: ; 51c1
add hl, bc
ld [hl], STEP_TYPE_SLEEP
ret
-; 51db
-Movement_48: ; 51db
+Movement_48:
call RestoreDefaultMovement
ld hl, OBJECT_MOVEMENTTYPE
add hl, bc
@@ -246,9 +233,8 @@ Movement_48: ; 51db
ld hl, wVramState
res 7, [hl]
ret
-; 51fd
-Movement_remove_object: ; 51fd
+Movement_remove_object:
call DeleteMapObject
ld hl, wObjectFollow_Leader
ld a, [hMapObjectIndexBuffer]
@@ -260,9 +246,8 @@ Movement_remove_object: ; 51fd
ld hl, wVramState
res 7, [hl]
ret
-; 5210
-Movement_4b: ; 5210
+Movement_4b:
ld hl, OBJECT_ACTION
add hl, bc
ld [hl], OBJECT_ACTION_STAND
@@ -274,48 +259,47 @@ Movement_4b: ; 5210
ld hl, wVramState
res 7, [hl]
ret
-; 5222
-Movement_step_sleep_1: ; 5222
+Movement_step_sleep_1:
ld a, 1
jr Movement_step_sleep_common
-Movement_step_sleep_2: ; 5226
+Movement_step_sleep_2:
ld a, 2
jr Movement_step_sleep_common
-Movement_step_sleep_3: ; 522a
+Movement_step_sleep_3:
ld a, 3
jr Movement_step_sleep_common
-Movement_step_sleep_4: ; 522e
+Movement_step_sleep_4:
ld a, 4
jr Movement_step_sleep_common
-Movement_step_sleep_5: ; 5232
+Movement_step_sleep_5:
ld a, 5
jr Movement_step_sleep_common
-Movement_step_sleep_6: ; 5236
+Movement_step_sleep_6:
ld a, 6
jr Movement_step_sleep_common
-Movement_step_sleep_7: ; 523a
+Movement_step_sleep_7:
ld a, 7
jr Movement_step_sleep_common
-Movement_step_sleep_8: ; 523e
+Movement_step_sleep_8:
ld a, 8
jr Movement_step_sleep_common
-Movement_step_sleep: ; 5242
+Movement_step_sleep:
; parameters:
; duration (DecimalParam)
call JumpMovementPointer
jr Movement_step_sleep_common
-Movement_step_sleep_common: ; 5247
+Movement_step_sleep_common:
ld hl, OBJECT_STEP_DURATION
add hl, bc
ld [hl], a
@@ -332,9 +316,8 @@ Movement_step_sleep_common: ; 5247
add hl, bc
ld [hl], STANDING
ret
-; 525f
-Movement_step_bump: ; 525f
+Movement_step_bump:
ld a, 1
ld hl, OBJECT_STEP_DURATION
add hl, bc
@@ -352,9 +335,8 @@ Movement_step_bump: ; 525f
add hl, bc
ld [hl], STANDING
ret
-; 5279
-Movement_tree_shake: ; 5279
+Movement_tree_shake:
ld a, 24
ld hl, OBJECT_STEP_DURATION
add hl, bc
@@ -372,86 +354,76 @@ Movement_tree_shake: ; 5279
add hl, bc
ld [hl], STANDING
ret
-; 5293
-Movement_remove_sliding: ; 5293
+Movement_remove_sliding:
ld hl, OBJECT_FLAGS1
add hl, bc
- res SLIDING, [hl]
+ res SLIDING_F, [hl]
jp ContinueReadingMovement
-; 529c
-Movement_set_sliding: ; 529c
+Movement_set_sliding:
ld hl, OBJECT_FLAGS1
add hl, bc
- set SLIDING, [hl]
+ set SLIDING_F, [hl]
jp ContinueReadingMovement
-; 52a5
-Movement_remove_fixed_facing: ; 52a5
+Movement_remove_fixed_facing:
ld hl, OBJECT_FLAGS1
add hl, bc
- res FIXED_FACING, [hl]
+ res FIXED_FACING_F, [hl]
jp ContinueReadingMovement
-; 52ae
-Movement_fix_facing: ; 52ae
+Movement_fix_facing:
ld hl, OBJECT_FLAGS1
add hl, bc
- set FIXED_FACING, [hl]
+ set FIXED_FACING_F, [hl]
jp ContinueReadingMovement
-; 52b7
-Movement_show_object: ; 52b7
+Movement_show_object:
ld hl, OBJECT_FLAGS1
add hl, bc
- res INVISIBLE, [hl]
+ res INVISIBLE_F, [hl]
jp ContinueReadingMovement
-; 52c0
-Movement_hide_object: ; 52c0
+Movement_hide_object:
ld hl, OBJECT_FLAGS1
add hl, bc
- set INVISIBLE, [hl]
+ set INVISIBLE_F, [hl]
jp ContinueReadingMovement
-; 52c9
-Movement_hide_emote: ; 52c9
+Movement_hide_emote:
call DespawnEmote
jp ContinueReadingMovement
-; 52cf
-Movement_show_emote: ; 52cf
+Movement_show_emote:
call SpawnEmote
jp ContinueReadingMovement
-; 52d5
-Movement_step_shake: ; 52d5
+Movement_step_shake:
; parameters:
; displacement (DecimalParam)
call JumpMovementPointer
call ShakeScreen
jp ContinueReadingMovement
-; 52de
-Movement_turn_head_down: ; 52de
+Movement_turn_head_down:
ld a, OW_DOWN
jr TurnHead
-Movement_turn_head_up: ; 52e2
+Movement_turn_head_up:
ld a, OW_UP
jr TurnHead
-Movement_turn_head_left: ; 52e6
+Movement_turn_head_left:
ld a, OW_LEFT
jr TurnHead
-Movement_turn_head_right: ; 52ea
+Movement_turn_head_right:
ld a, OW_RIGHT
jr TurnHead
-TurnHead: ; 52ee
+TurnHead:
ld hl, OBJECT_FACING
add hl, bc
ld [hl], a
@@ -464,269 +436,216 @@ TurnHead: ; 52ee
add hl, bc
ld [hl], STANDING
ret
-; 5300
-Movement_slow_step_down: ; 5300
+Movement_slow_step_down:
ld a, STEP_SLOW << 2 | DOWN
jp NormalStep
-; 5305
-Movement_slow_step_up: ; 5305
+Movement_slow_step_up:
ld a, STEP_SLOW << 2 | UP
jp NormalStep
-; 530a
-Movement_slow_step_left: ; 530a
+Movement_slow_step_left:
ld a, STEP_SLOW << 2 | LEFT
jp NormalStep
-; 530f
-Movement_slow_step_right: ; 530f
+Movement_slow_step_right:
ld a, STEP_SLOW << 2 | RIGHT
jp NormalStep
-; 5314
-Movement_step_down: ; 5314
+Movement_step_down:
ld a, STEP_WALK << 2 | DOWN
jp NormalStep
-; 5319
-Movement_step_up: ; 5319
+Movement_step_up:
ld a, STEP_WALK << 2 | UP
jp NormalStep
-; 531e
-Movement_step_left: ; 531e
+Movement_step_left:
ld a, STEP_WALK << 2 | LEFT
jp NormalStep
-; 5323
-Movement_step_right: ; 5323
+Movement_step_right:
ld a, STEP_WALK << 2 | RIGHT
jp NormalStep
-; 5328
-Movement_big_step_down: ; 5328
+Movement_big_step_down:
ld a, STEP_BIKE << 2 | DOWN
jp NormalStep
-; 532d
-Movement_big_step_up: ; 532d
+Movement_big_step_up:
ld a, STEP_BIKE << 2 | UP
jp NormalStep
-; 5332
-Movement_big_step_left: ; 5332
+Movement_big_step_left:
ld a, STEP_BIKE << 2 | LEFT
jp NormalStep
-; 5337
-Movement_big_step_right: ; 5337
+Movement_big_step_right:
ld a, STEP_BIKE << 2 | RIGHT
jp NormalStep
-; 533c
-
-Movement_turn_away_down: ; 533c
+Movement_turn_away_down:
ld a, STEP_SLOW << 2 | DOWN
jp TurningStep
-; 5341
-Movement_turn_away_up: ; 5341
+Movement_turn_away_up:
ld a, STEP_SLOW << 2 | UP
jp TurningStep
-; 5346
-Movement_turn_away_left: ; 5346
+Movement_turn_away_left:
ld a, STEP_SLOW << 2 | LEFT
jp TurningStep
-; 534b
-Movement_turn_away_right: ; 534b
+Movement_turn_away_right:
ld a, STEP_SLOW << 2 | RIGHT
jp TurningStep
-; 5350
-Movement_turn_in_down: ; 5350
+Movement_turn_in_down:
ld a, STEP_WALK << 2 | DOWN
jp TurningStep
-; 5355
-Movement_turn_in_up: ; 5355
+Movement_turn_in_up:
ld a, STEP_WALK << 2 | UP
jp TurningStep
-; 535a
-Movement_turn_in_left: ; 535a
+Movement_turn_in_left:
ld a, STEP_WALK << 2 | LEFT
jp TurningStep
-; 535f
-Movement_turn_in_right: ; 535f
+Movement_turn_in_right:
ld a, STEP_WALK << 2 | RIGHT
jp TurningStep
-; 5364
-Movement_turn_waterfall_down: ; 5364
+Movement_turn_waterfall_down:
ld a, STEP_BIKE << 2 | DOWN
jp TurningStep
-; 5369
-Movement_turn_waterfall_up: ; 5369
+Movement_turn_waterfall_up:
ld a, STEP_BIKE << 2 | UP
jp TurningStep
-; 536e
-Movement_turn_waterfall_left: ; 536e
+Movement_turn_waterfall_left:
ld a, STEP_BIKE << 2 | LEFT
jp TurningStep
-; 5373
-Movement_turn_waterfall_right: ; 5373
+Movement_turn_waterfall_right:
ld a, STEP_BIKE << 2 | RIGHT
jp TurningStep
-; 5378
-
-Movement_slow_slide_step_down: ; 5378
+Movement_slow_slide_step_down:
ld a, STEP_SLOW << 2 | DOWN
jp SlideStep
-; 537d
-Movement_slow_slide_step_up: ; 537d
+Movement_slow_slide_step_up:
ld a, STEP_SLOW << 2 | UP
jp SlideStep
-; 5382
-Movement_slow_slide_step_left: ; 5382
+Movement_slow_slide_step_left:
ld a, STEP_SLOW << 2 | LEFT
jp SlideStep
-; 5387
-Movement_slow_slide_step_right: ; 5387
+Movement_slow_slide_step_right:
ld a, STEP_SLOW << 2 | RIGHT
jp SlideStep
-; 538c
-Movement_slide_step_down: ; 538c
+Movement_slide_step_down:
ld a, STEP_WALK << 2 | DOWN
jp SlideStep
-; 5391
-Movement_slide_step_up: ; 5391
+Movement_slide_step_up:
ld a, STEP_WALK << 2 | UP
jp SlideStep
-; 5396
-Movement_slide_step_left: ; 5396
+Movement_slide_step_left:
ld a, STEP_WALK << 2 | LEFT
jp SlideStep
-; 539b
-Movement_slide_step_right: ; 539b
+Movement_slide_step_right:
ld a, STEP_WALK << 2 | RIGHT
jp SlideStep
-; 53a0
-Movement_fast_slide_step_down: ; 53a0
+Movement_fast_slide_step_down:
ld a, STEP_BIKE << 2 | DOWN
jp SlideStep
-; 53a5
-Movement_fast_slide_step_up: ; 53a5
+Movement_fast_slide_step_up:
ld a, STEP_BIKE << 2 | UP
jp SlideStep
-; 53aa
-Movement_fast_slide_step_left: ; 53aa
+Movement_fast_slide_step_left:
ld a, STEP_BIKE << 2 | LEFT
jp SlideStep
-; 53af
-Movement_fast_slide_step_right: ; 53af
+Movement_fast_slide_step_right:
ld a, STEP_BIKE << 2 | RIGHT
jp SlideStep
-; 53b4
-
-Movement_slow_jump_step_down: ; 53b4
+Movement_slow_jump_step_down:
ld a, STEP_SLOW << 2 | DOWN
jp JumpStep
-; 53b9
-Movement_slow_jump_step_up: ; 53b9
+Movement_slow_jump_step_up:
ld a, STEP_SLOW << 2 | UP
jp JumpStep
-; 53be
-Movement_slow_jump_step_left: ; 53be
+Movement_slow_jump_step_left:
ld a, STEP_SLOW << 2 | LEFT
jp JumpStep
-; 53c3
-Movement_slow_jump_step_right: ; 53c3
+Movement_slow_jump_step_right:
ld a, STEP_SLOW << 2 | RIGHT
jp JumpStep
-; 53c8
-Movement_jump_step_down: ; 53c8
+Movement_jump_step_down:
ld a, STEP_WALK << 2 | DOWN
jp JumpStep
-; 53cd
-Movement_jump_step_up: ; 53cd
+Movement_jump_step_up:
ld a, STEP_WALK << 2 | UP
jp JumpStep
-; 53d2
-Movement_jump_step_left: ; 53d2
+Movement_jump_step_left:
ld a, STEP_WALK << 2 | LEFT
jp JumpStep
-; 53d7
-Movement_jump_step_right: ; 53d7
+Movement_jump_step_right:
ld a, STEP_WALK << 2 | RIGHT
jp JumpStep
-; 53dc
-Movement_fast_jump_step_down: ; 53dc
+Movement_fast_jump_step_down:
ld a, STEP_BIKE << 2 | DOWN
jp JumpStep
-; 53e1
-Movement_fast_jump_step_up: ; 53e1
+Movement_fast_jump_step_up:
ld a, STEP_BIKE << 2 | UP
jp JumpStep
-; 53e6
-Movement_fast_jump_step_left: ; 53e6
+Movement_fast_jump_step_left:
ld a, STEP_BIKE << 2 | LEFT
jp JumpStep
-; 53eb
-Movement_fast_jump_step_right: ; 53eb
+Movement_fast_jump_step_right:
ld a, STEP_BIKE << 2 | RIGHT
jp JumpStep
-; 53f0
-
-Movement_turn_step_down: ; 53f0
+Movement_turn_step_down:
ld a, OW_DOWN
jr TurnStep
-Movement_turn_step_up: ; 53f4
+Movement_turn_step_up:
ld a, OW_UP
jr TurnStep
-Movement_turn_step_left: ; 53f8
+Movement_turn_step_left:
ld a, OW_LEFT
jr TurnStep
-Movement_turn_step_right: ; 53fc
+Movement_turn_step_right:
ld a, OW_RIGHT
jr TurnStep
-TurnStep: ; 5400
+TurnStep:
ld hl, OBJECT_1D ; new facing
add hl, bc
ld [hl], a
@@ -739,9 +658,8 @@ TurnStep: ; 5400
add hl, bc
ld [hl], STEP_TYPE_HALF_STEP
ret
-; 5412
-NormalStep: ; 5412
+NormalStep:
call InitStep
call UpdateTallGrassFlags
ld hl, OBJECT_ACTION
@@ -776,9 +694,8 @@ NormalStep: ; 5412
add hl, bc
ld [hl], STEP_TYPE_PLAYER_WALK
ret
-; 5446
-TurningStep: ; 5446
+TurningStep:
call InitStep
call UpdateTallGrassFlags
@@ -801,10 +718,8 @@ TurningStep: ; 5446
add hl, bc
ld [hl], STEP_TYPE_PLAYER_WALK
ret
-; 5468
-
-SlideStep: ; 5468
+SlideStep:
call InitStep
call UpdateTallGrassFlags
@@ -827,10 +742,8 @@ SlideStep: ; 5468
add hl, bc
ld [hl], STEP_TYPE_PLAYER_WALK
ret
-; 548a
-
-JumpStep: ; 548a
+JumpStep:
call InitStep
ld hl, OBJECT_1F
add hl, bc
@@ -838,7 +751,7 @@ JumpStep: ; 548a
ld hl, OBJECT_FLAGS2
add hl, bc
- res OVERHEAD, [hl]
+ res OVERHEAD_F, [hl]
ld hl, OBJECT_ACTION
add hl, bc
@@ -861,4 +774,3 @@ JumpStep: ; 548a
add hl, bc
ld [hl], STEP_TYPE_PLAYER_JUMP
ret
-; 54b8
diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm
index 5670935e8..b4b5ef467 100644
--- a/engine/overworld/npc_movement.asm
+++ b/engine/overworld/npc_movement.asm
@@ -1,37 +1,37 @@
-Function6ec1: ; 6ec1
-
+CanObjectMoveInDirection:
ld hl, OBJECT_PALETTE
add hl, bc
- bit 5, [hl]
- jr z, .not_bit_5
+ bit SWIMMING_F, [hl]
+ jr z, .not_swimming
ld hl, OBJECT_FLAGS1
add hl, bc
- bit 4, [hl] ; lost, uncomment next line to fix
-; jr nz, .resume
+ bit NOCLIP_TILES_F, [hl] ; lost, uncomment next line to fix
+ ; jr nz, .noclip_tiles
push hl
push bc
- call Function6f2c
+ call WillObjectBumpIntoLand
pop bc
pop hl
ret c
- jr .resume
+ jr .continue
-.not_bit_5
+.not_swimming
ld hl, OBJECT_FLAGS1
add hl, bc
- bit 4, [hl]
- jr nz, .resume
+ bit NOCLIP_TILES_F, [hl]
+ jr nz, .noclip_tiles
push hl
push bc
- call Function6f07
+ call WillObjectBumpIntoWater
pop bc
pop hl
ret c
-.resume
- bit 6, [hl]
- jr nz, .bit_6
+.noclip_tiles
+.continue
+ bit NOCLIP_OBJS_F, [hl]
+ jr nz, .noclip_objs
push hl
push bc
@@ -40,9 +40,9 @@ Function6ec1: ; 6ec1
pop hl
ret c
-.bit_6
- bit 5, [hl]
- jr nz, .bit_5
+.noclip_objs
+ bit MOVE_ANYWHERE_F, [hl]
+ jr nz, .move_anywhere
push hl
call HasObjectReachedMovementLimit
pop hl
@@ -53,13 +53,11 @@ Function6ec1: ; 6ec1
pop hl
ret c
-.bit_5
+.move_anywhere
and a
ret
-; 6f07
-
-Function6f07: ; 6f07
+WillObjectBumpIntoWater:
call Function6f5f
ret c
ld hl, OBJECT_NEXT_MAP_X
@@ -78,12 +76,11 @@ Function6f07: ; 6f07
ld d, a
call GetTileCollision
and a ; LANDTILE
- jr z, Function6f3e
+ jr z, WillObjectBumpIntoTile
scf
ret
-; 6f2c
-Function6f2c: ; 6f2c
+WillObjectBumpIntoLand:
call Function6f5f
ret c
ld hl, OBJECT_NEXT_TILE
@@ -91,12 +88,11 @@ Function6f2c: ; 6f2c
ld a, [hl]
call GetTileCollision
cp WATERTILE
- jr z, Function6f3e
+ jr z, WillObjectBumpIntoTile
scf
ret
-; 6f3e
-Function6f3e: ; 6f3e
+WillObjectBumpIntoTile:
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
@@ -116,13 +112,11 @@ Function6f3e: ; 6f3e
ret z
scf
ret
-; 6f5b
.data_6f5b
db DOWN_MASK, UP_MASK, RIGHT_MASK, LEFT_MASK
-; 6f5f
-Function6f5f: ; 6f5f
+Function6f5f:
ld hl, OBJECT_STANDING_TILE
add hl, bc
ld a, [hl]
@@ -141,18 +135,16 @@ Function6f5f: ; 6f5f
ret z
scf
ret
-; 6f7b
.data_6f7b
db UP_MASK, DOWN_MASK, LEFT_MASK, RIGHT_MASK
-; 6f7f
-Function6f7f: ; 6f7f
+Function6f7f:
ld d, a
and $f0
- cp $b0
+ cp HI_NYBBLE_SIDE_WALLS
jr z, .done
- cp $c0
+ cp HI_NYBBLE_UNUSED_C0
jr z, .done
xor a
ret
@@ -167,14 +159,12 @@ Function6f7f: ; 6f7f
ld a, [hl]
scf
ret
-; 6f99
.data_6f99
db 8, 4, 1, 2
db 10, 6, 9, 5
-; 6fa1
-Function6fa1: ; 6fa1
+Function6fa1:
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
@@ -223,12 +213,8 @@ Function6fa1: ; 6fa1
.not_land
scf
ret
-; 6fd9
-
-
-
-CheckFacingObject:: ; 6fd9
+CheckFacingObject::
call GetFacingTileCoord
; Double the distance for counter tiles.
@@ -266,10 +252,8 @@ CheckFacingObject:: ; 6fd9
.standing
scf
ret
-; 7009
-
-WillObjectBumpIntoSomeoneElse: ; 7009
+WillObjectBumpIntoSomeoneElse:
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
@@ -277,7 +261,6 @@ WillObjectBumpIntoSomeoneElse: ; 7009
add hl, bc
ld e, [hl]
jr IsNPCAtCoord
-; 7015
Unreferenced_Function7015:
ld a, [hMapObjectIndexBuffer]
@@ -286,7 +269,7 @@ Unreferenced_Function7015:
call IsNPCAtCoord
ret
-.CheckWillBeFacingNPC: ; 7021
+.CheckWillBeFacingNPC:
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
@@ -314,9 +297,8 @@ Unreferenced_Function7015:
.left
dec d
ret
-; 7041
-IsNPCAtCoord: ; 7041
+IsNPCAtCoord:
ld bc, wObjectStructs
xor a
.loop
@@ -331,7 +313,7 @@ IsNPCAtCoord: ; 7041
ld hl, OBJECT_PALETTE
add hl, bc
- bit 7, [hl]
+ bit BIG_OBJECT_F, [hl]
jr z, .got
call Function7171
@@ -389,9 +371,8 @@ IsNPCAtCoord: ; 7041
.setcarry
scf
ret
-; 70a4
-HasObjectReachedMovementLimit: ; 70a4
+HasObjectReachedMovementLimit:
ld hl, OBJECT_RADIUS
add hl, bc
ld a, [hl]
@@ -449,9 +430,8 @@ HasObjectReachedMovementLimit: ; 70a4
.yes
scf
ret
-; 70ed
-IsObjectMovingOffEdgeOfScreen: ; 70ed
+IsObjectMovingOffEdgeOfScreen:
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [wXCoord]
@@ -480,7 +460,6 @@ IsObjectMovingOffEdgeOfScreen: ; 70ed
.yes
scf
ret
-; 7113
Unreferenced_Function7113:
ld a, [wPlayerStandingMapX]
@@ -546,10 +525,8 @@ Unreferenced_Function7113:
.yes
scf
ret
-; 7171
-
-Function7171: ; 7171
+Function7171:
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, d
@@ -570,4 +547,3 @@ Function7171: ; 7171
.nope
and a
ret
-; 718d
diff --git a/engine/overworld/overworld.asm b/engine/overworld/overworld.asm
index 381c2d89f..f3dcb5b96 100644
--- a/engine/overworld/overworld.asm
+++ b/engine/overworld/overworld.asm
@@ -1,13 +1,12 @@
-GetEmote2bpp: ; 1412a
+GetEmote2bpp:
ld a, $1
ld [rVBK], a
call Get2bpp
xor a
ld [rVBK], a
ret
-; 14135
-_ReplaceKrisSprite:: ; 14135
+_ReplaceKrisSprite::
call GetPlayerSprite
ld a, [wUsedSprites]
ld [hUsedSpriteIndex], a
@@ -15,7 +14,6 @@ _ReplaceKrisSprite:: ; 14135
ld [hUsedSpriteTile], a
call GetUsedSprite
ret
-; 14146
Function14146: ; mobile
ld hl, wSpriteFlags
@@ -27,7 +25,6 @@ Function14146: ; mobile
pop af
ld [wSpriteFlags], a
ret
-; 14157
Function14157: ; mobile
ld hl, wSpriteFlags
@@ -39,15 +36,13 @@ Function14157: ; mobile
pop af
ld [wSpriteFlags], a
ret
-; 14168
-RefreshSprites:: ; 14168
+RefreshSprites::
call .Refresh
call LoadUsedSpritesGFX
ret
-; 1416f
-.Refresh: ; 1416f
+.Refresh:
xor a
ld bc, wUsedSpritesEnd - wUsedSprites
ld hl, wUsedSprites
@@ -56,9 +51,8 @@ RefreshSprites:: ; 14168
call AddMapSprites
call LoadAndSortSprites
ret
-; 14183
-GetPlayerSprite: ; 14183
+GetPlayerSprite:
; Get Chris or Kris's sprite.
ld hl, ChrisStateSprites
ld a, [wPlayerSpriteSetupFlags]
@@ -97,8 +91,7 @@ GetPlayerSprite: ; 14183
INCLUDE "data/sprites/player_sprites.asm"
-
-AddMapSprites: ; 141c9
+AddMapSprites:
call GetMapEnvironment
call CheckOutdoorMap
jr z, .outdoor
@@ -108,10 +101,8 @@ AddMapSprites: ; 141c9
.outdoor
call AddOutdoorSprites
ret
-; 141d9
-
-AddIndoorSprites: ; 141d9
+AddIndoorSprites:
ld hl, wMap1ObjectSprite
ld a, 1
.loop
@@ -125,10 +116,8 @@ AddIndoorSprites: ; 141d9
cp NUM_OBJECTS
jr nz, .loop
ret
-; 141ee
-
-AddOutdoorSprites: ; 141ee
+AddOutdoorSprites:
ld a, [wMapGroup]
dec a
ld c, a
@@ -148,18 +137,15 @@ AddOutdoorSprites: ; 141ee
dec c
jr nz, .loop
ret
-; 14209
-
-LoadUsedSpritesGFX: ; 14209
+LoadUsedSpritesGFX:
ld a, MAPCALLBACK_SPRITES
call RunMapCallback
call GetUsedSprites
call .LoadMiscTiles
ret
-; 14215
-.LoadMiscTiles: ; 14215
+.LoadMiscTiles:
ld a, [wSpriteFlags]
bit 6, a
ret nz
@@ -174,18 +160,14 @@ LoadUsedSpritesGFX: ; 14209
.outdoor
farcall LoadEmote
ret
-; 14236
-
-
-SafeGetSprite: ; 14236
+SafeGetSprite:
push hl
call GetSprite
pop hl
ret
-; 1423c
-GetSprite: ; 1423c
+GetSprite:
call GetMonSprite
ret c
@@ -211,10 +193,8 @@ GetSprite: ; 1423c
ld l, [hl]
ld h, a
ret
-; 14259
-
-GetMonSprite: ; 14259
+GetMonSprite:
; Return carry if a monster sprite was loaded.
cp SPRITE_POKEMON
@@ -275,10 +255,8 @@ GetMonSprite: ; 14259
ld h, 0
and a
ret
-; 142a7
-
-_DoesSpriteHaveFacings:: ; 142a7
+_DoesSpriteHaveFacings::
; Checks to see whether we can apply a facing to a sprite.
; Returns carry unless the sprite is a Pokemon or a Still Sprite.
cp SPRITE_POKEMON
@@ -303,10 +281,8 @@ _DoesSpriteHaveFacings:: ; 142a7
.only_down
and a
ret
-; 142c4
-
-_GetSpritePalette:: ; 142c4
+_GetSpritePalette::
ld a, c
call GetMonSprite
jr c, .is_pokemon
@@ -324,18 +300,14 @@ _GetSpritePalette:: ; 142c4
xor a
ld c, a
ret
-; 142db
-
-LoadAndSortSprites: ; 142db
+LoadAndSortSprites:
call LoadSpriteGFX
call SortUsedSprites
call ArrangeUsedSprites
ret
-; 142e5
-
-AddSpriteGFX: ; 142e5
+AddSpriteGFX:
; Add any new sprite ids to a list of graphics to be loaded.
; Return carry if the list is full.
@@ -372,10 +344,8 @@ AddSpriteGFX: ; 142e5
pop hl
and a
ret
-; 14306
-
-LoadSpriteGFX: ; 14306
+LoadSpriteGFX:
; Bug: b is not preserved, so it's useless as a next count.
; Uncomment the lines below to fix.
@@ -401,10 +371,8 @@ LoadSpriteGFX: ; 14306
; pop bc
ld a, l
ret
-; 1431e
-
-SortUsedSprites: ; 1431e
+SortUsedSprites:
; Bubble-sort sprites by type.
; Run backwards through wUsedSprites to find the last one.
@@ -473,10 +441,8 @@ SortUsedSprites: ; 1431e
.quit
ret
-; 14355
-
-ArrangeUsedSprites: ; 14355
+ArrangeUsedSprites:
; Get the length of each sprite and space them out in VRAM.
; Crystal introduces a second table in VRAM bank 0.
@@ -533,10 +499,8 @@ ArrangeUsedSprites: ; 14355
.quit
ret
-; 14386
-
-GetSpriteLength: ; 14386
+GetSpriteLength:
; Return the length of sprite type a in tiles.
cp WALKING_SPRITE
@@ -556,10 +520,8 @@ GetSpriteLength: ; 14386
.OneDirection:
ld a, 4
ret
-; 1439b
-
-GetUsedSprites: ; 1439b
+GetUsedSprites:
ld hl, wUsedSprites
ld c, SPRITE_GFX_LIST_CAPACITY
@@ -594,9 +556,8 @@ GetUsedSprites: ; 1439b
.done
ret
-; 143c8
-GetUsedSprite: ; 143c8
+GetUsedSprite:
ld a, [hUsedSpriteIndex]
call SafeGetSprite
ld a, [hUsedSpriteTile]
@@ -639,9 +600,8 @@ endr
.done
ret
-; 14406
-.GetTileAddr: ; 14406
+.GetTileAddr:
; Return the address of tile (a) in (hl).
and $7f
ld l, a
@@ -656,9 +616,8 @@ endr
adc HIGH(vTiles0)
ld h, a
ret
-; 14418
-.CopyToVram: ; 14418
+.CopyToVram:
ld a, [rVBK]
push af
ld a, [wSpriteFlags]
@@ -673,9 +632,8 @@ endr
pop af
ld [rVBK], a
ret
-; 1442f
-LoadEmote:: ; 1442f
+LoadEmote::
; Get the address of the pointer to emote c.
ld a, c
ld bc, 6 ; sizeof(emote)
@@ -703,8 +661,6 @@ LoadEmote:: ; 1442f
ret z
call GetEmote2bpp
ret
-; 1444d
-
INCLUDE "data/sprites/emotes.asm"
diff --git a/engine/overworld/player_movement.asm b/engine/overworld/player_movement.asm
index ef9afc7ad..a4926e7e5 100644
--- a/engine/overworld/player_movement.asm
+++ b/engine/overworld/player_movement.asm
@@ -1,4 +1,4 @@
-DoPlayerMovement:: ; 80000
+DoPlayerMovement::
call .GetDPad
ld a, movement_step_sleep
@@ -30,7 +30,6 @@ DoPlayerMovement:: ; 80000
or D_DOWN
ld [wCurInput], a
ret
-; 8002d
.TranslateIntoMovement:
ld a, [wPlayerState]
@@ -112,9 +111,8 @@ DoPlayerMovement:: ; 80000
call .StandInPlace
xor a
ret
-; 800b7
-.CheckTile: ; 800b7
+.CheckTile:
; Tiles such as waterfalls and warps move the player
; in a given direction, overriding input.
@@ -227,9 +225,8 @@ DoPlayerMovement:: ; 80000
ld a, 5
scf
ret
-; 80147
-.CheckTurning: ; 80147
+.CheckTurning:
; If the player is turning, change direction first. This also lets
; the player change facing without moving by tapping a direction.
@@ -257,10 +254,8 @@ DoPlayerMovement:: ; 80000
.not_turning
xor a
ret
-; 8016b
-
-.TryStep: ; 8016b
+.TryStep:
; Surfing actually calls .TrySurf directly instead of passing through here.
ld a, [wPlayerState]
cp PLAYER_SURF
@@ -323,10 +318,8 @@ DoPlayerMovement:: ; 80000
.bump
xor a
ret
-; 801c0
-
-.TrySurf: ; 801c0
+.TrySurf:
call .CheckSurfPerms
ld [wd040], a
jr c, .surf_bump
@@ -359,9 +352,8 @@ DoPlayerMovement:: ; 80000
.surf_bump
xor a
ret
-; 801f3
-.TryJump: ; 801f3
+.TryJump:
ld a, [wPlayerStandingTile]
ld e, a
and $f0
@@ -399,10 +391,8 @@ DoPlayerMovement:: ; 80000
db FACE_DOWN | FACE_LEFT ; COLL_HOP_DOWN_LEFT
db FACE_UP | FACE_RIGHT ; COLL_HOP_UP_RIGHT
db FACE_UP | FACE_LEFT ; COLL_HOP_UP_LEFT
-; 80226
-
-.CheckWarp: ; 80226
+.CheckWarp:
; Bug: Since no case is made for STANDING here, it will check
; [.edgewarps + $ff]. This resolves to $3e at $8035a.
; This causes wd041 to be nonzero when standing on tile $3e,
@@ -450,7 +440,6 @@ DoPlayerMovement:: ; 80000
db COLL_WARP_CARPET_UP
db COLL_WARP_CARPET_LEFT
db COLL_WARP_CARPET_RIGHT
-; 8025f
.DoStep:
ld e, a
@@ -529,27 +518,24 @@ DoPlayerMovement:: ; 80000
db $80 + UP
db $80 + LEFT
db $80 + RIGHT
-; 802b3
-.StandInPlace: ; 802b3
+.StandInPlace:
ld a, 0
ld [wPlayerTurningDirection], a
ld a, movement_step_sleep
ld [wMovementAnimation], a
xor a
ret
-; 802bf
-._WalkInPlace: ; 802bf
+._WalkInPlace:
ld a, 0
ld [wPlayerTurningDirection], a
ld a, movement_step_bump
ld [wMovementAnimation], a
xor a
ret
-; 802cb
-.CheckForced: ; 802cb
+.CheckForced:
; When sliding on ice, input is forced to remain in the same direction.
call CheckStandingOnIce
@@ -572,13 +558,12 @@ DoPlayerMovement:: ; 80000
.forced_dpad
db D_DOWN, D_UP, D_LEFT, D_RIGHT
-; 802ec
-.GetAction: ; 802ec
+.GetAction:
; Poll player input and update movement info.
- ld hl, .table
- ld de, .table2 - .table1
+ ld hl, .action_table
+ ld de, .action_table_1_end - .action_table_1
ld a, [wCurInput]
bit D_DOWN_F, a
jr nz, .d_down
@@ -612,28 +597,22 @@ DoPlayerMovement:: ; 80000
ld [wWalkingTile], a
ret
-.table
-; struct:
-; walk direction
-; facing
-; x movement
-; y movement
-; tile collision pointer
-.table1
- db STANDING, FACE_CURRENT, 0, 0
- dw wPlayerStandingTile
-.table2
- db RIGHT, FACE_RIGHT, 1, 0
- dw wTileRight
- db LEFT, FACE_LEFT, -1, 0
- dw wTileLeft
- db UP, FACE_UP, 0, -1
- dw wTileUp
- db DOWN, FACE_DOWN, 0, 1
- dw wTileDown
-; 80341
-
-.CheckNPC: ; 80341
+player_action: MACRO
+; walk direction, facing, x movement, y movement, tile collision pointer
+ db \1, \2, \3, \4
+ dw \5
+ENDM
+
+.action_table:
+.action_table_1
+ player_action STANDING, FACE_CURRENT, 0, 0, wPlayerStandingTile
+.action_table_1_end
+ player_action RIGHT, FACE_RIGHT, 1, 0, wTileRight
+ player_action LEFT, FACE_LEFT, -1, 0, wTileLeft
+ player_action UP, FACE_UP, 0, -1, wTileUp
+ player_action DOWN, FACE_DOWN, 0, 1, wTileDown
+
+.CheckNPC:
; Returns 0 if there is an NPC in front that you can't move
; Returns 1 if there is no NPC in front
; Returns 2 if there is a movable NPC in front
@@ -668,10 +647,8 @@ DoPlayerMovement:: ; 80000
.no_bump
ld a, 2
ret
-; 8036f
-
-.CheckStrengthBoulder: ; 8036f
+.CheckStrengthBoulder:
ld hl, wBikeFlags
bit BIKEFLAGS_STRENGTH_ACTIVE_F, [hl]
jr z, .not_boulder
@@ -684,7 +661,7 @@ DoPlayerMovement:: ; 80000
ld hl, OBJECT_PALETTE
add hl, bc
- bit 6, [hl]
+ bit STRENGTH_BOULDER_F, [hl]
jr z, .not_boulder
ld hl, OBJECT_FLAGS2
@@ -696,7 +673,7 @@ DoPlayerMovement:: ; 80000
ld hl, OBJECT_RANGE
add hl, bc
ld a, [hl]
- and $fc
+ and %11111100
or d
ld [hl], a
@@ -706,9 +683,8 @@ DoPlayerMovement:: ; 80000
.not_boulder
xor a
ret
-; 8039e
-.CheckLandPerms: ; 8039e
+.CheckLandPerms:
; Return 0 if walking onto land and tile permissions allow it.
; Otherwise, return carry.
@@ -728,9 +704,8 @@ DoPlayerMovement:: ; 80000
.NotWalkable:
scf
ret
-; 803b4
-.CheckSurfPerms: ; 803b4
+.CheckSurfPerms:
; Return 0 if moving in water, or 1 if moving onto land.
; Otherwise, return carry.
@@ -750,17 +725,15 @@ DoPlayerMovement:: ; 80000
.NotSurfable:
scf
ret
-; 803ca
-.BikeCheck: ; 803ca
+.BikeCheck:
ld a, [wPlayerState]
cp PLAYER_BIKE
ret z
cp PLAYER_SKATE
ret
-; 803d3
-.CheckWalkable: ; 803d3
+.CheckWalkable:
; Return 0 if tile a is land. Otherwise, return carry.
call GetTileCollision
@@ -768,9 +741,8 @@ DoPlayerMovement:: ; 80000
ret z
scf
ret
-; 803da
-.CheckSurfable: ; 803da
+.CheckSurfable:
; Return 0 if tile a is water, or 1 if land.
; Otherwise, return carry.
@@ -796,27 +768,23 @@ DoPlayerMovement:: ; 80000
.Neither:
scf
ret
-; 803ee
-
-.BumpSound: ; 803ee
+.BumpSound:
call CheckSFX
ret c
ld de, SFX_BUMP
call PlaySFX
ret
-; 803f9
-.GetOutOfWater: ; 803f9
+.GetOutOfWater:
push bc
ld a, PLAYER_NORMAL
ld [wPlayerState], a
call ReplaceKrisSprite ; UpdateSprites
pop bc
ret
-; 80404
-CheckStandingOnIce:: ; 80404
+CheckStandingOnIce::
ld a, [wPlayerTurningDirection]
cp 0
jr z, .not_ice
@@ -836,9 +804,8 @@ CheckStandingOnIce:: ; 80404
.not_ice
and a
ret
-; 80422
-StopPlayerForEvent:: ; 80422
+StopPlayerForEvent::
ld hl, wPlayerNextMovement
ld a, movement_step_sleep
cp [hl]
@@ -848,4 +815,3 @@ StopPlayerForEvent:: ; 80422
ld a, 0
ld [wPlayerTurningDirection], a
ret
-; 80430
diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm
index 7d287dedb..08a990f4b 100644
--- a/engine/overworld/player_object.asm
+++ b/engine/overworld/player_object.asm
@@ -1,4 +1,4 @@
-BlankScreen: ; 8000
+BlankScreen:
call DisableSpriteUpdates
xor a
ld [hBGMapMode], a
@@ -16,7 +16,7 @@ BlankScreen: ; 8000
call SetPalettes
ret
-SpawnPlayer: ; 8029
+SpawnPlayer:
ld a, -1
ld [wObjectFollow_Leader], a
ld [wObjectFollow_Follower], a
@@ -51,13 +51,13 @@ SpawnPlayer: ; 8029
ld [wCenteredObject], a
ret
-PlayerObjectTemplate: ; 8071
+PlayerObjectTemplate:
; A dummy map object used to initialize the player object.
; Shorter than the actual amount copied by two bytes.
; Said bytes seem to be unused.
object_event -4, -4, SPRITE_CHRIS, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, 0, -1
-CopyDECoordsToMapObject:: ; 807e
+CopyDECoordsToMapObject::
push de
ld a, b
call GetMapObject
@@ -70,7 +70,7 @@ CopyDECoordsToMapObject:: ; 807e
ld [hl], e
ret
-PlayerSpawn_ConvertCoords: ; 808f
+PlayerSpawn_ConvertCoords:
push bc
ld a, [wXCoord]
add 4
@@ -82,7 +82,7 @@ PlayerSpawn_ConvertCoords: ; 808f
call CopyDECoordsToMapObject
ret
-WriteObjectXY:: ; 80a1
+WriteObjectXY::
ld a, b
call CheckObjectVisibility
ret c
@@ -99,7 +99,7 @@ WriteObjectXY:: ; 80a1
and a
ret
-RefreshPlayerCoords: ; 80b8
+RefreshPlayerCoords:
ld a, [wXCoord]
add 4
ld d, a
@@ -127,7 +127,7 @@ RefreshPlayerCoords: ; 80b8
ret nz ; wtf
ret
-CopyObjectStruct:: ; 80e7
+CopyObjectStruct::
call CheckObjectMask
and a
ret nz ; masked
@@ -161,12 +161,12 @@ CopyObjectStruct:: ; 80e7
set 5, [hl]
ret
-CopyMapObjectToObjectStruct: ; 8116
+CopyMapObjectToObjectStruct:
call .CopyMapObjectToTempObject
call CopyTempObjectToObjectStruct
ret
-.CopyMapObjectToTempObject: ; 811d
+.CopyMapObjectToTempObject:
ld a, [hObjectStructIndexBuffer]
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
add hl, bc
@@ -223,7 +223,7 @@ CopyMapObjectToObjectStruct: ; 8116
ld [wTempObjectCopyRadius], a
ret
-InitializeVisibleSprites: ; 8177
+InitializeVisibleSprites:
ld bc, wMapObjects + OBJECT_LENGTH
ld a, 1
.loop
@@ -281,10 +281,10 @@ InitializeVisibleSprites: ; 8177
jr nz, .loop
ret
-.ret ; 81c9
+.ret
ret
-CheckObjectEnteringVisibleRange:: ; 81ca
+CheckObjectEnteringVisibleRange::
nop
ld a, [wPlayerStepDirection]
cp STANDING
@@ -293,21 +293,21 @@ CheckObjectEnteringVisibleRange:: ; 81ca
rst JumpTable
ret
-.dw ; 81d6
+.dw
dw .Down
dw .Up
dw .Left
dw .Right
-.Up: ; 81de
+.Up:
ld a, [wYCoord]
sub 1
jr .Vertical
-.Down: ; 81e5
+.Down:
ld a, [wYCoord]
add 9
-.Vertical: ; 81ea
+.Vertical:
ld d, a
ld a, [wXCoord]
ld e, a
@@ -355,15 +355,15 @@ CheckObjectEnteringVisibleRange:: ; 81ca
jr nz, .loop_v
ret
-.Left: ; 8232
+.Left:
ld a, [wXCoord]
sub 1
jr .Horizontal
-.Right: ; 8239
+.Right:
ld a, [wXCoord]
add 10
-.Horizontal: ; 823e
+.Horizontal:
ld e, a
ld a, [wYCoord]
ld d, a
@@ -411,7 +411,7 @@ CheckObjectEnteringVisibleRange:: ; 81ca
jr nz, .loop_h
ret
-CopyTempObjectToObjectStruct: ; 8286
+CopyTempObjectToObjectStruct:
ld a, [wTempObjectCopyMapObjectIndex]
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, de
@@ -461,7 +461,7 @@ CopyTempObjectToObjectStruct: ; 8286
and a
ret
-.InitYCoord: ; 82d5
+.InitYCoord:
ld hl, OBJECT_INIT_Y
add hl, de
ld [hl], a
@@ -481,7 +481,7 @@ CopyTempObjectToObjectStruct: ; 8286
ld [hl], a
ret
-.InitXCoord: ; 82f1
+.InitXCoord:
ld hl, OBJECT_INIT_X
add hl, de
ld [hl], a
@@ -499,7 +499,7 @@ CopyTempObjectToObjectStruct: ; 8286
ld [hl], a
ret
-.InitRadius: ; 830d
+.InitRadius:
ld h, a
inc a
and $f
@@ -513,7 +513,7 @@ CopyTempObjectToObjectStruct: ; 8286
ld [hl], a
ret
-TrainerWalkToPlayer: ; 831e
+TrainerWalkToPlayer:
ld a, [hLastTalked]
call InitMovementBuffer
ld a, movement_step_sleep
@@ -533,7 +533,7 @@ TrainerWalkToPlayer: ; 831e
call AppendToMovementBuffer
ret
-.GetPathToPlayer: ; 8341
+.GetPathToPlayer:
push de
push bc
; get player object struct, load to de
@@ -577,7 +577,7 @@ TrainerWalkToPlayer: ; 831e
call ComputePathToWalkToPlayer
ret
-SurfStartStep: ; 8379
+SurfStartStep:
call InitMovementBuffer
call .GetMovementData
call AppendToMovementBuffer
@@ -585,7 +585,7 @@ SurfStartStep: ; 8379
call AppendToMovementBuffer
ret
-.GetMovementData: ; 8388
+.GetMovementData:
ld a, [wPlayerDirection]
srl a
srl a
@@ -603,7 +603,7 @@ SurfStartStep: ; 8379
slow_step LEFT
slow_step RIGHT
-FollowNotExact:: ; 839e
+FollowNotExact::
push bc
ld a, c
call CheckObjectVisibility
@@ -690,7 +690,7 @@ FollowNotExact:: ; 839e
ld [hl], STEP_TYPE_00
ret
-GetRelativeFacing:: ; 8417
+GetRelativeFacing::
; Determines which way map object e would have to turn to face map object d. Returns carry if it's impossible for whatever reason.
ld a, d
call GetMapObject
@@ -715,7 +715,7 @@ GetRelativeFacing:: ; 8417
scf
ret
-.GetFacing_e_relativeto_d: ; 8439
+.GetFacing_e_relativeto_d:
; Determines which way object e would have to turn to face object d. Returns carry if it's impossible.
; load the coordinates of object d into bc
ld a, d
@@ -796,7 +796,7 @@ GetRelativeFacing:: ; 8417
scf
ret
-QueueFollowerFirstStep: ; 848a
+QueueFollowerFirstStep:
call .QueueFirstStep
jr c, .same
ld [wFollowMovementQueue], a
diff --git a/engine/overworld/player_step.asm b/engine/overworld/player_step.asm
index 675c6553b..eba149b57 100644
--- a/engine/overworld/player_step.asm
+++ b/engine/overworld/player_step.asm
@@ -1,4 +1,4 @@
-_HandlePlayerStep:: ; d497 (3:5497)
+_HandlePlayerStep::
ld a, [wPlayerStepFlags]
and a
ret z
@@ -34,7 +34,7 @@ _HandlePlayerStep:: ; d497 (3:5497)
ld [wPlayerBGMapOffsetY], a
ret
-ScrollScreen:: ; d4d2 (3:54d2)
+ScrollScreen::
ld a, [wPlayerStepVectorX]
ld d, a
ld a, [wPlayerStepVectorY]
@@ -47,7 +47,7 @@ ScrollScreen:: ; d4d2 (3:54d2)
ld [hSCY], a
ret
-HandlePlayerStep: ; d4e5 (3:54e5)
+HandlePlayerStep:
ld hl, wHandlePlayerStep
ld a, [hl]
and a
@@ -58,7 +58,7 @@ HandlePlayerStep: ; d4e5 (3:54e5)
rst JumpTable
ret
-.Jumptable: ; d4f2 (3:54f2)
+.Jumptable:
dw GetMovementPermissions
dw BufferScreen
dw .mobile
@@ -72,17 +72,17 @@ HandlePlayerStep: ; d4e5 (3:54e5)
dw .fail1
dw .fail1
-.fail1 ; d508 (3:5508)
+.fail1
ret
-.mobile ; d509 (3:5509)
+.mobile
farcall StubbedTrainerRankings_StepCount
ret
-.fail2 ; d510 (3:5510)
+.fail2
ret
-UpdatePlayerCoords: ; d511 (3:5511)
+UpdatePlayerCoords:
ld a, [wPlayerStepDirection]
and a
jr nz, .check_step_down
@@ -111,7 +111,7 @@ UpdatePlayerCoords: ; d511 (3:5511)
inc [hl]
ret
-UpdateOverworldMap: ; d536 (3:5536)
+UpdateOverworldMap:
ld a, [wPlayerStepDirection]
and a
jr z, .step_down
@@ -147,7 +147,7 @@ UpdateOverworldMap: ; d536 (3:5536)
call ScrollMapLeft
ret
-.ScrollOverworldMapDown: ; d571 (3:5571)
+.ScrollOverworldMapDown:
ld a, [wBGMapAnchor]
add 2 * BG_MAP_WIDTH
ld [wBGMapAnchor], a
@@ -168,7 +168,7 @@ UpdateOverworldMap: ; d536 (3:5536)
.done_down
ret
-.Add6ToOverworldMapAnchor: ; d595 (3:5595)
+.Add6ToOverworldMapAnchor:
ld hl, wOverworldMapAnchor
ld a, [wMapWidth]
add 6
@@ -178,7 +178,7 @@ UpdateOverworldMap: ; d536 (3:5536)
inc [hl]
ret
-.ScrollOverworldMapUp: ; d5a2 (3:55a2)
+.ScrollOverworldMapUp:
ld a, [wBGMapAnchor]
sub 2 * BG_MAP_WIDTH
ld [wBGMapAnchor], a
@@ -199,7 +199,7 @@ UpdateOverworldMap: ; d536 (3:5536)
.done_up
ret
-.Sub6FromOverworldMapAnchor: ; d5c6 (3:55c6)
+.Sub6FromOverworldMapAnchor:
ld hl, wOverworldMapAnchor
ld a, [wMapWidth]
add 6
@@ -211,7 +211,7 @@ UpdateOverworldMap: ; d536 (3:5536)
dec [hl]
ret
-.ScrollOverworldMapLeft: ; d5d5 (3:55d5)
+.ScrollOverworldMapLeft:
ld a, [wBGMapAnchor]
ld e, a
and $e0
@@ -231,7 +231,7 @@ UpdateOverworldMap: ; d536 (3:5536)
.done_left
ret
-.DecrementwOverworldMapAnchor: ; d5f4 (3:55f4)
+.DecrementwOverworldMapAnchor:
ld hl, wOverworldMapAnchor
ld a, [hl]
sub 1
@@ -240,7 +240,7 @@ UpdateOverworldMap: ; d536 (3:5536)
dec [hl]
ret
-.ScrollOverworldMapRight: ; d5fe (3:55fe)
+.ScrollOverworldMapRight:
ld a, [wBGMapAnchor]
ld e, a
and $e0
@@ -260,7 +260,7 @@ UpdateOverworldMap: ; d536 (3:5536)
.done_right
ret
-.IncrementwOverworldMapAnchor: ; d61d (3:561d)
+.IncrementwOverworldMapAnchor:
ld hl, wOverworldMapAnchor
ld a, [hl]
add 1
diff --git a/engine/overworld/scripting.asm b/engine/overworld/scripting.asm
index a18be2e6c..f8e702eb9 100644
--- a/engine/overworld/scripting.asm
+++ b/engine/overworld/scripting.asm
@@ -1,6 +1,5 @@
; Event scripting commands.
-
EnableScriptMode::
push af
ld a, SCRIPT_READ
@@ -62,7 +61,6 @@ RunScriptCommand:
rst JumpTable
ret
-
ScriptCommandTable:
; entries correspond to macros/scripts/events.asm enumeration
dw Script_scall ; 00
@@ -332,7 +330,6 @@ JumpTextScript:
closetext
end
-
if _CRYSTAL
Script_farjumptext:
@@ -351,7 +348,6 @@ Script_farjumptext:
endc
-
Script_writetext:
; script command 0x4c
; parameters: text_pointer
@@ -521,7 +517,6 @@ Script_verbosegiveitem:
ld de, GiveItemScript
jp ScriptCall
-
ret_96f76:
ret
@@ -544,7 +539,6 @@ ReceivedItemText:
text_jump UnknownText_0x1c4719
db "@"
-
Script_verbosegiveitem2:
; script command 0x9f
; parameters: item, var
@@ -608,7 +602,6 @@ Script_specialsound:
call WaitSFX
ret
-
GetPocketName:
farcall CheckItemPocket
ld a, [wItemAttributeParamBuffer]
@@ -634,7 +627,6 @@ CurItemName:
call GetItemName
ret
-
PutItemInPocketText:
text_jump UnknownText_0x1c472c
db "@"
@@ -643,7 +635,6 @@ PocketIsFullText:
text_jump UnknownText_0x1c474b
db "@"
-
Script_pokemart:
; script command 0x94
; parameters: dialog_id, mart_id
@@ -1071,7 +1062,7 @@ ApplyObjectFacing:
jr c, .not_visible ; STILL_SPRITE
ld hl, OBJECT_FLAGS1
add hl, bc
- bit FIXED_FACING, [hl]
+ bit FIXED_FACING_F, [hl]
jr nz, .not_visible
pop de
ld a, e
@@ -1274,7 +1265,6 @@ ShowEmoteScript:
step_sleep 1
step_end
-
Script_earthquake:
; script command 0x78
; parameters: param
@@ -1301,7 +1291,6 @@ EarthquakeMovement:
step_end
.End
-
Script_loadpikachudata:
; script command 0x5a
@@ -2664,7 +2653,6 @@ Script_closetext:
call CloseText
ret
-
Script_passtoengine:
; script command 0x89
; parameters: data_pointer
@@ -2834,7 +2822,6 @@ Script_checksave:
ld [wScriptVar], a
ret
-
; unused
ld a, [.byte]
ld [wScriptVar], a
diff --git a/engine/overworld/select_menu.asm b/engine/overworld/select_menu.asm
index 9898afda2..9eba9de83 100644
--- a/engine/overworld/select_menu.asm
+++ b/engine/overworld/select_menu.asm
@@ -1,5 +1,4 @@
-SelectMenu:: ; 13327
-
+SelectMenu::
call CheckRegisteredItem
jr c, .NotRegistered
jp UseRegisteredItem
@@ -11,17 +10,12 @@ SelectMenu:: ; 13327
call MapTextbox
call WaitButton
jp CloseText
-; 13340
-
-ItemMayBeRegisteredText: ; 13340
+ItemMayBeRegisteredText:
text_jump UnknownText_0x1c1cf3
db "@"
-; 13345
-
-
-CheckRegisteredItem: ; 13345
+CheckRegisteredItem:
ld a, [wWhichRegisteredItem]
and a
jr z, .NoRegisteredItem
@@ -86,10 +80,8 @@ CheckRegisteredItem: ; 13345
ld [wRegisteredItem], a
scf
ret
-; 133a6
-
-.CheckRegisteredNo: ; 133a6
+.CheckRegisteredNo:
ld a, [wWhichRegisteredItem]
and REGISTERED_NUMBER
dec a
@@ -102,10 +94,8 @@ CheckRegisteredItem: ; 13345
.NotEnoughItems:
scf
ret
-; 133b6
-
-.IsSameItem: ; 133b6
+.IsSameItem:
ld a, [wRegisteredItem]
cp [hl]
jr nz, .NotSameItem
@@ -116,11 +106,8 @@ CheckRegisteredItem: ; 13345
.NotSameItem:
scf
ret
-; 133c3
-
-
-UseRegisteredItem: ; 133c3
+UseRegisteredItem:
farcall CheckItemMenu
ld a, [wItemAttributeParamBuffer]
ld hl, .SwitchTo
@@ -136,25 +123,22 @@ UseRegisteredItem: ; 133c3
dw .Current
dw .Party
dw .Overworld
-; 133df
-.NoFunction: ; 133df
+.NoFunction:
call OpenText
call CantUseItem
call CloseText
and a
ret
-; 133ea
-.Current: ; 133ea
+.Current:
call OpenText
call DoItemEffect
call CloseText
and a
ret
-; 133f5
-.Party: ; 133f5
+.Party:
call RefreshScreen
call FadeToMenu
call DoItemEffect
@@ -162,9 +146,8 @@ UseRegisteredItem: ; 133c3
call CloseText
and a
ret
-; 13406
-.Overworld: ; 13406
+.Overworld:
call RefreshScreen
ld a, 1
ld [wUsingItemWithSelect], a
@@ -178,9 +161,8 @@ UseRegisteredItem: ; 133c3
ld a, HMENURETURN_SCRIPT
ld [hMenuReturn], a
ret
-; 13422
-.CantUse: ; 13422
+.CantUse:
call RefreshScreen
._cantuse
@@ -188,4 +170,3 @@ UseRegisteredItem: ; 133c3
call CloseText
and a
ret
-; 1342d
diff --git a/engine/overworld/spawn_points.asm b/engine/overworld/spawn_points.asm
index 1a3d12441..6b4476f2b 100644
--- a/engine/overworld/spawn_points.asm
+++ b/engine/overworld/spawn_points.asm
@@ -1,7 +1,6 @@
INCLUDE "data/maps/spawn_points.asm"
-
-LoadSpawnPoint: ; 1531f
+LoadSpawnPoint:
; loads the spawn point in wDefaultSpawnpoint
push hl
push de
@@ -26,10 +25,8 @@ LoadSpawnPoint: ; 1531f
pop de
pop hl
ret
-; 15344
-
-IsSpawnPoint: ; 15344
+IsSpawnPoint:
; Checks if the map loaded in de is a spawn point. Returns carry if it's a spawn point.
ld hl, SpawnPoints
ld c, 0
@@ -59,4 +56,3 @@ IsSpawnPoint: ; 15344
.yes
scf
ret
-; 15363
diff --git a/engine/overworld/tile_events.asm b/engine/overworld/tile_events.asm
index 705c0e427..bb566c997 100644
--- a/engine/overworld/tile_events.asm
+++ b/engine/overworld/tile_events.asm
@@ -1,4 +1,4 @@
-CheckWarpCollision:: ; 1499a
+CheckWarpCollision::
; Is this tile a warp?
ld a, [wPlayerStandingTile]
cp COLL_PIT
@@ -14,9 +14,8 @@ CheckWarpCollision:: ; 1499a
.warp
scf
ret
-; 149af
-CheckDirectionalWarp:: ; 149af
+CheckDirectionalWarp::
; If this is a directional warp, clear carry (press the designated button to warp).
; Else, set carry (immediate warp).
ld a, [wPlayerStandingTile]
@@ -34,17 +33,15 @@ CheckDirectionalWarp:: ; 149af
.directional
xor a
ret
-; 149c6
-CheckWarpFacingDown: ; 149c6
+CheckWarpFacingDown:
ld de, 1
ld hl, .blocks
ld a, [wPlayerStandingTile]
call IsInArray
ret
-; 149d3
-.blocks ; 149d3
+.blocks
db COLL_DOOR
db COLL_DOOR_79
db COLL_STAIRCASE
@@ -55,17 +52,15 @@ CheckWarpFacingDown: ; 149c6
db COLL_DOOR_75
db COLL_DOOR_7D
db -1
-; 149dd
-CheckGrassCollision:: ; 149dd
+CheckGrassCollision::
ld a, [wPlayerStandingTile]
ld hl, .blocks
ld de, 1
call IsInArray
ret
-; 149ea
-.blocks ; 149ea
+.blocks
db COLL_CUT_08
db COLL_TALL_GRASS
db COLL_LONG_GRASS
@@ -77,17 +72,15 @@ CheckGrassCollision:: ; 149dd
db COLL_GRASS_4B
db COLL_GRASS_4C
db -1
-; 149f5
-CheckCutCollision: ; 149f5
+CheckCutCollision:
ld a, c
ld hl, .blocks
ld de, 1
call IsInArray
ret
-; 14a00
-.blocks ; 14a00
+.blocks
db COLL_CUT_TREE
db COLL_CUT_TREE_1A
db COLL_TALL_GRASS_10
@@ -95,9 +88,8 @@ CheckCutCollision: ; 149f5
db COLL_LONG_GRASS
db COLL_LONG_GRASS_1C
db -1
-; 14a07
-GetWarpSFX:: ; 14a07
+GetWarpSFX::
ld a, [wPlayerStandingTile]
ld de, SFX_ENTER_DOOR
cp COLL_DOOR
@@ -107,4 +99,3 @@ GetWarpSFX:: ; 14a07
ret z
ld de, SFX_EXIT_BUILDING
ret
-; 14a1a
diff --git a/engine/overworld/time.asm b/engine/overworld/time.asm
index 0f83447cc..abb12d87d 100644
--- a/engine/overworld/time.asm
+++ b/engine/overworld/time.asm
@@ -1,21 +1,19 @@
-_InitializeStartDay: ; 113d6
+_InitializeStartDay:
call InitializeStartDay
ret
-; 113da
-ClearDailyTimers: ; 113da
+ClearDailyTimers:
xor a
ld [wLuckyNumberDayBuffer], a
ld [wUnusedTwoDayTimer], a
ld [wDailyResetTimer], a
ret
-; 113e5
-InitCallReceiveDelay:: ; 113e5
+InitCallReceiveDelay::
xor a
ld [wTimeCyclesSinceLastCall], a
-NextCallReceiveDelay: ; 113e9
+NextCallReceiveDelay:
ld a, [wTimeCyclesSinceLastCall]
cp 3
jr c, .okay
@@ -28,13 +26,11 @@ NextCallReceiveDelay: ; 113e9
add hl, de
ld a, [hl]
jp RestartReceiveCallDelay
-; 113fd
.ReceiveCallDelays:
db 20, 10, 5, 3
-; 11401
-CheckReceiveCallTimer: ; 11401
+CheckReceiveCallTimer:
call CheckReceiveCallDelay ; check timer
ret nc
ld hl, wTimeCyclesSinceLastCall
@@ -47,12 +43,11 @@ CheckReceiveCallTimer: ; 11401
call NextCallReceiveDelay ; restart timer
scf
ret
-; 11413
-InitOneDayCountdown: ; 11413
+InitOneDayCountdown:
ld a, 1
-InitNDaysCountdown: ; 11415
+InitNDaysCountdown:
ld [hl], a
push hl
call UpdateTime
@@ -60,9 +55,8 @@ InitNDaysCountdown: ; 11415
inc hl
call CopyDayToHL
ret
-; 11420
-CheckDayDependentEventHL: ; 11420
+CheckDayDependentEventHL:
inc hl
push hl
call CalcDaysSince
@@ -71,32 +65,28 @@ CheckDayDependentEventHL: ; 11420
dec hl
call UpdateTimeRemaining
ret
-; 1142e
-RestartReceiveCallDelay: ; 1142e
+RestartReceiveCallDelay:
ld hl, wReceiveCallDelay_MinsRemaining
ld [hl], a
call UpdateTime
ld hl, wReceiveCallDelay_StartTime
call CopyDayHourMinToHL
ret
-; 1143c
-CheckReceiveCallDelay: ; 1143c
+CheckReceiveCallDelay:
ld hl, wReceiveCallDelay_StartTime
call CalcMinsHoursDaysSince
call GetMinutesSinceIfLessThan60
ld hl, wReceiveCallDelay_MinsRemaining
call UpdateTimeRemaining
ret
-; 1144c
-RestartDailyResetTimer: ; 1144c
+RestartDailyResetTimer:
ld hl, wDailyResetTimer
jp InitOneDayCountdown
-; 11452
-CheckDailyResetTimer:: ; 11452
+CheckDailyResetTimer::
ld hl, wDailyResetTimer
call CheckDayDependentEventHL
ret nc
@@ -128,18 +118,16 @@ endr
call SampleKenjiBreakCountdown
.DontRestartKenjiBreakCountdown:
jr RestartDailyResetTimer
-; 11485
-SampleKenjiBreakCountdown: ; 11485
+SampleKenjiBreakCountdown:
; Generate a random number between 3 and 6
call Random
and %11
add 3
ld [wKenjiBreakTimer], a
ret
-; 11490
-StartBugContestTimer: ; 11490
+StartBugContestTimer:
ld a, BUG_CONTEST_MINUTES
ld [wBugContestMinsRemaining], a
ld a, BUG_CONTEST_SECONDS
@@ -148,10 +136,8 @@ StartBugContestTimer: ; 11490
ld hl, wBugContestStartTime
call CopyDayHourMinSecToHL
ret
-; 114a4
-
-CheckBugContestTimer:: ; 114a4 (4:54a4)
+CheckBugContestTimer::
ld hl, wBugContestStartTime
call CalcSecsMinsHoursDaysSince
ld a, [wDaysSince]
@@ -185,15 +171,13 @@ CheckBugContestTimer:: ; 114a4 (4:54a4)
scf
ret
-
-InitializeStartDay: ; 114dd
+InitializeStartDay:
call UpdateTime
ld hl, wTimerEventStartDay
call CopyDayToHL
ret
-; 114e7
-CheckPokerusTick:: ; 114e7
+CheckPokerusTick::
ld hl, wTimerEventStartDay
call CalcDaysSince
call GetDaysSince
@@ -204,9 +188,8 @@ CheckPokerusTick:: ; 114e7
.done
xor a
ret
-; 114fc
-SetUnusedTwoDayTimer: ; 114fc
+SetUnusedTwoDayTimer:
ld a, 2
ld hl, wUnusedTwoDayTimer
ld [hl], a
@@ -214,22 +197,19 @@ SetUnusedTwoDayTimer: ; 114fc
ld hl, wUnusedTwoDayTimerStartDate
call CopyDayToHL
ret
-; 1150c
-CheckUnusedTwoDayTimer: ; 1150c
+CheckUnusedTwoDayTimer:
ld hl, wUnusedTwoDayTimerStartDate
call CalcDaysSince
call GetDaysSince
ld hl, wUnusedTwoDayTimer
call UpdateTimeRemaining
ret
-; 1151c
; unused
ld hl, wDailyFlags
set DAILYFLAGS_FISH_SWARM_F, [hl]
ret
-; 11522
; unused
and a
@@ -238,15 +218,13 @@ CheckUnusedTwoDayTimer: ; 1150c
ret nz
scf
ret
-; 1152b
-RestartLuckyNumberCountdown: ; 1152b
+RestartLuckyNumberCountdown:
call .GetDaysUntilNextFriday
ld hl, wLuckyNumberDayBuffer
jp InitNDaysCountdown
-; 11534
-.GetDaysUntilNextFriday: ; 11534
+.GetDaysUntilNextFriday:
call GetWeekday
ld c, a
ld a, FRIDAY
@@ -259,14 +237,12 @@ RestartLuckyNumberCountdown: ; 1152b
.earlier
ret
-; 11542
-_CheckLuckyNumberShowFlag: ; 11542
+_CheckLuckyNumberShowFlag:
ld hl, wLuckyNumberDayBuffer
jp CheckDayDependentEventHL
-; 11548
-DoMysteryGiftIfDayHasPassed: ; 11548
+DoMysteryGiftIfDayHasPassed:
ld a, BANK(sMysteryGiftTimer)
call GetSRAMBank
ld hl, sMysteryGiftTimer
@@ -294,9 +270,8 @@ DoMysteryGiftIfDayHasPassed: ; 11548
ld [sMysteryGiftTimer + 1], a
call CloseSRAM
ret
-; 11586
-UpdateTimeRemaining: ; 11586
+UpdateTimeRemaining:
; If the amount of time elapsed exceeds the capacity of its
; unit, skip this part.
cp -1
@@ -318,9 +293,8 @@ UpdateTimeRemaining: ; 11586
ld [hl], a
scf
ret
-; 11599
-GetSecondsSinceIfLessThan60: ; 11599
+GetSecondsSinceIfLessThan60:
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
@@ -331,9 +305,8 @@ GetSecondsSinceIfLessThan60: ; 11599
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wSecondsSince]
ret
-; 115ae
-GetMinutesSinceIfLessThan60: ; 115ae
+GetMinutesSinceIfLessThan60:
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
@@ -342,45 +315,38 @@ GetMinutesSinceIfLessThan60: ; 115ae
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wMinutesSince]
ret
-; 115be
-GetHoursSinceIfLessThan24: ; 115be
+GetHoursSinceIfLessThan24:
ld a, [wDaysSince]
and a
jr nz, GetTimeElapsed_ExceedsUnitLimit
ld a, [wHoursSince]
ret
-; 115c8
-GetDaysSince: ; 115c8
+GetDaysSince:
ld a, [wDaysSince]
ret
-; 115cc
-GetTimeElapsed_ExceedsUnitLimit: ; 115cc
+GetTimeElapsed_ExceedsUnitLimit:
ld a, -1
ret
-; 115cf
-CalcDaysSince: ; 115cf
+CalcDaysSince:
xor a
jr _CalcDaysSince
-; 115d2
-CalcHoursDaysSince: ; 115d2
+CalcHoursDaysSince:
inc hl
xor a
jr _CalcHoursDaysSince
-; 115d6
-CalcMinsHoursDaysSince: ; 115d6
+CalcMinsHoursDaysSince:
inc hl
inc hl
xor a
jr _CalcMinsHoursDaysSince
-; 115db
-CalcSecsMinsHoursDaysSince: ; 115db
+CalcSecsMinsHoursDaysSince:
inc hl
inc hl
inc hl
@@ -394,7 +360,7 @@ CalcSecsMinsHoursDaysSince: ; 115db
dec hl
ld [wSecondsSince], a ; seconds since
-_CalcMinsHoursDaysSince: ; 115eb
+_CalcMinsHoursDaysSince:
ld a, [hMinutes]
ld c, a
sbc [hl]
@@ -405,7 +371,7 @@ _CalcMinsHoursDaysSince: ; 115eb
dec hl
ld [wMinutesSince], a ; minutes since
-_CalcHoursDaysSince: ; 115f8
+_CalcHoursDaysSince:
ld a, [hHours]
ld c, a
sbc [hl]
@@ -426,9 +392,8 @@ _CalcDaysSince:
ld [hl], c ; current days
ld [wDaysSince], a ; days since
ret
-; 11613
-CopyDayHourMinSecToHL: ; 11613
+CopyDayHourMinSecToHL:
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
@@ -438,23 +403,20 @@ CopyDayHourMinSecToHL: ; 11613
ld a, [hSeconds]
ld [hli], a
ret
-; 11621
-CopyDayToHL: ; 11621
+CopyDayToHL:
ld a, [wCurDay]
ld [hl], a
ret
-; 11626
-CopyDayHourToHL: ; 11626
+CopyDayHourToHL:
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
ld [hli], a
ret
-; 1162e
-CopyDayHourMinToHL: ; 1162e
+CopyDayHourMinToHL:
ld a, [wCurDay]
ld [hli], a
ld a, [hHours]
@@ -462,4 +424,3 @@ CopyDayHourMinToHL: ; 1162e
ld a, [hMinutes]
ld [hli], a
ret
-; 11639
diff --git a/engine/overworld/variables.asm b/engine/overworld/variables.asm
index 3adf6df33..9b5e3846c 100644
--- a/engine/overworld/variables.asm
+++ b/engine/overworld/variables.asm
@@ -1,4 +1,4 @@
-_GetVarAction:: ; 80648 (20:4648)
+_GetVarAction::
ld a, c
cp NUM_VARS
jr c, .valid
@@ -28,13 +28,12 @@ _GetVarAction:: ; 80648 (20:4648)
call _de_
ret
-.loadstringbuffer2 ; 8066c (20:466c)
+.loadstringbuffer2
ld de, wStringBuffer2
ld [de], a
ret
-; 80671 (20:4671)
-.VarActionTable: ; 80671
+.VarActionTable:
; entries correspond to VAR_* constants
; RETVAR_STRBUF2: copy [de] to wStringBuffer2
; RETVAR_ADDR_DE: return address in de
@@ -67,51 +66,45 @@ _GetVarAction:: ; 80648 (20:4648)
dwb wBuenasPassword, RETVAR_ADDR_DE
dwb wKenjiBreakTimer, RETVAR_STRBUF2
dwb NULL, RETVAR_STRBUF2
-; 806c5
-.CountCaughtMons: ; 806c5
+.CountCaughtMons:
; Caught mons.
ld hl, wPokedexCaught
ld b, wEndPokedexCaught - wPokedexCaught
call CountSetBits
ld a, [wd265]
jp .loadstringbuffer2
-; 806d3
-.CountSeenMons: ; 806d3
+.CountSeenMons:
; Seen mons.
ld hl, wPokedexSeen
ld b, wEndPokedexSeen - wPokedexSeen
call CountSetBits
ld a, [wd265]
jp .loadstringbuffer2
-; 806e1
-.CountBadges: ; 806e1
+.CountBadges:
; Number of owned badges.
ld hl, wBadges
ld b, 2
call CountSetBits
ld a, [wd265]
jp .loadstringbuffer2
-; 806ef
-.PlayerFacing: ; 806ef
+.PlayerFacing:
; The direction the player is facing.
ld a, [wPlayerDirection]
and $c
rrca
rrca
jp .loadstringbuffer2
-; 806f9
-.DayOfWeek: ; 806f9
+.DayOfWeek:
; The day of the week.
call GetWeekday
jp .loadstringbuffer2
-; 806ff
-.UnownCaught: ; 806ff
+.UnownCaught:
; Number of unique Unown caught.
call .count
ld a, b
@@ -129,9 +122,8 @@ _GetVarAction:: ; 80648 (20:4648)
cp NUM_UNOWN
jr c, .loop
ret
-; 80715
-.BoxFreeSpace: ; 80715
+.BoxFreeSpace:
; Remaining slots in the current box.
ld a, BANK(sBoxCount)
call GetSRAMBank
@@ -142,10 +134,8 @@ _GetVarAction:: ; 80648 (20:4648)
call CloseSRAM
ld a, b
jp .loadstringbuffer2
-; 80728
-.BattleResult: ; 80728
+.BattleResult:
ld a, [wBattleResult]
and $ff ^ BATTLERESULT_BITMASK
jp .loadstringbuffer2
-; 80730
diff --git a/engine/overworld/warp_connection.asm b/engine/overworld/warp_connection.asm
index 2f5e488cc..54df4a97f 100644
--- a/engine/overworld/warp_connection.asm
+++ b/engine/overworld/warp_connection.asm
@@ -1,5 +1,5 @@
-HandleNewMap: ; 1045b0
+HandleNewMap:
call Clearwc7e8
call ResetMapBufferEventFlags
call ResetFlashIfOutOfCave
@@ -7,7 +7,7 @@ HandleNewMap: ; 1045b0
call ResetBikeFlags
ld a, MAPCALLBACK_NEWMAP
call RunMapCallback
-InitCommandQueue: ; 1045c4
+InitCommandQueue:
farcall ClearCmdQueue
ld a, MAPCALLBACK_CMDQUEUE
call RunMapCallback
@@ -15,8 +15,7 @@ InitCommandQueue: ; 1045c4
ld [wMapTimeOfDay], a
ret
-
-EnterMapConnection: ; 1045d6
+EnterMapConnection:
; Return carry if a connection has been entered.
ld a, [wPlayerStepDirection]
and a
@@ -150,9 +149,8 @@ EnterMapConnection: ; 1045d6
.done
scf
ret
-; 1046c6
-LoadWarpData: ; 1046c6
+LoadWarpData:
call .SaveDigWarp
call .SetSpawn
ld a, [wNextWarp]
@@ -163,7 +161,7 @@ LoadWarpData: ; 1046c6
ld [wMapNumber], a
ret
-.SaveDigWarp: ; 1046df (41:46df)
+.SaveDigWarp:
call GetMapEnvironment
call CheckOutdoorMap
ret nz
@@ -195,7 +193,7 @@ LoadWarpData: ; 1046c6
ld [wDigMapNumber], a
ret
-.SetSpawn: ; 104718 (41:4718)
+.SetSpawn:
call GetMapEnvironment
call CheckOutdoorMap
ret nz
@@ -227,7 +225,7 @@ LoadWarpData: ; 1046c6
ld [wLastSpawnMapNumber], a
ret
-LoadMapTimeOfDay: ; 104750
+LoadMapTimeOfDay:
ld hl, wVramState
res 6, [hl]
ld a, $1
@@ -239,7 +237,7 @@ LoadMapTimeOfDay: ; 104750
call .PushAttrMap
ret
-.ClearBGMap: ; 104770 (41:4770)
+.ClearBGMap:
ld a, HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
xor a ; LOW(vBGMap0)
@@ -267,7 +265,7 @@ LoadMapTimeOfDay: ; 104750
call ByteFill
ret
-.PushAttrMap: ; 1047a3 (41:47a3)
+.PushAttrMap:
decoord 0, 0
call .copy
ld a, [hCGB]
@@ -298,7 +296,7 @@ LoadMapTimeOfDay: ; 104750
ld [rVBK], a
ret
-LoadGraphics: ; 1047cf
+LoadGraphics:
call LoadTileset
call LoadTilesetGFX
xor a
@@ -310,12 +308,11 @@ LoadGraphics: ; 1047cf
farcall LoadOverworldFont
ret
-LoadMapPalettes: ; 1047eb
+LoadMapPalettes:
ld b, SCGB_MAPPALS
jp GetSGBLayout
-; 1047f0
-RefreshMapSprites: ; 1047f0
+RefreshMapSprites:
call ClearSprites
farcall ReturnFromMapSetupScript
call GetMovementPermissions
@@ -333,7 +330,7 @@ RefreshMapSprites: ; 1047f0
ld [wPlayerSpriteSetupFlags], a
ret
-CheckMovingOffEdgeOfMap:: ; 104820 (41:4820)
+CheckMovingOffEdgeOfMap::
ld a, [wPlayerStepDirection]
cp STANDING
ret z
@@ -390,8 +387,7 @@ CheckMovingOffEdgeOfMap:: ; 104820 (41:4820)
scf
ret
-
-GetCoordOfUpperLeftCorner:: ; 10486d
+GetCoordOfUpperLeftCorner::
ld hl, wOverworldMapBlocks
ld a, [wXCoord]
bit 0, a
@@ -436,4 +432,3 @@ GetCoordOfUpperLeftCorner:: ; 10486d
and $1
ld [wMetatileStandingX], a
ret
-; 1048ba
diff --git a/engine/overworld/wildmons.asm b/engine/overworld/wildmons.asm
index 20375ba6c..d88e5908f 100644
--- a/engine/overworld/wildmons.asm
+++ b/engine/overworld/wildmons.asm
@@ -1,4 +1,4 @@
-LoadWildMonData: ; 29ff8
+LoadWildMonData:
call _GrassWildmonLookup
jr c, .copy
ld hl, wMornEncounterRate
@@ -25,7 +25,7 @@ LoadWildMonData: ; 29ff8
ld [wWaterEncounterRate], a
ret
-FindNest: ; 2a01f
+FindNest:
; Parameters:
; e: 0 = Johto, 1 = Kanto
; wNamedObjectIndexBuffer: species
@@ -51,9 +51,8 @@ FindNest: ; 2a01f
call .FindGrass
ld hl, KantoWaterWildMons
jp .FindWater
-; 2a052
-.FindGrass: ; 2a052
+.FindGrass:
ld a, [hl]
cp -1
ret z
@@ -76,9 +75,8 @@ FindNest: ; 2a01f
ld bc, GRASS_WILDDATA_LENGTH
add hl, bc
jr .FindGrass
-; 2a06e
-.FindWater: ; 2a06e
+.FindWater:
ld a, [hl]
cp -1
ret z
@@ -88,7 +86,7 @@ FindNest: ; 2a01f
ld a, [hli]
ld c, a
inc hl
- ld a, 3
+ ld a, NUM_WATERMON
call .SearchMapForMon
jr nc, .next_water
ld [de], a
@@ -96,12 +94,11 @@ FindNest: ; 2a01f
.next_water
pop hl
- ld bc, 3 * 3
+ ld bc, WATER_WILDDATA_LENGTH
add hl, bc
jr .FindWater
-; 2a088
-.SearchMapForMon: ; 2a088
+.SearchMapForMon:
inc hl
.ScanMapLoop:
push af
@@ -119,9 +116,8 @@ FindNest: ; 2a01f
.found
pop af
jp .AppendNest
-; 2a09c
-.AppendNest: ; 2a09c
+.AppendNest:
push de
call GetWorldMapLocation
ld c, a
@@ -144,9 +140,8 @@ FindNest: ; 2a01f
pop de
and a
ret
-; 2a0b7
-.RoamMon1: ; 2a0b7
+.RoamMon1:
ld a, [wRoamMon1Species]
ld b, a
ld a, [wNamedObjectIndexBuffer]
@@ -161,9 +156,8 @@ FindNest: ; 2a01f
ld [de], a
inc de
ret
-; 2a0cf
-.RoamMon2: ; 2a0cf
+.RoamMon2:
ld a, [wRoamMon2Species]
ld b, a
ld a, [wNamedObjectIndexBuffer]
@@ -178,9 +172,8 @@ FindNest: ; 2a01f
ld [de], a
inc de
ret
-; 2a0e7
-TryWildEncounter:: ; 2a0e7
+TryWildEncounter::
; Try to trigger a wild encounter.
call .EncounterRate
jr nc, .no_battle
@@ -198,18 +191,16 @@ TryWildEncounter:: ; 2a0e7
ld a, 1
and a
ret
-; 2a103
-.EncounterRate: ; 2a103
+.EncounterRate:
call GetMapEncounterRate
call ApplyMusicEffectOnEncounterRate
call ApplyCleanseTagEffectOnEncounterRate
call Random
cp b
ret
-; 2a111
-GetMapEncounterRate: ; 2a111
+GetMapEncounterRate:
ld hl, wMornEncounterRate
call CheckOnWater
ld a, wWaterEncounterRate - wMornEncounterRate
@@ -221,9 +212,8 @@ GetMapEncounterRate: ; 2a111
add hl, bc
ld b, [hl]
ret
-; 2a124
-ApplyMusicEffectOnEncounterRate:: ; 2a124
+ApplyMusicEffectOnEncounterRate::
; Pokemon March and Ruins of Alph signal double encounter rate.
; Pokemon Lullaby halves encounter rate.
ld a, [wMapMusic]
@@ -239,9 +229,8 @@ ApplyMusicEffectOnEncounterRate:: ; 2a124
.double
sla b
ret
-; 2a138
-ApplyCleanseTagEffectOnEncounterRate:: ; 2a138
+ApplyCleanseTagEffectOnEncounterRate::
; Cleanse Tag halves encounter rate.
ld hl, wPartyMon1Item
ld de, PARTYMON_STRUCT_LENGTH
@@ -259,9 +248,8 @@ ApplyCleanseTagEffectOnEncounterRate:: ; 2a138
.cleansetag
srl b
ret
-; 2a14f
-ChooseWildEncounter: ; 2a14f
+ChooseWildEncounter:
call LoadWildMonDataPointer
jp nc, .nowildbattle
call CheckEncounterRoamMon
@@ -276,7 +264,7 @@ ChooseWildEncounter: ; 2a14f
inc hl
inc hl
ld a, [wTimeOfDay]
- ld bc, $e
+ ld bc, NUM_GRASSMON * 2
call AddNTimes
ld de, GrassMonProbTable
@@ -355,11 +343,10 @@ ChooseWildEncounter: ; 2a14f
.startwildbattle
xor a
ret
-; 2a1cb
INCLUDE "data/wild/probabilities.asm"
-CheckRepelEffect:: ; 2a1df
+CheckRepelEffect::
; If there is no active Repel, there's no need to be here.
ld a, [wRepelEffect]
and a
@@ -389,13 +376,12 @@ endr
.encounter
scf
ret
-; 2a200
-LoadWildMonDataPointer: ; 2a200
+LoadWildMonDataPointer:
call CheckOnWater
jr z, _WaterWildmonLookup
-_GrassWildmonLookup: ; 2a205
+_GrassWildmonLookup:
ld hl, SwarmGrassWildMons
ld bc, GRASS_WILDDATA_LENGTH
call _SwarmWildmonCheck
@@ -406,7 +392,7 @@ _GrassWildmonLookup: ; 2a205
ld bc, GRASS_WILDDATA_LENGTH
jr _NormalWildmonOK
-_WaterWildmonLookup: ; 2a21d
+_WaterWildmonLookup:
ld hl, SwarmWaterWildMons
ld bc, WATER_WILDDATA_LENGTH
call _SwarmWildmonCheck
@@ -467,17 +453,15 @@ _NoSwarmWildmon:
_NormalWildmonOK:
call CopyCurrMapDE
jr LookUpWildmonsForMapDE
-; 2a27f
-CopyCurrMapDE: ; 2a27f
+CopyCurrMapDE:
ld a, [wMapGroup]
ld d, a
ld a, [wMapNumber]
ld e, a
ret
-; 2a288
-LookUpWildmonsForMapDE: ; 2a288
+LookUpWildmonsForMapDE:
.loop
push hl
ld a, [hl]
@@ -505,10 +489,8 @@ LookUpWildmonsForMapDE: ; 2a288
pop hl
scf
ret
-; 2a2a0
-
-InitRoamMons: ; 2a2a0
+InitRoamMons:
; initialize wRoamMon structs
; species
@@ -540,10 +522,8 @@ InitRoamMons: ; 2a2a0
ld [wRoamMon2HP], a
ret
-; 2a2ce
-
-CheckEncounterRoamMon: ; 2a2ce
+CheckEncounterRoamMon:
push hl
; Don't trigger an encounter if we're on water.
call CheckOnWater
@@ -589,10 +569,8 @@ CheckEncounterRoamMon: ; 2a2ce
pop hl
and a
ret
-; 2a30d
-
-UpdateRoamMons: ; 2a30d
+UpdateRoamMons:
ld a, [wRoamMon1MapGroup]
cp GROUP_N_A
jr z, .SkipRaikou
@@ -633,10 +611,8 @@ UpdateRoamMons: ; 2a30d
.Finished:
jp _BackUpMapIndices
-; 2a355
-
-.Update: ; 2a355
+.Update:
ld hl, RoamMaps
.loop
; Are we at the end of the table?
@@ -675,7 +651,7 @@ UpdateRoamMons: ; 2a30d
jr nc, .update_loop ; invalid index, try again
inc hl
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
add hl, bc
ld a, [wRoamMons_LastMapGroup]
@@ -693,7 +669,7 @@ UpdateRoamMons: ; 2a30d
ld c, [hl]
ret
-JumpRoamMons: ; 2a394
+JumpRoamMons:
ld a, [wRoamMon1MapGroup]
cp GROUP_N_A
jr z, .SkipRaikou
@@ -726,7 +702,7 @@ JumpRoamMons: ; 2a394
.Finished:
jp _BackUpMapIndices
-JumpRoamMon: ; 2a3cd
+JumpRoamMon:
.loop
ld hl, RoamMaps
.innerloop1 ; This loop happens to be unnecessary.
@@ -760,9 +736,8 @@ JumpRoamMon: ; 2a3cd
ld b, a
ld c, [hl]
ret
-; 2a3f6
-_BackUpMapIndices: ; 2a3f6
+_BackUpMapIndices:
ld a, [wRoamMons_CurrentMapNumber]
ld [wRoamMons_LastMapNumber], a
ld a, [wRoamMons_CurrentMapGroup]
@@ -772,13 +747,10 @@ _BackUpMapIndices: ; 2a3f6
ld a, [wMapGroup]
ld [wRoamMons_CurrentMapGroup], a
ret
-; 2a40f
-
INCLUDE "data/wild/roammon_maps.asm"
-
-ValidateTempWildMonSpecies: ; 2a4a0
+ValidateTempWildMonSpecies:
; Due to a development oversight, this function is called with the wild Pokemon's level, not its species, in a.
and a
jr z, .nowildmon ; = 0
@@ -790,11 +762,10 @@ ValidateTempWildMonSpecies: ; 2a4a0
.nowildmon
scf
ret
-; 2a4ab
; Finds a rare wild Pokemon in the route of the trainer calling, then checks if it's been Seen already.
; The trainer will then tell you about the Pokemon if you haven't seen it.
-RandomUnseenWildMon: ; 2a4ab
+RandomUnseenWildMon:
farcall GetCallerLocation
ld d, b
ld e, c
@@ -819,7 +790,7 @@ RandomUnseenWildMon: ; 2a4ab
jr z, .randloop1
dec a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
add hl, bc
; We now have the pointer to one of the last (rarest) three wild Pokemon found in that area.
@@ -865,9 +836,8 @@ RandomUnseenWildMon: ; 2a4ab
; I just saw some rare @ in @ . I'll call you if I see another rare #MON, OK?
text_jump UnknownText_0x1bd34b
db "@"
-; 0x2a51f
-RandomPhoneWildMon: ; 2a51f
+RandomPhoneWildMon:
farcall GetCallerLocation
ld d, b
ld e, c
@@ -894,7 +864,7 @@ RandomPhoneWildMon: ; 2a51f
call Random
and %11
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
add hl, bc
inc hl
@@ -905,9 +875,8 @@ RandomPhoneWildMon: ; 2a51f
ld de, wStringBuffer4
ld bc, MON_NAME_LENGTH
jp CopyBytes
-; 2a567
-RandomPhoneMon: ; 2a567
+RandomPhoneMon:
; Get a random monster owned by the trainer who's calling.
farcall GetCallerLocation
ld hl, TrainerGroups
@@ -989,8 +958,6 @@ RandomPhoneMon: ; 2a567
ld de, wStringBuffer4
ld bc, MON_NAME_LENGTH
jp CopyBytes
-; 2a5e9
-
INCLUDE "data/wild/johto_grass.asm"
INCLUDE "data/wild/johto_water.asm"