summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rwxr-xr-xengine/HoF_room_pc.asm317
-rw-r--r--engine/add_party_mon.asm345
-rwxr-xr-xengine/animated_objects_3e.asm394
-rw-r--r--engine/bank30.binbin0 -> 16384 bytes
-rw-r--r--engine/bank3c.asm235
-rw-r--r--engine/bank3d.asm697
-rw-r--r--engine/bank3e.asm5
-rw-r--r--engine/bank3f.asm23
-rwxr-xr-xengine/battle/animations.asm1808
-rw-r--r--engine/battle/bank3d_battle.asm291
-rwxr-xr-xengine/battle/bank_e_misc.asm19
-rw-r--r--engine/battle/battle_transitions.asm14
-rw-r--r--engine/battle/common_text.asm20
-rwxr-xr-xengine/battle/core.asm984
-rw-r--r--engine/battle/decrement_pp.asm2
-rw-r--r--engine/battle/draw_hud_pokeball_gfx.asm12
-rwxr-xr-xengine/battle/end_of_battle.asm4
-rw-r--r--engine/battle/experience.asm26
-rw-r--r--engine/battle/get_trainer_name.asm9
-rw-r--r--engine/battle/ghost_marowak_anim.asm5
-rw-r--r--engine/battle/link_battle_versus_text.asm3
-rw-r--r--engine/battle/moveEffects/heal_effect.asm6
-rw-r--r--engine/battle/moveEffects/reflect_light_screen_effect.asm6
-rw-r--r--engine/battle/moveEffects/transform_effect.asm11
-rwxr-xr-xengine/battle/read_trainer_party.asm109
-rwxr-xr-xengine/battle/safari_zone.asm10
-rw-r--r--engine/battle/scale_sprites.asm7
-rw-r--r--engine/battle/trainer_ai.asm45
-rw-r--r--engine/battle/wild_encounters.asm7
-rw-r--r--engine/bcd.asm216
-rw-r--r--engine/bg_map_attributes.asm219
-rwxr-xr-xengine/cable_club.asm93
-rwxr-xr-xengine/clear_save.asm6
-rw-r--r--engine/debug1.asm24
-rwxr-xr-xengine/diploma_3a.asm167
-rw-r--r--engine/display_pokedex.asm19
-rw-r--r--engine/draw_badges.asm120
-rwxr-xr-xengine/evolution.asm8
-rwxr-xr-xengine/evolve_trade.asm44
-rwxr-xr-xengine/evos_moves.asm224
-rw-r--r--engine/flag_action_predef.asm73
-rwxr-xr-xengine/gamefreak.asm78
-rw-r--r--engine/get_bag_item_quantity.asm18
-rwxr-xr-xengine/give_pokemon.asm5
-rwxr-xr-xengine/hall_of_fame.asm48
-rw-r--r--engine/heal_party.asm99
-rwxr-xr-xengine/hidden_object_functions14.asm14
-rwxr-xr-xengine/hidden_object_functions17.asm149
-rwxr-xr-xengine/hidden_object_functions18.asm78
-rwxr-xr-xengine/hidden_object_functions3.asm46
-rwxr-xr-xengine/hidden_object_functions7.asm109
-rwxr-xr-xengine/hp_bar.asm12
-rwxr-xr-xengine/in_game_trades.asm62
-rw-r--r--engine/init_player_data.asm60
-rwxr-xr-xengine/intro.asm352
-rwxr-xr-xengine/items/items.asm2267
-rwxr-xr-xengine/items/tms.asm6
-rw-r--r--engine/joypad.asm38
-rwxr-xr-xengine/learn_move.asm42
-rw-r--r--engine/load_mon_data.asm68
-rw-r--r--engine/menu/bills_pc.asm121
-rwxr-xr-xengine/menu/diploma.asm113
-rw-r--r--engine/menu/diploma_1.asm17
-rwxr-xr-xengine/menu/league_pc.asm7
-rw-r--r--engine/menu/link_menu.asm910
-rwxr-xr-xengine/menu/main_menu.asm451
-rwxr-xr-xengine/menu/naming_screen.asm42
-rwxr-xr-xengine/menu/oaks_pc.asm4
-rw-r--r--engine/menu/options.asm443
-rwxr-xr-xengine/menu/party_menu.asm24
-rwxr-xr-xengine/menu/pc.asm12
-rwxr-xr-xengine/menu/players_pc.asm7
-rwxr-xr-xengine/menu/pokedex.asm787
-rwxr-xr-xengine/menu/prize_menu.asm197
-rwxr-xr-xengine/menu/start_menu.asm95
-rwxr-xr-xengine/menu/start_sub_menus.asm57
-rwxr-xr-xengine/menu/status_screen.asm38
-rw-r--r--engine/menu/swap_items.asm149
-rw-r--r--engine/menu/text_ids1.asm163
-rw-r--r--engine/menu/text_ids2.asm733
-rwxr-xr-xengine/menu/vending_machine.asm12
-rwxr-xr-xengine/mon_party_sprites.asm36
-rw-r--r--engine/move_mon.asm172
-rwxr-xr-xengine/multiply_divide.asm111
-rwxr-xr-xengine/oak_speech.asm47
-rwxr-xr-xengine/oak_speech2.asm45
-rw-r--r--engine/overworld/advance_player_sprite.asm241
-rw-r--r--engine/overworld/boulders.asm94
-rwxr-xr-xengine/overworld/cable_club_npc.asm59
-rwxr-xr-xengine/overworld/card_key.asm13
-rw-r--r--engine/overworld/check_player_state.asm236
-rw-r--r--engine/overworld/clear_loadmapdata_vars.asm20
-rwxr-xr-xengine/overworld/cut.asm9
-rwxr-xr-xengine/overworld/cut2.asm2
-rw-r--r--engine/overworld/daycare_exp.asm18
-rwxr-xr-xengine/overworld/doors.asm4
-rw-r--r--engine/overworld/dungeon_warps.asm15
-rwxr-xr-xengine/overworld/elevator.asm10
-rwxr-xr-xengine/overworld/emotion_bubbles.asm30
-rw-r--r--engine/overworld/get_coords_tile_in_front_of_player.asm87
-rwxr-xr-xengine/overworld/healing_machine.asm51
-rwxr-xr-xengine/overworld/hidden_items.asm37
-rwxr-xr-xengine/overworld/hidden_objects.asm42
-rwxr-xr-xengine/overworld/ledges.asm18
-rw-r--r--engine/overworld/load_tileset_header.asm51
-rw-r--r--engine/overworld/load_wild_data.asm33
-rw-r--r--engine/overworld/map_sprite_functions1.asm390
-rwxr-xr-xengine/overworld/map_sprites.asm684
-rw-r--r--engine/overworld/missable_objects.asm212
-rw-r--r--engine/overworld/movement.asm420
-rwxr-xr-xengine/overworld/npc_movement.asm52
-rwxr-xr-xengine/overworld/npc_movement_2.asm24
-rw-r--r--engine/overworld/npc_pathfinding.asm201
-rwxr-xr-xengine/overworld/oaks_aide.asm2
-rw-r--r--engine/overworld/oam.asm165
-rwxr-xr-xengine/overworld/player_animations.asm51
-rwxr-xr-xengine/overworld/pokecenter.asm101
-rwxr-xr-xengine/overworld/pokemart.asm2
-rw-r--r--engine/overworld/print_safari_steps.asm36
-rw-r--r--engine/overworld/replace_tile_block.asm126
-rw-r--r--engine/overworld/set_blackout_map.asm29
-rw-r--r--engine/overworld/special_warps.asm147
-rwxr-xr-xengine/overworld/ssanne.asm4
-rw-r--r--engine/overworld/step_functions.asm151
-rwxr-xr-xengine/overworld/trainers.asm54
-rw-r--r--engine/overworld/try_pushing_boulder.asm107
-rwxr-xr-xengine/palettes.asm639
-rwxr-xr-xengine/pikachu_emotions.asm421
-rwxr-xr-xengine/pikachu_follow.asm1578
-rwxr-xr-xengine/pikachu_movement.asm1048
-rwxr-xr-xengine/pikachu_pcm.asm154
-rwxr-xr-xengine/pikachu_pic_animation.asm851
-rwxr-xr-xengine/pikachu_status.asm258
-rwxr-xr-xengine/play_time.asm61
-rwxr-xr-xengine/pokedex_rating.asm102
-rwxr-xr-xengine/predefs.asm99
-rwxr-xr-xengine/predefs7.asm6
-rw-r--r--[-rwxr-xr-x]engine/predefsA.asm (renamed from engine/predefs12.asm)16
-rw-r--r--engine/print_waiting_text.asm19
-rw-r--r--engine/printer.asm999
-rwxr-xr-xengine/printer/serial.asm622
-rw-r--r--engine/remove_pokemon.asm95
-rwxr-xr-xengine/save.asm192
-rwxr-xr-xengine/slot_machine.asm24
-rw-r--r--engine/subtract_paid_money.asm17
-rwxr-xr-xengine/surfing_minigame.asm2862
-rwxr-xr-xengine/titlescreen.asm466
-rwxr-xr-xengine/titlescreen2.asm6
-rwxr-xr-xengine/town_map.asm57
-rwxr-xr-xengine/trade.asm36
-rwxr-xr-xengine/trade2.asm8
-rwxr-xr-xengine/turn_sprite.asm25
-rwxr-xr-xengine/unknown_ea3ea.asm977
-rwxr-xr-xengine/vermilion_gym_trash_cans.asm108
-rwxr-xr-xengine/yellow_intro.asm1081
155 files changed, 25790 insertions, 6036 deletions
diff --git a/engine/HoF_room_pc.asm b/engine/HoF_room_pc.asm
index a17d2e51..31d11677 100755
--- a/engine/HoF_room_pc.asm
+++ b/engine/HoF_room_pc.asm
@@ -1,173 +1,214 @@
HallOfFamePC:
- callba AnimateHallOfFame
+ callab FallingStarEnd
call ClearScreen
ld c, 100
call DelayFrames
+
call DisableLCD
- ld hl, vFont
- ld bc, $800 / 2
- call ZeroMemory
- ld hl, vChars2 + $600
- ld bc, $200 / 2
- call ZeroMemory
- ld hl, vChars2 + $7e0
- ld bc, $10
- ld a, $ff
- call FillMemory
+ ld a, $a7
+ ld [rWX], a
+ xor a
+ ld [rSCX], a
+ ld [rSCY], a
+ ld [hSCX], a
+ ld [hSCY], a
+ ld [hWY], a
+ ld [rWY], a
+ call CreditsLoadFont
coord hl, 0, 0
call FillFourRowsWithBlack
coord hl, 0, 14
call FillFourRowsWithBlack
- ld a, $c0
+ ld a, %11000000
ld [rBGP], a
+ call UpdateGBCPal_BGP
call EnableLCD
- ld a, $ff
- call PlaySoundWaitForCurrent
+ call StopAllMusic
+ ld hl, vBGMap1
+ call CreditsCopyTileMapToVRAM
+ ld hl, vBGMap0
+ call CreditsCopyTileMapToVRAM
ld c, BANK(Music_Credits)
ld a, MUSIC_CREDITS
call PlayMusic
ld c, 128
call DelayFrames
xor a
- ld [wUnusedCD3D], a ; not read
+ ld [wHoFMonSpecies], a
ld [wNumCreditsMonsDisplayed], a
jp Credits
FadeInCreditsText:
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
ld hl, HoFGBPalettes
ld b, 4
-.asm_740bf
+.asm_f0f91
ld a, [hli]
ld [rBGP], a
+ call UpdateGBCPal_BGP
ld c, 5
call DelayFrames
dec b
- jr nz, .asm_740bf
+ jr nz, .asm_f0f91
ret
+HoFGBPalettes:
+ db %11000000
+ db %11010000
+ db %11100000
+ db %11110000
+
DisplayCreditsMon:
+ ld hl, vBGMap1
+ call CreditsCopyTileMapToVRAM
xor a
- ld [H_AUTOBGTRANSFERENABLED],a
- call SaveScreenTilesToBuffer1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld hl, rLCDC
+ set 3, [hl]
+ call SaveScreenTilesToBuffer2
call FillMiddleOfScreenWithWhite
-
- ; display the next monster from CreditsMons
- ld hl,wNumCreditsMonsDisplayed
- ld c,[hl] ; how many monsters have we displayed so far?
- inc [hl]
- ld b,0
- ld hl,CreditsMons
- add hl,bc ; go that far in the list of monsters and get the next one
- ld a,[hl]
- ld [wcf91],a
- ld [wd0b5],a
- coord hl, 8, 6
- call GetMonHeader
- call LoadFrontSpriteByMonIndex
- ld hl,vBGMap0 + $c
+ call GetNextCreditsMon
+ ld hl, vBGMap0 + 12
call CreditsCopyTileMapToVRAM
xor a
- ld [H_AUTOBGTRANSFERENABLED],a
- call LoadScreenTilesFromBuffer1
- ld hl,vBGMap0
- call CreditsCopyTileMapToVRAM
- ld a,$A7
- ld [rWX],a
- ld hl,vBGMap1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call LoadScreenTilesFromBuffer2DisableBGTransfer
+ ld hl, vBGMap0
call CreditsCopyTileMapToVRAM
- call FillMiddleOfScreenWithWhite
- ld a,%11111100 ; make the mon a black silhouette
- ld [rBGP],a
-
-; scroll the mon left by one tile 7 times
- ld bc,7
-.scrollLoop1
+ ld a, %11111100
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ ld hl, rLCDC
+ res 3, [hl]
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld b, 0
+ ld c, 10
call ScrollCreditsMonLeft
- dec c
- 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 FillLeftHalfOfScreenWithWhite
+ ld c, 10
call ScrollCreditsMonLeft
- ld a,[rWX]
- sub 8
- ld [rWX],a
- dec c
- jr nz,.scrollLoop2
-
+ call FillRightHalfOfScreenWithWhite
+ ld c, 8
+ call ScrollCreditsMonLeft
+ ld a, %11000000
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
xor a
- ld [hWY],a
- ld a,%11000000
- ld [rBGP],a
+ ld [hSCX], a
ret
-INCLUDE "data/credit_mons.asm"
-
ScrollCreditsMonLeft:
- ld h, b
- ld l, $20
- call ScrollCreditsMonLeft_SetSCX
- ld h, $0
- ld l, $70
- call ScrollCreditsMonLeft_SetSCX
+.asm_f0fff
ld a, b
- add $8
+ ld [hSCX], a
+ add 8
ld b, a
+ call DelayFrame
+ dec c
+ jr nz, .asm_f0fff
ret
-ScrollCreditsMonLeft_SetSCX:
- ld a, [rLY]
- cp l
- jr nz, ScrollCreditsMonLeft_SetSCX
- ld a, h
- ld [rSCX], a
-.loop
- ld a, [rLY]
- cp h
- jr z, .loop
+GetNextCreditsMon:
+ ld hl, wNumCreditsMonsDisplayed
+ ld c, [hl]
+ inc [hl]
+ ld b, 0
+ ld hl, CreditsMons
+ add hl, bc
+ ld a, [hl]
+ ld [wcf91], a
+ ld [wd0b5], a
+ coord hl, 8, 6
+ call GetMonHeader
+ call LoadFrontSpriteByMonIndex
ret
-HoFGBPalettes:
- db %11000000
- db %11010000
- db %11100000
- db %11110000
+INCLUDE "data/credit_mons.asm"
CreditsCopyTileMapToVRAM:
ld a, l
- ld [H_AUTOBGTRANSFERDEST], a
+ ld [$ffbc], a
ld a, h
- ld [H_AUTOBGTRANSFERDEST + 1], a
- ld a, 1
+ ld [$ffbd], a
+ ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
jp Delay3
+CreditsLoadFont:
+ call LoadFontTilePatterns
+ ld hl, vChars1
+ ld bc, $40 * $10
+ call ZeroMemory
+
+ call LoadTextBoxTilePatterns
+ ld hl, vChars2 + $60 * $10
+ ld bc, $10 * $10
+ call ZeroMemory
+
+ ld hl, vChars2 + $7e * $10
+ ld bc, $1 * $10
+ ld a, $ff
+ call FillMemory
+ ret
+
ZeroMemory:
-; zero bc bytes at hl
+.asm_f1071
ld [hl], 0
inc hl
inc hl
dec bc
ld a, b
or c
- jr nz, ZeroMemory
+ jr nz, .asm_f1071
ret
FillFourRowsWithBlack:
- ld bc, SCREEN_WIDTH * 4
+ ld bc, 4 * SCREEN_WIDTH
ld a, $7e
jp FillMemory
FillMiddleOfScreenWithWhite:
coord hl, 0, 4
- ld bc, SCREEN_WIDTH * 10
+ ld bc, 10 * SCREEN_WIDTH
ld a, " "
jp FillMemory
-Credits:
+FillLeftHalfOfScreenWithWhite:
+ coord hl, 0, 4
+ push bc
+ call FillHalfOfScreenWithWhite
+ pop bc
+ ret
+
+FillRightHalfOfScreenWithWhite:
+ coord hl, 10, 4
+ push bc
+ call FillHalfOfScreenWithWhite
+ pop bc
+ ret
+
+FillHalfOfScreenWithWhite:
+ ld b, 10
+ ld c, 10
+ ld a, " "
+.asm_f10a6
+ push bc
+ push hl
+.asm_f10a8
+ ld [hli], a
+ dec c
+ jr nz, .asm_f10a8
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .asm_f10a6
+ ret
+
+Credits: ; Roll credits
ld de, CreditsOrder
push de
.nextCreditsScreen
@@ -192,58 +233,48 @@ Credits:
jr z, .showCopyrightText
cp $fa
jr z, .showTheEnd
- push hl
- push hl
- ld hl, CreditsTextPointers
- add a
- ld c, a
- ld b, 0
- add hl, bc
- ld e, [hl]
- inc hl
- ld d, [hl]
- ld a, [de]
- inc de
- ld c, a
- ld b, $ff
- pop hl
- add hl, bc
- call PlaceString
- pop hl
- ld bc, SCREEN_WIDTH * 2
- add hl, bc
+ call PlaceCreditsText
pop de
jr .nextCreditsCommand
+
+.showCopyrightText
+ callba LoadCopyrightTiles
+ pop de
+ jr .nextCreditsCommand
+
+
.fadeInTextAndShowMon
call FadeInCreditsText
- ld c, 90
+ ld c, 102
jr .next1
+
.showTextAndShowMon
- ld c, 110
+ ld c, 122
.next1
call DelayFrames
call DisplayCreditsMon
jr .nextCreditsScreen
+
.fadeInText
call FadeInCreditsText
- ld c, 120
+ ld c, 132
jr .next2
+
.showText
- ld c, 140
+ ld c, 152
.next2
call DelayFrames
jr .nextCreditsScreen
-.showCopyrightText
- push de
- callba LoadCopyrightTiles
- pop de
- pop de
- jr .nextCreditsCommand
+
.showTheEnd
- ld c, 16
+ call ShowTheEndGFX
+ pop de
+ ret
+
+ShowTheEndGFX:
+ ld c, 24
call DelayFrames
call FillMiddleOfScreenWithWhite
- pop de
ld de, TheEndGfx
ld hl, vChars2 + $600
lb bc, BANK(TheEndGfx), (TheEndGfxEnd - TheEndGfx) / $10
@@ -258,8 +289,31 @@ Credits:
TheEndTextString:
; "T H E E N D"
- db $60," ",$62," ",$64," ",$64," ",$66," ",$68,"@"
- db $61," ",$63," ",$65," ",$65," ",$67," ",$69,"@"
+ db $60, " ", $62, " ", $64, " ", $64, " ", $66, " ", $68, "@"
+ db $61, " ", $63, " ", $65, " ", $65, " ", $67, " ", $69, "@"
+
+PlaceCreditsText:
+ push hl
+ push hl
+ ld hl, CreditsTextPointers
+ ld c, a
+ ld b, 0
+ add hl, bc
+ add hl, bc
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ pop hl
+ ld a, [de]
+ inc de
+ ld c, a
+ ld b, $ff
+ add hl, bc
+ call PlaceString
+ pop hl
+ ld bc, SCREEN_WIDTH * 2
+ add hl, bc
+ ret
INCLUDE "data/credits_order.asm"
@@ -268,3 +322,4 @@ INCLUDE "text/credits_text.asm"
TheEndGfx: ; 7473e (1d:473e) (7473f on blue)
INCBIN "gfx/theend.interleave.2bpp"
TheEndGfxEnd:
+
diff --git a/engine/add_party_mon.asm b/engine/add_party_mon.asm
new file mode 100644
index 00000000..1aa6bd16
--- /dev/null
+++ b/engine/add_party_mon.asm
@@ -0,0 +1,345 @@
+_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 a, [wcf91]
+ cp KADABRA
+ jr nz, .skipGivingTwistedSpoon
+ ld a, $60 ; twistedspoon in gen 2
+ ld [de], a
+.skipGivingTwistedSpoon
+ 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
diff --git a/engine/animated_objects_3e.asm b/engine/animated_objects_3e.asm
new file mode 100755
index 00000000..63a94350
--- /dev/null
+++ b/engine/animated_objects_3e.asm
@@ -0,0 +1,394 @@
+ClearObjectAnimationBuffers:
+ ld hl, wAnimatedObjectsData
+ ld bc, wAnimatedObjectsDataEnd - wAnimatedObjectsData
+ xor a
+ call FillMemory
+ ret
+
+RunObjectAnimations:
+ ld hl, wAnimatedObjectDataStructs
+ ld e, 10
+.loop
+ ld a, [hl]
+ and a
+ jr z, .next
+ ld c, l
+ ld b, h
+ push hl
+ push de
+ call ExecuteCurrentAnimatedObjectCallback
+ call UpdateCurrentAnimatedObjectFrame
+ pop de
+ pop hl
+ jr c, .quit
+.next
+ ld bc, $10
+ add hl, bc
+ dec e
+ jr nz, .loop
+ ld a, [wCurrentAnimatedObjectOAMBufferOffset]
+ ld l, a
+ ld h, wOAMBuffer / $100
+.deinit_unused_oam_loop
+ ld a, l
+ cp wOAMBufferEnd % $100
+ jr nc, .quit
+ xor a
+ ld [hli], a
+ jr .deinit_unused_oam_loop
+
+.quit
+ ret
+
+SpawnAnimatedObject:
+ push de
+ push af
+ ld hl, wAnimatedObjectDataStructs
+ ld e, 10
+.loop
+ ld a, [hl]
+ and a
+ jr z, .init
+ ld bc, $10
+ add hl, bc
+ dec e
+ jr nz, .loop
+ pop af
+ pop de
+ scf
+ ret
+
+.init
+ pop af
+ ld c, l
+ ld b, h
+ ld hl, wNumLoadedAnimatedObjects
+ inc [hl]
+ ld e, a
+ ld d, $0
+ ld a, [wAnimatedObjectSpawnStateDataPointer]
+ ld l, a
+ ld a, [wAnimatedObjectSpawnStateDataPointer + 1]
+ ld h, a
+ add hl, de
+ add hl, de
+ add hl, de
+ ld e, l
+ ld d, h
+ ld hl, $0
+ add hl, bc
+ ld a, [wNumLoadedAnimatedObjects]
+ ld [hli], a
+ ld a, [de]
+ ld [hli], a
+ inc de
+ ld a, [de]
+ ld [hli], a
+ inc de
+ xor a
+ ld [hli], a
+ pop de
+ ld hl, $4
+ add hl, bc
+ ld a, e
+ ld [hli], a
+ ld a, d
+ ld [hli], a
+ xor a
+ ld [hli], a
+ ld [hli], a
+ xor a
+ ld [hli], a
+ ld [hli], a
+ dec a
+ ld [hli], a
+ xor a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ret
+
+MaskCurrentAnimatedObjectStruct:
+ ld hl, $0
+ add hl, bc
+ ld [hl], $0
+ ret
+
+MaskAllAnimatedObjectStructs:
+ ld hl, wAnimatedObjectDataStructs
+ ld e, 10
+.loop
+ ld [hl], $0
+ ld bc, $10
+ add hl, bc
+ dec e
+ jr nz, .loop
+ ret
+
+UpdateCurrentAnimatedObjectFrame:
+ xor a
+ ld [wCurAnimatedObjectOAMAttributes], a
+ ld hl, $3
+ add hl, bc
+ ld a, [hli]
+ ld [wCurrentAnimatedObjectVTileOffset], a
+ ld a, [hli]
+ ld [wCurrentAnimatedObjectXCoord], a
+ ld a, [hli]
+ ld [wCurrentAnimatedObjectYCoord], a
+ ld a, [hli]
+ ld [wCurrentAnimatedObjectXOffset], a
+ ld a, [hl]
+ ld [wCurrentAnimatedObjectYOffset], a
+ call UpdateDurationTimerAndFrameStateForCurrentAnimatedObject
+ cp $fd
+ jr z, .finish
+ cp $fc
+ jr z, .delete_animation
+ call GetCurrentAnimatedObjectOAMDataPointer
+ ld a, [wCurrentAnimatedObjectVTileOffset]
+ add [hl]
+ ld [wCurrentAnimatedObjectVTileOffset], a
+ inc hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ push bc
+ ld a, [wCurrentAnimatedObjectOAMBufferOffset]
+ ld e, a
+ ld d, wOAMBuffer / $100
+ ld a, [hli]
+ ld c, a
+.loop
+ ld a, [wCurrentAnimatedObjectYCoord]
+ ld b, a
+ ld a, [wCurrentAnimatedObjectYOffset]
+ add b
+ ld b, a
+ ld a, [wAnimatedObjectGlobalYOffset]
+ add b
+ ld b, a
+ call GetCurrentAnimatedObjectTileYCoordinate
+ add b
+ ld [de], a
+ inc hl
+ inc de
+ ld a, [wCurrentAnimatedObjectXCoord]
+ ld b, a
+ ld a, [wCurrentAnimatedObjectXOffset]
+ add b
+ ld b, a
+ ld a, [wAnimatedObjectGlobalXOffset]
+ add b
+ ld b, a
+ call GetCurrentAnimatedObjectTileXCoordinate
+ add b
+ ld [de], a
+ inc hl
+ inc de
+ ld a, [wCurrentAnimatedObjectVTileOffset]
+ add [hl]
+ ld [de], a
+ inc hl
+ inc de
+ call SetCurrentAnimatedObjectOAMAttributes
+ ld b, a
+ ld a, [wc634]
+ cp $7
+ ld a, b
+ jr z, .skip_load
+ ld [de], a
+.skip_load
+ inc hl
+ inc de
+ ld a, e
+ ld [wCurrentAnimatedObjectOAMBufferOffset], a
+ cp wOAMBufferEnd % $100
+ jr nc, .oam_is_full
+ dec c
+ jr nz, .loop
+ pop bc
+ jr .finish
+
+.delete_animation
+ call MaskCurrentAnimatedObjectStruct
+.finish
+ and a
+ ret
+
+.oam_is_full
+ pop bc
+ scf
+ ret
+
+GetCurrentAnimatedObjectTileYCoordinate:
+ push hl
+ ld a, [hl]
+ ld hl, wCurAnimatedObjectOAMAttributes
+ bit 6, [hl]
+ jr z, .no_flip
+ add $8
+ xor $ff
+ inc a
+.no_flip
+ pop hl
+ ret
+
+GetCurrentAnimatedObjectTileXCoordinate:
+ push hl
+ ld a, [hl]
+ ld hl, wCurAnimatedObjectOAMAttributes
+ bit 5, [hl]
+ jr z, .no_flip
+ add $8
+ xor $ff
+ inc a
+.no_flip
+ pop hl
+ ret
+
+SetCurrentAnimatedObjectOAMAttributes:
+ ld a, [wCurAnimatedObjectOAMAttributes]
+ ld b, a
+ ld a, [hl]
+ xor b
+ and $e0
+ ld b, a
+ ld a, [hl]
+ and $10
+ or b
+ bit 4, a
+ ret z
+ or $4
+ ret
+
+GetCurrentAnimatedObjectOAMDataPointer:
+ ld e, a
+ ld d, $0
+ ld a, [wAnimatedObjectOAMDataPointer]
+ ld l, a
+ ld a, [wAnimatedObjectOAMDataPointer + 1]
+ ld h, a
+ add hl, de
+ add hl, de
+ add hl, de
+ ret
+
+SetCurrentAnimatedObjectCallbackAndResetFrameStateRegisters:
+ ld hl, $1
+ add hl, bc
+ ld [hl], a
+ ld hl, $8
+ add hl, bc
+ ld [hl], $0
+ ld hl, $9
+ add hl, bc
+ ld [hl], $0
+ ld hl, $a
+ add hl, bc
+ ld [hl], $ff
+ ret
+
+UpdateDurationTimerAndFrameStateForCurrentAnimatedObject:
+.loop
+ ld hl, $8
+ add hl, bc
+ ld a, [hl]
+ and a
+ jr z, .next_frame
+ dec [hl]
+ call GetPointerToCurrentAnimatedObjectFrameScript
+ ld a, [hli]
+ push af
+ jr .finish
+
+.next_frame
+ ld hl, $a
+ add hl, bc
+ inc [hl]
+ call GetPointerToCurrentAnimatedObjectFrameScript
+ ld a, [hli]
+ cp $fe
+ jr z, .restart_anim
+ cp $ff
+ jr z, .hold_last_frame_state
+ push af
+ ld a, [hl]
+ push hl
+ and $3f
+ ld hl, $9
+ add hl, bc
+ add [hl]
+ ld hl, $8
+ add hl, bc
+ ld [hl], a
+ pop hl
+.finish
+ ld a, [hl]
+ and $c0
+ srl a
+ ld [wCurAnimatedObjectOAMAttributes], a
+ pop af
+ ret
+
+.hold_last_frame_state
+ xor a
+ ld hl, $8
+ add hl, bc
+ ld [hl], a
+ ld hl, $a
+ add hl, bc
+ dec [hl]
+ dec [hl]
+ jr .loop
+
+.restart_anim
+ xor a
+ ld hl, $8
+ add hl, bc
+ ld [hl], a
+ dec a
+ ld hl, $a
+ add hl, bc
+ ld [hl], a
+ jr .loop
+
+GetPointerToCurrentAnimatedObjectFrameScript:
+ ld hl, $1
+ add hl, bc
+ ld e, [hl]
+ ld d, $0
+ ld a, [wAnimatedObjectFramesDataPointer]
+ ld l, a
+ ld a, [wAnimatedObjectFramesDataPointer + 1]
+ ld h, a
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld hl, $a
+ add hl, bc
+ ld l, [hl]
+ ld h, $0
+ add hl, hl
+ add hl, de
+ ret
+
+ExecuteCurrentAnimatedObjectCallback:
+ ld hl, $2
+ add hl, bc
+ ld e, [hl]
+ ld d, $0
+ ld a, [wAnimatedObjectJumptablePointer]
+ ld l, a
+ ld a, [wAnimatedObjectJumptablePointer + 1]
+ ld h, a
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
diff --git a/engine/bank30.bin b/engine/bank30.bin
new file mode 100644
index 00000000..6309c149
--- /dev/null
+++ b/engine/bank30.bin
Binary files differ
diff --git a/engine/bank3c.asm b/engine/bank3c.asm
new file mode 100644
index 00000000..7ae059e7
--- /dev/null
+++ b/engine/bank3c.asm
@@ -0,0 +1,235 @@
+INCLUDE "engine/pikachu_pcm.asm"
+INCLUDE "engine/overworld/advance_player_sprite.asm"
+
+ResetStatusAndHalveMoneyOnBlackout:
+; Reset player status on blackout.
+ xor a
+ ld [wd435], a
+ xor a ; gamefreak copypasting functions (double 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
+
+SetMapSpecificScriptFlagsOnMapReload:
+ ld a, [wCurMap]
+ cp VERMILION_GYM ; ??? new thing about verm gym?
+ jr z, .verm_gym
+ ld c, a
+ ld hl, .MapList
+.search_loop
+ ld a, [hli]
+ cp c
+ jr z, .in_list
+ cp a, $ff
+ jr nz, .search_loop
+ ret
+
+.verm_gym
+ ld hl, wCurrentMapScriptFlags
+ set 6, [hl]
+ ret
+
+.in_list
+ ld hl, wCurrentMapScriptFlags
+ set 5, [hl]
+ ret
+
+.MapList ; f02fa (3c:42fa)
+ db SILPH_CO_2F
+ db SILPH_CO_3F
+ db SILPH_CO_4F
+ db SILPH_CO_5F
+ db SILPH_CO_6F
+ db SILPH_CO_7F
+ db SILPH_CO_8F
+ db SILPH_CO_9F
+ db SILPH_CO_10F
+ db SILPH_CO_11F
+ db MANSION_2
+ db MANSION_3
+ db MANSION_4
+ db MANSION_1
+ db CINNABAR_GYM
+ db GAME_CORNER
+ db ROCKET_HIDEOUT_1
+ db ROCKET_HIDEOUT_4
+ db VICTORY_ROAD_3
+ db VICTORY_ROAD_1
+ db VICTORY_ROAD_2
+ db LANCES_ROOM
+ db LORELEIS_ROOM
+ db BRUNOS_ROOM
+ db AGATHAS_ROOM
+ db $ff
+
+BeachHouse_GFX:
+ INCBIN "gfx/tilesets/beachhouse.2bpp"
+
+BeachHouse_Block:
+ INCBIN "gfx/blocksets/beachhouse.bst"
+
+Func_f0a54:
+ ret
+
+LoadUnusedBluesHouseMissableObjectData:
+; referenced in an unused function
+ ld hl, .MissableObjectsMaps
+.loop
+ ld a, [hli]
+ cp a, $ff
+ ret z
+ ld b, a
+ ld a, [wCurMap]
+ cp b
+ jr z, .found
+ inc hl
+ inc hl
+ inc hl
+ jr .loop
+
+.found
+ ld a, [hli]
+ ld c, a
+ ld b, 0
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, wMissableObjectList
+ call CopyData
+ ret
+
+.MissableObjectsMaps:
+ dbbw BLUES_HOUSE, .End - .Start, .Start
+ db $ff
+
+.Start:
+ db 1, HS_DAISY_SITTING_COPY
+ db 2, HS_DAISY_WALKING_COPY
+ db 3, HS_TOWN_MAP_COPY
+ db $ff
+.End:
+
+TryApplyPikachuMovementData: ; f0a82
+ ld a, [wd472]
+ bit 7, a
+ ret z
+ ld a, [wWalkBikeSurfState]
+ and a
+ ret nz
+ push hl
+ push bc
+ callab GetPikachuFacingDirectionAndReturnToE
+ pop bc
+ pop hl
+ ld a, b
+ cp e
+ ret nz
+ push hl
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ callab LoadPikachuShadowIntoVRAM
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ pop hl
+ call ApplyPikachuMovementData
+ callab RefreshPikachuFollow
+ ret
+
+Pic_f0abf:
+INCBIN "gfx/pikachu/unknown_f0abf.pic"
+GFX_f0b64:
+INCBIN "gfx/pikachu/unknown_f0b64.2bpp"
+Pic_f0cf4:
+INCBIN "gfx/pikachu/unknown_f0cf4.pic"
+GFX_f0d82:
+INCBIN "gfx/pikachu/unknown_f0d82.2bpp"
+
+PokecenterChanseyText:
+ ld hl, NurseChanseyText
+ call PrintText
+ ld a, CHANSEY
+ call PlayCry
+ call WaitForSoundToFinish
+ ret
+
+NurseChanseyText:
+ TX_FAR _NurseChanseyText
+ db "@"
+
+INCLUDE "engine/HoF_room_pc.asm"
+INCLUDE "scripts/viridiancity2.asm"
+INCLUDE "scripts/vermilioncity2.asm"
+INCLUDE "scripts/celadoncity2.asm"
+INCLUDE "scripts/route1_2.asm"
+INCLUDE "scripts/route22_2.asm"
+INCLUDE "scripts/redshouse1f2.asm"
+INCLUDE "scripts/oakslab2.asm"
+INCLUDE "scripts/school2.asm"
+INCLUDE "scripts/museum1f2.asm"
+INCLUDE "scripts/pewterpokecenter2.asm"
+INCLUDE "scripts/pokemontower2_2.asm"
+INCLUDE "scripts/celadonmart3_2.asm"
+INCLUDE "scripts/celadonmansion1_2.asm"
+INCLUDE "scripts/celadonmansion3_2.asm"
+INCLUDE "scripts/celadongamecorner2.asm"
+INCLUDE "scripts/celadondiner2.asm"
+INCLUDE "scripts/safarizoneentrance2.asm"
+INCLUDE "scripts/cinnabargym3.asm"
+INCLUDE "scripts/mtmoonpokecenter2.asm"
+
+INCLUDE "data/mapHeaders/beach_house.asm"
+INCLUDE "scripts/beach_house.asm"
+BeachHouseBlockdata:
+INCBIN "maps/beach_house.blk"
+INCLUDE "data/mapObjects/beach_house.asm"
+
+INCLUDE "scripts/beach_house2.asm"
+INCLUDE "scripts/billshouse2.asm"
+INCLUDE "scripts/viridianforest2.asm"
+INCLUDE "scripts/ssanne9_2.asm"
+INCLUDE "scripts/silphco11_2.asm"
+
+INCLUDE "engine/overworld/hidden_objects.asm"
+INCLUDE "engine/vermilion_gym_trash_cans.asm"
diff --git a/engine/bank3d.asm b/engine/bank3d.asm
new file mode 100644
index 00000000..6efff351
--- /dev/null
+++ b/engine/bank3d.asm
@@ -0,0 +1,697 @@
+INCLUDE "engine/battle/common_text.asm"
+INCLUDE "engine/battle/link_battle_versus_text.asm"
+INCLUDE "engine/battle/unused_stats_functions.asm"
+INCLUDE "engine/battle/scroll_draw_trainer_pic.asm"
+
+StarterPikachuBattleEntranceAnimation:
+ coord hl, 0, 5
+ ld c, 0
+.loop1
+ inc c
+ ld a, c
+ cp 9
+ ret z
+ ld d, 7 * 13
+ push bc
+ push hl
+.loop2
+ call .PlaceColumn
+ dec hl
+ ld a, d
+ sub 7
+ ld d, a
+ dec c
+ jr nz, .loop2
+ ld c, 2
+ call DelayFrames
+ pop hl
+ pop bc
+ inc hl
+ jr .loop1
+
+.PlaceColumn:
+ push hl
+ push de
+ push bc
+ ld e, 7
+.loop3
+ ld a, d
+ cp 7 * 7
+ jr nc, .okay
+ ld a, $7f
+.okay
+ ld [hl], a
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ inc d
+ dec e
+ jr nz, .loop3
+ pop bc
+ pop de
+ pop hl
+ ret
+
+INCLUDE "engine/battle/decrement_pp.asm"
+
+ModifyPikachuHappiness::
+ ld a, d
+ cp PIKAHAPPY_GYMLEADER
+ jr z, .checkanywhereinparty
+ cp PIKAHAPPY_WALKING
+ jr z, .checkanywhereinparty
+ push de
+ callab IsThisPartymonStarterPikachu_Party
+ pop de
+ ret nc
+ jr .proceed
+
+.checkanywhereinparty
+ push de
+ callab IsStarterPikachuInOurParty
+ pop de
+ ret nc
+
+.proceed
+ push de
+ ; Divide [wPikachuHappiness] by 100. Hold the integer part in e.
+ ld e, $0
+ ld a, [wPikachuHappiness]
+ cp 100
+ jr c, .wPikachuHappiness_div_100
+ inc e
+ cp 200
+ jr c, .wPikachuHappiness_div_100
+ inc e
+.wPikachuHappiness_div_100
+ ; Get the (d, e) entry from HappinessChangeTable.
+ ld c, d
+ dec c
+ ld b, $0
+ ld hl, HappinessChangeTable
+ add hl, bc
+ add hl, bc
+ add hl, bc
+ ld d, $0
+ add hl, de
+ ld a, [hl]
+ ; If [hl] is positive, take min(0xff, [hl] + [wPikachuHappiness]).
+ ; If [hl] is negative, take max(0x00, [hl] + [wPikachuHappiness]).
+ ; Inexplicably, we're using 100 as the threshold for comparison.
+ cp 100
+ ld a, [wPikachuHappiness]
+ jr nc, .negative
+ add [hl]
+ jr nc, .okay
+ ld a, -1
+ jr .okay
+
+.negative
+ add [hl]
+ jr c, .okay
+ xor a
+.okay
+ ld [wPikachuHappiness], a
+
+ ; Restore d and get the d'th entry in PikachuMoods.
+ pop de
+ dec d
+ ld hl, PikachuMoods
+ ld e, d
+ ld d, $0
+ add hl, de
+ ld a, [hl]
+ ld b, a
+ ; Modify Pikachu's mood
+ cp $80
+ jr z, .done
+ ld a, [wPikachuMood]
+ jr c, .decreased
+ cp b
+ jr nc, .done
+ ld a, [wd49c]
+ and a
+ jr nz, .done
+ jr .update_mood
+
+.decreased
+ cp b
+ jr c, .done
+.update_mood
+ ld a, b
+ ld [wPikachuMood], a
+.done
+ ret
+
+HappinessChangeTable:
+ ; Increase
+ db 5, 3, 2 ; Gained a level
+ db 5, 3, 2 ; HP restore
+ db 1, 1, 0 ; Used X item
+ db 3, 2, 1 ; Challenged Gym Leader
+ db 1, 1, 0 ; Teach TM/HM
+ db 2, 1, 1 ; Walking around
+ ; Decrease
+ db -3, -3, -5 ; Deposited
+ db -1, -1, -1 ; Fainted in battle
+ db -5, -5, -10 ; Fainted due to Poison outside of battle
+ db -5, -5, -10 ; Unknown (d = 10)
+ db -10, -10, -20 ; Unknown (d = 11)
+
+PikachuMoods:
+ ; Increase
+ db $8a ; Gained a level
+ db $83 ; HP restore
+ db $80 ; Teach TM/HM
+ db $80 ; Challenged Gym Leader
+ db $94 ; Unknown (d = 5)
+ db $80 ; Unknown (d = 6)
+ ; Decrease
+ db $62 ; Deposited
+ db $6c ; Fainted
+ db $62 ; Unknown (d = 9)
+ db $6c ; Unknown (d = 10)
+ db $00 ; Unknown (d = 11)
+
+RedPicBack: INCBIN "pic/trainer/redb.pic"
+OldManPic: INCBIN "pic/trainer/oldman.pic"
+ProfOakPicBack: INCBIN "pic/ytrainer/prof.oakb.pic"
+
+LoadYellowTitleScreenGFX:
+ ld hl, PokemonLogoGraphics
+ ld de, vChars2
+ ld bc, 115 * $10
+ ld a, BANK(PokemonLogoGraphics) ; redundant because this function is in bank3d
+ call FarCopyData
+ ld hl, YellowLogoGraphics + 35 * $10
+ ld de, vChars0 + 253 * $10
+ ld bc, 3 * $10
+ ld a, BANK(YellowLogoGraphics)
+ call FarCopyData
+ ld hl, YellowLogoGraphics + 38 * $10
+ ld de, vChars1
+ ld bc, 64 * $10
+ ld a, BANK(YellowLogoGraphics)
+ call FarCopyData
+ ld hl, YellowLogoGraphics + 102 * $10
+ ld de, vChars0 + 240 * $10
+ ld bc, 12 * $10
+ ld a, BANK(YellowLogoGraphics)
+ call FarCopyData
+ ret
+
+TitleScreen_PlacePokemonLogo:
+ coord hl, 2, 1
+ ld de, TitleScreenPokemonLogoTilemap
+ lb bc, 7, 16
+ call Bank3D_CopyBox
+ ret
+
+TitleScreen_PlacePikaSpeechBubble:
+ coord hl, 6, 4
+ ld de, TitleScreenPikaBubbleTilemap
+ lb bc, 4, 7
+ call Bank3D_CopyBox
+ coord hl, 9, 8
+ ld [hl], $64
+ inc hl
+ ld [hl], $65
+ ret
+
+TitleScreen_PlacePikachu:
+ coord hl, 4, 8
+ ld de, TitleScreenPikachuTilemap
+ lb bc, 9, 12
+ call Bank3D_CopyBox
+ coord hl, 16, 10
+ ld [hl], $96
+ coord hl, 16, 11
+ ld [hl], $9d
+ coord hl, 16, 12
+ ld [hl], $a7
+ coord hl, 16, 13
+ ld [hl], $b1
+ ld hl, TitleScreenPikachuEyesOAMData
+ ld de, wOAMBuffer
+ ld bc, $20
+ call CopyData
+ ret
+
+TitleScreenPikachuEyesOAMData:
+ db $60, $40, $f1, $22
+ db $60, $48, $f0, $22
+ db $68, $40, $f3, $22
+ db $68, $48, $f2, $22
+ db $60, $60, $f0, $02
+ db $60, $68, $f1, $02
+ db $68, $60, $f2, $02
+ db $68, $68, $f3, $02
+
+Bank3D_CopyBox:
+; copy cxb (xy) screen area from de to hl
+.row
+ push bc
+ push hl
+.col
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .col
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .row
+ ret
+
+TitleScreenPokemonLogoTilemap:
+; 16x7 (xy)
+ db $f4, $f4, $f4, $f4, $f4, $f4, $49, $f4, $72, $30, $f4, $f4, $f4, $f4, $f4, $f4
+ db $fd, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0a, $0b, $f4, $0d, $0e, $0f
+ db $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $1a, $1b, $1c, $1d, $1e, $1f
+ db $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $2a, $2b, $2c, $2d, $2e, $2f
+ db $f4, $31, $32, $33, $34, $35, $36, $37, $38, $39, $3a, $3b, $3c, $3d, $3e, $3f
+ db $f4, $41, $42, $43, $44, $45, $46, $47, $48, $f4, $4a, $4b, $4c, $4d, $4e, $4f
+ db $f4, $6a, $6b, $6c, $6d, $f4, $f4, $f4, $f4, $f4, $f4, $6e, $6f, $70, $71, $f4
+
+Pointer_f4669:
+; Unreferenced
+ db $47, $48, $49, $4a, $4b, $4c, $4d, $4e, $4f, $5f
+
+TitleScreenPikaBubbleTilemap:
+; 7x4 (xy)
+ db $24, $25, $66, $67, $68, $69, $2a
+ db $50, $51, $52, $53, $54, $55, $56
+ db $57, $58, $59, $5a, $5b, $5c, $5d
+ db $6d, $5e, $5f, $60, $61, $62, $63
+
+TitleScreenPikachuTilemap:
+; 12x9 (xy)
+ db $80, $81, $82, $83, $00, $00, $00, $00, $84, $85, $86, $87
+ db $88, $89, $8a, $8b, $8c, $8d, $8d, $8e, $8f, $8a, $90, $91
+ db $00, $92, $93, $8a, $8a, $8a, $8a, $8a, $8a, $94, $95, $00
+ db $00, $00, $97, $8a, $8a, $98, $99, $8a, $8a, $9a, $9b, $9c
+ db $00, $00, $9e, $9f, $a0, $a1, $a2, $a3, $a4, $a5, $a6, $8a
+ db $00, $a8, $a9, $aa, $8a, $ab, $ac, $8a, $ad, $ae, $af, $b0
+ db $00, $b2, $b3, $b4, $8a, $8a, $8a, $8a, $b5, $b6, $b7, $b8
+ db $00, $b9, $ba, $8a, $8a, $8a, $8a, $8a, $8a, $bb, $bc, $00
+ db $00, $00, $bd, $8a, $8a, $8a, $8a, $8a, $8a, $be, $bf, $00
+
+; f46f9 (3d:46f9)
+PokemonLogoGraphics: INCBIN "gfx/pokemon_logo.2bpp"
+PokemonLogoGraphicsEnd:
+YellowLogoGraphics: INCBIN "gfx/yellow_titlescreen.2bpp"
+YellowLogoGraphicsEnd:
+
+INCLUDE "engine/menu/link_menu.asm"
+
+HandleMenuInputDouble:
+ xor a
+ ld [wPartyMenuAnimMonEnabled], a
+
+HandleMenuInputPokemonSelectionDouble:
+ ld a, [H_DOWNARROWBLINKCNT1]
+ push af
+ ld a, [H_DOWNARROWBLINKCNT2]
+ push af ; save existing values on stack
+ xor a
+ ld [H_DOWNARROWBLINKCNT1], a ; blinking down arrow timing value 1
+ ld a, $06
+ ld [H_DOWNARROWBLINKCNT2], a ; blinking down arrow timing value 2
+.loop1
+ xor a
+ ld [wAnimCounter], a ; counter for pokemon shaking animation
+ call .UpdateCursorTile
+ call JoypadLowSensitivity
+ ld a, [hJoy5]
+ and a ; was a key pressed?
+ jr nz, .keyPressed
+ pop af
+ ld [H_DOWNARROWBLINKCNT2], a
+ pop af
+ ld [H_DOWNARROWBLINKCNT1], a ; restore previous values
+ xor a
+ ld [wMenuWrappingEnabled], a ; disable menu wrapping
+ ret
+.keyPressed
+ xor a
+ ld [wCheckFor180DegreeTurn], a
+ ld a, [hJoy5]
+ ld b, a
+ bit 6, a ; pressed Up key?
+ jr z, .checkIfDownPressed
+.upPressed
+ ld a, [wCurrentMenuItem] ; selected menu item
+ and a ; already at the top of the menu?
+ jr z, .checkOtherKeys
+.notAtTop
+ dec a
+ ld [wCurrentMenuItem], a ; move selected menu item up one space
+ jr .checkOtherKeys
+.checkIfDownPressed
+ bit 7, a
+ jr z, .checkOtherKeys
+.downPressed
+ ld a, [wCurrentMenuItem]
+ inc a
+ ld c, a
+ ld a, [wMaxMenuItem]
+ cp c
+ jr c, .checkOtherKeys
+ ld a, c
+ ld [wCurrentMenuItem], a
+.checkOtherKeys
+ ld a, [wMenuWatchedKeys]
+ and b ; does the menu care about any of the pressed keys?
+ jp z, .loop1
+.checkIfAButtonOrBButtonPressed
+ ld a, [hJoy5]
+ and A_BUTTON | B_BUTTON
+ jr z, .skipPlayingSound
+.AButtonOrBButtonPressed
+ ld a, SFX_PRESS_AB
+ call PlaySound ; play sound
+.skipPlayingSound
+ pop af
+ ld [H_DOWNARROWBLINKCNT2], a
+ pop af
+ ld [H_DOWNARROWBLINKCNT1], a ; restore previous values
+ ld a, [hJoy5]
+ ret
+
+.UpdateCursorTile:
+ ld a, [wTopMenuItemY]
+ and a
+ jr z, .asm_f5ac0
+ coord hl, 0, 0
+ ld bc, SCREEN_WIDTH
+.loop
+ add hl, bc
+ dec a
+ jr nz, .loop
+.asm_f5ac0
+ ld a, [wTopMenuItemX]
+ ld b, $0
+ ld c, a
+ add hl, bc
+ push hl
+ ld a, [wLastMenuItem]
+ and a
+ jr z, .asm_f5ad5
+ ld bc, $28
+.loop2
+ add hl, bc
+ dec a
+ jr nz, .loop2
+.asm_f5ad5
+ ld a, [hl]
+ cp "▶"
+ jr nz, .asm_f5ade
+ ld a, [wTileBehindCursor]
+ ld [hl], a
+.asm_f5ade
+ pop hl
+ ld a, [wCurrentMenuItem]
+ and a
+ jr z, .asm_f5aec
+ ld bc, $28
+.loop3
+ add hl, bc
+ dec a
+ jr nz, .loop3
+.asm_f5aec
+ ld a, [hl]
+ cp "▶"
+ jr z, .asm_f5af4
+ ld [wTileBehindCursor], a
+.asm_f5af4
+ ld a, "▶"
+ ld [hl], a
+ ld a, l
+ ld [wMenuCursorLocation], a
+ ld a, h
+ ld [wMenuCursorLocation + 1], a
+ ld a, [wCurrentMenuItem]
+ ld [wLastMenuItem], a
+ ret
+
+PrintStrengthTxt:
+ ld hl, wd728
+ set 0, [hl]
+ ld hl, Text_f5b17
+ call PrintText
+ ld hl, Text_f5b28
+ jp PrintText
+
+Text_f5b17:
+ TX_FAR _UsedStrengthText ; 2d:417e
+ TX_ASM
+ ld a, [wcf91]
+ call PlayCry
+ call Delay3
+ jp TextScriptEnd
+
+Text_f5b28:
+ TX_FAR _CanMoveBouldersText ; 2d:4193
+ 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_f5b64
+ 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_f5b64:
+ db 11, 07
+ db $ff
+
+CurrentTooFastText:
+ TX_FAR _CurrentTooFastText ; 2d:41ab
+ db "@"
+
+CyclingIsFunText:
+ TX_FAR _CyclingIsFunText ; 2d:41ca
+ db "@"
+
+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
+.notAtEndOfInventory
+ 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
+.loop
+ ld a, [hl]
+ cp a, $ff ; is it the end of the table?
+ jr nz, .notAtEndOfInventory
+.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
+ add 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
+
+TrainerInfoTextBoxTileGraphics: INCBIN "gfx/trainer_info.2bpp"
+TrainerInfoTextBoxTileGraphicsEnd:
+BlankLeaderNames: INCBIN "gfx/blank_leader_names.2bpp"
+CircleTile: INCBIN "gfx/circle_tile.2bpp"
+BadgeNumbersTileGraphics: INCBIN "gfx/badge_numbers.2bpp"
+
+ReadSuperRodData:
+ ld a, [wCurMap]
+ ld c, a
+ ld hl, FishingSlots
+.loop
+ ld a, [hli]
+ cp $ff
+ jr z, .notfound
+ cp c
+ jr z, .found
+ ld de, $8
+ add hl, de
+ jr .loop
+.found
+ call GenerateRandomFishingEncounter
+ ret
+.notfound
+ ld de, $0
+ ret
+
+GenerateRandomFishingEncounter:
+ call Random
+ cp $66
+ jr c, .asm_f5ed6
+ inc hl
+ inc hl
+ cp $b2
+ jr c, .asm_f5ed6
+ inc hl
+ inc hl
+ cp $e5
+ jr c, .asm_f5ed6
+ inc hl
+ inc hl
+.asm_f5ed6
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ret
+
+INCLUDE "data/super_rod.asm"
+INCLUDE "engine/battle/bank3d_battle.asm"
+INCLUDE "engine/items/tm_prices.asm"
+INCLUDE "engine/multiply_divide.asm"
+INCLUDE "engine/give_pokemon.asm"
+INCLUDE "engine/battle/get_trainer_name.asm"
+INCLUDE "engine/random.asm"
+INCLUDE "engine/predefs.asm"
diff --git a/engine/bank3e.asm b/engine/bank3e.asm
new file mode 100644
index 00000000..32f5ebfd
--- /dev/null
+++ b/engine/bank3e.asm
@@ -0,0 +1,5 @@
+INCLUDE "engine/surfing_minigame.asm"
+INCLUDE "engine/yellow_intro.asm"
+INCLUDE "data/animated_objects_3e_2.asm"
+YellowIntroGraphics: INCBIN "gfx/yellow_intro.2bpp"
+INCLUDE "engine/animated_objects_3e.asm"
diff --git a/engine/bank3f.asm b/engine/bank3f.asm
new file mode 100644
index 00000000..23eadbb1
--- /dev/null
+++ b/engine/bank3f.asm
@@ -0,0 +1,23 @@
+INCLUDE "data/map_songs.asm"
+INCLUDE "data/map_header_pointers.asm"
+INCLUDE "data/map_header_banks.asm"
+INCLUDE "engine/pikachu_follow.asm"
+INCLUDE "engine/pikachu_status.asm"
+INCLUDE "engine/pikachu_emotions.asm"
+INCLUDE "engine/pikachu_movement.asm"
+INCLUDE "engine/pikachu_pic_animation.asm"
+
+Func_fe66e:
+ ret
+
+OfficerJennySprite: INCBIN "gfx/sprites/officer_jenny.2bpp"
+PikachuSprite: INCBIN "gfx/sprites/pikachu.2bpp"
+SandshrewSprite: INCBIN "gfx/sprites/sandshrew.2bpp"
+OddishSprite: INCBIN "gfx/sprites/oddish.2bpp"
+BulbasaurSprite: INCBIN "gfx/sprites/bulbasaur.2bpp"
+JigglypuffSprite: INCBIN "gfx/sprites/jigglypuff.2bpp"
+Clefairy2Sprite: INCBIN "gfx/sprites/clefairy2.2bpp"
+ChanseySprite: INCBIN "gfx/sprites/chansey.2bpp"
+SurfingPikachuSprite: INCBIN "gfx/sprites/surfing_pikachu.2bpp"
+JessieSprite: INCBIN "gfx/sprites/jessie.2bpp"
+JamesSprite: INCBIN "gfx/sprites/james.2bpp"
diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm
index ea5738bc..31148392 100755
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -1,202 +1,229 @@
; Draws a "frame block". Frame blocks are blocks of tiles that are put
; together to form frames in battle animations.
DrawFrameBlock:
- ld l,c
- ld h,b
- ld a,[hli]
- ld [wNumFBTiles],a
- ld a,[wFBDestAddr + 1]
- ld e,a
- ld a,[wFBDestAddr]
- ld d,a
+ ld l, c
+ ld h, b
+ ld a, [hli]
+ ld [wNumFBTiles], a
+ ld a, [wFBDestAddr + 1]
+ ld e, a
+ ld a, [wFBDestAddr]
+ ld d, a
xor a
- ld [wFBTileCounter],a ; loop counter
+ ld [wFBTileCounter], a ; loop counter
.loop
- ld a,[wFBTileCounter]
+ ld a, [wFBTileCounter]
inc a
- ld [wFBTileCounter],a
- ld a,[wSubAnimTransform]
+ ld [wFBTileCounter], a
+ ld a, $2
+ ld [wdef5], a
+ ld a, [wSubAnimTransform]
dec a
- jr z,.flipHorizontalAndVertical ; 1
+ jr z, .flipHorizontalAndVertical ; 1
dec a
- jp z,.flipHorizontalTranslateDown ; 2
+ jp z, .flipHorizontalTranslateDown ; 2
dec a
- jr z,.flipBaseCoords ; 3
+ jr z, .flipBaseCoords ; 3
.noTransformation
- ld a,[wBaseCoordY]
+ ld a, [wBaseCoordY]
add [hl]
- ld [de],a ; store Y
+ ld [de], a ; store Y
inc hl
inc de
- ld a,[wBaseCoordX]
+ ld a, [wBaseCoordX]
jr .finishCopying
.flipBaseCoords
- ld a,[wBaseCoordY]
- ld b,a
- ld a,136
+ ld a, [wBaseCoordY]
+ ld b, a
+ ld a, 136
sub b ; flip Y base coordinate
add [hl] ; Y offset
- ld [de],a ; store Y
+ ld [de], a ; store Y
inc hl
inc de
- ld a,[wBaseCoordX]
- ld b,a
- ld a,168
+ ld a, [wBaseCoordX]
+ ld b, a
+ ld a, 168
sub b ; flip X base coordinate
.finishCopying ; finish copying values to OAM (when [wSubAnimTransform] not 1 or 2)
add [hl] ; X offset
- ld [de],a ; store X
+ ld [de], a ; store X
+ cp 88
+ jr c, .asm_78056
+ ld a, [wdef5]
+ inc a
+ ld [wdef5], a
+.asm_78056
inc hl
inc de
- ld a,[hli]
- add a,$31 ; base tile ID for battle animations
- ld [de],a ; store tile ID
+ ld a, [hli]
+ add a, $31 ; base tile ID for battle animations
+ ld [de], a ; store tile ID
inc de
- ld a,[hli]
- ld [de],a ; store flags
+ ld a, [hli]
+ ld b, a
+ ld a, [wdef5]
+ or b
+ ld [de], a ; store flags
inc de
jp .nextTile
.flipHorizontalAndVertical
- ld a,[wBaseCoordY]
+ ld a, [wBaseCoordY]
add [hl] ; Y offset
- ld b,a
- ld a,136
+ ld b, a
+ ld a, 136
sub b ; flip Y coordinate
- ld [de],a ; store Y
+ ld [de], a ; store Y
inc hl
inc de
- ld a,[wBaseCoordX]
+ ld a, [wBaseCoordX]
add [hl] ; X offset
- ld b,a
- ld a,168
+ ld b, a
+ ld a, 168
sub b ; flip X coordinate
- ld [de],a ; store X
+ ld [de], a ; store X
+ cp 88
+ jr c, .asm_78087
+ ld a, [wdef5]
+ inc a
+ ld [wdef5], a
+.asm_78087
inc hl
inc de
- ld a,[hli]
- add a,$31 ; base tile ID for battle animations
- ld [de],a ; store tile ID
+ ld a, [hli]
+ add a, $31 ; base tile ID for battle animations
+ ld [de], a ; store tile ID
inc de
; toggle horizontal and vertical flip
- ld a,[hli] ; flags
+ ld a, [hli] ; flags
and a
- ld b,OAM_VFLIP | OAM_HFLIP
- jr z,.storeFlags1
- cp a,OAM_HFLIP
- ld b,OAM_VFLIP
- jr z,.storeFlags1
- cp a,OAM_VFLIP
- ld b,OAM_HFLIP
- jr z,.storeFlags1
- ld b,0
+ ld b, OAM_VFLIP | OAM_HFLIP
+ jr z, .storeFlags1
+ cp a, OAM_HFLIP
+ ld b, OAM_VFLIP
+ jr z, .storeFlags1
+ cp a, OAM_VFLIP
+ ld b, OAM_HFLIP
+ jr z, .storeFlags1
+ ld b, 0
.storeFlags1
- ld a,b
- ld [de],a
+ ld a, [wdef5]
+ or b
+ ld [de], a
inc de
jp .nextTile
.flipHorizontalTranslateDown
- ld a,[wBaseCoordY]
+ ld a, [wBaseCoordY]
add [hl]
- add a,40 ; translate Y coordinate downwards
- ld [de],a ; store Y
+ add a, 40 ; translate Y coordinate downwards
+ ld [de], a ; store Y
inc hl
inc de
- ld a,[wBaseCoordX]
+ ld a, [wBaseCoordX]
add [hl]
- ld b,a
- ld a,168
+ ld b, a
+ ld a, 168
sub b ; flip X coordinate
- ld [de],a ; store X
+ ld [de], a ; store X
+ cp 88
+ jr c, .asm_780c8
+ ld a, [wdef5]
+ inc a
+ ld [wdef5], a
+.asm_780c8
inc hl
inc de
- ld a,[hli]
- add a,$31 ; base tile ID for battle animations
- ld [de],a ; store tile ID
+ ld a, [hli]
+ add a, $31 ; base tile ID for battle animations
+ ld [de], a ; store tile ID
inc de
- ld a,[hli]
- bit 5,a ; is horizontal flip enabled?
- jr nz,.disableHorizontalFlip
+ ld a, [hli]
+ bit 5, a ; is horizontal flip enabled?
+ jr nz, .disableHorizontalFlip
.enableHorizontalFlip
- set 5,a
+ set 5, a
jr .storeFlags2
.disableHorizontalFlip
- res 5,a
+ res 5, a
.storeFlags2
- ld [de],a
+ ld b, a
+ ld a, [wdef5]
+ or b
+ ld [de], a
inc de
.nextTile
- ld a,[wFBTileCounter]
- ld c,a
- ld a,[wNumFBTiles]
+ ld a, [wFBTileCounter]
+ ld c, a
+ ld a, [wNumFBTiles]
cp c
- jp nz,.loop ; go back up if there are more tiles to draw
+ jp nz, .loop ; go back up if there are more tiles to draw
.afterDrawingTiles
- ld a,[wFBMode]
- cp a,2
- jr z,.advanceFrameBlockDestAddr; skip delay and don't clean OAM buffer
- ld a,[wSubAnimFrameDelay]
- ld c,a
+ ld a, [wFBMode]
+ cp a, 2
+ jr z, .advanceFrameBlockDestAddr; skip delay and don't clean OAM buffer
+ ld a, [wSubAnimFrameDelay]
+ ld c, a
call DelayFrames
- 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,[wAnimationID]
- cp a,GROWL
- jr z,.resetFrameBlockDestAddr
+ 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, [wAnimationID]
+ cp a, GROWL
+ jr z, .resetFrameBlockDestAddr
call AnimationCleanOAM
.resetFrameBlockDestAddr
- ld hl,wOAMBuffer ; OAM buffer
- ld a,l
- ld [wFBDestAddr + 1],a
- ld a,h
- ld [wFBDestAddr],a ; set destination address to beginning of OAM buffer
+ ld hl, wOAMBuffer ; OAM buffer
+ ld a, l
+ ld [wFBDestAddr + 1], a
+ ld a, h
+ ld [wFBDestAddr], a ; set destination address to beginning of OAM buffer
ret
.advanceFrameBlockDestAddr
- ld a,e
- ld [wFBDestAddr + 1],a
- ld a,d
- ld [wFBDestAddr],a
+ ld a, e
+ ld [wFBDestAddr + 1], a
+ ld a, d
+ ld [wFBDestAddr], a
.done
ret
PlayAnimation:
xor a
- ld [$FF8B],a ; it looks like nothing reads this
- ld [wSubAnimTransform],a
- ld a,[wAnimationID] ; 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 ; animation command stream pointers
- add hl,de
- ld a,[hli]
- ld h,[hl]
- ld l,a
+ ld l, a
+ ld h, 0
+ add hl, hl
+ ld de, AttackAnimationPointers ; animation command stream pointers
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
.animationLoop
- ld a,[hli]
- cp a,$FF
- jr z,.AnimationOver
- cp a,$C0 ; is this subanimation or a special effect?
- jr c,.playSubanimation
+ ld a, [hli]
+ cp a, $FF
+ jr z, .AnimationOver
+ cp a, $C0 ; is this subanimation or a special effect?
+ jr c, .playSubanimation
.doSpecialEffect
- ld c,a
- ld de,SpecialEffectPointers
+ ld c, a
+ ld de, SpecialEffectPointers
.searchSpecialEffectTableLoop
- ld a,[de]
+ ld a, [de]
cp c
- jr z,.foundMatch
+ jr z, .foundMatch
inc de
inc de
inc de
jr .searchSpecialEffectTableLoop
.foundMatch
- ld a,[hli]
- cp a,$FF ; is there a sound to play?
- jr z,.skipPlayingSound
- ld [wAnimSoundID],a ; store sound
+ ld a, [hli]
+ cp a, $FF ; is there a sound to play?
+ jr z, .skipPlayingSound
+ ld [wAnimSoundID], a ; store sound
push hl
push de
call GetMoveSound
@@ -206,50 +233,52 @@ PlayAnimation:
.skipPlayingSound
push hl
inc de
- ld a,[de]
- ld l,a
+ ld a, [de]
+ ld l, a
inc de
- ld a,[de]
- ld h,a
- ld de,.nextAnimationCommand
+ ld a, [de]
+ ld h, a
+ ld de, .nextAnimationCommand
push de
jp [hl] ; jump to special effect function
.playSubanimation
- ld c,a
- and a,%00111111
- ld [wSubAnimFrameDelay],a
+ ld c, a
+ and a, %00111111
+ ld [wSubAnimFrameDelay], a
xor a
sla c
rla
sla c
rla
- ld [wWhichBattleAnimTileset],a
- ld a,[hli] ; sound
- ld [wAnimSoundID],a ; store sound
- ld a,[hli] ; subanimation ID
- ld c,l
- ld b,h
- ld l,a
- ld h,0
- add hl,hl
- ld de,SubanimationPointers
- add hl,de
- ld a,l
- ld [wSubAnimAddrPtr],a
- ld a,h
- ld [wSubAnimAddrPtr + 1],a
- ld l,c
- ld h,b
+ ld [wWhichBattleAnimTileset], a
+ ld a, [hli] ; sound
+ ld [wAnimSoundID], a ; store sound
+ ld a, [hli] ; subanimation ID
+ ld c, l
+ ld b, h
+ ld l, a
+ ld h, 0
+ add hl, hl
+ ld de, SubanimationPointers
+ add hl, de
+ ld a, l
+ ld [wSubAnimAddrPtr], a
+ ld a, h
+ ld [wSubAnimAddrPtr + 1], a
+ ld l, c
+ ld h, b
push hl
- ld a,[rOBP0]
+ ld a, [rOBP0]
push af
- ld a,[wAnimPalette]
- ld [rOBP0],a
+ ld a, [wAnimPalette]
+ ld [rOBP0], a
+ call UpdateGBCPal_OBP0
call LoadAnimationTileset
call LoadSubanimation
call PlaySubanimation
pop af
- ld [rOBP0],a
+ ld [rOBP0], a
+ call UpdateGBCPal_OBP0
.nextAnimationCommand
pop hl
jr .animationLoop
@@ -257,22 +286,22 @@ PlayAnimation:
ret
LoadSubanimation:
- ld a,[wSubAnimAddrPtr + 1]
- ld h,a
- ld a,[wSubAnimAddrPtr]
- ld l,a
- ld a,[hli]
- ld e,a
- ld a,[hl]
- ld d,a ; de = address of subanimation
- ld a,[de]
- ld b,a
- and a,31
- ld [wSubAnimCounter],a ; number of frame blocks
- ld a,b
- and a,%11100000
- cp a,5 << 5 ; is subanimation type 5?
- jr nz,.isNotType5
+ ld a, [wSubAnimAddrPtr + 1]
+ ld h, a
+ ld a, [wSubAnimAddrPtr]
+ ld l, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hl]
+ ld d, a ; de = address of subanimation
+ ld a, [de]
+ ld b, a
+ and a, 31
+ ld [wSubAnimCounter], a ; number of frame blocks
+ ld a, b
+ and a, %11100000
+ cp a, 5 << 5 ; is subanimation type 5?
+ jr nz, .isNotType5
.isType5
call GetSubanimationTransform2
jr .saveTransformation
@@ -282,35 +311,35 @@ LoadSubanimation:
; place the upper 3 bits of a into bits 0-2 of a before storing
srl a
swap a
- ld [wSubAnimTransform],a
- cp a,4 ; is the animation reversed?
- ld hl,0
- jr nz,.storeSubentryAddr
+ 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,[wSubAnimCounter]
+ ld a, [wSubAnimCounter]
dec a
- ld bc,3
+ ld bc, 3
.loop
- add hl,bc
+ add hl, bc
dec a
- jr nz,.loop
+ jr nz, .loop
.storeSubentryAddr
inc de
- add hl,de
- ld a,l
- ld [wSubAnimSubEntryAddr],a
- ld a,h
- ld [wSubAnimSubEntryAddr + 1],a
+ add hl, de
+ ld a, l
+ ld [wSubAnimSubEntryAddr], a
+ ld a, h
+ 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:
- ld b,a
- ld a,[H_WHOSETURN]
+ ld b, a
+ ld a, [H_WHOSETURN]
and a
- ld a,b
+ ld a, b
ret nz
xor a
ret
@@ -319,32 +348,32 @@ GetSubanimationTransform1:
; 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:
- ld a,[H_WHOSETURN]
+ ld a, [H_WHOSETURN]
and a
- ld a,2 << 5
+ ld a, 2 << 5
ret z
xor a
ret
; loads tile patterns for battle animations
LoadAnimationTileset:
- ld a,[wWhichBattleAnimTileset]
+ ld a, [wWhichBattleAnimTileset]
add a
add a
- ld hl,AnimationTilesetPointers
- ld e,a
- ld d,0
- add hl,de
- ld a,[hli]
- 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 hl, AnimationTilesetPointers
+ ld e, a
+ ld d, 0
+ add hl, de
+ ld a, [hli]
+ 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,[wTempTilesetNumTiles]
- ld c,a ; number of tiles
+ ld a, [wTempTilesetNumTiles]
+ ld c, a ; number of tiles
jp CopyVideoData ; load tileset
AnimationTilesetPointers:
@@ -367,12 +396,7 @@ AnimationTileset2:
INCBIN "gfx/attack_anim_2.2bpp"
SlotMachineTiles2:
-IF DEF(_RED)
- INCBIN "gfx/red/slotmachine2.2bpp"
-ENDC
-IF DEF(_BLUE)
- INCBIN "gfx/blue/slotmachine2.2bpp"
-ENDC
+ INCBIN "gfx/slotmachine2.2bpp"
MoveAnimation:
push hl
@@ -381,38 +405,38 @@ MoveAnimation:
push af
call WaitForSoundToFinish
call SetAnimationPalette
- ld a,[wAnimationID]
+ 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
+ cp a, TOSS_ANIM
+ jr nz, .moveAnimation
+ ld de, .animationFinished
push de
jp TossBallAnimation
-.MoveAnimation
+.moveAnimation
; check if battle animations are disabled in the options
- ld a,[wOptions]
- bit 7,a
- jr nz,.AnimationsDisabled
+ ld a, [wOptions]
+ bit 7, a
+ jr nz, .animationsDisabled
call ShareMoveAnimations
call PlayAnimation
jr .next4
-.AnimationsDisabled
- ld c,30
+.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 [wSubAnimSubEntryAddr],a
- ld [wUnusedD09B],a
- ld [wSubAnimTransform],a
+ ld [wSubAnimSubEntryAddr], a
+ ld [wUnusedD09B], a
+ ld [wSubAnimTransform], a
dec a
- ld [wAnimSoundID],a
+ ld [wAnimSoundID], a
pop af
pop bc
pop de
@@ -421,42 +445,42 @@ MoveAnimation:
ShareMoveAnimations:
; some moves just reuse animations from status conditions
- ld a,[H_WHOSETURN]
+ ld a, [H_WHOSETURN]
and a
ret z
; opponent’s turn
- ld a,[wAnimationID]
+ ld a, [wAnimationID]
- cp a,AMNESIA
- ld b,CONF_ANIM
- jr z,.Replace
+ cp a, AMNESIA
+ ld b, CONF_ANIM
+ jr z, .replaceAnim
- cp a,REST
- ld b,SLP_ANIM
+ cp a, REST
+ ld b, SLP_ANIM
ret nz
-.Replace
- ld a,b
- ld [wAnimationID],a
+.replaceAnim
+ ld a, b
+ ld [wAnimationID], a
ret
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]
+ ld a, [wAnimationType]
and a
ret z
dec a
add a
- ld c,a
- ld b,0
- ld hl,AnimationTypePointerTable
- add hl,bc
- ld a,[hli]
- ld h,[hl]
- ld l,a
+ ld c, a
+ ld b, 0
+ ld hl, AnimationTypePointerTable
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
jp [hl]
AnimationTypePointerTable:
@@ -537,6 +561,8 @@ SetAnimationPalette:
ld [rOBP0], a
ld a, $6c
ld [rOBP1], a
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
ret
.notSGB
ld a, $e4
@@ -544,72 +570,94 @@ SetAnimationPalette:
ld [rOBP0], a
ld a, $6c
ld [rOBP1], a
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ret
+
+Func_78e98:
+ call SaveScreenTilesToBuffer2
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call ClearScreen
+ ld h, vBGMap0 / $100
+ call WriteLowerByteOfBGMapAndEnableBGTransfer
+ call Delay3
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call LoadScreenTilesFromBuffer2
+ ld h, vBGMap1 / $100
+
+WriteLowerByteOfBGMapAndEnableBGTransfer:
+ ld l, vBGMap0 & $ff
+ call BattleAnimCopyTileMapToVRAM
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
ret
PlaySubanimation:
- ld a,[wAnimSoundID]
- cp a,$FF
- jr z,.skipPlayingSound
+ ld a, [wAnimSoundID]
+ cp a, $FF
+ jr z, .skipPlayingSound
call GetMoveSound
call PlaySound
.skipPlayingSound
- ld hl,wOAMBuffer ; base address of OAM buffer
- ld a,l
- ld [wFBDestAddr + 1],a
- ld a,h
- ld [wFBDestAddr],a
- ld a,[wSubAnimSubEntryAddr + 1]
- ld h,a
- ld a,[wSubAnimSubEntryAddr]
- ld l,a
+ ld hl, wOAMBuffer ; base address of OAM buffer
+ ld a, l
+ ld [wFBDestAddr + 1], a
+ ld a, h
+ ld [wFBDestAddr], a
+ ld a, [wSubAnimSubEntryAddr + 1]
+ ld h, a
+ ld a, [wSubAnimSubEntryAddr]
+ ld l, a
.loop
push hl
- ld c,[hl] ; frame block ID
- ld b,0
- ld hl,FrameBlockPointers
- add hl,bc
- add hl,bc
- ld a,[hli]
- ld c,a
- ld a,[hli]
- ld b,a
+ ld c, [hl] ; frame block ID
+ ld b, 0
+ ld hl, FrameBlockPointers
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
pop hl
inc hl
push hl
- ld e,[hl] ; base coordinate ID
- ld d,0
- ld hl,FrameBlockBaseCoords ; base coordinate table
- add hl,de
- add hl,de
- ld a,[hli]
- ld [wBaseCoordY],a
- ld a,[hl]
- ld [wBaseCoordX],a
+ ld e, [hl] ; base coordinate ID
+ ld d, 0
+ ld hl, FrameBlockBaseCoords ; base coordinate table
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld [wBaseCoordY], a
+ ld a, [hl]
+ ld [wBaseCoordX], a
pop hl
inc hl
- ld a,[hl] ; frame block mode
- ld [wFBMode],a
+ ld a, [hl] ; frame block mode
+ ld [wFBMode], a
call DrawFrameBlock
call DoSpecialEffectByAnimationId ; run animation-specific function (if there is one)
- ld a,[wSubAnimCounter]
+ ld a, [wSubAnimCounter]
dec a
- ld [wSubAnimCounter],a
+ ld [wSubAnimCounter], a
ret z
- ld a,[wSubAnimSubEntryAddr + 1]
- ld h,a
- ld a,[wSubAnimSubEntryAddr]
- ld l,a
- ld a,[wSubAnimTransform]
- cp a,4 ; is the animation reversed?
- ld bc,3
- jr nz,.nextSubanimationSubentry
- ld bc,-3
+ ld a, [wSubAnimSubEntryAddr + 1]
+ ld h, a
+ ld a, [wSubAnimSubEntryAddr]
+ ld l, a
+ ld a, [wSubAnimTransform]
+ cp a, 4 ; is the animation reversed?
+ ld bc, 3
+ jr nz, .nextSubanimationSubentry
+ ld bc, -3
.nextSubanimationSubentry
- add hl,bc
- ld a,h
- ld [wSubAnimSubEntryAddr + 1],a
- ld a,l
- ld [wSubAnimSubEntryAddr],a
+ add hl, bc
+ ld a, h
+ ld [wSubAnimSubEntryAddr + 1], a
+ ld a, l
+ ld [wSubAnimSubEntryAddr], a
jp .loop
AnimationCleanOAM:
@@ -631,16 +679,16 @@ DoSpecialEffectByAnimationId:
push hl
push de
push bc
- ld a,[wAnimationID]
- ld hl,AnimationIdSpecialEffects
- ld de,3
+ ld a, [wAnimationID]
+ ld hl, AnimationIdSpecialEffects
+ ld de, 3
call IsInArray
- jr nc,.done
+ jr nc, .done
inc hl
- ld a,[hli]
- ld h,[hl]
- ld l,a
- ld de,.done
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, .done
push de
jp [hl]
.done
@@ -691,7 +739,7 @@ AnimationIdSpecialEffects:
dw DoExplodeSpecialEffects
db SPORE
- dw AnimationFlashScreen
+ dw FlashScreenEveryFourFrameBlocks
db EXPLOSION
dw DoExplodeSpecialEffects
@@ -726,38 +774,39 @@ AnimationIdSpecialEffects:
db $FF ; terminator
DoBallTossSpecialEffects:
- ld a,[wcf91]
- cp a,3 ; is it a Master Ball or Ultra Ball?
- jr nc,.skipFlashingEffect
+ ld a, [wcf91]
+ cp a, 3 ; is it a Master Ball or Ultra Ball?
+ jr nc, .skipFlashingEffect
.flashingEffect ; do a flashing effect if it's Master Ball or Ultra Ball
- ld a,[rOBP0]
- xor a,%00111100 ; complement colors 1 and 2
- ld [rOBP0],a
+ ld a, [rOBP0]
+ xor a, %00111100 ; complement colors 1 and 2
+ ld [rOBP0], a
+ call UpdateGBCPal_OBP0
.skipFlashingEffect
- ld a,[wSubAnimCounter]
- cp a,11 ; is it the beginning of the subanimation?
- jr nz,.skipPlayingSound
+ 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_BALL_TOSS
+ ld a, SFX_BALL_TOSS
call PlaySound
.skipPlayingSound
- 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?
+ 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,[wSubAnimCounter]
- cp a,3
- jr z,.moveGhostMarowakLeft
- cp a,2
- jr z,.moveGhostMarowakLeft
- cp a,1
+ ld a, [wSubAnimCounter]
+ cp a, 3
+ jr z, .moveGhostMarowakLeft
+ cp a, 2
+ jr z, .moveGhostMarowakLeft
+ cp a, 1
ret nz
.moveGhostMarowakLeft
coord hl, 17, 0
- ld de,20
+ ld de, 20
lb bc, 7, 7
.loop
push hl
@@ -765,152 +814,152 @@ DoBallTossSpecialEffects:
call AnimCopyRowRight ; move row of tiles left
pop bc
pop hl
- add hl,de
+ add hl, de
dec b
- jr nz,.loop
- ld a,%00001000
- ld [rNR10],a ; Channel 1 sweep register
+ jr nz, .loop
+ ld a, %00001000
+ ld [rNR10], a ; Channel 1 sweep register
ret
.isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame
- ld a,[wSubAnimCounter]
- cp a,3
+ ld a, [wSubAnimCounter]
+ cp a, 3
ret nz
dec a
- ld [wSubAnimCounter],a
+ ld [wSubAnimCounter], a
ret
DoBallShakeSpecialEffects:
- ld a,[wSubAnimCounter]
- cp a,4 ; is it the beginning of a shake?
- jr nz,.skipPlayingSound
+ 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_TINK
+ ld a, SFX_TINK
call PlaySound
- ld c,40
+ ld c, 40
call DelayFrames
.skipPlayingSound
- ld a,[wSubAnimCounter]
+ 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,[wNumShakes] ; number of shakes
+ ld a, [wNumShakes] ; number of shakes
dec a ; decrement number of shakes
- ld [wNumShakes],a
+ ld [wNumShakes], a
ret z
; if there are shakes left, restart the subanimation
- ld a,[wSubAnimSubEntryAddr]
- ld l,a
- 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 [wSubAnimSubEntryAddr],a
- ld a,h
- ld [wSubAnimSubEntryAddr + 1],a
- ld a,5 ; number of subentries in the ball shaking subanimation plus one
- ld [wSubAnimCounter],a
+ ld a, [wSubAnimSubEntryAddr]
+ ld l, a
+ 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 [wSubAnimSubEntryAddr], a
+ ld a, h
+ ld [wSubAnimSubEntryAddr + 1], a
+ ld a, 5 ; number of subentries in the ball shaking subanimation plus one
+ ld [wSubAnimCounter], a
ret
; plays a sound after the second frame of the poof animation
DoPoofSpecialEffects:
- ld a,[wSubAnimCounter]
- cp a,5
+ ld a, [wSubAnimCounter]
+ cp a, 5
ret nz
- ld a,SFX_BALL_POOF
+ ld a, SFX_BALL_POOF
jp PlaySound
DoRockSlideSpecialEffects:
- ld a,[wSubAnimCounter]
- cp a,12
+ ld a, [wSubAnimCounter]
+ cp a, 12
ret nc
- cp a,8
- jr nc,.shakeScreen
- cp a,1
- jp z,AnimationFlashScreen ; if it's the end of the subanimation, flash the screen
+ cp a, 8
+ jr nc, .shakeScreen
+ cp a, 1
+ jp z, AnimationFlashScreen ; if it's the end of the subanimation, flash the screen
ret
; if the subaninmation counter is between 8 and 11, shake the screen horizontally and vertically
.shakeScreen
- ld b,1
+ ld b, 1
predef PredefShakeScreenHorizontally ; shake horizontally
- ld b,1
+ ld b, 1
predef_jump PredefShakeScreenVertically ; shake vertically
FlashScreenEveryEightFrameBlocks:
- ld a,[wSubAnimCounter]
- and a,7 ; is the subanimation counter exactly 8?
- call z,AnimationFlashScreen ; if so, flash the screen
+ 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:
- ld a,[wSubAnimCounter]
- and a,3
- call z,AnimationFlashScreen
+ ld a, [wSubAnimCounter]
+ and a, 3
+ call z, AnimationFlashScreen
ret
; used for Explosion and Selfdestruct
DoExplodeSpecialEffects:
- ld a,[wSubAnimCounter]
- cp a,1 ; is it the end of the subanimation?
- jr nz,FlashScreenEveryFourFrameBlocks
+ 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
coord hl, 1, 5
jp AnimationHideMonPic ; make pokemon disappear
; flashes the screen when subanimation counter is 1 modulo 4
DoBlizzardSpecialEffects:
- ld a,[wSubAnimCounter]
- cp a,13
- jp z,AnimationFlashScreen
- cp a,9
- jp z,AnimationFlashScreen
- cp a,5
- jp z,AnimationFlashScreen
- cp a,1
- jp z,AnimationFlashScreen
+ ld a, [wSubAnimCounter]
+ cp a, 13
+ jp z, AnimationFlashScreen
+ cp a, 9
+ jp z, AnimationFlashScreen
+ cp a, 5
+ jp z, AnimationFlashScreen
+ cp a, 1
+ jp z, AnimationFlashScreen
ret
; flashes the screen at 3 points in the subanimation
; unused
FlashScreenUnused:
- ld a,[wSubAnimCounter]
- cp a,14
- jp z,AnimationFlashScreen
- cp a,9
- jp z,AnimationFlashScreen
- cp a,2
- jp z,AnimationFlashScreen
+ ld a, [wSubAnimCounter]
+ cp a, 14
+ jp z, AnimationFlashScreen
+ cp a, 9
+ jp z, AnimationFlashScreen
+ cp a, 2
+ jp z, AnimationFlashScreen
ret
; function to make the pokemon disappear at the beginning of the animation
TradeHidePokemon:
- ld a,[wSubAnimCounter]
- cp a,6
+ ld a, [wSubAnimCounter]
+ cp a, 6
ret nz
- ld a,2 * SCREEN_WIDTH + 7
+ 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
TradeShakePokeball:
- ld a,[wSubAnimCounter]
- cp a,1
+ ld a, [wSubAnimCounter]
+ cp a, 1
ret nz
; if it's the end of the animation, make the ball jump up
- ld de,BallMoveDistances1
+ ld de, BallMoveDistances1
.loop
- ld hl,wOAMBuffer ; OAM buffer
- ld bc,4
+ ld hl, wOAMBuffer ; OAM buffer
+ ld bc, 4
.innerLoop
- ld a,[de]
- cp a,$ff
- jr z,.done
+ ld a, [de]
+ cp a, $ff
+ jr z, .done
add [hl] ; add to Y value of OAM entry
- ld [hl],a
- add hl,bc
- ld a,l
- cp a,4 * 4 ; there are 4 entries, each 4 bytes
- jr nz,.innerLoop
+ ld [hl], a
+ add hl, bc
+ ld a, l
+ cp a, 4 * 4 ; there are 4 entries, each 4 bytes
+ jr nz, .innerLoop
inc de
push bc
call Delay3
@@ -918,74 +967,73 @@ TradeShakePokeball:
jr .loop
.done
call AnimationCleanOAM
- ld a,SFX_TRADE_MACHINE
+ ld a, SFX_TRADE_MACHINE
jp PlaySound
BallMoveDistances1:
- db -12,-12,-8
+ db -12, -12, -8
db $ff ; terminator
; function to make the pokeball jump up
-TradeJumpPokeball: ; 507C
- ld de,BallMoveDistances2
+TradeJumpPokeball:
+ ld de, BallMoveDistances2
.loop
- ld hl,wOAMBuffer ; OAM buffer
- ld bc,4
+ ld hl, wOAMBuffer ; OAM buffer
+ ld bc, 4
.innerLoop
- ld a,[de]
- cp a,$ff
- jp z,ClearScreen
+ ld a, [de]
+ cp a, $ff
+ jp z, ClearScreen
add [hl]
- ld [hl],a
- add hl,bc
- ld a,l
- cp a,4 * 4 ; there are 4 entries, each 4 bytes
- jr nz,.innerLoop
+ ld [hl], a
+ add hl, bc
+ ld a, l
+ cp a, 4 * 4 ; there are 4 entries, each 4 bytes
+ jr nz, .innerLoop
inc de
push de
- ld a,[de]
- cp a,12
- jr z,.playSound
- cp a,$ff
- jr nz,.skipPlayingSound
+ ld a, [de]
+ cp a, 12
+ jr z, .playSound
+ cp a, $ff
+ jr nz, .skipPlayingSound
.playSound ; play sound if next move distance is 12 or this is the last one
- ld a,SFX_BATTLE_18
+ ld a, SFX_BATTLE_18
call PlaySound
.skipPlayingSound
push bc
- ld c,5
+ ld c, 5
call DelayFrames
pop bc
- ld a,[hSCX] ; background scroll X
- sub a,8 ; scroll to the left
- ld [hSCX],a
+ ld a, [hSCX] ; background scroll X
+ sub a, 8 ; scroll to the left
+ ld [hSCX], a
pop de
jr .loop
BallMoveDistances2:
- db 11,12,-12,-7,7,12,-8,8
+ 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:
- ld hl,wOAMBuffer ; OAM buffer
- ld de,wOAMBuffer + $10
- ld bc,$10
+ ld hl, wOAMBuffer ; OAM buffer
+ ld de, wOAMBuffer + $10
+ ld bc, $10
call CopyData ; copy the musical note graphic
- ld a,[wSubAnimCounter]
+ ld a, [wSubAnimCounter]
dec a
- call z,AnimationCleanOAM ; clean up at the end of the subanimation
+ 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
TailWhipAnimationUnused:
- ld a,1
- ld [wSubAnimCounter],a
- ld c,20
+ ld a, 1
+ ld [wSubAnimCounter], a
+ ld c, 20
jp DelayFrames
-; Format: Special Effect ID (1 byte), Address (2 bytes)
SpecialEffectPointers:
db SE_DARK_SCREEN_FLASH ; $FE
dw AnimationFlashScreen
@@ -1068,48 +1116,49 @@ SpecialEffectPointers:
db $FF
AnimationDelay10:
- ld c,10
+ 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:
- ld a,[H_WHOSETURN]
+ ld a, [H_WHOSETURN]
push af
- xor a,1
- ld [H_WHOSETURN],a
- ld de,.returnAddress
+ xor a, 1
+ ld [H_WHOSETURN], a
+ ld de, .returnAddress
push de
jp [hl]
.returnAddress
pop af
- ld [H_WHOSETURN],a
+ ld [H_WHOSETURN], a
ret
; flashes the screen for an extended period (48 frames)
AnimationFlashScreenLong:
- ld a,3 ; cycle through the palettes 3 times
- ld [wFlashScreenLongCounter],a
- ld a,[wOnSGB] ; running on SGB?
+ ld a, 3 ; cycle through the palettes 3 times
+ ld [wFlashScreenLongCounter], a
+ ld a, [wOnSGB] ; running on SGB?
and a
- ld hl,FlashScreenLongMonochrome
- jr z,.loop
- ld hl,FlashScreenLongSGB
+ ld hl, FlashScreenLongMonochrome
+ jr z, .loop
+ ld hl, FlashScreenLongSGB
.loop
push hl
.innerLoop
- ld a,[hli]
- cp a,$01 ; is it the end of the palettes?
- jr z,.endOfPalettes
- ld [rBGP],a
+ ld a, [hli]
+ cp a, $01 ; is it the end of the palettes?
+ jr z, .endOfPalettes
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
call FlashScreenLongDelay
jr .innerLoop
.endOfPalettes
- ld a,[wFlashScreenLongCounter]
+ ld a, [wFlashScreenLongCounter]
dec a
- ld [wFlashScreenLongCounter],a
+ ld [wFlashScreenLongCounter], a
pop hl
- jr nz,.loop
+ jr nz, .loop
ret
; BG palettes
@@ -1147,31 +1196,34 @@ FlashScreenLongSGB:
; causes a delay of 2 frames for the first cycle
; causes a delay of 1 frame for the second and third cycles
FlashScreenLongDelay:
- ld a,[wFlashScreenLongCounter]
- cp a,4 ; never true since [wFlashScreenLongCounter] starts at 3
- ld c,4
- jr z,.delayFrames
- cp a,3
- ld c,2
- jr z,.delayFrames
- cp a,2 ; nothing is done with this
- ld c,1
+ ld a, [wFlashScreenLongCounter]
+ cp a, 4 ; never true since [wFlashScreenLongCounter] starts at 3
+ ld c, 4
+ jr z, .delayFrames
+ cp a, 3
+ ld c, 2
+ jr z, .delayFrames
+ cp a, 2 ; nothing is done with this
+ ld c, 1
.delayFrames
jp DelayFrames
AnimationFlashScreen:
- ld a,[rBGP]
+ ld a, [rBGP]
push af ; save initial palette
- ld a,%00011011 ; 0, 1, 2, 3 (inverted colors)
- ld [rBGP],a
- ld c,2
+ ld a, %00011011 ; 0, 1, 2, 3 (inverted colors)
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ ld c, 2
call DelayFrames
xor a ; white out background
- ld [rBGP],a
- ld c,2
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ ld c, 2
call DelayFrames
pop af
- ld [rBGP],a ; restore initial palette
+ ld [rBGP], a ; restore initial palette
+ call UpdateGBCPal_BGP
ret
AnimationDarkScreenPalette:
@@ -1217,6 +1269,7 @@ SetAnimationBGPalette:
ld a, c
.next
ld [rBGP], a
+ call UpdateGBCPal_BGP
ret
ld b, $5
@@ -1261,15 +1314,30 @@ AnimationWaterDropletsEverywhere:
_AnimationWaterDroplets:
ld hl, wOAMBuffer
.loop
+ ld a, $1
+ ld [wdef5], a
ld a, [wBaseCoordY]
ld [hli], a ; Y
+ cp 40
+ jr c, .asm_792d7
+ ld a, [wdef5]
+ inc a
+ ld [wdef5], a
+.asm_792d7
ld a, [wBaseCoordX]
add 27
ld [wBaseCoordX], a
ld [hli], a ; X
+ cp 88
+ jr c, .asm_792ee
+ ld a, [wdef5]
+ add $2
+ and $3
+ ld [wdef5], a
+.asm_792ee
ld a, [wDropletTile]
ld [hli], a ; tile
- xor a
+ ld a, [wdef5]
ld [hli], a ; attribute
ld a, [wBaseCoordX]
cp 144
@@ -1412,16 +1480,30 @@ BattleAnimWriteOAMEntry:
; Y coordinate = e (increased by 8 each call, before the write to OAM)
; X coordinate = [wBaseCoordX]
; tile = d
-; attributes = 0
+; attributes = variable (dependant on coords)
+ ld a, $1
+ ld [wdef5], a
ld a, e
add 8
ld e, a
ld [hli], a
+ cp 40
+ jr c, .asm_793d8
+ ld a, [wdef5]
+ inc a
+ ld [wdef5], a
+.asm_793d8
ld a, [wBaseCoordX]
ld [hli], a
+ cp 88
+ jr c, .asm_793e8
+ ld a, [wdef5]
+ add $2
+ ld [wdef5], a
+.asm_793e8
ld a, d
ld [hli], a
- xor a
+ ld a, [wdef5]
ld [hli], a
ret
@@ -1473,7 +1555,7 @@ AdjustOAMBlockYPos2:
ret
AnimationBlinkEnemyMon:
-; Make the enemy mon's sprite blink on and off for a second or two
+ ; Make the enemy mon's sprite blink on and off for a second or two
ld hl, AnimationBlinkMon
jp CallWithTurnFlipped
@@ -1626,6 +1708,8 @@ AnimationSpiralBallsInward:
ld a, [hl]
cp $ff
jr z, .done
+ ld a, $2
+ ld [wdef5], a
ld a, [wSpiralBallsBaseY]
add [hl]
ld [de], a ; Y
@@ -1634,9 +1718,20 @@ AnimationSpiralBallsInward:
ld a, [wSpiralBallsBaseX]
add [hl]
ld [de], a ; X
+ cp 88
+ jr c, .asm_79524
+ ld a, $3
+ ld [wdef5], a
+.asm_79524
inc hl
inc de
inc de
+ ld a, [de]
+ and $f0
+ ld b, a
+ ld a, [wdef5]
+ or b
+ ld [de], a
inc de
dec c
jr nz, .innerLoop
@@ -1845,13 +1940,13 @@ AnimationMinimizeMon:
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
- ld c, $5
+ ld c, MinimizedMonSpriteEnd - MinimizedMonSprite
.loop
ld a, [de]
ld [hli], a
@@ -1865,6 +1960,7 @@ AnimationMinimizeMon:
MinimizedMonSprite:
INCBIN "gfx/minimized_mon_sprite.1bpp"
+MinimizedMonSpriteEnd:
AnimationSlideMonDownAndHide:
; Slides the mon's sprite down and disappears. Used in Acid Armor.
@@ -1937,25 +2033,23 @@ _AnimationSlideMonOff:
jr nz, .slideLoop
ret
-; Since mon pic tile numbers go from top to bottom, left to right in order,
+; 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 ; 79633 (1e:5633)
+.PlayerNextTile ; 79702 (1e:5702)
ld a, [hl]
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
+; bugfix: compares against the max tile + 1 as opposed to the max tile
+ cp $62
ret c
ld a, " "
ret
-.EnemyNextTile ; 7963c (1e:563c)
+.EnemyNextTile ; 7970b (1e:570b)
ld a, [hl]
sub 7
; This has the same problem as above, but it has no visible effect because
@@ -2087,18 +2181,24 @@ AnimationSubstitute:
CopySlowbroSpriteData:
ld bc, $0010
ld a, BANK(SlowbroSprite)
- jp FarCopyData2
+ jp FarCopyData
HideSubstituteShowMonAnim:
ld a, [H_WHOSETURN]
and a
ld hl, wPlayerMonMinimized
+ ld de, wPlayerBattleStatus1
+ ld bc, wPlayerMoveNum
ld a, [wPlayerBattleStatus2]
jr z, .next1
ld hl, wEnemyMonMinimized
+ ld de, wEnemyBattleStatus1
+ ld bc, wEnemyMoveNum
ld a, [wEnemyBattleStatus2]
.next1
push hl
+ push de
+ push bc
; if the substitute broke, slide it down, else slide it offscreen horizontally
bit HasSubstituteUp, a
jr nz, .substituteStillUp
@@ -2107,12 +2207,65 @@ HideSubstituteShowMonAnim:
.substituteStillUp
call AnimationSlideMonOff
.next2
+ pop bc
+ pop de
+ ld a, [de]
+ bit Invulnerable, a
pop hl
+ jr nz, .invulnerable
+ ld a, [bc]
+ cp FLY
+ jr z, .flyOrDig
+ cp DIG
+ jr z, .flyOrDig
+.invulnerable
ld a, [hl]
and a
jp nz, AnimationMinimizeMon
call AnimationFlashMonPic
jp AnimationShowMonPic
+.flyOrDig
+ ld a, [H_WHOSETURN]
+ and a
+ jr nz, .enemy
+ ld a, [wPlayerMonMinimized]
+ and a
+ jr nz, .monIsMinimized
+ ld a, [wBattleMonSpecies]
+ ld [wcf91], a
+ ld [wd0b5], a
+ call GetMonHeader
+ predef LoadMonBackPic
+ ret
+.enemy
+ ld a, [wEnemyMonMinimized]
+ and a
+ jr nz, .monIsMinimized
+ ld a, [wEnemyMonSpecies]
+ ld [wcf91], a
+ ld [wd0b5], a
+ call GetMonHeader
+ ld de, vFrontPic
+ jp LoadMonFrontSprite
+.monIsMinimized
+ ld hl, wTempPic
+ push hl
+ xor a
+ ld bc, 7 * 7 * $10
+ call FillMemory
+ pop hl
+ ld de, $194
+ add hl, de
+ ld de, MinimizedMonSprite
+ ld c, MinimizedMonSpriteEnd - MinimizedMonSprite
+.loop
+ ld a, [de]
+ ld [hli], a
+ ld [hli], a
+ inc de
+ dec c
+ jr nz, .loop
+ jp CopyTempPicToMonPic
ReshowSubstituteAnim:
call AnimationSlideMonOff
@@ -2180,6 +2333,23 @@ AnimationHideEnemyMonPic:
ld [H_AUTOBGTRANSFERENABLED], a
jp Delay3
+Func_79929:
+ ld hl, wPlayerMonMinimized
+ ld a, [H_WHOSETURN]
+ and a
+ jr z, .playerTurn
+ ld hl, wEnemyMonMinimized
+.playerTurn
+ ld a, [hl]
+ and a
+ jr z, .notMinimized
+ call AnimationMinimizeMon
+ ret
+.notMinimized
+ call AnimationFlashMonPic
+ call AnimationShowMonPic
+ ret
+
InitMultipleObjectsOAM:
; Writes c OAM entries with tile d.
; Sets their Y coordinates to sequential multiples of 8, starting from 0.
@@ -2201,6 +2371,8 @@ InitMultipleObjectsOAM:
jr nz, .loop
ret
+ ret ; unreferenced
+
AnimationHideMonPic:
; Hides the mon's sprite.
ld a, [H_WHOSETURN]
@@ -2227,7 +2399,7 @@ ClearMonPicFromTileMap:
ret
; 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,
+; 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:
push de
@@ -2308,54 +2480,53 @@ GetMoveSoundB:
ld b, a
ret
-; get the sound of the (move id - 1) in a
GetMoveSound:
- ld hl,MoveSoundTable
- ld e,a
- ld d,0
- add hl,de
- add hl,de
- add hl,de
- ld a,[hli]
- ld b,a
+ ld hl, MoveSoundTable
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld b, a
call IsCryMove
- jr nc,.NotCryMove
- ld a,[H_WHOSETURN]
+ jr nc, .NotCryMove
+ ld a, [H_WHOSETURN]
and a
- jr nz,.next
- ld a,[wBattleMonSpecies] ; get number of current monster
+ jr nz, .next
+ ld a, [wBattleMonSpecies] ; get number of current monster
jr .Continue
.next
- ld a,[wEnemyMonSpecies]
+ ld a, [wEnemyMonSpecies]
.Continue
push hl
call GetCryData
- ld b,a
+ ld b, a
pop hl
- ld a,[wFrequencyModifier]
+ ld a, [wFrequencyModifier]
add [hl]
- ld [wFrequencyModifier],a
+ ld [wFrequencyModifier], a
inc hl
- ld a,[wTempoModifier]
+ ld a, [wTempoModifier]
add [hl]
- ld [wTempoModifier],a
+ ld [wTempoModifier], a
jr .done
.NotCryMove
- ld a,[hli]
- ld [wFrequencyModifier],a
- ld a,[hli]
- ld [wTempoModifier],a
+ ld a, [hli]
+ ld [wFrequencyModifier], a
+ ld a, [hli]
+ ld [wTempoModifier], a
.done
- ld a,b
+ ld a, b
ret
IsCryMove:
; set carry if the move animation involves playing a monster cry
- ld a,[wAnimationID]
- cp a,GROWL
- jr z,.CryMove
- cp a,ROAR
- jr z,.CryMove
+ ld a, [wAnimationID]
+ cp a, GROWL
+ jr z, .CryMove
+ cp a, ROAR
+ jr z, .CryMove
and a ; clear carry
ret
.CryMove
@@ -2363,172 +2534,173 @@ IsCryMove:
ret
MoveSoundTable:
- 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
+ ; 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_EARTHQUAKE, $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_EARTHQUAKE, $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_EARTHQUAKE, $f0, $80 ; DRAGON_RAGE
+ db SFX_EARTHQUAKE, $20, $c0 ; FIRE_SPIN
+ db SFX_THUNDERBOLT, $00, $20 ; THUNDERSHOCK
+ db SFX_THUNDERBOLT, $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_EARTHQUAKE, $0f, $e0 ; EARTHQUAKE
+ db SFX_EARTHQUAKE, $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_EARTHQUAKE, $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_EARTHQUAKE, $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]
@@ -2586,112 +2758,108 @@ CopyTileIDs:
ret
TileIDListPointerTable:
- dw Unknown_79b24
- db $77
- dw Unknown_79b55
- db $57
- dw Unknown_79b78
- db $37
- dw Unknown_79b8d
- db $77
- dw Unknown_79bbe
- db $77
- dw Unknown_79bef
- db $77
- dw Unknown_79c20
- db $86
- dw Unknown_79c50
- db $3C
+ dw DownscaledMonTiles_7x7
+ dn 7, 7
+ dw DownscaledMonTiles_5x7
+ dn 5, 7
+ dw DownscaledMonTiles_3x7
+ dn 3, 7
+ dw DownscaledMonTiles_79ce9
+ dn 7, 7
+ dw DownscaledMonTiles_79d1a
+ dn 7, 7
+ dw DownscaledMonTiles_79d4b
+ dn 7, 7
+ dw DownscaledMonTiles_79d7c
+ dn 8, 6
+ dw DownscaledMonTiles_79dac
+ dn 3, 12
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
+ 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
DownscaledMonTiles_3x3:
- db $31,$46,$5B
- db $34,$49,$5E
- db $37,$4C,$61
-
-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
- db $03,$0A,$11,$18,$1F,$26,$2D
- db $04,$0B,$12,$19,$20,$27,$2E
- db $05,$0C,$13,$1A,$21,$28,$2F
- db $06,$0D,$14,$1B,$22,$29,$30
-
-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:
- 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:
- db $00,$00,$00,$00,$00,$00,$00
- db $00,$00,$00,$00,$00,$19,$00
- db $02,$06,$0B,$10,$14,$1A,$00
- db $00,$07,$0C,$11,$15,$1B,$00
- db $03,$08,$0D,$12,$16,$1C,$00
- db $04,$09,$0E,$13,$17,$1D,$1F
- db $05,$0A,$0F,$01,$18,$1E,$20
-
-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
- db $22,$27,$2D,$32,$36,$01,$00
- db $23,$28,$2E,$33,$01,$3A,$00
- db $24,$29,$2F,$01,$01,$3B,$00
- db $25,$2A,$01,$01,$01,$3C,$00
-
-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
- db $3F,$43,$49,$4F,$53,$57,$5C
- db $40,$44,$4A,$50,$54,$58,$00
- db $41,$45,$4B,$51,$4C,$59,$5D
- db $42,$46,$4C,$4C,$55,$5A,$5E
-
-Unknown_79c20:
- db $31,$32,$32,$32,$32,$33
- db $34,$35,$36,$36,$37,$38
- db $34,$39,$3A,$3A,$3B,$38
- db $3C,$3D,$3E,$3E,$3F,$40
- db $41,$42,$43,$43,$44,$45
- db $46,$47,$43,$48,$49,$4A
- db $41,$43,$4B,$4C,$4D,$4E
- db $4F,$50,$50,$50,$51,$52
-
-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
+ db $31, $46, $5B
+ db $34, $49, $5E
+ db $37, $4C, $61
+
+DownscaledMonTiles_7x7:
+ db $00, $07, $0E, $15, $1C, $23, $2A
+ db $01, $08, $0F, $16, $1D, $24, $2B
+ db $02, $09, $10, $17, $1E, $25, $2C
+ db $03, $0A, $11, $18, $1F, $26, $2D
+ db $04, $0B, $12, $19, $20, $27, $2E
+ db $05, $0C, $13, $1A, $21, $28, $2F
+ db $06, $0D, $14, $1B, $22, $29, $30
+
+DownscaledMonTiles_5x7:
+ 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
+
+DownscaledMonTiles_3x7:
+ db $00, $07, $0E, $15, $1C, $23, $2A
+ db $02, $09, $10, $17, $1E, $25, $2C
+ db $04, $0B, $12, $19, $20, $27, $2E
+
+DownscaledMonTiles_79ce9:
+ db $00, $00, $00, $00, $00, $00, $00
+ db $00, $00, $00, $00, $00, $19, $00
+ db $02, $06, $0B, $10, $14, $1A, $00
+ db $00, $07, $0C, $11, $15, $1B, $00
+ db $03, $08, $0D, $12, $16, $1C, $00
+ db $04, $09, $0E, $13, $17, $1D, $1F
+ db $05, $0A, $0F, $01, $18, $1E, $20
+
+DownscaledMonTiles_79d1a:
+ db $00, $00, $00, $30, $00, $37, $00
+ db $00, $00, $2B, $31, $34, $38, $3D
+ db $21, $26, $2C, $01, $35, $39, $3E
+ db $22, $27, $2D, $32, $36, $01, $00
+ db $23, $28, $2E, $33, $01, $3A, $00
+ db $24, $29, $2F, $01, $01, $3B, $00
+ db $25, $2A, $01, $01, $01, $3C, $00
+
+DownscaledMonTiles_79d4b:
+ db $00, $00, $00, $00, $00, $00, $00
+ db $00, $00, $47, $4D, $00, $00, $00
+ db $00, $00, $48, $4E, $52, $56, $5B
+ db $3F, $43, $49, $4F, $53, $57, $5C
+ db $40, $44, $4A, $50, $54, $58, $00
+ db $41, $45, $4B, $51, $4C, $59, $5D
+ db $42, $46, $4C, $4C, $55, $5A, $5E
+
+DownscaledMonTiles_79d7c:
+ db $31, $32, $32, $32, $32, $33
+ db $34, $35, $36, $36, $37, $38
+ db $34, $39, $3A, $3A, $3B, $38
+ db $3C, $3D, $3E, $3E, $3F, $40
+ db $41, $42, $43, $43, $44, $45
+ db $46, $47, $43, $48, $49, $4A
+ db $41, $43, $4B, $4C, $4D, $4E
+ db $4F, $50, $50, $50, $51, $52
+
+DownscaledMonTiles_79dac:
+ 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:
; Makes leaves float down from the top of the screen. This is used
; in Razor Leaf's animation.
- ld a, [rOBP0]
- push af
ld a, [wAnimPalette]
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
ld d, $37 ; leaf tile
ld a, 3 ; number of leaves
ld [wNumFallingObjects], a
- call AnimationFallingObjects
- pop af
- ld [rOBP0], a
- ret
+ jp AnimationFallingObjects
AnimationPetalsFalling:
; Makes lots of petals fall down from the top of the screen. It's used in
@@ -2746,6 +2914,8 @@ FallingObjects_UpdateOAMEntry:
; movement byte.
ld hl, wOAMBuffer
add hl, de
+ ld a, $1
+ ld [wdef5], a
ld a, [hl]
inc a
inc a
@@ -2754,6 +2924,12 @@ FallingObjects_UpdateOAMEntry:
ld a, 160 ; if Y >= 112, put it off-screen
.next
ld [hli], a ; Y
+ cp 40
+ jr c, .asm_79e51
+ ld a, [wdef5]
+ inc a
+ ld [wdef5], a
+.asm_79e51
ld a, [wFallingObjectMovementByte]
ld b, a
ld de, FallingObjects_DeltaXs
@@ -2770,6 +2946,13 @@ FallingObjects_UpdateOAMEntry:
ld a, [de]
add [hl]
ld [hli], a ; X
+ cp 88
+ jr c, .asm_79e75
+ ld a, [wdef5]
+ add $2
+ and $3
+ ld [wdef5], a
+.asm_79e75
inc hl
xor a ; no horizontal flip
jr .next2
@@ -2779,9 +2962,19 @@ FallingObjects_UpdateOAMEntry:
ld a, [hl]
sub b
ld [hli], a ; X
+ cp 88
+ jr c, .asm_79e5c
+ ld a, [wdef5]
+ add $2
+ and $3
+ ld [wdef5], a
+.asm_79e5c
inc hl
ld a, (1 << OAM_X_FLIP)
.next2
+ ld b, a
+ ld a, [wdef5]
+ or b
ld [hl], a ; attribute
ret
@@ -2821,7 +3014,7 @@ FallingObjects_InitXCoords:
ret
FallingObjects_InitialXCoords:
- db $38,$40,$50,$60,$70,$88,$90,$56,$67,$4A,$77,$84,$98,$32,$22,$5C,$6C,$7D,$8E,$99
+ db $38, $40, $50, $60, $70, $88, $90, $56, $67, $4A, $77, $84, $98, $32, $22, $5C, $6C, $7D, $8E, $99
FallingObjects_InitMovementData:
ld hl, wFallingObjectsMovementData
@@ -2837,7 +3030,7 @@ FallingObjects_InitMovementData:
ret
FallingObjects_InitialMovementData:
- db $00,$84,$06,$81,$02,$88,$01,$83,$05,$89,$09,$80,$07,$87,$03,$82,$04,$85,$08,$86
+ db $00, $84, $06, $81, $02, $88, $01, $83, $05, $89, $09, $80, $07, $87, $03, $82, $04, $85, $08, $86
AnimationShakeEnemyHUD:
; Shakes the enemy HUD.
@@ -2866,6 +3059,14 @@ AnimationShakeEnemyHUD:
ld hl, vBGMap1 - $20 * 7
call BattleAnimCopyTileMapToVRAM
+; update BGMap attributes
+ ld a, [hGBC]
+ and a
+ jr z, .notGBC
+ ld c, 13
+ callba LoadBGMapAttributes
+.notGBC
+
; 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
@@ -2899,13 +3100,18 @@ AnimationShakeEnemyHUD:
ld [hWY], a
ld hl, vBGMap1
call BattleAnimCopyTileMapToVRAM
+; update BGMap attributes
+ ld a, [hGBC]
+ and a
+ jr z, .notGBC2
+ ld c, 11
+ callba LoadBGMapAttributes
+.notGBC2
xor a
ld [hWY], a
call SaveScreenTilesToBuffer1
ld hl, vBGMap0
call BattleAnimCopyTileMapToVRAM
- call ClearScreen
- call Delay3
call LoadScreenTilesFromBuffer1
ld hl, vBGMap1
jp BattleAnimCopyTileMapToVRAM
@@ -2950,60 +3156,60 @@ BattleAnimCopyTileMapToVRAM:
jp Delay3
TossBallAnimation:
- ld a,[wIsInBattle]
- cp a,2
- jr z,.BlockBall ; if in trainer battle, play different animation
- ld a,[wPokeBallAnimData]
- ld b,a
+ ld a, [wIsInBattle]
+ cp a, 2
+ jr z, .BlockBall ; if in trainer battle, play different animation
+ ld a, [wPokeBallAnimData]
+ ld b, a
; upper nybble: how many animations (from PokeBallAnimations) to play
; this will be 4 for successful capture, 6 for breakout
- and a,$F0
+ and a, $F0
swap a
- ld c,a
+ ld c, a
; lower nybble: number of shakes
; store these for later
- ld a,b
- and a,$F
- ld [wNumShakes],a
+ ld a, b
+ and a, $F
+ ld [wNumShakes], a
- ld hl,.PokeBallAnimations
+ ld hl, .PokeBallAnimations
; choose which toss animation to use
- ld a,[wcf91]
- cp a,POKE_BALL
- ld b,TOSS_ANIM
- jr z,.done
- cp a,GREAT_BALL
- ld b,GREATTOSS_ANIM
- jr z,.done
- ld b,ULTRATOSS_ANIM
+ ld a, [wcf91]
+ cp a, POKE_BALL
+ ld b, TOSS_ANIM
+ jr z, .done
+ cp a, GREAT_BALL
+ ld b, GREATTOSS_ANIM
+ jr z, .done
+ ld b, ULTRATOSS_ANIM
.done
- ld a,b
+ ld a, b
.PlayNextAnimation
- ld [wAnimationID],a
+ ld [wAnimationID], a
push bc
push hl
call PlayAnimation
pop hl
- ld a,[hli]
+ ld a, [hli]
pop bc
dec c
- jr nz,.PlayNextAnimation
+ jr nz, .PlayNextAnimation
ret
.PokeBallAnimations:
; sequence of animations that make up the Poké Ball toss
- db POOF_ANIM,HIDEPIC_ANIM,SHAKE_ANIM,POOF_ANIM,SHOWPIC_ANIM
+ db POOF_ANIM, HIDEPIC_ANIM, SHAKE_ANIM, POOF_ANIM, SHOWPIC_ANIM
-.BlockBall ; 5E55
- ld a,TOSS_ANIM
- ld [wAnimationID],a
+.BlockBall ; 79ff6 (1e:5ff6)
+ ld a, TOSS_ANIM
+ ld [wAnimationID], a
call PlayAnimation
- ld a,SFX_FAINT_THUD
+ ld a, SFX_FAINT_THUD
call PlaySound
- ld a,BLOCKBALL_ANIM
- ld [wAnimationID],a
+ ld a, BLOCKBALL_ANIM
+ ld [wAnimationID], a
jp PlayAnimation
PlayApplyingAttackSound:
diff --git a/engine/battle/bank3d_battle.asm b/engine/battle/bank3d_battle.asm
new file mode 100644
index 00000000..3719841f
--- /dev/null
+++ b/engine/battle/bank3d_battle.asm
@@ -0,0 +1,291 @@
+InitBattle:
+ ld a, [wCurOpponent]
+ and a
+ jr z, asm_f6003
+
+InitOpponent:
+ ld a, [wCurOpponent]
+ ld [wcf91], a
+ ld [wEnemyMonSpecies2], a
+ jr asm_f601d
+asm_f6003:
+ ld a, [wd732]
+ bit 1, a
+ jr z, .asm_f600f
+ ld a, [hJoyHeld]
+ bit 1, a ; B button pressed?
+ ret nz
+.asm_f600f
+ ld a, [wNumberOfNoRandomBattleStepsLeft]
+ and a
+ ret nz
+ callab TryDoWildEncounter
+ ret nz
+asm_f601d:
+ ld a, [wMapPalOffset]
+ push af
+ ld hl, wLetterPrintingDelayFlags
+ ld a, [hl]
+ push af
+ res 1, [hl]
+ call InitBattleVariables ; 3d:6236
+ ld a, [wEnemyMonSpecies2]
+ sub $c8
+ jp c, InitWildBattle
+ ld [wTrainerClass], a
+ call GetTrainerInformation
+ callab ReadTrainer
+ callab DoBattleTransitionAndInitBattleVariables
+ call _LoadTrainerPic ; 3d:615a
+ xor a
+ ld [wEnemyMonSpecies2], a
+ ld [$ffe1], a
+ dec a
+ ld [wAICount], a
+ coord hl, 12, 0
+ predef CopyUncompressedPicToTilemap
+ ld a, $ff
+ ld [wEnemyMonPartyPos], a
+ ld a, $2
+ ld [wIsInBattle], a
+
+ ; Is this a major story battle?
+ ld a,[wLoneAttackNo]
+ and a
+ jp z,InitBattle_Common
+ callabd_ModifyPikachuHappiness PIKAHAPPY_GYMLEADER ; useless since already in bank3d
+ jp InitBattle_Common
+
+InitWildBattle:
+ ld a, $1
+ ld [wIsInBattle], a
+ callab LoadEnemyMonData
+ callab DoBattleTransitionAndInitBattleVariables
+ ld a, [wCurOpponent]
+ cp MAROWAK
+ jr z, .isGhost
+ callab IsGhostBattle
+ jr nz, .isNoGhost
+.isGhost
+ ld hl, wMonHSpriteDim
+ ld a, $66
+ ld [hli], a ; write sprite dimensions
+ ld bc, GhostPic
+ ld a, c
+ ld [hli], a ; write front sprite pointer
+ ld [hl], b
+ ld hl, wEnemyMonNick ; set name to "GHOST"
+ ld a, "G"
+ ld [hli], a
+ ld a, "H"
+ ld [hli], a
+ ld a, "O"
+ ld [hli], a
+ ld a, "S"
+ ld [hli], a
+ ld a, "T"
+ ld [hli], a
+ ld [hl], "@"
+ ld a, [wcf91]
+ push af
+ ld a, MON_GHOST
+ ld [wcf91], a
+ ld de, vFrontPic
+ call LoadMonFrontSprite ; load ghost sprite
+ pop af
+ ld [wcf91], a
+ jr .spriteLoaded
+.isNoGhost
+ ld de, vFrontPic
+ call LoadMonFrontSprite ; load mon sprite
+.spriteLoaded
+ xor a
+ ld [wTrainerClass], a
+ ld [$ffe1], a
+ coord hl, 12, 0
+ predef CopyUncompressedPicToTilemap
+
+; common code that executes after init battle code specific to trainer or wild battles
+InitBattle_Common:
+ ld b, $0
+ call RunPaletteCommand
+ callab SlidePlayerAndEnemySilhouettesOnScreen
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld hl, .emptyString
+ call PrintText
+ call SaveScreenTilesToBuffer1
+ call ClearScreen
+ ld a, $98
+ ld [$ffbd], a
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Delay3
+ ld a, $9c
+ ld [$ffbd], a
+ call LoadScreenTilesFromBuffer1
+ coord hl, 9, 7
+ ld bc, $50a
+ call ClearScreenArea
+ coord hl, 1, 0
+ ld bc, $40a
+ call ClearScreenArea
+ call ClearSprites
+ ld a, [wIsInBattle]
+ dec a ; is it a wild battle?
+ ld hl, DrawEnemyHUDAndHPBar
+ ld b,BANK(DrawEnemyHUDAndHPBar)
+ call z, Bankswitch ; draw enemy HUD and HP bar if it's a wild battle
+ callab StartBattle
+ callab EndOfBattle
+ pop af
+ ld [wLetterPrintingDelayFlags], a
+ pop af
+ ld [wMapPalOffset], a
+ ld a, [wSavedTilesetType]
+ ld [hTilesetType], a
+ scf
+ ret
+.emptyString
+ db "@"
+
+_LoadTrainerPic:
+; wd033-wd034 contain pointer to pic
+ ld a, [wTrainerPicPointer] ; wd033
+ ld e, a
+ ld a, [wTrainerPicPointer + 1] ; wd034
+ ld d, a ; de contains pointer to trainer pic
+ ld a, [wLinkState]
+ and a
+ ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
+ jr z, .loadSprite
+ ld a, Bank(RedPicFront)
+.loadSprite
+ call UncompressSpriteFromDE
+ ld de, vFrontPic
+ ld a, $77
+ ld c, a
+ jp LoadUncompressedSpriteData
+
+LoadMonBackPic:
+; Assumes the monster's attributes have
+; been loaded with GetMonHeader.
+ ld a, [wBattleMonSpecies2]
+ ld [wcf91], a
+ coord hl, 1, 5
+ ld bc,$708
+ call ClearScreenArea
+ ld hl, wMonHBackSprite - wMonHeader
+ call UncompressMonSprite
+ predef ScaleSpriteByTwo
+ ld de, vBackPic
+ call InterlaceMergeSpriteBuffers ; combine the two buffers to a single 2bpp sprite
+ ld hl, vSprites
+ ld de, vBackPic
+ ld c, (2*SPRITEBUFFERSIZE)/16 ; count of 16-byte chunks to be copied
+ ld a, [H_LOADEDROMBANK]
+ ld b, a
+ jp CopyVideoData
+
+AnimateSendingOutMon:
+ ld a, [wPredefRegisters]
+ ld h, a
+ ld a, [wPredefRegisters + 1]
+ ld l, a
+ ld a, [$ffe1]
+ ld [H_DOWNARROWBLINKCNT1], a
+ ld b, $4c
+ ld a, [wIsInBattle]
+ and a
+ jr z, .asm_f61ef
+ add b
+ ld [hl], a
+ call Delay3
+ ld bc, -41
+ add hl, bc
+ ld a, $1
+ ld [wNumMovesMinusOne], a
+ ld bc, $303
+ predef CopyDownscaledMonTiles
+ ld c, $4
+ call DelayFrames
+ ld bc, -41
+ add hl, bc
+ xor a
+ ld [wNumMovesMinusOne], a
+ ld bc, $505
+ predef CopyDownscaledMonTiles
+ ld c, $5
+ call DelayFrames
+ ld bc, -41
+ jr .asm_f61f2
+.asm_f61ef
+ ld bc, -123
+.asm_f61f2
+ add hl, bc
+ ld a, [H_DOWNARROWBLINKCNT1]
+ add $31
+ jr CopyUncompressedPicToHL
+
+CopyUncompressedPicToTilemap:
+ ld a, [wPredefRegisters]
+ ld h, a
+ ld a, [wPredefRegisters + 1]
+ ld l, a
+ ld a, [$ffe1]
+CopyUncompressedPicToHL:
+ ld bc, $707
+ ld de, $14
+ push af
+ ld a, [wSpriteFlipped]
+ and a
+ jr nz, .asm_f6220
+ pop af
+.asm_f6211
+ push bc
+ push hl
+.asm_f6213
+ ld [hl], a
+ add hl, de
+ inc a
+ dec c
+ jr nz, .asm_f6213
+ pop hl
+ inc hl
+ pop bc
+ dec b
+ jr nz, .asm_f6211
+ ret
+
+.asm_f6220
+ push bc
+ ld b, $0
+ dec c
+ add hl, bc
+ pop bc
+ pop af
+.asm_f6227
+ push bc
+ push hl
+.asm_f6229
+ ld [hl], a
+ add hl, de
+ inc a
+ dec c
+ jr nz, .asm_f6229
+ pop hl
+ dec hl
+ pop bc
+ dec b
+ jr nz, .asm_f6227
+ ret
+
+INCLUDE "engine/battle/init_battle_variables.asm"
+INCLUDE "engine/battle/moveEffects/focus_energy_effect.asm"
+INCLUDE "engine/battle/moveEffects/heal_effect.asm"
+INCLUDE "engine/battle/moveEffects/transform_effect.asm"
+INCLUDE "engine/battle/moveEffects/reflect_light_screen_effect.asm"
+INCLUDE "engine/battle/moveEffects/mist_effect.asm"
+INCLUDE "engine/battle/moveEffects/one_hit_ko_effect.asm"
+INCLUDE "engine/battle/moveEffects/pay_day_effect.asm"
+INCLUDE "engine/battle/moveEffects/paralyze_effect.asm"
diff --git a/engine/battle/bank_e_misc.asm b/engine/battle/bank_e_misc.asm
index 33af6f6f..df9145f2 100755
--- a/engine/battle/bank_e_misc.asm
+++ b/engine/battle/bank_e_misc.asm
@@ -101,22 +101,3 @@ InitList:
ld a, b
ld [wItemPrices + 1], a
ret
-
-; get species of mon e in list [wMonDataLocation] for LoadMonData
-GetMonSpecies:
- ld hl, wPartySpecies
- ld a, [wMonDataLocation]
- and a
- jr z, .getSpecies
- dec a
- jr z, .enemyParty
- ld hl, wBoxSpecies
- jr .getSpecies
-.enemyParty
- ld hl, wEnemyPartyMons
-.getSpecies
- ld d, 0
- add hl, de
- ld a, [hl]
- ld [wcf91], a
- ret
diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm
index 9e02c56f..a4871837 100644
--- a/engine/battle/battle_transitions.asm
+++ b/engine/battle/battle_transitions.asm
@@ -1,5 +1,5 @@
BattleTransition:
- ld a, 1
+ ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
xor a
@@ -196,6 +196,9 @@ BattleTransition_BlackScreen:
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
ret
; for non-dungeon trainer battles
@@ -359,7 +362,8 @@ BattleTransition_FlashScreen_:
cp $1
jr z, .done
ld [rBGP], a
- ld c, 2
+ call UpdateGBCPal_BGP
+ ld c, $2
call DelayFrames
jr .loop
.done
@@ -373,7 +377,7 @@ BattleTransition_FlashScreenPalettes:
; used for low level trainer dungeon battles
BattleTransition_Shrink:
- ld c, SCREEN_HEIGHT / 2
+ ld c,9
.loop
push bc
xor a
@@ -407,7 +411,7 @@ BattleTransition_Shrink:
; used for high level trainer dungeon battles
BattleTransition_Split:
- ld c, SCREEN_HEIGHT / 2
+ ld c,$9
xor a
ld [H_AUTOBGTRANSFERENABLED], a
.loop
@@ -628,7 +632,7 @@ BattleTransition_Circle_Sub1:
ret
BattleTransition_TransferDelay3:
- ld a, 1
+ ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
xor a
diff --git a/engine/battle/common_text.asm b/engine/battle/common_text.asm
index 3d46c947..02bb1a61 100644
--- a/engine/battle/common_text.asm
+++ b/engine/battle/common_text.asm
@@ -1,5 +1,5 @@
PrintBeginningBattleText:
- ld a, [wIsInBattle]
+ ld a, [wIsInBattle] ; W_ISINBATTLE
dec a
jr nz, .trainerBattle
ld a, [wCurMap]
@@ -8,8 +8,20 @@ PrintBeginningBattleText:
cp LAVENDER_HOUSE_1
jr c, .pokemonTower
.notPokemonTower
+ ld a,[wBattleType]
+ cp BATTLE_TYPE_PIKACHU
+ jr nz,.notPikachuBattle
+ callab IsPlayerPikachuAsleepInParty
+ ld e,$24
+ jr c,.asm_f4026
+ ld e,$a
+.asm_f4026
+ callab PlayPikachuSoundClip
+ jr .continue
+.notPikachuBattle
ld a, [wEnemyMonSpecies2]
call PlayCry
+.continue
ld hl, WildMonAppearedText
ld a, [wMoveMissed]
and a
@@ -23,9 +35,13 @@ PrintBeginningBattleText:
call DelayFrames
ld hl, TrainerWantsToFightText
.wildBattle
+ ld a, [wBattleType]
+ and a
+ jr nz, .doNotDrawPokeballs
push hl
callab DrawAllPokeballs
pop hl
+.doNotDrawPokeballs
call PrintText
jr .done
.pokemonTower
@@ -64,7 +80,7 @@ PrintBeginningBattleText:
ld [wFrequencyModifier], a
ld a, $80
ld [wTempoModifier], a
- ld a, SFX_SILPH_SCOPE
+ ld a, $e9 ; (SFX_08_77 - SFX_Headers_08) / 3
call PlaySound
jp WaitForSoundToFinish
.done
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index f8053a9e..fa56e5b2 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -157,6 +157,9 @@ SlidePlayerAndEnemySilhouettesOnScreen:
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
.slideSilhouettesLoop ; slide silhouettes of the player's pic and the enemy's pic onto the screen
ld h, b
ld l, $40
@@ -246,10 +249,16 @@ StartBattle:
call DelayFrames
call SaveScreenTilesToBuffer1
.checkAnyPartyAlive
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_RUN
+ jp z, .specialBattle
+ cp BATTLE_TYPE_PIKACHU
+ jp z, .specialBattle
call AnyPartyAlive
ld a, d
and a
jp z, HandlePlayerBlackOut ; jump if no mon is alive
+.specialBattle
call LoadScreenTilesFromBuffer1
ld a, [wBattleType]
and a ; is it a normal battle?
@@ -443,7 +452,7 @@ MainInBattleLoop:
; the link battle enemy has switched mons
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
@@ -452,9 +461,9 @@ MainInBattleLoop:
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]
@@ -665,7 +674,7 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP:
and a
jr z, .playersTurn
ld hl, wEnemyBattleStatus3
- ld de, wEnemyToxcCounter
+ ld de, wEnemyToxicCounter
.playersTurn
bit BadlyPoisoned, [hl]
jr z, .noToxic
@@ -819,7 +828,7 @@ HandleEnemyMonFainted:
ld [wActionResultOrTookBattleTurn], a
jp MainInBattleLoop
-FaintEnemyPokemon: ; 0x3c567
+FaintEnemyPokemon:
call ReadPlayerMonCurHPAndStatus
ld a, [wIsInBattle]
dec a
@@ -884,6 +893,8 @@ 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]
@@ -945,7 +956,7 @@ FaintEnemyPokemon: ; 0x3c567
ld [wPartyGainExpFlags], a
jpab GainExperience
-EnemyMonFaintedText: ; 0x3c63e
+EnemyMonFaintedText:
TX_FAR _EnemyMonFaintedText
db "@"
@@ -981,6 +992,11 @@ ReplaceFaintedEnemyMon:
ld hl, wEnemyHPBarColor
ld e, $30
call GetBattleHealthBarColor
+ setpal SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
callab DrawEnemyPokeballs
ld a, [wLinkState]
cp LINK_STATE_BATTLING
@@ -1046,9 +1062,7 @@ TrainerDefeatedText:
PlayBattleVictoryMusic:
push af
- ld a, $ff
- ld [wNewSoundID], a
- call PlaySoundWaitForCurrent
+ call StopAllMusic
ld c, BANK(Music_DefeatedTrainer)
pop af
call PlayMusic
@@ -1102,6 +1116,7 @@ RemoveFaintedPlayerMon:
ld a, $ff
ld [wLowHealthAlarm], a ;disable low health alarm
call WaitForSoundToFinish
+ xor a
.skipWaitForSound
; a is 0, so this zeroes the enemy's accumulated damage.
ld hl, wEnemyBideAccumulatedDamage
@@ -1126,10 +1141,36 @@ RemoveFaintedPlayerMon:
and a ; was this called by HandleEnemyMonFainted?
ret z ; if so, return
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .notPlayerPikachu
+ ld e, $3
+ callab PlayPikachuSoundClip
+ jr .printText
+.notPlayerPikachu
ld a, [wBattleMonSpecies]
call PlayCry
+.printText
ld hl, PlayerMonFaintedText
- jp PrintText
+ call PrintText
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ ld a, [wBattleMonLevel]
+ ld b, a
+ ld a, [wEnemyMonLevel]
+ sub b ; enemylevel - playerlevel
+ ; are we stronger than the opposing pokemon?
+ jr c, .regularFaint ; if so, deduct happiness regularly
+
+ cp 30 ; is the enemy 30 levels greater than us?
+ jr nc, .carelessTrainer ; if so, punish the player for being careless, as they shouldn't be fighting a very high leveled trainer with such a level difference
+.regularFaint
+ callabd_ModifyPikachuHappiness PIKAHAPPY_FAINTED
+ ret
+.carelessTrainer
+ callabd_ModifyPikachuHappiness PIKAHAPPY_CARELESSTRAINER
+ ret
PlayerMonFaintedText:
TX_FAR _PlayerMonFaintedText
@@ -1186,7 +1227,7 @@ ChooseNextMon:
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
- inc a
+ ld a, $1
ld [wActionResultOrTookBattleTurn], a
call LinkBattleExchangeData
.notLinkBattle
@@ -1285,7 +1326,7 @@ SlideDownFaintedMonPic:
call CopyData
pop de
pop hl
- ld bc, -20
+ ld bc, -SCREEN_WIDTH
add hl, bc
push hl
ld h, d
@@ -1297,7 +1338,7 @@ SlideDownFaintedMonPic:
pop bc
dec b
jr nz, .rowLoop
- ld bc, 20
+ ld bc, SCREEN_WIDTH
add hl, bc
ld de, SevenSpacesText
call PlaceString
@@ -1586,6 +1627,8 @@ TryRunningFromBattle:
ld a, [wBattleType]
cp BATTLE_TYPE_SAFARI
jp z, .canEscape ; jump if it's a safari battle
+ cp BATTLE_TYPE_RUN
+ jp z, .canEscape ; hurry, get away?
ld a, [wLinkState]
cp LINK_STATE_BATTLING
jp z, .canEscape
@@ -1841,19 +1884,46 @@ SendOutMon:
call RunPaletteCommand
ld hl, wEnemyBattleStatus1
res UsingTrappingMove, [hl]
+ callab IsThisPartymonStarterPikachu
+ jr c, .starterPikachu
ld a, $1
ld [H_WHOSETURN], a
ld a, POOF_ANIM
call PlayMoveAnimation
coord hl, 4, 11
predef AnimateSendingOutMon
+ jr .playRegularCry
+.starterPikachu
+ xor a
+ ld [H_WHOSETURN], a
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ callab StarterPikachuBattleEntranceAnimation
+ callab IsPlayerPikachuAsleepInParty
+ ld e, $24
+ jr c, .asm_3cd81
+ ld e, $a
+.asm_3cd81
+ callab PlayPikachuSoundClip
+ jr .done
+.playRegularCry
ld a, [wcf91]
call PlayCry
+.done
call PrintEmptyString
jp SaveScreenTilesToBuffer1
; show 2 stages of the player mon getting smaller before disappearing
AnimateRetreatingPlayerMon:
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callab IsThisPartymonStarterPikachu
+ pop bc
+ ld a, b
+ ld [wWhichPokemon], a
+ jr c, .starterPikachu
coord hl, 1, 5
lb bc, 7, 7
call ClearScreenArea
@@ -1877,10 +1947,17 @@ AnimateRetreatingPlayerMon:
call .clearScreenArea
ld a, $4c
Coorda 5, 11
+ jr .clearScreenArea
+.starterPikachu
+ xor a
+ ld [H_WHOSETURN], a
+ callab AnimationSlideMonOff
+ ret
.clearScreenArea
coord hl, 1, 5
lb bc, 7, 7
- jp ClearScreenArea
+ call ClearScreenArea ; jp
+ ret
; reads player's current mon's HP into wBattleMonHP
ReadPlayerMonCurHPAndStatus:
@@ -1925,9 +2002,9 @@ DrawPlayerHUDAndHPBar:
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
coord hl, 10, 9
@@ -1939,14 +2016,14 @@ DrawPlayerHUDAndHPBar:
ld hl, wBattleMonHP
ld a, [hli]
or [hl]
- jr z, .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, .asm_3cde6
-.asm_3cdd9
+ jr z, .setLowHealthAlarm
+.fainted
ld hl, wLowHealthAlarm
bit 7, [hl] ;low health alarm enabled?
ld [hl], $0
@@ -1954,7 +2031,7 @@ DrawPlayerHUDAndHPBar:
xor a
ld [wChannelSoundIDs + CH4], a
ret
-.asm_3cde6
+.setLowHealthAlarm
ld hl, wLowHealthAlarm
set 7, [hl] ;enable low health alarm
ret
@@ -2102,36 +2179,49 @@ DisplayBattleMenu:
ld [wTextBoxID], a
call DisplayTextBoxID
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
+ cp BATTLE_TYPE_OLD_MAN
+ jr z, .doSimulatedMenuInput ; simulate menu input if it's the old man or prof. oak pikachu battle
+ cp BATTLE_TYPE_PIKACHU
+ jr z, .doSimulatedMenuInput
+ jp .handleBattleMenuInput
+; the following happens for the old man tutorial and prof. oak pikachu battle
+.doSimulatedMenuInput
ld hl, wPlayerName
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
+ ; map with wild Pokémon.
+ ; In Red/Blue, due to an oversight, the data
; may not get overwritten (cinnabar) and the infamous
- ; Missingno. glitch can show up.
+ ; Missingno. glitch can show up. However,
+ ; this has been fixed in yellow
ld hl, .oldManName
+ ld a, [wBattleType]
+ dec a
+ jr z, .useOldManName
+ ld hl, .profOakName
+.useOldManName
ld de, wPlayerName
ld bc, NAME_LENGTH
call CopyData
; the following simulates the keystrokes by drawing menus on screen
coord hl, 9, 14
ld [hl], "▶"
- ld c, 80
+ ld c, 20
call DelayFrames
ld [hl], " "
coord hl, 9, 16
ld [hl], "▶"
- ld c, 50
+ ld c, 20
call DelayFrames
ld [hl], $ec
ld a, $2 ; select the "ITEM" menu
jp .upperLeftMenuItemWasNotSelected
.oldManName
db "OLD MAN@"
+.profOakName
+ db "PROF.OAK@"
.handleBattleMenuInput
ld a, [wBattleAndStartSavedMenuItem]
ld [wCurrentMenuItem], a
@@ -2214,6 +2304,9 @@ DisplayBattleMenu:
.AButtonPressed
call PlaceUnfilledArrowMenuCursor
ld a, [wBattleType]
+ cp BATTLE_TYPE_RUN
+ jr z, .handleUnusedBattle
+ ld a, [wBattleType]
cp BATTLE_TYPE_SAFARI
ld a, [wCurrentMenuItem]
ld [wBattleAndStartSavedMenuItem], a
@@ -2245,7 +2338,18 @@ DisplayBattleMenu:
.throwSafariBallWasSelected
ld a, SAFARI_BALL
ld [wcf91], a
- jr UseBagItem
+ jp UseBagItem
+.handleUnusedBattle
+ ld a, [wCurrentMenuItem]
+ cp $3
+ jp z, BattleMenu_RunWasSelected
+ ld hl, .RunAwayText
+ call PrintText
+ jp DisplayBattleMenu
+
+.RunAwayText ; 3d0df (f:50df)
+ TX_FAR _RunAwayText
+ db "@"
.upperLeftMenuItemWasNotSelected ; a menu item other than the upper left item was selected
cp $2
@@ -2282,19 +2386,23 @@ BagWasSelected:
call DrawHUDsAndHPBars
.next
ld a, [wBattleType]
- dec a ; is it the old man tutorial?
- jr nz, DisplayPlayerBag ; no, it is a normal battle
- ld hl, OldManItemList
+ cp BATTLE_TYPE_OLD_MAN ; is it the old man tutorial?
+ jr z, .simulatedInputBattle
+ cp BATTLE_TYPE_PIKACHU ; is it the prof oak battle with pikachu?
+ jr z, .simulatedInputBattle
+ jr DisplayPlayerBag
+.simulatedInputBattle
+ ld hl, SimulatedInputBattleItemList
ld a, l
ld [wListPointer], a
ld a, h
ld [wListPointer + 1], a
jr DisplayBagMenu
-OldManItemList:
- db 1 ; # items
- db POKE_BALL, 50
- db -1
+SimulatedInputBattleItemList:
+ db 1 ; # of items
+ db POKE_BALL, 1
+ db $ff
DisplayPlayerBag:
; get the pointer to player's bag when in a normal battle
@@ -2453,6 +2561,8 @@ PartyMenuOrRockOrRun:
predef StatusScreen
predef StatusScreen2
; now we need to reload the enemy mon pic
+ ld a, $1
+ ld [H_WHOSETURN], a
ld a, [wEnemyBattleStatus2]
bit HasSubstituteUp, a ; does the enemy mon have a substitute?
ld hl, AnimationSubstitute
@@ -2557,13 +2667,13 @@ MoveSelectionMenu:
.writemoves
ld de, wMovesString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
set 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
call PlaceString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
res 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
ret
.regularmenu
@@ -2572,9 +2682,9 @@ MoveSelectionMenu:
ld hl, wBattleMonMoves
call .loadmoves
coord hl, 4, 12
- ld b, $4
- ld c, $e
- di
+ lb bc, 4, 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
coord hl, 4, 12
ld [hl], $7a
@@ -2590,8 +2700,7 @@ MoveSelectionMenu:
ld hl, wEnemyMonMoves
call .loadmoves
coord hl, 0, 7
- ld b, $4
- ld c, $e
+ lb bc, 4, 14
call TextBoxBorder
coord hl, 2, 8
call .writemoves
@@ -2605,8 +2714,7 @@ MoveSelectionMenu:
call AddNTimes
call .loadmoves
coord hl, 4, 7
- ld b, $4
- ld c, $e
+ lb bc, 4, 14
call TextBoxBorder
coord hl, 6, 8
call .writemoves
@@ -2620,8 +2728,6 @@ MoveSelectionMenu:
ld a, [wMoveMenuType]
cp $1
jr z, .selectedmoveknown
- ld a, $1
- jr nc, .selectedmoveknown
ld a, [wPlayerMoveListIndex]
inc a
.selectedmoveknown
@@ -2682,15 +2788,15 @@ SelectMenuItem:
call AddNTimes
ld [hl], $ec
.select
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
bit 6, a
- jp nz, CursorUp ; up
+ 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?
@@ -2703,10 +2809,10 @@ SelectMenuItem:
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
@@ -2723,7 +2829,7 @@ SelectMenuItem:
add hl, bc
ld a, [hl]
and $3f
- jr z, .nopp
+ jr z, .noPP
ld a, [wPlayerDisabledMove]
swap a
and $f
@@ -2746,7 +2852,7 @@ SelectMenuItem:
.disabled
ld hl, MoveDisabledText
jr .print
-.nopp
+.noPP
ld hl, MoveNoPPText
.print
call PrintText
@@ -2764,7 +2870,7 @@ MoveDisabledText:
WhichTechniqueString:
db "WHICH TECHNIQUE?@"
-CursorUp:
+SelectMenuItem_CursorUp:
ld a, [wCurrentMenuItem]
and a
jp nz, SelectMenuItem
@@ -2774,7 +2880,7 @@ CursorUp:
ld [wCurrentMenuItem], a
jp SelectMenuItem
-CursorDown:
+SelectMenuItem_CursorDown:
ld a, [wCurrentMenuItem]
ld b, a
ld a, [wNumMovesMinusOne]
@@ -2787,6 +2893,55 @@ CursorDown:
ld [wCurrentMenuItem], a
jp SelectMenuItem
+Func_3d4f5:
+ bit 3, a
+ ld a, $0
+ jr nz, .asm_3d4fd
+ ld a, $1
+.asm_3d4fd
+ ld [H_WHOSETURN], a
+ call LoadScreenTilesFromBuffer1
+ call Func_3d536
+ ld a, [wTestBattlePlayerSelectedMove]
+ and a
+ jp z, MoveSelectionMenu
+ ld [wAnimationID], a
+ xor a
+ ld [wAnimationType], a
+ predef MoveAnimation
+ callab Func_78e98
+ jp MoveSelectionMenu
+
+Func_3d523:
+ ld a, [wTestBattlePlayerSelectedMove]
+ dec a
+ jr asm_3d52d
+Func_3d529:
+ ld a, [wTestBattlePlayerSelectedMove]
+ inc a
+asm_3d52d:
+ ld [wTestBattlePlayerSelectedMove], a
+ call Func_3d536
+ jp MoveSelectionMenu
+
+Func_3d536:
+ coord hl, 10, 16
+ lb bc, 2, 10
+ call ClearScreenArea
+ coord hl, 10, 17
+ ld de, wTestBattlePlayerSelectedMove
+ lb bc, LEADING_ZEROES | 1, 3
+ call PrintNumber
+ ld a, [wTestBattlePlayerSelectedMove]
+ and a
+ ret z
+ cp STRUGGLE
+ ret nc
+ ld [wd11e], a
+ call GetMoveName
+ coord hl, 13, 17
+ jp PlaceString
+
AnyMoveToSelect:
; return z and Struggle as the selected move if all moves have 0 PP and/or are disabled
ld a, STRUGGLE
@@ -2794,7 +2949,7 @@ AnyMoveToSelect:
ld a, [wPlayerDisabledMove]
and a
ld hl, wBattleMonPP
- jr nz, .asm_3d40e
+ jr nz, .handleDisabledMove
ld a, [hli]
or [hl]
inc hl
@@ -2803,26 +2958,29 @@ AnyMoveToSelect:
or [hl]
and $3f
ret nz
- jr .asm_3d423
-.asm_3d40e
+ jr .noMovesLeft
+.handleDisabledMove
swap a
- and $f
+ and $f ; get move disabled
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
+; bugfix: only check PP value and not PP up bits
+; in case all other moves have no PP left and a move has a PP up used on it
+; and a non-PP up move is disabled
+ and $3f ; any PP left?
+ ret nz ; return if a move has PP left
+.noMovesLeft
ld hl, NoMovesLeftText
call PrintText
ld c, 60
@@ -2835,6 +2993,9 @@ NoMovesLeftText:
db "@"
SwapMovesInMenu:
+ ld a, [wPlayerBattleStatus3]
+ bit Transformed, a
+ jp nz, MoveSelectionMenu
ld a, [wMenuItemToSwap]
and a
jr z, .noMenuItemSelected
@@ -2914,8 +3075,7 @@ PrintMenuItem:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 0, 8
- ld b, $3
- ld c, $9
+ lb bc, 3, 9
call TextBoxBorder
ld a, [wPlayerDisabledMove]
and a
@@ -2982,7 +3142,7 @@ PrintMenuItem:
jp Delay3
DisabledText:
- db "disabled!@"
+ db "Disabled!@"
TypeText:
db "TYPE@"
@@ -2997,7 +3157,7 @@ SelectEnemyMove:
call LoadScreenTilesFromBuffer1
ld a, [wSerialExchangeNybbleReceiveData]
cp $e
- jp z, .asm_3d601
+ jp z, .linkedOpponentUsedStruggle
cp $d
jr z, .unableToSelectMove
cp $4
@@ -3075,7 +3235,7 @@ SelectEnemyMove:
.done
ld [wEnemySelectedMove], a
ret
-.asm_3d601
+.linkedOpponentUsedStruggle
ld a, STRUGGLE
jr .done
@@ -3205,7 +3365,7 @@ PlayerCalcMoveDamage:
call RandomizeDamage
.moveHitTest
call MoveHitTest
-handleIfPlayerMoveMissed
+handleIfPlayerMoveMissed:
ld a,[wMoveMissed]
and a
jr z,getPlayerAnimationType
@@ -3213,13 +3373,13 @@ handleIfPlayerMoveMissed
sub a,EXPLODE_EFFECT
jr z,playPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT
jr playerCheckIfFlyOrChargeEffect
-getPlayerAnimationType
+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 ; 3d890 (f:5890)
push af
ld a,[wPlayerBattleStatus2]
bit HasSubstituteUp,a
@@ -3238,7 +3398,7 @@ playPlayerMoveAnimation
ld b,BANK(ReshowSubstituteAnim)
call nz,Bankswitch
jr MirrorMoveCheck
-playerCheckIfFlyOrChargeEffect
+playerCheckIfFlyOrChargeEffect ; 3d8bd (f:58bd)
ld c,30
call DelayFrames
ld a,[wPlayerMoveEffect]
@@ -3252,7 +3412,7 @@ playerCheckIfFlyOrChargeEffect
ld [wAnimationType],a
ld a,STATUS_AFFECTED_ANIM
call PlayMoveAnimation
-MirrorMoveCheck
+MirrorMoveCheck:
ld a,[wPlayerMoveEffect]
cp a,MIRROR_MOVE_EFFECT
jr nz,.metronomeCheck
@@ -3785,10 +3945,10 @@ MonName1Text:
and a
ld a, [wPlayerMoveNum]
ld hl, wPlayerUsedMove
- jr z, .asm_3db11
+ jr z, .playerTurn
ld a, [wEnemyMoveNum]
ld hl, wEnemyUsedMove
-.asm_3db11
+.playerTurn
ld [hl], a
ld [wd11e], a
call DetermineExclamationPointTextNum
@@ -3902,11 +4062,13 @@ DetermineExclamationPointTextNum:
ret
ExclamationPointMoveSets:
+; a grammar mistake was fixed (only concerning japanese)
+; BIDE is in category 3, moved from category 2
db SWORDS_DANCE, GROWTH
db $00
- db RECOVER, BIDE, SELFDESTRUCT, AMNESIA
+ db RECOVER, SELFDESTRUCT, AMNESIA
db $00
- db MEDITATE, AGILITY, TELEPORT, MIMIC, DOUBLE_TEAM, BARRAGE
+ db MEDITATE, AGILITY, TELEPORT, MIMIC, DOUBLE_TEAM, BIDE, BARRAGE
db $00
db POUND, SCRATCH, VICEGRIP, WING_ATTACK, FLY, BIND, SLAM, HORN_ATTACK, BODY_SLAM
db WRAP, THRASH, TAIL_WHIP, LEER, BITE, GROWL, ROAR, SING, PECK, COUNTER
@@ -3943,7 +4105,7 @@ PrintMoveFailureText:
ret nz
; if you get here, the mon used jump kick or hi jump kick and missed
- ld hl, wDamage ; since the move missed, wDamage will always contain 0 at this point.
+ ld hl, wDamage ; since the move missed, W_DAMAGE 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]
@@ -4590,31 +4752,31 @@ CalculateDamage:
ld a, [H_QUOTIENT + 3]
add b
ld [H_QUOTIENT + 3], a
- jr nc, .asm_3dfd0
+ jr nc, .asm_3e142
ld a, [H_QUOTIENT + 2]
inc a
ld [H_QUOTIENT + 2], a
and a
- jr z, .asm_3e004
+ jr z, .asm_3e176
-.asm_3dfd0
+.asm_3e142
ld a, [H_QUOTIENT]
ld b, a
ld a, [H_QUOTIENT + 1]
or a
- jr nz, .asm_3e004
+ jr nz, .asm_3e176
ld a, [H_QUOTIENT + 2]
cp 998 / $100
- jr c, .asm_3dfe8
+ jr c, .asm_3e15a
cp 998 / $100 + 1
- jr nc, .asm_3e004
+ jr nc, .asm_3e176
ld a, [H_QUOTIENT + 3]
cp 998 % $100
- jr nc, .asm_3e004
+ jr nc, .asm_3e176
-.asm_3dfe8
+.asm_3e15a
inc hl
ld a, [H_QUOTIENT + 3]
ld b, [hl]
@@ -4625,26 +4787,26 @@ CalculateDamage:
ld b, [hl]
adc b
ld [hl], a
- jr c, .asm_3e004
+ jr c, .asm_3e176
ld a, [hl]
cp 998 / $100
- jr c, .asm_3e00a
+ jr c, .asm_3e17c
cp 998 / $100 + 1
- jr nc, .asm_3e004
+ jr nc, .asm_3e176
inc hl
ld a, [hld]
cp 998 % $100
- jr c, .asm_3e00a
+ jr c, .asm_3e17c
-.asm_3e004
+.asm_3e176
; cap at 997
ld a, 997 / $100
ld [hli], a
ld a, 997 % $100
ld [hld], a
-.asm_3e00a
+.asm_3e17c
; add 2
inc hl
ld a, [hl]
@@ -4675,7 +4837,7 @@ UnusedHighCriticalMoves:
; 3e023
; determines if attack is a critical hit
-; azure heights claims "the fastest pokémon (who are,not coincidentally,
+; 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:
xor a
@@ -4683,9 +4845,9 @@ CriticalHitTest:
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, [wMonHBaseSpeed]
@@ -5052,7 +5214,7 @@ ApplyDamageToPlayerPokemon:
ld a,$01
ld [wHPBarType],a
predef UpdateHPBar2 ; animate the HP bar shortening
-ApplyAttackToPlayerPokemonDone
+ApplyAttackToPlayerPokemonDone:
jp DrawHUDsAndHPBars
AttackSubstitute:
@@ -5096,7 +5258,7 @@ AttackSubstitute:
ld a,[H_WHOSETURN]
xor a,$01
ld [H_WHOSETURN],a
- callab HideSubstituteShowMonAnim ; animate the substitute breaking
+ callab Func_79929 ; animate the substitute breaking
; flip the turn back to the way it was
ld a,[H_WHOSETURN]
xor a,$01
@@ -5393,32 +5555,26 @@ AdjustDamageForMoveType:
.done
ret
-; 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 [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:
ld a,[wEnemyMoveType]
- ld d,a ; d = type of enemy move
+ 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 [wTypeEffectiveness],a ; initialize to neutral effectiveness
+ ld [wd11e],a ; initialize [wd11e] 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
@@ -5426,9 +5582,21 @@ AIGetTypeEffectiveness:
.nextTypePair2
inc hl
jr .loop
+
.done
+ ld a, [wTrainerClass]
+ cp LORELEI
+ jr nz, .ok
+ ld a, [wEnemyMonSpecies]
+ cp DEWGONG
+ jr nz, .ok
+ call BattleRandom
+ cp $66 ; 40 percent
+ ret c
+.ok
+
ld a,[hl]
- ld [wTypeEffectiveness],a ; store damage multiplier
+ ld [wd11e],a ; store damage multiplier
ret
INCLUDE "data/type_effects.asm"
@@ -5752,12 +5920,12 @@ EnemyMoveHitTest:
handleIfEnemyMoveMissed:
ld a, [wMoveMissed]
and a
- jr z, .asm_3e791
+ jr z, .moveDidNotMiss
ld a, [wEnemyMoveEffect]
cp EXPLODE_EFFECT
- jr z, asm_3e7a0
+ jr z, handleExplosionMiss
jr EnemyCheckIfFlyOrChargeEffect
-.asm_3e791
+.moveDidNotMiss
call SwapPlayerAndEnemyLevels
GetEnemyAnimationType:
@@ -5767,7 +5935,7 @@ GetEnemyAnimationType:
jr z, playEnemyMoveAnimation
ld a, $2
jr playEnemyMoveAnimation
-asm_3e7a0:
+handleExplosionMiss:
call SwapPlayerAndEnemyLevels
xor a
playEnemyMoveAnimation:
@@ -5825,19 +5993,19 @@ EnemyCheckIfMirrorMoveEffect:
jp c, JumpMoveEffect
ld a, [wMoveMissed]
and a
- jr z, .asm_3e82b
+ jr z, .moveDidNotMiss
call PrintMoveFailureText
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
+.handleExplosionMiss
ld a, [wEnemyMoveEffect]
ld hl, AlwaysHappenSideEffects
ld de, $1
@@ -5851,7 +6019,7 @@ EnemyCheckIfMirrorMoveEffect:
call HandleBuildingRage
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]
@@ -5862,7 +6030,7 @@ EnemyCheckIfMirrorMoveEffect:
call PrintText
xor a
ld [wEnemyNumHits], a
-.asm_3e873
+.notMultiHitMove
ld a, [wEnemyMoveEffect]
and a
jr z, ExecuteEnemyMoveDone
@@ -6407,10 +6575,13 @@ SwapPlayerAndEnemyLevels:
; (for use when scrolling the player sprite and enemy's silhouettes on screen)
LoadPlayerBackPic:
ld a, [wBattleType]
- dec a ; is it the old man tutorial?
- ld de, RedPicBack
- jr nz, .next
ld de, OldManPic
+ cp BATTLE_TYPE_OLD_MAN ; is it the old man tutorial?
+ jr z, .next
+ ld de, ProfOakPicBack
+ cp BATTLE_TYPE_PIKACHU ; is it the pikachu battle at the beginning of the game?
+ jr z, .next
+ ld de, RedPicBack
.next
ld a, BANK(RedPicBack)
call UncompressSpriteFromDE
@@ -6435,6 +6606,8 @@ LoadPlayerBackPic:
ld [hli], a ; OAM tile number
inc a ; increment tile number
ld [hOAMTile], a
+ ld a, $2
+ ld [hl], a
inc hl
dec c
jr nz, .innerLoop
@@ -6448,18 +6621,15 @@ LoadPlayerBackPic:
jr nz, .loop
ld de, vBackPic
call InterlaceMergeSpriteBuffers
- ld a, $a
- ld [$0], a
- xor a
- ld [$4000], a
+ ld a, $0
+ call SwitchSRAMBankAndLatchClockData
ld hl, vSprites
ld de, sSpriteBuffer1
ld a, [H_LOADEDROMBANK]
ld b, a
ld c, 7 * 7
call CopyVideoData
- xor a
- ld [$0], a
+ call PrepareRTCDataAndDisableSRAM
ld a, $31
ld [hStartTileID], a
coord hl, 1, 5
@@ -6802,16 +6972,16 @@ HandleExplodingAnimation:
ld hl, wEnemyMonType1
ld de, wEnemyBattleStatus1
ld a, [wPlayerMoveNum]
- jr z, .asm_3eeea
+ jr z, .player
ld hl, wBattleMonType1
ld de, wEnemyBattleStatus1
ld a, [wEnemyMoveNum]
-.asm_3eeea
+.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
@@ -6830,292 +7000,10 @@ HandleExplodingAnimation:
PlayMoveAnimation:
ld [wAnimationID],a
call Delay3
- predef_jump MoveAnimation
-
-InitBattle:
- ld a, [wCurOpponent]
- and a
- jr z, DetermineWildOpponent
-
-InitOpponent:
- ld a, [wCurOpponent]
- ld [wcf91], a
- ld [wEnemyMonSpecies2], a
- jr InitBattleCommon
-
-DetermineWildOpponent:
- ld a, [wd732]
- bit 1, a
- jr z, .asm_3ef2f
- ld a, [hJoyHeld]
- bit 1, a ; B button pressed?
- ret nz
-.asm_3ef2f
- ld a, [wNumberOfNoRandomBattleStepsLeft]
- and a
- ret nz
- callab TryDoWildEncounter
- ret nz
-InitBattleCommon:
- ld a, [wMapPalOffset]
- push af
- ld hl, wLetterPrintingDelayFlags
- ld a, [hl]
- push af
- res 1, [hl]
- callab InitBattleVariables
- ld a, [wEnemyMonSpecies2]
- sub 200
- jp c, InitWildBattle
- ld [wTrainerClass], a
- call GetTrainerInformation
- callab ReadTrainer
- call DoBattleTransitionAndInitBattleVariables
- call _LoadTrainerPic
- xor a
- ld [wEnemyMonSpecies2], a
- ld [hStartTileID], a
- dec a
- ld [wAICount], a
- coord hl, 12, 0
- predef CopyUncompressedPicToTilemap
- ld a, $ff
- ld [wEnemyMonPartyPos], a
- ld a, $2
- ld [wIsInBattle], a
- jp _InitBattleCommon
-
-InitWildBattle:
- ld a, $1
- ld [wIsInBattle], a
- call LoadEnemyMonData
- call DoBattleTransitionAndInitBattleVariables
- ld a, [wCurOpponent]
- cp MAROWAK
- jr z, .isGhost
- call IsGhostBattle
- jr nz, .isNoGhost
-.isGhost
- ld hl, wMonHSpriteDim
- ld a, $66
- ld [hli], a ; write sprite dimensions
- ld bc, GhostPic
- ld a, c
- ld [hli], a ; write front sprite pointer
- ld [hl], b
- ld hl, wEnemyMonNick ; set name to "GHOST"
- ld a, "G"
- ld [hli], a
- ld a, "H"
- ld [hli], a
- ld a, "O"
- ld [hli], a
- ld a, "S"
- ld [hli], a
- ld a, "T"
- ld [hli], a
- ld [hl], "@"
- ld a, [wcf91]
- push af
- ld a, MON_GHOST
- ld [wcf91], a
- ld de, vFrontPic
- call LoadMonFrontSprite ; load ghost sprite
- pop af
- ld [wcf91], a
- jr .spriteLoaded
-.isNoGhost
- ld de, vFrontPic
- call LoadMonFrontSprite ; load mon sprite
-.spriteLoaded
- xor a
- 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
-_InitBattleCommon:
- ld b, SET_PAL_BATTLE_BLACK
- call RunPaletteCommand
- call SlidePlayerAndEnemySilhouettesOnScreen
- xor a
- ld [H_AUTOBGTRANSFERENABLED], a
- ld hl, .emptyString
- call PrintText
- call SaveScreenTilesToBuffer1
- call ClearScreen
- ld a, $98
- ld [H_AUTOBGTRANSFERDEST + 1], a
- ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a
- call Delay3
- ld a, $9c
- ld [H_AUTOBGTRANSFERDEST + 1], a
- call LoadScreenTilesFromBuffer1
- coord hl, 9, 7
- lb bc, 5, 10
- call ClearScreenArea
- coord hl, 1, 0
- lb bc, 4, 10
- call ClearScreenArea
- call ClearSprites
- 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 [wLetterPrintingDelayFlags], a
- pop af
- ld [wMapPalOffset], a
- ld a, [wSavedTilesetType]
- ld [hTilesetType], a
- scf
- ret
-.emptyString
- db "@"
-
-_LoadTrainerPic:
-; wd033-wd034 contain pointer to pic
- ld a, [wTrainerPicPointer]
- ld e, a
- ld a, [wTrainerPicPointer + 1]
- ld d, a ; de contains pointer to trainer pic
- ld a, [wLinkState]
- and a
- ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
- jr z, .loadSprite
- ld a, Bank(RedPicFront)
-.loadSprite
- call UncompressSpriteFromDE
- ld de, vFrontPic
- ld a, $77
- ld c, a
- jp LoadUncompressedSpriteData
-
-; unreferenced
-ResetCryModifiers:
- xor a
- ld [wFrequencyModifier], a
- ld [wTempoModifier], a
- jp PlaySound
-
-; animates the mon "growing" out of the pokeball
-AnimateSendingOutMon:
- ld a, [wPredefRegisters]
- ld h, a
- ld a, [wPredefRegisters + 1]
- ld l, a
- ld a, [hStartTileID]
- ld [hBaseTileID], a
- ld b, $4c
- ld a, [wIsInBattle]
- and a
- jr z, .notInBattle
- add b
- ld [hl], a
- call Delay3
- ld bc, -(SCREEN_WIDTH * 2 + 1)
- add hl, bc
- ld a, 1
- ld [wDownscaledMonSize], a
- lb bc, 3, 3
- predef CopyDownscaledMonTiles
- ld c, 4
- call DelayFrames
- ld bc, -(SCREEN_WIDTH * 2 + 1)
- add hl, bc
- xor a
- ld [wDownscaledMonSize], a
- lb bc, 5, 5
- predef CopyDownscaledMonTiles
- ld c, 5
- call DelayFrames
- ld bc, -(SCREEN_WIDTH * 2 + 1)
- jr .next
-.notInBattle
- ld bc, -(SCREEN_WIDTH * 6 + 3)
-.next
- add hl, bc
- ld a, [hBaseTileID]
- add $31
- jr CopyUncompressedPicToHL
-
-CopyUncompressedPicToTilemap:
- ld a, [wPredefRegisters]
- ld h, a
- ld a, [wPredefRegisters + 1]
- ld l, a
- ld a, [hStartTileID]
-CopyUncompressedPicToHL:
- lb bc, 7, 7
- ld de, SCREEN_WIDTH
- push af
- ld a, [wSpriteFlipped]
- and a
- jr nz, .flipped
- pop af
-.loop
- push bc
- push hl
-.innerLoop
- ld [hl], a
- add hl, de
- inc a
- dec c
- jr nz, .innerLoop
- pop hl
- inc hl
- pop bc
- dec b
- jr nz, .loop
- ret
-
-.flipped
- push bc
- ld b, 0
- dec c
- add hl, bc
- pop bc
- pop af
-.flippedLoop
- push bc
- push hl
-.flippedInnerLoop
- ld [hl], a
- add hl, de
- inc a
- dec c
- jr nz, .flippedInnerLoop
- pop hl
- dec hl
- pop bc
- dec b
- jr nz, .flippedLoop
+ predef MoveAnimation
+ callab Func_78e98
ret
-LoadMonBackPic:
-; Assumes the monster's attributes have
-; been loaded with GetMonHeader.
- ld a, [wBattleMonSpecies2]
- ld [wcf91], a
- coord hl, 1, 5
- ld b, 7
- ld c, 8
- call ClearScreenArea
- ld hl, wMonHBackSprite - wMonHeader
- call UncompressMonSprite
- predef ScaleSpriteByTwo
- ld de, vBackPic
- call InterlaceMergeSpriteBuffers ; combine the two buffers to a single 2bpp sprite
- ld hl, vSprites
- ld de, vBackPic
- ld c, (2*SPRITEBUFFERSIZE)/16 ; count of 16-byte chunks to be copied
- ld a, [H_LOADEDROMBANK]
- ld b, a
- jp CopyVideoData
-
JumpMoveEffect:
call _JumpMoveEffect
ld b, $1
@@ -7264,6 +7152,16 @@ SleepEffect:
call BattleRandom
and $7
jr z, .setSleepCounter
+ ld b, a
+ ld a, [wUnknownSerialFlag_d499]
+ and a
+ jr z, .asm_3f1ba ; XXX stadium stuff?
+ ld a, b
+ and $3
+ jr z, .setSleepCounter
+ ld b, a
+.asm_3f1ba
+ ld a, b
ld [de], a
call PlayCurrentMoveAnimation2
ld hl, FellAsleepText
@@ -7275,7 +7173,7 @@ FellAsleepText:
TX_FAR _FellAsleepText
db "@"
-AlreadyAsleepText:
+AlreadyAsleepText: ; 3f1cd (f:71cds)
TX_FAR _AlreadyAsleepText
db "@"
@@ -7334,7 +7232,7 @@ PoisonEffect:
jr nz, .ok
ld b, ANIM_A9
ld hl, wEnemyBattleStatus3
- ld de, wEnemyToxcCounter
+ ld de, wEnemyToxicCounter
.ok
cp TOXIC
jr nz, .normalPoison ; done if move is not Toxic
@@ -7342,18 +7240,18 @@ PoisonEffect:
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
@@ -7402,7 +7300,7 @@ FreezeBurnParalyzeEffect:
ret nz ; return if they have a substitute, can't effect them
ld a, [H_WHOSETURN]
and a
- jp nz, opponentAttacker
+ jp nz, .opponentAttacker
ld a, [wEnemyMonStatus]
and a
jp nz, CheckDefrost ; can't inflict status if opponent is already statused
@@ -7415,6 +7313,16 @@ FreezeBurnParalyzeEffect:
cp b ; do target type 2 and move type match?
ret z ; return if they match
ld a, [wPlayerMoveEffect]
+ cp UNUSED_EFFECT_23 ; more stadium stuff
+ jr nz, .asm_3f2c7
+ ld a, [wUnknownSerialFlag_d499]
+ and a
+ ld a, FREEZE_SIDE_EFFECT
+ ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance
+ jr z, .next1
+ ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance
+ jr .next1
+.asm_3f2c7
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..
@@ -7428,9 +7336,9 @@ FreezeBurnParalyzeEffect:
ret nc ; do nothing if random value is >= 1A or 4D [no status applied]
ld a, b ; what type of effect is this?
cp a, BURN_SIDE_EFFECT1
- jr z, .burn
+ jr z, .burn1
cp a, FREEZE_SIDE_EFFECT
- jr z, .freeze
+ jr z, .freeze1
; .paralyze
ld a, 1 << PAR
ld [wEnemyMonStatus], a
@@ -7438,7 +7346,7 @@ FreezeBurnParalyzeEffect:
ld a, ANIM_A9
call PlayBattleAnimation
jp PrintMayNotAttackText ; print paralysis text
-.burn
+.burn1
ld a, 1 << BRN
ld [wEnemyMonStatus], a
call HalveAttackDueToBurn ; halve attack of affected mon
@@ -7446,7 +7354,7 @@ FreezeBurnParalyzeEffect:
call PlayBattleAnimation
ld hl, BurnedText
jp PrintText
-.freeze
+.freeze1
call ClearHyperBeam ; resets hyper beam (recharge) condition from target
ld a, 1 << FRZ
ld [wEnemyMonStatus], a
@@ -7454,7 +7362,7 @@ FreezeBurnParalyzeEffect:
call PlayBattleAnimation
ld hl, FrozenText
jp PrintText
-opponentAttacker:
+.opponentAttacker ; 3f382 (f:7382)
ld a, [wBattleMonStatus] ; mostly same as above with addresses swapped for opponent
and a
jp nz, CheckDefrost
@@ -7467,12 +7375,22 @@ opponentAttacker:
cp b
ret z
ld a, [wEnemyMoveEffect]
+ cp UNUSED_EFFECT_23 ; more stadium stuff
+ jr nz, .asm_3f341
+ ld a, [wUnknownSerialFlag_d499]
+ and a
+ ld a, FREEZE_SIDE_EFFECT
+ ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance
+ jr z, .next2
+ ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance
+ jr .next2
+.asm_3f341
cp a, PARALYZE_SIDE_EFFECT1 + 1
ld b, $1a
- jr c, .next1
+ jr c, .next2
ld b, $4d
sub a, $1e
-.next1
+.next2
push af
call BattleRandom
cp b
@@ -7480,23 +7398,29 @@ opponentAttacker:
ret nc
ld a, b
cp a, BURN_SIDE_EFFECT1
- jr z, .burn
+ jr z, .burn2
cp a, FREEZE_SIDE_EFFECT
- jr z, .freeze
+ jr z, .freeze2
ld a, 1 << PAR
ld [wBattleMonStatus], a
call QuarterSpeedDueToParalysis
+ ld a, ANIM_C7
+ call PlayBattleAnimation2
jp PrintMayNotAttackText
-.burn
+.burn2
ld a, 1 << BRN
ld [wBattleMonStatus], a
call HalveAttackDueToBurn
+ ld a, ANIM_C7
+ call PlayBattleAnimation2
ld hl, BurnedText
jp PrintText
-.freeze
+.freeze2
; hyper beam bits aren't reseted for opponent's side
ld a, 1 << FRZ
ld [wBattleMonStatus], a
+ ld a, ANIM_C7
+ call PlayBattleAnimation2
ld hl, FrozenText
jp PrintText
@@ -7661,25 +7585,25 @@ UpdateStatDone:
ld bc, wPlayerMonMinimized
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3f4e6
+ jr z, .playerTurn
ld hl, wEnemyBattleStatus2
ld de, wEnemyMoveNum
ld bc, wEnemyMonMinimized
-.asm_3f4e6
+.playerTurn
ld a, [de]
cp MINIMIZE
- jr nz, .asm_3f4f9
+ jr nz, .notMinimize
; 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
+ push de
ld hl, HideSubstituteShowMonAnim
ld b, BANK(HideSubstituteShowMonAnim)
- push de
call nz, Bankswitch
pop de
-.asm_3f4f9
+.notMinimize
call PlayCurrentMoveAnimation
ld a, [de]
cp MINIMIZE
@@ -7718,9 +7642,9 @@ MonsStatsRoseText:
ld a, [H_WHOSETURN]
and a
ld a, [wPlayerMoveEffect]
- jr z, .asm_3f53b
+ jr z, .playerTurn
ld a, [wEnemyMoveEffect]
-.asm_3f53b
+.playerTurn
cp ATTACK_DOWN1_EFFECT
ret nc
ld hl, RoseText
@@ -7729,7 +7653,7 @@ MonsStatsRoseText:
GreatlyRoseText:
db $0a
TX_FAR _GreatlyRoseText
-
+; fallthrough
RoseText:
TX_FAR _RoseText
db "@"
@@ -7818,9 +7742,9 @@ StatModifierDownEffect:
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)
@@ -7920,12 +7844,13 @@ MonsStatsFellText:
ld a, [H_WHOSETURN]
and a
ld a, [wPlayerMoveEffect]
- jr z, .asm_3f674
+ jr z, .playerTurn
ld a, [wEnemyMoveEffect]
-.asm_3f674
- cp $1a
+.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
@@ -7933,7 +7858,7 @@ MonsStatsFellText:
GreatlyFellText:
db $0a
TX_FAR _GreatlyFellText
-
+; fallthrough
FellText:
TX_FAR _FellText
db "@"
@@ -7941,15 +7866,15 @@ FellText:
PrintStatText:
ld hl, StatsTextStrings
ld c, "@"
-.asm_3f68d
+.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
@@ -8027,41 +7952,42 @@ ThrashPetalDanceEffect:
SwitchAndTeleportEffect:
ld a, [H_WHOSETURN]
and a
- jr nz, .asm_3f791
+ jr nz, .handleEnemy
ld a, [wIsInBattle]
dec a
- jr nz, .asm_3f77e
+ 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
- srl b
+ cp c ; get a random number between 0 and c
+ jr nc, .rejectionSampleLoop1
srl b
- cp b
- jr nc, .asm_3f76e
+ srl b ; b = enemy level * 4
+; bug: does not account for overflow, so levels above 63 can lead to erroneousness results
+ cp b ; is rand[0, playerLevel + enemyLevel] > enemyLevel?
+ jr nc, .playerMoveWasSuccessful ; if so, allow teleporting
ld c, 50
call DelayFrames
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, [wPlayerMoveNum]
- jr .asm_3f7e4
-.asm_3f77e
+ jr .playAnimAndPrintText
+.notWildBattle1
ld c, 50
call DelayFrames
ld hl, IsUnaffectedText
@@ -8069,41 +7995,41 @@ SwitchAndTeleportEffect:
cp TELEPORT
jp nz, PrintText
jp PrintButItFailedText_
-.asm_3f791
+.handleEnemy
ld a, [wIsInBattle]
dec a
- jr nz, .asm_3f7d1
+ jr nz, .notWildBattle2
ld a, [wBattleMonLevel]
ld b, a
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
+ jr nc, .enemyMoveWasSuccessful
ld c, 50
call DelayFrames
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, [wEnemyMoveNum]
- jr .asm_3f7e4
-.asm_3f7d1
+ jr .playAnimAndPrintText
+.notWildBattle2
ld c, 50
call DelayFrames
ld hl, IsUnaffectedText
@@ -8111,7 +8037,7 @@ SwitchAndTeleportEffect:
cp TELEPORT
jp nz, PrintText
jp ConditionalPrintButItFailed
-.asm_3f7e4
+.playAnimAndPrintText
push af
call PlayBattleAnimation
ld c, 20
@@ -8119,12 +8045,12 @@ SwitchAndTeleportEffect:
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:
@@ -8169,10 +8095,11 @@ TwoToFiveAttacksEffect:
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
@@ -8195,6 +8122,9 @@ FlinchSideEffect:
ld hl, wPlayerBattleStatus1
ld de, wEnemyMoveEffect
.flinchSideEffect
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
+ call z, ClearHyperBeam
ld a, [de]
cp FLINCH_SIDE_EFFECT1
ld b, $1a ; ~10% chance of flinch
@@ -8236,10 +8166,27 @@ ChargeEffect:
set Invulnerable, [hl] ; mon is now invulnerable to typical attacks (fly/dig)
ld b, ANIM_C0
.notDigOrFly
+ push de
+ push bc
+ inc hl ; battle status 2
+ push hl
+ ld a, [hl]
+ bit HasSubstituteUp, a
+ ld hl, HideSubstituteShowMonAnim
+ ld b, BANK(HideSubstituteShowMonAnim)
+ call nz, Bankswitch
+ pop hl
+ pop bc
xor a
ld [wAnimationType], a
ld a, b
call PlayBattleAnimation
+ ld a, [hl]
+ bit HasSubstituteUp, a
+ ld hl, ReshowSubstituteAnim
+ ld b, BANK(ReshowSubstituteAnim)
+ call nz, Bankswitch
+ pop de
ld a, [de]
ld [wChargeMoveNum], a
ld hl, ChargeMoveEffectText
@@ -8251,22 +8198,22 @@ ChargeMoveEffectText:
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:
@@ -8329,7 +8276,7 @@ RecoilEffect:
ConfusionSideEffect:
call BattleRandom
- cp $19
+ cp $19 ; ~10% chance
ret nc
jr ConfusionSideEffectSuccess
@@ -8399,9 +8346,9 @@ ClearHyperBeam:
ld hl, wEnemyBattleStatus2
ld a, [H_WHOSETURN]
and a
- jr z, .asm_3f9db
+ jr z, .playerTurn
ld hl, wPlayerBattleStatus2
-.asm_3f9db
+.playerTurn
res NeedsToRecharge, [hl] ; mon no longer needs to recharge
pop hl
ret
@@ -8422,21 +8369,21 @@ MimicEffect:
call MoveHitTest
ld a, [wMoveMissed]
and a
- jr nz, .asm_3fa74
+ jr nz, .mimicMissed
ld a, [H_WHOSETURN]
and a
ld hl, wBattleMonMoves
ld a, [wPlayerBattleStatus1]
- jr nz, .asm_3fa13
+ jr nz, .enemyTurn
ld a, [wLinkState]
cp LINK_STATE_BATTLING
- jr nz, .asm_3fa3a
+ jr nz, .letPlayerChooseMove
ld hl, wEnemyMonMoves
ld a, [wEnemyBattleStatus1]
-.asm_3fa13
+.enemyTurn
bit Invulnerable, a
- jr nz, .asm_3fa74
-.asm_3fa17
+ jr nz, .mimicMissed
+.getRandomMove
push hl
call BattleRandom
and $3
@@ -8446,20 +8393,20 @@ MimicEffect:
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
+ jr .playerTurn
+.letPlayerChooseMove
ld a, [wEnemyBattleStatus1]
bit Invulnerable, a
- jr nz, .asm_3fa74
+ jr nz, .mimicMissed
ld a, [wCurrentMenuItem]
push af
ld a, $1
@@ -8474,7 +8421,7 @@ MimicEffect:
ld d, [hl]
pop af
ld hl, wBattleMonMoves
-.asm_3fa5f
+.playerTurn
ld c, a
ld b, $0
add hl, bc
@@ -8485,7 +8432,7 @@ MimicEffect:
call PlayCurrentMoveAnimation
ld hl, MimicLearnedMoveText
jp PrintText
-.asm_3fa74
+.mimicMissed
jp PrintButItFailedText_
MimicLearnedMoveText:
@@ -8709,6 +8656,7 @@ PlayBattleAnimationGotID:
push de
push bc
predef MoveAnimation
+ callab Func_78e98
pop bc
pop de
pop hl
diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm
index 984af087..fd1a3184 100644
--- a/engine/battle/decrement_pp.asm
+++ b/engine/battle/decrement_pp.asm
@@ -33,7 +33,7 @@ DecrementPP:
ld a, [wPlayerMonNumber] ; which mon in party is active
ld bc, wPartyMon2 - wPartyMon1
call AddNTimes ; calculate address of the mon to modify
-.DecrementPP
+.DecrementPP ; f4301 (3d:4301)
ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use?
ld c, a
ld b, 0
diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm
index d477ffdf..8f9dce46 100644
--- a/engine/battle/draw_hud_pokeball_gfx.asm
+++ b/engine/battle/draw_hud_pokeball_gfx.asm
@@ -27,6 +27,8 @@ SetupOwnPartyPokeballs:
ld [hl], a
ld a, 8
ld [wHUDPokeballGfxOffsetX], a
+ xor a
+ ld [wdef5], a
ld hl, wOAMBuffer
jp WritePokeballOAMData
@@ -41,10 +43,12 @@ SetupEnemyPartyPokeballs:
ld [hl], $20
ld a, -8
ld [wHUDPokeballGfxOffsetX], a
+ ld a, $1
+ ld [wdef5], a
ld hl, wOAMBuffer + PARTY_LENGTH * 4
jp WritePokeballOAMData
-SetupPokeballs: ; 0x3a8a6
+SetupPokeballs:
ld a, [de]
push af
ld de, wBuffer
@@ -104,7 +108,7 @@ WritePokeballOAMData:
ld [hli], a
ld a, [de]
ld [hli], a
- xor a
+ ld a, [wdef5]
ld [hli], a
ld a, [wBaseCoordX]
ld b, a
@@ -174,6 +178,8 @@ SetupPlayerAndEnemyPokeballs:
ld [hl], $40
ld a, 8
ld [wHUDPokeballGfxOffsetX], a
+ xor a
+ ld [wdef5], a
ld hl, wOAMBuffer
call WritePokeballOAMData
ld hl, wEnemyMons
@@ -183,6 +189,8 @@ SetupPlayerAndEnemyPokeballs:
ld a, $50
ld [hli], a
ld [hl], $68
+ ld a, $1
+ ld [wdef5], a
ld hl, wOAMBuffer + $18
jp WritePokeballOAMData
diff --git a/engine/battle/end_of_battle.asm b/engine/battle/end_of_battle.asm
index 2d6ab2e9..47c9fa5d 100755
--- a/engine/battle/end_of_battle.asm
+++ b/engine/battle/end_of_battle.asm
@@ -10,6 +10,8 @@ EndOfBattle:
ld a, [wEnemyMonStatus]
ld [hl], a
call ClearScreen
+ ld b, SET_PAL_OVERWORLD
+ call RunPaletteCommand
callab DisplayLinkBattleVersusTextBox
ld a, [wBattleResult]
cp $1
@@ -43,6 +45,8 @@ EndOfBattle:
xor a
ld [wForceEvolution], a
predef EvolutionAfterBattle
+ ld d, $82
+ callab UpdatePikachuMoodAfterBattle
.resetVariables
xor a
ld [wLowHealthAlarm], a ;disable low health alarm
diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm
index c1914806..9946c6c6 100644
--- a/engine/battle/experience.asm
+++ b/engine/battle/experience.asm
@@ -43,17 +43,17 @@ GainExperience:
inc de
jr .nextBaseStat
.maxStatExp ; if the upper byte also overflowed, then we have hit the max stat exp
- ld a, $ff
+ dec a ; a is 0 from previous check
ld [de], a
inc de
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
@@ -233,13 +233,19 @@ GainExperience:
.recalcStatChanges
xor a ; battle mon
ld [wCalculateWhoseStats], a
- callab CalculateModifiedStats
- callab ApplyBurnAndParalysisPenaltiesToPlayer
- callab ApplyBadgeStatBoosts
- callab DrawPlayerHUDAndHPBar
- callab PrintEmptyString
+ ld hl, CalculateModifiedStats
+ call Bankswitch15ToF
+ ld hl, ApplyBurnAndParalysisPenaltiesToPlayer
+ call Bankswitch15ToF
+ ld hl, ApplyBadgeStatBoosts
+ call Bankswitch15ToF
+ ld hl, DrawPlayerHUDAndHPBar
+ call Bankswitch15ToF
+ ld hl, PrintEmptyString
+ call Bankswitch15ToF
call SaveScreenTilesToBuffer1
.printGrewLevelText
+ callabd_ModifyPikachuHappiness PIKAHAPPY_LEVELUP
ld hl, GrewLevelText
call PrintText
xor a ; PLAYER_PARTY_DATA
@@ -339,6 +345,10 @@ BoostExp:
ld [H_QUOTIENT + 2], a
ret
+Bankswitch15ToF:
+ ld b, BANK(BattleCore)
+ jp Bankswitch
+
GainedText:
TX_FAR _GainedText
TX_ASM
diff --git a/engine/battle/get_trainer_name.asm b/engine/battle/get_trainer_name.asm
index deed8e95..e051a02a 100644
--- a/engine/battle/get_trainer_name.asm
+++ b/engine/battle/get_trainer_name.asm
@@ -2,15 +2,15 @@ GetTrainerName_:
ld hl, wGrassRate
ld a, [wLinkState]
and a
- jr nz, .rival
+ 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,6 +18,7 @@ GetTrainerName_:
ld [wPredefBank], a
call GetName
ld hl, wcd6d
+.foundName
.rival
ld de, wTrainerName
ld bc, $d
diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm
index 7adb20d8..5bb3e308 100644
--- a/engine/battle/ghost_marowak_anim.asm
+++ b/engine/battle/ghost_marowak_anim.asm
@@ -2,6 +2,7 @@ MarowakAnim:
; animate the ghost being unveiled as a Marowak
ld a, $e4
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
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
coord hl, 12, 0
@@ -27,6 +28,7 @@ MarowakAnim:
sla a
sla a
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
jr nz, .fadeOutGhostLoop
call ClearSprites
call CopyMonPicFromBGToSpriteVRAM ; copy Marowak pic from BG to sprite VRAM
@@ -40,6 +42,7 @@ MarowakAnim:
srl b
rra
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
ld a, b
and a
jr nz, .fadeInMarowakLoop
@@ -74,7 +77,7 @@ CopyMonPicFromBGToSpriteVRAM:
ld [hli], a
ld a, d
ld [hli], a
- ld a, $10 ; use OBP1
+ ld a, $14 ; use OBP1
ld [hli], a
inc d
dec c
diff --git a/engine/battle/link_battle_versus_text.asm b/engine/battle/link_battle_versus_text.asm
index 57e7f1bb..5edf13e6 100644
--- a/engine/battle/link_battle_versus_text.asm
+++ b/engine/battle/link_battle_versus_text.asm
@@ -2,8 +2,7 @@
DisplayLinkBattleVersusTextBox:
call LoadTextBoxTilePatterns
coord hl, 3, 4
- ld b, $7
- ld c, $c
+ ld bc, $70c
call TextBoxBorder
coord hl, 4, 5
ld de, wPlayerName
diff --git a/engine/battle/moveEffects/heal_effect.asm b/engine/battle/moveEffects/heal_effect.asm
index b7d8283f..377c14c4 100644
--- a/engine/battle/moveEffects/heal_effect.asm
+++ b/engine/battle/moveEffects/heal_effect.asm
@@ -86,7 +86,7 @@ HealEffect_:
ld [wHPBarNewHP], a
.playAnim
ld hl, PlayCurrentMoveAnimation
- call BankswitchEtoF
+ call Bankswitch3DtoF
ld a, [H_WHOSETURN]
and a
coord hl, 10, 9
@@ -98,14 +98,14 @@ HealEffect_:
ld [wHPBarType], a
predef UpdateHPBar2
ld hl, DrawHUDsAndHPBars
- call BankswitchEtoF
+ call Bankswitch3DtoF
ld hl, RegainedHealthText
jp PrintText
.failed
ld c, 50
call DelayFrames
ld hl, PrintButItFailedText_
- jp BankswitchEtoF
+ jp Bankswitch3DtoF
StartedSleepingEffect:
TX_FAR _StartedSleepingEffect
diff --git a/engine/battle/moveEffects/reflect_light_screen_effect.asm b/engine/battle/moveEffects/reflect_light_screen_effect.asm
index b45fbe20..f2165956 100644
--- a/engine/battle/moveEffects/reflect_light_screen_effect.asm
+++ b/engine/battle/moveEffects/reflect_light_screen_effect.asm
@@ -23,14 +23,14 @@ ReflectLightScreenEffect_:
.playAnim
push hl
ld hl, PlayCurrentMoveAnimation
- call BankswitchEtoF
+ call Bankswitch3DtoF
pop hl
jp PrintText
.moveFailed
ld c, 50
call DelayFrames
ld hl, PrintButItFailedText_
- jp BankswitchEtoF
+ jp Bankswitch3DtoF
LightScreenProtectedText:
TX_FAR _LightScreenProtectedText
@@ -40,6 +40,6 @@ ReflectGainedArmorText:
TX_FAR _ReflectGainedArmorText
db "@"
-BankswitchEtoF:
+Bankswitch3DtoF:
ld b, BANK(BattleCore)
jp Bankswitch
diff --git a/engine/battle/moveEffects/transform_effect.asm b/engine/battle/moveEffects/transform_effect.asm
index 45f8c910..2906de11 100644
--- a/engine/battle/moveEffects/transform_effect.asm
+++ b/engine/battle/moveEffects/transform_effect.asm
@@ -100,18 +100,11 @@ TransformEffect_:
and a
jr z, .lessThanFourMoves
ld a, $5
- ld [de], a
- inc de
- dec b
- jr nz, .copyPPLoop
- jr .copyStats
.lessThanFourMoves
-; 0 PP for blank moves
- xor a
ld [de], a
inc de
dec b
- jr nz, .lessThanFourMoves
+ jr nz, .copyPPLoop
.copyStats
; original (unmodified) stats and stat mods
pop hl
@@ -141,7 +134,7 @@ TransformEffect_:
.failed
ld hl, PrintButItFailedText_
- jp BankswitchEtoF
+ jp Bankswitch3DtoF
TransformedText:
TX_FAR _TransformedText
diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm
index 3672d8dc..3f10a85d 100755
--- a/engine/battle/read_trainer_party.asm
+++ b/engine/battle/read_trainer_party.asm
@@ -15,9 +15,9 @@ ReadTrainer:
ld [hl],a
; get the pointer to trainer data for this class
- ld a,[wCurOpponent]
- sub $C9 ; convert value from pokemon to trainer
- add a,a
+ ld a,[wTrainerClass] ; get trainer class
+ dec a
+ add a
ld hl,TrainerDataPointers
ld c,a
ld b,0
@@ -53,7 +53,7 @@ ReadTrainer:
.LoopTrainerData
ld a,[hli]
and a ; have we reached the end of the trainer data?
- jr z,.FinishUp
+ jp z, .AddAdditionalMoveData
ld [wcf91],a ; write species somewhere (XXX why?)
ld a,ENEMY_PARTY_DATA
ld [wMonDataLocation],a
@@ -68,7 +68,7 @@ ReadTrainer:
; - 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
+ jr z,.AddAdditionalMoveData
ld [wCurEnemyLVL],a
ld a,[hli]
ld [wcf91],a
@@ -78,69 +78,48 @@ ReadTrainer:
call AddPartyMon
pop hl
jr .SpecialTrainer
-.AddLoneMove
-; does the trainer have a single monster with a different move
- ld a,[wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc
+.AddAdditionalMoveData
+; does the trainer have additional move data?
+ ld a, [wTrainerClass]
+ ld b, a
+ ld a, [wTrainerNo]
+ ld c, a
+ ld hl, SpecialTrainerMoves
+.loopAdditionalMoveData
+ ld a, [hli]
+ cp $ff
+ jr z, .FinishUp
+ cp b
+ jr nz, .asm_39c46
+ ld a, [hli]
+ cp c
+ jr nz, .asm_39c46
+ ld d, h
+ ld e, l
+.writeAdditionalMoveDataLoop
+ ld a, [de]
+ inc de
and a
- jr z,.AddTeamMove
+ jp z, .FinishUp
dec a
- add a,a
- ld c,a
- ld b,0
- ld hl,LoneMoves
- add hl,bc
- ld a,[hli]
- ld d,[hl]
- ld hl,wEnemyMon1Moves + 2
- ld bc,wEnemyMon2 - wEnemyMon1
+ ld hl, wEnemyMon1Moves
+ ld bc, wEnemyMon2 - wEnemyMon1
call AddNTimes
- ld [hl],d
- jr .FinishUp
-.AddTeamMove
-; check if our trainer's team has special moves
-
-; get trainer class number
- ld a,[wCurOpponent]
- sub 200
- ld b,a
- ld hl,TeamMoves
-
-; iterate through entries in TeamMoves, checking each for our trainer class
-.IterateTeamMoves
- ld a,[hli]
- cp b
- jr z,.GiveTeamMoves ; is there a match?
- inc hl ; if not, go to the next entry
- inc a
- jr nz,.IterateTeamMoves
-
-; no matches found. is this trainer champion rival?
- ld a,b
- cp SONY3
- jr z,.ChampionRival
- jr .FinishUp ; nope
-.GiveTeamMoves
- ld a,[hl]
- ld [wEnemyMon5Moves + 2],a
- jr .FinishUp
-.ChampionRival ; give moves to his team
-
-; pidgeot
- ld a,SKY_ATTACK
- ld [wEnemyMon1Moves + 2],a
-
-; starter
- ld a,[wRivalStarter]
- cp STARTER3
- ld b,MEGA_DRAIN
- jr z,.GiveStarterMove
- cp STARTER1
- ld b,FIRE_BLAST
- jr z,.GiveStarterMove
- ld b,BLIZZARD ; must be squirtle
-.GiveStarterMove
- ld a,b
- ld [wEnemyMon6Moves + 2],a
+ ld a, [de]
+ inc de
+ dec a
+ ld c, a
+ ld b, 0
+ add hl,bc
+ ld a, [de]
+ inc de
+ ld [hl], a
+ jr .writeAdditionalMoveDataLoop
+.asm_39c46
+ ld a, [hli]
+ and a
+ jr nz, .asm_39c46
+ jr .loopAdditionalMoveData
.FinishUp
; clear wAmountMoneyWon addresses
xor a
diff --git a/engine/battle/safari_zone.asm b/engine/battle/safari_zone.asm
index 1eb1a615..c6c0fa80 100755
--- a/engine/battle/safari_zone.asm
+++ b/engine/battle/safari_zone.asm
@@ -2,18 +2,18 @@ PrintSafariZoneBattleText:
ld hl, wSafariBaitFactor
ld a, [hl]
and a
- jr z, .asm_4284
+ jr z, .asm_411e
dec [hl]
ld hl, SafariZoneEatingText
- jr .asm_429f
-.asm_4284
+ jr .asm_4138
+.asm_411e
dec hl
ld a, [hl]
and a
ret z
dec [hl]
ld hl, SafariZoneAngryText
- jr nz, .asm_429f
+ jr nz, .asm_4138
push hl
ld a, [wEnemyMonSpecies]
ld [wd0b5], a
@@ -21,7 +21,7 @@ PrintSafariZoneBattleText:
ld a, [wMonHCatchRate]
ld [wEnemyMonCatchRate], a
pop hl
-.asm_429f
+.asm_4138
push hl
call LoadScreenTilesFromBuffer1
pop hl
diff --git a/engine/battle/scale_sprites.asm b/engine/battle/scale_sprites.asm
index 98521528..c614d638 100644
--- a/engine/battle/scale_sprites.asm
+++ b/engine/battle/scale_sprites.asm
@@ -2,6 +2,13 @@
; 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:
+ ld a, $0
+ call SwitchSRAMBankAndLatchClockData
+ call ScaleSpriteByTwo_
+ call PrepareRTCDataAndDisableSRAM
+ ret
+
+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
diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm
index 385cdd1b..3624f5ea 100644
--- a/engine/battle/trainer_ai.asm
+++ b/engine/battle/trainer_ai.asm
@@ -145,7 +145,7 @@ AIMoveChoiceModification1:
ld [hl], a
jr .nextMove
-StatusAilmentMoveEffects: ; 57e2
+StatusAilmentMoveEffects:
db $01 ; unused sleep effect
db SLEEP_EFFECT
db POISON_EFFECT
@@ -182,7 +182,7 @@ AIMoveChoiceModification2:
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).
@@ -295,7 +295,7 @@ TrainerClassMoveChoiceModifications:
db 1,0 ; GAMBLER
db 1,3,0 ; BEAUTY
db 1,2,0 ; PSYCHIC_TR
- db 1,3,0 ; ROCKER
+ db 1,0 ; ROCKER
db 1,0 ; JUGGLER
db 1,0 ; TAMER
db 1,0 ; BIRD_KEEPER
@@ -311,11 +311,11 @@ TrainerClassMoveChoiceModifications:
db 1,0 ; BRUNO
db 1,0 ; BROCK
db 1,3,0 ; MISTY
- db 1,3,0 ; LT_SURGE
+ db 1,0 ; LT_SURGE
db 1,3,0 ; ERIKA
db 1,3,0 ; KOGA
- db 1,3,0 ; BLAINE
- db 1,3,0 ; SABRINA
+ db 1,0 ; BLAINE
+ db 1,0 ; SABRINA
db 1,2,0 ; GENTLEMAN
db 1,3,0 ; SONY2
db 1,3,0 ; SONY3
@@ -337,13 +337,19 @@ INCLUDE "data/trainer_moves.asm"
INCLUDE "data/trainer_parties.asm"
TrainerAI:
- and a
ld a,[wIsInBattle]
dec a
- ret z ; if not a trainer, we're done here
+ jr z, .done ; if not a trainer, we're done here
ld a,[wLinkState]
cp LINK_STATE_BATTLING
- ret z
+ jr z, .done ; if in a link battle, we're done as well
+ ld a, [wEnemyBattleStatus1]
+ and 1 << ChargingUp | 1 << ThrashingAbout | 1 << StoringEnergy ; %10011
+ jr nz, .done ; don't follow trainer ai if opponent is in a locked state
+ ld a, [wEnemyBattleStatus2]
+ and 1 << UsingRage ; %1000000
+ jr nz, .done ; don't follow trainer ai if opponent is locked in rage
+ ; note that this doesn't check for hyper beam recharge which can cause problems
ld a,[wTrainerClass] ; what trainer class is this?
dec a
ld c,a
@@ -354,7 +360,7 @@ TrainerAI:
add hl,bc
ld a,[wAICount]
and a
- ret z ; if no AI uses left, we're done here
+ jr z, .done; if no AI uses left, we're done here
inc hl
inc a
jr nz,.getpointer
@@ -367,6 +373,9 @@ TrainerAI:
ld l,a
call Random
jp [hl]
+.done
+ and a
+ ret
TrainerAIPointers:
; one entry per trainer class
@@ -476,22 +485,22 @@ ErikaAI:
jp AIUseSuperPotion
KogaAI:
- cp $40
+ cp $20
ret nc
jp AIUseXAttack
BlaineAI:
cp $40
ret nc
+ ld a,$A
+ call AICheckIfHPBelowFraction
+ ret nc
jp AIUseSuperPotion
SabrinaAI:
cp $40
ret nc
- ld a,$A
- call AICheckIfHPBelowFraction
- ret nc
- jp AIUseHyperPotion
+ jp AIUseXDefend
Sony2AI:
cp $20
@@ -731,7 +740,8 @@ AICureStatus:
res 0,[hl]
ret
-AIUseXAccuracy: ; 0x3a7a8 unused
+AIUseXAccuracy:
+; unused
call AIPlayRestoringSFX
ld hl,wEnemyBattleStatus2
set 0,[hl]
@@ -745,7 +755,8 @@ AIUseGuardSpec:
ld a,GUARD_SPEC
jp AIPrintItemUse
-AIUseDireHit: ; 0x3a7c2 unused
+AIUseDireHit:
+; unused
call AIPlayRestoringSFX
ld hl,wEnemyBattleStatus2
set 2,[hl]
diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm
index 231c46e7..0285346e 100644
--- a/engine/battle/wild_encounters.asm
+++ b/engine/battle/wild_encounters.asm
@@ -24,8 +24,9 @@ TryDoWildEncounter:
ld [wRepelRemainingSteps], a
.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?
- coord hl, 9, 9
+; is the bottom left tile (8,9) of the half-block we're standing in a grass/water tile?
+; note that by using the bottom left tile, this prevents the "left-shore" tiles from generating grass encounters
+ coord hl, 8, 9
ld c, [hl]
ld a, [wGrassTile]
cp c
@@ -68,8 +69,6 @@ TryDoWildEncounter:
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, 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.
.gotWildEncounterType
ld b, 0
add hl, bc
diff --git a/engine/bcd.asm b/engine/bcd.asm
new file mode 100644
index 00000000..204c2e40
--- /dev/null
+++ b/engine/bcd.asm
@@ -0,0 +1,216 @@
+; divide hMoney by hDivideBCDDivisor
+; return output in hDivideBCDQuotient (same as hDivideBCDDivisor)
+; used only to halve player money upon losing a fight
+DivideBCDPredef::
+DivideBCDPredef2::
+DivideBCDPredef3:: ; only used function
+DivideBCDPredef4::
+ call GetPredefRegisters
+
+DivideBCD::
+ xor a
+ ld [hDivideBCDBuffer], a
+ ld [hDivideBCDBuffer + 1], a
+ ld [hDivideBCDBuffer + 2], a
+ ld d, $1
+.loop1
+ ld a, [hDivideBCDDivisor]
+ and $f0
+ jr nz, .go
+ inc d
+ ld a, [hDivideBCDDivisor]
+ swap a
+ and $f0
+ ld b, a
+ ld a, [hDivideBCDDivisor + 1]
+ swap a
+ ld [hDivideBCDDivisor + 1], a
+ and $f
+ or b
+ ld [hDivideBCDDivisor], a
+ ld a, [hDivideBCDDivisor + 1]
+ and $f0
+ ld b, a
+ ld a, [hDivideBCDDivisor + 2]
+ swap a
+ ld [hDivideBCDDivisor + 2], a
+ and $f
+ or b
+ ld [hDivideBCDDivisor + 1], a
+ ld a, [hDivideBCDDivisor + 2]
+ and $f0
+ ld [hDivideBCDDivisor + 2], a
+ jr .loop1
+
+.go
+ push de
+ push de
+ call DivideBCD_f686
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [hDivideBCDBuffer], a
+ dec d
+ jr z, .skip
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, [hDivideBCDBuffer]
+ or b
+ ld [hDivideBCDBuffer], a
+ dec d
+ jr z, .skip
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [hDivideBCDBuffer + 1], a
+ dec d
+ jr z, .skip
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, [hDivideBCDBuffer + 1]
+ or b
+ ld [hDivideBCDBuffer + 1], a
+ dec d
+ jr z, .skip
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, b
+ swap a
+ and $f0
+ ld [hDivideBCDBuffer + 2], a
+ dec d
+ jr z, .skip
+ push de
+ call DivideBCD_f65d
+ call DivideBCD_f686
+ pop de
+ ld a, [hDivideBCDBuffer + 2]
+ or b
+ ld [hDivideBCDBuffer + 2], a
+.skip
+ ld a, [hDivideBCDBuffer]
+ ld [hDivideBCDQuotient], a
+ ld a, [hDivideBCDBuffer + 1]
+ ld [hDivideBCDQuotient + 1], a
+ ld a, [hDivideBCDBuffer + 2]
+ ld [hDivideBCDQuotient + 2], a
+ pop de
+ ld a, $6
+ sub d
+ and a
+ ret z
+.loop2
+ push af
+ call DivideBCD_f65d
+ pop af
+ dec a
+ jr nz, .loop2
+ ret
+
+DivideBCD_f65d:
+ ld a, [hDivideBCDDivisor + 2]
+ swap a
+ and $f
+ ld b, a
+ ld a, [hDivideBCDDivisor + 1]
+ swap a
+ ld [hDivideBCDDivisor + 1], a
+ and $f0
+ or b
+ ld [hDivideBCDDivisor + 2], a
+ ld a, [hDivideBCDDivisor + 1]
+ and $f
+ ld b, a
+ ld a, [hDivideBCDDivisor]
+ swap a
+ ld [hDivideBCDDivisor], a
+ and $f0
+ or b
+ ld [hDivideBCDDivisor + 1], a
+ ld a, [hDivideBCDDivisor]
+ and $f
+ ld [hDivideBCDDivisor], a
+ ret
+
+DivideBCD_f686:
+ ld bc, $3
+.asm_f689
+ ld de, hMoney
+ ld hl, hDivideBCDDivisor
+ push bc
+ call StringCmp
+ pop bc
+ ret c
+ inc b
+ ld de, hMoney + 2
+ ld hl, hDivideBCDDivisor + 2
+ push bc
+ call SubBCD
+ pop bc
+ jr .asm_f689
+
+
+AddBCDPredef::
+ 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/bg_map_attributes.asm b/engine/bg_map_attributes.asm
new file mode 100644
index 00000000..90df9e27
--- /dev/null
+++ b/engine/bg_map_attributes.asm
@@ -0,0 +1,219 @@
+INCLUDE "data/bg_map_attributes.asm"
+
+LoadBGMapAttributes::
+ ld hl, BGMapAttributesPointers
+ ld a, c ; c = which packet
+ push af ; save for later (to determine if we're handling the trainer card or party menu)
+ dec a ; read this code as:
+ add a ; dec a
+ ld e, a ; add a
+ xor a ; ld e, a
+ ld d, a ; ld d, 0
+ add hl, de ; add hl, de
+ ld a, [hli] ; ld a, [hli]
+ ld e, a ; ld h, [hl]
+ ld a, [hl] ; ld l, a
+ ld h, a
+ ld a, e
+ ld l, a
+
+ di
+ ld a, $1
+ ld [rVBK], a
+ push hl
+ ld a, [hl]
+ ld c, a ; save attribute count for later
+ ld de, $10
+ add hl, de
+ ld a, h
+ ld [rHDMA1], a
+ ld a, l
+ ld [rHDMA2], a
+ ld de, vBGMap0
+ ld a, d
+ ld [rHDMA3], a
+ ld a, e
+ ld [rHDMA4], a
+
+ ld a, [rLCDC]
+ and rLCDC_ENABLE_MASK ; is LCD off?
+ jr z, .lcdOff ; if off, transfer immediately
+; wait for VBlank if LCD is on
+.waitForVBlankLoop1
+ ld a, [rLY]
+ cp $90
+ jr nz, .waitForVBlankLoop1
+.waitForAccessibleVRAMLoop1
+ ld a, [rSTAT]
+ and %10 ; are we in HBlank or VBlank?
+ jr nz, .waitForAccessibleVRAMLoop1 ; loop until we're in a safe period to transfer to VRAM
+.lcdOff
+ ld a, c ; number of BG attributes to transfer, plus 1 times 16
+ ld [rHDMA5], a ; initiate transfer
+ call Func_3082 ; update audio so it doesn't "lag"
+ pop hl
+ ld a, [hli]
+ ld c, a ; number of BG attributes to transfer, plus 1 times 16
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a ; offset of the attributes
+ add hl, de ; hl = new pointer
+ ld a, h
+ ld [rHDMA1], a
+ ld a, l
+ ld [rHDMA2], a
+ ld de, vBGMap1 ; copy to vBGMap1
+ ld a, d
+ ld [rHDMA3], a
+ ld a, e
+ ld [rHDMA4], a
+; LCD check again
+ ld a, [rLCDC]
+ and rLCDC_ENABLE_MASK ; is LCD off?
+ jr z, .lcdOff2 ; if off, transfer immediately
+; wait for VBlank if LCD is on
+.waitForVBlankLoop2
+ ld a, [rLY]
+ cp $90
+ jr nz, .waitForVBlankLoop2
+.waitForAccessibleVRAMLoop2
+ ld a, [rSTAT]
+ and %10 ; are we in HBlank or VBlank?
+ jr nz, .waitForAccessibleVRAMLoop2 ; loop until we're in a safe period to transfer to VRAM
+.lcdOff2
+ ld a, c
+ ld [rHDMA5], a
+ pop af
+ dec a
+ dec a
+ dec a
+ dec a
+ jr nz, .checkIfHandlingPartyMenu
+ call HandleBadgeFaceAttributes
+ jr .done
+.checkIfHandlingPartyMenu
+ dec a
+ call z, HandlePartyHPBarAttributes
+.done
+ call Func_3082
+ ld a, [rIF]
+ res VBLANK, a
+ ld [rIF], a
+ xor a
+ ld [rVBK], a
+ ei
+ ret
+
+BGMapAttributesPointers:
+ dw BGMapAttributes_Unknown1
+ dw BGMapAttributes_Unknown2
+ dw BGMapAttributes_GameFreakIntro
+ dw BGMapAttributes_TrainerCard
+ dw BGMapAttributes_PartyMenu
+ dw BGMapAttributes_NidorinoIntro
+ dw BGMapAttributes_TitleScreen
+ dw BGMapAttributes_Slots
+ dw BGMapAttributes_Pokedex
+ dw BGMapAttributes_StatusScreen
+ dw BGMapAttributes_Battle
+ dw BGMapAttributes_WholeScreen
+ dw BGMapAttributes_Unknown13
+
+HandleBadgeFaceAttributes:
+; zero out the attributes if the player doesn't have the respective badge
+; BOULDERBADGE
+ ld hl, vBGMap1 + $183
+ ld de, wTrainerCardBadgeAttributes + 6 * 0
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+; CASCADEBADGE
+ ld hl, vBGMap1 + $187
+ ld de, wTrainerCardBadgeAttributes + 6 * 1
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+; THUNDERBADGE
+ ld hl, vBGMap1 + $18b
+ ld de, wTrainerCardBadgeAttributes + 6 * 2
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+; RAINBOWBADGE
+ ld hl, vBGMap1 + $18f
+ ld de, wTrainerCardBadgeAttributes + 6 * 3
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+; SOULBADGE
+ ld hl, vBGMap1 + $1e3
+ ld de, wTrainerCardBadgeAttributes + 6 * 6
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+; MARSHBADGE
+ ld hl, vBGMap1 + $1e7
+ ld de, wTrainerCardBadgeAttributes + 6 * 7
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+; VOLCANOBADGE
+ ld hl, vBGMap1 + $1eb
+ ld de, wTrainerCardBadgeAttributes + 6 * 8
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+; EARTHBADGE
+ ld hl, vBGMap1 + $1ef
+ ld de, wTrainerCardBadgeAttributes + 6 * 9
+ ld a, [de]
+ and a
+ call z, ZeroOutCurrentBadgeAttributes
+ ret
+
+ZeroOutCurrentBadgeAttributes:
+ push hl
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ld bc, $1f
+ add hl, bc
+ ld [hli], a
+ ld [hl], a
+ pop hl
+ ret
+
+HandlePartyHPBarAttributes:
+; hp bars require 3 (green, orange, red) colours, when there are only 2 "free" colours per palette
+; therefore, we must transfer individual bg attributes where the locations of the hp bars are in vram
+ ld hl, vBGMap1 + $25 ; location of start of the HP bar in vram
+ ld de, wPartyHPBarAttributes
+ ld c, PARTY_LENGTH
+.loop
+ push bc
+ push hl
+ ld a, [de]
+ and $3 ; 4 possible palettes
+ rept 7 ; hp bar length in tiles
+ ld [hli], a
+ endr
+ pop hl
+ ld bc, $40 ; get 2nd party location
+ add hl, bc
+ push hl
+
+ push de ; (inefficiently) copy de to hl
+ pop hl
+
+ ld bc, $6
+ add hl, bc ; get the next palette
+
+ push hl
+ pop de ; copy back to de
+
+ pop hl
+ pop bc
+ dec c
+ jr nz, .loop
+ ret
diff --git a/engine/cable_club.asm b/engine/cable_club.asm
index d9893f1f..a6552939 100755
--- a/engine/cable_club.asm
+++ b/engine/cable_club.asm
@@ -10,8 +10,7 @@ CableClub_DoBattleOrTrade:
call LoadHpBarAndStatusTilePatterns
call LoadTrainerInfoTextBoxTiles
coord hl, 3, 8
- ld b, 2
- ld c, 12
+ lb bc, 2, 12
call CableClub_TextBoxBorder
coord hl, 4, 10
ld de, PleaseWaitString
@@ -23,14 +22,14 @@ CableClub_DoBattleOrTrade:
; 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
@@ -119,6 +118,7 @@ CableClub_DoBattleOrTradeAgain: ; 5345
ld [rSC], a
.skipSendingTwoZeroBytes
call Delay3
+ call StopAllMusic
ld a, (1 << SERIAL)
ld [rIE], a
ld hl, wSerialRandomNumberListBlock
@@ -139,8 +139,6 @@ CableClub_DoBattleOrTradeAgain: ; 5345
call Serial_ExchangeBytes
ld a, (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
ld [rIE], a
- ld a, $ff
- call PlaySound
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
jr z, .skipCopyingRandomNumberList ; the list generated by the gameboy clocking the connection is used by both gameboys
@@ -255,14 +253,13 @@ CableClub_DoBattleOrTradeAgain: ; 5345
ld hl, wEnemyMons + (SERIAL_PREAMBLE_BYTE - 1)
dec c
jr nz, .unpatchEnemyMonsLoop
- ld a, wEnemyMonOT % $100
+ ld a, wEnemyMonOT & $ff
ld [wUnusedCF8D], a
ld a, wEnemyMonOT / $100
ld [wUnusedCF8D + 1], a
xor a
ld [wTradeCenterPointerTableIndex], a
- ld a, $ff
- call PlaySound
+ call StopAllMusic
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
ld c, 66
@@ -271,19 +268,27 @@ CableClub_DoBattleOrTradeAgain: ; 5345
cp LINK_STATE_START_BATTLE
ld a, LINK_STATE_TRADING
ld [wLinkState], a
- jr nz, .asm_5506
+ jr nz, .asm_55a0
ld a, LINK_STATE_BATTLING
ld [wLinkState], a
ld a, OPP_SONY1
ld [wCurOpponent], a
call ClearScreen
call Delay3
+ ld b, $9
+ call RunPaletteCommand
ld hl, wOptions
res 7, [hl]
+ ld a, [wLetterPrintingDelayFlags]
+ push af
+ xor a
+ ld [wLetterPrintingDelayFlags], a
predef InitOpponent
+ pop af
+ ld [wLetterPrintingDelayFlags], a
predef HealParty
jp ReturnToCableClubRoom
-.asm_5506
+.asm_55a0
ld c, BANK(Music_GameCorner)
ld a, MUSIC_GAME_CORNER
call PlayMusic
@@ -308,6 +313,9 @@ CallCurrentTradeCenterFunction:
TradeCenter_SelectMon:
call ClearScreen
+ call Delay3
+ ld b, $9
+ call RunPaletteCommand
call LoadTrainerInfoTextBoxTiles
call TradeCenter_DrawPartyLists
call TradeCenter_DrawCancelBox
@@ -338,10 +346,10 @@ TradeCenter_SelectMon:
ld a, 1
ld [wTopMenuItemX], a
.enemyMonMenu_HandleInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
and a
jp z, .getNewInput
@@ -403,10 +411,10 @@ TradeCenter_SelectMon:
lb bc, 6, 1
call ClearScreenArea
.playerMonMenu_HandleInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
and a ; was anything pressed?
jr nz, .playerMonMenu_SomethingPressed
@@ -438,6 +446,7 @@ TradeCenter_SelectMon:
ld a, [wEnemyPartyCount]
dec a
cp b
+ ; continue
jr nc, .notPastLastEnemyMon
; when switching to the enemy mon menu, if the menu selection would be past the last enemy mon, select the last enemy mon
ld [wCurrentMenuItem], a
@@ -465,8 +474,7 @@ TradeCenter_SelectMon:
.displayStatsTradeMenu
push af
coord hl, 0, 14
- ld b, 2
- ld c, 18
+ lb bc, 2, 18
call CableClub_TextBoxBorder
coord hl, 2, 16
ld de, .statsTrade
@@ -601,8 +609,7 @@ TradeCenter_DrawCancelBox:
ld bc, 2 * SCREEN_WIDTH + 9
call FillMemory
coord hl, 0, 15
- ld b, 1
- ld c, 9
+ lb bc, 1, 9
call CableClub_TextBoxBorder
coord hl, 2, 16
ld de, CancelTextString
@@ -624,6 +631,9 @@ TradeCenter_DisplayStats:
ld [wWhichPokemon], a
predef StatusScreen
predef StatusScreen2
+ call Delay3
+ ld b, $9
+ call RunPaletteCommand
call GBPalNormal
call LoadTrainerInfoTextBoxTiles
call TradeCenter_DrawPartyLists
@@ -631,12 +641,10 @@ TradeCenter_DisplayStats:
TradeCenter_DrawPartyLists:
coord hl, 0, 0
- ld b, 6
- ld c, 18
+ lb bc, 6, 18
call CableClub_TextBoxBorder
coord hl, 0, 8
- ld b, 6
- ld c, 18
+ lb bc, 6, 18
call CableClub_TextBoxBorder
coord hl, 5, 0
ld de, wPlayerName
@@ -685,8 +693,7 @@ TradeCenter_Trade:
ld [wMenuWatchMovingOutOfBounds], a
ld [wMenuJoypadPollCount], a
coord hl, 0, 12
- ld b, 4
- ld c, 18
+ lb bc, 4, 18
call CableClub_TextBoxBorder
ld a, [wTradingWhichPlayerMon]
ld hl, wPartySpecies
@@ -727,8 +734,7 @@ TradeCenter_Trade:
ld a, $1
ld [wSerialExchangeNybbleSendData], a
coord hl, 0, 12
- ld b, 4
- ld c, 18
+ lb bc, 4, 18
call CableClub_TextBoxBorder
coord hl, 1, 14
ld de, TradeCanceled
@@ -744,8 +750,7 @@ TradeCenter_Trade:
jr nz, .doTrade
; if the other person cancelled
coord hl, 0, 12
- ld b, 4
- ld c, 18
+ lb bc, 4, 18
call CableClub_TextBoxBorder
coord hl, 1, 14
ld de, TradeCanceled
@@ -792,6 +797,7 @@ TradeCenter_Trade:
add hl, bc
ld a, [hl]
ld [wTradedPlayerMonSpecies], a
+ callabd_ModifyPikachuHappiness PIKAHAPPY_TRADE
xor a
ld [wRemoveMonFromBox], a
call RemovePokemon
@@ -845,15 +851,18 @@ TradeCenter_Trade:
.usingExternalClock
predef ExternalClockTradeAnim
.tradeCompleted
+; continue
callab TryEvolvingMon
call ClearScreen
call LoadTrainerInfoTextBoxTiles
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
ld c, 40
call DelayFrames
+ call Delay3
+ ld b, $9
+ call RunPaletteCommand
coord hl, 0, 12
- ld b, 4
- ld c, 18
+ lb bc, 4, 18
call CableClub_TextBoxBorder
coord hl, 1, 14
ld de, TradeCompleted
@@ -900,16 +909,16 @@ CableClub_Run:
call CableClub_DoBattleOrTrade
ld hl, Club_GFX
ld a, h
- ld [wTileSetGFXPtr + 1], a
+ ld [wTilesetGFXPtr + 1], a
ld a, l
- ld [wTileSetGFXPtr], a
+ ld [wTilesetGFXPtr], a
ld a, Bank(Club_GFX)
- ld [wTileSetBank], a
+ ld [wTilesetBank], a
ld hl, Club_Coll
ld a, h
- ld [wTileSetCollisionPtr + 1], a
+ ld [wTilesetCollisionPtr + 1], a
ld a, l
- ld [wTileSetCollisionPtr], a
+ ld [wTilesetCollisionPtr], a
xor a
ld [wGrassRate], a
inc a ; LINK_STATE_IN_CABLE_CLUB
@@ -964,8 +973,14 @@ CableClub_TextBoxBorder:
; c = width
CableClub_DrawHorizontalLine:
ld d, c
-.asm_5ae1
+.drawHorizontalLineLoop
ld [hli], a
dec d
- jr nz, .asm_5ae1
+ jr nz, .drawHorizontalLineLoop
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 b47cd6c4..ab2a6aa8 100755
--- a/engine/clear_save.asm
+++ b/engine/clear_save.asm
@@ -1,10 +1,12 @@
-DoClearSaveDialogue:
+DoClearSaveDialogue: ; DoClearSaveDialogue:
call ClearScreen
call RunDefaultPaletteCommand
call LoadFontTilePatterns
call LoadTextBoxTilePatterns
ld hl, ClearSaveDataText
call PrintText
+ ld a, B_BUTTON
+ ld [wJoyIgnore], a
coord hl, 14, 7
lb bc, 8, 15
ld a, NO_YES_MENU
@@ -12,6 +14,8 @@ DoClearSaveDialogue:
ld a, TWO_OPTION_MENU
ld [wTextBoxID], a
call DisplayTextBoxID
+ ld a, 0
+ ld [wJoyIgnore], a
ld a, [wCurrentMenuItem]
and a
jp z, Init
diff --git a/engine/debug1.asm b/engine/debug1.asm
new file mode 100644
index 00000000..a39e8cac
--- /dev/null
+++ b/engine/debug1.asm
@@ -0,0 +1,24 @@
+; not IshiharaTeam
+SetDebugTeam:
+ ld de, DebugTeam
+.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
+
+DebugTeam:
+ db SNORLAX,80
+ db PERSIAN,80
+ db JIGGLYPUFF,15
+ db PIKACHU,5
+ db $FF
+
+EmptyFunc:
+ ret
diff --git a/engine/diploma_3a.asm b/engine/diploma_3a.asm
new file mode 100755
index 00000000..3b633a1b
--- /dev/null
+++ b/engine/diploma_3a.asm
@@ -0,0 +1,167 @@
+_DisplayDiploma:
+ call GBPalWhiteOutWithDelay3
+ call ClearScreen
+ ld de, SurfingPikachu3Graphics
+ ld hl, vChars2
+ lb bc, BANK(SurfingPikachu3Graphics), (SurfingPikachu3GraphicsEnd - SurfingPikachu3Graphics) / $10
+ call CopyVideoData
+
+ coord hl, 0, 0
+ call Func_e9bdf
+
+ coord hl, 0, 0
+ call Func_e9beb
+
+ coord hl, 19, 0
+ call Func_e9beb
+
+ ld a, $00
+ coord hl, 0, 0
+ ld [hl], a
+ coord hl, 19, 0
+ ld [hl], a
+
+ ld de, String_e9a73
+ coord hl, 5, 2
+ call PlaceString
+
+ ld de, String_e9a7d
+ coord hl, 3, 4
+ call PlaceString
+
+ ld de, wPlayerName
+ coord hl, 10, 4
+ call PlaceString
+
+ ld de, String_e9a84
+ coord hl, 2, 6
+ call PlaceString
+
+ ld de, String_e9ac8
+ coord hl, 9, 16
+ call PlaceString
+
+ ld b, SET_PAL_GENERIC
+ call RunPaletteCommand
+ ld a, $01
+ ld [$ffba], a
+ call Delay3
+ call GBPalNormal
+ ret
+
+; e9a73
+String_e9a73:
+ db $10, "Diploma", $10, "@"
+
+String_e9a7d:
+ db "Player@"
+
+String_e9a84:
+ db "Congrats! This"
+ next "diploma certifies"
+ next "that you have"
+ next "completed your"
+ next "#DEX.@"
+
+String_e9ac8:
+ db "GAME FREAK@"
+
+Func_e9ad3:
+ call ClearScreen
+ coord hl, 0, 17
+ call Func_e9bdf
+ coord hl, 0, 0
+ call Func_e9beb
+ coord hl, 19, 0
+ call Func_e9beb
+ ld a, $00
+ coord hl, 0, 17
+ ld [hl], a
+ coord hl, 19, 17
+ ld [hl], a
+ ld de, Tilemap_e9b3e
+ coord hl, 6, 2
+ lb bc, 10, 12
+ call Diploma_Surfing_CopyBox
+ ld de, Tilemap_e9bb6
+ coord hl, 5, 13
+ lb bc, 1, 11
+ call Diploma_Surfing_CopyBox
+ ld de, String_e9bd5
+ coord hl, 2, 15
+ call PlaceString
+ coord hl, 12, 15
+ ld de, wPlayTimeHours
+ lb bc, $40 | 1, 3
+ call PrintNumber
+ ld [hl], $16
+ inc hl
+ ld de, wPlayTimeMinutes
+ lb bc, $80 | 1, 2
+ call PrintNumber
+ ld a, [wNumSetBits]
+ cp 151
+ ret nz
+ ld de, TileMap_e9bc1
+ coord hl, 2, 0
+ lb bc, 4, 5
+ call Diploma_Surfing_CopyBox
+ ret
+
+Tilemap_e9b3e:
+ db $7f, $7f, $7f, $1a, $1b, $7f, $7f, $7f, $7f, $7f
+ db $7f, $7f, $7f, $7f, $7f, $1c, $1d, $1e, $1f, $20
+ db $7f, $21, $22, $23, $7f, $24, $25, $26, $27, $28
+ db $29, $2a, $2b, $2c, $2d, $2e, $2f, $30, $31, $32
+ db $33, $34, $35, $36, $37, $38, $39, $3a, $3b, $3c
+ db $7f, $3d, $3e, $3f, $40, $41, $42, $43, $29, $44
+ db $45, $46, $47, $48, $49, $4a, $4b, $29, $29, $4c
+ db $4d, $4e, $4f, $50, $51, $52, $53, $54, $55, $56
+ db $57, $58, $59, $7f, $7f, $7f, $5a, $5b, $5c, $5d
+ db $5e, $5f, $60, $61, $62, $7f, $7f, $7f, $7f, $63
+ db $64, $65, $66, $67, $68, $7f, $7f, $7f, $7f, $7f
+ db $7f, $69, $6a, $6b, $6c, $6d, $6e, $7f, $7f, $7f
+
+Tilemap_e9bb6:
+ db $05
+ db $06
+ db $07
+ db $08
+ db $09
+ db $0a
+ db $0b
+ db $0c
+ db $0d
+ db $0e
+ db $0f
+
+TileMap_e9bc1:
+ db $70, $71, $7f, $72, $7f
+ db $73, $74, $75, $76, $77
+ db $7f, $78, $11, $12, $13
+ db $7f, $7f, $14, $15, $7f
+
+String_e9bd5: db "PLAY TIME@"
+
+Func_e9bdf:
+ ld c, 10
+.asm_e9be1
+ ld [hl], $02
+ inc hl
+ ld [hl], $01
+ inc hl
+ dec c
+ jr nz, .asm_e9be1
+ ret
+
+Func_e9beb:
+ ld c, 9
+ ld de, SCREEN_WIDTH
+.asm_e9bed
+ ld [hl], $04
+ add hl, de
+ ld [hl], $03
+ add hl, de
+ dec c
+ jr nz, .asm_e9bed
+ 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/draw_badges.asm b/engine/draw_badges.asm
new file mode 100644
index 00000000..412197b2
--- /dev/null
+++ b/engine/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 ; e8c9 (3:68c9)
+; 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/evolution.asm b/engine/evolution.asm
index c0a3434a..9cefff27 100755
--- a/engine/evolution.asm
+++ b/engine/evolution.asm
@@ -9,9 +9,7 @@ EvolveMon:
xor a
ld [wLowHealthAlarm], a
ld [wChannelSoundIDs + CH4], a
- dec a
- ld [wNewSoundID], a
- call PlaySound
+ call StopAllMusic
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld a, SFX_TINK
@@ -67,9 +65,7 @@ EvolveMon:
ld a, [wEvoNewSpecies]
.done
ld [wWholeScreenPaletteMonSpecies], a
- ld a, $ff
- ld [wNewSoundID], a
- call PlaySound
+ call StopAllMusic
ld a, [wWholeScreenPaletteMonSpecies]
call PlayCry
ld c, 0
diff --git a/engine/evolve_trade.asm b/engine/evolve_trade.asm
deleted file mode 100755
index e17fc05c..00000000
--- a/engine/evolve_trade.asm
+++ /dev/null
@@ -1,44 +0,0 @@
-EvolveTradeMon:
-; Verify the TradeMon's species name before
-; attempting to initiate a trade evolution.
-
-; The names of the trade evolutions in Blue (JP)
-; are checked. In that version, TradeMons that
-; can evolve are Graveler and Haunter.
-
-; In localization, this check was translated
-; before monster names were finalized.
-; Then, Haunter's name was "Spectre".
-; Since its name no longer starts with
-; "SP", it is prevented from evolving.
-
-; This may have been why Red/Green's trades
-; were used instead, where none can evolve.
-
-; This was fixed in Yellow.
-
- ld a, [wInGameTradeReceiveMonName]
-
- ; GRAVELER
- cp "G"
- jr z, .ok
-
- ; "SPECTRE" (HAUNTER)
- cp "S"
- ret nz
- ld a, [wInGameTradeReceiveMonName + 1]
- cp "P"
- ret nz
-
-.ok
- ld a, [wPartyCount]
- dec a
- ld [wWhichPokemon], a
- ld a, $1
- ld [wForceEvolution], a
- ld a, LINK_STATE_TRADING
- ld [wLinkState], a
- callab TryEvolvingMon
- xor a ; LINK_STATE_NONE
- ld [wLinkState], a
- jp PlayDefaultMusic
diff --git a/engine/evos_moves.asm b/engine/evos_moves.asm
index f50f8081..78ead030 100755
--- a/engine/evos_moves.asm
+++ b/engine/evos_moves.asm
@@ -1,5 +1,6 @@
; try to evolve the mon in [wWhichPokemon]
TryEvolvingMon:
+EvolveTradeMon:
ld hl, wCanEvolveFlags
xor a
ld [hl], a
@@ -23,7 +24,8 @@ EvolutionAfterBattle:
ld hl, wPartyCount
push hl
-Evolution_PartyMonLoop: ; loop over party mons
+Evolution_PartyMonLoop:
+; loop over party mons
ld hl, wWhichPokemon
inc [hl]
pop hl
@@ -93,9 +95,13 @@ Evolution_PartyMonLoop: ; loop over party mons
jp c, Evolution_PartyMonLoop ; if so, go the next mon
jr .doEvolution
.checkItemEvo
+ ld a, [wIsInBattle] ; are we in battle?
+ and a
ld a, [hli]
+ jp nz, .nextEvoEntry1 ; don't evolve if we're in a battle as wcf91 could be holding the last mon sent out
+
ld b, a ; evolution item
- ld a, [wcf91] ; this is supposed to be the last item used, but it is also used to hold species numbers
+ ld a, [wcf91] ; last item used
cp b ; was the evolution item in this entry used?
jp nz, .nextEvoEntry1 ; if not, go to the next evolution entry
.checkLevel
@@ -140,7 +146,7 @@ Evolution_PartyMonLoop: ; loop over party mons
ld [wEvoNewSpecies], a
ld a, MONSTER_NAME
ld [wNameListType], a
- ld a, BANK(TrainerNames) ; bank is not used for monster names
+ ld a, BANK(MonsterNames) ; bank is not used for monster names
ld [wPredefBank], a
call GetName
push hl
@@ -307,7 +313,7 @@ StoppedEvolvingText:
TX_FAR _StoppedEvolvingText
db "@"
-IsEvolvingText:
+IsEvolvingText: ; 3affe (e:6ffes)
TX_FAR _IsEvolvingText
db "@"
@@ -318,23 +324,9 @@ Evolution_ReloadTilesetTilePatterns:
jp ReloadTilesetTilePatterns
LearnMoveFromLevelUp:
- ld hl, EvosMovesPointerTable
ld a, [wd11e] ; species
ld [wcf91], a
- dec a
- ld bc, 0
- ld hl, EvosMovesPointerTable
- add a
- rl b
- ld c, a
- add hl, bc
- ld a, [hli]
- ld h, [hl]
- ld l, a
-.skipEvolutionDataLoop ; loop to skip past the evolution data, which comes before the move data
- ld a, [hli]
- and a ; have we reached the end of the evolution data?
- jr nz, .skipEvolutionDataLoop ; if not, jump back up
+ call GetMonLearnset
.learnSetLoop ; loop over the learn set until we reach a move that is learnt at the current level or the end of the list
ld a, [hli]
and a ; have we reached the end of the learn set?
@@ -370,33 +362,180 @@ LearnMoveFromLevelUp:
call GetMoveName
call CopyStringToCF4B
predef LearnMove
+ ld a, b
+ and a
+ jr z, .done
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .done
+ ld a, [wMoveNum]
+ cp THUNDERBOLT
+ jr z, .foundThunderOrThunderbolt
+ cp THUNDER
+ jr nz, .done
+.foundThunderOrThunderbolt
+ ld a, $5
+ ld [wd49c], a
+ ld a, $85
+ ld [wPikachuMood], a
.done
ld a, [wcf91]
ld [wd11e], a
ret
-; 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
-WriteMonMoves:
- call GetPredefRegisters
- push hl
- push de
- push bc
+Func_3b079:
+ ld a, [wcf91]
+ push af
+ call Func_3b0a2
+ jr c, .asm_3b09c
+
+ call Func_3b10f
+ jr nc, .asm_3b096
+
+ call Func_3b0a2
+ jr c, .asm_3b09c
+
+ call Func_3b10f
+ jr nc, .asm_3b096
+
+ call Func_3b0a2
+ jr c, .asm_3b09c
+.asm_3b096
+ pop af
+ ld [wcf91], a
+ and a
+ ret
+.asm_3b09c
+ pop af
+ ld [wcf91], a
+ scf
+ ret
+
+Func_3b0a2:
+; XXX what is wcf91 entering this function?
+ ld a, [wd11e]
+ ld [wMoveNum], a
+ predef CanLearnTM
+ ld a, c
+ and a
+ jr nz, .asm_3b0ec
+ ld hl, Pointer_3b0ee
+ ld a, [wcf91]
+ ld de, $1
+ call IsInArray
+ jr c, .asm_3b0d2
+ ld a, $ff
+ ld [wMonHGrowthRate], a
+ ld a, [wd11e]
+ ld hl, wMonHMoves
+ ld de, $1
+ call IsInArray
+ jr c, .asm_3b0ec
+.asm_3b0d2
+ ld a, [wd11e]
+ ld d, a
+ call GetMonLearnset
+.loop
+ ld a, [hli]
+ and a
+ jr z, .asm_3b0ea
+ ld b, a
+ ld a, [wCurEnemyLVL]
+ cp b
+ jr c, .asm_3b0ea
+ ld a, [hli]
+ cp d
+ jr z, .asm_3b0ec
+ jr .loop
+.asm_3b0ea
+ and a
+ ret
+.asm_3b0ec
+ scf
+ ret
+
+Pointer_3b0ee:
+ db NIDOKING
+ db IVYSAUR
+ db EXEGGUTOR
+ db GENGAR
+ db NIDOQUEEN
+ db ARCANINE
+ db GYARADOS
+ db BLASTOISE
+ db GOLEM
+ db DRAGONITE
+ db NINETALES
+ db DRAGONAIR
+ db KABUTOPS
+ db OMASTAR
+ db JIGGLYPUFF
+ db FLAREON
+ db JOLTEON
+ db VAPOREON
+ db BEEDRILL
+ db BUTTERFREE
+ db MACHAMP
+ db CLOYSTER
+ db CLEFABLE
+ db ALAKAZAM
+ db STARMIE
+ db VENUSAUR
+ db TENTACRUEL
+ db CHARMELEON
+ db WARTORTLE
+ db CHARIZARD
+ db VILEPLUME
+ db VICTREEBEL
+ db $ff
+
+Func_3b10f:
+ ld c, $0
+.asm_3b111
ld hl, EvosMovesPointerTable
- ld b, 0
- ld a, [wcf91] ; cur mon ID
- dec a
- add a
- rl b
- ld c, a
+ ld b, $0
+ add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
-.skipEvoEntriesLoop
+.asm_3b11b
ld a, [hli]
and a
- jr nz, .skipEvoEntriesLoop
+ jr z, .asm_3b130
+ cp $2
+ jr nz, .asm_3b124
+ inc hl
+.asm_3b124
+ inc hl
+ ld a, [wcf91]
+ cp [hl]
+ jr z, .asm_3b138
+ inc hl
+ ld a, [hl]
+ and a
+ jr nz, .asm_3b11b
+.asm_3b130
+ inc c
+ ld a, c
+ cp VICTREEBEL
+ jr c, .asm_3b111
+ and a
+ ret
+.asm_3b138
+ inc c
+ ld a, c
+ ld [wcf91], a
+ scf
+ ret
+
+; 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
+WriteMonMoves:
+ call GetPredefRegisters
+ push hl
+ push de
+ push bc
+ call GetMonLearnset
jr .firstMove
.nextMove
pop de
@@ -510,4 +649,21 @@ WriteMonMoves_ShiftMoveData:
Evolution_FlagAction:
predef_jump FlagActionPredef
+GetMonLearnset:
+ ld hl, EvosMovesPointerTable
+ ld b, 0
+ ld a, [wcf91]
+ dec a
+ ld c, a
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+.skipEvolutionDataLoop ; loop to skip past the evolution data, which comes before the move data
+ ld a, [hli]
+ and a ; have we reached the end of the evolution data?
+ jr nz, .skipEvolutionDataLoop ; if not, jump back up
+ ret
+
INCLUDE "data/evos_moves.asm"
diff --git a/engine/flag_action_predef.asm b/engine/flag_action_predef.asm
new file mode 100644
index 00000000..dc516887
--- /dev/null
+++ b/engine/flag_action_predef.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/gamefreak.asm b/engine/gamefreak.asm
index 69c059ff..6545e216 100755
--- a/engine/gamefreak.asm
+++ b/engine/gamefreak.asm
@@ -2,12 +2,14 @@ LoadShootingStarGraphics:
ld a, $f9
ld [rOBP0], a
ld a, $a4
- ld [rOBP1], a
- ld de, AnimationTileset2 + $30 ; star tile (top left quadrant)
+ ld [rOBP1], a ; $ff49
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ld de, AnimationTileset2 + $30 ; $4757 ; star tile (top left quadrant)
ld hl, vChars1 + $200
lb bc, BANK(AnimationTileset2), $01
call CopyVideoData
- ld de, AnimationTileset2 + $130 ; star tile (bottom left quadrant)
+ ld de, AnimationTileset2 + $130 ; $481e ; star tile (bottom left quadrant)
ld hl, vChars1 + $210
lb bc, BANK(AnimationTileset2), $01
call CopyVideoData
@@ -37,7 +39,7 @@ AnimateShootingStar:
push bc
.bigStarInnerLoop
ld a, [hl] ; Y
- add 4
+ add 4 ; y
ld [hli], a
ld a, [hl] ; X
add -4
@@ -58,11 +60,11 @@ AnimateShootingStar:
.next
cp b
jr nz, .bigStarLoop
-
-; Clear big star OAM.
ld hl, wOAMBuffer
ld c, 4
ld de, 4
+
+; Clear big star OAM.
.clearOAMLoop
ld [hl], 160
add hl, de
@@ -72,22 +74,22 @@ AnimateShootingStar:
; Make Gamefreak logo flash.
ld b, 3
.flashLogoLoop
- ld hl, rOBP0
+ ld hl, rOBP0 ; $ff48
rrc [hl]
rrc [hl]
+ call UpdateGBCPal_OBP0
ld c, 10
call CheckForUserInterruption
ret c
dec b
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, 24
.initSmallStarsOAMLoop
push af
- ld hl, SmallStarsOAM
+ ld hl, SmallStarsOAM ; $40ee
ld bc, SmallStarsOAMEnd - SmallStarsOAM
call CopyData
pop af
@@ -96,8 +98,8 @@ AnimateShootingStar:
; Animate the small stars falling from the Gamefreak logo.
xor a
- ld [wMoveDownSmallStarsOAMCount], a
- ld hl, SmallStarsWaveCoordsPointerTable
+ ld [wMoveDownSmallStarsOAMCount], a ; wWhichTrade
+ ld hl, SmallStarsWaveCoordsPointerTable ; 1c:4105
ld c, 6
.smallStarsLoop
ld a, [hli]
@@ -118,6 +120,15 @@ AnimateShootingStar:
ld [hli], a ; X
inc de
inc hl
+ push bc
+ ld a, [de]
+ ld b,a
+ ld a, [hl]
+ and $f0
+ or b
+ ld [hl], a
+ inc de
+ pop bc
inc hl
dec c
jr nz, .smallStarsInnerLoop
@@ -162,27 +173,35 @@ SmallStarsWaveCoordsPointerTable:
SmallStarsWave1Coords:
db $68,$30
- db $68,$40
+ db $05,$68
+ db $40,$05
db $68,$58
- db $68,$78
+ db $04,$68
+ db $78,$07
SmallStarsWave2Coords:
db $68,$38
- db $68,$48
+ db $05,$68
+ db $48,$06
db $68,$60
- db $68,$70
+ db $04,$68
+ db $70,$07
SmallStarsWave3Coords:
db $68,$34
- db $68,$4C
+ db $05,$68
+ db $4c,$06
db $68,$54
- db $68,$64
+ db $06,$68
+ db $64,$07
SmallStarsWave4Coords:
- db $68,$3C
- db $68,$5C
- db $68,$6C
- db $68,$74
+ db $68,$3c
+ db $05,$68
+ db $5c,$04
+ db $68,$6c
+ db $07,$68
+ db $74,$07
SmallStarsEmptyWave:
db $FF
@@ -195,17 +214,16 @@ MoveDownSmallStars:
ld de, -4
ld c, a
.innerLoop
- inc [hl] ; Y
+ inc [hl]
add hl, de
dec c
jr nz, .innerLoop
-
; Toggle the palette so that the lower star in the small stars tile blinks in
; and out.
- ld a, [rOBP1]
+ ld a, [rOBP1] ; $ff49
xor %10100000
- ld [rOBP1], a
-
+ ld [rOBP1], a ; $ff49
+ call UpdateGBCPal_OBP1
ld c, 3
call CheckForUserInterruption
ret c
@@ -233,10 +251,10 @@ GameFreakLogoOAMData:
GameFreakLogoOAMDataEnd:
GameFreakShootingStarOAMData:
- db $00,$A0,$A0,$10
- db $00,$A8,$A0,$30
- db $08,$A0,$A1,$10
- db $08,$A8,$A1,$30
+ db $00,$A0,$A0,$14
+ db $00,$A8,$A0,$34
+ db $08,$A0,$A1,$14
+ db $08,$A8,$A1,$34
GameFreakShootingStarOAMDataEnd:
FallingStar:
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 549a042d..9cbb4039 100755
--- a/engine/give_pokemon.asm
+++ b/engine/give_pokemon.asm
@@ -44,6 +44,8 @@ _GivePokemon:
ret
.addToParty
call SetPokedexOwnedFlag
+ ld hl, UnknownTerminator_f6794
+ call PrintText
call AddPartyMon
ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
@@ -68,6 +70,9 @@ SetPokedexOwnedFlag:
ld hl, GotMonText
jp PrintText
+UnknownTerminator_f6794:
+ db "@"
+
GotMonText:
TX_FAR _GotMonText
db $0b
diff --git a/engine/hall_of_fame.asm b/engine/hall_of_fame.asm
index 0e35f709..59e97892 100755
--- a/engine/hall_of_fame.asm
+++ b/engine/hall_of_fame.asm
@@ -33,8 +33,8 @@ AnimateHallOfFame:
.skipInc
ld a, $90
ld [hWY], a
- ld c, BANK(Music_HallOfFame)
- ld a, MUSIC_HALL_OF_FAME
+ ld c, $1f ; BANK(Music_HallOfFame)
+ ld a, $ca ; MUSIC_HALL_OF_FAME
call PlayMusic
ld hl, wPartySpecies
ld c, $ff
@@ -58,8 +58,7 @@ AnimateHallOfFame:
ld c, 80
call DelayFrames
coord hl, 2, 13
- ld b, $3
- ld c, $e
+ lb bc, $3, $e
call TextBoxBorder
coord hl, 4, 15
ld de, HallOfFameText
@@ -77,7 +76,7 @@ AnimateHallOfFame:
ld bc, HOF_MON
call AddNTimes
ld [hl], $ff
- call SaveHallOfFameTeams
+ callab SaveHallOfFameTeams ; useless since in same bank
xor a
ld [wHoFMonSpecies], a
inc a
@@ -122,6 +121,7 @@ HoFShowMonOrPlayer:
call RunPaletteCommand
ld a, %11100100
ld [rBGP], a
+ call UpdateGBCPal_BGP
ld c, $31 ; back pic
call HoFLoadMonPlayerPicTileIDs
ld d, $a0
@@ -151,15 +151,30 @@ HoFShowMonOrPlayer:
HoFDisplayAndRecordMonInfo:
ld a, [wHoFPartyMonIndex]
- ld hl, wPartyMonNicks
+ ld hl, wPartyMonNicks ; wPartyMonNicks
call GetPartyMonName
call HoFDisplayMonInfo
+ ld a, [wHoFPartyMonIndex]
+ ld [wWhichPokemon], a
+ callab IsThisPartymonStarterPikachu_Party ; 3f:4e18
+ jr nc, .asm_70336
+ ld e, $22
+ callab PlayPikachuSoundClip
+ jr .asm_7033c
+.asm_70336
+ ld a,[wHoFMonSpecies]
+ call PlayCry
+.asm_7033c
jp HoFRecordMonInfo
+Func_7033f:
+ call HoFDisplayMonInfo
+ ld a,[wHoFMonSpecies]
+ jp PlayCry
+
HoFDisplayMonInfo:
coord hl, 0, 2
- ld b, 9
- ld c, 10
+ lb bc, 9, 10
call TextBoxBorder
coord hl, 2, 6
ld de, HoFMonInfoText
@@ -174,8 +189,7 @@ HoFDisplayMonInfo:
ld [wd0b5], a
coord hl, 3, 9
predef PrintMonType
- ld a, [wHoFMonSpecies]
- jp PlayCry
+ ret
HoFMonInfoText:
db "LEVEL/"
@@ -183,13 +197,16 @@ HoFMonInfoText:
next "TYPE2/@"
HoFLoadPlayerPics:
- ld de, RedPicFront
+ ld de, RedPicFront ; $6ede
ld a, BANK(RedPicFront)
call UncompressSpriteFromDE
+ ld a,$0
+ call SwitchSRAMBankAndLatchClockData
ld hl, sSpriteBuffer1
ld de, sSpriteBuffer0
ld bc, $310
call CopyData
+ call PrepareRTCDataAndDisableSRAM
ld de, vFrontPic
call InterlaceMergeSpriteBuffers
ld de, RedPicBack
@@ -201,8 +218,7 @@ HoFLoadPlayerPics:
ld c, $1
HoFLoadMonPlayerPicTileIDs:
-; c = base tile ID
- ld b, 0
+ ld b, $0
coord hl, 12, 5
predef_jump CopyTileIDsFromList
@@ -210,12 +226,10 @@ HoFDisplayPlayerStats:
SetEvent EVENT_HALL_OF_FAME_DEX_RATING
predef DisplayDexRating
coord hl, 0, 4
- ld b, $6
- ld c, $a
+ lb bc, 6, 10
call TextBoxBorder
coord hl, 5, 0
- ld b, $2
- ld c, $9
+ lb bc, 2, 9
call TextBoxBorder
coord hl, 7, 2
ld de, wPlayerName
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 7591fac0..2781e182 100755
--- a/engine/hidden_object_functions14.asm
+++ b/engine/hidden_object_functions14.asm
@@ -66,18 +66,18 @@ ViridianSchoolNotebookText4:
PrintFightingDojoText2:
call EnableAutoTextBoxDrawing
- tx_pre_jump FightingDojoText_52a10
+ tx_pre_jump EnemiesOnEverySideText
-FightingDojoText_52a10:
- TX_FAR _FightingDojoText_52a10
+EnemiesOnEverySideText:
+ TX_FAR _EnemiesOnEverySideText
db "@"
PrintFightingDojoText3:
call EnableAutoTextBoxDrawing
- tx_pre_jump FightingDojoText_52a1d
+ tx_pre_jump WhatGoesAroundComesAroundText
-FightingDojoText_52a1d:
- TX_FAR _FightingDojoText_52a1d
+WhatGoesAroundComesAroundText:
+ TX_FAR _WhatGoesAroundComesAroundText
db "@"
PrintFightingDojoText:
@@ -89,7 +89,7 @@ FightingDojoText:
db "@"
PrintIndigoPlateauHQText:
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
diff --git a/engine/hidden_object_functions17.asm b/engine/hidden_object_functions17.asm
index dee5efea..a6044d94 100755
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -14,7 +14,7 @@ RedBedroomPCText:
TX_PLAYERS_PC
Route15GateLeftBinoculars:
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
@@ -22,7 +22,10 @@ Route15GateLeftBinoculars:
ld a, ARTICUNO
ld [wcf91], a
call PlayCry
- jp DisplayMonFrontSpriteInBox
+ call DisplayMonFrontSpriteInBox
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ret
Route15UpstairsBinocularsText:
TX_FAR _Route15UpstairsBinocularsText
@@ -52,6 +55,30 @@ KabutopsFossilText:
TX_FAR _KabutopsFossilText
db "@"
+FanClubPicture1:
+ ld a, RAPIDASH
+ ld [wcf91], a
+ call DisplayMonFrontSpriteInBox
+ call EnableAutoTextBoxDrawing
+ tx_pre FanClubPicture1Text
+ ret
+
+FanClubPicture1Text:
+ TX_FAR _FanClubPicture1Text
+ db "@"
+
+FanClubPicture2:
+ ld a, FEAROW
+ ld [wcf91], a
+ call DisplayMonFrontSpriteInBox
+ call EnableAutoTextBoxDrawing
+ tx_pre FanClubPicture2Text
+ ret
+
+FanClubPicture2Text:
+ TX_FAR _FanClubPicture2Text
+ db "@"
+
DisplayMonFrontSpriteInBox:
; Displays a pokemon's front sprite in a pop-up window.
; [wcf91] = pokemon interal id number
@@ -95,23 +122,22 @@ LinkCableHelp:
ld hl, LinkCableHelpText1
call PrintText
xor a
- ld [wMenuItemOffset], a ; not used
+ ld [wMenuItemOffset], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
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
.linkHelpLoop
ld hl, wd730
set 6, [hl]
coord hl, 0, 0
- ld b, 8
- ld c, 13
+ lb bc, $8, $d
call TextBoxBorder
coord hl, 2, 2
ld de, HowToLinkText
@@ -122,13 +148,13 @@ LinkCableHelp:
bit 1, a ; pressed b
jr nz, .exit
ld a, [wCurrentMenuItem]
- cp 3 ; pressed a on "STOP READING"
+ 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]
@@ -184,11 +210,11 @@ ViridianSchoolBlackboard:
ld [wLastMenuItem], a
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
.blackboardLoop
ld hl, wd730
@@ -210,24 +236,24 @@ ViridianSchoolBlackboard:
bit 4, a ; pressed right
jr z, .didNotPressRight
; move cursor to right column
- ld a, 2
+ 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 ; in the the right column, use an offset to prevent overlap
+ 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 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 [wMenuItemOffset], a
@@ -235,9 +261,9 @@ ViridianSchoolBlackboard:
.didNotPressLeftOrRight
ld a, [wCurrentMenuItem]
ld b, a
- ld a, [wMenuItemOffset]
+ ld a, [wAnimationID]
add b
- cp 5 ; cursor is pointing to "QUIT"
+ cp $5 ; cursor is pointing to "QUIT"
jr z, .exitBlackboard
; we must have pressed a on a status condition
; so print the text
@@ -245,7 +271,7 @@ ViridianSchoolBlackboard:
res 6, [hl]
ld hl, ViridianBlackboardStatusPointers
add a
- ld d, 0
+ ld d, $0
ld e, a
add hl, de
ld a, [hli]
@@ -339,53 +365,17 @@ GymTrashScript:
.openFirstLock
; Next can is trying for the second switch.
SetEvent EVENT_1ST_LOCK_OPENED
-
- ld hl, GymTrashCans
- ld a, [wGymTrashCanIndex]
- ; * 5
- ld b, a
- add a
- add a
- add b
-
- ld d, 0
- ld e, a
- add hl, de
- ld a, [hli]
-
-; 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, [hGymTrashCanRandNumMask]
- and b
- dec a
- pop hl
-
- ld d, 0
- ld e, a
- add hl, de
- ld a, [hl]
- and $f
- ld [wSecondLockTrashCanIndex], a
-
+ callab Yellow_SampleSecondTrashCan
tx_pre_id VermilionGymTrashSuccessText1
jr .done
.trySecondLock
- ld a, [wSecondLockTrashCanIndex]
- ld b, a
ld a, [wGymTrashCanIndex]
+ ld b, a
+ ld a, [wSecondLockTrashCanIndex]
+ cp b
+ jr z, .openSecondLock
+ ld a, [wSecondLockTrashCanIndex + 1]
cp b
jr z, .openSecondLock
@@ -413,25 +403,26 @@ GymTrashScript:
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
+; follow. The remaining bytes are filled with -1 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
- db 3, 0, 4, 6, 0 ; 3
+; This is functionally replaced with GymTrashCans3a but was never removed from source.
+
+ db 2, 1, 3, -1, -1 ; 0
+ db 3, 0, 2, 4, -1 ; 1
+ db 2, 1, 5, -1, -1 ; 2
+ db 3, 0, 4, 6, -1 ; 3
db 4, 1, 3, 5, 7 ; 4
- db 3, 2, 4, 8, 0 ; 5
- db 3, 3, 7, 9, 0 ; 6
+ db 3, 2, 4, 8, -1 ; 5
+ db 3, 3, 7, 9, -1 ; 6
db 4, 4, 6, 8, 10 ; 7
- db 3, 5, 7, 11, 0 ; 8
- db 3, 6, 10, 12, 0 ; 9
+ db 3, 5, 7, 11, -1 ; 8
+ db 3, 6, 10, 12, -1 ; 9
db 4, 7, 9, 11, 13 ; 10
- db 3, 8, 10, 14, 0 ; 11
- db 2, 9, 13, 0, 0 ; 12
- db 3, 10, 12, 14, 0 ; 13
- db 2, 11, 13, 0, 0 ; 14
+ db 3, 8, 10, 14, -1 ; 11
+ db 2, 9, 13, -1, -1 ; 12
+ db 3, 10, 12, 14, -1 ; 13
+ db 2, 11, 13, -1, -1 ; 14
; 5dec8
VermilionGymTrashSuccessText1:
diff --git a/engine/hidden_object_functions18.asm b/engine/hidden_object_functions18.asm
index 6ce582ed..f96f0e3a 100755
--- a/engine/hidden_object_functions18.asm
+++ b/engine/hidden_object_functions18.asm
@@ -3,7 +3,7 @@ GymStatues:
; 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]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
ld hl, .BadgeFlags
@@ -29,14 +29,14 @@ GymStatues:
jp PrintPredefTextID
.BadgeFlags:
- db PEWTER_GYM, %00000001
- db CERULEAN_GYM, %00000010
- db VERMILION_GYM,%00000100
- db CELADON_GYM, %00001000
- db FUCHSIA_GYM, %00010000
- db SAFFRON_GYM, %00100000
- db CINNABAR_GYM, %01000000
- db VIRIDIAN_GYM, %10000000
+ db PEWTER_GYM, %00000001
+ db CERULEAN_GYM, %00000010
+ db VERMILION_GYM, %00000100
+ db CELADON_GYM, %00001000
+ db FUCHSIA_GYM, %00010000
+ db SAFFRON_GYM, %00100000
+ db CINNABAR_GYM, %01000000
+ db VIRIDIAN_GYM, %10000000
db $ff
GymStatueText1:
@@ -64,7 +64,7 @@ PrintBenchGuyText:
.match
ld a, [hli]
ld b, a
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp b
jr nz, .loop ; player isn't facing left at the bench guy
ld a, [hl]
@@ -72,30 +72,36 @@ PrintBenchGuyText:
; format: db map id, player sprite facing direction, text id of PredefTextIDPointerTable
BenchGuyTextPointers:
- db VIRIDIAN_POKECENTER, SPRITE_FACING_LEFT
- db (ViridianCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db PEWTER_POKECENTER, SPRITE_FACING_LEFT
- db (PewterCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db CERULEAN_POKECENTER, SPRITE_FACING_LEFT
- db (CeruleanCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db LAVENDER_POKECENTER, SPRITE_FACING_LEFT
- db (LavenderCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db VERMILION_POKECENTER, SPRITE_FACING_LEFT
- db (VermilionCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db CELADON_POKECENTER, SPRITE_FACING_LEFT
- db (CeladonCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db CELADON_HOTEL, SPRITE_FACING_LEFT
- db (CeladonCityHotelText_id - TextPredefs) / 2 + 1
- db FUCHSIA_POKECENTER, SPRITE_FACING_LEFT
- db (FuchsiaCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db CINNABAR_POKECENTER, SPRITE_FACING_LEFT
- db (CinnabarIslandPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db SAFFRON_POKECENTER, SPRITE_FACING_LEFT
- db (SaffronCityPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db MT_MOON_POKECENTER, SPRITE_FACING_LEFT
- db (MtMoonPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
- db ROCK_TUNNEL_POKECENTER,SPRITE_FACING_LEFT
- db (RockTunnelPokecenterBenchGuyText_id - TextPredefs) / 2 + 1
+ 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 SAFARI_ZONE_REST_HOUSE_2,SPRITE_FACING_LEFT
+ db_tx_pre UnusedBenchGuyText1
+ db SAFARI_ZONE_REST_HOUSE_3,SPRITE_FACING_LEFT
+ db_tx_pre UnusedBenchGuyText2
+ db SAFARI_ZONE_REST_HOUSE_4,SPRITE_FACING_LEFT
+ db_tx_pre UnusedBenchGuyText3
db $FF
ViridianCityPokecenterBenchGuyText:
@@ -186,7 +192,7 @@ BookcaseText:
db "@"
OpenPokemonCenterPC:
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP ; check to see if player is facing up
ret nz
call EnableAutoTextBoxDrawing
@@ -195,4 +201,4 @@ OpenPokemonCenterPC:
tx_pre_jump PokemonCenterPCText
PokemonCenterPCText:
- TX_POKECENTER_PC
+ db $F9 ; FuncTX_PokemonCenterPC
diff --git a/engine/hidden_object_functions3.asm b/engine/hidden_object_functions3.asm
index efdbd081..06dc7560 100755
--- a/engine/hidden_object_functions3.asm
+++ b/engine/hidden_object_functions3.asm
@@ -1,6 +1,6 @@
; prints text for bookshelves in buildings without sign events
PrintBookshelfText:
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
cp SPRITE_FACING_UP
jr nz, .noMatch
; facing up
@@ -39,39 +39,39 @@ PrintBookshelfText:
; format: db tileset id, bookshelf tile id, text id
BookshelfTileIDs:
db PLATEAU, $30
- db (IndigoPlateauStatues_id - TextPredefs) / 2 + 1
+ db_tx_pre IndigoPlateauStatues
db HOUSE, $3D
- db (TownMapText_id - TextPredefs) / 2 + 1
+ db_tx_pre TownMapText
db HOUSE, $1E
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db MANSION, $32
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db REDS_HOUSE_1, $32
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db LAB, $28
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db LOBBY, $16
- db (ElevatorText_id - TextPredefs) / 2 + 1
+ db_tx_pre ElevatorText
db GYM, $1D
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db DOJO, $1D
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db GATE, $22
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db MART, $54
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db MART, $55
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db POKECENTER, $54
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db POKECENTER, $55
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db LOBBY, $50
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db LOBBY, $52
- db (PokemonStuffText_id - TextPredefs) / 2 + 1
+ db_tx_pre PokemonStuffText
db SHIP, $36
- db (BookOrSculptureText_id - TextPredefs) / 2 + 1
+ db_tx_pre BookOrSculptureText
db $FF
IndigoPlateauStatues:
@@ -81,9 +81,9 @@ IndigoPlateauStatues:
ld a, [wXCoord]
bit 0, a
ld hl, IndigoPlateauStatuesText2
- jr nz, .asm_fbd3
+ jr nz, .asm_fa61
ld hl, IndigoPlateauStatuesText3
-.asm_fbd3
+.asm_fa61
call PrintText
jp TextScriptEnd
@@ -104,12 +104,12 @@ BookOrSculptureText:
ld hl, PokemonBooksText
ld a, [wCurMapTileset]
cp MANSION ; Celadon Mansion tileset
- jr nz, .asm_fbfd
+ jr nz, .asm_fa8b
aCoord 8, 6
cp $38
- jr nz, .asm_fbfd
+ jr nz, .asm_fa8b
ld hl, DiglettSculptureText
-.asm_fbfd
+.asm_fa8b
call PrintText
jp TextScriptEnd
diff --git a/engine/hidden_object_functions7.asm b/engine/hidden_object_functions7.asm
index 9b1532bc..691d05f2 100755
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -65,15 +65,14 @@ SafariZoneGameOver:
call EnableAutoTextBoxDrawing
xor a
ld [wAudioFadeOutControl], a
- dec a
- call PlaySound
+ call StopAllMusic
ld c, BANK(SFX_Safari_Zone_PA)
ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
-.asm_1e9c2
+.waitForMusicToPlay
ld a, [wChannelSoundIDs + CH4]
- cp $b9
- jr nz, .asm_1e9c2
+ cp SFX_SAFARI_ZONE_PA
+ jr nz, .waitForMusicToPlay
ld a, TEXT_SAFARI_GAME_OVER
ld [hSpriteIndexOrTextID], a
call DisplayTextID
@@ -86,7 +85,7 @@ SafariZoneGameOver:
ld a, $5
ld [wSafariZoneEntranceCurScript], a
SetEvent EVENT_SAFARI_GAME_OVER
- ld a, 1
+ ld a, $1
ld [wSafariZoneGameOver], a
ret
@@ -100,10 +99,10 @@ 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
@@ -117,7 +116,7 @@ GameOverText:
db "@"
PrintCinnabarQuiz:
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
@@ -127,6 +126,8 @@ CinnabarGymQuiz:
TX_ASM
xor a
ld [wOpponentAfterWrongAnswer], a
+ ld hl, wd475
+ res 7, [hl]
ld a, [wHiddenObjectFunctionArgument]
push af
and $f
@@ -135,7 +136,12 @@ CinnabarGymQuiz:
and $f0
swap a
ld [$ffdc], a
+ ld a, [hGymGateIndex]
ld hl, CinnabarGymQuizIntroText
+ cp $1
+ jr z, .onFirstQuestion
+ ld hl, CinnabarGymQuizShortIntroText
+.onFirstQuestion
call PrintText
ld a, [hGymGateIndex]
dec a
@@ -148,15 +154,23 @@ CinnabarGymQuiz:
ld h, [hl]
ld l, a
call PrintText
- ld a, 1
+ ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
call CinnabarGymQuiz_1ea92
jp TextScriptEnd
+CinnabarGymQuizDummyIntroText:
+ TX_FAR _CinnabarGymQuizDummyIntroText
+ db "@"
+
CinnabarGymQuizIntroText:
TX_FAR _CinnabarGymQuizIntroText
db "@"
+CinnabarGymQuizShortIntroText:
+ TX_FAR _CinnabarGymQuizShortIntroText
+ db "@"
+
CinnabarQuizQuestions:
dw CinnabarQuizQuestionsText1
dw CinnabarQuizQuestionsText2
@@ -189,10 +203,6 @@ CinnabarQuizQuestionsText6:
TX_FAR _CinnabarQuizQuestionsText6
db "@"
-CinnabarGymGateFlagAction:
- EventFlagAddress hl, EVENT_CINNABAR_GYM_GATE0_UNLOCKED
- predef_jump FlagActionPredef
-
CinnabarGymQuiz_1ea92:
call YesNoChoice
ld a, [$ffdc]
@@ -232,6 +242,8 @@ CinnabarGymQuiz_1ea92:
ld a, [hGymGateIndex]
add $2
ld [wOpponentAfterWrongAnswer], a
+ ld hl, wd475
+ set 7, [hl]
ret
CinnabarGymQuizCorrectText:
@@ -258,6 +270,10 @@ CinnabarGymQuizIncorrectText:
TX_FAR _CinnabarGymQuizIncorrectText
db "@"
+CinnabarGymGateFlagAction:
+ EventFlagAddress hl, EVENT_CINNABAR_GYM_GATE0_UNLOCKED
+ predef_jump FlagActionPredef
+
UpdateCinnabarGymGateTileBlocks_:
; Update the overworld map with open floor blocks or locked gate blocks
; depending on event flags.
@@ -295,10 +311,11 @@ UpdateCinnabarGymGateTileBlocks_:
.next
pop bc
ld [wNewTileBlockID], a
- predef ReplaceTileBlock
+ call CinnabarGym_ReplaceTileBlock
ld hl, hGymGateIndex
dec [hl]
jr nz, .loop
+ callab RedrawMapView
ret
CinnabarGymGateCoords:
@@ -311,6 +328,34 @@ CinnabarGymGateCoords:
db $02,$06,$54,$00
db $02,$03,$54,$00
+
+CinnabarGym_ReplaceTileBlock:
+; basically a copy of the first half of ReplaceTileBlock
+; before checking if it is necessary to redraw the map view
+ 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
+.addWidthYTimesLoop
+ add hl, de
+ dec b
+ jr nz, .addWidthYTimesLoop
+.addX
+ add hl, bc
+ ld a, [wNewTileBlockID]
+ ld [hl], a
+ ret
+
PrintMagazinesText:
call EnableAutoTextBoxDrawing
tx_pre MagazinesText
@@ -322,18 +367,18 @@ MagazinesText:
BillsHousePC:
call EnableAutoTextBoxDrawing
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
CheckEvent EVENT_LEFT_BILLS_HOUSE_AFTER_HELPING
- jr nz, .asm_1ebd2
+ jr nz, .displayBillsHousePokemonList
CheckEventReuseA EVENT_USED_CELL_SEPARATOR_ON_BILL
- jr nz, .asm_1eb86
+ jr nz, .displayBillsHouseMonitorText
CheckEventReuseA EVENT_BILL_SAID_USE_CELL_SEPARATOR
- jr nz, .asm_1eb8b
-.asm_1eb86
+ jr nz, .doCellSeparator
+.displayBillsHouseMonitorText
tx_pre_jump BillsHouseMonitorText
-.asm_1eb8b
+.doCellSeparator
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
tx_pre BillsHouseInitiatedText
@@ -360,7 +405,7 @@ BillsHousePC:
call PlayDefaultMusic
SetEvent EVENT_USED_CELL_SEPARATOR_ON_BILL
ret
-.asm_1ebd2
+.displayBillsHousePokemonList
ld a, $1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
tx_pre BillsHousePokemonList
@@ -374,9 +419,7 @@ BillsHouseInitiatedText:
TX_FAR _BillsHouseInitiatedText
db $06
TX_ASM
- ld a, $ff
- ld [wNewSoundID], a
- call PlaySound
+ call StopAllMusic
ld c, 16
call DelayFrames
ld a, SFX_SWITCH
@@ -392,23 +435,22 @@ BillsHousePokemonList:
ld hl, BillsHousePokemonListText1
call PrintText
xor a
- ld [wMenuItemOffset], a ; not used
+ ld [wMenuItemOffset], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
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
.billsPokemonLoop
ld hl, wd730
set 6, [hl]
coord hl, 0, 0
- ld b, 10
- ld c, 9
+ lb bc, 10, 9
call TextBoxBorder
coord hl, 2, 2
ld de, BillsMonListText
@@ -456,11 +498,12 @@ BillsHousePokemonListText2:
db "@"
DisplayOakLabEmailText:
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
- tx_pre_jump OakLabEmailText
+ tx_pre OakLabEmailText
+ ret
OakLabEmailText:
TX_FAR _OakLabEmailText
diff --git a/engine/hp_bar.asm b/engine/hp_bar.asm
index 3fa01208..b4abf028 100755
--- a/engine/hp_bar.asm
+++ b/engine/hp_bar.asm
@@ -95,7 +95,7 @@ UpdateHPBar2:
call UpdateHPBar_CalcOldNewHPBarPixels
ld a, e
sub d ; calc pixel difference
- jr .asm_fa7e
+ jr .asm_f90e
.HPIncrease
inc bc ; add 1 HP
ld a, c
@@ -105,7 +105,7 @@ UpdateHPBar2:
call UpdateHPBar_CalcOldNewHPBarPixels
ld a, d
sub e ; calc pixel difference
-.asm_fa7e
+.asm_f90e
call UpdateHPBar_PrintHPNumber
and a
jr z, .noPixelDifference
@@ -212,13 +212,11 @@ UpdateHPBar_PrintHPNumber:
ld a, [wHPBarOldHP + 1]
ld [wHPBarTempHP], a
push hl
- ld a, [hFlags_0xFFF6]
+ ld de, $15
+ ld a, [hFlags_0xFFFA]
bit 0, a
- jr z, .asm_fb15
+ jr z, .next
ld de, $9
- jr .next
-.asm_fb15
- ld de, $15
.next
add hl, de
push hl
diff --git a/engine/in_game_trades.asm b/engine/in_game_trades.asm
index bacf531b..20069e30 100755
--- a/engine/in_game_trades.asm
+++ b/engine/in_game_trades.asm
@@ -3,13 +3,8 @@ DoInGameTradeDialogue:
call SaveScreenTilesToBuffer2
ld hl,TradeMons
ld a,[wWhichTrade]
- ld b,a
- swap a
- sub b
- sub b
- ld c,a
- ld b,0
- add hl,bc
+ ld bc,$e
+ call AddNTimes
ld a,[hli]
ld [wInGameTradeGiveMonSpecies],a
ld a,[hli]
@@ -21,7 +16,7 @@ DoInGameTradeDialogue:
call CopyData
pop af
ld l,a
- ld h,$0
+ ld h,0
ld de,InGameTradeTextPointers
add hl,hl
add hl,de
@@ -35,18 +30,15 @@ DoInGameTradeDialogue:
ld a,[wInGameTradeReceiveMonSpecies]
ld de,wInGameTradeReceiveMonName
call InGameTrade_GetMonName
- ld hl,wCompletedInGameTradeFlags
- ld a,[wWhichTrade]
- ld c,a
+ ld a,$4
+ ld [wInGameTradeTextPointerTableIndex],a
ld b,FLAG_TEST
- predef FlagActionPredef
+ call InGameTrade_FlagActionPredef
ld a,c
and a
- ld a,$4
- ld [wInGameTradeTextPointerTableIndex],a
jr nz,.printText
; if the trade hasn't been done yet
- xor a
+ ld a,$0
ld [wInGameTradeTextPointerTableIndex],a
call .printText
ld a,$1
@@ -109,11 +101,8 @@ InGameTrade_DoTrade:
call AddNTimes
ld a,[hl]
ld [wCurEnemyLVL],a
- ld hl,wCompletedInGameTradeFlags
- ld a,[wWhichTrade]
- ld c,a
ld b,FLAG_SET
- predef FlagActionPredef
+ call InGameTrade_FlagActionPredef
ld hl, ConnectCableText
call PrintText
ld a,[wWhichPokemon]
@@ -137,14 +126,14 @@ InGameTrade_DoTrade:
ld [wMonDataLocation],a
call AddPartyMon
call InGameTrade_CopyDataToReceivedMon
- callab EvolveTradeMon
+ call InGameTrade_CheckForTradeEvo
call ClearScreen
call InGameTrade_RestoreScreen
callba RedrawMapView
and a
ld a,$3
jr .tradeSucceeded
-.tradeFailed
+.tradeFailed ; never jumped to
scf
.tradeSucceeded
ld [wInGameTradeTextPointerTableIndex],a
@@ -229,6 +218,37 @@ InGameTrade_GetReceivedMonPointer:
ld d, h
ret
+InGameTrade_FlagActionPredef:
+ ld hl,wCompletedInGameTradeFlags
+ ld a,[wWhichTrade]
+ ld c,a
+ predef_jump FlagActionPredef
+
+InGameTrade_CheckForTradeEvo:
+ ld a,[wInGameTradeReceiveMonSpecies]
+ cp KADABRA
+ jr z,.tradeEvo
+ cp GRAVELER
+ jr z,.tradeEvo
+ cp MACHOKE
+ jr z,.tradeEvo
+ cp HAUNTER
+ jr z,.tradeEvo
+ ret
+
+.tradeEvo
+ ld a,[wPartyCount]
+ dec a
+ ld [wWhichPokemon],a
+ ld a,$1
+ ld [wForceEvolution],a
+ ld a,LINK_STATE_TRADING
+ ld [wLinkState],a
+ callab EvolveTradeMon
+ xor a ; LINK_STATE_NONE
+ ld [wLinkState],a
+ jp PlayDefaultMusic
+
InGameTrade_TrainerString:
; "TRAINER@@@@@@@@@@"
db $5d, "@@@@@@@@@@"
diff --git a/engine/init_player_data.asm b/engine/init_player_data.asm
new file mode 100644
index 00000000..5883547c
--- /dev/null
+++ b/engine/init_player_data.asm
@@ -0,0 +1,60 @@
+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 a, 90 ; initialize happiness to 90
+ ld [wPikachuHappiness], a
+ ld a, $80
+ ld [wPikachuMood], a ; initialize mood
+
+ ld hl, wPartyCount
+ call InitializeEmptyList
+ ld hl, wNumInBox
+ call InitializeEmptyList
+ ld hl, wNumBagItems
+ call InitializeEmptyList
+ ld hl, wNumBoxItems
+ call InitializeEmptyList
+
+START_MONEY EQU $3000
+ ld hl, wPlayerMoney + 1
+ ld a, START_MONEY / $100
+ ld [hld], a
+ xor a
+ ld [hli], a
+ inc hl
+ ld [hl], a
+
+ ld [wMonDataLocation], a
+
+ ld hl, wObtainedBadges
+ ld [hli], a
+
+ ld [hl], a
+
+ ld hl, wPlayerCoins
+ ld [hli], a
+ ld [hl], a
+
+ ld hl, wGameProgressFlags
+ ld bc, wGameProgressFlagsEnd - wGameProgressFlags
+ call FillMemory ; clear all game progress flags
+
+ jp InitializeMissableObjectsFlags
+
+InitializeEmptyList:
+ xor a ; count
+ ld [hli], a
+ dec a ; terminator
+ ld [hl], a
+ ret
diff --git a/engine/intro.asm b/engine/intro.asm
index 320267c7..9bc1f503 100755
--- a/engine/intro.asm
+++ b/engine/intro.asm
@@ -8,8 +8,7 @@ PlayIntro:
inc a
ld [H_AUTOBGTRANSFERENABLED], a
call PlayShootingStar
- call PlayIntroScene
- call GBFadeOutToWhite
+ callab PlayIntroScene ; 3e:582d
xor a
ld [hSCX], a
ld [H_AUTOBGTRANSFERENABLED], a
@@ -17,162 +16,6 @@ PlayIntro:
call DelayFrame
ret
-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 ; Gengar tiles
- call IntroCopyTiles
- ld a, 0
- ld [wBaseCoordX], a
- ld a, 80
- ld [wBaseCoordY], a
- lb bc, 6, 6
- call InitIntroNidorinoOAM
- lb de, 80 / 2, MOVE_NIDORINO_RIGHT
- call IntroMoveMon
- ret c
-
-; hip
- ld a, SFX_INTRO_HIP
- call PlaySound
- xor a
- ld [wIntroNidorinoBaseTile], a
- ld de, IntroNidorinoAnimation1
- call AnimateIntroNidorino
-; hop
- ld a, SFX_INTRO_HOP
- call PlaySound
- ld de, IntroNidorinoAnimation2
- call AnimateIntroNidorino
- ld c, $a
- call CheckForUserInterruption
- ret c
-
-; hip
- ld a, SFX_INTRO_HIP
- call PlaySound
- ld de, IntroNidorinoAnimation1
- call AnimateIntroNidorino
-; hop
- ld a, SFX_INTRO_HOP
- call PlaySound
- ld de, IntroNidorinoAnimation2
- call AnimateIntroNidorino
- ld c, $1e
- call CheckForUserInterruption
- ret c
-
-; raise
- ld b, $4
- call IntroCopyTiles
- ld a, SFX_INTRO_RAISE
- call PlaySound
- lb de, 8 / 2, MOVE_GENGAR_LEFT
- call IntroMoveMon
- ld c, $1e
- call CheckForUserInterruption
- ret c
-
-; slash
- ld b, $5
- call IntroCopyTiles
- ld a, SFX_INTRO_CRASH
- call PlaySound
- lb de, 16 / 2, MOVE_GENGAR_RIGHT
- call IntroMoveMon
-; hip
- ld a, SFX_INTRO_HIP
- call PlaySound
- ld a, $24
- ld [wIntroNidorinoBaseTile], a
- ld de, IntroNidorinoAnimation3
- call AnimateIntroNidorino
- ld c, $1e
- call CheckForUserInterruption
- ret c
-
- lb de, 8 / 2, MOVE_GENGAR_LEFT
- call IntroMoveMon
- ld b, $3
- call IntroCopyTiles
- ld c, $3c
- call CheckForUserInterruption
- ret c
-
-; hip
- ld a, SFX_INTRO_HIP
- call PlaySound
- xor a
- ld [wIntroNidorinoBaseTile], a
- ld de, IntroNidorinoAnimation4
- call AnimateIntroNidorino
-; hop
- ld a, SFX_INTRO_HOP
- call PlaySound
- ld de, IntroNidorinoAnimation5
- call AnimateIntroNidorino
- ld c, $14
- call CheckForUserInterruption
- ret c
-
- ld a, $24
- ld [wIntroNidorinoBaseTile], a
- ld de, IntroNidorinoAnimation6
- call AnimateIntroNidorino
- ld c, $1e
- call CheckForUserInterruption
- ret c
-
-; lunge
- ld a, SFX_INTRO_LUNGE
- call PlaySound
- ld a, $48
- ld [wIntroNidorinoBaseTile], a
- ld de, IntroNidorinoAnimation7
- jp AnimateIntroNidorino
-
-AnimateIntroNidorino:
- ld a, [de]
- cp $50
- ret z
- ld [wBaseCoordY], a
- inc de
- ld a, [de]
- ld [wBaseCoordX], a
- push de
- ld c, 6 * 6
- call UpdateIntroNidorinoOAM
- ld c, 5
- call DelayFrames
- pop de
- inc de
- jr AnimateIntroNidorino
-
-UpdateIntroNidorinoOAM:
- ld hl, wOAMBuffer
- ld a, [wIntroNidorinoBaseTile]
- ld d, a
-.loop
- ld a, [wBaseCoordY]
- add [hl]
- ld [hli], a ; Y
- ld a, [wBaseCoordX]
- add [hl]
- ld [hli], a ; X
- ld a, d
- ld [hli], a ; tile
- inc hl
- inc d
- dec c
- jr nz, .loop
- ret
-
InitIntroNidorinoOAM:
ld hl, wOAMBuffer
ld d, 0
@@ -229,84 +72,17 @@ IntroPlaceBlackTiles:
jr nz, .loop
ret
-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, .moveNidorinoRight
- cp $1
- jr z, .moveGengarLeft
-; move Gengar right
- ld a, [hSCX]
- dec a
- dec a
- jr .next
-.moveNidorinoRight
- push de
- ld a, 2
- ld [wBaseCoordX], a
- xor a
- ld [wBaseCoordY], a
- ld c, 6 * 6
- call UpdateIntroNidorinoOAM
- pop de
-.moveGengarLeft
- ld a, [hSCX]
- inc a
- inc a
-.next
- ld [hSCX], a
- push de
- ld c, 2
- call CheckForUserInterruption
- pop de
- ret c
- dec d
- jr nz, IntroMoveMon
- ret
-
-IntroCopyTiles:
- coord hl, 13, 7
-
CopyTileIDsFromList_ZeroBaseTileID:
ld c, 0
predef_jump CopyTileIDsFromList
-PlayMoveSoundB:
-; unused
- predef GetMoveSoundB
- ld a, b
- jp PlaySound
-
-LoadIntroGraphics:
- ld hl, FightIntroBackMon
- ld de, vChars2
- ld bc, FightIntroBackMonEnd - FightIntroBackMon
- ld a, BANK(FightIntroBackMon)
- call FarCopyData2
- ld hl, GameFreakIntro
- ld de, vChars2 + $600
- ld bc, GameFreakIntroEnd - GameFreakIntro
- ld a, BANK(GameFreakIntro)
- call FarCopyData2
- ld hl, GameFreakIntro
- ld de, vChars1
- ld bc, GameFreakIntroEnd - GameFreakIntro
- ld a, BANK(GameFreakIntro)
- call FarCopyData2
- ld hl, FightIntroFrontMon
- ld de, vChars0
- ld bc, FightIntroFrontMonEnd - FightIntroFrontMon
- ld a, BANK(FightIntroFrontMon)
- jp FarCopyData2
-
PlayShootingStar:
ld b, SET_PAL_GAME_FREAK_INTRO
call RunPaletteCommand
callba LoadCopyrightAndTextBoxTiles
- ld a, $e4
+ ld a, %11100100
ld [rBGP], a
+ call UpdateGBCPal_BGP
ld c, 180
call DelayFrames
call ClearScreen
@@ -314,7 +90,27 @@ PlayShootingStar:
xor a
ld [wCurOpponent], a
call IntroDrawBlackBars
- call LoadIntroGraphics
+; write the black and white tiles
+ ld hl, vChars2
+ ld bc, $10
+ xor a
+ call FillMemory
+ ld hl, vChars2 + $10
+ ld bc, $10
+ ld a, $ff
+ call FillMemory
+; copy gamefreak logo and others
+ ld hl, GameFreakIntro
+ ld de, vChars2 + $600
+ ld bc, GameFreakIntroEnd - GameFreakIntro
+ ld a, BANK(GameFreakIntro)
+ call FarCopyData
+ ld hl, GameFreakIntro
+ ld de, vChars1
+ ld bc, GameFreakIntroEnd - GameFreakIntro
+ ld a, BANK(GameFreakIntro)
+ call FarCopyData
+
call EnableLCD
ld hl, rLCDC
res 5, [hl]
@@ -328,12 +124,6 @@ PlayShootingStar:
ld c, 40
call DelayFrames
.next
- ld a, BANK(Music_IntroBattle)
- ld [wAudioROMBank], a
- ld [wAudioSavedROMBank], a
- ld a, MUSIC_INTRO_BATTLE
- ld [wNewSoundID], a
- call PlaySound
call IntroClearMiddleOfScreen
call ClearSprites
jp Delay3
@@ -357,102 +147,8 @@ IntroDrawBlackBars:
EmptyFunc4:
ret
-IntroNidorinoAnimation0:
- db 0, 0
- db $50
-
-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
- db 0, 0
- db -2, 2
- db -1, 2
- db 1, 2
- db 2, 2
- db $50 ; list terminator
-
-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
- db -2, -2
- db -1, -2
- db 1, -2
- db 2, -2
- db $50 ; list terminator
-
-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
- db -12, 6
- db -8, 6
- db 8, 6
- db 12, 6
- db $50 ; list terminator
-
-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
- db -8, -4
- db -4, -4
- db 4, -4
- db 8, -4
- db $50 ; list terminator
-
-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
- db -8, 4
- db -4, 4
- db 4, 4
- db 8, 4
- db $50 ; list terminator
-
-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
- db 2, 0
- db 2, 0
- db 0, 0
- db $50 ; list terminator
-
-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
- db -7, -14
- db -6, -12
- db -4, -10
- db $50 ; list terminator
-
GameFreakIntro:
INCBIN "gfx/gamefreak_intro.2bpp"
INCBIN "gfx/gamefreak_logo.2bpp"
ds $10 ; blank tile
GameFreakIntroEnd:
-
-FightIntroBackMon:
- INCBIN "gfx/intro_fight.2bpp"
-FightIntroBackMonEnd:
-
-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"
-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"
-ENDC
-
-FightIntroFrontMonEnd:
-
- ds $10 ; blank tile
diff --git a/engine/items/items.asm b/engine/items/items.asm
index a6717494..3fb4b7e1 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -1,18 +1,18 @@
UseItem_:
- ld a,1
- ld [wActionResultOrTookBattleTurn],a ; initialise to success value
- ld a,[wcf91] ;contains item_ID
- cp a,HM_01
- jp nc,ItemUseTMHM
- ld hl,ItemUsePtrTable
+ ld a, 1
+ ld [wActionResultOrTookBattleTurn], a ; initialise to success value
+ ld a, [wcf91] ;contains item_ID
+ cp HM_01
+ jp nc, ItemUseTMHM
+ ld hl, ItemUsePtrTable
dec a
add a
- ld c,a
- ld b,0
- add hl,bc
- ld a,[hli]
- ld h,[hl]
- ld l,a
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
jp [hl]
ItemUsePtrTable:
@@ -113,7 +113,9 @@ ItemUseBall:
; If this is for the old man battle, skip checking if the party & box are full.
ld a,[wBattleType]
- dec a
+ cp BATTLE_TYPE_OLD_MAN
+ jr z,.canUseBall
+ cp BATTLE_TYPE_PIKACHU
jr z,.canUseBall
ld a,[wPartyCount] ; is party full?
@@ -152,16 +154,26 @@ ItemUseBall:
jp z,.setAnimData
ld a,[wBattleType]
- dec a
- jr nz,.notOldManBattle
+ cp BATTLE_TYPE_OLD_MAN
+ jr z,.oldManBattle
+ cp BATTLE_TYPE_PIKACHU
+ jr z,.oldManBattle ; pikachu battle technically old man battle
+ jr .notOldManBattle
.oldManBattle
ld hl,wGrassRate
ld de,wPlayerName
ld bc,NAME_LENGTH
call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno. glitch)
+ ld a, [wBattleType]
+ cp BATTLE_TYPE_OLD_MAN
+ jp nz,.captured
+ ld a,$1
+ ld [wCapturedMonSpecies], a
+ CheckEvent EVENT_02F
+ ld b, $63
+ jp nz,.setAnimData
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.
@@ -187,6 +199,7 @@ ItemUseBall:
; Get the item ID.
ld hl,wcf91
+.asm_d54a
ld a,[hl]
; The Master Ball always succeeds.
@@ -229,7 +242,7 @@ ItemUseBall:
jr z,.notFrozenOrAsleep
ld c,25
.notFrozenOrAsleep
- ld a,b
+ ld a, b
sub c
jp c,.captured
ld b,a
@@ -251,7 +264,7 @@ ItemUseBall:
; Determine BallFactor. It's 8 for Great Balls and 12 for the others.
ld a,[wcf91]
- cp a,GREAT_BALL
+ cp GREAT_BALL
ld a,12
jr nz,.skip1
ld a,8
@@ -280,6 +293,7 @@ ItemUseBall:
inc a
.skip2
+
; Let W = ((MaxHP * 255) / BallFactor) / max(HP / 4, 1). Calculate W.
ld [H_DIVISOR],a
ld b,4
@@ -337,16 +351,17 @@ ItemUseBall:
; Ultra/Safari Ball: BallFactor2 = 150
ld a,[wcf91]
ld b,255
- cp a,POKE_BALL
+ cp POKE_BALL
jr z,.skip4
ld b,200
- cp a,GREAT_BALL
+ cp GREAT_BALL
jr z,.skip4
ld b,150
- cp a,ULTRA_BALL
+ cp ULTRA_BALL
jr z,.skip4
.skip4
+
; Let Y = (CatchRate * 100) / BallFactor2. Calculate Y.
ld a,b
ld [H_DIVISOR],a
@@ -371,7 +386,7 @@ ItemUseBall:
ld [H_DIVISOR],a
ld b,4
call Divide
-
+
; Determine Status2.
; no status ailment: Status2 = 0
; Burn/Paralysis/Poison: Status2 = 5
@@ -379,7 +394,7 @@ ItemUseBall:
ld a,[wEnemyMonStatus]
and a
jr z,.skip5
- and a, 1 << FRZ | SLP
+ and 1 << FRZ | SLP
ld b,5
jr z,.addAilmentValue
ld b,10
@@ -422,16 +437,16 @@ ItemUseBall:
ld a,TOSS_ANIM
ld [wAnimationID],a
xor a
- ld [H_WHOSETURN],a
- ld [wAnimationType],a
- ld [wDamageMultipliers],a
- ld a,[wWhichPokemon]
+ ld [H_WHOSETURN], a
+ ld [wAnimationType], a
+ ld [wDamageMultipliers], a
+ ld a, [wWhichPokemon]
push af
- ld a,[wcf91]
+ ld a, [wcf91]
push af
predef MoveAnimation
pop af
- ld [wcf91],a
+ ld [wcf91], a
pop af
ld [wWhichPokemon],a
@@ -491,19 +506,19 @@ ItemUseBall:
.skip6
ld a,[wcf91]
push af
- ld a,[wEnemyMonSpecies2]
- ld [wcf91],a
- ld a,[wEnemyMonLevel]
- ld [wCurEnemyLVL],a
+ ld a, [wEnemyMonSpecies2]
+ ld [wcf91], a
+ ld a, [wEnemyMonLevel]
+ ld [wCurEnemyLVL], a
callab LoadEnemyMonData
pop af
- ld [wcf91],a
+ ld [wcf91], a
pop hl
pop af
- ld [hld],a
+ ld [hld], a
dec hl
pop af
- ld [hld],a
+ ld [hld], a
pop af
ld [hl],a
ld a,[wEnemyMonSpecies]
@@ -511,26 +526,27 @@ ItemUseBall:
ld [wcf91],a
ld [wd11e],a
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
-
+ cp BATTLE_TYPE_OLD_MAN ; is this the old man battle?
+ jp z,.oldManCaughtMon ; if so, don't give the player the caught Pokémon
+ cp BATTLE_TYPE_PIKACHU
+ jr z,.oldManCaughtMon ; same with Pikachu battle
ld hl,ItemUseBallText05
call PrintText
; Add the caught Pokémon to the Pokédex.
predef IndexToPokedex
- ld a,[wd11e]
+ ld a, [wd11e]
dec a
- ld c,a
- ld b,FLAG_TEST
- ld hl,wPokedexOwned
+ ld c, a
+ ld b, FLAG_TEST
+ ld hl, wPokedexOwned
predef FlagActionPredef
- ld a,c
+ ld a, c
push af
- ld a,[wd11e]
+ ld a, [wd11e]
dec a
- ld c,a
- ld b,FLAG_SET
+ ld c, a
+ ld b, FLAG_SET
predef FlagActionPredef
pop af
@@ -545,12 +561,18 @@ ItemUseBall:
predef ShowPokedexData
.skipShowingPokedexData
+ ld a, $1
+ ld [wd49c], a
+ ld a, $85
+ ld [wPikachuMood], a
ld a,[wPartyCount]
- cp a,PARTY_LENGTH ; is party full?
+ cp PARTY_LENGTH ; is party full?
jr z,.sendToBox
xor a ; PLAYER_PARTY_DATA
- ld [wMonDataLocation],a
+ ld [wMonDataLocation], a
call ClearSprites
+ ld hl, .emptyString
+ call PrintText
call AddPartyMon
jr .done
@@ -580,9 +602,12 @@ ItemUseBall:
; Remove a ball from the bag.
ld hl,wNumBagItems
inc a
- ld [wItemQuantity],a
+ ld [wItemQuantity], a
jp RemoveItemFromInventory
+.emptyString
+ db "@"
+
ItemUseBallText00:
;"It dodged the thrown ball!"
;"This pokemon can't be caught"
@@ -608,7 +633,7 @@ ItemUseBallText05:
;"All right! {MonName} was caught!"
;play sound
TX_FAR _ItemUseBallText05
- db $12,$06
+ db $12, $06
db "@"
ItemUseBallText07:
;"X was transferred to Bill's PC"
@@ -623,123 +648,130 @@ ItemUseBallText06:
;"New DEX data will be added..."
;play sound
TX_FAR _ItemUseBallText06
- db $13,$06
+ db $13, $06
db "@"
ItemUseTownMap:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
+ jp nz, ItemUseNotTime
jpba DisplayTownMap
ItemUseBicycle:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
- ld a,[wWalkBikeSurfState]
- ld [wWalkBikeSurfStateCopy],a
- cp a,2 ; is the player surfing?
- jp z,ItemUseNotTime
+ jp nz, ItemUseNotTime
+ ld a, [wWalkBikeSurfState]
+ ld [wWalkBikeSurfStateCopy], a
+ cp 2 ; is the player surfing?
+ jp z, ItemUseNotTime
dec a ; is player already bicycling?
- jr nz,.tryToGetOnBike
+ jr nz, .tryToGetOnBike
.getOffBike
call ItemUseReloadOverworldData
xor a
- ld [wWalkBikeSurfState],a ; change player state to walking
+ ld [wWalkBikeSurfState], a ; change player state to walking
+ ld a, $00
+ ld [wPikachuSpawnState], a
call PlayDefaultMusic ; play walking music
- ld hl,GotOffBicycleText
- jr .printText
+ ld hl, GotOffBicycleText
+ jp PrintText
+
.tryToGetOnBike
call IsBikeRidingAllowed
- jp nc,NoCyclingAllowedHere
+ jp nc, NoCyclingAllowedHere
call ItemUseReloadOverworldData
xor a ; no keys pressed
- ld [hJoyHeld],a ; current joypad state
- inc a
- ld [wWalkBikeSurfState],a ; change player state to bicycling
- ld hl,GotOnBicycleText
+ ld [hJoyHeld], a ; current joypad state
+ ld a, $1
+ ld [wWalkBikeSurfState], a ; change player state to bicycling
call PlayDefaultMusic ; play bike riding music
-.printText
- jp PrintText
+ xor a
+ ld [wWalkBikeSurfState], a
+ ld hl, GotOnBicycleText
+ call PrintText
+ ld a, $1
+ ld [wWalkBikeSurfState], a
+ ret
; used for Surf out-of-battle effect
ItemUseSurfboard:
- ld a,[wWalkBikeSurfState]
- ld [wWalkBikeSurfStateCopy],a
- cp a,2 ; is the player already surfing?
- jr z,.tryToStopSurfing
+ ld a, [wWalkBikeSurfState]
+ ld [wWalkBikeSurfStateCopy], a
+ cp 2 ; is the player already surfing?
+ jr z, .tryToStopSurfing
.tryToSurf
call IsNextTileShoreOrWater
- jp c,SurfingAttemptFailed
- ld hl,TilePairCollisionsWater
+ jp nc, SurfingAttemptFailed
+ ld hl, TilePairCollisionsWater
call CheckForTilePairCollisions
- jp c,SurfingAttemptFailed
+ jp c, SurfingAttemptFailed
.surf
call .makePlayerMoveForward
- ld hl,wd730
- set 7,[hl]
- ld a,2
- ld [wWalkBikeSurfState],a ; change player state to surfing
+ ld hl, wd730
+ set 7, [hl]
+ ld a, 2
+ ld [wWalkBikeSurfState], a ; change player state to surfing
call PlayDefaultMusic ; play surfing music
- ld hl,SurfingGotOnText
+ ld hl, SurfingGotOnText
jp PrintText
+
.tryToStopSurfing
xor a
- ld [hSpriteIndexOrTextID],a
- ld d,16 ; talking range in pixels (normal range)
+ ld [hSpriteIndexOrTextID], a
+ ld d, 16 ; talking range in pixels (normal range)
call IsSpriteInFrontOfPlayer2
- res 7,[hl]
- ld a,[hSpriteIndexOrTextID]
+ res 7, [hl]
+ ld a, [hSpriteIndexOrTextID]
and a ; is there a sprite in the way?
- jr nz,.cannotStopSurfing
- ld hl,TilePairCollisionsWater
+ jr nz, .cannotStopSurfing
+ ld hl, TilePairCollisionsWater
call CheckForTilePairCollisions
- jr c,.cannotStopSurfing
- ld hl,wTileSetCollisionPtr ; pointer to list of passable tiles
- ld a,[hli]
- ld h,[hl]
- ld l,a ; hl now points to passable tiles
- ld a,[wTileInFrontOfPlayer] ; tile in front of the player
- ld b,a
-.passableTileLoop
- ld a,[hli]
- cp b
- jr z,.stopSurfing
- cp a,$ff
- jr nz,.passableTileLoop
+ jr c, .cannotStopSurfing
+ ld a, [wTileInFrontOfPlayer]
+ ld c, a
+ call IsTilePassable
+ jr nc, .stopSurfing
.cannotStopSurfing
- ld hl,SurfingNoPlaceToGetOffText
+ ld hl, SurfingNoPlaceToGetOffText
jp PrintText
+
.stopSurfing
call .makePlayerMoveForward
- ld hl,wd730
- set 7,[hl]
+ ld a, $3
+ ld [wPikachuSpawnState], a
+ ld hl, wPikachuOverworldStateFlags
+ set 5, [hl]
+ ld hl, wd730
+ set 7, [hl]
xor a
- ld [wWalkBikeSurfState],a ; change player state to walking
+ ld [wWalkBikeSurfState], a ; change player state to walking
dec a
- ld [wJoyIgnore],a
+ ld [wJoyIgnore], a
call PlayDefaultMusic ; play walking music
+ call GBPalWhiteOutWithDelay3
jp LoadWalkingPlayerSpriteGraphics
+
; uses a simulated button press to make the player move forward
.makePlayerMoveForward
- ld a,[wPlayerDirection] ; direction the player is going
- bit PLAYER_DIR_BIT_UP,a
- ld b,D_UP
- jr nz,.storeSimulatedButtonPress
- bit PLAYER_DIR_BIT_DOWN,a
- ld b,D_DOWN
- jr nz,.storeSimulatedButtonPress
- bit PLAYER_DIR_BIT_LEFT,a
- ld b,D_LEFT
- jr nz,.storeSimulatedButtonPress
- ld b,D_RIGHT
+ ld a, [wPlayerDirection] ; direction the player is going
+ bit PLAYER_DIR_BIT_UP, a
+ ld b, D_UP
+ jr nz, .storeSimulatedButtonPress
+ bit PLAYER_DIR_BIT_DOWN, a
+ ld b, D_DOWN
+ jr nz, .storeSimulatedButtonPress
+ bit PLAYER_DIR_BIT_LEFT, a
+ ld b, D_LEFT
+ jr nz, .storeSimulatedButtonPress
+ ld b, D_RIGHT
.storeSimulatedButtonPress
- ld a,b
- ld [wSimulatedJoypadStatesEnd],a
+ ld a, b
+ ld [wSimulatedJoypadStatesEnd], a
xor a
- ld [wWastedByteCD39],a
+ ld [wWastedByteCD39], a
inc a
- ld [wSimulatedJoypadStatesIndex],a
+ ld [wSimulatedJoypadStatesIndex], a
ret
SurfingGotOnText:
@@ -754,152 +786,221 @@ ItemUsePokedex:
predef_jump ShowPokedexMenu
ItemUseEvoStone:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
- ld a,[wWhichPokemon]
+ jp nz, ItemUseNotTime
+ ld a, [wWhichPokemon]
push af
- ld a,[wcf91]
- ld [wEvoStoneItemID],a
+ ld a, [wcf91]
+ ld [wEvoStoneItemID], a
push af
- ld a,EVO_STONE_PARTY_MENU
- ld [wPartyMenuTypeOrMessageID],a
- ld a,$ff
- ld [wUpdateSpritesEnabled],a
+ ld a, EVO_STONE_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
call DisplayPartyMenu
+ ld a, [wcf91]
+ ld [wLoadedMon], a
pop bc
- jr c,.canceledItemUse
- ld a,b
- ld [wcf91],a
- ld a,$01
- ld [wForceEvolution],a
- ld a,SFX_HEAL_AILMENT
+ jr c, .canceledItemUse
+ ld a, b
+ ld [wcf91], a
+ call Func_d85d
+ jr nc, .noEffect
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .notPlayerPikachu
+ ld e, $1b
+ callab PlayPikachuSoundClip
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMonNicks
+ call GetPartyMonName
+ ld hl, RefusingText
+ call PrintText
+ ld a, $4
+ ld [wd49c], a
+ ld a, $82
+ ld [wPikachuMood], a
+ jr .canceledItemUse
+
+.notPlayerPikachu
+ ld a, SFX_HEAL_AILMENT
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
+ ld a, $01
+ ld [wForceEvolution], a
callab TryEvolvingMon ; try to evolve pokemon
- ld a,[wEvolutionOccurred]
- and a
- jr z,.noEffect
pop af
- ld [wWhichPokemon],a
- ld hl,wNumBagItems
- ld a,1 ; remove 1 stone
- ld [wItemQuantity],a
+ ld [wWhichPokemon], a
+ ld hl, wNumBagItems
+ ld a, 1 ; remove 1 stone
+ ld [wItemQuantity], a
jp RemoveItemFromInventory
+
.noEffect
call ItemUseNoEffect
.canceledItemUse
xor a
- ld [wActionResultOrTookBattleTurn],a ; item not used
+ ld [wActionResultOrTookBattleTurn], a ; item not used
pop af
ret
+Func_d85d:
+ ld hl, EvosMovesPointerTable
+ ld a, [wLoadedMon]
+ dec a
+ ld c, a
+ ld b, $0
+ add hl, bc
+ add hl, bc
+ ld de, wcd6d
+ ld a, BANK(TryEvolvingMon)
+ ld bc, $2
+ call FarCopyData
+ ld hl, wcd6d
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, wcd6d
+ ld a, BANK(TryEvolvingMon)
+ ld bc, 13
+ call FarCopyData
+ ld hl, wcd6d
+.loop
+ ld a, [hli]
+ and a
+ jr z, .cannotEvolveWithUsedStone
+ inc hl
+ inc hl
+ cp EV_ITEM
+ jr nz, .loop
+ dec hl
+ dec hl
+ ld b, [hl]
+ ld a, [wcf91]
+ inc hl
+ inc hl
+ inc hl
+ cp b
+ jr nz, .loop
+ scf
+ ret
+
+.cannotEvolveWithUsedStone
+ and a
+ ret
+
+RefusingText:
+ TX_FAR _RefusingText
+ db "@"
+
ItemUseVitamin:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
+ jp nz, ItemUseNotTime
ItemUseMedicine:
- ld a,[wPartyCount]
+ ld a, [wPartyCount]
and a
- jp z,.emptyParty
- ld a,[wWhichPokemon]
+ jp z, Func_e4bf
+ ld a, [wWhichPokemon]
push af
- ld a,[wcf91]
+ ld a, [wcf91]
push af
- ld a,USE_ITEM_PARTY_MENU
- ld [wPartyMenuTypeOrMessageID],a
- ld a,$ff
- ld [wUpdateSpritesEnabled],a
- ld a,[wPseudoItemID]
+ ld a, USE_ITEM_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ ld a, [wPseudoItemID]
and a ; using Softboiled?
- jr z,.notUsingSoftboiled
+ jr z, .notUsingSoftboiled
; if using softboiled
call GoBackToPartyMenu
jr .getPartyMonDataAddress
-.emptyParty
- ld hl,.emptyPartyText
- xor a
- ld [wActionResultOrTookBattleTurn],a ; item use failed
- jp PrintText
-.emptyPartyText
- text "You don't have"
- line "any #MON!"
- prompt
+
.notUsingSoftboiled
call DisplayPartyMenu
.getPartyMonDataAddress
- jp c,.canceledItemUse
- ld hl,wPartyMons
- ld bc,wPartyMon2 - wPartyMon1
- ld a,[wWhichPokemon]
+ jp c, .canceledItemUse
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1
+ ld a, [wWhichPokemon]
call AddNTimes
- ld a,[wWhichPokemon]
- ld [wUsedItemOnWhichPokemon],a
- ld d,a
- ld a,[wcf91]
- ld e,a
- ld [wd0b5],a
+ ld a, [wWhichPokemon]
+ ld [wUsedItemOnWhichPokemon], a
+ ld d, a
+ ld a, [wcf91]
+ ld e, a
+ ld [wd0b5], a
pop af
- ld [wcf91],a
+ push af
+ cp $28
+ jr nc, .asm_d906
+ push hl
+ push de
+ callabd_ModifyPikachuHappiness PIKAHAPPY_USEDITEM
+ pop de
+ pop hl
+.asm_d906
pop af
- ld [wWhichPokemon],a
- ld a,[wPseudoItemID]
+ ld [wcf91], a
+ pop af
+ ld [wWhichPokemon], a
+ ld a, [wPseudoItemID]
and a ; using Softboiled?
- jr z,.checkItemType
+ jr z, .checkItemType
; if using softboiled
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
cp d ; is the pokemon trying to use softboiled on itself?
- jr z,ItemUseMedicine ; if so, force another choice
+ jr z, ItemUseMedicine ; if so, force another choice
.checkItemType
- ld a,[wcf91]
- cp a,REVIVE
- jr nc,.healHP ; if it's a Revive or Max Revive
- cp a,FULL_HEAL
- jr z,.cureStatusAilment ; if it's a Full Heal
- cp a,HP_UP
- jp nc,.useVitamin ; if it's a vitamin or Rare Candy
- cp a,FULL_RESTORE
- jr nc,.healHP ; if it's a Full Restore or one of the potions
+ ld a, [wcf91]
+ cp REVIVE
+ jr nc, .healHP ; if it's a Revive or Max Revive
+ cp FULL_HEAL
+ jr z, .cureStatusAilment ; if it's a Full Heal
+ cp HP_UP
+ jp nc, .useVitamin ; if it's a vitamin or Rare Candy
+ cp FULL_RESTORE
+ 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,wPartyMon1Status - wPartyMon1
add hl,bc ; hl now points to status
ld a,[wcf91]
lb bc, ANTIDOTE_MSG, 1 << PSN
- cp a,ANTIDOTE
- jr z,.checkMonStatus
+ cp ANTIDOTE
+ jr z, .checkMonStatus
lb bc, BURN_HEAL_MSG, 1 << BRN
- cp a,BURN_HEAL
- jr z,.checkMonStatus
+ cp BURN_HEAL
+ jr z, .checkMonStatus
lb bc, ICE_HEAL_MSG, 1 << FRZ
- cp a,ICE_HEAL
- jr z,.checkMonStatus
+ cp ICE_HEAL
+ jr z, .checkMonStatus
lb bc, AWAKENING_MSG, SLP
- cp a,AWAKENING
- jr z,.checkMonStatus
+ cp AWAKENING
+ jr z, .checkMonStatus
lb bc, PARALYZ_HEAL_MSG, 1 << PAR
- cp a,PARLYZ_HEAL
- jr z,.checkMonStatus
+ cp PARLYZ_HEAL
+ jr z, .checkMonStatus
lb bc, FULL_HEAL_MSG, $ff ; Full Heal
.checkMonStatus
- ld a,[hl] ; pokemon's status
+ ld a, [hl] ; pokemon's status
and c ; does the pokemon have a status ailment the item can cure?
- jp z,.healingItemNoEffect
+ jp z, .healingItemNoEffect
; if the pokemon has a status the item can heal
xor a
- ld [hl],a ; remove the status ailment in the party data
- ld a,b
- ld [wPartyMenuTypeOrMessageID],a ; the message to display for the item used
- ld a,[wPlayerMonNumber]
+ ld [hl], a ; remove the status ailment in the party data
+ ld a, b
+ 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
+ jp nz, .doneHealing
; if it is active in battle
xor a
- ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data
+ ld [wBattleMonStatus], a ; remove the status ailment in the in-battle pokemon data
push hl
- ld hl,wPlayerBattleStatus3
- res BadlyPoisoned,[hl] ; heal Toxic status
+ ld hl, wPlayerBattleStatus3
+ res BadlyPoisoned, [hl] ; heal Toxic status
pop hl
ld bc,wPartyMon1Stats - wPartyMon1Status
add hl,bc ; hl now points to party stats
@@ -908,87 +1009,105 @@ ItemUseMedicine:
call CopyData ; copy party stats to in-battle stat data
predef DoubleOrHalveSelectedStats
jp .doneHealing
+
.healHP
inc hl ; hl = address of current HP
- ld a,[hli]
- ld b,a
- ld [wHPBarOldHP+1],a
- ld a,[hl]
- ld c,a
- ld [wHPBarOldHP],a ; current HP stored at wHPBarOldHP (2 bytes, big-endian)
+ ld a, [hli]
+ ld b, a
+ ld [wHPBarOldHP+1], a
+ ld a, [hl]
+ ld c, a
+ ld [wHPBarOldHP], a ; current HP stored at wHPBarOldHP (2 bytes, big-endian)
or b
- jr nz,.notFainted
+ jr nz, .notFainted
.fainted
- ld a,[wcf91]
- cp a,REVIVE
- jr z,.updateInBattleFaintedData
- cp a,MAX_REVIVE
- jr z,.updateInBattleFaintedData
+ ld a, [wcf91]
+ cp REVIVE
+ jr z, .updateInBattleFaintedData
+ cp MAX_REVIVE
+ jr z, .updateInBattleFaintedData
jp .healingItemNoEffect
+
.updateInBattleFaintedData
- ld a,[wIsInBattle]
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wUsedItemOnWhichPokemon]
+ ld [wWhichPokemon], a
+ push hl
+ push de
+ push bc
+ callab Func_2fd6a
+ pop bc
+ pop de
+ pop hl
+ pop af
+ ld [wWhichPokemon], a
+
+ ld a, [wIsInBattle]
and a
- jr z,.compareCurrentHPToMaxHP
+ jr z, .compareCurrentHPToMaxHP
push hl
push de
push bc
- ld a,[wUsedItemOnWhichPokemon]
- ld c,a
- ld hl,wPartyFoughtCurrentEnemyFlags
- ld b,FLAG_TEST
+ ld a, [wUsedItemOnWhichPokemon]
+ ld c, a
+ ld hl, wPartyFoughtCurrentEnemyFlags
+ ld b, FLAG_TEST
predef FlagActionPredef
- ld a,c
+ ld a, c
and a
- jr z,.next
- ld a,[wUsedItemOnWhichPokemon]
- ld c,a
- ld hl,wPartyGainExpFlags
- ld b,FLAG_SET
+ jr z, .next
+ ld a, [wUsedItemOnWhichPokemon]
+ ld c, a
+ ld hl, wPartyGainExpFlags
+ ld b, FLAG_SET
predef FlagActionPredef
.next
pop bc
pop de
pop hl
jr .compareCurrentHPToMaxHP
+
.notFainted
- ld a,[wcf91]
- cp a,REVIVE
- jp z,.healingItemNoEffect
- cp a,MAX_REVIVE
- jp z,.healingItemNoEffect
+ ld a, [wcf91]
+ cp REVIVE
+ jp z, .healingItemNoEffect
+ cp MAX_REVIVE
+ jp z, .healingItemNoEffect
.compareCurrentHPToMaxHP
push hl
push bc
ld bc,wPartyMon1MaxHP - (wPartyMon1HP + 1)
add hl,bc ; hl now points to max HP
pop bc
- ld a,[hli]
+ ld a, [hli]
cp b
- jr nz,.skipComparingLSB ; no need to compare the LSB's if the MSB's don't match
- ld a,[hl]
+ jr nz, .skipComparingLSB ; no need to compare the LSB's if the MSB's don't match
+ ld a, [hl]
cp c
.skipComparingLSB
pop hl
- jr nz,.notFullHP
+ jr nz, .notFullHP
.fullHP ; if the pokemon's current HP equals its max HP
- ld a,[wcf91]
- cp a,FULL_RESTORE
- jp nz,.healingItemNoEffect
+ ld a, [wcf91]
+ cp FULL_RESTORE
+ jp nz, .healingItemNoEffect
inc hl
inc hl
- ld a,[hld] ; status ailment
+ ld a, [hld] ; status ailment
and a ; does the pokemon have a status ailment?
- jp z,.healingItemNoEffect
- ld a,FULL_HEAL
- ld [wcf91],a
+ jp z, .healingItemNoEffect
+ ld a, FULL_HEAL
+ ld [wcf91], a
dec hl
dec hl
dec hl
jp .cureStatusAilment
+
.notFullHP ; if the pokemon's current HP doesn't equal its max HP
xor a
- ld [wLowHealthAlarm],a ;disable low health alarm
- ld [wChannelSoundIDs + CH4],a
+ ld [wLowHealthAlarm], a ;disable low health alarm
+ ld [wChannelSoundIDs + CH4], a
push hl
push de
ld bc,wPartyMon1MaxHP - (wPartyMon1HP + 1)
@@ -999,105 +1118,106 @@ ItemUseMedicine:
ld [wHPBarMaxHP],a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian)
ld a,[wPseudoItemID]
and a ; using Softboiled?
- jp z,.notUsingSoftboiled2
+ jp z, .notUsingSoftboiled2
; if using softboiled
- ld hl,wHPBarMaxHP
- ld a,[hli]
+ ld hl, wHPBarMaxHP
+ ld a, [hli]
push af
- ld a,[hli]
+ ld a, [hli]
push af
- ld a,[hli]
+ ld a, [hli]
push af
- ld a,[hl]
+ ld a, [hl]
push af
- ld hl,wPartyMon1MaxHP
- ld a,[wWhichPokemon]
- ld bc,wPartyMon2 - wPartyMon1
+ ld hl, wPartyMon1MaxHP
+ ld a, [wWhichPokemon]
+ ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
- ld a,[hli]
- ld [wHPBarMaxHP + 1],a
- ld [H_DIVIDEND],a
- ld a,[hl]
- ld [wHPBarMaxHP],a
- ld [H_DIVIDEND + 1],a
- ld a,5
- ld [H_DIVISOR],a
- ld b,2 ; number of bytes
+ ld a, [hli]
+ ld [wHPBarMaxHP + 1], a
+ ld [H_DIVIDEND], a
+ ld a, [hl]
+ ld [wHPBarMaxHP], a
+ ld [H_DIVIDEND + 1], a
+ ld a, 5
+ 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 + 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]
+ ld a, [H_QUOTIENT + 3]
push af
- ld b,a
- ld a,[hl]
- ld [wHPBarOldHP],a
+ ld b, a
+ ld a, [hl]
+ ld [wHPBarOldHP], a
sub b
- ld [hld],a
- ld [wHPBarNewHP],a
- ld a,[H_QUOTIENT + 2]
- ld b,a
- ld a,[hl]
- ld [wHPBarOldHP+1],a
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ ld a, [H_QUOTIENT + 2]
+ ld b, a
+ ld a, [hl]
+ ld [wHPBarOldHP+1], a
sbc b
- ld [hl],a
- ld [wHPBarNewHP+1],a
+ ld [hl], a
+ ld [wHPBarNewHP+1], a
coord hl, 4, 1
- ld a,[wWhichPokemon]
- ld bc,2 * SCREEN_WIDTH
+ ld a, [wWhichPokemon]
+ ld bc, 2 * SCREEN_WIDTH
call AddNTimes ; calculate coordinates of HP bar of pokemon that used Softboiled
- ld a,SFX_HEAL_HP
+ ld a, SFX_HEAL_HP
call PlaySoundWaitForCurrent
- ld a,[hFlags_0xFFF6]
- set 0,a
- ld [hFlags_0xFFF6],a
- ld a,$02
- ld [wHPBarType],a
+ ld a, [hFlags_0xFFFA]
+ set 0, a
+ ld [hFlags_0xFFFA], a
+ ld a, $02
+ ld [wHPBarType], a
predef UpdateHPBar2 ; animate HP bar decrease of pokemon that used Softboiled
- ld a,[hFlags_0xFFF6]
- res 0,a
- ld [hFlags_0xFFF6],a
+ ld a, [hFlags_0xFFFA]
+ res 0, a
+ ld [hFlags_0xFFFA], a
pop af
- ld b,a ; store heal amount (1/5 of max HP)
- ld hl,wHPBarOldHP + 1
+ ld b, a ; store heal amount (1/5 of max HP)
+ ld hl, wHPBarOldHP + 1
pop af
- ld [hld],a
+ ld [hld], a
pop af
- ld [hld],a
+ ld [hld], a
pop af
- ld [hld],a
+ ld [hld], a
pop af
- ld [hl],a
+ ld [hl], a
jr .addHealAmount
+
.notUsingSoftboiled2
- ld a,[wcf91]
- cp a,SODA_POP
- ld b,60 ; Soda Pop heal amount
- jr z,.addHealAmount
- ld b,80 ; Lemonade heal amount
- jr nc,.addHealAmount
- cp a,FRESH_WATER
- ld b,50 ; Fresh Water heal amount
- jr z,.addHealAmount
- cp a,SUPER_POTION
- ld b,200 ; Hyper Potion heal amount
- jr c,.addHealAmount
- ld b,50 ; Super Potion heal amount
- jr z,.addHealAmount
- ld b,20 ; Potion heal amount
+ ld a, [wcf91]
+ cp SODA_POP
+ ld b, 60 ; Soda Pop heal amount
+ jr z, .addHealAmount
+ ld b, 80 ; Lemonade heal amount
+ jr nc, .addHealAmount
+ cp FRESH_WATER
+ ld b, 50 ; Fresh Water heal amount
+ jr z, .addHealAmount
+ cp SUPER_POTION
+ ld b, 200 ; Hyper Potion heal amount
+ jr c, .addHealAmount
+ ld b, 50 ; Super Potion heal amount
+ jr z, .addHealAmount
+ ld b, 20 ; Potion heal amount
.addHealAmount
pop de
pop hl
- ld a,[hl]
+ ld a, [hl]
add b
- ld [hld],a
- ld [wHPBarNewHP],a
- ld a,[hl]
- ld [wHPBarNewHP+1],a
- jr nc,.noCarry
+ ld [hld], a
+ ld [wHPBarNewHP], a
+ ld a, [hl]
+ ld [wHPBarNewHP+1], a
+ jr nc, .noCarry
inc [hl]
- ld a,[hl]
- ld [wHPBarNewHP + 1],a
+ ld a, [hl]
+ ld [wHPBarNewHP + 1], a
.noCarry
push de
inc hl
@@ -1113,38 +1233,40 @@ ItemUseMedicine:
ld a,[de]
sub b
dec de
- ld b,[hl]
- ld a,[de]
+ ld b, [hl]
+ ld a, [de]
sbc b
- jr nc,.setCurrentHPToMaxHp ; if current HP exceeds max HP after healing
- ld a,[wcf91]
- cp a,HYPER_POTION
- jr c,.setCurrentHPToMaxHp ; if using a Full Restore or Max Potion
- cp a,MAX_REVIVE
- jr z,.setCurrentHPToMaxHp ; if using a Max Revive
+ jr nc, .setCurrentHPToMaxHp ; if current HP exceeds max HP after healing
+ ld a, [wcf91]
+ cp HYPER_POTION
+ jr c, .setCurrentHPToMaxHp ; if using a Full Restore or Max Potion
+ cp MAX_REVIVE
+ jr z, .setCurrentHPToMaxHp ; if using a Max Revive
jr .updateInBattleData
+
.setCurrentHPToHalfMaxHP
dec hl
dec de
- ld a,[hli]
+ ld a, [hli]
srl a
- ld [de],a
- ld [wHPBarNewHP+1],a
- ld a,[hl]
+ ld [de], a
+ ld [wHPBarNewHP+1], a
+ ld a, [hl]
rr a
inc de
- ld [de],a
- ld [wHPBarNewHP],a
+ ld [de], a
+ ld [wHPBarNewHP], a
dec de
jr .doneHealingPartyHP
+
.setCurrentHPToMaxHp
- ld a,[hli]
- ld [de],a
- ld [wHPBarNewHP+1],a
+ ld a, [hli]
+ ld [de], a
+ ld [wHPBarNewHP+1], a
inc de
- ld a,[hl]
- ld [de],a
- ld [wHPBarNewHP],a
+ ld a, [hl]
+ ld [de], a
+ ld [wHPBarNewHP], a
dec de
.doneHealingPartyHP ; done updating the pokemon's current HP in the party data structure
ld a,[wcf91]
@@ -1153,101 +1275,106 @@ ItemUseMedicine:
ld bc,wPartyMon1Status - (wPartyMon1MaxHP + 1)
add hl,bc
xor a
- ld [hl],a ; remove the status ailment in the party data
+ ld [hl], a ; remove the status ailment in the party data
.updateInBattleData
- ld h,d
- ld l,e
+ ld h, d
+ ld l, e
pop de
- ld a,[wPlayerMonNumber]
+ ld a, [wPlayerMonNumber]
cp d ; is pokemon the item was used on active in battle?
- jr nz,.calculateHPBarCoords
+ jr nz, .calculateHPBarCoords
; copy party HP to in-battle HP
- ld a,[hli]
- ld [wBattleMonHP],a
- ld a,[hld]
- ld [wBattleMonHP + 1],a
- ld a,[wcf91]
- cp a,FULL_RESTORE
- jr nz,.calculateHPBarCoords
+ ld a, [hli]
+ ld [wBattleMonHP], a
+ ld a, [hld]
+ ld [wBattleMonHP + 1], a
+ ld a, [wcf91]
+ cp FULL_RESTORE
+ jr nz, .calculateHPBarCoords
xor a
- ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data
+ ld [wBattleMonStatus], a ; remove the status ailment in the in-battle pokemon data
.calculateHPBarCoords
ld hl,wOAMBuffer + $90
ld bc,2 * SCREEN_WIDTH
inc d
.calculateHPBarCoordsLoop
- add hl,bc
+ add hl, bc
dec d
- jr nz,.calculateHPBarCoordsLoop
+ jr nz, .calculateHPBarCoordsLoop
jr .doneHealing
+
.healingItemNoEffect
call ItemUseNoEffect
jp .done
+
.doneHealing
- ld a,[wPseudoItemID]
+ ld a, [wPseudoItemID]
and a ; using Softboiled?
- jr nz,.skipRemovingItem ; no item to remove if using Softboiled
+ jr nz, .skipRemovingItem ; no item to remove if using Softboiled
push hl
call RemoveUsedItem
pop hl
.skipRemovingItem
- ld a,[wcf91]
- cp a,FULL_RESTORE
- jr c,.playStatusAilmentCuringSound
- cp a,FULL_HEAL
- jr z,.playStatusAilmentCuringSound
- ld a,SFX_HEAL_HP
+ ld a, [wcf91]
+ cp FULL_RESTORE
+ jr c, .playStatusAilmentCuringSound
+ cp FULL_HEAL
+ jr z, .playStatusAilmentCuringSound
+ ld a, SFX_HEAL_HP
call PlaySoundWaitForCurrent
- ld a,[hFlags_0xFFF6]
- set 0,a
- ld [hFlags_0xFFF6],a
- ld a,$02
- ld [wHPBarType],a
+ ld a, [hFlags_0xFFFA]
+ set 0, a
+ ld [hFlags_0xFFFA], a
+ ld a, $02
+ ld [wHPBarType], a
predef UpdateHPBar2 ; animate the HP bar lengthening
- ld a,[hFlags_0xFFF6]
- res 0,a
- ld [hFlags_0xFFF6],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,POTION_MSG
- ld [wPartyMenuTypeOrMessageID],a
+ ld a, [hFlags_0xFFFA]
+ res 0, a
+ ld [hFlags_0xFFFA], a
+ ld a, REVIVE_MSG
+ ld [wPartyMenuTypeOrMessageID], a
+ ld a, [wcf91]
+ cp REVIVE
+ jr z, .showHealingItemMessage
+ cp MAX_REVIVE
+ jr z, .showHealingItemMessage
+ ld a, POTION_MSG
+ ld [wPartyMenuTypeOrMessageID], a
jr .showHealingItemMessage
+
.playStatusAilmentCuringSound
- ld a,SFX_HEAL_AILMENT
+ ld a, SFX_HEAL_AILMENT
call PlaySoundWaitForCurrent
.showHealingItemMessage
xor a
- ld [H_AUTOBGTRANSFERENABLED],a
+ ld [H_AUTOBGTRANSFERENABLED], a
call ClearScreen
dec a
- ld [wUpdateSpritesEnabled],a
+ ld [wUpdateSpritesEnabled], a
call RedrawPartyMenu ; redraws the party menu and displays the message
- ld a,1
- ld [H_AUTOBGTRANSFERENABLED],a
- ld c,50
+ ld a, 1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld c, 50
call DelayFrames
call WaitForTextScrollButtonPress
jr .done
+
.canceledItemUse
xor a
- ld [wActionResultOrTookBattleTurn],a ; item use failed
+ ld [wActionResultOrTookBattleTurn], a ; item use failed
pop af
pop af
.done
- ld a,[wPseudoItemID]
+ ld a, [wPseudoItemID]
and a ; using Softboiled?
ret nz ; if so, return
call GBPalWhiteOut
- call z,RunDefaultPaletteCommand
- ld a,[wIsInBattle]
+ call z, RunDefaultPaletteCommand
+ ld a, [wIsInBattle]
and a
ret nz
jp ReloadMapData
+
.useVitamin
push hl
ld a,[hl]
@@ -1259,64 +1386,67 @@ ItemUseMedicine:
ld [wCurEnemyLVL],a ; store level
call GetMonHeader
push de
- ld a,d
- ld hl,wPartyMonNicks
+ ld a, d
+ ld hl, wPartyMonNicks
call GetPartyMonName
pop de
pop hl
- ld a,[wcf91]
- cp a,RARE_CANDY
- jp z,.useRareCandy
+ ld a, [wcf91]
+ cp RARE_CANDY
+ jp z, .useRareCandy
push hl
- sub a,HP_UP
+ sub HP_UP
add a
ld bc,wPartyMon1HPExp - wPartyMon1
add hl,bc
add l
- ld l,a
- jr nc,.noCarry2
+ ld l, a
+ jr nc, .noCarry2
inc h
.noCarry2
- ld a,10
- ld b,a
- ld a,[hl] ; a = MSB of stat experience of the appropriate stat
- cp a,100 ; is there already at least 25600 (256 * 100) stat experience?
- jr nc,.vitaminNoEffect ; if so, vitamins can't add any more
+ ld a, 10
+ ld b, a
+ ld a, [hl] ; a = MSB of stat experience of the appropriate stat
+ cp 100 ; is there already at least 25600 (256 * 100) stat experience?
+ jr nc, .vitaminNoEffect ; if so, vitamins can't add any more
add b ; add 2560 (256 * 10) stat experience
- jr nc,.noCarry3 ; a carry should be impossible here, so this will always jump
- ld a,255
+ jr nc, .noCarry3 ; a carry should be impossible here, so this will always jump
+ ld a, 255
.noCarry3
- ld [hl],a
+ ld [hl], a
pop hl
call .recalculateStats
- ld hl,VitaminText
- ld a,[wcf91]
- sub a,HP_UP - 1
- ld c,a
+ ld hl, VitaminText
+ ld a, [wcf91]
+ sub HP_UP - 1
+ ld c, a
.statNameLoop ; loop to get the address of the name of the stat the vitamin increases
dec c
- jr z,.gotStatName
+ jr z, .gotStatName
.statNameInnerLoop
- ld a,[hli]
- ld b,a
- ld a,$50
+ ld a, [hli]
+ ld b, a
+ ld a, $50
cp b
- jr nz,.statNameInnerLoop
+ jr nz, .statNameInnerLoop
jr .statNameLoop
+
.gotStatName
- ld de,wcf4b
- ld bc,10
+ ld de, wcf4b
+ ld bc, 10
call CopyData ; copy the stat's name to wcf4b
- ld a,SFX_HEAL_AILMENT
+ ld a, SFX_HEAL_AILMENT
call PlaySound
- ld hl,VitaminStatRoseText
+ ld hl, VitaminStatRoseText
call PrintText
jp RemoveUsedItem
+
.vitaminNoEffect
pop hl
- ld hl,VitaminNoEffectText
+ ld hl, VitaminNoEffectText
call PrintText
jp GBPalWhiteOut
+
.recalculateStats
ld bc,wPartyMon1Stats - wPartyMon1
add hl,bc
@@ -1334,27 +1464,27 @@ ItemUseMedicine:
cp a, MAX_LEVEL
jr z,.vitaminNoEffect ; can't raise level above 100
inc a
- ld [hl],a ; store incremented level
- ld [wCurEnemyLVL],a
+ ld [hl], a ; store incremented level
+ ld [wCurEnemyLVL], a
push hl
push de
- ld d,a
+ ld d, a
callab CalcExperience ; calculate experience for next level and store it at $ff96
pop de
pop hl
ld bc,wPartyMon1Exp - wPartyMon1Level
add hl,bc ; hl now points to MSB of experience
; update experience to minimum for new level
- ld a,[hExperience]
- ld [hli],a
- ld a,[hExperience + 1]
- ld [hli],a
- ld a,[hExperience + 2]
- ld [hl],a
+ ld a, [hExperience]
+ ld [hli], a
+ ld a, [hExperience + 1]
+ ld [hli], a
+ ld a, [hExperience + 2]
+ ld [hl], a
pop hl
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
push af
- ld a,[wcf91]
+ ld a, [wcf91]
push af
push de
push hl
@@ -1371,47 +1501,57 @@ ItemUseMedicine:
ld bc,(wPartyMon1MaxHP + 1) - wPartyMon1
add hl,bc ; hl now points to LSB of max HP
pop bc
- ld a,[hld]
+ ld a, [hld]
sub c
- ld c,a
- ld a,[hl]
+ ld c, a
+ ld a, [hl]
sbc b
- ld b,a ; bc = the amount of max HP gained from leveling up
+ ld b, a ; bc = the amount of max HP gained from leveling up
; add the amount gained to the 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]
+ ld [hld], a
+ ld a, [hl]
adc b
- ld [hl],a
- ld a,RARE_CANDY_MSG
- ld [wPartyMenuTypeOrMessageID],a
+ ld [hl], 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
+ ld a, d
+ ld [wWhichPokemon], a
+ ld a, e
+ ld [wd11e], a
xor a ; PLAYER_PARTY_DATA
- ld [wMonDataLocation],a
+ ld [wMonDataLocation], a
call LoadMonData
- ld d,$01
+ ld d, $01
callab PrintStatsBox ; display new stats text box
call WaitForTextScrollButtonPress ; wait for button press
xor a ; PLAYER_PARTY_DATA
- ld [wMonDataLocation],a
+ ld [wMonDataLocation], a
predef LearnMoveFromLevelUp ; learn level up move, if any
+
xor a
- ld [wForceEvolution],a
- callab TryEvolvingMon ; evolve pokemon, if appropriate
- ld a,$01
- ld [wUpdateSpritesEnabled],a
+ ld [wForceEvolution], a
+ callabd_ModifyPikachuHappiness PIKAHAPPY_LEVELUP
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wUsedItemOnWhichPokemon]
+ ld [wWhichPokemon], a
+ callab Func_2fd6a ; evolve pokemon, if appropriate
pop af
- ld [wcf91],a
+ ld [wWhichPokemon], a
+
+ callab TryEvolvingMon
+ ld a, $01
+ ld [wUpdateSpritesEnabled], a
pop af
- ld [wWhichPokemon],a
+ ld [wcf91], a
+ pop af
+ ld [wWhichPokemon], a
jp RemoveUsedItem
VitaminStatRoseText:
@@ -1430,50 +1570,50 @@ VitaminText:
db "SPECIAL@"
ItemUseBait:
- ld hl,ThrewBaitText
+ ld hl, ThrewBaitText
call PrintText
- ld hl,wEnemyMonCatchRate ; catch rate
+ ld hl, wEnemyMonCatchRate ; catch rate
srl [hl] ; halve catch rate
- ld a,BAIT_ANIM
- ld hl,wSafariBaitFactor ; bait factor
- ld de,wSafariEscapeFactor ; escape factor
+ ld a, BAIT_ANIM
+ ld hl, wSafariBaitFactor ; bait factor
+ ld de, wSafariEscapeFactor ; escape factor
jr BaitRockCommon
ItemUseRock:
- ld hl,ThrewRockText
+ ld hl, ThrewRockText
call PrintText
- ld hl,wEnemyMonCatchRate ; catch rate
- ld a,[hl]
+ ld hl, wEnemyMonCatchRate ; catch rate
+ ld a, [hl]
add a ; double catch rate
- jr nc,.noCarry
- ld a,$ff
+ jr nc, .noCarry
+ ld a, $ff
.noCarry
- ld [hl],a
- ld a,ROCK_ANIM
- ld hl,wSafariEscapeFactor ; escape factor
- ld de,wSafariBaitFactor ; bait factor
+ ld [hl], a
+ ld a, ROCK_ANIM
+ ld hl, wSafariEscapeFactor ; escape factor
+ ld de, wSafariBaitFactor ; bait factor
BaitRockCommon:
- ld [wAnimationID],a
+ ld [wAnimationID], a
xor a
- ld [wAnimationType],a
- ld [H_WHOSETURN],a
- ld [de],a ; zero escape factor (for bait), zero bait factor (for rock)
+ 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
call Random
- and a,7
- cp a,5
- jr nc,.randomLoop
+ and 7
+ cp 5
+ jr nc, .randomLoop
inc a ; increment the random number, giving a range from 1 to 5 inclusive
- ld b,a
- ld a,[hl]
+ ld b, a
+ ld a, [hl]
add b ; increase bait factor (for bait), increase escape factor (for rock)
- jr nc,.noCarry
- ld a,$ff
+ jr nc, .noCarry
+ ld a, $ff
.noCarry
- ld [hl],a
+ ld [hl], a
predef MoveAnimation ; do animation
- ld c,70
+ ld c, 70
jp DelayFrames
ThrewBaitText:
@@ -1486,40 +1626,46 @@ ThrewRockText:
; also used for Dig out-of-battle effect
ItemUseEscapeRope:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jr nz,.notUsable
- ld a,[wCurMap]
- cp a,AGATHAS_ROOM
- jr z,.notUsable
- ld a,[wCurMapTileset]
- ld b,a
- ld hl,EscapeRopeTilesets
+ jr nz, .notUsable
+ ld a, [wCurMap]
+ cp AGATHAS_ROOM
+ jr z, .notUsable
+ cp BILLS_HOUSE
+ jr z, .notUsable
+ cp POKEMON_FAN_CLUB
+ jr z, .notUsable
+ ld a, [wCurMapTileset]
+ ld b, a
+ ld hl, EscapeRopeTilesets
.loop
- ld a,[hli]
- cp a,$ff
- jr z,.notUsable
+ ld a, [hli]
+ cp $ff
+ jr z, .notUsable
cp b
- jr nz,.loop
- ld hl,wd732
- set 3,[hl]
- set 6,[hl]
- ld hl,wd72e
- res 4,[hl]
+ jr nz, .loop
+ ld hl, wd732
+ set 3, [hl]
+ set 6, [hl]
+ call Func_1510
+ ld hl, wd72e
+ res 4, [hl]
ResetEvent EVENT_IN_SAFARI_ZONE
xor a
- ld [wNumSafariBalls],a
- ld [wSafariZoneEntranceCurScript],a
+ ld [wNumSafariBalls], a
+ ld [wSafariZoneEntranceCurScript], a
inc a
- ld [wEscapedFromBattle],a
- ld [wActionResultOrTookBattleTurn],a ; item used
- ld a,[wPseudoItemID]
+ ld [wEscapedFromBattle], a
+ ld [wActionResultOrTookBattleTurn], a ; item used
+ ld a, [wPseudoItemID]
and a ; using Dig?
ret nz ; if so, return
call ItemUseReloadOverworldData
- ld c,30
+ ld c, 30
call DelayFrames
jp RemoveUsedItem
+
.notUsable
jp ItemUseNotTime
@@ -1528,63 +1674,67 @@ EscapeRopeTilesets:
db $ff ; terminator
ItemUseRepel:
- ld b,100
+ ld b, 100
ItemUseRepelCommon:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
- ld a,b
- ld [wRepelRemainingSteps],a
+ jp nz, ItemUseNotTime
+ ld a, b
+ ld [wRepelRemainingSteps], a
jp PrintItemUseTextAndRemoveItem
; handles X Accuracy item
ItemUseXAccuracy:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp z,ItemUseNotTime
- ld hl,wPlayerBattleStatus2
- set UsingXAccuracy,[hl] ; X Accuracy bit
+ jp z, ItemUseNotTime
+ ld hl, wPlayerBattleStatus2
+ set UsingXAccuracy, [hl] ; X Accuracy bit
+ callabd_ModifyPikachuHappiness PIKAHAPPY_USEDXITEM
jp PrintItemUseTextAndRemoveItem
; This function is bugged and never works. It always jumps to ItemUseNotTime.
; The Card Key is handled in a different way.
ItemUseCardKey:
xor a
- ld [wUnusedD71F],a
+ ld [wUnusedD71F], a
call GetTileAndCoordsInFrontOfPlayer
ld a,[GetTileAndCoordsInFrontOfPlayer]
cp a,$18
jr nz,.next0
ld hl,CardKeyTable1
jr .next1
+
.next0
- cp a,$24
- jr nz,.next2
- ld hl,CardKeyTable2
+ cp $24
+ jr nz, .next2
+ ld hl, CardKeyTable2
jr .next1
+
.next2
- cp a,$5e
- jp nz,ItemUseNotTime
- ld hl,CardKeyTable3
+ cp $5e
+ jp nz, ItemUseNotTime
+ ld hl, CardKeyTable3
.next1
- ld a,[wCurMap]
- ld b,a
+ ld a, [wCurMap]
+ ld b, a
.loop
- ld a,[hli]
- cp a,$ff
- jp z,ItemUseNotTime
+ ld a, [hli]
+ cp $ff
+ jp z, ItemUseNotTime
cp b
- jr nz,.nextEntry1
- ld a,[hli]
+ jr nz, .nextEntry1
+ ld a, [hli]
cp d
- jr nz,.nextEntry2
- ld a,[hli]
+ jr nz, .nextEntry2
+ ld a, [hli]
cp e
- jr nz,.nextEntry3
- ld a,[hl]
- ld [wUnusedD71F],a
+ jr nz, .nextEntry3
+ ld a, [hl]
+ ld [wUnusedD71F], a
jr .done
+
.nextEntry1
inc hl
.nextEntry2
@@ -1592,11 +1742,12 @@ ItemUseCardKey:
.nextEntry3
inc hl
jr .loop
+
.done
- ld hl,ItemUseText00
+ ld hl, ItemUseText00
call PrintText
- ld hl,wd728
- set 7,[hl]
+ ld hl, wd728
+ set 7, [hl]
ret
; These tables are probably supposed to be door locations in Silph Co.,
@@ -1610,176 +1761,228 @@ ItemUseCardKey:
; 03: ID?
CardKeyTable1:
- db SILPH_CO_2F,$04,$04,$00
- db SILPH_CO_2F,$04,$05,$01
- db SILPH_CO_4F,$0C,$04,$02
- db SILPH_CO_4F,$0C,$05,$03
- db SILPH_CO_7F,$06,$0A,$04
- db SILPH_CO_7F,$06,$0B,$05
- db SILPH_CO_9F,$04,$12,$06
- db SILPH_CO_9F,$04,$13,$07
- db SILPH_CO_10F,$08,$0A,$08
- db SILPH_CO_10F,$08,$0B,$09
+ db SILPH_CO_2F, $04, $04, $00
+ db SILPH_CO_2F, $04, $05, $01
+ db SILPH_CO_4F, $0C, $04, $02
+ db SILPH_CO_4F, $0C, $05, $03
+ db SILPH_CO_7F, $06, $0A, $04
+ db SILPH_CO_7F, $06, $0B, $05
+ db SILPH_CO_9F, $04, $12, $06
+ db SILPH_CO_9F, $04, $13, $07
+ db SILPH_CO_10F, $08, $0A, $08
+ db SILPH_CO_10F, $08, $0B, $09
db $ff
CardKeyTable2:
- db SILPH_CO_3F,$08,$09,$0A
- db SILPH_CO_3F,$09,$09,$0B
- db SILPH_CO_5F,$04,$07,$0C
- db SILPH_CO_5F,$05,$07,$0D
- db SILPH_CO_6F,$0C,$05,$0E
- db SILPH_CO_6F,$0D,$05,$0F
- db SILPH_CO_8F,$08,$07,$10
- db SILPH_CO_8F,$09,$07,$11
- db SILPH_CO_9F,$08,$03,$12
- db SILPH_CO_9F,$09,$03,$13
+ db SILPH_CO_3F, $08, $09, $0A
+ db SILPH_CO_3F, $09, $09, $0B
+ db SILPH_CO_5F, $04, $07, $0C
+ db SILPH_CO_5F, $05, $07, $0D
+ db SILPH_CO_6F, $0C, $05, $0E
+ db SILPH_CO_6F, $0D, $05, $0F
+ db SILPH_CO_8F, $08, $07, $10
+ db SILPH_CO_8F, $09, $07, $11
+ db SILPH_CO_9F, $08, $03, $12
+ db SILPH_CO_9F, $09, $03, $13
db $ff
CardKeyTable3:
- db SILPH_CO_11F,$08,$09,$14
- db SILPH_CO_11F,$09,$09,$15
+ db SILPH_CO_11F, $08, $09, $14
+ db SILPH_CO_11F, $09, $09, $15
db $ff
ItemUsePokedoll:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
dec a
- jp nz,ItemUseNotTime
- ld a,$01
- ld [wEscapedFromBattle],a
+ jp nz, ItemUseNotTime
+ ld a, $01
+ ld [wEscapedFromBattle], a
jp PrintItemUseTextAndRemoveItem
ItemUseGuardSpec:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp z,ItemUseNotTime
- ld hl,wPlayerBattleStatus2
- set ProtectedByMist,[hl] ; Mist bit
+ jp z, ItemUseNotTime
+
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callabd_ModifyPikachuHappiness PIKAHAPPY_USEDXITEM
+ pop af
+ ld [wWhichPokemon], a
+
+ ld hl, wPlayerBattleStatus2
+ set ProtectedByMist, [hl] ; Mist bit
jp PrintItemUseTextAndRemoveItem
ItemUseSuperRepel:
- ld b,200
+ ld b, 200
jp ItemUseRepelCommon
ItemUseMaxRepel:
- ld b,250
+ ld b, 250
jp ItemUseRepelCommon
ItemUseDireHit:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp z,ItemUseNotTime
- ld hl,wPlayerBattleStatus2
- set GettingPumped,[hl] ; Focus Energy bit
+ jp z, ItemUseNotTime
+
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callabd_ModifyPikachuHappiness PIKAHAPPY_USEDXITEM
+ pop af
+ ld [wWhichPokemon], a
+
+ ld hl, wPlayerBattleStatus2
+ set GettingPumped, [hl] ; Focus Energy bit
jp PrintItemUseTextAndRemoveItem
ItemUseXStat:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jr nz,.inBattle
+ jr nz, .inBattle
call ItemUseNotTime
- ld a,2
- ld [wActionResultOrTookBattleTurn],a ; item not used
+ ld a, 2
+ ld [wActionResultOrTookBattleTurn], a ; item not used
ret
+
.inBattle
- ld hl,wPlayerMoveNum
- ld a,[hli]
+ ld hl, wPlayerMoveNum
+ ld a, [hli]
push af ; save [wPlayerMoveNum]
- ld a,[hl]
+ ld a, [hl]
push af ; save [wPlayerMoveEffect]
push hl
- ld a,[wcf91]
- sub a,X_ATTACK - ATTACK_UP1_EFFECT
- ld [hl],a ; store player move effect
+ ld a, [wcf91]
+ sub X_ATTACK - ATTACK_UP1_EFFECT
+ ld [hl], a ; store player move effect
call PrintItemUseTextAndRemoveItem
- ld a,XSTATITEM_ANIM ; X stat item animation ID
- ld [wPlayerMoveNum],a
+ ld a, XSTATITEM_ANIM ; X stat item animation ID
+ ld [wPlayerMoveNum], a
call LoadScreenTilesFromBuffer1 ; restore saved screen
call Delay3
xor a
- ld [H_WHOSETURN],a ; set turn to player's turn
+ ld [H_WHOSETURN], a ; set turn to player's turn
callba StatModifierUpEffect ; do stat increase move
+
+ ld a, [wWhichPokemon]
+ push af
+ ld a, [wPlayerMonNumber]
+ ld [wWhichPokemon], a
+ callabd_ModifyPikachuHappiness PIKAHAPPY_USEDXITEM
+ pop af
+ ld [wWhichPokemon], a
+
pop hl
pop af
- ld [hld],a ; restore [wPlayerMoveEffect]
+ ld [hld], a ; restore [wPlayerMoveEffect]
pop af
- ld [hl],a ; restore [wPlayerMoveNum]
+ ld [hl], a ; restore [wPlayerMoveNum]
ret
ItemUsePokeflute:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jr nz,.inBattle
+ jr nz, .inBattle
; if not in battle
call ItemUseReloadOverworldData
- ld a,[wCurMap]
- cp a,ROUTE_12
- jr nz,.notRoute12
+ ld a, [wCurMap]
+ cp ROUTE_12
+ jr nz, .notRoute12
CheckEvent EVENT_BEAT_ROUTE12_SNORLAX
- jr nz,.noSnorlaxToWakeUp
+ jr nz, .noSnorlaxOrPikachuToWakeUp
; if the player hasn't beaten Route 12 Snorlax
- ld hl,Route12SnorlaxFluteCoords
+ ld hl, Route12SnorlaxFluteCoords
call ArePlayerCoordsInArray
- jr nc,.noSnorlaxToWakeUp
- ld hl,PlayedFluteHadEffectText
+ jr nc, .noSnorlaxOrPikachuToWakeUp
+ ld hl, PlayedFluteHadEffectText
call PrintText
SetEvent EVENT_FIGHT_ROUTE12_SNORLAX
ret
+
.notRoute12
- cp a,ROUTE_16
- jr nz,.noSnorlaxToWakeUp
+ cp ROUTE_16
+ jr nz, .notRoute16
CheckEvent EVENT_BEAT_ROUTE16_SNORLAX
- jr nz,.noSnorlaxToWakeUp
+ jr nz, .noSnorlaxOrPikachuToWakeUp
; if the player hasn't beaten Route 16 Snorlax
- ld hl,Route16SnorlaxFluteCoords
+ ld hl, Route16SnorlaxFluteCoords
call ArePlayerCoordsInArray
- jr nc,.noSnorlaxToWakeUp
- ld hl,PlayedFluteHadEffectText
+ jr nc, .noSnorlaxOrPikachuToWakeUp
+ ld hl, PlayedFluteHadEffectText
call PrintText
SetEvent EVENT_FIGHT_ROUTE16_SNORLAX
ret
-.noSnorlaxToWakeUp
- ld hl,PlayedFluteNoEffectText
+
+.notRoute16
+ cp PEWTER_POKECENTER
+ jr nz, .noSnorlaxOrPikachuToWakeUp
+ call CheckPikachuFollowingPlayer
+ jr z, .noSnorlaxOrPikachuToWakeUp
+ callab IsPikachuRightNextToPlayer
+ jr nc, .noSnorlaxOrPikachuToWakeUp
+ ld hl, PlayedFluteHadEffectText
+ call PrintText
+ call ItemUseReloadOverworldData
+ ldpikaemotion e, PikachuEmotion26
+ callab PlaySpecificPikachuEmotion
+ ret
+
+.noSnorlaxOrPikachuToWakeUp
+ ld hl, PlayedFluteNoEffectText
jp PrintText
+
.inBattle
xor a
- ld [wWereAnyMonsAsleep],a
- ld b,~SLP & $ff
- ld hl,wPartyMon1Status
+ ld [wWereAnyMonsAsleep], a
+ ld b, $ff ^ SLP
+ ld hl, wPartyMon1Status
call WakeUpEntireParty
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
dec a ; is it a trainer battle?
- jr z,.skipWakingUpEnemyParty
+ jr z, .skipWakingUpEnemyParty
; if it's a trainer battle
- ld hl,wEnemyMon1Status
+ ld hl, wEnemyMon1Status
call WakeUpEntireParty
.skipWakingUpEnemyParty
- ld hl,wBattleMonStatus
- ld a,[hl]
+ ld hl, wBattleMonStatus
+ ld a, [hl]
and b ; remove Sleep status
- ld [hl],a
- ld hl,wEnemyMonStatus
- ld a,[hl]
+ ld [hl], a
+ ld hl, wEnemyMonStatus
+ ld a, [hl]
+ ld c, a
and b ; remove Sleep status
- ld [hl],a
+ ld [hl], a
+ ld a, c
+ and SLP
+ jr z, .asm_e063
+ ld a, $1
+ ld [wWereAnyMonsAsleep], a
+.asm_e063
call LoadScreenTilesFromBuffer2 ; restore saved screen
- ld a,[wWereAnyMonsAsleep]
+ ld a, [wWereAnyMonsAsleep]
and a ; were any pokemon asleep before playing the flute?
- ld hl,PlayedFluteNoEffectText
- jp z,PrintText ; if no pokemon were asleep
+ ld hl, PlayedFluteNoEffectText
+ jp z, PrintText ; if no pokemon were asleep
; if some pokemon were asleep
- ld hl,PlayedFluteHadEffectText
+ ld hl, PlayedFluteHadEffectText
call PrintText
- ld a,[wLowHealthAlarm]
- and a,$80
- jr nz,.skipMusic
+ ld a, [wLowHealthAlarm]
+ and $80
+ jr nz, .skipMusic
call WaitForSoundToFinish ; wait for sound to end
callba Music_PokeFluteInBattle ; play in-battle pokeflute music
.musicWaitLoop ; wait for music to finish playing
- ld a,[wChannelSoundIDs + CH6]
+ ld a, [wChannelSoundIDs + CH6]
and a ; music off?
- jr nz,.musicWaitLoop
+ jr nz, .musicWaitLoop
.skipMusic
- ld hl,FluteWokeUpText
+ ld hl, FluteWokeUpText
jp PrintText
; wakes up all party pokemon
@@ -1790,40 +1993,40 @@ ItemUsePokeflute:
; OUTPUT:
; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep
WakeUpEntireParty:
- ld de,44
- ld c,6
+ ld de, 44
+ ld c, 6
.loop
- ld a,[hl]
+ ld a, [hl]
push af
- and a,SLP ; is pokemon asleep?
- jr z,.notAsleep
- ld a,1
- ld [wWereAnyMonsAsleep],a ; indicate that a pokemon had to be woken up
+ and SLP ; is pokemon asleep?
+ jr z, .notAsleep
+ ld a, 1
+ ld [wWereAnyMonsAsleep], a ; indicate that a pokemon had to be woken up
.notAsleep
pop af
and b ; remove Sleep status
- ld [hl],a
- add hl,de
+ ld [hl], a
+ add hl, de
dec c
- jr nz,.loop
+ jr nz, .loop
ret
; Format:
; 00: Y
; 01: X
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
- db 62,11 ; one space East of Snorlax
+ db 62, 9 ; one space West of Snorlax
+ db 61, 10 ; one space North of Snorlax
+ db 63, 10 ; one space South of Snorlax
+ db 62, 11 ; one space East of Snorlax
db $ff ; terminator
; Format:
; 00: Y
; 01: X
Route16SnorlaxFluteCoords:
- db 10,27 ; one space East of Snorlax
- db 10,25 ; one space West of Snorlax
+ db 10, 27 ; one space East of Snorlax
+ db 10, 25 ; one space West of Snorlax
db $ff ; terminator
PlayedFluteNoEffectText:
@@ -1838,28 +2041,27 @@ PlayedFluteHadEffectText:
TX_FAR _PlayedFluteHadEffectText
db $06
TX_ASM
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jr nz,.done
+ jr nz, .done
; play out-of-battle pokeflute music
- ld a,$ff
- call PlaySound ; turn off music
- ld a, SFX_POKEFLUE
+ call StopAllMusic ; turn off music
+ ld a, SFX_POKEFLUTE
ld c, BANK(SFX_Pokeflute)
call PlayMusic
.musicWaitLoop ; wait for music to finish playing
- ld a,[wChannelSoundIDs + CH2]
- cp a, SFX_POKEFLUE
- jr z,.musicWaitLoop
+ ld a, [wChannelSoundIDs + CH2]
+ cp SFX_POKEFLUTE
+ jr z, .musicWaitLoop
call PlayDefaultMusic ; start playing normal music again
.done
jp TextScriptEnd ; end text
ItemUseCoinCase:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
- ld hl,CoinCaseNumCoinsText
+ jp nz, ItemUseNotTime
+ ld hl, CoinCaseNumCoinsText
jp PrintText
CoinCaseNumCoinsText:
@@ -1875,7 +2077,7 @@ ItemUseOldRod:
ItemUseGoodRod:
call FishingInit
- jp c,ItemUseNotTime
+ jp c, ItemUseNotTime
.RandomLoop
call Random
srl a
@@ -1884,17 +2086,17 @@ ItemUseGoodRod:
cp 2
jr nc, .RandomLoop
; choose which monster appears
- ld hl,GoodRodMons
- add a,a
- ld c,a
- ld b,0
- add hl,bc
- ld b,[hl]
+ ld hl, GoodRodMons
+ add a
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld b, [hl]
inc hl
- ld c,[hl]
+ ld c, [hl]
and a
.SetBite
- ld a,0
+ ld a, 0
rla
xor 1
jr RodResponse
@@ -1904,13 +2106,28 @@ INCLUDE "data/good_rod.asm"
ItemUseSuperRod:
call FishingInit
jp c, ItemUseNotTime
- call ReadSuperRodData
- ld a, e
+ callab ReadSuperRodData
+ ld c, e
+ ld b, d
+ ld a, $2
+ ld [wRodResponse], a
+ ld a, c
+ and a ; are there fish in the map?
+ jr z, DoNotGenerateFishingEncounter ; if not, do not generate an encounter
+ ld a, $1
+ ld [wRodResponse], a
+ call Random
+ and $1
+ jr nz, RodResponse
+ xor a
+ ld [wRodResponse], a
+ jr DoNotGenerateFishingEncounter
+
RodResponse:
ld [wRodResponse], a
dec a ; is there a bite?
- jr nz, .next
+ jr nz, DoNotGenerateFishingEncounter
; if yes, store level and species data
ld a, 1
ld [wMoveMissed], a
@@ -1919,7 +2136,7 @@ RodResponse:
ld a, c ; species
ld [wCurOpponent], a
-.next
+DoNotGenerateFishingEncounter:
ld hl, wWalkBikeSurfState
ld a, [hl] ; store the value in a
push af
@@ -1934,27 +2151,33 @@ RodResponse:
; 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:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jr z,.notInBattle
+ jr z, .notInBattle
scf ; can't fish during battle
ret
+
.notInBattle
call IsNextTileShoreOrWater
- ret c
- ld a,[wWalkBikeSurfState]
- cp a,2 ; Surfing?
- jr z,.surfing
+ jr nc, .cannotFish
+ ld a, [wWalkBikeSurfState]
+ cp 2 ; Surfing?
+ jr z, .cannotFish
call ItemUseReloadOverworldData
- ld hl,ItemUseText00
+ ld hl, ItemUseText00
call PrintText
- ld a,SFX_HEAL_AILMENT
+ ld a, SFX_HEAL_AILMENT
call PlaySound
- ld c,80
+ ld a, $2
+ ld [wd49c], a
+ ld a, $81
+ ld [wPikachuMood], a
+ ld c, 80
call DelayFrames
and a
ret
-.surfing
+
+.cannotFish
scf ; can't fish when surfing
ret
@@ -1962,22 +2185,22 @@ ItemUseOaksParcel:
jp ItemUseNotYoursToUse
ItemUseItemfinder:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
+ jp nz, ItemUseNotTime
call ItemUseReloadOverworldData
callba HiddenItemNear ; check for hidden items
- ld hl,ItemfinderFoundNothingText
- jr nc,.printText ; if no hidden items
- ld c,4
+ ld hl, ItemfinderFoundNothingText
+ jr nc, .printText ; if no hidden items
+ ld c, 4
.loop
- ld a,SFX_HEALING_MACHINE
+ ld a, SFX_HEALING_MACHINE
call PlaySoundWaitForCurrent
- ld a,SFX_PURCHASE
+ ld a, SFX_PURCHASE
call PlaySoundWaitForCurrent
dec c
- jr nz,.loop
- ld hl,ItemfinderFoundItemText
+ jr nz, .loop
+ ld hl, ItemfinderFoundItemText
.printText
jp PrintText
@@ -1990,54 +2213,70 @@ ItemfinderFoundNothingText:
db "@"
ItemUsePPUp:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
+ jp nz, ItemUseNotTime
ItemUsePPRestore:
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
push af
- ld a,[wcf91]
- ld [wPPRestoreItem],a
+ ld a, [wcf91]
+ ld [wPPRestoreItem], a
.chooseMon
xor a
- ld [wUpdateSpritesEnabled],a
- ld a,USE_ITEM_PARTY_MENU
- ld [wPartyMenuTypeOrMessageID],a
+ ld [wUpdateSpritesEnabled], a
+ ld a, USE_ITEM_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
call DisplayPartyMenu
- jr nc,.chooseMove
+ jr nc, .chooseMove
jp .itemNotUsed
+
.chooseMove
- 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,[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
+ ld a, [wIsInBattle]
+ and a
+ jr z, .usePPItem
+ ld a, [wWhichPokemon]
+ ld b, a
+ ld a, [wPlayerMonNumber]
+ cp b
+ jr nz, .usePPItem
+ ld a, [wPlayerBattleStatus3]
+ bit Transformed, a
+ jr z, .usePPItem
+ call ItemUseNotTime
+ jp .itemNotUsed
+
+.usePPItem
+ ld a, [wPPRestoreItem]
+ cp ELIXER
+ jp nc, .useElixir ; if Elixir or Max Elixir
+ ld a, $02
+ ld [wMoveMenuType], a
+ ld hl, RaisePPWhichTechniqueText
+ ld a, [wPPRestoreItem]
+ cp 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
.printWhichTechniqueMessage
call PrintText
xor a
- ld [wPlayerMoveListIndex],a
+ ld [wPlayerMoveListIndex], a
callab MoveSelectionMenu ; move selection menu
- ld a,0
- ld [wPlayerMoveListIndex],a
- jr nz,.chooseMon
- ld hl,wPartyMon1Moves
+ ld a, 0
+ ld [wPlayerMoveListIndex], a
+ jr nz, .chooseMon
+ ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
push hl
- ld a,[hl]
- ld [wd11e],a
+ ld a, [hl]
+ ld [wd11e], a
call GetMoveName
call CopyStringToCF4B ; copy name to wcf4b
pop hl
- ld a,[wPPRestoreItem]
- cp a,ETHER
- jr nc,.useEther ; if Ether or Max Ether
+ ld a, [wPPRestoreItem]
+ cp ETHER
+ jr nc, .useEther ; if Ether or Max Ether
.usePPUp
ld bc,wPartyMon1PP - wPartyMon1Moves
add hl,bc
@@ -2047,79 +2286,86 @@ ItemUsePPRestore:
ld hl,PPMaxedOutText
call PrintText
jr .chooseMove
+
.PPNotMaxedOut
- ld a,[hl]
- add a,1 << 6 ; increase PP Up count by 1
- ld [hl],a
- ld a,1 ; 1 PP Up used
- ld [wd11e],a
+ ld a, [hl]
+ add 1 << 6 ; increase PP Up count by 1
+ ld [hl], a
+ ld a, 1 ; 1 PP Up used
+ ld [wd11e], a
call RestoreBonusPP ; add the bonus PP to current PP
- ld hl,PPIncreasedText
+ ld a, SFX_HEAL_AILMENT
+ call PlaySound
+ ld hl, PPIncreasedText
call PrintText
.done
pop af
- ld [wWhichPokemon],a
+ ld [wWhichPokemon], a
call GBPalWhiteOut
call RunDefaultPaletteCommand
jp RemoveUsedItem
+
.afterRestoringPP ; after using a (Max) Ether/Elixir
- ld a,[wWhichPokemon]
- ld b,a
- ld a,[wPlayerMonNumber]
+ ld a, [wWhichPokemon]
+ ld b, a
+ ld a, [wPlayerMonNumber]
cp b ; is the pokemon whose PP was restored active in battle?
- jr nz,.skipUpdatingInBattleData
- ld hl,wPartyMon1PP
+ jr nz, .skipUpdatingInBattleData
+ ld hl, wPartyMon1PP
ld bc, wPartyMon2 - wPartyMon1
call AddNTimes
- ld de,wBattleMonPP
- ld bc,4
+ ld de, wBattleMonPP
+ ld bc, 4
call CopyData ; copy party data to in-battle data
.skipUpdatingInBattleData
- ld a,SFX_HEAL_AILMENT
+ ld a, SFX_HEAL_AILMENT
call PlaySound
- ld hl,PPRestoredText
+ ld hl, PPRestoredText
call PrintText
jr .done
+
.useEther
call .restorePP
- jr nz,.afterRestoringPP
+ jr nz, .afterRestoringPP
jp .noEffect
+
; 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 ; PLAYER_PARTY_DATA
- ld [wMonDataLocation],a
+ ld [wMonDataLocation], a
call GetMaxPP
- ld hl,wPartyMon1Moves
+ ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
ld bc, wPartyMon1PP - wPartyMon1Moves
- add hl,bc ; hl now points to move's PP
- ld a,[wMaxPP]
- ld b,a
- ld a,[wPPRestoreItem]
- cp a,MAX_ETHER
- jr z,.fullyRestorePP
- ld a,[hl] ; move PP
- and a,%00111111 ; lower 6 bit bits store current PP
+ add hl, bc ; hl now points to move's PP
+ ld a, [wMaxPP]
+ ld b, a
+ ld a, [wPPRestoreItem]
+ cp MAX_ETHER
+ jr z, .fullyRestorePP
+ ld a, [hl] ; move PP
+ and %00111111 ; lower 6 bit bits store current PP
cp b ; does current PP equal max PP?
ret z ; if so, return
- add a,10 ; increase current PP by 10
+ add 10 ; increase current PP by 10
; b holds the max PP amount and b will hold the new PP amount.
; So, if the new amount meets or exceeds the max amount,
; cap the amount to the max amount by leaving b unchanged.
; Otherwise, store the new amount in b.
cp b ; does the new amount meet or exceed the maximum?
- jr nc,.storeNewAmount
- ld b,a
+ jr nc, .storeNewAmount
+ ld b, a
.storeNewAmount
- ld a,[hl] ; move PP
- and a,%11000000 ; PP Up counter bits
+ ld a, [hl] ; move PP
+ and %11000000 ; PP Up counter bits
add b
- ld [hl],a
+ ld [hl], a
ret
+
.fullyRestorePP
- ld a,[hl] ; move PP
+ ld a, [hl] ; move PP
; Note that this code has a bug. It doesn't mask out the upper two bits, which
; are used to count how many PP Ups have been used on the move. So, Max Ethers
; and Max Elixirs will not be detected as having no effect on a move with full
@@ -2127,39 +2373,40 @@ ItemUsePPRestore:
cp b ; does current PP equal max PP?
ret z
jr .storeNewAmount
+
.useElixir
; decrement the item ID so that ELIXER becomes ETHER and MAX_ELIXER becomes MAX_ETHER
- ld hl,wPPRestoreItem
+ ld hl, wPPRestoreItem
dec [hl]
dec [hl]
xor a
- ld hl,wCurrentMenuItem
- ld [hli],a
- ld [hl],a ; zero the counter for number of moves that had their PP restored
- ld b,4
+ ld hl, wCurrentMenuItem
+ ld [hli], a
+ ld [hl], a ; zero the counter for number of moves that had their PP restored
+ ld b, 4
; loop through each move and restore PP
.elixirLoop
push bc
- ld hl,wPartyMon1Moves
+ ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
call GetSelectedMoveOffset
- ld a,[hl]
+ ld a, [hl]
and a ; does the current slot have a move?
- jr z,.nextMove
+ jr z, .nextMove
call .restorePP
- jr z,.nextMove
+ jr z, .nextMove
; if some PP was restored
- ld hl,wTileBehindCursor ; counter for number of moves that had their PP restored
+ ld hl, wTileBehindCursor ; counter for number of moves that had their PP restored
inc [hl]
.nextMove
- ld hl,wCurrentMenuItem
+ ld hl, wCurrentMenuItem
inc [hl]
pop bc
dec b
- jr nz,.elixirLoop
- ld a,[wTileBehindCursor]
+ jr nz, .elixirLoop
+ ld a, [wTileBehindCursor]
and a ; did any moves have their PP restored?
- jp nz,.afterRestoringPP
+ jp nz, .afterRestoringPP
.noEffect
call ItemUseNoEffect
.itemNotUsed
@@ -2167,7 +2414,7 @@ ItemUsePPRestore:
call RunDefaultPaletteCommand
pop af
xor a
- ld [wActionResultOrTookBattleTurn],a ; item use failed
+ ld [wActionResultOrTookBattleTurn], a ; item use failed
ret
RaisePPWhichTechniqueText:
@@ -2195,63 +2442,64 @@ UnusableItem:
jp ItemUseNotTime
ItemUseTMHM:
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
- ld a,[wcf91]
- sub a,TM_01
+ jp nz, ItemUseNotTime
+ ld a, [wcf91]
+ sub TM_01
push af
- jr nc,.skipAdding
- add a,55 ; if item is an HM, add 55
+ jr nc, .skipAdding
+ add 55 ; if item is an HM, add 55
.skipAdding
inc a
- ld [wd11e],a
+ ld [wd11e], a
predef TMToMove ; get move ID from TM/HM ID
- ld a,[wd11e]
- ld [wMoveNum],a
+ ld a, [wd11e]
+ ld [wMoveNum], a
call GetMoveName
call CopyStringToCF4B ; copy name to wcf4b
pop af
- ld hl,BootedUpTMText
- jr nc,.printBootedUpMachineText
- ld hl,BootedUpHMText
+ ld hl, BootedUpTMText
+ jr nc, .printBootedUpMachineText
+ ld hl, BootedUpHMText
.printBootedUpMachineText
call PrintText
- ld hl,TeachMachineMoveText
+ ld hl, TeachMachineMoveText
call PrintText
coord hl, 14, 7
lb bc, 8, 15
- ld a,TWO_OPTION_MENU
- ld [wTextBoxID],a
+ ld a, TWO_OPTION_MENU
+ ld [wTextBoxID], a
call DisplayTextBoxID ; yes/no menu
- ld a,[wCurrentMenuItem]
+ ld a, [wCurrentMenuItem]
and a
- jr z,.useMachine
- ld a,2
- ld [wActionResultOrTookBattleTurn],a ; item not used
+ jr z, .useMachine
+ ld a, 2
+ ld [wActionResultOrTookBattleTurn], a ; item not used
ret
+
.useMachine
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
push af
- ld a,[wcf91]
+ ld a, [wcf91]
push af
.chooseMon
- ld hl,wcf4b
- ld de,wTempMoveNameBuffer
- ld bc,14
+ ld hl, wcf4b
+ ld de, wTempMoveNameBuffer
+ ld bc, 14
call CopyData ; save the move name because DisplayPartyMenu will overwrite it
- ld a,$ff
- ld [wUpdateSpritesEnabled],a
- ld a,TMHM_PARTY_MENU
- ld [wPartyMenuTypeOrMessageID],a
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ ld a, TMHM_PARTY_MENU
+ ld [wPartyMenuTypeOrMessageID], a
call DisplayPartyMenu
push af
- ld hl,wTempMoveNameBuffer
- ld de,wcf4b
- ld bc,14
+ ld hl, wTempMoveNameBuffer
+ ld de, wcf4b
+ ld bc, 14
call CopyData
pop af
- jr nc,.checkIfAbleToLearnMove
+ jr nc, .checkIfAbleToLearnMove
; if the player canceled teaching the move
pop af
pop af
@@ -2262,31 +2510,56 @@ ItemUseTMHM:
.checkIfAbleToLearnMove
predef CanLearnTM ; check if the pokemon can learn the move
push bc
- ld a,[wWhichPokemon]
- ld hl,wPartyMonNicks
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMonNicks
call GetPartyMonName
pop bc
- ld a,c
+ ld a, c
and a ; can the pokemon learn the move?
- jr nz,.checkIfAlreadyLearnedMove
+ jr nz, .checkIfAlreadyLearnedMove
; if the pokemon can't learn the move
- ld a,SFX_DENIED
+ ld a, SFX_DENIED
call PlaySoundWaitForCurrent
- ld hl,MonCannotLearnMachineMoveText
+ ld hl, MonCannotLearnMachineMoveText
call PrintText
jr .chooseMon
+
.checkIfAlreadyLearnedMove
callab CheckIfMoveIsKnown ; check if the pokemon already knows the move
- jr c,.chooseMon
+ jr c, .chooseMon
predef LearnMove ; teach move
+ ld a, [wWhichPokemon]
+ ld d, a
pop af
- ld [wcf91],a
+ ld [wcf91], a
pop af
- ld [wWhichPokemon],a
- ld a,b
+ ld [wWhichPokemon], a
+ ld a, b
and a
ret z
- ld a,[wcf91]
+
+ ld a, [wWhichPokemon]
+ push af
+ ld a, d
+ ld [wWhichPokemon], a
+ callabd_ModifyPikachuHappiness PIKAHAPPY_USEDTMHM
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .notTeachingThunderboltOrThunderToPikachu
+ ld a, [wcf91]
+ cp TM_24 ; are we teaching thunderbolt to the player pikachu?
+ jr z, .teachingThunderboltOrThunderToPlayerPikachu
+ cp TM_25 ; are we teaching thunder then?
+ jr nz, .notTeachingThunderboltOrThunderToPikachu
+.teachingThunderboltOrThunderToPlayerPikachu
+ ld a, $5
+ ld [wd49c], a
+ ld a, $85
+ ld [wPikachuMood], a
+.notTeachingThunderboltOrThunderToPikachu
+ pop af
+ ld [wWhichPokemon], a
+
+ ld a, [wcf91]
call IsItemHM
ret c
jp RemoveUsedItem
@@ -2308,57 +2581,63 @@ MonCannotLearnMachineMoveText:
db "@"
PrintItemUseTextAndRemoveItem:
- ld hl,ItemUseText00
+ ld hl, ItemUseText00
call PrintText
- ld a,SFX_HEAL_AILMENT
+ ld a, SFX_HEAL_AILMENT
call PlaySound
call WaitForTextScrollButtonPress ; wait for button press
RemoveUsedItem:
- ld hl,wNumBagItems
- ld a,1 ; one item
- ld [wItemQuantity],a
+ ld hl, wNumBagItems
+ ld a, 1 ; one item
+ ld [wItemQuantity], a
jp RemoveItemFromInventory
ItemUseNoEffect:
- ld hl,ItemUseNoEffectText
+ ld hl, ItemUseNoEffectText
jr ItemUseFailed
ItemUseNotTime:
- ld hl,ItemUseNotTimeText
+ ld hl, ItemUseNotTimeText
jr ItemUseFailed
ItemUseNotYoursToUse:
- ld hl,ItemUseNotYoursToUseText
+ ld hl, ItemUseNotYoursToUseText
jr ItemUseFailed
+Func_e4bf:
+ ld a, $2
+ ld [wActionResultOrTookBattleTurn], a
+ ld hl, DontHavePokemonText
+ jp PrintText
+
ThrowBallAtTrainerMon:
call RunDefaultPaletteCommand
call LoadScreenTilesFromBuffer1 ; restore saved screen
call Delay3
- ld a,TOSS_ANIM
- ld [wAnimationID],a
+ ld a, TOSS_ANIM
+ ld [wAnimationID], a
predef MoveAnimation ; do animation
- ld hl,ThrowBallAtTrainerMonText1
+ ld hl, ThrowBallAtTrainerMonText1
call PrintText
- ld hl,ThrowBallAtTrainerMonText2
+ ld hl, ThrowBallAtTrainerMonText2
call PrintText
jr RemoveUsedItem
NoCyclingAllowedHere:
- ld hl,NoCyclingAllowedHereText
+ ld hl, NoCyclingAllowedHereText
jr ItemUseFailed
BoxFullCannotThrowBall:
- ld hl,BoxFullCannotThrowBallText
+ ld hl, BoxFullCannotThrowBallText
jr ItemUseFailed
SurfingAttemptFailed:
- ld hl,NoSurfingHereText
+ ld hl, NoSurfingHereText
ItemUseFailed:
xor a
- ld [wActionResultOrTookBattleTurn],a ; item use failed
+ ld [wActionResultOrTookBattleTurn], a ; item use failed
jp PrintText
ItemUseNotTimeText:
@@ -2393,6 +2672,10 @@ BoxFullCannotThrowBallText:
TX_FAR _BoxFullCannotThrowBallText
db "@"
+DontHavePokemonText:
+ TX_FAR _DontHavePokemonText
+ db "@"
+
ItemUseText00:
TX_FAR _ItemUseText001
db $05
@@ -2417,37 +2700,37 @@ GotOffBicycleText:
; [wWhichPokemon] = index of pokemon in party
; [wCurrentMenuItem] = index of move (when using a PP Up)
RestoreBonusPP:
- ld hl,wPartyMon1Moves
+ ld hl, wPartyMon1Moves
ld bc, wPartyMon2 - wPartyMon1
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
call AddNTimes
push hl
- ld de,wNormalMaxPPList - 1
+ ld de, wNormalMaxPPList - 1
predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList
pop hl
ld c, wPartyMon1PP - wPartyMon1Moves
- ld b,0
- add hl,bc ; hl now points to move 1 PP
- ld de,wNormalMaxPPList
- ld b,0 ; initialize move counter to zero
+ ld b, 0
+ add hl, bc ; hl now points to move 1 PP
+ ld de, wNormalMaxPPList
+ ld b, 0 ; initialize move counter to zero
; loop through the pokemon's moves
.loop
inc b
- ld a,b
- cp a,5 ; reached the end of the pokemon's moves?
+ ld a, b
+ cp 5 ; reached the end of the pokemon's moves?
ret z ; if so, return
- ld a,[wUsingPPUp]
+ ld a, [wUsingPPUp]
dec a ; using a PP Up?
- jr nz,.skipMenuItemIDCheck
+ jr nz, .skipMenuItemIDCheck
; if using a PP Up, check if this is the move it's being used on
- ld a,[wCurrentMenuItem]
+ ld a, [wCurrentMenuItem]
inc a
cp b
- jr nz,.nextMove
+ jr nz, .nextMove
.skipMenuItemIDCheck
- ld a,[hl]
- and a,%11000000 ; have any PP Ups been used?
- call nz,AddBonusPP ; if so, add bonus PP
+ ld a, [hl]
+ and %11000000 ; have any PP Ups been used?
+ call nz, AddBonusPP ; if so, add bonus PP
.nextMove
inc hl
inc de
@@ -2460,38 +2743,38 @@ RestoreBonusPP:
; [hl] = move PP
AddBonusPP:
push bc
- ld a,[de] ; normal max PP of move
- ld [H_DIVIDEND + 3],a
+ ld a, [de] ; normal max PP of move
+ ld [H_DIVIDEND + 3], a
xor a
- ld [H_DIVIDEND],a
- ld [H_DIVIDEND + 1],a
- ld [H_DIVIDEND + 2],a
- ld a,5
- ld [H_DIVISOR],a
- ld b,4
+ ld [H_DIVIDEND], a
+ ld [H_DIVIDEND + 1], a
+ ld [H_DIVIDEND + 2], a
+ ld a, 5
+ ld [H_DIVISOR], a
+ ld b, 4
call Divide
- ld a,[hl] ; move PP
- ld b,a
+ ld a, [hl] ; move PP
+ ld b, a
swap a
- and a,%00001111
+ and %1111
srl a
srl a
- ld c,a ; c = number of PP Ups used
+ ld c, a ; c = number of PP Ups used
.loop
- ld a,[H_QUOTIENT + 3]
- cp a,8 ; is the amount greater than or equal to 8?
- jr c,.addAmount
- ld a,7 ; cap the amount at 7
+ ld a, [H_QUOTIENT + 3]
+ cp 8 ; is the amount greater than or equal to 8?
+ jr c, .addAmount
+ ld a, 7 ; cap the amount at 7
.addAmount
add b
- ld b,a
- ld a,[wUsingPPUp]
+ ld b, a
+ ld a, [wUsingPPUp]
dec a ; is the player using a PP Up right now?
- jr z,.done ; if so, only add the bonus once
+ jr z, .done ; if so, only add the bonus once
dec c
- jr nz,.loop
+ jr nz, .loop
.done
- ld [hl],b
+ ld [hl], b
pop bc
ret
@@ -2508,74 +2791,75 @@ AddBonusPP:
; OUTPUT:
; [wMaxPP] = max PP
GetMaxPP:
- ld a,[wMonDataLocation]
+ ld a, [wMonDataLocation]
and a
- ld hl,wPartyMon1Moves
- ld bc,wPartyMon2 - wPartyMon1
- jr z,.sourceWithMultipleMon
- ld hl,wEnemyMon1Moves
+ ld hl, wPartyMon1Moves
+ ld bc, wPartyMon2 - wPartyMon1
+ jr z, .sourceWithMultipleMon
+ ld hl, wEnemyMon1Moves
dec a
- jr z,.sourceWithMultipleMon
- ld hl,wBoxMon1Moves
- ld bc,wBoxMon2 - wBoxMon1
+ jr z, .sourceWithMultipleMon
+ ld hl, wBoxMon1Moves
+ ld bc, wBoxMon2 - wBoxMon1
dec a
- jr z,.sourceWithMultipleMon
- ld hl,wDayCareMonMoves
+ jr z, .sourceWithMultipleMon
+ ld hl, wDayCareMonMoves
dec a
- jr z,.sourceWithOneMon
- ld hl,wBattleMonMoves ; player's in-battle pokemon
+ jr z, .sourceWithOneMon
+ ld hl, wBattleMonMoves ; player's in-battle pokemon
.sourceWithOneMon
call GetSelectedMoveOffset2
jr .next
+
.sourceWithMultipleMon
call GetSelectedMoveOffset
.next
- ld a,[hl]
+ ld a, [hl]
dec a
push hl
- ld hl,Moves
- ld bc,MoveEnd - Moves
+ ld hl, Moves
+ ld bc, MoveEnd - Moves
call AddNTimes
- ld de,wcd6d
- ld a,BANK(Moves)
+ ld de, wcd6d
+ ld a, BANK(Moves)
call FarCopyData
- ld de,wcd6d + 5 ; PP is byte 5 of move data
- ld a,[de]
- ld b,a ; b = normal max PP
+ 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,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,wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data
+ ld bc, wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data
+ ld a, [wMonDataLocation]
+ cp 4 ; player's in-battle pokemon?
+ jr nz, .addPPOffset
+ ld bc, wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data
.addPPOffset
- add hl,bc
- ld a,[hl] ; a = current PP
- and a,%11000000 ; get PP Up count
+ add hl, bc
+ ld a, [hl] ; a = current PP
+ and %11000000 ; get PP Up count
pop bc
or b ; place normal max PP in 6 lower bits of a
- ld h,d
- ld l,e
+ ld h, d
+ ld l, e
inc hl ; hl = wcd73
- ld [hl],a
+ ld [hl], a
xor a ; add the bonus for the existing PP Up count
- ld [wUsingPPUp],a
+ ld [wUsingPPUp], a
call AddBonusPP ; add bonus PP from PP Ups
- ld a,[hl]
- and a,%00111111 ; mask out the PP Up count
- ld [wMaxPP],a ; store max PP
+ ld a, [hl]
+ and %00111111 ; mask out the PP Up count
+ ld [wMaxPP], a ; store max PP
ret
GetSelectedMoveOffset:
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
call AddNTimes
GetSelectedMoveOffset2:
- ld a,[wCurrentMenuItem]
- ld c,a
- ld b,0
- add hl,bc
+ ld a, [wCurrentMenuItem]
+ ld c, a
+ ld b, 0
+ add hl, bc
ret
; confirms the item toss and then tosses the item
@@ -2588,49 +2872,50 @@ GetSelectedMoveOffset2:
; clears carry flag if the item is tossed, sets carry flag if not
TossItem_:
push hl
- ld a,[wcf91]
+ ld a, [wcf91]
call IsItemHM
pop hl
- jr c,.tooImportantToToss
+ jr c, .tooImportantToToss
push hl
call IsKeyItem_
- ld a,[wIsKeyItem]
+ ld a, [wIsKeyItem]
pop hl
and a
- jr nz,.tooImportantToToss
+ jr nz, .tooImportantToToss
push hl
- ld a,[wcf91]
- ld [wd11e],a
+ ld a, [wcf91]
+ ld [wd11e], a
call GetItemName
call CopyStringToCF4B ; copy name to wcf4b
- ld hl,IsItOKToTossItemText
+ ld hl, IsItOKToTossItemText
call PrintText
coord hl, 14, 7
lb bc, 8, 15
- ld a,TWO_OPTION_MENU
- ld [wTextBoxID],a
+ ld a, TWO_OPTION_MENU
+ ld [wTextBoxID], a
call DisplayTextBoxID ; yes/no menu
- ld a,[wMenuExitMethod]
- cp a,CHOSE_SECOND_ITEM
+ ld a, [wMenuExitMethod]
+ cp CHOSE_SECOND_ITEM
pop hl
scf
ret z ; return if the player chose No
; if the player chose Yes
push hl
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
call RemoveItemFromInventory
- ld a,[wcf91]
- ld [wd11e],a
+ ld a, [wcf91]
+ ld [wd11e], a
call GetItemName
call CopyStringToCF4B ; copy name to wcf4b
- ld hl,ThrewAwayItemText
+ ld hl, ThrewAwayItemText
call PrintText
pop hl
and a
ret
+
.tooImportantToToss
push hl
- ld hl,TooImportantToTossText
+ ld hl, TooImportantToTossText
call PrintText
pop hl
scf
@@ -2656,32 +2941,32 @@ TooImportantToTossText:
; 00: item is not key item
; 01: item is key item
IsKeyItem_:
- ld a,$01
- ld [wIsKeyItem],a
- ld a,[wcf91]
- cp a,HM_01 ; is the item an HM or TM?
- jr nc,.checkIfItemIsHM
+ ld a, $01
+ ld [wIsKeyItem], a
+ ld a, [wcf91]
+ cp 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,wBuffer
- ld bc,15 ; only 11 bytes are actually used
+ ld hl, KeyItemBitfield
+ ld de, wBuffer
+ ld bc, 15 ; only 11 bytes are actually used
call CopyData
pop af
dec a
- ld c,a
- ld hl,wBuffer
- ld b,FLAG_TEST
+ ld c, a
+ ld hl, wBuffer
+ ld b, FLAG_TEST
predef FlagActionPredef
- ld a,c
+ ld a, c
and a
ret nz
.checkIfItemIsHM
- ld a,[wcf91]
+ ld a, [wcf91]
call IsItemHM
ret c
xor a
- ld [wIsKeyItem],a
+ ld [wIsKeyItem], a
ret
INCLUDE "data/key_items.asm"
@@ -2694,7 +2979,7 @@ SendNewMonToBox:
ld a, [wcf91]
ld [wd0b5], a
ld c, a
-.asm_e7b1
+.asm_e6f5
inc de
ld a, [de]
ld b, a
@@ -2702,13 +2987,13 @@ SendNewMonToBox:
ld c, b
ld [de], a
cp $ff
- jr nz, .asm_e7b1
+ jr nz, .asm_e6f5
call GetMonHeader
ld hl, wBoxMonOT
ld bc, NAME_LENGTH
ld a, [wNumInBox]
dec a
- jr z, .asm_e7ee
+ jr z, .asm_e732
dec a
call AddNTimes
push hl
@@ -2720,7 +3005,7 @@ SendNewMonToBox:
ld a, [wNumInBox]
dec a
ld b, a
-.asm_e7db
+.asm_e71f
push bc
push hl
ld bc, NAME_LENGTH
@@ -2732,15 +3017,15 @@ SendNewMonToBox:
add hl, bc
pop bc
dec b
- jr nz, .asm_e7db
-.asm_e7ee
+ jr nz, .asm_e71f
+.asm_e732
ld hl, wPlayerName
ld de, wBoxMonOT
ld bc, NAME_LENGTH
call CopyData
ld a, [wNumInBox]
dec a
- jr z, .asm_e82a
+ jr z, .asm_e76e
ld hl, wBoxMonNicks
ld bc, NAME_LENGTH
dec a
@@ -2754,7 +3039,7 @@ SendNewMonToBox:
ld a, [wNumInBox]
dec a
ld b, a
-.asm_e817
+.asm_e75b
push bc
push hl
ld bc, NAME_LENGTH
@@ -2766,15 +3051,15 @@ SendNewMonToBox:
add hl, bc
pop bc
dec b
- jr nz, .asm_e817
-.asm_e82a
+ jr nz, .asm_e75b
+.asm_e76e
ld hl, wBoxMonNicks
ld a, NAME_MON_SCREEN
ld [wNamingScreenType], a
predef AskName
ld a, [wNumInBox]
dec a
- jr z, .asm_e867
+ jr z, .asm_e7ab
ld hl, wBoxMons
ld bc, wBoxMon2 - wBoxMon1
dec a
@@ -2788,7 +3073,7 @@ SendNewMonToBox:
ld a, [wNumInBox]
dec a
ld b, a
-.asm_e854
+.asm_e798
push bc
push hl
ld bc, wBoxMon2 - wBoxMon1
@@ -2800,8 +3085,8 @@ SendNewMonToBox:
add hl, bc
pop bc
dec b
- jr nz, .asm_e854
-.asm_e867
+ jr nz, .asm_e798
+.asm_e7ab
ld a, [wEnemyMonLevel]
ld [wEnemyMonBoxLevel], a
ld hl, wEnemyMon
@@ -2831,11 +3116,11 @@ SendNewMonToBox:
inc de
xor a
ld b, NUM_STATS * 2
-.asm_e89f
+.asm_e7e3
ld [de], a
inc de
dec b
- jr nz, .asm_e89f
+ jr nz, .asm_e7e3
ld hl, wEnemyMonDVs
ld a, [hli]
ld [de], a
@@ -2844,12 +3129,18 @@ SendNewMonToBox:
ld [de], a
ld hl, wEnemyMonPP
ld b, NUM_MOVES
-.asm_e8b1
+.asm_e7f5
ld a, [hli]
inc de
ld [de], a
dec b
- jr nz, .asm_e8b1
+ jr nz, .asm_e7f5
+ ld a, [wcf91]
+ cp KADABRA
+ jr nz, .notKadabra
+ ld a, $60 ; twistedspoon in gsc
+ ld [wBoxMon1CatchRate], a
+.notKadabra
ret
; checks if the tile in front of the player is a shore or water tile
@@ -2858,25 +3149,22 @@ SendNewMonToBox:
IsNextTileShoreOrWater:
ld a, [wCurMapTileset]
ld hl, WaterTilesets
- ld de,1
- call IsInArray
- jr nc, .notShoreOrWater
+ ld de, 1
+ call IsInArray ; does the current map allow surfing?
+ ret nc ; if not, return
+ ld hl, WaterTile
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
- cp $48 ; eastern shore tile in Safari Zone
- jr z, .shoreOrWater
- cp $32 ; usual eastern shore tile
- jr z, .shoreOrWater
+ cp GYM ; eastern shore tile in Safari Zone
+ jr z, .skipShoreTiles
+ cp DOJO ; usual eastern shore tile
+ jr z, .skipShoreTiles
+ ld hl, ShoreTiles
.skipShoreTiles
- cp $14 ; water tile
- jr z, .shoreOrWater
-.notShoreOrWater
- scf
- ret
-.shoreOrWater
- and a
+ ld a, [wTileInFrontOfPlayer]
+ ld de, $1
+ call IsInArray
ret
; tilesets with water
@@ -2884,52 +3172,12 @@ WaterTilesets:
db OVERWORLD, FOREST, DOJO, GYM, SHIP, SHIP_PORT, CAVERN, FACILITY, PLATEAU
db $ff ; terminator
-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, [wCurMap]
- ld de, 3 ; each fishing group is three bytes wide
- ld hl, SuperRodData
- call IsInArray
- jr c, .ReadFishingGroup
- ld e, $2 ; $2 if no fishing groups found
- ret
-
-.ReadFishingGroup
-; hl points to the fishing group entry in the index
- inc hl ; skip map id
-
- ; read fishing group address
- ld a, [hli]
- ld h, [hl]
- ld l, a
-
- ld b, [hl] ; how many mons in group
- inc hl ; point to data
- ld e, $0 ; no bite yet
-
-.RandomLoop
- call Random
- srl a
- ret c ; 50% chance of no battle
-
- and %11 ; 2-bit random number
- cp b
- jr nc, .RandomLoop ; if a is greater than the number of mons, regenerate
-
- ; get the mon
- add a
- ld c, a
- ld b, $0
- add hl, bc
- ld b, [hl] ; level
- inc hl
- ld c, [hl] ; species
- ld e, $1 ; $1 if there's a bite
- ret
-
-INCLUDE "data/super_rod.asm"
+; shore tiles
+ShoreTiles:
+ db $48, $32
+WaterTile:
+ db $14
+ db $ff ; terminator
; reloads map view and processes sprite data
; for items that cause the overworld to be displayed
@@ -2963,6 +3211,7 @@ FindWildLocationsOfMon:
inc hl
inc c
jr .loop
+
.done
ld a, $ff ; list terminator
ld [de], a
diff --git a/engine/items/tms.asm b/engine/items/tms.asm
index da1b5e72..84770747 100755
--- a/engine/items/tms.asm
+++ b/engine/items/tms.asm
@@ -11,6 +11,8 @@ CanLearnTM:
ld hl, TechnicalMachines
.findTMloop
ld a, [hli]
+ cp $ff ; reached terminator?
+ jr z, .done
cp b
jr z, .TMfoundLoop
inc c
@@ -19,6 +21,10 @@ CanLearnTM:
pop hl
ld b, FLAG_TEST
predef_jump FlagActionPredef
+.done
+ pop hl
+ ld c, 0
+ ret
; converts TM/HM number in wd11e into move number
; HMs start at 51
diff --git a/engine/joypad.asm b/engine/joypad.asm
index 31e197e2..4126568c 100644
--- a/engine/joypad.asm
+++ b/engine/joypad.asm
@@ -1,12 +1,48 @@
+ReadJoypad_::
+; Poll joypad input.
+; Unlike the hardware register, button
+; presses are indicated by a set bit.
+ ld a, [hDisableJoypadPolling]
+ and a
+ ret nz
+
+ ld a, 1 << 5 ; select direction keys
+ ;ld c, 0
+
+ ld [rJOYP], a
+ ld a, [rJOYP]
+ ld a, [rJOYP]
+ cpl
+ and %1111
+ swap a
+ ld b, a
+
+ ld a, 1 << 4 ; select button keys
+ ld [rJOYP], a
+ rept 6
+ ld a, [rJOYP]
+ endr
+ cpl
+ and %1111
+ or b
+
+ ld [hJoyInput], a
+
+ ld a, 1 << 4 + 1 << 5 ; deselect keys
+ ld [rJOYP], a
+ ret
+
+
_Joypad::
; hJoyReleased: (hJoyLast ^ hJoyInput) & hJoyLast
; hJoyPressed: (hJoyLast ^ hJoyInput) & hJoyInput
ld a, [hJoyInput]
+ ld b,a
+ and $4F
cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
jp z, TrySoftReset
- ld b, a
ld a, [hJoyLast]
ld e, a
xor b
diff --git a/engine/learn_move.asm b/engine/learn_move.asm
index 5fa6df08..dcaf4235 100755
--- a/engine/learn_move.asm
+++ b/engine/learn_move.asm
@@ -121,18 +121,17 @@ TryingToLearn:
ld hl, WhichMoveToForgetText
call PrintText
coord hl, 4, 7
- ld b, 4
- ld c, 14
+ lb bc, 4, 14
call TextBoxBorder
coord hl, 6, 8
ld de, wMovesString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
set 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
call PlaceString
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
res 2, a
- ld [hFlags_0xFFF6], a
+ ld [hFlags_0xFFFA], a
ld hl, wTopMenuItemY
ld a, 8
ld [hli], a ; wTopMenuItemY
@@ -146,10 +145,10 @@ TryingToLearn:
ld a, A_BUTTON | B_BUTTON
ld [hli], a ; wMenuWatchedKeys
ld [hl], 0 ; wLastMenuItem
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
push af
call LoadScreenTilesFromBuffer1
@@ -204,11 +203,36 @@ TryingToLearnText:
db "@"
OneTwoAndText:
+; bugfix: In Red/Blue, the SFX_SWAP sound was played in the wrong bank, which played an incorrect sound
+; Yellow has fixed this by swapping to the correct bank
TX_FAR _OneTwoAndText
db $a
TX_ASM
+ push af
+ push bc
+ push de
+ push hl
+ ld a, $1
+ ld [wMuteAudioAndPauseMusic], a
+ call DelayFrame
+ ld a, [wAudioROMBank]
+ push af
+ ld a, BANK(SFX_Swap_1)
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
+ call WaitForSoundToFinish
ld a, SFX_SWAP
- call PlaySoundWaitForCurrent
+ call PlaySound
+ call WaitForSoundToFinish
+ pop af
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
+ xor a
+ ld [wMuteAudioAndPauseMusic], a
+ pop hl
+ pop de
+ pop bc
+ pop af
ld hl, PoofText
ret
diff --git a/engine/load_mon_data.asm b/engine/load_mon_data.asm
new file mode 100644
index 00000000..e708113f
--- /dev/null
+++ b/engine/load_mon_data.asm
@@ -0,0 +1,68 @@
+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
+ call 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
+
+; get species of mon e in list [wMonDataLocation] for LoadMonData
+GetMonSpecies:
+ ld hl, wPartySpecies
+ ld a, [wMonDataLocation]
+ and a
+ jr z, .getSpecies
+ dec a
+ jr z, .enemyParty
+ ld hl, wBoxSpecies
+ jr .getSpecies
+.enemyParty
+ ld hl, wEnemyPartyMons
+.getSpecies
+ ld d, 0
+ add hl, de
+ ld a, [hl]
+ ld [wcf91], a
+ ret
diff --git a/engine/menu/bills_pc.asm b/engine/menu/bills_pc.asm
index 384ab485..57699b8f 100644
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -11,18 +11,15 @@ DisplayPCMainMenu::
and a
jr nz, .leaguePCAvailable
coord hl, 0, 0
- ld b, 8
- ld c, 14
+ lb bc, 8, 14
jr .next
.noOaksPC
coord hl, 0, 0
- ld b, 6
- ld c, 14
+ lb bc, 6, 14
jr .next
.leaguePCAvailable
coord hl, 0, 0
- ld b, 10
- ld c, 14
+ lb bc, 10, 14
.next
call TextBoxBorder
call UpdateSprites
@@ -92,7 +89,7 @@ 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
@@ -119,10 +116,13 @@ BillsPCMenu:
lb bc, BANK(PokeballTileGraphics), $01
call CopyVideoData
call LoadScreenTilesFromBuffer2DisableBGTransfer
+ coord hl, 0, 12
+ lb bc, 4, 18
+ call TextBoxBorder
coord hl, 0, 0
- ld b, 10
- ld c, 12
+ lb bc, 12, 12
call TextBoxBorder
+ call UpdateSprites
coord hl, 2, 2
ld de, BillsPCMenuText
call PlaceString
@@ -133,7 +133,7 @@ BillsPCMenu:
ld [hli], a ; wTopMenuItemX
inc hl
inc hl
- ld a, 4
+ ld a, 5
ld [hli], a ; wMaxMenuItem
ld a, A_BUTTON | B_BUTTON
ld [hli], a ; wMenuWatchedKeys
@@ -144,11 +144,8 @@ BillsPCMenu:
ld [hli], a ; wListScrollOffset
ld [hl], a ; wMenuWatchMovingOutOfBounds
ld [wPlayerMonNumber], a
- ld hl, WhatText
- call PrintText
coord hl, 9, 14
- ld b, 2
- ld c, 9
+ lb bc, 2, 9
call TextBoxBorder
ld a, [wCurrentBoxNum]
and $7f
@@ -184,6 +181,8 @@ BillsPCMenu:
jp z, BillsPCRelease ; release
cp $3
jp z, BillsPCChangeBox ; change box
+ cp $4
+ jp z, BillsPCPrintBox
ExitBillsPC:
ld a, [wFlags_0xcd60]
@@ -204,6 +203,10 @@ ExitBillsPC:
res 6, [hl]
ret
+BillsPCPrintBox:
+ callab PrintPCBox
+ jp BillsPCMenu
+
BillsPCDeposit:
ld a, [wPartyCount]
dec a
@@ -222,11 +225,26 @@ BillsPCDeposit:
ld hl, wPartyCount
call DisplayMonListMenu
jp c, BillsPCMenu
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .asm_215ad
+ call CheckPikachuFollowingPlayer
+ jr z, .asm_215ad
+ ld hl, SleepingPikachuText2
+ call PrintText
+ jp BillsPCMenu
+.asm_215ad
call DisplayDepositWithdrawMenu
jp nc, BillsPCMenu
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .asm_215c9
+ ld e, $1b
+ callab PlayPikachuSoundClip
+ jr .asm_215cf
+.asm_215c9
ld a, [wcf91]
- call GetCryData
- call PlaySoundWaitForCurrent
+ call PlayCry
+.asm_215cf
+ callabd_ModifyPikachuHappiness PIKAHAPPY_DEPOSITED
ld a, PARTY_TO_BOX
ld [wMoveMonType], a
call MoveMon
@@ -236,7 +254,7 @@ BillsPCDeposit:
call WaitForSoundToFinish
ld hl, wBoxNumString
ld a, [wCurrentBoxNum]
- and $7f
+ and " "
cp 9
jr c, .singleDigitBoxNum
sub 9
@@ -248,11 +266,15 @@ BillsPCDeposit:
add "1"
.next
ld [hli], a
- ld [hl], $50
+ ld [hl], "@"
ld hl, MonWasStoredText
call PrintText
jp BillsPCMenu
+SleepingPikachuText2:
+ TX_FAR _SleepingPikachuText2
+ db "@"
+
BillsPCWithdraw:
ld a, [wNumInBox]
and a
@@ -276,9 +298,15 @@ BillsPCWithdraw:
ld a, [wWhichPokemon]
ld hl, wBoxMonNicks
call GetPartyMonName
+ callab IsThisPartymonStarterPikachu_Box
+ jr nc, .asm_21660
+ ld e, $22
+ callab PlayPikachuSoundClip
+ jr .asm_21666
+.asm_21660
ld a, [wcf91]
- call GetCryData
- call PlaySoundWaitForCurrent
+ call PlayCry
+.asm_21666
xor a ; BOX_TO_PARTY
ld [wMoveMonType], a
call MoveMon
@@ -301,6 +329,8 @@ BillsPCRelease:
ld hl, wNumInBox
call DisplayMonListMenu
jp c, BillsPCMenu
+ callab IsThisPartymonStarterPikachu_Box
+ jr c, .asm_216cb
ld hl, OnceReleasedText
call PrintText
call YesNoChoice
@@ -317,6 +347,16 @@ BillsPCRelease:
call PrintText
jp BillsPCMenu
+.asm_216cb
+ ld a, [wWhichPokemon]
+ ld hl, wBoxMonNicks
+ call GetPartyMonName
+ ld e, $27
+ callab PlayPikachuSoundClip
+ ld hl, PikachuUnhappyText
+ call PrintText
+ jp BillsPCMenu
+
BillsPCChangeBox:
callba ChangeBox
jp BillsPCMenu
@@ -343,6 +383,7 @@ BillsPCMenuText:
next "DEPOSIT ", $4a
next "RELEASE ", $4a
next "CHANGE BOX"
+ next "PRINT BOX"
next "SEE YA!"
db "@"
@@ -382,12 +423,11 @@ HMMoveArray:
db SURF
db STRENGTH
db FLASH
- db -1
+ db $ff
DisplayDepositWithdrawMenu:
coord hl, 9, 10
- ld b, 6
- ld c, 9
+ lb bc, 6, 9
call TextBoxBorder
ld a, [wParentMenuItem]
and a ; was the Deposit or Withdraw item selected in the parent menu?
@@ -457,51 +497,55 @@ 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
+PikachuUnhappyText:
+ TX_FAR _PikachuUnhappyText
+ db "@"
+
+ReleaseWhichMonText:
TX_FAR _ReleaseWhichMonText
db "@"
-OnceReleasedText: ; 0x2181b
+OnceReleasedText:
TX_FAR _OnceReleasedText
db "@"
-MonWasReleasedText: ; 0x21820
+MonWasReleasedText:
TX_FAR _MonWasReleasedText
db "@"
@@ -509,7 +553,7 @@ CableClubLeftGameboy::
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
ret z
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
cp SPRITE_FACING_RIGHT
ret nz
ld a, [wCurMap]
@@ -526,7 +570,7 @@ CableClubRightGameboy::
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
ret z
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
cp SPRITE_FACING_LEFT
ret nz
ld a, [wCurMap]
@@ -543,7 +587,7 @@ JustAMomentText::
TX_FAR _JustAMomentText
db "@"
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
@@ -551,4 +595,3 @@ JustAMomentText::
OpenBillsPCText::
db $FD ; FuncTX_BillsPC
-
diff --git a/engine/menu/diploma.asm b/engine/menu/diploma.asm
deleted file mode 100755
index 09ba123e..00000000
--- a/engine/menu/diploma.asm
+++ /dev/null
@@ -1,113 +0,0 @@
-DisplayDiploma:
- call SaveScreenTilesToBuffer2
- call GBPalWhiteOutWithDelay3
- call ClearScreen
- xor a
- ld [wUpdateSpritesEnabled], a
- ld hl, wd730
- set 6, [hl]
- call DisableLCD
- ld hl, CircleTile
- ld de, vChars2 + $700
- ld bc, $0010
- ld a, BANK(CircleTile)
- call FarCopyData2
- coord hl, 0, 0
- lb bc, 16, 18
- predef Diploma_TextBoxBorder
- ld hl, DiplomaTextPointersAndCoords
- ld c, $5
-.asm_56715
- push bc
- ld a, [hli]
- ld e, a
- ld a, [hli]
- ld d, a
- ld a, [hli]
- push hl
- ld h, [hl]
- ld l, a
- call PlaceString
- pop hl
- inc hl
- pop bc
- dec c
- jr nz, .asm_56715
- coord hl, 10, 4
- ld de, wPlayerName
- call PlaceString
- callba DrawPlayerCharacter
-
-; Move the player 33 pixels right and set the priority bit so he appears
-; behind the background layer.
- ld hl, wOAMBuffer + $01
- lb bc, $80, $28
-.adjustPlayerGfxLoop
- ld a, [hl] ; X
- add 33
- ld [hli], a
- inc hl
- ld a, b
- ld [hli], a ; attributes
- inc hl
- dec c
- jr nz, .adjustPlayerGfxLoop
-
- call EnableLCD
- callba LoadTrainerInfoTextBoxTiles
- ld b, SET_PAL_GENERIC
- call RunPaletteCommand
- call Delay3
- call GBPalNormal
- ld a, $90
- ld [rOBP0], a
- call WaitForTextScrollButtonPress
- ld hl, wd730
- res 6, [hl]
- call GBPalWhiteOutWithDelay3
- call RestoreScreenTilesAndReloadTilePatterns
- call Delay3
- jp GBPalNormal
-
-UnusedPlayerNameLengthFunc:
-; Unused function that does a calculation involving the length of the player's
-; name.
- ld hl, wPlayerName
- ld bc, $ff00
-.loop
- ld a, [hli]
- cp "@"
- ret z
- dec c
- jr .loop
-
-DiplomaTextPointersAndCoords:
- dw DiplomaText
- dwCoord 5, 2
- dw DiplomaPlayer
- dwCoord 3, 4
- dw DiplomaEmptyText
- dwCoord 15, 4
- dw DiplomaCongrats
- dwCoord 2, 6
- dw DiplomaGameFreak
- dwCoord 9, 16
-
-DiplomaText:
- db $70,"Diploma",$70,"@"
-
-DiplomaPlayer:
- db "Player@"
-
-DiplomaEmptyText:
- db "@"
-
-DiplomaCongrats:
- db "Congrats! This"
- next "diploma certifies"
- next "that you have"
- next "completed your"
- next "#DEX.@"
-
-DiplomaGameFreak:
- db "GAME FREAK@"
diff --git a/engine/menu/diploma_1.asm b/engine/menu/diploma_1.asm
new file mode 100644
index 00000000..3f309bd2
--- /dev/null
+++ b/engine/menu/diploma_1.asm
@@ -0,0 +1,17 @@
+DisplayDiploma:
+ call SaveScreenTilesToBuffer2
+ call GBPalWhiteOutWithDelay3
+ call ClearScreen
+ xor a
+ ld [wUpdateSpritesEnabled], a
+ ld hl, wd730
+ set 6, [hl]
+ callab _DisplayDiploma
+ call WaitForTextScrollButtonPress
+ ld hl, wd730
+ res 6, [hl]
+ call GBPalWhiteOutWithDelay3
+ call ReloadTilesetTilePatterns
+ call RestoreScreenTilesAndReloadTilePatterns
+ call Delay3
+ jp GBPalNormal
diff --git a/engine/menu/league_pc.asm b/engine/menu/league_pc.asm
index e1359063..9946b90d 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
@@ -100,8 +100,7 @@ LeaguePCShowMon:
call LoadFrontSpriteByMonIndex
call GBPalNormal
coord hl, 0, 13
- ld b, 2
- ld c, $12
+ lb bc, 2, 18
call TextBoxBorder
coord hl, 1, 15
ld de, HallOfFameNoText
@@ -110,7 +109,7 @@ LeaguePCShowMon:
ld de, wHoFTeamNo
lb bc, 1, 3
call PrintNumber
- jpba HoFDisplayMonInfo
+ jpba Func_7033f
HallOfFameNoText:
db "HALL OF FAME No @"
diff --git a/engine/menu/link_menu.asm b/engine/menu/link_menu.asm
new file mode 100644
index 00000000..458f653b
--- /dev/null
+++ b/engine/menu/link_menu.asm
@@ -0,0 +1,910 @@
+Func_f531b::
+ ld c,$14
+ call DelayFrames
+ ld a,$1
+ ld [wBuffer],a
+ xor a
+ ld [wUnknownSerialFlag_d499],a
+ coord hl, 0,0
+ lb bc, 4, 5
+ call TextBoxBorder
+ ld de,Text_f5791
+ coord hl, 1,2
+ call PlaceString
+ coord hl, 8,0
+ lb bc, 8, 10
+ call TextBoxBorder
+ coord hl, 10,2
+ ld de,Text_f579c
+ call PlaceString
+ coord hl, 0,10
+ lb bc, 6, 18
+ call TextBoxBorder
+ call UpdateSprites
+ xor a
+ ld [wUnusedCD37],a
+ ld [wd72d],a
+ ld [wd11e],a
+ ld hl,wTopMenuItemY
+ ld a,$2
+ ld [hli],a
+ ld a,$9
+ ld [hli],a
+ xor a
+ ld [hli],a
+ inc hl
+ ld a,$3
+ ld [hli],a
+ ld a,$3
+ ld [hli],a
+ xor a
+ ld [hl],a
+.asm_f5377
+ call Func_f56bd
+ call HandleMenuInput
+ and $3
+ add a
+ add a
+ ld b,a
+ ld a,[wCurrentMenuItem]
+ cp $3
+ jr nz,.asm_f5390
+ bit 2,b
+ jr z,.asm_f5390
+ dec a
+ ld b,$8
+.asm_f5390
+ add b
+ add $c0
+ ld [wLinkMenuSelectionSendBuffer],a
+ ld [wLinkMenuSelectionSendBuffer+1],a
+.asm_f5399
+ ld hl,wLinkMenuSelectionSendBuffer
+ ld a,[hl]
+ ld [hSerialSendData],a
+ call Serial_ExchangeByte
+ push af
+ ld hl,wLinkMenuSelectionSendBuffer
+ ld a,[hl]
+ ld [hSerialSendData],a
+ call Serial_ExchangeByte
+ pop bc
+ cp b
+ jr nz,.asm_f5399
+ and $f0
+ cp $c0
+ jr nz,.asm_f5399
+ ld a,b
+ and $c
+ jr nz,.asm_f53c4
+ ld a,[wLinkMenuSelectionSendBuffer]
+ and $c
+ jr z,.asm_f5377
+ jr .asm_f53df
+.asm_f53c4
+ ld a,[wLinkMenuSelectionSendBuffer]
+ and $c
+ jr z,.asm_f53d1
+ ld a,[hSerialConnectionStatus]
+ cp $2
+ jr z,.asm_f53df
+.asm_f53d1
+ ld a,$1
+ ld [wd11e],a
+ ld a,b
+ ld [wLinkMenuSelectionSendBuffer],a
+ and $3
+ ld [wCurrentMenuItem],a
+.asm_f53df
+ call DelayFrame
+ call DelayFrame
+ ld hl,wLinkMenuSelectionSendBuffer
+ ld a,[hl]
+ ld [hSerialSendData],a
+ call Serial_ExchangeByte
+ call Serial_ExchangeByte
+ ld b,$14
+.loop
+ call DelayFrame
+ call Serial_SendZeroByte
+ dec b
+ jr nz,.loop
+ ld b,$7f
+ ld c,$7f
+ ld d,$7f
+ ld e,$ec
+ ld a,[wLinkMenuSelectionSendBuffer]
+ bit 3,a
+ jr nz,.asm_f541a
+ ld b,e
+ ld e,c
+ ld a,[wCurrentMenuItem]
+ and a
+ jr z,.asm_f541a
+ ld c,b
+ ld b,d
+ dec a
+ jr z,.asm_f541a
+ ld d,c
+ ld c,b
+.asm_f541a
+ ld a,b
+ Coorda 9,2
+ ld a,c
+ Coorda 9,4
+ ld a,d
+ Coorda 9,6
+ ld a,e
+ Coorda 9,8
+ ld c,40
+ call DelayFrames
+ ld a,[wLinkMenuSelectionSendBuffer]
+ bit 3,a
+ jr nz,asm_f547f
+ ld a,[wCurrentMenuItem]
+ cp $3
+ jr z,asm_f547f
+ inc a
+ ld [wUnknownSerialFlag_d499],a
+ ld a,[wCurrentMenuItem]
+ ld hl,PointerTable_f5488
+ ld c,a
+ ld b,$0
+ add hl,bc
+ add hl,bc
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ ld de,.returnaddress
+ push de
+ jp hl
+.returnaddress
+ ld [wLinkMenuSelectionSendBuffer],a
+ xor a
+ ld [wUnknownSerialCounter],a
+ ld [wUnknownSerialCounter+1],a
+ call Serial_SyncAndExchangeNybble
+ ld a,[wLinkMenuSelectionSendBuffer]
+ and a
+ jr nz,asm_f547c
+ ld a, [wLinkMenuSelectionReceiveBuffer]
+ and a
+ jr nz, Func_f5476
+ xor a
+ ld [wUnknownSerialCounter],a
+ ld [wUnknownSerialCounter+1],a
+ and a
+ ret
+
+Func_f5476::
+ ld hl,ColosseumIneligibleText
+ call PrintText
+asm_f547c::
+ jp Func_f531b
+
+asm_f547f::
+ xor a
+ ld [wUnknownSerialCounter],a
+ ld [wUnknownSerialCounter+1],a
+ scf
+ ret
+
+PointerTable_f5488::
+ dw PokeCup
+ dw PikaCup
+ dw PetitCup
+
+PokeCup::
+ ld hl,wPartyCount
+ ld a,[hli]
+ cp $3
+ jp nz,NotThreeMonsInParty
+ ld b,$3
+.loop
+ ld a,[hli]
+ cp MEW
+ jp z,MewInParty
+ dec b
+ jr nz,.loop
+ dec hl
+ dec hl
+ cp [hl] ; is third mon second mon?
+ jp z,DuplicateSpecies
+ dec hl ; wPartySpecies
+ cp [hl] ; is third mon first mon?
+ jp z,DuplicateSpecies
+ ld a,[hli]
+ cp [hl] ; is first mon second mon?
+ jp z,DuplicateSpecies
+ ld a,[wPartyMon1Level]
+ cp 56
+ jp nc,LevelAbove55
+ cp 50
+ jp c,LevelUnder50
+ ld b,a
+ ld a,[wPartyMon2Level]
+ cp 56
+ jp nc,LevelAbove55
+ cp 50
+ jp c,LevelUnder50
+ ld c,a
+ ld a,[wPartyMon3Level]
+ cp 56
+ jp nc,LevelAbove55
+ cp 50
+ jp c,LevelUnder50
+ add b
+ add c
+ cp 156
+ jp nc,CombinedLevelsGreaterThan155
+ xor a
+ ret
+
+PikaCup::
+ ld hl,wPartyCount
+ ld a,[hli]
+ cp $3
+ jp nz,NotThreeMonsInParty
+ ld b,$3
+.loop
+ ld a,[hli] ; wPartySpecies
+ cp MEW
+ jp z,MewInParty
+ dec b
+ jr nz,.loop
+ dec hl
+ dec hl
+ cp [hl] ; is third mon second mon?
+ jp z,DuplicateSpecies
+ dec hl ; wPartySpecies
+ cp [hl] ; is third mon first mon?
+ jp z,DuplicateSpecies
+ ld a,[hli]
+ cp [hl] ; is first mon second mon?
+ jp z,DuplicateSpecies
+ ld a,[wPartyMon1Level]
+ cp 21
+ jp nc,LevelAbove20
+ cp 15
+ jp c,LevelUnder15
+ ld b,a
+ ld a,[wPartyMon2Level]
+ cp 21
+ jp nc,LevelAbove20
+ cp 15
+ jp c,LevelUnder15
+ ld c,a
+ ld a,[wPartyMon3Level]
+ cp 21
+ jp nc,LevelAbove20
+ cp 15
+ jp c,LevelUnder15
+ add b
+ add c
+ cp 51
+ jp nc,CombinedLevelsAbove50
+ xor a
+ ret
+
+PetitCup::
+ ld hl,wPartyCount
+ ld a,[hli]
+ cp $3
+ jp nz,NotThreeMonsInParty
+ ld b,$3
+.loop
+ ld a,[hli]
+ cp MEW
+ jp z,MewInParty
+ dec b
+ jr nz,.loop
+ dec hl
+ dec hl
+ cp [hl] ; is third mon second mon?
+ jp z,DuplicateSpecies
+ dec hl ; wPartySpecies
+ cp [hl] ; is third mon first mon?
+ jp z,DuplicateSpecies
+ ld a,[hli]
+ cp [hl] ; is first mon second mon?
+ jp z,DuplicateSpecies
+ dec hl
+ ld a,[hl]
+ ld [wcf91],a
+ push hl
+ callab Func_3b10f
+ pop hl
+ jp c,asm_f56ad
+ inc hl
+ ld a,[hl]
+ ld [wcf91],a
+ push hl
+ callab Func_3b10f
+ pop hl
+ jp c,asm_f56ad
+ inc hl
+ ld a,[hl]
+ ld [wcf91],a
+ push hl
+ callab Func_3b10f
+ pop hl
+ jp c,asm_f56ad
+ dec hl
+ dec hl
+ ld b,$3
+.bigloop
+ ld a,[hli]
+ push hl
+ push bc
+ push af
+ dec a
+ ld c,a
+ ld b,$0
+ ld hl,PokedexEntryPointers
+ add hl,bc
+ add hl,bc
+ ld de,wcd6d
+ ld bc,$2
+ ld a,BANK(PokedexEntryPointers)
+ call FarCopyData
+ ld hl,wcd6d
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ ld de,wcd6d
+ ld bc,$14
+ ld a,BANK(PokedexEntryPointers)
+ call FarCopyData
+ ld hl,wcd6d
+.loop2
+ ld a,[hli]
+ cp "@"
+ jr nz,.loop2
+ ld a,[hli]
+ cp $7
+ jp nc,asm_f5689
+ add a
+ add a
+ ld b,a
+ add a
+ add b
+ ld b,a
+ ld a,[hli]
+ add b
+ cp $51
+ jp nc,asm_f5689
+ ld a,[hli]
+ sub $b9
+ ld a,[hl]
+ sbc $1
+ jp nc,asm_f569b
+ pop af
+ pop bc
+ pop hl
+ dec b
+ jr nz,.bigloop
+ ld a,[wPartyMon1Level]
+ cp 31
+ jp nc,LevelAbove30
+ cp 25
+ jp c,LevelUnder25
+ ld b,a
+ ld a,[wPartyMon2Level]
+ cp 31
+ jp nc,LevelAbove30
+ cp 25
+ jp c,LevelUnder25
+ ld c,a
+ ld a,[wPartyMon3Level]
+ cp 31
+ jp nc,LevelAbove30
+ cp 25
+ jp c,LevelUnder25
+ add b
+ add c
+ cp 81
+ jp nc,CombinedLevelsAbove80
+ xor a
+ ret
+
+NotThreeMonsInParty::
+ ld hl,Colosseum3MonsText
+ call PrintText
+ ld a,$1
+ ret
+
+MewInParty::
+ ld hl,ColosseumMewText
+ call PrintText
+ ld a,$2
+ ret
+
+DuplicateSpecies::
+ ld hl,ColosseumDifferentMonsText
+ call PrintText
+ ld a,$3
+ ret
+
+LevelAbove55::
+ ld hl,ColosseumMaxL55Text
+ call PrintText
+ ld a,$4
+ ret
+
+LevelUnder50::
+ ld hl,ColosseumMinL50Text
+ call PrintText
+ ld a,$5
+ ret
+
+CombinedLevelsGreaterThan155::
+ ld hl,ColosseumTotalL155Text
+ call PrintText
+ ld a,$6
+ ret
+
+LevelAbove30::
+ ld hl,ColosseumMaxL30Text
+ call PrintText
+ ld a,$7
+ ret
+
+LevelUnder25::
+ ld hl,ColosseumMinL25Text
+ call PrintText
+ ld a,$8
+ ret
+
+CombinedLevelsAbove80::
+ ld hl,ColosseumTotalL80Text
+ call PrintText
+ ld a,$9
+ ret
+
+LevelAbove20::
+ ld hl,ColosseumMaxL20Text
+ call PrintText
+ ld a,$a
+ ret
+
+LevelUnder15::
+ ld hl,ColosseumMinL15Text
+ call PrintText
+ ld a,$b
+ ret
+
+CombinedLevelsAbove50::
+ ld hl,ColosseumTotalL50Text
+ call PrintText
+ ld a,$c
+ ret
+
+asm_f5689::
+ pop af
+ pop bc
+ pop hl
+ ld [wd11e],a
+ call GetMonName
+ ld hl,ColosseumHeightText
+ call PrintText
+ ld a,$d
+ ret
+
+asm_f569b::
+ pop af
+ pop bc
+ pop hl
+ ld [wd11e],a
+ call GetMonName
+ ld hl,ColosseumWeightText
+ call PrintText
+ ld a,$e
+ ret
+
+asm_f56ad::
+ ld a,[hl]
+ ld [wd11e],a
+ call GetMonName
+ ld hl,ColosseumEvolvedText
+ call PrintText
+ ld a,$f
+ ret
+
+Func_f56bd::
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED],a
+ coord hl, 1,11
+ lb bc, 6, 18
+ call ClearScreenArea
+ ld a,[wCurrentMenuItem]
+ cp $3
+ jr nc,.asm_f56e6
+ ld hl,PointerTable_f56ee
+ ld a,[wCurrentMenuItem]
+ ld c,a
+ ld b,$0
+ add hl,bc
+ add hl,bc
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a
+ ld d,h
+ ld e,l
+ coord hl, 1,12
+ call PlaceString
+.asm_f56e6
+ call Delay3
+ ld a,$1
+ ld [H_AUTOBGTRANSFERENABLED],a
+ ret
+
+PointerTable_f56ee::
+ dw Text_f56f4
+ dw Text_f5728
+ dw Text_f575b
+
+Text_f56f4::
+ db "LVs of 3<pkmn>:50-55"
+ next "Sum of LVs:155 MAX"
+ next "MEW can't attend.@"
+
+Text_f5728::
+ db "LVs of 3<pkmn>:15-20"
+ next "Sum of LVs:50 MAX"
+ next "MEW can't attend.@"
+
+Text_f575b::
+ db "3 Basic <pkmn>.LV25-30"
+ next "Sum of LVs:80 MAX"
+ next "6′8″ and 44lb MAX@"
+
+Text_f5791::
+ db "View"
+ next "Rules@"
+
+Text_f579c::
+ db "# Cup"
+ next "Pika Cup"
+ next "Petit Cup"
+ next "CANCEL@"
+
+Colosseum3MonsText::
+ TX_FAR _Colosseum3MonsText ; a0a2b
+ db "@"
+
+ColosseumMewText::
+ TX_FAR _ColosseumMewText ; a0a46
+ db "@"
+
+ColosseumDifferentMonsText::
+ TX_FAR _ColosseumDifferentMonsText ; a0a5f
+ db "@"
+
+ColosseumMaxL55Text::
+ TX_FAR _ColosseumMaxL55Text ; a0a81
+ db "@"
+
+ColosseumMinL50Text::
+ TX_FAR _ColosseumMinL50Text ; a0a9a
+ db "@"
+
+ColosseumTotalL155Text::
+ TX_FAR _ColosseumTotalL155Text ; a0aba
+ db "@"
+
+ColosseumMaxL30Text::
+ TX_FAR _ColosseumMaxL30Text ; a0ad9
+ db "@"
+
+ColosseumMinL25Text::
+ TX_FAR _ColosseumMinL25Text ; a0af2
+ db "@"
+
+ColosseumTotalL80Text::
+ TX_FAR _ColosseumTotalL80Text ; a0b12
+ db "@"
+
+ColosseumMaxL20Text::
+ TX_FAR _ColosseumMaxL20Text ; a0b30
+ db "@"
+
+ColosseumMinL15Text::
+ TX_FAR _ColosseumMinL15Text ; a0b49
+ db "@"
+
+ColosseumTotalL50Text::
+ TX_FAR _ColosseumTotalL50Text ; a0b69
+ db "@"
+
+ColosseumHeightText::
+ TX_FAR _ColosseumHeightText ; a0b87
+ db "@"
+
+ColosseumWeightText::
+ TX_FAR _ColosseumWeightText ; a0b9f
+ db "@"
+
+ColosseumEvolvedText::
+ TX_FAR _ColosseumEvolvedText ; a0bbb
+ db "@"
+
+ColosseumIneligibleText::
+ TX_FAR _ColosseumIneligibleText ; a0bd4
+ db "@"
+
+LinkMenu:
+ xor a
+ ld [wLetterPrintingDelayFlags], a
+ ld hl, wd72e
+ set 6, [hl]
+ ld hl, TextTerminator_f5a16
+ call PrintText
+ call SaveScreenTilesToBuffer1
+ ld hl, ColosseumWhereToText
+ call PrintText
+ coord hl, 5, 3
+ lb bc, 8, 13
+ call TextBoxBorder
+ call UpdateSprites
+ coord hl, 7, 5
+ ld de, TradeCenterText
+ call PlaceString
+ xor a
+ ld [wUnusedCD37], a
+ ld [wd72d], a
+ ld [wd11e], a
+ ld hl, wTopMenuItemY
+ ld a, $5
+ ld [hli], a
+ ld a, $6
+ ld [hli], a
+ xor a
+ ld [hli], a
+ inc hl
+ ld a, $3
+ ld [hli], a
+ ld [hli], a
+ xor a
+ ld [hl], a
+.waitForInputLoop
+ call HandleMenuInput
+ and A_BUTTON | B_BUTTON
+ add a
+ add a
+ ld b, a
+ ld a, [wCurrentMenuItem]
+ cp $3
+ jr nz,.asm_f586b
+ bit 2,b
+ jr z,.asm_f586b
+ dec a
+ ld b,$8
+.asm_f586b
+ add b
+ add $d0
+ ld [wLinkMenuSelectionSendBuffer], a
+ ld [wLinkMenuSelectionSendBuffer + 1], a
+.exchangeMenuSelectionLoop
+ call Serial_ExchangeLinkMenuSelection
+ ld a, [wLinkMenuSelectionReceiveBuffer]
+ ld b, a
+ and $f0
+ cp $d0
+ jr z, .asm_f5c7d
+ ld a, [wLinkMenuSelectionReceiveBuffer + 1]
+ ld b, a
+ and $f0
+ cp $d0
+ jr nz, .exchangeMenuSelectionLoop
+.asm_f5c7d
+ ld a, b
+ and $c ; did the enemy press A or B?
+ jr nz, .enemyPressedAOrB
+; the enemy didn't press A or B
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and $c ; did the player press A or B?
+ jr z, .waitForInputLoop ; if neither the player nor the enemy pressed A or B, try again
+ jr .doneChoosingMenuSelection ; if the player pressed A or B but the enemy didn't, use the player's selection
+.enemyPressedAOrB
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and $c ; did the player press A or B?
+ jr z, .useEnemyMenuSelection ; if the enemy pressed A or B but the player didn't, use the enemy's selection
+; the enemy and the player both pressed A or B
+; The gameboy that is clocking the connection wins.
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr z, .doneChoosingMenuSelection
+.useEnemyMenuSelection
+ ld a, $1
+ ld [wd11e], a
+ ld a, b
+ ld [wLinkMenuSelectionSendBuffer], a
+ and $3
+ ld [wCurrentMenuItem], a ; wCurrentMenuItem
+.doneChoosingMenuSelection
+ ld a, [hSerialConnectionStatus]
+ cp USING_INTERNAL_CLOCK
+ jr nz, .skipStartingTransfer
+ call DelayFrame
+ call DelayFrame
+ ld a, START_TRANSFER_INTERNAL_CLOCK
+ ld [rSC], a
+.skipStartingTransfer
+ ld b, " "
+ ld c, " "
+ ld d, " "
+ ld e, "▷"
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and (B_BUTTON << 2) ; was B button pressed?
+ jr nz, .updateCursorPosition
+; A button was pressed
+ ld a, [wCurrentMenuItem]
+ cp $2
+ jp z, .asm_f5963
+ ld b, e
+ ld e, c
+ ld a, [wCurrentMenuItem]
+ and a
+ jr z, .updateCursorPosition
+ ld c, b
+ ld b, d
+ dec a
+ jr z, .updateCursorPosition
+ ld d, c
+ ld c, b
+.updateCursorPosition
+ call Func_f59ec
+ call LoadScreenTilesFromBuffer1
+ ld a, [wLinkMenuSelectionSendBuffer]
+ and (B_BUTTON << 2) ; was B button pressed?
+ jr nz, .choseCancel ; cancel if B pressed
+ ld a, [wCurrentMenuItem]
+ cp $2
+ jr z, .choseCancel
+ xor a
+ ld [wWalkBikeSurfState], a ; start walking
+ ld a, [wCurrentMenuItem]
+ and a
+ ld a, COLOSSEUM
+ jr nz, .next
+ ld a, TRADE_CENTER
+.next
+ ld [wd72d], a
+ ld hl, ColosseumPleaseWaitText
+ call PrintText
+ ld c, 50
+ call DelayFrames
+ ld hl, wd732
+ res 1, [hl]
+ ld a, [wDefaultMap]
+ ld [wDestinationMap], a
+ callab SpecialWarpIn
+ ld c, 20
+ call DelayFrames
+ xor a
+ ld [wMenuJoypadPollCount], a
+ ld [wSerialExchangeNybbleSendData], a
+ inc a ; LINK_STATE_IN_CABLE_CLUB
+ ld [wLinkState], a
+ ld [wEnteringCableClub], a
+ jpab SpecialEnterMap
+.choseCancel
+ xor a
+ ld [wMenuJoypadPollCount], a
+ call Delay3
+ callab CloseLinkConnection
+ ld hl, ColosseumCanceledText
+ call PrintText
+ ld hl, wd72e
+ res 6, [hl]
+ ret
+
+.asm_f5963
+ ld a,[wd11e]
+ and a
+ jr nz,.asm_f5974
+ ld b," "
+ ld c," "
+ ld d,"▷"
+ ld e," "
+ call Func_f59ec
+.asm_f5974
+ xor a
+ ld [wBuffer], a
+ ld a,$ff
+ ld [wSerialExchangeNybbleReceiveData],a
+ ld a, $b
+ ld [wLinkMenuSelectionSendBuffer], a
+ ld b,$78
+.loop
+ ld a,[hSerialConnectionStatus]
+ cp $2
+ call z,DelayFrame
+ dec b
+ jr z,.asm_f59b2
+ call Serial_ExchangeNybble
+ call DelayFrame
+ ld a,[wSerialExchangeNybbleReceiveData]
+ inc a
+ jr z,.loop
+ ld b,$f
+.loop2
+ call DelayFrame
+ call Serial_ExchangeNybble
+ dec b
+ jr nz,.loop2
+ ld b,$f
+.loop3
+ call DelayFrame
+ call Serial_SendZeroByte
+ dec b
+ jr nz,.loop3
+ jr .asm_f59d6
+
+.asm_f59b2
+ xor a
+ ld [wUnknownSerialCounter],a
+ ld [wUnknownSerialCounter+1],a
+ ld a,[wd11e]
+ and a
+ jr z,.asm_f59cd
+ ld b," "
+ ld c," "
+ ld d," "
+ ld e,"▷"
+ call Func_f59ec
+ jp .choseCancel
+
+.asm_f59cd
+ ld hl,ColosseumVersionText
+ call PrintText
+ jp .choseCancel
+
+.asm_f59d6
+ ld b," "
+ ld c," "
+ ld d,"▷"
+ ld e," "
+ call Func_f59ec
+ call Func_f531b
+ jp c,.choseCancel
+ ld a,$f0
+ jp .next
+
+Func_f59ec::
+ ld a, b
+ Coorda 6, 5
+ ld a, c
+ Coorda 6, 7
+ ld a, d
+ Coorda 6, 9
+ ld a, e
+ Coorda 6, 11
+ ld c, 40
+ call DelayFrames
+ ret
+
+ColosseumWhereToText:
+ TX_FAR _ColosseumWhereToText
+ db "@"
+
+ColosseumPleaseWaitText:
+ TX_FAR _ColosseumPleaseWaitText
+ db "@"
+
+ColosseumCanceledText:
+ TX_FAR _ColosseumCanceledText
+ db "@"
+
+ColosseumVersionText:
+ TX_FAR _ColosseumVersionText ; 28:4c47
+ db "@"
+
+TextTerminator_f5a16:
+ db "@"
+
+TradeCenterText:
+ db "TRADE CENTER"
+ next "COLOSSEUM"
+ next "COLOSSEUM2"
+ next "CANCEL@"
diff --git a/engine/menu/main_menu.asm b/engine/menu/main_menu.asm
index d3152e4e..cf837a54 100755
--- a/engine/menu/main_menu.asm
+++ b/engine/menu/main_menu.asm
@@ -34,8 +34,7 @@ MainMenu:
jr z,.noSaveFile
; there's a save file
coord hl, 0, 0
- ld b,6
- ld c,13
+ lb bc, 6, 13
call TextBoxBorder
coord hl, 2, 2
ld de,ContinueText
@@ -43,8 +42,7 @@ MainMenu:
jr .next2
.noSaveFile
coord hl, 0, 0
- ld b,4
- ld c,13
+ lb bc, 4, 13
call TextBoxBorder
coord hl, 2, 2
ld de,NewGameText
@@ -129,185 +127,29 @@ InitOptions:
ld [wLetterPrintingDelayFlags],a
ld a,3 ; medium speed
ld [wOptions],a
+ ld a,64 ; audio?
+ ld [wPrinterSettings], a
ret
-LinkMenu:
- xor a
- ld [wLetterPrintingDelayFlags], a
- ld hl, wd72e
- set 6, [hl]
- ld hl, TextTerminator_6b20
- call PrintText
- call SaveScreenTilesToBuffer1
- ld hl, WhereWouldYouLikeText
- call PrintText
- coord hl, 5, 5
- ld b, $6
- ld c, $d
- call TextBoxBorder
- call UpdateSprites
- coord hl, 7, 7
- ld de, CableClubOptionsText
- call PlaceString
- xor a
- ld [wUnusedCD37], a
- ld [wd72d], a
- ld hl, wTopMenuItemY
- ld a, $7
- ld [hli], a
- ld a, $6
- ld [hli], a
- xor a
- ld [hli], a
- inc hl
- ld a, $2
- ld [hli], a
- inc a
- ; ld a, A_BUTTON | B_BUTTON
- ld [hli], a ; wMenuWatchedKeys
- xor a
- ld [hl], a
-.waitForInputLoop
- call HandleMenuInput
- and A_BUTTON | B_BUTTON
- add a
- add a
- ld b, a
- ld a, [wCurrentMenuItem]
- add b
- add $d0
- ld [wLinkMenuSelectionSendBuffer], a
- ld [wLinkMenuSelectionSendBuffer + 1], a
-.exchangeMenuSelectionLoop
- call Serial_ExchangeLinkMenuSelection
- ld a, [wLinkMenuSelectionReceiveBuffer]
- ld b, a
- and $f0
- cp $d0
- jr z, .asm_5c7d
- ld a, [wLinkMenuSelectionReceiveBuffer + 1]
- ld b, a
- and $f0
- cp $d0
- jr nz, .exchangeMenuSelectionLoop
-.asm_5c7d
- ld a, b
- and $c ; did the enemy press A or B?
- jr nz, .enemyPressedAOrB
-; the enemy didn't press A or B
- ld a, [wLinkMenuSelectionSendBuffer]
- and $c ; did the player press A or B?
- jr z, .waitForInputLoop ; if neither the player nor the enemy pressed A or B, try again
- jr .doneChoosingMenuSelection ; if the player pressed A or B but the enemy didn't, use the player's selection
-.enemyPressedAOrB
- ld a, [wLinkMenuSelectionSendBuffer]
- and $c ; did the player press A or B?
- jr z, .useEnemyMenuSelection ; if the enemy pressed A or B but the player didn't, use the enemy's selection
-; the enemy and the player both pressed A or B
-; The gameboy that is clocking the connection wins.
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK
- jr z, .doneChoosingMenuSelection
-.useEnemyMenuSelection
- ld a, b
- ld [wLinkMenuSelectionSendBuffer], a
- and $3
- ld [wCurrentMenuItem], a
-.doneChoosingMenuSelection
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK
- jr nz, .skipStartingTransfer
- call DelayFrame
- call DelayFrame
- ld a, START_TRANSFER_INTERNAL_CLOCK
- ld [rSC], a
-.skipStartingTransfer
- ld b, $7f
- ld c, $7f
- ld d, $ec
- ld a, [wLinkMenuSelectionSendBuffer]
- and (B_BUTTON << 2) ; was B button pressed?
- jr nz, .updateCursorPosition
-; A button was pressed
- ld a, [wCurrentMenuItem]
- cp $2
- jr z, .updateCursorPosition
- ld c, d
- ld d, b
- dec a
- jr z, .updateCursorPosition
- ld b, c
- ld c, d
-.updateCursorPosition
- ld a, b
- Coorda 6, 7
- ld a, c
- Coorda 6, 9
- ld a, d
- Coorda 6, 11
- ld c, 40
- call DelayFrames
- call LoadScreenTilesFromBuffer1
- ld a, [wLinkMenuSelectionSendBuffer]
- and (B_BUTTON << 2) ; was B button pressed?
- jr nz, .choseCancel ; cancel if B pressed
- ld a, [wCurrentMenuItem]
- cp $2
- jr z, .choseCancel
- xor a
- ld [wWalkBikeSurfState], a ; start walking
- ld a, [wCurrentMenuItem]
- and a
- ld a, COLOSSEUM
- jr nz, .next
- ld a, TRADE_CENTER
-.next
- ld [wd72d], a
- ld hl, PleaseWaitText
- call PrintText
- ld c, 50
- call DelayFrames
- ld hl, wd732
- res 1, [hl]
- ld a, [wDefaultMap]
- ld [wDestinationMap], a
- call SpecialWarpIn
- ld c, 20
- call DelayFrames
- xor a
- ld [wMenuJoypadPollCount], a
- ld [wSerialExchangeNybbleSendData], a
- inc a ; LINK_STATE_IN_CABLE_CLUB
- ld [wLinkState], a
- ld [wEnteringCableClub], a
- jr SpecialEnterMap
-.choseCancel
- xor a
- ld [wMenuJoypadPollCount], a
- call Delay3
- call CloseLinkConnection
- ld hl, LinkCanceledText
+Func_5cc1:
+; unused?
+ ld a, $6d
+ cp $80
+ ret c ; will always be executed
+ ld hl, NotEnoughMemoryText
call PrintText
- ld hl, wd72e
- res 6, [hl]
ret
-WhereWouldYouLikeText:
- TX_FAR _WhereWouldYouLikeText
- db "@"
-
-PleaseWaitText:
- TX_FAR _PleaseWaitText
- db "@"
-
-LinkCanceledText:
- TX_FAR _LinkCanceledText
+NotEnoughMemoryText:
+ TX_FAR _NotEnoughMemoryText
db "@"
StartNewGame:
ld hl, wd732
res 1, [hl]
call OakSpeech
+ ld a, $8
+ ld [wPlayerMovingDirection], a
ld c, 20
call DelayFrames
@@ -323,6 +165,7 @@ SpecialEnterMap:
call ResetPlayerSpriteData
ld c, 20
call DelayFrames
+ call Func_5cc1
ld a, [wEnteringCableClub]
and a
ret nz
@@ -335,17 +178,11 @@ NewGameText:
db "NEW GAME", $4e
db "OPTION@"
-CableClubOptionsText:
- db "TRADE CENTER", $4e
- db "COLOSSEUM", $4e
- db "CANCEL@"
-
DisplayContinueGameInfo:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 4, 7
- ld b, 8
- ld c, 14
+ lb bc, 8, 14
call TextBoxBorder
coord hl, 5, 9
ld de, SaveScreenInfoText
@@ -368,8 +205,7 @@ PrintSaveScreenText:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 4, 0
- ld b, $8
- ld c, $e
+ lb bc, 8, 14
call TextBoxBorder
call LoadTextBoxTilePatterns
call UpdateSprites
@@ -427,260 +263,9 @@ SaveScreenInfoText:
next "TIME@"
DisplayOptionMenu:
- coord hl, 0, 0
- ld b,3
- ld c,18
- call TextBoxBorder
- coord hl, 0, 5
- ld b,3
- ld c,18
- call TextBoxBorder
- coord hl, 0, 10
- ld b,3
- ld c,18
- call TextBoxBorder
- coord hl, 1, 1
- ld de,TextSpeedOptionText
- call PlaceString
- coord hl, 1, 6
- ld de,BattleAnimationOptionText
- call PlaceString
- coord hl, 1, 11
- ld de,BattleStyleOptionText
- call PlaceString
- coord hl, 2, 16
- ld de,OptionMenuCancelText
- call PlaceString
- xor a
- ld [wCurrentMenuItem],a
- ld [wLastMenuItem],a
- inc a
- ld [wLetterPrintingDelayFlags],a
- ld [wUnusedCD40],a
- ld a,3 ; text speed cursor Y coordinate
- ld [wTopMenuItemY],a
- call SetCursorPositionsFromOptions
- ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
- ld [wTopMenuItemX],a
- ld a,$01
- ld [H_AUTOBGTRANSFERENABLED],a ; enable auto background transfer
- call Delay3
-.loop
- call PlaceMenuCursor
- call SetOptionsFromCursorPositions
-.getJoypadStateLoop
- call JoypadLowSensitivity
- ld a,[hJoy5]
- ld b,a
- 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
- bit 3,b ; Start button pressed?
- jr nz,.exitMenu
- bit 0,b ; A button pressed?
- jr z,.checkDirectionKeys
- ld a,[wTopMenuItemY]
- cp a,16 ; is the cursor on Cancel?
- jr nz,.loop
-.exitMenu
- ld a,SFX_PRESS_AB
- call PlaySound
- ret
-.eraseOldMenuCursor
- ld [wTopMenuItemX],a
- call EraseMenuCursor
- jp .loop
-.checkDirectionKeys
- ld a,[wTopMenuItemY]
- bit 7,b ; Down pressed?
- jr nz,.downPressed
- bit 6,b ; Up pressed?
- jr nz,.upPressed
- cp a,8 ; cursor in Battle Animation section?
- jr z,.cursorInBattleAnimation
- cp a,13 ; cursor in Battle Style section?
- jr z,.cursorInBattleStyle
- cp a,16 ; cursor on Cancel?
- jr z,.loop
-.cursorInTextSpeed
- bit 5,b ; Left pressed?
- jp nz,.pressedLeftInTextSpeed
- jp .pressedRightInTextSpeed
-.downPressed
- cp a,16
- ld b,-13
- ld hl,wOptionsTextSpeedCursorX
- jr z,.updateMenuVariables
- ld b,5
- cp a,3
- inc hl
- jr z,.updateMenuVariables
- cp a,8
- inc hl
- jr z,.updateMenuVariables
- ld b,3
- inc hl
- jr .updateMenuVariables
-.upPressed
- cp a,8
- ld b,-5
- ld hl,wOptionsTextSpeedCursorX
- jr z,.updateMenuVariables
- cp a,13
- inc hl
- jr z,.updateMenuVariables
- cp a,16
- ld b,-3
- inc hl
- jr z,.updateMenuVariables
- ld b,13
- inc hl
-.updateMenuVariables
- add b
- ld [wTopMenuItemY],a
- ld a,[hl]
- ld [wTopMenuItemX],a
- call PlaceUnfilledArrowMenuCursor
- jp .loop
-.cursorInBattleAnimation
- ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
- xor a,$0b ; toggle between 1 and 10
- ld [wOptionsBattleAnimCursorX],a
- jp .eraseOldMenuCursor
-.cursorInBattleStyle
- ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
- xor a,$0b ; toggle between 1 and 10
- ld [wOptionsBattleStyleCursorX],a
- jp .eraseOldMenuCursor
-.pressedLeftInTextSpeed
- ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
- cp a,1
- jr z,.updateTextSpeedXCoord
- cp a,7
- jr nz,.fromSlowToMedium
- sub a,6
- jr .updateTextSpeedXCoord
-.fromSlowToMedium
- sub a,7
- jr .updateTextSpeedXCoord
-.pressedRightInTextSpeed
- ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
- cp a,14
- jr z,.updateTextSpeedXCoord
- cp a,7
- jr nz,.fromFastToMedium
- add a,7
- jr .updateTextSpeedXCoord
-.fromFastToMedium
- add a,6
-.updateTextSpeedXCoord
- ld [wOptionsTextSpeedCursorX],a ; text speed cursor X coordinate
- jp .eraseOldMenuCursor
-
-TextSpeedOptionText:
- db "TEXT SPEED"
- next " FAST MEDIUM SLOW@"
-
-BattleAnimationOptionText:
- db "BATTLE ANIMATION"
- next " ON OFF@"
-
-BattleStyleOptionText:
- db "BATTLE STYLE"
- next " SHIFT SET@"
-
-OptionMenuCancelText:
- db "CANCEL@"
-
-; sets the options variable according to the current placement of the menu cursors in the options menu
-SetOptionsFromCursorPositions:
- ld hl,TextSpeedOptionData
- ld a,[wOptionsTextSpeedCursorX] ; text speed cursor X coordinate
- ld c,a
-.loop
- ld a,[hli]
- cp c
- jr z,.textSpeedMatchFound
- inc hl
- jr .loop
-.textSpeedMatchFound
- ld a,[hl]
- ld d,a
- ld a,[wOptionsBattleAnimCursorX] ; battle animation cursor X coordinate
- dec a
- jr z,.battleAnimationOn
-.battleAnimationOff
- set 7,d
- jr .checkBattleStyle
-.battleAnimationOn
- res 7,d
-.checkBattleStyle
- ld a,[wOptionsBattleStyleCursorX] ; battle style cursor X coordinate
- dec a
- jr z,.battleStyleShift
-.battleStyleSet
- set 6,d
- jr .storeOptions
-.battleStyleShift
- res 6,d
-.storeOptions
- ld a,d
- ld [wOptions],a
+ callab DisplayOptionMenu_ ; 10:5c70
ret
-; reads the options variable and places menu cursors in the correct positions within the options menu
-SetCursorPositionsFromOptions:
- ld hl,TextSpeedOptionData + 1
- ld a,[wOptions]
- ld c,a
- and a,$3f
- push bc
- ld de,2
- call IsInArray
- pop bc
- dec hl
- ld a,[hl]
- 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 [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 [wOptionsBattleStyleCursorX],a ; battle style cursor X coordinate
- coord hl, 0, 13
- call .placeUnfilledRightArrow
-; cursor in front of Cancel
- coord hl, 0, 16
- ld a,1
-.placeUnfilledRightArrow
- ld e,a
- ld d,0
- add hl,de
- ld [hl],$ec ; unfilled right arrow menu cursor
- ret
-
-; table that indicates how the 3 text speed options affect frame delays
-; Format:
-; 00: X coordinate of menu cursor
-; 01: delay after printing a letter (in frames)
-TextSpeedOptionData:
- db 14,5 ; Slow
- db 7,3 ; Medium
- db 1,1 ; Fast
- db 7 ; default X coordinate (Medium)
- db $ff ; terminator
-
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
diff --git a/engine/menu/naming_screen.asm b/engine/menu/naming_screen.asm
index 759be189..911c4e99 100755
--- a/engine/menu/naming_screen.asm
+++ b/engine/menu/naming_screen.asm
@@ -5,9 +5,8 @@ AskName:
ld a, [wIsInBattle]
dec a
coord hl, 0, 0
- ld b, 4
- ld c, 11
- call z, ClearScreenArea ; only if in wild batle
+ lb bc, 4, 11
+ call z, ClearScreenArea ; only if in wild battle
ld a, [wcf91]
ld [wd11e], a
call GetMonName
@@ -40,7 +39,7 @@ AskName:
pop af
ld [wUpdateSpritesEnabled], a
ld a, [wcf4b]
- cp $50
+ cp "@"
ret nz
.declinedNickname
ld d, h
@@ -49,7 +48,7 @@ AskName:
ld bc, NAME_LENGTH
jp CopyData
-DoYouWantToNicknameText: ; 0x6557
+DoYouWantToNicknameText:
TX_FAR _DoYouWantToNicknameText
db "@"
@@ -94,8 +93,7 @@ DisplayNamingScreen:
call LoadEDTile
callba LoadMonPartySpriteGfx
coord hl, 0, 4
- ld b, 9
- ld c, 18
+ lb bc, 9, 18
call TextBoxBorder
call PrintNamingText
ld a, 3
@@ -108,7 +106,7 @@ DisplayNamingScreen:
ld [wMenuWatchedKeys], a
ld a, 7
ld [wMaxMenuItem], a
- ld a, $50
+ ld a, "@"
ld [wcf4b], a
xor a
ld hl, wNamingScreenSubmitName
@@ -153,7 +151,7 @@ DisplayNamingScreen:
ld h, [hl]
ld l, a
push de
- jp [hl]
+ jp hl
.submitNickname
pop de
@@ -259,7 +257,7 @@ DisplayNamingScreen:
.addLetter
ld a, [wNamingScreenLetter]
ld [hli], a
- ld [hl], $50
+ ld [hl], "@"
ld a, SFX_PRESS_AB
call PlaySound
ret
@@ -324,12 +322,28 @@ DisplayNamingScreen:
jp EraseMenuCursor
LoadEDTile:
+; In Red/Blue, the bank for the ED_tile was defined incorrectly as bank0
+; Luckily, the MBC3 treats loading $0 into $2000-$2fff range as loading bank1 into $4000-$7fff range
+; Because Yellow uses the MBC5, loading $0 into $2000 - $2fff range will load bank0 instead of bank1 and thus incorrectly load the tile
+; Instead of defining the correct bank, GameFreak decided to simply copy the ED_Tile in the function during HBlank
ld de, ED_Tile
ld hl, vFont + $700
- 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
+ ld c, $4 ; number of copies needed
+.waitForHBlankLoop
+ ld a, [rSTAT]
+ and %10 ; in HBlank?
+ jr nz, .waitForHBlankLoop
+ ld a, [de]
+ ld [hli], a
+ ld [hli], a
+ inc de
+ ld a, [de]
+ ld [hli], a
+ ld [hli], a
+ inc de
+ dec c
+ jr nz, .waitForHBlankLoop
+ ret
ED_Tile:
INCBIN "gfx/ED_tile.1bpp"
diff --git a/engine/menu/oaks_pc.asm b/engine/menu/oaks_pc.asm
index 55852b63..e4172ec7 100755
--- a/engine/menu/oaks_pc.asm
+++ b/engine/menu/oaks_pc.asm
@@ -7,9 +7,9 @@ OpenOaksPC:
call YesNoChoice
ld a, [wCurrentMenuItem]
and a
- jr nz, .asm_1e932
+ jr nz, .closePC
predef DisplayDexRating
-.asm_1e932
+.closePC
ld hl, ClosedOaksPCText
call PrintText
jp LoadScreenTilesFromBuffer2
diff --git a/engine/menu/options.asm b/engine/menu/options.asm
new file mode 100644
index 00000000..7bed30ae
--- /dev/null
+++ b/engine/menu/options.asm
@@ -0,0 +1,443 @@
+DisplayOptionMenu_:
+ call Func_41f06
+.optionMenuLoop
+ call JoypadLowSensitivity
+ ld a, [hJoy5]
+ and START | B_BUTTON
+ jr nz, .exitOptionMenu
+ call Func_41eb7
+ jr c, .asm_41c86
+ call Func_41c95
+ jr c, .exitOptionMenu
+.asm_41c86
+ call Func_41ee9
+ call DelayFrame
+ call DelayFrame
+ call DelayFrame
+ jr .optionMenuLoop
+.exitOptionMenu
+ ret
+
+Func_41c95:
+ ld a, [wOptionsCursorLocation]
+ ld e, a
+ ld d, $0
+ ld hl, OptionMenuJumpTable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
+
+OptionMenuJumpTable:
+ dw OptionsMenu_TextSpeed
+ dw OptionsMenu_BattleAnimations
+ dw OptionsMenu_BattleStyle
+ dw OptionsMenu_SpeakerSettings
+ dw OptionsMenu_GBPrinterBrightness
+ dw OptionsMenu_Dummy
+ dw OptionsMenu_Dummy
+ dw OptionsMenu_Cancel
+
+OptionsMenu_TextSpeed:
+ call Func_41d07
+ ld a, [hJoy5]
+ bit 4, a ; right
+ jr nz, .pressedRight
+ bit 5, a
+ jr nz, .pressedLeft
+ jr .asm_41ce0
+.pressedRight
+ ld a, c
+ cp $2
+ jr c, .asm_41cca
+ ld c, $ff
+.asm_41cca
+ inc c
+ ld a, e
+ jr .asm_41cd6
+.pressedLeft
+ ld a, c
+ and a
+ jr nz, .asm_41cd4
+ ld c, $3
+.asm_41cd4
+ dec c
+ ld a, d
+.asm_41cd6
+ ld b, a
+ ld a, [wOptions]
+ and $f0
+ or b
+ ld [wOptions], a
+.asm_41ce0
+ ld b, $0
+ ld hl, TextSpeedStringsPointerTable
+ add hl, bc
+ add hl, bc
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ coord hl, 14, 2
+ call PlaceString
+ and a
+ ret
+
+TextSpeedStringsPointerTable:
+ dw FastText
+ dw MidText
+ dw SlowText
+
+FastText:
+ db "FAST@"
+MidText:
+ db "MID @"
+SlowText:
+ db "SLOW@"
+
+Func_41d07:
+ ld a, [wOptions]
+ and $f
+ cp $5
+ jr z, .slowTextOption
+ cp $1
+ jr z, .fastTextOption
+; mid text option
+ ld c, $1
+ lb de, 1, 5
+ ret
+.slowTextOption
+ ld c, $2
+ lb de, 3, 1
+ ret
+.fastTextOption
+ ld c, $0
+ lb de, 5, 3
+ ret
+
+OptionsMenu_BattleAnimations:
+ ld a, [hJoy5]
+ and D_RIGHT | D_LEFT
+ jr nz, .asm_41d33
+ ld a, [wOptions]
+ and $80 ; mask other bits
+ jr .asm_41d3b
+.asm_41d33
+ ld a, [wOptions]
+ xor $80
+ ld [wOptions], a
+.asm_41d3b
+ ld bc, $0
+ sla a
+ rl c
+ ld hl, AnimationOptionStringsPointerTable
+ add hl, bc
+ add hl, bc
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ coord hl, 14, 4
+ call PlaceString
+ and a
+ ret
+
+AnimationOptionStringsPointerTable:
+ dw AnimationOnText
+ dw AnimationOffText
+
+AnimationOnText:
+ db "ON @"
+AnimationOffText:
+ db "OFF@"
+
+OptionsMenu_BattleStyle:
+ ld a, [hJoy5]
+ and D_LEFT | D_RIGHT
+ jr nz, .asm_41d6b
+ ld a, [wOptions]
+ and $40 ; mask other bits
+ jr .asm_41d73
+.asm_41d6b
+ ld a, [wOptions]
+ xor $40
+ ld [wOptions], a
+.asm_41d73
+ ld bc, $0
+ sla a
+ sla a
+ rl c
+ ld hl, BattleStyleOptionStringsPointerTable
+ add hl, bc
+ add hl, bc
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ coord hl, 14, 6
+ call PlaceString
+ and a
+ ret
+
+BattleStyleOptionStringsPointerTable:
+ dw BattleStyleShiftText
+ dw BattleStyleSetText
+
+BattleStyleShiftText:
+ db "SHIFT@"
+BattleStyleSetText:
+ db "SET @"
+
+OptionsMenu_SpeakerSettings:
+ ld a, [wOptions]
+ and $30
+ swap a
+ ld c, a
+ ld a, [hJoy5]
+ bit 4, a
+ jr nz, .pressedRight
+ bit 5, a
+ jr nz, .pressedLeft
+ jr .asm_41dca
+.pressedRight
+ ld a, c
+ inc a
+ and $3
+ jr .asm_41dba
+.pressedLeft
+ ld a, c
+ dec a
+ and $3
+.asm_41dba
+ ld c, a
+ swap a
+ ld b, a
+ xor a
+ ld [rNR51], a
+ ld a, [wOptions]
+ and $cf
+ or b
+ ld [wOptions], a
+.asm_41dca
+ ld b, $0
+ ld hl, SpeakerOptionStringsPointerTable
+ add hl, bc
+ add hl, bc
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ coord hl, 8, 8
+ call PlaceString
+ and a
+ ret
+
+SpeakerOptionStringsPointerTable:
+ dw MonoSoundText
+ dw Earphone1SoundText
+ dw Earphone2SoundText
+ dw Earphone3SoundText
+
+MonoSoundText:
+ db "MONO @"
+Earphone1SoundText:
+ db "EARPHONE1@"
+Earphone2SoundText:
+ db "EARPHONE2@"
+Earphone3SoundText:
+ db "EARPHONE3@"
+
+OptionsMenu_GBPrinterBrightness:
+ call Func_41e7b
+ ld a, [hJoy5]
+ bit 4, a
+ jr nz, .pressedRight
+ bit 5, a
+ jr nz, .pressedLeft
+ jr .asm_41e32
+.pressedRight
+ ld a, c
+ cp $4
+ jr c, .asm_41e22
+ ld c, $ff
+.asm_41e22
+ inc c
+ ld a, e
+ jr .asm_41e2e
+.pressedLeft
+ ld a, c
+ and a
+ jr nz, .asm_41e2c
+ ld c, $5
+.asm_41e2c
+ dec c
+ ld a, d
+.asm_41e2e
+ ld b, a
+ ld [wPrinterSettings], a
+.asm_41e32
+ ld b, $0
+ ld hl, GBPrinterOptionStringsPointerTable
+ add hl, bc
+ add hl, bc
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ coord hl, 8, 10
+ call PlaceString
+ and a
+ ret
+
+GBPrinterOptionStringsPointerTable:
+ dw LightestPrintText
+ dw LighterPrintText
+ dw NormalPrintText
+ dw DarkerPrintText
+ dw DarkestPrintText
+
+LightestPrintText:
+ db "LIGHTEST@"
+LighterPrintText:
+ db "LIGHTER @"
+NormalPrintText:
+ db "NORMAL @"
+DarkerPrintText:
+ db "DARKER @"
+DarkestPrintText:
+ db "DARKEST @"
+
+Func_41e7b:
+ ld a, [wPrinterSettings]
+ and a
+ jr z, .asm_41e93
+ cp $20
+ jr z, .asm_41e99
+ cp $60
+ jr z, .asm_41e9f
+ cp $7f
+ jr z, .asm_41ea5
+ ld c, $2
+ lb de, $20, $60
+ ret
+.asm_41e93
+ ld c, $0
+ lb de, $7f, $20
+ ret
+.asm_41e99
+ ld c, $1
+ lb de, $0, $40
+ ret
+.asm_41e9f
+ ld c, $3
+ lb de, $40, $7f
+ ret
+.asm_41ea5
+ ld c, $4
+ lb de, $60, $0
+ ret
+
+OptionsMenu_Dummy:
+ and a
+ ret
+
+OptionsMenu_Cancel:
+ ld a, [hJoy5]
+ and A_BUTTON
+ jr nz, .pressedCancel
+ and a
+ ret
+.pressedCancel
+ scf
+ ret
+
+Func_41eb7:
+ ld hl, wOptionsCursorLocation
+ ld a, [hJoy5]
+ cp D_DOWN
+ jr z, .pressedDown
+ cp D_UP
+ jr z, .pressedUp
+ and a
+ ret
+.pressedDown
+ ld a, [hl]
+ cp $7
+ jr nz, .doNotWrapAround
+ ld [hl], $0
+ scf
+ ret
+.doNotWrapAround
+ cp $4
+ jr c, .regularIncrement
+ ld [hl], $6
+.regularIncrement
+ inc [hl]
+ scf
+ ret
+.pressedUp
+ ld a, [hl]
+ cp $7
+ jr nz, .doNotMoveCursorToPrintOption
+ ld [hl], $4
+ scf
+ ret
+.doNotMoveCursorToPrintOption
+ and a
+ jr nz, .regularDecrement
+ ld [hl], $8
+.regularDecrement
+ dec [hl]
+ scf
+ ret
+
+Func_41ee9:
+ coord hl, 1, 1
+ ld de, SCREEN_WIDTH
+ ld c, 16
+.loop
+ ld [hl], " "
+ add hl, de
+ dec c
+ jr nz, .loop
+ coord hl, 1, 2
+ ld bc, SCREEN_WIDTH * 2
+ ld a, [wOptionsCursorLocation]
+ call AddNTimes
+ ld [hl], "▶"
+ ret
+
+Func_41f06:
+ coord hl, 0, 0
+ lb bc, SCREEN_HEIGHT - 2, SCREEN_WIDTH - 2
+ call TextBoxBorder
+ coord hl, 2, 2
+ ld de, AllOptionsText
+ call PlaceString
+ coord hl, 2, 16
+ ld de, OptionMenuCancelText
+ call PlaceString
+ xor a
+ ld [wOptionsCursorLocation], a
+ ld c, 5
+.loop
+ push bc
+ call Func_41c95
+ pop bc
+ ld hl, wOptionsCursorLocation
+ inc [hl]
+ dec c
+ jr nz, .loop
+ xor a
+ ld [wOptionsCursorLocation], a
+ inc a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Delay3
+ ret
+
+AllOptionsText:
+ db "TEXT SPEED :"
+ next "ANIMATION :"
+ next "BATTLESTYLE:"
+ next "SOUND:"
+ next "PRINT:@"
+
+OptionMenuCancelText:
+ db "CANCEL@"
diff --git a/engine/menu/party_menu.asm b/engine/menu/party_menu.asm
index 7ef14232..669d49db 100755
--- a/engine/menu/party_menu.asm
+++ b/engine/menu/party_menu.asm
@@ -49,9 +49,17 @@ RedrawPartyMenu_:
call GetPartyMonName
pop hl
call PlaceString ; print the pokemon's name
- callba WriteMonPartySpriteOAMByPartyIndex ; place the appropriate pokemon icon
ld a,[hPartyMonIndex]
ld [wWhichPokemon],a
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .regularMon
+ call CheckPikachuFollowingPlayer
+ jr z, .regularMon
+ ld a, $ff
+ ld [hPartyMonIndex], a
+.regularMon
+ callba WriteMonPartySpriteOAMByPartyIndex ; place the appropriate pokemon icon
+ ld a, [wWhichPokemon]
inc a
ld [hPartyMonIndex],a
call LoadMonData
@@ -88,14 +96,14 @@ RedrawPartyMenu_:
pop hl
push hl
ld bc,20 + 1 ; down 1 row and right 1 column
- ld a,[hFlags_0xFFF6]
+ ld a,[hFlags_0xFFFA]
set 0,a
- ld [hFlags_0xFFF6],a
+ ld [hFlags_0xFFFA],a
add hl,bc
predef DrawHP2 ; draw HP bar and prints current / max HP
- ld a,[hFlags_0xFFF6]
+ ld a,[hFlags_0xFFFA]
res 0,a
- ld [hFlags_0xFFF6],a
+ ld [hFlags_0xFFFA],a
call SetPartyMenuHPBarColor ; color the HP bar (on SGB)
pop hl
jr .printLevel
@@ -109,8 +117,8 @@ RedrawPartyMenu_:
jr nz,.placeMoveLearnabilityString
ld de,.notAbleToLearnMoveText
.placeMoveLearnabilityString
- ld bc,20 + 9 ; down 1 row and right 9 columns
push hl
+ ld bc,20 + 9 ; down 1 row and right 9 columns
add hl,bc
call PlaceString
pop hl
@@ -150,7 +158,7 @@ RedrawPartyMenu_:
ld l,a
ld de,wcd6d
ld a,BANK(EvosMovesPointerTable)
- ld bc,Mon133_EvosEnd - Mon133_EvosMoves
+ ld bc, $0d ; Mon133_EvosEnd - Mon133_EvosMoves
call FarCopyData
ld hl,wcd6d
ld de,.notAbleToEvolveText
@@ -176,9 +184,9 @@ RedrawPartyMenu_:
; if it does match
ld de,.ableToEvolveText
.placeEvolutionStoneString
- ld bc,20 + 9 ; down 1 row and right 9 columns
pop hl
push hl
+ ld bc,20 + 9 ; down 1 row and right 9 columns
add hl,bc
call PlaceString
pop hl
diff --git a/engine/menu/pc.asm b/engine/menu/pc.asm
index 8ec31226..b31970c8 100755
--- a/engine/menu/pc.asm
+++ b/engine/menu/pc.asm
@@ -121,18 +121,18 @@ RemoveItemByID:
ld b, a
xor a
ld [hItemToRemoveIndex], a
-.asm_17f40
+.loop
ld a, [hli]
- cp $ff
+ cp $ff ; have we reached the cancel button (terminator)
ret z
- cp b
- jr z, .asm_17f4f
+ cp b ; is the current item the item we want?
+ jr z, .foundItem ; if so, remove it from the inventory
inc hl
ld a, [hItemToRemoveIndex]
inc a
ld [hItemToRemoveIndex], a
- jr .asm_17f40
-.asm_17f4f
+ jr .loop
+.foundItem
ld a, $1
ld [wItemQuantity], a
ld a, [hItemToRemoveIndex]
diff --git a/engine/menu/players_pc.asm b/engine/menu/players_pc.asm
index bc2be4ef..1cc02cbf 100755
--- a/engine/menu/players_pc.asm
+++ b/engine/menu/players_pc.asm
@@ -1,6 +1,4 @@
PlayerPC:
- ld hl, wd730
- set 6, [hl]
ld a, ITEM_NAME
ld [wNameListType], a
call SaveScreenTilesToBuffer1
@@ -17,14 +15,15 @@ PlayerPC:
call PrintText
PlayerPCMenu:
+ ld hl, wd730
+ set 6, [hl]
ld a, [wParentMenuItem]
ld [wCurrentMenuItem], a
ld hl, wFlags_0xcd60
set 5, [hl]
call LoadScreenTilesFromBuffer2
coord hl, 0, 0
- ld b, $8
- ld c, $e
+ lb bc, 8, 14
call TextBoxBorder
call UpdateSprites
coord hl, 2, 2
diff --git a/engine/menu/pokedex.asm b/engine/menu/pokedex.asm
index 3078f1a9..5bc8f119 100755
--- a/engine/menu/pokedex.asm
+++ b/engine/menu/pokedex.asm
@@ -2,53 +2,57 @@ ShowPokedexMenu:
call GBPalWhiteOut
call ClearScreen
call UpdateSprites
- ld a,[wListScrollOffset]
+ ld a, [wListScrollOffset]
push af
xor a
- ld [wCurrentMenuItem],a
- ld [wListScrollOffset],a
- ld [wLastMenuItem],a
+ ld [wCurrentMenuItem], a
+ ld [wListScrollOffset], a
+ ld [wLastMenuItem], a
inc a
- ld [wd11e],a
- ld [hJoy7],a
+ ld [wd11e], a
+ ld [hJoy7], a
.setUpGraphics
+ callab LoadPokedexTilePatterns
+.loop
ld b, SET_PAL_GENERIC
call RunPaletteCommand
- callab LoadPokedexTilePatterns
.doPokemonListMenu
- ld hl,wTopMenuItemY
- ld a,3
- ld [hli],a ; top menu item Y
+ ld hl, wTopMenuItemY
+ ld a, 3
+ ld [hli], a ; top menu item Y
xor a
- ld [hli],a ; top menu item X
+ ld [hli], a ; top menu item X
inc a
- ld [wMenuWatchMovingOutOfBounds],a
+ ld [wMenuWatchMovingOutOfBounds], a
inc hl
inc hl
- ld a,6
- ld [hli],a ; max menu item ID
- ld [hl],D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
+ ld a, 6
+ ld [hli], a ; max menu item ID
+ ld [hl], D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
call HandlePokedexListMenu
- jr c,.goToSideMenu ; if the player chose a pokemon from the list
+ jr c, .goToSideMenu ; if the player chose a pokemon from the list
.exitPokedex
xor a
- ld [wMenuWatchMovingOutOfBounds],a
- ld [wCurrentMenuItem],a
- ld [wLastMenuItem],a
- ld [hJoy7],a
- ld [wWastedByteCD3A],a
- ld [wOverrideSimulatedJoypadStatesMask],a
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld [wCurrentMenuItem], a
+ ld [wLastMenuItem], a
+ ld [hJoy7], a
+ ld [wWastedByteCD3A], a
+ ld [wOverrideSimulatedJoypadStatesMask], a
pop af
- ld [wListScrollOffset],a
+ ld [wListScrollOffset], a
call GBPalWhiteOutWithDelay3
call RunDefaultPaletteCommand
jp ReloadMapData
+
.goToSideMenu
call HandlePokedexSideMenu
dec b
- jr z,.exitPokedex ; if the player chose Quit
+ jr z, .exitPokedex ; if the player chose Quit
+ dec b
+ jr z, .doPokemonListMenu ; if pokemon not seen or player pressed B button
dec b
- jr z,.doPokemonListMenu ; if pokemon not seen or player pressed B button
+ jr z, .loop
jp .setUpGraphics ; if pokemon data or area was shown
; handles the menu on the lower right in the pokedex screen
@@ -59,204 +63,337 @@ ShowPokedexMenu:
; 02: the pokemon has not been seen yet or the player pressed the B button
HandlePokedexSideMenu:
call PlaceUnfilledArrowMenuCursor
- ld a,[wCurrentMenuItem]
+ ld a, [wCurrentMenuItem]
push af
- ld b,a
- ld a,[wLastMenuItem]
+ ld b, a
+ ld a, [wLastMenuItem]
push af
- ld a,[wListScrollOffset]
+ ld a, [wListScrollOffset]
push af
add b
inc a
- ld [wd11e],a
- ld a,[wd11e]
+ ld [wd11e], a
+ ld a, [wd11e]
push af
- ld a,[wDexMaxSeenMon]
+ ld a, [wDexMaxSeenMon]
push af ; this doesn't need to be preserved
- ld hl,wPokedexSeen
+ ld hl, wPokedexSeen
call IsPokemonBitSet
- ld b,2
- jr z,.exitSideMenu
+ ld b, 2
+ jr z, .exitSideMenu
call PokedexToIndex
- ld hl,wTopMenuItemY
- ld a,10
- ld [hli],a ; top menu item Y
- ld a,15
- ld [hli],a ; top menu item X
+ ld hl, wTopMenuItemY
+ ld a, 8
+ ld [hli], a ; top menu item Y
+ ld a, 15
+ ld [hli], a ; top menu item X
xor a
- ld [hli],a ; current menu item ID
+ ld [hli], a ; current menu item ID
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)
+ ld a, 4
+ 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 [wMenuWatchMovingOutOfBounds],a
+ ld [hli], a ; old menu item ID
+ ld [wMenuWatchMovingOutOfBounds], a
+ ld [hJoy7], a
.handleMenuInput
call HandleMenuInput
- bit 1,a ; was the B button pressed?
- ld b,2
- jr nz,.buttonBPressed
- ld a,[wCurrentMenuItem]
+ bit 1, a ; was the B button pressed?
+ ld b, 2
+ jr nz, .buttonBPressed
+ ld a, [wCurrentMenuItem]
and a
- jr z,.choseData
+ jr z, .choseData
+ dec a
+ jr z, .choseCry
dec a
- jr z,.choseCry
+ jr z, .choseArea
dec a
- jr z,.choseArea
+ jr z, .chosePrint
.choseQuit
- ld b,1
+ ld b, 1
.exitSideMenu
pop af
- ld [wDexMaxSeenMon],a
+ ld [wDexMaxSeenMon], a
pop af
- ld [wd11e],a
+ ld [wd11e], a
pop af
- ld [wListScrollOffset],a
+ ld [wListScrollOffset], a
pop af
- ld [wLastMenuItem],a
+ ld [wLastMenuItem], a
pop af
- ld [wCurrentMenuItem],a
+ ld [wCurrentMenuItem], a
+ ld a, $1
+ ld [hJoy7], a
push bc
coord hl, 0, 3
- ld de,20
+ ld de, 20
lb bc, " ", 13
call DrawTileLine ; cover up the menu cursor in the pokemon list
pop bc
ret
+
.buttonBPressed
push bc
- coord hl, 15, 10
- ld de,20
- lb bc, " ", 7
+ coord hl, 15, 8
+ ld de, 20
+ lb bc, " ", 9
call DrawTileLine ; cover up the menu cursor in the side menu
pop bc
jr .exitSideMenu
+
.choseData
call ShowPokedexDataInternal
- ld b,0
+ ld b, 0
jr .exitSideMenu
+
; play pokemon cry
.choseCry
- ld a,[wd11e]
+ ld a, [wd11e]
call GetCryData
call PlaySound
jr .handleMenuInput
+
.choseArea
predef LoadTownMap_Nest ; display pokemon areas
- ld b,0
+ ld b, 0
+ jr .exitSideMenu
+
+.chosePrint
+ ld a, [hTilesetType]
+ push af
+ xor a
+ ld [hTilesetType], a
+ ld a, [wd11e]
+ ld [wcf91], a
+ callab PrintPokedexEntry
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call ClearScreen
+ pop af
+ ld [hTilesetType], a
+ ld b, $3
jr .exitSideMenu
; 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:
+ call Pokedex_DrawInterface
+.loop
+ call Pokedex_PlacePokemonList
+ call GBPalNormal
+ call HandleMenuInput
+ bit BIT_B_BUTTON, a ; was the B button pressed?
+ jp nz, .buttonBPressed
+ bit BIT_A_BUTTON, a ; was the A button pressed?
+ jp nz, .buttonAPressed
+.checkIfUpPressed
+ bit BIT_D_UP, a ; was Up pressed?
+ jr z, .checkIfDownPressed
+.upPressed ; scroll up one row
+ ld a, [wListScrollOffset]
+ and a
+ jp z, .loop
+ dec a
+ ld [wListScrollOffset], a
+ jp .loop
+
+.checkIfDownPressed
+ bit BIT_D_DOWN, a ; was Down pressed?
+ jr z, .checkIfRightPressed
+.downPressed ; scroll down one row
+ ld a, [wDexMaxSeenMon]
+ cp a, 7
+ jp c, .loop ; can't if the list is shorter than 7
+ sub a, 7
+ ld b, a
+ ld a, [wListScrollOffset]
+ cp b
+ jp z, .loop
+ inc a
+ ld [wListScrollOffset], a
+ jp .loop
+
+.checkIfRightPressed
+ bit BIT_D_RIGHT, a ; was Right pressed?
+ jr z, .checkIfLeftPressed
+.rightPressed ; scroll down 7 rows
+ ld a, [wDexMaxSeenMon]
+ cp a, 7
+ jp c, .loop ; can't if the list is shorter than 7
+ sub a, 6
+ ld b, a
+ ld a, [wListScrollOffset]
+ add a, 7
+ ld [wListScrollOffset], a
+ cp b
+ jp c, .loop
+ dec b
+ ld a, b
+ ld [wListScrollOffset], a
+ jp .loop
+
+.checkIfLeftPressed ; scroll up 7 rows
+ bit BIT_D_LEFT, a ; was Left pressed?
+ jr z, .buttonAPressed
+.leftPressed
+ ld a, [wListScrollOffset]
+ sub a, 7
+ ld [wListScrollOffset], a
+ jp nc, .loop
+ xor a
+ ld [wListScrollOffset], a
+ jp .loop
+
+.buttonAPressed
+ scf
+ ret
+
+.buttonBPressed
+ and a
+ ret
+
+Pokedex_DrawInterface:
xor a
- ld [H_AUTOBGTRANSFERENABLED],a
+ ld [H_AUTOBGTRANSFERENABLED], a
; draw the horizontal line separating the seen and owned amounts from the menu
- coord hl, 15, 8
- ld a,$7a ; horizontal line tile
- ld [hli],a
- ld [hli],a
- ld [hli],a
- ld [hli],a
- ld [hli],a
+ coord hl, 15, 6
+ ld a, $7a ; horizontal line tile
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
coord hl, 14, 0
- ld [hl],$71 ; vertical line tile
+ ld [hl], $71 ; vertical line tile
coord hl, 14, 1
call DrawPokedexVerticalLine
coord hl, 14, 9
call DrawPokedexVerticalLine
- ld hl,wPokedexSeen
- ld b,wPokedexSeenEnd - wPokedexSeen
+ ld hl, wPokedexSeen
+ ld b, wPokedexSeenEnd - wPokedexSeen
call CountSetBits
ld de, wNumSetBits
- coord hl, 16, 3
+ coord hl, 16, 2
lb bc, 1, 3
call PrintNumber ; print number of seen pokemon
- ld hl,wPokedexOwned
- ld b,wPokedexOwnedEnd - wPokedexOwned
+ ld hl, wPokedexOwned
+ ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
ld de, wNumSetBits
- coord hl, 16, 6
+ coord hl, 16, 5
lb bc, 1, 3
call PrintNumber ; print number of owned pokemon
- coord hl, 16, 2
- ld de,PokedexSeenText
+ coord hl, 16, 1
+ ld de, PokedexSeenText
call PlaceString
- coord hl, 16, 5
- ld de,PokedexOwnText
+ coord hl, 16, 4
+ ld de, PokedexOwnText
call PlaceString
coord hl, 1, 1
- ld de,PokedexContentsText
+ ld de, PokedexContentsText
call PlaceString
- coord hl, 16, 10
- ld de,PokedexMenuItemsText
+ coord hl, 16, 8
+ ld de, PokedexMenuItemsText
call PlaceString
; find the highest pokedex number among the pokemon the player has seen
- ld hl,wPokedexSeenEnd - 1
- ld b,(wPokedexSeenEnd - wPokedexSeen) * 8 + 1
+ ld hl, wPokedexSeenEnd - 1
+ ld b, (wPokedexSeenEnd - wPokedexSeen) * 8 + 1
.maxSeenPokemonLoop
- ld a,[hld]
- ld c,8
+ ld a, [hld]
+ ld c, 8
.maxSeenPokemonInnerLoop
dec b
sla a
- jr c,.storeMaxSeenPokemon
+ jr c, .storeMaxSeenPokemon
dec c
- jr nz,.maxSeenPokemonInnerLoop
+ jr nz, .maxSeenPokemonInnerLoop
jr .maxSeenPokemonLoop
+
.storeMaxSeenPokemon
- ld a,b
- ld [wDexMaxSeenMon],a
+ ld a, b
+ ld [wDexMaxSeenMon], a
+ ret
+
+DrawPokedexVerticalLine:
+ ld c, 9 ; height of line
+ ld de, SCREEN_WIDTH ; width of screen
+ ld a, $71 ; vertical line tile
.loop
+ ld [hl], a
+ add hl, de
+ xor a, 1 ; toggle between vertical line tile and box tile
+ dec c
+ jr nz, .loop
+ ret
+
+PokedexSeenText:
+ db "SEEN@"
+
+PokedexOwnText:
+ db "OWN@"
+
+PokedexContentsText:
+ db "CONTENTS@"
+
+PokedexMenuItemsText:
+ db "DATA"
+ next "CRY"
+ next "AREA"
+ next "PRNT"
+ next "QUIT@"
+
+Pokedex_PlacePokemonList:
xor a
- ld [H_AUTOBGTRANSFERENABLED],a
+ ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 4, 2
lb bc, 14, 10
call ClearScreenArea
coord hl, 1, 3
- ld a,[wListScrollOffset]
- ld [wd11e],a
- ld d,7
- ld a,[wDexMaxSeenMon]
- cp a,7
- jr nc,.printPokemonLoop
- ld d,a
+ ld a, [wListScrollOffset]
+ ld [wd11e], a
+ ld d, 7
+ ld a, [wDexMaxSeenMon]
+ cp a, 7
+ jr nc, .printPokemonLoop
+ ld d, a
dec a
- ld [wMaxMenuItem],a
+ ld [wMaxMenuItem], a
; loop to print pokemon pokedex numbers and names
; if the player has owned the pokemon, it puts a pokeball beside the name
.printPokemonLoop
- ld a,[wd11e]
+ ld a, [wd11e]
inc a
- ld [wd11e],a
+ ld [wd11e], a
push af
push de
push hl
- ld de,-SCREEN_WIDTH
- add hl,de
- ld de,wd11e
+ ld de, -SCREEN_WIDTH
+ add hl, de
+ ld de, wd11e
lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; print the pokedex number
- ld de,SCREEN_WIDTH
- add hl,de
+ ld de, SCREEN_WIDTH
+ add hl, de
dec hl
push hl
- ld hl,wPokedexOwned
+ ld hl, wPokedexOwned
call IsPokemonBitSet
pop hl
- ld a," "
- jr z,.writeTile
- ld a,$72 ; pokeball tile
+ ld a, " "
+ jr z, .writeTile
+ ld a, $72 ; pokeball tile
.writeTile
- ld [hl],a ; put a pokeball next to pokemon that the player has owned
+ ld [hl], a ; put a pokeball next to pokemon that the player has owned
push hl
- ld hl,wPokedexSeen
+ ld hl, wPokedexSeen
call IsPokemonBitSet
- jr nz,.getPokemonName ; if the player has seen the pokemon
- ld de,.dashedLine ; print a dashed line in place of the name if the player hasn't seen the pokemon
+ jr nz, .getPokemonName ; if the player has seen the pokemon
+ ld de, .dashedLine ; print a dashed line in place of the name if the player hasn't seen the pokemon
jr .skipGettingName
+
.dashedLine ; for unseen pokemon in the list
db "----------@"
.getPokemonName
@@ -267,119 +404,29 @@ HandlePokedexListMenu:
inc hl
call PlaceString
pop hl
- ld bc,2 * 20
- add hl,bc
+ ld bc, 2 * 20
+ add hl, bc
pop de
pop af
- ld [wd11e],a
+ ld [wd11e], a
dec d
- jr nz,.printPokemonLoop
- ld a,01
- ld [H_AUTOBGTRANSFERENABLED],a
+ jr nz, .printPokemonLoop
+ ld a, 01
+ ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
- call GBPalNormal
- call HandleMenuInput
- bit 1,a ; was the B button pressed?
- jp nz,.buttonBPressed
-.checkIfUpPressed
- bit 6,a ; was Up pressed?
- jr z,.checkIfDownPressed
-.upPressed ; scroll up one row
- ld a,[wListScrollOffset]
- and a
- jp z,.loop
- dec a
- ld [wListScrollOffset],a
- jp .loop
-.checkIfDownPressed
- bit 7,a ; was Down pressed?
- jr z,.checkIfRightPressed
-.downPressed ; scroll down one row
- ld a,[wDexMaxSeenMon]
- cp a,7
- jp c,.loop ; can't if the list is shorter than 7
- sub a,7
- ld b,a
- ld a,[wListScrollOffset]
- cp b
- jp z,.loop
- inc a
- ld [wListScrollOffset],a
- jp .loop
-.checkIfRightPressed
- bit 4,a ; was Right pressed?
- jr z,.checkIfLeftPressed
-.rightPressed ; scroll down 7 rows
- ld a,[wDexMaxSeenMon]
- cp a,7
- jp c,.loop ; can't if the list is shorter than 7
- sub a,6
- ld b,a
- ld a,[wListScrollOffset]
- add a,7
- ld [wListScrollOffset],a
- cp b
- jp c,.loop
- dec b
- ld a,b
- ld [wListScrollOffset],a
- jp .loop
-.checkIfLeftPressed ; scroll up 7 rows
- bit 5,a ; was Left pressed?
- jr z,.buttonAPressed
-.leftPressed
- ld a,[wListScrollOffset]
- sub a,7
- ld [wListScrollOffset],a
- jp nc,.loop
- xor a
- ld [wListScrollOffset],a
- jp .loop
-.buttonAPressed
- scf
- ret
-.buttonBPressed
- and a
- ret
-
-DrawPokedexVerticalLine:
- ld c,9 ; height of line
- ld de,20 ; width of screen
- ld a,$71 ; vertical line tile
-.loop
- ld [hl],a
- add hl,de
- xor a,1 ; toggle between vertical line tile and box tile
- dec c
- jr nz,.loop
ret
-PokedexSeenText:
- db "SEEN@"
-
-PokedexOwnText:
- db "OWN@"
-
-PokedexContentsText:
- db "CONTENTS@"
-
-PokedexMenuItemsText:
- db "DATA"
- next "CRY"
- next "AREA"
- 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:
- ld a,[wd11e]
+ ld a, [wd11e]
dec a
- ld c,a
- ld b,FLAG_TEST
+ ld c, a
+ ld b, FLAG_TEST
predef FlagActionPredef
- ld a,c
+ ld a, c
and a
ret
@@ -392,195 +439,255 @@ ShowPokedexData:
; function to display pokedex data from inside the pokedex
ShowPokedexDataInternal:
- ld hl,wd72c
- set 1,[hl]
- ld a,$33 ; 3/7 volume
- ld [rNR50],a
+ ld hl, wd72c
+ set 1, [hl]
+ ld a, $33 ; 3/7 volume
+ ld [rNR50], a
+ ld a, [hTilesetType]
+ push af
+ xor a
+ ld [hTilesetType], a
call GBPalWhiteOut ; zero all palettes
- call ClearScreen
- ld a,[wd11e] ; pokemon ID
- ld [wcf91],a
+ ld a, [wd11e] ; pokemon ID
+ ld [wcf91], a
push af
ld b, SET_PAL_POKEDEX
call RunPaletteCommand
pop af
- ld [wd11e],a
- ld a,[hTilesetType]
- push af
- xor a
- ld [hTilesetType],a
+ ld [wd11e], a
+ call DrawDexEntryOnScreen
+ call c, Pokedex_PrintFlavorTextAtRow11
+.waitForButtonPress
+ call JoypadLowSensitivity
+ ld a, [hJoy5]
+ and a, A_BUTTON | B_BUTTON
+ jr z, .waitForButtonPress
+ pop af
+ ld [hTilesetType], a
+ call GBPalWhiteOut
+ call ClearScreen
+ call RunDefaultPaletteCommand
+ call LoadTextBoxTilePatterns
+ call GBPalNormal
+ ld hl, wd72c
+ res 1, [hl]
+ ld a, $77 ; max volume
+ ld [rNR50], a
+ ret
+
+HeightWeightText:
+ db "HT ?", $60, "??", $61
+ next "WT ???lb@"
+
+; XXX does anything point to this?
+PokeText:
+ db "#@"
+
+; horizontal line that divides the pokedex text description from the rest of the data
+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 "@"
+
+DrawDexEntryOnScreen:
+ call ClearScreen
+
coord hl, 0, 0
- ld de,1
+ ld de, 1
lb bc, $64, SCREEN_WIDTH
call DrawTileLine ; draw top border
+
coord hl, 0, 17
ld b, $6f
call DrawTileLine ; draw bottom border
+
coord hl, 0, 1
- ld de,20
+ ld de, 20
lb bc, $66, $10
call DrawTileLine ; draw left border
+
coord hl, 19, 1
- ld b,$67
+ ld b, $67
call DrawTileLine ; draw right border
- ld a,$63 ; upper left corner tile
+
+ ld a, $63 ; upper left corner tile
Coorda 0, 0
- ld a,$65 ; upper right corner tile
+ ld a, $65 ; upper right corner tile
Coorda 19, 0
- ld a,$6c ; lower left corner tile
+ ld a, $6c ; lower left corner tile
Coorda 0, 17
- ld a,$6e ; lower right corner tile
+ ld a, $6e ; lower right corner tile
+
Coorda 19, 17
coord hl, 0, 9
- ld de,PokedexDataDividerLine
+
+ ld de, PokedexDataDividerLine
call PlaceString ; draw horizontal divider line
+
coord hl, 9, 6
- ld de,HeightWeightText
+ ld de, HeightWeightText
call PlaceString
+
call GetMonName
coord hl, 9, 2
call PlaceString
- ld hl,PokedexEntryPointers
- ld a,[wd11e]
+
+ ld hl, PokedexEntryPointers
+ ld a, [wd11e]
dec a
- ld e,a
- ld d,0
- add hl,de
- add hl,de
- ld a,[hli]
- ld e,a
- ld d,[hl] ; de = address of pokedex entry
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld e, a
+ ld d, [hl] ; de = address of pokedex entry
+
coord hl, 9, 4
call PlaceString ; print species name
- ld h,b
- ld l,c
+
+ ld h, b
+ ld l, c
push de
- ld a,[wd11e]
+ ld a, [wd11e]
push af
call IndexToPokedex
+
coord hl, 2, 8
ld a, "№"
- ld [hli],a
- ld a,$f2
- ld [hli],a
- ld de,wd11e
+ ld [hli], a
+ ld a, $f2
+ ld [hli], a
+ ld de, wd11e
lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; print pokedex number
- ld hl,wPokedexOwned
+
+ ld hl, wPokedexOwned
call IsPokemonBitSet
pop af
- ld [wd11e],a
- ld a,[wcf91]
- ld [wd0b5],a
+ ld [wd11e], a
+ 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
coord hl, 1, 1
call LoadFlippedFrontSpriteByMonIndex ; draw pokemon picture
- ld a,[wcf91]
+ ld a, [wcf91]
call PlayCry ; play pokemon cry
+
pop hl
pop de
pop bc
pop af
- ld a,c
+
+ ld a, c
and a
- jp z,.waitForButtonPress ; if the pokemon has not been owned, don't print the height, weight, or description
+ ret z ; 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
+ ld a, [de] ; reads feet, but a is overwritten without being used
coord hl, 12, 6
lb bc, 1, 2
call PrintNumber ; print feet (height)
- ld a,$60 ; feet symbol tile (one tick)
- ld [hl],a
+ ld a, $60 ; feet symbol tile (one tick)
+ ld [hl], a
inc de
inc de ; de = address of inches (height)
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
+ ld a, $61 ; inches symbol tile (two ticks)
+ ld [hl], a
; now print the weight (note that weight is stored in tenths of pounds internally)
inc de
inc de
inc de ; de = address of upper byte of weight
push de
; put weight in big-endian order at hDexWeight
- ld hl,hDexWeight
- ld a,[hl] ; save existing value of [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 [hDexWeight]
- ld a,[hl] ; save existing value of [hDexWeight + 1]
+ ld a, [de] ; a = upper byte of weight
+ 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 [hDexWeight + 1]
- ld de,hDexWeight
+ ld a, [de] ; a = lower byte of weight
+ 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
coord hl, 14, 8
- ld a,[hDexWeight + 1]
- sub a,10
- 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
+ ld a, [hDexWeight + 1]
+ sub a, 10
+ 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
.next
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 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
pop af
- ld [hDexWeight + 1],a ; restore original value of [hDexWeight + 1]
+ ld [hDexWeight + 1], a ; restore original value of [hDexWeight + 1]
pop af
- ld [hDexWeight],a ; restore original value of [hDexWeight]
+ ld [hDexWeight], a ; restore original value of [hDexWeight]
pop hl
inc hl ; hl = address of pokedex description text
+ scf
+ ret
+
+Pokedex_PrintFlavorTextAtRow11:
coord bc, 1, 11
- ld a,2
- ld [$fff4],a
+Pokedex_PrintFlavorTextAtBC:
+ ld a, 2
+ ld [$fff9], a
call TextCommandProcessor ; print pokedex description text
xor a
- ld [$fff4],a
-.waitForButtonPress
- call JoypadLowSensitivity
- ld a,[hJoy5]
- and a,A_BUTTON | B_BUTTON
- jr z,.waitForButtonPress
- pop af
- ld [hTilesetType],a
- call GBPalWhiteOut
- call ClearScreen
- call RunDefaultPaletteCommand
- call LoadTextBoxTilePatterns
- call GBPalNormal
- ld hl,wd72c
- res 1,[hl]
- ld a,$77 ; max volume
- ld [rNR50],a
+ ld [$fff9], a
ret
-HeightWeightText:
- db "HT ?",$60,"??",$61,$4E,"WT ???lb@"
-
-; XXX does anything point to this?
-PokeText:
- db "#@"
-
-; horizontal line that divides the pokedex text description from the rest of the data
-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
+Pokedex_PrepareDexEntryForPrinting:
+ coord hl, 0, 0
+ ld de, SCREEN_WIDTH
+ lb bc, $66, $d
+ call DrawTileLine
+ coord hl, 19, 0
+ ld b, $67
+ call DrawTileLine
+ coord hl, 0, 13
+ ld de, $1
+ lb bc, $6f, SCREEN_WIDTH
+ call DrawTileLine
+ ld a, $6c
+ Coorda 0, 13
+ ld a, $6e
+ Coorda 19, 13
+ ld a, [wPrinterPokedexEntryTextPointer]
+ ld l, a
+ ld a, [wPrinterPokedexEntryTextPointer + 1]
+ ld h, a
+ coord bc, 1, 1
+ ld a, [hFlags_0xFFFA]
+ set 3, a
+ ld [hFlags_0xFFFA], a
+ call Pokedex_PrintFlavorTextAtBC
+ ld a, [hFlags_0xFFFA]
+ res 3, a
+ ld [hFlags_0xFFFA], a
+ ret
; draws a line of tiles
; INPUT:
@@ -592,10 +699,10 @@ DrawTileLine:
push bc
push de
.loop
- ld [hl],b
- add hl,de
+ ld [hl], b
+ add hl, de
dec c
- jr nz,.loop
+ jr nz, .loop
pop de
pop bc
ret
@@ -606,19 +713,19 @@ PokedexToIndex:
; converts the Pokédex number at wd11e to an index
push bc
push hl
- ld a,[wd11e]
- ld b,a
- ld c,0
- ld hl,PokedexOrder
+ ld a, [wd11e]
+ ld b, a
+ ld c, 0
+ ld hl, PokedexOrder
.loop ; go through the list until we find an entry with a matching dex number
inc c
- ld a,[hli]
+ ld a, [hli]
cp b
- jr nz,.loop
+ jr nz, .loop
- ld a,c
- ld [wd11e],a
+ ld a, c
+ ld [wd11e], a
pop hl
pop bc
ret
@@ -627,14 +734,14 @@ IndexToPokedex:
; converts the indexédex number at wd11e to a Pokédex number
push bc
push hl
- ld a,[wd11e]
+ ld a, [wd11e]
dec a
- ld hl,PokedexOrder
- ld b,0
- ld c,a
- add hl,bc
- ld a,[hl]
- ld [wd11e],a
+ ld hl, PokedexOrder
+ ld b, 0
+ ld c, a
+ add hl, bc
+ ld a, [hl]
+ ld [wd11e], a
pop hl
pop bc
ret
diff --git a/engine/menu/prize_menu.asm b/engine/menu/prize_menu.asm
index b48fa99c..2a8dcb83 100755
--- a/engine/menu/prize_menu.asm
+++ b/engine/menu/prize_menu.asm
@@ -23,8 +23,7 @@ CeladonPrizeMenu:
ld [wTopMenuItemX],a
call PrintPrizePrice
coord hl, 0, 2
- ld b,$08
- ld c,$10
+ lb bc, 8, 16
call TextBoxBorder
call GetPrizeMenuId
call UpdateSprites
@@ -32,14 +31,14 @@ CeladonPrizeMenu:
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
+ cp $03 ; "NO,THANKS" choice
+ jr z, .noChoice
call HandlePrizeChoice
-.NoChoice
- ld hl,wd730
- res 6,[hl]
+.noChoice
+ ld hl, wd730
+ res 6, [hl]
ret
RequireCoinCaseTextPtr:
@@ -64,70 +63,70 @@ GetPrizeMenuId:
; display the three prizes' names
; (distinguishing between Pokemon names
; and Items (specifically TMs) names)
- ld a,[hSpriteIndexOrTextID]
- sub a,3 ; prize-texts' id are 3, 4 and 5
- ld [wWhichPrizeWindow],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,0
- ld e,a
- ld hl,PrizeDifferentMenuPtrs
- add hl,de
- ld a,[hli]
- ld d,[hl]
- ld e,a
+ ld d, $0
+ ld e, a
+ ld hl, PrizeDifferentMenuPtrs
+ add hl, de
+ ld a, [hli]
+ ld d, [hl]
+ ld e, a
inc hl
push hl
- ld hl,wPrize1
+ ld hl, wPrize1
call CopyString
pop hl
- ld a,[hli]
- ld h,[hl]
- ld l,a
- ld de,wPrize1Price
- ld bc,6
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld de, wPrize1Price
+ ld bc, $6
call CopyData
- ld a,[wWhichPrizeWindow]
- cp a,$02 ;is TM_menu?
- jr nz,.putMonName
- ld a,[wPrize1]
- ld [wd11e],a
+ ld a, [wWhichPrizeWindow]
+ cp $02 ;is TM_menu?
+ jr nz, .putMonName
+ ld a, [wPrize1]
+ ld [wd11e], a
call GetItemName
coord hl, 2, 4
call PlaceString
- ld a,[wPrize2]
- ld [wd11e],a
+ ld a, [wPrize2]
+ ld [wd11e], a
call GetItemName
coord hl, 2, 6
call PlaceString
- ld a,[wPrize3]
- ld [wd11e],a
+ ld a, [wPrize3]
+ ld [wd11e], a
call GetItemName
coord hl, 2, 8
call PlaceString
jr .putNoThanksText
.putMonName
- ld a,[wPrize1]
- ld [wd11e],a
+ ld a, [wPrize1]
+ ld [wd11e], a
call GetMonName
coord hl, 2, 4
call PlaceString
- ld a,[wPrize2]
- ld [wd11e],a
+ ld a, [wPrize2]
+ ld [wd11e], a
call GetMonName
coord hl, 2, 6
call PlaceString
- ld a,[wPrize3]
- ld [wd11e],a
+ ld a, [wPrize3]
+ ld [wd11e], a
call GetMonName
coord hl, 2, 8
call PlaceString
.putNoThanksText
coord hl, 2, 10
- ld de,NoThanksText
+ ld de, NoThanksText
call PlaceString
; put prices on the right side of the textbox
- ld de,wPrize1Price
+ ld de, wPrize1Price
coord hl, 13, 5
; reg. c:
; [low nybble] number of bytes
@@ -138,91 +137,93 @@ GetPrizeMenuId:
call PrintBCDNumber
ld de,wPrize2Price
coord hl, 13, 7
- ld c,(%1 << 7 | 2)
+ ld c, (1 << 7 | 2)
call PrintBCDNumber
- ld de,wPrize3Price
+ ld de, wPrize3Price
coord hl, 13, 9
- ld c,(1 << 7 | 2)
+ ld c, (1 << 7 | 2)
jp PrintBCDNumber
+NoThanksText:
+ db "NO THANKS@"
+
INCLUDE "data/prizes.asm"
PrintPrizePrice:
coord hl, 11, 0
- ld b,$01
- ld c,$07
+ lb bc, 1, 7
call TextBoxBorder
call UpdateSprites
coord hl, 12, 0
- ld de,.CoinText
+ ld de, CoinString
call PlaceString
coord hl, 13, 1
- ld de,.SixSpacesText
+ ld de, SixSpacesString
call PlaceString
coord hl, 13, 1
ld de,wPlayerCoins
- ld c,%10000010
+ ld c, (1 << 7 | 2)
call PrintBCDNumber
ret
-.CoinText
+CoinString:
db "COIN@"
-.SixSpacesText
+SixSpacesString:
db " @"
LoadCoinsToSubtract:
ld a,[wWhichPrize]
add a
- ld d,0
- ld e,a
- ld hl,wPrize1Price
- add hl,de ; get selected prize's price
+ ld d, $0
+ ld e, a
+ ld hl, wPrize1Price
+ add hl, de ; get selected prize's price
xor a
- ld [hUnusedCoinsByte],a
- ld a,[hli]
- ld [hCoins],a
- ld a,[hl]
- ld [hCoins + 1],a
+ ld [hUnusedCoinsByte], a
+ ld a, [hli]
+ ld [hCoins], a
+ ld a, [hl]
+ ld [hCoins + 1], a
ret
HandlePrizeChoice:
- ld a,[wCurrentMenuItem]
- ld [wWhichPrize],a
- ld d,0
- ld e,a
- ld hl,wPrize1
- add hl,de
- ld a,[hl]
- ld [wd11e],a
- ld a,[wWhichPrizeWindow]
- cp a,$02 ; is prize a TM?
- jr nz,.GetMonName
+ ld a, [wCurrentMenuItem]
+ ld [wWhichPrize], a
+ ld d, $0
+ ld e, a
+ ld hl, wPrize1
+ add hl, de
+ ld a, [hl]
+ ld [wd11e], a
+ ld a, [wWhichPrizeWindow]
+ cp $02 ; is prize a TM?
+ jr nz, .getMonName
call GetItemName
- jr .GivePrize
-.GetMonName
+ jr .givePrize
+.getMonName
call GetMonName
-.GivePrize
+.givePrize
ld hl,SoYouWantPrizeTextPtr
call PrintText
call YesNoChoice
- ld a,[wCurrentMenuItem] ; yes/no answer (Y=0, N=1)
+ 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,[wWhichPrizeWindow]
- 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
+ ld b, a
+ ld a, 1
+ ld c, a
call GiveItem
- jr nc,.BagFull
- jr .SubtractCoins
-.GiveMon
+ jr nc, .bagFull
+ jr .subtractCoins
+.giveMon
ld a,[wd11e]
ld [wcf91],a
push af
@@ -243,24 +244,24 @@ HandlePrizeChoice:
; were full), return without subtracting coins.
ret nc
-.SubtractCoins
+.subtractCoins
call LoadCoinsToSubtract
ld hl,hCoins + 1
ld de,wPlayerCoins + 1
ld c,$02 ; how many bytes
predef SubBCDPredef
jp PrintPrizePrice
-.BagFull
+.bagFull
ld hl,PrizeRoomBagIsFullTextPtr
jp PrintText
-.NotEnoughCoins
+.notEnoughCoins
ld hl,SorryNeedMoreCoinsText
jp PrintText
-.PrintOhFineThen
+.printOhFineThen
ld hl,OhFineThenTextPtr
jp PrintText
-UnknownData52951:
+UnknownData528b1:
; XXX what's this?
db $00,$01,$00,$01,$00,$01,$00,$00,$01
@@ -289,18 +290,18 @@ OhFineThenTextPtr:
db "@"
GetPrizeMonLevel:
- ld a,[wcf91]
- ld b,a
- ld hl,PrizeMonLevelDictionary
+ ld a, [wcf91]
+ ld b, a
+ ld hl, PrizeMonLevelDictionary
.loop
- ld a,[hli]
+ ld a, [hli]
cp b
- jr z,.matchFound
+ jr z, .matchFound
inc hl
jr .loop
.matchFound
- ld a,[hl]
- ld [wCurEnemyLVL],a
+ ld a, [hl]
+ 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 029d8c01..16a9973d 100755
--- a/engine/menu/start_menu.asm
+++ b/engine/menu/start_menu.asm
@@ -1,85 +1,84 @@
DisplayStartMenu::
- ld a,BANK(StartMenu_Pokedex)
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
- ld a,[wWalkBikeSurfState] ; walking/biking/surfing
- ld [wWalkBikeSurfStateCopy],a
- ld a, SFX_START_MENU
+ switchbank StartMenu_Pokedex ; also bank for other functions
+ ld a, [wWalkBikeSurfState] ; walking/biking/surfing
+ ld [wWalkBikeSurfStateCopy], a
+ ld a, $8f ; (SFX_02_3f - SFX_Headers_02) / 3 ; Start menu sound
call PlaySound
RedisplayStartMenu::
callba DrawStartMenu
+RedisplayStartMenu_DoNotDrawStartMenu:
callba PrintSafariZoneSteps ; print Safari Zone info, if in Safari Zone
call UpdateSprites
.loop
call HandleMenuInput
- ld b,a
+ ld b, a
.checkIfUpPressed
- bit 6,a ; was Up pressed?
- jr z,.checkIfDownPressed
- ld a,[wCurrentMenuItem] ; menu selection
+ bit 6, a ; was Up pressed?
+ jr z, .checkIfDownPressed
+ ld a, [wCurrentMenuItem] ; menu selection
and a
- jr nz,.loop
- ld a,[wLastMenuItem]
+ jr nz, .loop
+ ld a, [wLastMenuItem]
and a
- jr nz,.loop
+ jr nz, .loop
; if the player pressed tried to go past the top item, wrap around to the bottom
- CheckEvent EVENT_GOT_POKEDEX
- ld a,6 ; there are 7 menu items with the pokedex, so the max index is 6
- jr nz,.wrapMenuItemId
+ CheckEvent EVENT_GOT_POKEDEX ; does the player have the 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
.wrapMenuItemId
- ld [wCurrentMenuItem],a
+ ld [wCurrentMenuItem], a
call EraseMenuCursor
jr .loop
.checkIfDownPressed
- bit 7,a
- jr z,.buttonPressed
+ bit 7, a
+ jr z, .buttonPressed
; if the player pressed tried to go past the bottom item, wrap around to the top
- CheckEvent EVENT_GOT_POKEDEX
- ld a,[wCurrentMenuItem]
- ld c,7 ; there are 7 menu items with the pokedex
- jr nz,.checkIfPastBottom
+ CheckEvent EVENT_GOT_POKEDEX ; does the player have the pokedex?
+ ld a, [wCurrentMenuItem]
+ ld c, 7 ; there are 7 menu items with the pokedex
+ jr nz, .checkIfPastBottom
dec c ; there are only 6 menu items without the pokedex
.checkIfPastBottom
cp c
- jr nz,.loop
+ jr nz, .loop
; the player went past the bottom, so wrap to the top
xor a
- ld [wCurrentMenuItem],a
+ ld [wCurrentMenuItem], a
call EraseMenuCursor
jr .loop
.buttonPressed ; A, B, or Start button pressed
call PlaceUnfilledArrowMenuCursor
- ld a,[wCurrentMenuItem]
- ld [wBattleAndStartSavedMenuItem],a ; save current menu selection
- ld a,b
- and a,%00001010 ; was the Start button or B button pressed?
- jp nz,CloseStartMenu
+ ld a, [wCurrentMenuItem]
+ 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
- CheckEvent EVENT_GOT_POKEDEX
- ld a,[wCurrentMenuItem]
- jr nz,.displayMenuItem
+ CheckEvent EVENT_GOT_POKEDEX ; does the player have the pokedex?
+ ld a, [wCurrentMenuItem]
+ jr nz, .displayMenuItem
inc a ; adjust position to account for missing pokedex menu item
.displayMenuItem
- cp a,0
- jp z,StartMenu_Pokedex
- cp a,1
- jp z,StartMenu_Pokemon
- cp a,2
- jp z,StartMenu_Item
- cp a,3
- jp z,StartMenu_TrainerInfo
- cp a,4
- jp z,StartMenu_SaveReset
- cp a,5
- jp z,StartMenu_Option
+ cp a, 0
+ jp z, StartMenu_Pokedex
+ cp a, 1
+ jp z, StartMenu_Pokemon
+ cp a, 2
+ jp z, StartMenu_Item
+ cp a, 3
+ jp z, StartMenu_TrainerInfo
+ cp a, 4
+ jp z, StartMenu_SaveReset
+ cp a, 5
+ jp z, StartMenu_Option
; EXIT falls through to here
CloseStartMenu::
call Joypad
- ld a,[hJoyPressed]
- bit 0,a ; was A button newly pressed?
- jr nz,CloseStartMenu
+ ld a, [hJoyPressed]
+ bit 0, a ; was A button newly pressed?
+ jr nz, CloseStartMenu
call LoadTextBoxTilePatterns
jp CloseTextDisplay
diff --git a/engine/menu/start_sub_menus.asm b/engine/menu/start_sub_menus.asm
index 9ae6cbe5..fc553d93 100755
--- a/engine/menu/start_sub_menus.asm
+++ b/engine/menu/start_sub_menus.asm
@@ -34,7 +34,7 @@ StartMenu_Pokemon:
ld [wTextBoxID],a
call DisplayTextBoxID ; display pokemon menu options
ld hl,wFieldMoves
- lb bc, $02, $0c ; max menu item ID, top menu item Y
+ lb bc, 2, 12 ; max menu item ID, top menu item Y
ld e,5
.adjustMenuVariablesLoop
dec e
@@ -129,7 +129,7 @@ StartMenu_Pokemon:
dw .dig
dw .teleport
dw .softboiled
-.fly
+.fly ; 11d1b (4:5d1b)
bit 2,a ; does the player have the Thunder Badge?
jp z,.newBadgeRequired
call CheckIfInOutsideMap
@@ -144,12 +144,15 @@ StartMenu_Pokemon:
call ChooseFlyDestination
ld a,[wd732]
bit 3,a ; did the player decide to fly?
- jp nz,.goBackToMap
+ jr nz,.asm_5d4c
call LoadFontTilePatterns
ld hl,wd72e
set 1,[hl]
jp StartMenu_Pokemon
-.cut
+.asm_5d4c
+ call Func_1510
+ jp .goBackToMap
+.cut ; 11d52 (4:5d52)
bit 1,a ; does the player have the Cascade Badge?
jp z,.newBadgeRequired
predef UsedCut
@@ -157,7 +160,7 @@ StartMenu_Pokemon:
and a
jp z,.loop
jp CloseTextDisplay
-.surf
+.surf ; 11d66 (4:5d66)
bit 4,a ; does the player have the Soul Badge?
jp z,.newBadgeRequired
callba IsSurfingAllowed
@@ -165,22 +168,35 @@ StartMenu_Pokemon:
bit 1,[hl]
res 1,[hl]
jp z,.loop
+ ld a, [wcf91]
+ cp PIKACHU ; is this surfing pikachu?
+ jr z, .surfingPikachu
+ ld a, $1
+ jr .continue
+.surfingPikachu
+ ld a, $2
+.continue
+ ld [wd473], a
ld a,SURFBOARD
ld [wcf91],a
ld [wPseudoItemID],a
call UseItem
ld a,[wActionResultOrTookBattleTurn]
and a
- jp z,.loop
+ jr z,.reloadNormalSprite
call GBPalWhiteOutWithDelay3
jp .goBackToMap
-.strength
+.reloadNormalSprite
+ xor a
+ ld [wd473], a
+ jp .loop
+.strength ; 11dab (4:5dab)
bit 3,a ; does the player have the Rainbow Badge?
jp z,.newBadgeRequired
predef PrintStrengthTxt
call GBPalWhiteOutWithDelay3
jp .goBackToMap
-.flash
+.flash ; 11dbb (4:5dbb)
bit 0,a ; does the player have the Boulder Badge?
jp z,.newBadgeRequired
xor a
@@ -192,7 +208,7 @@ StartMenu_Pokemon:
.flashLightsAreaText
TX_FAR _FlashLightsAreaText
db "@"
-.dig
+.dig ; 11dd5 (4:5dd5)
ld a,ESCAPE_ROPE
ld [wcf91],a
ld [wPseudoItemID],a
@@ -202,7 +218,7 @@ StartMenu_Pokemon:
jp z,.loop
call GBPalWhiteOutWithDelay3
jp .goBackToMap
-.teleport
+.teleport ; 11ded (4:5ded)
call CheckIfInOutsideMap
jr z,.canTeleport
ld a,[wWhichPokemon]
@@ -217,12 +233,13 @@ StartMenu_Pokemon:
ld hl,wd732
set 3,[hl]
set 6,[hl]
+ call Func_1510
ld hl,wd72e
set 1,[hl]
res 4,[hl]
ld c,60
call DelayFrames
- call GBPalWhiteOutWithDelay3 ; zero all three palettes and wait 3 V-blanks
+ call GBPalWhiteOutWithDelay3 ; zero all three palettes and wait 3 frames
jp .goBackToMap
.warpToLastPokemonCenterText
TX_FAR _WarpToLastPokemonCenterText
@@ -233,7 +250,7 @@ StartMenu_Pokemon:
.cannotFlyHereText
TX_FAR _CannotFlyHereText
db "@"
-.softboiled
+.softboiled ; 11e35 (4:5e35)
ld hl,wPartyMon1MaxHP
ld a,[wWhichPokemon]
ld bc,wPartyMon2 - wPartyMon1
@@ -307,11 +324,10 @@ StartMenu_Item:
call PrintText
jr .exitMenu
.notInCableClubRoom
- ld bc,wNumBagItems
ld hl,wListPointer
- ld a,c
- ld [hli],a
- ld [hl],b ; store item bag pointer in wListPointer (for DisplayListMenuID)
+ ld [hl], wNumBagItems & $ff
+ inc hl
+ ld [hl], wNumBagItems / $100 ; store item bag pointer in wListPointer (for DisplayListMenuID)
xor a
ld [wPrintItemPrices],a
ld a,ITEMLISTMENU
@@ -515,10 +531,11 @@ StartMenu_TrainerInfo:
call LoadScreenTilesFromBuffer2 ; restore saved screen
call RunDefaultPaletteCommand
call ReloadMapData
+ callba DrawStartMenu ; XXX what difference does this make?
call LoadGBPal
pop af
ld [hTilesetType],a
- jp RedisplayStartMenu
+ jp RedisplayStartMenu_DoNotDrawStartMenu
; loads tile patterns and draws everything except for gym leader faces / badges
DrawTrainerInfo:
@@ -552,7 +569,7 @@ DrawTrainerInfo:
ld de,vChars2 + $200
ld bc,$0400
ld a,$03
- call FarCopyData2
+ call FarCopyData
ld hl,TextBoxGraphics
ld de,$00d0
add hl,de ; hl = colon tile pattern
@@ -560,7 +577,7 @@ DrawTrainerInfo:
ld bc,$0010
ld a,$04
push bc
- call FarCopyData2
+ call FarCopyData
pop bc
ld hl,TrainerInfoTextBoxTileGraphics + $80 ; background tile pattern
ld de,vChars1 + $570
@@ -612,7 +629,7 @@ DrawTrainerInfo:
TrainerInfo_FarCopyData:
ld a,BANK(TrainerInfoTextBoxTileGraphics)
- jp FarCopyData2
+ jp FarCopyData
TrainerInfo_NameMoneyTimeText:
db "NAME/"
diff --git a/engine/menu/status_screen.asm b/engine/menu/status_screen.asm
index 4770483d..932d206a 100755
--- a/engine/menu/status_screen.asm
+++ b/engine/menu/status_screen.asm
@@ -40,7 +40,7 @@ DrawHP_:
push hl
call DrawHPBar
pop hl
- ld a, [hFlags_0xFFF6]
+ ld a, [hFlags_0xFFFA]
bit 0, a
jr z, .printFractionBelowBar
ld bc, $9 ; right of bar
@@ -170,8 +170,25 @@ StatusScreen:
call GBPalNormal
coord hl, 1, 0
call LoadFlippedFrontSpriteByMonIndex ; draw Pokémon picture
+ ld a, [wMonDataLocation]
+ cp ENEMY_PARTY_DATA
+ jr z, .playRegularCry
+ cp BOX_DATA
+ jr z, .checkBoxData
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .playRegularCry
+ jr .playPikachuSoundClip
+.checkBoxData
+ callab IsThisPartymonStarterPikachu_Box
+ jr nc, .playRegularCry
+.playPikachuSoundClip
+ ld e, 16
+ callab PlayPikachuSoundClip
+ jr .continue
+.playRegularCry
ld a, [wcf91]
call PlayCry ; play Pokémon cry
+.continue
call WaitForTextScrollButtonPress ; wait for button
pop af
ld [hTilesetType], a
@@ -223,7 +240,7 @@ OKText:
db "OK@"
; Draws a line starting from hl high b and wide c
-DrawLineBox: ; 0x12ac7
+DrawLineBox:
ld de, SCREEN_WIDTH ; New line
.PrintVerticalLine
ld [hl], $78 ; │
@@ -240,7 +257,7 @@ DrawLineBox: ; 0x12ac7
ld [hl], $6f ; ← (halfarrow ending)
ret
-PTile: ; 12adc (4:6adc) ; This is a single 1bpp "P" tile
+PTile: ; 11682 (4:5682) ; This is a single 1bpp "P" tile
INCBIN "gfx/p_tile.1bpp"
PTileEnd:
@@ -249,16 +266,14 @@ PrintStatsBox:
and a ; a is 0 from the status screen
jr nz, .DifferentBox
coord hl, 0, 8
- ld b, $8
- ld c, $8
+ lb bc, 8, 8
call TextBoxBorder ; Draws the box
coord hl, 1, 9 ; Start printing stats from here
ld bc, $0019 ; Number offset
jr .PrintStats
.DifferentBox
coord hl, 9, 2
- ld b, $8
- ld c, $9
+ lb bc, 8, 9
call TextBoxBorder
coord hl, 11, 3
ld bc, $0018
@@ -279,7 +294,7 @@ PrintStatsBox:
call PrintStat
ld de, wLoadedMonSpecial
jp PrintNumber
-PrintStat
+PrintStat:
push hl
call PrintNumber
pop hl
@@ -313,8 +328,7 @@ StatusScreen2:
coord hl, 19, 3
ld [hl], $78
coord hl, 0, 8
- ld b, 8
- ld c, 18
+ lb bc, 8, 18
call TextBoxBorder ; Draw move container
coord hl, 2, 9
ld de, wMovesString
@@ -335,11 +349,11 @@ StatusScreen2:
ld c, a
ld a, "-"
call StatusScreen_PrintPP ; Fill the rest with --
-.InitPP ; 12bbb
+.InitPP ; 1175e
ld hl, wLoadedMonMoves
coord de, 14, 10
ld b, 0
-.PrintPP ; 12bc3
+.PrintPP ; 11766
ld a, [hli]
and a
jr z, .PPDone
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_ids1.asm b/engine/menu/text_ids1.asm
new file mode 100644
index 00000000..e2fd76f4
--- /dev/null
+++ b/engine/menu/text_ids1.asm
@@ -0,0 +1,163 @@
+; 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
+ lb bc, 14, 8
+ jr nz,.drawTextBoxBorder
+; start menu without pokedex
+ coord hl, 10, 0
+ lb bc, 12, 8
+ 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
+ lb bc, 4, 18
+.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,vBGMap1 / $100 ; 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
+
+; function that displays the start menu
+DrawStartMenu:
+ CheckEvent EVENT_GOT_POKEDEX
+; menu with pokedex
+ coord hl, 10, 0
+ lb bc, 14, 8
+ jr nz,.drawTextBoxBorder
+; shorter menu if the player doesn't have the pokedex
+ coord hl, 10, 0
+ lb bc, 12, 8
+.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 "#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/text_ids2.asm b/engine/menu/text_ids2.asm
new file mode 100644
index 00000000..fbac3986
--- /dev/null
+++ b/engine/menu/text_ids2.asm
@@ -0,0 +1,733 @@
+; 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
+ lb bc, 1, 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
+ xor a
+ ld [wTwoOptionMenuID], a
+ ld hl, wd730
+ res 6, [hl]
+ 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 ; 7542 (1:7542)
+ db "NO",$4E,"YES@"
+.YesNoMenu ; 7549 (1:7549)
+ db "YES",$4E,"NO@"
+.NorthWestMenu ; 7550 (1:7550)
+ db "NORTH",$4E,"WEST@"
+.SouthEastMenu ; 755b (1:755b)
+ db "SOUTH",$4E,"EAST@"
+.NorthEastMenu ; 7566 (1:7566)
+ db "NORTH",$4E,"EAST@"
+.TradeCancelMenu ; 7571 (1:7571)
+ db "TRADE",$4E,"CANCEL@"
+.HealCancelMenu ; 757e (1:757e)
+ db "HEAL",$4E,"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
+ lb bc, 5, 7
+ call TextBoxBorder
+ call UpdateSprites
+ ld a, 12
+ ld [hFieldMoveMonMenuTopMenuItemX], a ; fffb, not fff7
+ 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 b32568f9..d864141d 100755
--- a/engine/menu/vending_machine.asm
+++ b/engine/menu/vending_machine.asm
@@ -18,8 +18,7 @@ VendingMachineMenu:
ld hl, wd730
set 6, [hl]
coord hl, 0, 3
- ld b, 8
- ld c, 12
+ lb bc, 8, 12
call TextBoxBorder
call UpdateSprites
coord hl, 2, 5
@@ -130,6 +129,9 @@ LoadVendingMachineItem:
ret
VendingPrices:
- db FRESH_WATER,$00,$02,$00
- db SODA_POP, $00,$03,$00
- db LEMONADE, $00,$03,$50
+ 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 6845b790..2e588aa4 100755
--- a/engine/mon_party_sprites.asm
+++ b/engine/mon_party_sprites.asm
@@ -91,7 +91,7 @@ PartyMonSpeeds:
LoadMonPartySpriteGfx:
; Load mon party sprite tile patterns into VRAM during V-blank.
ld hl, MonPartySpritePointers
- ld a, $1c
+ ld a, $1e
LoadAnimSpriteGfx:
; Load animated sprite tile patterns into VRAM during V-blank. hl is the address
@@ -130,9 +130,9 @@ LoadMonPartySpriteGfxWithLCDDisabled:
; LCD.
call DisableLCD
ld hl, MonPartySpritePointers
- ld a, $1c
+ ld a, $1e
ld bc, $0
-.asm_7179c
+.loop
push af
push bc
push hl
@@ -151,7 +151,7 @@ LoadMonPartySpriteGfxWithLCDDisabled:
inc hl
ld d, [hl]
pop hl
- call FarCopyData2
+ call FarCopyData
pop hl
pop bc
ld a, $6
@@ -159,7 +159,7 @@ LoadMonPartySpriteGfxWithLCDDisabled:
ld c, a
pop af
dec a
- jr nz, .asm_7179c
+ jr nz, .loop
jp EnableLCD
MonPartySpritePointers:
@@ -228,6 +228,11 @@ MonPartySpritePointers:
db BANK(MonPartySprites)
dw vSprites + $260
+ dw PikachuSprite
+ db $40 / $10 ; $40 bytes
+ db BANK(PikachuSprite)
+ dw vSprites + $280
+
dw MonPartySprites + $100
db $40 / $10 ; $40 bytes
db BANK(MonPartySprites)
@@ -298,6 +303,11 @@ MonPartySpritePointers:
db BANK(MonPartySprites)
dw vSprites + $660
+ dw PikachuSprite + $C0
+ db $40 / $10 ; $40 bytes
+ db BANK(PikachuSprite)
+ dw vSprites + $680
+
dw MonPartySprites + $140
db $40 / $10 ; $40 bytes
db BANK(MonPartySprites)
@@ -309,6 +319,8 @@ WriteMonPartySpriteOAMByPartyIndex:
push de
push bc
ld a, [hPartyMonIndex]
+ cp $ff
+ jr z, .asm_7191f
ld hl, wPartySpecies
ld e, a
ld d, 0
@@ -322,6 +334,16 @@ WriteMonPartySpriteOAMByPartyIndex:
pop hl
ret
+.asm_7191f
+ ld hl, wOAMBuffer
+ ld de, wMonPartySpritesSavedOAM
+ ld bc, $60
+ call CopyData
+ pop bc
+ pop de
+ pop hl
+ ret
+
WriteMonPartySpriteOAMBySpecies:
; Write OAM blocks for the party sprite of the species in
; [wMonPartySpriteSpecies].
@@ -343,14 +365,14 @@ UnusedPartyMonSpriteFunction:
ld hl, vSprites
call .LoadTilePatterns
pop af
- add $54
+ add $5A
ld hl, vSprites + $40
call .LoadTilePatterns
xor a
ld [wMonPartySpriteSpecies], a
jr WriteMonPartySpriteOAMBySpecies
-.LoadTilePatterns ; 718ac (1c:58ac)
+.LoadTilePatterns ; 71959 (1c:5959)
push hl
add a
ld c, a
diff --git a/engine/move_mon.asm b/engine/move_mon.asm
new file mode 100644
index 00000000..3471875e
--- /dev/null
+++ b/engine/move_mon.asm
@@ -0,0 +1,172 @@
+_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_f3fb
+ ld hl, wNumInBox
+ ld a, [hl]
+ cp MONS_PER_BOX
+ jr nz, .partyOrBoxNotFull
+ jr .boxFull
+.checkPartyMonSlots
+ ld hl, wPartyCount
+ ld a, [hl]
+ cp PARTY_LENGTH
+ jr nz, .partyOrBoxNotFull
+.boxFull
+ scf
+ ret
+.partyOrBoxNotFull
+ inc a
+ ld [hl], a ; increment number of mons in party/box
+ ld c, a
+ ld b, 0
+ add hl, bc
+ ld a, [wMoveMonType]
+ cp DAYCARE_TO_PARTY
+ ld a, [wDayCareMon]
+ jr z, .asm_f3dc
+ ld a, [wcf91]
+.asm_f3dc
+ ld [hli], a ; write new mon ID
+ ld [hl], $ff ; write new sentinel
+ ld a, [wMoveMonType]
+ dec a
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1 ; $2c
+ ld a, [wPartyCount]
+ jr nz, .skipToNewMonEntry
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1 ; $21
+ ld a, [wNumInBox]
+.skipToNewMonEntry
+ dec a
+ call AddNTimes
+.asm_f3fb
+ push hl
+ ld e, l
+ ld d, h
+ ld a, [wMoveMonType]
+ and a
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1 ; $21
+ jr z, .asm_f417
+ cp DAYCARE_TO_PARTY
+ ld hl, wDayCareMon
+ jr z, .asm_f41d
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1 ; $2c
+.asm_f417
+ ld a, [wWhichPokemon]
+ call AddNTimes
+.asm_f41d
+ push hl
+ push de
+ ld bc, wBoxMon2 - wBoxMon1
+ call CopyData
+ pop de
+ pop hl
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f43a
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f43a
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc
+ ld a, [hl]
+ inc de
+ inc de
+ inc de
+ ld [de], a
+.asm_f43a
+ ld a, [wMoveMonType]
+ cp PARTY_TO_DAYCARE
+ ld de, wDayCareMonOT
+ jr z, .asm_f459
+ dec a
+ ld hl, wPartyMonOT
+ ld a, [wPartyCount]
+ jr nz, .asm_f453
+ ld hl, wBoxMonOT
+ ld a, [wNumInBox]
+.asm_f453
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+.asm_f459
+ ld hl, wBoxMonOT
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f46c
+ ld hl, wDayCareMonOT
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f472
+ ld hl, wPartyMonOT
+.asm_f46c
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+.asm_f472
+ ld bc, NAME_LENGTH
+ call CopyData
+ ld a, [wMoveMonType]
+ cp PARTY_TO_DAYCARE
+ ld de, wDayCareMonName
+ jr z, .asm_f497
+ dec a
+ ld hl, wPartyMonNicks
+ ld a, [wPartyCount]
+ jr nz, .asm_f491
+ ld hl, wBoxMonNicks
+ ld a, [wNumInBox]
+.asm_f491
+ dec a
+ call SkipFixedLengthTextEntries
+ ld d, h
+ ld e, l
+.asm_f497
+ ld hl, wBoxMonNicks
+ ld a, [wMoveMonType]
+ and a
+ jr z, .asm_f4aa
+ ld hl, wDayCareMonName
+ cp DAYCARE_TO_PARTY
+ jr z, .asm_f4b0
+ ld hl, wPartyMonNicks
+.asm_f4aa
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+.asm_f4b0
+ ld bc, NAME_LENGTH
+ call CopyData
+ pop hl
+ ld a, [wMoveMonType]
+ cp PARTY_TO_BOX
+ jr z, .asm_f4ea
+ cp PARTY_TO_DAYCARE
+ jr z, .asm_f4ea
+ push hl
+ srl a
+ add $2
+ ld [wMonDataLocation], a
+ call LoadMonData
+ callba CalcLevelFromExperience
+ ld a, d
+ ld [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_f4ea
+ and a
+ ret
diff --git a/engine/multiply_divide.asm b/engine/multiply_divide.asm
index 52e86b36..2bc26de2 100755
--- a/engine/multiply_divide.asm
+++ b/engine/multiply_divide.asm
@@ -2,16 +2,17 @@ _Multiply:
ld a, $8
ld b, a
xor a
- 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]
+ ld [H_PRODUCT], a ; $ff95
+ ld [H_MULTIPLYBUFFER], a ; $ff9b
+ ld [H_MULTIPLYBUFFER+1], a ; $ff9c
+ ld [H_MULTIPLYBUFFER+2], a ; $ff9d
+ ld [H_MULTIPLYBUFFER+3], a ; $ff9e
+.multiplyLoop
+ ld a, [H_MULTIPLIER] ; $ff99
srl a
- ld [H_MULTIPLIER], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
- jr nc, .smallMultiplier
+ ld [H_MULTIPLIER], a ; $ff99
+ jr nc, .smallMultiplier ; less than $80
+; code to possibly multiply the multiplicand by 2 and divide the multiplier by 2?
ld a, [H_MULTIPLYBUFFER+3]
ld c, a
ld a, [H_MULTIPLICAND+2]
@@ -22,14 +23,14 @@ _Multiply:
ld a, [H_MULTIPLICAND+1]
adc c
ld [H_MULTIPLYBUFFER+2], a
- ld a, [H_MULTIPLYBUFFER+1]
+ ld a, [H_MULTIPLYBUFFER+1] ; $ff9c
ld c, a
- ld a, [H_MULTIPLICAND] ; (aliases: H_MULTIPLICAND)
+ ld a, [H_MULTIPLICAND] ; $ff96
adc c
- ld [H_MULTIPLYBUFFER+1], a
+ ld [H_MULTIPLYBUFFER+1], a ; $ff9c
ld a, [H_MULTIPLYBUFFER]
ld c, a
- ld a, [H_PRODUCT] ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [H_PRODUCT] ; $ff95
adc c
ld [H_MULTIPLYBUFFER], a
.smallMultiplier
@@ -41,103 +42,103 @@ _Multiply:
ld a, [H_MULTIPLICAND+1]
rl a
ld [H_MULTIPLICAND+1], a
- ld a, [H_MULTIPLICAND]
+ ld a, [H_MULTIPLICAND] ; $ff96
rl a
- ld [H_MULTIPLICAND], a
- ld a, [H_PRODUCT]
+ ld [H_MULTIPLICAND], a ; $ff96
+ ld a, [H_PRODUCT] ; $ff95
rl a
- ld [H_PRODUCT], a
- jr .loop
+ ld [H_PRODUCT], a ; $ff95
+ jr .multiplyLoop
.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+1] ; $ff9c
+ ld [H_PRODUCT+1], a ; $ff96
ld a, [H_MULTIPLYBUFFER]
- ld [H_PRODUCT], a
+ ld [H_PRODUCT], a ; $ff95
ret
_Divide:
xor 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 [H_DIVIDEBUFFER], a ; ff9a
+ ld [H_DIVIDEBUFFER+1], a ; ff9b
+ ld [H_DIVIDEBUFFER+2], a ; ff9c
+ ld [H_DIVIDEBUFFER+3], a ; ff9d
+ ld [H_DIVIDEBUFFER+4], a ; ff9e
ld a, $9
ld e, a
-.asm_37db3
+.asm_f6680
ld a, [H_DIVIDEBUFFER]
ld c, a
- ld a, [H_DIVIDEND+1] ; (aliases: H_MULTIPLICAND)
+ ld a, [H_DIVIDEND+1] ; $ff96
sub c
ld d, a
- ld a, [H_DIVISOR] ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld a, [H_DIVISOR] ; $ff99
ld c, a
- ld a, [H_DIVIDEND] ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld a, [H_DIVIDEND] ; $ff95
sbc c
- jr c, .asm_37dce
- ld [H_DIVIDEND], a ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ jr c, .asm_f669b
+ ld [H_DIVIDEND], a ; $ff95
ld a, d
- ld [H_DIVIDEND+1], a ; (aliases: H_MULTIPLICAND)
+ ld [H_DIVIDEND+1], a ; $ff96
ld a, [H_DIVIDEBUFFER+4]
inc a
ld [H_DIVIDEBUFFER+4], a
- jr .asm_37db3
-.asm_37dce
+ jr .asm_f6680
+.asm_f669b
ld a, b
cp $1
- jr z, .asm_37e18
+ jr z, .done
ld a, [H_DIVIDEBUFFER+4]
sla a
ld [H_DIVIDEBUFFER+4], a
ld a, [H_DIVIDEBUFFER+3]
rl a
ld [H_DIVIDEBUFFER+3], a
- ld a, [H_DIVIDEBUFFER+2]
+ ld a, [H_DIVIDEBUFFER+2] ; $ff9c
rl a
- ld [H_DIVIDEBUFFER+2], a
+ ld [H_DIVIDEBUFFER+2], a ; $ff9c
ld a, [H_DIVIDEBUFFER+1]
rl a
ld [H_DIVIDEBUFFER+1], a
dec e
- jr nz, .asm_37e04
+ jr nz, .asm_f66d1
ld a, $8
ld e, a
ld a, [H_DIVIDEBUFFER]
- ld [H_DIVISOR], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld [H_DIVISOR], a ; $ff99
xor 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+1] ; $ff96
+ ld [H_DIVIDEND], a ; $ff95
ld a, [H_DIVIDEND+2]
- ld [H_DIVIDEND+1], a ; (aliases: H_MULTIPLICAND)
+ ld [H_DIVIDEND+1], a ; $ff96
ld a, [H_DIVIDEND+3]
ld [H_DIVIDEND+2], a
-.asm_37e04
+.asm_f66d1
ld a, e
cp $1
- jr nz, .asm_37e0a
+ jr nz, .asm_f66d7
dec b
-.asm_37e0a
- ld a, [H_DIVISOR] ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+.asm_f66d7
+ ld a, [H_DIVISOR] ; $ff99
srl a
- ld [H_DIVISOR], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ ld [H_DIVISOR], a ; $ff99
ld a, [H_DIVIDEBUFFER]
rr a
ld [H_DIVIDEBUFFER], a
- jr .asm_37db3
-.asm_37e18
- ld a, [H_DIVIDEND+1] ; (aliases: H_MULTIPLICAND)
- ld [H_REMAINDER], a ; (aliases: H_DIVISOR, H_MULTIPLIER, H_POWEROFTEN)
+ jr .asm_f6680
+.done
+ ld a, [H_DIVIDEND+1] ; $ff96
+ ld [H_REMAINDER], a ; $ff99
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+2] ; $ff9c
+ ld [H_QUOTIENT+1], a ; $ff96
ld a, [H_DIVIDEBUFFER+1]
- ld [H_DIVIDEND], a ; (aliases: H_PRODUCT, H_PASTLEADINGZEROES, H_QUOTIENT)
+ ld [H_QUOTIENT], a ; $ff95
ret
diff --git a/engine/oak_speech.asm b/engine/oak_speech.asm
index 31c00fd0..38fe66f9 100755
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -5,14 +5,22 @@ SetDefaultNames:
push af
ld a, [wd732]
push af
+ ld a, [wPrinterSettings]
+ push af
ld hl, wPlayerName
- ld bc, $d8a
+ ld bc, wBoxDataEnd - wPlayerName
xor a
call FillMemory
ld hl, wSpriteStateData1
ld bc, $200
xor a
call FillMemory
+ xor a
+ ld [wSurfingMinigameHiScore], a
+ ld [wSurfingMinigameHiScore + 1], a
+ ld [wSurfingMinigameHiScore + 2], a
+ pop af
+ ld [wPrinterSettings], a
pop af
ld [wd732], a
pop af
@@ -29,11 +37,11 @@ SetDefaultNames:
ld hl, SonyText
ld de, wRivalName
ld bc, NAME_LENGTH
- jp CopyData
+ call CopyData ; rip optimizations
+ ret
OakSpeech:
- ld a,$FF
- call PlaySound ; stop music
+ call StopAllMusic ; stop music
ld a, BANK(Music_Routes2)
ld c,a
ld a, MUSIC_ROUTES2
@@ -64,7 +72,7 @@ OakSpeech:
call PrintText
call GBFadeOutToWhite
call ClearScreen
- ld a,NIDORINO
+ ld a,PIKACHU
ld [wd0b5],a
ld [wcf91],a
call GetMonHeader
@@ -109,13 +117,13 @@ OakSpeech:
ld a,SFX_SHRINK
call PlaySound
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ call BankswitchCommon
ld c,4
call DelayFrames
- ld de,RedSprite
ld hl,vSprites
- lb bc, BANK(RedSprite), $0C
+ ld de,RedSprite
+ ld b, BANK(RedSprite)
+ ld c, $0C
call CopyVideoData
ld de,ShrinkPic1
lb bc, BANK(ShrinkPic1), $00
@@ -133,17 +141,13 @@ OakSpeech:
ld [wAudioSavedROMBank],a
ld a, 10
ld [wAudioFadeOutControl],a
- ld a,$FF
- ld [wNewSoundID],a
- call PlaySound ; stop music
+ call StopAllMusic ; stop music
pop af
- ld [H_LOADEDROMBANK],a
- ld [MBC1RomBank],a
+ call BankswitchCommon
ld c,20
call DelayFrames
coord hl, 6, 5
- ld b,7
- ld c,7
+ lb bc, 7, 7
call ClearScreenArea
call LoadTextBoxTilePatterns
ld a,1
@@ -151,7 +155,9 @@ OakSpeech:
ld c,50
call DelayFrames
call GBFadeOutToWhite
- jp ClearScreen
+ call ClearScreen ; rip more tail-end optimizations
+ ret
+
OakSpeechText1:
TX_FAR _OakSpeechText1
db "@"
@@ -176,6 +182,7 @@ FadeInIntroPic:
.next
ld a,[hli]
ld [rBGP],a
+ call UpdateGBCPal_BGP
ld c,10
call DelayFrames
dec b
@@ -195,8 +202,9 @@ MovePicLeft:
ld [rWX],a
call DelayFrame
- ld a,$E4
+ ld a,%11100100
ld [rBGP],a
+ call UpdateGBCPal_BGP
.next
call DelayFrame
ld a,[rWX]
@@ -215,10 +223,13 @@ IntroDisplayPicCenteredOrUpperRight:
push bc
ld a,b
call UncompressSpriteFromDE
+ ld a, $0
+ call SwitchSRAMBankAndLatchClockData
ld hl,sSpriteBuffer1
ld de,sSpriteBuffer0
ld bc,$310
call CopyData
+ call PrepareRTCDataAndDisableSRAM
ld de,vFrontPic
call InterlaceMergeSpriteBuffers
pop bc
diff --git a/engine/oak_speech2.asm b/engine/oak_speech2.asm
index 1ae06313..122803fa 100755
--- a/engine/oak_speech2.asm
+++ b/engine/oak_speech2.asm
@@ -108,6 +108,7 @@ OakSpeechSlidePicCommon:
.loop
xor a
ld [H_AUTOBGTRANSFERENABLED], a
+ ld [H_AUTOBGTRANSFERPORTION], a
ld a, [hSlideDirection]
and a
jr nz, .slideLeft
@@ -129,8 +130,8 @@ OakSpeechSlidePicCommon:
; 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
+ xor a
ld [hl], a
.next3
ld a, 1
@@ -162,8 +163,7 @@ OakSpeechSlidePicCommon:
DisplayIntroNameTextBox:
push de
coord hl, 0, 0
- ld b, $a
- ld c, $9
+ lb bc, 10, 9
call TextBoxBorder
coord hl, 3, 0
ld de, .namestring
@@ -184,13 +184,12 @@ DisplayIntroNameTextBox:
ld [wMaxMenuItem], a
jp HandleMenuInput
-.namestring ; 6aa3 (1:6aa3)
+.namestring ; 6822 (1:6822)
db "NAME@"
-IF DEF(_RED)
DefaultNamesPlayer:
db "NEW NAME"
- next "RED"
+ next "YELLOW"
next "ASH"
next "JACK"
db "@"
@@ -201,23 +200,6 @@ DefaultNamesRival:
next "GARY"
next "JOHN"
db "@"
-ENDC
-
-IF DEF(_BLUE)
-DefaultNamesPlayer:
- db "NEW NAME"
- next "BLUE"
- next "GARY"
- next "JOHN"
- db "@"
-
-DefaultNamesRival:
- db "NEW NAME"
- next "RED"
- next "ASH"
- next "JACK"
- db "@"
-ENDC
GetDefaultName:
; a = name index
@@ -243,30 +225,17 @@ GetDefaultName:
ld bc, $14
jp CopyData
-IF DEF(_RED)
DefaultNamesPlayerList:
db "NEW NAME@"
- db "RED@"
+ db "YELLOW@"
db "ASH@"
db "JACK@"
+
DefaultNamesRivalList:
db "NEW NAME@"
db "BLUE@"
db "GARY@"
db "JOHN@"
-ENDC
-IF DEF(_BLUE)
-DefaultNamesPlayerList:
- db "NEW NAME@"
- db "BLUE@"
- db "GARY@"
- db "JOHN@"
-DefaultNamesRivalList:
- db "NEW NAME@"
- db "RED@"
- db "ASH@"
- db "JACK@"
-ENDC
TextTerminator_6b20:
db "@"
diff --git a/engine/overworld/advance_player_sprite.asm b/engine/overworld/advance_player_sprite.asm
new file mode 100644
index 00000000..6b4a0cbb
--- /dev/null
+++ b/engine/overworld/advance_player_sprite.asm
@@ -0,0 +1,241 @@
+_AdvancePlayerSprite::
+ ld a,[wSpriteStateData1 + 3] ; delta Y
+ ld b,a
+ ld a,[wSpriteStateData1 + 5] ; delta X
+ ld c,a
+ ld hl,wWalkCounter ; walking animation counter
+ dec [hl]
+ jr nz,.afterUpdateMapCoords
+; if it's the end of the animation, update the player's map coordinates
+ ld hl, wPikachuOverworldStateFlags
+ res 5, [hl]
+ ld a,[wYCoord]
+ add b
+ ld [wYCoord],a
+ ld a,[wXCoord]
+ add c
+ ld [wXCoord],a
+.afterUpdateMapCoords
+ ld a,[wWalkCounter] ; walking animation counter
+ cp a,$07
+ jp nz,.scrollBackgroundAndSprites
+; if this is the first iteration of the animation
+ ld a,c
+ cp a,$01
+ jr nz,.checkIfMovingWest
+; moving east
+ ld a,[wMapViewVRAMPointer]
+ ld e,a
+ and $e0
+ ld d,a
+ ld a,e
+ add $02
+ and $1f
+ or d
+ ld [wMapViewVRAMPointer],a
+ jr .adjustXCoordWithinBlock
+.checkIfMovingWest
+ cp a,$ff
+ jr nz,.checkIfMovingSouth
+; moving west
+ ld a,[wMapViewVRAMPointer]
+ ld e,a
+ and a,$e0
+ ld d,a
+ ld a,e
+ sub $02
+ and $1f
+ or d
+ ld [wMapViewVRAMPointer],a
+ jr .adjustXCoordWithinBlock
+.checkIfMovingSouth
+ ld a,b
+ cp a,$01
+ jr nz,.checkIfMovingNorth
+; moving south
+ ld a,[wMapViewVRAMPointer]
+ add $40
+ ld [wMapViewVRAMPointer],a
+ jr nc,.adjustXCoordWithinBlock
+ ld a,[wMapViewVRAMPointer + 1]
+ inc a
+ and $03
+ or $98
+ ld [wMapViewVRAMPointer + 1],a
+ jr .adjustXCoordWithinBlock
+.checkIfMovingNorth
+ cp a,$ff
+ jr nz,.adjustXCoordWithinBlock
+; moving north
+ ld a,[wMapViewVRAMPointer]
+ sub $40
+ ld [wMapViewVRAMPointer],a
+ jr nc,.adjustXCoordWithinBlock
+ ld a,[wMapViewVRAMPointer + 1]
+ dec a
+ and $03
+ or $98
+ ld [wMapViewVRAMPointer + 1],a
+.adjustXCoordWithinBlock
+ ld a,c
+ and a
+ jr z,.pointlessJump ; mistake?
+.pointlessJump
+ ld hl,wXBlockCoord
+ ld a,[hl]
+ add c
+ ld [hl],a
+ cp $02
+ jr nz,.checkForMoveToWestBlock
+; moved into the tile block to the east
+ xor a
+ ld [hl],a
+ ld hl,wXOffsetSinceLastSpecialWarp
+ inc [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ call MoveTileBlockMapPointerEast
+ jr .updateMapView
+.checkForMoveToWestBlock
+ cp a,$ff
+ jr nz,.adjustYCoordWithinBlock
+; moved into the tile block to the west
+ ld a,$1
+ ld [hl],a
+ ld hl,wXOffsetSinceLastSpecialWarp
+ dec [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ call MoveTileBlockMapPointerWest
+ jr .updateMapView
+.adjustYCoordWithinBlock
+ ld hl,wYBlockCoord
+ ld a,[hl]
+ add b
+ ld [hl],a
+ cp $2
+ jr nz,.checkForMoveToNorthBlock
+; moved into the tile block to the south
+ xor a
+ ld [hl],a
+ ld hl,wYOffsetSinceLastSpecialWarp
+ inc [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ ld a,[wCurMapWidth]
+ call MoveTileBlockMapPointerSouth
+ jr .updateMapView
+.checkForMoveToNorthBlock
+ cp a,$ff
+ jr nz,.updateMapView
+; moved into the tile block to the north
+ ld a,$1
+ ld [hl],a
+ ld hl,wYOffsetSinceLastSpecialWarp
+ dec [hl]
+ ld de,wCurrentTileBlockMapViewPointer
+ ld a,[wCurMapWidth]
+ call MoveTileBlockMapPointerNorth
+.updateMapView
+ call LoadCurrentMapView
+ ld a,[wSpriteStateData1 + 3] ; delta Y
+ cp $1
+ jr nz,.checkIfMovingNorth2
+; if moving south
+ call ScheduleSouthRowRedraw
+ jr .scrollBackgroundAndSprites
+.checkIfMovingNorth2
+ cp $ff
+ jr nz,.checkIfMovingEast2
+; if moving north
+ call ScheduleNorthRowRedraw
+ jr .scrollBackgroundAndSprites
+.checkIfMovingEast2
+ ld a,[wSpriteStateData1 + 5] ; delta X
+ cp $1
+ jr nz,.checkIfMovingWest2
+; if moving east
+ call ScheduleEastColumnRedraw
+ jr .scrollBackgroundAndSprites
+.checkIfMovingWest2
+ cp $ff
+ jr nz,.scrollBackgroundAndSprites
+; if moving west
+ call ScheduleWestColumnRedraw
+.scrollBackgroundAndSprites
+ ld a,[wSpriteStateData1 + 3] ; delta Y
+ add a
+ ld b,a
+ ld a,[wSpriteStateData1 + 5] ; delta X
+ add a
+ ld c,a
+; shift all the sprites in the direction opposite of the player's motion
+; so that the player appears to move relative to them
+ ld hl,wSpriteStateData1 + $14
+ ld e,15
+.spriteShiftLoop
+ ld a,[hl]
+ sub b
+ ld [hli],a
+ inc l
+ ld a,[hl]
+ sub c
+ ld [hl],a
+ ld a,$0e
+ add l
+ ld l,a
+ dec e
+ jr nz,.spriteShiftLoop
+.done
+ ld a,[hSCY]
+ add b
+ ld [hSCY],a ; update background scroll Y
+ ld a,[hSCX]
+ add c
+ ld [hSCX],a ; update background scroll X
+ ret
+
+MoveTileBlockMapPointerEast::
+ ld a,[de]
+ add $1
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ inc a
+ ld [de],a
+ ret
+
+MoveTileBlockMapPointerWest::
+ ld a,[de]
+ sub $1
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ dec a
+ ld [de],a
+ ret
+
+MoveTileBlockMapPointerSouth::
+ add $6
+ ld b,a
+ ld a,[de]
+ add b
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ inc a
+ ld [de],a
+ ret
+
+MoveTileBlockMapPointerNorth::
+ add $6
+ ld b,a
+ ld a,[de]
+ sub b
+ ld [de],a
+ ret nc
+ inc de
+ ld a,[de]
+ dec a
+ ld [de],a
+ ret
diff --git a/engine/overworld/boulders.asm b/engine/overworld/boulders.asm
new file mode 100644
index 00000000..669b7b83
--- /dev/null
+++ b/engine/overworld/boulders.asm
@@ -0,0 +1,94 @@
+CheckForCollisionWhenPushingBoulder:
+ call GetTileTwoStepsInFrontOfPlayer
+ call IsTilePassable
+ jr c, .done
+ 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/cable_club_npc.asm b/engine/overworld/cable_club_npc.asm
index 70b499a0..e3ce8e8d 100755
--- a/engine/overworld/cable_club_npc.asm
+++ b/engine/overworld/cable_club_npc.asm
@@ -1,9 +1,12 @@
CableClubNPC:
ld hl, CableClubNPCWelcomeText
call PrintText
+ call CheckPikachuFollowingPlayer
+ jr nz, .asm_7048
CheckEvent EVENT_GOT_POKEDEX
jp nz, .receivedPokedex
; if the player hasn't received the pokedex
+.asm_7048
ld c, 60
call DelayFrames
ld hl, CableClubNPCMakingPreparationsText
@@ -107,7 +110,61 @@ CableClubNPC:
xor a
ld [hld], a
ld [hl], a
- jpab LinkMenu
+ ld a, [wLetterPrintingDelayFlags]
+ push af
+ callab LinkMenu
+ pop af
+ ld [wLetterPrintingDelayFlags], a
+ ret
+
+; seems to be similar of Serial_SyncAndExchangeNybble
+Serial_SyncAndExchangeNybbleDouble:
+ ld a, $ff
+ ld [wSerialExchangeNybbleReceiveData], a
+.loop
+ call Serial_ExchangeNybble
+ call DelayFrame
+ push hl
+ ld hl, wUnknownSerialCounter + 1
+ dec [hl]
+ jr nz, .next
+ dec hl
+ dec [hl]
+ jr nz, .next
+ pop hl
+ jr .setUnknownSerialCounterToFFFF
+.next
+ pop hl
+ ld a, [wSerialExchangeNybbleReceiveData]
+ inc a
+ jr z, .loop
+ call DelayFrame
+ ld a, $ff
+ ld [wSerialExchangeNybbleReceiveData], a
+ call Serial_ExchangeNybble
+ ld a, [wSerialExchangeNybbleReceiveData]
+ inc a
+ jr z, .loop
+ ld b, 10
+.syncLoop1
+ call DelayFrame
+ call Serial_ExchangeNybble
+ dec b
+ jr nz, .syncLoop1
+ ld b, 10
+.syncLoop2
+ call DelayFrame
+ call Serial_SendZeroByte
+ dec b
+ jr nz, .syncLoop2
+ ld a, [wSerialExchangeNybbleReceiveData]
+ ld [wSerialSyncAndExchangeNybbleReceiveData], a
+ ret
+.setUnknownSerialCounterToFFFF
+ ld a, $ff
+ ld [wUnknownSerialCounter], a
+ ld [wUnknownSerialCounter + 1], a
+ ret
CableClubNPCAreaReservedFor2FriendsLinkedByCableText:
TX_FAR _CableClubNPCAreaReservedFor2FriendsLinkedByCableText
diff --git a/engine/overworld/card_key.asm b/engine/overworld/card_key.asm
index 61e512de..e1fc9160 100755
--- a/engine/overworld/card_key.asm
+++ b/engine/overworld/card_key.asm
@@ -8,7 +8,8 @@ PrintCardKeyText:
ret z
cp b
jr nz, .silphCoMapListLoop
- predef GetTileAndCoordsInFrontOfPlayer
+; does not check for tile in front of player. This might be buggy
+ ;predef GetTileAndCoordsInFrontOfPlayer
ld a, [wTileInFrontOfPlayer]
cp $18
jr z, .cardKeyDoorInFrontOfPlayer
@@ -25,12 +26,12 @@ PrintCardKeyText:
ld b, CARD_KEY
call IsItemInBag
jr z, .noCardKey
- call GetCoordsInFrontOfPlayer
- push de
+ xor a
+ ld [wPlayerMovingDirection], a
tx_pre_id CardKeySuccessText
ld [hSpriteIndexOrTextID], a
call PrintPredefTextID
- pop de
+ call GetCoordsInFrontOfPlayer
srl d
ld a, d
ld b, a
@@ -73,7 +74,7 @@ SilphCoMapList:
CardKeySuccessText:
TX_FAR _CardKeySuccessText1
- db $0b
+ TX_SFX_ITEM
TX_FAR _CardKeySuccessText2
db "@"
@@ -88,7 +89,7 @@ GetCoordsInFrontOfPlayer:
ld d, a
ld a, [wXCoord]
ld e, a
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
and a
jr nz, .notFacingDown
; facing down
diff --git a/engine/overworld/check_player_state.asm b/engine/overworld/check_player_state.asm
new file mode 100644
index 00000000..5fad4fc5
--- /dev/null
+++ b/engine/overworld/check_player_state.asm
@@ -0,0 +1,236 @@
+; 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 [$ff8b], 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
+ call ForceBikeOrSurf
+ ret
+.incorrectMap
+ inc hl
+.incorrectY
+ inc hl
+ jr .loop
+.forceSurfing
+ ld a, $2
+ ld [wWalkBikeSurfState], a
+ ld [wWalkBikeSurfStateCopy], a
+ call ForceBikeOrSurf
+ ret
+
+INCLUDE "data/force_bike_surf.asm"
+
+IsPlayerFacingEdgeOfMap:
+ push hl
+ push de
+ push bc
+ ld a, [wPlayerFacingDirection] ; 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, .returnaddress
+ push de
+ jp [hl]
+.returnaddress
+ 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, [wPlayerFacingDirection] ; 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 ; 6:6785
+ 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"
diff --git a/engine/overworld/clear_loadmapdata_vars.asm b/engine/overworld/clear_loadmapdata_vars.asm
new file mode 100644
index 00000000..c5dc21fa
--- /dev/null
+++ b/engine/overworld/clear_loadmapdata_vars.asm
@@ -0,0 +1,20 @@
+ClearVariablesAfterLoadingMapData:
+ ld a, $90
+ ld [hWY], a
+ ld [rWY], a
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld [wStepCounter], a
+ ld [wLoneAttackNo], a ; wGymLeaderNo
+ 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, wUnusedCD3D
+ ld bc, wStandingOnWarpPadOrHole - wUnusedCD3D
+ call FillMemory
+ ret
diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm
index 2f13dfba..462e3e8e 100755
--- a/engine/overworld/cut.asm
+++ b/engine/overworld/cut.asm
@@ -74,8 +74,9 @@ UsedCutText:
InitCutAnimOAM:
xor a
ld [wWhichAnimationOffsets], a
- ld a, $e4
+ ld a, %11100100
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
ld a, [wCutTile]
cp $52
jr z, .grass
@@ -123,8 +124,8 @@ WriteCutOrBoulderDustAnimationOAMBlock:
jp WriteOAMBlock
CutOrBoulderDustAnimationTilesAndAttributes:
- db $FC,$10,$FD,$10
- db $FE,$10,$FF,$10
+ db $FC,$14,$FD,$14
+ db $FE,$14,$FF,$14
GetCutOrBoulderDustAnimationOffsets:
ld hl, wSpriteStateData1 + 4
@@ -187,7 +188,7 @@ ReplaceTreeTileBlock:
ld h, [hl]
ld l, a
add hl, bc
- ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
+ ld a, [wPlayerFacingDirection] ; player sprite's facing direction
and a
jr z, .down
cp SPRITE_FACING_UP
diff --git a/engine/overworld/cut2.asm b/engine/overworld/cut2.asm
index f16fed66..37490f95 100755
--- a/engine/overworld/cut2.asm
+++ b/engine/overworld/cut2.asm
@@ -18,6 +18,7 @@ AnimCut:
ld a, [rOBP1]
xor $64
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
call DelayFrame
pop bc
dec c
@@ -68,6 +69,7 @@ AnimCutGrass_UpdateOAMEntries:
ld a, [rOBP1]
xor $64
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
call DelayFrame
pop bc
dec c
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 c39e096d..8bde8600 100755
--- a/engine/overworld/doors.asm
+++ b/engine/overworld/doors.asm
@@ -39,6 +39,7 @@ DoorTileIDPointers:
dbw LAB, LabDoorTileIDs
dbw FACILITY, FacilityDoorTileIDs
dbw PLATEAU, PlateauDoorTileIDs
+ dbw INTERIOR, InteriorDoorTileIDs
db $ff
OverworldDoorTileIDs:
@@ -73,3 +74,6 @@ FacilityDoorTileIDs:
PlateauDoorTileIDs:
db $3b,$1b,$00
+
+InteriorDoorTileIDs:
+ db $04,$15,$00
diff --git a/engine/overworld/dungeon_warps.asm b/engine/overworld/dungeon_warps.asm
new file mode 100644
index 00000000..f47dfb01
--- /dev/null
+++ b/engine/overworld/dungeon_warps.asm
@@ -0,0 +1,15 @@
+IsPlayerOnDungeonWarp:
+ xor a
+ ld [wWhichDungeonWarp], a
+ ld a, [wd72d]
+ bit 4, a
+ ret nz
+ call ArePlayerCoordsInArray
+ ret nc
+ ld a, [wCoordIndex]
+ ld [wWhichDungeonWarp], a
+ ld hl, wd72d
+ set 4, [hl]
+ ld hl, wd732
+ set 4, [hl]
+ ret
diff --git a/engine/overworld/elevator.asm b/engine/overworld/elevator.asm
index 4ec34922..cd7bf5ba 100755
--- a/engine/overworld/elevator.asm
+++ b/engine/overworld/elevator.asm
@@ -4,8 +4,7 @@ ShakeElevator:
ld de, SCREEN_HEIGHT * $20
call ShakeElevatorRedrawRow
call Delay3
- ld a, $ff
- call PlaySound
+ call StopAllMusic
ld a, [hSCY]
ld d, a
ld e, $1
@@ -27,14 +26,13 @@ ShakeElevator:
jr nz, .shakeLoop
ld a, d
ld [hSCY], a
- ld a, $ff
- call PlaySound
+ call StopAllMusic
ld c, BANK(SFX_Safari_Zone_PA)
ld a, SFX_SAFARI_ZONE_PA
call PlayMusic
.musicLoop
ld a, [wChannelSoundIDs + CH4]
- cp $b9
+ cp SFX_SAFARI_ZONE_PA
jr z, .musicLoop
call UpdateSprites
jp PlayDefaultMusic
@@ -56,7 +54,7 @@ ShakeElevatorRedrawRow:
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 4df8b6f6..7c7f5e7d 100755
--- a/engine/overworld/emotion_bubbles.asm
+++ b/engine/overworld/emotion_bubbles.asm
@@ -1,13 +1,16 @@
EmotionBubble:
ld a, [wWhichEmotionBubble]
+ and $f
+ swap a
ld c, a
- ld b, 0
- ld hl, EmotionBubblesPointerTable
+ ld b, $0
+ ld hl, EmotionBubbles
+ add hl, bc ; each emotion bubble is 16 bytes, so calculate the offset directly instead of with a pointer table
add hl, bc
add hl, bc
- ld e, [hl]
- inc hl
- ld d, [hl]
+ add hl, bc
+ ld e, l
+ ld d, h
ld hl, vChars1 + $780
lb bc, BANK(EmotionBubbles), $04
call CopyVideoData
@@ -17,11 +20,11 @@ EmotionBubble:
ld [wUpdateSpritesEnabled], a
ld a, [wd736]
bit 6, a ; are the last 4 OAM entries reserved for a shadow or fishing rod?
- ld hl, wOAMBuffer + $8f
- ld de, wOAMBuffer + $9f
+ ld hl, wOAMBuffer + 4 * 35 + $3 ; $8f
+ ld de, wOAMBuffer + 4 * 39 + $3 ; $9f
jr z, .next
- ld hl, wOAMBuffer + $7f
- ld de, wOAMBuffer + $8f
+ 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.
@@ -59,12 +62,9 @@ EmotionBubble:
pop af
ld [wUpdateSpritesEnabled], a
call DelayFrame
- jp UpdateSprites
-
-EmotionBubblesPointerTable:
- dw EmotionBubbles
- dw EmotionBubbles + $40
- dw EmotionBubbles + $80
+ call UpdateSprites
+ ret
+ ; jp UpdateSprites
EmotionBubblesOAM:
db $F8,$00,$F9,$00
diff --git a/engine/overworld/get_coords_tile_in_front_of_player.asm b/engine/overworld/get_coords_tile_in_front_of_player.asm
new file mode 100644
index 00000000..e8bbc660
--- /dev/null
+++ b/engine/overworld/get_coords_tile_in_front_of_player.asm
@@ -0,0 +1,87 @@
+GetTileAndCoordsInFrontOfPlayer:
+ call GetPredefRegisters
+
+_GetTileAndCoordsInFrontOfPlayer:
+ ld a, [wYCoord]
+ ld d, a
+ ld a, [wXCoord]
+ ld e, a
+ ld a, [wPlayerFacingDirection] ; 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, [wPlayerFacingDirection] ; 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
diff --git a/engine/overworld/healing_machine.asm b/engine/overworld/healing_machine.asm
index 38a44cfb..1dc74e2d 100755
--- a/engine/overworld/healing_machine.asm
+++ b/engine/overworld/healing_machine.asm
@@ -1,5 +1,5 @@
AnimateHealingMachine:
- ld de, PokeCenterFlashingMonitorAndHealBall
+ ld de, PokeCenterFlashingMonitorAndHealBall ; $44b7
ld hl, vChars0 + $7c0
lb bc, BANK(PokeCenterFlashingMonitorAndHealBall), $03 ; loads one too many tiles
call CopyVideoData
@@ -11,52 +11,50 @@ AnimateHealingMachine:
ld a, [rOBP1]
push af
ld a, $e0
- ld [rOBP1], a
+ ld [rOBP1], a ; $ff49
+ call UpdateGBCPal_OBP1
ld hl, wOAMBuffer + $84
- ld de, PokeCenterOAMData
+ ld de, PokeCenterOAMData ; $44d7
call CopyHealingMachineOAM
ld a, 4
ld [wAudioFadeOutControl], a
- ld a, $ff
- ld [wNewSoundID], a
- call PlaySound
+ call StopAllMusic
.waitLoop
ld a, [wAudioFadeOutControl]
- and a ; is fade-out finished?
- jr nz, .waitLoop ; if not, check again
- ld a, [wPartyCount]
+ and a
+ jr nz, .waitLoop
+ ld a, [wPartyCount] ; wPartyCount
ld b, a
.partyLoop
call CopyHealingMachineOAM
- ld a, SFX_HEALING_MACHINE
+ ld a, $9e ; (SFX_02_4a - SFX_Headers_02) / 3
call PlaySound
ld c, 30
call DelayFrames
dec b
jr nz, .partyLoop
ld a, [wAudioROMBank]
- cp BANK(Audio3_UpdateMusic)
+ cp $1f
ld [wAudioSavedROMBank], a
jr nz, .next
- ld a, $ff
- ld [wNewSoundID], a
- call PlaySound
- ld a, BANK(Music_PkmnHealed)
+ call StopAllMusic
+ ld a, $2 ; BANK(Music_PkmnHealed)
ld [wAudioROMBank], a
.next
- ld a, MUSIC_PKMN_HEALED
+ ld a, $e8 ; MUSIC_PKMN_HEALED
ld [wNewSoundID], a
call PlaySound
ld d, $28
call FlashSprite8Times
.waitLoop2
ld a, [wChannelSoundIDs]
- cp MUSIC_PKMN_HEALED ; is the healed music still playing?
- jr z, .waitLoop2 ; if so, check gain
+ cp $e8 ; MUSIC_PKMN_HEALED
+ jr z, .waitLoop2
ld c, 32
call DelayFrames
pop af
- ld [rOBP1], a
+ ld [rOBP1], a ; $ff49
+ call UpdateGBCPal_OBP1
pop hl
pop af
ld [hl], a
@@ -66,13 +64,13 @@ PokeCenterFlashingMonitorAndHealBall:
INCBIN "gfx/pokecenter_ball.2bpp"
PokeCenterOAMData:
- db $24,$34,$7C,$10 ; heal machine monitor
- db $2B,$30,$7D,$10 ; pokeballs 1-6
- db $2B,$38,$7D,$30
- db $30,$30,$7D,$10
- db $30,$38,$7D,$30
- db $35,$30,$7D,$10
- db $35,$38,$7D,$30
+ db $24,$34,$7C,$14 ; heal machine monitor
+ db $2B,$30,$7D,$14 ; pokeballs 1-6
+ db $2B,$38,$7D,$34
+ db $30,$30,$7D,$14
+ db $30,$38,$7D,$34
+ db $35,$30,$7D,$14
+ db $35,$38,$7D,$34
; d = value to xor with palette
FlashSprite8Times:
@@ -81,6 +79,7 @@ FlashSprite8Times:
ld a, [rOBP1]
xor d
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
ld c, 10
call DelayFrames
dec b
diff --git a/engine/overworld/hidden_items.asm b/engine/overworld/hidden_items.asm
index 11e6ad55..15082847 100755
--- a/engine/overworld/hidden_items.asm
+++ b/engine/overworld/hidden_items.asm
@@ -9,7 +9,7 @@ HiddenItems:
predef FlagActionPredef
ld a, c
and a
- ret nz
+ jr nz, .itemAlreadyFound
call EnableAutoTextBoxDrawing
ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
@@ -18,6 +18,11 @@ HiddenItems:
call GetItemName
tx_pre_jump FoundHiddenItemText
+.itemAlreadyFound
+ ld a, $ff
+ ld [hItemAlreadyFound], a
+ ret
+
INCLUDE "data/hidden_item_coords.asm"
FoundHiddenItemText:
@@ -27,7 +32,7 @@ FoundHiddenItemText:
ld b, a
ld c, 1
call GiveItem
- jr nc, .BagFull
+ jr nc, .bagFull
ld hl, wObtainedHiddenItemsFlags
ld a, [wHiddenItemOrCoinsIndex]
ld c, a
@@ -37,7 +42,7 @@ FoundHiddenItemText:
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
jp TextScriptEnd
-.BagFull
+.bagFull
call WaitForTextScrollButtonPress ; wait for button press
xor a
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
@@ -54,7 +59,7 @@ HiddenCoins:
predef GetQuantityOfItemInBag
ld a, b
and a
- ret z
+ jr z, .doNotPickUpCoins
ld hl, HiddenCoinCoords
call FindHiddenItemOrCoinsIndex
ld [wHiddenItemOrCoinsIndex], a
@@ -65,7 +70,7 @@ HiddenCoins:
predef FlagActionPredef
ld a, c
and a
- ret nz
+ jr nz, .doNotPickUpCoins
xor a
ld [hUnusedCoinsByte], a
ld [hCoins], a
@@ -77,24 +82,30 @@ HiddenCoins:
cp 20
jr z, .bcd20
cp 40
- jr z, .bcd20
+ jr z, .bcd20 ; should be bcd40
jr .bcd100
+
+.doNotPickUpCoins
+ ld a, $ff
+ ld [hItemAlreadyFound], a
+ ret
+
.bcd10
ld a, $10
ld [hCoins + 1], a
- jr .bcddone
+ jr .bcdDone
.bcd20
ld a, $20
ld [hCoins + 1], a
- jr .bcddone
+ jr .bcdDone
.bcd40 ; due to a typo, this is never used
ld a, $40
ld [hCoins + 1], a
- jr .bcddone
+ jr .bcdDone
.bcd100
ld a, $1
ld [hCoins], a
-.bcddone
+.bcdDone
ld de, wPlayerCoins + 1
ld hl, hCoins + 1
ld c, $2
@@ -107,13 +118,13 @@ HiddenCoins:
call EnableAutoTextBoxDrawing
ld a, [wPlayerCoins]
cp $99
- jr nz, .RoomInCoinCase
+ jr nz, .roomInCoinCase
ld a, [wPlayerCoins + 1]
cp $99
- jr nz, .RoomInCoinCase
+ jr nz, .roomInCoinCase
tx_pre_id DroppedHiddenCoinsText
jr .done
-.RoomInCoinCase
+.roomInCoinCase
tx_pre_id FoundHiddenCoinsText
.done
jp PrintPredefTextID
diff --git a/engine/overworld/hidden_objects.asm b/engine/overworld/hidden_objects.asm
index dcdf8537..9a81dcfc 100755
--- a/engine/overworld/hidden_objects.asm
+++ b/engine/overworld/hidden_objects.asm
@@ -1,43 +1,17 @@
-IsPlayerOnDungeonWarp:
- xor a
- ld [wWhichDungeonWarp], a
- ld a, [wd72d]
- bit 4, a
- ret nz
- call ArePlayerCoordsInArray
- ret nc
- ld a, [wCoordIndex]
- ld [wWhichDungeonWarp], a
- ld hl, wd72d
- set 4, [hl]
- ld hl, wd732
- set 4, [hl]
- ret
-
-; if a hidden object was found, stores $00 in [$ffee], else stores $ff
+; if a hidden object was found, stores $00 in [hDidntFindAnyHiddenObject], else stores $ff
CheckForHiddenObject:
- ld hl, $ffeb
+ ld hl, hItemAlreadyFound
xor a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
- ld de, $0
ld hl, HiddenObjectMaps
-.hiddenMapLoop
- ld a, [hli]
- ld b, a
- cp $ff
- jr z, .noMatch
+ ld de, 3
ld a, [wCurMap]
- cp b
- jr z, .foundMatchingMap
- inc de
- inc de
- jr .hiddenMapLoop
-.foundMatchingMap
- ld hl, HiddenObjectPointers
- add hl, de
+ call IsInArray
+ jr nc, .noMatch
+ inc hl
ld a, [hli]
ld h, [hl]
ld l, a
@@ -81,13 +55,13 @@ CheckForHiddenObject:
ret
.noMatch
ld a, $ff
- ld [$ffee], a
+ ld [hDidntFindAnyHiddenObject], a
ret
; checks if the coordinates in front of the player's sprite match Y in b and X in c
; [hCoordsInFrontOfPlayerMatch] = $00 if they match, $ff if they don't match
CheckIfCoordsInFrontOfPlayerMatch:
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
cp SPRITE_FACING_UP
jr z, .facingUp
cp SPRITE_FACING_LEFT
diff --git a/engine/overworld/ledges.asm b/engine/overworld/ledges.asm
index 342540b2..e7874637 100755
--- a/engine/overworld/ledges.asm
+++ b/engine/overworld/ledges.asm
@@ -6,7 +6,7 @@ HandleLedges:
and a ; OVERWORLD
ret nz
predef GetTileAndCoordsInFrontOfPlayer
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
ld b, a
aCoord 8, 9
ld c, a
@@ -71,10 +71,13 @@ LoadHoppingShadowOAM:
ld de, LedgeHoppingShadow
lb bc, BANK(LedgeHoppingShadow), (LedgeHoppingShadowEnd - LedgeHoppingShadow) / $8
call CopyVideoDataDouble
- ld a, $9
- lb bc, $54, $48 ; b, c = y, x coordinates of shadow
- ld de, LedgeHoppingShadowOAM
- call WriteOAMBlock
+ ld hl, LedgeHoppingShadowOAM
+ ld de, wOAMBuffer + 36 * 4
+ ld bc, LedgeHoppingShadowOAMEnd - LedgeHoppingShadowOAM
+ call CopyData
+ ld a, $a0
+ ld [wOAMBuffer + 38 * 4], a
+ ld [wOAMBuffer + 39 * 4], a
ret
LedgeHoppingShadow:
@@ -82,5 +85,6 @@ LedgeHoppingShadow:
LedgeHoppingShadowEnd:
LedgeHoppingShadowOAM:
- db $FF,$10,$FF,$20
- db $FF,$40,$FF,$60
+ db $58,$48,$FF,$00
+ db $58,$50,$FF,$20
+LedgeHoppingShadowOAMEnd:
diff --git a/engine/overworld/load_tileset_header.asm b/engine/overworld/load_tileset_header.asm
new file mode 100644
index 00000000..05061651
--- /dev/null
+++ b/engine/overworld/load_tileset_header.asm
@@ -0,0 +1,51 @@
+LoadTilesetHeader:
+ call GetPredefRegisters
+ push hl
+ ld d, 0
+ ld a, [wCurMapTileset]
+ add a
+ add a
+ ld e, a
+ ld hl, Tilesets
+ add hl, de
+ add hl, de
+ add hl, de
+ ld de, wTilesetBank
+ ld bc, $b
+ call CopyData
+ 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, .notDungeonTileset
+ ld a, [wCurMapTileset]
+ ld b, a
+ ld a, [hPreviousTileset]
+ cp b
+ jr z, .done
+.notDungeonTileset
+ 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/load_wild_data.asm b/engine/overworld/load_wild_data.asm
new file mode 100644
index 00000000..6444ab7e
--- /dev/null
+++ b/engine/overworld/load_wild_data.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/overworld/map_sprite_functions1.asm b/engine/overworld/map_sprite_functions1.asm
new file mode 100644
index 00000000..f0a718bd
--- /dev/null
+++ b/engine/overworld/map_sprite_functions1.asm
@@ -0,0 +1,390 @@
+_UpdateSprites:
+ ld h, wSpriteStateData1 / $100
+ inc h
+ ld a, $e ; (wSpriteStateData2 + $0e) & $ff
+.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 ; 4bd7 (1:4bd7)
+ ld a, [H_CURRENTSPRITEOFFSET]
+ and a
+ jp z, UpdatePlayerSprite
+ cp $f0 ; pikachu
+ jp z, SpawnPikachu
+ ld a, [hl]
+
+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]
+ 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, l
+ and $f0 ; collision with pikachu?
+ jr nz, .asm_4cd9
+ xor a
+ ld [wd434], a
+ ld a, [$ff8f]
+ cp $f
+ jr nz, .asm_4cd9
+ call Func_4d0a
+ jr .asm_4cef
+.asm_4cd9
+ 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
+.asm_4cef
+ 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
+Func_4d0a:
+ ld a, [$ff91]
+ ld b, a
+ ld a, [$ff90]
+ inc l
+ cp b
+ jr c, .asm_4d17
+ ld b, %1100
+ jr .asm_4d19
+.asm_4d17
+ ld b, %11
+.asm_4d19
+ ld a, c
+ and b
+ ld [wd434], a
+ ld a, c
+ inc l
+ inc l
+ ret
+
+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 05588321..43b44946 100755
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -8,433 +8,361 @@
; 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:
+_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)
- ld hl,wSpriteStateData1
- ld de,wSpriteStateData2 + $0d
-; Loop to copy picture ID's from $C1X0 to $C2XD for LoadMapSpriteTilePatterns.
-.copyPictureIDLoop
- ld a,[hl] ; $C1X0 (picture ID)
- ld [de],a ; $C2XD
- ld a,$10
- add e
- ld e,a
- ld a,$10
- add l
- ld l,a
- jr nz,.copyPictureIDLoop
-
-; This is used for both inside and outside maps, since it is called by
-; InitOutsideMapSprites.
-; Loads tile pattern data for sprites into VRAM.
-LoadMapSpriteTilePatterns:
- ld a,[wNumSprites]
- and a ; are there any sprites?
- jr nz,.spritesExist
- ret
-.spritesExist
- ld c,a ; c = [wNumSprites]
- ld b,$10 ; number of sprite slots
- ld hl,wSpriteStateData2 + $0d
- xor a
- ld [hFourTileSpriteCount],a
-.copyPictureIDLoop ; loop to copy picture ID from $C2XD to $C2XE
- ld a,[hli] ; $C2XD (sprite picture ID)
- ld [hld],a ; $C2XE
- ld a,l
- add a,$10
- ld l,a
- dec b
- jr nz,.copyPictureIDLoop
- ld hl,wSpriteStateData2 + $1e
-.loadTilePatternLoop
- ld de,wSpriteStateData2 + $1d
-; Check if the current picture ID has already had its tile patterns loaded.
-; This done by looping through the previous sprite slots and seeing if any of
-; their picture ID's match that of the current sprite slot.
-.checkIfAlreadyLoadedLoop
- ld a,e
- and a,$f0
- ld b,a ; b = offset of the wSpriteStateData2 sprite slot being checked against
- ld a,l
- and a,$f0 ; a = offset of current wSpriteStateData2 sprite slot
- cp b ; done checking all previous sprite slots?
- jr z,.notAlreadyLoaded
- ld a,[de] ; picture ID of the wSpriteStateData2 sprite slot being checked against
- cp [hl] ; do the picture ID's match?
- jp z,.alreadyLoaded
- ld a,e
- add a,$10
- ld e,a
- jr .checkIfAlreadyLoadedLoop
-.notAlreadyLoaded
- ld de,wSpriteStateData2 + $0e
- ld b,$01
-; loop to find the highest tile pattern VRAM slot (among the first 10 slots) used by a previous sprite slot
-; this is done in order to find the first free VRAM slot available
-.findNextVRAMSlotLoop
- ld a,e
- add a,$10
- ld e,a
- ld a,l
- cp e ; reached current slot?
- jr z,.foundNextVRAMSlot
- ld a,[de] ; $C2YE (VRAM slot)
- cp a,11 ; is it one of the first 10 slots?
- jr nc,.findNextVRAMSlotLoop
- cp b ; compare the slot being checked to the current max
- jr c,.findNextVRAMSlotLoop ; if the slot being checked is less than the current max
-; if the slot being checked is greater than or equal to the current max
- ld b,a ; store new max VRAM slot
- jr .findNextVRAMSlotLoop
-.foundNextVRAMSlot
- inc b ; increment previous max value to get next VRAM tile pattern slot
- ld a,b ; a = next VRAM tile pattern slot
- push af
- ld a,[hl] ; $C2XE (sprite picture ID)
- ld b,a ; b = current sprite picture ID
- cp a,SPRITE_BALL ; is it a 4-tile sprite?
- jr c,.notFourTileSprite
- pop af
- ld a,[hFourTileSpriteCount]
- add a,11
- jr .storeVRAMSlot
-.notFourTileSprite
- pop af
-.storeVRAMSlot
- ld [hl],a ; store VRAM slot at $C2XE
- 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
- add a
- push bc
- push hl
- ld hl,SpriteSheetPointerTable
- jr nc,.noCarry
- inc h
-.noCarry
- add l
- ld l,a
- jr nc,.noCarry2
- inc h
-.noCarry2
- push hl
- call ReadSpriteSheetData
- push af
- push de
- push bc
- ld hl,vNPCSprites ; VRAM base address
- ld bc,$c0 ; number of bytes per VRAM slot
- ld a,[hVRAMSlot]
- cp a,11 ; is it a 4-tile sprite?
- jr nc,.fourTileSpriteVRAMAddr
- ld d,a
- dec d
-; Equivalent to multiplying $C0 (number of bytes in 12 tiles) times the VRAM
-; slot and adding the result to $8000 (the VRAM base address).
-.calculateVRAMAddrLoop
- add hl,bc
- dec d
- jr nz,.calculateVRAMAddrLoop
- jr .loadStillTilePattern
-.fourTileSpriteVRAMAddr
- ld hl,vSprites + $7c0 ; address for second 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 [hFourTileSpriteCount],a
-.loadStillTilePattern
- pop bc
- pop de
- pop af
- push hl
- push hl
- ld h,d
- ld l,e
- pop de
- ld b,a
- ld a,[wFontLoaded]
- bit 0,a ; reloading upper half of tile patterns after displaying text?
- jr nz,.skipFirstLoad ; if so, skip loading data into the lower half
- ld a,b
- ld b,0
- call FarCopyData2 ; load tile pattern data for sprite when standing still
-.skipFirstLoad
- pop de
- pop hl
- ld a,[hVRAMSlot]
- cp a,11 ; is it a 4-tile sprite?
- jr nc,.skipSecondLoad ; if so, there is no second block
- push de
- call ReadSpriteSheetData
- push af
- ld a,$c0
- add e
- ld e,a
- jr nc,.noCarry3
- inc d
-.noCarry3
- ld a,[wFontLoaded]
- bit 0,a ; reloading upper half of tile patterns after displaying text?
- jr nz,.loadWhileLCDOn
- pop af
- pop hl
- set 3,h ; add $800 to hl
- push hl
- ld h,d
- ld l,e
- pop de
- call FarCopyData2 ; load tile pattern data for sprite when walking
- jr .skipSecondLoad
-; When reloading the upper half of tile patterns after diplaying text, the LCD
-; will be on, so CopyVideoData (which writes to VRAM only during V-blank) must
-; be used instead of FarCopyData2.
-.loadWhileLCDOn
- pop af
- pop hl
- set 3,h ; add $800 to hl
- ld b,a
- swap c
- call CopyVideoData ; load tile pattern data for sprite when walking
-.skipSecondLoad
- pop hl
- pop bc
- jr .nextSpriteSlot
-.alreadyLoaded ; if the current picture ID has already had its tile patterns loaded
- inc de
- ld a,[de] ; a = VRAM slot for the current picture ID (from $C2YE)
- ld [hl],a ; store VRAM slot in current wSpriteStateData2 sprite slot (at $C2XE)
-.nextSpriteSlot
- ld a,l
- add a,$10
- ld l,a
- dec c
- jp nz,.loadTilePatternLoop
- ld hl,wSpriteStateData2 + $0d
- ld b,$10
-; the pictures ID's stored at $C2XD are no longer needed, so zero them
-.zeroStoredPictureIDLoop
- xor a
- ld [hl],a ; $C2XD
- ld a,$10
- add l
- ld l,a
- dec b
- jr nz,.zeroStoredPictureIDLoop
- ret
-
-; reads data from SpriteSheetPointerTable
-; INPUT:
-; hl = address of sprite sheet entry
-; OUTPUT:
-; de = pointer to sprite sheet
-; bc = length in bytes
-; a = ROM bank
-ReadSpriteSheetData:
- ld a,[hli]
- ld e,a
- ld a,[hli]
- ld d,a
- ld a,[hli]
- ld c,a
- xor a
- ld b,a
- ld a,[hli]
+ call LoadSpriteSetFromMapHeader
+ call LoadMapSpriteTilePatterns
+ call Func_14150
ret
; 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:
- ld a,[wCurMap]
- cp a,REDS_HOUSE_1F ; is the map a city or a route (map ID less than $25)?
+ 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
- add l
- ld l,a
- jr nc,.noCarry
- inc h
-.noCarry
- ld a,[hl] ; a = spriteSetID
- cp a,$f0 ; does the map have 2 sprite sets?
- call nc,GetSplitMapSpriteSetID ; if so, choose the appropriate one
- ld b,a ; b = spriteSetID
- 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,[wSpriteSetID]
+ call GetSplitMapSpriteSetID
+; if so, choose the appropriate one
+ ld b, a ; b = spriteSetID
+ 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, [wSpriteSetID]
cp b ; has the sprite set ID changed?
- jr z,.skipLoadingSpriteSet ; if not, don't load it again
+ jr z, .skipLoadingSpriteSet ; if not, don't load it again
.loadSpriteSet
- ld a,b
- ld [wSpriteSetID],a
+ ld a, b
+ ld [wSpriteSetID], a
dec a
- ld b,a
- sla a
- ld c,a
- sla a
- sla a
- add c
- add b ; a = (spriteSetID - 1) * 11
- ld de,SpriteSets
-; add a to de to get offset of sprite set
- add e
- ld e,a
- jr nc,.noCarry2
- inc d
-.noCarry2
- ld hl,wSpriteStateData2 + $0d
- ld a,SPRITE_RED
- ld [hl],a
- 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
-; load tile patterns for all sprite pictures in the sprite set.
-.loadSpriteSetLoop
- ld a,$10
- add l
- ld l,a
- ld a,[de] ; sprite picture ID from sprite set
- ld [hl],a ; $C2XD (sprite picture ID)
- ld [bc],a
- inc de
- inc bc
- ld a,l
- cp a,$bd ; reached 11th sprite slot?
- jr nz,.loadSpriteSetLoop
- ld b,4 ; 4 remaining sprite slots
-.zeroRemainingSlotsLoop ; loop to zero the picture ID's of the remaining sprite slots
- ld a,$10
- add l
- ld l,a
- xor a
- ld [hl],a ; $C2XD (sprite picture ID)
- dec b
- jr nz,.zeroRemainingSlotsLoop
- ld a,[wNumSprites]
- push af ; save number of sprites
- ld a,11 ; 11 sprites in sprite set
- ld [wNumSprites],a
+ ld c, a
+ ld b, 0
+ ld a, (wSpriteSetID - wSpriteSet)
+ ld hl, SpriteSets
+ call AddNTimes ; get sprite set offset
+ ld de, wSpriteSet
+ ld bc, (wSpriteSetID - wSpriteSet)
+ call CopyData ; copy it to wSpriteSet
call LoadMapSpriteTilePatterns
- pop af
- 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
-; order of the map's sprite set, not the order of the actual sprites loaded
-; for the current map. So, they are not needed and are zeroed by this loop.
-.zeroVRAMSlotsLoop
- xor a
- ld [hl],a ; $C2XE (VRAM slot)
- ld a,$10
- add l
- ld l,a
- dec b
- jr nz,.zeroVRAMSlotsLoop
.skipLoadingSpriteSet
- ld hl,wSpriteStateData1 + $10
+ call Func_14150
+ scf
+ ret
+
+LoadSpriteSetFromMapHeader:
; This loop stores the correct VRAM tile pattern slots according the sprite
; data from the map's header. Since the VRAM tile pattern slots are filled in
; the order of the sprite set, in order to find the VRAM tile pattern slot
; for a sprite slot, the picture ID for the sprite is looked up within the
-; sprite set. The index of the picture ID within the sprite set plus one
-; (since the Red sprite always has the first VRAM tile pattern slot) is the
-; VRAM tile pattern slot.
+; sprite set. The index of the picture ID within the sprite set plus two
+; (since the Red sprite always has the first VRAM tile pattern slot and the
+; Pikachu sprite reserves the second slot) is the VRAM tile pattern slot.
+ ld hl, wSpriteSet
+ ld bc, (wSpriteSetID - wSpriteSet)
+ xor a
+ call FillMemory
+ ld a, SPRITE_PIKACHU ; load Pikachu separately
+ ld [wSpriteSet], a
+ ld hl, wSprite01SpriteStateData1
+ ld a, 14
.storeVRAMSlotsLoop
- ld c,0
- ld a,[hl] ; $C1X0 (picture ID) (zero if sprite slot is not used)
+ push af
+ ld a, [hl] ; $C1X0 (picture ID) (zero if sprite slot is not used)
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,wSpriteSet
-; Loop to find the index of the sprite's picture ID within the sprite set.
-.getPictureIndexLoop
- inc c
- ld a,[de]
+ jr z, .continue ; if the sprite slot is not used
+ ld c, a
+ call CheckForFourTileSprite ; is this a four tile sprite?
+ jr nc, .isFourTileSprite
+; loop through the space reserved for four tile picture IDs
+ ld de, wSpriteSet + 9
+ ld b, 2
+ call CheckIfPictureIDAlreadyLoaded
+ jr .continue
+
+.isFourTileSprite
+; loop through the space reserved for regular picture IDs
+ ld de, wSpriteSet
+ ld b, 9
+ call CheckIfPictureIDAlreadyLoaded
+.continue
+ ld de, wSprite02SpriteStateData1 - wSprite01SpriteStateData1
+ add hl, de
+ pop af
+ dec a
+ jr nz, .storeVRAMSlotsLoop
+ ret
+
+CheckIfPictureIDAlreadyLoaded:
+; Check if the current picture ID has already had its tile patterns loaded.
+; This done by looping through the previous sprite slots and seeing if any of
+; their picture ID's match that of the current sprite slot.
+.loop
+ ld a, [de]
+ and a ; is sprite set slot not taken up yet?
+ jr z, .spriteSlotNotTaken ; if so, load it as it signifies we've reached
+ ; the end of data for the last sprite set
+
+ cp c ; is the tile pattern already loaded?
+ ret z ; don't redundantly load
+ dec b ; have we reached the end of the sprite set?
+ jr z, .spriteNotAlreadyLoaded ; if so, we're done here
inc de
- cp b ; does the picture ID match?
- jr nz,.getPictureIndexLoop
- inc c
-.skipGettingPictureIndex
- push hl
- inc h
- ld a,$0e
- add l
- ld l,a
- ld a,c ; a = VRAM slot (zero if sprite slot is not used)
- ld [hl],a ; $C2XE (VRAM slot)
- pop hl
- ld a,$10
- add l
- ld l,a
+ jr .loop
+
+.spriteSlotNotTaken
+ ld a, c
+ ld [de], a
+ ret
+.spriteNotAlreadyLoaded
+ scf
+ ret
+
+CheckForFourTileSprite:
+; Checks for a sprite added in yellow
+; Returns no carry if the sprite is Pikachu, as its sprite is handled separately
+; Else, returns carry if the sprite uses 4 tiles
+ cp SPRITE_PIKACHU ; is this the Pikachu Sprite?
+ ret z ; return if yes
+
+ cp SPRITE_BALL ; is this a four tile sprite?
+ jr nc, .notYellowSprite ; set carry if yes
+; regular sprite
and a
- jr nz,.storeVRAMSlotsLoop
+ ret
+
+.notYellowSprite
scf
ret
+LoadMapSpriteTilePatterns:
+ ld a, 0
+.loop
+ ld [hVRAMSlot], a
+ cp 9
+ jr nc, .fourTileSprite
+ call LoadStillTilePattern
+ call LoadWalkingTilePattern
+ jr .continue
+
+.fourTileSprite
+ call LoadStillTilePattern
+.continue
+ ld a, [hVRAMSlot]
+ inc a
+ cp 11
+ jr nz, .loop
+ ret
+
+ReloadWalkingTilePatterns:
+ xor a
+.loop
+ ld [hVRAMSlot], a
+ cp 9
+ jr nc, .fourTileSprite
+ call LoadWalkingTilePattern
+.fourTileSprite
+ ld a, [hVRAMSlot]
+ inc a
+ cp 11
+ jr nz, .loop
+ ret
+
+LoadStillTilePattern:
+ ld a, [wFontLoaded]
+ bit 0, a ; reloading upper half of tile patterns after displaying text?
+ ret nz ; if so, skip loading data into the lower half
+ call ReadSpriteSheetData
+ ret nc
+ call GetSpriteVRAMAddress
+ call CopyVideoDataAlternate ; new yellow function
+ ret
+
+LoadWalkingTilePattern:
+ call ReadSpriteSheetData
+ ret nc
+ ld hl, $c0
+ add hl, de
+ ld d, h
+ ld e, l
+ call GetSpriteVRAMAddress
+ set 3, h ; add $800 to hl
+ call CopyVideoDataAlternate
+ ret
+
+GetSpriteVRAMAddress:
+ push bc
+ ld a, [hVRAMSlot]
+ ld c, a
+ ld b, 0
+ ld hl, SpriteVRAMAddresses
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop bc
+ ret
+
+SpriteVRAMAddresses:
+; Equivalent to multiplying $C0 (number of bytes in 12 tiles) times the VRAM
+; slot and adding the result to $8000 (the VRAM base address).
+ dw vChars0 + $0c0
+ dw vChars0 + $180
+ dw vChars0 + $240
+ dw vChars0 + $300
+ dw vChars0 + $3c0
+ dw vChars0 + $480
+ dw vChars0 + $540
+ dw vChars0 + $600
+ dw vChars0 + $6c0
+ dw vChars0 + $780 ; 4-tile sprites
+ dw vChars0 + $7c0 ; 4-tile sprites
+
+ReadSpriteSheetData:
+ ld a, [hVRAMSlot]
+ ld e, a
+ ld d, 0
+ ld hl, wSpriteSet
+ add hl, de
+ ld a, [hl]
+ and a
+ ret z
+
+ dec a
+ ld l, a
+ ld h, 0
+ add hl, hl
+ add hl, hl
+ ld de, SpriteSheetPointerTable
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+ ld c, [hl]
+ swap c ; get the number of tiles, not the raw byte length
+ ; this is because of the use of CopyVideoDataAlternate
+ inc hl
+ ld b, [hl]
+ inc hl
+ scf
+ ret
+
+Func_14150:
+ ld a, $1
+ ld [wPlayerSpriteImageBaseOffset], a ; vram slot for player
+ ld a, $2
+ ld [wPikachuSpriteImageBaseOffset], a ; vram slot for Pikachu
+ ld a, $e
+ ld hl, wSprite01SpriteStateData1
+.loop
+ ld [hVRAMSlot], a ; store current sprite set slot as a counter
+ ld a, [hl] ; $c1x0 (picture ID)
+ and a ; is the sprite unused?
+ jr z, .spriteUnused
+ call Func_14179
+ push hl
+ ld de, (wPlayerSpriteImageBaseOffset) - (wSpriteStateData1) ; $10e
+ add hl, de ; get $c2xe (sprite image base offset)
+ ld [hl], a ; write offset
+ pop hl
+.spriteUnused
+ ld de, wSprite02SpriteStateData1 - wSprite01SpriteStateData1
+ add hl, de
+ ld a, [hVRAMSlot]
+ dec a
+ jr nz, .loop
+ ret
+
+Func_14179:
+ push de
+ push bc
+ ld c, a ; c = picture ID
+ ld b, 11
+ ld de, wSpriteSet
+.findSpriteImageBaseOffsetLoop
+ ld a, [de] ; a = sprite set picture ID
+ cp c ; have we found a match?
+ jr z, .foundSpritePictureID ; if so, get the sprite image base offset and return
+ inc de
+ dec b ; have we looped through all entries in wSpriteSet?
+ jr nz, .findSpriteImageBaseOffsetLoop ; continue looping if not
+ ld a, $1 ; assume slot one if this ever happens
+ jr .done
+.foundSpritePictureID
+ ld a, 13
+ sub b ; get sprite image base offset
+.done
+ pop bc
+ pop de
+ ret
+
+GetSplitMapSpriteSetID:
+ ld e, a
+ ld d, 0
+ ld hl, MapSpriteSets
+ add hl, de
+ ld a, [hl] ; a = spriteSetID
+ cp a, $f0 ; does the map have 2 sprite sets?
+ ret c
; Chooses the correct sprite set ID depending on the player's position within
; the map for maps with two sprite sets.
-GetSplitMapSpriteSetID:
- cp a,$f8
- jr z,.route20
- ld hl,SplitMapSpriteSets
- and a,$0f
+ cp a, $f8
+ jr z, .route20
+ ld hl, SplitMapSpriteSets
+ and a, $0f
dec a
- sla a
- sla a
+ add a
+ add a
add l
- ld l,a
- jr nc,.noCarry
+ ld l, a
+ jr nc, .noCarry
inc h
.noCarry
- ld a,[hli] ; determines whether the map is split East/West or North/South
- cp a,$01
- ld a,[hli] ; position of dividing line
- ld b,a
- jr z,.eastWestDivide
+ ld a, [hli] ; determines whether the map is split East/West or North/South
+ cp a, $01
+ ld a, [hli] ; position of dividing line
+ ld b, a
+ jr z, .eastWestDivide
.northSouthDivide
- ld a,[wYCoord]
+ ld a, [wYCoord]
jr .compareCoord
+
.eastWestDivide
- ld a,[wXCoord]
+ ld a, [wXCoord]
.compareCoord
cp b
- jr c,.loadSpriteSetID
+ jr c, .loadSpriteSetID
; if in the East side or South side
inc hl
.loadSpriteSetID
- ld a,[hl]
+ ld a, [hl]
ret
; Uses sprite set $01 for West side and $0A for East side.
; 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,wXCoord
- ld a,[hl]
- cp a,$2b
- ld a,$01
+ ld hl, wXCoord
+ ld a, [hl]
+ cp a, $2b
+ ld a, $01
ret c
- ld a,[hl]
- cp a,$3e
- ld a,$0a
+ ld a, [hl]
+ cp a, $3e
+ ld a, $0a
ret nc
- ld a,[hl]
- cp a,$37
- ld b,$08
- jr nc,.next
- ld b,$0d
+ ld a, [hl]
+ cp a, $37
+ ld b, $08
+ jr nc, .next
+ ld b, $0d
.next
- ld a,[wYCoord]
+ ld a, [wYCoord]
cp b
- ld a,$0a
+ ld a, $0a
ret c
- ld a,$01
+ ld a, $01
ret
INCLUDE "data/sprite_sets.asm"
diff --git a/engine/overworld/missable_objects.asm b/engine/overworld/missable_objects.asm
new file mode 100644
index 00000000..dd601451
--- /dev/null
+++ b/engine/overworld/missable_objects.asm
@@ -0,0 +1,212 @@
+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:
+; seems to not exist in yellow (predef replaced with something near TryPushingBoulder)
+ ld l, a
+ push hl
+ ld a, l
+ sub MapHS00 & $ff ; calculate difference between out pointer and the base pointer
+ ld l, a
+ ld a, h
+ sbc MapHS00 / $100
+ 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 e60f820a..ad4515ff 100644
--- a/engine/overworld/movement.asm
+++ b/engine/overworld/movement.asm
@@ -20,7 +20,13 @@ UpdatePlayerSprite:
ld [wSpriteStateData1 + 2], a
ret
.lowerLeftTileIsMapTile
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
call DetectCollisionBetweenSprites
+ pop af
+ ld [wUpdateSpritesEnabled], a
ld h, wSpriteStateData1 / $100
ld a, [wWalkCounter]
and a
@@ -46,42 +52,24 @@ UpdatePlayerSprite:
jr z, .notMoving
ld a, SPRITE_FACING_RIGHT
jr .next
+.next
+ ld [wPlayerFacingDirection], a ; facing direction
+ ld a, [wFontLoaded]
+ bit 0, a
+ jr z, .moving
.notMoving
; zero the animation counters
xor a
ld [wSpriteStateData1 + 7], a
ld [wSpriteStateData1 + 8], a
- jr .calcImageIndex
-.next
- ld [wSpriteStateData1 + 9], a ; facing direction
- ld a, [wFontLoaded]
- bit 0, a
- jr nz, .notMoving
+ call Func_4e32
+ jr .skipSpriteAnim
.moving
ld a, [wd736]
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, .calcImageIndex
- xor a
- ld [hl], a
- inc hl
- ld a, [hl]
- inc a
- and $3
- ld [hl], a
-.calcImageIndex
- ld a, [wSpriteStateData1 + 8]
- ld b, a
- ld a, [wSpriteStateData1 + 9]
- add b
- ld [wSpriteStateData1 + 2], a
+ call Func_5274
+ call Func_4e32
.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
@@ -95,18 +83,15 @@ UpdatePlayerSprite:
jr nz, .next2
ld a, $80
.next2
- ld [wSpriteStateData2 + 7], a
+ ld [wSpriteStateData2 + $07], a
ret
-UnusedReadSpriteDataFunction:
- push bc
- push af
- ld a, [H_CURRENTSPRITEOFFSET]
- ld c, a
- pop af
- add c
- ld l, a
- pop bc
+Func_4e32:
+ ld a, [wSpriteStateData1 + 8]
+ ld b, a
+ ld a, [wPlayerFacingDirection]
+ add b
+ ld [wSpriteStateData1 + 2], a
ret
UpdateNPCSprite:
@@ -119,7 +104,7 @@ UpdateNPCSprite:
ld l, a
ld a, [hl] ; read movement byte 2
ld [wCurSpriteMovement2], a
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
ld l, a
inc l
@@ -128,7 +113,7 @@ UpdateNPCSprite:
jp z, InitializeSpriteStatus
call CheckSpriteAvailability
ret c ; if sprite is invisible, on tile >=$60, in grass or player is currently walking
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
ld l, a
inc l
@@ -144,19 +129,21 @@ UpdateNPCSprite:
jp z, UpdateSpriteMovementDelay ; c1x1 == 2
cp $3
jp z, UpdateSpriteInWalkingAnimation ; c1x1 == 3
+ cp $4
+ jp z, Func_5357
ld a, [wWalkCounter]
and a
ret nz ; don't do anything yet if player is currently moving (redundant, already tested in CheckSpriteAvailability)
call InitializeSpriteScreenPosition
- ld h, $c2
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $6
ld l, a
ld a, [hl] ; c2x6: movement byte 1
inc a
- jr z, .randomMovement ; value $FF
+ jp z, .randomMovement ; value $FF
inc a
- jr z, .randomMovement ; value $FE
+ jp z, .randomMovement ; value $FE
; scripted movement
dec a
ld [hl], a ; increment movement byte 1 (movement data index)
@@ -181,12 +168,18 @@ UpdateNPCSprite:
ret
.next
cp WALK
- jr nz, .determineDirection
+ jr nz, .asm_4ecb
; current NPC movement data is $fe. this seems buggy
ld [hl], $1 ; set movement byte 1 to $1
ld de, wNPCMovementDirections
call LoadDEPlusA ; a = [wNPCMovementDirections + $fe] (?)
- jr .determineDirection
+.asm_4ecb
+ push af
+ call Func_5288
+ pop bc
+ ld a, b
+ jr nc, .determineDirection
+ ret
.randomMovement
call GetTileSpriteStandsOn
call Random
@@ -261,59 +254,25 @@ ChangeFacingDirection:
; set carry on failure, clears carry on success
TryWalking:
push hl
- ld h, $c1
- ld a, [H_CURRENTSPRITEOFFSET]
- add $9
- ld l, a
- ld [hl], c ; c1x9 (update facing direction)
- ld a, [H_CURRENTSPRITEOFFSET]
- add $3
- ld l, a
- ld [hl], d ; c1x3 (update Y movement delta)
- inc l
- inc l
- ld [hl], e ; c1x5 (update X movement delta)
+ call Func_5337
pop hl
push de
- ld c, [hl] ; read tile to walk onto
+ ld c, [hl]
call CanWalkOntoTile
pop de
- ret c ; cannot walk there (reinitialization of delay values already done)
- ld h, $c2
- ld a, [H_CURRENTSPRITEOFFSET]
- add $4
- ld l, a
- ld a, [hl] ; c2x4: Y position
- add d
- ld [hli], a ; update Y position
- ld a, [hl] ; c2x5: X position
- add e
- ld [hl], a ; update X position
+ ret c
+ call Func_5349
ld a, [H_CURRENTSPRITEOFFSET]
ld l, a
- ld [hl], $10 ; c2x0=16: walk animation counter
+ ld [hl], $10 ; c1x9 (update facing direction)
dec h
inc l
- ld [hl], $3 ; c1x1: set movement status to walking
+ ld [hl], $3
jp UpdateSpriteImage
; update the walking animation parameters for a sprite that is currently walking
UpdateSpriteInWalkingAnimation:
- ld a, [H_CURRENTSPRITEOFFSET]
- add $7
- ld l, a
- ld a, [hl] ; c1x7 (counter until next walk animation frame)
- inc a
- ld [hl], a ; c1x7 += 1
- cp $4
- jr nz, .noNextAnimationFrame
- xor a
- ld [hl], a ; c1x7 = 0
- inc l
- ld a, [hl] ; c1x8 (walk animation frame)
- inc a
- and $3
- ld [hl], a ; advance to next animation frame every 4 ticks (16 ticks total for one step)
+ call Func_5274
.noNextAnimationFrame
ld a, [H_CURRENTSPRITEOFFSET]
add $3
@@ -393,7 +352,7 @@ UpdateSpriteMovementDelay:
ld l, a
ld [hl], $1 ; c1x1 = 1 (mark as ready to move)
notYetMoving:
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $8
ld l, a
@@ -408,7 +367,6 @@ MakeNPCFacePlayer:
ld a, [wd72d]
bit 5, a
jr nz, notYetMoving
-
res 7, [hl]
ld a, [wPlayerDirection]
bit PLAYER_DIR_BIT_UP, a
@@ -445,11 +403,12 @@ InitializeSpriteStatus:
ld a, $8
ld [hli], a ; $c2x2: set Y displacement to 8
ld [hl], a ; $c2x3: set X displacement to 8
+ call InitializeSpriteScreenPosition ; could have done fallthrough here
ret
; calculates the spprite's scrren position form its map position and the player position
InitializeSpriteScreenPosition:
- ld h, $c2
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $4
ld l, a
@@ -457,7 +416,7 @@ InitializeSpriteScreenPosition:
ld b, a
ld a, [hl] ; c2x4 (Y position + 4)
sub b ; relative to player position
- swap a ; * 16
+ call Func_5033
sub $4 ; - 4
dec h
ld [hli], a ; c1x4 (screen Y position)
@@ -466,18 +425,30 @@ InitializeSpriteScreenPosition:
ld b, a
ld a, [hli] ; c2x6 (X position + 4)
sub b ; relative to player position
- swap a ; * 16
+ call Func_5033
dec h
ld [hl], a ; c1x6 (screen X position)
ret
+Func_5033:
+ jr nc, .asm_503c
+ cpl
+ inc a
+ swap a
+ cpl
+ inc a
+ ret
+.asm_503c
+ swap a
+ ret
+
; tests if sprite is off screen or otherwise unable to do anything
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
@@ -525,7 +496,7 @@ CheckSpriteAvailability:
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
@@ -579,7 +550,7 @@ UpdateSpriteImage:
; e: X movement delta (-1, 0 or 1)
; set carry on failure, clears carry on success
CanWalkOntoTile:
- ld h, $c2
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $6
ld l, a
@@ -590,24 +561,16 @@ CanWalkOntoTile:
and a
ret
.notScripted
- ld a, [wTileSetCollisionPtr]
- ld l, a
- ld a, [wTileSetCollisionPtr+1]
- ld h, a
-.tilePassableLoop
- ld a, [hli]
- cp $ff
- jr z, .impassable
- cp c
- jr nz, .tilePassableLoop
- ld h, $c2
+ call _IsTilePassable
+ jr c, .impassable
+ ld h, wSpriteStateData2 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $6
ld l, a
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
@@ -623,17 +586,23 @@ CanWalkOntoTile:
jr nc, .impassable ; don't walk off screen
push de
push bc
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
call DetectCollisionBetweenSprites
+ pop af
+ ld [wUpdateSpritesEnabled], a
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
@@ -642,7 +611,7 @@ CanWalkOntoTile:
jr nz, .upwards
add d
cp $5
- jr c, .impassable ; if c2x2+d < 5, don't go ;bug: this tests probably were supposed to prevent sprites
+ ;jr c, .impassable (bugfix) ; if c2x2+d < 5, don't go ;bug: this tests probably were supposed to prevent sprites
jr .checkHorizontal ; from walking out too far, but this line makes sprites get stuck
.upwards ; whenever they walked upwards 5 steps
sub $1 ; on the other hand, the amount a sprite can walk out to the
@@ -664,7 +633,7 @@ CanWalkOntoTile:
and a ; clear carry (marking success)
ret
.impassable
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
inc a
ld l, a
@@ -690,13 +659,13 @@ CanWalkOntoTile:
; this is always the lower left tile of the 2x2 tile blocks all sprites are snapped to
; hl: output pointer
GetTileSpriteStandsOn:
- ld h, $c1
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
add $4
ld l, a
ld a, [hli] ; c1x4: screen Y position
add $4 ; align to 2*2 tile blocks (Y position is always off 4 pixels to the top)
- and $f0 ; in case object is currently moving
+ and $f8 ; in case object is currently moving (XXX why changed to $f8?)
srl a ; screen Y tile * 4
ld c, a
ld b, $0
@@ -862,20 +831,235 @@ AnimScriptedNPCMovement:
ret
AdvanceScriptedNPCAnimFrameCounter:
+ call Func_5274
+ ld h, wSpriteStateData1 / $100
ld a, [H_CURRENTSPRITEOFFSET]
- add $7
+ add $8
ld l, a
ld a, [hl] ; intra-animation frame counter
+ and $3
+ ld [hSpriteAnimFrameCounter], a
+ ret
+
+Func_5274:
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add $7
+ ld l, a
+ ld h, wSpriteStateData1 / $100
+ ld a, [hl] ; c1x7 (counter until next walk animation frame)
+ inc a
+ and $3
+ ld [hl], a ; c1x7 += 1
+ ret nz ; c1x7 = 0
+ inc l
+ ld a, [hl] ; c1x8 (walk animation frame)
inc a
+ and $3
+ ld [hl], a ; advance to next animation frame every 4 ticks (16 ticks total for one step)
+ ret
+
+Func_5288:
+; nice lookup table
+; a is supposedly [wNPCMovementDirections + $fe]
+ cp $5
+ jr z, .asm_52af
+ cp $4
+ jr z, .asm_52aa
+ cp $6
+ jr z, .asm_52b4
+ cp $7
+ jr z, .asm_52b9
+ cp $11
+ jr z, .asm_52c3
+ cp $12
+ jr z, .asm_52be
+ cp $13
+ jr z, .asm_52c8
+ cp $14
+ jr z, .asm_52cd
+ xor a
+ ret
+; set 1?
+.asm_52aa
+ call Func_531f
+ jr .asm_52e6
+.asm_52af
+ call Func_5325
+ jr .asm_52e6
+.asm_52b4
+ call Func_5331
+ jr .asm_52e6
+.asm_52b9
+ call Func_532b
+ jr .asm_52e6
+; set 2?
+.asm_52be
+ call Func_531f
+ jr .asm_52fa
+.asm_52c3
+ call Func_5325
+ jr .asm_52fa
+.asm_52c8
+ call Func_5331
+ jr .asm_52fa
+.asm_52cd
+ call Func_532b
+ jr .asm_52fa
+; set 3? (unused)
+.asm_52d2
+ call Func_531f
+ jr .asm_530b
+.asm_52d7
+ call Func_5325
+ jr .asm_530b
+.asm_52dc
+ call Func_5331
+ jr .asm_530b
+.asm_52e1
+ call Func_532b
+ jr .asm_530b
+
+.asm_52e6
+ call Func_5337
+ call Func_5349
+ ld a, [H_CURRENTSPRITEOFFSET]
+ ld l, a
+ ld [hl], $8
+ dec h
+ inc l
+ ld [hl], $4
+ call UpdateSpriteImage
+ scf
+ ret
+
+.asm_52fa
+ call Func_5337
+ ld a, [H_CURRENTSPRITEOFFSET]
+ ld l, a
+ ld [hl], $8
+ dec h
+ inc l
+ ld [hl], $3
+ call UpdateSpriteImage
+ scf
+ ret
+
+.asm_530b
+ call Func_5337
+ call Func_5349
+ ld a, [H_CURRENTSPRITEOFFSET]
+ ld l, a
+ ld [hl], $8
+ dec h
+ inc l
+ ld [hl], $3
+ call UpdateSpriteImage
+ scf
+ ret
+
+Func_531f:
+ lb de, 1, 0
+ ld c, SPRITE_FACING_DOWN
+ ret
+
+Func_5325:
+ lb de, -1, 0
+ ld c, SPRITE_FACING_UP
+ ret
+
+Func_532b:
+ lb de, 0, 1
+ ld c, SPRITE_FACING_RIGHT
+ ret
+
+Func_5331:
+ lb de, 0, -1
+ ld c, SPRITE_FACING_LEFT
+ ret
+
+Func_5337:
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add $9
+ ld l, a
+ ld h, wSpriteStateData1 / $100
+ ld [hl], c ; c1x9 (update facing direction)
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add $3
+ ld l, a
+ ld [hl], d ; c1x3 (update Y movement delta)
+ inc l
+ inc l
+ ld [hl], e ; c1x5 (update X movement delta)
+ ret
+
+Func_5349:
+ ld h, wSpriteStateData2 / $100
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add $4
+ ld l, a
+ ld a, [hl] ; c2x4: Y position
+ add d
+ ld [hli], a ; update Y position
+ ld a, [hl] ; c2x5: X position
+ add e
+ ld [hl], a ; update X position
+ ret
+
+Func_5357:
+ call Func_5274
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add $3
+ ld l, a
+ ld h, wSpriteStateData1 / $100
+ ld a, [hli]
+ add a
+ ld b, a
+ ld a, [hl]
+ add b
+ ld [hli], a
+ ld a, [hli]
+ add a
+ ld b, a
+ ld a, [hl]
+ add b
ld [hl], a
- cp 4
+ ld a, [H_CURRENTSPRITEOFFSET]
+ ld l, a
+ ld h, wSpriteStateData2 / $100
+ dec [hl]
ret nz
+ ld a, $6
+ add l
+ ld l, a
+ ld a, [hl]
+ cp $fe
+ jr nc, .asm_5386
+ ld a, [H_CURRENTSPRITEOFFSET]
+ inc a
+ ld l, a
+ ld h, wSpriteStateData1 / $100
+ ld [hl], $1
+ ret
+.asm_5386
+ call Random
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add $8
+ ld l, a
+ ld h, wSpriteStateData2 / $100
+ ld a, [hRandomAdd]
+ and $7f
+ ld [hl], a
+ dec h
+ ld a, [H_CURRENTSPRITEOFFSET]
+ inc a
+ ld l, a
+ ld [hl], $2
+ inc l
+ inc l
xor a
- ld [hl], a ; reset intra-animation frame counter
+ ld b, [hl]
+ ld [hli], a
inc l
- ld a, [hl] ; animation frame counter
- inc a
- and $3
+ ld c, [hl]
ld [hl], a
- ld [hSpriteAnimFrameCounter], a
ret
diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm
index 98d1b7a7..333779fa 100755
--- a/engine/overworld/npc_movement.asm
+++ b/engine/overworld/npc_movement.asm
@@ -37,8 +37,8 @@ _EndNPCMovementScript:
res 1, [hl]
xor a
ld [wNPCMovementScriptSpriteOffset], a
- ld [wNPCMovementScriptPointerTableNum], a
ld [wNPCMovementScriptFunctionNum], a
+ ld [wNPCMovementScriptPointerTableNum], a
ld [wWastedByteCD3A], a
ld [wSimulatedJoypadStatesIndex], a
ld [wSimulatedJoypadStatesEnd], a
@@ -79,6 +79,10 @@ PalletMovementScript_OakMoveLeft:
ld a, $3
ld [wNPCMovementScriptFunctionNum], a
.done
+ ld a, BANK(Music_MuseumGuy)
+ ld c, a
+ ld a, MUSIC_MUSEUM_GUY
+ call PlayMusic
ld hl, wFlags_D733
set 1, [hl]
ld a, $fc
@@ -127,8 +131,9 @@ PalletMovementScript_WalkToLab:
ld [wNPCMovementScriptFunctionNum], a
ret
+
RLEList_ProfOakWalkToLab:
- db NPC_MOVEMENT_DOWN, $05
+ db NPC_MOVEMENT_DOWN, $06 ; differs from red
db NPC_MOVEMENT_LEFT, $01
db NPC_MOVEMENT_DOWN, $05
db NPC_MOVEMENT_RIGHT, $03
@@ -141,7 +146,7 @@ RLEList_PlayerWalkToLab:
db D_RIGHT, $03
db D_DOWN, $05
db D_LEFT, $01
- db D_DOWN, $06
+ db D_DOWN, $07 ; differs from red
db $FF
PalletMovementScript_Done:
@@ -163,11 +168,9 @@ PewterMuseumGuyMovementScriptPointerTable:
PewterMovementScript_WalkToMuseum:
ld a, BANK(Music_MuseumGuy)
- ld [wAudioROMBank], a
- ld [wAudioSavedROMBank], a
+ ld c, a
ld a, MUSIC_MUSEUM_GUY
- ld [wNewSoundID], a
- call PlaySound
+ call PlayMusic
ld a, [wSpriteIndex]
swap a
ld [wNPCMovementScriptSpriteOffset], a
@@ -179,7 +182,7 @@ PewterMovementScript_WalkToMuseum:
ld [wSimulatedJoypadStatesIndex], a
xor a
ld [wWhichPewterGuy], a
- predef PewterGuys
+ call PewterGuys
ld hl, wNPCMovementDirections2
ld de, RLEList_PewterMuseumGuy
call DecodeRLEList
@@ -219,11 +222,9 @@ PewterGymGuyMovementScriptPointerTable:
PewterMovementScript_WalkToGym:
ld a, BANK(Music_MuseumGuy)
- ld [wAudioROMBank], a
- ld [wAudioSavedROMBank], a
+ ld c, a
ld a, MUSIC_MUSEUM_GUY
- ld [wNewSoundID], a
- call PlaySound
+ call PlayMusic
ld a, [wSpriteIndex]
swap a
ld [wNPCMovementScriptSpriteOffset], a
@@ -236,7 +237,7 @@ PewterMovementScript_WalkToGym:
ld [wSimulatedJoypadStatesIndex], a
ld a, 1
ld [wWhichPewterGuy], a
- predef PewterGuys
+ call PewterGuys
ld hl, wNPCMovementDirections2
ld de, RLEList_PewterGymGuy
call DecodeRLEList
@@ -266,27 +267,4 @@ RLEList_PewterGymGuy:
db NPC_MOVEMENT_RIGHT, $03
db $FF
-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
- ld a, [wEngagedTrainerClass]
- ld b, a
-.loop
- ld a, [hli]
- cp $ff
- jr z, .notRival
- cp b
- ret z ; the rival leaves after battling, so don't freeze him
- jr .loop
-.notRival
- ld a, [wSpriteIndex]
- ld [H_SPRITEINDEX], a
- jp SetSpriteMovementBytesToFF
-
-RivalIDs:
- db OPP_SONY1
- db OPP_SONY2
- db OPP_SONY3
- db $ff
+INCLUDE "engine/overworld/pewter_guys.asm"
diff --git a/engine/overworld/npc_movement_2.asm b/engine/overworld/npc_movement_2.asm
new file mode 100755
index 00000000..06ee9319
--- /dev/null
+++ b/engine/overworld/npc_movement_2.asm
@@ -0,0 +1,24 @@
+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
+ ld a, [wEngagedTrainerClass]
+ ld b, a
+.loop
+ ld a, [hli]
+ cp $ff
+ jr z, .notRival
+ cp b
+ ret z ; the rival leaves after battling, so don't freeze him
+ jr .loop
+.notRival
+ ld a, [wSpriteIndex]
+ ld [H_SPRITEINDEX], a
+ jp SetSpriteMovementBytesToFF
+
+RivalIDs:
+ db OPP_SONY1
+ db OPP_SONY2
+ db OPP_SONY3
+ db $ff
diff --git a/engine/overworld/npc_pathfinding.asm b/engine/overworld/npc_pathfinding.asm
new file mode 100644
index 00000000..f3d23b7c
--- /dev/null
+++ b/engine/overworld/npc_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_f76a
+ ld a, [hFindPathFlags]
+ set 0, a ; current end of path matches the player's Y coordinate
+ ld [hFindPathFlags], a
+.asm_f76a
+ ld a, [hFindPathXProgress]
+ ld b, a
+ ld a, [hNPCPlayerXDistance] ; X distance in steps
+ call CalcDifference
+ ld e, a
+ and a
+ jr nz, .asm_f77c
+ ld a, [hFindPathFlags]
+ set 1, a ; current end of path matches the player's X coordinate
+ ld [hFindPathFlags], a
+.asm_f77c
+ ld a, [hFindPathFlags]
+ cp $3 ; has the end of the path reached the player's position?
+ jr z, .done
+; Compare whether the X distance between the player and the current of the path
+; is greater or if the Y distance is. Then, try to reduce whichever is greater.
+ ld a, e
+ cp d
+ jr c, .yDistanceGreater
+; x distance is greater
+ ld a, [hNPCPlayerRelativePosFlags]
+ bit 1, a
+ jr nz, .playerIsLeftOfNPC
+ ld d, NPC_MOVEMENT_RIGHT
+ jr .next1
+.playerIsLeftOfNPC
+ ld d, NPC_MOVEMENT_LEFT
+.next1
+ ld a, [hFindPathXProgress]
+ add 1
+ ld [hFindPathXProgress], a
+ jr .storeDirection
+.yDistanceGreater
+ ld a, [hNPCPlayerRelativePosFlags]
+ bit 0, a
+ jr nz, .playerIsAboveNPC
+ ld d, NPC_MOVEMENT_DOWN
+ jr .next2
+.playerIsAboveNPC
+ ld d, NPC_MOVEMENT_UP
+.next2
+ ld a, [hFindPathYProgress]
+ add 1
+ ld [hFindPathYProgress], a
+.storeDirection
+ ld a, d
+ ld [hli], a
+ ld a, [hFindPathNumSteps]
+ inc a
+ ld [hFindPathNumSteps], a
+ jp .loop
+.done
+ ld [hl], $ff
+ ret
+
+CalcPositionOfPlayerRelativeToNPC:
+ 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/overworld/oaks_aide.asm b/engine/overworld/oaks_aide.asm
index d73174c4..54ba6b7a 100755
--- a/engine/overworld/oaks_aide.asm
+++ b/engine/overworld/oaks_aide.asm
@@ -1,4 +1,4 @@
-OaksAideScript: ; 0x59035
+OaksAideScript:
ld hl, OaksAideHiText
call PrintText
call YesNoChoice
diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm
index 94082beb..5b9831b0 100644
--- a/engine/overworld/oam.asm
+++ b/engine/overworld/oam.asm
@@ -1,12 +1,14 @@
PrepareOAMData:
; Determine OAM data for currently visible
; sprites and write it to wOAMBuffer.
+; Yellow code has been changed to use registers more efficiently
+; as well as tweaking the code to show gbc palettes
ld a, [wUpdateSpritesEnabled]
dec a
jr z, .updateEnabled
- cp 0 - 1
+ cp $ff
ret nz
ld [wUpdateSpritesEnabled], a
jp HideSprites
@@ -18,9 +20,9 @@ PrepareOAMData:
.spriteLoop
ld [hSpriteOffset2], a
- ld d, wSpriteStateData1 / $100
- ld a, [hSpriteOffset2]
ld e, a
+ ld d, wSpriteStateData1 / $100
+
ld a, [de] ; c1x0
and a
jp z, .nextSprite
@@ -40,16 +42,22 @@ PrepareOAMData:
jr c, .usefacing
; unchanging
- and $f
- add $10 ; skip to the second half of the table which doesn't account for facing direction
+ ld a, $0
jr .next
.usefacing
and $f
.next
+; read the entry from the table
+ ld c, a
+ ld b, 0
+ ld hl, SpriteFacingAndAnimationTable
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
ld l, a
-
; get sprite priority
push de
inc d
@@ -61,65 +69,46 @@ PrepareOAMData:
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]
- ld b, a
- ld a, [hli]
- ld h, [hl]
- ld l, a
call GetSpriteScreenXY
ld a, [hOAMBufferOffset]
+ add [hl]
+ cp $a0
+ jr z, .hidden
+ jr nc, .asm_4a41
+.hidden
+ call Func_4a7b
+ ld [wd5cd], a
+ ld a, [hOAMBufferOffset]
+
ld e, a
ld d, wOAMBuffer / $100
.tileLoop
+ ld a, [hli]
+ ld c, a
+.loop
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
+ inc e
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
+ ld [de], a
+ inc hl
inc e
- ld [de], a ; write new sprite OAM X position
- inc e
- 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 a, [wd5cd]
+ add [hl]
+ cp $80
+ jr c, .asm_4a1c
ld b, a
-
- ld a, [wd5cd] ; temp copy of c1x2
- swap a ; high nybble determines sprite used (0 is always player sprite, next are some npcs)
- and $f
-
- ; 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, .notFourTileSprite
- ld a, $a * 12 + 4
- jr .next2
-
-.notFourTileSprite
- ; a *= 12
- sla a
- sla a
- ld c, a
- sla a
- add c
-
-.next2
- add b ; add the tile offset from the table (based on frame and facing direction)
- pop bc
+ ld a, [$fffc]
+ add b
+.asm_4a1c
ld [de], a ; tile id
inc hl
inc e
@@ -129,15 +118,19 @@ PrepareOAMData:
ld a, [hSpritePriority]
or [hl]
.skipPriority
- inc hl
+ and $f0
+ bit 4, a ; OBP0 or OBP1
+ jr z, .spriteusesOBP0
+ or %100 ; palettes 4-7 are OBP1
+.spriteusesOBP0
ld [de], a
+ inc hl
inc e
- bit 0, a ; OAMFLAG_ENDOFDATA
- jr z, .tileLoop
+ dec c
+ jr nz, .loop
ld a, e
ld [hOAMBufferOffset], a
-
.nextSprite
ld a, [hSpriteOffset2]
add $10
@@ -145,26 +138,31 @@ PrepareOAMData:
jp nz, .spriteLoop
; Clear unused OAM.
- ld a, [hOAMBufferOffset]
- ld l, a
- ld h, wOAMBuffer / $100
- ld de, $4
- ld b, $a0
+.asm_4a41
ld a, [wd736]
bit 6, a ; jumping down ledge or fishing animation?
- ld a, $a0
+ ld c, $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
+ ld c, $90
.clear
- cp l
- ret z
+ ld a, [hOAMBufferOffset]
+ cp c
+ ret nc
+ ld l, a
+ ld h, wOAMBuffer / $100
+ ld a, c
+ ld de, $4 ; entry size
+ ld b, $a0
+.clearLoop
ld [hl], b
add hl, de
- jr .clear
+ cp l
+ jr nz, .clearLoop
+ ret
GetSpriteScreenXY:
inc e
@@ -187,3 +185,48 @@ GetSpriteScreenXY:
and $f0
ld [de], a ; c1xb (x)
ret
+
+Func_4a7b:
+ push bc
+ ld a, [wd5cd] ; temp copy of c1x2
+ swap a ; high nybble determines sprite used (0 is always player sprite, next are some npcs)
+ and $f
+
+ ; 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, .notFourTileSprite
+ ld a, $a * 12 + 4 ; $7c
+ jr .done
+
+.notFourTileSprite
+ ; a *= 12
+ add a
+ add a
+ ld c, a
+ add a
+ add c
+.done
+ pop bc
+ ret
+
+INCLUDE "engine/oam_dma.asm"
+
+_IsTilePassable::
+ ld hl,wTilesetCollisionPtr ; pointer to list of passable tiles
+ ld a,[hli]
+ ld h,[hl]
+ ld l,a ; hl now points to passable tiles
+.loop
+ ld a,[hli]
+ cp a,$ff
+ jr z,.tileNotPassable
+ cp c
+ jr nz,.loop
+ xor a
+ ret
+.tileNotPassable
+ scf
+ ret
+
+INCLUDE "data/collision.asm" ; probably
diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm
index f7b63aaa..eea1b375 100755
--- a/engine/overworld/player_animations.asm
+++ b/engine/overworld/player_animations.asm
@@ -9,15 +9,15 @@ EnterMapAnim:
bit 7, [hl] ; used fly out of battle?
res 7, [hl]
jr nz, .flyAnimation
- ld a, SFX_TELEPORT_ENTER_1
+ ld a, $a0 ; (SFX_02_4c - SFX_Headers_02) / 3
call PlaySound
ld hl, wd732
bit 4, [hl] ; used dungeon warp?
- res 4, [hl]
pop hl
+ ;res 4, [hl]
jr nz, .dungeonWarpAnimation
call PlayerSpinWhileMovingDown
- ld a, SFX_TELEPORT_ENTER_2
+ ld a, $a3 ; (SFX_02_4f - SFX_Headers_02) / 3
call PlaySound
call IsPlayerStandingOnWarpPadOrHole
ld a, b
@@ -34,23 +34,24 @@ EnterMapAnim:
ld [hl], $ff ; wPlayerSpinInPlaceAnimSoundID
ld hl, wFacingDirectionList
call PlayerSpinInPlace
+ ld a, $1
+ ld [wPikachuSpawnState], a
.restoreDefaultMusic
call PlayDefaultMusic
.done
+ call Func_151d
jp RestoreFacingDirectionAndYScreenPos
.dungeonWarpAnimation
ld c, 50
call DelayFrames
call PlayerSpinWhileMovingDown
+ ld a, $0
+ ld [wPikachuSpawnState], a
jr .done
.flyAnimation
pop hl
- ld de, BirdSprite
- ld hl, vNPCSprites
- lb bc, BANK(BirdSprite), $0c
- call CopyVideoData
call LoadBirdSpriteGraphics
- ld a, SFX_FLY
+ ld a, $a4 ; SFX_BIRD_FLY
call PlaySound
ld hl, wFlyAnimUsingCoordList
xor a ; is using coord list
@@ -61,6 +62,8 @@ EnterMapAnim:
ld de, FlyAnimationEnterScreenCoords
call DoFlyAnimation
call LoadPlayerSpriteGraphics
+ ld a, $1
+ ld [wPikachuSpawnState], a
jr .restoreDefaultMusic
FlyAnimationEnterScreenCoords:
@@ -90,7 +93,9 @@ PlayerSpinWhileMovingDown:
ld [hl], a ; wPlayerSpinWhileMovingUpOrDownAnimFrameDelay
jp PlayerSpinWhileMovingUpOrDown
+
_LeaveMapAnim:
+ call Func_1510
call InitFacingDirectionList
call IsPlayerStandingOnWarpPadOrHole
ld a, b
@@ -99,7 +104,7 @@ _LeaveMapAnim:
dec a
jp nz, LeaveMapThroughHoleAnim
.spinWhileMovingUp
- ld a, SFX_TELEPORT_EXIT_1
+ ld a, $9f ; (SFX_02_4b - SFX_Headers_02) / 3
call PlaySound
ld hl, wPlayerSpinWhileMovingUpOrDownAnimDeltaY
ld a, -$10
@@ -133,7 +138,7 @@ _LeaveMapAnim:
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayDelta
xor a
ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue
- ld [hl], SFX_TELEPORT_EXIT_2 ; wPlayerSpinInPlaceAnimSoundID
+ ld [hl], $a1 ; SFX_TELEPORT_EXIT_2
ld hl, wFacingDirectionList
call PlayerSpinInPlace
jr .spinWhileMovingUp
@@ -146,7 +151,7 @@ _LeaveMapAnim:
ld [hli], a ; wFlyAnimCounter
ld [hl], $c ; wFlyAnimBirdSpriteImageIndex
call DoFlyAnimation
- ld a, SFX_FLY
+ ld a, $a4 ; SFX_FLY
call PlaySound
ld hl, wFlyAnimUsingCoordList
xor a ; is using coord list
@@ -248,13 +253,15 @@ DoFlyAnimation:
ret
LoadBirdSpriteGraphics:
- ld de, BirdSprite
+ ld de, BirdSprite ; $4d80
+ ld b, BANK(BirdSprite)
+ ld c, $c
ld hl, vNPCSprites
- lb bc, BANK(BirdSprite), $0c
call CopyVideoData
- ld de, BirdSprite + $c0 ; moving animation sprite
+ ld de, BirdSprite + $c0 ; $4e40 ; moving amination sprite
+ ld b, BANK(BirdSprite)
+ ld c, $0c
ld hl, vNPCSprites2
- lb bc, BANK(BirdSprite), $0c
jp CopyVideoData
InitFacingDirectionList:
@@ -385,10 +392,11 @@ FishingAnim:
ld c, 10
call DelayFrames
ld hl, wd736
- set 6, [hl] ; reserve the last 4 OAM entries
- ld de, RedSprite
+ set 6, [hl]
ld hl, vNPCSprites
- lb bc, BANK(RedSprite), $0c
+ ld de, RedSprite ; $4180
+ ld b, BANK(RedSprite)
+ ld c, $c
call CopyVideoData
ld a, $4
ld hl, RedFishingTiles
@@ -414,6 +422,7 @@ FishingAnim:
; there was a bite
; shake the player's sprite vertically
+
ld b, 10
.loop
ld hl, wSpriteStateData1 + 4 ; player's sprite Y screen position
@@ -426,19 +435,17 @@ FishingAnim:
; 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
+ ld a, [wSpriteStateData1 + 2]
cp SPRITE_FACING_UP
jr nz, .skipHidingFishingRod
ld a, $a0
ld [wOAMBuffer + $9c], a
-
.skipHidingFishingRod
ld hl, wEmotionBubbleSpriteIndex
xor a
ld [hli], a ; player's sprite
ld [hl], a ; EXCLAMATION_BUBBLE
predef EmotionBubble
-
; If the player is facing up, unhide the fishing rod.
ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction
cp SPRITE_FACING_UP
@@ -456,7 +463,7 @@ FishingAnim:
call LoadFontTilePatterns
ret
-.ShakePlayerSprite
+.ShakePlayerSprite ; 708a3 (1c:48a3)
ld a, [hl]
xor $1
ld [hl], a
diff --git a/engine/overworld/pokecenter.asm b/engine/overworld/pokecenter.asm
index 3a302d70..1801d9e9 100755
--- a/engine/overworld/pokecenter.asm
+++ b/engine/overworld/pokecenter.asm
@@ -1,4 +1,13 @@
DisplayPokemonCenterDialogue_:
+ ld a, [wCurMap]
+ cp PEWTER_POKECENTER
+ jr nz, .regularCenter
+ call CheckPikachuFollowingPlayer
+ jr z, .regularCenter
+ ld hl, LooksContentText ; if pikachu is sleeping, don't heal
+ call PrintText
+ ret
+.regularCenter
call SaveScreenTilesToBuffer1 ; save screen
ld hl, PokemonCenterWelcomeText
call PrintText
@@ -11,18 +20,36 @@ DisplayPokemonCenterDialogue_:
call PrintText
.skipShallWeHealYourPokemon
call YesNoChoicePokeCenter ; yes/no menu
+ call UpdateSprites
ld a, [wCurrentMenuItem]
and a
- jr nz, .declinedHealing ; if the player chose No
+ jp nz, .declinedHealing ; if the player chose No
call SetLastBlackoutMap
- call LoadScreenTilesFromBuffer1 ; restore screen
+ callab IsStarterPikachuInOurParty
+ jr nc, .notHealingPlayerPikachu
+ call CheckPikachuFollowingPlayer
+ jr nz, .notHealingPlayerPikachu
+ call LoadCurrentMapView
+ call Delay3
+ call UpdateSprites
+ callab PikachuWalksToNurseJoy ; todo
+.notHealingPlayerPikachu
ld hl, NeedYourPokemonText
call PrintText
- ld a, $18
- ld [wSpriteStateData1 + $12], a ; make the nurse turn to face the machine
- call Delay3
- predef HealParty
+ ld c, 64
+ call DelayFrames
+ call CheckPikachuFollowingPlayer
+ jr nz, .playerPikachuNotOnScreen
+ call DisablePikachuOverworldSpriteDrawing
+ callab IsStarterPikachuInOurParty
+ call c, Func_6eaa
+.playerPikachuNotOnScreen
+ lb bc, 1, 8
+ call Func_6ebb
+ ld c, 30
+ call DelayFrames
callba AnimateHealingMachine ; do the healing machine animation
+ predef HealParty
xor a
ld [wAudioFadeOutControl], a
ld a, [wAudioSavedROMBank]
@@ -31,19 +58,69 @@ DisplayPokemonCenterDialogue_:
ld [wLastMusicSoundID], a
ld [wNewSoundID], a
call PlaySound
+ call CheckPikachuFollowingPlayer
+ jr nz, .doNotReturnPikachu
+ callab IsStarterPikachuInOurParty
+ call c, Func_6eaa
+ ld a, $5
+ ld [wPikachuSpawnState], a
+ call EnablePikachuOverworldSpriteDrawing
+.doNotReturnPikachu
+ lb bc, 1, 0
+ call Func_6ebb
ld hl, PokemonFightingFitText
call PrintText
- ld a, $14
- ld [wSpriteStateData1 + $12], a ; make the nurse bow
- ld c, a
+ callab IsStarterPikachuInOurParty
+ jr nc, .notInParty
+ lb bc, 15, 0
+ call Func_6ebb
+.notInParty
+ call LoadCurrentMapView
+ call Delay3
+ call UpdateSprites
+ callab ReloadWalkingTilePatterns
+ ld a, $1
+ ld [H_SPRITEINDEX], a
+ ld a, $1
+ ld [hSpriteImageIndex], a
+ call SpriteFunc_34a1
+ ld c, 40
call DelayFrames
+ call UpdateSprites
+ call LoadFontTilePatterns
jr .done
.declinedHealing
call LoadScreenTilesFromBuffer1 ; restore screen
.done
ld hl, PokemonCenterFarewellText
call PrintText
- jp UpdateSprites
+ call UpdateSprites
+ ret
+
+Func_6eaa:
+ ld a, $1
+ ld [H_SPRITEINDEX], a
+ ld a, $4
+ ld [hSpriteImageIndex], a
+ call SpriteFunc_34a1
+ ld c, 64
+ call DelayFrames
+ ret
+
+Func_6ebb:
+ ld a, b
+ ld [H_SPRITEINDEX], a
+ ld a, c
+ ld [hSpriteImageIndex], a
+ push bc
+ call SetSpriteFacingDirectionAndDelay
+ pop bc
+ ld a, b
+ ld [H_SPRITEINDEX], a
+ ld a, c
+ ld [hSpriteImageIndex], a
+ call SpriteFunc_34a1
+ ret
PokemonCenterWelcomeText:
TX_FAR _PokemonCenterWelcomeText
@@ -66,3 +143,7 @@ PokemonCenterFarewellText:
db $a
TX_FAR _PokemonCenterFarewellText
db "@"
+
+LooksContentText:
+ TX_FAR _LooksContentText
+ db "@"
diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm
index e50c508e..823939b1 100755
--- a/engine/overworld/pokemart.asm
+++ b/engine/overworld/pokemart.asm
@@ -85,7 +85,7 @@ DisplayPokemartDialogue_:
lb bc, 14, 1 ; location that PrintText always prints to, this is useless
call PrintText
coord hl, 14, 7
- lb bc, 08, 15
+ lb bc, 8, 15
ld a,TWO_OPTION_MENU
ld [wTextBoxID],a
call DisplayTextBoxID ; yes/no menu
diff --git a/engine/overworld/print_safari_steps.asm b/engine/overworld/print_safari_steps.asm
new file mode 100644
index 00000000..01dd34e0
--- /dev/null
+++ b/engine/overworld/print_safari_steps.asm
@@ -0,0 +1,36 @@
+PrintSafariZoneSteps:
+ ld a, [wCurMap]
+ cp SAFARI_ZONE_EAST
+ ret c
+ cp UNKNOWN_DUNGEON_2
+ ret nc
+ coord hl, 0, 0
+ lb bc, 3, 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, .numSafariBallsTwoDigits
+ coord hl, 5, 3
+ ld a, " "
+ ld [hl], a
+.numSafariBallsTwoDigits
+ coord hl, 6, 3
+ ld de, wNumSafariBalls
+ lb bc, 1, 2
+ jp PrintNumber
+
+SafariSteps:
+ db "/500@"
+
+SafariBallText:
+ db "BALL×× @"
diff --git a/engine/overworld/replace_tile_block.asm b/engine/overworld/replace_tile_block.asm
new file mode 100644
index 00000000..8577b9e7
--- /dev/null
+++ b/engine/overworld/replace_tile_block.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/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/special_warps.asm b/engine/overworld/special_warps.asm
new file mode 100644
index 00000000..4814e668
--- /dev/null
+++ b/engine/overworld/special_warps.asm
@@ -0,0 +1,147 @@
+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
diff --git a/engine/overworld/ssanne.asm b/engine/overworld/ssanne.asm
index 712c53ed..347dc459 100755
--- a/engine/overworld/ssanne.asm
+++ b/engine/overworld/ssanne.asm
@@ -7,6 +7,7 @@ AnimateBoulderDust:
ld [wUpdateSpritesEnabled], a
ld a, %11100100
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
call LoadSmokeTileFourTimes
callba WriteCutOrBoulderDustAnimationOAMBlock
ld c, 8 ; number of steps in animation
@@ -21,6 +22,7 @@ AnimateBoulderDust:
ld a, [rOBP1]
xor %01100100
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
call Delay3
pop bc
dec c
@@ -30,7 +32,7 @@ AnimateBoulderDust:
jp LoadPlayerSpriteGraphics
GetMoveBoulderDustFunctionPointer:
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
ld hl, MoveBoulderDustFunctionPointerTable
ld c, a
ld b, $0
diff --git a/engine/overworld/step_functions.asm b/engine/overworld/step_functions.asm
new file mode 100644
index 00000000..84b09291
--- /dev/null
+++ b/engine/overworld/step_functions.asm
@@ -0,0 +1,151 @@
+ApplyOutOfBattlePoisonDamage:
+ ld a, [wd730]
+ add a
+ jp c, .noBlackOut ; no black out if joypad states are being simulated
+ ld a, [wd492]
+ bit 7, a
+ jp nz, .noBlackOut
+ ld a, [wd72e]
+ bit 6, a
+ jp nz, .noBlackOut
+ ld a, [wPartyCount]
+ and a
+ jp z, .noBlackOut
+ call IncrementDayCareMonExp
+ call Func_c4c7
+ ld a, [wStepCounter]
+ and $3 ; is the counter a multiple of 4?
+ jp nz, .skipPoisonEffectAndSound ; 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, $d0
+ ld [hSpriteIndexOrTextID], a
+ call DisplayTextID
+ callab IsThisPartymonStarterPikachu_Party
+ jr nc, .curMonNotPlayerPikachu
+ ld e, $3
+ callab PlayPikachuSoundClip
+ calladb_ModifyPikachuHappiness PIKAHAPPY_PSNFNT
+.curMonNotPlayerPikachu
+ 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 InvertBGPal_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, $d1
+ ld [hSpriteIndexOrTextID], a
+ call DisplayTextID
+ ld hl, wd72e
+ set 5, [hl]
+ ld a, $ff
+ jr .done
+.noBlackOut
+ xor a
+.done
+ ld [wOutOfBattleBlackout], a
+ ret
+
+Func_c4c7:
+ ld a, [wStepCounter]
+ and a
+ jr nz, .asm_c4de
+ call Random
+ and $1
+ jr z, .asm_c4de
+ calladb_ModifyPikachuHappiness $6
+.asm_c4de
+ ld hl, wPikachuMood
+ ld a, [hl]
+ cp $80
+ jr z, .asm_c4ef
+ jr c, .asm_c4ea
+ dec a
+ dec a
+.asm_c4ea
+ inc a
+ ld [hl], a
+ cp $80
+ ret nz
+.asm_c4ef
+ xor a
+ ld [wd49c], a
+ ret
diff --git a/engine/overworld/trainers.asm b/engine/overworld/trainers.asm
index 1d0340c9..3ee19e8a 100755
--- a/engine/overworld/trainers.asm
+++ b/engine/overworld/trainers.asm
@@ -4,16 +4,16 @@ _GetSpritePosition1:
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
@@ -28,7 +28,7 @@ _GetSpritePosition2:
inc hl
ld a, [hl] ; c1x6 (screen X pos)
ld [wSavedSpriteScreenX], a
- ld de, $104 - $6
+ ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
add hl, de
ld a, [hli] ; c2x4 (map Y pos)
ld [wSavedSpriteMapY], a
@@ -47,7 +47,7 @@ _SetSpritePosition1:
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
@@ -57,21 +57,21 @@ _SetSpritePosition1:
_SetSpritePosition2:
ld hl, wSpriteStateData1
- ld de, $0004
+ ld de, $4
ld a, [wSpriteIndex]
ld [H_SPRITEINDEX], a
call GetSpriteDataPointer
ld a, [wSavedSpriteScreenY]
- ld [hli], a
+ ld [hli], a ; c1x4 (screen Y pos)
inc hl
ld a, [wSavedSpriteScreenX]
- ld [hl], a
- ld de, $00fe
+ ld [hl], a ; c1x6 (screen X pos)
+ ld de, (wSpriteStateData2 + $4) - (wSpriteStateData1 + $6)
add hl, de
ld a, [wSavedSpriteMapY]
- ld [hli], a
+ ld [hli], a ; c2x4 (map Y pos)
ld a, [wSavedSpriteMapX]
- ld [hl], a
+ ld [hl], a ; c2x5 (map X pos)
ret
TrainerWalkUpToPlayer:
@@ -80,11 +80,11 @@ TrainerWalkUpToPlayer:
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,7 +148,7 @@ TrainerWalkUpToPlayer:
jp MoveSprite_
; input: de = offset within sprite entry
-; output: de = pointer to sprite data
+; output: hl = pointer to sprite data
GetSpriteDataPointer:
push de
add hl, de
@@ -225,7 +225,7 @@ TrainerEngage:
set 0, [hl]
call EngageMapTrainer
ld a, $ff
-.noEngage:
+.noEngage
ld [wTrainerSpriteOffset], a
pop de
pop hl
@@ -239,7 +239,7 @@ ReadTrainerScreenPosition:
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]
add $6
@@ -247,7 +247,7 @@ ReadTrainerScreenPosition:
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl]
+ ld a, [hl] ; c1x6 (sprite X pos)
ld [wTrainerScreenX], a
ret
@@ -262,13 +262,13 @@ CheckSpriteCanSeePlayer:
jr .notInLine ; player too far away
.checkIfLinedUp
ld a, [wTrainerFacingDirection] ; sprite facing direction
- cp $0 ; down
+ cp SPRITE_FACING_DOWN ; down
jr z, .checkXCoord
- cp $4 ; up
+ cp SPRITE_FACING_UP ; up
jr z, .checkXCoord
- cp $8 ; left
+ cp SPRITE_FACING_LEFT ; left
jr z, .checkYCoord
- cp $c ; right
+ cp SPRITE_FACING_RIGHT ; right
jr z, .checkYCoord
jr .notInLine
.checkXCoord
@@ -315,21 +315,21 @@ CheckPlayerIsInFrontOfSprite:
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
diff --git a/engine/overworld/try_pushing_boulder.asm b/engine/overworld/try_pushing_boulder.asm
new file mode 100644
index 00000000..a00790b9
--- /dev/null
+++ b/engine/overworld/try_pushing_boulder.asm
@@ -0,0 +1,107 @@
+TryPushingBoulder:
+ ld a, [wd728]
+ bit 0, a ; using Strength?
+ ret z
+Func_f0a7:
+; where LoadMissableObjects predef points to now
+ 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, [wPlayerFacingDirection] ; 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/palettes.asm b/engine/palettes.asm
index 4785ade2..9418fb72 100755
--- a/engine/palettes.asm
+++ b/engine/palettes.asm
@@ -19,7 +19,7 @@ _RunPaletteCommand:
push de
jp [hl]
-SetPal_BattleBlack:
+SetPal_Black:
ld hl, PalPacket_Black
ld de, BlkPacket_Battle
ret
@@ -30,11 +30,19 @@ SetPal_Battle:
ld de, wPalPacket
ld bc, $10
call CopyData
- ld a, [wPlayerBattleStatus3]
+ ;ld a, [wPlayerBattleStatus3]
ld hl, wBattleMonSpecies
+ ld a, [hl]
+ and a
+ jr z, .asm_71ef9
+ ld hl, wPartyMon1
+ ld a, [wPlayerMonNumber]
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+.asm_71ef9
call DeterminePaletteID
ld b, a
- ld a, [wEnemyBattleStatus3]
+ ;ld a, [wEnemyBattleStatus3]
ld hl, wEnemyMonSpecies2
call DeterminePaletteID
ld c, a
@@ -110,7 +118,7 @@ SetPal_Slots:
ld de, BlkPacket_Slots
ret
-SetPal_TitleScreen:
+SetPal_Titlescreen:
ld hl, PalPacket_Titlescreen
ld de, BlkPacket_Titlescreen
ret
@@ -155,6 +163,10 @@ SetPal_Overworld:
jr z, .Lorelei
cp BRUNOS_ROOM
jr z, .caveOrBruno
+ cp TRADE_CENTER
+ jr z, .trade_center_colosseum
+ cp COLOSSEUM
+ jr z, .trade_center_colosseum
.normalDungeonOrBuilding
ld a, [wLastMap] ; town or route that current dungeon or building is located
.townOrRoute
@@ -169,16 +181,23 @@ SetPal_Overworld:
ld a, SET_PAL_OVERWORLD
ld [wDefaultPaletteCommand], a
ret
+
.PokemonTowerOrAgatha
ld a, PAL_GREYMON - 1
jr .town
+
.caveOrBruno
ld a, PAL_CAVE - 1
jr .town
+
.Lorelei
xor a
jr .town
+.trade_center_colosseum
+ ld a, PAL_GREYMON - 1
+ jr .town
+
; used when a Pokemon is the only thing on the screen
; such as evolution, trading and the Hall of Fame
SetPal_PokemonWholeScreen:
@@ -240,14 +259,24 @@ SetPal_TrainerCard:
ld de, wTrainerCardBlkPacket
ret
+SendUnknownPalPacket_7205d::
+ ld hl, UnknownPalPacket_72811
+ ld de, BlkPacket_WholeScreen
+ ret
+
+SendUnknownPalPacket_72064::
+ ld hl, UnknownPalPacket_72821
+ ld de, UnknownPacket_72751
+ ret
+
SetPalFunctions:
- dw SetPal_BattleBlack
+ dw SetPal_Black
dw SetPal_Battle
dw SetPal_TownMap
dw SetPal_StatusScreen
dw SetPal_Pokedex
dw SetPal_Slots
- dw SetPal_TitleScreen
+ dw SetPal_Titlescreen
dw SetPal_NidorinoIntro
dw SetPal_Generic
dw SetPal_Overworld
@@ -255,6 +284,8 @@ SetPalFunctions:
dw SetPal_PokemonWholeScreen
dw SetPal_GameFreakIntro
dw SetPal_TrainerCard
+ dw SendUnknownPalPacket_7205d
+ dw SendUnknownPalPacket_72064
; The length of the blk data of each badge on the Trainer Card.
; The Rainbow Badge has 3 entries because of its many colors.
@@ -269,9 +300,6 @@ BadgeBlkDataLengths:
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:
ld [wd11e], a
@@ -289,6 +317,132 @@ DeterminePaletteIDOutOfBattle:
ld a, [hl]
ret
+YellowIntroPaletteAction::
+ ld a, e
+ and a
+ jr nz, .asm_720bd
+ ld hl, PalPacket_Generic
+ ld a, [hGBC]
+ and a
+ jp z, SendSGBPacket
+ jp InitGBCPalettes
+
+.asm_720bd
+ ld hl, UnknownPalPacket_72811
+ ld a, [hGBC]
+ and a
+ jp z, SendSGBPacket
+ call InitGBCPalettes
+ ld hl, PalPacket_Generic
+ inc hl
+ ld a, [hli]
+ call GetGBCBasePalAddress
+ ld a, e
+ ld [wGBCBasePalPointers + 2], a
+ ld a, d
+ ld [wGBCBasePalPointers + 2 + 1], a
+ xor a ; CONVERT_BGP
+ call DMGPalToGBCPal
+ ld a, 1
+ call TransferCurBGPData
+ ret
+
+LoadOverworldPikachuFrontpicPalettes::
+ ld hl, PalPacket_Empty
+ ld de, wPalPacket
+ ld bc, $10
+ call CopyData
+ call GetPal_Pikachu
+ ld hl, wPartyMenuBlkPacket
+ ld [hl], a
+ ld hl, wPartyMenuBlkPacket + 2
+ ld a, $26
+ ld [hl], a
+ ld hl, wPalPacket
+ ld a, [hGBC]
+ and a
+ jr nz, .cgb_1
+ call SendSGBPacket
+ jr .okay_1
+
+.cgb_1
+ call InitGBCPalettes
+.okay_1
+ ld hl, BlkPacket_WholeScreen
+ ld de, wPalPacket
+ ld bc, $10
+ call CopyData
+ ld hl, wPartyMenuBlkPacket + 2
+ ld a, $5
+ ld [hli], a
+ ld a, $7
+ ld [hli], a
+ ld a, $6
+ ld [hli], a
+ ld a, $b
+ ld [hli], a
+ ld a, $a
+ ld [hl], a
+ ld hl, wPalPacket
+ ld a, [hGBC]
+ and a
+ jr nz, .cgb_2
+ call SendSGBPacket
+ jr .okay_2
+
+.cgb_2
+ call InitGBCPalettes
+.okay_2
+ ret
+
+GetPal_Pikachu::
+; similar to SetPal_Overworld
+ ld a, [wCurMapTileset]
+ cp CEMETERY
+ jr z, .PokemonTowerOrAgatha
+ cp CAVERN
+ jr z, .caveOrBruno
+ ld a, [wCurMap]
+ cp REDS_HOUSE_1F
+ jr c, .townOrRoute
+ cp UNKNOWN_DUNGEON_2
+ jr c, .normalDungeonOrBuilding
+ cp NAME_RATERS_HOUSE
+ jr c, .caveOrBruno
+ cp LORELEIS_ROOM
+ jr z, .Lorelei
+ cp BRUNOS_ROOM
+ jr z, .caveOrBruno
+ cp TRADE_CENTER
+ jr z, .battleOrTradeCenter
+ cp COLOSSEUM
+ jr z, .battleOrTradeCenter
+.normalDungeonOrBuilding
+ ld a, [wLastMap] ; town or route that current dungeon or building is located
+.townOrRoute
+ cp SAFFRON_CITY + 1
+ jr c, .town
+ ld a, PAL_ROUTE - 1
+.town
+ inc a ; a town's pallete ID is its map ID + 1
+ ret
+
+.PokemonTowerOrAgatha
+ ld a, PAL_GREYMON - 1
+ jr .town
+
+.caveOrBruno
+ ld a, PAL_CAVE - 1
+ jr .town
+
+.Lorelei
+ xor a ; PAL_PALLET - 1
+ jr .town
+
+.battleOrTradeCenter
+ ld a, PAL_GREYMON - 1
+ jr .town
+
InitPartyMenuBlkPacket:
ld hl, BlkPacket_PartyMenu
ld de, wPartyMenuBlkPacket
@@ -324,62 +478,66 @@ UpdatePartyMenuBlkPacket:
ret
SendSGBPacket:
+ ld a, 1
+ ld [hDisableJoypadPolling], a ; don't poll joypad while sending packet
+ call _SendSGBPacket
+ xor a
+ ld [hDisableJoypadPolling], a
+ ret
+
+_SendSGBPacket:
;check number of packets
- ld a,[hl]
- and a,$07
+ ld a, [hl]
+ and a, $07
ret z
; store number of packets in B
- ld b,a
+ ld b, a
.loop2
; save B for later use
push bc
-; 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 [rJOYP],a
+ ld [rJOYP], a
; set P14=HIGH, P15=HIGH
- ld a,$30
- ld [rJOYP],a
+ ld a, $30
+ ld [rJOYP], a
;load length of packets (16 bytes)
- ld b,$10
+ ld b, $10
.nextByte
;set bit counter (8 bits per byte)
- ld e,$08
+ ld e, $08
; get next byte in the packet
- ld a,[hli]
- ld d,a
+ ld a, [hli]
+ ld d, a
.nextBit0
- bit 0,d
-; if 0th bit is not zero set P14=HIGH,P15=LOW (send bit 1)
- ld a,$10
- jr nz,.next0
-; else (if 0th bit is zero) set P14=LOW,P15=HIGH (send bit 0)
- ld a,$20
+ bit 0, d
+; if 0th bit is not zero set P14=HIGH, P15=LOW (send bit 1)
+ ld a, $10
+ jr nz, .next0
+; else (if 0th bit is zero) set P14=LOW, P15=HIGH (send bit 0)
+ ld a, $20
.next0
- ld [rJOYP],a
-; must set P14=HIGH,P15=HIGH between each "pulse"
- ld a,$30
- ld [rJOYP],a
+ ld [rJOYP], a
+; must set P14=HIGH, P15=HIGH between each "pulse"
+ ld a, $30
+ 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)
+; "bit 0, d" to fetch the bit that has to be sent)
rr d
; decrease bit counter so we know when we have sent all 8 bits of current byte
dec e
- jr nz,.nextBit0
+ jr nz, .nextBit0
dec b
- jr nz,.nextByte
+ jr nz, .nextByte
; send bit 1 as a "stop bit" (end of parameter data)
- ld a,$20
- ld [rJOYP],a
-; set P14=HIGH,P15=HIGH
- ld a,$30
- ld [rJOYP],a
- xor a
- ld [hDisableJoypadPolling],a
-; wait for about 70000 cycles
+ ld a, $20
+ ld [rJOYP], a
+; set P14=HIGH, P15=HIGH
+ ld a, $30
+ ld [rJOYP], a
call Wait7000
+; wait for about 70000 cycles
+; call Wait7000
; restore (previously pushed) number of packets
pop bc
dec b
@@ -392,14 +550,17 @@ LoadSGB:
xor a
ld [wOnSGB], a
call CheckSGB
- ret nc
- ld a, 1
- ld [wOnSGB], a
- ld a, [wGBC]
+ jr c, .onSGB
+ ld a, [hGBC]
and a
- jr z, .notGBC
+ jr z, .onDMG
+ ld a, $1
+ ld [wOnSGB], a
+.onDMG
ret
-.notGBC
+.onSGB
+ ld a, $1
+ ld [wOnSGB], a
di
call PrepareSuperNintendoVRAMTransfer
ei
@@ -439,26 +600,21 @@ PrepareSuperNintendoVRAMTransfer:
jr nz, .loop
ret
-.packetPointers
+.packetPointers ; 7225b (1c:625b)
; Only the first packet is needed.
dw MaskEnFreezePacket
- dw DataSnd_72548
- dw DataSnd_72558
- dw DataSnd_72568
- dw DataSnd_72578
- dw DataSnd_72588
- dw DataSnd_72598
- dw DataSnd_725a8
- dw DataSnd_725b8
+ dw DataSnd_728a1
+ dw DataSnd_728b1
+ dw DataSnd_728c1
+ dw DataSnd_728d1
+ dw DataSnd_728e1
+ dw DataSnd_728f1
+ dw DataSnd_72901
+ dw DataSnd_72911
CheckSGB:
-; Returns whether the game is running on an SGB in carry.
ld hl, MltReq2Packet
- di
call SendSGBPacket
- ld a, 1
- ld [hDisableJoypadPolling], a
- ei
call Wait7000
ld a, [rJOYP]
and $3
@@ -514,6 +670,7 @@ CopyGfxToSuperNintendoVRAM:
call DisableLCD
ld a, $e4
ld [rBGP], a
+ call _UpdateGBCPal_BGP_CheckDMG
ld de, vChars1
ld a, [wCopyingSGBTileData]
and a
@@ -544,6 +701,7 @@ CopyGfxToSuperNintendoVRAM:
call SendSGBPacket
xor a
ld [rBGP], a
+ call _UpdateGBCPal_BGP_CheckDMG
ei
ret
@@ -561,13 +719,17 @@ Wait7000:
ret
SendSGBPackets:
- ld a, [wGBC]
+ ld a, [hGBC]
and a
jr z, .notGBC
push de
call InitGBCPalettes
pop hl
- call EmptyFunc5
+ call InitGBCPalettes
+ ld a, [rLCDC]
+ and rLCDC_ENABLE_MASK
+ ret z
+ call Delay3
ret
.notGBC
push de
@@ -576,30 +738,349 @@ SendSGBPackets:
jp SendSGBPacket
InitGBCPalettes:
- ld a, $80 ; index 0 with auto-increment
- ld [rBGPI], a
- inc hl
- ld c, $20
-.loop
- ld a, [hli]
+ ld a, [hl]
+ and $f8
+ cp $20
+ jp z, TranslatePalPacketToBGMapAttributes
+
inc hl
+
+index = 0
+
+ REPT NUM_ACTIVE_PALS
+ IF index > 0
+ pop hl
+ ENDC
+
+ ld a, [hli]
+ inc hl
+
+ IF index < (NUM_ACTIVE_PALS + -1)
+ push hl
+ ENDC
+
+ call GetGBCBasePalAddress
+ ld a, e
+ ld [wGBCBasePalPointers + index * 2], a
+ ld a, d
+ ld [wGBCBasePalPointers + index * 2 + 1], a
+
+ xor a ; CONVERT_BGP
+ call DMGPalToGBCPal
+ ld a, index
+ call TransferCurBGPData
+
+ ld a, CONVERT_OBP0
+ call DMGPalToGBCPal
+ ld a, index
+ call TransferCurOBPData
+
+ ld a, CONVERT_OBP1
+ call DMGPalToGBCPal
+ ld a, index + 4
+ call TransferCurOBPData
+
+index = index + 1
+ ENDR
+
+ ret
+
+GetGBCBasePalAddress::
+; Input: a = palette ID
+; Output: de = palette address
+ push hl
+ ld l, a
+ xor a
+ ld h, a
+ add hl, hl
+ add hl, hl
+ add hl, hl
+ ld de, GBCBasePalettes
+ add hl, de
+ ld a, l
+ ld e, a
+ ld a, h
+ ld d, a
+ pop hl
+ ret
+
+DMGPalToGBCPal::
+; Populate wGBCPal with colors from a base palette, selected using one of the
+; DMG palette registers.
+; Input:
+; a = which DMG palette register
+; de = address of GBC base palette
+ and a
+ jr nz, .notBGP
+ ld a, [rBGP]
+ ld [wLastBGP], a
+ jr .convert
+.notBGP
+ dec a
+ jr nz, .notOBP0
+ ld a, [rOBP0]
+ ld [wLastOBP0], a
+ jr .convert
+.notOBP0
+ ld a, [rOBP1]
+ ld [wLastOBP1], a
+.convert
+color_index = 0
+ REPT NUM_COLORS
+ ld b, a
+ and %11
+ call .GetColorAddress
+ ld a, [hli]
+ ld [wGBCPal + color_index * 2], a
+ ld a, [hl]
+ ld [wGBCPal + color_index * 2 + 1], a
+
+ IF color_index < (NUM_COLORS + -1)
+ ld a, b
+ rrca
+ rrca
+ ENDC
+
+color_index = color_index + 1
+ ENDR
+ ret
+
+.GetColorAddress:
+ add a
+ ld l, a
+ xor a
+ ld h, a
+ add hl, de
+ ret
+
+TransferCurBGPData::
+ push de
add a
add a
add a
- ld de, SuperPalettes
- add e
- jr nc, .noCarry
- inc d
-.noCarry
+ or $80 ; auto-increment
+ ld [rBGPI], a
+ ld de, rBGPD
+ ld hl, wGBCPal
+ ld b, %10 ; mask for non-V-blank/non-H-blank STAT mode
+ ld a, [rLCDC]
+ and rLCDC_ENABLE_MASK
+ jr nz, .lcdEnabled
+ rept NUM_COLORS
+ call TransferPalColorLCDDisabled
+ endr
+ jr .done
+.lcdEnabled
+ rept NUM_COLORS
+ call TransferPalColorLCDEnabled
+ endr
+.done
+ pop de
+ ret
+
+BufferBGPPal::
+; Copy wGBCPal to palette a in wBGPPalsBuffer.
+ push de
+ add a
+ add a
+ add a
+ ld l, a
+ xor a
+ ld h, a
+ ld de, wBGPPalsBuffer
+ add hl, de
+ ld de, wGBCPal
+ ld c, PAL_SIZE
+.loop
ld a, [de]
- ld [rBGPD], a
+ ld [hli], a
+ inc de
dec c
jr nz, .loop
+ pop de
ret
-EmptyFunc5:
+TransferBGPPals::
+; Transfer the buffered BG palettes.
+ ld a, [rLCDC]
+ and rLCDC_ENABLE_MASK
+ jr z, .lcdDisabled
+ di
+.waitLoop
+ ld a, [rLY]
+ cp 144
+ jr c, .waitLoop
+.lcdDisabled
+ call .DoTransfer
+ ei
ret
+.DoTransfer:
+ xor a
+ or $80 ; auto-increment
+ ld [rBGPI], a
+ ld de, rBGPD
+ ld hl, wBGPPalsBuffer
+ ld c, 4 * PAL_SIZE
+.loop
+ ld a, [hli]
+ ld [de], a
+ dec c
+ jr nz, .loop
+ ret
+
+TransferCurOBPData:
+ push de
+ add a
+ add a
+ add a
+ or $80 ; auto-increment
+ ld [rOBPI], a
+ ld de, rOBPD
+ ld hl, wGBCPal
+ ld b, %10 ; mask for non-V-blank/non-H-blank STAT mode
+ ld a, [rLCDC]
+ and rLCDC_ENABLE_MASK
+ jr nz, .lcdEnabled
+ rept NUM_COLORS
+ call TransferPalColorLCDDisabled
+ endr
+ jr .done
+.lcdEnabled
+ rept NUM_COLORS
+ call TransferPalColorLCDEnabled
+ endr
+.done
+ pop de
+ ret
+
+TransferPalColorLCDEnabled:
+; Transfer a palette color while the LCD is enabled.
+
+; In case we're already in H-blank or V-blank, wait for it to end. This is a
+; precaution so that the transfer doesn't extend past the blanking period.
+ ld a, [rSTAT]
+ and b
+ jr z, TransferPalColorLCDEnabled
+
+; Wait for H-blank or V-blank to begin.
+.notInBlankingPeriod
+ ld a, [rSTAT]
+ and b
+ jr nz, .notInBlankingPeriod
+; fall through
+
+TransferPalColorLCDDisabled:
+; Transfer a palette color while the LCD is disabled.
+ ld a, [hli]
+ ld [de], a
+ ld a, [hli]
+ ld [de], a
+ ret
+
+_UpdateGBCPal_BGP_CheckDMG::
+ ld a, [hGBC]
+ and a
+ ret z
+; fall through
+
+_UpdateGBCPal_BGP::
+index = 0
+
+ REPT NUM_ACTIVE_PALS
+ ld a, [wGBCBasePalPointers + index * 2]
+ ld e, a
+ ld a, [wGBCBasePalPointers + index * 2 + 1]
+ ld d, a
+ xor a ; CONVERT_BGP
+ call DMGPalToGBCPal
+ ld a, index
+ call BufferBGPPal
+
+index = index + 1
+ ENDR
+
+ call TransferBGPPals
+ ret
+
+_UpdateGBCPal_OBP::
+index = 0
+
+ REPT NUM_ACTIVE_PALS
+ ld a, [wGBCBasePalPointers + index * 2]
+ ld e, a
+ ld a, [wGBCBasePalPointers + index * 2 + 1]
+ ld d, a
+ ld a, c
+ call DMGPalToGBCPal
+ ld a, c
+ dec a
+ rlca
+ rlca
+
+ IF index > 0
+ IF index == 1
+ inc a
+ ELSE
+ add index
+ ENDC
+ ENDC
+
+ call TransferCurOBPData
+
+index = index + 1
+ ENDR
+
+ ret
+
+TranslatePalPacketToBGMapAttributes::
+; translate the SGB pal packets into something usable for the GBC
+ push hl
+ pop de
+ ld hl, PalPacketPointers
+ ld a, [hli]
+ ld c, a
+.loop
+ ld a, e
+.innerLoop
+ cp [hl]
+ jr z, .checkHighByte
+ inc hl
+ inc hl
+ dec c
+ jr nz, .innerLoop
+ ret
+.checkHighByte
+; the low byte of pointer matched, so check the high byte
+ inc hl
+ ld a, d
+ cp [hl]
+ jr z, .foundMatchingPointer
+ inc hl
+ dec c
+ jr nz, .loop
+ ret
+.foundMatchingPointer
+ callba LoadBGMapAttributes
+ ret
+
+PalPacketPointers::
+ db (palPacketPointersEnd - palPacketPointers) / 2
+palPacketPointers
+ dw BlkPacket_WholeScreen
+ dw BlkPacket_Battle
+ dw BlkPacket_StatusScreen
+ dw BlkPacket_Pokedex
+ dw BlkPacket_Slots
+ dw BlkPacket_Titlescreen
+ dw BlkPacket_NidorinoIntro
+ dw wPartyMenuBlkPacket
+ dw wTrainerCardBlkPacket
+ dw BlkPacket_GameFreakIntro
+ dw wPalPacket
+ dw UnknownPacket_72751
+palPacketPointersEnd
+
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
@@ -607,9 +1088,7 @@ CopySGBBorderTiles:
; 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
diff --git a/engine/pikachu_emotions.asm b/engine/pikachu_emotions.asm
new file mode 100755
index 00000000..8702bc3f
--- /dev/null
+++ b/engine/pikachu_emotions.asm
@@ -0,0 +1,421 @@
+IsPlayerTalkingToPikachu:
+ ld a, [wd436]
+ and a
+ ret z
+ ld a, [hSpriteIndexOrTextID]
+ cp $f
+ ret nz
+ call InitializePikachuTextID
+ xor a
+ ld [hSpriteIndexOrTextID], a
+ ld [wd436], a
+ ret
+
+InitializePikachuTextID:
+ ld a, $d4 ; display
+ ld [hSpriteIndexOrTextID], a
+ xor a
+ ld [wPlayerMovingDirection], a
+ ld a, $1
+ ld [wAutoTextBoxDrawingControl], a
+ call DisplayTextID
+ xor a
+ ld [wAutoTextBoxDrawingControl], a
+ ret
+
+DoStarterPikachuEmotions:
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+.loop
+ ld a, [de]
+ inc de
+ cp $ff
+ jr z, .done
+ ld c, a
+ ld b, 0
+ ld hl, StarterPikachuEmotionsJumptable
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call JumpToAddress
+ jr .loop
+
+.done
+ ret
+
+StarterPikachuEmotionsJumptable:
+ dw StarterPikachuEmotionCommand_nop ; 0
+ dw StarterPikachuEmotionCommand_text ; 1
+ dw StarterPikachuEmotionCommand_pcm ; 2
+ dw StarterPikachuEmotionCommand_emote ; 3
+ dw StarterPikachuEmotionCommand_movement ; 4
+ dw StarterPikachuEmotionCommand_pikapic ; 5
+ dw StarterPikachuEmotionCommand_subcmd ; 6
+ dw StarterPikachuEmotionCommand_delay ; 7
+ dw StarterPikachuEmotionCommand_nop2 ; 8
+ dw StarterPikachuEmotionCommand_9 ; 9
+ dw StarterPikachuEmotionCommand_nop3 ; a
+
+StarterPikachuEmotionCommand_nop:
+StarterPikachuEmotionCommand_nop3:
+ ret
+
+StarterPikachuEmotionCommand_text:
+ ld a, [de]
+ ld l, a
+ inc de
+ ld a, [de]
+ ld h, a
+ inc de
+ push de
+ call PrintText
+ pop de
+ ret
+
+StarterPikachuEmotionCommand_pcm:
+ ld a, [de]
+ inc de
+ push de
+ ld e, a
+ nop
+ call PlayPikachuSoundClip_
+ pop de
+ ret
+
+PlayPikachuSoundClip_:
+ cp $ff
+ ret z
+ callab PlayPikachuSoundClip
+ ret
+
+StarterPikachuEmotionCommand_emote:
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ ld a, [de]
+ inc de
+ push de
+ call ShowPikachuEmoteBubble
+ pop de
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ ret
+
+ShowPikachuEmoteBubble:
+ ld [wWhichEmotionBubble], a
+ ld a, $f ; Pikachu
+ ld [wEmotionBubbleSpriteIndex], a
+ predef EmotionBubble
+ ret
+
+StarterPikachuEmotionCommand_movement:
+ ld a, [de]
+ inc de
+ ld l, a
+ ld a, [de]
+ inc de
+ ld h, a
+ push de
+ ld b, BANK(DoStarterPikachuEmotions)
+ call ApplyPikachuMovementData_
+ pop de
+ ret
+
+StarterPikachuEmotionCommand_delay:
+ ld a, [de]
+ inc de
+ push de
+ ld c, a
+ call DelayFrames
+ pop de
+ ret
+
+StarterPikachuEmotionCommand_subcmd:
+ ld a, [de]
+ inc de
+ push de
+ ld e, a
+ ld d, 0
+ ld hl, .Subcommands
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call JumpToAddress
+ pop de
+ ret
+
+.Subcommands:
+ dw LoadPikachuSpriteIntoVRAM
+ dw LoadFontTilePatterns
+ dw Pikachu_LoadCurrentMapViewUpdateSpritesAndDelay3
+ dw WaitForTextScrollButtonPress
+ dw PikachuPewterPokecenterCheck
+ dw PikachuFanClubCheck
+ dw PikachuBillsHouseCheck
+
+StarterPikachuEmotionCommand_nop2:
+ ret
+
+StarterPikachuEmotionCommand_9:
+ push de
+ call StarterPikachuEmotionCommand_turnawayfromplayer
+ call UpdateSprites
+ pop de
+ ret
+
+StarterPikachuEmotionCommand_turnawayfromplayer:
+ ld a, [wPlayerFacingDirection]
+ xor $4
+ ld [wPikachuFacingDirection], a
+ ret
+
+DeletedFunction_fcffb:
+; Inexplicably empty.
+ rept 5
+ nop
+ endr
+ ret
+
+PlaySpecificPikachuEmotion:
+ ld a, e
+ jr load_expression
+
+TalkToPikachu:
+ call MapSpecificPikachuExpression
+ jr c, load_expression
+ call GetPikaPicAnimationScriptIndex
+ call DeletedFunction_fcffb
+load_expression:
+ ld [wExpressionNumber], a
+ ld hl, PikachuEmotionTable
+ call DoStarterPikachuEmotions
+ ret
+
+PikachuEmotionTable:
+pikaemotion_def: MACRO
+\1_id: dw \1
+ endm
+
+ pikaemotion_def PikachuEmotion0
+ pikaemotion_def PikachuEmotion1
+ pikaemotion_def PikachuEmotion2
+ pikaemotion_def PikachuEmotion3
+ pikaemotion_def PikachuEmotion4
+ pikaemotion_def PikachuEmotion5
+ pikaemotion_def PikachuEmotion6
+ pikaemotion_def PikachuEmotion7
+ pikaemotion_def PikachuEmotion8
+ pikaemotion_def PikachuEmotion9
+ pikaemotion_def PikachuEmotion10
+ pikaemotion_def PikachuEmotion11
+ pikaemotion_def PikachuEmotion12
+ pikaemotion_def PikachuEmotion13
+ pikaemotion_def PikachuEmotion14
+ pikaemotion_def PikachuEmotion15
+ pikaemotion_def PikachuEmotion16
+ pikaemotion_def PikachuEmotion17
+ pikaemotion_def PikachuEmotion18
+ pikaemotion_def PikachuEmotion19
+ pikaemotion_def PikachuEmotion20
+ pikaemotion_def PikachuEmotion21 ; used a fishing rod
+ pikaemotion_def PikachuEmotion22
+ pikaemotion_def PikachuEmotion23
+ pikaemotion_def PikachuEmotion24
+ pikaemotion_def PikachuEmotion25
+ pikaemotion_def PikachuEmotion26 ; wake up pikachu in pewter pokemon center
+ pikaemotion_def PikachuEmotion27
+ pikaemotion_def PikachuEmotion28
+ pikaemotion_def PikachuEmotion29
+ pikaemotion_def PikachuEmotion30
+ pikaemotion_def PikachuEmotion31
+ pikaemotion_def PikachuEmotion32
+ pikaemotion_def PikachuEmotion33
+
+PikachuEmotion33:
+ db $ff
+
+MapSpecificPikachuExpression:
+ ld a, [wCurMap]
+ cp POKEMON_FAN_CLUB
+ jr nz, .notFanClub
+ ld hl, wd492
+ bit 7, [hl]
+ ldpikaemotion a, PikachuEmotion29
+ jr z, .play_emotion
+ call CheckPikachuFollowingPlayer
+ ldpikaemotion a, PikachuEmotion30
+ jr nz, .play_emotion
+ jr .check_pikachu_status
+
+.notFanClub
+ ld a, [wCurMap]
+ cp PEWTER_POKECENTER
+ jr nz, .notPewterPokecenter
+ call CheckPikachuFollowingPlayer
+ ldpikaemotion a, PikachuEmotion26
+ jr nz, .play_emotion
+ jr .check_pikachu_status
+
+.notPewterPokecenter
+ callab Func_f24ae
+ ld a, e
+ cp $ff
+ jr nz, .play_emotion
+ jr .check_pikachu_status ; useless
+
+.check_pikachu_status
+ call IsPlayerPikachuAsleepInParty
+ ldpikaemotion a, PikachuEmotion11
+ jr c, .play_emotion
+ callab CheckPikachuFaintedOrStatused ; same bank
+ ldpikaemotion a, PikachuEmotion28
+ jr c, .play_emotion
+ ld a, [wCurMap]
+ cp POKEMONTOWER_1
+ jr c, .notInLavenderTower
+ cp POKEMONTOWER_7 + 1
+ ldpikaemotion a, PikachuEmotion22
+ jr c, .play_emotion
+.notInLavenderTower
+ ld a, [wd49c]
+ and a
+ jr z, .mood_based_emotion
+ dec a
+ ld c, a
+ ld b, $0
+ ld hl, .Emotions
+ add hl, bc
+ ld a, [hl]
+ jr .play_emotion
+
+.mood_based_emotion
+ and a
+ ret
+
+.play_emotion
+ scf
+ ret
+
+.Emotions:
+ dpikaemotion PikachuEmotion18
+ dpikaemotion PikachuEmotion21
+ dpikaemotion PikachuEmotion23
+ dpikaemotion PikachuEmotion24
+ dpikaemotion PikachuEmotion25
+
+IsPlayerPikachuAsleepInParty:
+ xor a
+ ld [wWhichPokemon], a
+.loop
+ ld a, [wWhichPokemon]
+ ld c, a
+ ld b, 0
+ ld hl, wPartySpecies
+ add hl, bc
+ ld a, [hl]
+ cp $ff
+ jr z, .done
+ cp PIKACHU
+ jr nz, .curMonNotStarterPikachu
+ callab IsThisPartymonStarterPikachu
+ jr nc, .curMonNotStarterPikachu
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMon1Status
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld a, [hl]
+ and SLP
+ jr z, .done
+ jr .curMonSleepingPikachu
+
+.curMonNotStarterPikachu
+ ld a, [wWhichPokemon]
+ cp PARTY_LENGTH - 1
+ jr z, .done
+ inc a
+ ld [wWhichPokemon], a
+ jr .loop
+
+.curMonSleepingPikachu
+ scf
+ ret
+
+.done
+ and a
+ ret
+
+INCLUDE "data/pikachu_emotions.asm"
+
+PikachuWalksToNurseJoy:
+ ld a, $40
+ ld [h_0xFFFC], a
+ call LoadPikachuSpriteIntoVRAM
+ call .GetMovementData
+ and a
+ jr z, .skip
+ call ApplyPikachuMovementData
+.skip
+ xor a
+ ld [h_0xFFFC], a
+ ret
+
+.GetMovementData:
+ ld a, [wPikachuMapY]
+ ld e, a
+ ld a, [wPikachuMapX]
+ ld d, a
+ ld a, [wYCoord]
+ add 4
+ cp e
+ jr z, .pikachu_at_same_y_as_player
+ jr nc, .pikachu_above_player
+ ld hl, .PikaMovementData1
+ ld a, 1
+ ret
+
+.pikachu_above_player
+ xor a
+ ret
+
+.pikachu_at_same_y_as_player
+ ld a, [wXCoord]
+ add 4
+ cp d
+ jr c, .pikachu_to_right_of_player
+ ld hl, .PikaMovementData2
+ ld a, 2
+ ret
+
+.pikachu_to_right_of_player
+ ld hl, .PikaMovementData3
+ ld a, 3
+ ret
+
+.PikaMovementData1:
+ db $00 ; init
+ db $36 ; look up
+ db $2b ; walk up left
+ db $34 ; hop up right
+ db $3f ; ret
+
+.PikaMovementData2:
+ db $00 ; init
+ db $36 ; look up
+ db $34 ; hop up right
+ db $3f ; ret
+
+.PikaMovementData3:
+ db $00 ; init
+ db $36 ; look up
+ db $33 ; hop up left
+ db $3f ; ret
diff --git a/engine/pikachu_follow.asm b/engine/pikachu_follow.asm
new file mode 100755
index 00000000..b5791919
--- /dev/null
+++ b/engine/pikachu_follow.asm
@@ -0,0 +1,1578 @@
+ShouldPikachuSpawn::
+; possibly to test if pika should be out?
+ ld a, [wPikachuOverworldStateFlags]
+ bit 5, a
+ jr nz, .hide ; 3f:44f8
+ ld a, [wPikachuOverworldStateFlags]
+ bit 7, a
+ jr nz, .hide
+ call IsStarterPikachuInOurParty
+ jr nc, .hide
+ ld a, [wWalkBikeSurfState]
+ and a
+ jr nz, .hide
+ scf
+ ret
+
+.hide
+ and a
+ ret
+
+SchedulePikachuSpawnForAfterText::
+ ld hl, wPikachuOverworldStateFlags
+ bit 4, [hl]
+ res 4, [hl]
+ jr nz, .normal_spawn_state
+ call EnablePikachuFollowingPlayer
+ call ClearPikachuSpriteStateData
+ ld a, $ff
+ ld [wPikachuSpriteImageIdx], a
+ call ClearPikachuFollowCommandBuffer
+ call CalculatePikachuFacingDirection
+ ret
+
+.normal_spawn_state
+ call CalculatePikachuPlacementCoords
+ xor a
+ ld [wPikachuSpawnState], a
+ ld a, [wPlayerFacingDirection]
+ ld [wPikachuFacingDirection], a
+ ret
+
+ClearPikachuSpriteStateData::
+ ld hl, wPikachuPictureID
+ call .clear
+ ld hl, wPikachuSpriteStateData2
+.clear
+ ld bc, $10
+ xor a
+ call FillMemory
+ ret
+
+CalculatePikachuSpawnCoordsAndFacing::
+ call CalculatePikachuPlacementCoords
+ call CalculatePikachuFacingDirection
+ xor a
+ ld [wPikachuSpawnState], a
+ ret
+
+CalculatePikachuPlacementCoords::
+ ld bc, wPikachuPictureID
+ ld a, [wYCoord]
+ add $4
+ ld e, a
+ ld a, [wXCoord]
+ add $4
+ ld d, a
+ ld a, [wPikachuSpawnState]
+ and a
+ jr z, .load_coords
+ cp $1
+ jr z, .right_of_player
+ cp $2
+ jr z, .check_player_facing2
+ cp $3
+ jr z, .load_coords
+ cp $4
+ jr z, .below_player
+ cp $5
+ jr z, .above_player
+ cp $6
+ jr z, .left_of_player
+ cp $7
+ jr z, .check_player_facing
+ jr .right_of_player
+
+.check_player_facing
+ ld a, [wPlayerFacingDirection]
+ and a ; SPRITE_FACING_DOWN
+ jr z, .below_player
+ cp SPRITE_FACING_UP
+ jr z, .above_player
+ cp SPRITE_FACING_LEFT
+ jr z, .left_of_player
+ cp SPRITE_FACING_RIGHT
+ jr z, .right_of_player
+.check_player_facing2
+ ld a, [wPlayerFacingDirection]
+ and a
+ jr nz, .check_up
+ dec e
+ jr .load_coords
+
+.check_up
+ cp SPRITE_FACING_UP
+ jr nz, .check_left
+ inc e
+ jr .load_coords
+
+.check_left
+ cp SPRITE_FACING_LEFT
+ jr nz, .left_of_player_2
+ inc d
+ jr .load_coords
+
+.left_of_player_2
+ dec d
+ jr .load_coords
+
+.right_of_player
+ inc d
+ jr .load_coords
+
+.left_of_player
+ dec d
+ jr .load_coords
+
+.below_player
+ inc e
+ jr .load_coords
+
+.above_player
+ dec e
+ jr .load_coords ; useless jr
+.load_coords
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
+ add hl, bc
+ ld [hl], e
+ inc hl
+ ld [hl], d
+ inc hl
+ ld [hl], $fe
+ push hl
+ ld hl, wd472
+ set 5, [hl]
+ pop hl
+ ret
+
+CalculatePikachuFacingDirection::
+ ld a, $49
+ ld [wPikachuPictureID], a
+ ld a, $ff
+ ld [wPikachuSpriteImageIdx], a
+ ld a, [wPikachuSpawnState]
+ and a
+ jr z, .copy_player_facing
+ cp $1
+ jr z, .copy_player_facing
+ cp $3
+ jr z, .force_facing_down
+ cp $4
+ jr z, .copy_player_facing
+ cp $6
+ jr z, .copy_player_facing
+ cp $7
+ jr z, .face_the_other_way
+ call ComputePikachuFacingDirection
+ ret
+
+.copy_player_facing
+ ld a, [wPlayerFacingDirection]
+ ld [wPikachuFacingDirection], a
+ ret
+
+.force_facing_down
+ ld a, SPRITE_FACING_DOWN
+ ld [wPikachuFacingDirection], a
+ ret
+
+.face_the_other_way
+ ld a, [wPlayerFacingDirection]
+ xor $4
+ ld [wPikachuFacingDirection], a
+ ret
+
+CalculatePikachuSpawnState1::
+ ld a, [wCurMap]
+ cp OAKS_LAB
+ jr z, .oaks_lab
+ cp ROUTE_22_GATE
+ jr z, .route_22_gate
+ cp MT_MOON_2
+ jr z, .mt_moon_2
+ cp ROCK_TUNNEL_1
+ jr z, .rock_tunnel_1
+ ld a, [wCurMap]
+ ld hl, Pointer_fc64b
+ call Pikachu_IsInArray ; similar to IsInArray, but not the same
+ jr c, .map_list_1
+ ld a, [wCurMap]
+ ld hl, Pointer_fc653
+ call Pikachu_IsInArray
+ jr nc, .not_map_list_2
+ ld a, [wPlayerFacingDirection]
+ and a
+ jr nz, .not_map_list_2
+ ld a, $3
+ jr .load
+
+.route_22_gate
+ ld a, [wPlayerFacingDirection]
+ and a
+ jr z, .rock_tunnel_1
+ jr .not_map_list_2
+
+.mt_moon_2
+ ld a, $3
+ jr .load
+
+.map_list_1
+ ld a, $4
+ jr .load
+
+.oaks_lab
+ ld a, $6
+ jr .load
+
+.not_map_list_2
+ ld a, $1
+ jr .load
+
+.rock_tunnel_1
+ ld a, $3
+.load
+ ld [wPikachuSpawnState], a
+ ret
+
+Pointer_fc64b::
+ db VICTORY_ROAD_2
+ db ROUTE_7_GATE
+ db ROUTE_8_GATE
+ db ROUTE_16_GATE_1F
+ db ROUTE_18_GATE_1F
+ db ROUTE_15_GATE_1F
+ db ROUTE_11_GATE_1F
+ db $ff
+
+Pointer_fc653::
+ db VIRIDIAN_FOREST_EXIT
+ db CERULEAN_HOUSE_2
+ db TRASHED_HOUSE
+ db VERMILION_DOCK
+ db CELADON_MANSION_1
+ db ROUTE_2_GATE
+ db FUCHSIA_HOUSE_3
+ db $ff
+
+CalculatePikachuSpawnState2::
+ ld a, [wCurMap]
+ cp VIRIDIAN_FOREST_EXIT
+ jr z, .viridian_forest_exit
+ cp VIRIDIAN_FOREST_ENTRANCE
+ jr z, .viridian_forest_entrance
+ ld a, [wCurMap]
+ ld hl, Pointer_fc68e
+ call Pikachu_IsInArray
+ jr c, .in_array
+ jr .not_in_array
+
+.viridian_forest_exit
+ ld a, [wPlayerFacingDirection]
+ cp SPRITE_FACING_UP
+ jr z, .in_array
+ jr .not_in_array
+
+.viridian_forest_entrance
+ ld a, [wPlayerFacingDirection]
+ and a ; SPRITE_FACING_DOWN
+ jr z, .not_in_array
+ jr .in_array
+
+.not_in_array
+ ld a, $0
+ jr .load_spawn_state
+
+.in_array
+ ld a, $1
+.load_spawn_state
+ ld [wPikachuSpawnState], a
+ ret
+
+Pointer_fc68e::
+ db VIRIDIAN_FOREST
+ db SAFARI_ZONE_REST_HOUSE_1
+ db SAFARI_ZONE_REST_HOUSE_2
+ db SAFARI_ZONE_REST_HOUSE_3
+ db SAFARI_ZONE_REST_HOUSE_4
+ db SAFARI_ZONE_SECRET_HOUSE
+ db SILPH_CO_ELEVATOR
+ db CELADON_MART_ELEVATOR
+ db CINNABAR_LAB_2
+ db CINNABAR_LAB_3
+ db CINNABAR_LAB_4
+ db $ff
+
+CalculatePikachuSpawnState3::
+ ld a, [wCurMap]
+ cp ROUTE_22_GATE
+ jr z, .asm_fc6a7
+ cp ROUTE_2_GATE
+ jr z, .asm_fc6b0
+ jr .asm_fc6bd
+
+.asm_fc6a7
+ ld a, [wPlayerFacingDirection]
+ cp SPRITE_FACING_UP
+ jr z, .asm_fc6b9
+ jr .asm_fc6bd
+
+.asm_fc6b0
+ ld a, [wPlayerFacingDirection]
+ cp SPRITE_FACING_UP
+ jr z, .asm_fc6b9
+ jr .asm_fc6bd
+
+.asm_fc6b9
+ ld a, $1
+ jr .asm_fc6c1
+
+.asm_fc6bd
+ ld a, $3
+ jr .asm_fc6c1
+
+.asm_fc6c1
+ ld [wPikachuSpawnState], a
+ ret
+
+SetPikachuOverworldStateFlag2::
+ push hl
+ ld hl, wPikachuOverworldStateFlags
+ set 2, [hl]
+ pop hl
+ ret
+
+ResetPikachuOverworldStateFlag2::
+ push hl
+ ld hl, wPikachuOverworldStateFlags
+ res 2, [hl]
+ pop hl
+ ret
+
+SpawnPikachu_::
+ call ResetPikachuOverworldStateFlag2
+ call TrySpawnPikachu
+ ret nc
+
+ push bc
+ call WillPikachuSpawnOnTheScreen
+ pop bc
+ ret c
+
+ ld bc, wPikachuSpriteStateData1
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ bit 7, [hl]
+ jp nz, Func_fc745
+ ld a, [wFontLoaded]
+ bit 0, a
+ jp nz, Func_fc76a
+ call CheckPikachuFollowingPlayer
+ jp nz, Func_fc76a
+ ld a, [hl]
+ and $7f
+ cp $a
+ jr c, .valid
+ xor a
+.valid
+ add a
+ ld e, a
+ ld d, 0
+ ld hl, PointerTable_fc710
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
+
+PointerTable_fc710:
+ dw Func_fc793
+ dw Func_fc7aa
+ dw Func_fc803
+ dw asm_fc9c3
+ dw asm_fca1c
+ dw asm_fc9ee
+ dw asm_fc87f
+ dw asm_fc904
+ dw asm_fc937
+ dw asm_fc969
+ dw .nop
+
+.nop:
+ ret
+
+TrySpawnPikachu:
+ call ShouldPikachuSpawn
+ jr nc, .dont_spawn
+ ld a, [wPikachuMovementStatus]
+ and a
+ jr nz, .already_spawned
+ push bc
+ push hl
+ call CalculatePikachuSpawnCoordsAndFacing
+ pop hl
+ pop bc
+.already_spawned
+ scf
+ ret
+
+.dont_spawn
+ ld hl, wPikachuSpriteImageIdx
+ ld [hl], $ff
+ dec hl
+ ld [hl], $0
+ xor a
+ ret
+
+Func_fc745:
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ res 7, [hl]
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], a
+ call CheckPikachuFollowingPlayer
+ jr nz, .okay
+ ; Have Pikachu face in the opposite direction of you
+ ld a, [wPlayerFacingDirection]
+ xor $4
+ ld hl, wPikachuFacingDirection - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], a
+.okay
+ xor a
+ ld hl, wPikachuIntraAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hli], a
+ ld [hl], a
+ call UpdatePikachuWalkingSprite
+ ret
+
+Func_fc76a:
+ xor a
+ ld hl, wPikachuIntraAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hli], a
+ ld [hl], a
+ call UpdatePikachuWalkingSprite
+ call Func_fc82e
+ jr c, .skip
+ push bc
+ callab InitializeSpriteScreenPosition
+ pop bc
+.skip
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $1
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $0
+ call RefreshPikachuFollow
+ ret
+
+Func_fc793:
+ call RefreshPikachuFollow
+ push bc
+ callab InitializeSpriteScreenPosition
+ pop bc
+ ld hl, wPikachuSpriteImageIdx - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $ff
+ dec hl
+ ld [hl], $1
+ ret
+
+Func_fc7aa:
+ call Func_fcc92
+ jp c, Func_fc803
+ dec a
+ ld l, a
+ ld h, $0
+ add hl, hl
+ add hl, hl
+ ld de, Pointer_fc7e3
+ add hl, de
+ ld d, h
+ ld e, l
+ ld a, [de]
+ inc de
+ ld hl, wPikachuFacingDirection - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], a
+ ld a, [de]
+ inc de
+ ld hl, wPikachuXStepVector - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], a
+ dec hl
+ dec hl
+ ld a, [de]
+ ld [hl], a
+ inc de
+ ld a, [de]
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], a
+ cp $4
+ jp z, Func_fca0a
+ call AreThereAtLeastTwoStepsInPikachuFollowCommandBuffer
+ jp c, FastPikachuFollow
+ jp NormalPikachuFollow
+
+Pointer_fc7e3:
+ db 0, 0
+ db 1, 3
+ db 4, 0
+ db -1, 3
+ db 8, -1
+ db 0, 3
+ db 12, 1
+ db 0, 3
+ db 0, 0
+ db 1, 4
+ db 4, 0
+ db -1, 4
+ db 8, -1
+ db 0, 4
+ db 12, 1
+ db 0, 4
+
+Func_fc803:
+ call Func_fcae2
+ ret c
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ jr nz, .asm_fc823
+ push hl
+ call GetPikachuFollowCommand
+ pop hl
+ cp $5
+ jr nc, Func_fc842
+ ld [hl], $20
+ call Random
+ and $c
+ ld hl, wPikachuFacingDirection - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], a
+.asm_fc823
+ xor a
+ ld hl, wPikachuIntraAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hli], a
+ ld [hl], a
+ call UpdatePikachuWalkingSprite
+ ret
+
+Func_fc82e:
+ ld a, [wWalkCounter]
+ and a
+ ret z
+ scf
+ ret
+
+Func_fc835:
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $10
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $1
+ ret
+
+Func_fc842:
+ ld hl, $0
+ push af
+ call Random
+ ld a, [hRandomAdd]
+ and %11
+ ld e, a
+ ld d, $0
+ ld hl, PointerTable_fc85a
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop af
+ jp hl
+
+PointerTable_fc85a:
+ dw Func_fc862
+ dw Func_fc8f8
+ dw Func_fc92b
+ dw Func_fc95d
+
+Func_fc862:
+ dec a
+ add a
+ add a
+ and $c
+ ld hl, wPikachuFacingDirection - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], a
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $6
+ xor a
+ ld [wd432], a
+ ld [wd433], a
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $11
+asm_fc87f:
+ ld a, [wd432]
+ ld e, a
+ ld a, [wd433]
+ ld d, a
+ call Func_fc82e
+ jr c, Func_fc8c7
+ call SetPikachuOverworldStateFlag2
+ ld hl, wPikachuYPixels - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ sub e
+ ld e, a
+ inc hl
+ inc hl
+ ld a, [hl]
+ sub d
+ ld d, a
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ dec a
+ add a
+ add Pointer_fc8d6 % $100
+ ld l, a
+ ld a, Pointer_fc8d6 / $100
+ adc $0
+ ld h, a
+ ld a, [hli]
+ ld [wd432], a
+ add e
+ ld e, a
+ ld a, [hl]
+ ld [wd433], a
+ add d
+ ld d, a
+ ld hl, wPikachuYPixels - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], e
+ inc hl
+ inc hl
+ ld [hl], d
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ ret nz
+ jp Func_fc835
+
+Func_fc8c7:
+ ld hl, wPikachuYPixels - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ sub e
+ ld [hl], a
+ inc hl
+ inc hl
+ ld a, [hl]
+ sub d
+ ld [hl], a
+ jp Func_fc835
+
+Pointer_fc8d6:
+ db 0, 0
+ db -2, 1
+ db -4, 2
+ db -2, 3
+ db 0, 4
+ db -2, 3
+ db -4, 2
+ db -2, 1
+ db 0, 0
+ db -2, -1
+ db -4, -2
+ db -2, -3
+ db 0, -4
+ db -2, -3
+ db -4, -2
+ db -2, -1
+ db 0, 0
+
+Func_fc8f8:
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $7
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $30
+asm_fc904:
+ call Func_fc82e
+ jp c, Func_fc835
+ call SetPikachuOverworldStateFlag2
+ ld hl, wPikachuIntraAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ inc a
+ cp $8
+ ld [hl], a
+ jr nz, .asm_fc91f
+ xor a
+ ld [hli], a
+ ld a, [hl]
+ inc a
+ and %11
+ ld [hl], a
+.asm_fc91f
+ call UpdatePikachuWalkingSprite
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ ret nz
+ jp Func_fc835
+
+Func_fc92b:
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $20
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $8
+asm_fc937:
+ call Func_fc82e
+ jp c, Func_fc835
+ call SetPikachuOverworldStateFlag2
+ ld hl, wPikachuIntraAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ inc a
+ cp $8
+ ld [hl], a
+ jr nz, .asm_fc951
+ xor a
+ ld [hli], a
+ ld a, [hl]
+ xor $1
+ ld [hl], a
+.asm_fc951
+ call UpdatePikachuWalkingSprite
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ ret nz
+ jp Func_fc835
+
+Func_fc95d:
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $20
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $9
+asm_fc969:
+ call Func_fc82e
+ jp c, Func_fc835
+ call SetPikachuOverworldStateFlag2
+ ld hl, wPikachuIntraAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ inc a
+ cp $8
+ ld [hl], a
+ jr nz, .skip
+ xor a
+ ld [hl], a
+ ld hl, wPikachuFacingDirection - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ call .TurnClockwise
+ ld [hl], a
+.skip
+ call UpdatePikachuWalkingSprite
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ ret nz
+ jp Func_fc835
+
+.TurnClockwise:
+ push hl
+ ld hl, .Facings
+ ld d, a
+.loop
+ ld a, [hli]
+ cp d
+ jr nz, .loop
+ ld a, [hl]
+ pop hl
+ ret
+
+.TurnCounterclockwise:
+ push hl
+ ld hl, .Facings_End
+ ld d, a
+.loop_
+ ld a, [hld]
+ cp d
+ jr nz, .loop_
+ ld a, [hl]
+ pop hl
+ ret
+
+.Facings:
+ db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT, SPRITE_FACING_UP, SPRITE_FACING_RIGHT
+ db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT, SPRITE_FACING_UP, SPRITE_FACING_RIGHT
+.Facings_End:
+
+NormalPikachuFollow:
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $8
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $3
+ call AddPikachuStepVector
+asm_fc9c3:
+ call TryDoubleAddPikachuStepVectorToScreenPixelCoords
+ call GetPikachuWalkingAnimationSpeed
+ call UpdatePikachuWalkingSprite
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ ret nz
+ call ResetPikachuStepVector
+ call ComputePikachuFacingDirection
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $1
+ ret
+
+FastPikachuFollow:
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $4
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $5
+ call AddPikachuStepVector
+asm_fc9ee:
+ call DoubleAddPikachuStepVectorToScreenPixelCoords
+ call GetPikachuWalkingAnimationSpeed
+ call UpdatePikachuWalkingSprite
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ ret nz
+ call ResetPikachuStepVector
+ call ComputePikachuFacingDirection
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $1
+ ret
+
+Func_fca0a:
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $8
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $4
+ call AddPikachuStepVector
+ call AddPikachuStepVector
+asm_fca1c:
+ call DoubleAddPikachuStepVectorToScreenPixelCoords
+ call GetPikachuWalkingAnimationSpeed
+ call UpdatePikachuWalkingSprite
+ ld hl, wPikachuWalkAnimationCounter - wPikachuSpriteStateData1
+ add hl, bc
+ dec [hl]
+ ret nz
+ call ResetPikachuStepVector
+ call ComputePikachuFacingDirection
+ ld hl, wPikachuMovementStatus - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $1
+ ret
+
+AddPikachuStepVector:
+ ld hl, wPikachuYStepVector - wPikachuSpriteStateData1
+ add hl, bc
+ ld e, [hl]
+ inc hl
+ inc hl
+ ld d, [hl]
+ ld hl, wPikachuMapY - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ add e
+ ld [hli], a
+ ld a, [hl]
+ add d
+ ld [hl], a
+ ret
+
+TryDoubleAddPikachuStepVectorToScreenPixelCoords:
+ ld a, [wWalkBikeSurfState]
+ cp $1 ; biking
+ jr nz, AddPikachuStepVectorToScreenPixelCoords
+ ld a, [wd736]
+ bit 6, a
+ jr nz, AddPikachuStepVectorToScreenPixelCoords
+DoubleAddPikachuStepVectorToScreenPixelCoords:
+ ld hl, wPikachuYStepVector - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hli]
+ add a
+ add a
+ add [hl]
+ ld [hli], a
+ ld a, [hli]
+ add a
+ add a
+ add [hl]
+ ld [hl], a
+ ret
+
+AddPikachuStepVectorToScreenPixelCoords:
+ ld hl, wPikachuYStepVector - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hli]
+ add a
+ add [hl]
+ ld [hli], a
+ ld a, [hli]
+ add a
+ add [hl]
+ ld [hli], a
+ ret
+
+ResetPikachuStepVector:
+ ld hl, wPikachuYStepVector - wPikachuSpriteStateData1
+ add hl, bc
+ xor a
+ ld [hli], a
+ inc hl
+ ld [hl], a
+ ret
+
+GetPikachuWalkingAnimationSpeed:
+ call ComparePikachuHappinessTo80
+ ld d, $2
+ jr nc, .happy
+ ld d, $5
+.happy
+ ld hl, wPikachuIntraAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ inc a
+ cp d
+ jr nz, .dont_reset
+ xor a
+.dont_reset
+ ld [hli], a
+ ret nz
+ ld a, [hl]
+ inc a
+ and $3
+ ld [hl], a
+ ret
+
+UpdatePikachuWalkingSprite:
+ ld a, [wPikachuOverworldStateFlags]
+ bit 3, a
+ jr nz, .uninitialized
+ ld hl, wPikachuSpriteImageBaseOffset - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ dec a
+ swap a
+ ld d, a
+ ld a, [wd736]
+ bit 7, a
+ jr nz, .copy_player
+ ld hl, wPikachuFacingDirection - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ or d
+ ld d, a
+ ld a, [wFontLoaded]
+ bit 0, a
+ jr z, .normal_get_sprite_index
+ call Func_fcae2
+ ret c
+ jr .load_sprite_index
+
+.normal_get_sprite_index
+ ld hl, wPikachuAnimFrameCounter - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, d
+ or [hl]
+ ld d, a
+.load_sprite_index
+ ld hl, wPikachuSpriteImageIdx - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], d
+ ret
+
+.uninitialized
+ ld hl, wPikachuSpriteImageIdx - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $ff
+ ret
+
+.copy_player
+ ld a, [wPlayerSpriteImageIdx]
+ and $f
+ or d
+ ld [wPikachuSpriteImageIdx], a
+ ret
+
+Func_fcae2:
+ ld hl, wPikachuMapY - wPikachuSpriteStateData1
+ add hl, bc
+ ld a, [wYCoord]
+ add $4
+ cp [hl]
+ jr nz, .on_screen
+ inc hl
+ ld a, [wXCoord]
+ add $4
+ cp [hl]
+ jr nz, .on_screen
+ ld hl, wPikachuSpriteImageIdx - wPikachuSpriteStateData1
+ add hl, bc
+ ld [hl], $ff
+ scf
+ ret
+
+.on_screen
+ and a
+ ret
+
+IsPikachuRightNextToPlayer:
+ push bc
+ push de
+ push hl
+ ld bc, wPikachuPictureID
+ ld a, [wXCoord]
+ add $4
+ ld d, a
+ ld a, [wYCoord]
+ add $4
+ ld e, a
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ sub e
+ and a
+ jr z, .equal
+ cp $ff
+ jr z, .one_away
+ cp $1
+ jr z, .one_away
+ jr .bad
+
+.one_away
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ sub d
+ jr z, .good
+ jr .bad
+
+.equal
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ sub d
+ cp $ff
+ jr z, .good
+ cp $1
+ jr z, .good
+ and a
+ jr z, .good
+ jr .bad
+
+.good
+ pop hl
+ pop de
+ pop bc
+ scf
+ ret
+
+.bad
+ pop hl
+ pop de
+ pop bc
+ xor a
+ ret
+
+GetPikachuFacingDirectionAndReturnToE:
+ call GetPikachuFacingDirection
+ ld e, a
+ ret
+
+GetPikachuFacingDirection:
+ ld bc, wPikachuPictureID
+ ld a, [wXCoord]
+ add $4
+ ld d, a
+ ld a, [wYCoord]
+ add $4
+ ld e, a
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ cp e
+ jr z, .asm_fcb71
+ jr nc, .asm_fcb6e
+ ld a, SPRITE_FACING_UP
+ ret
+
+.asm_fcb6e
+ ld a, SPRITE_FACING_DOWN
+ ret
+
+.asm_fcb71
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ cp d
+ jr z, .asm_fcb81
+ jr nc, .asm_fcb7e
+ ld a, SPRITE_FACING_LEFT
+ ret
+
+.asm_fcb7e
+ ld a, SPRITE_FACING_RIGHT
+ ret
+
+.asm_fcb81
+ ld a, $ff ; standing
+ ret
+
+ClearPikachuFollowCommandBuffer:
+ push bc
+ ld hl, wPikachuFollowCommandBufferSize
+ ld [hl], $ff
+ inc hl
+ ld bc, $10
+ xor a
+ call FillMemory
+ pop bc
+ ret
+
+AppendPikachuFollowCommandToBuffer:
+ ld hl, wPikachuFollowCommandBufferSize
+ inc [hl]
+ ld e, [hl]
+ ld d, 0
+ ld hl, wPikachuFollowCommandBuffer
+ add hl, de
+ ld [hl], a
+ ret
+
+RefreshPikachuFollow:
+ call ClearPikachuFollowCommandBuffer
+ call ComputePikachuFollowCommand
+ ret c
+ call AppendPikachuFollowCommandToBuffer
+ ret
+
+ComputePikachuFollowCommand:
+ ld bc, wPikachuPictureID
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [wYCoord]
+ add $4
+ sub [hl]
+ jr z, .checkXCoord
+ jr c, .pikaAbovePlayer
+ call CheckAbsoluteValueLessThan2
+ jr c, .return1
+ ld a, $5
+ and a
+ ret
+
+.return1
+ ld a, $1
+ and a
+ ret
+
+.pikaAbovePlayer
+ call CheckAbsoluteValueLessThan2
+ jr c, .return2
+ ld a, $6
+ and a
+ ret
+
+.return2
+ ld a, $2
+ and a
+ ret
+
+.checkXCoord
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [wXCoord]
+ add $4
+ sub [hl]
+ jr z, .pikachuOnTopOfPlayer
+ jr c, .pikaToLeftOfPlayer
+ call CheckAbsoluteValueLessThan2
+ jr c, .return4
+ ld a, $8
+ and a
+ ret
+
+.return4
+ ld a, $4
+ and a
+ ret
+
+.pikaToLeftOfPlayer
+ call CheckAbsoluteValueLessThan2
+ jr c, .return3
+ ld a, $7
+ and a
+ ret
+
+.return3
+ ld a, $3
+ and a
+ ret
+
+.pikachuOnTopOfPlayer
+ scf
+ ret
+
+CheckAbsoluteValueLessThan2:
+ jr nc, .positive
+ cpl
+ inc a
+.positive
+ cp $2
+ ret
+
+Func_fcc08::
+ call Func_fcc23
+ ret nc
+ ld a, [wd736]
+ bit 6, a
+ jr nz, .asm_fcc1b
+ call Func_fcc42
+ ret c
+ call AppendPikachuFollowCommandToBuffer
+ ret
+
+.asm_fcc1b
+ call Func_fcc64
+ ret c
+ call AppendPikachuFollowCommandToBuffer
+ ret
+
+Func_fcc23:
+ ld a, [wPikachuOverworldStateFlags]
+ bit 5, a
+ jr nz, .asm_fcc40
+ ld a, [wPikachuOverworldStateFlags]
+ bit 7, a
+ jr nz, .asm_fcc40
+ ld a, [wd472]
+ bit 7, a
+ jr z, .asm_fcc40
+ ld a, [wWalkBikeSurfState]
+ and a
+ jr nz, .asm_fcc40
+ scf
+ ret
+
+.asm_fcc40
+ and a
+ ret
+
+Func_fcc42:
+ xor a
+ ld a, [wPlayerDirection]
+ bit 3, a
+ jr nz, .asm_fcc58
+ bit 2, a
+ jr nz, .asm_fcc5b
+ bit 1, a
+ jr nz, .asm_fcc5e
+ bit 0, a
+ jr nz, .asm_fcc61
+ scf
+ ret
+
+.asm_fcc58
+ ld a, $2
+ ret
+
+.asm_fcc5b
+ ld a, $1
+ ret
+
+.asm_fcc5e
+ ld a, $3
+ ret
+
+.asm_fcc61
+ ld a, $4
+ ret
+
+Func_fcc64:
+ ld hl, wPikachuOverworldStateFlags
+ bit 6, [hl]
+ jr z, .asm_fcc6e
+ res 6, [hl]
+ ret
+
+.asm_fcc6e
+ set 6, [hl]
+ xor a
+ ld a, [wPlayerDirection]
+ bit 3, a
+ jr nz, .asm_fcc86
+ bit 2, a
+ jr nz, .asm_fcc89
+ bit 1, a
+ jr nz, .asm_fcc8c
+ bit 0, a
+ jr nz, .asm_fcc8f
+ scf
+ ret
+
+.asm_fcc86
+ ld a, $6
+ ret
+
+.asm_fcc89
+ ld a, $5
+ ret
+
+.asm_fcc8c
+ ld a, $7
+ ret
+
+.asm_fcc8f
+ ld a, $8
+ ret
+
+Func_fcc92:
+ ld hl, wPikachuFollowCommandBufferSize
+ ld a, [hl]
+ cp $ff
+ jr z, .asm_fccb0
+ and a
+ jr z, .asm_fccb0
+ dec [hl]
+ ld e, a
+ ld d, 0
+ ld hl, wPikachuFollowCommandBuffer
+ add hl, de
+ inc e
+ ld a, $ff
+.asm_fcca8
+ ld d, [hl]
+ ldd [hl], a
+ ld a, d
+ dec e
+ jr nz, .asm_fcca8
+ and a
+ ret
+
+.asm_fccb0
+ scf
+ ret
+
+ComputePikachuFacingDirection::
+ call GetPikachuFollowCommandIfBufferSizeNonzero
+ and a
+ jr z, .check_y
+ dec a
+ and $3
+ add a
+ add a
+ jr .load
+
+.check_y
+ ld a, [wYCoord]
+ add $4
+ ld d, a
+ ld a, [wXCoord]
+ add $4
+ ld e, a
+ ld a, [wPikachuMapY]
+ cp d
+ jr z, .check_x
+ ld a, SPRITE_FACING_DOWN
+ jr c, .load
+ ld a, SPRITE_FACING_UP
+ jr .load
+
+.check_x
+ ld a, [wPikachuMapX]
+ cp e
+ jr z, .copy_from_player
+ ld a, SPRITE_FACING_RIGHT
+ jr c, .load
+ ld a, SPRITE_FACING_LEFT
+ jr .load
+
+.copy_from_player
+ ld a, [wPlayerFacingDirection]
+.load
+ ld [wPikachuFacingDirection], a
+ ret
+
+GetPikachuFollowCommand:
+ ld hl, wPikachuFollowCommandBufferSize
+ ld a, [hl]
+ cp $ff
+ jr z, .asm_fccff
+ ld e, a
+ ld d, 0
+ ld hl, wPikachuFollowCommandBuffer
+ add hl, de
+ ld a, [hl]
+ ret
+
+.asm_fccff
+ xor a
+ ret
+
+GetPikachuFollowCommandIfBufferSizeNonzero:
+ ld hl, wPikachuFollowCommandBufferSize
+ ld a, [hl]
+ cp $ff
+ jr z, .default
+ and a
+ jr z, .default
+ ld e, a
+ ld d, 0
+ ld hl, wPikachuFollowCommandBuffer
+ add hl, de
+ ld a, [hl]
+ ret
+
+.default
+ xor a
+ ret
+
+AreThereAtLeastTwoStepsInPikachuFollowCommandBuffer:
+ ld a, [wPikachuFollowCommandBufferSize]
+ cp $ff
+ ret z
+ cp $2
+ jr nc, .set_carry
+ and a
+ ret
+
+.set_carry
+ scf
+ ret
+
+WillPikachuSpawnOnTheScreen:
+ ld h, wSpriteStateData2 / $100
+ ld a, [H_CURRENTSPRITEOFFSET] ; If we're here, this can only be $f0
+ add wPikachuMapY - wPikachuSpriteStateData2
+ ld l, a
+ ld b, [hl]
+ ld a, [wYCoord]
+ cp b
+ jr z, .same_y
+ jr nc, .not_on_screen
+ add (SCREEN_HEIGHT / 2) - 1
+ cp b
+ jr c, .not_on_screen
+.same_y
+ inc l
+ ld b, [hl]
+ ld a, [wXCoord]
+ cp b
+ jr z, .same_x
+ jr nc, .not_on_screen
+ add (SCREEN_WIDTH / 2) - 1
+ cp b
+ jr c, .not_on_screen
+.same_x
+ call .GetNPCCurrentTile
+ ld d, $60
+ ld a, [hli]
+ ld e, a
+ cp d
+ jr nc, .not_on_screen
+ ld a, [hld]
+ cp d
+ jr nc, .not_on_screen
+ ld bc, -20
+ add hl, bc
+ ld a, [hli]
+ cp d
+ jr nc, .not_on_screen
+ ld a, [hl]
+ cp d
+ jr c, .on_screen
+.not_on_screen
+ ld h, wSpriteStateData1 / $100
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add wPikachuSpriteImageIdx - wPikachuSpriteStateData1
+ ld l, a
+ ld [hl], $ff
+ scf
+ jr .return
+
+.on_screen
+ ld h, wSpriteStateData2 / $100
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add wPikachuGrassPriority - wPikachuSpriteStateData2
+ ld l, a
+ ld a, [wGrassTile]
+ cp e
+ ld a, $0
+ jr nz, .priority
+ ld a, $80
+.priority
+ ld [hl], a
+ and a
+.return
+ ret
+
+.GetNPCCurrentTile:
+ ld h, wSpriteStateData1 / $100
+ ld a, [H_CURRENTSPRITEOFFSET]
+ add wPikachuYPixels - wPikachuSpriteStateData1
+ ld l, a
+ ld a, [hli]
+ add $4
+ and $f0
+ srl a
+ ld c, a
+ ld b, $0
+ inc l
+ ld a, [hl]
+ add $2
+ srl a
+ srl a
+ srl a
+ add SCREEN_WIDTH
+ ld d, 0
+ ld e, a
+ ld hl, wTileMap
+ rept 5
+ add hl, bc
+ endr
+ add hl, de
+ ret
+
+ComparePikachuHappinessTo80:
+; preserves a and bc
+ push bc
+ push af
+ ld a, [wPikachuHappiness]
+ cp 80
+ pop bc
+ ld a, b
+ pop bc
+ ret
diff --git a/engine/pikachu_movement.asm b/engine/pikachu_movement.asm
new file mode 100755
index 00000000..8eb09b3b
--- /dev/null
+++ b/engine/pikachu_movement.asm
@@ -0,0 +1,1048 @@
+ApplyPikachuMovementData_::
+ ld a, b
+ ld [wPikachuMovementScriptBank], a
+ ld a, l
+ ld [wPikachuMovementScriptAddress], a
+ ld a, h
+ ld [wPikachuMovementScriptAddress + 1], a
+ call .SwapSpriteStateData
+.loop
+ call LoadPikachuMovementCommandData
+ jr nc, .done
+ call ExecutePikachuMovementCommand
+ jr .loop
+
+.done
+ call .SwapSpriteStateData
+ call DelayFrame
+ ret
+
+.SwapSpriteStateData:
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ push hl
+ push de
+ push bc
+
+ ld hl, wPlayerSpriteStateData1
+ ld de, wPikachuSpriteStateData1
+ ld c, $10
+ call .SwapBytes
+
+ ld hl, wPlayerSpriteStateData2
+ ld de, wPikachuSpriteStateData2
+ ld c, $10
+ call .SwapBytes
+
+ pop bc
+ pop de
+ pop hl
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ ret
+
+.SwapBytes:
+ ld b, [hl]
+ ld a, [de]
+ ld [hli], a
+ ld a, b
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .SwapBytes
+ ret
+
+LoadPikachuMovementCommandData:
+ call GetPikachuMovementScriptByte
+ cp $3f
+ ret z
+ ld c, a
+ ld b, 0
+ ld hl, PikachuMovementDatabase
+ add hl, bc
+ add hl, bc
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld [wCurPikaMovementFunc1], a
+ ld a, [hli]
+ cp $80
+ jr nz, .no_param
+ call GetPikachuMovementScriptByte
+.no_param
+ ld [wCurPikaMovementParam1], a
+ ld a, [hli]
+ ld [wCurPikaMovementFunc2], a
+ ld a, [hli]
+ cp $80
+ jr nz, .no_param2
+ call GetPikachuMovementScriptByte
+.no_param2
+ ld [wCurPikaMovementParam2], a
+ xor a
+ ld [wd451], a
+ scf
+ ret
+
+ExecutePikachuMovementCommand:
+ xor a
+ ld [wPikachuMovementFlags], a
+ ld [wPikachuStepTimer], a
+ ld [wPikachuStepSubtimer], a
+ ld a, [wPlayerGrassPriority]
+ push af
+.loop
+ ld bc, wPlayerSpriteStateData1 ; Currently holds Pikachu's sprite state data
+ ld a, [wCurPikaMovementFunc1]
+ ld hl, PikaMovementFunc1Jumptable
+ call .JumpTable
+ ld a, [wCurPikaMovementFunc2]
+ ld hl, PikaMovementFunc2Jumptable
+ call .JumpTable
+ call GetCoordsForPikachuShadow
+ call AnimatePikachuShadow
+ call DelayFrame
+ call DelayFrame
+ ld hl, wPikachuMovementFlags
+ bit 7, [hl]
+ jr z, .loop
+ pop af
+ ld [wPlayerGrassPriority], a
+ scf
+ ret
+
+.JumpTable:
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+GetCoordsForPikachuShadow:
+ ld hl, wPlayerSpriteImageIdx - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [wCurPikaMovementSpriteImageIdx]
+ ld [hl], a
+ ld a, [wPikaSpriteY]
+ ld d, a
+ ld a, [wPikachuMovementYOffset]
+ add d
+ ld hl, wPlayerYPixels - wPlayerSpriteStateData1
+ add hl, bc
+ ld [hl], a
+ ld a, [wPikaSpriteX]
+ ld d, a
+ ld a, [wPikachuMovementXOffset]
+ add d
+ ld hl, wPlayerXPixels - wPlayerSpriteStateData1
+ add hl, bc
+ ld [hl], a
+ ld hl, wPikachuMovementFlags
+ bit 6, [hl]
+ ret z
+ ld hl, wPlayerGrassPriority - wPlayerSpriteStateData1
+ add hl, bc
+ ld [hl], 0
+ ret
+
+AnimatePikachuShadow:
+ ld hl, wPikachuMovementFlags
+ bit 6, [hl]
+ res 6, [hl]
+ ld hl, wd736
+ res 6, [hl]
+ ret z
+ set 6, [hl]
+ call LoadPikachuShadowOAMData
+ ret
+
+PikachuMovementDatabase:
+ db $01, 1 - 1, $00, 1 - 1 ; $00 start
+
+ db $03, $80, $01, 1 - 1 ; $01
+ db $04, $80, $01, 1 - 1 ; $02
+ db $05, $80, $01, 1 - 1 ; $03
+ db $06, $80, $01, 1 - 1 ; $04
+ db $07, $80, $01, 1 - 1 ; $05
+ db $08, $80, $01, 1 - 1 ; $06
+ db $09, $80, $01, 1 - 1 ; $07
+ db $0a, $80, $01, 1 - 1 ; $08
+
+ db $03, $80, $06, 1 - 1 ; $09
+ db $04, $80, $06, 1 - 1 ; $0a
+ db $05, $80, $06, 1 - 1 ; $0b
+ db $06, $80, $06, 1 - 1 ; $0c
+ db $07, $80, $06, 1 - 1 ; $0d
+ db $08, $80, $06, 1 - 1 ; $0e
+ db $09, $80, $06, 1 - 1 ; $0f
+ db $0a, $80, $06, 1 - 1 ; $10
+
+ db $03, $80, $03, $80 ; $11
+ db $04, $80, $03, $80 ; $12
+ db $05, $80, $03, $80 ; $13
+ db $06, $80, $03, $80 ; $14
+ db $07, $80, $03, $80 ; $15
+ db $08, $80, $03, $80 ; $16
+ db $09, $80, $03, $80 ; $17
+ db $0a, $80, $03, $80 ; $18
+
+ db $03, $80, $07, $80 ; $19
+ db $04, $80, $07, $80 ; $1a
+ db $05, $80, $07, $80 ; $1b
+ db $06, $80, $07, $80 ; $1c
+
+ db $0b, (1 << 5) | 8 - 1, $02, 1 - 1 ; $1d step down
+ db $0c, (1 << 5) | 8 - 1, $02, 1 - 1 ; $1e step up
+ db $0d, (1 << 5) | 8 - 1, $02, 1 - 1 ; $1f step left
+ db $0e, (1 << 5) | 8 - 1, $02, 1 - 1 ; $20 step right
+ db $0f, (1 << 5) | 8 - 1, $02, 1 - 1 ; $21 step down left
+ db $10, (1 << 5) | 8 - 1, $02, 1 - 1 ; $22 step down right
+ db $11, (1 << 5) | 8 - 1, $02, 1 - 1 ; $23 step up left
+ db $12, (1 << 5) | 8 - 1, $02, 1 - 1 ; $24 step up right
+
+ db $0b, 16 - 1, $02, 1 - 1 ; $25 slide down
+ db $0c, 16 - 1, $02, 1 - 1 ; $26 slide up
+ db $0d, 16 - 1, $02, 1 - 1 ; $27 slide left
+ db $0e, 16 - 1, $02, 1 - 1 ; $28 slide right
+ db $0f, 16 - 1, $02, 1 - 1 ; $29 slide down left
+ db $10, 16 - 1, $02, 1 - 1 ; $2a slide down right
+ db $11, 16 - 1, $02, 1 - 1 ; $2b slide up left
+ db $12, 16 - 1, $02, 1 - 1 ; $2c slide up right
+
+ db $0b, 16 - 1, $08, (1 << 4) | 8 - 1 ; $2d hop down
+ db $0c, 16 - 1, $08, (1 << 4) | 8 - 1 ; $2e hop up
+ db $0d, 16 - 1, $08, (1 << 4) | 8 - 1 ; $2f hop left
+ db $0e, 16 - 1, $08, (1 << 4) | 8 - 1 ; $30 hop right
+ db $0f, 16 - 1, $08, (1 << 4) | 8 - 1 ; $31 hop down left
+ db $10, 16 - 1, $08, (1 << 4) | 8 - 1 ; $32 hop down right
+ db $11, 16 - 1, $08, (1 << 4) | 8 - 1 ; $33 hop up left
+ db $12, 16 - 1, $08, (1 << 4) | 8 - 1 ; $34 hop up right
+
+ db $13, 16 - 1, $06, 1 - 1 ; $35 look down
+ db $14, 16 - 1, $06, 1 - 1 ; $36 look up
+ db $15, 16 - 1, $06, 1 - 1 ; $37 look left
+ db $16, 16 - 1, $06, 1 - 1 ; $38 look right
+
+ db $02, $80, $04, 1 - 1 ; $39
+ db $02, $80, $05, 1 - 1 ; $3a
+ db $02, $80, $03, $80 ; $3b
+ db $02, $80, $07, $80 ; $3c
+ db $02, $80, $09, $80 ; $3d
+ db $02, $80, $06, 1 - 1 ; $3e
+
+PikaMovementFunc1Jumptable:
+ dw PikaMovementFunc1_EndCommand_ ; 00
+ dw PikaMovementFunc1_LoadPikachuCurrentPosition ; 01
+ dw PikaMovementFunc1_DelayFrames ; 02
+ dw PikaMovementFunc1_WalkInCurrentFacingDirection ; 03
+ dw PikaMovementFunc1_WalkInOppositeFacingDirection ; 04
+ dw PikaMovementFunc1_StepTurningCounterclockwise ; 05
+ dw PikaMovementFunc1_StepTurningClockwise ; 06
+ dw PikaMovementFunc1_StepForwardLeft ; 07
+ dw PikaMovementFunc1_StepForwardRight ; 08
+ dw PikaMovementFunc1_StepBackwardLeft ; 09
+ dw PikaMovementFunc1_StepBackwardRight ; 0a
+ dw PikaMovementFunc1_MoveDown ; 0b
+ dw PikaMovementFunc1_MoveUp ; 0c
+ dw PikaMovementFunc1_MoveLeft ; 0d
+ dw PikaMovementFunc1_MoveRight ; 0e
+ dw PikaMovementFunc1_MoveDownLeft ; 0f
+ dw PikaMovementFunc1_MoveDownRight ; 10
+ dw PikaMovementFunc1_MoveUpLeft ; 11
+ dw PikaMovementFunc1_MoveUpRight ; 12
+ dw PikaMovementFunc1_LookDown ; 13
+ dw PikaMovementFunc1_LookUp ; 14
+ dw PikaMovementFunc1_LookLeft ; 15
+ dw PikaMovementFunc1_LookRight ; 16
+ dw PikaMovementFunc1_EndCommand_ ; 17
+
+PikaMovementFunc1_EndCommand:
+ ld a, [wPikachuMovementFlags]
+ set 7, a
+ ld [wPikachuMovementFlags], a
+ ret
+
+PikaMovementFunc1_EndCommand_:
+ call PikaMovementFunc1_EndCommand
+ ret
+
+PikaMovementFunc1_LoadPikachuCurrentPosition:
+ ld hl, wPlayerYPixels - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ ld [wPikaSpriteY], a
+ ld hl, wPlayerXPixels - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ ld [wPikaSpriteX], a
+ xor a
+ ld [wPikachuMovementYOffset], a
+ ld [wPikachuMovementXOffset], a
+ call PikaMovementFunc1_EndCommand
+ ret
+
+PikaMovementFunc1_DelayFrames:
+ call CheckPikachuStepTimer1
+ ret nz
+ call PikaMovementFunc1_EndCommand
+ ret
+
+PikaMovementFunc1_WalkInCurrentFacingDirection:
+ call GetPikachuFacing
+ jr PikaMovementFunc1_ApplyStepVector
+
+PikaMovementFunc1_WalkInOppositeFacingDirection:
+ call GetPikachuFacing
+ xor %100
+ jr PikaMovementFunc1_ApplyStepVector
+
+PikaMovementFunc1_StepTurningCounterclockwise:
+ call GetPikachuFacing
+ ld hl, .Data
+ call PikaMovementFunc1_GetNextFacing
+ jr PikaMovementFunc1_ApplyStepVector
+
+.Data:
+ db SPRITE_FACING_DOWN, PIKASTEPDIR_RIGHT << 2
+ db SPRITE_FACING_UP, PIKASTEPDIR_LEFT << 2
+ db SPRITE_FACING_LEFT, PIKASTEPDIR_DOWN << 2
+ db SPRITE_FACING_RIGHT, PIKASTEPDIR_UP << 2
+ db $ff
+
+PikaMovementFunc1_StepTurningClockwise:
+ call GetPikachuFacing
+ ld hl, .Data
+ call PikaMovementFunc1_GetNextFacing
+ jr PikaMovementFunc1_ApplyStepVector
+
+.Data:
+ db SPRITE_FACING_DOWN, PIKASTEPDIR_LEFT << 2
+ db SPRITE_FACING_UP, PIKASTEPDIR_RIGHT << 2
+ db SPRITE_FACING_LEFT, PIKASTEPDIR_UP << 2
+ db SPRITE_FACING_RIGHT, PIKASTEPDIR_DOWN << 2
+ db $ff
+
+PikaMovementFunc1_StepForwardLeft:
+ call GetPikachuFacing
+ ld hl, .Data
+ call PikaMovementFunc1_GetNextFacing
+ jr PikaMovementFunc1_ApplyStepVector
+
+.Data:
+ db SPRITE_FACING_DOWN, PIKASTEPDIR_DOWN_RIGHT << 2
+ db SPRITE_FACING_UP, PIKASTEPDIR_UP_LEFT << 2
+ db SPRITE_FACING_LEFT, PIKASTEPDIR_DOWN_LEFT << 2
+ db SPRITE_FACING_RIGHT, PIKASTEPDIR_UP_RIGHT << 2
+
+PikaMovementFunc1_StepForwardRight:
+ call GetPikachuFacing
+ ld hl, .Data
+ call PikaMovementFunc1_GetNextFacing
+ jr PikaMovementFunc1_ApplyStepVector
+
+.Data:
+ db SPRITE_FACING_DOWN, PIKASTEPDIR_DOWN_LEFT << 2
+ db SPRITE_FACING_UP, PIKASTEPDIR_UP_RIGHT << 2
+ db SPRITE_FACING_LEFT, PIKASTEPDIR_UP_LEFT << 2
+ db SPRITE_FACING_RIGHT, PIKASTEPDIR_DOWN_RIGHT << 2
+
+PikaMovementFunc1_StepBackwardLeft:
+ call GetPikachuFacing
+ ld hl, .Data
+ call PikaMovementFunc1_GetNextFacing
+ jr PikaMovementFunc1_ApplyStepVector
+
+.Data:
+ db SPRITE_FACING_DOWN, PIKASTEPDIR_UP_RIGHT << 2
+ db SPRITE_FACING_UP, PIKASTEPDIR_DOWN_LEFT << 2
+ db SPRITE_FACING_LEFT, PIKASTEPDIR_DOWN_RIGHT << 2
+ db SPRITE_FACING_RIGHT, PIKASTEPDIR_UP_LEFT << 2
+
+PikaMovementFunc1_StepBackwardRight:
+ call GetPikachuFacing
+ ld hl, .Data
+ call PikaMovementFunc1_GetNextFacing
+ jr PikaMovementFunc1_ApplyStepVector
+
+.Data:
+ db SPRITE_FACING_DOWN, PIKASTEPDIR_UP_LEFT << 2
+ db SPRITE_FACING_UP, PIKASTEPDIR_DOWN_RIGHT << 2
+ db SPRITE_FACING_LEFT, PIKASTEPDIR_UP_RIGHT << 2
+ db SPRITE_FACING_RIGHT, PIKASTEPDIR_DOWN_LEFT << 2
+
+PikaMovementFunc1_ApplyStepVector:
+ rrca
+ rrca
+ and $7
+ ld e, a
+ call GetPikachuStepVectorMagnitude
+ ld d, a
+ call UpdatePikachuPosition
+ call CheckPikachuStepTimer1
+ ret nz
+ call PikaMovementFunc1_EndCommand
+ ret
+
+PikaMovementFunc1_GetNextFacing:
+ push de
+ ld d, a
+.loop
+ ld a, [hli]
+ cp d
+ jr z, .found
+ inc hl
+ cp $ff
+ jr nz, .loop
+ pop de
+ ret
+
+.found
+ ld a, [hl]
+ pop de
+ scf
+ ret
+
+PikaMovementFunc1_MoveDown:
+ ld a, PIKASTEPDIR_DOWN
+ jr PikaMovementFunc1_ApplyFacingAndMove
+
+PikaMovementFunc1_MoveUp:
+ ld a, PIKASTEPDIR_UP
+ jr PikaMovementFunc1_ApplyFacingAndMove
+
+PikaMovementFunc1_MoveLeft:
+ ld a, PIKASTEPDIR_LEFT
+ jr PikaMovementFunc1_ApplyFacingAndMove
+
+PikaMovementFunc1_MoveRight:
+ ld a, PIKASTEPDIR_RIGHT
+ jr PikaMovementFunc1_ApplyFacingAndMove
+
+PikaMovementFunc1_MoveDownLeft:
+ ld e, PIKASTEPDIR_DOWN_LEFT
+ jr PikaMovementFunc1_MoveDiagonally
+
+PikaMovementFunc1_MoveDownRight:
+ ld e, PIKASTEPDIR_DOWN_RIGHT
+ jr PikaMovementFunc1_MoveDiagonally
+
+PikaMovementFunc1_MoveUpLeft:
+ ld e, PIKASTEPDIR_UP_LEFT
+ jr PikaMovementFunc1_MoveDiagonally
+
+PikaMovementFunc1_MoveUpRight:
+ ld e, PIKASTEPDIR_UP_RIGHT
+ jr PikaMovementFunc1_MoveDiagonally
+
+PikaMovementFunc1_ApplyFacingAndMove:
+ ld e, a
+ call SetPikachuFacing
+PikaMovementFunc1_MoveDiagonally:
+ call GetPikachuStepVectorMagnitude
+ ld d, a
+ push de
+ call UpdatePikachuPosition
+ pop de
+ call CheckPikachuStepTimer1
+ ret nz
+ ld a, e
+ call ApplyPikachuStepVector
+ call PikaMovementFunc1_EndCommand
+ ret
+
+PikaMovementFunc1_LookDown:
+ ld a, PIKASTEPDIR_DOWN
+ jr PikaMovementFunc1_ApplyFacing
+
+PikaMovementFunc1_LookUp:
+ ld a, PIKASTEPDIR_UP
+ jr PikaMovementFunc1_ApplyFacing
+
+PikaMovementFunc1_LookLeft:
+ ld a, PIKASTEPDIR_LEFT
+ jr PikaMovementFunc1_ApplyFacing
+
+PikaMovementFunc1_LookRight:
+ ld a, PIKASTEPDIR_RIGHT
+ jr PikaMovementFunc1_ApplyFacing
+
+PikaMovementFunc1_ApplyFacing:
+ call SetPikachuFacing
+ call PikaMovementFunc1_EndCommand
+ ret
+
+UpdatePikachuPosition:
+ push de
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop de
+ ld a, d
+ jp [hl]
+
+.Jumptable:
+ dw .Down
+ dw .Up
+ dw .Left
+ dw .Right
+ dw .DownLeft
+ dw .DownRight
+ dw .UpLeft
+ dw .UpRight
+
+.Down:
+ ld d, 0
+ ld e, a
+ jr .ApplyVector
+
+.Up:
+ ld d, 0
+ cpl
+ inc a
+ ld e, a
+ jr .ApplyVector
+
+.Left:
+ cpl
+ inc a
+ ld d, a
+ ld e, 0
+ jr .ApplyVector
+
+.Right:
+ ld d, a
+ ld e, 0
+ jr .ApplyVector
+
+.DownLeft:
+ ld e, a
+ cpl
+ inc a
+ ld d, a
+ jr .ApplyVector
+
+.DownRight:
+ ld e, a
+ ld d, a
+ jr .ApplyVector
+
+.UpLeft:
+ cpl
+ inc a
+ ld e, a
+ ld d, a
+ jr .ApplyVector
+
+.UpRight:
+ ld d, a
+ cpl
+ inc a
+ ld e, a
+ jr .ApplyVector
+
+.ApplyVector:
+ ld a, [wPikaSpriteX]
+ add d
+ ld [wPikaSpriteX], a
+ ld a, [wPikaSpriteY]
+ add e
+ ld [wPikaSpriteY], a
+ ret
+
+PikaMovementFunc2Jumptable:
+ dw PikaMovementFunc2_ResetFrameCounterAndFaceCurrent ; 0
+ dw PikaMovementFunc2_UpdateSpriteImageIdxWithPreviousImageIdxDirection ; 1
+ dw PikaMovementFunc2_UpdateSpriteImageIdxWithFacing ; 2
+ dw PikaMovementFunc2_TurnParameter ; 3
+ dw PikaMovementFunc2_TurnClockwise ; 4
+ dw PikaMovementFunc2_TurnCounterClockwise ; 5
+ dw PikaMovementFunc2_CopySpriteImageIdxDirectionToSpriteImageIdx ; 6
+ dw PikaMovementFunc2_UpdateJumpWithPreviousImageIdxDirection ; 7
+ dw PikaMovementFunc2_UpdateJumpWithFacing ; 8
+ dw PikaMovementFunc2_CopyFacingToJump ; 9
+ dw PikaMovementFunc2_nop ; 10
+
+PikaMovement_SetSpawnShadow:
+ ld hl, wPikachuMovementFlags
+ set 6, [hl]
+ ret
+
+PikaMovementFunc2_ResetFrameCounterAndFaceCurrent:
+ ld hl, wPlayerIntraAnimFrameCounter - wPlayerSpriteStateData1
+ add hl, bc
+ xor a
+ ld [hli], a
+ ld [hl], a
+ call PikaMovementFunc2_GetImageBaseOffset
+ ld d, a
+ call GetPikachuFacing
+ or d
+ ld [wCurPikaMovementSpriteImageIdx], a
+ ret
+
+PikaMovementFunc2_nop:
+ ret
+
+PikaMovementFunc2_CopySpriteImageIdxDirectionToSpriteImageIdx:
+ call PikaMovementFunc2_GetImageBaseOffset
+ ld d, a
+ call PikaMovementFunc2_GetSpriteImageIdxDirection
+ or d
+ ld [wCurPikaMovementSpriteImageIdx], a
+ ret
+
+PikaMovementFunc2_UpdateSpriteImageIdxWithFacing:
+ call PikaMovementFunc2_GetImageBaseOffset
+ ld d, a
+ call GetPikachuFacing
+ or d
+ ld d, a
+ jr PikaMovementFunc2_UpdateSpriteImageIdx
+
+PikaMovementFunc2_UpdateSpriteImageIdxWithPreviousImageIdxDirection:
+ call PikaMovementFunc2_GetImageBaseOffset
+ ld d, a
+ call PikaMovementFunc2_GetSpriteImageIdxDirection
+ or d
+ ld d, a
+PikaMovementFunc2_UpdateSpriteImageIdx:
+ ld hl, wPlayerAnimFrameCounter - wPlayerSpriteStateData1
+ add hl, bc
+ call CheckPikachuStepTimer2 ; does not preserve hl
+ jr nz, .skip
+ inc [hl]
+.skip
+ ld a, [hl]
+ rrca
+ rrca
+ and 3
+ or d
+ ld [wCurPikaMovementSpriteImageIdx], a
+ ret
+
+PikaMovementFunc2_UpdateJumpWithFacing:
+ call GetPikachuFacing
+ ld d, a
+ jr PikaMovementFunc2_UpdateJump
+
+PikaMovementFunc2_UpdateJumpWithPreviousImageIdxDirection:
+ call PikaMovementFunc2_GetSpriteImageIdxDirection
+ ld d, a
+PikaMovementFunc2_UpdateJump:
+ call PikaMovementFunc2_GetImageBaseOffset
+ or d
+ ld d, a
+ call PikaMovementFunc2_Timer
+ or d
+ ld [wCurPikaMovementSpriteImageIdx], a
+ call PikaMovementFunc_Sine
+ ld [wPikachuMovementYOffset], a
+ and a
+ ret z
+ call PikaMovement_SetSpawnShadow
+ ret
+
+PikaMovementFunc2_CopyFacingToJump:
+ call GetPikachuFacing
+ ld d, a
+ call PikaMovementFunc2_GetImageBaseOffset
+ or d
+ ld [wCurPikaMovementSpriteImageIdx], a
+ call PikaMovementFunc_Sine
+ ld [wPikachuMovementYOffset], a
+ ret
+
+PikaMovementFunc2_TurnParameter:
+ ld a, [wCurPikaMovementParam2]
+ and $40
+ cp $40
+ jr z, PikaMovementFunc2_TurnClockwise
+ jr PikaMovementFunc2_TurnCounterClockwise
+
+PikaMovementFunc2_TurnClockwise:
+ call PikaMovementFunc2_GetSpriteImageIdxDirection
+ ld d, a
+ call CheckPikachuStepTimer2
+ jr nz, .skip
+ ld hl, Data_fd731
+.loop
+ ld a, [hli]
+ cp d
+ jr nz, .loop
+ ld d, [hl]
+.skip
+ call PikaMovementFunc2_GetImageBaseOffset
+ or d
+ ld [wCurPikaMovementSpriteImageIdx], a
+ ret
+
+PikaMovementFunc2_TurnCounterClockwise:
+ call PikaMovementFunc2_GetSpriteImageIdxDirection
+ ld d, a
+ call CheckPikachuStepTimer2
+ jr nz, .skip
+ ld hl, Data_fd731End
+.loop
+ ld a, [hld]
+ cp d
+ jr nz, .loop
+ ld d, [hl]
+.skip
+ call PikaMovementFunc2_GetImageBaseOffset
+ or d
+ ld [wCurPikaMovementSpriteImageIdx], a
+ ret
+
+Data_fd731:
+ db SPRITE_FACING_DOWN
+ db SPRITE_FACING_LEFT
+ db SPRITE_FACING_UP
+ db SPRITE_FACING_RIGHT
+ db SPRITE_FACING_DOWN
+Data_fd731End:
+
+PikaMovementFunc2_Timer:
+ push hl
+ ld hl, wPlayerIntraAnimFrameCounter - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ inc a
+ and $3
+ ld [hli], a
+ jr nz, .load_pop
+ ld a, [hl]
+ inc a
+ and $3
+ ld [hl], a
+.load_pop
+ ld a, [hl]
+ pop hl
+ ret
+
+PikaMovementFunc2_GetImageBaseOffset:
+ push hl
+ ld hl, wPlayerSpriteImageBaseOffset - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ dec a
+ swap a
+ pop hl
+ ret
+
+PikaMovementFunc2_GetSpriteImageIdxDirection:
+ push hl
+ ld hl, wPlayerSpriteImageIdx - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ and $c
+ pop hl
+ ret
+
+GetPikachuFacing:
+ push hl
+ ld hl, wPlayerFacingDirection - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ and $c
+ pop hl
+ ret
+
+SetPikachuFacing:
+ push hl
+ ld hl, wPlayerFacingDirection - wPlayerSpriteStateData1
+ add hl, bc
+ add a
+ add a
+ and $c
+ ld [hl], a
+ pop hl
+ ret
+
+CheckPikachuStepTimer1:
+ ld hl, wPikachuStepTimer
+ inc [hl]
+ ld a, [wCurPikaMovementParam1]
+ and $1f
+ inc a
+ cp [hl]
+ ret nz
+ ld [hl], 0
+ ret
+
+GetPikachuStepVectorMagnitude:
+ ; *XX*****
+ ld a, [wCurPikaMovementParam1]
+ swap a
+ rrca
+ and $3
+ inc a
+ ret
+
+CheckPikachuStepTimer2:
+ ld hl, wPikachuStepSubtimer
+ inc [hl]
+ ld a, [wCurPikaMovementParam2]
+ and $f
+ inc a
+ cp [hl]
+ ret nz
+ ld [hl], 0
+ ret
+
+PikaMovementFunc_Sine:
+ call .GetArgument
+ ld a, [wPikachuStepSubtimer]
+ add e
+ ld [wPikachuStepSubtimer], a
+ add $20
+ ld e, a
+ push hl
+ push bc
+ call Sine_e
+ pop bc
+ pop hl
+ ret
+
+.GetArgument:
+ ld a, [wCurPikaMovementParam2]
+ and $f
+ inc a
+ ld d, a
+ ld a, [wCurPikaMovementParam2]
+ swap a
+ and $7
+ ld e, a
+ ld a, 1
+ jr z, .okay
+.loop
+ add a
+ dec e
+ jr nz, .loop
+.okay
+ ld e, a
+ ret
+
+ApplyPikachuStepVector:
+ push bc
+ ld c, a
+ ld b, 0
+ ld hl, .StepVectors
+ add hl, bc
+ add hl, bc
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ pop bc
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
+ add hl, bc
+ ld a, [hl]
+ add e
+ ld [hli], a
+ ld a, [hl]
+ add d
+ ld [hl], a
+ ret
+
+.StepVectors:
+ db 0, 1
+ db 0, -1
+ db -1, 0
+ db 1, 0
+ db -1, 1
+ db 1, 1
+ db -1, -1
+ db 1, -1
+
+LoadPikachuShadowOAMData:
+ push bc
+ push de
+ push hl
+
+ ld bc, wOAMBuffer + 4 * 36
+ ld a, [wPikaSpriteY]
+ ld e, a
+ ld a, [wPikaSpriteX]
+ ld d, a
+ ld hl, .OAMData
+ call .LoadOAMData
+
+ pop hl
+ pop de
+ pop bc
+ ret
+
+.OAMData:
+ db 2
+ db $0c, $00, $ff, 0
+ db $0c, $08, $ff, 1 << OAM_X_FLIP
+
+.LoadOAMData:
+ ld a, e
+ add $10
+ ld e, a
+ ld a, d
+ add $8
+ ld d, a
+ ld a, [hli]
+.loop
+ push af
+ ld a, [hli]
+ add e
+ ld [bc], a
+ inc bc
+ ld a, [hli]
+ add d
+ ld [bc], a
+ inc bc
+ ld a, [hli]
+ ld [bc], a
+ inc bc
+ ld a, [hli]
+ ld [bc], a
+ inc bc
+ pop af
+ dec a
+ jr nz, .loop
+ ret
+
+LoadPikachuShadowIntoVRAM:
+ ld hl, vNPCSprites2 + $7f * $10
+ ld de, LedgeHoppingShadowGFX_3F
+ lb bc, BANK(LedgeHoppingShadowGFX_3F), (LedgeHoppingShadowGFX_3FEnd - LedgeHoppingShadowGFX_3F) / 8
+ jp CopyVideoDataDoubleAlternate
+
+LedgeHoppingShadowGFX_3F:
+INCBIN "gfx/ledge_hopping_shadow.1bpp"
+LedgeHoppingShadowGFX_3FEnd:
+
+LoadPikachuBallIconIntoVRAM:
+ ld hl, vNPCSprites2 + $7e * $10
+ ld de, GFX_fd86b
+ lb bc, BANK(GFX_fd86b), 1
+ jp CopyVideoDataDoubleAlternate
+
+Func_fd851:
+ ld hl, vNPCSprites + $c * $10
+ ld a, 3
+.loop
+ push af
+ push hl
+ ld de, GFX_fd86b
+ lb bc, BANK(GFX_fd86b), 4
+ call CopyVideoDataAlternate
+ pop hl
+ ld de, 4 * $10
+ add hl, de
+ pop af
+ dec a
+ jr nz, .loop
+ ret
+
+GFX_fd86b:
+INCBIN "gfx/unknown_fd86b.2bpp"
+
+LoadPikachuSpriteIntoVRAM:
+ ld de, PikachuSprite
+ lb bc, BANK(PikachuSprite), (SandshrewSprite - PikachuSprite) / 32
+ ld hl, vNPCSprites + $c * $10
+ push bc
+ call CopyVideoDataAlternate
+ ld de, PikachuSprite + $c * $10
+ ld hl, vNPCSprites2 + $c * $10
+ ld a, [h_0xFFFC]
+ and a
+ jr z, .load
+ ld de, PikachuSprite + $c * $10
+ ld hl, vNPCSprites2 + $4c * $10
+.load
+ pop bc
+ call CopyVideoDataAlternate
+ call LoadPikachuShadowIntoVRAM
+ call LoadPikachuBallIconIntoVRAM
+ ret
+
+PikachuPewterPokecenterCheck:
+ ld a, [wCurMap]
+ cp PEWTER_POKECENTER
+ ret nz
+ call EnablePikachuFollowingPlayer
+ call StarterPikachuEmotionCommand_turnawayfromplayer
+ ret
+
+PikachuFanClubCheck:
+ ld a, [wCurMap]
+ cp POKEMON_FAN_CLUB
+ ret nz
+ call EnablePikachuFollowingPlayer
+ call StarterPikachuEmotionCommand_turnawayfromplayer
+ ret
+
+PikachuBillsHouseCheck:
+ ld a, [wCurMap]
+ cp BILLS_HOUSE
+ ret nz
+ call EnablePikachuFollowingPlayer
+ ret
+
+Pikachu_LoadCurrentMapViewUpdateSpritesAndDelay3:
+ call LoadCurrentMapView
+ call UpdateSprites
+ call Delay3
+ ret
+
+Cosine_e: ; cosine?
+ ld a, e
+ add $10
+ jr asm_fd908
+
+Sine_e: ; sine?
+ ld a, e
+asm_fd908
+ and $3f
+ cp $20
+ jr nc, .asm_fd913
+ call GetSine
+ ld a, h
+ ret
+
+.asm_fd913
+ and $1f
+ call GetSine
+ ld a, h
+ cpl
+ inc a
+ ret
+
+GetSine:
+ ld e, a
+ ld a, d
+ ld d, 0
+ ld hl, SineWave_3f
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld hl, 0
+.asm_fd92b
+ srl a
+ jr nc, .asm_fd930
+ add hl, de
+.asm_fd930
+ sla e
+ rl d
+ and a
+ jr nz, .asm_fd92b
+ ret
+
+SineWave_3f:
+ sine_wave $100
diff --git a/engine/pikachu_pcm.asm b/engine/pikachu_pcm.asm
new file mode 100755
index 00000000..043f702c
--- /dev/null
+++ b/engine/pikachu_pcm.asm
@@ -0,0 +1,154 @@
+PlayPikachuSoundClip::
+ ld a, e
+ ld e, a
+ ld d, $0
+ ld hl, PikachuCriesPointerTable
+ add hl, de
+ add hl, de
+ add hl, de
+ ld b, [hl] ; bank of pikachu cry data
+ inc hl
+ ld a, [hli] ; cry data pointer
+ ld h, [hl]
+ ld l, a
+ ld c, $4
+.loop
+ dec c
+ jr z, .done_delay
+ call DelayFrame
+ jr .loop
+
+.done_delay
+ di
+ push bc
+ push hl
+ ld a, $80
+ ld [rNR52], a
+ ld a, $77
+ ld [rNR50], a
+ xor a
+ ld [rNR30], a
+ ld hl, $ff30 ; wave data
+ ld de, wRedrawRowOrColumnSrcTiles
+.saveWaveDataLoop
+ ld a, [hl]
+ ld [de], a
+ inc de
+ ld a, $ff
+ ld [hli], a
+ ld a, l
+ cp $40 ; end of wave data
+ jr nz, .saveWaveDataLoop
+ ld a, $80
+ ld [rNR30], a
+ ld a, [rNR51]
+ or $44
+ ld [rNR51], a
+ ld a, $ff
+ ld [rNR31], a
+ ld a, $20
+ ld [rNR32], a
+ ld a, $ff
+ ld [rNR33], a
+ ld a, $87
+ ld [rNR34], a
+ pop hl
+ pop bc
+ call PlayPikachuPCM
+ xor a
+ ld [wc0f3], a
+ ld [wc0f4], a
+ ld a, $80
+ ld [rNR52], a
+ xor a
+ ld [rNR30], a
+ ld hl, $ff30
+ ld de, wRedrawRowOrColumnSrcTiles
+.reloadWaveDataLoop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, l
+ cp $40 ; end of wave data
+ jr nz, .reloadWaveDataLoop
+ ld a, $80
+ ld [rNR30], a
+ ld a, [rNR51]
+ and $bb
+ ld [rNR51], a
+ xor a
+ ld [wChannelSoundIDs+CH4], a
+ ld [wChannelSoundIDs+CH5], a
+ ld [wChannelSoundIDs+CH6], a
+ ld [wChannelSoundIDs+CH7], a
+ ld a, [H_LOADEDROMBANK]
+ ei
+ ret
+
+PikachuCriesPointerTable:
+; format:
+; db bank
+; dw pointer to cry
+
+; bank 21
+ pikacry_def PikachuCry1 ; 21:4000
+ pikacry_def PikachuCry2 ; 21:491a
+ pikacry_def PikachuCry3 ; 21:4fdc
+ pikacry_def PikachuCry4 ; 21:59ee
+
+; bank 22
+ pikacry_def PikachuCry5 ; 22:4000
+ pikacry_def PikachuCry6 ; 22:5042
+ pikacry_def PikachuCry7 ; 22:6254
+
+; bank 23
+ pikacry_def PikachuCry8 ; 23:4000
+ pikacry_def PikachuCry9 ; 23:50ca
+ pikacry_def PikachuCry10 ; 23:5e0c
+
+; bank 24
+ pikacry_def PikachuCry11 ; 24:4000
+ pikacry_def PikachuCry12 ; 24:4722
+ pikacry_def PikachuCry13 ; 24:54a4
+
+; bank 25
+ pikacry_def PikachuCry14 ; 25:4000
+ pikacry_def PikachuCry15 ; 25:589a
+
+; banks 31-34, in no particular order
+
+ pikacry_def PikachuCry16 ; 31:4000
+ pikacry_def PikachuCry17 ; 34:4000
+ pikacry_def PikachuCry18 ; 31:549a
+ pikacry_def PikachuCry19 ; 33:4000
+ pikacry_def PikachuCry20 ; 32:4000
+ pikacry_def PikachuCry21 ; 32:6002
+ pikacry_def PikachuCry22 ; 31:63a4
+ pikacry_def PikachuCry23 ; 34:4862
+ pikacry_def PikachuCry24 ; 33:5632
+ pikacry_def PikachuCry25 ; 34:573c
+ pikacry_def PikachuCry26 ; 33:725c
+
+; bank 35
+ pikacry_def PikachuCry27 ; 35:4000
+ pikacry_def PikachuCry28 ; 35:4b5a
+ pikacry_def PikachuCry29 ; 35:5da4
+ pikacry_def PikachuCry30 ; 35:69ce
+ pikacry_def PikachuCry31 ; 35:6e80
+
+; bank 36
+ pikacry_def PikachuCry32 ; 36:4000
+ pikacry_def PikachuCry33 ; 36:458a
+ pikacry_def PikachuCry34 ; 36:523c
+
+; bank 37
+ pikacry_def PikachuCry35 ; 37:4000
+ pikacry_def PikachuCry36 ; 37:522a
+
+; banks 36-38
+ pikacry_def PikachuCry37 ; 38:4000
+ pikacry_def PikachuCry38 ; 38:4dfa
+ pikacry_def PikachuCry39 ; 37:6e0c
+ pikacry_def PikachuCry40 ; 38:5a64
+ pikacry_def PikachuCry41 ; 36:6746
+ pikacry_def PikachuCry42 ; 38:6976
diff --git a/engine/pikachu_pic_animation.asm b/engine/pikachu_pic_animation.asm
new file mode 100755
index 00000000..c04382c1
--- /dev/null
+++ b/engine/pikachu_pic_animation.asm
@@ -0,0 +1,851 @@
+GetPikaPicAnimationScriptIndex:
+ ld hl, PikachuMoodLookupTable
+ ld a, [wPikachuMood]
+ ld d, a
+.get_mood_param
+ ld a, [hli]
+ inc hl
+ cp d
+ jr c, .get_mood_param
+ dec hl
+ ld e, [hl]
+ ld hl, PikaPicAnimationScriptPointerLookupTable
+ ld a, [wPikachuHappiness]
+ ld d, a
+ ld bc, 6
+.get_happiness_param
+ ld a, [hl]
+ cp d
+ jr nc, .got_animation
+ add hl, bc
+ jr .get_happiness_param
+
+.got_animation
+ ld d, 0
+ add hl, de
+ ld a, [hl]
+ ret
+
+PikachuMoodLookupTable:
+; First byte: mood threshold
+; Second byte: column index in PikaPicAnimationScriptPointerLookupTable
+ db 40, 1
+ db 127, 2
+ db 128, 3
+ db 210, 4
+ db 255, 5
+
+PikaPicAnimationScriptPointerLookupTable:
+; First byte: happiness threshold
+; Remaining bytes: loaded based on Pikachu's mood
+ db 50
+ dpikapic PikaPicAnimScript14
+ dpikapic PikaPicAnimScript14
+ dpikapic PikaPicAnimScript6
+ dpikapic PikaPicAnimScript13
+ dpikapic PikaPicAnimScript13
+
+ db 100
+ dpikapic PikaPicAnimScript9
+ dpikapic PikaPicAnimScript9
+ dpikapic PikaPicAnimScript5
+ dpikapic PikaPicAnimScript12
+ dpikapic PikaPicAnimScript12
+
+ db 130
+ dpikapic PikaPicAnimScript3
+ dpikapic PikaPicAnimScript3
+ dpikapic PikaPicAnimScript1
+ dpikapic PikaPicAnimScript8
+ dpikapic PikaPicAnimScript8
+
+ db 160
+ dpikapic PikaPicAnimScript3
+ dpikapic PikaPicAnimScript3
+ dpikapic PikaPicAnimScript4
+ dpikapic PikaPicAnimScript15
+ dpikapic PikaPicAnimScript15
+
+ db 200
+ dpikapic PikaPicAnimScript17
+ dpikapic PikaPicAnimScript17
+ dpikapic PikaPicAnimScript7
+ dpikapic PikaPicAnimScript2
+ dpikapic PikaPicAnimScript2
+
+ db 250
+ dpikapic PikaPicAnimScript17
+ dpikapic PikaPicAnimScript17
+ dpikapic PikaPicAnimScript16
+ dpikapic PikaPicAnimScript10
+ dpikapic PikaPicAnimScript10
+
+ db 255
+ dpikapic PikaPicAnimScript17
+ dpikapic PikaPicAnimScript17
+ dpikapic PikaPicAnimScript19
+ dpikapic PikaPicAnimScript20
+ dpikapic PikaPicAnimScript20
+
+StarterPikachuEmotionCommand_pikapic:
+ ld a, [H_AUTOBGTRANSFERENABLED]
+ push af
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [de]
+ ld [wPikaPicAnimNumber], a
+ inc de
+ push de
+ call .RunPikapic
+ pop de
+ pop af
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ret
+
+.RunPikapic:
+ call PlacePikapicTextBoxBorder
+ callab LoadOverworldPikachuFrontpicPalettes
+ call ResetPikaPicAnimBuffer
+ call LoadCurrentPikaPicAnimScriptPointer
+ call ExecutePikaPicAnimScript
+ call PlacePikapicTextBoxBorder
+ call RunDefaultPaletteCommand
+ ret
+
+ResetPikaPicAnimBuffer:
+ ld hl, wCurPikaMovementData
+ ld bc, wCurPikaMovementDataEnd - wCurPikaMovementData
+ xor a
+ call FillMemory
+ ld hl, wPikaPicAnimObjectDataBufferSize
+ ld bc, wPikaPicAnimObjectDataBufferEnd - wPikaPicAnimObjectDataBufferSize
+ xor a
+ call FillMemory
+ call ClearPikaPicUsedGFXBuffer
+ ld hl, 100
+ ld a, l
+ ld [wPikaPicAnimTimer], a
+ ld a, h
+ ld [wPikaPicAnimTimer + 1], a
+ ld a, $7
+ ld [wPikaPicPikaDrawStartX], a
+ ld a, $6
+ ld [wPikaPicPikaDrawStartY], a
+ ret
+
+PlacePikapicTextBoxBorder:
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ coord hl, 6, 5
+ lb bc, 5, 5
+ call TextBoxBorder
+ call Delay3
+ call UpdateSprites
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Delay3
+ ret
+
+LoadCurrentPikaPicAnimScriptPointer:
+ ld a, [wPikaPicAnimNumber]
+ cp $1d
+ jr c, .valid
+ ld a, $0
+.valid
+ ld e, a
+ ld d, 0
+ ld hl, PikaPicAnimPointers
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call UpdatePikaPicAnimPointer
+ ret
+
+PikaPicAnimPointers:
+pikapic_def: macro
+\1_id: dw \1
+endm
+
+ pikapic_def PikaPicAnimScript0 ; 00
+ pikapic_def PikaPicAnimScript1 ; 01
+ pikapic_def PikaPicAnimScript2 ; 02
+ pikapic_def PikaPicAnimScript3 ; 03
+ pikapic_def PikaPicAnimScript4 ; 04
+ pikapic_def PikaPicAnimScript5 ; 05
+ pikapic_def PikaPicAnimScript6 ; 06
+ pikapic_def PikaPicAnimScript7 ; 07
+ pikapic_def PikaPicAnimScript8 ; 08
+ pikapic_def PikaPicAnimScript9 ; 09
+ pikapic_def PikaPicAnimScript10 ; 0a
+ pikapic_def PikaPicAnimScript11 ; 0b
+ pikapic_def PikaPicAnimScript12 ; 0c
+ pikapic_def PikaPicAnimScript13 ; 0d
+ pikapic_def PikaPicAnimScript14 ; 0e
+ pikapic_def PikaPicAnimScript15 ; 0f
+ pikapic_def PikaPicAnimScript16 ; 10
+ pikapic_def PikaPicAnimScript17 ; 11
+ pikapic_def PikaPicAnimScript18 ; 12
+ pikapic_def PikaPicAnimScript19 ; 13
+ pikapic_def PikaPicAnimScript20 ; 14
+ pikapic_def PikaPicAnimScript21 ; 15
+ pikapic_def PikaPicAnimScript22 ; 16
+ pikapic_def PikaPicAnimScript23 ; 17
+ pikapic_def PikaPicAnimScript24 ; 18
+ pikapic_def PikaPicAnimScript25 ; 19
+ pikapic_def PikaPicAnimScript26 ; 1a
+ pikapic_def PikaPicAnimScript27 ; 1b
+ pikapic_def PikaPicAnimScript28 ; 1c
+ pikapic_def PikaPicAnimScript29 ; 1d
+
+ExecutePikaPicAnimScript:
+.loop
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call RunPikaPicAnimSetupScript
+ call DummyFunction_fdad5
+ call AnimateCurrentPikaPicAnimFrame
+ call DummyFunction_fdad5
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call PikaPicAnimTimerAndJoypad
+ and a
+ jr z, .loop
+ ret
+
+PikaPicAnimTimerAndJoypad:
+ call Delay3
+ call CheckPikaPicAnimTimer
+ and a
+ ret nz
+ call JoypadLowSensitivity
+ ld a, [hJoyPressed]
+ and A_BUTTON | B_BUTTON
+ ret
+
+CheckPikaPicAnimTimer:
+ ld hl, wPikaPicAnimTimer
+ dec [hl]
+ jr nz, .not_done_yet
+ inc hl
+ ld a, [hl]
+ and a
+ jr z, .timer_expired
+ dec [hl]
+.not_done_yet
+ xor a
+ ret
+
+.timer_expired
+ ld a, $1
+ ret
+
+DummyFunction_fdad5:
+ ret
+
+AnimateCurrentPikaPicAnimFrame:
+ ld bc, wPikaPicAnimObjectDataBuffer
+ ld a, 4
+.loop
+ push af
+ push bc
+ ld hl, 0 ; struct index
+ add hl, bc
+ ld a, [hli]
+ and a
+ jr z, .skip
+ ld a, [hli]
+ ld [wCurPikaPicAnimObjectScriptIdx], a
+ ld a, [hli]
+ ld [wCurPikaPicAnimObjectFrameIdx], a
+ ld a, [hli]
+ ld [wCurPikaPicAnimObjectFrameTimer], a
+ ld a, [hli]
+ ld [wCurPikaPicAnimObjectVTileOffset], a
+ ld a, [hli]
+ ld [wCurPikaPicAnimObjectXOffset], a
+ ld a, [hli]
+ ld [wCurPikaPicAnimObjectYOffset], a
+ ld a, [hli]
+ ld [wCurPikaPicAnimObject + 6], a
+ push bc
+ call LoadPikaPicAnimObjectData
+ pop bc
+ ld hl, 1 ; script index
+ add hl, bc
+ ld a, [wCurPikaPicAnimObjectScriptIdx]
+ ld [hli], a
+ ld a, [wCurPikaPicAnimObjectFrameIdx]
+ ld [hli], a
+ ld a, [wCurPikaPicAnimObjectFrameTimer]
+ ld [hli], a
+ ld a, [wCurPikaPicAnimObjectVTileOffset]
+ ld [hli], a
+ ld a, [wCurPikaPicAnimObjectXOffset]
+ ld [hli], a
+ ld a, [wCurPikaPicAnimObjectYOffset]
+ ld [hli], a
+ ld a, [wCurPikaPicAnimObject + 6]
+ ld [hl], a
+.skip
+ pop bc
+ ld hl, 8
+ add hl, bc
+ ld b, h
+ ld c, l
+ pop af
+ dec a
+ jr nz, .loop
+ ret
+
+PikaPicAnimCommand_object:
+ ld hl, wPikaPicAnimObjectDataBuffer
+ ld de, 8
+ ld c, 4
+.loop
+ ld a, [hl]
+ and a
+ jr z, .found
+ add hl, de
+ dec c
+ jr nz, .loop
+ scf
+ ret
+
+.found
+ ld a, [wPikaPicAnimObjectDataBufferSize]
+ inc a
+ ld [wPikaPicAnimObjectDataBufferSize], a
+ ld [hli], a
+ call GetPikaPicAnimByte
+ ld [hli], a
+ call GetPikaPicAnimByte
+ ld [hl], a
+ xor a
+ ld [hli], a ; overloads
+ ld [hli], a
+ call GetPikaPicAnimByte
+ ld [hli], a
+ call GetPikaPicAnimByte
+ ld [hli], a
+ call GetPikaPicAnimByte
+ ld [hli], a
+ and a
+ ret
+
+PikaPicAnimCommand_deleteobject:
+ call GetPikaPicAnimByte
+ ld b, a
+ ld hl, wPikaPicAnimObjectDataBuffer
+ ld de, 8
+ ld c, 4
+.search
+ ld a, [hl]
+ cp b
+ jr z, .delete
+ add hl, de
+ dec c
+ jr nz, .search
+ scf
+ ret
+
+.delete
+ xor a
+ ld [hl], a
+ ret
+
+LoadPikaPicAnimObjectData:
+.loop
+ ld a, [wCurPikaPicAnimObjectScriptIdx]
+ cp $23
+ jr c, .valid
+ ld a, $4
+.valid
+ ld e, a
+ ld d, 0
+ ld hl, PikaPicAnimBGFramesPointers
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [wCurPikaPicAnimObjectFrameIdx]
+ ld e, a
+ ld d, 0
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ cp $e0
+ jr z, .end
+ jr .init
+
+.end
+ xor a
+ ld [wCurPikaPicAnimObjectFrameIdx], a
+ ld [wCurPikaPicAnimObjectFrameTimer], a
+ jr .loop
+
+.init
+ push hl
+ call LoadCurPikaPicObjectTilemap
+ pop hl
+ ld a, [hl]
+ and a
+ jr z, .not_done ; lasts forever
+ ld a, [wCurPikaPicAnimObjectFrameTimer]
+ inc a
+ ld [wCurPikaPicAnimObjectFrameTimer], a
+ cp [hl]
+ jr nz, .not_done
+ xor a
+ ld [wCurPikaPicAnimObjectFrameTimer], a
+ ld a, [wCurPikaPicAnimObjectFrameIdx]
+ inc a
+ ld [wCurPikaPicAnimObjectFrameIdx], a
+.not_done
+ ret
+
+INCLUDE "data/pikachu_pic_objects.asm"
+
+LoadCurPikaPicObjectTilemap:
+ and a
+ ret z
+ ld e, a
+ ld d, 0
+ ld hl, PikaPicTilemapPointers
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld a, [de]
+ ld c, a
+ inc de
+ ld a, [de]
+ ld b, a
+ inc de
+ push de
+ push bc
+ call .GetStartCoords
+ pop bc
+ pop de
+.row
+ push bc
+ push hl
+ ld a, [wCurPikaPicAnimObjectVTileOffset] ; tile id offset
+ ld c, a
+.col
+ ld a, [de]
+ inc de
+ cp $ff
+ jr z, .skip
+ add c
+ ld [hl], a
+.skip
+ inc hl
+ dec b
+ jr nz, .col
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec c
+ jr nz, .row
+ ret
+
+.GetStartCoords:
+ push bc
+ ld a, [wCurPikaPicAnimObjectYOffset] ; Y offset
+ ld b, a
+ ld a, [wPikaPicPikaDrawStartY]
+ add b
+ coord hl, 0, 0
+ ld bc, SCREEN_WIDTH
+ call AddNTimes
+ ld a, [wCurPikaPicAnimObjectXOffset] ; X offset
+ ld c, a
+ ld a, [wPikaPicPikaDrawStartX]
+ add c
+ ld c, a
+ ld b, 0
+ add hl, bc
+ pop bc
+ ret
+
+INCLUDE "data/pikachu_pic_tilemaps.asm"
+
+LoadPikaPicAnimGFXHeader:
+ push hl
+ ld e, a
+ ld d, 0
+ ld hl, PikaPicAnimGFXHeaders
+ add hl, de
+ add hl, de
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld c, a
+ ld a, [hli]
+ ld b, a
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ pop hl
+ ret
+
+RunPikaPicAnimSetupScript:
+ call .CheckAndAdvanceTimer
+ ret c
+ xor a
+ ld [wPikaPicAnimPointerSetupFinished], a
+.loop
+ call GetPikaPicAnimByte
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call JumpToAddress
+ ld a, [wPikaPicAnimPointerSetupFinished]
+ and a
+ jr z, .loop
+ ret
+
+.CheckAndAdvanceTimer:
+ ld a, [wPikaPicAnimDelay]
+ and a
+ ret z
+ dec a
+ ld [wPikaPicAnimDelay], a
+ scf
+ ret
+
+.Jumptable:
+ dw PikaPicAnimCommand_nop ; 00, 0 params
+ dw PikaPicAnimCommand_writebyte ; 01, 1 param
+ dw PikaPicAnimCommand_loadgfx ; 02, 1 param
+ dw PikaPicAnimCommand_object ; 03, 5 params
+ dw PikaPicAnimCommand_nop4 ; 04, 0 params
+ dw PikaPicAnimCommand_nop5 ; 05, 0 params
+ dw PikaPicAnimCommand_deleteobject ; 06, 1 param
+ dw PikaPicAnimCommand_nop7 ; 07, 0 params
+ dw PikaPicAnimCommand_nop8 ; 08, 0 params
+ dw PikaPicAnimCommand_jump ; 09, 1 dw param
+ dw PikaPicAnimCommand_setduration ; 0a, 1 dw param
+ dw PikaPicAnimCommand_cry ; 0b, 1 param
+ dw PikaPicAnimCommand_thunderbolt ; 0c, 0 params
+ dw PikaPicAnimCommand_run ; 0d, 0 params (ret)
+ dw PikaPicAnimCommand_ret ; 0e, 0 params (ret)
+
+PikaPicAnimCommand_nop:
+ ret
+
+PikaPicAnimCommand_ret:
+ ld a, 1
+ ld [wPikaPicAnimTimer], a
+ xor a
+ ld [wPikaPicAnimTimer + 1], a
+ jr PikaPicAnimCommand_run
+
+; XXX
+ ret
+
+PikaPicAnimCommand_setduration:
+ call GetPikaPicAnimByte
+ ld [wPikaPicAnimTimer], a
+ call GetPikaPicAnimByte
+ ld [wPikaPicAnimTimer + 1], a
+ ret
+
+PikaPicAnimCommand_run:
+ ld a, $ff
+ ld [wPikaPicAnimPointerSetupFinished], a
+ ret
+
+PikaPicAnimCommand_writebyte:
+ call GetPikaPicAnimByte
+ ld [wPikaPicAnimDelay], a
+ ret
+
+PikaPicAnimCommand_nop4:
+PikaPicAnimCommand_nop5:
+PikaPicAnimCommand_nop7:
+PikaPicAnimCommand_nop8:
+ ret
+
+PikaPicAnimCommand_jump:
+ call GetPikaPicAnimByte
+ ld l, a
+ call GetPikaPicAnimByte
+ ld h, a
+ call UpdatePikaPicAnimPointer
+ ret
+
+GetPikaPicAnimByte:
+ push hl
+ ld hl, wPikaPicAnimPointer
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld a, [hli]
+ call UpdatePikaPicAnimPointer
+ pop hl
+ ret
+
+UpdatePikaPicAnimPointer:
+ push af
+ ld a, l
+ ld [wPikaPicAnimPointer], a
+ ld a, h
+ ld [wPikaPicAnimPointer + 1], a
+ pop af
+ ret
+
+PikaPicAnimCommand_loadgfx:
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ ld a, [H_AUTOBGTRANSFERENABLED]
+ push af
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, [hTilesetType]
+ push af
+ xor a
+ ld [hTilesetType], a
+ call GetPikaPicAnimByte
+ ld [wPikaPicAnimCurGraphicID], a
+ ld a, [wPikaPicAnimCurGraphicID]
+ call LoadPikaPicAnimGFXHeader
+ ld a, c
+ cp a, $ff
+ jr z, .compressed
+ call RequestPikaPicAnimGFX
+ jr .done
+
+.compressed
+ call DecompressRequestPikaPicAnimGFX
+.done
+ pop af
+ ld [hTilesetType], a
+ pop af
+ ld [H_AUTOBGTRANSFERENABLED], a
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ ret
+
+RequestPikaPicAnimGFX: ; fe114
+ push de
+ ld a, [wPikaPicAnimCurGraphicID]
+ ld d, a
+ ld e, c
+ call CheckIfThereIsRoomForPikaPicAnimGFX
+ pop de
+ jr c, .failed
+ call GetPikaPicVRAMAddressForNewGFX
+ call CopyVideoDataAlternate
+ and a
+.failed
+ ret
+
+DecompressRequestPikaPicAnimGFX: ; fe128
+ push de
+ ld a, [wPikaPicAnimCurGraphicID]
+ ld d, a
+ ld e, 5 * 5
+ call CheckIfThereIsRoomForPikaPicAnimGFX
+ pop de
+ jr c, .failed
+ ld a, b
+ call UncompressSpriteFromDE
+ ld a, BANK(sSpriteBuffer1)
+ call SwitchSRAMBankAndLatchClockData
+ ld hl, sSpriteBuffer1
+ ld de, sSpriteBuffer0
+ ld bc, SPRITEBUFFERSIZE * 2
+ call CopyData
+ call PrepareRTCDataAndDisableSRAM
+ ld a, [wPikaPicAnimCurGraphicID]
+ call LookUpTileOffsetForCurrentPikaPicAnimGFX
+ call GetPikaPicVRAMAddressForNewGFX
+ ld d, h
+ ld e, l
+ call InterlaceMergeSpriteBuffers
+.failed
+ ret
+
+ClearPikaPicUsedGFXBuffer:
+ ld hl, wPikaPicUsedGFXCount
+ ld bc, wPikaPicUsedGFXEnd - wPikaPicUsedGFXCount
+ xor a
+ call FillMemory
+ ret
+
+GetPikaPicVRAMAddressForNewGFX:
+ ld hl, vNPCSprites
+ push bc
+ ld b, a
+ and $f
+ swap a
+ ld c, a
+ ld a, b
+ and $f0
+ swap a
+ ld b, a
+ add hl, bc
+ pop bc
+ ret
+
+CheckIfThereIsRoomForPikaPicAnimGFX:
+; d: idx
+; e: size
+; FATAL: If the graphic has already been loaded, or if there are
+; already 8 graphics objects loaded, the game will execute arbitrary
+; code.
+ push bc
+ push hl
+ ld hl, wPikaPicUsedGFX
+ ld c, 8
+.loop
+ ld a, [hl]
+ and a
+ jr z, .empty
+ cp d
+ jr z, .found
+ inc hl
+ inc hl
+ dec c
+ jr nz, .loop
+ scf
+ ret ; execute hl, then bc
+
+.found
+ inc hl
+ ld a, [hl]
+ ret ; execute hl, then bc
+
+.empty
+ ld [hl], d
+ inc hl
+ ld a, [wPikaPicUsedGFXCount]
+ add $80
+ ld [hl], a
+ ld a, [wPikaPicUsedGFXCount]
+ add e
+ ld [wPikaPicUsedGFXCount], a
+ cp $80
+ jr z, .okay
+ jr nc, .failed
+.okay
+ ld a, [hl]
+ and a
+ jr .pop_ret
+
+.failed
+ scf
+.pop_ret
+ pop hl
+ pop bc
+ ret
+
+LookUpTileOffsetForCurrentPikaPicAnimGFX:
+ push bc
+ push hl
+ ld b, a
+ ld hl, wPikaPicUsedGFX
+ ld c, 8
+.loop
+ ld a, [hli]
+ cp b
+ jr z, .found
+ inc hl
+ dec c
+ jr nz, .loop
+ scf
+ jr .pop_ret
+
+.found
+ ld a, [hl]
+ and a
+.pop_ret
+ pop hl
+ pop bc
+ ret
+
+PikaPicAnimCommand_cry:
+ call GetPikaPicAnimByte
+ cp $ff
+ ret z
+ ld e, a
+ callab PlayPikachuSoundClip
+ ret
+
+PikaPicAnimCommand_thunderbolt:
+ ld a, $1
+ ld [wMuteAudioAndPauseMusic], a
+ call DelayFrame
+ ld a, [wAudioROMBank]
+ push af
+ ld a, BANK(SFX_Thunderbolt)
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
+ call .LoadAudio
+ call PlaySound
+ call .FlashScreen
+ call WaitForSoundToFinish
+ pop af
+ ld [wAudioROMBank], a
+ ld [wAudioSavedROMBank], a
+ xor a
+ ld [wMuteAudioAndPauseMusic], a
+ ret
+
+.LoadAudio:
+ ld hl, MoveSoundTable
+ ld e, THUNDERBOLT
+ ld d, 0
+ add hl, de
+ add hl, de
+ add hl, de
+ ld a, BANK(MoveSoundTable)
+ call GetFarByte
+ ld b, a
+ inc hl
+ ld a, BANK(MoveSoundTable)
+ call GetFarByte
+ inc hl
+ ld [wFrequencyModifier], a
+ ld a, BANK(MoveSoundTable)
+ call GetFarByte
+ ld [wTempoModifier], a
+ ld a, b
+ ret
+
+.FlashScreen:
+ ld hl, PikaPicAnimThunderboltPals
+.loop
+ ld a, [hli]
+ cp $ff
+ ret z
+ ld c, a
+ ld b, [hl]
+ inc hl
+ push hl
+ call .UpdatePal
+ pop hl
+ jr .loop
+
+.UpdatePal:
+ ld a, b
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ call DelayFrames
+ ret
+
+INCLUDE "data/pikachu_pic_animation.asm"
diff --git a/engine/pikachu_status.asm b/engine/pikachu_status.asm
new file mode 100755
index 00000000..c73d3b3f
--- /dev/null
+++ b/engine/pikachu_status.asm
@@ -0,0 +1,258 @@
+IsStarterPikachuInOurParty::
+ ld hl, wPartySpecies
+ ld de, wPartyMon1OTID
+ ld bc, wPartyMonOT
+ push hl
+.loop
+ pop hl
+ ld a, [hli]
+ push hl
+ inc a
+ jr z, .noPlayerPikachu
+ cp PIKACHU + 1
+ jr nz, .curMonNotPlayerPikachu
+ ld h, d
+ ld l, e
+ ld a, [wPlayerID]
+ cp [hl]
+ jr nz, .curMonNotPlayerPikachu
+ inc hl
+ ld a, [wPlayerID+1]
+ cp [hl]
+ jr nz, .curMonNotPlayerPikachu
+ push de
+ push bc
+ ld hl, wPlayerName
+ ld d, $6 ; possible player length - 1
+.nameCompareLoop
+ dec d
+ jr z, .sameOT
+ ld a, [bc]
+ inc bc
+ cp [hl]
+ inc hl
+ jr z, .nameCompareLoop
+ pop bc
+ pop de
+.curMonNotPlayerPikachu
+ ld hl, wPartyMon2 - wPartyMon1
+ add hl, de
+ ld d, h
+ ld e, l
+ ld hl, NAME_LENGTH
+ add hl, bc
+ ld b, h
+ ld c, l
+ jr .loop
+
+.sameOT
+ pop bc
+ pop de
+ ld h, d
+ ld l, e
+ ld bc, -NAME_LENGTH
+ add hl, bc
+ ld a, [hli]
+ or [hl]
+ jr z, .noPlayerPikachu ; XXX how is this determined?
+ pop hl
+ scf
+ ret
+
+.noPlayerPikachu
+ pop hl
+ and a
+ ret
+
+IsThisPartymonStarterPikachu_Box::
+ ld hl, wBoxMon1
+ ld bc, wBoxMon2 - wBoxMon1
+ ld de, wBoxMonOT
+ jr asm_fce21
+
+IsThisPartymonStarterPikachu_Party::
+IsThisPartymonStarterPikachu::
+ ld hl, wPartyMon1
+ ld bc, wPartyMon2 - wPartyMon1
+ ld de, wPartyMonOT
+asm_fce21:
+ ld a, [wWhichPokemon]
+ call AddNTimes
+ ld a, [hl]
+ cp PIKACHU
+ jr nz, .notPlayerPikachu
+ ld bc, wPartyMon1OTID - wPartyMon1
+ add hl, bc
+ ld a, [wPlayerID]
+ cp [hl]
+ jr nz, .notPlayerPikachu
+ inc hl
+ ld a, [wPlayerID+1]
+ cp [hl]
+ jr nz, .notPlayerPikachu
+ ld h, d
+ ld l, e
+ ld a, [wWhichPokemon]
+ ld bc, NAME_LENGTH
+ call AddNTimes
+ ld de, wPlayerName
+ ld b, $6
+.loop
+ dec b
+ jr z, .isPlayerPikachu
+ ld a, [de]
+ inc de
+ cp [hl]
+ inc hl
+ jr z, .loop
+.notPlayerPikachu
+ and a
+ ret
+
+.isPlayerPikachu
+ scf
+ ret
+
+UpdatePikachuMoodAfterBattle::
+; because d is always $82 at this function, it serves to
+; ensure Pikachu's mood is at least 130 after battle
+ push de
+ call IsStarterPikachuInOurParty
+ pop de
+ ret nc
+ ld a, d
+ cp 128
+ ld a, [wPikachuMood]
+ jr c, .d_less_than_128 ; we never jump
+ cp d
+ jr c, .load_d_into_mood
+ ret
+
+.d_less_than_128
+ cp d
+ ret c
+.load_d_into_mood
+ ld a, d
+ ld [wPikachuMood], a
+ ret
+
+CheckPikachuFaintedOrStatused::
+; function to test if Pikachu is alive?
+ xor a
+ ld [wWhichPokemon], a
+ ld hl, wPartyCount
+.loop
+ inc hl
+ ld a, [hl]
+ cp $ff
+ jr z, .dead_or_not_in_party
+ push hl
+ call IsThisPartymonStarterPikachu_Party
+ pop hl
+ jr nc, .next
+ ld a, [wWhichPokemon]
+ ld hl, wPartyMon1HP
+ ld bc, wPartyMon2 - wPartyMon1
+ call AddNTimes
+ ld a, [hli]
+ or [hl]
+ ld d, a
+ inc hl
+ inc hl
+ ld a, [hl] ; status
+ and a
+ jr nz, .alive
+ jr .dead_or_not_in_party
+
+.next
+ ld a, [wWhichPokemon]
+ inc a
+ ld [wWhichPokemon], a
+ jr .loop
+
+.alive
+ scf
+ ret
+
+.dead_or_not_in_party
+ and a
+ ret
+
+IsSurfingPikachuInThePlayersParty::
+ ld hl, wPartySpecies
+ ld de, wPartyMon1Moves
+ ld bc, wPartyMonOT
+ push hl
+.loop
+ pop hl
+ ld a, [hli]
+ push hl
+ inc a
+ jr z, .noSurfingPlayerPikachu
+ cp PIKACHU+1
+ jr nz, .curMonNotSurfingPlayerPikachu
+ ld h, d
+ ld l, e
+ push hl
+ push bc
+ ld b, NUM_MOVES
+.moveSearchLoop
+ ld a, [hli]
+ cp SURF
+ jr z, .foundSurfingPikachu
+ dec b
+ jr nz, .moveSearchLoop
+ pop bc
+ pop hl
+ jr .curMonNotSurfingPlayerPikachu
+
+.foundSurfingPikachu
+ pop bc
+ pop hl
+ inc hl
+ inc hl
+ inc hl
+ inc hl
+ ld a, [wPlayerID]
+ cp [hl]
+ jr nz, .curMonNotSurfingPlayerPikachu
+ inc hl
+ ld a, [wPlayerID+1]
+ cp [hl]
+ jr nz, .curMonNotSurfingPlayerPikachu
+ push de
+ push bc
+ ld hl, wPlayerName
+ ld d, $6
+.nameCompareLoop
+ dec d
+ jr z, .foundSurfingPlayerPikachu
+ ld a, [bc]
+ inc bc
+ cp [hl]
+ inc hl
+ jr z, .nameCompareLoop
+ pop bc
+ pop de
+.curMonNotSurfingPlayerPikachu
+ ld hl, wPartyMon2 - wPartyMon1
+ add hl, de
+ ld d, h
+ ld e, l
+ ld hl, NAME_LENGTH
+ add hl, bc
+ ld b, h
+ ld c, l
+ jr .loop
+
+.foundSurfingPlayerPikachu
+ pop bc
+ pop de
+ pop hl
+ scf
+ ret
+
+.noSurfingPlayerPikachu
+ pop hl
+ and a
+ ret
diff --git a/engine/play_time.asm b/engine/play_time.asm
deleted file mode 100755
index a5202cc6..00000000
--- a/engine/play_time.asm
+++ /dev/null
@@ -1,61 +0,0 @@
-TrackPlayTime:
- call CountDownIgnoreInputBitReset
- ld a, [wd732]
- bit 0, a
- ret z
- ld a, [wPlayTimeMaxed]
- and a
- ret nz
- ld a, [wPlayTimeFrames]
- inc a
- ld [wPlayTimeFrames], a
- cp 60
- ret nz
- xor a
- ld [wPlayTimeFrames], a
- ld a, [wPlayTimeSeconds]
- inc a
- ld [wPlayTimeSeconds], a
- cp 60
- ret nz
- xor a
- ld [wPlayTimeSeconds], a
- ld a, [wPlayTimeMinutes]
- inc a
- ld [wPlayTimeMinutes], a
- cp 60
- ret nz
- xor a
- ld [wPlayTimeMinutes], a
- ld a, [wPlayTimeHours]
- inc a
- ld [wPlayTimeHours], a
- cp $ff
- ret nz
- ld a, $ff
- ld [wPlayTimeMaxed], a
- ret
-
-CountDownIgnoreInputBitReset:
- ld a, [wIgnoreInputCounter]
- and a
- jr nz, .asm_18e40
- ld a, $ff
- jr .asm_18e41
-.asm_18e40
- dec a
-.asm_18e41
- ld [wIgnoreInputCounter], a
- and a
- ret nz
- ld a, [wd730]
- res 1, a
- res 2, a
- bit 5, a
- res 5, a
- ld [wd730], a
- ret z
- xor a
- ld [hJoyPressed], a
- ld [hJoyHeld], a
- ret
diff --git a/engine/pokedex_rating.asm b/engine/pokedex_rating.asm
index f8e29e5c..97bbfc24 100755
--- a/engine/pokedex_rating.asm
+++ b/engine/pokedex_rating.asm
@@ -26,7 +26,7 @@ DisplayDexRating:
CheckAndResetEventA EVENT_HALL_OF_FAME_DEX_RATING
jr nz, .hallOfFame
push hl
- ld hl, PokedexRatingText_441cc
+ ld hl, DexCompletionText
call PrintText
pop hl
call PrintText
@@ -51,104 +51,104 @@ DisplayDexRating:
ld [de], a
ret
-PokedexRatingText_441cc:
- TX_FAR _OaksLabText_441cc
+DexCompletionText:
+ TX_FAR _DexCompletionText
db "@"
DexRatingsTable:
db 10
- dw PokedexRatingText_44201
+ dw DexRatingText_Own0To9
db 20
- dw PokedexRatingText_44206
+ dw DexRatingText_Own10To19
db 30
- dw PokedexRatingText_4420b
+ dw DexRatingText_Own20To29
db 40
- dw PokedexRatingText_44210
+ dw DexRatingText_Own30To39
db 50
- dw PokedexRatingText_44215
+ dw DexRatingText_Own40To49
db 60
- dw PokedexRatingText_4421a
+ dw DexRatingText_Own50To59
db 70
- dw PokedexRatingText_4421f
+ dw DexRatingText_Own60To69
db 80
- dw PokedexRatingText_44224
+ dw DexRatingText_Own70To79
db 90
- dw PokedexRatingText_44229
+ dw DexRatingText_Own80To89
db 100
- dw PokedexRatingText_4422e
+ dw DexRatingText_Own90To99
db 110
- dw PokedexRatingText_44233
+ dw DexRatingText_Own100To109
db 120
- dw PokedexRatingText_44238
+ dw DexRatingText_Own110To119
db 130
- dw PokedexRatingText_4423d
+ dw DexRatingText_Own120To129
db 140
- dw PokedexRatingText_44242
+ dw DexRatingText_Own130To139
db 150
- dw PokedexRatingText_44247
+ dw DexRatingText_Own140To149
db 152
- dw PokedexRatingText_4424c
+ dw DexRatingText_Own150To151
-PokedexRatingText_44201:
- TX_FAR _OaksLabText_44201
+DexRatingText_Own0To9:
+ TX_FAR _DexRatingText_Own0To9
db "@"
-PokedexRatingText_44206:
- TX_FAR _OaksLabText_44206
+DexRatingText_Own10To19:
+ TX_FAR _DexRatingText_Own10To19
db "@"
-PokedexRatingText_4420b:
- TX_FAR _OaksLabText_4420b
+DexRatingText_Own20To29:
+ TX_FAR _DexRatingText_Own20To29
db "@"
-PokedexRatingText_44210:
- TX_FAR _OaksLabText_44210
+DexRatingText_Own30To39:
+ TX_FAR _DexRatingText_Own30To39
db "@"
-PokedexRatingText_44215:
- TX_FAR _OaksLabText_44215
+DexRatingText_Own40To49:
+ TX_FAR _DexRatingText_Own40To49
db "@"
-PokedexRatingText_4421a:
- TX_FAR _OaksLabText_4421a
+DexRatingText_Own50To59:
+ TX_FAR _DexRatingText_Own50To59
db "@"
-PokedexRatingText_4421f:
- TX_FAR _OaksLabText_4421f
+DexRatingText_Own60To69:
+ TX_FAR _DexRatingText_Own60To69
db "@"
-PokedexRatingText_44224:
- TX_FAR _OaksLabText_44224
+DexRatingText_Own70To79:
+ TX_FAR _DexRatingText_Own70To79
db "@"
-PokedexRatingText_44229:
- TX_FAR _OaksLabText_44229
+DexRatingText_Own80To89:
+ TX_FAR _DexRatingText_Own80To89
db "@"
-PokedexRatingText_4422e:
- TX_FAR _OaksLabText_4422e
+DexRatingText_Own90To99:
+ TX_FAR _DexRatingText_Own90To99
db "@"
-PokedexRatingText_44233:
- TX_FAR _OaksLabText_44233
+DexRatingText_Own100To109:
+ TX_FAR _DexRatingText_Own100To109
db "@"
-PokedexRatingText_44238:
- TX_FAR _OaksLabText_44238
+DexRatingText_Own110To119:
+ TX_FAR _DexRatingText_Own110To119
db "@"
-PokedexRatingText_4423d:
- TX_FAR _OaksLabText_4423d
+DexRatingText_Own120To129:
+ TX_FAR _DexRatingText_Own120To129
db "@"
-PokedexRatingText_44242:
- TX_FAR _OaksLabText_44242
+DexRatingText_Own130To139:
+ TX_FAR _DexRatingText_Own130To139
db "@"
-PokedexRatingText_44247:
- TX_FAR _OaksLabText_44247
+DexRatingText_Own140To149:
+ TX_FAR _DexRatingText_Own140To149
db "@"
-PokedexRatingText_4424c:
- TX_FAR _OaksLabText_4424c
+DexRatingText_Own150To151:
+ TX_FAR _DexRatingText_Own150To151
db "@"
diff --git a/engine/predefs.asm b/engine/predefs.asm
index fd11475b..8b26706a 100755
--- a/engine/predefs.asm
+++ b/engine/predefs.asm
@@ -1,66 +1,67 @@
GetPredefPointer:
-; Store the contents of the register
-; pairs (hl, de, bc) at wPredefRegisters.
-; Then put the bank and address of predef
-; wPredefID in [wPredefBank] and hl.
+ ; Store the contents of the register
+ ; pairs (hl, de, bc) at wPredefRegisters.
+ ; Then put the bank and address of predef
+ ; wPredefID in [wPredefBank] and hl.
- ld a,h
- ld [wPredefRegisters],a
- ld a,l
- ld [wPredefRegisters + 1],a
+ ld a, h
+ ld [wPredefRegisters], a
+ ld a, l
+ ld [wPredefRegisters + 1], a
- ld hl,wPredefRegisters + 2
- ld a,d
- ld [hli],a
- ld a,e
- ld [hli],a
+ ld hl, wPredefRegisters + 2
+ ld a, d
+ ld [hli], a
+ ld a, e
+ ld [hli], a
- ld a,b
- ld [hli],a
- ld [hl],c
+ ld a, b
+ ld [hli], a
+ ld [hl], c
- ld hl,PredefPointers
- ld de,0
+ ld hl, PredefPointers
+ ld de, 0
- ld a,[wPredefID]
- ld e,a
+ ld a, [wPredefID]
+ ld e, a
add a
add e
- ld e,a
- jr nc,.next
+ ld e, a
+ jr nc, .nocarry
inc d
-.next
- add hl,de
- ld d,h
- ld e,l
+.nocarry
+ add hl, de
+ ld d, h
+ ld e, l
; get bank of predef routine
- ld a,[de]
- ld [wPredefBank],a
+ ld a, [de]
+ ld [wPredefBank], a
; get pointer
inc de
- ld a,[de]
- ld l,a
+ ld a, [de]
+ ld l, a
inc de
- ld a,[de]
- ld h,a
+ ld a, [de]
+ ld h, a
ret
PredefPointers::
-; these are pointers to ASM routines.
-; they appear to be used in overworld map scripts.
+ ; these are pointers to ASM routines.
+ ; they appear to be used in overworld map scripts.
+ const_def
add_predef DrawPlayerHUDAndHPBar
add_predef CopyUncompressedPicToTilemap
add_predef AnimateSendingOutMon
add_predef ScaleSpriteByTwo
add_predef LoadMonBackPic
add_predef CopyDownscaledMonTiles
- add_predef LoadMissableObjects
+ add_predef Func_f0a7
add_predef HealParty
- add_predef MoveAnimation; 08 play move animation
+ add_predef MoveAnimation ; 08 play move animation (1e:4d97)
add_predef DivideBCDPredef
add_predef DivideBCDPredef2
add_predef AddBCDPredef
@@ -81,9 +82,13 @@ PredefPointers::
add_predef LearnMoveFromLevelUp
add_predef LearnMove
add_predef GetQuantityOfItemInBag
- dbw $03,CheckForHiddenObjectOrBookshelfOrCardKeyDoor ; for these two, the bank number is actually 0
- dbw $03,GiveItem
- add_predef ChangeBGPalColor0_4Frames
+
+ predef_const CheckForHiddenObjectOrBookshelfOrCardKeyDoor
+ predef_const GiveItem
+ dbw $03, CheckForHiddenObjectOrBookshelfOrCardKeyDoor ; home bank
+ dbw $03, GiveItem ; home bank
+
+ add_predef InvertBGPal_4Frames
add_predef FindPathToPlayer
add_predef PredefShakeScreenVertically
add_predef CalcPositionOfPlayerRelativeToNPC
@@ -111,7 +116,7 @@ PredefPointers::
add_predef InternalClockTradeAnim
add_predef TrainerEngage
add_predef IndexToPokedex
- add_predef DisplayPicCenteredOrUpperRight
+ add_predef DisplayPicCenteredOrUpperRight ; 3B display pic? (01:600d)
add_predef UsedCut
add_predef ShowPokedexData
add_predef WriteMonMoves
@@ -122,32 +127,36 @@ PredefPointers::
add_predef CanLearnTM
add_predef TMToMove
add_predef _RunPaletteCommand
- add_predef StarterDex ; 46
+ add_predef StarterDex ; 46 (17:40d4)
add_predef _AddPartyMon
add_predef UpdateHPBar2
add_predef DrawEnemyHUDAndHPBar
add_predef LoadTownMap_Nest
add_predef PrintMonType
- add_predef EmotionBubble
- add_predef EmptyFunc3; return immediately
+ add_predef EmotionBubble ; 4C player exclamation (10:516f)
+ add_predef EmptyFunc3 ; return immediately (01:5b63)
add_predef AskName
add_predef PewterGuys
add_predef SaveSAVtoSRAM2
add_predef LoadSAV2
add_predef LoadSAV
add_predef SaveSAVtoSRAM1
- add_predef DoInGameTradeDialogue
+ add_predef DoInGameTradeDialogue ; 54 initiate trade (1c:5b86)
add_predef HallOfFamePC
add_predef DisplayDexRating
+
+ predef_const _LeaveMapAnim
+ predef_const EnterMapAnim
dbw $1E, _LeaveMapAnim ; wrong bank
dbw $1E, EnterMapAnim ; wrong bank
+
add_predef GetTileTwoStepsInFrontOfPlayer
add_predef CheckForCollisionWhenPushingBoulder
add_predef PrintStrengthTxt
add_predef PickUpItem
add_predef PrintMoveType
add_predef LoadMovePPs
- add_predef DrawHP ; 5F
+ add_predef DrawHP ; 5F (04:5468)
add_predef DrawHP2
add_predef DisplayElevatorFloorMenu
add_predef OaksAideScript
diff --git a/engine/predefs7.asm b/engine/predefs7.asm
index 752bdd1a..bfa0ab57 100755
--- a/engine/predefs7.asm
+++ b/engine/predefs7.asm
@@ -1,6 +1,12 @@
DisplayElevatorFloorMenu:
+ ld hl, wd730
+ ld a, [hl]
+ push af
+ set 6, [hl]
ld hl, WhichFloorText
call PrintText
+ pop af
+ ld [wd730], a
ld hl, wItemList
ld a, l
ld [wListPointer], a
diff --git a/engine/predefs12.asm b/engine/predefsA.asm
index dc79d6f3..b8384150 100755..100644
--- a/engine/predefs12.asm
+++ b/engine/predefsA.asm
@@ -1,14 +1,16 @@
-; b = new colour for BG colour 0 (usually white) for 4 frames
-ChangeBGPalColor0_4Frames:
- call GetPredefRegisters
+; inverts the BGP for 4 (6 on CGB due to lag) frames
+InvertBGPal_4Frames:
+ call GetPredefRegisters ; leftover of red/blue, has no use here
ld a, [rBGP]
- or b
+ xor $ff
ld [rBGP], a
+ call UpdateGBCPal_BGP
ld c, 4
call DelayFrames
ld a, [rBGP]
- and %11111100
+ xor $ff
ld [rBGP], a
+ call UpdateGBCPal_BGP
ret
PredefShakeScreenVertically:
@@ -29,7 +31,7 @@ PredefShakeScreenVertically:
ld [wDisableVBlankWYUpdate], a
ret
-.MutateWY ; 48119 (12:4119)
+.MutateWY ; 2bd81 (a:7d81)
ld a, [$ff96]
xor b
ld [$ff96], a
@@ -57,7 +59,7 @@ PredefShakeScreenHorizontally:
ld [rWX], a
ret
-.MutateWX ; 4813f (12:413f)
+.MutateWX ; 2bda7 (a:4da7)
ld a, [$ff97]
xor b
ld [$ff97], a
diff --git a/engine/print_waiting_text.asm b/engine/print_waiting_text.asm
new file mode 100644
index 00000000..bd2180a1
--- /dev/null
+++ b/engine/print_waiting_text.asm
@@ -0,0 +1,19 @@
+PrintWaitingText:
+ coord hl, 3, 10
+ lb bc, 1, 11
+ ld a, [wIsInBattle]
+ and a
+ jr z, .asm_4b9a
+ call TextBoxBorder
+ jr .asm_4b9d
+.asm_4b9a
+ call CableClub_TextBoxBorder
+.asm_4b9d
+ coord hl, 4, 11
+ ld de, WaitingText
+ call PlaceString
+ ld c, 50
+ jp DelayFrames
+
+WaitingText:
+ db "Waiting...!@"
diff --git a/engine/printer.asm b/engine/printer.asm
new file mode 100644
index 00000000..46eb2c59
--- /dev/null
+++ b/engine/printer.asm
@@ -0,0 +1,999 @@
+ const_def
+ const PRINTER_STATUS_BLANK
+ const PRINTER_STATUS_CHECKING_LINK
+ const PRINTER_STATUS_TRANSMITTING
+ const PRINTER_STATUS_PRINTING
+ const PRINTER_ERROR_1
+ const PRINTER_ERROR_2
+ const PRINTER_ERROR_3
+ const PRINTER_ERROR_4
+ const PRINTER_ERROR_WRONG_DEVICE
+
+INCLUDE "engine/printer/serial.asm"
+
+PrintPokedexEntry:
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ xor a
+ ld [wUpdateSpritesEnabled], a
+ ld [hCanceledPrinting], a
+ call Printer_PlayPrinterMusic
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $9
+ ld [rIE], a
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Printer_GetDexEntryRegisters
+ call Printer_StartTransmission
+ ld a, [wPrinterPokedexMonIsOwned]
+ and a
+ jr z, .not_caught
+ ld a, 16
+ jr .got_size
+
+.not_caught
+ ld a, 19
+.got_size
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call ClearScreen
+ callab Pokedex_DrawInterface
+ callab Pokedex_PlacePokemonList
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call .TryPrintPage
+ jr c, .finish_printing
+ ld a, [wPrinterPokedexMonIsOwned]
+ and a
+ jr z, .finish_printing
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ ld c, $c
+ call DelayFrames
+ call SaveScreenTilesToBuffer1
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Printer_PrepareDexEntryForPrinting
+ ld a, $7
+ call Printer_StartTransmission
+ ld a, $3
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call LoadScreenTilesFromBuffer1
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call .TryPrintPage
+.finish_printing
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ call ReloadMapAfterPrinter
+ call Printer_PlayMapMusic
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ ret
+
+.TryPrintPage:
+ call Printer_ResetJoypadHRAM
+.print_loop
+ call JoypadLowSensitivity
+ call Printer_CheckPressingB
+ jr c, .pressed_b
+ ld a, [wPrinterSendState]
+ bit 7, a
+ jr nz, .completed
+ call PrinterTransmissionJumptable
+ call GBPrinter_CheckForErrors
+ call GBPrinter_UpdateStatusMessage
+ call DelayFrame
+ jr .print_loop
+
+.completed
+ and a
+ ret
+
+.pressed_b
+ scf
+ ret
+
+Printer_GetDexEntryRegisters:
+ callab DrawDexEntryOnScreen
+ ld a, l
+ ld [wPrinterPokedexEntryTextPointer], a
+ ld a, h
+ ld [wPrinterPokedexEntryTextPointer + 1], a
+ ld a, $0
+ rla ; copy carry flag state to bit 0
+ ld [wPrinterPokedexMonIsOwned], a
+ and a
+ jr z, .not_caught
+ ld a, $5
+ jr .got_num_rows
+
+.not_caught
+ ld a, $9
+.got_num_rows
+ ret
+
+Printer_PrepareDexEntryForPrinting:
+ call ClearScreen
+ callab Pokedex_PrepareDexEntryForPrinting
+ ret
+
+PrintSurfingMinigameHighScore:
+ xor a
+ ld [hCanceledPrinting], a
+ call Printer_PlayPrinterMusic
+ call Printer_PrepareSurfingMinigameHighScoreTileMap
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $9
+ ld [rIE], a
+ call StartTransmission_Send9Rows
+ ld a, $13
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call Printer_ResetJoypadHRAM
+.loop
+ call JoypadLowSensitivity
+ call Printer_CheckPressingB
+ jr c, .quit
+ ld a, [wPrinterSendState]
+ bit 7, a
+ jr nz, .quit
+ call PrinterTransmissionJumptable
+ call GBPrinter_CheckForErrors
+ call GBPrinter_UpdateStatusMessage
+ call DelayFrame
+ jr .loop
+
+.quit
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ call Printer_CopyTileMapFromPrinterTileBuffer
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ call ReloadMapAfterPrinter
+ call Printer_PlayMapMusic
+ ret
+
+PrintDiploma:
+ xor a
+ ld [hCanceledPrinting], a
+ call Printer_PlayPrinterMusic
+ call _DisplayDiploma
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $9
+ ld [rIE], a
+ call StartTransmission_Send9Rows
+ ld a, $10
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call Func_e8d11
+ jr c, .asm_e8cfa
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ ld c, $c
+ call DelayFrames
+ call SaveScreenTilesToBuffer1
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Func_e9ad3
+ call StartTransmission_Send9Rows
+ ld a, $3
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call LoadScreenTilesFromBuffer1
+ call Func_e8d11
+.asm_e8cfa
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ call Printer_CopyTileMapFromPrinterTileBuffer
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ call ReloadMapAfterPrinter
+ call Printer_PlayMapMusic
+ ret
+
+Func_e8d11:
+ call Printer_ResetJoypadHRAM
+.asm_e8d14
+ call JoypadLowSensitivity
+ call Printer_CheckPressingB
+ jr c, .asm_e8d33
+ ld a, [wPrinterSendState]
+ bit 7, a
+ jr nz, .asm_e8d31
+ call PrinterTransmissionJumptable
+ call GBPrinter_CheckForErrors
+ call GBPrinter_UpdateStatusMessage
+ call DelayFrame
+ jr .asm_e8d14
+
+.asm_e8d31
+ and a
+ ret
+
+.asm_e8d33
+ scf
+ ret
+
+PrintPCBox::
+ ld a, [wBoxDataStart]
+ and a
+ jp z, Func_e8df4
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ xor a
+ ld [wUpdateSpritesEnabled], a
+ ld [hCanceledPrinting], a
+ call Printer_PlayPrinterMusic
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $9
+ ld [rIE], a
+ call SaveScreenTilesToBuffer1
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call PrintPCBox_DrawPage1
+ call StartTransmission_Send9Rows
+ ld a, $10
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call LoadScreenTilesFromBuffer1
+ call Func_e8dfb
+ jr c, .asm_e8ddc
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ ld c, 12
+ call DelayFrames
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call PrintPCBox_DrawPage2
+ call StartTransmission_Send9Rows
+ ld a, $0
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call LoadScreenTilesFromBuffer1
+ call Func_e8dfb
+ jr c, .asm_e8ddc
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ ld c, 12
+ call DelayFrames
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call PrintPCBox_DrawPage3
+ call StartTransmission_Send9Rows
+ ld a, $0
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call LoadScreenTilesFromBuffer1
+ call Func_e8dfb
+ jr c, .asm_e8ddc
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ ld c, 12
+ call DelayFrames
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call PrintPCBox_DrawPage4
+ call StartTransmission_Send9Rows
+ ld a, $3
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call LoadScreenTilesFromBuffer1
+ call Func_e8dfb
+.asm_e8ddc
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ call ReloadMapAfterPrinter
+ call Printer_PlayMapMusic
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ ret
+
+Func_e8df4: ; e8df4
+ ld hl, String_e8e1f
+ call PrintText
+ ret
+
+Func_e8dfb: ; e8dfb
+ call Printer_ResetJoypadHRAM
+.asm_e8dfe
+ call JoypadLowSensitivity
+ call Printer_CheckPressingB
+ jr c, .asm_e8e1d
+ ld a, [wPrinterSendState]
+ bit 7, a
+ jr nz, .asm_e8e1b
+ call PrinterTransmissionJumptable
+ call GBPrinter_CheckForErrors
+ call GBPrinter_UpdateStatusMessage
+ call DelayFrame
+ jr .asm_e8dfe
+
+.asm_e8e1b
+ and a
+ ret
+
+.asm_e8e1d
+ scf
+ ret
+
+String_e8e1f: ; e8e1f
+ TX_FAR _NoPokemonText
+ db "@"
+
+PrintFanClubPortrait: ; e8e24
+ xor a
+ ld [hCanceledPrinting], a
+ call Printer_PlayPrinterMusic
+ call Printer_GetMonStats
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $9
+ ld [rIE], a
+ call StartTransmission_Send9Rows
+ ld a, $13
+ ld [wcae2], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call Printer_ResetJoypadHRAM
+.asm_e8e45
+ call JoypadLowSensitivity
+ call Printer_CheckPressingB
+ jr c, .asm_e8e62
+ ld a, [wPrinterSendState]
+ bit 7, a
+ jr nz, .asm_e8e62
+ call PrinterTransmissionJumptable
+ call GBPrinter_CheckForErrors
+ call GBPrinter_UpdateStatusMessage
+ call DelayFrame
+ jr .asm_e8e45
+
+.asm_e8e62
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ call Printer_CopyTileMapFromPrinterTileBuffer
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ call ReloadMapAfterPrinter
+ call Printer_PlayMapMusic
+ ret
+
+PrinterDebug:
+ push af
+ push bc
+ push de
+ push hl
+ call StopAllMusic
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $9
+ ld [rIE], a
+ call StartTransmission_Send9Rows
+ ld a, $13
+ ld [wcae2], a
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Printer_CopyTileMapToPrinterTileBuffer
+ call PrinterDebug_LoadGFX
+.loop
+ ld a, [wPrinterSendState]
+ bit 7, a
+ jr nz, .quit
+ call PrinterDebug_DoFunction
+ call PrinterDebug_ConvertStatusFlagsToTiles
+ call DelayFrame
+ jr .loop
+
+.quit
+ xor a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
+ ld hl, wOAMBuffer + 32 * 4
+ ld bc, 8 * 4
+ xor a
+ call FillMemory
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ pop hl
+ pop de
+ pop bc
+ pop af
+ ret
+
+Printer_CheckPressingB:
+ ld a, [hJoyHeld]
+ and B_BUTTON
+ jr nz, .quit
+ and a
+ ret
+
+.quit
+ ld a, [wPrinterSendState]
+ cp $c
+ jr nz, .already_done
+.wait_current_task
+ ld a, [wPrinterOpcode]
+ and a
+ jr nz, .wait_current_task
+ ld a, $16
+ ld [wPrinterOpcode], a
+ ld a, $88
+ ld [rSB], a
+ ld a, $1
+ ld [rSC], a
+ ld a, $81
+ ld [rSC], a
+.wait_send_cancel
+ ld a, [wPrinterOpcode]
+ and a
+ jr nz, .wait_send_cancel
+.already_done
+ ld a, $1
+ ld [hCanceledPrinting], a
+ scf
+ ret
+
+Printer_CopyTileMapToPrinterTileBuffer:
+ coord hl, 0, 0
+ coord de, 0, 0, wPrinterTileBuffer
+ ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
+ call CopyData
+ ret
+
+Printer_CopyTileMapFromPrinterTileBuffer:
+ coord hl, 0, 0, wPrinterTileBuffer
+ coord de, 0, 0
+ ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
+ call CopyData
+ ret
+
+Printer_ResetJoypadHRAM:
+ xor a
+ ld [hJoyLast], a
+ ld [hJoyReleased], a
+ ld [hJoyPressed], a
+ ld [hJoyHeld], a
+ ld [hJoy5], a
+ ld [hJoy6], a
+ ret
+
+Printer_PlayPrinterMusic:
+ call Printer_FadeOutMusicAndWait
+ ld a, [wAudioROMBank]
+ ld [wAudioSavedROMBank], a
+ ld a, BANK(Music_GBPrinter)
+ ld [wAudioROMBank], a
+ ld a, MUSIC_GB_PRINTER
+ ld [wNewSoundID], a
+ call PlaySound
+ ret
+
+Printer_PlayMapMusic:
+ call Printer_FadeOutMusicAndWait
+ call PlayDefaultMusic
+ ret
+
+Printer_FadeOutMusicAndWait:
+ ld a, $4
+ ld [wAudioFadeOutControl], a
+ call StopAllMusic
+.wait_music_stop
+ ld a, [wAudioFadeOutControl]
+ and a
+ jr nz, .wait_music_stop
+ ret
+
+GBPrinter_CheckForErrors:
+ ld a, [wPrinterHandshake]
+ cp $81
+ jr z, .check_other_errors
+ ld a, [wPrinterStatusFlags]
+ cp $ff
+ jr z, .error2
+ xor a
+ jr .load_status
+
+.check_other_errors
+ ld a, [wPrinterStatusFlags]
+ and %11100000
+ ret z
+ bit 7, a
+ jr nz, .error1
+ bit 6, a
+ jr nz, .error4
+ ; error 3
+ ld a, PRINTER_ERROR_3
+ jr .load_status
+
+.error4
+ ld a, PRINTER_ERROR_4
+ jr .load_status
+
+.error1
+ ld a, PRINTER_ERROR_1
+ jr .load_status
+
+.error2
+ ld a, PRINTER_ERROR_2
+.load_status
+ ld [wPrinterStatusIndicator], a
+ ret
+
+GBPrinter_UpdateStatusMessage:
+ ld a, [wPrinterStatusIndicator]
+ and a
+ ret z
+ push af
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ coord hl, 0, 5
+ lb bc, 10, 18
+ call TextBoxBorder
+ pop af
+ ld e, a
+ ld d, $0
+ ld hl, .PrinterStatusMessages
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ coord hl, 1, 7
+ call PlaceString
+ coord hl, 2, 15
+ ld de, .PressBToCancel
+ call PlaceString
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ xor a
+ ld [wPrinterStatusIndicator], a
+ ret
+
+.PressBToCancel:
+ db "Press B to Cancel@"
+
+.PrinterStatusMessages:
+ dw .Blank
+ dw .CheckingLink
+ dw .Transmitting
+ dw .Printing
+ dw .Error1
+ dw .Error2
+ dw .Error3
+ dw .Error4
+ dw .WrongDevice
+
+.Blank:
+ db "@"
+.CheckingLink:
+ db ""
+ next " CHECKING LINK...@"
+.Transmitting:
+ db ""
+ next " TRANSMITTING...@"
+.Printing:
+ db ""
+ next " PRINTING...@"
+.Error1:
+ db " Printer Error 1"
+ next ""
+ next "Check the Game Boy"
+ next "Printer Manual.@"
+.Error2:
+ db " Printer Error 2"
+ next ""
+ next "Check the Game Boy"
+ next "Printer Manual.@"
+.Error3:
+ db " Printer Error 3"
+ next ""
+ next "Check the Game Boy"
+ next "Printer Manual.@"
+.Error4:
+ db " Printer Error 4"
+ next ""
+ next "Check the Game Boy"
+ next "Printer Manual.@"
+.WrongDevice:
+ db "This is not the"
+ next "Game Boy Printer!@"
+
+Printer_PrepareSurfingMinigameHighScoreTileMap:
+ call GBPalWhiteOutWithDelay3
+ call ClearScreen
+ ld de, SurfingPikachu2Graphics
+ ld hl, vChars2
+ lb bc, BANK(SurfingPikachu2Graphics), (SurfingPikachu2GraphicsEnd - SurfingPikachu2Graphics) / $10
+ call CopyVideoData
+ coord hl, 0, 0
+ call .PlaceRowAlternatingTiles
+ coord hl, 0, 17
+ call .PlaceRowAlternatingTiles
+ coord hl, 0, 0
+ call .PlaceColumnAlternatingTiles
+ coord hl, 19, 0
+ call .PlaceColumnAlternatingTiles
+ ld a, $4
+ coord hl, 0, 0
+ ld [hl], a
+ coord hl, 0, 17
+ ld [hl], a
+ coord hl, 19, 0
+ ld [hl], a
+ coord hl, 19, 17
+ ld [hl], a
+ ld de, .Tilemap1
+ coord hl, 10, 8
+ lb bc, 3, 8
+ call Diploma_Surfing_CopyBox
+ ld de, .Tilemap2
+ coord hl, 2, 11
+ lb bc, 6, 16
+ call Diploma_Surfing_CopyBox
+ ld de, .PikachusBeachString
+ coord hl, 3, 2
+ call PlaceString
+ ld de, .HiScoreString
+ coord hl, 9, 4
+ call PlaceString
+ ld de, .PointsString
+ coord hl, 12, 6
+ call PlaceString
+ ld de, wPlayerName
+ ld hl, wPlayerName
+ ld bc, 0
+.find_end_of_name
+ ld a, [hli]
+ inc c
+ cp "@"
+ jr nz, .find_end_of_name
+ ld a, 8
+ sub c
+ jr nc, .got_name_length
+ xor a
+.got_name_length
+ ld c, a
+ coord hl, 2, 4
+ add hl, bc
+ call PlaceString
+ call CopySurfingMinigameScore
+ ld b, 8
+ call RunPaletteCommand
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Delay3
+ call GBPalNormal
+ ret
+
+.PlaceRowAlternatingTiles:
+ ld c, SCREEN_WIDTH / 2
+.row_loop
+ ld [hl], $0
+ inc hl
+ ld [hl], $1
+ inc hl
+ dec c
+ jr nz, .row_loop
+ ret
+
+.PlaceColumnAlternatingTiles:
+ ld c, SCREEN_HEIGHT / 2
+ ld de, SCREEN_WIDTH
+.col_loop
+ ld [hl], $2
+ add hl, de
+ ld [hl], $3
+ add hl, de
+ dec c
+ jr nz, .col_loop
+ ret
+
+.Tilemap1:
+ db $7f, $7f, $10, $11, $12, $13, $14, $15
+ db $0f, $3c, $3d, $3e, $20, $21, $30, $31
+ db $4c, $4d, $4e, $50, $34, $1a, $51, $2d
+
+.Tilemap2:
+ db $7f, $7f, $7f, $7f, $7f, $7f, $16, $17, $18, $19, $7f, $1b, $1c, $1d, $1e, $1f
+ db $7f, $7f, $22, $23, $24, $25, $26, $27, $28, $29, $2a, $2b, $2c, $7f, $2e, $2f
+ db $7f, $7f, $32, $33, $33, $35, $36, $37, $38, $39, $3a, $3b, $7f, $7f, $7f, $3f
+ db $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4a, $4b, $40, $40, $40, $4f
+ db $52, $52, $52, $53, $54, $55, $56, $57, $58, $59, $5a, $5b, $5c, $5d, $5d, $5e
+ db $7f, $7f, $7f, $05, $06, $07, $08, $09, $0a, $0b, $0c, $0d, $0e, $7f, $7f, $7f
+
+.PikachusBeachString:
+ db "Pikachu's Beach@"
+.HiScoreString:
+ db "'s Hi-Score@"
+.PointsString:
+ db "Points@"
+
+Diploma_Surfing_CopyBox:
+.y
+ push bc
+ push hl
+.x
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .x
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .y
+ ret
+
+CopySurfingMinigameScore:
+ ld de, wSurfingMinigameHiScore + 1
+ coord hl, 7, 6
+ ld a, [de]
+ call .BCDConvertScore
+ ld a, [de]
+.BCDConvertScore:
+ ld c, a
+ swap a
+ and $f
+ add -10
+ ld [hli], a
+ ld a, c
+ and $f
+ add -10
+ ld [hli], a
+ dec de
+ ret
+
+SurfingPikachu2Graphics: INCBIN "gfx/surfing_pikachu_2.2bpp"
+SurfingPikachu2GraphicsEnd:
+
+PrintPCBox_DrawPage1:
+ xor a
+ ld [wBoxNumString], a
+ call ClearScreen
+ call PrintPCBox_PlaceHorizontalLines
+ coord hl, 0, 0
+ ld bc, 11 * SCREEN_WIDTH
+ ld a, " "
+ call FillMemory
+ call PrintPCBox_DrawLeftAndRightBorders
+ call PrintPCBox_DrawTopBorder
+ coord hl, 4, 4
+ ld de, .PokemonListString
+ call PlaceString
+ coord hl, 7, 6
+ ld de, .BoxString
+ call PlaceString
+ coord hl, 11, 6
+ ld a, [wCurrentBoxNum]
+ and $7f
+ cp 9
+ jr c, .less_than_9
+ sub 9
+ ld [hl], "1"
+ inc hl
+ add "0"
+ jr .placed_box_number
+
+.less_than_9
+ add "1"
+.placed_box_number
+ ld [hl], a
+ coord hl, 4, 9
+ ld de, wBoxSpecies
+ ld c, $3
+ call PrintPCBox_PlaceBoxMonInfo
+ ret
+
+.PokemonListString: db "POKéMON LIST@"
+.BoxString: db "BOX@"
+
+PrintPCBox_DrawPage2:
+ call ClearScreen
+ call PrintPCBox_PlaceHorizontalLines
+ call PrintPCBox_DrawLeftAndRightBorders
+ ld a, [wBoxDataStart]
+ cp 4
+ ret c
+ coord hl, 4, 0
+ ld de, wBoxSpecies + 3
+ ld c, 6
+ call PrintPCBox_PlaceBoxMonInfo
+ ret
+
+PrintPCBox_DrawPage3:
+ call ClearScreen
+ call PrintPCBox_PlaceHorizontalLines
+ call PrintPCBox_DrawLeftAndRightBorders
+ ld a, [wBoxDataStart]
+ cp 10
+ ret c
+ coord hl, 4, 0
+ ld de, wBoxSpecies + 9
+ ld c, 6
+ call PrintPCBox_PlaceBoxMonInfo
+ ret
+
+PrintPCBox_DrawPage4:
+ call ClearScreen
+ call PrintPCBox_PlaceHorizontalLines
+ call PrintPCBox_DrawLeftAndRightBorders
+ coord hl, 0, 15
+ call PrintPCBox_DrawBottomBorderAtHL
+ coord hl, 0, 16
+ ld bc, 2 * SCREEN_WIDTH
+ ld a, " "
+ call FillMemory
+ ld a, [wBoxDataStart]
+ cp 16
+ ret c
+ coord hl, 4, 0
+ ld de, wBoxSpecies + 15
+ ld c, 5
+ call PrintPCBox_PlaceBoxMonInfo
+ ret
+
+PrintPCBox_PlaceBoxMonInfo:
+.loop
+ ld a, c
+ and a
+ jr z, .done
+ dec c
+ ld a, [de]
+ cp $ff
+ jr z, .done
+ ld [wd11e], a
+ push bc
+ push hl
+ push de
+ push hl
+ ld bc, 12
+ ld a, " "
+ call FillMemory
+ pop hl
+ push hl
+ ld de, SCREEN_WIDTH
+ add hl, de
+ ld bc, 12
+ ld a, " "
+ call FillMemory
+ pop hl
+ push hl
+ call GetMonName
+ pop hl
+ call PlaceString
+ push hl
+ ld hl, wBoxMonNicks
+ ld bc, NAME_LENGTH
+ ld a, [wBoxNumString]
+ call AddNTimes
+ ld e, l
+ ld d, h
+ pop hl
+ ld bc, SCREEN_WIDTH + 1
+ add hl, bc
+ ld [hl], " "
+ inc hl
+ call PlaceString
+ ld hl, wBoxNumString
+ inc [hl]
+ pop de
+ pop hl
+ ld bc, 3 * SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ inc de
+ jr .loop
+
+.done
+ ret
+
+PrintPCBox_DrawTopBorder:
+ coord hl, 0, 0
+ ld a, $79
+ ld [hli], a
+ ld a, $7a
+ ld c, SCREEN_WIDTH - 2
+.loop
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ld a, $7b
+ ld [hl], a
+ ret
+
+PrintPCBox_DrawLeftAndRightBorders:
+ coord hl, 0, 0
+ ld de, SCREEN_WIDTH - 1
+ ld c, SCREEN_HEIGHT
+.loop
+ ld a, $7c
+ ld [hl], a
+ add hl, de
+ ld a, $7c
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ret
+
+PrintPCBox_DrawBottomBorder:
+ coord hl, 0, 17
+PrintPCBox_DrawBottomBorderAtHL:
+ ld a, $7d
+ ld [hli], a
+ ld a, $7a
+ ld c, SCREEN_WIDTH - 2
+.loop
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ld a, $7e
+ ld [hl], a
+ ret
+
+PrintPCBox_PlaceHorizontalLines:
+ coord hl, 4, 0
+ ld c, 6
+ call .PlaceHorizontalLine
+ coord hl, 6, 1
+ ld c, 6
+.PlaceHorizontalLine:
+.loop
+ push bc
+ push hl
+ ld de, .HorizontalLineString
+ call PlaceString
+ pop hl
+ ld bc, 3 * SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec c
+ jr nz, .loop
+ ret
+
+.HorizontalLineString:
+ db "----------@"
diff --git a/engine/printer/serial.asm b/engine/printer/serial.asm
new file mode 100755
index 00000000..b5d71596
--- /dev/null
+++ b/engine/printer/serial.asm
@@ -0,0 +1,622 @@
+StartTransmission_Send9Rows:
+ ld a, 9
+Printer_StartTransmission:
+ push af
+ ld hl, wPrinterData
+ ld bc, wPrinterDataEnd - wPrinterData
+ xor a
+ call Printer_FillMemory
+ xor a
+ ld [rSB], a
+ ld [rSC], a
+ ld [wPrinterOpcode], a
+ ld hl, wPrinterConnectionOpen
+ set 0, [hl]
+ ld a, [wPrinterSettings]
+ ld [wPrinterSettingsTempCopy], a
+ pop af
+ ld [wPrinterQueueLength], a
+ ret
+
+; e87a8
+PrinterTransmissionJumptable:
+ ld a, [wPrinterSendState]
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.Jumptable:
+ dw Printer_InitSerial ; 00
+ dw Printer_CheckConnectionStatus ; 01
+ dw Printer_WaitSerial ; 02
+ dw Printer_StartTransmittingTilemap ; 03
+ dw Printer_TransmissionLoop ; 04
+ dw Printer_WaitSerialAndLoopBack2 ; 05
+ dw Printer_EndTilemapTransmission ; 06
+ dw Printer_TransmissionLoop ; 07
+ dw Printer_WaitSerial ; 08
+
+ dw Printer_SignalSendHeader ; 09
+ dw Printer_TransmissionLoop ; 0a
+ dw Printer_WaitSerial ; 0b
+ dw Printer_WaitUntilFinished ; 0c
+ dw Printer_Quit ; 0d
+
+ dw Printer_Next_ ; 0e
+ dw Printer_WaitSerial ; 0f
+ dw Printer_SignalLoopBack ; 10
+ dw Printer_LoopBack ; 11
+ dw Printer_WaitLoopBack ; 12
+ dw Printer_WaitLoopBack_ ; 13
+
+Printer_Next:
+ ld hl, wPrinterSendState
+ inc [hl]
+ ret
+
+Printer_Back:
+ ld hl, wPrinterSendState
+ dec [hl]
+ ret
+
+Printer_Quit:
+ xor a
+ ld [wPrinterStatusFlags], a
+ ld hl, wPrinterSendState
+ set 7, [hl]
+ ret
+
+Printer_Next_:
+ call Printer_Next
+ ret
+
+Printer_LoopBack:
+ ld a, $1
+ ld [wPrinterSendState], a
+ ret
+
+Printer_InitSerial:
+ call ResetPrinterData
+ ld hl, PrinterDataPacket1
+ call CopyPrinterDataHeader
+ xor a
+ ld [wPrinterDataSize], a
+ ld [wPrinterDataSize + 1], a
+ ld a, [wPrinterQueueLength]
+ ld [wPrinterRowIndex], a
+ call Printer_Next
+ call Printer_PrepareToSend
+ ld a, PRINTER_STATUS_CHECKING_LINK
+ ld [wPrinterStatusIndicator], a
+ ret
+
+Printer_StartTransmittingTilemap:
+ call ResetPrinterData
+ ld hl, wPrinterRowIndex
+ ld a, [hl]
+ and a
+ jr z, Printer_EndTilemapTransmission
+ ld hl, PrinterDataPacket3
+ call CopyPrinterDataHeader
+ call Printer_Convert2RowsTo2bpp
+ ld a, (wPrinterSendDataSource1End - wPrinterSendDataSource1) % $100
+ ld [wPrinterDataSize], a
+ ld a, (wPrinterSendDataSource1End - wPrinterSendDataSource1) / $100
+ ld [wPrinterDataSize + 1], a
+ call ComputePrinterChecksum
+ call Printer_Next
+ call Printer_PrepareToSend
+ ld a, PRINTER_STATUS_TRANSMITTING
+ ld [wPrinterStatusIndicator], a
+ ret
+
+Printer_EndTilemapTransmission:
+ ld a, $6
+ ld [wPrinterSendState], a
+ ld hl, PrinterDataPacket4
+ call CopyPrinterDataHeader
+ xor a
+ ld [wPrinterDataSize], a
+ ld [wPrinterDataSize + 1], a
+ call Printer_Next
+ call Printer_PrepareToSend
+ ret
+
+Printer_SignalSendHeader:
+ call ResetPrinterData
+ ld hl, PrinterDataPacket2
+ call CopyPrinterDataHeader
+ call Printer_StageHeaderForSend
+ ld a, $4
+ ld [wPrinterDataSize], a
+ ld a, $0
+ ld [wPrinterDataSize + 1], a
+ call ComputePrinterChecksum
+ call Printer_Next
+ call Printer_PrepareToSend
+ ld a, PRINTER_STATUS_PRINTING
+ ld [wPrinterStatusIndicator], a
+ ret
+
+Printer_SignalLoopBack:
+ call ResetPrinterData
+ ld hl, PrinterDataPacket1
+ call CopyPrinterDataHeader
+ xor a
+ ld [wPrinterDataSize], a
+ ld [wPrinterDataSize + 1], a
+ ld a, [wPrinterQueueLength]
+ ld [wPrinterRowIndex], a
+ call Printer_Next
+ call Printer_PrepareToSend
+ ret
+
+Printer_WaitSerial:
+ ld hl, wPrinterSerialFrameDelay
+ inc [hl]
+ ld a, [hl]
+ cp $6
+ ret c
+ xor a
+ ld [hl], a
+ call Printer_Next
+ ret
+
+Printer_WaitSerialAndLoopBack2:
+ ld hl, wPrinterSerialFrameDelay
+ inc [hl]
+ ld a, [hl]
+ cp $6
+ ret c
+ xor a
+ ld [hl], a
+ ld hl, wPrinterRowIndex
+ dec [hl]
+ call Printer_Back
+ call Printer_Back
+ ret
+
+Printer_CheckConnectionStatus:
+ ld a, [wPrinterOpcode]
+ and a
+ ret nz
+ ld a, [wPrinterHandshake]
+ cp $ff
+ jr nz, .asm_e88dc
+ ld a, [wPrinterStatusFlags]
+ cp $ff
+ jr z, .asm_e88f8
+.asm_e88dc
+ ld a, [wPrinterHandshake]
+ cp $81
+ jr nz, .asm_e88f8
+ ld a, [wPrinterStatusFlags]
+ cp $0
+ jr nz, .asm_e88f8
+ ld hl, wPrinterConnectionOpen
+ set 1, [hl]
+ ld a, $5
+ ld [wHandshakeFrameDelay], a
+ call Printer_Next
+ ret
+
+.asm_e88f8
+ ld a, $ff
+ ld [wPrinterHandshake], a
+ ld [wPrinterStatusFlags], a
+ ld a, $e
+ ld [wPrinterSendState], a
+ ret
+
+Printer_TransmissionLoop:
+ ld a, [wPrinterOpcode]
+ and a
+ ret nz
+ ld a, [wPrinterStatusFlags]
+ and $f0
+ jr nz, .asm_e8921
+ ld a, [wPrinterStatusFlags]
+ and $1
+ jr nz, .asm_e891d
+ call Printer_Next
+ ret
+
+.asm_e891d
+ call Printer_Back
+ ret
+
+.asm_e8921
+ ld a, $12
+ ld [wPrinterSendState], a
+ ret
+
+Printer_WaitUntilFinished:
+ ld a, [wPrinterOpcode]
+ and a
+ ret nz
+ ld a, [wPrinterStatusFlags]
+ and $f3
+ ret nz
+ call Printer_Next
+ ret
+
+Printer_WaitLoopBack:
+ call Printer_Next
+Printer_WaitLoopBack_:
+ ld a, [wPrinterOpcode]
+ and a
+ ret nz
+ ld a, [wPrinterStatusFlags]
+ and $f0
+ ret nz
+ xor a
+ ld [wPrinterSendState], a
+ ret
+
+Printer_PrepareToSend:
+.wait_printer_operation
+ ld a, [wPrinterOpcode]
+ and a
+ jr nz, .wait_printer_operation
+ xor a
+ ld [wPrinterSendByteOffset], a
+ ld [wPrinterSendByteOffset + 1], a
+ ld a, $1
+ ld [wPrinterOpcode], a
+ ld a, $88
+ ld [rSB], a
+ ld a, $1
+ ld [rSC], a
+ ld a, $81
+ ld [rSC], a
+ ret
+
+CopyPrinterDataHeader:
+ ld a, [hli]
+ ld [wPrinterDataHeader], a
+ ld a, [hli]
+ ld [wPrinterDataHeader + 1], a
+ ld a, [hli]
+ ld [wPrinterDataHeader + 2], a
+ ld a, [hli]
+ ld [wPrinterDataHeader + 3], a
+ ld a, [hli]
+ ld [wPrinterChecksum], a
+ ld a, [hl]
+ ld [wPrinterChecksum + 1], a
+ ret
+
+ResetPrinterData:
+ xor a
+ ld hl, wPrinterDataHeader
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ld hl, wPrinterChecksum
+ ld [hli], a
+ ld [hl], a
+ xor a
+ ld [wPrinterDataSize], a
+ ld [wPrinterDataSize + 1], a
+ ld hl, wPrinterSendDataSource1
+ ld bc, wPrinterSendDataSource1End - wPrinterSendDataSource1
+ call Printer_FillMemory
+ ret
+
+ComputePrinterChecksum:
+ ld hl, $0
+ ld bc, $4
+ ld de, wPrinterDataHeader
+ call .AddToChecksum
+ ld a, [wPrinterDataSize]
+ ld c, a
+ ld a, [wPrinterDataSize + 1]
+ ld b, a
+ ld de, wPrinterSendDataSource1
+ call .AddToChecksum
+ ld a, l
+ ld [wPrinterChecksum], a
+ ld a, h
+ ld [wPrinterChecksum + 1], a
+ ret
+
+.AddToChecksum:
+.loop
+ ld a, [de]
+ inc de
+ add l
+ jr nc, .no_carry
+ inc h
+.no_carry
+ ld l, a
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ ret
+
+Printer_StageHeaderForSend:
+ ld a, $1
+ ld [wPrinterSendDataSource1], a
+ ld a, [wcae2]
+ ld [wPrinterSendDataSource1 + 1], a
+ ld a, %11100100
+ ld [wPrinterSendDataSource1 + 2], a
+ ld a, [wPrinterSettingsTempCopy]
+ ld [wPrinterSendDataSource1 + 3], a
+ ret
+
+Printer_Convert2RowsTo2bpp:
+ ld a, [wPrinterRowIndex]
+ ld b, a
+ ld a, [wPrinterQueueLength]
+ sub b
+ ld hl, wPrinterTileBuffer
+ ld de, 2 * SCREEN_WIDTH
+.get_row
+ and a
+ jr z, .got_row
+ add hl, de
+ dec a
+ jr .get_row
+
+.got_row
+ ld e, l
+ ld d, h
+ ld hl, wPrinterSendDataSource1
+ ld c, 2 * SCREEN_WIDTH
+.loop
+ ld a, [de]
+ inc de
+ push bc
+ push de
+ push hl
+ swap a
+ ld d, a
+ and $f0
+ ld e, a
+ ld a, d
+ and $f
+ ld d, a
+ and $8
+ ld a, d
+ jr nz, .vchars1
+ or $90
+ jr .got_addr
+
+.vchars1
+ or $80
+.got_addr
+ ld d, a
+ lb bc, BANK(Printer_Convert2RowsTo2bpp), 1
+ call CopyVideoData
+ pop hl
+ ld de, $10
+ add hl, de
+ pop de
+ pop bc
+ dec c
+ jr nz, .loop
+ ret
+
+Printer_FillMemory:
+ push de
+ ld e, a
+.loop
+ ld [hl], e
+ inc hl
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ ld a, e
+ pop de
+ ret
+
+PrinterDataPacket1:
+ db 1, 0, $00, 0
+ dw 1
+PrinterDataPacket2:
+ db 2, 0, $04, 0
+ dw 0
+PrinterDataPacket3:
+ db 4, 0, $80, 2
+ dw 0
+PrinterDataPacket4:
+ db 4, 0, $00, 0
+ dw 4
+PrinterDataPacket5: ; unused
+ db 8, 0, $00, 0
+ dw 8
+PrinterDataPacket6: ; unused
+ db 15, 0, $00, 0
+ dw 15
+
+PrinterSerial_:
+ ld a, [wPrinterOpcode]
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.Jumptable:
+ dw .Nop
+
+ dw .SignalTransmissionStart
+ dw .SendHeaderByte1
+ dw .SendHeaderByte2
+ dw .SendHeaderByte3
+ dw .SendHeaderByte4
+ dw .DataByte
+ dw .SendChecksumLo
+ dw .SendChecksumHi
+ dw .SignalTransmissionEnd
+ dw .Receive1
+ dw .Receive2
+
+ dw .SignalTransmissionStart
+ dw .Send_0F
+ dw .Send_00
+ dw .Send_00
+ dw .Send_00
+ dw .Send_0F
+ dw .Send_00
+ dw .SignalTransmissionEnd
+ dw .Receive1
+ dw .Receive2_
+
+ dw .SignalTransmissionStart
+ dw .SignalQuit
+ dw .Send_00
+ dw .Send_00
+ dw .Send_00
+ dw .SignalQuit
+ dw .Send_00
+ dw .SignalTransmissionEnd
+ dw .Receive1
+ dw .Receive2
+
+.NextInstruction:
+ ld hl, wPrinterOpcode
+ inc [hl]
+ ret
+
+.Nop:
+ ret
+
+.SignalTransmissionStart:
+ ld a, $33
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SendHeaderByte1:
+ ld a, [wPrinterDataHeader]
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SendHeaderByte2:
+ ld a, [wPrinterDataHeader + 1]
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SendHeaderByte3:
+ ld a, [wPrinterDataHeader + 2]
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SendHeaderByte4:
+ ld a, [wPrinterDataHeader + 3]
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.DataByte:
+ ld hl, wPrinterDataSize
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld a, e
+ or d
+ jr z, .sent_last_byte
+ dec de
+ ld [hl], d
+ dec hl
+ ld [hl], e
+ ld a, [wPrinterSendByteOffset]
+ ld e, a
+ ld a, [wPrinterSendByteOffset + 1]
+ ld d, a
+ ld hl, wPrinterSendDataSource1
+ add hl, de
+ inc de
+ ld a, e
+ ld [wPrinterSendByteOffset], a
+ ld a, d
+ ld [wPrinterSendByteOffset + 1], a
+ ld a, [hl]
+ call .SendByte
+ ret
+
+.sent_last_byte
+ call .NextInstruction
+.SendChecksumLo:
+ ld a, [wPrinterChecksum]
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SendChecksumHi:
+ ld a, [wPrinterChecksum + 1]
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SignalTransmissionEnd:
+ ld a, $0
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.Receive1:
+ ld a, [rSB]
+ ld [wPrinterHandshake], a
+ ld a, $0
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.Receive2:
+ ld a, [rSB]
+ ld [wPrinterStatusFlags], a
+ xor a
+ ld [wPrinterOpcode], a
+ ret
+
+.Send_0F:
+ ld a, $f
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.Send_00:
+ ld a, $0
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SignalQuit:
+ ld a, $8
+ call .SendByte
+ call .NextInstruction
+ ret
+
+.SendByte:
+ ld [rSB], a
+ ld a, $1
+ ld [rSC], a
+ ld a, $81
+ ld [rSC], a
+ ret
+
+.Receive2_:
+ ld a, [rSB]
+ ld [wPrinterStatusFlags], a
+ xor a
+ ld [wPrinterOpcode], a
+ ret
diff --git a/engine/remove_pokemon.asm b/engine/remove_pokemon.asm
new file mode 100644
index 00000000..f29a428d
--- /dev/null
+++ b/engine/remove_pokemon.asm
@@ -0,0 +1,95 @@
+_RemovePokemon:
+ ld hl, wPartyCount
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyCount
+ ld hl, wNumInBox
+.usePartyCount
+ 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
+.shiftMonSpeciesLoop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ inc a ; reached terminator?
+ jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species
+ ld hl, wPartyMonOT
+ ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonOTs
+ ld hl, wBoxMonOT
+ ld d, MONS_PER_BOX - 1
+.usePartyMonOTs
+ ld a, [wWhichPokemon]
+ call SkipFixedLengthTextEntries
+ ld a, [wWhichPokemon]
+ cp d ; are we removing the last pokemon?
+ jr nz, .notRemovingLastMon ; if not, shift the pokemon below
+ ld [hl], $ff ; else, write the terminator and return
+ ret
+.notRemovingLastMon
+ ld d, h
+ ld e, l
+ ld bc, NAME_LENGTH
+ add hl, bc
+ ld bc, wPartyMonNicks
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonNicks
+ ld bc, wBoxMonNicks
+.usePartyMonNicks
+ call CopyDataUntil
+ ld hl, wPartyMons
+ ld bc, wPartyMon2 - wPartyMon1
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonStructs
+ ld hl, wBoxMons
+ ld bc, wBoxMon2 - wBoxMon1
+.usePartyMonStructs
+ ld a, [wWhichPokemon]
+ call AddNTimes ; get address of the pokemon removed
+ ld d, h ; store in de for CopyDataUntil
+ ld e, l
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .copyUntilPartyMonOTs
+ ld bc, wBoxMon2 - wBoxMon1
+ add hl, bc ; get address of pokemon after the pokemon removed
+ ld bc, wBoxMonOT ; address of when to stop copying
+ jr .continue
+.copyUntilPartyMonOTs
+ ld bc, wPartyMon2 - wPartyMon1
+ add hl, bc ; get address of pokemon after the pokemon removed
+ ld bc, wPartyMonOT ; address of when to stop copying
+.continue
+ call CopyDataUntil ; shift all pokemon data after the removed mon to the removed mon's location
+ ld hl, wPartyMonNicks
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .usePartyMonNicks2
+ ld hl, wBoxMonNicks
+.usePartyMonNicks2
+ ld bc, NAME_LENGTH
+ ld a, [wWhichPokemon]
+ call AddNTimes
+ ld d, h
+ ld e, l
+ ld bc, NAME_LENGTH
+ add hl, bc
+ ld bc, wPartyMonNicksEnd
+ ld a, [wRemoveMonFromBox]
+ and a
+ jr z, .copyUntilPartyMonNicksEnd
+ ld bc, wBoxMonNicksEnd
+.copyUntilPartyMonNicksEnd
+ jp CopyDataUntil
diff --git a/engine/save.asm b/engine/save.asm
index 4a2ac196..171fd055 100755
--- a/engine/save.asm
+++ b/engine/save.asm
@@ -32,10 +32,8 @@ FileDataDestroyedText:
db "@"
LoadSAV0:
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
+ call EnableSRAMAndLatchClockData
ld a, $1
- ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, sPlayerName ; hero name located in SRAM
ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
@@ -79,10 +77,8 @@ LoadSAV0:
jp SAVGoodChecksum
LoadSAV1:
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
+ call EnableSRAMAndLatchClockData
ld a, $1
- ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, sPlayerName ; hero name located in SRAM
ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
@@ -99,10 +95,8 @@ LoadSAV1:
jp SAVGoodChecksum
LoadSAV2:
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
+ call EnableSRAMAndLatchClockData
ld a, $1
- ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, sPlayerName ; hero name located in SRAM
ld bc, sMainDataCheckSum - sPlayerName ; but here checks the full SAV
@@ -126,9 +120,7 @@ SAVBadCheckSum:
scf
SAVGoodChecksum:
- ld a, $0
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
ret
LoadSAVIgnoreBadCheckSum:
@@ -139,12 +131,16 @@ LoadSAVIgnoreBadCheckSum:
SaveSAV:
callba PrintSaveScreenText
+ ld c,10
+ call DelayFrames
ld hl,WouldYouLikeToSaveText
call SaveSAVConfirm
and a ;|0 = Yes|1 = No|
ret nz
+ ld c,10
+ call DelayFrames
ld a,[wSaveFileStatus]
- dec a
+ cp $1
jr z,.save
call SAVCheckRandomID
jr z,.save
@@ -154,24 +150,20 @@ SaveSAV:
ret nz
.save
call SaveSAVtoSRAM
- coord hl, 1, 13
- lb bc, 4, 18
- call ClearScreenArea
- coord hl, 1, 14
- ld de,NowSavingString
- call PlaceString
- ld c,120
+ ld hl,SavingText
+ call PrintText
+ ld c,128
call DelayFrames
ld hl,GameSavedText
call PrintText
- ld a, SFX_SAVE
+ ld c,10
+ call DelayFrames
+ ld a, $b6 ; SFX_SAVE
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
ld c,30
- jp DelayFrames
-
-NowSavingString:
- db "Now saving...@"
+ call DelayFrames
+ ret
SaveSAVConfirm:
call PrintText
@@ -183,10 +175,14 @@ SaveSAVConfirm:
ld a,[wCurrentMenuItem]
ret
-WouldYouLikeToSaveText: ; 0x7377d
+WouldYouLikeToSaveText:
TX_FAR _WouldYouLikeToSaveText
db "@"
+SavingText:
+ TX_FAR _SavingText
+ db "@"
+
GameSavedText:
TX_FAR _GameSavedText
db "@"
@@ -196,10 +192,8 @@ OlderFileWillBeErasedText:
db "@"
SaveSAVtoSRAM0:
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
+ call EnableSRAMAndLatchClockData
ld a, $1
- ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wPlayerName
ld de, sPlayerName
@@ -223,17 +217,13 @@ SaveSAVtoSRAM0:
ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
ld [sMainDataCheckSum], a
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
ret
SaveSAVtoSRAM1:
; stored pokémon
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
+ call EnableSRAMAndLatchClockData
ld a, $1
- ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wBoxDataStart
ld de, sCurBoxData
@@ -243,16 +233,12 @@ SaveSAVtoSRAM1:
ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
ld [sMainDataCheckSum], a
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
ret
SaveSAVtoSRAM2:
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
+ call EnableSRAMAndLatchClockData
ld a, $1
- ld [MBC1SRamBankingMode], a
ld [MBC1SRamBank], a
ld hl, wPartyDataStart
ld de, sPartyData
@@ -262,15 +248,20 @@ SaveSAVtoSRAM2:
ld de, sMainData
ld bc, wPokedexSeenEnd - wPokedexOwned
call CopyData
+ ld hl, wPikachuHappiness
+ ld de, sMainData + $179
+ ld a, [hli]
+ ld [de], a
+ inc de
+ ld a, [hl]
+ ld [de], a
ld hl, sPlayerName
ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
ld [sMainDataCheckSum], a
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
ret
-
+;;;
SaveSAVtoSRAM:
ld a, $2
ld [wSaveFileStatus], a
@@ -351,13 +342,16 @@ ChangeBox::
call z, EmptyAllSRAMBoxes ; if so, empty all boxes in SRAM
call DisplayChangeBoxMenu
call UpdateSprites
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 1, [hl]
call HandleMenuInput
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 1, [hl]
bit 1, a ; pressed b
ret nz
+ ld a, $b6
+ call PlaySoundWaitForCurrent
+ call WaitForSoundToFinish
call GetBoxSRAMLocation
ld e, l
ld d, h
@@ -380,9 +374,6 @@ ChangeBox::
call SaveSAVtoSRAM
ld hl, wChangeBoxSavedMapTextPointer
call SetMapTextPointer
- ld a, SFX_SAVE
- call PlaySoundWaitForCurrent
- call WaitForSoundToFinish
ret
WhenYouChangeBoxText:
@@ -392,10 +383,7 @@ WhenYouChangeBoxText:
CopyBoxToOrFromSRAM:
; copy an entire box from hl to de with b as the SRAM bank
push hl
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
- ld a, $1
- ld [MBC1SRamBankingMode], a
+ call EnableSRAMAndLatchClockData
ld a, b
ld [MBC1SRamBank], a
ld bc, wBoxDataEnd - wBoxDataStart
@@ -413,9 +401,7 @@ CopyBoxToOrFromSRAM:
call SAVCheckSum
ld [sBank2AllBoxesChecksum], a ; sBank3AllBoxesChecksum
call CalcIndividualBoxCheckSums
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
ret
DisplayChangeBoxMenu:
@@ -436,21 +422,19 @@ DisplayChangeBoxMenu:
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
coord hl, 0, 0
- ld b, 2
- ld c, 9
+ lb bc, 2, 9
call TextBoxBorder
ld hl, ChooseABoxText
call PrintText
coord hl, 11, 0
- ld b, 12
- ld c, 7
+ lb bc, 12, 7
call TextBoxBorder
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
set 2, [hl]
ld de, BoxNames
coord hl, 13, 1
call PlaceString
- ld hl, hFlags_0xFFF6
+ ld hl, hFlags_0xFFFA
res 2, [hl]
ld a, [wCurrentBoxNum]
and $7f
@@ -513,19 +497,14 @@ BoxNoText:
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
+ call EnableSRAMAndLatchClockData
ld a, 2
ld [MBC1SRamBank], a
call EmptySRAMBoxesInBank
ld a, 3
ld [MBC1SRamBank], a
call EmptySRAMBoxesInBank
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
ret
EmptySRAMBoxesInBank:
@@ -559,19 +538,14 @@ EmptySRAMBox:
GetMonCountsForAllBoxes:
ld hl, wBoxMonCounts
push hl
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
- ld a, $1
- ld [MBC1SRamBankingMode], a
+ call EnableSRAMAndLatchClockData
ld a, $2
ld [MBC1SRamBank], a
call GetMonCountsForBoxesInBank
ld a, $3
ld [MBC1SRamBank], a
call GetMonCountsForBoxesInBank
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
pop hl
; copy the count for the current box from WRAM
@@ -604,15 +578,13 @@ 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)s
- ld a,$0a
- ld [MBC1SRamEnable],a
- ld a,$01
- ld [MBC1SRamBankingMode],a
- ld [MBC1SRamBank],a
- ld a,[sPlayerName]
+ call EnableSRAMAndLatchClockData
+ ld a, $1
+ ld [MBC1SRamBank], a
+ ld a, [sPlayerName]
and a
- jr z,.next
- ld hl,sPlayerName
+ jr z, .next
+ ld hl, sPlayerName
ld bc, sMainDataCheckSum - sPlayerName
call SAVCheckSum
ld c,a
@@ -638,7 +610,7 @@ SaveHallOfFameTeams:
ld a, [wNumHoFTeams]
dec a
cp HOF_TEAM_CAPACITY
- jr nc, .asm_73b28
+ jr nc, .shiftHOFTeams
ld hl, sHallOfFame
ld bc, HOF_TEAM
call AddNTimes
@@ -648,7 +620,9 @@ SaveHallOfFameTeams:
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 * (HOF_TEAM_CAPACITY - 1)
@@ -668,34 +642,23 @@ LoadHallOfFameTeams:
; fallthrough
HallOfFame_Copy:
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
- ld a, $1
- ld [MBC1SRamBankingMode], a
+ call EnableSRAMAndLatchClockData
xor a
ld [MBC1SRamBank], a
call CopyData
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ call DisableSRAMAndPrepareClockData
ret
ClearSAV:
- ld a, SRAM_ENABLE
- ld [MBC1SRamEnable], a
- ld a, $1
- ld [MBC1SRamBankingMode], a
- xor a
- call PadSRAM_FF
- ld a, $1
- call PadSRAM_FF
- ld a, $2
- call PadSRAM_FF
- ld a, $3
+ call EnableSRAMAndLatchClockData
+ ld a, $4
+.loop
+ dec a
+ push af
call PadSRAM_FF
- xor a
- ld [MBC1SRamBankingMode], a
- ld [MBC1SRamEnable], a
+ pop af
+ jr nz, .loop
+ call DisableSRAMAndPrepareClockData
ret
PadSRAM_FF:
@@ -704,3 +667,16 @@ PadSRAM_FF:
ld bc, $2000
ld a, $ff
jp FillMemory
+
+EnableSRAMAndLatchClockData:
+ ld a, $1
+ ld [MBC1SRamBankingMode], a
+ ld a, SRAM_ENABLE
+ ld [MBC1SRamEnable], a
+ ret
+
+DisableSRAMAndPrepareClockData:
+ ld a, SRAM_DISABLE
+ ld [MBC1SRamBankingMode], a
+ ld [MBC1SRamEnable], a
+ ret
diff --git a/engine/slot_machine.asm b/engine/slot_machine.asm
index 733cc29c..769a3f37 100755
--- a/engine/slot_machine.asm
+++ b/engine/slot_machine.asm
@@ -23,9 +23,11 @@ PromptUserToPlaySlots:
call LoadFontTilePatterns
ld b, SET_PAL_SLOTS
call RunPaletteCommand
+ call Delay3
call GBPalNormal
ld a, $e4
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
ld hl, wd730
set 6, [hl]
xor a
@@ -80,8 +82,7 @@ MainSlotMachineLoop:
ld [wLastMenuItem], a
ld [wMenuWatchMovingOutOfBounds], a
coord hl, 14, 11
- ld b, 5
- ld c, 4
+ lb bc, 5, 4
call TextBoxBorder
coord hl, 16, 12
ld de, CoinMultiplierSlotMachineText
@@ -457,6 +458,7 @@ SlotMachine_CheckForMatches:
ld a, [rBGP]
xor $40
ld [rBGP], a
+ call UpdateGBCPal_BGP
ld c, 5
call DelayFrames
dec b
@@ -473,6 +475,7 @@ SlotMachine_CheckForMatches:
call SlotMachine_PrintPayoutCoins
ld a, $e4
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
jp .done
SymbolLinedUpSlotMachineText:
@@ -697,6 +700,7 @@ SlotMachine_PayCoinsToPlayer:
ld a, [rOBP0]
xor $40 ; make the slot wheel symbols flash
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
ld a, 5
.skip1
ld [wAnimCounter], a
@@ -851,20 +855,20 @@ LoadSlotMachineTiles:
ld de, vChars0
ld bc, $1c0
ld a, BANK(SlotMachineTiles2)
- call FarCopyData2
+ call FarCopyData
ld hl, SlotMachineTiles1
ld de, vChars2
ld bc, $250
ld a, BANK(SlotMachineTiles1)
- call FarCopyData2
+ call FarCopyData
ld hl, SlotMachineTiles2
ld de, vChars2 + $250
ld bc, $1c0
ld a, BANK(SlotMachineTiles2)
- call FarCopyData2
+ call FarCopyData
ld hl, SlotMachineMap
coord de, 0, 0
- ld bc, $00f0
+ ld bc, SlotMachineMapEnd - SlotMachineMap
call CopyData
call EnableLCD
ld hl, wSlotMachineWheel1Offset
@@ -878,13 +882,9 @@ LoadSlotMachineTiles:
SlotMachineMap:
INCBIN "gfx/tilemaps/slotmachine.map"
+SlotMachineMapEnd:
INCLUDE "data/slot_machine_wheels.asm"
SlotMachineTiles1:
-IF DEF(_RED)
- INCBIN "gfx/red/slotmachine1.2bpp"
-ENDC
-IF DEF(_BLUE)
- INCBIN "gfx/blue/slotmachine1.2bpp"
-ENDC
+ INCBIN "gfx/slotmachine1.2bpp"
diff --git a/engine/subtract_paid_money.asm b/engine/subtract_paid_money.asm
new file mode 100644
index 00000000..a6a6ec2e
--- /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/surfing_minigame.asm b/engine/surfing_minigame.asm
new file mode 100755
index 00000000..48aaca53
--- /dev/null
+++ b/engine/surfing_minigame.asm
@@ -0,0 +1,2862 @@
+SurfingPikachuMinigame:
+ call SurfingPikachuMinigame_BlankPals
+ call DelayFrame
+ call DelayFrame
+ call DelayFrame
+ ld a, [hTilesetType]
+ push af
+ xor a
+ ld [hTilesetType], a
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $f
+ ld [rIE], a
+ ld a, $8
+ ld [rSTAT], a
+ ld a, [H_AUTOBGTRANSFERDEST + 1]
+ push af
+ ld a, $98
+ ld [H_AUTOBGTRANSFERDEST + 1], a
+ call SurfingPikachuMinigameIntro
+ call SurfingPikachuLoop
+ xor a
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ call ClearObjectAnimationBuffers
+ call ClearSprites
+ xor a
+ ld [hLCDCPointer], a
+ ld [hSCX], a
+ ld [hSCY], a
+ ld a, $90
+ ld [hWY], a
+ call DelayFrame
+ pop af
+ ld [H_AUTOBGTRANSFERDEST + 1], a
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ xor a
+ ld [rSTAT], a
+ call RunDefaultPaletteCommand
+ call ReloadMapAfterSurfingMinigame
+ call PlayDefaultMusic
+ call GBPalNormal
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ pop af
+ ld [hTilesetType], a
+ ret
+
+SurfingPikachuLoop:
+ call SurfingPikachuMinigame_LoadGFXAndLayout
+ call DelayFrame
+ ld b, $e
+ call RunPaletteCommand
+.loop
+ ld a, [wSurfingMinigameRoutineNumber]
+ bit 7, a
+ ret nz
+ call SurfingPikachu_GetJoypad_3FrameBuffer
+ call SurfingPikachu_CheckPressedSelect
+ ret nz
+ call RunSurfingMinigameRoutine
+ ld a, $3c
+ ld [wCurrentAnimatedObjectOAMBufferOffset], a
+ call RunObjectAnimations
+ call Func_f8848
+ call .DelayFrame
+ call SurfingMinigame_UpdateMusicTempo
+ jr .loop
+
+.DelayFrame:
+ call DelayFrame
+ ret
+
+SurfingPikachu_CheckPressedSelect:
+ ld hl, wd492
+ bit 1, [hl]
+ ret z
+ ld a, [hJoyPressed]
+ and SELECT
+ ret
+
+Func_f80b7:
+ ld a, [hJoyPressed]
+ and START
+ ret z
+ ld hl, wc5e2
+ ld a, [hl]
+ xor $1
+ ld [hl], a
+ ret
+
+SurfingMinigame_UpdateMusicTempo:
+ ld a, [wc634]
+ and a
+ ret z
+
+ ; check that all channels are on their last frame of note delay
+ ld hl, wChannelNoteDelayCounters
+ ld a, $1
+ cp [hl]
+ ret nz
+ inc hl
+ cp [hl]
+ ret nz
+ inc hl
+ cp [hl]
+ ret nz
+
+ ; de = ([wc5e3] & 0x3f) * 2
+ ld a, [wc5e3]
+ ld e, a
+ ld a, [wc5e3 + 1]
+ and $3
+ ld d, a
+ sla e
+ rl d
+ ld e, d
+ ld d, $0
+ ld hl, .Tempos
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld [wMusicTempo + 1], a
+ ld a, [hl]
+ ld [wMusicTempo], a
+ ret
+
+.Tempos:
+ dw 117
+ dw 109
+ dw 101
+ dw 93
+ dw 85
+
+SurfingMinigame_ResetMusicTempo:
+ ld hl, wChannelNoteDelayCounters
+ ld a, $1
+ cp [hl]
+ ret nz
+ inc hl
+ cp [hl]
+ ret nz
+ inc hl
+ cp [hl]
+ ret nz
+ ld a, 117
+ ld [wMusicTempo + 1], a
+ xor a
+ ld [wMusicTempo], a
+ ret
+
+SurfingPikachuMinigame_LoadGFXAndLayout:
+ call SurfingPikachu_ClearTileMap
+ call ClearSprites
+ call DisableLCD
+ ld hl, wSurfingMinigameData
+ ld bc, wSurfingMinigameDataEnd - wSurfingMinigameData
+ xor a
+ call FillMemory
+ ld hl, wLYOverrides
+ ld bc, wLYOverridesBufferEnd - wLYOverrides
+ xor a
+ call FillMemory
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call ClearObjectAnimationBuffers
+
+ ld hl, SurfingPikachu1Graphics1
+ ld de, $9000
+ ld bc, $500
+ ld a, BANK(SurfingPikachu1Graphics1)
+ call FarCopyData
+
+ ld hl, SurfingPikachu1Graphics2
+ ld de, $8000
+ ld bc, $1000
+ ld a, BANK(SurfingPikachu1Graphics2)
+ call FarCopyData
+
+ ld a, SurfingPikachuSpawnStateDataPointer % $100
+ ld [wAnimatedObjectSpawnStateDataPointer], a
+ ld a, SurfingPikachuSpawnStateDataPointer / $100
+ ld [wAnimatedObjectSpawnStateDataPointer + 1], a
+
+ ld a, SurfingPikachuObjectJumptable % $100
+ ld [wAnimatedObjectJumptablePointer], a
+ ld a, SurfingPikachuObjectJumptable / $100
+ ld [wAnimatedObjectJumptablePointer + 1], a
+
+ ld a, SurfingPikachuOAMData % $100
+ ld [wAnimatedObjectOAMDataPointer], a
+ ld a, SurfingPikachuOAMData / $100
+ ld [wAnimatedObjectOAMDataPointer + 1], a
+
+ ld a, SurfingPikachuFrames % $100
+ ld [wAnimatedObjectFramesDataPointer], a
+ ld a, SurfingPikachuFrames / $100
+ ld [wAnimatedObjectFramesDataPointer + 1], a
+
+ ld hl, vBGMap0
+ ld bc, $800
+ ld a, $0
+ call FillMemory
+
+ ld hl, $98c0
+ ld bc, $180
+ ld a, $b
+ call FillMemory
+
+ ld a, $1
+ lb de, $74, $58
+ call SpawnAnimatedObject
+
+ ld a, $74
+ ld [wSurfingMinigamePikachuObjectHeight], a
+
+ call SurfingMinigame_InitScanlineOverrides
+
+ xor a
+ ld [hSCX], a
+ ld [hSCY], a
+ ld a, $7e
+ ld [hWY], a
+ ld a, rSCY - $ff00
+ ld [hLCDCPointer], a
+ ld a, $40
+ ld [wc5e3], a
+ xor a
+ ld [wc5e3 + 1], a
+ xor a
+ ld [wSurfingMinigamePikachuHP], a
+ ld a, $60
+ ld [wSurfingMinigamePikachuHP + 1], a
+ ld hl, wSurfingMinigameWaveHeight
+ ld bc, $14
+ ld a, $74
+ call FillMemory
+ call Func_f81ff
+ call Func_f8256
+ ld a, $e3
+ ld [rLCDC], a
+ call SurfingPikachuMinigame_SetBGPals
+ ld a, $e4
+ ld [rOBP0], a
+ ld a, $e0
+ ld [rOBP1], a
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ret
+
+SurfingPikachuMinigame_SetBGPals:
+ ld a, [wOnSGB]
+ and a
+ jr nz, .sgb
+ ld a, $d0
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ ret
+
+.sgb
+ ld a, $e4
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ ret
+
+Func_f81ff:
+ ld hl, wSpriteDataEnd
+ ld de, Unkn_f8249
+ ld b, $97
+ ld c, $80
+ ld a, $4
+ call Func_f8233
+ ld de, Unkn_f8248
+ ld b, $96
+ ld c, $50
+ ld a, $1
+ call Func_f8233
+ ld de, Unkn_f824d
+ ld b, $14
+ ld c, $20
+ ld a, $5
+ call Func_f8233
+ ld de, Unkn_f8252
+ ld b, $20
+ ld c, $80
+ ld a, $4
+ call Func_f8233
+ ret
+
+Func_f8233:
+.asm_f8233
+ push af
+ ld [hl], b
+ inc hl
+ ld [hl], c
+ inc hl
+ ld a, [de]
+ ld [hl], a
+ inc hl
+ ld [hl], $0
+ inc hl
+ ld a, c
+ add $8
+ ld c, a
+ inc de
+ pop af
+ dec a
+ jr nz, .asm_f8233
+ ret
+
+Unkn_f8248:
+ db $fe
+
+Unkn_f8249:
+ db $d0
+ db $d0
+ db $d0
+ db $d0
+
+Unkn_f824d:
+ db $ec
+ db $ed
+ db $ed
+ db $ee
+ db $ef
+
+Unkn_f8252:
+ db $ec
+ db $ed
+ db $ee
+ db $ef
+
+Func_f8256:
+ ld de, $9c21
+ ld hl, Unkn_f8279
+ ld c, $9
+.asm_f825e
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .asm_f825e
+ ld hl, $9c01
+ ld [hl], $15
+ ld hl, $9c02
+ ld [hl], $16
+ ld hl, $9c2c
+ ld [hl], $1b
+ ld hl, $9c2d
+ ld [hl], $1c
+ ret
+
+Unkn_f8279:
+ db $17
+ db $18
+ db $19
+ db $19
+ db $19
+ db $19
+ db $19
+ db $19
+ db $19
+
+RunSurfingMinigameRoutine:
+ ld a, [wSurfingMinigameRoutineNumber]
+ ld e, a
+ ld d, $0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.Jumptable:
+ dw SurfingMinigameRoutine_SpawnPikachu ; 0
+ dw SurfingMinigame_RunGame ; 1
+ dw Func_f8324 ; 2
+ dw Func_f835c ; 3
+ dw SurfingMinigame_DrawResultsScreenAndWait ; 4
+ dw SurfingMinigame_WriteHPLeftAndWait ; 5
+ dw SurfingMinigame_WriteRadnessAndWait ; 6
+ dw SurfingMinigame_WriteTotalAndWait ; 7
+ dw SurfingMinigame_AddRemainingHPToTotalAndWait ; 8
+ dw SurfingMinigame_AddRadnessToTotalAndWait ; 9
+ dw SurfingMinigame_WaitLast ; a
+ dw SurfingMinigame_ExitOnPressA ; b
+ dw SurfingMinigame_GameOver ; c
+
+SurfingMinigameRoutine_SpawnPikachu:
+ ld a, $2
+ lb de, $48, $e0
+ call SpawnAnimatedObject
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ld a, $1
+ ld [wc634], a
+ ret
+
+SurfingMinigame_RunGame:
+ ld a, [wc5e5]
+ cp $18
+ jr nc, .asm_f82e8
+ ld hl, wSurfingMinigamePikachuHP
+ ld a, [hli]
+ or [hl]
+ and a
+ jr z, .dead
+ call Random
+ ld [wc5d5], a
+ call SurfingMinigame_UpdateLYOverrides
+ call Func_f88ae
+ call Func_f886b
+ call Func_f8cb0
+ call Func_f844c
+ call SurfingMinigame_Deduct1HP
+ call Func_f88fd
+ ret
+
+.asm_f82e8
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ xor a
+ ld [wc634], a
+ ld a, 192
+ ld [wSurfingMinigameRoutineDelay], a
+ ret
+
+.dead
+ ld a, $1
+ ld [wc630], a
+ ld a, $c
+ ld [wSurfingMinigameRoutineNumber], a
+ ld a, $80
+ ld [wc631], a
+ ld a, $b
+ lb de, $88, $58
+ call SpawnAnimatedObject
+ ld hl, ANIM_OBJ_Y_OFFSET
+ add hl, bc
+ ld [hl], $80
+ ld hl, ANIM_OBJ_FIELD_B
+ add hl, bc
+ ld [hl], $80
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld [hl], $30
+ xor a
+ ld [wc634], a
+ ret
+
+Func_f8324:
+ call SurfingMinigame_RunDelayTimer
+ jr c, .done_delay
+ xor a
+ ld [wc5d5], a
+ call SurfingMinigame_UpdateLYOverrides
+ call Func_f88ae
+ call Func_f886b
+ call Func_f8c97
+ call SurfingMinigame_ResetMusicTempo
+ ret
+
+.done_delay
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ld a, $90
+ ld [hSCX], a
+ ld a, $72
+ ld [wSurfingMinigameWaveFunctionNumber], a
+ ld a, $4
+ ld [wc5d2], a
+ xor a
+ ld [hLCDCPointer], a
+ ld [wSurfingMinigameSCX], a
+ ld [wSurfingMinigameSCX + 1], a
+ ld [wSurfingMinigameSCX + 2], a
+ ret
+
+Func_f835c:
+ ld a, [hSCX]
+ and a
+ jr z, .asm_f837b
+ call SurfingMinigame_UpdateLYOverrides
+ call Func_f88ae
+ call Func_f886b
+ ld a, [hSCX]
+ dec a
+ dec a
+ dec a
+ dec a
+ ld [hSCX], a
+ ld a, $e0
+ ld [wSurfingMinigameXOffset], a
+ call Func_f8cc7
+ ret
+
+.asm_f837b
+ xor a
+ ld [wc5e3], a
+ ld [wc5e3 + 1], a
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ld a, $5
+ ld [wc5d2], a
+ ret
+
+SurfingMinigame_DrawResultsScreenAndWait:
+ call SurfingMinigame_DrawResultsScreen
+ ld a, 32
+ ld [wSurfingMinigameRoutineDelay], a
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ret
+
+SurfingMinigame_WriteHPLeftAndWait:
+ call SurfingMinigame_RunDelayTimer
+ ret nc
+ call SurfingMinigame_WriteHPLeft
+ ld a, 64
+ ld [wSurfingMinigameRoutineDelay], a
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ret
+
+SurfingMinigame_WriteRadnessAndWait:
+ call SurfingMinigame_RunDelayTimer
+ ret nc
+ call SurfingMinigame_WriteRadness
+ ld a, 64
+ ld [wSurfingMinigameRoutineDelay], a
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ret
+
+SurfingMinigame_WriteTotalAndWait:
+ call SurfingMinigame_RunDelayTimer
+ ret nc
+ call SurfingMinigame_WriteTotal
+ ld a, 64
+ ld [wSurfingMinigameRoutineDelay], a
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ret
+
+SurfingMinigame_AddRemainingHPToTotalAndWait:
+ call SurfingMinigame_RunDelayTimer
+ ret nc
+ call SurfingMinigame_AddRemainingHPToTotal
+ push af
+ call SurfingMinigame_BCDPrintTotalScore
+ pop af
+ ret nc
+ ld a, 64
+ ld [wSurfingMinigameRoutineDelay], a
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ret
+
+SurfingMinigame_AddRadnessToTotalAndWait:
+ call SurfingMinigame_RunDelayTimer
+ ret nc
+ call SurfingMinigame_AddRadnessToTotal
+ push af
+ call SurfingMinigame_BCDPrintTotalScore
+ pop af
+ ret nc
+ ld a, 128
+ ld [wSurfingMinigameRoutineDelay], a
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ call DidPlayerGetAHighScore
+ ret nc
+ call SurfingMinigame_PrintTextHiScore
+ ld a, $6
+ ld [wc5d2], a
+ ret
+
+SurfingMinigame_WaitLast:
+ call SurfingMinigame_RunDelayTimer
+ ret nc
+ ld hl, wSurfingMinigameRoutineNumber
+ inc [hl]
+ ret
+
+SurfingMinigame_ExitOnPressA:
+ call SurfingMinigame_UpdateLYOverrides
+ ld a, [hJoyPressed]
+ and A_BUTTON
+ ret z
+ ld hl, wSurfingMinigameRoutineNumber
+ set 7, [hl]
+ ret
+
+SurfingMinigame_GameOver:
+ call SurfingMinigame_UpdateLYOverrides
+ call Func_f88ae
+ call Func_f886b
+ call Func_f8cb0
+ call SurfingMinigame_ResetMusicTempo
+ ld hl, wc631
+ ld a, [hl]
+ and a
+ jr z, .wait_press_a
+ dec [hl]
+ ret
+
+.wait_press_a
+ ld a, [hJoyPressed]
+ and A_BUTTON
+ ret z
+ ld hl, wSurfingMinigameRoutineNumber
+ set 7, [hl]
+ ret
+
+SurfingMinigame_RunDelayTimer:
+ ld hl, wSurfingMinigameRoutineDelay
+ ld a, [hl]
+ and a
+ jr z, .set_carry
+ dec [hl]
+ and a
+ ret
+
+.set_carry
+ scf
+ ret
+
+Func_f844c:
+ ld a, [wc5e5 + 1]
+ ld h, a
+ ld a, [wc5e5 + 2]
+ ld l, a
+ ld a, [wc5e3]
+ ld e, a
+ ld a, [wc5e3 + 1]
+ ld d, a
+ add hl, de
+ ld a, h
+ ld [wc5e5 + 1], a
+ ld a, l
+ ld [wc5e5 + 2], a
+ ret nc
+ ld hl, wc5e5
+ inc [hl]
+ ld hl, wOAMBuffer + 4 * 4 + 1
+ dec [hl]
+ dec [hl]
+ ret
+
+SurfingMinigameAnimatedObjectFn_Pikachu
+ ld a, [wc5d2]
+ ld e, a
+ ld d, $0
+ ld hl, Jumptable_f847f
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+Jumptable_f847f:
+ dw Func_f848d
+ dw SurfingMinigame_ScoreCurrentWave
+ dw Func_f8516
+ dw Func_f8545
+ dw Func_f8561
+ dw Func_f856d
+ dw Func_f8579
+
+Func_f848d:
+ ld a, [wc630]
+ and a
+ jr nz, .asm_f84d2
+ call Func_f87b5
+ ld a, [wSurfingMinigamePikachuObjectHeight]
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld [hl], a
+ call Func_f871e
+ jr c, .splash
+ call Func_f8742
+ call Func_f86b8
+ ret
+
+.splash
+ call Func_f8742
+ ld a, $1 ; on a wave
+ ld [wc5d2], a
+ xor a
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld [hl], a
+ ld hl, ANIM_OBJ_FIELD_D
+ add hl, bc
+ ld [hl], a
+ ld hl, ANIM_OBJ_FIELD_E
+ add hl, bc
+ ld [hl], a
+ ld [wSurfingMinigameRadnessMeter], a
+ ld [wSurfingMinigameTrickFlags], a
+ xor a
+ ld [wChannelSoundIDs + CH7], a
+ ld a, SFX_UNKNOWN_801B3_4
+ call PlaySound
+ ret
+
+.asm_f84d2
+ xor a
+ ld [wc5e3], a
+ ld [wc5e3 + 1], a
+ ld a, $4
+ ld [wc5d2], a
+ call Func_f8742
+ ret
+
+SurfingMinigame_ScoreCurrentWave:
+ call SurfingMinigame_DPadAction
+ call SurfingMinigame_UpdatePikachuHeight
+ ret nc
+ call SurfingMinigame_TileInteraction
+ jr c, .splash
+ call SurfingMinigame_CalculateAndAddRadnessFromStunt
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld [hl], $0
+ ld a, $2
+ ld [wc5d2], a
+ ret
+
+.splash
+ ld a, $3
+ ld [wc5d2], a
+ ld a, $60
+ ld [wc5e1], a
+ ld a, $10
+ call SetCurrentAnimatedObjectCallbackAndResetFrameStateRegisters
+ xor a
+ ld [wChannelSoundIDs + CH7], a
+ ld a, SFX_UNKNOWN_801B9_4
+ call PlaySound
+ ret
+
+Func_f8516:
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld a, [hl]
+ cp $20
+ jr nc, .asm_f8539
+ inc [hl]
+ inc [hl]
+ inc [hl]
+ inc [hl]
+ ld d, $4
+ call SurfingPikachu_Sine
+ ld hl, ANIM_OBJ_Y_OFFSET
+ add hl, bc
+ ld [hl], a
+ call Func_f87b5
+ ld a, [wSurfingMinigamePikachuObjectHeight]
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld [hl], a
+ ret
+
+.asm_f8539
+ ld hl, ANIM_OBJ_Y_OFFSET
+ add hl, bc
+ ld [hl], $0
+ ld a, $0
+ ld [wc5d2], a
+ ret
+
+Func_f8545:
+ ld hl, wc5e1
+ ld a, [hl]
+ and a
+ jr z, .asm_f8556
+ dec [hl]
+ ld a, [wSurfingMinigamePikachuObjectHeight]
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld [hl], a
+ ret
+
+.asm_f8556
+ ld a, $0
+ ld [wc5d2], a
+ ld a, $4
+ call SetCurrentAnimatedObjectCallbackAndResetFrameStateRegisters
+ ret
+
+Func_f8561:
+ ld a, [wSurfingMinigamePikachuObjectHeight]
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld [hl], a
+ call Func_f8742
+ ret
+
+Func_f856d:
+ ld a, $f
+ call SetCurrentAnimatedObjectCallbackAndResetFrameStateRegisters
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld [hl], $0
+ ret
+
+Func_f8579:
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld a, [hl]
+ inc [hl]
+ inc [hl]
+ and $3f
+ cp $20
+ jr c, .asm_f8591
+ ld d, $10
+ call SurfingPikachu_Sine
+ ld hl, ANIM_OBJ_Y_OFFSET
+ add hl, bc
+ ld [hl], a
+ ret
+
+.asm_f8591
+ ld hl, ANIM_OBJ_Y_OFFSET
+ add hl, bc
+ ld [hl], $0
+ ret
+
+SurfingMinigame_DPadAction:
+ ld de, hJoy5
+ ld a, [de]
+ and D_LEFT
+ jr nz, .d_left
+ ld a, [de]
+ and D_RIGHT
+ jr nz, .d_right
+ ret
+
+.d_left
+ ld hl, ANIM_OBJ_FIELD_E
+ add hl, bc
+ ld [hl], $0
+ ld hl, ANIM_OBJ_FIELD_D
+ add hl, bc
+ ld a, [hl]
+ inc [hl]
+ cp $b
+ jr c, .d_left_skip
+ call .StartTrick
+ ld hl, wSurfingMinigameTrickFlags
+ set 0, [hl]
+.d_left_skip
+ ld hl, ANIM_OBJ_FRAME_SET
+ add hl, bc
+ ld a, [hl]
+ cp $e
+ jr nc, .d_left_reset
+ inc [hl]
+ ret
+
+.d_left_reset
+ ld [hl], $1
+ ret
+
+.d_right
+ ld hl, ANIM_OBJ_FIELD_D
+ add hl, bc
+ ld [hl], $0
+ ld hl, ANIM_OBJ_FIELD_E
+ add hl, bc
+ ld a, [hl]
+ inc [hl]
+ cp $d
+ jr c, .d_right_skip
+ call .StartTrick
+ ld hl, wSurfingMinigameTrickFlags
+ set 1, [hl]
+.d_right_skip
+ ld hl, ANIM_OBJ_FRAME_SET
+ add hl, bc
+ ld a, [hl]
+ cp $1
+ jr z, .d_right_reset
+ dec [hl]
+ ret
+
+.d_right_reset
+ ld [hl], $e
+ ret
+
+.StartTrick:
+ call SurfingMinigame_IncreaseRadnessMeter
+ xor a
+ ld hl, ANIM_OBJ_FIELD_D
+ add hl, bc
+ ld [hl], a
+ ld hl, ANIM_OBJ_FIELD_E
+ add hl, bc
+ ld [hl], a
+ ld a, SFX_UNKNOWN_801B6_4
+ call PlaySound
+ ret
+
+SurfingMinigame_TileInteraction:
+ ld hl, ANIM_OBJ_FRAME_SET
+ add hl, bc
+ ld a, [wSurfingMinigameBGMapReadBuffer]
+ cp $6
+ jr z, .tile_06
+ cp $14
+ jr z, .tile_14
+ cp $12
+ jr z, .tile_12
+ cp $7
+ jr z, .tile_07
+ ld a, [hl]
+ cp $1
+ jp z, .action_0
+ cp $2
+ jr z, .action_1
+ cp $3
+ jr z, .action_2
+ cp $4
+ jr z, .action_3
+ cp $5
+ jr z, .action_2
+ cp $6
+ jr z, .action_1
+ cp $7
+ jr z, .action_0
+ jr .action_0
+
+.tile_06
+ ld a, [hl]
+ cp $1
+ jr z, .action_0
+ cp $2
+ jr z, .action_0
+ cp $3
+ jr z, .action_0
+ cp $4
+ jr z, .action_1
+ cp $5
+ jr z, .action_2
+ cp $6
+ jr z, .action_3
+ cp $7
+ jr z, .action_2
+ jr .action_0
+
+.tile_07
+ ld a, [hl]
+ cp $1
+ jr z, .action_2
+ cp $2
+ jr z, .action_3
+ cp $3
+ jr z, .action_2
+ cp $4
+ jr z, .action_1
+ cp $5
+ jr z, .action_0
+ cp $6
+ jr z, .action_0
+ cp $7
+ jr z, .action_0
+ jr .action_0
+
+.tile_12
+.tile_14
+ ld a, [hl]
+ cp $1
+ jr z, .action_0
+ cp $2
+ jr z, .action_1
+ cp $3
+ jr z, .action_2
+ cp $4
+ jr z, .action_3
+ cp $5
+ jr z, .action_3
+ cp $6
+ jr z, .action_2
+ cp $7
+ jr z, .action_1
+ jr .action_0
+
+.action_1
+ call Subtract128Fromwc5e3
+ jr .action_3
+
+.action_2
+ call Subtract64Fromwc5e3
+.action_3
+ xor a
+ ld [wChannelSoundIDs + CH7], a
+ ld a, SFX_UNKNOWN_801BF_4
+ call PlaySound
+ and a
+ ret
+
+.action_0
+ ld a, $40
+ ld [wc5e3], a
+ xor a
+ ld [wc5e3 + 1], a
+ scf
+ ret
+
+Func_f86b8:
+ ld a, [wc5e3 + 1]
+ cp $2
+ ret nc
+ ld h, a
+ ld a, [wc5e3]
+ ld l, a
+ ld de, $2
+ add hl, de
+ ld a, h
+ ld [wc5e3 + 1], a
+ ld a, l
+ ld [wc5e3], a
+ ret
+
+Subtract64Fromwc5e3:
+ ld a, [wc5e3 + 1]
+ and a
+ jr nz, .go
+ ld a, [wc5e3]
+ cp $40
+ jr nc, .go
+ xor a
+ ld [wc5e3], a
+ ret
+
+.go
+ ld a, [wc5e3 + 1]
+ ld h, a
+ ld a, [wc5e3]
+ ld l, a
+ ld de, -$40
+ add hl, de
+ ld a, h
+ ld [wc5e3 + 1], a
+ ld a, l
+ ld [wc5e3], a
+ ret
+
+Subtract128Fromwc5e3:
+ ld a, [wc5e3 + 1]
+ and a
+ jr nz, .go
+ ld a, [wc5e3]
+ cp $80
+ jr nc, .go
+ xor a
+ ld [wc5e3], a
+ ret
+
+.go
+ ld a, [wc5e3 + 1]
+ ld h, a
+ ld a, [wc5e3]
+ ld l, a
+ ld de, -$80
+ add hl, de
+ ld a, h
+ ld [wc5e3 + 1], a
+ ld a, l
+ ld [wc5e3], a
+ ret
+
+Func_f871e:
+ ld a, [hSCX]
+ and $7
+ cp $3
+ jr c, .asm_f8740
+ cp $5
+ jr nc, .asm_f8740
+ ld a, [wSurfingMinigameBGMapReadBuffer]
+ cp $14
+ jr nz, .asm_f8740
+ call Func_f87a8
+ cp $a
+ jr c, .asm_f8740
+ ld [wc5ec], a
+ call Func_f9284
+ scf
+ ret
+
+.asm_f8740
+ and a
+ ret
+
+Func_f8742:
+ ld a, [hSCX]
+ and $7
+ cp $3
+ ret c
+ cp $5
+ ret nc
+ ld a, [wSurfingMinigameBGMapReadBuffer]
+ cp $6
+ jr z, .asm_f8766
+ cp $14
+ jr z, .asm_f8766
+ cp $7
+ jr z, .asm_f876a
+ call Func_f8778
+ ld a, $4
+ ld hl, ANIM_OBJ_FRAME_SET
+ add hl, bc
+ ld [hl], a
+ ret
+
+.asm_f8766
+ ld a, $6
+ jr .asm_f876c
+
+.asm_f876a
+ ld a, $2
+.asm_f876c
+ ld e, a
+ ld a, [wc5de]
+ dec a
+ add e
+ ld hl, ANIM_OBJ_FRAME_SET
+ add hl, bc
+ ld [hl], a
+ ret
+
+Func_f8778:
+ ld hl, wc5e0
+ ld a, [hl]
+ inc [hl]
+ and $7
+ ret nz
+ ld a, [wc5df]
+ and a
+ jr z, .asm_f8796
+ ld a, [wc5de]
+ and a
+ jr z, .asm_f8791
+ dec a
+ ld [wc5de], a
+ ret
+
+.asm_f8791
+ xor a
+ ld [wc5df], a
+ ret
+
+.asm_f8796
+ ld a, [wc5de]
+ cp $2
+ jr z, .asm_f87a2
+ inc a
+ ld [wc5de], a
+ ret
+
+.asm_f87a2
+ ld a, $1
+ ld [wc5df], a
+ ret
+
+Func_f87a8:
+ ld a, [wc5e3]
+ ld l, a
+ ld a, [wc5e3 + 1]
+ ld h, a
+ add hl, hl
+ add hl, hl
+ add hl, hl
+ ld a, h
+ ret
+
+Func_f87b5:
+ ld hl, wc5eb
+ ld a, [hl]
+ inc [hl]
+ and $3
+ ret nz
+ call .GetYCoord
+ ld d, a
+ ld hl, ANIM_OBJ_X_COORD
+ add hl, bc
+ ld e, [hl]
+ ld a, $a
+ push bc
+ call SpawnAnimatedObject
+ pop bc
+ ret
+
+.GetYCoord:
+ ld a, [hSCX]
+ and $8
+ jr nz, .get_height_plus_9
+ ld hl, wSurfingMinigameWaveHeight + 8
+ jr .got_hl
+
+.get_height_plus_9
+ ld hl, wSurfingMinigameWaveHeight + 9
+.got_hl
+ ld a, [wSurfingMinigameBGMapReadBuffer + 1]
+ cp $6
+ jr z, .six_or_twenty
+ cp $14
+ jr z, .six_or_twenty
+ cp $7
+ jr z, .seven
+ ld a, [hl]
+ ret
+
+.six_or_twenty
+ ld a, [hSCX]
+ and $7
+ ld e, a
+ ld a, [hl]
+ sub e
+ ret
+
+.seven
+ ld a, [hSCX]
+ and $7
+ add [hl]
+ ret
+
+Func_f87fb:
+ ld hl, ANIM_OBJ_X_COORD
+ add hl, bc
+ ld a, [hl]
+ cp $58
+ ret z
+ add $4
+ ld [hl], a
+ ret
+
+Func_f8807: ; unreferenced
+ call MaskCurrentAnimatedObjectStruct
+ ret
+
+SurfingMinigameAnimatedObjectFn_FlippingPika:
+ ld hl, ANIM_OBJ_FIELD_B
+ add hl, bc
+ ld a, [hl]
+ and a
+ ret z
+ dec [hl]
+ dec [hl]
+ ld d, a
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld a, [hl]
+ inc [hl]
+ call SurfingPikachu_Sine
+ cp $80
+ jr nc, .positive
+ xor $ff
+ inc a
+.positive
+ ld hl, ANIM_OBJ_Y_OFFSET
+ add hl, bc
+ ld [hl], a
+ ret
+
+SurfingMinigameAnimatedObjectFn_IntroAnimationPikachu:
+ ld hl, ANIM_OBJ_FIELD_B
+ add hl, bc
+ ld a, [hl]
+ inc [hl]
+ and $1
+ ret z
+ ld hl, ANIM_OBJ_X_COORD
+ add hl, bc
+ ld a, [hl]
+ cp $c0
+ jr z, .done
+ inc [hl]
+ ret
+
+.done
+ ld a, $1
+ ld [wSurfingMinigameIntroAnimationFinished], a
+ call MaskCurrentAnimatedObjectStruct
+ ret
+
+Func_f8848:
+ ld a, [wc635]
+ ld e, a
+ ld d, $0
+ ld a, [wc5e3]
+ ld l, a
+ ld a, [wc5e3 + 1]
+ ld h, a
+ add hl, de
+ ld a, l
+ ld [wc635], a
+ ld d, h
+ ld hl, wOAMBuffer + 5 * 4 + 1
+ ld e, $9
+.loop
+ ld a, [hl]
+ add d
+ ld [hli], a
+ inc hl
+ inc hl
+ inc hl
+ dec e
+ jr nz, .loop
+ ret
+
+Func_f886b:
+ ld a, [wSurfingMinigameBGMapReadBuffer] ; ???
+ ld a, [hSCX]
+ add $48
+ ld e, a
+ srl e
+ srl e
+ srl e
+ ld d, $0
+ ld hl, vBGMap0
+ add hl, de
+ ld a, [wSurfingMinigamePikachuObjectHeight]
+ srl a
+ srl a
+ srl a
+ ld c, a
+.loop
+ ld a, c
+ and a
+ jr z, .copy
+ dec c
+ ld de, $20
+ add hl, de
+ ld a, h
+ and $3
+ or $98
+ ld h, a
+ jr .loop
+
+.copy
+ ld de, wSurfingMinigameBGMapReadBuffer
+ ld a, e
+ ld [H_VBCOPYDEST], a
+ ld a, d
+ ld [H_VBCOPYDEST + 1], a
+ ld a, l
+ ld [H_VBCOPYSRC], a
+ ld a, h
+ ld [H_VBCOPYSRC + 1], a
+ ld a, 16 / $10
+ ld [H_VBCOPYSIZE], a
+ ret
+
+Func_f88ae:
+ ld a, [hSCX]
+ and $8
+ jr nz, .asm_f88b9
+ ld hl, wSurfingMinigameWaveHeight + 7
+ jr .asm_f88bc
+
+.asm_f88b9
+ ld hl, wSurfingMinigameWaveHeight + 8
+.asm_f88bc
+ ld a, [wSurfingMinigameBGMapReadBuffer]
+ cp $6
+ jr z, .asm_f88d0
+ cp $14
+ jr z, .asm_f88d0
+ cp $7
+ jr z, .asm_f88db
+ ld a, [hl]
+ ld [wSurfingMinigamePikachuObjectHeight], a
+ ret
+
+.asm_f88d0
+ ld a, [hSCX]
+ and $7
+ ld e, a
+ ld a, [hl]
+ sub e
+ ld [wSurfingMinigamePikachuObjectHeight], a
+ ret
+
+.asm_f88db
+ ld a, [hSCX]
+ and $7
+ add [hl]
+ ld [wSurfingMinigamePikachuObjectHeight], a
+ ret
+
+SurfingMinigame_Deduct1HP:
+ ld hl, wSurfingMinigamePikachuHP
+ ld e, $99
+ call .BCD_Deduct
+ ret nc
+ inc hl
+ ld e, $99
+.BCD_Deduct:
+ ld a, [hl]
+ and a
+ jr z, .roll_over
+ sub $1
+ daa
+ ld [hl], a
+ and a
+ ret
+
+.roll_over
+ ld [hl], e
+ scf
+ ret
+
+Func_f88fd:
+ ld de, wSurfingMinigamePikachuHP + 1
+ ld hl, wOAMBuffer + 0 * 4 + 2
+ ld a, [de]
+ call .PlaceBCDNumber
+ ld hl, wOAMBuffer + 2 * 4 + 2
+ ld a, [de]
+.PlaceBCDNumber:
+ ld c, a
+ swap a
+ and $f
+ add $d0
+ ld [hli], a
+ inc hl
+ inc hl
+ inc hl
+ ld a, c
+ and $f
+ add $d0
+ ld [hl], a
+ dec de
+ ret
+
+SurfingMinigame_DrawResultsScreen:
+ ld hl, wTileMap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ xor a
+ call FillMemory
+ ld hl, .BeachTilemap
+ coord de, 0, 6
+ ld bc, .BeachTilemapEnd - .BeachTilemap
+ call CopyData
+ call .PlaceTextbox
+ ld hl, wOAMBuffer + 5 * 4 + 1
+ ld bc, 9 * 4
+ xor a
+ call FillMemory
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ret
+
+.BeachTilemap:
+INCBIN "gfx/unknown_f8946.map"
+.BeachTilemapEnd:
+
+.PlaceTextbox:
+ coord hl, 1, 1
+ lb de, $3b, $3c
+ ld a, $40
+ call .place_row
+ coord hl, 1, 2
+ lb de, $3f, $3f
+ ld a, $ff
+ call .place_row
+ coord hl, 1, 3
+ lb de, $3f, $3f
+ ld a, $ff
+ call .place_row
+ coord hl, 1, 4
+ lb de, $3f, $3f
+ ld a, $ff
+ call .place_row
+ coord hl, 1, 5
+ lb de, $3f, $3f
+ ld a, $ff
+ call .place_row
+ coord hl, 1, 6
+ lb de, $3f, $3f
+ ld a, $ff
+ call .place_row
+ coord hl, 1, 7
+ lb de, $3f, $3f
+ ld a, $ff
+ call .place_row
+ coord hl, 1, 8
+ lb de, $3f, $3f
+ ld a, $ff
+ call .place_row
+ coord hl, 1, 9
+ lb de, $3d, $3e
+ ld a, $40
+ call .place_row
+ ret
+
+.place_row:
+ ld [hl], d
+ inc hl
+ ld c, $10
+.loop
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ld [hl], e
+ ret
+
+SurfingMinigame_PrintTextHiScore:
+ ld hl, .Hi_Score
+ coord de, 6, 8
+ ld bc, $9
+ call CopyData
+ ret
+
+.Hi_Score:
+ db $20,$2e,$2f,$30,$31,$2c,$32,$23,$33 ; Hi-Score!!
+
+SurfingMinigame_WriteHPLeft:
+ ld hl, .HP_Left
+ coord de, 2, 2
+ ld bc, $7
+ call CopyData
+ call SurfingMinigame_BCDPrintHPLeft
+ ret
+
+.HP_Left:
+ db $20,$21,$ff,$22,$23,$24,$25 ; HP Left
+
+SurfingMinigame_AddRemainingHPToTotal:
+ ld c, 99
+.loop
+ push bc
+ ld hl, wSurfingMinigamePikachuHP
+ ld a, [hli]
+ or [hl]
+ and a
+ jr z, .dead
+ call SurfingMinigame_Deduct1HP
+ ld e, $1
+ call SurfingMinigame_AddPointsToTotal
+ pop bc
+ dec c
+ jr nz, .loop
+ ld a, SFX_UNKNOWN_801B0_4
+ call PlaySound
+ and a
+ ret
+
+.dead
+ pop bc
+ scf
+ ret
+
+SurfingMinigame_BCDPrintHPLeft:
+ coord hl, 10, 2
+ ld de, wSurfingMinigamePikachuHP + 1
+ ld a, [de]
+ call SurfingPikachu_PlaceBCDNumber
+ inc hl
+ ld a, [de]
+ call SurfingPikachu_PlaceBCDNumber
+ inc hl
+ inc hl
+ ld [hl], $21 ; P
+ inc hl
+ ld [hl], $25 ; t
+ inc hl
+ ld [hl], $26 ; s
+ ret
+
+SurfingMinigame_WriteRadness:
+ ld hl, .Radness
+ coord de, 2, 4
+ ld bc, $7
+ call CopyData
+ call SurfingMinigame_BCDPrintRadness
+ ret
+
+.Radness:
+ db $27,$28,$29,$2a,$23,$26,$26 ; Radness
+
+SurfingMinigame_AddRadnessToTotal:
+ ld c, 99
+.loop
+ push bc
+ ld hl, wSurfingMinigameRadnessScore
+ ld a, [hli]
+ ld e, a
+ or [hl]
+ jr z, .done
+ ld d, [hl]
+ ld a, e
+ sub $1
+ daa
+ ld e, a
+ ld a, d
+ sbc $0
+ daa
+ ld [hld], a
+ ld [hl], e
+ ld e, $1
+ call SurfingMinigame_AddPointsToTotal
+ pop bc
+ dec c
+ jr nz, .loop
+ ld a, SFX_UNKNOWN_801B0_4
+ call PlaySound
+ and a
+ ret
+
+.done
+ pop bc
+ scf
+ ret
+
+SurfingMinigame_BCDPrintRadness:
+ ld a, [wSurfingMinigameRadnessScore + 1]
+ coord hl, 10, 4
+ call SurfingPikachu_PlaceBCDNumber
+ ld a, [wSurfingMinigameRadnessScore]
+ coord hl, 12, 4
+ call SurfingPikachu_PlaceBCDNumber
+ inc hl
+ inc hl
+ ld [hl], $21 ; P
+ inc hl
+ ld [hl], $25 ; t
+ inc hl
+ ld [hl], $26 ; s
+ ret
+
+SurfingMinigame_AddPointsToTotal:
+ ld a, [wSurfingMinigameTotalScore]
+ add e
+ daa
+ ld [wSurfingMinigameTotalScore], a
+ ld a, [wSurfingMinigameTotalScore + 1]
+ adc $0
+ daa
+ ld [wSurfingMinigameTotalScore + 1], a
+ ret nc
+ ld a, $99
+ ld [wSurfingMinigameTotalScore], a
+ ld [wSurfingMinigameTotalScore + 1], a
+ ret
+
+SurfingMinigame_BCDPrintTotalScore:
+ ld a, [wSurfingMinigameTotalScore + 1]
+ coord hl, 10, 6
+ call SurfingPikachu_PlaceBCDNumber
+ ld a, [wSurfingMinigameTotalScore]
+ coord hl, 12, 6
+ call SurfingPikachu_PlaceBCDNumber
+ inc hl
+ inc hl
+ ld [hl], $21 ; P
+ inc hl
+ ld [hl], $25 ; t
+ inc hl
+ ld [hl], $26 ; s
+ ret
+
+SurfingMinigame_WriteTotal:
+ ld hl, .Total
+ coord de, 2, 6
+ ld bc, $5
+ call CopyData
+ call SurfingMinigame_BCDPrintRadness
+ call SurfingMinigame_BCDPrintTotalScore
+ ret
+
+.Total:
+ db $2b,$2c,$25,$28,$2d ; Total
+
+DidPlayerGetAHighScore:
+ ld hl, wSurfingMinigameHiScore + 1
+ ld a, [wSurfingMinigameTotalScore + 1]
+ cp [hl]
+ jr c, .not_high_score
+ jr nz, .high_score
+ dec hl
+ ld a, [wSurfingMinigameTotalScore]
+ cp [hl]
+ jr c, .not_high_score
+ jr nz, .high_score
+.not_high_score
+ call WaitForSoundToFinish
+ ldpikacry e, PikachuCry28
+ call SurfingMinigame_PlayPikaCryIfSurfingPikaInParty
+ and a
+ ret
+
+.high_score
+ ld a, [wSurfingMinigameTotalScore]
+ ld [wSurfingMinigameHiScore], a
+ ld a, [wSurfingMinigameTotalScore + 1]
+ ld [wSurfingMinigameHiScore + 1], a
+ call WaitForSoundToFinish
+ ldpikacry e, PikachuCry34
+ call SurfingMinigame_PlayPikaCryIfSurfingPikaInParty
+ ld a, SFX_GET_ITEM2_4_2
+ call PlaySound
+ scf
+ ret
+
+SurfingMinigame_PlayPikaCryIfSurfingPikaInParty:
+ push de
+ callab IsSurfingPikachuInThePlayersParty
+ pop de
+ ret nc
+ callab PlayPikachuSoundClip
+ ret
+
+SurfingMinigame_IncreaseRadnessMeter:
+ ld a, [wSurfingMinigameRadnessMeter]
+ inc a
+ cp $4
+ jr c, .cap
+ ld a, $3
+.cap
+ ld [wSurfingMinigameRadnessMeter], a
+ ret
+
+SurfingMinigame_CalculateAndAddRadnessFromStunt:
+ ; Compute the amount of radness points from the
+ ; current trick based on the number of
+ ; consecutive flips
+ ; Single flip: +0050
+ ; 2 of the same flip: +0150
+ ; 3 or more of the same flip: +0350
+ ; 2 different flips: +0180
+ ; 3 or more different flips: +0500
+ ld a, [wSurfingMinigameRadnessMeter]
+ and a
+ ret z
+ ld a, [wSurfingMinigameTrickFlags]
+ and $3
+ cp $3 ; did a combination of front and back flips
+ jr z, .mixed_chain
+ ld a, [wSurfingMinigameRadnessMeter]
+ ld d, a
+ ld e, $1
+ ld a, $0
+.get_amount_of_radness
+ add e
+ sla e
+ dec d
+ jr nz, .get_amount_of_radness
+.add_radness_50_at_a_time
+ push af
+ ld e, $50
+ call SurfingMinigame_AddRadness
+ pop af
+ dec a
+ jr nz, .add_radness_50_at_a_time
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld a, [hl]
+ sub $10
+ ld d, a
+ ld hl, ANIM_OBJ_X_COORD
+ add hl, bc
+ ld e, [hl]
+ ld a, [wSurfingMinigameRadnessMeter]
+ add $3
+ push bc
+ call SpawnAnimatedObject
+ pop bc
+ ret
+
+.mixed_chain
+ ld a, [wSurfingMinigameRadnessMeter]
+ cp $3
+ jr c, .add_180_radness_points
+ ld a, 10
+.add_500_radness_50_at_a_time
+ push af
+ ld e, $50
+ call SurfingMinigame_AddRadness
+ pop af
+ dec a
+ jr nz, .add_500_radness_50_at_a_time
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld a, [hl]
+ sub $10
+ ld d, a
+ ld hl, ANIM_OBJ_X_COORD
+ add hl, bc
+ ld e, [hl]
+ ld a, $9
+ push bc
+ call SpawnAnimatedObject
+ pop bc
+ ret
+
+.add_180_radness_points
+ ld e, $50
+ call SurfingMinigame_AddRadness
+ ld e, $50
+ call SurfingMinigame_AddRadness
+ ld e, $50
+ call SurfingMinigame_AddRadness
+ ld e, $30
+ call SurfingMinigame_AddRadness
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld a, [hl]
+ sub $10
+ ld d, a
+ ld hl, ANIM_OBJ_X_COORD
+ add hl, bc
+ ld e, [hl]
+ ld a, $8
+ push bc
+ call SpawnAnimatedObject
+ pop bc
+ ret
+
+SurfingMinigame_AddRadness:
+ ld a, [wSurfingMinigameRadnessScore]
+ add e
+ daa
+ ld [wSurfingMinigameRadnessScore], a
+ ld a, [wSurfingMinigameRadnessScore + 1]
+ adc $0
+ daa
+ ld [wSurfingMinigameRadnessScore + 1], a
+ ret nc
+ ld a, $99
+ ld [wSurfingMinigameRadnessScore], a
+ ld [wSurfingMinigameRadnessScore + 1], a
+ ret
+
+Func_f8c97:
+ ld a, $a0
+ ld [wSurfingMinigameXOffset], a
+ ld a, [hSCX]
+ ld h, a
+ ld a, [wSurfingMinigameSCX]
+ ld l, a
+ ld de, $900
+ add hl, de
+ ld a, l
+ ld [wSurfingMinigameSCX], a
+ ld a, h
+ ld [hSCX], a
+ jr Func_f8cc7
+
+Func_f8cb0:
+ ld a, $a0
+ ld [wSurfingMinigameXOffset], a
+ ld a, [hSCX]
+ ld h, a
+ ld a, [wSurfingMinigameSCX]
+ ld l, a
+ ld de, $180
+ add hl, de
+ ld a, l
+ ld [wSurfingMinigameSCX], a
+ ld a, h
+ ld [hSCX], a
+Func_f8cc7:
+ ld hl, wSurfingMinigameSCX + 1
+ ld a, [hSCX]
+ cp [hl]
+ ret z
+ ld [hl], a
+ and $f0
+ ld hl, wSurfingMinigameSCX + 2
+ cp [hl]
+ ret z
+ ld [hl], a
+ call SurfingMinigame_GetWaveDataPointers
+ ; b and c contain the height of the next wave to appear
+ ; on screen, in number of pixels from the top of the screen
+ ld a, b
+ ld [wSurfingMinigameWaveHeightBuffer], a
+ ld a, c
+ ld [wSurfingMinigameWaveHeightBuffer + 1], a
+ push de
+ ld hl, wSurfingMinigameWaveHeight
+ ld de, wSurfingMinigameWaveHeight + 2
+ ld c, SCREEN_WIDTH - 2
+.copy_loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .copy_loop
+ ld a, [wSurfingMinigameWaveHeightBuffer]
+ ld [hli], a
+ ld a, [wSurfingMinigameWaveHeightBuffer + 1]
+ ld [hl], a
+ pop de
+ ld hl, wRedrawRowOrColumnSrcTiles
+ ld c, $8
+.loop
+ ld a, [de]
+ call .CopyRedrawSrcTiles
+ inc de
+ dec c
+ jr nz, .loop
+ ld a, [wSurfingMinigameXOffset]
+ ld e, a
+ ld a, [hSCX]
+ add e
+ and $f0
+ srl a
+ srl a
+ srl a
+ ld e, a
+ ld d, $0
+ ld hl, vBGMap0
+ add hl, de
+ ld a, l
+ ld [hRedrawRowOrColumnDest], a
+ ld a, h
+ ld [hRedrawRowOrColumnDest + 1], a
+ ld a, $1
+ ld [hRedrawRowOrColumnMode], a
+ ret
+
+.CopyRedrawSrcTiles:
+ push de
+ push hl
+ ld l, a
+ ld h, $0
+ ld de, Unkn_f96e5
+ add hl, hl
+ add hl, hl
+ add hl, de
+ ld e, l
+ ld d, h
+ pop hl
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ pop de
+ ret
+
+SurfingMinigame_GetWaveDataPointers:
+ ld a, [wSurfingMinigameWaveFunctionNumber]
+ ld e, a
+ ld d, $0
+ ld hl, Jumptable_f8d53
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+Jumptable_f8d53:
+ dw SurfingMinigameWaveFunction_NoWave ; 00
+
+ dw Func_f8f28 ; 01
+ dw Func_f8f31 ; 02
+ dw Func_f8f3a ; 03
+ dw Func_f8f43 ; 04
+ dw Func_f8e7d ; 05
+ dw Func_f8f4c ; 06
+ dw Func_f8f55 ; 07
+ dw Func_f8f5e ; 08
+ dw Func_f8e7d ; 09
+ dw Func_f8e7d ; 0a
+ dw Func_f8e7d ; 0b
+ dw Func_f8e7d ; 0c
+ dw Func_f8f94 ; 0d
+
+ dw Func_f8ec5 ; 0e
+ dw Func_f8ece ; 0f
+ dw Func_f8ed7 ; 10
+ dw Func_f8ee0 ; 11
+ dw Func_f8ee9 ; 12
+ dw Func_f8ef2 ; 13
+ dw Func_f8e7d ; 14
+ dw Func_f8e7d ; 15
+ dw Func_f8e7d ; 16
+ dw Func_f8e7d ; 17
+ dw Func_f8e7d ; 18
+ dw Func_f8f94 ; 19
+
+ dw Func_f8efb ; 1a
+ dw Func_f8f04 ; 1b
+ dw Func_f8f0d ; 1c
+ dw Func_f8f16 ; 1d
+ dw Func_f8f1f ; 1e
+ dw Func_f8efb ; 1f
+ dw Func_f8f04 ; 20
+ dw Func_f8f0d ; 21
+ dw Func_f8f16 ; 22
+ dw Func_f8f1f ; 23
+ dw Func_f8e7d ; 24
+ dw Func_f8e7d ; 25
+ dw Func_f8e7d ; 26
+ dw Func_f8e7d ; 27
+ dw Func_f8f94 ; 28
+
+ dw Func_f8f28 ; 29
+ dw Func_f8f31 ; 2a
+ dw Func_f8f3a ; 2b
+ dw Func_f8f43 ; 2c
+ dw Func_f8e7d ; 2d
+ dw Func_f8e7d ; 2e
+ dw Func_f8e7d ; 2f
+ dw Func_f8e7d ; 30
+ dw Func_f8f94 ; 31
+
+ dw Func_f8f4c ; 32
+ dw Func_f8f55 ; 33
+ dw Func_f8f5e ; 34
+ dw Func_f8f4c ; 35
+ dw Func_f8f55 ; 36
+ dw Func_f8f5e ; 37
+ dw Func_f8f4c ; 38
+ dw Func_f8f55 ; 39
+ dw Func_f8f5e ; 3a
+ dw Func_f8e7d ; 3b
+ dw Func_f8e7d ; 3c
+ dw Func_f8e7d ; 3d
+ dw Func_f8e7d ; 3e
+ dw Func_f8f94 ; 3f
+
+ dw Func_f8f67 ; 40
+ dw Func_f8f70 ; 41
+ dw Func_f8efb ; 42
+ dw Func_f8f04 ; 43
+ dw Func_f8f0d ; 44
+ dw Func_f8f16 ; 45
+ dw Func_f8f1f ; 46
+ dw Func_f8f67 ; 47
+ dw Func_f8f70 ; 48
+ dw Func_f8e7d ; 49
+ dw Func_f8e7d ; 4a
+ dw Func_f8e7d ; 4b
+ dw Func_f8f94 ; 4c
+
+ dw Func_f8ec5 ; 4d
+ dw Func_f8ece ; 4e
+ dw Func_f8ed7 ; 4f
+ dw Func_f8ee0 ; 50
+ dw Func_f8ee9 ; 51
+ dw Func_f8ef2 ; 52
+ dw Func_f8e7d ; 53
+ dw Func_f8f67 ; 54
+ dw Func_f8f70 ; 55
+ dw Func_f8f67 ; 56
+ dw Func_f8f70 ; 57
+ dw Func_f8e7d ; 58
+ dw Func_f8e7d ; 59
+ dw Func_f8e7d ; 5a
+ dw Func_f8f94 ; 5b
+
+ dw Func_f8efb ; 5c
+ dw Func_f8f04 ; 5d
+ dw Func_f8f0d ; 5e
+ dw Func_f8f16 ; 5f
+ dw Func_f8f1f ; 60
+ dw Func_f8f28 ; 61
+ dw Func_f8f31 ; 62
+ dw Func_f8f3a ; 63
+ dw Func_f8f43 ; 64
+ dw Func_f8e7d ; 65
+ dw Func_f8e7d ; 66
+ dw Func_f8e7d ; 67
+ dw Func_f8e7d ; 68
+ dw Func_f8f94 ; 69
+
+ dw Func_f8e86 ; 6a
+ dw Func_f8e8f ; 6b
+ dw Func_f8e98 ; 6c
+ dw Func_f8ea1 ; 6d
+ dw Func_f8eaa ; 6e
+ dw Func_f8eb3 ; 6f
+ dw Func_f8ebc ; 70
+ dw Func_f8f9d ; 71
+
+ dw Func_f8e7d ; 72
+ dw Func_f8f79 ; 73
+ dw Func_f8f82 ; 74
+ dw Func_f8f82 ; 75
+ dw Func_f8f82 ; 76
+ dw Func_f8f82 ; 77
+ dw Func_f8f82 ; 78
+ dw Func_f8f82 ; 79
+ dw Func_f8f82 ; 7a
+ dw Func_f8f8b ; 7b
+
+SurfingMinigameWaveFunction_NoWave:
+ ld a, [wc5e5]
+ cp $16
+ jr c, .check_param
+ jr z, .big_kahuna
+ jr nc, .got_wave
+.big_kahuna
+ ld a, $6a
+ jr .got_next_fn
+
+.check_param
+ ld a, [wc5d5]
+ and a
+ jr z, .got_wave
+ dec a
+ and $7
+ ld e, a
+ ld d, $0
+ ld hl, Unkn_f8e75
+ add hl, de
+ ld a, [hl]
+.got_next_fn
+ ld [wSurfingMinigameWaveFunctionNumber], a
+.got_wave
+ lb bc, $74, $74
+ ld de, Unkn_f973d
+ ret
+
+Unkn_f8e75:
+ db $01,$0e,$1a,$29,$32,$40,$4d,$5c
+
+Func_f8e7d:
+ lb bc, $74, $74
+ ld de, Unkn_f973d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8e86:
+ lb bc, $74, $6c
+ ld de, Unkn_f9745
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8e8f:
+ lb bc, $64, $5c
+ ld de, Unkn_f974d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8e98:
+ lb bc, $54, $4c
+ ld de, Unkn_f9755
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ea1:
+ lb bc, $44, $44
+ ld de, Unkn_f975d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8eaa:
+ lb bc, $44, $4c
+ ld de, Unkn_f9765
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8eb3:
+ lb bc, $54, $5c
+ ld de, Unkn_f976d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ebc:
+ lb bc, $64, $6c
+ ld de, Unkn_f9775
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ec5:
+ lb bc, $74, $6c
+ ld de, Unkn_f977d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ece:
+ lb bc, $64, $5c
+ ld de, Unkn_f9785
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ed7:
+ lb bc, $54, $4c
+ ld de, Unkn_f978d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ee0:
+ lb bc, $4c, $4c
+ ld de, Unkn_f9795
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ee9:
+ lb bc, $54, $5c
+ ld de, Unkn_f979d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8ef2:
+ lb bc, $64, $6c
+ ld de, Unkn_f97a5
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8efb:
+ lb bc, $74, $6c
+ ld de, Unkn_f97ad
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f04:
+ lb bc, $64, $5c
+ ld de, Unkn_f97b5
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f0d:
+ lb bc, $54, $54
+ ld de, Unkn_f97bd
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f16:
+ lb bc, $54, $5c
+ ld de, Unkn_f97c5
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f1f:
+ lb bc, $64, $6c
+ ld de, Unkn_f97cd
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f28:
+ lb bc, $74, $6c
+ ld de, Unkn_f97d5
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f31:
+ lb bc, $64, $5c
+ ld de, Unkn_f97dd
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f3a:
+ lb bc, $5c, $5c
+ ld de, Unkn_f97e5
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f43:
+ lb bc, $64, $6c
+ ld de, Unkn_f97ed
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f4c:
+ lb bc, $74, $6c
+ ld de, Unkn_f97f5
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f55:
+ lb bc, $64, $64
+ ld de, Unkn_f97fd
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f5e:
+ lb bc, $64, $6c
+ ld de, Unkn_f9805
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f67:
+ lb bc, $74, $6c
+ ld de, Unkn_f980d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f70:
+ lb bc, $6c, $6c
+ ld de, Unkn_f9815
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f79:
+ lb bc, $74, $74
+ ld de, Unkn_f981d
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f82:
+ lb bc, $74, $74
+ ld de, Unkn_f9825
+ jp SurfingMinigameWaveFunction_GoToNextWaveFunction
+
+Func_f8f8b:
+ lb bc, $74, $74
+ ld de, Unkn_f9825
+ jp SurfingMinigameWaveFunction_ResetWaveFunction
+
+Func_f8f94:
+ lb bc, $74, $74
+ ld de, Unkn_f973d
+ jp SurfingMinigameWaveFunction_ResetWaveFunction
+
+Func_f8f9d:
+ lb bc, $74, $74
+ ld de, Unkn_f973d
+ ret
+
+Func_f8fa4: ; unused
+ inc a
+ ld [wSurfingMinigameWaveFunctionNumber], a
+ ret
+
+SurfingMinigameWaveFunction_GoToNextWaveFunction:
+ ld hl, wSurfingMinigameWaveFunctionNumber
+ inc [hl]
+ ret
+
+SurfingMinigameWaveFunction_ResetWaveFunction:
+ xor a
+ ld [wSurfingMinigameWaveFunctionNumber], a
+ ret
+
+SurfingPikachuMinigameIntro:
+ call SurfingPikachu_ClearTileMap
+ call ClearSprites
+ call DisableLCD
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call ClearObjectAnimationBuffers
+ ld hl, SurfingPikachu1Graphics3
+ ld de, $8800
+ ld bc, $900
+ ld a, BANK(SurfingPikachu1Graphics3)
+ call FarCopyData
+ ld a, SurfingPikachuSpawnStateDataPointer % $100
+ ld [wAnimatedObjectSpawnStateDataPointer], a
+ ld a, SurfingPikachuSpawnStateDataPointer / $100
+ ld [wAnimatedObjectSpawnStateDataPointer + 1], a
+ ld a, SurfingPikachuObjectJumptable % $100
+ ld [wAnimatedObjectJumptablePointer], a
+ ld a, SurfingPikachuObjectJumptable / $100
+ ld [wAnimatedObjectJumptablePointer + 1], a
+ ld a, SurfingPikachuOAMData % $100
+ ld [wAnimatedObjectOAMDataPointer], a
+ ld a, SurfingPikachuOAMData / $100
+ ld [wAnimatedObjectOAMDataPointer + 1], a
+ ld a, SurfingPikachuFrames % $100
+ ld [wAnimatedObjectFramesDataPointer], a
+ ld a, SurfingPikachuFrames / $100
+ ld [wAnimatedObjectFramesDataPointer + 1], a
+ ld a, $c
+ lb de, $74, $58
+ call SpawnAnimatedObject
+ call DrawSurfingPikachuMinigameIntroBackground
+ xor a
+ ld [hSCX], a
+ ld [hSCY], a
+ ld a, $90
+ ld [hWY], a
+ ld b, $f
+ call RunPaletteCommand
+ ld a, $e3
+ ld [rLCDC], a
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call DelayFrame
+ call DelayFrame
+ call DelayFrame
+ call SurfingPikachuMinigame_SetBGPals
+ ld a, $e4
+ ld [rOBP0], a
+ ld a, $e0
+ ld [rOBP1], a
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ call DelayFrame
+ ld a, MUSIC_SURFING_PIKACHU
+ ld c, BANK(Music_SurfingPikachu)
+ call PlayMusic
+ xor a
+ ld [wSurfingMinigameIntroAnimationFinished], a
+.loop
+ ld a, [wSurfingMinigameIntroAnimationFinished]
+ and a
+ ret nz
+ ld a, $0
+ ld [wCurrentAnimatedObjectOAMBufferOffset], a
+ call RunObjectAnimations
+ call DelayFrame
+ jr .loop
+
+DrawSurfingPikachuMinigameIntroBackground:
+ ld hl, wTileMap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ ld a, $ff
+ call FillMemory
+ ld hl, Tilemap_f90bc
+ coord de, 0, 6
+ ld bc, 12 * SCREEN_WIDTH
+ call CopyData
+ ld de, Tilemap_f91c8
+ coord hl, 4, 0
+ lb bc, 6, 12
+ call .CopyBox
+ coord hl, 3, 7
+ lb bc, 3, 15
+ call .FillBoxWithFF
+ ld hl, Tilemap_f91ac
+ coord de, 3, 7
+ ld bc, 15
+ call CopyData
+ ld hl, Tilemap_f91bb
+ coord de, 4, 9
+ ld bc, 13
+ call CopyData
+ ret
+
+.CopyBox:
+.copy_row
+ push bc
+ push hl
+.copy_col
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .copy_col
+ ld bc, SCREEN_WIDTH
+ pop hl
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .copy_row
+ ret
+
+.FillBoxWithFF:
+.fill_row
+ push bc
+ push hl
+.fill_col
+ ld [hl], $ff
+ inc hl
+ dec c
+ jr nz, .fill_col
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .fill_row
+ ret
+
+Tilemap_f90bc: INCBIN "gfx/unknown_f90bc.map"
+Tilemap_f91ac: INCBIN "gfx/unknown_f91ac.map"
+Tilemap_f91bb: INCBIN "gfx/unknown_f91bb.map"
+Tilemap_f91c8: INCBIN "gfx/unknown_f91c8.map"
+
+SurfingMinigame_UpdateLYOverrides:
+ ld hl, wLYOverrides + $10
+ ld de, wLYOverrides + $11
+ ld c, $80
+ ld a, [hl]
+ push af
+.loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ pop af
+ ld [hl], a
+ ret
+
+SurfingMinigame_InitScanlineOverrides:
+ ld hl, wLYOverrides
+ ld bc, wLYOverridesEnd - wLYOverrides
+ ld de, $0
+.loop
+ ld a, e
+ and $1f
+ ld e, a
+ push hl
+ ld hl, SurfingMinigame_LYOverridesInitialSineWave
+ add hl, de
+ ld a, [hl]
+ pop hl
+ ld [hli], a
+ inc e
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ ret
+
+SurfingPikachu_GetJoypad_3FrameBuffer:
+ call Joypad
+ ld a, [H_FRAMECOUNTER]
+ and a
+ jr nz, .delayed
+ ld a, [hJoyHeld]
+ ld [hJoy5], a
+ ld a, $2
+ ld [H_FRAMECOUNTER], a
+ ret
+
+.delayed
+ xor a
+ ld [hJoy5], a
+ ret
+
+SurfingPikachuMinigame_BlankPals:
+ xor a
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ret
+
+SurfingPikachuMinigame_NormalPals:
+ ld a, $e4
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld a, $e0
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ret
+
+SurfingPikachu_ClearTileMap:
+ ld hl, wTileMap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ xor a
+ call FillMemory
+ ret
+
+Func_f9284:
+ xor a
+ ld [wc5ed], a
+ ld [wc5ee], a
+ ret
+
+SurfingMinigame_UpdatePikachuHeight:
+ ld a, [wc5ed]
+ and a
+ jr nz, .positive
+ ld a, [wc5ec]
+ ld d, a
+ ld a, [wc5ee]
+ or d
+ jr z, .done
+ ld a, [wc5ee]
+ ld e, a
+ ld hl, -$80
+ add hl, de
+ ld a, l
+ ld [wc5ee], a
+ ld a, h
+ ld [wc5ec], a
+
+ ; -(4 * a ** 2)
+ ld e, a
+ ld d, $0
+ call SurfingMinigame_NTimesDE
+ ld e, l
+ ld d, h
+ ld a, $4
+ call SurfingMinigame_NTimesDE
+ ld a, l
+ xor $ff
+ inc a
+ ld l, a
+ ld a, h
+ xor $ff
+ ld h, a
+
+ push hl
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld d, [hl]
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld e, [hl]
+ pop hl
+
+ add hl, de
+ ld e, l
+ ld d, h
+
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld [hl], d
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld [hl], e
+ and a
+ ret
+
+.done
+ ld a, $1
+ ld [wc5ed], a
+ and a
+ ret
+
+.positive
+ ld a, [wSurfingMinigamePikachuObjectHeight]
+ ld e, a
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld a, [hl]
+ cp $90
+ jr nc, .okay
+ cp e
+ jr nc, .reset
+.okay
+ ld a, [wc5ec]
+ ld d, a
+ ld a, [wc5ee]
+ ld e, a
+ ld hl, $80
+ add hl, de
+ ld a, l
+ ld [wc5ee], a
+ ld a, h
+ ld [wc5ec], a
+
+ ; 4 * a ** 2
+ ld e, a
+ ld d, $0
+ call SurfingMinigame_NTimesDE
+ ld e, l
+ ld d, h
+ ld a, $4
+ call SurfingMinigame_NTimesDE
+
+ push hl
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld d, [hl]
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld e, [hl]
+ pop hl
+
+ add hl, de
+ ld e, l
+ ld d, h
+
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld [hl], d
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld [hl], e
+ and a
+ ret
+
+.reset
+ ld hl, ANIM_OBJ_Y_COORD
+ add hl, bc
+ ld a, [wSurfingMinigamePikachuObjectHeight]
+ ld [hl], a
+ ld hl, ANIM_OBJ_FIELD_C
+ add hl, bc
+ ld [hl], $0
+ scf
+ ret
+
+SurfingMinigame_NTimesDE:
+ ld hl, $0
+.loop
+ srl a
+ jr nc, .no_add
+ add hl, de
+.no_add
+ sla e
+ rl d
+ and a
+ jr nz, .loop
+ ret
+
+SurfingPikachu_PlaceBCDNumber:
+ ld c, a
+ swap a
+ and $f
+ add $d0
+ ld [hli], a
+ ld a, c
+ and $f
+ add $d0
+ ld [hl], a
+ dec de
+ ret
+
+SurfingPikachu_Cosine: ; cosine
+ add $10
+SurfingPikachu_Sine: ; sine
+ and $3f
+ cp $20
+ jr nc, .positive
+ call .GetSine
+ ld a, h
+ ret
+
+.positive
+ and $1f
+ call .GetSine
+ ld a, h
+ xor $ff
+ inc a
+ ret
+
+.GetSine:
+ ld e, a
+ ld a, d
+ ld d, $0
+ ld hl, .SineWave
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld hl, $0
+.loop
+ srl a
+ jr nc, .no_add
+ add hl, de
+.no_add
+ sla e
+ rl d
+ and a
+ jr nz, .loop
+ ret
+
+.SineWave:
+ sine_wave $100
+
+SurfingPikachuSpawnStateDataPointer:
+ db $00, $00, $00 ; 0
+ db $04, $01, $00 ; 1
+ db $11, $02, $00 ; 2
+ db $12, $02, $00 ; 3
+ db $15, $00, $00 ; 4
+ db $16, $00, $00 ; 5
+ db $17, $00, $00 ; 6
+ db $18, $00, $00 ; 7
+ db $19, $00, $00 ; 8
+ db $1a, $00, $00 ; 9
+ db $14, $00, $00 ; a
+ db $13, $03, $00 ; b
+ db $1b, $04, $00 ; c
+
+SurfingPikachuObjectJumptable:
+ dw SurfingMinigameAnimatedObjectFn_nop ; 0
+ dw SurfingMinigameAnimatedObjectFn_Pikachu ; 1
+ dw Func_f87fb ; 2
+ dw SurfingMinigameAnimatedObjectFn_FlippingPika ; 3
+ dw SurfingMinigameAnimatedObjectFn_IntroAnimationPikachu ; 4
+
+SurfingMinigameAnimatedObjectFn_nop:
+ ret
+
+INCLUDE "data/animated_objects_3e_1.asm"
+
+SurfingMinigame_LYOverridesInitialSineWave:
+; a sine wave with amplitude 2
+ db 0, 0, 0, 1, 1, 1, 1, 2
+ db 2, 2, 1, 1, 1, 1, 0, 0
+ db 0, 0, 0, -1, -1, -1, -1, -2
+ db -2, -2, -1, -1, -1, -1, 0, 0
+
+Unkn_f96e5:
+ db $00, $00, $00, $00 ; 00
+ db $0b, $0b, $0b, $0b ; 01
+ db $0b, $02, $02, $06 ; 02
+ db $03, $0b, $07, $03 ; 03
+ db $06, $06, $06, $06 ; 04
+ db $07, $07, $07, $07 ; 05
+ db $06, $04, $04, $08 ; 06
+ db $05, $07, $08, $05 ; 07
+ db $0b, $0b, $11, $12 ; 08
+ db $0b, $0b, $13, $03 ; 09
+ db $14, $12, $04, $08 ; 0a
+ db $13, $07, $08, $05 ; 0b
+ db $06, $14, $06, $14 ; 0c
+ db $13, $07, $13, $07 ; 0d
+ db $08, $08, $08, $08 ; 0e
+ db $14, $12, $14, $12 ; 0f
+ db $0b, $11, $02, $14 ; 10
+ db $06, $14, $06, $14 ; 11
+ db $0c, $0c, $0d, $0d ; 12
+ db $0d, $0d, $0d, $0d ; 13
+ db $0e, $0f, $10, $0b ; 14
+ db $12, $13, $12, $13 ; 15
+
+Unkn_f973d:
+ db $00, $00, $00, $01, $01, $01, $01, $01
+Unkn_f9745:
+ db $00, $00, $00, $01, $01, $02, $04, $06
+Unkn_f974d:
+ db $00, $00, $00, $01, $02, $04, $06, $0e
+Unkn_f9755:
+ db $00, $00, $00, $10, $11, $06, $0e, $0e
+Unkn_f975d:
+ db $00, $00, $00, $15, $15, $0e, $0e, $0e
+Unkn_f9765:
+ db $00, $00, $00, $03, $05, $07, $0e, $0e
+Unkn_f976d:
+ db $00, $00, $00, $01, $03, $05, $07, $0e
+Unkn_f9775:
+ db $00, $00, $00, $01, $01, $03, $05, $07
+Unkn_f977d:
+ db $00, $00, $00, $01, $01, $02, $04, $06
+Unkn_f9785:
+ db $00, $00, $00, $01, $02, $04, $06, $0e
+Unkn_f978d:
+ db $00, $00, $00, $08, $0f, $0a, $0e, $0e
+Unkn_f9795:
+ db $00, $00, $00, $09, $0d, $0b, $0e, $0e
+Unkn_f979d:
+ db $00, $00, $00, $01, $03, $05, $07, $0e
+Unkn_f97a5:
+ db $00, $00, $00, $01, $01, $03, $05, $07
+Unkn_f97ad:
+ db $00, $00, $00, $01, $01, $02, $04, $06
+Unkn_f97b5:
+ db $00, $00, $00, $01, $10, $11, $06, $0e
+Unkn_f97bd:
+ db $00, $00, $00, $01, $15, $15, $0e, $0e
+Unkn_f97c5:
+ db $00, $00, $00, $01, $03, $05, $07, $0e
+Unkn_f97cd:
+ db $00, $00, $00, $01, $01, $03, $05, $07
+Unkn_f97d5:
+ db $00, $00, $00, $01, $01, $02, $04, $06
+Unkn_f97dd:
+ db $00, $00, $00, $01, $08, $0f, $0a, $0e
+Unkn_f97e5:
+ db $00, $00, $00, $01, $09, $0d, $0b, $0e
+Unkn_f97ed:
+ db $00, $00, $00, $01, $01, $03, $05, $07
+Unkn_f97f5:
+ db $00, $00, $00, $01, $01, $10, $11, $06
+Unkn_f97fd:
+ db $00, $00, $00, $01, $01, $15, $15, $0e
+Unkn_f9805:
+ db $00, $00, $00, $01, $01, $03, $05, $07
+Unkn_f980d:
+ db $00, $00, $00, $01, $01, $08, $0f, $0a
+Unkn_f9815:
+ db $00, $00, $00, $01, $01, $09, $0d, $0b
+Unkn_f981d:
+ db $00, $00, $00, $14, $14, $14, $14, $14
+Unkn_f9825:
+ db $00, $00, $00, $12, $13, $13, $13, $13
diff --git a/engine/titlescreen.asm b/engine/titlescreen.asm
index fb51d884..c4dff73c 100755
--- a/engine/titlescreen.asm
+++ b/engine/titlescreen.asm
@@ -1,8 +1,3 @@
-; copy text of fixed length NAME_LENGTH (like player name, rival name, mon names, ...)
-CopyFixedLengthText:
- ld bc, NAME_LENGTH
- jp CopyData
-
SetDefaultNamesBeforeTitlescreen:
ld hl, NintenText
ld de, wPlayerName
@@ -35,98 +30,35 @@ DisplayTitleScreen:
call ClearScreen
call DisableLCD
call LoadFontTilePatterns
- ld hl, NintendoCopyrightLogoGraphics
- ld de, vTitleLogo2 + $100
+; todo: fix hl pointers
+ ld hl, NintendoCopyrightLogoGraphics ; 4:4c48
+ ld de, vTitleLogo + $600
ld bc, $50
ld a, BANK(NintendoCopyrightLogoGraphics)
- call FarCopyData2
- ld hl, GamefreakLogoGraphics
- ld de, vTitleLogo2 + $100 + $50
- ld bc, $90
+ call FarCopyData
+ ld hl, NineTile ; 4:4e08
+ ld de, vTitleLogo + $6e0
+ ld bc, $10
+ ld a, BANK(NineTile)
+ call FarCopyData
+ ld hl, GamefreakLogoGraphics ; 4:4d78
+ ld de, vTitleLogo + 101 * $10
+ ld bc, 9 * $10
ld a, BANK(GamefreakLogoGraphics)
- call FarCopyData2
- ld hl, PokemonLogoGraphics
- ld de, vTitleLogo
- ld bc, $600
- ld a, BANK(PokemonLogoGraphics)
- call FarCopyData2 ; first chunk
- ld hl, PokemonLogoGraphics+$600
- ld de, vTitleLogo2
- ld bc, $100
- ld a, BANK(PokemonLogoGraphics)
- call FarCopyData2 ; second chunk
- 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 ClearBothBGMaps
-
-; place tiles for pokemon logo (except for the last row)
- coord hl, 2, 1
- ld a, $80
- ld de, SCREEN_WIDTH
- ld c, 6
-.pokemonLogoTileLoop
- ld b, $10
- push hl
-.pokemonLogoTileRowLoop ; place tiles for one row
- ld [hli], a
- inc a
- dec b
- jr nz, .pokemonLogoTileRowLoop
- pop hl
- add hl, de
- dec c
- jr nz, .pokemonLogoTileLoop
-
-; place tiles for the last row of the pokemon logo
- coord hl, 2, 7
- ld a, $31
- ld b, $10
-.pokemonLogoLastTileRowLoop
- ld [hli], a
- inc a
- dec b
- jr nz, .pokemonLogoLastTileRowLoop
-
- call DrawPlayerCharacter
-
-; put a pokeball in the player's hand
- ld hl, wOAMBuffer + $28
- ld a, $74
- ld [hl], a
-
-; place tiles for title screen copyright
- coord hl, 2, 17
- ld de, .tileScreenCopyrightTiles
- ld b, $10
-.tileScreenCopyrightTilesLoop
- ld a, [de]
- ld [hli], a
- inc de
- dec b
- jr nz, .tileScreenCopyrightTilesLoop
-
- jr .next
-
-.tileScreenCopyrightTiles ; 437f (1:437f)
- db $41,$42,$43,$42,$44,$42,$45,$46,$47,$48,$49,$4A,$4B,$4C,$4D,$4E ; ©'95.'96.'98 GAME FREAK inc.
-
-.next
+ call FarCopyData
+ callab LoadYellowTitleScreenGFX
+ ld hl, vBGMap0
+ ld bc, (vBGMap1 + $400) - vBGMap0
+ ld a, " "
+ call FillMemory
+ callab TitleScreen_PlacePokemonLogo
+ call FillSpriteBuffer0WithAA
+ call .WriteCopyrightTiles
call SaveScreenTilesToBuffer2
call LoadScreenTilesFromBuffer2
call EnableLCD
-IF DEF(_RED)
- ld a,CHARMANDER ; which Pokemon to show first on the title screen
-ENDC
-IF DEF(_BLUE)
- ld a,SQUIRTLE ; which Pokemon to show first on the title screen
-ENDC
-
- ld [wTitleMonSpecies], a
- call LoadTitleMonSprite
- ld a, (vBGMap0 + $300) / $100
+ callab TitleScreen_PlacePikachu
+ ld a, $9b
call TitleScreenCopyTileMapToVRAM
call SaveScreenTilesToBuffer1
ld a, $40
@@ -137,8 +69,9 @@ ENDC
ld b, SET_PAL_TITLE_SCREEN
call RunPaletteCommand
call GBPalNormal
- ld a, %11100100
+ ld a, %11100000
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
; make pokemon logo bounce up and down
ld bc, hSCY ; background scroll Y
@@ -158,7 +91,7 @@ ENDC
call .ScrollTitleScreenPokemonLogo
jr .bouncePokemonLogoLoop
-.TitleScreenPokemonLogoYScrolls:
+.TitleScreenPokemonLogoYScrolls ; 4228 (1:4228)
; 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
@@ -169,7 +102,7 @@ ENDC
db -1,2
db 0 ; terminate list with 0
-.ScrollTitleScreenPokemonLogo
+.ScrollTitleScreenPokemonLogo ; 4237 (1:4237)
; Scrolls the Pokemon logo on the title screen to create the bouncing effect
; Scrolls d pixels e times
call DelayFrame
@@ -180,7 +113,22 @@ ENDC
jr nz, .ScrollTitleScreenPokemonLogo
ret
-.finishedBouncingPokemonLogo
+; place tiles for title screen copyright
+.WriteCopyrightTiles ; 4241 (1:4241)
+ coord hl, 2, 17
+ ld de, .tileScreenCopyrightTiles
+.titleScreenCopyrightTilesLoop
+ ld a, [de]
+ inc de
+ cp $ff
+ ret z
+ ld [hli], a
+ jr .titleScreenCopyrightTilesLoop
+
+.tileScreenCopyrightTiles ; 424f (1:424f)
+ db $e0,$e1,$e2,$e3,$e1,$e2,$ee,$e5,$e6,$e7,$e8,$e9,$ea,$eb,$ec,$ed,$ff ; ©1995-1999 GAME FREAK inc.
+
+.finishedBouncingPokemonLogo ; 4260 (1:4260)
call LoadScreenTilesFromBuffer1
ld c, 36
call DelayFrames
@@ -188,52 +136,42 @@ ENDC
call PlaySound
; scroll game version in from the right
- call PrintGameVersionOnTitleScreen
+ callab TitleScreen_PlacePikaSpeechBubble
ld a, SCREEN_HEIGHT_PIXELS
ld [hWY], a
- ld d, 144
-.scrollTitleScreenGameVersionLoop
- ld h, d
- ld l, 64
- call ScrollTitleScreenGameVersion
- ld h, 0
- ld l, 80
- call ScrollTitleScreenGameVersion
- ld a, d
- add 4
- ld d, a
- and a
- jr nz, .scrollTitleScreenGameVersionLoop
-
- ld a, vBGMap1 / $100
- call TitleScreenCopyTileMapToVRAM
- call LoadScreenTilesFromBuffer2
- call PrintGameVersionOnTitleScreen
call Delay3
+ ld e, 0
+ call TitleScreen_PlayPikachuPCM
call WaitForSoundToFinish
+ call StopAllMusic
ld a, MUSIC_TITLE_SCREEN
ld [wNewSoundID], a
call PlaySound
+.loop
xor a
ld [wUnusedCC5B], a
-
-; Keep scrolling in new mons indefinitely until the user performs input.
-.awaitUserInterruptionLoop
- ld c, 200
- call CheckForUserInterruption
- jr c, .finishedWaiting
- call TitleScreenScrollInMon
- ld c, 1
- call CheckForUserInterruption
- jr c, .finishedWaiting
- callba TitleScreenAnimateBallIfStarterOut
- call TitleScreenPickNewMon
- jr .awaitUserInterruptionLoop
-
-.finishedWaiting
- ld a, [wTitleMonSpecies]
- call PlayCry
- call WaitForSoundToFinish
+ ld [wTitleScreenScene], a
+ ld [wTitleScreenScene + 1], a
+ ld [wTitleScreenScene + 2], a
+ ld [wTitleScreenScene + 3], a
+ ld a, $f
+ ld [wTitleScreenScene + 4], a
+.titleScreenLoop
+ call IncrementResetCounter
+ jp c, .doTitlescreenReset
+ call DelayFrame
+ call JoypadLowSensitivity
+ ld a, [hJoyHeld]
+ cp D_UP | SELECT | B_BUTTON
+ jr z, .go_to_main_menu
+ and A_BUTTON | START
+ jr nz, .go_to_main_menu
+ call DoTitleScreenFunction
+ jr .titleScreenLoop
+
+.go_to_main_menu
+ ld e, $a
+ call TitleScreen_PlayPikachuPCM
call GBPalWhiteOutWithDelay3
call ClearSprites
xor a
@@ -254,108 +192,39 @@ ENDC
jp z, .doClearSaveDialogue
jp MainMenu
-.doClearSaveDialogue
- jpba DoClearSaveDialogue
-
-TitleScreenPickNewMon:
- ld a, vBGMap0 / $100
- call TitleScreenCopyTileMapToVRAM
-
-.loop
-; Keep looping until a mon different from the current one is picked.
- call Random
- and $f
- ld c, a
- ld b, 0
- ld hl, TitleMons
- add hl, bc
- ld a, [hl]
- ld hl, wTitleMonSpecies
-
-; Can't be the same as before.
- cp [hl]
- jr z, .loop
+.asm_42f0 ; 42f0 (1:42f0)
+; unreferenced
+ callab PrinterDebug
+ jp .loop
- ld [hl], a
- call LoadTitleMonSprite
-
- ld a, $90
- ld [hWY], a
- ld d, 1 ; scroll out
- callba TitleScroll
- ret
-
-TitleScreenScrollInMon:
- ld d, 0 ; scroll in
- callba TitleScroll
- xor a
- ld [hWY], a
- ret
-
-ScrollTitleScreenGameVersion:
-.wait
- ld a, [rLY]
- cp l
- jr nz, .wait
-
- ld a, h
- ld [rSCX], a
-
-.wait2
- ld a, [rLY]
- cp h
- jr z, .wait2
- ret
-
-DrawPlayerCharacter:
- ld hl, PlayerCharacterTitleGraphics
- ld de, vSprites
- ld bc, PlayerCharacterTitleGraphicsEnd - PlayerCharacterTitleGraphics
- ld a, BANK(PlayerCharacterTitleGraphics)
- call FarCopyData2
- call ClearSprites
- xor a
- ld [wPlayerCharacterOAMTile], a
- ld hl, wOAMBuffer
- ld de, $605a
- ld b, 7
-.loop
- push de
- ld c, 5
-.innerLoop
- ld a, d
- ld [hli], a ; Y
- ld a, e
- ld [hli], a ; X
- add 8
- ld e, a
- ld a, [wPlayerCharacterOAMTile]
- ld [hli], a ; tile
+.asm_42fb ; 42fb (1:42fb)
+; unreferenced
+ ld a, [wTitleScreenScene + 4]
inc a
- ld [wPlayerCharacterOAMTile], a
- inc hl
- dec c
- jr nz, .innerLoop
- pop de
- ld a, 8
- add d
- ld d, a
- dec b
- jr nz, .loop
- ret
+ cp $2a
+ jr c, .asm_4305
+ ld a, $f
+.asm_4305
+ ld [wTitleScreenScene + 4], a
+ ld e, a
+ callab PlayPikachuSoundClip
+ xor a
+ ld [wTitleScreenScene + 2], a
+ ld [wTitleScreenScene + 3], a
+ jp .titleScreenLoop
+
+.doTitlescreenReset ; 431b (1:431b)
+ ld [wAudioFadeOutControl], a
+ call StopAllMusic
+.audioFadeLoop
+ ld a, [wAudioFadeOutControl]
+ and a
+ jr nz, .audioFadeLoop
+ jp Init
-ClearBothBGMaps:
- ld hl, vBGMap0
- ld bc, $400 * 2
- ld a, " "
- jp FillMemory
+.doClearSaveDialogue ; 432a (1:432a)
+ jpba DoClearSaveDialogue
-LoadTitleMonSprite:
- ld [wcf91], a
- ld [wd0b5], a
- coord hl, 5, 10
- call GetMonHeader
- jp LoadFrontSpriteByMonIndex
TitleScreenCopyTileMapToVRAM:
ld [H_AUTOBGTRANSFERDEST + 1], a
@@ -370,31 +239,132 @@ LoadCopyrightAndTextBoxTiles:
LoadCopyrightTiles:
ld de, NintendoCopyrightLogoGraphics
ld hl, vChars2 + $600
- lb bc, BANK(NintendoCopyrightLogoGraphics), (GamefreakLogoGraphicsEnd - NintendoCopyrightLogoGraphics) / $10
+ lb bc, BANK(NintendoCopyrightLogoGraphics), (TextBoxGraphics + $10 - NintendoCopyrightLogoGraphics) / $10 ; bug: overflows into text box graphics and copies the "A" tile
call CopyVideoData
coord hl, 2, 7
ld de, CopyrightTextString
jp PlaceString
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.
+ db $60,$61,$62,$63,$61,$62,$7c,$7f,$65,$66,$67,$68,$69,$6a ; ©1995-1999 Nintendo
+ next $60,$61,$62,$63,$61,$62,$7c,$7f,$6b,$6c,$6d,$6e,$6f,$70,$71,$72 ; ©1995-1999 Creatures inc.
+ next $60,$61,$62,$63,$61,$62,$7c,$7f,$73,$74,$75,$76,$77,$78,$79,$7a,$7b ; ©1995-1999 GAME FREAK inc.
db "@"
-INCLUDE "data/title_mons.asm"
+TitleScreen_PlayPikachuPCM:
+ callab PlayPikachuSoundClip
+ ret
+
+DoTitleScreenFunction:
+ call .CheckTimer
+ ld a, [wTitleScreenScene]
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+
+.Jumptable:
+ dw .Nop
+ dw .BlinkHalf
+ dw .BlinkWait
+ dw .BlinkWait
+ dw .BlinkClosed
+ dw .BlinkWait
+ dw .BlinkWait
+ dw .BlinkHalf
+ dw .BlinkWait
+ dw .BlinkWait
+ dw .BlinkOpen
+ dw .GoBackToStart
+
+.GoBackToStart:
+ xor a
+ ld [wTitleScreenScene], a
+.Nop
+ ret
+
+.BlinkOpen:
+ ld e, 0
+ jr .LoadBlinkFrame
+
+.BlinkHalf:
+ ld e, 4
+ jr .LoadBlinkFrame
+
+.BlinkClosed:
+ ld e, 8
+.LoadBlinkFrame:
+ ld hl, wOAMBuffer + 2
+ ld c, 8
+.loop
+ ld a, [hl]
+ and $f3
+ or e
+ ld [hli], a
+ inc hl
+ inc hl
+ inc hl
+ dec c
+ jr nz, .loop
+.BlinkWait:
+ ld hl, wTitleScreenScene
+ inc [hl]
+ ret
+
+.CheckTimer:
+ ld hl, wTitleScreenTimer
+ ld a, [hl]
+ inc [hl]
+ and a
+ jr z, .restart
+ cp $80
+ jr z, .restart
+ cp $90
+ ret nz
+.restart
+ ld a, $1
+ ld [wTitleScreenScene], a
+ ret
-; prints version text (red, blue)
-PrintGameVersionOnTitleScreen:
- coord hl, 7, 8
- ld de, VersionOnTitleScreenText
- jp PlaceString
+; copy text of fixed length NAME_LENGTH (like player name, rival name, mon names, ...)
+CopyFixedLengthText:
+ ld bc, NAME_LENGTH
+ jp CopyData
-; these point to special tiles specifically loaded for that purpose and are not usual text
-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@"
+
+IncrementResetCounter:
+ ld hl, wTitleScreenScene + 2
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc de
+ ld a, d
+ cp $c
+ jr z, .doReset
+ ld [hl], d
+ dec hl
+ ld [hl], e
+ and a
+ ret
+
+.doReset
+ scf
+ ret
+
+FillSpriteBuffer0WithAA:
+ xor a
+ call SwitchSRAMBankAndLatchClockData
+ ld hl, sSpriteBuffer0
+ ld bc, $20
+ ld a, $aa
+ call FillMemory
+ call PrepareRTCDataAndDisableSRAM
+ ret
diff --git a/engine/titlescreen2.asm b/engine/titlescreen2.asm
index 2ed77dec..92282b83 100755
--- a/engine/titlescreen2.asm
+++ b/engine/titlescreen2.asm
@@ -1,3 +1,5 @@
+; Leftover of Red/Blue. Seemingly unused
+
TitleScroll_WaitBall:
; Wait around for the TitleBall animation to play out.
; hi: speed
@@ -67,7 +69,7 @@ _TitleScroll:
pop bc
jr _TitleScroll
-.ScrollBetween ; 37292 (d:7292)
+.ScrollBetween ; 374ec (d:74ec)
.wait
ld a, [rLY] ; rLY
cp l
@@ -89,7 +91,7 @@ TitleBallYTable:
TitleScreenAnimateBallIfStarterOut:
; Animate the TitleBall if a starter just got scrolled out.
- ld a, [wTitleMonSpecies]
+ ld a, [wTitleScreenScene]
cp STARTER1
jr z, .ok
cp STARTER2
diff --git a/engine/town_map.asm b/engine/town_map.asm
index b2f1e656..65a10912 100755
--- a/engine/town_map.asm
+++ b/engine/town_map.asm
@@ -27,7 +27,7 @@ DisplayTownMap:
pop af
jr .enterLoop
-.townMapLoop
+.townMapLoop ; 70ef4 (1c:4ef4)
coord hl, 0, 0
lb bc, 1, 20
call ClearScreenArea
@@ -37,7 +37,7 @@ DisplayTownMap:
ld b, 0
add hl, bc
ld a, [hl]
-.enterLoop
+.enterLoop ; 70f08 (1c:4f08)
ld de, wTownMapCoords
call LoadTownMapEntry
ld a, [de]
@@ -69,7 +69,7 @@ DisplayTownMap:
ld b, a
and A_BUTTON | B_BUTTON | D_UP | D_DOWN
jr z, .inputLoop
- ld a, SFX_TINK
+ ld a, $8c
call PlaySound
bit 6, b
jr nz, .pressedUp
@@ -84,6 +84,7 @@ DisplayTownMap:
pop af
ld [hl], a
ret
+
.pressedUp
ld a, [wWhichTownMapLocation]
inc a
@@ -103,6 +104,13 @@ DisplayTownMap:
ld [wWhichTownMapLocation], a
jp .townMapLoop
+.asm_70f87
+ ld a,[hJoy5]
+ and D_DOWN | D_UP
+ ret z
+ callab PlayPikachuSoundClip
+ ret
+
INCLUDE "data/town_map_order.asm"
TownMapCursor:
@@ -137,11 +145,14 @@ MonsNestText:
LoadTownMap_Fly:
call ClearSprites
call LoadTownMap
+ ld a, $1
+ ld [hJoy7], a
call LoadPlayerSpriteGraphics
call LoadFontTilePatterns
- ld de, BirdSprite
+ ld de, BirdSprite ; $4d80
+ ld b, BANK(BirdSprite)
+ ld c, $c
ld hl, vSprites + $40
- lb bc, BANK(BirdSprite), $0c
call CopyVideoData
ld de, TownMapUpArrow
ld hl, vChars1 + $6d0
@@ -179,7 +190,7 @@ LoadTownMap_Fly:
ld c, 15
call DelayFrames
coord hl, 18, 0
- ld [hl], $ed
+ ld [hl], "▶"
coord hl, 19, 0
ld [hl], $ee
pop hl
@@ -194,7 +205,7 @@ LoadTownMap_Fly:
jr z, .inputLoop
bit 0, b
jr nz, .pressedA
- ld a, SFX_TINK
+ ld a, $8c ; SFX_TINK
call PlaySound
bit 6, b
jr nz, .pressedUp
@@ -202,7 +213,7 @@ LoadTownMap_Fly:
jr nz, .pressedDown
jr .pressedB
.pressedA
- ld a, SFX_HEAL_AILMENT
+ ld a, $8e ; SFX_HEAL_AILMENT
call PlaySound
ld a, [hl]
ld [wDestinationMap], a
@@ -213,6 +224,7 @@ LoadTownMap_Fly:
.pressedB
xor a
ld [wTownMapSpriteBlinkingEnabled], a
+ ld [hJoy7], a
call GBPalWhiteOutWithDelay3
pop hl
pop af
@@ -279,16 +291,15 @@ LoadTownMap:
call ClearScreen
call UpdateSprites
coord hl, 0, 0
- ld b, $12
- ld c, $12
+ lb bc, $12, $12
call TextBoxBorder
call DisableLCD
ld hl, WorldMapTileGraphics
ld de, vChars2 + $600
ld bc, WorldMapTileGraphicsEnd - WorldMapTileGraphics
ld a, BANK(WorldMapTileGraphics)
- call FarCopyData2
- ld hl, MonNestIcon
+ call FarCopyData
+ ld hl, MonNestIcon ; $574b
ld de, vSprites + $40
ld bc, MonNestIconEnd - MonNestIcon
ld a, BANK(MonNestIcon)
@@ -355,12 +366,12 @@ DrawPlayerOrBirdSprite:
call WritePlayerOrBirdSpriteOAM
pop hl
ld de, wcd6d
-.asm_711dc
+.asm_71266
ld a, [hli]
ld [de], a
inc de
- cp $50
- jr nz, .asm_711dc
+ cp "@"
+ jr nz, .asm_71266
ld hl, wOAMBuffer
ld de, wTileMapBackup
ld bc, $a0
@@ -397,8 +408,7 @@ DisplayWildLocations:
jr nz, .drawPlayerSprite
; if no OAM entries were written, print area unknown text
coord hl, 1, 7
- ld b, $2
- ld c, $f
+ lb bc, 2, 15
call TextBoxBorder
coord hl, 2, 9
ld de, AreaUnknownText
@@ -455,7 +465,7 @@ WriteTownMapSpriteOAM:
pop hl
WriteAsymmetricMonPartySpriteOAM:
-; Writes 4 OAM blocks for a helix mon party sprite, since it does not have
+; Writes 4 OAM blocks for a helix mon party sprite, since is does not have
; a vertical line of symmetry.
lb de, 2, 2
.loop
@@ -473,14 +483,14 @@ WriteAsymmetricMonPartySpriteOAM:
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
@@ -582,9 +592,14 @@ LoadTownMapEntry:
ld l, a
ret
+; ExternalMapEntries:
+ ; dr $7139c,$7140b
+; InternalMapEntries:
+ ; dr $7140b,$7174b
+
INCLUDE "data/town_map_entries.asm"
-INCLUDE "text/map_names.asm"
+INCLUDE "text/map_names.asm" ; TODO: relabel addresses
MonNestIcon:
INCBIN "gfx/mon_nest_icon.1bpp"
diff --git a/engine/trade.asm b/engine/trade.asm
index 78444cf6..bbd43779 100755
--- a/engine/trade.asm
+++ b/engine/trade.asm
@@ -20,12 +20,13 @@ ExternalClockTradeAnim:
TradeAnimCommon:
ld a, [wOptions]
push af
+ and %110000 ; preserve speaker options
+ ld [wOptions], a
ld a, [hSCY]
push af
ld a, [hSCX]
push af
xor a
- ld [wOptions], a
ld [hSCY], a
ld [hSCX], a
push de
@@ -160,12 +161,12 @@ LoadTradingGFXAndMonNames:
ld de, vChars2 + $310
ld bc, TradingAnimationGraphicsEnd - TradingAnimationGraphics
ld a, BANK(TradingAnimationGraphics)
- call FarCopyData2
+ call FarCopyData
ld hl, TradingAnimationGraphics2
ld de, vSprites + $7c0
ld bc, TradingAnimationGraphics2End - TradingAnimationGraphics2
ld a, BANK(TradingAnimationGraphics2)
- call FarCopyData2
+ call FarCopyData
ld hl, vBGMap0
ld bc, $800
ld a, " "
@@ -182,6 +183,7 @@ LoadTradingGFXAndMonNames:
ld a, $f0 ; SGB OBP0
.next
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
call EnableLCD
xor a
ld [H_AUTOBGTRANSFERENABLED], a
@@ -199,6 +201,7 @@ LoadTradingGFXAndMonNames:
Trade_LoadMonPartySpriteGfx:
ld a, %11010000
ld [rOBP1], a
+ call UpdateGBCPal_OBP1
jpba LoadMonPartySpriteGfx
Trade_SwapNames:
@@ -233,8 +236,7 @@ Trade_ShowPlayerMon:
xor a
ld [H_AUTOBGTRANSFERENABLED], a
coord hl, 4, 0
- ld b, 6
- ld c, 10
+ lb bc, 6, 10
call TextBoxBorder
call Trade_PrintPlayerMonInfoText
ld b, vBGMap0 / $100
@@ -251,7 +253,7 @@ Trade_ShowPlayerMon:
ld [hSCX], a
dec a
dec a
- and a
+ and a ; useless since flags are updated with dec a
jr nz, .slideScreenLoop
call Trade_Delay80
ld a, TRADE_BALL_POOF_ANIM
@@ -303,9 +305,10 @@ Trade_AnimateBallEnteringLinkCable:
call DelayFrames
ld a, %11100100
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
xor a
ld [wLinkCableAnimBulgeToggle], a
- ld bc, $2060
+ lb bc, $20, $60
.moveBallInsideLinkCableLoop
push bc
xor a
@@ -354,8 +357,7 @@ Trade_ShowEnemyMon:
call Trade_ShowAnimation
call Trade_ShowClearedWindow
coord hl, 4, 10
- ld b, 6
- ld c, 10
+ lb bc, 6, 10
call TextBoxBorder
call Trade_PrintEnemyMonInfoText
call Trade_CopyTileMapToVRAM
@@ -380,8 +382,9 @@ Trade_AnimLeftToRight:
call Trade_InitGameboyTransferGfx
ld a, $1
ld [wTradedMonMovingRight], a
- ld a, $e4
+ ld a, %11100100
ld [rOBP0], a
+ call UpdateGBCPal_OBP0
ld a, $54
ld [wBaseCoordX], a
ld a, $1c
@@ -446,6 +449,8 @@ Trade_InitGameboyTransferGfx:
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
call ClearScreen
+ ld b, SET_PAL_GENERIC
+ call RunPaletteCommand
xor a
ld [H_AUTOBGTRANSFERENABLED], a
call Trade_LoadMonPartySpriteGfx
@@ -466,7 +471,7 @@ Trade_DrawLeftGameboy:
ld a, $5d
ld [hli], a
ld a, $5e
- ld c, $8
+ ld c, 8
.loop
ld [hli], a
dec c
@@ -479,8 +484,7 @@ Trade_DrawLeftGameboy:
; draw text box with player name below gameboy pic
coord hl, 4, 12
- ld b, 2
- ld c, 7
+ lb bc, 2, 7
call TextBoxBorder
coord hl, 5, 14
ld de, wPlayerName
@@ -526,8 +530,7 @@ Trade_DrawRightGameboy:
; draw text box with enemy name above link cable
coord hl, 6, 0
- ld b, $2
- ld c, $7
+ lb bc, 2, 7
call TextBoxBorder
coord hl, 7, 2
ld de, wLinkEnemyTrainerName
@@ -599,6 +602,7 @@ Trade_AnimCircledMon:
ld a, [rBGP]
xor $3c ; make link cable flash
ld [rBGP], a
+ call UpdateGBCPal_BGP
ld hl, wOAMBuffer + $02
ld de, $4
ld c, $14
@@ -620,7 +624,7 @@ Trade_WriteCircledMonOAM:
Trade_AddOffsetsToOAMCoords:
ld hl, wOAMBuffer
- ld c, $14
+ ld c, $14 ; SCREEN_WIDTH?
.loop
ld a, [wBaseCoordY]
add [hl]
diff --git a/engine/trade2.asm b/engine/trade2.asm
index 16d07b17..c47da36a 100755
--- a/engine/trade2.asm
+++ b/engine/trade2.asm
@@ -43,7 +43,7 @@ Trade_PrintEnemyMonInfoText:
jp PrintNumber
Trade_MonInfoText:
- db "──",$74,$F2,$4E
- db $4E
- db "OT/",$4E
- db $73,"№",$F2,"@"
+ db "──",$74,$F2
+ db $4e ; next
+ next "OT/"
+ next $73,"№",$F2,"@"
diff --git a/engine/turn_sprite.asm b/engine/turn_sprite.asm
deleted file mode 100755
index e8a47a8f..00000000
--- a/engine/turn_sprite.asm
+++ /dev/null
@@ -1,25 +0,0 @@
-UpdateSpriteFacingOffsetAndDelayMovement:
- ld h, $c2
- ld a, [H_CURRENTSPRITEOFFSET]
- add $8
- ld l, a
- ld a, $7f ; maximum movement delay
- ld [hl], a ; c2x8 (movement delay)
- dec h
- ld a, [H_CURRENTSPRITEOFFSET]
- add $9
- ld l, a
- ld a, [hld] ; c1x9 (facing direction)
- ld b, a
- xor a
- ld [hld], a
- ld [hl], a ; c1x8 (walk animation frame)
- ld a, [H_CURRENTSPRITEOFFSET]
- add $2
- ld l, a
- ld a, [hl] ; c1x2 (facing and animation table offset)
- or b ; or in the facing direction
- ld [hld], a
- ld a, $2 ; delayed movement status
- ld [hl], a ; c1x1 (movement status)
- ret
diff --git a/engine/unknown_ea3ea.asm b/engine/unknown_ea3ea.asm
new file mode 100755
index 00000000..ca5d8bff
--- /dev/null
+++ b/engine/unknown_ea3ea.asm
@@ -0,0 +1,977 @@
+Printer_GetMonStats:
+ call GBPalWhiteOutWithDelay3
+ call ClearScreen
+ call LoadHpBarAndStatusTilePatterns
+ ld de, GFX_ea563
+ ld hl, vChars2 + $710
+ lb bc, BANK(GFX_ea563), (GFX_ea563End - GFX_ea563) / 8
+ call CopyVideoDataDouble
+
+ ld de, GFX_ea56b
+ ld hl, vChars2 + $6e0
+ lb bc, BANK(GFX_ea56b), (GFX_ea56bEnd - GFX_ea56b) / 8
+ call CopyVideoDataDouble
+
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ xor a
+ ld [wWhichTradeMonSelectionMenu], a
+ call LoadMonData
+
+ ld hl, wTileMap
+ lb bc, 16, 18
+ call TextBoxBorder
+
+ coord hl, 0, 12
+ lb bc, 4, 18
+ call TextBoxBorder
+
+ coord hl, 3, 10
+ call PrintLevelFull
+
+ coord hl, 2, 10
+ ld a, $6e
+ ld [hli], a
+ ld [hl], " "
+
+ coord hl, 2, 11
+ ld [hl], "′"
+
+ coord hl, 4, 11
+ ld de, wLoadedMonMaxHP
+ lb bc, 2, 3
+ call PrintNumber
+
+ ld a, [wMonHeader]
+ ld [wPokeBallAnimData], a
+ ld [wd0b5], a
+ ld hl, wPartyMonNicks
+ call .GetNamePointer
+ coord hl, 8, 2
+ call PlaceString
+
+ call GetMonName
+ coord hl, 9, 3
+ call PlaceString
+
+ predef IndexToPokedex
+ coord hl, 2, 8
+ ld [hl], "№"
+ inc hl
+ ld [hl], $f2
+ inc hl
+ ld de, wPokeBallAnimData
+ lb bc, $80 | 1, 3
+ call PrintNumber
+
+ coord hl, 8, 4
+ ld de, .OT
+ call PlaceString
+
+ ld hl, wPartyMonOT
+ call .GetNamePointer
+ coord hl, 9, 5
+ call PlaceString
+
+ coord hl, 9, 6
+ ld de, .IDNo
+ call PlaceString
+
+ coord hl, 13, 6
+ ld de, wLoadedMonOTID
+ lb bc, $80 | 2, 5
+ call PrintNumber
+
+ coord hl, 9, 8
+ ld de, .Stats
+ ld a, [hFlags_0xFFFA]
+ set 2, a
+ ld [hFlags_0xFFFA], a
+ call PlaceString
+ ld a, [hFlags_0xFFFA]
+ res 2, a
+ ld [hFlags_0xFFFA], a
+
+ coord hl, 16, 8
+ ld de, wLoadedMonAttack
+ ld a, 4
+.loop
+ push af
+ push de
+
+ push hl
+ lb bc, 2, 3
+ call PrintNumber
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+
+ pop de
+ inc de
+ inc de
+ pop af
+ dec a
+ jr nz, .loop
+
+ coord hl, 1, 13
+ ld a, [wLoadedMonMoves]
+ call .PlaceMoveName
+
+ coord hl, 1, 14
+ ld a, [wLoadedMonMoves + 1]
+ call .PlaceMoveName
+
+ coord hl, 1, 15
+ ld a, [wLoadedMonMoves + 2]
+ call .PlaceMoveName
+
+ coord hl, 1, 16
+ ld a, [wLoadedMonMoves + 3]
+ call .PlaceMoveName
+
+ ld b, $4 ; SET_PAL_STATUS_SCREEN
+ call RunPaletteCommand
+
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call Delay3
+ call GBPalNormal
+ coord hl, 1, 1
+ call LoadFlippedFrontSpriteByMonIndex
+ ret
+
+.GetNamePointer:
+ ld bc, NAME_LENGTH
+ ld a, [wWhichPokemon]
+ call AddNTimes
+ ld e, l
+ ld d, h
+ ret
+
+.PlaceMoveName:
+ and a
+ jr z, .no_move
+ ld [wPokeBallAnimData], a
+ call GetMoveName
+ jr .place_string
+
+.no_move
+ ld de, .Blank
+.place_string
+ call PlaceString
+ ret
+; ea52f
+
+.OT:
+ db "OT/@"
+; ea533
+
+.IDNo:
+ db $73, "№/@"
+; ea537
+
+.Stats:
+ db "ATTACK"
+ next "DEFENSE"
+ next "SPEED"
+ next "SPECIAL@"
+; ea554
+
+.Blank:
+ db "--------------@"
+
+GFX_ea563:
+INCBIN "gfx/stats_screen_hp.1bpp"
+GFX_ea563End:
+
+GFX_ea56b:
+INCBIN "gfx/stats_screen_lv.1bpp"
+GFX_ea56bEnd:
+
+PrinterDebug_LoadGFX:
+ ld hl, vChars1 + $7e0
+ ld de, GFX_ea597
+ lb bc, BANK(GFX_ea597), (GFX_ea597End - GFX_ea597) / 16
+ call CopyVideoData
+
+ ld hl, wOAMBuffer + 32 * 4
+ ld a, $8
+ ld c, $8
+.loop
+ ld [hl], $10
+ inc hl
+ ld [hl], a
+ inc hl
+ ld [hl], $fe
+ inc hl
+ ld [hl], $0
+ inc hl
+ add $8
+ dec c
+ jr nz, .loop
+ ret
+
+GFX_ea597:
+INCBIN "gfx/zero_one_ea597.2bpp"
+GFX_ea597End:
+
+PrinterDebug_ConvertStatusFlagsToTiles:
+ ld hl, wOAMBuffer + 32 * 4 + 2
+ ld de, 4
+ ld a, [wPrinterStatusFlags]
+ ld c, 8
+.loop
+ sla a
+ jr c, .place_1
+ ld [hl], $fe
+ jr .okay
+
+.place_1
+ ld [hl], $ff
+.okay
+ add hl, de
+ dec c
+ jr nz, .loop
+ ret
+
+PrinterDebug_DoFunction:
+ ld a, [wPrinterSendState]
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.Jumptable:
+ dw Func_ea623
+ dw Func_ea6d2
+ dw Func_ea6af
+ dw Func_ea645
+ dw Func_ea701
+ dw Func_ea6bd
+ dw Func_ea671
+ dw Func_ea701
+ dw Func_ea6af
+ dw Func_ea68a
+ dw Func_ea701
+ dw Func_ea6af
+ dw Func_ea721
+ dw Func_ea610
+ dw Func_ea61a
+ dw Func_ea6af
+ dw Func_ea61e
+ dw Func_ea72f
+ dw Func_ea732
+
+Func_ea606:
+ ld hl, wPrinterSendState
+ inc [hl]
+ ret
+
+Func_ea60b:
+ ld hl, wPrinterSendState
+ dec [hl]
+ ret
+
+Func_ea610:
+ xor a
+ ld [wPrinterStatusFlags], a
+ ld hl, wPrinterSendState
+ set 7, [hl]
+ ret
+
+Func_ea61a:
+ call Func_ea606
+ ret
+
+Func_ea61e:
+ xor a
+ ld [wPrinterSendState], a
+ ret
+
+Func_ea623:
+ call Func_ea784
+ ld hl, Data_ea9de
+ call Func_ea76b
+ xor a
+ ld [wPrinterDataSize], a
+ ld [wPrinterDataSize + 1], a
+ ld a, [wPrinterQueueLength]
+ ld [wPrinterRowIndex], a
+ call Func_ea606
+ call Func_ea74c
+ ld a, $1
+ ld [wPrinterStatusIndicator], a
+ ret
+
+Func_ea645:
+ call Func_ea784
+ ld hl, wPrinterRowIndex
+ ld a, [hl]
+ and a
+ jr z, Func_ea671
+ ld hl, Data_ea9ea
+ call Func_ea76b
+ call PrinterDebug_PrepOAMForPrinting
+ ld a, $80
+ ld [wPrinterDataSize], a
+ ld a, $2
+ ld [wPrinterDataSize + 1], a
+ call Func_ea7a2
+ call Func_ea606
+ call Func_ea74c
+ ld a, $2
+ ld [wPrinterStatusIndicator], a
+ ret
+
+Func_ea671:
+ ld a, $6
+ ld [wPrinterSendState], a
+ ld hl, Data_ea9f0
+ call Func_ea76b
+ xor a
+ ld [wPrinterDataSize], a
+ ld [wPrinterDataSize + 1], a
+ call Func_ea606
+ call Func_ea74c
+ ret
+
+Func_ea68a:
+ call Func_ea784
+ ld hl, Data_ea9e4
+ call Func_ea76b
+ call Func_ea7d2
+ ld a, $4
+ ld [wPrinterDataSize], a
+ ld a, $0
+ ld [wPrinterDataSize + 1], a
+ call Func_ea7a2
+ call Func_ea606
+ call Func_ea74c
+ ld a, $3
+ ld [wPrinterStatusIndicator], a
+ ret
+
+Func_ea6af:
+ ld hl, wPrinterSerialFrameDelay
+ inc [hl]
+ ld a, [hl]
+ cp a, $6
+ ret c
+ xor a
+ ld [hl], a
+ call Func_ea606
+ ret
+
+Func_ea6bd:
+ ld hl, wPrinterSerialFrameDelay
+ inc [hl]
+ ld a, [hl]
+ cp 6
+ ret c
+ xor a
+ ld [hl], a
+ ld hl, wPrinterRowIndex
+ dec [hl]
+ call Func_ea60b
+ call Func_ea60b
+ ret
+
+Func_ea6d2:
+ call Func_ea742
+ ret c
+ ld a, [wPrinterHandshake]
+ cp a, $ff
+ jr nz, .asm_ea6e4
+ ld a, [wPrinterStatusFlags]
+ cp a, $ff
+ jr z, .asm_ea6fb
+.asm_ea6e4
+ ld a, [wPrinterHandshake]
+ cp a, $81
+ jr nz, .asm_ea6fb
+ ld a, [wPrinterStatusFlags]
+ cp a, $0
+ jr nz, .asm_ea6fb
+ ld hl, wPrinterConnectionOpen
+ set 1, [hl]
+ call Func_ea606
+ ret
+
+.asm_ea6fb
+ ld a, $e
+ ld [wPrinterSendState], a
+ ret
+
+Func_ea701:
+ call Func_ea742
+ ret c
+ ld a, [wPrinterStatusFlags]
+ and $f0
+ jr nz, .asm_ea71b
+ ld a, [wPrinterStatusFlags]
+ and $1
+ jr nz, .asm_ea717
+ call Func_ea606
+ ret
+
+.asm_ea717
+ call Func_ea60b
+ ret
+
+.asm_ea71b
+ ld a, $11
+ ld [wPrinterSendState], a
+ ret
+
+Func_ea721:
+ call Func_ea742
+ ret c
+ ld a, [wPrinterStatusFlags]
+ and $f3
+ ret nz
+ call Func_ea606
+ ret
+
+Func_ea72f:
+ call Func_ea606
+Func_ea732:
+ ld a, [wPrinterOpcode]
+ and a
+ ret nz
+ ld a, [wPrinterStatusFlags]
+ and $f0
+ ret nz
+ xor a
+ ld [wPrinterSendState], a
+ ret
+
+Func_ea742:
+ ld a, [wPrinterOpcode]
+ and a
+ jr nz, .asm_ea74a
+ and a
+ ret
+
+.asm_ea74a
+ scf
+ ret
+
+Func_ea74c:
+.asm_ea74c
+ ld a, [wPrinterOpcode]
+ and a
+ jr nz, .asm_ea74c
+ ld a, $1
+ ld [wPrinterOpcode], a
+ xor a
+ ld [wPrinterSendByteOffset], a
+ ld [wPrinterSendByteOffset + 1], a
+ ld a, $88
+ ld [rSB], a
+ ld a, $1
+ ld [rSC], a
+ ld a, $81
+ ld [rSC], a
+ ret
+
+Func_ea76b:
+ ld a, [hli]
+ ld [wPrinterDataHeader], a
+ ld a, [hli]
+ ld [wPrinterDataHeader + 1], a
+ ld a, [hli]
+ ld [wPrinterDataHeader + 2], a
+ ld a, [hli]
+ ld [wPrinterDataHeader + 3], a
+ ld a, [hli]
+ ld [wPrinterDataHeader + 4], a
+ ld a, [hl]
+ ld [wPrinterDataHeader + 5], a
+ ret
+
+Func_ea784:
+ xor a
+ ld hl, wPrinterDataHeader
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ld hl, wPrinterDataHeader + 4
+ ld [hli], a
+ ld [hl], a
+ xor a
+ ld [wPrinterDataSize], a
+ ld [wPrinterDataSize + 1], a
+ ld hl, wPrinterSendDataSource1
+ ld bc, $280
+ call FillMemory
+ ret
+
+Func_ea7a2:
+ ld hl, $0
+ ld bc, $4
+ ld de, wPrinterDataHeader
+ call Func_ea7c5
+ ld a, [wPrinterDataSize]
+ ld c, a
+ ld a, [wPrinterDataSize + 1]
+ ld b, a
+ ld de, wPrinterSendDataSource1
+ call Func_ea7c5
+ ld a, l
+ ld [wPrinterDataHeader + 4], a
+ ld a, h
+ ld [wPrinterDataHeader + 5], a
+ ret
+
+Func_ea7c5:
+.asm_ea7c5
+ ld a, [de]
+ inc de
+ add l
+ jr nc, .asm_ea7cb
+ inc h
+.asm_ea7cb
+ ld l, a
+ dec bc
+ ld a, c
+ or b
+ jr nz, .asm_ea7c5
+ ret
+
+Func_ea7d2:
+ ld a, $1
+ ld [wPrinterSendDataSource1], a
+ ld a, [wcae2]
+ ld [wPrinterStatusReceived], a
+ ld a, $e4
+ ld [wc6f2], a
+ ld a, [wPrinterSettingsTempCopy]
+ ld [wc6f3], a
+ ret
+
+PrinterDebug_PrepOAMForPrinting:
+ ld a, [wPrinterRowIndex]
+ ld b, a
+ ld a, [wPrinterQueueLength]
+ sub b
+ ld hl, wPrinterTileBuffer
+ ld de, $28
+.get_start_addr
+ and a
+ jr z, .start_working
+ add hl, de
+ dec a
+ jr .get_start_addr
+
+.start_working
+ ld e, l
+ ld d, h
+ ld hl, wPrinterSendDataSource1
+ ld c, $28
+.prep_loop
+ ld a, [de]
+ inc de
+ push bc
+ push de
+ push hl
+ swap a
+ ld d, a
+ and $f0
+ ld e, a
+ ld a, d
+ and $f
+ ld d, a
+ and $8
+ ld a, d
+ jr nz, .vtiles1
+ or $90
+ jr .got_vram_address
+
+.vtiles1
+ or $80
+.got_vram_address
+ ld d, a
+ lb bc, BANK(PrinterDebug_PrepOAMForPrinting), $1
+ call CopyVideoData
+ pop hl
+ ld de, $10
+ add hl, de
+ pop de
+ pop bc
+ dec c
+ jr nz, .prep_loop
+ call .UnnecessaryCall
+ ret
+
+.UnnecessaryCall:
+ ld hl, wcbdc
+ ld bc, $20
+ xor a
+ call FillMemory
+ ld hl, wOAMBuffer
+ ld c, $28
+.master_loop
+ push bc
+ push hl
+ call .AreWePrintingThisSegment
+ jr nc, .skip_segment
+ call .GetVRAMAddress
+ call .GetOAMFlags
+ call .ApplyObjectPalettes
+ call .PlaceObject
+.skip_segment
+ pop hl
+ inc hl
+ inc hl
+ inc hl
+ inc hl
+ pop bc
+ dec c
+ jr nz, .master_loop
+ ret
+
+.AreWePrintingThisSegment:
+ ld a, [wPrinterRowIndex]
+ ld b, a
+ ld a, [wPrinterQueueLength]
+ sub b
+ ld c, a
+ ld b, $10
+.add_n_times
+ ld a, c
+ and a
+ jr z, .check
+ ld a, b
+ add $10
+ ld b, a
+ dec c
+ jr .add_n_times
+
+.check
+ ld a, b
+ ld e, a
+ add $10
+ ld d, a
+ ld a, [hl]
+ cp e
+ jr c, .not_printing
+ cp d
+ jr nc, .not_printing
+ scf
+ ret
+
+.not_printing
+ and a
+ ret
+
+.GetVRAMAddress:
+ push hl
+ inc hl
+ inc hl
+ ld a, [hl]
+ swap a
+ ld d, a
+ and $f0
+ ld e, a
+ ld a, d
+ and $f
+ or $80
+ ld d, a
+ ld hl, wcbdc
+ lb bc, BANK(.GetVRAMAddress), $1
+ call CopyVideoData
+ pop hl
+ ret
+
+.GetOAMFlags:
+ push hl
+ inc hl
+ inc hl
+ inc hl
+ ld a, [hl]
+ call .DoBitOperation
+ pop hl
+ ret
+
+.DoBitOperation:
+ and $60
+ swap a
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.Jumptable:
+ dw .nop
+ dw .xflip
+ dw .yflip
+ dw .both
+
+.nop:
+ ret
+
+.xflip:
+ call .XFlip
+ ret
+
+.yflip:
+ call .YFlip
+ ret
+
+.both:
+ call .XFlip
+ call .YFlip
+ ret
+
+.XFlip:
+ ld hl, wcbdc
+ ld c, 16
+.byte_loop
+ ld d, [hl]
+ ld a, 0
+ ld b, 8
+.bit_loop
+ sla d
+ rr a
+ dec b
+ jr nz, .bit_loop
+ ld [hli], a
+ dec c
+ jr nz, .byte_loop
+ ret
+
+.YFlip:
+ ld hl, wcbdc
+ ld de, wcbea
+ ld c, $4
+.swap_loop
+ ld b, [hl]
+ ld a, [de]
+ ld [hli], a
+ ld a, b
+ ld [de], a
+ inc de
+ ld b, [hl]
+ ld a, [de]
+ ld [hli], a
+ ld a, b
+ ld [de], a
+ dec de
+ dec de
+ dec de
+ dec c
+ jr nz, .swap_loop
+ ret
+
+.ApplyObjectPalettes:
+ push hl
+ ld hl, wcbdc
+ ld de, wcbec
+ ld a, 8
+.loop1
+ push af
+ ld bc, $0
+ ld a, 8
+.loop2
+ push af
+ xor a
+ rlc [hl]
+ rl a
+ inc hl
+ rlc [hl]
+ rl a
+ dec hl
+ push hl
+ push de
+ call .ExpandPalettesToBC
+ pop de
+ pop hl
+ pop af
+ dec a
+ jr nz, .loop2
+ inc hl
+ inc hl
+ ld a, b
+ ld [de], a
+ inc de
+ ld a, c
+ ld [de], a
+ inc de
+ pop af
+ dec a
+ jr nz, .loop1
+ pop hl
+ ret
+
+.ExpandPalettesToBC:
+ call .GetPaletteFunction
+ call .ApplyPaletteFunction
+ ret
+
+.GetPaletteFunction:
+ ld e, a
+ ld d, 0
+ ld hl, .PalJumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.PalJumptable:
+ dw .Pal0
+ dw .Pal1
+ dw .Pal2
+ dw .Pal3
+
+.Pal0:
+ ld a, [rOBP0]
+ and $3
+ ret
+
+.Pal2:
+ ld a, [rOBP0]
+ and $c
+ srl a
+ srl a
+ ret
+
+.Pal1:
+ ld a, [rOBP0]
+ and $30
+ swap a
+ ret
+
+.Pal3:
+ ld a, [rOBP0]
+ and $c0
+ rlca
+ rlca
+ ret
+
+.ApplyPaletteFunction:
+ ld e, a
+ ld d, 0
+ ld hl, .PalFunJumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+.PalFunJumptable:
+ dw .zero_zero
+ dw .xflip_zero
+ dw .zero_xflip
+ dw .xflip_xflip
+
+.zero_zero:
+ sla b
+ sla c
+ ret
+
+.xflip_zero:
+ scf
+ rl b
+ sla c
+ ret
+
+.zero_xflip:
+ sla b
+ scf
+ rl c
+ ret
+
+.xflip_xflip:
+ scf
+ rl b
+ scf
+ rl c
+ ret
+
+.PlaceObject:
+ push hl
+ ld a, [hli]
+ ld c, [hl]
+ and $8
+ jr nz, .use_source_2
+ ld hl, wPrinterSendDataSource1
+ jr .got_data_source
+
+.use_source_2
+ ld hl, wPrinterSendDataSource2
+.got_data_source
+ ld b, $0
+ ld a, c
+ and %11111000
+ sub $8
+ ld c, a
+ sla c
+ rl b
+ add hl, bc
+ ld e, l
+ ld d, h
+ ld hl, wcbec
+ ld c, $8
+.coord_copy_loop
+ call .GetBitMask
+ ld a, [de]
+ and b
+ or [hl]
+ ld [de], a
+ inc hl
+ inc de
+ ld a, [de]
+ and b
+ or [hl]
+ ld [de], a
+ inc hl
+ inc de
+ dec c
+ jr nz, .coord_copy_loop
+ pop hl
+ ret
+
+.GetBitMask:
+ push hl
+ push de
+ ld de, -$10
+ add hl, de
+ ld a, [hli]
+ or [hl]
+ xor $ff
+ ld b, a
+ pop de
+ pop hl
+ ret
+
+Data_ea9de: ; ea9de
+ db 1, 0, $00, 0
+ dw 1
+Data_ea9e4: ; ea9e4
+ db 2, 0, $04, 0
+ dw 0
+Data_ea9ea: ; ea9ea
+ db 4, 0, $80, 2
+ dw 0
+Data_ea9f0: ; ea9f0
+ db 4, 0, $00, 0
+ dw 4
+Data_ea9f6: ; ea9f6
+ db 8, 0, $00, 0
+ dw 8
+Data_ea9fc: ; ea9fc
+ db 15, 0, $00, 0
+ dw 15
diff --git a/engine/vermilion_gym_trash_cans.asm b/engine/vermilion_gym_trash_cans.asm
new file mode 100755
index 00000000..49dee50c
--- /dev/null
+++ b/engine/vermilion_gym_trash_cans.asm
@@ -0,0 +1,108 @@
+TrashCanRandom:
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call JumpToAddress
+ ld e, a
+ ld d, 0
+ ret
+
+.Jumptable:
+ dw .zero
+ dw .one
+ dw .two
+ dw .three
+ dw .four
+
+.zero
+.one
+ ld a, 0
+ ret
+
+.two
+ call Random
+ and $1
+ ret
+
+.three ; should return to a, instead returns to b
+ call Random
+ swap a
+ cp 1 * $ff / 3
+ ld b, 0
+ ret c
+ cp 2 * $ff / 3
+ ld b, 1
+ ret c
+ ld b, 2
+ ret
+
+.four
+ call Random
+ and $3
+ ret
+
+Yellow_SampleSecondTrashCan:
+ ld hl, GymTrashCans3c
+ ld a, [wGymTrashCanIndex]
+ ld c, a
+ ld b, 0
+ ld a, 9
+ call AddNTimes
+ call AddNTimes ; ????
+ ld a, [hli]
+ ld [hGymTrashCanRandNumMask], a
+ ld e, a
+ push hl
+ call TrashCanRandom
+ pop hl
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld [wSecondLockTrashCanIndex], a
+ ld a, [hl]
+ ld [wSecondLockTrashCanIndex + 1], a
+ ret
+
+GymTrashCans3c:
+; First byte: number of trashcan entries
+; Following four byte pairs: indices for the second trash can.
+; BUG: Rows that have 3 trashcan entries are sampled incorrectly.
+; The sampling occurs by taking a random number and seeing which
+; third of the range 0-255 the number falls in. However, it returns
+; that value to the wrong register, so the result is never used.
+; Instead of using an offset in [0,1,2], the offset is instead
+; in the full range 0-255. This results in truly random behavior.
+ db 4
+ db 1,3, 3,1, 1,-1, 3,-1
+ db 3
+ db 0,2, 2,4, 4,0, -1,-1
+ db 4
+ db 1,5, 5,1, 1,-1, 5,-1
+ db 3
+ db 0,4, 4,6, 6,0, -1,-1
+ db 4
+ db 1,3, 3,1, 5,5, 7,7
+ db 3
+ db 2,4, 4,8, 8,2, -1,-1
+ db 3
+ db 3,7, 7,9, 9,3, -1,-1
+ db 4
+ db 4,8, 6,10, 8,4, 10,6
+ db 3
+ db 5,7, 7,11, 11,5, -1,-1
+ db 3
+ db 6,10, 10,12, 12,6, -1,-1
+ db 4
+ db 7,9, 9,7, 11,13, 13,11
+ db 3
+ db 8,10, 10,14, 14,8, -1,-1
+ db 4
+ db 9,13, 13,9, 9,-1, 13,-1
+ db 3
+ db 10,12, 12,14, 14,10, -1,-1
+ db 4
+ db 11,13, 13,11, 11,-1, 13,-1
diff --git a/engine/yellow_intro.asm b/engine/yellow_intro.asm
new file mode 100755
index 00000000..3adb72b5
--- /dev/null
+++ b/engine/yellow_intro.asm
@@ -0,0 +1,1081 @@
+PlayIntroScene:
+ ld a, [rIE]
+ push af
+ xor a
+ ld [rIF], a
+ ld a, $f
+ ld [rIE], a
+ ld a, $8
+ ld [rSTAT], a
+ call InitYellowIntroGFXAndMusic
+ call DelayFrame
+.loop
+ ld a, [wYellowIntroCurrentScene]
+ bit 7, a
+ jr nz, .go_to_title_screen
+ call JoypadLowSensitivity
+ ld a, [hJoyPressed]
+ and A_BUTTON | B_BUTTON | START
+ jr nz, .go_to_title_screen
+ call Func_f98fc
+ ld a, $0
+ ld [wCurrentAnimatedObjectOAMBufferOffset], a
+ call RunObjectAnimations
+ ld a, [wYellowIntroCurrentScene]
+ cp $7
+ call z, Func_f98a2
+ cp $b
+ call z, Func_f98cb
+ call DelayFrame
+ jr .loop
+
+.go_to_title_screen
+ call YellowIntro_BlankPalettes
+ xor a
+ ld [hLCDCPointer], a
+ call DelayFrame
+ xor a
+ ld [rIF], a
+ pop af
+ ld [rIE], a
+ ld a, $90
+ ld [hWY], a
+ call ClearObjectAnimationBuffers
+ ld hl, wTileMap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ xor a
+ call Bank3E_FillMemory
+ call YellowIntro_BlankOAMBuffer
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call DelayFrame
+ call DelayFrame
+ call DelayFrame
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ret
+
+Func_f98a2:
+ ld a, [wOAMBuffer + 8 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 8 * 4 + 3], a
+ ld a, [wOAMBuffer + 14 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 14 * 4 + 3], a
+ ld a, [wOAMBuffer + 16 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 16 * 4 + 3], a
+ ld a, [wOAMBuffer + 18 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 18 * 4 + 3], a
+ ld a, [wOAMBuffer + 19 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 19 * 4 + 3], a
+ ret
+
+Func_f98cb:
+ ld a, [wOAMBuffer + 18 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 18 * 4 + 3], a
+ ld a, [wOAMBuffer + 19 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 19 * 4 + 3], a
+ ld a, [wOAMBuffer + 20 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 20 * 4 + 3], a
+ ld a, [wOAMBuffer + 25 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 25 * 4 + 3], a
+ ld a, [wOAMBuffer + 26 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 26 * 4 + 3], a
+ ld a, [wOAMBuffer + 28 * 4 + 3]
+ or $1
+ ld [wOAMBuffer + 28 * 4 + 3], a
+ ret
+
+Func_f98fc:
+ ld a, [wYellowIntroCurrentScene]
+ ld hl, Jumptable_f9906
+ call Func_fa06e
+ jp [hl]
+
+Jumptable_f9906:
+ dw YellowIntroScene0 ; running pika 1
+ dw YellowIntroScene1 ; wait last
+ dw YellowIntroScene2 ; pikachu kick
+ dw YellowIntroScene3 ; wait last
+ dw YellowIntroScene4 ; running pika 2
+ dw YellowIntroScene5 ; wait last
+ dw YellowIntroScene6 ; surfing pika
+ dw YellowIntroScene7 ; wait last
+ dw YellowIntroScene8 ; running pika 3
+ dw YellowIntroScene9 ; wait last
+ dw YellowIntroScene10 ; flying pika
+ dw YellowIntroScene11 ; wait last
+ dw YellowIntroScene12 ; pika close up
+ dw YellowIntroScene13 ; wait last
+ dw YellowIntroScene14 ; pika thunderbolt
+ dw YellowIntroScene15 ; wait last
+ dw YellowIntroScene16 ; fade to white
+ dw YellowIntroScene17 ; wait and quit
+
+YellowIntro_NextScene:
+ ld hl, wYellowIntroCurrentScene
+ inc [hl]
+ ret
+
+YellowIntroScene0:
+ xor a
+ ld [hLCDCPointer], a
+ lb de, $58, $58
+ ld a, $1
+ call YellowIntro_SpawnAnimatedObjectAndSavePointer
+ xor a
+ ld [hSCX], a
+ ld [hSCY], a
+ ld a, $90
+ ld [hWY], a
+ ld a, $e4
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld a, $c4
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ld a, 130
+ ld [wYellowIntroSceneTimer], a
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene1:
+ call YellowIntro_CheckFrameTimerDecrement
+ ret nc
+ call YellowIntro_MaskCurrentAnimatedObjectStruct
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene2:
+ call YellowIntro_BlankPalsDelay2AndDisableLCD
+ ld c, $8
+ call UpdateMusicCTimes
+ xor a
+ ld [hLCDCPointer], a
+ ld hl, vBGMap0
+ ld bc, $400
+ xor a
+ call Bank3E_FillMemory
+ call YellowIntroScene2_PlaceGraphic
+ lb de, $58, $b8 ; overloaded
+ ld a, $4 ; overloaded
+ call LoadYellowIntroFlyingSpeedBars
+ ld a, $1
+ call Func_f9e9a
+ call YellowIntro_SetTimerFor128Frames
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene2_PlaceGraphic:
+ ld hl, $98d4 ; (20, 6)
+ ld de, $20
+ ld b, $6
+ ld a, $90
+.row
+ ld c, $6
+ push af
+ push hl
+.col
+ ld [hli], a
+ inc a
+ dec c
+ jr nz, .col
+ pop hl
+ add hl, de
+ pop af
+ add $10
+ dec b
+ jr nz, .row
+ ld a, [hGBC]
+ and a
+ jr z, .dmg_sgb
+ ; We can actually set palettes!
+ ld hl, $98d4 ; (20, 6)
+ ld de, $20
+ ld b, $6
+ ld a, $1
+ ld [rVBK], a
+.attr_row
+ ld c, $6
+ push hl
+.attr_col
+ ld [hli], a
+ dec c
+ jr nz, .attr_col
+ pop hl
+ add hl, de
+ dec b
+ jr nz, .attr_row
+ xor a
+ ld [rVBK], a
+.dmg_sgb
+ ret
+
+LoadYellowIntroFlyingSpeedBars:
+ ld hl, YellowIntroFlyingSpeedBarData
+ ld a, $8
+.loop
+; Spawn object $8 at indicated coordinates with indicated speeds
+ push af
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+ ld a, [hli]
+ push hl
+ push af
+ ld a, $8
+ call SpawnAnimatedObject
+ pop af
+ ld hl, $b
+ add hl, bc
+ ld [hl], a
+ pop hl
+ pop af
+ dec a
+ jr nz, .loop
+ ret
+
+YellowIntroFlyingSpeedBarData:
+ ; y, x, speed
+ db $d0, $20, $02
+ db $f0, $30, $04
+ db $d0, $40, $06
+ db $c0, $50, $08
+ db $e0, $60, $08
+ db $c0, $70, $06
+ db $e0, $80, $04
+ db $f0, $90, $02
+
+YellowIntroScene3:
+ call YellowIntro_CheckFrameTimerDecrement
+ jr c, .expired
+ ld a, [hSCX]
+ cp $68
+ ret z
+ add $4
+ ld [hSCX], a
+ ret
+
+.expired
+ call MaskAllAnimatedObjectStructs
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene4:
+ call YellowIntro_BlankPalsDelay2AndDisableLCD
+ ld c, $5
+ call UpdateMusicCTimes
+ ld a, [hGBC]
+ and a
+ jr z, .dmg_sgb
+ ; We can actually set palettes!
+ ld hl, $98d4
+ ld de, $20
+ ld b, $6
+ ld a, $1
+ ld [rVBK], a
+ xor a
+.attr_row
+ ld c, $6
+ push hl
+.attr_col
+ ld [hli], a
+ dec c
+ jr nz, .attr_col
+ pop hl
+ add hl, de
+ dec b
+ jr nz, .attr_row
+ xor a
+ ld [rVBK], a
+.dmg_sgb
+ xor a
+ ld [hLCDCPointer], a
+ call Func_f9e5f
+ lb de, $58, $58
+ ld a, $2
+ call YellowIntro_SpawnAnimatedObjectAndSavePointer
+ xor a
+ call Func_f9e9a
+ call YellowIntro_SetTimerFor128Frames
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene5:
+ call YellowIntro_CheckFrameTimerDecrement
+ ret nc
+ call YellowIntro_MaskCurrentAnimatedObjectStruct
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene6:
+ call YellowIntro_BlankPalsDelay2AndDisableLCD
+ ld c, $5
+ call UpdateMusicCTimes
+ ld a, rSCY - $ff00
+ ld [hLCDCPointer], a
+ call YellowIntro_Copy8BitSineWave
+ ld hl, vBGMap0
+ ld bc, $60
+ xor a
+ call Bank3E_FillMemory
+ ld hl, $9860
+ ld c, $10
+ ld a, $20
+.asm_f9a8b
+ ld [hli], a
+ inc a
+ ld [hli], a
+ dec a
+ dec c
+ jr nz, .asm_f9a8b
+ ld hl, $9880
+ ld bc, $300
+ ld a, $10
+ call Bank3E_FillMemory
+ lb de, $40, $f8
+ ld a, $5
+ call YellowIntro_SpawnAnimatedObjectAndSavePointer
+ ld a, $1
+ call Func_f9e9a
+ call YellowIntro_SetTimerFor88Frames
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene7:
+ call YellowIntro_CheckFrameTimerDecrement
+ jr c, .expired
+ ld hl, hSCX
+ inc [hl]
+ inc [hl]
+ ld hl, wLYOverridesBuffer
+ ld de, wLYOverridesBuffer + 1
+ ld a, [hl]
+ push af
+ ld c, $ff
+.shift_loop
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .shift_loop
+ pop af
+ ld [hl], a
+ call Request7TileTransferFromC810ToC710
+ ret
+
+.expired
+ call YellowIntro_MaskCurrentAnimatedObjectStruct
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene8:
+ call YellowIntro_BlankPalsDelay2AndDisableLCD
+ ld c, $5
+ call UpdateMusicCTimes
+ xor a
+ ld [hLCDCPointer], a
+ call Func_f9e5f
+ lb de, $58, $58
+ ld a, $3
+ call YellowIntro_SpawnAnimatedObjectAndSavePointer
+ xor a
+ call Func_f9e9a
+ call YellowIntro_SetTimerFor128Frames
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene9:
+ call YellowIntro_CheckFrameTimerDecrement
+ ret nc
+ call YellowIntro_MaskCurrentAnimatedObjectStruct
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene10:
+ call YellowIntro_BlankPalsDelay2AndDisableLCD
+ ld c, $5
+ call UpdateMusicCTimes
+ xor a
+ ld [hLCDCPointer], a
+ ld hl, vBGMap0
+ ld bc, $400
+ xor a
+ call Bank3E_FillMemory
+ ld hl, vBGMap0
+ ld bc, $100
+ ld a, $2
+ call Bank3E_FillMemory
+ ld hl, $9900
+ ld de, Unkn_f9b6e
+ lb bc, 6, 20
+ call .FillBGMapBox
+ ld hl, $988c
+ ld de, Unkn_f9be6
+ lb bc, 3, 4
+ call .FillBGMapBox
+ ld hl, $98e3
+ ld de, Unkn_f9bf2
+ lb bc, 2, 2
+ call .FillBGMapBox
+ lb de, $98, $58
+ ld a, $6
+ call YellowIntro_SpawnAnimatedObjectAndSavePointer
+ ld a, $1
+ call Func_f9e9a
+ call YellowIntro_SetTimerFor128Frames
+ call YellowIntro_NextScene
+ ret
+
+.FillBGMapBox:
+.fill_row
+ push bc
+ push hl
+.fill_col
+ ld a, [de]
+ inc de
+ ld [hli], a
+ dec c
+ jr nz, .fill_col
+ pop hl
+ ld bc, $20
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .fill_row
+ ret
+
+Unkn_f9b6e: INCBIN "gfx/unknown_f9b6e.map"
+Unkn_f9be6: INCBIN "gfx/unknown_f9be6.map"
+Unkn_f9bf2: INCBIN "gfx/unknown_f9bf2.map"
+
+YellowIntroScene11:
+ call YellowIntro_CheckFrameTimerDecrement
+ jr c, .expired
+ ld a, [wYellowIntroSceneTimer]
+ and $7
+ ret nz
+ ld a, [wYellowIntroSceneTimer]
+ and $8
+ sla a
+ sla a
+ sla a
+ ld e, a
+ ld d, $0
+ ld hl, YellowIntroCloudGFX1
+ add hl, de
+ ld a, l
+ ld [H_VBCOPYSRC], a
+ ld a, h
+ ld [H_VBCOPYSRC + 1], a
+ xor a
+ ld [H_VBCOPYDEST], a
+ ld a, $96
+ ld [H_VBCOPYDEST + 1], a
+ ld a, $4
+ ld [H_VBCOPYSIZE], a
+ ret
+
+.expired
+ call YellowIntro_MaskCurrentAnimatedObjectStruct
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroCloudGFX1: INCBIN "gfx/unknown_f9c2c.2bpp"
+YellowIntroCloudGFX2: INCBIN "gfx/unknown_f9c6c.2bpp" ; indirectly referenced
+
+YellowIntroScene12:
+ call YellowIntro_BlankPalsDelay2AndDisableLCD
+ ld c, $5
+ call UpdateMusicCTimes
+ xor a
+ ld [hLCDCPointer], a
+ ld hl, vBGMap0
+ ld bc, $80
+ ld a, $1
+ call Bank3E_FillMemory
+ ld hl, $9880
+ ld bc, $140
+ xor a
+ call Bank3E_FillMemory
+ ld hl, $99c0
+ ld bc, $80
+ ld a, $1
+ call Bank3E_FillMemory
+
+ ; paste 8x12 graphic into vBGMap0 at (5, 6) starting at tile 4, skipping 4 vtiles at the end of each row
+ ld hl, $98c5
+ ld de, $20
+ ld a, $4
+ ld b, 8
+.row
+ ld c, 12
+ push hl
+.col
+ ld [hli], a
+ inc a
+ dec c
+ jr nz, .col
+ pop hl
+ add hl, de
+ add $4
+ dec b
+ jr nz, .row
+
+ ld hl, $98c4 ; (4, 6)
+ ld [hl], $3
+ ld hl, $98e4 ; (4, 7)
+ ld [hl], $74
+ ld hl, $99a5 ; (5, 5)
+ ld [hl], $0
+ lb de, $60, $58
+ ld a, $9
+ call YellowIntro_SpawnAnimatedObjectAndSavePointer
+ xor a
+ call Func_f9e9a
+ call YellowIntro_SetTimerFor128Frames
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene13:
+ call YellowIntro_CheckFrameTimerDecrement
+ ret nc
+ lb de, $68, $58
+ ld a, $a
+ call SpawnAnimatedObject
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroScene14:
+ ld de, YellowIntroPalSequence_f9dd6
+ call YellowIntro_LoadDMGPalAndIncrementCounter
+ jr c, .expired
+ ld [rBGP], a
+ ld [rOBP0], a
+ and $f0
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ret
+
+.expired
+ call MaskAllAnimatedObjectStructs
+ call YellowIntro_BlankOAMBuffer
+ ld hl, wTileMap
+ ld bc, $50
+ ld a, $1
+ call Bank3E_FillMemory
+ coord hl, 0, 4
+ ld bc, CopyVideoDataAlternate
+ xor a
+ call Bank3E_FillMemory
+ coord hl, 0, 14
+ ld bc, $50
+ ld a, $1
+ call Bank3E_FillMemory
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call DelayFrame
+ call DelayFrame
+ call DelayFrame
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld a, $e4
+ ld [rOBP0], a
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ lb de, $58, $58
+ ld a, $7
+ call YellowIntro_SpawnAnimatedObjectAndSavePointer
+ call YellowIntro_NextScene
+ ld a, $28
+ ld [wYellowIntroSceneTimer], a
+ ret
+
+YellowIntroScene15:
+ call YellowIntro_CheckFrameTimerDecrement
+ jr c, .expired
+ ld a, [wYellowIntroSceneTimer]
+ and $3
+ ret nz
+ ld a, [rOBP0]
+ xor $ff
+ ld [rOBP0], a
+ ld a, [rBGP]
+ xor $3
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ ret
+
+.expired
+ xor a
+ ld [hLCDCPointer], a
+ ld a, $e4
+ ld [rBGP], a
+ ld [rOBP0], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call YellowIntro_NextScene
+YellowIntroScene16:
+ ld de, YellowIntroPalSequence_f9e0a
+ call YellowIntro_LoadDMGPalAndIncrementCounter
+ jr c, .expired
+ ld [rOBP0], a
+ ld [rBGP], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ ret
+
+.expired
+ call YellowIntro_NextScene
+ ret
+
+YellowIntroPalSequence_f9dd6:
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $e4
+ db $e4, $c0, $c0, $ff
+
+YellowIntroPalSequence_f9e0a:
+ db $e4, $90, $90, $40
+ db $40, $00, $00, $ff
+
+YellowIntroScene17:
+ ld c, 64
+ call DelayFrames
+ ld hl, wYellowIntroCurrentScene
+ set 7, [hl]
+ ret
+
+YellowIntro_SpawnAnimatedObjectAndSavePointer:
+ call SpawnAnimatedObject
+ ld a, c
+ ld [wYellowIntroAnimatedObjectStructPointer], a
+ ld a, b
+ ld [wYellowIntroAnimatedObjectStructPointer + 1], a
+ ret
+
+YellowIntro_MaskCurrentAnimatedObjectStruct:
+ ld a, [wYellowIntroAnimatedObjectStructPointer]
+ ld c, a
+ ld a, [wYellowIntroAnimatedObjectStructPointer + 1]
+ ld b, a
+ call MaskCurrentAnimatedObjectStruct
+ ret
+
+YellowIntro_SetTimerFor128Frames:
+ ld a, 128
+ ld [wYellowIntroSceneTimer], a
+ ret
+
+YellowIntro_SetTimerFor88Frames:
+ ld a, 88
+ ld [wYellowIntroSceneTimer], a
+ ret
+
+YellowIntro_CheckFrameTimerDecrement:
+ ld hl, wYellowIntroSceneTimer
+ ld a, [hl]
+ and a
+ jr z, .asm_f9e4b
+ dec [hl]
+ and a
+ ret
+
+.asm_f9e4b
+ scf
+ ret
+
+YellowIntro_LoadDMGPalAndIncrementCounter:
+ ld hl, wYellowIntroSceneTimer
+ ld a, [hl]
+ inc [hl]
+ ld l, a
+ ld h, $0
+ add hl, de
+ ld a, [hl]
+ cp $ff
+ jr z, .asm_f9e5d
+ and a
+ ret
+
+.asm_f9e5d
+ scf
+ ret
+
+Func_f9e5f:
+ ld hl, vBGMap0
+ ld bc, $80
+ ld a, $1
+ call Bank3E_FillMemory
+ ld hl, $9880
+ ld bc, $140
+ xor a
+ call Bank3E_FillMemory
+ ld hl, $99c0
+ ld bc, $80
+ ld a, $1
+ call Bank3E_FillMemory
+ ret
+
+YellowIntro_BlankPalsDelay2AndDisableLCD:
+ xor a
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ call DelayFrame
+ call DelayFrame
+ call DisableLCD
+ ret
+
+Func_f9e9a:
+ ld e, a
+ callab YellowIntroPaletteAction
+ xor a
+ ld [hSCX], a
+ ld [hSCY], a
+ ld a, $90
+ ld [hWY], a
+ ld a, $e3
+ ld [rLCDC], a
+ ld a, $e4
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld a, $e0
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ret
+
+YellowIntro_Copy8BitSineWave:
+ ; Copy this sine wave into wLYOverridesBuffer 8 times (end just before wc900)
+ ld de, wLYOverridesBuffer
+ ld a, $8
+.loop
+ push af
+ ld hl, .SineWave
+ ld bc, .SineWaveEnd - .SineWave
+ call Bank3E_CopyData
+ pop af
+ dec a
+ jr nz, .loop
+ ret
+
+.SineWave:
+; a sine wave with amplitude 4
+ db 0, 0, 1, 2, 2, 3, 3, 3
+ db 4, 3, 3, 3, 2, 2, 1, 0
+ db 0, 0, -1, -2, -2, -3, -3, -3
+ db -4, -3, -3, -3, -2, -2, -1, 0
+.SineWaveEnd:
+
+Request7TileTransferFromC810ToC710:
+ ld a, $10
+ ld [H_VBCOPYSRC], a
+ ld a, wLYOverridesBuffer / $100
+ ld [H_VBCOPYSRC + 1], a
+ ld a, $10
+ ld [H_VBCOPYDEST], a
+ ld a, wLYOverrides / $100
+ ld [H_VBCOPYDEST + 1], a
+ ld a, $7
+ ld [H_VBCOPYSIZE], a
+ ret
+
+InitYellowIntroGFXAndMusic:
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld [hSCX], a
+ ld [hSCY], a
+ ld [H_AUTOBGTRANSFERDEST], a
+ ld a, $98
+ ld [H_AUTOBGTRANSFERDEST + 1], a
+ call YellowIntro_BlankTileMap
+ ld hl, wTileMap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ ld a, $1
+ call Bank3E_FillMemory
+ coord hl, 0, 4
+ ld bc, CopyVideoDataAlternate
+ xor a
+ call Bank3E_FillMemory
+ ld a, $1
+ ld [H_AUTOBGTRANSFERENABLED], a
+ call DelayFrame
+ call DelayFrame
+ call DelayFrame
+ xor a
+ ld [H_AUTOBGTRANSFERENABLED], a
+ ld de, $6b5a
+ ld hl, $8000
+ ld bc, $3eff
+ call CopyVideoData
+ ld de, $635a
+ ld hl, $9000
+ ld bc, $3e80
+ call CopyVideoData
+ call ClearObjectAnimationBuffers
+ call LoadYellowIntroObjectAnimationDataPointers
+ ld b, $8
+ call RunPaletteCommand
+ xor a
+ ld hl, wYellowIntroCurrentScene
+ ld [hli], a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ld a, MUSIC_INTRO_BATTLE
+ ld c, BANK(Music_IntroBattle)
+ call PlayMusic
+ ret
+
+LoadYellowIntroObjectAnimationDataPointers:
+ ld a, YellowIntro_AnimatedObjectSpawnStateData % $100
+ ld [wAnimatedObjectSpawnStateDataPointer], a
+ ld a, YellowIntro_AnimatedObjectSpawnStateData / $100
+ ld [wAnimatedObjectSpawnStateDataPointer + 1], a
+ ld a, YellowIntro_AnimatedObjectJumptable % $100
+ ld [wAnimatedObjectJumptablePointer], a
+ ld a, YellowIntro_AnimatedObjectJumptable / $100
+ ld [wAnimatedObjectJumptablePointer + 1], a
+ ld a, YellowIntro_AnimatedObjectOAMData % $100
+ ld [wAnimatedObjectOAMDataPointer], a
+ ld a, YellowIntro_AnimatedObjectOAMData / $100
+ ld [wAnimatedObjectOAMDataPointer + 1], a
+ ld a, YellowIntro_AnimatedObjectFramesData % $100
+ ld [wAnimatedObjectFramesDataPointer], a
+ ld a, YellowIntro_AnimatedObjectFramesData / $100
+ ld [wAnimatedObjectFramesDataPointer + 1], a
+ ret
+
+YellowIntro_BlankTileMap:
+ ld hl, wTileMap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ ld a, $7f
+ call Bank3E_FillMemory
+ ret
+
+Bank3E_CopyData:
+.loop
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ ret
+
+Bank3E_FillMemory:
+ push de
+ ld e, a
+.loop
+ ld a, e
+ ld [hli], a
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ pop de
+ ret
+
+YellowIntro_BlankOAMBuffer:
+ ld hl, wOAMBuffer
+ ld bc, wOAMBufferEnd - wOAMBuffer
+ xor a
+ call Bank3E_FillMemory
+ ret
+
+YellowIntro_BlankPalettes:
+ xor a
+ ld [rBGP], a
+ ld [rOBP0], a
+ ld [rOBP1], a
+ call UpdateGBCPal_BGP
+ call UpdateGBCPal_OBP0
+ call UpdateGBCPal_OBP1
+ ret
+
+YellowIntro_AnimatedObjectSpawnStateData:
+ db $00, $00, $00
+ db $01, $01, $00
+ db $02, $01, $00
+ db $03, $01, $00
+ db $04, $02, $00
+ db $05, $03, $00
+ db $06, $04, $00
+ db $07, $01, $00
+ db $08, $05, $00
+ db $09, $01, $00
+ db $0a, $01, $00
+
+YellowIntro_AnimatedObjectJumptable:
+ dw Func_fa007
+ dw Func_fa007
+ dw Func_fa008
+ dw Func_fa014
+ dw Func_fa02b
+ dw Func_fa062
+
+Func_fa007:
+ ret
+
+Func_fa008:
+ ld hl, $4
+ add hl, bc
+ ld a, [hl]
+ cp $58
+ ret z
+ sub $4
+ ld [hl], a
+ ret
+
+Func_fa014:
+ ld hl, $4
+ add hl, bc
+ ld a, [hl]
+ cp $58
+ jr z, .asm_fa020
+ add $4
+ ld [hl], a
+.asm_fa020
+ ld hl, $5
+ add hl, bc
+ cp $58
+ ret z
+ add $1
+ ld [hl], a
+ ret
+
+Func_fa02b:
+ ld hl, $b
+ add hl, bc
+ ld e, [hl]
+ ld d, $0
+ ld hl, Jumptable_fa03b
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+
+Jumptable_fa03b:
+ dw Func_fa03f
+ dw Func_fa051
+
+Func_fa03f:
+ ld hl, $5
+ add hl, bc
+ ld a, [hl]
+ cp $58
+ jr z, .asm_fa04c
+ sub $2
+ ld [hl], a
+ ret
+
+.asm_fa04c
+ ld hl, $b
+ add hl, bc
+ inc [hl]
+Func_fa051:
+ ld hl, $c
+ add hl, bc
+ ld a, [hl]
+ inc [hl]
+ ld d, $8
+ call Func_fa079
+ ld hl, $7
+ add hl, bc
+ ld [hl], a
+ ret
+
+Func_fa062:
+ ld hl, $b
+ add hl, bc
+ ld a, [hl]
+ ld hl, $4
+ add hl, bc
+ add [hl]
+ ld [hl], a
+ ret
+
+Func_fa06e:
+ ld e, a
+ ld d, $0
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ret
+
+Func_fa077: ; cosine
+ add $10
+Func_fa079:
+ and $3f
+ cp $20
+ jr nc, .asm_fa084
+ call Func_fa08e
+ ld a, h
+ ret
+
+.asm_fa084
+ and $1f
+ call Func_fa08e
+ ld a, h
+ xor $ff
+ inc a
+ ret
+
+Func_fa08e:
+ ld e, a
+ ld a, d
+ ld d, $0
+ ld hl, Unkn_fa0aa
+ add hl, de
+ add hl, de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ ld hl, $0
+.asm_fa09d
+ srl a
+ jr nc, .asm_fa0a2
+ add hl, de
+.asm_fa0a2
+ sla e
+ rl d
+ and a
+ jr nz, .asm_fa09d
+ ret
+
+Unkn_fa0aa:
+ sine_wave $100