summaryrefslogtreecommitdiff
path: root/engine/overworld
diff options
context:
space:
mode:
Diffstat (limited to 'engine/overworld')
-rwxr-xr-xengine/overworld/auto_movement.asm6
-rw-r--r--engine/overworld/clear_variables.asm12
-rwxr-xr-xengine/overworld/cut.asm34
-rwxr-xr-xengine/overworld/cut2.asm8
-rwxr-xr-xengine/overworld/doors.asm2
-rwxr-xr-xengine/overworld/dust_smoke.asm14
-rwxr-xr-xengine/overworld/elevator.asm8
-rwxr-xr-xengine/overworld/emotion_bubbles.asm4
-rwxr-xr-xengine/overworld/healing_machine.asm14
-rwxr-xr-xengine/overworld/hidden_objects.asm6
-rwxr-xr-xengine/overworld/ledges.asm6
-rwxr-xr-xengine/overworld/map_sprites.asm74
-rw-r--r--engine/overworld/missable_objects.asm16
-rw-r--r--engine/overworld/movement.asm329
-rw-r--r--engine/overworld/pathfinding.asm62
-rwxr-xr-xengine/overworld/player_animations.asm44
-rw-r--r--engine/overworld/player_state.asm58
-rw-r--r--engine/overworld/push_boulder.asm14
-rw-r--r--engine/overworld/special_warps.asm4
-rw-r--r--engine/overworld/sprite_collisions.asm126
-rw-r--r--engine/overworld/tilesets.asm6
-rwxr-xr-xengine/overworld/trainer_sight.asm84
-rwxr-xr-xengine/overworld/turn_sprite.asm22
-rw-r--r--engine/overworld/update_map.asm24
24 files changed, 493 insertions, 484 deletions
diff --git a/engine/overworld/auto_movement.asm b/engine/overworld/auto_movement.asm
index 5e70ab8c..9a717641 100755
--- a/engine/overworld/auto_movement.asm
+++ b/engine/overworld/auto_movement.asm
@@ -66,7 +66,7 @@ PalletMovementScript_OakMoveLeft:
call FillMemory
ld [hl], $ff
ld a, [wSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
ld de, wNPCMovementDirections2
call MoveSprite
ld a, $1
@@ -91,7 +91,7 @@ PalletMovementScript_PlayerMoveLeft:
ret nz ; return if Oak is still moving
ld a, [wNumStepsToTake]
ld [wSimulatedJoypadStatesIndex], a
- ld [hNPCMovementDirections2Index], a
+ ldh [hNPCMovementDirections2Index], a
predef ConvertNPCMovementDirectionsToJoypadMasks
call StartSimulatingJoypadStates
ld a, $2
@@ -282,7 +282,7 @@ FreezeEnemyTrainerSprite::
jr .loop
.notRival
ld a, [wSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
jp SetSpriteMovementBytesToFF
RivalIDs:
diff --git a/engine/overworld/clear_variables.asm b/engine/overworld/clear_variables.asm
index 9b735495..bbb7c986 100644
--- a/engine/overworld/clear_variables.asm
+++ b/engine/overworld/clear_variables.asm
@@ -1,14 +1,14 @@
ClearVariablesOnEnterMap::
ld a, SCREEN_HEIGHT_PX
- ld [hWY], a
- ld [rWY], a
+ ldh [hWY], a
+ ldh [rWY], a
xor a
- ld [hAutoBGTransferEnabled], a
+ ldh [hAutoBGTransferEnabled], a
ld [wStepCounter], a
ld [wLoneAttackNo], a
- ld [hJoyPressed], a
- ld [hJoyReleased], a
- ld [hJoyHeld], a
+ ldh [hJoyPressed], a
+ ldh [hJoyReleased], a
+ ldh [hJoyHeld], a
ld [wActionResultOrTookBattleTurn], a
ld [wUnusedD5A3], a
ld hl, wCardKeyDoorY
diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm
index f99bf323..07039e03 100755
--- a/engine/overworld/cut.asm
+++ b/engine/overworld/cut.asm
@@ -38,14 +38,14 @@ UsedCut:
call ClearSprites
call RestoreScreenTilesAndReloadTilePatterns
ld a, SCREEN_HEIGHT_PX
- ld [hWY], a
+ ldh [hWY], a
call Delay3
call LoadGBPal
call LoadCurrentMapView
call SaveScreenTilesToBuffer2
call Delay3
xor a
- ld [hWY], a
+ ldh [hWY], a
ld hl, UsedCutText
call PrintText
call LoadScreenTilesFromBuffer2
@@ -57,13 +57,13 @@ UsedCut:
ld de, CutTreeBlockSwaps
call ReplaceTreeTileBlock
call RedrawMapView
- callba AnimCut
+ farcall AnimCut
ld a, $1
ld [wUpdateSpritesEnabled], a
ld a, SFX_CUT
call PlaySound
ld a, $90
- ld [hWY], a
+ ldh [hWY], a
call UpdateSprites
jp RedrawMapView
@@ -75,28 +75,28 @@ InitCutAnimOAM:
xor a
ld [wWhichAnimationOffsets], a
ld a, %11100100
- ld [rOBP1], a
+ ldh [rOBP1], a
ld a, [wCutTile]
cp $52
jr z, .grass
; tree
- ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row
- ld hl, vChars1 + $7c0
- lb bc, BANK(Overworld_GFX), $02
+ ld de, Overworld_GFX tile $2d ; cuttable tree sprite top row
+ ld hl, vChars1 tile $7c
+ lb bc, BANK(Overworld_GFX), 2
call CopyVideoData
- ld de, Overworld_GFX + $3d0 ; cuttable tree sprite bottom row
- ld hl, vChars1 + $7e0
- lb bc, BANK(Overworld_GFX), $02
+ ld de, Overworld_GFX tile $3d ; cuttable tree sprite bottom row
+ ld hl, vChars1 tile $7e
+ lb bc, BANK(Overworld_GFX), 2
call CopyVideoData
jr WriteCutOrBoulderDustAnimationOAMBlock
.grass
- ld hl, vChars1 + $7c0
+ ld hl, vChars1 tile $7c
call LoadCutGrassAnimationTilePattern
- ld hl, vChars1 + $7d0
+ ld hl, vChars1 tile $7d
call LoadCutGrassAnimationTilePattern
- ld hl, vChars1 + $7e0
+ ld hl, vChars1 tile $7e
call LoadCutGrassAnimationTilePattern
- ld hl, vChars1 + $7f0
+ ld hl, vChars1 tile $7f
call LoadCutGrassAnimationTilePattern
call WriteCutOrBoulderDustAnimationOAMBlock
ld hl, wOAMBuffer + $93
@@ -112,8 +112,8 @@ InitCutAnimOAM:
ret
LoadCutGrassAnimationTilePattern:
- ld de, AnimationTileset2 + $60 ; tile depicting a leaf
- lb bc, BANK(AnimationTileset2), $01
+ ld de, AnimationTileset2 tile 6 ; tile depicting a leaf
+ lb bc, BANK(AnimationTileset2), 1
jp CopyVideoData
WriteCutOrBoulderDustAnimationOAMBlock:
diff --git a/engine/overworld/cut2.asm b/engine/overworld/cut2.asm
index f16fed66..3d4a5905 100755
--- a/engine/overworld/cut2.asm
+++ b/engine/overworld/cut2.asm
@@ -15,9 +15,9 @@ AnimCut:
ld [wCoordAdjustmentAmount], a
ld c, 2
call AdjustOAMBlockXPos2
- ld a, [rOBP1]
+ ldh a, [rOBP1]
xor $64
- ld [rOBP1], a
+ ldh [rOBP1], a
call DelayFrame
pop bc
dec c
@@ -65,9 +65,9 @@ AnimCutGrass_UpdateOAMEntries:
ld [wCoordAdjustmentAmount], a
ld c, 1
call AdjustOAMBlockXPos2
- ld a, [rOBP1]
+ ldh a, [rOBP1]
xor $64
- ld [rOBP1], a
+ ldh [rOBP1], a
call DelayFrame
pop bc
dec c
diff --git a/engine/overworld/doors.asm b/engine/overworld/doors.asm
index ed893773..d38818fa 100755
--- a/engine/overworld/doors.asm
+++ b/engine/overworld/doors.asm
@@ -11,7 +11,7 @@ IsPlayerStandingOnDoorTile:
ld a, [hli]
ld h, [hl]
ld l, a
- aCoord 8, 9 ; a = lower left background tile under player's sprite
+ lda_coord 8, 9 ; a = lower left background tile under player's sprite
ld b, a
.loop
ld a, [hli]
diff --git a/engine/overworld/dust_smoke.asm b/engine/overworld/dust_smoke.asm
index 2dc6882e..a20a0591 100755
--- a/engine/overworld/dust_smoke.asm
+++ b/engine/overworld/dust_smoke.asm
@@ -6,9 +6,9 @@ AnimateBoulderDust:
ld a, $ff
ld [wUpdateSpritesEnabled], a
ld a, %11100100
- ld [rOBP1], a
+ ldh [rOBP1], a
call LoadSmokeTileFourTimes
- callba WriteCutOrBoulderDustAnimationOAMBlock
+ farcall WriteCutOrBoulderDustAnimationOAMBlock
ld c, 8 ; number of steps in animation
.loop
push bc
@@ -18,9 +18,9 @@ AnimateBoulderDust:
ld c, 4
jp hl
.returnAddress
- ld a, [rOBP1]
+ ldh a, [rOBP1]
xor %01100100
- ld [rOBP1], a
+ ldh [rOBP1], a
call Delay3
pop bc
dec c
@@ -69,14 +69,14 @@ MoveBoulderDustFunctionPointerTable:
dw AdjustOAMBlockXPos
LoadSmokeTileFourTimes::
- ld hl, vChars1 + $7c0
- ld c, $4
+ ld hl, vChars1 tile $7c
+ ld c, 4
.loop
push bc
push hl
call LoadSmokeTile
pop hl
- ld bc, $10
+ ld bc, 1 tiles
add hl, bc
pop bc
dec c
diff --git a/engine/overworld/elevator.asm b/engine/overworld/elevator.asm
index 05ca08c9..fa404602 100755
--- a/engine/overworld/elevator.asm
+++ b/engine/overworld/elevator.asm
@@ -6,7 +6,7 @@ ShakeElevator::
call Delay3
ld a, SFX_STOP_ALL_MUSIC
call PlaySound
- ld a, [hSCY]
+ ldh a, [hSCY]
ld d, a
ld e, $1
ld b, 100
@@ -15,7 +15,7 @@ ShakeElevator::
xor $fe
ld e, a
add d
- ld [hSCY], a
+ ldh [hSCY], a
push bc
ld c, BANK(SFX_Collision_1)
ld a, SFX_COLLISION
@@ -26,7 +26,7 @@ ShakeElevator::
dec b
jr nz, .shakeLoop
ld a, d
- ld [hSCY], a
+ ldh [hSCY], a
ld a, SFX_STOP_ALL_MUSIC
call PlaySound
ld c, BANK(SFX_Safari_Zone_PA)
@@ -56,7 +56,7 @@ ShakeElevatorRedrawRow:
add hl, de
ld a, h
and $3
- or vBGMap0 / $100
+ or HIGH(vBGMap0)
ld d, a
ld a, l
pop hl
diff --git a/engine/overworld/emotion_bubbles.asm b/engine/overworld/emotion_bubbles.asm
index 1ac07b80..298858a2 100755
--- a/engine/overworld/emotion_bubbles.asm
+++ b/engine/overworld/emotion_bubbles.asm
@@ -8,8 +8,8 @@ EmotionBubble:
ld e, [hl]
inc hl
ld d, [hl]
- ld hl, vChars1 + $780
- lb bc, BANK(EmotionBubbles), $04
+ ld hl, vChars1 tile $78
+ lb bc, BANK(EmotionBubbles), 4
call CopyVideoData
ld a, [wUpdateSpritesEnabled]
push af
diff --git a/engine/overworld/healing_machine.asm b/engine/overworld/healing_machine.asm
index a09a7590..eaa396d0 100755
--- a/engine/overworld/healing_machine.asm
+++ b/engine/overworld/healing_machine.asm
@@ -1,17 +1,17 @@
AnimateHealingMachine:
ld de, PokeCenterFlashingMonitorAndHealBall
- ld hl, vChars0 + $7c0
- lb bc, BANK(PokeCenterFlashingMonitorAndHealBall), $03 ; loads one too many tiles
+ ld hl, vChars0 tile $7c
+ lb bc, BANK(PokeCenterFlashingMonitorAndHealBall), 3 ; should be 2
call CopyVideoData
ld hl, wUpdateSpritesEnabled
ld a, [hl]
push af
ld [hl], $ff
push hl
- ld a, [rOBP1]
+ ldh a, [rOBP1]
push af
ld a, $e0
- ld [rOBP1], a
+ ldh [rOBP1], a
ld hl, wOAMBuffer + $84
ld de, PokeCenterOAMData
call CopyHealingMachineOAM
@@ -56,7 +56,7 @@ AnimateHealingMachine:
ld c, 32
call DelayFrames
pop af
- ld [rOBP1], a
+ ldh [rOBP1], a
pop hl
pop af
ld [hl], a
@@ -78,9 +78,9 @@ PokeCenterOAMData:
FlashSprite8Times:
ld b, 8
.loop
- ld a, [rOBP1]
+ ldh a, [rOBP1]
xor d
- ld [rOBP1], a
+ ldh [rOBP1], a
ld c, 10
call DelayFrames
dec b
diff --git a/engine/overworld/hidden_objects.asm b/engine/overworld/hidden_objects.asm
index 5ce7f3cb..855328e7 100755
--- a/engine/overworld/hidden_objects.asm
+++ b/engine/overworld/hidden_objects.asm
@@ -58,7 +58,7 @@ CheckForHiddenObject::
ld [wHiddenObjectX], a
ld c, a
call CheckIfCoordsInFrontOfPlayerMatch
- ld a, [hCoordsInFrontOfPlayerMatch]
+ ldh a, [hCoordsInFrontOfPlayerMatch]
and a
jr z, .foundMatchingObject
inc hl
@@ -81,7 +81,7 @@ CheckForHiddenObject::
ret
.noMatch
ld a, $ff
- ld [hDidntFindAnyHiddenObject], a
+ ldh [hDidntFindAnyHiddenObject], a
ret
; checks if the coordinates in front of the player's sprite match Y in b and X in c
@@ -127,7 +127,7 @@ CheckIfCoordsInFrontOfPlayerMatch:
.didNotMatch
ld a, $ff
.done
- ld [hCoordsInFrontOfPlayerMatch], a
+ ldh [hCoordsInFrontOfPlayerMatch], a
ret
INCLUDE "data/events/hidden_objects.asm"
diff --git a/engine/overworld/ledges.asm b/engine/overworld/ledges.asm
index 0f135fb6..0e006c5e 100755
--- a/engine/overworld/ledges.asm
+++ b/engine/overworld/ledges.asm
@@ -8,7 +8,7 @@ HandleLedges::
predef GetTileAndCoordsInFrontOfPlayer
ld a, [wSpritePlayerStateData1FacingDirection]
ld b, a
- aCoord 8, 9
+ lda_coord 8, 9
ld c, a
ld a, [wTileInFrontOfPlayer]
ld d, a
@@ -36,7 +36,7 @@ HandleLedges::
inc hl
jr .loop
.foundMatch
- ld a, [hJoyHeld]
+ ldh a, [hJoyHeld]
and e
ret z
ld a, $ff
@@ -57,7 +57,7 @@ HandleLedges::
INCLUDE "data/tilesets/ledge_tiles.asm"
LoadHoppingShadowOAM:
- ld hl, vChars1 + $7f0
+ ld hl, vChars1 tile $7f
ld de, LedgeHoppingShadow
lb bc, BANK(LedgeHoppingShadow), (LedgeHoppingShadowEnd - LedgeHoppingShadow) / $8
call CopyVideoDataDouble
diff --git a/engine/overworld/map_sprites.asm b/engine/overworld/map_sprites.asm
index 0de1befd..8f1f3931 100755
--- a/engine/overworld/map_sprites.asm
+++ b/engine/overworld/map_sprites.asm
@@ -4,20 +4,21 @@
; This is also called after displaying text because loading
; text tile patterns overwrites half of the sprite tile pattern data.
; Note on notation:
-; $C1X* and $C2X* are used to denote wSpriteStateData1-wSpriteStateData1 + $ff and wSpriteStateData2 + $00-wSpriteStateData2 + $ff sprite slot
-; fields, respectively, within loops. The X is the loop index.
-; If there is an inner loop, Y is the inner loop index, i.e. $C1Y* and $C2Y*
-; denote fields of the sprite slots iterated over in the inner loop.
+; x#SPRITESTATEDATA1_* and x#SPRITESTATEDATA2_* are used to denote wSpriteStateData1 and
+; wSpriteStateData2 sprite slot, respectively, within loops. The X is the loop index.
+; If there is an inner loop, Y is the inner loop index, i.e. y#SPRITESTATEDATA1_* and
+; y#SPRITESTATEDATA2_* denote fields of the sprite slots iterated over in the inner loop.
InitMapSprites::
call InitOutsideMapSprites
ret c ; return if the map is an outside map (already handled by above call)
; if the map is an inside map (i.e. mapID >= $25)
ld hl, wSpritePlayerStateData1PictureID
ld de, wSpritePlayerStateData2PictureID
-; Loop to copy picture ID's from $C1X0 to $C2XD for LoadMapSpriteTilePatterns.
+; Loop to copy picture IDs from [x#SPRITESTATEDATA1_PICTUREID]
+; to [x#SPRITESTATEDATA2_PICTUREID] for LoadMapSpriteTilePatterns.
.copyPictureIDLoop
- ld a, [hl] ; $C1X0 (picture ID)
- ld [de], a ; $C2XD
+ ld a, [hl] ; a = [x#SPRITESTATEDATA1_PICTUREID]
+ ld [de], a ; [x#SPRITESTATEDATA2_PICTUREID] = a
ld a, $10
add e
ld e, a
@@ -39,10 +40,12 @@ LoadMapSpriteTilePatterns:
ld b, $10 ; number of sprite slots
ld hl, wSpritePlayerStateData2PictureID
xor a
- ld [hFourTileSpriteCount], a
-.copyPictureIDLoop ; loop to copy picture ID from $C2XD to $C2XE
- ld a, [hli] ; $C2XD (sprite picture ID)
- ld [hld], a ; $C2XE
+ ldh [hFourTileSpriteCount], a
+; Loop to copy picture IDs from [x#SPRITESTATEDATA2_PICTUREID]
+; to [x#SPRITESTATEDATA2_IMAGEBASEOFFSET].
+.copyPictureIDLoop
+ ld a, [hli] ; a = [x#SPRITESTATEDATA2_PICTUREID]
+ ld [hld], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET] = a
ld a, l
add $10
ld l, a
@@ -81,7 +84,7 @@ LoadMapSpriteTilePatterns:
ld a, l
cp e ; reached current slot?
jr z, .foundNextVRAMSlot
- ld a, [de] ; $C2YE (VRAM slot)
+ ld a, [de] ; y#SPRITESTATEDATA2_IMAGEBASEOFFSET
cp 11 ; is it one of the first 10 slots?
jr nc, .findNextVRAMSlotLoop
cp b ; compare the slot being checked to the current max
@@ -93,19 +96,19 @@ LoadMapSpriteTilePatterns:
inc b ; increment previous max value to get next VRAM tile pattern slot
ld a, b ; a = next VRAM tile pattern slot
push af
- ld a, [hl] ; $C2XE (sprite picture ID)
+ ld a, [hl] ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET]
ld b, a ; b = current sprite picture ID
cp SPRITE_BALL ; is it a 4-tile sprite?
jr c, .notFourTileSprite
pop af
- ld a, [hFourTileSpriteCount]
+ ldh a, [hFourTileSpriteCount]
add 11
jr .storeVRAMSlot
.notFourTileSprite
pop af
.storeVRAMSlot
- ld [hl], a ; store VRAM slot at $C2XE
- ld [hVRAMSlot], a ; used to determine if it's 4-tile sprite later
+ ld [hl], a ; store VRAM slot at [x#SPRITESTATEDATA2_IMAGEBASEOFFSET]
+ ldh [hVRAMSlot], a ; used to determine if it's 4-tile sprite later
ld a, b ; a = current sprite picture ID
dec a
add a
@@ -127,27 +130,27 @@ LoadMapSpriteTilePatterns:
push de
push bc
ld hl, vNPCSprites ; VRAM base address
- ld bc, $c0 ; number of bytes per VRAM slot
- ld a, [hVRAMSlot]
+ ld bc, 12 tiles ; number of bytes per VRAM slot
+ ldh a, [hVRAMSlot]
cp 11 ; is it a 4-tile sprite?
jr nc, .fourTileSpriteVRAMAddr
ld d, a
dec d
-; hl = vSprites + [hVRAMSlot] * $C0 (the number of bytes in 12 tiles)
+; hl = vSprites + [hVRAMSlot] * 12 tiles
.calculateVRAMAddrLoop
add hl, bc
dec d
jr nz, .calculateVRAMAddrLoop
jr .loadStillTilePattern
.fourTileSpriteVRAMAddr
- ld hl, vSprites + $7c0 ; address for second 4-tile sprite
- ld a, [hFourTileSpriteCount]
+ ld hl, vSprites tile $7c ; address for second 4-tile sprite
+ ldh a, [hFourTileSpriteCount]
and a
jr nz, .loadStillTilePattern
; if it's the first 4-tile sprite
- ld hl, vSprites + $780 ; address for first 4-tile sprite
+ ld hl, vSprites tile $78 ; address for first 4-tile sprite
inc a
- ld [hFourTileSpriteCount], a
+ ldh [hFourTileSpriteCount], a
.loadStillTilePattern
pop bc
pop de
@@ -167,7 +170,7 @@ LoadMapSpriteTilePatterns:
.skipFirstLoad
pop de
pop hl
- ld a, [hVRAMSlot]
+ ldh a, [hVRAMSlot]
cp 11 ; is it a 4-tile sprite?
jr nc, .skipSecondLoad ; if so, there is no second block
push de
@@ -207,8 +210,8 @@ LoadMapSpriteTilePatterns:
jr .nextSpriteSlot
.alreadyLoaded ; if the current picture ID has already had its tile patterns loaded
inc de
- ld a, [de] ; a = VRAM slot for the current picture ID (from $C2YE)
- ld [hl], a ; store VRAM slot in current wSpriteStateData2 sprite slot (at $C2XE)
+ ld a, [de] ; a = [y#SPRITESTATEDATA2_IMAGEBASEOFFSET]
+ ld [hl], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET] = a
.nextSpriteSlot
ld a, l
add $10
@@ -217,10 +220,11 @@ LoadMapSpriteTilePatterns:
jp nz, .loadTilePatternLoop
ld hl, wSpritePlayerStateData2PictureID
ld b, $10
-; the pictures ID's stored at $C2XD are no longer needed, so zero them
+; the pictures IDs stored at [x#SPRITESTATEDATA2_PICTUREID] are no longer needed,
+; so zero them
.zeroStoredPictureIDLoop
xor a
- ld [hl], a ; $C2XD
+ ld [hl], a ; [x#SPRITESTATEDATA2_PICTUREID]
ld a, $10
add l
ld l, a
@@ -292,15 +296,15 @@ InitOutsideMapSprites:
ld [hl], a
ld bc, wSpriteSet
; Load the sprite set into RAM.
-; This loop also fills $C2XD (sprite picture ID) where X is from $0 to $A
-; with picture ID's. This is done so that LoadMapSpriteTilePatterns will
+; This loop also fills [x#SPRITESTATEDATA2_PICTUREID] where X is from $0 to $A
+; with picture IDs. This is done so that LoadMapSpriteTilePatterns will
; load tile patterns for all sprite pictures in the sprite set.
.loadSpriteSetLoop
ld a, $10
add l
ld l, a
ld a, [de] ; sprite picture ID from sprite set
- ld [hl], a ; $C2XD (sprite picture ID)
+ ld [hl], a ; [x#SPRITESTATEDATA2_PICTUREID]
ld [bc], a
inc de
inc bc
@@ -313,7 +317,7 @@ InitOutsideMapSprites:
add l
ld l, a
xor a
- ld [hl], a ; $C2XD (sprite picture ID)
+ ld [hl], a ; [x#SPRITESTATEDATA2_PICTUREID]
dec b
jr nz, .zeroRemainingSlotsLoop
ld a, [wNumSprites]
@@ -330,7 +334,7 @@ InitOutsideMapSprites:
; for the current map. So, they are not needed and are zeroed by this loop.
.zeroVRAMSlotsLoop
xor a
- ld [hl], a ; $C2XE (VRAM slot)
+ ld [hl], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET]
ld a, $10
add l
ld l, a
@@ -347,7 +351,7 @@ InitOutsideMapSprites:
; VRAM tile pattern slot.
.storeVRAMSlotsLoop
ld c, 0
- ld a, [hl] ; $C1X0 (picture ID) (zero if sprite slot is not used)
+ ld a, [hl] ; [x#SPRITESTATEDATA1_PICTUREID] (zero if sprite slot is not used)
and a ; is the sprite slot used?
jr z, .skipGettingPictureIndex ; if the sprite slot is not used
ld b, a ; b = picture ID
@@ -367,7 +371,7 @@ InitOutsideMapSprites:
add l
ld l, a
ld a, c ; a = VRAM slot (zero if sprite slot is not used)
- ld [hl], a ; $C2XE (VRAM slot)
+ ld [hl], a ; [x#SPRITESTATEDATA2_IMAGEBASEOFFSET]
pop hl
ld a, $10
add l
diff --git a/engine/overworld/missable_objects.asm b/engine/overworld/missable_objects.asm
index 1ebe8064..fd2fe578 100644
--- a/engine/overworld/missable_objects.asm
+++ b/engine/overworld/missable_objects.asm
@@ -31,19 +31,19 @@ LoadMissableObjects:
sub d
ld h, a
ld a, h
- ld [hDividend], a
+ ldh [hDividend], a
ld a, l
- ld [hDividend+1], a
+ ldh [hDividend+1], a
xor a
- ld [hDividend+2], a
- ld [hDividend+3], a
+ ldh [hDividend+2], a
+ ldh [hDividend+3], a
ld a, $3
- ld [hDivisor], a
+ ldh [hDivisor], a
ld b, $2
call Divide ; divide difference by 3, resulting in the global offset (number of missable items before ours)
ld a, [wCurMap]
ld b, a
- ld a, [hDividend+3]
+ ldh a, [hDividend+3]
ld c, a ; store global offset in c
ld de, wMissableObjectList
pop hl
@@ -99,7 +99,7 @@ InitializeMissableObjectsFlags:
; tests if current sprite is a missable object that is hidden/has been removed
IsObjectHidden:
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
swap a
ld b, a
ld hl, wMissableObjectList
@@ -120,7 +120,7 @@ IsObjectHidden:
.notHidden
xor a
.hidden
- ld [hIsHiddenMissableObject], a
+ ldh [hIsHiddenMissableObject], a
ret
; adds missable object (items, leg. pokemon, etc.) to the map
diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm
index d27ccb4b..58481613 100644
--- a/engine/overworld/movement.asm
+++ b/engine/overworld/movement.asm
@@ -13,8 +13,8 @@ UpdatePlayerSprite:
; background tile the sprite is standing on is greater than $5F, which is
; the maximum number for map tiles
.checkIfTextBoxInFrontOfSprite
- aCoord 8, 9
- ld [hTilePlayerStandingOn], a
+ lda_coord 8, 9
+ ldh [hTilePlayerStandingOn], a
cp MAP_TILESET_SIZE
jr c, .lowerLeftTileIsMapTile
.disableSprite
@@ -23,7 +23,7 @@ UpdatePlayerSprite:
ret
.lowerLeftTileIsMapTile
call DetectCollisionBetweenSprites
- ld h, wSpriteStateData1 / $100
+ ld h, HIGH(wSpriteStateData1)
ld a, [wWalkCounter]
and a
jr nz, .moving
@@ -63,7 +63,7 @@ UpdatePlayerSprite:
ld a, [wd736]
bit 7, a ; is the player sprite spinning due to a spin tile?
jr nz, .skipSpriteAnim
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $7
ld l, a
ld a, [hl]
@@ -89,7 +89,7 @@ UpdatePlayerSprite:
; lower priority than the background so that it's partially obscured by the
; grass. Only the lower half of the sprite is permitted to have the priority
; bit set by later logic.
- ld a, [hTilePlayerStandingOn]
+ ldh a, [hTilePlayerStandingOn]
ld c, a
ld a, [wGrassTile]
cp c
@@ -103,7 +103,7 @@ UpdatePlayerSprite:
UnusedReadSpriteDataFunction:
push bc
push af
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
ld c, a
pop af
add c
@@ -112,7 +112,7 @@ UnusedReadSpriteDataFunction:
ret
UpdateNPCSprite:
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
swap a
dec a
add a
@@ -121,20 +121,20 @@ UpdateNPCSprite:
ld l, a
ld a, [hl] ; read movement byte 2
ld [wCurSpriteMovement2], a
- ld h, $c1
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
ld l, a
inc l
- ld a, [hl] ; c1x1
+ ld a, [hl] ; x#SPRITESTATEDATA1_MOVEMENTSTATUS
and a
jp z, InitializeSpriteStatus
call CheckSpriteAvailability
ret c ; if sprite is invisible, on tile >=MAP_TILESET_SIZE, in grass or player is currently walking
- ld h, $c1
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
ld l, a
inc l
- ld a, [hl] ; c1x1
+ ld a, [hl] ; x#SPRITESTATEDATA1_MOVEMENTSTATUS
bit 7, a ; is the face player flag set?
jp nz, MakeNPCFacePlayer
ld b, a
@@ -143,18 +143,18 @@ UpdateNPCSprite:
jp nz, notYetMoving
ld a, b
cp $2
- jp z, UpdateSpriteMovementDelay ; c1x1 == 2
+ jp z, UpdateSpriteMovementDelay ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] == 2
cp $3
- jp z, UpdateSpriteInWalkingAnimation ; c1x1 == 3
+ jp z, UpdateSpriteInWalkingAnimation ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] == 3
ld a, [wWalkCounter]
and a
ret nz ; don't do anything yet if player is currently moving (redundant, already tested in CheckSpriteAvailability)
call InitializeSpriteScreenPosition
ld h, $c2
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $6
ld l, a
- ld a, [hl] ; c2x6: movement byte 1
+ ld a, [hl] ; x#SPRITESTATEDATA2_MOVEMENTBYTE1
inc a
jr z, .randomMovement ; value $FF
inc a
@@ -263,18 +263,18 @@ ChangeFacingDirection:
; set carry on failure, clears carry on success
TryWalking:
push hl
- ld h, $c1
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
add $9
ld l, a
- ld [hl], c ; c1x9 (update facing direction)
- ld a, [hCurrentSpriteOffset]
+ ld [hl], c ; x#SPRITESTATEDATA1_FACINGDIRECTION
+ ldh a, [hCurrentSpriteOffset]
add $3
ld l, a
- ld [hl], d ; c1x3 (update Y movement delta)
+ ld [hl], d ; x#SPRITESTATEDATA1_YSTEPVECTOR
inc l
inc l
- ld [hl], e ; c1x5 (update X movement delta)
+ ld [hl], e ; x#SPRITESTATEDATA1_XSTEPVECTOR
pop hl
push de
ld c, [hl] ; read tile to walk onto
@@ -282,103 +282,105 @@ TryWalking:
pop de
ret c ; cannot walk there (reinitialization of delay values already done)
ld h, $c2
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $4
ld l, a
- ld a, [hl] ; c2x4: Y position
+ ld a, [hl] ; x#SPRITESTATEDATA2_MAPY
add d
ld [hli], a ; update Y position
- ld a, [hl] ; c2x5: X position
+ ld a, [hl] ; x#SPRITESTATEDATA2_MAPX
add e
ld [hl], a ; update X position
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
ld l, a
- ld [hl], $10 ; c2x0=16: walk animation counter
+ ld [hl], $10 ; [x#SPRITESTATEDATA2_WALKANIMATIONCOUNTER] = 16
dec h
inc l
- ld [hl], $3 ; c1x1: set movement status to walking
+ ld [hl], $3 ; x#SPRITESTATEDATA1_MOVEMENTSTATUS
jp UpdateSpriteImage
; update the walking animation parameters for a sprite that is currently walking
UpdateSpriteInWalkingAnimation:
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $7
ld l, a
- ld a, [hl] ; c1x7 (counter until next walk animation frame)
+ ld a, [hl] ; x#SPRITESTATEDATA1_INTRAANIMFRAMECOUNTER
inc a
- ld [hl], a ; c1x7 += 1
+ ld [hl], a ; [x#SPRITESTATEDATA1_INTRAANIMFRAMECOUNTER]++
cp $4
jr nz, .noNextAnimationFrame
xor a
- ld [hl], a ; c1x7 = 0
+ ld [hl], a ; [x#SPRITESTATEDATA1_INTRAANIMFRAMECOUNTER] = 0
inc l
- ld a, [hl] ; c1x8 (walk animation frame)
+ ld a, [hl] ; x#SPRITESTATEDATA1_ANIMFRAMECOUNTER
inc a
and $3
ld [hl], a ; advance to next animation frame every 4 ticks (16 ticks total for one step)
.noNextAnimationFrame
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $3
ld l, a
- ld a, [hli] ; c1x3 (movement Y delta)
+ ld a, [hli] ; x#SPRITESTATEDATA1_YSTEPVECTOR
ld b, a
- ld a, [hl] ; c1x4 (screen Y position)
+ ld a, [hl] ; x#SPRITESTATEDATA1_YPIXELS
add b
- ld [hli], a ; update screen Y position
- ld a, [hli] ; c1x5 (movement X delta)
+ ld [hli], a ; update [x#SPRITESTATEDATA1_YPIXELS]
+ ld a, [hli] ; x#SPRITESTATEDATA1_XSTEPVECTOR
ld b, a
- ld a, [hl] ; c1x6 (screen X position)
+ ld a, [hl] ; x#SPRITESTATEDATA1_XPIXELS
add b
- ld [hl], a ; update screen X position
- ld a, [hCurrentSpriteOffset]
+ ld [hl], a ; update [x#SPRITESTATEDATA1_XPIXELS]
+ ldh a, [hCurrentSpriteOffset]
ld l, a
inc h
- ld a, [hl] ; c2x0 (walk animation counter)
+ ld a, [hl] ; x#SPRITESTATEDATA2_WALKANIMATIONCOUNTER
dec a
ld [hl], a ; update walk animation counter
ret nz
ld a, $6 ; walking finished, update state
add l
ld l, a
- ld a, [hl] ; c2x6 (movement byte 1)
+ ld a, [hl] ; x#SPRITESTATEDATA2_MOVEMENTBYTE1
cp $fe
jr nc, .initNextMovementCounter ; values $fe and $ff
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
inc a
ld l, a
dec h
- ld [hl], $1 ; c1x1 = 1 (movement status ready)
+ ld [hl], $1 ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] = 1 (movement status ready)
ret
.initNextMovementCounter
call Random
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $8
ld l, a
- ld a, [hRandomAdd]
+ ldh a, [hRandomAdd]
and $7f
- ld [hl], a ; c2x8: set next movement delay to a random value in [0,$7f]
- dec h ; note that value 0 actually makes the delay $100 (bug?)
- ld a, [hCurrentSpriteOffset]
+ ld [hl], a ; x#SPRITESTATEDATA2_MOVEMENTDELAY:
+ ; set next movement delay to a random value in [0,$7f]
+ ; note that value 0 actually makes the delay $100 (bug?)
+ dec h ; HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
inc a
ld l, a
- ld [hl], $2 ; c1x1 = 2 (movement status)
+ ld [hl], $2 ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] = 2 (movement status)
inc l
inc l
xor a
- ld b, [hl] ; c1x3 (movement Y delta)
- ld [hli], a ; reset movement Y delta
+ ld b, [hl] ; x#SPRITESTATEDATA1_YSTEPVECTOR
+ ld [hli], a ; [x#SPRITESTATEDATA1_YSTEPVECTOR] = 0
inc l
- ld c, [hl] ; c1x5 (movement X delta)
- ld [hl], a ; reset movement X delta
+ ld c, [hl] ; x#SPRITESTATEDATA1_XSTEPVECTOR
+ ld [hl], a ; [x#SPRITESTATEDATA1_XSTEPVECTOR] = 0
ret
-; update delay value (c2x8) for sprites in the delayed state (c1x1)
+; update [x#SPRITESTATEDATA2_MOVEMENTDELAY] for sprites in the delayed state (x#SPRITESTATEDATA1_MOVEMENTSTATUS)
UpdateSpriteMovementDelay:
- ld h, $c2
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData2)
+ ldh a, [hCurrentSpriteOffset]
add $6
ld l, a
- ld a, [hl] ; c2x6: movement byte 1
+ ld a, [hl] ; x#SPRITESTATEDATA2_MOVEMENTBYTE1
inc l
inc l
cp $fe
@@ -386,20 +388,20 @@ UpdateSpriteMovementDelay:
ld [hl], $0
jr .moving
.tickMoveCounter
- dec [hl] ; c2x8: frame counter until next movement
+ dec [hl] ; x#SPRITESTATEDATA2_MOVEMENTDELAY
jr nz, notYetMoving
.moving
dec h
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
inc a
ld l, a
- ld [hl], $1 ; c1x1 = 1 (mark as ready to move)
+ ld [hl], $1 ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] = 1 (mark as ready to move)
notYetMoving:
- ld h, wSpriteStateData1 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData1AnimFrameCounter - wSpritePlayerStateData1
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA1_ANIMFRAMECOUNTER
ld l, a
- ld [hl], $0 ; c1x8 = 0 (walk animation frame)
+ ld [hl], $0 ; [x#SPRITESTATEDATA1_ANIMFRAMECOUNTER] = 0 (walk animation frame)
jp UpdateSpriteImage
MakeNPCFacePlayer:
@@ -429,66 +431,66 @@ MakeNPCFacePlayer:
.notFacingRight
ld c, SPRITE_FACING_LEFT
.facingDirectionDetermined
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $9
ld l, a
- ld [hl], c ; c1x9: set facing direction
+ ld [hl], c ; [x#SPRITESTATEDATA1_FACINGDIRECTION]: set facing direction
jr notYetMoving
InitializeSpriteStatus:
- ld [hl], $1 ; $c1x1: set movement status to ready
+ ld [hl], $1 ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] = ready
inc l
- ld [hl], $ff ; $c1x2: set sprite image to $ff (invisible/off screen)
- inc h
- ld a, [hCurrentSpriteOffset]
+ ld [hl], $ff ; [x#SPRITESTATEDATA1_IMAGEINDEX] = invisible/off screen
+ inc h ; HIGH(wSpriteStateData2)
+ ldh a, [hCurrentSpriteOffset]
add $2
ld l, a
ld a, $8
- ld [hli], a ; $c2x2: set Y displacement to 8
- ld [hl], a ; $c2x3: set X displacement to 8
+ ld [hli], a ; [x#SPRITESTATEDATA2_YDISPLACEMENT] = 8
+ ld [hl], a ; [x#SPRITESTATEDATA2_XDISPLACEMENT] = 8
ret
-; calculates the sprite's screen position form its map position and the player position
+; calculates the sprite's screen position from its map position and the player position
InitializeSpriteScreenPosition:
- ld h, wSpriteStateData2 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData2MapY - wSpritePlayerStateData2
+ ld h, HIGH(wSpriteStateData2)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA2_MAPY
ld l, a
ld a, [wYCoord]
ld b, a
- ld a, [hl] ; c2x4 (Y position + 4)
+ ld a, [hl] ; x#SPRITESTATEDATA2_MAPY
sub b ; relative to player position
swap a ; * 16
sub $4 ; - 4
dec h
- ld [hli], a ; c1x4 (screen Y position)
+ ld [hli], a ; [x#SPRITESTATEDATA1_YPIXELS]
inc h
ld a, [wXCoord]
ld b, a
- ld a, [hli] ; c2x6 (X position + 4)
+ ld a, [hli] ; x#SPRITESTATEDATA2_MAPX
sub b ; relative to player position
swap a ; * 16
dec h
- ld [hl], a ; c1x6 (screen X position)
+ ld [hl], a ; [x#SPRITESTATEDATA1_XPIXELS]
ret
; tests if sprite is off screen or otherwise unable to do anything
CheckSpriteAvailability:
predef IsObjectHidden
- ld a, [hIsHiddenMissableObject]
+ ldh a, [hIsHiddenMissableObject]
and a
jp nz, .spriteInvisible
- ld h, wSpriteStateData2 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData2MovementByte1 - wSpritePlayerStateData2
+ ld h, HIGH(wSpriteStateData2)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA2_MOVEMENTBYTE1
ld l, a
- ld a, [hl] ; c2x6: movement byte 1
+ ld a, [hl] ; x#SPRITESTATEDATA2_MOVEMENTBYTE1
cp $fe
jr c, .skipXVisibilityTest ; movement byte 1 < $fe (i.e. the sprite's movement is scripted)
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData2MapY - wSpritePlayerStateData2
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA2_MAPY
ld l, a
- ld b, [hl] ; c2x4: Y pos (+4)
+ ld b, [hl] ; x#SPRITESTATEDATA2_MAPY
ld a, [wYCoord]
cp b
jr z, .skipYVisibilityTest
@@ -498,7 +500,7 @@ CheckSpriteAvailability:
jr c, .spriteInvisible ; below screen region
.skipYVisibilityTest
inc l
- ld b, [hl] ; c2x5: X pos (+4)
+ ld b, [hl] ; x#SPRITESTATEDATA2_MAPX
ld a, [wXCoord]
cp b
jr z, .skipXVisibilityTest
@@ -526,11 +528,11 @@ CheckSpriteAvailability:
cp d
jr c, .spriteVisible ; standing on tile with ID >=MAP_TILESET_SIZE (top right tile)
.spriteInvisible
- ld h, wSpriteStateData1 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData1ImageIndex - wSpritePlayerStateData1
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA1_IMAGEINDEX
ld l, a
- ld [hl], $ff ; c1x2
+ ld [hl], $ff ; x#SPRITESTATEDATA1_IMAGEINDEX
scf
jr .done
.spriteVisible
@@ -540,7 +542,7 @@ CheckSpriteAvailability:
jr nz, .done ; if player is currently walking, we're done
call UpdateSpriteImage
inc h
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $7
ld l, a
ld a, [wGrassTile]
@@ -549,28 +551,28 @@ CheckSpriteAvailability:
jr nz, .notInGrass
ld a, $80
.notInGrass
- ld [hl], a ; c2x7
+ ld [hl], a ; x#SPRITESTATEDATA2_GRASSPRIORITY
and a
.done
ret
UpdateSpriteImage:
- ld h, $c1
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
add $8
ld l, a
- ld a, [hli] ; c1x8: walk animation frame
+ ld a, [hli] ; x#SPRITESTATEDATA1_ANIMFRAMECOUNTER
ld b, a
- ld a, [hl] ; c1x9: facing direction
+ ld a, [hl] ; x#SPRITESTATEDATA1_FACINGDIRECTION
add b
ld b, a
- ld a, [hTilePlayerStandingOn]
+ ldh a, [hTilePlayerStandingOn]
add b
ld b, a
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $2
ld l, a
- ld [hl], b ; c1x2: sprite to display
+ ld [hl], b ; x#SPRITESTATEDATA1_IMAGEINDEX
ret
; tests if sprite can walk the specified direction
@@ -580,11 +582,11 @@ UpdateSpriteImage:
; e: X movement delta (-1, 0 or 1)
; set carry on failure, clears carry on success
CanWalkOntoTile:
- ld h, wSpriteStateData2 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData2MovementByte1 - wSpritePlayerStateData2
+ ld h, HIGH(wSpriteStateData2)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA2_MOVEMENTBYTE1
ld l, a
- ld a, [hl] ; c2x6 (movement byte 1)
+ ld a, [hl] ; x#SPRITESTATEDATA2_MOVEMENTBYTE1
cp $fe
jr nc, .notScripted ; values $fe and $ff
; always allow walking if the movement is scripted
@@ -602,23 +604,23 @@ CanWalkOntoTile:
cp c
jr nz, .tilePassableLoop
ld h, $c2
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $6
ld l, a
- ld a, [hl] ; $c2x6 (movement byte 1)
+ ld a, [hl] ; x#SPRITESTATEDATA2_MOVEMENTBYTE1
inc a
jr z, .impassable ; if $ff, no movement allowed (however, changing direction is)
- ld h, wSpriteStateData1 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA1_YPIXELS
ld l, a
- ld a, [hli] ; c1x4 (screen Y pos)
+ ld a, [hli] ; x#SPRITESTATEDATA1_YPIXELS
add $4 ; align to blocks (Y pos is always 4 pixels off)
add d ; add Y delta
cp $80 ; if value is >$80, the destination is off screen (either $81 or $FF underflow)
jr nc, .impassable ; don't walk off screen
inc l
- ld a, [hl] ; c1x6 (screen X pos)
+ ld a, [hl] ; x#SPRITESTATEDATA1_XPIXELS
add e ; add X delta
cp $90 ; if value is >$90, the destination is off screen (either $91 or $FF underflow)
jr nc, .impassable ; don't walk off screen
@@ -627,30 +629,35 @@ CanWalkOntoTile:
call DetectCollisionBetweenSprites
pop bc
pop de
- ld h, wSpriteStateData1 / $100
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
add $c
ld l, a
- ld a, [hl] ; c1xc (directions in which sprite collision would occur)
+ ld a, [hl] ; x#SPRITESTATEDATA1_COLLISIONDATA (directions in which sprite collision would occur)
and b ; check against chosen direction (1,2,4 or 8)
jr nz, .impassable ; collision between sprites, don't go there
- ld h, wSpriteStateData2 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData2YDisplacement - wSpritePlayerStateData2
+ ld h, HIGH(wSpriteStateData2)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA2_YDISPLACEMENT
ld l, a
- ld a, [hli] ; c2x2 (sprite Y displacement, initialized at $8, keep track of where a sprite did go)
+ ld a, [hli] ; x#SPRITESTATEDATA2_YDISPLACEMENT (initialized at $8, keep track of where a sprite did go)
bit 7, d ; check if going upwards (d=$ff)
jr nz, .upwards
add d
+ ; bug: these tests against $5 probably were supposed to prevent
+ ; sprites from walking out too far, but this line makes sprites get
+ ; stuck whenever they walked upwards 5 steps
+ ; on the other hand, the amount a sprite can walk out to the
+ ; right of bottom is not limited (until the counter overflows)
cp $5
- jr c, .impassable ; if c2x2+d < 5, don't go ;bug: this tests probably were supposed to prevent sprites
- jr .checkHorizontal ; from walking out too far, but this line makes sprites get stuck
-.upwards ; whenever they walked upwards 5 steps
- sub $1 ; on the other hand, the amount a sprite can walk out to the
- jr c, .impassable ; if d2x2 == 0, don't go ; right of bottom is not limited (until the counter overflows)
+ jr c, .impassable ; if [x#SPRITESTATEDATA2_YDISPLACEMENT]+d < 5, don't go
+ jr .checkHorizontal
+.upwards
+ sub $1
+ jr c, .impassable ; if [x#SPRITESTATEDATA2_YDISPLACEMENT] == 0, don't go
.checkHorizontal
ld d, a
- ld a, [hl] ; c2x3 (sprite X displacement, initialized at $8, keep track of where a sprite did go)
+ ld a, [hl] ; x#SPRITESTATEDATA2_XDISPLACEMENT (initialized at $8, keep track of where a sprite did go)
bit 7, e ; check if going left (e=$ff)
jr nz, .left
add e
@@ -658,32 +665,32 @@ CanWalkOntoTile:
jr .passable
.left
sub $1
- jr c, .impassable ; if d2x3 == 0, don't go
+ jr c, .impassable ; if [x#SPRITESTATEDATA2_XDISPLACEMENT] == 0, don't go
.passable
- ld [hld], a ; update c2x3
- ld [hl], d ; update c2x2
+ ld [hld], a ; update x#SPRITESTATEDATA2_XDISPLACEMENT
+ ld [hl], d ; update x#SPRITESTATEDATA2_YDISPLACEMENT
and a ; clear carry (marking success)
ret
.impassable
- ld h, wSpriteStateData1 / $100
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
inc a
ld l, a
- ld [hl], $2 ; c1x1 = 2 (set movement status to delayed)
+ ld [hl], $2 ; [x#SPRITESTATEDATA1_MOVEMENTSTATUS] = 2 (delayed)
inc l
inc l
xor a
- ld [hli], a ; c1x3 = 0 (clear Y movement delta)
+ ld [hli], a ; [x#SPRITESTATEDATA1_YSTEPVECTOR] = 0
inc l
- ld [hl], a ; c1x5 = 0 (clear X movement delta)
+ ld [hl], a ; [x#SPRITESTATEDATA1_XSTEPVECTOR] = 0
inc h
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $8
ld l, a
call Random
- ld a, [hRandomAdd]
+ ldh a, [hRandomAdd]
and $7f
- ld [hl], a ; c2x8: set next movement delay to a random value in [0,$7f] (again with delay $100 if value is 0)
+ ld [hl], a ; x#SPRITESTATEDATA2_MOVEMENTDELAY: set to a random value in [0,$7f] (again with delay $100 if value is 0)
scf ; set carry (marking failure to walk)
ret
@@ -691,25 +698,25 @@ CanWalkOntoTile:
; this is always the lower left tile of the 2x2 tile blocks all sprites are snapped to
; hl: output pointer
GetTileSpriteStandsOn:
- ld h, wSpriteStateData1 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA1_YPIXELS
ld l, a
- ld a, [hli] ; c1x4: screen Y position
+ ld a, [hli] ; x#SPRITESTATEDATA1_YPIXELS
add $4 ; align to 2*2 tile blocks (Y position is always off 4 pixels to the top)
and $f0 ; in case object is currently moving
srl a ; screen Y tile * 4
ld c, a
ld b, $0
inc l
- ld a, [hl] ; c1x6: screen X position
+ ld a, [hl] ; x#SPRITESTATEDATA1_XPIXELS
srl a
srl a
srl a ; screen X tile
add SCREEN_WIDTH ; screen X tile + 20
ld d, $0
ld e, a
- coord hl, 0, 0
+ hlcoord 0, 0
add hl, bc
add hl, bc
add hl, bc
@@ -784,7 +791,7 @@ DoScriptedNPCMovement:
ld a, [hl]
add b
ld [hl], a
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $9
ld l, a
ld a, c
@@ -807,17 +814,17 @@ InitScriptedNPCMovement:
jp AnimScriptedNPCMovement
GetSpriteScreenYPointer:
- ld a, wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ ld a, SPRITESTATEDATA1_YPIXELS
ld b, a
jr GetSpriteScreenXYPointerCommon
GetSpriteScreenXPointer:
- ld a, wSpritePlayerStateData1XPixels - wSpritePlayerStateData1
+ ld a, SPRITESTATEDATA1_XPIXELS
ld b, a
GetSpriteScreenXYPointerCommon:
ld hl, wSpriteStateData1
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add l
add b
ld l, a
@@ -825,16 +832,16 @@ GetSpriteScreenXYPointerCommon:
AnimScriptedNPCMovement:
ld hl, wSpriteStateData2
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData2ImageBaseOffset - wSpritePlayerStateData2
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA2_IMAGEBASEOFFSET
ld l, a
ld a, [hl] ; VRAM slot
dec a
swap a
ld b, a
ld hl, wSpriteStateData1
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData1FacingDirection - wSpritePlayerStateData1
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA1_FACINGDIRECTION
ld l, a
ld a, [hl] ; facing direction
cp SPRITE_FACING_DOWN
@@ -849,21 +856,21 @@ AnimScriptedNPCMovement:
.anim
add b
ld b, a
- ld [hSpriteVRAMSlotAndFacing], a
+ ldh [hSpriteVRAMSlotAndFacing], a
call AdvanceScriptedNPCAnimFrameCounter
ld hl, wSpriteStateData1
- ld a, [hCurrentSpriteOffset]
- add wSpritePlayerStateData1ImageIndex - wSpritePlayerStateData1
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA1_IMAGEINDEX
ld l, a
- ld a, [hSpriteVRAMSlotAndFacing]
+ ldh a, [hSpriteVRAMSlotAndFacing]
ld b, a
- ld a, [hSpriteAnimFrameCounter]
+ ldh a, [hSpriteAnimFrameCounter]
add b
ld [hl], a
ret
AdvanceScriptedNPCAnimFrameCounter:
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add $7
ld l, a
ld a, [hl] ; intra-animation frame counter
@@ -878,5 +885,5 @@ AdvanceScriptedNPCAnimFrameCounter:
inc a
and $3
ld [hl], a
- ld [hSpriteAnimFrameCounter], a
+ ldh [hSpriteAnimFrameCounter], a
ret
diff --git a/engine/overworld/pathfinding.asm b/engine/overworld/pathfinding.asm
index 7251759c..1925dbbc 100644
--- a/engine/overworld/pathfinding.asm
+++ b/engine/overworld/pathfinding.asm
@@ -8,29 +8,29 @@ FindPathToPlayer:
ld hl, wNPCMovementDirections2
ld de, $0
.loop
- ld a, [hFindPathYProgress]
+ ldh a, [hFindPathYProgress]
ld b, a
- ld a, [hNPCPlayerYDistance] ; Y distance in steps
+ ldh a, [hNPCPlayerYDistance] ; Y distance in steps
call CalcDifference
ld d, a
and a
jr nz, .asm_f8da
- ld a, [hFindPathFlags]
+ ldh a, [hFindPathFlags]
set 0, a ; current end of path matches the player's Y coordinate
- ld [hFindPathFlags], a
+ ldh [hFindPathFlags], a
.asm_f8da
- ld a, [hFindPathXProgress]
+ ldh a, [hFindPathXProgress]
ld b, a
- ld a, [hNPCPlayerXDistance] ; X distance in steps
+ ldh a, [hNPCPlayerXDistance] ; X distance in steps
call CalcDifference
ld e, a
and a
jr nz, .asm_f8ec
- ld a, [hFindPathFlags]
+ ldh a, [hFindPathFlags]
set 1, a ; current end of path matches the player's X coordinate
- ld [hFindPathFlags], a
+ ldh [hFindPathFlags], a
.asm_f8ec
- ld a, [hFindPathFlags]
+ ldh a, [hFindPathFlags]
cp $3 ; has the end of the path reached the player's position?
jr z, .done
; Compare whether the X distance between the player and the current of the path
@@ -39,7 +39,7 @@ FindPathToPlayer:
cp d
jr c, .yDistanceGreater
; x distance is greater
- ld a, [hNPCPlayerRelativePosFlags]
+ ldh a, [hNPCPlayerRelativePosFlags]
bit 1, a
jr nz, .playerIsLeftOfNPC
ld d, NPC_MOVEMENT_RIGHT
@@ -47,12 +47,12 @@ FindPathToPlayer:
.playerIsLeftOfNPC
ld d, NPC_MOVEMENT_LEFT
.next1
- ld a, [hFindPathXProgress]
+ ldh a, [hFindPathXProgress]
add 1
- ld [hFindPathXProgress], a
+ ldh [hFindPathXProgress], a
jr .storeDirection
.yDistanceGreater
- ld a, [hNPCPlayerRelativePosFlags]
+ ldh a, [hNPCPlayerRelativePosFlags]
bit 0, a
jr nz, .playerIsAboveNPC
ld d, NPC_MOVEMENT_DOWN
@@ -60,15 +60,15 @@ FindPathToPlayer:
.playerIsAboveNPC
ld d, NPC_MOVEMENT_UP
.next2
- ld a, [hFindPathYProgress]
+ ldh a, [hFindPathYProgress]
add 1
- ld [hFindPathYProgress], a
+ ldh [hFindPathYProgress], a
.storeDirection
ld a, d
ld [hli], a
- ld a, [hFindPathNumSteps]
+ ldh a, [hFindPathNumSteps]
inc a
- ld [hFindPathNumSteps], a
+ ldh [hFindPathNumSteps], a
jp .loop
.done
ld [hl], $ff
@@ -76,15 +76,15 @@ FindPathToPlayer:
CalcPositionOfPlayerRelativeToNPC:
xor a
- ld [hNPCPlayerRelativePosFlags], a
+ ldh [hNPCPlayerRelativePosFlags], a
ld a, [wSpritePlayerStateData1YPixels]
ld d, a
ld a, [wSpritePlayerStateData1XPixels]
ld e, a
ld hl, wSpriteStateData1
- ld a, [hNPCSpriteOffset]
+ ldh a, [hNPCSpriteOffset]
add l
- add wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ add SPRITESTATEDATA1_YPIXELS
ld l, a
jr nc, .noCarry
inc h
@@ -115,7 +115,7 @@ CalcPositionOfPlayerRelativeToNPC:
ld [hli], a
call DivideBytes ; divide Y absolute distance by 16
ld a, [hl] ; quotient
- ld [hNPCPlayerYDistance], a
+ ldh [hNPCPlayerYDistance], a
pop hl
inc hl
ld b, e
@@ -136,23 +136,23 @@ CalcPositionOfPlayerRelativeToNPC:
res 1, [hl]
pop hl
.divideXDistance
- ld [hDividend2], a
+ ldh [hDividend2], a
ld a, 16
- ld [hDivisor2], a
+ ldh [hDivisor2], a
call DivideBytes ; divide X absolute distance by 16
- ld a, [hQuotient2]
- ld [hNPCPlayerXDistance], a
- ld a, [hNPCPlayerRelativePosPerspective]
+ ldh a, [hQuotient2]
+ ldh [hNPCPlayerXDistance], a
+ ldh a, [hNPCPlayerRelativePosPerspective]
and a
ret z
- ld a, [hNPCPlayerRelativePosFlags]
+ ldh a, [hNPCPlayerRelativePosFlags]
cpl
and $3
- ld [hNPCPlayerRelativePosFlags], a
+ ldh [hNPCPlayerRelativePosFlags], a
ret
ConvertNPCMovementDirectionsToJoypadMasks:
- ld a, [hNPCMovementDirections2Index]
+ ldh a, [hNPCMovementDirections2Index]
ld [wNPCMovementDirections2Index], a
dec a
ld de, wSimulatedJoypadStatesEnd
@@ -166,9 +166,9 @@ ConvertNPCMovementDirectionsToJoypadMasks:
call ConvertNPCMovementDirectionToJoypadMask
ld [de], a
inc de
- ld a, [hNPCMovementDirections2Index]
+ ldh a, [hNPCMovementDirections2Index]
dec a
- ld [hNPCMovementDirections2Index], a
+ ldh [hNPCMovementDirections2Index], a
jr nz, .loop
ret
diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm
index cfd6cc8d..9e9b4073 100755
--- a/engine/overworld/player_animations.asm
+++ b/engine/overworld/player_animations.asm
@@ -250,11 +250,11 @@ DoFlyAnimation:
LoadBirdSpriteGraphics:
ld de, BirdSprite
ld hl, vNPCSprites
- lb bc, BANK(BirdSprite), $0c
+ lb bc, BANK(BirdSprite), 12
call CopyVideoData
- ld de, BirdSprite + $c0 ; moving animation sprite
+ ld de, BirdSprite tile 12 ; moving animation sprite
ld hl, vNPCSprites2
- lb bc, BANK(BirdSprite), $0c
+ lb bc, BANK(BirdSprite), 12
jp CopyVideoData
InitFacingDirectionList:
@@ -358,7 +358,7 @@ IsPlayerStandingOnWarpPadOrHole::
jr z, .done
cp c
jr nz, .nextEntry
- aCoord 8, 9
+ lda_coord 8, 9
cp [hl]
jr z, .foundMatch
.nextEntry
@@ -381,8 +381,8 @@ FishingAnim:
ld hl, wd736
set 6, [hl] ; reserve the last 4 OAM entries
ld de, RedSprite
- ld hl, vNPCSprites
- lb bc, BANK(RedSprite), $c
+ ld hl, vNPCSprites tile $00
+ lb bc, BANK(RedSprite), 12
call CopyVideoData
ld a, $4
ld hl, RedFishingTiles
@@ -479,22 +479,18 @@ FishingRodOAM:
db $50, $40, $FE, $00 ; player facing left
db $50, $58, $FE, $20 ; player facing right ($20 means "horizontally flip the tile")
-RedFishingTiles:
- dw RedFishingTilesFront
- db 2, BANK(RedFishingTilesFront)
- dw vNPCSprites + $20
+fishing_gfx: MACRO
+ dw \1
+ db \2
+ db BANK(\1)
+ dw vNPCSprites tile \3
+ENDM
- dw RedFishingTilesBack
- db 2, BANK(RedFishingTilesBack)
- dw vNPCSprites + $60
-
- dw RedFishingTilesSide
- db 2, BANK(RedFishingTilesSide)
- dw vNPCSprites + $a0
-
- dw RedFishingRodTiles
- db 3, BANK(RedFishingRodTiles)
- dw vNPCSprites2 + $7d0
+RedFishingTiles:
+ fishing_gfx RedFishingTilesFront, 2, $02
+ fishing_gfx RedFishingTilesBack, 2, $06
+ fishing_gfx RedFishingTilesSide, 2, $0a
+ fishing_gfx RedFishingRodTiles, 3, $fd
_HandleMidJump::
ld a, [wPlayerJumpingYScreenCoordsIndex]
@@ -516,9 +512,9 @@ _HandleMidJump::
call UpdateSprites
call Delay3
xor a
- ld [hJoyHeld], a
- ld [hJoyPressed], a
- ld [hJoyReleased], a
+ ldh [hJoyHeld], a
+ ldh [hJoyPressed], a
+ ldh [hJoyReleased], a
ld [wPlayerJumpingYScreenCoordsIndex], a
ld hl, wd736
res 6, [hl] ; not jumping down a ledge any more
diff --git a/engine/overworld/player_state.asm b/engine/overworld/player_state.asm
index 9ff67df8..70326754 100644
--- a/engine/overworld/player_state.asm
+++ b/engine/overworld/player_state.asm
@@ -17,7 +17,7 @@ IsPlayerStandingOnWarp::
ld a, [hli] ; target warp
ld [wDestinationWarpID], a
ld a, [hl] ; target map
- ld [hWarpDestinationMap], a
+ ldh [hWarpDestinationMap], a
ld hl, wd736
set 2, [hl] ; standing on warp flag
ret
@@ -192,7 +192,7 @@ IsPlayerStandingOnDoorTileOrWarpTile::
push hl
push de
push bc
- callba IsPlayerStandingOnDoorTile
+ farcall IsPlayerStandingOnDoorTile
jr c, .done
ld a, [wCurMapTileset]
add a
@@ -204,7 +204,7 @@ IsPlayerStandingOnDoorTileOrWarpTile::
ld h, [hl]
ld l, a
ld de, $1
- aCoord 8, 9
+ lda_coord 8, 9
call IsInArray
jr nc, .done
ld hl, wd736
@@ -223,28 +223,28 @@ PrintSafariZoneSteps::
ret c
cp CERULEAN_CAVE_2F
ret nc
- coord hl, 0, 0
+ hlcoord 0, 0
ld b, 3
ld c, 7
call TextBoxBorder
- coord hl, 1, 1
+ hlcoord 1, 1
ld de, wSafariSteps
lb bc, 2, 3
call PrintNumber
- coord hl, 4, 1
+ hlcoord 4, 1
ld de, SafariSteps
call PlaceString
- coord hl, 1, 3
+ hlcoord 1, 3
ld de, SafariBallText
call PlaceString
ld a, [wNumSafariBalls]
cp 10
jr nc, .asm_c56d
- coord hl, 5, 3
+ hlcoord 5, 3
ld a, " "
ld [hl], a
.asm_c56d
- coord hl, 6, 3
+ hlcoord 6, 3
ld de, wNumSafariBalls
lb bc, 1, 2
jp PrintNumber
@@ -267,28 +267,28 @@ _GetTileAndCoordsInFrontOfPlayer:
and a ; cp SPRITE_FACING_DOWN
jr nz, .notFacingDown
; facing down
- aCoord 8, 11
+ lda_coord 8, 11
inc d
jr .storeTile
.notFacingDown
cp SPRITE_FACING_UP
jr nz, .notFacingUp
; facing up
- aCoord 8, 7
+ lda_coord 8, 7
dec d
jr .storeTile
.notFacingUp
cp SPRITE_FACING_LEFT
jr nz, .notFacingLeft
; facing left
- aCoord 6, 9
+ lda_coord 6, 9
dec e
jr .storeTile
.notFacingLeft
cp SPRITE_FACING_RIGHT
jr nz, .storeTile
; facing right
- aCoord 10, 9
+ lda_coord 10, 9
inc e
.storeTile
ld c, a
@@ -297,7 +297,7 @@ _GetTileAndCoordsInFrontOfPlayer:
GetTileTwoStepsInFrontOfPlayer:
xor a
- ld [hPlayerFacing], a
+ ldh [hPlayerFacing], a
ld hl, wYCoord
ld a, [hli]
ld d, a
@@ -308,7 +308,7 @@ GetTileTwoStepsInFrontOfPlayer:
; facing down
ld hl, hPlayerFacing
set 0, [hl]
- aCoord 8, 13
+ lda_coord 8, 13
inc d
jr .storeTile
.notFacingDown
@@ -317,7 +317,7 @@ GetTileTwoStepsInFrontOfPlayer:
; facing up
ld hl, hPlayerFacing
set 1, [hl]
- aCoord 8, 5
+ lda_coord 8, 5
dec d
jr .storeTile
.notFacingUp
@@ -326,7 +326,7 @@ GetTileTwoStepsInFrontOfPlayer:
; facing left
ld hl, hPlayerFacing
set 2, [hl]
- aCoord 4, 9
+ lda_coord 4, 9
dec e
jr .storeTile
.notFacingLeft
@@ -335,7 +335,7 @@ GetTileTwoStepsInFrontOfPlayer:
; facing right
ld hl, hPlayerFacing
set 3, [hl]
- aCoord 12, 9
+ lda_coord 12, 9
inc e
.storeTile
ld c, a
@@ -378,33 +378,33 @@ CheckForBoulderCollisionWithSprites:
ld hl, wSprite01StateData2MapY
add hl, de
ld a, [hli] ; map Y position
- ld [hPlayerYCoord], a
+ ldh [hPlayerYCoord], a
ld a, [hl] ; map X position
- ld [hPlayerXCoord], a
+ ldh [hPlayerXCoord], a
ld a, [wNumSprites]
ld c, a
ld de, $f
ld hl, wSprite01StateData2MapY
- ld a, [hPlayerFacing]
+ ldh a, [hPlayerFacing]
and $3 ; facing up or down?
jr z, .pushingHorizontallyLoop
.pushingVerticallyLoop
inc hl
- ld a, [hPlayerXCoord]
+ ldh a, [hPlayerXCoord]
cp [hl]
jr nz, .nextSprite1 ; if X coordinates don't match
dec hl
ld a, [hli]
ld b, a
- ld a, [hPlayerFacing]
+ ldh a, [hPlayerFacing]
rrca
jr c, .pushingDown
; pushing up
- ld a, [hPlayerYCoord]
+ ldh a, [hPlayerYCoord]
dec a
jr .compareYCoords
.pushingDown
- ld a, [hPlayerYCoord]
+ ldh a, [hPlayerYCoord]
inc a
.compareYCoords
cp b
@@ -417,19 +417,19 @@ CheckForBoulderCollisionWithSprites:
.pushingHorizontallyLoop
ld a, [hli]
ld b, a
- ld a, [hPlayerYCoord]
+ ldh a, [hPlayerYCoord]
cp b
jr nz, .nextSprite2
ld b, [hl]
- ld a, [hPlayerFacing]
+ ldh a, [hPlayerFacing]
bit 2, a
jr nz, .pushingLeft
; pushing right
- ld a, [hPlayerXCoord]
+ ldh a, [hPlayerXCoord]
inc a
jr .compareXCoords
.pushingLeft
- ld a, [hPlayerXCoord]
+ ldh a, [hPlayerXCoord]
dec a
.compareXCoords
cp b
diff --git a/engine/overworld/push_boulder.asm b/engine/overworld/push_boulder.asm
index da1c6dee..4cef8b64 100644
--- a/engine/overworld/push_boulder.asm
+++ b/engine/overworld/push_boulder.asm
@@ -6,15 +6,15 @@ TryPushingBoulder::
bit 1, a ; has boulder dust animation from previous push played yet?
ret nz
xor a
- ld [hSpriteIndexOrTextID], a
+ ldh [hSpriteIndexOrTextID], a
call IsSpriteInFrontOfPlayer
- ld a, [hSpriteIndexOrTextID]
+ ldh a, [hSpriteIndexOrTextID]
ld [wBoulderSpriteIndex], a
and a
jp z, ResetBoulderPushFlags
ld hl, wSpritePlayerStateData1MovementStatus
ld d, $0
- ld a, [hSpriteIndexOrTextID]
+ ldh a, [hSpriteIndexOrTextID]
swap a
ld e, a
add hl, de
@@ -27,14 +27,14 @@ TryPushingBoulder::
bit 6, [hl]
set 6, [hl] ; indicate that the player has tried pushing
ret z ; the player must try pushing twice before the boulder will move
- ld a, [hJoyHeld]
+ ldh a, [hJoyHeld]
and D_RIGHT | D_LEFT | D_UP | D_DOWN
ret z
predef CheckForCollisionWhenPushingBoulder
ld a, [wTileInFrontOfBoulderAndBoulderCollisionResult]
and a ; was there a collision?
jp nz, ResetBoulderPushFlags
- ld a, [hJoyHeld]
+ ldh a, [hJoyHeld]
ld b, a
ld a, [wSpritePlayerStateData1FacingDirection]
cp SPRITE_FACING_UP
@@ -86,13 +86,13 @@ DoBoulderDustAnimation::
ld a, [wd730]
bit 0, a
ret nz
- callab AnimateBoulderDust
+ callfar AnimateBoulderDust
call DiscardButtonPresses
ld [wJoyIgnore], a
call ResetBoulderPushFlags
set 7, [hl]
ld a, [wBoulderSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
call GetSpriteMovementByte2Pointer
ld [hl], $10
ld a, SFX_CUT
diff --git a/engine/overworld/special_warps.asm b/engine/overworld/special_warps.asm
index 042146f9..54471ee0 100644
--- a/engine/overworld/special_warps.asm
+++ b/engine/overworld/special_warps.asm
@@ -34,7 +34,7 @@ LoadSpecialWarpData:
cp TRADE_CENTER
jr nz, .notTradeCenter
ld hl, TradeCenterSpec1
- ld a, [hSerialConnectionStatus]
+ ldh a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK ; which gameboy is clocking determines who is on the left and who is on the right
jr z, .copyWarpData
ld hl, TradeCenterSpec2
@@ -43,7 +43,7 @@ LoadSpecialWarpData:
cp COLOSSEUM
jr nz, .notColosseum
ld hl, ColosseumSpec1
- ld a, [hSerialConnectionStatus]
+ ldh a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
jr z, .copyWarpData
ld hl, ColosseumSpec2
diff --git a/engine/overworld/sprite_collisions.asm b/engine/overworld/sprite_collisions.asm
index 48cd95b9..dc57d5b9 100644
--- a/engine/overworld/sprite_collisions.asm
+++ b/engine/overworld/sprite_collisions.asm
@@ -1,15 +1,15 @@
_UpdateSprites::
ld h, $c1
inc h
- ld a, wSpritePlayerStateData2ImageBaseOffset - wSpritePlayerStateData2
+ ld a, SPRITESTATEDATA2_IMAGEBASEOFFSET
.spriteLoop
ld l, a
- sub wSpritePlayerStateData2ImageBaseOffset - wSpritePlayerStateData2
+ sub SPRITESTATEDATA2_IMAGEBASEOFFSET
ld c, a
- ld [hCurrentSpriteOffset], a
+ ldh [hCurrentSpriteOffset], a
ld a, [hl]
and a
- jr z, .skipSprite ; tests $c2Xe
+ jr z, .skipSprite ; tests SPRITESTATEDATA2_IMAGEBASEOFFSET
push hl
push de
push bc
@@ -20,7 +20,7 @@ _UpdateSprites::
.skipSprite
ld a, l
add $10 ; move to next sprite
- cp wSpritePlayerStateData2ImageBaseOffset - wSpritePlayerStateData2 ; test for overflow (back at beginning)
+ cp SPRITESTATEDATA2_IMAGEBASEOFFSET ; test for overflow (back at beginning)
jr nz, .spriteLoop
ret
.updateCurrentSprite
@@ -31,10 +31,10 @@ _UpdateSprites::
UpdateNonPlayerSprite:
dec a
swap a
- ld [hTilePlayerStandingOn], a ; $10 * sprite#
+ ldh [hTilePlayerStandingOn], a ; $10 * sprite#
ld a, [wNPCMovementScriptSpriteOffset] ; some sprite offset?
ld b, a
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
cp b
jr nz, .unequal
jp DoScriptedNPCMovement
@@ -43,22 +43,23 @@ UpdateNonPlayerSprite:
; This detects if the current sprite (whose offset is at hCurrentSpriteOffset)
; is going to collide with another sprite by looping over the other sprites.
-; The current sprite's offset will be labelled with i (e.g. $c1i0).
-; The loop sprite's offset will labelled with j (e.g. $c1j0).
+; The current sprite's offset will be labelled with i (e.g. i#SPRITESTATEDATA1_PICTUREID).
+; The loop sprite's offset will labelled with j (e.g. j#SPRITESTATEDATA1_PICTUREID).
;
-; Note that the Y coordinate of the sprite (in [$c1k4]) is one of the following
-; 9 values when the sprite is aligned with the grid: $fc, $0c, $1c, $2c, ..., $7c.
+; Note that the Y coordinate of the sprite (in [k#SPRITESTATEDATA1_YPIXELS])
+; is one of the following 9 values when the sprite is aligned with the grid:
+; $fc, $0c, $1c, $2c, ..., $7c.
; The reason that 4 is added below to the coordinate is to make it align with a
; multiple of $10 to make comparisons easier.
DetectCollisionBetweenSprites:
nop
- ld h, wSpriteStateData1 / $100
- ld a, [hCurrentSpriteOffset]
- add wSpriteStateData1 % $100
+ ld h, HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
+ add LOW(wSpriteStateData1)
ld l, a
- ld a, [hl] ; a = [$c1i0] (picture) (0 if slot is unused)
+ ld a, [hl] ; a = [i#SPRITESTATEDATA1_PICTUREID] (0 if slot is unused)
and a ; is this sprite slot slot used?
ret z ; return if not used
@@ -66,10 +67,10 @@ DetectCollisionBetweenSprites:
add 3
ld l, a
- ld a, [hli] ; a = [$c1i3] (delta Y) (-1, 0, or 1)
+ ld a, [hli] ; a = [i#SPRITESTATEDATA1_YSTEPVECTOR] (-1, 0, or 1)
call SetSpriteCollisionValues
- ld a, [hli] ; a = [$C1i4] (Y screen coordinate)
+ ld a, [hli] ; a = [i#SPRITESTATEDATA1_YPIXELS]
add 4 ; align with multiple of $10
; The effect of the following 3 lines is to
@@ -79,11 +80,11 @@ DetectCollisionBetweenSprites:
and $f0
or c
- ld [hFF90], a ; store Y coordinate adjusted for direction of movement
+ ldh [hFF90], a ; store Y coordinate adjusted for direction of movement
- ld a, [hli] ; a = [$c1i5] (delta X) (-1, 0, or 1)
+ ld a, [hli] ; a = [i#SPRITESTATEDATA1_XSTEPVECTOR] (-1, 0, or 1)
call SetSpriteCollisionValues
- ld a, [hl] ; a = [$C1i6] (X screen coordinate)
+ ld a, [hl] ; a = [i#SPRITESTATEDATA1_XPIXELS]
; The effect of the following 3 lines is to
; add 7 to a if moving east or
@@ -92,52 +93,52 @@ DetectCollisionBetweenSprites:
and $f0
or c
- ld [hFF91], a ; store X coordinate adjusted for direction of movement
+ ldh [hFF91], a ; store X coordinate adjusted for direction of movement
ld a, l
add 7
ld l, a
xor a
- ld [hld], a ; zero [$c1id] XXX what's [$c1id] for?
- ld [hld], a ; zero [$c1ic] (directions in which collisions occurred)
+ ld [hld], a ; zero [i#SPRITESTATEDATA1_0D] XXX what's this for?
+ ld [hld], a ; zero [i#SPRITESTATEDATA1_COLLISIONDATA]
- ld a, [hFF91]
- ld [hld], a ; [$c1ib] = adjusted X coordinate
- ld a, [hFF90]
- ld [hl], a ; [$c1ia] = adjusted Y coordinate
+ ldh a, [hFF91]
+ ld [hld], a ; [i#SPRITESTATEDATA1_XADJUSTED]
+ ldh a, [hFF90]
+ ld [hl], a ; [i#SPRITESTATEDATA1_YADJUSTED]
xor a ; zero the loop counter
.loop
- ld [hFF8F], a ; store loop counter
+ ldh [hFF8F], a ; store loop counter
swap a
ld e, a
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
cp e ; does the loop sprite match the current sprite?
jp z, .next ; go to the next sprite if they match
ld d, h
- ld a, [de] ; a = [$c1j0] (picture) (0 if slot is unused)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_PICTUREID] (0 if slot is unused)
and a ; is this sprite slot slot used?
jp z, .next ; go the next sprite if not used
inc e
inc e
- ld a, [de] ; a = [$c1j2] ($ff means the sprite is offscreen)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_IMAGEINDEX] ($ff means the sprite is offscreen)
inc a
jp z, .next ; go the next sprite if offscreen
- ld a, [hCurrentSpriteOffset]
+ ldh a, [hCurrentSpriteOffset]
add 10
ld l, a
inc e
- ld a, [de] ; a = [$c1j3] (delta Y)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_YSTEPVECTOR]
call SetSpriteCollisionValues
inc e
- ld a, [de] ; a = [$C1j4] (Y screen coordinate)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_YPIXELS]
add 4 ; align with multiple of $10
; The effect of the following 3 lines is to
@@ -147,18 +148,18 @@ DetectCollisionBetweenSprites:
and $f0
or c
- sub [hl] ; subtract the adjusted Y coordinate of sprite i ([$c1ia]) from that of sprite j
+ sub [hl] ; subtract [i#SPRITESTATEDATA1_YADJUSTED] from [j#SPRITESTATEDATA1_YADJUSTED]
; calculate the absolute value of the difference to get the distance
jr nc, .noCarry1
cpl
inc a
.noCarry1
- ld [hFF90], a ; store the distance between the two sprites' adjusted Y values
+ ldh [hFF90], a ; store the distance between the two sprites' adjusted Y values
; Use the carry flag set by the above subtraction to determine which sprite's
-; Y coordinate is larger. This information is used later to set [$c1ic],
-; which stores which direction the collision occurred in.
+; Y coordinate is larger. This information is used later to set
+; [i#SPRITESTATEDATA1_COLLISIONDATA].
; The following 5 lines set the lowest 2 bits of c, which are later shifted left by 2.
; If sprite i's Y is larger, set lowest 2 bits of c to 10.
; If sprite j's Y is larger or both are equal, set lowest 2 bits of c to 01.
@@ -170,30 +171,30 @@ DetectCollisionBetweenSprites:
; If sprite i's delta Y is 0, then b = 7, else b = 9.
ld b, 7
- ld a, [hl] ; a = [$c1ia] (adjusted Y coordinate)
+ ld a, [hl] ; a = [i#SPRITESTATEDATA1_YADJUSTED]
and $f
jr z, .next1
ld b, 9
.next1
- ld a, [hFF90] ; a = distance between adjusted Y coordinates
+ ldh a, [hFF90] ; a = distance between adjusted Y coordinates
sub b
- ld [hFF92], a ; store distance adjusted using sprite i's direction
+ ldh [hFF92], a ; store distance adjusted using sprite i's direction
ld a, b
- ld [hFF90], a ; store 7 or 9 depending on sprite i's delta Y
+ ldh [hFF90], a ; store 7 or 9 depending on sprite i's delta Y
jr c, .checkXDistance
; If sprite j's delta Y is 0, then b = 7, else b = 9.
ld b, 7
dec e
- ld a, [de] ; a = [$c1j3] (delta Y)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_YSTEPVECTOR]
inc e
and a
jr z, .next2
ld b, 9
.next2
- ld a, [hFF92] ; a = distance adjusted using sprite i's direction
+ ldh a, [hFF92] ; a = distance adjusted using sprite i's direction
sub b ; adjust distance using sprite j's direction
jr z, .checkXDistance
jr nc, .next ; go to next sprite if distance is still positive after both adjustments
@@ -201,13 +202,13 @@ DetectCollisionBetweenSprites:
.checkXDistance
inc e
inc l
- ld a, [de] ; a = [$c1j5] (delta X)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_XSTEPVECTOR]
push bc
call SetSpriteCollisionValues
inc e
- ld a, [de] ; a = [$c1j6] (X screen coordinate)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_XPIXELS]
; The effect of the following 3 lines is to
; add 7 to a if moving east or
@@ -218,18 +219,18 @@ DetectCollisionBetweenSprites:
pop bc
- sub [hl] ; subtract the adjusted X coordinate of sprite i ([$c1ib]) from that of sprite j
+ sub [hl] ; subtract [i#SPRITESTATEDATA1_XADJUSTED] from [j#SPRITESTATEDATA1_XADJUSTED]
; calculate the absolute value of the difference to get the distance
jr nc, .noCarry2
cpl
inc a
.noCarry2
- ld [hFF91], a ; store the distance between the two sprites' adjusted X values
+ ldh [hFF91], a ; store the distance between the two sprites' adjusted X values
; Use the carry flag set by the above subtraction to determine which sprite's
-; X coordinate is larger. This information is used later to set [$c1ic],
-; which stores which direction the collision occurred in.
+; X coordinate is larger. This information is used later to set
+; [i#SPRITESTATEDATA1_COLLISIONDATA].
; The following 5 lines set the lowest 2 bits of c.
; If sprite i's X is larger, set lowest 2 bits of c to 10.
; If sprite j's X is larger or both are equal, set lowest 2 bits of c to 01.
@@ -241,38 +242,38 @@ DetectCollisionBetweenSprites:
; If sprite i's delta X is 0, then b = 7, else b = 9.
ld b, 7
- ld a, [hl] ; a = [$c1ib] (adjusted X coordinate)
+ ld a, [hl] ; a = [i#SPRITESTATEDATA1_XADJUSTED]
and $f
jr z, .next3
ld b, 9
.next3
- ld a, [hFF91] ; a = distance between adjusted X coordinates
+ ldh a, [hFF91] ; a = distance between adjusted X coordinates
sub b
- ld [hFF92], a ; store distance adjusted using sprite i's direction
+ ldh [hFF92], a ; store distance adjusted using sprite i's direction
ld a, b
- ld [hFF91], a ; store 7 or 9 depending on sprite i's delta X
+ ldh [hFF91], a ; store 7 or 9 depending on sprite i's delta X
jr c, .collision
; If sprite j's delta X is 0, then b = 7, else b = 9.
ld b, 7
dec e
- ld a, [de] ; a = [$c1j5] (delta X)
+ ld a, [de] ; a = [j#SPRITESTATEDATA1_XSTEPVECTOR]
inc e
and a
jr z, .next4
ld b, 9
.next4
- ld a, [hFF92] ; a = distance adjusted using sprite i's direction
+ ldh a, [hFF92] ; a = distance adjusted using sprite i's direction
sub b ; adjust distance using sprite j's direction
jr z, .collision
jr nc, .next ; go to next sprite if distance is still positive after both adjustments
.collision
- ld a, [hFF91] ; a = 7 or 9 depending on sprite i's delta X
+ ldh a, [hFF91] ; a = 7 or 9 depending on sprite i's delta X
ld b, a
- ld a, [hFF90] ; a = 7 or 9 depending on sprite i's delta Y
+ ldh a, [hFF90] ; a = 7 or 9 depending on sprite i's delta Y
inc l
; If delta X isn't 0 and delta Y is 0, then b = %0011, else b = %1100.
@@ -287,14 +288,15 @@ DetectCollisionBetweenSprites:
.next6
ld a, c ; c has 2 bits set (one of bits 0-1 is set for the X axis and one of bits 2-3 for the Y axis)
and b ; we select either the bit in bits 0-1 or bits 2-3 based on the calculation immediately above
- or [hl] ; or with existing collision direction bits in [$c1ic]
+ or [hl] ; or with existing collision direction bits in [i#SPRITESTATEDATA1_COLLISIONDATA]
ld [hl], a ; store new value
ld a, c ; useless code because a is overwritten before being used again
-; set bit in [$c1ie] or [$c1if] to indicate which sprite the collision occurred with
+; set bit in [i#SPRITESTATEDATA1_0E] or [i#SPRITESTATEDATA1_0F]
+; to indicate which sprite the collision occurred with
inc l
inc l
- ld a, [hFF8F] ; a = loop counter
+ ldh a, [hFF8F] ; a = loop counter
ld de, SpriteCollisionBitTable
add a
add e
@@ -311,7 +313,7 @@ DetectCollisionBetweenSprites:
ld [hl], a
.next
- ld a, [hFF8F] ; a = loop counter
+ ldh a, [hFF8F] ; a = loop counter
inc a
cp $10
jp nz, .loop
diff --git a/engine/overworld/tilesets.asm b/engine/overworld/tilesets.asm
index 88147233..f40cbbc2 100644
--- a/engine/overworld/tilesets.asm
+++ b/engine/overworld/tilesets.asm
@@ -23,9 +23,9 @@ LoadTilesetHeader:
dec c
jr nz, .copyTilesetHeaderLoop
ld a, [hl]
- ld [hTilesetType], a
+ ldh [hTilesetType], a
xor a
- ld [hMovingBGTilesCounter1], a
+ ldh [hMovingBGTilesCounter1], a
pop hl
ld a, [wCurMapTileset]
push hl
@@ -38,7 +38,7 @@ LoadTilesetHeader:
jr c, .asm_c797
ld a, [wCurMapTileset]
ld b, a
- ld a, [hPreviousTileset]
+ ldh a, [hPreviousTileset]
cp b
jr z, .done
.asm_c797
diff --git a/engine/overworld/trainer_sight.asm b/engine/overworld/trainer_sight.asm
index c12c064b..816dea7f 100755
--- a/engine/overworld/trainer_sight.asm
+++ b/engine/overworld/trainer_sight.asm
@@ -1,77 +1,77 @@
_GetSpritePosition1::
ld hl, wSpriteStateData1
- ld de, wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ ld de, SPRITESTATEDATA1_YPIXELS
ld a, [wSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
call GetSpriteDataPointer
- ld a, [hli] ; c1x4 (screen Y pos)
- ld [hSpriteScreenYCoord], a
+ ld a, [hli] ; x#SPRITESTATEDATA1_YPIXELS
+ ldh [hSpriteScreenYCoord], a
inc hl
- ld a, [hl] ; c1x6 (screen X pos)
- ld [hSpriteScreenXCoord], a
+ ld a, [hl] ; x#SPRITESTATEDATA1_XPIXELS
+ ldh [hSpriteScreenXCoord], a
ld de, wSpritePlayerStateData2MapY - wSpritePlayerStateData1XPixels
add hl, de
- ld a, [hli] ; c2x4 (map Y pos)
- ld [hSpriteMapYCoord], a
- ld a, [hl] ; c2x5 (map X pos)
- ld [hSpriteMapXCoord], a
+ ld a, [hli] ; x#SPRITESTATEDATA2_MAPY
+ ldh [hSpriteMapYCoord], a
+ ld a, [hl] ; x#SPRITESTATEDATA2_MAPX
+ ldh [hSpriteMapXCoord], a
ret
_GetSpritePosition2::
ld hl, wSpriteStateData1
- ld de, wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ ld de, SPRITESTATEDATA1_YPIXELS
ld a, [wSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
call GetSpriteDataPointer
- ld a, [hli] ; c1x4 (screen Y pos)
+ ld a, [hli] ; x#SPRITESTATEDATA1_YPIXELS
ld [wSavedSpriteScreenY], a
inc hl
- ld a, [hl] ; c1x6 (screen X pos)
+ ld a, [hl] ; x#SPRITESTATEDATA1_XPIXELS
ld [wSavedSpriteScreenX], a
ld de, wSpritePlayerStateData2MapY - wSpritePlayerStateData1XPixels
add hl, de
- ld a, [hli] ; c2x4 (map Y pos)
+ ld a, [hli] ; x#SPRITESTATEDATA2_MAPY
ld [wSavedSpriteMapY], a
- ld a, [hl] ; c2x5 (map X pos)
+ ld a, [hl] ; x#SPRITESTATEDATA2_MAPX
ld [wSavedSpriteMapX], a
ret
_SetSpritePosition1::
ld hl, wSpriteStateData1
- ld de, wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ ld de, SPRITESTATEDATA1_YPIXELS
ld a, [wSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
call GetSpriteDataPointer
- ld a, [hSpriteScreenYCoord] ; c1x4 (screen Y pos)
+ ldh a, [hSpriteScreenYCoord] ; x#SPRITESTATEDATA1_YPIXELS
ld [hli], a
inc hl
- ld a, [hSpriteScreenXCoord] ; c1x6 (screen X pos)
+ ldh a, [hSpriteScreenXCoord] ; x#SPRITESTATEDATA1_XPIXELS
ld [hl], a
ld de, wSpritePlayerStateData2MapY - wSpritePlayerStateData1XPixels
add hl, de
- ld a, [hSpriteMapYCoord] ; c2x4 (map Y pos)
+ ldh a, [hSpriteMapYCoord] ; x#SPRITESTATEDATA2_MAPY
ld [hli], a
- ld a, [hSpriteMapXCoord] ; c2x5 (map X pos)
+ ldh a, [hSpriteMapXCoord] ; x#SPRITESTATEDATA2_MAPX
ld [hl], a
ret
_SetSpritePosition2::
ld hl, wSpriteStateData1
- ld de, wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ ld de, SPRITESTATEDATA1_YPIXELS
ld a, [wSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
call GetSpriteDataPointer
ld a, [wSavedSpriteScreenY]
- ld [hli], a ; c1x4 (screen Y pos)
+ ld [hli], a ; x#SPRITESTATEDATA1_YPIXELS
inc hl
ld a, [wSavedSpriteScreenX]
- ld [hl], a ; c1x6 (screen X pos)
+ ld [hl], a ; x#SPRITESTATEDATA1_XPIXELS
ld de, wSpritePlayerStateData2MapY - wSpritePlayerStateData1XPixels
add hl, de
ld a, [wSavedSpriteMapY]
- ld [hli], a ; c2x4 (map Y pos)
+ ld [hli], a ; x#SPRITESTATEDATA2_MAPY
ld a, [wSavedSpriteMapX]
- ld [hl], a ; c2x5 (map X pos)
+ ld [hl], a ; x#SPRITESTATEDATA2_MAPX
ret
TrainerWalkUpToPlayer::
@@ -144,7 +144,7 @@ TrainerWalkUpToPlayer::
call FillMemory ; write the necessary steps to reach player
ld [hl], $ff ; write end of list sentinel
ld a, [wSpriteIndex]
- ld [hSpriteIndex], a
+ ldh [hSpriteIndex], a
jp MoveSprite_
; input: de = offset within sprite entry
@@ -152,7 +152,7 @@ TrainerWalkUpToPlayer::
GetSpriteDataPointer:
push de
add hl, de
- ld a, [hSpriteIndex]
+ ldh a, [hSpriteIndex]
swap a
ld d, $0
ld e, a
@@ -165,23 +165,23 @@ TrainerEngage:
push hl
push de
ld a, [wTrainerSpriteOffset]
- add wSpritePlayerStateData1ImageIndex - wSpritePlayerStateData1
+ add SPRITESTATEDATA1_IMAGEINDEX
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl] ; c1x2: sprite image index
+ ld a, [hl] ; x#SPRITESTATEDATA1_IMAGEINDEX
sub $ff
jr nz, .spriteOnScreen ; test if sprite is on screen
jp .noEngage
.spriteOnScreen
ld a, [wTrainerSpriteOffset]
- add wSpritePlayerStateData1FacingDirection - wSpritePlayerStateData1
+ add SPRITESTATEDATA1_FACINGDIRECTION
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl] ; c1x9: facing direction
+ ld a, [hl] ; x#SPRITESTATEDATA1_FACINGDIRECTION
ld [wTrainerFacingDirection], a
call ReadTrainerScreenPosition
ld a, [wTrainerScreenY] ; sprite screen Y pos
@@ -234,20 +234,20 @@ TrainerEngage:
; reads trainer's Y position to wTrainerScreenY and X position to wTrainerScreenX
ReadTrainerScreenPosition:
ld a, [wTrainerSpriteOffset]
- add wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ add SPRITESTATEDATA1_YPIXELS
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl] ; c1x4 (sprite Y pos)
+ ld a, [hl] ; x#SPRITESTATEDATA1_YPIXELS
ld [wTrainerScreenY], a
ld a, [wTrainerSpriteOffset]
- add wSpritePlayerStateData1XPixels - wSpritePlayerStateData1
+ add SPRITESTATEDATA1_XPIXELS
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl] ; c1x6 (sprite X pos)
+ ld a, [hl] ; x#SPRITESTATEDATA1_XPIXELS
ld [wTrainerScreenX], a
ret
@@ -295,24 +295,24 @@ CheckPlayerIsInFrontOfSprite:
cp POWER_PLANT
jp z, .engage ; bypass this for power plant to get voltorb fake items to work
ld a, [wTrainerSpriteOffset]
- add wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
+ add SPRITESTATEDATA1_YPIXELS
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl] ; c1x4 (sprite screen Y pos)
+ ld a, [hl] ; x#SPRITESTATEDATA1_YPIXELS
cp $fc
jr nz, .notOnTopmostTile ; special case if sprite is on topmost tile (Y = $fc (-4)), make it come down a block
ld a, $c
.notOnTopmostTile
ld [wTrainerScreenY], a
ld a, [wTrainerSpriteOffset]
- add wSpritePlayerStateData1XPixels - wSpritePlayerStateData1
+ add SPRITESTATEDATA1_XPIXELS
ld d, $0
ld e, a
ld hl, wSpriteStateData1
add hl, de
- ld a, [hl] ; c1x6 (sprite screen X pos)
+ ld a, [hl] ; x#SPRITESTATEDATA1_XPIXELS
ld [wTrainerScreenX], a
ld a, [wTrainerFacingDirection] ; facing direction
cp SPRITE_FACING_DOWN
diff --git a/engine/overworld/turn_sprite.asm b/engine/overworld/turn_sprite.asm
index bef26537..7b34a03a 100755
--- a/engine/overworld/turn_sprite.asm
+++ b/engine/overworld/turn_sprite.asm
@@ -1,25 +1,25 @@
UpdateSpriteFacingOffsetAndDelayMovement::
- ld h, $c2
- ld a, [hCurrentSpriteOffset]
+ ld h, HIGH(wSpriteStateData2)
+ ldh a, [hCurrentSpriteOffset]
add $8
ld l, a
ld a, $7f ; maximum movement delay
- ld [hl], a ; c2x8 (movement delay)
- dec h
- ld a, [hCurrentSpriteOffset]
+ ld [hl], a ; x#SPRITESTATEDATA2_MOVEMENTDELAY
+ dec h ; HIGH(wSpriteStateData1)
+ ldh a, [hCurrentSpriteOffset]
add $9
ld l, a
- ld a, [hld] ; c1x9 (facing direction)
+ ld a, [hld] ; x#SPRITESTATEDATA1_FACINGDIRECTION
ld b, a
xor a
ld [hld], a
- ld [hl], a ; c1x8 (walk animation frame)
- ld a, [hCurrentSpriteOffset]
- add $2
+ ld [hl], a ; x#SPRITESTATEDATA1_ANIMFRAMECOUNTER
+ ldh a, [hCurrentSpriteOffset]
+ add SPRITESTATEDATA1_IMAGEINDEX
ld l, a
- ld a, [hl] ; c1x2 (facing and animation table offset)
+ ld a, [hl] ; x#SPRITESTATEDATA1_IMAGEINDEX
or b ; or in the facing direction
ld [hld], a
ld a, $2 ; delayed movement status
- ld [hl], a ; c1x1 (movement status)
+ ld [hl], a ; x#SPRITESTATEDATA1_MOVEMENTSTATUS
ret
diff --git a/engine/overworld/update_map.asm b/engine/overworld/update_map.asm
index 92ae2b10..53a5592d 100644
--- a/engine/overworld/update_map.asm
+++ b/engine/overworld/update_map.asm
@@ -50,13 +50,13 @@ RedrawMapView:
ld a, [wIsInBattle]
inc a
ret z
- ld a, [hAutoBGTransferEnabled]
+ ldh a, [hAutoBGTransferEnabled]
push af
- ld a, [hTilesetType]
+ ldh a, [hTilesetType]
push af
xor a
- ld [hAutoBGTransferEnabled], a
- ld [hTilesetType], a ; no flower/water BG tile animations
+ ldh [hAutoBGTransferEnabled], a
+ ldh [hTilesetType], a ; no flower/water BG tile animations
call LoadCurrentMapView
call RunDefaultPaletteCommand
ld hl, wMapViewVRAMPointer
@@ -73,7 +73,7 @@ RedrawMapView:
ld a, h
ld [wBuffer + 1], a ; this copy of the address is not used
ld a, 2
- ld [hRedrawMapViewRowOffset], a
+ ldh [hRedrawMapViewRowOffset], a
ld c, SCREEN_HEIGHT / 2 ; number of rows of 2x2 tiles (this covers the whole screen)
.redrawRowLoop
push bc
@@ -81,7 +81,7 @@ RedrawMapView:
push hl
ld hl, wTileMap - 2 * SCREEN_WIDTH
ld de, SCREEN_WIDTH
- ld a, [hRedrawMapViewRowOffset]
+ ldh a, [hRedrawMapViewRowOffset]
.calcWRAMAddrLoop
add hl, de
dec a
@@ -89,7 +89,7 @@ RedrawMapView:
call CopyToRedrawRowOrColumnSrcTiles
pop hl
ld de, BG_MAP_WIDTH
- ld a, [hRedrawMapViewRowOffset]
+ ldh a, [hRedrawMapViewRowOffset]
ld c, a
.calcVRAMAddrLoop
add hl, de
@@ -98,11 +98,11 @@ RedrawMapView:
or $98
dec c
jr nz, .calcVRAMAddrLoop
- ld [hRedrawRowOrColumnDest + 1], a
+ ldh [hRedrawRowOrColumnDest + 1], a
ld a, l
- ld [hRedrawRowOrColumnDest], a
+ ldh [hRedrawRowOrColumnDest], a
ld a, REDRAW_ROW
- ld [hRedrawRowOrColumnMode], a
+ ldh [hRedrawRowOrColumnMode], a
call DelayFrame
ld hl, hRedrawMapViewRowOffset
inc [hl]
@@ -112,9 +112,9 @@ RedrawMapView:
dec c
jr nz, .redrawRowLoop
pop af
- ld [hTilesetType], a
+ ldh [hTilesetType], a
pop af
- ld [hAutoBGTransferEnabled], a
+ ldh [hAutoBGTransferEnabled], a
ret
CompareHLWithBC: