summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rwxr-xr-xengine/HoF_room_pc.asm222
-rw-r--r--engine/add_mon.asm512
-rwxr-xr-xengine/battle/animations.asm2080
-rwxr-xr-x[-rw-r--r--]engine/battle/bank_e_misc.asm62
-rw-r--r--engine/battle/battle_transitions.asm367
-rw-r--r--engine/battle/common_text.asm109
-rwxr-xr-xengine/battle/core.asm3038
-rw-r--r--engine/battle/decrement_pp.asm26
-rw-r--r--engine/battle/display_effectiveness.asm6
-rw-r--r--engine/battle/draw_hud_pokeball_gfx.asm109
-rwxr-xr-x[-rw-r--r--]engine/battle/end_of_battle.asm32
-rw-r--r--engine/battle/experience.asm84
-rw-r--r--engine/battle/get_trainer_name.asm20
-rw-r--r--engine/battle/ghost_marowak_anim.asm26
-rw-r--r--engine/battle/init_battle_variables.asm32
-rw-r--r--engine/battle/link_battle_versus_text.asm14
-rw-r--r--engine/battle/moveEffects/conversion_effect.asm17
-rw-r--r--engine/battle/moveEffects/drain_hp_effect.asm24
-rw-r--r--engine/battle/moveEffects/focus_energy_effect.asm16
-rw-r--r--engine/battle/moveEffects/haze_effect.asm43
-rw-r--r--engine/battle/moveEffects/heal_effect.asm58
-rw-r--r--engine/battle/moveEffects/leech_seed_effect.asm39
-rw-r--r--engine/battle/moveEffects/mist_effect.asm22
-rw-r--r--engine/battle/moveEffects/one_hit_ko_effect.asm20
-rw-r--r--engine/battle/moveEffects/paralyze_effect.asm22
-rw-r--r--engine/battle/moveEffects/pay_day_effect.asm14
-rw-r--r--engine/battle/moveEffects/recoil_effect.asm44
-rw-r--r--engine/battle/moveEffects/reflect_light_screen_effect.asm26
-rw-r--r--engine/battle/moveEffects/substitute_effect.asm64
-rw-r--r--engine/battle/moveEffects/transform_effect.asm86
-rw-r--r--engine/battle/print_type.asm18
-rwxr-xr-x[-rw-r--r--]engine/battle/read_trainer_party.asm48
-rwxr-xr-xengine/battle/safari_zone.asm8
-rw-r--r--engine/battle/save_trainer_name.asm100
-rw-r--r--engine/battle/scale_sprites.asm26
-rw-r--r--engine/battle/scroll_draw_trainer_pic.asm10
-rw-r--r--engine/battle/trainer_ai.asm225
-rwxr-xr-x[-rw-r--r--]engine/battle/trainer_pic_money_pointers.asm4
-rw-r--r--engine/battle/unused_stats_functions.asm4
-rw-r--r--engine/battle/wild_encounters.asm52
-rw-r--r--engine/bcd.asm212
-rw-r--r--engine/black_out.asm46
-rwxr-xr-xengine/cable_club.asm202
-rwxr-xr-xengine/clear_save.asm10
-rw-r--r--engine/debug1.asm33
-rw-r--r--engine/display_pokedex.asm19
-rw-r--r--engine/display_text_id_init.asm78
-rwxr-xr-xengine/evolution.asm149
-rwxr-xr-xengine/evolve_trade.asm8
-rwxr-xr-xengine/evos_moves.asm169
-rwxr-xr-xengine/experience.asm104
-rw-r--r--engine/flag_action.asm73
-rwxr-xr-xengine/game_corner_slots.asm38
-rwxr-xr-xengine/game_corner_slots2.asm14
-rwxr-xr-xengine/gamefreak.asm207
-rw-r--r--engine/get_bag_item_quantity.asm18
-rwxr-xr-xengine/give_pokemon.asm49
-rwxr-xr-xengine/hall_of_fame.asm253
-rw-r--r--engine/heal_party.asm99
-rwxr-xr-xengine/hidden_object_functions14.asm62
-rwxr-xr-xengine/hidden_object_functions17.asm317
-rwxr-xr-xengine/hidden_object_functions18.asm151
-rwxr-xr-xengine/hidden_object_functions3.asm105
-rwxr-xr-xengine/hidden_object_functions7.asm375
-rwxr-xr-xengine/hp_bar.asm44
-rwxr-xr-xengine/in_game_trades.asm116
-rw-r--r--engine/init_player_data.asm55
-rwxr-xr-xengine/intro.asm315
-rw-r--r--engine/items/inventory.asm150
-rwxr-xr-xengine/items/itemfinder.asm46
-rwxr-xr-xengine/items/items.asm1235
-rwxr-xr-xengine/items/tm_prices.asm13
-rwxr-xr-xengine/items/tmhm.asm4
-rwxr-xr-xengine/items/tms.asm8
-rwxr-xr-xengine/learn_move.asm128
-rw-r--r--engine/load_mon_data.asm49
-rwxr-xr-xengine/load_pokedex_tiles.asm10
-rw-r--r--engine/menu/bills_pc.asm456
-rwxr-xr-xengine/menu/diploma.asm60
-rw-r--r--engine/menu/draw_badges.asm120
-rw-r--r--engine/menu/draw_start_menu.asm89
-rwxr-xr-xengine/menu/league_pc.asm78
-rwxr-xr-xengine/menu/main_menu.asm364
-rwxr-xr-xengine/menu/naming_screen.asm437
-rwxr-xr-xengine/menu/oaks_pc.asm17
-rwxr-xr-xengine/menu/party_menu.asm92
-rwxr-xr-xengine/menu/pc.asm101
-rwxr-xr-xengine/menu/players_pc.asm214
-rwxr-xr-xengine/menu/pokedex.asm243
-rwxr-xr-xengine/menu/prize_menu.asm232
-rwxr-xr-xengine/menu/start_menu.asm25
-rwxr-xr-xengine/menu/start_sub_menus.asm309
-rwxr-xr-xengine/menu/status_screen.asm306
-rw-r--r--engine/menu/swap_items.asm149
-rw-r--r--engine/menu/text_box.asm767
-rwxr-xr-xengine/menu/vending_machine.asm93
-rwxr-xr-xengine/mon_party_sprites.asm56
-rwxr-xr-xengine/multiply_divide.asm174
-rwxr-xr-xengine/oak_speech.asm157
-rwxr-xr-xengine/oak_speech2.asm267
-rw-r--r--engine/oam_dma.asm5
-rwxr-xr-xengine/overworld/cable_club_npc.asm55
-rwxr-xr-xengine/overworld/card_key.asm36
-rwxr-xr-xengine/overworld/cinnabar_lab.asm91
-rw-r--r--engine/overworld/clear_variables.asm20
-rwxr-xr-xengine/overworld/cut.asm201
-rwxr-xr-xengine/overworld/cut2.asm86
-rw-r--r--engine/overworld/daycare_exp.asm18
-rwxr-xr-xengine/overworld/doors.asm69
-rwxr-xr-xengine/overworld/elevator.asm42
-rwxr-xr-xengine/overworld/emotion_bubbles.asm48
-rw-r--r--engine/overworld/field_move_messages.asm57
-rwxr-xr-xengine/overworld/healing_machine.asm77
-rwxr-xr-xengine/overworld/hidden_items.asm129
-rwxr-xr-xengine/overworld/hidden_objects.asm28
-rw-r--r--engine/overworld/is_player_just_outside_map.asm10
-rw-r--r--engine/overworld/item.asm14
-rwxr-xr-xengine/overworld/ledges.asm19
-rw-r--r--engine/overworld/map_sprite_functions1.asm356
-rwxr-xr-xengine/overworld/map_sprites.asm54
-rw-r--r--engine/overworld/missable_objects.asm215
-rw-r--r--engine/overworld/movement.asm407
-rwxr-xr-xengine/overworld/npc_movement.asm156
-rwxr-xr-xengine/overworld/oaks_aide.asm50
-rw-r--r--engine/overworld/oam.asm101
-rwxr-xr-xengine/overworld/pewter_guys.asm49
-rwxr-xr-xengine/overworld/player_animations.asm205
-rw-r--r--engine/overworld/player_state.asm463
-rw-r--r--engine/overworld/poison.asm112
-rwxr-xr-xengine/overworld/pokecenter.asm30
-rwxr-xr-xengine/overworld/pokemart.asm168
-rw-r--r--engine/overworld/push_boulder.asm105
-rwxr-xr-xengine/overworld/saffron_guards.asm8
-rw-r--r--engine/overworld/set_blackout_map.asm29
-rwxr-xr-xengine/overworld/ssanne.asm25
-rw-r--r--engine/overworld/tileset_header.asm60
-rwxr-xr-xengine/overworld/trainers.asm116
-rw-r--r--engine/overworld/update_map.asm126
-rw-r--r--engine/overworld/wild_mons.asm33
-rwxr-xr-xengine/palettes.asm453
-rw-r--r--engine/pathfinding.asm201
-rwxr-xr-xengine/play_time.asm30
-rwxr-xr-xengine/pokedex_rating.asm77
-rwxr-xr-xengine/predefs.asm46
-rwxr-xr-xengine/predefs12.asm68
-rwxr-xr-xengine/predefs17.asm6
-rwxr-xr-xengine/predefs17_2.asm6
-rwxr-xr-xengine/predefs7.asm28
-rw-r--r--engine/print_waiting_text.asm20
-rw-r--r--engine/remove_pokemon.asm95
-rwxr-xr-xengine/save.asm525
-rwxr-xr-xengine/slot_machine.asm723
-rw-r--r--engine/special_warps.asm149
-rwxr-xr-xengine/status_ailments.asm2
-rw-r--r--engine/subtract_paid_money.asm17
-rw-r--r--engine/test_battle.asm45
-rwxr-xr-xengine/titlescreen.asm311
-rwxr-xr-xengine/titlescreen2.asm26
-rwxr-xr-xengine/town_map.asm460
-rwxr-xr-xengine/trade.asm257
-rwxr-xr-xengine/trade2.asm41
-rwxr-xr-xengine/turn_sprite.asm2
162 files changed, 15053 insertions, 9907 deletions
diff --git a/engine/HoF_room_pc.asm b/engine/HoF_room_pc.asm
index ae4ecb0d..82aa6d52 100755
--- a/engine/HoF_room_pc.asm
+++ b/engine/HoF_room_pc.asm
@@ -1,58 +1,58 @@
-HallOfFamePC: ; 7405c (1d:405c)
+HallOfFamePC:
callba AnimateHallOfFame
call ClearScreen
- ld c, $64
+ ld c, 100
call DelayFrames
call DisableLCD
ld hl, vFont
ld bc, $800 / 2
- call Func_74171
+ call ZeroMemory
ld hl, vChars2 + $600
ld bc, $200 / 2
- call Func_74171
+ call ZeroMemory
ld hl, vChars2 + $7e0
ld bc, $10
ld a, $ff
call FillMemory
- ld hl, wTileMap
- call Func_7417b
- hlCoord 0, 14
- call Func_7417b
- ld a, $c0
- ld [rBGP], a ; $ff47
+ coord hl, 0, 0
+ call FillFourRowsWithBlack
+ coord hl, 0, 14
+ call FillFourRowsWithBlack
+ ld a, %11000000
+ ld [rBGP], a
call EnableLCD
ld a, $ff
call PlaySoundWaitForCurrent
ld c, BANK(Music_Credits)
ld a, MUSIC_CREDITS
call PlayMusic
- ld c, $80
+ ld c, 128
call DelayFrames
xor a
- ld [wWhichTrade], a ; wWhichTrade
- ld [wTrainerEngageDistance], a
+ ld [wUnusedCD3D], a ; not read
+ ld [wNumCreditsMonsDisplayed], a
jp Credits
-Func_740ba: ; 740ba (1d:40ba)
- ld hl, DataTable_74160 ; $4160
- ld b, $4
-.asm_740bf
+FadeInCreditsText:
+ ld hl, HoFGBPalettes
+ ld b, 4
+.loop
ld a, [hli]
- ld [rBGP], a ; $ff47
- ld c, $5
+ ld [rBGP], a
+ ld c, 5
call DelayFrames
dec b
- jr nz, .asm_740bf
+ jr nz, .loop
ret
-DisplayCreditsMon: ; 740cb (1d:40cb)
+DisplayCreditsMon:
xor a
ld [H_AUTOBGTRANSFERENABLED],a
call SaveScreenTilesToBuffer1
call FillMiddleOfScreenWithWhite
; display the next monster from CreditsMons
- ld hl,wTrainerEngageDistance
+ ld hl,wNumCreditsMonsDisplayed
ld c,[hl] ; how many monsters have we displayed so far?
inc [hl]
ld b,0
@@ -61,132 +61,143 @@ DisplayCreditsMon: ; 740cb (1d:40cb)
ld a,[hl]
ld [wcf91],a
ld [wd0b5],a
- hlCoord 8, 6
+ coord hl, 8, 6
call GetMonHeader
call LoadFrontSpriteByMonIndex
ld hl,vBGMap0 + $c
- call Func_74164
+ call CreditsCopyTileMapToVRAM
xor a
ld [H_AUTOBGTRANSFERENABLED],a
call LoadScreenTilesFromBuffer1
ld hl,vBGMap0
- call Func_74164
+ call CreditsCopyTileMapToVRAM
ld a,$A7
- ld [$FF4B],a
+ ld [rWX],a
ld hl,vBGMap1
- call Func_74164
+ call CreditsCopyTileMapToVRAM
call FillMiddleOfScreenWithWhite
- ld a,$FC
- ld [$FF47],a
+ ld a,%11111100 ; make the mon a black silhouette
+ ld [rBGP],a
+
+; scroll the mon left by one tile 7 times
ld bc,7
-.next
- call Func_74140
+.scrollLoop1
+ call ScrollCreditsMonLeft
dec c
- jr nz,.next
- ld c,$14
-.next2
- call Func_74140
- ld a,[$FF4B]
+ jr nz,.scrollLoop1
+
+; scroll the mon left by one tile 20 times
+; This time, we have to move the window left too in order to hide the text that
+; is wrapping around to the right side of the screen.
+ ld c,20
+.scrollLoop2
+ call ScrollCreditsMonLeft
+ ld a,[rWX]
sub 8
- ld [$FF4B],a
+ ld [rWX],a
dec c
- jr nz,.next2
+ jr nz,.scrollLoop2
+
xor a
ld [hWY],a
- ld a,$C0
- ld [$FF47],a
+ ld a,%11000000
+ ld [rBGP],a
ret
INCLUDE "data/credit_mons.asm"
-Func_74140: ; 74140 (1d:4140)
+ScrollCreditsMonLeft:
ld h, b
ld l, $20
- call Func_74152
+ call ScrollCreditsMonLeft_SetSCX
ld h, $0
ld l, $70
- call Func_74152
+ call ScrollCreditsMonLeft_SetSCX
ld a, b
add $8
ld b, a
ret
-Func_74152: ; 74152 (1d:4152)
- ld a, [$ff44]
+ScrollCreditsMonLeft_SetSCX:
+ ld a, [rLY]
cp l
- jr nz, Func_74152
+ jr nz, ScrollCreditsMonLeft_SetSCX
ld a, h
- ld [rSCX], a ; $ff43
-.asm_7415a
- ld a, [$ff44]
+ ld [rSCX], a
+.loop
+ ld a, [rLY]
cp h
- jr z, .asm_7415a
+ jr z, .loop
ret
-DataTable_74160: ; 74160 (1d:4160)
- db $C0,$D0,$E0,$F0
+HoFGBPalettes:
+ db %11000000
+ db %11010000
+ db %11100000
+ db %11110000
-Func_74164: ; 74164 (1d:4164)
+CreditsCopyTileMapToVRAM:
ld a, l
- ld [H_AUTOBGTRANSFERDEST], a ; $ffbc
+ ld [H_AUTOBGTRANSFERDEST], a
ld a, h
- ld [$ffbd], a
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERDEST + 1], a
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
jp Delay3
-Func_74171: ; 74171 (1d:4171)
- ld [hl], $0
+ZeroMemory:
+; zero bc bytes at hl
+ ld [hl], 0
inc hl
inc hl
dec bc
ld a, b
or c
- jr nz, Func_74171
+ jr nz, ZeroMemory
ret
-Func_7417b: ; 7417b (1d:417b)
- ld bc, $50
+FillFourRowsWithBlack:
+ ld bc, SCREEN_WIDTH * 4
ld a, $7e
jp FillMemory
-FillMiddleOfScreenWithWhite: ; 74183 (1d:4183)
- hlCoord 0, 4
- ld bc, $c8 ; 10 rows of 20 tiles each
- ld a, $7f ; blank white tile
+FillMiddleOfScreenWithWhite:
+ coord hl, 0, 4
+ ld bc, SCREEN_WIDTH * 10
+ ld a, " "
jp FillMemory
-Credits: ; 7418e (1d:418e)
- ld de, CreditsOrder ; $4243
+Credits:
+ ld de, CreditsOrder
push de
-.asm_74192
+.nextCreditsScreen
pop de
- hlCoord 9, 6
+ coord hl, 9, 6
push hl
call FillMiddleOfScreenWithWhite
pop hl
-.asm_7419b
+.nextCreditsCommand
ld a, [de]
inc de
push de
cp $ff
- jr z, .asm_741d5
+ jr z, .fadeInTextAndShowMon
cp $fe
- jr z, .asm_741dc
+ jr z, .showTextAndShowMon
cp $fd
- jr z, .asm_741e6
+ jr z, .fadeInText
cp $fc
- jr z, .asm_741ed
+ jr z, .showText
cp $fb
- jr z, .asm_741f4
+ jr z, .showCopyrightText
cp $fa
jr z, .showTheEnd
push hl
push hl
- ld hl, CreditsTextPointers ; $42c3
+ ld hl, CreditsTextPointers
add a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld e, [hl]
inc hl
@@ -199,53 +210,53 @@ Credits: ; 7418e (1d:418e)
add hl, bc
call PlaceString
pop hl
- ld bc, $28
+ ld bc, SCREEN_WIDTH * 2
add hl, bc
pop de
- jr .asm_7419b
-.asm_741d5
- call Func_740ba
- ld c, $5a
- jr .asm_741de
-.asm_741dc
- ld c, $6e
-.asm_741de
+ jr .nextCreditsCommand
+.fadeInTextAndShowMon
+ call FadeInCreditsText
+ ld c, 90
+ jr .next1
+.showTextAndShowMon
+ ld c, 110
+.next1
call DelayFrames
call DisplayCreditsMon
- jr .asm_74192
-.asm_741e6
- call Func_740ba
- ld c, $78
- jr .asm_741ef
-.asm_741ed
- ld c, $8c
-.asm_741ef
+ jr .nextCreditsScreen
+.fadeInText
+ call FadeInCreditsText
+ ld c, 120
+ jr .next2
+.showText
+ ld c, 140
+.next2
call DelayFrames
- jr .asm_74192
-.asm_741f4
+ jr .nextCreditsScreen
+.showCopyrightText
push de
callba LoadCopyrightTiles
pop de
pop de
- jr .asm_7419b
+ jr .nextCreditsCommand
.showTheEnd
- ld c, $10
+ ld c, 16
call DelayFrames
call FillMiddleOfScreenWithWhite
pop de
ld de, TheEndGfx
ld hl, vChars2 + $600
- ld bc, (BANK(TheEndGfx) << 8) + $0a
+ lb bc, BANK(TheEndGfx), (TheEndGfxEnd - TheEndGfx) / $10
call CopyVideoData
- hlCoord 4, 8
+ coord hl, 4, 8
ld de, TheEndTextString
call PlaceString
- hlCoord 4, 9
+ coord hl, 4, 9
inc de
call PlaceString
- jp Func_740ba
+ jp FadeInCreditsText
-TheEndTextString: ; 74229 (1d:4229)
+TheEndTextString:
; "T H E E N D"
db $60," ",$62," ",$64," ",$64," ",$66," ",$68,"@"
db $61," ",$63," ",$65," ",$65," ",$67," ",$69,"@"
@@ -254,5 +265,6 @@ INCLUDE "data/credits_order.asm"
INCLUDE "text/credits_text.asm"
-TheEndGfx: ; 7473e (1d:473e) ; 473E (473F on blue)
+TheEndGfx:
INCBIN "gfx/theend.interleave.2bpp"
+TheEndGfxEnd:
diff --git a/engine/add_mon.asm b/engine/add_mon.asm
new file mode 100644
index 00000000..19d03942
--- /dev/null
+++ b/engine/add_mon.asm
@@ -0,0 +1,512 @@
+_AddPartyMon:
+; Adds a new mon to the player's or enemy's party.
+; [wMonDataLocation] is used in an unusual way in this function.
+; If the lower nybble is 0, the mon is added to the player's party, else the enemy's.
+; If the entire value is 0, then the player is allowed to name the mon.
+ ld de, wPartyCount
+ ld a, [wMonDataLocation]
+ and $f
+ jr z, .next
+ ld de, wEnemyPartyCount
+.next
+ ld a, [de]
+ inc a
+ cp PARTY_LENGTH + 1
+ ret nc ; return if the party is already full
+ ld [de], a
+ ld a, [de]
+ ld [hNewPartyLength], a
+ add e
+ ld e, a
+ jr nc, .noCarry
+ inc d
+.noCarry
+ ld a, [wcf91]
+ ld [de], a ; write species of new mon in party list
+ inc de
+ ld a, $ff ; terminator
+ ld [de], a
+ ld hl, wPartyMonOT
+ ld a, [wMonDataLocation]
+ and $f
+ jr z, .next2
+ ld hl, wEnemyMonOT
+.next2
+ ld a, [hNewPartyLength]
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+ ld hl, wPlayerName
+ ld bc, NAME_LENGTH
+ call CopyData
+ ld a, [wMonDataLocation]
+ and a
+ jr nz, .skipNaming
+ ld hl, wPartyMonNicks
+ ld a, [hNewPartyLength]
+ dec a
+ call SkipFixedLengthTextEntries
+ ld a, NAME_MON_SCREEN
+ ld [wNamingScreenType], a
+ predef AskName
+.skipNaming
+ ld hl, wPartyMons
+ ld a, [wMonDataLocation]
+ and $f
+ jr z, .next3
+ ld hl, wEnemyMons
+.next3
+ ld a, [hNewPartyLength]
+ dec a
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld e, l
+ ld d, h
+ push hl
+ ld a, [wcf91]
+ ld [wd0b5], a
+ call GetMonHeader
+ ld hl, wMonHeader
+ ld a, [hli]
+ ld [de], a ; species
+ inc de
+ pop hl
+ push hl
+ ld a, [wMonDataLocation]
+ and $f
+ ld a, $98 ; set enemy trainer mon IVs to fixed average values
+ ld b, $88
+ jr nz, .next4
+
+; If the mon is being added to the player's party, update the pokedex.
+ ld a, [wcf91]
+ ld [wd11e], a
+ push de
+ predef IndexToPokedex
+ pop de
+ ld a, [wd11e]
+ dec a
+ ld c, a
+ ld b, FLAG_TEST
+ ld hl, wPokedexOwned
+ call FlagAction
+ ld a, c ; whether the mon was already flagged as owned
+ ld [wUnusedD153], a ; not read
+ ld a, [wd11e]
+ dec a
+ ld c, a
+ ld b, FLAG_SET
+ push bc
+ call FlagAction
+ pop bc
+ ld hl, wPokedexSeen
+ call FlagAction
+
+ pop hl
+ push hl
+
+ ld a, [wIsInBattle]
+ and a ; is this a wild mon caught in battle?
+ jr nz, .copyEnemyMonData
+
+; Not wild.
+ call Random ; generate random IVs
+ ld b, a
+ call Random
+
+.next4
+ push bc
+ ld bc, wPartyMon1DVs - wPartyMon1
+ add hl, bc
+ pop bc
+ ld [hli], a
+ ld [hl], b ; write IVs
+ ld bc, (wPartyMon1HPExp - 1) - (wPartyMon1DVs + 1)
+ add hl, bc
+ ld a, 1
+ ld c, a
+ xor a
+ ld b, a
+ call CalcStat ; calc HP stat (set cur Hp to max HP)
+ ld a, [H_MULTIPLICAND+1]
+ ld [de], a
+ inc de
+ ld a, [H_MULTIPLICAND+2]
+ ld [de], a
+ inc de
+ xor a
+ ld [de], a ; box level
+ inc de
+ ld [de], a ; status ailments
+ inc de
+ jr .copyMonTypesAndMoves
+.copyEnemyMonData
+ ld bc, wEnemyMon1DVs - wEnemyMon1
+ add hl, bc
+ ld a, [wEnemyMonDVs] ; copy IVs from cur enemy mon
+ ld [hli], a
+ ld a, [wEnemyMonDVs + 1]
+ ld [hl], a
+ ld a, [wEnemyMonHP] ; copy HP from cur enemy mon
+ ld [de], a
+ inc de
+ ld a, [wEnemyMonHP+1]
+ ld [de], a
+ inc de
+ xor a
+ ld [de], a ; box level
+ inc de
+ ld a, [wEnemyMonStatus] ; copy status ailments from cur enemy mon
+ ld [de], a
+ inc de
+.copyMonTypesAndMoves
+ ld hl, wMonHTypes
+ ld a, [hli] ; type 1
+ ld [de], a
+ inc de
+ ld a, [hli] ; type 2
+ ld [de], a
+ inc de
+ ld a, [hli] ; catch rate (held item in gen 2)
+ ld [de], a
+ ld hl, wMonHMoves
+ ld a, [hli]
+ inc de
+ push de
+ ld [de], a
+ ld a, [hli]
+ inc de
+ ld [de], a
+ ld a, [hli]
+ inc de
+ ld [de], a
+ ld a, [hli]
+ inc de
+ ld [de], a
+ push de
+ dec de
+ dec de
+ dec de
+ xor a
+ ld [wLearningMovesFromDayCare], a
+ predef WriteMonMoves
+ pop de
+ ld a, [wPlayerID] ; set trainer ID to player ID
+ inc de
+ ld [de], a
+ ld a, [wPlayerID + 1]
+ inc de
+ ld [de], a
+ push de
+ ld a, [wCurEnemyLVL]
+ ld d, a
+ callab CalcExperience
+ pop de
+ inc de
+ ld a, [hExperience] ; write experience
+ ld [de], a
+ inc de
+ ld a, [hExperience + 1]
+ ld [de], a
+ inc de
+ ld a, [hExperience + 2]
+ ld [de], a
+ xor a
+ ld b, NUM_STATS * 2
+.writeEVsLoop ; set all EVs to 0
+ inc de
+ ld [de], a
+ dec b
+ jr nz, .writeEVsLoop
+ inc de
+ inc de
+ pop hl
+ call AddPartyMon_WriteMovePP
+ inc de
+ ld a, [wCurEnemyLVL]
+ ld [de], a
+ inc de
+ ld a, [wIsInBattle]
+ dec a
+ jr nz, .calcFreshStats
+ ld hl, wEnemyMonMaxHP
+ ld bc, $a
+ call CopyData ; copy stats of cur enemy mon
+ pop hl
+ jr .done
+.calcFreshStats
+ pop hl
+ ld bc, wPartyMon1HPExp - 1 - wPartyMon1
+ add hl, bc
+ ld b, $0
+ call CalcStats ; calculate fresh set of stats
+.done
+ scf
+ ret
+
+LoadMovePPs:
+ call GetPredefRegisters
+ ; fallthrough
+AddPartyMon_WriteMovePP:
+ ld b, NUM_MOVES
+.pploop
+ ld a, [hli] ; read move ID
+ and a
+ jr z, .empty
+ dec a
+ push hl
+ push de
+ push bc
+ ld hl, Moves
+ ld bc, MoveEnd - Moves
+ call AddNTimes
+ ld de, wcd6d
+ ld a, BANK(Moves)
+ call FarCopyData
+ pop bc
+ pop de
+ pop hl
+ ld a, [wcd6d + 5] ; PP is byte 5 of move data
+.empty
+ inc de
+ ld [de], a
+ dec b
+ jr nz, .pploop ; there are still moves to read
+ ret
+
+; adds enemy mon [wcf91] (at position [wWhichPokemon] in enemy list) to own party
+; used in the cable club trade center
+_AddEnemyMonToPlayerParty:
+ ld hl, wPartyCount
+ ld a, [hl]
+ cp PARTY_LENGTH
+ scf
+ ret z ; party full, return failure
+ inc a
+ ld [hl], a ; add 1 to party members
+ ld c, a
+ ld b, $0
+ add hl, bc
+ ld a, [wcf91]
+ ld [hli], a ; add mon as last list entry
+ ld [hl], $ff ; write new sentinel
+ ld hl, wPartyMons
+ ld a, [wPartyCount]
+ dec a
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld e, l
+ ld d, h
+ ld hl, wLoadedMon
+ call CopyData ; write new mon's data (from wLoadedMon)
+ ld hl, wPartyMonOT
+ ld a, [wPartyCount]
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+ ld hl, wEnemyMonOT
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld bc, NAME_LENGTH
+ call CopyData ; write new mon's OT name (from an enemy mon)
+ ld hl, wPartyMonNicks
+ ld a, [wPartyCount]
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+ ld hl, wEnemyMonNicks
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld bc, NAME_LENGTH
+ call CopyData ; write new mon's nickname (from an enemy mon)
+ ld a, [wcf91]
+ ld [wd11e], a
+ predef IndexToPokedex
+ ld a, [wd11e]
+ dec a
+ ld c, a
+ ld b, FLAG_SET
+ ld hl, wPokedexOwned
+ push bc
+ call FlagAction ; add to owned pokemon
+ pop bc
+ ld hl, wPokedexSeen
+ call FlagAction ; add to seen pokemon
+ and a
+ ret ; return success
+
+_MoveMon:
+ ld a, [wMoveMonType]
+ and a
+ jr z, .checkPartyMonSlots
+ cp DAYCARE_TO_PARTY
+ jr z, .checkPartyMonSlots
+ cp PARTY_TO_DAYCARE
+ ld hl, wDayCareMon
+ jr z, .asm_f575
+ ld hl, wNumInBox
+ ld a, [hl]
+ cp MONS_PER_BOX
+ jr nz, .partyOrBoxNotFull
+ jr .boxFull
+.checkPartyMonSlots
+ ld hl, wPartyCount
+ ld a, [hl]
+ cp PARTY_LENGTH
+ jr nz, .partyOrBoxNotFull
+.boxFull
+ scf
+ ret
+.partyOrBoxNotFull
+ inc a
+ ld [hl], a ; increment number of mons in party/box
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [wMoveMonType]
+ cp DAYCARE_TO_PARTY
+ ld a, [wDayCareMon]
+ jr z, .asm_f556
+ ld a, [wcf91]
+.asm_f556
+ ld [hli], a ; write new mon ID
+ ld [hl], $ff ; write new sentinel
+ ld a, [wMoveMonType]
+ dec a
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1 ; $2c
+ ld a, [wPartyCount]
+ jr nz, .skipToNewMonEntry
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1 ; $21
+ ld a, [wNumInBox]
+.skipToNewMonEntry
+ dec a
+ call AddNTimes
+.asm_f575
+ push hl
+ ld e, l
+ ld d, h
+ ld a, [wMoveMonType]
+ and a
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1 ; $21
+ jr z, .asm_f591
+ cp DAYCARE_TO_PARTY
+ ld hl, wDayCareMon
+ jr z, .asm_f597
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1 ; $2c
+.asm_f591
+ ld a, [wWhichPokemon]
+ call AddNTimes
+.asm_f597
+ push hl
+ push de
+ ld bc, wBoxMon2 - wBoxMon1
+ call CopyData
+ pop de
+ pop hl
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f5b4
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f5b4
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc
+ ld a, [hl]
+ inc de
+ inc de
+ inc de
+ ld [de], a
+.asm_f5b4
+ ld a, [wMoveMonType]
+ cp PARTY_TO_DAYCARE
+ ld de, wDayCareMonOT
+ jr z, .asm_f5d3
+ dec a
+ ld hl, wPartyMonOT
+ ld a, [wPartyCount]
+ jr nz, .asm_f5cd
+ ld hl, wBoxMonOT
+ ld a, [wNumInBox]
+.asm_f5cd
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+.asm_f5d3
+ ld hl, wBoxMonOT
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f5e6
+ ld hl, wDayCareMonOT
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f5ec
+ ld hl, wPartyMonOT
+.asm_f5e6
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+.asm_f5ec
+ ld bc, NAME_LENGTH
+ call CopyData
+ ld a, [wMoveMonType]
+ cp PARTY_TO_DAYCARE
+ ld de, wDayCareMonName
+ jr z, .asm_f611
+ dec a
+ ld hl, wPartyMonNicks
+ ld a, [wPartyCount]
+ jr nz, .asm_f60b
+ ld hl, wBoxMonNicks
+ ld a, [wNumInBox]
+.asm_f60b
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+.asm_f611
+ ld hl, wBoxMonNicks
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f624
+ ld hl, wDayCareMonName
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f62a
+ ld hl, wPartyMonNicks
+.asm_f624
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+.asm_f62a
+ ld bc, NAME_LENGTH
+ call CopyData
+ pop hl
+ ld a, [wMoveMonType]
+ cp PARTY_TO_BOX
+ jr z, .asm_f664
+ cp PARTY_TO_DAYCARE
+ jr z, .asm_f664
+ push hl
+ srl a
+ add $2
+ ld [wMonDataLocation], a
+ call LoadMonData
+ callba CalcLevelFromExperience
+ ld a, d
+ ld [wCurEnemyLVL], a
+ pop hl
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc
+ ld [hli], a
+ ld d, h
+ ld e, l
+ ld bc, -18
+ add hl, bc
+ ld b, $1
+ call CalcStats
+.asm_f664
+ and a
+ ret
diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm
index dc08e0e1..373136a8 100755
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -1,21 +1,21 @@
; Draws a "frame block". Frame blocks are blocks of tiles that are put
; together to form frames in battle animations.
-DrawFrameBlock: ; 78000 (1e:4000)
+DrawFrameBlock:
ld l,c
ld h,b
ld a,[hli]
- ld [W_NUMFBTILES],a
- ld a,[W_FBDESTADDR + 1]
+ ld [wNumFBTiles],a
+ ld a,[wFBDestAddr + 1]
ld e,a
- ld a,[W_FBDESTADDR]
+ ld a,[wFBDestAddr]
ld d,a
xor a
- ld [W_FBTILECOUNTER],a ; loop counter
+ ld [wFBTileCounter],a ; loop counter
.loop
- ld a,[W_FBTILECOUNTER]
+ ld a,[wFBTileCounter]
inc a
- ld [W_FBTILECOUNTER],a
- ld a,[W_SUBANIMTRANSFORM]
+ ld [wFBTileCounter],a
+ ld a,[wSubAnimTransform]
dec a
jr z,.flipHorizontalAndVertical ; 1
dec a
@@ -23,15 +23,15 @@ DrawFrameBlock: ; 78000 (1e:4000)
dec a
jr z,.flipBaseCoords ; 3
.noTransformation
- ld a,[W_BASECOORDY]
+ ld a,[wBaseCoordY]
add [hl]
ld [de],a ; store Y
inc hl
inc de
- ld a,[W_BASECOORDX]
+ ld a,[wBaseCoordX]
jr .finishCopying
.flipBaseCoords
- ld a,[W_BASECOORDY]
+ ld a,[wBaseCoordY]
ld b,a
ld a,136
sub b ; flip Y base coordinate
@@ -39,11 +39,11 @@ DrawFrameBlock: ; 78000 (1e:4000)
ld [de],a ; store Y
inc hl
inc de
- ld a,[W_BASECOORDX]
+ ld a,[wBaseCoordX]
ld b,a
ld a,168
sub b ; flip X base coordinate
-.finishCopying ; finish copying values to OAM (when [W_SUBANIMTRANSFORM] not 1 or 2)
+.finishCopying ; finish copying values to OAM (when [wSubAnimTransform] not 1 or 2)
add [hl] ; X offset
ld [de],a ; store X
inc hl
@@ -57,7 +57,7 @@ DrawFrameBlock: ; 78000 (1e:4000)
inc de
jp .nextTile
.flipHorizontalAndVertical
- ld a,[W_BASECOORDY]
+ ld a,[wBaseCoordY]
add [hl] ; Y offset
ld b,a
ld a,136
@@ -65,7 +65,7 @@ DrawFrameBlock: ; 78000 (1e:4000)
ld [de],a ; store Y
inc hl
inc de
- ld a,[W_BASECOORDX]
+ ld a,[wBaseCoordX]
add [hl] ; X offset
ld b,a
ld a,168
@@ -95,13 +95,13 @@ DrawFrameBlock: ; 78000 (1e:4000)
inc de
jp .nextTile
.flipHorizontalTranslateDown
- ld a,[W_BASECOORDY]
+ ld a,[wBaseCoordY]
add [hl]
add a,40 ; translate Y coordinate downwards
ld [de],a ; store Y
inc hl
inc de
- ld a,[W_BASECOORDX]
+ ld a,[wBaseCoordX]
add [hl]
ld b,a
ld a,168
@@ -125,52 +125,52 @@ DrawFrameBlock: ; 78000 (1e:4000)
ld [de],a
inc de
.nextTile
- ld a,[W_FBTILECOUNTER]
+ ld a,[wFBTileCounter]
ld c,a
- ld a,[W_NUMFBTILES]
+ ld a,[wNumFBTiles]
cp c
jp nz,.loop ; go back up if there are more tiles to draw
.afterDrawingTiles
- ld a,[W_FBMODE]
+ ld a,[wFBMode]
cp a,2
jr z,.advanceFrameBlockDestAddr; skip delay and don't clean OAM buffer
- ld a,[W_SUBANIMFRAMEDELAY]
+ ld a,[wSubAnimFrameDelay]
ld c,a
call DelayFrames
- ld a,[W_FBMODE]
+ ld a,[wFBMode]
cp a,3
jr z,.advanceFrameBlockDestAddr ; skip cleaning OAM buffer
cp a,4
jr z,.done ; skip cleaning OAM buffer and don't advance the frame block destination address
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
cp a,GROWL
jr z,.resetFrameBlockDestAddr
call AnimationCleanOAM
.resetFrameBlockDestAddr
ld hl,wOAMBuffer ; OAM buffer
ld a,l
- ld [W_FBDESTADDR + 1],a
+ ld [wFBDestAddr + 1],a
ld a,h
- ld [W_FBDESTADDR],a ; set destination address to beginning of OAM buffer
+ ld [wFBDestAddr],a ; set destination address to beginning of OAM buffer
ret
.advanceFrameBlockDestAddr
ld a,e
- ld [W_FBDESTADDR + 1],a
+ ld [wFBDestAddr + 1],a
ld a,d
- ld [W_FBDESTADDR],a
+ ld [wFBDestAddr],a
.done
ret
-PlayAnimation: ; 780f1 (1e:40f1)
+PlayAnimation:
xor a
- ld [$FF8B],a
- ld [W_SUBANIMTRANSFORM],a
- ld a,[W_ANIMATIONID] ; get animation number
+ ld [$FF8B],a ; it looks like nothing reads this
+ ld [wSubAnimTransform],a
+ ld a,[wAnimationID] ; get animation number
dec a
ld l,a
ld h,0
add hl,hl
- ld de,AttackAnimationPointers ; $607d ; animation command stream pointers
+ ld de,AttackAnimationPointers ; animation command stream pointers
add hl,de
ld a,[hli]
ld h,[hl]
@@ -199,7 +199,7 @@ PlayAnimation: ; 780f1 (1e:40f1)
ld [wAnimSoundID],a ; store sound
push hl
push de
- call Func_7986f
+ call GetMoveSound
call PlaySound
pop de
pop hl
@@ -217,13 +217,13 @@ PlayAnimation: ; 780f1 (1e:40f1)
.playSubanimation
ld c,a
and a,%00111111
- ld [W_SUBANIMFRAMEDELAY],a
+ ld [wSubAnimFrameDelay],a
xor a
sla c
rla
sla c
rla
- ld [wd09f],a ; tile select
+ ld [wWhichBattleAnimTileset],a
ld a,[hli] ; sound
ld [wAnimSoundID],a ; store sound
ld a,[hli] ; subanimation ID
@@ -235,15 +235,15 @@ PlayAnimation: ; 780f1 (1e:40f1)
ld de,SubanimationPointers
add hl,de
ld a,l
- ld [W_SUBANIMADDRPTR],a
+ ld [wSubAnimAddrPtr],a
ld a,h
- ld [W_SUBANIMADDRPTR + 1],a
+ ld [wSubAnimAddrPtr + 1],a
ld l,c
ld h,b
push hl
ld a,[rOBP0]
push af
- ld a,[wcc79]
+ ld a,[wAnimPalette]
ld [rOBP0],a
call LoadAnimationTileset
call LoadSubanimation
@@ -253,13 +253,13 @@ PlayAnimation: ; 780f1 (1e:40f1)
.nextAnimationCommand
pop hl
jr .animationLoop
-.AnimationOver ; 417B
+.AnimationOver
ret
-LoadSubanimation: ; 7817c (1e:417c)
- ld a,[W_SUBANIMADDRPTR + 1]
+LoadSubanimation:
+ ld a,[wSubAnimAddrPtr + 1]
ld h,a
- ld a,[W_SUBANIMADDRPTR]
+ ld a,[wSubAnimAddrPtr]
ld l,a
ld a,[hli]
ld e,a
@@ -268,7 +268,7 @@ LoadSubanimation: ; 7817c (1e:417c)
ld a,[de]
ld b,a
and a,31
- ld [W_SUBANIMCOUNTER],a ; number of frame blocks
+ ld [wSubAnimCounter],a ; number of frame blocks
ld a,b
and a,%11100000
cp a,5 << 5 ; is subanimation type 5?
@@ -282,12 +282,12 @@ LoadSubanimation: ; 7817c (1e:417c)
; place the upper 3 bits of a into bits 0-2 of a before storing
srl a
swap a
- ld [W_SUBANIMTRANSFORM],a
+ ld [wSubAnimTransform],a
cp a,4 ; is the animation reversed?
ld hl,0
jr nz,.storeSubentryAddr
; if the animation is reversed, then place the initial subentry address at the end of the list of subentries
- ld a,[W_SUBANIMCOUNTER]
+ ld a,[wSubAnimCounter]
dec a
ld bc,3
.loop
@@ -298,15 +298,15 @@ LoadSubanimation: ; 7817c (1e:417c)
inc de
add hl,de
ld a,l
- ld [W_SUBANIMSUBENTRYADDR],a
+ ld [wSubAnimSubEntryAddr],a
ld a,h
- ld [W_SUBANIMSUBENTRYADDR + 1],a
+ ld [wSubAnimSubEntryAddr + 1],a
ret
; called if the subanimation type is not 5
; sets the transform to 0 (i.e. no transform) if it's the player's turn
; sets the transform to the subanimation type if it's the enemy's turn
-GetSubanimationTransform1: ; 781c2 (1e:41c2)
+GetSubanimationTransform1:
ld b,a
ld a,[H_WHOSETURN]
and a
@@ -318,7 +318,7 @@ GetSubanimationTransform1: ; 781c2 (1e:41c2)
; called if the subanimation type is 5
; sets the transform to 2 (i.e. horizontal and vertical flip) if it's the player's turn
; sets the transform to 0 (i.e. no transform) if it's the enemy's turn
-GetSubanimationTransform2: ; 781ca (1e:41ca)
+GetSubanimationTransform2:
ld a,[H_WHOSETURN]
and a
ld a,2 << 5
@@ -327,8 +327,8 @@ GetSubanimationTransform2: ; 781ca (1e:41ca)
ret
; loads tile patterns for battle animations
-LoadAnimationTileset: ; 781d2 (1e:41d2)
- ld a,[wd09f] ; tileset select
+LoadAnimationTileset:
+ ld a,[wWhichBattleAnimTileset]
add a
add a
ld hl,AnimationTilesetPointers
@@ -336,18 +336,18 @@ LoadAnimationTileset: ; 781d2 (1e:41d2)
ld d,0
add hl,de
ld a,[hli]
- ld [wd07d],a ; number of tiles
+ ld [wTempTilesetNumTiles],a ; number of tiles
ld a,[hli]
ld e,a
ld a,[hl]
ld d,a ; de = address of tileset
ld hl,vSprites + $310
ld b, BANK(AnimationTileset1) ; ROM bank
- ld a,[wd07d]
+ ld a,[wTempTilesetNumTiles]
ld c,a ; number of tiles
jp CopyVideoData ; load tileset
-AnimationTilesetPointers: ; 781f2 (1e:41f2)
+AnimationTilesetPointers:
db 79 ; number of tiles
dw AnimationTileset1
db $FF
@@ -360,60 +360,57 @@ AnimationTilesetPointers: ; 781f2 (1e:41f2)
dw AnimationTileset1
db $FF
-AnimationTileset1: ; 781fe (1e:41fe)
+AnimationTileset1:
INCBIN "gfx/attack_anim_1.2bpp"
-AnimationTileset2: ; 786ee (1e:46ee)
+AnimationTileset2:
INCBIN "gfx/attack_anim_2.2bpp"
-SlotMachineTiles2: ; 78bde (1e:4bde)
+SlotMachineTiles2:
IF DEF(_RED)
INCBIN "gfx/red/slotmachine2.2bpp"
ENDC
IF DEF(_BLUE)
INCBIN "gfx/blue/slotmachine2.2bpp"
ENDC
-IF DEF(_YELLOW)
- INCBIN "gfx/yellow/slotmachine2.2bpp"
-ENDC
-MoveAnimation: ; 78d5e (1e:4d5e)
+MoveAnimation:
push hl
push de
push bc
push af
call WaitForSoundToFinish
- call Func_78e23
- ld a,[W_ANIMATIONID]
+ call SetAnimationPalette
+ ld a,[wAnimationID]
and a
- jr z,.AnimationFinished
+ jr z, .animationFinished
; if throwing a Poké Ball, skip the regular animation code
cp a,TOSS_ANIM
- jr nz,.MoveAnimation
- ld de,.AnimationFinished
+ jr nz, .moveAnimation
+ ld de, .animationFinished
push de
jp TossBallAnimation
-.MoveAnimation
+.moveAnimation
; check if battle animations are disabled in the options
- ld a,[W_OPTIONS]
+ ld a,[wOptions]
bit 7,a
- jr nz,.AnimationsDisabled
+ jr nz, .animationsDisabled
call ShareMoveAnimations
call PlayAnimation
jr .next4
-.AnimationsDisabled
+.animationsDisabled
ld c,30
call DelayFrames
.next4
call PlayApplyingAttackAnimation ; shake the screen or flash the pic in and out (to show damage)
-.AnimationFinished
+.animationFinished
call WaitForSoundToFinish
xor a
- ld [W_SUBANIMSUBENTRYADDR],a
- ld [wd09b],a
- ld [W_SUBANIMTRANSFORM],a
+ ld [wSubAnimSubEntryAddr],a
+ ld [wUnusedD09B],a
+ ld [wSubAnimTransform],a
dec a
ld [wAnimSoundID],a
pop af
@@ -422,7 +419,7 @@ MoveAnimation: ; 78d5e (1e:4d5e)
pop hl
ret
-ShareMoveAnimations: ; 78da6 (1e:4da6)
+ShareMoveAnimations:
; some moves just reuse animations from status conditions
ld a,[H_WHOSETURN]
and a
@@ -430,22 +427,22 @@ ShareMoveAnimations: ; 78da6 (1e:4da6)
; opponent’s turn
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
cp a,AMNESIA
ld b,CONF_ANIM
- jr z,.Replace
+ jr z, .replaceAnim
cp a,REST
ld b,SLP_ANIM
ret nz
-.Replace
+.replaceAnim
ld a,b
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
ret
-PlayApplyingAttackAnimation: ; 78dbd (1e:4dbd)
+PlayApplyingAttackAnimation:
; Generic animation that shows after the move's individual animation
; Different animation depending on whether the move has an additional effect and on whose turn it is
ld a,[wAnimationType]
@@ -462,7 +459,7 @@ PlayApplyingAttackAnimation: ; 78dbd (1e:4dbd)
ld l,a
jp [hl]
-AnimationTypePointerTable: ; 78dcf (1e:4dcf)
+AnimationTypePointerTable:
dw ShakeScreenVertically ; enemy mon has used a damaging move without a side effect
dw ShakeScreenHorizontallyHeavy ; enemy mon has used a damaging move with a side effect
dw ShakeScreenHorizontallySlow ; enemy mon has used a non-damaging move
@@ -470,100 +467,100 @@ AnimationTypePointerTable: ; 78dcf (1e:4dcf)
dw ShakeScreenHorizontallyLight ; player mon has used a damaging move with a side effect
dw ShakeScreenHorizontallySlow2 ; player mon has used a non-damaging move
-ShakeScreenVertically: ; 78ddb (1e:4ddb)
+ShakeScreenVertically:
call PlayApplyingAttackSound
- ld b, $8
+ ld b, 8
jp AnimationShakeScreenVertically
-ShakeScreenHorizontallyHeavy: ; 78de3 (1e:4de3)
+ShakeScreenHorizontallyHeavy:
call PlayApplyingAttackSound
- ld b, $8
+ ld b, 8
jp AnimationShakeScreenHorizontallyFast
-ShakeScreenHorizontallySlow: ; 78deb (1e:4deb)
- ld bc, $602
+ShakeScreenHorizontallySlow:
+ lb bc, 6, 2
jr AnimationShakeScreenHorizontallySlow
-BlinkEnemyMonSprite: ; 78df0 (1e:4df0)
+BlinkEnemyMonSprite:
call PlayApplyingAttackSound
jp AnimationBlinkEnemyMon
-ShakeScreenHorizontallyLight: ; 78df6 (1e:4df6)
+ShakeScreenHorizontallyLight:
call PlayApplyingAttackSound
- ld b, $2
+ ld b, 2
jp AnimationShakeScreenHorizontallyFast
-ShakeScreenHorizontallySlow2: ; 78dfe (1e:4dfe)
- ld bc, $302
+ShakeScreenHorizontallySlow2:
+ lb bc, 3, 2
-AnimationShakeScreenHorizontallySlow: ; 78e01 (1e:4e01)
+AnimationShakeScreenHorizontallySlow:
push bc
push bc
-.asm_78e03
- ld a, [rWX] ; $ff4b
+.loop1
+ ld a, [rWX]
inc a
- ld [rWX], a ; $ff4b
- ld c, $2
+ ld [rWX], a
+ ld c, 2
call DelayFrames
dec b
- jr nz, .asm_78e03
+ jr nz, .loop1
pop bc
-.asm_78e11
- ld a, [rWX] ; $ff4b
+.loop2
+ ld a, [rWX]
dec a
- ld [rWX], a ; $ff4b
- ld c, $2
+ ld [rWX], a
+ ld c, 2
call DelayFrames
dec b
- jr nz, .asm_78e11
+ jr nz, .loop2
pop bc
dec c
jr nz, AnimationShakeScreenHorizontallySlow
ret
-Func_78e23: ; 78e23 (1e:4e23)
+SetAnimationPalette:
ld a, [wOnSGB]
and a
ld a, $e4
- jr z, .asm_78e47
+ jr z, .notSGB
ld a, $f0
- ld [wcc79], a
+ ld [wAnimPalette], a
ld b, $e4
- ld a, [W_ANIMATIONID] ; W_ANIMATIONID
+ ld a, [wAnimationID]
cp TRADE_BALL_DROP_ANIM
- jr c, .asm_78e3f
+ jr c, .next
cp TRADE_BALL_POOF_ANIM + 1
- jr nc, .asm_78e3f
+ jr nc, .next
ld b, $f0
-.asm_78e3f
+.next
ld a, b
- ld [rOBP0], a ; $ff48
+ ld [rOBP0], a
ld a, $6c
- ld [rOBP1], a ; $ff49
+ ld [rOBP1], a
ret
-.asm_78e47
+.notSGB
ld a, $e4
- ld [wcc79], a
- ld [rOBP0], a ; $ff48
+ ld [wAnimPalette], a
+ ld [rOBP0], a
ld a, $6c
- ld [rOBP1], a ; $ff49
+ ld [rOBP1], a
ret
-PlaySubanimation: ; 78e53 (1e:4e53)
+PlaySubanimation:
ld a,[wAnimSoundID]
cp a,$FF
jr z,.skipPlayingSound
- call Func_7986f
- call PlaySound ; play sound effect
+ call GetMoveSound
+ call PlaySound
.skipPlayingSound
ld hl,wOAMBuffer ; base address of OAM buffer
ld a,l
- ld [W_FBDESTADDR + 1],a
+ ld [wFBDestAddr + 1],a
ld a,h
- ld [W_FBDESTADDR],a
- ld a,[W_SUBANIMSUBENTRYADDR + 1]
+ ld [wFBDestAddr],a
+ ld a,[wSubAnimSubEntryAddr + 1]
ld h,a
- ld a,[W_SUBANIMSUBENTRYADDR]
+ ld a,[wSubAnimSubEntryAddr]
ld l,a
.loop
push hl
@@ -581,28 +578,28 @@ PlaySubanimation: ; 78e53 (1e:4e53)
push hl
ld e,[hl] ; base coordinate ID
ld d,0
- ld hl,FrameBlockBaseCoords ; $7c85 ; base coordinate table
+ ld hl,FrameBlockBaseCoords ; base coordinate table
add hl,de
add hl,de
ld a,[hli]
- ld [W_BASECOORDY],a
+ ld [wBaseCoordY],a
ld a,[hl]
- ld [W_BASECOORDX],a
+ ld [wBaseCoordX],a
pop hl
inc hl
ld a,[hl] ; frame block mode
- ld [W_FBMODE],a
+ ld [wFBMode],a
call DrawFrameBlock
call DoSpecialEffectByAnimationId ; run animation-specific function (if there is one)
- ld a,[W_SUBANIMCOUNTER]
+ ld a,[wSubAnimCounter]
dec a
- ld [W_SUBANIMCOUNTER],a
+ ld [wSubAnimCounter],a
ret z
- ld a,[W_SUBANIMSUBENTRYADDR + 1]
+ ld a,[wSubAnimSubEntryAddr + 1]
ld h,a
- ld a,[W_SUBANIMSUBENTRYADDR]
+ ld a,[wSubAnimSubEntryAddr]
ld l,a
- ld a,[W_SUBANIMTRANSFORM]
+ ld a,[wSubAnimTransform]
cp a,4 ; is the animation reversed?
ld bc,3
jr nz,.nextSubanimationSubentry
@@ -610,12 +607,12 @@ PlaySubanimation: ; 78e53 (1e:4e53)
.nextSubanimationSubentry
add hl,bc
ld a,h
- ld [W_SUBANIMSUBENTRYADDR + 1],a
+ ld [wSubAnimSubEntryAddr + 1],a
ld a,l
- ld [W_SUBANIMSUBENTRYADDR],a
+ ld [wSubAnimSubEntryAddr],a
jp .loop
-AnimationCleanOAM: ; 78ec8 (1e:4ec8)
+AnimationCleanOAM:
push hl
push de
push bc
@@ -630,11 +627,11 @@ AnimationCleanOAM: ; 78ec8 (1e:4ec8)
; this runs after each frame block is drawn in a subanimation
; it runs a particular special effect based on the animation ID
-DoSpecialEffectByAnimationId: ; 78ed7 (1e:4ed7)
+DoSpecialEffectByAnimationId:
push hl
push de
push bc
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
ld hl,AnimationIdSpecialEffects
ld de,3
call IsInArray
@@ -653,7 +650,7 @@ DoSpecialEffectByAnimationId: ; 78ed7 (1e:4ed7)
ret
; Format: Animation ID (1 byte), Address (2 bytes)
-AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5)
+AnimationIdSpecialEffects:
db MEGA_PUNCH
dw AnimationFlashScreen
@@ -667,7 +664,7 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5)
dw AnimationFlashScreen
db TAIL_WHIP
- dw Func_790d0
+ dw TailWhipAnimationUnused
db GROWL
dw DoGrowlSpecialEffects
@@ -703,13 +700,13 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5)
dw DoRockSlideSpecialEffects
db TRADE_BALL_DROP_ANIM
- dw Func_79041
+ dw TradeHidePokemon
db TRADE_BALL_SHAKE_ANIM
- dw Func_7904c
+ dw TradeShakePokeball
db TRADE_BALL_TILT_ANIM
- dw Func_7907c
+ dw TradeJumpPokeball
db TOSS_ANIM
dw DoBallTossSpecialEffects
@@ -728,7 +725,7 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5)
db $FF ; terminator
-DoBallTossSpecialEffects: ; 78f3e (1e:4f3e)
+DoBallTossSpecialEffects:
ld a,[wcf91]
cp a,3 ; is it a Master Ball or Ultra Ball?
jr nc,.skipFlashingEffect
@@ -737,21 +734,21 @@ DoBallTossSpecialEffects: ; 78f3e (1e:4f3e)
xor a,%00111100 ; complement colors 1 and 2
ld [rOBP0],a
.skipFlashingEffect
- ld a,[W_SUBANIMCOUNTER]
+ ld a,[wSubAnimCounter]
cp a,11 ; is it the beginning of the subanimation?
jr nz,.skipPlayingSound
; if it is the beginning of the subanimation, play a sound
- ld a,(SFX_08_41 - SFX_Headers_08) / 3
- call PlaySound ; play sound
+ ld a,SFX_BALL_TOSS
+ call PlaySound
.skipPlayingSound
- ld a,[W_ISINBATTLE]
+ ld a,[wIsInBattle]
cp a,02 ; is it a trainer battle?
jr z,.isTrainerBattle
ld a,[wd11e]
cp a,$10 ; is the enemy pokemon the Ghost Marowak?
ret nz
; if the enemy pokemon is the Ghost Marowak, make it dodge during the last 3 frames
- ld a,[W_SUBANIMCOUNTER]
+ ld a,[wSubAnimCounter]
cp a,3
jr z,.moveGhostMarowakLeft
cp a,2
@@ -759,72 +756,72 @@ DoBallTossSpecialEffects: ; 78f3e (1e:4f3e)
cp a,1
ret nz
.moveGhostMarowakLeft
- hlCoord 17, 0
+ coord hl, 17, 0
ld de,20
- ld bc,$0707 ; 7 rows and 7 columns
+ lb bc, 7, 7
.loop
push hl
push bc
- call Func_79862 ; move row of tiles left
+ call AnimCopyRowRight ; move row of tiles left
pop bc
pop hl
add hl,de
dec b
jr nz,.loop
ld a,%00001000
- ld [$ff10],a ; Channel 1 sweep register
+ ld [rNR10],a ; Channel 1 sweep register
ret
.isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame
- ld a,[W_SUBANIMCOUNTER]
+ ld a,[wSubAnimCounter]
cp a,3
ret nz
dec a
- ld [W_SUBANIMCOUNTER],a
+ ld [wSubAnimCounter],a
ret
-DoBallShakeSpecialEffects: ; 78f96 (1e:4f96)
- ld a,[W_SUBANIMCOUNTER]
+DoBallShakeSpecialEffects:
+ ld a,[wSubAnimCounter]
cp a,4 ; is it the beginning of a shake?
jr nz,.skipPlayingSound
; if it is the beginning of a shake, play a sound and wait 2/3 of a second
- ld a,(SFX_08_3c - SFX_Headers_08) / 3
- call PlaySound ; play sound
+ ld a,SFX_TINK
+ call PlaySound
ld c,40
call DelayFrames
.skipPlayingSound
- ld a,[W_SUBANIMCOUNTER]
+ ld a,[wSubAnimCounter]
dec a
ret nz
; if it's the end of the ball shaking subanimation, check if more shakes are left and restart the subanimation
- ld a,[wWhichTrade] ; number of shakes
+ ld a,[wNumShakes] ; number of shakes
dec a ; decrement number of shakes
- ld [wWhichTrade],a
+ ld [wNumShakes],a
ret z
; if there are shakes left, restart the subanimation
- ld a,[W_SUBANIMSUBENTRYADDR]
+ ld a,[wSubAnimSubEntryAddr]
ld l,a
- ld a,[W_SUBANIMSUBENTRYADDR + 1]
+ ld a,[wSubAnimSubEntryAddr + 1]
ld h,a
ld de,-(4 * 3) ; 4 subentries and 3 bytes per subentry
add hl,de
ld a,l
- ld [W_SUBANIMSUBENTRYADDR],a
+ ld [wSubAnimSubEntryAddr],a
ld a,h
- ld [W_SUBANIMSUBENTRYADDR + 1],a
+ ld [wSubAnimSubEntryAddr + 1],a
ld a,5 ; number of subentries in the ball shaking subanimation plus one
- ld [W_SUBANIMCOUNTER],a
+ ld [wSubAnimCounter],a
ret
; plays a sound after the second frame of the poof animation
-DoPoofSpecialEffects: ; 78fce (1e:4fce)
- ld a,[W_SUBANIMCOUNTER]
+DoPoofSpecialEffects:
+ ld a,[wSubAnimCounter]
cp a,5
ret nz
- ld a,(SFX_08_42 - SFX_Headers_08) / 3
+ ld a,SFX_BALL_POOF
jp PlaySound
-DoRockSlideSpecialEffects: ; 78fd9 (1e:4fd9)
- ld a,[W_SUBANIMCOUNTER]
+DoRockSlideSpecialEffects:
+ ld a,[wSubAnimCounter]
cp a,12
ret nc
cp a,8
@@ -835,35 +832,35 @@ DoRockSlideSpecialEffects: ; 78fd9 (1e:4fd9)
; if the subaninmation counter is between 8 and 11, shake the screen horizontally and vertically
.shakeScreen
ld b,1
- predef Func_48125 ; shake horizontally
+ predef PredefShakeScreenHorizontally ; shake horizontally
ld b,1
- predef_jump Func_480ff ; shake vertically
+ predef_jump PredefShakeScreenVertically ; shake vertically
-FlashScreenEveryEightFrameBlocks: ; 78ff7 (1e:4ff7)
- ld a,[W_SUBANIMCOUNTER]
+FlashScreenEveryEightFrameBlocks:
+ ld a,[wSubAnimCounter]
and a,7 ; is the subanimation counter exactly 8?
call z,AnimationFlashScreen ; if so, flash the screen
ret
; flashes the screen if the subanimation counter is divisible by 4
-FlashScreenEveryFourFrameBlocks: ; 79000 (1e:5000)
- ld a,[W_SUBANIMCOUNTER]
+FlashScreenEveryFourFrameBlocks:
+ ld a,[wSubAnimCounter]
and a,3
call z,AnimationFlashScreen
ret
; used for Explosion and Selfdestruct
-DoExplodeSpecialEffects: ; 79009 (1e:5009)
- ld a,[W_SUBANIMCOUNTER]
+DoExplodeSpecialEffects:
+ ld a,[wSubAnimCounter]
cp a,1 ; is it the end of the subanimation?
jr nz,FlashScreenEveryFourFrameBlocks
; if it's the end of the subanimation, make the attacking pokemon disappear
- hlCoord 1, 5
+ coord hl, 1, 5
jp AnimationHideMonPic ; make pokemon disappear
; flashes the screen when subanimation counter is 1 modulo 4
-DoBlizzardSpecialEffects: ; 79016 (1e:5016)
- ld a,[W_SUBANIMCOUNTER]
+DoBlizzardSpecialEffects:
+ ld a,[wSubAnimCounter]
cp a,13
jp z,AnimationFlashScreen
cp a,9
@@ -875,9 +872,9 @@ DoBlizzardSpecialEffects: ; 79016 (1e:5016)
ret
; flashes the screen at 3 points in the subanimation
-; XXX is this unused?
-Func_7902e: ; 7902e (1e:502e)
- ld a,[W_SUBANIMCOUNTER]
+; unused
+FlashScreenUnused:
+ ld a,[wSubAnimCounter]
cp a,14
jp z,AnimationFlashScreen
cp a,9
@@ -887,18 +884,16 @@ Func_7902e: ; 7902e (1e:502e)
ret
; function to make the pokemon disappear at the beginning of the animation
-; XXX probably a trade-related animation
-Func_79041: ; 79041 (1e:5041)
- ld a,[W_SUBANIMCOUNTER]
+TradeHidePokemon:
+ ld a,[wSubAnimCounter]
cp a,6
ret nz
- ld a,$2F
- jp Func_7980c ; make pokemon disappear
+ ld a,2 * SCREEN_WIDTH + 7
+ jp ClearMonPicFromTileMap ; make pokemon disappear
; function to make a shaking pokeball jump up at the end of the animation
-; XXX probably a trade-related animation
-Func_7904c: ; 7904c (1e:504c)
- ld a,[W_SUBANIMCOUNTER]
+TradeShakePokeball:
+ ld a,[wSubAnimCounter]
cp a,1
ret nz
; if it's the end of the animation, make the ball jump up
@@ -923,16 +918,15 @@ Func_7904c: ; 7904c (1e:504c)
jr .loop
.done
call AnimationCleanOAM
- ld a,(SFX_02_44 - SFX_Headers_02) / 3
- jp PlaySound ; play sound
+ ld a,SFX_TRADE_MACHINE
+ jp PlaySound
-BallMoveDistances1: ; 79078 (1e:5078)
+BallMoveDistances1:
db -12,-12,-8
db $ff ; terminator
; function to make the pokeball jump up
-; XXX probably a trade-related animation
-Func_7907c ; 507C
+TradeJumpPokeball:
ld de,BallMoveDistances2
.loop
ld hl,wOAMBuffer ; OAM buffer
@@ -955,7 +949,7 @@ Func_7907c ; 507C
cp a,$ff
jr nz,.skipPlayingSound
.playSound ; play sound if next move distance is 12 or this is the last one
- ld a,(SFX_08_58 - SFX_Headers_08) / 3
+ ld a,SFX_BATTLE_18
call PlaySound
.skipPlayingSound
push bc
@@ -968,31 +962,31 @@ Func_7907c ; 507C
pop de
jr .loop
-BallMoveDistances2: ; 790b3 (1e:50b3)
+BallMoveDistances2:
db 11,12,-12,-7,7,12,-8,8
db $ff ; terminator
; this function copies the current musical note graphic
; so that there are two musical notes flying towards the defending pokemon
-DoGrowlSpecialEffects: ; 790bc (1e:50bc)
+DoGrowlSpecialEffects:
ld hl,wOAMBuffer ; OAM buffer
ld de,wOAMBuffer + $10
ld bc,$10
call CopyData ; copy the musical note graphic
- ld a,[W_SUBANIMCOUNTER]
+ ld a,[wSubAnimCounter]
dec a
call z,AnimationCleanOAM ; clean up at the end of the subanimation
ret
; this is associated with Tail Whip, but Tail Whip doesn't use any subanimations
-Func_790d0: ; 790d0 (1e:50d0)
+TailWhipAnimationUnused:
ld a,1
- ld [W_SUBANIMCOUNTER],a
+ ld [wSubAnimCounter],a
ld c,20
jp DelayFrames
; Format: Special Effect ID (1 byte), Address (2 bytes)
-SpecialEffectPointers: ; 790da (1e:50da)
+SpecialEffectPointers:
db SE_DARK_SCREEN_FLASH ; $FE
dw AnimationFlashScreen
db SE_DARK_SCREEN_PALETTE ; $FD
@@ -1013,8 +1007,8 @@ SpecialEffectPointers: ; 790da (1e:50da)
dw AnimationSlideMonDown
db SE_FLASH_MON_PIC ; $F5
dw AnimationFlashMonPic
- db SE_SLIDE_MON_OUT ; $F4
- dw AnimationSlideMonOut
+ db SE_SLIDE_MON_OFF ; $F4
+ dw AnimationSlideMonOff
db SE_BLINK_MON ; $F3
dw AnimationBlinkMon
db SE_MOVE_MON_HORIZONTALLY ; $F2
@@ -1043,8 +1037,8 @@ SpecialEffectPointers: ; 790da (1e:50da)
dw AnimationLeavesFalling
db SE_PETALS_FALLING ; $E6
dw AnimationPetalsFalling
- db SE_SLIDE_MON_HALF_LEFT ; $E5
- dw AnimationSlideMonHalfLeft
+ db SE_SLIDE_MON_HALF_OFF ; $E5
+ dw AnimationSlideMonHalfOff
db SE_SHAKE_ENEMY_HUD ; $E4
dw AnimationShakeEnemyHUD
db SE_SHAKE_ENEMY_HUD_2 ; unused--same pointer as SE_SHAKE_ENEMY_HUD ($E4)
@@ -1063,8 +1057,8 @@ SpecialEffectPointers: ; 790da (1e:50da)
dw AnimationShowMonPic
db SE_SHOW_ENEMY_MON_PIC ; $DC
dw AnimationShowEnemyMonPic
- db SE_SLIDE_ENEMY_MON_OUT ; $DB
- dw AnimationSlideEnemyMonOut
+ db SE_SLIDE_ENEMY_MON_OFF ; $DB
+ dw AnimationSlideEnemyMonOff
db SE_SHAKE_BACK_AND_FORTH ; $DA
dw AnimationShakeBackAndForth
db SE_SUBSTITUTE_MON ; $D9
@@ -1073,13 +1067,13 @@ SpecialEffectPointers: ; 790da (1e:50da)
dw AnimationWavyScreen
db $FF
-AnimationDelay10: ; 79150 (1e:5150)
+AnimationDelay10:
ld c,10
jp DelayFrames
; calls a function with the turn flipped from player to enemy or vice versa
; input - hl - address of function to call
-CallWithTurnFlipped: ; 79155 (1e:5155)
+CallWithTurnFlipped:
ld a,[H_WHOSETURN]
push af
xor a,1
@@ -1093,9 +1087,9 @@ CallWithTurnFlipped: ; 79155 (1e:5155)
ret
; flashes the screen for an extended period (48 frames)
-AnimationFlashScreenLong: ; 79165 (1e:5165)
+AnimationFlashScreenLong:
ld a,3 ; cycle through the palettes 3 times
- ld [wd08a],a
+ ld [wFlashScreenLongCounter],a
ld a,[wOnSGB] ; running on SGB?
and a
ld hl,FlashScreenLongMonochrome
@@ -1111,15 +1105,15 @@ AnimationFlashScreenLong: ; 79165 (1e:5165)
call FlashScreenLongDelay
jr .innerLoop
.endOfPalettes
- ld a,[wd08a]
+ ld a,[wFlashScreenLongCounter]
dec a
- ld [wd08a],a
+ ld [wFlashScreenLongCounter],a
pop hl
jr nz,.loop
ret
; BG palettes
-FlashScreenLongMonochrome: ; 7918e (1e:518e)
+FlashScreenLongMonochrome:
db %11111001 ; 3, 3, 2, 1
db %11111110 ; 3, 3, 3, 2
db %11111111 ; 3, 3, 3, 3
@@ -1135,7 +1129,7 @@ FlashScreenLongMonochrome: ; 7918e (1e:518e)
db $01 ; terminator
; BG palettes
-FlashScreenLongSGB: ; 7919b (1e:519b)
+FlashScreenLongSGB:
db %11111000 ; 3, 3, 2, 0
db %11111100 ; 3, 3, 3, 0
db %11111111 ; 3, 3, 3, 3
@@ -1152,9 +1146,9 @@ FlashScreenLongSGB: ; 7919b (1e:519b)
; causes a delay of 2 frames for the first cycle
; causes a delay of 1 frame for the second and third cycles
-FlashScreenLongDelay: ; 791a8 (1e:51a8)
- ld a,[wd08a]
- cp a,4 ; never true since [wd08a] starts at 3
+FlashScreenLongDelay:
+ ld a,[wFlashScreenLongCounter]
+ cp a,4 ; never true since [wFlashScreenLongCounter] starts at 3
ld c,4
jr z,.delayFrames
cp a,3
@@ -1165,7 +1159,7 @@ FlashScreenLongDelay: ; 791a8 (1e:51a8)
.delayFrames
jp DelayFrames
-AnimationFlashScreen: ; 791be (1e:51be)
+AnimationFlashScreen:
ld a,[rBGP]
push af ; save initial palette
ld a,%00011011 ; 0, 1, 2, 3 (inverted colors)
@@ -1180,235 +1174,250 @@ AnimationFlashScreen: ; 791be (1e:51be)
ld [rBGP],a ; restore initial palette
ret
-AnimationDarkScreenPalette: ; 791d6 (1e:51d6)
+AnimationDarkScreenPalette:
; Changes the screen's palette to a dark palette.
- ld bc, $6f6f
- jr Func_791fc
+ lb bc, $6f, $6f
+ jr SetAnimationBGPalette
-AnimationDarkenMonPalette: ; 791db (1e:51db)
+AnimationDarkenMonPalette:
; Darkens the mon sprite's palette.
- ld bc, $f9f4
- jr Func_791fc
+ lb bc, $f9, $f4
+ jr SetAnimationBGPalette
-Func_791e0: ; 791e0 (1e:51e0)
- ld bc, $fef8
- jr Func_791fc
+AnimationUnusedPalette1:
+ lb bc, $fe, $f8
+ jr SetAnimationBGPalette
-Func_791e5: ; 791e5 (1e:51e5)
- ld bc, $ffff
- jr Func_791fc
+AnimationUnusedPalette2:
+ lb bc, $ff, $ff
+ jr SetAnimationBGPalette
-AnimationResetScreenPalette: ; 791ea (1e:51ea)
+AnimationResetScreenPalette:
; Restores the screen's palette to the normal palette.
- ld bc, $e4e4
- jr Func_791fc
+ lb bc, $e4, $e4
+ jr SetAnimationBGPalette
-Func_791ef: ; 791ef (1e:51ef)
- ld bc, $0000
- jr Func_791fc
+AnimationUnusedPalette3:
+ lb bc, $00, $00
+ jr SetAnimationBGPalette
-AnimationLightScreenPalette: ; 791f4 (1e:51f4)
+AnimationLightScreenPalette:
; Changes the screen to use a palette with light colors.
- ld bc, $9090
- jr Func_791fc
+ lb bc, $90, $90
+ jr SetAnimationBGPalette
-Func_791f9: ; 791f9 (1e:51f9)
- ld bc, $4040
+AnimationUnusedPalette4:
+ lb bc, $40, $40
-Func_791fc: ; 791fc (1e:51fc)
+SetAnimationBGPalette:
ld a, [wOnSGB]
and a
ld a, b
- jr z, .asm_79204
+ jr z, .next
ld a, c
-.asm_79204
- ld [rBGP], a ; $ff47
+.next
+ ld [rBGP], a
ret
ld b, $5
-AnimationShakeScreenVertically: ; 79209 (1e:5209)
- predef_jump Func_480ff
+AnimationShakeScreenVertically:
+ predef_jump PredefShakeScreenVertically
-AnimationShakeScreen: ; 7920e (1e:520e)
+AnimationShakeScreen:
; Shakes the screen for a while. Used in Earthquake/Fissure/etc. animations.
ld b, $8
-AnimationShakeScreenHorizontallyFast: ; 79210 (1e:5210)
- predef_jump Func_48125
+AnimationShakeScreenHorizontallyFast:
+ predef_jump PredefShakeScreenHorizontally
-AnimationWaterDropletsEverywhere: ; 79215 (1e:5215)
+AnimationWaterDropletsEverywhere:
; Draws water droplets all over the screen and makes them
; scroll. It's hard to describe, but it's the main animation
; in Surf/Mist/Toxic.
xor a
- ld [wd09f], a
+ ld [wWhichBattleAnimTileset], a
call LoadAnimationTileset
- ld d, $20
- ld a, $f0
- ld [W_BASECOORDX], a ; wd081
+ ld d, 32
+ ld a, -16
+ ld [wBaseCoordX], a
ld a, $71
- ld [wd09f], a
-.asm_79228
- ld a, $10
- ld [W_BASECOORDY], a ; wd082
- ld a, $0
- ld [wd08a], a
- call Func_79246
- ld a, $18
- ld [W_BASECOORDY], a ; wd082
- ld a, $20
- ld [wd08a], a
- call Func_79246
+ ld [wDropletTile], a
+.loop
+ ld a, 16
+ ld [wBaseCoordY], a
+ ld a, 0
+ ld [wUnusedD08A], a
+ call _AnimationWaterDroplets
+ ld a, 24
+ ld [wBaseCoordY], a
+ ld a, 32
+ ld [wUnusedD08A], a
+ call _AnimationWaterDroplets
dec d
- jr nz, .asm_79228
+ jr nz, .loop
ret
-Func_79246: ; 79246 (1e:5246)
+_AnimationWaterDroplets:
ld hl, wOAMBuffer
-.asm_79249
- ld a, [W_BASECOORDY] ; wd082
- ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
- add $1b
- ld [W_BASECOORDX], a ; wd081
- ld [hli], a
- ld a, [wd09f]
- ld [hli], a
+.loop
+ ld a, [wBaseCoordY]
+ ld [hli], a ; Y
+ ld a, [wBaseCoordX]
+ add 27
+ ld [wBaseCoordX], a
+ ld [hli], a ; X
+ ld a, [wDropletTile]
+ ld [hli], a ; tile
xor a
- ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
- cp $90
- jr c, .asm_79249
- sub $a8
- ld [W_BASECOORDX], a ; wd081
- ld a, [W_BASECOORDY] ; wd082
- add $10
- ld [W_BASECOORDY], a ; wd082
- cp $70
- jr c, .asm_79249
+ ld [hli], a ; attribute
+ ld a, [wBaseCoordX]
+ cp 144
+ jr c, .loop
+ sub 168
+ ld [wBaseCoordX], a
+ ld a, [wBaseCoordY]
+ add 16
+ ld [wBaseCoordY], a
+ cp 112
+ jr c, .loop
call AnimationCleanOAM
jp DelayFrame
-AnimationSlideMonUp: ; 7927a (1e:527a)
+AnimationSlideMonUp:
; Slides the mon's sprite upwards.
- ld c, $7
+ ld c, 7
ld a, [H_WHOSETURN]
and a
- ld hl, wTileMap + $79
- ld de, wTileMap + $65
+ coord hl, 1, 6
+ coord de, 1, 5
ld a, $30
- jr z, .asm_79291
- ld hl, wTileMap + $20
- ld de, wTileMap + $c
+ jr z, .next
+ coord hl, 12, 1
+ coord de, 12, 0
ld a, $ff
-.asm_79291
- ld [wd09f], a
- jp Func_792bf
+.next
+ ld [wSlideMonUpBottomRowLeftTile], a
+ jp _AnimationSlideMonUp
-AnimationSlideMonDown: ; 79297 (1e:5297)
+AnimationSlideMonDown:
; Slides the mon's sprite down out of the screen.
xor a
call GetTileIDList
-.asm_7929b
+.loop
call GetMonSpriteTileMapPointerFromRowCount
push bc
push de
- call Func_79aae
+ call CopyPicTiles
call Delay3
call AnimationHideMonPic
pop de
pop bc
dec b
- jr nz, .asm_7929b
+ jr nz, .loop
ret
-AnimationSlideMonOut: ; 792af (1e:52af)
-; Slides the mon's sprite out of the screen horizontally.
- ld e, $8
- ld a, $3
- ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM
- jp Func_795f8
+AnimationSlideMonOff:
+; Slides the mon's sprite off the screen horizontally.
+ ld e, 8
+ ld a, 3
+ ld [wSlideMonDelay], a
+ jp _AnimationSlideMonOff
-AnimationSlideEnemyMonOut: ; 792b9 (1e:52b9)
-; Slides the enemy mon out of the screen horizontally.
- ld hl, AnimationSlideMonOut ; $52af
+AnimationSlideEnemyMonOff:
+; Slides the enemy mon off the screen horizontally.
+ ld hl, AnimationSlideMonOff
jp CallWithTurnFlipped
-Func_792bf: ; 792bf (1e:52bf)
+_AnimationSlideMonUp:
push de
push hl
push bc
- ld b, $6
-.asm_792c4
+
+; In each iteration, slide up all rows but the top one (which is overwritten).
+ ld b, 6
+.slideLoop
push bc
push de
push hl
- ld bc, $0007
+ ld bc, 7
call CopyData
+; Note that de and hl are popped in the same order they are pushed, swapping
+; their values. When CopyData is called, hl points to a tile 1 row below
+; the one de points to. To maintain this relationship, after swapping, we add 2
+; rows to hl so that it is 1 row below again.
pop de
pop hl
- ld bc, $0028
+ ld bc, SCREEN_WIDTH * 2
add hl, bc
pop bc
dec b
- jr nz, .asm_792c4
+ jr nz, .slideLoop
+
+; Fill in the bottom row of the mon pic with the next row's tile IDs.
ld a, [H_WHOSETURN]
and a
- ld hl, wTileMap + $dd
- jr z, .asm_792e2
- ld hl, wTileMap + $84
-.asm_792e2
- ld a, [wd09f]
+ coord hl, 1, 11
+ jr z, .next
+ coord hl, 12, 6
+.next
+ ld a, [wSlideMonUpBottomRowLeftTile]
inc a
- ld [wd09f], a
- ld c, $7
-.asm_792eb
+ ld [wSlideMonUpBottomRowLeftTile], a
+ ld c, 7
+.fillBottomRowLoop
ld [hli], a
- add $7
+ add 7
dec c
- jr nz, .asm_792eb
- ld c, $2
+ jr nz, .fillBottomRowLoop
+
+ ld c, 2
call DelayFrames
pop bc
pop hl
pop de
dec c
- jr nz, Func_792bf
+ jr nz, _AnimationSlideMonUp
ret
-Func_792fd: ; 792fd (1e:52fd)
+ShakeEnemyHUD_WritePlayerMonPicOAM:
+; Writes the OAM entries for a copy of the player mon's pic in OAM.
+; The top 5 rows are reproduced in OAM, although only 2 are actually needed.
ld a, $10
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
ld a, $30
- ld [W_BASECOORDY], a
+ ld [wBaseCoordY], a
ld hl, wOAMBuffer
- ld d, $0
- ld c, $7
-.asm_7930e
- ld a, [W_BASECOORDY]
+ ld d, 0
+ ld c, 7
+.loop
+ ld a, [wBaseCoordY]
ld e, a
- ld b, $5
-.asm_79314
- call Func_79329
+ ld b, 5
+.innerLoop
+ call BattleAnimWriteOAMEntry
inc d
dec b
- jr nz, .asm_79314
+ jr nz, .innerLoop
dec c
ret z
inc d
inc d
- ld a, [W_BASECOORDX]
- add $8
- ld [W_BASECOORDX], a
- jr .asm_7930e
+ ld a, [wBaseCoordX]
+ add 8
+ ld [wBaseCoordX], a
+ jr .loop
-Func_79329: ; 79329 (1e:5329)
+BattleAnimWriteOAMEntry:
+; Y coordinate = e (increased by 8 each call, before the write to OAM)
+; X coordinate = [wBaseCoordX]
+; tile = d
+; attributes = 0
ld a, e
- add $8
+ add 8
ld e, a
ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
+ ld a, [wBaseCoordX]
ld [hli], a
ld a, d
ld [hli], a
@@ -1416,21 +1425,22 @@ Func_79329: ; 79329 (1e:5329)
ld [hli], a
ret
-AdjustOAMBlockXPos: ; 79337 (1e:5337)
+AdjustOAMBlockXPos:
ld l, e
ld h, d
-AdjustOAMBlockXPos2: ; 79339 (1e:5339)
- ld de, $4
+AdjustOAMBlockXPos2:
+ ld de, 4
.loop
- ld a, [wd08a]
+ ld a, [wCoordAdjustmentAmount]
ld b, a
ld a, [hl]
add b
- cp $a8
+ cp 168
jr c, .skipPuttingEntryOffScreen
+; put off-screen if X >= 168
dec hl
- ld a, $a0
+ ld a, 160
ld [hli], a
.skipPuttingEntryOffScreen
ld [hl], a
@@ -1439,21 +1449,21 @@ AdjustOAMBlockXPos2: ; 79339 (1e:5339)
jr nz, .loop
ret
-AdjustOAMBlockYPos: ; 79350 (1e:5350)
+AdjustOAMBlockYPos:
ld l, e
ld h, d
-AdjustOAMBlockYPos2: ; 79352 (1e:5352)
- ld de, $4
+AdjustOAMBlockYPos2:
+ ld de, 4
.loop
- ld a, [wd08a]
+ ld a, [wCoordAdjustmentAmount]
ld b, a
ld a, [hl]
add b
- cp $70
+ cp 112
jr c, .skipSettingPreviousEntrysAttribute
dec hl
- ld a, $a0 ; bug, sets previous OAM entry's attribute
+ ld a, 160 ; bug, sets previous OAM entry's attribute
ld [hli], a
.skipSettingPreviousEntrysAttribute
ld [hl], a
@@ -1462,70 +1472,70 @@ AdjustOAMBlockYPos2: ; 79352 (1e:5352)
jr nz, .loop
ret
-AnimationBlinkEnemyMon: ; 79369 (1e:5369)
+AnimationBlinkEnemyMon:
; Make the enemy mon's sprite blink on and off for a second or two
- ld hl, AnimationBlinkMon ; $536f
+ ld hl, AnimationBlinkMon
jp CallWithTurnFlipped
-AnimationBlinkMon: ; 7936f (1e:536f)
+AnimationBlinkMon:
; Make the mon's sprite blink on and off for a second or two.
push af
- ld c, $6
-.asm_79372
+ ld c, 6
+.loop
push bc
call AnimationHideMonPic
- ld c, $5
+ ld c, 5
call DelayFrames
call AnimationShowMonPic
- ld c, $5
+ ld c, 5
call DelayFrames
pop bc
dec c
- jr nz, .asm_79372
+ jr nz, .loop
pop af
ret
-AnimationFlashMonPic: ; 79389 (1e:5389)
+AnimationFlashMonPic:
; Flashes the mon's sprite on and off
ld a, [wBattleMonSpecies]
- ld [wHPBarMaxHP + 1], a
+ ld [wChangeMonPicPlayerTurnSpecies], a
ld a, [wEnemyMonSpecies]
- ld [wHPBarMaxHP], a
- jp Func_79793
+ ld [wChangeMonPicEnemyTurnSpecies], a
+ jp ChangeMonPic
-AnimationFlashEnemyMonPic: ; 79398 (1e:5398)
+AnimationFlashEnemyMonPic:
; Flashes the enemy mon's sprite on and off
ld hl, AnimationFlashMonPic
jp CallWithTurnFlipped
-AnimationShowMonPic: ; 7939e (1e:539e)
+AnimationShowMonPic:
xor a
call GetTileIDList
call GetMonSpriteTileMapPointerFromRowCount
- call Func_79aae
+ call CopyPicTiles
jp Delay3
-AnimationShowEnemyMonPic: ; 793ab (1e:53ab)
+AnimationShowEnemyMonPic:
; Shows the emenmy mon's front sprite. Used in animations like Seismic Toss
; to make the mon's sprite reappear after disappears offscreen.
ld hl, AnimationShowMonPic
jp CallWithTurnFlipped
-AnimationShakeBackAndForth: ; 793b1 (1e:53b1)
+AnimationShakeBackAndForth:
; Shakes the mon's sprite back and forth rapidly. This is used in Double Team.
; The mon's sprite disappears after this animation.
ld a, [H_WHOSETURN]
and a
- ld hl, wTileMap + $64
- ld de, wTileMap + $66
- jr z, .asm_793c2
- ld hl, wTileMap + $b
- ld de, wTileMap + $d
+ coord hl, 0, 5
+ coord de, 2, 5
+ jr z, .next
+ coord hl, 11, 0
+ coord de, 13, 0
-.asm_793c2
+.next
xor a
ld c, $10
-.asm_793c5
+.loop
push af
push bc
push de
@@ -1537,113 +1547,113 @@ AnimationShakeBackAndForth: ; 793b1 (1e:53b1)
push hl
call GetTileIDList
pop hl
- call Func_79aae
+ call CopyPicTiles
call Delay3
pop hl
- ld bc, $0709
+ lb bc, 7, 9
call ClearScreenArea
pop af
call GetTileIDList
pop hl
- call Func_79aae
+ call CopyPicTiles
call Delay3
pop hl
- ld bc, $0709
+ lb bc, 7, 9
call ClearScreenArea
pop hl
pop de
pop bc
pop af
dec c
- jr nz, .asm_793c5
+ jr nz, .loop
ret
-AnimationMoveMonHorizontally: ; 793f9 (1e:53f9)
+AnimationMoveMonHorizontally:
; Shifts the mon's sprite horizontally to a fixed location. Used by lots of
; animations like Tackle/Body Slam.
call AnimationHideMonPic
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- hlCoord 2, 5
- jr z, .asm_79407
- hlCoord 11, 0
-.asm_79407
+ coord hl, 2, 5
+ jr z, .next
+ coord hl, 11, 0
+.next
xor a
push hl
call GetTileIDList
pop hl
- call Func_79aae
- ld c, $3
+ call CopyPicTiles
+ ld c, 3
jp DelayFrames
-AnimationResetMonPosition: ; 79415 (1e:5415)
+AnimationResetMonPosition:
; Resets the mon's sprites to be located at the normal coordinates.
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- ld a, $66
- jr z, .asm_7941e
- ld a, $b
-.asm_7941e
- call Func_7980c
+ ld a, 5 * SCREEN_WIDTH + 2
+ jr z, .next
+ ld a, 11
+.next
+ call ClearMonPicFromTileMap
jp AnimationShowMonPic
-AnimationSpiralBallsInward: ; 79424 (1e:5424)
-; Creates an effect that looks like energy balls sprialing into the
+AnimationSpiralBallsInward:
+; Creates an effect that looks like energy balls spiralling into the
; player mon's sprite. Used in Focus Energy, for example.
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_79435
- ld a, $d8
- ld [wd08a], a
- ld a, $50
- ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM
- jr .asm_7943c
-.asm_79435
+ jr z, .playerTurn
+ ld a, -40
+ ld [wSpiralBallsBaseY], a
+ ld a, 80
+ ld [wSpiralBallsBaseX], a
+ jr .next
+.playerTurn
xor a
- ld [wd08a], a
- ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM
-.asm_7943c
- ld d, $7a
- ld c, $3
+ ld [wSpiralBallsBaseY], a
+ ld [wSpiralBallsBaseX], a
+.next
+ ld d, $7a ; ball tile
+ ld c, 3 ; number of balls
xor a
- call Func_797e8
- ld hl, SpiralBallAnimationCoordinates ; $5476
-.asm_79447
+ call InitMultipleObjectsOAM
+ ld hl, SpiralBallAnimationCoordinates
+.loop
push hl
- ld c, $3
+ ld c, 3
ld de, wOAMBuffer
-.asm_7944d
+.innerLoop
ld a, [hl]
cp $ff
- jr z, .asm_7946f
- ld a, [wd08a]
+ jr z, .done
+ ld a, [wSpiralBallsBaseY]
add [hl]
- ld [de], a
+ ld [de], a ; Y
inc de
inc hl
- ld a, [W_SUBANIMTRANSFORM] ; W_SUBANIMTRANSFORM
+ ld a, [wSpiralBallsBaseX]
add [hl]
- ld [de], a
+ ld [de], a ; X
inc hl
inc de
inc de
inc de
dec c
- jr nz, .asm_7944d
- ld c, $5
+ jr nz, .innerLoop
+ ld c, 5
call DelayFrames
pop hl
inc hl
inc hl
- jr .asm_79447
-.asm_7946f
+ jr .loop
+.done
pop hl
call AnimationCleanOAM
jp AnimationFlashScreen
-SpiralBallAnimationCoordinates: ; 79476 (1e:5476)
+SpiralBallAnimationCoordinates:
; y, x pairs
-; This is the sequence of screen coordinates that the spiraling
+; This is the sequence of screen coordinates that the spiralling
; balls are positioned at.
db $38, $28
db $40, $18
@@ -1668,131 +1678,132 @@ SpiralBallAnimationCoordinates: ; 79476 (1e:5476)
db $50, $28
db $FF ; list terminator
-AnimationSquishMonPic: ; 794a1 (1e:54a1)
+AnimationSquishMonPic:
; Squishes the mon's sprite horizontally making it
; disappear. Used by Teleport/Sky Attack animations.
- ld c, $4
-.asm_794a3
+ ld c, 4
+.loop
push bc
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_794b1
- hlCoord 16, 0
- deCoord 14, 0
- jr .asm_794b7
-.asm_794b1
- hlCoord 5, 5
- deCoord 3, 5
-.asm_794b7
+ jr z, .playerTurn
+ coord hl, 16, 0
+ coord de, 14, 0
+ jr .next
+.playerTurn
+ coord hl, 5, 5
+ coord de, 3, 5
+.next
push de
- xor a
- ld [wd09f], a
- call Func_794d4
+ xor a ; left
+ ld [wSquishMonCurrentDirection], a
+ call _AnimationSquishMonPic
pop hl
- ld a, $1
- ld [wd09f], a
- call Func_794d4
+ ld a, 1 ; right
+ ld [wSquishMonCurrentDirection], a
+ call _AnimationSquishMonPic
pop bc
dec c
- jr nz, .asm_794a3
+ jr nz, .loop
call AnimationHideMonPic
- ld c, $2
+ ld c, 2
jp DelayFrame
-Func_794d4: ; 794d4 (1e:54d4)
- ld c, $7
-.asm_794d6
+_AnimationSquishMonPic:
+ ld c, 7
+.loop
push bc
push hl
- ld c, $3
- ld a, [wd09f]
- cp $0
- jr nz, .asm_794e7
- call Func_7985b
+ ld c, 3
+ ld a, [wSquishMonCurrentDirection]
+ cp 0
+ jr nz, .right
+ call AnimCopyRowLeft
dec hl
- jr .asm_794eb
-.asm_794e7
- call Func_79862
+ jr .next
+.right
+ call AnimCopyRowRight
inc hl
-.asm_794eb
- ld [hl], $7f
+.next
+ ld [hl], " "
pop hl
- ld de, $14
+ ld de, SCREEN_WIDTH
add hl, de
pop bc
dec c
- jr nz, .asm_794d6
+ jr nz, .loop
jp Delay3
-AnimationShootBallsUpward: ; 794f9 (1e:54f9)
+AnimationShootBallsUpward:
; Shoots one pillar of "energy" balls upwards. Used in Teleport/Sky Attack
; animations.
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_79503
- ld bc, $80
- jr .asm_79506
-.asm_79503
- ld bc, $3028
-.asm_79506
+ jr z, .playerTurn
+ lb bc, 0, 16 * 8
+ jr .next
+.playerTurn
+ lb bc, 6 * 8, 5 * 8
+.next
ld a, b
- ld [W_BASECOORDY], a ; wd082
+ ld [wBaseCoordY], a
ld a, c
- ld [W_BASECOORDX], a ; wd081
- ld bc, $501
- call Func_79517
+ ld [wBaseCoordX], a
+ lb bc, 5, 1
+ call _AnimationShootBallsUpward
jp AnimationCleanOAM
-Func_79517: ; 79517 (1e:5517)
+_AnimationShootBallsUpward:
push bc
xor a
- ld [wd09f], a
+ ld [wWhichBattleAnimTileset], a
call LoadAnimationTileset
pop bc
- ld d, $7a
+ ld d, $7a ; ball tile
ld hl, wOAMBuffer
push bc
- ld a, [W_BASECOORDY] ; wd082
+ ld a, [wBaseCoordY]
ld e, a
-.asm_7952a
- call Func_79329
+.initOAMLoop
+ call BattleAnimWriteOAMEntry
dec b
- jr nz, .asm_7952a
+ jr nz, .initOAMLoop
call DelayFrame
pop bc
ld a, b
- ld [wd08a], a
-.asm_79538
+ ld [wNumShootingBalls], a
+.loop
push bc
ld hl, wOAMBuffer
-.asm_7953c
- ld a, [W_BASECOORDY] ; wd082
- add $8
+.innerLoop
+ ld a, [wBaseCoordY]
+ add 8
ld e, a
ld a, [hl]
- cp e
- jr z, .asm_7954b
- add $fc
+ cp e ; has the ball reached the top?
+ jr z, .reachedTop
+ add -4 ; ball hasn't reached the top. move it up 4 pixels
ld [hl], a
- jr .asm_79554
-.asm_7954b
- ld [hl], $0
- ld a, [wd08a]
+ jr .next
+.reachedTop
+; remove the ball once it has reached the top
+ ld [hl], 0 ; put it off-screen
+ ld a, [wNumShootingBalls]
dec a
- ld [wd08a], a
-.asm_79554
- ld de, $4
- add hl, de
+ ld [wNumShootingBalls], a
+.next
+ ld de, 4
+ add hl, de ; next OAM entry
dec b
- jr nz, .asm_7953c
+ jr nz, .innerLoop
call DelayFrames
pop bc
- ld a, [wd08a]
+ ld a, [wNumShootingBalls]
and a
- jr nz, .asm_79538
+ jr nz, .loop
ret
-AnimationShootManyBallsUpward: ; 79566 (1e:5566)
+AnimationShootManyBallsUpward:
; Shoots several pillars of "energy" balls upward.
ld a, [H_WHOSETURN]
and a
@@ -1802,64 +1813,65 @@ AnimationShootManyBallsUpward: ; 79566 (1e:5566)
ld hl, UpwardBallsAnimXCoordinatesEnemyTurn
ld a, $28 ; y coordinate for "energy" ball pillar
.player
- ld [wTrainerSpriteOffset], a
+ ld [wSavedY], a
.loop
- ld a, [wTrainerSpriteOffset]
- ld [W_BASECOORDY], a
+ ld a, [wSavedY]
+ ld [wBaseCoordY], a
ld a, [hli]
cp $ff
jp z, AnimationCleanOAM
- ld [W_BASECOORDX], a
- ld bc, $0401
+ ld [wBaseCoordX], a
+ lb bc, 4, 1
push hl
- call Func_79517
+ call _AnimationShootBallsUpward
pop hl
jr .loop
-UpwardBallsAnimXCoordinatesPlayerTurn: ; 79591 (1e:5591)
+UpwardBallsAnimXCoordinatesPlayerTurn:
; List of x coordinates for each pillar of "energy" balls in the
; AnimationShootManyBallsUpward animation. It's unused in the game.
db $10, $40, $28, $18, $38, $30
db $FF ; list terminator
-UpwardBallsAnimXCoordinatesEnemyTurn: ; 79598 (1e:5598)
+UpwardBallsAnimXCoordinatesEnemyTurn:
; List of x coordinates for each pillar of "energy" balls in the
; AnimationShootManyBallsUpward animation. It's unused in the game.
db $60, $90, $78, $68, $88, $80
db $FF ; list terminator
-AnimationMinimizeMon: ; 7959f (1e:559f)
+AnimationMinimizeMon:
; Changes the mon's sprite to a mini black sprite. Used by the
; Minimize animation.
ld hl, wTempPic
push hl
xor a
- ld bc, $310
+ ld bc, 7 * 7 * $10
call FillMemory
pop hl
ld de, $194
add hl, de
- ld de, MinimizedMonSprite ; $55c4
- ld c, $5
-.asm_795b4
+ ld de, MinimizedMonSprite
+ ld c, MinimizedMonSpriteEnd - MinimizedMonSprite
+.loop
ld a, [de]
ld [hli], a
ld [hli], a
inc de
dec c
- jr nz, .asm_795b4
- call Func_79652
+ jr nz, .loop
+ call CopyTempPicToMonPic
call Delay3
jp AnimationShowMonPic
-MinimizedMonSprite: ; 795c4 (1e:55c4)
+MinimizedMonSprite:
INCBIN "gfx/minimized_mon_sprite.1bpp"
+MinimizedMonSpriteEnd:
-AnimationSlideMonDownAndHide: ; 795c9 (1e:55c9)
+AnimationSlideMonDownAndHide:
; Slides the mon's sprite down and disappears. Used in Acid Armor.
ld a, $1
ld c, $2
-.asm_795cd
+.loop
push bc
push af
call AnimationHideMonPic
@@ -1867,168 +1879,182 @@ AnimationSlideMonDownAndHide: ; 795c9 (1e:55c9)
push af
call GetTileIDList
call GetMonSpriteTileMapPointerFromRowCount
- call Func_79aae
- ld c, $8
+ call CopyPicTiles
+ ld c, 8
call DelayFrames
pop af
inc a
pop bc
dec c
- jr nz, .asm_795cd
+ jr nz, .loop
call AnimationHideMonPic
ld hl, wTempPic
ld bc, $0310
xor a
call FillMemory
- jp Func_79652
+ jp CopyTempPicToMonPic
-Func_795f8: ; 795f8 (1e:55f8)
- ld a, [H_WHOSETURN] ; $fff3
+_AnimationSlideMonOff:
+; Slides the mon's sprite off the screen horizontally by e tiles and waits
+; [wSlideMonDelay] V-blanks each time the pic is slid by one tile.
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_79602
- hlCoord 12, 0
- jr .asm_79605
-.asm_79602
- hlCoord 0, 5
-.asm_79605
- ld d, $8
-.asm_79607
+ jr z, .playerTurn
+ coord hl, 12, 0
+ jr .next
+.playerTurn
+ coord hl, 0, 5
+.next
+ ld d, 8 ; d's value is unused
+.slideLoop ; iterates once for each time the pic slides by one tile
push hl
- ld b, $7
-.asm_7960a
- ld c, $8
-.asm_7960c
- ld a, [H_WHOSETURN] ; $fff3
+ ld b, 7
+.rowLoop ; iterates once for each row
+ ld c, 8
+.tileLoop ; iterates once for each tile in the row
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_79616
- call Func_7963c
- jr .asm_79619
-.asm_79616
- call Func_79633
-.asm_79619
+ jr z, .playerTurn2
+ call .EnemyNextTile
+ jr .next2
+.playerTurn2
+ call .PlayerNextTile
+.next2
ld [hli], a
dec c
- jr nz, .asm_7960c
+ jr nz, .tileLoop
push de
- ld de, $c
+ ld de, SCREEN_WIDTH - 8
add hl, de
pop de
dec b
- jr nz, .asm_7960a
- ld a, [W_SUBANIMTRANSFORM] ; W_SUBANIMTRANSFORM
+ jr nz, .rowLoop
+ ld a, [wSlideMonDelay]
ld c, a
call DelayFrames
pop hl
dec d
dec e
- jr nz, .asm_79607
+ jr nz, .slideLoop
ret
-Func_79633: ; 79633 (1e:5633)
+; Since mon pic tile numbers go from top to bottom, left to right in order,
+; adding the height of the mon pic in tiles to a tile number gives the tile
+; number of the tile one column to the right (and thus subtracting the height
+; gives the reverse). If the next tile would be past the edge of the pic, the 2
+; functions below catch it by checking if the tile number is within the valid
+; range and if not, replacing it with a blank tile.
+
+.PlayerNextTile
ld a, [hl]
- add $7
+ add 7
+; This is a bug. The lower right corner tile of the mon back pic is blanked
+; while the mon is sliding off the screen. It should compare with the max tile
+; plus one instead.
cp $61
ret c
- ld a, $7f
+ ld a, " "
ret
-Func_7963c: ; 7963c (1e:563c)
+.EnemyNextTile
ld a, [hl]
- sub $7
+ sub 7
+; This has the same problem as above, but it has no visible effect because
+; the lower right tile is in the first column to slide off the screen.
cp $30
ret c
- ld a, $7f
+ ld a, " "
ret
-AnimationSlideMonHalfLeft: ; 79645 (1e:5645)
-; Slides the mon's sprite halfway out of the screen. It's used in Softboiled.
- ld e, $4
- ld a, $4
- ld [W_SUBANIMTRANSFORM], a
- call Func_795f8
+AnimationSlideMonHalfOff:
+; Slides the mon's sprite halfway off the screen. It's used in Softboiled.
+ ld e, 4
+ ld a, 4
+ ld [wSlideMonDelay], a
+ call _AnimationSlideMonOff
jp Delay3
-Func_79652: ; 79652 (1e:5652)
- ld a, [H_WHOSETURN] ; $fff3
+CopyTempPicToMonPic:
+ ld a, [H_WHOSETURN]
and a
- ld hl, vBackPic
- jr z, .asm_7965d
- ld hl, vFrontPic
-.asm_7965d
+ ld hl, vBackPic ; player turn
+ jr z, .next
+ ld hl, vFrontPic ; enemy turn
+.next
ld de, wTempPic
ld bc, 7 * 7
jp CopyVideoData
-AnimationWavyScreen: ; 79666 (1e:5666)
+AnimationWavyScreen:
; used in Psywave/Psychic etc.
ld hl, vBGMap0
- call Func_79e0d
+ call BattleAnimCopyTileMapToVRAM
call Delay3
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- ld a, $90
+ ld a, SCREEN_HEIGHT_PIXELS
ld [hWY], a
- ld d, $80
- ld e, $8f
+ ld d, $80 ; terminator
+ ld e, SCREEN_HEIGHT_PIXELS - 1
ld c, $ff
ld hl, WavyScreenLineOffsets
-.asm_7967f
+.loop
push hl
-.asm_79680
- call Func_796ae
- ld a, [$ff44]
- cp e
- jr nz, .asm_79680
+.innerLoop
+ call WavyScreen_SetSCX
+ ld a, [rLY]
+ cp e ; is it the last visible line in the frame?
+ jr nz, .innerLoop ; keep going if not
pop hl
inc hl
ld a, [hl]
- cp d
- jr nz, .asm_79691
- ld hl, WavyScreenLineOffsets
-.asm_79691
+ cp d ; have we reached the end?
+ jr nz, .next
+ ld hl, WavyScreenLineOffsets ; go back to the beginning if so
+.next
dec c
- jr nz, .asm_7967f
+ jr nz, .loop
xor a
ld [hWY], a
call SaveScreenTilesToBuffer2
call ClearScreen
- ld a, $1
+ ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
call LoadScreenTilesFromBuffer2
ld hl, vBGMap1
- call Func_79e0d
+ call BattleAnimCopyTileMapToVRAM
ret
-Func_796ae: ; 796ae (1e:56ae)
- ld a, [$ff41]
- and $3
- jr nz, Func_796ae
+WavyScreen_SetSCX:
+ ld a, [rSTAT]
+ and $3 ; is it H-blank?
+ jr nz, WavyScreen_SetSCX ; wait until it's H-blank
ld a, [hl]
- ld [$ff43], a
+ ld [rSCX], a
inc hl
ld a, [hl]
- cp d
+ cp d ; have we reached the end?
ret nz
- ld hl, WavyScreenLineOffsets
+ ld hl, WavyScreenLineOffsets ; go back to the beginning if so
ret
-WavyScreenLineOffsets: ; 796bf (1e:56bf)
+WavyScreenLineOffsets:
; Sequence of horizontal line pixel offsets for the wavy screen animation.
; This sequence vaguely resembles a sine wave.
db 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1
db 0, 0, 0, 0, 0, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1, -1
db $80 ; terminator
-AnimationSubstitute: ; 796e0 (1e:56e0)
+AnimationSubstitute:
; Changes the pokemon's sprite to the mini sprite
ld hl, wTempPic
xor a
ld bc, $0310
call FillMemory
- ld a, [$fff3]
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_79715 ; 0x796ed $26
+ jr z, .playerTurn
ld hl, SlowbroSprite ; facing down sprite
ld de, wTempPic + $120
call CopySlowbroSpriteData
@@ -2041,8 +2067,8 @@ AnimationSubstitute: ; 796e0 (1e:56e0)
ld hl, SlowbroSprite + $30
ld de, wTempPic + $120 + $10 + $70
call CopySlowbroSpriteData
- jr .asm_79739
-.asm_79715
+ jr .next
+.playerTurn
ld hl, SlowbroSprite + $40 ; facing up sprite
ld de, wTempPic + $120 + $70
call CopySlowbroSpriteData
@@ -2055,32 +2081,33 @@ AnimationSubstitute: ; 796e0 (1e:56e0)
ld hl, SlowbroSprite + $70
ld de, wTempPic + $120 + $f0
call CopySlowbroSpriteData
-.asm_79739
- call Func_79652
+.next
+ call CopyTempPicToMonPic
jp AnimationShowMonPic
-CopySlowbroSpriteData: ; 7973f (1e:573f)
+CopySlowbroSpriteData:
ld bc, $0010
ld a, BANK(SlowbroSprite)
jp FarCopyData2
-Func_79747: ; 79747 (1e:5747)
- ld a, [H_WHOSETURN] ; $fff3
+HideSubstituteShowMonAnim:
+ ld a, [H_WHOSETURN]
and a
- ld hl, wccf7
- ld a, [W_PLAYERBATTSTATUS2] ; W_PLAYERBATTSTATUS2
- jr z, .asm_79758
- ld hl, wccf3
- ld a, [W_ENEMYBATTSTATUS2] ; W_ENEMYBATTSTATUS2
-.asm_79758
+ ld hl, wPlayerMonMinimized
+ ld a, [wPlayerBattleStatus2]
+ jr z, .next1
+ ld hl, wEnemyMonMinimized
+ ld a, [wEnemyBattleStatus2]
+.next1
push hl
- bit 4, a
- jr nz, .asm_79762
+; if the substitute broke, slide it down, else slide it offscreen horizontally
+ bit HasSubstituteUp, a
+ jr nz, .substituteStillUp
call AnimationSlideMonDown
- jr .asm_79765
-.asm_79762
- call AnimationSlideMonOut
-.asm_79765
+ jr .next2
+.substituteStillUp
+ call AnimationSlideMonOff
+.next2
pop hl
ld a, [hl]
and a
@@ -2088,48 +2115,48 @@ Func_79747: ; 79747 (1e:5747)
call AnimationFlashMonPic
jp AnimationShowMonPic
-Func_79771: ; 79771 (1e:5771)
- call AnimationSlideMonOut
+ReshowSubstituteAnim:
+ call AnimationSlideMonOff
call AnimationSubstitute
jp AnimationShowMonPic
-AnimationBoundUpAndDown: ; 7977a (1e:577a)
+AnimationBoundUpAndDown:
; Bounces the mon's sprite up and down several times. It is used
; by Splash's animation.
- ld c, $5
-.asm_7977c
+ ld c, 5
+.loop
push bc
call AnimationSlideMonDown
pop bc
dec c
- jr nz, .asm_7977c ; 0x79782 $f8
+ jr nz, .loop
jp AnimationShowMonPic
-AnimationTransformMon: ; 79787 (1e:5787)
+AnimationTransformMon:
; Redraws this mon's sprite as the back/front sprite of the opposing mon.
; Used in Transform.
ld a, [wEnemyMonSpecies]
- ld [wHPBarMaxHP + 1], a
+ ld [wChangeMonPicPlayerTurnSpecies], a
ld a, [wBattleMonSpecies]
- ld [wHPBarMaxHP], a
+ ld [wChangeMonPicEnemyTurnSpecies], a
-Func_79793: ; 79793 (1e:5793)
- ld a, [H_WHOSETURN] ; $fff3
+ChangeMonPic:
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_797b0
- ld a, [wHPBarMaxHP]
+ jr z, .playerTurn
+ ld a, [wChangeMonPicEnemyTurnSpecies]
ld [wcf91], a
ld [wd0b5], a
xor a
- ld [W_SPRITEFLIPPED], a
+ ld [wSpriteFlipped], a
call GetMonHeader
- hlCoord 12, 0
+ coord hl, 12, 0
call LoadFrontSpriteByMonIndex
- jr .asm_797d3
-.asm_797b0
+ jr .done
+.playerTurn
ld a, [wBattleMonSpecies2]
push af
- ld a, [wHPBarMaxHP + 1]
+ ld a, [wChangeMonPicPlayerTurnSpecies]
ld [wBattleMonSpecies2], a
ld [wd0b5], a
call GetMonHeader
@@ -2137,59 +2164,63 @@ Func_79793: ; 79793 (1e:5793)
xor a
call GetTileIDList
call GetMonSpriteTileMapPointerFromRowCount
- call Func_79aae
+ call CopyPicTiles
pop af
ld [wBattleMonSpecies2], a
-.asm_797d3
- ld b, $1
- jp GoPAL_SET
+.done
+ ld b, SET_PAL_BATTLE
+ jp RunPaletteCommand
-AnimationHideEnemyMonPic: ; 797d8 (1e:57d8)
+AnimationHideEnemyMonPic:
; Hides the enemy mon's sprite
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld hl, AnimationHideMonPic ; $5801
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld hl, AnimationHideMonPic
call CallWithTurnFlipped
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
jp Delay3
-Func_797e8: ; 797e8 (1e:57e8)
+InitMultipleObjectsOAM:
+; Writes c OAM entries with tile d.
+; Sets their Y coordinates to sequential multiples of 8, starting from 0.
+; Sets their X coordinates to 0.
+; Loads animation tileset a.
push bc
push de
- ld [wd09f], a
+ ld [wWhichBattleAnimTileset], a
call LoadAnimationTileset
pop de
pop bc
xor a
ld e, a
- ld [W_BASECOORDX], a ; wd081
+ ld [wBaseCoordX], a
ld hl, wOAMBuffer
-.asm_797fa
- call Func_79329
+.loop
+ call BattleAnimWriteOAMEntry
dec c
- jr nz, .asm_797fa
+ jr nz, .loop
ret
-AnimationHideMonPic: ; 79801 (1e:5801)
+AnimationHideMonPic:
; Hides the mon's sprite.
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_7980a
- ld a, $c
- jr Func_7980c
-.asm_7980a
- ld a, $65
+ jr z, .playerTurn
+ ld a, 12
+ jr ClearMonPicFromTileMap
+.playerTurn
+ ld a, 5 * SCREEN_WIDTH + 1
-Func_7980c: ; 7980c (1e:580c)
+ClearMonPicFromTileMap:
push hl
push de
push bc
ld e, a
- ld d, $0
- ld hl, wTileMap
+ ld d, 0
+ coord hl, 0, 0
add hl, de
- ld bc, $707
+ lb bc, 7, 7
call ClearScreenArea
pop bc
pop de
@@ -2199,7 +2230,7 @@ Func_7980c: ; 7980c (1e:580c)
; puts the tile map destination address of a mon sprite in hl, given the row count in b
; The usual row count is 7, but it may be smaller when sliding a mon sprite in/out,
; in order to show only a portion of the mon sprite.
-GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820)
+GetMonSpriteTileMapPointerFromRowCount:
push de
ld a, [H_WHOSETURN]
and a
@@ -2209,7 +2240,7 @@ GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820)
.enemyTurn
ld a, 12
.next
- ld hl, wTileMap
+ coord hl, 0, 0
ld e, a
ld d, 0
add hl, de
@@ -2232,7 +2263,7 @@ GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820)
; de = tile ID list pointer
; b = number of rows
; c = number of columns
-GetTileIDList: ; 79842 (1e:5842)
+GetTileIDList:
ld hl, TileIDListPointerTable
ld e, a
ld d, 0
@@ -2253,29 +2284,32 @@ GetTileIDList: ; 79842 (1e:5842)
ld b, a
ret
-Func_7985b: ; 7985b (1e:585b)
+AnimCopyRowLeft:
+; copy a row of c tiles 1 tile left
ld a, [hld]
ld [hli], a
inc hl
dec c
- jr nz, Func_7985b
+ jr nz, AnimCopyRowLeft
ret
-Func_79862: ; 79862 (1e:5862)
+AnimCopyRowRight:
+; copy a row of c tiles 1 tile right
ld a, [hli]
ld [hld], a
dec hl
dec c
- jr nz, Func_79862
+ jr nz, AnimCopyRowRight
ret
-Func_79869: ; 79869 (1e:5869)
+; get the sound of the move id in b
+GetMoveSoundB:
ld a, b
- call Func_7986f
+ call GetMoveSound
ld b, a
ret
-Func_7986f: ; 7986f (1e:586f)
+GetMoveSound:
ld hl,MoveSoundTable
ld e,a
ld d,0
@@ -2298,26 +2332,26 @@ Func_7986f: ; 7986f (1e:586f)
call GetCryData
ld b,a
pop hl
- ld a,[wc0f1]
+ ld a,[wFrequencyModifier]
add [hl]
- ld [wc0f1],a
+ ld [wFrequencyModifier],a
inc hl
- ld a,[wc0f2]
+ ld a,[wTempoModifier]
add [hl]
- ld [wc0f2],a
+ ld [wTempoModifier],a
jr .done
.NotCryMove
ld a,[hli]
- ld [wc0f1],a
+ ld [wFrequencyModifier],a
ld a,[hli]
- ld [wc0f2],a
+ ld [wTempoModifier],a
.done
ld a,b
ret
-IsCryMove: ; 798ad (1e:58ad)
+IsCryMove:
; set carry if the move animation involves playing a monster cry
- ld a,[W_ANIMATIONID]
+ ld a,[wAnimationID]
cp a,GROWL
jr z,.CryMove
cp a,ROAR
@@ -2328,201 +2362,206 @@ IsCryMove: ; 798ad (1e:58ad)
scf
ret
-MoveSoundTable: ; 798bc (1e:58bc)
- db (SFX_08_4a - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_4c - SFX_Headers_08) / 3,$10,$80
- db (SFX_08_5d - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_4b - SFX_Headers_08) / 3,$01,$80
- db (SFX_08_4d - SFX_Headers_08) / 3,$00,$40
- db (SFX_08_77 - SFX_Headers_08) / 3,$00,$ff
- db (SFX_08_4d - SFX_Headers_08) / 3,$10,$60
- db (SFX_08_4d - SFX_Headers_08) / 3,$20,$80
- db (SFX_08_4d - SFX_Headers_08) / 3,$00,$a0
- db (SFX_08_50 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_4f - SFX_Headers_08) / 3,$20,$40
- db (SFX_08_4f - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_4e - SFX_Headers_08) / 3,$00,$a0
- db (SFX_08_51 - SFX_Headers_08) / 3,$10,$c0
- db (SFX_08_51 - SFX_Headers_08) / 3,$00,$a0
- db (SFX_08_52 - SFX_Headers_08) / 3,$00,$c0
- db (SFX_08_52 - SFX_Headers_08) / 3,$10,$a0
- db (SFX_08_53 - SFX_Headers_08) / 3,$00,$e0
- db (SFX_08_51 - SFX_Headers_08) / 3,$20,$c0
- db (SFX_08_54 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_62 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_55 - SFX_Headers_08) / 3,$01,$80
- db (SFX_08_60 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_57 - SFX_Headers_08) / 3,$f0,$40
- db (SFX_08_5a - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_57 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_61 - SFX_Headers_08) / 3,$10,$80
- db (SFX_08_5b - SFX_Headers_08) / 3,$01,$a0
- db (SFX_08_58 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_5e - SFX_Headers_08) / 3,$00,$60
- db (SFX_08_5e - SFX_Headers_08) / 3,$01,$40
- db (SFX_08_5f - SFX_Headers_08) / 3,$00,$a0
- db (SFX_08_5a - SFX_Headers_08) / 3,$10,$a0
- db (SFX_08_60 - SFX_Headers_08) / 3,$00,$c0
- db (SFX_08_54 - SFX_Headers_08) / 3,$10,$60
- db (SFX_08_5a - SFX_Headers_08) / 3,$00,$a0
- db (SFX_08_62 - SFX_Headers_08) / 3,$11,$c0
- db (SFX_08_5a - SFX_Headers_08) / 3,$20,$c0
- db (SFX_08_61 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_5b - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_5b - SFX_Headers_08) / 3,$20,$c0
- db (SFX_08_59 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_71 - SFX_Headers_08) / 3,$ff,$40
- db (SFX_08_5e - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_4b - SFX_Headers_08) / 3,$00,$c0
- db (SFX_08_4b - SFX_Headers_08) / 3,$00,$40
- db (SFX_08_75 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_67 - SFX_Headers_08) / 3,$40,$60
- db (SFX_08_67 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_67 - SFX_Headers_08) / 3,$ff,$40
- db (SFX_08_6a - SFX_Headers_08) / 3,$80,$c0
- db (SFX_08_59 - SFX_Headers_08) / 3,$10,$a0
- db (SFX_08_59 - SFX_Headers_08) / 3,$21,$e0
- db (SFX_08_69 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_64 - SFX_Headers_08) / 3,$20,$60
- db (SFX_08_6a - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_6c - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_68 - SFX_Headers_08) / 3,$40,$80
- db (SFX_08_69 - SFX_Headers_08) / 3,$f0,$e0
- db (SFX_08_6d - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_6a - SFX_Headers_08) / 3,$f0,$60
- db (SFX_08_68 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_76 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_47 - SFX_Headers_08) / 3,$01,$a0
- db (SFX_08_53 - SFX_Headers_08) / 3,$f0,$20
- db (SFX_08_63 - SFX_Headers_08) / 3,$01,$c0
- db (SFX_08_63 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_5a - SFX_Headers_08) / 3,$00,$e0
- db (SFX_08_66 - SFX_Headers_08) / 3,$01,$60
- db (SFX_08_66 - SFX_Headers_08) / 3,$20,$40
- db (SFX_08_64 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_64 - SFX_Headers_08) / 3,$40,$c0
- db (SFX_08_5b - SFX_Headers_08) / 3,$03,$60
- db (SFX_08_65 - SFX_Headers_08) / 3,$11,$e0
- db (SFX_08_52 - SFX_Headers_08) / 3,$20,$e0
- db (SFX_08_6e - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_5c - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_5c - SFX_Headers_08) / 3,$11,$a0
- db (SFX_08_5c - SFX_Headers_08) / 3,$01,$c0
- db (SFX_08_53 - SFX_Headers_08) / 3,$14,$c0
- db (SFX_08_5b - SFX_Headers_08) / 3,$02,$a0
- db (SFX_08_69 - SFX_Headers_08) / 3,$f0,$80
- db (SFX_08_69 - SFX_Headers_08) / 3,$20,$c0
- db (SFX_08_6f - SFX_Headers_08) / 3,$00,$20
- db (SFX_08_6f - SFX_Headers_08) / 3,$20,$80
- db (SFX_08_6e - SFX_Headers_08) / 3,$12,$60
- db (SFX_08_66 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_54 - SFX_Headers_08) / 3,$01,$e0
- db (SFX_08_69 - SFX_Headers_08) / 3,$0f,$e0
- db (SFX_08_69 - SFX_Headers_08) / 3,$11,$20
- db (SFX_08_50 - SFX_Headers_08) / 3,$10,$40
- db (SFX_08_4f - SFX_Headers_08) / 3,$10,$c0
- db (SFX_08_54 - SFX_Headers_08) / 3,$00,$20
- db (SFX_08_70 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_75 - SFX_Headers_08) / 3,$11,$18
- db (SFX_08_49 - SFX_Headers_08) / 3,$20,$c0
- db (SFX_08_48 - SFX_Headers_08) / 3,$20,$c0
- db (SFX_08_65 - SFX_Headers_08) / 3,$00,$10
- db (SFX_08_66 - SFX_Headers_08) / 3,$f0,$20
- db (SFX_08_73 - SFX_Headers_08) / 3,$f0,$c0
- db (SFX_08_51 - SFX_Headers_08) / 3,$f0,$e0
- db (SFX_08_49 - SFX_Headers_08) / 3,$f0,$40
- db (SFX_08_71 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_73 - SFX_Headers_08) / 3,$80,$40
- db (SFX_08_73 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_54 - SFX_Headers_08) / 3,$11,$20
- db (SFX_08_54 - SFX_Headers_08) / 3,$22,$10
- db (SFX_08_5b - SFX_Headers_08) / 3,$f1,$ff
- db (SFX_08_53 - SFX_Headers_08) / 3,$f1,$ff
- db (SFX_08_54 - SFX_Headers_08) / 3,$33,$30
- db (SFX_08_72 - SFX_Headers_08) / 3,$40,$c0
- db (SFX_08_4e - SFX_Headers_08) / 3,$20,$20
- db (SFX_08_4e - SFX_Headers_08) / 3,$f0,$10
- db (SFX_08_4f - SFX_Headers_08) / 3,$f8,$10
- db (SFX_08_51 - SFX_Headers_08) / 3,$f0,$10
- db (SFX_08_65 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_58 - SFX_Headers_08) / 3,$00,$c0
- db (SFX_08_72 - SFX_Headers_08) / 3,$c0,$ff
- db (SFX_08_49 - SFX_Headers_08) / 3,$f2,$20
- db (SFX_08_74 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_74 - SFX_Headers_08) / 3,$00,$40
- db (SFX_08_49 - SFX_Headers_08) / 3,$00,$40
- db (SFX_08_51 - SFX_Headers_08) / 3,$10,$ff
- db (SFX_08_6a - SFX_Headers_08) / 3,$20,$20
- db (SFX_08_72 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_69 - SFX_Headers_08) / 3,$1f,$20
- db (SFX_08_65 - SFX_Headers_08) / 3,$2f,$80
- db (SFX_08_4f - SFX_Headers_08) / 3,$1f,$ff
- db (SFX_08_6b - SFX_Headers_08) / 3,$1f,$60
- db (SFX_08_66 - SFX_Headers_08) / 3,$1e,$20
- db (SFX_08_66 - SFX_Headers_08) / 3,$1f,$18
- db (SFX_08_54 - SFX_Headers_08) / 3,$0f,$80
- db (SFX_08_49 - SFX_Headers_08) / 3,$f8,$10
- db (SFX_08_48 - SFX_Headers_08) / 3,$18,$20
- db (SFX_08_72 - SFX_Headers_08) / 3,$08,$40
- db (SFX_08_57 - SFX_Headers_08) / 3,$01,$e0
- db (SFX_08_51 - SFX_Headers_08) / 3,$09,$ff
- db (SFX_08_75 - SFX_Headers_08) / 3,$42,$01
- db (SFX_08_5c - SFX_Headers_08) / 3,$00,$ff
- db (SFX_08_72 - SFX_Headers_08) / 3,$08,$e0
- db (SFX_08_64 - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_49 - SFX_Headers_08) / 3,$88,$10
- db (SFX_08_65 - SFX_Headers_08) / 3,$48,$ff
- db (SFX_08_48 - SFX_Headers_08) / 3,$ff,$ff
- db (SFX_08_64 - SFX_Headers_08) / 3,$ff,$10
- db (SFX_08_48 - SFX_Headers_08) / 3,$ff,$04
- db (SFX_08_5c - SFX_Headers_08) / 3,$01,$ff
- db (SFX_08_53 - SFX_Headers_08) / 3,$f8,$ff
- db (SFX_08_4c - SFX_Headers_08) / 3,$f0,$f0
- db (SFX_08_4f - SFX_Headers_08) / 3,$08,$10
- db (SFX_08_4d - SFX_Headers_08) / 3,$f0,$ff
- db (SFX_08_5a - SFX_Headers_08) / 3,$f0,$ff
- db (SFX_08_74 - SFX_Headers_08) / 3,$10,$ff
- db (SFX_08_4e - SFX_Headers_08) / 3,$f0,$20
- db (SFX_08_6b - SFX_Headers_08) / 3,$f0,$60
- db (SFX_08_61 - SFX_Headers_08) / 3,$12,$10
- db (SFX_08_76 - SFX_Headers_08) / 3,$f0,$20
- db (SFX_08_5e - SFX_Headers_08) / 3,$12,$ff
- db (SFX_08_71 - SFX_Headers_08) / 3,$80,$04
- db (SFX_08_73 - SFX_Headers_08) / 3,$f0,$10
- db (SFX_08_69 - SFX_Headers_08) / 3,$f8,$ff
- db (SFX_08_66 - SFX_Headers_08) / 3,$f0,$ff
- db (SFX_08_51 - SFX_Headers_08) / 3,$01,$ff
- db (SFX_08_6c - SFX_Headers_08) / 3,$d8,$04
- db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80
- db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80
-
-Func_79aae: ; 79aae (1e:5aae)
+MoveSoundTable:
+ ; ID, pitch mod, tempo mod
+ db SFX_POUND, $00,$80 ; POUND
+ db SFX_BATTLE_0C, $10,$80 ; KARATE_CHOP
+ db SFX_DOUBLESLAP, $00,$80 ; DOUBLESLAP
+ db SFX_BATTLE_0B, $01,$80 ; COMET_PUNCH
+ db SFX_BATTLE_0D, $00,$40 ; MEGA_PUNCH
+ db SFX_SILPH_SCOPE, $00,$ff ; PAY_DAY
+ db SFX_BATTLE_0D, $10,$60 ; FIRE_PUNCH
+ db SFX_BATTLE_0D, $20,$80 ; ICE_PUNCH
+ db SFX_BATTLE_0D, $00,$a0 ; THUNDERPUNCH
+ db SFX_DAMAGE, $00,$80 ; SCRATCH
+ db SFX_BATTLE_0F, $20,$40 ; VICEGRIP
+ db SFX_BATTLE_0F, $00,$80 ; GUILLOTINE
+ db SFX_BATTLE_0E, $00,$a0 ; RAZOR_WIND
+ db SFX_NOT_VERY_EFFECTIVE,$10,$c0 ; SWORDS_DANCE
+ db SFX_NOT_VERY_EFFECTIVE,$00,$a0 ; CUT
+ db SFX_BATTLE_12, $00,$c0 ; GUST
+ db SFX_BATTLE_12, $10,$a0 ; WING_ATTACK
+ db SFX_BATTLE_13, $00,$e0 ; WHIRLWIND
+ db SFX_NOT_VERY_EFFECTIVE,$20,$c0 ; FLY
+ db SFX_BATTLE_14, $00,$80 ; BIND
+ db SFX_BATTLE_22, $00,$80 ; SLAM
+ db SFX_VINE_WHIP, $01,$80 ; VINE_WHIP
+ db SFX_BATTLE_20, $00,$80 ; STOMP
+ db SFX_BATTLE_17, $f0,$40 ; DOUBLE_KICK
+ db SFX_SUPER_EFFECTIVE, $00,$80 ; MEGA_KICK
+ db SFX_BATTLE_17, $00,$80 ; JUMP_KICK
+ db SFX_BATTLE_21, $10,$80 ; ROLLING_KICK
+ db SFX_BATTLE_1B, $01,$a0 ; SAND_ATTACK
+ db SFX_BATTLE_18, $00,$80 ; HEADBUTT
+ db SFX_BATTLE_1E, $00,$60 ; HORN_ATTACK
+ db SFX_BATTLE_1E, $01,$40 ; FURY_ATTACK
+ db SFX_HORN_DRILL, $00,$a0 ; HORN_DRILL
+ db SFX_SUPER_EFFECTIVE, $10,$a0 ; TACKLE
+ db SFX_BATTLE_20, $00,$c0 ; BODY_SLAM
+ db SFX_BATTLE_14, $10,$60 ; WRAP
+ db SFX_SUPER_EFFECTIVE, $00,$a0 ; TAKE_DOWN
+ db SFX_BATTLE_22, $11,$c0 ; THRASH
+ db SFX_SUPER_EFFECTIVE, $20,$c0 ; DOUBLE_EDGE
+ db SFX_BATTLE_21, $00,$80 ; TAIL_WHIP
+ db SFX_BATTLE_1B, $00,$80 ; POISON_STING
+ db SFX_BATTLE_1B, $20,$c0 ; TWINEEDLE
+ db SFX_BATTLE_19, $00,$80 ; PIN_MISSILE
+ db SFX_BATTLE_31, $ff,$40 ; LEER
+ db SFX_BATTLE_1E, $00,$80 ; BITE
+ db SFX_BATTLE_0B, $00,$c0 ; GROWL
+ db SFX_BATTLE_0B, $00,$40 ; ROAR
+ db SFX_BATTLE_35, $00,$80 ; SING
+ db SFX_BATTLE_27, $40,$60 ; SUPERSONIC
+ db SFX_BATTLE_27, $00,$80 ; SONICBOOM
+ db SFX_BATTLE_27, $ff,$40 ; DISABLE
+ db SFX_BATTLE_2A, $80,$c0 ; ACID
+ db SFX_BATTLE_19, $10,$a0 ; EMBER
+ db SFX_BATTLE_19, $21,$e0 ; FLAMETHROWER
+ db SFX_BATTLE_29, $00,$80 ; MIST
+ db SFX_BATTLE_24, $20,$60 ; WATER_GUN
+ db SFX_BATTLE_2A, $00,$80 ; HYDRO_PUMP
+ db SFX_BATTLE_2C, $00,$80 ; SURF
+ db SFX_BATTLE_28, $40,$80 ; ICE_BEAM
+ db SFX_BATTLE_29, $f0,$e0 ; BLIZZARD
+ db SFX_PSYBEAM, $00,$80 ; PSYBEAM
+ db SFX_BATTLE_2A, $f0,$60 ; BUBBLEBEAM
+ db SFX_BATTLE_28, $00,$80 ; AURORA_BEAM
+ db SFX_BATTLE_36, $00,$80 ; HYPER_BEAM
+ db SFX_PECK,$01, $a0 ; PECK
+ db SFX_BATTLE_13, $f0,$20 ; DRILL_PECK
+ db SFX_BATTLE_23, $01,$c0 ; SUBMISSION
+ db SFX_BATTLE_23, $00,$80 ; LOW_KICK
+ db SFX_SUPER_EFFECTIVE, $00,$e0 ; COUNTER
+ db SFX_BATTLE_26, $01,$60 ; SEISMIC_TOSS
+ db SFX_BATTLE_26, $20,$40 ; STRENGTH
+ db SFX_BATTLE_24, $00,$80 ; ABSORB
+ db SFX_BATTLE_24, $40,$c0 ; MEGA_DRAIN
+ db SFX_BATTLE_1B, $03,$60 ; LEECH_SEED
+ db SFX_BATTLE_25, $11,$e0 ; GROWTH
+ db SFX_BATTLE_12, $20,$e0 ; RAZOR_LEAF
+ db SFX_BATTLE_2E, $00,$80 ; SOLARBEAM
+ db SFX_BATTLE_1C, $00,$80 ; POISONPOWDER
+ db SFX_BATTLE_1C, $11,$a0 ; STUN_SPORE
+ db SFX_BATTLE_1C, $01,$c0 ; SLEEP_POWDER
+ db SFX_BATTLE_13, $14,$c0 ; PETAL_DANCE
+ db SFX_BATTLE_1B, $02,$a0 ; STRING_SHOT
+ db SFX_BATTLE_29, $f0,$80 ; DRAGON_RAGE
+ db SFX_BATTLE_29, $20,$c0 ; FIRE_SPIN
+ db SFX_BATTLE_2F, $00,$20 ; THUNDERSHOCK
+ db SFX_BATTLE_2F, $20,$80 ; THUNDERBOLT
+ db SFX_BATTLE_2E, $12,$60 ; THUNDER_WAVE
+ db SFX_BATTLE_26, $00,$80 ; THUNDER
+ db SFX_BATTLE_14, $01,$e0 ; ROCK_THROW
+ db SFX_BATTLE_29, $0f,$e0 ; EARTHQUAKE
+ db SFX_BATTLE_29, $11,$20 ; FISSURE
+ db SFX_DAMAGE, $10,$40 ; DIG
+ db SFX_BATTLE_0F, $10,$c0 ; TOXIC
+ db SFX_BATTLE_14, $00,$20 ; CONFUSION
+ db SFX_PSYCHIC_M, $00,$80 ; PSYCHIC_M
+ db SFX_BATTLE_35, $11,$18 ; HYPNOSIS
+ db SFX_BATTLE_09, $20,$c0 ; MEDITATE
+ db SFX_FAINT_FALL, $20,$c0 ; AGILITY
+ db SFX_BATTLE_25, $00,$10 ; QUICK_ATTACK
+ db SFX_BATTLE_26, $f0,$20 ; RAGE
+ db SFX_BATTLE_33, $f0,$c0 ; TELEPORT
+ db SFX_NOT_VERY_EFFECTIVE,$f0,$e0 ; NIGHT_SHADE
+ db SFX_BATTLE_09, $f0,$40 ; MIMIC
+ db SFX_BATTLE_31, $00,$80 ; SCREECH
+ db SFX_BATTLE_33, $80,$40 ; DOUBLE_TEAM
+ db SFX_BATTLE_33, $00,$80 ; RECOVER
+ db SFX_BATTLE_14, $11,$20 ; HARDEN
+ db SFX_BATTLE_14, $22,$10 ; MINIMIZE
+ db SFX_BATTLE_1B, $f1,$ff ; SMOKESCREEN
+ db SFX_BATTLE_13, $f1,$ff ; CONFUSE_RAY
+ db SFX_BATTLE_14, $33,$30 ; WITHDRAW
+ db SFX_BATTLE_32, $40,$c0 ; DEFENSE_CURL
+ db SFX_BATTLE_0E, $20,$20 ; BARRIER
+ db SFX_BATTLE_0E, $f0,$10 ; LIGHT_SCREEN
+ db SFX_BATTLE_0F, $f8,$10 ; HAZE
+ db SFX_NOT_VERY_EFFECTIVE,$f0,$10 ; REFLECT
+ db SFX_BATTLE_25, $00,$80 ; FOCUS_ENERGY
+ db SFX_BATTLE_18, $00,$c0 ; BIDE
+ db SFX_BATTLE_32, $c0,$ff ; METRONOME
+ db SFX_BATTLE_09, $f2,$20 ; MIRROR_MOVE
+ db SFX_BATTLE_34, $00,$80 ; SELFDESTRUCT
+ db SFX_BATTLE_34, $00,$40 ; EGG_BOMB
+ db SFX_BATTLE_09, $00,$40 ; LICK
+ db SFX_NOT_VERY_EFFECTIVE,$10,$ff ; SMOG
+ db SFX_BATTLE_2A, $20,$20 ; SLUDGE
+ db SFX_BATTLE_32, $00,$80 ; BONE_CLUB
+ db SFX_BATTLE_29, $1f,$20 ; FIRE_BLAST
+ db SFX_BATTLE_25, $2f,$80 ; WATERFALL
+ db SFX_BATTLE_0F, $1f,$ff ; CLAMP
+ db SFX_BATTLE_2B, $1f,$60 ; SWIFT
+ db SFX_BATTLE_26, $1e,$20 ; SKULL_BASH
+ db SFX_BATTLE_26, $1f,$18 ; SPIKE_CANNON
+ db SFX_BATTLE_14, $0f,$80 ; CONSTRICT
+ db SFX_BATTLE_09, $f8,$10 ; AMNESIA
+ db SFX_FAINT_FALL, $18,$20 ; KINESIS
+ db SFX_BATTLE_32, $08,$40 ; SOFTBOILED
+ db SFX_BATTLE_17, $01,$e0 ; HI_JUMP_KICK
+ db SFX_NOT_VERY_EFFECTIVE,$09,$ff ; GLARE
+ db SFX_BATTLE_35, $42,$01 ; DREAM_EATER
+ db SFX_BATTLE_1C, $00,$ff ; POISON_GAS
+ db SFX_BATTLE_32, $08,$e0 ; BARRAGE
+ db SFX_BATTLE_24, $00,$80 ; LEECH_LIFE
+ db SFX_BATTLE_09, $88,$10 ; LOVELY_KISS
+ db SFX_BATTLE_25, $48,$ff ; SKY_ATTACK
+ db SFX_FAINT_FALL, $ff,$ff ; TRANSFORM
+ db SFX_BATTLE_24, $ff,$10 ; BUBBLE
+ db SFX_FAINT_FALL, $ff,$04 ; DIZZY_PUNCH
+ db SFX_BATTLE_1C, $01,$ff ; SPORE
+ db SFX_BATTLE_13, $f8,$ff ; FLASH
+ db SFX_BATTLE_0C, $f0,$f0 ; PSYWAVE
+ db SFX_BATTLE_0F, $08,$10 ; SPLASH
+ db SFX_BATTLE_0D, $f0,$ff ; ACID_ARMOR
+ db SFX_SUPER_EFFECTIVE, $f0,$ff ; CRABHAMMER
+ db SFX_BATTLE_34, $10,$ff ; EXPLOSION
+ db SFX_BATTLE_0E, $f0,$20 ; FURY_SWIPES
+ db SFX_BATTLE_2B, $f0,$60 ; BONEMERANG
+ db SFX_BATTLE_21, $12,$10 ; REST
+ db SFX_BATTLE_36, $f0,$20 ; ROCK_SLIDE
+ db SFX_BATTLE_1E, $12,$ff ; HYPER_FANG
+ db SFX_BATTLE_31, $80,$04 ; SHARPEN
+ db SFX_BATTLE_33, $f0,$10 ; CONVERSION
+ db SFX_BATTLE_29, $f8,$ff ; TRI_ATTACK
+ db SFX_BATTLE_26, $f0,$ff ; SUPER_FANG
+ db SFX_NOT_VERY_EFFECTIVE,$01,$ff ; SLASH
+ db SFX_BATTLE_2C, $d8,$04 ; SUBSTITUTE
+ db SFX_BATTLE_0B, $00,$80 ; STRUGGLE
+ db SFX_BATTLE_0B, $00,$80
+
+CopyPicTiles:
ld a, [H_WHOSETURN]
and a
ld a, $31 ; base tile ID of player mon sprite
- jr z, .asm_79ab6
+ jr z, .next
; enemy turn
xor a ; base tile ID of enemy mon sprite
-.asm_79ab6
+.next
ld [hBaseTileID], a
- jr asm_79acb
+ jr CopyTileIDs_NoBGTransfer
-Func_79aba: ; 79aba (1e:5aba)
+; copy the tiles used when a mon is being sent out of or into a pokeball
+CopyDownscaledMonTiles:
call GetPredefRegisters
- ld a, [wcd6c]
+ ld a, [wDownscaledMonSize]
and a
- jr nz, .asm_79ac8
- ld de, Unknown_79b02 ; $5b02
- jr asm_79acb
-.asm_79ac8
- ld de, Unknown_79b1b ; $5b1b
-asm_79acb: ; 79acb (1e:5acb)
+ jr nz, .smallerSize
+ ld de, DownscaledMonTiles_5x5
+ jr CopyTileIDs_NoBGTransfer
+.smallerSize
+ ld de, DownscaledMonTiles_3x3
+; fall through
+
+CopyTileIDs_NoBGTransfer:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
+; fall through
; b = number of rows
; c = number of columns
-CopyTileIDs: ; 79ace (1e:5ace)
+CopyTileIDs:
push hl
.rowLoop
push bc
@@ -2547,7 +2586,7 @@ CopyTileIDs: ; 79ace (1e:5ace)
pop hl
ret
-TileIDListPointerTable: ; 79aea (1e:5aea)
+TileIDListPointerTable:
dw Unknown_79b24
db $77
dw Unknown_79b55
@@ -2565,19 +2604,19 @@ TileIDListPointerTable: ; 79aea (1e:5aea)
dw Unknown_79c50
db $3C
-Unknown_79b02: ; 79b02 (1e:5b02)
+DownscaledMonTiles_5x5:
db $31,$38,$46,$54,$5B
db $32,$39,$47,$55,$5C
db $34,$3B,$49,$57,$5E
db $36,$3D,$4B,$59,$60
db $37,$3E,$4C,$5A,$61
-Unknown_79b1b: ; 79b1b (1e:5b1b)
+DownscaledMonTiles_3x3:
db $31,$46,$5B
db $34,$49,$5E
db $37,$4C,$61
-Unknown_79b24: ; 79b24 (1e:5b24)
+Unknown_79b24:
db $00,$07,$0E,$15,$1C,$23,$2A
db $01,$08,$0F,$16,$1D,$24,$2B
db $02,$09,$10,$17,$1E,$25,$2C
@@ -2586,19 +2625,19 @@ Unknown_79b24: ; 79b24 (1e:5b24)
db $05,$0C,$13,$1A,$21,$28,$2F
db $06,$0D,$14,$1B,$22,$29,$30
-Unknown_79b55: ; 79b55 (1e:5b55)
+Unknown_79b55:
db $00,$07,$0E,$15,$1C,$23,$2A
db $01,$08,$0F,$16,$1D,$24,$2B
db $03,$0A,$11,$18,$1F,$26,$2D
db $04,$0B,$12,$19,$20,$27,$2E
db $05,$0C,$13,$1A,$21,$28,$2F
-Unknown_79b78: ; 79b78 (1e:5b78)
+Unknown_79b78:
db $00,$07,$0E,$15,$1C,$23,$2A
db $02,$09,$10,$17,$1E,$25,$2C
db $04,$0B,$12,$19,$20,$27,$2E
-Unknown_79b8d: ; 79b8d (1e:5b8d)
+Unknown_79b8d:
db $00,$00,$00,$00,$00,$00,$00
db $00,$00,$00,$00,$00,$19,$00
db $02,$06,$0B,$10,$14,$1A,$00
@@ -2607,7 +2646,7 @@ Unknown_79b8d: ; 79b8d (1e:5b8d)
db $04,$09,$0E,$13,$17,$1D,$1F
db $05,$0A,$0F,$01,$18,$1E,$20
-Unknown_79bbe: ; 79bbe (1e:5bbe)
+Unknown_79bbe:
db $00,$00,$00,$30,$00,$37,$00
db $00,$00,$2B,$31,$34,$38,$3D
db $21,$26,$2C,$01,$35,$39,$3E
@@ -2616,7 +2655,7 @@ Unknown_79bbe: ; 79bbe (1e:5bbe)
db $24,$29,$2F,$01,$01,$3B,$00
db $25,$2A,$01,$01,$01,$3C,$00
-Unknown_79bef: ; 79bef (1e:5bef)
+Unknown_79bef:
db $00,$00,$00,$00,$00,$00,$00
db $00,$00,$47,$4D,$00,$00,$00
db $00,$00,$48,$4E,$52,$56,$5B
@@ -2625,7 +2664,7 @@ Unknown_79bef: ; 79bef (1e:5bef)
db $41,$45,$4B,$51,$4C,$59,$5D
db $42,$46,$4C,$4C,$55,$5A,$5E
-Unknown_79c20: ; 79c20 (1e:5c20)
+Unknown_79c20:
db $31,$32,$32,$32,$32,$33
db $34,$35,$36,$36,$37,$38
db $34,$39,$3A,$3A,$3B,$38
@@ -2635,138 +2674,143 @@ Unknown_79c20: ; 79c20 (1e:5c20)
db $41,$43,$4B,$4C,$4D,$4E
db $4F,$50,$50,$50,$51,$52
-Unknown_79c50: ; 79c50 (1e:5c50)
+Unknown_79c50:
db $43,$55,$56,$53,$53,$53,$53,$53,$53,$53,$53,$53
db $43,$57,$58,$54,$54,$54,$54,$54,$54,$54,$54,$54
db $43,$59,$5A,$43,$43,$43,$43,$43,$43,$43,$43,$43
-AnimationLeavesFalling: ; 79c74 (1e:5c74)
+AnimationLeavesFalling:
; Makes leaves float down from the top of the screen. This is used
; in Razor Leaf's animation.
- ld a, [$ff48]
+ ld a, [rOBP0]
push af
- ld a, [wcc79]
- ld [$ff48], a
- ld d, $37
- ld a, $3
- ld [W_SUBANIMTRANSFORM], a
- call Func_79c97
+ ld a, [wAnimPalette]
+ ld [rOBP0], a
+ ld d, $37 ; leaf tile
+ ld a, 3 ; number of leaves
+ ld [wNumFallingObjects], a
+ call AnimationFallingObjects
pop af
- ld [$ff48], a
+ ld [rOBP0], a
ret
-AnimationPetalsFalling: ; 79c8a (1e:5c8a)
+AnimationPetalsFalling:
; Makes lots of petals fall down from the top of the screen. It's used in
; the animation for Petal Dance.
- ld d, $71
- ld a, $14
- ld [W_SUBANIMTRANSFORM], a
- call Func_79c97
+ ld d, $71 ; petal tile
+ ld a, 20 ; number of petals
+ ld [wNumFallingObjects], a
+ call AnimationFallingObjects
jp ClearSprites
-Func_79c97: ; 79c97 (1e:5c97)
+AnimationFallingObjects:
ld c, a
- ld a, $1
- call Func_797e8
- call Func_79d2a
- call Func_79d52
+ ld a, 1
+ call InitMultipleObjectsOAM
+ call FallingObjects_InitXCoords
+ call FallingObjects_InitMovementData
ld hl, wOAMBuffer
- ld [hl], $0
-.asm_79ca8
- ld hl, wTrainerSpriteOffset
- ld de, $0000
- ld a, [W_SUBANIMTRANSFORM]
+ ld [hl], 0
+.loop
+ ld hl, wFallingObjectsMovementData
+ ld de, 0
+ ld a, [wNumFallingObjects]
ld c, a
-.asm_79cb2
+.innerLoop
push bc
push hl
push de
ld a, [hl]
- ld [wd08a], a
- call Func_79d16
- call Func_79cdb
+ ld [wFallingObjectMovementByte], a
+ call FallingObjects_UpdateMovementByte
+ call FallingObjects_UpdateOAMEntry
pop de
- ld hl, $0004
+ ld hl, 4
add hl, de
ld e, l
ld d, h
pop hl
- ld a, [wd08a]
+ ld a, [wFallingObjectMovementByte]
ld [hli], a
pop bc
dec c
- jr nz, .asm_79cb2
+ jr nz, .innerLoop
call Delay3
ld hl, wOAMBuffer
- ld a, [hl]
- cp $68
- jr nz, .asm_79ca8
+ ld a, [hl] ; Y
+ cp 104 ; has the top falling object reached 104 yet?
+ jr nz, .loop ; keep moving the falling objects down until it does
ret
-Func_79cdb: ; 79cdb (1e:5cdb)
+FallingObjects_UpdateOAMEntry:
+; Increases Y by 2 pixels and adjusts X and X flip based on the falling object's
+; movement byte.
ld hl, wOAMBuffer
add hl, de
ld a, [hl]
inc a
inc a
- cp $70
- jr c, .asm_79ce8
- ld a, $a0
-.asm_79ce8
- ld [hli], a
- ld a, [wd08a]
+ cp 112
+ jr c, .next
+ ld a, 160 ; if Y >= 112, put it off-screen
+.next
+ ld [hli], a ; Y
+ ld a, [wFallingObjectMovementByte]
ld b, a
- ld de, Unknown_79d0d
+ ld de, FallingObjects_DeltaXs
and $7f
add e
- jr nc, .asm_79cf6
+ jr nc, .noCarry
inc d
-.asm_79cf6
+.noCarry
ld e, a
ld a, b
and $80
- jr nz, .asm_79d03
+ jr nz, .movingLeft
+; moving right
ld a, [de]
add [hl]
- ld [hli], a
+ ld [hli], a ; X
inc hl
- xor a
- jr .asm_79d0b
-.asm_79d03
+ xor a ; no horizontal flip
+ jr .next2
+.movingLeft
ld a, [de]
ld b, a
ld a, [hl]
sub b
- ld [hli], a
+ ld [hli], a ; X
inc hl
- ld a, $20
-.asm_79d0b
- ld [hl], a
+ ld a, (1 << OAM_X_FLIP)
+.next2
+ ld [hl], a ; attribute
ret
-Unknown_79d0d: ; 79d0d (1e:5d0d)
- db $00,$01,$03,$05,$07,$09,$0B,$0D,$0F
+FallingObjects_DeltaXs:
+ db 0, 1, 3, 5, 7, 9, 11, 13, 15
-Func_79d16: ; 79d16 (1e:5d16)
- ld a, [wd08a]
+FallingObjects_UpdateMovementByte:
+ ld a, [wFallingObjectMovementByte]
inc a
ld b, a
and $7f
- cp $9
+ cp 9 ; have we reached the end of the delta-Xs?
ld a, b
- jr nz, .asm_79d26
+ jr nz, .next
+; We've reached the end of the delta-Xs, so wrap to the start and change
+; direction from right to left or vice versa.
and $80
xor $80
-.asm_79d26
- ld [wd08a], a
+.next
+ ld [wFallingObjectMovementByte], a
ret
-Func_79d2a: ; 79d2a (1e:5d2a)
+FallingObjects_InitXCoords:
ld hl, wOAMBuffer + $01
- ld de, Unknown_79d3e
- ld a, [W_SUBANIMTRANSFORM]
+ ld de, FallingObjects_InitialXCoords
+ ld a, [wNumFallingObjects]
ld c, a
-.asm_79d34
+.loop
ld a, [de]
ld [hli], a
inc hl
@@ -2774,70 +2818,102 @@ Func_79d2a: ; 79d2a (1e:5d2a)
inc hl
inc de
dec c
- jr nz, .asm_79d34
+ jr nz, .loop
ret
-Unknown_79d3e: ; 79d3e (1e:5d3e)
+FallingObjects_InitialXCoords:
db $38,$40,$50,$60,$70,$88,$90,$56,$67,$4A,$77,$84,$98,$32,$22,$5C,$6C,$7D,$8E,$99
-Func_79d52: ; 79d52 (1e:5d52)
- ld hl, wTrainerSpriteOffset
- ld de, Unknown_79d63
- ld a, [W_SUBANIMTRANSFORM]
+FallingObjects_InitMovementData:
+ ld hl, wFallingObjectsMovementData
+ ld de, FallingObjects_InitialMovementData
+ ld a, [wNumFallingObjects]
ld c, a
-.asm_79d5c
+.loop
ld a, [de]
ld [hli], a
inc de
dec c
- jr nz, .asm_79d5c
+ jr nz, .loop
ret
-Unknown_79d63: ; 79d63 (1e:5d63)
+FallingObjects_InitialMovementData:
db $00,$84,$06,$81,$02,$88,$01,$83,$05,$89,$09,$80,$07,$87,$03,$82,$04,$85,$08,$86
-AnimationShakeEnemyHUD: ; 79d77 (1e:5d77)
+AnimationShakeEnemyHUD:
+; Shakes the enemy HUD.
+
+; Make a copy of the back pic's tile patterns in sprite tile pattern VRAM.
ld de, vBackPic
ld hl, vSprites
ld bc, 7 * 7
call CopyVideoData
+
xor a
ld [hSCX], a
+
+; Copy wTileMap to BG map 0. The regular BG (not the window) is set to use
+; map 0 and can be scrolled with SCX, which allows a shaking effect.
ld hl, vBGMap0
- call Func_79e0d
- ld a, $90
+ call BattleAnimCopyTileMapToVRAM
+
+; Now that the regular BG is showing the same thing the window was, move the
+; window off the screen so that we can modify its contents below.
+ ld a, SCREEN_HEIGHT_PIXELS
ld [hWY], a
- ld hl, vBGMap0 + $320
- call Func_79e0d
- ld a, $38
+
+; Copy wTileMap to VRAM such that the row below the enemy HUD (in wTileMap) is
+; lined up with row 0 of the window.
+ ld hl, vBGMap1 - $20 * 7
+ call BattleAnimCopyTileMapToVRAM
+
+; Move the window so that the row below the enemy HUD (in BG map 0) lines up
+; with the top row of the window on the screen. This makes it so that the window
+; covers everything below the enemy HD with a copy that looks just like what
+; was there before.
+ ld a, 7 * 8
ld [hWY], a
- call Func_792fd
+
+; Write OAM entries so that the copy of the back pic from the top of this
+; function shows up on screen. We need this because the back pic's Y coordinates
+; range overlaps with that of the enemy HUD and we don't want to shake the top
+; of the back pic when we shake the enemy HUD. The OAM copy won't be affected
+; by SCX.
+ call ShakeEnemyHUD_WritePlayerMonPicOAM
+
ld hl, vBGMap0
- call Func_79e0d
+ call BattleAnimCopyTileMapToVRAM
+
+; Remove the back pic from the BG map.
call AnimationHideMonPic
call Delay3
- ld de, $0208
- call Func_79de9
+
+; Use SCX to shake the regular BG. The window and the back pic OAM copy are
+; not affected.
+ lb de, 2, 8
+ call ShakeEnemyHUD_ShakeBG
+
+; Restore the original graphics.
call AnimationShowMonPic
call ClearSprites
- ld a, $90
+ ld a, SCREEN_HEIGHT_PIXELS
ld [hWY], a
ld hl, vBGMap1
- call Func_79e0d
+ call BattleAnimCopyTileMapToVRAM
xor a
ld [hWY], a
call SaveScreenTilesToBuffer1
ld hl, vBGMap0
- call Func_79e0d
+ call BattleAnimCopyTileMapToVRAM
call ClearScreen
call Delay3
call LoadScreenTilesFromBuffer1
ld hl, vBGMap1
- jp Func_79e0d
+ jp BattleAnimCopyTileMapToVRAM
; b = tile ID list index
; c = base tile ID
-CopyTileIDsFromList: ; 79dda (1e:5dda)
+CopyTileIDsFromList:
call GetPredefRegisters
ld a, c
ld [hBaseTileID], a
@@ -2847,38 +2923,38 @@ CopyTileIDsFromList: ; 79dda (1e:5dda)
pop hl
jp CopyTileIDs
-Func_79de9: ; 79de9 (1e:5de9)
+ShakeEnemyHUD_ShakeBG:
ld a, [hSCX]
- ld [wTrainerSpriteOffset], a
-.asm_79dee
- ld a, [wTrainerSpriteOffset]
+ ld [wTempSCX], a
+.loop
+ ld a, [wTempSCX]
add d
ld [hSCX], a
- ld c, $2
+ ld c, 2
call DelayFrames
- ld a, [wTrainerSpriteOffset]
+ ld a, [wTempSCX]
sub d
ld [hSCX], a
- ld c, $2
+ ld c, 2
call DelayFrames
dec e
- jr nz, .asm_79dee
- ld a, [wTrainerSpriteOffset]
+ jr nz, .loop
+ ld a, [wTempSCX]
ld [hSCX], a
ret
-Func_79e0d: ; 79e0d (1e:5e0d)
+BattleAnimCopyTileMapToVRAM:
ld a, h
- ld [$ffbd], a
+ ld [H_AUTOBGTRANSFERDEST + 1], a
ld a, l
ld [H_AUTOBGTRANSFERDEST], a
jp Delay3
-TossBallAnimation: ; 79e16 (1e:5e16)
- ld a,[W_ISINBATTLE]
+TossBallAnimation:
+ ld a,[wIsInBattle]
cp a,2
jr z,.BlockBall ; if in trainer battle, play different animation
- ld a,[wd11e]
+ ld a,[wPokeBallAnimData]
ld b,a
; upper nybble: how many animations (from PokeBallAnimations) to play
@@ -2891,7 +2967,7 @@ TossBallAnimation: ; 79e16 (1e:5e16)
; store these for later
ld a,b
and a,$F
- ld [wWhichTrade],a
+ ld [wNumShakes],a
ld hl,.PokeBallAnimations
; choose which toss animation to use
@@ -2906,7 +2982,7 @@ TossBallAnimation: ; 79e16 (1e:5e16)
.done
ld a,b
.PlayNextAnimation
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
push bc
push hl
call PlayAnimation
@@ -2917,42 +2993,42 @@ TossBallAnimation: ; 79e16 (1e:5e16)
jr nz,.PlayNextAnimation
ret
-.PokeBallAnimations: ; 79e50 (1e:5e50)
+.PokeBallAnimations:
; sequence of animations that make up the Poké Ball toss
db POOF_ANIM,HIDEPIC_ANIM,SHAKE_ANIM,POOF_ANIM,SHOWPIC_ANIM
-.BlockBall ; 5E55
+.BlockBall
ld a,TOSS_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
call PlayAnimation
- ld a,(SFX_08_43 - SFX_Headers_08) / 3
- call PlaySound ; play sound effect
+ ld a,SFX_FAINT_THUD
+ call PlaySound
ld a,BLOCKBALL_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
jp PlayAnimation
-PlayApplyingAttackSound: ; 79e6a (1e:5e6a)
+PlayApplyingAttackSound:
; play a different sound depending if move is not very effective, neutral, or super-effective
; don't play any sound at all if move is ineffective
call WaitForSoundToFinish
ld a, [wDamageMultipliers]
and $7f
ret z
- cp $a
+ cp 10
ld a, $20
ld b, $30
- ld c, (SFX_08_50 - SFX_Headers_08) / 3
- jr z, .asm_79e8b
+ ld c, SFX_DAMAGE
+ jr z, .playSound
ld a, $e0
ld b, $ff
- ld c, (SFX_08_5a - SFX_Headers_08) / 3
- jr nc, .asm_79e8b
+ ld c, SFX_SUPER_EFFECTIVE
+ jr nc, .playSound
ld a, $50
ld b, $1
- ld c, (SFX_08_51 - SFX_Headers_08) / 3
-.asm_79e8b
- ld [wc0f1], a
+ ld c, SFX_NOT_VERY_EFFECTIVE
+.playSound
+ ld [wFrequencyModifier], a
ld a, b
- ld [wc0f2], a
+ ld [wTempoModifier], a
ld a, c
jp PlaySound
diff --git a/engine/battle/bank_e_misc.asm b/engine/battle/bank_e_misc.asm
index 78b27108..33af6f6f 100644..100755
--- a/engine/battle/bank_e_misc.asm
+++ b/engine/battle/bank_e_misc.asm
@@ -1,5 +1,5 @@
; formats a string at wMovesString that lists the moves at wMoves
-FormatMovesString: ; 39b87 (e:5b87)
+FormatMovesString:
ld hl, wMoves
ld de, wMovesString
ld b, $0
@@ -24,7 +24,7 @@ FormatMovesString: ; 39b87 (e:5b87)
jr .copyNameLoop
.doneCopyingName
ld a, b
- ld [wcd6c], a
+ ld [wNumMovesMinusOne], a
inc b
ld a, $4e ; line break
ld [de], a
@@ -52,49 +52,49 @@ FormatMovesString: ; 39b87 (e:5b87)
ret
; XXX this is called in a few places, but it doesn't appear to do anything useful
-Func_39bd5: ; 39bd5 (e:5bd5)
- ld a, [wd11b]
- cp $1
- jr nz, .asm_39be6
+InitList:
+ ld a, [wInitListType]
+ cp INIT_ENEMYOT_LIST
+ jr nz, .notEnemy
ld hl, wEnemyPartyCount
ld de, wEnemyMonOT
ld a, ENEMYOT_NAME
- jr .asm_39c18
-.asm_39be6
- cp $4
- jr nz, .calcAttackStat4
+ jr .done
+.notEnemy
+ cp INIT_PLAYEROT_LIST
+ jr nz, .notPlayer
ld hl, wPartyCount
ld de, wPartyMonOT
ld a, PLAYEROT_NAME
- jr .asm_39c18
-.calcAttackStat4
- cp $5
- jr nz, .asm_39c02
- ld hl, wStringBuffer2 + 11
+ jr .done
+.notPlayer
+ cp INIT_MON_LIST
+ jr nz, .notMonster
+ ld hl, wItemList
ld de, MonsterNames
ld a, MONSTER_NAME
- jr .asm_39c18
-.asm_39c02
- cp $2
- jr nz, .asm_39c10
+ jr .done
+.notMonster
+ cp INIT_BAG_ITEM_LIST
+ jr nz, .notBag
ld hl, wNumBagItems
ld de, ItemNames
ld a, ITEM_NAME
- jr .asm_39c18
-.asm_39c10
- ld hl, wStringBuffer2 + 11
+ jr .done
+.notBag
+ ld hl, wItemList
ld de, ItemNames
ld a, ITEM_NAME
-.asm_39c18
+.done
ld [wNameListType], a
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
ld a, e
- ld [wcf8d], a
+ ld [wUnusedCF8D], a
ld a, d
- ld [wcf8e], a
+ ld [wUnusedCF8D + 1], a
ld bc, ItemPrices
ld a, c
ld [wItemPrices], a
@@ -102,10 +102,10 @@ Func_39bd5: ; 39bd5 (e:5bd5)
ld [wItemPrices + 1], a
ret
-; get species of mon e in list [wcc49] for LoadMonData
-GetMonSpecies: ; 39c37 (e:5c37)
+; get species of mon e in list [wMonDataLocation] for LoadMonData
+GetMonSpecies:
ld hl, wPartySpecies
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and a
jr z, .getSpecies
dec a
@@ -119,4 +119,4 @@ GetMonSpecies: ; 39c37 (e:5c37)
add hl, de
ld a, [hl]
ld [wcf91], a
- ret \ No newline at end of file
+ ret
diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm
index f1aa4161..9e02c56f 100644
--- a/engine/battle/battle_transitions.asm
+++ b/engine/battle/battle_transitions.asm
@@ -1,5 +1,5 @@
-BattleTransition: ; 7096d (1c:496d)
- ld a, $1
+BattleTransition:
+ ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
xor a
@@ -7,10 +7,13 @@ BattleTransition: ; 7096d (1c:496d)
dec a
ld [wUpdateSpritesEnabled], a
call DelayFrame
+
+; Determine which OAM block is being used by the enemy trainer sprite (if there
+; is one).
ld hl, wSpriteStateData1 + 2
- ld a, [H_DOWNARROWBLINKCNT2]
+ ld a, [hSpriteIndexOrTextID] ; enemy trainer sprite index (0 if wild battle)
ld c, a
- ld b, $0
+ ld b, 0
ld de, $10
.loop1
ld a, [hl]
@@ -21,13 +24,15 @@ BattleTransition: ; 7096d (1c:496d)
add hl, de
dec c
jr nz, .loop1
+
+; Clear OAM except for the blocks used by the player and enemy trainer sprites.
ld hl, wOAMBuffer + $10
- ld c, $9
+ ld c, 9
.loop2
ld a, b
swap a
cp l
- jr z, .skip2
+ jr z, .skip2 ; skip clearing the block if the enemy trainer is using it
push hl
push bc
ld bc, $10
@@ -40,9 +45,10 @@ BattleTransition: ; 7096d (1c:496d)
add hl, de
dec c
jr nz, .loop2
+
call Delay3
call LoadBattleTransitionTile
- ld bc, $0
+ ld bc, 0
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr z, .linkBattle
@@ -64,7 +70,7 @@ BattleTransition: ; 7096d (1c:496d)
; bit 0: set if trainer battle
; bit 1: set if enemy is at least 3 levels higher than player
; bit 2: set if dungeon map
-BattleTransitions: ; 709d2 (1c:49d2)
+BattleTransitions:
dw BattleTransition_DoubleCircle ; %000
dw BattleTransition_Spiral ; %001
dw BattleTransition_Circle ; %010
@@ -74,9 +80,9 @@ BattleTransitions: ; 709d2 (1c:49d2)
dw BattleTransition_VerticalStripes ; %110
dw BattleTransition_Split ; %111
-GetBattleTransitionID_WildOrTrainer: ; 709e2 (1c:49e2)
- ld a, [W_CUROPPONENT]
- cp $c8
+GetBattleTransitionID_WildOrTrainer:
+ ld a, [wCurOpponent]
+ cp 200
jr nc, .trainer
res 0, c
ret
@@ -84,7 +90,7 @@ GetBattleTransitionID_WildOrTrainer: ; 709e2 (1c:49e2)
set 0, c
ret
-GetBattleTransitionID_CompareLevels: ; 709ef (1c:49ef)
+GetBattleTransitionID_CompareLevels:
ld hl, wPartyMon1HP
.faintedLoop
ld a, [hli]
@@ -99,24 +105,24 @@ GetBattleTransitionID_CompareLevels: ; 709ef (1c:49ef)
ld a, [hl]
add $3
ld e, a
- ld a, [W_CURENEMYLVL]
+ ld a, [wCurEnemyLVL]
sub e
jr nc, .highLevelEnemy
res 1, c
- ld a, $1
- ld [wcd47], a
+ ld a, 1
+ ld [wBattleTransitionSpiralDirection], a
ret
.highLevelEnemy
set 1, c
xor a
- ld [wcd47], a
+ ld [wBattleTransitionSpiralDirection], a
ret
; fails to recognize VICTORY_ROAD_2, VICTORY_ROAD_3, all ROCKET_HIDEOUT maps,
; MANSION_1, SEAFOAM_ISLANDS_[2-5], POWER_PLANT, DIGLETTS_CAVE
; and SILPH_CO_[9-11]F as dungeon maps
-GetBattleTransitionID_IsDungeonMap: ; 70a19 (1c:4a19)
- ld a, [W_CURMAP]
+GetBattleTransitionID_IsDungeonMap:
+ ld a, [wCurMap]
ld e, a
ld hl, DungeonMaps1
.loop1
@@ -145,18 +151,18 @@ GetBattleTransitionID_IsDungeonMap: ; 70a19 (1c:4a19)
res 2, c
ret
-; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP
+; GetBattleTransitionID_IsDungeonMap checks if wCurMap
; is equal to one of these maps
-DungeonMaps1: ; 70a3f (1c:4a3f)
+DungeonMaps1:
db VIRIDIAN_FOREST
db ROCK_TUNNEL_1
db SEAFOAM_ISLANDS_1
db ROCK_TUNNEL_2
db $FF
-; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP
+; GetBattleTransitionID_IsDungeonMap checks if wCurMap
; is in between or equal to each pair of maps
-DungeonMaps2: ; 70a44 (1c:4a44)
+DungeonMaps2:
; all MT_MOON maps
db MT_MOON_1
db MT_MOON_3
@@ -175,16 +181,17 @@ DungeonMaps2: ; 70a44 (1c:4a44)
db UNKNOWN_DUNGEON_1
db $FF
-LoadBattleTransitionTile: ; 70a4d (1c:4a4d)
+LoadBattleTransitionTile:
ld hl, vChars1 + $7f0
ld de, BattleTransitionTile
- ld bc, (BANK(BattleTransitionTile) << 8) + $01
+ lb bc, BANK(BattleTransitionTile), (BattleTransitionTileEnd - BattleTransitionTile) / $10
jp CopyVideoData
-BattleTransitionTile: ; 70a59 (1c:4a59)
+BattleTransitionTile:
INCBIN "gfx/battle_transition.2bpp"
+BattleTransitionTileEnd:
-BattleTransition_BlackScreen: ; 70a69 (1c:4a69)
+BattleTransition_BlackScreen:
ld a, $ff
ld [rBGP], a
ld [rOBP0], a
@@ -195,61 +202,61 @@ BattleTransition_BlackScreen: ; 70a69 (1c:4a69)
; called regardless of mon levels, but does an
; outward spiral if enemy is at least 3 levels
; higher than player and does an inward spiral otherwise
-BattleTransition_Spiral: ; 70a72 (1c:4a72)
- ld a, [wcd47]
+BattleTransition_Spiral:
+ ld a, [wBattleTransitionSpiralDirection]
and a
jr z, .outwardSpiral
call BattleTransition_InwardSpiral
jr .done
.outwardSpiral
- hlCoord 10, 10
+ coord hl, 10, 10
ld a, $3
- ld [wd09f], a
+ ld [wOutwardSpiralCurrentDirection], a
ld a, l
- ld [wd09b], a
+ ld [wOutwardSpiralTileMapPointer + 1], a
ld a, h
- ld [wd09a], a
- ld b, $78
-.loop1
- ld c, $3
-.loop2
+ ld [wOutwardSpiralTileMapPointer], a
+ ld b, 120
+.loop
+ ld c, 3
+.innerLoop
push bc
call BattleTransition_OutwardSpiral_
pop bc
dec c
- jr nz, .loop2
+ jr nz, .innerLoop
call DelayFrame
dec b
- jr nz, .loop1
+ jr nz, .loop
.done
call BattleTransition_BlackScreen
xor a
- ld [wd09b], a
- ld [wd09a], a
+ ld [wOutwardSpiralTileMapPointer + 1], a
+ ld [wOutwardSpiralTileMapPointer], a
ret
-BattleTransition_InwardSpiral: ; 70aaa (1c:4aaa)
- ld a, $7
- ld [wWhichTrade], a
- ld hl, wTileMap
- ld c, $11
- ld de, $14
+BattleTransition_InwardSpiral:
+ ld a, 7
+ ld [wInwardSpiralUpdateScreenCounter], a
+ coord hl, 0, 0
+ ld c, SCREEN_HEIGHT - 1
+ ld de, SCREEN_WIDTH
call BattleTransition_InwardSpiral_
inc c
jr .skip
.loop
- ld de, $14
+ ld de, SCREEN_WIDTH
call BattleTransition_InwardSpiral_
.skip
inc c
- ld de, $1
+ ld de, 1
call BattleTransition_InwardSpiral_
dec c
dec c
- ld de, $ffec
+ ld de, -SCREEN_WIDTH
call BattleTransition_InwardSpiral_
inc c
- ld de, rIE
+ ld de, -1
call BattleTransition_InwardSpiral_
dec c
dec c
@@ -258,101 +265,101 @@ BattleTransition_InwardSpiral: ; 70aaa (1c:4aaa)
jr nz, .loop
ret
-BattleTransition_InwardSpiral_: ; 70ae0 (1c:4ae0)
+BattleTransition_InwardSpiral_:
push bc
.loop
ld [hl], $ff
add hl, de
push bc
- ld a, [wWhichTrade]
+ ld a, [wInwardSpiralUpdateScreenCounter]
dec a
jr nz, .skip
call BattleTransition_TransferDelay3
- ld a, $7
+ ld a, 7
.skip
- ld [wWhichTrade], a
+ ld [wInwardSpiralUpdateScreenCounter], a
pop bc
dec c
jr nz, .loop
pop bc
ret
-BattleTransition_OutwardSpiral_: ; 70af9 (1c:4af9)
- ld bc, $ffec
- ld de, $14
- ld a, [wd09b]
+BattleTransition_OutwardSpiral_:
+ ld bc, -SCREEN_WIDTH
+ ld de, SCREEN_WIDTH
+ ld a, [wOutwardSpiralTileMapPointer + 1]
ld l, a
- ld a, [wd09a]
+ ld a, [wOutwardSpiralTileMapPointer]
ld h, a
- ld a, [wd09f]
+ ld a, [wOutwardSpiralCurrentDirection]
cp $0
- jr z, .zero
+ jr z, .up
cp $1
- jr z, .one
+ jr z, .left
cp $2
- jr z, .two
+ jr z, .down
cp $3
- jr z, .three
-.done1
+ jr z, .right
+.keepSameDirection
ld [hl], $ff
-.done2_
+.done
ld a, l
- ld [wd09b], a
+ ld [wOutwardSpiralTileMapPointer + 1], a
ld a, h
- ld [wd09a], a
+ ld [wOutwardSpiralTileMapPointer], a
ret
-.zero
+.up
dec hl
ld a, [hl]
cp $ff
- jr nz, .done2
+ jr nz, .changeDirection
inc hl
add hl, bc
- jr .done1
-.one
+ jr .keepSameDirection
+.left
add hl, de
ld a, [hl]
cp $ff
- jr nz, .done2
+ jr nz, .changeDirection
add hl, bc
dec hl
- jr .done1
-.two
+ jr .keepSameDirection
+.down
inc hl
ld a, [hl]
cp $ff
- jr nz, .done2
+ jr nz, .changeDirection
dec hl
add hl, de
- jr .done1
-.three
+ jr .keepSameDirection
+.right
add hl, bc
ld a, [hl]
cp $ff
- jr nz, .done2
+ jr nz, .changeDirection
add hl, de
inc hl
- jr .done1
-.done2
+ jr .keepSameDirection
+.changeDirection
ld [hl], $ff
- ld a, [wd09f]
+ ld a, [wOutwardSpiralCurrentDirection]
inc a
cp $4
jr nz, .skip
xor a
.skip
- ld [wd09f], a
- jr .done2_
+ ld [wOutwardSpiralCurrentDirection], a
+ jr .done
FlashScreen:
-BattleTransition_FlashScreen_: ; 70b5d (1c:4b5d)
+BattleTransition_FlashScreen_:
ld hl, BattleTransition_FlashScreenPalettes
.loop
ld a, [hli]
cp $1
jr z, .done
ld [rBGP], a
- ld c, $2
+ ld c, 2
call DelayFrames
jr .loop
.done
@@ -360,66 +367,66 @@ BattleTransition_FlashScreen_: ; 70b5d (1c:4b5d)
jr nz, BattleTransition_FlashScreen_
ret
-BattleTransition_FlashScreenPalettes: ; 70b72 (1c:4b72)
+BattleTransition_FlashScreenPalettes:
db $F9,$FE,$FF,$FE,$F9,$E4,$90,$40,$00,$40,$90,$E4
db $01 ; terminator
; used for low level trainer dungeon battles
-BattleTransition_Shrink: ; 70b7f (1c:4b7f)
- ld c, $9
+BattleTransition_Shrink:
+ ld c, SCREEN_HEIGHT / 2
.loop
push bc
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- hlCoord 0, 7
- deCoord 0, 8
- ld bc, $ffd8
+ coord hl, 0, 7
+ coord de, 0, 8
+ ld bc, -SCREEN_WIDTH * 2
call BattleTransition_CopyTiles1
- hlCoord 0, 10
- deCoord 0, 9
- ld bc, $28
+ coord hl, 0, 10
+ coord de, 0, 9
+ ld bc, SCREEN_WIDTH * 2
call BattleTransition_CopyTiles1
- hlCoord 8, 0
- deCoord 9, 0
- ld bc, $fffe
+ coord hl, 8, 0
+ coord de, 9, 0
+ ld bc, -2
call BattleTransition_CopyTiles2
- hlCoord 11, 0
- deCoord 10, 0
- ld bc, $2
+ coord hl, 11, 0
+ coord de, 10, 0
+ ld bc, 2
call BattleTransition_CopyTiles2
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
- ld c, $6
+ ld c, 6
call DelayFrames
pop bc
dec c
jr nz, .loop
call BattleTransition_BlackScreen
- ld c, $a
+ ld c, 10
jp DelayFrames
; used for high level trainer dungeon battles
-BattleTransition_Split: ; 70bca (1c:4bca)
- ld c, $9
+BattleTransition_Split:
+ ld c, SCREEN_HEIGHT / 2
xor a
ld [H_AUTOBGTRANSFERENABLED], a
.loop
push bc
- hlCoord 0, 16
- deCoord 0, 17
- ld bc, $ffd8
+ coord hl, 0, 16
+ coord de, 0, 17
+ ld bc, -SCREEN_WIDTH * 2
call BattleTransition_CopyTiles1
- hlCoord 0, 1
- ld de, wTileMap
- ld bc, $28
+ coord hl, 0, 1
+ coord de, 0, 0
+ ld bc, SCREEN_WIDTH * 2
call BattleTransition_CopyTiles1
- hlCoord 18, 0
- deCoord 19, 0
- ld bc, $fffe
+ coord hl, 18, 0
+ coord de, 19, 0
+ ld bc, -2
call BattleTransition_CopyTiles2
- hlCoord 1, 0
- ld de, wTileMap
- ld bc, $2
+ coord hl, 1, 0
+ coord de, 0, 0
+ ld bc, 2
call BattleTransition_CopyTiles2
call BattleTransition_TransferDelay3
call Delay3
@@ -427,26 +434,26 @@ BattleTransition_Split: ; 70bca (1c:4bca)
dec c
jr nz, .loop
call BattleTransition_BlackScreen
- ld c, $a
+ ld c, 10
jp DelayFrames
-BattleTransition_CopyTiles1: ; 70c12 (1c:4c12)
+BattleTransition_CopyTiles1:
ld a, c
- ld [wWhichTrade], a
+ ld [wBattleTransitionCopyTilesOffset], a
ld a, b
- ld [wTrainerEngageDistance], a
- ld c, $8
+ ld [wBattleTransitionCopyTilesOffset + 1], a
+ ld c, 8
.loop1
push bc
push hl
push de
- ld bc, $14
+ ld bc, SCREEN_WIDTH
call CopyData
pop hl
pop de
- ld a, [wWhichTrade]
+ ld a, [wBattleTransitionCopyTilesOffset]
ld c, a
- ld a, [wTrainerEngageDistance]
+ ld a, [wBattleTransitionCopyTilesOffset + 1]
ld b, a
add hl, bc
pop bc
@@ -455,35 +462,35 @@ BattleTransition_CopyTiles1: ; 70c12 (1c:4c12)
ld l, e
ld h, d
ld a, $ff
- ld c, $14
+ ld c, SCREEN_WIDTH
.loop2
ld [hli], a
dec c
jr nz, .loop2
ret
-BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f)
+BattleTransition_CopyTiles2:
ld a, c
- ld [wWhichTrade], a
+ ld [wBattleTransitionCopyTilesOffset], a
ld a, b
- ld [wTrainerEngageDistance], a
- ld c, $9
+ ld [wBattleTransitionCopyTilesOffset + 1], a
+ ld c, SCREEN_HEIGHT / 2
.loop1
push bc
push hl
push de
- ld c, $12
+ ld c, SCREEN_HEIGHT
.loop2
ld a, [hl]
ld [de], a
ld a, e
- add $14
+ add SCREEN_WIDTH
jr nc, .noCarry1
inc d
.noCarry1
ld e, a
ld a, l
- add $14
+ add SCREEN_WIDTH
jr nc, .noCarry2
inc h
.noCarry2
@@ -492,9 +499,9 @@ BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f)
jr nz, .loop2
pop hl
pop de
- ld a, [wWhichTrade]
+ ld a, [wBattleTransitionCopyTilesOffset]
ld c, a
- ld a, [wTrainerEngageDistance]
+ ld a, [wBattleTransitionCopyTilesOffset + 1]
ld b, a
add hl, bc
pop bc
@@ -502,8 +509,8 @@ BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f)
jr nz, .loop1
ld l, e
ld h, d
- ld de, $14
- ld c, $12
+ ld de, SCREEN_WIDTH
+ ld c, SCREEN_HEIGHT
.loop3
ld [hl], $ff
add hl, de
@@ -512,10 +519,10 @@ BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f)
ret
; used for high level wild dungeon battles
-BattleTransition_VerticalStripes: ; 70c7e (1c:4c7e)
- ld c, $12
- ld hl, wTileMap
- deCoord 1, 17
+BattleTransition_VerticalStripes:
+ ld c, SCREEN_HEIGHT
+ coord hl, 0, 0
+ coord de, 1, 17
xor a
ld [H_AUTOBGTRANSFERENABLED], a
.loop
@@ -528,20 +535,20 @@ BattleTransition_VerticalStripes: ; 70c7e (1c:4c7e)
call BattleTransition_VerticalStripes_
call BattleTransition_TransferDelay3
pop hl
- ld bc, $ffec
+ ld bc, -SCREEN_WIDTH
add hl, bc
ld e, l
ld d, h
pop hl
- ld bc, $14
+ ld bc, SCREEN_WIDTH
add hl, bc
pop bc
dec c
jr nz, .loop
jp BattleTransition_BlackScreen
-BattleTransition_VerticalStripes_: ; 70caa (1c:4caa)
- ld c, $a
+BattleTransition_VerticalStripes_:
+ ld c, SCREEN_WIDTH / 2
.loop
ld [hl], $ff
inc hl
@@ -551,10 +558,10 @@ BattleTransition_VerticalStripes_: ; 70caa (1c:4caa)
ret
; used for low level wild dungeon battles
-BattleTransition_HorizontalStripes: ; 70cb4 (1c:4cb4)
- ld c, $14
- ld hl, wTileMap
- deCoord 19, 1
+BattleTransition_HorizontalStripes:
+ ld c, SCREEN_WIDTH
+ coord hl, 0, 0
+ coord de, 19, 1
xor a
ld [H_AUTOBGTRANSFERENABLED], a
.loop
@@ -575,9 +582,9 @@ BattleTransition_HorizontalStripes: ; 70cb4 (1c:4cb4)
jr nz, .loop
jp BattleTransition_BlackScreen
-BattleTransition_HorizontalStripes_: ; 70cd8 (1c:4cd8)
- ld c, $9
- ld de, $28
+BattleTransition_HorizontalStripes_:
+ ld c, SCREEN_HEIGHT / 2
+ ld de, SCREEN_WIDTH * 2
.loop
ld [hl], $ff
add hl, de
@@ -588,31 +595,31 @@ BattleTransition_HorizontalStripes_: ; 70cd8 (1c:4cd8)
; used for high level wild non-dungeon battles
; makes one full circle around the screen
; by animating each half circle one at a time
-BattleTransition_Circle: ; 70ce4 (1c:4ce4)
+BattleTransition_Circle:
call BattleTransition_FlashScreen
- ld bc, $000a
+ lb bc, 0, SCREEN_WIDTH / 2
ld hl, BattleTransition_HalfCircle1
call BattleTransition_Circle_Sub1
- ld c, $a
- ld b, $1
+ ld c, SCREEN_WIDTH / 2
+ ld b, 1
ld hl, BattleTransition_HalfCircle2
call BattleTransition_Circle_Sub1
jp BattleTransition_BlackScreen
-BattleTransition_FlashScreen: ; 70cfd (1c:4cfd)
+BattleTransition_FlashScreen:
ld b, $3
call BattleTransition_FlashScreen_
xor a
ld [H_AUTOBGTRANSFERENABLED], a
ret
-BattleTransition_Circle_Sub1: ; 70d06 (1c:4d06)
+BattleTransition_Circle_Sub1:
push bc
push hl
ld a, b
call BattleTransition_Circle_Sub2
pop hl
- ld bc, $0005
+ ld bc, 5
add hl, bc
call BattleTransition_TransferDelay3
pop bc
@@ -620,8 +627,8 @@ BattleTransition_Circle_Sub1: ; 70d06 (1c:4d06)
jr nz, BattleTransition_Circle_Sub1
ret
-BattleTransition_TransferDelay3: ; 70d19 (1c:4d19)
- ld a, $1
+BattleTransition_TransferDelay3:
+ ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
xor a
@@ -631,9 +638,9 @@ BattleTransition_TransferDelay3: ; 70d19 (1c:4d19)
; used for low level wild non-dungeon battles
; makes two half circles around the screen
; by animating both half circles at the same time
-BattleTransition_DoubleCircle: ; 70d24 (1c:4d24)
+BattleTransition_DoubleCircle:
call BattleTransition_FlashScreen
- ld c, $a
+ ld c, SCREEN_WIDTH / 2
ld hl, BattleTransition_HalfCircle1
ld de, BattleTransition_HalfCircle2
.loop
@@ -647,7 +654,7 @@ BattleTransition_DoubleCircle: ; 70d24 (1c:4d24)
ld a, $1
call BattleTransition_Circle_Sub2
pop hl
- ld bc, $5
+ ld bc, 5
add hl, bc
ld e, l
ld d, h
@@ -659,10 +666,10 @@ BattleTransition_DoubleCircle: ; 70d24 (1c:4d24)
jr nz, .loop
jp BattleTransition_BlackScreen
-BattleTransition_Circle_Sub2: ; 70d50 (1c:4d50)
- ld [wWhichTrade], a
+BattleTransition_Circle_Sub2:
+ ld [wBattleTransitionCircleScreenQuadrantY], a
ld a, [hli]
- ld [wTrainerEngageDistance], a
+ ld [wBattleTransitionCircleScreenQuadrantX], a
ld a, [hli]
ld e, a
ld a, [hli]
@@ -672,7 +679,7 @@ BattleTransition_Circle_Sub2: ; 70d50 (1c:4d50)
ld l, a
jp BattleTransition_Circle_Sub3
-BattleTransition_HalfCircle1: ; 70d61 (1c:4d61)
+BattleTransition_HalfCircle1:
db $01
dw BattleTransition_CircleData1
dwCoord 18, 6
@@ -713,7 +720,7 @@ BattleTransition_HalfCircle1: ; 70d61 (1c:4d61)
dw BattleTransition_CircleData1
dwCoord 1, 6
-BattleTransition_HalfCircle2: ; 70d93 (1c:4d93)
+BattleTransition_HalfCircle2:
db $00
dw BattleTransition_CircleData1
dwCoord 1, 11
@@ -754,14 +761,14 @@ BattleTransition_HalfCircle2: ; 70d93 (1c:4d93)
dw BattleTransition_CircleData1
dwCoord 18, 11
-BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5)
+BattleTransition_Circle_Sub3:
push hl
ld a, [de]
ld c, a
inc de
.loop1
ld [hl], $ff
- ld a, [wTrainerEngageDistance]
+ ld a, [wBattleTransitionCircleScreenQuadrantX]
and a
jr z, .skip1
inc hl
@@ -772,11 +779,11 @@ BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5)
dec c
jr nz, .loop1
pop hl
- ld a, [wWhichTrade]
+ ld a, [wBattleTransitionCircleScreenQuadrantY]
and a
- ld bc, $14
+ ld bc, SCREEN_WIDTH
jr z, .skip3
- ld bc, $ffec
+ ld bc, -SCREEN_WIDTH
.skip3
add hl, bc
ld a, [de]
@@ -787,7 +794,7 @@ BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5)
jr z, BattleTransition_Circle_Sub3
ld c, a
.loop2
- ld a, [wTrainerEngageDistance]
+ ld a, [wBattleTransitionCircleScreenQuadrantX]
and a
jr z, .skip4
dec hl
@@ -799,17 +806,17 @@ BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5)
jr nz, .loop2
jr BattleTransition_Circle_Sub3
-BattleTransition_CircleData1: ; 70dfe (1c:4dfe)
+BattleTransition_CircleData1:
db $02,$03,$05,$04,$09,$FF
-BattleTransition_CircleData2: ; 70e04 (1c:4e04)
+BattleTransition_CircleData2:
db $01,$01,$02,$02,$04,$02,$04,$02,$03,$FF
-BattleTransition_CircleData3: ; 70e0e (1c:4e0e)
+BattleTransition_CircleData3:
db $02,$01,$03,$01,$04,$01,$04,$01,$04,$01,$03,$01,$02,$01,$01,$01,$01,$FF
-BattleTransition_CircleData4: ; 70e20 (1c:4e20)
+BattleTransition_CircleData4:
db $04,$01,$04,$00,$03,$01,$03,$00,$02,$01,$02,$00,$01,$FF
-BattleTransition_CircleData5: ; 70e2e (1c:4e2e)
+BattleTransition_CircleData5:
db $04,$00,$03,$00,$03,$00,$02,$00,$02,$00,$01,$00,$01,$00,$01,$FF
diff --git a/engine/battle/common_text.asm b/engine/battle/common_text.asm
index 9a00bd98..3d46c947 100644
--- a/engine/battle/common_text.asm
+++ b/engine/battle/common_text.asm
@@ -1,8 +1,8 @@
-PrintBeginningBattleText: ; 58d99 (16:4d99)
- ld a, [W_ISINBATTLE] ; W_ISINBATTLE
+PrintBeginningBattleText:
+ ld a, [wIsInBattle]
dec a
jr nz, .trainerBattle
- ld a, [W_CURMAP] ; W_CURMAP
+ ld a, [wCurMap]
cp POKEMONTOWER_3
jr c, .notPokemonTower
cp LAVENDER_HOUSE_1
@@ -11,7 +11,7 @@ PrintBeginningBattleText: ; 58d99 (16:4d99)
ld a, [wEnemyMonSpecies2]
call PlayCry
ld hl, WildMonAppearedText
- ld a, [W_MOVEMISSED] ; W_MOVEMISSED
+ ld a, [wMoveMissed]
and a
jr z, .notFishing
ld hl, HookedMonAttackedText
@@ -19,7 +19,7 @@ PrintBeginningBattleText: ; 58d99 (16:4d99)
jr .wildBattle
.trainerBattle
call .playSFX
- ld c, $14
+ ld c, 20
call DelayFrames
ld hl, TrainerWantsToFightText
.wildBattle
@@ -61,40 +61,40 @@ PrintBeginningBattleText: ; 58d99 (16:4d99)
.playSFX
xor a
- ld [wc0f1], a
+ ld [wFrequencyModifier], a
ld a, $80
- ld [wc0f2], a
- ld a, (SFX_08_77 - SFX_Headers_08) / 3
+ ld [wTempoModifier], a
+ ld a, SFX_SILPH_SCOPE
call PlaySound
jp WaitForSoundToFinish
.done
ret
-WildMonAppearedText: ; 58e3b (16:4e3b)
+WildMonAppearedText:
TX_FAR _WildMonAppearedText
db "@"
-HookedMonAttackedText: ; 58e40 (16:4e40)
+HookedMonAttackedText:
TX_FAR _HookedMonAttackedText
db "@"
-EnemyAppearedText: ; 58e45 (16:4e45)
+EnemyAppearedText:
TX_FAR _EnemyAppearedText
db "@"
-TrainerWantsToFightText: ; 58e4a (16:4e4a)
+TrainerWantsToFightText:
TX_FAR _TrainerWantsToFightText
db "@"
-UnveiledGhostText: ; 58e4f (16:4e4f)
+UnveiledGhostText:
TX_FAR _UnveiledGhostText
db "@"
-GhostCantBeIDdText: ; 58e54 (16:4e54)
+GhostCantBeIDdText:
TX_FAR _GhostCantBeIDdText
db "@"
-PrintSendOutMonMessage: ; 58e59 (16:4e59)
+PrintSendOutMonMessage:
ld hl, wEnemyMonHP
ld a, [hli]
or [hl]
@@ -104,10 +104,10 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59)
ld [H_MULTIPLICAND], a
ld hl, wEnemyMonHP
ld a, [hli]
- ld [wcce3], a
+ ld [wLastSwitchInEnemyMonHP], a
ld [H_MULTIPLICAND + 1], a
ld a, [hl]
- ld [wcce4], a
+ ld [wLastSwitchInEnemyMonHP + 1], a
ld [H_MULTIPLICAND + 2], a
ld a, 25
ld [H_MULTIPLIER], a
@@ -120,7 +120,7 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59)
srl a
rr b
ld a, b
- ld b, $4
+ ld b, 4
ld [H_DIVISOR], a ; enemy mon max HP divided by 4
call Divide
ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP
@@ -137,56 +137,56 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59)
.printText
jp PrintText
-GoText: ; 58eae (16:4eae)
+GoText:
TX_FAR _GoText
- db $08 ; asm
+ TX_ASM
jr PrintPlayerMon1Text
-DoItText: ; 58eb5 (16:4eb5)
+DoItText:
TX_FAR _DoItText
- db $08 ; asm
+ TX_ASM
jr PrintPlayerMon1Text
-GetmText: ; 58ebc (16:4ebc)
+GetmText:
TX_FAR _GetmText
- db $08 ; asm
+ TX_ASM
jr PrintPlayerMon1Text
-EnemysWeakText: ; 58ec3 (16:4ec3)
+EnemysWeakText:
TX_FAR _EnemysWeakText
- db $08 ; asm
+ TX_ASM
PrintPlayerMon1Text:
ld hl, PlayerMon1Text
ret
-PlayerMon1Text: ; 58ecc (16:4ecc)
+PlayerMon1Text:
TX_FAR _PlayerMon1Text
db "@"
-RetreatMon: ; 58ed1 (16:4ed1)
+RetreatMon:
ld hl, PlayerMon2Text
jp PrintText
-PlayerMon2Text: ; 58ed7 (16:4ed7)
+PlayerMon2Text:
TX_FAR _PlayerMon2Text
- db $08 ; asm
+ TX_ASM
push de
push bc
ld hl, wEnemyMonHP + 1
- ld de, wcce4
+ ld de, wLastSwitchInEnemyMonHP + 1
ld b, [hl]
dec hl
ld a, [de]
sub b
- ld [$ff98], a
+ ld [H_MULTIPLICAND + 2], a
dec de
ld b, [hl]
ld a, [de]
sbc b
- ld [$ff97], a
- ld a, $19
- ld [H_POWEROFTEN], a
+ ld [H_MULTIPLICAND + 1], a
+ ld a, 25
+ ld [H_MULTIPLIER], a
call Multiply
ld hl, wEnemyMonMaxHP
ld a, [hli]
@@ -196,43 +196,48 @@ PlayerMon2Text: ; 58ed7 (16:4ed7)
srl a
rr b
ld a, b
- ld b, $4
- ld [H_POWEROFTEN], a
+ ld b, 4
+ ld [H_DIVISOR], a
call Divide
pop bc
pop de
- ld a, [$ff98]
- ld hl, EnoughText
+ ld a, [H_QUOTIENT + 3] ; a = ((LastSwitchInEnemyMonHP - CurrentEnemyMonHP) / 25) / (EnemyMonMaxHP / 4)
+; Assuming that the enemy mon hasn't gained HP since the last switch in,
+; a approximates the percentage that the enemy mon's total HP has decreased
+; since the last switch in.
+; If the enemy mon has gained HP, then a is garbage due to wrap-around and
+; can fall in any of the ranges below.
+ ld hl, EnoughText ; HP stayed the same
and a
ret z
- ld hl, ComeBackText
- cp $1e
+ ld hl, ComeBackText ; HP went down 1% - 29%
+ cp 30
ret c
- ld hl, OKExclamationText
- cp $46
+ ld hl, OKExclamationText ; HP went down 30% - 69%
+ cp 70
ret c
- ld hl, GoodText
+ ld hl, GoodText ; HP went down 70% or more
ret
-EnoughText: ; 58f25 (16:4f25)
+EnoughText:
TX_FAR _EnoughText
- db $08 ; asm
+ TX_ASM
jr PrintComeBackText
-OKExclamationText: ; 58f2c (16:4f2c)
+OKExclamationText:
TX_FAR _OKExclamationText
- db $08 ; asm
+ TX_ASM
jr PrintComeBackText
-GoodText: ; 58f33 (16:4f33)
+GoodText:
TX_FAR _GoodText
- db $08 ; asm
+ TX_ASM
jr PrintComeBackText
-PrintComeBackText: ; 58f3a (16:4f3a)
+PrintComeBackText:
ld hl, ComeBackText
ret
-ComeBackText: ; 58f3e (16:4f3e)
+ComeBackText:
TX_FAR _ComeBackText
db "@"
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index 48bed512..153a9048 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -1,7 +1,7 @@
BattleCore:
; These are move effects (second value from the Moves table in bank $E).
-ResidualEffects1: ; 3c000 (f:4000)
+ResidualEffects1:
; most non-side effects
db CONVERSION_EFFECT
db HAZE_EFFECT
@@ -20,13 +20,13 @@ ResidualEffects1: ; 3c000 (f:4000)
db LEECH_SEED_EFFECT
db SPLASH_EFFECT
db -1
-SetDamageEffects: ; 3c011 (f:4011)
+SetDamageEffects:
; moves that do damage but not through normal calculations
; e.g., Super Fang, Psywave
db SUPER_FANG_EFFECT
db SPECIAL_DAMAGE_EFFECT
db -1
-ResidualEffects2: ; 3c014 (f:4014)
+ResidualEffects2:
; non-side effects not included in ResidualEffects1
; stat-affecting moves, sleep-inflicting moves, and Bide
; e.g., Meditate, Bide, Hypnosis
@@ -58,7 +58,7 @@ ResidualEffects2: ; 3c014 (f:4014)
db ACCURACY_DOWN2_EFFECT
db EVASION_DOWN2_EFFECT
db -1
-AlwaysHappenSideEffects: ; 3c030 (f:4030)
+AlwaysHappenSideEffects:
; Attacks that aren't finished after they faint the opponent.
db DRAIN_HP_EFFECT
db EXPLODE_EFFECT
@@ -71,7 +71,7 @@ AlwaysHappenSideEffects: ; 3c030 (f:4030)
db TWINEEDLE_EFFECT
db RAGE_EFFECT
db -1
-SpecialEffects: ; 3c03b (f:403b)
+SpecialEffects:
; Effects from arrays 2, 4, and 5B, minus Twineedle and Rage.
; Includes all effects that do not need to be called at the end of
; ExecutePlayerMove (or ExecuteEnemyMove), because they have already been handled
@@ -90,19 +90,19 @@ SpecialEffects: ; 3c03b (f:403b)
db JUMP_KICK_EFFECT
db RECOIL_EFFECT
; fallthrough to Next EffectsArray
-SpecialEffectsCont: ; 3c049 (f:4049)
+SpecialEffectsCont:
; damaging moves whose effect is executed prior to damage calculation
db THRASH_PETAL_DANCE_EFFECT
db TRAPPING_EFFECT
db -1
-SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c)
+SlidePlayerAndEnemySilhouettesOnScreen:
call LoadPlayerBackPic
ld a, MESSAGE_BOX ; the usual text box at the bottom of the screen
ld [wTextBoxID], a
call DisplayTextBoxID
- hlCoord 1, 5
- ld bc, $307
+ coord hl, 1, 5
+ lb bc, 3, 7
call ClearScreenArea
call DisableLCD
call LoadFontTilePatterns
@@ -110,14 +110,14 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c)
ld hl, vBGMap0
ld bc, $400
.clearBackgroundLoop
- ld a, $7f
+ ld a, " "
ld [hli], a
dec bc
ld a, b
or c
jr nz, .clearBackgroundLoop
; copy the work RAM tile map to VRAM
- ld hl, wTileMap
+ coord hl, 0, 0
ld de, vBGMap0
ld b, 18 ; number of rows
.copyRowLoop
@@ -175,27 +175,25 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c)
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld a, $31
- ld [$ffe1], a
- hlCoord 1, 5
- predef Func_3f0c6
+ ld [hStartTileID], a
+ coord hl, 1, 5
+ predef CopyUncompressedPicToTilemap
xor a
ld [hWY], a
ld [rWY], a
inc a
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
- ld b, $1
- call GoPAL_SET
+ ld b, SET_PAL_BATTLE
+ call RunPaletteCommand
call HideSprites
- ld hl, PrintBeginningBattleText
- ld b, BANK(PrintBeginningBattleText)
- jp Bankswitch
+ jpab PrintBeginningBattleText
; when a battle is starting, silhouettes of the player's pic and the enemy's pic are slid onto the screen
; the lower of the player's pic (his body) is part of the background, but his head is a sprite
; the reason for this is that it shares Y coordinates with the lower part of the enemy pic, so background scrolling wouldn't work for both pics
; instead, the enemy pic is part of the background and uses the scroll register, while the player's head is a sprite and is slid by changing its X coordinates in a loop
-SlidePlayerHeadLeft: ; 3c0ff (f:40ff)
+SlidePlayerHeadLeft:
push bc
ld hl, wOAMBuffer + $01
ld c, $15 ; number of OAM entries
@@ -209,7 +207,7 @@ SlidePlayerHeadLeft: ; 3c0ff (f:40ff)
pop bc
ret
-SetScrollXForSlidingPlayerBodyLeft: ; 3c110 (f:4110)
+SetScrollXForSlidingPlayerBodyLeft:
ld a, [rLY]
cp l
jr nz, SetScrollXForSlidingPlayerBodyLeft
@@ -221,13 +219,13 @@ SetScrollXForSlidingPlayerBodyLeft: ; 3c110 (f:4110)
jr z, .loop
ret
-StartBattle: ; 3c11e (f:411e)
+StartBattle:
xor a
ld [wPartyGainExpFlags], a
ld [wPartyFoughtCurrentEnemyFlags], a
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
inc a
- ld [wd11d], a
+ ld [wFirstMonsNotOutYet], a
ld hl, wEnemyMon1HP
ld bc, wEnemyMon2 - wEnemyMon1 - 1
ld d, $3
@@ -241,7 +239,7 @@ StartBattle: ; 3c11e (f:411e)
.foundFirstAliveEnemyMon
ld a, d
ld [wSerialExchangeNybbleReceiveData], a
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a ; is it a trainer battle?
call nz, EnemySendOutFirstMon ; if it is a trainer battle, send out enemy mon
ld c, 40
@@ -253,17 +251,17 @@ StartBattle: ; 3c11e (f:411e)
and a
jp z, HandlePlayerBlackOut ; jump if no mon is alive
call LoadScreenTilesFromBuffer1
- ld a, [W_BATTLETYPE]
+ ld a, [wBattleType]
and a ; is it a normal battle?
jp z, .playerSendOutFirstMon ; if so, send out player mon
; safari zone battle
.displaySafariZoneBattleMenu
call DisplayBattleMenu
ret c ; return if the player ran from battle
- ld a, [wcd6a]
+ ld a, [wActionResultOrTookBattleTurn]
and a ; was the item used successfully?
jr z, .displaySafariZoneBattleMenu ; if not, display the menu again; XXX does this ever jump?
- ld a, [W_NUMSAFARIBALLS]
+ ld a, [wNumSafariBalls]
and a
jr nz, .notOutOfSafariBalls
call LoadScreenTilesFromBuffer1
@@ -324,13 +322,13 @@ StartBattle: ; 3c11e (f:411e)
ld [wcf91], a
ld [wBattleMonSpecies2], a
call LoadScreenTilesFromBuffer1
- hlCoord 1, 5
+ coord hl, 1, 5
ld a, $9
call SlideTrainerPicOffScreen
call SaveScreenTilesToBuffer1
ld a, [wWhichPokemon]
ld c, a
- ld b, $1
+ ld b, FLAG_SET
push bc
ld hl, wPartyGainExpFlags
predef FlagActionPredef
@@ -343,7 +341,7 @@ StartBattle: ; 3c11e (f:411e)
jr MainInBattleLoop
; wild mon or link battle enemy ran from battle
-EnemyRan: ; 3c202 (f:4202)
+EnemyRan:
call LoadScreenTilesFromBuffer1
ld a, [wLinkState]
cp LINK_STATE_BATTLING
@@ -355,23 +353,21 @@ EnemyRan: ; 3c202 (f:4202)
ld hl, EnemyRanText
.printText
call PrintText
- ld a, (SFX_08_44 - SFX_Headers_08) / 3
+ ld a, SFX_RUN
call PlaySoundWaitForCurrent
xor a
ld [H_WHOSETURN], a
- ld hl, AnimationSlideEnemyMonOut
- ld b, BANK(AnimationSlideEnemyMonOut)
- jp Bankswitch
+ jpab AnimationSlideEnemyMonOff
-WildRanText: ; 3c229 (f:4229)
+WildRanText:
TX_FAR _WildRanText
db "@"
-EnemyRanText: ; 3c22e (f:422e)
+EnemyRanText:
TX_FAR _EnemyRanText
db "@"
-MainInBattleLoop: ; 3c233 (f:4233)
+MainInBattleLoop:
call ReadPlayerMonCurHPAndStatus
ld hl, wBattleMonHP
ld a, [hli]
@@ -383,14 +379,14 @@ MainInBattleLoop: ; 3c233 (f:4233)
jp z, HandleEnemyMonFainted ; if enemy mon HP is 0, jump
call SaveScreenTilesToBuffer1
xor a
- ld [wd11d], a
- ld a, [W_PLAYERBATTSTATUS2]
+ ld [wFirstMonsNotOutYet], a
+ ld a, [wPlayerBattleStatus2]
and (1 << NeedsToRecharge) | (1 << UsingRage) ; check if the player is using Rage or needs to recharge
jr nz, .selectEnemyMove
; the player is not using Rage and doesn't need to recharge
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
res Flinched, [hl] ; reset flinch bit
- ld hl, W_PLAYERBATTSTATUS1
+ ld hl, wPlayerBattleStatus1
res Flinched, [hl] ; reset flinch bit
ld a, [hl]
and (1 << ThrashingAbout) | (1 << ChargingUp) ; check if the player is thrashing about or charging for an attack
@@ -404,10 +400,10 @@ MainInBattleLoop: ; 3c233 (f:4233)
ld a, [wBattleMonStatus]
and (1 << FRZ) | SLP ; is mon frozen or asleep?
jr nz, .selectEnemyMove ; if so, jump
- ld a, [W_PLAYERBATTSTATUS1]
+ ld a, [wPlayerBattleStatus1]
and (1 << StoringEnergy) | (1 << UsingTrappingMove) ; check player is using Bide or using a multi-turn attack like wrap
jr nz, .selectEnemyMove ; if so, jump
- ld a, [W_ENEMYBATTSTATUS1]
+ ld a, [wEnemyBattleStatus1]
bit UsingTrappingMove, a ; check if enemy is using a multi-turn attack like wrap
jr z, .selectPlayerMove ; if not, jump
; enemy is using a mult-turn attack like wrap, so player is trapped and cannot execute a move
@@ -415,12 +411,12 @@ MainInBattleLoop: ; 3c233 (f:4233)
ld [wPlayerSelectedMove], a
jr .selectEnemyMove
.selectPlayerMove
- ld a, [wcd6a]
- and a
+ ld a, [wActionResultOrTookBattleTurn]
+ and a ; has the player already used the turn (e.g. by using an item, trying to run or switching pokemon)
jr nz, .selectEnemyMove
ld [wMoveMenuType], a
inc a
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
xor a
ld [wMenuItemToSwap], a
call MoveSelectionMenu
@@ -436,18 +432,18 @@ MainInBattleLoop: ; 3c233 (f:4233)
jr nz, .noLinkBattle
; link battle
ld a, [wSerialExchangeNybbleReceiveData]
- cp $f
+ cp LINKBATTLE_RUN
jp z, EnemyRan
- cp $e
+ cp LINKBATTLE_STRUGGLE
jr z, .noLinkBattle
- cp $d
+ cp LINKBATTLE_NO_ACTION
jr z, .noLinkBattle
- sub $4
+ sub 4
jr c, .noLinkBattle
; the link battle enemy has switched mons
- ld a, [W_PLAYERBATTSTATUS1]
+ ld a, [wPlayerBattleStatus1]
bit UsingTrappingMove, a ; check if using multi-turn move like Wrap
- jr z, .asm_3c2dd
+ jr z, .specialMoveNotUsed
ld a, [wPlayerMoveListIndex]
ld hl, wBattleMonMoves
ld c, a
@@ -456,9 +452,9 @@ MainInBattleLoop: ; 3c233 (f:4233)
ld a, [hl]
cp METRONOME ; a MIRROR MOVE check is missing, might lead to a desync in link battles
; when combined with multi-turn moves
- jr nz, .asm_3c2dd
+ jr nz, .specialMoveNotUsed
ld [wPlayerSelectedMove], a
-.asm_3c2dd
+.specialMoveNotUsed
callab SwitchEnemyMon
.noLinkBattle
ld a, [wPlayerSelectedMove]
@@ -492,8 +488,8 @@ MainInBattleLoop: ; 3c233 (f:4233)
jr nc, .playerMovesFirst ; if player is faster
jr .enemyMovesFirst ; if enemy is faster
.speedEqual ; 50/50 chance for both players
- ld a, [$ffaa]
- cp $2
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
jr z, .invertOutcome
call BattleRandom
cp $80
@@ -561,7 +557,7 @@ MainInBattleLoop: ; 3c233 (f:4233)
call CheckNumAttacksLeft
jp MainInBattleLoop
-HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd)
+HandlePoisonBurnLeechSeed:
ld hl, wBattleMonHP
ld de, wBattleMonStatus
ld a, [H_WHOSETURN]
@@ -588,11 +584,11 @@ HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd)
pop hl
call HandlePoisonBurnLeechSeed_DecreaseOwnHP
.notBurnedOrPoisoned
- ld de, W_PLAYERBATTSTATUS2
+ ld de, wPlayerBattleStatus2
ld a, [H_WHOSETURN]
and a
jr z, .playersTurn2
- ld de, W_ENEMYBATTSTATUS2
+ ld de, wEnemyBattleStatus2
.playersTurn2
ld a, [de]
add a
@@ -620,20 +616,20 @@ HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd)
or [hl]
ret nz ; test if fainted
call DrawHUDsAndHPBars
- ld c, $14
+ ld c, 20
call DelayFrames
xor a
ret
-HurtByPoisonText: ; 3c42e (f:442e)
+HurtByPoisonText:
TX_FAR _HurtByPoisonText
db "@"
-HurtByBurnText: ; 3c433 (f:4433)
+HurtByBurnText:
TX_FAR _HurtByBurnText
db "@"
-HurtByLeechSeedText: ; 3c438 (f:4438)
+HurtByLeechSeedText:
TX_FAR _HurtByLeechSeedText
db "@"
@@ -641,7 +637,7 @@ HurtByLeechSeedText: ; 3c438 (f:4438)
; note that the toxic ticks are considered even if the damage is not poison (hence the Leech Seed glitch)
; hl: HP pointer
; bc (out): total damage
-HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d)
+HandlePoisonBurnLeechSeed_DecreaseOwnHP:
push hl
push hl
ld bc, $e ; skip to max HP
@@ -663,13 +659,13 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d)
jr nz, .nonZeroDamage
inc c ; damage is at least 1
.nonZeroDamage
- ld hl, W_PLAYERBATTSTATUS3
- ld de, W_PLAYERTOXICCOUNTER
+ ld hl, wPlayerBattleStatus3
+ ld de, wPlayerToxicCounter
ld a, [H_WHOSETURN]
and a
jr z, .playersTurn
- ld hl, W_ENEMYBATTSTATUS3
- ld de, W_ENEMYTOXICCOUNTER
+ ld hl, wEnemyBattleStatus3
+ ld de, wEnemyToxicCounter
.playersTurn
bit BadlyPoisoned, [hl]
jr z, .noToxic
@@ -709,7 +705,7 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d)
; adds bc to enemy HP
; bc isn't updated if HP substracted was capped to prevent overkill
-HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3)
+HandlePoisonBurnLeechSeed_IncreaseEnemyHP:
push hl
ld hl, wEnemyMonMaxHP
ld a, [H_WHOSETURN]
@@ -721,8 +717,8 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3)
ld [wHPBarMaxHP+1], a
ld a, [hl]
ld [wHPBarMaxHP], a
- ld de, $fff2
- add hl, de ; skip back fomr max hp to current hp
+ ld de, wBattleMonHP - wBattleMonMaxHP
+ add hl, de ; skip back from max hp to current hp
ld a, [hl]
ld [wHPBarOldHP], a ; add bc to current HP
add c
@@ -759,13 +755,13 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3)
pop hl
ret
-UpdateCurMonHPBar: ; 3c4f6 (f:44f6)
- hlCoord 10, 9 ; tile pointer to player HP bar
+UpdateCurMonHPBar:
+ coord hl, 10, 9 ; tile pointer to player HP bar
ld a, [H_WHOSETURN]
and a
ld a, $1
jr z, .playersTurn
- hlCoord 2, 2 ; tile pointer to enemy HP bar
+ coord hl, 2, 2 ; tile pointer to enemy HP bar
xor a
.playersTurn
push bc
@@ -774,25 +770,25 @@ UpdateCurMonHPBar: ; 3c4f6 (f:44f6)
pop bc
ret
-CheckNumAttacksLeft: ; 3c50f (f:450f)
+CheckNumAttacksLeft:
ld a, [wPlayerNumAttacksLeft]
and a
jr nz, .checkEnemy
; player has 0 attacks left
- ld hl, W_PLAYERBATTSTATUS1
+ ld hl, wPlayerBattleStatus1
res UsingTrappingMove, [hl] ; player not using multi-turn attack like wrap any more
.checkEnemy
ld a, [wEnemyNumAttacksLeft]
and a
ret nz
; enemy has 0 attacks left
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
res UsingTrappingMove, [hl] ; enemy not using multi-turn attack like wrap any more
ret
-HandleEnemyMonFainted: ; 3c525 (f:4525)
+HandleEnemyMonFainted:
xor a
- ld [wccf0], a
+ ld [wInHandlePlayerMonFainted], a
call FaintEnemyPokemon
call AnyPartyAlive
ld a, d
@@ -802,7 +798,7 @@ HandleEnemyMonFainted: ; 3c525 (f:4525)
ld a, [hli]
or [hl] ; is battle mon HP zero?
call nz, DrawPlayerHUDAndHPBar ; if battle mon HP is not zero, draw player HD and HP bar
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
ret z ; return if it's a wild battle
call AnyEnemyPokemonAliveCheck
@@ -816,16 +812,16 @@ HandleEnemyMonFainted: ; 3c525 (f:4525)
call ChooseNextMon
.skipReplacingBattleMon
ld a, $1
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
call ReplaceFaintedEnemyMon
jp z, EnemyRan
xor a
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
jp MainInBattleLoop
-FaintEnemyPokemon ; 0x3c567
+FaintEnemyPokemon:
call ReadPlayerMonCurHPAndStatus
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
jr z, .wild
ld a, [wEnemyMonPartyPos]
@@ -836,41 +832,50 @@ FaintEnemyPokemon ; 0x3c567
ld [hli], a
ld [hl], a
.wild
- ld hl, W_PLAYERBATTSTATUS1
+ ld hl, wPlayerBattleStatus1
res AttackingMultipleTimes, [hl]
- xor a
- ld [wPlayerNumHits], a
+; Bug. This only zeroes the high byte of the player's accumulated damage,
+; setting the accumulated damage to itself mod 256 instead of 0 as was probably
+; intended. That alone is problematic, but this mistake has another more severe
+; effect. This function's counterpart for when the player mon faints,
+; RemoveFaintedPlayerMon, zeroes both the high byte and the low byte. In a link
+; battle, the other player's Game Boy will call that function in response to
+; the enemy mon (the player mon from the other side's perspective) fainting,
+; and the states of the two Game Boys will go out of sync unless the damage
+; was congruent to 0 modulo 256.
+ xor a
+ ld [wPlayerBideAccumulatedDamage], a
ld hl, wEnemyStatsToDouble ; clear enemy statuses
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
- ld [W_ENEMYDISABLEDMOVE], a
- ld [wccef], a
- ld [wccf3], a
+ ld [wEnemyDisabledMove], a
+ ld [wEnemyDisabledMoveNumber], a
+ ld [wEnemyMonMinimized], a
ld hl, wPlayerUsedMove
ld [hli], a
ld [hl], a
- hlCoord 12, 5
- deCoord 12, 6
+ coord hl, 12, 5
+ coord de, 12, 6
call SlideDownFaintedMonPic
- ld hl, wTileMap
- ld bc, $40b
+ coord hl, 0, 0
+ lb bc, 4, 11
call ClearScreenArea
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
jr z, .wild_win
xor a
- ld [wc0f1], a
- ld [wc0f2], a
- ld a, (SFX_08_48 - SFX_Headers_08) / 3 ; SFX_FALL?
+ ld [wFrequencyModifier], a
+ ld [wTempoModifier], a
+ ld a, SFX_FAINT_FALL
call PlaySoundWaitForCurrent
.sfxwait
- ld a, [wc02a]
- cp (SFX_08_48 - SFX_Headers_08) / 3
+ ld a, [wChannelSoundIDs + Ch4]
+ cp SFX_FAINT_FALL
jr z, .sfxwait
- ld a, (SFX_08_43 - SFX_Headers_08) / 3 ; SFX_DROP
+ ld a, SFX_FAINT_THUD
call PlaySound
call WaitForSoundToFinish
jr .sfxplayed
@@ -879,13 +884,15 @@ FaintEnemyPokemon ; 0x3c567
ld a, MUSIC_DEFEATED_WILD_MON
call PlayBattleVictoryMusic
.sfxplayed
+; bug: win sfx is played for wild battles before checking for player mon HP
+; this can lead to odd scenarios where both player and enemy faint, as the win sfx plays yet the player never won the battle
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
jr nz, .playermonnotfaint
- ld a, [wccf0]
- and a
- jr nz, .playermonnotfaint
+ ld a, [wInHandlePlayerMonFainted]
+ and a ; was this called by HandlePlayerMonFainted?
+ jr nz, .playermonnotfaint ; if so, don't call RemoveFaintedPlayerMon twice
call RemoveFaintedPlayerMon
.playermonnotfaint
call AnyPartyAlive
@@ -898,7 +905,7 @@ FaintEnemyPokemon ; 0x3c567
call SaveScreenTilesToBuffer1
xor a
ld [wBattleResult], a
- ld b, EXP__ALL
+ ld b, EXP_ALL
call IsItemInBag
push af
jr z, .giveExpToMonsThatFought ; if no exp all, then jump
@@ -938,23 +945,23 @@ FaintEnemyPokemon ; 0x3c567
jr nz, .gainExpFlagsLoop
ld a, b
ld [wPartyGainExpFlags], a
- ld hl, GainExperience
- ld b, BANK(GainExperience)
- jp Bankswitch
+ jpab GainExperience
-EnemyMonFaintedText: ; 0x3c63e
+EnemyMonFaintedText:
TX_FAR _EnemyMonFaintedText
db "@"
-EndLowHealthAlarm: ; 3c643 (f:4643)
+EndLowHealthAlarm:
+; This function is called when the player has the won the battle. It turns off
+; the low health alarm and prevents it from reactivating until the next battle.
xor a
- ld [wLowHealthAlarm], a ;disable low health alarm
- ld [wc02a], a
+ ld [wLowHealthAlarm], a ; turn off low health alarm
+ ld [wChannelSoundIDs + Ch4], a
inc a
- ld [wccf6], a
+ ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating
ret
-AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f)
+AnyEnemyPokemonAliveCheck:
ld a, [wEnemyPartyCount]
ld b, a
xor a
@@ -972,8 +979,8 @@ AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f)
ret
; stores whether enemy ran in Z flag
-ReplaceFaintedEnemyMon: ; 3c664 (f:4664)
- ld hl, wcf1e
+ReplaceFaintedEnemyMon:
+ ld hl, wEnemyHPBarColor
ld e, $30
call GetBattleHealthBarColor
callab DrawEnemyPokeballs
@@ -983,31 +990,31 @@ ReplaceFaintedEnemyMon: ; 3c664 (f:4664)
; link battle
call LinkBattleExchangeData
ld a, [wSerialExchangeNybbleReceiveData]
- cp $f
+ cp LINKBATTLE_RUN
ret z
call LoadScreenTilesFromBuffer1
.notLinkBattle
call EnemySendOut
xor a
- ld [W_ENEMYMOVENUM], a
- ld [wcd6a], a
+ ld [wEnemyMoveNum], a
+ ld [wActionResultOrTookBattleTurn], a
ld [wAILayer2Encouragement], a
inc a ; reset Z flag
ret
-TrainerBattleVictory: ; 3c696 (f:4696)
+TrainerBattleVictory:
call EndLowHealthAlarm
ld b, MUSIC_DEFEATED_GYM_LEADER
- ld a, [W_GYMLEADERNO]
+ ld a, [wGymLeaderNo]
and a
jr nz, .gymleader
ld b, MUSIC_DEFEATED_TRAINER
.gymleader
- ld a, [W_TRAINERCLASS]
+ ld a, [wTrainerClass]
cp SONY3 ; final battle against rival
jr nz, .notrival
ld b, MUSIC_DEFEATED_GYM_LEADER
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
set 1, [hl]
.notrival
ld a, [wLinkState]
@@ -1020,37 +1027,38 @@ TrainerBattleVictory: ; 3c696 (f:4696)
cp LINK_STATE_BATTLING
ret z
call ScrollTrainerPicAfterBattle
- ld c, $28
+ ld c, 40
call DelayFrames
call PrintEndBattleText
+; win money
ld hl, MoneyForWinningText
call PrintText
ld de, wPlayerMoney + 2
- ld hl, wd07b
+ ld hl, wAmountMoneyWon + 2
ld c, $3
predef_jump AddBCDPredef
-MoneyForWinningText: ; 3c6e4 (f:46e4)
+MoneyForWinningText:
TX_FAR _MoneyForWinningText
db "@"
-TrainerDefeatedText: ; 3c6e9 (f:46e9)
+TrainerDefeatedText:
TX_FAR _TrainerDefeatedText
db "@"
-PlayBattleVictoryMusic: ; 3c6ee (f:46ee)
+PlayBattleVictoryMusic:
push af
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySoundWaitForCurrent
ld c, BANK(Music_DefeatedTrainer)
pop af
call PlayMusic
jp Delay3
-HandlePlayerMonFainted: ; 3c700 (f:4700)
- ld a, $1
- ld [wccf0], a
+HandlePlayerMonFainted:
+ ld a, 1
+ ld [wInHandlePlayerMonFainted], a
call RemoveFaintedPlayerMon
call AnyPartyAlive ; test if any more mons are alive
ld a, d
@@ -1062,7 +1070,7 @@ HandlePlayerMonFainted: ; 3c700 (f:4700)
jr nz, .doUseNextMonDialogue ; if not, jump
; the enemy mon has 0 HP
call FaintEnemyPokemon
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
ret z ; if wild encounter, battle is over
call AnyEnemyPokemonAliveCheck
@@ -1074,21 +1082,21 @@ HandlePlayerMonFainted: ; 3c700 (f:4700)
jp nz, MainInBattleLoop ; if the enemy mon has more than 0 HP, go back to battle loop
; the enemy mon has 0 HP
ld a, $1
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
call ReplaceFaintedEnemyMon
jp z, EnemyRan ; if enemy ran from battle rather than sending out another mon, jump
xor a
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
jp MainInBattleLoop
; resets flags, slides mon's pic down, plays cry, and prints fainted message
-RemoveFaintedPlayerMon: ; 3c741 (f:4741)
+RemoveFaintedPlayerMon:
ld a, [wPlayerMonNumber]
ld c, a
ld hl, wPartyGainExpFlags
- ld b, $0
+ ld b, FLAG_RESET
predef FlagActionPredef ; clear gain exp flag for fainted mon
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
res 2, [hl] ; reset "attacking multiple times" flag
ld a, [wLowHealthAlarm]
bit 7, a ; skip sound flag (red bar (?))
@@ -1097,52 +1105,57 @@ RemoveFaintedPlayerMon: ; 3c741 (f:4741)
ld [wLowHealthAlarm], a ;disable low health alarm
call WaitForSoundToFinish
.skipWaitForSound
-; bug? if the player mon faints while the enemy mon is using bide,
-; the accumulated damage is overwritten. xxx what values can [wLowHealthAlarm] have here?
+; a is 0, so this zeroes the enemy's accumulated damage.
ld hl, wEnemyBideAccumulatedDamage
ld [hli], a
ld [hl], a
ld [wBattleMonStatus], a
call ReadPlayerMonCurHPAndStatus
- hlCoord 9, 7
- ld bc, $50b
+ coord hl, 9, 7
+ lb bc, 5, 11
call ClearScreenArea
- hlCoord 1, 10
- deCoord 1, 11
+ coord hl, 1, 10
+ coord de, 1, 11
call SlideDownFaintedMonPic
ld a, $1
ld [wBattleResult], a
- ld a, [wccf0]
- and a
- ret z
+
+; When the player mon and enemy mon faint at the same time and the fact that the
+; enemy mon has fainted is detected first (e.g. when the player mon knocks out
+; the enemy mon using a move with recoil and faints due to the recoil), don't
+; play the player mon's cry or show the "[player mon] fainted!" message.
+ ld a, [wInHandlePlayerMonFainted]
+ and a ; was this called by HandleEnemyMonFainted?
+ ret z ; if so, return
+
ld a, [wBattleMonSpecies]
call PlayCry
ld hl, PlayerMonFaintedText
jp PrintText
-PlayerMonFaintedText: ; 3c796 (f:4796)
+PlayerMonFaintedText:
TX_FAR _PlayerMonFaintedText
db "@"
; asks if you want to use next mon
; stores whether you ran in C flag
-DoUseNextMonDialogue: ; 3c79b (f:479b)
+DoUseNextMonDialogue:
call PrintEmptyString
call SaveScreenTilesToBuffer1
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
dec a
ret nz ; return if it's a trainer battle
ld hl, UseNextMonText
call PrintText
.displayYesNoBox
- hlCoord 13, 9
- ld bc, $a0e
+ coord hl, 13, 9
+ lb bc, 10, 14
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID
- ld a, [wd12e]
- cp $2 ; did the player choose NO?
+ ld a, [wMenuExitMethod]
+ cp CHOSE_SECOND_ITEM ; did the player choose NO?
jr z, .tryRunning ; if the player chose NO, try running
and a ; reset carry
ret
@@ -1154,15 +1167,15 @@ DoUseNextMonDialogue: ; 3c79b (f:479b)
ld de, wEnemyMonSpeed
jp TryRunningFromBattle
-UseNextMonText: ; 3c7d3 (f:47d3)
+UseNextMonText:
TX_FAR _UseNextMonText
db "@"
; choose next player mon to send out
; stores whether enemy mon has no HP left in Z flag
-ChooseNextMon: ; 3c7d8 (f:47d8)
- ld a, $2
- ld [wd07d], a
+ChooseNextMon:
+ ld a, BATTLE_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
call DisplayPartyMenu
.checkIfMonChosen
jr nc, .monChosen
@@ -1176,17 +1189,17 @@ ChooseNextMon: ; 3c7d8 (f:47d8)
cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
inc a
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
call LinkBattleExchangeData
.notLinkBattle
xor a
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
call ClearSprites
ld a, [wWhichPokemon]
ld [wPlayerMonNumber], a
ld c, a
ld hl, wPartyGainExpFlags
- ld b, $1
+ ld b, FLAG_SET
push bc
predef FlagActionPredef
pop bc
@@ -1196,7 +1209,7 @@ ChooseNextMon: ; 3c7d8 (f:47d8)
call GBPalWhiteOut
call LoadHudTilePatterns
call LoadScreenTilesFromBuffer1
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call GBPalNormal
call SendOutMon
ld hl, wEnemyMonHP
@@ -1206,27 +1219,27 @@ ChooseNextMon: ; 3c7d8 (f:47d8)
; called when player is out of usable mons.
; prints approriate lose message, sets carry flag if player blacked out (special case for initial rival fight)
-HandlePlayerBlackOut: ; 3c837 (f:4837)
+HandlePlayerBlackOut:
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr z, .notSony1Battle
- ld a, [W_CUROPPONENT]
- cp $c8 + SONY1
+ ld a, [wCurOpponent]
+ cp OPP_SONY1
jr nz, .notSony1Battle
- ld hl, wTileMap ; sony 1 battle
- ld bc, $815
+ coord hl, 0, 0 ; sony 1 battle
+ lb bc, 8, 21
call ClearScreenArea
call ScrollTrainerPicAfterBattle
- ld c, $28
+ ld c, 40
call DelayFrames
ld hl, Sony1WinText
call PrintText
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp OAKS_LAB
ret z ; starter battle in oak's lab: don't black out
.notSony1Battle
- ld b, $0
- call GoPAL_SET
+ ld b, SET_PAL_BATTLE_BLACK
+ call RunPaletteCommand
ld hl, PlayerBlackedOutText2
ld a, [wLinkState]
cp LINK_STATE_BATTLING
@@ -1241,21 +1254,21 @@ HandlePlayerBlackOut: ; 3c837 (f:4837)
scf
ret
-Sony1WinText: ; 3c884 (f:4884)
+Sony1WinText:
TX_FAR _Sony1WinText
db "@"
-PlayerBlackedOutText2: ; 3c889 (f:4889)
+PlayerBlackedOutText2:
TX_FAR _PlayerBlackedOutText2
db "@"
-LinkBattleLostText: ; 3c88e (f:488e)
+LinkBattleLostText:
TX_FAR _LinkBattleLostText
db "@"
; slides pic of fainted mon downwards until it disappears
; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing
-SlideDownFaintedMonPic: ; 3c893 (f:4893)
+SlideDownFaintedMonPic:
ld a, [wd730]
push af
set 6, a
@@ -1274,7 +1287,7 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893)
call CopyData
pop de
pop hl
- ld bc, -20
+ ld bc, -SCREEN_WIDTH
add hl, bc
push hl
ld h, d
@@ -1286,7 +1299,7 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893)
pop bc
dec b
jr nz, .rowLoop
- ld bc, 20
+ ld bc, SCREEN_WIDTH
add hl, bc
ld de, SevenSpacesText
call PlaceString
@@ -1301,15 +1314,15 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893)
ld [wd730], a
ret
-SevenSpacesText: ; 3c8d7 (f:48d7)
+SevenSpacesText:
db " @"
; slides the player or enemy trainer off screen
; a is the number of tiles to slide it horizontally (always 9 for the player trainer or 8 for the enemy trainer)
; if a is 8, the slide is to the right, else it is to the left
; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing
-SlideTrainerPicOffScreen: ; 3c8df (f:48df)
- ld [$FF8B], a
+SlideTrainerPicOffScreen:
+ ld [hSlideAmount], a
ld c, a
.slideStepLoop ; each iteration, the trainer pic is slid one tile left/right
push bc
@@ -1317,10 +1330,10 @@ SlideTrainerPicOffScreen: ; 3c8df (f:48df)
ld b, 7 ; number of rows
.rowLoop
push hl
- ld a, [$FF8B]
+ ld a, [hSlideAmount]
ld c, a
.columnLoop
- ld a, [$FF8B]
+ ld a, [hSlideAmount]
cp 8
jr z, .slideRight
.slideLeft ; slide player sprite off screen
@@ -1349,13 +1362,13 @@ SlideTrainerPicOffScreen: ; 3c8df (f:48df)
ret
; send out a trainer's mon
-EnemySendOut: ; 3c90e (f:490e)
+EnemySendOut:
ld hl,wPartyGainExpFlags
xor a
ld [hl],a
ld a,[wPlayerMonNumber]
ld c,a
- ld b,1
+ ld b,FLAG_SET
push bc
predef FlagActionPredef
ld hl,wPartyFoughtCurrentEnemyFlags
@@ -1365,7 +1378,7 @@ EnemySendOut: ; 3c90e (f:490e)
predef FlagActionPredef
; don't change wPartyGainExpFlags or wPartyFoughtCurrentEnemyFlags
-EnemySendOutFirstMon: ; 3c92a (f:492a)
+EnemySendOutFirstMon:
xor a
ld hl,wEnemyStatsToDouble ; clear enemy statuses
ld [hli],a
@@ -1373,17 +1386,17 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
ld [hli],a
ld [hli],a
ld [hl],a
- ld [W_ENEMYDISABLEDMOVE],a
- ld [wccef],a
- ld [wccf3],a
+ ld [wEnemyDisabledMove],a
+ ld [wEnemyDisabledMoveNumber],a
+ ld [wEnemyMonMinimized],a
ld hl,wPlayerUsedMove
ld [hli],a
ld [hl],a
dec a
ld [wAICount],a
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
res 5,[hl]
- hlCoord 18, 0
+ coord hl, 18, 0
ld a,8
call SlideTrainerPicOffScreen
call PrintEmptyString
@@ -1421,7 +1434,7 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
ld bc,wEnemyMon2 - wEnemyMon1
call AddNTimes
ld a,[hl]
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
ld a,[wWhichPokemon]
inc a
ld hl,wEnemyPartyCount
@@ -1434,12 +1447,12 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call LoadEnemyMonData
ld hl,wEnemyMonHP
ld a,[hli]
- ld [wcce3],a
+ ld [wLastSwitchInEnemyMonHP],a
ld a,[hl]
- ld [wcce4],a
+ ld [wLastSwitchInEnemyMonHP + 1],a
ld a,1
ld [wCurrentMenuItem],a
- ld a,[wd11d]
+ ld a,[wFirstMonsNotOutYet]
dec a
jr z,.next4
ld a,[wPartyCount]
@@ -1448,21 +1461,21 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
ld a,[wLinkState]
cp LINK_STATE_BATTLING
jr z,.next4
- ld a,[W_OPTIONS]
+ ld a,[wOptions]
bit 6,a
jr nz,.next4
ld hl, TrainerAboutToUseText
call PrintText
- hlCoord 0, 7
- ld bc,$0801
+ coord hl, 0, 7
+ lb bc, 8, 1
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID
ld a,[wCurrentMenuItem]
and a
jr nz,.next4
- ld a,2
- ld [wd07d],a
+ ld a,BATTLE_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
call DisplayPartyMenu
.next9
ld a,1
@@ -1488,11 +1501,11 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call LoadScreenTilesFromBuffer1
.next4
call ClearSprites
- ld hl,wTileMap
- ld bc,$040B
+ coord hl, 0, 0
+ lb bc, 4, 11
call ClearScreenArea
- ld b,1
- call GoPAL_SET
+ ld b, SET_PAL_BATTLE
+ call RunPaletteCommand
call GBPalNormal
ld hl,TrainerSentOutText
call PrintText
@@ -1502,10 +1515,10 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call GetMonHeader
ld de,vFrontPic
call LoadMonFrontSprite
- ld a,$CF
- ld [$FFE1],a
- hlCoord 15, 6
- predef Func_3f073
+ ld a,-$31
+ ld [hStartTileID],a
+ coord hl, 15, 6
+ predef AnimateSendingOutMon
ld a,[wEnemyMonSpecies2]
call PlayCry
call DrawEnemyHUDAndHPBar
@@ -1518,17 +1531,17 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call SaveScreenTilesToBuffer1
jp SwitchPlayerMon
-TrainerAboutToUseText: ; 3ca79 (f:4a79)
+TrainerAboutToUseText:
TX_FAR _TrainerAboutToUseText
db "@"
-TrainerSentOutText: ; 3ca7e (f:4a7e)
+TrainerSentOutText:
TX_FAR _TrainerSentOutText
db "@"
; tests if the player has any pokemon that are not fainted
; sets d = 0 if all fainted, d != 0 if some mons are still alive
-AnyPartyAlive: ; 3ca83 (f:4a83)
+AnyPartyAlive:
ld a, [wPartyCount]
ld e, a
xor a
@@ -1546,7 +1559,7 @@ AnyPartyAlive: ; 3ca83 (f:4a83)
; tests if player mon has fainted
; stores whether mon has fainted in Z flag
-HasMonFainted: ; 3ca97 (f:4a97)
+HasMonFainted:
ld a, [wWhichPokemon]
ld hl, wPartyMon1HP
ld bc, wPartyMon2 - wPartyMon1
@@ -1554,7 +1567,7 @@ HasMonFainted: ; 3ca97 (f:4a97)
ld a, [hli]
or [hl]
ret nz
- ld a, [wd11d]
+ ld a, [wFirstMonsNotOutYet]
and a
jr nz, .done
ld hl, NoWillText
@@ -1563,22 +1576,22 @@ HasMonFainted: ; 3ca97 (f:4a97)
xor a
ret
-NoWillText: ; 3cab4 (f:4ab4)
+NoWillText:
TX_FAR _NoWillText
db "@"
; try to run from battle (hl = player speed, de = enemy speed)
; stores whether the attempt was successful in carry flag
-TryRunningFromBattle: ; 3cab9 (f:4ab9)
+TryRunningFromBattle:
call IsGhostBattle
jp z, .canEscape ; jump if it's a ghost battle
- ld a, [W_BATTLETYPE]
- cp $2
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
jp z, .canEscape ; jump if it's a safari battle
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jp z, .canEscape
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
jr nz, .trainerBattle ; jump if it's a trainer battle
ld a, [wNumRunAttempts]
@@ -1589,14 +1602,14 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
ld a, [hl]
ld [H_MULTIPLICAND + 2], a
ld a, [de]
- ld [$ff8d], a
+ ld [hEnemySpeed], a
inc de
ld a, [de]
- ld [$ff8e], a
+ ld [hEnemySpeed + 1], a
call LoadScreenTilesFromBuffer1
ld de, H_MULTIPLICAND + 1
- ld hl, $ff8d
- ld c, $2
+ ld hl, hEnemySpeed
+ ld c, 2
call StringCmp
jr nc, .canEscape ; jump if player speed greater than enemy speed
xor a
@@ -1608,9 +1621,9 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
ld [H_DIVIDEND], a
ld a, [H_PRODUCT + 3]
ld [H_DIVIDEND + 1], a
- ld a, [$ff8d]
+ ld a, [hEnemySpeed]
ld b, a
- ld a, [$ff8e]
+ ld a, [hEnemySpeed + 1]
; divide enemy speed by 4
srl b
rr a
@@ -1641,19 +1654,19 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
ld b, a
ld a, [H_QUOTIENT + 3]
cp b
- jr nc, .canEscape ; if the random value was less than or equal to the quotient
+ jr nc, .canEscape ; if the random value was less than or equal to the quotient
; plus 30 times the number of attempts, the player can escape
; can't escape
ld a, $1
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a ; you lose your turn when you can't escape
ld hl, CantEscapeText
jr .printCantEscapeOrNoRunningText
.trainerBattle
ld hl, NoRunningText
.printCantEscapeOrNoRunningText
call PrintText
- ld a, $1
- ld [wd11f], a
+ ld a, 1
+ ld [wForcePlayerToChooseMon], a
call SaveScreenTilesToBuffer1
and a ; reset carry
ret
@@ -1665,19 +1678,19 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
; link battle
call SaveScreenTilesToBuffer1
xor a
- ld [wcd6a], a
- ld a, $f
+ ld [wActionResultOrTookBattleTurn], a
+ ld a, LINKBATTLE_RUN
ld [wPlayerMoveListIndex], a
call LinkBattleExchangeData
call LoadScreenTilesFromBuffer1
ld a, [wSerialExchangeNybbleReceiveData]
- cp $f
+ cp LINKBATTLE_RUN
ld a, $2
jr z, .playSound
dec a
.playSound
ld [wBattleResult], a
- ld a, (SFX_08_44 - SFX_Headers_08) / 3
+ ld a, SFX_RUN
call PlaySoundWaitForCurrent
ld hl, GotAwayText
call PrintText
@@ -1686,37 +1699,37 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
scf ; set carry
ret
-CantEscapeText: ; 3cb97 (f:4b97)
+CantEscapeText:
TX_FAR _CantEscapeText
db "@"
-NoRunningText: ; 3cb9c (f:4b9c)
+NoRunningText:
TX_FAR _NoRunningText
db "@"
-GotAwayText: ; 3cba1 (f:4ba1)
+GotAwayText:
TX_FAR _GotAwayText
db "@"
; copies from party data to battle mon data when sending out a new player mon
-LoadBattleMonFromParty: ; 3cba6 (f:4ba6)
+LoadBattleMonFromParty:
ld a, [wWhichPokemon]
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
ld hl, wPartyMon1Species
call AddNTimes
ld de, wBattleMonSpecies
- ld bc, $c
+ ld bc, wBattleMonDVs - wBattleMonSpecies
call CopyData
- ld bc, $f
+ ld bc, wPartyMon1DVs - wPartyMon1OTID
add hl, bc
ld de, wBattleMonDVs
- ld bc, $2
+ ld bc, NUM_DVS
call CopyData
ld de, wBattleMonPP
- ld bc, $4
+ ld bc, NUM_MOVES
call CopyData
ld de, wBattleMonLevel
- ld bc, $b
+ ld bc, wBattleMonPP - wBattleMonLevel
call CopyData
ld a, [wBattleMonSpecies2]
ld [wd0b5], a
@@ -1725,16 +1738,16 @@ LoadBattleMonFromParty: ; 3cba6 (f:4ba6)
ld a, [wPlayerMonNumber]
call SkipFixedLengthTextEntries
ld de, wBattleMonNick
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wBattleMonLevel
ld de, wPlayerMonUnmodifiedLevel ; block of memory used for unmodified stats
- ld bc, $b
+ ld bc, 1 + NUM_STATS * 2
call CopyData
call ApplyBurnAndParalysisPenaltiesToPlayer
call ApplyBadgeStatBoosts
ld a, $7 ; default stat modifier
- ld b, $8
+ ld b, NUM_STAT_MODS
ld hl, wPlayerMonAttackMod
.statModLoop
ld [hli], a
@@ -1743,24 +1756,24 @@ LoadBattleMonFromParty: ; 3cba6 (f:4ba6)
ret
; copies from enemy party data to current enemy mon data when sending out a new enemy mon
-LoadEnemyMonFromParty: ; 3cc13 (f:4c13)
+LoadEnemyMonFromParty:
ld a, [wWhichPokemon]
- ld bc, $2c
+ ld bc, wEnemyMon2 - wEnemyMon1
ld hl, wEnemyMons
call AddNTimes
ld de, wEnemyMonSpecies
- ld bc, $c
+ ld bc, wEnemyMonDVs - wEnemyMonSpecies
call CopyData
- ld bc, $f
+ ld bc, wEnemyMon1DVs - wEnemyMon1OTID
add hl, bc
ld de, wEnemyMonDVs
- ld bc, $2
+ ld bc, NUM_DVS
call CopyData
ld de, wEnemyMonPP
- ld bc, $4
+ ld bc, NUM_MOVES
call CopyData
ld de, wEnemyMonLevel
- ld bc, $b
+ ld bc, wEnemyMonPP - wEnemyMonLevel
call CopyData
ld a, [wEnemyMonSpecies]
ld [wd0b5], a
@@ -1769,16 +1782,16 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13)
ld a, [wWhichPokemon]
call SkipFixedLengthTextEntries
ld de, wEnemyMonNick
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wEnemyMonLevel
ld de, wEnemyMonUnmodifiedLevel ; block of memory used for unmodified stats
- ld bc, $b
+ ld bc, 1 + NUM_STATS * 2
call CopyData
call ApplyBurnAndParalysisPenaltiesToEnemy
- ld hl, W_MONHBASESTATS
+ ld hl, wMonHBaseStats
ld de, wEnemyMonBaseStats
- ld b, $5
+ ld b, NUM_STATS
.copyBaseStatsLoop
ld a, [hli]
ld [de], a
@@ -1786,7 +1799,7 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13)
dec b
jr nz, .copyBaseStatsLoop
ld a, $7 ; default stat modifier
- ld b, $8
+ ld b, NUM_STAT_MODS
ld hl, wEnemyMonStatMods
.statModLoop
ld [hli], a
@@ -1796,7 +1809,7 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13)
ld [wEnemyMonPartyPos], a
ret
-SendOutMon: ; 3cc91 (f:4c91)
+SendOutMon:
callab PrintSendOutMonMessage
ld hl, wEnemyMonHP
ld a, [hli]
@@ -1807,13 +1820,13 @@ SendOutMon: ; 3cc91 (f:4c91)
call DrawPlayerHUDAndHPBar
predef LoadMonBackPic
xor a
- ld [$ffe1], a
- ld hl, wcc2d
+ ld [hStartTileID], a
+ ld hl, wBattleAndStartSavedMenuItem
ld [hli], a
ld [hl], a
ld [wBoostExpByExpAll], a
ld [wDamageMultipliers], a
- ld [W_PLAYERMOVENUM], a
+ ld [wPlayerMoveNum], a
ld hl, wPlayerUsedMove
ld [hli], a
ld [hl], a
@@ -1823,56 +1836,56 @@ SendOutMon: ; 3cc91 (f:4c91)
ld [hli], a
ld [hli], a
ld [hl], a
- ld [W_PLAYERDISABLEDMOVE], a
- ld [wccee], a
- ld [wccf7], a
- ld b, $1
- call GoPAL_SET
- ld hl, W_ENEMYBATTSTATUS1
+ ld [wPlayerDisabledMove], a
+ ld [wPlayerDisabledMoveNumber], a
+ ld [wPlayerMonMinimized], a
+ ld b, SET_PAL_BATTLE
+ call RunPaletteCommand
+ ld hl, wEnemyBattleStatus1
res UsingTrappingMove, [hl]
ld a, $1
ld [H_WHOSETURN], a
ld a, POOF_ANIM
call PlayMoveAnimation
- hlCoord 4, 11
- predef Func_3f073
+ coord hl, 4, 11
+ predef AnimateSendingOutMon
ld a, [wcf91]
call PlayCry
call PrintEmptyString
jp SaveScreenTilesToBuffer1
-; show 2 stages of the player getting smaller before disappearing
-AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa)
- hlCoord 1, 5
- ld bc, $707
+; show 2 stages of the player mon getting smaller before disappearing
+AnimateRetreatingPlayerMon:
+ coord hl, 1, 5
+ lb bc, 7, 7
call ClearScreenArea
- hlCoord 3, 7
- ld bc, $505
+ coord hl, 3, 7
+ lb bc, 5, 5
xor a
- ld [wcd6c], a
- ld [H_DOWNARROWBLINKCNT1], a
- predef Func_79aba
- ld c, $4
+ ld [wDownscaledMonSize], a
+ ld [hBaseTileID], a
+ predef CopyDownscaledMonTiles
+ ld c, 4
call DelayFrames
call .clearScreenArea
- hlCoord 4, 9
- ld bc, $303
- ld a, $1
- ld [wcd6c], a
+ coord hl, 4, 9
+ lb bc, 3, 3
+ ld a, 1
+ ld [wDownscaledMonSize], a
xor a
- ld [H_DOWNARROWBLINKCNT1], a
- predef Func_79aba
+ ld [hBaseTileID], a
+ predef CopyDownscaledMonTiles
call Delay3
call .clearScreenArea
ld a, $4c
Coorda 5, 11
.clearScreenArea
- hlCoord 1, 5
- ld bc, $707
+ coord hl, 1, 5
+ lb bc, 7, 7
jp ClearScreenArea
; reads player's current mon's HP into wBattleMonHP
-ReadPlayerMonCurHPAndStatus: ; 3cd43 (f:4d43)
+ReadPlayerMonCurHPAndStatus:
ld a, [wPlayerMonNumber]
ld hl, wPartyMon1HP
ld bc, wPartyMon2 - wPartyMon1
@@ -1883,83 +1896,83 @@ ReadPlayerMonCurHPAndStatus: ; 3cd43 (f:4d43)
ld bc, $4 ; 2 bytes HP, 1 byte unknown (unused?), 1 byte status
jp CopyData
-DrawHUDsAndHPBars: ; 3cd5a (f:4d5a)
+DrawHUDsAndHPBars:
call DrawPlayerHUDAndHPBar
jp DrawEnemyHUDAndHPBar
-DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60)
+DrawPlayerHUDAndHPBar:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- hlCoord 9, 7
- ld bc, $50b
+ coord hl, 9, 7
+ lb bc, 5, 11
call ClearScreenArea
callab PlacePlayerHUDTiles
- hlCoord 18, 9
+ coord hl, 18, 9
ld [hl], $73
ld de, wBattleMonNick
- hlCoord 10, 7
+ coord hl, 10, 7
call CenterMonName
call PlaceString
ld hl, wBattleMonSpecies
ld de, wLoadedMon
- ld bc, $c
+ ld bc, wBattleMonDVs - wBattleMonSpecies
call CopyData
ld hl, wBattleMonLevel
ld de, wLoadedMonLevel
- ld bc, $b
+ ld bc, wBattleMonPP - wBattleMonLevel
call CopyData
- hlCoord 14, 8
+ coord hl, 14, 8
push hl
inc hl
ld de, wLoadedMonStatus
call PrintStatusConditionNotFainted
pop hl
- jr nz, .asm_3cdae
+ jr nz, .doNotPrintLevel
call PrintLevel
-.asm_3cdae
+.doNotPrintLevel
ld a, [wLoadedMonSpecies]
ld [wcf91], a
- hlCoord 10, 9
+ coord hl, 10, 9
predef DrawHP
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, wcf1d
+ ld hl, wPlayerHPBarColor
call GetBattleHealthBarColor
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
- jr z, .asm_3cdd9
- ld a, [wccf6]
- and a
- ret nz
- ld a, [wcf1d]
- cp $2
- jr z, .asm_3cde6
-.asm_3cdd9
+ jr z, .fainted
+ ld a, [wLowHealthAlarmDisabled]
+ and a ; has the alarm been disabled because the player has already won?
+ ret nz ; if so, return
+ ld a, [wPlayerHPBarColor]
+ cp HP_BAR_RED
+ jr z, .setLowHealthAlarm
+.fainted
ld hl, wLowHealthAlarm
bit 7, [hl] ;low health alarm enabled?
ld [hl], $0
ret z
xor a
- ld [wc02a], a
+ ld [wChannelSoundIDs + Ch4], a
ret
-.asm_3cde6
+.setLowHealthAlarm
ld hl, wLowHealthAlarm
set 7, [hl] ;enable low health alarm
ret
-DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec)
+DrawEnemyHUDAndHPBar:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, wTileMap
- ld bc, $40c
+ coord hl, 0, 0
+ lb bc, 4, 12
call ClearScreenArea
callab PlaceEnemyHUDTiles
ld de, wEnemyMonNick
- hlCoord 1, 0
+ coord hl, 1, 0
call CenterMonName
call PlaceString
- hlCoord 4, 1
+ coord hl, 4, 1
push hl
inc hl
ld de, wEnemyMonStatus
@@ -2032,27 +2045,27 @@ DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec)
.drawHPBar
xor a
ld [wHPBarType], a
- hlCoord 2, 2
+ coord hl, 2, 2
call DrawHPBar
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, wcf1e
+ ld hl, wEnemyHPBarColor
-GetBattleHealthBarColor: ; 3ce90 (f:4e90)
+GetBattleHealthBarColor:
ld b, [hl]
call GetHealthBarColor
ld a, [hl]
cp b
ret z
- ld b, $1
- jp GoPAL_SET
+ ld b, SET_PAL_BATTLE
+ jp RunPaletteCommand
; center's mon's name on the battle screen
; if the name is 1 or 2 letters long, it is printed 2 spaces more to the right than usual
; (i.e. for names longer than 4 letters)
; if the name is 3 or 4 letters long, it is printed 1 space more to the right than usual
; (i.e. for names longer than 4 letters)
-CenterMonName: ; 3ce9c (f:4e9c)
+CenterMonName:
push de
inc hl
inc hl
@@ -2060,11 +2073,11 @@ CenterMonName: ; 3ce9c (f:4e9c)
.loop
inc de
ld a, [de]
- cp $50
+ cp "@"
jr z, .done
inc de
ld a, [de]
- cp $50
+ cp "@"
jr z, .done
dec hl
dec b
@@ -2073,30 +2086,30 @@ CenterMonName: ; 3ce9c (f:4e9c)
pop de
ret
-DisplayBattleMenu: ; 3ceb3 (f:4eb3)
+DisplayBattleMenu:
call LoadScreenTilesFromBuffer1 ; restore saved screen
- ld a, [W_BATTLETYPE]
+ ld a, [wBattleType]
and a
jr nz, .nonstandardbattle
call DrawHUDsAndHPBars
call PrintEmptyString
call SaveScreenTilesToBuffer1
.nonstandardbattle
- ld a, [W_BATTLETYPE]
- cp $2 ; safari
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
ld a, BATTLE_MENU_TEMPLATE
jr nz, .menuselected
ld a, SAFARI_BATTLE_MENU_TEMPLATE
.menuselected
ld [wTextBoxID], a
call DisplayTextBoxID
- ld a, [W_BATTLETYPE]
+ ld a, [wBattleType]
dec a
jp nz, .handleBattleMenuInput ; handle menu input if it's not the old man tutorial
; the following happens for the old man tutorial
ld hl, wPlayerName
- ld de, W_GRASSRATE
- ld bc, $b
+ ld de, wGrassRate
+ ld bc, NAME_LENGTH
call CopyData ; temporarily save the player name in unused space,
; which is supposed to get overwritten when entering a
; map with wild Pokémon. Due to an oversight, the data
@@ -2104,25 +2117,25 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
; Missingno. glitch can show up.
ld hl, .oldManName
ld de, wPlayerName
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
; the following simulates the keystrokes by drawing menus on screen
- hlCoord 9, 14
+ coord hl, 9, 14
ld [hl], "▶"
- ld c, $50
+ ld c, 80
call DelayFrames
- ld [hl], $7f
- hlCoord 9, 16
+ ld [hl], " "
+ coord hl, 9, 16
ld [hl], "▶"
- ld c, $32
+ ld c, 50
call DelayFrames
- ld [hl], $ec
+ ld [hl], "▷"
ld a, $2 ; select the "ITEM" menu
jp .upperLeftMenuItemWasNotSelected
.oldManName
db "OLD MAN@"
.handleBattleMenuInput
- ld a, [wcc2d]
+ ld a, [wBattleAndStartSavedMenuItem]
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
sub 2 ; check if the cursor is in the left column
@@ -2132,8 +2145,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
ld [wLastMenuItem], a
jr .rightColumn
.leftColumn ; put cursor in left column of menu
- ld a, [W_BATTLETYPE]
- cp $2
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
ld a, " "
jr z, .safariLeftColumn
; put cursor in left column for normal battle menu (i.e. when it's not a Safari battle)
@@ -2144,9 +2157,9 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
.safariLeftColumn
Coorda 13, 14
Coorda 13, 16
- hlCoord 7, 14
- ld de, W_NUMSAFARIBALLS
- ld bc, $102
+ coord hl, 7, 14
+ ld de, wNumSafariBalls
+ lb bc, 1, 2
call PrintNumber
ld b, $1 ; top menu item X
.leftColumn_WaitForInput
@@ -2165,8 +2178,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
jr nz, .rightColumn
jr .AButtonPressed ; the A button was pressed
.rightColumn ; put cursor in right column of menu
- ld a, [W_BATTLETYPE]
- cp $2
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
ld a, " "
jr z, .safariRightColumn
; put cursor in right column for normal battle menu (i.e. when it's not a Safari battle)
@@ -2177,9 +2190,9 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
.safariRightColumn
Coorda 1, 14 ; clear upper cursor position in left column
Coorda 1, 16 ; clear lower cursor position in left column
- hlCoord 7, 14
- ld de, W_NUMSAFARIBALLS
- ld bc, $102
+ coord hl, 7, 14
+ ld de, wNumSafariBalls
+ lb bc, 1, 2
call PrintNumber
ld b, $d ; top menu item X
.rightColumn_WaitForInput
@@ -2202,10 +2215,10 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
ld [wCurrentMenuItem], a
.AButtonPressed
call PlaceUnfilledArrowMenuCursor
- ld a, [W_BATTLETYPE]
- cp $2 ; is it a Safari battle?
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
ld a, [wCurrentMenuItem]
- ld [wcc2d], a
+ ld [wBattleAndStartSavedMenuItem], a
jr z, .handleMenuSelection
; not Safari battle
; swap the IDs of the item menu and party menu (this is probably because they swapped the positions
@@ -2224,8 +2237,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
and a
jr nz, .upperLeftMenuItemWasNotSelected
; the upper left menu item was selected
- ld a, [W_BATTLETYPE]
- cp $2
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
jr z, .throwSafariBallWasSelected
; the "FIGHT" menu was selected
xor a
@@ -2252,8 +2265,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
.notLinkBattle
call SaveScreenTilesToBuffer2
- ld a, [W_BATTLETYPE]
- cp $2 ; is it a safari battle?
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
jr nz, BagWasSelected
; bait was selected
@@ -2263,21 +2276,21 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
BagWasSelected:
call LoadScreenTilesFromBuffer1
- ld a, [W_BATTLETYPE]
+ ld a, [wBattleType]
and a ; is it a normal battle?
jr nz, .next
; normal battle
call DrawHUDsAndHPBars
.next
- ld a, [W_BATTLETYPE]
+ ld a, [wBattleType]
dec a ; is it the old man tutorial?
jr nz, DisplayPlayerBag ; no, it is a normal battle
ld hl, OldManItemList
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
jr DisplayBagMenu
OldManItemList:
@@ -2289,22 +2302,22 @@ DisplayPlayerBag:
; get the pointer to player's bag when in a normal battle
ld hl, wNumBagItems
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
DisplayBagMenu:
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld a, ITEMLISTMENU
ld [wListMenuID], a
- ld a, [wcc2c]
+ ld a, [wBagSavedMenuItem]
ld [wCurrentMenuItem], a
call DisplayListMenuID
ld a, [wCurrentMenuItem]
- ld [wcc2c], a
+ ld [wBagSavedMenuItem], a
ld a, $0
- ld [wcc37], a
+ ld [wMenuWatchMovingOutOfBounds], a
ld [wMenuItemToSwap], a
jp c, DisplayBattleMenu ; go back to battle menu if an item was not selected
@@ -2315,36 +2328,36 @@ UseBagItem:
call GetItemName
call CopyStringToCF4B ; copy name
xor a
- ld [wd152], a
+ ld [wPseudoItemID], a
call UseItem
call LoadHudTilePatterns
call ClearSprites
xor a
ld [wCurrentMenuItem], a
- ld a, [W_BATTLETYPE]
- cp $2 ; is it a safari battle?
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
jr z, .checkIfMonCaptured
- ld a, [wcd6a]
+ ld a, [wActionResultOrTookBattleTurn]
and a ; was the item used successfully?
jp z, BagWasSelected ; if not, go back to the bag menu
- ld a, [W_PLAYERBATTSTATUS1]
+ ld a, [wPlayerBattleStatus1]
bit UsingTrappingMove, a ; is the player using a multi-turn move like wrap?
jr z, .checkIfMonCaptured
ld hl, wPlayerNumAttacksLeft
dec [hl]
jr nz, .checkIfMonCaptured
- ld hl, W_PLAYERBATTSTATUS1
+ ld hl, wPlayerBattleStatus1
res UsingTrappingMove, [hl] ; not using multi-turn move any more
.checkIfMonCaptured
- ld a, [wd11c]
+ ld a, [wCapturedMonSpecies]
and a ; was the enemy mon captured with a ball?
jr nz, .returnAfterCapturingMon
- ld a, [W_BATTLETYPE]
- cp $2 ; is it a safari battle?
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
jr z, .returnAfterUsingItem_NoCapture
; not a safari battle
call LoadScreenTilesFromBuffer1
@@ -2359,7 +2372,7 @@ UseBagItem:
.returnAfterCapturingMon
call GBPalNormal
xor a
- ld [wd11c], a
+ ld [wCapturedMonSpecies], a
ld a, $2
ld [wBattleResult], a
scf ; set carry
@@ -2374,8 +2387,8 @@ PartyMenuOrRockOrRun:
jp nz, BattleMenu_RunWasSelected
; party menu or rock was selected
call SaveScreenTilesToBuffer2
- ld a, [W_BATTLETYPE]
- cp $2 ; is it a safari battle?
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_SAFARI
jr nz, .partyMenuWasSelected
; safari battle
ld a, SAFARI_ROCK
@@ -2383,8 +2396,8 @@ PartyMenuOrRockOrRun:
jp UseBagItem
.partyMenuWasSelected
call LoadScreenTilesFromBuffer1
- xor a
- ld [wd07d], a
+ xor a ; NORMAL_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
ld [wMenuItemToSwap], a
call DisplayPartyMenu
.checkIfPartyMonWasSelected
@@ -2394,16 +2407,16 @@ PartyMenuOrRockOrRun:
call GBPalWhiteOut
call LoadHudTilePatterns
call LoadScreenTilesFromBuffer2
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call GBPalNormal
jp DisplayBattleMenu
.partyMonDeselected
- hlCoord 11, 11
- ld bc, $81
- ld a, $7f
+ coord hl, 11, 11
+ ld bc, 6 * SCREEN_WIDTH + 9
+ ld a, " "
call FillMemory
- xor a
- ld [wd07d], a
+ xor a ; NORMAL_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
call GoBackToPartyMenu
jr .checkIfPartyMonWasSelected
.partyMonWasSelected
@@ -2434,20 +2447,20 @@ PartyMenuOrRockOrRun:
and a ; was Switch selected?
jr z, .switchMon ; if so, jump
; Stats was selected
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
ld hl, wPartyMon1
call ClearSprites
; display the two status screens
predef StatusScreen
predef StatusScreen2
; now we need to reload the enemy mon pic
- ld a, [W_ENEMYBATTSTATUS2]
+ ld a, [wEnemyBattleStatus2]
bit HasSubstituteUp, a ; does the enemy mon have a substitute?
ld hl, AnimationSubstitute
jr nz, .doEnemyMonAnimation
; enemy mon doesn't have substitute
- ld a, [wccf3]
+ ld a, [wEnemyMonMinimized]
and a ; has the enemy mon used Minimise?
ld hl, AnimationMinimizeMon
jr nz, .doEnemyMonAnimation
@@ -2478,24 +2491,24 @@ PartyMenuOrRockOrRun:
call HasMonFainted
jp z, .partyMonDeselected ; can't switch to fainted mon
ld a, $1
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
call GBPalWhiteOut
call ClearSprites
call LoadHudTilePatterns
call LoadScreenTilesFromBuffer1
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call GBPalNormal
; fall through to SwitchPlayerMon
-SwitchPlayerMon: ; 3d1ba (f:51ba)
+SwitchPlayerMon:
callab RetreatMon
- ld c, $32
+ ld c, 50
call DelayFrames
call AnimateRetreatingPlayerMon
ld a, [wWhichPokemon]
ld [wPlayerMonNumber], a
ld c, a
- ld b, $1
+ ld b, FLAG_SET
push bc
ld hl, wPartyGainExpFlags
predef FlagActionPredef
@@ -2510,26 +2523,26 @@ SwitchPlayerMon: ; 3d1ba (f:51ba)
and a
ret
-AlreadyOutText: ; 3d1f5 (f:51f5)
+AlreadyOutText:
TX_FAR _AlreadyOutText
db "@"
-BattleMenu_RunWasSelected: ; 3d1fa (f:51fa)
+BattleMenu_RunWasSelected:
call LoadScreenTilesFromBuffer1
ld a, $3
ld [wCurrentMenuItem], a
ld hl, wBattleMonSpeed
ld de, wEnemyMonSpeed
call TryRunningFromBattle
- ld a, $0
- ld [wd11f], a
+ ld a, 0
+ ld [wForcePlayerToChooseMon], a
ret c
- ld a, [wcd6a]
+ ld a, [wActionResultOrTookBattleTurn]
and a
- ret nz
+ ret nz ; return if the player couldn't escape
jp DisplayBattleMenu
-MoveSelectionMenu: ; 3d219 (f:5219)
+MoveSelectionMenu:
ld a, [wMoveMenuType]
dec a
jr z, .mimicmenu
@@ -2560,17 +2573,18 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ret z
ld hl, wBattleMonMoves
call .loadmoves
- hlCoord 4, 12
- ld b, $4
- ld c, $e
- di
+ coord hl, 4, 12
+ ld b, 4
+ ld c, 14
+ di ; out of pure coincidence, it is possible for vblank to occur between the di and ei
+ ; so it is necessary to put the di ei block to not cause tearing
call TextBoxBorder
- hlCoord 4, 12
+ coord hl, 4, 12
ld [hl], $7a
- hlCoord 10, 12
+ coord hl, 10, 12
ld [hl], $7e
ei
- hlCoord 6, 13
+ coord hl, 6, 13
call .writemoves
ld b, $5
ld a, $c
@@ -2578,11 +2592,11 @@ MoveSelectionMenu: ; 3d219 (f:5219)
.mimicmenu
ld hl, wEnemyMonMoves
call .loadmoves
- hlCoord 0, 7
- ld b, $4
- ld c, $e
+ coord hl, 0, 7
+ ld b, 4
+ ld c, 14
call TextBoxBorder
- hlCoord 2, 8
+ coord hl, 2, 8
call .writemoves
ld b, $1
ld a, $7
@@ -2590,22 +2604,22 @@ MoveSelectionMenu: ; 3d219 (f:5219)
.relearnmenu
ld a, [wWhichPokemon]
ld hl, wPartyMon1Moves
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
call .loadmoves
- hlCoord 4, 7
- ld b, $4
- ld c, $e
+ coord hl, 4, 7
+ ld b, 4
+ ld c, 14
call TextBoxBorder
- hlCoord 6, 8
+ coord hl, 6, 8
call .writemoves
ld b, $5
ld a, $7
.menuset
ld hl, wTopMenuItemY
- ld [hli], a
+ ld [hli], a ; wTopMenuItemY
ld a, b
- ld [hli], a
+ ld [hli], a ; wTopMenuItemX
ld a, [wMoveMenuType]
cp $1
jr z, .selectedmoveknown
@@ -2614,30 +2628,30 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ld a, [wPlayerMoveListIndex]
inc a
.selectedmoveknown
- ld [hli], a
+ ld [hli], a ; wCurrentMenuItem
inc hl ; wTileBehindCursor untouched
- ld a, [wcd6c]
+ ld a, [wNumMovesMinusOne]
inc a
inc a
- ld [hli], a
+ ld [hli], a ; wMaxMenuItem
ld a, [wMoveMenuType]
dec a
- ld b, $c1 ; can't use B
+ ld b, D_UP | D_DOWN | A_BUTTON
jr z, .matchedkeyspicked
dec a
- ld b, $c3
+ ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON
jr z, .matchedkeyspicked
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr z, .matchedkeyspicked
- ld a, [W_FLAGS_D733]
- bit 0, a
- ld b, $c7
+ ld a, [wFlags_D733]
+ bit BIT_TEST_BATTLE, a
+ ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON | SELECT
jr z, .matchedkeyspicked
ld b, $ff
.matchedkeyspicked
ld a, b
- ld [hli], a
+ ld [hli], a ; wMenuWatchedKeys
ld a, [wMoveMenuType]
cp $1
jr z, .movelistindex1
@@ -2647,29 +2661,29 @@ MoveSelectionMenu: ; 3d219 (f:5219)
ld [hl], a
; fallthrough
-SelectMenuItem: ; 3d2fe (f:52fe)
+SelectMenuItem:
ld a, [wMoveMenuType]
and a
jr z, .battleselect
dec a
jr nz, .select
- hlCoord 1, 14
+ coord hl, 1, 14
ld de, WhichTechniqueString
call PlaceString
jr .select
.battleselect
- ld a, [W_FLAGS_D733]
- bit 0, a
+ ld a, [wFlags_D733]
+ bit BIT_TEST_BATTLE, a
jr nz, .select
call PrintMenuItem
ld a, [wMenuItemToSwap]
and a
jr z, .select
- hlCoord 5, 13
+ coord hl, 5, 13
dec a
- ld bc, $14
+ ld bc, SCREEN_WIDTH
call AddNTimes
- ld [hl], $ec
+ ld [hl], "▷"
.select
ld hl, hFlags_0xFFF6
set 1, [hl]
@@ -2677,9 +2691,9 @@ SelectMenuItem: ; 3d2fe (f:52fe)
ld hl, hFlags_0xFFF6
res 1, [hl]
bit 6, a
- jp nz, CursorUp ; up
+ jp nz, SelectMenuItem_CursorUp ; up
bit 7, a
- jp nz, CursorDown ; down
+ jp nz, SelectMenuItem_CursorDown ; down
bit 2, a
jp nz, SwapMovesInMenu ; select
bit 1, a ; B, but was it reset above?
@@ -2692,10 +2706,10 @@ SelectMenuItem: ; 3d2fe (f:52fe)
ld b, a
ld a, [wMoveMenuType]
dec a ; if not mimic
- jr nz, .nob
+ jr nz, .notB
pop af
ret
-.nob
+.notB
dec a
ld a, b
ld [wPlayerMoveListIndex], a
@@ -2712,14 +2726,14 @@ SelectMenuItem: ; 3d2fe (f:52fe)
add hl, bc
ld a, [hl]
and $3f
- jr z, .nopp
- ld a, [W_PLAYERDISABLEDMOVE]
+ jr z, .noPP
+ ld a, [wPlayerDisabledMove]
swap a
and $f
dec a
cp c
jr z, .disabled
- ld a, [W_PLAYERBATTSTATUS3]
+ ld a, [wPlayerBattleStatus3]
bit 3, a ; transformed
jr nz, .dummy ; game freak derp
.dummy
@@ -2735,38 +2749,38 @@ SelectMenuItem: ; 3d2fe (f:52fe)
.disabled
ld hl, MoveDisabledText
jr .print
-.nopp
+.noPP
ld hl, MoveNoPPText
.print
call PrintText
call LoadScreenTilesFromBuffer1
jp MoveSelectionMenu
-MoveNoPPText: ; 3d3ae (f:53ae)
+MoveNoPPText:
TX_FAR _MoveNoPPText
db "@"
-MoveDisabledText: ; 3d3b3 (f:53b3)
+MoveDisabledText:
TX_FAR _MoveDisabledText
db "@"
-WhichTechniqueString: ; 3d3b8 (f:53b8)
+WhichTechniqueString:
db "WHICH TECHNIQUE?@"
-CursorUp: ; 3d3c9 (f:53c9)
+SelectMenuItem_CursorUp:
ld a, [wCurrentMenuItem]
and a
jp nz, SelectMenuItem
call EraseMenuCursor
- ld a, [wcd6c]
+ ld a, [wNumMovesMinusOne]
inc a
ld [wCurrentMenuItem], a
jp SelectMenuItem
-CursorDown: ; 3d3dd (f:53dd)
+SelectMenuItem_CursorDown:
ld a, [wCurrentMenuItem]
ld b, a
- ld a, [wcd6c]
+ ld a, [wNumMovesMinusOne]
inc a
inc a
cp b
@@ -2776,14 +2790,14 @@ CursorDown: ; 3d3dd (f:53dd)
ld [wCurrentMenuItem], a
jp SelectMenuItem
-AnyMoveToSelect: ; 3d3f5 (f:53f5)
+AnyMoveToSelect:
; return z and Struggle as the selected move if all moves have 0 PP and/or are disabled
ld a, STRUGGLE
ld [wPlayerSelectedMove], a
- ld a, [W_PLAYERDISABLEDMOVE]
+ ld a, [wPlayerDisabledMove]
and a
ld hl, wBattleMonPP
- jr nz, .asm_3d40e
+ jr nz, .handleDisabledMove
ld a, [hli]
or [hl]
inc hl
@@ -2792,38 +2806,38 @@ AnyMoveToSelect: ; 3d3f5 (f:53f5)
or [hl]
and $3f
ret nz
- jr .asm_3d423
-.asm_3d40e
+ jr .noMovesLeft
+.handleDisabledMove
swap a
- and $f
+ and $f ; get disabled move
ld b, a
- ld d, $5
+ ld d, NUM_MOVES + 1
xor a
-.asm_3d416
+.handleDisabledMovePPLoop
dec d
- jr z, .asm_3d421
- ld c, [hl]
+ jr z, .allMovesChecked
+ ld c, [hl] ; get move PP
inc hl
- dec b
- jr z, .asm_3d416
+ dec b ; is this the disabled move?
+ jr z, .handleDisabledMovePPLoop ; if so, ignore its PP value
or c
- jr .asm_3d416
-.asm_3d421
- and a
- ret nz
-.asm_3d423
+ jr .handleDisabledMovePPLoop
+.allMovesChecked
+ and a ; any PP left?
+ ret nz ; return if a move has PP left
+.noMovesLeft
ld hl, NoMovesLeftText
call PrintText
- ld c, $3c
+ ld c, 60
call DelayFrames
xor a
ret
-NoMovesLeftText: ; 3d430 (f:5430)
+NoMovesLeftText:
TX_FAR _NoMovesLeftText
db "@"
-SwapMovesInMenu: ; 3d435 (f:5435)
+SwapMovesInMenu:
ld a, [wMenuItemToSwap]
and a
jr z, .noMenuItemSelected
@@ -2832,7 +2846,7 @@ SwapMovesInMenu: ; 3d435 (f:5435)
ld hl, wBattleMonPP
call .swapBytes ; swap move PP
; update the index of the disabled move if necessary
- ld hl, W_PLAYERDISABLEDMOVE
+ ld hl, wPlayerDisabledMove
ld a, [hl]
swap a
and $f
@@ -2867,7 +2881,7 @@ SwapMovesInMenu: ; 3d435 (f:5435)
push hl
call .swapBytes ; swap moves
pop hl
- ld bc, $15
+ ld bc, wPartyMon1PP - wPartyMon1Moves
add hl, bc
call .swapBytes ; swap move PP
xor a
@@ -2899,14 +2913,14 @@ SwapMovesInMenu: ; 3d435 (f:5435)
ld [wMenuItemToSwap], a ; select the current menu item for swapping
jp MoveSelectionMenu
-PrintMenuItem: ; 3d4b6 (f:54b6)
+PrintMenuItem:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- hlCoord 0, 8
- ld b, $3
- ld c, $9
+ coord hl, 0, 8
+ ld b, 3
+ ld c, 9
call TextBoxBorder
- ld a, [W_PLAYERDISABLEDMOVE]
+ ld a, [wPlayerDisabledMove]
and a
jr z, .notDisabled
swap a
@@ -2915,7 +2929,7 @@ PrintMenuItem: ; 3d4b6 (f:54b6)
ld a, [wCurrentMenuItem]
cp b
jr nz, .notDisabled
- hlCoord 1, 10
+ coord hl, 1, 10
ld de, DisabledText
call PlaceString
jr .moveDisabled
@@ -2929,13 +2943,13 @@ PrintMenuItem: ; 3d4b6 (f:54b6)
ld c, a
ld b, $0 ; which item in the menu is the cursor pointing to? (0-3)
add hl, bc ; point to the item (move) in memory
- ld a, [hl]
- ld [wPlayerSelectedMove], a ; update wPlayerSelectedMove even if the move
+ ld a, [hl]
+ ld [wPlayerSelectedMove], a ; update wPlayerSelectedMove even if the move
; isn't actually selected (just pointed to by the cursor)
ld a, [wPlayerMonNumber]
ld [wWhichPokemon], a
- ld a, $4
- ld [wcc49], a
+ ld a, BATTLE_MON_DATA
+ ld [wMonDataLocation], a
callab GetMaxPP
ld hl, wCurrentMenuItem
ld c, [hl]
@@ -2946,77 +2960,73 @@ PrintMenuItem: ; 3d4b6 (f:54b6)
ld a, [hl]
and $3f
ld [wcd6d], a
-; print TYPE/<type> and <curPP>/<maxPP>
- hlCoord 1, 9
+; print TYPE/<type> and <curPP>/<maxPP>
+ coord hl, 1, 9
ld de, TypeText
call PlaceString
- hlCoord 7, 11
+ coord hl, 7, 11
ld [hl], "/"
- hlCoord 5, 9
+ coord hl, 5, 9
ld [hl], "/"
- hlCoord 5, 11
+ coord hl, 5, 11
ld de, wcd6d
- ld bc, $102
+ lb bc, 1, 2
call PrintNumber
- hlCoord 8, 11
- ld de, wd11e
- ld bc, $102
+ coord hl, 8, 11
+ ld de, wMaxPP
+ lb bc, 1, 2
call PrintNumber
- call GetCurrentMove
- hlCoord 2, 10
+ call GetCurrentMove
+ coord hl, 2, 10
predef PrintMoveType
.moveDisabled
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
jp Delay3
-DisabledText: ; 3d555 (f:5555)
-IF DEF(_YELLOW)
- db "Disabled!@"
-ELSE
+DisabledText:
db "disabled!@"
-ENDC
-TypeText: ; 3d55f (f:555f)
+TypeText:
db "TYPE@"
-SelectEnemyMove: ; 3d564 (f:5564)
+SelectEnemyMove:
ld a, [wLinkState]
- sub $4
+ sub LINK_STATE_BATTLING
jr nz, .noLinkBattle
; link battle
call SaveScreenTilesToBuffer1
call LinkBattleExchangeData
call LoadScreenTilesFromBuffer1
ld a, [wSerialExchangeNybbleReceiveData]
- cp $e
- jp z, .asm_3d601
- cp $d
+ cp LINKBATTLE_STRUGGLE
+ jp z, .linkedOpponentUsedStruggle
+ cp LINKBATTLE_NO_ACTION
jr z, .unableToSelectMove
- cp $4
+ cp 4
ret nc
ld [wEnemyMoveListIndex], a
ld c, a
ld hl, wEnemyMonMoves
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hl]
jr .done
.noLinkBattle
- ld a, [W_ENEMYBATTSTATUS2]
+ ld a, [wEnemyBattleStatus2]
and (1 << NeedsToRecharge) | (1 << UsingRage) ; need to recharge or using rage
ret nz
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
ld a, [hl]
and (1 << ChargingUp) | (1 << ThrashingAbout) ; using a charging move or thrash/petal dance
ret nz
ld a, [wEnemyMonStatus]
and SLP | 1 << FRZ ; sleeping or frozen
ret nz
- ld a, [W_ENEMYBATTSTATUS1]
+ ld a, [wEnemyBattleStatus1]
and (1 << UsingTrappingMove) | (1 << StoringEnergy) ; using a trapping move like wrap or bide
ret nz
- ld a, [W_PLAYERBATTSTATUS1]
+ ld a, [wPlayerBattleStatus1]
bit UsingTrappingMove, a ; caught in player's trapping move (e.g. wrap)
jr z, .canSelectMove
.unableToSelectMove
@@ -3027,12 +3037,12 @@ SelectEnemyMove: ; 3d564 (f:5564)
ld a, [hld]
and a
jr nz, .atLeastTwoMovesAvailable
- ld a, [W_ENEMYDISABLEDMOVE]
+ ld a, [wEnemyDisabledMove]
and a
ld a, STRUGGLE ; struggle if the only move is disabled
jr nz, .done
.atLeastTwoMovesAvailable
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
jr z, .chooseRandomMove ; wild encounter
callab AIEnemyTrainerChooseMoves
@@ -3040,23 +3050,23 @@ SelectEnemyMove: ; 3d564 (f:5564)
push hl
call BattleRandom
ld b, $1
- cp $3f ; select move 1 in [0,3e] (63/256 chance)
+ cp $3f ; select move 1, [0,3e] (63/256 chance)
jr c, .moveChosen
inc hl
inc b
- cp $7f ; select move 1 in [3f,7e] (64/256 chance)
+ cp $7f ; select move 2, [3f,7e] (64/256 chance)
jr c, .moveChosen
inc hl
inc b
- cp $be ; select move 1 in [7f,bd] (63/256 chance)
+ cp $be ; select move 3, [7f,bd] (63/256 chance)
jr c, .moveChosen
inc hl
- inc b ; select move 4 in [be,ff] (66/256 chance)
+ inc b ; select move 4, [be,ff] (66/256 chance)
.moveChosen
ld a, b
dec a
ld [wEnemyMoveListIndex], a
- ld a, [W_ENEMYDISABLEDMOVE]
+ ld a, [wEnemyDisabledMove]
swap a
and $f
cp b
@@ -3068,72 +3078,73 @@ SelectEnemyMove: ; 3d564 (f:5564)
.done
ld [wEnemySelectedMove], a
ret
-.asm_3d601
+.linkedOpponentUsedStruggle
ld a, STRUGGLE
jr .done
; this appears to exchange data with the other gameboy during link battles
-LinkBattleExchangeData: ; 3d605 (f:5605)
+LinkBattleExchangeData:
ld a, $ff
ld [wSerialExchangeNybbleReceiveData], a
ld a, [wPlayerMoveListIndex]
- cp $f ; is the player running from battle?
- jr z, .asm_3d630
- ld a, [wcd6a]
- and a
- jr nz, .asm_3d629
+ cp LINKBATTLE_RUN ; is the player running from battle?
+ jr z, .doExchange
+ ld a, [wActionResultOrTookBattleTurn]
+ and a ; is the player switching in another mon?
+ jr nz, .switching
+; the player used a move
ld a, [wPlayerSelectedMove]
cp STRUGGLE
- ld b, $e
- jr z, .asm_3d62f
- dec b
- inc a
- jr z, .asm_3d62f
+ ld b, LINKBATTLE_STRUGGLE
+ jr z, .next
+ dec b ; LINKBATTLE_NO_ACTION
+ inc a ; does move equal -1 (i.e. no action)?
+ jr z, .next
ld a, [wPlayerMoveListIndex]
- jr .asm_3d630
-.asm_3d629
+ jr .doExchange
+.switching
ld a, [wWhichPokemon]
- add $4
+ add 4
ld b, a
-.asm_3d62f
+.next
ld a, b
-.asm_3d630
+.doExchange
ld [wSerialExchangeNybbleSendData], a
callab PrintWaitingText
-.asm_3d63b
+.syncLoop1
call Serial_ExchangeNybble
call DelayFrame
ld a, [wSerialExchangeNybbleReceiveData]
inc a
- jr z, .asm_3d63b
- ld b, $a
-.asm_3d649
+ jr z, .syncLoop1
+ ld b, 10
+.syncLoop2
call DelayFrame
call Serial_ExchangeNybble
dec b
- jr nz, .asm_3d649
- ld b, $a
-.asm_3d654
+ jr nz, .syncLoop2
+ ld b, 10
+.syncLoop3
call DelayFrame
call Serial_SendZeroByte
dec b
- jr nz, .asm_3d654
+ jr nz, .syncLoop3
ret
-ExecutePlayerMove: ; 3d65e (f:565e)
+ExecutePlayerMove:
xor a
ld [H_WHOSETURN], a ; set player's turn
ld a, [wPlayerSelectedMove]
inc a
jp z, ExecutePlayerMoveDone ; for selected move = FF, skip most of player's turn
xor a
- ld [W_MOVEMISSED], a
+ ld [wMoveMissed], a
ld [wMonIsDisobedient], a
ld [wMoveDidntMiss], a
ld a, $a
ld [wDamageMultipliers], a
- ld a, [wcd6a]
- and a
+ ld a, [wActionResultOrTookBattleTurn]
+ and a ; has the player already used the turn (e.g. by using an item, trying to run or switching pokemon)
jp nz, ExecutePlayerMoveDone
call PrintGhostText
jp z, ExecutePlayerMoveDone
@@ -3142,14 +3153,14 @@ ExecutePlayerMove: ; 3d65e (f:565e)
jp [hl]
.playerHasNoSpecialCondition
call GetCurrentMove
- ld hl, W_PLAYERBATTSTATUS1
+ ld hl, wPlayerBattleStatus1
bit ChargingUp, [hl] ; charging up for attack
jr nz, PlayerCanExecuteChargingMove
call CheckForDisobedience
jp z, ExecutePlayerMoveDone
-CheckIfPlayerNeedsToChargeUp: ; 3d69a (f:569a)
- ld a, [W_PLAYERMOVEEFFECT]
+CheckIfPlayerNeedsToChargeUp:
+ ld a, [wPlayerMoveEffect]
cp CHARGE_EFFECT
jp z, JumpMoveEffect
cp FLY_EFFECT
@@ -3157,31 +3168,31 @@ CheckIfPlayerNeedsToChargeUp: ; 3d69a (f:569a)
jr PlayerCanExecuteMove
; in-battle stuff
-PlayerCanExecuteChargingMove: ; 3d6a9 (f:56a9)
- ld hl,W_PLAYERBATTSTATUS1
+PlayerCanExecuteChargingMove:
+ ld hl,wPlayerBattleStatus1
res ChargingUp,[hl] ; reset charging up and invulnerability statuses if mon was charging up for an attack
; being fully paralyzed or hurting oneself in confusion removes charging up status
; resulting in the Pokemon being invulnerable for the whole battle
res Invulnerable,[hl]
-PlayerCanExecuteMove: ; 3d6b0 (f:56b0)
+PlayerCanExecuteMove:
call PrintMonName1Text
ld hl,DecrementPP
ld de,wPlayerSelectedMove ; pointer to the move just used
ld b,BANK(DecrementPP)
call Bankswitch
- ld a,[W_PLAYERMOVEEFFECT] ; effect of the move just used
+ ld a,[wPlayerMoveEffect] ; effect of the move just used
ld hl,ResidualEffects1
ld de,1
call IsInArray
- jp c,JumpMoveEffect ; ResidualEffects1 moves skip damage calculation and accuracy tests
- ; unless executed as part of their exclusive effect functions
- ld a,[W_PLAYERMOVEEFFECT]
+ jp c,JumpMoveEffect ; ResidualEffects1 moves skip damage calculation and accuracy tests
+ ; unless executed as part of their exclusive effect functions
+ ld a,[wPlayerMoveEffect]
ld hl,SpecialEffectsCont
ld de,1
call IsInArray
- call c,JumpMoveEffect ; execute the effects of SpecialEffectsCont moves (e.g. Wrap, Thrash) but don't skip anything
-PlayerCalcMoveDamage: ; 3d6dc (f:56dc)
- ld a,[W_PLAYERMOVEEFFECT]
+ call c,JumpMoveEffect ; execute the effects of SpecialEffectsCont moves (e.g. Wrap, Thrash) but don't skip anything
+PlayerCalcMoveDamage:
+ ld a,[wPlayerMoveEffect]
ld hl,SetDamageEffects
ld de,1
call IsInArray
@@ -3197,43 +3208,43 @@ PlayerCalcMoveDamage: ; 3d6dc (f:56dc)
call RandomizeDamage
.moveHitTest
call MoveHitTest
-handleIfPlayerMoveMissed
- ld a,[W_MOVEMISSED]
+handleIfPlayerMoveMissed:
+ ld a,[wMoveMissed]
and a
jr z,getPlayerAnimationType
- ld a,[W_PLAYERMOVEEFFECT]
- sub a,EXPLODE_EFFECT
+ ld a,[wPlayerMoveEffect]
+ sub a,EXPLODE_EFFECT
jr z,playPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT
jr playerCheckIfFlyOrChargeEffect
-getPlayerAnimationType
- ld a,[W_PLAYERMOVEEFFECT]
+getPlayerAnimationType:
+ ld a,[wPlayerMoveEffect]
and a
ld a,4 ; move has no effect other than dealing damage
jr z,playPlayerMoveAnimation
ld a,5 ; move has effect
-playPlayerMoveAnimation
+playPlayerMoveAnimation:
push af
- ld a,[W_PLAYERBATTSTATUS2]
- bit 4,a
- ld hl,Func_79747
- ld b,BANK(Func_79747)
+ ld a,[wPlayerBattleStatus2]
+ bit HasSubstituteUp,a
+ ld hl,HideSubstituteShowMonAnim
+ ld b,BANK(HideSubstituteShowMonAnim)
call nz,Bankswitch
pop af
ld [wAnimationType],a
- ld a,[W_PLAYERMOVENUM]
+ ld a,[wPlayerMoveNum]
call PlayMoveAnimation
call HandleExplodingAnimation
call DrawPlayerHUDAndHPBar
- ld a,[W_PLAYERBATTSTATUS2]
- bit 4,a
- ld hl,Func_79771
- ld b,BANK(Func_79771)
+ ld a,[wPlayerBattleStatus2]
+ bit HasSubstituteUp,a
+ ld hl,ReshowSubstituteAnim
+ ld b,BANK(ReshowSubstituteAnim)
call nz,Bankswitch
jr MirrorMoveCheck
-playerCheckIfFlyOrChargeEffect
- ld c,$1E
+playerCheckIfFlyOrChargeEffect:
+ ld c,30
call DelayFrames
- ld a,[W_PLAYERMOVEEFFECT]
+ ld a,[wPlayerMoveEffect]
cp a,FLY_EFFECT
jr z,.playAnim
cp a,CHARGE_EFFECT
@@ -3244,8 +3255,8 @@ playerCheckIfFlyOrChargeEffect
ld [wAnimationType],a
ld a,STATUS_AFFECTED_ANIM
call PlayMoveAnimation
-MirrorMoveCheck
- ld a,[W_PLAYERMOVEEFFECT]
+MirrorMoveCheck:
+ ld a,[wPlayerMoveEffect]
cp a,MIRROR_MOVE_EFFECT
jr nz,.metronomeCheck
call MirrorMoveCopyMove
@@ -3259,16 +3270,16 @@ MirrorMoveCheck
call MetronomePickMove
jp CheckIfPlayerNeedsToChargeUp ; Go back to damage calculation for the move picked by Metronome
.next
- ld a,[W_PLAYERMOVEEFFECT]
+ ld a,[wPlayerMoveEffect]
ld hl,ResidualEffects2
ld de,1
call IsInArray
jp c,JumpMoveEffect ; done here after executing effects of ResidualEffects2
- ld a,[W_MOVEMISSED]
+ ld a,[wMoveMissed]
and a
jr z,.moveDidNotMiss
call PrintMoveFailureText
- ld a,[W_PLAYERMOVEEFFECT]
+ ld a,[wPlayerMoveEffect]
cp a,EXPLODE_EFFECT ; even if Explosion or Selfdestruct missed, its effect still needs to be activated
jr z,.notDone
jp ExecutePlayerMoveDone ; otherwise, we're done if the move missed
@@ -3279,7 +3290,7 @@ MirrorMoveCheck
ld a,1
ld [wMoveDidntMiss],a
.notDone
- ld a,[W_PLAYERMOVEEFFECT]
+ ld a,[wPlayerMoveEffect]
ld hl,AlwaysHappenSideEffects
ld de,1
call IsInArray
@@ -3291,13 +3302,13 @@ MirrorMoveCheck
ret z ; don't do anything else if the enemy fainted
call HandleBuildingRage
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
bit AttackingMultipleTimes,[hl]
jr z,.executeOtherEffects
ld a,[wPlayerNumAttacksLeft]
dec a
ld [wPlayerNumAttacksLeft],a
- jp nz,getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints.
+ jp nz,getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints.
; damage calculation and accuracy tests only happen for the first hit
res AttackingMultipleTimes,[hl] ; clear attacking multiple times status when all attacks are over
ld hl,MultiHitText
@@ -3305,7 +3316,7 @@ MirrorMoveCheck
xor a
ld [wPlayerNumHits],a
.executeOtherEffects
- ld a,[W_PLAYERMOVEEFFECT]
+ ld a,[wPlayerMoveEffect]
and a
jp z,ExecutePlayerMoveDone
ld hl,SpecialEffects
@@ -3317,17 +3328,17 @@ MirrorMoveCheck
; Responsible for executing Twineedle's second side effect (poison).
jp ExecutePlayerMoveDone
-MultiHitText: ; 3d805 (f:5805)
+MultiHitText:
TX_FAR _MultiHitText
db "@"
-ExecutePlayerMoveDone: ; 3d80a (f:580a)
+ExecutePlayerMoveDone:
xor a
- ld [wcd6a],a
+ ld [wActionResultOrTookBattleTurn],a
ld b,1
ret
-PrintGhostText: ; 3d811 (f:5811)
+PrintGhostText:
; print the ghost battle messages
call IsGhostBattle
ret nz
@@ -3347,19 +3358,19 @@ PrintGhostText: ; 3d811 (f:5811)
xor a
ret
-ScaredText: ; 3d830 (f:5830)
+ScaredText:
TX_FAR _ScaredText
db "@"
-GetOutText: ; 3d835 (f:5835)
+GetOutText:
TX_FAR _GetOutText
db "@"
-IsGhostBattle: ; 3d83a (f:583a)
- ld a,[W_ISINBATTLE]
+IsGhostBattle:
+ ld a,[wIsInBattle]
dec a
ret nz
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
cp a,POKEMONTOWER_1
jr c,.next
cp a,LAVENDER_HOUSE_1
@@ -3374,7 +3385,7 @@ IsGhostBattle: ; 3d83a (f:583a)
; checks for various status conditions affecting the player mon
; stores whether the mon cannot use a move this turn in Z flag
-CheckPlayerStatusConditions: ; 3d854 (f:5854)
+CheckPlayerStatusConditions:
ld hl,wBattleMonStatus
ld a,[hl]
and a,SLP ; sleep mask
@@ -3412,7 +3423,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
jp .returnToHL
.HeldInPlaceCheck
- ld a,[W_ENEMYBATTSTATUS1]
+ ld a,[wEnemyBattleStatus1]
bit UsingTrappingMove,a ; is enemy using a mult-turn move like wrap?
jp z,.FlinchedCheck
ld hl,CantMoveText
@@ -3421,7 +3432,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
jp .returnToHL
.FlinchedCheck
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
bit Flinched,[hl]
jp z,.HyperBeamCheck
res Flinched,[hl] ; reset player's flinch status
@@ -3431,7 +3442,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
jp .returnToHL
.HyperBeamCheck
- ld hl,W_PLAYERBATTSTATUS2
+ ld hl,wPlayerBattleStatus2
bit NeedsToRecharge,[hl]
jr z,.AnyMoveDisabledCheck
res NeedsToRecharge,[hl] ; reset player's recharge status
@@ -3441,27 +3452,27 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
jp .returnToHL
.AnyMoveDisabledCheck
- ld hl,W_PLAYERDISABLEDMOVE
+ ld hl,wPlayerDisabledMove
ld a,[hl]
and a
jr z,.ConfusedCheck
dec a
ld [hl],a
- and a,$F ; did Disable counter hit 0?
+ and $f ; did Disable counter hit 0?
jr nz,.ConfusedCheck
ld [hl],a
- ld [wccee],a
+ ld [wPlayerDisabledMoveNumber],a
ld hl,DisabledNoMoreText
call PrintText
.ConfusedCheck
- ld a,[W_PLAYERBATTSTATUS1]
+ ld a,[wPlayerBattleStatus1]
add a ; is player confused?
jr nc,.TriedToUseDisabledMoveCheck
- ld hl,W_PLAYERCONFUSEDCOUNTER
+ ld hl,wPlayerConfusedCounter
dec [hl]
jr nz,.IsConfused
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
res Confused,[hl] ; if confused counter hit 0, reset confusion status
ld hl,ConfusedNoMoreText
call PrintText
@@ -3476,15 +3487,16 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
call BattleRandom
cp a,$80 ; 50% chance to hurt itself
jr c,.TriedToUseDisabledMoveCheck
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
ld a,[hl]
- and a, 1 << Confused ; if mon hurts itself, clear every other status from W_PLAYERBATTSTATUS1
+ and a, 1 << Confused ; if mon hurts itself, clear every other status from wPlayerBattleStatus1
ld [hl],a
call HandleSelfConfusionDamage
jr .MonHurtItselfOrFullyParalysed
.TriedToUseDisabledMoveCheck
- ld a,[wccee]
+; prevents a disabled move that was selected before being disabled from being used
+ ld a,[wPlayerDisabledMoveNumber]
and a
jr z,.ParalysisCheck
ld hl,wPlayerSelectedMove
@@ -3505,12 +3517,12 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
call PrintText
.MonHurtItselfOrFullyParalysed
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
ld a,[hl]
- ; clear bide, thrashing, charging up, and trapping moves such as warp (already cleared for confusion damage)
- and a, (1 << AttackingMultipleTimes) | (1 << Flinched) | (1 << Invulnerable) | (1 << Confused)
+ ; clear bide, thrashing, charging up, and trapping moves such as warp (already cleared for confusion damage)
+ and $ff ^ ((1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << ChargingUp) | (1 << UsingTrappingMove))
ld [hl],a
- ld a,[W_PLAYERMOVEEFFECT]
+ ld a,[wPlayerMoveEffect]
cp a,FLY_EFFECT
jr z,.FlyOrChargeEffect
cp a,CHARGE_EFFECT
@@ -3527,12 +3539,12 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
jp .returnToHL ; if using a two-turn move, we need to recharge the first turn
.BideCheck
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
bit StoringEnergy,[hl] ; is mon using bide?
jr z,.ThrashingAboutCheck
xor a
- ld [W_PLAYERMOVENUM],a
- ld hl,W_DAMAGE
+ ld [wPlayerMoveNum],a
+ ld hl,wDamage
ld a,[hli]
ld b,a
ld c,[hl]
@@ -3549,30 +3561,30 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
ld hl,ExecutePlayerMoveDone
jp .returnToHL ; unless mon unleashes energy, can't move this turn
.UnleashEnergy
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
res StoringEnergy,[hl] ; not using bide any more
ld hl,UnleashedEnergyText
call PrintText
ld a,1
- ld [W_PLAYERMOVEPOWER],a
+ ld [wPlayerMovePower],a
ld hl,wPlayerBideAccumulatedDamage + 1
ld a,[hld]
add a
ld b,a
- ld [W_DAMAGE + 1],a
+ ld [wDamage + 1],a
ld a,[hl]
rl a ; double the damage
- ld [W_DAMAGE],a
+ ld [wDamage],a
or b
jr nz,.next
ld a,1
- ld [W_MOVEMISSED],a
+ ld [wMoveMissed],a
.next
xor a
ld [hli],a
ld [hl],a
ld a,BIDE
- ld [W_PLAYERMOVENUM],a
+ ld [wPlayerMoveNum],a
ld hl,handleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
jp .returnToHL
@@ -3580,22 +3592,22 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
bit ThrashingAbout,[hl] ; is mon using thrash or petal dance?
jr z,.MultiturnMoveCheck
ld a,THRASH
- ld [W_PLAYERMOVENUM],a
+ ld [wPlayerMoveNum],a
ld hl,ThrashingAboutText
call PrintText
ld hl,wPlayerNumAttacksLeft
- dec [hl] ; did Trashing About counter hit 0?
+ dec [hl] ; did Thrashing About counter hit 0?
ld hl,PlayerCalcMoveDamage ; skip DecrementPP
- jp nz,.returnToHL
+ jp nz,.returnToHL
push hl
- ld hl,W_PLAYERBATTSTATUS1
- res ThrashingAbout,[hl] ; no longer trashing about
+ ld hl,wPlayerBattleStatus1
+ res ThrashingAbout,[hl] ; no longer thrashing about
set Confused,[hl] ; confused
call BattleRandom
and a,3
inc a
inc a ; confused for 2-5 turns
- ld [W_PLAYERCONFUSEDCOUNTER],a
+ ld [wPlayerConfusedCounter],a
pop hl ; skip DecrementPP
jp .returnToHL
@@ -3607,13 +3619,13 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
ld a,[wPlayerNumAttacksLeft]
dec a ; did multi-turn move end?
ld [wPlayerNumAttacksLeft],a
- ld hl,getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit),
+ ld hl,getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit),
; DecrementPP and MoveHitTest
jp nz,.returnToHL
jp .returnToHL
.RageCheck
- ld a, [W_PLAYERBATTSTATUS2]
+ ld a, [wPlayerBattleStatus2]
bit UsingRage, a ; is mon using rage?
jp z, .checkPlayerStatusConditionsDone ; if we made it this far, mon can move normally this turn
ld a, RAGE
@@ -3621,7 +3633,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
call GetMoveName
call CopyStringToCF4B
xor a
- ld [W_PLAYERMOVEEFFECT], a
+ ld [wPlayerMoveEffect], a
ld hl, PlayerCanExecuteMove
jp .returnToHL
@@ -3634,77 +3646,77 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
and a
ret
-FastAsleepText: ; 3da3d (f:5a3d)
+FastAsleepText:
TX_FAR _FastAsleepText
db "@"
-WokeUpText: ; 3da42 (f:5a42)
+WokeUpText:
TX_FAR _WokeUpText
db "@"
-IsFrozenText: ; 3da47 (f:5a47)
+IsFrozenText:
TX_FAR _IsFrozenText
db "@"
-FullyParalyzedText: ; 3da4c (f:5a4c)
+FullyParalyzedText:
TX_FAR _FullyParalyzedText
db "@"
-FlinchedText: ; 3da51 (f:5a51)
+FlinchedText:
TX_FAR _FlinchedText
db "@"
-MustRechargeText: ; 3da56 (f:5a56)
+MustRechargeText:
TX_FAR _MustRechargeText
db "@"
-DisabledNoMoreText: ; 3da5b (f:5a5b)
+DisabledNoMoreText:
TX_FAR _DisabledNoMoreText
db "@"
-IsConfusedText: ; 3da60 (f:5a60)
+IsConfusedText:
TX_FAR _IsConfusedText
db "@"
-HurtItselfText: ; 3da65 (f:5a65)
+HurtItselfText:
TX_FAR _HurtItselfText
db "@"
-ConfusedNoMoreText: ; 3da6a (f:5a6a)
+ConfusedNoMoreText:
TX_FAR _ConfusedNoMoreText
db "@"
-SavingEnergyText: ; 3da6f (f:5a6f)
+SavingEnergyText:
TX_FAR _SavingEnergyText
db "@"
-UnleashedEnergyText: ; 3da74 (f:5a74)
+UnleashedEnergyText:
TX_FAR _UnleashedEnergyText
db "@"
-ThrashingAboutText: ; 3da79 (f:5a79)
+ThrashingAboutText:
TX_FAR _ThrashingAboutText
db "@"
-AttackContinuesText: ; 3da7e (f:5a7e)
+AttackContinuesText:
TX_FAR _AttackContinuesText
db "@"
-CantMoveText: ; 3da83 (f:5a83)
+CantMoveText:
TX_FAR _CantMoveText
db "@"
-PrintMoveIsDisabledText: ; 3da88 (f:5a88)
+PrintMoveIsDisabledText:
ld hl, wPlayerSelectedMove
- ld de, W_PLAYERBATTSTATUS1
+ ld de, wPlayerBattleStatus1
ld a, [H_WHOSETURN]
and a
jr z, .removeChargingUp
inc hl
- ld de, W_ENEMYBATTSTATUS1
+ ld de, wEnemyBattleStatus1
.removeChargingUp
ld a, [de]
- res ChargingUp, a ; end the pokemon's
+ res ChargingUp, a ; end the pokemon's
ld [de], a
ld a, [hl]
ld [wd11e], a
@@ -3712,11 +3724,11 @@ PrintMoveIsDisabledText: ; 3da88 (f:5a88)
ld hl, MoveIsDisabledText
jp PrintText
-MoveIsDisabledText: ; 3daa8 (f:5aa8)
+MoveIsDisabledText:
TX_FAR _MoveIsDisabledText
db "@"
-HandleSelfConfusionDamage: ; 3daad (f:5aad)
+HandleSelfConfusionDamage:
ld hl, HurtItselfText
call PrintText
ld hl, wEnemyMonDefense
@@ -3728,7 +3740,7 @@ HandleSelfConfusionDamage: ; 3daad (f:5aad)
ld [hli], a
ld a, [wBattleMonDefense + 1]
ld [hl], a
- ld hl, W_PLAYERMOVEEFFECT
+ ld hl, wPlayerMoveEffect
push hl
ld a, [hl]
push af
@@ -3760,24 +3772,29 @@ HandleSelfConfusionDamage: ; 3daad (f:5aad)
ld [H_WHOSETURN], a
jp ApplyDamageToPlayerPokemon
-PrintMonName1Text: ; 3daf5 (f:5af5)
+PrintMonName1Text:
ld hl, MonName1Text
jp PrintText
-MonName1Text: ; 3dafb (f:5afb)
+; this function wastes time calling DetermineExclamationPointTextNum
+; and choosing between Used1Text and Used2Text, even though
+; those text strings are identical and both continue at PrintInsteadText
+; this likely had to do with Japanese grammar that got translated,
+; but the functionality didn't get removed
+MonName1Text:
TX_FAR _MonName1Text
- db $08 ; asm
+ TX_ASM
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVENUM]
+ ld a, [wPlayerMoveNum]
ld hl, wPlayerUsedMove
- jr z, .asm_3db11
- ld a, [W_ENEMYMOVENUM]
+ jr z, .playerTurn
+ ld a, [wEnemyMoveNum]
ld hl, wEnemyUsedMove
-.asm_3db11
+.playerTurn
ld [hl], a
ld [wd11e], a
- call Func_3db85
+ call DetermineExclamationPointTextNum
ld a, [wMonIsDisobedient]
and a
ld hl, Used2Text
@@ -3789,35 +3806,37 @@ MonName1Text: ; 3dafb (f:5afb)
ld hl, Used1Text
ret
-Used1Text: ; 3db2d (f:5b2d)
+Used1Text:
TX_FAR _Used1Text
- db $08 ; asm
+ TX_ASM
jr PrintInsteadText
-Used2Text: ; 3db34 (f:5b34)
+Used2Text:
TX_FAR _Used2Text
- db $08 ; asm
+ TX_ASM
+ ; fall through
-PrintInsteadText: ; 3db39 (f:5b39)
+PrintInsteadText:
ld a, [wMonIsDisobedient]
and a
- jr z, PrintCF4BText
+ jr z, PrintMoveName
ld hl, InsteadText
ret
-InsteadText: ; 3db43 (f:5b43)
+InsteadText:
TX_FAR _InsteadText
- db $08 ; asm
+ TX_ASM
+ ; fall through
-PrintCF4BText: ; 3db48 (f:5b48)
- ld hl, CF4BText
+PrintMoveName:
+ ld hl, _PrintMoveName
ret
-CF4BText: ; 3db4c (f:5b4c)
+_PrintMoveName:
TX_FAR _CF4BText
- db $08 ; asm
+ TX_ASM
ld hl, ExclamationPointPointerTable
- ld a, [wd11e]
+ ld a, [wd11e] ; exclamation point num
add a
push bc
ld b, $0
@@ -3829,56 +3848,63 @@ CF4BText: ; 3db4c (f:5b4c)
ld l, a
ret
-ExclamationPointPointerTable: ; 3db62 (f:5b62)
+ExclamationPointPointerTable:
dw ExclamationPoint1Text
dw ExclamationPoint2Text
dw ExclamationPoint3Text
dw ExclamationPoint4Text
dw ExclamationPoint5Text
-ExclamationPoint1Text: ; 3db6c (f:5b6c)
+ExclamationPoint1Text:
TX_FAR _ExclamationPoint1Text
db "@"
-ExclamationPoint2Text: ; 3db71 (f:5b71)
+ExclamationPoint2Text:
TX_FAR _ExclamationPoint2Text
db "@"
-ExclamationPoint3Text: ; 3db76 (f:5b76)
+ExclamationPoint3Text:
TX_FAR _ExclamationPoint3Text
db "@"
-ExclamationPoint4Text: ; 3db7b (f:5b7b)
+ExclamationPoint4Text:
TX_FAR _ExclamationPoint4Text
db "@"
-ExclamationPoint5Text: ; 3db80 (f:5b80)
+ExclamationPoint5Text:
TX_FAR _ExclamationPoint5Text
db "@"
-Func_3db85: ; 3db85 (f:5b85)
+; this function does nothing useful
+; if the move being used is in set [1-4] from ExclamationPointMoveSets,
+; use ExclamationPoint[1-4]Text
+; otherwise, use ExclamationPoint5Text
+; but all five text strings are identical
+; this likely had to do with Japanese grammar that got translated,
+; but the functionality didn't get removed
+DetermineExclamationPointTextNum:
push bc
- ld a, [wd11e] ; move number
+ ld a, [wd11e] ; move ID
ld c, a
ld b, $0
- ld hl, UnknownMovesList_3dba3
-.asm_3db8f
+ ld hl, ExclamationPointMoveSets
+.loop
ld a, [hli]
cp $ff
- jr z, .asm_3db9d
+ jr z, .done
cp c
- jr z, .asm_3db9d
+ jr z, .done
and a
- jr nz, .asm_3db8f
+ jr nz, .loop
inc b
- jr .asm_3db8f
-.asm_3db9d
+ jr .loop
+.done
ld a, b
- ld [wd11e], a
+ ld [wd11e], a ; exclamation point num
pop bc
ret
-UnknownMovesList_3dba3: ; 3dba3 (f:5ba3)
+ExclamationPointMoveSets:
db SWORDS_DANCE, GROWTH
db $00
db RECOVER, BIDE, SELFDESTRUCT, AMNESIA
@@ -3893,12 +3919,12 @@ UnknownMovesList_3dba3: ; 3dba3 (f:5ba3)
db $00
db $FF ; terminator
-PrintMoveFailureText: ; 3dbe2 (f:5be2)
- ld de, W_PLAYERMOVEEFFECT
+PrintMoveFailureText:
+ ld de, wPlayerMoveEffect
ld a, [H_WHOSETURN]
and a
jr z, .playersTurn
- ld de, W_ENEMYMOVEEFFECT
+ ld de, wEnemyMoveEffect
.playersTurn
ld hl, DoesntAffectMonText
ld a, [wDamageMultipliers]
@@ -3920,8 +3946,8 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2)
ret nz
; if you get here, the mon used jump kick or hi jump kick and missed
- ld hl, W_DAMAGE ; since the move missed, W_DAMAGE will always contain 0 at this point.
- ; Thus, recoil damage will always be equal to 1
+ ld hl, wDamage ; since the move missed, wDamage will always contain 0 at this point.
+ ; Thus, recoil damage will always be equal to 1
; even if it was intended to be potential damage/8.
ld a, [hli]
ld b, [hl]
@@ -3942,7 +3968,7 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2)
ld hl, KeptGoingAndCrashedText
call PrintText
ld b, $4
- predef Func_48125
+ predef PredefShakeScreenHorizontally
ld a, [H_WHOSETURN]
and a
jr nz, .enemyTurn
@@ -3950,28 +3976,28 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2)
.enemyTurn
jp ApplyDamageToEnemyPokemon
-AttackMissedText: ; 3dc42 (f:5c42)
+AttackMissedText:
TX_FAR _AttackMissedText
db "@"
-KeptGoingAndCrashedText: ; 3dc47 (f:5c47)
+KeptGoingAndCrashedText:
TX_FAR _KeptGoingAndCrashedText
db "@"
-UnaffectedText: ; 3dc4c (f:5c4c)
+UnaffectedText:
TX_FAR _UnaffectedText
db "@"
-PrintDoesntAffectText: ; 3dc51 (f:5c51)
+PrintDoesntAffectText:
ld hl, DoesntAffectMonText
jp PrintText
-DoesntAffectMonText: ; 3dc57 (f:5c57)
+DoesntAffectMonText:
TX_FAR _DoesntAffectMonText
db "@"
; if there was a critical hit or an OHKO was successful, print the corresponding text
-PrintCriticalOHKOText: ; 3dc5c (f:5c5c)
+PrintCriticalOHKOText:
ld a, [wCriticalHitOrOHKO]
and a
jr z, .done ; do nothing if there was no critical hit or successful OHKO
@@ -3988,24 +4014,24 @@ PrintCriticalOHKOText: ; 3dc5c (f:5c5c)
xor a
ld [wCriticalHitOrOHKO], a
.done
- ld c, $14
+ ld c, 20
jp DelayFrames
-CriticalOHKOTextPointers: ; 3dc7a (f:5c7a)
+CriticalOHKOTextPointers:
dw CriticalHitText
dw OHKOText
-CriticalHitText: ; 3dc7e (f:5c7e)
+CriticalHitText:
TX_FAR _CriticalHitText
db "@"
-OHKOText: ; 3dc83 (f:5c83)
+OHKOText:
TX_FAR _OHKOText
db "@"
; checks if a traded mon will disobey due to lack of badges
; stores whether the mon will use a move in Z flag
-CheckForDisobedience: ; 3dc88 (f:5c88)
+CheckForDisobedience:
xor a
ld [wMonIsDisobedient], a
ld a, [wLinkState]
@@ -4030,7 +4056,7 @@ CheckForDisobedience: ; 3dc88 (f:5c88)
; it was traded
.monIsTraded
; what level might disobey?
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
bit 7, [hl]
ld a, 101
jr nz, .next
@@ -4112,7 +4138,7 @@ CheckForDisobedience: ; 3dc88 (f:5c88)
ld a, [wBattleMonMoves + 1]
and a ; is the second move slot empty?
jr z, .monDoesNothing ; mon will not use move if it only knows one move
- ld a, [wccee]
+ ld a, [wPlayerDisabledMoveNumber]
and a
jr nz, .monDoesNothing
ld a, [wPlayerSelectedMove]
@@ -4184,38 +4210,38 @@ CheckForDisobedience: ; 3dc88 (f:5c88)
xor a ; set Z flag
ret
-LoafingAroundText: ; 3ddb6 (f:5db6)
+LoafingAroundText:
TX_FAR _LoafingAroundText
db "@"
-BeganToNapText: ; 3ddbb (f:5dbb)
+BeganToNapText:
TX_FAR _BeganToNapText
db "@"
-WontObeyText: ; 3ddc0 (f:5dc0)
+WontObeyText:
TX_FAR _WontObeyText
db "@"
-TurnedAwayText: ; 3ddc5 (f:5dc5)
+TurnedAwayText:
TX_FAR _TurnedAwayText
db "@"
-IgnoredOrdersText: ; 3ddca (f:5dca)
+IgnoredOrdersText:
TX_FAR _IgnoredOrdersText
db "@"
; sets b, c, d, and e for the CalculateDamage routine in the case of an attack by the player mon
-GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf)
+GetDamageVarsForPlayerAttack:
xor a
- ld hl, W_DAMAGE ; damage to eventually inflict, initialise to zero
+ ld hl, wDamage ; damage to eventually inflict, initialise to zero
ldi [hl], a
ld [hl], a
- ld hl, W_PLAYERMOVEPOWER
+ ld hl, wPlayerMovePower
ld a, [hli]
and a
ld d, a ; d = move power
ret z ; return if move power is zero
- ld a, [hl] ; a = [W_PLAYERMOVETYPE]
+ ld a, [hl] ; a = [wPlayerMoveType]
cp FIRE ; types >= FIRE are all special
jr nc, .specialAttack
.physicalAttack
@@ -4223,7 +4249,7 @@ GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf)
ld a, [hli]
ld b, a
ld c, [hl] ; bc = enemy defense
- ld a, [W_ENEMYBATTSTATUS3]
+ ld a, [wEnemyBattleStatus3]
bit HasReflectUp, a ; check for Reflect
jr z, .physicalAttackCritCheck
; if the enemy has used Reflect, double the enemy's defense
@@ -4253,7 +4279,7 @@ GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf)
ld a, [hli]
ld b, a
ld c, [hl] ; bc = enemy special
- ld a, [W_ENEMYBATTSTATUS3]
+ ld a, [wEnemyBattleStatus3]
bit HasLightScreenUp, a ; check for Light Screen
jr z, .specialAttackCritCheck
; if the enemy has used Light Screen, double the enemy's special
@@ -4318,17 +4344,17 @@ GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf)
ret
; sets b, c, d, and e for the CalculateDamage routine in the case of an attack by the enemy mon
-GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75)
- ld hl, W_DAMAGE ; damage to eventually inflict, initialise to zero
+GetDamageVarsForEnemyAttack:
+ ld hl, wDamage ; damage to eventually inflict, initialise to zero
xor a
ld [hli], a
ld [hl], a
- ld hl, W_ENEMYMOVEPOWER
+ ld hl, wEnemyMovePower
ld a, [hli]
ld d, a ; d = move power
and a
ret z ; return if move power is zero
- ld a, [hl] ; a = [W_ENEMYMOVETYPE]
+ ld a, [hl] ; a = [wEnemyMoveType]
cp FIRE ; types >= FIRE are all special
jr nc, .specialAttack
.physicalAttack
@@ -4336,7 +4362,7 @@ GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75)
ld a, [hli]
ld b, a
ld c, [hl] ; bc = player defense
- ld a, [W_PLAYERBATTSTATUS3]
+ ld a, [wPlayerBattleStatus3]
bit HasReflectUp, a ; check for Reflect
jr z, .physicalAttackCritCheck
; if the player has used Reflect, double the player's defense
@@ -4366,7 +4392,7 @@ GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75)
ld a, [hli]
ld b, a
ld c, [hl]
- ld a, [W_PLAYERBATTSTATUS3]
+ ld a, [wPlayerBattleStatus3]
bit HasLightScreenUp, a ; check for Light Screen
jr z, .specialAttackCritCheck
; if the player has used Light Screen, double the player's special
@@ -4433,7 +4459,7 @@ GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75)
; get stat c of enemy mon
; c: stat to get (HP=1,Attack=2,Defense=3,Speed=4,Special=5)
-GetEnemyMonStat: ; 3df1c (f:5f1c)
+GetEnemyMonStat:
push de
push bc
ld a, [wLinkState]
@@ -4456,7 +4482,7 @@ GetEnemyMonStat: ; 3df1c (f:5f1c)
ret
.notLinkBattle
ld a, [wEnemyMonLevel]
- ld [W_CURENEMYLVL], a
+ ld [wCurEnemyLVL], a
ld a, [wEnemyMonSpecies]
ld [wd0b5], a
call GetMonHeader
@@ -4474,18 +4500,18 @@ GetEnemyMonStat: ; 3df1c (f:5f1c)
pop de
ret
-CalculateDamage: ; 3df65 (f:5f65)
+CalculateDamage:
; input:
-; b: attack
-; c: opponent defense
-; d: base power
-; e: level
+; b: attack
+; c: opponent defense
+; d: base power
+; e: level
ld a, [H_WHOSETURN] ; whose turn?
and a
- ld a, [W_PLAYERMOVEEFFECT]
+ ld a, [wPlayerMoveEffect]
jr z, .effect
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
.effect
; EXPLODE_EFFECT halves defense.
@@ -4562,7 +4588,7 @@ CalculateDamage: ; 3df65 (f:5f65)
ld b, 4
call Divide
- ld hl, W_DAMAGE
+ ld hl, wDamage
ld b, [hl]
ld a, [H_QUOTIENT + 3]
add b
@@ -4636,46 +4662,45 @@ CalculateDamage: ; 3df65 (f:5f65)
and a
ret
-JumpToOHKOMoveEffect: ; 3e016 (f:6016)
+JumpToOHKOMoveEffect:
call JumpMoveEffect
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
dec a
ret
-UnusedHighCriticalMoves: ; 3e01e (f:601e)
+UnusedHighCriticalMoves:
db KARATE_CHOP
db RAZOR_LEAF
db CRABHAMMER
db SLASH
db $FF
-; 3e023
; determines if attack is a critical hit
; azure heights claims "the fastest pokémon (who are,not coincidentally,
; among the most popular) tend to CH about 20 to 25% of the time."
-CriticalHitTest: ; 3e023 (f:6023)
+CriticalHitTest:
xor a
ld [wCriticalHitOrOHKO], a
ld a, [H_WHOSETURN]
and a
ld a, [wEnemyMonSpecies]
- jr nz, .asm_3e032
+ jr nz, .handleEnemy
ld a, [wBattleMonSpecies]
-.asm_3e032
+.handleEnemy
ld [wd0b5], a
call GetMonHeader
- ld a, [W_MONHBASESPEED]
+ ld a, [wMonHBaseSpeed]
ld b, a
srl b ; (effective (base speed/2))
ld a, [H_WHOSETURN]
and a
- ld hl, W_PLAYERMOVEPOWER
- ld de, W_PLAYERBATTSTATUS2
+ ld hl, wPlayerMovePower
+ ld de, wPlayerBattleStatus2
jr z, .calcCriticalHitProbability
- ld hl, W_ENEMYMOVEPOWER
- ld de, W_ENEMYBATTSTATUS2
-.calcCriticalHitProbability ; 0x3e04f
+ ld hl, wEnemyMovePower
+ ld de, wEnemyBattleStatus2
+.calcCriticalHitProbability
ld a, [hld] ; read base power from RAM
and a
ret z ; do nothing if zero
@@ -4721,7 +4746,7 @@ CriticalHitTest: ; 3e023 (f:6023)
ret
; high critical hit moves
-HighCriticalMoves: ; 3e08e (f:608e)
+HighCriticalMoves:
db KARATE_CHOP
db RAZOR_LEAF
db CRABHAMMER
@@ -4730,7 +4755,7 @@ HighCriticalMoves: ; 3e08e (f:608e)
; function to determine if Counter hits and if so, how much damage it does
-HandleCounterMove: ; 3e093 (f:6093)
+HandleCounterMove:
; The variables checked by Counter are updated whenever the cursor points to a new move in the battle selection menu.
; This is irrelevant for the opponent's side outside of link battles, since the move selection is controlled by the AI.
; However, in the scenario where the player switches out and the opponent uses Counter,
@@ -4741,18 +4766,18 @@ HandleCounterMove: ; 3e093 (f:6093)
and a
; player's turn
ld hl,wEnemySelectedMove
- ld de,W_ENEMYMOVEPOWER
+ ld de,wEnemyMovePower
ld a,[wPlayerSelectedMove]
jr z,.next
; enemy's turn
ld hl,wPlayerSelectedMove
- ld de,W_PLAYERMOVEPOWER
+ ld de,wPlayerMovePower
ld a,[wEnemySelectedMove]
.next
cp a,COUNTER
ret nz ; return if not using Counter
ld a,$01
- ld [W_MOVEMISSED],a ; initialize the move missed variable to true (it is set to false below if the move hits)
+ ld [wMoveMissed],a ; initialize the move missed variable to true (it is set to false below if the move hits)
ld a,[hl]
cp a,COUNTER
ret z ; miss if the opponent's last selected move is Counter.
@@ -4770,11 +4795,11 @@ HandleCounterMove: ; 3e093 (f:6093)
xor a
ret
.counterableType
- ld hl,W_DAMAGE
+ ld hl,wDamage
ld a,[hli]
or [hl]
ret z ; If we made it here, Counter still misses if the last move used in battle did no damage to its target.
- ; W_DAMAGE is shared by both players, so Counter may strike back damage dealt by the Counter user itself
+ ; wDamage is shared by both players, so Counter may strike back damage dealt by the Counter user itself
; if the conditions meet, even though 99% of the times damage will come from the target.
; if it did damage, double it
ld a,[hl]
@@ -4790,27 +4815,27 @@ HandleCounterMove: ; 3e093 (f:6093)
ld [hl],a
.noCarry
xor a
- ld [W_MOVEMISSED],a
+ ld [wMoveMissed],a
call MoveHitTest ; do the normal move hit test in addition to Counter's special rules
xor a
ret
-ApplyAttackToEnemyPokemon: ; 3e0df (f:60df)
- ld a,[W_PLAYERMOVEEFFECT]
+ApplyAttackToEnemyPokemon:
+ ld a,[wPlayerMoveEffect]
cp a,OHKO_EFFECT
jr z,ApplyDamageToEnemyPokemon
cp a,SUPER_FANG_EFFECT
jr z,.superFangEffect
cp a,SPECIAL_DAMAGE_EFFECT
jr z,.specialDamage
- ld a,[W_PLAYERMOVEPOWER]
+ ld a,[wPlayerMovePower]
and a
jp z,ApplyAttackToEnemyPokemonDone ; no attack to apply if base power is 0
jr ApplyDamageToEnemyPokemon
.superFangEffect
; set the damage to half the target's HP
ld hl,wEnemyMonHP
- ld de,W_DAMAGE
+ ld de,wDamage
ld a,[hli]
srl a
ld [de],a
@@ -4829,7 +4854,7 @@ ApplyAttackToEnemyPokemon: ; 3e0df (f:60df)
ld hl,wBattleMonLevel
ld a,[hl]
ld b,a ; Seismic Toss deals damage equal to the user's level
- ld a,[W_PLAYERMOVENUM]
+ ld a,[wPlayerMoveNum]
cp a,SEISMIC_TOSS
jr z,.storeDamage
cp a,NIGHT_SHADE
@@ -4855,20 +4880,20 @@ ApplyAttackToEnemyPokemon: ; 3e0df (f:60df)
jr nc,.loop
ld b,a
.storeDamage ; store damage value at b
- ld hl,W_DAMAGE
+ ld hl,wDamage
xor a
ld [hli],a
ld a,b
ld [hl],a
-ApplyDamageToEnemyPokemon: ; 3e142 (f:6142)
- ld hl,W_DAMAGE
+ApplyDamageToEnemyPokemon:
+ ld hl,wDamage
ld a,[hli]
ld b,a
ld a,[hl]
or b
jr z,ApplyAttackToEnemyPokemonDone ; we're done if damage is 0
- ld a,[W_ENEMYBATTSTATUS2]
+ ld a,[wEnemyBattleStatus2]
bit HasSubstituteUp,a ; does the enemy have a substitute?
jp nz,AttackSubstitute
; subtract the damage from the pokemon's current HP
@@ -4886,7 +4911,7 @@ ApplyDamageToEnemyPokemon: ; 3e142 (f:6142)
sbc b
ld [wEnemyMonHP],a
jr nc,.animateHpBar
-; if more damage was done than the current HP, zero the HP and set the damage (W_DAMAGE)
+; if more damage was done than the current HP, zero the HP and set the damage (wDamage)
; equal to how much HP the pokemon had before the attack
ld a,[wHPBarOldHP+1]
ld [hli],a
@@ -4907,29 +4932,29 @@ ApplyDamageToEnemyPokemon: ; 3e142 (f:6142)
ld [wHPBarNewHP+1],a
ld a,[hl]
ld [wHPBarNewHP],a
- hlCoord 2, 2
+ coord hl, 2, 2
xor a
ld [wHPBarType],a
predef UpdateHPBar2 ; animate the HP bar shortening
-ApplyAttackToEnemyPokemonDone: ; 3e19d (f:619d)
+ApplyAttackToEnemyPokemonDone:
jp DrawHUDsAndHPBars
-ApplyAttackToPlayerPokemon: ; 3e1a0 (f:61a0)
- ld a,[W_ENEMYMOVEEFFECT]
+ApplyAttackToPlayerPokemon:
+ ld a,[wEnemyMoveEffect]
cp a,OHKO_EFFECT
jr z,ApplyDamageToPlayerPokemon
cp a,SUPER_FANG_EFFECT
jr z,.superFangEffect
cp a,SPECIAL_DAMAGE_EFFECT
jr z,.specialDamage
- ld a,[W_ENEMYMOVEPOWER]
+ ld a,[wEnemyMovePower]
and a
jp z,ApplyAttackToPlayerPokemonDone
jr ApplyDamageToPlayerPokemon
.superFangEffect
; set the damage to half the target's HP
ld hl,wBattleMonHP
- ld de,W_DAMAGE
+ ld de,wDamage
ld a,[hli]
srl a
ld [de],a
@@ -4948,7 +4973,7 @@ ApplyAttackToPlayerPokemon: ; 3e1a0 (f:61a0)
ld hl,wEnemyMonLevel
ld a,[hl]
ld b,a
- ld a,[W_ENEMYMOVENUM]
+ ld a,[wEnemyMoveNum]
cp a,SEISMIC_TOSS
jr z,.storeDamage
cp a,NIGHT_SHADE
@@ -4974,20 +4999,20 @@ ApplyAttackToPlayerPokemon: ; 3e1a0 (f:61a0)
jr nc,.loop
ld b,a
.storeDamage
- ld hl,W_DAMAGE
+ ld hl,wDamage
xor a
ld [hli],a
ld a,b
ld [hl],a
-ApplyDamageToPlayerPokemon: ; 3e200 (f:6200)
- ld hl,W_DAMAGE
+ApplyDamageToPlayerPokemon:
+ ld hl,wDamage
ld a,[hli]
ld b,a
ld a,[hl]
or b
jr z,ApplyAttackToPlayerPokemonDone ; we're done if damage is 0
- ld a,[W_PLAYERBATTSTATUS2]
+ ld a,[wPlayerBattleStatus2]
bit HasSubstituteUp,a ; does the player have a substitute?
jp nz,AttackSubstitute
; subtract the damage from the pokemon's current HP
@@ -5006,7 +5031,7 @@ ApplyDamageToPlayerPokemon: ; 3e200 (f:6200)
ld [wBattleMonHP],a
ld [wHPBarNewHP+1],a
jr nc,.animateHpBar
-; if more damage was done than the current HP, zero the HP and set the damage (W_DAMAGE)
+; if more damage was done than the current HP, zero the HP and set the damage (wDamage)
; equal to how much HP the pokemon had before the attack
ld a,[wHPBarOldHP+1]
ld [hli],a
@@ -5025,34 +5050,34 @@ ApplyDamageToPlayerPokemon: ; 3e200 (f:6200)
ld [wHPBarMaxHP+1],a
ld a,[hl]
ld [wHPBarMaxHP],a
- hlCoord 10, 9
+ coord hl, 10, 9
ld a,$01
ld [wHPBarType],a
predef UpdateHPBar2 ; animate the HP bar shortening
-ApplyAttackToPlayerPokemonDone
+ApplyAttackToPlayerPokemonDone:
jp DrawHUDsAndHPBars
-AttackSubstitute: ; 3e25e (f:625e)
+AttackSubstitute:
; Unlike the two ApplyAttackToPokemon functions, Attack Substitute is shared by player and enemy.
; Self-confusion damage as well as Hi-Jump Kick and Jump Kick recoil cause a momentary turn swap before being applied.
-; If the user has a Substitute up and would take damage because of that,
+; If the user has a Substitute up and would take damage because of that,
; damage will be applied to the other player's Substitute.
-; Normal recoil such as from Double-Edge isn't affected by this glitch,
+; Normal recoil such as from Double-Edge isn't affected by this glitch,
; because this function is never called in that case.
ld hl,SubstituteTookDamageText
call PrintText
; values for player turn
ld de,wEnemySubstituteHP
- ld bc,W_ENEMYBATTSTATUS2
+ ld bc,wEnemyBattleStatus2
ld a,[H_WHOSETURN]
and a
jr z,.applyDamageToSubstitute
; values for enemy turn
ld de,wPlayerSubstituteHP
- ld bc,W_PLAYERBATTSTATUS2
+ ld bc,wPlayerBattleStatus2
.applyDamageToSubstitute
- ld hl,W_DAMAGE
+ ld hl,wDamage
ld a,[hli]
and a
jr nz,.substituteBroke ; damage > 0xFF always breaks substitutes
@@ -5062,7 +5087,7 @@ AttackSubstitute: ; 3e25e (f:625e)
ld [de],a
ret nc
.substituteBroke
-; If the target's Substitute breaks, W_DAMAGE isn't updated with the amount of HP
+; If the target's Substitute breaks, wDamage isn't updated with the amount of HP
; the Substitute had before being attacked.
ld h,b
ld l,c
@@ -5073,41 +5098,41 @@ AttackSubstitute: ; 3e25e (f:625e)
ld a,[H_WHOSETURN]
xor a,$01
ld [H_WHOSETURN],a
- callab Func_79747 ; animate the substitute breaking
+ callab HideSubstituteShowMonAnim ; animate the substitute breaking
; flip the turn back to the way it was
ld a,[H_WHOSETURN]
xor a,$01
ld [H_WHOSETURN],a
- ld hl,W_PLAYERMOVEEFFECT ; value for player's turn
+ ld hl,wPlayerMoveEffect ; value for player's turn
and a
jr z,.nullifyEffect
- ld hl,W_ENEMYMOVEEFFECT ; value for enemy's turn
+ ld hl,wEnemyMoveEffect ; value for enemy's turn
.nullifyEffect
xor a
ld [hl],a ; zero the effect of the attacker's move
jp DrawHUDsAndHPBars
-SubstituteTookDamageText: ; 3e2ac (f:62ac)
+SubstituteTookDamageText:
TX_FAR _SubstituteTookDamageText
db "@"
-SubstituteBrokeText: ; 3e2b1 (f:62b1)
+SubstituteBrokeText:
TX_FAR _SubstituteBrokeText
db "@"
; this function raises the attack modifier of a pokemon using Rage when that pokemon is attacked
-HandleBuildingRage: ; 3e2b6 (f:62b6)
+HandleBuildingRage:
; values for the player turn
- ld hl,W_ENEMYBATTSTATUS2
+ ld hl,wEnemyBattleStatus2
ld de,wEnemyMonStatMods
- ld bc,W_ENEMYMOVENUM
+ ld bc,wEnemyMoveNum
ld a,[H_WHOSETURN]
and a
jr z,.next
; values for the enemy turn
- ld hl,W_PLAYERBATTSTATUS2
+ ld hl,wPlayerBattleStatus2
ld de,wPlayerMonStatMods
- ld bc,W_PLAYERMOVENUM
+ ld bc,wPlayerMoveNum
.next
bit UsingRage,[hl] ; is the pokemon being attacked under the effect of Rage?
ret z ; return if not
@@ -5138,13 +5163,13 @@ HandleBuildingRage: ; 3e2b6 (f:62b6)
ld [H_WHOSETURN],a
ret
-BuildingRageText: ; 3e2f8 (f:62f8)
+BuildingRageText:
TX_FAR _BuildingRageText
db "@"
; copy last move for Mirror Move
; sets zero flag on failure and unsets zero flag on success
-MirrorMoveCopyMove: ; 3e2fd (f:62fd)
+MirrorMoveCopyMove:
; Mirror Move makes use of ccf1 (wPlayerUsedMove) and ccf2 (wEnemyUsedMove) addresses,
; which are mainly used to print the "[Pokemon] used [Move]" text.
; Both are set to 0 whenever a new Pokemon is sent out
@@ -5156,11 +5181,11 @@ MirrorMoveCopyMove: ; 3e2fd (f:62fd)
; values for player turn
ld a,[wEnemyUsedMove]
ld hl,wPlayerSelectedMove
- ld de,W_PLAYERMOVENUM
+ ld de,wPlayerMoveNum
jr z,.next
; values for enemy turn
ld a,[wPlayerUsedMove]
- ld de,W_ENEMYMOVENUM
+ ld de,wEnemyMoveNum
ld hl,wEnemySelectedMove
.next
ld [hl],a
@@ -5174,16 +5199,16 @@ MirrorMoveCopyMove: ; 3e2fd (f:62fd)
xor a
ret
-MirrorMoveFailedText: ; 3e324 (f:6324)
+MirrorMoveFailedText:
TX_FAR _MirrorMoveFailedText
db "@"
; function used to reload move data for moves like Mirror Move and Metronome
-ReloadMoveData: ; 3e329 (f:6329)
+ReloadMoveData:
ld [wd11e],a
dec a
ld hl,Moves
- ld bc,$0006
+ ld bc,MoveEnd - Moves
call AddNTimes
ld a,BANK(Moves)
call FarCopyData ; copy the move's stats
@@ -5196,19 +5221,19 @@ ReloadMoveData: ; 3e329 (f:6329)
ret
; function that picks a random move for metronome
-MetronomePickMove: ; 3e348 (f:6348)
+MetronomePickMove:
xor a
ld [wAnimationType],a
ld a,METRONOME
call PlayMoveAnimation ; play Metronome's animation
; values for player turn
- ld de,W_PLAYERMOVENUM
+ ld de,wPlayerMoveNum
ld hl,wPlayerSelectedMove
ld a,[H_WHOSETURN]
and a
jr z,.pickMoveLoop
; values for enemy turn
- ld de,W_ENEMYMOVENUM
+ ld de,wEnemyMoveNum
ld hl,wEnemySelectedMove
; loop to pick a random number in the range [1, $a5) to be the move used by Metronome
.pickMoveLoop
@@ -5225,7 +5250,7 @@ MetronomePickMove: ; 3e348 (f:6348)
; this function increments the current move's PP
; it's used to prevent moves that run another move within the same turn
; (like Mirror Move and Metronome) from losing 2 PP
-IncrementMovePP: ; 3e373 (f:6373)
+IncrementMovePP:
ld a,[H_WHOSETURN]
and a
; values for player turn
@@ -5257,7 +5282,7 @@ IncrementMovePP: ; 3e373 (f:6373)
ret
; function to adjust the base damage of an attack to account for type effectiveness
-AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
+AdjustDamageForMoveType:
; values for player turn
ld hl,wBattleMonType
ld a,[hli]
@@ -5267,8 +5292,8 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
ld a,[hli]
ld d,a ; d = type 1 of defender
ld e,[hl] ; e = type 2 of defender
- ld a,[W_PLAYERMOVETYPE]
- ld [wd11e],a
+ ld a,[wPlayerMoveType]
+ ld [wMoveType],a
ld a,[H_WHOSETURN]
and a
jr z,.next
@@ -5281,10 +5306,10 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
ld a,[hli]
ld d,a ; d = type 1 of defender
ld e,[hl] ; e = type 2 of defender
- ld a,[W_ENEMYMOVETYPE]
- ld [wd11e],a
+ ld a,[wEnemyMoveType]
+ ld [wMoveType],a
.next
- ld a,[wd11e] ; move type
+ ld a,[wMoveType]
cp b ; does the move type match type 1 of the attacker?
jr z,.sameTypeAttackBonus
cp c ; does the move type match type 2 of the attacker?
@@ -5292,7 +5317,7 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
jr .skipSameTypeAttackBonus
.sameTypeAttackBonus
; if the move type matches one of the attacker's types
- ld hl,W_DAMAGE + 1
+ ld hl,wDamage + 1
ld a,[hld]
ld h,[hl]
ld l,a ; hl = damage
@@ -5303,14 +5328,14 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
add hl,bc ; hl = floor(1.5 * damage)
; store damage
ld a,h
- ld [W_DAMAGE],a
+ ld [wDamage],a
ld a,l
- ld [W_DAMAGE + 1],a
+ ld [wDamage + 1],a
ld hl,wDamageMultipliers
set 7,[hl]
.skipSameTypeAttackBonus
- ld a,[wd11e]
- ld b,a ; b = move type
+ ld a,[wMoveType]
+ ld b,a
ld hl,TypeEffects
.loop
ld a,[hli] ; a = "attacking type" of the current type pair
@@ -5338,7 +5363,7 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
ld [wDamageMultipliers],a
xor a
ld [H_MULTIPLICAND],a
- ld hl,W_DAMAGE
+ ld hl,wDamage
ld a,[hli]
ld [H_MULTIPLICAND + 1],a
ld a,[hld]
@@ -5359,7 +5384,7 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
; if damage is 0, make the move miss
; this only occurs if a move that would do 2 or 3 damage is 0.25x effective against the target
inc a
- ld [W_MOVEMISSED],a
+ ld [wMoveMissed],a
.skipTypeImmunity
pop bc
pop hl
@@ -5373,29 +5398,29 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5)
; function to tell how effective the type of an enemy attack is on the player's current pokemon
; this doesn't take into account the effects that dual types can have
; (e.g. 4x weakness / resistance, weaknesses and resistances canceling)
-; the result is stored in [wd11e]
+; the result is stored in [wTypeEffectiveness]
; ($05 is not very effective, $10 is neutral, $14 is super effective)
; as far is can tell, this is only used once in some AI code to help decide which move to use
-AIGetTypeEffectiveness: ; 3e449 (f:6449)
- ld a,[W_ENEMYMOVETYPE]
- ld d,a ; d = type of enemy move
+AIGetTypeEffectiveness:
+ ld a,[wEnemyMoveType]
+ ld d,a ; d = type of enemy move
ld hl,wBattleMonType
- ld b,[hl] ; b = type 1 of player's pokemon
+ ld b,[hl] ; b = type 1 of player's pokemon
inc hl
- ld c,[hl] ; c = type 2 of player's pokemon
+ ld c,[hl] ; c = type 2 of player's pokemon
ld a,$10
- ld [wd11e],a ; initialize [wd11e] to neutral effectiveness
+ ld [wTypeEffectiveness],a ; initialize to neutral effectiveness
ld hl,TypeEffects
.loop
ld a,[hli]
cp a,$ff
ret z
- cp d ; match the type of the move
+ cp d ; match the type of the move
jr nz,.nextTypePair1
ld a,[hli]
- cp b ; match with type 1 of pokemon
+ cp b ; match with type 1 of pokemon
jr z,.done
- cp c ; or match with type 2 of pokemon
+ cp c ; or match with type 2 of pokemon
jr z,.done
jr .nextTypePair2
.nextTypePair1
@@ -5405,23 +5430,23 @@ AIGetTypeEffectiveness: ; 3e449 (f:6449)
jr .loop
.done
ld a,[hl]
- ld [wd11e],a ; store damage multiplier
+ ld [wTypeEffectiveness],a ; store damage multiplier
ret
INCLUDE "data/type_effects.asm"
; some tests that need to pass for a move to hit
-MoveHitTest: ; 3e56b (f:656b)
+MoveHitTest:
; player's turn
- ld hl,W_ENEMYBATTSTATUS1
- ld de,W_PLAYERMOVEEFFECT
+ ld hl,wEnemyBattleStatus1
+ ld de,wPlayerMoveEffect
ld bc,wEnemyMonStatus
ld a,[H_WHOSETURN]
and a
jr z,.dreamEaterCheck
; enemy's turn
- ld hl,W_PLAYERBATTSTATUS1
- ld de,W_ENEMYMOVEEFFECT
+ ld hl,wPlayerBattleStatus1
+ ld de,wEnemyMoveEffect
ld bc,wBattleMonStatus
.dreamEaterCheck
ld a,[de]
@@ -5450,7 +5475,7 @@ MoveHitTest: ; 3e56b (f:656b)
jr nz,.enemyTurn
.playerTurn
; this checks if the move effect is disallowed by mist
- ld a,[W_PLAYERMOVEEFFECT]
+ ld a,[wPlayerMoveEffect]
cp a,ATTACK_DOWN1_EFFECT
jr c,.skipEnemyMistCheck
cp a,HAZE_EFFECT + 1
@@ -5467,16 +5492,16 @@ MoveHitTest: ; 3e56b (f:656b)
; FLASH, CONVERSION*, HAZE*, SCREECH, LIGHT SCREEN*, REFLECT*
; the moves that are marked with an asterisk are not affected since this
; function is not called when those moves are used
- ld a,[W_ENEMYBATTSTATUS2]
+ ld a,[wEnemyBattleStatus2]
bit ProtectedByMist,a ; is mon protected by mist?
jp nz,.moveMissed
.skipEnemyMistCheck
- ld a,[W_PLAYERBATTSTATUS2]
+ ld a,[wPlayerBattleStatus2]
bit UsingXAccuracy,a ; is the player using X Accuracy?
ret nz ; if so, always hit regardless of accuracy/evasion
jr .calcHitChance
.enemyTurn
- ld a,[W_ENEMYMOVEEFFECT]
+ ld a,[wEnemyMoveEffect]
cp a,ATTACK_DOWN1_EFFECT
jr c,.skipPlayerMistCheck
cp a,HAZE_EFFECT + 1
@@ -5488,21 +5513,21 @@ MoveHitTest: ; 3e56b (f:656b)
jr .skipPlayerMistCheck
.playerMistCheck
; similar to enemy mist check
- ld a,[W_PLAYERBATTSTATUS2]
+ ld a,[wPlayerBattleStatus2]
bit ProtectedByMist,a ; is mon protected by mist?
jp nz,.moveMissed
.skipPlayerMistCheck
- ld a,[W_ENEMYBATTSTATUS2]
+ ld a,[wEnemyBattleStatus2]
bit UsingXAccuracy,a ; is the enemy using X Accuracy?
ret nz ; if so, always hit regardless of accuracy/evasion
.calcHitChance
call CalcHitChance ; scale the move accuracy according to attacker's accuracy and target's evasion
- ld a,[W_PLAYERMOVEACCURACY]
+ ld a,[wPlayerMoveAccuracy]
ld b,a
ld a,[H_WHOSETURN]
and a
jr z,.doAccuracyCheck
- ld a,[W_ENEMYMOVEACCURACY]
+ ld a,[wEnemyMoveAccuracy]
ld b,a
.doAccuracyCheck
; if the random number generated is greater than or equal to the scaled accuracy, the move misses
@@ -5513,26 +5538,26 @@ MoveHitTest: ; 3e56b (f:656b)
ret
.moveMissed
xor a
- ld hl,W_DAMAGE ; zero the damage
+ ld hl,wDamage ; zero the damage
ld [hli],a
ld [hl],a
inc a
- ld [W_MOVEMISSED],a
+ ld [wMoveMissed],a
ld a,[H_WHOSETURN]
and a
jr z,.playerTurn2
.enemyTurn2
- ld hl,W_ENEMYBATTSTATUS1
+ ld hl,wEnemyBattleStatus1
res UsingTrappingMove,[hl] ; end multi-turn attack e.g. wrap
ret
.playerTurn2
- ld hl,W_PLAYERBATTSTATUS1
+ ld hl,wPlayerBattleStatus1
res UsingTrappingMove,[hl] ; end multi-turn attack e.g. wrap
ret
; values for player turn
-CalcHitChance: ; 3e624 (f:6624)
- ld hl,W_PLAYERMOVEACCURACY
+CalcHitChance:
+ ld hl,wPlayerMoveAccuracy
ld a,[H_WHOSETURN]
and a
ld a,[wPlayerMonAccuracyMod]
@@ -5541,7 +5566,7 @@ CalcHitChance: ; 3e624 (f:6624)
ld c,a
jr z,.next
; values for enemy turn
- ld hl,W_ENEMYMOVEACCURACY
+ ld hl,wEnemyMoveAccuracy
ld a,[wEnemyMonAccuracyMod]
ld b,a
ld a,[wPlayerMonEvasionMod]
@@ -5563,7 +5588,7 @@ CalcHitChance: ; 3e624 (f:6624)
; the second iteration multiplies by the evasion ratio
.loop
push bc
- ld hl, StatModifierRatios ; $76cb ; stat modifier ratios
+ ld hl, StatModifierRatios ; stat modifier ratios
dec b
sla b
ld c,b
@@ -5603,8 +5628,8 @@ CalcHitChance: ; 3e624 (f:6624)
ret
; multiplies damage by a random percentage from ~85% to 100%
-RandomizeDamage: ; 3e687 (f:6687)
- ld hl, W_DAMAGE
+RandomizeDamage:
+ ld hl, wDamage
ld a, [hli]
and a
jr nz, .DamageGreaterThanOne
@@ -5633,14 +5658,14 @@ RandomizeDamage: ; 3e687 (f:6687)
call Divide ; divide the result by 255
; store the modified damage
ld a, [H_QUOTIENT + 2]
- ld hl, W_DAMAGE
+ ld hl, wDamage
ld [hli], a
ld a, [H_QUOTIENT + 3]
ld [hl], a
ret
; for more detailed commentary, see equivalent function for player side (ExecutePlayerMove)
-ExecuteEnemyMove: ; 3e6bc (f:66bc)
+ExecuteEnemyMove:
ld a, [wEnemySelectedMove]
inc a
jp z, ExecuteEnemyMoveDone
@@ -5651,15 +5676,15 @@ ExecuteEnemyMove: ; 3e6bc (f:66bc)
jr nz, .executeEnemyMove
ld b, $1
ld a, [wSerialExchangeNybbleReceiveData]
- cp $e
+ cp LINKBATTLE_STRUGGLE
jr z, .executeEnemyMove
- cp $4
+ cp 4
ret nc
.executeEnemyMove
ld hl, wAILayer2Encouragement
inc [hl]
xor a
- ld [W_MOVEMISSED], a
+ ld [wMoveMissed], a
ld [wMoveDidntMiss], a
ld a, $a
ld [wDamageMultipliers], a
@@ -5667,23 +5692,23 @@ ExecuteEnemyMove: ; 3e6bc (f:66bc)
jr nz, .enemyHasNoSpecialConditions
jp [hl]
.enemyHasNoSpecialConditions
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
bit ChargingUp, [hl] ; is the enemy charging up for attack?
jr nz, EnemyCanExecuteChargingMove ; if so, jump
call GetCurrentMove
-CheckIfEnemyNeedsToChargeUp: ; 3e6fc (f:66fc)
- ld a, [W_ENEMYMOVEEFFECT]
+CheckIfEnemyNeedsToChargeUp:
+ ld a, [wEnemyMoveEffect]
cp CHARGE_EFFECT
jp z, JumpMoveEffect
cp FLY_EFFECT
jp z, JumpMoveEffect
jr EnemyCanExecuteMove
-EnemyCanExecuteChargingMove: ; 3e70b (f:670b)
- ld hl, W_ENEMYBATTSTATUS1
+EnemyCanExecuteChargingMove:
+ ld hl, wEnemyBattleStatus1
res ChargingUp, [hl] ; no longer charging up for attack
res Invulnerable, [hl] ; no longer invulnerable to typical attacks
- ld a, [W_ENEMYMOVENUM]
+ ld a, [wEnemyMoveNum]
ld [wd0b5], a
ld a, BANK(MoveNames)
ld [wPredefBank], a
@@ -5692,23 +5717,23 @@ EnemyCanExecuteChargingMove: ; 3e70b (f:670b)
call GetName
ld de, wcd6d
call CopyStringToCF4B
-EnemyCanExecuteMove: ; 3e72b (f:672b)
+EnemyCanExecuteMove:
xor a
ld [wMonIsDisobedient], a
call PrintMonName1Text
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
ld hl, ResidualEffects1
ld de, $1
call IsInArray
jp c, JumpMoveEffect
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
ld hl, SpecialEffectsCont
ld de, $1
call IsInArray
call c, JumpMoveEffect
-EnemyCalcMoveDamage: ; 3e750 (f:6750)
+EnemyCalcMoveDamage:
call SwapPlayerAndEnemyLevels
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
ld hl, SetDamageEffects
ld de, $1
call IsInArray
@@ -5724,54 +5749,54 @@ EnemyCalcMoveDamage: ; 3e750 (f:6750)
call AdjustDamageForMoveType
call RandomizeDamage
-EnemyMoveHitTest: ; 3e77f (f:677f)
+EnemyMoveHitTest:
call MoveHitTest
-handleIfEnemyMoveMissed: ; 3e782 (f:6782)
- ld a, [W_MOVEMISSED]
+handleIfEnemyMoveMissed:
+ ld a, [wMoveMissed]
and a
- jr z, .asm_3e791
- ld a, [W_ENEMYMOVEEFFECT]
+ jr z, .moveDidNotMiss
+ ld a, [wEnemyMoveEffect]
cp EXPLODE_EFFECT
- jr z, asm_3e7a0
+ jr z, handleExplosionMiss
jr EnemyCheckIfFlyOrChargeEffect
-.asm_3e791
+.moveDidNotMiss
call SwapPlayerAndEnemyLevels
-GetEnemyAnimationType: ; 3e794 (f:6794)
- ld a, [W_ENEMYMOVEEFFECT]
+GetEnemyAnimationType:
+ ld a, [wEnemyMoveEffect]
and a
ld a, $1
jr z, playEnemyMoveAnimation
ld a, $2
jr playEnemyMoveAnimation
-asm_3e7a0: ; 3e7a0 (f:67a0)
+handleExplosionMiss:
call SwapPlayerAndEnemyLevels
xor a
-playEnemyMoveAnimation: ; 3e7a4 (f:67a4)
+playEnemyMoveAnimation:
push af
- ld a, [W_ENEMYBATTSTATUS2]
+ ld a, [wEnemyBattleStatus2]
bit HasSubstituteUp, a ; does mon have a substitute?
- ld hl, Func_79747
- ld b, BANK(Func_79747)
+ ld hl, HideSubstituteShowMonAnim
+ ld b, BANK(HideSubstituteShowMonAnim)
call nz, Bankswitch
pop af
ld [wAnimationType], a
- ld a, [W_ENEMYMOVENUM]
+ ld a, [wEnemyMoveNum]
call PlayMoveAnimation
call HandleExplodingAnimation
call DrawEnemyHUDAndHPBar
- ld a, [W_ENEMYBATTSTATUS2]
+ ld a, [wEnemyBattleStatus2]
bit HasSubstituteUp, a ; does mon have a substitute?
- ld hl, Func_79771
- ld b, BANK(Func_79771)
+ ld hl, ReshowSubstituteAnim
+ ld b, BANK(ReshowSubstituteAnim)
call nz, Bankswitch ; slide the substitute's sprite out
jr EnemyCheckIfMirrorMoveEffect
-EnemyCheckIfFlyOrChargeEffect: ; 3e7d1 (f:67d1)
+EnemyCheckIfFlyOrChargeEffect:
call SwapPlayerAndEnemyLevels
- ld c, $1e
+ ld c, 30
call DelayFrames
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp FLY_EFFECT
jr z, .playAnim
cp CHARGE_EFFECT
@@ -5782,8 +5807,8 @@ EnemyCheckIfFlyOrChargeEffect: ; 3e7d1 (f:67d1)
ld [wAnimationType], a
ld a,STATUS_AFFECTED_ANIM
call PlayMoveAnimation
-EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef)
- ld a, [W_ENEMYMOVEEFFECT]
+EnemyCheckIfMirrorMoveEffect:
+ ld a, [wEnemyMoveEffect]
cp MIRROR_MOVE_EFFECT
jr nz, .notMirrorMoveEffect
call MirrorMoveCopyMove
@@ -5795,27 +5820,27 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef)
call MetronomePickMove
jp CheckIfEnemyNeedsToChargeUp
.notMetronomeEffect
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
ld hl, ResidualEffects2
ld de, $1
call IsInArray
jp c, JumpMoveEffect
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
- jr z, .asm_3e82b
+ jr z, .moveDidNotMiss
call PrintMoveFailureText
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp EXPLODE_EFFECT
- jr z, .asm_3e83e
+ jr z, .handleExplosionMiss
jp ExecuteEnemyMoveDone
-.asm_3e82b
+.moveDidNotMiss
call ApplyAttackToPlayerPokemon
call PrintCriticalOHKOText
callab DisplayEffectiveness
ld a, 1
ld [wMoveDidntMiss], a
-.asm_3e83e
- ld a, [W_ENEMYMOVEEFFECT]
+.handleExplosionMiss
+ ld a, [wEnemyMoveEffect]
ld hl, AlwaysHappenSideEffects
ld de, $1
call IsInArray
@@ -5826,9 +5851,9 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef)
or b
ret z
call HandleBuildingRage
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
bit AttackingMultipleTimes, [hl] ; is mon hitting multiple times? (example: double kick)
- jr z, .asm_3e873
+ jr z, .notMultiHitMove
push hl
ld hl, wEnemyNumAttacksLeft
dec [hl]
@@ -5839,8 +5864,8 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef)
call PrintText
xor a
ld [wEnemyNumHits], a
-.asm_3e873
- ld a, [W_ENEMYMOVEEFFECT]
+.notMultiHitMove
+ ld a, [wEnemyMoveEffect]
and a
jr z, ExecuteEnemyMoveDone
ld hl, SpecialEffects
@@ -5849,17 +5874,17 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef)
call nc, JumpMoveEffect
jr ExecuteEnemyMoveDone
-HitXTimesText: ; 3e887 (f:6887)
+HitXTimesText:
TX_FAR _HitXTimesText
db "@"
-ExecuteEnemyMoveDone: ; 3e88c (f:688c)
+ExecuteEnemyMoveDone:
ld b, $1
ret
; checks for various status conditions affecting the enemy mon
; stores whether the mon cannot use a move this turn in Z flag
-CheckEnemyStatusConditions: ; 3e88f (f:688f)
+CheckEnemyStatusConditions:
ld hl, wEnemyMonStatus
ld a, [hl]
and SLP ; sleep mask
@@ -5874,14 +5899,14 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
ld [wAnimationType], a
ld a,SLP_ANIM
call PlayMoveAnimation
- jr .next1
+ jr .sleepDone
.wokeUp
ld hl, WokeUpText
call PrintText
-.next1
+.sleepDone
xor a
ld [wEnemyUsedMove], a
- ld hl, ExecuteEnemyMoveDone
+ ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn
jp .enemyReturnToHL
.checkIfFrozen
bit FRZ, [hl]
@@ -5890,56 +5915,56 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
call PrintText
xor a
ld [wEnemyUsedMove], a
- ld hl, ExecuteEnemyMoveDone
+ ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn
jp .enemyReturnToHL
.checkIfTrapped
- ld a, [W_PLAYERBATTSTATUS1]
+ ld a, [wPlayerBattleStatus1]
bit UsingTrappingMove, a ; is the player using a multi-turn attack like warp
jp z, .checkIfFlinched
ld hl, CantMoveText
call PrintText
- ld hl, ExecuteEnemyMoveDone
+ ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn
jp .enemyReturnToHL
.checkIfFlinched
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
bit Flinched, [hl] ; check if enemy mon flinched
jp z, .checkIfMustRecharge
res Flinched, [hl]
ld hl, FlinchedText
call PrintText
- ld hl, ExecuteEnemyMoveDone
+ ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn
jp .enemyReturnToHL
.checkIfMustRecharge
- ld hl, W_ENEMYBATTSTATUS2
+ ld hl, wEnemyBattleStatus2
bit NeedsToRecharge, [hl] ; check if enemy mon has to recharge after using a move
jr z, .checkIfAnyMoveDisabled
res NeedsToRecharge, [hl]
ld hl, MustRechargeText
call PrintText
- ld hl, ExecuteEnemyMoveDone
+ ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn
jp .enemyReturnToHL
.checkIfAnyMoveDisabled
- ld hl, W_ENEMYDISABLEDMOVE
+ ld hl, wEnemyDisabledMove
ld a, [hl]
and a
jr z, .checkIfConfused
- dec a
+ dec a ; decrement disable counter
ld [hl], a
- and $f
+ and $f ; did disable counter hit 0?
jr nz, .checkIfConfused
ld [hl], a
- ld [wccef], a
+ ld [wEnemyDisabledMoveNumber], a
ld hl, DisabledNoMoreText
call PrintText
.checkIfConfused
- ld a, [W_ENEMYBATTSTATUS1]
+ ld a, [wEnemyBattleStatus1]
add a ; check if enemy mon is confused
jp nc, .checkIfTriedToUseDisabledMove
- ld hl, W_ENEMYCONFUSEDCOUNTER
+ ld hl, wEnemyConfusedCounter
dec [hl]
jr nz, .isConfused
- ld hl, W_ENEMYBATTSTATUS1
- res Confused, [hl]
+ ld hl, wEnemyBattleStatus1
+ res Confused, [hl] ; if confused counter hit 0, reset confusion status
ld hl, ConfusedNoMoreText
call PrintText
jp .checkIfTriedToUseDisabledMove
@@ -5953,9 +5978,9 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
call BattleRandom
cp $80
jr c, .checkIfTriedToUseDisabledMove
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
ld a, [hl]
- and 1 << Confused
+ and 1 << Confused ; if mon hurts itself, clear every other status from wEnemyBattleStatus1
ld [hl], a
ld hl, HurtItselfText
call PrintText
@@ -5968,7 +5993,7 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
ld [hli], a
ld a, [wEnemyMonDefense + 1]
ld [hl], a
- ld hl, W_ENEMYMOVEEFFECT
+ ld hl, wEnemyMoveEffect
push hl
ld a, [hl]
push af
@@ -5999,31 +6024,32 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
call ApplyDamageToEnemyPokemon
jr .monHurtItselfOrFullyParalysed
.checkIfTriedToUseDisabledMove
- ld a, [wccef]
+; prevents a disabled move that was selected before being disabled from being used
+ ld a, [wEnemyDisabledMoveNumber]
and a
jr z, .checkIfParalysed
ld hl, wEnemySelectedMove
cp [hl]
jr nz, .checkIfParalysed
call PrintMoveIsDisabledText
- ld hl, ExecuteEnemyMoveDone
+ ld hl, ExecuteEnemyMoveDone ; if a disabled move was somehow selected, player can't move this turn
jp .enemyReturnToHL
.checkIfParalysed
ld hl, wEnemyMonStatus
bit PAR, [hl]
jr z, .checkIfUsingBide
call BattleRandom
- cp $3f
+ cp $3f ; 25% to be fully paralysed
jr nc, .checkIfUsingBide
ld hl, FullyParalyzedText
call PrintText
.monHurtItselfOrFullyParalysed
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
ld a, [hl]
- ; clear bide, thrashing about, charging up, and multi-turn moves such as warp
- and (1 << AttackingMultipleTimes) | (1 << Flinched) | (1 << Invulnerable) | (1 << Confused)
+ ; clear bide, thrashing about, charging up, and multi-turn moves such as warp
+ and $ff ^ ((1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << ChargingUp) | (1 << UsingTrappingMove))
ld [hl], a
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp FLY_EFFECT
jr z, .flyOrChargeEffect
cp CHARGE_EFFECT
@@ -6036,78 +6062,78 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
call PlayMoveAnimation
.notFlyOrChargeEffect
ld hl, ExecuteEnemyMoveDone
- jp .enemyReturnToHL
+ jp .enemyReturnToHL ; if using a two-turn move, enemy needs to recharge the first turn
.checkIfUsingBide
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
bit StoringEnergy, [hl] ; is mon using bide?
jr z, .checkIfThrashingAbout
xor a
- ld [W_ENEMYMOVENUM], a
- ld hl, W_DAMAGE
+ ld [wEnemyMoveNum], a
+ ld hl, wDamage
ld a, [hli]
ld b, a
ld c, [hl]
ld hl, wEnemyBideAccumulatedDamage + 1
ld a, [hl]
- add c
+ add c ; accumulate damage taken
ld [hld], a
ld a, [hl]
adc b
ld [hl], a
ld hl, wEnemyNumAttacksLeft
- dec [hl]
+ dec [hl] ; did Bide counter hit 0?
jr z, .unleashEnergy
ld hl, ExecuteEnemyMoveDone
- jp .enemyReturnToHL
+ jp .enemyReturnToHL ; unless mon unleashes energy, can't move this turn
.unleashEnergy
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
res StoringEnergy, [hl] ; not using bide any more
ld hl, UnleashedEnergyText
call PrintText
ld a, $1
- ld [W_ENEMYMOVEPOWER], a
+ ld [wEnemyMovePower], a
ld hl, wEnemyBideAccumulatedDamage + 1
ld a, [hld]
add a
ld b, a
- ld [W_DAMAGE + 1], a
+ ld [wDamage + 1], a
ld a, [hl]
- rl a
- ld [W_DAMAGE], a
+ rl a ; double the damage
+ ld [wDamage], a
or b
- jr nz, .next2
+ jr nz, .next
ld a, $1
- ld [W_MOVEMISSED], a
-.next2
+ ld [wMoveMissed], a
+.next
xor a
ld [hli], a
ld [hl], a
ld a, BIDE
- ld [W_ENEMYMOVENUM], a
+ ld [wEnemyMoveNum], a
call SwapPlayerAndEnemyLevels
- ld hl, handleIfEnemyMoveMissed
+ ld hl, handleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest
jp .enemyReturnToHL
.checkIfThrashingAbout
bit ThrashingAbout, [hl] ; is mon using thrash or petal dance?
jr z, .checkIfUsingMultiturnMove
ld a, THRASH
- ld [W_ENEMYMOVENUM], a
+ ld [wEnemyMoveNum], a
ld hl, ThrashingAboutText
call PrintText
ld hl, wEnemyNumAttacksLeft
- dec [hl]
- ld hl, EnemyCalcMoveDamage
+ dec [hl] ; did Thrashing About counter hit 0?
+ ld hl, EnemyCalcMoveDamage ; skip DecrementPP
jp nz, .enemyReturnToHL
push hl
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
res ThrashingAbout, [hl] ; mon is no longer using thrash or petal dance
set Confused, [hl] ; mon is now confused
call BattleRandom
and $3
inc a
- inc a
- ld [W_ENEMYCONFUSEDCOUNTER], a
- pop hl
+ inc a ; confused for 2-5 turns
+ ld [wEnemyConfusedCounter], a
+ pop hl ; skip DecrementPP
jp .enemyReturnToHL
.checkIfUsingMultiturnMove
bit UsingTrappingMove, [hl] ; is mon using multi-turn move?
@@ -6115,20 +6141,21 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
ld hl, AttackContinuesText
call PrintText
ld hl, wEnemyNumAttacksLeft
- dec [hl]
- ld hl, GetEnemyAnimationType
+ dec [hl] ; did multi-turn move end?
+ ld hl, GetEnemyAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit),
+ ; DecrementPP and MoveHitTest
jp nz, .enemyReturnToHL
jp .enemyReturnToHL
.checkIfUsingRage
- ld a, [W_ENEMYBATTSTATUS2]
+ ld a, [wEnemyBattleStatus2]
bit UsingRage, a ; is mon using rage?
- jp z, .checkEnemyStatusConditionsDone
+ jp z, .checkEnemyStatusConditionsDone ; if we made it this far, mon can move normally this turn
ld a, RAGE
ld [wd11e], a
call GetMoveName
call CopyStringToCF4B
xor a
- ld [W_ENEMYMOVEEFFECT], a
+ ld [wEnemyMoveEffect], a
ld hl, EnemyCanExecuteMove
jp .enemyReturnToHL
.enemyReturnToHL
@@ -6139,25 +6166,25 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
and a ; clear Z flag
ret
-GetCurrentMove: ; 3eabe (f:6abe)
+GetCurrentMove:
ld a, [H_WHOSETURN]
and a
jp z, .player
- ld de, W_ENEMYMOVENUM
+ ld de, wEnemyMoveNum
ld a, [wEnemySelectedMove]
jr .selected
.player
- ld de, W_PLAYERMOVENUM
- ld a, [W_FLAGS_D733]
- bit 0, a
- ld a, [wccd9]
+ ld de, wPlayerMoveNum
+ ld a, [wFlags_D733]
+ bit BIT_TEST_BATTLE, a
+ ld a, [wTestBattlePlayerSelectedMove]
jr nz, .selected
ld a, [wPlayerSelectedMove]
.selected
ld [wd0b5], a
dec a
ld hl, Moves
- ld bc, $6
+ ld bc, MoveEnd - Moves
call AddNTimes
ld a, BANK(Moves)
call FarCopyData
@@ -6170,7 +6197,7 @@ GetCurrentMove: ; 3eabe (f:6abe)
ld de, wcd6d
jp CopyStringToCF4B
-LoadEnemyMonData: ; 3eb01 (f:6b01)
+LoadEnemyMonData:
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jp z, LoadEnemyMonFromParty
@@ -6178,13 +6205,13 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
ld [wEnemyMonSpecies], a
ld [wd0b5], a
call GetMonHeader
- ld a, [W_ENEMYBATTSTATUS3]
+ ld a, [wEnemyBattleStatus3]
bit Transformed, a ; is enemy mon transformed?
- ld hl, wcceb ; copied DVs from when it used Transform
+ ld hl, wTransformedEnemyMonOriginalDVs ; original DVs before transforming
ld a, [hli]
ld b, [hl]
jr nz, .storeDVs
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
cp $2 ; is it a trainer battle?
; fixed DVs for trainer mon
ld a, $98
@@ -6199,7 +6226,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
ld [hli], a
ld [hl], b
ld de, wEnemyMonLevel
- ld a, [W_CURENEMYLVL]
+ ld a, [wCurEnemyLVL]
ld [de], a
inc de
ld b, $0
@@ -6207,10 +6234,10 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
push hl
call CalcStats
pop hl
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
cp $2 ; is it a trainer battle?
jr z, .copyHPAndStatusFromPartyData
- ld a, [W_ENEMYBATTSTATUS3]
+ ld a, [wEnemyBattleStatus3]
bit Transformed, a ; is enemy mon transformed?
jr nz, .copyTypes ; if transformed, jump
; if it's a wild mon and not transformed, init the current HP to max HP and the status to 0
@@ -6239,7 +6266,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
ld [wEnemyMonStatus], a
jr .copyTypes
.copyTypes
- ld hl, W_MONHTYPES
+ ld hl, wMonHTypes
ld de, wEnemyMonType
ld a, [hli] ; copy type 1
ld [de], a
@@ -6250,7 +6277,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
ld a, [hli] ; copy catch rate
ld [de], a
inc de
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
cp $2 ; is it a trainer battle?
jr nz, .copyStandardMoves
; if it's a trainer battle, copy moves from enemy party data
@@ -6263,7 +6290,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
jr .loadMovePPs
.copyStandardMoves
; for a wild mon, first copy default moves from the mon header
- ld hl, W_MONHMOVES
+ ld hl, wMonHMoves
ld a, [hli]
ld [de], a
inc de
@@ -6279,22 +6306,22 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
dec de
dec de
xor a
- ld [wHPBarMaxHP], a
+ ld [wLearningMovesFromDayCare], a
predef WriteMonMoves ; get moves based on current level
.loadMovePPs
ld hl, wEnemyMonMoves
- ld de, wEnemyMonSpecial + 1
+ ld de, wEnemyMonPP - 1
predef LoadMovePPs
- ld hl, W_MONHBASESTATS
+ ld hl, wMonHBaseStats
ld de, wEnemyMonBaseStats
- ld b, $5
+ ld b, NUM_STATS
.copyBaseStatsLoop
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .copyBaseStatsLoop
- ld hl, W_MONHCATCHRATE
+ ld hl, wMonHCatchRate
ld a, [hli]
ld [de], a
inc de
@@ -6305,7 +6332,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
call GetMonName
ld hl, wcd6d
ld de, wEnemyMonNick
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld a, [wEnemyMonSpecies2]
ld [wd11e], a
@@ -6313,15 +6340,15 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
ld a, [wd11e]
dec a
ld c, a
- ld b, $1
+ ld b, FLAG_SET
ld hl, wPokedexSeen
predef FlagActionPredef ; mark this mon as seen in the pokedex
ld hl, wEnemyMonLevel
ld de, wEnemyMonUnmodifiedLevel
- ld bc, $b
+ ld bc, 1 + NUM_STATS * 2
call CopyData
ld a, $7 ; default stat mod
- ld b, $8 ; number of stat mods
+ ld b, NUM_STAT_MODS ; number of stat mods
ld hl, wEnemyMonStatMods
.statModLoop
ld [hli], a
@@ -6330,7 +6357,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
ret
; calls BattleTransition to show the battle transition animation and initializes some battle variables
-DoBattleTransitionAndInitBattleVariables: ; 3ec32 (f:6c32)
+DoBattleTransitionAndInitBattleVariables:
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr nz, .next
@@ -6362,11 +6389,11 @@ DoBattleTransitionAndInitBattleVariables: ; 3ec32 (f:6c32)
ld [hli], a
ld [hli], a
ld [hl], a
- ld [W_PLAYERDISABLEDMOVE], a
+ ld [wPlayerDisabledMove], a
ret
; swaps the level values of the BattleMon and EnemyMon structs
-SwapPlayerAndEnemyLevels: ; 3ec81 (f:6c81)
+SwapPlayerAndEnemyLevels:
push bc
ld a, [wBattleMonLevel]
ld b, a
@@ -6380,8 +6407,8 @@ SwapPlayerAndEnemyLevels: ; 3ec81 (f:6c81)
; loads either red back pic or old man back pic
; also writes OAM data and loads tile patterns for the Red or Old Man back sprite's head
; (for use when scrolling the player sprite and enemy's silhouettes on screen)
-LoadPlayerBackPic: ; 3ec92 (f:6c92)
- ld a, [W_BATTLETYPE]
+LoadPlayerBackPic:
+ ld a, [wBattleType]
dec a ; is it the old man tutorial?
ld de, RedPicBack
jr nz, .next
@@ -6392,7 +6419,7 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92)
predef ScaleSpriteByTwo
ld hl, wOAMBuffer
xor a
- ld [$FF8B], a ; initial tile number
+ ld [hOAMTile], a ; initial tile number
ld b, $7 ; 7 columns
ld e, $a0 ; X for the left-most column
.loop ; each loop iteration writes 3 OAM entries in a vertical column
@@ -6406,16 +6433,16 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92)
add d ; increase Y by height of tile
ld d, a
inc hl
- ld a, [$FF8B]
+ ld a, [hOAMTile]
ld [hli], a ; OAM tile number
inc a ; increment tile number
- ld [$FF8B], a
+ ld [hOAMTile], a
inc hl
dec c
jr nz, .innerLoop
- ld a, [$FF8B]
+ ld a, [hOAMTile]
add $4 ; increase tile number by 4
- ld [$FF8B], a
+ ld [hOAMTile], a
ld a, $8 ; width of tile
add e ; increase X by width of tile
ld e, a
@@ -6428,7 +6455,7 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92)
xor a
ld [$4000], a
ld hl, vSprites
- ld de, S_SPRITEBUFFER1
+ ld de, sSpriteBuffer1
ld a, [H_LOADEDROMBANK]
ld b, a
ld c, 7 * 7
@@ -6436,35 +6463,31 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92)
xor a
ld [$0], a
ld a, $31
- ld [$ffe1], a
- hlCoord 1, 5
- predef_jump Func_3f0c6
+ ld [hStartTileID], a
+ coord hl, 1, 5
+ predef_jump CopyUncompressedPicToTilemap
; does nothing since no stats are ever selected (barring glitches)
-DoubleOrHalveSelectedStats: ; 3ed02 (f:6d02)
+DoubleOrHalveSelectedStats:
callab DoubleSelectedStats
- ld hl, HalveSelectedStats
- ld b, BANK(HalveSelectedStats)
- jp Bankswitch
+ jpab HalveSelectedStats
-ScrollTrainerPicAfterBattle: ; 3ed12 (f:6d12)
- ld hl, _ScrollTrainerPicAfterBattle
- ld b, BANK(_ScrollTrainerPicAfterBattle)
- jp Bankswitch
+ScrollTrainerPicAfterBattle:
+ jpab _ScrollTrainerPicAfterBattle
-ApplyBurnAndParalysisPenaltiesToPlayer: ; 3ed1a (f:6d1a)
+ApplyBurnAndParalysisPenaltiesToPlayer:
ld a, $1
jr ApplyBurnAndParalysisPenalties
-ApplyBurnAndParalysisPenaltiesToEnemy: ; 3ed1e (f:6d1e)
+ApplyBurnAndParalysisPenaltiesToEnemy:
xor a
-ApplyBurnAndParalysisPenalties: ; 3ed1f (f:6d1f)
+ApplyBurnAndParalysisPenalties:
ld [H_WHOSETURN], a
call QuarterSpeedDueToParalysis
jp HalveAttackDueToBurn
-QuarterSpeedDueToParalysis: ; 3ed27 (f:6d27)
+QuarterSpeedDueToParalysis:
ld a, [H_WHOSETURN]
and a
jr z, .playerTurn
@@ -6507,7 +6530,7 @@ QuarterSpeedDueToParalysis: ; 3ed27 (f:6d27)
ld [hl], b
ret
-HalveAttackDueToBurn: ; 3ed64 (f:6d64)
+HalveAttackDueToBurn:
ld a, [H_WHOSETURN]
and a
jr z, .playerTurn
@@ -6546,26 +6569,26 @@ HalveAttackDueToBurn: ; 3ed64 (f:6d64)
ld [hl], b
ret
-CalculateModifiedStats: ; 3ed99 (f:6d99)
+CalculateModifiedStats:
ld c, 0
.loop
call CalculateModifiedStat
inc c
ld a, c
- cp 4
+ cp NUM_STATS - 1
jr nz, .loop
ret
; calculate modified stat for stat c (0 = attack, 1 = defense, 2 = speed, 3 = special)
-CalculateModifiedStat: ; 3eda5 (f:6da5)
+CalculateModifiedStat:
push bc
push bc
- ld a, [wd11e]
+ ld a, [wCalculateWhoseStats]
and a
ld a, c
ld hl, wBattleMonAttack
ld de, wPlayerMonUnmodifiedAttack
- ld bc, wPlayerMonAttackMod
+ ld bc, wPlayerMonStatMods
jr z, .next
ld hl, wEnemyMonAttack
ld de, wEnemyMonUnmodifiedAttack
@@ -6635,11 +6658,11 @@ CalculateModifiedStat: ; 3eda5 (f:6da5)
pop bc
ret
-ApplyBadgeStatBoosts: ; 3ee19 (f:6e19)
+ApplyBadgeStatBoosts:
ld a, [wLinkState]
cp LINK_STATE_BATTLING
ret z ; return if link battle
- ld a, [W_OBTAINEDBADGES]
+ ld a, [wObtainedBadges]
ld b, a
ld hl, wBattleMonAttack
ld c, $4
@@ -6688,35 +6711,35 @@ ApplyBadgeStatBoosts: ; 3ee19 (f:6e19)
ld [hld], a
ret
-LoadHudAndHpBarAndStatusTilePatterns: ; 3ee58 (f:6e58)
+LoadHudAndHpBarAndStatusTilePatterns:
call LoadHpBarAndStatusTilePatterns
-LoadHudTilePatterns: ; 3ee5b (f:6e5b)
+LoadHudTilePatterns:
ld a, [rLCDC]
add a ; is LCD disabled?
jr c, .lcdEnabled
.lcdDisabled
ld hl, BattleHudTiles1
ld de, vChars2 + $6d0
- ld bc, $18
+ ld bc, BattleHudTiles1End - BattleHudTiles1
ld a, BANK(BattleHudTiles1)
call FarCopyDataDouble
ld hl, BattleHudTiles2
ld de, vChars2 + $730
- ld bc, $30
+ ld bc, BattleHudTiles3End - BattleHudTiles2
ld a, BANK(BattleHudTiles2)
jp FarCopyDataDouble
.lcdEnabled
ld de, BattleHudTiles1
ld hl, vChars2 + $6d0
- ld bc, (BANK(BattleHudTiles1) << 8) + $03
+ lb bc, BANK(BattleHudTiles1), (BattleHudTiles1End - BattleHudTiles1) / $8
call CopyVideoDataDouble
ld de, BattleHudTiles2
ld hl, vChars2 + $730
- ld bc, (BANK(BattleHudTiles2) << 8) + $06
+ lb bc, BANK(BattleHudTiles2), (BattleHudTiles3End - BattleHudTiles2) / $8
jp CopyVideoDataDouble
-PrintEmptyString: ; 3ee94 (f:6e94)
+PrintEmptyString:
ld hl, .emptyString
jp PrintText
.emptyString
@@ -6749,8 +6772,8 @@ BattleRandom:
push hl
push bc
push af
-
-; point to seed 0 so we pick the first number the next time
+
+; point to seed 0 so we pick the first number the next time
xor a
ld [wLinkBattleRandomNumberListIndex], a
@@ -6759,11 +6782,11 @@ BattleRandom:
.loop
ld a, [hl]
ld c, a
-; multiply by 5
+; multiply by 5
add a
add a
add c
-; add 1
+; add 1
inc a
ld [hli], a
dec b
@@ -6775,22 +6798,22 @@ BattleRandom:
ret
-HandleExplodingAnimation: ; 3eed3 (f:6ed3)
+HandleExplodingAnimation:
ld a, [H_WHOSETURN]
and a
- ld hl, wEnemyMonType1 ; wcfea
- ld de, W_ENEMYBATTSTATUS1
- ld a, [W_PLAYERMOVENUM]
- jr z, .asm_3eeea
- ld hl, wBattleMonType1 ; wd019
- ld de, W_ENEMYBATTSTATUS1
- ld a, [W_ENEMYMOVENUM]
-.asm_3eeea
+ ld hl, wEnemyMonType1
+ ld de, wEnemyBattleStatus1
+ ld a, [wPlayerMoveNum]
+ jr z, .player
+ ld hl, wBattleMonType1
+ ld de, wEnemyBattleStatus1
+ ld a, [wEnemyMoveNum]
+.player
cp SELFDESTRUCT
- jr z, .asm_3eef1
+ jr z, .isExplodingMove
cp EXPLOSION
ret nz
-.asm_3eef1
+.isExplodingMove
ld a, [de]
bit Invulnerable, a ; fly/dig
ret nz
@@ -6800,28 +6823,29 @@ HandleExplodingAnimation: ; 3eed3 (f:6ed3)
ld a, [hl]
cp GHOST
ret z
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
ret nz
ld a, 5
ld [wAnimationType], a
-PlayMoveAnimation: ; 3ef07 (f:6f07)
- ld [W_ANIMATIONID],a
+PlayMoveAnimation:
+ ld [wAnimationID],a
call Delay3
predef_jump MoveAnimation
-InitBattle: ; 3ef12 (f:6f12)
- ld a, [W_CUROPPONENT]
+InitBattle:
+ ld a, [wCurOpponent]
and a
- jr z, asm_3ef23
+ jr z, DetermineWildOpponent
-InitOpponent: ; 3ef18 (f:6f18)
- ld a, [W_CUROPPONENT]
+InitOpponent:
+ ld a, [wCurOpponent]
ld [wcf91], a
ld [wEnemyMonSpecies2], a
- jr asm_3ef3d
-asm_3ef23: ; 3ef23 (f:6f23)
+ jr InitBattleCommon
+
+DetermineWildOpponent:
ld a, [wd732]
bit 1, a
jr z, .asm_3ef2f
@@ -6834,47 +6858,47 @@ asm_3ef23: ; 3ef23 (f:6f23)
ret nz
callab TryDoWildEncounter
ret nz
-asm_3ef3d: ; 3ef3d (f:6f3d)
+InitBattleCommon:
ld a, [wMapPalOffset]
push af
- ld hl, wd358
+ ld hl, wLetterPrintingDelayFlags
ld a, [hl]
push af
res 1, [hl]
callab InitBattleVariables
ld a, [wEnemyMonSpecies2]
- sub $c8
+ sub 200
jp c, InitWildBattle
- ld [W_TRAINERCLASS], a
+ ld [wTrainerClass], a
call GetTrainerInformation
callab ReadTrainer
call DoBattleTransitionAndInitBattleVariables
call _LoadTrainerPic
xor a
ld [wEnemyMonSpecies2], a
- ld [$ffe1], a
+ ld [hStartTileID], a
dec a
ld [wAICount], a
- hlCoord 12, 0
- predef Func_3f0c6
+ coord hl, 12, 0
+ predef CopyUncompressedPicToTilemap
ld a, $ff
ld [wEnemyMonPartyPos], a
ld a, $2
- ld [W_ISINBATTLE], a
- jp InitBattle_Common
+ ld [wIsInBattle], a
+ jp _InitBattleCommon
-InitWildBattle: ; 3ef8b (f:6f8b)
+InitWildBattle:
ld a, $1
- ld [W_ISINBATTLE], a
+ ld [wIsInBattle], a
call LoadEnemyMonData
call DoBattleTransitionAndInitBattleVariables
- ld a, [W_CUROPPONENT]
+ ld a, [wCurOpponent]
cp MAROWAK
jr z, .isGhost
call IsGhostBattle
jr nz, .isNoGhost
.isGhost
- ld hl, W_MONHSPRITEDIM
+ ld hl, wMonHSpriteDim
ld a, $66
ld [hli], a ; write sprite dimensions
ld bc, GhostPic
@@ -6907,15 +6931,15 @@ InitWildBattle: ; 3ef8b (f:6f8b)
call LoadMonFrontSprite ; load mon sprite
.spriteLoaded
xor a
- ld [W_TRAINERCLASS], a
- ld [$ffe1], a
- hlCoord 12, 0
- predef Func_3f0c6
+ ld [wTrainerClass], a
+ ld [hStartTileID], a
+ coord hl, 12, 0
+ predef CopyUncompressedPicToTilemap
; common code that executes after init battle code specific to trainer or wild battles
-InitBattle_Common: ; 3efeb (f:6feb)
- ld b, $0
- call GoPAL_SET
+_InitBattleCommon:
+ ld b, SET_PAL_BATTLE_BLACK
+ call RunPaletteCommand
call SlidePlayerAndEnemySilhouettesOnScreen
xor a
ld [H_AUTOBGTRANSFERENABLED], a
@@ -6924,41 +6948,41 @@ InitBattle_Common: ; 3efeb (f:6feb)
call SaveScreenTilesToBuffer1
call ClearScreen
ld a, $98
- ld [$ffbd], a
+ ld [H_AUTOBGTRANSFERDEST + 1], a
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
ld a, $9c
- ld [$ffbd], a
+ ld [H_AUTOBGTRANSFERDEST + 1], a
call LoadScreenTilesFromBuffer1
- hlCoord 9, 7
- ld bc, $50a
+ coord hl, 9, 7
+ lb bc, 5, 10
call ClearScreenArea
- hlCoord 1, 0
- ld bc, $40a
+ coord hl, 1, 0
+ lb bc, 4, 10
call ClearScreenArea
call ClearSprites
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a ; is it a wild battle?
call z, DrawEnemyHUDAndHPBar ; draw enemy HUD and HP bar if it's a wild battle
call StartBattle
callab EndOfBattle
pop af
- ld [wd358], a
+ ld [wLetterPrintingDelayFlags], a
pop af
ld [wMapPalOffset], a
- ld a, [wd0d4]
+ ld a, [wSavedTilesetType]
ld [hTilesetType], a
scf
ret
.emptyString
db "@"
-_LoadTrainerPic: ; 3f04b (f:704b)
+_LoadTrainerPic:
; wd033-wd034 contain pointer to pic
- ld a, [wd033]
+ ld a, [wTrainerPicPointer]
ld e, a
- ld a, [wd034]
+ ld a, [wTrainerPicPointer + 1]
ld d, a ; de contains pointer to trainer pic
ld a, [wLinkState]
and a
@@ -6973,115 +6997,116 @@ _LoadTrainerPic: ; 3f04b (f:704b)
jp LoadUncompressedSpriteData
; unreferenced
-Func_3f069: ; 3f069 (f:7069)
+ResetCryModifiers:
xor a
- ld [wc0f1], a
- ld [wc0f2], a
+ ld [wFrequencyModifier], a
+ ld [wTempoModifier], a
jp PlaySound
-Func_3f073: ; 3f073 (f:7073)
+; animates the mon "growing" out of the pokeball
+AnimateSendingOutMon:
ld a, [wPredefRegisters]
ld h, a
ld a, [wPredefRegisters + 1]
ld l, a
- ld a, [$ffe1]
- ld [H_DOWNARROWBLINKCNT1], a
+ ld a, [hStartTileID]
+ ld [hBaseTileID], a
ld b, $4c
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
- jr z, .asm_3f0bc
+ jr z, .notInBattle
add b
ld [hl], a
call Delay3
- ld bc, -41
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
add hl, bc
- ld a, $1
- ld [wcd6c], a
- ld bc, $303
- predef Func_79aba
- ld c, $4
+ ld a, 1
+ ld [wDownscaledMonSize], a
+ lb bc, 3, 3
+ predef CopyDownscaledMonTiles
+ ld c, 4
call DelayFrames
- ld bc, -41
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
add hl, bc
xor a
- ld [wcd6c], a
- ld bc, $505
- predef Func_79aba
- ld c, $5
+ ld [wDownscaledMonSize], a
+ lb bc, 5, 5
+ predef CopyDownscaledMonTiles
+ ld c, 5
call DelayFrames
- ld bc, -41
- jr .asm_3f0bf
-.asm_3f0bc
- ld bc, -123
-.asm_3f0bf
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
+ jr .next
+.notInBattle
+ ld bc, -(SCREEN_WIDTH * 6 + 3)
+.next
add hl, bc
- ld a, [H_DOWNARROWBLINKCNT1]
+ ld a, [hBaseTileID]
add $31
- jr asm_3f0d0
+ jr CopyUncompressedPicToHL
-Func_3f0c6: ; 3f0c6 (f:70c6)
+CopyUncompressedPicToTilemap:
ld a, [wPredefRegisters]
ld h, a
ld a, [wPredefRegisters + 1]
ld l, a
- ld a, [$ffe1]
-asm_3f0d0: ; 3f0d0 (f:70d0)
- ld bc, $707
- ld de, $14
+ ld a, [hStartTileID]
+CopyUncompressedPicToHL:
+ lb bc, 7, 7
+ ld de, SCREEN_WIDTH
push af
- ld a, [W_SPRITEFLIPPED]
+ ld a, [wSpriteFlipped]
and a
- jr nz, .asm_3f0ed
+ jr nz, .flipped
pop af
-.asm_3f0de
+.loop
push bc
push hl
-.asm_3f0e0
+.innerLoop
ld [hl], a
add hl, de
inc a
dec c
- jr nz, .asm_3f0e0
+ jr nz, .innerLoop
pop hl
inc hl
pop bc
dec b
- jr nz, .asm_3f0de
+ jr nz, .loop
ret
-
-.asm_3f0ed
+
+.flipped
push bc
- ld b, $0
+ ld b, 0
dec c
add hl, bc
pop bc
pop af
-.asm_3f0f4
+.flippedLoop
push bc
push hl
-.asm_3f0f6
+.flippedInnerLoop
ld [hl], a
add hl, de
inc a
dec c
- jr nz, .asm_3f0f6
+ jr nz, .flippedInnerLoop
pop hl
dec hl
pop bc
dec b
- jr nz, .asm_3f0f4
+ jr nz, .flippedLoop
ret
-LoadMonBackPic: ; 3f103 (f:7103)
+LoadMonBackPic:
; Assumes the monster's attributes have
; been loaded with GetMonHeader.
ld a, [wBattleMonSpecies2]
ld [wcf91], a
- hlCoord 1, 5
- ld b, $7
- ld c, $8
+ coord hl, 1, 5
+ ld b, 7
+ ld c, 8
call ClearScreenArea
- ld hl, W_MONHBACKSPRITE - W_MONHEADER
+ ld hl, wMonHBackSprite - wMonHeader
call UncompressMonSprite
predef ScaleSpriteByTwo
ld de, vBackPic
@@ -7093,17 +7118,17 @@ LoadMonBackPic: ; 3f103 (f:7103)
ld b, a
jp CopyVideoData
-JumpMoveEffect: ; 3f132 (f:7132)
+JumpMoveEffect:
call _JumpMoveEffect
ld b, $1
ret
-_JumpMoveEffect: ; 3f138 (f:7138)
+_JumpMoveEffect:
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVEEFFECT]
+ ld a, [wPlayerMoveEffect]
jr z, .next1
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
.next1
dec a ; subtract 1, there is no special effect for 00
add a ; x2, 16bit pointers
@@ -7116,7 +7141,7 @@ _JumpMoveEffect: ; 3f138 (f:7138)
ld l, a
jp [hl] ; jump to special effect handler
-MoveEffectPointerTable: ; 3f150 (f:7150)
+MoveEffectPointerTable:
dw SleepEffect ; unused effect
dw PoisonEffect ; POISON_SIDE_EFFECT1
dw DrainHPEffect ; DRAIN_HP_EFFECT
@@ -7204,14 +7229,14 @@ MoveEffectPointerTable: ; 3f150 (f:7150)
dw SplashEffect ; SPLASH_EFFECT
dw DisableEffect ; DISABLE_EFFECT
-SleepEffect: ; 3f1fc (f:71fc)
+SleepEffect:
ld de, wEnemyMonStatus
- ld bc, W_ENEMYBATTSTATUS2
+ ld bc, wEnemyBattleStatus2
ld a, [H_WHOSETURN]
and a
jp z, .sleepEffect
ld de, wBattleMonStatus
- ld bc, W_PLAYERBATTSTATUS2
+ ld bc, wPlayerBattleStatus2
.sleepEffect
ld a, [bc]
@@ -7233,7 +7258,7 @@ SleepEffect: ; 3f1fc (f:71fc)
push de
call MoveHitTest ; apply accuracy tests
pop de
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
jr nz, .didntAffect
.setSleepCounter
@@ -7248,22 +7273,22 @@ SleepEffect: ; 3f1fc (f:71fc)
.didntAffect
jp PrintDidntAffectText
-FellAsleepText: ; 3f245 (f:7245)
+FellAsleepText:
TX_FAR _FellAsleepText
db "@"
-AlreadyAsleepText: ; 3f24a (f:724a)
+AlreadyAsleepText:
TX_FAR _AlreadyAsleepText
db "@"
-PoisonEffect: ; 3f24f (f:724f)
+PoisonEffect:
ld hl, wEnemyMonStatus
- ld de, W_PLAYERMOVEEFFECT
+ ld de, wPlayerMoveEffect
ld a, [H_WHOSETURN]
and a
jr z, .poisonEffect
ld hl, wBattleMonStatus
- ld de, W_ENEMYMOVEEFFECT
+ ld de, wEnemyMoveEffect
.poisonEffect
call CheckTargetSubstitute
jr nz, .noEffect ; can't posion a substitute target
@@ -7289,7 +7314,7 @@ PoisonEffect: ; 3f24f (f:724f)
call MoveHitTest ; apply accuracy tests
pop de
pop hl
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
jr nz, .didntAffect
jr .inflictPoison
@@ -7305,13 +7330,13 @@ PoisonEffect: ; 3f24f (f:724f)
ld a, [H_WHOSETURN]
and a
ld b, ANIM_C7
- ld hl, W_PLAYERBATTSTATUS3
+ ld hl, wPlayerBattleStatus3
ld a, [de]
- ld de, W_PLAYERTOXICCOUNTER
+ ld de, wPlayerToxicCounter
jr nz, .ok
ld b, ANIM_A9
- ld hl, W_ENEMYBATTSTATUS3
- ld de, W_ENEMYTOXICCOUNTER
+ ld hl, wEnemyBattleStatus3
+ ld de, wEnemyToxicCounter
.ok
cp TOXIC
jr nz, .normalPoison ; done if move is not Toxic
@@ -7319,18 +7344,18 @@ PoisonEffect: ; 3f24f (f:724f)
xor a
ld [de], a
ld hl, BadlyPoisonedText
- jr .asm_3f2c0
+ jr .continue
.normalPoison
ld hl, PoisonedText
-.asm_3f2c0
+.continue
pop de
ld a, [de]
cp POISON_EFFECT
- jr z, .asm_3f2cd
+ jr z, .regularPoisonEffect
ld a, b
call PlayBattleAnimation2
jp PrintText
-.asm_3f2cd
+.regularPoisonEffect
call PlayCurrentMoveAnimation2
jp PrintText
.noEffect
@@ -7338,31 +7363,29 @@ PoisonEffect: ; 3f24f (f:724f)
cp POISON_EFFECT
ret nz
.didntAffect
- ld c, $32
+ ld c, 50
call DelayFrames
jp PrintDidntAffectText
-PoisonedText: ; 3f2df (f:72df)
+PoisonedText:
TX_FAR _PoisonedText
db "@"
-BadlyPoisonedText: ; 3f2e4 (f:72e4)
+BadlyPoisonedText:
TX_FAR _BadlyPoisonedText
db "@"
-DrainHPEffect: ; 3f2e9 (f:72e9)
- ld hl, DrainHPEffect_
- ld b, BANK(DrainHPEffect_)
- jp Bankswitch
+DrainHPEffect:
+ jpab DrainHPEffect_
-ExplodeEffect: ; 3f2f1 (f:72f1)
+ExplodeEffect:
ld hl, wBattleMonHP
- ld de, W_PLAYERBATTSTATUS2
+ ld de, wPlayerBattleStatus2
ld a, [H_WHOSETURN]
and a
jr z, .faintUser
ld hl, wEnemyMonHP
- ld de, W_ENEMYBATTSTATUS2
+ ld de, wEnemyBattleStatus2
.faintUser
xor a
ld [hli], a ; set the mon's HP to 0
@@ -7374,7 +7397,7 @@ ExplodeEffect: ; 3f2f1 (f:72f1)
ld [de], a
ret
-FreezeBurnParalyzeEffect: ; 3f30c (f:730c)
+FreezeBurnParalyzeEffect:
xor a
ld [wAnimationType], a
call CheckTargetSubstitute ; test bit 4 of d063/d068 flags [target has substitute flag]
@@ -7385,7 +7408,7 @@ FreezeBurnParalyzeEffect: ; 3f30c (f:730c)
ld a, [wEnemyMonStatus]
and a
jp nz, CheckDefrost ; can't inflict status if opponent is already statused
- ld a, [W_PLAYERMOVETYPE]
+ ld a, [wPlayerMoveType]
ld b, a
ld a, [wEnemyMonType1]
cp b ; do target type 1 and move type match?
@@ -7393,7 +7416,7 @@ FreezeBurnParalyzeEffect: ; 3f30c (f:730c)
ld a, [wEnemyMonType2]
cp b ; do target type 2 and move type match?
ret z ; return if they match
- ld a, [W_PLAYERMOVEEFFECT]
+ ld a, [wPlayerMoveEffect]
cp a, PARALYZE_SIDE_EFFECT1 + 1 ; 10% status effects are 04, 05, 06 so 07 will set carry for those
ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance
jr c, .next1 ; branch ahead if this is a 10% chance effect..
@@ -7433,11 +7456,11 @@ FreezeBurnParalyzeEffect: ; 3f30c (f:730c)
call PlayBattleAnimation
ld hl, FrozenText
jp PrintText
-opponentAttacker: ; 3f382 (f:7382)
+opponentAttacker:
ld a, [wBattleMonStatus] ; mostly same as above with addresses swapped for opponent
and a
jp nz, CheckDefrost
- ld a, [W_ENEMYMOVETYPE]
+ ld a, [wEnemyMoveType]
ld b, a
ld a, [wBattleMonType1]
cp b
@@ -7445,7 +7468,7 @@ opponentAttacker: ; 3f382 (f:7382)
ld a, [wBattleMonType2]
cp b
ret z
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp a, PARALYZE_SIDE_EFFECT1 + 1
ld b, $1a
jr c, .next1
@@ -7479,26 +7502,26 @@ opponentAttacker: ; 3f382 (f:7382)
ld hl, FrozenText
jp PrintText
-BurnedText: ; 3f3d8 (f:73d8)
+BurnedText:
TX_FAR _BurnedText
db "@"
-FrozenText: ; 3f3dd (f:73dd)
+FrozenText:
TX_FAR _FrozenText
db "@"
-CheckDefrost: ; 3f3e2 (f:73e2)
+CheckDefrost:
; any fire-type move that has a chance inflict burn (all but Fire Spin) will defrost a frozen target
- and a, 1 << FRZ ; are they frozen?
+ and a, 1 << FRZ ; are they frozen?
ret z ; return if so
ld a, [H_WHOSETURN]
and a
jr nz, .opponent
;player [attacker]
- ld a, [W_PLAYERMOVETYPE]
+ ld a, [wPlayerMoveType]
sub a, FIRE
ret nz ; return if type of move used isn't fire
- ld [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster]
+ ld [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster]
ld hl, wEnemyMon1Status
ld a, [wEnemyMonPartyPos]
ld bc, wEnemyMon2 - wEnemyMon1
@@ -7508,7 +7531,7 @@ CheckDefrost: ; 3f3e2 (f:73e2)
ld hl, FireDefrostedText
jr .common
.opponent
- ld a, [W_ENEMYMOVETYPE] ; same as above with addresses swapped
+ ld a, [wEnemyMoveType] ; same as above with addresses swapped
sub a, FIRE
ret nz
ld [wBattleMonStatus], a
@@ -7522,18 +7545,18 @@ CheckDefrost: ; 3f3e2 (f:73e2)
.common
jp PrintText
-FireDefrostedText: ; 3f423 (f:7423)
+FireDefrostedText:
TX_FAR _FireDefrostedText
db "@"
-StatModifierUpEffect: ; 3f428 (f:7428)
+StatModifierUpEffect:
ld hl, wPlayerMonStatMods
- ld de, W_PLAYERMOVEEFFECT
+ ld de, wPlayerMoveEffect
ld a, [H_WHOSETURN]
and a
jr z, .statModifierUpEffect
ld hl, wEnemyMonStatMods
- ld de, W_ENEMYMOVEEFFECT
+ ld de, wEnemyMoveEffect
.statModifierUpEffect
ld a, [de]
sub ATTACK_UP1_EFFECT
@@ -7600,17 +7623,17 @@ StatModifierUpEffect: ; 3f428 (f:7428)
add hl, bc
pop bc
xor a
- ld [H_MULTIPLICAND], a
+ ld [H_MULTIPLICAND], a
ld a, [de]
ld [H_MULTIPLICAND + 1], a
inc de
ld a, [de]
ld [H_MULTIPLICAND + 2], a
ld a, [hli]
- ld [H_MULTIPLIER], a
+ ld [H_MULTIPLIER], a
call Multiply
ld a, [hl]
- ld [H_DIVISOR], a
+ ld [H_DIVISOR], a
ld b, $4
call Divide
pop hl
@@ -7625,36 +7648,38 @@ StatModifierUpEffect: ; 3f428 (f:7428)
ld a, 999 % $100
ld [H_MULTIPLICAND + 2], a
-UpdateStat: ; 3f4c3 (f:74c3)
+UpdateStat:
ld a, [H_PRODUCT + 2]
ld [hli], a
ld a, [H_PRODUCT + 3]
ld [hl], a
pop hl
-UpdateStatDone: ; 3f4ca (f:74ca)
+UpdateStatDone:
ld b, c
inc b
- call Func_3f688
- ld hl, W_PLAYERBATTSTATUS2
- ld de, W_PLAYERMOVENUM
- ld bc, wccf7
+ call PrintStatText
+ ld hl, wPlayerBattleStatus2
+ ld de, wPlayerMoveNum
+ ld bc, wPlayerMonMinimized
ld a, [H_WHOSETURN]
and a
jr z, .asm_3f4e6
- ld hl, W_ENEMYBATTSTATUS2
- ld de, W_ENEMYMOVENUM
- ld bc, wccf3
+ ld hl, wEnemyBattleStatus2
+ ld de, wEnemyMoveNum
+ ld bc, wEnemyMonMinimized
.asm_3f4e6
ld a, [de]
cp MINIMIZE
jr nz, .asm_3f4f9
- bit HasSubstituteUp, [hl] ; substitute
+ ; if a substitute is up, slide off the substitute and show the mon pic before
+ ; playing the minimize animation
+ bit HasSubstituteUp, [hl]
push af
push bc
- ld hl, Func_79747
- ld b, BANK(Func_79747)
+ ld hl, HideSubstituteShowMonAnim
+ ld b, BANK(HideSubstituteShowMonAnim)
push de
- call nz, Bankswitch ; play Minimize animation unless there's Substitute involved
+ call nz, Bankswitch
pop de
.asm_3f4f9
call PlayCurrentMoveAnimation
@@ -7664,8 +7689,8 @@ UpdateStatDone: ; 3f4ca (f:74ca)
pop bc
ld a, $1
ld [bc], a
- ld hl, Func_79771
- ld b, BANK(Func_79771)
+ ld hl, ReshowSubstituteAnim
+ ld b, BANK(ReshowSubstituteAnim)
pop af
call nz, Bankswitch
.applyBadgeBoostsAndStatusPenalties
@@ -7680,47 +7705,47 @@ UpdateStatDone: ; 3f4ca (f:74ca)
call QuarterSpeedDueToParalysis ; apply speed penalty to the player whose turn is not, if it's paralyzed
jp HalveAttackDueToBurn ; apply attack penalty to the player whose turn is not, if it's burned
-RestoreOriginalStatModifier: ; 3f520 (f:7520)
+RestoreOriginalStatModifier:
pop hl
dec [hl]
-PrintNothingHappenedText: ; 3f522 (f:7522)
+PrintNothingHappenedText:
ld hl, NothingHappenedText
jp PrintText
-MonsStatsRoseText: ; 3f528 (f:7528)
+MonsStatsRoseText:
TX_FAR _MonsStatsRoseText
- db $08 ; asm
+ TX_ASM
ld hl, GreatlyRoseText
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVEEFFECT]
- jr z, .asm_3f53b
- ld a, [W_ENEMYMOVEEFFECT]
-.asm_3f53b
+ ld a, [wPlayerMoveEffect]
+ jr z, .playerTurn
+ ld a, [wEnemyMoveEffect]
+.playerTurn
cp ATTACK_DOWN1_EFFECT
ret nc
ld hl, RoseText
ret
-GreatlyRoseText: ; 3f542 (f:7542)
- db $0a
+GreatlyRoseText:
+ TX_DELAY
TX_FAR _GreatlyRoseText
-
-RoseText: ; 3f547 (f:7547)
+; fallthrough
+RoseText:
TX_FAR _RoseText
db "@"
-StatModifierDownEffect: ; 3f54c (f:754c)
+StatModifierDownEffect:
ld hl, wEnemyMonStatMods
- ld de, W_PLAYERMOVEEFFECT
- ld bc, W_ENEMYBATTSTATUS1
+ ld de, wPlayerMoveEffect
+ ld bc, wEnemyBattleStatus1
ld a, [H_WHOSETURN]
and a
jr z, .statModifierDownEffect
ld hl, wPlayerMonStatMods
- ld de, W_ENEMYMOVEEFFECT
- ld bc, W_PLAYERBATTSTATUS1
+ ld de, wEnemyMoveEffect
+ ld bc, wPlayerBattleStatus1
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr z, .statModifierDownEffect
@@ -7747,7 +7772,7 @@ StatModifierDownEffect: ; 3f54c (f:754c)
pop bc
pop de
pop hl
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
jp nz, MoveMissed
ld a, [bc]
@@ -7795,16 +7820,16 @@ StatModifierDownEffect: ; 3f54c (f:754c)
ld a, c
add e
ld e, a
- jr nc, .asm_3f5e4
+ jr nc, .noCarry
inc d ; de = unmodified stat
-.asm_3f5e4
+.noCarry
pop bc
ld a, [hld]
sub $1 ; can't lower stat below 1 (-6)
jr nz, .recalculateStat
ld a, [hl]
and a
- jp z, Func_3f64d
+ jp z, CantLowerAnymore_Pop
.recalculateStat
; recalculate affected stat
; paralysis and burn penalties, as well as badge boosts are ignored
@@ -7818,17 +7843,17 @@ StatModifierDownEffect: ; 3f54c (f:754c)
add hl, bc
pop bc
xor a
- ld [H_MULTIPLICAND], a
+ ld [H_MULTIPLICAND], a
ld a, [de]
ld [H_MULTIPLICAND + 1], a
inc de
ld a, [de]
ld [H_MULTIPLICAND + 2], a
ld a, [hli]
- ld [H_MULTIPLIER], a
+ ld [H_MULTIPLIER], a
call Multiply
ld a, [hl]
- ld [H_DIVISOR], a
+ ld [H_DIVISOR], a
ld b, $4
call Divide
pop hl
@@ -7841,18 +7866,18 @@ StatModifierDownEffect: ; 3f54c (f:754c)
ld a, $1
ld [H_MULTIPLICAND + 2], a
-UpdateLoweredStat: ; 3f624 (f:7624)
+UpdateLoweredStat:
ld a, [H_PRODUCT + 2]
ld [hli], a
ld a, [H_PRODUCT + 3]
ld [hl], a
pop de
pop hl
-UpdateLoweredStatDone: ; 3f62c (f:762c)
+UpdateLoweredStatDone:
ld b, c
inc b
push de
- call Func_3f688
+ call PrintStatText
pop de
ld a, [de]
cp $44
@@ -7872,66 +7897,67 @@ UpdateLoweredStatDone: ; 3f62c (f:762c)
call QuarterSpeedDueToParalysis
jp HalveAttackDueToBurn
-Func_3f64d: ; 3f64d (f:764d)
+CantLowerAnymore_Pop:
pop de
pop hl
inc [hl]
-CantLowerAnymore: ; 3f650 (f:7650)
+CantLowerAnymore:
ld a, [de]
cp ATTACK_DOWN_SIDE_EFFECT
ret nc
ld hl, NothingHappenedText
jp PrintText
-MoveMissed: ; 3f65a (f:765a)
+MoveMissed:
ld a, [de]
cp $44
ret nc
jp ConditionalPrintButItFailed
-MonsStatsFellText: ; 3f661 (f:7661)
+MonsStatsFellText:
TX_FAR _MonsStatsFellText
- db $08 ; asm
+ TX_ASM
ld hl, FellText
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVEEFFECT]
- jr z, .asm_3f674
- ld a, [W_ENEMYMOVEEFFECT]
-.asm_3f674
- cp $1a
+ ld a, [wPlayerMoveEffect]
+ jr z, .playerTurn
+ ld a, [wEnemyMoveEffect]
+.playerTurn
+; check if the move's effect decreases a stat by 2
+ cp BIDE_EFFECT
ret c
- cp $44
+ cp ATTACK_DOWN_SIDE_EFFECT
ret nc
ld hl, GreatlyFellText
ret
-GreatlyFellText: ; 3f67e (f:767e)
- db $0a
+GreatlyFellText:
+ TX_DELAY
TX_FAR _GreatlyFellText
-
-FellText: ; 3f683 (f:7683)
+; fallthrough
+FellText:
TX_FAR _FellText
db "@"
-Func_3f688: ; 3f688 (f:7688)
+PrintStatText:
ld hl, StatsTextStrings
- ld c, $50
-.asm_3f68d
+ ld c, "@"
+.findStatName_outer
dec b
- jr z, .asm_3f696
-.asm_3f690
+ jr z, .foundStatName
+.findStatName_inner
ld a, [hli]
cp c
- jr z, .asm_3f68d
- jr .asm_3f690
-.asm_3f696
+ jr z, .findStatName_outer
+ jr .findStatName_inner
+.foundStatName
ld de, wcf4b
ld bc, $a
jp CopyData
-StatsTextStrings: ; 3f69f (f:769f)
+StatsTextStrings:
db "ATTACK@"
db "DEFENSE@"
db "SPEED@"
@@ -7939,7 +7965,7 @@ StatsTextStrings: ; 3f69f (f:769f)
db "ACCURACY@"
db "EVADE@"
-StatModifierRatios: ; 3f6cb (f:76cb)
+StatModifierRatios:
; first byte is numerator, second byte is denominator
db 25, 100 ; 0.25
db 28, 100 ; 0.28
@@ -7955,14 +7981,14 @@ StatModifierRatios: ; 3f6cb (f:76cb)
db 35, 10 ; 3.50
db 4, 1 ; 4.00
-BideEffect: ; 3f6e5 (f:76e5)
- ld hl, W_PLAYERBATTSTATUS1
+BideEffect:
+ ld hl, wPlayerBattleStatus1
ld de, wPlayerBideAccumulatedDamage
ld bc, wPlayerNumAttacksLeft
ld a, [H_WHOSETURN]
and a
jr z, .bideEffect
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
ld de, wEnemyBideAccumulatedDamage
ld bc, wEnemyNumAttacksLeft
.bideEffect
@@ -7971,8 +7997,8 @@ BideEffect: ; 3f6e5 (f:76e5)
ld [de], a
inc de
ld [de], a
- ld [W_PLAYERMOVEEFFECT], a
- ld [W_ENEMYMOVEEFFECT], a
+ ld [wPlayerMoveEffect], a
+ ld [wEnemyMoveEffect], a
call BattleRandom
and $1
inc a
@@ -7982,13 +8008,13 @@ BideEffect: ; 3f6e5 (f:76e5)
add XSTATITEM_ANIM
jp PlayBattleAnimation2
-ThrashPetalDanceEffect: ; 3f717 (f:7717)
- ld hl, W_PLAYERBATTSTATUS1
+ThrashPetalDanceEffect:
+ ld hl, wPlayerBattleStatus1
ld de, wPlayerNumAttacksLeft
ld a, [H_WHOSETURN]
and a
jr z, .thrashPetalDanceEffect
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
ld de, wEnemyNumAttacksLeft
.thrashPetalDanceEffect
set ThrashingAbout, [hl] ; mon is now using thrash/petal dance
@@ -8001,140 +8027,140 @@ ThrashPetalDanceEffect: ; 3f717 (f:7717)
add ANIM_B0
jp PlayBattleAnimation2
-SwitchAndTeleportEffect: ; 3f739 (f:7739)
+SwitchAndTeleportEffect:
ld a, [H_WHOSETURN]
and a
- jr nz, .asm_3f791
- ld a, [W_ISINBATTLE]
+ jr nz, .handleEnemy
+ ld a, [wIsInBattle]
dec a
- jr nz, .asm_3f77e
- ld a, [W_CURENEMYLVL]
+ jr nz, .notWildBattle1
+ ld a, [wCurEnemyLVL]
ld b, a
ld a, [wBattleMonLevel]
- cp b
- jr nc, .asm_3f76e
+ cp b ; is the player's level greater than the enemy's level?
+ jr nc, .playerMoveWasSuccessful ; if so, teleport will always succeed
add b
ld c, a
- inc c
-.asm_3f751
+ inc c ; c = sum of player level and enemy level
+.rejectionSampleLoop1
call BattleRandom
- cp c
- jr nc, .asm_3f751
+ cp c ; get a random number between 0 and c
+ jr nc, .rejectionSampleLoop1
srl b
- srl b
- cp b
- jr nc, .asm_3f76e
- ld c, $32
+ srl b ; b = enemyLevel / 4
+ cp b ; is rand[0, playerLevel + enemyLevel) >= (enemyLevel / 4)?
+ jr nc, .playerMoveWasSuccessful ; if so, allow teleporting
+ ld c, 50
call DelayFrames
- ld a, [W_PLAYERMOVENUM]
+ ld a, [wPlayerMoveNum]
cp TELEPORT
jp nz, PrintDidntAffectText
jp PrintButItFailedText_
-.asm_3f76e
+.playerMoveWasSuccessful
call ReadPlayerMonCurHPAndStatus
xor a
ld [wAnimationType], a
inc a
ld [wEscapedFromBattle], a
- ld a, [W_PLAYERMOVENUM]
- jr .asm_3f7e4
-.asm_3f77e
- ld c, $32
+ ld a, [wPlayerMoveNum]
+ jr .playAnimAndPrintText
+.notWildBattle1
+ ld c, 50
call DelayFrames
ld hl, IsUnaffectedText
- ld a, [W_PLAYERMOVENUM]
+ ld a, [wPlayerMoveNum]
cp TELEPORT
jp nz, PrintText
jp PrintButItFailedText_
-.asm_3f791
- ld a, [W_ISINBATTLE]
+.handleEnemy
+ ld a, [wIsInBattle]
dec a
- jr nz, .asm_3f7d1
+ jr nz, .notWildBattle2
ld a, [wBattleMonLevel]
ld b, a
- ld a, [W_CURENEMYLVL]
+ ld a, [wCurEnemyLVL]
cp b
- jr nc, .asm_3f7c1
+ jr nc, .enemyMoveWasSuccessful
add b
ld c, a
inc c
-.asm_3f7a4
+.rejectionSampleLoop2
call BattleRandom
cp c
- jr nc, .asm_3f7a4
+ jr nc, .rejectionSampleLoop2
srl b
srl b
cp b
- jr nc, .asm_3f7c1
- ld c, $32
+ jr nc, .enemyMoveWasSuccessful
+ ld c, 50
call DelayFrames
- ld a, [W_ENEMYMOVENUM]
+ ld a, [wEnemyMoveNum]
cp TELEPORT
jp nz, PrintDidntAffectText
jp PrintButItFailedText_
-.asm_3f7c1
+.enemyMoveWasSuccessful
call ReadPlayerMonCurHPAndStatus
xor a
ld [wAnimationType], a
inc a
ld [wEscapedFromBattle], a
- ld a, [W_ENEMYMOVENUM]
- jr .asm_3f7e4
-.asm_3f7d1
- ld c, $32
+ ld a, [wEnemyMoveNum]
+ jr .playAnimAndPrintText
+.notWildBattle2
+ ld c, 50
call DelayFrames
ld hl, IsUnaffectedText
- ld a, [W_ENEMYMOVENUM]
+ ld a, [wEnemyMoveNum]
cp TELEPORT
jp nz, PrintText
jp ConditionalPrintButItFailed
-.asm_3f7e4
+.playAnimAndPrintText
push af
call PlayBattleAnimation
- ld c, $14
+ ld c, 20
call DelayFrames
pop af
ld hl, RanFromBattleText
cp TELEPORT
- jr z, .asm_3f7ff
+ jr z, .printText
ld hl, RanAwayScaredText
cp ROAR
- jr z, .asm_3f7ff
+ jr z, .printText
ld hl, WasBlownAwayText
-.asm_3f7ff
+.printText
jp PrintText
-RanFromBattleText: ; 3f802 (f:7802)
+RanFromBattleText:
TX_FAR _RanFromBattleText
db "@"
-RanAwayScaredText: ; 3f807 (f:7807)
+RanAwayScaredText:
TX_FAR _RanAwayScaredText
db "@"
-WasBlownAwayText: ; 3f80c (f:780c)
+WasBlownAwayText:
TX_FAR _WasBlownAwayText
db "@"
-TwoToFiveAttacksEffect: ; 3f811 (f:7811)
- ld hl, W_PLAYERBATTSTATUS1
+TwoToFiveAttacksEffect:
+ ld hl, wPlayerBattleStatus1
ld de, wPlayerNumAttacksLeft
ld bc, wPlayerNumHits
ld a, [H_WHOSETURN]
and a
jr z, .twoToFiveAttacksEffect
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
ld de, wEnemyNumAttacksLeft
ld bc, wEnemyNumHits
.twoToFiveAttacksEffect
bit AttackingMultipleTimes, [hl] ; is mon attacking multiple times?
ret nz
set AttackingMultipleTimes, [hl] ; mon is now attacking multiple times
- ld hl, W_PLAYERMOVEEFFECT
+ ld hl, wPlayerMoveEffect
ld a, [H_WHOSETURN]
and a
jr z, .setNumberOfHits
- ld hl, W_ENEMYMOVEEFFECT
+ ld hl, wEnemyMoveEffect
.setNumberOfHits
ld a, [hl]
cp TWINEEDLE_EFFECT
@@ -8146,10 +8172,11 @@ TwoToFiveAttacksEffect: ; 3f811 (f:7811)
call BattleRandom
and $3
cp $2
- jr c, .asm_3f851
+ jr c, .gotNumHits
+; if the number of hits was greater than 2, re-roll again for a lower chance
call BattleRandom
and $3
-.asm_3f851
+.gotNumHits
inc a
inc a
.saveNumberOfHits
@@ -8161,16 +8188,16 @@ TwoToFiveAttacksEffect: ; 3f811 (f:7811)
ld [hl], a ; set Twineedle's effect to poison effect
jr .saveNumberOfHits
-FlinchSideEffect: ; 3f85b (f:785b)
+FlinchSideEffect:
call CheckTargetSubstitute
ret nz
- ld hl, W_ENEMYBATTSTATUS1
- ld de, W_PLAYERMOVEEFFECT
+ ld hl, wEnemyBattleStatus1
+ ld de, wPlayerMoveEffect
ld a, [H_WHOSETURN]
and a
jr z, .flinchSideEffect
- ld hl, W_PLAYERBATTSTATUS1
- ld de, W_ENEMYMOVEEFFECT
+ ld hl, wPlayerBattleStatus1
+ ld de, wEnemyMoveEffect
.flinchSideEffect
ld a, [de]
cp FLINCH_SIDE_EFFECT1
@@ -8185,20 +8212,18 @@ FlinchSideEffect: ; 3f85b (f:785b)
call ClearHyperBeam
ret
-OneHitKOEffect: ; 3f884 (f:7884)
- ld hl, OneHitKOEffect_
- ld b, BANK(OneHitKOEffect_)
- jp Bankswitch
+OneHitKOEffect:
+ jpab OneHitKOEffect_
-ChargeEffect: ; 3f88c (f:788c)
- ld hl, W_PLAYERBATTSTATUS1
- ld de, W_PLAYERMOVEEFFECT
+ChargeEffect:
+ ld hl, wPlayerBattleStatus1
+ ld de, wPlayerMoveEffect
ld a, [H_WHOSETURN]
and a
ld b, XSTATITEM_ANIM
jr z, .chargeEffect
- ld hl, W_ENEMYBATTSTATUS1
- ld de, W_ENEMYMOVEEFFECT
+ ld hl, wEnemyBattleStatus1
+ ld de, wEnemyMoveEffect
ld b, ANIM_AF
.chargeEffect
set ChargingUp, [hl]
@@ -8220,71 +8245,71 @@ ChargeEffect: ; 3f88c (f:788c)
ld a, b
call PlayBattleAnimation
ld a, [de]
- ld [wWhichTrade], a
+ ld [wChargeMoveNum], a
ld hl, ChargeMoveEffectText
jp PrintText
-ChargeMoveEffectText: ; 3f8c8 (f:78c8)
+ChargeMoveEffectText:
TX_FAR _ChargeMoveEffectText
- db $08 ; asm
- ld a, [wWhichTrade]
+ TX_ASM
+ ld a, [wChargeMoveNum]
cp RAZOR_WIND
ld hl, MadeWhirlwindText
- jr z, .asm_3f8f8
+ jr z, .gotText
cp SOLARBEAM
ld hl, TookInSunlightText
- jr z, .asm_3f8f8
+ jr z, .gotText
cp SKULL_BASH
ld hl, LoweredItsHeadText
- jr z, .asm_3f8f8
+ jr z, .gotText
cp SKY_ATTACK
ld hl, SkyAttackGlowingText
- jr z, .asm_3f8f8
+ jr z, .gotText
cp FLY
ld hl, FlewUpHighText
- jr z, .asm_3f8f8
+ jr z, .gotText
cp DIG
ld hl, DugAHoleText
-.asm_3f8f8
+.gotText
ret
-MadeWhirlwindText: ; 3f8f9 (f:78f9)
+MadeWhirlwindText:
TX_FAR _MadeWhirlwindText
db "@"
-TookInSunlightText: ; 3f8fe (f:78fe)
+TookInSunlightText:
TX_FAR _TookInSunlightText
db "@"
-LoweredItsHeadText: ; 3f903 (f:7903)
+LoweredItsHeadText:
TX_FAR _LoweredItsHeadText
db "@"
-SkyAttackGlowingText: ; 3f908 (f:7908)
+SkyAttackGlowingText:
TX_FAR _SkyAttackGlowingText
db "@"
-FlewUpHighText: ; 3f90d (f:790d)
+FlewUpHighText:
TX_FAR _FlewUpHighText
db "@"
-DugAHoleText: ; 3f912 (f:7912)
+DugAHoleText:
TX_FAR _DugAHoleText
db "@"
-TrappingEffect: ; 3f917 (f:7917)
- ld hl, W_PLAYERBATTSTATUS1
+TrappingEffect:
+ ld hl, wPlayerBattleStatus1
ld de, wPlayerNumAttacksLeft
ld a, [H_WHOSETURN]
and a
jr z, .trappingEffect
- ld hl, W_ENEMYBATTSTATUS1
+ ld hl, wEnemyBattleStatus1
ld de, wEnemyNumAttacksLeft
.trappingEffect
bit UsingTrappingMove, [hl]
ret nz
- call ClearHyperBeam ; since this effect is called before testing whether the move will hit,
- ; the target won't need to recharge even if the trapping move missed
+ call ClearHyperBeam ; since this effect is called before testing whether the move will hit,
+ ; the target won't need to recharge even if the trapping move missed
set UsingTrappingMove, [hl] ; mon is now using a trapping move
call BattleRandom ; 3/8 chance for 2 and 3 attacks, and 1/8 chance for 4 and 5 attacks
and $3
@@ -8297,52 +8322,46 @@ TrappingEffect: ; 3f917 (f:7917)
ld [de], a
ret
-MistEffect: ; 3f941 (f:7941)
- ld hl, MistEffect_
- ld b, BANK(MistEffect_)
- jp Bankswitch
+MistEffect:
+ jpab MistEffect_
-FocusEnergyEffect: ; 3f949 (f:7949)
- ld hl, FocusEnergyEffect_
- ld b, BANK(FocusEnergyEffect_)
- jp Bankswitch
+FocusEnergyEffect:
+ jpab FocusEnergyEffect_
-RecoilEffect: ; 3f951 (f:7951)
- ld hl, RecoilEffect_
- ld b, BANK(RecoilEffect_)
- jp Bankswitch
+RecoilEffect:
+ jpab RecoilEffect_
-ConfusionSideEffect: ; 3f959 (f:7959)
+ConfusionSideEffect:
call BattleRandom
- cp $19
+ cp $19 ; ~10% chance
ret nc
jr ConfusionSideEffectSuccess
-ConfusionEffect: ; 3f961 (f:7961)
+ConfusionEffect:
call CheckTargetSubstitute
jr nz, ConfusionEffectFailed
call MoveHitTest
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
jr nz, ConfusionEffectFailed
-ConfusionSideEffectSuccess: ; 3f96f (f:796f)
+ConfusionSideEffectSuccess:
ld a, [H_WHOSETURN]
and a
- ld hl, W_ENEMYBATTSTATUS1
- ld bc, W_ENEMYCONFUSEDCOUNTER
- ld a, [W_PLAYERMOVEEFFECT]
+ ld hl, wEnemyBattleStatus1
+ ld bc, wEnemyConfusedCounter
+ ld a, [wPlayerMoveEffect]
jr z, .confuseTarget
- ld hl, W_PLAYERBATTSTATUS1
- ld bc, W_PLAYERCONFUSEDCOUNTER
- ld a, [W_ENEMYMOVEEFFECT]
+ ld hl, wPlayerBattleStatus1
+ ld bc, wPlayerConfusedCounter
+ ld a, [wEnemyMoveEffect]
.confuseTarget
bit Confused, [hl] ; is mon confused?
jr nz, ConfusionEffectFailed
set Confused, [hl] ; mon is now confused
push af
call BattleRandom
- and $3
+ and $3
inc a
inc a
ld [bc], a ; confusion status will last 2-5 turns
@@ -8352,80 +8371,76 @@ ConfusionSideEffectSuccess: ; 3f96f (f:796f)
ld hl, BecameConfusedText
jp PrintText
-BecameConfusedText: ; 3f9a1 (f:79a1)
+BecameConfusedText:
TX_FAR _BecameConfusedText
db "@"
-ConfusionEffectFailed: ; 3f9a6 (f:79a6)
+ConfusionEffectFailed:
cp CONFUSION_SIDE_EFFECT
ret z
- ld c, $32
+ ld c, 50
call DelayFrames
jp ConditionalPrintButItFailed
-ParalyzeEffect: ; 3f9b1 (f:79b1)
- ld hl, ParalyzeEffect_
- ld b, BANK(ParalyzeEffect_)
- jp Bankswitch
+ParalyzeEffect:
+ jpab ParalyzeEffect_
-SubstituteEffect: ; 3f9b9 (f:79b9)
- ld hl, SubstituteEffect_
- ld b, BANK(SubstituteEffect_)
- jp Bankswitch
+SubstituteEffect:
+ jpab SubstituteEffect_
-HyperBeamEffect: ; 3f9c1 (f:79c1)
- ld hl, W_PLAYERBATTSTATUS2
+HyperBeamEffect:
+ ld hl, wPlayerBattleStatus2
ld a, [H_WHOSETURN]
and a
jr z, .hyperBeamEffect
- ld hl, W_ENEMYBATTSTATUS2
+ ld hl, wEnemyBattleStatus2
.hyperBeamEffect
set NeedsToRecharge, [hl] ; mon now needs to recharge
ret
-ClearHyperBeam: ; 3f9cf (f:79cf)
+ClearHyperBeam:
push hl
- ld hl, W_ENEMYBATTSTATUS2
+ ld hl, wEnemyBattleStatus2
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3f9db
- ld hl, W_PLAYERBATTSTATUS2
-.asm_3f9db
+ jr z, .playerTurn
+ ld hl, wPlayerBattleStatus2
+.playerTurn
res NeedsToRecharge, [hl] ; mon no longer needs to recharge
pop hl
ret
-RageEffect: ; 3f9df (f:79df)
- ld hl, W_PLAYERBATTSTATUS2
+RageEffect:
+ ld hl, wPlayerBattleStatus2
ld a, [H_WHOSETURN]
and a
jr z, .player
- ld hl, W_ENEMYBATTSTATUS2
+ ld hl, wEnemyBattleStatus2
.player
set UsingRage, [hl] ; mon is now in "rage" mode
ret
-MimicEffect: ; 3f9ed (f:79ed)
- ld c, $32
+MimicEffect:
+ ld c, 50
call DelayFrames
call MoveHitTest
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
- jr nz, .asm_3fa74
+ jr nz, .mimicMissed
ld a, [H_WHOSETURN]
and a
ld hl, wBattleMonMoves
- ld a, [W_PLAYERBATTSTATUS1]
- jr nz, .asm_3fa13
+ ld a, [wPlayerBattleStatus1]
+ jr nz, .enemyTurn
ld a, [wLinkState]
cp LINK_STATE_BATTLING
- jr nz, .asm_3fa3a
+ jr nz, .letPlayerChooseMove
ld hl, wEnemyMonMoves
- ld a, [W_ENEMYBATTSTATUS1]
-.asm_3fa13
+ ld a, [wEnemyBattleStatus1]
+.enemyTurn
bit Invulnerable, a
- jr nz, .asm_3fa74
-.asm_3fa17
+ jr nz, .mimicMissed
+.getRandomMove
push hl
call BattleRandom
and $3
@@ -8435,20 +8450,20 @@ MimicEffect: ; 3f9ed (f:79ed)
ld a, [hl]
pop hl
and a
- jr z, .asm_3fa17
+ jr z, .getRandomMove
ld d, a
ld a, [H_WHOSETURN]
and a
ld hl, wBattleMonMoves
ld a, [wPlayerMoveListIndex]
- jr z, .asm_3fa5f
+ jr z, .playerTurn
ld hl, wEnemyMonMoves
ld a, [wEnemyMoveListIndex]
- jr .asm_3fa5f
-.asm_3fa3a
- ld a, [W_ENEMYBATTSTATUS1]
+ jr .playerTurn
+.letPlayerChooseMove
+ ld a, [wEnemyBattleStatus1]
bit Invulnerable, a
- jr nz, .asm_3fa74
+ jr nz, .mimicMissed
ld a, [wCurrentMenuItem]
push af
ld a, $1
@@ -8463,7 +8478,7 @@ MimicEffect: ; 3f9ed (f:79ed)
ld d, [hl]
pop af
ld hl, wBattleMonMoves
-.asm_3fa5f
+.playerTurn
ld c, a
ld b, $0
add hl, bc
@@ -8474,39 +8489,38 @@ MimicEffect: ; 3f9ed (f:79ed)
call PlayCurrentMoveAnimation
ld hl, MimicLearnedMoveText
jp PrintText
-.asm_3fa74
+.mimicMissed
jp PrintButItFailedText_
-MimicLearnedMoveText: ; 3fa77 (f:7a77)
+MimicLearnedMoveText:
TX_FAR _MimicLearnedMoveText
db "@"
-LeechSeedEffect: ; 3fa7c (f:7a7c)
- ld hl, LeechSeedEffect_
- ld b, BANK(LeechSeedEffect_)
- jp Bankswitch
+LeechSeedEffect:
+ jpab LeechSeedEffect_
-SplashEffect: ; 3fa84 (f:7a84)
+SplashEffect:
call PlayCurrentMoveAnimation
jp PrintNoEffectText
-DisableEffect: ; 3fa8a (f:7a8a)
+DisableEffect:
call MoveHitTest
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
- jr nz, .asm_3fb06
- ld de, W_ENEMYDISABLEDMOVE
+ jr nz, .moveMissed
+ ld de, wEnemyDisabledMove
ld hl, wEnemyMonMoves
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3faa4
- ld de, W_PLAYERDISABLEDMOVE
+ jr z, .disableEffect
+ ld de, wPlayerDisabledMove
ld hl, wBattleMonMoves
-.asm_3faa4
+.disableEffect
+; no effect if target already has a move disabled
ld a, [de]
and a
- jr nz, .asm_3fb06
-.asm_3faa8
+ jr nz, .moveMissed
+.pickMoveToDisable
push hl
call BattleRandom
and $3
@@ -8516,20 +8530,21 @@ DisableEffect: ; 3fa8a (f:7a8a)
ld a, [hl]
pop hl
and a
- jr z, .asm_3faa8
- ld [wd11e], a
+ jr z, .pickMoveToDisable ; loop until a non-00 move slot is found
+ ld [wd11e], a ; store move number
push hl
ld a, [H_WHOSETURN]
and a
ld hl, wBattleMonPP
- jr nz, .asm_3facf
+ jr nz, .enemyTurn
ld a, [wLinkState]
cp LINK_STATE_BATTLING
- pop hl
- jr nz, .asm_3fae1
+ pop hl ; wEnemyMonMoves
+ jr nz, .playerTurnNotLinkBattle
+; .playerTurnLinkBattle
push hl
ld hl, wEnemyMonPP
-.asm_3facf
+.enemyTurn
push hl
ld a, [hli]
or [hl]
@@ -8538,144 +8553,133 @@ DisableEffect: ; 3fa8a (f:7a8a)
inc hl
or [hl]
and $3f
- pop hl
- jr z, .asm_3fb05
+ pop hl ; wBattleMonPP or wEnemyMonPP
+ jr z, .moveMissedPopHL ; nothing to do if all moves have no PP left
add hl, bc
ld a, [hl]
pop hl
and a
- jr z, .asm_3faa8
-.asm_3fae1
+ jr z, .pickMoveToDisable ; pick another move if this one had 0 PP
+.playerTurnNotLinkBattle
+; non-link battle enemies have unlimited PP so the previous checks aren't needed
call BattleRandom
and $7
- inc a
- inc c
+ inc a ; 1-8 turns disabled
+ inc c ; move 1-4 will be disabled
swap c
- add c
+ add c ; map disabled move to high nibble of wEnemyDisabledMove / wPlayerDisabledMove
ld [de], a
call PlayCurrentMoveAnimation2
- ld hl, wccee
+ ld hl, wPlayerDisabledMoveNumber
ld a, [H_WHOSETURN]
and a
- jr nz, .asm_3faf8
- inc hl
-.asm_3faf8
- ld a, [wd11e]
+ jr nz, .printDisableText
+ inc hl ; wEnemyDisabledMoveNumber
+.printDisableText
+ ld a, [wd11e] ; move number
ld [hl], a
call GetMoveName
ld hl, MoveWasDisabledText
jp PrintText
-.asm_3fb05
+.moveMissedPopHL
pop hl
-.asm_3fb06
+.moveMissed
jp PrintButItFailedText_
-MoveWasDisabledText: ; 3fb09 (f:7b09)
+MoveWasDisabledText:
TX_FAR _MoveWasDisabledText
db "@"
-PayDayEffect: ; 3fb0e (f:7b0e)
- ld hl, PayDayEffect_
- ld b, BANK(PayDayEffect_)
- jp Bankswitch
-
-ConversionEffect: ; 3fb16 (f:7b16)
- ld hl, ConversionEffect_
- ld b, BANK(ConversionEffect_)
- jp Bankswitch
-
-HazeEffect: ; 3fb1e (f:7b1e)
- ld hl, HazeEffect_
- ld b, BANK(HazeEffect_)
- jp Bankswitch
-
-HealEffect: ; 3fb26 (f:7b26)
- ld hl, HealEffect_
- ld b, BANK(HealEffect_)
- jp Bankswitch
-
-TransformEffect: ; 3fb2e (f:7b2e)
- ld hl, TransformEffect_
- ld b, BANK(TransformEffect_)
- jp Bankswitch
-
-ReflectLightScreenEffect: ; 3fb36 (f:7b36)
- ld hl, ReflectLightScreenEffect_
- ld b, BANK(ReflectLightScreenEffect_)
- jp Bankswitch
-
-NothingHappenedText: ; 3fb3e (f:7b3e)
+PayDayEffect:
+ jpab PayDayEffect_
+
+ConversionEffect:
+ jpab ConversionEffect_
+
+HazeEffect:
+ jpab HazeEffect_
+
+HealEffect:
+ jpab HealEffect_
+
+TransformEffect:
+ jpab TransformEffect_
+
+ReflectLightScreenEffect:
+ jpab ReflectLightScreenEffect_
+
+NothingHappenedText:
TX_FAR _NothingHappenedText
db "@"
-PrintNoEffectText: ; 3fb43 (f:7b43)
+PrintNoEffectText:
ld hl, NoEffectText
jp PrintText
-NoEffectText: ; 3fb49 (f:7b49)
+NoEffectText:
TX_FAR _NoEffectText
db "@"
-ConditionalPrintButItFailed: ; 3fb4e (f:7b4e)
+ConditionalPrintButItFailed:
ld a, [wMoveDidntMiss]
and a
ret nz ; return if the side effect failed, yet the attack was successful
-PrintButItFailedText_: ; 3fb53 (f:7b53)
+PrintButItFailedText_:
ld hl, ButItFailedText
jp PrintText
-ButItFailedText: ; 3fb59 (f:7b59)
+ButItFailedText:
TX_FAR _ButItFailedText
db "@"
-PrintDidntAffectText: ; 3fb5e (f:7b5e)
+PrintDidntAffectText:
ld hl, DidntAffectText
jp PrintText
-DidntAffectText: ; 3fb64 (f:7b64)
+DidntAffectText:
TX_FAR _DidntAffectText
db "@"
-IsUnaffectedText: ; 3fb69 (f:7b69)
+IsUnaffectedText:
TX_FAR _IsUnaffectedText
db "@"
-PrintMayNotAttackText: ; 3fb6e (f:7b6e)
+PrintMayNotAttackText:
ld hl, ParalyzedMayNotAttackText
jp PrintText
-ParalyzedMayNotAttackText: ; 3fb74 (f:7b74)
+ParalyzedMayNotAttackText:
TX_FAR _ParalyzedMayNotAttackText
db "@"
-CheckTargetSubstitute: ; 3fb79 (f:7b79)
+CheckTargetSubstitute:
push hl
- ld hl, W_ENEMYBATTSTATUS2
- ld a, [H_WHOSETURN]
+ ld hl, wEnemyBattleStatus2
+ ld a, [H_WHOSETURN]
and a
jr z, .next1
- ld hl, W_PLAYERBATTSTATUS2
+ ld hl, wPlayerBattleStatus2
.next1
- bit HasSubstituteUp, [hl]
+ bit HasSubstituteUp, [hl]
pop hl
ret
-PlayCurrentMoveAnimation2: ; 3fb89 (f:7b89)
+PlayCurrentMoveAnimation2:
; animation at MOVENUM will be played unless MOVENUM is 0
; plays wAnimationType 3 or 6
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVENUM]
+ ld a, [wPlayerMoveNum]
jr z, .notEnemyTurn
- ld a, [W_ENEMYMOVENUM]
+ ld a, [wEnemyMoveNum]
.notEnemyTurn
and a
ret z
-PlayBattleAnimation2: ; 3fb96 (f:7b96)
+PlayBattleAnimation2:
; play animation ID at a and animation type 6 or 3
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
ld a, [H_WHOSETURN]
and a
ld a, $6
@@ -8685,26 +8689,26 @@ PlayBattleAnimation2: ; 3fb96 (f:7b96)
ld [wAnimationType], a
jp PlayBattleAnimationGotID
-PlayCurrentMoveAnimation: ; 3fba8 (f:7ba8)
+PlayCurrentMoveAnimation:
; animation at MOVENUM will be played unless MOVENUM is 0
; resets wAnimationType
xor a
ld [wAnimationType], a
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVENUM]
+ ld a, [wPlayerMoveNum]
jr z, .notEnemyTurn
- ld a, [W_ENEMYMOVENUM]
+ ld a, [wEnemyMoveNum]
.notEnemyTurn
and a
ret z
-PlayBattleAnimation: ; 3fbb9 (f:7bb9)
+PlayBattleAnimation:
; play animation ID at a and predefined animation type
- ld [W_ANIMATIONID], a
+ ld [wAnimationID], a
-PlayBattleAnimationGotID: ; 3fbbc (f:7bbc)
-; play animation at W_ANIMATIONID
+PlayBattleAnimationGotID:
+; play animation at wAnimationID
push hl
push de
push bc
diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm
index ecf5040b..e23a85ba 100644
--- a/engine/battle/decrement_pp.asm
+++ b/engine/battle/decrement_pp.asm
@@ -1,23 +1,23 @@
-DecrementPP: ; 68000 (1a:4000)
+DecrementPP:
; after using a move, decrement pp in battle and (if not transformed?) in party
ld a, [de]
cp a, STRUGGLE
ret z ; if the pokemon is using "struggle", there's nothing to do
; we don't decrement PP for "struggle"
- ld hl, W_PLAYERBATTSTATUS1
- ld a, [hli] ; load the W_PLAYERBATTSTATUS1 pokemon status flags and increment hl to load the
- ; W_PLAYERBATTSTATUS2 status flags later
+ ld hl, wPlayerBattleStatus1
+ ld a, [hli] ; load the wPlayerBattleStatus1 pokemon status flags and increment hl to load the
+ ; wPlayerBattleStatus2 status flags later
and a, (1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << AttackingMultipleTimes)
ret nz ; if any of these statuses are true, don't decrement PP
- bit UsingRage, [hl]
+ bit UsingRage, [hl]
ret nz ; don't decrement PP either if Pokemon is using Rage
ld hl, wBattleMonPP ; PP of first move (in battle)
-
-; decrement PP in the battle struct
- call .DecrementPP
-
-; decrement PP in the party struct
- ld a, [W_PLAYERBATTSTATUS3]
+
+; decrement PP in the battle struct
+ call .DecrementPP
+
+; decrement PP in the party struct
+ ld a, [wPlayerBattleStatus3]
bit Transformed, a
ret nz ; Return if transformed. Pokemon Red stores the "current pokemon's" PP
; separately from the "Pokemon in your party's" PP. This is
@@ -31,9 +31,9 @@ DecrementPP: ; 68000 (1a:4000)
ld hl, wPartyMon1PP ; PP of first move (in party)
ld a, [wPlayerMonNumber] ; which mon in party is active
- ld bc, wPartyMon2 - wPartyMon1
+ ld bc, wPartyMon2 - wPartyMon1
call AddNTimes ; calculate address of the mon to modify
-.DecrementPP
+.DecrementPP:
ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use?
ld c, a
ld b, 0
diff --git a/engine/battle/display_effectiveness.asm b/engine/battle/display_effectiveness.asm
index 17f0bd5b..85f2bc3e 100644
--- a/engine/battle/display_effectiveness.asm
+++ b/engine/battle/display_effectiveness.asm
@@ -1,4 +1,4 @@
-DisplayEffectiveness: ; 2fb7b (b:7b7b)
+DisplayEffectiveness:
ld a, [wDamageMultipliers]
and a, $7F
cp a, $0A
@@ -9,10 +9,10 @@ DisplayEffectiveness: ; 2fb7b (b:7b7b)
.done
jp PrintText
-SuperEffectiveText: ; 2fb8e (b:7b8e)
+SuperEffectiveText:
TX_FAR _SuperEffectiveText
db "@"
-NotVeryEffectiveText: ; 2fb93 (b:7b93)
+NotVeryEffectiveText:
TX_FAR _NotVeryEffectiveText
db "@"
diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm
index fce3701c..f44d64f5 100644
--- a/engine/battle/draw_hud_pokeball_gfx.asm
+++ b/engine/battle/draw_hud_pokeball_gfx.asm
@@ -1,50 +1,50 @@
-DrawAllPokeballs: ; 3a849 (e:6849)
+DrawAllPokeballs:
call LoadPartyPokeballGfx
call SetupOwnPartyPokeballs
- ld a, [W_ISINBATTLE] ; W_ISINBATTLE
+ ld a, [wIsInBattle]
dec a
ret z ; return if wild pokémon
jp SetupEnemyPartyPokeballs
-DrawEnemyPokeballs: ; 0x3a857
+DrawEnemyPokeballs:
call LoadPartyPokeballGfx
jp SetupEnemyPartyPokeballs
-LoadPartyPokeballGfx: ; 3a85d (e:685d)
- ld de, PokeballTileGraphics ; $697e
+LoadPartyPokeballGfx:
+ ld de, PokeballTileGraphics
ld hl, vSprites + $310
- ld bc, (BANK(PokeballTileGraphics) << 8) + $04
+ lb bc, BANK(PokeballTileGraphics), (PokeballTileGraphicsEnd - PokeballTileGraphics) / $10
jp CopyVideoData
-SetupOwnPartyPokeballs: ; 3a869 (e:6869)
+SetupOwnPartyPokeballs:
call PlacePlayerHUDTiles
ld hl, wPartyMon1
- ld de, wPartyCount ; wPartyCount
+ ld de, wPartyCount
call SetupPokeballs
ld a, $60
- ld hl, W_BASECOORDX ; wd081
+ ld hl, wBaseCoordX
ld [hli], a
ld [hl], a
- ld a, $8
- ld [wTrainerEngageDistance], a
+ ld a, 8
+ ld [wHUDPokeballGfxOffsetX], a
ld hl, wOAMBuffer
jp WritePokeballOAMData
-SetupEnemyPartyPokeballs: ; 3a887 (e:6887)
+SetupEnemyPartyPokeballs:
call PlaceEnemyHUDTiles
ld hl, wEnemyMons
- ld de, wEnemyPartyCount ; wEnemyPartyCount
+ ld de, wEnemyPartyCount
call SetupPokeballs
- ld hl, W_BASECOORDX ; wd081
+ ld hl, wBaseCoordX
ld a, $48
ld [hli], a
ld [hl], $20
- ld a, $f8
- ld [wTrainerEngageDistance], a
+ ld a, -8
+ ld [wHUDPokeballGfxOffsetX], a
ld hl, wOAMBuffer + PARTY_LENGTH * 4
jp WritePokeballOAMData
-SetupPokeballs: ; 0x3a8a6
+SetupPokeballs:
ld a, [de]
push af
ld de, wBuffer
@@ -66,7 +66,7 @@ SetupPokeballs: ; 0x3a8a6
jr nz, .monloop
ret
-PickPokeball: ; 3a8c2 (e:68c2)
+PickPokeball:
inc hl
ld a, [hli]
and a
@@ -90,96 +90,96 @@ PickPokeball: ; 3a8c2 (e:68c2)
.done
ld a, b
ld [de], a
- ld bc, $0028 ; rest of mon struct
- add hl, bc
+ ld bc, wPartyMon2 - wPartyMon1Status
+ add hl, bc ; next mon struct
ret
-WritePokeballOAMData: ; 3a8e1 (e:68e1)
+WritePokeballOAMData:
ld de, wBuffer
ld c, PARTY_LENGTH
.loop
- ld a, [W_BASECOORDY] ; wd082
+ ld a, [wBaseCoordY]
ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
+ ld a, [wBaseCoordX]
ld [hli], a
ld a, [de]
ld [hli], a
xor a
ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
+ ld a, [wBaseCoordX]
ld b, a
- ld a, [wTrainerEngageDistance]
+ ld a, [wHUDPokeballGfxOffsetX]
add b
- ld [W_BASECOORDX], a ; wd081
+ ld [wBaseCoordX], a
inc de
dec c
jr nz, .loop
ret
-PlacePlayerHUDTiles: ; 3a902 (e:6902)
- ld hl, PlayerBattleHUDGraphicsTiles ; $6916
- ld de, wTrainerFacingDirection
+PlacePlayerHUDTiles:
+ ld hl, PlayerBattleHUDGraphicsTiles
+ ld de, wHUDGraphicsTiles
ld bc, $3
call CopyData
- hlCoord 18, 10
- ld de, rIE ; $ffff
+ coord hl, 18, 10
+ ld de, -1
jr PlaceHUDTiles
-PlayerBattleHUDGraphicsTiles: ; 3a916 (e:6916)
+PlayerBattleHUDGraphicsTiles:
; The tile numbers for specific parts of the battle display for the player's pokemon
db $73 ; unused ($73 is hardcoded into the routine that uses these bytes)
db $77 ; lower-right corner tile of the HUD
db $6F ; lower-left triangle tile of the HUD
-PlaceEnemyHUDTiles: ; 3a919 (e:6919)
- ld hl, EnemyBattleHUDGraphicsTiles ; $692d
- ld de, wTrainerFacingDirection
+PlaceEnemyHUDTiles:
+ ld hl, EnemyBattleHUDGraphicsTiles
+ ld de, wHUDGraphicsTiles
ld bc, $3
call CopyData
- hlCoord 1, 2
+ coord hl, 1, 2
ld de, $1
jr PlaceHUDTiles
-EnemyBattleHUDGraphicsTiles: ; 3a92d (e:692d)
+EnemyBattleHUDGraphicsTiles:
; The tile numbers for specific parts of the battle display for the enemy
db $73 ; unused ($73 is hardcoded in the routine that uses these bytes)
db $74 ; lower-left corner tile of the HUD
db $78 ; lower-right triangle tile of the HUD
-PlaceHUDTiles: ; 3a930 (e:6930)
+PlaceHUDTiles:
ld [hl], $73
- ld bc, $14
+ ld bc, SCREEN_WIDTH
add hl, bc
- ld a, [wTrainerScreenY]
+ ld a, [wHUDGraphicsTiles + 1] ; leftmost tile
ld [hl], a
- ld a, $8
-.asm_3a93c
+ ld a, 8
+.loop
add hl, de
ld [hl], $76
dec a
- jr nz, .asm_3a93c
+ jr nz, .loop
add hl, de
- ld a, [wTrainerScreenX]
+ ld a, [wHUDGraphicsTiles + 2] ; rightmost tile
ld [hl], a
ret
-SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948)
+SetupPlayerAndEnemyPokeballs:
call LoadPartyPokeballGfx
- ld hl, wPartyMon1Species ; wPartyMon1Species (aliases: wPartyMon1)
- ld de, wPartyCount ; wPartyCount
+ ld hl, wPartyMons
+ ld de, wPartyCount
call SetupPokeballs
- ld hl, W_BASECOORDX ; wd081
+ ld hl, wBaseCoordX
ld a, $50
ld [hli], a
ld [hl], $40
- ld a, $8
- ld [wTrainerEngageDistance], a
+ ld a, 8
+ ld [wHUDPokeballGfxOffsetX], a
ld hl, wOAMBuffer
call WritePokeballOAMData
- ld hl, wEnemyMons ; wEnemyMon1Species
- ld de, wEnemyPartyCount ; wEnemyPartyCount
+ ld hl, wEnemyMons
+ ld de, wEnemyPartyCount
call SetupPokeballs
- ld hl, W_BASECOORDX ; wd081
+ ld hl, wBaseCoordX
ld a, $50
ld [hli], a
ld [hl], $68
@@ -187,5 +187,6 @@ SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948)
jp WritePokeballOAMData
; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (faited) and pokeball slot (no mon)
-PokeballTileGraphics:: ; 3a97e (e:697e)
+PokeballTileGraphics::
INCBIN "gfx/pokeball.2bpp"
+PokeballTileGraphicsEnd:
diff --git a/engine/battle/end_of_battle.asm b/engine/battle/end_of_battle.asm
index f03dd07f..c77e3b39 100644..100755
--- a/engine/battle/end_of_battle.asm
+++ b/engine/battle/end_of_battle.asm
@@ -1,4 +1,4 @@
-EndOfBattle: ; 137aa (4:77aa)
+EndOfBattle:
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
@@ -19,9 +19,9 @@ EndOfBattle: ; 137aa (4:77aa)
jr z, .placeWinOrLoseString
ld de, DrawText
.placeWinOrLoseString
- hlCoord 6, 8
+ coord hl, 6, 8
call PlaceString
- ld c, $c8
+ ld c, 200
call DelayFrames
jr .evolution
.notLinkBattle
@@ -41,20 +41,20 @@ EndOfBattle: ; 137aa (4:77aa)
call PrintText
.evolution
xor a
- ld [wccd4], a
+ ld [wForceEvolution], a
predef EvolutionAfterBattle
.resetVariables
xor a
ld [wLowHealthAlarm], a ;disable low health alarm
- ld [wc02a], a
- ld [W_ISINBATTLE], a
- ld [W_BATTLETYPE], a
- ld [W_MOVEMISSED], a
- ld [W_CUROPPONENT], a
- ld [wd11f], a
+ ld [wChannelSoundIDs + Ch4], a
+ ld [wIsInBattle], a
+ ld [wBattleType], a
+ ld [wMoveMissed], a
+ ld [wCurOpponent], a
+ ld [wForcePlayerToChooseMon], a
ld [wNumRunAttempts], a
ld [wEscapedFromBattle], a
- ld hl, wcc2b
+ ld hl, wPartyAndBillsPCSavedMenuItem
ld [hli], a
ld [hli], a
ld [hli], a
@@ -74,15 +74,15 @@ EndOfBattle: ; 137aa (4:77aa)
ld [wDestinationWarpID], a
ret
-YouWinText: ; 13853 (4:7853)
+YouWinText:
db "YOU WIN@"
-YouLoseText: ; 1385b (4:785b)
+YouLoseText:
db "YOU LOSE@"
-DrawText: ; 13864 (4:7864)
+DrawText:
db " DRAW@"
-PickUpPayDayMoneyText: ; 1386b (4:786b)
+PickUpPayDayMoneyText:
TX_FAR _PickUpPayDayMoneyText
- db "@" \ No newline at end of file
+ db "@"
diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm
index 9bd67654..24748338 100644
--- a/engine/battle/experience.asm
+++ b/engine/battle/experience.asm
@@ -1,4 +1,4 @@
-GainExperience: ; 5524f (15:524f)
+GainExperience:
ld a, [wLinkState]
cp LINK_STATE_BATTLING
ret z ; return if link battle
@@ -15,7 +15,7 @@ GainExperience: ; 5524f (15:524f)
ld hl, wPartyGainExpFlags
ld a, [wWhichPokemon]
ld c, a
- ld b, $2
+ ld b, FLAG_TEST
predef FlagActionPredef
ld a, c
and a ; is mon's gain exp flag set?
@@ -26,7 +26,7 @@ GainExperience: ; 5524f (15:524f)
ld d, h
ld e, l
ld hl, wEnemyMonBaseStats
- ld c, $5
+ ld c, NUM_STATS
.gainStatExpLoop
ld a, [hli]
ld b, a ; enemy mon base stat
@@ -49,11 +49,11 @@ GainExperience: ; 5524f (15:524f)
ld [de], a
.nextBaseStat
dec c
- jr z, .asm_552a1
+ jr z, .statExpDone
inc de
inc de
jr .gainStatExpLoop
-.asm_552a1
+.statExpDone
xor a
ld [H_MULTIPLICAND], a
ld [H_MULTIPLICAND + 1], a
@@ -66,7 +66,7 @@ GainExperience: ; 5524f (15:524f)
ld [H_DIVISOR], a
ld b, 4
call Divide
- ld hl, -((wPartyMon1HPExp + 1) - wPartyMon1OTID + 4 * 2)
+ ld hl, wPartyMon1OTID - (wPartyMon1DVs - 1)
add hl, de
ld b, [hl] ; party mon OTID
inc hl
@@ -76,14 +76,14 @@ GainExperience: ; 5524f (15:524f)
ld b, [hl]
ld a, [wPlayerID + 1]
cp b
- ld a, $0
+ ld a, 0
jr z, .next
.tradedMon
call BoostExp ; traded mon exp boost
- ld a, $1
+ ld a, 1
.next
ld [wGainBoostedExp], a
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a ; is it a trainer battle?
call nz, BoostExp ; if so, boost exp
inc hl
@@ -92,12 +92,12 @@ GainExperience: ; 5524f (15:524f)
; add the gained exp to the party mon's exp
ld b, [hl]
ld a, [H_QUOTIENT + 3]
- ld [wcf4c], a
+ ld [wExpAmountGained + 1], a
add b
ld [hld], a
ld b, [hl]
ld a, [H_QUOTIENT + 2]
- ld [wcf4b], a
+ ld [wExpAmountGained], a
adc b
ld [hl], a
jr nc, .noCarry
@@ -119,11 +119,11 @@ GainExperience: ; 5524f (15:524f)
ld d, MAX_LEVEL
callab CalcExperience ; get max exp
; compare max exp with current exp
- ld a, [$ff96]
+ ld a, [hExperience]
ld b, a
- ld a, [$ff97]
+ ld a, [hExperience + 1]
ld c, a
- ld a, [$ff98]
+ ld a, [hExperience + 2]
ld d, a
pop hl
ld a, [hld]
@@ -148,8 +148,8 @@ GainExperience: ; 5524f (15:524f)
call GetPartyMonName
ld hl, GainedText
call PrintText
- xor a ; party mon data
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
call LoadMonData
pop hl
ld bc, wPartyMon1Level - wPartyMon1Exp
@@ -160,11 +160,11 @@ GainExperience: ; 5524f (15:524f)
ld a, [hl] ; current level
cp d
jp z, .nextMon ; if level didn't change, go to next mon
- ld a, [W_CURENEMYLVL]
+ ld a, [wCurEnemyLVL]
push af
push hl
ld a, d
- ld [W_CURENEMYLVL], a
+ ld [wCurEnemyLVL], a
ld [hl], a
ld bc, wPartyMon1Species - wPartyMon1Level
add hl, bc
@@ -220,19 +220,19 @@ GainExperience: ; 5524f (15:524f)
add hl, bc
push hl
ld de, wBattleMonLevel
- ld bc, $b ; size of stats
+ ld bc, 1 + NUM_STATS * 2 ; size of stats
call CopyData
pop hl
- ld a, [W_PLAYERBATTSTATUS3]
+ ld a, [wPlayerBattleStatus3]
bit 3, a ; is the mon transformed?
jr nz, .recalcStatChanges
; the mon is not transformed, so update the unmodified stats
ld de, wPlayerMonUnmodifiedLevel
- ld bc, $b
+ ld bc, 1 + NUM_STATS * 2
call CopyData
.recalcStatChanges
- xor a
- ld [wd11e], a
+ xor a ; battle mon
+ ld [wCalculateWhoseStats], a
callab CalculateModifiedStats
callab ApplyBurnAndParalysisPenaltiesToPlayer
callab ApplyBadgeStatBoosts
@@ -242,26 +242,26 @@ GainExperience: ; 5524f (15:524f)
.printGrewLevelText
ld hl, GrewLevelText
call PrintText
- xor a ; party mon data
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
call LoadMonData
ld d, $1
callab PrintStatsBox
call WaitForTextScrollButtonPress
call LoadScreenTilesFromBuffer1
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
ld a, [wd0b5]
ld [wd11e], a
predef LearnMoveFromLevelUp
- ld hl, wccd3
+ ld hl, wCanEvolveFlags
ld a, [wWhichPokemon]
ld c, a
- ld b, $1
+ ld b, FLAG_SET
predef FlagActionPredef
pop hl
pop af
- ld [W_CURENEMYLVL], a
+ ld [wCurEnemyLVL], a
.nextMon
ld a, [wPartyCount]
@@ -281,7 +281,7 @@ GainExperience: ; 5524f (15:524f)
ld [hl], a ; clear gain exp flags
ld a, [wPlayerMonNumber]
ld c, a
- ld b, $1
+ ld b, FLAG_SET
push bc
predef FlagActionPredef ; set the gain exp flag for the mon that is currently out
ld hl, wPartyFoughtCurrentEnemyFlags
@@ -291,7 +291,7 @@ GainExperience: ; 5524f (15:524f)
predef_jump FlagActionPredef ; set the fought current enemy flag for the mon that is currently out
; divide enemy base stats, catch rate, and base exp by the number of mons gaining exp
-DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c)
+DivideExpDataByNumMonsGainingExp:
ld a, [wPartyGainExpFlags]
ld b, a
xor a
@@ -308,7 +308,7 @@ DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c)
ret c ; return if only one mon is gaining exp
ld [wd11e], a ; store number of mons gaining exp
ld hl, wEnemyMonBaseStats
- ld c, $7
+ ld c, wEnemyMonBaseExp + 1 - wEnemyMonBaseStats
.divideLoop
xor a
ld [H_DIVIDEND], a
@@ -325,7 +325,7 @@ DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c)
ret
; multiplies exp by 1.5
-BoostExp: ; 5549f (15:549f)
+BoostExp:
ld a, [H_QUOTIENT + 2]
ld b, a
ld a, [H_QUOTIENT + 3]
@@ -339,9 +339,9 @@ BoostExp: ; 5549f (15:549f)
ld [H_QUOTIENT + 2], a
ret
-GainedText: ; 554b2 (15:54b2)
+GainedText:
TX_FAR _GainedText
- db $08 ; asm
+ TX_ASM
ld a, [wBoostExpByExpAll]
ld hl, WithExpAllText
and a
@@ -353,20 +353,20 @@ GainedText: ; 554b2 (15:54b2)
ld hl, BoostedText
ret
-WithExpAllText: ; 554cb (15:54cb)
+WithExpAllText:
TX_FAR _WithExpAllText
- db $08 ; asm
+ TX_ASM
ld hl, ExpPointsText
ret
-BoostedText: ; 554d4 (15:54d4)
+BoostedText:
TX_FAR _BoostedText
-ExpPointsText: ; 554d8 (15:54d8)
+ExpPointsText:
TX_FAR _ExpPointsText
db "@"
-GrewLevelText: ; 554dd (15:54dd)
+GrewLevelText:
TX_FAR _GrewLevelText
- db $0b
+ TX_SFX_LEVEL_UP
db "@"
diff --git a/engine/battle/get_trainer_name.asm b/engine/battle/get_trainer_name.asm
index 961f25cf..36ca019e 100644
--- a/engine/battle/get_trainer_name.asm
+++ b/engine/battle/get_trainer_name.asm
@@ -1,16 +1,16 @@
-GetTrainerName_: ; 13a58 (4:7a58)
- ld hl, W_GRASSRATE
+GetTrainerName_:
+ ld hl, wGrassRate
ld a, [wLinkState]
and a
- jr nz, .rival
- ld hl, W_RIVALNAME
- ld a, [W_TRAINERCLASS]
+ jr nz, .foundName
+ ld hl, wRivalName
+ ld a, [wTrainerClass]
cp SONY1
- jr z, .rival
+ jr z, .foundName
cp SONY2
- jr z, .rival
+ jr z, .foundName
cp SONY3
- jr z, .rival
+ jr z, .foundName
ld [wd0b5], a
ld a, TRAINER_NAME
ld [wNameListType], a
@@ -18,7 +18,7 @@ GetTrainerName_: ; 13a58 (4:7a58)
ld [wPredefBank], a
call GetName
ld hl, wcd6d
-.rival
- ld de, W_TRAINERNAME
+.foundName
+ ld de, wTrainerName
ld bc, $d
jp CopyData
diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm
index 73d3bcc2..7adb20d8 100644
--- a/engine/battle/ghost_marowak_anim.asm
+++ b/engine/battle/ghost_marowak_anim.asm
@@ -1,21 +1,21 @@
-MarowakAnim: ; 708ca (1c:48ca)
+MarowakAnim:
; animate the ghost being unveiled as a Marowak
ld a, $e4
ld [rOBP1], a
call CopyMonPicFromBGToSpriteVRAM ; cover the BG ghost pic with a sprite ghost pic that looks the same
; now that the ghost pic is being displayed using sprites, clear the ghost pic from the BG tilemap
- hlCoord 12, 0
- ld bc, $707
+ coord hl, 12, 0
+ lb bc, 7, 7
call ClearScreenArea
call Delay3
xor a
ld [H_AUTOBGTRANSFERENABLED], a ; disable BG transfer so we don't see the Marowak too soon
; replace ghost pic with Marowak in BG
ld a, MAROWAK
- ld [wHPBarMaxHP], a
+ ld [wChangeMonPicEnemyTurnSpecies], a
ld a, $1
ld [H_WHOSETURN], a
- callab Func_79793
+ callab ChangeMonPic
; alternate between black and light grey 8 times.
; this makes the ghost's body appear to flash
ld d, $80
@@ -49,28 +49,28 @@ MarowakAnim: ; 708ca (1c:48ca)
jp ClearSprites
; copies a mon pic's from background VRAM to sprite VRAM and sets up OAM
-CopyMonPicFromBGToSpriteVRAM: ; 7092a (1c:492a)
+CopyMonPicFromBGToSpriteVRAM:
ld de, vFrontPic
ld hl, vSprites
ld bc, 7 * 7
call CopyVideoData
ld a, $10
- ld [W_BASECOORDY], a
+ ld [wBaseCoordY], a
ld a, $70
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
ld hl, wOAMBuffer
- ld bc, $606
+ lb bc, 6, 6
ld d, $8
.oamLoop
push bc
- ld a, [W_BASECOORDY]
+ ld a, [wBaseCoordY]
ld e, a
.oamInnerLoop
ld a, e
add $8
ld e, a
ld [hli], a
- ld a, [W_BASECOORDX]
+ ld a, [wBaseCoordX]
ld [hli], a
ld a, d
ld [hli], a
@@ -80,9 +80,9 @@ CopyMonPicFromBGToSpriteVRAM: ; 7092a (1c:492a)
dec c
jr nz, .oamInnerLoop
inc d
- ld a, [W_BASECOORDX]
+ ld a, [wBaseCoordX]
add $8
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
pop bc
dec b
jr nz, .oamLoop
diff --git a/engine/battle/init_battle_variables.asm b/engine/battle/init_battle_variables.asm
index 457cc4e1..bdd5d8f4 100644
--- a/engine/battle/init_battle_variables.asm
+++ b/engine/battle/init_battle_variables.asm
@@ -1,10 +1,10 @@
-InitBattleVariables: ; 525af (14:65af)
+InitBattleVariables:
ld a, [hTilesetType]
- ld [wd0d4], a
+ ld [wSavedTilesetType], a
xor a
- ld [wcd6a], a
+ ld [wActionResultOrTookBattleTurn], a
ld [wBattleResult], a
- ld hl, wcc2b
+ ld hl, wPartyAndBillsPCSavedMenuItem
ld [hli], a
ld [hli], a
ld [hli], a
@@ -13,28 +13,26 @@ InitBattleVariables: ; 525af (14:65af)
ld [wCriticalHitOrOHKO], a
ld [wBattleMonSpecies], a
ld [wPartyGainExpFlags], a
- ld [wPlayerMonNumber], a
+ ld [wPlayerMonNumber], a
ld [wEscapedFromBattle], a
ld [wMapPalOffset], a
- ld hl, wcf1d
- ld [hli], a
- ld [hl], a
- ld hl, wccd3
+ ld hl, wPlayerHPBarColor
+ ld [hli], a ; wPlayerHPBarColor
+ ld [hl], a ; wEnemyHPBarColor
+ ld hl, wCanEvolveFlags
ld b, $3c
.loop
ld [hli], a
dec b
jr nz, .loop
- inc a
- ld [wccd9], a
- ld a, [W_CURMAP]
+ inc a ; POUND
+ ld [wTestBattlePlayerSelectedMove], a
+ ld a, [wCurMap]
cp SAFARI_ZONE_EAST
jr c, .notSafariBattle
cp SAFARI_ZONE_REST_HOUSE_1
jr nc, .notSafariBattle
- ld a, $2 ; safari battle
- ld [W_BATTLETYPE], a
+ ld a, BATTLE_TYPE_SAFARI
+ ld [wBattleType], a
.notSafariBattle
- ld hl, PlayBattleMusic
- ld b, BANK(PlayBattleMusic)
- jp Bankswitch
+ jpab PlayBattleMusic
diff --git a/engine/battle/link_battle_versus_text.asm b/engine/battle/link_battle_versus_text.asm
index 7320da29..76559117 100644
--- a/engine/battle/link_battle_versus_text.asm
+++ b/engine/battle/link_battle_versus_text.asm
@@ -1,18 +1,18 @@
; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names
-DisplayLinkBattleVersusTextBox: ; 372d6 (d:72d6)
+DisplayLinkBattleVersusTextBox:
call LoadTextBoxTilePatterns
- hlCoord 3, 4
- ld b, $7
- ld c, $c
+ coord hl, 3, 4
+ ld b, 7
+ ld c, 12
call TextBoxBorder
- hlCoord 4, 5
+ coord hl, 4, 5
ld de, wPlayerName
call PlaceString
- hlCoord 4, 10
+ coord hl, 4, 10
ld de, wLinkEnemyTrainerName
call PlaceString
; place bold "VS" tiles between the names
- hlCoord 9, 8
+ coord hl, 9, 8
ld a, $69
ld [hli], a
ld [hl], $6a
diff --git a/engine/battle/moveEffects/conversion_effect.asm b/engine/battle/moveEffects/conversion_effect.asm
index 511df2fd..9c347876 100644
--- a/engine/battle/moveEffects/conversion_effect.asm
+++ b/engine/battle/moveEffects/conversion_effect.asm
@@ -1,18 +1,19 @@
-ConversionEffect_: ; 139a3 (4:79a3)
+ConversionEffect_:
ld hl, wEnemyMonType1
ld de, wBattleMonType1
ld a, [H_WHOSETURN]
and a
- ld a, [W_ENEMYBATTSTATUS1]
- jr z, .asm_139b8
+ ld a, [wEnemyBattleStatus1]
+ jr z, .conversionEffect
push hl
ld h, d
ld l, e
pop de
- ld a, [W_PLAYERBATTSTATUS1]
-.asm_139b8
+ ld a, [wPlayerBattleStatus1]
+.conversionEffect
bit Invulnerable, a ; is mon immune to typical attacks (dig/fly)
jr nz, PrintButItFailedText
+; copy target's types to user
ld a, [hli]
ld [de], a
inc de
@@ -23,12 +24,12 @@ ConversionEffect_: ; 139a3 (4:79a3)
ld hl, ConvertedTypeText
jp PrintText
-ConvertedTypeText: ; 139cd (4:79cd)
+ConvertedTypeText:
TX_FAR _ConvertedTypeText
db "@"
-PrintButItFailedText: ; 139d2 (4:79d2)
+PrintButItFailedText:
ld hl, PrintButItFailedText_
-CallBankF: ; 139d5 (4:79d5)
+CallBankF:
ld b, BANK(PrintButItFailedText_)
jp Bankswitch
diff --git a/engine/battle/moveEffects/drain_hp_effect.asm b/engine/battle/moveEffects/drain_hp_effect.asm
index 517d53d1..e5f4681a 100644
--- a/engine/battle/moveEffects/drain_hp_effect.asm
+++ b/engine/battle/moveEffects/drain_hp_effect.asm
@@ -1,5 +1,5 @@
-DrainHPEffect_: ; 783f (1:783f)
- ld hl, W_DAMAGE
+DrainHPEffect_:
+ ld hl, wDamage
ld a, [hl]
srl a ; divide damage by 2
ld [hli], a
@@ -17,8 +17,8 @@ DrainHPEffect_: ; 783f (1:783f)
ld a, [H_WHOSETURN]
and a
jp z, .addDamageToAttackerHP
- ld hl, wEnemyMonHP
- ld de, wEnemyMonMaxHP
+ ld hl, wEnemyMonHP
+ ld de, wEnemyMonMaxHP
.addDamageToAttackerHP
ld bc, wHPBarOldHP+1
; copy current HP to wHPBarOldHP
@@ -36,12 +36,12 @@ DrainHPEffect_: ; 783f (1:783f)
dec bc
ld [bc], a
; add damage to attacker's HP and copy new HP to wHPBarNewHP
- ld a, [W_DAMAGE + 1]
+ ld a, [wDamage + 1]
ld b, [hl]
add b
ld [hld], a
ld [wHPBarNewHP], a
- ld a, [W_DAMAGE]
+ ld a, [wDamage]
ld b, [hl]
adc b
ld [hli], a
@@ -71,10 +71,10 @@ DrainHPEffect_: ; 783f (1:783f)
.next
ld a, [H_WHOSETURN]
and a
- hlCoord 10, 9
+ coord hl, 10, 9
ld a, $1
jr z, .next2
- hlCoord 2, 2
+ coord hl, 2, 2
xor a
.next2
ld [wHPBarType], a
@@ -85,9 +85,9 @@ DrainHPEffect_: ; 783f (1:783f)
ld hl, SuckedHealthText
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVEEFFECT]
+ ld a, [wPlayerMoveEffect]
jr z, .next3
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
.next3
cp DREAM_EATER_EFFECT
jr nz, .printText
@@ -95,10 +95,10 @@ DrainHPEffect_: ; 783f (1:783f)
.printText
jp PrintText
-SuckedHealthText: ; 78dc (1:78dc)
+SuckedHealthText:
TX_FAR _SuckedHealthText
db "@"
-DreamWasEatenText: ; 78e1 (1:78e1)
+DreamWasEatenText:
TX_FAR _DreamWasEatenText
db "@"
diff --git a/engine/battle/moveEffects/focus_energy_effect.asm b/engine/battle/moveEffects/focus_energy_effect.asm
index f01e61cc..69301d8e 100644
--- a/engine/battle/moveEffects/focus_energy_effect.asm
+++ b/engine/battle/moveEffects/focus_energy_effect.asm
@@ -1,9 +1,9 @@
-FocusEnergyEffect_: ; 27f86 (9:7f86)
- ld hl, W_PLAYERBATTSTATUS2
+FocusEnergyEffect_:
+ ld hl, wPlayerBattleStatus2
ld a, [H_WHOSETURN]
and a
jr z, .notEnemy
- ld hl, W_ENEMYBATTSTATUS2
+ ld hl, wEnemyBattleStatus2
.notEnemy
bit GettingPumped, [hl] ; is mon already using focus energy?
jr nz, .alreadyUsing
@@ -12,13 +12,11 @@ FocusEnergyEffect_: ; 27f86 (9:7f86)
ld hl, GettingPumpedText
jp PrintText
.alreadyUsing
- ld c, $32
+ ld c, 50
call DelayFrames
- ld hl, PrintButItFailedText_
- ld b, BANK(PrintButItFailedText_)
- jp Bankswitch
+ jpab PrintButItFailedText_
-GettingPumpedText: ; 27fb3 (9:7fb3)
- db $0a
+GettingPumpedText:
+ TX_DELAY
TX_FAR _GettingPumpedText
db "@"
diff --git a/engine/battle/moveEffects/haze_effect.asm b/engine/battle/moveEffects/haze_effect.asm
index 2343e784..06907bcc 100644
--- a/engine/battle/moveEffects/haze_effect.asm
+++ b/engine/battle/moveEffects/haze_effect.asm
@@ -1,59 +1,64 @@
-HazeEffect_: ; 139da (4:79da)
+HazeEffect_:
ld a, $7
+; store 7 on every stat mod
ld hl, wPlayerMonAttackMod
call ResetStatMods
ld hl, wEnemyMonAttackMod
call ResetStatMods
+; copy unmodified stats to battle stats
ld hl, wPlayerMonUnmodifiedAttack
ld de, wBattleMonAttack
call ResetStats
ld hl, wEnemyMonUnmodifiedAttack
ld de, wEnemyMonAttack
call ResetStats
+; cure non-volatile status, but only for the target
ld hl, wEnemyMonStatus
ld de, wEnemySelectedMove
ld a, [H_WHOSETURN]
and a
- jr z, .asm_13a09
+ jr z, .cureStatuses
ld hl, wBattleMonStatus
- dec de
+ dec de ; wPlayerSelectedMove
-.asm_13a09
+.cureStatuses
ld a, [hl]
ld [hl], $0
- and $27
- jr z, .asm_13a13
+ and SLP | (1 << FRZ)
+ jr z, .cureVolatileStatuses
+; prevent the Pokemon from executing a move if it was asleep or frozen
ld a, $ff
ld [de], a
-.asm_13a13
+.cureVolatileStatuses
xor a
- ld [W_PLAYERDISABLEDMOVE], a
- ld [W_ENEMYDISABLEDMOVE], a
- ld hl, wccee
+ ld [wPlayerDisabledMove], a
+ ld [wEnemyDisabledMove], a
+ ld hl, wPlayerDisabledMoveNumber
ld [hli], a
ld [hl], a
- ld hl, W_PLAYERBATTSTATUS1
- call CureStatuses
- ld hl, W_ENEMYBATTSTATUS1
- call CureStatuses
+ ld hl, wPlayerBattleStatus1
+ call CureVolatileStatuses
+ ld hl, wEnemyBattleStatus1
+ call CureVolatileStatuses
ld hl, PlayCurrentMoveAnimation
call CallBankF
ld hl, StatusChangesEliminatedText
jp PrintText
-CureStatuses: ; 13a37 (4:7a37)
+CureVolatileStatuses:
res Confused, [hl]
inc hl ; BATTSTATUS2
ld a, [hl]
- and (1 << UsingRage) | (1 << NeedsToRecharge) | (1 << HasSubstituteUp) | (1 << 3) ; clear all but these from BATTSTATUS2
+ ; clear UsingXAccuracy, ProtectedByMist, GettingPumped, and Seeded statuses
+ and $ff ^((1 << UsingXAccuracy) | (1 << ProtectedByMist) | (1 << GettingPumped) | (1 << Seeded))
ld [hli], a ; BATTSTATUS3
ld a, [hl]
and %11110000 | (1 << Transformed) ; clear Bad Poison, Reflect and Light Screen statuses
ld [hl], a
ret
-ResetStatMods: ; 13a43 (4:7a43)
+ResetStatMods:
ld b, $8
.loop
ld [hli], a
@@ -61,7 +66,7 @@ ResetStatMods: ; 13a43 (4:7a43)
jr nz, .loop
ret
-ResetStats: ; 13a4a (4:7a4a)
+ResetStats:
ld b, $8
.loop
ld a, [hli]
@@ -71,6 +76,6 @@ ResetStats: ; 13a4a (4:7a4a)
jr nz, .loop
ret
-StatusChangesEliminatedText: ; 13a53 (4:7a53)
+StatusChangesEliminatedText:
TX_FAR _StatusChangesEliminatedText
db "@"
diff --git a/engine/battle/moveEffects/heal_effect.asm b/engine/battle/moveEffects/heal_effect.asm
index 22d482e7..b7d8283f 100644
--- a/engine/battle/moveEffects/heal_effect.asm
+++ b/engine/battle/moveEffects/heal_effect.asm
@@ -1,25 +1,26 @@
-HealEffect_: ; 3b9ec (e:79ec)
+HealEffect_:
ld a, [H_WHOSETURN]
and a
ld de, wBattleMonHP
ld hl, wBattleMonMaxHP
- ld a, [W_PLAYERMOVENUM]
- jr z, .asm_3ba03
+ ld a, [wPlayerMoveNum]
+ jr z, .healEffect
ld de, wEnemyMonHP
ld hl, wEnemyMonMaxHP
- ld a, [W_ENEMYMOVENUM]
-.asm_3ba03
+ ld a, [wEnemyMoveNum]
+.healEffect
ld b, a
ld a, [de]
- cp [hl]
+ cp [hl] ; most significant bytes comparison is ignored
+ ; causes the move to miss if max HP is 255 or 511 points higher than the current HP
inc de
inc hl
ld a, [de]
sbc [hl]
- jp z, .failed
+ jp z, .failed ; no effect if user's HP is already at its maximum
ld a, b
cp REST
- jr nz, .asm_3ba37
+ jr nz, .healHP
push hl
push de
push af
@@ -28,31 +29,33 @@ HealEffect_: ; 3b9ec (e:79ec)
ld hl, wBattleMonStatus
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3ba25
+ jr z, .restEffect
ld hl, wEnemyMonStatus
-.asm_3ba25
+.restEffect
ld a, [hl]
and a
- ld [hl], 2 ; Number of turns from Rest
- ld hl, StartedSleepingEffect
- jr z, .asm_3ba31
- ld hl, FellAsleepBecameHealthyText
-.asm_3ba31
+ ld [hl], 2 ; clear status and set number of turns asleep to 2
+ ld hl, StartedSleepingEffect ; if mon didn't have an status
+ jr z, .printRestText
+ ld hl, FellAsleepBecameHealthyText ; if mon had an status
+.printRestText
call PrintText
pop af
pop de
pop hl
-.asm_3ba37
+.healHP
ld a, [hld]
ld [wHPBarMaxHP], a
ld c, a
ld a, [hl]
ld [wHPBarMaxHP+1], a
ld b, a
- jr z, .asm_3ba47
+ jr z, .gotHPAmountToHeal
+; Recover and Softboiled only heal for half the mon's max HP
srl b
rr c
-.asm_3ba47
+.gotHPAmountToHeal
+; update HP
ld a, [de]
ld [wHPBarOldHP], a
add c
@@ -72,7 +75,8 @@ HealEffect_: ; 3b9ec (e:79ec)
dec hl
ld a, [de]
sbc [hl]
- jr c, .asm_3ba6f
+ jr c, .playAnim
+; copy max HP to current HP if an overflow ocurred
ld a, [hli]
ld [de], a
ld [wHPBarNewHP+1], a
@@ -80,17 +84,17 @@ HealEffect_: ; 3b9ec (e:79ec)
ld a, [hl]
ld [de], a
ld [wHPBarNewHP], a
-.asm_3ba6f
+.playAnim
ld hl, PlayCurrentMoveAnimation
call BankswitchEtoF
ld a, [H_WHOSETURN]
and a
- hlCoord 10, 9
+ coord hl, 10, 9
ld a, $1
- jr z, .asm_3ba83
- hlCoord 2, 2
+ jr z, .updateHPBar
+ coord hl, 2, 2
xor a
-.asm_3ba83
+.updateHPBar
ld [wHPBarType], a
predef UpdateHPBar2
ld hl, DrawHUDsAndHPBars
@@ -103,14 +107,14 @@ HealEffect_: ; 3b9ec (e:79ec)
ld hl, PrintButItFailedText_
jp BankswitchEtoF
-StartedSleepingEffect: ; 3baa2 (e:7aa2)
+StartedSleepingEffect:
TX_FAR _StartedSleepingEffect
db "@"
-FellAsleepBecameHealthyText: ; 3baa7 (e:7aa7)
+FellAsleepBecameHealthyText:
TX_FAR _FellAsleepBecameHealthyText
db "@"
-RegainedHealthText: ; 3baac (e:7aac)
+RegainedHealthText:
TX_FAR _RegainedHealthText
db "@"
diff --git a/engine/battle/moveEffects/leech_seed_effect.asm b/engine/battle/moveEffects/leech_seed_effect.asm
index a257d143..0f3a2666 100644
--- a/engine/battle/moveEffects/leech_seed_effect.asm
+++ b/engine/battle/moveEffects/leech_seed_effect.asm
@@ -1,39 +1,40 @@
-LeechSeedEffect_: ; 2bea9 (a:7ea9)
+LeechSeedEffect_:
callab MoveHitTest
- ld a, [W_MOVEMISSED] ; W_MOVEMISSED
+ ld a, [wMoveMissed]
and a
- jr nz, .asm_2bee7
- ld hl, W_ENEMYBATTSTATUS2 ; W_ENEMYBATTSTATUS2
- ld de, wEnemyMonType1 ; wcfea (aliases: wEnemyMonType)
- ld a, [H_WHOSETURN] ; $fff3
+ jr nz, .moveMissed
+ ld hl, wEnemyBattleStatus2
+ ld de, wEnemyMonType1
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_2bec8
- ld hl, W_PLAYERBATTSTATUS2 ; W_PLAYERBATTSTATUS2
- ld de, wBattleMonType1 ; wd019 (aliases: wBattleMonType)
-.asm_2bec8
+ jr z, .leechSeedEffect
+ ld hl, wPlayerBattleStatus2
+ ld de, wBattleMonType1
+.leechSeedEffect
+; miss if the target is grass-type or already seeded
ld a, [de]
cp GRASS
- jr z, .asm_2bee7
+ jr z, .moveMissed
inc de
ld a, [de]
cp GRASS
- jr z, .asm_2bee7
+ jr z, .moveMissed
bit Seeded, [hl]
- jr nz, .asm_2bee7
+ jr nz, .moveMissed
set Seeded, [hl]
callab PlayCurrentMoveAnimation
- ld hl, WasSeededText ; $7ef2
+ ld hl, WasSeededText
jp PrintText
-.asm_2bee7
- ld c, $32
+.moveMissed
+ ld c, 50
call DelayFrames
- ld hl, EvadedAttackText ; $7ef7
+ ld hl, EvadedAttackText
jp PrintText
-WasSeededText: ; 2bef2 (a:7ef2)
+WasSeededText:
TX_FAR _WasSeededText
db "@"
-EvadedAttackText: ; 2bef7 (a:7ef7)
+EvadedAttackText:
TX_FAR _EvadedAttackText
db "@"
diff --git a/engine/battle/moveEffects/mist_effect.asm b/engine/battle/moveEffects/mist_effect.asm
index adee1dfd..b92777de 100644
--- a/engine/battle/moveEffects/mist_effect.asm
+++ b/engine/battle/moveEffects/mist_effect.asm
@@ -1,21 +1,19 @@
-MistEffect_: ; 33f2b (c:7f2b)
- ld hl, W_PLAYERBATTSTATUS2
- ld a, [$fff3]
+MistEffect_:
+ ld hl, wPlayerBattleStatus2
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_33f36
- ld hl, W_ENEMYBATTSTATUS2
-.asm_33f36
+ jr z, .mistEffect
+ ld hl, wEnemyBattleStatus2
+.mistEffect
bit ProtectedByMist, [hl] ; is mon protected by mist?
- jr nz, .asm_33f4a
+ jr nz, .mistAlreadyInUse
set ProtectedByMist, [hl] ; mon is now protected by mist
callab PlayCurrentMoveAnimation
ld hl, ShroudedInMistText
jp PrintText
-.asm_33f4a
- ld hl, PrintButItFailedText_
- ld b, BANK(PrintButItFailedText_)
- jp Bankswitch
+.mistAlreadyInUse
+ jpab PrintButItFailedText_
-ShroudedInMistText: ; 33f52 (c:7f52)
+ShroudedInMistText:
TX_FAR _ShroudedInMistText
db "@"
diff --git a/engine/battle/moveEffects/one_hit_ko_effect.asm b/engine/battle/moveEffects/one_hit_ko_effect.asm
index 84418e33..827e2197 100644
--- a/engine/battle/moveEffects/one_hit_ko_effect.asm
+++ b/engine/battle/moveEffects/one_hit_ko_effect.asm
@@ -1,5 +1,5 @@
-OneHitKOEffect_: ; 33f57 (c:7f57)
- ld hl, W_DAMAGE
+OneHitKOEffect_:
+ ld hl, wDamage
xor a
ld [hli], a
ld [hl], a ; set the damage output to zero
@@ -7,12 +7,13 @@ OneHitKOEffect_: ; 33f57 (c:7f57)
ld [wCriticalHitOrOHKO], a
ld hl, wBattleMonSpeed + 1
ld de, wEnemyMonSpeed + 1
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr z, .asm_33f72
+ jr z, .compareSpeed
ld hl, wEnemyMonSpeed + 1
ld de, wBattleMonSpeed + 1
-.asm_33f72
+.compareSpeed
+; set damage to 65535 and OHKO flag is the user's current speed is higher than the target's
ld a, [de]
dec de
ld b, a
@@ -22,15 +23,16 @@ OneHitKOEffect_: ; 33f57 (c:7f57)
ld b, a
ld a, [hl]
sbc b
- jr c, .asm_33f8a
- ld hl, W_DAMAGE
+ jr c, .userIsSlower
+ ld hl, wDamage
ld a, $ff
ld [hli], a
ld [hl], a
ld a, $2
ld [wCriticalHitOrOHKO], a
ret
-.asm_33f8a
+.userIsSlower
+; keep damage at 0 and set move missed flag if target's current speed is higher instead
ld a, $1
- ld [W_MOVEMISSED], a
+ ld [wMoveMissed], a
ret
diff --git a/engine/battle/moveEffects/paralyze_effect.asm b/engine/battle/moveEffects/paralyze_effect.asm
index 69acbb01..95979ae6 100644
--- a/engine/battle/moveEffects/paralyze_effect.asm
+++ b/engine/battle/moveEffects/paralyze_effect.asm
@@ -1,11 +1,11 @@
-ParalyzeEffect_: ; 52601 (14:6601)
+ParalyzeEffect_:
ld hl, wEnemyMonStatus
- ld de, W_PLAYERMOVETYPE
+ ld de, wPlayerMoveType
ld a, [H_WHOSETURN]
and a
jp z, .next
- ld hl, wBattleMonStatus
- ld de, W_ENEMYMOVETYPE
+ ld hl, wBattleMonStatus
+ ld de, wEnemyMoveType
.next
ld a, [hl]
and a ; does the target already have a status ailment?
@@ -28,7 +28,7 @@ ParalyzeEffect_: ; 52601 (14:6601)
push hl
callab MoveHitTest
pop hl
- ld a, [W_MOVEMISSED]
+ ld a, [wMoveMissed]
and a
jr nz, .didntAffect
set PAR, [hl]
@@ -36,18 +36,12 @@ ParalyzeEffect_: ; 52601 (14:6601)
ld c, 30
call DelayFrames
callab PlayCurrentMoveAnimation
- ld hl, PrintMayNotAttackText
- ld b, BANK(PrintMayNotAttackText)
- jp Bankswitch
+ jpab PrintMayNotAttackText
.didntAffect
ld c, 50
call DelayFrames
- ld hl, PrintDidntAffectText
- ld b, BANK(PrintDidntAffectText)
- jp Bankswitch
+ jpab PrintDidntAffectText
.doesntAffect
ld c, 50
call DelayFrames
- ld hl, PrintDoesntAffectText
- ld b, BANK(PrintDoesntAffectText)
- jp Bankswitch
+ jpab PrintDoesntAffectText
diff --git a/engine/battle/moveEffects/pay_day_effect.asm b/engine/battle/moveEffects/pay_day_effect.asm
index 75a005ed..e5daf014 100644
--- a/engine/battle/moveEffects/pay_day_effect.asm
+++ b/engine/battle/moveEffects/pay_day_effect.asm
@@ -1,20 +1,22 @@
-PayDayEffect_ ; 2feb8 (b:7eb8)
+PayDayEffect_:
xor a
ld hl, wcd6d
ld [hli], a
ld a, [H_WHOSETURN]
and a
ld a, [wBattleMonLevel]
- jr z, .asm_2fec8
+ jr z, .payDayEffect
ld a, [wEnemyMonLevel]
-.asm_2fec8
+.payDayEffect
+; level * 2
add a
ld [H_DIVIDEND + 3], a
xor a
ld [H_DIVIDEND], a
ld [H_DIVIDEND + 1], a
ld [H_DIVIDEND + 2], a
- ld a, $64
+; convert to BCD
+ ld a, 100
ld [H_DIVISOR], a
ld b, $4
call Divide
@@ -22,7 +24,7 @@ PayDayEffect_ ; 2feb8 (b:7eb8)
ld [hli], a
ld a, [H_REMAINDER]
ld [H_DIVIDEND + 3], a
- ld a, $a
+ ld a, 10
ld [H_DIVISOR], a
ld b, $4
call Divide
@@ -38,6 +40,6 @@ PayDayEffect_ ; 2feb8 (b:7eb8)
ld hl, CoinsScatteredText
jp PrintText
-CoinsScatteredText: ; 2ff04 (b:7f04)
+CoinsScatteredText:
TX_FAR _CoinsScatteredText
db "@"
diff --git a/engine/battle/moveEffects/recoil_effect.asm b/engine/battle/moveEffects/recoil_effect.asm
index 0460b208..7fc90c44 100644
--- a/engine/battle/moveEffects/recoil_effect.asm
+++ b/engine/battle/moveEffects/recoil_effect.asm
@@ -1,36 +1,37 @@
-RecoilEffect_: ; 1392c (4:792c)
+RecoilEffect_:
ld a, [H_WHOSETURN]
and a
- ld a, [W_PLAYERMOVENUM]
+ ld a, [wPlayerMoveNum]
ld hl, wBattleMonMaxHP
- jr z, .asm_1393d
- ld a, [W_ENEMYMOVENUM]
+ jr z, .recoilEffect
+ ld a, [wEnemyMoveNum]
ld hl, wEnemyMonMaxHP
-.asm_1393d
+.recoilEffect
ld d, a
- ld a, [W_DAMAGE]
+ ld a, [wDamage]
ld b, a
- ld a, [W_DAMAGE + 1]
+ ld a, [wDamage + 1]
ld c, a
srl b
rr c
ld a, d
- cp STRUGGLE
- jr z, .asm_13953
+ cp STRUGGLE ; struggle deals 50% recoil damage
+ jr z, .gotRecoilDamage
srl b
rr c
-.asm_13953
+.gotRecoilDamage
ld a, b
or c
- jr nz, .asm_13958
- inc c
-.asm_13958
+ jr nz, .updateHP
+ inc c ; minimum recoil damage is 1
+.updateHP
+; substract HP from user due to the recoil damage
ld a, [hli]
ld [wHPBarMaxHP+1], a
ld a, [hl]
ld [wHPBarMaxHP], a
push bc
- ld bc, $fff2
+ ld bc, wBattleMonHP - wBattleMonMaxHP
add hl, bc
pop bc
ld a, [hl]
@@ -43,26 +44,27 @@ RecoilEffect_: ; 1392c (4:792c)
sbc b
ld [hl], a
ld [wHPBarNewHP+1], a
- jr nc, .asm_13982
+ jr nc, .getHPBarCoords
+; if recoil damage is higher than the Pokemon's HP, set its HP to 0
xor a
ld [hli], a
ld [hl], a
ld hl, wHPBarNewHP
ld [hli], a
ld [hl], a
-.asm_13982
- hlCoord 10, 9
+.getHPBarCoords
+ coord hl, 10, 9
ld a, [H_WHOSETURN]
and a
ld a, $1
- jr z, .asm_13990
- hlCoord 2, 2
+ jr z, .updateHPBar
+ coord hl, 2, 2
xor a
-.asm_13990
+.updateHPBar
ld [wHPBarType], a
predef UpdateHPBar2
ld hl, HitWithRecoilText
jp PrintText
-HitWithRecoilText: ; 1399e (4:799e)
+HitWithRecoilText:
TX_FAR _HitWithRecoilText
db "@"
diff --git a/engine/battle/moveEffects/reflect_light_screen_effect.asm b/engine/battle/moveEffects/reflect_light_screen_effect.asm
index 39a2c154..b45fbe20 100644
--- a/engine/battle/moveEffects/reflect_light_screen_effect.asm
+++ b/engine/battle/moveEffects/reflect_light_screen_effect.asm
@@ -1,12 +1,12 @@
-ReflectLightScreenEffect_: ; 3bb97 (e:7b97)
- ld hl, W_PLAYERBATTSTATUS3
- ld de, W_PLAYERMOVEEFFECT
+ReflectLightScreenEffect_:
+ ld hl, wPlayerBattleStatus3
+ ld de, wPlayerMoveEffect
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bba8
- ld hl, W_ENEMYBATTSTATUS3
- ld de, W_ENEMYMOVEEFFECT
-.asm_3bba8
+ jr z, .reflectLightScreenEffect
+ ld hl, wEnemyBattleStatus3
+ ld de, wEnemyMoveEffect
+.reflectLightScreenEffect
ld a, [de]
cp LIGHT_SCREEN_EFFECT
jr nz, .reflect
@@ -14,32 +14,32 @@ ReflectLightScreenEffect_: ; 3bb97 (e:7b97)
jr nz, .moveFailed
set HasLightScreenUp, [hl] ; mon is now protected by light screen
ld hl, LightScreenProtectedText
- jr .asm_3bbc1
+ jr .playAnim
.reflect
bit HasReflectUp, [hl] ; is mon already protected by reflect?
jr nz, .moveFailed
set HasReflectUp, [hl] ; mon is now protected by reflect
ld hl, ReflectGainedArmorText
-.asm_3bbc1
+.playAnim
push hl
ld hl, PlayCurrentMoveAnimation
call BankswitchEtoF
pop hl
jp PrintText
.moveFailed
- ld c, $32
+ ld c, 50
call DelayFrames
ld hl, PrintButItFailedText_
jp BankswitchEtoF
-LightScreenProtectedText: ; 3bbd7 (e:7bd7)
+LightScreenProtectedText:
TX_FAR _LightScreenProtectedText
db "@"
-ReflectGainedArmorText: ; 3bbdc (e:7bdc)
+ReflectGainedArmorText:
TX_FAR _ReflectGainedArmorText
db "@"
-BankswitchEtoF: ; 3bbe1 (e:7be1)
+BankswitchEtoF:
ld b, BANK(BattleCore)
jp Bankswitch
diff --git a/engine/battle/moveEffects/substitute_effect.asm b/engine/battle/moveEffects/substitute_effect.asm
index e88def4a..03314ebf 100644
--- a/engine/battle/moveEffects/substitute_effect.asm
+++ b/engine/battle/moveEffects/substitute_effect.asm
@@ -1,61 +1,61 @@
-SubstituteEffect_: ; 17dad (5:7dad)
+SubstituteEffect_:
ld c, 50
call DelayFrames
ld hl, wBattleMonMaxHP
ld de, wPlayerSubstituteHP
- ld bc, W_PLAYERBATTSTATUS2
+ ld bc, wPlayerBattleStatus2
ld a, [H_WHOSETURN]
and a
jr z, .notEnemy
ld hl, wEnemyMonMaxHP
ld de, wEnemySubstituteHP
- ld bc, W_ENEMYBATTSTATUS2
+ ld bc, wEnemyBattleStatus2
.notEnemy
- ld a, [bc] ;load flags
- bit HasSubstituteUp, a ;user already has substitute?
- jr nz, .alreadyHasSubstitute ;skip this code if so
- ;user doesn't have a substitute [yet]
+ ld a, [bc]
+ bit HasSubstituteUp, a ; user already has substitute?
+ jr nz, .alreadyHasSubstitute
+; quarter health to remove from user
+; assumes max HP is 1023 or lower
push bc
- ld a, [hli] ;load max hp
+ ld a, [hli]
ld b, [hl]
- srl a ;max hp / 4, [quarter health to remove from user]
- rr b
srl a
rr b
+ srl a
+ rr b ; max hp / 4
push de
ld de, wBattleMonHP - wBattleMonMaxHP
- add hl, de ; point hl to current HP
+ add hl, de ; point hl to current HP low byte
pop de
ld a, b
- ld [de], a ;save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
- ld a, [hld] ;load current hp
- sub b ;subtract [max hp / 4]
- ld d, a ;save low byte result in D
+ ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
+ ld a, [hld]
+; subtract [max hp / 4] to current HP
+ sub b
+ ld d, a
ld a, [hl]
- sbc a, 0 ;borrow from high byte if needed
+ sbc 0
pop bc
- jr c, .notEnoughHP ;underflow means user would be left with negative health
- ;bug: note since it only brances on carry, it will possibly leave user with 0HP
+ jr c, .notEnoughHP ; underflow means user would be left with negative health
+ ; bug: since it only brances on carry, it will possibly leave user with 0 HP
.userHasZeroOrMoreHP
- ldi [hl], a ;store high byte HP
- ld [hl], d ;store low byte HP
+ ldi [hl], a ; save resulting HP after substraction into current HP
+ ld [hl], d
ld h, b
ld l, c
- set HasSubstituteUp, [hl] ;set bit 4 of flags, user now has substitute
- ld a, [W_OPTIONS] ;load options
- bit 7, a ;battle animation is enabled?
- ld hl, PlayCurrentMoveAnimation ;animation enabled: 0F:7BA8
+ set HasSubstituteUp, [hl]
+ ld a, [wOptions]
+ bit 7, a ; battle animation is enabled?
+ ld hl, PlayCurrentMoveAnimation
ld b, BANK(PlayCurrentMoveAnimation)
jr z, .animationEnabled
- ld hl, AnimationSubstitute ;animation disabled: 1E:56E0
+ ld hl, AnimationSubstitute
ld b, BANK(AnimationSubstitute)
.animationEnabled
- call Bankswitch ;jump to routine depending on animation setting
+ call Bankswitch ; jump to routine depending on animation setting
ld hl, SubstituteText
call PrintText
- ld hl, DrawHUDsAndHPBars
- ld b, BANK(DrawHUDsAndHPBars)
- jp Bankswitch
+ jpab DrawHUDsAndHPBars
.alreadyHasSubstitute
ld hl, HasSubstituteText
jr .printText
@@ -64,14 +64,14 @@ SubstituteEffect_: ; 17dad (5:7dad)
.printText
jp PrintText
-SubstituteText: ; 17e1d (5:7e1d)
+SubstituteText:
TX_FAR _SubstituteText
db "@"
-HasSubstituteText: ; 17e22 (5:7e22)
+HasSubstituteText:
TX_FAR _HasSubstituteText
db "@"
-TooWeakSubstituteText: ; 17e27 (5:7e27)
+TooWeakSubstituteText:
TX_FAR _TooWeakSubstituteText
db "@"
diff --git a/engine/battle/moveEffects/transform_effect.asm b/engine/battle/moveEffects/transform_effect.asm
index 6e25712a..45f8c910 100644
--- a/engine/battle/moveEffects/transform_effect.asm
+++ b/engine/battle/moveEffects/transform_effect.asm
@@ -1,55 +1,59 @@
-TransformEffect_: ; 3bab1 (e:7ab1)
+TransformEffect_:
ld hl, wBattleMonSpecies
ld de, wEnemyMonSpecies
- ld bc, W_ENEMYBATTSTATUS3
- ld a, [W_ENEMYBATTSTATUS1]
+ ld bc, wEnemyBattleStatus3
+ ld a, [wEnemyBattleStatus1]
ld a, [H_WHOSETURN]
and a
- jr nz, .asm_3bad1
+ jr nz, .hitTest
ld hl, wEnemyMonSpecies
ld de, wBattleMonSpecies
- ld bc, W_PLAYERBATTSTATUS3
+ ld bc, wPlayerBattleStatus3
ld [wPlayerMoveListIndex], a
- ld a, [W_PLAYERBATTSTATUS1]
-.asm_3bad1
+ ld a, [wPlayerBattleStatus1]
+.hitTest
bit Invulnerable, a ; is mon invulnerable to typical attacks? (fly/dig)
jp nz, .failed
push hl
push de
push bc
- ld hl, W_PLAYERBATTSTATUS2
+ ld hl, wPlayerBattleStatus2
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bae4
- ld hl, W_ENEMYBATTSTATUS2
-.asm_3bae4
+ jr z, .transformEffect
+ ld hl, wEnemyBattleStatus2
+.transformEffect
+; animation(s) played are different if target has Substitute up
bit HasSubstituteUp, [hl]
push af
- ld hl, Func_79747
- ld b, BANK(Func_79747)
+ ld hl, HideSubstituteShowMonAnim
+ ld b, BANK(HideSubstituteShowMonAnim)
call nz, Bankswitch
- ld a, [W_OPTIONS]
+ ld a, [wOptions]
add a
ld hl, PlayCurrentMoveAnimation
ld b, BANK(PlayCurrentMoveAnimation)
- jr nc, .asm_3baff
+ jr nc, .gotAnimToPlay
ld hl, AnimationTransformMon
ld b, BANK(AnimationTransformMon)
-.asm_3baff
+.gotAnimToPlay
call Bankswitch
- ld hl, Func_79771
- ld b, BANK(Func_79771)
+ ld hl, ReshowSubstituteAnim
+ ld b, BANK(ReshowSubstituteAnim)
pop af
call nz, Bankswitch
pop bc
ld a, [bc]
- set Transformed, a
+ set Transformed, a ; mon is now Transformed
ld [bc], a
pop de
pop hl
push hl
+; transform user into opposing Pokemon
+; species
ld a, [hl]
ld [de], a
+; type 1, type 2, catch rate, and moves
ld bc, $5
add hl, bc
inc de
@@ -62,20 +66,23 @@ TransformEffect_: ; 3bab1 (e:7ab1)
call CopyData
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bb32
+ jr z, .next
+; save enemy mon DVs at wTransformedEnemyMonOriginalDVs
ld a, [de]
- ld [wcceb], a
+ ld [wTransformedEnemyMonOriginalDVs], a
inc de
ld a, [de]
- ld [wccec], a
+ ld [wTransformedEnemyMonOriginalDVs + 1], a
dec de
-.asm_3bb32
+.next
+; DVs
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
inc de
+; Attack, Defense, Speed, and Special stats
inc hl
inc hl
inc hl
@@ -84,48 +91,51 @@ TransformEffect_: ; 3bab1 (e:7ab1)
inc de
ld bc, $8
call CopyData
- ld bc, $ffef
- add hl, bc
- ld b, $4
-.asm_3bb4a
+ ld bc, wBattleMonMoves - wBattleMonPP
+ add hl, bc ; ld hl, wBattleMonMoves
+ ld b, NUM_MOVES
+.copyPPLoop
+; 5 PP for all moves
ld a, [hli]
and a
- jr z, .asm_3bb57
+ jr z, .lessThanFourMoves
ld a, $5
ld [de], a
inc de
dec b
- jr nz, .asm_3bb4a
- jr .asm_3bb5d
-.asm_3bb57
+ jr nz, .copyPPLoop
+ jr .copyStats
+.lessThanFourMoves
+; 0 PP for blank moves
xor a
ld [de], a
inc de
dec b
- jr nz, .asm_3bb57
-.asm_3bb5d
+ jr nz, .lessThanFourMoves
+.copyStats
+; original (unmodified) stats and stat mods
pop hl
ld a, [hl]
ld [wd11e], a
call GetMonName
ld hl, wEnemyMonUnmodifiedAttack
ld de, wPlayerMonUnmodifiedAttack
- call .copyBasedOnTurn
+ call .copyBasedOnTurn ; original (unmodified) stats
ld hl, wEnemyMonStatMods
ld de, wPlayerMonStatMods
- call .copyBasedOnTurn
+ call .copyBasedOnTurn ; stat mods
ld hl, TransformedText
jp PrintText
.copyBasedOnTurn
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3bb86
+ jr z, .gotStatsOrModsToCopy
push hl
ld h, d
ld l, e
pop de
-.asm_3bb86
+.gotStatsOrModsToCopy
ld bc, $8
jp CopyData
@@ -133,6 +143,6 @@ TransformEffect_: ; 3bab1 (e:7ab1)
ld hl, PrintButItFailedText_
jp BankswitchEtoF
-TransformedText: ; 3bb92 (e:7b92)
+TransformedText:
TX_FAR _TransformedText
db "@"
diff --git a/engine/battle/print_type.asm b/engine/battle/print_type.asm
index 38c701a8..f717f871 100644
--- a/engine/battle/print_type.asm
+++ b/engine/battle/print_type.asm
@@ -1,16 +1,16 @@
; [wd0b5] = pokemon ID
; hl = dest addr
-PrintMonType: ; 27d6b (9:7d6b)
+PrintMonType:
call GetPredefRegisters
push hl
call GetMonHeader
pop hl
push hl
- ld a, [W_MONHTYPE1]
+ ld a, [wMonHType1]
call PrintType
- ld a, [W_MONHTYPE1]
+ ld a, [wMonHType1]
ld b, a
- ld a, [W_MONHTYPE2]
+ ld a, [wMonHType2]
cp b
pop hl
jr z, EraseType2Text
@@ -19,25 +19,25 @@ PrintMonType: ; 27d6b (9:7d6b)
; a = type
; hl = dest addr
-PrintType: ; 27d89 (9:7d89)
+PrintType:
push hl
jr PrintType_
; erase "TYPE2/" if the mon only has 1 type
-EraseType2Text: ; 27d8c (9:7d8c)
+EraseType2Text:
ld a, " "
ld bc, $13
add hl, bc
ld bc, $6
jp FillMemory
-PrintMoveType: ; 27d98 (9:7d98)
+PrintMoveType:
call GetPredefRegisters
push hl
- ld a, [W_PLAYERMOVETYPE]
+ ld a, [wPlayerMoveType]
; fall through
-PrintType_: ; 27d9f (9:7d9f)
+PrintType_:
add a
ld hl, TypeNames
ld e, a
diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm
index f1e3aaf1..3672d8dc 100644..100755
--- a/engine/battle/read_trainer_party.asm
+++ b/engine/battle/read_trainer_party.asm
@@ -1,4 +1,4 @@
-ReadTrainer: ; 39c53 (e:5c53)
+ReadTrainer:
; don't change any moves in a link battle
ld a,[wLinkState]
@@ -15,7 +15,7 @@ ReadTrainer: ; 39c53 (e:5c53)
ld [hl],a
; get the pointer to trainer data for this class
- ld a,[W_CUROPPONENT]
+ ld a,[wCurOpponent]
sub $C9 ; convert value from pokemon to trainer
add a,a
ld hl,TrainerDataPointers
@@ -25,7 +25,7 @@ ReadTrainer: ; 39c53 (e:5c53)
ld a,[hli]
ld h,[hl]
ld l,a
- ld a,[W_TRAINERNO]
+ ld a,[wTrainerNo]
ld b,a
; At this point b contains the trainer number,
; and hl points to the trainer class.
@@ -43,20 +43,20 @@ ReadTrainer: ; 39c53 (e:5c53)
; if the first byte of trainer data is FF,
; - each pokemon has a specific level
; (as opposed to the whole team being of the same level)
-; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move
+; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
; else the first byte is the level of every pokemon on the team
.IterateTrainer
ld a,[hli]
cp $FF ; is the trainer special?
jr z,.SpecialTrainer ; if so, check for special moves
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
.LoopTrainerData
ld a,[hli]
and a ; have we reached the end of the trainer data?
jr z,.FinishUp
ld [wcf91],a ; write species somewhere (XXX why?)
- ld a,1
- ld [wcc49],a
+ ld a,ENEMY_PARTY_DATA
+ ld [wMonDataLocation],a
push hl
call AddPartyMon
pop hl
@@ -65,22 +65,22 @@ ReadTrainer: ; 39c53 (e:5c53)
; if this code is being run:
; - each pokemon has a specific level
; (as opposed to the whole team being of the same level)
-; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move
+; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move
ld a,[hli]
and a ; have we reached the end of the trainer data?
jr z,.AddLoneMove
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
ld a,[hli]
ld [wcf91],a
- ld a,1
- ld [wcc49],a
+ ld a,ENEMY_PARTY_DATA
+ ld [wMonDataLocation],a
push hl
call AddPartyMon
pop hl
jr .SpecialTrainer
.AddLoneMove
; does the trainer have a single monster with a different move
- ld a,[W_LONEATTACKNO] ; Brock is 01, Misty is 02, Erika is 04, etc
+ ld a,[wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc
and a
jr z,.AddTeamMove
dec a
@@ -100,8 +100,8 @@ ReadTrainer: ; 39c53 (e:5c53)
; check if our trainer's team has special moves
; get trainer class number
- ld a,[W_CUROPPONENT]
- sub $C8
+ ld a,[wCurOpponent]
+ sub 200
ld b,a
ld hl,TeamMoves
@@ -130,7 +130,7 @@ ReadTrainer: ; 39c53 (e:5c53)
ld [wEnemyMon1Moves + 2],a
; starter
- ld a,[W_RIVALSTARTER]
+ ld a,[wRivalStarter]
cp STARTER3
ld b,MEGA_DRAIN
jr z,.GiveStarterMove
@@ -141,24 +141,26 @@ ReadTrainer: ; 39c53 (e:5c53)
.GiveStarterMove
ld a,b
ld [wEnemyMon6Moves + 2],a
-.FinishUp ; XXX this needs documenting
- xor a ; clear D079-D07B
- ld de,wd079
+.FinishUp
+; clear wAmountMoneyWon addresses
+ xor a
+ ld de,wAmountMoneyWon
ld [de],a
inc de
ld [de],a
inc de
ld [de],a
- ld a,[W_CURENEMYLVL]
+ ld a,[wCurEnemyLVL]
ld b,a
.LastLoop
- ld hl,wd047
- ld c,2
+; update wAmountMoneyWon addresses (money to win) based on enemy's level
+ ld hl,wTrainerBaseMoney + 1
+ ld c,2 ; wAmountMoneyWon is a 3-byte number
push bc
predef AddBCDPredef
pop bc
inc de
inc de
dec b
- jr nz,.LastLoop
- ret \ No newline at end of file
+ jr nz,.LastLoop ; repeat wCurEnemyLVL times
+ ret
diff --git a/engine/battle/safari_zone.asm b/engine/battle/safari_zone.asm
index 6b0e2220..1eb1a615 100755
--- a/engine/battle/safari_zone.asm
+++ b/engine/battle/safari_zone.asm
@@ -1,4 +1,4 @@
-PrintSafariZoneBattleText: ; 4277 (1:4277)
+PrintSafariZoneBattleText:
ld hl, wSafariBaitFactor
ld a, [hl]
and a
@@ -18,7 +18,7 @@ PrintSafariZoneBattleText: ; 4277 (1:4277)
ld a, [wEnemyMonSpecies]
ld [wd0b5], a
call GetMonHeader
- ld a, [W_MONHCATCHRATE]
+ ld a, [wMonHCatchRate]
ld [wEnemyMonCatchRate], a
pop hl
.asm_429f
@@ -27,10 +27,10 @@ PrintSafariZoneBattleText: ; 4277 (1:4277)
pop hl
jp PrintText
-SafariZoneEatingText: ; 42a7 (1:42a7)
+SafariZoneEatingText:
TX_FAR _SafariZoneEatingText
db "@"
-SafariZoneAngryText: ; 42ac (1:42ac)
+SafariZoneAngryText:
TX_FAR _SafariZoneAngryText
db "@"
diff --git a/engine/battle/save_trainer_name.asm b/engine/battle/save_trainer_name.asm
index 84ef1f69..7e2c911c 100644
--- a/engine/battle/save_trainer_name.asm
+++ b/engine/battle/save_trainer_name.asm
@@ -1,6 +1,6 @@
-SaveTrainerName: ; 27e4a (9:7e4a)
+SaveTrainerName:
ld hl,TrainerNamePointers
- ld a,[W_TRAINERCLASS]
+ ld a,[wTrainerClass]
dec a
ld c,a
ld b,0
@@ -18,95 +18,95 @@ SaveTrainerName: ; 27e4a (9:7e4a)
jr nz,.CopyCharacter
ret
-TrainerNamePointers: ; 27e64 (9:7e64)
+TrainerNamePointers:
; what is the point of these?
dw YoungsterName
dw BugCatcherName
dw LassName
- dw W_TRAINERNAME
+ dw wTrainerName
dw JrTrainerMName
dw JrTrainerFName
dw PokemaniacName
dw SuperNerdName
- dw W_TRAINERNAME
- dw W_TRAINERNAME
+ dw wTrainerName
+ dw wTrainerName
dw BurglarName
dw EngineerName
dw JugglerXName
- dw W_TRAINERNAME
+ dw wTrainerName
dw SwimmerName
- dw W_TRAINERNAME
- dw W_TRAINERNAME
+ dw wTrainerName
+ dw wTrainerName
dw BeautyName
- dw W_TRAINERNAME
+ dw wTrainerName
dw RockerName
dw JugglerName
- dw W_TRAINERNAME
- dw W_TRAINERNAME
+ dw wTrainerName
+ dw wTrainerName
dw BlackbeltName
- dw W_TRAINERNAME
+ dw wTrainerName
dw ProfOakName
dw ChiefName
dw ScientistName
- dw W_TRAINERNAME
+ dw wTrainerName
dw RocketName
dw CooltrainerMName
dw CooltrainerFName
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
- dw W_TRAINERNAME
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
+ dw wTrainerName
-YoungsterName: ; 27ec2 (9:7ec2)
+YoungsterName:
db "YOUNGSTER@"
-BugCatcherName: ; 27ecc (9:7ecc)
+BugCatcherName:
db "BUG CATCHER@"
-LassName: ; 27ed8 (9:7ed8)
+LassName:
db "LASS@"
-JrTrainerMName: ; 27edd (9:7edd)
+JrTrainerMName:
db "JR.TRAINER♂@"
-JrTrainerFName: ; 27ee9 (9:7ee9)
+JrTrainerFName:
db "JR.TRAINER♀@"
-PokemaniacName: ; 27ef5 (9:7ef5)
+PokemaniacName:
db "POKéMANIAC@"
-SuperNerdName: ; 27f00 (9:7f00)
+SuperNerdName:
db "SUPER NERD@"
-BurglarName: ; 27f0b (9:7f0b)
+BurglarName:
db "BURGLAR@"
-EngineerName: ; 27f13 (9:7f13)
+EngineerName:
db "ENGINEER@"
-JugglerXName: ; 27f1c (9:7f1c)
+JugglerXName:
db "JUGGLER@"
-SwimmerName: ; 27f24 (9:7f24)
+SwimmerName:
db "SWIMMER@"
-BeautyName: ; 27f2c (9:7f2c)
+BeautyName:
db "BEAUTY@"
-RockerName: ; 27f33 (9:7f33)
+RockerName:
db "ROCKER@"
-JugglerName: ; 27f3a (9:7f3a)
+JugglerName:
db "JUGGLER@"
-BlackbeltName: ; 27f42 (9:7f42)
+BlackbeltName:
db "BLACKBELT@"
-ProfOakName: ; 27f4c (9:7f4c)
+ProfOakName:
db "PROF.OAK@"
-ChiefName: ; 27f55 (9:7f55)
+ChiefName:
db "CHIEF@"
-ScientistName: ; 27f5b (9:7f5b)
+ScientistName:
db "SCIENTIST@"
-RocketName: ; 27f65 (9:7f65)
+RocketName:
db "ROCKET@"
-CooltrainerMName: ; 27f6c (9:7f6c)
+CooltrainerMName:
db "COOLTRAINER♂@"
-CooltrainerFName: ; 27f79 (9:7f79)
+CooltrainerFName:
db "COOLTRAINER♀@"
diff --git a/engine/battle/scale_sprites.asm b/engine/battle/scale_sprites.asm
index dae4ad42..98521528 100644
--- a/engine/battle/scale_sprites.asm
+++ b/engine/battle/scale_sprites.asm
@@ -1,16 +1,16 @@
; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel)
; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored
; resulting in a 7*7 tile output sprite chunk
-ScaleSpriteByTwo: ; 2fe40 (b:7e40)
- ld de, S_SPRITEBUFFER1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
- ld hl, S_SPRITEBUFFER0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
+ScaleSpriteByTwo:
+ ld de, sSpriteBuffer1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
+ ld hl, sSpriteBuffer0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
call ScaleLastSpriteColumnByTwo ; last tile column is special case
call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns
- ld de, S_SPRITEBUFFER2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
- ld hl, S_SPRITEBUFFER1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
+ ld de, sSpriteBuffer2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
+ ld hl, sSpriteBuffer1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
call ScaleLastSpriteColumnByTwo ; last tile column is special case
-ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55)
+ScaleFirstThreeSpriteColumnsByTwo:
ld b, $3 ; 3 tile columns
.columnLoop
ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
@@ -39,18 +39,18 @@ ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55)
jr nz, .columnLoop
ret
-ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d)
+ScaleLastSpriteColumnByTwo:
ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
- ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b
- ld bc, -1 ; $ffff
+ ld [H_SPRITEINTERLACECOUNTER], a
+ ld bc, -1
.columnInnerLoop
ld a, [de]
dec de
swap a ; only high nybble contains information
call ScalePixelsByTwo
- ld a, [H_SPRITEINTERLACECOUNTER] ; $ff8b
+ ld a, [H_SPRITEINTERLACECOUNTER]
dec a
- ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b
+ ld [H_SPRITEINTERLACECOUNTER], a
jr nz, .columnInnerLoop
dec de ; skip last 4 rows of new column
dec de
@@ -61,7 +61,7 @@ ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d)
; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels)
; hl: destination pointer
; bc: destination pointer offset (added after the two bytes have been written)
-ScalePixelsByTwo: ; 2fe97 (b:7e97)
+ScalePixelsByTwo:
push hl
and $f
ld hl, DuplicateBitsTable
@@ -78,7 +78,7 @@ ScalePixelsByTwo: ; 2fe97 (b:7e97)
ret
; repeats each input bit twice
-DuplicateBitsTable: ; 2fea8 (b:7ea8)
+DuplicateBitsTable:
db $00, $03, $0c, $0f
db $30, $33, $3c, $3f
db $c0, $c3, $cc, $cf
diff --git a/engine/battle/scroll_draw_trainer_pic.asm b/engine/battle/scroll_draw_trainer_pic.asm
index 18df86e0..98893dcf 100644
--- a/engine/battle/scroll_draw_trainer_pic.asm
+++ b/engine/battle/scroll_draw_trainer_pic.asm
@@ -1,12 +1,12 @@
-_ScrollTrainerPicAfterBattle: ; 396d3 (e:56d3)
+_ScrollTrainerPicAfterBattle:
; Load the enemy trainer's pic and scrolls it into
; the screen from the right.
xor a
ld [wEnemyMonSpecies2], a
- ld b, $1
- call GoPAL_SET
+ ld b, SET_PAL_BATTLE
+ call RunPaletteCommand
callab _LoadTrainerPic
- hlCoord 19, 0
+ coord hl, 19, 0
ld c, $0
.scrollLoop
inc c
@@ -32,7 +32,7 @@ _ScrollTrainerPicAfterBattle: ; 396d3 (e:56d3)
jr .scrollLoop
; write one 7-tile column of the trainer pic to the tilemap
-DrawTrainerPicColumn: ; 39707 (e:5707)
+DrawTrainerPicColumn:
push hl
push de
push bc
diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm
index 191cfd5e..b175fcaf 100644
--- a/engine/battle/trainer_ai.asm
+++ b/engine/battle/trainer_ai.asm
@@ -1,25 +1,25 @@
; creates a set of moves that may be used and returns its address in hl
; unused slots are filled with 0, all used slots may be chosen with equal probability
-AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
+AIEnemyTrainerChooseMoves:
ld a, $a
- ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end
+ ld hl, wBuffer ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end
ld [hli], a ; move 1
ld [hli], a ; move 2
ld [hli], a ; move 3
ld [hl], a ; move 4
- ld a, [W_ENEMYDISABLEDMOVE] ; forbid disabled move (if any)
+ ld a, [wEnemyDisabledMove] ; forbid disabled move (if any)
swap a
and $f
jr z, .noMoveDisabled
- ld hl, wHPBarMaxHP
+ ld hl, wBuffer
dec a
ld c, a
ld b, $0
add hl, bc ; advance pointer to forbidden move
ld [hl], $50 ; forbid (highly discourage) disabled move
.noMoveDisabled
- ld hl, TrainerClassMoveChoiceModifications ; 589B
- ld a, [W_TRAINERCLASS]
+ ld hl, TrainerClassMoveChoiceModifications
+ ld a, [wTrainerClass]
ld b, a
.loopTrainerClasses
dec b
@@ -40,11 +40,11 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
and a
jr z, .loopFindMinimumEntries
push hl
- ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3
+ ld hl, AIMoveChoiceModificationFunctionPointers
dec a
add a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc ; skip to pointer
ld a, [hli] ; read pointer into hl
ld h, [hl]
@@ -53,9 +53,9 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
push de
jp [hl] ; execute modification function
.loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero
- ld hl, wHPBarMaxHP ; temp move selection array
+ ld hl, wBuffer ; temp move selection array
ld de, wEnemyMonMoves ; enemy moves
- ld c, $4
+ ld c, NUM_MOVES
.loopDecrementEntries
ld a, [de]
inc de
@@ -73,15 +73,15 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
inc [hl]
dec hl
inc a
- cp $5
+ cp NUM_MOVES + 1
jr nz, .loopUndoPartialIteration
- ld hl, wHPBarMaxHP ; temp move selection array
+ ld hl, wBuffer ; temp move selection array
ld de, wEnemyMonMoves ; enemy moves
- ld c, $4
+ ld c, NUM_MOVES
.filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0)
ld a, [de]
and a
- jr nz, .moveExisting ; 0x3978a $1
+ jr nz, .moveExisting
ld [hl], a
.moveExisting
ld a, [hl]
@@ -97,20 +97,20 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719)
inc de
dec c
jr nz, .filterMinimalEntries
- ld hl, wHPBarMaxHP ; use created temporary array as move set
+ ld hl, wBuffer ; use created temporary array as move set
ret
.useOriginalMoveSet
ld hl, wEnemyMonMoves ; use original move set
ret
-AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3)
+AIMoveChoiceModificationFunctionPointers:
dw AIMoveChoiceModification1
dw AIMoveChoiceModification2
dw AIMoveChoiceModification3
dw AIMoveChoiceModification4 ; unused, does nothing
; discourages moves that cause no damage but only a status ailment if player's mon already has one
-AIMoveChoiceModification1: ; 397ab (e:57ab)
+AIMoveChoiceModification1:
ld a, [wBattleMonStatus]
and a
ret z ; return if no status ailment on player's mon
@@ -126,10 +126,10 @@ AIMoveChoiceModification1: ; 397ab (e:57ab)
ret z ; no more moves in move set
inc de
call ReadMove
- ld a, [W_ENEMYMOVEPOWER]
+ ld a, [wEnemyMovePower]
and a
jr nz, .nextMove
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
push hl
push de
push bc
@@ -145,7 +145,7 @@ AIMoveChoiceModification1: ; 397ab (e:57ab)
ld [hl], a
jr .nextMove
-StatusAilmentMoveEffects ; 57e2
+StatusAilmentMoveEffects:
db $01 ; unused sleep effect
db SLEEP_EFFECT
db POISON_EFFECT
@@ -155,9 +155,9 @@ StatusAilmentMoveEffects ; 57e2
; slightly encourage moves with specific effects.
; in particular, stat-modifying moves and other move effects
; that fall in-bewteen
-AIMoveChoiceModification2: ; 397e7 (e:57e7)
+AIMoveChoiceModification2:
ld a, [wAILayer2Encouragement]
- cp $1
+ cp $1
ret nz
ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset)
ld de, wEnemyMonMoves ; enemy moves
@@ -171,7 +171,7 @@ AIMoveChoiceModification2: ; 397e7 (e:57e7)
ret z ; no more moves in move set
inc de
call ReadMove
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp ATTACK_UP1_EFFECT
jr c, .nextMove
cp BIDE_EFFECT
@@ -182,16 +182,16 @@ AIMoveChoiceModification2: ; 397e7 (e:57e7)
jr c, .preferMove
jr .nextMove
.preferMove
- dec [hl] ; sligthly encourage this move
+ dec [hl] ; slightly encourage this move
jr .nextMove
; encourages moves that are effective against the player's mon (even if non-damaging).
; discourage damaging moves that are ineffective or not very effective against the player's mon,
; unless there's no damaging move that deals at least neutral damage
-AIMoveChoiceModification3: ; 39817 (e:5817)
+AIMoveChoiceModification3:
ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset)
ld de, wEnemyMonMoves ; enemy moves
- ld b, $5
+ ld b, NUM_MOVES + 1
.nextMove
dec b
ret z ; processed all 4 moves
@@ -208,7 +208,7 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
pop de
pop bc
pop hl
- ld a, [wd11e]
+ ld a, [wTypeEffectiveness]
cp $10
jr z, .nextMove
jr c, .notEffectiveMove
@@ -218,7 +218,7 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
push hl
push de
push bc
- ld a, [W_ENEMYMOVETYPE]
+ ld a, [wEnemyMoveType]
ld d, a
ld hl, wEnemyMonMoves ; enemy moves
ld b, NUM_MOVES + 1
@@ -230,17 +230,17 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
and a
jr z, .done
call ReadMove
- ld a, [W_ENEMYMOVEEFFECT]
+ ld a, [wEnemyMoveEffect]
cp SUPER_FANG_EFFECT
jr z, .betterMoveFound ; Super Fang is considered to be a better move
cp SPECIAL_DAMAGE_EFFECT
jr z, .betterMoveFound ; any special damage moves are considered to be better moves
cp FLY_EFFECT
jr z, .betterMoveFound ; Fly is considered to be a better move
- ld a, [W_ENEMYMOVETYPE]
+ ld a, [wEnemyMoveType]
cp d
jr z, .loopMoves
- ld a, [W_ENEMYMOVEPOWER]
+ ld a, [wEnemyMovePower]
and a
jr nz, .betterMoveFound ; damaging moves of a different type are considered to be better moves
jr .loopMoves
@@ -255,18 +255,18 @@ AIMoveChoiceModification3: ; 39817 (e:5817)
jr z, .nextMove
inc [hl] ; sligthly discourage this move
jr .nextMove
-AIMoveChoiceModification4: ; 39883 (e:5883)
+AIMoveChoiceModification4:
ret
-ReadMove: ; 39884 (e:5884)
+ReadMove:
push hl
push de
push bc
dec a
ld hl,Moves
- ld bc,6
+ ld bc,MoveEnd - Moves
call AddNTimes
- ld de,W_ENEMYMOVENUM
+ ld de,wEnemyMoveNum
call CopyData
pop bc
pop de
@@ -275,13 +275,13 @@ ReadMove: ; 39884 (e:5884)
; move choice modification methods that are applied for each trainer class
; 0 is sentinel value
-TrainerClassMoveChoiceModifications: ; 3989b (e:589b)
+TrainerClassMoveChoiceModifications:
db 0 ; YOUNGSTER
db 1,0 ; BUG CATCHER
db 1,0 ; LASS
db 1,3,0 ; SAILOR
- db 1,0 ; JR__TRAINER_M
- db 1,0 ; JR__TRAINER_F
+ db 1,0 ; JR_TRAINER_M
+ db 1,0 ; JR_TRAINER_F
db 1,2,3,0; POKEMANIAC
db 1,2,0 ; SUPER_NERD
db 1,0 ; HIKER
@@ -311,7 +311,7 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b)
db 1,0 ; BRUNO
db 1,0 ; BROCK
db 1,3,0 ; MISTY
- db 1,3,0 ; LT__SURGE
+ db 1,3,0 ; LT_SURGE
db 1,3,0 ; ERIKA
db 1,3,0 ; KOGA
db 1,3,0 ; BLAINE
@@ -325,8 +325,8 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b)
db 1,3,0 ; LANCE
INCLUDE "engine/battle/trainer_pic_money_pointers.asm"
-
-INCLUDE "text/trainer_names.asm"
+
+INCLUDE "text/trainer_names.asm"
INCLUDE "engine/battle/bank_e_misc.asm"
@@ -336,16 +336,15 @@ INCLUDE "data/trainer_moves.asm"
INCLUDE "data/trainer_parties.asm"
-TrainerAI: ; 3a52e (e:652e)
-;XXX called at 34964, 3c342, 3c398
+TrainerAI:
and a
- ld a,[W_ISINBATTLE]
+ ld a,[wIsInBattle]
dec a
ret z ; if not a trainer, we're done here
ld a,[wLinkState]
cp LINK_STATE_BATTLING
ret z
- ld a,[W_TRAINERCLASS] ; what trainer class is this?
+ ld a,[wTrainerClass] ; what trainer class is this?
dec a
ld c,a
ld b,0
@@ -369,7 +368,7 @@ TrainerAI: ; 3a52e (e:652e)
call Random
jp [hl]
-TrainerAIPointers: ; 3a55c (e:655c)
+TrainerAIPointers:
; one entry per trainer class
; first byte, number of times (per Pokémon) it can occur
; next two bytes, pointer to AI subroutine for trainer class
@@ -421,27 +420,27 @@ TrainerAIPointers: ; 3a55c (e:655c)
dbw 2,AgathaAI ; agatha
dbw 1,LanceAI ; lance
-JugglerAI: ; 3a5e9 (e:65e9)
+JugglerAI:
cp $40
ret nc
jp AISwitchIfEnoughMons
-BlackbeltAI: ; 3a5ef (e:65ef)
+BlackbeltAI:
cp $20
ret nc
jp AIUseXAttack
-GiovanniAI: ; 3a5f5 (e:65f5)
+GiovanniAI:
cp $40
ret nc
jp AIUseGuardSpec
-CooltrainerMAI: ; 3a5fb (e:65fb)
+CooltrainerMAI:
cp $40
ret nc
jp AIUseXAttack
-CooltrainerFAI: ; 3a601 (e:6601)
+CooltrainerFAI:
cp $40
ld a,$A
call AICheckIfHPBelowFraction
@@ -451,24 +450,24 @@ CooltrainerFAI: ; 3a601 (e:6601)
ret nc
jp AISwitchIfEnoughMons
-BrockAI: ; 3a614 (e:6614)
+BrockAI:
; if his active monster has a status condition, use a full heal
ld a,[wEnemyMonStatus]
and a
ret z
jp AIUseFullHeal
-MistyAI: ; 3a61c (e:661c)
+MistyAI:
cp $40
ret nc
jp AIUseXDefend
-LtSurgeAI: ; 3a622 (e:6622)
+LtSurgeAI:
cp $40
ret nc
jp AIUseXSpeed
-ErikaAI: ; 3a628 (e:6628)
+ErikaAI:
cp $80
ret nc
ld a,$A
@@ -476,17 +475,17 @@ ErikaAI: ; 3a628 (e:6628)
ret nc
jp AIUseSuperPotion
-KogaAI: ; 3a634 (e:6634)
+KogaAI:
cp $40
ret nc
jp AIUseXAttack
-BlaineAI: ; 3a63a (e:663a)
+BlaineAI:
cp $40
ret nc
jp AIUseSuperPotion
-SabrinaAI: ; 3a640 (e:6640)
+SabrinaAI:
cp $40
ret nc
ld a,$A
@@ -494,7 +493,7 @@ SabrinaAI: ; 3a640 (e:6640)
ret nc
jp AIUseHyperPotion
-Sony2AI: ; 3a64c (e:664c)
+Sony2AI:
cp $20
ret nc
ld a,5
@@ -502,7 +501,7 @@ Sony2AI: ; 3a64c (e:664c)
ret nc
jp AIUsePotion
-Sony3AI: ; 3a658 (e:6658)
+Sony3AI:
cp $20
ret nc
ld a,5
@@ -510,7 +509,7 @@ Sony3AI: ; 3a658 (e:6658)
ret nc
jp AIUseFullRestore
-LoreleiAI: ; 3a664 (e:6664)
+LoreleiAI:
cp $80
ret nc
ld a,5
@@ -518,12 +517,12 @@ LoreleiAI: ; 3a664 (e:6664)
ret nc
jp AIUseSuperPotion
-BrunoAI: ; 3a670 (e:6670)
+BrunoAI:
cp $40
ret nc
jp AIUseXDefend
-AgathaAI: ; 3a676 (e:6676)
+AgathaAI:
cp $14
jp c,AISwitchIfEnoughMons
cp $80
@@ -533,7 +532,7 @@ AgathaAI: ; 3a676 (e:6676)
ret nc
jp AIUseSuperPotion
-LanceAI: ; 3a687 (e:6687)
+LanceAI:
cp $80
ret nc
ld a,5
@@ -541,26 +540,26 @@ LanceAI: ; 3a687 (e:6687)
ret nc
jp AIUseHyperPotion
-GenericAI: ; 3a693 (e:6693)
+GenericAI:
and a ; clear carry
ret
; end of individual trainer AI routines
-DecrementAICount: ; 3a695 (e:6695)
+DecrementAICount:
ld hl,wAICount
dec [hl]
scf
ret
-Func_3a69b: ; 3a69b (e:669b)
- ld a,(SFX_08_3e - SFX_Headers_08) / 3
+AIPlayRestoringSFX:
+ ld a,SFX_HEAL_AILMENT
jp PlaySoundWaitForCurrent
-AIUseFullRestore: ; 3a6a0 (e:66a0)
+AIUseFullRestore:
call AICureStatus
ld a,FULL_RESTORE
- ld [wcf05],a
+ ld [wAIItem],a
ld de,wHPBarOldHP
ld hl,wEnemyMonHP + 1
ld a,[hld]
@@ -581,27 +580,27 @@ AIUseFullRestore: ; 3a6a0 (e:66a0)
ld [wEnemyMonHP],a
jr AIPrintItemUseAndUpdateHPBar
-AIUsePotion: ; 3a6ca (e:66ca)
+AIUsePotion:
; enemy trainer heals his monster with a potion
ld a,POTION
ld b,20
jr AIRecoverHP
-AIUseSuperPotion: ; 3a6d0 (e:66d0)
+AIUseSuperPotion:
; enemy trainer heals his monster with a super potion
ld a,SUPER_POTION
ld b,50
jr AIRecoverHP
-AIUseHyperPotion: ; 3a6d6 (e:66d6)
+AIUseHyperPotion:
; enemy trainer heals his monster with a hyper potion
ld a,HYPER_POTION
ld b,200
; fallthrough
-AIRecoverHP: ; 3a6da (e:66da)
+AIRecoverHP:
; heal b HP and print "trainer used $(a) on pokemon!"
- ld [wcf05],a
+ ld [wAIItem],a
ld hl,wEnemyMonHP + 1
ld a,[hl]
ld [wHPBarOldHP],a
@@ -640,15 +639,15 @@ AIRecoverHP: ; 3a6da (e:66da)
ld [wHPBarNewHP+1],a
; fallthrough
-AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718)
+AIPrintItemUseAndUpdateHPBar:
call AIPrintItemUse_
- hlCoord 2, 2
+ coord hl, 2, 2
xor a
ld [wHPBarType],a
predef UpdateHPBar2
jp DecrementAICount
-AISwitchIfEnoughMons: ; 3a72a (e:672a)
+AISwitchIfEnoughMons:
; enemy trainer switches if there are 3 or more unfainted mons in party
ld a,[wEnemyPartyCount]
ld c,a
@@ -666,7 +665,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a)
inc d
.Fainted
push bc
- ld bc,$2C
+ ld bc, wEnemyMon2 - wEnemyMon1
add hl,bc
pop bc
dec c
@@ -678,7 +677,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a)
and a
ret
-SwitchEnemyMon: ; 3a74b (e:674b)
+SwitchEnemyMon:
; prepare to withdraw the active monster: copy hp, number, and status to roster
@@ -695,11 +694,13 @@ SwitchEnemyMon: ; 3a74b (e:674b)
ld hl, AIBattleWithdrawText
call PrintText
+ ; This wFirstMonsNotOutYet variable is abused to prevent the player from
+ ; switching in a new mon in response to this switch.
ld a,1
- ld [wd11d],a
+ ld [wFirstMonsNotOutYet],a
callab EnemySendOut
xor a
- ld [wd11d],a
+ ld [wFirstMonsNotOutYet],a
ld a,[wLinkState]
cp LINK_STATE_BATTLING
@@ -707,17 +708,17 @@ SwitchEnemyMon: ; 3a74b (e:674b)
scf
ret
-AIBattleWithdrawText: ; 3a781 (e:6781)
+AIBattleWithdrawText:
TX_FAR _AIBattleWithdrawText
db "@"
-AIUseFullHeal: ; 3a786 (e:6786)
- call Func_3a69b
+AIUseFullHeal:
+ call AIPlayRestoringSFX
call AICureStatus
ld a,FULL_HEAL
jp AIPrintItemUse
-AICureStatus: ; 3a791 (e:6791)
+AICureStatus:
; cures the status of enemy's active pokemon
ld a,[wEnemyMonPartyPos]
ld hl,wEnemyMon1Status
@@ -726,32 +727,32 @@ AICureStatus: ; 3a791 (e:6791)
xor a
ld [hl],a ; clear status in enemy team roster
ld [wEnemyMonStatus],a ; clear status of active enemy
- ld hl,W_ENEMYBATTSTATUS3
+ ld hl,wEnemyBattleStatus3
res 0,[hl]
ret
-AIUseXAccuracy: ; 0x3a7a8 unused
- call Func_3a69b
- ld hl,W_ENEMYBATTSTATUS2
+AIUseXAccuracy: ; unused
+ call AIPlayRestoringSFX
+ ld hl,wEnemyBattleStatus2
set 0,[hl]
ld a,X_ACCURACY
jp AIPrintItemUse
-AIUseGuardSpec: ; 3a7b5 (e:67b5)
- call Func_3a69b
- ld hl,W_ENEMYBATTSTATUS2
+AIUseGuardSpec:
+ call AIPlayRestoringSFX
+ ld hl,wEnemyBattleStatus2
set 1,[hl]
- ld a,GUARD_SPEC_
+ ld a,GUARD_SPEC
jp AIPrintItemUse
-AIUseDireHit: ; 0x3a7c2 unused
- call Func_3a69b
- ld hl,W_ENEMYBATTSTATUS2
+AIUseDireHit: ; unused
+ call AIPlayRestoringSFX
+ ld hl,wEnemyBattleStatus2
set 2,[hl]
ld a,DIRE_HIT
jp AIPrintItemUse
-AICheckIfHPBelowFraction: ; 3a7cf (e:67cf)
+AICheckIfHPBelowFraction:
; return carry if enemy trainer's current HP is below 1 / a of the maximum
ld [H_DIVISOR],a
ld hl,wEnemyMonMaxHP
@@ -777,38 +778,38 @@ AICheckIfHPBelowFraction: ; 3a7cf (e:67cf)
sub c
ret
-AIUseXAttack: ; 3a7f2 (e:67f2)
+AIUseXAttack:
ld b,$A
ld a,X_ATTACK
jr AIIncreaseStat
-AIUseXDefend: ; 3a7f8 (e:67f8)
+AIUseXDefend:
ld b,$B
ld a,X_DEFEND
jr AIIncreaseStat
-AIUseXSpeed: ; 3a7fe (e:67fe)
+AIUseXSpeed:
ld b,$C
ld a,X_SPEED
jr AIIncreaseStat
-AIUseXSpecial: ; 3a804 (e:6804)
+AIUseXSpecial:
ld b,$D
ld a,X_SPECIAL
; fallthrough
-AIIncreaseStat: ; 3a808 (e:6808)
- ld [wcf05],a
+AIIncreaseStat:
+ ld [wAIItem],a
push bc
call AIPrintItemUse_
pop bc
- ld hl,W_ENEMYMOVEEFFECT
+ ld hl,wEnemyMoveEffect
ld a,[hld]
push af
ld a,[hl]
push af
push hl
- ld a,$AF
+ ld a,ANIM_AF
ld [hli],a
ld [hl],b
callab StatModifierUpEffect
@@ -819,19 +820,19 @@ AIIncreaseStat: ; 3a808 (e:6808)
ld [hl],a
jp DecrementAICount
-AIPrintItemUse: ; 3a82c (e:682c)
- ld [wcf05],a
+AIPrintItemUse:
+ ld [wAIItem],a
call AIPrintItemUse_
jp DecrementAICount
-AIPrintItemUse_: ; 3a835 (e:6835)
-; print "x used [wcf05] on z!"
- ld a,[wcf05]
+AIPrintItemUse_:
+; print "x used [wAIItem] on z!"
+ ld a,[wAIItem]
ld [wd11e],a
call GetItemName
ld hl, AIBattleUseItemText
jp PrintText
-AIBattleUseItemText: ; 3a844 (e:6844)
+AIBattleUseItemText:
TX_FAR _AIBattleUseItemText
db "@"
diff --git a/engine/battle/trainer_pic_money_pointers.asm b/engine/battle/trainer_pic_money_pointers.asm
index 3d32eb00..37678e74 100644..100755
--- a/engine/battle/trainer_pic_money_pointers.asm
+++ b/engine/battle/trainer_pic_money_pointers.asm
@@ -1,4 +1,4 @@
-TrainerPicAndMoneyPointers: ; 39914 (e:5914)
+TrainerPicAndMoneyPointers:
; trainer pic pointers and base money.
; money received after battle = base money × level of highest-level enemy mon
dw YoungsterPic
@@ -140,4 +140,4 @@ TrainerPicAndMoneyPointers: ; 39914 (e:5914)
money 9900
dw LancePic
- money 9900 \ No newline at end of file
+ money 9900
diff --git a/engine/battle/unused_stats_functions.asm b/engine/battle/unused_stats_functions.asm
index 23ddbc20..55f78fd3 100644
--- a/engine/battle/unused_stats_functions.asm
+++ b/engine/battle/unused_stats_functions.asm
@@ -1,5 +1,5 @@
; does nothing since no stats are ever selected (barring glitches)
-DoubleSelectedStats: ; 39680 (e:5680)
+DoubleSelectedStats:
ld a, [H_WHOSETURN]
and a
ld a, [wPlayerStatsToDouble]
@@ -29,7 +29,7 @@ DoubleSelectedStats: ; 39680 (e:5680)
ret
; does nothing since no stats are ever selected (barring glitches)
-HalveSelectedStats: ; 396a7 (e:56a7)
+HalveSelectedStats:
ld a, [H_WHOSETURN]
and a
ld a, [wPlayerStatsToHalve]
diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm
index 03119b90..231c46e7 100644
--- a/engine/battle/wild_encounters.asm
+++ b/engine/battle/wild_encounters.asm
@@ -1,6 +1,6 @@
; try to initiate a wild pokemon encounter
; returns success in Z
-TryDoWildEncounter: ; 13870 (4:7870)
+TryDoWildEncounter:
ld a, [wNPCMovementScriptPointerTableNum]
and a
ret nz
@@ -18,33 +18,33 @@ TryDoWildEncounter: ; 13870 (4:7870)
jr z, .CantEncounter
ld a, [wRepelRemainingSteps]
and a
- jr z, .asm_1389e
+ jr z, .next
dec a
jr z, .lastRepelStep
ld [wRepelRemainingSteps], a
-.asm_1389e
-; determine if wild pokmon can appear in the half-block were standing in
+.next
+; determine if wild pokemon can appear in the half-block we're standing in
; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile?
- hlCoord 9, 9
+ coord hl, 9, 9
ld c, [hl]
- ld a, [W_GRASSTILE]
+ ld a, [wGrassTile]
cp c
- ld a, [W_GRASSRATE]
+ ld a, [wGrassRate]
jr z, .CanEncounter
ld a, $14 ; in all tilesets with a water tile, this is its id
cp c
- ld a, [W_WATERRATE]
+ ld a, [wWaterRate]
jr z, .CanEncounter
-; even if not in grass/water, standing anywhere we can encounter pokmon
-; so long as the map is indoor and has wild pokmon defined.
-; as long as its not Viridian Forest or Safari Zone.
- ld a, [W_CURMAP]
+; even if not in grass/water, standing anywhere we can encounter pokemon
+; so long as the map is "indoor" and has wild pokemon defined.
+; ...as long as it's not Viridian Forest or Safari Zone.
+ ld a, [wCurMap]
cp REDS_HOUSE_1F ; is this an indoor map?
jr c, .CantEncounter2
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp FOREST ; Viridian Forest/Safari Zone
jr z, .CantEncounter2
- ld a, [W_GRASSRATE]
+ ld a, [wGrassRate]
.CanEncounter
; compare encounter chance with a random number to determine if there will be an encounter
ld b, a
@@ -61,20 +61,20 @@ TryDoWildEncounter: ; 13870 (4:7870)
inc hl
jr .determineEncounterSlot
.gotEncounterSlot
-; determine which wild pokmon (grass or water) can appear in the half-block were standing in
+; determine which wild pokemon (grass or water) can appear in the half-block we're standing in
ld c, [hl]
- ld hl, W_GRASSMONS
- aCoord 8, 9
- cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile?
+ ld hl, wGrassMons
+ aCoord 8, 9
+ cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile?
jr nz, .gotWildEncounterType ; else, it's treated as a grass tile by default
- ld hl, W_WATERMONS
+ ld hl, wWaterMons
; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not,
-; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters.
+; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters.
.gotWildEncounterType
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hli]
- ld [W_CURENEMYLVL], a
+ ld [wCurEnemyLVL], a
ld a, [hl]
ld [wcf91], a
ld [wEnemyMonSpecies2], a
@@ -83,14 +83,14 @@ TryDoWildEncounter: ; 13870 (4:7870)
jr z, .willEncounter
ld a, [wPartyMon1Level]
ld b, a
- ld a, [W_CURENEMYLVL]
+ ld a, [wCurEnemyLVL]
cp b
jr c, .CantEncounter2 ; repel prevents encounters if the leading party mon's level is higher than the wild mon
jr .willEncounter
.lastRepelStep
ld [wRepelRemainingSteps], a
- ld a, $d2
- ld [H_DOWNARROWBLINKCNT2], a
+ ld a, TEXT_REPEL_WORE_OFF
+ ld [hSpriteIndexOrTextID], a
call EnableAutoTextBoxDrawing
call DisplayTextID
.CantEncounter2
@@ -101,7 +101,7 @@ TryDoWildEncounter: ; 13870 (4:7870)
xor a
ret
-WildMonEncounterSlotChances: ; 13918 (4:7918)
+WildMonEncounterSlotChances:
; There are 10 slots for wild pokemon, and this is the table that defines how common each of
; those 10 slots is. A random number is generated and then the first byte of each pair in this
; table is compared against that random number. If the random number is less than or equal
diff --git a/engine/bcd.asm b/engine/bcd.asm
new file mode 100644
index 00000000..3e693e1f
--- /dev/null
+++ b/engine/bcd.asm
@@ -0,0 +1,212 @@
+DivideBCDPredef::
+DivideBCDPredef2::
+DivideBCDPredef3::
+DivideBCDPredef4::
+ call GetPredefRegisters
+
+DivideBCD::
+ xor a
+ ld [$ffa5], a
+ ld [$ffa6], a
+ ld [$ffa7], a
+ ld d, $1
+.asm_f72a
+ ld a, [$ffa2]
+ and $f0
+ jr nz, .asm_f75b
+ inc d
+ ld a, [$ffa2]
+ swap a
+ and $f0
+ ld b, a
+ ld a, [$ffa3]
+ swap a
+ ld [$ffa3], a
+ and $f
+ or b
+ ld [$ffa2], a
+ ld a, [$ffa3]
+ and $f0
+ ld b, a
+ ld a, [$ffa4]
+ swap a
+ ld [$ffa4], a
+ and $f
+ or b
+ ld [$ffa3], a
+ ld a, [$ffa4]
+ and $f0
+ ld [$ffa4], a
+ jr .asm_f72a
+.asm_f75b
+ push de
+ push de
+ call DivideBCD_f800
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [$ffa5], a
+ dec d
+ jr z, .asm_f7bc
+ push de
+ call DivideBCD_f7d7
+ call DivideBCD_f800
+ pop de
+ ld a, [$ffa5]
+ or b
+ ld [$ffa5], a
+ dec d
+ jr z, .asm_f7bc
+ push de
+ call DivideBCD_f7d7
+ call DivideBCD_f800
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [$ffa6], a
+ dec d
+ jr z, .asm_f7bc
+ push de
+ call DivideBCD_f7d7
+ call DivideBCD_f800
+ pop de
+ ld a, [$ffa6]
+ or b
+ ld [$ffa6], a
+ dec d
+ jr z, .asm_f7bc
+ push de
+ call DivideBCD_f7d7
+ call DivideBCD_f800
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [$ffa7], a
+ dec d
+ jr z, .asm_f7bc
+ push de
+ call DivideBCD_f7d7
+ call DivideBCD_f800
+ pop de
+ ld a, [$ffa7]
+ or b
+ ld [$ffa7], a
+.asm_f7bc
+ ld a, [$ffa5]
+ ld [$ffa2], a
+ ld a, [$ffa6]
+ ld [$ffa3], a
+ ld a, [$ffa7]
+ ld [$ffa4], a
+ pop de
+ ld a, $6
+ sub d
+ and a
+ ret z
+.asm_f7ce
+ push af
+ call DivideBCD_f7d7
+ pop af
+ dec a
+ jr nz, .asm_f7ce
+ ret
+
+DivideBCD_f7d7:
+ ld a, [$ffa4]
+ swap a
+ and $f
+ ld b, a
+ ld a, [$ffa3]
+ swap a
+ ld [$ffa3], a
+ and $f0
+ or b
+ ld [$ffa4], a
+ ld a, [$ffa3]
+ and $f
+ ld b, a
+ ld a, [$ffa2]
+ swap a
+ ld [$ffa2], a
+ and $f0
+ or b
+ ld [$ffa3], a
+ ld a, [$ffa2]
+ and $f
+ ld [$ffa2], a
+ ret
+
+DivideBCD_f800:
+ ld bc, $3
+.asm_f803
+ ld de, $ff9f
+ ld hl, $ffa2
+ push bc
+ call StringCmp
+ pop bc
+ ret c
+ inc b
+ ld de, $ffa1
+ ld hl, $ffa4
+ push bc
+ call SubBCD
+ pop bc
+ jr .asm_f803
+
+
+AddBCDPredef::
+ call GetPredefRegisters
+
+AddBCD::
+ and a
+ ld b, c
+.add
+ ld a, [de]
+ adc [hl]
+ daa
+ ld [de], a
+ dec de
+ dec hl
+ dec c
+ jr nz, .add
+ jr nc, .done
+ ld a, $99
+ inc de
+.fill
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .fill
+.done
+ ret
+
+
+SubBCDPredef::
+ call GetPredefRegisters
+
+SubBCD::
+ and a
+ ld b, c
+.sub
+ ld a, [de]
+ sbc [hl]
+ daa
+ ld [de], a
+ dec de
+ dec hl
+ dec c
+ jr nz, .sub
+ jr nc, .done
+ ld a, $00
+ inc de
+.fill
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .fill
+ scf
+.done
+ ret
diff --git a/engine/black_out.asm b/engine/black_out.asm
new file mode 100644
index 00000000..6c358ce3
--- /dev/null
+++ b/engine/black_out.asm
@@ -0,0 +1,46 @@
+ResetStatusAndHalveMoneyOnBlackout::
+; Reset player status on blackout.
+ xor a
+ ld [wBattleResult], a
+ ld [wWalkBikeSurfState], a
+ ld [wIsInBattle], a
+ ld [wMapPalOffset], a
+ ld [wNPCMovementScriptFunctionNum], a
+ ld [hJoyHeld], a
+ ld [wNPCMovementScriptPointerTableNum], a
+ ld [wFlags_0xcd60], a
+
+ ld [hMoney], a
+ ld [hMoney + 1], a
+ ld [hMoney + 2], a
+ call HasEnoughMoney
+ jr c, .lostmoney ; never happens
+
+ ; Halve the player's money.
+ ld a, [wPlayerMoney]
+ ld [hMoney], a
+ ld a, [wPlayerMoney + 1]
+ ld [hMoney + 1], a
+ ld a, [wPlayerMoney + 2]
+ ld [hMoney + 2], a
+ xor a
+ ld [hDivideBCDDivisor], a
+ ld [hDivideBCDDivisor + 1], a
+ ld a, 2
+ ld [hDivideBCDDivisor + 2], a
+ predef DivideBCDPredef3
+ ld a, [hDivideBCDQuotient]
+ ld [wPlayerMoney], a
+ ld a, [hDivideBCDQuotient + 1]
+ ld [wPlayerMoney + 1], a
+ ld a, [hDivideBCDQuotient + 2]
+ ld [wPlayerMoney + 2], a
+
+.lostmoney
+ ld hl, wd732
+ set 2, [hl]
+ res 3, [hl]
+ set 6, [hl]
+ ld a, %11111111
+ ld [wJoyIgnore], a
+ predef_jump HealParty
diff --git a/engine/cable_club.asm b/engine/cable_club.asm
index 2cfb1734..474dbd11 100755
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -1,19 +1,19 @@
-; performs the appropriate action when the player uses the gameboy on the table in the Colosseum or Trade Centre
-; In the Colosseum, it starts a battle. In the Trade Centre, it displays the trade selection screen.
+; performs the appropriate action when the player uses the gameboy on the table in the Colosseum or Trade Center
+; In the Colosseum, it starts a battle. In the Trade Center, it displays the trade selection screen.
; Before doing either action, it swaps random numbers, trainer names and party data with the other gameboy.
-CableClub_DoBattleOrTrade: ; 5317 (1:5317)
- ld c, $50
+CableClub_DoBattleOrTrade:
+ ld c, 80
call DelayFrames
call ClearScreen
call UpdateSprites
call LoadFontTilePatterns
call LoadHpBarAndStatusTilePatterns
call LoadTrainerInfoTextBoxTiles
- hlCoord 3, 8
+ coord hl, 3, 8
ld b, 2
ld c, 12
call CableClub_TextBoxBorder
- hlCoord 4, 10
+ coord hl, 4, 10
ld de, PleaseWaitString
call PlaceString
ld hl, wPlayerNumHits
@@ -23,14 +23,14 @@ CableClub_DoBattleOrTrade: ; 5317 (1:5317)
; fall through
; This is called after completing a trade.
-CableClub_DoBattleOrTradeAgain: ; 5345
+CableClub_DoBattleOrTradeAgain:
ld hl, wSerialPlayerDataBlock
ld a, SERIAL_PREAMBLE_BYTE
ld b, 6
-.writePlayeDataBlockPreambleLoop
+.writePlayerDataBlockPreambleLoop
ld [hli], a
dec b
- jr nz, .writePlayeDataBlockPreambleLoop
+ jr nz, .writePlayerDataBlockPreambleLoop
ld hl, wSerialRandomNumberListBlock
ld a, SERIAL_PREAMBLE_BYTE
ld b, 7
@@ -57,8 +57,8 @@ CableClub_DoBattleOrTradeAgain: ; 5345
ld [hli], a
dec b
jr nz, .zeroPlayerDataPatchListLoop
- ld hl, W_GRASSRATE
- ld bc, W_TRAINERHEADERPTR - W_GRASSRATE
+ ld hl, wGrassRate
+ ld bc, wTrainerHeaderPtr - wGrassRate
.zeroEnemyPartyLoop
xor a
ld [hli], a
@@ -96,7 +96,7 @@ CableClub_DoBattleOrTradeAgain: ; 5345
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a ; end of part 1
inc de
- ld bc, $100
+ lb bc, 1, 0
jr .patchPartyMonsLoop
.finishedPatchingPlayerData
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
@@ -176,7 +176,7 @@ CableClub_DoBattleOrTradeAgain: ; 5345
jr z, .findStartOfEnemyNameLoop
dec hl
ld de, wLinkEnemyTrainerName
- ld c, 11
+ ld c, NAME_LENGTH
.copyEnemyNameLoop
ld a, [hli]
cp SERIAL_NO_DATA_BYTE
@@ -186,7 +186,7 @@ CableClub_DoBattleOrTradeAgain: ; 5345
dec c
jr nz, .copyEnemyNameLoop
ld de, wEnemyPartyCount
- ld bc, W_TRAINERHEADERPTR - wEnemyPartyCount
+ ld bc, wTrainerHeaderPtr - wEnemyPartyCount
.copyEnemyPartyLoop
ld a, [hli]
cp SERIAL_NO_DATA_BYTE
@@ -256,9 +256,9 @@ CableClub_DoBattleOrTradeAgain: ; 5345
dec c
jr nz, .unpatchEnemyMonsLoop
ld a, wEnemyMonOT % $100
- ld [wcf8d], a
+ ld [wUnusedCF8D], a
ld a, wEnemyMonOT / $100
- ld [wcf8e], a
+ ld [wUnusedCF8D + 1], a
xor a
ld [wTradeCenterPointerTableIndex], a
ld a, $ff
@@ -271,25 +271,25 @@ CableClub_DoBattleOrTradeAgain: ; 5345
cp LINK_STATE_START_BATTLE
ld a, LINK_STATE_TRADING
ld [wLinkState], a
- jr nz, .asm_5506
+ jr nz, .trading
ld a, LINK_STATE_BATTLING
ld [wLinkState], a
- ld a, SONY1 + $c8
- ld [W_CUROPPONENT], a
+ ld a, OPP_SONY1
+ ld [wCurOpponent], a
call ClearScreen
call Delay3
- ld hl, W_OPTIONS
+ ld hl, wOptions
res 7, [hl]
predef InitOpponent
predef HealParty
jp ReturnToCableClubRoom
-.asm_5506
+.trading
ld c, BANK(Music_GameCorner)
ld a, MUSIC_GAME_CORNER
call PlayMusic
jr CallCurrentTradeCenterFunction
-PleaseWaitString: ; 550f (1:550f)
+PleaseWaitString:
db "PLEASE WAIT!@"
CallCurrentTradeCenterFunction:
@@ -297,7 +297,7 @@ CallCurrentTradeCenterFunction:
ld b, 0
ld a, [wTradeCenterPointerTableIndex]
cp $ff
- jp z, LoadTitlescreenGraphics
+ jp z, DisplayTitleScreen
add a
ld c, a
add hl, bc
@@ -317,7 +317,7 @@ TradeCenter_SelectMon:
ld [hli], a
ld [hli], a
ld [hl], a
- ld [wcc37], a
+ ld [wMenuWatchMovingOutOfBounds], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld [wMenuJoypadPollCount], a
@@ -326,7 +326,7 @@ TradeCenter_SelectMon:
jp .playerMonMenu
.enemyMonMenu
xor a
- ld [wcc37], a
+ ld [wMenuWatchMovingOutOfBounds], a
inc a
ld [wWhichTradeMonSelectionMenu], a
ld a, D_DOWN | D_LEFT | A_BUTTON
@@ -357,9 +357,9 @@ TradeCenter_SelectMon:
dec a
ld [wCurrentMenuItem], a
.displayEnemyMonStats
- ld a, $1
- ld [wd11b], a
- callab Func_39bd5
+ ld a, INIT_ENEMYOT_LIST
+ ld [wInitListType], a
+ callab InitList ; the list isn't used
ld hl, wEnemyMons
call TradeCenter_DisplayStats
jp .getNewInput
@@ -390,7 +390,7 @@ TradeCenter_SelectMon:
.playerMonMenu
xor a ; player mon menu
ld [wWhichTradeMonSelectionMenu], a
- ld [wcc37], a
+ ld [wMenuWatchMovingOutOfBounds], a
ld a, D_DOWN | D_RIGHT | A_BUTTON
ld [wMenuWatchedKeys], a
ld a, [wPartyCount]
@@ -399,8 +399,8 @@ TradeCenter_SelectMon:
ld [wTopMenuItemY], a
ld a, 1
ld [wTopMenuItemX], a
- hlCoord 1, 1
- ld bc, $0601
+ coord hl, 1, 1
+ lb bc, 6, 1
call ClearScreenArea
.playerMonMenu_HandleInput
ld hl, hFlags_0xFFF6
@@ -416,9 +416,9 @@ TradeCenter_SelectMon:
jr z, .playerMonMenu_ANotPressed
jp .chosePlayerMon ; jump if A button pressed
; unreachable code
- ld a, $4
- ld [wd11b], a
- callab Func_39bd5
+ ld a, INIT_PLAYEROT_LIST
+ ld [wInitListType], a
+ callab InitList ; the list isn't used
call TradeCenter_DisplayStats
jp .getNewInput
.playerMonMenu_ANotPressed
@@ -464,11 +464,11 @@ TradeCenter_SelectMon:
dec a
.displayStatsTradeMenu
push af
- hlCoord 0, 14
+ coord hl, 0, 14
ld b, 2
ld c, 18
call CableClub_TextBoxBorder
- hlCoord 2, 16
+ coord hl, 2, 16
ld de, .statsTrade
call PlaceString
xor a
@@ -511,9 +511,9 @@ TradeCenter_SelectMon:
.displayPlayerMonStats
pop af
ld [wCurrentMenuItem], a
- ld a, $4
- ld [wd11b], a
- callab Func_39bd5
+ ld a, INIT_PLAYEROT_LIST
+ ld [wInitListType], a
+ callab InitList ; the list isn't used
call TradeCenter_DisplayStats
call LoadScreenTilesFromBuffer1
jp .playerMonMenu
@@ -547,11 +547,11 @@ TradeCenter_SelectMon:
ld a, " "
ld [hl], a
.cancelMenuItem_Loop
- ld a, $ed ; filled arrow cursor
+ ld a, "▶" ; filled arrow cursor
Coorda 1, 16
.cancelMenuItem_JoypadLoop
call JoypadLowSensitivity
- ld a, [$ffb5]
+ ld a, [hJoy5]
and a ; pressed anything?
jr z, .cancelMenuItem_JoypadLoop
bit 0, a ; A button pressed?
@@ -566,7 +566,7 @@ TradeCenter_SelectMon:
ld [wCurrentMenuItem], a
jp .playerMonMenu
.cancelMenuItem_APressed
- ld a, $ec ; unfilled arrow cursor
+ ld a, "▷" ; unfilled arrow cursor
Coorda 1, 16
ld a, $f
ld [wSerialExchangeNybbleSendData], a
@@ -576,7 +576,7 @@ TradeCenter_SelectMon:
jr nz, .cancelMenuItem_Loop
; fall through
-ReturnToCableClubRoom: ; 577d (1:577d)
+ReturnToCableClubRoom:
call GBPalWhiteOutWithDelay3
ld hl, wFontLoaded
ld a, [hl]
@@ -588,7 +588,7 @@ ReturnToCableClubRoom: ; 577d (1:577d)
dec a
ld [wDestinationWarpID], a
call LoadMapData
- callba ClearVariablesAfterLoadingMapData
+ callba ClearVariablesOnEnterMap
pop hl
pop af
ld [hl], a
@@ -596,15 +596,15 @@ ReturnToCableClubRoom: ; 577d (1:577d)
ret
TradeCenter_DrawCancelBox:
- hlCoord 11, 15
+ coord hl, 11, 15
ld a, $7e
- ld bc, 2 * 20 + 9
+ ld bc, 2 * SCREEN_WIDTH + 9
call FillMemory
- hlCoord 0, 15
+ coord hl, 0, 15
ld b, 1
ld c, 9
call CableClub_TextBoxBorder
- hlCoord 2, 16
+ coord hl, 2, 16
ld de, CancelTextString
jp PlaceString
@@ -613,10 +613,10 @@ CancelTextString:
TradeCenter_PlaceSelectedEnemyMonMenuCursor:
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
- hlCoord 1, 9
- ld bc, 20
+ coord hl, 1, 9
+ ld bc, SCREEN_WIDTH
call AddNTimes
- ld [hl], $ec ; cursor
+ ld [hl], "▷" ; cursor
ret
TradeCenter_DisplayStats:
@@ -630,24 +630,24 @@ TradeCenter_DisplayStats:
jp TradeCenter_DrawCancelBox
TradeCenter_DrawPartyLists:
- hlCoord 0, 0
+ coord hl, 0, 0
ld b, 6
ld c, 18
call CableClub_TextBoxBorder
- hlCoord 0, 8
+ coord hl, 0, 8
ld b, 6
ld c, 18
call CableClub_TextBoxBorder
- hlCoord 5, 0
+ coord hl, 5, 0
ld de, wPlayerName
call PlaceString
- hlCoord 5, 8
+ coord hl, 5, 8
ld de, wLinkEnemyTrainerName
call PlaceString
- hlCoord 2, 1
+ coord hl, 2, 1
ld de, wPartySpecies
call TradeCenter_PrintPartyListNames
- hlCoord 2, 9
+ coord hl, 2, 9
ld de, wEnemyPartyMons
; fall through
@@ -682,9 +682,9 @@ TradeCenter_Trade:
xor a
ld [wSerialExchangeNybbleSendData + 1], a ; unnecessary
ld [wSerialExchangeNybbleReceiveData], a
- ld [wcc37], a
+ ld [wMenuWatchMovingOutOfBounds], a
ld [wMenuJoypadPollCount], a
- hlCoord 0, 12
+ coord hl, 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
@@ -698,7 +698,7 @@ TradeCenter_Trade:
call GetMonName
ld hl, wcd6d
ld de, wNameOfPlayerMonToBeTraded
- ld bc, 11
+ ld bc, NAME_LENGTH
call CopyData
ld a, [wTradingWhichEnemyMon]
ld hl, wEnemyPartyMons
@@ -709,11 +709,11 @@ TradeCenter_Trade:
ld [wd11e], a
call GetMonName
ld hl, WillBeTradedText
- bcCoord 1, 14
+ coord bc, 1, 14
call TextCommandProcessor
call SaveScreenTilesToBuffer1
- hlCoord 10, 7
- ld bc, $080b
+ coord hl, 10, 7
+ lb bc, 8, 11
ld a, TRADE_CANCEL_MENU
ld [wTwoOptionMenuID], a
ld a, TWO_OPTION_MENU
@@ -726,11 +726,11 @@ TradeCenter_Trade:
; if trade cancelled
ld a, $1
ld [wSerialExchangeNybbleSendData], a
- hlCoord 0, 12
+ coord hl, 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
- hlCoord 1, 14
+ coord hl, 1, 14
ld de, TradeCanceled
call PlaceString
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
@@ -743,11 +743,11 @@ TradeCenter_Trade:
dec a ; did the other person cancel?
jr nz, .doTrade
; if the other person cancelled
- hlCoord 0, 12
+ coord hl, 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
- hlCoord 1, 14
+ coord hl, 1, 14
ld de, TradeCanceled
call PlaceString
jp .tradeCancelled
@@ -756,7 +756,7 @@ TradeCenter_Trade:
ld hl, wPartyMonOT
call SkipFixedLengthTextEntries
ld de, wTradedPlayerMonOT
- ld bc, 11
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wPartyMon1Species
ld a, [wTradingWhichPlayerMon]
@@ -772,7 +772,7 @@ TradeCenter_Trade:
ld hl, wEnemyMonOT
call SkipFixedLengthTextEntries
ld de, wTradedEnemyMonOT
- ld bc, 11
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wEnemyMons
ld a, [wTradingWhichEnemyMon]
@@ -793,7 +793,7 @@ TradeCenter_Trade:
ld a, [hl]
ld [wTradedPlayerMonSpecies], a
xor a
- ld [wcf95], a
+ ld [wRemoveMonFromBox], a
call RemovePokemon
ld a, [wTradingWhichEnemyMon]
ld c, a
@@ -816,7 +816,7 @@ TradeCenter_Trade:
dec a
ld [wWhichPokemon], a
ld a, $1
- ld [wccd4], a
+ ld [wForceEvolution], a
ld a, [wTradingWhichEnemyMon]
ld hl, wEnemyPartyMons
ld b, 0
@@ -824,19 +824,19 @@ TradeCenter_Trade:
add hl, bc
ld a, [hl]
ld [wTradedEnemyMonSpecies], a
- ld a, $a
- ld [wMusicHeaderPointer], a
+ ld a, 10
+ ld [wAudioFadeOutControl], a
ld a, $2
- ld [wc0f0], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_SAFARI_ZONE
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld c, 100
call DelayFrames
call ClearScreen
call LoadHpBarAndStatusTilePatterns
xor a
- ld [wcc5b], a
+ ld [wUnusedCC5B], a
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .usingExternalClock
@@ -851,11 +851,11 @@ TradeCenter_Trade:
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
ld c, 40
call DelayFrames
- hlCoord 0, 12
+ coord hl, 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
- hlCoord 1, 14
+ coord hl, 1, 14
ld de, TradeCompleted
call PlaceString
predef SaveSAVtoSRAM2
@@ -871,7 +871,7 @@ TradeCenter_Trade:
ld [wTradeCenterPointerTableIndex], a
jp CallCurrentTradeCenterFunction
-WillBeTradedText: ; 5a24 (1:5a24)
+WillBeTradedText:
TX_FAR _WillBeTradedText
db "@"
@@ -882,11 +882,11 @@ TradeCanceled:
db "Too bad! The trade"
next "was canceled!@"
-TradeCenterPointerTable: ; 5a5b (1:5a5b)
+TradeCenterPointerTable:
dw TradeCenter_SelectMon
dw TradeCenter_Trade
-CableClub_Run: ; 5a5f (1:5a5f)
+CableClub_Run:
ld a, [wLinkState]
cp LINK_STATE_START_TRADE
jr z, .doBattleOrTrade
@@ -900,38 +900,38 @@ CableClub_Run: ; 5a5f (1:5a5f)
call CableClub_DoBattleOrTrade
ld hl, Club_GFX
ld a, h
- ld [W_TILESETGFXPTR + 1], a
+ ld [wTilesetGfxPtr + 1], a
ld a, l
- ld [W_TILESETGFXPTR], a
+ ld [wTilesetGfxPtr], a
ld a, Bank(Club_GFX)
- ld [W_TILESETBANK], a
+ ld [wTilesetBank], a
ld hl, Club_Coll
ld a, h
- ld [W_TILESETCOLLISIONPTR + 1], a
+ ld [wTilesetCollisionPtr + 1], a
ld a, l
- ld [W_TILESETCOLLISIONPTR], a
+ ld [wTilesetCollisionPtr], a
xor a
- ld [W_GRASSRATE], a
+ ld [wGrassRate], a
inc a ; LINK_STATE_IN_CABLE_CLUB
ld [wLinkState], a
- ld [$ffb5], a
- ld a, $a
- ld [wMusicHeaderPointer], a
+ ld [hJoy5], a
+ ld a, 10
+ ld [wAudioFadeOutControl], a
ld a, BANK(Music_Celadon)
- ld [wc0f0], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_CELADON
- ld [wc0ee], a
+ ld [wNewSoundID], a
jp PlaySound
-EmptyFunc3: ; 5aaf (1:5aaf)
+EmptyFunc3:
ret
-Diploma_TextBoxBorder: ; 5ab0 (1:5ab0)
+Diploma_TextBoxBorder:
call GetPredefRegisters
; b = height
; c = width
-CableClub_TextBoxBorder: ; 5ab3 (1:5ab3)
+CableClub_TextBoxBorder:
push hl
ld a, $78 ; border upper left corner tile
ld [hli], a
@@ -962,10 +962,16 @@ CableClub_TextBoxBorder: ; 5ab3 (1:5ab3)
ret
; c = width
-CableClub_DrawHorizontalLine: ; 5ae0 (1:5ae0)
+CableClub_DrawHorizontalLine:
ld d, c
-.asm_5ae1
+.loop
ld [hli], a
dec d
- jr nz, .asm_5ae1
+ jr nz, .loop
ret
+
+LoadTrainerInfoTextBoxTiles:
+ ld de, TrainerInfoTextBoxTileGraphics
+ ld hl, vChars2 + $760
+ lb bc, BANK(TrainerInfoTextBoxTileGraphics), (TrainerInfoTextBoxTileGraphicsEnd - TrainerInfoTextBoxTileGraphics) / $10
+ jp CopyVideoData
diff --git a/engine/clear_save.asm b/engine/clear_save.asm
index 66d7e920..b47cd6c4 100755
--- a/engine/clear_save.asm
+++ b/engine/clear_save.asm
@@ -1,12 +1,12 @@
-DoClearSaveDialogue: ; 1c98a (7:498a)
+DoClearSaveDialogue:
call ClearScreen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call LoadFontTilePatterns
call LoadTextBoxTilePatterns
ld hl, ClearSaveDataText
call PrintText
- hlCoord 14, 7
- ld bc, $80f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a, NO_YES_MENU
ld [wTwoOptionMenuID], a
ld a, TWO_OPTION_MENU
@@ -18,6 +18,6 @@ DoClearSaveDialogue: ; 1c98a (7:498a)
callba ClearSAV
jp Init
-ClearSaveDataText: ; 1c9c1 (7:49c1)
+ClearSaveDataText:
TX_FAR _ClearSaveDataText
db "@"
diff --git a/engine/debug1.asm b/engine/debug1.asm
new file mode 100644
index 00000000..a5eb7dde
--- /dev/null
+++ b/engine/debug1.asm
@@ -0,0 +1,33 @@
+; This function appears to never be used.
+; It is likely a debugging feature to give the player Tsunekazu Ishihara's
+; favorite Pokemon. This is indicated by the overpowered Exeggutor, which
+; Ishihara (president of Creatures Inc.) said was his favorite Pokemon in an ABC
+; interview on February 8, 2000.
+; "Exeggutor is my favorite. That's because I was always using this character
+; while I was debugging the program."
+; http://www.ign.com/articles/2000/02/09/abc-news-pokamon-chat-transcript
+
+SetIshiharaTeam:
+ ld de, IshiharaTeam
+.loop
+ ld a, [de]
+ cp $ff
+ ret z
+ ld [wcf91], a
+ inc de
+ ld a, [de]
+ ld [wCurEnemyLVL], a
+ inc de
+ call AddPartyMon
+ jr .loop
+
+IshiharaTeam:
+ db EXEGGUTOR,90
+ db MEW,20
+ db JOLTEON,56
+ db DUGTRIO,56
+ db ARTICUNO,57
+ db $FF
+
+EmptyFunc:
+ ret
diff --git a/engine/display_pokedex.asm b/engine/display_pokedex.asm
new file mode 100644
index 00000000..96a2dd6c
--- /dev/null
+++ b/engine/display_pokedex.asm
@@ -0,0 +1,19 @@
+_DisplayPokedex:
+ ld hl, wd730
+ set 6, [hl]
+ predef ShowPokedexData
+ ld hl, wd730
+ res 6, [hl]
+ call ReloadMapData
+ ld c, 10
+ call DelayFrames
+ predef IndexToPokedex
+ ld a, [wd11e]
+ dec a
+ ld c, a
+ ld b, FLAG_SET
+ ld hl, wPokedexSeen
+ predef FlagActionPredef
+ ld a, $1
+ ld [wDoNotWaitForButtonPressAfterDisplayingText], a
+ ret
diff --git a/engine/display_text_id_init.asm b/engine/display_text_id_init.asm
new file mode 100644
index 00000000..312d6329
--- /dev/null
+++ b/engine/display_text_id_init.asm
@@ -0,0 +1,78 @@
+; function that performs initialization for DisplayTextID
+DisplayTextIDInit:
+ xor a
+ ld [wListMenuID],a
+ ld a,[wAutoTextBoxDrawingControl]
+ bit 0,a
+ jr nz,.skipDrawingTextBoxBorder
+ ld a,[hSpriteIndexOrTextID] ; text ID (or sprite ID)
+ and a
+ jr nz,.notStartMenu
+; if text ID is 0 (i.e. the start menu)
+; Note that the start menu text border is also drawn in the function directly
+; below this, so this seems unnecessary.
+ CheckEvent EVENT_GOT_POKEDEX
+; start menu with pokedex
+ coord hl, 10, 0
+ ld b,$0e
+ ld c,$08
+ jr nz,.drawTextBoxBorder
+; start menu without pokedex
+ coord hl, 10, 0
+ ld b,$0c
+ ld c,$08
+ jr .drawTextBoxBorder
+; if text ID is not 0 (i.e. not the start menu) then do a standard dialogue text box
+.notStartMenu
+ coord hl, 0, 12
+ ld b,$04
+ ld c,$12
+.drawTextBoxBorder
+ call TextBoxBorder
+.skipDrawingTextBoxBorder
+ ld hl,wFontLoaded
+ set 0,[hl]
+ ld hl,wFlags_0xcd60
+ bit 4,[hl]
+ res 4,[hl]
+ jr nz,.skipMovingSprites
+ call UpdateSprites
+.skipMovingSprites
+; loop to copy C1X9 (direction the sprite is facing) to C2X9 for each sprite
+; this is done because when you talk to an NPC, they turn to look your way
+; the original direction they were facing must be restored after the dialogue is over
+ ld hl,wSpriteStateData1 + $19
+ ld c,$0f
+ ld de,$0010
+.spriteFacingDirectionCopyLoop
+ ld a,[hl]
+ inc h
+ ld [hl],a
+ dec h
+ add hl,de
+ dec c
+ jr nz,.spriteFacingDirectionCopyLoop
+; loop to force all the sprites in the middle of animation to stand still
+; (so that they don't like they're frozen mid-step during the dialogue)
+ ld hl,wSpriteStateData1 + 2
+ ld de,$0010
+ ld c,e
+.spriteStandStillLoop
+ ld a,[hl]
+ cp a,$ff ; is the sprite visible?
+ jr z,.nextSprite
+; if it is visible
+ and a,$fc
+ ld [hl],a
+.nextSprite
+ add hl,de
+ dec c
+ jr nz,.spriteStandStillLoop
+ ld b,$9c ; window background address
+ call CopyScreenTileBufferToVRAM ; transfer background in WRAM to VRAM
+ xor a
+ ld [hWY],a ; put the window on the screen
+ call LoadFontTilePatterns
+ ld a,$01
+ ld [H_AUTOBGTRANSFERENABLED],a ; enable continuous WRAM to VRAM transfer each V-blank
+ ret
diff --git a/engine/evolution.asm b/engine/evolution.asm
index 7ae88fdf..a2c52765 100755
--- a/engine/evolution.asm
+++ b/engine/evolution.asm
@@ -1,4 +1,4 @@
-Func_7bde9: ; 7bde9 (1e:7de9)
+EvolveMon:
push hl
push de
push bc
@@ -8,72 +8,72 @@ Func_7bde9: ; 7bde9 (1e:7de9)
push af
xor a
ld [wLowHealthAlarm], a
- ld [wc02a], a
+ ld [wChannelSoundIDs + Ch4], a
dec a
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, (SFX_08_3c - SFX_Headers_08) / 3
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, SFX_TINK
call PlaySound
call Delay3
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
ld [hTilesetType], a
- ld a, [wHPBarMaxHP]
- ld [wcf1d], a
- ld c, $0
- call Func_7beb4
- ld a, [wHPBarMaxHP + 1]
+ ld a, [wEvoOldSpecies]
+ ld [wWholeScreenPaletteMonSpecies], a
+ ld c, 0
+ call EvolutionSetWholeScreenPalette
+ ld a, [wEvoNewSpecies]
ld [wcf91], a
ld [wd0b5], a
- call Func_7beb9
+ call Evolution_LoadPic
ld de, vFrontPic
ld hl, vBackPic
ld bc, 7 * 7
call CopyVideoData
- ld a, [wHPBarMaxHP]
+ ld a, [wEvoOldSpecies]
ld [wcf91], a
ld [wd0b5], a
- call Func_7beb9
+ call Evolution_LoadPic
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, [wHPBarMaxHP]
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [wEvoOldSpecies]
call PlayCry
call WaitForSoundToFinish
ld c, BANK(Music_SafariZone)
ld a, MUSIC_SAFARI_ZONE
call PlayMusic
- ld c, $50
+ ld c, 80
call DelayFrames
- ld c, $1
- call Func_7beb4
- ld bc, $110
-.asm_7be63
+ ld c, 1 ; set PAL_BLACK instead of mon palette
+ call EvolutionSetWholeScreenPalette
+ lb bc, $1, $10
+.animLoop
push bc
- call asm_7befa
- jr c, .asm_7bea9
- call asm_7bec2
+ call Evolution_CheckForCancel
+ jr c, .evolutionCancelled
+ call Evolution_BackAndForthAnim
pop bc
inc b
dec c
dec c
- jr nz, .asm_7be63
+ jr nz, .animLoop
xor a
- ld [wHPBarOldHP + 1], a
+ ld [wEvoCancelled], a
ld a, $31
- ld [wHPBarOldHP], a
- call Func_7bed6
- ld a, [wHPBarMaxHP + 1]
-.asm_7be81
- ld [wcf1d], a
+ ld [wEvoMonTileOffset], a
+ call Evolution_ChangeMonPic ; show the new species pic
+ ld a, [wEvoNewSpecies]
+.done
+ ld [wWholeScreenPaletteMonSpecies], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
- ld a, [wcf1d]
+ ld a, [wWholeScreenPaletteMonSpecies]
call PlayCry
- ld c, $0
- call Func_7beb4
+ ld c, 0
+ call EvolutionSetWholeScreenPalette
pop af
ld [wd0b5], a
pop af
@@ -81,77 +81,80 @@ Func_7bde9: ; 7bde9 (1e:7de9)
pop bc
pop de
pop hl
- ld a, [wHPBarOldHP + 1]
+ ld a, [wEvoCancelled]
and a
ret z
scf
ret
-.asm_7bea9
+.evolutionCancelled
pop bc
- ld a, $1
- ld [wHPBarOldHP + 1], a
- ld a, [wHPBarMaxHP]
- jr .asm_7be81
+ ld a, 1
+ ld [wEvoCancelled], a
+ ld a, [wEvoOldSpecies]
+ jr .done
-Func_7beb4: ; 7beb4 (1e:7eb4)
- ld b, $b
- jp GoPAL_SET
+EvolutionSetWholeScreenPalette:
+ ld b, SET_PAL_POKEMON_WHOLE_SCREEN
+ jp RunPaletteCommand
-Func_7beb9: ; 7beb9 (1e:7eb9)
+Evolution_LoadPic:
call GetMonHeader
- hlCoord 7, 2
+ coord hl, 7, 2
jp LoadFlippedFrontSpriteByMonIndex
-asm_7bec2: ; 7bec2 (1e:7ec2)
+
+Evolution_BackAndForthAnim:
+; show the mon change back and forth between the new and old species b times
ld a, $31
- ld [wHPBarOldHP], a
- call Func_7bed6
- ld a, $cf
- ld [wHPBarOldHP], a
- call Func_7bed6
+ ld [wEvoMonTileOffset], a
+ call Evolution_ChangeMonPic
+ ld a, -$31
+ ld [wEvoMonTileOffset], a
+ call Evolution_ChangeMonPic
dec b
- jr nz, asm_7bec2
+ jr nz, Evolution_BackAndForthAnim
ret
-Func_7bed6: ; 7bed6 (1e:7ed6)
+Evolution_ChangeMonPic:
push bc
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- hlCoord 7, 2
- ld bc, $707
- ld de, $d
-.asm_7bee3
+ ld [H_AUTOBGTRANSFERENABLED], a
+ coord hl, 7, 2
+ lb bc, 7, 7
+ ld de, SCREEN_WIDTH - 7
+.loop
push bc
-.asm_7bee4
- ld a, [wHPBarOldHP]
+.innerLoop
+ ld a, [wEvoMonTileOffset]
add [hl]
ld [hli], a
dec c
- jr nz, .asm_7bee4
+ jr nz, .innerLoop
pop bc
add hl, de
dec b
- jr nz, .asm_7bee3
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ jr nz, .loop
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
pop bc
ret
-asm_7befa: ; 7befa (1e:7efa)
+
+Evolution_CheckForCancel:
call DelayFrame
push bc
call JoypadLowSensitivity
ld a, [hJoy5]
pop bc
- and $2
- jr nz, .asm_7bf0d
-.asm_7bf08
+ and B_BUTTON
+ jr nz, .pressedB
+.notAllowedToCancel
dec c
- jr nz, asm_7befa
+ jr nz, Evolution_CheckForCancel
and a
ret
-.asm_7bf0d
- ld a, [wccd4]
+.pressedB
+ ld a, [wForceEvolution]
and a
- jr nz, .asm_7bf08
+ jr nz, .notAllowedToCancel
scf
ret
diff --git a/engine/evolve_trade.asm b/engine/evolve_trade.asm
index ec230677..e17fc05c 100755
--- a/engine/evolve_trade.asm
+++ b/engine/evolve_trade.asm
@@ -1,4 +1,4 @@
-EvolveTradeMon: ; 17d7d (5:7d7d)
+EvolveTradeMon:
; Verify the TradeMon's species name before
; attempting to initiate a trade evolution.
@@ -31,11 +31,11 @@ EvolveTradeMon: ; 17d7d (5:7d7d)
ret nz
.ok
- ld a, [wPartyCount] ; wPartyCount
+ ld a, [wPartyCount]
dec a
- ld [wWhichPokemon], a ; wWhichPokemon
+ ld [wWhichPokemon], a
ld a, $1
- ld [wccd4], a
+ ld [wForceEvolution], a
ld a, LINK_STATE_TRADING
ld [wLinkState], a
callab TryEvolvingMon
diff --git a/engine/evos_moves.asm b/engine/evos_moves.asm
index 23bffa8d..f50f8081 100755
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -1,20 +1,20 @@
; try to evolve the mon in [wWhichPokemon]
-TryEvolvingMon: ; 3ad0e (e:6d0e)
- ld hl, wccd3
+TryEvolvingMon:
+ ld hl, wCanEvolveFlags
xor a
ld [hl], a
ld a, [wWhichPokemon]
ld c, a
- ld b, $1
+ ld b, FLAG_SET
call Evolution_FlagAction
; this is only called after battle
; it is supposed to do level up evolutions, though there is a bug that allows item evolutions to occur
-EvolutionAfterBattle: ; 3ad1c (e:6d1c)
+EvolutionAfterBattle:
ld a, [hTilesetType]
push af
xor a
- ld [wd121], a
+ ld [wEvolutionOccurred], a
dec a
ld [wWhichPokemon], a
push hl
@@ -31,17 +31,17 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, [hl]
cp $ff ; have we reached the end of the party?
jp z, .done
- ld [wHPBarMaxHP], a
+ ld [wEvoOldSpecies], a
push hl
ld a, [wWhichPokemon]
ld c, a
- ld hl, wccd3
- ld b, $2
+ ld hl, wCanEvolveFlags
+ ld b, FLAG_TEST
call Evolution_FlagAction
ld a, c
and a ; is the mon's bit set?
jp z, Evolution_PartyMonLoop ; if not, go to the next mon
- ld a, [wHPBarMaxHP]
+ ld a, [wEvoOldSpecies]
dec a
ld b, 0
ld hl, EvosMovesPointerTable
@@ -55,8 +55,8 @@ Evolution_PartyMonLoop: ; loop over party mons
push hl
ld a, [wcf91]
push af
- xor a
- ld [wcc49], a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation], a
call LoadMonData
pop af
ld [wcf91], a
@@ -76,7 +76,7 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, b
cp EV_ITEM
jr z, .checkItemEvo
- ld a, [wccd4]
+ ld a, [wForceEvolution]
and a
jr nz, Evolution_PartyMonLoop
ld a, b
@@ -91,7 +91,7 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, [wLoadedMonLevel]
cp b ; is the mon's level greater than the evolution requirement?
jp c, Evolution_PartyMonLoop ; if so, go the next mon
- jr .asm_3adb6
+ jr .doEvolution
.checkItemEvo
ld a, [hli]
ld b, a ; evolution item
@@ -104,32 +104,32 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, [wLoadedMonLevel]
cp b ; is the mon's level greater than the evolution requirement?
jp c, .nextEvoEntry2 ; if so, go the next evolution entry
-.asm_3adb6
- ld [W_CURENEMYLVL], a
- ld a, $1
- ld [wd121], a
+.doEvolution
+ ld [wCurEnemyLVL], a
+ ld a, 1
+ ld [wEvolutionOccurred], a
push hl
ld a, [hl]
- ld [wHPBarMaxHP + 1], a
+ ld [wEvoNewSpecies], a
ld a, [wWhichPokemon]
ld hl, wPartyMonNicks
call GetPartyMonName
call CopyStringToCF4B
ld hl, IsEvolvingText
call PrintText
- ld c, $32
+ ld c, 50
call DelayFrames
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, wTileMap
- ld bc, $c14
+ coord hl, 0, 0
+ lb bc, 12, 20
call ClearScreenArea
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld a, $ff
ld [wUpdateSpritesEnabled], a
call ClearSprites
- callab Func_7bde9
+ callab EvolveMon
jp c, CancelledEvolution
ld hl, EvolvedText
call PrintText
@@ -137,7 +137,7 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, [hl]
ld [wd0b5], a
ld [wLoadedMonSpecies], a
- ld [wHPBarMaxHP + 1], a
+ ld [wEvoNewSpecies], a
ld a, MONSTER_NAME
ld [wNameListType], a
ld a, BANK(TrainerNames) ; bank is not used for monster names
@@ -145,11 +145,11 @@ Evolution_PartyMonLoop: ; loop over party mons
call GetName
push hl
ld hl, IntoText
- call Func_3c59
- ld a, (SFX_02_3b - SFX_Headers_02) / 3
+ call PrintText_NoCreatingTextBox
+ ld a, SFX_GET_ITEM_2
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
- ld c, $28
+ ld c, 40
call DelayFrames
call ClearScreen
call RenameEvolvedMon
@@ -161,12 +161,12 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, [wd11e]
dec a
ld hl, BaseStats
- ld bc, $1c
+ ld bc, MonBaseStatsEnd - MonBaseStats
call AddNTimes
- ld de, W_MONHEADER
+ ld de, wMonHeader
call CopyData
ld a, [wd0b5]
- ld [W_MONHDEXNUM], a
+ ld [wMonHIndex], a
pop af
ld [wd11e], a
ld hl, wLoadedMonHPExp - 1
@@ -206,18 +206,18 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, [wd0b5]
ld [wd11e], a
xor a
- ld [wcc49], a
+ ld [wMonDataLocation], a
call LearnMoveFromLevelUp
pop hl
predef SetPartyMonTypes
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
call z, Evolution_ReloadTilesetTilePatterns
predef IndexToPokedex
ld a, [wd11e]
dec a
ld c, a
- ld b, $1
+ ld b, FLAG_SET
ld hl, wPokedexOwned
push bc
call Evolution_FlagAction
@@ -249,20 +249,20 @@ Evolution_PartyMonLoop: ; loop over party mons
ld a, [wLinkState]
cp LINK_STATE_TRADING
ret z
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
ret nz
- ld a, [wd121]
+ ld a, [wEvolutionOccurred]
and a
call nz, PlayDefaultMusic
ret
-; checks if the evolved mon's name is different from the standard name (i.e. it has a nickname)
-; if so, rename it to is evolved form's standard name
-RenameEvolvedMon: ; 3aef7 (e:6ef7)
+RenameEvolvedMon:
+; Renames the mon to its new, evolved form's standard name unless it had a
+; nickname, in which case the nickname is kept.
ld a, [wd0b5]
push af
- ld a, [W_MONHDEXNUM]
+ ld a, [wMonHIndex]
ld [wd0b5], a
call GetName
pop af
@@ -275,10 +275,10 @@ RenameEvolvedMon: ; 3aef7 (e:6ef7)
cp [hl]
inc hl
ret nz
- cp $50
+ cp "@"
jr nz, .compareNamesLoop
ld a, [wWhichPokemon]
- ld bc, $b
+ ld bc, NAME_LENGTH
ld hl, wPartyMonNicks
call AddNTimes
push hl
@@ -287,7 +287,7 @@ RenameEvolvedMon: ; 3aef7 (e:6ef7)
pop de
jp CopyData
-CancelledEvolution: ; 3af2e (e:6f2e)
+CancelledEvolution:
ld hl, StoppedEvolvingText
call PrintText
call ClearScreen
@@ -295,29 +295,29 @@ CancelledEvolution: ; 3af2e (e:6f2e)
call Evolution_ReloadTilesetTilePatterns
jp Evolution_PartyMonLoop
-EvolvedText: ; 3af3e (e:6f3e)
+EvolvedText:
TX_FAR _EvolvedText
db "@"
-IntoText: ; 3af43 (e:6f43)
+IntoText:
TX_FAR _IntoText
db "@"
-StoppedEvolvingText: ; 3af48 (e:6f48)
+StoppedEvolvingText:
TX_FAR _StoppedEvolvingText
db "@"
-IsEvolvingText: ; 3af4d (e:6f4d)
+IsEvolvingText:
TX_FAR _IsEvolvingText
db "@"
-Evolution_ReloadTilesetTilePatterns: ; 3af52 (e:6f52)
+Evolution_ReloadTilesetTilePatterns:
ld a, [wLinkState]
cp LINK_STATE_TRADING
ret z
jp ReloadTilesetTilePatterns
-LearnMoveFromLevelUp: ; 3af5b (e:6f5b)
+LearnMoveFromLevelUp:
ld hl, EvosMovesPointerTable
ld a, [wd11e] ; species
ld [wcf91], a
@@ -340,23 +340,24 @@ LearnMoveFromLevelUp: ; 3af5b (e:6f5b)
and a ; have we reached the end of the learn set?
jr z, .done ; if we've reached the end of the learn set, jump
ld b, a ; level the move is learnt at
- ld a, [W_CURENEMYLVL]
+ ld a, [wCurEnemyLVL]
cp b ; is the move learnt at the mon's current level?
ld a, [hli] ; move ID
jr nz, .learnSetLoop
ld d, a ; ID of move to learn
- ld a, [wcc49]
+ ld a, [wMonDataLocation]
and a
jr nz, .next
-; if [wcc49] is 0, get the address of the mon's current moves
-; there is no reason to make this conditional because the code wouldn't work properly without doing this
-; every call to this function sets [wcc49] to 0
+; If [wMonDataLocation] is 0 (PLAYER_PARTY_DATA), get the address of the mon's
+; current moves in party data. Every call to this function sets
+; [wMonDataLocation] to 0 because other data locations are not supported.
+; If it is not 0, this function will not work properly.
ld hl, wPartyMon1Moves
ld a, [wWhichPokemon]
ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
.next
- ld b, $4
+ ld b, NUM_MOVES
.checkCurrentMovesLoop ; check if the move to learn is already known
ld a, [hli]
cp d
@@ -374,16 +375,15 @@ LearnMoveFromLevelUp: ; 3af5b (e:6f5b)
ld [wd11e], a
ret
-; writes the moves a mon has at level [W_CURENEMYLVL] to [de]
+; writes the moves a mon has at level [wCurEnemyLVL] to [de]
; move slots are being filled up sequentially and shifted if all slots are full
-; [wHPBarMaxHP]: (?)
-WriteMonMoves: ; 3afb8 (e:6fb8)
+WriteMonMoves:
call GetPredefRegisters
push hl
push de
push bc
ld hl, EvosMovesPointerTable
- ld b, $0
+ ld b, 0
ld a, [wcf91] ; cur mon ID
dec a
add a
@@ -407,28 +407,33 @@ WriteMonMoves: ; 3afb8 (e:6fb8)
and a
jp z, .done ; end of list
ld b, a
- ld a, [W_CURENEMYLVL] ; W_CURENEMYLVL
+ ld a, [wCurEnemyLVL]
cp b
jp c, .done ; mon level < move level (assumption: learnset is sorted by level)
- ld a, [wHPBarMaxHP]
+ ld a, [wLearningMovesFromDayCare]
and a
jr z, .skipMinLevelCheck
- ld a, [wWhichTrade] ; wWhichTrade (min move level)
+ ld a, [wDayCareStartLevel]
cp b
jr nc, .nextMove2 ; min level >= move level
+
.skipMinLevelCheck
+
+; check if the move is already known
push de
- ld c, $4
-.moveAlreadyLearnedCheckLoop
+ ld c, NUM_MOVES
+.alreadyKnowsCheckLoop
ld a, [de]
inc de
cp [hl]
jr z, .nextMove
dec c
- jr nz, .moveAlreadyLearnedCheckLoop
+ jr nz, .alreadyKnowsCheckLoop
+
+; try to find an empty move slot
pop de
push de
- ld c, $4
+ ld c, NUM_MOVES
.findEmptySlotLoop
ld a, [de]
and a
@@ -436,47 +441,55 @@ WriteMonMoves: ; 3afb8 (e:6fb8)
inc de
dec c
jr nz, .findEmptySlotLoop
- pop de ; no empty move slots found
+
+; no empty move slots found
+ pop de
push de
push hl
ld h, d
ld l, e
call WriteMonMoves_ShiftMoveData ; shift all moves one up (deleting move 1)
- ld a, [wHPBarMaxHP]
+ ld a, [wLearningMovesFromDayCare]
and a
jr z, .writeMoveToSlot
+
+; shift PP as well if learning moves from day care
push de
- ld bc, $12
+ ld bc, wPartyMon1PP - (wPartyMon1Moves + 3)
add hl, bc
ld d, h
ld e, l
call WriteMonMoves_ShiftMoveData ; shift all move PP data one up
pop de
+
.writeMoveToSlot
pop hl
.writeMoveToSlot2
ld a, [hl]
ld [de], a
- ld a, [wHPBarMaxHP]
+ ld a, [wLearningMovesFromDayCare]
and a
jr z, .nextMove
- push hl ; write move PP value
+
+; write move PP value if learning moves from day care
+ push hl
ld a, [hl]
- ld hl, $15
+ ld hl, wPartyMon1PP - wPartyMon1Moves
add hl, de
push hl
dec a
ld hl, Moves
- ld bc, $6
+ ld bc, MoveEnd - Moves
call AddNTimes
- ld de, wHPBarMaxHP
+ ld de, wBuffer
ld a, BANK(Moves)
call FarCopyData
- ld a, [wHPBarNewHP + 1]
+ ld a, [wBuffer + 5]
pop hl
ld [hl], a
pop hl
jr .nextMove
+
.done
pop bc
pop de
@@ -484,17 +497,17 @@ WriteMonMoves: ; 3afb8 (e:6fb8)
ret
; shifts all move data one up (freeing 4th move slot)
-WriteMonMoves_ShiftMoveData: ; 3b04e (e:704e)
- ld c, $3
-.asm_3b050
+WriteMonMoves_ShiftMoveData:
+ ld c, NUM_MOVES - 1
+.loop
inc de
ld a, [de]
ld [hli], a
dec c
- jr nz, .asm_3b050
+ jr nz, .loop
ret
-Evolution_FlagAction: ; 3b057 (e:7057)
+Evolution_FlagAction:
predef_jump FlagActionPredef
INCLUDE "data/evos_moves.asm"
diff --git a/engine/experience.asm b/engine/experience.asm
index 68d22843..2efc13de 100755
--- a/engine/experience.asm
+++ b/engine/experience.asm
@@ -1,5 +1,5 @@
; calculates the level a mon should be based on its current exp
-CalcLevelFromExperience: ; 58f43 (16:4f43)
+CalcLevelFromExperience:
ld a, [wLoadedMonSpecies]
ld [wd0b5], a
call GetMonHeader
@@ -10,15 +10,15 @@ CalcLevelFromExperience: ; 58f43 (16:4f43)
push hl
ld hl, wLoadedMonExp + 2 ; current exp
; compare exp needed for level d with current exp
- ld a, [H_MULTIPLICAND + 2]
+ ld a, [hExperience + 2]
ld c, a
ld a, [hld]
sub c
- ld a, [H_MULTIPLICAND + 1]
+ ld a, [hExperience + 1]
ld c, a
ld a, [hld]
sbc c
- ld a, [H_MULTIPLICAND]
+ ld a, [hExperience]
ld c, a
ld a, [hl]
sbc c
@@ -28,118 +28,122 @@ CalcLevelFromExperience: ; 58f43 (16:4f43)
ret
; calculates the amount of experience needed for level d
-CalcExperience: ; 58f6a (16:4f6a)
- ld a, [W_MONHGROWTHRATE]
+CalcExperience:
+ ld a, [wMonHGrowthRate]
add a
add a
ld c, a
- ld b, $0
+ ld b, 0
ld hl, GrowthRateTable
add hl, bc
call CalcDSquared
ld a, d
- ld [H_MULTIPLIER], a ; $ff99
+ ld [H_MULTIPLIER], a
call Multiply
ld a, [hl]
and $f0
swap a
- ld [H_MULTIPLIER], a ; $ff99
+ ld [H_MULTIPLIER], a
call Multiply
ld a, [hli]
and $f
- ld [H_DIVISOR], a ; $ff99
+ ld [H_DIVISOR], a
ld b, $4
call Divide
- ld a, [H_MULTIPLICAND] ; $ff96 (aliases: H_NUMTOPRINT)
+ ld a, [H_QUOTIENT + 1]
push af
- ld a, [H_MULTIPLICAND+1]
+ ld a, [H_QUOTIENT + 2]
push af
- ld a, [H_MULTIPLICAND+2]
+ ld a, [H_QUOTIENT + 3]
push af
call CalcDSquared
ld a, [hl]
and $7f
- ld [H_MULTIPLIER], a ; $ff99
+ ld [H_MULTIPLIER], a
call Multiply
- ld a, [H_MULTIPLICAND] ; $ff96 (aliases: H_NUMTOPRINT)
+ ld a, [H_PRODUCT + 1]
push af
- ld a, [H_MULTIPLICAND+1]
+ ld a, [H_PRODUCT + 2]
push af
- ld a, [H_MULTIPLICAND+2]
+ ld a, [H_PRODUCT + 3]
push af
ld a, [hli]
push af
xor a
- ld [H_MULTIPLICAND], a ; $ff96
- ld [H_MULTIPLICAND+1], a
+ ld [H_MULTIPLICAND], a
+ ld [H_MULTIPLICAND + 1], a
ld a, d
- ld [H_MULTIPLICAND+2], a
+ ld [H_MULTIPLICAND + 2], a
ld a, [hli]
ld [H_MULTIPLIER], a
call Multiply
ld b, [hl]
- ld a, [H_MULTIPLICAND+2]
+ ld a, [H_PRODUCT + 3]
sub b
- ld [H_MULTIPLICAND+2], a
+ ld [H_PRODUCT + 3], a
ld b, $0
- ld a, [H_MULTIPLICAND+1]
+ ld a, [H_PRODUCT + 2]
sbc b
- ld [H_MULTIPLICAND+1], a
- ld a, [H_MULTIPLICAND] ; $ff96
+ ld [H_PRODUCT + 2], a
+ ld a, [H_PRODUCT + 1]
sbc b
- ld [H_MULTIPLICAND], a ; $ff96
+ ld [H_PRODUCT + 1], a
+; The difference of the linear term and the constant term consists of 3 bytes
+; starting at H_PRODUCT + 1. Below, hExperience (an alias of that address) will
+; be used instead for the further work of adding or subtracting the squared
+; term and adding the cubed term.
pop af
and $80
jr nz, .subtractSquaredTerm ; check sign
pop bc
- ld a, [H_MULTIPLICAND+2]
+ ld a, [hExperience + 2]
add b
- ld [H_MULTIPLICAND+2], a
+ ld [hExperience + 2], a
pop bc
- ld a, [H_MULTIPLICAND+1]
+ ld a, [hExperience + 1]
adc b
- ld [H_MULTIPLICAND+1], a
+ ld [hExperience + 1], a
pop bc
- ld a, [H_MULTIPLICAND]
+ ld a, [hExperience]
adc b
- ld [H_MULTIPLICAND], a
+ ld [hExperience], a
jr .addCubedTerm
.subtractSquaredTerm
pop bc
- ld a, [H_MULTIPLICAND+2]
+ ld a, [hExperience + 2]
sub b
- ld [H_MULTIPLICAND+2], a
+ ld [hExperience + 2], a
pop bc
- ld a, [H_MULTIPLICAND+1]
+ ld a, [hExperience + 1]
sbc b
- ld [H_MULTIPLICAND+1], a
+ ld [hExperience + 1], a
pop bc
- ld a, [H_MULTIPLICAND]
+ ld a, [hExperience]
sbc b
- ld [H_MULTIPLICAND], a
+ ld [hExperience], a
.addCubedTerm
pop bc
- ld a, [H_MULTIPLICAND+2]
+ ld a, [hExperience + 2]
add b
- ld [H_MULTIPLICAND+2], a
+ ld [hExperience + 2], a
pop bc
- ld a, [H_MULTIPLICAND+1]
+ ld a, [hExperience + 1]
adc b
- ld [H_MULTIPLICAND+1], a
+ ld [hExperience + 1], a
pop bc
- ld a, [H_MULTIPLICAND]
+ ld a, [hExperience]
adc b
- ld [H_MULTIPLICAND], a
+ ld [hExperience], a
ret
; calculates d*d
-CalcDSquared: ; 59010 (16:5010)
+CalcDSquared:
xor a
- ld [H_MULTIPLICAND], a ; $ff96 (aliases: H_NUMTOPRINT)
- ld [H_MULTIPLICAND+1], a
+ ld [H_MULTIPLICAND], a
+ ld [H_MULTIPLICAND + 1], a
ld a, d
- ld [H_MULTIPLICAND+2], a
- ld [H_MULTIPLIER], a ; $ff99 (aliases: H_DIVISOR, H_REMAINDER, H_POWEROFTEN)
+ ld [H_MULTIPLICAND + 2], a
+ ld [H_MULTIPLIER], a
jp Multiply
; each entry has the following scheme:
@@ -147,7 +151,7 @@ CalcDSquared: ; 59010 (16:5010)
; resulting in
; (a*n^3)/b + sign*c*n^2 + d*n - e
; where sign = -1 <=> S=1
-GrowthRateTable: ; 5901d (16:501d)
+GrowthRateTable:
db $11,$00,$00,$00 ; medium fast n^3
db $34,$0A,$00,$1E ; (unused?) 3/4 n^3 + 10 n^2 - 30
db $34,$14,$00,$46 ; (unused?) 3/4 n^3 + 20 n^2 - 70
diff --git a/engine/flag_action.asm b/engine/flag_action.asm
new file mode 100644
index 00000000..dc516887
--- /dev/null
+++ b/engine/flag_action.asm
@@ -0,0 +1,73 @@
+FlagActionPredef:
+ call GetPredefRegisters
+
+FlagAction:
+; Perform action b on bit c
+; in the bitfield at hl.
+; 0: reset
+; 1: set
+; 2: read
+; Return the result in c.
+
+ push hl
+ push de
+ push bc
+
+ ; bit
+ ld a, c
+ ld d, a
+ and 7
+ ld e, a
+
+ ; byte
+ ld a, d
+ srl a
+ srl a
+ srl a
+ add l
+ ld l, a
+ jr nc, .ok
+ inc h
+.ok
+
+ ; d = 1 << e (bitmask)
+ inc e
+ ld d, 1
+.shift
+ dec e
+ jr z, .shifted
+ sla d
+ jr .shift
+.shifted
+
+ ld a, b
+ and a
+ jr z, .reset
+ cp 2
+ jr z, .read
+
+.set
+ ld b, [hl]
+ ld a, d
+ or b
+ ld [hl], a
+ jr .done
+
+.reset
+ ld b, [hl]
+ ld a, d
+ xor $ff
+ and b
+ ld [hl], a
+ jr .done
+
+.read
+ ld b, [hl]
+ ld a, d
+ and b
+.done
+ pop bc
+ pop de
+ pop hl
+ ld c, a
+ ret
diff --git a/engine/game_corner_slots.asm b/engine/game_corner_slots.asm
index 52f61daf..3c5b3a10 100755
--- a/engine/game_corner_slots.asm
+++ b/engine/game_corner_slots.asm
@@ -1,5 +1,5 @@
-StartSlotMachine: ; 37e2d (d:7e2d)
- ld a, [wTrainerSpriteOffset]
+StartSlotMachine:
+ ld a, [wHiddenObjectFunctionArgument]
cp $fd
jr z, .printOutOfOrder
cp $fe
@@ -7,33 +7,33 @@ StartSlotMachine: ; 37e2d (d:7e2d)
cp $ff
jr z, .printSomeonesKeys
callba AbleToPlaySlotsCheck
- ld a, [wTrainerSpriteOffset]
+ ld a, [wCanPlaySlots]
and a
ret z
- ld a, [wUnknownSlotVar]
+ ld a, [wLuckySlotHiddenObjectIndex]
ld b, a
- ld a, [wTrainerFacingDirection]
+ ld a, [wHiddenObjectIndex]
inc a
cp b
- jr z, .asm_37e58
- ld a, $fd
- jr .asm_37e5a
-.asm_37e58
- ld a, $fa
-.asm_37e5a
- ld [wcc5b], a
+ jr z, .match
+ ld a, 253
+ jr .next
+.match
+ ld a, 250
+.next
+ ld [wSlotMachineSevenAndBarModeChance], a
ld a, [H_LOADEDROMBANK]
- ld [wcc5e], a
+ ld [wSlotMachineSavedROMBank], a
call PromptUserToPlaySlots
ret
.printOutOfOrder
- ld a, $28
+ tx_pre_id GameCornerOutOfOrderText
jr .printText
.printOutToLunch
- ld a, $29
+ tx_pre_id GameCornerOutToLunchText
jr .printText
.printSomeonesKeys
- ld a, $2a
+ tx_pre_id GameCornerSomeonesKeysText
.printText
push af
call EnableAutoTextBoxDrawing
@@ -41,14 +41,14 @@ StartSlotMachine: ; 37e2d (d:7e2d)
call PrintPredefTextID
ret
-GameCornerOutOfOrderText: ; 37e79 (d:7e79)
+GameCornerOutOfOrderText:
TX_FAR _GameCornerOutOfOrderText
db "@"
-GameCornerOutToLunchText: ; 37e7e (d:7e7e)
+GameCornerOutToLunchText:
TX_FAR _GameCornerOutToLunchText
db "@"
-GameCornerSomeonesKeysText: ; 37e83 (d:7e83)
+GameCornerSomeonesKeysText:
TX_FAR _GameCornerSomeonesKeysText
db "@"
diff --git a/engine/game_corner_slots2.asm b/engine/game_corner_slots2.asm
index 66e51237..6bbaf72d 100755
--- a/engine/game_corner_slots2.asm
+++ b/engine/game_corner_slots2.asm
@@ -1,31 +1,31 @@
-AbleToPlaySlotsCheck ; 2ff09 (b:7f09)
+AbleToPlaySlotsCheck:
ld a, [wSpriteStateData1 + 2]
and $8
jr z, .done ; not able
ld b, COIN_CASE
- predef IsItemInBag_ ; IsItemInBag_
+ predef GetQuantityOfItemInBag
ld a, b
and a
- ld b, $33 ; GameCornerCoinCaseText
+ ld b, (GameCornerCoinCaseText_id - TextPredefs) / 2 + 1
jr z, .printCoinCaseRequired
ld hl, wPlayerCoins
ld a, [hli]
or [hl]
jr nz, .done ; able to play
- ld b, $32 ; GameCornerNoCoinsText
+ ld b, (GameCornerNoCoinsText_id - TextPredefs) / 2 + 1
.printCoinCaseRequired
call EnableAutoTextBoxDrawing
ld a, b
call PrintPredefTextID
xor a
.done
- ld [wWhichTrade], a
+ ld [wCanPlaySlots], a
ret
-GameCornerCoinCaseText: ; 2ff32 (b:7f32)
+GameCornerCoinCaseText:
TX_FAR _GameCornerCoinCaseText
db "@"
-GameCornerNoCoinsText: ; 2ff37 (b:7f37)
+GameCornerNoCoinsText:
TX_FAR _GameCornerNoCoinsText
db "@"
diff --git a/engine/gamefreak.asm b/engine/gamefreak.asm
index d0f1bbac..5226072b 100755
--- a/engine/gamefreak.asm
+++ b/engine/gamefreak.asm
@@ -1,94 +1,105 @@
-LoadShootingStarGraphics: ; 70000 (1c:4000)
+LoadShootingStarGraphics:
ld a, $f9
- ld [rOBP0], a ; $ff48
+ ld [rOBP0], a
ld a, $a4
- ld [rOBP1], a ; $ff49
- ld de, AnimationTileset2 + $30 ; $471e ; star tile (top left quadrant)
+ ld [rOBP1], a
+ ld de, AnimationTileset2 + $30 ; star tile (top left quadrant)
ld hl, vChars1 + $200
- ld bc, (BANK(AnimationTileset2) << 8) + $01
+ lb bc, BANK(AnimationTileset2), $01
call CopyVideoData
- ld de, AnimationTileset2 + $130 ; $481e ; star tile (bottom left quadrant)
+ ld de, AnimationTileset2 + $130 ; star tile (bottom left quadrant)
ld hl, vChars1 + $210
- ld bc, (BANK(AnimationTileset2) << 8) + $01
+ lb bc, BANK(AnimationTileset2), $01
call CopyVideoData
- ld de, FallingStar ; $4190
+ ld de, FallingStar
ld hl, vChars1 + $220
- ld bc, (BANK(FallingStar) << 8) + $01
+ lb bc, BANK(FallingStar), (FallingStarEnd - FallingStar) / $10
call CopyVideoData
- ld hl, GameFreakLogoOAMData ; $4140
+ ld hl, GameFreakLogoOAMData
ld de, wOAMBuffer + $60
- ld bc, $40
+ ld bc, GameFreakLogoOAMDataEnd - GameFreakLogoOAMData
call CopyData
- ld hl, GameFreakShootingStarOAMData ; $4180
+ ld hl, GameFreakShootingStarOAMData
ld de, wOAMBuffer
- ld bc, $10
+ ld bc, GameFreakShootingStarOAMDataEnd - GameFreakShootingStarOAMData
jp CopyData
-AnimateShootingStar: ; 70044 (1c:4044)
+AnimateShootingStar:
call LoadShootingStarGraphics
- ld a, (SFX_1f_67 - SFX_Headers_1f) / 3
+ ld a, SFX_SHOOTING_STAR
call PlaySound
+
+; Move the big star down and left across the screen.
ld hl, wOAMBuffer
- ld bc, $a004
-.asm_70052
+ lb bc, $a0, $4
+.bigStarLoop
push hl
push bc
-.asm_70054
- ld a, [hl]
- add $4
+.bigStarInnerLoop
+ ld a, [hl] ; Y
+ add 4
ld [hli], a
- ld a, [hl]
- add $fc
+ ld a, [hl] ; X
+ add -4
ld [hli], a
inc hl
inc hl
dec c
- jr nz, .asm_70054
- ld c, $1
+ jr nz, .bigStarInnerLoop
+ ld c, 1
call CheckForUserInterruption
pop bc
pop hl
ret c
ld a, [hl]
- cp $50
- jr nz, .asm_70070
- jr .asm_70052
-.asm_70070
+ cp 80
+ jr nz, .next
+ jr .bigStarLoop
+.next
cp b
- jr nz, .asm_70052
+ jr nz, .bigStarLoop
+
+; Clear big star OAM.
ld hl, wOAMBuffer
- ld c, $4
- ld de, $4
-.asm_7007b
- ld [hl], $a0
+ ld c, 4
+ ld de, 4
+.clearOAMLoop
+ ld [hl], 160
add hl, de
dec c
- jr nz, .asm_7007b
- ld b, $3
-.asm_70083
- ld hl, rOBP0 ; $ff48
+ jr nz, .clearOAMLoop
+
+; Make Gamefreak logo flash.
+ ld b, 3
+.flashLogoLoop
+ ld hl, rOBP0
rrc [hl]
rrc [hl]
- ld c, $a
+ ld c, 10
call CheckForUserInterruption
ret c
dec b
- jr nz, .asm_70083
+ jr nz, .flashLogoLoop
+
+; Copy 24 instances of the small stars OAM data.
+; Note that their coordinates put them off-screen.
ld de, wOAMBuffer
- ld a, $18
-.asm_70098
+ ld a, 24
+.initSmallStarsOAMLoop
push af
- ld hl, OAMData_700ee ; $40ee
- ld bc, $4
+ ld hl, SmallStarsOAM
+ ld bc, SmallStarsOAMEnd - SmallStarsOAM
call CopyData
pop af
dec a
- jr nz, .asm_70098
+ jr nz, .initSmallStarsOAMLoop
+
+; Animate the small stars falling from the Gamefreak logo.
xor a
- ld [wWhichTrade], a ; wWhichTrade
- ld hl, PointerTable_700f2 ; $40f2
- ld c, $6
-.asm_700af
+ ld [wMoveDownSmallStarsOAMCount], a
+ ld hl, SmallStarsWaveCoordsPointerTable
+ ld c, 6
+.smallStarsLoop
ld a, [hli]
ld e, a
ld a, [hli]
@@ -96,103 +107,112 @@ AnimateShootingStar: ; 70044 (1c:4044)
push bc
push hl
ld hl, wOAMBuffer + $50
- ld c, $4
-.asm_700ba
+ ld c, 4
+.smallStarsInnerLoop ; introduce new wave of 4 small stars OAM entries
ld a, [de]
cp $ff
- jr z, .asm_700d5
- ld [hli], a
+ jr z, .next2
+ ld [hli], a ; Y
inc de
ld a, [de]
- ld [hli], a
+ ld [hli], a ; X
inc de
inc hl
inc hl
dec c
- jr nz, .asm_700ba
- ld a, [wWhichTrade] ; wWhichTrade
- cp $18
- jr z, .asm_700d5
- add $6
- ld [wWhichTrade], a ; wWhichTrade
-.asm_700d5
- call Func_7011f
+ jr nz, .smallStarsInnerLoop
+ ld a, [wMoveDownSmallStarsOAMCount]
+ cp 24
+ jr z, .next2
+ add 6 ; should be 4, but the extra 2 aren't visible on screen
+ ld [wMoveDownSmallStarsOAMCount], a
+.next2
+ call MoveDownSmallStars
push af
+
+; shift the existing OAM entries down to make room for the next wave
ld hl, wOAMBuffer + $10
ld de, wOAMBuffer
ld bc, $50
call CopyData
+
pop af
pop hl
pop bc
ret c
dec c
- jr nz, .asm_700af
+ jr nz, .smallStarsLoop
and a
ret
-OAMData_700ee: ; 700ee (1c:40ee)
+SmallStarsOAM:
db $00,$00,$A2,$90
+SmallStarsOAMEnd:
+
+SmallStarsWaveCoordsPointerTable:
+ dw SmallStarsWave1Coords
+ dw SmallStarsWave2Coords
+ dw SmallStarsWave3Coords
+ dw SmallStarsWave4Coords
+ dw SmallStarsEmptyWave
+ dw SmallStarsEmptyWave
-PointerTable_700f2: ; 700f2 (1c:40f2)
- dw OAMData_700fe
- dw OAMData_70106
- dw OAMData_7010e
- dw OAMData_70116
- dw OAMData_7011e
- dw OAMData_7011e
+; The stars that fall from the Gamefreak logo come in 4 waves of 4 OAM entries.
+; These arrays contain the Y and X coordinates of each OAM entry.
-; each entry is only half of an OAM tile
-OAMData_700fe: ; 700fe (1c:40fe)
+SmallStarsWave1Coords:
db $68,$30
db $68,$40
db $68,$58
db $68,$78
-OAMData_70106: ; 70106 (1c:4106)
+SmallStarsWave2Coords:
db $68,$38
db $68,$48
db $68,$60
db $68,$70
-OAMData_7010e: ; 7010e (1c:410e)
+SmallStarsWave3Coords:
db $68,$34
db $68,$4C
db $68,$54
db $68,$64
-OAMData_70116: ; 70116 (1c:4116)
+SmallStarsWave4Coords:
db $68,$3C
db $68,$5C
db $68,$6C
db $68,$74
-OAMData_7011e: ; 7011e (1c:411e)
+SmallStarsEmptyWave:
db $FF
-Func_7011f: ; 7011f (1c:411f)
- ld b, $8
-.asm_70121
+MoveDownSmallStars:
+ ld b, 8
+.loop
ld hl, wOAMBuffer + $5c
- ld a, [wWhichTrade] ; wWhichTrade
- ld de, $fffc
+ ld a, [wMoveDownSmallStarsOAMCount]
+ ld de, -4
ld c, a
-.asm_7012b
- inc [hl]
+.innerLoop
+ inc [hl] ; Y
add hl, de
dec c
- jr nz, .asm_7012b
- ld a, [rOBP1] ; $ff49
- xor $a0
- ld [rOBP1], a ; $ff49
- ld c, $3
+ jr nz, .innerLoop
+; Toggle the palette so that the lower star in the small stars tile blinks in
+; and out.
+ ld a, [rOBP1]
+ xor %10100000
+ ld [rOBP1], a
+
+ ld c, 3
call CheckForUserInterruption
ret c
dec b
- jr nz, .asm_70121
+ jr nz, .loop
ret
-GameFreakLogoOAMData: ; 70140 (1c:4140)
+GameFreakLogoOAMData:
db $48,$50,$8D,$00
db $48,$58,$8E,$00
db $50,$50,$8F,$00
@@ -209,12 +229,15 @@ GameFreakLogoOAMData: ; 70140 (1c:4140)
db $60,$68,$83,$00
db $60,$70,$81,$00
db $60,$78,$86,$00
+GameFreakLogoOAMDataEnd:
-GameFreakShootingStarOAMData: ; 70180 (1c:4180)
+GameFreakShootingStarOAMData:
db $00,$A0,$A0,$10
db $00,$A8,$A0,$30
db $08,$A0,$A1,$10
db $08,$A8,$A1,$30
+GameFreakShootingStarOAMDataEnd:
-FallingStar: ; 70190 (1c:4190)
+FallingStar:
INCBIN "gfx/falling_star.2bpp"
+FallingStarEnd:
diff --git a/engine/get_bag_item_quantity.asm b/engine/get_bag_item_quantity.asm
new file mode 100644
index 00000000..f10df1a0
--- /dev/null
+++ b/engine/get_bag_item_quantity.asm
@@ -0,0 +1,18 @@
+GetQuantityOfItemInBag:
+; In: b = item ID
+; Out: b = how many of that item are in the bag
+ call GetPredefRegisters
+ ld hl, wNumBagItems
+.loop
+ inc hl
+ ld a, [hli]
+ cp $ff
+ jr z, .notInBag
+ cp b
+ jr nz, .loop
+ ld a, [hl]
+ ld b, a
+ ret
+.notInBag
+ ld b, 0
+ ret
diff --git a/engine/give_pokemon.asm b/engine/give_pokemon.asm
index 64876d22..49596782 100755
--- a/engine/give_pokemon.asm
+++ b/engine/give_pokemon.asm
@@ -1,54 +1,57 @@
-_GivePokemon: ; 4fda5 (13:7da5)
+_GivePokemon:
+; returns success in carry
+; and whether the mon was added to the party in [wAddedToParty]
call EnableAutoTextBoxDrawing
xor a
- ld [wccd3], a
- ld a, [wPartyCount] ; wPartyCount
+ ld [wAddedToParty], a
+ ld a, [wPartyCount]
cp PARTY_LENGTH
- jr c, .asm_4fe01
- ld a, [W_NUMINBOX] ; wda80
+ jr c, .addToParty
+ ld a, [wNumInBox]
cp MONS_PER_BOX
- jr nc, .asm_4fdf9
+ jr nc, .boxFull
+; add to box
xor a
- ld [W_ENEMYBATTSTATUS3], a ; W_ENEMYBATTSTATUS3
+ ld [wEnemyBattleStatus3], a
ld a, [wcf91]
ld [wEnemyMonSpecies2], a
callab LoadEnemyMonData
call SetPokedexOwnedFlag
callab SendNewMonToBox
ld hl, wcf4b
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
- jr c, .asm_4fdec
+ jr c, .singleDigitBoxNum
sub 9
ld [hl], "1"
inc hl
add "0"
- jr .asm_4fdee
-.asm_4fdec
+ jr .next
+.singleDigitBoxNum
add "1"
-.asm_4fdee
+.next
ld [hli], a
ld [hl], "@"
ld hl, SetToBoxText
call PrintText
scf
ret
-.asm_4fdf9
+.boxFull
ld hl, BoxIsFullText
call PrintText
and a
ret
-.asm_4fe01
+.addToParty
call SetPokedexOwnedFlag
call AddPartyMon
- ld a, $1
+ ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ld [wccd3], a
+ ld [wAddedToParty], a
scf
ret
-SetPokedexOwnedFlag: ; 4fe11 (13:7e11)
+SetPokedexOwnedFlag:
ld a, [wcf91]
push af
ld [wd11e], a
@@ -56,8 +59,8 @@ SetPokedexOwnedFlag: ; 4fe11 (13:7e11)
ld a, [wd11e]
dec a
ld c, a
- ld hl, wPokedexOwned ; wPokedexOwned
- ld b, $1
+ ld hl, wPokedexOwned
+ ld b, FLAG_SET
predef FlagActionPredef
pop af
ld [wd11e], a
@@ -65,15 +68,15 @@ SetPokedexOwnedFlag: ; 4fe11 (13:7e11)
ld hl, GotMonText
jp PrintText
-GotMonText: ; 4fe39 (13:7e39)
+GotMonText:
TX_FAR _GotMonText
- db $0b
+ TX_SFX_ITEM_1
db "@"
-SetToBoxText: ; 4fe3f (13:7e3f)
+SetToBoxText:
TX_FAR _SetToBoxText
db "@"
-BoxIsFullText: ; 4fe44 (13:7e44)
+BoxIsFullText:
TX_FAR _BoxIsFullText
db "@"
diff --git a/engine/hall_of_fame.asm b/engine/hall_of_fame.asm
index 30979118..9eb4edc5 100755
--- a/engine/hall_of_fame.asm
+++ b/engine/hall_of_fame.asm
@@ -1,5 +1,5 @@
-AnimateHallOfFame: ; 701a0 (1c:41a0)
- call Func_70423
+AnimateHallOfFame:
+ call HoFFadeOutScreenAndMusic
call ClearScreen
ld c, 100
call DelayFrames
@@ -8,10 +8,10 @@ AnimateHallOfFame: ; 701a0 (1c:41a0)
call DisableLCD
ld hl,vBGMap0
ld bc, $800
- ld a, $7f
+ ld a, " "
call FillMemory
call EnableLCD
- ld hl, rLCDC ; $ff40
+ ld hl, rLCDC
set 3, [hl]
xor a
ld hl, wHallOfFame
@@ -20,17 +20,17 @@ AnimateHallOfFame: ; 701a0 (1c:41a0)
xor a
ld [wUpdateSpritesEnabled], a
ld [hTilesetType], a
- ld [W_SPRITEFLIPPED], a
- ld [wd358], a
- ld [wTrainerScreenY], a
+ ld [wSpriteFlipped], a
+ ld [wLetterPrintingDelayFlags], a ; no delay
+ ld [wHoFMonOrPlayer], a ; mon
inc a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld hl, wd5a2
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld hl, wNumHoFTeams
ld a, [hl]
inc a
- jr z, .asm_701eb
+ jr z, .skipInc ; don't wrap around to 0
inc [hl]
-.asm_701eb
+.skipInc
ld a, $90
ld [hWY], a
ld c, BANK(Music_HallOfFame)
@@ -38,30 +38,30 @@ AnimateHallOfFame: ; 701a0 (1c:41a0)
call PlayMusic
ld hl, wPartySpecies
ld c, $ff
-.asm_701fb
+.partyMonLoop
ld a, [hli]
cp $ff
- jr z, .asm_70241
+ jr z, .doneShowingParty
inc c
push hl
push bc
- ld [wWhichTrade], a ; wWhichTrade
+ ld [wHoFMonSpecies], a
ld a, c
- ld [wTrainerEngageDistance], a
- ld hl, wPartyMon1Level ; wPartyMon1Level
+ ld [wHoFPartyMonIndex], a
+ ld hl, wPartyMon1Level
ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
ld a, [hl]
- ld [wTrainerFacingDirection], a
- call Func_70278
- call Func_702e1
- ld c, $50
+ ld [wHoFMonLevel], a
+ call HoFShowMonOrPlayer
+ call HoFDisplayAndRecordMonInfo
+ ld c, 80
call DelayFrames
- hlCoord 2, 13
- ld b, $3
- ld c, $e
+ coord hl, 2, 13
+ ld b, 3
+ ld c, 14
call TextBoxBorder
- hlCoord 4, 15
+ coord hl, 4, 15
ld de, HallOfFameText
call PlaceString
ld c, 180
@@ -69,8 +69,8 @@ AnimateHallOfFame: ; 701a0 (1c:41a0)
call GBFadeOutToWhite
pop bc
pop hl
- jr .asm_701fb
-.asm_70241
+ jr .partyMonLoop
+.doneShowingParty
ld a, c
inc a
ld hl, wHallOfFame
@@ -79,117 +79,120 @@ AnimateHallOfFame: ; 701a0 (1c:41a0)
ld [hl], $ff
call SaveHallOfFameTeams
xor a
- ld [wWhichTrade], a ; wWhichTrade
+ ld [wHoFMonSpecies], a
inc a
- ld [wTrainerScreenY], a
- call Func_70278
- call Func_70377
- call Func_70423
+ ld [wHoFMonOrPlayer], a ; player
+ call HoFShowMonOrPlayer
+ call HoFDisplayPlayerStats
+ call HoFFadeOutScreenAndMusic
xor a
ld [hWY], a
- ld hl, rLCDC ; $ff40
+ ld hl, rLCDC
res 3, [hl]
ret
-HallOfFameText: ; 7026b (1c:426b)
+HallOfFameText:
db "HALL OF FAME@"
-Func_70278: ; 70278 (1c:4278)
+HoFShowMonOrPlayer:
call ClearScreen
ld a, $d0
ld [hSCY], a
ld a, $c0
ld [hSCX], a
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wHoFMonSpecies]
ld [wcf91], a
ld [wd0b5], a
ld [wBattleMonSpecies2], a
- ld [wcf1d], a
- ld a, [wTrainerScreenY]
+ ld [wWholeScreenPaletteMonSpecies], a
+ ld a, [wHoFMonOrPlayer]
and a
- jr z, .asm_7029d
- call Func_7033e
- jr .asm_702ab
-.asm_7029d
- hlCoord 12, 5
+ jr z, .showMon
+; show player
+ call HoFLoadPlayerPics
+ jr .next1
+.showMon
+ coord hl, 12, 5
call GetMonHeader
call LoadFrontSpriteByMonIndex
predef LoadMonBackPic
-.asm_702ab
- ld b, $b
- ld c, $0
- call GoPAL_SET
- ld a, $e4
- ld [rBGP], a ; $ff47
- ld c, $31
- call Func_7036d
+.next1
+ ld b, SET_PAL_POKEMON_WHOLE_SCREEN
+ ld c, 0
+ call RunPaletteCommand
+ ld a, %11100100
+ ld [rBGP], a
+ ld c, $31 ; back pic
+ call HoFLoadMonPlayerPicTileIDs
ld d, $a0
- ld e, $4
+ ld e, 4
ld a, [wOnSGB]
and a
- jr z, .asm_702c7
- sla e
-.asm_702c7
- call .asm_702d5
+ jr z, .next2
+ sla e ; scroll more slowly on SGB
+.next2
+ call .ScrollPic ; scroll back pic left
xor a
ld [hSCY], a
- ld c, a
- call Func_7036d
- ld d, $0
- ld e, $fc
-.asm_702d5
+ ld c, a ; front pic
+ call HoFLoadMonPlayerPicTileIDs
+ ld d, 0
+ ld e, -4
+; scroll front pic right
+
+.ScrollPic
call DelayFrame
ld a, [hSCX]
add e
ld [hSCX], a
cp d
- jr nz, .asm_702d5
+ jr nz, .ScrollPic
ret
-Func_702e1: ; 702e1 (1c:42e1)
- ld a, [wTrainerEngageDistance]
- ld hl, wPartyMonNicks ; wPartyMonNicks
+HoFDisplayAndRecordMonInfo:
+ ld a, [wHoFPartyMonIndex]
+ ld hl, wPartyMonNicks
call GetPartyMonName
- call Func_702f0
- jp Func_70404
+ call HoFDisplayMonInfo
+ jp HoFRecordMonInfo
-Func_702f0: ; 702f0 (1c:42f0)
- hlCoord 0, 2
- ld b, $9
- ld c, $a
+HoFDisplayMonInfo:
+ coord hl, 0, 2
+ ld b, 9
+ ld c, 10
call TextBoxBorder
- hlCoord 2, 6
+ coord hl, 2, 6
ld de, HoFMonInfoText
call PlaceString
- hlCoord 1, 4
+ coord hl, 1, 4
ld de, wcd6d
call PlaceString
- ld a, [wTrainerFacingDirection]
- hlCoord 8, 7
+ ld a, [wHoFMonLevel]
+ coord hl, 8, 7
call PrintLevelCommon
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wHoFMonSpecies]
ld [wd0b5], a
- hlCoord 3, 9
+ coord hl, 3, 9
predef PrintMonType
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wHoFMonSpecies]
jp PlayCry
-HoFMonInfoText: ; 70329 (1c:4329)
+HoFMonInfoText:
db "LEVEL/"
next "TYPE1/"
next "TYPE2/@"
-Func_7033e: ; 7033e (1c:433e)
- ld de, RedPicFront ; $6ede
+HoFLoadPlayerPics:
+ ld de, RedPicFront
ld a, BANK(RedPicFront)
call UncompressSpriteFromDE
- ld hl, S_SPRITEBUFFER1
- ld de, $a000
+ ld hl, sSpriteBuffer1
+ ld de, sSpriteBuffer0
ld bc, $310
call CopyData
ld de, vFrontPic
call InterlaceMergeSpriteBuffers
- ld de, RedPicBack ; $7e0a
+ ld de, RedPicBack
ld a, BANK(RedPicBack)
call UncompressSpriteFromDE
predef ScaleSpriteByTwo
@@ -197,89 +200,89 @@ Func_7033e: ; 7033e (1c:433e)
call InterlaceMergeSpriteBuffers
ld c, $1
-Func_7036d: ; 7036d (1c:436d)
- ld b, $0
- hlCoord 12, 5
+HoFLoadMonPlayerPicTileIDs:
+; c = base tile ID
+ ld b, 0
+ coord hl, 12, 5
predef_jump CopyTileIDsFromList
-Func_70377: ; 70377 (1c:4377)
- ld hl, wd747
- set 3, [hl]
+HoFDisplayPlayerStats:
+ SetEvent EVENT_HALL_OF_FAME_DEX_RATING
predef DisplayDexRating
- hlCoord 0, 4
- ld b, $6
- ld c, $a
+ coord hl, 0, 4
+ ld b, 6
+ ld c, 10
call TextBoxBorder
- hlCoord 5, 0
- ld b, $2
- ld c, $9
+ coord hl, 5, 0
+ ld b, 2
+ ld c, 9
call TextBoxBorder
- hlCoord 7, 2
- ld de, wPlayerName ; wd158
+ coord hl, 7, 2
+ ld de, wPlayerName
call PlaceString
- hlCoord 1, 6
+ coord hl, 1, 6
ld de, HoFPlayTimeText
call PlaceString
- hlCoord 5, 7
- ld de, W_PLAYTIMEHOURS + 1
- ld bc, $103
+ coord hl, 5, 7
+ ld de, wPlayTimeHours
+ lb bc, 1, 3
call PrintNumber
ld [hl], $6d
inc hl
- ld de, W_PLAYTIMEMINUTES + 1
- ld bc, $8102
+ ld de, wPlayTimeMinutes
+ lb bc, LEADING_ZEROES | 1, 2
call PrintNumber
- hlCoord 1, 9
+ coord hl, 1, 9
ld de, HoFMoneyText
call PlaceString
- hlCoord 4, 10
- ld de, wPlayerMoney ; wPlayerMoney
+ coord hl, 4, 10
+ ld de, wPlayerMoney
ld c, $a3
call PrintBCDNumber
ld hl, DexSeenOwnedText
- call Func_703e2
+ call HoFPrintTextAndDelay
ld hl, DexRatingText
- call Func_703e2
- ld hl, wcc5d
+ call HoFPrintTextAndDelay
+ ld hl, wDexRatingText
-Func_703e2: ; 703e2 (1c:43e2)
+HoFPrintTextAndDelay:
call PrintText
- ld c, $78
+ ld c, 120
jp DelayFrames
-HoFPlayTimeText: ; 703ea (1c:43ea)
+HoFPlayTimeText:
db "PLAY TIME@"
-HoFMoneyText: ; 703f4 (1c:43f4)
+HoFMoneyText:
db "MONEY@"
-DexSeenOwnedText: ; 703fa (1c:43fa)
+DexSeenOwnedText:
TX_FAR _DexSeenOwnedText
db "@"
-DexRatingText: ; 703ff (1c:43ff)
+DexRatingText:
TX_FAR _DexRatingText
db "@"
-Func_70404: ; 70404 (1c:4404)
+HoFRecordMonInfo:
ld hl, wHallOfFame
ld bc, HOF_MON
- ld a, [wTrainerEngageDistance]
+ ld a, [wHoFPartyMonIndex]
call AddNTimes
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wHoFMonSpecies]
ld [hli], a
- ld a, [wTrainerFacingDirection]
+ ld a, [wHoFMonLevel]
ld [hli], a
ld e, l
ld d, h
ld hl, wcd6d
- ld bc, $b
+ ld bc, NAME_LENGTH
jp CopyData
-Func_70423: ; 70423 (1c:4423)
- ld a, $a
- ld [wcfc8], a
- ld [wcfc9], a
+HoFFadeOutScreenAndMusic:
+ ld a, 10
+ ld [wAudioFadeOutCounterReloadValue], a
+ ld [wAudioFadeOutCounter], a
ld a, $ff
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
jp GBFadeOutToWhite
diff --git a/engine/heal_party.asm b/engine/heal_party.asm
new file mode 100644
index 00000000..7aaa1bd1
--- /dev/null
+++ b/engine/heal_party.asm
@@ -0,0 +1,99 @@
+HealParty:
+; Restore HP and PP.
+
+ ld hl, wPartySpecies
+ ld de, wPartyMon1HP
+.healmon
+ ld a, [hli]
+ cp $ff
+ jr z, .done
+
+ push hl
+ push de
+
+ ld hl, wPartyMon1Status - wPartyMon1HP
+ add hl, de
+ xor a
+ ld [hl], a
+
+ push de
+ ld b, NUM_MOVES ; A Pokémon has 4 moves
+.pp
+ ld hl, wPartyMon1Moves - wPartyMon1HP
+ add hl, de
+
+ ld a, [hl]
+ and a
+ jr z, .nextmove
+
+ dec a
+ ld hl, wPartyMon1PP - wPartyMon1HP
+ add hl, de
+
+ push hl
+ push de
+ push bc
+
+ ld hl, Moves
+ ld bc, MoveEnd - Moves
+ call AddNTimes
+ ld de, wcd6d
+ ld a, BANK(Moves)
+ call FarCopyData
+ ld a, [wcd6d + 5] ; PP is byte 5 of move data
+
+ pop bc
+ pop de
+ pop hl
+
+ inc de
+ push bc
+ ld b, a
+ ld a, [hl]
+ and $c0
+ add b
+ ld [hl], a
+ pop bc
+
+.nextmove
+ dec b
+ jr nz, .pp
+ pop de
+
+ ld hl, wPartyMon1MaxHP - wPartyMon1HP
+ add hl, de
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
+
+ pop de
+ pop hl
+
+ push hl
+ ld bc, wPartyMon2 - wPartyMon1
+ ld h, d
+ ld l, e
+ add hl, bc
+ ld d, h
+ ld e, l
+ pop hl
+ jr .healmon
+
+.done
+ xor a
+ ld [wWhichPokemon], a
+ ld [wd11e], a
+
+ ld a, [wPartyCount]
+ ld b, a
+.ppup
+ push bc
+ call RestoreBonusPP
+ pop bc
+ ld hl, wWhichPokemon
+ inc [hl]
+ dec b
+ jr nz, .ppup
+ ret
diff --git a/engine/hidden_object_functions14.asm b/engine/hidden_object_functions14.asm
index a162c905..f8cdf44e 100755
--- a/engine/hidden_object_functions14.asm
+++ b/engine/hidden_object_functions14.asm
@@ -1,17 +1,17 @@
-PrintNotebookText: ; 52996 (14:6996)
+PrintNotebookText:
call EnableAutoTextBoxDrawing
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ld a, [wTrainerSpriteOffset]
+ ld a, [wHiddenObjectFunctionArgument]
jp PrintPredefTextID
-TMNotebook: ; 529a4 (14:69a4)
+TMNotebook:
TX_FAR TMNotebookText
- db $0d
+ TX_WAIT
db "@"
-ViridianSchoolNotebook: ; 529aa (14:69aa)
- db $08 ; asm
+ViridianSchoolNotebook:
+ TX_ASM
ld hl, ViridianSchoolNotebookText1
call PrintText
call TurnPageSchoolNotebook
@@ -31,7 +31,7 @@ ViridianSchoolNotebook: ; 529aa (14:69aa)
.doneReading
jp TextScriptEnd
-TurnPageSchoolNotebook: ; 529db (14:69db)
+TurnPageSchoolNotebook:
ld hl, TurnPageText
call PrintText
call YesNoChoice
@@ -39,66 +39,62 @@ TurnPageSchoolNotebook: ; 529db (14:69db)
and a
ret
-TurnPageText: ; 529e9 (14:69e9)
+TurnPageText:
TX_FAR _TurnPageText
db "@"
-ViridianSchoolNotebookText5: ; 529ee (14:69ee)
+ViridianSchoolNotebookText5:
TX_FAR _ViridianSchoolNotebookText5
- db $0d
+ TX_WAIT
db "@"
-ViridianSchoolNotebookText1: ; 529f4 (14:69f4)
+ViridianSchoolNotebookText1:
TX_FAR _ViridianSchoolNotebookText1
db "@"
-ViridianSchoolNotebookText2: ; 529f9 (14:69f9)
+ViridianSchoolNotebookText2:
TX_FAR _ViridianSchoolNotebookText2
db "@"
-ViridianSchoolNotebookText3: ; 529fe (14:69fe)
+ViridianSchoolNotebookText3:
TX_FAR _ViridianSchoolNotebookText3
db "@"
-ViridianSchoolNotebookText4: ; 52a03 (14:6a03)
+ViridianSchoolNotebookText4:
TX_FAR _ViridianSchoolNotebookText4
db "@"
-PrintFightingDojoText2: ; 52a08 (14:6a08)
+PrintFightingDojoText2:
call EnableAutoTextBoxDrawing
- ld a, $37
- jp PrintPredefTextID
+ tx_pre_jump EnemiesOnEverySideText
-FightingDojoText_52a10: ; 52a10 (14:6a10)
- TX_FAR _FightingDojoText_52a10
+EnemiesOnEverySideText:
+ TX_FAR _EnemiesOnEverySideText
db "@"
-PrintFightingDojoText3: ; 52a15 (14:6a15)
+PrintFightingDojoText3:
call EnableAutoTextBoxDrawing
- ld a, $38
- jp PrintPredefTextID
+ tx_pre_jump WhatGoesAroundComesAroundText
-FightingDojoText_52a1d: ; 52a1d (14:6a1d)
- TX_FAR _FightingDojoText_52a1d
+WhatGoesAroundComesAroundText:
+ TX_FAR _WhatGoesAroundComesAroundText
db "@"
-PrintFightingDojoText: ; 52a22 (14:6a22)
+PrintFightingDojoText:
call EnableAutoTextBoxDrawing
- ld a, $36
- jp PrintPredefTextID
+ tx_pre_jump FightingDojoText
-FightingDojoText: ; 52a2a (14:6a2a)
+FightingDojoText:
TX_FAR _FightingDojoText
db "@"
-PrintIndigoPlateauHQText: ; 52a2f (14:6a2f)
+PrintIndigoPlateauHQText:
ld a, [wSpriteStateData1 + 9]
- cp $4
+ cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
- ld a, $27
- jp PrintPredefTextID
+ tx_pre_jump IndigoPlateauHQText
-IndigoPlateauHQText: ; 52a3d (14:6a3d)
+IndigoPlateauHQText:
TX_FAR _IndigoPlateauHQText
db "@"
diff --git a/engine/hidden_object_functions17.asm b/engine/hidden_object_functions17.asm
index 9dbcbf98..1b571d35 100755
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -1,67 +1,62 @@
-PrintRedsNESText: ; 5db79 (17:5b79)
+PrintRedSNESText:
call EnableAutoTextBoxDrawing
- ld a, $4 ; RedBedroomSNESText
- jp PrintPredefTextID
+ tx_pre_jump RedBedroomSNESText
-RedBedroomSNESText: ; 5db81 (17:5b81)
+RedBedroomSNESText:
TX_FAR _RedBedroomSNESText
db "@"
-OpenRedsPC: ; 5db86 (17:5b86)
+OpenRedsPC:
call EnableAutoTextBoxDrawing
- ld a, $3
- jp PrintPredefTextID
+ tx_pre_jump RedBedroomPCText
-RedBedroomPC: ; 5db8e (17:5b8e)
- db $fc ; FuncTX_ItemStoragePC
+RedBedroomPCText:
+ TX_PLAYERS_PC
-Route15GateLeftBinoculars: ; 5db8f (17:5b8f)
+Route15GateLeftBinoculars:
ld a, [wSpriteStateData1 + 9]
- cp $4 ; i
+ cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
- ld a, $a ; text id Route15UpstairsBinocularsText
- call PrintPredefTextID
+ tx_pre Route15UpstairsBinocularsText
ld a, ARTICUNO
ld [wcf91], a
call PlayCry
jp DisplayMonFrontSpriteInBox
-Route15UpstairsBinocularsText: ; 5dba8 (17:5ba8)
+Route15UpstairsBinocularsText:
TX_FAR _Route15UpstairsBinocularsText
db "@"
-AerodactylFossil: ; 5dbad (17:5bad)
+AerodactylFossil:
ld a, FOSSIL_AERODACTYL
ld [wcf91], a
call DisplayMonFrontSpriteInBox
call EnableAutoTextBoxDrawing
- ld a, $9
- call PrintPredefTextID
+ tx_pre AerodactylFossilText
ret
-AerodactylFossilText: ; 5dbbe (17:5bbe)
+AerodactylFossilText:
TX_FAR _AerodactylFossilText
db "@"
-KabutopsFossil: ; 5bdc3 (17:5bc3)
+KabutopsFossil:
ld a, FOSSIL_KABUTOPS
ld [wcf91], a
call DisplayMonFrontSpriteInBox
call EnableAutoTextBoxDrawing
- ld a, $b
- call PrintPredefTextID
+ tx_pre KabutopsFossilText
ret
-KabutopsFossilText: ; 5dbd4 (17:5bd4)
+KabutopsFossilText:
TX_FAR _KabutopsFossilText
db "@"
-DisplayMonFrontSpriteInBox: ; 5dbd9 (17:5bd9)
+DisplayMonFrontSpriteInBox:
; Displays a pokemon's front sprite in a pop-up window.
; [wcf91] = pokemon interal id number
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
xor a
ld [hWY], a
@@ -76,9 +71,9 @@ DisplayMonFrontSpriteInBox: ; 5dbd9 (17:5bd9)
ld de, vChars1 + $310
call LoadMonFrontSprite
ld a, $80
- ld [$ffe1], a
- hlCoord 10, 11
- predef Func_3f073
+ ld [hStartTileID], a
+ coord hl, 10, 11
+ predef AnimateSendingOutMon
call WaitForTextScrollButtonPress
call LoadScreenTilesFromBuffer1
call Delay3
@@ -86,267 +81,267 @@ DisplayMonFrontSpriteInBox: ; 5dbd9 (17:5bd9)
ld [hWY], a
ret
-PrintBlackboardLinkCableText: ; 5dc1a (17:5c1a)
+PrintBlackboardLinkCableText:
call EnableAutoTextBoxDrawing
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ld a, [wWhichTrade]
+ ld a, [wHiddenObjectFunctionArgument]
call PrintPredefTextID
ret
-LinkCableHelp: ; 5dc29 (17:5c29)
- db $08 ; asm
+LinkCableHelp:
+ TX_ASM
call SaveScreenTilesToBuffer1
ld hl, LinkCableHelpText1
call PrintText
xor a
- ld [W_ANIMATIONID], a
+ ld [wMenuItemOffset], a ; not used
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld a, $3
+ ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $3
+ ld a, 3
ld [wMaxMenuItem], a
- ld a, $2
+ ld a, 2
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
-.asm_5c51
+.linkHelpLoop
ld hl, wd730
set 6, [hl]
- ld hl, wTileMap
- ld b, $8
- ld c, $d
+ coord hl, 0, 0
+ ld b, 8
+ ld c, 13
call TextBoxBorder
- ld hl, wTileMap + $2a
+ coord hl, 2, 2
ld de, HowToLinkText
call PlaceString
ld hl, LinkCableHelpText2
call PrintText
call HandleMenuInput
- bit 1, a
- jr nz, .asm_5dc93 ; 0x5dc74 $1d
+ bit 1, a ; pressed b
+ jr nz, .exit
ld a, [wCurrentMenuItem]
- cp $3
- jr z, .asm_5dc93 ; 0x5dc7b $16
+ cp 3 ; pressed a on "STOP READING"
+ jr z, .exit
ld hl, wd730
res 6, [hl]
ld hl, LinkCableInfoTexts
add a
- ld d, $0
+ ld d, 0
ld e, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
call PrintText
- jp .asm_5c51
-.asm_5dc93
+ jp .linkHelpLoop
+.exit
ld hl, wd730
res 6, [hl]
call LoadScreenTilesFromBuffer1
jp TextScriptEnd
-LinkCableHelpText1: ; 5dc9e (17:5c9e)
+LinkCableHelpText1:
TX_FAR _LinkCableHelpText1
db "@"
-LinkCableHelpText2: ; 5dca3 (17:5ca3)
+LinkCableHelpText2:
TX_FAR _LinkCableHelpText2
db "@"
-HowToLinkText: ; 5dca8 (17:5ca8)
+HowToLinkText:
db "HOW TO LINK"
next "COLOSSEUM"
next "TRADE CENTER"
next "STOP READING@"
-LinkCableInfoTexts: ; 5dcd8 (17:5cd8)
+LinkCableInfoTexts:
dw LinkCableInfoText1
dw LinkCableInfoText2
dw LinkCableInfoText3
-LinkCableInfoText1: ; 5dcde (17:5cde)
+LinkCableInfoText1:
TX_FAR _LinkCableInfoText1
db "@"
-LinkCableInfoText2: ; 5dce3 (17:5ce3)
+LinkCableInfoText2:
TX_FAR _LinkCableInfoText2
db "@"
-LinkCableInfoText3: ; 5dce8 (17:5ce8)
+LinkCableInfoText3:
TX_FAR _LinkCableInfoText3
db "@"
-ViridianSchoolBlackboard: ; 5dced (17:5ced)
- db $08 ; asm
+ViridianSchoolBlackboard:
+ TX_ASM
call SaveScreenTilesToBuffer1
ld hl, ViridianSchoolBlackboardText1
call PrintText
xor a
- ld [W_ANIMATIONID], a
+ ld [wMenuItemOffset], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld a, $33
+ ld a, D_LEFT | D_RIGHT | A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $2
+ ld a, 2
ld [wMaxMenuItem], a
- ld a, $2
+ ld a, 2
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
-.asm_5dd15
+.blackboardLoop
ld hl, wd730
set 6, [hl]
- ld hl, wTileMap
- ld bc, $060a
+ coord hl, 0, 0
+ lb bc, 6, 10
call TextBoxBorder
- ld hl, wTileMap + $29
+ coord hl, 1, 2
ld de, StatusAilmentText1
call PlaceString
- ld hl, wTileMap + $2e
+ coord hl, 6, 2
ld de, StatusAilmentText2
call PlaceString
ld hl, ViridianSchoolBlackboardText2
call PrintText
- call HandleMenuInput
- bit 1, a
+ call HandleMenuInput ; pressing up and down is handled in here
+ bit 1, a ; pressed b
jr nz, .exitBlackboard
- bit 4, a
- jr z, .asm_5dd5c
- ld a, $2
+ bit 4, a ; pressed right
+ jr z, .didNotPressRight
+ ; move cursor to right column
+ ld a, 2
ld [wMaxMenuItem], a
- ld a, $2
+ ld a, 2
ld [wTopMenuItemY], a
- ld a, $6
+ ld a, 6
ld [wTopMenuItemX], a
- ld a, $3
- ld [W_ANIMATIONID], a
- jr .asm_5dd15
-.asm_5dd5c
- bit 5, a
- jr z, .asm_5dd75
- ld a, $2
+ ld a, 3 ; in the the right column, use an offset to prevent overlap
+ ld [wMenuItemOffset], a
+ jr .blackboardLoop
+.didNotPressRight
+ bit 5, a ; pressed left
+ jr z, .didNotPressLeftOrRight
+ ; move cursor to left column
+ ld a, 2
ld [wMaxMenuItem], a
- ld a, $2
+ ld a, 2
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
xor a
- ld [W_ANIMATIONID], a
- jr .asm_5dd15
-.asm_5dd75
+ ld [wMenuItemOffset], a
+ jr .blackboardLoop
+.didNotPressLeftOrRight
ld a, [wCurrentMenuItem]
ld b, a
- ld a, [W_ANIMATIONID]
+ ld a, [wMenuItemOffset]
add b
- cp $5
+ cp 5 ; cursor is pointing to "QUIT"
jr z, .exitBlackboard
+ ; we must have pressed a on a status condition
+ ; so print the text
ld hl, wd730
res 6, [hl]
ld hl, ViridianBlackboardStatusPointers
add a
- ld d, $0
+ ld d, 0
ld e, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
call PrintText
- jp .asm_5dd15
+ jp .blackboardLoop
.exitBlackboard
ld hl, wd730
res 6, [hl]
call LoadScreenTilesFromBuffer1
jp TextScriptEnd
-ViridianSchoolBlackboardText1: ; 5dda2 (17:5da2)
+ViridianSchoolBlackboardText1:
TX_FAR _ViridianSchoolBlackboardText1
db "@"
-ViridianSchoolBlackboardText2: ; 5dda7 (17:5da7)
+ViridianSchoolBlackboardText2:
TX_FAR _ViridianSchoolBlackboardText2
db "@"
-StatusAilmentText1: ; 5ddac (17:5dac)
+StatusAilmentText1:
db " SLP"
next " PSN"
next " PAR@"
-StatusAilmentText2: ; 5ddbb (17:5dbb)
+StatusAilmentText2:
db " BRN"
next " FRZ"
next " QUIT@@"
-ViridianBlackboardStatusPointers: ; 5ddcc (17:5ddc)
+ViridianBlackboardStatusPointers:
dw ViridianBlackboardSleepText
dw ViridianBlackboardPoisonText
- dw ViridianBlackbaordPrlzText
+ dw ViridianBlackboardPrlzText
dw ViridianBlackboardBurnText
dw ViridianBlackboardFrozenText
-ViridianBlackboardSleepText: ; 5ddd6 (17:5dd6)
+ViridianBlackboardSleepText:
TX_FAR _ViridianBlackboardSleepText
db "@"
-ViridianBlackboardPoisonText: ; 5dddb (17:5ddb)
+ViridianBlackboardPoisonText:
TX_FAR _ViridianBlackboardPoisonText
db "@"
-ViridianBlackbaordPrlzText: ; 5dde0 (17:5de0)
- TX_FAR _ViridianBlackbaordPrlzText
+ViridianBlackboardPrlzText:
+ TX_FAR _ViridianBlackboardPrlzText
db "@"
-ViridianBlackboardBurnText: ; 5dde5 (17:5de5)
+ViridianBlackboardBurnText:
TX_FAR _ViridianBlackboardBurnText
db "@"
-ViridianBlackboardFrozenText: ; 5ddea (17:5dea)
+ViridianBlackboardFrozenText:
TX_FAR _ViridianBlackboardFrozenText
db "@"
-PrintTrashText: ; 5ddef (17:5def)
+PrintTrashText:
call EnableAutoTextBoxDrawing
- ld a, $26
- jp PrintPredefTextID
+ tx_pre_jump VermilionGymTrashText
-VermilionGymTrashText: ; 5ddf7 (17:5df7)
+VermilionGymTrashText:
TX_FAR _VermilionGymTrashText
db "@"
-GymTrashScript: ; 5ddfc (17:5dfc)
+GymTrashScript:
call EnableAutoTextBoxDrawing
- ld a, [wWhichTrade] ; wWhichTrade
- ld [wcd5b], a
+ ld a, [wHiddenObjectFunctionArgument]
+ ld [wGymTrashCanIndex], a
; Don't do the trash can puzzle if it's already been done.
- ld a, [wd773]
- bit 0, a
+ CheckEvent EVENT_2ND_LOCK_OPENED
jr z, .ok
- ld a, $26 ; DisplayTextID $26 = VermilionGymTrashText (nothing in the trash)
- jp PrintPredefTextID
+ tx_pre_jump VermilionGymTrashText
.ok
- bit 1, a
+ CheckEventReuseA EVENT_1ST_LOCK_OPENED
jr nz, .trySecondLock
- ld a, [wd743]
+ ld a, [wFirstLockTrashCanIndex]
ld b, a
- ld a, [wcd5b]
+ ld a, [wGymTrashCanIndex]
cp b
jr z, .openFirstLock
- ld a, $26 ; DisplayTextID $26 = VermilionGymTrashText (nothing in the trash)
+ tx_pre_id VermilionGymTrashText
jr .done
.openFirstLock
; Next can is trying for the second switch.
- ld hl, wd773
- set 1, [hl]
+ SetEvent EVENT_1ST_LOCK_OPENED
- ld hl, GymTrashCans ; $5e7d
- ld a, [wcd5b]
+ ld hl, GymTrashCans
+ ld a, [wGymTrashCanIndex]
; * 5
ld b, a
add a
@@ -358,12 +353,21 @@ GymTrashScript: ; 5ddfc (17:5dfc)
add hl, de
ld a, [hli]
- ld [$ffdb], a
+; There is a bug in this code. It should calculate a value in the range [0, 3]
+; but if the mask and random number don't have any 1 bits in common, then
+; the result of the AND will be 0. When 1 is subtracted from that, the value
+; will become $ff. This will result in 255 being added to hl, which will cause
+; hl to point to one of the zero bytes that pad the end of the ROM bank.
+; Trash can 0 was intended to be able to have the second lock only when the
+; first lock was in trash can 1 or 3. However, due to this bug, trash can 0 can
+; have the second lock regardless of which trash can had the first lock.
+
+ ld [hGymTrashCanRandNumMask], a
push hl
call Random
swap a
ld b, a
- ld a, [$ffdb]
+ ld a, [hGymTrashCanRandNumMask]
and b
dec a
pop hl
@@ -373,42 +377,46 @@ GymTrashScript: ; 5ddfc (17:5dfc)
add hl, de
ld a, [hl]
and $f
- ld [wd744], a
+ ld [wSecondLockTrashCanIndex], a
- ld a, $3b ; DisplayTextID $3b = VermilionGymTrashSuccesText1 (first lock opened!)
+ tx_pre_id VermilionGymTrashSuccessText1
jr .done
.trySecondLock
- ld a, [wd744]
+ ld a, [wSecondLockTrashCanIndex]
ld b, a
- ld a, [wcd5b]
+ ld a, [wGymTrashCanIndex]
cp b
jr z, .openSecondLock
; Reset the cans.
- ld hl, wd773
- res 1, [hl]
+ ResetEvent EVENT_1ST_LOCK_OPENED
call Random
and $e
- ld [wd743], a
+ ld [wFirstLockTrashCanIndex], a
- ld a, $3e ; DisplayTextID $3e = VermilionGymTrashFailText (locks reset!)
+ tx_pre_id VermilionGymTrashFailText
jr .done
.openSecondLock
; Completed the trash can puzzle.
- ld hl, wd773
- set 0, [hl]
- ld hl, wd126
+ SetEvent EVENT_2ND_LOCK_OPENED
+ ld hl, wCurrentMapScriptFlags
set 6, [hl]
- ld a, $3d ; DisplayTextID $3d = VermilionGymTrashSuccesText3 (2nd lock opened!)
+ tx_pre_id VermilionGymTrashSuccessText3
.done
jp PrintPredefTextID
-GymTrashCans: ; 5de7d (17:5e7d)
+GymTrashCans:
+; byte 0: mask for random number
+; bytes 1-4: indices of the trash cans that can have the second lock
+; (but see the comment above explaining a bug regarding this)
+; Note that the mask is simply the number of valid trash can indices that
+; follow. The remaining bytes are filled with 0 to pad the length of each entry
+; to 5 bytes.
db 2, 1, 3, 0, 0 ; 0
db 3, 0, 2, 4, 0 ; 1
db 2, 1, 5, 0, 0 ; 2
@@ -424,43 +432,44 @@ GymTrashCans: ; 5de7d (17:5e7d)
db 2, 9, 13, 0, 0 ; 12
db 3, 10, 12, 14, 0 ; 13
db 2, 11, 13, 0, 0 ; 14
-; 5dec8
-VermilionGymTrashSuccesText1: ; 5dec8 (17:5ec8)
- TX_FAR _VermilionGymTrashSuccesText1
- db $08 ; asm
+VermilionGymTrashSuccessText1:
+ TX_FAR _VermilionGymTrashSuccessText1
+ TX_ASM
call WaitForSoundToFinish
- ld a, (SFX_02_49 - SFX_Headers_02) / 3
+ ld a, SFX_SWITCH
call PlaySound
call WaitForSoundToFinish
jp TextScriptEnd
-VermilionGymTrashSuccesText2: ; 5dedb (17:5edb)
- TX_FAR _VermilionGymTrashSuccesText2
+; unused
+VermilionGymTrashSuccessText2:
+ TX_FAR _VermilionGymTrashSuccessText2
db "@"
-UnnamedText_5dee0: ; 5dee0 (17:5ee0)
- db $08 ; asm
+; unused
+VermilionGymTrashSuccesPlaySfx:
+ TX_ASM
call WaitForSoundToFinish
- ld a, (SFX_02_49 - SFX_Headers_02) / 3
+ ld a, SFX_SWITCH
call PlaySound
call WaitForSoundToFinish
jp TextScriptEnd
-VermilionGymTrashSuccesText3: ; 5deef (17:5eef)
- TX_FAR _VermilionGymTrashSuccesText3
- db $08 ; asm
+VermilionGymTrashSuccessText3:
+ TX_FAR _VermilionGymTrashSuccessText3
+ TX_ASM
call WaitForSoundToFinish
- ld a, (SFX_02_57 - SFX_Headers_02) / 3
+ ld a, SFX_GO_INSIDE
call PlaySound
call WaitForSoundToFinish
jp TextScriptEnd
-VermilionGymTrashFailText: ; 5df02 (17:5f02)
+VermilionGymTrashFailText:
TX_FAR _VermilionGymTrashFailText
- db $08 ; asm
+ TX_ASM
call WaitForSoundToFinish
- ld a, (SFX_02_51 - SFX_Headers_02) / 3
+ ld a, SFX_DENIED
call PlaySound
call WaitForSoundToFinish
jp TextScriptEnd
diff --git a/engine/hidden_object_functions18.asm b/engine/hidden_object_functions18.asm
index 7696626f..c6fb3109 100755
--- a/engine/hidden_object_functions18.asm
+++ b/engine/hidden_object_functions18.asm
@@ -1,34 +1,34 @@
-GymStatues: ; 62419 (18:6419)
-; if in a gym and have the corresponding badge, a = $D and jp PrintPredefTextID
-; if in a gym and don’t have the corresponding badge, a = $C and jp PrintPredefTextID
+GymStatues:
+; if in a gym and have the corresponding badge, a = GymStatueText2_id and jp PrintPredefTextID
+; if in a gym and don’t have the corresponding badge, a = GymStatueText1_id and jp PrintPredefTextID
; else ret
call EnableAutoTextBoxDrawing
ld a, [wSpriteStateData1 + 9]
- cp $4
+ cp SPRITE_FACING_UP
ret nz
ld hl, .BadgeFlags
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
ld b, a
-.asm_62429
+.loop
ld a, [hli]
cp $ff
ret z
cp b
- jr z, .asm_62433 ; 0x6242e $3
+ jr z, .match
inc hl
- jr .asm_62429 ; 0x62431 $f6
-.asm_62433
+ jr .loop
+.match
ld b, [hl]
- ld a, [wd72a]
+ ld a, [wBeatGymFlags]
and b
cp b
- ld a, $d
- jr z, .asm_6243f ; 0x6243b $2
- ld a, $c
-.asm_6243f
+ tx_pre_id GymStatueText2
+ jr z, .haveBadge
+ tx_pre_id GymStatueText1
+.haveBadge
jp PrintPredefTextID
-.BadgeFlags: ; 62442 (18:6442)
+.BadgeFlags:
db PEWTER_GYM, %00000001
db CERULEAN_GYM, %00000010
db VERMILION_GYM,%00000100
@@ -39,151 +39,160 @@ GymStatues: ; 62419 (18:6419)
db VIRIDIAN_GYM, %10000000
db $ff
-GymStatueText1: ; 62453 (18:6453)
+GymStatueText1:
TX_FAR _GymStatueText1
db "@"
-GymStatueText2: ; 62458 (18:6458)
+GymStatueText2:
TX_FAR _GymStatueText2
db "@"
-PrintBenchGuyText: ; 6245d (18:645d)
+PrintBenchGuyText:
call EnableAutoTextBoxDrawing
- ld hl, PokeCenterMapIDList
- ld a, [W_CURMAP]
+ ld hl, BenchGuyTextPointers
+ ld a, [wCurMap]
ld b, a
-.asm_62467
+.loop
ld a, [hli]
cp $ff
ret z
cp b
- jr z, .asm_62472
+ jr z, .match
inc hl
inc hl
- jr .asm_62467
-.asm_62472
+ jr .loop
+.match
ld a, [hli]
ld b, a
ld a, [wSpriteStateData1 + 9]
cp b
- jr nz, .asm_62467
+ jr nz, .loop ; player isn't facing left at the bench guy
ld a, [hl]
jp PrintPredefTextID
-; format: db map id, 08, text id of PredefTextIDPointerTable
-PokeCenterMapIDList: ; 6247e (18:647e)
- db VIRIDIAN_POKECENTER,$08,$0F
- db PEWTER_POKECENTER,$08,$10
- db CERULEAN_POKECENTER,$08,$11
- db LAVENDER_POKECENTER,$08,$12
- db VERMILION_POKECENTER,$08,$13
- db CELADON_POKECENTER,$08,$14
- db CELADON_HOTEL,$08,$15
- db FUCHSIA_POKECENTER,$08,$16
- db CINNABAR_POKECENTER,$08,$17
- db SAFFRON_POKECENTER,$08,$18
- db MT_MOON_POKECENTER,$08,$19
- db ROCK_TUNNEL_POKECENTER,$08,$1A
+; format: db map id, player sprite facing direction, text id of PredefTextIDPointerTable
+BenchGuyTextPointers:
+ db VIRIDIAN_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre ViridianCityPokecenterBenchGuyText
+ db PEWTER_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre PewterCityPokecenterBenchGuyText
+ db CERULEAN_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre CeruleanCityPokecenterBenchGuyText
+ db LAVENDER_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre LavenderCityPokecenterBenchGuyText
+ db VERMILION_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre VermilionCityPokecenterBenchGuyText
+ db CELADON_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre CeladonCityPokecenterBenchGuyText
+ db CELADON_HOTEL, SPRITE_FACING_LEFT
+ db_tx_pre CeladonCityHotelText
+ db FUCHSIA_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre FuchsiaCityPokecenterBenchGuyText
+ db CINNABAR_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre CinnabarIslandPokecenterBenchGuyText
+ db SAFFRON_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre SaffronCityPokecenterBenchGuyText
+ db MT_MOON_POKECENTER, SPRITE_FACING_LEFT
+ db_tx_pre MtMoonPokecenterBenchGuyText
+ db ROCK_TUNNEL_POKECENTER,SPRITE_FACING_LEFT
+ db_tx_pre RockTunnelPokecenterBenchGuyText
db $FF
-ViridianCityPokecenterBenchGuyText: ; 624a3 (18:64a3)
+ViridianCityPokecenterBenchGuyText:
TX_FAR _ViridianCityPokecenterGuyText
db "@"
-PewterCityPokecenterBenchGuyText: ; 624a8 (18:64a8)
+PewterCityPokecenterBenchGuyText:
TX_FAR _PewterCityPokecenterGuyText
db "@"
-CeruleanCityPokecenterBenchGuyText: ; 624ad (18:64ad)
+CeruleanCityPokecenterBenchGuyText:
TX_FAR _CeruleanPokecenterGuyText
db "@"
-LavenderCityPokecenterBenchGuyText: ; 624b2 (18:64b2)
+LavenderCityPokecenterBenchGuyText:
TX_FAR _LavenderPokecenterGuyText
db "@"
-MtMoonPokecenterBenchGuyText: ; 624b7 (18:64b7)
+MtMoonPokecenterBenchGuyText:
TX_FAR _MtMoonPokecenterBenchGuyText
db "@"
-RockTunnelPokecenterBenchGuyText: ; 624bc (18:64bc)
+RockTunnelPokecenterBenchGuyText:
TX_FAR _RockTunnelPokecenterGuyText
db "@"
-UnusedBenchGuyText1: ; 624c1 (18:64c1)
+UnusedBenchGuyText1:
TX_FAR _UnusedBenchGuyText1
db "@"
-UnusedBenchGuyText2: ; 624c6 (18:64c6)
+UnusedBenchGuyText2:
TX_FAR _UnusedBenchGuyText2
db "@"
-UnusedBenchGuyText3: ; 624cb (18:64cb)
+UnusedBenchGuyText3:
TX_FAR _UnusedBenchGuyText3
db "@"
-VermilionCityPokecenterBenchGuyText: ; 624d0 (18:64d0)
+VermilionCityPokecenterBenchGuyText:
TX_FAR _VermilionPokecenterGuyText
db "@"
-CeladonCityPokecenterBenchGuyText: ; 624d5 (18:64d5)
+CeladonCityPokecenterBenchGuyText:
TX_FAR _CeladonCityPokecenterGuyText
db "@"
-FuchsiaCityPokecenterBenchGuyText: ; 624da (18:64da)
+FuchsiaCityPokecenterBenchGuyText:
TX_FAR _FuchsiaCityPokecenterGuyText
db "@"
-CinnabarIslandPokecenterBenchGuyText: ; 624df (18:64df)
+CinnabarIslandPokecenterBenchGuyText:
TX_FAR _CinnabarPokecenterGuyText
db "@"
-SaffronCityPokecenterBenchGuyText: ; 624e4 (18:64e4)
- db $8 ; asm
- ld a, [wd838]
- bit 7, a
+SaffronCityPokecenterBenchGuyText:
+ TX_ASM
+ CheckEvent EVENT_BEAT_SILPH_CO_GIOVANNI
ld hl, SaffronCityPokecenterBenchGuyText2
- jr nz, .asm_624f2 ; 0x624ed $3
+ jr nz, .asm_624f2
ld hl, SaffronCityPokecenterBenchGuyText1
.asm_624f2
call PrintText
jp TextScriptEnd
-SaffronCityPokecenterBenchGuyText1: ; 624f8 (18:64f8)
+SaffronCityPokecenterBenchGuyText1:
TX_FAR _SaffronCityPokecenterGuyText1
db "@"
-SaffronCityPokecenterBenchGuyText2: ; 624fd (18:64fd)
+SaffronCityPokecenterBenchGuyText2:
TX_FAR _SaffronCityPokecenterGuyText2
db "@"
-CeladonCityHotelText: ; 62502 (18:6502)
+CeladonCityHotelText:
TX_FAR _CeladonCityHotelText
db "@"
ret
-TerminatorText_62508: ; 62508 (18:6508)
+UnusedPredefText:
db "@"
-PrintBookcaseText: ; 6509 (18:6509)
+PrintBookcaseText:
call EnableAutoTextBoxDrawing
- ld a, $e ; BookcaseText
- jp PrintPredefTextID
+ tx_pre_jump BookcaseText
-BookcaseText: ; 62511 (18:6511)
+BookcaseText:
TX_FAR _BookcaseText
db "@"
-OpenPokemonCenterPC: ; 62516 (18:6516)
+OpenPokemonCenterPC:
ld a, [wSpriteStateData1 + 9]
- cp $4 ; check to see if player is facing up
+ cp SPRITE_FACING_UP ; check to see if player is facing up
ret nz
call EnableAutoTextBoxDrawing
ld a, $1
ld [wAutoTextBoxDrawingControl], a
- ld a, $1f ; PredefText1f
- jp PrintPredefTextID
+ tx_pre_jump PokemonCenterPCText
-PredefText1f: ; 62529 (18:6529)
- db $F9 ; FuncTX_PokemonCenterPC
+PokemonCenterPCText:
+ TX_POKECENTER_PC
diff --git a/engine/hidden_object_functions3.asm b/engine/hidden_object_functions3.asm
index c471c7bb..aaedcbca 100755
--- a/engine/hidden_object_functions3.asm
+++ b/engine/hidden_object_functions3.asm
@@ -1,10 +1,10 @@
; prints text for bookshelves in buildings without sign events
-PrintBookshelfText: ; fb50 (3:7b50)
+PrintBookshelfText:
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
cp SPRITE_FACING_UP
jr nz, .noMatch
; facing up
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld b, a
aCoord 8, 7
ld c, a
@@ -34,86 +34,101 @@ PrintBookshelfText: ; fb50 (3:7b50)
.noMatch
ld a, $ff
ld [$ffdb], a
- ld b, BANK(PrintCardKeyText)
- ld hl, PrintCardKeyText
- jp Bankswitch
+ jpba PrintCardKeyText
; format: db tileset id, bookshelf tile id, text id
-BookshelfTileIDs: ; fb8b (3:7b8b)
- db PLATEAU, $30, $3A
- db HOUSE, $3D, $3F
- db HOUSE, $1E, $40
- db MANSION, $32, $40
- db REDS_HOUSE_1, $32, $40
- db LAB, $28, $40
- db LOBBY, $16, $41
- db GYM, $1D, $40
- db DOJO, $1D, $40
- db GATE, $22, $40
- db MART, $54, $42
- db MART, $55, $42
- db POKECENTER, $54, $42
- db POKECENTER, $55, $42
- db LOBBY, $50, $42
- db LOBBY, $52, $42
- db SHIP, $36, $40
+BookshelfTileIDs:
+ db PLATEAU, $30
+ db_tx_pre IndigoPlateauStatues
+ db HOUSE, $3D
+ db_tx_pre TownMapText
+ db HOUSE, $1E
+ db_tx_pre BookOrSculptureText
+ db MANSION, $32
+ db_tx_pre BookOrSculptureText
+ db REDS_HOUSE_1, $32
+ db_tx_pre BookOrSculptureText
+ db LAB, $28
+ db_tx_pre BookOrSculptureText
+ db LOBBY, $16
+ db_tx_pre ElevatorText
+ db GYM, $1D
+ db_tx_pre BookOrSculptureText
+ db DOJO, $1D
+ db_tx_pre BookOrSculptureText
+ db GATE, $22
+ db_tx_pre BookOrSculptureText
+ db MART, $54
+ db_tx_pre PokemonStuffText
+ db MART, $55
+ db_tx_pre PokemonStuffText
+ db POKECENTER, $54
+ db_tx_pre PokemonStuffText
+ db POKECENTER, $55
+ db_tx_pre PokemonStuffText
+ db LOBBY, $50
+ db_tx_pre PokemonStuffText
+ db LOBBY, $52
+ db_tx_pre PokemonStuffText
+ db SHIP, $36
+ db_tx_pre BookOrSculptureText
db $FF
-IndigoPlateauStatues: ; fbbf (3:7bbf)
- db $08 ; asm
+IndigoPlateauStatues:
+ TX_ASM
ld hl, IndigoPlateauStatuesText1
call PrintText
- ld a, [W_XCOORD]
+ ld a, [wXCoord]
bit 0, a
ld hl, IndigoPlateauStatuesText2
- jr nz, .asm_fbd3
+ jr nz, .ok
ld hl, IndigoPlateauStatuesText3
-.asm_fbd3
+.ok
call PrintText
jp TextScriptEnd
-IndigoPlateauStatuesText1: ; fbd9 (3:7bd9)
+IndigoPlateauStatuesText1:
TX_FAR _IndigoPlateauStatuesText1
db "@"
-IndigoPlateauStatuesText2: ; fbde (3:7bde)
+IndigoPlateauStatuesText2:
TX_FAR _IndigoPlateauStatuesText2
db "@"
-IndigoPlateauStatuesText3: ; fbe3 (3:7be3)
+IndigoPlateauStatuesText3:
TX_FAR _IndigoPlateauStatuesText3
db "@"
-BookOrSculptureText: ; fbe8 (3:7be8)
- db $08 ; asm
+BookOrSculptureText:
+ TX_ASM
ld hl, PokemonBooksText
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp MANSION ; Celadon Mansion tileset
- jr nz, .asm_fbfd
- ld a, [wTileMap + $80]
+ jr nz, .ok
+ aCoord 8, 6
cp $38
- jr nz, .asm_fbfd
+ jr nz, .ok
ld hl, DiglettSculptureText
-.asm_fbfd
+.ok
call PrintText
jp TextScriptEnd
-PokemonBooksText: ; fc03 (3:7c03)
+PokemonBooksText:
TX_FAR _PokemonBooksText
db "@"
-DiglettSculptureText: ; fc08 (3:7c08)
+DiglettSculptureText:
TX_FAR _DiglettSculptureText
db "@"
-ElevatorText: ; fc0d (3:7c0d)
+ElevatorText:
TX_FAR _ElevatorText
db "@"
-TownMapText: ; fc12 (3:7c12)
+TownMapText:
TX_FAR _TownMapText
- db $06
- db $08 ; asm
+ TX_BLINK
+ TX_ASM
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ld hl, wd730
@@ -133,6 +148,6 @@ TownMapText: ; fc12 (3:7c12)
push af
jp CloseTextDisplay
-PokemonStuffText: ; fc45 (3:7c45)
+PokemonStuffText:
TX_FAR _PokemonStuffText
db "@"
diff --git a/engine/hidden_object_functions7.asm b/engine/hidden_object_functions7.asm
index f97190de..f04c1deb 100755
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -1,149 +1,146 @@
-PrintNewBikeText: ; 1e94b (7:694b)
+PrintNewBikeText:
call EnableAutoTextBoxDrawing
- ld a, $39
- jp PrintPredefTextID
+ tx_pre_jump NewBicycleText
-NewBicycleText: ; 1e953 (7:6953)
+NewBicycleText:
TX_FAR _NewBicycleText
db "@"
-DisplayOakLabLeftPoster: ; 1e958 (7:6958)
+DisplayOakLabLeftPoster:
call EnableAutoTextBoxDrawing
- ld a, $05 ; PushStartText
- jp PrintPredefTextID
+ tx_pre_jump PushStartText
-PushStartText: ; 1e960 (7:6960)
+PushStartText:
TX_FAR _PushStartText
db "@"
-DisplayOakLabRightPoster: ; 1e965 (7:6965)
+DisplayOakLabRightPoster:
call EnableAutoTextBoxDrawing
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e]
- cp $2
- ld a, $6 ; SaveOptionText
- jr c, .asm_1e97b
- ld a, $7 ; StrengthsAndWeaknessesText
-.asm_1e97b
+ ld a, [wNumSetBits]
+ cp 2
+ tx_pre_id SaveOptionText
+ jr c, .ownLessThanTwo
+ ; own two or more mon
+ tx_pre_id StrengthsAndWeaknessesText
+.ownLessThanTwo
jp PrintPredefTextID
-SaveOptionText: ; 1e97e (7:697e)
+SaveOptionText:
TX_FAR _SaveOptionText
db "@"
-StrengthsAndWeaknessesText: ; 1e983 (7:6983)
+StrengthsAndWeaknessesText:
TX_FAR _StrengthsAndWeaknessesText
db "@"
-SafariZoneCheck: ; 1e988 (7:6988)
- ld hl, wd790
- bit 7, [hl]
- jr z, asm_1e9ab
- ld a, [W_NUMSAFARIBALLS] ; W_NUMSAFARIBALLS
+SafariZoneCheck:
+ CheckEventHL EVENT_IN_SAFARI_ZONE ; if we are not in the Safari Zone,
+ jr z, SafariZoneGameStillGoing ; don't bother printing game over text
+ ld a, [wNumSafariBalls]
and a
- jr z, asm_1e9b0
- jr asm_1e9ab
+ jr z, SafariZoneGameOver
+ jr SafariZoneGameStillGoing
-SafariZoneCheckSteps: ; 1e997 (7:6997)
- ld a, [wSafariSteps] ; wd70d
+SafariZoneCheckSteps:
+ ld a, [wSafariSteps]
ld b, a
- ld a, [wSafariSteps + 1] ; wd70e
+ ld a, [wSafariSteps + 1]
ld c, a
or b
- jr z, asm_1e9b0
+ jr z, SafariZoneGameOver
dec bc
ld a, b
- ld [wSafariSteps], a ; wd70d
+ ld [wSafariSteps], a
ld a, c
- ld [wSafariSteps + 1], a ; wd70e
-asm_1e9ab: ; 1e9ab (7:69ab)
+ ld [wSafariSteps + 1], a
+SafariZoneGameStillGoing:
xor a
ld [wSafariZoneGameOver], a
ret
-asm_1e9b0: ; 1e9b0 (7:69b0)
+
+SafariZoneGameOver:
call EnableAutoTextBoxDrawing
xor a
- ld [wMusicHeaderPointer], a
+ ld [wAudioFadeOutControl], a
dec a
call PlaySound
- ld c, BANK(SFX_02_5f)
- ld a, (SFX_02_5f - SFX_Headers_02) / 3
+ ld c, BANK(SFX_Safari_Zone_PA)
+ ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
-.asm_1e9c2
- ld a, [wc02a]
- cp $b9
- jr nz, .asm_1e9c2
- ld a, $d3
- ld [H_DOWNARROWBLINKCNT2], a ; $ff8c
+.waitForMusicToPlay
+ ld a, [wChannelSoundIDs + Ch4]
+ cp SFX_SAFARI_ZONE_PA
+ jr nz, .waitForMusicToPlay
+ ld a, TEXT_SAFARI_GAME_OVER
+ ld [hSpriteIndexOrTextID], a
call DisplayTextID
xor a
- ld [wd528], a
+ ld [wPlayerMovingDirection], a
ld a, SAFARI_ZONE_ENTRANCE
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
+ ld [hWarpDestinationMap], a
ld a, $3
ld [wDestinationWarpID], a
ld a, $5
- ld [W_SAFARIZONEENTRANCECURSCRIPT], a
- ld hl, wd790
- set 6, [hl]
- ld a, $1
+ ld [wSafariZoneEntranceCurScript], a
+ SetEvent EVENT_SAFARI_GAME_OVER
+ ld a, 1
ld [wSafariZoneGameOver], a
ret
-PrintSafariGameOverText: ; 1e9ed (7:69ed)
+PrintSafariGameOverText:
xor a
ld [wJoyIgnore], a
ld hl, SafariGameOverText
jp PrintText
-SafariGameOverText: ; 1e9f7 (7:69f7)
- db $08 ; asm
- ld a, [W_NUMSAFARIBALLS] ; W_NUMSAFARIBALLS
+SafariGameOverText:
+ TX_ASM
+ ld a, [wNumSafariBalls]
and a
- jr z, .asm_1ea04
+ jr z, .noMoreSafariBalls
ld hl, TimesUpText
call PrintText
-.asm_1ea04
+.noMoreSafariBalls
ld hl, GameOverText
call PrintText
jp TextScriptEnd
-TimesUpText: ; 1ea0d (7:6a0d)
+TimesUpText:
TX_FAR _TimesUpText
db "@"
-GameOverText: ; 1ea12 (7:6a12)
+GameOverText:
TX_FAR _GameOverText
db "@"
-PrintCinnabarQuiz: ; 1ea17 (7:6a17)
+PrintCinnabarQuiz:
ld a, [wSpriteStateData1 + 9]
- cp $4
+ cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
- ld a, $31
- jp PrintPredefTextID
+ tx_pre_jump CinnabarGymQuiz
-CinnabarGymQuiz: ; 1ea25 (7:6a25)
- db $08 ; asm
+CinnabarGymQuiz:
+ TX_ASM
xor a
- ld [wda38], a
- ld a, [wWhichTrade] ; wWhichTrade
+ ld [wOpponentAfterWrongAnswer], a
+ ld a, [wHiddenObjectFunctionArgument]
push af
and $f
- ld [$ffdb], a
+ ld [hGymGateIndex], a
pop af
and $f0
swap a
ld [$ffdc], a
ld hl, CinnabarGymQuizIntroText
call PrintText
- ld a, [$ffdb]
+ ld a, [hGymGateIndex]
dec a
add a
- ld d, $0
+ ld d, 0
ld e, a
ld hl, CinnabarQuizQuestions
add hl, de
@@ -151,16 +148,16 @@ CinnabarGymQuiz: ; 1ea25 (7:6a25)
ld h, [hl]
ld l, a
call PrintText
- ld a, $1
+ ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
call CinnabarGymQuiz_1ea92
jp TextScriptEnd
-CinnabarGymQuizIntroText: ; 1ea5b (7:6a5b)
+CinnabarGymQuizIntroText:
TX_FAR _CinnabarGymQuizIntroText
db "@"
-CinnabarQuizQuestions: ; 1ea60 (7:6a60)
+CinnabarQuizQuestions:
dw CinnabarQuizQuestionsText1
dw CinnabarQuizQuestionsText2
dw CinnabarQuizQuestionsText3
@@ -168,136 +165,143 @@ CinnabarQuizQuestions: ; 1ea60 (7:6a60)
dw CinnabarQuizQuestionsText5
dw CinnabarQuizQuestionsText6
-CinnabarQuizQuestionsText1: ; 1ea6c (7:6a6c)
+CinnabarQuizQuestionsText1:
TX_FAR _CinnabarQuizQuestionsText1
db "@"
-CinnabarQuizQuestionsText2: ; 1ea71 (7:6a71)
+CinnabarQuizQuestionsText2:
TX_FAR _CinnabarQuizQuestionsText2
db "@"
-CinnabarQuizQuestionsText3: ; 1ea76 (7:6a76)
+CinnabarQuizQuestionsText3:
TX_FAR _CinnabarQuizQuestionsText3
db "@"
-CinnabarQuizQuestionsText4: ; 1ea7b (7:6a7b)
+CinnabarQuizQuestionsText4:
TX_FAR _CinnabarQuizQuestionsText4
db "@"
-CinnabarQuizQuestionsText5: ; 1ea80 (7:6a80)
+CinnabarQuizQuestionsText5:
TX_FAR _CinnabarQuizQuestionsText5
db "@"
-CinnabarQuizQuestionsText6: ; 1ea85 (7:6a85)
+CinnabarQuizQuestionsText6:
TX_FAR _CinnabarQuizQuestionsText6
db "@"
-CinnabarGymQuiz_1ea8a: ; 1ea8a (7:6a8a)
- ld hl, wd79c
+CinnabarGymGateFlagAction:
+ EventFlagAddress hl, EVENT_CINNABAR_GYM_GATE0_UNLOCKED
predef_jump FlagActionPredef
-CinnabarGymQuiz_1ea92: ; 1ea92 (7:6a92)
+CinnabarGymQuiz_1ea92:
call YesNoChoice
ld a, [$ffdc]
ld c, a
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
cp c
- jr nz, .asm_1eab8
- ld hl, wd126
+ jr nz, .wrongAnswer
+ ld hl, wCurrentMapScriptFlags
set 5, [hl]
- ld a, [$ffdb]
+ ld a, [hGymGateIndex]
ld [$ffe0], a
ld hl, CinnabarGymQuizCorrectText
call PrintText
ld a, [$ffe0]
+ AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
ld c, a
- ld b, $1
- call CinnabarGymQuiz_1ea8a
- jp CinnabarGymQuiz_1eb0a
-.asm_1eab8
+ ld b, FLAG_SET
+ call CinnabarGymGateFlagAction
+ jp UpdateCinnabarGymGateTileBlocks_
+.wrongAnswer
call WaitForSoundToFinish
- ld a, (SFX_02_51 - SFX_Headers_02) / 3
+ ld a, SFX_DENIED
call PlaySound
call WaitForSoundToFinish
ld hl, CinnabarGymQuizIncorrectText
call PrintText
- ld a, [$ffdb]
+ ld a, [hGymGateIndex]
add $2
+ AdjustEventBit EVENT_BEAT_CINNABAR_GYM_TRAINER_0, 2
ld c, a
- ld b, $2
- ld hl, wd79a
+ ld b, FLAG_TEST
+ EventFlagAddress hl, EVENT_BEAT_CINNABAR_GYM_TRAINER_0
predef FlagActionPredef
ld a, c
and a
ret nz
- ld a, [$ffdb]
+ ld a, [hGymGateIndex]
add $2
- ld [wda38], a
+ ld [wOpponentAfterWrongAnswer], a
ret
-CinnabarGymQuizCorrectText: ; 1eae3 (7:6ae3)
- db $0b
+CinnabarGymQuizCorrectText:
+ TX_SFX_ITEM_1
TX_FAR _CinnabarGymQuizCorrectText
- db $06,$08
+ TX_BLINK
+ TX_ASM
ld a, [$ffe0]
+ AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
ld c, a
- ld b, $2
- call CinnabarGymQuiz_1ea8a
+ ld b, FLAG_TEST
+ call CinnabarGymGateFlagAction
ld a, c
and a
jp nz, TextScriptEnd
call WaitForSoundToFinish
- ld a, (SFX_02_57 - SFX_Headers_02) / 3
+ ld a, SFX_GO_INSIDE
call PlaySound
call WaitForSoundToFinish
jp TextScriptEnd
-CinnabarGymQuizIncorrectText: ; 1eb05 (7:6b05)
+CinnabarGymQuizIncorrectText:
TX_FAR _CinnabarGymQuizIncorrectText
db "@"
-CinnabarGymQuiz_1eb0a: ; 1eb0a (7:6b0a)
- ld a, $6
- ld [$ffdb], a
-.asm_1eb0e
- ld a, [$ffdb]
+UpdateCinnabarGymGateTileBlocks_:
+; Update the overworld map with open floor blocks or locked gate blocks
+; depending on event flags.
+ ld a, 6
+ ld [hGymGateIndex], a
+.loop
+ ld a, [hGymGateIndex]
dec a
add a
add a
- ld d, $0
+ ld d, 0
ld e, a
- ld hl, CinnabarGymGateCoords ; $6b48
+ ld hl, CinnabarGymGateCoords
add hl, de
ld a, [hli]
ld b, [hl]
ld c, a
inc hl
ld a, [hl]
- ld [wd12f], a
+ ld [wGymGateTileBlock], a
push bc
- ld a, [$ffdb]
+ ld a, [hGymGateIndex]
ld [$ffe0], a
+ AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
ld c, a
- ld b, $2
- call CinnabarGymQuiz_1ea8a
+ ld b, FLAG_TEST
+ call CinnabarGymGateFlagAction
ld a, c
and a
- jr nz, .asm_1eb36
- ld a, [wd12f]
- jr .asm_1eb38
-.asm_1eb36
+ jr nz, .unlocked
+ ld a, [wGymGateTileBlock]
+ jr .next
+.unlocked
ld a, $e
-.asm_1eb38
+.next
pop bc
- ld [wd09f], a
+ ld [wNewTileBlockID], a
predef ReplaceTileBlock
- ld hl, $ffdb
+ ld hl, hGymGateIndex
dec [hl]
- jr nz, .asm_1eb0e
+ jr nz, .loop
ret
-CinnabarGymGateCoords: ; 1eb48 (7:6b48)
+CinnabarGymGateCoords:
; format: x-coord, y-coord, direction, padding
; direction: $54 = horizontal gate, $5f = vertical gate
db $09,$03,$54,$00
@@ -307,164 +311,157 @@ CinnabarGymGateCoords: ; 1eb48 (7:6b48)
db $02,$06,$54,$00
db $02,$03,$54,$00
-PrintMagazinesText: ; 1eb60 (7:6b60)
+PrintMagazinesText:
call EnableAutoTextBoxDrawing
- ld a, $30
- call PrintPredefTextID
+ tx_pre MagazinesText
ret
-MagazinesText: ; 1eb69 (7:6b69)
+MagazinesText:
TX_FAR _MagazinesText
db "@"
-BillsHousePC: ; 1eb6e (7:6b6e)
+BillsHousePC:
call EnableAutoTextBoxDrawing
ld a, [wSpriteStateData1 + 9]
- cp $4
+ cp SPRITE_FACING_UP
ret nz
- ld a, [wd7f2]
- bit 7, a
- jr nz, .asm_1ebd2
- bit 3, a
- jr nz, .asm_1eb86
- bit 6, a
- jr nz, .asm_1eb8b
-.asm_1eb86
- ld a, $2d
- jp PrintPredefTextID
-.asm_1eb8b
+ CheckEvent EVENT_LEFT_BILLS_HOUSE_AFTER_HELPING
+ jr nz, .displayBillsHousePokemonList
+ CheckEventReuseA EVENT_USED_CELL_SEPARATOR_ON_BILL
+ jr nz, .displayBillsHouseMonitorText
+ CheckEventReuseA EVENT_BILL_SAID_USE_CELL_SEPARATOR
+ jr nz, .doCellSeparator
+.displayBillsHouseMonitorText
+ tx_pre_jump BillsHouseMonitorText
+.doCellSeparator
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ld a, $2e
- call PrintPredefTextID
- ld c, $20
+ tx_pre BillsHouseInitiatedText
+ ld c, 32
call DelayFrames
- ld a, (SFX_02_3c - SFX_Headers_02) / 3
+ ld a, SFX_TINK
call PlaySound
call WaitForSoundToFinish
- ld c, $50
+ ld c, 80
call DelayFrames
- ld a, (SFX_02_48 - SFX_Headers_02) / 3
+ ld a, SFX_SHRINK
call PlaySound
call WaitForSoundToFinish
- ld c, $30
+ ld c, 48
call DelayFrames
- ld a, (SFX_02_3c - SFX_Headers_02) / 3
+ ld a, SFX_TINK
call PlaySound
call WaitForSoundToFinish
- ld c, $20
+ ld c, 32
call DelayFrames
- ld a, (SFX_02_3a - SFX_Headers_02) / 3
+ ld a, SFX_GET_ITEM_1
call PlaySound
call WaitForSoundToFinish
call PlayDefaultMusic
- ld hl, wd7f2
- set 3, [hl]
+ SetEvent EVENT_USED_CELL_SEPARATOR_ON_BILL
ret
-.asm_1ebd2
+.displayBillsHousePokemonList
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ld a, $2f
- call PrintPredefTextID
+ tx_pre BillsHousePokemonList
ret
-BillsHouseMonitorText: ; 1ebdd (7:6bdd)
+BillsHouseMonitorText:
TX_FAR _BillsHouseMonitorText
db "@"
-BillsHouseInitiatedText: ; 1ebe2 (7:6be2)
+BillsHouseInitiatedText:
TX_FAR _BillsHouseInitiatedText
- db $06
- db $08 ; asm
+ TX_BLINK
+ TX_ASM
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
- ld c, $10
+ ld c, 16
call DelayFrames
- ld a, (SFX_02_49 - SFX_Headers_02) / 3
+ ld a, SFX_SWITCH
call PlaySound
call WaitForSoundToFinish
- ld c, $3c
+ ld c, 60
call DelayFrames
jp TextScriptEnd
-BillsHousePokemonList: ; 1ec05 (7:6c05)
- db $08 ; asm
+BillsHousePokemonList:
+ TX_ASM
call SaveScreenTilesToBuffer1
ld hl, BillsHousePokemonListText1
call PrintText
xor a
- ld [W_ANIMATIONID], a
+ ld [wMenuItemOffset], a ; not used
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld a, $3
+ ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $4
+ ld a, 4
ld [wMaxMenuItem], a
- ld a, $2
+ ld a, 2
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
-.asm_1ec2d
+.billsPokemonLoop
ld hl, wd730
set 6, [hl]
- ld hl, wTileMap
- ld b, $a
- ld c, $9
+ coord hl, 0, 0
+ ld b, 10
+ ld c, 9
call TextBoxBorder
- ld hl, wTileMap + $2a
+ coord hl, 2, 2
ld de, BillsMonListText
call PlaceString
ld hl, BillsHousePokemonListText2
call PrintText
call SaveScreenTilesToBuffer2
call HandleMenuInput
- bit 1, a
- jr nz, .asm_1ec74
+ bit 1, a ; pressed b
+ jr nz, .cancel
ld a, [wCurrentMenuItem]
add EEVEE
cp EEVEE
- jr z, .asm_1ec6c
+ jr z, .displayPokedex
cp FLAREON
- jr z, .asm_1ec6c
+ jr z, .displayPokedex
cp JOLTEON
- jr z, .asm_1ec6c
+ jr z, .displayPokedex
cp VAPOREON
- jr z, .asm_1ec6c
- jr .asm_1ec74
-.asm_1ec6c
+ jr z, .displayPokedex
+ jr .cancel
+.displayPokedex
call DisplayPokedex
call LoadScreenTilesFromBuffer2
- jr .asm_1ec2d
-.asm_1ec74
+ jr .billsPokemonLoop
+.cancel
ld hl, wd730
res 6, [hl]
call LoadScreenTilesFromBuffer2
jp TextScriptEnd
-BillsHousePokemonListText1: ; 1ec7f (7:6c7f)
+BillsHousePokemonListText1:
TX_FAR _BillsHousePokemonListText1
db "@"
-BillsMonListText: ; 1ec84 (7:6c84)
+BillsMonListText:
db "EEVEE"
next "FLAREON"
next "JOLTEON"
next "VAPOREON"
next "CANCEL@"
-BillsHousePokemonListText2: ; 1ecaa (7:6caa)
+BillsHousePokemonListText2:
TX_FAR _BillsHousePokemonListText2
db "@"
-DisplayOakLabEmailText: ; 1ecaf (7:6caf)
+DisplayOakLabEmailText:
ld a, [wSpriteStateData1 + 9]
- cp $4
+ cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
- ld a, $8 ; OakLabEmailText
- jp PrintPredefTextID
+ tx_pre_jump OakLabEmailText
-OakLabEmailText: ; 1ecbd (7:6cbd)
+OakLabEmailText:
TX_FAR _OakLabEmailText
db "@"
diff --git a/engine/hp_bar.asm b/engine/hp_bar.asm
index 333b0b90..221bd7a9 100755
--- a/engine/hp_bar.asm
+++ b/engine/hp_bar.asm
@@ -1,9 +1,9 @@
-HPBarLength: ; f9dc (3:79dc)
+HPBarLength:
call GetPredefRegisters
; calculates bc * 48 / de, the number of pixels the HP bar has
; the result is always at least 1
-GetHPBarLength: ; f9df (3:79df)
+GetHPBarLength:
push hl
xor a
ld hl, H_MULTIPLICAND
@@ -45,7 +45,7 @@ GetHPBarLength: ; f9df (3:79df)
ret
; predef $48
-UpdateHPBar: ; fa1d (3:7a1d)
+UpdateHPBar:
UpdateHPBar2:
push hl
ld hl, wHPBarOldHP
@@ -87,6 +87,7 @@ UpdateHPBar2:
call UpdateHPBar_CompareNewHPToOldHP
jr z, .animateHPBarDone
jr nc, .HPIncrease
+; HP decrease
dec bc ; subtract 1 HP
ld a, c
ld [wHPBarNewHP], a
@@ -95,7 +96,7 @@ UpdateHPBar2:
call UpdateHPBar_CalcOldNewHPBarPixels
ld a, e
sub d ; calc pixel difference
- jr .asm_fa7e
+ jr .ok
.HPIncrease
inc bc ; add 1 HP
ld a, c
@@ -105,7 +106,7 @@ UpdateHPBar2:
call UpdateHPBar_CalcOldNewHPBarPixels
ld a, d
sub e ; calc pixel difference
-.asm_fa7e
+.ok
call UpdateHPBar_PrintHPNumber
and a
jr z, .noPixelDifference
@@ -136,14 +137,14 @@ UpdateHPBar2:
; animates the HP bar going up or down for (a) ticks (two waiting frames each)
; stops prematurely if bar is filled up
; e: current health (in pixels) to start with
-UpdateHPBar_AnimateHPBar: ; fab1 (3:7ab1)
+UpdateHPBar_AnimateHPBar:
push hl
.barAnimationLoop
push af
push de
ld d, $6
call DrawHPBar
- ld c, $2
+ ld c, 2
call DelayFrames
pop de
ld a, [wHPBarDelta] ; +1 or -1
@@ -162,7 +163,7 @@ UpdateHPBar_AnimateHPBar: ; fab1 (3:7ab1)
ret
; compares old HP and new HP and sets c and z flags accordingly
-UpdateHPBar_CompareNewHPToOldHP: ; fad1 (3:7ad1)
+UpdateHPBar_CompareNewHPToOldHP:
ld a, d
sub b
ret nz
@@ -171,7 +172,7 @@ UpdateHPBar_CompareNewHPToOldHP: ; fad1 (3:7ad1)
ret
; calcs HP difference between bc and de (into de)
-UpdateHPBar_CalcHPDifference: ; fad7 (3:7ad7)
+UpdateHPBar_CalcHPDifference:
ld a, d
sub b
jr c, .oldHPGreater
@@ -200,38 +201,39 @@ UpdateHPBar_CalcHPDifference: ; fad7 (3:7ad7)
ld de, $0
ret
-UpdateHPBar_PrintHPNumber: ; faf5 (3:7af5)
+UpdateHPBar_PrintHPNumber:
push af
push de
ld a, [wHPBarType]
and a
- jr z, .asm_fb2d
+ jr z, .done ; don't print number in enemy HUD
+; convert from little-endian to big-endian for PrintNumber
ld a, [wHPBarOldHP]
- ld [wcef1], a
- ld a, [wHPBarOldHP+1]
- ld [wcef0], a
+ ld [wHPBarTempHP + 1], a
+ ld a, [wHPBarOldHP + 1]
+ ld [wHPBarTempHP], a
push hl
ld a, [hFlags_0xFFF6]
bit 0, a
jr z, .asm_fb15
ld de, $9
- jr .asm_fb18
+ jr .next
.asm_fb15
ld de, $15
-.asm_fb18
+.next
add hl, de
push hl
- ld a, $7f
+ ld a, " "
ld [hli], a
ld [hli], a
ld [hli], a
pop hl
- ld de, wcef0
- ld bc, $203
+ ld de, wHPBarTempHP
+ lb bc, 2, 3
call PrintNumber
call DelayFrame
pop hl
-.asm_fb2d
+.done
pop de
pop af
ret
@@ -239,7 +241,7 @@ UpdateHPBar_PrintHPNumber: ; faf5 (3:7af5)
; calcs number of HP bar pixels for old and new HP value
; d: new pixels
; e: old pixels
-UpdateHPBar_CalcOldNewHPBarPixels: ; fb30 (3:7b30)
+UpdateHPBar_CalcOldNewHPBarPixels:
push hl
ld hl, wHPBarMaxHP
ld a, [hli] ; max HP into de
diff --git a/engine/in_game_trades.asm b/engine/in_game_trades.asm
index cb03a074..a1fe85bc 100755
--- a/engine/in_game_trades.asm
+++ b/engine/in_game_trades.asm
@@ -1,4 +1,4 @@
-DoInGameTradeDialogue: ; 71ad9 (1c:5ad9)
+DoInGameTradeDialogue:
; trigger the trade offer/action specified by wWhichTrade
call SaveScreenTilesToBuffer2
ld hl,TradeMons
@@ -17,12 +17,12 @@ DoInGameTradeDialogue: ; 71ad9 (1c:5ad9)
ld a,[hli]
push af
ld de,wInGameTradeMonNick
- ld bc,$000b
+ ld bc, NAME_LENGTH
call CopyData
pop af
ld l,a
- ld h,$0
- ld de,InGameTradeTextPointers ; $5d64
+ ld h,0
+ ld de,InGameTradeTextPointers
add hl,hl
add hl,de
ld a,[hli]
@@ -38,7 +38,7 @@ DoInGameTradeDialogue: ; 71ad9 (1c:5ad9)
ld hl,wCompletedInGameTradeFlags
ld a,[wWhichTrade]
ld c,a
- ld b,$2
+ ld b,FLAG_TEST
predef FlagActionPredef
ld a,c
and a
@@ -75,20 +75,20 @@ DoInGameTradeDialogue: ; 71ad9 (1c:5ad9)
jp PrintText
; copies name of species a to hl
-InGameTrade_GetMonName: ; 71b6a (1c:5b6a)
+InGameTrade_GetMonName:
push de
ld [wd11e],a
call GetMonName
ld hl,wcd6d
pop de
- ld bc,$b
+ ld bc, NAME_LENGTH
jp CopyData
INCLUDE "data/trades.asm"
-InGameTrade_DoTrade: ; 71c07 (1c:5c07)
- xor a
- ld [wd07d],a
+InGameTrade_DoTrade:
+ xor a ; NORMAL_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
dec a
ld [wUpdateSpritesEnabled],a
call DisplayPartyMenu
@@ -105,36 +105,36 @@ InGameTrade_DoTrade: ; 71c07 (1c:5c07)
jr nz,.tradeFailed ; jump if the selected mon's species is not the required one
ld a,[wWhichPokemon]
ld hl,wPartyMon1Level
- ld bc,$002c
+ ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
ld a,[hl]
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
ld hl,wCompletedInGameTradeFlags
ld a,[wWhichTrade]
ld c,a
- ld b,$1
+ ld b,FLAG_SET
predef FlagActionPredef
ld hl, ConnectCableText
call PrintText
ld a,[wWhichPokemon]
push af
- ld a,[W_CURENEMYLVL]
+ ld a,[wCurEnemyLVL]
push af
call LoadHpBarAndStatusTilePatterns
call InGameTrade_PrepareTradeData
predef InternalClockTradeAnim
pop af
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
pop af
ld [wWhichPokemon],a
ld a,[wInGameTradeReceiveMonSpecies]
ld [wcf91],a
xor a
- ld [wcc49],a
- ld [wcf95],a
+ ld [wMonDataLocation],a ; not used
+ ld [wRemoveMonFromBox],a
call RemovePokemon
- ld a,$80
- ld [wcc49],a
+ ld a,$80 ; prevent the player from naming the mon
+ ld [wMonDataLocation],a
call AddPartyMon
call InGameTrade_CopyDataToReceivedMon
callab EvolveTradeMon
@@ -150,7 +150,7 @@ InGameTrade_DoTrade: ; 71c07 (1c:5c07)
ld [wInGameTradeTextPointerTableIndex],a
ret
-InGameTrade_RestoreScreen: ; 71ca2 (1c:5ca2)
+InGameTrade_RestoreScreen:
call GBPalWhiteOutWithDelay3
call RestoreScreenTilesAndReloadTilePatterns
call ReloadTilesetTilePatterns
@@ -159,27 +159,25 @@ InGameTrade_RestoreScreen: ; 71ca2 (1c:5ca2)
call LoadGBPal
ld c, 10
call DelayFrames
- ld b, BANK(LoadWildData)
- ld hl, LoadWildData
- jp Bankswitch
+ jpba LoadWildData
-InGameTrade_PrepareTradeData: ; 71cc1 (1c:5cc1)
+InGameTrade_PrepareTradeData:
ld hl, wTradedPlayerMonSpecies
ld a, [wInGameTradeGiveMonSpecies]
ld [hli], a ; wTradedPlayerMonSpecies
ld a, [wInGameTradeReceiveMonSpecies]
ld [hl], a ; wTradedEnemyMonSpecies
ld hl, wPartyMonOT
- ld bc, $b
+ ld bc, NAME_LENGTH
ld a, [wWhichPokemon]
call AddNTimes
ld de, wTradedPlayerMonOT
- ld bc, $b
+ ld bc, NAME_LENGTH
call InGameTrade_CopyData
ld hl, InGameTrade_TrainerString
- ld de, wcd4e
+ ld de, wTradedEnemyMonOT
call InGameTrade_CopyData
- ld de, W_GRASSRATE
+ ld de, wLinkEnemyTrainerName
call InGameTrade_CopyData
ld hl, wPartyMon1OTID
ld bc, wPartyMon2 - wPartyMon1
@@ -193,7 +191,7 @@ InGameTrade_PrepareTradeData: ; 71cc1 (1c:5cc1)
ld de, wTradedEnemyMonOTID
jp CopyData
-InGameTrade_CopyData: ; 71d11 (1c:5d11)
+InGameTrade_CopyData:
push hl
push bc
call CopyData
@@ -201,18 +199,18 @@ InGameTrade_CopyData: ; 71d11 (1c:5d11)
pop hl
ret
-InGameTrade_CopyDataToReceivedMon: ; 71d19 (1c:5d19)
+InGameTrade_CopyDataToReceivedMon:
ld hl, wPartyMonNicks
- ld bc, $b
+ ld bc, NAME_LENGTH
call InGameTrade_GetReceivedMonPointer
ld hl, wInGameTradeMonNick
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wPartyMonOT
- ld bc, $b
+ ld bc, NAME_LENGTH
call InGameTrade_GetReceivedMonPointer
ld hl, InGameTrade_TrainerString
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wPartyMon1OTID
ld bc, wPartyMon2 - wPartyMon1
@@ -223,7 +221,7 @@ InGameTrade_CopyDataToReceivedMon: ; 71d19 (1c:5d19)
; the received mon's index is (partyCount - 1),
; so this adds bc to hl (partyCount - 1) times and moves the result to de
-InGameTrade_GetReceivedMonPointer: ; 71d4f (1c:5d4f)
+InGameTrade_GetReceivedMonPointer:
ld a, [wPartyCount]
dec a
call AddNTimes
@@ -231,100 +229,102 @@ InGameTrade_GetReceivedMonPointer: ; 71d4f (1c:5d4f)
ld d, h
ret
-InGameTrade_TrainerString: ; 71d59 (1c:5d59)
+InGameTrade_TrainerString:
; "TRAINER@@@@@@@@@@"
db $5d, "@@@@@@@@@@"
-InGameTradeTextPointers: ; 71d64 (1c:5d64)
+InGameTradeTextPointers:
dw TradeTextPointers1
dw TradeTextPointers2
dw TradeTextPointers3
-TradeTextPointers1: ; 71d6a (1c:5d6a)
+TradeTextPointers1:
dw WannaTrade1Text
dw NoTrade1Text
dw WrongMon1Text
dw Thanks1Text
dw AfterTrade1Text
-TradeTextPointers2: ; 71d74 (1c:5d74)
+TradeTextPointers2:
dw WannaTrade2Text
dw NoTrade2Text
dw WrongMon2Text
dw Thanks2Text
dw AfterTrade2Text
-TradeTextPointers3: ; 71d7e (1c:5d7e)
+TradeTextPointers3:
dw WannaTrade3Text
dw NoTrade3Text
dw WrongMon3Text
dw Thanks3Text
dw AfterTrade3Text
-ConnectCableText: ; 71d88 (1c:5d88)
+ConnectCableText:
TX_FAR _ConnectCableText
db "@"
-TradedForText: ; 71d8d (1c:5d8d)
+TradedForText:
TX_FAR _TradedForText
- db $11, $a, "@"
+ TX_SFX_KEY_ITEM
+ TX_DELAY
+ db "@"
-WannaTrade1Text: ; 71d94 (1c:5d94)
+WannaTrade1Text:
TX_FAR _WannaTrade1Text
db "@"
-NoTrade1Text: ; 71d99 (1c:5d99)
+NoTrade1Text:
TX_FAR _NoTrade1Text
db "@"
-WrongMon1Text: ; 71d9e (1c:5d9e)
+WrongMon1Text:
TX_FAR _WrongMon1Text
db "@"
-Thanks1Text: ; 71da3 (1c:5da3)
+Thanks1Text:
TX_FAR _Thanks1Text
db "@"
-AfterTrade1Text: ; 71da8 (1c:5da8)
+AfterTrade1Text:
TX_FAR _AfterTrade1Text
db "@"
-WannaTrade2Text: ; 71dad (1c:5dad)
+WannaTrade2Text:
TX_FAR _WannaTrade2Text
db "@"
-NoTrade2Text: ; 71db2 (1c:5db2)
+NoTrade2Text:
TX_FAR _NoTrade2Text
db "@"
-WrongMon2Text: ; 71db7 (1c:5db7)
+WrongMon2Text:
TX_FAR _WrongMon2Text
db "@"
-Thanks2Text: ; 71dbc (1c:5dbc)
+Thanks2Text:
TX_FAR _Thanks2Text
db "@"
-AfterTrade2Text: ; 71dc1 (1c:5dc1)
+AfterTrade2Text:
TX_FAR _AfterTrade2Text
db "@"
-WannaTrade3Text: ; 71dc6 (1c:5dc6)
+WannaTrade3Text:
TX_FAR _WannaTrade3Text
db "@"
-NoTrade3Text: ; 71dcb (1c:5dcb)
+NoTrade3Text:
TX_FAR _NoTrade3Text
db "@"
-WrongMon3Text: ; 71dd0 (1c:5dd0)
+WrongMon3Text:
TX_FAR _WrongMon3Text
db "@"
-Thanks3Text: ; 71dd5 (1c:5dd5)
+Thanks3Text:
TX_FAR _Thanks3Text
db "@"
-AfterTrade3Text: ; 71dda (1c:5dda)
+AfterTrade3Text:
TX_FAR _AfterTrade3Text
db "@"
diff --git a/engine/init_player_data.asm b/engine/init_player_data.asm
new file mode 100644
index 00000000..c576e65a
--- /dev/null
+++ b/engine/init_player_data.asm
@@ -0,0 +1,55 @@
+InitPlayerData:
+InitPlayerData2:
+
+ call Random
+ ld a, [hRandomSub]
+ ld [wPlayerID], a
+
+ call Random
+ ld a, [hRandomAdd]
+ ld [wPlayerID + 1], a
+
+ ld a, $ff
+ ld [wUnusedD71B], a
+
+ ld hl, wPartyCount
+ call InitializeEmptyList
+ ld hl, wNumInBox
+ call InitializeEmptyList
+ ld hl, wNumBagItems
+ call InitializeEmptyList
+ ld hl, wNumBoxItems
+ call InitializeEmptyList
+
+START_MONEY EQU $3000
+ ld hl, wPlayerMoney + 1
+ ld a, START_MONEY / $100
+ ld [hld], a
+ xor a
+ ld [hli], a
+ inc hl
+ ld [hl], a
+
+ ld [wMonDataLocation], a
+
+ ld hl, wObtainedBadges
+ ld [hli], a
+
+ ld [hl], a
+
+ ld hl, wPlayerCoins
+ ld [hli], a
+ ld [hl], a
+
+ ld hl, wGameProgressFlags
+ ld bc, wGameProgressFlagsEnd - wGameProgressFlags
+ call FillMemory ; clear all game progress flags
+
+ jp InitializeMissableObjectsFlags
+
+InitializeEmptyList:
+ xor a ; count
+ ld [hli], a
+ dec a ; terminator
+ ld [hl], a
+ ret
diff --git a/engine/intro.asm b/engine/intro.asm
index 7c0464d3..ed532681 100755
--- a/engine/intro.asm
+++ b/engine/intro.asm
@@ -1,4 +1,8 @@
-PlayIntro: ; 41682 (10:5682)
+MOVE_GENGAR_RIGHT EQU $00
+MOVE_GENGAR_LEFT EQU $01
+MOVE_NIDORINO_RIGHT EQU $ff
+
+PlayIntro:
xor a
ld [hJoyHeld], a
inc a
@@ -13,36 +17,36 @@ PlayIntro: ; 41682 (10:5682)
call DelayFrame
ret
-PlayIntroScene: ; 4169d (10:569d)
- ld b, $7
- call GoPAL_SET
+PlayIntroScene:
+ ld b, SET_PAL_NIDORINO_INTRO
+ call RunPaletteCommand
ld a, %11100100
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
xor a
ld [hSCX], a
- ld b, $3
- call Func_4183f
+ ld b, $3 ; Gengar tiles
+ call IntroCopyTiles
ld a, 0
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
ld a, 80
- ld [W_BASECOORDY], a
- ld bc, $606
- call Func_417c7
- ld de, $28ff
- call Func_4180e
+ ld [wBaseCoordY], a
+ lb bc, 6, 6
+ call InitIntroNidorinoOAM
+ lb de, 80 / 2, MOVE_NIDORINO_RIGHT
+ call IntroMoveMon
ret c
; hip
- ld a, (SFX_1f_5f - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_HIP
call PlaySound
xor a
- ld [wd09f], a
+ ld [wIntroNidorinoBaseTile], a
ld de, IntroNidorinoAnimation1
call AnimateIntroNidorino
; hop
- ld a, (SFX_1f_60 - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_HOP
call PlaySound
ld de, IntroNidorinoAnimation2
call AnimateIntroNidorino
@@ -51,12 +55,12 @@ PlayIntroScene: ; 4169d (10:569d)
ret c
; hip
- ld a, (SFX_1f_5f - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_HIP
call PlaySound
ld de, IntroNidorinoAnimation1
call AnimateIntroNidorino
; hop
- ld a, (SFX_1f_60 - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_HOP
call PlaySound
ld de, IntroNidorinoAnimation2
call AnimateIntroNidorino
@@ -66,291 +70,298 @@ PlayIntroScene: ; 4169d (10:569d)
; raise
ld b, $4
- call Func_4183f
- ld a, (SFX_1f_61 - SFX_Headers_1f) / 3
+ call IntroCopyTiles
+ ld a, SFX_INTRO_RAISE
call PlaySound
- ld de, $401
- call Func_4180e
+ lb de, 8 / 2, MOVE_GENGAR_LEFT
+ call IntroMoveMon
ld c, $1e
call CheckForUserInterruption
ret c
; slash
ld b, $5
- call Func_4183f
- ld a, (SFX_1f_62 - SFX_Headers_1f) / 3
+ call IntroCopyTiles
+ ld a, SFX_INTRO_CRASH
call PlaySound
- ld de, $800
- call Func_4180e
+ lb de, 16 / 2, MOVE_GENGAR_RIGHT
+ call IntroMoveMon
; hip
- ld a, (SFX_1f_5f - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_HIP
call PlaySound
ld a, $24
- ld [wd09f], a
+ ld [wIntroNidorinoBaseTile], a
ld de, IntroNidorinoAnimation3
call AnimateIntroNidorino
ld c, $1e
call CheckForUserInterruption
ret c
- ld de, $401
- call Func_4180e
+ lb de, 8 / 2, MOVE_GENGAR_LEFT
+ call IntroMoveMon
ld b, $3
- call Func_4183f
+ call IntroCopyTiles
ld c, $3c
call CheckForUserInterruption
ret c
; hip
- ld a, (SFX_1f_5f - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_HIP
call PlaySound
xor a
- ld [wd09f], a
- ld de, IntroNidorinoAnimation4 ; $5931
+ ld [wIntroNidorinoBaseTile], a
+ ld de, IntroNidorinoAnimation4
call AnimateIntroNidorino
; hop
- ld a, (SFX_1f_60 - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_HOP
call PlaySound
- ld de, IntroNidorinoAnimation5 ; $593c
+ ld de, IntroNidorinoAnimation5
call AnimateIntroNidorino
ld c, $14
call CheckForUserInterruption
ret c
ld a, $24
- ld [wd09f], a
- ld de, IntroNidorinoAnimation6 ; $5947
+ ld [wIntroNidorinoBaseTile], a
+ ld de, IntroNidorinoAnimation6
call AnimateIntroNidorino
ld c, $1e
call CheckForUserInterruption
ret c
; lunge
- ld a, (SFX_1f_5e - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_LUNGE
call PlaySound
ld a, $48
- ld [wd09f], a
- ld de, IntroNidorinoAnimation7 ; $5950
+ ld [wIntroNidorinoBaseTile], a
+ ld de, IntroNidorinoAnimation7
jp AnimateIntroNidorino
-AnimateIntroNidorino: ; 41793 (10:5793)
+AnimateIntroNidorino:
ld a, [de]
cp $50
ret z
- ld [W_BASECOORDY], a ; wd082
+ ld [wBaseCoordY], a
inc de
ld a, [de]
- ld [W_BASECOORDX], a ; wd081
+ ld [wBaseCoordX], a
push de
- ld c, $24
- call Func_417ae
+ ld c, 6 * 6
+ call UpdateIntroNidorinoOAM
ld c, 5
call DelayFrames
pop de
inc de
jr AnimateIntroNidorino
-Func_417ae: ; 417ae (10:57ae)
+UpdateIntroNidorinoOAM:
ld hl, wOAMBuffer
- ld a, [wd09f]
+ ld a, [wIntroNidorinoBaseTile]
ld d, a
-.asm_417b5
- ld a, [W_BASECOORDY] ; wd082
+.loop
+ ld a, [wBaseCoordY]
add [hl]
- ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
+ ld [hli], a ; Y
+ ld a, [wBaseCoordX]
add [hl]
- ld [hli], a
+ ld [hli], a ; X
ld a, d
- ld [hli], a
+ ld [hli], a ; tile
inc hl
inc d
dec c
- jr nz, .asm_417b5
+ jr nz, .loop
ret
-Func_417c7: ; 417c7 (10:57c7)
+InitIntroNidorinoOAM:
ld hl, wOAMBuffer
- ld d, $0
-.asm_417cc
+ ld d, 0
+.loop
push bc
- ld a, [W_BASECOORDY] ; wd082
+ ld a, [wBaseCoordY]
ld e, a
-.asm_417d1
+.innerLoop
ld a, e
- add $8
+ add 8
ld e, a
- ld [hli], a
- ld a, [W_BASECOORDX] ; wd081
- ld [hli], a
+ ld [hli], a ; Y
+ ld a, [wBaseCoordX]
+ ld [hli], a ; X
ld a, d
- ld [hli], a
+ ld [hli], a ; tile
ld a, $80
- ld [hli], a
+ ld [hli], a ; attributes
inc d
dec c
- jr nz, .asm_417d1
- ld a, [W_BASECOORDX] ; wd081
- add $8
- ld [W_BASECOORDX], a ; wd081
+ jr nz, .innerLoop
+ ld a, [wBaseCoordX]
+ add 8
+ ld [wBaseCoordX], a
pop bc
dec b
- jr nz, .asm_417cc
+ jr nz, .loop
ret
-Func_417f0: ; 417f0 (10:57f0)
+IntroClearScreen:
ld hl, vBGMap1
ld bc, $240
- jr asm_417fe
+ jr IntroClearCommon
-Func_417f8: ; 417f8 (10:57f8)
- hlCoord 0, 4
- ld bc, $c8
-asm_417fe: ; 417fe (10:57fe)
+IntroClearMiddleOfScreen:
+; clear the area of the tile map between the black bars on the top and bottom
+ coord hl, 0, 4
+ ld bc, SCREEN_WIDTH * 10
+
+IntroClearCommon:
ld [hl], $0
inc hl
dec bc
ld a, b
or c
- jr nz, asm_417fe
+ jr nz, IntroClearCommon
ret
-Func_41807: ; 41807 (10:5807)
+IntroPlaceBlackTiles:
ld a, $1
-.asm_41809
+.loop
ld [hli], a
dec c
- jr nz, .asm_41809
+ jr nz, .loop
ret
-Func_4180e: ; 4180e (10:580e)
+IntroMoveMon:
+; d = number of times to move the mon (2 pixels each time)
+; e: $00 = move Gengar right, $01 = move Gengar left, $ff = move Nidorino right
ld a, e
cp $ff
- jr z, .asm_4181d
+ jr z, .moveNidorinoRight
cp $1
- jr z, .asm_4182d
+ jr z, .moveGengarLeft
+; move Gengar right
ld a, [hSCX]
dec a
dec a
- jr .asm_41831
-.asm_4181d
+ jr .next
+.moveNidorinoRight
push de
- ld a, $2
- ld [W_BASECOORDX], a ; wd081
+ ld a, 2
+ ld [wBaseCoordX], a
xor a
- ld [W_BASECOORDY], a ; wd082
- ld c, $24
- call Func_417ae
+ ld [wBaseCoordY], a
+ ld c, 6 * 6
+ call UpdateIntroNidorinoOAM
pop de
-.asm_4182d
+.moveGengarLeft
ld a, [hSCX]
inc a
inc a
-.asm_41831
+.next
ld [hSCX], a
push de
- ld c, $2
+ ld c, 2
call CheckForUserInterruption
pop de
ret c
dec d
- jr nz, Func_4180e
+ jr nz, IntroMoveMon
ret
-Func_4183f: ; 4183f (10:583f)
- hlCoord 13, 7
+IntroCopyTiles:
+ coord hl, 13, 7
-CopyTileIDsFromList_ZeroBaseTileID: ; 41842 (10:5842)
- ld c, $0
+CopyTileIDsFromList_ZeroBaseTileID:
+ ld c, 0
predef_jump CopyTileIDsFromList
-Func_41849: ; 41849 (10:5849)
- predef Func_79869
+PlayMoveSoundB:
+; unused
+ predef GetMoveSoundB
ld a, b
jp PlaySound
-LoadIntroGraphics: ; 41852 (10:5852)
- ld hl, FightIntroBackMon ; $5a99
+LoadIntroGraphics:
+ ld hl, FightIntroBackMon
ld de, vChars2
- ld bc, $600
+ ld bc, FightIntroBackMonEnd - FightIntroBackMon
ld a, BANK(FightIntroBackMon)
call FarCopyData2
- ld hl, GameFreakIntro ; $5959
+ ld hl, GameFreakIntro
ld de, vChars2 + $600
- ld bc, $140
+ ld bc, GameFreakIntroEnd - GameFreakIntro
ld a, BANK(GameFreakIntro)
call FarCopyData2
- ld hl, GameFreakIntro ; $5959
+ ld hl, GameFreakIntro
ld de, vChars1
- ld bc, $140
+ ld bc, GameFreakIntroEnd - GameFreakIntro
ld a, BANK(GameFreakIntro)
call FarCopyData2
- ld hl, FightIntroFrontMon ; $6099
+ ld hl, FightIntroFrontMon
ld de, vChars0
- ld bc, $6c0
+ ld bc, FightIntroFrontMonEnd - FightIntroFrontMon
ld a, BANK(FightIntroFrontMon)
jp FarCopyData2
-PlayShootingStar: ; 4188a (10:588a)
- ld b, $c
- call GoPAL_SET
+PlayShootingStar:
+ ld b, SET_PAL_GAME_FREAK_INTRO
+ call RunPaletteCommand
callba LoadCopyrightAndTextBoxTiles
- ld a, $e4
- ld [rBGP], a ; $ff47
- ld c, $b4
+ ld a, %11100100
+ ld [rBGP], a
+ ld c, 180
call DelayFrames
call ClearScreen
call DisableLCD
xor a
- ld [W_CUROPPONENT], a ; wd059
- call Func_418e9
+ ld [wCurOpponent], a
+ call IntroDrawBlackBars
call LoadIntroGraphics
call EnableLCD
- ld hl, rLCDC ; $ff40
+ ld hl, rLCDC
res 5, [hl]
set 3, [hl]
- ld c, $40
+ ld c, 64
call DelayFrames
callba AnimateShootingStar
push af
pop af
- jr c, .asm_418d0
- ld c, $28
+ jr c, .next ; skip the delay if the user interrupted the animation
+ ld c, 40
call DelayFrames
-.asm_418d0
+.next
ld a, BANK(Music_IntroBattle)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_INTRO_BATTLE
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
- call Func_417f8
+ call IntroClearMiddleOfScreen
call ClearSprites
jp Delay3
-Func_418e9: ; 418e9 (10:58e9)
- call Func_417f0
- ld hl, wTileMap
- ld c, $50
- call Func_41807
- hlCoord 0, 14
- ld c, $50
- call Func_41807
+IntroDrawBlackBars:
+; clear the screen and draw black bars on the top and bottom
+ call IntroClearScreen
+ coord hl, 0, 0
+ ld c, SCREEN_WIDTH * 4
+ call IntroPlaceBlackTiles
+ coord hl, 0, 14
+ ld c, SCREEN_WIDTH * 4
+ call IntroPlaceBlackTiles
ld hl, vBGMap1
ld c, $80
- call Func_41807
+ call IntroPlaceBlackTiles
ld hl, vBGMap1 + $1c0
ld c, $80
- jp Func_41807
+ jp IntroPlaceBlackTiles
-Func_4190c: ; 4190c (10:590c)
+EmptyFunc4:
ret
-IntroNidorinoAnimation0: ; 4190d (10:590d)
+IntroNidorinoAnimation0:
db 0, 0
db $50
-IntroNidorinoAnimation1: ; 41910 (10:5910)
+IntroNidorinoAnimation1:
; This is a sequence of pixel movements for part of the Nidorino animation. This
; list describes how Nidorino should hop.
; First byte is y movement, second byte is x movement
@@ -361,7 +372,7 @@ IntroNidorinoAnimation1: ; 41910 (10:5910)
db 2, 2
db $50 ; list terminator
-IntroNidorinoAnimation2: ; 4191b (10:591b)
+IntroNidorinoAnimation2:
; This is a sequence of pixel movements for part of the Nidorino animation.
; First byte is y movement, second byte is x movement
db 0, 0
@@ -371,7 +382,7 @@ IntroNidorinoAnimation2: ; 4191b (10:591b)
db 2, -2
db $50 ; list terminator
-IntroNidorinoAnimation3: ; 41926 (10:5926)
+IntroNidorinoAnimation3:
; This is a sequence of pixel movements for part of the Nidorino animation.
; First byte is y movement, second byte is x movement
db 0, 0
@@ -381,7 +392,7 @@ IntroNidorinoAnimation3: ; 41926 (10:5926)
db 12, 6
db $50 ; list terminator
-IntroNidorinoAnimation4: ; 41931 (10:5931)
+IntroNidorinoAnimation4:
; This is a sequence of pixel movements for part of the Nidorino animation.
; First byte is y movement, second byte is x movement
db 0, 0
@@ -391,7 +402,7 @@ IntroNidorinoAnimation4: ; 41931 (10:5931)
db 8, -4
db $50 ; list terminator
-IntroNidorinoAnimation5: ; 4193c (10:593c)
+IntroNidorinoAnimation5:
; This is a sequence of pixel movements for part of the Nidorino animation.
; First byte is y movement, second byte is x movement
db 0, 0
@@ -401,7 +412,7 @@ IntroNidorinoAnimation5: ; 4193c (10:593c)
db 8, 4
db $50 ; list terminator
-IntroNidorinoAnimation6: ; 41947 (10:5947)
+IntroNidorinoAnimation6:
; This is a sequence of pixel movements for part of the Nidorino animation.
; First byte is y movement, second byte is x movement
db 0, 0
@@ -410,7 +421,7 @@ IntroNidorinoAnimation6: ; 41947 (10:5947)
db 0, 0
db $50 ; list terminator
-IntroNidorinoAnimation7: ; 41950 (10:5950)
+IntroNidorinoAnimation7:
; This is a sequence of pixel movements for part of the Nidorino animation.
; First byte is y movement, second byte is x movement
db -8, -16
@@ -419,25 +430,29 @@ IntroNidorinoAnimation7: ; 41950 (10:5950)
db -4, -10
db $50 ; list terminator
-GameFreakIntro: ; 41959 (10:5959)
+GameFreakIntro:
INCBIN "gfx/gamefreak_intro.2bpp"
INCBIN "gfx/gamefreak_logo.2bpp"
ds $10 ; blank tile
+GameFreakIntroEnd:
-FightIntroBackMon: ; 41a99 (10:5a99)
+FightIntroBackMon:
INCBIN "gfx/intro_fight.2bpp"
+FightIntroBackMonEnd:
-FightIntroFrontMon: ; 42099 (10:6099)
+FightIntroFrontMon:
IF DEF(_RED)
INCBIN "gfx/red/intro_nido_1.6x6.2bpp"
INCBIN "gfx/red/intro_nido_2.6x6.2bpp"
INCBIN "gfx/red/intro_nido_3.6x6.2bpp"
- ds $10 ; blank tile
ENDC
IF DEF(_BLUE)
INCBIN "gfx/blue/intro_purin_1.6x6.2bpp"
INCBIN "gfx/blue/intro_purin_2.6x6.2bpp"
INCBIN "gfx/blue/intro_purin_3.6x6.2bpp"
- ds $10 ; blank tile
ENDC
+
+FightIntroFrontMonEnd:
+
+ ds $10 ; blank tile
diff --git a/engine/items/inventory.asm b/engine/items/inventory.asm
new file mode 100644
index 00000000..1294ed8d
--- /dev/null
+++ b/engine/items/inventory.asm
@@ -0,0 +1,150 @@
+; function to add an item (in varying quantities) to the player's bag or PC box
+; INPUT:
+; hl = address of inventory (either wNumBagItems or wNumBoxItems)
+; [wcf91] = item ID
+; [wItemQuantity] = item quantity
+; sets carry flag if successful, unsets carry flag if unsuccessful
+AddItemToInventory_:
+ ld a,[wItemQuantity] ; a = item quantity
+ push af
+ push bc
+ push de
+ push hl
+ push hl
+ ld d,PC_ITEM_CAPACITY ; how many items the PC can hold
+ ld a,wNumBagItems & $FF
+ cp l
+ jr nz,.checkIfInventoryFull
+ ld a,wNumBagItems >> 8
+ cp h
+ jr nz,.checkIfInventoryFull
+; if the destination is the bag
+ ld d,BAG_ITEM_CAPACITY ; how many items the bag can hold
+.checkIfInventoryFull
+ ld a,[hl]
+ sub d
+ ld d,a
+ ld a,[hli]
+ and a
+ jr z,.addNewItem
+.loop
+ ld a,[hli]
+ ld b,a ; b = ID of current item in table
+ ld a,[wcf91] ; a = ID of item being added
+ cp b ; does the current item in the table match the item being added?
+ jp z,.increaseItemQuantity ; if so, increase the item's quantity
+ inc hl
+ ld a,[hl]
+ cp a,$ff ; is it the end of the table?
+ jr nz,.loop
+.addNewItem ; add an item not yet in the inventory
+ pop hl
+ ld a,d
+ and a ; is there room for a new item slot?
+ jr z,.done
+; if there is room
+ inc [hl] ; increment the number of items in the inventory
+ ld a,[hl] ; the number of items will be the index of the new item
+ add a
+ dec a
+ ld c,a
+ ld b,0
+ add hl,bc ; hl = address to store the item
+ ld a,[wcf91]
+ ld [hli],a ; store item ID
+ ld a,[wItemQuantity]
+ ld [hli],a ; store item quantity
+ ld [hl],$ff ; store terminator
+ jp .success
+.increaseItemQuantity ; increase the quantity of an item already in the inventory
+ ld a,[wItemQuantity]
+ ld b,a ; b = quantity to add
+ ld a,[hl] ; a = existing item quantity
+ add b ; a = new item quantity
+ cp a,100
+ jp c,.storeNewQuantity ; if the new quantity is less than 100, store it
+; if the new quantity is greater than or equal to 100,
+; try to max out the current slot and add the rest in a new slot
+ sub a,99
+ ld [wItemQuantity],a ; a = amount left over (to put in the new slot)
+ ld a,d
+ and a ; is there room for a new item slot?
+ jr z,.increaseItemQuantityFailed
+; if so, store 99 in the current slot and store the rest in a new slot
+ ld a,99
+ ld [hli],a
+ jp .loop
+.increaseItemQuantityFailed
+ pop hl
+ and a
+ jr .done
+.storeNewQuantity
+ ld [hl],a
+ pop hl
+.success
+ scf
+.done
+ pop hl
+ pop de
+ pop bc
+ pop bc
+ ld a,b
+ ld [wItemQuantity],a ; restore the initial value from when the function was called
+ ret
+
+; function to remove an item (in varying quantities) from the player's bag or PC box
+; INPUT:
+; hl = address of inventory (either wNumBagItems or wNumBoxItems)
+; [wWhichPokemon] = index (within the inventory) of the item to remove
+; [wItemQuantity] = quantity to remove
+RemoveItemFromInventory_:
+ push hl
+ inc hl
+ ld a,[wWhichPokemon] ; index (within the inventory) of the item being removed
+ sla a
+ add l
+ ld l,a
+ jr nc,.noCarry
+ inc h
+.noCarry
+ inc hl
+ ld a,[wItemQuantity] ; quantity being removed
+ ld e,a
+ ld a,[hl] ; a = current quantity
+ sub e
+ ld [hld],a ; store new quantity
+ ld [wMaxItemQuantity],a
+ and a
+ jr nz,.skipMovingUpSlots
+; if the remaining quantity is 0,
+; remove the emptied item slot and move up all the following item slots
+.moveSlotsUp
+ ld e,l
+ ld d,h
+ inc de
+ inc de ; de = address of the slot following the emptied one
+.loop ; loop to move up the following slots
+ ld a,[de]
+ inc de
+ ld [hli],a
+ cp a,$ff
+ jr nz,.loop
+; update menu info
+ xor a
+ ld [wListScrollOffset],a
+ ld [wCurrentMenuItem],a
+ ld [wBagSavedMenuItem],a
+ ld [wSavedListScrollOffset],a
+ pop hl
+ ld a,[hl] ; a = number of items in inventory
+ dec a ; decrement the number of items
+ ld [hl],a ; store new number of items
+ ld [wListCount],a
+ cp a,2
+ jr c,.done
+ ld [wMaxMenuItem],a
+ jr .done
+.skipMovingUpSlots
+ pop hl
+.done
+ ret
diff --git a/engine/items/itemfinder.asm b/engine/items/itemfinder.asm
index d7e5b3ce..7c15d4bb 100755
--- a/engine/items/itemfinder.asm
+++ b/engine/items/itemfinder.asm
@@ -1,16 +1,16 @@
-HiddenItemNear: ; 7481f (1d:481f)
+HiddenItemNear:
ld hl, HiddenItemCoords
- ld b, $0
-.asm_74824
- ld de, $0003
- ld a, [W_CURMAP]
+ ld b, 0
+.loop
+ ld de, 3
+ ld a, [wCurMap]
call IsInRestOfArray
ret nc ; return if current map has no hidden items
push bc
push hl
- ld hl, wd6f0
+ ld hl, wObtainedHiddenItemsFlags
ld c, b
- ld b, $2
+ ld b, FLAG_TEST
predef FlagActionPredef
ld a, c
pop hl
@@ -22,28 +22,30 @@ HiddenItemNear: ; 7481f (1d:481f)
inc hl
ld e, [hl]
inc hl
- jr nz, .asm_74824 ; 0x74845 $dd
- ld a, [W_YCOORD]
- call Func_7486b
+ jr nz, .loop ; if the item has already been obtained
+; check if the item is within 4-5 tiles (depending on the direction of item)
+ ld a, [wYCoord]
+ call Sub5ClampTo0
cp d
- jr nc, .asm_74824 ; 0x7484e $d4
- ld a, [W_YCOORD]
- add $4
+ jr nc, .loop
+ ld a, [wYCoord]
+ add 4
cp d
- jr c, .asm_74824 ; 0x74856 $cc
- ld a, [W_XCOORD]
- call Func_7486b
+ jr c, .loop
+ ld a, [wXCoord]
+ call Sub5ClampTo0
cp e
- jr nc, .asm_74824 ; 0x7485f $c3
- ld a, [W_XCOORD]
- add $5
+ jr nc, .loop
+ ld a, [wXCoord]
+ add 5
cp e
- jr c, .asm_74824 ; 0x74867 $bb
+ jr c, .loop
scf
ret
-Func_7486b: ; 7486b (1d:486b)
- sub $5
+Sub5ClampTo0:
+; subtract 5 but clamp to 0
+ sub 5
cp $f0
ret c
xor a
diff --git a/engine/items/items.asm b/engine/items/items.asm
index 21e6e924..f8873a6e 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -1,7 +1,7 @@
-UseItem_: ; d5c7 (3:55c7)
+UseItem_:
ld a,1
- ld [wcd6a],a
- ld a,[wcf91] ;contains item_ID
+ ld [wActionResultOrTookBattleTurn],a ; initialise to success value
+ ld a,[wcf91] ;contains item_ID
cp a,HM_01
jp nc,ItemUseTMHM
ld hl,ItemUsePtrTable
@@ -15,7 +15,7 @@ UseItem_: ; d5c7 (3:55c7)
ld l,a
jp [hl]
-ItemUsePtrTable: ; d5e1 (3:55e1)
+ItemUsePtrTable:
dw ItemUseBall ; MASTER_BALL
dw ItemUseBall ; ULTRA_BALL
dw ItemUseBall ; GREAT_BALL
@@ -70,7 +70,7 @@ ItemUsePtrTable: ; d5e1 (3:55e1)
dw ItemUseMedicine ; FULL_HEAL
dw ItemUseMedicine ; REVIVE
dw ItemUseMedicine ; MAX_REVIVE
- dw ItemUseGuardSpec ; GUARD_SPEC_
+ dw ItemUseGuardSpec ; GUARD_SPEC
dw ItemUseSuperRepel ; SUPER_REPL
dw ItemUseMaxRepel ; MAX_REPEL
dw ItemUseDireHit ; DIRE_HIT
@@ -78,7 +78,7 @@ ItemUsePtrTable: ; d5e1 (3:55e1)
dw ItemUseMedicine ; FRESH_WATER
dw ItemUseMedicine ; SODA_POP
dw ItemUseMedicine ; LEMONADE
- dw UnusableItem ; S_S__TICKET
+ dw UnusableItem ; S_S_TICKET
dw UnusableItem ; GOLD_TEETH
dw ItemUseXStat ; X_ATTACK
dw ItemUseXStat ; X_DEFEND
@@ -90,108 +90,154 @@ ItemUsePtrTable: ; d5e1 (3:55e1)
dw UnusableItem ; SILPH_SCOPE
dw ItemUsePokeflute ; POKE_FLUTE
dw UnusableItem ; LIFT_KEY
- dw UnusableItem ; EXP__ALL
- dw OldRodCode ; OLD_ROD
- dw GoodRodCode ; GOOD_ROD
- dw SuperRodCode ; SUPER_ROD
+ dw UnusableItem ; EXP_ALL
+ dw ItemUseOldRod ; OLD_ROD
+ dw ItemUseGoodRod ; GOOD_ROD
+ dw ItemUseSuperRod ; SUPER_ROD
dw ItemUsePPUp ; PP_UP (real one)
dw ItemUsePPRestore ; ETHER
dw ItemUsePPRestore ; MAX_ETHER
dw ItemUsePPRestore ; ELIXER
dw ItemUsePPRestore ; MAX_ELIXER
-ItemUseBall: ; d687 (3:5687)
- ld a,[W_ISINBATTLE]
+ItemUseBall:
+
+; Balls can't be used out of battle.
+ ld a,[wIsInBattle]
and a
- jp z,ItemUseNotTime ; not in battle
+ jp z,ItemUseNotTime
+
+; Balls can't catch trainers' Pokémon.
dec a
jp nz,ThrowBallAtTrainerMon
- ld a,[W_BATTLETYPE]
+
+; If this is for the old man battle, skip checking if the party & box are full.
+ ld a,[wBattleType]
dec a
- jr z,.UseBall
- ld a,[wPartyCount] ;is Party full?
+ jr z,.canUseBall
+
+ ld a,[wPartyCount] ; is party full?
cp a,PARTY_LENGTH
- jr nz,.UseBall
- ld a,[W_NUMINBOX] ;is Box full?
+ jr nz,.canUseBall
+ ld a,[wNumInBox] ; is box full?
cp a,MONS_PER_BOX
jp z,BoxFullCannotThrowBall
-.UseBall ;$56a7
-;ok, you can use a ball
+
+.canUseBall
xor a
- ld [wd11c],a
- ld a,[W_BATTLETYPE]
- cp a,2 ;SafariBattle
+ ld [wCapturedMonSpecies],a
+
+ ld a,[wBattleType]
+ cp a,BATTLE_TYPE_SAFARI
jr nz,.skipSafariZoneCode
+
.safariZone
- ; remove a Safari Ball from inventory
- ld hl,W_NUMSAFARIBALLS
- dec [hl]
-.skipSafariZoneCode ;$56b6
- call GoPAL_SET_CF1C
- ld a,$43
- ld [wd11e],a
- call LoadScreenTilesFromBuffer1 ;restore screenBuffer from Backup
+ ld hl,wNumSafariBalls
+ dec [hl] ; remove a Safari Ball
+
+.skipSafariZoneCode
+ call RunDefaultPaletteCommand
+
+ ld a,$43 ; successful capture value
+ ld [wPokeBallAnimData],a
+
+ call LoadScreenTilesFromBuffer1
ld hl,ItemUseText00
call PrintText
+
+; If the player is fighting an unidentified ghost, set the value that indicates
+; the Pokémon can't be caught and skip the capture calculations.
callab IsGhostBattle
- ld b,$10
- jp z,.next12
- ld a,[W_BATTLETYPE]
+ ld b,$10 ; can't be caught value
+ jp z,.setAnimData
+
+ ld a,[wBattleType]
dec a
jr nz,.notOldManBattle
+
.oldManBattle
- ld hl,W_GRASSRATE
+ ld hl,wGrassRate
ld de,wPlayerName
- ld bc,11
- call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno glitch)
- jp .BallSuccess ;$578b
-.notOldManBattle ;$56e9
- ld a,[W_CURMAP]
+ ld bc,NAME_LENGTH
+ call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno. glitch)
+ jp .captured
+
+.notOldManBattle
+; If the player is fighting the ghost Marowak, set the value that indicates the
+; Pokémon can't be caught and skip the capture calculations.
+ ld a,[wCurMap]
cp a,POKEMONTOWER_6
jr nz,.loop
ld a,[wEnemyMonSpecies2]
cp a,MAROWAK
- ld b,$10
- jp z,.next12
-; if not fighting ghost Marowak, loop until a random number in the current
-; pokeball's allowed range is found
-.loop ;$56fa
+ ld b,$10 ; can't be caught value
+ jp z,.setAnimData
+
+; Get the first random number. Let it be called Rand1.
+; Rand1 must be within a certain range according the kind of ball being thrown.
+; The ranges are as follows.
+; Poké Ball: [0, 255]
+; Great Ball: [0, 200]
+; Ultra/Safari Ball: [0, 150]
+; Loop until an acceptable number is found.
+
+.loop
call Random
ld b,a
+
+; Get the item ID.
ld hl,wcf91
ld a,[hl]
+
+; The Master Ball always succeeds.
cp a,MASTER_BALL
- jp z,.BallSuccess ;$578b
+ jp z,.captured
+
+; Anything will do for the basic Poké Ball.
cp a,POKE_BALL
jr z,.checkForAilments
+
+; If it's a Great/Ultra/Safari Ball and Rand1 is greater than 200, try again.
ld a,200
cp b
- jr c,.loop ;get only numbers <= 200 for Great Ball
+ jr c,.loop
+
+; Less than or equal to 200 is good enough for a Great Ball.
ld a,[hl]
cp a,GREAT_BALL
jr z,.checkForAilments
- ld a,150 ;get only numbers <= 150 for Ultra Ball
+
+; If it's an Ultra/Safari Ball and Rand1 is greater than 150, try again.
+ ld a,150
cp b
jr c,.loop
-.checkForAilments ;$571a
-; pokemon can be caught more easily with any (primary) status ailment
-; Frozen/Asleep pokemon are relatively even easier to catch
-; for Frozen/Asleep pokemon, any random number from 0-24 ensures a catch.
-; for the others, a random number from 0-11 ensures a catch.
- ld a,[wEnemyMonStatus] ;status ailments
+
+.checkForAilments
+; Pokémon can be caught more easily with a status ailment.
+; Depending on the status ailment, a certain value will be subtracted from
+; Rand1. Let this value be called Status.
+; The larger Status is, the more easily the Pokémon can be caught.
+; no status ailment: Status = 0
+; Burn/Paralysis/Poison: Status = 12
+; Freeze/Sleep: Status = 25
+; If Status is greater than Rand1, the Pokémon will be caught for sure.
+ ld a,[wEnemyMonStatus]
and a
- jr z,.noAilments
- and a, 1 << FRZ | SLP ;is frozen and/or asleep?
+ jr z,.skipAilmentValueSubtraction ; no ailments
+ and a, 1 << FRZ | SLP
ld c,12
jr z,.notFrozenOrAsleep
ld c,25
-.notFrozenOrAsleep ;$5728
+.notFrozenOrAsleep
ld a,b
sub c
- jp c,.BallSuccess ;$578b
+ jp c,.captured
ld b,a
-.noAilments ;$572e
- push bc ;save RANDOM number
+
+.skipAilmentValueSubtraction
+ push bc ; save (Rand1 - Status)
+
+; Calculate MaxHP * 255.
xor a
ld [H_MULTIPLICAND],a
ld hl,wEnemyMonMaxHP
@@ -201,125 +247,182 @@ ItemUseBall: ; d687 (3:5687)
ld [H_MULTIPLICAND + 2],a
ld a,255
ld [H_MULTIPLIER],a
- call Multiply ; MaxHP * 255
+ call Multiply
+
+; Determine BallFactor. It's 8 for Great Balls and 12 for the others.
ld a,[wcf91]
cp a,GREAT_BALL
- ld a,12 ;any other BallFactor
- jr nz,.next7
+ ld a,12
+ jr nz,.skip1
ld a,8
-.next7 ;$574d
+
+.skip1
+; Note that the results of all division operations are floored.
+
+; Calculate (MaxHP * 255) / BallFactor.
ld [H_DIVISOR],a
- ld b,4 ; number of bytes in dividend
+ ld b,4 ; number of bytes in dividend
call Divide
+
+; Divide the enemy's current HP by 4. HP is not supposed to exceed 999 so
+; the result should fit in a. If the division results in a quotient of 0,
+; change it to 1.
ld hl,wEnemyMonHP
ld a,[hli]
ld b,a
ld a,[hl]
-
-; explanation: we have a 16-bit value equal to [b << 8 | a].
-; This number is divided by 4. The result is 8 bit (reg. a).
-; Always bigger than zero.
srl b
rr a
srl b
- rr a ; a = current HP / 4
+ rr a
and a
- jr nz,.next8
+ jr nz,.skip2
inc a
-.next8 ;$5766
+
+.skip2
+; Let W = ((MaxHP * 255) / BallFactor) / max(HP / 4, 1). Calculate W.
ld [H_DIVISOR],a
ld b,4
- call Divide ; ((MaxHP * 255) / BallFactor) / (CurHP / 4)
+ call Divide
+
+; If W > 255, store 255 in [H_QUOTIENT + 3].
+; Let X = min(W, 255) = [H_QUOTIENT + 3].
ld a,[H_QUOTIENT + 2]
and a
- jr z,.next9
+ jr z,.skip3
ld a,255
ld [H_QUOTIENT + 3],a
-.next9 ;$5776
- pop bc
- ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate
+
+.skip3
+ pop bc ; b = Rand1 - Status
+
+; If Rand1 - Status > CatchRate, the ball fails to capture the Pokémon.
+ ld a,[wEnemyMonCatchRate]
cp b
- jr c,.next10
+ jr c,.failedToCapture
+
+; If W > 255, the ball captures the Pokémon.
ld a,[H_QUOTIENT + 2]
and a
- jr nz,.BallSuccess ; if ((MaxHP * 255) / BallFactor) / (CurHP / 4) > 0x255, automatic success
- call Random
+ jr nz,.captured
+
+ call Random ; Let this random number be called Rand2.
+
+; If Rand2 > X, the ball fails to capture the Pokémon.
ld b,a
ld a,[H_QUOTIENT + 3]
cp b
- jr c,.next10
-.BallSuccess ;$578b
- jr .BallSuccess2
-.next10 ;$578d
+ jr c,.failedToCapture
+
+.captured
+ jr .skipShakeCalculations
+
+.failedToCapture
ld a,[H_QUOTIENT + 3]
- ld [wd11e],a
+ ld [wPokeBallCaptureCalcTemp],a ; Save X.
+
+; Calculate CatchRate * 100.
xor a
ld [H_MULTIPLICAND],a
ld [H_MULTIPLICAND + 1],a
- ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate
+ ld a,[wEnemyMonCatchRate]
ld [H_MULTIPLICAND + 2],a
ld a,100
ld [H_MULTIPLIER],a
- call Multiply ; CatchRate * 100
+ call Multiply
+
+; Determine BallFactor2.
+; Poké Ball: BallFactor2 = 255
+; Great Ball: BallFactor2 = 200
+; Ultra/Safari Ball: BallFactor2 = 150
ld a,[wcf91]
ld b,255
cp a,POKE_BALL
- jr z,.next11
+ jr z,.skip4
ld b,200
cp a,GREAT_BALL
- jr z,.next11
+ jr z,.skip4
ld b,150
cp a,ULTRA_BALL
- jr z,.next11
-.next11 ;$57b8
+ jr z,.skip4
+
+.skip4
+; Let Y = (CatchRate * 100) / BallFactor2. Calculate Y.
ld a,b
ld [H_DIVISOR],a
ld b,4
call Divide
+
+; If Y > 255, there are 3 shakes.
+; Note that this shouldn't be possible.
+; The maximum value of Y is (255 * 100) / 150 = 170.
ld a,[H_QUOTIENT + 2]
and a
- ld b,$63
- jr nz,.next12
- ld a,[wd11e]
+ ld b,$63 ; 3 shakes
+ jr nz,.setAnimData
+
+; Calculate X * Y.
+ ld a,[wPokeBallCaptureCalcTemp]
ld [H_MULTIPLIER],a
call Multiply
+
+; Calculate (X * Y) / 255.
ld a,255
ld [H_DIVISOR],a
ld b,4
call Divide
- ld a,[wEnemyMonStatus] ;status ailments
+
+; Determine Status2.
+; no status ailment: Status2 = 0
+; Burn/Paralysis/Poison: Status2 = 5
+; Freeze/Sleep: Status2 = 10
+ ld a,[wEnemyMonStatus]
and a
- jr z,.next13
+ jr z,.skip5
and a, 1 << FRZ | SLP
ld b,5
- jr z,.next14
+ jr z,.addAilmentValue
ld b,10
-.next14 ;$57e6
+
+.addAilmentValue
+; If the Pokémon has a status ailment, add Status2.
ld a,[H_QUOTIENT + 3]
add b
ld [H_QUOTIENT + 3],a
-.next13 ;$57eb
+
+.skip5
+; Finally determine the number of shakes.
+; Let Z = ((X * Y) / 255) + Status2 = [H_QUOTIENT + 3].
+; The number of shakes depend on the range Z is in.
+; 0 ≤ Z < 10: 0 shakes (the ball misses)
+; 10 ≤ Z < 30: 1 shake
+; 30 ≤ Z < 70: 2 shakes
+; 70 ≤ Z: 3 shakes
ld a,[H_QUOTIENT + 3]
cp a,10
ld b,$20
- jr c,.next12
+ jr c,.setAnimData
cp a,30
ld b,$61
- jr c,.next12
+ jr c,.setAnimData
cp a,70
ld b,$62
- jr c,.next12
+ jr c,.setAnimData
ld b,$63
-.next12 ;$5801
+
+.setAnimData
ld a,b
- ld [wd11e],a
-.BallSuccess2 ;$5805
+ ld [wPokeBallAnimData],a
+
+.skipShakeCalculations
ld c,20
call DelayFrames
+
+; Do the animation.
ld a,TOSS_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
xor a
- ld [$fff3],a
+ ld [H_WHOSETURN],a
ld [wAnimationType],a
ld [wDamageMultipliers],a
ld a,[wWhichPokemon]
@@ -331,51 +434,67 @@ ItemUseBall: ; d687 (3:5687)
ld [wcf91],a
pop af
ld [wWhichPokemon],a
- ld a,[wd11e]
+
+; Determine the message to display from the animation.
+ ld a,[wPokeBallAnimData]
cp a,$10
ld hl,ItemUseBallText00
- jp z,.printText0
+ jp z,.printMessage
cp a,$20
ld hl,ItemUseBallText01
- jp z,.printText0
+ jp z,.printMessage
cp a,$61
ld hl,ItemUseBallText02
- jp z,.printText0
+ jp z,.printMessage
cp a,$62
ld hl,ItemUseBallText03
- jp z,.printText0
+ jp z,.printMessage
cp a,$63
ld hl,ItemUseBallText04
- jp z,.printText0
- ld hl,wEnemyMonHP ;current HP
+ jp z,.printMessage
+
+; Save current HP.
+ ld hl,wEnemyMonHP
ld a,[hli]
push af
ld a,[hli]
- push af ;backup currentHP...
+ push af
+
+; Save status ailment.
inc hl
ld a,[hl]
- push af ;...and status ailments
+ push af
+
push hl
- ld hl,W_ENEMYBATTSTATUS3
+
+; If the Pokémon is transformed, the Pokémon is assumed to be a Ditto.
+; This is a bug because a wild Pokémon could have used Transform via
+; Mirror Move even though the only wild Pokémon that knows Transform is Ditto.
+ ld hl,wEnemyBattleStatus3
bit Transformed,[hl]
- jr z,.next15
- ld a,$4c
+ jr z,.notTransformed
+ ld a,DITTO
ld [wEnemyMonSpecies2],a
- jr .next16
-.next15 ;$5871
+ jr .skip6
+
+.notTransformed
+; If the Pokémon is not transformed, set the transformed bit and copy the
+; DVs to wTransformedEnemyMonOriginalDVs so that LoadEnemyMonData won't generate
+; new DVs.
set Transformed,[hl]
- ld hl,wcceb
+ ld hl,wTransformedEnemyMonOriginalDVs
ld a,[wEnemyMonDVs]
ld [hli],a
ld a,[wEnemyMonDVs + 1]
ld [hl],a
-.next16 ;$587e
+
+.skip6
ld a,[wcf91]
push af
ld a,[wEnemyMonSpecies2]
ld [wcf91],a
ld a,[wEnemyMonLevel]
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
callab LoadEnemyMonData
pop af
ld [wcf91],a
@@ -387,124 +506,136 @@ ItemUseBall: ; d687 (3:5687)
ld [hld],a
pop af
ld [hl],a
- ld a,[wEnemyMonSpecies] ;enemy
- ld [wd11c],a
+ ld a,[wEnemyMonSpecies]
+ ld [wCapturedMonSpecies],a
ld [wcf91],a
ld [wd11e],a
- ld a,[W_BATTLETYPE]
- dec a
- jr z,.printText1
+ ld a,[wBattleType]
+ dec a ; is this the old man battle?
+ jr z,.oldManCaughtMon ; if so, don't give the player the caught Pokémon
+
ld hl,ItemUseBallText05
call PrintText
+
+; Add the caught Pokémon to the Pokédex.
predef IndexToPokedex
ld a,[wd11e]
dec a
ld c,a
- ld b,2
- ld hl,wPokedexOwned ;Dex_own_flags (pokemon)
+ ld b,FLAG_TEST
+ ld hl,wPokedexOwned
predef FlagActionPredef
ld a,c
push af
ld a,[wd11e]
dec a
ld c,a
- ld b,1
+ ld b,FLAG_SET
predef FlagActionPredef
pop af
- and a
- jr nz,.checkParty
+
+ and a ; was the Pokémon already in the Pokédex?
+ jr nz,.skipShowingPokedexData ; if so, don't show the Pokédex data
+
ld hl,ItemUseBallText06
call PrintText
call ClearSprites
- ld a,[wEnemyMonSpecies] ;caught mon_ID
+ ld a,[wEnemyMonSpecies]
ld [wd11e],a
predef ShowPokedexData
-.checkParty ;$58f4
+
+.skipShowingPokedexData
ld a,[wPartyCount]
- cp a,PARTY_LENGTH ;is party full?
+ cp a,PARTY_LENGTH ; is party full?
jr z,.sendToBox
- xor a
- ld [wcc49],a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
call ClearSprites
- call AddPartyMon ;add mon to Party
- jr .End
-.sendToBox ;$5907
+ call AddPartyMon
+ jr .done
+
+.sendToBox
call ClearSprites
call SendNewMonToBox
ld hl,ItemUseBallText07
- ld a,[wd7f1]
- bit 0,a ;already met Bill?
- jr nz,.sendToBox2
+ CheckEvent EVENT_MET_BILL
+ jr nz,.printTransferredToPCText
ld hl,ItemUseBallText08
-.sendToBox2 ;$591a
+.printTransferredToPCText
call PrintText
- jr .End
-.printText1 ;$591f
+ jr .done
+
+.oldManCaughtMon
ld hl,ItemUseBallText05
-.printText0 ;$5922
+
+.printMessage
call PrintText
call ClearSprites
-.End ;$5928
- ld a,[W_BATTLETYPE]
- and a
- ret nz
+
+.done
+ ld a,[wBattleType]
+ and a ; is this the old man battle?
+ ret nz ; if so, don't remove a ball from the bag
+
+; Remove a ball from the bag.
ld hl,wNumBagItems
inc a
- ld [wcf96],a
- jp RemoveItemFromInventory ;remove ITEM (XXX)
-ItemUseBallText00: ; d937 (3:5937)
+ ld [wItemQuantity],a
+ jp RemoveItemFromInventory
+
+ItemUseBallText00:
;"It dodged the thrown ball!"
;"This pokemon can't be caught"
TX_FAR _ItemUseBallText00
db "@"
-ItemUseBallText01: ; d93c (3:593c)
+ItemUseBallText01:
;"You missed the pokemon!"
TX_FAR _ItemUseBallText01
db "@"
-ItemUseBallText02: ; d941 (3:5941)
+ItemUseBallText02:
;"Darn! The pokemon broke free!"
TX_FAR _ItemUseBallText02
db "@"
-ItemUseBallText03: ; d946 (3:5946)
+ItemUseBallText03:
;"Aww! It appeared to be caught!"
TX_FAR _ItemUseBallText03
db "@"
-ItemUseBallText04: ; d94b (3:594b)
+ItemUseBallText04:
;"Shoot! It was so close too!"
TX_FAR _ItemUseBallText04
db "@"
-ItemUseBallText05: ; d950 (3:5950)
+ItemUseBallText05:
;"All right! {MonName} was caught!"
;play sound
TX_FAR _ItemUseBallText05
- db $12,$06
+ TX_SFX_CAUGHT_MON
+ TX_BLINK
db "@"
-ItemUseBallText07: ; d957 (3:5957)
+ItemUseBallText07:
;"X was transferred to Bill's PC"
TX_FAR _ItemUseBallText07
db "@"
-ItemUseBallText08: ; d95c (3:595c)
+ItemUseBallText08:
;"X was transferred to someone's PC"
TX_FAR _ItemUseBallText08
db "@"
-ItemUseBallText06: ; d961 (3:5961)
+ItemUseBallText06:
;"New DEX data will be added..."
;play sound
TX_FAR _ItemUseBallText06
- db $13,$06
+ TX_SFX_DEX_PAGE_ADDED
+ TX_BLINK
db "@"
-ItemUseTownMap: ; d968 (3:5968)
- ld a,[W_ISINBATTLE]
+ItemUseTownMap:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
- ld b, BANK(DisplayTownMap)
- ld hl, DisplayTownMap
- jp Bankswitch ; display Town Map
+ jpba DisplayTownMap
-ItemUseBicycle: ; d977 (3:5977)
- ld a,[W_ISINBATTLE]
+ItemUseBicycle:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
ld a,[wWalkBikeSurfState]
@@ -534,7 +665,7 @@ ItemUseBicycle: ; d977 (3:5977)
jp PrintText
; used for Surf out-of-battle effect
-ItemUseSurfboard: ; d9b4 (3:59b4)
+ItemUseSurfboard:
ld a,[wWalkBikeSurfState]
ld [wWalkBikeSurfStateCopy],a
cp a,2 ; is the player already surfing?
@@ -556,17 +687,17 @@ ItemUseSurfboard: ; d9b4 (3:59b4)
jp PrintText
.tryToStopSurfing
xor a
- ld [$ff8c],a
+ ld [hSpriteIndexOrTextID],a
ld d,16 ; talking range in pixels (normal range)
call IsSpriteInFrontOfPlayer2
res 7,[hl]
- ld a,[$ff8c]
+ ld a,[hSpriteIndexOrTextID]
and a ; is there a sprite in the way?
jr nz,.cannotStopSurfing
ld hl,TilePairCollisionsWater
call CheckForTilePairCollisions
jr c,.cannotStopSurfing
- ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles
+ ld hl,wTilesetCollisionPtr ; pointer to list of passable tiles
ld a,[hli]
ld h,[hl]
ld l,a ; hl now points to passable tiles
@@ -593,14 +724,14 @@ ItemUseSurfboard: ; d9b4 (3:59b4)
jp LoadWalkingPlayerSpriteGraphics
; uses a simulated button press to make the player move forward
.makePlayerMoveForward
- ld a,[wd52a] ; direction the player is going
- bit 3,a
+ ld a,[wPlayerDirection] ; direction the player is going
+ bit PLAYER_DIR_BIT_UP,a
ld b,D_UP
jr nz,.storeSimulatedButtonPress
- bit 2,a
+ bit PLAYER_DIR_BIT_DOWN,a
ld b,D_DOWN
jr nz,.storeSimulatedButtonPress
- bit 1,a
+ bit PLAYER_DIR_BIT_LEFT,a
ld b,D_LEFT
jr nz,.storeSimulatedButtonPress
ld b,D_RIGHT
@@ -613,28 +744,28 @@ ItemUseSurfboard: ; d9b4 (3:59b4)
ld [wSimulatedJoypadStatesIndex],a
ret
-SurfingGotOnText: ; da4c (3:5a4c)
+SurfingGotOnText:
TX_FAR _SurfingGotOnText
db "@"
-SurfingNoPlaceToGetOffText: ; da51 (3:5a51)
+SurfingNoPlaceToGetOffText:
TX_FAR _SurfingNoPlaceToGetOffText
db "@"
-ItemUsePokedex: ; da56 (3:5a56)
+ItemUsePokedex:
predef_jump ShowPokedexMenu
-ItemUseEvoStone: ; da5b (3:5a5b)
- ld a,[W_ISINBATTLE]
+ItemUseEvoStone:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
ld a,[wWhichPokemon]
push af
ld a,[wcf91]
- ld [wd156],a
+ ld [wEvoStoneItemID],a
push af
- ld a,$05 ; evolution stone party menu
- ld [wd07d],a
+ ld a,EVO_STONE_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
ld a,$ff
ld [wUpdateSpritesEnabled],a
call DisplayPartyMenu
@@ -643,34 +774,34 @@ ItemUseEvoStone: ; da5b (3:5a5b)
ld a,b
ld [wcf91],a
ld a,$01
- ld [wccd4],a
- ld a,(SFX_02_3e - SFX_Headers_02) / 3
- call PlaySoundWaitForCurrent ; play sound
- call WaitForSoundToFinish ; wait for sound to end
+ ld [wForceEvolution],a
+ ld a,SFX_HEAL_AILMENT
+ call PlaySoundWaitForCurrent
+ call WaitForSoundToFinish
callab TryEvolvingMon ; try to evolve pokemon
- ld a,[wd121]
+ ld a,[wEvolutionOccurred]
and a
jr z,.noEffect
pop af
ld [wWhichPokemon],a
ld hl,wNumBagItems
ld a,1 ; remove 1 stone
- ld [wcf96],a
+ ld [wItemQuantity],a
jp RemoveItemFromInventory
.noEffect
call ItemUseNoEffect
.canceledItemUse
xor a
- ld [wcd6a],a
+ ld [wActionResultOrTookBattleTurn],a ; item not used
pop af
ret
-ItemUseVitamin: ; dab4 (3:5ab4)
- ld a,[W_ISINBATTLE]
+ItemUseVitamin:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
-ItemUseMedicine: ; dabb (3:5abb)
+ItemUseMedicine:
ld a,[wPartyCount]
and a
jp z,.emptyParty
@@ -678,11 +809,11 @@ ItemUseMedicine: ; dabb (3:5abb)
push af
ld a,[wcf91]
push af
- ld a,$01
- ld [wd07d],a ; item use party menu
+ ld a,USE_ITEM_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
ld a,$ff
ld [wUpdateSpritesEnabled],a
- ld a,[wd152]
+ ld a,[wPseudoItemID]
and a ; using Softboiled?
jr z,.notUsingSoftboiled
; if using softboiled
@@ -691,7 +822,7 @@ ItemUseMedicine: ; dabb (3:5abb)
.emptyParty
ld hl,.emptyPartyText
xor a
- ld [wcd6a],a ; item use failed
+ ld [wActionResultOrTookBattleTurn],a ; item use failed
jp PrintText
.emptyPartyText
text "You don't have"
@@ -706,7 +837,7 @@ ItemUseMedicine: ; dabb (3:5abb)
ld a,[wWhichPokemon]
call AddNTimes
ld a,[wWhichPokemon]
- ld [wcf06],a
+ ld [wUsedItemOnWhichPokemon],a
ld d,a
ld a,[wcf91]
ld e,a
@@ -715,7 +846,7 @@ ItemUseMedicine: ; dabb (3:5abb)
ld [wcf91],a
pop af
ld [wWhichPokemon],a
- ld a,[wd152]
+ ld a,[wPseudoItemID]
and a ; using Softboiled?
jr z,.checkItemType
; if using softboiled
@@ -734,25 +865,25 @@ ItemUseMedicine: ; dabb (3:5abb)
jr nc,.healHP ; if it's a Full Restore or one of the potions
; fall through if it's one of the status-specifc healing items
.cureStatusAilment
- ld bc,4
+ ld bc,wPartyMon1Status - wPartyMon1
add hl,bc ; hl now points to status
ld a,[wcf91]
- ld bc,$f008
+ lb bc, ANTIDOTE_MSG, 1 << PSN
cp a,ANTIDOTE
jr z,.checkMonStatus
- ld bc,$f110
+ lb bc, BURN_HEAL_MSG, 1 << BRN
cp a,BURN_HEAL
jr z,.checkMonStatus
- ld bc,$f220
+ lb bc, ICE_HEAL_MSG, 1 << FRZ
cp a,ICE_HEAL
jr z,.checkMonStatus
- ld bc,$f307
+ lb bc, AWAKENING_MSG, SLP
cp a,AWAKENING
jr z,.checkMonStatus
- ld bc,$f440
+ lb bc, PARALYZ_HEAL_MSG, 1 << PAR
cp a,PARLYZ_HEAL
jr z,.checkMonStatus
- ld bc,$f6ff ; Full Heal
+ lb bc, FULL_HEAL_MSG, $ff ; Full Heal
.checkMonStatus
ld a,[hl] ; pokemon's status
and c ; does the pokemon have a status ailment the item can cure?
@@ -761,7 +892,7 @@ ItemUseMedicine: ; dabb (3:5abb)
xor a
ld [hl],a ; remove the status ailment in the party data
ld a,b
- ld [wd07d],a ; the message to display for the item used
+ ld [wPartyMenuTypeOrMessageID],a ; the message to display for the item used
ld a,[wPlayerMonNumber]
cp d ; is pokemon the item was used on active in battle?
jp nz,.doneHealing
@@ -769,13 +900,13 @@ ItemUseMedicine: ; dabb (3:5abb)
xor a
ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data
push hl
- ld hl,W_PLAYERBATTSTATUS3
+ ld hl,wPlayerBattleStatus3
res BadlyPoisoned,[hl] ; heal Toxic status
pop hl
- ld bc,30
+ ld bc,wPartyMon1Stats - wPartyMon1Status
add hl,bc ; hl now points to party stats
- ld de,wBattleMonMaxHP
- ld bc,10
+ ld de,wBattleMonStats
+ ld bc,NUM_STATS * 2
call CopyData ; copy party stats to in-battle stat data
predef DoubleOrHalveSelectedStats
jp .doneHealing
@@ -797,24 +928,24 @@ ItemUseMedicine: ; dabb (3:5abb)
jr z,.updateInBattleFaintedData
jp .healingItemNoEffect
.updateInBattleFaintedData
- ld a,[W_ISINBATTLE]
+ ld a,[wIsInBattle]
and a
jr z,.compareCurrentHPToMaxHP
push hl
push de
push bc
- ld a,[wcf06]
+ ld a,[wUsedItemOnWhichPokemon]
ld c,a
ld hl,wPartyFoughtCurrentEnemyFlags
- ld b,$02
+ ld b,FLAG_TEST
predef FlagActionPredef
ld a,c
and a
jr z,.next
- ld a,[wcf06]
+ ld a,[wUsedItemOnWhichPokemon]
ld c,a
ld hl,wPartyGainExpFlags
- ld b,$01
+ ld b,FLAG_SET
predef FlagActionPredef
.next
pop bc
@@ -830,7 +961,7 @@ ItemUseMedicine: ; dabb (3:5abb)
.compareCurrentHPToMaxHP
push hl
push bc
- ld bc,32
+ ld bc,wPartyMon1MaxHP - (wPartyMon1HP + 1)
add hl,bc ; hl now points to max HP
pop bc
ld a,[hli]
@@ -859,16 +990,16 @@ ItemUseMedicine: ; dabb (3:5abb)
.notFullHP ; if the pokemon's current HP doesn't equal its max HP
xor a
ld [wLowHealthAlarm],a ;disable low health alarm
- ld [wc02a],a
+ ld [wChannelSoundIDs + Ch4],a
push hl
push de
- ld bc,32
+ ld bc,wPartyMon1MaxHP - (wPartyMon1HP + 1)
add hl,bc ; hl now points to max HP
ld a,[hli]
ld [wHPBarMaxHP+1],a
ld a,[hl]
ld [wHPBarMaxHP],a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian)
- ld a,[wd152]
+ ld a,[wPseudoItemID]
and a ; using Softboiled?
jp z,.notUsingSoftboiled2
; if using softboiled
@@ -895,7 +1026,7 @@ ItemUseMedicine: ; dabb (3:5abb)
ld [H_DIVISOR],a
ld b,2 ; number of bytes
call Divide ; get 1/5 of max HP of pokemon that used Softboiled
- ld bc,wPartyMon1HP - wPartyMon1MaxHP
+ ld bc,(wPartyMon1HP + 1) - (wPartyMon1MaxHP + 1)
add hl,bc ; hl now points to LSB of current HP of pokemon that used Softboiled
; subtract 1/5 of max HP from current HP of pokemon that used Softboiled
ld a,[H_QUOTIENT + 3]
@@ -913,12 +1044,12 @@ ItemUseMedicine: ; dabb (3:5abb)
sbc b
ld [hl],a
ld [wHPBarNewHP+1],a
- hlCoord 4, 1
+ coord hl, 4, 1
ld a,[wWhichPokemon]
- ld bc,2 * 20
+ ld bc,2 * SCREEN_WIDTH
call AddNTimes ; calculate coordinates of HP bar of pokemon that used Softboiled
- ld a,(SFX_02_3d - SFX_Headers_02) / 3
- call PlaySoundWaitForCurrent ; play sound
+ ld a,SFX_HEAL_HP
+ call PlaySoundWaitForCurrent
ld a,[hFlags_0xFFF6]
set 0,a
ld [hFlags_0xFFF6],a
@@ -974,7 +1105,7 @@ ItemUseMedicine: ; dabb (3:5abb)
inc hl
ld d,h
ld e,l ; de now points to current HP
- ld hl,33
+ ld hl,(wPartyMon1MaxHP + 1) - (wPartyMon1HP + 1)
add hl,de ; hl now points to max HP
ld a,[wcf91]
cp a,REVIVE
@@ -1021,7 +1152,7 @@ ItemUseMedicine: ; dabb (3:5abb)
ld a,[wcf91]
cp a,FULL_RESTORE
jr nz,.updateInBattleData
- ld bc,-31
+ ld bc,wPartyMon1Status - (wPartyMon1MaxHP + 1)
add hl,bc
xor a
ld [hl],a ; remove the status ailment in the party data
@@ -1044,7 +1175,7 @@ ItemUseMedicine: ; dabb (3:5abb)
ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data
.calculateHPBarCoords
ld hl,wOAMBuffer + $90
- ld bc,2 * 20
+ ld bc,2 * SCREEN_WIDTH
inc d
.calculateHPBarCoordsLoop
add hl,bc
@@ -1055,7 +1186,7 @@ ItemUseMedicine: ; dabb (3:5abb)
call ItemUseNoEffect
jp .done
.doneHealing
- ld a,[wd152]
+ ld a,[wPseudoItemID]
and a ; using Softboiled?
jr nz,.skipRemovingItem ; no item to remove if using Softboiled
push hl
@@ -1067,8 +1198,8 @@ ItemUseMedicine: ; dabb (3:5abb)
jr c,.playStatusAilmentCuringSound
cp a,FULL_HEAL
jr z,.playStatusAilmentCuringSound
- ld a,(SFX_02_3d - SFX_Headers_02) / 3 ; HP healing sound
- call PlaySoundWaitForCurrent ; play sound
+ ld a,SFX_HEAL_HP
+ call PlaySoundWaitForCurrent
ld a,[hFlags_0xFFF6]
set 0,a
ld [hFlags_0xFFF6],a
@@ -1078,18 +1209,18 @@ ItemUseMedicine: ; dabb (3:5abb)
ld a,[hFlags_0xFFF6]
res 0,a
ld [hFlags_0xFFF6],a
- ld a,$f7 ; revived message
- ld [wd07d],a
+ ld a,REVIVE_MSG
+ ld [wPartyMenuTypeOrMessageID],a
ld a,[wcf91]
cp a,REVIVE
jr z,.showHealingItemMessage
cp a,MAX_REVIVE
jr z,.showHealingItemMessage
- ld a,$f5 ; standard HP healed message
- ld [wd07d],a
+ ld a,POTION_MSG
+ ld [wPartyMenuTypeOrMessageID],a
jr .showHealingItemMessage
.playStatusAilmentCuringSound
- ld a,(SFX_02_3e - SFX_Headers_02) / 3 ; status ailment curing sound
+ ld a,SFX_HEAL_AILMENT
call PlaySoundWaitForCurrent
.showHealingItemMessage
xor a
@@ -1106,16 +1237,16 @@ ItemUseMedicine: ; dabb (3:5abb)
jr .done
.canceledItemUse
xor a
- ld [wcd6a],a ; item use failed
+ ld [wActionResultOrTookBattleTurn],a ; item use failed
pop af
pop af
.done
- ld a,[wd152]
+ ld a,[wPseudoItemID]
and a ; using Softboiled?
ret nz ; if so, return
call GBPalWhiteOut
- call z,GoPAL_SET_CF1C
- ld a,[W_ISINBATTLE]
+ call z,RunDefaultPaletteCommand
+ ld a,[wIsInBattle]
and a
ret nz
jp ReloadMapData
@@ -1124,10 +1255,10 @@ ItemUseMedicine: ; dabb (3:5abb)
ld a,[hl]
ld [wd0b5],a
ld [wd11e],a
- ld bc,33
+ ld bc,wPartyMon1Level - wPartyMon1
add hl,bc ; hl now points to level
ld a,[hl] ; a = level
- ld [W_CURENEMYLVL],a ; store level
+ ld [wCurEnemyLVL],a ; store level
call GetMonHeader
push de
ld a,d
@@ -1141,7 +1272,7 @@ ItemUseMedicine: ; dabb (3:5abb)
push hl
sub a,HP_UP
add a
- ld bc,17
+ ld bc,wPartyMon1HPExp - wPartyMon1
add hl,bc
add l
ld l,a
@@ -1178,8 +1309,8 @@ ItemUseMedicine: ; dabb (3:5abb)
ld de,wcf4b
ld bc,10
call CopyData ; copy the stat's name to wcf4b
- ld a,(SFX_02_3e - SFX_Headers_02) / 3
- call PlaySound ; play sound
+ ld a,SFX_HEAL_AILMENT
+ call PlaySound
ld hl,VitaminStatRoseText
call PrintText
jp RemoveUsedItem
@@ -1189,38 +1320,38 @@ ItemUseMedicine: ; dabb (3:5abb)
call PrintText
jp GBPalWhiteOut
.recalculateStats
- ld bc,34
+ ld bc,wPartyMon1Stats - wPartyMon1
add hl,bc
ld d,h
ld e,l ; de now points to stats
- ld bc,-18
- add hl,bc ; hl now points to byte 3 of experience
+ ld bc,(wPartyMon1Exp + 2) - wPartyMon1Stats
+ add hl,bc ; hl now points to LSB of experience
ld b,1
jp CalcStats ; recalculate stats
.useRareCandy
push hl
- ld bc,33
+ ld bc,wPartyMon1Level - wPartyMon1
add hl,bc ; hl now points to level
ld a,[hl] ; a = level
cp a, MAX_LEVEL
jr z,.vitaminNoEffect ; can't raise level above 100
inc a
ld [hl],a ; store incremented level
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
push hl
push de
ld d,a
callab CalcExperience ; calculate experience for next level and store it at $ff96
pop de
pop hl
- ld bc,-19
- add hl,bc ; hl now points to experience
+ ld bc,wPartyMon1Exp - wPartyMon1Level
+ add hl,bc ; hl now points to MSB of experience
; update experience to minimum for new level
- ld a,[$ff96]
+ ld a,[hExperience]
ld [hli],a
- ld a,[$ff97]
+ ld a,[hExperience + 1]
ld [hli],a
- ld a,[$ff98]
+ ld a,[hExperience + 2]
ld [hl],a
pop hl
ld a,[wWhichPokemon]
@@ -1229,7 +1360,7 @@ ItemUseMedicine: ; dabb (3:5abb)
push af
push de
push hl
- ld bc,34
+ ld bc,wPartyMon1MaxHP - wPartyMon1
add hl,bc ; hl now points to MSB of max HP
ld a,[hli]
ld b,a
@@ -1239,8 +1370,8 @@ ItemUseMedicine: ; dabb (3:5abb)
push hl
call .recalculateStats
pop hl
- ld bc,35 ; hl now points to LSB of max HP
- add hl,bc
+ ld bc,(wPartyMon1MaxHP + 1) - wPartyMon1
+ add hl,bc ; hl now points to LSB of max HP
pop bc
ld a,[hld]
sub c
@@ -1249,33 +1380,33 @@ ItemUseMedicine: ; dabb (3:5abb)
sbc b
ld b,a ; bc = the amount of max HP gained from leveling up
; add the amount gained to the current HP
- ld de,-32
- add hl,de ; hl now points to MSB of current HP
+ ld de,(wPartyMon1HP + 1) - wPartyMon1MaxHP
+ add hl,de ; hl now points to LSB of current HP
ld a,[hl]
add c
ld [hld],a
ld a,[hl]
adc b
ld [hl],a
- ld a,$f8 ; level up message
- ld [wd07d],a
+ ld a,RARE_CANDY_MSG
+ ld [wPartyMenuTypeOrMessageID],a
call RedrawPartyMenu
pop de
ld a,d
ld [wWhichPokemon],a
ld a,e
ld [wd11e],a
- xor a
- ld [wcc49],a ; load from player's party
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
call LoadMonData
ld d,$01
callab PrintStatsBox ; display new stats text box
call WaitForTextScrollButtonPress ; wait for button press
- xor a
- ld [wcc49],a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
predef LearnMoveFromLevelUp ; learn level up move, if any
xor a
- ld [wccd4],a
+ ld [wForceEvolution],a
callab TryEvolvingMon ; evolve pokemon, if appropriate
ld a,$01
ld [wUpdateSpritesEnabled],a
@@ -1285,22 +1416,22 @@ ItemUseMedicine: ; dabb (3:5abb)
ld [wWhichPokemon],a
jp RemoveUsedItem
-VitaminStatRoseText: ; df24 (3:5f24)
+VitaminStatRoseText:
TX_FAR _VitaminStatRoseText
db "@"
-VitaminNoEffectText: ; df29 (3:5f29)
+VitaminNoEffectText:
TX_FAR _VitaminNoEffectText
db "@"
-VitaminText: ; df2e (3:5f2e)
+VitaminText:
db "HEALTH@"
db "ATTACK@"
db "DEFENSE@"
db "SPEED@"
db "SPECIAL@"
-ItemUseBait: ; df52 (3:5f52)
+ItemUseBait:
ld hl,ThrewBaitText
call PrintText
ld hl,wEnemyMonCatchRate ; catch rate
@@ -1310,7 +1441,7 @@ ItemUseBait: ; df52 (3:5f52)
ld de,wSafariEscapeFactor ; escape factor
jr BaitRockCommon
-ItemUseRock: ; df67 (3:5f67)
+ItemUseRock:
ld hl,ThrewRockText
call PrintText
ld hl,wEnemyMonCatchRate ; catch rate
@@ -1324,10 +1455,10 @@ ItemUseRock: ; df67 (3:5f67)
ld hl,wSafariEscapeFactor ; escape factor
ld de,wSafariBaitFactor ; bait factor
-BaitRockCommon: ; df7f (3:5f7f)
- ld [W_ANIMATIONID],a
+BaitRockCommon:
+ ld [wAnimationID],a
xor a
- ld [wcc5b],a
+ ld [wAnimationType],a
ld [H_WHOSETURN],a
ld [de],a ; zero escape factor (for bait), zero bait factor (for rock)
.randomLoop ; loop until a random number less than 5 is generated
@@ -1347,23 +1478,23 @@ BaitRockCommon: ; df7f (3:5f7f)
ld c,70
jp DelayFrames
-ThrewBaitText: ; dfa5 (3:5fa5)
+ThrewBaitText:
TX_FAR _ThrewBaitText
db "@"
-ThrewRockText: ; dfaa (3:5faa)
+ThrewRockText:
TX_FAR _ThrewRockText
db "@"
; also used for Dig out-of-battle effect
-ItemUseEscapeRope: ; dfaf (3:5faf)
- ld a,[W_ISINBATTLE]
+ItemUseEscapeRope:
+ ld a,[wIsInBattle]
and a
jr nz,.notUsable
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
cp a,AGATHAS_ROOM
jr z,.notUsable
- ld a,[W_CURMAPTILESET]
+ ld a,[wCurMapTileset]
ld b,a
ld hl,EscapeRopeTilesets
.loop
@@ -1377,15 +1508,14 @@ ItemUseEscapeRope: ; dfaf (3:5faf)
set 6,[hl]
ld hl,wd72e
res 4,[hl]
- ld hl,wd790
- res 7,[hl] ; unset Safari Zone bit
+ ResetEvent EVENT_IN_SAFARI_ZONE
xor a
- ld [W_NUMSAFARIBALLS],a
- ld [W_SAFARIZONEENTRANCECURSCRIPT],a
+ ld [wNumSafariBalls],a
+ ld [wSafariZoneEntranceCurScript],a
inc a
ld [wEscapedFromBattle],a
- ld [wcd6a],a ; item used
- ld a,[wd152]
+ ld [wActionResultOrTookBattleTurn],a ; item used
+ ld a,[wPseudoItemID]
and a ; using Dig?
ret nz ; if so, return
call ItemUseReloadOverworldData
@@ -1395,15 +1525,15 @@ ItemUseEscapeRope: ; dfaf (3:5faf)
.notUsable
jp ItemUseNotTime
-EscapeRopeTilesets: ; dffd (3:5ffd)
+EscapeRopeTilesets:
db FOREST, CEMETERY, CAVERN, FACILITY, INTERIOR
db $ff ; terminator
-ItemUseRepel: ; e003 (3:6003)
+ItemUseRepel:
ld b,100
-ItemUseRepelCommon: ; e005 (3:6005)
- ld a,[W_ISINBATTLE]
+ItemUseRepelCommon:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
ld a,b
@@ -1411,21 +1541,21 @@ ItemUseRepelCommon: ; e005 (3:6005)
jp PrintItemUseTextAndRemoveItem
; handles X Accuracy item
-ItemUseXAccuracy: ; e013 (3:6013)
- ld a,[W_ISINBATTLE]
+ItemUseXAccuracy:
+ ld a,[wIsInBattle]
and a
jp z,ItemUseNotTime
- ld hl,W_PLAYERBATTSTATUS2
+ ld hl,wPlayerBattleStatus2
set UsingXAccuracy,[hl] ; X Accuracy bit
jp PrintItemUseTextAndRemoveItem
; This function is bugged and never works. It always jumps to ItemUseNotTime.
; The Card Key is handled in a different way.
-ItemUseCardKey: ; e022 (3:6022)
+ItemUseCardKey:
xor a
- ld [wd71f],a
+ ld [wUnusedD71F],a
call GetTileAndCoordsInFrontOfPlayer
- ld a,[GetTileAndCoordsInFrontOfPlayer] ; $4586
+ ld a,[GetTileAndCoordsInFrontOfPlayer]
cp a,$18
jr nz,.next0
ld hl,CardKeyTable1
@@ -1440,7 +1570,7 @@ ItemUseCardKey: ; e022 (3:6022)
jp nz,ItemUseNotTime
ld hl,CardKeyTable3
.next1
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
ld b,a
.loop
ld a,[hli]
@@ -1455,7 +1585,7 @@ ItemUseCardKey: ; e022 (3:6022)
cp e
jr nz,.nextEntry3
ld a,[hl]
- ld [wd71f],a
+ ld [wUnusedD71F],a
jr .done
.nextEntry1
inc hl
@@ -1481,7 +1611,7 @@ ItemUseCardKey: ; e022 (3:6022)
; 02: X
; 03: ID?
-CardKeyTable1: ; e072 (3:6072)
+CardKeyTable1:
db SILPH_CO_2F,$04,$04,$00
db SILPH_CO_2F,$04,$05,$01
db SILPH_CO_4F,$0C,$04,$02
@@ -1494,7 +1624,7 @@ CardKeyTable1: ; e072 (3:6072)
db SILPH_CO_10F,$08,$0B,$09
db $ff
-CardKeyTable2: ; e09b (3:609b)
+CardKeyTable2:
db SILPH_CO_3F,$08,$09,$0A
db SILPH_CO_3F,$09,$09,$0B
db SILPH_CO_5F,$04,$07,$0C
@@ -1507,64 +1637,64 @@ CardKeyTable2: ; e09b (3:609b)
db SILPH_CO_9F,$09,$03,$13
db $ff
-CardKeyTable3: ; e0c4 (3:60c4)
+CardKeyTable3:
db SILPH_CO_11F,$08,$09,$14
db SILPH_CO_11F,$09,$09,$15
db $ff
-ItemUsePokedoll: ; e0cd (3:60cd)
- ld a,[W_ISINBATTLE]
+ItemUsePokedoll:
+ ld a,[wIsInBattle]
dec a
jp nz,ItemUseNotTime
ld a,$01
ld [wEscapedFromBattle],a
jp PrintItemUseTextAndRemoveItem
-ItemUseGuardSpec: ; e0dc (3:60dc)
- ld a,[W_ISINBATTLE]
+ItemUseGuardSpec:
+ ld a,[wIsInBattle]
and a
jp z,ItemUseNotTime
- ld hl,W_PLAYERBATTSTATUS2
+ ld hl,wPlayerBattleStatus2
set ProtectedByMist,[hl] ; Mist bit
jp PrintItemUseTextAndRemoveItem
-ItemUseSuperRepel: ; e0eb (3:60eb)
+ItemUseSuperRepel:
ld b,200
jp ItemUseRepelCommon
-ItemUseMaxRepel: ; e0f0 (3:60f0)
+ItemUseMaxRepel:
ld b,250
jp ItemUseRepelCommon
-ItemUseDireHit: ; e0f5 (3:60f5)
- ld a,[W_ISINBATTLE]
+ItemUseDireHit:
+ ld a,[wIsInBattle]
and a
jp z,ItemUseNotTime
- ld hl,W_PLAYERBATTSTATUS2
+ ld hl,wPlayerBattleStatus2
set GettingPumped,[hl] ; Focus Energy bit
jp PrintItemUseTextAndRemoveItem
-ItemUseXStat: ; e104 (3:6104)
- ld a,[W_ISINBATTLE]
+ItemUseXStat:
+ ld a,[wIsInBattle]
and a
jr nz,.inBattle
call ItemUseNotTime
ld a,2
- ld [wcd6a],a ; item not used
+ ld [wActionResultOrTookBattleTurn],a ; item not used
ret
.inBattle
- ld hl,W_PLAYERMOVENUM
+ ld hl,wPlayerMoveNum
ld a,[hli]
- push af ; save [W_PLAYERMOVENUM]
+ push af ; save [wPlayerMoveNum]
ld a,[hl]
- push af ; save [W_PLAYERMOVEEFFECT]
+ push af ; save [wPlayerMoveEffect]
push hl
ld a,[wcf91]
sub a,X_ATTACK - ATTACK_UP1_EFFECT
ld [hl],a ; store player move effect
call PrintItemUseTextAndRemoveItem
ld a,XSTATITEM_ANIM ; X stat item animation ID
- ld [W_PLAYERMOVENUM],a
+ ld [wPlayerMoveNum],a
call LoadScreenTilesFromBuffer1 ; restore saved screen
call Delay3
xor a
@@ -1572,22 +1702,21 @@ ItemUseXStat: ; e104 (3:6104)
callba StatModifierUpEffect ; do stat increase move
pop hl
pop af
- ld [hld],a ; restore [W_PLAYERMOVEEFFECT]
+ ld [hld],a ; restore [wPlayerMoveEffect]
pop af
- ld [hl],a ; restore [W_PLAYERMOVENUM]
+ ld [hl],a ; restore [wPlayerMoveNum]
ret
-ItemUsePokeflute: ; e140 (3:6140)
- ld a,[W_ISINBATTLE]
+ItemUsePokeflute:
+ ld a,[wIsInBattle]
and a
jr nz,.inBattle
; if not in battle
call ItemUseReloadOverworldData
- ld a,[W_CURMAP]
+ ld a,[wCurMap]
cp a,ROUTE_12
jr nz,.notRoute12
- ld a,[wd7d8]
- bit 7,a ; has the player beaten Route 12 Snorlax yet?
+ CheckEvent EVENT_BEAT_ROUTE12_SNORLAX
jr nz,.noSnorlaxToWakeUp
; if the player hasn't beaten Route 12 Snorlax
ld hl,Route12SnorlaxFluteCoords
@@ -1595,14 +1724,12 @@ ItemUsePokeflute: ; e140 (3:6140)
jr nc,.noSnorlaxToWakeUp
ld hl,PlayedFluteHadEffectText
call PrintText
- ld hl,wd7d8
- set 6,[hl] ; trigger Snorlax fight (handled by map script)
+ SetEvent EVENT_FIGHT_ROUTE12_SNORLAX
ret
.notRoute12
cp a,ROUTE_16
jr nz,.noSnorlaxToWakeUp
- ld a,[wd7e0]
- bit 1,a ; has the player beaten Route 16 Snorlax yet?
+ CheckEvent EVENT_BEAT_ROUTE16_SNORLAX
jr nz,.noSnorlaxToWakeUp
; if the player hasn't beaten Route 16 Snorlax
ld hl,Route16SnorlaxFluteCoords
@@ -1610,19 +1737,18 @@ ItemUsePokeflute: ; e140 (3:6140)
jr nc,.noSnorlaxToWakeUp
ld hl,PlayedFluteHadEffectText
call PrintText
- ld hl,wd7e0
- set 0,[hl] ; trigger Snorlax fight (handled by map script)
+ SetEvent EVENT_FIGHT_ROUTE16_SNORLAX
ret
.noSnorlaxToWakeUp
ld hl,PlayedFluteNoEffectText
jp PrintText
.inBattle
xor a
- ld [wWhichTrade],a ; initialize variable that indicates if any pokemon were woken up to zero
- ld b,~SLP & $FF
+ ld [wWereAnyMonsAsleep],a
+ ld b,~SLP & $ff
ld hl,wPartyMon1Status
call WakeUpEntireParty
- ld a,[W_ISINBATTLE]
+ ld a,[wIsInBattle]
dec a ; is it a trainer battle?
jr z,.skipWakingUpEnemyParty
; if it's a trainer battle
@@ -1638,7 +1764,7 @@ ItemUsePokeflute: ; e140 (3:6140)
and b ; remove Sleep status
ld [hl],a
call LoadScreenTilesFromBuffer2 ; restore saved screen
- ld a,[wWhichTrade]
+ ld a,[wWereAnyMonsAsleep]
and a ; were any pokemon asleep before playing the flute?
ld hl,PlayedFluteNoEffectText
jp z,PrintText ; if no pokemon were asleep
@@ -1651,7 +1777,7 @@ ItemUsePokeflute: ; e140 (3:6140)
call WaitForSoundToFinish ; wait for sound to end
callba Music_PokeFluteInBattle ; play in-battle pokeflute music
.musicWaitLoop ; wait for music to finish playing
- ld a,[wc02c]
+ ld a,[wChannelSoundIDs + Ch6]
and a ; music off?
jr nz,.musicWaitLoop
.skipMusic
@@ -1662,10 +1788,10 @@ ItemUsePokeflute: ; e140 (3:6140)
; INPUT:
; hl must point to status of first pokemon in party (player's or enemy's)
; b must equal ~SLP
-; [wWhichTrade] should be initialized to 0
+; [wWereAnyMonsAsleep] should be initialized to 0
; OUTPUT:
-; [wWhichTrade]: set to 1 if any pokemon were asleep
-WakeUpEntireParty: ; e1e5 (3:61e5)
+; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep
+WakeUpEntireParty:
ld de,44
ld c,6
.loop
@@ -1674,7 +1800,7 @@ WakeUpEntireParty: ; e1e5 (3:61e5)
and a,SLP ; is pokemon asleep?
jr z,.notAsleep
ld a,1
- ld [wWhichTrade],a ; indicate that a pokemon had to be woken up
+ ld [wWereAnyMonsAsleep],a ; indicate that a pokemon had to be woken up
.notAsleep
pop af
and b ; remove Sleep status
@@ -1687,7 +1813,7 @@ WakeUpEntireParty: ; e1e5 (3:61e5)
; Format:
; 00: Y
; 01: X
-Route12SnorlaxFluteCoords: ; e1fd (3:61fd)
+Route12SnorlaxFluteCoords:
db 62,9 ; one space West of Snorlax
db 61,10 ; one space North of Snorlax
db 63,10 ; one space South of Snorlax
@@ -1697,59 +1823,59 @@ Route12SnorlaxFluteCoords: ; e1fd (3:61fd)
; Format:
; 00: Y
; 01: X
-Route16SnorlaxFluteCoords: ; e206 (3:6206)
+Route16SnorlaxFluteCoords:
db 10,27 ; one space East of Snorlax
db 10,25 ; one space West of Snorlax
db $ff ; terminator
-PlayedFluteNoEffectText: ; e20b (3:620b)
+PlayedFluteNoEffectText:
TX_FAR _PlayedFluteNoEffectText
db "@"
-FluteWokeUpText: ; e210 (3:6210)
+FluteWokeUpText:
TX_FAR _FluteWokeUpText
db "@"
-PlayedFluteHadEffectText: ; e215 (3:6215)
+PlayedFluteHadEffectText:
TX_FAR _PlayedFluteHadEffectText
- db $06
- db $08
- ld a,[W_ISINBATTLE]
+ TX_BLINK
+ TX_ASM
+ ld a,[wIsInBattle]
and a
jr nz,.done
; play out-of-battle pokeflute music
ld a,$ff
call PlaySound ; turn off music
- ld a, (SFX_02_5e - SFX_Headers_02) / 3
- ld c, BANK(SFX_02_5e)
- call PlayMusic ; play music
+ ld a, SFX_POKEFLUE
+ ld c, BANK(SFX_Pokeflute)
+ call PlayMusic
.musicWaitLoop ; wait for music to finish playing
- ld a,[wc028]
- cp a,$b8
+ ld a,[wChannelSoundIDs + Ch2]
+ cp a, SFX_POKEFLUE
jr z,.musicWaitLoop
call PlayDefaultMusic ; start playing normal music again
.done
jp TextScriptEnd ; end text
-ItemUseCoinCase: ; e23a (3:623a)
- ld a,[W_ISINBATTLE]
+ItemUseCoinCase:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
ld hl,CoinCaseNumCoinsText
jp PrintText
-CoinCaseNumCoinsText: ; e247 (3:6247)
+CoinCaseNumCoinsText:
TX_FAR _CoinCaseNumCoinsText
db "@"
-OldRodCode: ; e24c (3:624c)
+ItemUseOldRod:
call FishingInit
jp c, ItemUseNotTime
- ld bc, (5 << 8) | MAGIKARP
+ lb bc, 5, MAGIKARP
ld a, $1 ; set bite
- jr RodResponse ; 0xe257 $34
+ jr RodResponse
-GoodRodCode: ; e259 (3:6259)
+ItemUseGoodRod:
call FishingInit
jp c,ItemUseNotTime
.RandomLoop
@@ -1777,23 +1903,23 @@ GoodRodCode: ; e259 (3:6259)
INCLUDE "data/good_rod.asm"
-SuperRodCode: ; e283 (3:6283)
+ItemUseSuperRod:
call FishingInit
jp c, ItemUseNotTime
- call ReadSuperRodData ; 0xe8ea
+ call ReadSuperRodData
ld a, e
-RodResponse: ; e28d (3:628d)
- ld [wWhichTrade], a
+RodResponse:
+ ld [wRodResponse], a
dec a ; is there a bite?
jr nz, .next
; if yes, store level and species data
ld a, 1
- ld [W_MOVEMISSED], a
+ ld [wMoveMissed], a
ld a, b ; level
- ld [W_CURENEMYLVL], a
+ ld [wCurEnemyLVL], a
ld a, c ; species
- ld [W_CUROPPONENT], a
+ ld [wCurOpponent], a
.next
ld hl, wWalkBikeSurfState
@@ -1801,7 +1927,7 @@ RodResponse: ; e28d (3:628d)
push af
push hl
ld [hl], 0
- callba Func_707b6
+ callba FishingAnim
pop hl
pop af
ld [hl], a
@@ -1809,8 +1935,8 @@ RodResponse: ; e28d (3:628d)
; checks if fishing is possible and if so, runs initialization code common to all rods
; unsets carry if fishing is possible, sets carry if not
-FishingInit: ; e2b4 (3:62b4)
- ld a,[W_ISINBATTLE]
+FishingInit:
+ ld a,[wIsInBattle]
and a
jr z,.notInBattle
scf ; can't fish during battle
@@ -1824,8 +1950,8 @@ FishingInit: ; e2b4 (3:62b4)
call ItemUseReloadOverworldData
ld hl,ItemUseText00
call PrintText
- ld a,(SFX_02_3e - SFX_Headers_02) / 3
- call PlaySound ; play sound
+ ld a,SFX_HEAL_AILMENT
+ call PlaySound
ld c,80
call DelayFrames
and a
@@ -1834,11 +1960,11 @@ FishingInit: ; e2b4 (3:62b4)
scf ; can't fish when surfing
ret
-ItemUseOaksParcel: ; e2de (3:62de)
+ItemUseOaksParcel:
jp ItemUseNotYoursToUse
-ItemUseItemfinder: ; e2e1 (3:62e1)
- ld a,[W_ISINBATTLE]
+ItemUseItemfinder:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
call ItemUseReloadOverworldData
@@ -1847,50 +1973,50 @@ ItemUseItemfinder: ; e2e1 (3:62e1)
jr nc,.printText ; if no hidden items
ld c,4
.loop
- ld a,(SFX_02_4a - SFX_Headers_02) / 3
- call PlaySoundWaitForCurrent ; play sound
- ld a,(SFX_02_5a - SFX_Headers_02) / 3
- call PlaySoundWaitForCurrent ; play sound
+ ld a,SFX_HEALING_MACHINE
+ call PlaySoundWaitForCurrent
+ ld a,SFX_PURCHASE
+ call PlaySoundWaitForCurrent
dec c
jr nz,.loop
ld hl,ItemfinderFoundItemText
.printText
jp PrintText
-ItemfinderFoundItemText: ; e30d (3:630d)
+ItemfinderFoundItemText:
TX_FAR _ItemfinderFoundItemText
db "@"
-ItemfinderFoundNothingText: ; e312 (3:6312)
+ItemfinderFoundNothingText:
TX_FAR _ItemfinderFoundNothingText
db "@"
-ItemUsePPUp: ; e317 (3:6317)
- ld a,[W_ISINBATTLE]
+ItemUsePPUp:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
-ItemUsePPRestore: ; e31e (3:631e)
+ItemUsePPRestore:
ld a,[wWhichPokemon]
push af
ld a,[wcf91]
- ld [wWhichTrade],a
+ ld [wPPRestoreItem],a
.chooseMon
xor a
ld [wUpdateSpritesEnabled],a
- ld a,$01 ; item use party menu
- ld [wd07d],a
+ ld a,USE_ITEM_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
call DisplayPartyMenu
jr nc,.chooseMove
jp .itemNotUsed
.chooseMove
- ld a,[wWhichTrade]
+ ld a,[wPPRestoreItem]
cp a,ELIXER
jp nc,.useElixir ; if Elixir or Max Elixir
ld a,$02
ld [wMoveMenuType],a
ld hl,RaisePPWhichTechniqueText
- ld a,[wWhichTrade]
+ ld a,[wPPRestoreItem]
cp a,ETHER ; is it a PP Up?
jr c,.printWhichTechniqueMessage ; if so, print the raise PP message
ld hl,RestorePPWhichTechniqueText ; otherwise, print the restore PP message
@@ -1903,7 +2029,7 @@ ItemUsePPRestore: ; e31e (3:631e)
ld [wPlayerMoveListIndex],a
jr nz,.chooseMon
ld hl,wPartyMon1Moves
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
push hl
ld a,[hl]
@@ -1911,11 +2037,11 @@ ItemUsePPRestore: ; e31e (3:631e)
call GetMoveName
call CopyStringToCF4B ; copy name to wcf4b
pop hl
- ld a,[wWhichTrade]
+ ld a,[wPPRestoreItem]
cp a,ETHER
jr nc,.useEther ; if Ether or Max Ether
.usePPUp
- ld bc,21
+ ld bc,wPartyMon1PP - wPartyMon1Moves
add hl,bc
ld a,[hl] ; move PP
cp a,3 << 6 ; have 3 PP Ups already been used?
@@ -1936,7 +2062,7 @@ ItemUsePPRestore: ; e31e (3:631e)
pop af
ld [wWhichPokemon],a
call GBPalWhiteOut
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
jp RemoveUsedItem
.afterRestoringPP ; after using a (Max) Ether/Elixir
ld a,[wWhichPokemon]
@@ -1945,13 +2071,13 @@ ItemUsePPRestore: ; e31e (3:631e)
cp b ; is the pokemon whose PP was restored active in battle?
jr nz,.skipUpdatingInBattleData
ld hl,wPartyMon1PP
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
ld de,wBattleMonPP
ld bc,4
call CopyData ; copy party data to in-battle data
.skipUpdatingInBattleData
- ld a,(SFX_02_3e - SFX_Headers_02) / 3
+ ld a,SFX_HEAL_AILMENT
call PlaySound
ld hl,PPRestoredText
call PrintText
@@ -1963,17 +2089,17 @@ ItemUsePPRestore: ; e31e (3:631e)
; unsets zero flag if PP was restored, sets zero flag if not
; however, this is bugged for Max Ethers and Max Elixirs (see below)
.restorePP
- xor a
- ld [wcc49],a ; party pokemon
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
call GetMaxPP
ld hl,wPartyMon1Moves
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
- ld bc,21
+ ld bc, wPartyMon1PP - wPartyMon1Moves
add hl,bc ; hl now points to move's PP
- ld a,[wd11e]
- ld b,a ; b = max PP
- ld a,[wWhichTrade]
+ ld a,[wMaxPP]
+ ld b,a
+ ld a,[wPPRestoreItem]
cp a,MAX_ETHER
jr z,.fullyRestorePP
ld a,[hl] ; move PP
@@ -2005,7 +2131,7 @@ ItemUsePPRestore: ; e31e (3:631e)
jr .storeNewAmount
.useElixir
; decrement the item ID so that ELIXER becomes ETHER and MAX_ELIXER becomes MAX_ETHER
- ld hl,wWhichTrade
+ ld hl,wPPRestoreItem
dec [hl]
dec [hl]
xor a
@@ -2017,7 +2143,7 @@ ItemUsePPRestore: ; e31e (3:631e)
.elixirLoop
push bc
ld hl,wPartyMon1Moves
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
ld a,[hl]
and a ; does the current slot have a move?
@@ -2040,38 +2166,38 @@ ItemUsePPRestore: ; e31e (3:631e)
call ItemUseNoEffect
.itemNotUsed
call GBPalWhiteOut
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
pop af
xor a
- ld [wcd6a],a ; item use failed
+ ld [wActionResultOrTookBattleTurn],a ; item use failed
ret
-RaisePPWhichTechniqueText: ; e45d (3:645d)
+RaisePPWhichTechniqueText:
TX_FAR _RaisePPWhichTechniqueText
db "@"
-RestorePPWhichTechniqueText: ; e462 (3:6462)
+RestorePPWhichTechniqueText:
TX_FAR _RestorePPWhichTechniqueText
db "@"
-PPMaxedOutText: ; e467 (3:6467)
+PPMaxedOutText:
TX_FAR _PPMaxedOutText
db "@"
-PPIncreasedText: ; e46c (3:646c)
+PPIncreasedText:
TX_FAR _PPIncreasedText
db "@"
-PPRestoredText: ; e471 (3:6471)
+PPRestoredText:
TX_FAR _PPRestoredText
db "@"
; for items that can't be used from the Item menu
-UnusableItem: ; e476 (3:6476)
+UnusableItem:
jp ItemUseNotTime
-ItemUseTMHM: ; e479 (3:6479)
- ld a,[W_ISINBATTLE]
+ItemUseTMHM:
+ ld a,[wIsInBattle]
and a
jp nz,ItemUseNotTime
ld a,[wcf91]
@@ -2095,8 +2221,8 @@ ItemUseTMHM: ; e479 (3:6479)
call PrintText
ld hl,TeachMachineMoveText
call PrintText
- hlCoord 14, 7
- ld bc,$080f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
@@ -2104,7 +2230,7 @@ ItemUseTMHM: ; e479 (3:6479)
and a
jr z,.useMachine
ld a,2
- ld [wcd6a],a ; item not used
+ ld [wActionResultOrTookBattleTurn],a ; item not used
ret
.useMachine
ld a,[wWhichPokemon]
@@ -2113,16 +2239,16 @@ ItemUseTMHM: ; e479 (3:6479)
push af
.chooseMon
ld hl,wcf4b
- ld de,wd036
+ ld de,wTempMoveNameBuffer
ld bc,14
- call CopyData
+ call CopyData ; save the move name because DisplayPartyMenu will overwrite it
ld a,$ff
ld [wUpdateSpritesEnabled],a
- ld a,$03 ; teach TM/HM party menu
- ld [wd07d],a
+ ld a,TMHM_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
call DisplayPartyMenu
push af
- ld hl,wd036
+ ld hl,wTempMoveNameBuffer
ld de,wcf4b
ld bc,14
call CopyData
@@ -2133,7 +2259,7 @@ ItemUseTMHM: ; e479 (3:6479)
pop af
call GBPalWhiteOutWithDelay3
call ClearSprites
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
jp LoadScreenTilesFromBuffer1 ; restore saved screen
.checkIfAbleToLearnMove
predef CanLearnTM ; check if the pokemon can learn the move
@@ -2146,8 +2272,8 @@ ItemUseTMHM: ; e479 (3:6479)
and a ; can the pokemon learn the move?
jr nz,.checkIfAlreadyLearnedMove
; if the pokemon can't learn the move
- ld a,(SFX_02_51 - SFX_Headers_02) / 3
- call PlaySoundWaitForCurrent ; play sound
+ ld a,SFX_DENIED
+ call PlaySoundWaitForCurrent
ld hl,MonCannotLearnMachineMoveText
call PrintText
jr .chooseMon
@@ -2167,53 +2293,53 @@ ItemUseTMHM: ; e479 (3:6479)
ret c
jp RemoveUsedItem
-BootedUpTMText: ; e54f (3:654f)
+BootedUpTMText:
TX_FAR _BootedUpTMText
db "@"
-BootedUpHMText: ; e554 (3:6554)
+BootedUpHMText:
TX_FAR _BootedUpHMText
db "@"
-TeachMachineMoveText: ; e559 (3:6559)
+TeachMachineMoveText:
TX_FAR _TeachMachineMoveText
db "@"
-MonCannotLearnMachineMoveText: ; e55e (3:655e)
+MonCannotLearnMachineMoveText:
TX_FAR _MonCannotLearnMachineMoveText
db "@"
-PrintItemUseTextAndRemoveItem: ; e563 (3:6563)
+PrintItemUseTextAndRemoveItem:
ld hl,ItemUseText00
call PrintText
- ld a,(SFX_02_3e - SFX_Headers_02) / 3
- call PlaySound ; play sound
+ ld a,SFX_HEAL_AILMENT
+ call PlaySound
call WaitForTextScrollButtonPress ; wait for button press
-RemoveUsedItem: ; e571 (3:6571)
+RemoveUsedItem:
ld hl,wNumBagItems
ld a,1 ; one item
- ld [wcf96],a ; store quantity
+ ld [wItemQuantity],a
jp RemoveItemFromInventory
-ItemUseNoEffect: ; e57c (3:657c)
+ItemUseNoEffect:
ld hl,ItemUseNoEffectText
jr ItemUseFailed
-ItemUseNotTime: ; e581 (3:6581)
+ItemUseNotTime:
ld hl,ItemUseNotTimeText
jr ItemUseFailed
-ItemUseNotYoursToUse: ; e586 (3:6586)
+ItemUseNotYoursToUse:
ld hl,ItemUseNotYoursToUseText
jr ItemUseFailed
-ThrowBallAtTrainerMon: ; e58b (3:658b)
- call GoPAL_SET_CF1C
+ThrowBallAtTrainerMon:
+ call RunDefaultPaletteCommand
call LoadScreenTilesFromBuffer1 ; restore saved screen
call Delay3
ld a,TOSS_ANIM
- ld [W_ANIMATIONID],a
+ ld [wAnimationID],a
predef MoveAnimation ; do animation
ld hl,ThrowBallAtTrainerMonText1
call PrintText
@@ -2221,69 +2347,69 @@ ThrowBallAtTrainerMon: ; e58b (3:658b)
call PrintText
jr RemoveUsedItem
-NoCyclingAllowedHere: ; e5ac (3:65ac)
+NoCyclingAllowedHere:
ld hl,NoCyclingAllowedHereText
jr ItemUseFailed
-BoxFullCannotThrowBall: ; e5b1 (3:65b1)
+BoxFullCannotThrowBall:
ld hl,BoxFullCannotThrowBallText
jr ItemUseFailed
-SurfingAttemptFailed: ; e5b6 (3:65b6)
+SurfingAttemptFailed:
ld hl,NoSurfingHereText
-ItemUseFailed: ; e5b9 (3:65b9)
+ItemUseFailed:
xor a
- ld [wcd6a],a ; item use failed
+ ld [wActionResultOrTookBattleTurn],a ; item use failed
jp PrintText
-ItemUseNotTimeText: ; e5c0 (3:65c0)
+ItemUseNotTimeText:
TX_FAR _ItemUseNotTimeText
db "@"
-ItemUseNotYoursToUseText: ; e5c5 (3:65c5)
+ItemUseNotYoursToUseText:
TX_FAR _ItemUseNotYoursToUseText
db "@"
-ItemUseNoEffectText: ; e5ca (3:65ca)
+ItemUseNoEffectText:
TX_FAR _ItemUseNoEffectText
db "@"
-ThrowBallAtTrainerMonText1: ; e5cf (3:65cf)
+ThrowBallAtTrainerMonText1:
TX_FAR _ThrowBallAtTrainerMonText1
db "@"
-ThrowBallAtTrainerMonText2: ; e5d4 (3:65d4)
+ThrowBallAtTrainerMonText2:
TX_FAR _ThrowBallAtTrainerMonText2
db "@"
-NoCyclingAllowedHereText: ; e5d9 (3:65d9)
+NoCyclingAllowedHereText:
TX_FAR _NoCyclingAllowedHereText
db "@"
-NoSurfingHereText: ; e5de (3:65de)
+NoSurfingHereText:
TX_FAR _NoSurfingHereText
db "@"
-BoxFullCannotThrowBallText: ; e5e3 (3:65e3)
+BoxFullCannotThrowBallText:
TX_FAR _BoxFullCannotThrowBallText
db "@"
-ItemUseText00: ; e5e8 (3:65e8)
+ItemUseText00:
TX_FAR _ItemUseText001
- db $05
+ TX_LINE
TX_FAR _ItemUseText002
db "@"
-GotOnBicycleText: ; e5f2 (3:65f2)
+GotOnBicycleText:
TX_FAR _GotOnBicycleText1
- db $05
+ TX_LINE
TX_FAR _GotOnBicycleText2
db "@"
-GotOffBicycleText: ; e5fc (3:65fc)
+GotOffBicycleText:
TX_FAR _GotOffBicycleText1
- db $05
+ TX_LINE
TX_FAR _GotOffBicycleText2
db "@"
@@ -2291,23 +2417,20 @@ GotOffBicycleText: ; e5fc (3:65fc)
; also, when a PP Up is used, it increases the current PP by one PP Up bonus
; INPUT:
; [wWhichPokemon] = index of pokemon in party
-; [wd11e] = mode
-; 0: Pokemon Center healing
-; 1: using a PP Up
; [wCurrentMenuItem] = index of move (when using a PP Up)
-RestoreBonusPP: ; e606 (3:6606)
+RestoreBonusPP:
ld hl,wPartyMon1Moves
- ld bc,44
+ ld bc, wPartyMon2 - wPartyMon1
ld a,[wWhichPokemon]
call AddNTimes
push hl
- ld de,wcd78 - 1
- predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wcd78
+ ld de,wNormalMaxPPList - 1
+ predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList
pop hl
- ld c,21
+ ld c, wPartyMon1PP - wPartyMon1Moves
ld b,0
add hl,bc ; hl now points to move 1 PP
- ld de,wcd78
+ ld de,wNormalMaxPPList
ld b,0 ; initialize move counter to zero
; loop through the pokemon's moves
.loop
@@ -2315,7 +2438,7 @@ RestoreBonusPP: ; e606 (3:6606)
ld a,b
cp a,5 ; reached the end of the pokemon's moves?
ret z ; if so, return
- ld a,[wd11e]
+ ld a,[wUsingPPUp]
dec a ; using a PP Up?
jr nz,.skipMenuItemIDCheck
; if using a PP Up, check if this is the move it's being used on
@@ -2337,9 +2460,7 @@ RestoreBonusPP: ; e606 (3:6606)
; INPUT:
; [de] = normal max PP
; [hl] = move PP
-; [wd11e] = max number of times to add bonus
-; set to 1 when using a PP Up, set to 255 otherwise
-AddBonusPP: ; e642 (3:6642)
+AddBonusPP:
push bc
ld a,[de] ; normal max PP of move
ld [H_DIVIDEND + 3],a
@@ -2366,9 +2487,9 @@ AddBonusPP: ; e642 (3:6642)
.addAmount
add b
ld b,a
- ld a,[wd11e]
- dec a
- jr z,.done
+ ld a,[wUsingPPUp]
+ dec a ; is the player using a PP Up right now?
+ jr z,.done ; if so, only add the bonus once
dec c
jr nz,.loop
.done
@@ -2379,7 +2500,7 @@ AddBonusPP: ; e642 (3:6642)
; gets max PP of a pokemon's move (including PP from PP Ups)
; INPUT:
; [wWhichPokemon] = index of pokemon within party/box
-; [wcc49] = pokemon source
+; [wMonDataLocation] = pokemon source
; 00: player's party
; 01: enemy's party
; 02: current box
@@ -2387,9 +2508,9 @@ AddBonusPP: ; e642 (3:6642)
; 04: player's in-battle pokemon
; [wCurrentMenuItem] = move index
; OUTPUT:
-; [wd11e] = max PP
-GetMaxPP: ; e677 (3:6677)
- ld a,[wcc49]
+; [wMaxPP] = max PP
+GetMaxPP:
+ ld a,[wMonDataLocation]
and a
ld hl,wPartyMon1Moves
ld bc,wPartyMon2 - wPartyMon1
@@ -2415,21 +2536,21 @@ GetMaxPP: ; e677 (3:6677)
dec a
push hl
ld hl,Moves
- ld bc,6
+ ld bc,MoveEnd - Moves
call AddNTimes
ld de,wcd6d
ld a,BANK(Moves)
call FarCopyData
- ld de,wcd72
+ ld de,wcd6d + 5 ; PP is byte 5 of move data
ld a,[de]
ld b,a ; b = normal max PP
pop hl
push bc
- ld bc,21 ; PP offset if not player's in-battle pokemon data
- ld a,[wcc49]
+ ld bc,wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data
+ ld a,[wMonDataLocation]
cp a,4 ; player's in-battle pokemon?
jr nz,.addPPOffset
- ld bc,17 ; PP offset if player's in-battle pokemon data
+ ld bc,wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data
.addPPOffset
add hl,bc
ld a,[hl] ; a = current PP
@@ -2440,19 +2561,19 @@ GetMaxPP: ; e677 (3:6677)
ld l,e
inc hl ; hl = wcd73
ld [hl],a
- xor a
- ld [wd11e],a ; no limit on PP Up amount
+ xor a ; add the bonus for the existing PP Up count
+ ld [wUsingPPUp],a
call AddBonusPP ; add bonus PP from PP Ups
ld a,[hl]
and a,%00111111 ; mask out the PP Up count
- ld [wd11e],a ; store max PP
+ ld [wMaxPP],a ; store max PP
ret
-GetSelectedMoveOffset: ; e6e3 (3:66e3)
+GetSelectedMoveOffset:
ld a,[wWhichPokemon]
call AddNTimes
-GetSelectedMoveOffset2: ; e6e9 (3:66e9)
+GetSelectedMoveOffset2:
ld a,[wCurrentMenuItem]
ld c,a
ld b,0
@@ -2464,10 +2585,10 @@ GetSelectedMoveOffset2: ; e6e9 (3:66e9)
; hl = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcf91] = item ID
; [wWhichPokemon] = index of item within inventory
-; [wcf96] = quantity to toss
+; [wItemQuantity] = quantity to toss
; OUTPUT:
; clears carry flag if the item is tossed, sets carry flag if not
-TossItem_: ; e6f1 (3:66f1)
+TossItem_:
push hl
ld a,[wcf91]
call IsItemHM
@@ -2475,7 +2596,7 @@ TossItem_: ; e6f1 (3:66f1)
jr c,.tooImportantToToss
push hl
call IsKeyItem_
- ld a,[wd124]
+ ld a,[wIsKeyItem]
pop hl
and a
jr nz,.tooImportantToToss
@@ -2486,16 +2607,16 @@ TossItem_: ; e6f1 (3:66f1)
call CopyStringToCF4B ; copy name to wcf4b
ld hl,IsItOKToTossItemText
call PrintText
- hlCoord 14, 7
- ld bc,$080f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,2
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
pop hl
scf
- ret z
+ ret z ; return if the player chose No
; if the player chose Yes
push hl
ld a,[wWhichPokemon]
@@ -2517,15 +2638,15 @@ TossItem_: ; e6f1 (3:66f1)
scf
ret
-ThrewAwayItemText: ; e755 (3:6755)
+ThrewAwayItemText:
TX_FAR _ThrewAwayItemText
db "@"
-IsItOKToTossItemText: ; e75a (3:675a)
+IsItOKToTossItemText:
TX_FAR _IsItOKToTossItemText
db "@"
-TooImportantToTossText: ; e75f (3:675f)
+TooImportantToTossText:
TX_FAR _TooImportantToTossText
db "@"
@@ -2533,27 +2654,27 @@ TooImportantToTossText: ; e75f (3:675f)
; INPUT:
; [wcf91] = item ID
; OUTPUT:
-; [wd124] = result
+; [wIsKeyItem] = result
; 00: item is not key item
; 01: item is key item
-IsKeyItem_: ; e764 (3:6764)
+IsKeyItem_:
ld a,$01
- ld [wd124],a
+ ld [wIsKeyItem],a
ld a,[wcf91]
cp a,HM_01 ; is the item an HM or TM?
jr nc,.checkIfItemIsHM
; if the item is not an HM or TM
push af
ld hl,KeyItemBitfield
- ld de,wHPBarMaxHP
+ ld de,wBuffer
ld bc,15 ; only 11 bytes are actually used
call CopyData
pop af
dec a
ld c,a
- ld hl,wHPBarMaxHP
- ld b,$02 ; test bit
- predef FlagActionPredef ; bitfield operation function
+ ld hl,wBuffer
+ ld b,FLAG_TEST
+ predef FlagActionPredef
ld a,c
and a
ret nz
@@ -2562,13 +2683,13 @@ IsKeyItem_: ; e764 (3:6764)
call IsItemHM
ret c
xor a
- ld [wd124],a
+ ld [wIsKeyItem],a
ret
INCLUDE "data/key_items.asm"
-SendNewMonToBox: ; e7a4 (3:67a4)
- ld de, W_NUMINBOX ; wda80
+SendNewMonToBox:
+ ld de, wNumInBox
ld a, [de]
inc a
ld [de], a
@@ -2586,74 +2707,74 @@ SendNewMonToBox: ; e7a4 (3:67a4)
jr nz, .asm_e7b1
call GetMonHeader
ld hl, wBoxMonOT
- ld bc, $b
- ld a, [W_NUMINBOX] ; wda80
+ ld bc, NAME_LENGTH
+ ld a, [wNumInBox]
dec a
jr z, .asm_e7ee
dec a
call AddNTimes
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
add hl, bc
ld d, h
ld e, l
pop hl
- ld a, [W_NUMINBOX] ; wda80
+ ld a, [wNumInBox]
dec a
ld b, a
.asm_e7db
push bc
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
pop hl
ld d, h
ld e, l
- ld bc, $fff5
+ ld bc, -NAME_LENGTH
add hl, bc
pop bc
dec b
jr nz, .asm_e7db
.asm_e7ee
- ld hl, wPlayerName ; wd158
+ ld hl, wPlayerName
ld de, wBoxMonOT
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
- ld a, [W_NUMINBOX] ; wda80
+ ld a, [wNumInBox]
dec a
jr z, .asm_e82a
ld hl, wBoxMonNicks
- ld bc, $b
+ ld bc, NAME_LENGTH
dec a
call AddNTimes
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
add hl, bc
ld d, h
ld e, l
pop hl
- ld a, [W_NUMINBOX] ; wda80
+ ld a, [wNumInBox]
dec a
ld b, a
.asm_e817
push bc
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
pop hl
ld d, h
ld e, l
- ld bc, $fff5
+ ld bc, -NAME_LENGTH
add hl, bc
pop bc
dec b
jr nz, .asm_e817
.asm_e82a
ld hl, wBoxMonNicks
- ld a, $2
- ld [wd07d], a
+ ld a, NAME_MON_SCREEN
+ ld [wNamingScreenType], a
predef AskName
- ld a, [W_NUMINBOX] ; wda80
+ ld a, [wNumInBox]
dec a
jr z, .asm_e867
ld hl, wBoxMons
@@ -2666,7 +2787,7 @@ SendNewMonToBox: ; e7a4 (3:67a4)
ld d, h
ld e, l
pop hl
- ld a, [W_NUMINBOX] ; wda80
+ ld a, [wNumInBox]
dec a
ld b, a
.asm_e854
@@ -2677,19 +2798,19 @@ SendNewMonToBox: ; e7a4 (3:67a4)
pop hl
ld d, h
ld e, l
- ld bc, $ffdf
+ ld bc, wBoxMon1 - wBoxMon2
add hl, bc
pop bc
dec b
jr nz, .asm_e854
.asm_e867
- ld a, [wEnemyMonLevel] ; wEnemyMonLevel
+ ld a, [wEnemyMonLevel]
ld [wEnemyMonBoxLevel], a
ld hl, wEnemyMon
ld de, wBoxMon1
- ld bc, $c
+ ld bc, wEnemyMonDVs - wEnemyMon
call CopyData
- ld hl, wPlayerID ; wPlayerID
+ ld hl, wPlayerID
ld a, [hli]
ld [de], a
inc de
@@ -2697,21 +2818,21 @@ SendNewMonToBox: ; e7a4 (3:67a4)
ld [de], a
inc de
push de
- ld a, [W_CURENEMYLVL] ; W_CURENEMYLVL
+ ld a, [wCurEnemyLVL]
ld d, a
callab CalcExperience
pop de
- ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
+ ld a, [hExperience]
ld [de], a
inc de
- ld a, [$ff97]
+ ld a, [hExperience + 1]
ld [de], a
inc de
- ld a, [$ff98]
+ ld a, [hExperience + 2]
ld [de], a
inc de
xor a
- ld b, $a
+ ld b, NUM_STATS * 2
.asm_e89f
ld [de], a
inc de
@@ -2723,8 +2844,8 @@ SendNewMonToBox: ; e7a4 (3:67a4)
inc de
ld a, [hli]
ld [de], a
- ld hl, wEnemyMonPP ; wcffe
- ld b, $4
+ ld hl, wEnemyMonPP
+ ld b, NUM_MOVES
.asm_e8b1
ld a, [hli]
inc de
@@ -2736,13 +2857,13 @@ SendNewMonToBox: ; e7a4 (3:67a4)
; checks if the tile in front of the player is a shore or water tile
; used for surfing and fishing
; unsets carry if it is, sets carry if not
-IsNextTileShoreOrWater: ; e8b8 (3:68b8)
- ld a, [W_CURMAPTILESET]
+IsNextTileShoreOrWater:
+ ld a, [wCurMapTileset]
ld hl, WaterTilesets
ld de,1
call IsInArray
jr nc, .notShoreOrWater
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp SHIP_PORT ; Vermilion Dock tileset
ld a, [wTileInFrontOfPlayer] ; tile in front of player
jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset
@@ -2761,15 +2882,15 @@ IsNextTileShoreOrWater: ; e8b8 (3:68b8)
ret
; tilesets with water
-WaterTilesets: ; e8e0 (3:68e0)
+WaterTilesets:
db OVERWORLD, FOREST, DOJO, GYM, SHIP, SHIP_PORT, CAVERN, FACILITY, PLATEAU
db $ff ; terminator
-ReadSuperRodData: ; e8ea (3:68ea)
+ReadSuperRodData:
; return e = 2 if no fish on this map
; return e = 1 if a bite, bc = level,species
; return e = 0 if no bite
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
ld de, 3 ; each fishing group is three bytes wide
ld hl, SuperRodData
call IsInArray
@@ -2777,7 +2898,7 @@ ReadSuperRodData: ; e8ea (3:68ea)
ld e, $2 ; $2 if no fishing groups found
ret
-.ReadFishingGroup ; 0xe8f6
+.ReadFishingGroup
; hl points to the fishing group entry in the index
inc hl ; skip map id
@@ -2790,7 +2911,7 @@ ReadSuperRodData: ; e8ea (3:68ea)
inc hl ; point to data
ld e, $0 ; no bite yet
-.RandomLoop ; 0xe90c
+.RandomLoop
call Random
srl a
ret c ; 50% chance of no battle
@@ -2814,13 +2935,13 @@ INCLUDE "data/super_rod.asm"
; reloads map view and processes sprite data
; for items that cause the overworld to be displayed
-ItemUseReloadOverworldData: ; e9c5 (3:69c5)
+ItemUseReloadOverworldData:
call LoadCurrentMapView
jp UpdateSprites
; creates a list at wBuffer of maps where the mon in [wd11e] can be found.
; this is used by the pokedex to display locations the mon can be found on the map.
-FindWildLocationsOfMon: ; e9cb (3:69cb)
+FindWildLocationsOfMon:
ld hl, WildDataPointers
ld de, wBuffer
ld c, $0
@@ -2849,7 +2970,7 @@ FindWildLocationsOfMon: ; e9cb (3:69cb)
ld [de], a
ret
-CheckMapForMon: ; e9f0 (3:69f0)
+CheckMapForMon:
inc hl
ld b, $a
.loop
diff --git a/engine/items/tm_prices.asm b/engine/items/tm_prices.asm
index 7c5c56fa..80e6bf3c 100755
--- a/engine/items/tm_prices.asm
+++ b/engine/items/tm_prices.asm
@@ -1,12 +1,11 @@
-GetMachinePrice: ; 7bf86 (1e:7f86)
+GetMachinePrice:
; Input: [wcf91] = Item Id of a TM
-; Output: Stores the 2-byte TM price in [H_DOWNARROWBLINKCNT1] and [H_DOWNARROWBLINKCNT2]
-; as a BCD
+; Output: Stores the TM price at hItemPrice
ld a, [wcf91] ; a contains TM item id
sub TM_01
ret c
ld d, a
- ld hl, TechnicalMachinePrices ; $7fa7
+ ld hl, TechnicalMachinePrices
srl a
ld c, a
ld b, 0
@@ -17,10 +16,10 @@ GetMachinePrice: ; 7bf86 (1e:7f86)
swap a
.highNybbleIsPrice
and $f0
- ld [H_DOWNARROWBLINKCNT2], a ; $ff8c
+ ld [hItemPrice + 1], a
xor a
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
- ld [$ff8d], a
+ ld [hItemPrice], a
+ ld [hItemPrice + 2], a
ret
INCLUDE "data/tm_prices.asm"
diff --git a/engine/items/tmhm.asm b/engine/items/tmhm.asm
index 0fcc5710..7ccaa232 100755
--- a/engine/items/tmhm.asm
+++ b/engine/items/tmhm.asm
@@ -1,5 +1,5 @@
; checks if the mon in [wWhichPokemon] already knows the move in [wMoveNum]
-CheckIfMoveIsKnown: ; 2fe18 (b:7e18)
+CheckIfMoveIsKnown:
ld a, [wWhichPokemon]
ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
@@ -21,6 +21,6 @@ CheckIfMoveIsKnown: ; 2fe18 (b:7e18)
scf
ret
-AlreadyKnowsText: ; 2fe3b (b:7e3b)
+AlreadyKnowsText:
TX_FAR _AlreadyKnowsText
db "@"
diff --git a/engine/items/tms.asm b/engine/items/tms.asm
index 511aab5b..da1b5e72 100755
--- a/engine/items/tms.asm
+++ b/engine/items/tms.asm
@@ -1,9 +1,9 @@
; tests if mon [wcf91] can learn move [wMoveNum]
-CanLearnTM: ; 1373e (4:773e)
+CanLearnTM:
ld a, [wcf91]
ld [wd0b5], a
call GetMonHeader
- ld hl, W_MONHLEARNSET
+ ld hl, wMonHLearnset
push hl
ld a, [wMoveNum]
ld b, a
@@ -17,12 +17,12 @@ CanLearnTM: ; 1373e (4:773e)
jr .findTMloop
.TMfoundLoop
pop hl
- ld b, $2 ; read corresponding bit from TM compatibility array
+ ld b, FLAG_TEST
predef_jump FlagActionPredef
; converts TM/HM number in wd11e into move number
; HMs start at 51
-TMToMove: ; 13763 (4:7763)
+TMToMove:
ld a, [wd11e]
dec a
ld hl, TechnicalMachines
diff --git a/engine/learn_move.asm b/engine/learn_move.asm
index 75056edb..ba73d4c0 100755
--- a/engine/learn_move.asm
+++ b/engine/learn_move.asm
@@ -1,28 +1,28 @@
-LearnMove: ; 6e43 (1:6e43)
+LearnMove:
call SaveScreenTilesToBuffer1
ld a, [wWhichPokemon]
ld hl, wPartyMonNicks
call GetPartyMonName
ld hl, wcd6d
- ld de, wd036
- ld bc, $b
+ ld de, wLearnMoveMonName
+ ld bc, NAME_LENGTH
call CopyData
-DontAbandonLearning: ; 6e5b (1:6e5b)
+DontAbandonLearning:
ld hl, wPartyMon1Moves
- ld bc, $2c
+ ld bc, wPartyMon2Moves - wPartyMon1Moves
ld a, [wWhichPokemon]
call AddNTimes
ld d, h
ld e, l
- ld b, $4
-.asm_6e6b
+ ld b, NUM_MOVES
+.findEmptyMoveSlotLoop
ld a, [hl]
and a
- jr z, .asm_6e8b
+ jr z, .next
inc hl
dec b
- jr nz, .asm_6e6b
+ jr nz, .findEmptyMoveSlotLoop
push de
call TryingToLearn
pop de
@@ -35,25 +35,25 @@ DontAbandonLearning: ; 6e5b (1:6e5b)
call PrintText
pop de
pop hl
-.asm_6e8b
+.next
ld a, [wMoveNum]
ld [hl], a
- ld bc, $15
+ ld bc, wPartyMon1PP - wPartyMon1Moves
add hl, bc
push hl
push de
dec a
ld hl, Moves
- ld bc, $6
+ ld bc, MoveEnd - Moves
call AddNTimes
- ld de, wHPBarMaxHP
+ ld de, wBuffer
ld a, BANK(Moves)
call FarCopyData
- ld a, [wHPBarNewHP + 1]
+ ld a, [wBuffer + 5] ; a = move's max PP
pop de
pop hl
ld [hl], a
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
jp z, PrintLearnedMove
ld a, [wWhichPokemon]
@@ -66,18 +66,18 @@ DontAbandonLearning: ; 6e5b (1:6e5b)
ld de, wBattleMonMoves
ld bc, NUM_MOVES
call CopyData
- ld bc, $11
+ ld bc, wPartyMon1PP - wPartyMon1OTID
add hl, bc
ld de, wBattleMonPP
- ld bc, $4
+ ld bc, NUM_MOVES
call CopyData
jp PrintLearnedMove
-AbandonLearning: ; 6eda (1:6eda)
+AbandonLearning:
ld hl, AbandonLearningText
call PrintText
- hlCoord 14, 7
- ld bc, $80f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID ; yes/no menu
@@ -86,21 +86,21 @@ AbandonLearning: ; 6eda (1:6eda)
jp nz, DontAbandonLearning
ld hl, DidNotLearnText
call PrintText
- ld b, $0
+ ld b, 0
ret
-PrintLearnedMove: ; 6efe (1:6efe)
+PrintLearnedMove:
ld hl, LearnedMove1Text
call PrintText
- ld b, $1
+ ld b, 1
ret
-TryingToLearn: ; 6f07 (1:6f07)
+TryingToLearn:
push hl
ld hl, TryingToLearnText
call PrintText
- hlCoord 14, 7
- ld bc, $80f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID ; yes/no menu
@@ -108,7 +108,7 @@ TryingToLearn: ; 6f07 (1:6f07)
ld a, [wCurrentMenuItem]
rra
ret c
- ld bc, $fffc
+ ld bc, -NUM_MOVES
add hl, bc
push hl
ld de, wMoves
@@ -116,15 +116,15 @@ TryingToLearn: ; 6f07 (1:6f07)
call CopyData
callab FormatMovesString
pop hl
-.asm_6f39
+.loop
push hl
ld hl, WhichMoveToForgetText
call PrintText
- hlCoord 4, 7
- ld b, $4
- ld c, $e
+ coord hl, 4, 7
+ ld b, 4
+ ld c, 14
call TextBoxBorder
- hlCoord 6, 8
+ coord hl, 6, 8
ld de, wMovesString
ld a, [hFlags_0xFFF6]
set 2, a
@@ -134,18 +134,18 @@ TryingToLearn: ; 6f07 (1:6f07)
res 2, a
ld [hFlags_0xFFF6], a
ld hl, wTopMenuItemY
- ld a, $8
- ld [hli], a
- ld a, $5
- ld [hli], a
+ ld a, 8
+ ld [hli], a ; wTopMenuItemY
+ ld a, 5
+ ld [hli], a ; wTopMenuItemX
xor a
- ld [hli], a
+ ld [hli], a ; wCurrentMenuItem
inc hl
- ld a, [wcd6c]
- ld [hli], a
- ld a, $3
- ld [hli], a
- ld [hl], $0
+ ld a, [wNumMovesMinusOne]
+ ld [hli], a ; wMaxMenuItem
+ ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
+ ld [hl], 0 ; wLastMenuItem
ld hl, hFlags_0xFFF6
set 1, [hl]
call HandleMenuInput
@@ -155,12 +155,12 @@ TryingToLearn: ; 6f07 (1:6f07)
call LoadScreenTilesFromBuffer1
pop af
pop hl
- bit 1, a
- jr nz, .asm_6fab
+ bit 1, a ; pressed b
+ jr nz, .cancel
push hl
ld a, [wCurrentMenuItem]
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hl]
push af
@@ -169,56 +169,58 @@ TryingToLearn: ; 6f07 (1:6f07)
pop bc
pop de
ld a, d
- jr c, .asm_6fa2
+ jr c, .hm
pop hl
add hl, bc
and a
ret
-.asm_6fa2
+.hm
ld hl, HMCantDeleteText
call PrintText
pop hl
- jr .asm_6f39
-.asm_6fab
+ jr .loop
+.cancel
scf
ret
-LearnedMove1Text: ; 6fb4 (1:6fb4)
+LearnedMove1Text:
TX_FAR _LearnedMove1Text
- db $b,6,"@"
+ TX_SFX_ITEM_1 ; plays SFX_GET_ITEM_1 in the pary menu (rare candy) and plays SFX_LEVEL_UP in battle
+ TX_BLINK
+ db "@"
-WhichMoveToForgetText: ; 6fb4 (1:6fb4)
+WhichMoveToForgetText:
TX_FAR _WhichMoveToForgetText
db "@"
-AbandonLearningText: ; 6fb9 (1:6fb9)
+AbandonLearningText:
TX_FAR _AbandonLearningText
db "@"
-DidNotLearnText: ; 6fbe (1:6fbe)
+DidNotLearnText:
TX_FAR _DidNotLearnText
db "@"
-TryingToLearnText: ; 6fc3 (1:6fc3)
+TryingToLearnText:
TX_FAR _TryingToLearnText
db "@"
-OneTwoAndText: ; 6fc8 (1:6fc8)
+OneTwoAndText:
TX_FAR _OneTwoAndText
- db $a
- db $8
- ld a, (SFX_02_58 - SFX_Headers_02) / 3
+ TX_DELAY
+ TX_ASM
+ ld a, SFX_SWAP
call PlaySoundWaitForCurrent
ld hl, PoofText
ret
-PoofText: ; 6fd7 (1:6fd7)
+PoofText:
TX_FAR _PoofText
- db $a
-ForgotAndText: ; 6fdc (1:6fdc)
+ TX_DELAY
+ForgotAndText:
TX_FAR _ForgotAndText
db "@"
-HMCantDeleteText: ; 6fe1 (1:6fe1)
+HMCantDeleteText:
TX_FAR _HMCantDeleteText
db "@"
diff --git a/engine/load_mon_data.asm b/engine/load_mon_data.asm
new file mode 100644
index 00000000..a71a81c5
--- /dev/null
+++ b/engine/load_mon_data.asm
@@ -0,0 +1,49 @@
+LoadMonData_:
+; Load monster [wWhichPokemon] from list [wMonDataLocation]:
+; 0: partymon
+; 1: enemymon
+; 2: boxmon
+; 3: daycaremon
+; Return monster id at wcf91 and its data at wLoadedMon.
+; Also load base stats at wMonHeader for convenience.
+
+ ld a, [wDayCareMonSpecies]
+ ld [wcf91], a
+ ld a, [wMonDataLocation]
+ cp DAYCARE_DATA
+ jr z, .GetMonHeader
+
+ ld a, [wWhichPokemon]
+ ld e, a
+ callab GetMonSpecies
+
+.GetMonHeader
+ ld a, [wcf91]
+ ld [wd0b5], a ; input for GetMonHeader
+ call GetMonHeader
+
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1
+ ld a, [wMonDataLocation]
+ cp ENEMY_PARTY_DATA
+ jr c, .getMonEntry
+
+ ld hl, wEnemyMons
+ jr z, .getMonEntry
+
+ cp 2
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1
+ jr z, .getMonEntry
+
+ ld hl, wDayCareMon
+ jr .copyMonData
+
+.getMonEntry
+ ld a, [wWhichPokemon]
+ call AddNTimes
+
+.copyMonData
+ ld de, wLoadedMon
+ ld bc, wPartyMon2 - wPartyMon1
+ jp CopyData
diff --git a/engine/load_pokedex_tiles.asm b/engine/load_pokedex_tiles.asm
index e8205ef8..637b7a24 100755
--- a/engine/load_pokedex_tiles.asm
+++ b/engine/load_pokedex_tiles.asm
@@ -1,11 +1,11 @@
; Loads tile patterns for tiles used in the pokedex.
-LoadPokedexTilePatterns: ; 17840 (5:7840)
+LoadPokedexTilePatterns:
call LoadHpBarAndStatusTilePatterns
- ld de,PokedexTileGraphics ; $6488
+ ld de,PokedexTileGraphics
ld hl,vChars2 + $600
- ld bc,(BANK(PokedexTileGraphics) << 8) + $12
+ lb bc, BANK(PokedexTileGraphics), (PokedexTileGraphicsEnd - PokedexTileGraphics) / $10
call CopyVideoData
- ld de,PokeballTileGraphics ; $697e
+ ld de,PokeballTileGraphics
ld hl,vChars2 + $720
- ld bc,(BANK(PokeballTileGraphics) << 8) + $01
+ lb bc, BANK(PokeballTileGraphics), $01
jp CopyVideoData ; load pokeball tile for marking caught mons
diff --git a/engine/menu/bills_pc.asm b/engine/menu/bills_pc.asm
index 61e6204e..85a546e1 100644
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -1,90 +1,87 @@
-Func_213c8:: ; 213c8 (8:53c8)
+DisplayPCMainMenu::
xor a
ld [H_AUTOBGTRANSFERENABLED], a
call SaveScreenTilesToBuffer2
- ld a, [wd5a2]
+ ld a, [wNumHoFTeams]
and a
- jr nz, .asm_213f3
- ld a, [wd74b]
- bit 5, a
- jr z, .asm_213ea
- ld a, [wd5a2]
+ jr nz, .leaguePCAvailable
+ CheckEvent EVENT_GOT_POKEDEX
+ jr z, .noOaksPC
+ ld a, [wNumHoFTeams]
and a
- jr nz, .asm_213f3
- ld hl, wTileMap
- ld b, $8
- ld c, $e
- jr .asm_213fa
-.asm_213ea
- ld hl, wTileMap
- ld b, $6
- ld c, $e
- jr .asm_213fa
-.asm_213f3
- ld hl, wTileMap
- ld b, $a
- ld c, $e
-.asm_213fa
+ jr nz, .leaguePCAvailable
+ coord hl, 0, 0
+ ld b, 8
+ ld c, 14
+ jr .next
+.noOaksPC
+ coord hl, 0, 0
+ ld b, 6
+ ld c, 14
+ jr .next
+.leaguePCAvailable
+ coord hl, 0, 0
+ ld b, 10
+ ld c, 14
+.next
call TextBoxBorder
call UpdateSprites
- ld a, $3
+ ld a, 3
ld [wMaxMenuItem], a
- ld a, [wd7f1]
- bit 0, a
- jr nz, .asm_21414
- hlCoord 2, 2
+ CheckEvent EVENT_MET_BILL
+ jr nz, .metBill
+ coord hl, 2, 2
ld de, SomeonesPCText
- jr .asm_2141a
-.asm_21414
- hlCoord 2, 2
+ jr .next2
+.metBill
+ coord hl, 2, 2
ld de, BillsPCText
-.asm_2141a
+.next2
call PlaceString
- hlCoord 2, 4
+ coord hl, 2, 4
ld de, wPlayerName
call PlaceString
ld l, c
ld h, b
ld de, PlayersPCText
call PlaceString
- ld a, [wd74b]
- bit 5, a
- jr z, .asm_21462
- hlCoord 2, 6
+ CheckEvent EVENT_GOT_POKEDEX
+ jr z, .noOaksPC2
+ coord hl, 2, 6
ld de, OaksPCText
call PlaceString
- ld a, [wd5a2]
+ ld a, [wNumHoFTeams]
and a
- jr z, .asm_2145a
- ld a, $4
+ jr z, .noLeaguePC
+ ld a, 4
ld [wMaxMenuItem], a
- hlCoord 2, 8
+ coord hl, 2, 8
ld de, PKMNLeaguePCText
call PlaceString
- hlCoord 2, 10
+ coord hl, 2, 10
ld de, LogOffPCText
- jr .asm_2146d
-.asm_2145a
- hlCoord 2, 8
+ jr .next3
+.noLeaguePC
+ coord hl, 2, 8
ld de, LogOffPCText
- jr .asm_2146d
-.asm_21462
+ jr .next3
+.noOaksPC2
ld a, $2
ld [wMaxMenuItem], a
- hlCoord 2, 6
+ coord hl, 2, 6
ld de, LogOffPCText
-.asm_2146d
+.next3
call PlaceString
- ld a, $3
+ ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $2
+ ld a, 2
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld a, $1
+ ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
ret
@@ -95,107 +92,109 @@ OaksPCText: db "PROF.OAK's PC@"
PKMNLeaguePCText: db $4a, "LEAGUE@"
LogOffPCText: db "LOG OFF@"
-BillsPC_:: ; 0x214c2
+BillsPC_::
ld hl, wd730
set 6, [hl]
xor a
- ld [wccd3], a
+ ld [wParentMenuItem], a
inc a ; MONSTER_NAME
ld [wNameListType], a
call LoadHpBarAndStatusTilePatterns
ld a, [wListScrollOffset]
push af
ld a, [wFlags_0xcd60]
- bit 3, a
+ bit 3, a ; accessing Bill's PC through another PC?
jr nz, BillsPCMenu
+; accessing it directly
ld a, $99
call PlaySound
ld hl, SwitchOnText
call PrintText
-Func_214e8: ; 214e8 (8:54e8)
BillsPCMenu:
- ld a, [wccd3]
+ ld a, [wParentMenuItem]
ld [wCurrentMenuItem], a
ld hl, vChars2 + $780
ld de, PokeballTileGraphics
- ld bc, (BANK(PokeballTileGraphics) << 8) + $01
+ lb bc, BANK(PokeballTileGraphics), $01
call CopyVideoData
call LoadScreenTilesFromBuffer2DisableBGTransfer
- ld hl, wTileMap
- ld b, $a
- ld c, $c
+ coord hl, 0, 0
+ ld b, 10
+ ld c, 12
call TextBoxBorder
- hlCoord 2, 2
+ coord hl, 2, 2
ld de, BillsPCMenuText
call PlaceString
ld hl, wTopMenuItemY
- ld a, $2
- ld [hli], a
+ ld a, 2
+ ld [hli], a ; wTopMenuItemY
dec a
- ld [hli], a
+ ld [hli], a ; wTopMenuItemX
inc hl
inc hl
- ld a, $4
- ld [hli], a
- ld a, $3
- ld [hli], a
+ ld a, 4
+ ld [hli], a ; wMaxMenuItem
+ ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
- ld [hli], a
- ld [hli], a
+ ld [hli], a ; wLastMenuItem
+ ld [hli], a ; wPartyAndBillsPCSavedMenuItem
ld hl, wListScrollOffset
- ld [hli], a
- ld [hl], a
+ ld [hli], a ; wListScrollOffset
+ ld [hl], a ; wMenuWatchMovingOutOfBounds
ld [wPlayerMonNumber], a
ld hl, WhatText
call PrintText
- hlCoord 9, 14
- ld b, $2
- ld c, $9
+ coord hl, 9, 14
+ ld b, 2
+ ld c, 9
call TextBoxBorder
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
- jr c, .asm_2154f
+ jr c, .singleDigitBoxNum
+; two digit box num
sub 9
- hlCoord 17, 16
+ coord hl, 17, 16
ld [hl], "1"
add "0"
- jr .asm_21551
-.asm_2154f
+ jr .next
+.singleDigitBoxNum
add "1"
-.asm_21551
+.next
Coorda 18, 16
- hlCoord 10, 16
+ coord hl, 10, 16
ld de, BoxNoPCText
call PlaceString
- ld a, $1
+ ld a, 1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
call HandleMenuInput
bit 1, a
- jp nz, Func_21588 ; b button
+ jp nz, ExitBillsPC ; b button
call PlaceUnfilledArrowMenuCursor
ld a, [wCurrentMenuItem]
- ld [wccd3], a
+ ld [wParentMenuItem], a
and a
- jp z, Func_21618 ; withdraw
+ jp z, BillsPCWithdraw ; withdraw
cp $1
- jp z, Func_215ac ; deposit
+ jp z, BillsPCDeposit ; deposit
cp $2
- jp z, Func_21673 ; release
+ jp z, BillsPCRelease ; release
cp $3
- jp z, Func_216b3 ; change box
+ jp z, BillsPCChangeBox ; change box
-Func_21588: ; 21588 (8:5588)
+ExitBillsPC:
ld a, [wFlags_0xcd60]
- bit 3, a
- jr nz, .asm_2159a
+ bit 3, a ; accessing Bill's PC through another PC?
+ jr nz, .next
+; accessing it directly
call LoadTextBoxTilePatterns
ld a, $9a
call PlaySound
call WaitForSoundToFinish
-.asm_2159a
+.next
ld hl, wFlags_0xcd60
res 5, [hl]
call LoadScreenTilesFromBuffer2
@@ -205,166 +204,164 @@ Func_21588: ; 21588 (8:5588)
res 6, [hl]
ret
-Func_215ac: ; 215ac (8:55ac)
BillsPCDeposit:
ld a, [wPartyCount]
dec a
- jr nz, .asm_215bb
+ jr nz, .partyLargeEnough
ld hl, CantDepositLastMonText
call PrintText
jp BillsPCMenu
-.asm_215bb
- ld a, [W_NUMINBOX]
+.partyLargeEnough
+ ld a, [wNumInBox]
cp MONS_PER_BOX
- jr nz, .asm_215cb
+ jr nz, .boxNotFull
ld hl, BoxFullText
call PrintText
jp BillsPCMenu
-.asm_215cb
+.boxNotFull
ld hl, wPartyCount
- call Func_216be
+ call DisplayMonListMenu
jp c, BillsPCMenu
- call Func_2174b
+ call DisplayDepositWithdrawMenu
jp nc, BillsPCMenu
ld a, [wcf91]
call GetCryData
call PlaySoundWaitForCurrent
- ld a, $1
- ld [wcf95], a
- call Func_3a68
+ ld a, PARTY_TO_BOX
+ ld [wMoveMonType], a
+ call MoveMon
xor a
- ld [wcf95], a
+ ld [wRemoveMonFromBox], a
call RemovePokemon
call WaitForSoundToFinish
- ld hl, wWhichTrade
- ld a, [wd5a0]
+ ld hl, wBoxNumString
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
- jr c, .asm_2160a
+ jr c, .singleDigitBoxNum
sub 9
ld [hl], "1"
inc hl
add "0"
- jr .asm_2160c
-.asm_2160a
+ jr .next
+.singleDigitBoxNum
add "1"
-.asm_2160c
+.next
ld [hli], a
- ld [hl], $50
+ ld [hl], "@"
ld hl, MonWasStoredText
call PrintText
jp BillsPCMenu
-Func_21618: ; 21618 (8:5618)
- ld a, [W_NUMINBOX]
+BillsPCWithdraw:
+ ld a, [wNumInBox]
and a
- jr nz, .asm_21627
+ jr nz, .boxNotEmpty
ld hl, NoMonText
call PrintText
- jp Func_214e8
-.asm_21627
+ jp BillsPCMenu
+.boxNotEmpty
ld a, [wPartyCount]
cp PARTY_LENGTH
- jr nz, .asm_21637
+ jr nz, .partyNotFull
ld hl, CantTakeMonText
call PrintText
- jp Func_214e8
-.asm_21637
- ld hl, W_NUMINBOX
- call Func_216be
- jp c, Func_214e8
- call Func_2174b
- jp nc, Func_214e8
+ jp BillsPCMenu
+.partyNotFull
+ ld hl, wNumInBox
+ call DisplayMonListMenu
+ jp c, BillsPCMenu
+ call DisplayDepositWithdrawMenu
+ jp nc, BillsPCMenu
ld a, [wWhichPokemon]
ld hl, wBoxMonNicks
call GetPartyMonName
ld a, [wcf91]
call GetCryData
call PlaySoundWaitForCurrent
- xor a
- ld [wcf95], a
- call Func_3a68
- ld a, $1
- ld [wcf95], a
+ xor a ; BOX_TO_PARTY
+ ld [wMoveMonType], a
+ call MoveMon
+ ld a, 1
+ ld [wRemoveMonFromBox], a
call RemovePokemon
call WaitForSoundToFinish
ld hl, MonIsTakenOutText
call PrintText
- jp Func_214e8
+ jp BillsPCMenu
-Func_21673: ; 21673 (8:5673)
- ld a, [W_NUMINBOX]
+BillsPCRelease:
+ ld a, [wNumInBox]
and a
- jr nz, .asm_21682
+ jr nz, .loop
ld hl, NoMonText
call PrintText
- jp Func_214e8
-.asm_21682
- ld hl, W_NUMINBOX
- call Func_216be
- jp c, Func_214e8
+ jp BillsPCMenu
+.loop
+ ld hl, wNumInBox
+ call DisplayMonListMenu
+ jp c, BillsPCMenu
ld hl, OnceReleasedText
call PrintText
call YesNoChoice
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_21682
+ jr nz, .loop
inc a
- ld [wcf95], a
+ ld [wRemoveMonFromBox], a
call RemovePokemon
call WaitForSoundToFinish
ld a, [wcf91]
call PlayCry
ld hl, MonWasReleasedText
call PrintText
- jp Func_214e8
+ jp BillsPCMenu
-Func_216b3: ; 216b3 (8:56b3)
+BillsPCChangeBox:
callba ChangeBox
- jp Func_214e8
+ jp BillsPCMenu
-Func_216be: ; 216be (8:56be)
+DisplayMonListMenu:
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
+ ld [wPrintItemPrices], a
ld [wListMenuID], a
inc a ; MONSTER_NAME
ld [wNameListType], a
- ld a, [wcc2b]
+ ld a, [wPartyAndBillsPCSavedMenuItem]
ld [wCurrentMenuItem], a
call DisplayListMenuID
ld a, [wCurrentMenuItem]
- ld [wcc2b], a
+ ld [wPartyAndBillsPCSavedMenuItem], a
ret
-BillsPCMenuText: ; 216e1 (8:56e1)
+BillsPCMenuText:
db "WITHDRAW ", $4a
next "DEPOSIT ", $4a
next "RELEASE ", $4a
next "CHANGE BOX"
-IF DEF(_YELLOW)
- next "PRINT BOX"
-ENDC
next "SEE YA!"
db "@"
-BoxNoPCText: ; 21713 (8:5713)
+BoxNoPCText:
db "BOX No.@"
-Func_2171b:: ; 2171b (8:571b)
+KnowsHMMove::
+; returns whether mon with party index [wWhichPokemon] knows an HM move
ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
- jr .asm_21729 ; 0x21721 $6
+ jr .next
+; unreachable
ld hl, wBoxMon1Moves
ld bc, wBoxMon2 - wBoxMon1
-.asm_21729
+.next
ld a, [wWhichPokemon]
call AddNTimes
ld b, NUM_MOVES
-.asm_21731
+.loop
ld a, [hli]
push hl
push bc
@@ -375,11 +372,11 @@ Func_2171b:: ; 2171b (8:571b)
pop hl
ret c
dec b
- jr nz, .asm_21731 ; 0x21741 $ee
+ jr nz, .loop
and a
ret
-HMMoveArray: ; 21745 (8:5745)
+HMMoveArray:
db CUT
db FLY
db SURF
@@ -387,72 +384,72 @@ HMMoveArray: ; 21745 (8:5745)
db FLASH
db -1
-Func_2174b: ; 2174b (8:574b)
- hlCoord 9, 10
- ld b, $6
- ld c, $9
+DisplayDepositWithdrawMenu:
+ coord hl, 9, 10
+ ld b, 6
+ ld c, 9
call TextBoxBorder
- ld a, [wccd3]
- and a
+ ld a, [wParentMenuItem]
+ and a ; was the Deposit or Withdraw item selected in the parent menu?
ld de, DepositPCText
- jr nz, .asm_21761
+ jr nz, .next
ld de, WithdrawPCText
-.asm_21761
- hlCoord 11, 12
+.next
+ coord hl, 11, 12
call PlaceString
- hlCoord 11, 14
+ coord hl, 11, 14
ld de, StatsCancelPCText
call PlaceString
ld hl, wTopMenuItemY
- ld a, $c
- ld [hli], a
- ld a, $a
- ld [hli], a
+ ld a, 12
+ ld [hli], a ; wTopMenuItemY
+ ld a, 10
+ ld [hli], a ; wTopMenuItemX
xor a
- ld [hli], a
+ ld [hli], a ; wCurrentMenuItem
inc hl
- ld a, $2
- ld [hli], a
- ld a, $3
- ld [hli], a
+ ld a, 2
+ ld [hli], a ; wMaxMenuItem
+ ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
- ld [hl], a
+ ld [hl], a ; wLastMenuItem
ld hl, wListScrollOffset
- ld [hli], a
- ld [hl], a
+ ld [hli], a ; wListScrollOffset
+ ld [hl], a ; wMenuWatchMovingOutOfBounds
ld [wPlayerMonNumber], a
- ld [wcc2b], a
-.asm_2178f
+ ld [wPartyAndBillsPCSavedMenuItem], a
+.loop
call HandleMenuInput
- bit 1, a
- jr nz, .asm_2179f
+ bit 1, a ; pressed B?
+ jr nz, .exit
ld a, [wCurrentMenuItem]
and a
- jr z, .asm_217a1
+ jr z, .choseDepositWithdraw
dec a
- jr z, .asm_217a3
-.asm_2179f
+ jr z, .viewStats
+.exit
and a
ret
-.asm_217a1
+.choseDepositWithdraw
scf
ret
-.asm_217a3
+.viewStats
call SaveScreenTilesToBuffer1
- ld a, [wccd3]
+ ld a, [wParentMenuItem]
and a
- ld a, $0
- jr nz, .asm_217b0
- ld a, $2
-.asm_217b0
- ld [wcc49], a
+ ld a, PLAYER_PARTY_DATA
+ jr nz, .next2
+ ld a, BOX_DATA
+.next2
+ ld [wMonDataLocation], a
predef StatusScreen
predef StatusScreen2
call LoadScreenTilesFromBuffer1
call ReloadTilesetTilePatterns
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call LoadGBPal
- jr .asm_2178f
+ jr .loop
DepositPCText: db "DEPOSIT@"
WithdrawPCText: db "WITHDRAW@"
@@ -460,91 +457,89 @@ StatsCancelPCText:
db "STATS"
next "CANCEL@"
-SwitchOnText: ; 0x217e9
+SwitchOnText:
TX_FAR _SwitchOnText
db "@"
-WhatText: ; 0x217ee
+WhatText:
TX_FAR _WhatText
db "@"
-DepositWhichMonText: ; 0x217f3
+DepositWhichMonText:
TX_FAR _DepositWhichMonText
db "@"
-MonWasStoredText: ; 0x217f8
+MonWasStoredText:
TX_FAR _MonWasStoredText
db "@"
-CantDepositLastMonText: ; 0x217fd
+CantDepositLastMonText:
TX_FAR _CantDepositLastMonText
db "@"
-BoxFullText: ; 0x21802
+BoxFullText:
TX_FAR _BoxFullText
db "@"
-MonIsTakenOutText: ; 0x21807
+MonIsTakenOutText:
TX_FAR _MonIsTakenOutText
db "@"
-NoMonText: ; 0x2180c
+NoMonText:
TX_FAR _NoMonText
db "@"
-CantTakeMonText: ; 0x21811
+CantTakeMonText:
TX_FAR _CantTakeMonText
db "@"
-ReleaseWhichMonText: ; 0x21816
+ReleaseWhichMonText:
TX_FAR _ReleaseWhichMonText
db "@"
-OnceReleasedText: ; 0x2181b
+OnceReleasedText:
TX_FAR _OnceReleasedText
db "@"
-MonWasReleasedText: ; 0x21820
+MonWasReleasedText:
TX_FAR _MonWasReleasedText
db "@"
-CableClubLeftGameboy:: ; 5824 (8:5825)
+CableClubLeftGameboy::
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
ret z
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
cp SPRITE_FACING_RIGHT
ret nz
- ld a, [W_CURMAP]
- cp BATTLE_CENTER
+ ld a, [wCurMap]
+ cp TRADE_CENTER
ld a, LINK_STATE_START_TRADE
- jr z, .asm_2183a
+ jr z, .next
inc a ; LINK_STATE_START_BATTLE
-.asm_2183a
+.next
ld [wLinkState], a
call EnableAutoTextBoxDrawing
- ld a, $22 ; JustAMomentText
- jp PrintPredefTextID
+ tx_pre_jump JustAMomentText
-CableClubRightGameboy:: ; 5845 (8:5845)
+CableClubRightGameboy::
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
ret z
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
cp SPRITE_FACING_LEFT
ret nz
- ld a, [W_CURMAP]
- cp BATTLE_CENTER
+ ld a, [wCurMap]
+ cp TRADE_CENTER
ld a, LINK_STATE_START_TRADE
- jr z, .asm_2185a
+ jr z, .next
inc a ; LINK_STATE_START_BATTLE
-.asm_2185a
+.next
ld [wLinkState], a
call EnableAutoTextBoxDrawing
- ld a, $22 ; JustAMomentText
- jp PrintPredefTextID
+ tx_pre_jump JustAMomentText
-JustAMomentText:: ; 21865 (8:5865)
+JustAMomentText::
TX_FAR _JustAMomentText
db "@"
@@ -552,9 +547,8 @@ JustAMomentText:: ; 21865 (8:5865)
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
- ld a, $23
- jp PrintPredefTextID
+ tx_pre_jump OpenBillsPCText
-PredefText23:: ; 21878 (8:5878)
+OpenBillsPCText::
db $FD ; FuncTX_BillsPC
diff --git a/engine/menu/diploma.asm b/engine/menu/diploma.asm
index 1624ed70..09ba123e 100755
--- a/engine/menu/diploma.asm
+++ b/engine/menu/diploma.asm
@@ -1,4 +1,4 @@
-DisplayDiploma: ; 566e2 (15:66e2)
+DisplayDiploma:
call SaveScreenTilesToBuffer2
call GBPalWhiteOutWithDelay3
call ClearScreen
@@ -7,15 +7,15 @@ DisplayDiploma: ; 566e2 (15:66e2)
ld hl, wd730
set 6, [hl]
call DisableLCD
- ld hl, CircleTile ; $7d88
+ ld hl, CircleTile
ld de, vChars2 + $700
ld bc, $0010
ld a, BANK(CircleTile)
call FarCopyData2
- ld hl, wTileMap
- ld bc, $1012
+ coord hl, 0, 0
+ lb bc, 16, 18
predef Diploma_TextBoxBorder
- ld hl, DiplomaTextPointersAndCoords ; $6784
+ ld hl, DiplomaTextPointersAndCoords
ld c, $5
.asm_56715
push bc
@@ -32,31 +32,35 @@ DisplayDiploma: ; 566e2 (15:66e2)
inc hl
pop bc
dec c
- jr nz, .asm_56715 ; 0x56725 $ee
- hlCoord 10, 4
+ jr nz, .asm_56715
+ coord hl, 10, 4
ld de, wPlayerName
call PlaceString
- callba Func_44dd
+ callba DrawPlayerCharacter
+
+; Move the player 33 pixels right and set the priority bit so he appears
+; behind the background layer.
ld hl, wOAMBuffer + $01
- ld bc, $8028
-.asm_5673e
- ld a, [hl]
- add $21
+ lb bc, $80, $28
+.adjustPlayerGfxLoop
+ ld a, [hl] ; X
+ add 33
ld [hli], a
inc hl
ld a, b
- ld [hli], a
+ ld [hli], a ; attributes
inc hl
dec c
- jr nz, .asm_5673e ; 0x56747 $f5
+ jr nz, .adjustPlayerGfxLoop
+
call EnableLCD
callba LoadTrainerInfoTextBoxTiles
- ld b, $8
- call GoPAL_SET
+ ld b, SET_PAL_GENERIC
+ call RunPaletteCommand
call Delay3
call GBPalNormal
ld a, $90
- ld [$ff48], a
+ ld [rOBP0], a
call WaitForTextScrollButtonPress
ld hl, wd730
res 6, [hl]
@@ -65,27 +69,29 @@ DisplayDiploma: ; 566e2 (15:66e2)
call Delay3
jp GBPalNormal
-Func_56777: ; 56777 (15:6777)
+UnusedPlayerNameLengthFunc:
+; Unused function that does a calculation involving the length of the player's
+; name.
ld hl, wPlayerName
ld bc, $ff00
-.asm_5677d
+.loop
ld a, [hli]
- cp $50
+ cp "@"
ret z
dec c
- jr .asm_5677d ; 0x56782 $f9
+ jr .loop
-DiplomaTextPointersAndCoords: ; 56784 (15:6784)
+DiplomaTextPointersAndCoords:
dw DiplomaText
- dw wTileMap + $2d
+ dwCoord 5, 2
dw DiplomaPlayer
- dw wTileMap + $53
+ dwCoord 3, 4
dw DiplomaEmptyText
- dw wTileMap + $5f
+ dwCoord 15, 4
dw DiplomaCongrats
- dw wTileMap + $7a
+ dwCoord 2, 6
dw DiplomaGameFreak
- dw wTileMap + $149
+ dwCoord 9, 16
DiplomaText:
db $70,"Diploma",$70,"@"
diff --git a/engine/menu/draw_badges.asm b/engine/menu/draw_badges.asm
new file mode 100644
index 00000000..9e6262a0
--- /dev/null
+++ b/engine/menu/draw_badges.asm
@@ -0,0 +1,120 @@
+DrawBadges:
+; Draw 4x2 gym leader faces, with the faces replaced by
+; badges if they are owned. Used in the player status screen.
+
+; In Japanese versions, names are displayed above faces.
+; Instead of removing relevant code, the name graphics were erased.
+
+; Tile ids for face/badge graphics.
+ ld de, wBadgeOrFaceTiles
+ ld hl, .FaceBadgeTiles
+ ld bc, 8
+ call CopyData
+
+; Booleans for each badge.
+ ld hl, wTempObtainedBadgesBooleans
+ ld bc, 8
+ xor a
+ call FillMemory
+
+; Alter these based on owned badges.
+ ld de, wTempObtainedBadgesBooleans
+ ld hl, wBadgeOrFaceTiles
+ ld a, [wObtainedBadges]
+ ld b, a
+ ld c, 8
+.CheckBadge
+ srl b
+ jr nc, .NextBadge
+ ld a, [hl]
+ add 4 ; Badge graphics are after each face
+ ld [hl], a
+ ld a, 1
+ ld [de], a
+.NextBadge
+ inc hl
+ inc de
+ dec c
+ jr nz, .CheckBadge
+
+; Draw two rows of badges.
+ ld hl, wBadgeNumberTile
+ ld a, $d8 ; [1]
+ ld [hli], a
+ ld [hl], $60 ; First name
+
+ coord hl, 2, 11
+ ld de, wTempObtainedBadgesBooleans
+ call .DrawBadgeRow
+
+ coord hl, 2, 14
+ ld de, wTempObtainedBadgesBooleans + 4
+; call .DrawBadgeRow
+; ret
+
+.DrawBadgeRow
+; Draw 4 badges.
+
+ ld c, 4
+.DrawBadge
+ push de
+ push hl
+
+; Badge no.
+ ld a, [wBadgeNumberTile]
+ ld [hli], a
+ inc a
+ ld [wBadgeNumberTile], a
+
+; Names aren't printed if the badge is owned.
+ ld a, [de]
+ and a
+ ld a, [wBadgeNameTile]
+ jr nz, .SkipName
+ call .PlaceTiles
+ jr .PlaceBadge
+
+.SkipName
+ inc a
+ inc a
+ inc hl
+
+.PlaceBadge
+ ld [wBadgeNameTile], a
+ ld de, SCREEN_WIDTH - 1
+ add hl, de
+ ld a, [wBadgeOrFaceTiles]
+ call .PlaceTiles
+ add hl, de
+ call .PlaceTiles
+
+; Shift badge array back one byte.
+ push bc
+ ld hl, wBadgeOrFaceTiles + 1
+ ld de, wBadgeOrFaceTiles
+ ld bc, 8
+ call CopyData
+ pop bc
+
+ pop hl
+ ld de, 4
+ add hl, de
+
+ pop de
+ inc de
+ dec c
+ jr nz, .DrawBadge
+ ret
+
+.PlaceTiles
+ ld [hli], a
+ inc a
+ ld [hl], a
+ inc a
+ ret
+
+.FaceBadgeTiles
+ db $20, $28, $30, $38, $40, $48, $50, $58
+
+GymLeaderFaceAndBadgeTileGraphics:
+ INCBIN "gfx/badges.2bpp"
diff --git a/engine/menu/draw_start_menu.asm b/engine/menu/draw_start_menu.asm
new file mode 100644
index 00000000..4df9de27
--- /dev/null
+++ b/engine/menu/draw_start_menu.asm
@@ -0,0 +1,89 @@
+; function that displays the start menu
+DrawStartMenu:
+ CheckEvent EVENT_GOT_POKEDEX
+; menu with pokedex
+ coord hl, 10, 0
+ ld b,$0e
+ ld c,$08
+ jr nz,.drawTextBoxBorder
+; shorter menu if the player doesn't have the pokedex
+ coord hl, 10, 0
+ ld b,$0c
+ ld c,$08
+.drawTextBoxBorder
+ call TextBoxBorder
+ ld a,D_DOWN | D_UP | START | B_BUTTON | A_BUTTON
+ ld [wMenuWatchedKeys],a
+ ld a,$02
+ ld [wTopMenuItemY],a ; Y position of first menu choice
+ ld a,$0b
+ ld [wTopMenuItemX],a ; X position of first menu choice
+ ld a,[wBattleAndStartSavedMenuItem] ; remembered menu selection from last time
+ ld [wCurrentMenuItem],a
+ ld [wLastMenuItem],a
+ xor a
+ ld [wMenuWatchMovingOutOfBounds],a
+ ld hl,wd730
+ set 6,[hl] ; no pauses between printing each letter
+ coord hl, 12, 2
+ CheckEvent EVENT_GOT_POKEDEX
+; case for not having pokdex
+ ld a,$06
+ jr z,.storeMenuItemCount
+; case for having pokedex
+ ld de,StartMenuPokedexText
+ call PrintStartMenuItem
+ ld a,$07
+.storeMenuItemCount
+ ld [wMaxMenuItem],a ; number of menu items
+ ld de,StartMenuPokemonText
+ call PrintStartMenuItem
+ ld de,StartMenuItemText
+ call PrintStartMenuItem
+ ld de,wPlayerName ; player's name
+ call PrintStartMenuItem
+ ld a,[wd72e]
+ bit 6,a ; is the player using the link feature?
+; case for not using link feature
+ ld de,StartMenuSaveText
+ jr z,.printSaveOrResetText
+; case for using link feature
+ ld de,StartMenuResetText
+.printSaveOrResetText
+ call PrintStartMenuItem
+ ld de,StartMenuOptionText
+ call PrintStartMenuItem
+ ld de,StartMenuExitText
+ call PlaceString
+ ld hl,wd730
+ res 6,[hl] ; turn pauses between printing letters back on
+ ret
+
+StartMenuPokedexText:
+ db "POKéDEX@"
+
+StartMenuPokemonText:
+ db "POKéMON@"
+
+StartMenuItemText:
+ db "ITEM@"
+
+StartMenuSaveText:
+ db "SAVE@"
+
+StartMenuResetText:
+ db "RESET@"
+
+StartMenuExitText:
+ db "EXIT@"
+
+StartMenuOptionText:
+ db "OPTION@"
+
+PrintStartMenuItem:
+ push hl
+ call PlaceString
+ pop hl
+ ld de,SCREEN_WIDTH * 2
+ add hl,de
+ ret
diff --git a/engine/menu/league_pc.asm b/engine/menu/league_pc.asm
index a6dd7021..170c0ef3 100755
--- a/engine/menu/league_pc.asm
+++ b/engine/menu/league_pc.asm
@@ -1,4 +1,4 @@
-PKMNLeaguePC: ; 0x7657e
+PKMNLeaguePC:
ld hl, AccessedHoFPCText
call PrintText
ld hl, wd730
@@ -10,33 +10,35 @@ PKMNLeaguePC: ; 0x7657e
push af
xor a
ld [hTilesetType], a
- ld [W_SPRITEFLIPPED], a
+ ld [wSpriteFlipped], a
ld [wUpdateSpritesEnabled], a
- ld [wTrainerScreenX], a
- ld [wcd42], a
- ld a, [wd5a2]
+ ld [wHoFTeamIndex2], a
+ ld [wHoFTeamNo], a
+ ld a, [wNumHoFTeams]
ld b, a
- cp NUM_HOF_TEAMS + 1
- jr c, .first
- ld b, NUM_HOF_TEAMS
+ cp HOF_TEAM_CAPACITY + 1
+ jr c, .loop
+; If the total number of hall of fame teams is greater than the storage
+; capacity, then calculate the number of the first team that is still recorded.
+ ld b, HOF_TEAM_CAPACITY
sub b
- ld [wcd42], a
-.first
- ld hl, wcd42
+ ld [wHoFTeamNo], a
+.loop
+ ld hl, wHoFTeamNo
inc [hl]
push bc
- ld a, [wTrainerScreenX]
- ld [wWhichTrade], a
+ ld a, [wHoFTeamIndex2]
+ ld [wHoFTeamIndex], a
callba LoadHallOfFameTeams
- call Func_765e5
+ call LeaguePCShowTeam
pop bc
- jr c, .second
- ld hl, wTrainerScreenX
+ jr c, .doneShowingTeams
+ ld hl, wHoFTeamIndex2
inc [hl]
ld a, [hl]
cp b
- jr nz, .first
-.second
+ jr nz, .loop
+.doneShowingTeams
pop af
ld [hTilesetType], a
pop af
@@ -45,14 +47,14 @@ PKMNLeaguePC: ; 0x7657e
res 6, [hl]
call GBPalWhiteOutWithDelay3
call ClearScreen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
jp GBPalNormal
-Func_765e5: ; 765e5 (1d:65e5)
+LeaguePCShowTeam:
ld c, PARTY_LENGTH
.loop
push bc
- call Func_76610
+ call LeaguePCShowMon
call WaitForTextScrollButtonPress
ld a, [hJoyHeld]
bit 1, a
@@ -75,46 +77,44 @@ Func_765e5: ; 765e5 (1d:65e5)
scf
ret
-Func_76610: ; 76610 (1d:6610)
+LeaguePCShowMon:
call GBPalWhiteOutWithDelay3
call ClearScreen
ld hl, wHallOfFame
ld a, [hli]
- ld [wWhichTrade], a
+ ld [wHoFMonSpecies], a
ld [wcf91], a
ld [wd0b5], a
ld [wBattleMonSpecies2], a
- ld [wcf1d], a
+ ld [wWholeScreenPaletteMonSpecies], a
ld a, [hli]
- ld [wTrainerFacingDirection], a
+ ld [wHoFMonLevel], a
ld de, wcd6d
- ld bc, $000B
+ ld bc, NAME_LENGTH
call CopyData
- ld b, $0B
+ ld b, SET_PAL_POKEMON_WHOLE_SCREEN
ld c, 0
- call GoPAL_SET
- hlCoord 12, 5
+ call RunPaletteCommand
+ coord hl, 12, 5
call GetMonHeader
call LoadFrontSpriteByMonIndex
call GBPalNormal
- hlCoord 0, 13
+ coord hl, 0, 13
ld b, 2
ld c, $12
call TextBoxBorder
- hlCoord 1, 15
+ coord hl, 1, 15
ld de, HallOfFameNoText
call PlaceString
- hlCoord 16, 15
- ld de, wcd42
- ld bc, $0103
+ coord hl, 16, 15
+ ld de, wHoFTeamNo
+ lb bc, 1, 3
call PrintNumber
- ld b, BANK(Func_702f0)
- ld hl, Func_702f0
- jp Bankswitch
+ jpba HoFDisplayMonInfo
-HallOfFameNoText: ; 76670 (1d:6670)
+HallOfFameNoText:
db "HALL OF FAME No @"
-AccessedHoFPCText: ; 76683 (1d:6683)
+AccessedHoFPCText:
TX_FAR _AccessedHoFPCText
db "@"
diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm
index 756c7755..cd4198b6 100755
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -1,58 +1,58 @@
-MainMenu: ; 5af2 (1:5af2)
+MainMenu:
; Check save file
- call Func_5bff
+ call InitOptions
xor a
- ld [wd08a],a
+ ld [wOptionsInitialized],a
inc a
- ld [wd088],a
- call Func_609e
- jr nc,.next0
+ ld [wSaveFileStatus],a
+ call CheckForPlayerNameInSRAM
+ jr nc,.mainMenuLoop
- ; Predef 52 loads the save from SRAM to RAM
predef LoadSAV
-.next0
+.mainMenuLoop
ld c,20
call DelayFrames
xor a ; LINK_STATE_NONE
ld [wLinkState],a
- ld hl,wcc2b
+ ld hl,wPartyAndBillsPCSavedMenuItem
ld [hli],a
ld [hli],a
ld [hli],a
ld [hl],a
- ld [W_ANIMATIONID],a
+ ld [wDefaultMap],a
ld hl,wd72e
res 6,[hl]
call ClearScreen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call LoadTextBoxTilePatterns
call LoadFontTilePatterns
ld hl,wd730
set 6,[hl]
- ld a,[wd088]
+ ld a,[wSaveFileStatus]
cp a,1
- jr z,.next1
- hlCoord 0, 0
+ jr z,.noSaveFile
+; there's a save file
+ coord hl, 0, 0
ld b,6
ld c,13
call TextBoxBorder
- hlCoord 2, 2
+ coord hl, 2, 2
ld de,ContinueText
call PlaceString
jr .next2
-.next1
- hlCoord 0, 0
+.noSaveFile
+ coord hl, 0, 0
ld b,4
ld c,13
call TextBoxBorder
- hlCoord 2, 2
+ coord hl, 2, 2
ld de,NewGameText
call PlaceString
.next2
ld hl,wd730
res 6,[hl]
- call UpdateSprites ; OAM?
+ call UpdateSprites
xor a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
@@ -61,36 +61,38 @@ MainMenu: ; 5af2 (1:5af2)
ld [wTopMenuItemX],a
inc a
ld [wTopMenuItemY],a
- ld a,$B
+ ld a,A_BUTTON | B_BUTTON | START
ld [wMenuWatchedKeys],a
- ld a,[wd088]
+ ld a,[wSaveFileStatus]
ld [wMaxMenuItem],a
call HandleMenuInput
- bit 1,a
- jp nz,LoadTitlescreenGraphics ; load title screen (gfx and arrangement)
+ bit 1,a ; pressed B?
+ jp nz,DisplayTitleScreen ; if so, go back to the title screen
ld c,20
call DelayFrames
ld a,[wCurrentMenuItem]
ld b,a
- ld a,[wd088]
+ ld a,[wSaveFileStatus]
cp a,2
- jp z,.next3
- inc b ; adjust MenuArrow_Counter
-.next3
+ jp z,.skipInc
+; If there's no save file, increment the current menu item so that the numbers
+; are the same whether or not there's a save file.
+ inc b
+.skipInc
ld a,b
and a
- jr z,.next4 ; if press_A on Continue
+ jr z,.choseContinue
cp a,1
- jp z,Func_5d52 ; if press_A on NewGame
- call DisplayOptionMenu ; if press_a on Options
+ jp z,StartNewGame
+ call DisplayOptionMenu
ld a,1
- ld [wd08a],a
- jp .next0
-.next4
- call ContinueGame
- ld hl,wd126
+ ld [wOptionsInitialized],a
+ jp .mainMenuLoop
+.choseContinue
+ call DisplayContinueGameInfo
+ ld hl,wCurrentMapScriptFlags
set 5,[hl]
-.next6
+.inputLoop
xor a
ld [hJoyPressed],a
ld [hJoyReleased],a
@@ -98,21 +100,21 @@ MainMenu: ; 5af2 (1:5af2)
call Joypad
ld a,[hJoyHeld]
bit 0,a
- jr nz,.next5
+ jr nz,.pressedA
bit 1,a
- jp nz,.next0
- jr .next6
-.next5
+ jp nz,.mainMenuLoop ; pressed B
+ jr .inputLoop
+.pressedA
call GBPalWhiteOutWithDelay3
call ClearScreen
- ld a,4
- ld [wd52a],a
+ ld a,PLAYER_DIR_DOWN
+ ld [wPlayerDirection],a
ld c,10
call DelayFrames
- ld a,[wd5a2]
+ ld a,[wNumHoFTeams]
and a
jp z,SpecialEnterMap
- ld a,[W_CURMAP] ; map ID
+ ld a,[wCurMap] ; map ID
cp a,HALL_OF_FAME
jp nz,SpecialEnterMap
xor a
@@ -121,16 +123,17 @@ MainMenu: ; 5af2 (1:5af2)
set 2,[hl] ; fly warp or dungeon warp
call SpecialWarpIn
jp SpecialEnterMap
-Func_5bff: ; 5bff (1:5bff)
- ld a,1
- ld [wd358],a
- ld a,3
- ld [W_OPTIONS],a
+
+InitOptions:
+ ld a,1 ; no delay
+ ld [wLetterPrintingDelayFlags],a
+ ld a,3 ; medium speed
+ ld [wOptions],a
ret
-LinkMenu: ; 5c0a (1:5c0a)
+LinkMenu:
xor a
- ld [wd358], a
+ ld [wLetterPrintingDelayFlags], a
ld hl, wd72e
set 6, [hl]
ld hl, TextTerminator_6b20
@@ -138,16 +141,16 @@ LinkMenu: ; 5c0a (1:5c0a)
call SaveScreenTilesToBuffer1
ld hl, WhereWouldYouLikeText
call PrintText
- hlCoord 5, 5
+ coord hl, 5, 5
ld b, $6
ld c, $d
call TextBoxBorder
call UpdateSprites
- hlCoord 7, 7
- ld de, TradeCenterText
+ coord hl, 7, 7
+ ld de, CableClubOptionsText
call PlaceString
xor a
- ld [wcd37], a
+ ld [wUnusedCD37], a
ld [wd72d], a
ld hl, wTopMenuItemY
ld a, $7
@@ -160,7 +163,8 @@ LinkMenu: ; 5c0a (1:5c0a)
ld a, $2
ld [hli], a
inc a
- ld [hli], a
+ ; ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
ld [hl], a
.waitForInputLoop
@@ -208,7 +212,7 @@ LinkMenu: ; 5c0a (1:5c0a)
ld a, b
ld [wLinkMenuSelectionSendBuffer], a
and $3
- ld [wCurrentMenuItem], a ; wCurrentMenuItem
+ ld [wCurrentMenuItem], a
.doneChoosingMenuSelection
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
@@ -254,28 +258,28 @@ LinkMenu: ; 5c0a (1:5c0a)
ld [wWalkBikeSurfState], a ; start walking
ld a, [wCurrentMenuItem]
and a
- ld a, TRADE_CENTER
+ ld a, COLOSSEUM
jr nz, .next
- ld a, BATTLE_CENTER
+ ld a, TRADE_CENTER
.next
ld [wd72d], a
ld hl, PleaseWaitText
call PrintText
- ld c, $32
+ ld c, 50
call DelayFrames
ld hl, wd732
res 1, [hl]
- ld a, [W_ANIMATIONID]
+ ld a, [wDefaultMap]
ld [wDestinationMap], a
call SpecialWarpIn
- ld c, $14
+ ld c, 20
call DelayFrames
xor a
ld [wMenuJoypadPollCount], a
ld [wSerialExchangeNybbleSendData], a
inc a ; LINK_STATE_IN_CABLE_CLUB
ld [wLinkState], a
- ld [wcc47], a
+ ld [wEnteringCableClub], a
jr SpecialEnterMap
.choseCancel
xor a
@@ -288,27 +292,27 @@ LinkMenu: ; 5c0a (1:5c0a)
res 6, [hl]
ret
-WhereWouldYouLikeText: ; 5d43 (1:5d43)
+WhereWouldYouLikeText:
TX_FAR _WhereWouldYouLikeText
db "@"
-PleaseWaitText: ; 5d48 (1:5d48)
+PleaseWaitText:
TX_FAR _PleaseWaitText
db "@"
-LinkCanceledText: ; 5d4d (1:5d4d)
+LinkCanceledText:
TX_FAR _LinkCanceledText
db "@"
-Func_5d52: ; 5d52 (1:5d52)
+StartNewGame:
ld hl, wd732
res 1, [hl]
call OakSpeech
- ld c, $14
+ ld c, 20
call DelayFrames
; enter map after using a special warp or loading the game from the main menu
-SpecialEnterMap: ; 5d5f (1:5d5f)
+SpecialEnterMap:
xor a
ld [hJoyPressed], a
ld [hJoyHeld], a
@@ -319,144 +323,144 @@ SpecialEnterMap: ; 5d5f (1:5d5f)
call ResetPlayerSpriteData
ld c, 20
call DelayFrames
- ld a, [wcc47]
+ ld a, [wEnteringCableClub]
and a
ret nz
jp EnterMap
-ContinueText: ; 5d7e (1:5d7e)
+ContinueText:
db "CONTINUE", $4e
-NewGameText: ; 5d87 (1:5d87)
- db "NEW GAME", $4e
- db "OPTION@"
+NewGameText:
+ db "NEW GAME"
+ next "OPTION@"
-TradeCenterText: ; 5d97 (1:5d97)
- db "TRADE CENTER", $4e
- db "COLOSSEUM", $4e
- db "CANCEL@"
+CableClubOptionsText:
+ db "TRADE CENTER"
+ next "COLOSSEUM"
+ next "CANCEL@"
-ContinueGame: ; 5db5 (1:5db5)
+DisplayContinueGameInfo:
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- hlCoord 4, 7
- ld b, $8
- ld c, $e
+ ld [H_AUTOBGTRANSFERENABLED], a
+ coord hl, 4, 7
+ ld b, 8
+ ld c, 14
call TextBoxBorder
- hlCoord 5, 9
+ coord hl, 5, 9
ld de, SaveScreenInfoText
call PlaceString
- hlCoord 12, 9
- ld de, wPlayerName ; wd158
+ coord hl, 12, 9
+ ld de, wPlayerName
call PlaceString
- hlCoord 17, 11
- call Func_5e2f
- hlCoord 16, 13
- call Func_5e42
- hlCoord 13, 15
- call Func_5e55
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld c, $1e
+ coord hl, 17, 11
+ call PrintNumBadges
+ coord hl, 16, 13
+ call PrintNumOwnedMons
+ coord hl, 13, 15
+ call PrintPlayTime
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld c, 30
jp DelayFrames
-PrintSaveScreenText: ; 5def (1:5def)
+PrintSaveScreenText:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, wTileMap + $4
+ coord hl, 4, 0
ld b, $8
ld c, $e
call TextBoxBorder
call LoadTextBoxTilePatterns
call UpdateSprites
- ld hl, wTileMap + $2d
+ coord hl, 5, 2
ld de, SaveScreenInfoText
call PlaceString
- ld hl, wTileMap + $34
+ coord hl, 12, 2
ld de, wPlayerName
call PlaceString
- ld hl, wTileMap + $61
- call Func_5e2f
- ld hl, wTileMap + $88
- call Func_5e42
- ld hl, wTileMap + $ad
- call Func_5e55
+ coord hl, 17, 4
+ call PrintNumBadges
+ coord hl, 16, 6
+ call PrintNumOwnedMons
+ coord hl, 13, 8
+ call PrintPlayTime
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
- ld c, $1e
+ ld c, 30
jp DelayFrames
-Func_5e2f: ; 5e2f (1:5e2f)
+PrintNumBadges:
push hl
- ld hl, W_OBTAINEDBADGES
+ ld hl, wObtainedBadges
ld b, $1
call CountSetBits
pop hl
- ld de, wd11e
- ld bc, $102
+ ld de, wNumSetBits
+ lb bc, 1, 2
jp PrintNumber
-Func_5e42: ; 5e42 (1:5e42)
+PrintNumOwnedMons:
push hl
- ld hl, wPokedexOwned ; wPokedexOwned
+ ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
pop hl
- ld de, wd11e
- ld bc, $103
+ ld de, wNumSetBits
+ lb bc, 1, 3
jp PrintNumber
-Func_5e55: ; 5e55 (1:5e55)
- ld de, W_PLAYTIMEHOURS + 1
- ld bc, $103
+PrintPlayTime:
+ ld de, wPlayTimeHours
+ lb bc, 1, 3
call PrintNumber
ld [hl], $6d
inc hl
- ld de, W_PLAYTIMEMINUTES + 1
- ld bc, $8102
+ ld de, wPlayTimeMinutes
+ lb bc, LEADING_ZEROES | 1, 2
jp PrintNumber
-SaveScreenInfoText: ; 5e6a (1:5e6a)
+SaveScreenInfoText:
db "PLAYER"
next "BADGES "
next "#DEX "
next "TIME@"
-DisplayOptionMenu: ; 5e8a (1:5e8a)
- hlCoord 0, 0
+DisplayOptionMenu:
+ coord hl, 0, 0
ld b,3
ld c,18
call TextBoxBorder
- hlCoord 0, 5
+ coord hl, 0, 5
ld b,3
ld c,18
call TextBoxBorder
- hlCoord 0, 10
+ coord hl, 0, 10
ld b,3
ld c,18
call TextBoxBorder
- hlCoord 1, 1
+ coord hl, 1, 1
ld de,TextSpeedOptionText
call PlaceString
- hlCoord 1, 6
+ coord hl, 1, 6
ld de,BattleAnimationOptionText
call PlaceString
- hlCoord 1, 11
+ coord hl, 1, 11
ld de,BattleStyleOptionText
call PlaceString
- hlCoord 2, 16
+ coord hl, 2, 16
ld de,OptionMenuCancelText
call PlaceString
xor a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
inc a
- ld [wd358],a
- ld [wTrainerScreenY],a
+ ld [wLetterPrintingDelayFlags],a
+ ld [wUnusedCD40],a
ld a,3 ; text speed cursor Y coordinate
ld [wTopMenuItemY],a
call SetCursorPositionsFromOptions
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
ld [wTopMenuItemX],a
ld a,$01
ld [H_AUTOBGTRANSFERENABLED],a ; enable auto background transfer
@@ -468,7 +472,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
call JoypadLowSensitivity
ld a,[hJoy5]
ld b,a
- and a,%11111011 ; any key besides select pressed?
+ and a,A_BUTTON | B_BUTTON | START | D_RIGHT | D_LEFT | D_UP | D_DOWN ; any key besides select pressed?
jr z,.getJoypadStateLoop
bit 1,b ; B button pressed?
jr nz,.exitMenu
@@ -480,8 +484,8 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
cp a,16 ; is the cursor on Cancel?
jr nz,.loop
.exitMenu
- ld a,(SFX_02_40 - SFX_Headers_02) / 3
- call PlaySound ; play sound
+ ld a,SFX_PRESS_AB
+ call PlaySound
ret
.eraseOldMenuCursor
ld [wTopMenuItemX],a
@@ -506,7 +510,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
.downPressed
cp a,16
ld b,-13
- ld hl,wWhichTrade
+ ld hl,wOptionsTextSpeedCursorX
jr z,.updateMenuVariables
ld b,5
cp a,3
@@ -521,7 +525,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
.upPressed
cp a,8
ld b,-5
- ld hl,wWhichTrade
+ ld hl,wOptionsTextSpeedCursorX
jr z,.updateMenuVariables
cp a,13
inc hl
@@ -540,17 +544,17 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
call PlaceUnfilledArrowMenuCursor
jp .loop
.cursorInBattleAnimation
- ld a,[wTrainerEngageDistance] ; battle animation cursor X coordinate
+ ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
xor a,$0b ; toggle between 1 and 10
- ld [wTrainerEngageDistance],a
+ ld [wOptionsBattleAnimCursorX],a
jp .eraseOldMenuCursor
.cursorInBattleStyle
- ld a,[wTrainerFacingDirection] ; battle style cursor X coordinate
+ ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
xor a,$0b ; toggle between 1 and 10
- ld [wTrainerFacingDirection],a
+ ld [wOptionsBattleStyleCursorX],a
jp .eraseOldMenuCursor
.pressedLeftInTextSpeed
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
cp a,1
jr z,.updateTextSpeedXCoord
cp a,7
@@ -561,7 +565,7 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
sub a,7
jr .updateTextSpeedXCoord
.pressedRightInTextSpeed
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
cp a,14
jr z,.updateTextSpeedXCoord
cp a,7
@@ -571,28 +575,28 @@ DisplayOptionMenu: ; 5e8a (1:5e8a)
.fromFastToMedium
add a,6
.updateTextSpeedXCoord
- ld [wWhichTrade],a ; text speed cursor X coordinate
+ ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate
jp .eraseOldMenuCursor
-TextSpeedOptionText: ; 5fc0 (1:5fc0)
+TextSpeedOptionText:
db "TEXT SPEED"
next " FAST MEDIUM SLOW@"
-BattleAnimationOptionText: ; 5fde (1:5fde)
+BattleAnimationOptionText:
db "BATTLE ANIMATION"
next " ON OFF@"
-BattleStyleOptionText: ; 5ffd (1:5ffd)
+BattleStyleOptionText:
db "BATTLE STYLE"
next " SHIFT SET@"
-OptionMenuCancelText: ; 6018 (1:6018)
+OptionMenuCancelText:
db "CANCEL@"
; sets the options variable according to the current placement of the menu cursors in the options menu
-SetOptionsFromCursorPositions: ; 601f (1:601f)
+SetOptionsFromCursorPositions:
ld hl,TextSpeedOptionData
- ld a,[wWhichTrade] ; text speed cursor X coordinate
+ ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
ld c,a
.loop
ld a,[hli]
@@ -603,7 +607,7 @@ SetOptionsFromCursorPositions: ; 601f (1:601f)
.textSpeedMatchFound
ld a,[hl]
ld d,a
- ld a,[wTrainerEngageDistance] ; battle animation cursor X coordinate
+ ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
dec a
jr z,.battleAnimationOn
.battleAnimationOff
@@ -612,7 +616,7 @@ SetOptionsFromCursorPositions: ; 601f (1:601f)
.battleAnimationOn
res 7,d
.checkBattleStyle
- ld a,[wTrainerFacingDirection] ; battle style cursor X coordinate
+ ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
dec a
jr z,.battleStyleShift
.battleStyleSet
@@ -622,13 +626,13 @@ SetOptionsFromCursorPositions: ; 601f (1:601f)
res 6,d
.storeOptions
ld a,d
- ld [W_OPTIONS],a
+ ld [wOptions],a
ret
; reads the options variable and places menu cursors in the correct positions within the options menu
-SetCursorPositionsFromOptions: ; 604c (1:604c)
+SetCursorPositionsFromOptions:
ld hl,TextSpeedOptionData + 1
- ld a,[W_OPTIONS]
+ ld a,[wOptions]
ld c,a
and a,$3f
push bc
@@ -637,27 +641,27 @@ SetCursorPositionsFromOptions: ; 604c (1:604c)
pop bc
dec hl
ld a,[hl]
- ld [wWhichTrade],a ; text speed cursor X coordinate
- hlCoord 0, 3
+ ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate
+ coord hl, 0, 3
call .placeUnfilledRightArrow
sla c
ld a,1 ; On
jr nc,.storeBattleAnimationCursorX
ld a,10 ; Off
.storeBattleAnimationCursorX
- ld [wTrainerEngageDistance],a ; battle animation cursor X coordinate
- hlCoord 0, 8
+ ld [wOptionsBattleAnimCursorX],a ; battle animation cursor X coordinate
+ coord hl, 0, 8
call .placeUnfilledRightArrow
sla c
ld a,1
jr nc,.storeBattleStyleCursorX
ld a,10
.storeBattleStyleCursorX
- ld [wTrainerFacingDirection],a ; battle style cursor X coordinate
- hlCoord 0, 13
+ ld [wOptionsBattleStyleCursorX],a ; battle style cursor X coordinate
+ coord hl, 0, 13
call .placeUnfilledRightArrow
; cursor in front of Cancel
- hlCoord 0, 16
+ coord hl, 0, 16
ld a,1
.placeUnfilledRightArrow
ld e,a
@@ -670,35 +674,39 @@ SetCursorPositionsFromOptions: ; 604c (1:604c)
; Format:
; 00: X coordinate of menu cursor
; 01: delay after printing a letter (in frames)
-TextSpeedOptionData: ; 6096 (1:6096)
+TextSpeedOptionData:
db 14,5 ; Slow
db 7,3 ; Medium
db 1,1 ; Fast
db 7 ; default X coordinate (Medium)
db $ff ; terminator
-Func_609e: ; 609e (1:609e)
- ld a, $a
- ld [$0], a
+CheckForPlayerNameInSRAM:
+; Check if the player name data in SRAM has a string terminator character
+; (indicating that a name may have been saved there) and return whether it does
+; in carry.
+ ld a, SRAM_ENABLE
+ ld [MBC1SRamEnable], a
ld a, $1
- ld [$6000], a
- ld [$4000], a
- ld b, $b
- ld hl, $a598
-.asm_60b0
+ ld [MBC1SRamBankingMode], a
+ ld [MBC1SRamBank], a
+ ld b, NAME_LENGTH
+ ld hl, sPlayerName
+.loop
ld a, [hli]
- cp $50
- jr z, .asm_60c1
+ cp "@"
+ jr z, .found
dec b
- jr nz, .asm_60b0
+ jr nz, .loop
+; not found
xor a
- ld [$0], a
- ld [$6000], a
+ ld [MBC1SRamEnable], a
+ ld [MBC1SRamBankingMode], a
and a
ret
-.asm_60c1
+.found
xor a
- ld [$0], a
- ld [$6000], a
+ ld [MBC1SRamEnable], a
+ ld [MBC1SRamBankingMode], a
scf
ret
diff --git a/engine/menu/naming_screen.asm b/engine/menu/naming_screen.asm
index df862d69..2628da48 100755
--- a/engine/menu/naming_screen.asm
+++ b/engine/menu/naming_screen.asm
@@ -1,131 +1,131 @@
-AskName: ; 64eb (1:64eb)
+AskName:
call SaveScreenTilesToBuffer1
call GetPredefRegisters
push hl
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
dec a
- ld hl, wTileMap
- ld b, $4
- ld c, $b
- call z, ClearScreenArea ; only if in wild batle
+ coord hl, 0, 0
+ ld b, 4
+ ld c, 11
+ call z, ClearScreenArea ; only if in wild battle
ld a, [wcf91]
ld [wd11e], a
call GetMonName
ld hl, DoYouWantToNicknameText
call PrintText
- hlCoord 14, 7
- ld bc, $80f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID
pop hl
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_654c
+ jr nz, .declinedNickname
ld a, [wUpdateSpritesEnabled]
push af
xor a
ld [wUpdateSpritesEnabled], a
push hl
- ld a, $2
- ld [wd07d], a
+ ld a, NAME_MON_SCREEN
+ ld [wNamingScreenType], a
call DisplayNamingScreen
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
- jr nz, .asm_653e
+ jr nz, .inBattle
call ReloadMapSpriteTilePatterns
-.asm_653e
+.inBattle
call LoadScreenTilesFromBuffer1
pop hl
pop af
ld [wUpdateSpritesEnabled], a
ld a, [wcf4b]
- cp $50
+ cp "@"
ret nz
-.asm_654c
+.declinedNickname
ld d, h
ld e, l
ld hl, wcd6d
- ld bc, $000b
+ ld bc, NAME_LENGTH
jp CopyData
-DoYouWantToNicknameText: ; 0x6557
+DoYouWantToNicknameText:
TX_FAR _DoYouWantToNicknameText
db "@"
-Func_655c: ; 655c (1:655c)
- ld hl, wHPBarMaxHP
+DisplayNameRaterScreen:
+ ld hl, wBuffer
xor a
ld [wUpdateSpritesEnabled], a
- ld a, $2
- ld [wd07d], a
+ ld a, NAME_MON_SCREEN
+ ld [wNamingScreenType], a
call DisplayNamingScreen
call GBPalWhiteOutWithDelay3
call RestoreScreenTilesAndReloadTilePatterns
call LoadGBPal
ld a, [wcf4b]
- cp $50
- jr z, .asm_6594
+ cp "@"
+ jr z, .playerCancelled
ld hl, wPartyMonNicks
- ld bc, $b
+ ld bc, NAME_LENGTH
ld a, [wWhichPokemon]
call AddNTimes
ld e, l
ld d, h
- ld hl, wHPBarMaxHP
- ld bc, $b
+ ld hl, wBuffer
+ ld bc, NAME_LENGTH
call CopyData
and a
ret
-.asm_6594
+.playerCancelled
scf
ret
-DisplayNamingScreen: ; 6596 (1:6596)
+DisplayNamingScreen:
push hl
ld hl, wd730
set 6, [hl]
call GBPalWhiteOutWithDelay3
call ClearScreen
call UpdateSprites
- ld b, $8
- call GoPAL_SET
+ ld b, SET_PAL_GENERIC
+ call RunPaletteCommand
call LoadHpBarAndStatusTilePatterns
call LoadEDTile
callba LoadMonPartySpriteGfx
- hlCoord 0, 4
- ld b, $9
- ld c, $12
+ coord hl, 0, 4
+ ld b, 9
+ ld c, 18
call TextBoxBorder
call PrintNamingText
- ld a, $3
+ ld a, 3
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
ld [wLastMenuItem], a
ld [wCurrentMenuItem], a
ld a, $ff
ld [wMenuWatchedKeys], a
- ld a, $7
+ ld a, 7
ld [wMaxMenuItem], a
- ld a, $50
+ ld a, "@"
ld [wcf4b], a
xor a
- ld hl, wHPBarMaxHP + 1
+ ld hl, wNamingScreenSubmitName
ld [hli], a
ld [hli], a
- ld [wPartyMonAnimCounter], a
-.asm_65ed
+ ld [wAnimCounter], a
+.selectReturnPoint
call PrintAlphabet
call GBPalNormal
-.asm_65f3
- ld a, [wHPBarMaxHP + 1]
+.ABStartReturnPoint
+ ld a, [wNamingScreenSubmitName]
and a
- jr nz, .asm_662d
- call Func_680e
-.asm_65fc
+ jr nz, .submitNickname
+ call PrintNicknameAndUnderscores
+.dPadReturnPoint
call PlaceMenuCursor
-.asm_65ff
+.inputLoop
ld a, [wCurrentMenuItem]
push af
callba AnimatePartyMon_ForceSpeed1
@@ -134,17 +134,17 @@ DisplayNamingScreen: ; 6596 (1:6596)
call JoypadLowSensitivity
ld a, [hJoyPressed]
and a
- jr z, .asm_65ff
- ld hl, .unknownPointerTable_665e
-.asm_661a
+ jr z, .inputLoop
+ ld hl, .namingScreenButtonFunctions
+.checkForPressedButton
sla a
- jr c, .asm_6624
+ jr c, .foundPressedButton
inc hl
inc hl
inc hl
inc hl
- jr .asm_661a
-.asm_6624
+ jr .checkForPressedButton
+.foundPressedButton
ld a, [hli]
ld e, a
ld a, [hli]
@@ -153,272 +153,279 @@ DisplayNamingScreen: ; 6596 (1:6596)
ld h, [hl]
ld l, a
push de
- jp [hl]
-.asm_662d
+ jp hl
+
+.submitNickname
pop de
ld hl, wcf4b
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
call GBPalWhiteOutWithDelay3
call ClearScreen
call ClearSprites
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call GBPalNormal
xor a
- ld [W_SUBANIMTRANSFORM], a
+ ld [wAnimCounter], a
ld hl, wd730
res 6, [hl]
- ld a, [W_ISINBATTLE]
+ ld a, [wIsInBattle]
and a
jp z, LoadTextBoxTilePatterns
- ld hl, LoadHudTilePatterns
- ld b, BANK(LoadHudTilePatterns)
- jp Bankswitch
+ jpab LoadHudTilePatterns
-.unknownPointerTable_665e: ; 665e (1:665e)
- dw .asm_65fc
- dw .asm_673e
- dw .asm_65fc
- dw .asm_672c
- dw .asm_65fc
- dw .asm_6718
- dw .asm_65fc
- dw .asm_6702
- dw .asm_65f3
- dw .asm_668c
- dw .asm_65ed
- dw .asm_6683
- dw .asm_65f3
- dw .deleteLetter
- dw .asm_65f3
- dw .asm_6692
+.namingScreenButtonFunctions
+ dw .dPadReturnPoint
+ dw .pressedDown
+ dw .dPadReturnPoint
+ dw .pressedUp
+ dw .dPadReturnPoint
+ dw .pressedLeft
+ dw .dPadReturnPoint
+ dw .pressedRight
+ dw .ABStartReturnPoint
+ dw .pressedStart
+ dw .selectReturnPoint
+ dw .pressedSelect
+ dw .ABStartReturnPoint
+ dw .pressedB
+ dw .ABStartReturnPoint
+ dw .pressedA
-.asm_667e
+.pressedA_changedCase
pop de
- ld de, .asm_65ed ; $65ed
+ ld de, .selectReturnPoint
push de
-.asm_6683
- ld a, [wHPBarOldHP]
+.pressedSelect
+ ld a, [wAlphabetCase]
xor $1
- ld [wHPBarOldHP], a
+ ld [wAlphabetCase], a
ret
-.asm_668c
- ld a, $1
- ld [wHPBarMaxHP + 1], a
+
+.pressedStart
+ ld a, 1
+ ld [wNamingScreenSubmitName], a
ret
-.asm_6692
+
+.pressedA
ld a, [wCurrentMenuItem]
- cp $5
- jr nz, .asm_66a0
+ cp $5 ; "ED" row
+ jr nz, .didNotPressED
ld a, [wTopMenuItemX]
- cp $11
- jr z, .asm_668c
-.asm_66a0
+ cp $11 ; "ED" column
+ jr z, .pressedStart
+.didNotPressED
ld a, [wCurrentMenuItem]
- cp $6
- jr nz, .asm_66ae
+ cp $6 ; case switch row
+ jr nz, .didNotPressCaseSwtich
ld a, [wTopMenuItemX]
- cp $1
- jr z, .asm_667e
-.asm_66ae
+ cp $1 ; case switch column
+ jr z, .pressedA_changedCase
+.didNotPressCaseSwtich
ld hl, wMenuCursorLocation
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
ld a, [hl]
- ld [wHPBarNewHP], a
+ ld [wNamingScreenLetter], a
call CalcStringLength
- ld a, [wHPBarNewHP]
+ ld a, [wNamingScreenLetter]
cp $e5
- ld de, Dakutens ; $6885
- jr z, .asm_66e3
+ ld de, Dakutens
+ jr z, .dakutensAndHandakutens
cp $e4
- ld de, Handakutens ; $68d6
- jr z, .asm_66e3
- ld a, [wd07d]
- cp $2
+ ld de, Handakutens
+ jr z, .dakutensAndHandakutens
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
jr nc, .checkMonNameLength
- ld a, [wHPBarMaxHP]
+ ld a, [wNamingScreenNameLength]
cp $7 ; max length of player/rival names
jr .checkNameLength
.checkMonNameLength
- ld a, [wHPBarMaxHP]
+ ld a, [wNamingScreenNameLength]
cp $a ; max length of pokemon nicknames
.checkNameLength
jr c, .addLetter
ret
-.asm_66e3
+
+.dakutensAndHandakutens
push hl
- call Func_6871
+ call DakutensAndHandakutens
pop hl
ret nc
dec hl
.addLetter
- ld a, [wHPBarNewHP]
+ ld a, [wNamingScreenLetter]
ld [hli], a
- ld [hl], $50
- ld a, (SFX_02_40 - SFX_Headers_02) / 3
+ ld [hl], "@"
+ ld a, SFX_PRESS_AB
call PlaySound
ret
-.deleteLetter
- ld a, [wHPBarMaxHP]
+.pressedB
+ ld a, [wNamingScreenNameLength]
and a
ret z
call CalcStringLength
dec hl
- ld [hl], $50
+ ld [hl], "@"
ret
-.asm_6702
+.pressedRight
ld a, [wCurrentMenuItem]
cp $6
- ret z
+ ret z ; can't scroll right on bottom row
ld a, [wTopMenuItemX]
- cp $11
- jp z, .asm_6714
+ cp $11 ; max
+ jp z, .wrapToFirstColumn
inc a
inc a
- jr .asm_6755
-.asm_6714
+ jr .done
+.wrapToFirstColumn
ld a, $1
- jr .asm_6755
-.asm_6718
+ jr .done
+.pressedLeft
ld a, [wCurrentMenuItem]
cp $6
- ret z
+ ret z ; can't scroll right on bottom row
ld a, [wTopMenuItemX]
dec a
- jp z, .asm_6728
+ jp z, .wrapToLastColumn
dec a
- jr .asm_6755
-.asm_6728
- ld a, $11
- jr .asm_6755
-.asm_672c
+ jr .done
+.wrapToLastColumn
+ ld a, $11 ; max
+ jr .done
+.pressedUp
ld a, [wCurrentMenuItem]
dec a
ld [wCurrentMenuItem], a
and a
ret nz
- ld a, $6
+ ld a, $6 ; wrap to bottom row
ld [wCurrentMenuItem], a
- ld a, $1
- jr .asm_6755
-.asm_673e
+ ld a, $1 ; force left column
+ jr .done
+.pressedDown
ld a, [wCurrentMenuItem]
inc a
ld [wCurrentMenuItem], a
cp $7
- jr nz, .asm_6750
+ jr nz, .wrapToTopRow
ld a, $1
ld [wCurrentMenuItem], a
- jr .asm_6755
-.asm_6750
+ jr .done
+.wrapToTopRow
cp $6
ret nz
ld a, $1
-.asm_6755
+.done
ld [wTopMenuItemX], a
jp EraseMenuCursor
-LoadEDTile: ; 675b (1:675b)
+LoadEDTile:
ld de, ED_Tile
ld hl, vFont + $700
- ld bc, $1
+ ld bc, (ED_TileEnd - ED_Tile) / $8
+ ; to fix the graphical bug on poor emulators
+ ;lb bc, BANK(ED_Tile), (ED_TileEnd - ED_Tile) / $8
jp CopyVideoDataDouble
-ED_Tile: ; 6767 (1:6767)
+ED_Tile:
INCBIN "gfx/ED_tile.1bpp"
+ED_TileEnd:
-PrintAlphabet: ; 676f (1:676f)
+PrintAlphabet:
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, [wHPBarOldHP]
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [wAlphabetCase]
and a
- ld de, LowerCaseAlphabet ; $679e
- jr nz, .asm_677e
- ld de, UpperCaseAlphabet ; $67d6
-.asm_677e
- hlCoord 2, 5
- ld bc, $509
-.asm_6784
+ ld de, LowerCaseAlphabet
+ jr nz, .lowercase
+ ld de, UpperCaseAlphabet
+.lowercase
+ coord hl, 2, 5
+ lb bc, 5, 9 ; 5 rows, 9 columns
+.outerLoop
push bc
-.asm_6785
+.innerLoop
ld a, [de]
ld [hli], a
inc hl
inc de
dec c
- jr nz, .asm_6785
- ld bc, $16
+ jr nz, .innerLoop
+ ld bc, SCREEN_WIDTH + 2
add hl, bc
pop bc
dec b
- jr nz, .asm_6784
+ jr nz, .outerLoop
call PlaceString
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
jp Delay3
-LowerCaseAlphabet: ; 679e (1:679e)
- db "abcdefghijklmnopqrstuvwxyz ×():;[]",$e1,$e2,"-?!♂♀/",$f2,",¥UPPER CASE@"
+LowerCaseAlphabet:
+ db "abcdefghijklmnopqrstuvwxyz ×():;[]",$e1,$e2,"-?!♂♀/⠄,¥UPPER CASE@"
-UpperCaseAlphabet: ; 67d6 (1:67d6)
- db "ABCDEFGHIJKLMNOPQRSTUVWXYZ ×():;[]",$e1,$e2,"-?!♂♀/",$f2,",¥lower case@"
+UpperCaseAlphabet:
+ db "ABCDEFGHIJKLMNOPQRSTUVWXYZ ×():;[]",$e1,$e2,"-?!♂♀/⠄,¥lower case@"
-Func_680e: ; 680e (1:680e)
+PrintNicknameAndUnderscores:
call CalcStringLength
ld a, c
- ld [wHPBarMaxHP], a
- hlCoord 10, 2
- ld bc, $10a
+ ld [wNamingScreenNameLength], a
+ coord hl, 10, 2
+ lb bc, 1, 10
call ClearScreenArea
- hlCoord 10, 2
+ coord hl, 10, 2
ld de, wcf4b
call PlaceString
- hlCoord 10, 3
- ld a, [wd07d]
- cp $2
- jr nc, .asm_6835
- ld b, $7
- jr .asm_6837
-.asm_6835
- ld b, $a
-.asm_6837
- ld a, $76
-.asm_6839
+ coord hl, 10, 3
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
+ jr nc, .pokemon1
+ ld b, 7 ; player or rival max name length
+ jr .playerOrRival1
+.pokemon1
+ ld b, 10 ; pokemon max name length
+.playerOrRival1
+ ld a, $76 ; underscore tile id
+.placeUnderscoreLoop
ld [hli], a
dec b
- jr nz, .asm_6839
- ld a, [wd07d]
- cp $2
- ld a, [wHPBarMaxHP]
- jr nc, .asm_684b
- cp $7
- jr .asm_684d
-.asm_684b
- cp $a
-.asm_684d
- jr nz, .asm_6867
+ jr nz, .placeUnderscoreLoop
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
+ ld a, [wNamingScreenNameLength]
+ jr nc, .pokemon2
+ cp 7 ; player or rival max name length
+ jr .playerOrRival2
+.pokemon2
+ cp 10 ; pokemon max name length
+.playerOrRival2
+ jr nz, .emptySpacesRemaining
+ ; when all spaces are filled, force the cursor onto the ED tile
call EraseMenuCursor
- ld a, $11
+ ld a, $11 ; "ED" x coord
ld [wTopMenuItemX], a
- ld a, $5
+ ld a, $5 ; "ED" y corrd
ld [wCurrentMenuItem], a
- ld a, [wd07d]
- cp $2
- ld a, $9
- jr nc, .asm_6867
- ld a, $6
-.asm_6867
+ ld a, [wNamingScreenType]
+ cp NAME_MON_SCREEN
+ ld a, 9 ; keep the last underscore raised
+ jr nc, .pokemon3
+ ld a, 6 ; keep the last underscore raised
+.pokemon3
+.emptySpacesRemaining
ld c, a
ld b, $0
- hlCoord 10, 3
+ coord hl, 10, 3
add hl, bc
- ld [hl], $77
+ ld [hl], $77 ; raised underscore tile id
ret
-Func_6871: ; 6871 (1:6871)
+DakutensAndHandakutens:
push de
call CalcStringLength
dec hl
@@ -429,10 +436,10 @@ Func_6871: ; 6871 (1:6871)
ret nc
inc hl
ld a, [hl]
- ld [wHPBarNewHP], a
+ ld [wNamingScreenLetter], a
ret
-Dakutens: ; 6885 (1:6885)
+Dakutens:
db "かが", "きぎ", "くぐ", "けげ", "こご"
db "さざ", "しじ", "すず", "せぜ", "そぞ"
db "ただ", "ちぢ", "つづ", "てで", "とど"
@@ -443,26 +450,26 @@ Dakutens: ; 6885 (1:6885)
db "ハバ", "ヒビ", "フブ", "へべ", "ホボ"
db $ff
-Handakutens: ; 68d6 (1:68d6)
+Handakutens:
db "はぱ", "ひぴ", "ふぷ", "へぺ", "ほぽ"
db "ハパ", "ヒピ", "フプ", "へぺ", "ホポ"
db $ff
; calculates the length of the string at wcf4b and stores it in c
-CalcStringLength: ; 68eb (1:68eb)
+CalcStringLength:
ld hl, wcf4b
ld c, $0
-.asm_68f0
+.loop
ld a, [hl]
- cp $50
+ cp "@"
ret z
inc hl
inc c
- jr .asm_68f0
+ jr .loop
-PrintNamingText: ; 68f8 (1:68f8)
- hlCoord 0, 1
- ld a, [wd07d]
+PrintNamingText:
+ coord hl, 0, 1
+ ld a, [wNamingScreenType]
ld de, YourTextString
and a
jr z, .notNickname
@@ -476,12 +483,12 @@ PrintNamingText: ; 68f8 (1:68f8)
pop af
ld [wd11e], a
call GetMonName
- hlCoord 4, 1
+ coord hl, 4, 1
call PlaceString
ld hl, $1
add hl, bc
ld [hl], $c9
- hlCoord 1, 3
+ coord hl, 1, 3
ld de, NicknameTextString
jr .placeString
.notNickname
@@ -492,14 +499,14 @@ PrintNamingText: ; 68f8 (1:68f8)
.placeString
jp PlaceString
-YourTextString: ; 693f (1:693f)
+YourTextString:
db "YOUR @"
-RivalsTextString: ; 6945 (1:6945)
+RivalsTextString:
db "RIVAL's @"
-NameTextString: ; 694d (1:694d)
+NameTextString:
db "NAME?@"
-NicknameTextString: ; 6953 (1:6953)
+NicknameTextString:
db "NICKNAME?@"
diff --git a/engine/menu/oaks_pc.asm b/engine/menu/oaks_pc.asm
index 6e7edda2..03c9b8f1 100755
--- a/engine/menu/oaks_pc.asm
+++ b/engine/menu/oaks_pc.asm
@@ -1,27 +1,28 @@
-OpenOaksPC: ; 1e915 (7:6915)
+OpenOaksPC:
call SaveScreenTilesToBuffer2
ld hl, AccessedOaksPCText
call PrintText
ld hl, GetDexRatedText
call PrintText
call YesNoChoice
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_1e932
+ jr nz, .closePC
predef DisplayDexRating
-.asm_1e932
+.closePC
ld hl, ClosedOaksPCText
call PrintText
jp LoadScreenTilesFromBuffer2
-GetDexRatedText: ; 1e93b (7:693b)
+GetDexRatedText:
TX_FAR _GetDexRatedText
db "@"
-ClosedOaksPCText: ; 1e940 (7:6940)
+ClosedOaksPCText:
TX_FAR _ClosedOaksPCText
- db $0d,"@"
+ TX_WAIT
+ db "@"
-AccessedOaksPCText: ; 1e946 (7:6946)
+AccessedOaksPCText:
TX_FAR _AccessedOaksPCText
db "@"
diff --git a/engine/menu/party_menu.asm b/engine/menu/party_menu.asm
index 242edd40..a35524ed 100755
--- a/engine/menu/party_menu.asm
+++ b/engine/menu/party_menu.asm
@@ -1,4 +1,4 @@
-; [wd07d] = menu type / message ID
+; [wPartyMenuTypeOrMessageID] = menu type / message ID
; if less than $F0, it is a menu type
; menu types:
; 00: normal pokemon menu (e.g. Start menu)
@@ -17,25 +17,25 @@
; f6: health returned
; f7: revitalized
; f8: leveled up
-DrawPartyMenu_: ; 12cd2 (4:6cd2)
+DrawPartyMenu_:
xor a
ld [H_AUTOBGTRANSFERENABLED],a
call ClearScreen
- call UpdateSprites ; move sprites
+ call UpdateSprites
callba LoadMonPartySpriteGfxWithLCDDisabled ; load pokemon icon graphics
-RedrawPartyMenu_: ; 12ce3 (4:6ce3)
- ld a,[wd07d]
- cp a,$04
+RedrawPartyMenu_:
+ ld a,[wPartyMenuTypeOrMessageID]
+ cp a,SWAP_MONS_PARTY_MENU
jp z,.printMessage
call ErasePartyMenuCursors
- callba SendBlkPacket_PartyMenu ; loads some data to wcf2e
- hlCoord 3, 0
+ callba InitPartyMenuBlkPacket
+ coord hl, 3, 0
ld de,wPartySpecies
xor a
ld c,a
ld [hPartyMonIndex],a
- ld [wcf2d],a
+ ld [wWhichPartyMenuHPBar],a
.loop
ld a,[de]
cp a,$FF ; reached the terminator?
@@ -70,15 +70,15 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
dec hl
dec hl
dec hl
- ld a,$EC ; unfilled right arrow menu cursor
+ ld a,"▷" ; unfilled right arrow menu cursor
ld [hli],a ; place the cursor
inc hl
inc hl
.skipUnfilledRightArrow
- ld a,[wd07d] ; menu type
- cp a,$03
+ ld a,[wPartyMenuTypeOrMessageID] ; menu type
+ cp a,TMHM_PARTY_MENU
jr z,.teachMoveMenu
- cp a,$05
+ cp a,EVO_STONE_PARTY_MENU
jr z,.evolutionStoneMenu
push hl
ld bc,14 ; 14 columns to the right
@@ -87,7 +87,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
call PrintStatusCondition
pop hl
push hl
- ld bc,20 + 1 ; down 1 row and right 1 column
+ ld bc,SCREEN_WIDTH + 1 ; down 1 row and right 1 column
ld a,[hFlags_0xFFF6]
set 0,a
ld [hFlags_0xFFF6],a
@@ -96,7 +96,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
ld a,[hFlags_0xFFF6]
res 0,a
ld [hFlags_0xFFF6],a
- call SetPartyMenuHealthBarColor ; color the HP bar (on SGB)
+ call SetPartyMenuHPBarColor ; color the HP bar (on SGB)
pop hl
jr .printLevel
.teachMoveMenu
@@ -150,7 +150,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
ld l,a
ld de,wcd6d
ld a,BANK(EvosMovesPointerTable)
- ld bc,13
+ ld bc,Mon133_EvosEnd - Mon133_EvosMoves
call FarCopyData
ld hl,wcd6d
ld de,.notAbleToEvolveText
@@ -167,7 +167,7 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
dec hl
dec hl
ld b,[hl]
- ld a,[wd156] ; evolution stone item ID
+ ld a,[wEvoStoneItemID] ; the stone the player used
inc hl
inc hl
inc hl
@@ -188,15 +188,15 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
.notAbleToEvolveText
db "NOT ABLE@"
.afterDrawingMonEntries
- ld b,$0A
- call GoPAL_SET
+ ld b, SET_PAL_PARTY_MENU
+ call RunPaletteCommand
.printMessage
ld hl,wd730
ld a,[hl]
push af
push hl
set 6,[hl] ; turn off letter printing delay
- ld a,[wd07d] ; message ID
+ ld a,[wPartyMenuTypeOrMessageID] ; message ID
cp a,$F0
jr nc,.printItemUseMessage
add a
@@ -227,14 +227,14 @@ RedrawPartyMenu_: ; 12ce3 (4:6ce3)
ld h,[hl]
ld l,a
push hl
- ld a,[wcf06]
+ ld a,[wUsedItemOnWhichPokemon]
ld hl,wPartyMonNicks
call GetPartyMonName
pop hl
call PrintText
jr .done
-PartyMenuItemUseMessagePointers: ; 12e61 (4:6e61)
+PartyMenuItemUseMessagePointers:
dw AntidoteText
dw BurnHealText
dw IceHealText
@@ -245,7 +245,7 @@ PartyMenuItemUseMessagePointers: ; 12e61 (4:6e61)
dw ReviveText
dw RareCandyText
-PartyMenuMessagePointers: ; 12e73 (4:6e73)
+PartyMenuMessagePointers:
dw PartyMenuNormalText
dw PartyMenuItemUseText
dw PartyMenuBattleText
@@ -253,73 +253,73 @@ PartyMenuMessagePointers: ; 12e73 (4:6e73)
dw PartyMenuSwapMonText
dw PartyMenuItemUseText
-PartyMenuNormalText: ; 12e7f (4:6e7f)
+PartyMenuNormalText:
TX_FAR _PartyMenuNormalText
db "@"
-PartyMenuItemUseText: ; 12e84 (4:6e84)
+PartyMenuItemUseText:
TX_FAR _PartyMenuItemUseText
db "@"
-PartyMenuBattleText: ; 12e89 (4:6e89)
+PartyMenuBattleText:
TX_FAR _PartyMenuBattleText
db "@"
-PartyMenuUseTMText: ; 12e8e (4:6e8e)
+PartyMenuUseTMText:
TX_FAR _PartyMenuUseTMText
db "@"
-PartyMenuSwapMonText: ; 12e93 (4:6e93)
+PartyMenuSwapMonText:
TX_FAR _PartyMenuSwapMonText
db "@"
-PotionText: ; 12e98 (4:6e98)
+PotionText:
TX_FAR _PotionText
db "@"
-AntidoteText: ; 12e9d (4:6e9d)
+AntidoteText:
TX_FAR _AntidoteText
db "@"
-ParlyzHealText: ; 12ea2 (4:6ea2)
+ParlyzHealText:
TX_FAR _ParlyzHealText
db "@"
-BurnHealText: ; 12ea7 (4:6ea7)
+BurnHealText:
TX_FAR _BurnHealText
db "@"
-IceHealText: ; 12eac (4:6eac)
+IceHealText:
TX_FAR _IceHealText
db "@"
-AwakeningText: ; 12eb1 (4:6eb1)
+AwakeningText:
TX_FAR _AwakeningText
db "@"
-FullHealText: ; 12eb6 (4:6eb6)
+FullHealText:
TX_FAR _FullHealText
db "@"
-ReviveText: ; 12ebb (4:6ebb)
+ReviveText:
TX_FAR _ReviveText
db "@"
-RareCandyText: ; 12ec0 (4:6ec0)
+RareCandyText:
TX_FAR _RareCandyText
- db $0B
- db $06
+ TX_SFX_ITEM_1 ; probably supposed to play SFX_LEVEL_UP but the wrong music bank is loaded
+ TX_BLINK
db "@"
-SetPartyMenuHealthBarColor: ; 12ec7 (4:6ec7)
- ld hl, wcf1f
- ld a, [wcf2d]
+SetPartyMenuHPBarColor:
+ ld hl, wPartyMenuHPBarColors
+ ld a, [wWhichPartyMenuHPBar]
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
call GetHealthBarColor
- ld b, $fc
- call GoPAL_SET
- ld hl, wcf2d
+ ld b, UPDATE_PARTY_MENU_BLK_PACKET
+ call RunPaletteCommand
+ ld hl, wWhichPartyMenuHPBar
inc [hl]
ret
diff --git a/engine/menu/pc.asm b/engine/menu/pc.asm
index 97895ca6..c9e2cf08 100755
--- a/engine/menu/pc.asm
+++ b/engine/menu/pc.asm
@@ -1,16 +1,16 @@
-ActivatePC: ; 17e2c (5:7e2c)
- call SaveScreenTilesToBuffer2 ;XXX: copy background from wTileMap to wTileMapBackup2
- ld a, (SFX_02_45 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
+ActivatePC:
+ call SaveScreenTilesToBuffer2
+ ld a, SFX_TURN_ON_PC
+ call PlaySound
ld hl, TurnedOnPC1Text
call PrintText
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+ call WaitForSoundToFinish
ld hl, wFlags_0xcd60
set 3, [hl]
- call LoadScreenTilesFromBuffer2 ;XXX: restore saved screen
+ call LoadScreenTilesFromBuffer2
call Delay3
-PCMainMenu: ; 17e48 (5:7e48)
- callba Func_213c8
+PCMainMenu:
+ callba DisplayPCMainMenu
ld hl, wFlags_0xcd60
set 5, [hl]
call HandleMenuInput
@@ -51,31 +51,30 @@ PCMainMenu: ; 17e48 (5:7e48)
ld hl, wFlags_0xcd60
res 5, [hl]
set 3, [hl]
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
ld hl, AccessedMyPCText
call PrintText
callba PlayerPC
jr ReloadMainMenu
-OaksPC: ; 17ec0 (5:7ec0)
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+OaksPC:
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
callba OpenOaksPC
jr ReloadMainMenu
-PKMNLeague: ; 17ed2 (5:7ed2)
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+PKMNLeague:
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
callba PKMNLeaguePC
jr ReloadMainMenu
-BillsPC: ; 17ee4 (5:7ee4)
- ld a, (SFX_02_47 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
- ld a, [wd7f1] ;has to do with having met Bill
- bit 0, a
+BillsPC:
+ ld a, SFX_ENTER_PC
+ call PlaySound
+ call WaitForSoundToFinish
+ CheckEvent EVENT_MET_BILL
jr nz, .billsPC ;if you've met bill, use that bill's instead of someone's
ld hl, AccessedSomeonesPCText
jr .printText
@@ -84,59 +83,59 @@ BillsPC: ; 17ee4 (5:7ee4)
.printText
call PrintText
callba BillsPC_
-ReloadMainMenu: ; 17f06 (5:7f06)
+ReloadMainMenu:
xor a
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
call ReloadMapData
- call UpdateSprites ;XXX: moves sprites
+ call UpdateSprites
jp PCMainMenu
-LogOff: ; 17f13 (5:7f13)
- ld a, (SFX_02_46 - SFX_Headers_02) / 3
- call PlaySound ;XXX: play sound or stop music
- call WaitForSoundToFinish ;XXX: wait for sound to be done
+LogOff:
+ ld a, SFX_TURN_OFF_PC
+ call PlaySound
+ call WaitForSoundToFinish
ld hl, wFlags_0xcd60
res 3, [hl]
res 5, [hl]
ret
-TurnedOnPC1Text: ; 17f23 (5:7f23)
+TurnedOnPC1Text:
TX_FAR _TurnedOnPC1Text
db "@"
-AccessedBillsPCText: ; 17f28 (5:7f28)
+AccessedBillsPCText:
TX_FAR _AccessedBillsPCText
db "@"
-AccessedSomeonesPCText: ; 17f2d (5:7f2d)
+AccessedSomeonesPCText:
TX_FAR _AccessedSomeonesPCText
db "@"
-AccessedMyPCText: ; 17f32 (5:7f32)
+AccessedMyPCText:
TX_FAR _AccessedMyPCText
db "@"
-; removes one of the specified item ID [$FFdb] from bag (if existent)
-RemoveItemByID: ; 17f37 (5:7f37)
- ld hl, wBagItems ; wd31e
- ld a, [$ffdb]
+; removes one of the specified item ID [hItemToRemoveID] from bag (if existent)
+RemoveItemByID:
+ ld hl, wBagItems
+ ld a, [hItemToRemoveID]
ld b, a
xor a
- ld [$ffdc], a
-.asm_17f40
+ ld [hItemToRemoveIndex], a
+.loop
ld a, [hli]
- cp $ff
+ cp -1 ; reached terminator?
ret z
cp b
- jr z, .asm_17f4f
+ jr z, .foundItem
inc hl
- ld a, [$ffdc]
+ ld a, [hItemToRemoveIndex]
inc a
- ld [$ffdc], a
- jr .asm_17f40
-.asm_17f4f
+ ld [hItemToRemoveIndex], a
+ jr .loop
+.foundItem
ld a, $1
- ld [wcf96], a
- ld a, [$ffdc]
- ld [wWhichPokemon], a ; wWhichPokemon
- ld hl, wNumBagItems ; wNumBagItems
+ ld [wItemQuantity], a
+ ld a, [hItemToRemoveIndex]
+ ld [wWhichPokemon], a
+ ld hl, wNumBagItems
jp RemoveItemFromInventory
diff --git a/engine/menu/players_pc.asm b/engine/menu/players_pc.asm
index 147a27a4..bc2be4ef 100755
--- a/engine/menu/players_pc.asm
+++ b/engine/menu/players_pc.asm
@@ -1,301 +1,303 @@
-PlayerPC: ; 78e6 (1:78e6)
+PlayerPC:
ld hl, wd730
set 6, [hl]
ld a, ITEM_NAME
ld [wNameListType], a
call SaveScreenTilesToBuffer1
xor a
- ld [wcc2c], a
- ld [wccd3], a
+ ld [wBagSavedMenuItem], a
+ ld [wParentMenuItem], a
ld a, [wFlags_0xcd60]
- bit 3, a
- jr nz, Func_790c
- ld a, (SFX_02_45 - SFX_Headers_02) / 3
+ bit 3, a ; accessing player's PC through another PC?
+ jr nz, PlayerPCMenu
+; accessing it directly
+ ld a, SFX_TURN_ON_PC
call PlaySound
ld hl, TurnedOnPC2Text
call PrintText
-Func_790c: ; 790c (1:790c)
- ld a, [wccd3]
+PlayerPCMenu:
+ ld a, [wParentMenuItem]
ld [wCurrentMenuItem], a
ld hl, wFlags_0xcd60
set 5, [hl]
call LoadScreenTilesFromBuffer2
- ld hl, wTileMap
+ coord hl, 0, 0
ld b, $8
ld c, $e
call TextBoxBorder
call UpdateSprites
- hlCoord 2, 2
+ coord hl, 2, 2
ld de, PlayersPCMenuEntries
call PlaceString
ld hl, wTopMenuItemY
- ld a, $2
- ld [hli], a
+ ld a, 2
+ ld [hli], a ; wTopMenuItemY
dec a
- ld [hli], a
+ ld [hli], a ; wTopMenuItemX
inc hl
inc hl
- ld a, $3
- ld [hli], a
- ld a, $3
- ld [hli], a
+ ld a, 3
+ ld [hli], a ; wMaxMenuItem
+ ld a, A_BUTTON | B_BUTTON
+ ld [hli], a ; wMenuWatchedKeys
xor a
ld [hl], a
ld hl, wListScrollOffset
- ld [hli], a
- ld [hl], a
+ ld [hli], a ; wListScrollOffset
+ ld [hl], a ; wMenuWatchMovingOutOfBounds
ld [wPlayerMonNumber], a
ld hl, WhatDoYouWantText
call PrintText
call HandleMenuInput
bit 1, a
- jp nz, Func_796d
+ jp nz, ExitPlayerPC
call PlaceUnfilledArrowMenuCursor
ld a, [wCurrentMenuItem]
- ld [wccd3], a
+ ld [wParentMenuItem], a
and a
- jp z, Func_7a12
+ jp z, PlayerPCWithdraw
dec a
- jp z, Func_7995
+ jp z, PlayerPCDeposit
dec a
- jp z, Func_7a8f
+ jp z, PlayerPCToss
-Func_796d: ; 796d (1:796d)
+ExitPlayerPC:
ld a, [wFlags_0xcd60]
- bit 3, a
- jr nz, .asm_797c
- ld a, (SFX_02_46 - SFX_Headers_02) / 3
+ bit 3, a ; accessing player's PC through another PC?
+ jr nz, .next
+; accessing it directly
+ ld a, SFX_TURN_OFF_PC
call PlaySound
call WaitForSoundToFinish
-.asm_797c
+.next
ld hl, wFlags_0xcd60
res 5, [hl]
call LoadScreenTilesFromBuffer2
xor a
ld [wListScrollOffset], a
- ld [wcc2c], a
+ ld [wBagSavedMenuItem], a
ld hl, wd730
res 6, [hl]
xor a
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
ret
-Func_7995: ; 7995 (1:7995)
+PlayerPCDeposit:
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
ld a, [wNumBagItems]
and a
- jr nz, Func_79ab
+ jr nz, .loop
ld hl, NothingToDepositText
call PrintText
- jp Func_790c
-
-Func_79ab: ; 79ab (1:79ab)
+ jp PlayerPCMenu
+.loop
ld hl, WhatToDepositText
call PrintText
ld hl, wNumBagItems
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
- ld a, $3
+ ld [wPrintItemPrices], a
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
- jp c, Func_790c
+ jp c, PlayerPCMenu
call IsKeyItem
- ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ ld a, 1
+ ld [wItemQuantity], a
+ ld a, [wIsKeyItem]
and a
- jr nz, .asm_79e7
+ jr nz, .next
+; if it's not a key item, there can be more than one of the item
ld hl, DepositHowManyText
call PrintText
call DisplayChooseQuantityMenu
cp $ff
- jp z, Func_79ab
-.asm_79e7
+ jp z, .loop
+.next
ld hl, wNumBoxItems
call AddItemToInventory
- jr c, .asm_79f8
+ jr c, .roomAvailable
ld hl, NoRoomToStoreText
call PrintText
- jp Func_79ab
-.asm_79f8
+ jp .loop
+.roomAvailable
ld hl, wNumBagItems
call RemoveItemFromInventory
call WaitForSoundToFinish
- ld a, (SFX_02_55 - SFX_Headers_02) / 3
+ ld a, SFX_WITHDRAW_DEPOSIT
call PlaySound
call WaitForSoundToFinish
ld hl, ItemWasStoredText
call PrintText
- jp Func_79ab
+ jp .loop
-Func_7a12: ; 7a12 (1:7a12)
+PlayerPCWithdraw:
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
ld a, [wNumBoxItems]
and a
- jr nz, Func_7a28
+ jr nz, .loop
ld hl, NothingStoredText
call PrintText
- jp Func_790c
-
-Func_7a28: ; 7a28 (1:7a28)
+ jp PlayerPCMenu
+.loop
ld hl, WhatToWithdrawText
call PrintText
ld hl, wNumBoxItems
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
- ld a, $3
+ ld [wPrintItemPrices], a
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
- jp c, Func_790c
+ jp c, PlayerPCMenu
call IsKeyItem
- ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ ld a, 1
+ ld [wItemQuantity], a
+ ld a, [wIsKeyItem]
and a
- jr nz, .asm_7a64
+ jr nz, .next
+; if it's not a key item, there can be more than one of the item
ld hl, WithdrawHowManyText
call PrintText
call DisplayChooseQuantityMenu
cp $ff
- jp z, Func_7a28
-.asm_7a64
+ jp z, .loop
+.next
ld hl, wNumBagItems
call AddItemToInventory
- jr c, .asm_7a75
+ jr c, .roomAvailable
ld hl, CantCarryMoreText
call PrintText
- jp Func_7a28
-.asm_7a75
+ jp .loop
+.roomAvailable
ld hl, wNumBoxItems
call RemoveItemFromInventory
call WaitForSoundToFinish
- ld a, (SFX_02_55 - SFX_Headers_02) / 3
+ ld a, SFX_WITHDRAW_DEPOSIT
call PlaySound
call WaitForSoundToFinish
ld hl, WithdrewItemText
call PrintText
- jp Func_7a28
+ jp .loop
-Func_7a8f: ; 7a8f (1:7a8f)
+PlayerPCToss:
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
ld a, [wNumBoxItems]
and a
- jr nz, Func_7aa5
+ jr nz, .loop
ld hl, NothingStoredText
call PrintText
- jp Func_790c
-
-Func_7aa5: ; 7aa5 (1:7aa5)
+ jp PlayerPCMenu
+.loop
ld hl, WhatToTossText
call PrintText
ld hl, wNumBoxItems
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
xor a
- ld [wcf93], a
- ld a, $3
+ ld [wPrintItemPrices], a
+ ld a, ITEMLISTMENU
ld [wListMenuID], a
push hl
call DisplayListMenuID
pop hl
- jp c, Func_790c
+ jp c, PlayerPCMenu
push hl
call IsKeyItem
pop hl
- ld a, $1
- ld [wcf96], a
- ld a, [wd124]
+ ld a, 1
+ ld [wItemQuantity], a
+ ld a, [wIsKeyItem]
and a
- jr nz, .asm_7aef
+ jr nz, .next
ld a, [wcf91]
call IsItemHM
- jr c, .asm_7aef
+ jr c, .next
+; if it's not a key item, there can be more than one of the item
push hl
ld hl, TossHowManyText
call PrintText
call DisplayChooseQuantityMenu
pop hl
cp $ff
- jp z, Func_7aa5
-.asm_7aef
- call TossItem
- jp Func_7aa5
+ jp z, .loop
+.next
+ call TossItem ; disallows tossing key items
+ jp .loop
-PlayersPCMenuEntries: ; 7af5 (1:7af5)
+PlayersPCMenuEntries:
db "WITHDRAW ITEM"
next "DEPOSIT ITEM"
next "TOSS ITEM"
next "LOG OFF@"
-TurnedOnPC2Text: ; 7b22 (1:7b22)
+TurnedOnPC2Text:
TX_FAR _TurnedOnPC2Text
db "@"
-WhatDoYouWantText: ; 7b27 (1:7b27)
+WhatDoYouWantText:
TX_FAR _WhatDoYouWantText
db "@"
-WhatToDepositText: ; 7b2c (1:7b2c)
+WhatToDepositText:
TX_FAR _WhatToDepositText
db "@"
-DepositHowManyText: ; 7b31 (1:7b31)
+DepositHowManyText:
TX_FAR _DepositHowManyText
db "@"
-ItemWasStoredText: ; 7b36 (1:7b36)
+ItemWasStoredText:
TX_FAR _ItemWasStoredText
db "@"
-NothingToDepositText: ; 7b3b (1:7b3b)
+NothingToDepositText:
TX_FAR _NothingToDepositText
db "@"
-NoRoomToStoreText: ; 7b40 (1:7b40)
+NoRoomToStoreText:
TX_FAR _NoRoomToStoreText
db "@"
-WhatToWithdrawText: ; 7b45 (1:7b45)
+WhatToWithdrawText:
TX_FAR _WhatToWithdrawText
db "@"
-WithdrawHowManyText: ; 7b4a (1:7b4a)
+WithdrawHowManyText:
TX_FAR _WithdrawHowManyText
db "@"
-WithdrewItemText: ; 7b4f (1:7b4f)
+WithdrewItemText:
TX_FAR _WithdrewItemText
db "@"
-NothingStoredText: ; 7b54 (1:7b54)
+NothingStoredText:
TX_FAR _NothingStoredText
db "@"
-CantCarryMoreText: ; 7b59 (1:7b59)
+CantCarryMoreText:
TX_FAR _CantCarryMoreText
db "@"
-WhatToTossText: ; 7b5e (1:7b5e)
+WhatToTossText:
TX_FAR _WhatToTossText
db "@"
-TossHowManyText: ; 7b63 (1:7b63)
+TossHowManyText:
TX_FAR _TossHowManyText
db "@"
diff --git a/engine/menu/pokedex.asm b/engine/menu/pokedex.asm
index 4351ae4c..2da3a0f6 100755
--- a/engine/menu/pokedex.asm
+++ b/engine/menu/pokedex.asm
@@ -1,7 +1,7 @@
-ShowPokedexMenu: ; 40000 (10:4000)
+ShowPokedexMenu:
call GBPalWhiteOut
call ClearScreen
- call UpdateSprites ; move sprites
+ call UpdateSprites
ld a,[wListScrollOffset]
push af
xor a
@@ -12,8 +12,8 @@ ShowPokedexMenu: ; 40000 (10:4000)
ld [wd11e],a
ld [hJoy7],a
.setUpGraphics
- ld b,$08
- call GoPAL_SET
+ ld b, SET_PAL_GENERIC
+ call RunPaletteCommand
callab LoadPokedexTilePatterns
.doPokemonListMenu
ld hl,wTopMenuItemY
@@ -22,17 +22,17 @@ ShowPokedexMenu: ; 40000 (10:4000)
xor a
ld [hli],a ; top menu item X
inc a
- ld [wcc37],a
+ ld [wMenuWatchMovingOutOfBounds],a
inc hl
inc hl
ld a,6
ld [hli],a ; max menu item ID
- ld [hl],%00110011 ; menu watched keys (Left, Right, B button, A button)
+ ld [hl],D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
call HandlePokedexListMenu
jr c,.goToSideMenu ; if the player chose a pokemon from the list
.exitPokedex
xor a
- ld [wcc37],a
+ ld [wMenuWatchMovingOutOfBounds],a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
ld [hJoy7],a
@@ -41,7 +41,7 @@ ShowPokedexMenu: ; 40000 (10:4000)
pop af
ld [wListScrollOffset],a
call GBPalWhiteOutWithDelay3
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
jp ReloadMapData
.goToSideMenu
call HandlePokedexSideMenu
@@ -57,7 +57,7 @@ ShowPokedexMenu: ; 40000 (10:4000)
; 00: showed pokemon data or area
; 01: the player chose Quit
; 02: the pokemon has not been seen yet or the player pressed the B button
-HandlePokedexSideMenu: ; 4006d (10:406d)
+HandlePokedexSideMenu:
call PlaceUnfilledArrowMenuCursor
ld a,[wCurrentMenuItem]
push af
@@ -71,8 +71,8 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
ld [wd11e],a
ld a,[wd11e]
push af
- ld a,[wWhichTrade]
- push af
+ ld a,[wDexMaxSeenMon]
+ push af ; this doesn't need to be preserved
ld hl,wPokedexSeen
call IsPokemonBitSet
ld b,2
@@ -88,10 +88,11 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
inc hl
ld a,3
ld [hli],a ; max menu item ID
+ ;ld a, A_BUTTON | B_BUTTON
ld [hli],a ; menu watched keys (A button and B button)
xor a
ld [hli],a ; old menu item ID
- ld [wcc37],a
+ ld [wMenuWatchMovingOutOfBounds],a
.handleMenuInput
call HandleMenuInput
bit 1,a ; was the B button pressed?
@@ -108,7 +109,7 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
ld b,1
.exitSideMenu
pop af
- ld [wWhichTrade],a
+ ld [wDexMaxSeenMon],a
pop af
ld [wd11e],a
pop af
@@ -118,30 +119,34 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
pop af
ld [wCurrentMenuItem],a
push bc
- hlCoord 0, 3
+ coord hl, 0, 3
ld de,20
- ld bc,$7f0d ; 13 blank tiles
+ lb bc, " ", 13
call DrawTileLine ; cover up the menu cursor in the pokemon list
pop bc
ret
+
.buttonBPressed
push bc
- hlCoord 15, 10
+ coord hl, 15, 10
ld de,20
- ld bc,$7f07 ; 7 blank tiles
+ lb bc, " ", 7
call DrawTileLine ; cover up the menu cursor in the side menu
pop bc
jr .exitSideMenu
+
.choseData
call ShowPokedexDataInternal
ld b,0
jr .exitSideMenu
+
; play pokemon cry
.choseCry
ld a,[wd11e]
- call GetCryData ; get cry data
- call PlaySound ; play sound
+ call GetCryData
+ call PlaySound
jr .handleMenuInput
+
.choseArea
predef LoadTownMap_Nest ; display pokemon areas
ld b,0
@@ -149,47 +154,47 @@ HandlePokedexSideMenu: ; 4006d (10:406d)
; handles the list of pokemon on the left of the pokedex screen
; sets carry flag if player presses A, unsets carry flag if player presses B
-HandlePokedexListMenu: ; 40111 (10:4111)
+HandlePokedexListMenu:
xor a
ld [H_AUTOBGTRANSFERENABLED],a
; draw the horizontal line separating the seen and owned amounts from the menu
- hlCoord 15, 8
- ld a,$7a ; horizontal line tile
+ coord hl, 15, 8
+ ld a,"─"
ld [hli],a
ld [hli],a
ld [hli],a
ld [hli],a
ld [hli],a
- hlCoord 14, 0
+ coord hl, 14, 0
ld [hl],$71 ; vertical line tile
- hlCoord 14, 1
+ coord hl, 14, 1
call DrawPokedexVerticalLine
- hlCoord 14, 9
+ coord hl, 14, 9
call DrawPokedexVerticalLine
ld hl,wPokedexSeen
ld b,wPokedexSeenEnd - wPokedexSeen
call CountSetBits
- ld de,wd11e
- hlCoord 16, 3
- ld bc,$0103
+ ld de, wNumSetBits
+ coord hl, 16, 3
+ lb bc, 1, 3
call PrintNumber ; print number of seen pokemon
ld hl,wPokedexOwned
ld b,wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld de,wd11e
- hlCoord 16, 6
- ld bc,$0103
+ ld de, wNumSetBits
+ coord hl, 16, 6
+ lb bc, 1, 3
call PrintNumber ; print number of owned pokemon
- hlCoord 16, 2
+ coord hl, 16, 2
ld de,PokedexSeenText
call PlaceString
- hlCoord 16, 5
+ coord hl, 16, 5
ld de,PokedexOwnText
call PlaceString
- hlCoord 1, 1
+ coord hl, 1, 1
ld de,PokedexContentsText
call PlaceString
- hlCoord 16, 10
+ coord hl, 16, 10
ld de,PokedexMenuItemsText
call PlaceString
; find the highest pokedex number among the pokemon the player has seen
@@ -205,20 +210,21 @@ HandlePokedexListMenu: ; 40111 (10:4111)
dec c
jr nz,.maxSeenPokemonInnerLoop
jr .maxSeenPokemonLoop
+
.storeMaxSeenPokemon
ld a,b
- ld [wWhichTrade],a ; max seen pokemon
+ ld [wDexMaxSeenMon],a
.loop
xor a
ld [H_AUTOBGTRANSFERENABLED],a
- hlCoord 4, 2
- ld bc,$0e0a
+ coord hl, 4, 2
+ lb bc, 14, 10
call ClearScreenArea
- hlCoord 1, 3
+ coord hl, 1, 3
ld a,[wListScrollOffset]
ld [wd11e],a
ld d,7
- ld a,[wWhichTrade]
+ ld a,[wDexMaxSeenMon]
cp a,7
jr nc,.printPokemonLoop
ld d,a
@@ -233,12 +239,12 @@ HandlePokedexListMenu: ; 40111 (10:4111)
push af
push de
push hl
- ld de,-20
+ ld de,-SCREEN_WIDTH
add hl,de
ld de,wd11e
- ld bc,$8103
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; print the pokedex number
- ld de,20
+ ld de,SCREEN_WIDTH
add hl,de
dec hl
push hl
@@ -266,7 +272,7 @@ HandlePokedexListMenu: ; 40111 (10:4111)
inc hl
call PlaceString
pop hl
- ld bc,2 * 20
+ ld bc,2 * SCREEN_WIDTH
add hl,bc
pop de
pop af
@@ -294,9 +300,9 @@ HandlePokedexListMenu: ; 40111 (10:4111)
bit 7,a ; was Down pressed?
jr z,.checkIfRightPressed
.downPressed ; scroll down one row
- ld a,[wWhichTrade]
+ ld a,[wDexMaxSeenMon]
cp a,7
- jp c,.loop
+ jp c,.loop ; can't if the list is shorter than 7
sub a,7
ld b,a
ld a,[wListScrollOffset]
@@ -309,9 +315,9 @@ HandlePokedexListMenu: ; 40111 (10:4111)
bit 4,a ; was Right pressed?
jr z,.checkIfLeftPressed
.rightPressed ; scroll down 7 rows
- ld a,[wWhichTrade]
+ ld a,[wDexMaxSeenMon]
cp a,7
- jp c,.loop
+ jp c,.loop ; can't if the list is shorter than 7
sub a,6
ld b,a
ld a,[wListScrollOffset]
@@ -341,9 +347,9 @@ HandlePokedexListMenu: ; 40111 (10:4111)
and a
ret
-DrawPokedexVerticalLine: ; 4028e (10:428e)
+DrawPokedexVerticalLine:
ld c,9 ; height of line
- ld de,20 ; width of screen
+ ld de,SCREEN_WIDTH
ld a,$71 ; vertical line tile
.loop
ld [hl],a
@@ -353,78 +359,80 @@ DrawPokedexVerticalLine: ; 4028e (10:428e)
jr nz,.loop
ret
-PokedexSeenText: ; 4029d (10:429d)
+PokedexSeenText:
db "SEEN@"
-PokedexOwnText: ; 402a2 (10:42a2)
+PokedexOwnText:
db "OWN@"
-PokedexContentsText: ; 402a6 (10:42a6)
+PokedexContentsText:
db "CONTENTS@"
-PokedexMenuItemsText: ; 402af (10:42af)
+PokedexMenuItemsText:
db "DATA"
next "CRY"
next "AREA"
-IF DEF(_YELLOW)
- next "PRNT"
-ENDC
next "QUIT@"
; tests if a pokemon's bit is set in the seen or owned pokemon bit fields
; INPUT:
; [wd11e] = pokedex number
; hl = address of bit field
-IsPokemonBitSet: ; 402c2 (10:42c2)
+IsPokemonBitSet:
ld a,[wd11e]
dec a
ld c,a
- ld b,2
+ ld b,FLAG_TEST
predef FlagActionPredef
ld a,c
and a
ret
; function to display pokedex data from outside the pokedex
-ShowPokedexData: ; 402d1 (10:42d1)
+ShowPokedexData:
call GBPalWhiteOutWithDelay3
call ClearScreen
call UpdateSprites
callab LoadPokedexTilePatterns ; load pokedex tiles
; function to display pokedex data from inside the pokedex
-ShowPokedexDataInternal: ; 402e2 (10:42e2)
+ShowPokedexDataInternal:
ld hl,wd72c
set 1,[hl]
ld a,$33 ; 3/7 volume
- ld [$ff24],a
+ ld [rNR50],a
call GBPalWhiteOut ; zero all palettes
call ClearScreen
ld a,[wd11e] ; pokemon ID
ld [wcf91],a
push af
- ld b,04
- call GoPAL_SET
+ ld b, SET_PAL_POKEDEX
+ call RunPaletteCommand
pop af
ld [wd11e],a
ld a,[hTilesetType]
push af
xor a
ld [hTilesetType],a
- hlCoord 0, 0
+
+ coord hl, 0, 0
ld de,1
- ld bc,$6414
+ lb bc, $64, SCREEN_WIDTH
call DrawTileLine ; draw top border
- hlCoord 0, 17
- ld b,$6f
+
+ coord hl, 0, 17
+ ld b, $6f
call DrawTileLine ; draw bottom border
- hlCoord 0, 1
+
+ coord hl, 0, 1
ld de,20
- ld bc,$6610
+ lb bc, $66, $10
call DrawTileLine ; draw left border
- hlCoord 19, 1
+
+ coord hl, 19, 1
ld b,$67
call DrawTileLine ; draw right border
+
ld a,$63 ; upper left corner tile
Coorda 0, 0
ld a,$65 ; upper right corner tile
@@ -433,15 +441,19 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
Coorda 0, 17
ld a,$6e ; lower right corner tile
Coorda 19, 17
- hlCoord 0, 9
+
+ coord hl, 0, 9
ld de,PokedexDataDividerLine
call PlaceString ; draw horizontal divider line
- hlCoord 9, 6
+
+ coord hl, 9, 6
ld de,HeightWeightText
call PlaceString
+
call GetMonName
- hlCoord 9, 2
+ coord hl, 9, 2
call PlaceString
+
ld hl,PokedexEntryPointers
ld a,[wd11e]
dec a
@@ -452,22 +464,26 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
ld a,[hli]
ld e,a
ld d,[hl] ; de = address of pokedex entry
- hlCoord 9, 4
+
+ coord hl, 9, 4
call PlaceString ; print species name
+
ld h,b
ld l,c
push de
ld a,[wd11e]
push af
call IndexToPokedex
- hlCoord 2, 8
+
+ coord hl, 2, 8
ld a, "№"
ld [hli],a
- ld a,$f2
+ ld a,"⠄"
ld [hli],a
ld de,wd11e
- ld bc,$8103
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; print pokedex number
+
ld hl,wPokedexOwned
call IsPokemonBitSet
pop af
@@ -475,35 +491,39 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
ld a,[wcf91]
ld [wd0b5],a
pop de
+
push af
push bc
push de
push hl
+
call Delay3
call GBPalNormal
call GetMonHeader ; load pokemon picture location
- hlCoord 1, 1
+ coord hl, 1, 1
call LoadFlippedFrontSpriteByMonIndex ; draw pokemon picture
ld a,[wcf91]
call PlayCry ; play pokemon cry
+
pop hl
pop de
pop bc
pop af
+
ld a,c
and a
jp z,.waitForButtonPress ; if the pokemon has not been owned, don't print the height, weight, or description
inc de ; de = address of feet (height)
ld a,[de] ; reads feet, but a is overwritten without being used
- hlCoord 12, 6
- ld bc,$0102
+ coord hl, 12, 6
+ lb bc, 1, 2
call PrintNumber ; print feet (height)
ld a,$60 ; feet symbol tile (one tick)
ld [hl],a
inc de
inc de ; de = address of inches (height)
- hlCoord 15, 6
- ld bc,$8102
+ coord hl, 15, 6
+ lb bc, LEADING_ZEROES | 1, 2
call PrintNumber ; print inches (height)
ld a,$61 ; inches symbol tile (two ticks)
ld [hl],a
@@ -512,25 +532,25 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
inc de
inc de ; de = address of upper byte of weight
push de
-; put weight in big-endian order at $ff8b
- ld hl,$ff8b
- ld a,[hl] ; save existing value of [$ff8b]
+; put weight in big-endian order at hDexWeight
+ ld hl,hDexWeight
+ ld a,[hl] ; save existing value of [hDexWeight]
push af
ld a,[de] ; a = upper byte of weight
- ld [hli],a ; store upper byte of weight in [$ff8b]
- ld a,[hl] ; save existing value of [$ff8c]
+ ld [hli],a ; store upper byte of weight in [hDexWeight]
+ ld a,[hl] ; save existing value of [hDexWeight + 1]
push af
dec de
ld a,[de] ; a = lower byte of weight
- ld [hl],a ; store lower byte of weight in [$ff8c]
- ld de,$ff8b
- hlCoord 11, 8
- ld bc,$0205 ; no leading zeroes, right-aligned, 2 bytes, 5 digits
+ ld [hl],a ; store lower byte of weight in [hDexWeight + 1]
+ ld de,hDexWeight
+ coord hl, 11, 8
+ lb bc, 2, 5 ; 2 bytes, 5 digits
call PrintNumber ; print weight
- hlCoord 14, 8
- ld a,[$ff8c]
+ coord hl, 14, 8
+ ld a,[hDexWeight + 1]
sub a,10
- ld a,[$ff8b]
+ ld a,[hDexWeight]
sbc a,0
jr nc,.next
ld [hl],"0" ; if the weight is less than 10, put a 0 before the decimal point
@@ -538,14 +558,14 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
inc hl
ld a,[hli]
ld [hld],a ; make space for the decimal point by moving the last digit forward one tile
- ld [hl],$f2 ; decimal point tile
+ ld [hl],"⠄" ; decimal point tile
pop af
- ld [$ff8c],a ; restore original value of [$ff8c]
+ ld [hDexWeight + 1],a ; restore original value of [hDexWeight + 1]
pop af
- ld [$ff8b],a ; restore original value of [$ff8b]
+ ld [hDexWeight],a ; restore original value of [hDexWeight]
pop hl
inc hl ; hl = address of pokedex description text
- bcCoord 1, 11
+ coord bc, 1, 11
ld a,2
ld [$fff4],a
call TextCommandProcessor ; print pokedex description text
@@ -554,35 +574,36 @@ ShowPokedexDataInternal: ; 402e2 (10:42e2)
.waitForButtonPress
call JoypadLowSensitivity
ld a,[hJoy5]
- and a,%00000011 ; A button and B button
+ and a,A_BUTTON | B_BUTTON
jr z,.waitForButtonPress
pop af
ld [hTilesetType],a
call GBPalWhiteOut
call ClearScreen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call LoadTextBoxTilePatterns
call GBPalNormal
ld hl,wd72c
res 1,[hl]
ld a,$77 ; max volume
- ld [$ff24],a
+ ld [rNR50],a
ret
-HeightWeightText: ; 40448 (10:4448)
- db "HT ?",$60,"??",$61,$4E,"WT ???lb@"
+HeightWeightText:
+ db "HT ?",$60,"??",$61
+ next "WT ???lb@"
; XXX does anything point to this?
-Unknown_4045D: ; 4045d (10:445d)
- db $54,$50
+PokeText:
+ db "#@"
; horizontal line that divides the pokedex text description from the rest of the data
-PokedexDataDividerLine: ; 4045f (10:445f)
+PokedexDataDividerLine:
db $68,$69,$6B,$69,$6B
db $69,$6B,$69,$6B,$6B
db $6B,$6B,$69,$6B,$69
db $6B,$69,$6B,$69,$6A
- db $50
+ db "@"
; draws a line of tiles
; INPUT:
@@ -590,7 +611,7 @@ PokedexDataDividerLine: ; 4045f (10:445f)
; c = number of tile ID's to write
; de = amount to destination address after each tile (1 for horizontal, 20 for vertical)
; hl = destination address
-DrawTileLine: ; 40474 (10:4474)
+DrawTileLine:
push bc
push de
.loop
@@ -604,7 +625,7 @@ DrawTileLine: ; 40474 (10:4474)
INCLUDE "data/pokedex_entries.asm"
-PokedexToIndex: ; 40ff9 (10:4ff9)
+PokedexToIndex:
; converts the Pokédex number at wd11e to an index
push bc
push hl
@@ -625,7 +646,7 @@ PokedexToIndex: ; 40ff9 (10:4ff9)
pop bc
ret
-IndexToPokedex: ; 41010 (10:5010)
+IndexToPokedex:
; converts the indexédex number at wd11e to a Pokédex number
push bc
push hl
diff --git a/engine/menu/prize_menu.asm b/engine/menu/prize_menu.asm
index 0e904200..f6ca013b 100755
--- a/engine/menu/prize_menu.asm
+++ b/engine/menu/prize_menu.asm
@@ -1,4 +1,4 @@
-CeladonPrizeMenu: ; 5271b (14:671b)
+CeladonPrizeMenu:
ld b,COIN_CASE
call IsItemInBag
jr nz,.havingCoinCase
@@ -13,7 +13,7 @@ CeladonPrizeMenu: ; 5271b (14:671b)
xor a
ld [wCurrentMenuItem],a
ld [wLastMenuItem],a
- ld a,$03
+ ld a,A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys],a
ld a,$03
ld [wMaxMenuItem],a
@@ -21,55 +21,55 @@ CeladonPrizeMenu: ; 5271b (14:671b)
ld [wTopMenuItemY],a
ld a,$01
ld [wTopMenuItemX],a
- call PrintPrizePrice ; 687A
- hlCoord 0, 2
- ld b,$08
- ld c,$10
+ call PrintPrizePrice
+ coord hl, 0, 2
+ ld b, 8
+ ld c, 16
call TextBoxBorder
- call GetPrizeMenuId ;678E
+ call GetPrizeMenuId
call UpdateSprites
ld hl,WhichPrizeTextPtr
call PrintText
call HandleMenuInput ; menu choice handler
bit 1,a ; keypress = B (Cancel)
- jr nz,.NoChoice
+ jr nz, .noChoice
ld a,[wCurrentMenuItem]
- cp a,$03 ; "NO,THANKS" choice
- jr z,.NoChoice
- call HandlePrizeChoice ; 14:68C6
-.NoChoice
+ cp 3 ; "NO,THANKS" choice
+ jr z, .noChoice
+ call HandlePrizeChoice
+.noChoice
ld hl,wd730
res 6,[hl]
ret
-RequireCoinCaseTextPtr: ; 5277e (14:677e)
+RequireCoinCaseTextPtr:
TX_FAR _RequireCoinCaseText
- db $0D
+ TX_WAIT
db "@"
-ExchangeCoinsForPrizesTextPtr: ; 52784 (14:6784)
+ExchangeCoinsForPrizesTextPtr:
TX_FAR _ExchangeCoinsForPrizesText
db "@"
-WhichPrizeTextPtr: ; 52789 (14:6789)
+WhichPrizeTextPtr:
TX_FAR _WhichPrizeText
db "@"
-GetPrizeMenuId: ; 5278e (14:678e)
+GetPrizeMenuId:
; determine which one among the three
; prize-texts has been selected
-; using the text ID (stored in [$FF8C])
+; using the text ID (stored in [hSpriteIndexOrTextID])
; load the three prizes at wd13d-wd13f
; load the three prices at wd141-wd146
; display the three prizes' names
; (distinguishing between Pokemon names
; and Items (specifically TMs) names)
- ld a,[$FF8C]
- sub a,$03 ; prize-texts' id are 3, 4 and 5
- ld [wd12f],a ; prize-texts' id (relative, i.e. 0, 1 or 2)
+ ld a,[hSpriteIndexOrTextID]
+ sub 3 ; prize-texts' id are 3, 4 and 5
+ ld [wWhichPrizeWindow],a ; prize-texts' id (relative, i.e. 0, 1 or 2)
add a
add a
- ld d,$00
+ ld d,0
ld e,a
ld hl,PrizeDifferentMenuPtrs
add hl,de
@@ -78,223 +78,229 @@ GetPrizeMenuId: ; 5278e (14:678e)
ld e,a
inc hl
push hl
- ld hl,W_PRIZE1
- call CopyString ; XXX what does this do
+ ld hl,wPrize1
+ call CopyString
pop hl
ld a,[hli]
ld h,[hl]
ld l,a
- ld de,wd141
- ld bc,$0006
+ ld de,wPrize1Price
+ ld bc,6
call CopyData
- ld a,[wd12f]
- cp a,$02 ;is TM_menu?
+ ld a,[wWhichPrizeWindow]
+ cp 2 ;is TM_menu?
jr nz,.putMonName
- ld a,[W_PRIZE1]
+ ld a,[wPrize1]
ld [wd11e],a
call GetItemName
- hlCoord 2, 4
+ coord hl, 2, 4
call PlaceString
- ld a,[W_PRIZE2]
+ ld a,[wPrize2]
ld [wd11e],a
call GetItemName
- hlCoord 2, 6
+ coord hl, 2, 6
call PlaceString
- ld a,[W_PRIZE3]
+ ld a,[wPrize3]
ld [wd11e],a
call GetItemName
- hlCoord 2, 8
+ coord hl, 2, 8
call PlaceString
jr .putNoThanksText
-.putMonName ; 14:67EC
- ld a,[W_PRIZE1]
+.putMonName
+ ld a,[wPrize1]
ld [wd11e],a
call GetMonName
- hlCoord 2, 4
+ coord hl, 2, 4
call PlaceString
- ld a,[W_PRIZE2]
+ ld a,[wPrize2]
ld [wd11e],a
call GetMonName
- hlCoord 2, 6
+ coord hl, 2, 6
call PlaceString
- ld a,[W_PRIZE3]
+ ld a,[wPrize3]
ld [wd11e],a
call GetMonName
- hlCoord 2, 8
+ coord hl, 2, 8
call PlaceString
-.putNoThanksText ; 14:6819
- hlCoord 2, 10
+.putNoThanksText
+ coord hl, 2, 10
ld de,NoThanksText
call PlaceString
; put prices on the right side of the textbox
- ld de,wd141
- hlCoord 13, 5
+ ld de,wPrize1Price
+ coord hl, 13, 5
; reg. c:
; [low nybble] number of bytes
; [bit 765 = %100] space-padding (not zero-padding)
ld c,(1 << 7 | 2)
; Function $15CD displays BCD value (same routine
; used by text-command $02)
- call PrintBCDNumber ; Print_BCD
- ld de,wd143
- hlCoord 13, 7
- ld c,(%1 << 7 | 2)
call PrintBCDNumber
- ld de,wd145
- hlCoord 13, 9
+ ld de,wPrize2Price
+ coord hl, 13, 7
+ ld c,(1 << 7 | 2)
+ call PrintBCDNumber
+ ld de,wPrize3Price
+ coord hl, 13, 9
ld c,(1 << 7 | 2)
jp PrintBCDNumber
INCLUDE "data/prizes.asm"
-PrintPrizePrice: ; 5287a (14:687a)
- hlCoord 11, 0
- ld b,$01
- ld c,$07
+PrintPrizePrice:
+ coord hl, 11, 0
+ ld b, 1
+ ld c, 7
call TextBoxBorder
- call UpdateSprites ; XXX save OAM?
- hlCoord 12, 0
- ld de,.CoinText
+ call UpdateSprites
+ coord hl, 12, 0
+ ld de, .CoinString
call PlaceString
- hlCoord 13, 1
- ld de,.SixSpacesText
+ coord hl, 13, 1
+ ld de, .SixSpacesString
call PlaceString
- hlCoord 13, 1
+ coord hl, 13, 1
ld de,wPlayerCoins
ld c,%10000010
call PrintBCDNumber
ret
-.CoinText ; 14:68A5
+.CoinString:
db "COIN@"
-.SixSpacesText ; 14:68AA
+.SixSpacesString:
db " @"
-LoadCoinsToSubtract: ; 528b1 (14:68b1)
- ld a,[wd139] ; backup of selected menu_entry
+LoadCoinsToSubtract:
+ ld a,[wWhichPrize]
add a
- ld d,$00
+ ld d,0
ld e,a
- ld hl,wd141 ; first prize's price
+ ld hl,wPrize1Price
add hl,de ; get selected prize's price
xor a
- ld [$FF9F],a
+ ld [hUnusedCoinsByte],a
ld a,[hli]
- ld [$FFA0],a
+ ld [hCoins],a
ld a,[hl]
- ld [$FFA1],a
+ ld [hCoins + 1],a
ret
-HandlePrizeChoice: ; 528c6 (14:68c6)
- ld a,[wCurrentMenuItem] ; selected menu_entry
- ld [wd139],a
- ld d,$00
+HandlePrizeChoice:
+ ld a,[wCurrentMenuItem]
+ ld [wWhichPrize],a
+ ld d,0
ld e,a
- ld hl,W_PRIZE1
+ ld hl,wPrize1
add hl,de
ld a,[hl]
ld [wd11e],a
- ld a,[wd12f]
- cp a,$02 ; is prize a TM?
- jr nz,.GetMonName
+ ld a,[wWhichPrizeWindow]
+ cp 2 ; is prize a TM?
+ jr nz, .getMonName
call GetItemName
- jr .GivePrize
-.GetMonName ; 14:68E3
+ jr .givePrize
+.getMonName
call GetMonName
-.GivePrize ; 14:68E6
+.givePrize
ld hl,SoYouWantPrizeTextPtr
call PrintText
- call YesNoChoice ; yes/no textbox
+ call YesNoChoice
ld a,[wCurrentMenuItem] ; yes/no answer (Y=0, N=1)
and a
- jr nz,.PrintOhFineThen
+ jr nz, .printOhFineThen
call LoadCoinsToSubtract
call HasEnoughCoins
- jr c,.NotEnoughCoins
- ld a,[wd12f]
- cp a,$02
- jr nz,.GiveMon
+ jr c, .notEnoughCoins
+ ld a,[wWhichPrizeWindow]
+ cp $02
+ jr nz, .giveMon
ld a,[wd11e]
ld b,a
ld a,1
ld c,a
- call GiveItem ; GiveItem
- jr nc,.BagFull
- jr .SubtractCoins
-.GiveMon ; 14:6912
+ call GiveItem
+ jr nc, .bagFull
+ jr .subtractCoins
+.giveMon
ld a,[wd11e]
ld [wcf91],a
push af
- call GetPrizeMonLevel ; 14:6977
+ call GetPrizeMonLevel
ld c,a
pop af
ld b,a
call GivePokemon
+
+; If either the party or box was full, wait after displaying message.
push af
- ld a,[wccd3] ; XXX is there room?
+ ld a,[wAddedToParty]
and a
call z,WaitForTextScrollButtonPress
pop af
+
+; If the mon couldn't be given to the player (because both the party and box
+; were full), return without subtracting coins.
ret nc
-.SubtractCoins ; 14:692C
+
+.subtractCoins
call LoadCoinsToSubtract
- ld hl,$FFA1
+ ld hl,hCoins + 1
ld de,wPlayerCoins + 1
ld c,$02 ; how many bytes
- predef SubBCDPredef ; subtract coins (BCD daa operations)
+ predef SubBCDPredef
jp PrintPrizePrice
-.BagFull
+.bagFull
ld hl,PrizeRoomBagIsFullTextPtr
jp PrintText
-.NotEnoughCoins ; 14:6945
+.notEnoughCoins
ld hl,SorryNeedMoreCoinsText
jp PrintText
-.PrintOhFineThen ; 14:694B
+.printOhFineThen
ld hl,OhFineThenTextPtr
jp PrintText
-UnknownData52951: ; 52951 (14:6951)
+UnknownPrizeData:
; XXX what's this?
db $00,$01,$00,$01,$00,$01,$00,$00,$01
-HereYouGoTextPtr: ; 5295a (14:695a)
+HereYouGoTextPtr:
TX_FAR _HereYouGoText
- db $0D
+ TX_WAIT
db "@"
-SoYouWantPrizeTextPtr: ; 52960 (14:6960)
+SoYouWantPrizeTextPtr:
TX_FAR _SoYouWantPrizeText
db "@"
-SorryNeedMoreCoinsText: ; 52965 (14:6965)
+SorryNeedMoreCoinsText:
TX_FAR _SorryNeedMoreCoinsText
- db $0D
+ TX_WAIT
db "@"
-PrizeRoomBagIsFullTextPtr: ; 5296b (14:696b)
+PrizeRoomBagIsFullTextPtr:
TX_FAR _OopsYouDontHaveEnoughRoomText
- db $0D
+ TX_WAIT
db "@"
-OhFineThenTextPtr: ; 52971 (14:6971)
+OhFineThenTextPtr:
TX_FAR _OhFineThenText
- db $0D ; wait keypress (A/B) without blink
+ TX_WAIT
db "@"
-GetPrizeMonLevel: ; 52977 (14:6977)
+GetPrizeMonLevel:
ld a,[wcf91]
ld b,a
ld hl,PrizeMonLevelDictionary
-.loop ; 14:697E
+.loop
ld a,[hli]
cp b
jr z,.matchFound
inc hl
jr .loop
-.matchFound ; 14:6985
+.matchFound
ld a,[hl]
- ld [W_CURENEMYLVL],a
+ ld [wCurEnemyLVL],a
ret
INCLUDE "data/prize_mon_levels.asm"
diff --git a/engine/menu/start_menu.asm b/engine/menu/start_menu.asm
index da17822b..029d8c01 100755
--- a/engine/menu/start_menu.asm
+++ b/engine/menu/start_menu.asm
@@ -1,16 +1,16 @@
-DisplayStartMenu:: ; 2acd (0:2acd)
- ld a,$04 ; hardcoded Bank, not sure what's it refers to
+DisplayStartMenu::
+ ld a,BANK(StartMenu_Pokedex)
ld [H_LOADEDROMBANK],a
- ld [$2000],a ; ROM bank 4
+ ld [MBC1RomBank],a
ld a,[wWalkBikeSurfState] ; walking/biking/surfing
ld [wWalkBikeSurfStateCopy],a
- ld a, (SFX_02_3f - SFX_Headers_02) / 3 ; Start menu sound
+ ld a, SFX_START_MENU
call PlaySound
-RedisplayStartMenu:: ; 2adf (0:2adf)
+RedisplayStartMenu::
callba DrawStartMenu
callba PrintSafariZoneSteps ; print Safari Zone info, if in Safari Zone
- call UpdateSprites ; move sprites
+ call UpdateSprites
.loop
call HandleMenuInput
ld b,a
@@ -24,8 +24,7 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
and a
jr nz,.loop
; if the player pressed tried to go past the top item, wrap around to the bottom
- ld a,[wd74b]
- bit 5,a ; does the player have the pokedex?
+ CheckEvent EVENT_GOT_POKEDEX
ld a,6 ; there are 7 menu items with the pokedex, so the max index is 6
jr nz,.wrapMenuItemId
dec a ; there are only 6 menu items without the pokedex
@@ -37,8 +36,7 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
bit 7,a
jr z,.buttonPressed
; if the player pressed tried to go past the bottom item, wrap around to the top
- ld a,[wd74b]
- bit 5,a ; does the player have the pokedex?
+ CheckEvent EVENT_GOT_POKEDEX
ld a,[wCurrentMenuItem]
ld c,7 ; there are 7 menu items with the pokedex
jr nz,.checkIfPastBottom
@@ -54,13 +52,12 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
.buttonPressed ; A, B, or Start button pressed
call PlaceUnfilledArrowMenuCursor
ld a,[wCurrentMenuItem]
- ld [wcc2d],a ; save current menu item ID
+ ld [wBattleAndStartSavedMenuItem],a ; save current menu selection
ld a,b
and a,%00001010 ; was the Start button or B button pressed?
jp nz,CloseStartMenu
call SaveScreenTilesToBuffer2 ; copy background from wTileMap to wTileMapBackup2
- ld a,[wd74b]
- bit 5,a ; does the player have the pokedex?
+ CheckEvent EVENT_GOT_POKEDEX
ld a,[wCurrentMenuItem]
jr nz,.displayMenuItem
inc a ; adjust position to account for missing pokedex menu item
@@ -79,7 +76,7 @@ RedisplayStartMenu:: ; 2adf (0:2adf)
jp z,StartMenu_Option
; EXIT falls through to here
-CloseStartMenu:: ; 2b70 (0:2b70)
+CloseStartMenu::
call Joypad
ld a,[hJoyPressed]
bit 0,a ; was A button newly pressed?
diff --git a/engine/menu/start_sub_menus.asm b/engine/menu/start_sub_menus.asm
index 589224ab..251d7ae4 100755
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -1,4 +1,4 @@
-StartMenu_Pokedex: ; 13095 (4:7095)
+StartMenu_Pokedex:
predef ShowPokedexMenu
call LoadScreenTilesFromBuffer2 ; restore saved screen
call Delay3
@@ -6,20 +6,20 @@ StartMenu_Pokedex: ; 13095 (4:7095)
call UpdateSprites
jp RedisplayStartMenu
-StartMenu_Pokemon: ; 130a9 (4:70a9)
+StartMenu_Pokemon:
ld a,[wPartyCount]
and a
jp z,RedisplayStartMenu
xor a
ld [wMenuItemToSwap],a
- ld [wd07d],a
+ ld [wPartyMenuTypeOrMessageID],a
ld [wUpdateSpritesEnabled],a
call DisplayPartyMenu
jr .checkIfPokemonChosen
.loop
xor a
ld [wMenuItemToSwap],a
- ld [wd07d],a
+ ld [wPartyMenuTypeOrMessageID],a
call GoBackToPartyMenu
.checkIfPokemonChosen
jr nc,.chosePokemon
@@ -33,14 +33,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld a,FIELD_MOVE_MON_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; display pokemon menu options
- ld hl,wWhichTrade
- ld bc,$020c ; max menu item ID, top menu item Y
+ ld hl,wFieldMoves
+ lb bc, 2, 12 ; max menu item ID, top menu item Y
ld e,5
.adjustMenuVariablesLoop
dec e
jr z,.storeMenuVariables
ld a,[hli]
- and a
+ and a ; end of field moves?
jr z,.storeMenuVariables
inc b
dec c
@@ -50,14 +50,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld hl,wTopMenuItemY
ld a,c
ld [hli],a ; top menu item Y
- ld a,[$fff7]
+ ld a,[hFieldMoveMonMenuTopMenuItemX]
ld [hli],a ; top menu item X
xor a
ld [hli],a ; current menu item ID
inc hl
ld a,b
ld [hli],a ; max menu item ID
- ld a,%00000011 ; A button, B button
+ ld a,A_BUTTON | B_BUTTON
ld [hli],a ; menu watched keys
xor a
ld [hl],a
@@ -81,22 +81,22 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
jp z,.choseStats
ld c,a
ld b,0
- ld hl,wWhichTrade
+ ld hl,wFieldMoves
add hl,bc
jp .choseOutOfBattleMove
.choseSwitch
ld a,[wPartyCount]
cp a,2 ; is there more than one pokemon in the party?
jp c,StartMenu_Pokemon ; if not, no switching
- call SwitchPartyMon_Stats
- ld a,$04 ; swap pokemon positions menu
- ld [wd07d],a
+ call SwitchPartyMon_InitVarOrSwapData ; init [wMenuItemToSwap]
+ ld a,SWAP_MONS_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID],a
call GoBackToPartyMenu
jp .checkIfPokemonChosen
.choseStats
call ClearSprites
- xor a
- ld [wcc49],a
+ xor a ; PLAYER_PARTY_DATA
+ ld [wMonDataLocation],a
predef StatusScreen
predef StatusScreen2
call ReloadMapData
@@ -117,7 +117,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld a,[hli]
ld h,[hl]
ld l,a
- ld a,[W_OBTAINEDBADGES] ; badges obtained
+ ld a,[wObtainedBadges] ; badges obtained
jp [hl]
.outOfBattleMovePointers
dw .cut
@@ -153,23 +153,23 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
bit 1,a ; does the player have the Cascade Badge?
jp z,.newBadgeRequired
predef UsedCut
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,.loop
jp CloseTextDisplay
.surf
bit 4,a ; does the player have the Soul Badge?
jp z,.newBadgeRequired
- callba CheckForForcedBikeSurf
+ callba IsSurfingAllowed
ld hl,wd728
bit 1,[hl]
res 1,[hl]
jp z,.loop
ld a,SURFBOARD
ld [wcf91],a
- ld [wd152],a
+ ld [wPseudoItemID],a
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,.loop
call GBPalWhiteOutWithDelay3
@@ -195,9 +195,9 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
.dig
ld a,ESCAPE_ROPE
ld [wcf91],a
- ld [wd152],a
+ ld [wPseudoItemID],a
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,.loop
call GBPalWhiteOutWithDelay3
@@ -222,7 +222,7 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
res 4,[hl]
ld c,60
call DelayFrames
- call GBPalWhiteOutWithDelay3 ; zero all three palettes and wait 3 V-blanks
+ call GBPalWhiteOutWithDelay3
jp .goBackToMap
.warpToLastPokemonCenterText
TX_FAR _WarpToLastPokemonCenterText
@@ -256,14 +256,14 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
ld a,[H_QUOTIENT + 2]
sbc b
jp nc,.notHealthyEnough
- ld a,[wcc2b]
+ ld a,[wPartyAndBillsPCSavedMenuItem]
push af
ld a,POTION
ld [wcf91],a
- ld [wd152],a
+ ld [wPseudoItemID],a
call UseItem
pop af
- ld [wcc2b],a
+ ld [wPartyAndBillsPCSavedMenuItem],a
jp .loop
.notHealthyEnough ; if current HP is less than 1/5 of max HP
ld hl,.notHealthyEnoughText
@@ -284,8 +284,8 @@ StartMenu_Pokemon: ; 130a9 (4:70a9)
db "@"
; writes a blank tile to all possible menu cursor positions on the party menu
-ErasePartyMenuCursors: ; 132ed (4:72ed)
- hlCoord 0, 1
+ErasePartyMenuCursors:
+ coord hl, 0, 1
ld bc,2 * 20 ; menu cursor positions are 2 rows apart
ld a,6 ; 6 menu cursor positions
.loop
@@ -295,11 +295,11 @@ ErasePartyMenuCursors: ; 132ed (4:72ed)
jr nz,.loop
ret
-ItemMenuLoop: ; 132fc (4:72fc)
+ItemMenuLoop:
call LoadScreenTilesFromBuffer2DisableBGTransfer ; restore saved screen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
-StartMenu_Item: ; 13302 (4:7302)
+StartMenu_Item:
ld a,[wLinkState]
dec a ; is the player in the Colosseum or Trade Centre?
jr nz,.notInCableClubRoom
@@ -308,24 +308,24 @@ StartMenu_Item: ; 13302 (4:7302)
jr .exitMenu
.notInCableClubRoom
ld bc,wNumBagItems
- ld hl,wList
+ ld hl,wListPointer
ld a,c
ld [hli],a
- ld [hl],b ; store item bag pointer at wList (for DisplayListMenuID)
+ ld [hl],b ; store item bag pointer in wListPointer (for DisplayListMenuID)
xor a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld a,ITEMLISTMENU
ld [wListMenuID],a
- ld a,[wcc2c]
+ ld a,[wBagSavedMenuItem]
ld [wCurrentMenuItem],a
call DisplayListMenuID
ld a,[wCurrentMenuItem]
- ld [wcc2c],a
+ ld [wBagSavedMenuItem],a
jr nc,.choseItem
.exitMenu
call LoadScreenTilesFromBuffer2 ; restore saved screen
call LoadTextBoxTilePatterns
- call UpdateSprites ; move sprites
+ call UpdateSprites
jp RedisplayStartMenu
.choseItem
; erase menu cursor (blank each tile in front of an item name)
@@ -354,7 +354,7 @@ StartMenu_Item: ; 13302 (4:7302)
inc hl
inc a ; a = 1
ld [hli],a ; max menu item ID
- ld a,%00000011 ; A button, B button
+ ld a,A_BUTTON | B_BUTTON
ld [hli],a ; menu watched keys
xor a
ld [hl],a ; old menu item id
@@ -381,8 +381,8 @@ StartMenu_Item: ; 13302 (4:7302)
ld a,[wCurrentMenuItem]
and a
jr nz,.tossItem
-.useItem
- ld [wd152],a
+; use item
+ ld [wPseudoItemID],a ; a must be 0 due to above conditional jump
ld a,[wcf91]
cp a,HM_01
jr nc,.useItem_partyMenu
@@ -399,9 +399,9 @@ StartMenu_Item: ; 13302 (4:7302)
jp ItemMenuLoop
.useItem_closeMenu
xor a
- ld [wd152],a
+ ld [wPseudoItemID],a
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
and a
jp z,ItemMenuLoop
jp CloseStartMenu
@@ -409,7 +409,7 @@ StartMenu_Item: ; 13302 (4:7302)
ld a,[wUpdateSpritesEnabled]
push af
call UseItem
- ld a,[wcd6a]
+ ld a,[wActionResultOrTookBattleTurn]
cp a,$02
jp z,.partyMenuNotDisplayed
call GBPalWhiteOutWithDelay3
@@ -423,7 +423,7 @@ StartMenu_Item: ; 13302 (4:7302)
jp ItemMenuLoop
.tossItem
call IsKeyItem
- ld a,[wd124]
+ ld a,[wIsKeyItem]
and a
jr nz,.skipAskingQuantity
ld a,[wcf91]
@@ -438,16 +438,16 @@ StartMenu_Item: ; 13302 (4:7302)
.tossZeroItems
jp ItemMenuLoop
-CannotUseItemsHereText: ; 1342a (4:742a)
+CannotUseItemsHereText:
TX_FAR _CannotUseItemsHereText
db "@"
-CannotGetOffHereText: ; 1342f (4:742f)
+CannotGetOffHereText:
TX_FAR _CannotGetOffHereText
db "@"
; items which bring up the party menu when used
-UsableItems_PartyMenu: ; 13434 (4:7434)
+UsableItems_PartyMenu:
db MOON_STONE
db ANTIDOTE
db BURN_HEAL
@@ -487,7 +487,7 @@ UsableItems_PartyMenu: ; 13434 (4:7434)
db $ff
; items which close the item menu when used
-UsableItems_CloseMenu: ; 13459 (4:7459)
+UsableItems_CloseMenu:
db ESCAPE_ROPE
db ITEMFINDER
db POKE_FLUTE
@@ -496,24 +496,24 @@ UsableItems_CloseMenu: ; 13459 (4:7459)
db SUPER_ROD
db $ff
-StartMenu_TrainerInfo: ; 13460 (4:7460)
+StartMenu_TrainerInfo:
call GBPalWhiteOut
call ClearScreen
- call UpdateSprites ; move sprites
+ call UpdateSprites
ld a,[hTilesetType]
push af
xor a
ld [hTilesetType],a
call DrawTrainerInfo
predef DrawBadges ; draw badges
- ld b,$0d
- call GoPAL_SET
+ ld b, SET_PAL_TRAINER_CARD
+ call RunPaletteCommand
call GBPalNormal
call WaitForTextScrollButtonPress ; wait for button press
call GBPalWhiteOut
call LoadFontTilePatterns
call LoadScreenTilesFromBuffer2 ; restore saved screen
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call ReloadMapData
call LoadGBPal
pop af
@@ -521,39 +521,39 @@ StartMenu_TrainerInfo: ; 13460 (4:7460)
jp RedisplayStartMenu
; loads tile patterns and draws everything except for gym leader faces / badges
-DrawTrainerInfo: ; 1349a (4:749a)
+DrawTrainerInfo:
ld de,RedPicFront
- ld bc,(BANK(RedPicFront) << 8) | $01
- predef Predef3B
+ lb bc, BANK(RedPicFront), $01
+ predef DisplayPicCenteredOrUpperRight
call DisableLCD
- hlCoord 0, 2
+ coord hl, 0, 2
ld a," "
call TrainerInfo_DrawVerticalLine
- hlCoord 1, 2
+ coord hl, 1, 2
call TrainerInfo_DrawVerticalLine
ld hl,vChars2 + $70
ld de,vChars2
ld bc,$70 * 4
call CopyData
- ld hl,TrainerInfoTextBoxTileGraphics ; $7b98 ; trainer info text box tile patterns
+ ld hl,TrainerInfoTextBoxTileGraphics ; trainer info text box tile patterns
ld de,vChars2 + $770
ld bc,$0080
push bc
call TrainerInfo_FarCopyData
- ld hl,BlankLeaderNames ; $7c28
+ ld hl,BlankLeaderNames
ld de,vChars2 + $600
ld bc,$0170
call TrainerInfo_FarCopyData
pop bc
- ld hl,BadgeNumbersTileGraphics ; $7d98 ; badge number tile patterns
+ ld hl,BadgeNumbersTileGraphics ; badge number tile patterns
ld de,vChars1 + $580
call TrainerInfo_FarCopyData
- ld hl,GymLeaderFaceAndBadgeTileGraphics ; $6a9e ; gym leader face and badge tile patterns
+ ld hl,GymLeaderFaceAndBadgeTileGraphics ; gym leader face and badge tile patterns
ld de,vChars2 + $200
ld bc,$0400
ld a,$03
call FarCopyData2
- ld hl,TextBoxGraphics ; $6288
+ ld hl,TextBoxGraphics
ld de,$00d0
add hl,de ; hl = colon tile pattern
ld de,vChars1 + $560
@@ -562,80 +562,80 @@ DrawTrainerInfo: ; 1349a (4:749a)
push bc
call FarCopyData2
pop bc
- ld hl,TrainerInfoTextBoxTileGraphics + $80 ; $7c18 ; background tile pattern
+ ld hl,TrainerInfoTextBoxTileGraphics + $80 ; background tile pattern
ld de,vChars1 + $570
call TrainerInfo_FarCopyData
call EnableLCD
- ld hl,wWhichTrade
+ ld hl,wTrainerInfoTextBoxWidthPlus1
ld a,18 + 1
ld [hli],a
dec a
ld [hli],a
ld [hl],1
- hlCoord 0, 0
+ coord hl, 0, 0
call TrainerInfo_DrawTextBox
- ld hl,wWhichTrade
+ ld hl,wTrainerInfoTextBoxWidthPlus1
ld a,16 + 1
ld [hli],a
dec a
ld [hli],a
ld [hl],3
- hlCoord 1, 10
+ coord hl, 1, 10
call TrainerInfo_DrawTextBox
- hlCoord 0, 10
+ coord hl, 0, 10
ld a,$d7
call TrainerInfo_DrawVerticalLine
- hlCoord 19, 10
+ coord hl, 19, 10
call TrainerInfo_DrawVerticalLine
- hlCoord 6, 9
+ coord hl, 6, 9
ld de,TrainerInfo_BadgesText
call PlaceString
- hlCoord 2, 2
+ coord hl, 2, 2
ld de,TrainerInfo_NameMoneyTimeText
call PlaceString
- hlCoord 7, 2
+ coord hl, 7, 2
ld de,wPlayerName
call PlaceString
- hlCoord 8, 4
+ coord hl, 8, 4
ld de,wPlayerMoney
ld c,$e3
call PrintBCDNumber
- hlCoord 9, 6
- ld de,W_PLAYTIMEHOURS + 1 ; hours
- ld bc,$4103
+ coord hl, 9, 6
+ ld de,wPlayTimeHours ; hours
+ lb bc, LEFT_ALIGN | 1, 3
call PrintNumber
ld [hl],$d6 ; colon tile ID
inc hl
- ld de,W_PLAYTIMEMINUTES + 1 ; minutes
- ld bc,$8102
+ ld de,wPlayTimeMinutes ; minutes
+ lb bc, LEADING_ZEROES | 1, 2
jp PrintNumber
-TrainerInfo_FarCopyData: ; 1357f (4:757f)
- ld a,$0b
+TrainerInfo_FarCopyData:
+ ld a,BANK(TrainerInfoTextBoxTileGraphics)
jp FarCopyData2
-TrainerInfo_NameMoneyTimeText: ; 13584 (4:7584)
+TrainerInfo_NameMoneyTimeText:
db "NAME/"
next "MONEY/"
next "TIME/@"
; $76 is a circle tile
-TrainerInfo_BadgesText: ; 13597 (4:7597)
+TrainerInfo_BadgesText:
db $76,"BADGES",$76,"@"
; draws a text box on the trainer info screen
; height is always 6
; INPUT:
; hl = destination address
-; [wWhichTrade] = width + 1
-; [wTrainerEngageDistance] = width
-; [wTrainerFacingDirection] = distance from the end of a text box row to the start of the next
-TrainerInfo_DrawTextBox: ; 135a0 (4:75a0)
+; [wTrainerInfoTextBoxWidthPlus1] = width
+; [wTrainerInfoTextBoxWidth] = width - 1
+; [wTrainerInfoTextBoxNextRowOffset] = distance from the end of a text box row to the start of the next
+TrainerInfo_DrawTextBox:
ld a,$79 ; upper left corner tile ID
- ld de,$7a7b ; top edge and upper right corner tile ID's
+ lb de, $7a, $7b ; top edge and upper right corner tile ID's
call TrainerInfo_DrawHorizontalEdge ; draw top edge
call TrainerInfo_NextTextBoxRow
- ld a,[wWhichTrade] ; width of the text box plus one
+ ld a,[wTrainerInfoTextBoxWidthPlus1]
ld e,a
ld d,0
ld c,6 ; height of the text box
@@ -647,11 +647,11 @@ TrainerInfo_DrawTextBox: ; 135a0 (4:75a0)
dec c
jr nz,.loop
ld a,$7d ; lower left corner tile ID
- ld de,$777e ; bottom edge and lower right corner tile ID's
+ lb de,$77, $7e ; bottom edge and lower right corner tile ID's
-TrainerInfo_DrawHorizontalEdge: ; 135c3 (4:75c3)
+TrainerInfo_DrawHorizontalEdge:
ld [hli],a ; place left corner tile
- ld a,[wTrainerEngageDistance] ; width of the text box
+ ld a,[wTrainerInfoTextBoxWidth]
ld c,a
ld a,d
.loop
@@ -662,8 +662,8 @@ TrainerInfo_DrawHorizontalEdge: ; 135c3 (4:75c3)
ld [hl],a ; place right corner tile
ret
-TrainerInfo_NextTextBoxRow: ; 135d0 (4:75d0)
- ld a,[wTrainerFacingDirection] ; distance to the start of the next row
+TrainerInfo_NextTextBoxRow:
+ ld a,[wTrainerInfoTextBoxNextRowOffset] ; distance to the start of the next row
.loop
inc hl
dec a
@@ -674,8 +674,8 @@ TrainerInfo_NextTextBoxRow: ; 135d0 (4:75d0)
; INPUT:
; hl = address of top tile in the line
; a = tile ID
-TrainerInfo_DrawVerticalLine: ; 135d8 (4:75d8)
- ld de,20
+TrainerInfo_DrawVerticalLine:
+ ld de,SCREEN_WIDTH
ld c,8
.loop
ld [hl],a
@@ -684,7 +684,7 @@ TrainerInfo_DrawVerticalLine: ; 135d8 (4:75d8)
jr nz,.loop
ret
-StartMenu_SaveReset: ; 135e3 (4:75e3)
+StartMenu_SaveReset:
ld a,[wd72e]
bit 6,a ; is the player using the link feature?
jp nz,Init
@@ -692,7 +692,7 @@ StartMenu_SaveReset: ; 135e3 (4:75e3)
call LoadScreenTilesFromBuffer2 ; restore saved screen
jp HoldTextDisplayOpen
-StartMenu_Option: ; 135f6 (4:75f6)
+StartMenu_Option:
xor a
ld [H_AUTOBGTRANSFERENABLED],a
call ClearScreen
@@ -703,63 +703,66 @@ StartMenu_Option: ; 135f6 (4:75f6)
call UpdateSprites
jp RedisplayStartMenu
-SwitchPartyMon: ; 13613 (4:7613)
- call SwitchPartyMon_Stats
- ld a, [wWhichTrade] ; wWhichTrade
- call SwitchPartyMon_OAM
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
- call SwitchPartyMon_OAM
+SwitchPartyMon:
+ call SwitchPartyMon_InitVarOrSwapData ; swap data
+ ld a, [wSwappedMenuItem]
+ call SwitchPartyMon_ClearGfx
+ ld a, [wCurrentMenuItem]
+ call SwitchPartyMon_ClearGfx
jp RedrawPartyMenu_
-SwitchPartyMon_OAM: ; 13625 (4:7625)
+SwitchPartyMon_ClearGfx:
push af
- ld hl, wTileMap
- ld bc, $28
+ coord hl, 0, 0
+ ld bc, SCREEN_WIDTH * 2
call AddNTimes
- ld c, $28
- ld a, $7f
-.asm_13633
+ ld c, SCREEN_WIDTH * 2
+ ld a, " "
+.clearMonBGLoop ; clear the mon's row in the party menu
ld [hli], a
dec c
- jr nz, .asm_13633
+ jr nz, .clearMonBGLoop
pop af
ld hl, wOAMBuffer
ld bc, $10
call AddNTimes
ld de, $4
ld c, e
-.asm_13645
+.clearMonOAMLoop
ld [hl], $a0
add hl, de
dec c
- jr nz, .asm_13645
+ jr nz, .clearMonOAMLoop
call WaitForSoundToFinish
- ld a, (SFX_02_58 - SFX_Headers_02) / 3
+ ld a, SFX_SWAP
jp PlaySound
-SwitchPartyMon_Stats: ; 13653 (4:7653)
+SwitchPartyMon_InitVarOrSwapData:
+; This is used to initialise [wMenuItemToSwap] and to actually swap the data.
ld a, [wMenuItemToSwap]
- and a
- jr nz, .asm_13661
- ld a, [wWhichPokemon] ; wWhichPokemon
- inc a
+ and a ; has [wMenuItemToSwap] been initialised yet?
+ jr nz, .pickedMonsToSwap
+; If not, initialise [wMenuItemToSwap] so that it matches the current mon.
+ ld a, [wWhichPokemon]
+ inc a ; [wMenuItemToSwap] counts from 1
ld [wMenuItemToSwap], a
ret
-.asm_13661
+.pickedMonsToSwap
xor a
- ld [wd07d], a
+ ld [wPartyMenuTypeOrMessageID], a
ld a, [wMenuItemToSwap]
dec a
ld b, a
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
- ld [wWhichTrade], a ; wWhichTrade
- cp b
- jr nz, .asm_1367b
+ ld a, [wCurrentMenuItem]
+ ld [wSwappedMenuItem], a
+ cp b ; swapping a mon with itself?
+ jr nz, .swappingDifferentMons
+; can't swap a mon with itself
xor a
ld [wMenuItemToSwap], a
- ld [wd07d], a
+ ld [wPartyMenuTypeOrMessageID], a
ret
-.asm_1367b
+.swappingDifferentMons
ld a, b
ld [wMenuItemToSwap], a
push hl
@@ -767,85 +770,85 @@ SwitchPartyMon_Stats: ; 13653 (4:7653)
ld hl, wPartySpecies
ld d, h
ld e, l
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
add l
ld l, a
- jr nc, .asm_1368e
+ jr nc, .noCarry
inc h
-.asm_1368e
+.noCarry
ld a, [wMenuItemToSwap]
add e
ld e, a
- jr nc, .asm_13696
+ jr nc, .noCarry2
inc d
-.asm_13696
+.noCarry2
ld a, [hl]
- ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld [hSwapTemp], a
ld a, [de]
ld [hl], a
- ld a, [H_DIVIDEND] ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [hSwapTemp]
ld [de], a
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
call AddNTimes
push hl
ld de, wSwitchPartyMonTempBuffer
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
call CopyData
ld hl, wPartyMons
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
ld a, [wMenuItemToSwap]
call AddNTimes
pop de
push hl
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
call CopyData
pop de
ld hl, wSwitchPartyMonTempBuffer
- ld bc, $2c
+ ld bc, wPartyMon2 - wPartyMon1
call CopyData
- ld hl, wPartyMonOT ; wd273
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld hl, wPartyMonOT
+ ld a, [wCurrentMenuItem]
call SkipFixedLengthTextEntries
push hl
ld de, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, wPartyMonOT ; wd273
+ ld hl, wPartyMonOT
ld a, [wMenuItemToSwap]
call SkipFixedLengthTextEntries
pop de
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
pop de
ld hl, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, wPartyMonNicks ; wPartyMonNicks
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld hl, wPartyMonNicks
+ ld a, [wCurrentMenuItem]
call SkipFixedLengthTextEntries
push hl
ld de, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, wPartyMonNicks ; wPartyMonNicks
+ ld hl, wPartyMonNicks
ld a, [wMenuItemToSwap]
call SkipFixedLengthTextEntries
pop de
push hl
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
pop de
ld hl, wSwitchPartyMonTempBuffer
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld a, [wMenuItemToSwap]
- ld [wWhichTrade], a ; wWhichTrade
+ ld [wSwappedMenuItem], a
xor a
ld [wMenuItemToSwap], a
- ld [wd07d], a
+ ld [wPartyMenuTypeOrMessageID], a
pop de
pop hl
ret
diff --git a/engine/menu/status_screen.asm b/engine/menu/status_screen.asm
index b5254694..ef94f13c 100755
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -1,15 +1,15 @@
-DrawHP: ; 128ef (4:68ef)
+DrawHP:
; Draws the HP bar in the stats screen
call GetPredefRegisters
ld a, $1
jr DrawHP_
-DrawHP2: ; 128f6 (4:68f6)
+DrawHP2:
; Draws the HP bar in the party screen
call GetPredefRegisters
ld a, $2
-DrawHP_: ; 128fb (4:68fb)
+DrawHP_:
ld [wHPBarType], a
push hl
ld a, [wLoadedMonHP]
@@ -50,12 +50,12 @@ DrawHP_: ; 128fb (4:68fb)
.printFraction
add hl, bc
ld de, wLoadedMonHP
- ld bc, $203
+ lb bc, 2, 3
call PrintNumber
ld a, "/"
ld [hli], a
ld de, wLoadedMonMaxHP
- ld bc, $203
+ lb bc, 2, 3
call PrintNumber
pop hl
pop de
@@ -63,14 +63,15 @@ DrawHP_: ; 128fb (4:68fb)
; Predef 0x37
-StatusScreen: ; 12953 (4:6953)
+StatusScreen:
call LoadMonData
- ld a, [wcc49]
- cp $2 ; 2 means we're in a PC box
- jr c, .DontRecalculate ; 0x1295b $14
+ ld a, [wMonDataLocation]
+ cp BOX_DATA
+ jr c, .DontRecalculate
+; mon is in a box or daycare
ld a, [wLoadedMonBoxLevel]
ld [wLoadedMonLevel], a
- ld [W_CURENEMYLVL], a
+ ld [wCurEnemyLVL], a
ld hl, wLoadedMonHPExp - 1
ld de, wLoadedMonStats
ld b, $1
@@ -79,95 +80,95 @@ StatusScreen: ; 12953 (4:6953)
ld hl, wd72c
set 1, [hl]
ld a, $33
- ld [$ff24], a ; Reduce the volume
+ ld [rNR50], a ; Reduce the volume
call GBPalWhiteOutWithDelay3
call ClearScreen
- call UpdateSprites ; move sprites (?)
+ call UpdateSprites
call LoadHpBarAndStatusTilePatterns
- ld de, BattleHudTiles1 ; $6080 ; source
+ ld de, BattleHudTiles1 ; source
ld hl, vChars2 + $6d0 ; dest
- ld bc, (BANK(BattleHudTiles1) << 8) + $03 ; bank bytes/8
+ lb bc, BANK(BattleHudTiles1), $03
call CopyVideoDataDouble ; ·│ :L and halfarrow line end
- ld de, BattleHudTiles2 ; $6098
+ ld de, BattleHudTiles2
ld hl, vChars2 + $780
- ld bc, (BANK(BattleHudTiles2) << 8) + $01
+ lb bc, BANK(BattleHudTiles2), $01
call CopyVideoDataDouble ; │
- ld de, BattleHudTiles3 ; $60b0
+ ld de, BattleHudTiles3
ld hl, vChars2 + $760
- ld bc, (BANK(BattleHudTiles3) << 8) + $02
+ lb bc, BANK(BattleHudTiles3), $02
call CopyVideoDataDouble ; ─┘
ld de, PTile
ld hl, vChars2 + $720
- ld bc,(BANK(PTile) << 8 | $01)
+ lb bc, BANK(PTile), (PTileEnd - PTile) / $8
call CopyVideoDataDouble ; P (for PP), inline
ld a, [hTilesetType]
push af
xor a
ld [hTilesetType], a
- hlCoord 19, 1
- ld bc, $060a
+ coord hl, 19, 1
+ lb bc, 6, 10
call DrawLineBox ; Draws the box around name, HP and status
- ld de, $fffa
+ ld de, -6
add hl, de
- ld [hl], $f2 ; . after No ("." is a different one)
+ ld [hl], "⠄" ; . after No ("." is a different one)
dec hl
ld [hl], "№"
- hlCoord 19, 9
- ld bc, $0806
+ coord hl, 19, 9
+ lb bc, 8, 6
call DrawLineBox ; Draws the box around types, ID No. and OT
- hlCoord 10, 9
+ coord hl, 10, 9
ld de, Type1Text
call PlaceString ; "TYPE1/"
- hlCoord 11, 3
+ coord hl, 11, 3
predef DrawHP
- ld hl, wcf25
+ ld hl, wStatusScreenHPBarColor
call GetHealthBarColor
- ld b, $3
- call GoPAL_SET ; SGB palette
- hlCoord 16, 6
+ ld b, SET_PAL_STATUS_SCREEN
+ call RunPaletteCommand
+ coord hl, 16, 6
ld de, wLoadedMonStatus
call PrintStatusCondition
- jr nz, .StatusWritten ; 0x129fc $9
- hlCoord 16, 6
+ jr nz, .StatusWritten
+ coord hl, 16, 6
ld de, OKText
call PlaceString ; "OK"
.StatusWritten
- hlCoord 9, 6
+ coord hl, 9, 6
ld de, StatusText
call PlaceString ; "STATUS/"
- hlCoord 14, 2
+ coord hl, 14, 2
call PrintLevel ; Pokémon level
- ld a, [W_MONHDEXNUM]
+ ld a, [wMonHIndex]
ld [wd11e], a
ld [wd0b5], a
predef IndexToPokedex
- hlCoord 3, 7
+ coord hl, 3, 7
ld de, wd11e
- ld bc, $8103 ; Zero-padded, 3
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; Pokémon no.
- hlCoord 11, 10
+ coord hl, 11, 10
predef PrintMonType
- ld hl, NamePointers2 ; $6a9d
- call .unk_12a7e
+ ld hl, NamePointers2
+ call .GetStringPointer
ld d, h
ld e, l
- hlCoord 9, 1
+ coord hl, 9, 1
call PlaceString ; Pokémon name
- ld hl, OTPointers ; $6a95
- call .unk_12a7e
+ ld hl, OTPointers
+ call .GetStringPointer
ld d, h
ld e, l
- hlCoord 12, 16
+ coord hl, 12, 16
call PlaceString ; OT
- hlCoord 12, 14
+ coord hl, 12, 14
ld de, wLoadedMonOTID
- ld bc, $8205 ; 5
+ lb bc, LEADING_ZEROES | 2, 5
call PrintNumber ; ID Number
ld d, $0
call PrintStatsBox
call Delay3
call GBPalNormal
- hlCoord 1, 0
+ coord hl, 1, 0
call LoadFlippedFrontSpriteByMonIndex ; draw Pokémon picture
ld a, [wcf91]
call PlayCry ; play Pokémon cry
@@ -175,89 +176,92 @@ StatusScreen: ; 12953 (4:6953)
pop af
ld [hTilesetType], a
ret
-.unk_12a7e ; 0x12a7e ; I don't know what this does, iterates over pointers?
- ld a, [wcc49]
+
+.GetStringPointer
+ ld a, [wMonDataLocation]
add a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
- ld a, [wcc49]
- cp $3
+ ld a, [wMonDataLocation]
+ cp DAYCARE_DATA
ret z
ld a, [wWhichPokemon]
jp SkipFixedLengthTextEntries
-OTPointers: ; 12a95 (4:6a95)
+OTPointers:
dw wPartyMonOT
dw wEnemyMonOT
dw wBoxMonOT
- dw W_DAYCAREMONOT
+ dw wDayCareMonOT
-NamePointers2: ; 12a9d (4:6a9d)
+NamePointers2:
dw wPartyMonNicks
dw wEnemyMonNicks
dw wBoxMonNicks
- dw W_DAYCAREMONNAME
+ dw wDayCareMonName
-Type1Text: ; 12aa5 (4:6aa5)
+Type1Text:
db "TYPE1/", $4e
-Type2Text: ; 12aac (4:6aac)
+Type2Text:
db "TYPE2/", $4e
-IDNoText: ; 12ab3 (4:6ab3)
- db $73, "№", "/", $4e
+IDNoText:
+ db $73, "№/", $4e
-OTText: ; 12ab7 (4:6ab7)
- db "OT/", $4e, "@"
+OTText:
+ db "OT/"
+ next "@"
-StatusText: ; 12abc (4:6abc)
+StatusText:
db "STATUS/@"
-OKText: ; 12ac4 (4:6ac4)
+OKText:
db "OK@"
; Draws a line starting from hl high b and wide c
-DrawLineBox ; 0x12ac7
- ld de, $0014 ; New line
+DrawLineBox:
+ ld de, SCREEN_WIDTH ; New line
.PrintVerticalLine
ld [hl], $78 ; │
add hl, de
dec b
- jr nz, .PrintVerticalLine ; 0x12ace $fa
+ jr nz, .PrintVerticalLine
ld [hl], $77 ; ┘
dec hl
.PrintHorizLine
ld [hl], $76 ; ─
dec hl
dec c
- jr nz, .PrintHorizLine ; 0x12ad7 $fa
+ jr nz, .PrintHorizLine
ld [hl], $6f ; ← (halfarrow ending)
ret
-PTile: ; 12adc (4:6adc) ; This is a single 1bpp "P" tile
+PTile: ; This is a single 1bpp "P" tile
INCBIN "gfx/p_tile.1bpp"
+PTileEnd:
-PrintStatsBox: ; 12ae4 (4:6ae4)
+PrintStatsBox:
ld a, d
and a ; a is 0 from the status screen
- jr nz, .DifferentBox ; 0x12ae6 $12
- hlCoord 0, 8
- ld b, $8
- ld c, $8
+ jr nz, .DifferentBox
+ coord hl, 0, 8
+ ld b, 8
+ ld c, 8
call TextBoxBorder ; Draws the box
- hlCoord 1, 9 ; Start printing stats from here
+ coord hl, 1, 9 ; Start printing stats from here
ld bc, $0019 ; Number offset
- jr .PrintStats ; 0x12af8 $10
+ jr .PrintStats
.DifferentBox
- hlCoord 9, 2
- ld b, $8
- ld c, $9
+ coord hl, 9, 2
+ ld b, 8
+ ld c, 9
call TextBoxBorder
- hlCoord 11, 3
+ coord hl, 11, 3
ld bc, $0018
.PrintStats
push bc
@@ -268,7 +272,7 @@ PrintStatsBox: ; 12ae4 (4:6ae4)
pop bc
add hl, bc
ld de, wLoadedMonAttack
- ld bc, $0203 ; three digits
+ lb bc, 2, 3
call PrintStat
ld de, wLoadedMonDefense
call PrintStat
@@ -276,27 +280,27 @@ PrintStatsBox: ; 12ae4 (4:6ae4)
call PrintStat
ld de, wLoadedMonSpecial
jp PrintNumber
-PrintStat
+PrintStat:
push hl
call PrintNumber
pop hl
- ld de, $0028
+ ld de, SCREEN_WIDTH * 2
add hl, de
ret
-StatsText: ; 12b3a (4:6b3a)
+StatsText:
db "ATTACK"
next "DEFENSE"
next "SPEED"
next "SPECIAL@"
-StatusScreen2: ; 12b57 (4:6b57)
+StatusScreen2:
ld a, [hTilesetType]
push af
xor a
ld [hTilesetType], a
- ld [$ffba], a
- ld bc, $0005
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld bc, NUM_MOVES + 1
ld hl, wMoves
call FillMemory
ld hl, wLoadedMonMoves
@@ -304,42 +308,42 @@ StatusScreen2: ; 12b57 (4:6b57)
ld bc, NUM_MOVES
call CopyData
callab FormatMovesString
- hlCoord 9, 2
- ld bc, $050a
+ coord hl, 9, 2
+ lb bc, 5, 10
call ClearScreenArea ; Clear under name
- hlCoord 19, 3
+ coord hl, 19, 3
ld [hl], $78
- hlCoord 0, 8
- ld b, $8
- ld c, $12
+ coord hl, 0, 8
+ ld b, 8
+ ld c, 18
call TextBoxBorder ; Draw move container
- hlCoord 2, 9
+ coord hl, 2, 9
ld de, wMovesString
call PlaceString ; Print moves
- ld a, [wcd6c]
+ ld a, [wNumMovesMinusOne]
inc a
ld c, a
ld a, $4
sub c
ld b, a ; Number of moves ?
- hlCoord 11, 10
- ld de, $0028
- ld a, $72
- call Func_12ccb ; Print "PP"
+ coord hl, 11, 10
+ ld de, SCREEN_WIDTH * 2
+ ld a, $72 ; special P tile id
+ call StatusScreen_PrintPP ; Print "PP"
ld a, b
and a
- jr z, .InitPP ; 0x12bb3 $6
+ jr z, .InitPP
ld c, a
ld a, "-"
- call Func_12ccb ; Fill the rest with --
-.InitPP ; 12bbb
+ call StatusScreen_PrintPP ; Fill the rest with --
+.InitPP
ld hl, wLoadedMonMoves
- deCoord 14, 10
- ld b, $0
-.PrintPP ; 12bc3
+ coord de, 14, 10
+ ld b, 0
+.PrintPP
ld a, [hli]
and a
- jr z, .PPDone ; 0x12bc5 $4a
+ jr z, .PPDone
push bc
push hl
push de
@@ -356,24 +360,24 @@ StatusScreen2: ; 12b57 (4:6b57)
pop de
pop hl
push hl
- ld bc, $0014
+ ld bc, wPartyMon1PP - wPartyMon1Moves - 1
add hl, bc
ld a, [hl]
and $3f
- ld [wcd71], a
+ ld [wStatusScreenCurrentPP], a
ld h, d
ld l, e
push hl
- ld de, wcd71
- ld bc, $0102
+ ld de, wStatusScreenCurrentPP
+ lb bc, 1, 2
call PrintNumber
ld a, "/"
ld [hli], a
- ld de, wd11e
- ld bc, $0102
+ ld de, wMaxPP
+ lb bc, 1, 2
call PrintNumber
pop hl
- ld de, $0028
+ ld de, SCREEN_WIDTH * 2
add hl, de
ld d, h
ld e, l
@@ -382,19 +386,19 @@ StatusScreen2: ; 12b57 (4:6b57)
inc b
ld a, b
cp $4
- jr nz, .PrintPP ; 0x12c0f $b2
+ jr nz, .PrintPP
.PPDone
- hlCoord 9, 3
- ld de, EXPPointsText
+ coord hl, 9, 3
+ ld de, StatusScreenExpText
call PlaceString
- ld a, [wLoadedMonLevel] ; level
+ ld a, [wLoadedMonLevel]
push af
cp MAX_LEVEL
- jr z, .Level100 ; 0x12c20 $4
+ jr z, .Level100
inc a
ld [wLoadedMonLevel], a ; Increase temporarily if not 100
.Level100
- hlCoord 14, 6
+ coord hl, 14, 6
ld [hl], $70 ; 1-tile "to"
inc hl
inc hl
@@ -402,25 +406,25 @@ StatusScreen2: ; 12b57 (4:6b57)
pop af
ld [wLoadedMonLevel], a
ld de, wLoadedMonExp
- hlCoord 12, 4
- ld bc, $0307
+ coord hl, 12, 4
+ lb bc, 3, 7
call PrintNumber ; exp
- call .asm_12c86
+ call CalcExpToLevelUp
ld de, wLoadedMonExp
- hlCoord 7, 6
- ld bc, $0307
- call PrintNumber
- hlCoord 9, 0
- call Func_12cc3
- hlCoord 9, 1
- call Func_12cc3
- ld a, [W_MONHDEXNUM]
+ coord hl, 7, 6
+ lb bc, 3, 7
+ call PrintNumber ; exp needed to level up
+ coord hl, 9, 0
+ call StatusScreen_ClearName
+ coord hl, 9, 1
+ call StatusScreen_ClearName
+ ld a, [wMonHIndex]
ld [wd11e], a
call GetMonName
- hlCoord 9, 1
+ coord hl, 9, 1
call PlaceString
ld a, $1
- ld [$ffba], a
+ ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
call WaitForTextScrollButtonPress ; wait for button
pop af
@@ -428,28 +432,29 @@ StatusScreen2: ; 12b57 (4:6b57)
ld hl, wd72c
res 1, [hl]
ld a, $77
- ld [$ff24], a
+ ld [rNR50], a
call GBPalWhiteOut
jp ClearScreen
-.asm_12c86 ; This does some magic with lvl/exp?
- ld a, [wLoadedMonLevel] ; Load level
+
+CalcExpToLevelUp:
+ ld a, [wLoadedMonLevel]
cp MAX_LEVEL
- jr z, .asm_12ca7 ; 0x12c8b $1a ; If 100
+ jr z, .atMaxLevel
inc a
ld d, a
callab CalcExperience
ld hl, wLoadedMonExp + 2
- ld a, [$ff98]
+ ld a, [hExperience + 2]
sub [hl]
ld [hld], a
- ld a, [$ff97]
+ ld a, [hExperience + 1]
sbc [hl]
ld [hld], a
- ld a, [$ff96]
+ ld a, [hExperience]
sbc [hl]
ld [hld], a
ret
-.asm_12ca7
+.atMaxLevel
ld hl, wLoadedMonExp
xor a
ld [hli], a
@@ -457,21 +462,20 @@ StatusScreen2: ; 12b57 (4:6b57)
ld [hl], a
ret
-EXPPointsText: ; 12caf (4:6caf)
- db "EXP POINTS", $4e
-
-LevelUpText: ; 12cba (4:6cba)
- db "LEVEL UP@"
+StatusScreenExpText:
+ db "EXP POINTS"
+ next "LEVEL UP@"
-Func_12cc3: ; 12cc3 (4:6cc3)
- ld bc, $a
- ld a, $7f
+StatusScreen_ClearName:
+ ld bc, 10
+ ld a, " "
jp FillMemory
-Func_12ccb: ; 12ccb (4:6ccb)
+StatusScreen_PrintPP:
+; print PP or -- c times, going down two rows each time
ld [hli], a
ld [hld], a
add hl, de
dec c
- jr nz, Func_12ccb
+ jr nz, StatusScreen_PrintPP
ret
diff --git a/engine/menu/swap_items.asm b/engine/menu/swap_items.asm
new file mode 100644
index 00000000..b1fa78be
--- /dev/null
+++ b/engine/menu/swap_items.asm
@@ -0,0 +1,149 @@
+HandleItemListSwapping:
+ ld a,[wListMenuID]
+ cp a,ITEMLISTMENU
+ jp nz,DisplayListMenuIDLoop ; only rearrange item list menus
+ push hl
+ ld hl,wListPointer
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ inc hl ; hl = beginning of list entries
+ ld a,[wCurrentMenuItem]
+ ld b,a
+ ld a,[wListScrollOffset]
+ add b
+ add a
+ ld c,a
+ ld b,0
+ add hl,bc ; hl = address of currently selected item entry
+ ld a,[hl]
+ pop hl
+ inc a
+ jp z,DisplayListMenuIDLoop ; ignore attempts to swap the Cancel menu item
+ ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
+ and a ; has the first item to swap already been chosen?
+ jr nz,.swapItems
+; if not, set the currently selected item as the first item
+ ld a,[wCurrentMenuItem]
+ inc a
+ ld b,a
+ ld a,[wListScrollOffset] ; index of top (visible) menu item within the list
+ add b
+ ld [wMenuItemToSwap],a ; ID of item chosen for swapping (counts from 1)
+ ld c,20
+ call DelayFrames
+ jp DisplayListMenuIDLoop
+.swapItems
+ ld a,[wCurrentMenuItem]
+ inc a
+ ld b,a
+ ld a,[wListScrollOffset]
+ add b
+ ld b,a
+ ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
+ cp b ; is the currently selected item the same as the first item to swap?
+ jp z,DisplayListMenuIDLoop ; ignore attempts to swap an item with itself
+ dec a
+ ld [wMenuItemToSwap],a ; ID of item chosen for swapping (counts from 1)
+ ld c,20
+ call DelayFrames
+ push hl
+ push de
+ ld hl,wListPointer
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ inc hl ; hl = beginning of list entries
+ ld d,h
+ ld e,l ; de = beginning of list entries
+ ld a,[wCurrentMenuItem]
+ ld b,a
+ ld a,[wListScrollOffset]
+ add b
+ add a
+ ld c,a
+ ld b,0
+ add hl,bc ; hl = address of currently selected item entry
+ ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
+ add a
+ add e
+ ld e,a
+ jr nc,.noCarry
+ inc d
+.noCarry ; de = address of first item to swap
+ ld a,[de]
+ ld b,a
+ ld a,[hli]
+ cp b
+ jr z,.swapSameItemType
+.swapDifferentItems
+ ld [$ff95],a ; [$ff95] = second item ID
+ ld a,[hld]
+ ld [$ff96],a ; [$ff96] = second item quantity
+ ld a,[de]
+ ld [hli],a ; put first item ID in second item slot
+ inc de
+ ld a,[de]
+ ld [hl],a ; put first item quantity in second item slot
+ ld a,[$ff96]
+ ld [de],a ; put second item quantity in first item slot
+ dec de
+ ld a,[$ff95]
+ ld [de],a ; put second item ID in first item slot
+ xor a
+ ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
+ pop de
+ pop hl
+ jp DisplayListMenuIDLoop
+.swapSameItemType
+ inc de
+ ld a,[hl]
+ ld b,a
+ ld a,[de]
+ add b ; a = sum of both item quantities
+ cp a,100 ; is the sum too big for one item slot?
+ jr c,.combineItemSlots
+; swap enough items from the first slot to max out the second slot if they can't be combined
+ sub a,99
+ ld [de],a
+ ld a,99
+ ld [hl],a
+ jr .done
+.combineItemSlots
+ ld [hl],a ; put the sum in the second item slot
+ ld hl,wListPointer
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ dec [hl] ; decrease the number of items
+ ld a,[hl]
+ ld [wListCount],a ; update number of items variable
+ cp a,1
+ jr nz,.skipSettingMaxMenuItemID
+ ld [wMaxMenuItem],a ; if the number of items is only one now, update the max menu item ID
+.skipSettingMaxMenuItemID
+ dec de
+ ld h,d
+ ld l,e
+ inc hl
+ inc hl ; hl = address of item after first item to swap
+.moveItemsUpLoop ; erase the first item slot and move up all the following item slots to fill the gap
+ ld a,[hli]
+ ld [de],a
+ inc de
+ inc a ; reached the $ff terminator?
+ jr z,.afterMovingItemsUp
+ ld a,[hli]
+ ld [de],a
+ inc de
+ jr .moveItemsUpLoop
+.afterMovingItemsUp
+ xor a
+ ld [wListScrollOffset],a
+ ld [wCurrentMenuItem],a
+.done
+ xor a
+ ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
+ pop de
+ pop hl
+ jp DisplayListMenuIDLoop
diff --git a/engine/menu/text_box.asm b/engine/menu/text_box.asm
new file mode 100644
index 00000000..12067dd4
--- /dev/null
+++ b/engine/menu/text_box.asm
@@ -0,0 +1,767 @@
+; function to draw various text boxes
+DisplayTextBoxID_:
+ ld a,[wTextBoxID]
+ cp a,TWO_OPTION_MENU
+ jp z,DisplayTwoOptionMenu
+ ld c,a
+ ld hl,TextBoxFunctionTable
+ ld de,3
+ call SearchTextBoxTable
+ jr c,.functionTableMatch
+ ld hl,TextBoxCoordTable
+ ld de,5
+ call SearchTextBoxTable
+ jr c,.coordTableMatch
+ ld hl,TextBoxTextAndCoordTable
+ ld de,9
+ call SearchTextBoxTable
+ jr c,.textAndCoordTableMatch
+.done
+ ret
+.functionTableMatch
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a ; hl = address of function
+ ld de,.done
+ push de
+ jp [hl] ; jump to the function
+.coordTableMatch
+ call GetTextBoxIDCoords
+ call GetAddressOfScreenCoords
+ call TextBoxBorder
+ ret
+.textAndCoordTableMatch
+ call GetTextBoxIDCoords
+ push hl
+ call GetAddressOfScreenCoords
+ call TextBoxBorder
+ pop hl
+ call GetTextBoxIDText
+ ld a,[wd730]
+ push af
+ ld a,[wd730]
+ set 6,a ; no pauses between printing each letter
+ ld [wd730],a
+ call PlaceString
+ pop af
+ ld [wd730],a
+ call UpdateSprites
+ ret
+
+; function to search a table terminated with $ff for a byte matching c in increments of de
+; sets carry flag if a match is found and clears carry flag if not
+SearchTextBoxTable:
+ dec de
+.loop
+ ld a,[hli]
+ cp a,$ff
+ jr z,.notFound
+ cp c
+ jr z,.found
+ add hl,de
+ jr .loop
+.found
+ scf
+.notFound
+ ret
+
+; function to load coordinates from the TextBoxCoordTable or the TextBoxTextAndCoordTable
+; INPUT:
+; hl = address of coordinates
+; OUTPUT:
+; b = height
+; c = width
+; d = row of upper left corner
+; e = column of upper left corner
+GetTextBoxIDCoords:
+ ld a,[hli] ; column of upper left corner
+ ld e,a
+ ld a,[hli] ; row of upper left corner
+ ld d,a
+ ld a,[hli] ; column of lower right corner
+ sub e
+ dec a
+ ld c,a ; c = width
+ ld a,[hli] ; row of lower right corner
+ sub d
+ dec a
+ ld b,a ; b = height
+ ret
+
+; function to load a text address and text coordinates from the TextBoxTextAndCoordTable
+GetTextBoxIDText:
+ ld a,[hli]
+ ld e,a
+ ld a,[hli]
+ ld d,a ; de = address of text
+ push de ; save text address
+ ld a,[hli]
+ ld e,a ; column of upper left corner of text
+ ld a,[hl]
+ ld d,a ; row of upper left corner of text
+ call GetAddressOfScreenCoords
+ pop de ; restore text address
+ ret
+
+; function to point hl to the screen coordinates
+; INPUT:
+; d = row
+; e = column
+; OUTPUT:
+; hl = address of upper left corner of text box
+GetAddressOfScreenCoords:
+ push bc
+ coord hl, 0, 0
+ ld bc,20
+.loop ; loop to add d rows to the base address
+ ld a,d
+ and a
+ jr z,.addedRows
+ add hl,bc
+ dec d
+ jr .loop
+.addedRows
+ pop bc
+ add hl,de
+ ret
+
+; Format:
+; 00: text box ID
+; 01-02: function address
+TextBoxFunctionTable:
+ dbw MONEY_BOX, DisplayMoneyBox
+ dbw BUY_SELL_QUIT_MENU, DoBuySellQuitMenu
+ dbw FIELD_MOVE_MON_MENU, DisplayFieldMoveMonMenu
+ db $ff ; terminator
+
+; Format:
+; 00: text box ID
+; 01: column of upper left corner
+; 02: row of upper left corner
+; 03: column of lower right corner
+; 04: row of lower right corner
+TextBoxCoordTable:
+ db MESSAGE_BOX, 0, 12, 19, 17
+ db $03, 0, 0, 19, 14
+ db $07, 0, 0, 11, 6
+ db LIST_MENU_BOX, 4, 2, 19, 12
+ db $10, 7, 0, 19, 17
+ db MON_SPRITE_POPUP, 6, 4, 14, 13
+ db $ff ; terminator
+
+; Format:
+; 00: text box ID
+; 01: column of upper left corner
+; 02: row of upper left corner
+; 03: column of lower right corner
+; 04: row of lower right corner
+; 05-06: address of text
+; 07: column of beginning of text
+; 08: row of beginning of text
+; table of window positions and corresponding text [key, start column, start row, end column, end row, text pointer [2 bytes], text column, text row]
+TextBoxTextAndCoordTable:
+ db JP_MOCHIMONO_MENU_TEMPLATE
+ db 0,0,14,17 ; text box coordinates
+ dw JapaneseMochimonoText
+ db 3,0 ; text coordinates
+
+ db USE_TOSS_MENU_TEMPLATE
+ db 13,10,19,14 ; text box coordinates
+ dw UseTossText
+ db 15,11 ; text coordinates
+
+ db JP_SAVE_MESSAGE_MENU_TEMPLATE
+ db 0,0,7,5 ; text box coordinates
+ dw JapaneseSaveMessageText
+ db 2,2 ; text coordinates
+
+ db JP_SPEED_OPTIONS_MENU_TEMPLATE
+ db 0,6,5,10 ; text box coordinates
+ dw JapaneseSpeedOptionsText
+ db 2,7 ; text coordinates
+
+ db BATTLE_MENU_TEMPLATE
+ db 8,12,19,17 ; text box coordinates
+ dw BattleMenuText
+ db 10,14 ; text coordinates
+
+ db SAFARI_BATTLE_MENU_TEMPLATE
+ db 0,12,19,17 ; text box coordinates
+ dw SafariZoneBattleMenuText
+ db 2,14 ; text coordinates
+
+ db SWITCH_STATS_CANCEL_MENU_TEMPLATE
+ db 11,11,19,17 ; text box coordinates
+ dw SwitchStatsCancelText
+ db 13,12 ; text coordinates
+
+ db BUY_SELL_QUIT_MENU_TEMPLATE
+ db 0,0,10,6 ; text box coordinates
+ dw BuySellQuitText
+ db 2,1 ; text coordinates
+
+ db MONEY_BOX_TEMPLATE
+ db 11,0,19,2 ; text box coordinates
+ dw MoneyText
+ db 13,0 ; text coordinates
+
+ db JP_AH_MENU_TEMPLATE
+ db 7,6,11,10 ; text box coordinates
+ dw JapaneseAhText
+ db 8,8 ; text coordinates
+
+ db JP_POKEDEX_MENU_TEMPLATE
+ db 11,8,19,17 ; text box coordinates
+ dw JapanesePokedexMenu
+ db 12,10 ; text coordinates
+
+; note that there is no terminator
+
+BuySellQuitText:
+ db "BUY"
+ next "SELL"
+ next "QUIT@@"
+
+UseTossText:
+ db "USE"
+ next "TOSS@"
+
+JapaneseSaveMessageText:
+ db "きろく"
+ next "メッセージ@"
+
+JapaneseSpeedOptionsText:
+ db "はやい"
+ next "おそい@"
+
+MoneyText:
+ db "MONEY@"
+
+JapaneseMochimonoText:
+ db "もちもの@"
+
+JapaneseMainMenuText:
+ db "つづきから"
+ next "さいしょから@"
+
+BattleMenuText:
+ db "FIGHT ",$E1,$E2
+ next "ITEM RUN@"
+
+SafariZoneBattleMenuText:
+ db "BALL× BAIT"
+ next "THROW ROCK RUN@"
+
+SwitchStatsCancelText:
+ db "SWITCH"
+ next "STATS"
+ next "CANCEL@"
+
+JapaneseAhText:
+ db "アッ!@"
+
+JapanesePokedexMenu:
+ db "データをみる"
+ next "なきごえ"
+ next "ぶんぷをみる"
+ next "キャンセル@"
+
+DisplayMoneyBox:
+ ld hl, wd730
+ set 6, [hl]
+ ld a, MONEY_BOX_TEMPLATE
+ ld [wTextBoxID], a
+ call DisplayTextBoxID
+ coord hl, 13, 1
+ ld b, 1
+ ld c, 6
+ call ClearScreenArea
+ coord hl, 12, 1
+ ld de, wPlayerMoney
+ ld c, $a3
+ call PrintBCDNumber
+ ld hl, wd730
+ res 6, [hl]
+ ret
+
+CurrencyString:
+ db " ¥@"
+
+DoBuySellQuitMenu:
+ ld a, [wd730]
+ set 6, a ; no printing delay
+ ld [wd730], a
+ xor a
+ ld [wChosenMenuItem], a
+ ld a, BUY_SELL_QUIT_MENU_TEMPLATE
+ ld [wTextBoxID], a
+ call DisplayTextBoxID
+ ld a, A_BUTTON | B_BUTTON
+ ld [wMenuWatchedKeys], a
+ ld a, $2
+ ld [wMaxMenuItem], a
+ ld a, $1
+ ld [wTopMenuItemY], a
+ ld a, $1
+ ld [wTopMenuItemX], a
+ xor a
+ ld [wCurrentMenuItem], a
+ ld [wLastMenuItem], a
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld a, [wd730]
+ res 6, a ; turn on the printing delay
+ ld [wd730], a
+ call HandleMenuInput
+ call PlaceUnfilledArrowMenuCursor
+ bit 0, a ; was A pressed?
+ jr nz, .pressedA
+ bit 1, a ; was B pressed? (always true since only A/B are watched)
+ jr z, .pressedA
+ ld a, CANCELLED_MENU
+ ld [wMenuExitMethod], a
+ jr .quit
+.pressedA
+ ld a, CHOSE_MENU_ITEM
+ ld [wMenuExitMethod], a
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
+ ld b, a
+ ld a, [wMaxMenuItem]
+ cp b
+ jr z, .quit
+ ret
+.quit
+ ld a, CANCELLED_MENU
+ ld [wMenuExitMethod], a
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
+ scf
+ ret
+
+; displays a menu with two options to choose from
+; b = Y of upper left corner of text region
+; c = X of upper left corner of text region
+; hl = address where the text box border should be drawn
+DisplayTwoOptionMenu:
+ push hl
+ ld a, [wd730]
+ set 6, a ; no printing delay
+ ld [wd730], a
+
+; pointless because both values are overwritten before they are read
+ xor a
+ ld [wChosenMenuItem], a
+ ld [wMenuExitMethod], a
+
+ ld a, A_BUTTON | B_BUTTON
+ ld [wMenuWatchedKeys], a
+ ld a, $1
+ ld [wMaxMenuItem], a
+ ld a, b
+ ld [wTopMenuItemY], a
+ ld a, c
+ ld [wTopMenuItemX], a
+ xor a
+ ld [wLastMenuItem], a
+ ld [wMenuWatchMovingOutOfBounds], a
+ push hl
+ ld hl, wTwoOptionMenuID
+ bit 7, [hl] ; select second menu item by default?
+ res 7, [hl]
+ jr z, .storeCurrentMenuItem
+ inc a
+.storeCurrentMenuItem
+ ld [wCurrentMenuItem], a
+ pop hl
+ push hl
+ push hl
+ call TwoOptionMenu_SaveScreenTiles
+ ld a, [wTwoOptionMenuID]
+ ld hl, TwoOptionMenuStrings
+ ld e, a
+ ld d, $0
+ ld a, $5
+.menuStringLoop
+ add hl, de
+ dec a
+ jr nz, .menuStringLoop
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
+ ld e, l
+ ld d, h
+ pop hl
+ push de
+ ld a, [wTwoOptionMenuID]
+ cp TRADE_CANCEL_MENU
+ jr nz, .notTradeCancelMenu
+ call CableClub_TextBoxBorder
+ jr .afterTextBoxBorder
+.notTradeCancelMenu
+ call TextBoxBorder
+.afterTextBoxBorder
+ call UpdateSprites
+ pop hl
+ ld a, [hli]
+ and a ; put blank line before first menu item?
+ ld bc, 20 + 2
+ jr z, .noBlankLine
+ ld bc, 2 * 20 + 2
+.noBlankLine
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ pop hl
+ add hl, bc
+ call PlaceString
+ ld hl, wd730
+ res 6, [hl] ; turn on the printing delay
+ ld a, [wTwoOptionMenuID]
+ cp NO_YES_MENU
+ jr nz, .notNoYesMenu
+; No/Yes menu
+; this menu type ignores the B button
+; it only seems to be used when confirming the deletion of a save file
+ xor a
+ ld [wTwoOptionMenuID], a
+ ld a, [wFlags_0xcd60]
+ push af
+ push hl
+ ld hl, wFlags_0xcd60
+ bit 5, [hl]
+ set 5, [hl] ; don't play sound when A or B is pressed in menu
+ pop hl
+.noYesMenuInputLoop
+ call HandleMenuInput
+ bit 1, a ; A button pressed?
+ jr nz, .noYesMenuInputLoop ; try again if A was not pressed
+ pop af
+ pop hl
+ ld [wFlags_0xcd60], a
+ ld a, SFX_PRESS_AB
+ call PlaySound
+ jr .pressedAButton
+.notNoYesMenu
+ xor a
+ ld [wTwoOptionMenuID], a
+ call HandleMenuInput
+ pop hl
+ bit 1, a ; A button pressed?
+ jr nz, .choseSecondMenuItem ; automatically choose the second option if B is pressed
+.pressedAButton
+ ld a, [wCurrentMenuItem]
+ ld [wChosenMenuItem], a
+ and a
+ jr nz, .choseSecondMenuItem
+; chose first menu item
+ ld a, CHOSE_FIRST_ITEM
+ ld [wMenuExitMethod], a
+ ld c, 15
+ call DelayFrames
+ call TwoOptionMenu_RestoreScreenTiles
+ and a
+ ret
+.choseSecondMenuItem
+ ld a, 1
+ ld [wCurrentMenuItem], a
+ ld [wChosenMenuItem], a
+ ld a, CHOSE_SECOND_ITEM
+ ld [wMenuExitMethod], a
+ ld c, 15
+ call DelayFrames
+ call TwoOptionMenu_RestoreScreenTiles
+ scf
+ ret
+
+; Some of the wider/taller two option menus will not have the screen areas
+; they cover be fully saved/restored by the two functions below.
+; The bottom and right edges of the menu may remain after the function returns.
+
+TwoOptionMenu_SaveScreenTiles:
+ ld de, wBuffer
+ lb bc, 5, 6
+.loop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .loop
+ push bc
+ ld bc, SCREEN_WIDTH - 6
+ add hl, bc
+ pop bc
+ ld c, $6
+ dec b
+ jr nz, .loop
+ ret
+
+TwoOptionMenu_RestoreScreenTiles:
+ ld de, wBuffer
+ lb bc, 5, 6
+.loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ push bc
+ ld bc, SCREEN_WIDTH - 6
+ add hl, bc
+ pop bc
+ ld c, 6
+ dec b
+ jr nz, .loop
+ call UpdateSprites
+ ret
+
+; Format:
+; 00: byte width
+; 01: byte height
+; 02: byte put blank line before first menu item
+; 03: word text pointer
+TwoOptionMenuStrings:
+ db 4,3,0
+ dw .YesNoMenu
+ db 6,3,0
+ dw .NorthWestMenu
+ db 6,3,0
+ dw .SouthEastMenu
+ db 6,3,0
+ dw .YesNoMenu
+ db 6,3,0
+ dw .NorthEastMenu
+ db 7,3,0
+ dw .TradeCancelMenu
+ db 7,4,1
+ dw .HealCancelMenu
+ db 4,3,0
+ dw .NoYesMenu
+
+.NoYesMenu
+ db "NO"
+ next "YES@"
+.YesNoMenu
+ db "YES"
+ next "NO@"
+.NorthWestMenu
+ db "NORTH"
+ next "WEST@"
+.SouthEastMenu
+ db "SOUTH"
+ next "EAST@"
+.NorthEastMenu
+ db "NORTH"
+ next "EAST@"
+.TradeCancelMenu
+ db "TRADE"
+ next "CANCEL@"
+.HealCancelMenu
+ db "HEAL"
+ next "CANCEL@"
+
+DisplayFieldMoveMonMenu:
+ xor a
+ ld hl, wFieldMoves
+ ld [hli], a ; wFieldMoves
+ ld [hli], a ; wFieldMoves + 1
+ ld [hli], a ; wFieldMoves + 2
+ ld [hli], a ; wFieldMoves + 3
+ ld [hli], a ; wNumFieldMoves
+ ld [hl], 12 ; wFieldMovesLeftmostXCoord
+ call GetMonFieldMoves
+ ld a, [wNumFieldMoves]
+ and a
+ jr nz, .fieldMovesExist
+
+; no field moves
+ coord hl, 11, 11
+ ld b, 5
+ ld c, 7
+ call TextBoxBorder
+ call UpdateSprites
+ ld a, 12
+ ld [hFieldMoveMonMenuTopMenuItemX], a
+ coord hl, 13, 12
+ ld de, PokemonMenuEntries
+ jp PlaceString
+
+.fieldMovesExist
+ push af
+
+; Calculate the text box position and dimensions based on the leftmost X coord
+; of the field move names before adjusting for the number of field moves.
+ coord hl, 0, 11
+ ld a, [wFieldMovesLeftmostXCoord]
+ dec a
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld b, 5
+ ld a, 18
+ sub e
+ ld c, a
+ pop af
+
+; For each field move, move the top of the text box up 2 rows while the leaving
+; the bottom of the text box at the bottom of the screen.
+ ld de, -SCREEN_WIDTH * 2
+.textBoxHeightLoop
+ add hl, de
+ inc b
+ inc b
+ dec a
+ jr nz, .textBoxHeightLoop
+
+; Make space for an extra blank row above the top field move.
+ ld de, -SCREEN_WIDTH
+ add hl, de
+ inc b
+
+ call TextBoxBorder
+ call UpdateSprites
+
+; Calculate the position of the first field move name to print.
+ coord hl, 0, 12
+ ld a, [wFieldMovesLeftmostXCoord]
+ inc a
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld de, -SCREEN_WIDTH * 2
+ ld a, [wNumFieldMoves]
+.calcFirstFieldMoveYLoop
+ add hl, de
+ dec a
+ jr nz, .calcFirstFieldMoveYLoop
+
+ xor a
+ ld [wNumFieldMoves], a
+ ld de, wFieldMoves
+.printNamesLoop
+ push hl
+ ld hl, FieldMoveNames
+ ld a, [de]
+ and a
+ jr z, .donePrintingNames
+ inc de
+ ld b, a ; index of name
+.skipNamesLoop ; skip past names before the name we want
+ dec b
+ jr z, .reachedName
+.skipNameLoop ; skip past current name
+ ld a, [hli]
+ cp "@"
+ jr nz, .skipNameLoop
+ jr .skipNamesLoop
+.reachedName
+ ld b, h
+ ld c, l
+ pop hl
+ push de
+ ld d, b
+ ld e, c
+ call PlaceString
+ ld bc, SCREEN_WIDTH * 2
+ add hl, bc
+ pop de
+ jr .printNamesLoop
+
+.donePrintingNames
+ pop hl
+ ld a, [wFieldMovesLeftmostXCoord]
+ ld [hFieldMoveMonMenuTopMenuItemX], a
+ coord hl, 0, 12
+ ld a, [wFieldMovesLeftmostXCoord]
+ inc a
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld de, PokemonMenuEntries
+ jp PlaceString
+
+FieldMoveNames:
+ db "CUT@"
+ db "FLY@"
+ db "@"
+ db "SURF@"
+ db "STRENGTH@"
+ db "FLASH@"
+ db "DIG@"
+ db "TELEPORT@"
+ db "SOFTBOILED@"
+
+PokemonMenuEntries:
+ db "STATS"
+ next "SWITCH"
+ next "CANCEL@"
+
+GetMonFieldMoves:
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMon1Moves
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld c, NUM_MOVES + 1
+ ld hl, wFieldMoves
+.loop
+ push hl
+.nextMove
+ dec c
+ jr z, .done
+ ld a, [de] ; move ID
+ and a
+ jr z, .done
+ ld b, a
+ inc de
+ ld hl, FieldMoveDisplayData
+.fieldMoveLoop
+ ld a, [hli]
+ cp $ff
+ jr z, .nextMove ; if the move is not a field move
+ cp b
+ jr z, .foundFieldMove
+ inc hl
+ inc hl
+ jr .fieldMoveLoop
+.foundFieldMove
+ ld a, b
+ ld [wLastFieldMoveID], a
+ ld a, [hli] ; field move name index
+ ld b, [hl] ; field move leftmost X coordinate
+ pop hl
+ ld [hli], a ; store name index in wFieldMoves
+ ld a, [wNumFieldMoves]
+ inc a
+ ld [wNumFieldMoves], a
+ ld a, [wFieldMovesLeftmostXCoord]
+ cp b
+ jr c, .skipUpdatingLeftmostXCoord
+ ld a, b
+ ld [wFieldMovesLeftmostXCoord], a
+.skipUpdatingLeftmostXCoord
+ ld a, [wLastFieldMoveID]
+ ld b, a
+ jr .loop
+.done
+ pop hl
+ ret
+
+; Format: [Move id], [name index], [leftmost tile]
+; Move id = id of move
+; Name index = index of name in FieldMoveNames
+; Leftmost tile = -1 + tile column in which the first letter of the move's name should be displayed
+; "SOFTBOILED" is $08 because it has 4 more letters than "SURF", for example, whose value is $0C
+FieldMoveDisplayData:
+ db CUT, $01, $0C
+ db FLY, $02, $0C
+ db $B4, $03, $0C ; unused field move
+ db SURF, $04, $0C
+ db STRENGTH, $05, $0A
+ db FLASH, $06, $0C
+ db DIG, $07, $0C
+ db TELEPORT, $08, $0A
+ db SOFTBOILED, $09, $08
+ db $ff ; list terminator
diff --git a/engine/menu/vending_machine.asm b/engine/menu/vending_machine.asm
index 88cfcf65..aab4adf4 100755
--- a/engine/menu/vending_machine.asm
+++ b/engine/menu/vending_machine.asm
@@ -1,4 +1,4 @@
-VendingMachineMenu: ; 74ee0 (1d:4ee0)
+VendingMachineMenu:
ld hl, VendingMachineText1
call PrintText
ld a, MONEY_BOX
@@ -7,65 +7,66 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0)
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld a, $3
+ ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $3
+ ld a, 3
ld [wMaxMenuItem], a
- ld a, $5
+ ld a, 5
ld [wTopMenuItemY], a
- ld a, $1
+ ld a, 1
ld [wTopMenuItemX], a
ld hl, wd730
set 6, [hl]
- hlCoord 0, 3
- ld b, $8
- ld c, $c
+ coord hl, 0, 3
+ ld b, 8
+ ld c, 12
call TextBoxBorder
call UpdateSprites
- hlCoord 2, 5
+ coord hl, 2, 5
ld de, DrinkText
call PlaceString
- hlCoord 9, 6
+ coord hl, 9, 6
ld de, DrinkPriceText
call PlaceString
ld hl, wd730
res 6, [hl]
call HandleMenuInput
- bit 1, a
- jr nz, .asm_74f93
+ bit 1, a ; pressed B?
+ jr nz, .notThirsty
ld a, [wCurrentMenuItem]
- cp $3
- jr z, .asm_74f93
+ cp 3 ; chose Cancel?
+ jr z, .notThirsty
xor a
- ld [$ff9f], a
- ld [$ffa1], a
+ ld [hMoney], a
+ ld [hMoney + 2], a
ld a, $2
- ld [$ffa0], a
+ ld [hMoney + 1], a
call HasEnoughMoney
jr nc, .enoughMoney
ld hl, VendingMachineText4
jp PrintText
.enoughMoney
- call Func_74fe7
- ld a, [$ffdb]
+ call LoadVendingMachineItem
+ ld a, [hVendingMachineItem]
ld b, a
ld c, 1
call GiveItem
jr nc, .BagFull
- ld b, $3c ; number of times to play the "brrrrr" sound
-.playDeliverySound ; 0x74f63
- ld c, $2
+
+ ld b, 60 ; number of times to play the "brrrrr" sound
+.playDeliverySound
+ ld c, 2
call DelayFrames
push bc
- ld a, (SFX_02_53 - SFX_Headers_02) / 3
+ ld a, SFX_PUSH_BOULDER
call PlaySound
pop bc
dec b
jr nz, .playDeliverySound
-.asm_74f72
+
ld hl, VendingMachineText5
call PrintText
- ld hl, $ffde
+ ld hl, hVendingMachinePrice + 2
ld de, wPlayerMoney + 2
ld c, $3
predef SubBCDPredef
@@ -75,60 +76,64 @@ VendingMachineMenu: ; 74ee0 (1d:4ee0)
.BagFull
ld hl, VendingMachineText6
jp PrintText
-.asm_74f93
+.notThirsty
ld hl, VendingMachineText7
jp PrintText
-VendingMachineText1: ; 74f99 (1d:4f99)
+VendingMachineText1:
TX_FAR _VendingMachineText1
db "@"
-DrinkText: ; 74f9e (1d:4f9e)
+DrinkText:
db "FRESH WATER"
next "SODA POP"
next "LEMONADE"
next "CANCEL@"
-DrinkPriceText: ; 74fc3 (1d:4fc3)
+DrinkPriceText:
db "¥200"
next "¥300"
- next "¥350",$4E,"@"
+ next "¥350"
+ next "@"
-VendingMachineText4: ; 74fd3 (1d:4fd3)
+VendingMachineText4:
TX_FAR _VendingMachineText4
db "@"
-VendingMachineText5: ; 74fd8 (1d:4fd8)
+VendingMachineText5:
TX_FAR _VendingMachineText5
db "@"
-VendingMachineText6: ; 74fdd (1d:4fdd)
+VendingMachineText6:
TX_FAR _VendingMachineText6
db "@"
-VendingMachineText7: ; 74fe2 (1d:4fe2)
+VendingMachineText7:
TX_FAR _VendingMachineText7
db "@"
-Func_74fe7: ; 74fe7 (1d:4fe7)
+LoadVendingMachineItem:
ld hl, VendingPrices
ld a, [wCurrentMenuItem]
add a
add a
- ld d, $0
+ ld d, 0
ld e, a
add hl, de
ld a, [hli]
- ld [$ffdb], a
+ ld [hVendingMachineItem], a
ld a, [hli]
- ld [$ffdc], a
+ ld [hVendingMachinePrice], a
ld a, [hli]
- ld [$ffdd], a
+ ld [hVendingMachinePrice + 1], a
ld a, [hl]
- ld [$ffde], a
+ ld [hVendingMachinePrice + 2], a
ret
-VendingPrices: ; 75000 (1d:5000)
- db FRESH_WATER,$00,$02,$00
- db SODA_POP, $00,$03,$00
- db LEMONADE, $00,$03,$50
+VendingPrices:
+ db FRESH_WATER
+ money 200
+ db SODA_POP
+ money 300
+ db LEMONADE
+ money 350
diff --git a/engine/mon_party_sprites.asm b/engine/mon_party_sprites.asm
index e3323cfc..864ac136 100755
--- a/engine/mon_party_sprites.asm
+++ b/engine/mon_party_sprites.asm
@@ -1,23 +1,23 @@
-AnimatePartyMon_ForceSpeed1: ; 716f7 (1c:56f7)
+AnimatePartyMon_ForceSpeed1:
xor a
ld [wCurrentMenuItem], a
ld b, a
inc a
jr GetAnimationSpeed
-; wcf1f contains the party mon's health bar colors
+; wPartyMenuHPBarColors contains the party mon's health bar colors
; 0: green
; 1: yellow
; 2: red
-AnimatePartyMon: ; 716ff (1c:56ff)
- ld hl, wcf1f
+AnimatePartyMon:
+ ld hl, wPartyMenuHPBarColors
ld a, [wCurrentMenuItem]
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hl]
-GetAnimationSpeed: ; 7170a (1c:570a)
+GetAnimationSpeed:
ld c, a
ld hl, PartyMonSpeeds
add hl, bc
@@ -27,7 +27,7 @@ GetAnimationSpeed: ; 7170a (1c:570a)
ld c, a
add a
ld b, a
- ld a, [wPartyMonAnimCounter]
+ ld a, [wAnimCounter]
and a
jr z, .resetSprites
cp c
@@ -38,11 +38,11 @@ GetAnimationSpeed: ; 7170a (1c:570a)
jr nz, .skipResetTimer
xor a ; reset timer
.skipResetTimer
- ld [wPartyMonAnimCounter], a
+ ld [wAnimCounter], a
jp DelayFrame
.resetSprites
push bc
- ld hl, wcc5b
+ ld hl, wMonPartySpritesSavedOAM
ld de, wOAMBuffer
ld bc, $60
call CopyData
@@ -85,15 +85,15 @@ GetAnimationSpeed: ; 7170a (1c:570a)
; The members of the PartyMonSpeeds array specify the number of V-blanks
; that each frame lasts for green HP, yellow HP, and red HP in order.
; On the naming screen, the yellow HP speed is always used.
-PartyMonSpeeds: ; 71769 (1c:5769)
- db $05,$10,$20
+PartyMonSpeeds:
+ db 5, 16, 32
-LoadMonPartySpriteGfx: ; 7176c (1c:576c)
+LoadMonPartySpriteGfx:
; Load mon party sprite tile patterns into VRAM during V-blank.
ld hl, MonPartySpritePointers
ld a, $1c
-LoadAnimSpriteGfx: ; 71771 (1c:5771)
+LoadAnimSpriteGfx:
; Load animated sprite tile patterns into VRAM during V-blank. hl is the address
; of an array of structures that contain arguments for CopyVideoData and a is
; the number of structures in the array.
@@ -125,14 +125,14 @@ LoadAnimSpriteGfx: ; 71771 (1c:5771)
jr nz, .loop
ret
-LoadMonPartySpriteGfxWithLCDDisabled: ; 71791 (1c:5791)
+LoadMonPartySpriteGfxWithLCDDisabled:
; Load mon party sprite tile patterns into VRAM immediately by disabling the
; LCD.
call DisableLCD
ld hl, MonPartySpritePointers
ld a, $1c
ld bc, $0
-.asm_7179c
+.loop
push af
push bc
push hl
@@ -159,10 +159,10 @@ LoadMonPartySpriteGfxWithLCDDisabled: ; 71791 (1c:5791)
ld c, a
pop af
dec a
- jr nz, .asm_7179c
+ jr nz, .loop
jp EnableLCD
-MonPartySpritePointers: ; 717c0 (1c:57c0)
+MonPartySpritePointers:
dw SlowbroSprite + $c0
db $40 / $10 ; 40 bytes
db BANK(SlowbroSprite)
@@ -303,7 +303,7 @@ MonPartySpritePointers: ; 717c0 (1c:57c0)
db BANK(MonPartySprites)
dw vSprites + $780
-WriteMonPartySpriteOAMByPartyIndex: ; 71868 (1c:5868)
+WriteMonPartySpriteOAMByPartyIndex:
; Write OAM blocks for the party mon in [hPartyMonIndex].
push hl
push de
@@ -315,24 +315,24 @@ WriteMonPartySpriteOAMByPartyIndex: ; 71868 (1c:5868)
add hl, de
ld a, [hl]
call GetPartyMonSpriteID
- ld [wcd5b], a
+ ld [wOAMBaseTile], a
call WriteMonPartySpriteOAM
pop bc
pop de
pop hl
ret
-WriteMonPartySpriteOAMBySpecies: ; 71882 (1c:5882)
+WriteMonPartySpriteOAMBySpecies:
; Write OAM blocks for the party sprite of the species in
; [wMonPartySpriteSpecies].
xor a
ld [hPartyMonIndex], a
ld a, [wMonPartySpriteSpecies]
call GetPartyMonSpriteID
- ld [wcd5b], a
+ ld [wOAMBaseTile], a
jr WriteMonPartySpriteOAM
-UnusedPartyMonSpriteFunction: ; 71890 (1c:5890)
+UnusedPartyMonSpriteFunction:
; This function is unused and doesn't appear to do anything useful. It looks
; like it may have been intended to load the tile patterns and OAM data for
; the mon party sprite associated with the species in [wcf91].
@@ -350,7 +350,7 @@ UnusedPartyMonSpriteFunction: ; 71890 (1c:5890)
ld [wMonPartySpriteSpecies], a
jr WriteMonPartySpriteOAMBySpecies
-.LoadTilePatterns ; 718ac (1c:58ac)
+.LoadTilePatterns
push hl
add a
ld c, a
@@ -370,9 +370,9 @@ UnusedPartyMonSpriteFunction: ; 71890 (1c:5890)
pop hl
jp CopyVideoData
-WriteMonPartySpriteOAM: ; 718c3 (1c:58c3)
+WriteMonPartySpriteOAM:
; Write the OAM blocks for the first animation frame into the OAM buffer and
-; make a copy at wcc5b.
+; make a copy at wMonPartySpritesSavedOAM.
push af
ld c, $10
ld h, wOAMBuffer / $100
@@ -392,11 +392,11 @@ WriteMonPartySpriteOAM: ; 718c3 (1c:58c3)
; we can flip back to it from the second frame by copying it back.
.makeCopy
ld hl, wOAMBuffer
- ld de, wcc5b
+ ld de, wMonPartySpritesSavedOAM
ld bc, $60
jp CopyData
-GetPartyMonSpriteID: ; 718e9 (1c:58e9)
+GetPartyMonSpriteID:
ld [wd11e], a
predef IndexToPokedex
ld a, [wd11e]
@@ -419,5 +419,5 @@ GetPartyMonSpriteID: ; 718e9 (1c:58e9)
INCLUDE "data/mon_party_sprites.asm"
-MonPartySprites: ; 71959 (1c:5959)
+MonPartySprites:
INCBIN "gfx/mon_ow_sprites.2bpp"
diff --git a/engine/multiply_divide.asm b/engine/multiply_divide.asm
index 4aa5fa26..52e86b36 100755
--- a/engine/multiply_divide.asm
+++ b/engine/multiply_divide.asm
@@ -1,143 +1,143 @@
-_Multiply: ; 37d41 (d:7d41)
+_Multiply:
ld a, $8
ld b, a
xor a
- ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
- ld [$ff9b], a
- ld [H_SAVEDNUMTOPRINT], a ; $ff9c
- ld [$ff9d], a
- ld [$ff9e], a
-.asm_37d4f
- ld a, [H_REMAINDER] ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld [H_PRODUCT], a
+ ld [H_MULTIPLYBUFFER], a
+ ld [H_MULTIPLYBUFFER+1], a
+ ld [H_MULTIPLYBUFFER+2], a
+ ld [H_MULTIPLYBUFFER+3], a
+.loop
+ ld a, [H_MULTIPLIER]
srl a
- ld [H_REMAINDER], a ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
- jr nc, .asm_37d77
- ld a, [$ff9e]
+ ld [H_MULTIPLIER], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ jr nc, .smallMultiplier
+ ld a, [H_MULTIPLYBUFFER+3]
ld c, a
- ld a, [$ff98]
+ ld a, [H_MULTIPLICAND+2]
add c
- ld [$ff9e], a
- ld a, [$ff9d]
+ ld [H_MULTIPLYBUFFER+3], a
+ ld a, [H_MULTIPLYBUFFER+2]
ld c, a
- ld a, [$ff97]
+ ld a, [H_MULTIPLICAND+1]
adc c
- ld [$ff9d], a
- ld a, [H_SAVEDNUMTOPRINT] ; $ff9c
+ ld [H_MULTIPLYBUFFER+2], a
+ ld a, [H_MULTIPLYBUFFER+1]
ld c, a
- ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
+ ld a, [H_MULTIPLICAND] ; (aliases: H_MULTIPLICAND)
adc c
- ld [H_SAVEDNUMTOPRINT], a ; $ff9c
- ld a, [$ff9b]
+ ld [H_MULTIPLYBUFFER+1], a
+ ld a, [H_MULTIPLYBUFFER]
ld c, a
- ld a, [H_DIVIDEND] ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [H_PRODUCT] ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
adc c
- ld [$ff9b], a
-.asm_37d77
+ ld [H_MULTIPLYBUFFER], a
+.smallMultiplier
dec b
- jr z, .asm_37d94
- ld a, [$ff98]
+ jr z, .done
+ ld a, [H_MULTIPLICAND+2]
sla a
- ld [$ff98], a
- ld a, [$ff97]
+ ld [H_MULTIPLICAND+2], a
+ ld a, [H_MULTIPLICAND+1]
rl a
- ld [$ff97], a
- ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
+ ld [H_MULTIPLICAND+1], a
+ ld a, [H_MULTIPLICAND]
rl a
- ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
- ld a, [H_DIVIDEND] ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld [H_MULTIPLICAND], a
+ ld a, [H_PRODUCT]
rl a
- ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
- jr .asm_37d4f
-.asm_37d94
- ld a, [$ff9e]
- ld [$ff98], a
- ld a, [$ff9d]
- ld [$ff97], a
- ld a, [H_SAVEDNUMTOPRINT] ; $ff9c
- ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
- ld a, [$ff9b]
- ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld [H_PRODUCT], a
+ jr .loop
+.done
+ ld a, [H_MULTIPLYBUFFER+3]
+ ld [H_PRODUCT+3], a
+ ld a, [H_MULTIPLYBUFFER+2]
+ ld [H_PRODUCT+2], a
+ ld a, [H_MULTIPLYBUFFER+1]
+ ld [H_PRODUCT+1], a
+ ld a, [H_MULTIPLYBUFFER]
+ ld [H_PRODUCT], a
ret
-_Divide: ; 37da5 (d:7da5)
+_Divide:
xor a
- ld [$ff9a], a
- ld [$ff9b], a
- ld [H_SAVEDNUMTOPRINT], a ; $ff9c
- ld [$ff9d], a
- ld [$ff9e], a
+ ld [H_DIVIDEBUFFER], a
+ ld [H_DIVIDEBUFFER+1], a
+ ld [H_DIVIDEBUFFER+2], a
+ ld [H_DIVIDEBUFFER+3], a
+ ld [H_DIVIDEBUFFER+4], a
ld a, $9
ld e, a
.asm_37db3
- ld a, [$ff9a]
+ ld a, [H_DIVIDEBUFFER]
ld c, a
- ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
+ ld a, [H_DIVIDEND+1] ; (aliases: H_MULTIPLICAND)
sub c
ld d, a
- ld a, [H_REMAINDER] ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld a, [H_DIVISOR] ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
ld c, a
- ld a, [H_DIVIDEND] ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [H_DIVIDEND] ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
sbc c
jr c, .asm_37dce
- ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld [H_DIVIDEND], a ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
ld a, d
- ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
- ld a, [$ff9e]
+ ld [H_DIVIDEND+1], a ; (aliases: H_MULTIPLICAND)
+ ld a, [H_DIVIDEBUFFER+4]
inc a
- ld [$ff9e], a
+ ld [H_DIVIDEBUFFER+4], a
jr .asm_37db3
.asm_37dce
ld a, b
cp $1
jr z, .asm_37e18
- ld a, [$ff9e]
+ ld a, [H_DIVIDEBUFFER+4]
sla a
- ld [$ff9e], a
- ld a, [$ff9d]
+ ld [H_DIVIDEBUFFER+4], a
+ ld a, [H_DIVIDEBUFFER+3]
rl a
- ld [$ff9d], a
- ld a, [H_SAVEDNUMTOPRINT] ; $ff9c
+ ld [H_DIVIDEBUFFER+3], a
+ ld a, [H_DIVIDEBUFFER+2]
rl a
- ld [H_SAVEDNUMTOPRINT], a ; $ff9c
- ld a, [$ff9b]
+ ld [H_DIVIDEBUFFER+2], a
+ ld a, [H_DIVIDEBUFFER+1]
rl a
- ld [$ff9b], a
+ ld [H_DIVIDEBUFFER+1], a
dec e
jr nz, .asm_37e04
ld a, $8
ld e, a
- ld a, [$ff9a]
- ld [H_REMAINDER], a ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld a, [H_DIVIDEBUFFER]
+ ld [H_DIVISOR], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
xor a
- ld [$ff9a], a
- ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
- ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
- ld a, [$ff97]
- ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
- ld a, [$ff98]
- ld [$ff97], a
+ ld [H_DIVIDEBUFFER], a
+ ld a, [H_DIVIDEND+1] ; (aliases: H_MULTIPLICAND)
+ ld [H_DIVIDEND], a ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [H_DIVIDEND+2]
+ ld [H_DIVIDEND+1], a ; (aliases: H_MULTIPLICAND)
+ ld a, [H_DIVIDEND+3]
+ ld [H_DIVIDEND+2], a
.asm_37e04
ld a, e
cp $1
jr nz, .asm_37e0a
dec b
.asm_37e0a
- ld a, [H_REMAINDER] ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld a, [H_DIVISOR] ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
srl a
- ld [H_REMAINDER], a ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
- ld a, [$ff9a]
+ ld [H_DIVISOR], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld a, [H_DIVIDEBUFFER]
rr a
- ld [$ff9a], a
+ ld [H_DIVIDEBUFFER], a
jr .asm_37db3
.asm_37e18
- ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
- ld [H_REMAINDER], a ; $ff99 (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
- ld a, [$ff9e]
- ld [$ff98], a
- ld a, [$ff9d]
- ld [$ff97], a
- ld a, [H_SAVEDNUMTOPRINT] ; $ff9c
- ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
- ld a, [$ff9b]
- ld [H_DIVIDEND], a ; $ff95 (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [H_DIVIDEND+1] ; (aliases: H_MULTIPLICAND)
+ ld [H_REMAINDER], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld a, [H_DIVIDEBUFFER+4]
+ ld [H_QUOTIENT+3], a
+ ld a, [H_DIVIDEBUFFER+3]
+ ld [H_QUOTIENT+2], a
+ ld a, [H_DIVIDEBUFFER+2]
+ ld [H_QUOTIENT+1], a ; (aliases: H_MULTIPLICAND)
+ ld a, [H_DIVIDEBUFFER+1]
+ ld [H_DIVIDEND], a ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
ret
diff --git a/engine/oak_speech.asm b/engine/oak_speech.asm
index 0cbdaa3d..43efecbc 100755
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -1,12 +1,12 @@
-SetDefaultNames: ; 60ca (1:60ca)
- ld a, [wd358]
+SetDefaultNames:
+ ld a, [wLetterPrintingDelayFlags]
push af
- ld a, [W_OPTIONS] ; W_OPTIONS
+ ld a, [wOptions]
push af
ld a, [wd732]
push af
- ld hl, wPlayerName ; wd158
- ld bc, $d8a
+ ld hl, wPlayerName
+ ld bc, wBoxDataEnd - wPlayerName
xor a
call FillMemory
ld hl, wSpriteStateData1
@@ -16,28 +16,28 @@ SetDefaultNames: ; 60ca (1:60ca)
pop af
ld [wd732], a
pop af
- ld [W_OPTIONS], a ; W_OPTIONS
+ ld [wOptions], a
pop af
- ld [wd358], a
- ld a, [wd08a]
+ ld [wLetterPrintingDelayFlags], a
+ ld a, [wOptionsInitialized]
and a
- call z, Func_5bff
+ call z, InitOptions
ld hl, NintenText
- ld de, wPlayerName ; wd158
- ld bc, $b
+ ld de, wPlayerName
+ ld bc, NAME_LENGTH
call CopyData
ld hl, SonyText
- ld de, W_RIVALNAME ; wd34a
- ld bc, $b
+ ld de, wRivalName
+ ld bc, NAME_LENGTH
jp CopyData
-OakSpeech: ; 6115 (1:6115)
+OakSpeech:
ld a,$FF
call PlaySound ; stop music
- ld a, BANK(Music_Routes2) ; bank of song
+ ld a, BANK(Music_Routes2)
ld c,a
- ld a, MUSIC_ROUTES2 ; song #
- call PlayMusic ; plays music
+ ld a, MUSIC_ROUTES2
+ call PlayMusic
call ClearScreen
call LoadTextBoxTilePatterns
call SetDefaultNames
@@ -46,58 +46,57 @@ OakSpeech: ; 6115 (1:6115)
ld a,POTION
ld [wcf91],a
ld a,1
- ld [wcf96],a
+ ld [wItemQuantity],a
call AddItemToInventory ; give one potion
- ld a,[W_ANIMATIONID]
+ ld a,[wDefaultMap]
ld [wDestinationMap],a
call SpecialWarpIn
xor a
ld [hTilesetType],a
ld a,[wd732]
- bit 1,a ; XXX when is bit 1 set?
- jp nz,Func_61bc ; easter egg: skip the intro
+ bit 1,a ; possibly a debug mode bit
+ jp nz,.skipChoosingNames
ld de,ProfOakPic
- ld bc, (Bank(ProfOakPic) << 8) | $00
- call IntroPredef3B ; displays Oak pic?
+ lb bc, Bank(ProfOakPic), $00
+ call IntroDisplayPicCenteredOrUpperRight
call FadeInIntroPic
ld hl,OakSpeechText1
- call PrintText ; prints text box
+ call PrintText
call GBFadeOutToWhite
call ClearScreen
ld a,NIDORINO
- ld [wd0b5],a ; pic displayed is stored at this location
+ ld [wd0b5],a
ld [wcf91],a
- call GetMonHeader ; this is also related to the pic
- hlCoord 6, 4 ; position on tilemap the pic is displayed
- call LoadFlippedFrontSpriteByMonIndex ; displays pic?
+ call GetMonHeader
+ coord hl, 6, 4
+ call LoadFlippedFrontSpriteByMonIndex
call MovePicLeft
ld hl,OakSpeechText2
- call PrintText ; Prints text box
+ call PrintText
call GBFadeOutToWhite
call ClearScreen
ld de,RedPicFront
- ld bc,(Bank(RedPicFront) << 8) | $00
- call IntroPredef3B ; displays player pic?
+ lb bc, Bank(RedPicFront), $00
+ call IntroDisplayPicCenteredOrUpperRight
call MovePicLeft
ld hl,IntroducePlayerText
call PrintText
- call LoadDefaultNamesPlayer ; brings up NewName/Red/etc menu
+ call ChoosePlayerName
call GBFadeOutToWhite
call ClearScreen
ld de,Rival1Pic
- ld bc,(Bank(Rival1Pic) << 8) | $00
- call IntroPredef3B ; displays rival pic
+ lb bc, Bank(Rival1Pic), $00
+ call IntroDisplayPicCenteredOrUpperRight
call FadeInIntroPic
ld hl,IntroduceRivalText
call PrintText
- call LoadDefaultNamesRival
-
-Func_61bc: ; 61bc (1:61bc)
+ call ChooseRivalName
+.skipChoosingNames
call GBFadeOutToWhite
call ClearScreen
ld de,RedPicFront
- ld bc,(Bank(RedPicFront) << 8) | $00
- call IntroPredef3B
+ lb bc, Bank(RedPicFront), $00
+ call IntroDisplayPicCenteredOrUpperRight
call GBFadeInFromWhite
ld a,[wd72d]
and a
@@ -107,71 +106,71 @@ Func_61bc: ; 61bc (1:61bc)
.next
ld a,[H_LOADEDROMBANK]
push af
- ld a,(SFX_02_48 - SFX_Headers_02) / 3
+ ld a,SFX_SHRINK
call PlaySound
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a
+ ld [MBC1RomBank],a
ld c,4
call DelayFrames
- ld de,RedSprite ; $4180
+ ld de,RedSprite
ld hl,vSprites
- ld bc,(BANK(RedSprite) << 8) | $0C
+ lb bc, BANK(RedSprite), $0C
call CopyVideoData
ld de,ShrinkPic1
- ld bc,(BANK(ShrinkPic1) << 8) | $00
- call IntroPredef3B
+ lb bc, BANK(ShrinkPic1), $00
+ call IntroDisplayPicCenteredOrUpperRight
ld c,4
call DelayFrames
ld de,ShrinkPic2
- ld bc,(BANK(ShrinkPic2) << 8) | $00
- call IntroPredef3B
+ lb bc, BANK(ShrinkPic2), $00
+ call IntroDisplayPicCenteredOrUpperRight
call ResetPlayerSpriteData
ld a,[H_LOADEDROMBANK]
push af
ld a, BANK(Music_PalletTown)
- ld [wc0ef],a
- ld [wc0f0],a
- ld a,$A
- ld [wMusicHeaderPointer],a
+ ld [wAudioROMBank],a
+ ld [wAudioSavedROMBank],a
+ ld a, 10
+ ld [wAudioFadeOutControl],a
ld a,$FF
- ld [wc0ee],a
+ ld [wNewSoundID],a
call PlaySound ; stop music
pop af
ld [H_LOADEDROMBANK],a
- ld [$2000],a
- ld c,$14
+ ld [MBC1RomBank],a
+ ld c,20
call DelayFrames
- hlCoord 6, 5
+ coord hl, 6, 5
ld b,7
ld c,7
call ClearScreenArea
call LoadTextBoxTilePatterns
ld a,1
ld [wUpdateSpritesEnabled],a
- ld c,$32
+ ld c,50
call DelayFrames
call GBFadeOutToWhite
jp ClearScreen
-OakSpeechText1: ; 6253 (1:6253)
+OakSpeechText1:
TX_FAR _OakSpeechText1
db "@"
-OakSpeechText2: ; 6258 (1:6258)
+OakSpeechText2:
TX_FAR _OakSpeechText2A
- db $14 ; play NIDORINA cry from TextCommandSounds
+ TX_CRY_NIDORINA
TX_FAR _OakSpeechText2B
db "@"
-IntroducePlayerText: ; 6262 (1:6262)
+IntroducePlayerText:
TX_FAR _IntroducePlayerText
db "@"
-IntroduceRivalText: ; 6267 (1:6267)
+IntroduceRivalText:
TX_FAR _IntroduceRivalText
db "@"
-OakSpeechText3: ; 626c (1:626c)
+OakSpeechText3:
TX_FAR _OakSpeechText3
db "@"
-FadeInIntroPic: ; 6271 (1:6271)
+FadeInIntroPic:
ld hl,IntroFadePalettes
ld b,6
.next
@@ -183,7 +182,7 @@ FadeInIntroPic: ; 6271 (1:6271)
jr nz,.next
ret
-IntroFadePalettes: ; 6282 (1:6282)
+IntroFadePalettes:
db %01010100
db %10101000
db %11111100
@@ -191,31 +190,33 @@ IntroFadePalettes: ; 6282 (1:6282)
db %11110100
db %11100100
-MovePicLeft: ; 6288 (1:6288)
+MovePicLeft:
ld a,119
- ld [$FF4B],a
+ ld [rWX],a
call DelayFrame
- ld a,$E4
+ ld a,%11100100
ld [rBGP],a
.next
call DelayFrame
- ld a,[$FF4B]
+ ld a,[rWX]
sub 8
cp $FF
ret z
- ld [$FF4B],a
+ ld [rWX],a
jr .next
-Predef3B: ; 62a1 (1:62a1)
+DisplayPicCenteredOrUpperRight:
call GetPredefRegisters
-IntroPredef3B: ; 62a4 (1:62a4)
-; bank of sprite given in b
+IntroDisplayPicCenteredOrUpperRight:
+; b = bank
+; de = address of compressed pic
+; c: 0 = centred, non-zero = upper-right
push bc
ld a,b
call UncompressSpriteFromDE
- ld hl,S_SPRITEBUFFER1
- ld de,S_SPRITEBUFFER0
+ ld hl,sSpriteBuffer1
+ ld de,sSpriteBuffer0
ld bc,$310
call CopyData
ld de,vFrontPic
@@ -223,10 +224,10 @@ IntroPredef3B: ; 62a4 (1:62a4)
pop bc
ld a,c
and a
- hlCoord 15, 1
+ coord hl, 15, 1
jr nz,.next
- hlCoord 6, 4
+ coord hl, 6, 4
.next
xor a
- ld [$FFE1],a
- predef_jump Func_3f0c6
+ ld [hStartTileID],a
+ predef_jump CopyUncompressedPicToTilemap
diff --git a/engine/oak_speech2.asm b/engine/oak_speech2.asm
index 34d98fd7..1258c59b 100755
--- a/engine/oak_speech2.asm
+++ b/engine/oak_speech2.asm
@@ -1,195 +1,201 @@
-LoadDefaultNamesPlayer: ; 695d (1:695d)
- call Func_6a12
- ld de, DefaultNamesPlayer ; $6aa8
+ChoosePlayerName:
+ call OakSpeechSlidePicRight
+ ld de, DefaultNamesPlayer
call DisplayIntroNameTextBox
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
and a
- jr z, .asm_697a
- ld hl, DefaultNamesPlayerList ; $6af2
- call Func_6ad6
- ld de, wPlayerName ; wd158
- call Func_69ec
- jr .asm_6999
-.asm_697a
- ld hl, wPlayerName ; wd158
- xor a
- ld [wd07d], a
+ jr z, .customName
+ ld hl, DefaultNamesPlayerList
+ call GetDefaultName
+ ld de, wPlayerName
+ call OakSpeechSlidePicLeft
+ jr .done
+.customName
+ ld hl, wPlayerName
+ xor a ; NAME_PLAYER_SCREEN
+ ld [wNamingScreenType], a
call DisplayNamingScreen
ld a, [wcf4b]
- cp $50
- jr z, .asm_697a
+ cp "@"
+ jr z, .customName
call ClearScreen
call Delay3
- ld de, RedPicFront ; $6ede
+ ld de, RedPicFront
ld b, BANK(RedPicFront)
- call IntroPredef3B
-.asm_6999
+ call IntroDisplayPicCenteredOrUpperRight
+.done
ld hl, YourNameIsText
jp PrintText
-YourNameIsText: ; 699f (1:699f)
+YourNameIsText:
TX_FAR _YourNameIsText
db "@"
-LoadDefaultNamesRival: ; 69a4 (1:69a4)
- call Func_6a12 ; 0x69a4 call 0x6a12
+ChooseRivalName:
+ call OakSpeechSlidePicRight
ld de, DefaultNamesRival
call DisplayIntroNameTextBox
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
and a
- jr z, .asm_69c1
+ jr z, .customName
ld hl, DefaultNamesRivalList
- call Func_6ad6
- ld de, W_RIVALNAME ; wd34a
- call Func_69ec
- jr .asm_69e1
-.asm_69c1
- ld hl, W_RIVALNAME ; wd34a
- ld a, $1
- ld [wd07d], a
+ call GetDefaultName
+ ld de, wRivalName
+ call OakSpeechSlidePicLeft
+ jr .done
+.customName
+ ld hl, wRivalName
+ ld a, NAME_RIVAL_SCREEN
+ ld [wNamingScreenType], a
call DisplayNamingScreen
ld a, [wcf4b]
- cp $50
- jr z, .asm_69c1
+ cp "@"
+ jr z, .customName
call ClearScreen
call Delay3
- ld de, Rival1Pic ; $6049
+ ld de, Rival1Pic
ld b, $13
- call IntroPredef3B
-.asm_69e1
+ call IntroDisplayPicCenteredOrUpperRight
+.done
ld hl, HisNameIsText
jp PrintText
-HisNameIsText: ; 69e7 (1:69e7)
+HisNameIsText:
TX_FAR _HisNameIsText
db "@"
-Func_69ec: ; 69ec (1:69ec)
+OakSpeechSlidePicLeft:
push de
- ld hl, wTileMap
- ld bc, $c0b
- call ClearScreenArea
- ld c, $a
+ coord hl, 0, 0
+ lb bc, 12, 11
+ call ClearScreenArea ; clear the name list text box
+ ld c, 10
call DelayFrames
pop de
ld hl, wcd6d
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
call Delay3
- hlCoord 12, 4
- ld de, $67d
+ coord hl, 12, 4
+ lb de, 6, 6 * SCREEN_WIDTH + 5
ld a, $ff
- jr asm_6a19
+ jr OakSpeechSlidePicCommon
-Func_6a12: ; 6a12 (1:6a12)
- hlCoord 5, 4
- ld de, $67d
+OakSpeechSlidePicRight:
+ coord hl, 5, 4
+ lb de, 6, 6 * SCREEN_WIDTH + 5
xor a
-asm_6a19: ; 6a19 (1:6a19)
+
+OakSpeechSlidePicCommon:
push hl
push de
push bc
- ld [$ff8d], a
+ ld [hSlideDirection], a
ld a, d
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
+ ld [hSlideAmount], a
ld a, e
- ld [H_DOWNARROWBLINKCNT2], a ; $ff8c
+ ld [hSlidingRegionSize], a
ld c, a
- ld a, [$ff8d]
+ ld a, [hSlideDirection]
and a
- jr nz, .asm_6a2d
- ld d, $0
+ jr nz, .next
+; If sliding right, point hl to the end of the pic's tiles.
+ ld d, 0
add hl, de
-.asm_6a2d
+.next
ld d, h
ld e, l
-.asm_6a2f
+.loop
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, [$ff8d]
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [hSlideDirection]
and a
- jr nz, .asm_6a3c
+ jr nz, .slideLeft
+; sliding right
ld a, [hli]
ld [hld], a
dec hl
- jr .asm_6a3f
-.asm_6a3c
+ jr .next2
+.slideLeft
ld a, [hld]
ld [hli], a
inc hl
-.asm_6a3f
+.next2
dec c
- jr nz, .asm_6a2f
- ld a, [$ff8d]
+ jr nz, .loop
+ ld a, [hSlideDirection]
and a
- jr z, .asm_6a4a
+ jr z, .next3
+; If sliding left, we need to zero the last tile in the pic (there is no need
+; to take a corresponding action when sliding right because hl initially points
+; to a 0 tile in that case).
xor a
dec hl
ld [hl], a
-.asm_6a4a
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+.next3
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
- ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c
+ ld a, [hSlidingRegionSize]
ld c, a
ld h, d
ld l, e
- ld a, [$ff8d]
+ ld a, [hSlideDirection]
and a
- jr nz, .asm_6a5e
+ jr nz, .slideLeft2
inc hl
- jr .asm_6a5f
-.asm_6a5e
+ jr .next4
+.slideLeft2
dec hl
-.asm_6a5f
+.next4
ld d, h
ld e, l
- ld a, [H_DOWNARROWBLINKCNT1] ; $ff8b
+ ld a, [hSlideAmount]
dec a
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
- jr nz, .asm_6a2f
+ ld [hSlideAmount], a
+ jr nz, .loop
pop bc
pop de
pop hl
ret
-DisplayIntroNameTextBox: ; 6a6c (1:6a6c)
+DisplayIntroNameTextBox:
push de
- ld hl, wTileMap
+ coord hl, 0, 0
ld b, $a
ld c, $9
call TextBoxBorder
- hlCoord 3, 0
- ld de, .namestring ; $6aa3
+ coord hl, 3, 0
+ ld de, .namestring
call PlaceString
pop de
- hlCoord 2, 2
+ coord hl, 2, 2
call PlaceString
call UpdateSprites
xor a
- ld [wCurrentMenuItem], a ; wCurrentMenuItem
- ld [wLastMenuItem], a ; wLastMenuItem
+ ld [wCurrentMenuItem], a
+ ld [wLastMenuItem], a
inc a
- ld [wTopMenuItemX], a ; wTopMenuItemX
- ld [wMenuWatchedKeys], a ; wMenuWatchedKeys
+ ld [wTopMenuItemX], a
+ ld [wMenuWatchedKeys], a ; A_BUTTON
inc a
- ld [wTopMenuItemY], a ; wTopMenuItemY
+ ld [wTopMenuItemY], a
inc a
- ld [wMaxMenuItem], a ; wMaxMenuItem
+ ld [wMaxMenuItem], a
jp HandleMenuInput
-.namestring ; 6aa3 (1:6aa3)
+.namestring
db "NAME@"
IF DEF(_RED)
-DefaultNamesPlayer: ; 6aa8 (1:6aa8)
+DefaultNamesPlayer:
db "NEW NAME"
next "RED"
next "ASH"
next "JACK"
db "@"
-DefaultNamesRival: ; 6abe (1:6abe)
+DefaultNamesRival:
db "NEW NAME"
next "BLUE"
next "GARY"
@@ -198,14 +204,14 @@ DefaultNamesRival: ; 6abe (1:6abe)
ENDC
IF DEF(_BLUE)
-DefaultNamesPlayer: ; 6aa8 (1:6aa8)
+DefaultNamesPlayer:
db "NEW NAME"
next "BLUE"
next "GARY"
next "JOHN"
db "@"
-DefaultNamesRival: ; 6abe (1:6abe)
+DefaultNamesRival:
db "NEW NAME"
next "RED"
next "ASH"
@@ -213,61 +219,54 @@ DefaultNamesRival: ; 6abe (1:6abe)
db "@"
ENDC
-IF DEF(_YELLOW)
-DefaultNamesPlayer:
- db "NEW NAME"
- next "YELLOW"
- next "ASH"
- next "JACK"
- db "@"
-
-DefaultNamesRival:
- db "NEW NAME"
- next "BLUE"
- next "GARY"
- next "JOHN"
- db "@"
-ENDC
-
-Func_6ad6: ; 6ad6 (1:6ad6)
+GetDefaultName:
+; a = name index
+; hl = name list
ld b, a
- ld c, $0
-.asm_6ad9
+ ld c, 0
+.loop
ld d, h
ld e, l
-.asm_6adb
+.innerLoop
ld a, [hli]
- cp $50
- jr nz, .asm_6adb
+ cp "@"
+ jr nz, .innerLoop
ld a, b
cp c
- jr z, .asm_6ae7
+ jr z, .foundName
inc c
- jr .asm_6ad9
-.asm_6ae7
+ jr .loop
+.foundName
ld h, d
ld l, e
ld de, wcd6d
ld bc, $14
jp CopyData
+
IF DEF(_RED)
-DefaultNamesPlayerList: ; 6af2 (1:6af2)
- db "NEW NAME@RED@ASH@JACK@"
-DefaultNamesRivalList: ; 6b08 (1:6b08)
- db "NEW NAME@BLUE@GARY@JOHN@"
+DefaultNamesPlayerList:
+ db "NEW NAME@"
+ db "RED@"
+ db "ASH@"
+ db "JACK@"
+DefaultNamesRivalList:
+ db "NEW NAME@"
+ db "BLUE@"
+ db "GARY@"
+ db "JOHN@"
ENDC
IF DEF(_BLUE)
-DefaultNamesPlayerList: ; 6af2 (1:6af2)
- db "NEW NAME@BLUE@GARY@JOHN@"
-DefaultNamesRivalList: ; 6b08 (1:6b08)
- db "NEW NAME@RED@ASH@JACK@"
-ENDC
-IF DEF(_YELLOW)
DefaultNamesPlayerList:
- db "NEW NAME@YELLOW@ASH@JACK@"
+ db "NEW NAME@"
+ db "BLUE@"
+ db "GARY@"
+ db "JOHN@"
DefaultNamesRivalList:
- db "NEW NAME@BLUE@GARY@JOHN@"
+ db "NEW NAME@"
+ db "RED@"
+ db "ASH@"
+ db "JACK@"
ENDC
-TextTerminator_6b20: ; 6b20 (1:6b20)
+TextTerminator_6b20:
db "@"
diff --git a/engine/oam_dma.asm b/engine/oam_dma.asm
index 3de4d773..7326445e 100644
--- a/engine/oam_dma.asm
+++ b/engine/oam_dma.asm
@@ -15,11 +15,12 @@ WriteDMACodeToHRAM:
DMARoutine:
; initiate DMA
ld a, wOAMBuffer / $100
- ld [$ff46], a
+ ld [rDMA], a
; wait for DMA to finish
ld a, $28
-.wait dec a
+.wait
+ dec a
jr nz, .wait
ret
DMARoutineEnd:
diff --git a/engine/overworld/cable_club_npc.asm b/engine/overworld/cable_club_npc.asm
index bdab41a6..08067412 100755
--- a/engine/overworld/cable_club_npc.asm
+++ b/engine/overworld/cable_club_npc.asm
@@ -1,15 +1,14 @@
-CableClubNPC: ; 71c5 (1:71c5)
+CableClubNPC:
ld hl, CableClubNPCWelcomeText
call PrintText
- ld a, [wd74b]
- bit 5, a ; received pokedex?
+ CheckEvent EVENT_GOT_POKEDEX
jp nz, .receivedPokedex
; if the player hasn't received the pokedex
- ld c, $3c
+ ld c, 60
call DelayFrames
ld hl, CableClubNPCMakingPreparationsText
call PrintText
- jp Func_7298
+ jp .didNotConnect
.receivedPokedex
ld a, $1
ld [wMenuJoypadPollCount], a
@@ -57,7 +56,7 @@ CableClubNPC: ; 71c5 (1:71c5)
jr nz, .choseNo
callab SaveSAVtoSRAM
call WaitForSoundToFinish
- ld a, (SFX_02_5d - SFX_Headers_02) / 3
+ ld a, SFX_SAVE
call PlaySoundWaitForCurrent
ld hl, CableClubNPCPleaseWaitText
call PrintText
@@ -72,31 +71,29 @@ CableClubNPC: ; 71c5 (1:71c5)
ld hl, wUnknownSerialCounter
ld a, [hli]
inc a
- jr nz, Func_72a8 ; 0x726b $3b
+ jr nz, .connected
ld a, [hl]
inc a
- jr nz, Func_72a8 ; 0x726f $37
- ld b, $a
-.asm_7273
+ jr nz, .connected
+ ld b, 10
+.syncLoop
call DelayFrame
call Serial_SendZeroByte
dec b
- jr nz, .asm_7273 ; 0x727a $f7
+ jr nz, .syncLoop
call CloseLinkConnection
ld hl, CableClubNPCLinkClosedBecauseOfInactivityText
call PrintText
- jr Func_7298 ; 0x7285 $11
+ jr .didNotConnect
.failedToEstablishConnection
ld hl, CableClubNPCAreaReservedFor2FriendsLinkedByCableText
call PrintText
- jr Func_7298 ; 0x728d $9
+ jr .didNotConnect
.choseNo
call CloseLinkConnection
ld hl, CableClubNPCPleaseComeAgainText
call PrintText
- ; fall through
-
-Func_7298: ; 7298 (1:7298)
+.didNotConnect
xor a
ld hl, wUnknownSerialCounter
ld [hli], a
@@ -106,44 +103,42 @@ Func_7298: ; 7298 (1:7298)
xor a
ld [wMenuJoypadPollCount], a
ret
-
-Func_72a8: ; 72a8 (1:72a8)
+.connected
xor a
ld [hld], a
ld [hl], a
- ld hl, LinkMenu
- ld b, BANK(LinkMenu)
- jp Bankswitch
+ jpab LinkMenu
-CableClubNPCAreaReservedFor2FriendsLinkedByCableText: ; 72b3 (1:72b3)
+CableClubNPCAreaReservedFor2FriendsLinkedByCableText:
TX_FAR _CableClubNPCAreaReservedFor2FriendsLinkedByCableText
db "@"
-CableClubNPCWelcomeText: ; 72b8 (1:72b8)
+CableClubNPCWelcomeText:
TX_FAR _CableClubNPCWelcomeText
db "@"
-CableClubNPCPleaseApplyHereHaveToSaveText: ; 72bd (1:72bd)
+CableClubNPCPleaseApplyHereHaveToSaveText:
TX_FAR _CableClubNPCPleaseApplyHereHaveToSaveText
db "@"
-CableClubNPCPleaseWaitText: ; 72c2 (1:72c2)
+CableClubNPCPleaseWaitText:
TX_FAR _CableClubNPCPleaseWaitText
- db $a, "@"
+ TX_DELAY
+ db "@"
-CableClubNPCLinkClosedBecauseOfInactivityText: ; 72c8 (1:72c8)
+CableClubNPCLinkClosedBecauseOfInactivityText:
TX_FAR _CableClubNPCLinkClosedBecauseOfInactivityText
db "@"
-CableClubNPCPleaseComeAgainText: ; 72cd (1:72cd)
+CableClubNPCPleaseComeAgainText:
TX_FAR _CableClubNPCPleaseComeAgainText
db "@"
-CableClubNPCMakingPreparationsText: ; 72d2 (1:72d2)
+CableClubNPCMakingPreparationsText:
TX_FAR _CableClubNPCMakingPreparationsText
db "@"
-CloseLinkConnection: ; 72d7 (1:72d7)
+CloseLinkConnection:
call Delay3
ld a, CONNECTION_NOT_ESTABLISHED
ld [hSerialConnectionStatus], a
diff --git a/engine/overworld/card_key.asm b/engine/overworld/card_key.asm
index c4df0d51..35495c82 100755
--- a/engine/overworld/card_key.asm
+++ b/engine/overworld/card_key.asm
@@ -1,6 +1,6 @@
-PrintCardKeyText: ; 52673 (14:6673)
+PrintCardKeyText:
ld hl, SilphCoMapList
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
ld b, a
.silphCoMapListLoop
ld a, [hli]
@@ -15,7 +15,7 @@ PrintCardKeyText: ; 52673 (14:6673)
cp $24
jr z, .cardKeyDoorInFrontOfPlayer
ld b, a
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp SILPH_CO_11F
ret nz
ld a, b
@@ -27,8 +27,8 @@ PrintCardKeyText: ; 52673 (14:6673)
jr z, .noCardKey
call GetCoordsInFrontOfPlayer
push de
- ld a, $1
- ld [H_DOWNARROWBLINKCNT2], a
+ tx_pre_id CardKeySuccessText
+ ld [hSpriteIndexOrTextID], a
call PrintPredefTextID
pop de
srl d
@@ -39,7 +39,7 @@ PrintCardKeyText: ; 52673 (14:6673)
ld a, e
ld c, a
ld [wCardKeyDoorX], a
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp SILPH_CO_11F
jr nz, .notSilphCo11F
ld a, $3
@@ -47,18 +47,18 @@ PrintCardKeyText: ; 52673 (14:6673)
.notSilphCo11F
ld a, $e
.replaceCardKeyDoorTileBlock
- ld [wd09f], a
+ ld [wNewTileBlockID], a
predef ReplaceTileBlock
- ld hl, wd126
+ ld hl, wCurrentMapScriptFlags
set 5, [hl]
- ld a, (SFX_1f_57 - SFX_Headers_1f) / 3
+ ld a, SFX_GO_INSIDE
jp PlaySound
.noCardKey
- ld a, $2
- ld [H_DOWNARROWBLINKCNT2], a
+ tx_pre_id CardKeyFailText
+ ld [hSpriteIndexOrTextID], a
jp PrintPredefTextID
-SilphCoMapList: ; 526e3 (14:66e3)
+SilphCoMapList:
db SILPH_CO_2F
db SILPH_CO_3F
db SILPH_CO_4F
@@ -71,22 +71,22 @@ SilphCoMapList: ; 526e3 (14:66e3)
db SILPH_CO_11F
db $FF
-CardKeySuccessText: ; 526ee (14:66ee)
+CardKeySuccessText:
TX_FAR _CardKeySuccessText1
- db $0b
+ TX_SFX_ITEM_1
TX_FAR _CardKeySuccessText2
db "@"
-CardKeyFailText: ; 526f8 (14:66f8)
+CardKeyFailText:
TX_FAR _CardKeyFailText
db "@"
; d = Y
; e = X
-GetCoordsInFrontOfPlayer: ; 526fd (14:66fd)
- ld a, [W_YCOORD]
+GetCoordsInFrontOfPlayer:
+ ld a, [wYCoord]
ld d, a
- ld a, [W_XCOORD]
+ ld a, [wXCoord]
ld e, a
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
and a
diff --git a/engine/overworld/cinnabar_lab.asm b/engine/overworld/cinnabar_lab.asm
index eefa2176..13313746 100755
--- a/engine/overworld/cinnabar_lab.asm
+++ b/engine/overworld/cinnabar_lab.asm
@@ -1,37 +1,37 @@
-GiveFossilToCinnabarLab: ; 61006 (18:5006)
+GiveFossilToCinnabarLab:
ld hl, wd730
set 6, [hl]
xor a
- ld [wCurrentMenuItem], a ; wCurrentMenuItem
- ld a, $3
- ld [wMenuWatchedKeys], a ; wMenuWatchedKeys
- ld a, [wcd37]
+ ld [wCurrentMenuItem], a
+ ld a, A_BUTTON | B_BUTTON
+ ld [wMenuWatchedKeys], a
+ ld a, [wFilteredBagItemsCount]
dec a
- ld [wMaxMenuItem], a ; wMaxMenuItem
- ld a, $2
- ld [wTopMenuItemY], a ; wTopMenuItemY
- ld a, $1
- ld [wTopMenuItemX], a ; wTopMenuItemX
- ld a, [wcd37]
+ ld [wMaxMenuItem], a
+ ld a, 2
+ ld [wTopMenuItemY], a
+ ld a, 1
+ ld [wTopMenuItemX], a
+ ld a, [wFilteredBagItemsCount]
dec a
- ld bc, $2
- ld hl, $3
+ ld bc, 2
+ ld hl, 3
call AddNTimes
dec l
ld b, l
ld c, $d
- ld hl, wTileMap
+ coord hl, 0, 0
call TextBoxBorder
call UpdateSprites
- call Func_610c2
+ call PrintFossilsInBag
ld hl, wd730
res 6, [hl]
call HandleMenuInput
- bit 1, a
- jr nz, .asm_610a7
- ld hl, wcc5b
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
- ld d, $0
+ bit 1, a ; pressed B?
+ jr nz, .cancelledGivingFossil
+ ld hl, wFilteredBagItems
+ ld a, [wCurrentMenuItem]
+ ld d, 0
ld e, a
add hl, de
ld a, [hl]
@@ -48,77 +48,76 @@ GiveFossilToCinnabarLab: ; 61006 (18:5006)
.choseDomeFossil
ld b, KABUTO
.fossilSelected
- ld [W_FOSSILITEM], a
+ ld [wFossilItem], a
ld a, b
- ld [W_FOSSILMON], a
+ ld [wFossilMon], a
call LoadFossilItemAndMonName
ld hl, LabFossil_610ae
call PrintText
call YesNoChoice
- ld a, [wCurrentMenuItem] ; wCurrentMenuItem
+ ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_610a7
+ jr nz, .cancelledGivingFossil
ld hl, LabFossil_610b3
call PrintText
- ld a, [W_FOSSILITEM]
- ld [$ffdb], a
+ ld a, [wFossilItem]
+ ld [hItemToRemoveID], a
callba RemoveItemByID
ld hl, LabFossil_610b8
call PrintText
- ld hl, wd7a3
- set 0, [hl]
- set 1, [hl]
+ SetEvents EVENT_GAVE_FOSSIL_TO_LAB, EVENT_LAB_STILL_REVIVING_FOSSIL
ret
-.asm_610a7
+.cancelledGivingFossil
ld hl, LabFossil_610bd
call PrintText
ret
-LabFossil_610ae: ; 610ae (18:50ae)
+LabFossil_610ae:
TX_FAR _Lab4Text_610ae
db "@"
-LabFossil_610b3: ; 610b3 (18:50b3)
+LabFossil_610b3:
TX_FAR _Lab4Text_610b3
db "@"
-LabFossil_610b8: ; 610b8 (18:50b8)
+LabFossil_610b8:
TX_FAR _Lab4Text_610b8
db "@"
-LabFossil_610bd: ; 610bd (18:50bd)
+LabFossil_610bd:
TX_FAR _Lab4Text_610bd
db "@"
-Func_610c2: ; 610c2 (18:50c2)
- ld hl, wcc5b
+PrintFossilsInBag:
+; Prints each fossil in the player's bag on a separate line in the menu.
+ ld hl, wFilteredBagItems
xor a
- ld [$ffdb], a
-.asm_610c8
+ ld [hItemCounter], a
+.loop
ld a, [hli]
cp $ff
ret z
push hl
ld [wd11e], a
call GetItemName
- hlCoord 2, 2
- ld a, [$ffdb]
- ld bc, $28
+ coord hl, 2, 2
+ ld a, [hItemCounter]
+ ld bc, SCREEN_WIDTH * 2
call AddNTimes
ld de, wcd6d
call PlaceString
- ld hl, $ffdb
+ ld hl, hItemCounter
inc [hl]
pop hl
- jr .asm_610c8
+ jr .loop
; loads the names of the fossil item and the resulting mon
-LoadFossilItemAndMonName: ; 610eb (18:50eb)
- ld a, [W_FOSSILMON]
+LoadFossilItemAndMonName:
+ ld a, [wFossilMon]
ld [wd11e], a
call GetMonName
call CopyStringToCF4B
- ld a, [W_FOSSILITEM]
+ ld a, [wFossilItem]
ld [wd11e], a
call GetItemName
ret
diff --git a/engine/overworld/clear_variables.asm b/engine/overworld/clear_variables.asm
new file mode 100644
index 00000000..9a59cc7c
--- /dev/null
+++ b/engine/overworld/clear_variables.asm
@@ -0,0 +1,20 @@
+ClearVariablesOnEnterMap:
+ ld a, SCREEN_HEIGHT_PIXELS
+ ld [hWY], a
+ ld [rWY], a
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld [wStepCounter], a
+ ld [wLoneAttackNo], a
+ ld [hJoyPressed], a
+ ld [hJoyReleased], a
+ ld [hJoyHeld], a
+ ld [wActionResultOrTookBattleTurn], a
+ ld [wUnusedD5A3], a
+ ld hl, wCardKeyDoorY
+ ld [hli], a
+ ld [hl], a
+ ld hl, wWhichTrade
+ ld bc, wStandingOnWarpPadOrHole - wWhichTrade
+ call FillMemory
+ ret
diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm
index 7b92bca3..f6ae6468 100755
--- a/engine/overworld/cut.asm
+++ b/engine/overworld/cut.asm
@@ -1,43 +1,43 @@
-UsedCut: ; ef54 (3:6f54)
+UsedCut:
xor a
- ld [wcd6a], a
- ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET
+ ld [wActionResultOrTookBattleTurn], a ; initialise to failure value
+ ld a, [wCurMapTileset]
and a ; OVERWORLD
- jr z, .asm_ef6b
+ jr z, .overworld
cp GYM
- jr nz, .asm_ef77
+ jr nz, .nothingToCut
ld a, [wTileInFrontOfPlayer]
cp $50 ; gym cut tree
- jr nz, .asm_ef77
- jr asm_ef82
-.asm_ef6b
+ jr nz, .nothingToCut
+ jr .canCut
+.overworld
dec a
ld a, [wTileInFrontOfPlayer]
cp $3d ; cut tree
- jr z, asm_ef82
+ jr z, .canCut
cp $52 ; grass
- jr z, asm_ef82
-.asm_ef77
- ld hl, NothingToCutText
+ jr z, .canCut
+.nothingToCut
+ ld hl, .NothingToCutText
jp PrintText
-NothingToCutText: ; ef7d (3:6f7d)
+.NothingToCutText
TX_FAR _NothingToCutText
db "@"
-asm_ef82: ; ef82 (3:6f82)
- ld [wcd4d], a
- ld a, $1
- ld [wcd6a], a
- ld a, [wWhichPokemon] ; wWhichPokemon
- ld hl, wPartyMonNicks ; wPartyMonNicks
+.canCut
+ ld [wCutTile], a
+ ld a, 1
+ ld [wActionResultOrTookBattleTurn], a ; used cut
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMonNicks
call GetPartyMonName
ld hl, wd730
set 6, [hl]
call GBPalWhiteOutWithDelay3
call ClearSprites
call RestoreScreenTilesAndReloadTilePatterns
- ld a, $90
+ ld a, SCREEN_HEIGHT_PIXELS
ld [hWY], a
call Delay3
call LoadGBPal
@@ -53,79 +53,80 @@ asm_ef82: ; ef82 (3:6f82)
res 6, [hl]
ld a, $ff
ld [wUpdateSpritesEnabled], a
- call AnimateCutTree
- ld de, CutTreeBlockSwaps ; $7100
- call Func_f09f
+ call InitCutAnimOAM
+ ld de, CutTreeBlockSwaps
+ call ReplaceTreeTileBlock
call RedrawMapView
- callba Func_79e96
+ callba AnimCut
ld a, $1
ld [wUpdateSpritesEnabled], a
- ld a, (SFX_02_56 - SFX_Headers_02) / 3
+ ld a, SFX_CUT
call PlaySound
ld a, $90
ld [hWY], a
call UpdateSprites
jp RedrawMapView
-UsedCutText: ; eff2 (3:6ff2)
+UsedCutText:
TX_FAR _UsedCutText
db "@"
-AnimateCutTree: ; eff7 (3:6ff7)
+InitCutAnimOAM:
xor a
- ld [wcd50], a
- ld a, $e4
- ld [rOBP1], a ; $ff49
- ld a, [wcd4d]
+ ld [wWhichAnimationOffsets], a
+ ld a, %11100100
+ ld [rOBP1], a
+ ld a, [wCutTile]
cp $52
- jr z, .asm_f020
- ld de, Overworld_GFX + $2d0 ; $42d0 ; cuttable tree sprite top row
+ jr z, .grass
+; tree
+ ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row
ld hl, vChars1 + $7c0
- ld bc, (BANK(Overworld_GFX) << 8) + $02
+ lb bc, BANK(Overworld_GFX), $02
call CopyVideoData
- ld de, Overworld_GFX + $3d0 ; $43d0 ; cuttable tree sprite bottom row
+ ld de, Overworld_GFX + $3d0 ; cuttable tree sprite bottom row
ld hl, vChars1 + $7e0
- ld bc, (BANK(Overworld_GFX) << 8) + $02
+ lb bc, BANK(Overworld_GFX), $02
call CopyVideoData
- jr WriteCutTreeBoulderDustAnimationOAMBlock
-.asm_f020
+ jr WriteCutOrBoulderDustAnimationOAMBlock
+.grass
ld hl, vChars1 + $7c0
- call LoadCutTreeAnimationTilePattern
+ call LoadCutGrassAnimationTilePattern
ld hl, vChars1 + $7d0
- call LoadCutTreeAnimationTilePattern
+ call LoadCutGrassAnimationTilePattern
ld hl, vChars1 + $7e0
- call LoadCutTreeAnimationTilePattern
+ call LoadCutGrassAnimationTilePattern
ld hl, vChars1 + $7f0
- call LoadCutTreeAnimationTilePattern
- call WriteCutTreeBoulderDustAnimationOAMBlock
+ call LoadCutGrassAnimationTilePattern
+ call WriteCutOrBoulderDustAnimationOAMBlock
ld hl, wOAMBuffer + $93
- ld de, $4
+ ld de, 4
ld a, $30
ld c, e
-.asm_f044
+.loop
ld [hl], a
add hl, de
xor $60
dec c
- jr nz, .asm_f044
+ jr nz, .loop
ret
-LoadCutTreeAnimationTilePattern: ; f04c (3:704c)
- ld de, AnimationTileset2 + $60 ; $474e ; tile depicting a leaf
- ld bc, (BANK(AnimationTileset2) << 8) + $01
+LoadCutGrassAnimationTilePattern:
+ ld de, AnimationTileset2 + $60 ; tile depicting a leaf
+ lb bc, BANK(AnimationTileset2), $01
jp CopyVideoData
-WriteCutTreeBoulderDustAnimationOAMBlock: ; f055 (3:7055)
- call GetCutTreeBoulderDustAnimationOffsets
+WriteCutOrBoulderDustAnimationOAMBlock:
+ call GetCutOrBoulderDustAnimationOffsets
ld a, $9
- ld de, CutTreeBoulderDustAnimationTilesAndAttributes
+ ld de, CutOrBoulderDustAnimationTilesAndAttributes
jp WriteOAMBlock
-CutTreeBoulderDustAnimationTilesAndAttributes: ; f060 (3:7060)
+CutOrBoulderDustAnimationTilesAndAttributes:
db $FC,$10,$FD,$10
db $FE,$10,$FF,$10
-GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068)
+GetCutOrBoulderDustAnimationOffsets:
ld hl, wSpriteStateData1 + 4
ld a, [hli] ; player's sprite screen Y position
ld b, a
@@ -138,12 +139,12 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068)
srl a
ld e, a
ld d, $0 ; de holds direction (00: down, 02: up, 04: left, 06: right)
- ld a, [wcd50]
+ ld a, [wWhichAnimationOffsets]
and a
- ld hl, CutTreeAnimationOffsets
- jr z, .asm_f084
+ ld hl, CutAnimationOffsets
+ jr z, .next
ld hl, BoulderDustAnimationOffsets
-.asm_f084
+.next
add hl, de
ld e, [hl]
inc hl
@@ -156,14 +157,14 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068)
ld c, a
ret
-CutTreeAnimationOffsets: ; f08f (3:708f)
+CutAnimationOffsets:
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
db 8, 36 ; player is facing down
db 8, 4 ; player is facing up
db -8, 20 ; player is facing left
db 24, 20 ; player is facing right
-BoulderDustAnimationOffsets: ; f097 (3:7097)
+BoulderDustAnimationOffsets:
; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn
; These offsets represent 2 blocks away from the player
db 8, 52 ; player is facing down
@@ -171,79 +172,83 @@ BoulderDustAnimationOffsets: ; f097 (3:7097)
db -24, 20 ; player is facing left
db 40, 20 ; player is facing right
-Func_f09f: ; f09f (3:709f)
+ReplaceTreeTileBlock:
+; Determine the address of the tile block that contains the tile in front of the
+; player (i.e. where the tree is) and replace it with the corresponding tile
+; block that doesn't have the tree.
push de
- ld a, [W_CURMAPWIDTH] ; wd369
- add $6
+ ld a, [wCurMapWidth]
+ add 6
ld c, a
- ld b, $0
- ld d, $0
+ ld b, 0
+ ld d, 0
ld hl, wCurrentTileBlockMapViewPointer
ld a, [hli]
ld h, [hl]
ld l, a
add hl, bc
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
and a
- jr z, .asm_f0c7
- cp $4
- jr z, .asm_f0cf
- cp $8
- jr z, .asm_f0d7
- ld a, [W_XBLOCKCOORD] ; wd364
+ jr z, .down
+ cp SPRITE_FACING_UP
+ jr z, .up
+ cp SPRITE_FACING_LEFT
+ jr z, .left
+; right
+ ld a, [wXBlockCoord]
and a
- jr z, .asm_f0e0
- jr .asm_f0ec
-.asm_f0c7
- ld a, [W_YBLOCKCOORD] ; wd363
+ jr z, .centerTileBlock
+ jr .rightOfCenter
+.down
+ ld a, [wYBlockCoord]
and a
- jr z, .asm_f0e0
- jr .asm_f0df
-.asm_f0cf
- ld a, [W_YBLOCKCOORD] ; wd363
+ jr z, .centerTileBlock
+ jr .belowCenter
+.up
+ ld a, [wYBlockCoord]
and a
- jr z, .asm_f0e1
- jr .asm_f0e0
-.asm_f0d7
- ld a, [W_XBLOCKCOORD] ; wd364
+ jr z, .aboveCenter
+ jr .centerTileBlock
+.left
+ ld a, [wXBlockCoord]
and a
- jr z, .asm_f0e6
- jr .asm_f0e0
-.asm_f0df
+ jr z, .leftOfCenter
+ jr .centerTileBlock
+.belowCenter
add hl, bc
-.asm_f0e0
+.centerTileBlock
add hl, bc
-.asm_f0e1
+.aboveCenter
ld e, $2
add hl, de
- jr .asm_f0f0
-.asm_f0e6
+ jr .next
+.leftOfCenter
ld e, $1
add hl, bc
add hl, de
- jr .asm_f0f0
-.asm_f0ec
+ jr .next
+.rightOfCenter
ld e, $3
add hl, bc
add hl, de
-.asm_f0f0
+.next
pop de
ld a, [hl]
ld c, a
-.asm_f0f3
+.loop ; find the matching tile block in the array
ld a, [de]
inc de
inc de
cp $ff
ret z
cp c
- jr nz, .asm_f0f3
+ jr nz, .loop
dec de
- ld a, [de]
+ ld a, [de] ; replacement tile block from matching array entry
ld [hl], a
ret
-CutTreeBlockSwaps: ; f100 (3:7100)
+CutTreeBlockSwaps:
; first byte = tileset block containing the cut tree
; second byte = corresponding tileset block after the cut animation happens
db $32, $6D
diff --git a/engine/overworld/cut2.asm b/engine/overworld/cut2.asm
index de2b9d55..f16fed66 100755
--- a/engine/overworld/cut2.asm
+++ b/engine/overworld/cut2.asm
@@ -1,89 +1,89 @@
-Func_79e96: ; 79e96 (1e:5e96)
- ld a, [wcd4d]
+AnimCut:
+ ld a, [wCutTile]
cp $52
- jr z, .asm_79ec8
+ jr z, .grass
ld c, $8
-.asm_79e9f
+.cutTreeLoop
push bc
ld hl, wOAMBuffer + $91
- ld a, $1
- ld [wd08a], a
- ld c, $2
+ ld a, 1
+ ld [wCoordAdjustmentAmount], a
+ ld c, 2
call AdjustOAMBlockXPos2
ld hl, wOAMBuffer + $99
- ld a, $ff
- ld [wd08a], a
- ld c, $2
+ ld a, -1
+ ld [wCoordAdjustmentAmount], a
+ ld c, 2
call AdjustOAMBlockXPos2
- ld a, [rOBP1] ; $ff49
+ ld a, [rOBP1]
xor $64
- ld [rOBP1], a ; $ff49
+ ld [rOBP1], a
call DelayFrame
pop bc
dec c
- jr nz, .asm_79e9f
+ jr nz, .cutTreeLoop
ret
-.asm_79ec8
- ld c, $2
-.asm_79eca
+.grass
+ ld c, 2
+.cutGrassLoop
push bc
ld c, $8
- call Func_79eed
- call Func_79f30
+ call AnimCutGrass_UpdateOAMEntries
+ call AnimCutGrass_SwapOAMEntries
ld c, $8
- call Func_79eed
- call Func_79f30
+ call AnimCutGrass_UpdateOAMEntries
+ call AnimCutGrass_SwapOAMEntries
ld hl, wOAMBuffer + $90
- ld a, $2
- ld [wd08a], a
- ld c, $4
+ ld a, 2
+ ld [wCoordAdjustmentAmount], a
+ ld c, 4
call AdjustOAMBlockYPos2
pop bc
dec c
- jr nz, .asm_79eca
+ jr nz, .cutGrassLoop
ret
-Func_79eed: ; 79eed (1e:5eed)
+AnimCutGrass_UpdateOAMEntries:
push bc
ld hl, wOAMBuffer + $91
- ld a, $1
- ld [wd08a], a
- ld c, $1
+ ld a, 1
+ ld [wCoordAdjustmentAmount], a
+ ld c, 1
call AdjustOAMBlockXPos2
ld hl, wOAMBuffer + $95
- ld a, $2
- ld [wd08a], a
- ld c, $1
+ ld a, 2
+ ld [wCoordAdjustmentAmount], a
+ ld c, 1
call AdjustOAMBlockXPos2
ld hl, wOAMBuffer + $99
- ld a, $fe
- ld [wd08a], a
- ld c, $1
+ ld a, -2
+ ld [wCoordAdjustmentAmount], a
+ ld c, 1
call AdjustOAMBlockXPos2
ld hl, wOAMBuffer + $9d
- ld a, $ff
- ld [wd08a], a
- ld c, $1
+ ld a, -1
+ ld [wCoordAdjustmentAmount], a
+ ld c, 1
call AdjustOAMBlockXPos2
- ld a, [rOBP1] ; $ff49
+ ld a, [rOBP1]
xor $64
- ld [rOBP1], a ; $ff49
+ ld [rOBP1], a
call DelayFrame
pop bc
dec c
- jr nz, Func_79eed
+ jr nz, AnimCutGrass_UpdateOAMEntries
ret
-Func_79f30: ; 79f30 (1e:5f30)
+AnimCutGrass_SwapOAMEntries:
ld hl, wOAMBuffer + $90
- ld de, wHPBarMaxHP
+ ld de, wBuffer
ld bc, $8
call CopyData
ld hl, wOAMBuffer + $98
ld de, wOAMBuffer + $90
ld bc, $8
call CopyData
- ld hl, wHPBarMaxHP
+ ld hl, wBuffer
ld de, wOAMBuffer + $98
ld bc, $8
jp CopyData
diff --git a/engine/overworld/daycare_exp.asm b/engine/overworld/daycare_exp.asm
new file mode 100644
index 00000000..dbe4023a
--- /dev/null
+++ b/engine/overworld/daycare_exp.asm
@@ -0,0 +1,18 @@
+IncrementDayCareMonExp:
+ ld a, [wDayCareInUse]
+ and a
+ ret z
+ ld hl, wDayCareMonExp + 2
+ inc [hl]
+ ret nz
+ dec hl
+ inc [hl]
+ ret nz
+ dec hl
+ inc [hl]
+ ld a, [hl]
+ cp $50
+ ret c
+ ld a, $50
+ ld [hl], a
+ ret
diff --git a/engine/overworld/doors.asm b/engine/overworld/doors.asm
index ac345af9..c39e096d 100755
--- a/engine/overworld/doors.asm
+++ b/engine/overworld/doors.asm
@@ -1,8 +1,8 @@
; returns whether the player is standing on a door tile in carry
-IsPlayerStandingOnDoorTile: ; 1a609 (6:6609)
+IsPlayerStandingOnDoorTile:
push de
- ld hl, DoorTileIDPointers ; $662c
- ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET
+ ld hl, DoorTileIDPointers
+ ld a, [wCurMapTileset]
ld de, $3
call IsInArray
pop de
@@ -25,64 +25,51 @@ IsPlayerStandingOnDoorTile: ; 1a609 (6:6609)
and a
ret
-DoorTileIDPointers: ; 1a62c (6:662c)
- db OVERWORLD
- dw OverworldDoorTileIDs
- db FOREST
- dw ForestDoorTileIDs
- db MART
- dw MartDoorTileIDs
- db HOUSE
- dw HouseDoorTileIDs
- db FOREST_GATE
- dw TilesetMuseumDoorTileIDs
- db MUSEUM
- dw TilesetMuseumDoorTileIDs
- db GATE
- dw TilesetMuseumDoorTileIDs
- db SHIP
- dw ShipDoorTileIDs
- db LOBBY
- dw LobbyDoorTileIDs
- db MANSION
- dw MansionDoorTileIDs
- db LAB
- dw LabDoorTileIDs
- db FACILITY
- dw FacilityDoorTileIDs
- db PLATEAU
- dw PlateauDoorTileIDs
+DoorTileIDPointers:
+ dbw OVERWORLD, OverworldDoorTileIDs
+ dbw FOREST, ForestDoorTileIDs
+ dbw MART, MartDoorTileIDs
+ dbw HOUSE, HouseDoorTileIDs
+ dbw FOREST_GATE, TilesetMuseumDoorTileIDs
+ dbw MUSEUM, TilesetMuseumDoorTileIDs
+ dbw GATE, TilesetMuseumDoorTileIDs
+ dbw SHIP, ShipDoorTileIDs
+ dbw LOBBY, LobbyDoorTileIDs
+ dbw MANSION, MansionDoorTileIDs
+ dbw LAB, LabDoorTileIDs
+ dbw FACILITY, FacilityDoorTileIDs
+ dbw PLATEAU, PlateauDoorTileIDs
db $ff
-OverworldDoorTileIDs: ; 1a654 (6:6654)
+OverworldDoorTileIDs:
db $1B,$58,$00
-ForestDoorTileIDs: ; 1a657 (6:6657)
+ForestDoorTileIDs:
db $3a,$00
-MartDoorTileIDs: ; 1a659 (6:6659)
+MartDoorTileIDs:
db $5e,$00
-HouseDoorTileIDs: ; 1a65b (6:665b)
+HouseDoorTileIDs:
db $54,$00
-TilesetMuseumDoorTileIDs: ; 1a65d (6:665d)
+TilesetMuseumDoorTileIDs:
db $3b,$00
-ShipDoorTileIDs: ; 1a65f (6:665f)
+ShipDoorTileIDs:
db $1e,$00
-LobbyDoorTileIDs: ; 1a661 (6:6661)
+LobbyDoorTileIDs:
db $1c,$38,$1a,$00
-MansionDoorTileIDs: ; 1a665 (6:6665)
+MansionDoorTileIDs:
db $1a,$1c,$53,$00
-LabDoorTileIDs: ; 1a669 (6:6669)
+LabDoorTileIDs:
db $34,$00
-FacilityDoorTileIDs: ; 1a66b (6:666b)
+FacilityDoorTileIDs:
db $43,$58,$1b,$00
-PlateauDoorTileIDs: ; 1a66f (6:666f)
+PlateauDoorTileIDs:
db $3b,$1b,$00
diff --git a/engine/overworld/elevator.asm b/engine/overworld/elevator.asm
index 3a23d410..7ff4ff71 100755
--- a/engine/overworld/elevator.asm
+++ b/engine/overworld/elevator.asm
@@ -1,46 +1,48 @@
-ShakeElevator: ; 7bf15 (1e:7f15)
- ld de, $ffe0
- call Func_7bf64
- ld de, $240
- call Func_7bf64
+ShakeElevator:
+ ld de, -$20
+ call ShakeElevatorRedrawRow
+ ld de, SCREEN_HEIGHT * $20
+ call ShakeElevatorRedrawRow
call Delay3
ld a, $ff
call PlaySound
ld a, [hSCY]
ld d, a
ld e, $1
- ; number of times to play collision sfx
- ld b, $64
-.asm_7bf30
+ ld b, 100
+.shakeLoop ; scroll the BG up and down and play a sound effect
ld a, e
xor $fe
ld e, a
add d
ld [hSCY], a
push bc
- ld c, BANK(SFX_02_5b)
- ld a, (SFX_02_5b - SFX_Headers_02) / 3
+ ld c, BANK(SFX_Collision_1)
+ ld a, SFX_COLLISION
call PlayMusic
pop bc
- ld c, $2
+ ld c, 2
call DelayFrames
dec b
- jr nz, .asm_7bf30
+ jr nz, .shakeLoop
ld a, d
ld [hSCY], a
ld a, $ff
call PlaySound
- ld c, BANK(SFX_02_5f)
- ld a, (SFX_02_5f - SFX_Headers_02) / 3
+ ld c, BANK(SFX_Safari_Zone_PA)
+ ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
-.asm_7bf57
- ld a, [wc02a]
- cp $b9
- jr z, .asm_7bf57
+.musicLoop
+ ld a, [wChannelSoundIDs + Ch4]
+ cp SFX_SAFARI_ZONE_PA
+ jr z, .musicLoop
call UpdateSprites
jp PlayDefaultMusic
-Func_7bf64: ; 7bf64 (1e:7f64)
+ShakeElevatorRedrawRow:
+; This function is used to redraw certain portions of the screen, but it does
+; not appear to ever result in any visible effect, so this function seems to
+; be pointless.
ld hl, wMapViewVRAMPointer + 1
ld a, [hld]
push af
@@ -54,7 +56,7 @@ Func_7bf64: ; 7bf64 (1e:7f64)
add hl, de
ld a, h
and $3
- or $98
+ or vBGMap0 / $100
ld d, a
ld a, l
pop hl
diff --git a/engine/overworld/emotion_bubbles.asm b/engine/overworld/emotion_bubbles.asm
index 7106063b..ac4276bd 100755
--- a/engine/overworld/emotion_bubbles.asm
+++ b/engine/overworld/emotion_bubbles.asm
@@ -1,30 +1,33 @@
-EmotionBubble: ; 17c47 (5:7c47)
- ld a, [wcd50]
+EmotionBubble:
+ ld a, [wWhichEmotionBubble]
ld c, a
- ld b, $0
- ld hl, EmotionBubblesPointerTable ; $7caf
+ ld b, 0
+ ld hl, EmotionBubblesPointerTable
add hl, bc
add hl, bc
ld e, [hl]
inc hl
ld d, [hl]
ld hl, vChars1 + $780
- ld bc, (BANK(EmotionBubblesPointerTable) << 8) + $04
+ lb bc, BANK(EmotionBubbles), $04
call CopyVideoData
ld a, [wUpdateSpritesEnabled]
push af
ld a, $ff
ld [wUpdateSpritesEnabled], a
ld a, [wd736]
- bit 6, a
- ld hl, wOAMBuffer + $8f
- ld de, wOAMBuffer + $9f
- jr z, .asm_17c7a
- ld hl, wOAMBuffer + $7f
- ld de, wOAMBuffer + $8f
-.asm_17c7a
+ bit 6, a ; are the last 4 OAM entries reserved for a shadow or fishing rod?
+ ld hl, wOAMBuffer + 4 * 35 + $3 ; $8f
+ ld de, wOAMBuffer + 4 * 39 + $3 ; $9f
+ jr z, .next
+ ld hl, wOAMBuffer + 4 * 31 + $3 ; $7f
+ ld de, wOAMBuffer + 4 * 35 + $3 ; $8f
+
+; Copy OAM data 16 bytes forward to make room for emotion bubble OAM data at the
+; start of the OAM buffer.
+.next
ld bc, $90
-.asm_17c7d
+.loop
ld a, [hl]
ld [de], a
dec hl
@@ -32,12 +35,14 @@ EmotionBubble: ; 17c47 (5:7c47)
dec bc
ld a, c
or b
- jr nz, .asm_17c7d
+ jr nz, .loop
+
+; get the screen coordinates of the sprite the bubble is to be displayed above
ld hl, wSpriteStateData1 + 4
- ld a, [wcd4f]
+ ld a, [wEmotionBubbleSpriteIndex]
swap a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hli]
ld b, a
@@ -45,24 +50,25 @@ EmotionBubble: ; 17c47 (5:7c47)
ld a, [hl]
add $8
ld c, a
- ld de, EmotionBubblesOAM ; $7cb5
+
+ ld de, EmotionBubblesOAM
xor a
call WriteOAMBlock
- ld c, $3c
+ ld c, 60
call DelayFrames
pop af
ld [wUpdateSpritesEnabled], a
call DelayFrame
jp UpdateSprites
-EmotionBubblesPointerTable: ; 17caf (5:7caf)
+EmotionBubblesPointerTable:
dw EmotionBubbles
dw EmotionBubbles + $40
dw EmotionBubbles + $80
-EmotionBubblesOAM: ; 17cb5 (5:7cb5)
+EmotionBubblesOAM:
db $F8,$00,$F9,$00
db $FA,$00,$FB,$00
-EmotionBubbles: ; 17cbd (5:7cbd)
+EmotionBubbles:
INCBIN "gfx/emotion_bubbles.2bpp"
diff --git a/engine/overworld/field_move_messages.asm b/engine/overworld/field_move_messages.asm
new file mode 100644
index 00000000..69914bfc
--- /dev/null
+++ b/engine/overworld/field_move_messages.asm
@@ -0,0 +1,57 @@
+PrintStrengthTxt:
+ ld hl, wd728
+ set 0, [hl]
+ ld hl, UsedStrengthText
+ call PrintText
+ ld hl, CanMoveBouldersText
+ jp PrintText
+
+UsedStrengthText:
+ TX_FAR _UsedStrengthText
+ TX_ASM
+ ld a, [wcf91]
+ call PlayCry
+ call Delay3
+ jp TextScriptEnd
+
+CanMoveBouldersText:
+ TX_FAR _CanMoveBouldersText
+ db "@"
+
+IsSurfingAllowed:
+; Returns whether surfing is allowed in bit 1 of wd728.
+; Surfing isn't allowed on the Cycling Road or in the lowest level of the
+; Seafoam Islands before the current has been slowed with boulders.
+ ld hl, wd728
+ set 1, [hl]
+ ld a, [wd732]
+ bit 5, a
+ jr nz, .forcedToRideBike
+ ld a, [wCurMap]
+ cp SEAFOAM_ISLANDS_5
+ ret nz
+ CheckBothEventsSet EVENT_SEAFOAM4_BOULDER1_DOWN_HOLE, EVENT_SEAFOAM4_BOULDER2_DOWN_HOLE
+ ret z
+ ld hl, CoordsData_cdf7
+ call ArePlayerCoordsInArray
+ ret nc
+ ld hl, wd728
+ res 1, [hl]
+ ld hl, CurrentTooFastText
+ jp PrintText
+.forcedToRideBike
+ ld hl, wd728
+ res 1, [hl]
+ ld hl, CyclingIsFunText
+ jp PrintText
+
+CoordsData_cdf7:
+ db $0B,$07,$FF
+
+CurrentTooFastText:
+ TX_FAR _CurrentTooFastText
+ db "@"
+
+CyclingIsFunText:
+ TX_FAR _CyclingIsFunText
+ db "@"
diff --git a/engine/overworld/healing_machine.asm b/engine/overworld/healing_machine.asm
index 90d306c3..38a44cfb 100755
--- a/engine/overworld/healing_machine.asm
+++ b/engine/overworld/healing_machine.asm
@@ -1,71 +1,71 @@
-AnimateHealingMachine: ; 70433 (1c:4433)
- ld de, PokeCenterFlashingMonitorAndHealBall ; $44b7
+AnimateHealingMachine:
+ ld de, PokeCenterFlashingMonitorAndHealBall
ld hl, vChars0 + $7c0
- ld bc, (BANK(PokeCenterFlashingMonitorAndHealBall) << 8) + $03
+ lb bc, BANK(PokeCenterFlashingMonitorAndHealBall), $03 ; loads one too many tiles
call CopyVideoData
ld hl, wUpdateSpritesEnabled
ld a, [hl]
push af
ld [hl], $ff
push hl
- ld a, [rOBP1] ; $ff49
+ ld a, [rOBP1]
push af
ld a, $e0
- ld [rOBP1], a ; $ff49
+ ld [rOBP1], a
ld hl, wOAMBuffer + $84
- ld de, PokeCenterOAMData ; $44d7
- call Func_70503
- ld a, $4
- ld [wMusicHeaderPointer], a
+ ld de, PokeCenterOAMData
+ call CopyHealingMachineOAM
+ ld a, 4
+ ld [wAudioFadeOutControl], a
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
-.asm_70464
- ld a, [wMusicHeaderPointer]
- and a
- jr nz, .asm_70464
- ld a, [wPartyCount] ; wPartyCount
+.waitLoop
+ ld a, [wAudioFadeOutControl]
+ and a ; is fade-out finished?
+ jr nz, .waitLoop ; if not, check again
+ ld a, [wPartyCount]
ld b, a
-.asm_7046e
- call Func_70503
- ld a, (SFX_02_4a - SFX_Headers_02) / 3
+.partyLoop
+ call CopyHealingMachineOAM
+ ld a, SFX_HEALING_MACHINE
call PlaySound
- ld c, $1e
+ ld c, 30
call DelayFrames
dec b
- jr nz, .asm_7046e
- ld a, [wc0ef]
- cp $1f
- ld [wc0f0], a
- jr nz, .asm_70495
+ jr nz, .partyLoop
+ ld a, [wAudioROMBank]
+ cp BANK(Audio3_UpdateMusic)
+ ld [wAudioSavedROMBank], a
+ jr nz, .next
ld a, $ff
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, BANK(Music_PkmnHealed)
- ld [wc0ef], a
-.asm_70495
+ ld [wAudioROMBank], a
+.next
ld a, MUSIC_PKMN_HEALED
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld d, $28
call FlashSprite8Times
-.asm_704a2
- ld a, [wc026]
- cp MUSIC_PKMN_HEALED
- jr z, .asm_704a2
- ld c, $20
+.waitLoop2
+ ld a, [wChannelSoundIDs]
+ cp MUSIC_PKMN_HEALED ; is the healed music still playing?
+ jr z, .waitLoop2 ; if so, check gain
+ ld c, 32
call DelayFrames
pop af
- ld [rOBP1], a ; $ff49
+ ld [rOBP1], a
pop hl
pop af
ld [hl], a
jp UpdateSprites
-PokeCenterFlashingMonitorAndHealBall: ; 704b7 (1c:44b7)
+PokeCenterFlashingMonitorAndHealBall:
INCBIN "gfx/pokecenter_ball.2bpp"
-PokeCenterOAMData: ; 704d7 (1c:44d7)
+PokeCenterOAMData:
db $24,$34,$7C,$10 ; heal machine monitor
db $2B,$30,$7D,$10 ; pokeballs 1-6
db $2B,$38,$7D,$30
@@ -75,7 +75,7 @@ PokeCenterOAMData: ; 704d7 (1c:44d7)
db $35,$38,$7D,$30
; d = value to xor with palette
-FlashSprite8Times: ; 704f3 (1c:44f3)
+FlashSprite8Times:
ld b, 8
.loop
ld a, [rOBP1]
@@ -87,7 +87,8 @@ FlashSprite8Times: ; 704f3 (1c:44f3)
jr nz, .loop
ret
-Func_70503: ; 70503 (1c:4503)
+CopyHealingMachineOAM:
+; copy one OAM entry and advance the pointers
ld a, [de]
inc de
ld [hli], a
diff --git a/engine/overworld/hidden_items.asm b/engine/overworld/hidden_items.asm
index 17288a17..32783f83 100755
--- a/engine/overworld/hidden_items.asm
+++ b/engine/overworld/hidden_items.asm
@@ -1,45 +1,43 @@
-HiddenItems: ; 76688 (1d:6688)
+HiddenItems:
ld hl, HiddenItemCoords
- call Func_76857
- ld [wTrainerScreenX], a
- ld hl, wd6f0
- ld a, [wTrainerScreenX]
+ call FindHiddenItemOrCoinsIndex
+ ld [wHiddenItemOrCoinsIndex], a
+ ld hl, wObtainedHiddenItemsFlags
+ ld a, [wHiddenItemOrCoinsIndex]
ld c, a
- ld b, $2
+ ld b, FLAG_TEST
predef FlagActionPredef
ld a, c
and a
ret nz
call EnableAutoTextBoxDrawing
- ld a, $1
+ ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ld a, [wWhichTrade] ; item ID
+ ld a, [wHiddenObjectFunctionArgument] ; item ID
ld [wd11e], a
call GetItemName
- ld a, $24
- jp PrintPredefTextID
+ tx_pre_jump FoundHiddenItemText
INCLUDE "data/hidden_item_coords.asm"
-FoundHiddenItemText: ; 7675b (1d:675b)
-; XXX where is the pointer to this?
+FoundHiddenItemText:
TX_FAR _FoundHiddenItemText
- db $8
- ld a, [wWhichTrade] ; item ID
+ TX_ASM
+ ld a, [wHiddenObjectFunctionArgument] ; item ID
ld b, a
ld c, 1
call GiveItem
- jr nc, .BagFull
- ld hl, wd6f0
- ld a, [wTrainerScreenX]
+ jr nc, .bagFull
+ ld hl, wObtainedHiddenItemsFlags
+ ld a, [wHiddenItemOrCoinsIndex]
ld c, a
- ld b, $1
+ ld b, FLAG_SET
predef FlagActionPredef
- ld a, (SFX_02_3b - SFX_Headers_02) / 3
- call PlaySoundWaitForCurrent ; play sound
- call WaitForSoundToFinish ; wait for sound to finish playing
+ ld a, SFX_GET_ITEM_2
+ call PlaySoundWaitForCurrent
+ call WaitForSoundToFinish
jp TextScriptEnd
-.BagFull
+.bagFull
call WaitForTextScrollButtonPress ; wait for button press
xor a
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
@@ -47,116 +45,117 @@ FoundHiddenItemText: ; 7675b (1d:675b)
call PrintText
jp TextScriptEnd
-HiddenItemBagFullText: ; 76794 (1d:6794)
+HiddenItemBagFullText:
TX_FAR _HiddenItemBagFullText
db "@"
-HiddenCoins: ; 76799 (1d:6799)
+HiddenCoins:
ld b, COIN_CASE
- predef IsItemInBag_
+ predef GetQuantityOfItemInBag
ld a, b
and a
ret z
ld hl, HiddenCoinCoords
- call Func_76857
- ld [wTrainerScreenX], a
- ld hl, wd6fe
- ld a, [wTrainerScreenX]
+ call FindHiddenItemOrCoinsIndex
+ ld [wHiddenItemOrCoinsIndex], a
+ ld hl, wObtainedHiddenCoinsFlags
+ ld a, [wHiddenItemOrCoinsIndex]
ld c, a
- ld b, $2
+ ld b, FLAG_TEST
predef FlagActionPredef
ld a, c
and a
ret nz
xor a
- ld [$ff9f], a
- ld [$ffa0], a
- ld [$ffa1], a
- ld a, [wWhichTrade]
+ ld [hUnusedCoinsByte], a
+ ld [hCoins], a
+ ld [hCoins + 1], a
+ ld a, [wHiddenObjectFunctionArgument]
sub COIN
cp 10
jr z, .bcd10
cp 20
jr z, .bcd20
cp 40
- jr z, .bcd20
+ jr z, .bcd20 ; should be bcd40
jr .bcd100
.bcd10
ld a, $10
- ld [$ffa1], a
- jr .bcddone
+ ld [hCoins + 1], a
+ jr .bcdDone
.bcd20
ld a, $20
- ld [$ffa1], a
- jr .bcddone
+ ld [hCoins + 1], a
+ jr .bcdDone
.bcd40 ; due to a typo, this is never used
ld a, $40
- ld [$ffa1], a
- jr .bcddone
+ ld [hCoins + 1], a
+ jr .bcdDone
.bcd100
ld a, $1
- ld [$ffa0], a
-.bcddone
+ ld [hCoins], a
+.bcdDone
ld de, wPlayerCoins + 1
- ld hl, $ffa1
+ ld hl, hCoins + 1
ld c, $2
predef AddBCDPredef
- ld hl, wd6fe
- ld a, [wTrainerScreenX]
+ ld hl, wObtainedHiddenCoinsFlags
+ ld a, [wHiddenItemOrCoinsIndex]
ld c, a
- ld b, $1
+ ld b, FLAG_SET
predef FlagActionPredef
call EnableAutoTextBoxDrawing
ld a, [wPlayerCoins]
cp $99
- jr nz, .RoomInCoinCase
+ jr nz, .roomInCoinCase
ld a, [wPlayerCoins + 1]
cp $99
- jr nz, .RoomInCoinCase
- ld a, $2c
+ jr nz, .roomInCoinCase
+ tx_pre_id DroppedHiddenCoinsText
jr .done
-.RoomInCoinCase
- ld a, $2b
+.roomInCoinCase
+ tx_pre_id FoundHiddenCoinsText
.done
jp PrintPredefTextID
INCLUDE "data/hidden_coins.asm"
-FoundHiddenCoinsText: ; 76847 (1d:6847)
+FoundHiddenCoinsText:
TX_FAR _FoundHiddenCoinsText
- db $10,"@"
+ TX_SFX_ITEM_2
+ db "@"
-DroppedHiddenCoinsText: ; 7684d (1d:684d)
+DroppedHiddenCoinsText:
TX_FAR _FoundHiddenCoins2Text
- db $10
+ TX_SFX_ITEM_2
TX_FAR _DroppedHiddenCoinsText
db "@"
-Func_76857: ; 76857 (1d:6857)
- ld a, [wTrainerScreenY]
+FindHiddenItemOrCoinsIndex:
+ ld a, [wHiddenObjectY]
ld d, a
- ld a, [wTrainerScreenX]
+ ld a, [wHiddenObjectX]
ld e, a
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
ld b, a
- ld c, $ff
+ ld c, -1
.loop
inc c
ld a, [hli]
cp $ff ; end of the list?
ret z ; if so, we're done here
cp b
- jr nz, .asm_76877 ; 0x7686b $a
+ jr nz, .next1
ld a, [hli]
cp d
- jr nz, .asm_76878 ; 0x7686f $7
+ jr nz, .next2
ld a, [hli]
cp e
jr nz, .loop
ld a, c
ret
-.asm_76877
+.next1
inc hl
-.asm_76878
+.next2
inc hl
jr .loop
diff --git a/engine/overworld/hidden_objects.asm b/engine/overworld/hidden_objects.asm
index ae67aeed..dcdf8537 100755
--- a/engine/overworld/hidden_objects.asm
+++ b/engine/overworld/hidden_objects.asm
@@ -1,4 +1,4 @@
-Func_46981: ; 46981 (11:6981)
+IsPlayerOnDungeonWarp:
xor a
ld [wWhichDungeonWarp], a
ld a, [wd72d]
@@ -6,7 +6,7 @@ Func_46981: ; 46981 (11:6981)
ret nz
call ArePlayerCoordsInArray
ret nc
- ld a, [wWhichTrade]
+ ld a, [wCoordIndex]
ld [wWhichDungeonWarp], a
ld hl, wd72d
set 4, [hl]
@@ -15,7 +15,7 @@ Func_46981: ; 46981 (11:6981)
ret
; if a hidden object was found, stores $00 in [$ffee], else stores $ff
-CheckForHiddenObject: ; 469a0 (11:69a0)
+CheckForHiddenObject:
ld hl, $ffeb
xor a
ld [hli], a
@@ -29,7 +29,7 @@ CheckForHiddenObject: ; 469a0 (11:69a0)
ld b, a
cp $ff
jr z, .noMatch
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp b
jr z, .foundMatchingMap
inc de
@@ -58,7 +58,7 @@ CheckForHiddenObject: ; 469a0 (11:69a0)
ld [wHiddenObjectX], a
ld c, a
call CheckIfCoordsInFrontOfPlayerMatch
- ld a, [$ffea]
+ ld a, [hCoordsInFrontOfPlayerMatch]
and a
jr z, .foundMatchingObject
inc hl
@@ -85,8 +85,8 @@ CheckForHiddenObject: ; 469a0 (11:69a0)
ret
; checks if the coordinates in front of the player's sprite match Y in b and X in c
-; [$ffea] = $00 if they match, $ff if they don't match
-CheckIfCoordsInFrontOfPlayerMatch: ; 46a01 (11:6a01)
+; [hCoordsInFrontOfPlayerMatch] = $00 if they match, $ff if they don't match
+CheckIfCoordsInFrontOfPlayerMatch:
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
cp SPRITE_FACING_UP
jr z, .facingUp
@@ -95,30 +95,30 @@ CheckIfCoordsInFrontOfPlayerMatch: ; 46a01 (11:6a01)
cp SPRITE_FACING_RIGHT
jr z, .facingRight
; facing down
- ld a, [W_YCOORD]
+ ld a, [wYCoord]
inc a
jr .upDownCommon
.facingUp
- ld a, [W_YCOORD]
+ ld a, [wYCoord]
dec a
.upDownCommon
cp b
jr nz, .didNotMatch
- ld a, [W_XCOORD]
+ ld a, [wXCoord]
cp c
jr nz, .didNotMatch
jr .matched
.facingLeft
- ld a, [W_XCOORD]
+ ld a, [wXCoord]
dec a
jr .leftRightCommon
.facingRight
- ld a, [W_XCOORD]
+ ld a, [wXCoord]
inc a
.leftRightCommon
cp c
jr nz, .didNotMatch
- ld a, [W_YCOORD]
+ ld a, [wYCoord]
cp b
jr nz, .didNotMatch
.matched
@@ -127,7 +127,7 @@ CheckIfCoordsInFrontOfPlayerMatch: ; 46a01 (11:6a01)
.didNotMatch
ld a, $ff
.done
- ld [$ffea], a
+ ld [hCoordsInFrontOfPlayerMatch], a
ret
INCLUDE "data/hidden_objects.asm"
diff --git a/engine/overworld/is_player_just_outside_map.asm b/engine/overworld/is_player_just_outside_map.asm
index 24e434b3..44690db0 100644
--- a/engine/overworld/is_player_just_outside_map.asm
+++ b/engine/overworld/is_player_just_outside_map.asm
@@ -1,13 +1,13 @@
; returns whether the player is one tile outside the map in Z
-IsPlayerJustOutsideMap: ; 128d8 (4:68d8)
- ld a, [W_YCOORD]
+IsPlayerJustOutsideMap:
+ ld a, [wYCoord]
ld b, a
- ld a, [W_CURMAPHEIGHT]
+ ld a, [wCurMapHeight]
call .compareCoordWithMapDimension
ret z
- ld a, [W_XCOORD]
+ ld a, [wXCoord]
ld b, a
- ld a, [W_CURMAPWIDTH]
+ ld a, [wCurMapWidth]
.compareCoordWithMapDimension
add a
cp b
diff --git a/engine/overworld/item.asm b/engine/overworld/item.asm
index a49fc268..9f19100a 100644
--- a/engine/overworld/item.asm
+++ b/engine/overworld/item.asm
@@ -1,9 +1,9 @@
-PickupItem:
+PickUpItem:
call EnableAutoTextBoxDrawing
- ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c
+ ld a, [hSpriteIndexOrTextID]
ld b, a
- ld hl, W_MISSABLEOBJECTLIST
+ ld hl, wMissableObjectList
.missableObjectsListLoop
ld a, [hli]
cp $ff
@@ -17,8 +17,8 @@ PickupItem:
ld a, [hl]
ld [$ffdb], a
- ld hl, W_MAPSPRITEEXTRADATA
- ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c
+ ld hl, wMapSpriteExtraData
+ ld a, [hSpriteIndexOrTextID]
dec a
add a
ld d, 0
@@ -31,7 +31,7 @@ PickupItem:
jr nc, .BagFull
ld a, [$ffdb]
- ld [wcc4d], a
+ ld [wMissableObjectIndex], a
predef HideObject
ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
@@ -46,7 +46,7 @@ PickupItem:
FoundItemText:
TX_FAR _FoundItemText
- db $0B
+ TX_SFX_ITEM_1
db "@"
NoMoreRoomForItemText:
diff --git a/engine/overworld/ledges.asm b/engine/overworld/ledges.asm
index b8c19181..342540b2 100755
--- a/engine/overworld/ledges.asm
+++ b/engine/overworld/ledges.asm
@@ -1,8 +1,8 @@
-HandleLedges: ; 1a672 (6:6672)
+HandleLedges:
ld a, [wd736]
bit 6, a ; already jumping down ledge
ret nz
- ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET
+ ld a, [wCurMapTileset]
and a ; OVERWORLD
ret nz
predef GetTileAndCoordsInFrontOfPlayer
@@ -50,12 +50,12 @@ HandleLedges: ; 1a672 (6:6672)
ld a, $2
ld [wSimulatedJoypadStatesIndex], a
call LoadHoppingShadowOAM
- ld a, (SFX_02_4e - SFX_Headers_02) / 3
+ ld a, SFX_LEDGE
call PlaySound
ret
; (player direction) (tile player standing on) (ledge tile) (input required)
-LedgeTiles: ; 1a6cf (6:66cf)
+LedgeTiles:
db SPRITE_FACING_DOWN, $2C,$37,D_DOWN
db SPRITE_FACING_DOWN, $39,$36,D_DOWN
db SPRITE_FACING_DOWN, $39,$37,D_DOWN
@@ -66,20 +66,21 @@ LedgeTiles: ; 1a6cf (6:66cf)
db SPRITE_FACING_RIGHT,$39,$0D,D_RIGHT
db $FF
-LoadHoppingShadowOAM: ; 1a6f0 (6:66f0)
+LoadHoppingShadowOAM:
ld hl, vChars1 + $7f0
ld de, LedgeHoppingShadow
- ld bc, (BANK(LedgeHoppingShadow) << 8) + $01
+ lb bc, BANK(LedgeHoppingShadow), (LedgeHoppingShadowEnd - LedgeHoppingShadow) / $8
call CopyVideoDataDouble
ld a, $9
- ld bc, $5448 ; b, c = y, x coordinates of shadow
+ lb bc, $54, $48 ; b, c = y, x coordinates of shadow
ld de, LedgeHoppingShadowOAM
call WriteOAMBlock
ret
-LedgeHoppingShadow: ; 1a708 (6:6708)
+LedgeHoppingShadow:
INCBIN "gfx/ledge_hopping_shadow.1bpp"
+LedgeHoppingShadowEnd:
-LedgeHoppingShadowOAM: ; 1a710 (6:6710)
+LedgeHoppingShadowOAM:
db $FF,$10,$FF,$20
db $FF,$40,$FF,$60
diff --git a/engine/overworld/map_sprite_functions1.asm b/engine/overworld/map_sprite_functions1.asm
new file mode 100644
index 00000000..d1a411fa
--- /dev/null
+++ b/engine/overworld/map_sprite_functions1.asm
@@ -0,0 +1,356 @@
+_UpdateSprites:
+ ld h, $c1
+ inc h
+ ld a, $e ; wSpriteStateData2 + $0e
+.spriteLoop
+ ld l, a
+ sub $e
+ ld c, a
+ ld [H_CURRENTSPRITEOFFSET], a
+ ld a, [hl]
+ and a
+ jr z, .skipSprite ; tests $c2Xe
+ push hl
+ push de
+ push bc
+ call .updateCurrentSprite
+ pop bc
+ pop de
+ pop hl
+.skipSprite
+ ld a, l
+ add $10 ; move to next sprite
+ cp $e ; test for overflow (back at $0e)
+ jr nz, .spriteLoop
+ ret
+.updateCurrentSprite
+ cp $1
+ jp nz, UpdateNonPlayerSprite
+ jp UpdatePlayerSprite
+
+UpdateNonPlayerSprite:
+ dec a
+ swap a
+ ld [$ff93], a ; $10 * sprite#
+ ld a, [wNPCMovementScriptSpriteOffset] ; some sprite offset?
+ ld b, a
+ ld a, [H_CURRENTSPRITEOFFSET]
+ cp b
+ jr nz, .unequal
+ jp DoScriptedNPCMovement
+.unequal
+ jp UpdateNPCSprite
+
+; This detects if the current sprite (whose offset is at H_CURRENTSPRITEOFFSET)
+; is going to collide with another sprite by looping over the other sprites.
+; The current sprite's offset will be labelled with i (e.g. $c1i0).
+; The loop sprite's offset will labelled with j (e.g. $c1j0).
+;
+; Note that the Y coordinate of the sprite (in [$c1k4]) is one of the following
+; 9 values when the sprite is aligned with the grid: $fc, $0c, $1c, $2c, ..., $7c.
+; The reason that 4 is added below to the coordinate is to make it align with a
+; multiple of $10 to make comparisons easier.
+DetectCollisionBetweenSprites:
+ nop
+
+ ld h, wSpriteStateData1 / $100
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add wSpriteStateData1 % $100
+ ld l, a
+
+ ld a, [hl] ; a = [$c1i0] (picture) (0 if slot is unused)
+ and a ; is this sprite slot slot used?
+ ret z ; return if not used
+
+ ld a, l
+ add 3
+ ld l, a
+
+ ld a, [hli] ; a = [$c1i3] (delta Y) (-1, 0, or 1)
+ call SetSpriteCollisionValues
+
+ ld a, [hli] ; a = [$C1i4] (Y screen coordinate)
+ add 4 ; align with multiple of $10
+
+; The effect of the following 3 lines is to
+; add 7 to a if moving south or
+; subtract 7 from a if moving north.
+ add b
+ and $f0
+ or c
+
+ ld [$ff90], a ; store Y coordinate adjusted for direction of movement
+
+ ld a, [hli] ; a = [$c1i5] (delta X) (-1, 0, or 1)
+ call SetSpriteCollisionValues
+ ld a, [hl] ; a = [$C1i6] (X screen coordinate)
+
+; The effect of the following 3 lines is to
+; add 7 to a if moving east or
+; subtract 7 from a if moving west.
+ add b
+ and $f0
+ or c
+
+ ld [$ff91], a ; store X coordinate adjusted for direction of movement
+
+ ld a, l
+ add 7
+ ld l, a
+
+ xor a
+ ld [hld], a ; zero [$c1id] XXX what's [$c1id] for?
+ ld [hld], a ; zero [$c1ic] (directions in which collisions occurred)
+
+ ld a, [$ff91]
+ ld [hld], a ; [$c1ib] = adjusted X coordinate
+ ld a, [$ff90]
+ ld [hl], a ; [$c1ia] = adjusted Y coordinate
+
+ xor a ; zero the loop counter
+
+.loop
+ ld [$ff8f], a ; store loop counter
+ swap a
+ ld e, a
+ ld a, [H_CURRENTSPRITEOFFSET]
+ cp e ; does the loop sprite match the current sprite?
+ jp z, .next ; go to the next sprite if they match
+
+ ld d, h
+ ld a, [de] ; a = [$c1j0] (picture) (0 if slot is unused)
+ and a ; is this sprite slot slot used?
+ jp z, .next ; go the next sprite if not used
+
+ inc e
+ inc e
+ ld a, [de] ; a = [$c1j2] ($ff means the sprite is offscreen)
+ inc a
+ jp z, .next ; go the next sprite if offscreen
+
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add 10
+ ld l, a
+
+ inc e
+ ld a, [de] ; a = [$c1j3] (delta Y)
+ call SetSpriteCollisionValues
+
+ inc e
+ ld a, [de] ; a = [$C1j4] (Y screen coordinate)
+ add 4 ; align with multiple of $10
+
+; The effect of the following 3 lines is to
+; add 7 to a if moving south or
+; subtract 7 from a if moving north.
+ add b
+ and $f0
+ or c
+
+ sub [hl] ; subtract the adjusted Y coordinate of sprite i ([$c1ia]) from that of sprite j
+
+; calculate the absolute value of the difference to get the distance
+ jr nc, .noCarry1
+ cpl
+ inc a
+.noCarry1
+ ld [$ff90], a ; store the distance between the two sprites' adjusted Y values
+
+; Use the carry flag set by the above subtraction to determine which sprite's
+; Y coordinate is larger. This information is used later to set [$c1ic],
+; which stores which direction the collision occurred in.
+; The following 5 lines set the lowest 2 bits of c, which are later shifted left by 2.
+; If sprite i's Y is larger, set lowest 2 bits of c to 10.
+; If sprite j's Y is larger or both are equal, set lowest 2 bits of c to 01.
+ push af
+ rl c
+ pop af
+ ccf
+ rl c
+
+; If sprite i's delta Y is 0, then b = 7, else b = 9.
+ ld b, 7
+ ld a, [hl] ; a = [$c1ia] (adjusted Y coordinate)
+ and $f
+ jr z, .next1
+ ld b, 9
+
+.next1
+ ld a, [$ff90] ; a = distance between adjusted Y coordinates
+ sub b
+ ld [$ff92], a ; store distance adjusted using sprite i's direction
+ ld a, b
+ ld [$ff90], a ; store 7 or 9 depending on sprite i's delta Y
+ jr c, .checkXDistance
+
+; If sprite j's delta Y is 0, then b = 7, else b = 9.
+ ld b, 7
+ dec e
+ ld a, [de] ; a = [$c1j3] (delta Y)
+ inc e
+ and a
+ jr z, .next2
+ ld b, 9
+
+.next2
+ ld a, [$ff92] ; a = distance adjusted using sprite i's direction
+ sub b ; adjust distance using sprite j's direction
+ jr z, .checkXDistance
+ jr nc, .next ; go to next sprite if distance is still positive after both adjustments
+
+.checkXDistance
+ inc e
+ inc l
+ ld a, [de] ; a = [$c1j5] (delta X)
+
+ push bc
+
+ call SetSpriteCollisionValues
+ inc e
+ ld a, [de] ; a = [$c1j6] (X screen coordinate)
+
+; The effect of the following 3 lines is to
+; add 7 to a if moving east or
+; subtract 7 from a if moving west.
+ add b
+ and $f0
+ or c
+
+ pop bc
+
+ sub [hl] ; subtract the adjusted X coordinate of sprite i ([$c1ib]) from that of sprite j
+
+; calculate the absolute value of the difference to get the distance
+ jr nc, .noCarry2
+ cpl
+ inc a
+.noCarry2
+ ld [$ff91], a ; store the distance between the two sprites' adjusted X values
+
+; Use the carry flag set by the above subtraction to determine which sprite's
+; X coordinate is larger. This information is used later to set [$c1ic],
+; which stores which direction the collision occurred in.
+; The following 5 lines set the lowest 2 bits of c.
+; If sprite i's X is larger, set lowest 2 bits of c to 10.
+; If sprite j's X is larger or both are equal, set lowest 2 bits of c to 01.
+ push af
+ rl c
+ pop af
+ ccf
+ rl c
+
+; If sprite i's delta X is 0, then b = 7, else b = 9.
+ ld b, 7
+ ld a, [hl] ; a = [$c1ib] (adjusted X coordinate)
+ and $f
+ jr z, .next3
+ ld b, 9
+
+.next3
+ ld a, [$ff91] ; a = distance between adjusted X coordinates
+ sub b
+ ld [$ff92], a ; store distance adjusted using sprite i's direction
+ ld a, b
+ ld [$ff91], a ; store 7 or 9 depending on sprite i's delta X
+ jr c, .collision
+
+; If sprite j's delta X is 0, then b = 7, else b = 9.
+ ld b, 7
+ dec e
+ ld a, [de] ; a = [$c1j5] (delta X)
+ inc e
+ and a
+ jr z, .next4
+ ld b, 9
+
+.next4
+ ld a, [$ff92] ; a = distance adjusted using sprite i's direction
+ sub b ; adjust distance using sprite j's direction
+ jr z, .collision
+ jr nc, .next ; go to next sprite if distance is still positive after both adjustments
+
+.collision
+ ld a, [$ff91] ; a = 7 or 9 depending on sprite i's delta X
+ ld b, a
+ ld a, [$ff90] ; a = 7 or 9 depending on sprite i's delta Y
+ inc l
+
+; If delta X isn't 0 and delta Y is 0, then b = %0011, else b = %1100.
+; (note that normally if delta X isn't 0, then delta Y must be 0 and vice versa)
+ cp b
+ jr c, .next5
+ ld b, %1100
+ jr .next6
+.next5
+ ld b, %0011
+
+.next6
+ ld a, c ; c has 2 bits set (one of bits 0-1 is set for the X axis and one of bits 2-3 for the Y axis)
+ and b ; we select either the bit in bits 0-1 or bits 2-3 based on the calculation immediately above
+ or [hl] ; or with existing collision direction bits in [$c1ic]
+ ld [hl], a ; store new value
+ ld a, c ; useless code because a is overwritten before being used again
+
+; set bit in [$c1ie] or [$c1if] to indicate which sprite the collision occurred with
+ inc l
+ inc l
+ ld a, [$ff8f] ; a = loop counter
+ ld de, SpriteCollisionBitTable
+ add a
+ add e
+ ld e, a
+ jr nc, .noCarry3
+ inc d
+.noCarry3
+ ld a, [de]
+ or [hl]
+ ld [hli], a
+ inc de
+ ld a, [de]
+ or [hl]
+ ld [hl], a
+
+.next
+ ld a, [$ff8f] ; a = loop counter
+ inc a
+ cp $10
+ jp nz, .loop
+ ret
+
+; takes delta X or delta Y in a
+; b = delta X/Y
+; c = 0 if delta X/Y is 0
+; c = 7 if delta X/Y is 1
+; c = 9 if delta X/Y is -1
+SetSpriteCollisionValues:
+ and a
+ ld b, 0
+ ld c, 0
+ jr z, .done
+ ld c, 9
+ cp -1
+ jr z, .ok
+ ld c, 7
+ ld a, 0
+.ok
+ ld b, a
+.done
+ ret
+
+SpriteCollisionBitTable:
+ db %00000000,%00000001
+ db %00000000,%00000010
+ db %00000000,%00000100
+ db %00000000,%00001000
+ db %00000000,%00010000
+ db %00000000,%00100000
+ db %00000000,%01000000
+ db %00000000,%10000000
+ db %00000001,%00000000
+ db %00000010,%00000000
+ db %00000100,%00000000
+ db %00001000,%00000000
+ db %00010000,%00000000
+ db %00100000,%00000000
+ db %01000000,%00000000
+ db %10000000,%00000000
diff --git a/engine/overworld/map_sprites.asm b/engine/overworld/map_sprites.asm
index df39d112..05588321 100755
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -8,7 +8,7 @@
; fields, respectively, within loops. The X is the loop index.
; If there is an inner loop, Y is the inner loop index, i.e. $C1Y* and $C2Y*
; denote fields of the sprite slots interated over in the inner loop.
-InitMapSprites: ; 1785b (5:785b)
+InitMapSprites:
call InitOutsideMapSprites
ret c ; return if the map is an outside map (already handled by above call)
; if the map is an inside map (i.e. mapID >= $25)
@@ -29,17 +29,17 @@ InitMapSprites: ; 1785b (5:785b)
; This is used for both inside and outside maps, since it is called by
; InitOutsideMapSprites.
; Loads tile pattern data for sprites into VRAM.
-LoadMapSpriteTilePatterns: ; 17871 (5:7871)
- ld a,[W_NUMSPRITES]
+LoadMapSpriteTilePatterns:
+ ld a,[wNumSprites]
and a ; are there any sprites?
jr nz,.spritesExist
ret
.spritesExist
- ld c,a ; c = [W_NUMSPRITES]
+ ld c,a ; c = [wNumSprites]
ld b,$10 ; number of sprite slots
ld hl,wSpriteStateData2 + $0d
xor a
- ld [$ff8e],a ; 4-tile sprite counter
+ ld [hFourTileSpriteCount],a
.copyPictureIDLoop ; loop to copy picture ID from $C2XD to $C2XE
ld a,[hli] ; $C2XD (sprite picture ID)
ld [hld],a ; $C2XE
@@ -98,14 +98,14 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871)
cp a,SPRITE_BALL ; is it a 4-tile sprite?
jr c,.notFourTileSprite
pop af
- ld a,[$ff8e] ; 4-tile sprite counter
+ ld a,[hFourTileSpriteCount]
add a,11
jr .storeVRAMSlot
.notFourTileSprite
pop af
.storeVRAMSlot
ld [hl],a ; store VRAM slot at $C2XE
- ld [$ff8d],a ; used to determine if it's 4-tile sprite later
+ ld [hVRAMSlot],a ; used to determine if it's 4-tile sprite later
ld a,b ; a = current sprite picture ID
dec a
add a
@@ -128,7 +128,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871)
push bc
ld hl,vNPCSprites ; VRAM base address
ld bc,$c0 ; number of bytes per VRAM slot
- ld a,[$ff8d]
+ ld a,[hVRAMSlot]
cp a,11 ; is it a 4-tile sprite?
jr nc,.fourTileSpriteVRAMAddr
ld d,a
@@ -142,13 +142,13 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871)
jr .loadStillTilePattern
.fourTileSpriteVRAMAddr
ld hl,vSprites + $7c0 ; address for second 4-tile sprite
- ld a,[$ff8e] ; 4-tile sprite counter
- and a ; is it the first 4-tile sprite?
+ ld a,[hFourTileSpriteCount]
+ and a
jr nz,.loadStillTilePattern
; if it's the first 4-tile sprite
ld hl,vSprites + $780 ; address for first 4-tile sprite
inc a
- ld [$ff8e],a ; 4-tile sprite counter
+ ld [hFourTileSpriteCount],a
.loadStillTilePattern
pop bc
pop de
@@ -168,7 +168,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871)
.skipFirstLoad
pop de
pop hl
- ld a,[$ff8d]
+ ld a,[hVRAMSlot]
cp a,11 ; is it a 4-tile sprite?
jr nc,.skipSecondLoad ; if so, there is no second block
push de
@@ -236,7 +236,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871)
; de = pointer to sprite sheet
; bc = length in bytes
; a = ROM bank
-ReadSpriteSheetData: ; 17971 (5:7971)
+ReadSpriteSheetData:
ld a,[hli]
ld e,a
ld a,[hli]
@@ -250,8 +250,8 @@ ReadSpriteSheetData: ; 17971 (5:7971)
; Loads sprite set for outside maps (cities and routes) and sets VRAM slots.
; sets carry if the map is a city or route, unsets carry if not
-InitOutsideMapSprites: ; 1797b (5:797b)
- ld a,[W_CURMAP]
+InitOutsideMapSprites:
+ ld a,[wCurMap]
cp a,REDS_HOUSE_1F ; is the map a city or a route (map ID less than $25)?
ret nc ; if not, return
ld hl,MapSpriteSets
@@ -267,12 +267,12 @@ InitOutsideMapSprites: ; 1797b (5:797b)
ld a,[wFontLoaded]
bit 0,a ; reloading upper half of tile patterns after displaying text?
jr nz,.loadSpriteSet ; if so, forcibly reload the sprite set
- ld a,[W_SPRITESETID]
+ ld a,[wSpriteSetID]
cp b ; has the sprite set ID changed?
jr z,.skipLoadingSpriteSet ; if not, don't load it again
.loadSpriteSet
ld a,b
- ld [W_SPRITESETID],a
+ ld [wSpriteSetID],a
dec a
ld b,a
sla a
@@ -291,7 +291,7 @@ InitOutsideMapSprites: ; 1797b (5:797b)
ld hl,wSpriteStateData2 + $0d
ld a,SPRITE_RED
ld [hl],a
- ld bc,W_SPRITESET
+ ld bc,wSpriteSet
; Load the sprite set into RAM.
; This loop also fills $C2XD (sprite picture ID) where X is from $0 to $A
; with picture ID's. This is done so that LoadMapSpriteTilePatterns will
@@ -317,13 +317,13 @@ InitOutsideMapSprites: ; 1797b (5:797b)
ld [hl],a ; $C2XD (sprite picture ID)
dec b
jr nz,.zeroRemainingSlotsLoop
- ld a,[W_NUMSPRITES]
+ ld a,[wNumSprites]
push af ; save number of sprites
ld a,11 ; 11 sprites in sprite set
- ld [W_NUMSPRITES],a
+ ld [wNumSprites],a
call LoadMapSpriteTilePatterns
pop af
- ld [W_NUMSPRITES],a ; restore number of sprites
+ ld [wNumSprites],a ; restore number of sprites
ld hl,wSpriteStateData2 + $1e
ld b,$0f
; The VRAM tile pattern slots that LoadMapSpriteTilePatterns set are in the
@@ -352,7 +352,7 @@ InitOutsideMapSprites: ; 1797b (5:797b)
and a ; is the sprite slot used?
jr z,.skipGettingPictureIndex ; if the sprite slot is not used
ld b,a ; b = picture ID
- ld de,W_SPRITESET
+ ld de,wSpriteSet
; Loop to find the index of the sprite's picture ID within the sprite set.
.getPictureIndexLoop
inc c
@@ -380,7 +380,7 @@ InitOutsideMapSprites: ; 1797b (5:797b)
; Chooses the correct sprite set ID depending on the player's position within
; the map for maps with two sprite sets.
-GetSplitMapSpriteSetID: ; 17a1a (5:7a1a)
+GetSplitMapSpriteSetID:
cp a,$f8
jr z,.route20
ld hl,SplitMapSpriteSets
@@ -399,10 +399,10 @@ GetSplitMapSpriteSetID: ; 17a1a (5:7a1a)
ld b,a
jr z,.eastWestDivide
.northSouthDivide
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
jr .compareCoord
.eastWestDivide
- ld a,[W_XCOORD]
+ ld a,[wXCoord]
.compareCoord
cp b
jr c,.loadSpriteSetID
@@ -415,7 +415,7 @@ GetSplitMapSpriteSetID: ; 17a1a (5:7a1a)
; Route 20 is a special case because the two map sections have a more complex
; shape instead of the map simply being split horizontally or vertically.
.route20
- ld hl,W_XCOORD
+ ld hl,wXCoord
ld a,[hl]
cp a,$2b
ld a,$01
@@ -430,7 +430,7 @@ GetSplitMapSpriteSetID: ; 17a1a (5:7a1a)
jr nc,.next
ld b,$0d
.next
- ld a,[W_YCOORD]
+ ld a,[wYCoord]
cp b
ld a,$0a
ret c
diff --git a/engine/overworld/missable_objects.asm b/engine/overworld/missable_objects.asm
new file mode 100644
index 00000000..8587c0f7
--- /dev/null
+++ b/engine/overworld/missable_objects.asm
@@ -0,0 +1,215 @@
+MarkTownVisitedAndLoadMissableObjects:
+ ld a, [wCurMap]
+ cp ROUTE_1
+ jr nc, .notInTown
+ ld c, a
+ ld b, FLAG_SET
+ ld hl, wTownVisitedFlag ; mark town as visited (for flying)
+ predef FlagActionPredef
+.notInTown
+ ld hl, MapHSPointers
+ ld a, [wCurMap]
+ ld b, $0
+ ld c, a
+ add hl, bc
+ add hl, bc
+ ld a, [hli] ; load missable objects pointer in hl
+ ld h, [hl]
+ ; fall through
+
+LoadMissableObjects:
+ ld l, a
+ push hl
+ ld de, MapHS00 ; calculate difference between out pointer and the base pointer
+ ld a, l
+ sub e
+ jr nc, .asm_f13c
+ dec h
+.asm_f13c
+ ld l, a
+ ld a, h
+ sub d
+ ld h, a
+ ld a, h
+ ld [H_DIVIDEND], a
+ ld a, l
+ ld [H_DIVIDEND+1], a
+ xor a
+ ld [H_DIVIDEND+2], a
+ ld [H_DIVIDEND+3], a
+ ld a, $3
+ ld [H_DIVISOR], a
+ ld b, $2
+ call Divide ; divide difference by 3, resulting in the global offset (number of missable items before ours)
+ ld a, [wCurMap]
+ ld b, a
+ ld a, [H_DIVIDEND+3]
+ ld c, a ; store global offset in c
+ ld de, wMissableObjectList
+ pop hl
+.writeMissableObjectsListLoop
+ ld a, [hli]
+ cp $ff
+ jr z, .done ; end of list
+ cp b
+ jr nz, .done ; not for current map anymore
+ ld a, [hli]
+ inc hl
+ ld [de], a ; write (map-local) sprite ID
+ inc de
+ ld a, c
+ inc c
+ ld [de], a ; write (global) missable object index
+ inc de
+ jr .writeMissableObjectsListLoop
+.done
+ ld a, $ff
+ ld [de], a ; write sentinel
+ ret
+
+InitializeMissableObjectsFlags:
+ ld hl, wMissableObjectFlags
+ ld bc, wMissableObjectFlagsEnd - wMissableObjectFlags
+ xor a
+ call FillMemory ; clear missable objects flags
+ ld hl, MapHS00
+ xor a
+ ld [wMissableObjectCounter], a
+.missableObjectsLoop
+ ld a, [hli]
+ cp $ff ; end of list
+ ret z
+ push hl
+ inc hl
+ ld a, [hl]
+ cp Hide
+ jr nz, .skip
+ ld hl, wMissableObjectFlags
+ ld a, [wMissableObjectCounter]
+ ld c, a
+ ld b, FLAG_SET
+ call MissableObjectFlagAction ; set flag if Item is hidden
+.skip
+ ld hl, wMissableObjectCounter
+ inc [hl]
+ pop hl
+ inc hl
+ inc hl
+ jr .missableObjectsLoop
+
+; tests if current sprite is a missable object that is hidden/has been removed
+IsObjectHidden:
+ ld a, [H_CURRENTSPRITEOFFSET]
+ swap a
+ ld b, a
+ ld hl, wMissableObjectList
+.loop
+ ld a, [hli]
+ cp $ff
+ jr z, .notHidden ; not missable -> not hidden
+ cp b
+ ld a, [hli]
+ jr nz, .loop
+ ld c, a
+ ld b, FLAG_TEST
+ ld hl, wMissableObjectFlags
+ call MissableObjectFlagAction
+ ld a, c
+ and a
+ jr nz, .hidden
+.notHidden
+ xor a
+.hidden
+ ld [$ffe5], a
+ ret
+
+; adds missable object (items, leg. pokemon, etc.) to the map
+; [wMissableObjectIndex]: index of the missable object to be added (global index)
+ShowObject:
+ShowObject2:
+ ld hl, wMissableObjectFlags
+ ld a, [wMissableObjectIndex]
+ ld c, a
+ ld b, FLAG_RESET
+ call MissableObjectFlagAction ; reset "removed" flag
+ jp UpdateSprites
+
+; removes missable object (items, leg. pokemon, etc.) from the map
+; [wMissableObjectIndex]: index of the missable object to be removed (global index)
+HideObject:
+ ld hl, wMissableObjectFlags
+ ld a, [wMissableObjectIndex]
+ ld c, a
+ ld b, FLAG_SET
+ call MissableObjectFlagAction ; set "removed" flag
+ jp UpdateSprites
+
+MissableObjectFlagAction:
+; identical to FlagAction
+
+ push hl
+ push de
+ push bc
+
+ ; bit
+ ld a, c
+ ld d, a
+ and 7
+ ld e, a
+
+ ; byte
+ ld a, d
+ srl a
+ srl a
+ srl a
+ add l
+ ld l, a
+ jr nc, .ok
+ inc h
+.ok
+
+ ; d = 1 << e (bitmask)
+ inc e
+ ld d, 1
+.shift
+ dec e
+ jr z, .shifted
+ sla d
+ jr .shift
+.shifted
+
+ ld a, b
+ and a
+ jr z, .reset
+ cp 2
+ jr z, .read
+
+.set
+ ld a, [hl]
+ ld b, a
+ ld a, d
+ or b
+ ld [hl], a
+ jr .done
+
+.reset
+ ld a, [hl]
+ ld b, a
+ ld a, d
+ xor $ff
+ and b
+ ld [hl], a
+ jr .done
+
+.read
+ ld a, [hl]
+ ld b, a
+ ld a, d
+ and b
+
+.done
+ pop bc
+ pop de
+ pop hl
+ ld c, a
+ ret
diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm
index c4482700..6d05859e 100644
--- a/engine/overworld/movement.asm
+++ b/engine/overworld/movement.asm
@@ -1,4 +1,4 @@
-UpdatePlayerSprite: ; 4e31 (1:4e31)
+UpdatePlayerSprite:
ld a, [wSpriteStateData2]
and a
jr z, .checkIfTextBoxInFrontOfSprite
@@ -12,7 +12,7 @@ UpdatePlayerSprite: ; 4e31 (1:4e31)
; the maximum number for map tiles
.checkIfTextBoxInFrontOfSprite
aCoord 8, 9
- ld [$ff93], a
+ ld [hTilePlayerStandingOn], a
cp $60
jr c, .lowerLeftTileIsMapTile
.disableSprite
@@ -21,52 +21,54 @@ UpdatePlayerSprite: ; 4e31 (1:4e31)
ret
.lowerLeftTileIsMapTile
call DetectCollisionBetweenSprites
- ld h, $c1
- ld a, [wWalkCounter] ; wcfc5
+ ld h, wSpriteStateData1 / $100
+ ld a, [wWalkCounter]
and a
- jr nz, .asm_4e90
- ld a, [wd528]
- bit 2, a
- jr z, .asm_4e65
- xor a
- jr .asm_4e86
-.asm_4e65
- bit 3, a
- jr z, .asm_4e6d
- ld a, $4
- jr .asm_4e86
-.asm_4e6d
- bit 1, a
- jr z, .asm_4e75
- ld a, $8
- jr .asm_4e86
-.asm_4e75
- bit 0, a
- jr z, .asm_4e7d
- ld a, $c
- jr .asm_4e86
-.asm_4e7d
+ jr nz, .moving
+ ld a, [wPlayerMovingDirection]
+; check if down
+ bit PLAYER_DIR_BIT_DOWN, a
+ jr z, .checkIfUp
+ xor a ; ld a, SPRITE_FACING_DOWN
+ jr .next
+.checkIfUp
+ bit PLAYER_DIR_BIT_UP, a
+ jr z, .checkIfLeft
+ ld a, SPRITE_FACING_UP
+ jr .next
+.checkIfLeft
+ bit PLAYER_DIR_BIT_LEFT, a
+ jr z, .checkIfRight
+ ld a, SPRITE_FACING_LEFT
+ jr .next
+.checkIfRight
+ bit PLAYER_DIR_BIT_RIGHT, a
+ jr z, .notMoving
+ ld a, SPRITE_FACING_RIGHT
+ jr .next
+.notMoving
+; zero the animation counters
xor a
ld [wSpriteStateData1 + 7], a
ld [wSpriteStateData1 + 8], a
- jr .asm_4eab
-.asm_4e86
- ld [wSpriteStateData1 + 9], a
+ jr .calcImageIndex
+.next
+ ld [wSpriteStateData1 + 9], a ; facing direction
ld a, [wFontLoaded]
bit 0, a
- jr nz, .asm_4e7d
-.asm_4e90
+ jr nz, .notMoving
+.moving
ld a, [wd736]
- bit 7, a
- jr nz, .asm_4eb6
+ bit 7, a ; is the player sprite spinning due to a spin tile?
+ jr nz, .skipSpriteAnim
ld a, [H_CURRENTSPRITEOFFSET]
add $7
ld l, a
ld a, [hl]
inc a
ld [hl], a
- cp $4
- jr nz, .asm_4eab
+ cp 4
+ jr nz, .calcImageIndex
xor a
ld [hl], a
inc hl
@@ -74,28 +76,32 @@ UpdatePlayerSprite: ; 4e31 (1:4e31)
inc a
and $3
ld [hl], a
-.asm_4eab
+.calcImageIndex
ld a, [wSpriteStateData1 + 8]
ld b, a
ld a, [wSpriteStateData1 + 9]
add b
ld [wSpriteStateData1 + 2], a
-.asm_4eb6
- ld a, [$ff93]
+.skipSpriteAnim
+; If the player is standing on a grass tile, make the player's sprite have
+; lower priority than the background so that it's partially obscured by the
+; grass. Only the lower half of the sprite is permitted to have the priority
+; bit set by later logic.
+ ld a, [hTilePlayerStandingOn]
ld c, a
- ld a, [W_GRASSTILE]
+ ld a, [wGrassTile]
cp c
ld a, $0
- jr nz, .asm_4ec3
+ jr nz, .next2
ld a, $80
-.asm_4ec3
- ld [wSpriteStateData2 + $07], a
+.next2
+ ld [wSpriteStateData2 + 7], a
ret
-Func_4ec7: ; 4ec7 (1:4ec7)
+UnusedReadSpriteDataFunction:
push bc
push af
- ld a, [$ffda]
+ ld a, [H_CURRENTSPRITEOFFSET]
ld c, a
pop af
add c
@@ -103,12 +109,12 @@ Func_4ec7: ; 4ec7 (1:4ec7)
pop bc
ret
-Func_4ed1: ; 4ed1 (1:4ed1)
+UpdateNPCSprite:
ld a, [H_CURRENTSPRITEOFFSET]
swap a
dec a
add a
- ld hl, W_MAPSPRITEDATA ; wd4e4
+ ld hl, wMapSpriteData
add l
ld l, a
ld a, [hl] ; read movement byte 2
@@ -127,8 +133,8 @@ Func_4ed1: ; 4ed1 (1:4ed1)
ld l, a
inc l
ld a, [hl] ; c1x1
- bit 7, a
- jp nz, InitializeSpriteFacingDirection ; c1x1 >= $80
+ bit 7, a ; is the face player flag set?
+ jp nz, MakeNPCFacePlayer
ld b, a
ld a, [wFontLoaded]
bit 0, a
@@ -138,7 +144,7 @@ Func_4ed1: ; 4ed1 (1:4ed1)
jp z, UpdateSpriteMovementDelay ; c1x1 == 2
cp $3
jp z, UpdateSpriteInWalkingAnimation ; c1x1 == 3
- ld a, [wWalkCounter] ; wcfc5
+ ld a, [wWalkCounter]
and a
ret nz ; don't do anything yet if player is currently moving (redundant, already tested in CheckSpriteAvailability)
call InitializeSpriteScreenPosition
@@ -148,40 +154,43 @@ Func_4ed1: ; 4ed1 (1:4ed1)
ld l, a
ld a, [hl] ; c2x6: movement byte 1
inc a
- jr z, .asm_4f59 ; value $FF
+ jr z, .randomMovement ; value $FF
inc a
- jr z, .asm_4f59 ; value $FE
+ jr z, .randomMovement ; value $FE
+; scripted movement
dec a
- ld [hl], a ; (temporarily) increment movement byte 1
+ ld [hl], a ; increment movement byte 1 (movement data index)
dec a
push hl
- ld hl, wcf0f
- dec [hl] ; decrement wcf0f
+ ld hl, wNPCNumScriptedSteps
+ dec [hl] ; decrement wNPCNumScriptedSteps
pop hl
- ld de, wcc5b
- call LoadDEPlusA ; a = [wcc5b + movement byte 1]
+ ld de, wNPCMovementDirections
+ call LoadDEPlusA ; a = [wNPCMovementDirections + movement byte 1]
cp $e0
jp z, ChangeFacingDirection
- cp $ff
- jr nz, .asm_4f4b
- ld [hl], a ; reset movement byte 1 to initial value
+ cp STAY
+ jr nz, .next
+; reached end of wNPCMovementDirections list
+ ld [hl], a ; store $ff in movement byte 1, disabling scripted movement
ld hl, wd730
res 0, [hl]
xor a
ld [wSimulatedJoypadStatesIndex], a
ld [wWastedByteCD3A], a
ret
-.asm_4f4b
- cp $fe
- jr nz, .asm_4f5f
+.next
+ cp WALK
+ jr nz, .determineDirection
+; current NPC movement data is $fe. this seems buggy
ld [hl], $1 ; set movement byte 1 to $1
- ld de, wcc5b
- call LoadDEPlusA ; a = [wcc5b + $fe] (?)
- jr .asm_4f5f
-.asm_4f59
- call getTileSpriteStandsOn
+ ld de, wNPCMovementDirections
+ call LoadDEPlusA ; a = [wNPCMovementDirections + $fe] (?)
+ jr .determineDirection
+.randomMovement
+ call GetTileSpriteStandsOn
call Random
-.asm_4f5f
+.determineDirection
ld b, a
ld a, [wCurSpriteMovement2]
cp $d0
@@ -199,11 +208,10 @@ Func_4ed1: ; 4ed1 (1:4ed1)
cp $2
jr z, .moveLeft ; movement byte 2 = $2 only allows left or right
.moveDown
- ld de, 2*20
+ ld de, 2*SCREEN_WIDTH
add hl, de ; move tile pointer two rows down
- ld de, $100
-
- ld bc, $400
+ lb de, 1, 0
+ lb bc, 4, SPRITE_FACING_DOWN
jr TryWalking
.notDown
cp $80 ; $40 <= a < $80: up (or right)
@@ -212,10 +220,10 @@ Func_4ed1: ; 4ed1 (1:4ed1)
cp $2
jr z, .moveRight ; movement byte 2 = $2 only allows left or right
.moveUp
- ld de, -2*20 ; $ffd8
+ ld de, -2*SCREEN_WIDTH
add hl, de ; move tile pointer two rows up
- ld de, $ff00
- ld bc, $804
+ lb de, -1, 0
+ lb bc, 8, SPRITE_FACING_UP
jr TryWalking
.notUp
cp $c0 ; $80 <= a < $c0: left (or up)
@@ -226,8 +234,8 @@ Func_4ed1: ; 4ed1 (1:4ed1)
.moveLeft
dec hl
dec hl ; move tile pointer two columns left
- ld de, $ff
- ld bc, $208
+ lb de, 0, -1
+ lb bc, 2, SPRITE_FACING_LEFT
jr TryWalking
.notLeft ; $c0 <= a: right (or down)
ld a, [wCurSpriteMovement2]
@@ -236,12 +244,12 @@ Func_4ed1: ; 4ed1 (1:4ed1)
.moveRight
inc hl
inc hl ; move tile pointer two columns right
- ld de, $1
- ld bc, $10c
+ lb de, 0, 1
+ lb bc, 1, SPRITE_FACING_RIGHT
jr TryWalking
; changes facing direction by zeroing the movement delta and calling TryWalking
-ChangeFacingDirection: ; 4fc8 (1:4fc8)
+ChangeFacingDirection:
ld de, $0
; fall through
@@ -249,9 +257,9 @@ ChangeFacingDirection: ; 4fc8 (1:4fc8)
; c: new facing direction (0,4,8 or $c)
; d: Y movement delta (-1, 0 or 1)
; e: X movement delta (-1, 0 or 1)
-; hl: pointer to tile the sprite would wlak onto
+; hl: pointer to tile the sprite would walk onto
; set carry on failure, clears carry on success
-TryWalking: ; 4fcb (1:4fcb)
+TryWalking:
push hl
ld h, $c1
ld a, [H_CURRENTSPRITEOFFSET]
@@ -290,7 +298,7 @@ TryWalking: ; 4fcb (1:4fcb)
jp UpdateSpriteImage
; update the walking animation parameters for a sprite that is currently walking
-UpdateSpriteInWalkingAnimation: ; 4ffe (1:4ffe)
+UpdateSpriteInWalkingAnimation:
ld a, [H_CURRENTSPRITEOFFSET]
add $7
ld l, a
@@ -363,7 +371,7 @@ UpdateSpriteInWalkingAnimation: ; 4ffe (1:4ffe)
ret
; update delay value (c2x8) for sprites in the delayed state (c1x1)
-UpdateSpriteMovementDelay: ; 5057 (1:5057)
+UpdateSpriteMovementDelay:
ld h, $c2
ld a, [H_CURRENTSPRITEOFFSET]
add $6
@@ -384,36 +392,40 @@ UpdateSpriteMovementDelay: ; 5057 (1:5057)
inc a
ld l, a
ld [hl], $1 ; c1x1 = 1 (mark as ready to move)
-notYetMoving: ; 5073 (1:5073)
- ld h, $c1
+notYetMoving:
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $8
ld l, a
ld [hl], $0 ; c1x8 = 0 (walk animation frame)
jp UpdateSpriteImage
-InitializeSpriteFacingDirection: ; 507f (1:507f)
+MakeNPCFacePlayer:
+; Make an NPC face the player if the player has spoken to him or her.
+
+; Check if the behaviour of the NPC facing the player when spoken to is
+; disabled. This is only done when rubbing the S.S. Anne captain's back.
ld a, [wd72d]
bit 5, a
jr nz, notYetMoving
res 7, [hl]
- ld a, [wd52a]
- bit 3, a
+ ld a, [wPlayerDirection]
+ bit PLAYER_DIR_BIT_UP, a
jr z, .notFacingDown
- ld c, $0 ; make sprite face down
+ ld c, SPRITE_FACING_DOWN
jr .facingDirectionDetermined
.notFacingDown
- bit 2, a
+ bit PLAYER_DIR_BIT_DOWN, a
jr z, .notFacingUp
- ld c, $4 ; make sprite face up
+ ld c, SPRITE_FACING_UP
jr .facingDirectionDetermined
.notFacingUp
- bit 1, a
+ bit PLAYER_DIR_BIT_LEFT, a
jr z, .notFacingRight
- ld c, $c ; make sprite face right
+ ld c, SPRITE_FACING_RIGHT
jr .facingDirectionDetermined
.notFacingRight
- ld c, $8 ; make sprite face left
+ ld c, SPRITE_FACING_LEFT
.facingDirectionDetermined
ld a, [H_CURRENTSPRITEOFFSET]
add $9
@@ -421,7 +433,7 @@ InitializeSpriteFacingDirection: ; 507f (1:507f)
ld [hl], c ; c1x9: set facing direction
jr notYetMoving
-InitializeSpriteStatus: ; 50ad (1:50ad)
+InitializeSpriteStatus:
ld [hl], $1 ; $c1x1: set movement status to ready
inc l
ld [hl], $ff ; $c1x2: set sprite image to $ff (invisible/off screen)
@@ -435,12 +447,12 @@ InitializeSpriteStatus: ; 50ad (1:50ad)
ret
; calculates the spprite's scrren position form its map position and the player position
-InitializeSpriteScreenPosition: ; 50bd (1:50bd)
- ld h, $c2
+InitializeSpriteScreenPosition:
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $4
ld l, a
- ld a, [W_YCOORD] ; wd361
+ ld a, [wYCoord]
ld b, a
ld a, [hl] ; c2x4 (Y position + 4)
sub b ; relative to player position
@@ -449,7 +461,7 @@ InitializeSpriteScreenPosition: ; 50bd (1:50bd)
dec h
ld [hli], a ; c1x4 (screen Y position)
inc h
- ld a, [W_XCOORD] ; wd362
+ ld a, [wXCoord]
ld b, a
ld a, [hli] ; c2x6 (X position + 4)
sub b ; relative to player position
@@ -459,23 +471,23 @@ InitializeSpriteScreenPosition: ; 50bd (1:50bd)
ret
; tests if sprite is off screen or otherwise unable to do anything
-CheckSpriteAvailability: ; 50dc (1:50dc)
+CheckSpriteAvailability:
predef IsObjectHidden
ld a, [$ffe5]
and a
jp nz, .spriteInvisible
- ld h, $c2
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $6
ld l, a
ld a, [hl] ; c2x6: movement byte 1
cp $fe
- jr c, .skipXVisibilityTest ; movement byte 1 < $fe
+ jr c, .skipXVisibilityTest ; movement byte 1 < $fe (i.e. the sprite's movement is scripted)
ld a, [H_CURRENTSPRITEOFFSET]
add $4
ld l, a
ld b, [hl] ; c2x4: Y pos (+4)
- ld a, [W_YCOORD] ; wd361
+ ld a, [wYCoord]
cp b
jr z, .skipYVisibilityTest
jr nc, .spriteInvisible ; above screen region
@@ -485,7 +497,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc)
.skipYVisibilityTest
inc l
ld b, [hl] ; c2x5: X pos (+4)
- ld a, [W_XCOORD] ; wd362
+ ld a, [wXCoord]
cp b
jr z, .skipXVisibilityTest
jr nc, .spriteInvisible ; left of screen region
@@ -495,7 +507,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc)
.skipXVisibilityTest
; make the sprite invisible if a text box is in front of it
; $5F is the maximum number for map tiles
- call getTileSpriteStandsOn
+ call GetTileSpriteStandsOn
ld d, $60
ld a, [hli]
cp d
@@ -503,7 +515,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc)
ld a, [hld]
cp d
jr nc, .spriteInvisible ; standing on tile with ID >=$60 (bottom right tile)
- ld bc, -20 ; $ffec
+ ld bc, -20
add hl, bc ; go back one row of tiles
ld a, [hli]
cp d
@@ -512,7 +524,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc)
cp d
jr c, .spriteVisible ; standing on tile with ID >=$60 (top right tile)
.spriteInvisible
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $2
ld l, a
@@ -521,7 +533,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc)
jr .done
.spriteVisible
ld c, a
- ld a, [wWalkCounter] ; wcfc5
+ ld a, [wWalkCounter]
and a
jr nz, .done ; if player is currently walking, we're done
call UpdateSpriteImage
@@ -529,7 +541,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc)
ld a, [H_CURRENTSPRITEOFFSET]
add $7
ld l, a
- ld a, [W_GRASSTILE]
+ ld a, [wGrassTile]
cp c
ld a, $0
jr nz, .notInGrass
@@ -540,7 +552,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc)
.done
ret
-UpdateSpriteImage: ; 5157 (1:5157)
+UpdateSpriteImage:
ld h, $c1
ld a, [H_CURRENTSPRITEOFFSET]
add $8
@@ -565,20 +577,21 @@ UpdateSpriteImage: ; 5157 (1:5157)
; d: Y movement delta (-1, 0 or 1)
; e: X movement delta (-1, 0 or 1)
; set carry on failure, clears carry on success
-CanWalkOntoTile: ; 516e (1:516e)
- ld h, $c2
+CanWalkOntoTile:
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $6
ld l, a
ld a, [hl] ; c2x6 (movement byte 1)
cp $fe
- jr nc, .canMove ; values $fe and $ff
+ jr nc, .notScripted ; values $fe and $ff
+; always allow walking if the movement is scripted
and a
ret
-.canMove
- ld a, [W_TILESETCOLLISIONPTR]
+.notScripted
+ ld a, [wTilesetCollisionPtr]
ld l, a
- ld a, [W_TILESETCOLLISIONPTR+1]
+ ld a, [wTilesetCollisionPtr+1]
ld h, a
.tilePassableLoop
ld a, [hli]
@@ -593,7 +606,7 @@ CanWalkOntoTile: ; 516e (1:516e)
ld a, [hl] ; $c2x6 (movement byte 1)
inc a
jr z, .impassable ; if $ff, no movement allowed (however, changing direction is)
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $4
ld l, a
@@ -612,14 +625,14 @@ CanWalkOntoTile: ; 516e (1:516e)
call DetectCollisionBetweenSprites
pop bc
pop de
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $c
ld l, a
ld a, [hl] ; c1xc (directions in which sprite collision would occur)
and b ; check against chosen direction (1,2,4 or 8)
jr nz, .impassable ; collision between sprites, don't go there
- ld h, $c2
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $2
ld l, a
@@ -675,8 +688,8 @@ CanWalkOntoTile: ; 516e (1:516e)
; calculates the tile pointer pointing to the tile the current sprite stancs on
; this is always the lower left tile of the 2x2 tile blocks all sprites are snapped to
; hl: output pointer
-getTileSpriteStandsOn: ; 5207 (1:5207)
- ld h, $c1
+GetTileSpriteStandsOn:
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $4
ld l, a
@@ -690,11 +703,11 @@ getTileSpriteStandsOn: ; 5207 (1:5207)
ld a, [hl] ; c1x6: screen Y position
srl a
srl a
- srl a ; screen X tile
- add $14 ; screen X tile + 20
+ srl a ; screen X tile
+ add SCREEN_WIDTH ; screen X tile + 20
ld d, $0
ld e, a
- ld hl, wTileMap
+ coord hl, 0, 0
add hl, bc
add hl, bc
add hl, bc
@@ -704,7 +717,7 @@ getTileSpriteStandsOn: ; 5207 (1:5207)
ret
; loads [de+a] into a
-LoadDEPlusA: ; 522f (1:522f)
+LoadDEPlusA:
add e
ld e, a
jr nc, .noCarry
@@ -713,53 +726,58 @@ LoadDEPlusA: ; 522f (1:522f)
ld a, [de]
ret
-Func_5236: ; 5236 (1:5236)
+DoScriptedNPCMovement:
+; This is an alternative method of scripting an NPC's movement and is only used
+; a few times in the game. It is used when the NPC and player must walk together
+; in sync, such as when the player is following the NPC somewhere. An NPC can't
+; be moved in sync with the player using the other method.
ld a, [wd730]
bit 7, a
ret z
ld hl, wd72e
bit 7, [hl]
set 7, [hl]
- jp z, Func_52a6
+ jp z, InitScriptedNPCMovement
ld hl, wNPCMovementDirections2
ld a, [wNPCMovementDirections2Index]
add l
ld l, a
- jr nc, .asm_5251
+ jr nc, .noCarry
inc h
-.asm_5251
+.noCarry
ld a, [hl]
- cp $40
- jr nz, .asm_525f
- call Func_52b2
- ld c, $4
- ld a, $fe
- jr .asm_5289
-.asm_525f
- cp $0
- jr nz, .asm_526c
- call Func_52b2
- ld c, $0
- ld a, $2
- jr .asm_5289
-.asm_526c
- cp $80
- jr nz, .asm_5279
- call Func_52b7
- ld c, $8
- ld a, $fe
- jr .asm_5289
-.asm_5279
- cp $c0
- jr nz, .asm_5286
- call Func_52b7
- ld c, $c
- ld a, $2
- jr .asm_5289
-.asm_5286
+; check if moving up
+ cp NPC_MOVEMENT_UP
+ jr nz, .checkIfMovingDown
+ call GetSpriteScreenYPointer
+ ld c, SPRITE_FACING_UP
+ ld a, -2
+ jr .move
+.checkIfMovingDown
+ cp NPC_MOVEMENT_DOWN
+ jr nz, .checkIfMovingLeft
+ call GetSpriteScreenYPointer
+ ld c, SPRITE_FACING_DOWN
+ ld a, 2
+ jr .move
+.checkIfMovingLeft
+ cp NPC_MOVEMENT_LEFT
+ jr nz, .checkIfMovingRight
+ call GetSpriteScreenXPointer
+ ld c, SPRITE_FACING_LEFT
+ ld a, -2
+ jr .move
+.checkIfMovingRight
+ cp NPC_MOVEMENT_RIGHT
+ jr nz, .noMatch
+ call GetSpriteScreenXPointer
+ ld c, SPRITE_FACING_RIGHT
+ ld a, 2
+ jr .move
+.noMatch
cp $ff
ret
-.asm_5289
+.move
ld b, a
ld a, [hl]
add b
@@ -768,33 +786,34 @@ Func_5236: ; 5236 (1:5236)
add $9
ld l, a
ld a, c
- ld [hl], a
- call Func_52c3
- ld hl, wcf18
+ ld [hl], a ; facing direction
+ call AnimScriptedNPCMovement
+ ld hl, wScriptedNPCWalkCounter
dec [hl]
ret nz
- ld a, $8
- ld [wcf18], a
+ ld a, 8
+ ld [wScriptedNPCWalkCounter], a
ld hl, wNPCMovementDirections2Index
inc [hl]
ret
-Func_52a6: ; 52a6 (1:52a6)
+InitScriptedNPCMovement:
xor a
ld [wNPCMovementDirections2Index], a
- ld a, $8
- ld [wcf18], a
- jp Func_52c3
+ ld a, 8
+ ld [wScriptedNPCWalkCounter], a
+ jp AnimScriptedNPCMovement
-Func_52b2: ; 52b2 (1:52b2)
+GetSpriteScreenYPointer:
ld a, $4
ld b, a
- jr asm_52ba
+ jr GetSpriteScreenXYPointerCommon
-Func_52b7: ; 52b7 (1:52b7)
+GetSpriteScreenXPointer:
ld a, $6
ld b, a
-asm_52ba: ; 52ba (1:52ba)
+
+GetSpriteScreenXYPointerCommon:
ld hl, wSpriteStateData1
ld a, [H_CURRENTSPRITEOFFSET]
add l
@@ -802,12 +821,12 @@ asm_52ba: ; 52ba (1:52ba)
ld l, a
ret
-Func_52c3: ; 52c3 (1:52c3)
+AnimScriptedNPCMovement:
ld hl, wSpriteStateData2
ld a, [H_CURRENTSPRITEOFFSET]
add $e
ld l, a
- ld a, [hl]
+ ld a, [hl] ; VRAM slot
dec a
swap a
ld b, a
@@ -815,47 +834,47 @@ Func_52c3: ; 52c3 (1:52c3)
ld a, [H_CURRENTSPRITEOFFSET]
add $9
ld l, a
- ld a, [hl]
- cp $0
- jr z, .asm_52ea
- cp $4
- jr z, .asm_52ea
- cp $8
- jr z, .asm_52ea
- cp $c
- jr z, .asm_52ea
+ ld a, [hl] ; facing direction
+ cp SPRITE_FACING_DOWN
+ jr z, .anim
+ cp SPRITE_FACING_UP
+ jr z, .anim
+ cp SPRITE_FACING_LEFT
+ jr z, .anim
+ cp SPRITE_FACING_RIGHT
+ jr z, .anim
ret
-.asm_52ea
+.anim
add b
ld b, a
- ld [$ffe9], a
- call Func_5301
+ ld [hSpriteVRAMSlotAndFacing], a
+ call AdvanceScriptedNPCAnimFrameCounter
ld hl, wSpriteStateData1
ld a, [H_CURRENTSPRITEOFFSET]
add $2
ld l, a
- ld a, [$ffe9]
+ ld a, [hSpriteVRAMSlotAndFacing]
ld b, a
- ld a, [$ffea]
+ ld a, [hSpriteAnimFrameCounter]
add b
ld [hl], a
ret
-Func_5301: ; 5301 (1:5301)
+AdvanceScriptedNPCAnimFrameCounter:
ld a, [H_CURRENTSPRITEOFFSET]
add $7
ld l, a
- ld a, [hl]
+ ld a, [hl] ; intra-animation frame counter
inc a
ld [hl], a
- cp $4
+ cp 4
ret nz
xor a
- ld [hl], a
+ ld [hl], a ; reset intra-animation frame counter
inc l
- ld a, [hl]
+ ld a, [hl] ; animation frame counter
inc a
and $3
ld [hl], a
- ld [$ffea], a
+ ld [hSpriteAnimFrameCounter], a
ret
diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm
index 84e39853..98d1b7a7 100755
--- a/engine/overworld/npc_movement.asm
+++ b/engine/overworld/npc_movement.asm
@@ -1,4 +1,4 @@
-PlayerStepOutFromDoor: ; 1a3e0 (6:63e0)
+PlayerStepOutFromDoor:
ld hl, wd730
res 1, [hl]
call IsPlayerStandingOnDoorTile
@@ -27,7 +27,7 @@ PlayerStepOutFromDoor: ; 1a3e0 (6:63e0)
res 7, [hl]
ret
-_EndNPCMovementScript: ; 1a41d (6:641d)
+_EndNPCMovementScript:
ld hl, wd730
res 7, [hl]
ld hl, wd72e
@@ -44,60 +44,66 @@ _EndNPCMovementScript: ; 1a41d (6:641d)
ld [wSimulatedJoypadStatesEnd], a
ret
-ProfOakMovementScriptPointerTable: ; 1a442 (6:6442)
- dw Func_1a44c
- dw Func_1a485
- dw Func_1a4a1
- dw Func_1a4a6
- dw Func_1a4f4
+PalletMovementScriptPointerTable:
+ dw PalletMovementScript_OakMoveLeft
+ dw PalletMovementScript_PlayerMoveLeft
+ dw PalletMovementScript_WaitAndWalkToLab
+ dw PalletMovementScript_WalkToLab
+ dw PalletMovementScript_Done
-Func_1a44c: ; 1a44c (6:644c)
- ld a, [W_XCOORD] ; wd362
+PalletMovementScript_OakMoveLeft:
+ ld a, [wXCoord]
sub $a
- ld [wcca1], a
- jr z, .asm_1a475
- ld b, $0
+ ld [wNumStepsToTake], a
+ jr z, .playerOnLeftTile
+; The player is on the right tile of the northern path out of Pallet Town and
+; Prof. Oak is below.
+; Make Prof. Oak step to the left.
+ ld b, 0
ld c, a
ld hl, wNPCMovementDirections2
- ld a, $80
+ ld a, NPC_MOVEMENT_LEFT
call FillMemory
ld [hl], $ff
ld a, [wSpriteIndex]
- ld [H_DOWNARROWBLINKCNT2], a ; $ff8c
+ ld [H_SPRITEINDEX], a
ld de, wNPCMovementDirections2
call MoveSprite
ld a, $1
ld [wNPCMovementScriptFunctionNum], a
- jr .asm_1a47a
-.asm_1a475
+ jr .done
+; The player is on the left tile of the northern path out of Pallet Town and
+; Prof. Oak is below.
+; Prof. Oak is already where he needs to be.
+.playerOnLeftTile
ld a, $3
ld [wNPCMovementScriptFunctionNum], a
-.asm_1a47a
- ld hl, W_FLAGS_D733
+.done
+ ld hl, wFlags_D733
set 1, [hl]
ld a, $fc
ld [wJoyIgnore], a
ret
-Func_1a485: ; 1a485 (6:6485)
+PalletMovementScript_PlayerMoveLeft:
ld a, [wd730]
- bit 0, a
- ret nz
- ld a, [wcca1]
+ bit 0, a ; is an NPC being moved by a script?
+ ret nz ; return if Oak is still moving
+ ld a, [wNumStepsToTake]
ld [wSimulatedJoypadStatesIndex], a
- ld [$ff95], a
+ ld [hNPCMovementDirections2Index], a
predef ConvertNPCMovementDirectionsToJoypadMasks
call StartSimulatingJoypadStates
ld a, $2
ld [wNPCMovementScriptFunctionNum], a
ret
-Func_1a4a1: ; 1a4a1 (6:64a1)
+PalletMovementScript_WaitAndWalkToLab:
ld a, [wSimulatedJoypadStatesIndex]
- and a
+ and a ; is the player done moving left yet?
ret nz
-Func_1a4a6: ; 1a4a6 (6:64a6)
+PalletMovementScript_WalkToLab:
xor a
ld [wOverrideSimulatedJoypadStatesMask], a
ld a, [wSpriteIndex]
@@ -121,16 +127,16 @@ Func_1a4a6: ; 1a4a6 (6:64a6)
ld [wNPCMovementScriptFunctionNum], a
ret
-RLEList_ProfOakWalkToLab: ; 1a4dc (6:64dc)
- db $00, $05
- db $80, $01
- db $00, $05
- db $C0, $03
- db $40, $01
- db $E0, $01
+RLEList_ProfOakWalkToLab:
+ db NPC_MOVEMENT_DOWN, $05
+ db NPC_MOVEMENT_LEFT, $01
+ db NPC_MOVEMENT_DOWN, $05
+ db NPC_MOVEMENT_RIGHT, $03
+ db NPC_MOVEMENT_UP, $01
+ db $E0, $01 ; stand still
db $FF
-RLEList_PlayerWalkToLab: ; 1a4e9 (6:64e9)
+RLEList_PlayerWalkToLab:
db D_UP, $02
db D_RIGHT, $03
db D_DOWN, $05
@@ -138,12 +144,12 @@ RLEList_PlayerWalkToLab: ; 1a4e9 (6:64e9)
db D_DOWN, $06
db $FF
-Func_1a4f4: ; 1a4f4 (6:64f4)
+PalletMovementScript_Done:
ld a, [wSimulatedJoypadStatesIndex]
and a
ret nz
ld a, $0
- ld [wcc4d], a
+ ld [wMissableObjectIndex], a
predef HideObject
ld hl, wd730
res 7, [hl]
@@ -151,16 +157,16 @@ Func_1a4f4: ; 1a4f4 (6:64f4)
res 7, [hl]
jp EndNPCMovementScript
-PewterMuseumGuyMovementScriptPointerTable: ; 1a510 (6:6510)
- dw Func_1a514
- dw PewterMovementScriptDone
+PewterMuseumGuyMovementScriptPointerTable:
+ dw PewterMovementScript_WalkToMuseum
+ dw PewterMovementScript_Done
-Func_1a514: ; 1a514 (6:6514)
+PewterMovementScript_WalkToMuseum:
ld a, BANK(Music_MuseumGuy)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, [wSpriteIndex]
swap a
@@ -172,7 +178,7 @@ Func_1a514: ; 1a514 (6:6514)
dec a
ld [wSimulatedJoypadStatesIndex], a
xor a
- ld [wd12f], a
+ ld [wWhichPewterGuy], a
predef PewterGuys
ld hl, wNPCMovementDirections2
ld de, RLEList_PewterMuseumGuy
@@ -183,21 +189,21 @@ Func_1a514: ; 1a514 (6:6514)
ld [wNPCMovementScriptFunctionNum], a
ret
-RLEList_PewterMuseumPlayer: ; 1a559 (6:6559)
+RLEList_PewterMuseumPlayer:
db 0, $01
db D_UP, $03
db D_LEFT, $0D
db D_UP, $06
db $FF
-RLEList_PewterMuseumGuy: ; 1a562 (6:6562)
- db $40, $06
- db $80, $0D
- db $40, $03
- db $80, $01
+RLEList_PewterMuseumGuy:
+ db NPC_MOVEMENT_UP, $06
+ db NPC_MOVEMENT_LEFT, $0D
+ db NPC_MOVEMENT_UP, $03
+ db NPC_MOVEMENT_LEFT, $01
db $FF
-PewterMovementScriptDone: ; 1a56b (6:656b)
+PewterMovementScript_Done:
ld a, [wSimulatedJoypadStatesIndex]
and a
ret nz
@@ -207,16 +213,16 @@ PewterMovementScriptDone: ; 1a56b (6:656b)
res 7, [hl]
jp EndNPCMovementScript
-PewterGymGuyMovementScriptPointerTable: ; 1a57d (6:657d)
- dw Func_1a581
- dw PewterMovementScriptDone
+PewterGymGuyMovementScriptPointerTable:
+ dw PewterMovementScript_WalkToGym
+ dw PewterMovementScript_Done
-Func_1a581: ; 1a581 (6:6581)
+PewterMovementScript_WalkToGym:
ld a, BANK(Music_MuseumGuy)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
ld a, [wSpriteIndex]
swap a
@@ -228,8 +234,8 @@ Func_1a581: ; 1a581 (6:6581)
call DecodeRLEList
dec a
ld [wSimulatedJoypadStatesIndex], a
- ld a, $1
- ld [wd12f], a
+ ld a, 1
+ ld [wWhichPewterGuy], a
predef PewterGuys
ld hl, wNPCMovementDirections2
ld de, RLEList_PewterGymGuy
@@ -242,7 +248,7 @@ Func_1a581: ; 1a581 (6:6581)
ld [wNPCMovementScriptFunctionNum], a
ret
-RLEList_PewterGymPlayer: ; 1a5cd (6:65cd)
+RLEList_PewterGymPlayer:
db 0, $01
db D_RIGHT, $02
db D_DOWN, $05
@@ -251,17 +257,17 @@ RLEList_PewterGymPlayer: ; 1a5cd (6:65cd)
db D_LEFT, $0F
db $FF
-RLEList_PewterGymGuy: ; 1a5da (6:65da)
- db $00, $02
- db $80, $0F
- db $40, $05
- db $80, $0B
- db $00, $05
- db $C0, $03
+RLEList_PewterGymGuy:
+ db NPC_MOVEMENT_DOWN, $02
+ db NPC_MOVEMENT_LEFT, $0F
+ db NPC_MOVEMENT_UP, $05
+ db NPC_MOVEMENT_LEFT, $0B
+ db NPC_MOVEMENT_DOWN, $05
+ db NPC_MOVEMENT_RIGHT, $03
db $FF
-FreezeEnemyTrainerSprite: ; 1a5e7 (6:65e7)
- ld a, [W_CURMAP]
+FreezeEnemyTrainerSprite:
+ ld a, [wCurMap]
cp POKEMONTOWER_7
ret z ; the Rockets on Pokemon Tower 7F leave after battling, so don't freeze them
ld hl, RivalIDs
@@ -279,8 +285,8 @@ FreezeEnemyTrainerSprite: ; 1a5e7 (6:65e7)
ld [H_SPRITEINDEX], a
jp SetSpriteMovementBytesToFF
-RivalIDs: ; 1a605 (6:6605)
- db SONY1 + $c8
- db SONY2 + $c8
- db SONY3 + $c8
+RivalIDs:
+ db OPP_SONY1
+ db OPP_SONY2
+ db OPP_SONY3
db $ff
diff --git a/engine/overworld/oaks_aide.asm b/engine/overworld/oaks_aide.asm
index 68135287..f5068fda 100755
--- a/engine/overworld/oaks_aide.asm
+++ b/engine/overworld/oaks_aide.asm
@@ -1,71 +1,71 @@
-OaksAideScript ; 0x59035
+OaksAideScript:
ld hl, OaksAideHiText
call PrintText
call YesNoChoice
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_59086 ; 0x59042 $42
+ jr nz, .choseNo
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e]
- ld [$ffdd], a
+ ld a, [wNumSetBits]
+ ld [hOaksAideNumMonsOwned], a
ld b, a
- ld a, [$ffdb]
+ ld a, [hOaksAideRequirement]
cp b
- jr z, .asm_59059 ; 0x59055 $2
- jr nc, .asm_5907c ; 0x59057 $23
-.asm_59059
+ jr z, .giveItem
+ jr nc, .notEnoughOwnedMons
+.giveItem
ld hl, OaksAideHereYouGoText
call PrintText
- ld a, [$ffdc]
+ ld a, [hOaksAideRewardItem]
ld b, a
ld c, 1
call GiveItem
- jr nc, .BagFull
+ jr nc, .bagFull
ld hl, OaksAideGotItemText
call PrintText
ld a, $1
- jr .asm_5908e ; 0x59071 $1b
-.BagFull
+ jr .done
+.bagFull
ld hl, OaksAideNoRoomText
call PrintText
xor a
- jr .asm_5908e ; 0x5907a $12
-.asm_5907c
+ jr .done
+.notEnoughOwnedMons
ld hl, OaksAideUhOhText
call PrintText
ld a, $80
- jr .asm_5908e ; 0x59084 $8
-.asm_59086
+ jr .done
+.choseNo
ld hl, OaksAideComeBackText
call PrintText
ld a, $ff
-.asm_5908e
- ld [$ffdb], a
+.done
+ ld [hOaksAideResult], a
ret
-OaksAideHiText: ; 59091 (16:5091)
+OaksAideHiText:
TX_FAR _OaksAideHiText
db "@"
-OaksAideUhOhText: ; 59096 (16:5096)
+OaksAideUhOhText:
TX_FAR _OaksAideUhOhText
db "@"
-OaksAideComeBackText: ; 5909b (16:509b)
+OaksAideComeBackText:
TX_FAR _OaksAideComeBackText
db "@"
-OaksAideHereYouGoText: ; 590a0 (16:50a0)
+OaksAideHereYouGoText:
TX_FAR _OaksAideHereYouGoText
db "@"
-OaksAideGotItemText: ; 590a5 (16:50a5)
+OaksAideGotItemText:
TX_FAR _OaksAideGotItemText
- db $0b
+ TX_SFX_ITEM_1
db "@"
-OaksAideNoRoomText: ; 590ab (16:50ab)
+OaksAideNoRoomText:
TX_FAR _OaksAideNoRoomText
db "@"
diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm
index b4247257..2c2a3dff 100644
--- a/engine/overworld/oam.asm
+++ b/engine/overworld/oam.asm
@@ -4,25 +4,26 @@ PrepareOAMData:
ld a, [wUpdateSpritesEnabled]
dec a
- jr z, .asm_4b1e
+ jr z, .updateEnabled
- cp 0 - 1
+ cp -1
ret nz
ld [wUpdateSpritesEnabled], a
jp HideSprites
-.asm_4b1e
+.updateEnabled
xor a
- ld [$ff90], a
-.asm_4b21
- ld [$ff8f], a
+ ld [hOAMBufferOffset], a
+
+.spriteLoop
+ ld [hSpriteOffset2], a
ld d, wSpriteStateData1 / $100
- ld a, [$ff8f]
+ ld a, [hSpriteOffset2]
ld e, a
ld a, [de] ; c1x0
and a
- jp z, .asm_4bad
+ jp z, .nextSprite
inc e
inc e
@@ -31,21 +32,25 @@ PrepareOAMData:
cp $ff ; off-screen (don't draw)
jr nz, .visible
- call Func_4bd1
- jr .asm_4bad
+ call GetSpriteScreenXY
+ jr .nextSprite
.visible
- cp $a0
+ cp $a0 ; is the sprite unchanging like an item ball or boulder?
jr c, .usefacing
+
+; unchanging
and $f
- add $10
- jr .asm_4b48
+ add $10 ; skip to the second half of the table which doesn't account for facing direction
+ jr .next
.usefacing
and $f
-.asm_4b48
+
+.next
ld l, a
+; get sprite priority
push de
inc d
ld a, e
@@ -53,15 +58,15 @@ PrepareOAMData:
ld e, a
ld a, [de] ; c2x7
and $80
- ld [$ff94], a ; temp store sprite priority
+ ld [hSpritePriority], a ; temp store sprite priority
pop de
+; read the entry from the table
ld h, 0
ld bc, SpriteFacingAndAnimationTable
add hl, hl
add hl, hl
add hl, bc
-
ld a, [hli]
ld c, a
ld a, [hli]
@@ -70,24 +75,25 @@ PrepareOAMData:
ld h, [hl]
ld l, a
- call Func_4bd1
+ call GetSpriteScreenXY
- ld a, [$ff90]
+ ld a, [hOAMBufferOffset]
ld e, a
ld d, wOAMBuffer / $100
-.tile
- ld a, [$ff92] ; temp for sprite Y position
+
+.tileLoop
+ ld a, [hSpriteScreenY] ; temp for sprite Y position
add $10 ; Y=16 is top of screen (Y=0 is invisible)
add [hl] ; add Y offset from table
ld [de], a ; write new sprite OAM Y position
inc hl
- ld a, [$ff91] ; temp for sprite X position
+ ld a, [hSpriteScreenX] ; temp for sprite X position
add $8 ; X=8 is left of screen (X=0 is invisible)
add [hl] ; add X offset from table
inc e
ld [de], a ; write new sprite OAM X position
inc e
- ld a, [bc] ; read pattern number offset (accomodates orientation (offset 0,4 or 8) and animation (offset 0 or $80))
+ ld a, [bc] ; read pattern number offset (accommodates orientation (offset 0,4 or 8) and animation (offset 0 or $80))
inc bc
push bc
ld b, a
@@ -99,55 +105,60 @@ PrepareOAMData:
; Sprites $a and $b have one face (and therefore 4 tiles instead of 12).
; As a result, sprite $b's tile offset is less than normal.
cp $b
- jr nz, .offset
+ jr nz, .notFourTileSprite
ld a, $a * 12 + 4
- jr .gotoffset
+ jr .next2
-.offset
+.notFourTileSprite
; a *= 12
sla a
sla a
ld c, a
sla a
add c
-.gotoffset
- add b ; which frame
+
+.next2
+ add b ; add the tile offset from the table (based on frame and facing direction)
pop bc
ld [de], a ; tile id
inc hl
inc e
ld a, [hl]
- bit 1, a ; sprite priority
- jr z, .fg
- ld a, [$ff94] ; facing priority
+ bit 1, a ; is the tile allowed to set the sprite priority bit?
+ jr z, .skipPriority
+ ld a, [hSpritePriority]
or [hl]
-.fg
+.skipPriority
inc hl
ld [de], a
inc e
bit 0, a ; OAMFLAG_ENDOFDATA
- jr z, .tile
+ jr z, .tileLoop
ld a, e
- ld [$ff90], a
+ ld [hOAMBufferOffset], a
-.asm_4bad
- ld a, [$ff8f]
+.nextSprite
+ ld a, [hSpriteOffset2]
add $10
cp $100 % $100
- jp nz, .asm_4b21
+ jp nz, .spriteLoop
; Clear unused OAM.
- ld a, [$ff90]
+ ld a, [hOAMBufferOffset]
ld l, a
ld h, wOAMBuffer / $100
ld de, $4
ld b, $a0
ld a, [wd736]
- bit 6, a
+ bit 6, a ; jumping down ledge or fishing animation?
ld a, $a0
jr z, .clear
+
+; Don't clear the last 4 entries because they are used for the shadow in the
+; jumping down ledge animation and the rod in the fishing animation.
ld a, $90
+
.clear
cp l
ret z
@@ -155,24 +166,24 @@ PrepareOAMData:
add hl, de
jr .clear
-Func_4bd1: ; 4bd1 (1:4bd1)
+GetSpriteScreenXY:
inc e
inc e
ld a, [de] ; c1x4
- ld [$ff92], a
+ ld [hSpriteScreenY], a
inc e
inc e
ld a, [de] ; c1x6
- ld [$ff91], a
- ld a, $4
+ ld [hSpriteScreenX], a
+ ld a, 4
add e
ld e, a
- ld a, [$ff92]
- add $4
+ ld a, [hSpriteScreenY]
+ add 4
and $f0
ld [de], a ; c1xa (y)
inc e
- ld a, [$ff91]
+ ld a, [hSpriteScreenX]
and $f0
ld [de], a ; c1xb (x)
ret
diff --git a/engine/overworld/pewter_guys.asm b/engine/overworld/pewter_guys.asm
index eb6dd5ac..532fa4bf 100755
--- a/engine/overworld/pewter_guys.asm
+++ b/engine/overworld/pewter_guys.asm
@@ -1,4 +1,4 @@
-PewterGuys: ; 37ca1 (d:7ca1)
+PewterGuys:
ld hl, wSimulatedJoypadStatesEnd
ld a, [wSimulatedJoypadStatesIndex]
dec a ; this decrement causes it to overwrite the last byte before $FF in the list
@@ -9,7 +9,7 @@ PewterGuys: ; 37ca1 (d:7ca1)
ld d, h
ld e, l
ld hl, PointerTable_37ce6
- ld a, [wd12f]
+ ld a, [wWhichPewterGuy]
add a
ld b, 0
ld c, a
@@ -17,21 +17,21 @@ PewterGuys: ; 37ca1 (d:7ca1)
ld a, [hli]
ld h, [hl]
ld l, a
- ld a, [W_YCOORD]
+ ld a, [wYCoord]
ld b, a
- ld a, [W_XCOORD]
+ ld a, [wXCoord]
ld c, a
-.asm_37cc7
+.findMatchingCoordsLoop
ld a, [hli]
cp b
- jr nz, .asm_37ce1
+ jr nz, .nextEntry1
ld a, [hli]
cp c
- jr nz, .asm_37ce2
+ jr nz, .nextEntry2
ld a, [hli]
ld h, [hl]
ld l, a
-.asm_37cd2
+.copyMovementDataLoop
ld a, [hli]
cp $ff
ret z
@@ -40,22 +40,22 @@ PewterGuys: ; 37ca1 (d:7ca1)
ld a, [wSimulatedJoypadStatesIndex]
inc a
ld [wSimulatedJoypadStatesIndex], a
- jr .asm_37cd2
-.asm_37ce1
+ jr .copyMovementDataLoop
+.nextEntry1
inc hl
-.asm_37ce2
+.nextEntry2
inc hl
inc hl
- jr .asm_37cc7
+ jr .findMatchingCoordsLoop
-PointerTable_37ce6: ; 37ce6 (d:7ce6)
+PointerTable_37ce6:
dw PewterMuseumGuyCoords
dw PewterGymGuyCoords
; these are the four coordinates of the spaces below, above, to the left and
; to the right of the museum guy, and pointers to different movements for
; the player to make to get positioned before the main movement.
-PewterMuseumGuyCoords: ; 37cea (d:7cea)
+PewterMuseumGuyCoords:
db 18, 27
dw .down
db 16, 27
@@ -66,18 +66,19 @@ PewterMuseumGuyCoords: ; 37cea (d:7cea)
dw .right
.down
- db $40, $40, $ff
+ db D_UP, D_UP, $ff
.up
- db $10, $20, $ff
+ db D_RIGHT, D_LEFT, $ff
.left
- db $40, $10, $ff
+ db D_UP, D_RIGHT, $ff
.right
- db $40, $20, $ff
+ db D_UP, D_LEFT, $ff
; these are the five coordinates which trigger the gym guy and pointers to
; different movements for the player to make to get positioned before the
; main movement
-PewterGymGuyCoords: ; 37d06 (d:7d06)
+; $00 is a pause
+PewterGymGuyCoords:
db 16, 34
dw .one
db 17, 35
@@ -90,12 +91,12 @@ PewterGymGuyCoords: ; 37d06 (d:7d06)
dw .five
.one
- db $20, $80, $80, $10, $ff
+ db D_LEFT, D_DOWN, D_DOWN, D_RIGHT, $ff
.two
- db $20, $80, $10, $20, $ff
+ db D_LEFT, D_DOWN, D_RIGHT, D_LEFT, $ff
.three
- db $20, $20, $20, $00, $00, $00, $00, $00, $00, $00, $00, $ff
+ db D_LEFT, D_LEFT, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff
.four
- db $20, $20, $40, $20, $ff
+ db D_LEFT, D_LEFT, D_UP, D_LEFT, $ff
.five
- db $20, $80, $20, $00, $00, $00, $00, $00, $00, $00, $00, $ff
+ db D_LEFT, D_DOWN, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff
diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm
index 6602cedd..a17e67bd 100755
--- a/engine/overworld/player_animations.asm
+++ b/engine/overworld/player_animations.asm
@@ -1,15 +1,15 @@
-EnterMapAnim: ; 70510 (1c:4510)
- call InitFacingDirectionBuffer
+EnterMapAnim:
+ call InitFacingDirectionList
ld a, $ec
ld [wSpriteStateData1 + 4], a ; player's sprite Y screen position
call Delay3
push hl
call GBFadeInFromWhite
- ld hl, W_FLAGS_D733
+ ld hl, wFlags_D733
bit 7, [hl] ; used fly out of battle?
res 7, [hl]
jr nz, .flyAnimation
- ld a, (SFX_02_4c - SFX_Headers_02) / 3
+ ld a, SFX_TELEPORT_ENTER_1
call PlaySound
ld hl, wd732
bit 4, [hl] ; used dungeon warp?
@@ -17,7 +17,7 @@ EnterMapAnim: ; 70510 (1c:4510)
pop hl
jr nz, .dungeonWarpAnimation
call PlayerSpinWhileMovingDown
- ld a, (SFX_02_4f - SFX_Headers_02) / 3
+ ld a, SFX_TELEPORT_ENTER_2
call PlaySound
call IsPlayerStandingOnWarpPadOrHole
ld a, b
@@ -32,7 +32,7 @@ EnterMapAnim: ; 70510 (1c:4510)
ld a, $8
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue
ld [hl], $ff ; wPlayerSpinInPlaceAnimSoundID
- ld hl, wcd48
+ ld hl, wFacingDirectionList
call PlayerSpinInPlace
.restoreDefaultMusic
call PlayDefaultMusic
@@ -47,10 +47,10 @@ EnterMapAnim: ; 70510 (1c:4510)
pop hl
ld de, BirdSprite
ld hl, vNPCSprites
- ld bc, (BANK(BirdSprite) << 8) + $0c
+ lb bc, BANK(BirdSprite), $0c
call CopyVideoData
call LoadBirdSpriteGraphics
- ld a, (SFX_02_50 - SFX_Headers_02) / 3
+ ld a, SFX_FLY
call PlaySound
ld hl, wFlyAnimUsingCoordList
xor a ; is using coord list
@@ -58,12 +58,12 @@ EnterMapAnim: ; 70510 (1c:4510)
ld a, 12
ld [hli], a ; wFlyAnimCounter
ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing right)
- ld de, FlyAnimationEnterScreenCoords ; $4592
+ ld de, FlyAnimationEnterScreenCoords
call DoFlyAnimation
call LoadPlayerSpriteGraphics
jr .restoreDefaultMusic
-FlyAnimationEnterScreenCoords: ; 70592 (1c:4592)
+FlyAnimationEnterScreenCoords:
; y, x pairs
; This is the sequence of screen coordinates used by the overworld
; Fly animation when the player is entering a map.
@@ -80,7 +80,7 @@ FlyAnimationEnterScreenCoords: ; 70592 (1c:4592)
db $3C, $48
db $3C, $40
-PlayerSpinWhileMovingDown: ; 705aa (1c:45aa)
+PlayerSpinWhileMovingDown:
ld hl, wPlayerSpinWhileMovingUpOrDownAnimDeltaY
ld a, $10
ld [hli], a ; wPlayerSpinWhileMovingUpOrDownAnimDeltaY
@@ -90,8 +90,8 @@ PlayerSpinWhileMovingDown: ; 705aa (1c:45aa)
ld [hl], a ; wPlayerSpinWhileMovingUpOrDownAnimFrameDelay
jp PlayerSpinWhileMovingUpOrDown
-_LeaveMapAnim: ; 705ba (1c:45ba)
- call InitFacingDirectionBuffer
+_LeaveMapAnim:
+ call InitFacingDirectionList
call IsPlayerStandingOnWarpPadOrHole
ld a, b
and a
@@ -99,7 +99,7 @@ _LeaveMapAnim: ; 705ba (1c:45ba)
dec a
jp nz, LeaveMapThroughHoleAnim
.spinWhileMovingUp
- ld a, (SFX_02_4b - SFX_Headers_02) / 3
+ ld a, SFX_TELEPORT_EXIT_1
call PlaySound
ld hl, wPlayerSpinWhileMovingUpOrDownAnimDeltaY
ld a, -$10
@@ -133,8 +133,8 @@ _LeaveMapAnim: ; 705ba (1c:45ba)
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayDelta
xor a
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue
- ld [hl], (SFX_02_4d - SFX_Headers_02) / 3 ; wPlayerSpinInPlaceAnimSoundID
- ld hl, wcd48
+ ld [hl], SFX_TELEPORT_EXIT_2 ; wPlayerSpinInPlaceAnimSoundID
+ ld hl, wFacingDirectionList
call PlayerSpinInPlace
jr .spinWhileMovingUp
.flyAnimation
@@ -146,7 +146,7 @@ _LeaveMapAnim: ; 705ba (1c:45ba)
ld [hli], a ; wFlyAnimCounter
ld [hl], $c ; wFlyAnimBirdSpriteImageIndex
call DoFlyAnimation
- ld a, (SFX_02_50 - SFX_Headers_02) / 3
+ ld a, SFX_FLY
call PlaySound
ld hl, wFlyAnimUsingCoordList
xor a ; is using coord list
@@ -154,7 +154,7 @@ _LeaveMapAnim: ; 705ba (1c:45ba)
ld a, $c
ld [hli], a ; wFlyAnimCounter
ld [hl], $c ; wFlyAnimBirdSpriteImageIndex (facing right)
- ld de, FlyAnimationScreenCoords1 ; $464f
+ ld de, FlyAnimationScreenCoords1
call DoFlyAnimation
ld c, 40
call DelayFrames
@@ -162,12 +162,12 @@ _LeaveMapAnim: ; 705ba (1c:45ba)
ld a, 11
ld [hli], a ; wFlyAnimCounter
ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing left)
- ld de, FlyAnimationScreenCoords2 ; $4667
+ ld de, FlyAnimationScreenCoords2
call DoFlyAnimation
call GBFadeOutToWhite
jp RestoreFacingDirectionAndYScreenPos
-FlyAnimationScreenCoords1: ; 7064f (1c:464f)
+FlyAnimationScreenCoords1:
; y, x pairs
; This is the sequence of screen coordinates used by the first part
; of the Fly overworld animation.
@@ -184,7 +184,7 @@ FlyAnimationScreenCoords1: ; 7064f (1c:464f)
db $2A, $98
db $27, $A0
-FlyAnimationScreenCoords2: ; 70667 (1c:4667)
+FlyAnimationScreenCoords2:
; y, x pairs
; This is the sequence of screen coordinates used by the second part
; of the Fly overworld animation.
@@ -201,7 +201,7 @@ FlyAnimationScreenCoords2: ; 70667 (1c:4667)
db $F0, $00
-LeaveMapThroughHoleAnim: ; 7067d (1c:467d)
+LeaveMapThroughHoleAnim:
ld a, $ff
ld [wUpdateSpritesEnabled], a ; disable UpdateSprites
; shift upper half of player's sprite down 8 pixels and hide lower half
@@ -214,7 +214,7 @@ LeaveMapThroughHoleAnim: ; 7067d (1c:467d)
ld [wOAMBuffer + 1 * 4], a
ld c, 2
call DelayFrames
- ; hide lower half of player's sprite
+ ; hide upper half of player's sprite
ld a, $a0
ld [wOAMBuffer + 2 * 4], a
ld [wOAMBuffer + 3 * 4], a
@@ -223,7 +223,7 @@ LeaveMapThroughHoleAnim: ; 7067d (1c:467d)
ld [wUpdateSpritesEnabled], a ; enable UpdateSprites
jp RestoreFacingDirectionAndYScreenPos
-DoFlyAnimation: ; 706ae (1c:46ae)
+DoFlyAnimation:
ld a, [wFlyAnimBirdSpriteImageIndex]
xor $1 ; make the bird flap its wings
ld [wFlyAnimBirdSpriteImageIndex], a
@@ -231,7 +231,7 @@ DoFlyAnimation: ; 706ae (1c:46ae)
call Delay3
ld a, [wFlyAnimUsingCoordList]
cp $ff
- jr z, .asm_706cd
+ jr z, .skipCopyingCoords ; if the bird is flapping its wings in place
ld hl, wSpriteStateData1 + 4
ld a, [de]
inc de
@@ -240,34 +240,35 @@ DoFlyAnimation: ; 706ae (1c:46ae)
ld a, [de]
inc de
ld [hl], a
-.asm_706cd
+.skipCopyingCoords
ld a, [wFlyAnimCounter]
dec a
ld [wFlyAnimCounter], a
jr nz, DoFlyAnimation
ret
-LoadBirdSpriteGraphics: ; 706d7 (1c:46d7)
- ld de, BirdSprite ; $4d80
+LoadBirdSpriteGraphics:
+ ld de, BirdSprite
ld hl, vNPCSprites
- ld bc, (BANK(BirdSprite) << 8) + $0c
+ lb bc, BANK(BirdSprite), $0c
call CopyVideoData
- ld de, BirdSprite + $c0 ; $4e40 ; moving amination sprite
+ ld de, BirdSprite + $c0 ; moving animation sprite
ld hl, vNPCSprites2
- ld bc, (BANK(BirdSprite) << 8) + $0c
+ lb bc, BANK(BirdSprite), $0c
jp CopyVideoData
-InitFacingDirectionBuffer: ; 706ef (1c:46ef)
+InitFacingDirectionList:
ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction (image index is locked to standing images)
- ld [wcd50], a
+ ld [wSavedPlayerFacingDirection], a
ld a, [wSpriteStateData1 + 4] ; player's sprite Y screen position
- ld [wcd4f], a
+ ld [wSavedPlayerScreenY], a
ld hl, PlayerSpinningFacingOrder
- ld de, wcd48
- ld bc, $4
+ ld de, wFacingDirectionList
+ ld bc, 4
call CopyData
ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction (image index is locked to standing images)
- ld hl, wcd48
+ ld hl, wFacingDirectionList
+; find the place in the list that matches the current facing direction
.loop
cp [hl]
inc hl
@@ -275,34 +276,36 @@ InitFacingDirectionBuffer: ; 706ef (1c:46ef)
dec hl
ret
-PlayerSpinningFacingOrder: ; 70713 (1c:4713)
+PlayerSpinningFacingOrder:
; The order of the direction the player's sprite is facing when teleporting
; away. Creates a spinning effect.
db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT, SPRITE_FACING_UP, SPRITE_FACING_RIGHT
-SpinPlayerSprite: ; 70717 (1c:4717)
+SpinPlayerSprite:
+; copy the current value from the list into the sprite data and rotate the list
ld a, [hl]
ld [wSpriteStateData1 + 2], a ; player's sprite facing direction (image index is locked to standing images)
push hl
- ld hl, wcd48
- ld de, wcd47
- ld bc, $4
+ ld hl, wFacingDirectionList
+ ld de, wFacingDirectionList - 1
+ ld bc, 4
call CopyData
- ld a, [wcd47]
- ld [wcd4b], a
+ ld a, [wFacingDirectionList - 1]
+ ld [wFacingDirectionList + 3], a
pop hl
ret
-PlayerSpinInPlace: ; 70730 (1c:4730)
+PlayerSpinInPlace:
call SpinPlayerSprite
ld a, [wPlayerSpinInPlaceAnimFrameDelay]
ld c, a
and $3
- jr nz, .asm_70743
+ jr nz, .skipPlayingSound
+; when the last delay was a multiple of 4, play a sound if there is one
ld a, [wPlayerSpinInPlaceAnimSoundID]
cp $ff
call nz, PlaySound
-.asm_70743
+.skipPlayingSound
ld a, [wPlayerSpinInPlaceAnimFrameDelayDelta]
add c
ld [wPlayerSpinInPlaceAnimFrameDelay], a
@@ -313,7 +316,7 @@ PlayerSpinInPlace: ; 70730 (1c:4730)
call DelayFrames
jr PlayerSpinInPlace
-PlayerSpinWhileMovingUpOrDown: ; 70755 (1c:4755)
+PlayerSpinWhileMovingUpOrDown:
call SpinPlayerSprite
ld a, [wPlayerSpinWhileMovingUpOrDownAnimDeltaY]
ld c, a
@@ -329,25 +332,25 @@ PlayerSpinWhileMovingUpOrDown: ; 70755 (1c:4755)
call DelayFrames
jr PlayerSpinWhileMovingUpOrDown
-RestoreFacingDirectionAndYScreenPos: ; 70772 (1c:4772)
- ld a, [wcd4f]
+RestoreFacingDirectionAndYScreenPos:
+ ld a, [wSavedPlayerScreenY]
ld [wSpriteStateData1 + 4], a
- ld a, [wcd50]
+ ld a, [wSavedPlayerFacingDirection]
ld [wSpriteStateData1 + 2], a
ret
; if SGB, 2 frames, else 3 frames
-GetPlayerTeleportAnimFrameDelay: ; 7077f (1c:477f)
+GetPlayerTeleportAnimFrameDelay:
ld a, [wOnSGB]
xor $1
inc a
inc a
ret
-IsPlayerStandingOnWarpPadOrHole: ; 70787 (1c:4787)
+IsPlayerStandingOnWarpPadOrHole:
ld b, 0
ld hl, .warpPadAndHoleData
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
ld c, a
.loop
ld a, [hli]
@@ -367,99 +370,111 @@ IsPlayerStandingOnWarpPadOrHole: ; 70787 (1c:4787)
ld b, [hl]
.done
ld a, b
- ld [wcd5b], a
+ ld [wStandingOnWarpPadOrHole], a
ret
-; format: db tileset id, tile id, value to be put in wcd5b
-.warpPadAndHoleData: ; 707a9 (1c:47a9)
+; format: db tileset id, tile id, value to be put in [wStandingOnWarpPadOrHole]
+.warpPadAndHoleData:
db FACILITY, $20, 1 ; warp pad
db FACILITY, $11, 2 ; hole
db CAVERN, $22, 2 ; hole
db INTERIOR, $55, 1 ; warp pad
db $FF
-Func_707b6: ; 707b6 (1c:47b6)
- ld c, $a
+FishingAnim:
+ ld c, 10
call DelayFrames
ld hl, wd736
- set 6, [hl]
- ld de, RedSprite ; $4180
+ set 6, [hl] ; reserve the last 4 OAM entries
+ ld de, RedSprite
ld hl, vNPCSprites
- ld bc, (BANK(RedSprite) << 8) + $0c
+ lb bc, BANK(RedSprite), $c
call CopyVideoData
ld a, $4
- ld hl, RedFishingTiles ; $4866
+ ld hl, RedFishingTiles
call LoadAnimSpriteGfx
ld a, [wSpriteStateData1 + 2]
ld c, a
ld b, $0
- ld hl, FishingRodGfxProperties ; $4856
+ ld hl, FishingRodOAM
add hl, bc
ld de, wOAMBuffer + $9c
ld bc, $4
call CopyData
- ld c, $64
+ ld c, 100
call DelayFrames
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wRodResponse]
and a
ld hl, NoNibbleText
- jr z, .asm_70836
+ jr z, .done
cp $2
ld hl, NothingHereText
- jr z, .asm_70836
- ld b, $a
-.asm_707fe
- ld hl, wSpriteStateData1 + 4
- call Func_70842
+ jr z, .done
+
+; there was a bite
+
+; shake the player's sprite vertically
+ ld b, 10
+.loop
+ ld hl, wSpriteStateData1 + 4 ; player's sprite Y screen position
+ call .ShakePlayerSprite
ld hl, wOAMBuffer + $9c
- call Func_70842
+ call .ShakePlayerSprite
call Delay3
dec b
- jr nz, .asm_707fe
- ld a, [wSpriteStateData1 + 2]
- cp $4
- jr nz, .asm_7081c
+ jr nz, .loop
+
+; If the player is facing up, hide the fishing rod so it doesn't overlap with
+; the exclamation bubble that will be shown next.
+ ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction
+ cp SPRITE_FACING_UP
+ jr nz, .skipHidingFishingRod
ld a, $a0
ld [wOAMBuffer + $9c], a
-.asm_7081c
- ld hl, wcd4f
+
+.skipHidingFishingRod
+ ld hl, wEmotionBubbleSpriteIndex
xor a
- ld [hli], a
- ld [hl], a
+ ld [hli], a ; player's sprite
+ ld [hl], a ; EXCLAMATION_BUBBLE
predef EmotionBubble
- ld a, [wSpriteStateData1 + 2]
- cp $4
- jr nz, .asm_70833
+
+; If the player is facing up, unhide the fishing rod.
+ ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction
+ cp SPRITE_FACING_UP
+ jr nz, .skipUnhidingFishingRod
ld a, $44
ld [wOAMBuffer + $9c], a
-.asm_70833
+
+.skipUnhidingFishingRod
ld hl, ItsABiteText
-.asm_70836
+
+.done
call PrintText
ld hl, wd736
- res 6, [hl]
+ res 6, [hl] ; unreserve the last 4 OAM entries
call LoadFontTilePatterns
ret
-Func_70842: ; 70842 (1c:4842)
+.ShakePlayerSprite
ld a, [hl]
xor $1
ld [hl], a
ret
-NoNibbleText: ; 70847 (1c:4847)
+NoNibbleText:
TX_FAR _NoNibbleText
db "@"
-NothingHereText: ; 7084c (1c:484c)
+NothingHereText:
TX_FAR _NothingHereText
db "@"
-ItsABiteText: ; 70851 (1c:4851)
+ItsABiteText:
TX_FAR _ItsABiteText
db "@"
-FishingRodGfxProperties: ; 70856 (1c:4856)
+FishingRodOAM:
; specifies how the fishing rod should be drawn on the screen
; first byte = screen y coordinate
; second byte = screen x coordinate
@@ -470,7 +485,7 @@ FishingRodGfxProperties: ; 70856 (1c:4856)
db $50, $40, $FE, $00 ; player facing left
db $50, $58, $FE, $20 ; player facing right ($20 means "horizontally flip the tile")
-RedFishingTiles: ; 70866 (1c:4866)
+RedFishingTiles:
dw RedFishingTilesFront
db 2, BANK(RedFishingTilesFront)
dw vNPCSprites + $20
@@ -487,7 +502,7 @@ RedFishingTiles: ; 70866 (1c:4866)
db 3, BANK(RedFishingRodTiles)
dw vNPCSprites2 + $7d0
-_HandleMidJump: ; 7087e (1c:487e)
+_HandleMidJump:
ld a, [wPlayerJumpingYScreenCoordsIndex]
ld c, a
inc a
@@ -519,6 +534,6 @@ _HandleMidJump: ; 7087e (1c:487e)
ld [wJoyIgnore], a
ret
-PlayerJumpingYScreenCoords: ; 708ba (1c:48ba)
+PlayerJumpingYScreenCoords:
; Sequence of y screen coordinates for player's sprite when jumping over a ledge.
db $38, $36, $34, $32, $31, $30, $30, $30, $31, $32, $33, $34, $36, $38, $3C, $3C
diff --git a/engine/overworld/player_state.asm b/engine/overworld/player_state.asm
new file mode 100644
index 00000000..79f755b9
--- /dev/null
+++ b/engine/overworld/player_state.asm
@@ -0,0 +1,463 @@
+; only used for setting bit 2 of wd736 upon entering a new map
+IsPlayerStandingOnWarp:
+ ld a, [wNumberOfWarps]
+ and a
+ ret z
+ ld c, a
+ ld hl, wWarpEntries
+.loop
+ ld a, [wYCoord]
+ cp [hl]
+ jr nz, .nextWarp1
+ inc hl
+ ld a, [wXCoord]
+ cp [hl]
+ jr nz, .nextWarp2
+ inc hl
+ ld a, [hli] ; target warp
+ ld [wDestinationWarpID], a
+ ld a, [hl] ; target map
+ ld [hWarpDestinationMap], a
+ ld hl, wd736
+ set 2, [hl] ; standing on warp flag
+ ret
+.nextWarp1
+ inc hl
+.nextWarp2
+ inc hl
+ inc hl
+ inc hl
+ dec c
+ jr nz, .loop
+ ret
+
+CheckForceBikeOrSurf:
+ ld hl, wd732
+ bit 5, [hl]
+ ret nz
+ ld hl, ForcedBikeOrSurfMaps
+ ld a, [wYCoord]
+ ld b, a
+ ld a, [wXCoord]
+ ld c, a
+ ld a, [wCurMap]
+ ld d, a
+.loop
+ ld a, [hli]
+ cp $ff
+ ret z ;if we reach FF then it's not part of the list
+ cp d ;compare to current map
+ jr nz, .incorrectMap
+ ld a, [hli]
+ cp b ;compare y-coord
+ jr nz, .incorrectY
+ ld a, [hli]
+ cp c ;compare x-coord
+ jr nz, .loop ; incorrect x-coord, check next item
+ ld a, [wCurMap]
+ cp SEAFOAM_ISLANDS_4
+ ld a, $2
+ ld [wSeafoamIslands4CurScript], a
+ jr z, .forceSurfing
+ ld a, [wCurMap]
+ cp SEAFOAM_ISLANDS_5
+ ld a, $2
+ ld [wSeafoamIslands5CurScript], a
+ jr z, .forceSurfing
+ ;force bike riding
+ ld hl, wd732
+ set 5, [hl]
+ ld a, $1
+ ld [wWalkBikeSurfState], a
+ ld [wWalkBikeSurfStateCopy], a
+ jp ForceBikeOrSurf
+.incorrectMap
+ inc hl
+.incorrectY
+ inc hl
+ jr .loop
+.forceSurfing
+ ld a, $2
+ ld [wWalkBikeSurfState], a
+ ld [wWalkBikeSurfStateCopy], a
+ jp ForceBikeOrSurf
+
+INCLUDE "data/force_bike_surf.asm"
+
+IsPlayerFacingEdgeOfMap:
+ push hl
+ push de
+ push bc
+ ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
+ srl a
+ ld c, a
+ ld b, $0
+ ld hl, .functionPointerTable
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [wYCoord]
+ ld b, a
+ ld a, [wXCoord]
+ ld c, a
+ ld de, .asm_c41e
+ push de
+ jp [hl]
+.asm_c41e
+ pop bc
+ pop de
+ pop hl
+ ret
+
+.functionPointerTable
+ dw .facingDown
+ dw .facingUp
+ dw .facingLeft
+ dw .facingRight
+
+.facingDown
+ ld a, [wCurMapHeight]
+ add a
+ dec a
+ cp b
+ jr z, .setCarry
+ jr .resetCarry
+
+.facingUp
+ ld a, b
+ and a
+ jr z, .setCarry
+ jr .resetCarry
+
+.facingLeft
+ ld a, c
+ and a
+ jr z, .setCarry
+ jr .resetCarry
+
+.facingRight
+ ld a, [wCurMapWidth]
+ add a
+ dec a
+ cp c
+ jr z, .setCarry
+ jr .resetCarry
+.resetCarry
+ and a
+ ret
+.setCarry
+ scf
+ ret
+
+IsWarpTileInFrontOfPlayer:
+ push hl
+ push de
+ push bc
+ call _GetTileAndCoordsInFrontOfPlayer
+ ld a, [wCurMap]
+ cp SS_ANNE_5
+ jr z, .ssAnne5
+ ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
+ srl a
+ ld c, a
+ ld b, 0
+ ld hl, .warpTileListPointers
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [wTileInFrontOfPlayer]
+ ld de, $1
+ call IsInArray
+.done
+ pop bc
+ pop de
+ pop hl
+ ret
+
+.warpTileListPointers:
+ dw .facingDownWarpTiles
+ dw .facingUpWarpTiles
+ dw .facingLeftWarpTiles
+ dw .facingRightWarpTiles
+
+.facingDownWarpTiles
+ db $01,$12,$17,$3D,$04,$18,$33,$FF
+
+.facingUpWarpTiles
+ db $01,$5C,$FF
+
+.facingLeftWarpTiles
+ db $1A,$4B,$FF
+
+.facingRightWarpTiles
+ db $0F,$4E,$FF
+
+.ssAnne5
+ ld a, [wTileInFrontOfPlayer]
+ cp $15
+ jr nz, .notSSAnne5Warp
+ scf
+ jr .done
+.notSSAnne5Warp
+ and a
+ jr .done
+
+IsPlayerStandingOnDoorTileOrWarpTile:
+ push hl
+ push de
+ push bc
+ callba IsPlayerStandingOnDoorTile
+ jr c, .done
+ ld a, [wCurMapTileset]
+ add a
+ ld c, a
+ ld b, $0
+ ld hl, WarpTileIDPointers
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, $1
+ aCoord 8, 9
+ call IsInArray
+ jr nc, .done
+ ld hl, wd736
+ res 2, [hl]
+.done
+ pop bc
+ pop de
+ pop hl
+ ret
+
+INCLUDE "data/warp_tile_ids.asm"
+
+PrintSafariZoneSteps:
+ ld a, [wCurMap]
+ cp SAFARI_ZONE_EAST
+ ret c
+ cp UNKNOWN_DUNGEON_2
+ ret nc
+ coord hl, 0, 0
+ ld b, 3
+ ld c, 7
+ call TextBoxBorder
+ coord hl, 1, 1
+ ld de, wSafariSteps
+ lb bc, 2, 3
+ call PrintNumber
+ coord hl, 4, 1
+ ld de, SafariSteps
+ call PlaceString
+ coord hl, 1, 3
+ ld de, SafariBallText
+ call PlaceString
+ ld a, [wNumSafariBalls]
+ cp 10
+ jr nc, .asm_c56d
+ coord hl, 5, 3
+ ld a, " "
+ ld [hl], a
+.asm_c56d
+ coord hl, 6, 3
+ ld de, wNumSafariBalls
+ lb bc, 1, 2
+ jp PrintNumber
+
+SafariSteps:
+ db "/500@"
+
+SafariBallText:
+ db "BALL×× @"
+
+GetTileAndCoordsInFrontOfPlayer:
+ call GetPredefRegisters
+
+_GetTileAndCoordsInFrontOfPlayer:
+ ld a, [wYCoord]
+ ld d, a
+ ld a, [wXCoord]
+ ld e, a
+ ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ and a ; cp SPRITE_FACING_DOWN
+ jr nz, .notFacingDown
+; facing down
+ aCoord 8, 11
+ inc d
+ jr .storeTile
+.notFacingDown
+ cp SPRITE_FACING_UP
+ jr nz, .notFacingUp
+; facing up
+ aCoord 8, 7
+ dec d
+ jr .storeTile
+.notFacingUp
+ cp SPRITE_FACING_LEFT
+ jr nz, .notFacingLeft
+; facing left
+ aCoord 6, 9
+ dec e
+ jr .storeTile
+.notFacingLeft
+ cp SPRITE_FACING_RIGHT
+ jr nz, .storeTile
+; facing right
+ aCoord 10, 9
+ inc e
+.storeTile
+ ld c, a
+ ld [wTileInFrontOfPlayer], a
+ ret
+
+GetTileTwoStepsInFrontOfPlayer:
+ xor a
+ ld [$ffdb], a
+ ld hl, wYCoord
+ ld a, [hli]
+ ld d, a
+ ld e, [hl]
+ ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ and a ; cp SPRITE_FACING_DOWN
+ jr nz, .notFacingDown
+; facing down
+ ld hl, $ffdb
+ set 0, [hl]
+ aCoord 8, 13
+ inc d
+ jr .storeTile
+.notFacingDown
+ cp SPRITE_FACING_UP
+ jr nz, .notFacingUp
+; facing up
+ ld hl, $ffdb
+ set 1, [hl]
+ aCoord 8, 5
+ dec d
+ jr .storeTile
+.notFacingUp
+ cp SPRITE_FACING_LEFT
+ jr nz, .notFacingLeft
+; facing left
+ ld hl, $ffdb
+ set 2, [hl]
+ aCoord 4, 9
+ dec e
+ jr .storeTile
+.notFacingLeft
+ cp SPRITE_FACING_RIGHT
+ jr nz, .storeTile
+; facing right
+ ld hl, $ffdb
+ set 3, [hl]
+ aCoord 12, 9
+ inc e
+.storeTile
+ ld c, a
+ ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
+ ld [wTileInFrontOfPlayer], a
+ ret
+
+CheckForCollisionWhenPushingBoulder:
+ call GetTileTwoStepsInFrontOfPlayer
+ ld hl, wTilesetCollisionPtr
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+.loop
+ ld a, [hli]
+ cp $ff
+ jr z, .done ; if the tile two steps ahead is not passable
+ cp c
+ jr nz, .loop
+ ld hl, TilePairCollisionsLand
+ call CheckForTilePairCollisions2
+ ld a, $ff
+ jr c, .done ; if there is an elevation difference between the current tile and the one two steps ahead
+ ld a, [wTileInFrontOfBoulderAndBoulderCollisionResult]
+ cp $15 ; stairs tile
+ ld a, $ff
+ jr z, .done ; if the tile two steps ahead is stairs
+ call CheckForBoulderCollisionWithSprites
+.done
+ ld [wTileInFrontOfBoulderAndBoulderCollisionResult], a
+ ret
+
+; sets a to $ff if there is a collision and $00 if there is no collision
+CheckForBoulderCollisionWithSprites:
+ ld a, [wBoulderSpriteIndex]
+ dec a
+ swap a
+ ld d, 0
+ ld e, a
+ ld hl, wSpriteStateData2 + $14
+ add hl, de
+ ld a, [hli] ; map Y position
+ ld [$ffdc], a
+ ld a, [hl] ; map X position
+ ld [$ffdd], a
+ ld a, [wNumSprites]
+ ld c, a
+ ld de, $f
+ ld hl, wSpriteStateData2 + $14
+ ld a, [$ffdb]
+ and $3 ; facing up or down?
+ jr z, .pushingHorizontallyLoop
+.pushingVerticallyLoop
+ inc hl
+ ld a, [$ffdd]
+ cp [hl]
+ jr nz, .nextSprite1 ; if X coordinates don't match
+ dec hl
+ ld a, [hli]
+ ld b, a
+ ld a, [$ffdb]
+ rrca
+ jr c, .pushingDown
+; pushing up
+ ld a, [$ffdc]
+ dec a
+ jr .compareYCoords
+.pushingDown
+ ld a, [$ffdc]
+ inc a
+.compareYCoords
+ cp b
+ jr z, .failure
+.nextSprite1
+ dec c
+ jr z, .success
+ add hl, de
+ jr .pushingVerticallyLoop
+.pushingHorizontallyLoop
+ ld a, [hli]
+ ld b, a
+ ld a, [$ffdc]
+ cp b
+ jr nz, .nextSprite2
+ ld b, [hl]
+ ld a, [$ffdb]
+ bit 2, a
+ jr nz, .pushingLeft
+; pushing right
+ ld a, [$ffdd]
+ inc a
+ jr .compareXCoords
+.pushingLeft
+ ld a, [$ffdd]
+ dec a
+.compareXCoords
+ cp b
+ jr z, .failure
+.nextSprite2
+ dec c
+ jr z, .success
+ add hl, de
+ jr .pushingHorizontallyLoop
+.failure
+ ld a, $ff
+ ret
+.success
+ xor a
+ ret
diff --git a/engine/overworld/poison.asm b/engine/overworld/poison.asm
new file mode 100644
index 00000000..5d8eb9fd
--- /dev/null
+++ b/engine/overworld/poison.asm
@@ -0,0 +1,112 @@
+ApplyOutOfBattlePoisonDamage:
+ ld a, [wd730]
+ add a
+ jp c, .noBlackOut ; no black out if joypad states are being simulated
+ ld a, [wPartyCount]
+ and a
+ jp z, .noBlackOut
+ call IncrementDayCareMonExp
+ ld a, [wStepCounter]
+ and $3 ; is the counter a multiple of 4?
+ jp nz, .noBlackOut ; only apply poison damage every fourth step
+ ld [wWhichPokemon], a
+ ld hl, wPartyMon1Status
+ ld de, wPartySpecies
+.applyDamageLoop
+ ld a, [hl]
+ and (1 << PSN)
+ jr z, .nextMon2 ; not poisoned
+ dec hl
+ dec hl
+ ld a, [hld]
+ ld b, a
+ ld a, [hli]
+ or b
+ jr z, .nextMon ; already fainted
+; subtract 1 from HP
+ ld a, [hl]
+ dec a
+ ld [hld], a
+ inc a
+ jr nz, .noBorrow
+; borrow 1 from upper byte of HP
+ dec [hl]
+ inc hl
+ jr .nextMon
+.noBorrow
+ ld a, [hli]
+ or [hl]
+ jr nz, .nextMon ; didn't faint from damage
+; the mon fainted from the damage
+ push hl
+ inc hl
+ inc hl
+ ld [hl], a
+ ld a, [de]
+ ld [wd11e], a
+ push de
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMonNicks
+ call GetPartyMonName
+ xor a
+ ld [wJoyIgnore], a
+ call EnableAutoTextBoxDrawing
+ ld a, TEXT_MON_FAINTED
+ ld [hSpriteIndexOrTextID], a
+ call DisplayTextID
+ pop de
+ pop hl
+.nextMon
+ inc hl
+ inc hl
+.nextMon2
+ inc de
+ ld a, [de]
+ inc a
+ jr z, .applyDamageLoopDone
+ ld bc, wPartyMon2 - wPartyMon1
+ add hl, bc
+ push hl
+ ld hl, wWhichPokemon
+ inc [hl]
+ pop hl
+ jr .applyDamageLoop
+.applyDamageLoopDone
+ ld hl, wPartyMon1Status
+ ld a, [wPartyCount]
+ ld d, a
+ ld e, 0
+.countPoisonedLoop
+ ld a, [hl]
+ and (1 << PSN)
+ or e
+ ld e, a
+ ld bc, wPartyMon2 - wPartyMon1
+ add hl, bc
+ dec d
+ jr nz, .countPoisonedLoop
+ ld a, e
+ and a ; are any party members poisoned?
+ jr z, .skipPoisonEffectAndSound
+ ld b, $2
+ predef ChangeBGPalColor0_4Frames ; change BG white to dark grey for 4 frames
+ ld a, SFX_POISONED
+ call PlaySound
+.skipPoisonEffectAndSound
+ predef AnyPartyAlive
+ ld a, d
+ and a
+ jr nz, .noBlackOut
+ call EnableAutoTextBoxDrawing
+ ld a, TEXT_BLACKED_OUT
+ ld [hSpriteIndexOrTextID], a
+ call DisplayTextID
+ ld hl, wd72e
+ set 5, [hl]
+ ld a, $ff
+ jr .done
+.noBlackOut
+ xor a
+.done
+ ld [wOutOfBattleBlackout], a
+ ret
diff --git a/engine/overworld/pokecenter.asm b/engine/overworld/pokecenter.asm
index 3c640d8e..f26bedf8 100755
--- a/engine/overworld/pokecenter.asm
+++ b/engine/overworld/pokecenter.asm
@@ -1,4 +1,4 @@
-DisplayPokemonCenterDialogue_: ; 6fe6 (1:6fe6)
+DisplayPokemonCenterDialogue_:
call SaveScreenTilesToBuffer1 ; save screen
ld hl, PokemonCenterWelcomeText
call PrintText
@@ -24,12 +24,12 @@ DisplayPokemonCenterDialogue_: ; 6fe6 (1:6fe6)
predef HealParty
callba AnimateHealingMachine ; do the healing machine animation
xor a
- ld [wMusicHeaderPointer], a
- ld a, [wc0f0]
- ld [wc0ef], a
- ld a, [wd35b]
- ld [wcfca], a
- ld [wc0ee], a
+ ld [wAudioFadeOutControl], a
+ ld a, [wAudioSavedROMBank]
+ ld [wAudioROMBank], a
+ ld a, [wMapMusicSoundID]
+ ld [wLastMusicSoundID], a
+ ld [wNewSoundID], a
call PlaySound
ld hl, PokemonFightingFitText
call PrintText
@@ -43,26 +43,26 @@ DisplayPokemonCenterDialogue_: ; 6fe6 (1:6fe6)
.done
ld hl, PokemonCenterFarewellText
call PrintText
- jp UpdateSprites ; move sprites
+ jp UpdateSprites
-PokemonCenterWelcomeText: ; 705d (1:705d)
+PokemonCenterWelcomeText:
TX_FAR _PokemonCenterWelcomeText
db "@"
-ShallWeHealYourPokemonText: ; 7062 (1:7062)
- db $a
+ShallWeHealYourPokemonText:
+ TX_DELAY
TX_FAR _ShallWeHealYourPokemonText
db "@"
-NeedYourPokemonText: ; 7068 (1:7068)
+NeedYourPokemonText:
TX_FAR _NeedYourPokemonText
db "@"
-PokemonFightingFitText: ; 706d (1:706d)
+PokemonFightingFitText:
TX_FAR _PokemonFightingFitText
db "@"
-PokemonCenterFarewellText: ; 7072 (1:7072)
- db $a
+PokemonCenterFarewellText:
+ TX_DELAY
TX_FAR _PokemonCenterFarewellText
db "@"
diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm
index 8325b93f..823939b1 100755
--- a/engine/overworld/pokemart.asm
+++ b/engine/overworld/pokemart.asm
@@ -1,30 +1,34 @@
-DisplayPokemartDialogue_: ; 6c20 (1:6c20)
+DisplayPokemartDialogue_:
ld a,[wListScrollOffset]
- ld [wd07e],a
- call UpdateSprites ; move sprites
+ ld [wSavedListScrollOffset],a
+ call UpdateSprites
xor a
- ld [wcf0a],a ; flag that is set if something is sold or bought
+ ld [wBoughtOrSoldItemInMart],a
.loop
xor a
ld [wListScrollOffset],a
ld [wCurrentMenuItem],a
ld [wPlayerMonNumber],a
inc a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
+ call DisplayTextBoxID
ld a,BUY_SELL_QUIT_MENU
ld [wTextBoxID],a
- call DisplayTextBoxID ; do buy/sell/quit menu
- ld hl,wd128 ; pointer to this pokemart's inventory
+ call DisplayTextBoxID
+
+; This code is useless. It copies the address of the pokemart's inventory to hl,
+; but the address is never used.
+ ld hl,wItemListPointer
ld a,[hli]
ld l,[hl]
- ld h,a ; hl = address of inventory
- ld a,[wd12e]
- cp a,$02
+ ld h,a
+
+ ld a,[wMenuExitMethod]
+ cp a,CANCELLED_MENU
jp z,.done
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wChosenMenuItem]
and a ; buying?
jp z,.buyMenu
dec a ; selling?
@@ -32,11 +36,14 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
dec a ; quitting?
jp z,.done
.sellMenu
+
+; the same variables are set again below, so this code has no effect
xor a
- ld [wcf93],a
- ld a,$02
- ld [wd11b],a
- callab Func_39bd5
+ ld [wPrintItemPrices],a
+ ld a,INIT_BAG_ITEM_LIST
+ ld [wInitListType],a
+ callab InitList
+
ld a,[wNumBagItems]
and a
jp z,.bagEmpty
@@ -50,19 +57,19 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call DisplayTextBoxID ; draw money text box
ld hl,wNumBagItems
ld a,l
- ld [wList],a
+ ld [wListPointer],a
ld a,h
- ld [wList + 1],a
+ ld [wListPointer + 1],a
xor a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
ld [wCurrentMenuItem],a
ld a,ITEMLISTMENU
ld [wListMenuID],a
call DisplayListMenuID
jp c,.returnToMainPokemartMenu ; if the player closed the menu
.confirmItemSale ; if the player is trying to sell a specific item
- call IsKeyItem ; check if item is unsellable
- ld a,[wd124]
+ call IsKeyItem
+ ld a,[wIsKeyItem]
and a
jr nz,.unsellableItem
ld a,[wcf91]
@@ -70,30 +77,34 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
jr c,.unsellableItem
ld a,PRICEDITEMLISTMENU
ld [wListMenuID],a
- ld [$ff8e],a ; halve prices when selling
+ ld [hHalveItemPrices],a ; halve prices when selling
call DisplayChooseQuantityMenu
inc a
jr z,.sellMenuLoop ; if the player closed the choose quantity menu with the B button
ld hl,PokemartTellSellPriceText
- ld bc,$0e01
+ lb bc, 14, 1 ; location that PrintText always prints to, this is useless
call PrintText
- hlCoord 14, 7
- ld bc,$080f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,$02
- jr z,.sellMenuLoop ; if the player pressed the B button
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
+ jr z,.sellMenuLoop ; if the player chose No or pressed the B button
+
+; The following code is supposed to check if the player chose No, but the above
+; check already catches it.
+ ld a,[wChosenMenuItem]
dec a
- jr z,.sellMenuLoop ; if the player chose No
+ jr z,.sellMenuLoop
+
.sellItem
- ld a,[wcf0a] ; flag that is set if something is sold or bought
+ ld a,[wBoughtOrSoldItemInMart]
and a
jr nz,.skipSettingFlag1
inc a
- ld [wcf0a],a
+ ld [wBoughtOrSoldItemInMart],a
.skipSettingFlag1
call AddAmountSoldToMoney
ld hl,wNumBagItems
@@ -106,39 +117,42 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
.bagEmpty
ld hl,PokemartItemBagEmptyText
call PrintText
- call SaveScreenTilesToBuffer1 ; save screen
+ call SaveScreenTilesToBuffer1
jp .returnToMainPokemartMenu
.buyMenu
- ld a,$01
- ld [wcf93],a
- ld a,$03
- ld [wd11b],a
- callab Func_39bd5
+
+; the same variables are set again below, so this code has no effect
+ ld a,1
+ ld [wPrintItemPrices],a
+ ld a,INIT_OTHER_ITEM_LIST
+ ld [wInitListType],a
+ callab InitList
+
ld hl,PokemartBuyingGreetingText
call PrintText
- call SaveScreenTilesToBuffer1 ; save screen
+ call SaveScreenTilesToBuffer1
.buyMenuLoop
- call LoadScreenTilesFromBuffer1 ; restore saved screen
+ call LoadScreenTilesFromBuffer1
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
- ld hl,wStringBuffer2 + 11
+ call DisplayTextBoxID
+ ld hl,wItemList
ld a,l
- ld [wList],a
+ ld [wListPointer],a
ld a,h
- ld [wList + 1],a
+ ld [wListPointer + 1],a
xor a
ld [wCurrentMenuItem],a
inc a
- ld [wcf93],a
+ ld [wPrintItemPrices],a
inc a ; a = 2 (PRICEDITEMLISTMENU)
ld [wListMenuID],a
call DisplayListMenuID
jr c,.returnToMainPokemartMenu ; if the player closed the menu
- ld a,$63
- ld [wcf97],a
+ ld a,99
+ ld [wMaxItemQuantity],a
xor a
- ld [$ff8e],a
+ ld [hHalveItemPrices],a ; don't halve item prices when buying
call DisplayChooseQuantityMenu
inc a
jr z,.buyMenuLoop ; if the player closed the choose quantity menu with the B button
@@ -148,17 +162,21 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call CopyStringToCF4B ; copy name to wcf4b
ld hl,PokemartTellBuyPriceText
call PrintText
- hlCoord 14, 7
- ld bc,$080f
+ coord hl, 14, 7
+ lb bc, 8, 15
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
- ld a,[wd12e]
- cp a,$02
- jp z,.buyMenuLoop ; if the player pressed the B button
- ld a,[wd12d] ; ID of the chosen menu item
+ ld a,[wMenuExitMethod]
+ cp a,CHOSE_SECOND_ITEM
+ jp z,.buyMenuLoop ; if the player chose No or pressed the B button
+
+; The following code is supposed to check if the player chose No, but the above
+; check already catches it.
+ ld a,[wChosenMenuItem]
dec a
- jr z,.buyMenuLoop ; if the player chose No
+ jr z,.buyMenuLoop
+
.buyItem
call .isThereEnoughMoney
jr c,.notEnoughMoney
@@ -166,13 +184,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call AddItemToInventory
jr nc,.bagFull
call SubtractAmountPaidFromMoney
- ld a,[wcf0a] ; flag that is set if something is sold or bought
+ ld a,[wBoughtOrSoldItemInMart]
and a
jr nz,.skipSettingFlag2
- ld a,$01
- ld [wcf0a],a
+ ld a,1
+ ld [wBoughtOrSoldItemInMart],a
.skipSettingFlag2
- ld a,(SFX_02_5a - SFX_Headers_02) / 3
+ ld a,SFX_PURCHASE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
ld hl,PokemartBoughtItemText
@@ -182,13 +200,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
call LoadScreenTilesFromBuffer1
ld a,MONEY_BOX
ld [wTextBoxID],a
- call DisplayTextBoxID ; draw money text box
+ call DisplayTextBoxID
ld hl,PokemartAnythingElseText
call PrintText
jp .loop
.isThereEnoughMoney
ld de,wPlayerMoney
- ld hl,$ff9f ; item price
+ ld hl,hMoney
ld c,3 ; length of money in bytes
jp StringCmp
.notEnoughMoney
@@ -202,53 +220,53 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20)
.done
ld hl,PokemartThankYouText
call PrintText
- ld a,$01
+ ld a,1
ld [wUpdateSpritesEnabled],a
- call UpdateSprites ; move sprites
- ld a,[wd07e]
+ call UpdateSprites
+ ld a,[wSavedListScrollOffset]
ld [wListScrollOffset],a
ret
-PokemartBuyingGreetingText: ; 6e0c (1:6e0c)
+PokemartBuyingGreetingText:
TX_FAR _PokemartBuyingGreetingText
db "@"
-PokemartTellBuyPriceText: ; 6e11 (1:6e11)
+PokemartTellBuyPriceText:
TX_FAR _PokemartTellBuyPriceText
db "@"
-PokemartBoughtItemText: ; 6e16 (1:6e16)
+PokemartBoughtItemText:
TX_FAR _PokemartBoughtItemText
db "@"
-PokemartNotEnoughMoneyText: ; 6e1b (1:6e1b)
+PokemartNotEnoughMoneyText:
TX_FAR _PokemartNotEnoughMoneyText
db "@"
-PokemartItemBagFullText: ; 6e20 (1:6e20)
+PokemartItemBagFullText:
TX_FAR _PokemartItemBagFullText
db "@"
-PokemonSellingGreetingText: ; 6e25 (1:6e25)
+PokemonSellingGreetingText:
TX_FAR _PokemonSellingGreetingText
db "@"
-PokemartTellSellPriceText: ; 6e2a (1:6e2a)
+PokemartTellSellPriceText:
TX_FAR _PokemartTellSellPriceText
db "@"
-PokemartItemBagEmptyText: ; 6e2f (1:6e2f)
+PokemartItemBagEmptyText:
TX_FAR _PokemartItemBagEmptyText
db "@"
-PokemartUnsellableItemText: ; 6e34 (1:6e34)
+PokemartUnsellableItemText:
TX_FAR _PokemartUnsellableItemText
db "@"
-PokemartThankYouText: ; 6e39 (1:6e39)
+PokemartThankYouText:
TX_FAR _PokemartThankYouText
db "@"
-PokemartAnythingElseText: ; 6e3e (1:6e3e)
+PokemartAnythingElseText:
TX_FAR _PokemartAnythingElseText
db "@"
diff --git a/engine/overworld/push_boulder.asm b/engine/overworld/push_boulder.asm
new file mode 100644
index 00000000..c91605a8
--- /dev/null
+++ b/engine/overworld/push_boulder.asm
@@ -0,0 +1,105 @@
+TryPushingBoulder:
+ ld a, [wd728]
+ bit 0, a ; using Strength?
+ ret z
+ ld a, [wFlags_0xcd60]
+ bit 1, a ; has boulder dust animation from previous push played yet?
+ ret nz
+ xor a
+ ld [hSpriteIndexOrTextID], a
+ call IsSpriteInFrontOfPlayer
+ ld a, [hSpriteIndexOrTextID]
+ ld [wBoulderSpriteIndex], a
+ and a
+ jp z, ResetBoulderPushFlags
+ ld hl, wSpriteStateData1 + 1
+ ld d, $0
+ ld a, [hSpriteIndexOrTextID]
+ swap a
+ ld e, a
+ add hl, de
+ res 7, [hl]
+ call GetSpriteMovementByte2Pointer
+ ld a, [hl]
+ cp BOULDER_MOVEMENT_BYTE_2
+ jp nz, ResetBoulderPushFlags
+ ld hl, wFlags_0xcd60
+ bit 6, [hl]
+ set 6, [hl] ; indicate that the player has tried pushing
+ ret z ; the player must try pushing twice before the boulder will move
+ ld a, [hJoyHeld]
+ and D_RIGHT | D_LEFT | D_UP | D_DOWN
+ ret z
+ predef CheckForCollisionWhenPushingBoulder
+ ld a, [wTileInFrontOfBoulderAndBoulderCollisionResult]
+ and a ; was there a collision?
+ jp nz, ResetBoulderPushFlags
+ ld a, [hJoyHeld]
+ ld b, a
+ ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ cp SPRITE_FACING_UP
+ jr z, .pushBoulderUp
+ cp SPRITE_FACING_LEFT
+ jr z, .pushBoulderLeft
+ cp SPRITE_FACING_RIGHT
+ jr z, .pushBoulderRight
+.pushBoulderDown
+ bit 7, b
+ ret z
+ ld de, PushBoulderDownMovementData
+ jr .done
+.pushBoulderUp
+ bit 6, b
+ ret z
+ ld de, PushBoulderUpMovementData
+ jr .done
+.pushBoulderLeft
+ bit 5, b
+ ret z
+ ld de, PushBoulderLeftMovementData
+ jr .done
+.pushBoulderRight
+ bit 4, b
+ ret z
+ ld de, PushBoulderRightMovementData
+.done
+ call MoveSprite
+ ld a, SFX_PUSH_BOULDER
+ call PlaySound
+ ld hl, wFlags_0xcd60
+ set 1, [hl]
+ ret
+
+PushBoulderUpMovementData:
+ db NPC_MOVEMENT_UP,$FF
+
+PushBoulderDownMovementData:
+ db NPC_MOVEMENT_DOWN,$FF
+
+PushBoulderLeftMovementData:
+ db NPC_MOVEMENT_LEFT,$FF
+
+PushBoulderRightMovementData:
+ db NPC_MOVEMENT_RIGHT,$FF
+
+DoBoulderDustAnimation:
+ ld a, [wd730]
+ bit 0, a
+ ret nz
+ callab AnimateBoulderDust
+ call DiscardButtonPresses
+ ld [wJoyIgnore], a
+ call ResetBoulderPushFlags
+ set 7, [hl]
+ ld a, [wBoulderSpriteIndex]
+ ld [H_SPRITEINDEX], a
+ call GetSpriteMovementByte2Pointer
+ ld [hl], $10
+ ld a, SFX_CUT
+ jp PlaySound
+
+ResetBoulderPushFlags:
+ ld hl, wFlags_0xcd60
+ res 1, [hl]
+ res 6, [hl]
+ ret
diff --git a/engine/overworld/saffron_guards.asm b/engine/overworld/saffron_guards.asm
index 8e584a2d..3b26b6f8 100755
--- a/engine/overworld/saffron_guards.asm
+++ b/engine/overworld/saffron_guards.asm
@@ -1,4 +1,4 @@
-RemoveGuardDrink: ; 5a59f (16:659f)
+RemoveGuardDrink:
ld hl, GuardDrinksList
.drinkLoop
ld a, [hli]
@@ -10,9 +10,7 @@ RemoveGuardDrink: ; 5a59f (16:659f)
call IsItemInBag
pop hl
jr z, .drinkLoop
- ld b, BANK(RemoveItemByID)
- ld hl, RemoveItemByID
- jp Bankswitch
+ jpba RemoveItemByID
-GuardDrinksList: ; 5a5b7 (16:65b7)
+GuardDrinksList:
db FRESH_WATER, SODA_POP, LEMONADE, $00
diff --git a/engine/overworld/set_blackout_map.asm b/engine/overworld/set_blackout_map.asm
new file mode 100644
index 00000000..9bfe82bd
--- /dev/null
+++ b/engine/overworld/set_blackout_map.asm
@@ -0,0 +1,29 @@
+SetLastBlackoutMap:
+; Set the map to return to when
+; blacking out or using Teleport or Dig.
+; Safari rest houses don't count.
+
+ push hl
+ ld hl, SafariZoneRestHouses
+ ld a, [wCurMap]
+ ld b, a
+.loop
+ ld a, [hli]
+ cp -1
+ jr z, .notresthouse
+ cp b
+ jr nz, .loop
+ jr .done
+
+.notresthouse
+ ld a, [wLastMap]
+ ld [wLastBlackoutMap], a
+.done
+ pop hl
+ ret
+
+SafariZoneRestHouses:
+ db SAFARI_ZONE_REST_HOUSE_2
+ db SAFARI_ZONE_REST_HOUSE_3
+ db SAFARI_ZONE_REST_HOUSE_4
+ db -1
diff --git a/engine/overworld/ssanne.asm b/engine/overworld/ssanne.asm
index f1a8ecf9..712c53ed 100755
--- a/engine/overworld/ssanne.asm
+++ b/engine/overworld/ssanne.asm
@@ -1,6 +1,6 @@
-AnimateBoulderDust: ; 79f54 (1e:5f54)
+AnimateBoulderDust:
ld a, $1
- ld [wcd50], a ; select the boulder dust offsets
+ ld [wWhichAnimationOffsets], a ; select the boulder dust offsets
ld a, [wUpdateSpritesEnabled]
push af
ld a, $ff
@@ -8,14 +8,14 @@ AnimateBoulderDust: ; 79f54 (1e:5f54)
ld a, %11100100
ld [rOBP1], a
call LoadSmokeTileFourTimes
- callba WriteCutTreeBoulderDustAnimationOAMBlock
+ callba WriteCutOrBoulderDustAnimationOAMBlock
ld c, 8 ; number of steps in animation
.loop
push bc
call GetMoveBoulderDustFunctionPointer
ld bc, .returnAddress
push bc
- ld c, $4
+ ld c, 4
jp [hl]
.returnAddress
ld a, [rOBP1]
@@ -29,14 +29,14 @@ AnimateBoulderDust: ; 79f54 (1e:5f54)
ld [wUpdateSpritesEnabled], a
jp LoadPlayerSpriteGraphics
-GetMoveBoulderDustFunctionPointer: ; 79f92 (1e:5f92)
+GetMoveBoulderDustFunctionPointer:
ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
ld hl, MoveBoulderDustFunctionPointerTable
ld c, a
ld b, $0
add hl, bc
ld a, [hli]
- ld [wd08a], a
+ ld [wCoordAdjustmentAmount], a
ld a, [hli]
ld e, a
ld a, [hli]
@@ -51,7 +51,7 @@ GetMoveBoulderDustFunctionPointer: ; 79f92 (1e:5f92)
pop hl
ret
-MoveBoulderDustFunctionPointerTable: ; 79fb0 (1e:5fb0)
+MoveBoulderDustFunctionPointerTable:
; facing down
db $FF,$00
dw AdjustOAMBlockYPos
@@ -68,7 +68,7 @@ MoveBoulderDustFunctionPointerTable: ; 79fb0 (1e:5fb0)
db $FF,$01
dw AdjustOAMBlockXPos
-LoadSmokeTileFourTimes: ; 79fc0 (1e:5fc0)
+LoadSmokeTileFourTimes:
ld hl, vChars1 + $7c0
ld c, $4
.loop
@@ -83,10 +83,11 @@ LoadSmokeTileFourTimes: ; 79fc0 (1e:5fc0)
jr nz, .loop
ret
-LoadSmokeTile: ; 79fd4 (1e:5fd4)
- ld de, SSAnneSmokePuffTile ; $5fdd
- ld bc, (BANK(SSAnneSmokePuffTile) << 8) + $01
+LoadSmokeTile:
+ ld de, SSAnneSmokePuffTile
+ lb bc, BANK(SSAnneSmokePuffTile), (SSAnneSmokePuffTileEnd - SSAnneSmokePuffTile) / $10
jp CopyVideoData
-SSAnneSmokePuffTile: ; 79fdd (1e:5fdd)
+SSAnneSmokePuffTile:
INCBIN "gfx/ss_anne_smoke_puff.2bpp"
+SSAnneSmokePuffTileEnd:
diff --git a/engine/overworld/tileset_header.asm b/engine/overworld/tileset_header.asm
new file mode 100644
index 00000000..6e33974f
--- /dev/null
+++ b/engine/overworld/tileset_header.asm
@@ -0,0 +1,60 @@
+LoadTilesetHeader:
+ call GetPredefRegisters
+ push hl
+ ld d, 0
+ ld a, [wCurMapTileset]
+ add a
+ add a
+ ld b, a
+ add a
+ add b ; a = tileset * 12
+ jr nc, .noCarry
+ inc d
+.noCarry
+ ld e, a
+ ld hl, Tilesets
+ add hl, de
+ ld de, wTilesetBank
+ ld c, $b
+.copyTilesetHeaderLoop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .copyTilesetHeaderLoop
+ ld a, [hl]
+ ld [hTilesetType], a
+ xor a
+ ld [$ffd8], a
+ pop hl
+ ld a, [wCurMapTileset]
+ push hl
+ push de
+ ld hl, DungeonTilesets
+ ld de, $1
+ call IsInArray
+ pop de
+ pop hl
+ jr c, .asm_c797
+ ld a, [wCurMapTileset]
+ ld b, a
+ ld a, [hPreviousTileset]
+ cp b
+ jr z, .done
+.asm_c797
+ ld a, [wDestinationWarpID]
+ cp $ff
+ jr z, .done
+ call LoadDestinationWarpPosition
+ ld a, [wYCoord]
+ and $1
+ ld [wYBlockCoord], a
+ ld a, [wXCoord]
+ and $1
+ ld [wXBlockCoord], a
+.done
+ ret
+
+INCLUDE "data/dungeon_tilesets.asm"
+
+INCLUDE "data/tileset_headers.asm"
diff --git a/engine/overworld/trainers.asm b/engine/overworld/trainers.asm
index 4aaab3ed..655c6b2a 100755
--- a/engine/overworld/trainers.asm
+++ b/engine/overworld/trainers.asm
@@ -1,42 +1,42 @@
-_GetSpritePosition1: ; 567f9 (15:67f9)
+_GetSpritePosition1:
ld hl, wSpriteStateData1
ld de, $4
ld a, [wSpriteIndex]
ld [H_SPRITEINDEX], a
call GetSpriteDataPointer
- ld a, [hli]
+ ld a, [hli] ; c1x4 (screen Y pos)
ld [$ffeb], a
inc hl
- ld a, [hl]
+ ld a, [hl] ; c1x6 (screen X pos)
ld [$ffec], a
- ld de, $fe
+ ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
add hl, de
- ld a, [hli]
+ ld a, [hli] ; c2x4 (map Y pos)
ld [$ffed], a
- ld a, [hl]
+ ld a, [hl] ; c2x5 (map X pos)
ld [$ffee], a
ret
-_GetSpritePosition2: ; 56819 (15:6819)
+_GetSpritePosition2:
ld hl, wSpriteStateData1
ld de, $4
ld a, [wSpriteIndex]
ld [H_SPRITEINDEX], a
call GetSpriteDataPointer
ld a, [hli] ; c1x4 (screen Y pos)
- ld [wd130], a
+ ld [wSavedSpriteScreenY], a
inc hl
ld a, [hl] ; c1x6 (screen X pos)
- ld [wd131], a
- ld de, $104 - $6
+ ld [wSavedSpriteScreenX], a
+ ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
add hl, de
ld a, [hli] ; c2x4 (map Y pos)
- ld [wd132], a
+ ld [wSavedSpriteMapY], a
ld a, [hl] ; c2x5 (map X pos)
- ld [wd133], a
+ ld [wSavedSpriteMapX], a
ret
-_SetSpritePosition1: ; 5683d (15:683d)
+_SetSpritePosition1:
ld hl, wSpriteStateData1
ld de, $4
ld a, [wSpriteIndex]
@@ -47,7 +47,7 @@ _SetSpritePosition1: ; 5683d (15:683d)
inc hl
ld a, [$ffec] ; c1x6 (screen X pos)
ld [hl], a
- ld de, $104 - $6
+ ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
add hl, de
ld a, [$ffed] ; c2x4 (map Y pos)
ld [hli], a
@@ -55,36 +55,36 @@ _SetSpritePosition1: ; 5683d (15:683d)
ld [hl], a
ret
-_SetSpritePosition2: ; 5685d (15:685d)
+_SetSpritePosition2:
ld hl, wSpriteStateData1
- ld de, $0004
+ ld de, 4
ld a, [wSpriteIndex]
ld [H_SPRITEINDEX], a
call GetSpriteDataPointer
- ld a, [wd130]
- ld [hli], a
+ ld a, [wSavedSpriteScreenY]
+ ld [hli], a ; c1x4 (screen Y pos)
inc hl
- ld a, [wd131]
- ld [hl], a
- ld de, $00fe
+ ld a, [wSavedSpriteScreenX]
+ ld [hl], a ; c1x6 (screen X pos)
+ ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
add hl, de
- ld a, [wd132]
- ld [hli], a
- ld a, [wd133]
- ld [hl], a
+ ld a, [wSavedSpriteMapY]
+ ld [hli], a ; c2x4 (map Y pos)
+ ld a, [wSavedSpriteMapX]
+ ld [hl], a ; c2x5 (map X pos)
ret
-TrainerWalkUpToPlayer: ; 56881 (15:6881)
+TrainerWalkUpToPlayer:
ld a, [wSpriteIndex]
swap a
- ld [wTrainerSpriteOffset], a ; wWhichTrade
+ ld [wTrainerSpriteOffset], a
call ReadTrainerScreenPosition
ld a, [wTrainerFacingDirection]
- and a
+ and a ; SPRITE_FACING_DOWN
jr z, .facingDown
- cp $4
+ cp SPRITE_FACING_UP
jr z, .facingUp
- cp $8
+ cp SPRITE_FACING_LEFT
jr z, .facingLeft
jr .facingRight
.facingDown
@@ -148,8 +148,8 @@ TrainerWalkUpToPlayer: ; 56881 (15:6881)
jp MoveSprite_
; input: de = offset within sprite entry
-; output: de = pointer to sprite data
-GetSpriteDataPointer: ; 56903 (15:6903)
+; output: hl = pointer to sprite data
+GetSpriteDataPointer:
push de
add hl, de
ld a, [H_SPRITEINDEX]
@@ -161,10 +161,10 @@ GetSpriteDataPointer: ; 56903 (15:6903)
ret
; tests if this trainer is in the right position to engage the player and do so if she is.
-TrainerEngage: ; 5690f (15:690f)
+TrainerEngage:
push hl
push de
- ld a, [wTrainerSpriteOffset] ; wWhichTrade
+ ld a, [wTrainerSpriteOffset]
add $2
ld d, $0
ld e, a
@@ -175,7 +175,7 @@ TrainerEngage: ; 5690f (15:690f)
jr nz, .spriteOnScreen ; test if sprite is on screen
jp .noEngage
.spriteOnScreen
- ld a, [wTrainerSpriteOffset] ; wWhichTrade
+ ld a, [wTrainerSpriteOffset]
add $9
ld d, $0
ld e, a
@@ -218,57 +218,57 @@ TrainerEngage: ; 5690f (15:690f)
jp .noEngage
.engage
call CheckPlayerIsInFrontOfSprite
- ld a, [wTrainerSpriteOffset] ; wWhichTrade
+ ld a, [wTrainerSpriteOffset]
and a
jr z, .noEngage
ld hl, wFlags_0xcd60
set 0, [hl]
call EngageMapTrainer
ld a, $ff
-.noEngage: ; 56988 (15:6988)
- ld [wTrainerSpriteOffset], a ; wWhichTrade
+.noEngage
+ ld [wTrainerSpriteOffset], a
pop de
pop hl
ret
; reads trainer's Y position to wTrainerScreenY and X position to wTrainerScreenX
-ReadTrainerScreenPosition: ; 5698e (15:698e)
- ld a, [wTrainerSpriteOffset] ; wWhichTrade
+ReadTrainerScreenPosition:
+ ld a, [wTrainerSpriteOffset]
add $4
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl]
+ ld a, [hl] ; c1x4 (sprite Y pos)
ld [wTrainerScreenY], a
- ld a, [wTrainerSpriteOffset] ; wWhichTrade
+ ld a, [wTrainerSpriteOffset]
add $6
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl]
+ ld a, [hl] ; c1x6 (sprite X pos)
ld [wTrainerScreenX], a
ret
; checks if the sprite is properly lined up with the player with respect to the direction it's looking. Also checks the distance between player and sprite
; note that this does not necessarily mean the sprite is seeing the player, he could be behind it's back
; a: distance player to sprite
-CheckSpriteCanSeePlayer: ; 569af (15:69af)
+CheckSpriteCanSeePlayer:
ld b, a
- ld a, [wTrainerEngageDistance] ; sprite line of sight (engage distance)
+ ld a, [wTrainerEngageDistance] ; how far the trainer can see
cp b
jr nc, .checkIfLinedUp
jr .notInLine ; player too far away
.checkIfLinedUp
ld a, [wTrainerFacingDirection] ; sprite facing direction
- cp $0 ; down
+ cp SPRITE_FACING_DOWN
jr z, .checkXCoord
- cp $4 ; up
+ cp SPRITE_FACING_UP
jr z, .checkXCoord
- cp $8 ; left
+ cp SPRITE_FACING_LEFT
jr z, .checkYCoord
- cp $c ; right
+ cp SPRITE_FACING_RIGHT
jr z, .checkYCoord
jr .notInLine
.checkXCoord
@@ -290,11 +290,11 @@ CheckSpriteCanSeePlayer: ; 569af (15:69af)
ret
; tests if the player is in front of the sprite (rather than behind it)
-CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3)
- ld a, [W_CURMAP] ; W_CURMAP
+CheckPlayerIsInFrontOfSprite:
+ ld a, [wCurMap]
cp POWER_PLANT
- jp z, .engage ; XXX not sure why bypass this for power plant (maybe to get voltorb fake items to work?)
- ld a, [wTrainerSpriteOffset] ; wWhichTrade
+ jp z, .engage ; bypass this for power plant to get voltorb fake items to work
+ ld a, [wTrainerSpriteOffset]
add $4
ld d, $0
ld e, a
@@ -306,7 +306,7 @@ CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3)
ld a, $c
.notOnTopmostTile
ld [wTrainerScreenY], a
- ld a, [wTrainerSpriteOffset] ; wWhichTrade
+ ld a, [wTrainerSpriteOffset]
add $6
ld d, $0
ld e, a
@@ -315,21 +315,21 @@ CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3)
ld a, [hl] ; c1x6 (sprite screen X pos)
ld [wTrainerScreenX], a
ld a, [wTrainerFacingDirection] ; facing direction
- cp $0
+ cp SPRITE_FACING_DOWN
jr nz, .notFacingDown
ld a, [wTrainerScreenY] ; sprite screen Y pos
cp $3c
jr c, .engage ; sprite above player
jr .noEngage ; sprite below player
.notFacingDown
- cp $4
+ cp SPRITE_FACING_UP
jr nz, .notFacingUp
ld a, [wTrainerScreenY] ; sprite screen Y pos
cp $3c
jr nc, .engage ; sprite below player
jr .noEngage ; sprite above player
.notFacingUp
- cp $8
+ cp SPRITE_FACING_LEFT
jr nz, .notFacingLeft
ld a, [wTrainerScreenX] ; sprite screen X pos
cp $40
@@ -345,5 +345,5 @@ CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3)
.noEngage
xor a
.done
- ld [wTrainerSpriteOffset], a ; wWhichTrade
+ ld [wTrainerSpriteOffset], a
ret
diff --git a/engine/overworld/update_map.asm b/engine/overworld/update_map.asm
new file mode 100644
index 00000000..8577b9e7
--- /dev/null
+++ b/engine/overworld/update_map.asm
@@ -0,0 +1,126 @@
+; replaces a tile block with the one specified in [wNewTileBlockID]
+; and redraws the map view if necessary
+; b = Y
+; c = X
+ReplaceTileBlock:
+ call GetPredefRegisters
+ ld hl, wOverworldMap
+ ld a, [wCurMapWidth]
+ add $6
+ ld e, a
+ ld d, $0
+ add hl, de
+ add hl, de
+ add hl, de
+ ld e, $3
+ add hl, de
+ ld e, a
+ ld a, b
+ and a
+ jr z, .addX
+; add width * Y
+.addWidthYTimesLoop
+ add hl, de
+ dec b
+ jr nz, .addWidthYTimesLoop
+.addX
+ add hl, bc ; add X
+ ld a, [wNewTileBlockID]
+ ld [hl], a
+ ld a, [wCurrentTileBlockMapViewPointer]
+ ld c, a
+ ld a, [wCurrentTileBlockMapViewPointer + 1]
+ ld b, a
+ call CompareHLWithBC
+ ret c ; return if the replaced tile block is below the map view in memory
+ push hl
+ ld l, e
+ ld h, $0
+ ld e, $6
+ ld d, h
+ add hl, hl
+ add hl, hl
+ add hl, de
+ add hl, bc
+ pop bc
+ call CompareHLWithBC
+ ret c ; return if the replaced tile block is above the map view in memory
+
+RedrawMapView:
+ ld a, [wIsInBattle]
+ inc a
+ ret z
+ ld a, [H_AUTOBGTRANSFERENABLED]
+ push af
+ ld a, [hTilesetType]
+ push af
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld [hTilesetType], a ; no flower/water BG tile animations
+ call LoadCurrentMapView
+ call RunDefaultPaletteCommand
+ ld hl, wMapViewVRAMPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, -2 * 32
+ add hl, de
+ ld a, h
+ and $3
+ or $98
+ ld a, l
+ ld [wBuffer], a
+ ld a, h
+ ld [wBuffer + 1], a ; this copy of the address is not used
+ ld a, 2
+ ld [$ffbe], a
+ ld c, 9 ; number of rows of 2x2 tiles (this covers the whole screen)
+.redrawRowLoop
+ push bc
+ push hl
+ push hl
+ ld hl, wTileMap - 2 * SCREEN_WIDTH
+ ld de, SCREEN_WIDTH
+ ld a, [$ffbe]
+.calcWRAMAddrLoop
+ add hl, de
+ dec a
+ jr nz, .calcWRAMAddrLoop
+ call CopyToRedrawRowOrColumnSrcTiles
+ pop hl
+ ld de, $20
+ ld a, [$ffbe]
+ ld c, a
+.calcVRAMAddrLoop
+ add hl, de
+ ld a, h
+ and $3
+ or $98
+ dec c
+ jr nz, .calcVRAMAddrLoop
+ ld [hRedrawRowOrColumnDest + 1], a
+ ld a, l
+ ld [hRedrawRowOrColumnDest], a
+ ld a, REDRAW_ROW
+ ld [hRedrawRowOrColumnMode], a
+ call DelayFrame
+ ld hl, $ffbe
+ inc [hl]
+ inc [hl]
+ pop hl
+ pop bc
+ dec c
+ jr nz, .redrawRowLoop
+ pop af
+ ld [hTilesetType], a
+ pop af
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ret
+
+CompareHLWithBC:
+ ld a, h
+ sub b
+ ret nz
+ ld a, l
+ sub c
+ ret
diff --git a/engine/overworld/wild_mons.asm b/engine/overworld/wild_mons.asm
new file mode 100644
index 00000000..6444ab7e
--- /dev/null
+++ b/engine/overworld/wild_mons.asm
@@ -0,0 +1,33 @@
+LoadWildData:
+ ld hl,WildDataPointers
+ ld a,[wCurMap]
+
+ ; get wild data for current map
+ ld c,a
+ ld b,0
+ add hl,bc
+ add hl,bc
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a ; hl now points to wild data for current map
+ ld a,[hli]
+ ld [wGrassRate],a
+ and a
+ jr z,.NoGrassData ; if no grass data, skip to surfing data
+ push hl
+ ld de,wGrassMons ; otherwise, load grass data
+ ld bc,$0014
+ call CopyData
+ pop hl
+ ld bc,$0014
+ add hl,bc
+.NoGrassData
+ ld a,[hli]
+ ld [wWaterRate],a
+ and a
+ ret z ; if no water data, we're done
+ ld de,wWaterMons ; otherwise, load surfing data
+ ld bc,$0014
+ jp CopyData
+
+INCLUDE "data/wild_mons.asm"
diff --git a/engine/palettes.asm b/engine/palettes.asm
index ed06cf4e..4785ade2 100755
--- a/engine/palettes.asm
+++ b/engine/palettes.asm
@@ -1,49 +1,49 @@
-Func_71ddf: ; 71ddf (1c:5ddf)
+_RunPaletteCommand:
call GetPredefRegisters
ld a, b
cp $ff
- jr nz, .asm_71dea
- ld a, [wcf1c]
-.asm_71dea
- cp $fc
- jp z, Func_71fc2
+ jr nz, .next
+ ld a, [wDefaultPaletteCommand] ; use default command if command ID is $ff
+.next
+ cp UPDATE_PARTY_MENU_BLK_PACKET
+ jp z, UpdatePartyMenuBlkPacket
ld l, a
- ld h, $0
+ ld h, 0
add hl, hl
- ld de, PointerTable_71f73
+ ld de, SetPalFunctions
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
- ld de, Func_72156
+ ld de, SendSGBPackets
push de
jp [hl]
-SendPalPacket_Black: ; 71dff (1c:5dff)
+SetPal_BattleBlack:
ld hl, PalPacket_Black
ld de, BlkPacket_Battle
ret
; uses PalPacket_Empty to build a packet based on mon IDs and health color
-BuildBattlePalPacket: ; 71e06 (1c:5e06)
+SetPal_Battle:
ld hl, PalPacket_Empty
- ld de, wcf2d
+ ld de, wPalPacket
ld bc, $10
call CopyData
- ld a, [W_PLAYERBATTSTATUS3]
+ ld a, [wPlayerBattleStatus3]
ld hl, wBattleMonSpecies
call DeterminePaletteID
ld b, a
- ld a, [W_ENEMYBATTSTATUS3]
+ ld a, [wEnemyBattleStatus3]
ld hl, wEnemyMonSpecies2
call DeterminePaletteID
ld c, a
- ld hl, wcf2e
- ld a, [wcf1d]
+ ld hl, wPalPacket + 1
+ ld a, [wPlayerHPBarColor]
add PAL_GREENBAR
ld [hli], a
inc hl
- ld a, [wcf1e]
+ ld a, [wEnemyHPBarColor]
add PAL_GREENBAR
ld [hli], a
inc hl
@@ -52,21 +52,21 @@ BuildBattlePalPacket: ; 71e06 (1c:5e06)
inc hl
ld a, c
ld [hl], a
- ld hl, wcf2d
+ ld hl, wPalPacket
ld de, BlkPacket_Battle
- ld a, $1
- ld [wcf1c], a
+ ld a, SET_PAL_BATTLE
+ ld [wDefaultPaletteCommand], a
ret
-SendPalPacket_TownMap: ; 71e48 (1c:5e48)
+SetPal_TownMap:
ld hl, PalPacket_TownMap
ld de, BlkPacket_WholeScreen
ret
; uses PalPacket_Empty to build a packet based the mon ID
-BuildStatusScreenPalPacket: ; 71e4f (1c:5e4f)
+SetPal_StatusScreen:
ld hl, PalPacket_Empty
- ld de, wcf2d
+ ld de, wPalPacket
ld bc, $10
call CopyData
ld a, [wcf91]
@@ -76,75 +76,75 @@ BuildStatusScreenPalPacket: ; 71e4f (1c:5e4f)
.pokemon
call DeterminePaletteIDOutOfBattle
push af
- ld hl, wcf2e
- ld a, [wcf25]
- add $1f
+ ld hl, wPalPacket + 1
+ ld a, [wStatusScreenHPBarColor]
+ add PAL_GREENBAR
ld [hli], a
inc hl
pop af
ld [hl], a
- ld hl, wcf2d
+ ld hl, wPalPacket
ld de, BlkPacket_StatusScreen
ret
-SendPalPacket_PartyMenu: ; 71e7b (1c:5e7b)
+SetPal_PartyMenu:
ld hl, PalPacket_PartyMenu
- ld de, wcf2e
+ ld de, wPartyMenuBlkPacket
ret
-SendPalPacket_Pokedex: ; 71e82 (1c:5e82)
+SetPal_Pokedex:
ld hl, PalPacket_Pokedex
- ld de, wcf2d
+ ld de, wPalPacket
ld bc, $10
call CopyData
ld a, [wcf91]
call DeterminePaletteIDOutOfBattle
- ld hl, wcf30
+ ld hl, wPalPacket + 3
ld [hl], a
- ld hl, wcf2d
+ ld hl, wPalPacket
ld de, BlkPacket_Pokedex
ret
-SendPalPacket_Slots: ; 71e9f (1c:5e9f)
+SetPal_Slots:
ld hl, PalPacket_Slots
ld de, BlkPacket_Slots
ret
-SendPalPacket_Titlescreen: ; 71ea6 (1c:5ea6)
+SetPal_TitleScreen:
ld hl, PalPacket_Titlescreen
ld de, BlkPacket_Titlescreen
ret
; used mostly for menus and the Oak intro
-SendPalPacket_Generic: ; 71ead (1c:5ead)
+SetPal_Generic:
ld hl, PalPacket_Generic
ld de, BlkPacket_WholeScreen
ret
-SendPalPacket_NidorinoIntro: ; 71eb4 (1c:5eb4)
+SetPal_NidorinoIntro:
ld hl, PalPacket_NidorinoIntro
ld de, BlkPacket_NidorinoIntro
ret
-SendPalPacket_GameFreakIntro: ; 71ebb (1c:5ebb)
+SetPal_GameFreakIntro:
ld hl, PalPacket_GameFreakIntro
ld de, BlkPacket_GameFreakIntro
- ld a, $8
- ld [wcf1c], a
+ ld a, SET_PAL_GENERIC
+ ld [wDefaultPaletteCommand], a
ret
; uses PalPacket_Empty to build a packet based on the current map
-BuildOverworldPalPacket: ; 71ec7 (1c:5ec7)
+SetPal_Overworld:
ld hl, PalPacket_Empty
- ld de, wcf2d
+ ld de, wPalPacket
ld bc, $10
call CopyData
- ld a, [W_CURMAPTILESET]
+ ld a, [wCurMapTileset]
cp CEMETERY
jr z, .PokemonTowerOrAgatha
cp CAVERN
jr z, .caveOrBruno
- ld a, [W_CURMAP]
+ ld a, [wCurMap]
cp REDS_HOUSE_1F
jr c, .townOrRoute
cp UNKNOWN_DUNGEON_2
@@ -162,12 +162,12 @@ BuildOverworldPalPacket: ; 71ec7 (1c:5ec7)
jr c, .town
ld a, PAL_ROUTE - 1
.town
- inc a ; a town's pallete ID is its map ID + 1
- ld hl, wcf2e
+ inc a ; a town's palette ID is its map ID + 1
+ ld hl, wPalPacket + 1
ld [hld], a
ld de, BlkPacket_WholeScreen
- ld a, $9
- ld [wcf1c], a
+ ld a, SET_PAL_OVERWORLD
+ ld [wDefaultPaletteCommand], a
ret
.PokemonTowerOrAgatha
ld a, PAL_GREYMON - 1
@@ -181,137 +181,149 @@ BuildOverworldPalPacket: ; 71ec7 (1c:5ec7)
; used when a Pokemon is the only thing on the screen
; such as evolution, trading and the Hall of Fame
-SendPokemonPalette_WholeScreen: ; 71f17 (1c:5f17)
+SetPal_PokemonWholeScreen:
push bc
ld hl, PalPacket_Empty
- ld de, wcf2d
+ ld de, wPalPacket
ld bc, $10
call CopyData
pop bc
ld a, c
and a
- ld a, $1e
- jr nz, .asm_71f31
- ld a, [wcf1d]
+ ld a, PAL_BLACK
+ jr nz, .next
+ ld a, [wWholeScreenPaletteMonSpecies]
call DeterminePaletteIDOutOfBattle
-.asm_71f31
- ld [wcf2e], a
- ld hl, wcf2d
+.next
+ ld [wPalPacket + 1], a
+ ld hl, wPalPacket
ld de, BlkPacket_WholeScreen
ret
-BuildTrainerCardPalPacket: ; 71f3b (1c:5f3b)
+SetPal_TrainerCard:
ld hl, BlkPacket_TrainerCard
- ld de, wcc5b
+ ld de, wTrainerCardBlkPacket
ld bc, $40
call CopyData
- ld de, LoopCounts_71f8f
- ld hl, wcc5d
- ld a, [W_OBTAINEDBADGES]
- ld c, $8
-.asm_71f52
+ ld de, BadgeBlkDataLengths
+ ld hl, wTrainerCardBlkPacket + 2
+ ld a, [wObtainedBadges]
+ ld c, 8
+.badgeLoop
srl a
push af
- jr c, .asm_71f62
+ jr c, .haveBadge
+; The player doens't have the badge, so zero the badge's blk data.
push bc
ld a, [de]
ld c, a
xor a
-.asm_71f5b
+.zeroBadgeDataLoop
ld [hli], a
dec c
- jr nz, .asm_71f5b
+ jr nz, .zeroBadgeDataLoop
pop bc
- jr .asm_71f67
-.asm_71f62
+ jr .nextBadge
+.haveBadge
+; The player does have the badge, so skip past the badge's blk data.
ld a, [de]
-.asm_71f63
+.skipBadgeDataLoop
inc hl
dec a
- jr nz, .asm_71f63
-.asm_71f67
+ jr nz, .skipBadgeDataLoop
+.nextBadge
pop af
inc de
dec c
- jr nz, .asm_71f52
+ jr nz, .badgeLoop
ld hl, PalPacket_TrainerCard
- ld de, wcc5b
+ ld de, wTrainerCardBlkPacket
ret
-PointerTable_71f73: ; 71f73 (1c:5f73)
- dw SendPalPacket_Black
- dw BuildBattlePalPacket
- dw SendPalPacket_TownMap
- dw BuildStatusScreenPalPacket
- dw SendPalPacket_Pokedex
- dw SendPalPacket_Slots
- dw SendPalPacket_Titlescreen
- dw SendPalPacket_NidorinoIntro
- dw SendPalPacket_Generic
- dw BuildOverworldPalPacket
- dw SendPalPacket_PartyMenu
- dw SendPokemonPalette_WholeScreen
- dw SendPalPacket_GameFreakIntro
- dw BuildTrainerCardPalPacket
-
-; each byte is the number of loops to make in .asm_71f5b for each badge
-LoopCounts_71f8f: ; 71f8f (1c:5f8f)
- db $06,$06,$06,$12,$06,$06,$06,$06
-
-DeterminePaletteID: ; 71f97 (1c:5f97)
- bit 3, a ; bit 3 of battle status 3, set if current Pokemon is transformed
- ld a, PAL_GREYMON ; if yes, use Ditto's palette
+SetPalFunctions:
+ dw SetPal_BattleBlack
+ dw SetPal_Battle
+ dw SetPal_TownMap
+ dw SetPal_StatusScreen
+ dw SetPal_Pokedex
+ dw SetPal_Slots
+ dw SetPal_TitleScreen
+ dw SetPal_NidorinoIntro
+ dw SetPal_Generic
+ dw SetPal_Overworld
+ dw SetPal_PartyMenu
+ dw SetPal_PokemonWholeScreen
+ dw SetPal_GameFreakIntro
+ dw SetPal_TrainerCard
+
+; The length of the blk data of each badge on the Trainer Card.
+; The Rainbow Badge has 3 entries because of its many colors.
+BadgeBlkDataLengths:
+ db 6 ; Boulder Badge
+ db 6 ; Cascade Badge
+ db 6 ; Thunder Badge
+ db 6 * 3 ; Rainbow Badge
+ db 6 ; Soul Badge
+ db 6 ; Marsh Badge
+ db 6 ; Volcano Badge
+ db 6 ; Earth Badge
+
+DeterminePaletteID:
+ bit Transformed, a ; a is battle status 3
+ ld a, PAL_GREYMON ; if the mon has used Transform, use Ditto's palette
ret nz
ld a, [hl]
-DeterminePaletteIDOutOfBattle: ; 71f9d (1c:5f9d)
+DeterminePaletteIDOutOfBattle:
ld [wd11e], a
- and a
- jr z, .idZero
+ and a ; is the mon index 0?
+ jr z, .skipDexNumConversion
push bc
- predef IndexToPokedex ; turn Pokemon ID number into Pokedex number
+ predef IndexToPokedex
pop bc
ld a, [wd11e]
-.idZero
+.skipDexNumConversion
ld e, a
- ld d, $00
- ld hl, MonsterPalettes ; not just for Pokemon, Trainers use it too
+ ld d, 0
+ ld hl, MonsterPalettes ; not just for Pokemon, Trainers use it too
add hl, de
ld a, [hl]
ret
-SendBlkPacket_PartyMenu: ; 71fb6 (1c:5fb6)
- ld hl, BlkPacket_PartyMenu ; $62f4
- ld de, wcf2e
+InitPartyMenuBlkPacket:
+ ld hl, BlkPacket_PartyMenu
+ ld de, wPartyMenuBlkPacket
ld bc, $30
jp CopyData
-Func_71fc2: ; 71fc2 (1c:5fc2)
- ld hl, wcf1f
- ld a, [wcf2d]
+UpdatePartyMenuBlkPacket:
+; Update the blk packet with the palette of the HP bar that is
+; specified in [wWhichPartyMenuHPBar].
+ ld hl, wPartyMenuHPBarColors
+ ld a, [wWhichPartyMenuHPBar]
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
ld e, l
ld d, h
ld a, [de]
and a
- ld e, $5
- jr z, .asm_71fdb
+ ld e, (1 << 2) | 1 ; green
+ jr z, .next
dec a
- ld e, $a
- jr z, .asm_71fdb
- ld e, $f
-.asm_71fdb
+ ld e, (2 << 2) | 2 ; yellow
+ jr z, .next
+ ld e, (3 << 2) | 3 ; red
+.next
push de
- ld hl, wcf37
- ld bc, $6
- ld a, [wcf2d]
+ ld hl, wPartyMenuBlkPacket + 8 + 1
+ ld bc, 6
+ ld a, [wWhichPartyMenuHPBar]
call AddNTimes
pop de
ld [hl], e
ret
-SendSGBPacket: ; 71feb (1c:5feb)
+SendSGBPacket:
;check number of packets
ld a,[hl]
and a,$07
@@ -321,17 +333,15 @@ SendSGBPacket: ; 71feb (1c:5feb)
.loop2
; save B for later use
push bc
-; load a non-zero value in $fff9 to disable the routine that checks actual
-; joypad input (said routine, located at $15f, does nothing if $fff9 is not
-; zero)
- ld a,$01
- ld [$fff9],a
+; disable ReadJoypad to prevent it from interfering with sending the packet
+ ld a, 1
+ ld [hDisableJoypadPolling], a
; send RESET signal (P14=LOW, P15=LOW)
xor a
- ld [$ff00],a
+ ld [rJOYP],a
; set P14=HIGH, P15=HIGH
ld a,$30
- ld [$ff00],a
+ ld [rJOYP],a
;load length of packets (16 bytes)
ld b,$10
.nextByte
@@ -348,10 +358,10 @@ SendSGBPacket: ; 71feb (1c:5feb)
; else (if 0th bit is zero) set P14=LOW,P15=HIGH (send bit 0)
ld a,$20
.next0
- ld [$ff00],a
+ ld [rJOYP],a
; must set P14=HIGH,P15=HIGH between each "pulse"
ld a,$30
- ld [$ff00],a
+ ld [rJOYP],a
; rotation will put next bit in 0th position (so we can always use command
; "bit 0,d" to fetch the bit that has to be sent)
rr d
@@ -362,12 +372,12 @@ SendSGBPacket: ; 71feb (1c:5feb)
jr nz,.nextByte
; send bit 1 as a "stop bit" (end of parameter data)
ld a,$20
- ld [$ff00],a
+ ld [rJOYP],a
; set P14=HIGH,P15=HIGH
ld a,$30
- ld [$ff00],a
+ ld [rJOYP],a
xor a
- ld [$fff9],a
+ ld [hDisableJoypadPolling],a
; wait for about 70000 cycles
call Wait7000
; restore (previously pushed) number of packets
@@ -378,44 +388,44 @@ SendSGBPacket: ; 71feb (1c:5feb)
; else send 16 more bytes
jr .loop2
-LoadSGB: ; 7202b (1c:602b)
+LoadSGB:
xor a
ld [wOnSGB], a
call CheckSGB
ret nc
- ld a, $1
+ ld a, 1
ld [wOnSGB], a
ld a, [wGBC]
and a
- jr z, .asm_7203f
+ jr z, .notGBC
ret
-.asm_7203f
+.notGBC
di
- call Func_72075
+ call PrepareSuperNintendoVRAMTransfer
ei
- ld a, $1
- ld [wcf2d], a
+ ld a, 1
+ ld [wCopyingSGBTileData], a
ld de, ChrTrnPacket
ld hl, SGBBorderGraphics
- call Func_7210b
+ call CopyGfxToSuperNintendoVRAM
xor a
- ld [wcf2d], a
+ ld [wCopyingSGBTileData], a
ld de, PctTrnPacket
ld hl, BorderPalettes
- call Func_7210b
+ call CopyGfxToSuperNintendoVRAM
xor a
- ld [wcf2d], a
+ ld [wCopyingSGBTileData], a
ld de, PalTrnPacket
ld hl, SuperPalettes
- call Func_7210b
+ call CopyGfxToSuperNintendoVRAM
call ClearVram
ld hl, MaskEnCancelPacket
jp SendSGBPacket
-Func_72075: ; 72075 (1c:6075)
- ld hl, PointerTable_72089
- ld c, $9
-.asm_7207a
+PrepareSuperNintendoVRAMTransfer:
+ ld hl, .packetPointers
+ ld c, 9
+.loop
push bc
ld a, [hli]
push hl
@@ -426,10 +436,11 @@ Func_72075: ; 72075 (1c:6075)
inc hl
pop bc
dec c
- jr nz, .asm_7207a
+ jr nz, .loop
ret
-PointerTable_72089: ; 72089 (1c:6089)
+.packetPointers
+; Only the first packet is needed.
dw MaskEnFreezePacket
dw DataSnd_72548
dw DataSnd_72558
@@ -440,102 +451,103 @@ PointerTable_72089: ; 72089 (1c:6089)
dw DataSnd_725a8
dw DataSnd_725b8
-CheckSGB: ; 7209b (1c:609b)
+CheckSGB:
+; Returns whether the game is running on an SGB in carry.
ld hl, MltReq2Packet
di
call SendSGBPacket
- ld a, $1
- ld [$fff9], a
+ ld a, 1
+ ld [hDisableJoypadPolling], a
ei
call Wait7000
- ld a, [rJOYP] ; $ff0
+ ld a, [rJOYP]
and $3
cp $3
- jr nz, .asm_720fd
+ jr nz, .isSGB
ld a, $20
- ld [rJOYP], a ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
+ ld [rJOYP], a
+ ld a, [rJOYP]
+ ld a, [rJOYP]
call Wait7000
call Wait7000
ld a, $30
- ld [rJOYP], a ; $ff0
+ ld [rJOYP], a
call Wait7000
call Wait7000
ld a, $10
- ld [rJOYP], a ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
+ ld [rJOYP], a
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
call Wait7000
call Wait7000
ld a, $30
- ld [rJOYP], a ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
- ld a, [rJOYP] ; $ff0
+ ld [rJOYP], a
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ ld a, [rJOYP]
call Wait7000
call Wait7000
- ld a, [rJOYP] ; $ff0
+ ld a, [rJOYP]
and $3
cp $3
- jr nz, .asm_720fd
- call Func_72102
+ jr nz, .isSGB
+ call SendMltReq1Packet
and a
ret
-.asm_720fd
- call Func_72102
+.isSGB
+ call SendMltReq1Packet
scf
ret
-Func_72102: ; 72102 (1c:6102)
+SendMltReq1Packet:
ld hl, MltReq1Packet
call SendSGBPacket
jp Wait7000
-Func_7210b: ; 7210b (1c:610b)
+CopyGfxToSuperNintendoVRAM:
di
push de
call DisableLCD
ld a, $e4
- ld [rBGP], a ; $ff47
+ ld [rBGP], a
ld de, vChars1
- ld a, [wcf2d]
+ ld a, [wCopyingSGBTileData]
and a
- jr z, .asm_72122
- call Func_72188
- jr .asm_72128
-.asm_72122
+ jr z, .notCopyingTileData
+ call CopySGBBorderTiles
+ jr .next
+.notCopyingTileData
ld bc, $1000
call CopyData
-.asm_72128
+.next
ld hl, vBGMap0
ld de, $c
ld a, $80
ld c, $d
-.asm_72132
+.loop
ld b, $14
-.asm_72134
+.innerLoop
ld [hli], a
inc a
dec b
- jr nz, .asm_72134
+ jr nz, .innerLoop
add hl, de
dec c
- jr nz, .asm_72132
+ jr nz, .loop
ld a, $e3
- ld [rLCDC], a ; $ff40
+ ld [rLCDC], a
pop hl
call SendSGBPacket
xor a
- ld [rBGP], a ; $ff47
+ ld [rBGP], a
ei
ret
-Wait7000: ; 7214a (1c:614a)
+Wait7000:
; Each loop takes 9 cycles so this routine actually waits 63000 cycles.
ld de, 7000
.loop
@@ -548,27 +560,27 @@ Wait7000: ; 7214a (1c:614a)
jr nz, .loop
ret
-Func_72156: ; 72156 (1c:6156)
+SendSGBPackets:
ld a, [wGBC]
and a
- jr z, .asm_72165
+ jr z, .notGBC
push de
- call Func_7216d
+ call InitGBCPalettes
pop hl
- call Func_72187
+ call EmptyFunc5
ret
-.asm_72165
+.notGBC
push de
call SendSGBPacket
pop hl
jp SendSGBPacket
-Func_7216d: ; 7216d (1c:616d)
- ld a, $80
- ld [$ff68], a
+InitGBCPalettes:
+ ld a, $80 ; index 0 with auto-increment
+ ld [rBGPI], a
inc hl
ld c, $20
-.asm_72174
+.loop
ld a, [hli]
inc hl
add a
@@ -576,37 +588,48 @@ Func_7216d: ; 7216d (1c:616d)
add a
ld de, SuperPalettes
add e
- jr nc, .asm_72180
+ jr nc, .noCarry
inc d
-.asm_72180
+.noCarry
ld a, [de]
- ld [$ff69], a
+ ld [rBGPD], a
dec c
- jr nz, .asm_72174
+ jr nz, .loop
ret
-Func_72187: ; 72187 (1c:6187)
+EmptyFunc5:
ret
-Func_72188: ; 72188 (1c:6188)
- ld b, $80
-.asm_7218a
- ld c, $10
-.asm_7218c
+CopySGBBorderTiles:
+; SGB tile data is stored in a 4BPP planar format.
+; Each tile is 32 bytes. The first 16 bytes contain bit planes 1 and 2, while
+; the second 16 bytes contain bit planes 3 and 4.
+; This function converts 2BPP planar data into this format by mapping
+; 2BPP colors 0-3 to 4BPP colors 0-3. 4BPP colors 4-15 are not used.
+ ld b, 128
+
+.tileLoop
+
+; Copy bit planes 1 and 2 of the tile data.
+ ld c, 16
+.copyLoop
ld a, [hli]
ld [de], a
inc de
dec c
- jr nz, .asm_7218c
- ld c, $10
+ jr nz, .copyLoop
+
+; Zero bit planes 3 and 4.
+ ld c, 16
xor a
-.asm_72195
+.zeroLoop
ld [de], a
inc de
dec c
- jr nz, .asm_72195
+ jr nz, .zeroLoop
+
dec b
- jr nz, .asm_7218a
+ jr nz, .tileLoop
ret
INCLUDE "data/sgb_packets.asm"
diff --git a/engine/pathfinding.asm b/engine/pathfinding.asm
new file mode 100644
index 00000000..ba052d38
--- /dev/null
+++ b/engine/pathfinding.asm
@@ -0,0 +1,201 @@
+FindPathToPlayer:
+ xor a
+ ld hl, hFindPathNumSteps
+ ld [hli], a ; hFindPathNumSteps
+ ld [hli], a ; hFindPathFlags
+ ld [hli], a ; hFindPathYProgress
+ ld [hl], a ; hFindPathXProgress
+ ld hl, wNPCMovementDirections2
+ ld de, $0
+.loop
+ ld a, [hFindPathYProgress]
+ ld b, a
+ ld a, [hNPCPlayerYDistance] ; Y distance in steps
+ call CalcDifference
+ ld d, a
+ and a
+ jr nz, .asm_f8da
+ ld a, [hFindPathFlags]
+ set 0, a ; current end of path matches the player's Y coordinate
+ ld [hFindPathFlags], a
+.asm_f8da
+ ld a, [hFindPathXProgress]
+ ld b, a
+ ld a, [hNPCPlayerXDistance] ; X distance in steps
+ call CalcDifference
+ ld e, a
+ and a
+ jr nz, .asm_f8ec
+ ld a, [hFindPathFlags]
+ set 1, a ; current end of path matches the player's X coordinate
+ ld [hFindPathFlags], a
+.asm_f8ec
+ ld a, [hFindPathFlags]
+ cp $3 ; has the end of the path reached the player's position?
+ jr z, .done
+; Compare whether the X distance between the player and the current of the path
+; is greater or if the Y distance is. Then, try to reduce whichever is greater.
+ ld a, e
+ cp d
+ jr c, .yDistanceGreater
+; x distance is greater
+ ld a, [hNPCPlayerRelativePosFlags]
+ bit 1, a
+ jr nz, .playerIsLeftOfNPC
+ ld d, NPC_MOVEMENT_RIGHT
+ jr .next1
+.playerIsLeftOfNPC
+ ld d, NPC_MOVEMENT_LEFT
+.next1
+ ld a, [hFindPathXProgress]
+ add 1
+ ld [hFindPathXProgress], a
+ jr .storeDirection
+.yDistanceGreater
+ ld a, [hNPCPlayerRelativePosFlags]
+ bit 0, a
+ jr nz, .playerIsAboveNPC
+ ld d, NPC_MOVEMENT_DOWN
+ jr .next2
+.playerIsAboveNPC
+ ld d, NPC_MOVEMENT_UP
+.next2
+ ld a, [hFindPathYProgress]
+ add 1
+ ld [hFindPathYProgress], a
+.storeDirection
+ ld a, d
+ ld [hli], a
+ ld a, [hFindPathNumSteps]
+ inc a
+ ld [hFindPathNumSteps], a
+ jp .loop
+.done
+ ld [hl], $ff
+ ret
+
+CalcPositionOfPlayerRelativeToNPC:
+ xor a
+ ld [hNPCPlayerRelativePosFlags], a
+ ld a, [wSpriteStateData1 + 4] ; player's sprite screen Y position in pixels
+ ld d, a
+ ld a, [wSpriteStateData1 + 6] ; player's sprite screen X position in pixels
+ ld e, a
+ ld hl, wSpriteStateData1
+ ld a, [hNPCSpriteOffset]
+ add l
+ add $4
+ ld l, a
+ jr nc, .noCarry
+ inc h
+.noCarry
+ ld a, d
+ ld b, a
+ ld a, [hli] ; NPC sprite screen Y position in pixels
+ call CalcDifference
+ jr nc, .NPCSouthOfOrAlignedWithPlayer
+.NPCNorthOfPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 0, [hl]
+ set 0, [hl]
+ pop hl
+ jr .divideYDistance
+.NPCSouthOfOrAlignedWithPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 0, [hl]
+ res 0, [hl]
+ pop hl
+.divideYDistance
+ push hl
+ ld hl, hDividend2
+ ld [hli], a
+ ld a, 16
+ ld [hli], a
+ call DivideBytes ; divide Y absolute distance by 16
+ ld a, [hl] ; quotient
+ ld [hNPCPlayerYDistance], a
+ pop hl
+ inc hl
+ ld b, e
+ ld a, [hl] ; NPC sprite screen X position in pixels
+ call CalcDifference
+ jr nc, .NPCEastOfOrAlignedWithPlayer
+.NPCWestOfPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 1, [hl]
+ set 1, [hl]
+ pop hl
+ jr .divideXDistance
+.NPCEastOfOrAlignedWithPlayer
+ push hl
+ ld hl, hNPCPlayerRelativePosFlags
+ bit 1, [hl]
+ res 1, [hl]
+ pop hl
+.divideXDistance
+ ld [hDividend2], a
+ ld a, 16
+ ld [hDivisor2], a
+ call DivideBytes ; divide X absolute distance by 16
+ ld a, [hQuotient2]
+ ld [hNPCPlayerXDistance], a
+ ld a, [hNPCPlayerRelativePosPerspective]
+ and a
+ ret z
+ ld a, [hNPCPlayerRelativePosFlags]
+ cpl
+ and $3
+ ld [hNPCPlayerRelativePosFlags], a
+ ret
+
+ConvertNPCMovementDirectionsToJoypadMasks:
+ ld a, [hNPCMovementDirections2Index]
+ ld [wNPCMovementDirections2Index], a
+ dec a
+ ld de, wSimulatedJoypadStatesEnd
+ ld hl, wNPCMovementDirections2
+ add l
+ ld l, a
+ jr nc, .loop
+ inc h
+.loop
+ ld a, [hld]
+ call ConvertNPCMovementDirectionToJoypadMask
+ ld [de], a
+ inc de
+ ld a, [hNPCMovementDirections2Index]
+ dec a
+ ld [hNPCMovementDirections2Index], a
+ jr nz, .loop
+ ret
+
+ConvertNPCMovementDirectionToJoypadMask:
+ push hl
+ ld b, a
+ ld hl, NPCMovementDirectionsToJoypadMasksTable
+.loop
+ ld a, [hli]
+ cp $ff
+ jr z, .done
+ cp b
+ jr z, .loadJoypadMask
+ inc hl
+ jr .loop
+.loadJoypadMask
+ ld a, [hl]
+.done
+ pop hl
+ ret
+
+NPCMovementDirectionsToJoypadMasksTable:
+ db NPC_MOVEMENT_UP, D_UP
+ db NPC_MOVEMENT_DOWN, D_DOWN
+ db NPC_MOVEMENT_LEFT, D_LEFT
+ db NPC_MOVEMENT_RIGHT, D_RIGHT
+ db $ff
+
+; unreferenced
+ ret
diff --git a/engine/play_time.asm b/engine/play_time.asm
index 74da9c59..a5202cc6 100755
--- a/engine/play_time.asm
+++ b/engine/play_time.asm
@@ -1,42 +1,42 @@
-TrackPlayTime: ; 18dee (6:4dee)
+TrackPlayTime:
call CountDownIgnoreInputBitReset
ld a, [wd732]
bit 0, a
ret z
- ld a, [W_PLAYTIMEMINUTES]
+ ld a, [wPlayTimeMaxed]
and a
ret nz
- ld a, [W_PLAYTIMEFRAMES]
+ ld a, [wPlayTimeFrames]
inc a
- ld [W_PLAYTIMEFRAMES], a
+ ld [wPlayTimeFrames], a
cp 60
ret nz
xor a
- ld [W_PLAYTIMEFRAMES], a
- ld a, [W_PLAYTIMESECONDS]
+ ld [wPlayTimeFrames], a
+ ld a, [wPlayTimeSeconds]
inc a
- ld [W_PLAYTIMESECONDS], a
+ ld [wPlayTimeSeconds], a
cp 60
ret nz
xor a
- ld [W_PLAYTIMESECONDS], a
- ld a, [W_PLAYTIMEMINUTES + 1]
+ ld [wPlayTimeSeconds], a
+ ld a, [wPlayTimeMinutes]
inc a
- ld [W_PLAYTIMEMINUTES + 1], a
+ ld [wPlayTimeMinutes], a
cp 60
ret nz
xor a
- ld [W_PLAYTIMEMINUTES + 1], a
- ld a, [W_PLAYTIMEHOURS + 1]
+ ld [wPlayTimeMinutes], a
+ ld a, [wPlayTimeHours]
inc a
- ld [W_PLAYTIMEHOURS + 1], a
+ ld [wPlayTimeHours], a
cp $ff
ret nz
ld a, $ff
- ld [W_PLAYTIMEMINUTES], a
+ ld [wPlayTimeMaxed], a
ret
-CountDownIgnoreInputBitReset: ; 18e36 (6:4e36)
+CountDownIgnoreInputBitReset:
ld a, [wIgnoreInputCounter]
and a
jr nz, .asm_18e40
diff --git a/engine/pokedex_rating.asm b/engine/pokedex_rating.asm
index 080025c6..f8e29e5c 100755
--- a/engine/pokedex_rating.asm
+++ b/engine/pokedex_rating.asm
@@ -1,19 +1,19 @@
-DisplayDexRating: ; 44169 (11:4169)
+DisplayDexRating:
ld hl, wPokedexSeen
ld b, wPokedexSeenEnd - wPokedexSeen
call CountSetBits
- ld a, [wd11e] ; result of CountSetBits (seen count)
- ld [$FFDB], a
+ ld a, [wNumSetBits]
+ ld [hDexRatingNumMonsSeen], a
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
- ld a, [wd11e] ; result of CountSetBits (own count)
- ld [$FFDC], a
+ ld a, [wNumSetBits]
+ ld [hDexRatingNumMonsOwned], a
ld hl, DexRatingsTable
.findRating
ld a, [hli]
ld b, a
- ld a, [$FFDC] ; number of pokemon owned
+ ld a, [hDexRatingNumMonsOwned]
cp b
jr c, .foundRating
inc hl
@@ -23,42 +23,39 @@ DisplayDexRating: ; 44169 (11:4169)
ld a, [hli]
ld h, [hl]
ld l, a ; load text pointer into hl
- ld a, [wd747]
- bit 3, a
- res 3, a
- ld [wd747], a
- jr nz, .label3
+ CheckAndResetEventA EVENT_HALL_OF_FAME_DEX_RATING
+ jr nz, .hallOfFame
push hl
ld hl, PokedexRatingText_441cc
call PrintText
pop hl
call PrintText
- callba Func_7d13b
- jp WaitForTextScrollButtonPress ; wait for button press
-.label3
- ld de, wcc5b
- ld a, [$FFDB]
+ callba PlayPokedexRatingSfx
+ jp WaitForTextScrollButtonPress
+.hallOfFame
+ ld de, wDexRatingNumMonsSeen
+ ld a, [hDexRatingNumMonsSeen]
ld [de], a
inc de
- ld a, [$FFDC]
+ ld a, [hDexRatingNumMonsOwned]
ld [de], a
inc de
-.label4
+.copyRatingTextLoop
ld a, [hli]
- cp a, $50
- jr z, .label5
+ cp a, "@"
+ jr z, .doneCopying
ld [de], a
inc de
- jr .label4
-.label5
+ jr .copyRatingTextLoop
+.doneCopying
ld [de], a
ret
-PokedexRatingText_441cc: ; 441cc (11:41cc)
+PokedexRatingText_441cc:
TX_FAR _OaksLabText_441cc
db "@"
-DexRatingsTable: ; 441d1 (11:41d1)
+DexRatingsTable:
db 10
dw PokedexRatingText_44201
db 20
@@ -92,66 +89,66 @@ DexRatingsTable: ; 441d1 (11:41d1)
db 152
dw PokedexRatingText_4424c
-PokedexRatingText_44201: ; 44201 (11:4201)
+PokedexRatingText_44201:
TX_FAR _OaksLabText_44201
db "@"
-PokedexRatingText_44206: ; 44206 (11:4206)
+PokedexRatingText_44206:
TX_FAR _OaksLabText_44206
db "@"
-PokedexRatingText_4420b: ; 4420b (11:420b)
+PokedexRatingText_4420b:
TX_FAR _OaksLabText_4420b
db "@"
-PokedexRatingText_44210: ; 44210 (11:4210)
+PokedexRatingText_44210:
TX_FAR _OaksLabText_44210
db "@"
-PokedexRatingText_44215: ; 44215 (11:4215)
+PokedexRatingText_44215:
TX_FAR _OaksLabText_44215
db "@"
-PokedexRatingText_4421a: ; 4421a (11:421a)
+PokedexRatingText_4421a:
TX_FAR _OaksLabText_4421a
db "@"
-PokedexRatingText_4421f: ; 4421f (11:421f)
+PokedexRatingText_4421f:
TX_FAR _OaksLabText_4421f
db "@"
-PokedexRatingText_44224: ; 44224 (11:4224)
+PokedexRatingText_44224:
TX_FAR _OaksLabText_44224
db "@"
-PokedexRatingText_44229: ; 44229 (11:4229)
+PokedexRatingText_44229:
TX_FAR _OaksLabText_44229
db "@"
-PokedexRatingText_4422e: ; 4422e (11:422e)
+PokedexRatingText_4422e:
TX_FAR _OaksLabText_4422e
db "@"
-PokedexRatingText_44233: ; 44233 (11:4233)
+PokedexRatingText_44233:
TX_FAR _OaksLabText_44233
db "@"
-PokedexRatingText_44238: ; 44238 (11:4238)
+PokedexRatingText_44238:
TX_FAR _OaksLabText_44238
db "@"
-PokedexRatingText_4423d: ; 4423d (11:423d)
+PokedexRatingText_4423d:
TX_FAR _OaksLabText_4423d
db "@"
-PokedexRatingText_44242: ; 44242 (11:4242)
+PokedexRatingText_44242:
TX_FAR _OaksLabText_44242
db "@"
-PokedexRatingText_44247: ; 44247 (11:4247)
+PokedexRatingText_44247:
TX_FAR _OaksLabText_44247
db "@"
-PokedexRatingText_4424c: ; 4424c (11:424c)
+PokedexRatingText_4424c:
TX_FAR _OaksLabText_4424c
db "@"
diff --git a/engine/predefs.asm b/engine/predefs.asm
index f6ecf018..605cba3a 100755
--- a/engine/predefs.asm
+++ b/engine/predefs.asm
@@ -27,10 +27,10 @@ GetPredefPointer:
add a
add e
ld e,a
- jr nc,.next
+ jr nc, .nocarry
inc d
-.next
+.nocarry
add hl,de
ld d,h
ld e,l
@@ -49,18 +49,18 @@ GetPredefPointer:
ret
-PredefPointers:: ; 4fe79 (13:7e79)
+PredefPointers::
; these are pointers to ASM routines.
; they appear to be used in overworld map scripts.
add_predef DrawPlayerHUDAndHPBar
- add_predef Func_3f0c6
- add_predef Func_3f073
+ add_predef CopyUncompressedPicToTilemap
+ add_predef AnimateSendingOutMon
add_predef ScaleSpriteByTwo
add_predef LoadMonBackPic
- add_predef Func_79aba
- add_predef LoadMissableObjects
+ add_predef CopyDownscaledMonTiles
+ dbw $03,JumpMoveEffect ; wrong bank
add_predef HealParty
- add_predef MoveAnimation; 08 play move animation
+ add_predef MoveAnimation
add_predef DivideBCDPredef
add_predef DivideBCDPredef2
add_predef AddBCDPredef
@@ -80,15 +80,15 @@ PredefPointers:: ; 4fe79 (13:7e79)
add_predef LoadTilesetHeader
add_predef LearnMoveFromLevelUp
add_predef LearnMove
- add_predef IsItemInBag_
- dbw $03,CheckForHiddenObjectOrBookshelfOrCardKeyDoor ; for these two, the bank number is actually 0
- dbw $03,GiveItem
+ add_predef GetQuantityOfItemInBag
+ dbw $03,CheckForHiddenObjectOrBookshelfOrCardKeyDoor ; home bank
+ dbw $03,GiveItem ; home bank
add_predef ChangeBGPalColor0_4Frames
add_predef FindPathToPlayer
- add_predef Func_480ff
+ add_predef PredefShakeScreenVertically
add_predef CalcPositionOfPlayerRelativeToNPC
add_predef ConvertNPCMovementDirectionsToJoypadMasks
- add_predef Func_48125
+ add_predef PredefShakeScreenHorizontally
add_predef UpdateHPBar
add_predef HPBarLength
add_predef Diploma_TextBoxBorder
@@ -103,7 +103,7 @@ PredefPointers:: ; 4fe79 (13:7e79)
add_predef BattleTransition
add_predef CopyTileIDsFromList
add_predef PlayIntro
- add_predef Func_79869
+ add_predef GetMoveSoundB
add_predef FlashScreen
add_predef GetTileAndCoordsInFrontOfPlayer
add_predef StatusScreen
@@ -111,7 +111,7 @@ PredefPointers:: ; 4fe79 (13:7e79)
add_predef InternalClockTradeAnim
add_predef TrainerEngage
add_predef IndexToPokedex
- add_predef Predef3B; 3B display pic?
+ add_predef DisplayPicCenteredOrUpperRight
add_predef UsedCut
add_predef ShowPokedexData
add_predef WriteMonMoves
@@ -121,22 +121,22 @@ PredefPointers:: ; 4fe79 (13:7e79)
add_predef SetPartyMonTypes
add_predef CanLearnTM
add_predef TMToMove
- add_predef Func_71ddf
- add_predef StarterDex ; 46
+ add_predef _RunPaletteCommand
+ add_predef StarterDex
add_predef _AddPartyMon
add_predef UpdateHPBar2
add_predef DrawEnemyHUDAndHPBar
add_predef LoadTownMap_Nest
add_predef PrintMonType
- add_predef EmotionBubble; 4C player exclamation
+ add_predef EmotionBubble
add_predef EmptyFunc3; return immediately
add_predef AskName
add_predef PewterGuys
add_predef SaveSAVtoSRAM2
- add_predef LoadSAVCheckSum2
+ add_predef LoadSAV2
add_predef LoadSAV
add_predef SaveSAVtoSRAM1
- add_predef DoInGameTradeDialogue ; 54 initiate trade
+ add_predef DoInGameTradeDialogue
add_predef HallOfFamePC
add_predef DisplayDexRating
dbw $1E, _LeaveMapAnim ; wrong bank
@@ -144,10 +144,10 @@ PredefPointers:: ; 4fe79 (13:7e79)
add_predef GetTileTwoStepsInFrontOfPlayer
add_predef CheckForCollisionWhenPushingBoulder
add_predef PrintStrengthTxt
- add_predef PickupItem
+ add_predef PickUpItem
add_predef PrintMoveType
add_predef LoadMovePPs
- add_predef DrawHP ; 5F
+ add_predef DrawHP
add_predef DrawHP2
- add_predef Func_1c9c6
+ add_predef DisplayElevatorFloorMenu
add_predef OaksAideScript
diff --git a/engine/predefs12.asm b/engine/predefs12.asm
index 90032a14..95f0ea25 100755
--- a/engine/predefs12.asm
+++ b/engine/predefs12.asm
@@ -1,65 +1,71 @@
; b = new colour for BG colour 0 (usually white) for 4 frames
-ChangeBGPalColor0_4Frames: ; 480eb (12:40eb)
+ChangeBGPalColor0_4Frames:
call GetPredefRegisters
ld a, [rBGP]
or b
ld [rBGP], a
- ld c, $4
+ ld c, 4
call DelayFrames
ld a, [rBGP]
and %11111100
ld [rBGP], a
ret
-Func_480ff: ; 480ff (12:40ff)
+PredefShakeScreenVertically:
+; Moves the window down and then back in a sequence of progressively smaller
+; numbers of pixels, starting at b.
call GetPredefRegisters
- ld a, $1
- ld [wd0a0], a
+ ld a, 1
+ ld [wDisableVBlankWYUpdate], a
xor a
-.asm_48108
- ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
- call Func_48119
- call Func_48119
+.loop
+ ld [$ff96], a
+ call .MutateWY
+ call .MutateWY
dec b
ld a, b
- jr nz, .asm_48108
+ jr nz, .loop
xor a
- ld [wd0a0], a
+ ld [wDisableVBlankWYUpdate], a
ret
-Func_48119: ; 48119 (12:4119)
- ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND)
+.MutateWY
+ ld a, [$ff96]
xor b
- ld [H_NUMTOPRINT], a ; $ff96 (aliases: H_MULTIPLICAND)
- ld [rWY], a ; $ff4a
- ld c, $3
+ ld [$ff96], a
+ ld [rWY], a
+ ld c, 3
jp DelayFrames
-Func_48125: ; 48125 (12:4125)
+PredefShakeScreenHorizontally:
+; Moves the window right and then back in a sequence of progressively smaller
+; numbers of pixels, starting at b.
call GetPredefRegisters
xor a
-.asm_48129
+.loop
ld [$ff97], a
- call Func_4813f
- ld c, $1
+ call .MutateWX
+ ld c, 1
call DelayFrames
- call Func_4813f
+ call .MutateWX
dec b
ld a, b
- jr nz, .asm_48129
- ld a, $7
- ld [rWX], a ; $ff4b
+ jr nz, .loop
+
+; restore normal WX
+ ld a, 7
+ ld [rWX], a
ret
-Func_4813f: ; 4813f (12:413f)
+.MutateWX
ld a, [$ff97]
xor b
ld [$ff97], a
bit 7, a
- jr z, .asm_48149
- xor a
-.asm_48149
- add $7
- ld [rWX], a ; $ff4b
- ld c, $4
+ jr z, .skipZeroing
+ xor a ; zero a if it's negative
+.skipZeroing
+ add 7
+ ld [rWX], a
+ ld c, 4
jp DelayFrames
diff --git a/engine/predefs17.asm b/engine/predefs17.asm
index 74977ee8..21289c6a 100755
--- a/engine/predefs17.asm
+++ b/engine/predefs17.asm
@@ -1,9 +1,9 @@
; this function temporarily makes the starters (and Ivysaur) seen
; so that the full Pokedex information gets displayed in Oak's lab
-StarterDex: ; 5c0dc (17:40dc)
+StarterDex:
ld a, %01001011 ; set starter flags
- ld [wPokedexOwned], a ; wPokedexOwned
+ ld [wPokedexOwned], a
predef ShowPokedexData
xor a ; unset starter flags
- ld [wPokedexOwned], a ; wPokedexOwned
+ ld [wPokedexOwned], a
ret
diff --git a/engine/predefs17_2.asm b/engine/predefs17_2.asm
index a2dac120..e9235f13 100755
--- a/engine/predefs17_2.asm
+++ b/engine/predefs17_2.asm
@@ -1,5 +1,5 @@
; updates the types of a party mon (pointed to in hl) to the ones of the mon specified in wd11e
-SetPartyMonTypes: ; 5db5e (17:5b5e)
+SetPartyMonTypes:
call GetPredefRegisters
ld bc, wPartyMon1Type - wPartyMon1 ; $5
add hl, bc
@@ -8,8 +8,8 @@ SetPartyMonTypes: ; 5db5e (17:5b5e)
push hl
call GetMonHeader
pop hl
- ld a, [W_MONHTYPE1]
+ ld a, [wMonHType1]
ld [hli], a
- ld a, [W_MONHTYPE2]
+ ld a, [wMonHType2]
ld [hl], a
ret
diff --git a/engine/predefs7.asm b/engine/predefs7.asm
index 9786c097..752bdd1a 100755
--- a/engine/predefs7.asm
+++ b/engine/predefs7.asm
@@ -1,30 +1,30 @@
-Func_1c9c6: ; 1c9c6 (7:49c6)
+DisplayElevatorFloorMenu:
ld hl, WhichFloorText
call PrintText
- ld hl, wStringBuffer2 + 11
+ ld hl, wItemList
ld a, l
- ld [wList], a
+ ld [wListPointer], a
ld a, h
- ld [wList + 1], a
+ ld [wListPointer + 1], a
ld a, [wListScrollOffset]
push af
xor a
ld [wCurrentMenuItem], a
ld [wListScrollOffset], a
- ld [wcf93], a
- ld a, $4
+ ld [wPrintItemPrices], a
+ ld a, SPECIALLISTMENU
ld [wListMenuID], a
call DisplayListMenuID
pop bc
ld a, b
ld [wListScrollOffset], a
ret c
- ld hl, wd126
+ ld hl, wCurrentMapScriptFlags
set 7, [hl]
- ld hl, wcc5b
+ ld hl, wElevatorWarpMaps
ld a, [wWhichPokemon]
add a
- ld d, $0
+ ld d, 0
ld e, a
add hl, de
ld a, [hli]
@@ -32,17 +32,17 @@ Func_1c9c6: ; 1c9c6 (7:49c6)
ld a, [hl]
ld c, a
ld hl, wWarpEntries
- call Func_1ca0d
+ call .UpdateWarp
-Func_1ca0d: ; 1ca0d (7:4a0d)
+.UpdateWarp
inc hl
inc hl
ld a, b
- ld [hli], a
+ ld [hli], a ; destination warp ID
ld a, c
- ld [hli], a
+ ld [hli], a ; destination map ID
ret
-WhichFloorText: ; 1ca14 (7:4a14)
+WhichFloorText:
TX_FAR _WhichFloorText
db "@"
diff --git a/engine/print_waiting_text.asm b/engine/print_waiting_text.asm
new file mode 100644
index 00000000..7a95da2a
--- /dev/null
+++ b/engine/print_waiting_text.asm
@@ -0,0 +1,20 @@
+PrintWaitingText:
+ coord hl, 3, 10
+ ld b, $1
+ ld c, $b
+ ld a, [wIsInBattle]
+ and a
+ jr z, .asm_4c17
+ call TextBoxBorder
+ jr .asm_4c1a
+.asm_4c17
+ call CableClub_TextBoxBorder
+.asm_4c1a
+ coord hl, 4, 11
+ ld de, WaitingText
+ call PlaceString
+ ld c, 50
+ jp DelayFrames
+
+WaitingText:
+ db "Waiting...!@"
diff --git a/engine/remove_pokemon.asm b/engine/remove_pokemon.asm
new file mode 100644
index 00000000..1fcb5d09
--- /dev/null
+++ b/engine/remove_pokemon.asm
@@ -0,0 +1,95 @@
+_RemovePokemon:
+ ld hl, wPartyCount
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .asm_7b74
+ ld hl, wNumInBox
+.asm_7b74
+ ld a, [hl]
+ dec a
+ ld [hli], a
+ ld a, [wWhichPokemon]
+ ld c, a
+ ld b, $0
+ add hl, bc
+ ld e, l
+ ld d, h
+ inc de
+.asm_7b81
+ ld a, [de]
+ inc de
+ ld [hli], a
+ inc a
+ jr nz, .asm_7b81
+ ld hl, wPartyMonOT
+ ld d, $5
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .asm_7b97
+ ld hl, wBoxMonOT
+ ld d, $13
+.asm_7b97
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld a, [wWhichPokemon]
+ cp d
+ jr nz, .asm_7ba6
+ ld [hl], $ff
+ ret
+.asm_7ba6
+ ld d, h
+ ld e, l
+ ld bc, NAME_LENGTH
+ add hl, bc
+ ld bc, wPartyMonNicks
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .asm_7bb8
+ ld bc, wBoxMonNicks
+.asm_7bb8
+ call CopyDataUntil
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .asm_7bcd
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1
+.asm_7bcd
+ ld a, [wWhichPokemon]
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .asm_7be4
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc
+ ld bc, wBoxMonOT
+ jr .asm_7beb
+.asm_7be4
+ ld bc, wPartyMon2 - wPartyMon1
+ add hl, bc
+ ld bc, wPartyMonOT
+.asm_7beb
+ call CopyDataUntil
+ ld hl, wPartyMonNicks
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .asm_7bfa
+ ld hl, wBoxMonNicks
+.asm_7bfa
+ ld bc, NAME_LENGTH
+ ld a, [wWhichPokemon]
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld bc, NAME_LENGTH
+ add hl, bc
+ ld bc, wPokedexOwned
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .asm_7c15
+ ld bc, wBoxMonNicksEnd
+.asm_7c15
+ jp CopyDataUntil
diff --git a/engine/save.asm b/engine/save.asm
index d3127f04..4fb2c4c8 100755
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -1,14 +1,14 @@
-LoadSAV: ; 735e8 (1c:75e8)
+LoadSAV:
;(if carry -> write
;"the file data is destroyed")
call ClearScreen
call LoadFontTilePatterns
call LoadTextBoxTilePatterns
- call LoadSAVCheckSum
+ call LoadSAV0
jr c, .badsum
- call LoadSAVCheckSum1
+ call LoadSAV1
jr c, .badsum
- call LoadSAVCheckSum2
+ call LoadSAV2
jr c, .badsum
ld a, $2 ; good checksum
jr .goodsum
@@ -18,129 +18,132 @@ LoadSAV: ; 735e8 (1c:75e8)
set 6, [hl]
ld hl, FileDataDestroyedText
call PrintText
- ld c, $64
+ ld c, 100
call DelayFrames
pop hl
res 6, [hl]
ld a, $1 ; bad checksum
.goodsum
- ld [wd088], a ; checksum flag
+ ld [wSaveFileStatus], a
ret
-FileDataDestroyedText: ; 7361e (1c:761e)
+FileDataDestroyedText:
TX_FAR _FileDataDestroyedText
db "@"
-LoadSAVCheckSum: ; 73623 (1c:7623)
+LoadSAV0:
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
- ld bc, $f8b ; but here checks the full SAV
+ ld hl, sPlayerName ; hero name located in SRAM
+ ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [sMainDataCheckSum] ; SAV's checksum
cp c
- jp z, .Func_73652
- ld hl, $a598
- ld bc, $f8b
+ jp z, .checkSumsMatched
+
+; If the computed checksum didn't match the saved on, try again.
+ ld hl, sPlayerName
+ ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [sMainDataCheckSum] ; SAV's checksum
cp c
jp nz, SAVBadCheckSum
-.Func_73652 ; 73652 (1c:7652)
- ld hl, $a598
- ld de, wPlayerName ; wd158
- ld bc, $b
+.checkSumsMatched
+ ld hl, sPlayerName
+ ld de, wPlayerName
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, $a5a3
- ld de, wPokedexOwned
- ld bc, $789
+ ld hl, sMainData
+ ld de, wMainDataStart
+ ld bc, wMainDataEnd - wMainDataStart
call CopyData
- ld hl, W_CURMAPTILESET
+ ld hl, wCurMapTileset
set 7, [hl]
- ld hl, $ad2c
- ld de, wSpriteStateData1
- ld bc, $200
+ ld hl, sSpriteData
+ ld de, wSpriteDataStart
+ ld bc, wSpriteDataEnd - wSpriteDataStart
call CopyData
- ld a, [$b522]
+ ld a, [sTilesetType]
ld [hTilesetType], a
- ld hl, $b0c0
- ld de, W_NUMINBOX
- ld bc, wBoxMonNicksEnd - W_NUMINBOX
+ ld hl, sCurBoxData
+ ld de, wBoxDataStart
+ ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
and a
jp SAVGoodChecksum
-LoadSAVCheckSum1: ; 73690 (1c:7690)
+LoadSAV1:
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
- ld bc, $f8b ; but here checks the full SAV
+ ld hl, sPlayerName ; hero name located in SRAM
+ ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [sMainDataCheckSum] ; SAV's checksum
cp c
jr nz, SAVBadCheckSum
- ld hl, $b0c0
- ld de, W_NUMINBOX
- ld bc, wBoxMonNicksEnd - W_NUMINBOX
+ ld hl, sCurBoxData
+ ld de, wBoxDataStart
+ ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
and a
jp SAVGoodChecksum
-LoadSAVCheckSum2: ; 736bd (1c:76bd)
+LoadSAV2:
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, $a598 ; hero name located in SRAM
- ld bc, $f8b ; but here checks the full SAV
+ ld hl, sPlayerName ; hero name located in SRAM
+ ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
call SAVCheckSum
ld c, a
- ld a, [$b523] ; SAV's checksum
+ ld a, [sMainDataCheckSum] ; SAV's checksum
cp c
jp nz, SAVBadCheckSum
- ld hl, $af2c
- ld de, wPartyCount ; wPartyCount
- ld bc, $194
+ ld hl, sPartyData
+ ld de, wPartyDataStart
+ ld bc, wPartyDataEnd - wPartyDataStart
call CopyData
- ld hl, $a5a3
- ld de, wPokedexOwned ; wPokedexOwned
+ ld hl, sMainData
+ ld de, wPokedexOwned
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
and a
jp SAVGoodChecksum
-SAVBadCheckSum: ; 736f7 (1c:76f7)
+SAVBadCheckSum:
scf
-SAVGoodChecksum: ; 736f8 (1c:76f8)
+SAVGoodChecksum:
ld a, $0
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
ret
-Func_73701: ; 0x73701
- call LoadSAVCheckSum
- call LoadSAVCheckSum1
- jp LoadSAVCheckSum2
+LoadSAVIgnoreBadCheckSum:
+; unused function that loads save data and ignores bad checksums
+ call LoadSAV0
+ call LoadSAV1
+ jp LoadSAV2
-SaveSAV: ;$770a
+SaveSAV:
callba PrintSaveScreenText
ld hl,WouldYouLikeToSaveText
call SaveSAVConfirm
and a ;|0 = Yes|1 = No|
ret nz
- ld a,[wd088]
+ ld a,[wSaveFileStatus]
dec a
jr z,.save
call SAVCheckRandomID
@@ -149,135 +152,135 @@ SaveSAV: ;$770a
call SaveSAVConfirm
and a
ret nz
-.save ;$772d
- call SaveSAVtoSRAM ;$7848
- hlCoord 1, 13
- ld bc,$0412
- call ClearScreenArea ; clear area 4x12 starting at 13,1
- hlCoord 1, 14
+.save
+ call SaveSAVtoSRAM
+ coord hl, 1, 13
+ lb bc, 4, 18
+ call ClearScreenArea
+ coord hl, 1, 14
ld de,NowSavingString
call PlaceString
- ld c,$78
+ ld c,120
call DelayFrames
ld hl,GameSavedText
call PrintText
- ld a, (SFX_02_5d - SFX_Headers_02) / 3 ;sound for saved game
+ ld a, SFX_SAVE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
- ld c,$1e
+ ld c,30
jp DelayFrames
NowSavingString:
db "Now saving...@"
-SaveSAVConfirm: ; 73768 (1c:7768)
+SaveSAVConfirm:
call PrintText
- hlCoord 0, 7
- ld bc,$0801
+ coord hl, 0, 7
+ lb bc, 8, 1
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
ld a,[wCurrentMenuItem]
ret
-WouldYouLikeToSaveText: ; 0x7377d
+WouldYouLikeToSaveText:
TX_FAR _WouldYouLikeToSaveText
db "@"
-GameSavedText: ; 73782 (1c:7782)
+GameSavedText:
TX_FAR _GameSavedText
db "@"
-OlderFileWillBeErasedText: ; 73787 (1c:7787)
+OlderFileWillBeErasedText:
TX_FAR _OlderFileWillBeErasedText
db "@"
-SaveSAVtoSRAM0: ; 7378c (1c:778c)
+SaveSAVtoSRAM0:
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wPlayerName
- ld de, $a598
- ld bc, $b
+ ld de, sPlayerName
+ ld bc, NAME_LENGTH
call CopyData
- ld hl, wPokedexOwned
- ld de, $a5a3
- ld bc, W_NUMINBOX - wPokedexOwned
+ ld hl, wMainDataStart
+ ld de, sMainData
+ ld bc, wMainDataEnd - wMainDataStart
call CopyData
- ld hl, wSpriteStateData1
- ld de, $ad2c
- ld bc, $200
+ ld hl, wSpriteDataStart
+ ld de, sSpriteData
+ ld bc, wSpriteDataEnd - wSpriteDataStart
call CopyData
- ld hl, W_NUMINBOX
- ld de, $b0c0
- ld bc, wBoxMonNicksEnd - W_NUMINBOX
+ ld hl, wBoxDataStart
+ ld de, sCurBoxData
+ ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
ld a, [hTilesetType]
- ld [$b522], a
- ld hl, $a598
- ld bc, $f8b
+ ld [sTilesetType], a
+ ld hl, sPlayerName
+ ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
- ld [$b523], a
+ ld [sMainDataCheckSum], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
ret
-SaveSAVtoSRAM1: ; 737e2 (1c:77e2)
+SaveSAVtoSRAM1:
; stored pokémon
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, W_NUMINBOX
- ld de, $b0c0
- ld bc, wBoxMonNicksEnd - W_NUMINBOX
+ ld hl, wBoxDataStart
+ ld de, sCurBoxData
+ ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
- ld hl, $a598
- ld bc, $f8b
+ ld hl, sPlayerName
+ ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
- ld [$b523], a
+ ld [sMainDataCheckSum], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
ret
-SaveSAVtoSRAM2: ; 7380f (1c:780f)
+SaveSAVtoSRAM2:
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
- ld hl, wPartyCount
- ld de, $af2c
- ld bc, wPokedexOwned - wPartyCount
+ ld hl, wPartyDataStart
+ ld de, sPartyData
+ ld bc, wPartyDataEnd - wPartyDataStart
call CopyData
ld hl, wPokedexOwned ; pokédex only
- ld de, $a5a3
+ ld de, sMainData
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
- ld hl, $a598
- ld bc, $f8b
+ ld hl, sPlayerName
+ ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
- ld [$b523], a
+ ld [sMainDataCheckSum], a
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
ret
-SaveSAVtoSRAM: ; 73848 (1c:7848)
+SaveSAVtoSRAM:
ld a, $2
- ld [wd088], a
+ ld [wSaveFileStatus], a
call SaveSAVtoSRAM0
call SaveSAVtoSRAM1
jp SaveSAVtoSRAM2
-SAVCheckSum: ; 73856 (1c:7856)
+SAVCheckSum:
;Check Sum (result[1 byte] is complemented)
- ld d, $0
+ ld d, 0
.loop
ld a, [hli]
add d
@@ -290,35 +293,37 @@ SAVCheckSum: ; 73856 (1c:7856)
cpl
ret
-Func_73863: ; 73863 (1c:7863)
- ld hl, $a000
- ld de, $ba4d
- ld b, $6
-.asm_7386b
+CalcIndividualBoxCheckSums:
+ ld hl, sBox1 ; sBox7
+ ld de, sBank2IndividualBoxChecksums ; sBank3IndividualBoxChecksums
+ ld b, NUM_BOXES / 2
+.loop
push bc
push de
- ld bc, $462
+ ld bc, wBoxDataEnd - wBoxDataStart
call SAVCheckSum
pop de
ld [de], a
inc de
pop bc
dec b
- jr nz, .asm_7386b
+ jr nz, .loop
ret
-Func_7387b: ; 7387b (1c:787b)
- ld hl, PointerTable_73895 ; $7895
- ld a, [wd5a0]
+GetBoxSRAMLocation:
+; in: a = box num
+; out: b = box SRAM bank, hl = pointer to start of box
+ ld hl, BoxSRAMPointerTable
+ ld a, [wCurrentBoxNum]
and $7f
- cp $6
- ld b, $2
- jr c, .asm_7388c
+ cp NUM_BOXES / 2
+ ld b, 2
+ jr c, .next
inc b
- sub $6
-.asm_7388c
+ sub NUM_BOXES / 2
+.next
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
add hl, de
ld a, [hli]
@@ -326,45 +331,45 @@ Func_7387b: ; 7387b (1c:787b)
ld l, a
ret
-PointerTable_73895: ; 73895 (1c:7895)
- dw $A000
- dw $A462
- dw $A8C4
- dw $AD26
- dw $B188
- dw $B5EA
+BoxSRAMPointerTable:
+ dw sBox1 ; sBox7
+ dw sBox2 ; sBox8
+ dw sBox3 ; sBox9
+ dw sBox4 ; sBox10
+ dw sBox5 ; sBox11
+ dw sBox6 ; sBox12
-ChangeBox:: ; 738a1 (1c:78a1)
+ChangeBox::
ld hl, WhenYouChangeBoxText
call PrintText
call YesNoChoice
ld a, [wCurrentMenuItem]
and a
ret nz ; return if No was chosen
- ld hl, wd5a0
- bit 7, [hl]
- call z, Func_73a29
- call Func_7393f
+ ld hl, wCurrentBoxNum
+ bit 7, [hl] ; is it the first time player is changing the box?
+ call z, EmptyAllSRAMBoxes ; if so, empty all boxes in SRAM
+ call DisplayChangeBoxMenu
call UpdateSprites
ld hl, hFlags_0xFFF6
set 1, [hl]
call HandleMenuInput
ld hl, hFlags_0xFFF6
res 1, [hl]
- bit 1, a
+ bit 1, a ; pressed b
ret nz
- call Func_7387b
+ call GetBoxSRAMLocation
ld e, l
ld d, h
- ld hl, W_NUMINBOX
- call Func_7390e
+ ld hl, wBoxDataStart
+ call CopyBoxToOrFromSRAM ; copy old box from WRAM to SRAM
ld a, [wCurrentMenuItem]
set 7, a
- ld [wd5a0], a
- call Func_7387b
- ld de, W_NUMINBOX
- call Func_7390e
- ld hl, W_MAPTEXTPTR
+ ld [wCurrentBoxNum], a
+ call GetBoxSRAMLocation
+ ld de, wBoxDataStart
+ call CopyBoxToOrFromSRAM ; copy new box from SRAM to WRAM
+ ld hl, wMapTextPtr
ld de, wChangeBoxSavedMapTextPointer
ld a, [hli]
ld [de], a
@@ -375,16 +380,17 @@ ChangeBox:: ; 738a1 (1c:78a1)
call SaveSAVtoSRAM
ld hl, wChangeBoxSavedMapTextPointer
call SetMapTextPointer
- ld a, (SFX_02_5d - SFX_Headers_02) / 3
+ ld a, SFX_SAVE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
ret
-WhenYouChangeBoxText: ; 73909 (1c:7909)
+WhenYouChangeBoxText:
TX_FAR _WhenYouChangeBoxText
db "@"
-Func_7390e: ; 7390e (1c:790e)
+CopyBoxToOrFromSRAM:
+; copy an entire box from hl to de with b as the SRAM bank
push hl
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
@@ -392,99 +398,102 @@ Func_7390e: ; 7390e (1c:790e)
ld [MBC1SRamBankingMode], a
ld a, b
ld [MBC1SRamBank], a
- ld bc, $462
+ ld bc, wBoxDataEnd - wBoxDataStart
call CopyData
pop hl
+
+; mark the memory that the box was copied from as am empty box
xor a
ld [hli], a
dec a
ld [hl], a
- ld hl, $a000
- ld bc, $1a4c
+
+ ld hl, sBox1 ; sBox7
+ ld bc, sBank2AllBoxesChecksum - sBox1
call SAVCheckSum
- ld [$ba4c], a
- call Func_73863
+ ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum
+ call CalcIndividualBoxCheckSums
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
ret
-Func_7393f: ; 7393f (1c:793f)
+DisplayChangeBoxMenu:
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
- ld a, $3
- ld [wMenuWatchedKeys], a ; wMenuWatchedKeys
- ld a, $b
- ld [wMaxMenuItem], a ; wMaxMenuItem
- ld a, $1
- ld [wTopMenuItemY], a ; wTopMenuItemY
- ld a, $c
- ld [wTopMenuItemX], a ; wTopMenuItemX
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, A_BUTTON | B_BUTTON
+ ld [wMenuWatchedKeys], a
+ ld a, 11
+ ld [wMaxMenuItem], a
+ ld a, 1
+ ld [wTopMenuItemY], a
+ ld a, 12
+ ld [wTopMenuItemX], a
xor a
- ld [wcc37], a
- ld a, [wd5a0]
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld a, [wCurrentBoxNum]
and $7f
- ld [wCurrentMenuItem], a ; wCurrentMenuItem
- ld [wLastMenuItem], a ; wLastMenuItem
- ld hl, wTileMap
- ld b, $2
- ld c, $9
+ ld [wCurrentMenuItem], a
+ ld [wLastMenuItem], a
+ coord hl, 0, 0
+ ld b, 2
+ ld c, 9
call TextBoxBorder
ld hl, ChooseABoxText
call PrintText
- hlCoord 11, 0
- ld b, $c
- ld c, $7
+ coord hl, 11, 0
+ ld b, 12
+ ld c, 7
call TextBoxBorder
ld hl, hFlags_0xFFF6
set 2, [hl]
- ld de, BoxNames ; $79d9
- hlCoord 13, 1
+ ld de, BoxNames
+ coord hl, 13, 1
call PlaceString
ld hl, hFlags_0xFFF6
res 2, [hl]
- ld a, [wd5a0]
+ ld a, [wCurrentBoxNum]
and $7f
cp 9
- jr c, .asm_739a6
+ jr c, .singleDigitBoxNum
sub 9
- hlCoord 8, 2
+ coord hl, 8, 2
ld [hl], "1"
add "0"
- jr .asm_739a8
-.asm_739a6
+ jr .next
+.singleDigitBoxNum
add "1"
-.asm_739a8
+.next
Coorda 9, 2
- hlCoord 1, 2
+ coord hl, 1, 2
ld de, BoxNoText
call PlaceString
- call Func_73a84
- hlCoord 18, 1
- ld de, wWhichTrade ; wWhichTrade
- ld bc, $14
+ call GetMonCountsForAllBoxes
+ coord hl, 18, 1
+ ld de, wBoxMonCounts
+ ld bc, SCREEN_WIDTH
ld a, $c
-.asm_739c2
+.loop
push af
ld a, [de]
- and a
- jr z, .asm_739c9
- ld [hl], $78
-.asm_739c9
+ and a ; is the box empty?
+ jr z, .skipPlacingPokeball
+ ld [hl], $78 ; place pokeball tile next to box name if box not empty
+.skipPlacingPokeball
add hl, bc
inc de
pop af
dec a
- jr nz, .asm_739c2
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ jr nz, .loop
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
ret
-ChooseABoxText: ; 739d4 (1c:79d4)
+ChooseABoxText:
TX_FAR _ChooseABoxText
db "@"
-BoxNames: ; 739d9 (1c:79d9)
+BoxNames:
db "BOX 1"
next "BOX 2"
next "BOX 3"
@@ -498,54 +507,57 @@ BoxNames: ; 739d9 (1c:79d9)
next "BOX11"
next "BOX12@"
-BoxNoText: ; 73a21 (1c:7a21)
+BoxNoText:
db "BOX No.@"
-Func_73a29: ; 73a29 (1c:7a29)
+EmptyAllSRAMBoxes:
+; marks all boxes in SRAM as empty (initialisation for the first time the
+; player changes the box)
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
ld [MBC1SRamBankingMode], a
- ld a, $2
+ ld a, 2
ld [MBC1SRamBank], a
- call Func_73a4b
- ld a, $3
+ call EmptySRAMBoxesInBank
+ ld a, 3
ld [MBC1SRamBank], a
- call Func_73a4b
+ call EmptySRAMBoxesInBank
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
ret
-Func_73a4b: ; 73a4b (1c:7a4b)
- ld hl, $a000
- call Func_73a7f
- ld hl, $a462
- call Func_73a7f
- ld hl, $a8c4
- call Func_73a7f
- ld hl, $ad26
- call Func_73a7f
- ld hl, $b188
- call Func_73a7f
- ld hl, $b5ea
- call Func_73a7f
- ld hl, $a000
- ld bc, $1a4c
+EmptySRAMBoxesInBank:
+; marks every box in the current SRAM bank as empty
+ ld hl, sBox1 ; sBox7
+ call EmptySRAMBox
+ ld hl, sBox2 ; sBox8
+ call EmptySRAMBox
+ ld hl, sBox3 ; sBox9
+ call EmptySRAMBox
+ ld hl, sBox4 ; sBox10
+ call EmptySRAMBox
+ ld hl, sBox5 ; sBox11
+ call EmptySRAMBox
+ ld hl, sBox6 ; sBox12
+ call EmptySRAMBox
+ ld hl, sBox1 ; sBox7
+ ld bc, sBank2AllBoxesChecksum - sBox1
call SAVCheckSum
- ld [$ba4c], a
- call Func_73863
+ ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum
+ call CalcIndividualBoxCheckSums
ret
-Func_73a7f: ; 73a7f (1c:7a7f)
+EmptySRAMBox:
xor a
ld [hli], a
dec a
ld [hl], a
ret
-Func_73a84: ; 73a84 (1c:7a84)
- ld hl, wWhichTrade ; wWhichTrade
+GetMonCountsForAllBoxes:
+ ld hl, wBoxMonCounts
push hl
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
@@ -553,58 +565,61 @@ Func_73a84: ; 73a84 (1c:7a84)
ld [MBC1SRamBankingMode], a
ld a, $2
ld [MBC1SRamBank], a
- call Func_73ab8
+ call GetMonCountsForBoxesInBank
ld a, $3
ld [MBC1SRamBank], a
- call Func_73ab8
+ call GetMonCountsForBoxesInBank
xor a
ld [MBC1SRamBankingMode], a
ld [MBC1SRamEnable], a
pop hl
- ld a, [wd5a0]
+
+; copy the count for the current box from WRAM
+ ld a, [wCurrentBoxNum]
and $7f
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
- ld a, [W_NUMINBOX] ; wda80
+ ld a, [wNumInBox]
ld [hl], a
+
ret
-Func_73ab8: ; 73ab8 (1c:7ab8)
- ld a, [$a000]
+GetMonCountsForBoxesInBank:
+ ld a, [sBox1] ; sBox7
ld [hli], a
- ld a, [$a462]
+ ld a, [sBox2] ; sBox8
ld [hli], a
- ld a, [$a8c4]
+ ld a, [sBox3] ; sBox9
ld [hli], a
- ld a, [$ad26]
+ ld a, [sBox4] ; sBox10
ld [hli], a
- ld a, [$b188]
+ ld a, [sBox5] ; sBox11
ld [hli], a
- ld a, [$b5ea]
+ ld a, [sBox6] ; sBox12
ld [hli], a
ret
-SAVCheckRandomID: ;$7ad1
+SAVCheckRandomID:
;checks if Sav file is the same by checking player's name 1st letter ($a598)
; and the two random numbers generated at game beginning
-;(which are stored at wPlayerID)
+;(which are stored at wPlayerID)s
ld a,$0a
- ld [$0000],a
+ ld [MBC1SRamEnable],a
ld a,$01
ld [MBC1SRamBankingMode],a
ld [MBC1SRamBank],a
- ld a,[$a598]
+ ld a,[sPlayerName]
and a
jr z,.next
- ld hl,$a598
- ld bc,$0f8b
+ ld hl,sPlayerName
+ ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
ld c,a
- ld a,[$b523]
+ ld a,[sMainDataCheckSum]
cp c
jr nz,.next
- ld hl,$a605
+ ld hl,sMainData + 98 ; player ID
ld a,[hli]
ld h,[hl]
ld l,a
@@ -616,43 +631,45 @@ SAVCheckRandomID: ;$7ad1
.next
ld a,$00
ld [MBC1SRamBankingMode],a
- ld [$0000],a
+ ld [MBC1SRamEnable],a
ret
-SaveHallOfFameTeams: ; 73b0d (1c:7b0d)
- ld a, [wd5a2]
+SaveHallOfFameTeams:
+ ld a, [wNumHoFTeams]
dec a
- cp NUM_HOF_TEAMS
- jr nc, .asm_73b28
+ cp HOF_TEAM_CAPACITY
+ jr nc, .shiftHOFTeams
ld hl, sHallOfFame
ld bc, HOF_TEAM
call AddNTimes
ld e, l
ld d, h
- ld hl, wcc5b
+ ld hl, wHallOfFame
ld bc, HOF_TEAM
jr HallOfFame_Copy
-.asm_73b28
+.shiftHOFTeams
+; if the space designated for HOF teams is full, then shift all HOF teams to the next slot, making space for the new HOF team
+; this deletes the last HOF team though
ld hl, sHallOfFame + HOF_TEAM
ld de, sHallOfFame
- ld bc, HOF_TEAM * (NUM_HOF_TEAMS - 1)
+ ld bc, HOF_TEAM * (HOF_TEAM_CAPACITY - 1)
call HallOfFame_Copy
- ld hl, wcc5b
- ld de, sHallOfFame + HOF_TEAM * (NUM_HOF_TEAMS - 1)
+ ld hl, wHallOfFame
+ ld de, sHallOfFame + HOF_TEAM * (HOF_TEAM_CAPACITY - 1)
ld bc, HOF_TEAM
jr HallOfFame_Copy
-LoadHallOfFameTeams: ; 73b3f (1c:7b3f)
+LoadHallOfFameTeams:
ld hl, sHallOfFame
ld bc, HOF_TEAM
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wHoFTeamIndex]
call AddNTimes
- ld de, wcc5b
+ ld de, wHallOfFame
ld bc, HOF_TEAM
; fallthrough
-HallOfFame_Copy: ; 73b51 (1c:7b51)
+HallOfFame_Copy:
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
@@ -665,7 +682,7 @@ HallOfFame_Copy: ; 73b51 (1c:7b51)
ld [MBC1SRamEnable], a
ret
-ClearSAV: ; 73b6a (1c:7b6a)
+ClearSAV:
ld a, SRAM_ENABLE
ld [MBC1SRamEnable], a
ld a, $1
@@ -683,7 +700,7 @@ ClearSAV: ; 73b6a (1c:7b6a)
ld [MBC1SRamEnable], a
ret
-PadSRAM_FF: ; 73b8f (1c:7b8f)
+PadSRAM_FF:
ld [MBC1SRamBank], a
ld hl, $a000
ld bc, $2000
diff --git a/engine/slot_machine.asm b/engine/slot_machine.asm
index e3e452f3..2dfcffde 100755
--- a/engine/slot_machine.asm
+++ b/engine/slot_machine.asm
@@ -1,4 +1,4 @@
-PromptUserToPlaySlots: ; 3730e (d:730e)
+PromptUserToPlaySlots:
call SaveScreenTilesToBuffer2
ld a, BANK(DisplayTextIDInit)
ld [wAutoTextBoxDrawingControl], a
@@ -10,90 +10,90 @@ PromptUserToPlaySlots: ; 3730e (d:730e)
call YesNoChoice
ld a, [wCurrentMenuItem]
and a
- jr nz, .skip
+ jr nz, .done ; if player chose No
dec a
ld [wUpdateSpritesEnabled], a
- ld hl, wcd4f
+ ld hl, wSlotMachineRerollCounter
xor a
ld [hli], a
- ld [hl], $2
+ ld [hl], SMILE_BUBBLE
predef EmotionBubble
call GBPalWhiteOutWithDelay3
call LoadSlotMachineTiles
call LoadFontTilePatterns
- ld b, $5
- call GoPAL_SET
+ ld b, SET_PAL_SLOTS
+ call RunPaletteCommand
call GBPalNormal
ld a, $e4
- ld [$ff48], a
+ ld [rOBP0], a
ld hl, wd730
set 6, [hl]
xor a
- ld [W_SUBANIMSUBENTRYADDR], a
- ld hl, wTrainerSpriteOffset
+ ld [wSlotMachineAllowMatchesCounter], a
+ ld hl, wStoppingWhichSlotMachineWheel
ld bc, $0014
call FillMemory
call MainSlotMachineLoop
ld hl, wd730
res 6, [hl]
xor a
- ld [W_SUBANIMSUBENTRYADDR], a
+ ld [wSlotMachineAllowMatchesCounter], a
call GBPalWhiteOutWithDelay3
ld a, $1
ld [wUpdateSpritesEnabled], a
- call GoPAL_SET_CF1C
+ call RunDefaultPaletteCommand
call ReloadMapSpriteTilePatterns
call ReloadTilesetTilePatterns
-.skip
+.done
call LoadScreenTilesFromBuffer2
call Delay3
call GBPalNormal
- ld a, [wcc5e]
+ ld a, [wSlotMachineSavedROMBank]
push af
jp CloseTextDisplay
-PlaySlotMachineText: ; 37390 (d:7390)
+PlaySlotMachineText:
TX_FAR _PlaySlotMachineText
db "@"
-MainSlotMachineLoop: ; 37395 (d:7395)
- call SlotMachine_37754
+MainSlotMachineLoop:
+ call SlotMachine_PrintCreditCoins
xor a
- ld hl, wcd4a
+ ld hl, wPayoutCoins
ld [hli], a
ld [hl], a
- call SlotMachine_3775f
+ call SlotMachine_PrintPayoutCoins
ld hl, BetHowManySlotMachineText
call PrintText
call SaveScreenTilesToBuffer1
.loop
- ld a, $3
+ ld a, A_BUTTON | B_BUTTON
ld [wMenuWatchedKeys], a
- ld a, $2
+ ld a, 2
ld [wMaxMenuItem], a
- ld a, $c
+ ld a, 12
ld [wTopMenuItemY], a
- ld a, $f
+ ld a, 15
ld [wTopMenuItemX], a
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
- ld [wcc37], a
- ld hl, wTileMap + $ea
- ld b, $5
- ld c, $4
+ ld [wMenuWatchMovingOutOfBounds], a
+ coord hl, 14, 11
+ ld b, 5
+ ld c, 4
call TextBoxBorder
- ld hl, wTileMap + $100
+ coord hl, 16, 12
ld de, CoinMultiplierSlotMachineText
call PlaceString
call HandleMenuInput
- and $2
+ and B_BUTTON
jp nz, LoadScreenTilesFromBuffer1
ld a, [wCurrentMenuItem]
ld b, a
- ld a, $3
+ ld a, 3
sub b
- ld [wcd50], a
+ ld [wSlotMachineBet], a
ld hl, wPlayerCoins
ld c, a
ld a, [hli]
@@ -107,34 +107,34 @@ MainSlotMachineLoop: ; 37395 (d:7395)
jr .loop
.skip1
call LoadScreenTilesFromBuffer1
- call SlotMachine_37741
- call SlotMachine_377d5
- call SlotMachine_37480
- ld a, $4
- ld hl, wcd4d
+ call SlotMachine_SubtractBetFromPlayerCoins
+ call SlotMachine_LightBalls
+ call SlotMachine_SetFlags
+ ld a, 4
+ ld hl, wSlotMachineWheel1SlipCounter
ld [hli], a
ld [hli], a
ld [hl], a
call WaitForSoundToFinish
- ld a, (SFX_1f_66 - SFX_Headers_1f) / 3
+ ld a, SFX_SLOTS_NEW_SPIN
call PlaySound
ld hl, StartSlotMachineText
call PrintText
- call SlotMachine_374ad
- call SlotMachine_37588
+ call SlotMachine_SpinWheels
+ call SlotMachine_CheckForMatches
ld hl, wPlayerCoins
ld a, [hli]
or [hl]
jr nz, .skip2
ld hl, OutOfCoinsSlotMachineText
call PrintText
- ld c, $3c
+ ld c, 60
jp DelayFrames
.skip2
ld hl, OneMoreGoSlotMachineText
call PrintText
- ld hl, wTileMap + $fe
- ld bc, $0d0f
+ coord hl, 14, 12
+ lb bc, 13, 15
xor a ; YES_NO_MENU
ld [wTwoOptionMenuID], a
ld a, TWO_OPTION_MENU
@@ -143,83 +143,83 @@ MainSlotMachineLoop: ; 37395 (d:7395)
ld a, [wCurrentMenuItem]
and a
ret nz
- call SlotMachine_377ce
+ call SlotMachine_PutOutLitBalls
jp MainSlotMachineLoop
-CoinMultiplierSlotMachineText: ; 3745e (d:745e)
+CoinMultiplierSlotMachineText:
db "×3"
next "×2"
next "×1@"
-OutOfCoinsSlotMachineText: ; 37467 (d:7467)
+OutOfCoinsSlotMachineText:
TX_FAR _OutOfCoinsSlotMachineText
db "@"
-BetHowManySlotMachineText: ; 3746c (d:746c)
+BetHowManySlotMachineText:
TX_FAR _BetHowManySlotMachineText
db "@"
-StartSlotMachineText: ; 37471 (d:7471)
+StartSlotMachineText:
TX_FAR _StartSlotMachineText
db "@"
-NotEnoughCoinsSlotMachineText: ; 37476 (d:7476)
+NotEnoughCoinsSlotMachineText:
TX_FAR _NotEnoughCoinsSlotMachineText
db "@"
-OneMoreGoSlotMachineText: ; 3747b (d:747b)
+OneMoreGoSlotMachineText:
TX_FAR _OneMoreGoSlotMachineText
db "@"
-SlotMachine_37480: ; 37480 (d:7480)
- ld hl, wcd4c
+SlotMachine_SetFlags:
+ ld hl, wSlotMachineFlags
bit 7, [hl]
ret nz
- ld a, [W_SUBANIMSUBENTRYADDR]
+ ld a, [wSlotMachineAllowMatchesCounter]
and a
- jr nz, .skip1
+ jr nz, .allowMatches
call Random
and a
- jr z, .skip2
+ jr z, .setAllowMatchesCounter ; 1/256 (~0.4%) chance
ld b, a
- ld a, [wcc5b]
+ ld a, [wSlotMachineSevenAndBarModeChance]
cp b
- jr c, .skip3
- ld a, $d2
+ jr c, .allowSevenAndBarMatches
+ ld a, 210
cp b
- jr c, .skip1
- ld [hl], $0
+ jr c, .allowMatches ; 55/256 (~21.5%) chance
+ ld [hl], 0
ret
-.skip1
+.allowMatches
set 6, [hl]
ret
-.skip2
- ld a, $3c
- ld [W_SUBANIMSUBENTRYADDR], a
+.setAllowMatchesCounter
+ ld a, 60
+ ld [wSlotMachineAllowMatchesCounter], a
ret
-.skip3
+.allowSevenAndBarMatches
set 7, [hl]
ret
-SlotMachine_374ad: ; 374ad (d:74ad)
- ld c, $14
+SlotMachine_SpinWheels:
+ ld c, 20
.loop1
push bc
- call SlotMachine_37813
- call SlotMachine_37823
- call SlotMachine_37833
- ld c, $2
+ call SlotMachine_AnimWheel1
+ call SlotMachine_AnimWheel2
+ call SlotMachine_AnimWheel3
+ ld c, 2
call DelayFrames
pop bc
dec c
jr nz, .loop1
xor a
- ld [wTrainerSpriteOffset], a
+ ld [wStoppingWhichSlotMachineWheel], a
.loop2
- call SlotMachine_37882
- call SlotMachine_374df
- call SlotMachine_374fb
- call SlotMachine_37517
+ call SlotMachine_HandleInputWhileWheelsSpin
+ call SlotMachine_StopOrAnimWheel1
+ call SlotMachine_StopOrAnimWheel2
+ call SlotMachine_StopOrAnimWheel3
ret c
ld a, [wOnSGB]
xor $1
@@ -228,194 +228,214 @@ SlotMachine_374ad: ; 374ad (d:74ad)
call DelayFrames
jr .loop2
-SlotMachine_374df: ; 374df (d:74df)
- ld a, [wTrainerSpriteOffset]
- cp $1
- jr c, .skip
- ld de, wTrainerEngageDistance
+; Note that the wheels can only stop when a symbol is centred in the wheel
+; and thus 3 full symbols rather than 2 full symbols and 2 half symbols are
+; visible. The 3 functions below ensure this by checking if the wheel offset
+; is even before stopping the wheel.
+
+SlotMachine_StopOrAnimWheel1:
+ ld a, [wStoppingWhichSlotMachineWheel]
+ cp 1
+ jr c, .animWheel
+ ld de, wSlotMachineWheel1Offset
ld a, [de]
rra
- jr nc, .skip
- ld hl, wcd4d
+ jr nc, .animWheel ; check that a symbol is centred in the wheel
+ ld hl, wSlotMachineWheel1SlipCounter
ld a, [hl]
and a
ret z
dec [hl]
- call SlotMachine_3752c
+ call SlotMachine_StopWheel1Early
ret nz
-.skip
- jp SlotMachine_37813
-
-SlotMachine_374fb: ; 374fb (d:74fb)
- ld a, [wTrainerSpriteOffset]
- cp $2
- jr c, .skip
- ld de, wTrainerFacingDirection
+.animWheel
+ jp SlotMachine_AnimWheel1
+
+SlotMachine_StopOrAnimWheel2:
+ ld a, [wStoppingWhichSlotMachineWheel]
+ cp 2
+ jr c, .animWheel
+ ld de, wSlotMachineWheel2Offset
ld a, [de]
rra
- jr nc, .skip
- ld hl, wcd4e
+ jr nc, .animWheel ; check that a symbol is centred in the wheel
+ ld hl, wSlotMachineWheel2SlipCounter
ld a, [hl]
and a
ret z
dec [hl]
- call SlotMachine_37552
+ call SlotMachine_StopWheel2Early
ret z
-.skip
- jp SlotMachine_37823
-
-SlotMachine_37517: ; 37517 (d:7517)
- ld a, [wTrainerSpriteOffset]
- cp $3
- jr c, .skip
- ld de, wTrainerScreenY
+.animWheel
+ jp SlotMachine_AnimWheel2
+
+SlotMachine_StopOrAnimWheel3:
+ ld a, [wStoppingWhichSlotMachineWheel]
+ cp 3
+ jr c, .animWheel
+ ld de, wSlotMachineWheel3Offset
ld a, [de]
rra
- jr nc, .skip
+ jr nc, .animWheel ; check that a symbol is centred in the wheel
+; wheel 3 stops as soon as possible
scf
ret
-.skip
- call SlotMachine_37833
+.animWheel
+ call SlotMachine_AnimWheel3
and a
ret
-SlotMachine_3752c: ; 3752c (d:752c)
- call SlotMachine_GetWheelOneTile
- ld hl, wTrainerScreenX
- ld a, [wcd4c]
+SlotMachine_StopWheel1Early:
+ call SlotMachine_GetWheel1Tiles
+ ld hl, wSlotMachineWheel1BottomTile
+ ld a, [wSlotMachineFlags]
and $80
- jr nz, .skip1
+ jr nz, .sevenAndBarMode
+; Stop early if the middle symbol is not a cherry.
inc hl
ld a, [hl]
- cp $a
- jr nz, .skip2
+ cp SLOTSCHERRY >> 8
+ jr nz, .stopWheel
ret
-.skip1
+; It looks like this was intended to make the wheel stop when a 7 symbol was
+; visible, but it has a bug and so the wheel stops randomly.
+.sevenAndBarMode
ld c, $3
.loop
ld a, [hli]
- cp $2
- jr c, .skip2
+ cp SLOTS7 >> 8
+ jr c, .stopWheel ; condition never true
dec c
jr nz, .loop
ret
-.skip2
+.stopWheel
inc a
- ld hl, wcd4d
- ld [hl], $0
+ ld hl, wSlotMachineWheel1SlipCounter
+ ld [hl], 0
ret
-SlotMachine_37552: ; 37552 (d:7552)
- call SlotMachine_GetWheelTwoTile
- ld a, [wcd4c]
+SlotMachine_StopWheel2Early:
+ call SlotMachine_GetWheel2Tiles
+ ld a, [wSlotMachineFlags]
and $80
- jr nz, .skip1
- call SlotMachine_3756e
+ jr nz, .sevenAndBarMode
+; Stop early if any symbols are lined up in the first two wheels.
+ call SlotMachine_FindWheel1Wheel2Matches
ret nz
- jr .skip2
-.skip1
- call SlotMachine_3756e
+ jr .stopWheel
+; Stop early if two 7 symbols or two bar symbols are lined up in the first two
+; wheels OR if no symbols are lined up and the bottom symbol in wheel 2 is a
+; 7 symbol or bar symbol. The second part could be a bug or a way to reduce the
+; player's odds.
+.sevenAndBarMode
+ call SlotMachine_FindWheel1Wheel2Matches
ld a, [de]
- cp $7
+ cp (SLOTSBAR >> 8) + 1
ret nc
-.skip2
+.stopWheel
xor a
- ld [wcd4e], a
+ ld [wSlotMachineWheel2SlipCounter], a
ret
-SlotMachine_3756e: ; 3756e (d:756e)
- ld hl, wTrainerScreenX
- ld de, wcd44
+SlotMachine_FindWheel1Wheel2Matches:
+; return whether wheel 1 and wheel 2's current positions allow a match (given
+; that wheel 3 stops in a good position) in Z
+ ld hl, wSlotMachineWheel1BottomTile
+ ld de, wSlotMachineWheel2BottomTile
ld a, [de]
- cp [hl]
+ cp [hl] ; wheel 1 bottom, wheel 2 bottom
ret z
inc de
ld a, [de]
- cp [hl]
+ cp [hl] ; wheel 1 bottom, wheel 2 middle
ret z
inc hl
- cp [hl]
+ cp [hl] ; wheel 1 middle, wheel 2 middle
ret z
inc hl
- cp [hl]
+ cp [hl] ; wheel 1 top, wheel 2 middle
ret z
inc de
ld a, [de]
- cp [hl]
+ cp [hl] ; wheel 1 top, wheel 2 top
ret z
dec de
dec de
ret
-SlotMachine_37588: ; 37588 (d:7588)
- call SlotMachine_GetWheelThreeTile
- ld a, [wcd50]
- cp $2
- jr z, .skip1
- cp $1
- jr z, .skip2
- ld hl, wTrainerScreenX
- ld de, wcd45
- ld bc, wcd49
+SlotMachine_CheckForMatches:
+ call SlotMachine_GetWheel3Tiles
+ ld a, [wSlotMachineBet]
+ cp 2
+ jr z, .checkMatchesFor2CoinBet
+ cp 1
+ jr z, .checkMatchFor1CoinBet
+; 3 coin bet allows diagonal matches (plus the matches for 1/2 coin bets)
+ ld hl, wSlotMachineWheel1BottomTile
+ ld de, wSlotMachineWheel2MiddleTile
+ ld bc, wSlotMachineWheel3TopTile
call SlotMachine_CheckForMatch
- jp z, .skip5
- ld hl, wcd43
- ld de, wcd45
- ld bc, wcd47
+ jp z, .foundMatch
+ ld hl, wSlotMachineWheel1TopTile
+ ld de, wSlotMachineWheel2MiddleTile
+ ld bc, wSlotMachineWheel3BottomTile
call SlotMachine_CheckForMatch
- jr z, .skip5
-.skip1
- ld hl, wcd43
- ld de, wcd46
- ld bc, wcd49
+ jr z, .foundMatch
+; 2 coin bet allows top/bottom horizontal matches (plus the match for a 1 coin bet)
+.checkMatchesFor2CoinBet
+ ld hl, wSlotMachineWheel1TopTile
+ ld de, wSlotMachineWheel2TopTile
+ ld bc, wSlotMachineWheel3TopTile
call SlotMachine_CheckForMatch
- jr z, .skip5
- ld hl, wTrainerScreenX
- ld de, wcd44
- ld bc, wcd47
+ jr z, .foundMatch
+ ld hl, wSlotMachineWheel1BottomTile
+ ld de, wSlotMachineWheel2BottomTile
+ ld bc, wSlotMachineWheel3BottomTile
call SlotMachine_CheckForMatch
- jr z, .skip5
-.skip2
- ld hl, wcd42
- ld de, wcd45
- ld bc, wcd48
+ jr z, .foundMatch
+; 1 coin bet only allows a middle horizontal match
+.checkMatchFor1CoinBet
+ ld hl, wSlotMachineWheel1MiddleTile
+ ld de, wSlotMachineWheel2MiddleTile
+ ld bc, wSlotMachineWheel3MiddleTile
call SlotMachine_CheckForMatch
- jr z, .skip5
- ld a, [wcd4c]
+ jr z, .foundMatch
+ ld a, [wSlotMachineFlags]
and $c0
- jr z, .skip3
- ld hl, wcd4f
+ jr z, .noMatch
+ ld hl, wSlotMachineRerollCounter
dec [hl]
- jr nz, .skip4
-.skip3
+ jr nz, .rollWheel3DownByOneSymbol
+.noMatch
ld hl, NotThisTimeText
call PrintText
-.loop
+.done
xor a
- ld [wc002], a
+ ld [wMuteAudioAndPauseMusic], a
ret
-.skip4
- call SlotMachine_37833
+.rollWheel3DownByOneSymbol
+ call SlotMachine_AnimWheel3
call DelayFrame
- call SlotMachine_37833
+ call SlotMachine_AnimWheel3
call DelayFrame
- jp SlotMachine_37588
-.skip5
- ld a, [wcd4c]
+ jp SlotMachine_CheckForMatches
+.foundMatch
+ ld a, [wSlotMachineFlags]
and $c0
- jr z, .skip4
+ jr z, .rollWheel3DownByOneSymbol ; roll wheel if player isn't allowed to win
and $80
- jr nz, .skip6
+ jr nz, .acceptMatch
+; if 7/bar matches aren't enabled and the match was a 7/bar symbol, roll wheel
ld a, [hl]
- cp $7
- jr c, .skip4
-.skip6
+ cp (SLOTSBAR >> 8) + 1
+ jr c, .rollWheel3DownByOneSymbol
+.acceptMatch
ld a, [hl]
sub $2
- ld [wTrainerScreenX], a
+ ld [wSlotMachineWinningSymbol], a
ld hl, SlotRewardPointers
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hli]
ld e, a
@@ -426,39 +446,39 @@ SlotMachine_37588: ; 37588 (d:7588)
ld h, [hl]
ld l, a
ld de, wcf4b
- ld bc, $0004
+ ld bc, 4
call CopyData
pop hl
- ld de, .asm_37638
+ ld de, .flashScreenLoop
push de
jp [hl]
-.asm_37638
- ld a, [$ff47]
+.flashScreenLoop
+ ld a, [rBGP]
xor $40
- ld [$ff47], a
- ld c, $5
+ ld [rBGP], a
+ ld c, 5
call DelayFrames
dec b
- jr nz, .asm_37638
- ld hl, wcd4a
+ jr nz, .flashScreenLoop
+ ld hl, wPayoutCoins
ld [hl], d
inc hl
ld [hl], e
- call SlotMachine_3775f
- ld hl, SlotsMachineText_37665
+ call SlotMachine_PrintPayoutCoins
+ ld hl, SymbolLinedUpSlotMachineText
call PrintText
call WaitForTextScrollButtonPress
- call SlotMachine_3776b
- call SlotMachine_3775f
+ call SlotMachine_PayCoinsToPlayer
+ call SlotMachine_PrintPayoutCoins
ld a, $e4
- ld [$ff48], a
- jp .loop
+ ld [rOBP0], a
+ jp .done
-SlotsMachineText_37665: ; 37665 (d:7665)
- db $08 ; asm
+SymbolLinedUpSlotMachineText:
+ TX_ASM
push bc
- call SlotMachine_37728
+ call SlotMachine_PrintWinningSymbol
ld hl, LinedUpText
pop bc
inc bc
@@ -467,11 +487,11 @@ SlotsMachineText_37665: ; 37665 (d:7665)
inc bc
ret
-LinedUpText: ; 37673 (d:7673)
+LinedUpText:
TX_FAR _LinedUpText
db "@"
-SlotRewardPointers: ; 37678 (d:7678)
+SlotRewardPointers:
dw SlotReward300Func
dw SlotReward300Text
dw SlotReward100Func
@@ -485,24 +505,24 @@ SlotRewardPointers: ; 37678 (d:7678)
dw SlotReward15Func
dw SlotReward15Text
-SlotReward300Text: ; 37690 (d:7690)
+SlotReward300Text:
db "300@"
-SlotReward100Text: ; 37694 (d:7694)
+SlotReward100Text:
db "100@"
-SlotReward8Text: ; 37698 (d:7698)
+SlotReward8Text:
db "8@"
-SlotReward15Text: ; 3769a (d:769a)
+SlotReward15Text:
db "15@"
-NotThisTimeText: ; 3769d (d:769d)
+NotThisTimeText:
TX_FAR _NotThisTimeText
db "@"
; compares the slot machine tiles at bc, de, and hl
-SlotMachine_CheckForMatch: ; 376a2 (d:76a2)
+SlotMachine_CheckForMatch:
ld a, [de]
cp [hl]
ret nz
@@ -510,28 +530,28 @@ SlotMachine_CheckForMatch: ; 376a2 (d:76a2)
cp [hl]
ret
-SlotMachine_GetWheelThreeTile: ; 376a8 (d:76a8)
- ld de, wcd47
+SlotMachine_GetWheel3Tiles:
+ ld de, wSlotMachineWheel3BottomTile
ld hl, SlotMachineWheel3
- ld a, [wTrainerScreenY]
- call SlotMachine_GetWheelTile
+ ld a, [wSlotMachineWheel3Offset]
+ call SlotMachine_GetWheelTiles
-SlotMachine_GetWheelTwoTile: ; 376b4 (d:76b4)
- ld de, wcd44
+SlotMachine_GetWheel2Tiles:
+ ld de, wSlotMachineWheel2BottomTile
ld hl, SlotMachineWheel2
- ld a, [wTrainerFacingDirection]
- call SlotMachine_GetWheelTile
+ ld a, [wSlotMachineWheel2Offset]
+ call SlotMachine_GetWheelTiles
-SlotMachine_GetWheelOneTile: ; 376c0 (d:76c0)
- ld de, wTrainerScreenX
+SlotMachine_GetWheel1Tiles:
+ ld de, wSlotMachineWheel1BottomTile
ld hl, SlotMachineWheel1
- ld a, [wTrainerEngageDistance]
+ ld a, [wSlotMachineWheel1Offset]
-SlotMachine_GetWheelTile: ; 376c9 (d:76c9)
+SlotMachine_GetWheelTiles:
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
- ld c, $3
+ ld c, 3
.loop
ld a, [hli]
ld [de], a
@@ -541,8 +561,8 @@ SlotMachine_GetWheelTile: ; 376c9 (d:76c9)
jr nz, .loop
ret
-SlotReward8Func: ; 376d7 (d:76d7)
- ld hl, W_SUBANIMSUBENTRYADDR
+SlotReward8Func:
+ ld hl, wSlotMachineAllowMatchesCounter
ld a, [hl]
and a
jr z, .skip
@@ -552,8 +572,8 @@ SlotReward8Func: ; 376d7 (d:76d7)
ld de, 8
ret
-SlotReward15Func: ; 376e5 (d:76e5)
- ld hl, W_SUBANIMSUBENTRYADDR
+SlotReward15Func:
+ ld hl, wSlotMachineAllowMatchesCounter
ld a, [hl]
and a
jr z, .skip
@@ -563,55 +583,57 @@ SlotReward15Func: ; 376e5 (d:76e5)
ld de, 15
ret
-SlotReward100Func: ; 376f3 (d:76f3)
- ld a, (SFX_1f_42 - SFX_Headers_1f) / 3
+SlotReward100Func:
+ ld a, SFX_GET_KEY_ITEM
call PlaySound
xor a
- ld [wcd4c], a
+ ld [wSlotMachineFlags], a
ld b, $8
ld de, 100
ret
-SlotReward300Func: ; 37702 (d:7702)
+SlotReward300Func:
ld hl, YeahText
call PrintText
- ld a, (SFX_1f_3b - SFX_Headers_1f) / 3
+ ld a, SFX_GET_ITEM_2
call PlaySound
call Random
cp $80
ld a, $0
jr c, .skip
- ld [wcd4c], a
+ ld [wSlotMachineFlags], a
.skip
- ld [W_SUBANIMSUBENTRYADDR], a
+ ld [wSlotMachineAllowMatchesCounter], a
ld b, $14
ld de, 300
ret
-YeahText: ; 37722 (d:7722)
+YeahText:
TX_FAR _YeahText
- db $0a, "@"
+ TX_DELAY
+ db "@"
-SlotMachine_37728: ; 37728 (d:7728)
- ld hl, wTileMap + $11a
- ld a, [wTrainerScreenX]
+SlotMachine_PrintWinningSymbol:
+; prints winning symbol and down arrow in text box
+ coord hl, 2, 14
+ ld a, [wSlotMachineWinningSymbol]
add $25
ld [hli], a
inc a
ld [hld], a
inc a
- ld de, $ffec
+ ld de, -SCREEN_WIDTH
add hl, de
ld [hli], a
inc a
ld [hl], a
- ld hl, wTileMap + $152
- ld [hl], $ee
+ coord hl, 18, 16
+ ld [hl], "▼"
ret
-SlotMachine_37741: ; 37741 (d:7741)
- ld hl, wcd4b
- ld a, [wcd50]
+SlotMachine_SubtractBetFromPlayerCoins:
+ ld hl, wTempCoins2 + 1
+ ld a, [wSlotMachineBet]
ld [hld], a
xor a
ld [hli], a
@@ -619,158 +641,164 @@ SlotMachine_37741: ; 37741 (d:7741)
ld c, $2
predef SubBCDPredef
-SlotMachine_37754: ; 37754 (d:7754)
- ld hl, wTileMap + $19
+SlotMachine_PrintCreditCoins:
+ coord hl, 5, 1
ld de, wPlayerCoins
ld c, $2
jp PrintBCDNumber
-SlotMachine_3775f: ; 3775f (d:775f)
- ld hl, wTileMap + $1f
- ld de, wcd4a
- ld bc, $8204
+SlotMachine_PrintPayoutCoins:
+ coord hl, 11, 1
+ ld de, wPayoutCoins
+ lb bc, LEADING_ZEROES | 2, 4 ; 2 bytes, 4 digits
jp PrintNumber
-SlotMachine_3776b: ; 3776b (d:776b)
+SlotMachine_PayCoinsToPlayer:
ld a, $1
- ld [wc002], a
+ ld [wMuteAudioAndPauseMusic], a
call WaitForSoundToFinish
- ld hl, wcd46
+
+; Put 1 in the temp coins variable. This value is added to the player's coins
+; repeatedly so the player can watch the value go up 1 coin at a time.
+ ld hl, wTempCoins1
xor a
ld [hli], a
inc a
ld [hl], a
- ld a, $5
- ld [W_SUBANIMTRANSFORM], a
+
+ ld a, 5
+ ld [wAnimCounter], a
+
+; Subtract 1 from the payout amount and add 1 to the player's coins each
+; iteration until the payout amount reaches 0.
.loop
- ld a, [wcd4b]
+ ld a, [wPayoutCoins + 1]
ld l, a
- ld a, [wcd4a]
+ ld a, [wPayoutCoins]
ld h, a
or l
ret z
- ld de, $ffff
+ ld de, -1
add hl, de
ld a, l
- ld [wcd4b], a
+ ld [wPayoutCoins + 1], a
ld a, h
- ld [wcd4a], a
- ld hl, wcd47
+ ld [wPayoutCoins], a
+ ld hl, wTempCoins1 + 1
ld de, wPlayerCoins + 1
ld c, $2
predef AddBCDPredef
- call SlotMachine_37754
- call SlotMachine_3775f
- ld a, (SFX_1f_65 - SFX_Headers_1f) / 3
+ call SlotMachine_PrintCreditCoins
+ call SlotMachine_PrintPayoutCoins
+ ld a, SFX_SLOTS_REWARD
call PlaySound
- ld a, [W_SUBANIMTRANSFORM]
+ ld a, [wAnimCounter]
dec a
jr nz, .skip1
- ld a, [$ff48]
- xor $40
- ld [$ff48], a
- ld a, $5
+ ld a, [rOBP0]
+ xor $40 ; make the slot wheel symbols flash
+ ld [rOBP0], a
+ ld a, 5
.skip1
- ld [W_SUBANIMTRANSFORM], a
- ld a, [wTrainerScreenX]
- cp $7
- ld c, $8
+ ld [wAnimCounter], a
+ ld a, [wSlotMachineWinningSymbol]
+ cp (SLOTSBAR >> 8) + 1
+ ld c, 8
jr nc, .skip2
- srl c
+ srl c ; c = 4 (make the the coins transfer faster if the symbol was 7 or bar)
.skip2
call DelayFrames
jr .loop
-SlotMachine_377ce: ; 377ce (d:77ce)
+SlotMachine_PutOutLitBalls:
ld a, $23
- ld [wd08a], a
- jr SlotMachine_377e3
+ ld [wNewSlotMachineBallTile], a
+ jr SlotMachine_UpdateThreeCoinBallTiles
-SlotMachine_377d5: ; 377d5 (d:77d5)
+SlotMachine_LightBalls:
ld a, $14
- ld [wd08a], a
- ld a, [wcd50]
+ ld [wNewSlotMachineBallTile], a
+ ld a, [wSlotMachineBet]
dec a
- jr z, SlotMachine_377fb
+ jr z, SlotMachine_UpdateOneCoinBallTiles
dec a
- jr z, SlotMachine_377ef
+ jr z, SlotMachine_UpdateTwoCoinBallTiles
-SlotMachine_377e3: ; 377e3 (d:77e3)
- ld hl, wTileMap + $2b
- call SlotMachine_377fe
- ld hl, wTileMap + $cb
- call SlotMachine_377fe
+SlotMachine_UpdateThreeCoinBallTiles:
+ coord hl, 3, 2
+ call SlotMachine_UpdateBallTiles
+ coord hl, 3, 10
+ call SlotMachine_UpdateBallTiles
-SlotMachine_377ef: ; 377ef (d:77ef)
- ld hl, wTileMap + $53
- call SlotMachine_377fe
- ld hl, wTileMap + $a3
- call SlotMachine_377fe
+SlotMachine_UpdateTwoCoinBallTiles:
+ coord hl, 3, 4
+ call SlotMachine_UpdateBallTiles
+ coord hl, 3, 8
+ call SlotMachine_UpdateBallTiles
-SlotMachine_377fb: ; 377fb (d:77fb)
- ld hl, wTileMap + $7b
+SlotMachine_UpdateOneCoinBallTiles:
+ coord hl, 3, 6
-SlotMachine_377fe: ; 377fe (d:77fe)
- ld a, [wd08a]
+SlotMachine_UpdateBallTiles:
+ ld a, [wNewSlotMachineBallTile]
ld [hl], a
- ld bc, $000d
+ ld bc, 13
add hl, bc
ld [hl], a
- ld bc, $0007
+ ld bc, 7
add hl, bc
inc a
ld [hl], a
- ld bc, $000d
+ ld bc, 13
add hl, bc
ld [hl], a
ret
-SlotMachine_37813: ; 37813 (d:7813)
+SlotMachine_AnimWheel1:
ld bc, SlotMachineWheel1
- ld de, wTrainerEngageDistance
+ ld de, wSlotMachineWheel1Offset
ld hl, wOAMBuffer
ld a, $30
- ld [W_BASECOORDX], a
- jr SlotMachine_37841
+ ld [wBaseCoordX], a
+ jr SlotMachine_AnimWheel
-SlotMachine_37823: ; 37823 (d:7823)
+SlotMachine_AnimWheel2:
ld bc, SlotMachineWheel2
- ld de, wTrainerFacingDirection
+ ld de, wSlotMachineWheel2Offset
ld hl, wOAMBuffer + $30
ld a, $50
- ld [W_BASECOORDX], a
- jr SlotMachine_37841
+ ld [wBaseCoordX], a
+ jr SlotMachine_AnimWheel
-SlotMachine_37833: ; 37833 (d:7833)
+SlotMachine_AnimWheel3:
ld bc, SlotMachineWheel3
- ld de, wTrainerScreenY
+ ld de, wSlotMachineWheel3Offset
ld hl, wOAMBuffer + $60
ld a, $70
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
-SlotMachine_37841: ; 37841 (d:7841)
+SlotMachine_AnimWheel:
ld a, $58
- ld [W_BASECOORDY], a
+ ld [wBaseCoordY], a
push de
ld a, [de]
ld d, b
add c
ld e, a
- jr nc, SlotMachine_3784e
+ jr nc, .loop
inc d
-
-SlotMachine_3784e: ; 3784e (d:784e)
- ld a, [W_BASECOORDY]
+.loop
+ ld a, [wBaseCoordY]
ld [hli], a
- ld a, [W_BASECOORDX]
+ ld a, [wBaseCoordX]
ld [hli], a
ld a, [de]
ld [hli], a
ld a, $80
ld [hli], a
- ld a, [W_BASECOORDY]
+ ld a, [wBaseCoordY]
ld [hli], a
- ld a, [W_BASECOORDX]
+ ld a, [wBaseCoordX]
add $8
ld [hli], a
ld a, [de]
@@ -779,38 +807,38 @@ SlotMachine_3784e: ; 3784e (d:784e)
ld a, $80
ld [hli], a
inc de
- ld a, [W_BASECOORDY]
+ ld a, [wBaseCoordY]
sub $8
- ld [W_BASECOORDY], a
+ ld [wBaseCoordY], a
cp $28
- jr nz, SlotMachine_3784e
+ jr nz, .loop
pop de
ld a, [de]
- inc a
- cp $1e
+ inc a ; advance the offset so that the wheel animates
+ cp 30
jr nz, .skip
- xor a
+ xor a ; wrap around to 0 when the offset reaches 30
.skip
ld [de], a
ret
-SlotMachine_37882: ; 37882 (d:7882)
+SlotMachine_HandleInputWhileWheelsSpin:
call DelayFrame
call JoypadLowSensitivity
ld a, [hJoy5]
- and $1
+ and A_BUTTON
ret z
- ld hl, wTrainerSpriteOffset
+ ld hl, wStoppingWhichSlotMachineWheel
ld a, [hl]
dec a
- ld de, wcd4d
+ ld de, wSlotMachineWheel1SlipCounter
jr z, .skip
dec a
- ld de, wcd4e
+ ld de, wSlotMachineWheel2SlipCounter
jr z, .skip
.loop
inc [hl]
- ld a, (SFX_1f_64 - SFX_Headers_1f) / 3
+ ld a, SFX_SLOTS_STOP_WHEEL
jp PlaySound
.skip
ld a, [de]
@@ -818,7 +846,7 @@ SlotMachine_37882: ; 37882 (d:7882)
ret nz
jr .loop
-LoadSlotMachineTiles: ; 378a8 (d:78a8)
+LoadSlotMachineTiles:
call DisableLCD
ld hl, SlotMachineTiles2
ld de, vChars0
@@ -836,38 +864,29 @@ LoadSlotMachineTiles: ; 378a8 (d:78a8)
ld a, BANK(SlotMachineTiles2)
call FarCopyData2
ld hl, SlotMachineMap
- ld de, wTileMap
- ld bc, $00f0
+ coord de, 0, 0
+ ld bc, SlotMachineMapEnd - SlotMachineMap
call CopyData
call EnableLCD
- ld hl, wTrainerEngageDistance
+ ld hl, wSlotMachineWheel1Offset
ld a, $1c
ld [hli], a
ld [hli], a
ld [hl], a
- call SlotMachine_37813
- call SlotMachine_37823
- jp SlotMachine_37833
+ call SlotMachine_AnimWheel1
+ call SlotMachine_AnimWheel2
+ jp SlotMachine_AnimWheel3
-SlotMachineMap: ; 378f5 (d:78f5)
+SlotMachineMap:
INCBIN "gfx/tilemaps/slotmachine.map"
-
-SLOTS7 EQU $0200
-SLOTSBAR EQU $0604
-SLOTSCHERRY EQU $0A08
-SLOTSFISH EQU $0E0C
-SLOTSBIRD EQU $1210
-SLOTSMOUSE EQU $1614
+SlotMachineMapEnd:
INCLUDE "data/slot_machine_wheels.asm"
-SlotMachineTiles1: ; 37a51 (d:7a51)
+SlotMachineTiles1:
IF DEF(_RED)
INCBIN "gfx/red/slotmachine1.2bpp"
ENDC
IF DEF(_BLUE)
INCBIN "gfx/blue/slotmachine1.2bpp"
ENDC
-IF DEF(_YELLOW)
- INCBIN "gfx/yellow/slotmachine1.2bpp"
-ENDC
diff --git a/engine/special_warps.asm b/engine/special_warps.asm
new file mode 100644
index 00000000..de00a817
--- /dev/null
+++ b/engine/special_warps.asm
@@ -0,0 +1,149 @@
+SpecialWarpIn:
+ call LoadSpecialWarpData
+ predef LoadTilesetHeader
+ ld hl,wd732
+ bit 2,[hl] ; dungeon warp or fly warp?
+ res 2,[hl]
+ jr z,.next
+; if dungeon warp or fly warp
+ ld a,[wDestinationMap]
+ jr .next2
+.next
+ bit 1,[hl]
+ jr z,.next3
+ call EmptyFunc
+.next3
+ ld a,0
+.next2
+ ld b,a
+ ld a,[wd72d]
+ and a
+ jr nz,.next4
+ ld a,b
+.next4
+ ld hl,wd732
+ bit 4,[hl] ; dungeon warp?
+ ret nz
+; if not dungeon warp
+ ld [wLastMap],a
+ ret
+
+; gets the map ID, tile block map view pointer, tileset, and coordinates
+LoadSpecialWarpData:
+ ld a, [wd72d]
+ cp TRADE_CENTER
+ jr nz, .notTradeCenter
+ ld hl, TradeCenterSpec1
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK ; which gameboy is clocking determines who is on the left and who is on the right
+ jr z, .copyWarpData
+ ld hl, TradeCenterSpec2
+ jr .copyWarpData
+.notTradeCenter
+ cp COLOSSEUM
+ jr nz, .notColosseum
+ ld hl, ColosseumSpec1
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr z, .copyWarpData
+ ld hl, ColosseumSpec2
+ jr .copyWarpData
+.notColosseum
+ ld a, [wd732]
+ bit 1, a
+ jr nz, .notFirstMap
+ bit 2, a
+ jr nz, .notFirstMap
+ ld hl, FirstMapSpec
+.copyWarpData
+ ld de, wCurMap
+ ld c, $7
+.copyWarpDataLoop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .copyWarpDataLoop
+ ld a, [hli]
+ ld [wCurMapTileset], a
+ xor a
+ jr .done
+.notFirstMap
+ ld a, [wLastMap] ; this value is overwritten before it's ever read
+ ld hl, wd732
+ bit 4, [hl] ; used dungeon warp (jumped down hole/waterfall)?
+ jr nz, .usedDunegonWarp
+ bit 6, [hl] ; return to last pokemon center (or player's house)?
+ res 6, [hl]
+ jr z, .otherDestination
+; return to last pokemon center or player's house
+ ld a, [wLastBlackoutMap]
+ jr .usedFlyWarp
+.usedDunegonWarp
+ ld hl, wd72d
+ res 4, [hl]
+ ld a, [wDungeonWarpDestinationMap]
+ ld b, a
+ ld [wCurMap], a
+ ld a, [wWhichDungeonWarp]
+ ld c, a
+ ld hl, DungeonWarpList
+ ld de, 0
+ ld a, 6
+ ld [wDungeonWarpDataEntrySize], a
+.dungeonWarpListLoop
+ ld a, [hli]
+ cp b
+ jr z, .matchedDungeonWarpDestinationMap
+ inc hl
+ jr .nextDungeonWarp
+.matchedDungeonWarpDestinationMap
+ ld a, [hli]
+ cp c
+ jr z, .matchedDungeonWarpID
+.nextDungeonWarp
+ ld a, [wDungeonWarpDataEntrySize]
+ add e
+ ld e, a
+ jr .dungeonWarpListLoop
+.matchedDungeonWarpID
+ ld hl, DungeonWarpData
+ add hl, de
+ jr .copyWarpData2
+.otherDestination
+ ld a, [wDestinationMap]
+.usedFlyWarp
+ ld b, a
+ ld [wCurMap], a
+ ld hl, FlyWarpDataPtr
+.flyWarpDataPtrLoop
+ ld a, [hli]
+ inc hl
+ cp b
+ jr z, .foundFlyWarpMatch
+ inc hl
+ inc hl
+ jr .flyWarpDataPtrLoop
+.foundFlyWarpMatch
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+.copyWarpData2
+ ld de, wCurrentTileBlockMapViewPointer
+ ld c, $6
+.copyWarpDataLoop2
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .copyWarpDataLoop2
+ xor a ; OVERWORLD
+ ld [wCurMapTileset], a
+.done
+ ld [wYOffsetSinceLastSpecialWarp], a
+ ld [wXOffsetSinceLastSpecialWarp], a
+ ld a, $ff ; the player's coordinates have already been updated using a special warp, so don't use any of the normal warps
+ ld [wDestinationWarpID], a
+ ret
+
+INCLUDE "data/special_warps.asm"
diff --git a/engine/status_ailments.asm b/engine/status_ailments.asm
index 9bcfe9f0..787533c4 100755
--- a/engine/status_ailments.asm
+++ b/engine/status_ailments.asm
@@ -1,4 +1,4 @@
-PrintStatusAilment: ; 747de (1d:47de)
+PrintStatusAilment:
ld a, [de]
bit PSN, a
jr nz, .psn
diff --git a/engine/subtract_paid_money.asm b/engine/subtract_paid_money.asm
new file mode 100644
index 00000000..2888c3fb
--- /dev/null
+++ b/engine/subtract_paid_money.asm
@@ -0,0 +1,17 @@
+; subtracts the amount the player paid from their money
+; sets carry flag if there is enough money and unsets carry flag if not
+SubtractAmountPaidFromMoney_:
+ ld de,wPlayerMoney
+ ld hl,hMoney ; total price of items
+ ld c,3 ; length of money in bytes
+ call StringCmp
+ ret c
+ ld de,wPlayerMoney + 2
+ ld hl,hMoney + 2 ; total price of items
+ ld c,3 ; length of money in bytes
+ predef SubBCDPredef ; subtract total price from money
+ ld a,MONEY_BOX
+ ld [wTextBoxID],a
+ call DisplayTextBoxID ; redraw money text box
+ and a
+ ret
diff --git a/engine/test_battle.asm b/engine/test_battle.asm
new file mode 100644
index 00000000..d9dcf1fa
--- /dev/null
+++ b/engine/test_battle.asm
@@ -0,0 +1,45 @@
+TestBattle:
+ ret
+
+.loop
+ call GBPalNormal
+
+ ; Don't mess around
+ ; with obedience.
+ ld a, %10000000 ; EARTHBADGE
+ ld [wObtainedBadges], a
+
+ ld hl, wFlags_D733
+ set BIT_TEST_BATTLE, [hl]
+
+ ; Reset the party.
+ ld hl, wPartyCount
+ xor a
+ ld [hli], a
+ dec a
+ ld [hl], a
+
+ ; Give the player a
+ ; level 20 Rhydon.
+ ld a, RHYDON
+ ld [wcf91], a
+ ld a, 20
+ ld [wCurEnemyLVL], a
+ xor a
+ ld [wMonDataLocation], a
+ ld [wCurMap], a
+ call AddPartyMon
+
+ ; Fight against a
+ ; level 20 Rhydon.
+ ld a, RHYDON
+ ld [wCurOpponent], a
+
+ predef InitOpponent
+
+ ; When the battle ends,
+ ; do it all again.
+ ld a, 1
+ ld [wUpdateSpritesEnabled], a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ jr .loop
diff --git a/engine/titlescreen.asm b/engine/titlescreen.asm
index ed23fbc4..f4cce5b4 100755
--- a/engine/titlescreen.asm
+++ b/engine/titlescreen.asm
@@ -1,30 +1,30 @@
-; copy text of fixed length $b (like player name, rival name, mon names, ...)
-CopyFixedLengthText: ; 42b1 (1:42b1)
- ld bc, $b
+; copy text of fixed length NAME_LENGTH (like player name, rival name, mon names, ...)
+CopyFixedLengthText:
+ ld bc, NAME_LENGTH
jp CopyData
-SetDefaultNamesBeforeTitlescreen: ; 42b7 (1:42b7)
+SetDefaultNamesBeforeTitlescreen:
ld hl, NintenText
- ld de, wPlayerName ; wd158
+ ld de, wPlayerName
call CopyFixedLengthText
ld hl, SonyText
- ld de, W_RIVALNAME ; wd34a
+ ld de, wRivalName
call CopyFixedLengthText
xor a
ld [hWY], a
- ld [wd358], a
+ ld [wLetterPrintingDelayFlags], a
ld hl, wd732
ld [hli], a
ld [hli], a
ld [hl], a
ld a, BANK(Music_TitleScreen)
- ld [wc0ef], a
- ld [wc0f0], a
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
-LoadTitlescreenGraphics: ; 42dd (1:42dd)
+DisplayTitleScreen:
call GBPalWhiteOut
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
xor a
ld [hTilesetType], a
ld [hSCX], a
@@ -35,82 +35,85 @@ LoadTitlescreenGraphics: ; 42dd (1:42dd)
call ClearScreen
call DisableLCD
call LoadFontTilePatterns
- ld hl, NintendoCopyrightLogoGraphics ; $60c8
+ ld hl, NintendoCopyrightLogoGraphics
ld de, vTitleLogo2 + $100
ld bc, $50
ld a, BANK(NintendoCopyrightLogoGraphics)
call FarCopyData2
- ld hl, GamefreakLogoGraphics ; $61f8
+ ld hl, GamefreakLogoGraphics
ld de, vTitleLogo2 + $100 + $50
ld bc, $90
ld a, BANK(GamefreakLogoGraphics)
call FarCopyData2
- ld hl, PokemonLogoGraphics ; $5380
+ ld hl, PokemonLogoGraphics
ld de, vTitleLogo
ld bc, $600
ld a, BANK(PokemonLogoGraphics)
call FarCopyData2 ; first chunk
- ld hl, PokemonLogoGraphics+$600 ; $5980
+ ld hl, PokemonLogoGraphics+$600
ld de, vTitleLogo2
ld bc, $100
ld a, BANK(PokemonLogoGraphics)
call FarCopyData2 ; second chunk
- ld hl, Version_GFX ; $402f
-IF DEF(_RED)
- ld de,vChars2 + $600
- ld bc,$50
-ENDC
-IF DEF(_BLUE)
- ld de,vChars2 + $600 + $10
- ld bc,$50 - $10
-ENDC
-
+ ld hl, Version_GFX
+ ld de,vChars2 + $600 - (Version_GFXEnd - Version_GFX - $50)
+ ld bc, Version_GFXEnd - Version_GFX
ld a, BANK(Version_GFX)
call FarCopyDataDouble
- call Func_4519
- hlCoord 2, 1
+ call ClearBothBGMaps
+
+; place tiles for pokemon logo (except for the last row)
+ coord hl, 2, 1
ld a, $80
- ld de, $14
- ld c, $6
-.asm_434d
+ ld de, SCREEN_WIDTH
+ ld c, 6
+.pokemonLogoTileLoop
ld b, $10
push hl
-.asm_4350
+.pokemonLogoTileRowLoop ; place tiles for one row
ld [hli], a
inc a
dec b
- jr nz, .asm_4350
+ jr nz, .pokemonLogoTileRowLoop
pop hl
add hl, de
dec c
- jr nz, .asm_434d
- hlCoord 2, 7
+ jr nz, .pokemonLogoTileLoop
+
+; place tiles for the last row of the pokemon logo
+ coord hl, 2, 7
ld a, $31
ld b, $10
-.asm_4361
+.pokemonLogoLastTileRowLoop
ld [hli], a
inc a
dec b
- jr nz, .asm_4361
- call Func_44dd
+ jr nz, .pokemonLogoLastTileRowLoop
+
+ call DrawPlayerCharacter
+
+; put a pokeball in the player's hand
ld hl, wOAMBuffer + $28
ld a, $74
ld [hl], a
- hlCoord 2, 17
- ld de, .titlescreenTilemap ; $437f
+
+; place tiles for title screen copyright
+ coord hl, 2, 17
+ ld de, .tileScreenCopyrightTiles
ld b, $10
-.asm_4377
+.tileScreenCopyrightTilesLoop
ld a, [de]
ld [hli], a
inc de
dec b
- jr nz, .asm_4377
- jr .asm_438f
+ jr nz, .tileScreenCopyrightTilesLoop
+
+ jr .next
-.titlescreenTilemap ; 437f (1:437f)
+.tileScreenCopyrightTiles
db $41,$42,$43,$42,$44,$42,$45,$46,$47,$48,$49,$4A,$4B,$4C,$4D,$4E ; ©'95.'96.'98 GAME FREAK inc.
-.asm_438f
+.next
call SaveScreenTilesToBuffer2
call LoadScreenTilesFromBuffer2
call EnableLCD
@@ -121,39 +124,41 @@ IF DEF(_BLUE)
ld a,SQUIRTLE ; which Pokemon to show first on the title screen
ENDC
- ld [wWhichTrade], a ; wWhichTrade
- call Func_4524
- ld a, $9b
- call Func_4533
+ ld [wTitleMonSpecies], a
+ call LoadTitleMonSprite
+ ld a, (vBGMap0 + $300) / $100
+ call TitleScreenCopyTileMapToVRAM
call SaveScreenTilesToBuffer1
ld a, $40
ld [hWY], a
call LoadScreenTilesFromBuffer2
- ld a, $98
- call Func_4533
- ld b, $6
- call GoPAL_SET
+ ld a, vBGMap0 / $100
+ call TitleScreenCopyTileMapToVRAM
+ ld b, SET_PAL_TITLE_SCREEN
+ call RunPaletteCommand
call GBPalNormal
- ld a, $e4
- ld [rOBP0], a ; $ff48
- ld bc, $ffaf ; background scroll Y
- ld hl, .TitleScreenPokemonLogoYScrolls ; $43db
-.asm_43c6
+ ld a, %11100100
+ ld [rOBP0], a
+
+; make pokemon logo bounce up and down
+ ld bc, hSCY ; background scroll Y
+ ld hl, .TitleScreenPokemonLogoYScrolls
+.bouncePokemonLogoLoop
ld a, [hli]
and a
- jr z, .asm_43f4
+ jr z, .finishedBouncingPokemonLogo
ld d, a
- cp $fd
- jr nz, .asm_43d4
- ld a, (SFX_1f_62 - SFX_Headers_1f) / 3
+ cp -3
+ jr nz, .skipPlayingSound
+ ld a, SFX_INTRO_CRASH
call PlaySound
-.asm_43d4
+.skipPlayingSound
ld a, [hli]
ld e, a
call .ScrollTitleScreenPokemonLogo
- jr .asm_43c6
+ jr .bouncePokemonLogoLoop
-.TitleScreenPokemonLogoYScrolls: ; 43db (1:43db)
+.TitleScreenPokemonLogoYScrolls:
; Controls the bouncing effect of the Pokemon logo on the title screen
db -4,16 ; y scroll amount, number of times to scroll
db 3,4
@@ -164,62 +169,69 @@ ENDC
db -1,2
db 0 ; terminate list with 0
-.ScrollTitleScreenPokemonLogo
+.ScrollTitleScreenPokemonLogo:
; Scrolls the Pokemon logo on the title screen to create the bouncing effect
; Scrolls d pixels e times
call DelayFrame
- ld a, [bc]
+ ld a, [bc] ; background scroll Y
add d
ld [bc], a
dec e
jr nz, .ScrollTitleScreenPokemonLogo
ret
-.asm_43f4
+
+.finishedBouncingPokemonLogo
call LoadScreenTilesFromBuffer1
- ld c, $24
+ ld c, 36
call DelayFrames
- ld a, (SFX_1f_63 - SFX_Headers_1f) / 3
+ ld a, SFX_INTRO_WHOOSH
call PlaySound
+
+; scroll game version in from the right
call PrintGameVersionOnTitleScreen
- ld a, $90
+ ld a, SCREEN_HEIGHT_PIXELS
ld [hWY], a
- ld d, $90
-.asm_440a
+ ld d, 144
+.scrollTitleScreenGameVersionLoop
ld h, d
- ld l, $40
- call Func_44cf
- ld h, $0
- ld l, $50
- call Func_44cf
+ ld l, 64
+ call ScrollTitleScreenGameVersion
+ ld h, 0
+ ld l, 80
+ call ScrollTitleScreenGameVersion
ld a, d
- add $4
+ add 4
ld d, a
and a
- jr nz, .asm_440a
- ld a, $9c
- call Func_4533
+ jr nz, .scrollTitleScreenGameVersionLoop
+
+ ld a, vBGMap1 / $100
+ call TitleScreenCopyTileMapToVRAM
call LoadScreenTilesFromBuffer2
call PrintGameVersionOnTitleScreen
call Delay3
call WaitForSoundToFinish
ld a, MUSIC_TITLE_SCREEN
- ld [wc0ee], a
+ ld [wNewSoundID], a
call PlaySound
xor a
- ld [wcc5b], a
-.asm_443b
- ld c, $c8
+ ld [wUnusedCC5B], a
+
+; Keep scrolling in new mons indefinitely until the user performs input.
+.awaitUserInterruptionLoop
+ ld c, 200
call CheckForUserInterruption
- jr c, .asm_4459
- call Func_44c1
- ld c, $1
+ jr c, .finishedWaiting
+ call TitleScreenScrollInMon
+ ld c, 1
call CheckForUserInterruption
- jr c, .asm_4459
- callba Func_372ac
- call Func_4496
- jr .asm_443b
-.asm_4459
- ld a, [wWhichTrade] ; wWhichTrade
+ jr c, .finishedWaiting
+ callba TitleScreenAnimateBallIfStarterOut
+ call TitleScreenPickNewMon
+ jr .awaitUserInterruptionLoop
+
+.finishedWaiting
+ ld a, [wTitleMonSpecies]
call PlayCry
call WaitForSoundToFinish
call GBPalWhiteOutWithDelay3
@@ -227,12 +239,12 @@ ENDC
xor a
ld [hWY], a
inc a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
call ClearScreen
- ld a, $98
- call Func_4533
- ld a, $9c
- call Func_4533
+ ld a, vBGMap0 / $100
+ call TitleScreenCopyTileMapToVRAM
+ ld a, vBGMap1 / $100
+ call TitleScreenCopyTileMapToVRAM
call Delay3
call LoadGBPal
ld a, [hJoyHeld]
@@ -243,16 +255,14 @@ ENDC
jp MainMenu
.doClearSaveDialogue
- ld b, BANK(DoClearSaveDialogue)
- ld hl, DoClearSaveDialogue
- jp Bankswitch
+ jpba DoClearSaveDialogue
-Func_4496: ; 4496 (1:4496)
- ld a, $98
- call Func_4533
+TitleScreenPickNewMon:
+ ld a, vBGMap0 / $100
+ call TitleScreenCopyTileMapToVRAM
-.new
-; Generate a new TitleMon.
+.loop
+; Keep looping until a mon different from the current one is picked.
call Random
and $f
ld c, a
@@ -260,14 +270,14 @@ Func_4496: ; 4496 (1:4496)
ld hl, TitleMons
add hl, bc
ld a, [hl]
- ld hl, wWhichTrade ; wWhichTrade
+ ld hl, wTitleMonSpecies
; Can't be the same as before.
cp [hl]
- jr z, .new
+ jr z, .loop
ld [hl], a
- call Func_4524
+ call LoadTitleMonSprite
ld a, $90
ld [hWY], a
@@ -275,98 +285,98 @@ Func_4496: ; 4496 (1:4496)
callba TitleScroll
ret
-Func_44c1: ; 44c1 (1:44c1)
+TitleScreenScrollInMon:
ld d, 0 ; scroll in
callba TitleScroll
xor a
ld [hWY], a
ret
-Func_44cf: ; 44cf (1:44cf)
+ScrollTitleScreenGameVersion:
.wait
- ld a, [$ff44] ; rLY
+ ld a, [rLY]
cp l
jr nz, .wait
ld a, h
- ld [rSCX], a ; $ff43
+ ld [rSCX], a
.wait2
- ld a, [$ff44] ; rLY
+ ld a, [rLY]
cp h
jr z, .wait2
ret
-Func_44dd: ; 44dd (1:44dd)
- ld hl, PlayerCharacterTitleGraphics ; $66a8
+DrawPlayerCharacter:
+ ld hl, PlayerCharacterTitleGraphics
ld de, vSprites
- ld bc, $230
+ ld bc, PlayerCharacterTitleGraphicsEnd - PlayerCharacterTitleGraphics
ld a, BANK(PlayerCharacterTitleGraphics)
call FarCopyData2
call ClearSprites
xor a
- ld [wWhichTrade], a ; wWhichTrade
+ ld [wPlayerCharacterOAMTile], a
ld hl, wOAMBuffer
ld de, $605a
- ld b, $7
-.asm_44fa
+ ld b, 7
+.loop
push de
- ld c, $5
-.asm_44fd
+ ld c, 5
+.innerLoop
ld a, d
- ld [hli], a
+ ld [hli], a ; Y
ld a, e
- ld [hli], a
- add $8
+ ld [hli], a ; X
+ add 8
ld e, a
- ld a, [wWhichTrade] ; wWhichTrade
- ld [hli], a
+ ld a, [wPlayerCharacterOAMTile]
+ ld [hli], a ; tile
inc a
- ld [wWhichTrade], a ; wWhichTrade
+ ld [wPlayerCharacterOAMTile], a
inc hl
dec c
- jr nz, .asm_44fd
+ jr nz, .innerLoop
pop de
- ld a, $8
+ ld a, 8
add d
ld d, a
dec b
- jr nz, .asm_44fa
+ jr nz, .loop
ret
-Func_4519: ; 4519 (1:4519)
+ClearBothBGMaps:
ld hl, vBGMap0
- ld bc, $800
- ld a, $7f
+ ld bc, $400 * 2
+ ld a, " "
jp FillMemory
-Func_4524: ; 4524 (1:4524)
+LoadTitleMonSprite:
ld [wcf91], a
ld [wd0b5], a
- hlCoord 5, 10
+ coord hl, 5, 10
call GetMonHeader
jp LoadFrontSpriteByMonIndex
-Func_4533: ; 4533 (1:4533)
- ld [$ffbd], a
+TitleScreenCopyTileMapToVRAM:
+ ld [H_AUTOBGTRANSFERDEST + 1], a
jp Delay3
-LoadCopyrightAndTextBoxTiles: ; 4538 (1:4538)
+LoadCopyrightAndTextBoxTiles:
xor a
ld [hWY], a
call ClearScreen
call LoadTextBoxTilePatterns
-LoadCopyrightTiles: ; 4541 (1:4541)
- ld de, NintendoCopyrightLogoGraphics ; $60c8
+LoadCopyrightTiles:
+ ld de, NintendoCopyrightLogoGraphics
ld hl, vChars2 + $600
- ld bc, (BANK(NintendoCopyrightLogoGraphics) << 8) + $1c
+ lb bc, BANK(NintendoCopyrightLogoGraphics), (GamefreakLogoGraphicsEnd - NintendoCopyrightLogoGraphics) / $10
call CopyVideoData
- hlCoord 2, 7
- ld de, CopyrightTextString ; $4556
+ coord hl, 2, 7
+ ld de, CopyrightTextString
jp PlaceString
-CopyrightTextString: ; 4556 (1:4556)
+CopyrightTextString:
db $60,$61,$62,$61,$63,$61,$64,$7F,$65,$66,$67,$68,$69,$6A ; ©'95.'96.'98 Nintendo
next $60,$61,$62,$61,$63,$61,$64,$7F,$6B,$6C,$6D,$6E,$6F,$70,$71,$72 ; ©'95.'96.'98 Creatures inc.
next $60,$61,$62,$61,$63,$61,$64,$7F,$73,$74,$75,$76,$77,$78,$79,$7A,$7B ; ©'95.'96.'98 GAME FREAK inc.
@@ -375,16 +385,19 @@ CopyrightTextString: ; 4556 (1:4556)
INCLUDE "data/title_mons.asm"
; prints version text (red, blue)
-PrintGameVersionOnTitleScreen: ; 4598 (1:4598)
- hlCoord 7, 8
+PrintGameVersionOnTitleScreen:
+ coord hl, 7, 8
ld de, VersionOnTitleScreenText
jp PlaceString
; these point to special tiles specifically loaded for that purpose and are not usual text
-VersionOnTitleScreenText: ; 45a1 (1:45a1)
+VersionOnTitleScreenText:
IF DEF(_RED)
db $60,$61,$7F,$65,$66,$67,$68,$69,"@" ; "Red Version"
ENDC
IF DEF(_BLUE)
db $61,$62,$63,$64,$65,$66,$67,$68,"@" ; "Blue Version"
ENDC
+
+NintenText: db "NINTEN@"
+SonyText: db "SONY@"
diff --git a/engine/titlescreen2.asm b/engine/titlescreen2.asm
index dc1c633a..2346fcc5 100755
--- a/engine/titlescreen2.asm
+++ b/engine/titlescreen2.asm
@@ -1,22 +1,22 @@
-TitleScroll_WaitBall: ; 37244 (d:7244)
+TitleScroll_WaitBall:
; Wait around for the TitleBall animation to play out.
; hi: speed
; lo: duration
db $05, $05, 0
-TitleScroll_In: ; 37247 (d:7247)
+TitleScroll_In:
; Scroll a TitleMon in from the right.
; hi: speed
; lo: duration
db $a2, $94, $84, $63, $52, $31, $11, 0
-TitleScroll_Out: ; 3724f (d:724f)
+TitleScroll_Out:
; Scroll a TitleMon out to the left.
; hi: speed
; lo: duration
db $12, $22, $32, $42, $52, $62, $83, $93, 0
-TitleScroll: ; 37258 (d:7258)
+TitleScroll:
ld a, d
ld bc, TitleScroll_In
@@ -31,7 +31,7 @@ TitleScroll: ; 37258 (d:7258)
ld e, 0 ; don't animate titleball
.ok
-_TitleScroll: ; 3726a (d:726a)
+_TitleScroll:
ld a, [bc]
and a
ret z
@@ -67,29 +67,29 @@ _TitleScroll: ; 3726a (d:726a)
pop bc
jr _TitleScroll
-.ScrollBetween ; 37292 (d:7292)
+.ScrollBetween:
.wait
- ld a, [$ff44] ; rLY
+ ld a, [rLY] ; rLY
cp l
jr nz, .wait
ld a, h
- ld [rSCX], a ; $ff43
+ ld [rSCX], a
.wait2
- ld a, [$ff44] ; rLY
+ ld a, [rLY] ; rLY
cp h
jr z, .wait2
ret
-TitleBallYTable: ; 372a0 (d:72a0)
+TitleBallYTable:
; OBJ y-positions for the Poke Ball held by Red in the title screen.
; This is really two 0-terminated lists. Initiated with an index of 1.
db 0, $71, $6f, $6e, $6d, $6c, $6d, $6e, $6f, $71, $74, 0
-Func_372ac: ; 372ac (d:72ac)
+TitleScreenAnimateBallIfStarterOut:
; Animate the TitleBall if a starter just got scrolled out.
- ld a, [wWhichTrade] ; wWhichTrade
+ ld a, [wTitleMonSpecies]
cp STARTER1
jr z, .ok
cp STARTER2
@@ -102,7 +102,7 @@ Func_372ac: ; 372ac (d:72ac)
ld d, 0
jp _TitleScroll
-GetTitleBallY: ; 372c4 (d:72c4)
+GetTitleBallY:
; Get position e from TitleBallYTable
push de
push hl
diff --git a/engine/town_map.asm b/engine/town_map.asm
index 5a718519..d417e0a3 100755
--- a/engine/town_map.asm
+++ b/engine/town_map.asm
@@ -1,4 +1,4 @@
-DisplayTownMap: ; 70e3e (1c:4e3e)
+DisplayTownMap:
call LoadTownMap
ld hl, wUpdateSpritesEnabled
ld a, [hl]
@@ -7,11 +7,11 @@ DisplayTownMap: ; 70e3e (1c:4e3e)
push hl
ld a, $1
ld [hJoy7], a
- ld a, [W_CURMAP] ; W_CURMAP
+ ld a, [wCurMap]
push af
ld b, $0
- call Func_711c4
- hlCoord 1, 0
+ call DrawPlayerOrBirdSprite ; player sprite
+ coord hl, 1, 0
ld de, wcd6d
call PlaceString
ld hl, wOAMBuffer
@@ -19,191 +19,190 @@ DisplayTownMap: ; 70e3e (1c:4e3e)
ld bc, $10
call CopyData
ld hl, vSprites + $40
- ld de, TownMapCursor ; $4f40
- ld bc, (BANK(TownMapCursor) << 8) + $04
+ ld de, TownMapCursor
+ lb bc, BANK(TownMapCursor), (TownMapCursorEnd - TownMapCursor) / $8
call CopyVideoDataDouble
xor a
- ld [wWhichTrade], a ; wWhichTrade
+ ld [wWhichTownMapLocation], a
pop af
- jr Func_70e92
+ jr .enterLoop
-Func_70e7e: ; 70e7e (1c:4e7e)
- ld hl, wTileMap
- ld bc, $114
+.townMapLoop
+ coord hl, 0, 0
+ lb bc, 1, 20
call ClearScreenArea
- ld hl, TownMapOrder ; $4f11
- ld a, [wWhichTrade] ; wWhichTrade
+ ld hl, TownMapOrder
+ ld a, [wWhichTownMapLocation]
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hl]
-
-Func_70e92: ; 70e92 (1c:4e92)
- ld de, wHPBarMaxHP
- call Func_712f1
+.enterLoop
+ ld de, wTownMapCoords
+ call LoadTownMapEntry
ld a, [de]
push hl
- call Func_71258
+ call TownMapCoordsToOAMCoords
ld a, $4
- ld [wcd5b], a
+ ld [wOAMBaseTile], a
ld hl, wOAMBuffer + $10
- call Func_71279
+ call WriteTownMapSpriteOAM ; town map cursor sprite
pop hl
ld de, wcd6d
-.asm_70eac
+.copyMapName
ld a, [hli]
ld [de], a
inc de
cp $50
- jr nz, .asm_70eac
- hlCoord 1, 0
+ jr nz, .copyMapName
+ coord hl, 1, 0
ld de, wcd6d
call PlaceString
ld hl, wOAMBuffer + $10
ld de, wTileMapBackup + 16
ld bc, $10
call CopyData
-.asm_70ec8
+.inputLoop
call TownMapSpriteBlinkingAnimation
call JoypadLowSensitivity
ld a, [hJoy5]
ld b, a
- and $c3
- jr z, .asm_70ec8
- ld a, (SFX_02_3c - SFX_Headers_02) / 3
+ and A_BUTTON | B_BUTTON | D_UP | D_DOWN
+ jr z, .inputLoop
+ ld a, SFX_TINK
call PlaySound
bit 6, b
- jr nz, .asm_70ef2
+ jr nz, .pressedUp
bit 7, b
- jr nz, .asm_70f01
+ jr nz, .pressedDown
xor a
ld [wTownMapSpriteBlinkingEnabled], a
ld [hJoy7], a
- ld [wTownMapSpriteBlinkingCounter], a
- call Func_711ab
+ ld [wAnimCounter], a
+ call ExitTownMap
pop hl
pop af
ld [hl], a
ret
-.asm_70ef2
- ld a, [wWhichTrade] ; wWhichTrade
+.pressedUp
+ ld a, [wWhichTownMapLocation]
inc a
- cp $2f
- jr nz, .asm_70efb
+ cp TownMapOrderEnd - TownMapOrder ; number of list items + 1
+ jr nz, .noOverflow
xor a
-.asm_70efb
- ld [wWhichTrade], a ; wWhichTrade
- jp Func_70e7e
-.asm_70f01
- ld a, [wWhichTrade] ; wWhichTrade
+.noOverflow
+ ld [wWhichTownMapLocation], a
+ jp .townMapLoop
+.pressedDown
+ ld a, [wWhichTownMapLocation]
dec a
- cp $ff
- jr nz, .asm_70f0b
- ld a, $2e
-.asm_70f0b
- ld [wWhichTrade], a ; wWhichTrade
- jp Func_70e7e
+ cp -1
+ jr nz, .noUnderflow
+ ld a, TownMapOrderEnd - TownMapOrder - 1 ; number of list items
+.noUnderflow
+ ld [wWhichTownMapLocation], a
+ jp .townMapLoop
INCLUDE "data/town_map_order.asm"
-TownMapCursor: ; 70f40 (1c:4f40)
+TownMapCursor:
INCBIN "gfx/town_map_cursor.1bpp"
+TownMapCursorEnd:
-LoadTownMap_Nest: ; 70f60 (1c:4f60)
+LoadTownMap_Nest:
call LoadTownMap
ld hl, wUpdateSpritesEnabled
ld a, [hl]
push af
ld [hl], $ff
push hl
- call Func_711ef
+ call DisplayWildLocations
call GetMonName
- hlCoord 1, 0
+ coord hl, 1, 0
call PlaceString
ld h, b
ld l, c
ld de, MonsNestText
call PlaceString
call WaitForTextScrollButtonPress
- call Func_711ab
+ call ExitTownMap
pop hl
pop af
ld [hl], a
ret
-MonsNestText: ; 70f89 (1c:4f89)
+MonsNestText:
db "'s NEST@"
-LoadTownMap_Fly: ; 70f90 (1c:4f90)
+LoadTownMap_Fly:
call ClearSprites
call LoadTownMap
call LoadPlayerSpriteGraphics
call LoadFontTilePatterns
- ld de, BirdSprite ; $4d80
+ ld de, BirdSprite
ld hl, vSprites + $40
- ld bc, (BANK(BirdSprite) << 8) + $0c
+ lb bc, BANK(BirdSprite), $c
call CopyVideoData
- ld de, TownMapUpArrow ; $5093
+ ld de, TownMapUpArrow
ld hl, vChars1 + $6d0
- ld bc, (BANK(TownMapUpArrow) << 8) + $01
+ lb bc, BANK(TownMapUpArrow), (TownMapUpArrowEnd - TownMapUpArrow) / $8
call CopyVideoDataDouble
- call Func_71070
+ call BuildFlyLocationsList
ld hl, wUpdateSpritesEnabled
ld a, [hl]
push af
ld [hl], $ff
push hl
- ld hl, wTileMap
+ coord hl, 0, 0
ld de, ToText
call PlaceString
- ld a, [W_CURMAP] ; W_CURMAP
+ ld a, [wCurMap]
ld b, $0
- call Func_711c4
- ld hl, wTrainerEngageDistance
- deCoord 18, 0
-
+ call DrawPlayerOrBirdSprite
+ ld hl, wFlyLocationsList
+ coord de, 18, 0
.townMapFlyLoop
- ld a, $7f
+ ld a, " "
ld [de], a
push hl
push hl
- hlCoord 3, 0
- ld bc, $10f
+ coord hl, 3, 0
+ lb bc, 1, 15
call ClearScreenArea
pop hl
ld a, [hl]
ld b, $4
- call Func_711c4
- hlCoord 3, 0
+ call DrawPlayerOrBirdSprite ; draw bird sprite
+ coord hl, 3, 0
ld de, wcd6d
call PlaceString
- ld c, $f
+ ld c, 15
call DelayFrames
- hlCoord 18, 0
- ld [hl], $ed
- hlCoord 19, 0
- ld [hl], $ee
+ coord hl, 18, 0
+ ld [hl], "▲"
+ coord hl, 19, 0
+ ld [hl], "▼"
pop hl
-.asm_71004
+.inputLoop
push hl
call DelayFrame
call JoypadLowSensitivity
ld a, [hJoy5]
ld b, a
pop hl
- and $c3
- jr z, .asm_71004
+ and A_BUTTON | B_BUTTON | D_UP | D_DOWN
+ jr z, .inputLoop
bit 0, b
- jr nz, .asm_71026
- ld a, (SFX_02_3c - SFX_Headers_02) / 3
+ jr nz, .pressedA
+ ld a, SFX_TINK
call PlaySound
bit 6, b
- jr nz, .asm_71042
+ jr nz, .pressedUp
bit 7, b
- jr nz, .asm_71058
- jr .asm_71037
-.asm_71026
- ld a, (SFX_02_3e - SFX_Headers_02) / 3
+ jr nz, .pressedDown
+ jr .pressedB
+.pressedA
+ ld a, SFX_HEAL_AILMENT
call PlaySound
ld a, [hl]
ld [wDestinationMap], a
@@ -211,7 +210,7 @@ LoadTownMap_Fly: ; 70f90 (1c:4f90)
set 3, [hl]
inc hl
set 7, [hl]
-.asm_71037
+.pressedB
xor a
ld [wTownMapSpriteBlinkingEnabled], a
call GBPalWhiteOutWithDelay3
@@ -219,86 +218,87 @@ LoadTownMap_Fly: ; 70f90 (1c:4f90)
pop af
ld [hl], a
ret
-.asm_71042
- deCoord 18, 0
+.pressedUp
+ coord de, 18, 0
inc hl
ld a, [hl]
cp $ff
- jr z, .asm_71052
+ jr z, .wrapToStartOfList
cp $fe
- jr z, .asm_71042
+ jr z, .pressedUp ; skip past unvisited towns
jp .townMapFlyLoop
-.asm_71052
- ld hl, wTrainerEngageDistance
+.wrapToStartOfList
+ ld hl, wFlyLocationsList
jp .townMapFlyLoop
-.asm_71058
- deCoord 19, 0
+.pressedDown
+ coord de, 19, 0
dec hl
ld a, [hl]
cp $ff
- jr z, .asm_71068
+ jr z, .wrapToEndOfList
cp $fe
- jr z, .asm_71058
+ jr z, .pressedDown ; skip past unvisited towns
jp .townMapFlyLoop
-.asm_71068
- ld hl, wcd49
- jr .asm_71058
+.wrapToEndOfList
+ ld hl, wFlyLocationsList + 11
+ jr .pressedDown
-ToText: ; 7106d (1c:506d)
+ToText:
db "To@"
-Func_71070: ; 71070 (1c:5070)
- ld hl, wWhichTrade ; wWhichTrade
+BuildFlyLocationsList:
+ ld hl, wFlyLocationsList - 1
ld [hl], $ff
inc hl
- ld a, [W_TOWNVISITEDFLAG]
+ ld a, [wTownVisitedFlag]
ld e, a
- ld a, [W_TOWNVISITEDFLAG + 1]
+ ld a, [wTownVisitedFlag + 1]
ld d, a
- ld bc, $b
-.asm_71081
+ ld bc, SAFFRON_CITY + 1
+.loop
srl d
rr e
- ld a, $fe
- jr nc, .asm_7108a
- ld a, b
-.asm_7108a
+ ld a, $fe ; store $fe if the town hasn't been visited
+ jr nc, .notVisited
+ ld a, b ; store the map number of the town if it has been visited
+.notVisited
ld [hl], a
inc hl
inc b
dec c
- jr nz, .asm_71081
+ jr nz, .loop
ld [hl], $ff
ret
-TownMapUpArrow: ; 71093 (1c:5093)
+TownMapUpArrow:
INCBIN "gfx/up_arrow.1bpp"
+TownMapUpArrowEnd:
-LoadTownMap: ; 7109b (1c:509b)
+LoadTownMap:
call GBPalWhiteOutWithDelay3
call ClearScreen
call UpdateSprites
- ld hl, wTileMap
+ coord hl, 0, 0
ld b, $12
ld c, $12
call TextBoxBorder
call DisableLCD
- ld hl, WorldMapTileGraphics ; $65a8
+ ld hl, WorldMapTileGraphics
ld de, vChars2 + $600
- ld bc, $100
+ ld bc, WorldMapTileGraphicsEnd - WorldMapTileGraphics
ld a, BANK(WorldMapTileGraphics)
call FarCopyData2
- ld hl, MonNestIcon ; $56be
+ ld hl, MonNestIcon
ld de, vSprites + $40
- ld bc, $8
+ ld bc, MonNestIconEnd - MonNestIcon
ld a, BANK(MonNestIcon)
call FarCopyDataDouble
- ld hl, wTileMap
- ld de, CompressedMap ; $5100
-.asm_710d3
+ coord hl, 0, 0
+ ld de, CompressedMap
+.nextTile
ld a, [de]
and a
- jr z, .asm_710e9
+ jr z, .done
ld b, a
and $f
ld c, a
@@ -306,29 +306,30 @@ LoadTownMap: ; 7109b (1c:509b)
swap a
and $f
add $60
-.asm_710e2
+.writeRunLoop
ld [hli], a
dec c
- jr nz, .asm_710e2
+ jr nz, .writeRunLoop
inc de
- jr .asm_710d3
-.asm_710e9
+ jr .nextTile
+.done
call EnableLCD
- ld b, $2
- call GoPAL_SET
+ ld b, SET_PAL_TOWN_MAP
+ call RunPaletteCommand
call Delay3
call GBPalNormal
xor a
- ld [wTownMapSpriteBlinkingCounter], a
+ ld [wAnimCounter], a
inc a
ld [wTownMapSpriteBlinkingEnabled], a
ret
-CompressedMap: ; 71100 (1c:5100)
+CompressedMap:
; you can decompress this file with the redrle program in the extras/ dir
INCBIN "gfx/town_map.rle"
-Func_711ab: ; 711ab (1c:51ab)
+ExitTownMap:
+; clear town map graphics data and load usual graphics data
xor a
ld [wTownMapSpriteBlinkingEnabled], a
call GBPalWhiteOut
@@ -337,117 +338,126 @@ Func_711ab: ; 711ab (1c:51ab)
call LoadPlayerSpriteGraphics
call LoadFontTilePatterns
call UpdateSprites
- jp GoPAL_SET_CF1C
+ jp RunDefaultPaletteCommand
-Func_711c4: ; 711c4 (1c:51c4)
+DrawPlayerOrBirdSprite:
+; a = map number
+; b = OAM base tile
push af
ld a, b
- ld [wcd5b], a
+ ld [wOAMBaseTile], a
pop af
- ld de, wHPBarMaxHP
- call Func_712f1
+ ld de, wTownMapCoords
+ call LoadTownMapEntry
ld a, [de]
push hl
- call Func_71258
- call Func_7126d
+ call TownMapCoordsToOAMCoords
+ call WritePlayerOrBirdSpriteOAM
pop hl
ld de, wcd6d
-.asm_711dc
+.loop
ld a, [hli]
ld [de], a
inc de
- cp $50
- jr nz, .asm_711dc
+ cp "@"
+ jr nz, .loop
ld hl, wOAMBuffer
ld de, wTileMapBackup
ld bc, $a0
jp CopyData
-Func_711ef: ; 711ef (1c:51ef)
+DisplayWildLocations:
callba FindWildLocationsOfMon
- call Func_712d9
+ call ZeroOutDuplicatesInList
ld hl, wOAMBuffer
- ld de, wBuffer
-.asm_71200
+ ld de, wTownMapCoords
+.loop
ld a, [de]
cp $ff
- jr z, .asm_7121d
+ jr z, .exitLoop
and a
- jr z, .asm_7121a
+ jr z, .nextEntry
push hl
- call Func_712f1
+ call LoadTownMapEntry
pop hl
ld a, [de]
- cp $19
- jr z, .asm_7121a
- call Func_71258
- ld a, $4
+ cp $19 ; Cerulean Cave's coordinates
+ jr z, .nextEntry ; skip Cerulean Cave
+ call TownMapCoordsToOAMCoords
+ ld a, $4 ; nest icon tile no.
ld [hli], a
xor a
ld [hli], a
-.asm_7121a
+.nextEntry
inc de
- jr .asm_71200
-.asm_7121d
+ jr .loop
+.exitLoop
ld a, l
- and a
- jr nz, .asm_71236
- hlCoord 1, 7
- ld b, $2
- ld c, $f
+ and a ; were any OAM entries written?
+ jr nz, .drawPlayerSprite
+; if no OAM entries were written, print area unknown text
+ coord hl, 1, 7
+ ld b, 2
+ ld c, 15
call TextBoxBorder
- hlCoord 2, 9
+ coord hl, 2, 9
ld de, AreaUnknownText
call PlaceString
- jr .asm_7123e
-.asm_71236
- ld a, [W_CURMAP] ; W_CURMAP
+ jr .done
+.drawPlayerSprite
+ ld a, [wCurMap]
ld b, $0
- call Func_711c4
-.asm_7123e
+ call DrawPlayerOrBirdSprite
+.done
ld hl, wOAMBuffer
ld de, wTileMapBackup
ld bc, $a0
jp CopyData
-AreaUnknownText: ; 7124a (1c:524a)
+AreaUnknownText:
db " AREA UNKNOWN@"
-Func_71258: ; 71258 (1c:5258)
+TownMapCoordsToOAMCoords:
+; in: lower nybble of a = x, upper nybble of a = y
+; out: b and [hl] = (y * 8) + 24, c and [hl+1] = (x * 8) + 24
push af
and $f0
srl a
- add $18
+ add 24
ld b, a
ld [hli], a
pop af
and $f
swap a
srl a
- add $18
+ add 24
ld c, a
ld [hli], a
ret
-Func_7126d: ; 7126d (1c:526d)
- ld a, [wcd5b]
+WritePlayerOrBirdSpriteOAM:
+ ld a, [wOAMBaseTile]
and a
- ld hl, wOAMBuffer + $90
- jr z, Func_71279
- ld hl, wOAMBuffer + $80
+ ld hl, wOAMBuffer + $90 ; for player sprite
+ jr z, WriteTownMapSpriteOAM
+ ld hl, wOAMBuffer + $80 ; for bird sprite
-Func_71279: ; 71279 (1c:5279)
+WriteTownMapSpriteOAM:
push hl
- ld hl, $fcfc
+
+; Subtract 4 from c (X coord) and 4 from b (Y coord). However, the carry from c
+; is added to b, so the net result is that only 3 is subtracted from b.
+ lb hl, -4, -4
add hl, bc
+
ld b, h
ld c, l
pop hl
-WriteAsymmetricMonPartySpriteOAM: ; 71281 (1c:5281)
-; Writes 4 OAM blocks for a helix mon party sprite, since is does not have
+WriteAsymmetricMonPartySpriteOAM:
+; Writes 4 OAM blocks for a helix mon party sprite, since it does not have
; a vertical line of symmetry.
- ld de, $202
+ lb de, 2, 2
.loop
push de
push bc
@@ -456,51 +466,51 @@ WriteAsymmetricMonPartySpriteOAM: ; 71281 (1c:5281)
ld [hli], a
ld a, c
ld [hli], a
- ld a, [wcd5b]
+ ld a, [wOAMBaseTile]
ld [hli], a
inc a
- ld [wcd5b], a
+ ld [wOAMBaseTile], a
xor a
ld [hli], a
inc d
- ld a, $8
+ ld a, 8
add c
ld c, a
dec e
jr nz, .innerLoop
pop bc
pop de
- ld a, $8
+ ld a, 8
add b
ld b, a
dec d
jr nz, .loop
ret
-WriteSymmetricMonPartySpriteOAM: ; 712a6 (1c:52a6)
+WriteSymmetricMonPartySpriteOAM:
; Writes 4 OAM blocks for a mon party sprite other than a helix. All the
; sprites other than the helix one have a vertical line of symmetry which allows
; the X-flip OAM bit to be used so that only 2 rather than 4 tile patterns are
; needed.
xor a
- ld [wcd5c], a
- ld de, $202
+ ld [wSymmetricSpriteOAMAttributes], a
+ lb de, 2, 2
.loop
push de
push bc
.innerLoop
ld a, b
- ld [hli], a
+ ld [hli], a ; Y
ld a, c
- ld [hli], a
- ld a, [wcd5b]
- ld [hli], a
- ld a, [wcd5c]
- ld [hli], a
- xor $20
- ld [wcd5c], a
+ ld [hli], a ; X
+ ld a, [wOAMBaseTile]
+ ld [hli], a ; tile
+ ld a, [wSymmetricSpriteOAMAttributes]
+ ld [hli], a ; attributes
+ xor (1 << OAM_X_FLIP)
+ ld [wSymmetricSpriteOAMAttributes], a
inc d
- ld a, $8
+ ld a, 8
add c
ld c, a
dec e
@@ -508,20 +518,21 @@ WriteSymmetricMonPartySpriteOAM: ; 712a6 (1c:52a6)
pop bc
pop de
push hl
- ld hl, wcd5b
+ ld hl, wOAMBaseTile
inc [hl]
inc [hl]
pop hl
- ld a, $8
+ ld a, 8
add b
ld b, a
dec d
jr nz, .loop
ret
-Func_712d9: ; 712d9 (1c:52d9)
- ld de, wHPBarMaxHP
-.asm_712dc
+ZeroOutDuplicatesInList:
+; replace duplicate bytes in the list of wild pokemon locations with 0
+ ld de, wBuffer
+.loop
ld a, [de]
inc de
cp $ff
@@ -529,39 +540,41 @@ Func_712d9: ; 712d9 (1c:52d9)
ld c, a
ld l, e
ld h, d
-.asm_712e4
+.zeroDuplicatesLoop
ld a, [hl]
cp $ff
- jr z, .asm_712dc
+ jr z, .loop
cp c
- jr nz, .asm_712ee
+ jr nz, .skipZeroing
xor a
ld [hl], a
-.asm_712ee
+.skipZeroing
inc hl
- jr .asm_712e4
+ jr .zeroDuplicatesLoop
-Func_712f1: ; 712f1 (1c:52f1)
+LoadTownMapEntry:
+; in: a = map number
+; out: lower nybble of [de] = x, upper nybble of [de] = y, hl = address of name
cp REDS_HOUSE_1F
- jr c, .asm_71304
- ld bc, $4
- ld hl, InternalMapEntries ; $5382
-.asm_712fb
+ jr c, .external
+ ld bc, 4
+ ld hl, InternalMapEntries
+.loop
cp [hl]
- jr c, .asm_71301
+ jr c, .foundEntry
add hl, bc
- jr .asm_712fb
-.asm_71301
+ jr .loop
+.foundEntry
inc hl
- jr .asm_7130d
-.asm_71304
- ld hl, ExternalMapEntries ; $5313
+ jr .readEntry
+.external
+ ld hl, ExternalMapEntries
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
add hl, bc
add hl, bc
-.asm_7130d
+.readEntry
ld a, [hli]
ld [de], a
ld a, [hli]
@@ -573,11 +586,12 @@ INCLUDE "data/town_map_entries.asm"
INCLUDE "text/map_names.asm"
-MonNestIcon: ; 716be (1c:56be)
+MonNestIcon:
INCBIN "gfx/mon_nest_icon.1bpp"
+MonNestIconEnd:
-TownMapSpriteBlinkingAnimation: ; 716c6 (1c:56c6)
- ld a, [wTownMapSpriteBlinkingCounter]
+TownMapSpriteBlinkingAnimation:
+ ld a, [wAnimCounter]
inc a
cp 25
jr z, .hideSprites
@@ -601,5 +615,5 @@ TownMapSpriteBlinkingAnimation: ; 716c6 (1c:56c6)
jr nz, .hideSpritesLoop
ld a, 25
.done
- ld [wTownMapSpriteBlinkingCounter], a
+ ld [wAnimCounter], a
jp DelayFrame
diff --git a/engine/trade.asm b/engine/trade.asm
index bb4fa4e1..c3913a7e 100755
--- a/engine/trade.asm
+++ b/engine/trade.asm
@@ -1,4 +1,4 @@
-InternalClockTradeAnim: ; 410e2 (10:50e2)
+InternalClockTradeAnim:
; Do the trading animation with the player's gameboy on the left.
; In-game trades and internally clocked link cable trades use this.
ld a, [wTradedPlayerMonSpecies]
@@ -8,24 +8,24 @@ InternalClockTradeAnim: ; 410e2 (10:50e2)
ld de, InternalClockTradeFuncSequence
jr TradeAnimCommon
-ExternalClockTradeAnim: ; 410f3 (10:50f3)
+ExternalClockTradeAnim:
; Do the trading animation with the player's gameboy on the right.
; Externally clocked link cable trades use this.
ld a, [wTradedEnemyMonSpecies]
ld [wLeftGBMonSpecies], a
- ld a, [wTrainerSpriteOffset]
+ ld a, [wTradedPlayerMonSpecies]
ld [wRightGBMonSpecies], a
ld de, ExternalClockTradeFuncSequence
-TradeAnimCommon: ; 41102 (10:5102)
- ld a, [W_OPTIONS]
+TradeAnimCommon:
+ ld a, [wOptions]
push af
ld a, [hSCY]
push af
ld a, [hSCX]
push af
xor a
- ld [W_OPTIONS], a
+ ld [wOptions], a
ld [hSCY], a
ld [hSCX], a
push de
@@ -53,7 +53,7 @@ TradeAnimCommon: ; 41102 (10:5102)
pop af
ld [hSCY], a
pop af
- ld [W_OPTIONS], a
+ ld [wOptions], a
ret
addtradefunc: MACRO
@@ -69,7 +69,7 @@ tradefunc: MACRO
; They are from opposite perspectives. The external clock one makes use of
; Trade_SwapNames to swap the player and enemy names for some functions.
-InternalClockTradeFuncSequence: ; 41138 (10:5138)
+InternalClockTradeFuncSequence:
tradefunc LoadTradingGFXAndMonNames
tradefunc Trade_ShowPlayerMon
tradefunc Trade_DrawOpenEndOfLinkCable
@@ -88,7 +88,7 @@ InternalClockTradeFuncSequence: ; 41138 (10:5138)
tradefunc Trade_Cleanup
db $FF
-ExternalClockTradeFuncSequence: ; 41149 (10:5149)
+ExternalClockTradeFuncSequence:
tradefunc LoadTradingGFXAndMonNames
tradefunc Trade_ShowClearedWindow
tradefunc PrintTradeWillTradeText
@@ -112,7 +112,7 @@ ExternalClockTradeFuncSequence: ; 41149 (10:5149)
tradefunc Trade_Cleanup
db $FF
-TradeFuncPointerTable: ; 4115f (10:515f)
+TradeFuncPointerTable:
addtradefunc LoadTradingGFXAndMonNames
addtradefunc Trade_ShowPlayerMon
addtradefunc Trade_DrawOpenEndOfLinkCable
@@ -131,11 +131,11 @@ TradeFuncPointerTable: ; 4115f (10:515f)
addtradefunc Trade_SlideTextBoxOffScreen
addtradefunc Trade_SwapNames
-Trade_Delay100: ; 41181 (10:5181)
+Trade_Delay100:
ld c, 100
jp DelayFrames
-Trade_CopyTileMapToVRAM: ; 41186 (10:5186)
+Trade_CopyTileMapToVRAM:
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
@@ -143,27 +143,27 @@ Trade_CopyTileMapToVRAM: ; 41186 (10:5186)
ld [H_AUTOBGTRANSFERENABLED], a
ret
-Trade_Delay80: ; 41191 (10:5191)
+Trade_Delay80:
ld c, 80
jp DelayFrames
-Trade_ClearTileMap: ; 41196 (10:5196)
- ld hl, wTileMap
- ld bc, 20 * 18
+Trade_ClearTileMap:
+ coord hl, 0, 0
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
ld a, " "
jp FillMemory
-LoadTradingGFXAndMonNames: ; 411a1 (10:51a1)
+LoadTradingGFXAndMonNames:
call Trade_ClearTileMap
call DisableLCD
ld hl, TradingAnimationGraphics
ld de, vChars2 + $310
- ld bc, $310
+ ld bc, TradingAnimationGraphicsEnd - TradingAnimationGraphics
ld a, BANK(TradingAnimationGraphics)
call FarCopyData2
ld hl, TradingAnimationGraphics2
ld de, vSprites + $7c0
- ld bc, $40
+ ld bc, TradingAnimationGraphics2End - TradingAnimationGraphics2
ld a, BANK(TradingAnimationGraphics2)
call FarCopyData2
ld hl, vBGMap0
@@ -190,41 +190,39 @@ LoadTradingGFXAndMonNames: ; 411a1 (10:51a1)
call GetMonName
ld hl, wcd6d
ld de, wcf4b
- ld bc, $b
+ ld bc, NAME_LENGTH
call CopyData
ld a, [wTradedEnemyMonSpecies]
ld [wd11e], a
jp GetMonName
-Trade_LoadMonPartySpriteGfx: ; 4120b (10:520b)
+Trade_LoadMonPartySpriteGfx:
ld a, %11010000
ld [rOBP1], a
- ld b, BANK(LoadMonPartySpriteGfx)
- ld hl, LoadMonPartySpriteGfx
- jp Bankswitch
+ jpba LoadMonPartySpriteGfx
-Trade_SwapNames: ; 41217 (10:5217)
+Trade_SwapNames:
ld hl, wPlayerName
ld de, wBuffer
- ld bc, 11
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wLinkEnemyTrainerName
ld de, wPlayerName
- ld bc, 11
+ ld bc, NAME_LENGTH
call CopyData
ld hl, wBuffer
ld de, wLinkEnemyTrainerName
- ld bc, 11
+ ld bc, NAME_LENGTH
jp CopyData
-Trade_Cleanup: ; 4123b (10:523b)
+Trade_Cleanup:
xor a
call LoadGBPal
ld hl, wd730
res 6, [hl] ; turn off instant text printing
ret
-Trade_ShowPlayerMon: ; 41245 (10:5245)
+Trade_ShowPlayerMon:
ld a, %10101011
ld [rLCDC], a
ld a, $50
@@ -234,7 +232,7 @@ Trade_ShowPlayerMon: ; 41245 (10:5245)
ld [hSCX], a
xor a
ld [H_AUTOBGTRANSFERENABLED], a
- hlCoord 4, 0
+ coord hl, 4, 0
ld b, 6
ld c, 10
call TextBoxBorder
@@ -259,31 +257,35 @@ Trade_ShowPlayerMon: ; 41245 (10:5245)
ld a, TRADE_BALL_POOF_ANIM
call Trade_ShowAnimation
ld a, TRADE_BALL_DROP_ANIM
- call Trade_ShowAnimation
+ call Trade_ShowAnimation ; clears mon pic
ld a, [wTradedPlayerMonSpecies]
call PlayCry
xor a
ld [H_AUTOBGTRANSFERENABLED], a
ret
-Trade_DrawOpenEndOfLinkCable: ; 41298 (10:5298)
+Trade_DrawOpenEndOfLinkCable:
call Trade_ClearTileMap
ld b, vBGMap0 / $100
call CopyScreenTileBufferToVRAM
- ld b, $8
- call GoPAL_SET
+ ld b, SET_PAL_GENERIC
+ call RunPaletteCommand
+
+; This function call is pointless. It just copies blank tiles to VRAM that was
+; already filled with blank tiles.
ld hl, vBGMap1 + $8c
call Trade_CopyCableTilesOffScreen
+
ld a, $a0
ld [hSCX], a
call DelayFrame
ld a, %10001011
ld [rLCDC], a
- hlCoord 6, 2
+ coord hl, 6, 2
ld b, $7 ; open end of link cable tile ID list index
call CopyTileIDsFromList_ZeroBaseTileID
call Trade_CopyTileMapToVRAM
- ld a, (SFX_02_3d - SFX_Headers_02) / 3
+ ld a, SFX_HEAL_HP
call PlaySound
ld c, 20
.loop
@@ -294,7 +296,7 @@ Trade_DrawOpenEndOfLinkCable: ; 41298 (10:5298)
jr nz, .loop
ret
-Trade_AnimateBallEnteringLinkCable: ; 412d2 (10:52d2)
+Trade_AnimateBallEnteringLinkCable:
ld a, TRADE_BALL_SHAKE_ANIM
call Trade_ShowAnimation
ld c, 10
@@ -302,25 +304,25 @@ Trade_AnimateBallEnteringLinkCable: ; 412d2 (10:52d2)
ld a, %11100100
ld [rOBP0], a
xor a
- ld [wd09f], a
- ld bc, $2060
+ ld [wLinkCableAnimBulgeToggle], a
+ lb bc, $20, $60
.moveBallInsideLinkCableLoop
push bc
xor a
ld de, Trade_BallInsideLinkCableOAM
call WriteOAMBlock
- ld a, [wd09f]
+ ld a, [wLinkCableAnimBulgeToggle]
xor $1
- ld [wd09f], a
+ ld [wLinkCableAnimBulgeToggle], a
add $7e
ld hl, wOAMBuffer + $02
- ld de, $4
+ ld de, 4
ld c, e
-.cycleSpriteFramesLoop
+.cycleLinkCableBulgeTile
ld [hl], a
add hl, de
dec c
- jr nz, .cycleSpriteFramesLoop
+ jr nz, .cycleLinkCableBulgeTile
call Delay3
pop bc
ld a, c
@@ -328,7 +330,7 @@ Trade_AnimateBallEnteringLinkCable: ; 412d2 (10:52d2)
ld c, a
cp $a0
jr nc, .ballSpriteReachedEdgeOfScreen
- ld a, (SFX_02_3c - SFX_Headers_02) / 3
+ ld a, SFX_TINK
call PlaySound
jr .moveBallInsideLinkCableLoop
.ballSpriteReachedEdgeOfScreen
@@ -343,15 +345,15 @@ Trade_AnimateBallEnteringLinkCable: ; 412d2 (10:52d2)
ld [H_AUTOBGTRANSFERENABLED], a
ret
-Trade_BallInsideLinkCableOAM: ; 4132e (10:532e)
+Trade_BallInsideLinkCableOAM:
db $7E,$00,$7E,$20
db $7E,$40,$7E,$60
-Trade_ShowEnemyMon: ; 41336 (10:5336)
+Trade_ShowEnemyMon:
ld a, TRADE_BALL_TILT_ANIM
call Trade_ShowAnimation
call Trade_ShowClearedWindow
- hlCoord 4, 10
+ coord hl, 4, 10
ld b, 6
ld c, 10
call TextBoxBorder
@@ -368,22 +370,22 @@ Trade_ShowEnemyMon: ; 41336 (10:5336)
ld a, [wTradedEnemyMonSpecies]
call PlayCry
call Trade_Delay100
- hlCoord 4, 10
- ld bc, $80c
+ coord hl, 4, 10
+ lb bc, 8, 12
call ClearScreenArea
jp PrintTradeTakeCareText
-Trade_AnimLeftToRight: ; 41376 (10:5376)
+Trade_AnimLeftToRight:
; Animates the mon moving from the left GB to the right one.
call Trade_InitGameboyTransferGfx
ld a, $1
ld [wTradedMonMovingRight], a
- ld a, $e4
+ ld a, %11100100
ld [rOBP0], a
ld a, $54
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
ld a, $1c
- ld [W_BASECOORDY], a
+ ld [wBaseCoordY], a
ld a, [wLeftGBMonSpecies]
ld [wMonPartySpriteSpecies], a
call Trade_WriteCircledMonOAM
@@ -407,15 +409,15 @@ Trade_AnimLeftToRight: ; 41376 (10:5376)
call Trade_AnimMonMoveVertical
jp ClearSprites
-Trade_AnimRightToLeft: ; 413c6 (10:53c6)
+Trade_AnimRightToLeft:
; Animates the mon moving from the right GB to the left one.
call Trade_InitGameboyTransferGfx
xor a
ld [wTradedMonMovingRight], a
ld a, $64
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
ld a, $44
- ld [W_BASECOORDY], a
+ ld [wBaseCoordY], a
ld a, [wRightGBMonSpecies]
ld [wMonPartySpriteSpecies], a
call Trade_WriteCircledMonOAM
@@ -439,7 +441,7 @@ Trade_AnimRightToLeft: ; 413c6 (10:53c6)
ld [H_AUTOBGTRANSFERENABLED], a
jp ClearSprites
-Trade_InitGameboyTransferGfx: ; 41411 (10:5411)
+Trade_InitGameboyTransferGfx:
; Initialises the graphics for showing a mon moving between gameboys.
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
@@ -456,41 +458,41 @@ Trade_InitGameboyTransferGfx: ; 41411 (10:5411)
ld [hWY], a
ret
-Trade_DrawLeftGameboy: ; 4142d (10:542d)
+Trade_DrawLeftGameboy:
call Trade_ClearTileMap
; draw link cable
- hlCoord 11, 4
+ coord hl, 11, 4
ld a, $5d
ld [hli], a
ld a, $5e
- ld c, $8
+ ld c, 8
.loop
ld [hli], a
dec c
jr nz, .loop
; draw gameboy pic
- hlCoord 5, 3
+ coord hl, 5, 3
ld b, $6
call CopyTileIDsFromList_ZeroBaseTileID
; draw text box with player name below gameboy pic
- hlCoord 4, 12
+ coord hl, 4, 12
ld b, 2
ld c, 7
call TextBoxBorder
- hlCoord 5, 14
+ coord hl, 5, 14
ld de, wPlayerName
call PlaceString
jp DelayFrame
-Trade_DrawRightGameboy: ; 4145c (10:545c)
+Trade_DrawRightGameboy:
call Trade_ClearTileMap
; draw horizontal segment of link cable
- hlCoord 0, 4
+ coord hl, 0, 4
ld a, $5e
ld c, $e
.loop
@@ -518,25 +520,25 @@ Trade_DrawRightGameboy: ; 4145c (10:545c)
ld [hl], a
; draw gameboy pic
- hlCoord 7, 8
+ coord hl, 7, 8
ld b, $6
call CopyTileIDsFromList_ZeroBaseTileID
; draw text box with enemy name above link cable
- hlCoord 6, 0
- ld b, $2
- ld c, $7
+ coord hl, 6, 0
+ ld b, 2
+ ld c, 7
call TextBoxBorder
- hlCoord 7, 2
+ coord hl, 7, 2
ld de, wLinkEnemyTrainerName
call PlaceString
jp DelayFrame
-Trade_DrawCableAcrossScreen: ; 4149f (10:549f)
+Trade_DrawCableAcrossScreen:
; Draws the link cable across the screen.
call Trade_ClearTileMap
- hlCoord 0, 4
+ coord hl, 0, 4
ld a, $5e
ld c, SCREEN_WIDTH
.loop
@@ -545,23 +547,23 @@ Trade_DrawCableAcrossScreen: ; 4149f (10:549f)
jr nz, .loop
ret
-Trade_CopyCableTilesOffScreen: ; 414ae (10:54ae)
+Trade_CopyCableTilesOffScreen:
; This is used to copy the link cable tiles off screen so that the cable
; continues when the screen is scrolled.
push hl
- hlCoord 0, 4
- call CopyToScreenEdgeTiles
+ coord hl, 0, 4
+ call CopyToRedrawRowOrColumnSrcTiles
pop hl
ld a, h
- ld [H_SCREENEDGEREDRAWADDR + 1], a
+ ld [hRedrawRowOrColumnDest + 1], a
ld a, l
- ld [H_SCREENEDGEREDRAWADDR], a
- ld a, REDRAWROW
- ld [H_SCREENEDGEREDRAW], a
+ ld [hRedrawRowOrColumnDest], a
+ ld a, REDRAW_ROW
+ ld [hRedrawRowOrColumnMode], a
ld c, 10
jp DelayFrames
-Trade_AnimMonMoveHorizontal: ; 414c5 (10:54c5)
+Trade_AnimMonMoveHorizontal:
; Animates the mon going through the link cable horizontally over a distance of
; b 16-pixel units.
ld a, [wTradedMonMovingRight]
@@ -588,7 +590,7 @@ Trade_AnimMonMoveHorizontal: ; 414c5 (10:54c5)
jr nz, Trade_AnimMonMoveHorizontal
ret
-Trade_AnimCircledMon: ; 414e8 (10:54e8)
+Trade_AnimCircledMon:
; Cycles between the two animation frames of the mon party sprite, cycles
; between a circle and an oval around the mon sprite, and makes the cable flash.
push de
@@ -612,18 +614,18 @@ Trade_AnimCircledMon: ; 414e8 (10:54e8)
pop de
ret
-Trade_WriteCircledMonOAM: ; 41505 (10:5505)
+Trade_WriteCircledMonOAM:
callba WriteMonPartySpriteOAMBySpecies
call Trade_WriteCircleOAM
-Trade_AddOffsetsToOAMCoords: ; 41510 (10:5510)
+Trade_AddOffsetsToOAMCoords:
ld hl, wOAMBuffer
ld c, $14
.loop
- ld a, [W_BASECOORDY]
+ ld a, [wBaseCoordY]
add [hl]
ld [hli], a
- ld a, [W_BASECOORDX]
+ ld a, [wBaseCoordX]
add [hl]
ld [hli], a
inc hl
@@ -632,7 +634,7 @@ Trade_AddOffsetsToOAMCoords: ; 41510 (10:5510)
jr nz, .loop
ret
-Trade_AnimMonMoveVertical: ; 41525 (10:5525)
+Trade_AnimMonMoveVertical:
; Animates the mon going through the link cable vertically as well as
; horizontally for a bit. The last bit of horizontal movement (when moving
; right) or the first bit of horizontal movement (when moving left) are done
@@ -645,30 +647,30 @@ Trade_AnimMonMoveVertical: ; 41525 (10:5525)
and a
jr z, .movingLeft
; moving right
- ld bc, $400 ; move right
+ lb bc, 4, 0 ; move right
call .doAnim
- ld bc, $a ; move down
+ lb bc, 0, 10 ; move down
jr .doAnim
.movingLeft
- ld bc, $f6 ; move up
+ lb bc, 0, -10 ; move up
call .doAnim
- ld bc, $fc00 ; move left
+ lb bc, -4, 0 ; move left
.doAnim
ld a, b
- ld [W_BASECOORDX], a
+ ld [wBaseCoordX], a
ld a, c
- ld [W_BASECOORDY], a
+ ld [wBaseCoordY], a
ld d, $4
.loop
call Trade_AddOffsetsToOAMCoords
call Trade_AnimCircledMon
- ld c, $8
+ ld c, 8
call DelayFrames
dec d
jr nz, .loop
ret
-Trade_WriteCircleOAM: ; 41558 (10:5558)
+Trade_WriteCircleOAM:
; Writes the OAM blocks for the circle around the traded mon as it passes
; the link cable.
ld hl, Trade_CircleOAMPointers
@@ -695,7 +697,7 @@ Trade_WriteCircleOAM: ; 41558 (10:5558)
jr nz, .loop
ret
-Trade_CircleOAMPointers: ; 41574 (10:5574)
+Trade_CircleOAMPointers:
dw Trade_CircleOAM0
db $08,$08
dw Trade_CircleOAM1
@@ -705,40 +707,40 @@ Trade_CircleOAMPointers: ; 41574 (10:5574)
dw Trade_CircleOAM3
db $18,$18
-Trade_CircleOAM0: ; 41584 (10:5584)
+Trade_CircleOAM0:
db $38,$10,$39,$10
db $3A,$10,$3B,$10
-Trade_CircleOAM1: ; 4158c (10:558c)
+Trade_CircleOAM1:
db $39,$30,$38,$30
db $3B,$30,$3A,$30
-Trade_CircleOAM2: ; 41594 (10:5594)
+Trade_CircleOAM2:
db $3A,$50,$3B,$50
db $38,$50,$39,$50
-Trade_CircleOAM3: ; 4159c (10:559c)
+Trade_CircleOAM3:
db $3B,$70,$3A,$70
db $39,$70,$38,$70
; a = species
-Trade_LoadMonSprite: ; 415a4 (10:55a4)
+Trade_LoadMonSprite:
ld [wcf91], a
ld [wd0b5], a
- ld [wcf1d], a
- ld b, $b
- ld c, $0
- call GoPAL_SET
+ ld [wWholeScreenPaletteMonSpecies], a
+ ld b, SET_PAL_POKEMON_WHOLE_SCREEN
+ ld c, 0
+ call RunPaletteCommand
ld a, [H_AUTOBGTRANSFERENABLED]
xor $1
ld [H_AUTOBGTRANSFERENABLED], a
call GetMonHeader
- hlCoord 7, 2
+ coord hl, 7, 2
call LoadFlippedFrontSpriteByMonIndex
ld c, 10
jp DelayFrames
-Trade_ShowClearedWindow: ; 415c8 (10:55c8)
+Trade_ShowClearedWindow:
; clears the window and covers the BG entirely with the window
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
@@ -753,8 +755,11 @@ Trade_ShowClearedWindow: ; 415c8 (10:55c8)
ld [hSCX], a
ret
-Trade_SlideTextBoxOffScreen: ; 415df (10:55df)
-; Slides the window right until it's off screen.
+Trade_SlideTextBoxOffScreen:
+; Slides the window right until it's off screen. The window usually just has
+; a text box at the bottom when this is called. However, when this is called
+; after Trade_ShowEnemyMon in the external clock sequence, there is a mon pic
+; above the text box and it is also scrolled off the screen.
ld c, 50
call DelayFrames
.loop
@@ -772,18 +777,18 @@ Trade_SlideTextBoxOffScreen: ; 415df (10:55df)
ld [rWX], a
ret
-PrintTradeWentToText: ; 415fe (10:55fe)
+PrintTradeWentToText:
ld hl, TradeWentToText
call PrintText
ld c, 200
call DelayFrames
jp Trade_SlideTextBoxOffScreen
-TradeWentToText: ; 4160c (10:560c)
+TradeWentToText:
TX_FAR _TradeWentToText
db "@"
-PrintTradeForSendsText: ; 41611 (10:5611)
+PrintTradeForSendsText:
ld hl, TradeForText
call PrintText
call Trade_Delay80
@@ -791,15 +796,15 @@ PrintTradeForSendsText: ; 41611 (10:5611)
call PrintText
jp Trade_Delay80
-TradeForText: ; 41623 (10:5623)
+TradeForText:
TX_FAR _TradeForText
db "@"
-TradeSendsText: ; 41628 (10:5628)
+TradeSendsText:
TX_FAR _TradeSendsText
db "@"
-PrintTradeFarewellText: ; 4162d (10:562d)
+PrintTradeFarewellText:
ld hl, TradeWavesFarewellText
call PrintText
call Trade_Delay80
@@ -808,24 +813,24 @@ PrintTradeFarewellText: ; 4162d (10:562d)
call Trade_Delay80
jp Trade_SlideTextBoxOffScreen
-TradeWavesFarewellText: ; 41642 (10:5642)
+TradeWavesFarewellText:
TX_FAR _TradeWavesFarewellText
db "@"
-TradeTransferredText: ; 41647 (10:5647)
+TradeTransferredText:
TX_FAR _TradeTransferredText
db "@"
-PrintTradeTakeCareText: ; 4164c (10:564c)
+PrintTradeTakeCareText:
ld hl, TradeTakeCareText
call PrintText
jp Trade_Delay80
-TradeTakeCareText: ; 41655 (10:5655)
+TradeTakeCareText:
TX_FAR _TradeTakeCareText
db "@"
-PrintTradeWillTradeText: ; 4165a (10:565a)
+PrintTradeWillTradeText:
ld hl, TradeWillTradeText
call PrintText
call Trade_Delay80
@@ -833,16 +838,16 @@ PrintTradeWillTradeText: ; 4165a (10:565a)
call PrintText
jp Trade_Delay80
-TradeWillTradeText: ; 4166c (10:566c)
+TradeWillTradeText:
TX_FAR _TradeWillTradeText
db "@"
-TradeforText: ; 41671 (10:5671)
+TradeforText:
TX_FAR _TradeforText
db "@"
-Trade_ShowAnimation: ; 41676 (10:5676)
- ld [W_ANIMATIONID], a
+Trade_ShowAnimation:
+ ld [wAnimationID], a
xor a
- ld [wcc5b], a
+ ld [wAnimationType], a
predef_jump MoveAnimation
diff --git a/engine/trade2.asm b/engine/trade2.asm
index da199e77..062d5285 100755
--- a/engine/trade2.asm
+++ b/engine/trade2.asm
@@ -1,49 +1,48 @@
-Trade_PrintPlayerMonInfoText: ; 42769 (10:6769)
- hlCoord 5, 0
+Trade_PrintPlayerMonInfoText:
+ coord hl, 5, 0
ld de,Trade_MonInfoText
call PlaceString
ld a,[wTradedPlayerMonSpecies]
ld [wd11e],a
predef IndexToPokedex
- hlCoord 9, 0
+ coord hl, 9, 0
ld de,wd11e
- ld bc,$8103
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber
- hlCoord 5, 2
+ coord hl, 5, 2
ld de,wcf4b
call PlaceString
- hlCoord 8, 4
+ coord hl, 8, 4
ld de,wTradedPlayerMonOT
call PlaceString
- hlCoord 8, 6
+ coord hl, 8, 6
ld de,wTradedPlayerMonOTID
- ld bc,$8205
+ lb bc, LEADING_ZEROES | 2, 5
jp PrintNumber
-Trade_PrintEnemyMonInfoText: ; 427a7 (10:67a7)
- hlCoord 5, 10
+Trade_PrintEnemyMonInfoText:
+ coord hl, 5, 10
ld de,Trade_MonInfoText
call PlaceString
ld a,[wTradedEnemyMonSpecies]
ld [wd11e],a
predef IndexToPokedex
- hlCoord 9, 10
+ coord hl, 9, 10
ld de,wd11e
- ld bc,$8103
+ lb bc, LEADING_ZEROES | 1, 3
call PrintNumber
- hlCoord 5, 12
+ coord hl, 5, 12
ld de,wcd6d
call PlaceString
- hlCoord 8, 14
+ coord hl, 8, 14
ld de,wTradedEnemyMonOT
call PlaceString
- hlCoord 8, 16
+ coord hl, 8, 16
ld de,wTradedEnemyMonOTID
- ld bc,$8205
+ lb bc, LEADING_ZEROES | 2, 5
jp PrintNumber
-Trade_MonInfoText: ; 427e5 (10:67e5)
- db "──",$74,$F2,$4E
- db $4E
- db "OT/",$4E
- db $73,"№",$F2,"@"
+Trade_MonInfoText:
+ db "──№⠄",$4E
+ next "OT/"
+ next $73,"№⠄","@"
diff --git a/engine/turn_sprite.asm b/engine/turn_sprite.asm
index 84037cfe..e8a47a8f 100755
--- a/engine/turn_sprite.asm
+++ b/engine/turn_sprite.asm
@@ -1,4 +1,4 @@
-UpdateSpriteFacingOffsetAndDelayMovement: ; 13074 (4:7074)
+UpdateSpriteFacingOffsetAndDelayMovement:
ld h, $c2
ld a, [H_CURRENTSPRITEOFFSET]
add $8