summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--constants/pikachu_emotion_constants.asm4
-rwxr-xr-xconstants/sprite_constants.asm2
-rw-r--r--engine/bank3c.asm200
-rw-r--r--engine/bank3f.asm563
-rwxr-xr-xengine/hidden_object_functions14.asm2
-rwxr-xr-xengine/hidden_object_functions17.asm2
-rwxr-xr-xengine/hidden_object_functions18.asm6
-rwxr-xr-xengine/hidden_object_functions3.asm2
-rwxr-xr-xengine/hidden_object_functions7.asm6
-rwxr-xr-xengine/items/items.asm2437
-rw-r--r--engine/menu/bills_pc.asm6
-rwxr-xr-xengine/overworld/card_key.asm2
-rw-r--r--engine/overworld/check_player_state.asm4
-rwxr-xr-xengine/overworld/cut.asm2
-rw-r--r--engine/overworld/get_coords_tile_in_front_of_player.asm4
-rwxr-xr-xengine/overworld/hidden_objects.asm2
-rwxr-xr-xengine/overworld/ledges.asm2
-rw-r--r--engine/overworld/map_sprite_functions1.asm2
-rwxr-xr-xengine/overworld/map_sprites.asm124
-rw-r--r--engine/overworld/movement.asm4
-rwxr-xr-xengine/overworld/player_animations.asm6
-rwxr-xr-xengine/overworld/pokecenter.asm2
-rwxr-xr-xengine/overworld/ssanne.asm2
-rw-r--r--engine/overworld/step_functions.asm2
-rw-r--r--engine/overworld/try_pushing_boulder.asm2
-rwxr-xr-xengine/pikachu_emotions.asm674
-rwxr-xr-xengine/pikachu_movement.asm1039
-rwxr-xr-xengine/pikachu_pcm.asm154
-rwxr-xr-xengine/pikachu_pic_animation.asm1713
-rwxr-xr-xengine/surfing_minigame.asm2
-rw-r--r--home/overworld.asm66
-rwxr-xr-xhome/pikachu.asm29
-rwxr-xr-xmain.asm4
-rw-r--r--scripts/beach_house.asm8
-rwxr-xr-xscripts/billshouse.asm14
-rwxr-xr-xscripts/billshouse2.asm6
-rwxr-xr-xscripts/cinnabargym.asm2
-rwxr-xr-xscripts/cinnabarisland.asm2
-rwxr-xr-xscripts/copycatshouse2f.asm2
-rwxr-xr-xscripts/daycarem.asm2
-rwxr-xr-xscripts/fanclub.asm10
-rwxr-xr-xscripts/mansion1.asm2
-rwxr-xr-xscripts/mansion2.asm2
-rwxr-xr-xscripts/mansion3.asm2
-rwxr-xr-xscripts/mansion4.asm2
-rwxr-xr-xscripts/oakslab.asm6
-rwxr-xr-xscripts/oakslab2.asm4
-rwxr-xr-xscripts/pallettown.asm2
-rwxr-xr-xscripts/pewtercity.asm2
-rwxr-xr-xscripts/pewterpokecenter.asm2
-rwxr-xr-xscripts/pokemontower7.asm2
-rwxr-xr-xscripts/redshouse1f2.asm2
-rwxr-xr-xscripts/route11gateupstairs.asm2
-rwxr-xr-xscripts/route12gateupstairs.asm2
-rwxr-xr-xscripts/route22.asm2
-rwxr-xr-xscripts/route22gate.asm2
-rwxr-xr-xscripts/route23.asm2
-rwxr-xr-xscripts/route25.asm2
-rwxr-xr-xscripts/safarizoneentrance.asm6
-rwxr-xr-xscripts/vermilioncity.asm6
-rwxr-xr-xscripts/viridiancity.asm6
-rwxr-xr-xscripts/viridiancity2.asm2
-rwxr-xr-xwram.asm84
63 files changed, 3743 insertions, 3518 deletions
diff --git a/constants/pikachu_emotion_constants.asm b/constants/pikachu_emotion_constants.asm
index 22c1d8ea..ff56082a 100644
--- a/constants/pikachu_emotion_constants.asm
+++ b/constants/pikachu_emotion_constants.asm
@@ -47,12 +47,12 @@ pikaemotion_emotebubble: MACRO
db \1
ENDM
-pikaemotion_4: MACRO
+pikaemotion_movement: MACRO
db PIKAEMOTION_4
dw \1
ENDM
-pikaemotion_5: MACRO
+pikaemotion_pikapic: MACRO
db PIKAEMOTION_5
db \1
ENDM
diff --git a/constants/sprite_constants.asm b/constants/sprite_constants.asm
index ae0c9dfa..3349e374 100755
--- a/constants/sprite_constants.asm
+++ b/constants/sprite_constants.asm
@@ -85,6 +85,8 @@ const_value = 1
const SPRITE_CHANSEY ; $44
const SPRITE_JESSIE ; $45
const SPRITE_JAMES ; $46
+
+ ; 4-tile sprites
const SPRITE_BALL ; $47
const SPRITE_OMANYTE ; $48
const SPRITE_BOULDER ; $49
diff --git a/engine/bank3c.asm b/engine/bank3c.asm
index 4fa185e0..0028d1fc 100644
--- a/engine/bank3c.asm
+++ b/engine/bank3c.asm
@@ -1,158 +1,4 @@
-PlayPikachuSoundClip:: ; f0000 (3c:4000)
- 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: ; f008e (3c:408e)
-; 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
-
+INCLUDE "engine/pikachu_pcm.asm"
INCLUDE "engine/overworld/advance_player_sprite.asm"
ResetStatusAndHalveMoneyOnBlackout:: ; f0274 (3c:4274)
@@ -169,30 +15,30 @@ ResetStatusAndHalveMoneyOnBlackout:: ; f0274 (3c:4274)
ld [wNPCMovementScriptPointerTableNum], a
ld [wFlags_0xcd60], a
- ld [$ff9f], a
- ld [$ff9f + 1], a
- ld [$ff9f + 2], 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 [$ff9f], a
+ ld [hMoney], a
ld a, [wPlayerMoney + 1]
- ld [$ff9f + 1], a
+ ld [hMoney + 1], a
ld a, [wPlayerMoney + 2]
- ld [$ff9f + 2], a
+ ld [hMoney + 2], a
xor a
- ld [$ffa2], a
- ld [$ffa3], a
+ ld [hDivideBCDDivisor], a
+ ld [hDivideBCDDivisor + 1], a
ld a, 2
- ld [$ffa4], a
+ ld [hDivideBCDDivisor + 2], a
predef DivideBCDPredef3
- ld a, [$ffa2]
+ ld a, [hDivideBCDQuotient]
ld [wPlayerMoney], a
- ld a, [$ffa2 + 1]
+ ld a, [hDivideBCDQuotient + 1]
ld [wPlayerMoney + 1], a
- ld a, [$ffa2 + 2]
+ ld a, [hDivideBCDQuotient + 2]
ld [wPlayerMoney + 2], a
.lostmoney
@@ -217,10 +63,12 @@ Func_f02da:: ; f02da (3c:42da)
cp a, $ff
jr nz, .asm_f02e5
ret
+
.asm_f02ee
ld hl, wd126
set 6, [hl]
ret
+
.asm_f02f4
ld hl, wd126
set 5, [hl]
@@ -301,7 +149,7 @@ Pointer_f0a7b:
db $ff
Pointer_f0a7bEnd:
-Func_f0a82: ; f0a82
+TryApplyPikachuMovementData: ; f0a82
ld a, [wd472]
bit 7, a
ret z
@@ -325,8 +173,8 @@ Func_f0a82: ; f0a82
pop af
ld [wUpdateSpritesEnabled], a
pop hl
- call Func_159b ; homecall Func_fd2a1 - pikachu movement script?
- callab Func_fcba1
+ call ApplyPikachuMovementData
+ callab RefreshPikachuFollow
ret
Pic_f0abf: ; f0abf (3c:4abf)
@@ -365,7 +213,7 @@ INCLUDE "scripts/pewterpokecenter2.asm"
Func_f1e22:
ld hl, PikachuMovementData_f1e2b
ld b, SPRITE_FACING_RIGHT
- call Func_f0a82
+ call TryApplyPikachuMovementData
ret
PikachuMovementData_f1e2b:
@@ -382,7 +230,7 @@ INCLUDE "scripts/celadonmansion3_2.asm"
Func_f1f23:
ld hl, PikachuMovementData_f1f2c
ld b, SPRITE_FACING_DOWN
- call Func_f0a82
+ call TryApplyPikachuMovementData
ret
PikachuMovementData_f1f2c:
@@ -444,10 +292,10 @@ Func_f2cee:
Func_f2cf4: ; should return to a, instead returns to b
call Random
swap a
- cp $55
+ cp 1 * $ff / 3
ld b, 0
ret c
- cp $aa
+ cp 2 * $ff / 3
ld b, 1
ret c
ld b, 2
@@ -459,7 +307,7 @@ Func_f2d06:
ret
Func_f2d0c:
- ld hl, GymTrashCans3a
+ ld hl, GymTrashCans3c
ld a, [wGymTrashCanIndex]
ld c, a
ld b, 0
@@ -480,7 +328,7 @@ Func_f2d0c:
ld [wSecondLockTrashCanIndex + 1], a
ret
-GymTrashCans3a: ; f2d31 (3c:6d31)
+GymTrashCans3c: ; f2d31 (3c:6d31)
; 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.
diff --git a/engine/bank3f.asm b/engine/bank3f.asm
index 85674ec4..37aca92f 100644
--- a/engine/bank3f.asm
+++ b/engine/bank3f.asm
@@ -26,123 +26,122 @@ Func_fc4fa:: ; fc4fa (3f:44fa)
ld hl, wPikachuOverworldStateFlags
bit 4, [hl]
res 4, [hl]
- jr nz, .asm_fc515
+ jr nz, .normal_spawn_state
call EnablePikachuFollowingPlayer
- call Func_fc523
+ call ClearPikachuSpriteStateData
ld a, $ff
- ld [wSpriteStateData1 + $f2], a
+ ld [wPikachuSpriteImageIdx], a
call ClearPikachuFollowCommandBuffer
- call Func_fc5bc
+ call CalculatePikachuFacingDirection
ret
-.asm_fc515
- call Func_fc53f
+.normal_spawn_state
+ call CalculatePikachuPlacementCoords
xor a
- ld [wd431], a
- ld a, [wSpriteStateData1 + $9]
- ld [wSpriteStateData1 + $f9], a
+ ld [wPikachuSpawnState], a
+ ld a, [wPlayerFacingDirection]
+ ld [wPikachuFacingDirection], a
ret
-Func_fc523:: ; fc523 (3f:4523)
- ld hl, wSpriteStateData1 + $f0
- call Func_fc52c
- ld hl, wSpriteStateData2 + $f0
-Func_fc52c:: ; fc52c (3f:4523)
+ClearPikachuSpriteStateData:: ; fc523 (3f:4523)
+ ld hl, wPikachuPictureID
+ call .clear
+ ld hl, wPikachuSpriteStateData2
+.clear
ld bc, $10
xor a
call FillMemory
ret
Func_fc534:: ; fc534 (3f:4534)
- call Func_fc53f
- call Func_fc5bc
+ call CalculatePikachuPlacementCoords
+ call CalculatePikachuFacingDirection
xor a
- ld [wd431], a
+ ld [wPikachuSpawnState], a
ret
-Func_fc53f:: ; fc53f (3f:453f)
- ld bc, wSpriteStateData1 + $f0
+CalculatePikachuPlacementCoords:: ; fc53f (3f:453f)
+ ld bc, wPikachuPictureID
ld a, [wYCoord]
add $4
ld e, a
ld a, [wXCoord]
add $4
ld d, a
- ld a, [wd431]
+ ld a, [wPikachuSpawnState]
and a
- jr z, .asm_fc5aa
+ jr z, .load_coords
cp $1
- jr z, .asm_fc59e
+ jr z, .right_of_player
cp $2
- jr z, .asm_fc584
+ jr z, .check_player_facing2
cp $3
- jr z, .asm_fc5aa
+ jr z, .load_coords
cp $4
- jr z, .asm_fc5a4
+ jr z, .below_player
cp $5
- jr z, .asm_fc5a7
+ jr z, .above_player
cp $6
- jr z, .asm_fc5a1
+ jr z, .left_of_player
cp $7
- jr z, .asm_fc572
- jr .asm_fc59e
+ jr z, .check_player_facing
+ jr .right_of_player
-.asm_fc572
- ld a, [wSpriteStateData1 + $9]
+.check_player_facing
+ ld a, [wPlayerFacingDirection]
and a ; SPRITE_FACING_DOWN
- jr z, .asm_fc5a4
+ jr z, .below_player
cp SPRITE_FACING_UP
- jr z, .asm_fc5a7
+ jr z, .above_player
cp SPRITE_FACING_LEFT
- jr z, .asm_fc5a1
+ jr z, .left_of_player
cp SPRITE_FACING_RIGHT
- jr z, .asm_fc59e
-.asm_fc584
- ld a, [wSpriteStateData1 + $9]
+ jr z, .right_of_player
+.check_player_facing2
+ ld a, [wPlayerFacingDirection]
and a
- jr nz, .asm_fc58d
+ jr nz, .check_up
dec e
- jr .asm_fc5aa
+ jr .load_coords
-.asm_fc58d
+.check_up
cp SPRITE_FACING_UP
- jr nz, .asm_fc594
+ jr nz, .check_left
inc e
- jr .asm_fc5aa
+ jr .load_coords
-.asm_fc594
+.check_left
cp SPRITE_FACING_LEFT
- jr nz, .asm_fc59b
+ jr nz, .left_of_player_2
inc d
- jr .asm_fc5aa
+ jr .load_coords
-.asm_fc59b
+.left_of_player_2
dec d
- jr .asm_fc5aa
+ jr .load_coords
-.asm_fc59e
+.right_of_player
inc d
- jr .asm_fc5aa
+ jr .load_coords
-.asm_fc5a1
+.left_of_player
dec d
- jr .asm_fc5aa
+ jr .load_coords
-.asm_fc5a4
+.below_player
inc e
- jr .asm_fc5aa
+ jr .load_coords
-.asm_fc5a7
+.above_player
dec e
- jr .asm_fc5aa ; useless jr
-.asm_fc5aa
- ld hl, $104
+ jr .load_coords ; useless jr
+.load_coords
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
add hl, bc
ld [hl], e
inc hl
ld [hl], d
inc hl
-Func_fc4b2:: ; fc4b2 (3f:44b2)
ld [hl], $fe
push hl
ld hl, wd472
@@ -150,139 +149,164 @@ Func_fc4b2:: ; fc4b2 (3f:44b2)
pop hl
ret
-Func_fc5bc:: ; fc5bc (3f:45bc)
+CalculatePikachuFacingDirection:: ; fc5bc (3f:45bc)
ld a, $49
- ld [wSpriteStateData1 + $f0], a
+ ld [wPikachuPictureID], a
ld a, $ff
- ld [wSpriteStateData1 + $f2], a
- ld a, [wd431]
+ ld [wPikachuSpriteImageIdx], a
+ ld a, [wPikachuSpawnState]
and a
- jr z, .asm_fc5e4
+ jr z, .copy_player_facing
cp $1
- jr z, .asm_fc5e4
+ jr z, .copy_player_facing
cp $3
- jr z, .asm_fc5eb
+ jr z, .force_facing_down
cp $4
- jr z, .asm_fc5e4
+ jr z, .copy_player_facing
cp $6
- jr z, .asm_fc5e4
+ jr z, .copy_player_facing
cp $7
- jr z, .asm_fc5f1
+ jr z, .face_the_other_way
call Func_fccb2
ret
-.asm_fc5e4
- ld a, [wSpriteStateData1 + $9]
- ld [wSpriteStateData1 + $f9], a
+.copy_player_facing
+ ld a, [wPlayerFacingDirection]
+ ld [wPikachuFacingDirection], a
ret
-.asm_fc5eb
- ld a, $0
- ld [wSpriteStateData1 + $f9], a
+.force_facing_down
+ ld a, SPRITE_FACING_DOWN
+ ld [wPikachuFacingDirection], a
ret
-.asm_fc5f1
- ld a, [wSpriteStateData1 + $9]
+.face_the_other_way
+ ld a, [wPlayerFacingDirection]
xor $4
- ld [wSpriteStateData1 + $f9], a
+ ld [wPikachuFacingDirection], a
ret
-Func_fc5fa:: ; fc5fa (3f:45fa)
+CalculatePikachuSpawnState1:: ; fc5fa (3f:45fa)
ld a, [wCurMap]
cp OAKS_LAB
- jr z, .asm_fc63d
+ jr z, .oaks_lab
cp ROUTE_22_GATE
- jr z, .asm_fc62d
+ jr z, .route_22_gate
cp MT_MOON_2
- jr z, .asm_fc635
+ jr z, .mt_moon_2
cp ROCK_TUNNEL_1
- jr z, .asm_fc645
+ jr z, .rock_tunnel_1
ld a, [wCurMap]
ld hl, Pointer_fc64b
- call Func_1568 ; similar to IsInArray, but not the same
- jr c, .asm_fc639
+ call Pikachu_IsInArray ; similar to IsInArray, but not the same
+ jr c, .map_list_1
ld a, [wCurMap]
ld hl, Pointer_fc653
- call Func_1568
- jr nc, .asm_fc641
- ld a, [wSpriteStateData1 + $9]
+ call Pikachu_IsInArray
+ jr nc, .not_map_list_2
+ ld a, [wPlayerFacingDirection]
and a
- jr nz, .asm_fc641
+ jr nz, .not_map_list_2
ld a, $3
- jr .asm_fc647
+ jr .load
-.asm_fc62d
- ld a, [wSpriteStateData1 + $9]
+.route_22_gate
+ ld a, [wPlayerFacingDirection]
and a
- jr z, .asm_fc645
- jr .asm_fc641
+ jr z, .rock_tunnel_1
+ jr .not_map_list_2
-.asm_fc635
+.mt_moon_2
ld a, $3
- jr .asm_fc647
+ jr .load
-.asm_fc639
+.map_list_1
ld a, $4
- jr .asm_fc647
+ jr .load
-.asm_fc63d
+.oaks_lab
ld a, $6
- jr .asm_fc647
+ jr .load
-.asm_fc641
+.not_map_list_2
ld a, $1
- jr .asm_fc647
+ jr .load
-.asm_fc645
+.rock_tunnel_1
ld a, $3
-.asm_fc647
- ld [wd431], a
+.load
+ ld [wPikachuSpawnState], a
ret
Pointer_fc64b:: ; fc64b (3f:464b)
- db $c2, $4c, $4f, $ba, $be, $b8, $54, $ff
+ 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:: ; fc653 (3f:4653)
- db $2f, $e6, $3e, $5e, $80, $31, $a4, $ff
-
-Func_fc65b:: ; fc65b (3f:465b)
+ 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:: ; fc65b (3f:465b)
ld a, [wCurMap]
cp VIRIDIAN_FOREST_EXIT
- jr z, .asm_fc673
+ jr z, .viridian_forest_exit
cp VIRIDIAN_FOREST_ENTRANCE
- jr z, .asm_fc67c
+ jr z, .viridian_forest_entrance
ld a, [wCurMap]
ld hl, Pointer_fc68e
- call Func_1568
- jr c, .asm_fc688
- jr .asm_fc684
+ call Pikachu_IsInArray
+ jr c, .in_array
+ jr .not_in_array
-.asm_fc673
- ld a, [wSpriteStateData1 + $9]
+.viridian_forest_exit
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
- jr z, .asm_fc688
- jr .asm_fc684
+ jr z, .in_array
+ jr .not_in_array
-.asm_fc67c
- ld a, [wSpriteStateData1 + $9]
+.viridian_forest_entrance
+ ld a, [wPlayerFacingDirection]
and a ; SPRITE_FACING_DOWN
- jr z, .asm_fc684
- jr .asm_fc688
+ jr z, .not_in_array
+ jr .in_array
-.asm_fc684
+.not_in_array
ld a, $0
- jr .asm_fc68a
+ jr .load_spawn_state
-.asm_fc688
+.in_array
ld a, $1
-.asm_fc68a
- ld [wd431], a
+.load_spawn_state
+ ld [wPikachuSpawnState], a
ret
Pointer_fc68e:: ; fc68e (3f:468e)
- db $33, $dd, $df, $e0, $e1, $de, $ec, $7f, $a8, $a9, $aa, $ff
-
-Func_fc69a:: ; fc69a (3f:469a)
+ 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:: ; fc69a (3f:469a)
ld a, [wCurMap]
cp ROUTE_22_GATE
jr z, .asm_fc6a7
@@ -291,13 +315,13 @@ Func_fc69a:: ; fc69a (3f:469a)
jr .asm_fc6bd
.asm_fc6a7
- ld a, [wSpriteStateData1 + $9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
jr z, .asm_fc6b9
jr .asm_fc6bd
.asm_fc6b0
- ld a, [wSpriteStateData1 + $9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
jr z, .asm_fc6b9
jr .asm_fc6bd
@@ -311,7 +335,7 @@ Func_fc69a:: ; fc69a (3f:469a)
jr .asm_fc6c1
.asm_fc6c1
- ld [wd431], a
+ ld [wPikachuSpawnState], a
ret
Func_fc6c5:: ; fc6c5 (3f:46c5)
@@ -328,7 +352,7 @@ Func_fc6cd:: ; fc6cd (3f:46cd)
pop hl
ret
-Func_fc6d5:: ; fc6d5 (3f:46d5)
+SpawnPikachu_:: ; fc6d5 (3f:46d5)
call Func_fc6cd
call Func_fc727
ret nc
@@ -336,8 +360,8 @@ Func_fc6d5:: ; fc6d5 (3f:46d5)
call Func_fcd25
pop bc
ret c
- ld bc, wSpriteStateData1 + $f0
- ld hl, $1
+ ld bc, wPikachuPictureID
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
bit 7, [hl]
jp nz, asm_fc745
@@ -380,21 +404,21 @@ Func_fc726: ; fc726 (3f:4726)
Func_fc727: ; fc727 (3f:4727)
call Func_fc4dd
- jr nc, .asm_fc73b
- ld a, [wSpriteStateData1 + $f1]
+ jr nc, .dont_spawn
+ ld a, [wPikachuMovementStatus]
and a
- jr nz, .asm_fc739
+ jr nz, .already_spawned
push bc
push hl
call Func_fc534
pop hl
pop bc
-.asm_fc739
+.already_spawned
scf
ret
-.asm_fc73b
- ld hl, wSpriteStateData1 + $f2
+.dont_spawn
+ ld hl, wPikachuSpriteImageIdx
ld [hl], $ff
dec hl
ld [hl], $0
@@ -402,22 +426,22 @@ Func_fc727: ; fc727 (3f:4727)
ret
asm_fc745: ; fc745 (3f:4745)
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
res 7, [hl]
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], a
call CheckPikachuFollowingPlayer
jr nz, .asm_fc75f
- ld a, [wSpriteStateData1 + $9]
+ ld a, [wPlayerFacingDirection]
xor $4
- ld hl, $9
+ ld hl, wSprite01FacingDirection - wSprite01SpriteStateData1
add hl, bc
ld [hl], a
.asm_fc75f
xor a
- ld hl, $7
+ ld hl, wSprite01IntraAnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld [hli], a
ld [hl], a
@@ -426,7 +450,7 @@ asm_fc745: ; fc745 (3f:4745)
asm_fc76a: ; fc76a (3f:476a)
xor a
- ld hl, $7
+ ld hl, wSprite01IntraAnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld [hli], a
ld [hl], a
@@ -437,21 +461,21 @@ asm_fc76a: ; fc76a (3f:476a)
callab InitializeSpriteScreenPosition
pop bc
.asm_fc783
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $1
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $0
- call Func_fcba1
+ call RefreshPikachuFollow
ret
Func_fc793: ; fc793 (3f:4793)
- call Func_fcba1
+ call RefreshPikachuFollow
push bc
callab InitializeSpriteScreenPosition
pop bc
- ld hl, $2
+ ld hl, wSprite01SpriteImageIdx - wSprite01SpriteStateData1
add hl, bc
ld [hl], $ff
dec hl
@@ -472,12 +496,12 @@ Func_fc7aa: ; fc7aa (3f:47aa)
ld e, l
ld a, [de]
inc de
- ld hl, $9
+ ld hl, wSprite01FacingDirection - wSprite01SpriteStateData1
add hl, bc
ld [hl], a
ld a, [de]
inc de
- ld hl, $5
+ ld hl, wSprite01XStepVector - wSprite01SpriteStateData1
add hl, bc
ld [hl], a
dec hl
@@ -486,7 +510,7 @@ Func_fc7aa: ; fc7aa (3f:47aa)
ld [hl], a
inc de
ld a, [de]
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], a
cp $4
@@ -496,27 +520,27 @@ Func_fc7aa: ; fc7aa (3f:47aa)
jp Func_fc9b4
Pointer_fc7e3: ; fc7e3 (3f:47e3)
- db $0, $0
- db $1, $3
- db $4, $0
- db $ff, $3
- db $8, $ff
- db $0, $3
- db $c, $1
- db $0, $3
- db $0, $0
- db $1, $4
- db $4, $0
- db $ff, $4
- db $8, $ff
- db $0, $4
- db $c, $1
- db $0, $4
+ 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: ; fc803 (3f:4803)
call Func_fcae2
ret c
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
jr nz, .asm_fc823
@@ -528,12 +552,12 @@ Func_fc803: ; fc803 (3f:4803)
ld [hl], $20
call Random
and $c
- ld hl, $9
+ ld hl, wSprite01FacingDirection - wSprite01SpriteStateData1
add hl, bc
ld [hl], a
.asm_fc823
xor a
- ld hl, $7
+ ld hl, wSprite01IntraAnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld [hli], a
ld [hl], a
@@ -548,10 +572,10 @@ Func_fc82e: ; fc82e (3f:482e)
ret
Func_fc835: ; fc835 (3f:4835)
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $10
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $1
ret
@@ -584,16 +608,16 @@ Func_fc862: ; fc862 (3f:4862)
add a
add a
and $c
- ld hl, $9
+ ld hl, wSprite01FacingDirection - wSprite01SpriteStateData1
add hl, bc
ld [hl], a
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $6
xor a
ld [wd432], a
ld [wd433], a
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $11
asm_fc87f: ; fc87f (3f:487f)
@@ -604,7 +628,7 @@ asm_fc87f: ; fc87f (3f:487f)
call Func_fc82e
jr c, Func_fc8c7
call Func_fc6c5
- ld hl, $4
+ ld hl, wSprite01YPixels - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
sub e
@@ -614,14 +638,14 @@ asm_fc87f: ; fc87f (3f:487f)
ld a, [hl]
sub d
ld d, a
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
dec a
add a
- add $d6
+ add Pointer_fc8d6 % $100
ld l, a
- ld a, $48
+ ld a, Pointer_fc8d6 / $100
adc $0
ld h, a
ld a, [hli]
@@ -632,20 +656,20 @@ asm_fc87f: ; fc87f (3f:487f)
ld [wd433], a
add d
ld d, a
- ld hl, $4
+ ld hl, wSprite01YPixels - wSprite01SpriteStateData1
add hl, bc
ld [hl], e
inc hl
inc hl
ld [hl], d
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
ret nz
jp Func_fc835
Func_fc8c7: ; fc8c7 (3f:48c7)
- ld hl, $4
+ ld hl, wSprite01YPixels - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
sub e
@@ -658,26 +682,36 @@ Func_fc8c7: ; fc8c7 (3f:48c7)
jp Func_fc835
Pointer_fc8d6: ; fc8d6 (3f:48d6)
- db $0, $0, $fe, $1, $fc
- db $2, $fe, $3, $0, $4
- db $fe, $3, $fc, $2, $fe
- db $1, $0, $0, $fe, $ff
- db $fc, $fe, $fe, $fd, $0
- db $fc, $fe, $fd, $fc, $fe
- db $fe, $ff, $00, $00
+ 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: ; fc8f8 (3f:48f8)
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $7
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $30
asm_fc904: ; fc904 (3f:4904)
call Func_fc82e
jp c, Func_fc835
call Func_fc6c5
- ld hl, $7
+ ld hl, wSprite01IntraAnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
inc a
@@ -692,24 +726,24 @@ asm_fc904: ; fc904 (3f:4904)
ld [hl], a
.asm_fc91f
call Func_fca99
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
ret nz
jp Func_fc835
Func_fc92b: ; fc92b (3f:492b)
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $20
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $8
asm_fc937: ; fc937 (3f:4937)
call Func_fc82e
jp c, Func_fc835
call Func_fc6c5
- ld hl, $7
+ ld hl, wSprite01IntraAnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
inc a
@@ -723,24 +757,24 @@ asm_fc937: ; fc937 (3f:4937)
ld [hl], a
.asm_fc951
call Func_fca99
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
ret nz
jp Func_fc835
Func_fc95d: ; fc95d (3f:495d)
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $20
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $9
asm_fc969: ; fc969 (3f:4969)
call Func_fc82e
jp c, Func_fc835
call Func_fc6c5
- ld hl, $7
+ ld hl, wSprite01IntraAnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
inc a
@@ -749,14 +783,14 @@ asm_fc969: ; fc969 (3f:4969)
jr nz, .asm_fc988
xor a
ld [hl], a
- ld hl, $9
+ ld hl, wSprite01FacingDirection - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
call Func_fc994
ld [hl], a
.asm_fc988
call Func_fca99
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
ret nz
@@ -790,11 +824,12 @@ Pointer_fc9ac: ; fc9ac (3f:49ac)
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
Pointer_fc9ac_End:
+
Func_fc9b4: ; fc9b4 (3f:49b4)
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $8
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $3
call Func_fca38
@@ -802,22 +837,22 @@ asm_fc9c3: ; fc9c3 (3f:49c3)
call Func_fca4b
call Func_fca7e
call Func_fca99
- ld hl, $100
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
ret nz
call Func_fca75
call Func_fccb2
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $1
ret
Func_fc9df: ; fc9df (3f:49df)
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $4
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $5
call Func_fca38
@@ -825,22 +860,22 @@ asm_fc9ee: ; fc9ee (3f:49ee)
call asm_fca59
call Func_fca7e
call Func_fca99
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
ret nz
call Func_fca75
call Func_fccb2
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $1
ret
Func_fca0a: ; fca0a (3f:4a0a)
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
ld [hl], $8
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $4
call Func_fca38
@@ -849,25 +884,25 @@ asm_fca1c: ; fca1c (3f:4a1c)
call asm_fca59
call Func_fca7e
call Func_fca99
- ld hl, wSpriteStateData2 - wSpriteStateData1
+ ld hl, wSprite01WalkAnimationCounter - wSprite01SpriteStateData1
add hl, bc
dec [hl]
ret nz
call Func_fca75
call Func_fccb2
- ld hl, $1
+ ld hl, wSprite01MovementStatus - wSprite01SpriteStateData1
add hl, bc
ld [hl], $1
ret
Func_fca38: ; fca38 (3f:4a38)
- ld hl, $3
+ ld hl, wSprite01YStepVector - wSprite01SpriteStateData1
add hl, bc
ld e, [hl]
inc hl
inc hl
ld d, [hl]
- ld hl, $104
+ ld hl, wSprite01MapY - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
add e
@@ -885,7 +920,7 @@ Func_fca4b: ; fca4b (3f:4a4b)
bit 6, a
jr nz, Func_fca68
asm_fca59: ; fca59 (3f:4a59)
- ld hl, $3
+ ld hl, wSprite01YStepVector - wSprite01SpriteStateData1
add hl, bc
ld a, [hli]
add a
@@ -900,7 +935,7 @@ asm_fca59: ; fca59 (3f:4a59)
ret
Func_fca68: ; fca68 (3f:4a68)
- ld hl, $3
+ ld hl, wSprite01YStepVector - wSprite01SpriteStateData1
add hl, bc
ld a, [hli]
add a
@@ -913,7 +948,7 @@ Func_fca68: ; fca68 (3f:4a68)
ret
Func_fca75: ; fca75 (3f:4a75)
- ld hl, $3
+ ld hl, wSprite01YStepVector - wSprite01SpriteStateData1
add hl, bc
xor a
ld [hli], a
@@ -927,7 +962,7 @@ Func_fca7e: ; fca7e (3f:4a7e)
jr nc, .asm_fca87
ld d, $5
.asm_fca87
- ld hl, $7
+ ld hl, wSprite01IntraAnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
inc a
@@ -947,7 +982,7 @@ Func_fca99: ; fca99 (3f:4a99)
ld a, [wPikachuOverworldStateFlags]
bit 3, a
jr nz, .asm_fcad1
- ld hl, $10e
+ ld hl, wSprite01SpriteImageBaseOffset - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
dec a
@@ -956,7 +991,7 @@ Func_fca99: ; fca99 (3f:4a99)
ld a, [wd736]
bit 7, a
jr nz, .asm_fcad8
- ld hl, $9
+ ld hl, wSprite01FacingDirection - wSprite01SpriteStateData1
add hl, bc
ld a, [hl]
or d
@@ -969,32 +1004,32 @@ Func_fca99: ; fca99 (3f:4a99)
jr .asm_fcacb
.asm_fcac4
- ld hl, $8
+ ld hl, wSprite01AnimFrameCounter - wSprite01SpriteStateData1
add hl, bc
ld a, d
or [hl]
ld d, a
.asm_fcacb
- ld hl, $2
+ ld hl, wSprite01SpriteImageIdx - wSprite01SpriteStateData1
add hl, bc
ld [hl], d
ret
.asm_fcad1
- ld hl, $2
+ ld hl, wSprite01SpriteImageIdx - wSprite01SpriteStateData1
add hl, bc
ld [hl], $ff
ret
.asm_fcad8
- ld a, [wSpriteStateData1 + $2]
+ ld a, [wPlayerSpriteImageIdx]
and $f
or d
- ld [wSpriteStateData1 + $f2], a
+ ld [wPikachuSpriteImageIdx], a
ret
Func_fcae2: ; fcae2 (3f:4ae2)
- ld hl, $104
+ ld hl, wSprite01MapY - wSprite01SpriteStateData1
add hl, bc
ld a, [wYCoord]
add $4
@@ -1005,7 +1040,7 @@ Func_fcae2: ; fcae2 (3f:4ae2)
add $4
cp [hl]
jr nz, .asm_fcaff
- ld hl, $2
+ ld hl, wSprite01SpriteImageIdx - wSprite01SpriteStateData1
add hl, bc
ld [hl], $ff
scf
@@ -1015,58 +1050,58 @@ Func_fcae2: ; fcae2 (3f:4ae2)
and a
ret
-Func_fcb01: ; fcb01 (3f:4b01)
+IsPikachuRightNextToPlayer: ; fcb01 (3f:4b01)
push bc
push de
push hl
- ld bc, wSpriteStateData1 + $f0
+ ld bc, wPikachuPictureID
ld a, [wXCoord]
add $4
ld d, a
ld a, [wYCoord]
add $4
ld e, a
- ld hl, $104
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
add hl, bc
ld a, [hl]
sub e
and a
- jr z, .asm_fcb30
+ jr z, .equal
cp $ff
- jr z, .asm_fcb26
+ jr z, .one_away
cp $1
- jr z, .asm_fcb26
- jr .asm_fcb48
+ jr z, .one_away
+ jr .bad
-.asm_fcb26
- ld hl, $105
+.one_away
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
add hl, bc
ld a, [hl]
sub d
- jr z, .asm_fcb43
- jr .asm_fcb48
+ jr z, .good
+ jr .bad
-.asm_fcb30
- ld hl, $105
+.equal
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
add hl, bc
ld a, [hl]
sub d
cp $ff
- jr z, .asm_fcb43
+ jr z, .good
cp $1
- jr z, .asm_fcb43
+ jr z, .good
and a
- jr z, .asm_fcb43
- jr .asm_fcb48
+ jr z, .good
+ jr .bad
-.asm_fcb43
+.good
pop hl
pop de
pop bc
scf
ret
-.asm_fcb48
+.bad
pop hl
pop de
pop bc
@@ -1079,14 +1114,14 @@ GetPikachuFacingDirectionAndReturnToE: ; fcb4d (3f:4b4d)
ret
GetPikachuFacingDirection: ; fcb52 (3f:4b52)
- ld bc, wSpriteStateData1 + $f0
+ ld bc, wPikachuPictureID
ld a, [wXCoord]
add $4
ld d, a
ld a, [wYCoord]
add $4
ld e, a
- ld hl, wSpriteStateData2 - wSpriteStateData1 + 4
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
add hl, bc
ld a, [hl]
cp e
@@ -1100,7 +1135,7 @@ GetPikachuFacingDirection: ; fcb52 (3f:4b52)
ret
.asm_fcb71
- ld hl, wSpriteStateData2 - wSpriteStateData1 + 5
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
add hl, bc
ld a, [hl]
cp d
@@ -1138,7 +1173,7 @@ AppendPikachuFollowCommandToBuffer: ; fcb94 (3f:4b94)
ld [hl], a
ret
-Func_fcba1: ; fcba1 (3f:4ba1)
+RefreshPikachuFollow: ; fcba1 (3f:4ba1)
call ClearPikachuFollowCommandBuffer
call GetPikachuFollowCommand
ret c
@@ -1146,8 +1181,8 @@ Func_fcba1: ; fcba1 (3f:4ba1)
ret
GetPikachuFollowCommand: ; fcbac (3f:4bac)
- ld bc, wSpriteStateData1 + $f0
- ld hl, wSpriteStateData2 - wSpriteStateData1 + 4
+ ld bc, wPikachuPictureID
+ ld hl, wPlayerMapY - wPlayerSpriteStateData1
add hl, bc
ld a, [wYCoord]
add $4
@@ -1178,7 +1213,7 @@ GetPikachuFollowCommand: ; fcbac (3f:4bac)
ret
.checkXCoord
- ld hl, wSpriteStateData2 - wSpriteStateData1 + 5
+ ld hl, wPlayerMapX - wPlayerSpriteStateData1
add hl, bc
ld a, [wXCoord]
add $4
@@ -1369,7 +1404,7 @@ Func_fccb2:: ; fccb2 (3f:4cb2)
ld a, [wXCoord]
add $4
ld e, a
- ld a, [wSpriteStateData2 + $f4]
+ ld a, [wPikachuMapY]
cp d
jr z, .asm_fccd9
ld a, SPRITE_FACING_DOWN
@@ -1378,7 +1413,7 @@ Func_fccb2:: ; fccb2 (3f:4cb2)
jr .asm_fccea
.asm_fccd9
- ld a, [wSpriteStateData2 + $f5]
+ ld a, [wPikachuMapX]
cp e
jr z, .asm_fcce7
ld a, SPRITE_FACING_RIGHT
@@ -1387,9 +1422,9 @@ Func_fccb2:: ; fccb2 (3f:4cb2)
jr .asm_fccea
.asm_fcce7
- ld a, [wSpriteStateData1 + $9]
+ ld a, [wPlayerFacingDirection]
.asm_fccea
- ld [wSpriteStateData1 + $f9], a
+ ld [wPikachuFacingDirection], a
ret
Func_fccee: ; fccee (3f:4cee)
@@ -1799,6 +1834,8 @@ IsSurfingPikachuInThePlayersParty:: ; fceab (3f:4eab)
and a
ret
+INCLUDE "engine/pikachu_emotions.asm"
+INCLUDE "engine/pikachu_movement.asm"
INCLUDE "engine/pikachu_pic_animation.asm"
Func_fe66e:
diff --git a/engine/hidden_object_functions14.asm b/engine/hidden_object_functions14.asm
index 0724f962..e69e802c 100755
--- a/engine/hidden_object_functions14.asm
+++ b/engine/hidden_object_functions14.asm
@@ -89,7 +89,7 @@ FightingDojoText: ; 5298a (14:698a)
db "@"
PrintIndigoPlateauHQText: ; 5298f (14:698f)
- 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 8e5920d5..31f9befc 100755
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -14,7 +14,7 @@ RedBedroomPCText: ; 5db8e (17:5b8e)
db $fc ; FuncTX_ItemStoragePC
Route15GateLeftBinoculars: ; 5db8f (17:5b8f)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
diff --git a/engine/hidden_object_functions18.asm b/engine/hidden_object_functions18.asm
index 443f8369..cdba142b 100755
--- a/engine/hidden_object_functions18.asm
+++ b/engine/hidden_object_functions18.asm
@@ -3,7 +3,7 @@ GymStatues: ; 625e8 (18:65e8)
; 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
@@ -64,7 +64,7 @@ PrintBenchGuyText: ; 6245d (18:645d)
.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]
@@ -192,7 +192,7 @@ BookcaseText: ; 62511 (18:6511)
db "@"
OpenPokemonCenterPC: ; 62516 (18:6516)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP ; check to see if player is facing up
ret nz
call EnableAutoTextBoxDrawing
diff --git a/engine/hidden_object_functions3.asm b/engine/hidden_object_functions3.asm
index e43ae451..78da8274 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: ; f9de (3:79de)
- 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
diff --git a/engine/hidden_object_functions7.asm b/engine/hidden_object_functions7.asm
index 3108a836..c49c04bd 100755
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -115,7 +115,7 @@ GameOverText: ; 1e3aa (7:63aa)
db "@"
PrintCinnabarQuiz: ; 1e3af (7:63af)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
@@ -366,7 +366,7 @@ MagazinesText: ; 1e544 (7:6544)
BillsHousePC: ; 1e549 (7:6549)
call EnableAutoTextBoxDrawing
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
CheckEvent EVENT_LEFT_BILLS_HOUSE_AFTER_HELPING
@@ -497,7 +497,7 @@ BillsHousePokemonListText2: ; 1e67f (7:667f)
db "@"
DisplayOakLabEmailText: ; 1e684 (7:6684)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
diff --git a/engine/items/items.asm b/engine/items/items.asm
index f37f9f47..e147f5a5 100755
--- a/engine/items/items.asm
+++ b/engine/items/items.asm
@@ -1,18 +1,18 @@
UseItem_: ; d2ed (3:52ed)
- 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 a, 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: ; d307 (3:5307)
@@ -101,135 +101,137 @@ ItemUsePtrTable: ; d307 (3:5307)
dw ItemUsePPRestore ; MAX_ELIXER
ItemUseBall: ; d3ad (3:53ad)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp z,ItemUseNotTime ; not in battle
+ jp z, ItemUseNotTime ; not in battle
dec a
- jp nz,ThrowBallAtTrainerMon
- ld a,[wBattleType]
+ jp nz, ThrowBallAtTrainerMon
+ ld a, [wBattleType]
cp $1
- jr z,.UseBall
+ jr z, .UseBall
cp $4 ; pikachu battle?
- jr z,.UseBall
- ld a,[wPartyCount] ;is Party full?
- cp a,PARTY_LENGTH
- jr nz,.UseBall
- ld a,[wNumInBox] ;is Box full?
- cp a,MONS_PER_BOX
- jp z,BoxFullCannotThrowBall
+ jr z, .UseBall
+ ld a, [wPartyCount] ;is Party full?
+ cp a, PARTY_LENGTH
+ jr nz, .UseBall
+ ld a, [wNumInBox] ;is Box full?
+ cp a, MONS_PER_BOX
+ jp z, BoxFullCannotThrowBall
.UseBall
;ok, you can use a ball
xor a
- ld [wCapturedMonSpecies],a
- ld a,[wBattleType]
- cp a,2 ;SafariBattle
- jr nz,.skipSafariZoneCode
+ ld [wCapturedMonSpecies], a
+ ld a, [wBattleType]
+ cp a, 2 ;SafariBattle
+ jr nz, .skipSafariZoneCode
.safariZone
; remove a Safari Ball from inventory
- ld hl,wNumSafariBalls
+ ld hl, wNumSafariBalls
dec [hl]
.skipSafariZoneCode
call RunDefaultPaletteCommand
- ld a,$43
- ld [wd11e],a
+ ld a, $43
+ ld [wd11e], a
call LoadScreenTilesFromBuffer1 ;restore screenBuffer from Backup
- ld hl,ItemUseText00
+ ld hl, ItemUseText00
call PrintText
callab IsGhostBattle
- ld b,$10
- jp z,.next12
- ld a,[wBattleType]
+ ld b, $10
+ jp z, .next12
+ ld a, [wBattleType]
cp $1
- jr z,.oldManBattle
+ jr z, .oldManBattle
cp $4
- jr z,.oldManBattle ; pikachu battle technically old man battle
+ jr z, .oldManBattle ; pikachu battle technically old man battle
jr .notOldManBattle
+
.oldManBattle
- ld hl,wGrassRate
- ld de,wPlayerName
- ld bc,NAME_LENGTH
+ ld hl, wGrassRate
+ ld de, wPlayerName
+ ld bc, NAME_LENGTH
call CopyData ; save the player's name in the Wild Monster data
ld a, [wBattleType]
cp $1
- jp nz,.BallSuccess
- ld a,$1
+ jp nz, .BallSuccess
+ ld a, $1
ld [wCapturedMonSpecies], a
ld a, [wd74c]
bit 7, a
ld b, $63
- jp nz,.next12
+ jp nz, .next12
jp .BallSuccess
+
.notOldManBattle
- ld a,[wCurMap]
- cp a,POKEMONTOWER_6
- jr nz,.loop
- ld a,[wEnemyMonSpecies2]
- cp a,MAROWAK
- ld b,$10
- jp z,.next12
+ ld a, [wCurMap]
+ cp a, POKEMONTOWER_6
+ jr nz, .loop
+ ld a, [wEnemyMonSpecies2]
+ cp a, MAROWAK
+ ld b, $10
+ jp z, .next12
; if not fighting ghost Marowak, loop until a random number in the current
; pokeball's allowed range is found
.loop
call Random
- ld b,a
- ld hl,wcf91
+ ld b, a
+ ld hl, wcf91
.asm_d54a
- ld a,[hl]
- cp a,MASTER_BALL
- jp z,.BallSuccess
- cp a,POKE_BALL
- jr z,.checkForAilments
- ld a,200
+ ld a, [hl]
+ cp a, MASTER_BALL
+ jp z, .BallSuccess
+ cp a, POKE_BALL
+ jr z, .checkForAilments
+ ld a, 200
cp b
- jr c,.loop ;get only numbers <= 200 for Great Ball
- ld a,[hl]
- cp a,GREAT_BALL
- jr z,.checkForAilments
- ld a,150 ;get only numbers <= 150 for Ultra Ball
+ jr c, .loop ;get only numbers <= 200 for Great Ball
+ ld a, [hl]
+ cp a, GREAT_BALL
+ jr z, .checkForAilments
+ ld a, 150 ;get only numbers <= 150 for Ultra Ball
cp b
- jr c,.loop
+ jr c, .loop
.checkForAilments
; pokemon can be caught more easily with any (primary) status ailment
; Frozen/Asleep pokemon are relatively even easier to catch
; for Frozen/Asleep pokemon, any random number from 0-24 ensures a catch.
; for the others, a random number from 0-11 ensures a catch.
- ld a,[wEnemyMonStatus] ;status ailments
+ ld a, [wEnemyMonStatus] ;status ailments
and a
- jr z,.noAilments
+ jr z, .noAilments
and a, 1 << FRZ | SLP ;is frozen and/or asleep?
- ld c,12
- jr z,.notFrozenOrAsleep
- ld c,25
+ ld c, 12
+ jr z, .notFrozenOrAsleep
+ ld c, 25
.notFrozenOrAsleep
- ld a,b
+ ld a, b
sub c
- jp c,.BallSuccess
- ld b,a
+ jp c, .BallSuccess
+ ld b, a
.noAilments
push bc ;save RANDOM number
xor a
- ld [H_MULTIPLICAND],a
- ld hl,wEnemyMonMaxHP
- ld a,[hli]
- ld [H_MULTIPLICAND + 1],a
- ld a,[hl]
- ld [H_MULTIPLICAND + 2],a
- ld a,255
- ld [H_MULTIPLIER],a
+ ld [H_MULTIPLICAND], a
+ ld hl, wEnemyMonMaxHP
+ ld a, [hli]
+ ld [H_MULTIPLICAND + 1], a
+ ld a, [hl]
+ ld [H_MULTIPLICAND + 2], a
+ ld a, 255
+ ld [H_MULTIPLIER], a
call Multiply ; MaxHP * 255
- ld a,[wcf91]
+ ld a, [wcf91]
cp GREAT_BALL
- ld a,12 ;any other BallFactor
- jr nz,.next7
- ld a,8
+ ld a, 12 ;any other BallFactor
+ jr nz, .next7
+ ld a, 8
.next7
- ld [H_DIVISOR],a
- ld b,4 ; number of bytes in dividend
+ ld [H_DIVISOR], a
+ ld b, 4 ; number of bytes in dividend
call Divide
- ld hl,wEnemyMonHP
- ld a,[hli]
- ld b,a
- ld a,[hl]
+ ld hl, wEnemyMonHP
+ ld a, [hli]
+ ld b, a
+ ld a, [hl]
; explanation: we have a 16-bit value equal to [b << 8 | a].
; This number is divided by 4. The result is 8 bit (reg. a).
@@ -239,242 +241,247 @@ ItemUseBall: ; d3ad (3:53ad)
srl b
rr a ; a = current HP / 4
and a
- jr nz,.next8
+ jr nz, .next8
inc a
.next8
- ld [H_DIVISOR],a
- ld b,4
+ ld [H_DIVISOR], a
+ ld b, 4
call Divide ; ((MaxHP * 255) / BallFactor) / (CurHP / 4)
- ld a,[H_QUOTIENT + 2]
+ ld a, [H_QUOTIENT + 2]
and a
- jr z,.next9
- ld a,255
- ld [H_QUOTIENT + 3],a
+ jr z, .next9
+ ld a, 255
+ ld [H_QUOTIENT + 3], a
.next9
pop bc
- ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate
+ ld a, [wEnemyMonCatchRate] ;enemy: Catch Rate
cp b
- jr c,.next10
- ld a,[H_QUOTIENT + 2]
+ jr c, .next10
+ ld a, [H_QUOTIENT + 2]
and a
- jr nz,.BallSuccess ; if ((MaxHP * 255) / BallFactor) / (CurHP / 4) > 0x255, automatic success
+ jr nz, .BallSuccess ; if ((MaxHP * 255) / BallFactor) / (CurHP / 4) > 0x255, automatic success
call Random
- ld b,a
- ld a,[H_QUOTIENT + 3]
+ ld b, a
+ ld a, [H_QUOTIENT + 3]
cp b
- jr c,.next10
+ jr c, .next10
.BallSuccess
jr .BallSuccess2
+
.next10
- ld a,[H_QUOTIENT + 3]
- ld [wd11e],a
+ ld a, [H_QUOTIENT + 3]
+ ld [wd11e], a
xor a
- ld [H_MULTIPLICAND],a
- ld [H_MULTIPLICAND + 1],a
- ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate
- ld [H_MULTIPLICAND + 2],a
- ld a,100
- ld [H_MULTIPLIER],a
+ ld [H_MULTIPLICAND], a
+ ld [H_MULTIPLICAND + 1], a
+ ld a, [wEnemyMonCatchRate] ;enemy: Catch Rate
+ ld [H_MULTIPLICAND + 2], a
+ ld a, 100
+ ld [H_MULTIPLIER], a
call Multiply ; CatchRate * 100
- ld a,[wcf91]
- ld b,255
+ ld a, [wcf91]
+ ld b, 255
cp POKE_BALL
- jr z,.next11
- ld b,200
+ jr z, .next11
+ ld b, 200
cp GREAT_BALL
- jr z,.next11
- ld b,150
+ jr z, .next11
+ ld b, 150
cp ULTRA_BALL
- jr z,.next11
+ jr z, .next11
.next11
- ld a,b
- ld [H_DIVISOR],a
- ld b,4
+ ld a, b
+ ld [H_DIVISOR], a
+ ld b, 4
call Divide
- ld a,[H_QUOTIENT + 2]
+ ld a, [H_QUOTIENT + 2]
and a
- ld b,$63
- jr nz,.next12
- ld a,[wd11e]
- ld [H_MULTIPLIER],a
+ ld b, $63
+ jr nz, .next12
+ ld a, [wd11e]
+ ld [H_MULTIPLIER], a
call Multiply
- ld a,255
- ld [H_DIVISOR],a
- ld b,4
+ ld a, 255
+ ld [H_DIVISOR], a
+ ld b, 4
call Divide
- ld a,[wEnemyMonStatus] ;status ailments
+ ld a, [wEnemyMonStatus] ;status ailments
and a
- jr z,.next13
+ jr z, .next13
and 1 << FRZ | SLP
- ld b,5
- jr z,.next14
- ld b,10
+ ld b, 5
+ jr z, .next14
+ ld b, 10
.next14
- ld a,[H_QUOTIENT + 3]
+ ld a, [H_QUOTIENT + 3]
add b
- ld [H_QUOTIENT + 3],a
+ ld [H_QUOTIENT + 3], a
.next13
- ld a,[H_QUOTIENT + 3]
- cp a,10
- ld b,$20
- jr c,.next12
- cp a,30
- ld b,$61
- jr c,.next12
- cp a,70
- ld b,$62
- jr c,.next12
- ld b,$63
+ ld a, [H_QUOTIENT + 3]
+ cp a, 10
+ ld b, $20
+ jr c, .next12
+ cp a, 30
+ ld b, $61
+ jr c, .next12
+ cp a, 70
+ ld b, $62
+ jr c, .next12
+ ld b, $63
.next12
- ld a,b
- ld [wPokeBallAnimData],a
+ ld a, b
+ ld [wPokeBallAnimData], a
.BallSuccess2
- ld c,20
+ ld c, 20
call DelayFrames
- ld a,TOSS_ANIM
- ld [wAnimationID],a
+ 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
- ld a,[wPokeBallAnimData]
- cp a,$10
- ld hl,ItemUseBallText00
- jp z,.printText0
- cp a,$20
- ld hl,ItemUseBallText01
- jp z,.printText0
- cp a,$61
- ld hl,ItemUseBallText02
- jp z,.printText0
- cp a,$62
- ld hl,ItemUseBallText03
- jp z,.printText0
- cp a,$63
- ld hl,ItemUseBallText04
- jp z,.printText0
- ld hl,wEnemyMonHP ;current HP
- ld a,[hli]
+ ld [wWhichPokemon], a
+ ld a, [wPokeBallAnimData]
+ cp a, $10
+ ld hl, ItemUseBallText00
+ jp z, .printText0
+ cp a, $20
+ ld hl, ItemUseBallText01
+ jp z, .printText0
+ cp a, $61
+ ld hl, ItemUseBallText02
+ jp z, .printText0
+ cp a, $62
+ ld hl, ItemUseBallText03
+ jp z, .printText0
+ cp a, $63
+ ld hl, ItemUseBallText04
+ jp z, .printText0
+ ld hl, wEnemyMonHP ;current HP
+ ld a, [hli]
push af
- ld a,[hli]
+ ld a, [hli]
push af ;backup currentHP...
inc hl
- ld a,[hl]
+ ld a, [hl]
push af ;...and status ailments
push hl
- ld hl,wEnemyBattleStatus3
- bit Transformed,[hl]
- jr z,.next15
- ld a,$4c
- ld [wEnemyMonSpecies2],a
+ ld hl, wEnemyBattleStatus3
+ bit Transformed, [hl]
+ jr z, .next15
+ ld a, $4c
+ ld [wEnemyMonSpecies2], a
jr .next16
+
.next15
- set Transformed,[hl]
- ld hl,wTransformedEnemyMonOriginalDVs
- ld a,[wEnemyMonDVs]
- ld [hli],a
- ld a,[wEnemyMonDVs + 1]
- ld [hl],a
+ set Transformed, [hl]
+ ld hl, wTransformedEnemyMonOriginalDVs
+ ld a, [wEnemyMonDVs]
+ ld [hli], a
+ ld a, [wEnemyMonDVs + 1]
+ ld [hl], a
.next16
- ld a,[wcf91]
+ 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] ;enemy
- ld [wCapturedMonSpecies],a
- ld [wcf91],a
- ld [wd11e],a
- ld a,[wBattleType]
+ ld [hl], a
+ ld a, [wEnemyMonSpecies] ;enemy
+ ld [wCapturedMonSpecies], a
+ ld [wcf91], a
+ ld [wd11e], a
+ ld a, [wBattleType]
cp $1
- jp z,.printText1 ; just barely out of reach for a relative jump
+ jp z, .printText1 ; just barely out of reach for a relative jump
cp $4
- jr z,.printText1
- ld hl,ItemUseBallText05
+ jr z, .printText1
+ ld hl, ItemUseBallText05
call PrintText
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
and a
- jr nz,.checkParty
- ld hl,ItemUseBallText06
+ jr nz, .checkParty
+ ld hl, ItemUseBallText06
call PrintText
call ClearSprites
- ld a,[wEnemyMonSpecies] ;caught mon_ID
- ld [wd11e],a
+ ld a, [wEnemyMonSpecies] ;caught mon_ID
+ ld [wd11e], a
predef ShowPokedexData
.checkParty
ld a, $1
ld [wd49c], a
ld a, $85
ld [wPikachuMood], a
- ld a,[wPartyCount]
+ ld a, [wPartyCount]
cp PARTY_LENGTH ;is party full?
- jr z,.sendToBox
+ jr z, .sendToBox
xor a ; PLAYER_PARTY_DATA
- ld [wMonDataLocation],a
+ ld [wMonDataLocation], a
call ClearSprites
ld hl, .emptyString
call PrintText
call AddPartyMon ;add mon to Party
jr .End
+
.sendToBox
call ClearSprites
call SendNewMonToBox
- ld hl,ItemUseBallText07
+ ld hl, ItemUseBallText07
ld a, [wd7f1]
bit 0, a
- jr nz,.sendToBox2
- ld hl,ItemUseBallText08
+ jr nz, .sendToBox2
+ ld hl, ItemUseBallText08
.sendToBox2
call PrintText
jr .End
+
.printText1
- ld hl,ItemUseBallText05
+ ld hl, ItemUseBallText05
.printText0
call PrintText
call ClearSprites
.End
- ld a,[wBattleType]
+ ld a, [wBattleType]
and a
ret nz
- ld hl,wNumBagItems
+ ld hl, wNumBagItems
inc a
- ld [wItemQuantity],a
+ ld [wItemQuantity], a
jp RemoveItemFromInventory
+
.emptyString
db "@"
@@ -503,7 +510,7 @@ ItemUseBallText05: ; d6b0 (3:56b0)
;"All right! {MonName} was caught!"
;play sound
TX_FAR _ItemUseBallText05
- db $12,$06
+ db $12, $06
db "@"
ItemUseBallText07: ; d6b7 (3:59b7)
;"X was transferred to Bill's PC"
@@ -518,46 +525,47 @@ ItemUseBallText06: ; d6c1 (3:56c1)
;"New DEX data will be added..."
;play sound
TX_FAR _ItemUseBallText06
- db $13,$06
+ db $13, $06
db "@"
ItemUseTownMap: ; d6c8 (3:56c8)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
+ jp nz, ItemUseNotTime
jpba DisplayTownMap
ItemUseBicycle: ; d6d7 (3:56d7)
- 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 a, 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 [wd431], a
+ ld [wPikachuSpawnState], a
call PlayDefaultMusic ; play walking music
- ld hl,GotOffBicycleText
+ 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
+ ld [hJoyHeld], a ; current joypad state
ld a, $1
- ld [wWalkBikeSurfState],a ; change player state to bicycling
+ ld [wWalkBikeSurfState], a ; change player state to bicycling
call PlayDefaultMusic ; play bike riding music
xor a
- ld [wWalkBikeSurfState],a
- ld hl,GotOnBicycleText
+ ld [wWalkBikeSurfState], a
+ ld hl, GotOnBicycleText
call PrintText
ld a, $1
ld [wWalkBikeSurfState], a
@@ -565,79 +573,82 @@ ItemUseBicycle: ; d6d7 (3:56d7)
; used for Surf out-of-battle effect
ItemUseSurfboard: ; d725 (3:5725)
- ld a,[wWalkBikeSurfState]
- ld [wWalkBikeSurfStateCopy],a
- cp a,2 ; is the player already surfing?
- jr z,.tryToStopSurfing
+ ld a, [wWalkBikeSurfState]
+ ld [wWalkBikeSurfStateCopy], a
+ cp a, 2 ; is the player already surfing?
+ jr z, .tryToStopSurfing
.tryToSurf
call IsNextTileShoreOrWater
- jp nc,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 a,[wTileInFrontOfPlayer]
- ld c,a
+ jr c, .cannotStopSurfing
+ ld a, [wTileInFrontOfPlayer]
+ ld c, a
call IsTilePassable
- jr nc,.stopSurfing
+ jr nc, .stopSurfing
.cannotStopSurfing
- ld hl,SurfingNoPlaceToGetOffText
+ ld hl, SurfingNoPlaceToGetOffText
jp PrintText
+
.stopSurfing
call .makePlayerMoveForward
- ld a,$3
- ld [wd431], a
- ld hl,wPikachuOverworldStateFlags
- set 5,[hl]
- 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: ; d7c1 (3:57c1)
@@ -652,25 +663,25 @@ ItemUsePokedex: ; d7cb (3:57cb)
predef_jump ShowPokedexMenu
ItemUseEvoStone: ; d7d0 (3:57d0)
- 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
+ jr c, .canceledItemUse
+ ld a, b
+ ld [wcf91], a
call Func_d85d
jr nc, .noEffect
callab IsThisPartymonStarterPikachu_Party
@@ -687,24 +698,26 @@ ItemUseEvoStone: ; d7d0 (3:57d0)
ld a, $82
ld [wPikachuMood], a
jr .canceledItemUse
+
.notPlayerPikachu
- ld a,SFX_HEAL_AILMENT
+ ld a, SFX_HEAL_AILMENT
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
- ld a,$01
- ld [wForceEvolution],a
+ ld a, $01
+ ld [wForceEvolution], a
callab TryEvolvingMon ; try to evolve pokemon
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
@@ -748,6 +761,7 @@ Func_d85d: ; d85d (3:585d)
jr nz, .loop
scf
ret
+
.cannotEvolveWithUsedStone
and a
ret
@@ -757,42 +771,43 @@ RefusingText: ; d8a2 (3:58a2)
db "@"
ItemUseVitamin: ; d8a7 (3:58a7)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
+ jp nz, ItemUseNotTime
ItemUseMedicine: ; d8ae (3:58ae)
- ld a,[wPartyCount]
+ ld a, [wPartyCount]
and a
- jp z,Func_e4bf
- 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
+
.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
push af
cp $28
@@ -804,90 +819,92 @@ ItemUseMedicine: ; d8ae (3:58ae)
pop hl
.asm_d906
pop af
- ld [wcf91],a
+ ld [wcf91], a
pop af
- ld [wWhichPokemon],a
- ld a,[wPseudoItemID]
+ 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 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
; fall through if it's one of the status-specifc healing items
.cureStatusAilment
- ld bc,4
- add hl,bc ; hl now points to status
- ld a,[wcf91]
+ ld bc, 4
+ add hl, bc ; hl now points to status
+ ld a, [wcf91]
lb bc, ANTIDOTE_MSG, 1 << PSN
- cp a,ANTIDOTE
- jr z,.checkMonStatus
+ cp a, ANTIDOTE
+ jr z, .checkMonStatus
lb bc, BURN_HEAL_MSG, 1 << BRN
- cp a,BURN_HEAL
- jr z,.checkMonStatus
+ cp a, BURN_HEAL
+ jr z, .checkMonStatus
lb bc, ICE_HEAL_MSG, 1 << FRZ
- cp a,ICE_HEAL
- jr z,.checkMonStatus
+ cp a, ICE_HEAL
+ jr z, .checkMonStatus
lb bc, AWAKENING_MSG, SLP
- cp a,AWAKENING
- jr z,.checkMonStatus
+ cp a, AWAKENING
+ jr z, .checkMonStatus
lb bc, PARALYZ_HEAL_MSG, 1 << PAR
- cp a,PARLYZ_HEAL
- jr z,.checkMonStatus
+ cp a, 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,30
- add hl,bc ; hl now points to party stats
- ld de,wBattleMonMaxHP
- ld bc,10
+ ld bc, 30
+ add hl, bc ; hl now points to party stats
+ ld de, wBattleMonMaxHP
+ ld bc, 10
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 a, REVIVE
+ jr z, .updateInBattleFaintedData
+ cp a, MAX_REVIVE
+ jr z, .updateInBattleFaintedData
jp .healingItemNoEffect
+
.updateInBattleFaintedData
ld a, [wWhichPokemon]
push af
@@ -903,486 +920,499 @@ ItemUseMedicine: ; d8ae (3:58ae)
pop af
ld [wWhichPokemon], a
- ld a,[wIsInBattle]
+ 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 a, REVIVE
+ jp z, .healingItemNoEffect
+ cp a, MAX_REVIVE
+ jp z, .healingItemNoEffect
.compareCurrentHPToMaxHP
push hl
push bc
- ld bc,32
- add hl,bc ; hl now points to max HP
+ ld bc, 32
+ 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 a, 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,32
- add hl,bc ; hl now points to max HP
- ld a,[hli]
- ld [wHPBarMaxHP+1],a
- ld a,[hl]
- ld [wHPBarMaxHP],a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian)
- ld a,[wPseudoItemID]
+ ld bc, 32
+ add hl, bc ; hl now points to max HP
+ ld a, [hli]
+ ld [wHPBarMaxHP+1], a
+ ld a, [hl]
+ ld [wHPBarMaxHP], a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian)
+ ld a, [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 - wPartyMon1MaxHP
- add hl,bc ; hl now points to LSB of current HP of pokemon that used Softboiled
+ ld bc, wPartyMon1HP - wPartyMon1MaxHP
+ 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_0xFFFA]
- set 0,a
- ld [hFlags_0xFFFA],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_0xFFFA]
- res 0,a
- ld [hFlags_0xFFFA],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 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
.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
- ld d,h
- ld e,l ; de now points to current HP
- ld hl,33
- add hl,de ; hl now points to max HP
- ld a,[wcf91]
- cp a,REVIVE
- jr z,.setCurrentHPToHalfMaxHP
- ld a,[hld]
- ld b,a
- ld a,[de]
+ ld d, h
+ ld e, l ; de now points to current HP
+ ld hl, 33
+ add hl, de ; hl now points to max HP
+ ld a, [wcf91]
+ cp a, REVIVE
+ jr z, .setCurrentHPToHalfMaxHP
+ ld a, [hld]
+ ld b, a
+ 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 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 .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]
- cp a,FULL_RESTORE
- jr nz,.updateInBattleData
- ld bc,-31
- add hl,bc
+ ld a, [wcf91]
+ cp a, FULL_RESTORE
+ jr nz, .updateInBattleData
+ ld bc, -31
+ 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 a, 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 * 20
+ ld hl, wOAMBuffer + $90
+ ld bc, 2 * 20
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 a, FULL_RESTORE
+ jr c, .playStatusAilmentCuringSound
+ cp a, FULL_HEAL
+ jr z, .playStatusAilmentCuringSound
+ ld a, SFX_HEAL_HP
call PlaySoundWaitForCurrent
- ld a,[hFlags_0xFFFA]
- set 0,a
- ld [hFlags_0xFFFA],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_0xFFFA]
- res 0,a
- ld [hFlags_0xFFFA],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 a, REVIVE
+ jr z, .showHealingItemMessage
+ cp a, 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]
- ld [wd0b5],a
- ld [wd11e],a
- ld bc,33
- add hl,bc ; hl now points to level
- ld a,[hl] ; a = level
- ld [wCurEnemyLVL],a ; store level
+ ld a, [hl]
+ ld [wd0b5], a
+ ld [wd11e], a
+ ld bc, 33
+ add hl, bc ; hl now points to level
+ ld a, [hl] ; a = level
+ 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 a, RARE_CANDY
+ jp z, .useRareCandy
push hl
- sub a,HP_UP
+ sub a, HP_UP
add a
- ld bc,17
- add hl,bc
+ ld bc, 17
+ 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 a, 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 a, 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,34
- add hl,bc
- ld d,h
- ld e,l ; de now points to stats
- ld bc,-18
- add hl,bc ; hl now points to byte 3 of experience
- ld b,1
+ ld bc, 34
+ add hl, bc
+ ld d, h
+ ld e, l ; de now points to stats
+ ld bc, -18
+ add hl, bc ; hl now points to byte 3 of experience
+ ld b, 1
jp CalcStats ; recalculate stats
.useRareCandy
push hl
- ld bc,33
- add hl,bc ; hl now points to level
- ld a,[hl] ; a = level
+ ld bc, 33
+ add hl, bc ; hl now points to level
+ ld a, [hl] ; a = level
cp a, MAX_LEVEL
- jr z,.vitaminNoEffect ; can't raise level above 100
+ 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,-19
- add hl,bc ; hl now points to experience
+ ld bc, -19
+ add hl, bc ; hl now points to 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
- ld bc,34
- add hl,bc ; hl now points to MSB of max HP
- ld a,[hli]
- ld b,a
- ld c,[hl]
+ ld bc, 34
+ add hl, bc ; hl now points to MSB of max HP
+ ld a, [hli]
+ ld b, a
+ ld c, [hl]
pop hl
push bc
push hl
call .recalculateStats
pop hl
- ld bc,35 ; hl now points to LSB of max HP
- add hl,bc
+ ld bc, 35 ; hl now points to LSB of max HP
+ add hl, bc
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,-32
- add hl,de ; hl now points to MSB of current HP
- ld a,[hl]
+ ld de, -32
+ add hl, de ; hl now points to MSB 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
+ ld [wForceEvolution], a
callabd_ModifyPikachuHappiness PIKAHAPPY_LEVELUP
ld a, [wWhichPokemon]
push af
@@ -1390,15 +1420,15 @@ ItemUseMedicine: ; d8ae (3:58ae)
ld [wWhichPokemon], a
callab Func_2fd6a ; evolve pokemon, if appropriate
pop af
- ld [wWhichPokemon],a
+ ld [wWhichPokemon], a
callab TryEvolvingMon
- ld a,$01
- ld [wUpdateSpritesEnabled],a
+ ld a, $01
+ ld [wUpdateSpritesEnabled], a
pop af
- ld [wcf91],a
+ ld [wcf91], a
pop af
- ld [wWhichPokemon],a
+ ld [wWhichPokemon], a
jp RemoveUsedItem
VitaminStatRoseText: ; dd44 (3:5d44)
@@ -1417,50 +1447,50 @@ VitaminText: ; dd4e (3:5d4e)
db "SPECIAL@"
ItemUseBait: ; dd72 (3:5d72)
- 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: ; dd87 (3:5d87)
- 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: ; dd9f (3:5d9f)
- 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 a, 7
+ cp a, 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: ; ddc6 (3:5dc6)
@@ -1473,46 +1503,47 @@ ThrewRockText: ; ddca (3:5dca)
; also used for Dig out-of-battle effect
ItemUseEscapeRope: ; ddcf (3:5dcf)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jr nz,.notUsable
- ld a,[wCurMap]
- cp a,AGATHAS_ROOM
- jr z,.notUsable
- cp a,BILLS_HOUSE
- jr z,.notUsable
- cp a,POKEMON_FAN_CLUB
- jr z,.notUsable
- ld a,[wCurMapTileset]
- ld b,a
- ld hl,EscapeRopeTilesets
+ jr nz, .notUsable
+ ld a, [wCurMap]
+ cp a, AGATHAS_ROOM
+ jr z, .notUsable
+ cp a, BILLS_HOUSE
+ jr z, .notUsable
+ cp a, 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 a, $ff
+ jr z, .notUsable
cp b
- jr nz,.loop
- ld hl,wd732
- set 3,[hl]
- set 6,[hl]
+ jr nz, .loop
+ ld hl, wd732
+ set 3, [hl]
+ set 6, [hl]
call Func_1510
- ld hl,wd72e
- res 4,[hl]
- ld hl,wd790
- res 7,[hl]
+ ld hl, wd72e
+ res 4, [hl]
+ ld hl, wd790
+ res 7, [hl]
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
@@ -1521,23 +1552,23 @@ EscapeRopeTilesets: ; de28 (3:5e28)
db $ff ; terminator
ItemUseRepel: ; de2e (3:5e2e)
- ld b,100
+ ld b, 100
ItemUseRepelCommon: ; e005 (3:6005)
- 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: ; de3e (3:5e3e)
- 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
@@ -1545,40 +1576,43 @@ ItemUseXAccuracy: ; de3e (3:5e3e)
; The Card Key is handled in a different way.
ItemUseCardKey: ; de57 (3:de57)
xor a
- ld [wUnusedD71F],a
+ ld [wUnusedD71F], a
call GetTileAndCoordsInFrontOfPlayer
- ld a,[GetTileAndCoordsInFrontOfPlayer] ; $4586
- cp a,$18
- jr nz,.next0
- ld hl,CardKeyTable1
+ ld a, [GetTileAndCoordsInFrontOfPlayer] ; $4586
+ cp a, $18
+ jr nz, .next0
+ ld hl, CardKeyTable1
jr .next1
+
.next0
- cp a,$24
- jr nz,.next2
- ld hl,CardKeyTable2
+ cp a, $24
+ jr nz, .next2
+ ld hl, CardKeyTable2
jr .next1
+
.next2
- cp a,$5e
- jp nz,ItemUseNotTime
- ld hl,CardKeyTable3
+ cp a, $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 a, $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
@@ -1586,14 +1620,15 @@ ItemUseCardKey: ; de57 (3:de57)
.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.,
+; These tables are probably supposed to be door locations in Silph Co.,
; but they are unused.
; The reason there are 3 tables is unknown.
@@ -1604,48 +1639,48 @@ ItemUseCardKey: ; de57 (3:de57)
; 03: ID?
CardKeyTable1: ; dea7 (3:5ea7)
- 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: ; ded0 (3:5ed0)
- 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: ; def9 (3:5ef9)
- 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: ; df02 (3:5f02)
- 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: ; df11 (3:5f11)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp z,ItemUseNotTime
+ jp z, ItemUseNotTime
ld a, [wWhichPokemon]
push af
@@ -1655,22 +1690,22 @@ ItemUseGuardSpec: ; df11 (3:5f11)
pop af
ld [wWhichPokemon], a
- ld hl,wPlayerBattleStatus2
- set ProtectedByMist,[hl] ; Mist bit
+ ld hl, wPlayerBattleStatus2
+ set ProtectedByMist, [hl] ; Mist bit
jp PrintItemUseTextAndRemoveItem
ItemUseSuperRepel: ; df38 (3:5f38)
- ld b,200
+ ld b, 200
jp ItemUseRepelCommon
ItemUseMaxRepel: ; df3d (3:5f3d)
- ld b,250
+ ld b, 250
jp ItemUseRepelCommon
ItemUseDireHit: ; df42 (3:5f42)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp z,ItemUseNotTime
+ jp z, ItemUseNotTime
ld a, [wWhichPokemon]
push af
@@ -1680,35 +1715,36 @@ ItemUseDireHit: ; df42 (3:5f42)
pop af
ld [wWhichPokemon], a
- ld hl,wPlayerBattleStatus2
- set GettingPumped,[hl] ; Focus Energy bit
+ ld hl, wPlayerBattleStatus2
+ set GettingPumped, [hl] ; Focus Energy bit
jp PrintItemUseTextAndRemoveItem
ItemUseXStat: ; df69 (3:df69)
- 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 a, X_ATTACK - ATTACK_UP1_EFFECT
+ ld [hl], a ; store player move effect
call PrintItemUseTextAndRemoveItem
- ld a,XSTATITEM_ANIM ; X stat item animation ID
- ld [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]
@@ -1721,110 +1757,114 @@ ItemUseXStat: ; df69 (3:df69)
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: ; dfbd (3:5fbd)
- 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 a, ROUTE_12
+ jr nz, .notRoute12
ld a, [wd7d8]
bit 7, a
- jr nz,.noSnorlaxOrPikachuToWakeUp
+ jr nz, .noSnorlaxOrPikachuToWakeUp
; if the player hasn't beaten Route 12 Snorlax
- ld hl,Route12SnorlaxFluteCoords
+ ld hl, Route12SnorlaxFluteCoords
call ArePlayerCoordsInArray
- jr nc,.noSnorlaxOrPikachuToWakeUp
- ld hl,PlayedFluteHadEffectText
+ jr nc, .noSnorlaxOrPikachuToWakeUp
+ ld hl, PlayedFluteHadEffectText
call PrintText
ld hl, wd7d8
set 6, [hl]
ret
+
.notRoute12
- cp a,ROUTE_16
- jr nz,.notRoute16
+ cp a, ROUTE_16
+ jr nz, .notRoute16
ld a, [wd7e0]
bit 1, a
- jr nz,.noSnorlaxOrPikachuToWakeUp
+ jr nz, .noSnorlaxOrPikachuToWakeUp
; if the player hasn't beaten Route 16 Snorlax
- ld hl,Route16SnorlaxFluteCoords
+ ld hl, Route16SnorlaxFluteCoords
call ArePlayerCoordsInArray
- jr nc,.noSnorlaxOrPikachuToWakeUp
- ld hl,PlayedFluteHadEffectText
+ jr nc, .noSnorlaxOrPikachuToWakeUp
+ ld hl, PlayedFluteHadEffectText
call PrintText
ld hl, wd7e0
set 0, [hl]
ret
+
.notRoute16
- cp a,PEWTER_POKECENTER
- jr nz,.noSnorlaxOrPikachuToWakeUp
+ cp a, PEWTER_POKECENTER
+ jr nz, .noSnorlaxOrPikachuToWakeUp
call CheckPikachuFollowingPlayer
- jr z,.noSnorlaxOrPikachuToWakeUp
- callab Func_fcb01
- jr nc,.noSnorlaxOrPikachuToWakeUp
+ jr z, .noSnorlaxOrPikachuToWakeUp
+ callab IsPikachuRightNextToPlayer
+ jr nc, .noSnorlaxOrPikachuToWakeUp
ld hl, PlayedFluteHadEffectText
call PrintText
call ItemUseReloadOverworldData
ld e, $1a
callab Func_fd001
ret
+
.noSnorlaxOrPikachuToWakeUp
- ld hl,PlayedFluteNoEffectText
+ 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 c,a
+ ld [hl], a
+ ld hl, wEnemyMonStatus
+ ld a, [hl]
+ ld c, a
and b ; remove Sleep status
- ld [hl],a
- ld a,c
- and a,SLP
- jr z,.asm_e063
- ld a,$1
- ld [wWereAnyMonsAsleep],a
+ ld [hl], a
+ ld a, c
+ and a, 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 a, $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
@@ -1835,40 +1875,40 @@ ItemUsePokeflute: ; dfbd (3:5fbd)
; OUTPUT:
; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep
WakeUpEntireParty: ; e094 (3:6094)
- 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 a, 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: ; e0ac (3:60ac)
- 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: ; e0b5 (3:60b5)
- 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: ; e0ba (3:60ba)
@@ -1883,27 +1923,27 @@ PlayedFluteHadEffectText: ; e0c4 (3:60c4)
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
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]
+ ld a, [wChannelSoundIDs + CH2]
cp a, SFX_POKEFLUTE
- jr z,.musicWaitLoop
+ jr z, .musicWaitLoop
call PlayDefaultMusic ; start playing normal music again
.done
jp TextScriptEnd ; end text
ItemUseCoinCase: ; e0e7 (3:60e7)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
- ld hl,CoinCaseNumCoinsText
+ jp nz, ItemUseNotTime
+ ld hl, CoinCaseNumCoinsText
jp PrintText
CoinCaseNumCoinsText: ; e0f1 (3:60f1)
@@ -1919,7 +1959,7 @@ ItemUseOldRod: ; e0f9 (3:60f9)
ItemUseGoodRod: ; e106 (3:6106)
call FishingInit
- jp c,ItemUseNotTime
+ jp c, ItemUseNotTime
.RandomLoop
call Random
srl a
@@ -1928,17 +1968,17 @@ ItemUseGoodRod: ; e106 (3:6106)
cp 2
jr nc, .RandomLoop
; choose which monster appears
- ld hl,GoodRodMons
+ ld hl, GoodRodMons
add a
- ld c,a
- ld b,0
- add hl,bc
- ld b,[hl]
+ 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
@@ -1964,6 +2004,7 @@ ItemUseSuperRod: ; e130 (3:6130)
xor a
ld [wRodResponse], a
jr DoNotGenerateFishingEncounter
+
RodResponse: ; e15b (3:615b)
ld [wRodResponse], a
@@ -1993,30 +2034,32 @@ DoNotGenerateFishingEncounter: ; e16e (3:616e)
; 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: ; e182 (3:6182)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jr z,.notInBattle
+ jr z, .notInBattle
scf ; can't fish during battle
ret
+
.notInBattle
call IsNextTileShoreOrWater
- jr nc,.cannotFish
- ld a,[wWalkBikeSurfState]
- cp a,2 ; Surfing?
- jr z,.cannotFish
+ jr nc, .cannotFish
+ ld a, [wWalkBikeSurfState]
+ cp a, 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 a, $2
ld [wd49c], a
ld a, $81
ld [wPikachuMood], a
- ld c,80
+ ld c, 80
call DelayFrames
and a
ret
+
.cannotFish
scf ; can't fish when surfing
ret
@@ -2025,22 +2068,22 @@ ItemUseOaksParcel: ; e1b7 (3:61b7)
jp ItemUseNotYoursToUse
ItemUseItemfinder: ; e1ba (3:61ba)
- 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
@@ -2053,23 +2096,24 @@ ItemfinderFoundNothingText: ; e1eb (3:61eb)
db "@"
ItemUsePPUp: ; e1f0 (3:61f0)
- ld a,[wIsInBattle]
+ ld a, [wIsInBattle]
and a
- jp nz,ItemUseNotTime
+ jp nz, ItemUseNotTime
ItemUsePPRestore: ; e1f7 (3:61f7)
- 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, [wIsInBattle]
and a
@@ -2084,121 +2128,127 @@ ItemUsePPRestore: ; e1f7 (3:61f7)
jr z, .usePPItem
call ItemUseNotTime
jp .itemNotUsed
+
.usePPItem
- 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, [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
.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 a, ETHER
+ jr nc, .useEther ; if Ether or Max Ether
.usePPUp
- ld bc,21
- add hl,bc
- ld a,[hl] ; move PP
- cp a,3 << 6 ; have 3 PP Ups already been used?
- jr c,.PPNotMaxedOut
- ld hl,PPMaxedOutText
+ ld bc, 21
+ add hl, bc
+ ld a, [hl] ; move PP
+ cp a, 3 << 6 ; have 3 PP Ups already been used?
+ jr c, .PPNotMaxedOut
+ 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 a, 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 a, SFX_HEAL_AILMENT
call PlaySound
- ld hl,PPIncreasedText
+ 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 a, MAX_ETHER
+ jr z, .fullyRestorePP
+ ld a, [hl] ; move PP
+ and a, %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 a, 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,
+; 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 a, %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
@@ -2206,39 +2256,40 @@ ItemUsePPRestore: ; e1f7 (3:61f7)
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
@@ -2246,7 +2297,7 @@ ItemUsePPRestore: ; e1f7 (3:61f7)
call RunDefaultPaletteCommand
pop af
xor a
- ld [wActionResultOrTookBattleTurn],a ; item use failed
+ ld [wActionResultOrTookBattleTurn], a ; item use failed
ret
RaisePPWhichTechniqueText: ; e358 (3:6358)
@@ -2274,63 +2325,64 @@ UnusableItem: ; e371 (3:6371)
jp ItemUseNotTime
ItemUseTMHM: ; e374 (3:6374)
- 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 a, TM_01
push af
- jr nc,.skipAdding
- add a,55 ; if item is an HM, add 55
+ jr nc, .skipAdding
+ add a, 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
@@ -2341,45 +2393,46 @@ ItemUseTMHM: ; e374 (3:6374)
.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,[wWhichPokemon]
+ ld a, [wWhichPokemon]
push af
- ld a,d
- ld [wWhichPokemon],a
+ ld a, d
+ ld [wWhichPokemon], a
callabd_ModifyPikachuHappiness PIKAHAPPY_USEDTMHM
callab IsThisPartymonStarterPikachu_Party
- jr nc,.notTeachingThunderboltOrThunderToPikachu
- ld a,[wcf91]
- cp a,TM_24 ; are we teaching thunderbolt to the player pikachu?
- jr z,.teachingThunderboltOrThunderToPlayerPikachu
- cp a,TM_25 ; are we teaching thunder then?
- jr nz,.notTeachingThunderboltOrThunderToPikachu
+ jr nc, .notTeachingThunderboltOrThunderToPikachu
+ ld a, [wcf91]
+ cp a, TM_24 ; are we teaching thunderbolt to the player pikachu?
+ jr z, .teachingThunderboltOrThunderToPlayerPikachu
+ cp a, TM_25 ; are we teaching thunder then?
+ jr nz, .notTeachingThunderboltOrThunderToPikachu
.teachingThunderboltOrThunderToPlayerPikachu
ld a, $5
ld [wd49c], a
@@ -2389,7 +2442,7 @@ ItemUseTMHM: ; e374 (3:6374)
pop af
ld [wWhichPokemon], a
- ld a,[wcf91]
+ ld a, [wcf91]
call IsItemHM
ret c
jp RemoveUsedItem
@@ -2411,28 +2464,28 @@ MonCannotLearnMachineMoveText: ; e492 (3:6492)
db "@"
PrintItemUseTextAndRemoveItem: ; e497 (3:6497)
- 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: ; e4a5 (3:64a5)
- 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: ; e4b0 (3:64b0)
- ld hl,ItemUseNoEffectText
+ ld hl, ItemUseNoEffectText
jr ItemUseFailed
ItemUseNotTime: ; e4b5 (3:64b5)
- ld hl,ItemUseNotTimeText
+ ld hl, ItemUseNotTimeText
jr ItemUseFailed
ItemUseNotYoursToUse: ; e4ba (3:64ba)
- ld hl,ItemUseNotYoursToUseText
+ ld hl, ItemUseNotYoursToUseText
jr ItemUseFailed
Func_e4bf: ; e4bf (3:64bf)
@@ -2440,34 +2493,35 @@ Func_e4bf: ; e4bf (3:64bf)
ld [wActionResultOrTookBattleTurn], a
ld hl, DontHavePokemonText
jp PrintText
+
ThrowBallAtTrainerMon: ; e4ca (3:64ca)
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: ; e4eb (3:64eb)
- ld hl,NoCyclingAllowedHereText
+ ld hl, NoCyclingAllowedHereText
jr ItemUseFailed
BoxFullCannotThrowBall: ; e4f0 (3:64f0)
- ld hl,BoxFullCannotThrowBallText
+ ld hl, BoxFullCannotThrowBallText
jr ItemUseFailed
SurfingAttemptFailed: ; e4f5 (3:64f5)
- ld hl,NoSurfingHereText
+ ld hl, NoSurfingHereText
ItemUseFailed: ; e4f8 (3:64f8)
xor a
- ld [wActionResultOrTookBattleTurn],a ; item use failed
+ ld [wActionResultOrTookBattleTurn], a ; item use failed
jp PrintText
ItemUseNotTimeText: ; e4ff (3:64ff)
@@ -2530,37 +2584,37 @@ GotOffBicycleText: ; e540 (3:6540)
; [wWhichPokemon] = index of pokemon in party
; [wCurrentMenuItem] = index of move (when using a PP Up)
RestoreBonusPP: ; e54a (3:654a)
- 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 a, 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 a, %11000000 ; have any PP Ups been used?
+ call nz, AddBonusPP ; if so, add bonus PP
.nextMove
inc hl
inc de
@@ -2573,38 +2627,38 @@ RestoreBonusPP: ; e54a (3:654a)
; [hl] = move PP
AddBonusPP: ; e586 (3:6586)
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,%1111
+ and a, %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 a, 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
@@ -2621,74 +2675,75 @@ AddBonusPP: ; e586 (3:6586)
; OUTPUT:
; [wMaxPP] = max PP
GetMaxPP: ; e5bb (3:65bb)
- 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 a, 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 a, %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 a, %00111111 ; mask out the PP Up count
+ ld [wMaxPP], a ; store max PP
ret
GetSelectedMoveOffset: ; e627 (3:6627)
- ld a,[wWhichPokemon]
+ ld a, [wWhichPokemon]
call AddNTimes
GetSelectedMoveOffset2: ; e62d (3:662d)
- 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
@@ -2701,49 +2756,50 @@ GetSelectedMoveOffset2: ; e62d (3:662d)
; clears carry flag if the item is tossed, sets carry flag if not
TossItem_: ; e635 (3:6635)
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 a, 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
@@ -2769,32 +2825,32 @@ TooImportantToTossText: ; e6a3 (3:66a3)
; 00: item is not key item
; 01: item is key item
IsKeyItem_: ; e6a8 (3:66a8)
- 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 a, HM_01 ; is the item an HM or TM?
+ jr nc, .checkIfItemIsHM
; if the item is not an HM or TM
push af
- ld hl,KeyItemBitfield
- ld de,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"
@@ -2977,10 +3033,10 @@ SendNewMonToBox: ; e6e8 (3:66e8)
IsNextTileShoreOrWater: ; e808 (3:6808)
ld a, [wCurMapTileset]
ld hl, WaterTilesets
- ld de,1
+ ld de, 1
call IsInArray ; does the current map allow surfing?
ret nc ; if not, return
- ld hl,WaterTile
+ ld hl, WaterTile
ld a, [wCurMapTileset]
cp SHIP_PORT ; Vermilion Dock tileset
jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset
@@ -2988,10 +3044,10 @@ IsNextTileShoreOrWater: ; e808 (3:6808)
jr z, .skipShoreTiles
cp DOJO ; usual eastern shore tile
jr z, .skipShoreTiles
- ld hl,ShoreTiles
+ ld hl, ShoreTiles
.skipShoreTiles
- ld a,[wTileInFrontOfPlayer]
- ld de,$1
+ ld a, [wTileInFrontOfPlayer]
+ ld de, $1
call IsInArray
ret
@@ -3039,6 +3095,7 @@ FindWildLocationsOfMon: ; e848 (3:6848)
inc hl
inc c
jr .loop
+
.done
ld a, $ff ; list terminator
ld [de], a
diff --git a/engine/menu/bills_pc.asm b/engine/menu/bills_pc.asm
index a3f6f7fc..280b9df8 100644
--- a/engine/menu/bills_pc.asm
+++ b/engine/menu/bills_pc.asm
@@ -553,7 +553,7 @@ CableClubLeftGameboy:: ; 21867 (8:5867)
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]
@@ -570,7 +570,7 @@ CableClubRightGameboy:: ; 21887 (8:5887)
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]
@@ -587,7 +587,7 @@ JustAMomentText:: ; 218a7 (8:58a7)
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
diff --git a/engine/overworld/card_key.asm b/engine/overworld/card_key.asm
index 48b2380d..62d1d4fb 100755
--- a/engine/overworld/card_key.asm
+++ b/engine/overworld/card_key.asm
@@ -89,7 +89,7 @@ GetCoordsInFrontOfPlayer: ; 5265f (14:665f)
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
index 157649a7..0fc73bc7 100644
--- a/engine/overworld/check_player_state.asm
+++ b/engine/overworld/check_player_state.asm
@@ -90,7 +90,7 @@ IsPlayerFacingEdgeOfMap: ; c148 (3:4148)
push hl
push de
push bc
- ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
+ ld a, [wPlayerFacingDirection] ; player sprite's facing direction
srl a
ld c, a
ld b, $0
@@ -160,7 +160,7 @@ IsWarpTileInFrontOfPlayer: ; c197 (3:4197)
ld a, [wCurMap]
cp SS_ANNE_5
jr z, .ssAnne5
- ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction
+ ld a, [wPlayerFacingDirection] ; player sprite's facing direction
srl a
ld c, a
ld b, 0
diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm
index 3978cb9c..488bc4de 100755
--- a/engine/overworld/cut.asm
+++ b/engine/overworld/cut.asm
@@ -188,7 +188,7 @@ ReplaceTreeTileBlock: ; ef1f (3:6f1f)
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/get_coords_tile_in_front_of_player.asm b/engine/overworld/get_coords_tile_in_front_of_player.asm
index a0d38d7c..ce45e79c 100644
--- a/engine/overworld/get_coords_tile_in_front_of_player.asm
+++ b/engine/overworld/get_coords_tile_in_front_of_player.asm
@@ -6,7 +6,7 @@ _GetTileAndCoordsInFrontOfPlayer: ; c2d4 (3:42d4)
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 ; cp SPRITE_FACING_DOWN
jr nz, .notFacingDown
; facing down
@@ -45,7 +45,7 @@ GetTileTwoStepsInFrontOfPlayer: ; c309 (3:4309)
ld a, [hli]
ld d, a
ld e, [hl]
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
and a ; cp SPRITE_FACING_DOWN
jr nz, .notFacingDown
; facing down
diff --git a/engine/overworld/hidden_objects.asm b/engine/overworld/hidden_objects.asm
index cba2a221..6e515b5a 100755
--- a/engine/overworld/hidden_objects.asm
+++ b/engine/overworld/hidden_objects.asm
@@ -61,7 +61,7 @@ CheckForHiddenObject: ; f25f8 (3c:65f8)
; 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: ; 46a01 (11:6a01)
- 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 a6ebd9be..5d95cb18 100755
--- a/engine/overworld/ledges.asm
+++ b/engine/overworld/ledges.asm
@@ -6,7 +6,7 @@ HandleLedges: ; 1a7f4 (6:67f4)
and a ; OVERWORLD
ret nz
predef GetTileAndCoordsInFrontOfPlayer
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
ld b, a
aCoord 8, 9
ld c, a
diff --git a/engine/overworld/map_sprite_functions1.asm b/engine/overworld/map_sprite_functions1.asm
index 48eed56e..46479a9f 100644
--- a/engine/overworld/map_sprite_functions1.asm
+++ b/engine/overworld/map_sprite_functions1.asm
@@ -28,7 +28,7 @@ _UpdateSprites: ; 4bb7 (1:4bb7)
and a
jp z, UpdatePlayerSprite
cp $f0 ; pikachu
- jp z, Func_1552
+ jp z, SpawnPikachu
ld a, [hl]
UpdateNonPlayerSprite: ; 4be3 (1:4be3)
diff --git a/engine/overworld/map_sprites.asm b/engine/overworld/map_sprites.asm
index 9f25c585..68f6b006 100755
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -20,26 +20,26 @@ _InitMapSprites: ; 1401b (5:401b)
; 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: ; 14029 (5:4029)
- 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
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]
+ 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 c,a
- ld b,0
+ ld c, a
+ ld b, 0
ld a, (wSpriteSetID - wSpriteSet)
- ld hl,SpriteSets
+ ld hl, SpriteSets
call AddNTimes ; get sprite set offset
ld de, wSpriteSet
ld bc, (wSpriteSetID - wSpriteSet)
@@ -64,8 +64,8 @@ LoadSpriteSetFromMapHeader: ; 14061 (5:4061)
call FillMemory
ld a, SPRITE_PIKACHU ; load Pikachu separately
ld [wSpriteSet], a
- ld hl,wSpriteStateData1 + $10
- ld a,$0e
+ ld hl, wSprite01SpriteStateData1
+ ld a, 14
.storeVRAMSlotsLoop
push af
ld a, [hl] ; $C1X0 (picture ID) (zero if sprite slot is not used)
@@ -79,13 +79,14 @@ LoadSpriteSetFromMapHeader: ; 14061 (5:4061)
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, $10
+ ld de, wSprite02SpriteStateData1 - wSprite01SpriteStateData1
add hl, de
pop af
dec a
@@ -96,6 +97,7 @@ CheckIfPictureIDAlreadyLoaded: ; 1409b (5:409b)
; 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
@@ -106,7 +108,8 @@ CheckIfPictureIDAlreadyLoaded: ; 1409b (5:409b)
dec b ; have we reached the end of the sprite set?
jr z, .spriteNotAlreadyLoaded ; if so, we're done here
inc de
- jr CheckIfPictureIDAlreadyLoaded
+ jr .loop
+
.spriteSlotNotTaken
ld a, c
ld [de], a
@@ -127,6 +130,7 @@ CheckForFourTileSprite: ; 140ac (5:40ac)
; regular sprite
and a
ret
+
.notYellowSprite
scf
ret
@@ -140,6 +144,7 @@ LoadMapSpriteTilePatterns: ; 140b7 (5:40b7)
call LoadStillTilePattern
call LoadWalkingTilePattern
jr .continue
+
.fourTileSprite
call LoadStillTilePattern
.continue
@@ -202,7 +207,7 @@ GetSpriteVRAMAddress: ; 14018 (5:4108)
SpriteVRAMAddresses: ; 14118 (5:4118)
; 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 + $c0
+ dw vChars0 + $0c0
dw vChars0 + $180
dw vChars0 + $240
dw vChars0 + $300
@@ -211,8 +216,8 @@ SpriteVRAMAddresses: ; 14118 (5:4118)
dw vChars0 + $540
dw vChars0 + $600
dw vChars0 + $6c0
- dw vChars0 + $780
- dw vChars0 + $7c0
+ dw vChars0 + $780 ; 4-tile sprites
+ dw vChars0 + $7c0 ; 4-tile sprites
ReadSpriteSheetData: ; 1412e (5:412e)
ld a, [hVRAMSlot]
@@ -246,12 +251,12 @@ ReadSpriteSheetData: ; 1412e (5:412e)
Func_14150: ; 14150 (5:4150)
ld a, $1
- ld [wSpriteStateData2 + $e], a ; vram slot for player
+ ld [wPlayerSpriteImageBaseOffset], a ; vram slot for player
ld a, $2
- ld [wSpriteStateData2 + $fe], a ; vram slot for Pikachu
+ ld [wPikachuSpriteImageBaseOffset], a ; vram slot for Pikachu
ld a, $e
- ld hl, wSpriteStateData1 + $10
+ ld hl, wSprite01SpriteStateData1
.loop
ld [hVRAMSlot], a ; store current sprite set slot as a counter
ld a, [hl] ; $c1x0 (picture ID)
@@ -259,12 +264,12 @@ Func_14150: ; 14150 (5:4150)
jr z, .spriteUnused
call Func_14179
push hl
- ld de, (wSpriteStateData2 + $e) - (wSpriteStateData1) ; $10e
+ ld de, (wPlayerSpriteImageBaseOffset) - (wSpriteStateData1) ; $10e
add hl, de ; get $c2xe (sprite image base offset)
ld [hl], a ; write offset
pop hl
.spriteUnused
- ld de, $10
+ ld de, wSprite02SpriteStateData1 - wSprite01SpriteStateData1
add hl, de
ld a, [hVRAMSlot]
dec a
@@ -297,67 +302,68 @@ Func_14179: ; 14179 (5:4179)
GetSplitMapSpriteSetID: ; 14193 (5:4193)
ld e, a
ld d, 0
- ld hl,MapSpriteSets
+ ld hl, MapSpriteSets
add hl, de
- ld a,[hl] ; a = spriteSetID
- cp a,$f0 ; does the map have 2 sprite sets?
+ 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.
- 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
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" \ No newline at end of file
+INCLUDE "data/sprite_sets.asm"
diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm
index dfd1c012..6bd28dad 100644
--- a/engine/overworld/movement.asm
+++ b/engine/overworld/movement.asm
@@ -53,7 +53,7 @@ UpdatePlayerSprite: ; 4da5 (1:4da5)
ld a, SPRITE_FACING_RIGHT
jr .next
.next
- ld [wSpriteStateData1 + 9], a ; facing direction
+ ld [wPlayerFacingDirection], a ; facing direction
ld a, [wFontLoaded]
bit 0, a
jr z, .moving
@@ -89,7 +89,7 @@ UpdatePlayerSprite: ; 4da5 (1:4da5)
Func_4e32: ; 4e32 (1:4e32)
ld a, [wSpriteStateData1 + 8]
ld b, a
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
add b
ld [wSpriteStateData1 + 2], a
ret
diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm
index d883f0e3..d0b1cde4 100755
--- a/engine/overworld/player_animations.asm
+++ b/engine/overworld/player_animations.asm
@@ -35,7 +35,7 @@ EnterMapAnim: ; 70567 (1c:4567)
ld hl, wFacingDirectionList
call PlayerSpinInPlace
ld a, $1
- ld [wd431], a
+ ld [wPikachuSpawnState], a
.restoreDefaultMusic
call PlayDefaultMusic
.done
@@ -46,7 +46,7 @@ EnterMapAnim: ; 70567 (1c:4567)
call DelayFrames
call PlayerSpinWhileMovingDown
ld a, $0
- ld [wd431], a
+ ld [wPikachuSpawnState], a
jr .done
.flyAnimation
pop hl
@@ -63,7 +63,7 @@ EnterMapAnim: ; 70567 (1c:4567)
call DoFlyAnimation
call LoadPlayerSpriteGraphics
ld a, $1
- ld [wd431], a
+ ld [wPikachuSpawnState], a
jr .restoreDefaultMusic
FlyAnimationEnterScreenCoords: ; 705ed (1c:45ed)
diff --git a/engine/overworld/pokecenter.asm b/engine/overworld/pokecenter.asm
index b9307517..63137433 100755
--- a/engine/overworld/pokecenter.asm
+++ b/engine/overworld/pokecenter.asm
@@ -63,7 +63,7 @@ DisplayPokemonCenterDialogue_: ; 6d97 (1:6d97)
callab IsStarterPikachuInOurParty
call c, Func_6eaa
ld a, $5
- ld [wd431], a
+ ld [wPikachuSpawnState], a
call Func_1525
.doNotReturnPikachu
lb bc, 1, 0
diff --git a/engine/overworld/ssanne.asm b/engine/overworld/ssanne.asm
index ece4446d..d0d957be 100755
--- a/engine/overworld/ssanne.asm
+++ b/engine/overworld/ssanne.asm
@@ -32,7 +32,7 @@ AnimateBoulderDust: ; 7a0fb (1e:60fb)
jp LoadPlayerSpriteGraphics
GetMoveBoulderDustFunctionPointer: ; 7913f (1e:613f)
- 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
index 58667e51..64d215a1 100644
--- a/engine/overworld/step_functions.asm
+++ b/engine/overworld/step_functions.asm
@@ -2,7 +2,7 @@ ApplyOutOfBattlePoisonDamage: ; c3de (3:43de)
ld a, [wd730]
add a
jp c, .noBlackOut ; no black out if joypad states are being simulated
- ld a, [wPreventBlackout]
+ ld a, [wd492]
bit 7, a
jp nz, .noBlackOut
ld a, [wd72e]
diff --git a/engine/overworld/try_pushing_boulder.asm b/engine/overworld/try_pushing_boulder.asm
index 89e83ff9..b7e04092 100644
--- a/engine/overworld/try_pushing_boulder.asm
+++ b/engine/overworld/try_pushing_boulder.asm
@@ -38,7 +38,7 @@ Func_f0a7: ; f0a7 (3:70a7)
jp nz, ResetBoulderPushFlags
ld a, [hJoyHeld]
ld b, a
- ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction
+ ld a, [wPlayerFacingDirection] ; player's sprite facing direction
cp SPRITE_FACING_UP
jr z, .pushBoulderUp
cp SPRITE_FACING_LEFT
diff --git a/engine/pikachu_emotions.asm b/engine/pikachu_emotions.asm
new file mode 100755
index 00000000..fdfb7813
--- /dev/null
+++ b/engine/pikachu_emotions.asm
@@ -0,0 +1,674 @@
+IsPlayerTalkingToPikachu:: ; fcf0c (3f:4f0c)
+ 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: ; fcf20 (3f:4f20)
+ 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: ; fcf35 (3f:4f35)
+ 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: ; fcf54 (3f:4f54)
+ 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: ; fcf6a (3f:4f6a)
+StarterPikachuEmotionCommand_nop3: ; fcf6a (3f:4f6a)
+ ret
+
+StarterPikachuEmotionCommand_text: ; fcf6b (3f:4f6b)
+ 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: ; fcf77 (3f:4f77)
+ ld a, [de]
+ inc de
+ push de
+ ld e, a
+ nop
+ call PlayPikachuSoundClip_
+ pop de
+ ret
+
+PlayPikachuSoundClip_: ; fcf81 (3f:4f81)
+ cp $ff
+ ret z
+ callab PlayPikachuSoundClip
+ ret
+
+StarterPikachuEmotionCommand_emote: ; fcf8d (3f:4f8d)
+ 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: ; fcfa2 (3f:4fa2)
+ ld [wWhichEmotionBubble], a
+ ld a, $f
+ ld [wEmotionBubbleSpriteIndex], a
+ predef EmotionBubble
+ ret
+
+StarterPikachuEmotionCommand_movement: ; fcfb0 (3f:4fb0)
+ 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: ; fcfbe (3f:4fbe)
+ ld a, [de]
+ inc de
+ push de
+ ld c, a
+ call DelayFrames
+ pop de
+ ret
+
+StarterPikachuEmotionCommand_subcmd: ; fcfc7 (3f:4fc7)
+ ld a, [de]
+ inc de
+ push de
+ ld e, a
+ ld d, $0
+ ld hl, Jumptable_fcfda
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ call JumpToAddress
+ pop de
+ ret
+
+Jumptable_fcfda:
+ dw LoadPikachuSpriteIntoVRAM
+ dw LoadFontTilePatterns
+ dw Pikachu_LoadCurrentMapViewUpdateSpritesAndDelay3
+ dw WaitForTextScrollButtonPress
+ dw PikachuPewterPokecenterCheck
+ dw PikachuFanClubCheck
+ dw PikachuBillsHouseCheck
+
+StarterPikachuEmotionCommand_nop2: ; fcfe8 (3f:4fe8)
+ ret
+
+StarterPikachuEmotionCommand_9: ; fcfe9 (3f:4fe9)
+ push de
+ call StarterPikachuEmotionCommand_turnawayfromplayer
+ call UpdateSprites
+ pop de
+ ret
+
+StarterPikachuEmotionCommand_turnawayfromplayer: ; fcff2 (3f:4ff2)
+ ld a, [wPlayerFacingDirection]
+ xor $4
+ ld [wPikachuFacingDirection], a
+ ret
+
+DeletedFunction_fcffb: ; fcffb (3f:4ffb)
+; Inexplicably empty.
+ rept 5
+ nop
+ endr
+ ret
+
+Func_fd001:: ; fd001 (3f:5001)
+ ld a, e
+ jr load_expression
+
+Func_fd004:: ; fd004 (3f:5004)
+ call MapSpecificPikachuExpression
+ jr c, load_expression
+ call GetPikaPicAnimationScriptIndex
+ call DeletedFunction_fcffb
+load_expression: ; fd00f (3f:500f)
+ ld [wExpressionNumber], a
+ ld hl, PikachuEmotionTable
+ call DoStarterPikachuEmotions
+ ret
+
+PikachuEmotionTable: ; fd019 (3f:4019)
+ dw PikachuEmotion0_fd115
+ dw PikachuEmotion1_fd141
+ dw PikachuEmotion2_fd116
+ dw PikachuEmotion3_fd160
+ dw PikachuEmotion4_fd136
+ dw PikachuEmotion5_fd14d
+ dw PikachuEmotion6_fd153
+ dw PikachuEmotion7_fd128
+ dw PikachuEmotion8_fd147
+ dw PikachuEmotion9_fd166
+ dw PikachuEmotion10_fd11e
+ dw PikachuEmotion11_fd173
+ dw PikachuEmotion12_fd17a
+ dw PikachuEmotion13_fd180
+ dw PikachuEmotion14_fd189
+ dw PikachuEmotion15_fd191
+ dw PikachuEmotion16_fd197
+ dw PikachuEmotion17_fd19d
+ dw PikachuEmotion18_fd1a3
+ dw PikachuEmotion19_fd1a9
+ dw PikachuEmotion20_fd1b1
+ dw PikachuEmotion21_fd1b9 ; used a fishing rod
+ dw PikachuEmotion22_fd1c1
+ dw PikachuEmotion23_fd1c7
+ dw PikachuEmotion24_fd1cf
+ dw PikachuEmotion25_fd1d7
+ dw PikachuEmotion26_fd1df ; wake up pikachu in pewter pokemon center
+ dw PikachuEmotion27_fd1eb
+ dw PikachuEmotion28_fd1f1
+ dw PikachuEmotion29_fd1f7
+ dw PikachuEmotion30_fd1fc
+ dw PikachuEmotion31_fd20a
+ dw PikachuEmotion32_fd213
+ dw PikachuEmotion33_fd05d
+
+PikachuEmotion33_fd05d: ; fd05d (3f:505d)
+ db $ff
+
+MapSpecificPikachuExpression: ; fd05e (3f:505e)
+ ld a, [wCurMap]
+ cp POKEMON_FAN_CLUB
+ jr nz, .notFanClub
+ ld hl, wd492
+ bit 7, [hl]
+ ld a, $1d
+ jr z, .set_carry
+ call CheckPikachuFollowingPlayer
+ ld a, $1e
+ jr nz, .set_carry
+ jr .asm_fd096
+
+.notFanClub
+ ld a, [wCurMap]
+ cp PEWTER_POKECENTER
+ jr nz, .notPewterPokecenter
+ call CheckPikachuFollowingPlayer
+ ld a, $1a
+ jr nz, .set_carry
+ jr .asm_fd096
+
+.notPewterPokecenter
+ callab Func_f24ae
+ ld a, e
+ cp $ff
+ jr nz, .set_carry
+ jr .asm_fd096
+
+.asm_fd096
+ call IsPlayerPikachuAsleepInParty
+ ld a, $b
+ jr c, .set_carry
+ callab Func_fce73 ; same bank
+ ld a, $1c
+ jr c, .set_carry
+ ld a, [wCurMap]
+ cp POKEMONTOWER_1
+ jr c, .notInLavenderTower
+ cp POKEMONTOWER_7 + 1
+ ld a, $16
+ jr c, .set_carry
+.notInLavenderTower
+ ld a, [wd49c]
+ and a
+ jr z, .no_carry
+ dec a
+ ld c, a
+ ld b, $0
+ ld hl, Pointer_fd0cb
+ add hl, bc
+ ld a, [hl]
+ jr .set_carry
+
+.no_carry
+ and a
+ ret
+
+.set_carry
+ scf
+ ret
+
+Pointer_fd0cb:
+ db $12, $15, $17, $18, $19
+
+IsPlayerPikachuAsleepInParty:: ; fd0d0 (3f:50d0)
+ 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
+
+PikachuEmotion0_fd115: ; fd115 (3f:5115)
+ db $ff
+
+PikachuEmotion2_fd116: ; fd116 (3f:5116)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble SMILE_BUBBLE
+ pikaemotion_pcm PikachuCry35
+ pikaemotion_pikapic $2
+ db $ff
+
+PikachuEmotion10_fd11e: ; fd11e (3f:511e)
+ pikaemotion_dummy2
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
+ pikaemotion_emotebubble HEART_BUBBLE
+ pikaemotion_pcm PikachuCry5
+ pikaemotion_pikapic $a
+ db $ff
+
+PikachuEmotion7_fd128: ; fd128 (3f:5128)
+ pikaemotion_dummy2
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
+ pikaemotion_movement Pointer_fd224
+ pikaemotion_pcm PikachuCry1
+ pikaemotion_movement Pointer_fd224
+ pikaemotion_pikapic $7
+ db $ff
+
+PikachuEmotion4_fd136: ; fd136 (3f:5136)
+ pikaemotion_dummy2
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
+ pikaemotion_movement Pointer_fd230
+ pikaemotion_pcm PikachuCry29
+ pikaemotion_pikapic $4
+ db $ff
+
+PikachuEmotion1_fd141: ; fd141 (3f:5141)
+ pikaemotion_dummy2
+ pikaemotion_pcm
+ pikaemotion_pikapic $1
+ db $ff
+
+PikachuEmotion8_fd147: ; fd147 (3f:5147)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry39
+ pikaemotion_pikapic $8
+ db $ff
+
+PikachuEmotion5_fd14d: ; fd14d (3f:514d)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry31
+ pikaemotion_pikapic $5
+ db $ff
+
+PikachuEmotion6_fd153: ; fd153 (3f:5153)
+ pikaemotion_dummy2
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
+ pikaemotion_pcm
+ pikaemotion_movement Pointer_fd21e
+ pikaemotion_emotebubble SKULL_BUBBLE
+ pikaemotion_pikapic $6
+ db $ff
+
+PikachuEmotion3_fd160: ; fd160 (3f:5160)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry40
+ pikaemotion_pikapic $3
+ db $ff
+
+PikachuEmotion9_fd166: ; fd166 (3f:5166)
+ pikaemotion_dummy2
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
+ pikaemotion_pcm PikachuCry6
+ pikaemotion_movement Pointer_fd218
+ pikaemotion_emotebubble SKULL_BUBBLE
+ pikaemotion_pikapic $9
+ db $ff
+
+PikachuEmotion11_fd173: ; fd173 (3f:5173)
+ pikaemotion_emotebubble ZZZ_BUBBLE
+ pikaemotion_pcm PikachuCry37
+ pikaemotion_pikapic $b
+ db $ff
+
+PikachuEmotion12_fd17a: ; fd17a (3f:517a)
+ pikaemotion_dummy2
+ pikaemotion_pcm
+ pikaemotion_pikapic $c
+ db $ff
+
+PikachuEmotion13_fd180: ; fd180 (3f:5180)
+ pikaemotion_dummy2
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
+ pikaemotion_movement Pointer_fd21e
+ pikaemotion_pikapic $d
+ db $ff
+
+PikachuEmotion14_fd189: ; fd189 (3f:5189)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble BOLT_BUBBLE
+ pikaemotion_pcm PikachuCry10
+ pikaemotion_pikapic $e
+ db $ff
+
+PikachuEmotion15_fd191: ; fd191 (3f:5191)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry34
+ pikaemotion_pikapic $f
+ db $ff
+
+PikachuEmotion16_fd197: ; fd197 (3f:5197)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry33
+ pikaemotion_pikapic $10
+ db $ff
+
+PikachuEmotion17_fd19d: ; fd19d (3f:519d)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry13
+ pikaemotion_pikapic $11
+ db $ff
+
+PikachuEmotion18_fd1a3: ; fd1a3 (3f:51a3)
+ pikaemotion_dummy2
+ pikaemotion_pcm
+ pikaemotion_pikapic $12
+ db $ff
+
+PikachuEmotion19_fd1a9: ; fd1a9 (3f:51a9)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble HEART_BUBBLE
+ pikaemotion_pcm PikachuCry33
+ pikaemotion_pikapic $13
+ db $ff
+
+PikachuEmotion20_fd1b1: ; fd1b1 (3f:51b1)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble HEART_BUBBLE
+ pikaemotion_pcm PikachuCry5
+ pikaemotion_pikapic $14
+ db $ff
+
+PikachuEmotion21_fd1b9: ; fd1b9 (3f:51b9)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble FISH_BUBBLE
+ pikaemotion_pcm
+ pikaemotion_pikapic $15
+ db $ff
+
+PikachuEmotion22_fd1c1: ; fd1c1 (3f:51c1)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry4
+ pikaemotion_pikapic $16
+ db $ff
+
+PikachuEmotion23_fd1c7: ; fd1c7 (3f:51c7)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry19
+ pikaemotion_pikapic $17
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
+ db $ff
+
+PikachuEmotion24_fd1cf: ; fd1cf (3f:51cf)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble EXCLAMATION_BUBBLE
+ pikaemotion_pcm
+ pikaemotion_pikapic $18
+ db $ff
+
+PikachuEmotion25_fd1d7: ; fd1d7 (3f:51d7)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble BOLT_BUBBLE
+ pikaemotion_pcm PikachuCry35
+ pikaemotion_pikapic $19
+ db $ff
+
+PikachuEmotion26_fd1df: ; fd1df (3f:51df)
+ pikaemotion_dummy2
+ pikaemotion_emotebubble ZZZ_BUBBLE
+ pikaemotion_pcm PikachuCry37
+ pikaemotion_pikapic $1a
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_CHECKPEWTERCENTER
+ db $ff
+
+PikachuEmotion27_fd1eb: ; fd1eb (3f:51eb)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry9
+ pikaemotion_pikapic $1b
+ db $ff
+
+PikachuEmotion28_fd1f1: ; fd1f1 (3f:51f1)
+ pikaemotion_dummy2
+ pikaemotion_pcm PikachuCry15
+ pikaemotion_pikapic $1c
+ db $ff
+
+PikachuEmotion29_fd1f7: ; fd1f7 (3f:51f7)
+ pikaemotion_pcm PikachuCry5
+ pikaemotion_pikapic $a
+ db $ff
+
+PikachuEmotion30_fd1fc: ; fd1fc (3f:51fc)
+ pikaemotion_9
+ pikaemotion_emotebubble HEART_BUBBLE
+ pikaemotion_pcm PikachuCry5
+ pikaemotion_pikapic $14
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADFONT
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_CHECKLAVENDERTOWER
+ db $ff
+
+PikachuEmotion31_fd20a: ; fd20a (3f:520a)
+ pikaemotion_pcm PikachuCry19
+ pikaemotion_pikapic $17
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
+ pikaemotion_subcmd PIKAEMOTION_SUBCMD_CHECKBILLSHOUSE
+ db $ff
+
+PikachuEmotion32_fd213: ; fd213 (3f:5213)
+ pikaemotion_pcm PikachuCry26
+ pikaemotion_pikapic $17
+ db $ff
+
+Pointer_fd218: ; fd218 (3f:5218)
+ db $00
+ db $39, $01
+ db $3e, $1e
+ db $3f
+
+Pointer_fd21e: ; fd21e (3f:521e)
+ db $00
+ db $39, $00
+ db $3e, $1e
+ db $3f
+
+Pointer_fd224: ; fd224 (3f:5224)
+ db $00
+ db $3c, $07, $2f
+ db $3c, $07, $2f
+ db $3f
+
+Pointer_fd22c: ; fd22c (3f:522c)
+ db $3b, $1f, $03
+ db $3f
+
+Pointer_fd230: ; fd230 (3f:5230)
+ db $00
+ db $3c, $0f, $1f
+ db $3c, $0f, $1f
+ db $3f
+
+Pointer_fd238: ; fd238 (3f:5238)
+ db $00
+ db $05, $07
+ db $39, $00
+ db $05, $07
+ db $06, $07
+ db $39, $00
+ db $06, $07
+ db $08, $07
+ db $39, $00
+ db $08, $07
+ db $07, $07
+ db $39, $00
+ db $07, $07
+ db $3f
+
+Func_fd252: ; fd252 (3f:5252)
+ ld a, $40
+ ld [h_0xFFFC], a
+ call LoadPikachuSpriteIntoVRAM
+ call Func_fd266
+ and a
+ jr z, .asm_fd262
+ call ApplyPikachuMovementData
+.asm_fd262
+ xor a
+ ld [h_0xFFFC], a
+ ret
+
+Func_fd266:
+ ld a, [wSpriteStateData2 + 15 * 16 + 4]
+ ld e, a
+ ld a, [wSpriteStateData2 + 15 * 16 + 5]
+ ld d, a
+ ld a, [wYCoord]
+ add 4
+ cp e
+ jr z, .asm_fd280
+ jr nc, .asm_fd27e
+ ld hl, Data_fd294
+ ld a, 1
+ ret
+
+.asm_fd27e
+ xor a
+ ret
+
+.asm_fd280
+ ld a, [wXCoord]
+ add 4
+ cp d
+ jr c, .asm_fd28e
+ ld hl, Data_fd299
+ ld a, 2
+ ret
+
+.asm_fd28e
+ ld hl, Data_fd29d
+ ld a, 3
+ ret
+
+Data_fd294:
+ db $00
+ db $36
+ db $2b
+ db $34
+ db $3f
+
+Data_fd299:
+ db $00
+ db $36
+ db $34
+ db $3f
+
+Data_fd29d:
+ db $00
+ db $36
+ db $33
+ db $3f
diff --git a/engine/pikachu_movement.asm b/engine/pikachu_movement.asm
new file mode 100755
index 00000000..fbb71ffd
--- /dev/null
+++ b/engine/pikachu_movement.asm
@@ -0,0 +1,1039 @@
+ApplyPikachuMovementData_:: ; fd2a1 (3f:52a1)
+ ld a, b
+ ld [wPikachuMovementScriptBank], a
+ ld a, l
+ ld [wPikachuMovementScriptAddress], a
+ ld a, h
+ ld [wPikachuMovementScriptAddress + 1], a
+ call PikachuSwapSpriteStateData
+.loop
+ call LoadPikachuMovementCommandData
+ jr nc, .done
+ call ExecutePikachuMovementCommand
+ jr .loop
+
+.done
+ call PikachuSwapSpriteStateData
+ call DelayFrame
+ ret
+
+PikachuSwapSpriteStateData:
+ ld a, [wUpdateSpritesEnabled]
+ push af
+ ld a, $ff
+ ld [wUpdateSpritesEnabled], a
+ push hl
+ push de
+ push bc
+
+ ld hl, wSpriteStateData1
+ ld de, wPikachuSpriteStateData1
+ ld c, $10
+ call SwapBytes3f
+
+ ld hl, wSpriteStateData2
+ ld de, wPikachuSpriteStateData2
+ ld c, $10
+ call SwapBytes3f
+
+ pop bc
+ pop de
+ pop hl
+ pop af
+ ld [wUpdateSpritesEnabled], a
+ ret
+
+SwapBytes3f:
+.loop
+ ld b, [hl]
+ ld a, [de]
+ ld [hli], a
+ ld a, b
+ ld [de], a
+ inc de
+ dec c
+ jr nz, .loop
+ ret
+
+LoadPikachuMovementCommandData:
+ call GetPikachuMovementScriptByte
+ cp $3f
+ ret z
+ ld c, a
+ ld b, 0
+ ld hl, Data_fd3b0
+ add hl, bc
+ add hl, bc
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld [wPikaPicAnimPointer + 1], a
+ ld a, [hli]
+ cp $80
+ jr nz, .no_param
+ call GetPikachuMovementScriptByte
+.no_param
+ ld [wPikaPicAnimPointer], a
+ ld a, [hli]
+ ld [wPikaPicAnimCurGraphicID], a
+ ld a, [hli]
+ cp $80
+ jr nz, .no_param2
+ call GetPikachuMovementScriptByte
+.no_param2
+ ld [wPikaPicAnimPointerSetupFinished], a
+ xor a
+ ld [wPikaPicAnimTimer], a
+ scf
+ ret
+
+ExecutePikachuMovementCommand:
+ xor a
+ ld [wd44d], a
+ ld [wd457], a
+ ld [wd458], a
+ ld a, [wPlayerGrassPriority]
+ push af
+.loop
+ ld bc, wSpriteStateData1
+ ld a, [wPikaPicAnimPointer + 1]
+ ld hl, Jumptable_fd4ac
+ call .JumpTable
+ ld a, [wPikaPicAnimCurGraphicID]
+ ld hl, Jumptable_fd65c
+ call .JumpTable
+ call Func_fd36e
+ call Func_fd39d
+ call DelayFrame
+ call DelayFrame
+ ld hl, wd44d
+ 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]
+
+Func_fd36e:
+ ld hl, 2
+ add hl, bc
+ ld a, [wPikaPicAnimTimer + 1]
+ ld [hl], a
+ ld a, [wPikaSpriteY]
+ ld d, a
+ ld a, [wd456]
+ add d
+ ld hl, 4
+ add hl, bc
+ ld [hl], a
+ ld a, [wPikaPicAnimDelay]
+ ld d, a
+ ld a, [wPikaPicTextboxStartY]
+ add d
+ ld hl, 6
+ add hl, bc
+ ld [hl], a
+ ld hl, wd44d
+ bit 6, [hl]
+ ret z
+ ld hl, wPlayerGrassPriority - wSpriteStateData1
+ add hl, bc
+ ld [hl], 0
+ ret
+
+Func_fd39d:
+ ld hl, wd44d
+ bit 6, [hl]
+ res 6, [hl]
+ ld hl, wd736
+ res 6, [hl]
+ ret z
+ set 6, [hl]
+ call Func_fd7f3
+ ret
+
+Data_fd3b0:
+ db $01, $00, $00, $00 ; $00
+ db $03, $80, $01, $00 ; $01
+ db $04, $80, $01, $00 ; $02
+ db $05, $80, $01, $00 ; $03
+ db $06, $80, $01, $00 ; $04
+ db $07, $80, $01, $00 ; $05
+ db $08, $80, $01, $00 ; $06
+ db $09, $80, $01, $00 ; $07
+ db $0a, $80, $01, $00 ; $08
+ db $03, $80, $06, $00 ; $09
+ db $04, $80, $06, $00 ; $0a
+ db $05, $80, $06, $00 ; $0b
+ db $06, $80, $06, $00 ; $0c
+ db $07, $80, $06, $00 ; $0d
+ db $08, $80, $06, $00 ; $0e
+ db $09, $80, $06, $00 ; $0f
+ db $0a, $80, $06, $00 ; $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, $27, $02, $00 ; $1d step down
+ db $0c, $27, $02, $00 ; $1e step up
+ db $0d, $27, $02, $00 ; $1f step left
+ db $0e, $27, $02, $00 ; $20 step right
+ db $0f, $27, $02, $00 ; $21
+ db $10, $27, $02, $00 ; $22
+ db $11, $27, $02, $00 ; $23
+ db $12, $27, $02, $00 ; $24
+ db $0b, $0f, $02, $00 ; $25
+ db $0c, $0f, $02, $00 ; $26
+ db $0d, $0f, $02, $00 ; $27
+ db $0e, $0f, $02, $00 ; $28
+ db $0f, $0f, $02, $00 ; $29
+ db $10, $0f, $02, $00 ; $2a
+ db $11, $0f, $02, $00 ; $2b
+ db $12, $0f, $02, $00 ; $2c
+ db $0b, $0f, $08, $17 ; $2d
+ db $0c, $0f, $08, $17 ; $2e
+ db $0d, $0f, $08, $17 ; $2f
+ db $0e, $0f, $08, $17 ; $30
+ db $0f, $0f, $08, $17 ; $31
+ db $10, $0f, $08, $17 ; $32
+ db $11, $0f, $08, $17 ; $33
+ db $12, $0f, $08, $17 ; $34
+ db $13, $0f, $06, $00 ; $35 look down
+ db $14, $0f, $06, $00 ; $36 look up
+ db $15, $0f, $06, $00 ; $37 look left
+ db $16, $0f, $06, $00 ; $38 look right
+ db $02, $80, $04, $00 ; $39
+ db $02, $80, $05, $00 ; $3a
+ db $02, $80, $03, $80 ; $3b
+ db $02, $80, $07, $80 ; $3c
+ db $02, $80, $09, $80 ; $3d
+ db $02, $80, $06, $00 ; $3e
+
+Jumptable_fd4ac:
+ dw Func_fd4e5
+ dw Func_fd4e9
+ dw Func_fd504
+ dw Func_fd50c
+ dw Func_fd511
+ dw Func_fd518
+ dw Func_fd52c
+ dw Func_fd540
+ dw Func_fd553
+ dw Func_fd566
+ dw Func_fd579
+ dw Func_fd5b1
+ dw Func_fd5b5
+ dw Func_fd5b9
+ dw Func_fd5bd
+ dw Func_fd5c1
+ dw Func_fd5c5
+ dw Func_fd5c9
+ dw Func_fd5cd
+ dw Func_fd5ea
+ dw Func_fd5ee
+ dw Func_fd5f2
+ dw Func_fd5f6
+ dw Func_fd4e5
+
+Func_fd4dc:
+ ld a, [wd44d]
+ set 7, a
+ ld [wd44d], a
+ ret
+
+Func_fd4e5:
+ call Func_fd4dc
+ ret
+
+Func_fd4e9:
+ ld hl, 4
+ add hl, bc
+ ld a, [hl]
+ ld [wPikaSpriteY], a
+ ld hl, 6
+ add hl, bc
+ ld a, [hl]
+ ld [wPikaPicAnimDelay], a
+ xor a
+ ld [wd456], a
+ ld [wPikaPicTextboxStartY], a
+ call Func_fd4dc
+ ret
+
+Func_fd504:
+ call Func_fd775
+ ret nz
+ call Func_fd4dc
+ ret
+
+Func_fd50c:
+ call GetObjectFacing
+ jr asm_fd58c
+
+Func_fd511:
+ call GetObjectFacing
+ xor %100
+ jr asm_fd58c
+
+Func_fd518:
+ call GetObjectFacing
+ ld hl, Data_fd523
+ call Func_fd5a0
+ jr asm_fd58c
+
+Data_fd523:
+ db SPRITE_FACING_DOWN, SPRITE_FACING_RIGHT
+ db SPRITE_FACING_UP, SPRITE_FACING_LEFT
+ db SPRITE_FACING_LEFT, SPRITE_FACING_DOWN
+ db SPRITE_FACING_RIGHT, SPRITE_FACING_UP
+ db $ff
+
+Func_fd52c:
+ call GetObjectFacing
+ ld hl, Data_fd537
+ call Func_fd5a0
+ jr asm_fd58c
+
+Data_fd537:
+ db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT
+ db SPRITE_FACING_UP, SPRITE_FACING_RIGHT
+ db SPRITE_FACING_LEFT, SPRITE_FACING_UP
+ db SPRITE_FACING_RIGHT, SPRITE_FACING_DOWN
+ db $ff
+
+Func_fd540:
+ call GetObjectFacing
+ ld hl, Data_fd54b
+ call Func_fd5a0
+ jr asm_fd58c
+
+Data_fd54b:
+ db SPRITE_FACING_DOWN, SPRITE_FACING_UP | $10
+ db SPRITE_FACING_UP, SPRITE_FACING_LEFT | $10
+ db SPRITE_FACING_LEFT, SPRITE_FACING_DOWN | $10
+ db SPRITE_FACING_RIGHT, SPRITE_FACING_RIGHT | $10
+
+Func_fd553:
+ call GetObjectFacing
+ ld hl, Data_fd55e
+ call Func_fd5a0
+ jr asm_fd58c
+
+Data_fd55e:
+ db SPRITE_FACING_DOWN, SPRITE_FACING_DOWN | $10
+ db SPRITE_FACING_UP, SPRITE_FACING_RIGHT | $10
+ db SPRITE_FACING_LEFT, SPRITE_FACING_LEFT | $10
+ db SPRITE_FACING_RIGHT, SPRITE_FACING_UP | $10
+
+Func_fd566:
+ call GetObjectFacing
+ ld hl, Data_fd571
+ call Func_fd5a0
+ jr asm_fd58c
+
+Data_fd571:
+ db SPRITE_FACING_DOWN, SPRITE_FACING_RIGHT | $10
+ db SPRITE_FACING_UP, SPRITE_FACING_DOWN | $10
+ db SPRITE_FACING_LEFT, SPRITE_FACING_UP | $10
+ db SPRITE_FACING_RIGHT, SPRITE_FACING_LEFT | $10
+
+Func_fd579:
+ call GetObjectFacing
+ ld hl, Data_fd584
+ call Func_fd5a0
+ jr asm_fd58c
+
+Data_fd584:
+ db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT | $10
+ db SPRITE_FACING_UP, SPRITE_FACING_UP | $10
+ db SPRITE_FACING_LEFT, SPRITE_FACING_RIGHT | $10
+ db SPRITE_FACING_RIGHT, SPRITE_FACING_DOWN | $10
+
+asm_fd58c
+ rrca
+ rrca
+ and $7
+ ld e, a
+ call Func_fd784
+ ld d, a
+ call UpdatePikachuPosition
+ call Func_fd775
+ ret nz
+ call Func_fd4dc
+ ret
+
+Func_fd5a0:
+ push de
+ ld d, a
+.asm_fd5a2
+ ld a, [hli]
+ cp d
+ jr z, .asm_fd5ad
+ inc hl
+ cp $ff
+ jr nz, .asm_fd5a2
+ pop de
+ ret
+
+.asm_fd5ad
+ ld a, [hl]
+ pop de
+ scf
+ ret
+
+Func_fd5b1:
+ ld a, SPRITE_FACING_DOWN >> 2
+ jr asm_fd5d1
+
+Func_fd5b5:
+ ld a, SPRITE_FACING_UP >> 2
+ jr asm_fd5d1
+
+Func_fd5b9:
+ ld a, SPRITE_FACING_LEFT >> 2
+ jr asm_fd5d1
+
+Func_fd5bd:
+ ld a, SPRITE_FACING_RIGHT >> 2
+ jr asm_fd5d1
+
+Func_fd5c1:
+ ld e, 4
+ jr asm_fd5d5
+
+Func_fd5c5:
+ ld e, 5
+ jr asm_fd5d5
+
+Func_fd5c9:
+ ld e, 6
+ jr asm_fd5d5
+
+Func_fd5cd:
+ ld e, 7
+ jr asm_fd5d5
+
+asm_fd5d1
+ ld e, a
+ call SetObjectFacing
+asm_fd5d5
+ call Func_fd784
+ ld d, a
+ push de
+ call UpdatePikachuPosition
+ pop de
+ call Func_fd775
+ ret nz
+ ld a, e
+ call Func_fd7cb
+ call Func_fd4dc
+ ret
+
+Func_fd5ea:
+ ld a, SPRITE_FACING_DOWN >> 2
+ jr asm_fd5fa
+
+Func_fd5ee:
+ ld a, SPRITE_FACING_UP >> 2
+ jr asm_fd5fa
+
+Func_fd5f2:
+ ld a, SPRITE_FACING_LEFT >> 2
+ jr asm_fd5fa
+
+Func_fd5f6:
+ ld a, SPRITE_FACING_RIGHT >> 2
+ jr asm_fd5fa
+
+asm_fd5fa
+ call SetObjectFacing
+ call Func_fd4dc
+ ret
+
+UpdatePikachuPosition:
+ push de
+ ld d, 0
+ ld hl, Jumptable_fd60f
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop de
+ ld a, d
+ jp [hl]
+
+Jumptable_fd60f:
+ dw MovePikachuSpriteDown
+ dw MovePikachuSpriteUp
+ dw MovePikachuSpriteLeft
+ dw MovePikachuSpriteRight
+ dw MovePikachuSpriteDownLeft
+ dw MovePikachuSpriteDownRight
+ dw MovePikachuSpriteUpLeft
+ dw MovePikachuSpriteUpRight
+
+MovePikachuSpriteDown:
+ ld d, 0
+ ld e, a
+ jr asm_fd64d
+
+MovePikachuSpriteUp:
+ ld d, 0
+ cpl
+ inc a
+ ld e, a
+ jr asm_fd64d
+
+MovePikachuSpriteLeft:
+ cpl
+ inc a
+ ld d, a
+ ld e, 0
+ jr asm_fd64d
+
+MovePikachuSpriteRight:
+ ld d, a
+ ld e, 0
+ jr asm_fd64d
+
+MovePikachuSpriteDownLeft:
+ ld e, a
+ cpl
+ inc a
+ ld d, a
+ jr asm_fd64d
+
+MovePikachuSpriteDownRight:
+ ld e, a
+ ld d, a
+ jr asm_fd64d
+
+MovePikachuSpriteUpLeft:
+ cpl
+ inc a
+ ld e, a
+ ld d, a
+ jr asm_fd64d
+
+MovePikachuSpriteUpRight:
+ ld d, a
+ cpl
+ inc a
+ ld e, a
+ jr asm_fd64d
+
+asm_fd64d
+ ld a, [wPikaPicAnimDelay]
+ add d
+ ld [wPikaPicAnimDelay], a
+ ld a, [wPikaSpriteY]
+ add e
+ ld [wPikaSpriteY], a
+ ret
+
+Jumptable_fd65c:
+ dw Func_fd678
+ dw Func_fd6a3
+ dw Func_fd698
+ dw Func_fd6f4
+ dw Func_fd6ff
+ dw Func_fd718
+ dw Func_fd68c
+ dw Func_fd6c6
+ dw Func_fd6c0
+ dw Func_fd6e2
+ dw Func_fd68b
+
+Func_fd672:
+ ld hl, wd44d
+ set 6, [hl]
+ ret
+
+Func_fd678:
+ ld hl, 7
+ add hl, bc
+ xor a
+ ld [hli], a
+ ld [hl], a
+ call Func_fd74a
+ ld d, a
+ call GetObjectFacing
+ or d
+ ld [wPikaPicAnimTimer + 1], a
+ ret
+
+Func_fd68b:
+ ret
+
+Func_fd68c:
+ call Func_fd74a
+ ld d, a
+ call Func_fd755
+ or d
+ ld [wPikaPicAnimTimer + 1], a
+ ret
+
+Func_fd698:
+ call Func_fd74a
+ ld d, a
+ call GetObjectFacing
+ or d
+ ld d, a
+ jr asm_fd6ac
+
+Func_fd6a3:
+ call Func_fd74a
+ ld d, a
+ call Func_fd755
+ or d
+ ld d, a
+asm_fd6ac
+ ld hl, 8
+ add hl, bc
+ call Func_fd78e
+ jr nz, .asm_fd6b6
+ inc [hl]
+.asm_fd6b6
+ ld a, [hl]
+ rrca
+ rrca
+ and 3
+ or d
+ ld [wPikaPicAnimTimer + 1], a
+ ret
+
+Func_fd6c0:
+ call GetObjectFacing
+ ld d, a
+ jr asm_fd6ca
+
+Func_fd6c6:
+ call Func_fd755
+ ld d, a
+asm_fd6ca
+ call Func_fd74a
+ or d
+ ld d, a
+ call Func_fd736
+ or d
+ ld [wPikaPicAnimTimer + 1], a
+ call Func_fd79d
+ ld [wd456], a
+ and a
+ ret z
+ call Func_fd672
+ ret
+
+Func_fd6e2:
+ call GetObjectFacing
+ ld d, a
+ call Func_fd74a
+ or d
+ ld [wPikaPicAnimTimer + 1], a
+ call Func_fd79d
+ ld [wd456], a
+ ret
+
+Func_fd6f4:
+ ld a, [wPikaPicAnimPointerSetupFinished]
+ and $40
+ cp $40
+ jr z, Func_fd6ff
+ jr Func_fd718
+
+Func_fd6ff:
+ call Func_fd755
+ ld d, a
+ call Func_fd78e
+ jr nz, .asm_fd710
+ ld hl, Data_fd731
+.asm_fd70b
+ ld a, [hli]
+ cp d
+ jr nz, .asm_fd70b
+ ld d, [hl]
+.asm_fd710
+ call Func_fd74a
+ or d
+ ld [wPikaPicAnimTimer + 1], a
+ ret
+
+Func_fd718:
+ call Func_fd755
+ ld d, a
+ call Func_fd78e
+ jr nz, .asm_fd529
+ ld hl, Data_fd731End
+.asm_fd524
+ ld a, [hld]
+ cp d
+ jr nz, .asm_fd524
+ ld d, [hl]
+.asm_fd529
+ call Func_fd74a
+ or d
+ ld [wPikaPicAnimTimer + 1], 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:
+
+Func_fd736:
+ push hl
+ ld hl, 7
+ add hl, bc
+ ld a, [hl]
+ inc a
+ and $3
+ ld [hli], a
+ jr nz, .asm_fd747
+ ld a, [hl]
+ inc a
+ and $3
+ ld [hl], a
+.asm_fd747
+ ld a, [hl]
+ pop hl
+ ret
+
+Func_fd74a:
+ push hl
+ ld hl, wSpriteStateData2 - wSpriteStateData1 + 14
+ add hl, bc
+ ld a, [hl]
+ dec a
+ swap a
+ pop hl
+ ret
+
+Func_fd755:
+ push hl
+ ld hl, 2
+ add hl, bc
+ ld a, [hl]
+ and $c
+ pop hl
+ ret
+
+GetObjectFacing:
+ push hl
+ ld hl, 9
+ add hl, bc
+ ld a, [hl]
+ and $c
+ pop hl
+ ret
+
+SetObjectFacing:
+ push hl
+ ld hl, 9
+ add hl, bc
+ add a
+ add a
+ and $c
+ ld [hl], a
+ pop hl
+ ret
+
+Func_fd775:
+ ld hl, wd457
+ inc [hl]
+ ld a, [wPikaPicAnimPointer]
+ and $1f
+ inc a
+ cp [hl]
+ ret nz
+ ld [hl], 0
+ ret
+
+Func_fd784:
+ ld a, [wPikaPicAnimPointer]
+ swap a
+ rrca
+ and $3
+ inc a
+ ret
+
+Func_fd78e:
+ ld hl, wd458
+ inc [hl]
+ ld a, [wPikaPicAnimPointerSetupFinished]
+ and $f
+ inc a
+ cp [hl]
+ ret nz
+ ld [hl], 0
+ ret
+
+Func_fd79d:
+ call Func_fd7b2
+ ld a, [wd458]
+ add e
+ ld [wd458], a
+ add $20
+ ld e, a
+ push hl
+ push bc
+ call Sine_e
+ pop bc
+ pop hl
+ ret
+
+Func_fd7b2:
+ ld a, [wPikaPicAnimPointerSetupFinished]
+ and $f
+ inc a
+ ld d, a
+ ld a, [wPikaPicAnimPointerSetupFinished]
+ swap a
+ and $7
+ ld e, a
+ ld a, 1
+ jr z, .asm_fd7c9
+.asm_fd7c5
+ add a
+ dec e
+ jr nz, .asm_fd7c5
+.asm_fd7c9
+ ld e, a
+ ret
+
+Func_fd7cb:
+ push bc
+ ld c, a
+ ld b, 0
+ ld hl, Data_fd7e3
+ add hl, bc
+ add hl, bc
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ pop bc
+ ld hl, wSpriteStateData2 - wSpriteStateData1 + 4
+ add hl, bc
+ ld a, [hl]
+ add e
+ ld [hli], a
+ ld a, [hl]
+ add d
+ ld [hl], a
+ ret
+
+Data_fd7e3:
+ db 0, 1
+ db 0, -1
+ db -1, 0
+ db 1, 0
+ db -1, 1
+ db 1, 1
+ db -1, -1
+ db 1, -1
+
+Func_fd7f3:
+ push bc
+ push de
+ push hl
+
+ ld bc, wOAMBuffer + 4 * 36
+ ld a, [wPikaSpriteY]
+ ld e, a
+ ld a, [wPikaPicAnimDelay]
+ ld d, a
+ ld hl, Data_fd80b
+ call Func_fd814
+
+ pop hl
+ pop de
+ pop bc
+ ret
+
+Data_fd80b:
+ db $02
+ db $0c, $00, $ff, 0
+ db $0c, $08, $ff, 1 << OAM_X_FLIP
+
+Func_fd814:
+ ld a, e
+ add $10
+ ld e, a
+ ld a, d
+ add $8
+ ld d, a
+ ld a, [hli]
+.asm_fd81d
+ 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, .asm_fd81d
+ 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
+.asm_fd856
+ 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, .asm_fd856
+ ret
+
+GFX_fd86b:
+INCBIN "gfx/unknown_fd86b.2bpp"
+
+LoadPikachuSpriteIntoVRAM: ; fd8ab (3f:58ab)
+ 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: ; fd8d4 (3f:58d4)
+ ld a, [wCurMap]
+ cp PEWTER_POKECENTER
+ ret nz
+ call EnablePikachuFollowingPlayer
+ call StarterPikachuEmotionCommand_turnawayfromplayer
+ ret
+
+PikachuFanClubCheck: ; fd8e1 (3f:58e1)
+ ld a, [wCurMap]
+ cp POKEMON_FAN_CLUB
+ ret nz
+ call EnablePikachuFollowingPlayer
+ call StarterPikachuEmotionCommand_turnawayfromplayer
+ ret
+
+PikachuBillsHouseCheck: ; fd8ee (3f:58ee)
+ ld a, [wCurMap]
+ cp BILLS_HOUSE
+ ret nz
+ call EnablePikachuFollowingPlayer
+ ret
+
+Pikachu_LoadCurrentMapViewUpdateSpritesAndDelay3: ; fd8f8 (3f:58f8)
+ 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..e0238468
--- /dev/null
+++ b/engine/pikachu_pcm.asm
@@ -0,0 +1,154 @@
+PlayPikachuSoundClip:: ; f0000 (3c:4000)
+ 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: ; f008e (3c:408e)
+; 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
index 38045a05..226049f2 100755
--- a/engine/pikachu_pic_animation.asm
+++ b/engine/pikachu_pic_animation.asm
@@ -1,1714 +1,3 @@
-IsPlayerTalkingToPikachu:: ; fcf0c (3f:4f0c)
- 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: ; fcf20 (3f:4f20)
- 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: ; fcf35 (3f:4f35)
- 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: ; fcf54 (3f:4f54)
- dw StarterPikachuEmotionCommand_nop ; 0
- dw StarterPikachuEmotionCommand_text ; 1
- dw StarterPikachuEmotionCommand_pcm ; 2
- dw StarterPikachuEmotionCommand_emote ; 3
- dw StarterPikachuEmotionCommand_4 ; 4
- dw StarterPikachuEmotionCommand_5 ; 5
- dw StarterPikachuEmotionCommand_subcmd ; 6
- dw StarterPikachuEmotionCommand_delay ; 7
- dw StarterPikachuEmotionCommand_nop2 ; 8
- dw StarterPikachuEmotionCommand_9 ; 9
- dw StarterPikachuEmotionCommand_nop3 ; a
-
-StarterPikachuEmotionCommand_nop: ; fcf6a (3f:4f6a)
-StarterPikachuEmotionCommand_nop3: ; fcf6a (3f:4f6a)
- ret
-
-StarterPikachuEmotionCommand_text: ; fcf6b (3f:4f6b)
- 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: ; fcf77 (3f:4f77)
- ld a, [de]
- inc de
- push de
- ld e, a
- nop
- call PlayPikachuSoundClip_
- pop de
- ret
-
-PlayPikachuSoundClip_: ; fcf81 (3f:4f81)
- cp $ff
- ret z
- callab PlayPikachuSoundClip
- ret
-
-StarterPikachuEmotionCommand_emote: ; fcf8d (3f:4f8d)
- 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: ; fcfa2 (3f:4fa2)
- ld [wWhichEmotionBubble], a
- ld a, $f
- ld [wEmotionBubbleSpriteIndex], a
- predef EmotionBubble
- ret
-
-StarterPikachuEmotionCommand_4: ; fcfb0 (3f:4fb0)
- ld a, [de]
- inc de
- ld l, a
- ld a, [de]
- inc de
- ld h, a
- push de
- ld b, $3f
- call Func_fd2a1
- pop de
- ret
-
-StarterPikachuEmotionCommand_delay: ; fcfbe (3f:4fbe)
- ld a, [de]
- inc de
- push de
- ld c, a
- call DelayFrames
- pop de
- ret
-
-StarterPikachuEmotionCommand_subcmd: ; fcfc7 (3f:4fc7)
- ld a, [de]
- inc de
- push de
- ld e, a
- ld d, $0
- ld hl, Jumptable_fcfda
- add hl, de
- add hl, de
- ld a, [hli]
- ld h, [hl]
- ld l, a
- call JumpToAddress
- pop de
- ret
-
-Jumptable_fcfda:
- dw LoadPikachuSpriteIntoVRAM
- dw LoadFontTilePatterns
- dw Pikachu_LoadCurrentMapViewUpdateSpritesAndDelay3
- dw WaitForTextScrollButtonPress
- dw PikachuPewterPokecenterCheck
- dw PikachuFanClubCheck
- dw PikachuBillsHouseCheck
-
-StarterPikachuEmotionCommand_nop2: ; fcfe8 (3f:4fe8)
- ret
-
-StarterPikachuEmotionCommand_9: ; fcfe9 (3f:4fe9)
- push de
- call Func_fcff2
- call UpdateSprites
- pop de
- ret
-
-Func_fcff2: ; fcff2 (3f:4ff2)
- ld a, [wSpriteStateData1 + $9]
- xor $4
- ld [wSpriteStateData1 + $f9], a
- ret
-
-Func_fcffb: ; fcffb (3f:4ffb)
-; Inexplicably empty.
- rept 5
- nop
- endr
- ret
-
-Func_fd001:: ; fd001 (3f:5001)
- ld a, e
- jr asm_fd00f
-
-Func_fd004:: ; fd004 (3f:5004)
- call Func_fd05e
- jr c, asm_fd00f
- call GetPikaPicAnimationScriptIndex
- call Func_fcffb
-asm_fd00f: ; fd00f (3f:500f)
- ld [wExpressionNumber], a
- ld hl, PikachuEmotionTable
- call DoStarterPikachuEmotions
- ret
-
-PikachuEmotionTable: ; fd019 (3f:4019)
- dw PikachuEmotion0_fd115
- dw PikachuEmotion1_fd141
- dw PikachuEmotion2_fd116
- dw PikachuEmotion3_fd160
- dw PikachuEmotion4_fd136
- dw PikachuEmotion5_fd14d
- dw PikachuEmotion6_fd153
- dw PikachuEmotion7_fd128
- dw PikachuEmotion8_fd147
- dw PikachuEmotion9_fd166
- dw PikachuEmotion10_fd11e
- dw PikachuEmotion11_fd173
- dw PikachuEmotion12_fd17a
- dw PikachuEmotion13_fd180
- dw PikachuEmotion14_fd189
- dw PikachuEmotion15_fd191
- dw PikachuEmotion16_fd197
- dw PikachuEmotion17_fd19d
- dw PikachuEmotion18_fd1a3
- dw PikachuEmotion19_fd1a9
- dw PikachuEmotion20_fd1b1
- dw PikachuEmotion21_fd1b9
- dw PikachuEmotion22_fd1c1
- dw PikachuEmotion23_fd1c7
- dw PikachuEmotion24_fd1cf
- dw PikachuEmotion25_fd1d7
- dw PikachuEmotion26_fd1df
- dw PikachuEmotion27_fd1eb
- dw PikachuEmotion28_fd1f1
- dw PikachuEmotion29_fd1f7
- dw PikachuEmotion30_fd1fc
- dw PikachuEmotion31_fd20a
- dw PikachuEmotion32_fd213
- dw PikachuEmotion33_fd05d
-
-PikachuEmotion33_fd05d: ; fd05d (3f:505d)
- db $ff
-
-Func_fd05e: ; fd05e (3f:505e)
- ld a, [wCurMap]
- cp POKEMON_FAN_CLUB
- jr nz, .notFanClub
- ld hl, wPreventBlackout
- bit 7, [hl]
- ld a, $1d
- jr z, .asm_fd0c9
- call CheckPikachuFollowingPlayer
- ld a, $1e
- jr nz, .asm_fd0c9
- jr .asm_fd096
-.notFanClub
- ld a, [wCurMap]
- cp PEWTER_POKECENTER
- jr nz, .notPewterPokecenter
- call CheckPikachuFollowingPlayer
- ld a, $1a
- jr nz, .asm_fd0c9
- jr .asm_fd096
-.notPewterPokecenter
- callab Func_f24ae
- ld a, e
- cp $ff
- jr nz, .asm_fd0c9
- jr .asm_fd096
-.asm_fd096
- call IsPlayerPikachuAsleepInParty
- ld a, $b
- jr c, .asm_fd0c9
- callab Func_fce73 ; same bank
- ld a, $1c
- jr c, .asm_fd0c9
- ld a, [wCurMap]
- cp POKEMONTOWER_1
- jr c, .notInLavenderTower
- cp POKEMONTOWER_7 + 1
- ld a, $16
- jr c, .asm_fd0c9
-.notInLavenderTower
- ld a, [wd49c]
- and a
- jr z, .asm_fd0c7
- dec a
- ld c, a
- ld b, $0
- ld hl, Pointer_fd0cb
- add hl, bc
- ld a, [hl]
- jr .asm_fd0c9
-.asm_fd0c7
- and a
- ret
-.asm_fd0c9
- scf
- ret
-
-Pointer_fd0cb:
- db $12, $15, $17, $18, $19
-
-IsPlayerPikachuAsleepInParty:: ; fd0d0 (3f:50d0)
- 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
-
-PikachuEmotion0_fd115: ; fd115 (3f:5115)
- db $ff
-
-PikachuEmotion2_fd116: ; fd116 (3f:5116)
- pikaemotion_dummy2
- pikaemotion_emotebubble SMILE_BUBBLE
- pikaemotion_pcm PikachuCry35
- pikaemotion_5 $2
- db $ff
-
-PikachuEmotion10_fd11e: ; fd11e (3f:511e)
- pikaemotion_dummy2
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
- pikaemotion_emotebubble HEART_BUBBLE
- pikaemotion_pcm PikachuCry5
- pikaemotion_5 $a
- db $ff
-
-PikachuEmotion7_fd128: ; fd128 (3f:5128)
- pikaemotion_dummy2
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
- pikaemotion_4 Pointer_fd224
- pikaemotion_pcm PikachuCry1
- pikaemotion_4 Pointer_fd224
- pikaemotion_5 $7
- db $ff
-
-PikachuEmotion4_fd136: ; fd136 (3f:5136)
- pikaemotion_dummy2
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
- pikaemotion_4 Pointer_fd230
- pikaemotion_pcm PikachuCry29
- pikaemotion_5 $4
- db $ff
-
-PikachuEmotion1_fd141: ; fd141 (3f:5141)
- pikaemotion_dummy2
- pikaemotion_pcm
- pikaemotion_5 $1
- db $ff
-
-PikachuEmotion8_fd147: ; fd147 (3f:5147)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry39
- pikaemotion_5 $8
- db $ff
-
-PikachuEmotion5_fd14d: ; fd14d (3f:514d)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry31
- pikaemotion_5 $5
- db $ff
-
-PikachuEmotion6_fd153: ; fd153 (3f:5153)
- pikaemotion_dummy2
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
- pikaemotion_pcm
- pikaemotion_4 Pointer_fd21e
- pikaemotion_emotebubble SKULL_BUBBLE
- pikaemotion_5 $6
- db $ff
-
-PikachuEmotion3_fd160: ; fd160 (3f:5160)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry40
- pikaemotion_5 $3
- db $ff
-
-PikachuEmotion9_fd166: ; fd166 (3f:5166)
- pikaemotion_dummy2
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
- pikaemotion_pcm PikachuCry6
- pikaemotion_4 Pointer_fd218
- pikaemotion_emotebubble SKULL_BUBBLE
- pikaemotion_5 $9
- db $ff
-
-PikachuEmotion11_fd173: ; fd173 (3f:5173)
- pikaemotion_emotebubble ZZZ_BUBBLE
- pikaemotion_pcm PikachuCry37
- pikaemotion_5 $b
- db $ff
-
-PikachuEmotion12_fd17a: ; fd17a (3f:517a)
- pikaemotion_dummy2
- pikaemotion_pcm
- pikaemotion_5 $c
- db $ff
-
-PikachuEmotion13_fd180: ; fd180 (3f:5180)
- pikaemotion_dummy2
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADEXTRAPIKASPRITES
- pikaemotion_4 Pointer_fd21e
- pikaemotion_5 $d
- db $ff
-
-PikachuEmotion14_fd189: ; fd189 (3f:5189)
- pikaemotion_dummy2
- pikaemotion_emotebubble BOLT_BUBBLE
- pikaemotion_pcm PikachuCry10
- pikaemotion_5 $e
- db $ff
-
-PikachuEmotion15_fd191: ; fd191 (3f:5191)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry34
- pikaemotion_5 $f
- db $ff
-
-PikachuEmotion16_fd197: ; fd197 (3f:5197)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry33
- pikaemotion_5 $10
- db $ff
-
-PikachuEmotion17_fd19d: ; fd19d (3f:519d)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry13
- pikaemotion_5 $11
- db $ff
-
-PikachuEmotion18_fd1a3: ; fd1a3 (3f:51a3)
- pikaemotion_dummy2
- pikaemotion_pcm
- pikaemotion_5 $12
- db $ff
-
-PikachuEmotion19_fd1a9: ; fd1a9 (3f:51a9)
- pikaemotion_dummy2
- pikaemotion_emotebubble HEART_BUBBLE
- pikaemotion_pcm PikachuCry33
- pikaemotion_5 $13
- db $ff
-
-PikachuEmotion20_fd1b1: ; fd1b1 (3f:51b1)
- pikaemotion_dummy2
- pikaemotion_emotebubble HEART_BUBBLE
- pikaemotion_pcm PikachuCry5
- pikaemotion_5 $14
- db $ff
-
-PikachuEmotion21_fd1b9: ; fd1b9 (3f:51b9)
- pikaemotion_dummy2
- pikaemotion_emotebubble FISH_BUBBLE
- pikaemotion_pcm
- pikaemotion_5 $15
- db $ff
-
-PikachuEmotion22_fd1c1: ; fd1c1 (3f:51c1)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry4
- pikaemotion_5 $16
- db $ff
-
-PikachuEmotion23_fd1c7: ; fd1c7 (3f:51c7)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry19
- pikaemotion_5 $17
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
- db $ff
-
-PikachuEmotion24_fd1cf: ; fd1cf (3f:51cf)
- pikaemotion_dummy2
- pikaemotion_emotebubble EXCLAMATION_BUBBLE
- pikaemotion_pcm
- pikaemotion_5 $18
- db $ff
-
-PikachuEmotion25_fd1d7: ; fd1d7 (3f:51d7)
- pikaemotion_dummy2
- pikaemotion_emotebubble BOLT_BUBBLE
- pikaemotion_pcm PikachuCry35
- pikaemotion_5 $19
- db $ff
-
-PikachuEmotion26_fd1df: ; fd1df (3f:51df)
- pikaemotion_dummy2
- pikaemotion_emotebubble ZZZ_BUBBLE
- pikaemotion_pcm PikachuCry37
- pikaemotion_5 $1a
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_CHECKPEWTERCENTER
- db $ff
-
-PikachuEmotion27_fd1eb: ; fd1eb (3f:51eb)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry9
- pikaemotion_5 $1b
- db $ff
-
-PikachuEmotion28_fd1f1: ; fd1f1 (3f:51f1)
- pikaemotion_dummy2
- pikaemotion_pcm PikachuCry15
- pikaemotion_5 $1c
- db $ff
-
-PikachuEmotion29_fd1f7: ; fd1f7 (3f:51f7)
- pikaemotion_pcm PikachuCry5
- pikaemotion_5 $a
- db $ff
-
-PikachuEmotion30_fd1fc: ; fd1fc (3f:51fc)
- pikaemotion_9
- pikaemotion_emotebubble HEART_BUBBLE
- pikaemotion_pcm PikachuCry5
- pikaemotion_5 $14
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_LOADFONT
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_CHECKLAVENDERTOWER
- db $ff
-
-PikachuEmotion31_fd20a: ; fd20a (3f:520a)
- pikaemotion_pcm PikachuCry19
- pikaemotion_5 $17
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_SHOWMAPVIEW
- pikaemotion_subcmd PIKAEMOTION_SUBCMD_CHECKBILLSHOUSE
- db $ff
-
-PikachuEmotion32_fd213: ; fd213 (3f:5213)
- pikaemotion_pcm PikachuCry26
- pikaemotion_5 $17
- db $ff
-
-Pointer_fd218: ; fd218 (3f:5218)
-
- db $00
- db $39, $01
- db $3e, $1e
- db $3f
-
-Pointer_fd21e: ; fd21e (3f:521e)
- db $00
- db $39, $00
- db $3e, $1e
- db $3f
-
-Pointer_fd224: ; fd224 (3f:5224)
- db $00
- db $3c, $07, $2f
- db $3c, $07, $2f
- db $3f
-
-Pointer_fd22c: ; fd22c (3f:522c)
- db $3b, $1f, $03
- db $3f
-
-Pointer_fd230: ; fd230 (3f:5230)
- db $00
- db $3c, $0f, $1f
- db $3c, $0f, $1f
- db $3f
-
-Pointer_fd238: ; fd238 (3f:5238)
- db $00
- db $05, $07
- db $39, $00
- db $05, $07
- db $06, $07
- db $39, $00
- db $06, $07
- db $08, $07
- db $39, $00
- db $08, $07
- db $07, $07
- db $39, $00
- db $07, $07
- db $3f
-
-Func_fd252: ; fd252 (3f:5252)
- ld a, $40
- ld [h_0xFFFC], a
- call LoadPikachuSpriteIntoVRAM
- call Func_fd266
- and a
- jr z, .asm_fd262
- call Func_159b
-.asm_fd262
- xor a
- ld [h_0xFFFC], a
- ret
-
-Func_fd266:
- ld a, [wSpriteStateData2 + 15 * 16 + 4]
- ld e, a
- ld a, [wSpriteStateData2 + 15 * 16 + 5]
- ld d, a
- ld a, [wYCoord]
- add 4
- cp e
- jr z, .asm_fd280
- jr nc, .asm_fd27e
- ld hl, Data_fd294
- ld a, 1
- ret
-
-.asm_fd27e
- xor a
- ret
-
-.asm_fd280
- ld a, [wXCoord]
- add 4
- cp d
- jr c, .asm_fd28e
- ld hl, Data_fd299
- ld a, 2
- ret
-
-.asm_fd28e
- ld hl, Data_fd29d
- ld a, 3
- ret
-
-Data_fd294:
- db $00
- db $36
- db $2b
- db $34
- db $3f
-
-Data_fd299:
- db $00
- db $36
- db $34
- db $3f
-
-Data_fd29d:
- db $00
- db $36
- db $33
- db $3f
-
-Func_fd2a1:: ; fd2a1 (3f:52a1)
- ld a, b
- ld [wd44a], a
- ld a, l
- ld [wd44b], a
- ld a, h
- ld [wd44b + 1], a
- call PikachuSwapSpriteStateData
-.loop
- call Func_fd2f5
- jr nc, .done
- call Func_fd329
- jr .loop
-
-.done
- call PikachuSwapSpriteStateData
- call DelayFrame
- ret
-
-PikachuSwapSpriteStateData:
- ld a, [wUpdateSpritesEnabled]
- push af
- ld a, $ff
- ld [wUpdateSpritesEnabled], a
- push hl
- push de
- push bc
-
- ld hl, wSpriteStateData1
- ld de, wSpriteStateData1 + $f0
- ld c, $10
- call SwapBytes3f
-
- ld hl, wSpriteStateData2
- ld de, wSpriteStateData2 + $f0
- ld c, $10
- call SwapBytes3f
-
- pop bc
- pop de
- pop hl
- pop af
- ld [wUpdateSpritesEnabled], a
- ret
-
-SwapBytes3f:
-.loop
- ld b, [hl]
- ld a, [de]
- ld [hli], a
- ld a, b
- ld [de], a
- inc de
- dec c
- jr nz, .loop
- ret
-
-Func_fd2f5:
- call Func_157c
- cp $3f
- ret z
- ld c, a
- ld b, 0
- ld hl, Data_fd3b0
- add hl, bc
- add hl, bc
- add hl, bc
- add hl, bc
- ld a, [hli]
- ld [wPikaPicAnimPointer + 1], a
- ld a, [hli]
- cp $80
- jr nz, .asm_fd311
- call Func_157c
-.asm_fd311
- ld [wPikaPicAnimPointer], a
- ld a, [hli]
- ld [wPikaPicAnimCurGraphicID], a
- ld a, [hli]
- cp $80
- jr nz, .asm_fd320
- call Func_157c
-.asm_fd320
- ld [wPikaPicAnimPointerSetupFinished], a
- xor a
- ld [wPikaPicAnimTimer], a
- scf
- ret
-
-Func_fd329:
- xor a
- ld [$d44c], a
- ld [wd457], a
- ld [wd458], a
- ld a, [wSpriteStateData2 + 7]
- push af
-.asm_fd337
- ld bc, wSpriteStateData1
- ld a, [wPikaPicAnimPointer + 1]
- ld hl, Jumptable_fd4ac
- call Func_fd365
- ld a, [wPikaPicAnimCurGraphicID]
- ld hl, Jumptable_fd65c
- call Func_fd365
- call Func_fd36e
- call Func_fd39d
- call DelayFrame
- call DelayFrame
- ld hl, $d44c
- bit 7, [hl]
- jr z, .asm_fd337
- pop af
- ld [wSpriteStateData2 + 7], a
- scf
- ret
-
-Func_fd365:
- ld e, a
- ld d, 0
- add hl, de
- add hl, de
- ld a, [hli]
- ld h, [hl]
- ld l, a
- jp [hl]
-
-Func_fd36e:
- ld hl, 2
- add hl, bc
- ld a, [wPikaPicAnimTimer + 1]
- ld [hl], a
- ld a, [wPikaSpriteY]
- ld d, a
- ld a, [wd456]
- add d
- ld hl, 4
- add hl, bc
- ld [hl], a
- ld a, [wPikaPicAnimDelay]
- ld d, a
- ld a, [wPikaPicTextboxStartY]
- add d
- ld hl, 6
- add hl, bc
- ld [hl], a
- ld hl, $d44c
- bit 6, [hl]
- ret z
- ld hl, wSpriteStateData2 + 7 - wSpriteStateData1
- add hl, bc
- ld [hl], 0
- ret
-
-Func_fd39d:
- ld hl, $d44c
- bit 6, [hl]
- res 6, [hl]
- ld hl, wd736
- res 6, [hl]
- ret z
- set 6, [hl]
- call Func_fd7f3
- ret
-
-Data_fd3b0:
- db $01, $00, $00, $00 ; $00
- db $03, $80, $01, $00 ; $01
- db $04, $80, $01, $00 ; $02
- db $05, $80, $01, $00 ; $03
- db $06, $80, $01, $00 ; $04
- db $07, $80, $01, $00 ; $05
- db $08, $80, $01, $00 ; $06
- db $09, $80, $01, $00 ; $07
- db $0a, $80, $01, $00 ; $08
- db $03, $80, $06, $00 ; $09
- db $04, $80, $06, $00 ; $0a
- db $05, $80, $06, $00 ; $0b
- db $06, $80, $06, $00 ; $0c
- db $07, $80, $06, $00 ; $0d
- db $08, $80, $06, $00 ; $0e
- db $09, $80, $06, $00 ; $0f
- db $0a, $80, $06, $00 ; $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, $27, $02, $00 ; $1d step down
- db $0c, $27, $02, $00 ; $1e step up
- db $0d, $27, $02, $00 ; $1f step left
- db $0e, $27, $02, $00 ; $20 step right
- db $0f, $27, $02, $00 ; $21
- db $10, $27, $02, $00 ; $22
- db $11, $27, $02, $00 ; $23
- db $12, $27, $02, $00 ; $24
- db $0b, $0f, $02, $00 ; $25
- db $0c, $0f, $02, $00 ; $26
- db $0d, $0f, $02, $00 ; $27
- db $0e, $0f, $02, $00 ; $28
- db $0f, $0f, $02, $00 ; $29
- db $10, $0f, $02, $00 ; $2a
- db $11, $0f, $02, $00 ; $2b
- db $12, $0f, $02, $00 ; $2c
- db $0b, $0f, $08, $17 ; $2d
- db $0c, $0f, $08, $17 ; $2e
- db $0d, $0f, $08, $17 ; $2f
- db $0e, $0f, $08, $17 ; $30
- db $0f, $0f, $08, $17 ; $31
- db $10, $0f, $08, $17 ; $32
- db $11, $0f, $08, $17 ; $33
- db $12, $0f, $08, $17 ; $34
- db $13, $0f, $06, $00 ; $35 look down
- db $14, $0f, $06, $00 ; $36 look up
- db $15, $0f, $06, $00 ; $37 look left
- db $16, $0f, $06, $00 ; $38 look right
- db $02, $80, $04, $00 ; $39
- db $02, $80, $05, $00 ; $3a
- db $02, $80, $03, $80 ; $3b
- db $02, $80, $07, $80 ; $3c
- db $02, $80, $09, $80 ; $3d
- db $02, $80, $06, $00 ; $3e
-
-Jumptable_fd4ac:
- dw Func_fd4e5
- dw Func_fd4e9
- dw Func_fd504
- dw Func_fd50c
- dw Func_fd511
- dw Func_fd518
- dw Func_fd52c
- dw Func_fd540
- dw Func_fd553
- dw Func_fd566
- dw Func_fd579
- dw Func_fd5b1
- dw Func_fd5b5
- dw Func_fd5b9
- dw Func_fd5bd
- dw Func_fd5c1
- dw Func_fd5c5
- dw Func_fd5c9
- dw Func_fd5cd
- dw Func_fd5ea
- dw Func_fd5ee
- dw Func_fd5f2
- dw Func_fd5f6
- dw Func_fd4e5
-
-Func_fd4dc:
- ld a, [$d44c]
- set 7, a
- ld [$d44c], a
- ret
-
-Func_fd4e5:
- call Func_fd4dc
- ret
-
-Func_fd4e9:
- ld hl, 4
- add hl, bc
- ld a, [hl]
- ld [wPikaSpriteY], a
- ld hl, 6
- add hl, bc
- ld a, [hl]
- ld [wPikaPicAnimDelay], a
- xor a
- ld [wd456], a
- ld [wPikaPicTextboxStartY], a
- call Func_fd4dc
- ret
-
-Func_fd504:
- call Func_fd775
- ret nz
- call Func_fd4dc
- ret
-
-Func_fd50c:
- call GetObjectFacing
- jr asm_fd58c
-
-Func_fd511:
- call GetObjectFacing
- xor %100
- jr asm_fd58c
-
-Func_fd518:
- call GetObjectFacing
- ld hl, Data_fd523
- call Func_fd5a0
- jr asm_fd58c
-
-Data_fd523:
- db SPRITE_FACING_DOWN, SPRITE_FACING_RIGHT
- db SPRITE_FACING_UP, SPRITE_FACING_LEFT
- db SPRITE_FACING_LEFT, SPRITE_FACING_DOWN
- db SPRITE_FACING_RIGHT, SPRITE_FACING_UP
- db $ff
-
-Func_fd52c:
- call GetObjectFacing
- ld hl, Data_fd537
- call Func_fd5a0
- jr asm_fd58c
-
-Data_fd537:
- db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT
- db SPRITE_FACING_UP, SPRITE_FACING_RIGHT
- db SPRITE_FACING_LEFT, SPRITE_FACING_UP
- db SPRITE_FACING_RIGHT, SPRITE_FACING_DOWN
- db $ff
-
-Func_fd540:
- call GetObjectFacing
- ld hl, Data_fd54b
- call Func_fd5a0
- jr asm_fd58c
-
-Data_fd54b:
- db SPRITE_FACING_DOWN, SPRITE_FACING_UP | $10
- db SPRITE_FACING_UP, SPRITE_FACING_LEFT | $10
- db SPRITE_FACING_LEFT, SPRITE_FACING_DOWN | $10
- db SPRITE_FACING_RIGHT, SPRITE_FACING_RIGHT | $10
-
-Func_fd553:
- call GetObjectFacing
- ld hl, Data_fd55e
- call Func_fd5a0
- jr asm_fd58c
-
-Data_fd55e:
- db SPRITE_FACING_DOWN, SPRITE_FACING_DOWN | $10
- db SPRITE_FACING_UP, SPRITE_FACING_RIGHT | $10
- db SPRITE_FACING_LEFT, SPRITE_FACING_LEFT | $10
- db SPRITE_FACING_RIGHT, SPRITE_FACING_UP | $10
-
-Func_fd566:
- call GetObjectFacing
- ld hl, Data_fd571
- call Func_fd5a0
- jr asm_fd58c
-
-Data_fd571:
- db SPRITE_FACING_DOWN, SPRITE_FACING_RIGHT | $10
- db SPRITE_FACING_UP, SPRITE_FACING_DOWN | $10
- db SPRITE_FACING_LEFT, SPRITE_FACING_UP | $10
- db SPRITE_FACING_RIGHT, SPRITE_FACING_LEFT | $10
-
-Func_fd579:
- call GetObjectFacing
- ld hl, Data_fd584
- call Func_fd5a0
- jr asm_fd58c
-
-Data_fd584:
- db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT | $10
- db SPRITE_FACING_UP, SPRITE_FACING_UP | $10
- db SPRITE_FACING_LEFT, SPRITE_FACING_RIGHT | $10
- db SPRITE_FACING_RIGHT, SPRITE_FACING_DOWN | $10
-
-asm_fd58c
- rrca
- rrca
- and $7
- ld e, a
- call Func_fd784
- ld d, a
- call UpdatePikachuPosition
- call Func_fd775
- ret nz
- call Func_fd4dc
- ret
-
-Func_fd5a0:
- push de
- ld d, a
-.asm_fd5a2
- ld a, [hli]
- cp d
- jr z, .asm_fd5ad
- inc hl
- cp $ff
- jr nz, .asm_fd5a2
- pop de
- ret
-
-.asm_fd5ad
- ld a, [hl]
- pop de
- scf
- ret
-
-Func_fd5b1:
- ld a, SPRITE_FACING_DOWN >> 2
- jr asm_fd5d1
-
-Func_fd5b5:
- ld a, SPRITE_FACING_UP >> 2
- jr asm_fd5d1
-
-Func_fd5b9:
- ld a, SPRITE_FACING_LEFT >> 2
- jr asm_fd5d1
-
-Func_fd5bd:
- ld a, SPRITE_FACING_RIGHT >> 2
- jr asm_fd5d1
-
-Func_fd5c1:
- ld e, 4
- jr asm_fd5d5
-
-Func_fd5c5:
- ld e, 5
- jr asm_fd5d5
-
-Func_fd5c9:
- ld e, 6
- jr asm_fd5d5
-
-Func_fd5cd:
- ld e, 7
- jr asm_fd5d5
-
-asm_fd5d1
- ld e, a
- call SetObjectFacing
-asm_fd5d5
- call Func_fd784
- ld d, a
- push de
- call UpdatePikachuPosition
- pop de
- call Func_fd775
- ret nz
- ld a, e
- call Func_fd7cb
- call Func_fd4dc
- ret
-
-Func_fd5ea:
- ld a, SPRITE_FACING_DOWN >> 2
- jr asm_fd5fa
-
-Func_fd5ee:
- ld a, SPRITE_FACING_UP >> 2
- jr asm_fd5fa
-
-Func_fd5f2:
- ld a, SPRITE_FACING_LEFT >> 2
- jr asm_fd5fa
-
-Func_fd5f6:
- ld a, SPRITE_FACING_RIGHT >> 2
- jr asm_fd5fa
-
-asm_fd5fa
- call SetObjectFacing
- call Func_fd4dc
- ret
-
-UpdatePikachuPosition:
- push de
- ld d, 0
- ld hl, Jumptable_fd60f
- add hl, de
- add hl, de
- ld a, [hli]
- ld h, [hl]
- ld l, a
- pop de
- ld a, d
- jp [hl]
-
-Jumptable_fd60f:
- dw MovePikachuSpriteDown
- dw MovePikachuSpriteUp
- dw MovePikachuSpriteLeft
- dw MovePikachuSpriteRight
- dw MovePikachuSpriteDownLeft
- dw MovePikachuSpriteDownRight
- dw MovePikachuSpriteUpLeft
- dw MovePikachuSpriteUpRight
-
-MovePikachuSpriteDown:
- ld d, 0
- ld e, a
- jr asm_fd64d
-
-MovePikachuSpriteUp:
- ld d, 0
- cpl
- inc a
- ld e, a
- jr asm_fd64d
-
-MovePikachuSpriteLeft:
- cpl
- inc a
- ld d, a
- ld e, 0
- jr asm_fd64d
-
-MovePikachuSpriteRight:
- ld d, a
- ld e, 0
- jr asm_fd64d
-
-MovePikachuSpriteDownLeft:
- ld e, a
- cpl
- inc a
- ld d, a
- jr asm_fd64d
-
-MovePikachuSpriteDownRight:
- ld e, a
- ld d, a
- jr asm_fd64d
-
-MovePikachuSpriteUpLeft:
- cpl
- inc a
- ld e, a
- ld d, a
- jr asm_fd64d
-
-MovePikachuSpriteUpRight:
- ld d, a
- cpl
- inc a
- ld e, a
- jr asm_fd64d
-
-asm_fd64d
- ld a, [wPikaPicAnimDelay]
- add d
- ld [wPikaPicAnimDelay], a
- ld a, [wPikaSpriteY]
- add e
- ld [wPikaSpriteY], a
- ret
-
-Jumptable_fd65c:
- dw Func_fd678
- dw Func_fd6a3
- dw Func_fd698
- dw Func_fd6f4
- dw Func_fd6ff
- dw Func_fd718
- dw Func_fd68c
- dw Func_fd6c6
- dw Func_fd6c0
- dw Func_fd6e2
- dw Func_fd68b
-
-Func_fd672:
- ld hl, $d44c
- set 6, [hl]
- ret
-
-Func_fd678:
- ld hl, 7
- add hl, bc
- xor a
- ld [hli], a
- ld [hl], a
- call Func_fd74a
- ld d, a
- call GetObjectFacing
- or d
- ld [wPikaPicAnimTimer + 1], a
- ret
-
-Func_fd68b:
- ret
-
-Func_fd68c:
- call Func_fd74a
- ld d, a
- call Func_fd755
- or d
- ld [wPikaPicAnimTimer + 1], a
- ret
-
-Func_fd698:
- call Func_fd74a
- ld d, a
- call GetObjectFacing
- or d
- ld d, a
- jr asm_fd6ac
-
-Func_fd6a3:
- call Func_fd74a
- ld d, a
- call Func_fd755
- or d
- ld d, a
-asm_fd6ac
- ld hl, 8
- add hl, bc
- call Func_fd78e
- jr nz, .asm_fd6b6
- inc [hl]
-.asm_fd6b6
- ld a, [hl]
- rrca
- rrca
- and 3
- or d
- ld [wPikaPicAnimTimer + 1], a
- ret
-
-Func_fd6c0:
- call GetObjectFacing
- ld d, a
- jr asm_fd6ca
-
-Func_fd6c6:
- call Func_fd755
- ld d, a
-asm_fd6ca
- call Func_fd74a
- or d
- ld d, a
- call Func_fd736
- or d
- ld [wPikaPicAnimTimer + 1], a
- call Func_fd79d
- ld [wd456], a
- and a
- ret z
- call Func_fd672
- ret
-
-Func_fd6e2:
- call GetObjectFacing
- ld d, a
- call Func_fd74a
- or d
- ld [wPikaPicAnimTimer + 1], a
- call Func_fd79d
- ld [wd456], a
- ret
-
-Func_fd6f4:
- ld a, [wPikaPicAnimPointerSetupFinished]
- and $40
- cp $40
- jr z, Func_fd6ff
- jr Func_fd718
-
-Func_fd6ff:
- call Func_fd755
- ld d, a
- call Func_fd78e
- jr nz, .asm_fd710
- ld hl, Data_fd731
-.asm_fd70b
- ld a, [hli]
- cp d
- jr nz, .asm_fd70b
- ld d, [hl]
-.asm_fd710
- call Func_fd74a
- or d
- ld [wPikaPicAnimTimer + 1], a
- ret
-
-Func_fd718:
- call Func_fd755
- ld d, a
- call Func_fd78e
- jr nz, .asm_fd529
- ld hl, Data_fd731End
-.asm_fd524
- ld a, [hld]
- cp d
- jr nz, .asm_fd524
- ld d, [hl]
-.asm_fd529
- call Func_fd74a
- or d
- ld [wPikaPicAnimTimer + 1], 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:
-
-Func_fd736:
- push hl
- ld hl, 7
- add hl, bc
- ld a, [hl]
- inc a
- and $3
- ld [hli], a
- jr nz, .asm_fd747
- ld a, [hl]
- inc a
- and $3
- ld [hl], a
-.asm_fd747
- ld a, [hl]
- pop hl
- ret
-
-Func_fd74a:
- push hl
- ld hl, wSpriteStateData2 - wSpriteStateData1 + 14
- add hl, bc
- ld a, [hl]
- dec a
- swap a
- pop hl
- ret
-
-Func_fd755:
- push hl
- ld hl, 2
- add hl, bc
- ld a, [hl]
- and $c
- pop hl
- ret
-
-GetObjectFacing:
- push hl
- ld hl, 9
- add hl, bc
- ld a, [hl]
- and $c
- pop hl
- ret
-
-SetObjectFacing:
- push hl
- ld hl, 9
- add hl, bc
- add a
- add a
- and $c
- ld [hl], a
- pop hl
- ret
-
-Func_fd775:
- ld hl, wd457
- inc [hl]
- ld a, [wPikaPicAnimPointer]
- and $1f
- inc a
- cp [hl]
- ret nz
- ld [hl], 0
- ret
-
-Func_fd784:
- ld a, [wPikaPicAnimPointer]
- swap a
- rrca
- and $3
- inc a
- ret
-
-Func_fd78e:
- ld hl, wd458
- inc [hl]
- ld a, [wPikaPicAnimPointerSetupFinished]
- and $f
- inc a
- cp [hl]
- ret nz
- ld [hl], 0
- ret
-
-Func_fd79d:
- call Func_fd7b2
- ld a, [wd458]
- add e
- ld [wd458], a
- add $20
- ld e, a
- push hl
- push bc
- call Sine_e
- pop bc
- pop hl
- ret
-
-Func_fd7b2:
- ld a, [wPikaPicAnimPointerSetupFinished]
- and $f
- inc a
- ld d, a
- ld a, [wPikaPicAnimPointerSetupFinished]
- swap a
- and $7
- ld e, a
- ld a, 1
- jr z, .asm_fd7c9
-.asm_fd7c5
- add a
- dec e
- jr nz, .asm_fd7c5
-.asm_fd7c9
- ld e, a
- ret
-
-Func_fd7cb:
- push bc
- ld c, a
- ld b, 0
- ld hl, Data_fd7e3
- add hl, bc
- add hl, bc
- ld d, [hl]
- inc hl
- ld e, [hl]
- pop bc
- ld hl, wSpriteStateData2 - wSpriteStateData1 + 4
- add hl, bc
- ld a, [hl]
- add e
- ld [hli], a
- ld a, [hl]
- add d
- ld [hl], a
- ret
-
-Data_fd7e3:
- db 0, 1
- db 0, -1
- db -1, 0
- db 1, 0
- db -1, 1
- db 1, 1
- db -1, -1
- db 1, -1
-
-Func_fd7f3:
- push bc
- push de
- push hl
-
- ld bc, wOAMBuffer + 4 * 36
- ld a, [wPikaSpriteY]
- ld e, a
- ld a, [wPikaPicAnimDelay]
- ld d, a
- ld hl, Data_fd80b
- call Func_fd814
-
- pop hl
- pop de
- pop bc
- ret
-
-Data_fd80b:
- db $02
- db $0c, $00, $ff, 0
- db $0c, $08, $ff, 1 << OAM_X_FLIP
-
-Func_fd814:
- ld a, e
- add $10
- ld e, a
- ld a, d
- add $8
- ld d, a
- ld a, [hli]
-.asm_fd81d
- 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, .asm_fd81d
- 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
-.asm_fd856
- 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, .asm_fd856
- ret
-
-GFX_fd86b:
-INCBIN "gfx/unknown_fd86b.2bpp"
-
-LoadPikachuSpriteIntoVRAM: ; fd8ab (3f:58ab)
- 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: ; fd8d4 (3f:58d4)
- ld a, [wCurMap]
- cp PEWTER_POKECENTER
- ret nz
- call EnablePikachuFollowingPlayer
- call Func_fcff2
- ret
-
-PikachuFanClubCheck: ; fd8e1 (3f:58e1)
- ld a, [wCurMap]
- cp POKEMON_FAN_CLUB
- ret nz
- call EnablePikachuFollowingPlayer
- call Func_fcff2
- ret
-
-PikachuBillsHouseCheck: ; fd8ee (3f:58ee)
- ld a, [wCurMap]
- cp BILLS_HOUSE
- ret nz
- call EnablePikachuFollowingPlayer
- ret
-
-Pikachu_LoadCurrentMapViewUpdateSpritesAndDelay3: ; fd8f8 (3f:58f8)
- 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
-
GetPikaPicAnimationScriptIndex: ; fd978 (3f:5978)
ld hl, PikachuMoodLookupTable
ld a, [wPikachuMood]
@@ -1757,7 +46,7 @@ PikaPicAnimationScriptPointerLookupTable:
db $fa, $11, $11, $10, $0a, $0a
db $ff, $11, $11, $13, $14, $14
-StarterPikachuEmotionCommand_5: ; fd9d0 (3f:59d0)
+StarterPikachuEmotionCommand_pikapic: ; fd9d0 (3f:59d0)
ld a, [H_AUTOBGTRANSFERENABLED]
push af
xor a
diff --git a/engine/surfing_minigame.asm b/engine/surfing_minigame.asm
index 6a37eb10..c1533583 100755
--- a/engine/surfing_minigame.asm
+++ b/engine/surfing_minigame.asm
@@ -85,7 +85,7 @@ Func_f80a8:
ret
Func_f80ac:
- ld hl, wPreventBlackout
+ ld hl, wd492
bit 1, [hl]
ret z
ld a, [hJoyPressed]
diff --git a/home/overworld.asm b/home/overworld.asm
index 18829022..de062f46 100644
--- a/home/overworld.asm
+++ b/home/overworld.asm
@@ -70,6 +70,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
jr z, .notSimulating
ld a, [hJoyHeld]
jr .checkIfStartIsPressed
+
.notSimulating
ld a, [hJoyPressed]
.checkIfStartIsPressed
@@ -79,6 +80,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
xor a
ld [hSpriteIndexOrTextID], a ; start menu text ID
jp .displayDialogue
+
.startButtonNotPressed
bit 0, a ; A button
jp z, .checkIfDownButtonIsPressed
@@ -116,6 +118,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
xor a
ld [wLinkTimeoutCounter], a
jp EnterMap
+
; predef LoadSAV
; ld a, [wCurMap]
; ld [wDestinationMap], a
@@ -129,6 +132,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
and a
jp nz, .newBattle
jp OverworldLoop
+
.noDirectionButtonsPressed
call UpdateSprites ; 231c
ld hl, wFlags_0xcd60
@@ -146,6 +150,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
ld [wPlayerMovingDirection], a ; zero the direction
.overworldloop
jp OverworldLoop
+
.checkIfDownButtonIsPressed
ld a, [hJoyHeld] ; current joypad state
bit 7, a ; down button
@@ -154,6 +159,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
ld [wSpriteStateData1 + 3], a ; delta Y
ld a, PLAYER_DIR_DOWN
jr .handleDirectionButtonPress
+
.checkIfUpButtonIsPressed
bit 6, a ; up button
jr z, .checkIfLeftButtonIsPressed
@@ -161,6 +167,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
ld [wSpriteStateData1 + 3], a ; delta Y
ld a, PLAYER_DIR_UP
jr .handleDirectionButtonPress
+
.checkIfLeftButtonIsPressed
bit 5, a ; left button
jr z, .checkIfRightButtonIsPressed
@@ -168,6 +175,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
ld [wSpriteStateData1 + 5], a ; delta X
ld a, PLAYER_DIR_LEFT
jr .handleDirectionButtonPress
+
.checkIfRightButtonIsPressed
bit 4, a ; right button
jr z, .noDirectionButtonsPressed
@@ -199,6 +207,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
call NewBattle
jp c, .battleOccurred
jp OverworldLoop
+
.noDirectionChange
ld a, [wPlayerDirection] ; current direction
ld [wPlayerMovingDirection], a ; save direction
@@ -221,6 +230,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
pop hl
jp c, CheckWarpsCollision
jp OverworldLoop
+
.surfing
call CollisionCheckOnWater
jp c, OverworldLoop
@@ -229,6 +239,7 @@ OverworldLoopLessDelay:: ; 0245 (0:0245)
ld [wWalkCounter], a
callab Func_fcc08
jr .moveAhead2
+
.moveAhead
call IsSpinning
call UpdateSprites ; move sprites
@@ -402,6 +413,7 @@ CheckWarpsNoCollisionLoop:: ; 04d5 (0:04d5)
and D_DOWN | D_UP | D_LEFT | D_RIGHT
jr z, CheckWarpsNoCollisionRetry2 ; if directional buttons aren't being pressed, do not pass through the warp
jr WarpFound1
+
CheckWarpsNoCollisionRetry1:: ; 050f (0:050f)
inc hl
@@ -413,6 +425,7 @@ ContinueCheckWarpsNoCollisionLoop:: ; 0512 (0:0512)
dec c ; decrement number of warps
jp nz, CheckWarpsNoCollisionLoop
jp CheckMapConnections
+
; check if the player has stepped onto a warp after having collided
CheckWarpsCollision:: ; 051a (0:051a)
@@ -435,6 +448,7 @@ CheckWarpsCollision:: ; 051a (0:051a)
ld a, [hl]
ld [hWarpDestinationMap], a
jr WarpFound2
+
.retry1
inc hl
.retry2
@@ -471,10 +485,12 @@ WarpFound2:: ; 054a (0:054a)
ld [wMapPalOffset], a
call GBFadeOutToBlack
.notRockTunnel
- callab Func_fc5fa ; 3f:45fa
+ callab CalculatePikachuSpawnState1 ; 3f:45fa
call PlayMapChangeSound
jr .done
-; for maps that can have the 0xFF destination map, which means to return to the outside map; not all these maps are necessarily indoors, though
+
+; for maps that can have the 0xFF destination map, which means to return to the outside map
+; not all these maps are necessarily indoors, though
.indoorMaps
ld a, [hWarpDestinationMap] ; destination map
cp $ff
@@ -490,16 +506,18 @@ WarpFound2:: ; 054a (0:054a)
ld hl, wd732
set 3, [hl]
jr .skipMapChangeSound
+
.notWarpPad
call PlayMapChangeSound
.skipMapChangeSound
ld hl, wd736
res 0, [hl]
res 1, [hl]
- callab Func_fc65b ; 3f:465b
+ callab CalculatePikachuSpawnState2 ; 3f:465b
jr .done
+
.goBackOutside
- callab Func_fc69a ; 3f:469a
+ callab CalculatePikachuSpawnState3 ; 3f:469a
ld a, [wLastMap]
ld [wCurMap], a
call PlayMapChangeSound
@@ -548,6 +566,7 @@ CheckMapConnections:: ; 05db (0:05db)
ld a, h
ld [wCurrentTileBlockMapViewPointer + 1], a
jp .loadNewMap
+
.checkEastMap
ld b, a
ld a, [wCurrentMapWidth2] ; map width
@@ -584,6 +603,7 @@ CheckMapConnections:: ; 05db (0:05db)
ld a, h
ld [wCurrentTileBlockMapViewPointer + 1], a
jp .loadNewMap
+
.checkNorthMap
ld a, [wYCoord]
cp $ff
@@ -610,6 +630,7 @@ CheckMapConnections:: ; 05db (0:05db)
ld a, h
ld [wCurrentTileBlockMapViewPointer + 1], a
jp .loadNewMap
+
.checkSouthMap
ld b, a
ld a, [wCurrentMapHeight2]
@@ -641,7 +662,7 @@ CheckMapConnections:: ; 05db (0:05db)
ld hl, wPikachuOverworldStateFlags
set 4, [hl]
ld a, $2
- ld [wd431], a
+ ld [wPikachuSpawnState], a
call LoadMapHeader ; 0dab (0:0dab)
call PlayDefaultMusicFadeOutCurrent ; music
ld b, SET_PAL_OVERWORLD
@@ -651,6 +672,7 @@ CheckMapConnections:: ; 05db (0:05db)
call InitMapSprites
call LoadTileBlockMap
jp OverworldLoopLessDelay
+
.didNotEnterConnectedMap
jp OverworldLoop
@@ -666,6 +688,7 @@ PlayMapChangeSound:: ; 06ef (0:06ef)
jr nz, .didNotGoThroughDoor
ld a, $ad ; SFX_GO_INSIDE
jr .playSound
+
.didNotGoThroughDoor
ld a, $b5 ; SFX_GO_OUTSIDE
.playSound
@@ -713,6 +736,7 @@ ExtraWarpCheck:: ; 071a (0:071a)
.useFunction1
ld hl, IsPlayerFacingEdgeOfMap
jr .doBankswitch
+
.useFunction2
ld hl, IsWarpTileInFrontOfPlayer
.doBankswitch
@@ -779,6 +803,7 @@ Func_07c4:: ; 07c4 (0:07c4)
ret z
call PlayDefaultMusic
ret
+
LoadPlayerSpriteGraphics:: ; 07d7 (0:07d7)
; Load sprite graphics based on whether the player is standing, biking, or surfing.
@@ -1073,7 +1098,7 @@ IsSpriteInFrontOfPlayer:: ; 0983 (0:0983)
ld d, $10 ; talking range in pixels (normal range)
IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
lb bc, $3c, $40 ; Y and X position of player sprite
- ld a, [wSpriteStateData1 + 9] ; direction the player is facing
+ ld a, [wPlayerFacingDirection] ; direction the player is facing
.checkIfPlayerFacingUp
cp SPRITE_FACING_UP
jr nz, .checkIfPlayerFacingDown
@@ -1083,6 +1108,7 @@ IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
ld b, a
ld a, PLAYER_DIR_UP
jr .doneCheckingDirection
+
.checkIfPlayerFacingDown
cp SPRITE_FACING_DOWN
jr nz, .checkIfPlayerFacingRight
@@ -1092,6 +1118,7 @@ IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
ld b, a
ld a, PLAYER_DIR_DOWN
jr .doneCheckingDirection
+
.checkIfPlayerFacingRight
cp SPRITE_FACING_RIGHT
jr nz, .playerFacingLeft
@@ -1101,6 +1128,7 @@ IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
ld c, a
ld a, PLAYER_DIR_RIGHT
jr .doneCheckingDirection
+
.playerFacingLeft
; facing left
ld a, c
@@ -1140,6 +1168,7 @@ IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
jr nz, .spriteLoop
xor a
ret
+
.foundSpriteInFrontOfPlayer
pop hl
ld a, l
@@ -1157,6 +1186,7 @@ IsSpriteInFrontOfPlayer2:: ; 0985 (0:0985)
.dontwritetowd436
scf
ret
+
SignLoop:: ; 09f2 (0:09f2)
; search if a player is facing a sign
@@ -1171,6 +1201,7 @@ SignLoop:: ; 09f2 (0:09f2)
jr z, .yCoordMatched
inc hl
jr .retry
+
.yCoordMatched
ld a, [hli] ; sign X
cp e
@@ -1189,6 +1220,7 @@ SignLoop:: ; 09f2 (0:09f2)
pop hl
scf
ret
+
.retry
dec b
jr nz, .signLoop
@@ -1248,6 +1280,7 @@ CollisionCheckOnLand:: ; 0a1c (0:0a1c)
.setCarry
scf
ret
+
.noCollision
and a
ret
@@ -1300,6 +1333,7 @@ CheckForTilePairCollisions:: ; 0aa6 (0:0aa6)
.retry
inc hl
jr .tilePairCollisionLoop
+
.tilesetMatches
ld a, [wTilePlayerStandingOn] ; tile the player is on
ld b, a
@@ -1311,12 +1345,14 @@ CheckForTilePairCollisions:: ; 0aa6 (0:0aa6)
cp b
jr z, .currentTileMatchesSecondInPair
jr .retry
+
.currentTileMatchesFirstInPair
inc hl
ld a, [hl]
cp c
jr z, .foundMatch
jr .tilePairCollisionLoop
+
.currentTileMatchesSecondInPair
dec hl
ld a, [hli]
@@ -1326,6 +1362,7 @@ CheckForTilePairCollisions:: ; 0aa6 (0:0aa6)
.foundMatch
scf
ret
+
.noMatch
and a
ret
@@ -1480,6 +1517,7 @@ CopyToRedrawRowOrColumnSrcTiles:: ; 0baa (0:0baa)
dec c
jr nz, .loop
ret
+
ScheduleSouthRowRedraw:: ; 0bb6 (0:0bb6)
coord hl, 0, 16
@@ -1601,6 +1639,7 @@ JoypadOverworld:: ; 0c51 (0:0c51)
call ForceBikeDown
call AreInputsSimulated
ret
+
ForceBikeDown:: ; 0c65 (0:0c65)
ld a, [wFlags_D733]
@@ -1615,6 +1654,7 @@ ForceBikeDown:: ; 0c65 (0:0c65)
ld a, D_DOWN
ld [hJoyHeld], a ; on the cycling road, if there isn't a trainer and the player isn't pressing buttons, simulate a down press
ret
+
AreInputsSimulated:: ; 0c7b (0:0c7b)
ld a, [wd730]
@@ -1634,6 +1674,7 @@ AreInputsSimulated:: ; 0c7b (0:0c7b)
ld [hJoyPressed], a
ld [hJoyReleased], a
ret
+
; if done simulating button presses
.doneSimulating
@@ -1650,6 +1691,7 @@ AreInputsSimulated:: ; 0c7b (0:0c7b)
ld hl, wd730
res 7, [hl]
ret
+
GetSimulatedInput:: ; 0cb3 (0:0cb3)
ld hl, wSimulatedJoypadStatesIndex
@@ -1666,6 +1708,7 @@ GetSimulatedInput:: ; 0cb3 (0:0cb3)
pop de
scf
ret
+
.endofsimulatedinputs
and a
ret
@@ -1708,6 +1751,7 @@ CollisionCheckOnWater:: ; 0cca (0:0cca)
.setCarry
scf
jr .done
+
.checkIfVermilionDockTileset
ld a, [wCurMapTileset] ; tileset
cp SHIP_PORT ; Vermilion Dock tileset
@@ -1715,7 +1759,7 @@ CollisionCheckOnWater:: ; 0cca (0:0cca)
jr .stopSurfing ; if it is the boarding platform tile, stop surfing
.stopSurfing ; based game freak
ld a, $3
- ld [wd431], a
+ ld [wPikachuSpawnState], a
ld hl, wPikachuOverworldStateFlags
set 5, [hl]
xor a
@@ -1723,6 +1767,7 @@ CollisionCheckOnWater:: ; 0cca (0:0cca)
call LoadPlayerSpriteGraphics
call PlayDefaultMusic
jr .noCollision
+
.noCollision ; ...and they do the same mistake twice
and a
.done
@@ -1762,6 +1807,7 @@ LoadWalkingPlayerSpriteGraphics:: ; 0d5e (0:0d5e)
ld b, BANK(RedSprite)
ld de, RedSprite ; $4180
jr LoadPlayerSpriteGraphicsCommon
+
LoadSurfingPlayerSpriteGraphics2:: ; 0d69 (0:0d69)
ld a, [wd473]
@@ -1779,6 +1825,7 @@ LoadSurfingPlayerSpriteGraphics2:: ; 0d69 (0:0d69)
ld b, BANK(SurfingPikachuSprite)
ld de, SurfingPikachuSprite ; 3f:6def
jr LoadPlayerSpriteGraphicsCommon
+
LoadSurfingPlayerSpriteGraphics:: ; 0d83 (0:0d83)
ld b, BANK(RedSprite) ; not sure, but probably same bank (5)
@@ -1970,6 +2017,7 @@ CopySignData:: ; 0eb3 (0:0eb3)
dec a
jr nz, .signcopyloop
ret
+
; function to load map data
LoadMapData:: ; 1241 (0:1241)
@@ -2217,6 +2265,7 @@ ZeroSpriteStateData:: ; 1050 (0:1050)
dec b
jr nz, .loop
ret
+
DisableRegularSprites:: ; 1060 (0:1060)
; initialize all C100-C1FF sprite entries to disabled (other than player's and pikachu)
@@ -2229,6 +2278,7 @@ DisableRegularSprites:: ; 1060 (0:1060)
dec c
jr nz, .loop
ret
+
LoadSprite:: ; 106f (0:106f)
push hl
@@ -2259,6 +2309,7 @@ LoadSprite:: ; 106f (0:106f)
ld [hl], a
pop hl
ret
+
.trainerSprite
ld a, [hli]
@@ -2274,6 +2325,7 @@ LoadSprite:: ; 106f (0:106f)
ld [hl], a ; store trainer number in byte 1 of the entry
pop hl
ret
+
.itemBallSprite
ld a, [hli]
diff --git a/home/pikachu.asm b/home/pikachu.asm
index bd750773..f3ab9b8e 100755
--- a/home/pikachu.asm
+++ b/home/pikachu.asm
@@ -2,7 +2,7 @@ Func_1510:: ; 1510 (0:1510)
push hl
ld hl, wPikachuOverworldStateFlags
set 7, [hl]
- ld hl, wSpriteStateData1 + $f2 ; pikachu data?
+ ld hl, wPikachuSpriteImageIdx ; pikachu data?
ld [hl], $ff
pop hl
ret
@@ -25,7 +25,7 @@ Func_152d:: ; 152d (0:152d)
push hl
ld hl, wPikachuOverworldStateFlags
set 3, [hl]
- ld hl, wSpriteStateData1 + $f2 ; pikachu data?
+ ld hl, wPikachuSpriteImageIdx ; pikachu data?
ld [hl], $ff
pop hl
ret
@@ -51,42 +51,43 @@ CheckPikachuFollowingPlayer:: ; 154a (0:154a)
pop hl
ret
-Func_1552:: ; 1552 (0:1552)
+SpawnPikachu:: ; 1552 (0:1552)
ld a, [hl]
dec a
swap a
ld [hTilePlayerStandingOn], a
- homecall Func_fc6d5 ; 3f:46d5
+ homecall SpawnPikachu_ ; 3f:46d5
ret
-Func_1568:: ; 1568 (0:1568)
+Pikachu_IsInArray:: ; 1568 (0:1568)
ld b, $0
ld c, a
-.asm_156b
+.loop
inc b
ld a, [hli]
cp $ff
- jr z, .asm_1578
+ jr z, .not_in_array
cp c
- jr nz, .asm_156b
+ jr nz, .loop
dec b
dec hl
scf
ret
-.asm_1578
+
+.not_in_array
dec b
dec hl
and a
ret
-Func_157c:: ; 157c (0:157c)
+GetPikachuMovementScriptByte:: ; 157c (0:157c)
push hl
push bc
ld a, [H_LOADEDROMBANK]
push af
- ld a, [wd44a]
+ ld a, [wPikachuMovementScriptBank]
call BankswitchCommon
- ld hl, wd44b
+ ld hl, wPikachuMovementScriptAddress
ld c, [hl]
inc hl
ld b, [hl]
@@ -103,11 +104,11 @@ Func_157c:: ; 157c (0:157c)
pop hl
ret
-Func_159b:: ; 159b (0:159b)
+ApplyPikachuMovementData:: ; 159b (0:159b)
ld a, [H_LOADEDROMBANK]
ld b, a
push af
- callbs Func_fd2a1
+ callbs ApplyPikachuMovementData_
pop af
call BankswitchCommon
ret
diff --git a/main.asm b/main.asm
index cc67186d..12b1d645 100755
--- a/main.asm
+++ b/main.asm
@@ -689,7 +689,7 @@ Func_2fd6a: ; 2fd6a (b:7d6a)
callab IsThisPartymonStarterPikachu_Party
ret nc
ld a, $3
- ld [wd431], a
+ ld [wPikachuSpawnState], a
ret
INCLUDE "engine/battle/scale_sprites.asm"
@@ -1186,7 +1186,7 @@ MtMoon3Script_4a325: ; pikachu-related function?
pop af
ld [wUpdateSpritesEnabled], a
pop hl
- call Func_159b
+ call ApplyPikachuMovementData
ret
INCLUDE "data/mapHeaders/safarizonewest.asm"
diff --git a/scripts/beach_house.asm b/scripts/beach_house.asm
index fb0d78f2..d43e0977 100644
--- a/scripts/beach_house.asm
+++ b/scripts/beach_house.asm
@@ -19,7 +19,7 @@ SurfinDudeText:
call PrintText
jr .done
.next
- ld hl, wPreventBlackout
+ ld hl, wd492
bit 0, [hl]
set 0, [hl]
jr nz, .next2
@@ -36,7 +36,7 @@ SurfinDudeText:
ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
callba SurfingPikachuMinigame
- ld hl, wPreventBlackout
+ ld hl, wd492
set 1, [hl]
jr .done
.asm_f226b
@@ -133,7 +133,7 @@ BeachHouseSign4Text:
bit 6, a
jr z, .asm_f2369
- ld hl, wPreventBlackout
+ ld hl, wd492
bit 1, [hl]
jr z, .next2
ld a, 0
@@ -141,7 +141,7 @@ BeachHouseSign4Text:
.next2
ld hl, .BeachHousePrinterText2
call PrintText
- ld a, [wPreventBlackout]
+ ld a, [wd492]
bit 1, a
jr z, .asm_f236f
diff --git a/scripts/billshouse.asm b/scripts/billshouse.asm
index 5d6d668f..c93d86df 100755
--- a/scripts/billshouse.asm
+++ b/scripts/billshouse.asm
@@ -19,7 +19,7 @@ BillsHouseScriptPointers: ; 1e776 (7:6776)
dw BillsHouseScript9
BillsHouseScript_1e09e:
- ld hl, wPreventBlackout
+ ld hl, wd492
bit 7, [hl]
set 7, [hl]
ret nz
@@ -58,7 +58,7 @@ BillsHouseScript1: ; 1e783 (7:6783)
BillsHouseScript2:
ld a, $ff
ld [wJoyIgnore], a
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
and a ; cp SPRITE_FACING_DOWN
ld de, MovementData_1e79c
jr nz, .notDown
@@ -100,12 +100,12 @@ BillsHouseScript3: ; 1e7a6 (7:67a6)
call CheckPikachuFollowingPlayer
jr z, .asm_1e13e
ld hl, PikachuMovementData_1e14d
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
and a ; cp SPRITE_FACING_DOWN
jr nz, .asm_1e133
ld hl, PikachuMovementData_1e152
.asm_1e133
- call Func_159b
+ call ApplyPikachuMovementData
callab InitializePikachuTextID
.asm_1e13e
xor a
@@ -169,7 +169,7 @@ BillsHouseScript5:
ld [hSpriteFacingDirection], a
call SetSpriteFacingDirectionAndDelay
ld hl, PikachuMovementData_1e1a9
- call Func_159b
+ call ApplyPikachuMovementData
ld a, $f
ld [wEmotionBubbleSpriteIndex], a
ld a, $0
@@ -212,7 +212,7 @@ BillsHouseScript7:
xor a
ld [wPlayerMovingDirection], a
ld a, SPRITE_FACING_UP
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, $FF ^ (A_BUTTON | B_BUTTON)
ld [wJoyIgnore], a
ld de, RLE_1e219
@@ -236,7 +236,7 @@ BillsHouseScript8:
xor a
ld [wPlayerMovingDirection], a
ld a, SPRITE_FACING_UP
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, $2
ld [H_SPRITEINDEX], a
ld a, SPRITE_FACING_DOWN
diff --git a/scripts/billshouse2.asm b/scripts/billshouse2.asm
index 87a39969..2ae17ae6 100755
--- a/scripts/billshouse2.asm
+++ b/scripts/billshouse2.asm
@@ -114,7 +114,7 @@ Func_f24d5:
call UpdateSprites
call UpdateSprites
ld hl, Data_f2505
- call Func_159b
+ call ApplyPikachuMovementData
ld a, $f ; pikachu
ld [wEmotionBubbleSpriteIndex], a
ld a, $1
@@ -135,10 +135,10 @@ Data_f2505:
Func_f250b:
ld hl, Data_f251c
ld b, SPRITE_FACING_UP
- call Func_f0a82
+ call TryApplyPikachuMovementData
ld hl, Data_f2521
ld b, SPRITE_FACING_RIGHT
- call Func_f0a82
+ call TryApplyPikachuMovementData
ret
Data_f251c:
diff --git a/scripts/cinnabargym.asm b/scripts/cinnabargym.asm
index 8ae77507..4ad26a42 100755
--- a/scripts/cinnabargym.asm
+++ b/scripts/cinnabargym.asm
@@ -112,7 +112,7 @@ CinnabarGymScript_74fa3:
ld a, b
cp e
ret nz
- call Func_159b
+ call ApplyPikachuMovementData
ret
CinnabarGymScript1: ; 757dc (1d:57dc)
diff --git a/scripts/cinnabarisland.asm b/scripts/cinnabarisland.asm
index 3a2e9a2b..a6fa3af7 100755
--- a/scripts/cinnabarisland.asm
+++ b/scripts/cinnabarisland.asm
@@ -35,7 +35,7 @@ CinnabarIslandScript0: ; 1ca38 (7:4a38)
ld [wSimulatedJoypadStatesEnd], a
call StartSimulatingJoypadStates
xor a
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld [wJoyIgnore], a
ld a, $1
ld [W_CINNABARISLANDCURSCRIPT], a
diff --git a/scripts/copycatshouse2f.asm b/scripts/copycatshouse2f.asm
index 74dbb1c5..6d896ce7 100755
--- a/scripts/copycatshouse2f.asm
+++ b/scripts/copycatshouse2f.asm
@@ -82,7 +82,7 @@ CopycatsHouse2FText6: ; 5ccfe (17:4cfe)
CopycatsHouse2FText7: ; 5cd03 (17:4d03)
TX_ASM
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ld hl, CopycatsHouse2FText_5cd1c
jr nz, .notUp
diff --git a/scripts/daycarem.asm b/scripts/daycarem.asm
index b80b3dac..82622285 100755
--- a/scripts/daycarem.asm
+++ b/scripts/daycarem.asm
@@ -218,7 +218,7 @@ DayCareMText1: ; 56254 (15:6254)
.withdrewPikachuFromDayCare
ld a, $6
- ld [wd431], a
+ ld [wPikachuSpawnState], a
; GameFreak... TriHard
ld hl, Func_fc4fa
diff --git a/scripts/fanclub.asm b/scripts/fanclub.asm
index a03fd2d7..fbc6d959 100755
--- a/scripts/fanclub.asm
+++ b/scripts/fanclub.asm
@@ -10,18 +10,18 @@ FanClubScriptPointers:
dw FanClubScript2
FanClubScript1:
- ld hl, wPreventBlackout
+ ld hl, wd492
bit 7, [hl]
call z, FanClubScript_59a44
- ld hl, wPreventBlackout
+ ld hl, wd492
set 7, [hl]
ret
FanClubScript2:
- ld hl, wPreventBlackout
+ ld hl, wd492
bit 7, [hl]
call z, FanClubScript_59a39
- ld hl, wPreventBlackout
+ ld hl, wd492
set 7, [hl]
ret
@@ -50,7 +50,7 @@ FanClubScript_59a44:
ld [wEmotionBubbleSpriteIndex], a
predef EmotionBubble
ld hl, PikachuMovementScript_59a8c
- call Func_159b
+ call ApplyPikachuMovementData
ld a, $2
ld [wSpriteStateData1 + 3 * $10 + 1], a ; Seel
xor a ; SPRITE_FACING_DOWN
diff --git a/scripts/mansion1.asm b/scripts/mansion1.asm
index bbfb0a0b..c6381678 100755
--- a/scripts/mansion1.asm
+++ b/scripts/mansion1.asm
@@ -46,7 +46,7 @@ Mansion1ReplaceBlock: ; 44310 (11:4310)
ret
Mansion1Script_Switches: ; 44316 (11:4316)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
xor a
diff --git a/scripts/mansion2.asm b/scripts/mansion2.asm
index 22bc2b12..2162b3fc 100755
--- a/scripts/mansion2.asm
+++ b/scripts/mansion2.asm
@@ -42,7 +42,7 @@ Mansion2Script_5202f: ; 5202f (14:602f)
predef_jump ReplaceTileBlock
Mansion2Script_Switches: ; 52037 (14:6037)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
xor a
diff --git a/scripts/mansion3.asm b/scripts/mansion3.asm
index e49667ef..9333912d 100755
--- a/scripts/mansion3.asm
+++ b/scripts/mansion3.asm
@@ -73,7 +73,7 @@ Mansion3Script_5225b: ; 5225b (14:625b)
ret
Mansion3Script_Switches: ; 5227a (14:627a)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
xor a
diff --git a/scripts/mansion4.asm b/scripts/mansion4.asm
index 59ee3704..d3a1ded6 100755
--- a/scripts/mansion4.asm
+++ b/scripts/mansion4.asm
@@ -44,7 +44,7 @@ Mansion4Script_523cf: ; 523cf (14:63cf)
ret
Mansion4Script_Switches: ; 52420 (14:6420)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
ret nz
xor a
diff --git a/scripts/oakslab.asm b/scripts/oakslab.asm
index 43464d77..585d0ae4 100755
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -466,15 +466,15 @@ OaksLabScript16:
ret nz
xor a
.asm_1c707
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ret
OaksLabScript17:
; Pikachu comes out
ld a, SPRITE_FACING_UP
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, $2
- ld [wd431], a
+ ld [wPikachuSpawnState], a
callba Func_fc4fa
call Func_1525
ld a, $1a
diff --git a/scripts/oakslab2.asm b/scripts/oakslab2.asm
index fef72470..5e4e98a4 100755
--- a/scripts/oakslab2.asm
+++ b/scripts/oakslab2.asm
@@ -4,13 +4,13 @@ Func_f1be0:
jr z, .asm_f1bf0
ld b, SPRITE_FACING_DOWN
ld hl, Data_f1bf9
- call Func_f0a82
+ call TryApplyPikachuMovementData
ret
.asm_f1bf0
ld b, SPRITE_FACING_LEFT
ld hl, Data_f1bfe
- call Func_f0a82
+ call TryApplyPikachuMovementData
ret
Data_f1bf9:
diff --git a/scripts/pallettown.asm b/scripts/pallettown.asm
index 73f50e3e..f29eacd1 100755
--- a/scripts/pallettown.asm
+++ b/scripts/pallettown.asm
@@ -174,7 +174,7 @@ PalletTownScript5: ; 18f56 (6:4f56)
PalletTownScript6: ; 18f87 (6:4f87)
xor a
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, $1
ld [wSpriteIndex], a
xor a
diff --git a/scripts/pewtercity.asm b/scripts/pewtercity.asm
index 1e9a922a..93806878 100755
--- a/scripts/pewtercity.asm
+++ b/scripts/pewtercity.asm
@@ -1,6 +1,6 @@
PewterCityScript: ; 192f5 (6:52f5)
call EnableAutoTextBoxDrawing
- ld hl, wPreventBlackout
+ ld hl, wd492
res 7, [hl]
ld hl, PewterCityScriptPointers
ld a, [W_PEWTERCITYCURSCRIPT]
diff --git a/scripts/pewterpokecenter.asm b/scripts/pewterpokecenter.asm
index 70cf17f6..3835c0c9 100755
--- a/scripts/pewterpokecenter.asm
+++ b/scripts/pewterpokecenter.asm
@@ -1,5 +1,5 @@
PewterPokecenterScript: ; 5c587 (17:4587)
- ld hl, wPreventBlackout
+ ld hl, wd492
set 7, [hl]
call Serial_TryEstablishingExternallyClockedConnection
call EnableAutoTextBoxDrawing
diff --git a/scripts/pokemontower7.asm b/scripts/pokemontower7.asm
index abf6104d..77394447 100755
--- a/scripts/pokemontower7.asm
+++ b/scripts/pokemontower7.asm
@@ -235,7 +235,7 @@ PokemonTower7Script11:
ld [wMissableObjectIndex], a
predef HideObject
ld a, SPRITE_FACING_UP
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, LAVENDER_HOUSE_1
ld [hWarpDestinationMap], a
ld a, $1
diff --git a/scripts/redshouse1f2.asm b/scripts/redshouse1f2.asm
index 0ddd22d6..7fd98d41 100755
--- a/scripts/redshouse1f2.asm
+++ b/scripts/redshouse1f2.asm
@@ -40,7 +40,7 @@ MomHealText2: ; 481c1 (12:41c1)
Func_f1bc4:
ld hl, TVWrongSideText
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
jp nz, .notUp
ld hl, StandByMeText
diff --git a/scripts/route11gateupstairs.asm b/scripts/route11gateupstairs.asm
index e41e46e5..320f8606 100755
--- a/scripts/route11gateupstairs.asm
+++ b/scripts/route11gateupstairs.asm
@@ -47,7 +47,7 @@ Route11GateUpstairsText_494a3: ; 494a3 (12:54a3)
Route11GateUpstairsText3: ; 494a8 (12:54a8)
TX_ASM
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
jp nz, GateUpstairsScript_PrintIfFacingUp
CheckEvent EVENT_BEAT_ROUTE12_SNORLAX
diff --git a/scripts/route12gateupstairs.asm b/scripts/route12gateupstairs.asm
index e7ad5cbf..12b7b242 100755
--- a/scripts/route12gateupstairs.asm
+++ b/scripts/route12gateupstairs.asm
@@ -64,7 +64,7 @@ Route12GateUpstairsText_495c4: ; 495c4 (12:55c4)
db "@"
GateUpstairsScript_PrintIfFacingUp: ; 495c9 (12:55c9)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_UP
jr z, .up
ld a, $1
diff --git a/scripts/route22.asm b/scripts/route22.asm
index 5ea8178f..db46efa1 100755
--- a/scripts/route22.asm
+++ b/scripts/route22.asm
@@ -153,7 +153,7 @@ Route22Script2: ; 50fb5 (14:4fb5)
ld a, $1
ld [W_RIVALSTARTER], a
.asm_50fc9
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
and a ; cp SPRITE_FACING_DOWN
jr nz, .notDown
ld a, SPRITE_FACING_UP
diff --git a/scripts/route22gate.asm b/scripts/route22gate.asm
index c957e4a6..7f38db70 100755
--- a/scripts/route22gate.asm
+++ b/scripts/route22gate.asm
@@ -40,7 +40,7 @@ Route22GateScript_1e6ba: ; 1e6ba (7:66ba)
ld [wSimulatedJoypadStatesIndex], a
ld a, D_DOWN
ld [wSimulatedJoypadStatesEnd], a
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld [wJoyIgnore], a
jp StartSimulatingJoypadStates
diff --git a/scripts/route23.asm b/scripts/route23.asm
index f324963b..d26edb2e 100755
--- a/scripts/route23.asm
+++ b/scripts/route23.asm
@@ -118,7 +118,7 @@ Route23Script_512d8: ; 512d8 (14:52d8)
ld a, D_DOWN
ld [wSimulatedJoypadStatesEnd], a
xor a
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld [wJoyIgnore], a
jp StartSimulatingJoypadStates
diff --git a/scripts/route25.asm b/scripts/route25.asm
index 20dcc890..9883f056 100755
--- a/scripts/route25.asm
+++ b/scripts/route25.asm
@@ -9,7 +9,7 @@ Route25Script: ; 515cb (14:55cb)
ret
Route25Script_515e1: ; 515e1 (14:55e1)
- ld hl, wPreventBlackout
+ ld hl, wd492
res 2, [hl]
res 3, [hl]
res 4, [hl]
diff --git a/scripts/safarizoneentrance.asm b/scripts/safarizoneentrance.asm
index df80f4e1..a83944fc 100755
--- a/scripts/safarizoneentrance.asm
+++ b/scripts/safarizoneentrance.asm
@@ -26,7 +26,7 @@ SafariZoneEntranceScriptPointers: ; 751d9 (1d:51d9)
xor a
ld [hJoyHeld], a
ld a, SPRITE_FACING_RIGHT
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, [wCoordIndex]
cp $1
jr z, .asm_7520f
@@ -160,7 +160,7 @@ SafariZoneEntranceTextPointers: ; 752b9 (1d:52b9)
ld hl, .SafariZoneEntranceText_753bb
call PrintText
xor a
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, D_DOWN
ld c, $3
call SafariZoneEntranceAutoWalk
@@ -172,7 +172,7 @@ SafariZoneEntranceTextPointers: ; 752b9 (1d:52b9)
ld hl, .SafariZoneEntranceText_753c0
call PrintText
ld a, SPRITE_FACING_UP
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, D_UP
ld c, $1
call SafariZoneEntranceAutoWalk
diff --git a/scripts/vermilioncity.asm b/scripts/vermilioncity.asm
index a8fc8ce7..4e4a4959 100755
--- a/scripts/vermilioncity.asm
+++ b/scripts/vermilioncity.asm
@@ -1,6 +1,6 @@
VermilionCityScript: ; 197a1 (6:57a1)
call EnableAutoTextBoxDrawing
- ld hl, wPreventBlackout
+ ld hl, wd492
res 7, [hl]
ld hl, wd126
bit 6, [hl]
@@ -53,7 +53,7 @@ VermilionCityScriptPointers: ; 197dc (6:57dc)
dw VermilionCityScript4
VermilionCityScript0: ; 197e6 (6:57e6)
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
and a ; cp SPRITE_FACING_DOWN
jr nz, .asm_198de
ld hl, CoordsData_19823
@@ -176,7 +176,7 @@ VermilionCityText3: ; 198b1 (6:58b1)
TX_ASM
CheckEvent EVENT_SS_ANNE_LEFT
jr nz, .asm_198f6
- ld a, [wSpriteStateData1 + 9]
+ ld a, [wPlayerFacingDirection]
cp SPRITE_FACING_RIGHT
jr z, .asm_198c8
ld hl, VermilionCityCoords1
diff --git a/scripts/viridiancity.asm b/scripts/viridiancity.asm
index c20285bc..319e0106 100755
--- a/scripts/viridiancity.asm
+++ b/scripts/viridiancity.asm
@@ -54,7 +54,7 @@ ViridianCityScript_1905b:
ld a, D_DOWN
ld [wSimulatedJoypadStatesEnd], a
xor a
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld [wJoyIgnore], a
ld [hJoyHeld], a
ld a, $6
@@ -161,7 +161,7 @@ ViridianCityScript_1914d:
ld a, D_DOWN
ld [wSimulatedJoypadStatesEnd], a
xor a
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld [wJoyIgnore], a
ret
@@ -180,7 +180,7 @@ ViridianCityScript_19162:
ld [hSpriteFacingDirection], a
call SetSpriteFacingDirectionAndDelay
ld a, $8
- ld [wSpriteStateData1 + 9], a
+ ld [wPlayerFacingDirection], a
ld a, $8
ld [hSpriteIndexOrTextID], a
call DisplayTextID
diff --git a/scripts/viridiancity2.asm b/scripts/viridiancity2.asm
index 80ae3924..8e8b51db 100755
--- a/scripts/viridiancity2.asm
+++ b/scripts/viridiancity2.asm
@@ -207,7 +207,7 @@ ViridianCityText_f19fc:
Func_f1a01:
ld hl, Data_f1a0a
ld b, SPRITE_FACING_RIGHT
- call Func_f0a82
+ call TryApplyPikachuMovementData
ret
Data_f1a0a:
diff --git a/wram.asm b/wram.asm
index c5b443f3..6dd0cdba 100755
--- a/wram.asm
+++ b/wram.asm
@@ -228,7 +228,39 @@ wSpriteStateData1:: ; c100
; C1xD
; C1xE
; C1xF
- ds $10 * $10
+spritestatedata1: MACRO
+w\1SpriteStateData1::
+w\1PictureID:: db
+w\1MovementStatus:: db
+w\1SpriteImageIdx:: db
+w\1YStepVector:: db
+w\1YPixels:: db
+w\1XStepVector:: db
+w\1XPixels:: db
+w\1IntraAnimFrameCounter:: db
+w\1AnimFrameCounter:: db
+w\1FacingDirection:: db
+ ds 6
+w\1SpriteStateData1End::
+endm
+
+ spritestatedata1 Player
+ spritestatedata1 Sprite01
+ spritestatedata1 Sprite02
+ spritestatedata1 Sprite03
+ spritestatedata1 Sprite04
+ spritestatedata1 Sprite05
+ spritestatedata1 Sprite06
+ spritestatedata1 Sprite07
+ spritestatedata1 Sprite08
+ spritestatedata1 Sprite09
+ spritestatedata1 Sprite10
+ spritestatedata1 Sprite11
+ spritestatedata1 Sprite12
+ spritestatedata1 Sprite13
+ spritestatedata1 Sprite14
+ spritestatedata1 Pikachu
+ ; ds $10 * $10
;SECTION "Sprite State Data 2", WRAM0[$c200]
@@ -253,7 +285,40 @@ wSpriteStateData2:: ; c200
; C2xD
; C2xE: sprite image base offset (in video ram, player always has value 1, used to compute c1x2)
; C2xF
- ds $10 * $10
+spritestatedata2: MACRO
+w\1SpriteStateData2::
+w\1WalkAnimationCounter:: db
+ ds 1
+w\1YDisplacement:: db
+w\1XDisplacement:: db
+w\1MapY:: db
+w\1MapX:: db
+w\1MovementByte1:: db
+w\1GrassPriority:: db
+w\1MovementDelay:: db
+ ds 5
+w\1SpriteImageBaseOffset:: db
+ ds 1
+w\1SpriteStateData2End::
+endm
+
+ spritestatedata2 Player
+ spritestatedata2 Sprite01
+ spritestatedata2 Sprite02
+ spritestatedata2 Sprite03
+ spritestatedata2 Sprite04
+ spritestatedata2 Sprite05
+ spritestatedata2 Sprite06
+ spritestatedata2 Sprite07
+ spritestatedata2 Sprite08
+ spritestatedata2 Sprite09
+ spritestatedata2 Sprite10
+ spritestatedata2 Sprite11
+ spritestatedata2 Sprite12
+ spritestatedata2 Sprite13
+ spritestatedata2 Sprite14
+ spritestatedata2 Pikachu
+ ; ds $10 * $10
wSpriteDataEnd::
@@ -2735,7 +2800,7 @@ wDestinationWarpID:: ; d42f
ds 1
wPikachuOverworldStateFlags:: ds 1 ; d42f
-wd431:: ds 1 ; d430
+wPikachuSpawnState:: ds 1 ; d430
wd432:: ds 1 ; d431
wd433:: ds 1 ; d432
wd434:: ds 1
@@ -2749,11 +2814,12 @@ wExpressionNumber:: ; d447
wExpressionNumber2::
ds 1
-wd44a:: ds 1 ; d449
-wd44b:: ds 1
-wd44c:: ds 1
-wd44d:: ds 1
-wPikaPicAnimPointer:: dw ; d44d
+wPikachuMovementScriptBank:: ds 1 ; d449
+wPikachuMovementScriptAddress:: dw ; d44a
+wd44d:: ds 1 ; d44c
+
+wCurPikaMovementData:: ;
+wPikaPicAnimPointer:: dw ; d44d
wPikaPicAnimPointerSetupFinished:: ds 1 ; d44f
wPikaPicAnimCurGraphicID:: ds 1
wPikaPicAnimTimer:: ds 2 ; d451
@@ -2785,7 +2851,7 @@ wd47a:: ds 1
ds 24
-wPreventBlackout:: ds 1 ; d492
+wd492:: ds 1 ; d492
ds 1