Skip to content

Commit

Permalink
Identify wSavedCoordIndex and its other usages
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Nov 20, 2023
1 parent b066d3c commit 77887be
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 54 deletions.
4 changes: 2 additions & 2 deletions engine/gfx/sprite_oam.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PrepareOAMData::
inc e
inc e
ld a, [de] ; [x#SPRITESTATEDATA1_IMAGEINDEX]
ld [wSpriteImageIndexBackup], a
ld [wSavedSpriteImageIndex], a
cp $ff ; off-screen (don't draw)
jr nz, .visible

Expand Down Expand Up @@ -98,7 +98,7 @@ PrepareOAMData::
push bc
ld b, a

ld a, [wSpriteImageIndexBackup]
ld a, [wSavedSpriteImageIndex]
swap a ; high nybble determines sprite used (0 is always player sprite, next are some npcs)
and $f

Expand Down
2 changes: 1 addition & 1 deletion engine/items/item_effects.asm
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ ItemUseSurfboard:
ld a, b
ld [wSimulatedJoypadStatesEnd], a
xor a
ld [wWastedByteCD39], a
ld [wUnusedCD39], a
inc a
ld [wSimulatedJoypadStatesIndex], a
ret
Expand Down
2 changes: 1 addition & 1 deletion engine/menus/pokedex.asm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ShowPokedexMenu:
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ldh [hJoy7], a
ld [wWastedByteCD3A], a
ld [wUnusedCD3A], a
ld [wOverrideSimulatedJoypadStatesMask], a
pop af
ld [wListScrollOffset], a
Expand Down
4 changes: 2 additions & 2 deletions engine/overworld/auto_movement.asm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PlayerStepOutFromDoor::
ret
.notStandingOnDoor
xor a
ld [wWastedByteCD3A], a
ld [wUnusedCD3A], a
ld [wSimulatedJoypadStatesIndex], a
ld [wSimulatedJoypadStatesEnd], a
ld hl, wd736
Expand All @@ -39,7 +39,7 @@ _EndNPCMovementScript::
ld [wNPCMovementScriptSpriteOffset], a
ld [wNPCMovementScriptPointerTableNum], a
ld [wNPCMovementScriptFunctionNum], a
ld [wWastedByteCD3A], a
ld [wUnusedCD3A], a
ld [wSimulatedJoypadStatesIndex], a
ld [wSimulatedJoypadStatesEnd], a
ret
Expand Down
2 changes: 1 addition & 1 deletion engine/overworld/movement.asm
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ UpdateNPCSprite:
res 0, [hl]
xor a
ld [wSimulatedJoypadStatesIndex], a
ld [wWastedByteCD3A], a
ld [wUnusedCD3A], a
ret
.next
cp WALK
Expand Down
2 changes: 1 addition & 1 deletion home/overworld.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ JoypadOverworld::
; if done simulating button presses
.doneSimulating
xor a
ld [wWastedByteCD3A], a
ld [wUnusedCD3A], a
ld [wSimulatedJoypadStatesIndex], a
ld [wSimulatedJoypadStatesEnd], a
ld [wJoyIgnore], a
Expand Down
2 changes: 1 addition & 1 deletion home/pathfinding.asm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MoveSprite_::
ld [wSimulatedJoypadStatesEnd], a
dec a
ld [wJoyIgnore], a
ld [wWastedByteCD3A], a
ld [wUnusedCD3A], a
ret

; divides [hDividend2] by [hDivisor2] and stores the quotient in [hQuotient2]
Expand Down
13 changes: 8 additions & 5 deletions ram/wram.asm
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,10 @@ wFilteredBagItemsCount:: db
wSimulatedJoypadStatesIndex:: db

; written to but nothing ever reads it
wWastedByteCD39:: db
wUnusedCD39:: db

; written to but nothing ever reads it
wWastedByteCD3A:: db
wUnusedCD3A:: db

; mask indicating which real button presses can override simulated ones
; XXX is it ever not 0?
Expand Down Expand Up @@ -979,7 +979,10 @@ wBattleResult:: db
; bit 0: if set, DisplayTextID automatically draws a text box
wAutoTextBoxDrawingControl:: db

wcf0d:: db ; used with some overworld scripts (not exactly sure what it's used for)
; used in some overworld scripts to vary scripted movement
wSavedCoordIndex::
wOakWalkedToPlayer::
wNextSafariZoneGateScript:: db

; used in CheckForTilePairCollisions2 to store the tile the player is on
wTilePlayerStandingOn:: db
Expand Down Expand Up @@ -1913,8 +1916,8 @@ wMissableObjectFlagsEnd::

ds 7

; temp copy of SPRITESTATEDATA1_IMAGEINDEX (used for sprite facing/anim)
wSpriteImageIndexBackup:: db
; saved copy of SPRITESTATEDATA1_IMAGEINDEX (used for sprite facing/anim)
wSavedSpriteImageIndex:: db

; each entry consists of 2 bytes
; * the sprite ID (depending on the current map)
Expand Down
10 changes: 5 additions & 5 deletions scripts/FightingDojo.asm
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ FightingDojoDefaultScript:
ret nz
xor a
ldh [hJoyHeld], a
ld [wcf0d], a
ld [wSavedCoordIndex], a
ld a, [wYCoord]
cp 3
ret nz
ld a, [wXCoord]
cp 4
ret nz
ld a, $1
ld [wcf0d], a
ld a, 1
ld [wSavedCoordIndex], a
ld a, PLAYER_DIR_RIGHT
ld [wPlayerMovingDirection], a
ld a, FIGHTINGDOJO_KARATE_MASTER
Expand All @@ -57,8 +57,8 @@ FightingDojoKarateMasterPostBattleScript:
ld a, [wIsInBattle]
cp $ff
jp z, FightingDojoResetScripts
ld a, [wcf0d]
and a
ld a, [wSavedCoordIndex]
and a ; nz if the player was at (4, 3), left of the Karate Master
jr z, .already_facing
ld a, PLAYER_DIR_RIGHT
ld [wPlayerMovingDirection], a
Expand Down
8 changes: 4 additions & 4 deletions scripts/PalletTown.asm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ PalletTownDefaultScript:

PalletTownOakHeyWaitScript:
xor a
ld [wcf0d], a
ld [wOakWalkedToPlayer], a
ld a, TEXT_PALLETTOWN_OAK
ldh [hSpriteIndexOrTextID], a
call DisplayTextID
Expand Down Expand Up @@ -96,8 +96,8 @@ PalletTownOakNotSafeComeWithMeScript:
ret nz
xor a ; ld a, SPRITE_FACING_DOWN
ld [wSpritePlayerStateData1FacingDirection], a
ld a, 1
ld [wcf0d], a
ld a, TRUE
ld [wOakWalkedToPlayer], a
ld a, SELECT | START | D_RIGHT | D_LEFT | D_UP | D_DOWN
ld [wJoyIgnore], a
ld a, TEXT_PALLETTOWN_OAK
Expand Down Expand Up @@ -161,7 +161,7 @@ PalletTown_TextPointers:

PalletTownOakText:
text_asm
ld a, [wcf0d]
ld a, [wOakWalkedToPlayer]
and a
jr nz, .next
ld a, 1
Expand Down
24 changes: 12 additions & 12 deletions scripts/Route22.asm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Route22GetRivalTrainerNoByStarterScript:

Route22MoveRivalRightScript:
ld de, Route22RivalMovementData
ld a, [wcf0d]
ld a, [wSavedCoordIndex]
cp $1
jr z, .skip_first_right
inc de
Expand All @@ -62,7 +62,7 @@ Route22DefaultScript:
call ArePlayerCoordsInArray
ret nc
ld a, [wCoordIndex]
ld [wcf0d], a
ld [wSavedCoordIndex], a
xor a
ldh [hJoyHeld], a
ld a, D_RIGHT | D_LEFT | D_UP | D_DOWN
Expand Down Expand Up @@ -107,8 +107,8 @@ Route22Rival1StartBattleScript:
ld a, [wd730]
bit 0, a
ret nz
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, lower entry in Route22DefaultScript.Route22RivalBattleCoords
jr nz, .set_rival_facing_right
ld a, PLAYER_DIR_DOWN
ld [wPlayerMovingDirection], a
Expand Down Expand Up @@ -172,8 +172,8 @@ Route22Rival1AfterBattleScript:
ld [wNewSoundID], a
call PlaySound
farcall Music_RivalAlternateStart
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, lower entry in Route22DefaultScript.Route22RivalBattleCoords
jr nz, .exit_movement_2
call .RivalExit1Script
jr .next_script
Expand Down Expand Up @@ -263,8 +263,8 @@ Route22Rival2StartBattleScript:
ret nz
ld a, ROUTE22_RIVAL2
ldh [hSpriteIndex], a
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, lower entry in Route22DefaultScript.Route22RivalBattleCoords
jr nz, .set_player_direction_left
ld a, PLAYER_DIR_DOWN
ld [wPlayerMovingDirection], a
Expand Down Expand Up @@ -307,8 +307,8 @@ Route22Rival2AfterBattleScript:
jp z, Route22SetDefaultScript
ld a, ROUTE22_RIVAL2
ldh [hSpriteIndex], a
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, lower entry in Route22DefaultScript.Route22RivalBattleCoords
jr nz, .set_player_direction_left
ld a, PLAYER_DIR_DOWN
ld [wPlayerMovingDirection], a
Expand All @@ -331,8 +331,8 @@ Route22Rival2AfterBattleScript:
ld [wNewSoundID], a
call PlaySound
farcall Music_RivalAlternateStartAndTempo
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, lower entry in Route22DefaultScript.Route22RivalBattleCoords
jr nz, .exit_movement_2
call .RivalExit1Script
jr .next_script
Expand Down
18 changes: 9 additions & 9 deletions scripts/SafariZoneGate.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ SafariZoneGateDefaultScript:
ld a, SPRITE_FACING_RIGHT
ld [wSpritePlayerStateData1FacingDirection], a
ld a, [wCoordIndex]
cp $1
cp 1 ; index of second, lower entry in .PlayerNextToSafariZoneWorker1CoordsArray
jr z, .player_not_next_to_worker
ld a, SCRIPT_SAFARIZONEGATE_WOULD_YOU_LIKE_TO_JOIN
ld [wSafariZoneGateCurScript], a
ret
.player_not_next_to_worker
ld a, D_RIGHT
ld c, $1
ld c, 1
call SafariZoneEntranceAutoWalk
ld a, D_RIGHT | D_LEFT | D_UP | D_DOWN
ld [wJoyIgnore], a
Expand Down Expand Up @@ -88,7 +88,7 @@ SafariZoneGateLeavingSafariScript:
xor a
ld [wNumSafariBalls], a
ld a, D_DOWN
ld c, $3
ld c, 3
call SafariZoneEntranceAutoWalk
ld a, SCRIPT_SAFARIZONEGATE_PLAYER_MOVING_DOWN
ld [wSafariZoneGateCurScript], a
Expand All @@ -113,7 +113,7 @@ SafariZoneGateSetScriptAfterMoveScript:
call SafariZoneGateReturnSimulatedJoypadStateScript
ret nz
call Delay3
ld a, [wcf0d]
ld a, [wNextSafariZoneGateScript]
ld [wSafariZoneGateCurScript], a
ret

Expand Down Expand Up @@ -236,22 +236,22 @@ SafariZoneGateSafariZoneWorker1LeavingEarlyText:
xor a
ld [wSpritePlayerStateData1FacingDirection], a
ld a, D_DOWN
ld c, $3
ld c, 3
call SafariZoneEntranceAutoWalk
ResetEvents EVENT_SAFARI_GAME_OVER, EVENT_IN_SAFARI_ZONE
ld a, $0
ld [wcf0d], a
ld a, SCRIPT_SAFARIZONEGATE_DEFAULT
ld [wNextSafariZoneGateScript], a
jr .set_current_script
.not_ready_to_leave
ld hl, .GoodLuckText
call PrintText
ld a, SPRITE_FACING_UP
ld [wSpritePlayerStateData1FacingDirection], a
ld a, D_UP
ld c, $1
ld c, 1
call SafariZoneEntranceAutoWalk
ld a, SCRIPT_SAFARIZONEGATE_LEAVING_SAFARI
ld [wcf0d], a
ld [wNextSafariZoneGateScript], a
.set_current_script
ld a, SCRIPT_SAFARIZONEGATE_SET_SCRIPT_AFTER_MOVE
ld [wSafariZoneGateCurScript], a
Expand Down
10 changes: 5 additions & 5 deletions scripts/SilphCo11F.asm
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ SilphCo11FDefaultScript:
call ArePlayerCoordsInArray
jp nc, CheckFightingMapTrainers
ld a, [wCoordIndex]
ld [wcf0d], a
ld [wSavedCoordIndex], a
xor a
ldh [hJoyHeld], a
ld a, D_RIGHT | D_LEFT | D_UP | D_DOWN
Expand Down Expand Up @@ -209,8 +209,8 @@ SilphCo11FGiovanniAfterBattleScript:
ld a, [wIsInBattle]
cp $ff
jp z, SilphCo11FResetCurScript
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, upper-right entry in SilphCo11FDefaultScript.PlayerCoordsArray
jr z, .face_player_up
ld a, PLAYER_DIR_LEFT
ld b, SPRITE_FACING_RIGHT
Expand Down Expand Up @@ -242,8 +242,8 @@ SilphCo11FGiovanniBattleFacingScript:
ld a, SILPHCO11F_GIOVANNI
ldh [hSpriteIndex], a
call SetSpriteMovementBytesToFF
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, upper-right entry in SilphCo11FDefaultScript.PlayerCoordsArray
jr z, .face_player_up
ld a, PLAYER_DIR_LEFT
ld b, SPRITE_FACING_RIGHT
Expand Down
8 changes: 4 additions & 4 deletions scripts/SilphCo7F.asm
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ SilphCo7FDefaultScript:
call SetSpriteMovementBytesToFF
ld de, .RivalMovementUp
ld a, [wCoordIndex]
ld [wcf0d], a
cp $1
ld [wSavedCoordIndex], a
cp 1 ; index of second, lower entry in .RivalEncounterCoordinates
jr z, .full_rival_movement
inc de
.full_rival_movement
Expand Down Expand Up @@ -225,8 +225,8 @@ SilphCo7FRivalAfterBattleScript:
call PlaySound
farcall Music_RivalAlternateStart
ld de, .RivalWalkAroundPlayerMovement
ld a, [wcf0d]
cp $1
ld a, [wSavedCoordIndex]
cp 1 ; index of second, lower entry in SilphCo7FDefaultScript.RivalEncounterCoordinates
jr nz, .walk_around_player
ld de, .RivalExitRightMovement
.walk_around_player
Expand Down
2 changes: 1 addition & 1 deletion scripts/VermilionCity.asm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ VermilionCityDefaultScript:
ret nc
xor a
ldh [hJoyHeld], a
ld [wcf0d], a
ld [wSavedCoordIndex], a ; unnecessary
ld a, TEXT_VERMILIONCITY_SAILOR1
ldh [hSpriteIndexOrTextID], a
call DisplayTextID
Expand Down

0 comments on commit 77887be

Please sign in to comment.