diff options
Diffstat (limited to 'engine/overworld')
-rwxr-xr-x | engine/overworld/cut.asm | 12 | ||||
-rwxr-xr-x | engine/overworld/cut2.asm | 2 | ||||
-rwxr-xr-x | engine/overworld/emotion_bubbles.asm | 24 | ||||
-rw-r--r-- | engine/overworld/movement.asm | 262 | ||||
-rwxr-xr-x | engine/overworld/npc_movement.asm | 100 | ||||
-rw-r--r-- | engine/overworld/oam.asm | 99 | ||||
-rwxr-xr-x | engine/overworld/player_animations.asm | 115 | ||||
-rwxr-xr-x | engine/overworld/pokemart.asm | 10 | ||||
-rwxr-xr-x | engine/overworld/ssanne.asm | 2 |
9 files changed, 340 insertions, 286 deletions
diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm index 26a65b5b..f7be269c 100755 --- a/engine/overworld/cut.asm +++ b/engine/overworld/cut.asm @@ -1,6 +1,6 @@ UsedCut: ; ef54 (3:6f54) xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ; initialise to failure value ld a, [W_CURMAPTILESET] and a ; OVERWORLD jr z, .asm_ef6b @@ -26,9 +26,9 @@ UsedCut: ; ef54 (3:6f54) db "@" .asm_ef82 - ld [wcd4d], a + ld [wCutTile], a ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ; used cut ld a, [wWhichPokemon] ld hl, wPartyMonNicks call GetPartyMonName @@ -73,10 +73,10 @@ UsedCutText: ; eff2 (3:6ff2) AnimateCutTree: ; eff7 (3:6ff7) xor a - ld [wcd50], a + ld [wWhichAnimationOffsets], a ld a, $e4 ld [rOBP1], a - ld a, [wcd4d] + ld a, [wCutTile] cp $52 jr z, .asm_f020 ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row @@ -138,7 +138,7 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068) srl a ld e, a ld d, $0 ; de holds direction (00: down, 02: up, 04: left, 06: right) - ld a, [wcd50] + ld a, [wWhichAnimationOffsets] and a ld hl, CutTreeAnimationOffsets jr z, .asm_f084 diff --git a/engine/overworld/cut2.asm b/engine/overworld/cut2.asm index 9cb011b4..3194b39b 100755 --- a/engine/overworld/cut2.asm +++ b/engine/overworld/cut2.asm @@ -1,5 +1,5 @@ Func_79e96: ; 79e96 (1e:5e96) - ld a, [wcd4d] + ld a, [wCutTile] cp $52 jr z, .asm_79ec8 ld c, $8 diff --git a/engine/overworld/emotion_bubbles.asm b/engine/overworld/emotion_bubbles.asm index 01b3ae85..22dfb24f 100755 --- a/engine/overworld/emotion_bubbles.asm +++ b/engine/overworld/emotion_bubbles.asm @@ -1,7 +1,7 @@ EmotionBubble: ; 17c47 (5:7c47) - ld a, [wcd50] + ld a, [wWhichEmotionBubble] ld c, a - ld b, $0 + ld b, 0 ld hl, EmotionBubblesPointerTable add hl, bc add hl, bc @@ -16,15 +16,18 @@ EmotionBubble: ; 17c47 (5:7c47) ld a, $ff ld [wUpdateSpritesEnabled], a ld a, [wd736] - bit 6, a + bit 6, a ; are the last 4 OAM entries reserved for a shadow or fishing rod? ld hl, wOAMBuffer + $8f ld de, wOAMBuffer + $9f - jr z, .asm_17c7a + jr z, .next ld hl, wOAMBuffer + $7f ld de, wOAMBuffer + $8f -.asm_17c7a + +; Copy OAM data 16 bytes forward to make room for emotion bubble OAM data at the +; start of the OAM buffer. +.next ld bc, $90 -.asm_17c7d +.loop ld a, [hl] ld [de], a dec hl @@ -32,12 +35,14 @@ EmotionBubble: ; 17c47 (5:7c47) dec bc ld a, c or b - jr nz, .asm_17c7d + jr nz, .loop + +; get the screen coordinates of the sprite the bubble is to be displayed above ld hl, wSpriteStateData1 + 4 - ld a, [wcd4f] + ld a, [wEmotionBubbleSpriteIndex] swap a ld c, a - ld b, $0 + ld b, 0 add hl, bc ld a, [hli] ld b, a @@ -45,6 +50,7 @@ EmotionBubble: ; 17c47 (5:7c47) ld a, [hl] add $8 ld c, a + ld de, EmotionBubblesOAM xor a call WriteOAMBlock diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm index 0cbb7f1c..30793dec 100644 --- a/engine/overworld/movement.asm +++ b/engine/overworld/movement.asm @@ -12,7 +12,7 @@ UpdatePlayerSprite: ; 4e31 (1:4e31) ; the maximum number for map tiles .checkIfTextBoxInFrontOfSprite aCoord 8, 9 - ld [$ff93], a + ld [hTilePlayerStandingOn], a cp $60 jr c, .lowerLeftTileIsMapTile .disableSprite @@ -21,52 +21,54 @@ UpdatePlayerSprite: ; 4e31 (1:4e31) ret .lowerLeftTileIsMapTile call DetectCollisionBetweenSprites - ld h, $c1 + ld h, wSpriteStateData1 / $100 ld a, [wWalkCounter] and a - jr nz, .asm_4e90 + jr nz, .moving ld a, [wd528] +; check if down bit 2, a - jr z, .notDown + jr z, .checkIfUp xor a ; ld a, SPRITE_FACING_DOWN - jr .done -.notDown + jr .next +.checkIfUp bit 3, a - jr z, .notUp + jr z, .checkIfLeft ld a, SPRITE_FACING_UP - jr .done -.notUp + jr .next +.checkIfLeft bit 1, a - jr z, .notLeft + jr z, .checkIfRight ld a, SPRITE_FACING_LEFT - jr .done -.notLeft + jr .next +.checkIfRight bit 0, a - jr z, .notRight + jr z, .notMoving ld a, SPRITE_FACING_RIGHT - jr .done -.notRight + jr .next +.notMoving +; zero the animation counters xor a ld [wSpriteStateData1 + 7], a ld [wSpriteStateData1 + 8], a - jr .asm_4eab -.done - ld [wSpriteStateData1 + 9], a + jr .calcImageIndex +.next + ld [wSpriteStateData1 + 9], a ; facing direction ld a, [wFontLoaded] bit 0, a - jr nz, .notRight -.asm_4e90 + jr nz, .notMoving +.moving ld a, [wd736] - bit 7, a - jr nz, .asm_4eb6 + bit 7, a ; is the player sprite spinning due to a spin tile? + jr nz, .skipSpriteAnim ld a, [H_CURRENTSPRITEOFFSET] add $7 ld l, a ld a, [hl] inc a ld [hl], a - cp $4 - jr nz, .asm_4eab + cp 4 + jr nz, .calcImageIndex xor a ld [hl], a inc hl @@ -74,28 +76,32 @@ UpdatePlayerSprite: ; 4e31 (1:4e31) inc a and $3 ld [hl], a -.asm_4eab +.calcImageIndex ld a, [wSpriteStateData1 + 8] ld b, a ld a, [wSpriteStateData1 + 9] add b ld [wSpriteStateData1 + 2], a -.asm_4eb6 - ld a, [$ff93] +.skipSpriteAnim +; If the player is standing on a grass tile, make the player's sprite have +; lower priority than the background so that it's partially obscured by the +; grass. Only the lower half of the sprite is permitted to have the priority +; bit set by later logic. + ld a, [hTilePlayerStandingOn] ld c, a ld a, [W_GRASSTILE] cp c ld a, $0 - jr nz, .asm_4ec3 + jr nz, .next2 ld a, $80 -.asm_4ec3 +.next2 ld [wSpriteStateData2 + $07], a ret -Func_4ec7: ; 4ec7 (1:4ec7) +UnusedReadSpriteDataFunction: ; 4ec7 (1:4ec7) push bc push af - ld a, [$ffda] + ld a, [H_CURRENTSPRITEOFFSET] ld c, a pop af add c @@ -103,7 +109,7 @@ Func_4ec7: ; 4ec7 (1:4ec7) pop bc ret -Func_4ed1: ; 4ed1 (1:4ed1) +UpdateNPCSprite: ; 4ed1 (1:4ed1) ld a, [H_CURRENTSPRITEOFFSET] swap a dec a @@ -148,40 +154,43 @@ Func_4ed1: ; 4ed1 (1:4ed1) ld l, a ld a, [hl] ; c2x6: movement byte 1 inc a - jr z, .asm_4f59 ; value $FF + jr z, .randomMovement ; value $FF inc a - jr z, .asm_4f59 ; value $FE + jr z, .randomMovement ; value $FE +; scripted movement dec a - ld [hl], a ; (temporarily) increment movement byte 1 + ld [hl], a ; increment movement byte 1 (movement data index) dec a push hl ld hl, wcf0f dec [hl] ; decrement wcf0f pop hl - ld de, wcc5b - call LoadDEPlusA ; a = [wcc5b + movement byte 1] + ld de, wNPCMovementDirections + call LoadDEPlusA ; a = [wNPCMovementDirections + movement byte 1] cp $e0 jp z, ChangeFacingDirection cp $ff - jr nz, .asm_4f4b - ld [hl], a ; reset movement byte 1 to initial value + jr nz, .next +; reached end of wNPCMovementDirections list + ld [hl], a ; store $ff in movement byte 1, disabling scripted movement ld hl, wd730 res 0, [hl] xor a ld [wSimulatedJoypadStatesIndex], a ld [wWastedByteCD3A], a ret -.asm_4f4b +.next cp $fe - jr nz, .asm_4f5f + jr nz, .determineDirection +; current NPC movement data is $fe. this seems buggy ld [hl], $1 ; set movement byte 1 to $1 - ld de, wcc5b - call LoadDEPlusA ; a = [wcc5b + $fe] (?) - jr .asm_4f5f -.asm_4f59 - call getTileSpriteStandsOn + ld de, wNPCMovementDirections + call LoadDEPlusA ; a = [wNPCMovementDirections + $fe] (?) + jr .determineDirection +.randomMovement + call GetTileSpriteStandsOn call Random -.asm_4f5f +.determineDirection ld b, a ld a, [wCurSpriteMovement2] cp $d0 @@ -199,7 +208,7 @@ Func_4ed1: ; 4ed1 (1:4ed1) cp $2 jr z, .moveLeft ; movement byte 2 = $2 only allows left or right .moveDown - ld de, 2*20 + ld de, 2*SCREEN_WIDTH add hl, de ; move tile pointer two rows down ld de, $100 @@ -212,7 +221,7 @@ Func_4ed1: ; 4ed1 (1:4ed1) cp $2 jr z, .moveRight ; movement byte 2 = $2 only allows left or right .moveUp - ld de, -2*20 + ld de, -2*SCREEN_WIDTH add hl, de ; move tile pointer two rows up ld de, $ff00 ld bc, $804 @@ -249,7 +258,7 @@ ChangeFacingDirection: ; 4fc8 (1:4fc8) ; c: new facing direction (0,4,8 or $c) ; d: Y movement delta (-1, 0 or 1) ; e: X movement delta (-1, 0 or 1) -; hl: pointer to tile the sprite would wlak onto +; hl: pointer to tile the sprite would walk onto ; set carry on failure, clears carry on success TryWalking: ; 4fcb (1:4fcb) push hl @@ -470,7 +479,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) ld l, a ld a, [hl] ; c2x6: movement byte 1 cp $fe - jr c, .skipXVisibilityTest ; movement byte 1 < $fe + jr c, .skipXVisibilityTest ; movement byte 1 < $fe (i.e. the sprite's movement is scripted) ld a, [H_CURRENTSPRITEOFFSET] add $4 ld l, a @@ -495,7 +504,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) .skipXVisibilityTest ; make the sprite invisible if a text box is in front of it ; $5F is the maximum number for map tiles - call getTileSpriteStandsOn + call GetTileSpriteStandsOn ld d, $60 ld a, [hli] cp d @@ -572,10 +581,11 @@ CanWalkOntoTile: ; 516e (1:516e) ld l, a ld a, [hl] ; c2x6 (movement byte 1) cp $fe - jr nc, .canMove ; values $fe and $ff + jr nc, .notScripted ; values $fe and $ff +; always allow walking if the movement is scripted and a ret -.canMove +.notScripted ld a, [W_TILESETCOLLISIONPTR] ld l, a ld a, [W_TILESETCOLLISIONPTR+1] @@ -675,7 +685,7 @@ CanWalkOntoTile: ; 516e (1:516e) ; calculates the tile pointer pointing to the tile the current sprite stancs on ; this is always the lower left tile of the 2x2 tile blocks all sprites are snapped to ; hl: output pointer -getTileSpriteStandsOn: ; 5207 (1:5207) +GetTileSpriteStandsOn: ; 5207 (1:5207) ld h, $c1 ld a, [H_CURRENTSPRITEOFFSET] add $4 @@ -713,53 +723,58 @@ LoadDEPlusA: ; 522f (1:522f) ld a, [de] ret -Func_5236: ; 5236 (1:5236) +DoScriptedNPCMovement: ; 5236 (1:5236) +; This is an alternative method of scripting an NPC's movement and is only used +; a few times in the game. It is used when the NPC and player must walk together +; in sync, such as when the player is following the NPC somewhere. An NPC can't +; be moved in sync with the player using the other method. ld a, [wd730] bit 7, a ret z ld hl, wd72e bit 7, [hl] set 7, [hl] - jp z, Func_52a6 + jp z, InitScriptedNPCMovement ld hl, wNPCMovementDirections2 ld a, [wNPCMovementDirections2Index] add l ld l, a - jr nc, .asm_5251 + jr nc, .noCarry inc h -.asm_5251 +.noCarry ld a, [hl] - cp $40 - jr nz, .asm_525f - call Func_52b2 - ld c, $4 - ld a, $fe - jr .asm_5289 -.asm_525f - cp $0 - jr nz, .asm_526c - call Func_52b2 - ld c, $0 - ld a, $2 - jr .asm_5289 -.asm_526c - cp $80 - jr nz, .asm_5279 - call Func_52b7 - ld c, $8 - ld a, $fe - jr .asm_5289 -.asm_5279 - cp $c0 - jr nz, .asm_5286 - call Func_52b7 - ld c, $c - ld a, $2 - jr .asm_5289 -.asm_5286 +; check if moving up + cp NPC_MOVEMENT_UP + jr nz, .checkIfMovingDown + call GetSpriteScreenYPointer + ld c, SPRITE_FACING_UP + ld a, -2 + jr .move +.checkIfMovingDown + cp NPC_MOVEMENT_DOWN + jr nz, .checkIfMovingLeft + call GetSpriteScreenYPointer + ld c, SPRITE_FACING_DOWN + ld a, 2 + jr .move +.checkIfMovingLeft + cp NPC_MOVEMENT_LEFT + jr nz, .checkIfMovingRight + call GetSpriteScreenXPointer + ld c, SPRITE_FACING_LEFT + ld a, -2 + jr .move +.checkIfMovingRight + cp NPC_MOVEMENT_RIGHT + jr nz, .noMatch + call GetSpriteScreenXPointer + ld c, SPRITE_FACING_RIGHT + ld a, 2 + jr .move +.noMatch cp $ff ret -.asm_5289 +.move ld b, a ld a, [hl] add b @@ -768,33 +783,34 @@ Func_5236: ; 5236 (1:5236) add $9 ld l, a ld a, c - ld [hl], a - call Func_52c3 - ld hl, wcf18 + ld [hl], a ; facing direction + call AnimScriptedNPCMovement + ld hl, wScriptedNPCWalkCounter dec [hl] ret nz - ld a, $8 - ld [wcf18], a + ld a, 8 + ld [wScriptedNPCWalkCounter], a ld hl, wNPCMovementDirections2Index inc [hl] ret -Func_52a6: ; 52a6 (1:52a6) +InitScriptedNPCMovement: ; 52a6 (1:52a6) xor a ld [wNPCMovementDirections2Index], a - ld a, $8 - ld [wcf18], a - jp Func_52c3 + ld a, 8 + ld [wScriptedNPCWalkCounter], a + jp AnimScriptedNPCMovement -Func_52b2: ; 52b2 (1:52b2) +GetSpriteScreenYPointer: ; 52b2 (1:52b2) ld a, $4 ld b, a - jr asm_52ba + jr GetSpriteScreenXYPointerCommon -Func_52b7: ; 52b7 (1:52b7) +GetSpriteScreenXPointer: ; 52b7 (1:52b7) ld a, $6 ld b, a -asm_52ba: ; 52ba (1:52ba) + +GetSpriteScreenXYPointerCommon: ; 52ba (1:52ba) ld hl, wSpriteStateData1 ld a, [H_CURRENTSPRITEOFFSET] add l @@ -802,12 +818,12 @@ asm_52ba: ; 52ba (1:52ba) ld l, a ret -Func_52c3: ; 52c3 (1:52c3) +AnimScriptedNPCMovement: ; 52c3 (1:52c3) ld hl, wSpriteStateData2 ld a, [H_CURRENTSPRITEOFFSET] add $e ld l, a - ld a, [hl] + ld a, [hl] ; VRAM slot dec a swap a ld b, a @@ -815,47 +831,47 @@ Func_52c3: ; 52c3 (1:52c3) ld a, [H_CURRENTSPRITEOFFSET] add $9 ld l, a - ld a, [hl] - cp $0 - jr z, .asm_52ea - cp $4 - jr z, .asm_52ea - cp $8 - jr z, .asm_52ea - cp $c - jr z, .asm_52ea + ld a, [hl] ; facing direction + cp SPRITE_FACING_DOWN + jr z, .anim + cp SPRITE_FACING_UP + jr z, .anim + cp SPRITE_FACING_LEFT + jr z, .anim + cp SPRITE_FACING_RIGHT + jr z, .anim ret -.asm_52ea +.anim add b ld b, a - ld [$ffe9], a - call Func_5301 + ld [hSpriteVRAMSlotAndFacing], a + call AdvanceScriptedNPCAnimFrameCounter ld hl, wSpriteStateData1 ld a, [H_CURRENTSPRITEOFFSET] add $2 ld l, a - ld a, [$ffe9] + ld a, [hSpriteVRAMSlotAndFacing] ld b, a - ld a, [$ffea] + ld a, [hSpriteAnimFrameCounter] add b ld [hl], a ret -Func_5301: ; 5301 (1:5301) +AdvanceScriptedNPCAnimFrameCounter: ; 5301 (1:5301) ld a, [H_CURRENTSPRITEOFFSET] add $7 ld l, a - ld a, [hl] + ld a, [hl] ; intra-animation frame counter inc a ld [hl], a - cp $4 + cp 4 ret nz xor a - ld [hl], a + ld [hl], a ; reset intra-animation frame counter inc l - ld a, [hl] + ld a, [hl] ; animation frame counter inc a and $3 ld [hl], a - ld [$ffea], a + ld [hSpriteAnimFrameCounter], a ret diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm index 73a3fdfb..aabc2de8 100755 --- a/engine/overworld/npc_movement.asm +++ b/engine/overworld/npc_movement.asm @@ -44,60 +44,66 @@ _EndNPCMovementScript: ; 1a41d (6:641d) ld [wSimulatedJoypadStatesEnd], a ret -ProfOakMovementScriptPointerTable: ; 1a442 (6:6442) - dw Func_1a44c - dw Func_1a485 - dw Func_1a4a1 - dw Func_1a4a6 - dw Func_1a4f4 +PalletMovementScriptPointerTable: ; 1a442 (6:6442) + dw PalletMovementScript_OakMoveLeft + dw PalletMovementScript_PlayerMoveLeft + dw PalletMovementScript_WaitAndWalkToLab + dw PalletMovementScript_WalkToLab + dw PalletMovementScript_Done -Func_1a44c: ; 1a44c (6:644c) +PalletMovementScript_OakMoveLeft: ; 1a44c (6:644c) ld a, [W_XCOORD] sub $a - ld [wcca1], a - jr z, .asm_1a475 - ld b, $0 + ld [wNumStepsToTake], a + jr z, .playerOnLeftTile +; The player is on the right tile of the northern path out of Pallet Town and +; Prof. Oak is below. +; Make Prof. Oak step to the left. + ld b, 0 ld c, a ld hl, wNPCMovementDirections2 - ld a, $80 + ld a, NPC_MOVEMENT_LEFT call FillMemory ld [hl], $ff ld a, [wSpriteIndex] - ld [H_DOWNARROWBLINKCNT2], a + ld [H_SPRITEINDEX], a ld de, wNPCMovementDirections2 call MoveSprite ld a, $1 ld [wNPCMovementScriptFunctionNum], a - jr .asm_1a47a -.asm_1a475 + jr .done +; The player is on the left tile of the northern path out of Pallet Town and +; Prof. Oak is below. +; Prof. Oak is already on the right tile. +.playerOnLeftTile ld a, $3 ld [wNPCMovementScriptFunctionNum], a -.asm_1a47a +.done ld hl, W_FLAGS_D733 set 1, [hl] ld a, $fc ld [wJoyIgnore], a ret -Func_1a485: ; 1a485 (6:6485) +PalletMovementScript_PlayerMoveLeft: ; 1a485 (6:6485) ld a, [wd730] - bit 0, a - ret nz - ld a, [wcca1] + bit 0, a ; is an NPC being moved by a script? + ret nz ; return if Oak is still moving + ld a, [wNumStepsToTake] ld [wSimulatedJoypadStatesIndex], a - ld [$ff95], a + ld [hNPCMovementDirections2Index], a predef ConvertNPCMovementDirectionsToJoypadMasks call StartSimulatingJoypadStates ld a, $2 ld [wNPCMovementScriptFunctionNum], a ret -Func_1a4a1: ; 1a4a1 (6:64a1) +PalletMovementScript_WaitAndWalkToLab: ; 1a4a1 (6:64a1) ld a, [wSimulatedJoypadStatesIndex] - and a + and a ; is the player done moving left yet? ret nz -Func_1a4a6: ; 1a4a6 (6:64a6) +PalletMovementScript_WalkToLab: ; 1a4a6 (6:64a6) xor a ld [wOverrideSimulatedJoypadStatesMask], a ld a, [wSpriteIndex] @@ -122,12 +128,12 @@ Func_1a4a6: ; 1a4a6 (6:64a6) ret RLEList_ProfOakWalkToLab: ; 1a4dc (6:64dc) - db $00, $05 - db $80, $01 - db $00, $05 - db $C0, $03 - db $40, $01 - db $E0, $01 + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_LEFT, $01 + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_RIGHT, $03 + db NPC_MOVEMENT_UP, $01 + db $E0, $01 ; stand still db $FF RLEList_PlayerWalkToLab: ; 1a4e9 (6:64e9) @@ -138,7 +144,7 @@ RLEList_PlayerWalkToLab: ; 1a4e9 (6:64e9) db D_DOWN, $06 db $FF -Func_1a4f4: ; 1a4f4 (6:64f4) +PalletMovementScript_Done: ; 1a4f4 (6:64f4) ld a, [wSimulatedJoypadStatesIndex] and a ret nz @@ -152,10 +158,10 @@ Func_1a4f4: ; 1a4f4 (6:64f4) jp EndNPCMovementScript PewterMuseumGuyMovementScriptPointerTable: ; 1a510 (6:6510) - dw Func_1a514 - dw PewterMovementScriptDone + dw PewterMovementScript_WalkToMuseum + dw PewterMovementScript_Done -Func_1a514: ; 1a514 (6:6514) +PewterMovementScript_WalkToMuseum: ; 1a514 (6:6514) ld a, BANK(Music_MuseumGuy) ld [wc0ef], a ld [wc0f0], a @@ -191,13 +197,13 @@ RLEList_PewterMuseumPlayer: ; 1a559 (6:6559) db $FF RLEList_PewterMuseumGuy: ; 1a562 (6:6562) - db $40, $06 - db $80, $0D - db $40, $03 - db $80, $01 + db NPC_MOVEMENT_UP, $06 + db NPC_MOVEMENT_LEFT, $0D + db NPC_MOVEMENT_UP, $03 + db NPC_MOVEMENT_LEFT, $01 db $FF -PewterMovementScriptDone: ; 1a56b (6:656b) +PewterMovementScript_Done: ; 1a56b (6:656b) ld a, [wSimulatedJoypadStatesIndex] and a ret nz @@ -208,10 +214,10 @@ PewterMovementScriptDone: ; 1a56b (6:656b) jp EndNPCMovementScript PewterGymGuyMovementScriptPointerTable: ; 1a57d (6:657d) - dw Func_1a581 - dw PewterMovementScriptDone + dw PewterMovementScript_WalkToGym + dw PewterMovementScript_Done -Func_1a581: ; 1a581 (6:6581) +PewterMovementScript_WalkToGym: ; 1a581 (6:6581) ld a, BANK(Music_MuseumGuy) ld [wc0ef], a ld [wc0f0], a @@ -252,12 +258,12 @@ RLEList_PewterGymPlayer: ; 1a5cd (6:65cd) db $FF RLEList_PewterGymGuy: ; 1a5da (6:65da) - db $00, $02 - db $80, $0F - db $40, $05 - db $80, $0B - db $00, $05 - db $C0, $03 + db NPC_MOVEMENT_DOWN, $02 + db NPC_MOVEMENT_LEFT, $0F + db NPC_MOVEMENT_UP, $05 + db NPC_MOVEMENT_LEFT, $0B + db NPC_MOVEMENT_DOWN, $05 + db NPC_MOVEMENT_RIGHT, $03 db $FF FreezeEnemyTrainerSprite: ; 1a5e7 (6:65e7) diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm index b4247257..41360965 100644 --- a/engine/overworld/oam.asm +++ b/engine/overworld/oam.asm @@ -4,25 +4,26 @@ PrepareOAMData: ld a, [wUpdateSpritesEnabled] dec a - jr z, .asm_4b1e + jr z, .updateEnabled cp 0 - 1 ret nz ld [wUpdateSpritesEnabled], a jp HideSprites -.asm_4b1e +.updateEnabled xor a - ld [$ff90], a -.asm_4b21 - ld [$ff8f], a + ld [hOAMBufferOffset], a + +.spriteLoop + ld [hSpriteOffset2], a ld d, wSpriteStateData1 / $100 - ld a, [$ff8f] + ld a, [hSpriteOffset2] ld e, a ld a, [de] ; c1x0 and a - jp z, .asm_4bad + jp z, .nextSprite inc e inc e @@ -31,21 +32,25 @@ PrepareOAMData: cp $ff ; off-screen (don't draw) jr nz, .visible - call Func_4bd1 - jr .asm_4bad + call GetSpriteScreenXY + jr .nextSprite .visible - cp $a0 + cp $a0 ; is the sprite unchanging like an item ball or boulder? jr c, .usefacing + +; unchanging and $f - add $10 - jr .asm_4b48 + add $10 ; skip to the second half of the table which doesn't account for facing direction + jr .next .usefacing and $f -.asm_4b48 + +.next ld l, a +; get sprite priority push de inc d ld a, e @@ -53,15 +58,15 @@ PrepareOAMData: ld e, a ld a, [de] ; c2x7 and $80 - ld [$ff94], a ; temp store sprite priority + ld [hSpritePriority], a ; temp store sprite priority pop de +; read the entry from the table ld h, 0 ld bc, SpriteFacingAndAnimationTable add hl, hl add hl, hl add hl, bc - ld a, [hli] ld c, a ld a, [hli] @@ -70,24 +75,25 @@ PrepareOAMData: ld h, [hl] ld l, a - call Func_4bd1 + call GetSpriteScreenXY - ld a, [$ff90] + ld a, [hOAMBufferOffset] ld e, a ld d, wOAMBuffer / $100 -.tile - ld a, [$ff92] ; temp for sprite Y position + +.tileLoop + ld a, [hSpriteScreenY] ; temp for sprite Y position add $10 ; Y=16 is top of screen (Y=0 is invisible) add [hl] ; add Y offset from table ld [de], a ; write new sprite OAM Y position inc hl - ld a, [$ff91] ; temp for sprite X position + ld a, [hSpriteScreenX] ; temp for sprite X position add $8 ; X=8 is left of screen (X=0 is invisible) add [hl] ; add X offset from table inc e ld [de], a ; write new sprite OAM X position inc e - ld a, [bc] ; read pattern number offset (accomodates orientation (offset 0,4 or 8) and animation (offset 0 or $80)) + ld a, [bc] ; read pattern number offset (accommodates orientation (offset 0,4 or 8) and animation (offset 0 or $80)) inc bc push bc ld b, a @@ -99,55 +105,60 @@ PrepareOAMData: ; Sprites $a and $b have one face (and therefore 4 tiles instead of 12). ; As a result, sprite $b's tile offset is less than normal. cp $b - jr nz, .offset + jr nz, .notFourTileSprite ld a, $a * 12 + 4 - jr .gotoffset + jr .next2 -.offset +.notFourTileSprite ; a *= 12 sla a sla a ld c, a sla a add c -.gotoffset - add b ; which frame + +.next2 + add b ; add the tile offset from the table (based on frame and facing direction) pop bc ld [de], a ; tile id inc hl inc e ld a, [hl] - bit 1, a ; sprite priority - jr z, .fg - ld a, [$ff94] ; facing priority + bit 1, a ; is the tile allowed to set the sprite priority bit? + jr z, .skipPriority + ld a, [hSpritePriority] or [hl] -.fg +.skipPriority inc hl ld [de], a inc e bit 0, a ; OAMFLAG_ENDOFDATA - jr z, .tile + jr z, .tileLoop ld a, e - ld [$ff90], a + ld [hOAMBufferOffset], a -.asm_4bad - ld a, [$ff8f] +.nextSprite + ld a, [hSpriteOffset2] add $10 cp $100 % $100 - jp nz, .asm_4b21 + jp nz, .spriteLoop ; Clear unused OAM. - ld a, [$ff90] + ld a, [hOAMBufferOffset] ld l, a ld h, wOAMBuffer / $100 ld de, $4 ld b, $a0 ld a, [wd736] - bit 6, a + bit 6, a ; jumping down ledge or fishing animation? ld a, $a0 jr z, .clear + +; Don't clear the last 4 entries because they are used for the shadow in the +; jumping down ledge animation and the rod in the fishing animation. ld a, $90 + .clear cp l ret z @@ -155,24 +166,24 @@ PrepareOAMData: add hl, de jr .clear -Func_4bd1: ; 4bd1 (1:4bd1) +GetSpriteScreenXY: ; 4bd1 (1:4bd1) inc e inc e ld a, [de] ; c1x4 - ld [$ff92], a + ld [hSpriteScreenY], a inc e inc e ld a, [de] ; c1x6 - ld [$ff91], a - ld a, $4 + ld [hSpriteScreenX], a + ld a, 4 add e ld e, a - ld a, [$ff92] - add $4 + ld a, [hSpriteScreenY] + add 4 and $f0 ld [de], a ; c1xa (y) inc e - ld a, [$ff91] + ld a, [hSpriteScreenX] and $f0 ld [de], a ; c1xb (x) ret diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm index d68e4e57..98ea466d 100755 --- a/engine/overworld/player_animations.asm +++ b/engine/overworld/player_animations.asm @@ -1,5 +1,5 @@ EnterMapAnim: ; 70510 (1c:4510) - call InitFacingDirectionBuffer + call InitFacingDirectionList ld a, $ec ld [wSpriteStateData1 + 4], a ; player's sprite Y screen position call Delay3 @@ -32,7 +32,7 @@ EnterMapAnim: ; 70510 (1c:4510) ld a, $8 ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue ld [hl], $ff ; wPlayerSpinInPlaceAnimSoundID - ld hl, wcd48 + ld hl, wFacingDirectionList call PlayerSpinInPlace .restoreDefaultMusic call PlayDefaultMusic @@ -91,7 +91,7 @@ PlayerSpinWhileMovingDown: ; 705aa (1c:45aa) jp PlayerSpinWhileMovingUpOrDown _LeaveMapAnim: ; 705ba (1c:45ba) - call InitFacingDirectionBuffer + call InitFacingDirectionList call IsPlayerStandingOnWarpPadOrHole ld a, b and a @@ -134,7 +134,7 @@ _LeaveMapAnim: ; 705ba (1c:45ba) xor a ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue ld [hl], (SFX_02_4d - SFX_Headers_02) / 3 ; wPlayerSpinInPlaceAnimSoundID - ld hl, wcd48 + ld hl, wFacingDirectionList call PlayerSpinInPlace jr .spinWhileMovingUp .flyAnimation @@ -214,7 +214,7 @@ LeaveMapThroughHoleAnim: ; 7067d (1c:467d) ld [wOAMBuffer + 1 * 4], a ld c, 2 call DelayFrames - ; hide lower half of player's sprite + ; hide upper half of player's sprite ld a, $a0 ld [wOAMBuffer + 2 * 4], a ld [wOAMBuffer + 3 * 4], a @@ -231,7 +231,7 @@ DoFlyAnimation: ; 706ae (1c:46ae) call Delay3 ld a, [wFlyAnimUsingCoordList] cp $ff - jr z, .asm_706cd + jr z, .skipCopyingCoords ; if the bird is flapping its wings in place ld hl, wSpriteStateData1 + 4 ld a, [de] inc de @@ -240,7 +240,7 @@ DoFlyAnimation: ; 706ae (1c:46ae) ld a, [de] inc de ld [hl], a -.asm_706cd +.skipCopyingCoords ld a, [wFlyAnimCounter] dec a ld [wFlyAnimCounter], a @@ -252,22 +252,23 @@ LoadBirdSpriteGraphics: ; 706d7 (1c:46d7) ld hl, vNPCSprites ld bc, (BANK(BirdSprite) << 8) + $0c call CopyVideoData - ld de, BirdSprite + $c0 ; moving amination sprite + ld de, BirdSprite + $c0 ; moving animation sprite ld hl, vNPCSprites2 ld bc, (BANK(BirdSprite) << 8) + $0c jp CopyVideoData -InitFacingDirectionBuffer: ; 706ef (1c:46ef) +InitFacingDirectionList: ; 706ef (1c:46ef) ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction (image index is locked to standing images) - ld [wcd50], a + ld [wSavedPlayerFacingDirection], a ld a, [wSpriteStateData1 + 4] ; player's sprite Y screen position - ld [wcd4f], a + ld [wSavedPlayerScreenY], a ld hl, PlayerSpinningFacingOrder - ld de, wcd48 - ld bc, $4 + ld de, wFacingDirectionList + ld bc, 4 call CopyData ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction (image index is locked to standing images) - ld hl, wcd48 + ld hl, wFacingDirectionList +; find the place in the list that matches the current facing direction .loop cp [hl] inc hl @@ -281,15 +282,16 @@ PlayerSpinningFacingOrder: ; 70713 (1c:4713) db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT, SPRITE_FACING_UP, SPRITE_FACING_RIGHT SpinPlayerSprite: ; 70717 (1c:4717) +; copy the current value from the list into the sprite data and rotate the list ld a, [hl] ld [wSpriteStateData1 + 2], a ; player's sprite facing direction (image index is locked to standing images) push hl - ld hl, wcd48 - ld de, wcd47 - ld bc, $4 + ld hl, wFacingDirectionList + ld de, wFacingDirectionList - 1 + ld bc, 4 call CopyData - ld a, [wcd47] - ld [wcd4b], a + ld a, [wFacingDirectionList - 1] + ld [wFacingDirectionList + 3], a pop hl ret @@ -298,11 +300,12 @@ PlayerSpinInPlace: ; 70730 (1c:4730) ld a, [wPlayerSpinInPlaceAnimFrameDelay] ld c, a and $3 - jr nz, .asm_70743 + jr nz, .skipPlayingSound +; when the last delay was a multiple of 4, play a sound if there is one ld a, [wPlayerSpinInPlaceAnimSoundID] cp $ff call nz, PlaySound -.asm_70743 +.skipPlayingSound ld a, [wPlayerSpinInPlaceAnimFrameDelayDelta] add c ld [wPlayerSpinInPlaceAnimFrameDelay], a @@ -330,9 +333,9 @@ PlayerSpinWhileMovingUpOrDown: ; 70755 (1c:4755) jr PlayerSpinWhileMovingUpOrDown RestoreFacingDirectionAndYScreenPos: ; 70772 (1c:4772) - ld a, [wcd4f] + ld a, [wSavedPlayerScreenY] ld [wSpriteStateData1 + 4], a - ld a, [wcd50] + ld a, [wSavedPlayerFacingDirection] ld [wSpriteStateData1 + 2], a ret @@ -378,11 +381,11 @@ IsPlayerStandingOnWarpPadOrHole: ; 70787 (1c:4787) db INTERIOR, $55, 1 ; warp pad db $FF -Func_707b6: ; 707b6 (1c:47b6) +FishingAnim: ; 707b6 (1c:47b6) ld c, 10 call DelayFrames ld hl, wd736 - set 6, [hl] + set 6, [hl] ; reserve the last 4 OAM entries ld de, RedSprite ld hl, vNPCSprites ld bc, (BANK(RedSprite) << 8) + $0c @@ -393,55 +396,67 @@ Func_707b6: ; 707b6 (1c:47b6) ld a, [wSpriteStateData1 + 2] ld c, a ld b, $0 - ld hl, FishingRodGfxProperties + ld hl, FishingRodOAM add hl, bc ld de, wOAMBuffer + $9c ld bc, $4 call CopyData ld c, 100 call DelayFrames - ld a, [wWhichTrade] + ld a, [wRodResponse] and a ld hl, NoNibbleText - jr z, .asm_70836 + jr z, .done cp $2 ld hl, NothingHereText - jr z, .asm_70836 - ld b, $a -.asm_707fe - ld hl, wSpriteStateData1 + 4 - call Func_70842 + jr z, .done + +; there was a bite + +; shake the player's sprite vertically + ld b, 10 +.loop + ld hl, wSpriteStateData1 + 4 ; player's sprite Y screen position + call .ShakePlayerSprite ld hl, wOAMBuffer + $9c - call Func_70842 + call .ShakePlayerSprite call Delay3 dec b - jr nz, .asm_707fe - ld a, [wSpriteStateData1 + 2] - cp $4 - jr nz, .asm_7081c + jr nz, .loop + +; If the player is facing up, hide the fishing rod so it doesn't overlap with +; the exclamation bubble that will be shown next. + ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction + cp SPRITE_FACING_UP + jr nz, .skipHidingFishingRod ld a, $a0 ld [wOAMBuffer + $9c], a -.asm_7081c - ld hl, wcd4f + +.skipHidingFishingRod + ld hl, wEmotionBubbleSpriteIndex xor a - ld [hli], a - ld [hl], a + ld [hli], a ; player's sprite + ld [hl], a ; EXCLAMATION_BUBBLE predef EmotionBubble - ld a, [wSpriteStateData1 + 2] - cp $4 - jr nz, .asm_70833 + +; If the player is facing up, unhide the fishing rod. + ld a, [wSpriteStateData1 + 2] ; player's sprite facing direction + cp SPRITE_FACING_UP + jr nz, .skipUnhidingFishingRod ld a, $44 ld [wOAMBuffer + $9c], a -.asm_70833 + +.skipUnhidingFishingRod ld hl, ItsABiteText -.asm_70836 + +.done call PrintText ld hl, wd736 - res 6, [hl] + res 6, [hl] ; unreserve the last 4 OAM entries call LoadFontTilePatterns ret -Func_70842: ; 70842 (1c:4842) +.ShakePlayerSprite ld a, [hl] xor $1 ld [hl], a @@ -459,7 +474,7 @@ ItsABiteText: ; 70851 (1c:4851) TX_FAR _ItsABiteText db "@" -FishingRodGfxProperties: ; 70856 (1c:4856) +FishingRodOAM: ; 70856 (1c:4856) ; specifies how the fishing rod should be drawn on the screen ; first byte = screen y coordinate ; second byte = screen x coordinate diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm index de18a1ab..2caada1d 100755 --- a/engine/overworld/pokemart.asm +++ b/engine/overworld/pokemart.asm @@ -57,9 +57,9 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call DisplayTextBoxID ; draw money text box ld hl,wNumBagItems ld a,l - ld [wList],a + ld [wListPointer],a ld a,h - ld [wList + 1],a + ld [wListPointer + 1],a xor a ld [wPrintItemPrices],a ld [wCurrentMenuItem],a @@ -136,11 +136,11 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) ld a,MONEY_BOX ld [wTextBoxID],a call DisplayTextBoxID - ld hl,wStringBuffer2 + 11 + ld hl,wItemList ld a,l - ld [wList],a + ld [wListPointer],a ld a,h - ld [wList + 1],a + ld [wListPointer + 1],a xor a ld [wCurrentMenuItem],a inc a diff --git a/engine/overworld/ssanne.asm b/engine/overworld/ssanne.asm index 4cac4957..a59ae794 100755 --- a/engine/overworld/ssanne.asm +++ b/engine/overworld/ssanne.asm @@ -1,6 +1,6 @@ AnimateBoulderDust: ; 79f54 (1e:5f54) ld a, $1 - ld [wcd50], a ; select the boulder dust offsets + ld [wWhichAnimationOffsets], a ; select the boulder dust offsets ld a, [wUpdateSpritesEnabled] push af ld a, $ff |