diff options
Diffstat (limited to 'engine/overworld')
25 files changed, 851 insertions, 787 deletions
diff --git a/engine/overworld/cable_club_npc.asm b/engine/overworld/cable_club_npc.asm index bdab41a6..a2feba06 100755 --- a/engine/overworld/cable_club_npc.asm +++ b/engine/overworld/cable_club_npc.asm @@ -1,15 +1,14 @@ CableClubNPC: ; 71c5 (1:71c5) ld hl, CableClubNPCWelcomeText call PrintText - ld a, [wd74b] - bit 5, a ; received pokedex? + CheckEvent EVENT_GOT_POKEDEX jp nz, .receivedPokedex ; if the player hasn't received the pokedex - ld c, $3c + ld c, 60 call DelayFrames ld hl, CableClubNPCMakingPreparationsText call PrintText - jp Func_7298 + jp .didNotConnect .receivedPokedex ld a, $1 ld [wMenuJoypadPollCount], a @@ -57,7 +56,7 @@ CableClubNPC: ; 71c5 (1:71c5) jr nz, .choseNo callab SaveSAVtoSRAM call WaitForSoundToFinish - ld a, (SFX_02_5d - SFX_Headers_02) / 3 + ld a, SFX_SAVE call PlaySoundWaitForCurrent ld hl, CableClubNPCPleaseWaitText call PrintText @@ -72,31 +71,29 @@ CableClubNPC: ; 71c5 (1:71c5) ld hl, wUnknownSerialCounter ld a, [hli] inc a - jr nz, Func_72a8 ; 0x726b $3b + jr nz, .connected ld a, [hl] inc a - jr nz, Func_72a8 ; 0x726f $37 - ld b, $a -.asm_7273 + jr nz, .connected + ld b, 10 +.syncLoop call DelayFrame call Serial_SendZeroByte dec b - jr nz, .asm_7273 ; 0x727a $f7 + jr nz, .syncLoop call CloseLinkConnection ld hl, CableClubNPCLinkClosedBecauseOfInactivityText call PrintText - jr Func_7298 ; 0x7285 $11 + jr .didNotConnect .failedToEstablishConnection ld hl, CableClubNPCAreaReservedFor2FriendsLinkedByCableText call PrintText - jr Func_7298 ; 0x728d $9 + jr .didNotConnect .choseNo call CloseLinkConnection ld hl, CableClubNPCPleaseComeAgainText call PrintText - ; fall through - -Func_7298: ; 7298 (1:7298) +.didNotConnect xor a ld hl, wUnknownSerialCounter ld [hli], a @@ -106,14 +103,11 @@ Func_7298: ; 7298 (1:7298) xor a ld [wMenuJoypadPollCount], a ret - -Func_72a8: ; 72a8 (1:72a8) +.connected xor a ld [hld], a ld [hl], a - ld hl, LinkMenu - ld b, BANK(LinkMenu) - jp Bankswitch + jpab LinkMenu CableClubNPCAreaReservedFor2FriendsLinkedByCableText: ; 72b3 (1:72b3) TX_FAR _CableClubNPCAreaReservedFor2FriendsLinkedByCableText diff --git a/engine/overworld/card_key.asm b/engine/overworld/card_key.asm index c4df0d51..cc9fe3a7 100755 --- a/engine/overworld/card_key.asm +++ b/engine/overworld/card_key.asm @@ -27,8 +27,8 @@ PrintCardKeyText: ; 52673 (14:6673) jr z, .noCardKey call GetCoordsInFrontOfPlayer push de - ld a, $1 - ld [H_DOWNARROWBLINKCNT2], a + tx_pre_id CardKeySuccessText + ld [hSpriteIndexOrTextID], a call PrintPredefTextID pop de srl d @@ -47,15 +47,15 @@ PrintCardKeyText: ; 52673 (14:6673) .notSilphCo11F ld a, $e .replaceCardKeyDoorTileBlock - ld [wd09f], a + ld [wNewTileBlockID], a predef ReplaceTileBlock ld hl, wd126 set 5, [hl] - ld a, (SFX_1f_57 - SFX_Headers_1f) / 3 + ld a, SFX_GO_INSIDE jp PlaySound .noCardKey - ld a, $2 - ld [H_DOWNARROWBLINKCNT2], a + tx_pre_id CardKeyFailText + ld [hSpriteIndexOrTextID], a jp PrintPredefTextID SilphCoMapList: ; 526e3 (14:66e3) diff --git a/engine/overworld/cinnabar_lab.asm b/engine/overworld/cinnabar_lab.asm index eefa2176..f81324e0 100755 --- a/engine/overworld/cinnabar_lab.asm +++ b/engine/overworld/cinnabar_lab.asm @@ -2,36 +2,36 @@ GiveFossilToCinnabarLab: ; 61006 (18:5006) ld hl, wd730 set 6, [hl] xor a - ld [wCurrentMenuItem], a ; wCurrentMenuItem - ld a, $3 - ld [wMenuWatchedKeys], a ; wMenuWatchedKeys - ld a, [wcd37] + ld [wCurrentMenuItem], a + ld a, A_BUTTON | B_BUTTON + ld [wMenuWatchedKeys], a + ld a, [wFilteredBagItemsCount] dec a - ld [wMaxMenuItem], a ; wMaxMenuItem - ld a, $2 - ld [wTopMenuItemY], a ; wTopMenuItemY - ld a, $1 - ld [wTopMenuItemX], a ; wTopMenuItemX - ld a, [wcd37] + ld [wMaxMenuItem], a + ld a, 2 + ld [wTopMenuItemY], a + ld a, 1 + ld [wTopMenuItemX], a + ld a, [wFilteredBagItemsCount] dec a - ld bc, $2 - ld hl, $3 + ld bc, 2 + ld hl, 3 call AddNTimes dec l ld b, l ld c, $d - ld hl, wTileMap + coord hl, 0, 0 call TextBoxBorder call UpdateSprites - call Func_610c2 + call PrintFossilsInBag ld hl, wd730 res 6, [hl] call HandleMenuInput - bit 1, a - jr nz, .asm_610a7 - ld hl, wcc5b - ld a, [wCurrentMenuItem] ; wCurrentMenuItem - ld d, $0 + bit 1, a ; pressed B? + jr nz, .cancelledGivingFossil + ld hl, wFilteredBagItems + ld a, [wCurrentMenuItem] + ld d, 0 ld e, a add hl, de ld a, [hl] @@ -55,21 +55,19 @@ GiveFossilToCinnabarLab: ; 61006 (18:5006) ld hl, LabFossil_610ae call PrintText call YesNoChoice - ld a, [wCurrentMenuItem] ; wCurrentMenuItem + ld a, [wCurrentMenuItem] and a - jr nz, .asm_610a7 + jr nz, .cancelledGivingFossil ld hl, LabFossil_610b3 call PrintText ld a, [W_FOSSILITEM] - ld [$ffdb], a + ld [hItemToRemoveID], a callba RemoveItemByID ld hl, LabFossil_610b8 call PrintText - ld hl, wd7a3 - set 0, [hl] - set 1, [hl] + SetEvents EVENT_GAVE_FOSSIL_TO_LAB, EVENT_LAB_STILL_REVIVING_FOSSIL ret -.asm_610a7 +.cancelledGivingFossil ld hl, LabFossil_610bd call PrintText ret @@ -90,27 +88,28 @@ LabFossil_610bd: ; 610bd (18:50bd) TX_FAR _Lab4Text_610bd db "@" -Func_610c2: ; 610c2 (18:50c2) - ld hl, wcc5b +PrintFossilsInBag: ; 610c2 (18:50c2) +; Prints each fossil in the player's bag on a separate line in the menu. + ld hl, wFilteredBagItems xor a - ld [$ffdb], a -.asm_610c8 + ld [hItemCounter], a +.loop ld a, [hli] cp $ff ret z push hl ld [wd11e], a call GetItemName - hlCoord 2, 2 - ld a, [$ffdb] - ld bc, $28 + coord hl, 2, 2 + ld a, [hItemCounter] + ld bc, SCREEN_WIDTH * 2 call AddNTimes ld de, wcd6d call PlaceString - ld hl, $ffdb + ld hl, hItemCounter inc [hl] pop hl - jr .asm_610c8 + jr .loop ; loads the names of the fossil item and the resulting mon LoadFossilItemAndMonName: ; 610eb (18:50eb) diff --git a/engine/overworld/cut.asm b/engine/overworld/cut.asm index 7b92bca3..30aedbc1 100755 --- a/engine/overworld/cut.asm +++ b/engine/overworld/cut.asm @@ -1,43 +1,43 @@ UsedCut: ; ef54 (3:6f54) xor a - ld [wcd6a], a - ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET + ld [wActionResultOrTookBattleTurn], a ; initialise to failure value + ld a, [W_CURMAPTILESET] and a ; OVERWORLD - jr z, .asm_ef6b + jr z, .overworld cp GYM - jr nz, .asm_ef77 + jr nz, .nothingToCut ld a, [wTileInFrontOfPlayer] cp $50 ; gym cut tree - jr nz, .asm_ef77 - jr asm_ef82 -.asm_ef6b + jr nz, .nothingToCut + jr .canCut +.overworld dec a ld a, [wTileInFrontOfPlayer] cp $3d ; cut tree - jr z, asm_ef82 + jr z, .canCut cp $52 ; grass - jr z, asm_ef82 -.asm_ef77 - ld hl, NothingToCutText + jr z, .canCut +.nothingToCut + ld hl, .NothingToCutText jp PrintText -NothingToCutText: ; ef7d (3:6f7d) +.NothingToCutText TX_FAR _NothingToCutText db "@" -asm_ef82: ; ef82 (3:6f82) - ld [wcd4d], a - ld a, $1 - ld [wcd6a], a - ld a, [wWhichPokemon] ; wWhichPokemon - ld hl, wPartyMonNicks ; wPartyMonNicks +.canCut + ld [wCutTile], a + ld a, 1 + ld [wActionResultOrTookBattleTurn], a ; used cut + ld a, [wWhichPokemon] + ld hl, wPartyMonNicks call GetPartyMonName ld hl, wd730 set 6, [hl] call GBPalWhiteOutWithDelay3 call ClearSprites call RestoreScreenTilesAndReloadTilePatterns - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a call Delay3 call LoadGBPal @@ -53,14 +53,14 @@ asm_ef82: ; ef82 (3:6f82) res 6, [hl] ld a, $ff ld [wUpdateSpritesEnabled], a - call AnimateCutTree - ld de, CutTreeBlockSwaps ; $7100 - call Func_f09f + call InitCutAnimOAM + ld de, CutTreeBlockSwaps + call ReplaceTreeTileBlock call RedrawMapView - callba Func_79e96 + callba AnimCut ld a, $1 ld [wUpdateSpritesEnabled], a - ld a, (SFX_02_56 - SFX_Headers_02) / 3 + ld a, SFX_CUT call PlaySound ld a, $90 ld [hWY], a @@ -71,61 +71,62 @@ UsedCutText: ; eff2 (3:6ff2) TX_FAR _UsedCutText db "@" -AnimateCutTree: ; eff7 (3:6ff7) +InitCutAnimOAM: ; eff7 (3:6ff7) xor a - ld [wcd50], a + ld [wWhichAnimationOffsets], a ld a, $e4 - ld [rOBP1], a ; $ff49 - ld a, [wcd4d] + ld [rOBP1], a + ld a, [wCutTile] cp $52 - jr z, .asm_f020 - ld de, Overworld_GFX + $2d0 ; $42d0 ; cuttable tree sprite top row + jr z, .grass +; tree + ld de, Overworld_GFX + $2d0 ; cuttable tree sprite top row ld hl, vChars1 + $7c0 - ld bc, (BANK(Overworld_GFX) << 8) + $02 + lb bc, BANK(Overworld_GFX), $02 call CopyVideoData - ld de, Overworld_GFX + $3d0 ; $43d0 ; cuttable tree sprite bottom row + ld de, Overworld_GFX + $3d0 ; cuttable tree sprite bottom row ld hl, vChars1 + $7e0 - ld bc, (BANK(Overworld_GFX) << 8) + $02 + lb bc, BANK(Overworld_GFX), $02 call CopyVideoData - jr WriteCutTreeBoulderDustAnimationOAMBlock -.asm_f020 + jr WriteCutOrBoulderDustAnimationOAMBlock +.grass ld hl, vChars1 + $7c0 - call LoadCutTreeAnimationTilePattern + call LoadCutGrassAnimationTilePattern ld hl, vChars1 + $7d0 - call LoadCutTreeAnimationTilePattern + call LoadCutGrassAnimationTilePattern ld hl, vChars1 + $7e0 - call LoadCutTreeAnimationTilePattern + call LoadCutGrassAnimationTilePattern ld hl, vChars1 + $7f0 - call LoadCutTreeAnimationTilePattern - call WriteCutTreeBoulderDustAnimationOAMBlock + call LoadCutGrassAnimationTilePattern + call WriteCutOrBoulderDustAnimationOAMBlock ld hl, wOAMBuffer + $93 - ld de, $4 + ld de, 4 ld a, $30 ld c, e -.asm_f044 +.loop ld [hl], a add hl, de xor $60 dec c - jr nz, .asm_f044 + jr nz, .loop ret -LoadCutTreeAnimationTilePattern: ; f04c (3:704c) - ld de, AnimationTileset2 + $60 ; $474e ; tile depicting a leaf - ld bc, (BANK(AnimationTileset2) << 8) + $01 +LoadCutGrassAnimationTilePattern: ; f04c (3:704c) + ld de, AnimationTileset2 + $60 ; tile depicting a leaf + lb bc, BANK(AnimationTileset2), $01 jp CopyVideoData -WriteCutTreeBoulderDustAnimationOAMBlock: ; f055 (3:7055) - call GetCutTreeBoulderDustAnimationOffsets +WriteCutOrBoulderDustAnimationOAMBlock: ; f055 (3:7055) + call GetCutOrBoulderDustAnimationOffsets ld a, $9 - ld de, CutTreeBoulderDustAnimationTilesAndAttributes + ld de, CutOrBoulderDustAnimationTilesAndAttributes jp WriteOAMBlock -CutTreeBoulderDustAnimationTilesAndAttributes: ; f060 (3:7060) +CutOrBoulderDustAnimationTilesAndAttributes: ; f060 (3:7060) db $FC,$10,$FD,$10 db $FE,$10,$FF,$10 -GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068) +GetCutOrBoulderDustAnimationOffsets: ; f068 (3:7068) ld hl, wSpriteStateData1 + 4 ld a, [hli] ; player's sprite screen Y position ld b, a @@ -138,12 +139,12 @@ 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 + ld hl, CutAnimationOffsets + jr z, .next ld hl, BoulderDustAnimationOffsets -.asm_f084 +.next add hl, de ld e, [hl] inc hl @@ -156,7 +157,7 @@ GetCutTreeBoulderDustAnimationOffsets: ; f068 (3:7068) ld c, a ret -CutTreeAnimationOffsets: ; f08f (3:708f) +CutAnimationOffsets: ; f08f (3:708f) ; Each pair represents the x and y pixels offsets from the player of where the cut tree animation should be drawn db 8, 36 ; player is facing down db 8, 4 ; player is facing up @@ -171,75 +172,79 @@ BoulderDustAnimationOffsets: ; f097 (3:7097) db -24, 20 ; player is facing left db 40, 20 ; player is facing right -Func_f09f: ; f09f (3:709f) +ReplaceTreeTileBlock: ; f09f (3:709f) +; Determine the address of the tile block that contains the tile in front of the +; player (i.e. where the tree is) and replace it with the corresponding tile +; block that doesn't have the tree. push de - ld a, [W_CURMAPWIDTH] ; wd369 - add $6 + ld a, [W_CURMAPWIDTH] + add 6 ld c, a - ld b, $0 - ld d, $0 + ld b, 0 + ld d, 0 ld hl, wCurrentTileBlockMapViewPointer ld a, [hli] ld h, [hl] ld l, a add hl, bc - ld a, [wSpriteStateData1 + 9] + ld a, [wSpriteStateData1 + 9] ; player sprite's facing direction and a - jr z, .asm_f0c7 - cp $4 - jr z, .asm_f0cf - cp $8 - jr z, .asm_f0d7 - ld a, [W_XBLOCKCOORD] ; wd364 + jr z, .down + cp SPRITE_FACING_UP + jr z, .up + cp SPRITE_FACING_LEFT + jr z, .left +; right + ld a, [W_XBLOCKCOORD] and a - jr z, .asm_f0e0 - jr .asm_f0ec -.asm_f0c7 - ld a, [W_YBLOCKCOORD] ; wd363 + jr z, .centerTileBlock + jr .rightOfCenter +.down + ld a, [W_YBLOCKCOORD] and a - jr z, .asm_f0e0 - jr .asm_f0df -.asm_f0cf - ld a, [W_YBLOCKCOORD] ; wd363 + jr z, .centerTileBlock + jr .belowCenter +.up + ld a, [W_YBLOCKCOORD] and a - jr z, .asm_f0e1 - jr .asm_f0e0 -.asm_f0d7 - ld a, [W_XBLOCKCOORD] ; wd364 + jr z, .aboveCenter + jr .centerTileBlock +.left + ld a, [W_XBLOCKCOORD] and a - jr z, .asm_f0e6 - jr .asm_f0e0 -.asm_f0df + jr z, .leftOfCenter + jr .centerTileBlock +.belowCenter add hl, bc -.asm_f0e0 +.centerTileBlock add hl, bc -.asm_f0e1 +.aboveCenter ld e, $2 add hl, de - jr .asm_f0f0 -.asm_f0e6 + jr .next +.leftOfCenter ld e, $1 add hl, bc add hl, de - jr .asm_f0f0 -.asm_f0ec + jr .next +.rightOfCenter ld e, $3 add hl, bc add hl, de -.asm_f0f0 +.next pop de ld a, [hl] ld c, a -.asm_f0f3 +.loop ; find the matching tile block in the array ld a, [de] inc de inc de cp $ff ret z cp c - jr nz, .asm_f0f3 + jr nz, .loop dec de - ld a, [de] + ld a, [de] ; replacement tile block from matching array entry ld [hl], a ret diff --git a/engine/overworld/cut2.asm b/engine/overworld/cut2.asm index de2b9d55..1cf832b5 100755 --- a/engine/overworld/cut2.asm +++ b/engine/overworld/cut2.asm @@ -1,89 +1,89 @@ -Func_79e96: ; 79e96 (1e:5e96) - ld a, [wcd4d] +AnimCut: ; 79e96 (1e:5e96) + ld a, [wCutTile] cp $52 - jr z, .asm_79ec8 + jr z, .grass ld c, $8 -.asm_79e9f +.cutTreeLoop push bc ld hl, wOAMBuffer + $91 - ld a, $1 - ld [wd08a], a - ld c, $2 + ld a, 1 + ld [wCoordAdjustmentAmount], a + ld c, 2 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $99 - ld a, $ff - ld [wd08a], a - ld c, $2 + ld a, -1 + ld [wCoordAdjustmentAmount], a + ld c, 2 call AdjustOAMBlockXPos2 - ld a, [rOBP1] ; $ff49 + ld a, [rOBP1] xor $64 - ld [rOBP1], a ; $ff49 + ld [rOBP1], a call DelayFrame pop bc dec c - jr nz, .asm_79e9f + jr nz, .cutTreeLoop ret -.asm_79ec8 - ld c, $2 -.asm_79eca +.grass + ld c, 2 +.cutGrassLoop push bc ld c, $8 - call Func_79eed - call Func_79f30 + call AnimCutGrass_UpdateOAMEntries + call AnimCutGrass_SwapOAMEntries ld c, $8 - call Func_79eed - call Func_79f30 + call AnimCutGrass_UpdateOAMEntries + call AnimCutGrass_SwapOAMEntries ld hl, wOAMBuffer + $90 - ld a, $2 - ld [wd08a], a - ld c, $4 + ld a, 2 + ld [wCoordAdjustmentAmount], a + ld c, 4 call AdjustOAMBlockYPos2 pop bc dec c - jr nz, .asm_79eca + jr nz, .cutGrassLoop ret -Func_79eed: ; 79eed (1e:5eed) +AnimCutGrass_UpdateOAMEntries: ; 79eed (1e:5eed) push bc ld hl, wOAMBuffer + $91 - ld a, $1 - ld [wd08a], a - ld c, $1 + ld a, 1 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $95 - ld a, $2 - ld [wd08a], a - ld c, $1 + ld a, 2 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $99 - ld a, $fe - ld [wd08a], a - ld c, $1 + ld a, -2 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 ld hl, wOAMBuffer + $9d - ld a, $ff - ld [wd08a], a - ld c, $1 + ld a, -1 + ld [wCoordAdjustmentAmount], a + ld c, 1 call AdjustOAMBlockXPos2 - ld a, [rOBP1] ; $ff49 + ld a, [rOBP1] xor $64 - ld [rOBP1], a ; $ff49 + ld [rOBP1], a call DelayFrame pop bc dec c - jr nz, Func_79eed + jr nz, AnimCutGrass_UpdateOAMEntries ret -Func_79f30: ; 79f30 (1e:5f30) +AnimCutGrass_SwapOAMEntries: ; 79f30 (1e:5f30) ld hl, wOAMBuffer + $90 - ld de, wHPBarMaxHP + ld de, wBuffer ld bc, $8 call CopyData ld hl, wOAMBuffer + $98 ld de, wOAMBuffer + $90 ld bc, $8 call CopyData - ld hl, wHPBarMaxHP + ld hl, wBuffer ld de, wOAMBuffer + $98 ld bc, $8 jp CopyData diff --git a/engine/overworld/doors.asm b/engine/overworld/doors.asm index ac345af9..641c021f 100755 --- a/engine/overworld/doors.asm +++ b/engine/overworld/doors.asm @@ -1,8 +1,8 @@ ; returns whether the player is standing on a door tile in carry IsPlayerStandingOnDoorTile: ; 1a609 (6:6609) push de - ld hl, DoorTileIDPointers ; $662c - ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET + ld hl, DoorTileIDPointers + ld a, [W_CURMAPTILESET] ld de, $3 call IsInArray pop de diff --git a/engine/overworld/elevator.asm b/engine/overworld/elevator.asm index 3a23d410..05a9cc4e 100755 --- a/engine/overworld/elevator.asm +++ b/engine/overworld/elevator.asm @@ -1,46 +1,48 @@ ShakeElevator: ; 7bf15 (1e:7f15) - ld de, $ffe0 - call Func_7bf64 - ld de, $240 - call Func_7bf64 + ld de, -$20 + call ShakeElevatorRedrawRow + ld de, SCREEN_HEIGHT * $20 + call ShakeElevatorRedrawRow call Delay3 ld a, $ff call PlaySound ld a, [hSCY] ld d, a ld e, $1 - ; number of times to play collision sfx - ld b, $64 -.asm_7bf30 + ld b, 100 +.shakeLoop ; scroll the BG up and down and play a sound effect ld a, e xor $fe ld e, a add d ld [hSCY], a push bc - ld c, BANK(SFX_02_5b) - ld a, (SFX_02_5b - SFX_Headers_02) / 3 + ld c, BANK(SFX_Collision_1) + ld a, SFX_COLLISION call PlayMusic pop bc - ld c, $2 + ld c, 2 call DelayFrames dec b - jr nz, .asm_7bf30 + jr nz, .shakeLoop ld a, d ld [hSCY], a ld a, $ff call PlaySound - ld c, BANK(SFX_02_5f) - ld a, (SFX_02_5f - SFX_Headers_02) / 3 + ld c, BANK(SFX_Safari_Zone_PA) + ld a, SFX_SAFARI_ZONE_PA call PlayMusic -.asm_7bf57 - ld a, [wc02a] +.musicLoop + ld a, [wChannelSoundIDs + CH4] cp $b9 - jr z, .asm_7bf57 + jr z, .musicLoop call UpdateSprites jp PlayDefaultMusic -Func_7bf64: ; 7bf64 (1e:7f64) +ShakeElevatorRedrawRow: ; 7bf64 (1e:7f64) +; This function is used to redraw certain portions of the screen, but it does +; not appear to ever result in any visible effect, so this function seems to +; be pointless. ld hl, wMapViewVRAMPointer + 1 ld a, [hld] push af diff --git a/engine/overworld/emotion_bubbles.asm b/engine/overworld/emotion_bubbles.asm index 7106063b..f8665dd6 100755 --- a/engine/overworld/emotion_bubbles.asm +++ b/engine/overworld/emotion_bubbles.asm @@ -1,30 +1,33 @@ EmotionBubble: ; 17c47 (5:7c47) - ld a, [wcd50] + ld a, [wWhichEmotionBubble] ld c, a - ld b, $0 - ld hl, EmotionBubblesPointerTable ; $7caf + ld b, 0 + ld hl, EmotionBubblesPointerTable add hl, bc add hl, bc ld e, [hl] inc hl ld d, [hl] ld hl, vChars1 + $780 - ld bc, (BANK(EmotionBubblesPointerTable) << 8) + $04 + lb bc, BANK(EmotionBubbles), $04 call CopyVideoData ld a, [wUpdateSpritesEnabled] push af 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,10 +50,11 @@ EmotionBubble: ; 17c47 (5:7c47) ld a, [hl] add $8 ld c, a - ld de, EmotionBubblesOAM ; $7cb5 + + ld de, EmotionBubblesOAM xor a call WriteOAMBlock - ld c, $3c + ld c, 60 call DelayFrames pop af ld [wUpdateSpritesEnabled], a diff --git a/engine/overworld/healing_machine.asm b/engine/overworld/healing_machine.asm index 23e24b23..8269aefd 100755 --- a/engine/overworld/healing_machine.asm +++ b/engine/overworld/healing_machine.asm @@ -1,59 +1,56 @@ AnimateHealingMachine: ; 7048b (1c:448b) ld de, PokeCenterFlashingMonitorAndHealBall ; $44b7 ld hl, vChars0 + $7c0 - ld bc, (BANK(PokeCenterFlashingMonitorAndHealBall) << 8) + $03 + lb bc, BANK(PokeCenterFlashingMonitorAndHealBall), $03 ; loads one too many tiles call CopyVideoData ld hl, wUpdateSpritesEnabled ld a, [hl] push af ld [hl], $ff push hl - ld a, [rOBP1] ; $ff49 + ld a, [rOBP1] push af ld a, $e0 ld [rOBP1], a ; $ff49 call Func_3061 ld hl, wOAMBuffer + $84 ld de, PokeCenterOAMData ; $44d7 - call Func_7055a - ld a, $4 - ld [wMusicHeaderPointer], a + call CopyHealingMachineOAM + ld a, 4 + ld [wAudioFadeOutControl], a call StopAllMusic - ;ld a, $ff - ;ld [wc0ee], a - ;call PlaySound -.asm_704ba - ld a, [wMusicHeaderPointer] +.waitLoop + ld a, [wAudioFadeOutControl] and a - jr nz, .asm_704ba + jr nz, .waitLoop ld a, [wPartyCount] ; wPartyCount ld b, a -.asm_704c4 - call Func_7055a +.partyLoop + call CopyHealingMachineOAM ld a, $9e ; (SFX_02_4a - SFX_Headers_02) / 3 call PlaySound - ld c, $1e + ld c, 30 call DelayFrames dec b - jr nz, .asm_704c4 - ld a, [wc0ef] + jr nz, .partyLoop + ld a, [wAudioROMBank] cp $1f - ld [wc0f0], a - jr nz, .asm_704e6 + ld [wAudioSavedROMBank], a + jr nz, .next call StopAllMusic ld a, $2 ; BANK(Music_PkmnHealed) - ld [wc0ef], a -.asm_704e6 + ld [wAudioROMBank], a +.next ld a, $e8 ; MUSIC_PKMN_HEALED - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld d, $28 call FlashSprite8Times -.asm_704f3 +.waitLoop2 ld a, [wc026] cp $e8 ; MUSIC_PKMN_HEALED - jr z, .asm_704f3 - ld c, $20 + jr z, .waitLoop2 + ld c, 32 call DelayFrames pop af ld [rOBP1], a ; $ff49 @@ -89,7 +86,8 @@ FlashSprite8Times: ; 70547 (1c:4547) jr nz, .loop ret -Func_7055a: ; 7055a (1c:455a) +CopyHealingMachineOAM: ; 7055a (1c:455a) +; copy one OAM entry and advance the pointers ld a, [de] inc de ld [hli], a diff --git a/engine/overworld/hidden_items.asm b/engine/overworld/hidden_items.asm index 17288a17..28528116 100755 --- a/engine/overworld/hidden_items.asm +++ b/engine/overworld/hidden_items.asm @@ -1,43 +1,41 @@ HiddenItems: ; 76688 (1d:6688) ld hl, HiddenItemCoords - call Func_76857 - ld [wTrainerScreenX], a - ld hl, wd6f0 - ld a, [wTrainerScreenX] + call FindHiddenItemOrCoinsIndex + ld [wHiddenItemOrCoinsIndex], a + ld hl, wObtainedHiddenItemsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $2 + ld b, FLAG_TEST predef FlagActionPredef ld a, c and a ret nz call EnableAutoTextBoxDrawing - ld a, $1 + ld a, 1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a - ld a, [wWhichTrade] ; item ID + ld a, [wHiddenObjectFunctionArgument] ; item ID ld [wd11e], a call GetItemName - ld a, $24 - jp PrintPredefTextID + tx_pre_jump FoundHiddenItemText INCLUDE "data/hidden_item_coords.asm" FoundHiddenItemText: ; 7675b (1d:675b) -; XXX where is the pointer to this? TX_FAR _FoundHiddenItemText - db $8 - ld a, [wWhichTrade] ; item ID + TX_ASM + ld a, [wHiddenObjectFunctionArgument] ; item ID ld b, a ld c, 1 call GiveItem jr nc, .BagFull - ld hl, wd6f0 - ld a, [wTrainerScreenX] + ld hl, wObtainedHiddenItemsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $1 + ld b, FLAG_SET predef FlagActionPredef - ld a, (SFX_02_3b - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound - call WaitForSoundToFinish ; wait for sound to finish playing + ld a, SFX_GET_ITEM_2 + call PlaySoundWaitForCurrent + call WaitForSoundToFinish jp TextScriptEnd .BagFull call WaitForTextScrollButtonPress ; wait for button press @@ -53,26 +51,26 @@ HiddenItemBagFullText: ; 76794 (1d:6794) HiddenCoins: ; 76799 (1d:6799) ld b, COIN_CASE - predef IsItemInBag_ + predef GetQuantityOfItemInBag ld a, b and a ret z ld hl, HiddenCoinCoords - call Func_76857 - ld [wTrainerScreenX], a - ld hl, wd6fe - ld a, [wTrainerScreenX] + call FindHiddenItemOrCoinsIndex + ld [wHiddenItemOrCoinsIndex], a + ld hl, wObtainedHiddenCoinsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $2 + ld b, FLAG_TEST predef FlagActionPredef ld a, c and a ret nz xor a - ld [$ff9f], a - ld [$ffa0], a - ld [$ffa1], a - ld a, [wWhichTrade] + ld [hUnusedCoinsByte], a + ld [hCoins], a + ld [hCoins + 1], a + ld a, [wHiddenObjectFunctionArgument] sub COIN cp 10 jr z, .bcd10 @@ -83,28 +81,28 @@ HiddenCoins: ; 76799 (1d:6799) jr .bcd100 .bcd10 ld a, $10 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd20 ld a, $20 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd40 ; due to a typo, this is never used ld a, $40 - ld [$ffa1], a + ld [hCoins + 1], a jr .bcddone .bcd100 ld a, $1 - ld [$ffa0], a + ld [hCoins], a .bcddone ld de, wPlayerCoins + 1 - ld hl, $ffa1 + ld hl, hCoins + 1 ld c, $2 predef AddBCDPredef - ld hl, wd6fe - ld a, [wTrainerScreenX] + ld hl, wObtainedHiddenCoinsFlags + ld a, [wHiddenItemOrCoinsIndex] ld c, a - ld b, $1 + ld b, FLAG_SET predef FlagActionPredef call EnableAutoTextBoxDrawing ld a, [wPlayerCoins] @@ -113,10 +111,10 @@ HiddenCoins: ; 76799 (1d:6799) ld a, [wPlayerCoins + 1] cp $99 jr nz, .RoomInCoinCase - ld a, $2c + tx_pre_id DroppedHiddenCoinsText jr .done .RoomInCoinCase - ld a, $2b + tx_pre_id FoundHiddenCoinsText .done jp PrintPredefTextID @@ -132,31 +130,31 @@ DroppedHiddenCoinsText: ; 7684d (1d:684d) TX_FAR _DroppedHiddenCoinsText db "@" -Func_76857: ; 76857 (1d:6857) - ld a, [wTrainerScreenY] +FindHiddenItemOrCoinsIndex: ; 76857 (1d:6857) + ld a, [wHiddenObjectY] ld d, a - ld a, [wTrainerScreenX] + ld a, [wHiddenObjectX] ld e, a ld a, [W_CURMAP] ld b, a - ld c, $ff + ld c, -1 .loop inc c ld a, [hli] cp $ff ; end of the list? ret z ; if so, we're done here cp b - jr nz, .asm_76877 ; 0x7686b $a + jr nz, .next1 ld a, [hli] cp d - jr nz, .asm_76878 ; 0x7686f $7 + jr nz, .next2 ld a, [hli] cp e jr nz, .loop ld a, c ret -.asm_76877 +.next1 inc hl -.asm_76878 +.next2 inc hl jr .loop diff --git a/engine/overworld/hidden_objects.asm b/engine/overworld/hidden_objects.asm index ae67aeed..cabfc093 100755 --- a/engine/overworld/hidden_objects.asm +++ b/engine/overworld/hidden_objects.asm @@ -1,4 +1,4 @@ -Func_46981: ; 46981 (11:6981) +IsPlayerOnDungeonWarp: ; 46981 (11:6981) xor a ld [wWhichDungeonWarp], a ld a, [wd72d] @@ -6,7 +6,7 @@ Func_46981: ; 46981 (11:6981) ret nz call ArePlayerCoordsInArray ret nc - ld a, [wWhichTrade] + ld a, [wCoordIndex] ld [wWhichDungeonWarp], a ld hl, wd72d set 4, [hl] @@ -58,7 +58,7 @@ CheckForHiddenObject: ; 469a0 (11:69a0) ld [wHiddenObjectX], a ld c, a call CheckIfCoordsInFrontOfPlayerMatch - ld a, [$ffea] + ld a, [hCoordsInFrontOfPlayerMatch] and a jr z, .foundMatchingObject inc hl @@ -85,7 +85,7 @@ CheckForHiddenObject: ; 469a0 (11:69a0) ret ; checks if the coordinates in front of the player's sprite match Y in b and X in c -; [$ffea] = $00 if they match, $ff if they don't match +; [hCoordsInFrontOfPlayerMatch] = $00 if they match, $ff if they don't match CheckIfCoordsInFrontOfPlayerMatch: ; 46a01 (11:6a01) ld a, [wSpriteStateData1 + 9] ; player's sprite facing direction cp SPRITE_FACING_UP @@ -127,7 +127,7 @@ CheckIfCoordsInFrontOfPlayerMatch: ; 46a01 (11:6a01) .didNotMatch ld a, $ff .done - ld [$ffea], a + ld [hCoordsInFrontOfPlayerMatch], a ret INCLUDE "data/hidden_objects.asm" diff --git a/engine/overworld/item.asm b/engine/overworld/item.asm index a49fc268..6fbe823d 100644 --- a/engine/overworld/item.asm +++ b/engine/overworld/item.asm @@ -1,7 +1,7 @@ -PickupItem: +PickUpItem: call EnableAutoTextBoxDrawing - ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c + ld a, [hSpriteIndexOrTextID] ld b, a ld hl, W_MISSABLEOBJECTLIST .missableObjectsListLoop @@ -18,7 +18,7 @@ PickupItem: ld [$ffdb], a ld hl, W_MAPSPRITEEXTRADATA - ld a, [H_DOWNARROWBLINKCNT2] ; $ff8c + ld a, [hSpriteIndexOrTextID] dec a add a ld d, 0 @@ -31,7 +31,7 @@ PickupItem: jr nc, .BagFull ld a, [$ffdb] - ld [wcc4d], a + ld [wMissableObjectIndex], a predef HideObject ld a, 1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a diff --git a/engine/overworld/ledges.asm b/engine/overworld/ledges.asm index b8c19181..df4273fd 100755 --- a/engine/overworld/ledges.asm +++ b/engine/overworld/ledges.asm @@ -2,7 +2,7 @@ HandleLedges: ; 1a672 (6:6672) ld a, [wd736] bit 6, a ; already jumping down ledge ret nz - ld a, [W_CURMAPTILESET] ; W_CURMAPTILESET + ld a, [W_CURMAPTILESET] and a ; OVERWORLD ret nz predef GetTileAndCoordsInFrontOfPlayer @@ -50,7 +50,7 @@ HandleLedges: ; 1a672 (6:6672) ld a, $2 ld [wSimulatedJoypadStatesIndex], a call LoadHoppingShadowOAM - ld a, (SFX_02_4e - SFX_Headers_02) / 3 + ld a, SFX_LEDGE call PlaySound ret @@ -69,16 +69,17 @@ LedgeTiles: ; 1a6cf (6:66cf) LoadHoppingShadowOAM: ; 1a6f0 (6:66f0) ld hl, vChars1 + $7f0 ld de, LedgeHoppingShadow - ld bc, (BANK(LedgeHoppingShadow) << 8) + $01 + lb bc, BANK(LedgeHoppingShadow), (LedgeHoppingShadowEnd - LedgeHoppingShadow) / $8 call CopyVideoDataDouble ld a, $9 - ld bc, $5448 ; b, c = y, x coordinates of shadow + lb bc, $54, $48 ; b, c = y, x coordinates of shadow ld de, LedgeHoppingShadowOAM call WriteOAMBlock ret LedgeHoppingShadow: ; 1a708 (6:6708) INCBIN "gfx/ledge_hopping_shadow.1bpp" +LedgeHoppingShadowEnd: LedgeHoppingShadowOAM: ; 1a710 (6:6710) db $FF,$10,$FF,$20 diff --git a/engine/overworld/map_sprites.asm b/engine/overworld/map_sprites.asm index 747a0a45..84d67b36 100755 --- a/engine/overworld/map_sprites.asm +++ b/engine/overworld/map_sprites.asm @@ -39,7 +39,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) ld b,$10 ; number of sprite slots ld hl,wSpriteStateData2 + $0d xor a - ld [$ff8e],a ; 4-tile sprite counter + ld [hFourTileSpriteCount],a .copyPictureIDLoop ; loop to copy picture ID from $C2XD to $C2XE ld a,[hli] ; $C2XD (sprite picture ID) ld [hld],a ; $C2XE @@ -98,14 +98,14 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) cp a,SPRITE_BALL ; is it a 4-tile sprite? jr c,.notFourTileSprite pop af - ld a,[$ff8e] ; 4-tile sprite counter + ld a,[hFourTileSpriteCount] add a,11 jr .storeVRAMSlot .notFourTileSprite pop af .storeVRAMSlot ld [hl],a ; store VRAM slot at $C2XE - ld [$ff8d],a ; used to determine if it's 4-tile sprite later + ld [hVRAMSlot],a ; used to determine if it's 4-tile sprite later ld a,b ; a = current sprite picture ID dec a add a @@ -128,7 +128,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) push bc ld hl,vNPCSprites ; VRAM base address ld bc,$c0 ; number of bytes per VRAM slot - ld a,[$ff8d] + ld a,[hVRAMSlot] cp a,11 ; is it a 4-tile sprite? jr nc,.fourTileSpriteVRAMAddr ld d,a @@ -142,13 +142,13 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) jr .loadStillTilePattern .fourTileSpriteVRAMAddr ld hl,vSprites + $7c0 ; address for second 4-tile sprite - ld a,[$ff8e] ; 4-tile sprite counter - and a ; is it the first 4-tile sprite? + ld a,[hFourTileSpriteCount] + and a jr nz,.loadStillTilePattern ; if it's the first 4-tile sprite ld hl,vSprites + $780 ; address for first 4-tile sprite inc a - ld [$ff8e],a ; 4-tile sprite counter + ld [hFourTileSpriteCount],a .loadStillTilePattern pop bc pop de @@ -168,7 +168,7 @@ LoadMapSpriteTilePatterns: ; 17871 (5:7871) .skipFirstLoad pop de pop hl - ld a,[$ff8d] + ld a,[hVRAMSlot] cp a,11 ; is it a 4-tile sprite? jr nc,.skipSecondLoad ; if so, there is no second block push de diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm index c4482700..be10fd69 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 a, [wWalkCounter] ; wcfc5 + ld h, wSpriteStateData1 / $100 + ld a, [wWalkCounter] and a - jr nz, .asm_4e90 - ld a, [wd528] - bit 2, a - jr z, .asm_4e65 - xor a - jr .asm_4e86 -.asm_4e65 - bit 3, a - jr z, .asm_4e6d - ld a, $4 - jr .asm_4e86 -.asm_4e6d - bit 1, a - jr z, .asm_4e75 - ld a, $8 - jr .asm_4e86 -.asm_4e75 - bit 0, a - jr z, .asm_4e7d - ld a, $c - jr .asm_4e86 -.asm_4e7d + jr nz, .moving + ld a, [wPlayerMovingDirection] +; check if down + bit PLAYER_DIR_BIT_DOWN, a + jr z, .checkIfUp + xor a ; ld a, SPRITE_FACING_DOWN + jr .next +.checkIfUp + bit PLAYER_DIR_BIT_UP, a + jr z, .checkIfLeft + ld a, SPRITE_FACING_UP + jr .next +.checkIfLeft + bit PLAYER_DIR_BIT_LEFT, a + jr z, .checkIfRight + ld a, SPRITE_FACING_LEFT + jr .next +.checkIfRight + bit PLAYER_DIR_BIT_RIGHT, a + jr z, .notMoving + ld a, SPRITE_FACING_RIGHT + jr .next +.notMoving +; zero the animation counters xor a ld [wSpriteStateData1 + 7], a ld [wSpriteStateData1 + 8], a - jr .asm_4eab -.asm_4e86 - ld [wSpriteStateData1 + 9], a + jr .calcImageIndex +.next + ld [wSpriteStateData1 + 9], a ; facing direction ld a, [wFontLoaded] bit 0, a - jr nz, .asm_4e7d -.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,12 +109,12 @@ 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 add a - ld hl, W_MAPSPRITEDATA ; wd4e4 + ld hl, W_MAPSPRITEDATA add l ld l, a ld a, [hl] ; read movement byte 2 @@ -138,7 +144,7 @@ Func_4ed1: ; 4ed1 (1:4ed1) jp z, UpdateSpriteMovementDelay ; c1x1 == 2 cp $3 jp z, UpdateSpriteInWalkingAnimation ; c1x1 == 3 - ld a, [wWalkCounter] ; wcfc5 + ld a, [wWalkCounter] and a ret nz ; don't do anything yet if player is currently moving (redundant, already tested in CheckSpriteAvailability) call InitializeSpriteScreenPosition @@ -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 + ld hl, wNPCNumScriptedSteps + dec [hl] ; decrement wNPCNumScriptedSteps 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,11 +208,10 @@ 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 - - ld bc, $400 + lb de, 1, 0 + lb bc, 4, SPRITE_FACING_DOWN jr TryWalking .notDown cp $80 ; $40 <= a < $80: up (or right) @@ -212,10 +220,10 @@ Func_4ed1: ; 4ed1 (1:4ed1) cp $2 jr z, .moveRight ; movement byte 2 = $2 only allows left or right .moveUp - ld de, -2*20 ; $ffd8 + ld de, -2*SCREEN_WIDTH add hl, de ; move tile pointer two rows up - ld de, $ff00 - ld bc, $804 + lb de, -1, 0 + lb bc, 8, SPRITE_FACING_UP jr TryWalking .notUp cp $c0 ; $80 <= a < $c0: left (or up) @@ -226,8 +234,8 @@ Func_4ed1: ; 4ed1 (1:4ed1) .moveLeft dec hl dec hl ; move tile pointer two columns left - ld de, $ff - ld bc, $208 + lb de, 0, -1 + lb bc, 2, SPRITE_FACING_LEFT jr TryWalking .notLeft ; $c0 <= a: right (or down) ld a, [wCurSpriteMovement2] @@ -236,8 +244,8 @@ Func_4ed1: ; 4ed1 (1:4ed1) .moveRight inc hl inc hl ; move tile pointer two columns right - ld de, $1 - ld bc, $10c + lb de, 0, 1 + lb bc, 1, SPRITE_FACING_RIGHT jr TryWalking ; changes facing direction by zeroing the movement delta and calling TryWalking @@ -249,7 +257,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 @@ -397,23 +405,23 @@ InitializeSpriteFacingDirection: ; 507f (1:507f) bit 5, a jr nz, notYetMoving res 7, [hl] - ld a, [wd52a] - bit 3, a + ld a, [wPlayerDirection] + bit PLAYER_DIR_BIT_UP, a jr z, .notFacingDown - ld c, $0 ; make sprite face down + ld c, SPRITE_FACING_DOWN jr .facingDirectionDetermined .notFacingDown - bit 2, a + bit PLAYER_DIR_BIT_DOWN, a jr z, .notFacingUp - ld c, $4 ; make sprite face up + ld c, SPRITE_FACING_UP jr .facingDirectionDetermined .notFacingUp - bit 1, a + bit PLAYER_DIR_BIT_LEFT, a jr z, .notFacingRight - ld c, $c ; make sprite face right + ld c, SPRITE_FACING_RIGHT jr .facingDirectionDetermined .notFacingRight - ld c, $8 ; make sprite face left + ld c, SPRITE_FACING_LEFT .facingDirectionDetermined ld a, [H_CURRENTSPRITEOFFSET] add $9 @@ -440,7 +448,7 @@ InitializeSpriteScreenPosition: ; 50bd (1:50bd) ld a, [H_CURRENTSPRITEOFFSET] add $4 ld l, a - ld a, [W_YCOORD] ; wd361 + ld a, [W_YCOORD] ld b, a ld a, [hl] ; c2x4 (Y position + 4) sub b ; relative to player position @@ -449,7 +457,7 @@ InitializeSpriteScreenPosition: ; 50bd (1:50bd) dec h ld [hli], a ; c1x4 (screen Y position) inc h - ld a, [W_XCOORD] ; wd362 + ld a, [W_XCOORD] ld b, a ld a, [hli] ; c2x6 (X position + 4) sub b ; relative to player position @@ -470,12 +478,12 @@ 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 ld b, [hl] ; c2x4: Y pos (+4) - ld a, [W_YCOORD] ; wd361 + ld a, [W_YCOORD] cp b jr z, .skipYVisibilityTest jr nc, .spriteInvisible ; above screen region @@ -485,7 +493,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) .skipYVisibilityTest inc l ld b, [hl] ; c2x5: X pos (+4) - ld a, [W_XCOORD] ; wd362 + ld a, [W_XCOORD] cp b jr z, .skipXVisibilityTest jr nc, .spriteInvisible ; left of screen region @@ -495,7 +503,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 @@ -503,7 +511,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) ld a, [hld] cp d jr nc, .spriteInvisible ; standing on tile with ID >=$60 (bottom right tile) - ld bc, -20 ; $ffec + ld bc, -20 add hl, bc ; go back one row of tiles ld a, [hli] cp d @@ -521,7 +529,7 @@ CheckSpriteAvailability: ; 50dc (1:50dc) jr .done .spriteVisible ld c, a - ld a, [wWalkCounter] ; wcfc5 + ld a, [wWalkCounter] and a jr nz, .done ; if player is currently walking, we're done call UpdateSpriteImage @@ -572,10 +580,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 +684,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 @@ -690,11 +699,11 @@ getTileSpriteStandsOn: ; 5207 (1:5207) ld a, [hl] ; c1x6: screen Y position srl a srl a - srl a ; screen X tile - add $14 ; screen X tile + 20 + srl a ; screen X tile + add SCREEN_WIDTH ; screen X tile + 20 ld d, $0 ld e, a - ld hl, wTileMap + coord hl, 0, 0 add hl, bc add hl, bc add hl, bc @@ -713,53 +722,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 +782,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 +817,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 +830,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 84e39853..098be875 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) - ld a, [W_XCOORD] ; wd362 +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 ; $ff8c + 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 where he needs to be. +.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,12 +144,12 @@ 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 ld a, $0 - ld [wcc4d], a + ld [wMissableObjectIndex], a predef HideObject ld hl, wd730 res 7, [hl] @@ -152,15 +158,15 @@ 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 + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a ld a, MUSIC_MUSEUM_GUY - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld a, [wSpriteIndex] swap a @@ -172,7 +178,7 @@ Func_1a514: ; 1a514 (6:6514) dec a ld [wSimulatedJoypadStatesIndex], a xor a - ld [wd12f], a + ld [wWhichPewterGuy], a predef PewterGuys ld hl, wNPCMovementDirections2 ld de, RLEList_PewterMuseumGuy @@ -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,15 +214,15 @@ 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 + ld [wAudioROMBank], a + ld [wAudioSavedROMBank], a ld a, MUSIC_MUSEUM_GUY - ld [wc0ee], a + ld [wNewSoundID], a call PlaySound ld a, [wSpriteIndex] swap a @@ -228,8 +234,8 @@ Func_1a581: ; 1a581 (6:6581) call DecodeRLEList dec a ld [wSimulatedJoypadStatesIndex], a - ld a, $1 - ld [wd12f], a + ld a, 1 + ld [wWhichPewterGuy], a predef PewterGuys ld hl, wNPCMovementDirections2 ld de, RLEList_PewterGymGuy @@ -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) @@ -280,7 +286,7 @@ FreezeEnemyTrainerSprite: ; 1a5e7 (6:65e7) jp SetSpriteMovementBytesToFF RivalIDs: ; 1a605 (6:6605) - db SONY1 + $c8 - db SONY2 + $c8 - db SONY3 + $c8 + db OPP_SONY1 + db OPP_SONY2 + db OPP_SONY3 db $ff diff --git a/engine/overworld/oaks_aide.asm b/engine/overworld/oaks_aide.asm index 68135287..8ac456d2 100755 --- a/engine/overworld/oaks_aide.asm +++ b/engine/overworld/oaks_aide.asm @@ -1,48 +1,48 @@ -OaksAideScript ; 0x59035 +OaksAideScript: ; 0x59035 ld hl, OaksAideHiText call PrintText call YesNoChoice ld a, [wCurrentMenuItem] and a - jr nz, .asm_59086 ; 0x59042 $42 + jr nz, .choseNo ld hl, wPokedexOwned ld b, wPokedexOwnedEnd - wPokedexOwned call CountSetBits - ld a, [wd11e] - ld [$ffdd], a + ld a, [wNumSetBits] + ld [hOaksAideNumMonsOwned], a ld b, a - ld a, [$ffdb] + ld a, [hOaksAideRequirement] cp b - jr z, .asm_59059 ; 0x59055 $2 - jr nc, .asm_5907c ; 0x59057 $23 -.asm_59059 + jr z, .giveItem + jr nc, .notEnoughOwnedMons +.giveItem ld hl, OaksAideHereYouGoText call PrintText - ld a, [$ffdc] + ld a, [hOaksAideRewardItem] ld b, a ld c, 1 call GiveItem - jr nc, .BagFull + jr nc, .bagFull ld hl, OaksAideGotItemText call PrintText ld a, $1 - jr .asm_5908e ; 0x59071 $1b -.BagFull + jr .done +.bagFull ld hl, OaksAideNoRoomText call PrintText xor a - jr .asm_5908e ; 0x5907a $12 -.asm_5907c + jr .done +.notEnoughOwnedMons ld hl, OaksAideUhOhText call PrintText ld a, $80 - jr .asm_5908e ; 0x59084 $8 -.asm_59086 + jr .done +.choseNo ld hl, OaksAideComeBackText call PrintText ld a, $ff -.asm_5908e - ld [$ffdb], a +.done + ld [hOaksAideResult], a ret OaksAideHiText: ; 59091 (16:5091) diff --git a/engine/overworld/oam.asm b/engine/overworld/oam.asm index 71eb297c..ff85eb3e 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/pewter_guys.asm b/engine/overworld/pewter_guys.asm index eb6dd5ac..4ac60e00 100755 --- a/engine/overworld/pewter_guys.asm +++ b/engine/overworld/pewter_guys.asm @@ -9,7 +9,7 @@ PewterGuys: ; 37ca1 (d:7ca1) ld d, h ld e, l ld hl, PointerTable_37ce6 - ld a, [wd12f] + ld a, [wWhichPewterGuy] add a ld b, 0 ld c, a @@ -21,17 +21,17 @@ PewterGuys: ; 37ca1 (d:7ca1) ld b, a ld a, [W_XCOORD] ld c, a -.asm_37cc7 +.findMatchingCoordsLoop ld a, [hli] cp b - jr nz, .asm_37ce1 + jr nz, .nextEntry1 ld a, [hli] cp c - jr nz, .asm_37ce2 + jr nz, .nextEntry2 ld a, [hli] ld h, [hl] ld l, a -.asm_37cd2 +.copyMovementDataLoop ld a, [hli] cp $ff ret z @@ -40,13 +40,13 @@ PewterGuys: ; 37ca1 (d:7ca1) ld a, [wSimulatedJoypadStatesIndex] inc a ld [wSimulatedJoypadStatesIndex], a - jr .asm_37cd2 -.asm_37ce1 + jr .copyMovementDataLoop +.nextEntry1 inc hl -.asm_37ce2 +.nextEntry2 inc hl inc hl - jr .asm_37cc7 + jr .findMatchingCoordsLoop PointerTable_37ce6: ; 37ce6 (d:7ce6) dw PewterMuseumGuyCoords @@ -66,17 +66,18 @@ PewterMuseumGuyCoords: ; 37cea (d:7cea) dw .right .down - db $40, $40, $ff + db D_UP, D_UP, $ff .up - db $10, $20, $ff + db D_RIGHT, D_LEFT, $ff .left - db $40, $10, $ff + db D_UP, D_RIGHT, $ff .right - db $40, $20, $ff + db D_UP, D_LEFT, $ff ; these are the five coordinates which trigger the gym guy and pointers to ; different movements for the player to make to get positioned before the ; main movement +; $00 is a pause PewterGymGuyCoords: ; 37d06 (d:7d06) db 16, 34 dw .one @@ -90,12 +91,12 @@ PewterGymGuyCoords: ; 37d06 (d:7d06) dw .five .one - db $20, $80, $80, $10, $ff + db D_LEFT, D_DOWN, D_DOWN, D_RIGHT, $ff .two - db $20, $80, $10, $20, $ff + db D_LEFT, D_DOWN, D_RIGHT, D_LEFT, $ff .three - db $20, $20, $20, $00, $00, $00, $00, $00, $00, $00, $00, $ff + db D_LEFT, D_LEFT, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff .four - db $20, $20, $40, $20, $ff + db D_LEFT, D_LEFT, D_UP, D_LEFT, $ff .five - db $20, $80, $20, $00, $00, $00, $00, $00, $00, $00, $00, $ff + db D_LEFT, D_DOWN, D_LEFT, $00, $00, $00, $00, $00, $00, $00, $00, $ff diff --git a/engine/overworld/player_animations.asm b/engine/overworld/player_animations.asm index fc0a3a6c..6488eaac 100755 --- a/engine/overworld/player_animations.asm +++ b/engine/overworld/player_animations.asm @@ -1,5 +1,5 @@ EnterMapAnim: ; 70567 (1c:4567) - call InitFacingDirectionBuffer + call InitFacingDirectionList ld a, $ec ld [wSpriteStateData1 + 4], a ; player's sprite Y screen position call Delay3 @@ -32,7 +32,7 @@ EnterMapAnim: ; 70567 (1c:4567) ld a, $8 ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue ld [hl], $ff ; wPlayerSpinInPlaceAnimSoundID - ld hl, wcd48 + ld hl, wFacingDirectionList call PlayerSpinInPlace ld a, $1 ld [wd431], a @@ -50,12 +50,8 @@ EnterMapAnim: ; 70567 (1c:4567) jr .done .flyAnimation pop hl - ;ld de, BirdSprite - ;ld hl, vNPCSprites - ;ld bc, (BANK(BirdSprite) << 8) + $0c - ;call CopyVideoData call LoadBirdSpriteGraphics - ld a, $a4 ; (SFX_02_50 - SFX_Headers_02) / 3 + ld a, $a4 ; SFX_BIRD_FLY call PlaySound ld hl, wFlyAnimUsingCoordList xor a ; is using coord list @@ -63,7 +59,7 @@ EnterMapAnim: ; 70567 (1c:4567) ld a, 12 ld [hli], a ; wFlyAnimCounter ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing right) - ld de, FlyAnimationEnterScreenCoords ; $4592 + ld de, FlyAnimationEnterScreenCoords call DoFlyAnimation call LoadPlayerSpriteGraphics ld a, $1 @@ -97,9 +93,10 @@ PlayerSpinWhileMovingDown: ; 70605 (1c:4605) ld [hl], a ; wPlayerSpinWhileMovingUpOrDownAnimFrameDelay jp PlayerSpinWhileMovingUpOrDown + _LeaveMapAnim: ; 70615 (1c:4615) call Func_1510 - call InitFacingDirectionBuffer + call InitFacingDirectionList call IsPlayerStandingOnWarpPadOrHole ld a, b and a @@ -141,8 +138,8 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayDelta xor a ld [hli], a ; wPlayerSpinInPlaceAnimFrameDelayEndValue - ld [hl], $a1 ; (SFX_02_4d - SFX_Headers_02) / 3 ; wPlayerSpinInPlaceAnimSoundID - ld hl, wcd48 + ld [hl], $a1 ; SFX_TELEPORT_EXIT_2 + ld hl, wFacingDirectionList call PlayerSpinInPlace jr .spinWhileMovingUp .flyAnimation @@ -154,7 +151,7 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld [hli], a ; wFlyAnimCounter ld [hl], $c ; wFlyAnimBirdSpriteImageIndex call DoFlyAnimation - ld a, $a4 ; (SFX_02_50 - SFX_Headers_02) / 3 + ld a, $a4 ; SFX_FLY call PlaySound ld hl, wFlyAnimUsingCoordList xor a ; is using coord list @@ -162,7 +159,7 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld a, $c ld [hli], a ; wFlyAnimCounter ld [hl], $c ; wFlyAnimBirdSpriteImageIndex (facing right) - ld de, FlyAnimationScreenCoords1 ; $464f + ld de, FlyAnimationScreenCoords1 call DoFlyAnimation ld c, 40 call DelayFrames @@ -170,7 +167,7 @@ _LeaveMapAnim: ; 70615 (1c:4615) ld a, 11 ld [hli], a ; wFlyAnimCounter ld [hl], $8 ; wFlyAnimBirdSpriteImageIndex (facing left) - ld de, FlyAnimationScreenCoords2 ; $4667 + ld de, FlyAnimationScreenCoords2 call DoFlyAnimation call GBFadeOutToWhite jp RestoreFacingDirectionAndYScreenPos @@ -222,7 +219,7 @@ LeaveMapThroughHoleAnim: ; 706db (1c:46db) 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 @@ -239,7 +236,7 @@ DoFlyAnimation: ; 7070c (1c:470c) call Delay3 ld a, [wFlyAnimUsingCoordList] cp $ff - jr z, .asm_7072b + jr z, .skipCopyingCoords ; if the bird is flapping its wings in place ld hl, wSpriteStateData1 + 4 ld a, [de] inc de @@ -248,7 +245,7 @@ DoFlyAnimation: ; 7070c (1c:470c) ld a, [de] inc de ld [hl], a -.asm_7072b +.skipCopyingCoords ld a, [wFlyAnimCounter] dec a ld [wFlyAnimCounter], a @@ -258,7 +255,7 @@ DoFlyAnimation: ; 7070c (1c:470c) LoadBirdSpriteGraphics: ; 70735 (1c:4735) ld de, BirdSprite ; $4d80 ld b, BANK(BirdSprite) - ld c,$c + ld c, $c ld hl, vNPCSprites call CopyVideoData ld de, BirdSprite + $c0 ; $4e40 ; moving amination sprite @@ -267,17 +264,18 @@ LoadBirdSpriteGraphics: ; 70735 (1c:4735) ld hl, vNPCSprites2 jp CopyVideoData -InitFacingDirectionBuffer: ; 7074f (1c:474f) +InitFacingDirectionList: ; 7074f (1c:474f) 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 @@ -291,15 +289,16 @@ PlayerSpinningFacingOrder: ; 70773 (1c:4773) db SPRITE_FACING_DOWN, SPRITE_FACING_LEFT, SPRITE_FACING_UP, SPRITE_FACING_RIGHT SpinPlayerSprite: ; 70777 (1c:4777) +; 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 @@ -308,11 +307,12 @@ PlayerSpinInPlace: ; 70790 (1c:4790) ld a, [wPlayerSpinInPlaceAnimFrameDelay] ld c, a and $3 - jr nz, .asm_707a3 + 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_707a3 +.skipPlayingSound ld a, [wPlayerSpinInPlaceAnimFrameDelayDelta] add c ld [wPlayerSpinInPlaceAnimFrameDelay], a @@ -340,9 +340,9 @@ PlayerSpinWhileMovingUpOrDown: ; 707b5 (1c:47b5) jr PlayerSpinWhileMovingUpOrDown RestoreFacingDirectionAndYScreenPos: ; 707d2 (1c:47d2) - ld a, [wcd4f] + ld a, [wSavedPlayerScreenY] ld [wSpriteStateData1 + 4], a - ld a, [wcd50] + ld a, [wSavedPlayerFacingDirection] ld [wSpriteStateData1 + 2], a ret @@ -377,10 +377,10 @@ IsPlayerStandingOnWarpPadOrHole: ; 707e7 (1c:47e7) ld b, [hl] .done ld a, b - ld [wcd5b], a + ld [wStandingOnWarpPadOrHole], a ret -; format: db tileset id, tile id, value to be put in wcd5b +; format: db tileset id, tile id, value to be put in [wStandingOnWarpPadOrHole] .warpPadAndHoleData: ; 70809 (1c:4809) db FACILITY, $20, 1 ; warp pad db FACILITY, $11, 2 ; hole @@ -388,8 +388,8 @@ IsPlayerStandingOnWarpPadOrHole: ; 707e7 (1c:47e7) db INTERIOR, $55, 1 ; warp pad db $FF -Func_70816: ; 70816 (1c:4816) - ld c, $a +FishingAnim: ; 70816 (1c:4816) + ld c, 10 call DelayFrames ld hl, wd736 set 6, [hl] @@ -399,60 +399,71 @@ Func_70816: ; 70816 (1c:4816) ld c, $c call CopyVideoData ld a, $4 - ld hl, RedFishingTiles ; $4866 + ld hl, RedFishingTiles call LoadAnimSpriteGfx ld a, [wSpriteStateData1 + 2] ld c, a ld b, $0 - ld hl, FishingRodGfxProperties ; $4856 + ld hl, FishingRodOAM add hl, bc ld de, wOAMBuffer + $9c ld bc, $4 call CopyData ld c, 100 call DelayFrames - ld a, [wWhichTrade] ; wWhichTrade + ld a, [wRodResponse] and a ld hl, NoNibbleText - jr z, .asm_70897 + jr z, .done cp $2 ld hl, NothingHereText - jr z, .asm_70897 - ld b, $a -.asm_7085f - ld hl, wSpriteStateData1 + 4 - call Func_708a3 + 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_708a3 + call .ShakePlayerSprite call Delay3 dec b - jr nz, .asm_7085f + 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] - cp $4 - jr nz, .asm_7087d + cp SPRITE_FACING_UP + jr nz, .skipHidingFishingRod ld a, $a0 ld [wOAMBuffer + $9c], a -.asm_7087d - 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_70894 +; 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_70894 + +.skipUnhidingFishingRod ld hl, ItsABiteText -.asm_70897 + +.done call PrintText ld hl, wd736 - res 6, [hl] + res 6, [hl] ; unreserve the last 4 OAM entries call LoadFontTilePatterns ret -Func_708a3: ; 708a3 (1c:48a3) +.ShakePlayerSprite ; 708a3 (1c:48a3) ld a, [hl] xor $1 ld [hl], a @@ -470,7 +481,7 @@ ItsABiteText: ; 708b2 (1c:48b2) TX_FAR _ItsABiteText db "@" -FishingRodGfxProperties: ; 708b7 (1c:48b7) +FishingRodOAM: ; 708b7 (1c:48b7) ; 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/pokecenter.asm b/engine/overworld/pokecenter.asm index 3c640d8e..f302d994 100755 --- a/engine/overworld/pokecenter.asm +++ b/engine/overworld/pokecenter.asm @@ -24,12 +24,12 @@ DisplayPokemonCenterDialogue_: ; 6fe6 (1:6fe6) predef HealParty callba AnimateHealingMachine ; do the healing machine animation xor a - ld [wMusicHeaderPointer], a - ld a, [wc0f0] - ld [wc0ef], a - ld a, [wd35b] - ld [wcfca], a - ld [wc0ee], a + ld [wAudioFadeOutControl], a + ld a, [wAudioSavedROMBank] + ld [wAudioROMBank], a + ld a, [wMapMusicSoundID] + ld [wLastMusicSoundID], a + ld [wNewSoundID], a call PlaySound ld hl, PokemonFightingFitText call PrintText @@ -43,7 +43,7 @@ DisplayPokemonCenterDialogue_: ; 6fe6 (1:6fe6) .done ld hl, PokemonCenterFarewellText call PrintText - jp UpdateSprites ; move sprites + jp UpdateSprites PokemonCenterWelcomeText: ; 705d (1:705d) TX_FAR _PokemonCenterWelcomeText diff --git a/engine/overworld/pokemart.asm b/engine/overworld/pokemart.asm index 8325b93f..ae96c4a9 100755 --- a/engine/overworld/pokemart.asm +++ b/engine/overworld/pokemart.asm @@ -1,30 +1,34 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) ld a,[wListScrollOffset] - ld [wd07e],a - call UpdateSprites ; move sprites + ld [wSavedListScrollOffset],a + call UpdateSprites xor a - ld [wcf0a],a ; flag that is set if something is sold or bought + ld [wBoughtOrSoldItemInMart],a .loop xor a ld [wListScrollOffset],a ld [wCurrentMenuItem],a ld [wPlayerMonNumber],a inc a - ld [wcf93],a + ld [wPrintItemPrices],a ld a,MONEY_BOX ld [wTextBoxID],a - call DisplayTextBoxID ; draw money text box + call DisplayTextBoxID ld a,BUY_SELL_QUIT_MENU ld [wTextBoxID],a - call DisplayTextBoxID ; do buy/sell/quit menu - ld hl,wd128 ; pointer to this pokemart's inventory + call DisplayTextBoxID + +; This code is useless. It copies the address of the pokemart's inventory to hl, +; but the address is never used. + ld hl,wItemListPointer ld a,[hli] ld l,[hl] - ld h,a ; hl = address of inventory - ld a,[wd12e] - cp a,$02 + ld h,a + + ld a,[wMenuExitMethod] + cp a,CANCELLED_MENU jp z,.done - ld a,[wd12d] ; ID of the chosen menu item + ld a,[wChosenMenuItem] and a ; buying? jp z,.buyMenu dec a ; selling? @@ -32,11 +36,14 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) dec a ; quitting? jp z,.done .sellMenu + +; the same variables are set again below, so this code has no effect xor a - ld [wcf93],a - ld a,$02 - ld [wd11b],a - callab Func_39bd5 + ld [wPrintItemPrices],a + ld a,INIT_BAG_ITEM_LIST + ld [wInitListType],a + callab InitList + ld a,[wNumBagItems] and a jp z,.bagEmpty @@ -50,19 +57,19 @@ 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 [wcf93],a + ld [wPrintItemPrices],a ld [wCurrentMenuItem],a ld a,ITEMLISTMENU ld [wListMenuID],a call DisplayListMenuID jp c,.returnToMainPokemartMenu ; if the player closed the menu .confirmItemSale ; if the player is trying to sell a specific item - call IsKeyItem ; check if item is unsellable - ld a,[wd124] + call IsKeyItem + ld a,[wIsKeyItem] and a jr nz,.unsellableItem ld a,[wcf91] @@ -70,30 +77,34 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) jr c,.unsellableItem ld a,PRICEDITEMLISTMENU ld [wListMenuID],a - ld [$ff8e],a ; halve prices when selling + ld [hHalveItemPrices],a ; halve prices when selling call DisplayChooseQuantityMenu inc a jr z,.sellMenuLoop ; if the player closed the choose quantity menu with the B button ld hl,PokemartTellSellPriceText - ld bc,$0e01 + lb bc, 14, 1 ; location that PrintText always prints to, this is useless call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 08, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu - ld a,[wd12e] - cp a,$02 - jr z,.sellMenuLoop ; if the player pressed the B button - ld a,[wd12d] ; ID of the chosen menu item + ld a,[wMenuExitMethod] + cp a,CHOSE_SECOND_ITEM + jr z,.sellMenuLoop ; if the player chose No or pressed the B button + +; The following code is supposed to check if the player chose No, but the above +; check already catches it. + ld a,[wChosenMenuItem] dec a - jr z,.sellMenuLoop ; if the player chose No + jr z,.sellMenuLoop + .sellItem - ld a,[wcf0a] ; flag that is set if something is sold or bought + ld a,[wBoughtOrSoldItemInMart] and a jr nz,.skipSettingFlag1 inc a - ld [wcf0a],a + ld [wBoughtOrSoldItemInMart],a .skipSettingFlag1 call AddAmountSoldToMoney ld hl,wNumBagItems @@ -106,39 +117,42 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) .bagEmpty ld hl,PokemartItemBagEmptyText call PrintText - call SaveScreenTilesToBuffer1 ; save screen + call SaveScreenTilesToBuffer1 jp .returnToMainPokemartMenu .buyMenu - ld a,$01 - ld [wcf93],a - ld a,$03 - ld [wd11b],a - callab Func_39bd5 + +; the same variables are set again below, so this code has no effect + ld a,1 + ld [wPrintItemPrices],a + ld a,INIT_OTHER_ITEM_LIST + ld [wInitListType],a + callab InitList + ld hl,PokemartBuyingGreetingText call PrintText - call SaveScreenTilesToBuffer1 ; save screen + call SaveScreenTilesToBuffer1 .buyMenuLoop - call LoadScreenTilesFromBuffer1 ; restore saved screen + call LoadScreenTilesFromBuffer1 ld a,MONEY_BOX ld [wTextBoxID],a - call DisplayTextBoxID ; draw money text box - ld hl,wStringBuffer2 + 11 + call DisplayTextBoxID + 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 - ld [wcf93],a + ld [wPrintItemPrices],a inc a ; a = 2 (PRICEDITEMLISTMENU) ld [wListMenuID],a call DisplayListMenuID jr c,.returnToMainPokemartMenu ; if the player closed the menu - ld a,$63 - ld [wcf97],a + ld a,99 + ld [wMaxItemQuantity],a xor a - ld [$ff8e],a + ld [hHalveItemPrices],a ; don't halve item prices when buying call DisplayChooseQuantityMenu inc a jr z,.buyMenuLoop ; if the player closed the choose quantity menu with the B button @@ -148,17 +162,21 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call CopyStringToCF4B ; copy name to wcf4b ld hl,PokemartTellBuyPriceText call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 8, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu - ld a,[wd12e] - cp a,$02 - jp z,.buyMenuLoop ; if the player pressed the B button - ld a,[wd12d] ; ID of the chosen menu item + ld a,[wMenuExitMethod] + cp a,CHOSE_SECOND_ITEM + jp z,.buyMenuLoop ; if the player chose No or pressed the B button + +; The following code is supposed to check if the player chose No, but the above +; check already catches it. + ld a,[wChosenMenuItem] dec a - jr z,.buyMenuLoop ; if the player chose No + jr z,.buyMenuLoop + .buyItem call .isThereEnoughMoney jr c,.notEnoughMoney @@ -166,13 +184,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call AddItemToInventory jr nc,.bagFull call SubtractAmountPaidFromMoney - ld a,[wcf0a] ; flag that is set if something is sold or bought + ld a,[wBoughtOrSoldItemInMart] and a jr nz,.skipSettingFlag2 - ld a,$01 - ld [wcf0a],a + ld a,1 + ld [wBoughtOrSoldItemInMart],a .skipSettingFlag2 - ld a,(SFX_02_5a - SFX_Headers_02) / 3 + ld a,SFX_PURCHASE call PlaySoundWaitForCurrent call WaitForSoundToFinish ld hl,PokemartBoughtItemText @@ -182,13 +200,13 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) call LoadScreenTilesFromBuffer1 ld a,MONEY_BOX ld [wTextBoxID],a - call DisplayTextBoxID ; draw money text box + call DisplayTextBoxID ld hl,PokemartAnythingElseText call PrintText jp .loop .isThereEnoughMoney ld de,wPlayerMoney - ld hl,$ff9f ; item price + ld hl,hMoney ld c,3 ; length of money in bytes jp StringCmp .notEnoughMoney @@ -202,10 +220,10 @@ DisplayPokemartDialogue_: ; 6c20 (1:6c20) .done ld hl,PokemartThankYouText call PrintText - ld a,$01 + ld a,1 ld [wUpdateSpritesEnabled],a - call UpdateSprites ; move sprites - ld a,[wd07e] + call UpdateSprites + ld a,[wSavedListScrollOffset] ld [wListScrollOffset],a ret diff --git a/engine/overworld/saffron_guards.asm b/engine/overworld/saffron_guards.asm index 8e584a2d..c0d6a985 100755 --- a/engine/overworld/saffron_guards.asm +++ b/engine/overworld/saffron_guards.asm @@ -10,9 +10,7 @@ RemoveGuardDrink: ; 5a59f (16:659f) call IsItemInBag pop hl jr z, .drinkLoop - ld b, BANK(RemoveItemByID) - ld hl, RemoveItemByID - jp Bankswitch + jpba RemoveItemByID GuardDrinksList: ; 5a5b7 (16:65b7) db FRESH_WATER, SODA_POP, LEMONADE, $00 diff --git a/engine/overworld/ssanne.asm b/engine/overworld/ssanne.asm index f1a8ecf9..e631bbfa 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 @@ -8,14 +8,14 @@ AnimateBoulderDust: ; 79f54 (1e:5f54) ld a, %11100100 ld [rOBP1], a call LoadSmokeTileFourTimes - callba WriteCutTreeBoulderDustAnimationOAMBlock + callba WriteCutOrBoulderDustAnimationOAMBlock ld c, 8 ; number of steps in animation .loop push bc call GetMoveBoulderDustFunctionPointer ld bc, .returnAddress push bc - ld c, $4 + ld c, 4 jp [hl] .returnAddress ld a, [rOBP1] @@ -36,7 +36,7 @@ GetMoveBoulderDustFunctionPointer: ; 79f92 (1e:5f92) ld b, $0 add hl, bc ld a, [hli] - ld [wd08a], a + ld [wCoordAdjustmentAmount], a ld a, [hli] ld e, a ld a, [hli] @@ -84,9 +84,10 @@ LoadSmokeTileFourTimes: ; 79fc0 (1e:5fc0) ret LoadSmokeTile: ; 79fd4 (1e:5fd4) - ld de, SSAnneSmokePuffTile ; $5fdd - ld bc, (BANK(SSAnneSmokePuffTile) << 8) + $01 + ld de, SSAnneSmokePuffTile + lb bc, BANK(SSAnneSmokePuffTile), (SSAnneSmokePuffTileEnd - SSAnneSmokePuffTile) / $10 jp CopyVideoData SSAnneSmokePuffTile: ; 79fdd (1e:5fdd) INCBIN "gfx/ss_anne_smoke_puff.2bpp" +SSAnneSmokePuffTileEnd: diff --git a/engine/overworld/trainers.asm b/engine/overworld/trainers.asm index 4aaab3ed..7d2ec0dd 100755 --- a/engine/overworld/trainers.asm +++ b/engine/overworld/trainers.asm @@ -24,16 +24,16 @@ _GetSpritePosition2: ; 56819 (15:6819) ld [H_SPRITEINDEX], a call GetSpriteDataPointer ld a, [hli] ; c1x4 (screen Y pos) - ld [wd130], a + ld [wSavedSpriteScreenY], a inc hl ld a, [hl] ; c1x6 (screen X pos) - ld [wd131], a + ld [wSavedSpriteScreenX], a ld de, $104 - $6 add hl, de ld a, [hli] ; c2x4 (map Y pos) - ld [wd132], a + ld [wSavedSpriteMapY], a ld a, [hl] ; c2x5 (map X pos) - ld [wd133], a + ld [wSavedSpriteMapX], a ret _SetSpritePosition1: ; 5683d (15:683d) @@ -61,23 +61,23 @@ _SetSpritePosition2: ; 5685d (15:685d) ld a, [wSpriteIndex] ld [H_SPRITEINDEX], a call GetSpriteDataPointer - ld a, [wd130] + ld a, [wSavedSpriteScreenY] ld [hli], a inc hl - ld a, [wd131] + ld a, [wSavedSpriteScreenX] ld [hl], a ld de, $00fe add hl, de - ld a, [wd132] + ld a, [wSavedSpriteMapY] ld [hli], a - ld a, [wd133] + ld a, [wSavedSpriteMapX] ld [hl], a ret TrainerWalkUpToPlayer: ; 56881 (15:6881) ld a, [wSpriteIndex] swap a - ld [wTrainerSpriteOffset], a ; wWhichTrade + ld [wTrainerSpriteOffset], a call ReadTrainerScreenPosition ld a, [wTrainerFacingDirection] and a @@ -164,7 +164,7 @@ GetSpriteDataPointer: ; 56903 (15:6903) TrainerEngage: ; 5690f (15:690f) push hl push de - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $2 ld d, $0 ld e, a @@ -175,7 +175,7 @@ TrainerEngage: ; 5690f (15:690f) jr nz, .spriteOnScreen ; test if sprite is on screen jp .noEngage .spriteOnScreen - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $9 ld d, $0 ld e, a @@ -218,7 +218,7 @@ TrainerEngage: ; 5690f (15:690f) jp .noEngage .engage call CheckPlayerIsInFrontOfSprite - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] and a jr z, .noEngage ld hl, wFlags_0xcd60 @@ -226,14 +226,14 @@ TrainerEngage: ; 5690f (15:690f) call EngageMapTrainer ld a, $ff .noEngage: ; 56988 (15:6988) - ld [wTrainerSpriteOffset], a ; wWhichTrade + ld [wTrainerSpriteOffset], a pop de pop hl ret ; reads trainer's Y position to wTrainerScreenY and X position to wTrainerScreenX ReadTrainerScreenPosition: ; 5698e (15:698e) - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $4 ld d, $0 ld e, a @@ -241,7 +241,7 @@ ReadTrainerScreenPosition: ; 5698e (15:698e) add hl, de ld a, [hl] ld [wTrainerScreenY], a - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $6 ld d, $0 ld e, a @@ -256,7 +256,7 @@ ReadTrainerScreenPosition: ; 5698e (15:698e) ; a: distance player to sprite CheckSpriteCanSeePlayer: ; 569af (15:69af) ld b, a - ld a, [wTrainerEngageDistance] ; sprite line of sight (engage distance) + ld a, [wTrainerEngageDistance] ; how far the trainer can see cp b jr nc, .checkIfLinedUp jr .notInLine ; player too far away @@ -291,10 +291,10 @@ CheckSpriteCanSeePlayer: ; 569af (15:69af) ; tests if the player is in front of the sprite (rather than behind it) CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3) - ld a, [W_CURMAP] ; W_CURMAP + ld a, [W_CURMAP] cp POWER_PLANT - jp z, .engage ; XXX not sure why bypass this for power plant (maybe to get voltorb fake items to work?) - ld a, [wTrainerSpriteOffset] ; wWhichTrade + jp z, .engage ; bypass this for power plant to get voltorb fake items to work + ld a, [wTrainerSpriteOffset] add $4 ld d, $0 ld e, a @@ -306,7 +306,7 @@ CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3) ld a, $c .notOnTopmostTile ld [wTrainerScreenY], a - ld a, [wTrainerSpriteOffset] ; wWhichTrade + ld a, [wTrainerSpriteOffset] add $6 ld d, $0 ld e, a @@ -345,5 +345,5 @@ CheckPlayerIsInFrontOfSprite: ; 569e3 (15:69e3) .noEngage xor a .done - ld [wTrainerSpriteOffset], a ; wWhichTrade + ld [wTrainerSpriteOffset], a ret |