2014-05-31 01:30:25 +00:00
|
|
|
HandleMidJump::
|
|
|
|
; Handle the player jumping down
|
|
|
|
; a ledge in the overworld.
|
2020-07-07 01:18:22 +00:00
|
|
|
farjp _HandleMidJump
|
2014-05-31 01:30:25 +00:00
|
|
|
|
|
|
|
EnterMap::
|
|
|
|
; Load a new map.
|
|
|
|
ld a, $ff
|
|
|
|
ld [wJoyIgnore], a
|
|
|
|
call LoadMapData
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall ClearVariablesOnEnterMap
|
2014-05-31 01:30:25 +00:00
|
|
|
ld hl, wd72c
|
2014-09-13 07:50:56 +00:00
|
|
|
bit 0, [hl] ; has the player already made 3 steps since the last battle?
|
|
|
|
jr z, .skipGivingThreeStepsOfNoRandomBattles
|
|
|
|
ld a, 3 ; minimum number of steps between battles
|
|
|
|
ld [wNumberOfNoRandomBattleStepsLeft], a
|
|
|
|
.skipGivingThreeStepsOfNoRandomBattles
|
2014-05-31 01:30:25 +00:00
|
|
|
ld hl, wd72e
|
|
|
|
bit 5, [hl] ; did a battle happen immediately before this?
|
|
|
|
res 5, [hl] ; unset the "battle just happened" flag
|
2014-09-14 18:29:18 +00:00
|
|
|
call z, ResetUsingStrengthOutOfBattleBit
|
2014-05-31 01:30:25 +00:00
|
|
|
call nz, MapEntryAfterBattle
|
|
|
|
ld hl, wd732
|
|
|
|
ld a, [hl]
|
2014-09-13 07:50:56 +00:00
|
|
|
and 1 << 4 | 1 << 3 ; fly warp or dungeon warp
|
|
|
|
jr z, .didNotEnterUsingFlyWarpOrDungeonWarp
|
2014-05-31 01:30:25 +00:00
|
|
|
res 3, [hl]
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall EnterMapAnim
|
2014-05-31 01:30:25 +00:00
|
|
|
call UpdateSprites
|
2014-09-13 07:50:56 +00:00
|
|
|
.didNotEnterUsingFlyWarpOrDungeonWarp
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall CheckForceBikeOrSurf ; handle currents in SF islands and forced bike riding in cycling road
|
2014-05-31 01:30:25 +00:00
|
|
|
ld hl, wd72d
|
|
|
|
res 5, [hl]
|
|
|
|
call UpdateSprites
|
2016-01-03 19:17:10 +00:00
|
|
|
ld hl, wCurrentMapScriptFlags
|
2014-05-31 01:30:25 +00:00
|
|
|
set 5, [hl]
|
|
|
|
set 6, [hl]
|
|
|
|
xor a
|
|
|
|
ld [wJoyIgnore], a
|
|
|
|
|
|
|
|
OverworldLoop::
|
|
|
|
call DelayFrame
|
|
|
|
OverworldLoopLessDelay::
|
|
|
|
call DelayFrame
|
|
|
|
call LoadGBPal
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd736]
|
|
|
|
bit 6, a ; jumping down a ledge?
|
2014-05-31 01:30:25 +00:00
|
|
|
call nz, HandleMidJump
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wWalkCounter]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, .moveAhead ; if the player sprite has not yet completed the walking animation
|
2014-05-31 01:30:25 +00:00
|
|
|
call JoypadOverworld ; get joypad state (which is possibly simulated)
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall SafariZoneCheck
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wSafariZoneGameOver]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, WarpFound2
|
|
|
|
ld hl, wd72d
|
|
|
|
bit 3, [hl]
|
|
|
|
res 3, [hl]
|
|
|
|
jp nz, WarpFound2
|
|
|
|
ld a, [wd732]
|
2016-06-12 18:35:21 +00:00
|
|
|
and 1 << 4 | 1 << 3 ; fly warp or dungeon warp
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, HandleFlyWarpOrDungeonWarp
|
|
|
|
ld a, [wCurOpponent]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, .newBattle
|
|
|
|
ld a, [wd730]
|
|
|
|
bit 7, a ; are we simulating button presses?
|
|
|
|
jr z, .notSimulating
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hJoyHeld]
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .checkIfStartIsPressed
|
|
|
|
.notSimulating
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hJoyPressed]
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfStartIsPressed
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 3, a ; start button
|
|
|
|
jr z, .startButtonNotPressed
|
2014-05-31 01:30:25 +00:00
|
|
|
; if START is pressed
|
2020-07-04 21:09:35 +00:00
|
|
|
xor a ; TEXT_START_MENU
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSpriteIndexOrTextID], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jp .displayDialogue
|
|
|
|
.startButtonNotPressed
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 0, a ; A button
|
|
|
|
jp z, .checkIfDownButtonIsPressed
|
2014-05-31 01:30:25 +00:00
|
|
|
; if A is pressed
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd730]
|
|
|
|
bit 2, a
|
|
|
|
jp nz, .noDirectionButtonsPressed
|
2014-09-14 18:29:18 +00:00
|
|
|
call IsPlayerCharacterBeingControlledByGame
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .checkForOpponent
|
2014-09-14 18:29:18 +00:00
|
|
|
call CheckForHiddenObjectOrBookshelfOrCardKeyDoor
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hItemAlreadyFound]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, OverworldLoop ; jump if a hidden object or bookshelf was found, but not if a card key door was found
|
2014-09-14 18:29:18 +00:00
|
|
|
call IsSpriteOrSignInFrontOfPlayer
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hSpriteIndexOrTextID]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, OverworldLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.displayDialogue
|
2014-09-13 07:50:56 +00:00
|
|
|
predef GetTileAndCoordsInFrontOfPlayer
|
|
|
|
call UpdateSprites
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wFlags_0xcd60]
|
|
|
|
bit 2, a
|
|
|
|
jr nz, .checkForOpponent
|
|
|
|
bit 0, a
|
|
|
|
jr nz, .checkForOpponent
|
2014-06-25 20:58:27 +00:00
|
|
|
aCoord 8, 9
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wTilePlayerStandingOn], a ; unused?
|
2014-05-31 01:30:25 +00:00
|
|
|
call DisplayTextID ; display either the start menu or the NPC/sign text
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wEnteringCableClub]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .checkForOpponent
|
2014-05-31 01:30:25 +00:00
|
|
|
dec a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, 0
|
|
|
|
ld [wEnteringCableClub], a
|
|
|
|
jr z, .changeMap
|
2015-07-26 02:26:54 +00:00
|
|
|
; XXX can this code be reached?
|
2014-06-16 20:57:26 +00:00
|
|
|
predef LoadSAV
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMap]
|
|
|
|
ld [wDestinationMap], a
|
2014-09-13 07:50:56 +00:00
|
|
|
call SpecialWarpIn
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMap]
|
2014-05-31 01:30:25 +00:00
|
|
|
call SwitchToMapRomBank ; switch to the ROM bank of the current map
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wCurMapTileset
|
|
|
|
set 7, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
.changeMap
|
|
|
|
jp EnterMap
|
|
|
|
.checkForOpponent
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurOpponent]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, .newBattle
|
2014-05-31 01:30:25 +00:00
|
|
|
jp OverworldLoop
|
|
|
|
.noDirectionButtonsPressed
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wFlags_0xcd60
|
|
|
|
res 2, [hl]
|
2014-09-13 07:50:56 +00:00
|
|
|
call UpdateSprites
|
2016-06-12 18:35:21 +00:00
|
|
|
ld a, 1
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wCheckFor180DegreeTurn], a
|
|
|
|
ld a, [wPlayerMovingDirection] ; the direction that was pressed last time
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, OverworldLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
; if a direction was pressed last time
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wPlayerLastStopDirection], a ; save the last direction
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wPlayerMovingDirection], a ; zero the direction
|
2014-05-31 01:30:25 +00:00
|
|
|
jp OverworldLoop
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfDownButtonIsPressed
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hJoyHeld] ; current joypad state
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 7, a ; down button
|
|
|
|
jr z, .checkIfUpButtonIsPressed
|
|
|
|
ld a, 1
|
2020-07-05 21:29:11 +00:00
|
|
|
ld [wSpritePlayerStateData1YStepVector], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, PLAYER_DIR_DOWN
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .handleDirectionButtonPress
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfUpButtonIsPressed
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 6, a ; up button
|
|
|
|
jr z, .checkIfLeftButtonIsPressed
|
|
|
|
ld a, -1
|
2020-07-05 21:29:11 +00:00
|
|
|
ld [wSpritePlayerStateData1YStepVector], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, PLAYER_DIR_UP
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .handleDirectionButtonPress
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfLeftButtonIsPressed
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 5, a ; left button
|
|
|
|
jr z, .checkIfRightButtonIsPressed
|
|
|
|
ld a, -1
|
2020-07-05 21:29:11 +00:00
|
|
|
ld [wSpritePlayerStateData1XStepVector], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, PLAYER_DIR_LEFT
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .handleDirectionButtonPress
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfRightButtonIsPressed
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 4, a ; right button
|
|
|
|
jr z, .noDirectionButtonsPressed
|
2016-06-12 18:35:21 +00:00
|
|
|
ld a, 1
|
2020-07-05 21:29:11 +00:00
|
|
|
ld [wSpritePlayerStateData1XStepVector], a
|
2016-06-12 18:35:21 +00:00
|
|
|
|
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.handleDirectionButtonPress
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wPlayerDirection], a ; new direction
|
|
|
|
ld a, [wd730]
|
|
|
|
bit 7, a ; are we simulating button presses?
|
|
|
|
jr nz, .noDirectionChange ; ignore direction changes if we are
|
|
|
|
ld a, [wCheckFor180DegreeTurn]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .noDirectionChange
|
|
|
|
ld a, [wPlayerDirection] ; new direction
|
|
|
|
ld b, a
|
|
|
|
ld a, [wPlayerLastStopDirection] ; old direction
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .noDirectionChange
|
2015-07-25 03:27:59 +00:00
|
|
|
; Check whether the player did a 180-degree turn.
|
|
|
|
; It appears that this code was supposed to show the player rotate by having
|
|
|
|
; the player's sprite face an intermediate direction before facing the opposite
|
|
|
|
; direction (instead of doing an instantaneous about-face), but the intermediate
|
|
|
|
; direction is only set for a short period of time. It is unlikely for it to
|
|
|
|
; ever be visible because DelayFrame is called at the start of OverworldLoop and
|
|
|
|
; normally not enough cycles would be executed between then and the time the
|
|
|
|
; direction is set for V-blank to occur while the direction is still set.
|
2014-05-31 01:30:25 +00:00
|
|
|
swap a ; put old direction in upper half
|
|
|
|
or b ; put new direction in lower half
|
2017-12-30 00:54:27 +00:00
|
|
|
cp (PLAYER_DIR_DOWN << 4) | PLAYER_DIR_UP ; change dir from down to up
|
|
|
|
jr nz, .notDownToUp
|
|
|
|
ld a, PLAYER_DIR_LEFT
|
|
|
|
ld [wPlayerMovingDirection], a
|
2015-07-25 03:27:59 +00:00
|
|
|
jr .holdIntermediateDirectionLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.notDownToUp
|
2017-12-30 00:54:27 +00:00
|
|
|
cp (PLAYER_DIR_UP << 4) | PLAYER_DIR_DOWN ; change dir from up to down
|
|
|
|
jr nz, .notUpToDown
|
|
|
|
ld a, PLAYER_DIR_RIGHT
|
|
|
|
ld [wPlayerMovingDirection], a
|
2015-07-25 03:27:59 +00:00
|
|
|
jr .holdIntermediateDirectionLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.notUpToDown
|
2017-12-30 00:54:27 +00:00
|
|
|
cp (PLAYER_DIR_RIGHT << 4) | PLAYER_DIR_LEFT ; change dir from right to left
|
|
|
|
jr nz, .notRightToLeft
|
|
|
|
ld a, PLAYER_DIR_DOWN
|
|
|
|
ld [wPlayerMovingDirection], a
|
2015-07-25 03:27:59 +00:00
|
|
|
jr .holdIntermediateDirectionLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.notRightToLeft
|
2017-12-30 00:54:27 +00:00
|
|
|
cp (PLAYER_DIR_LEFT << 4) | PLAYER_DIR_RIGHT ; change dir from left to right
|
|
|
|
jr nz, .holdIntermediateDirectionLoop
|
|
|
|
ld a, PLAYER_DIR_UP
|
|
|
|
ld [wPlayerMovingDirection], a
|
2015-07-25 03:27:59 +00:00
|
|
|
.holdIntermediateDirectionLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wFlags_0xcd60
|
|
|
|
set 2, [hl]
|
|
|
|
ld hl, wCheckFor180DegreeTurn
|
2014-05-31 01:30:25 +00:00
|
|
|
dec [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .holdIntermediateDirectionLoop
|
|
|
|
ld a, [wPlayerDirection]
|
|
|
|
ld [wPlayerMovingDirection], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call NewBattle
|
2017-12-30 00:54:27 +00:00
|
|
|
jp c, .battleOccurred
|
2014-05-31 01:30:25 +00:00
|
|
|
jp OverworldLoop
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.noDirectionChange
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wPlayerDirection] ; current direction
|
|
|
|
ld [wPlayerMovingDirection], a ; save direction
|
2014-09-13 07:50:56 +00:00
|
|
|
call UpdateSprites
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wWalkBikeSurfState]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $02 ; surfing
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .surfing
|
2014-05-31 01:30:25 +00:00
|
|
|
; not surfing
|
|
|
|
call CollisionCheckOnLand
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nc, .noCollision
|
2014-09-13 07:50:56 +00:00
|
|
|
; collision occurred
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd736
|
|
|
|
bit 2, [hl] ; standing on warp flag
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, OverworldLoop
|
2014-09-13 07:50:56 +00:00
|
|
|
; collision occurred while standing on a warp
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
|
|
|
call ExtraWarpCheck ; sets carry if there is a potential to warp
|
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
jp c, CheckWarpsCollision
|
2014-05-31 01:30:25 +00:00
|
|
|
jp OverworldLoop
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.surfing
|
|
|
|
call CollisionCheckOnWater
|
2017-12-30 00:54:27 +00:00
|
|
|
jp c, OverworldLoop
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.noCollision
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $08
|
|
|
|
ld [wWalkCounter], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .moveAhead2
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.moveAhead
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd736]
|
|
|
|
bit 7, a
|
|
|
|
jr z, .noSpinning
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall LoadSpinnerArrowTiles
|
2014-05-31 01:30:25 +00:00
|
|
|
.noSpinning
|
2015-07-03 19:37:53 +00:00
|
|
|
call UpdateSprites
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.moveAhead2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wFlags_0xcd60
|
|
|
|
res 2, [hl]
|
|
|
|
ld a, [wWalkBikeSurfState]
|
2014-05-31 01:30:25 +00:00
|
|
|
dec a ; riding a bike?
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .normalPlayerSpriteAdvancement
|
|
|
|
ld a, [wd736]
|
|
|
|
bit 6, a ; jumping a ledge?
|
|
|
|
jr nz, .normalPlayerSpriteAdvancement
|
2016-06-12 18:35:21 +00:00
|
|
|
call DoBikeSpeedup
|
2014-05-31 01:30:25 +00:00
|
|
|
.normalPlayerSpriteAdvancement
|
|
|
|
call AdvancePlayerSprite
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wWalkCounter]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, CheckMapConnections ; it seems like this check will never succeed (the other place where CheckMapConnections is run works)
|
2014-05-31 01:30:25 +00:00
|
|
|
; walking animation finished
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd730]
|
|
|
|
bit 7, a
|
|
|
|
jr nz, .doneStepCounting ; if button presses are being simulated, don't count steps
|
2014-05-31 01:30:25 +00:00
|
|
|
; step counting
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wStepCounter
|
2014-05-31 01:30:25 +00:00
|
|
|
dec [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd72c]
|
|
|
|
bit 0, a
|
|
|
|
jr z, .doneStepCounting
|
|
|
|
ld hl, wNumberOfNoRandomBattleStepsLeft
|
2014-05-31 01:30:25 +00:00
|
|
|
dec [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .doneStepCounting
|
|
|
|
ld hl, wd72c
|
|
|
|
res 0, [hl] ; indicate that the player has stepped thrice since the last battle
|
2014-05-31 01:30:25 +00:00
|
|
|
.doneStepCounting
|
2015-07-21 01:32:02 +00:00
|
|
|
CheckEvent EVENT_IN_SAFARI_ZONE
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .notSafariZone
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall SafariZoneCheckSteps
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wSafariZoneGameOver]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, WarpFound2
|
2014-05-31 01:30:25 +00:00
|
|
|
.notSafariZone
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wIsInBattle]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, CheckWarpsNoCollision
|
2014-09-13 07:50:56 +00:00
|
|
|
predef ApplyOutOfBattlePoisonDamage ; also increment daycare mon exp
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wOutOfBattleBlackout]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, HandleBlackOut ; if all pokemon fainted
|
2014-05-31 01:30:25 +00:00
|
|
|
.newBattle
|
|
|
|
call NewBattle
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd736
|
|
|
|
res 2, [hl] ; standing on warp flag
|
|
|
|
jp nc, CheckWarpsNoCollision ; check for warps if there was no battle
|
2014-05-31 01:30:25 +00:00
|
|
|
.battleOccurred
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd72d
|
|
|
|
res 6, [hl]
|
|
|
|
ld hl, wFlags_D733
|
|
|
|
res 3, [hl]
|
|
|
|
ld hl, wCurrentMapScriptFlags
|
|
|
|
set 5, [hl]
|
|
|
|
set 6, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hJoyHeld], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMap]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp CINNABAR_GYM
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .notCinnabarGym
|
2015-07-21 01:32:02 +00:00
|
|
|
SetEvent EVENT_2A7
|
2014-05-31 01:30:25 +00:00
|
|
|
.notCinnabarGym
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd72e
|
|
|
|
set 5, [hl]
|
|
|
|
ld a, [wCurMap]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp OAKS_LAB
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, .noFaintCheck ; no blacking out if the player lost to the rival in Oak's lab
|
2020-07-07 01:18:22 +00:00
|
|
|
callfar AnyPartyAlive
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, d
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .allPokemonFainted
|
2014-05-31 01:30:25 +00:00
|
|
|
.noFaintCheck
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, 10
|
2014-05-31 01:30:25 +00:00
|
|
|
call DelayFrames
|
|
|
|
jp EnterMap
|
|
|
|
.allPokemonFainted
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $ff
|
|
|
|
ld [wIsInBattle], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call RunMapScript
|
|
|
|
jp HandleBlackOut
|
|
|
|
|
|
|
|
; function to determine if there will be a battle and execute it (either a trainer battle or wild battle)
|
|
|
|
; sets carry if a battle occurred and unsets carry if not
|
2016-06-12 00:24:04 +00:00
|
|
|
NewBattle::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd72d]
|
|
|
|
bit 4, a
|
|
|
|
jr nz, .noBattle
|
2014-09-14 18:29:18 +00:00
|
|
|
call IsPlayerCharacterBeingControlledByGame
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .noBattle ; no battle if the player character is under the game's control
|
|
|
|
ld a, [wd72e]
|
|
|
|
bit 4, a
|
|
|
|
jr nz, .noBattle
|
2020-07-07 01:18:22 +00:00
|
|
|
farjp InitBattle
|
2014-05-31 01:30:25 +00:00
|
|
|
.noBattle
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
; function to make bikes twice as fast as walking
|
2016-06-12 18:35:21 +00:00
|
|
|
DoBikeSpeedup::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNPCMovementScriptPointerTableNum]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
|
|
|
ret nz
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMap]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp ROUTE_17 ; Cycling Road
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .goFaster
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hJoyHeld]
|
2016-06-12 18:35:21 +00:00
|
|
|
and D_UP | D_LEFT | D_RIGHT
|
2014-05-31 01:30:25 +00:00
|
|
|
ret nz
|
|
|
|
.goFaster
|
|
|
|
jp AdvancePlayerSprite
|
|
|
|
|
|
|
|
; check if the player has stepped onto a warp after having not collided
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckWarpsNoCollision::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNumberOfWarps]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, CheckMapConnections
|
|
|
|
ld a, [wNumberOfWarps]
|
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
|
|
|
ld a, [wYCoord]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wXCoord]
|
|
|
|
ld e, a
|
|
|
|
ld hl, wWarpEntries
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckWarpsNoCollisionLoop::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; check if the warp's Y position matches
|
2014-05-31 01:30:25 +00:00
|
|
|
cp d
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, CheckWarpsNoCollisionRetry1
|
|
|
|
ld a, [hli] ; check if the warp's X position matches
|
2014-05-31 01:30:25 +00:00
|
|
|
cp e
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, CheckWarpsNoCollisionRetry2
|
2014-05-31 01:30:25 +00:00
|
|
|
; if a match was found
|
|
|
|
push hl
|
|
|
|
push bc
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd736
|
|
|
|
set 2, [hl] ; standing on warp flag
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall IsPlayerStandingOnDoorTileOrWarpTile
|
2014-05-31 01:30:25 +00:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
jr c, WarpFound1 ; jump if standing on door or warp
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
|
|
|
push bc
|
2014-09-13 07:50:56 +00:00
|
|
|
call ExtraWarpCheck
|
2014-05-31 01:30:25 +00:00
|
|
|
pop bc
|
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nc, CheckWarpsNoCollisionRetry2
|
2014-05-31 01:30:25 +00:00
|
|
|
; if the extra check passed
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wFlags_D733]
|
|
|
|
bit 2, a
|
|
|
|
jr nz, WarpFound1
|
2014-05-31 01:30:25 +00:00
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
call Joypad
|
|
|
|
pop bc
|
|
|
|
pop de
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hJoyHeld]
|
2016-06-12 18:35:21 +00:00
|
|
|
and D_DOWN | D_UP | D_LEFT | D_RIGHT
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, CheckWarpsNoCollisionRetry2 ; if directional buttons aren't being pressed, do not pass through the warp
|
2014-05-31 01:30:25 +00:00
|
|
|
jr WarpFound1
|
|
|
|
|
|
|
|
; check if the player has stepped onto a warp after having collided
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckWarpsCollision::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNumberOfWarps]
|
|
|
|
ld c, a
|
|
|
|
ld hl, wWarpEntries
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; Y coordinate of warp
|
|
|
|
ld b, a
|
|
|
|
ld a, [wYCoord]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .retry1
|
|
|
|
ld a, [hli] ; X coordinate of warp
|
|
|
|
ld b, a
|
|
|
|
ld a, [wXCoord]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .retry2
|
|
|
|
ld a, [hli]
|
|
|
|
ld [wDestinationWarpID], a
|
|
|
|
ld a, [hl]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hWarpDestinationMap], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jr WarpFound2
|
|
|
|
.retry1
|
|
|
|
inc hl
|
|
|
|
.retry2
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .loop
|
2014-05-31 01:30:25 +00:00
|
|
|
jp OverworldLoop
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckWarpsNoCollisionRetry1::
|
2014-05-31 01:30:25 +00:00
|
|
|
inc hl
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckWarpsNoCollisionRetry2::
|
2014-05-31 01:30:25 +00:00
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
jp ContinueCheckWarpsNoCollisionLoop
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
WarpFound1::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [wDestinationWarpID], a
|
|
|
|
ld a, [hli]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hWarpDestinationMap], a
|
2014-05-31 01:30:25 +00:00
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
WarpFound2::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNumberOfWarps]
|
2014-05-31 01:30:25 +00:00
|
|
|
sub c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wWarpedFromWhichWarp], a ; save ID of used warp
|
|
|
|
ld a, [wCurMap]
|
|
|
|
ld [wWarpedFromWhichMap], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call CheckIfInOutsideMap
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .indoorMaps
|
2014-05-31 01:30:25 +00:00
|
|
|
; this is for handling "outside" maps that can't have the 0xFF destination map
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMap]
|
|
|
|
ld [wLastMap], a
|
|
|
|
ld a, [wCurMapWidth]
|
|
|
|
ld [wUnusedD366], a ; not read
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hWarpDestinationMap]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wCurMap], a
|
2019-01-01 20:06:23 +00:00
|
|
|
cp ROCK_TUNNEL_1F
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .notRockTunnel
|
|
|
|
ld a, $06
|
|
|
|
ld [wMapPalOffset], a
|
2014-09-13 07:50:56 +00:00
|
|
|
call GBFadeOutToBlack
|
2014-05-31 01:30:25 +00:00
|
|
|
.notRockTunnel
|
|
|
|
call PlayMapChangeSound
|
|
|
|
jr .done
|
2016-06-12 18:35:21 +00:00
|
|
|
|
|
|
|
; for maps that can have the 0xFF destination map, which means to return to the outside map
|
|
|
|
; not all these maps are necessarily indoors, though
|
2014-05-31 01:30:25 +00:00
|
|
|
.indoorMaps
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hWarpDestinationMap] ; destination map
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .goBackOutside
|
2014-05-31 01:30:25 +00:00
|
|
|
; if not going back to the previous map
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wCurMap], a
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall IsPlayerStandingOnWarpPadOrHole
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wStandingOnWarpPadOrHole]
|
2014-09-13 07:50:56 +00:00
|
|
|
dec a ; is the player on a warp pad?
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .notWarpPad
|
2014-09-13 07:50:56 +00:00
|
|
|
; if the player is on a warp pad
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd732
|
|
|
|
set 3, [hl]
|
2014-06-16 20:03:05 +00:00
|
|
|
call LeaveMapAnim
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .skipMapChangeSound
|
2014-09-13 07:50:56 +00:00
|
|
|
.notWarpPad
|
2014-05-31 01:30:25 +00:00
|
|
|
call PlayMapChangeSound
|
|
|
|
.skipMapChangeSound
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd736
|
|
|
|
res 0, [hl]
|
|
|
|
res 1, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .done
|
|
|
|
.goBackOutside
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wLastMap]
|
|
|
|
ld [wCurMap], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call PlayMapChangeSound
|
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wMapPalOffset], a
|
2014-05-31 01:30:25 +00:00
|
|
|
.done
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd736
|
|
|
|
set 0, [hl] ; have the player's sprite step out from the door (if there is one)
|
2014-09-14 18:29:18 +00:00
|
|
|
call IgnoreInputForHalfSecond
|
2014-05-31 01:30:25 +00:00
|
|
|
jp EnterMap
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ContinueCheckWarpsNoCollisionLoop::
|
2014-05-31 01:30:25 +00:00
|
|
|
inc b ; increment warp number
|
|
|
|
dec c ; decrement number of warps
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, CheckWarpsNoCollisionLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
|
|
|
|
; if no matching warp was found
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckMapConnections::
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkWestMap
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wXCoord]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .checkEastMap
|
|
|
|
ld a, [wMapConn3Ptr]
|
|
|
|
ld [wCurMap], a
|
|
|
|
ld a, [wWestConnectedMapXAlignment] ; new X coordinate upon entering west map
|
|
|
|
ld [wXCoord], a
|
|
|
|
ld a, [wYCoord]
|
|
|
|
ld c, a
|
|
|
|
ld a, [wWestConnectedMapYAlignment] ; Y adjustment upon entering west map
|
2014-05-31 01:30:25 +00:00
|
|
|
add c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld [wYCoord], a
|
|
|
|
ld a, [wWestConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
|
|
|
|
ld l, a
|
|
|
|
ld a, [wWestConnectedMapViewPointer + 1]
|
|
|
|
ld h, a
|
2014-05-31 01:30:25 +00:00
|
|
|
srl c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .savePointer1
|
2014-05-31 01:30:25 +00:00
|
|
|
.pointerAdjustmentLoop1
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wWestConnectedMapWidth] ; width of connected map
|
2016-06-12 18:35:21 +00:00
|
|
|
add MAP_BORDER * 2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
ld b, 0
|
|
|
|
add hl, de
|
2014-05-31 01:30:25 +00:00
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .pointerAdjustmentLoop1
|
2014-05-31 01:30:25 +00:00
|
|
|
.savePointer1
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, l
|
|
|
|
ld [wCurrentTileBlockMapViewPointer], a ; pointer to upper left corner of current tile block map section
|
|
|
|
ld a, h
|
|
|
|
ld [wCurrentTileBlockMapViewPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jp .loadNewMap
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkEastMap
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
|
|
|
ld a, [wCurrentMapWidth2] ; map width
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .checkNorthMap
|
|
|
|
ld a, [wMapConn4Ptr]
|
|
|
|
ld [wCurMap], a
|
|
|
|
ld a, [wEastConnectedMapXAlignment] ; new X coordinate upon entering east map
|
|
|
|
ld [wXCoord], a
|
|
|
|
ld a, [wYCoord]
|
|
|
|
ld c, a
|
|
|
|
ld a, [wEastConnectedMapYAlignment] ; Y adjustment upon entering east map
|
2014-05-31 01:30:25 +00:00
|
|
|
add c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld [wYCoord], a
|
|
|
|
ld a, [wEastConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for Y position
|
|
|
|
ld l, a
|
|
|
|
ld a, [wEastConnectedMapViewPointer + 1]
|
|
|
|
ld h, a
|
2014-05-31 01:30:25 +00:00
|
|
|
srl c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .savePointer2
|
2014-05-31 01:30:25 +00:00
|
|
|
.pointerAdjustmentLoop2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wEastConnectedMapWidth]
|
2016-06-12 18:35:21 +00:00
|
|
|
add MAP_BORDER * 2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
ld b, 0
|
|
|
|
add hl, de
|
2014-05-31 01:30:25 +00:00
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .pointerAdjustmentLoop2
|
2014-05-31 01:30:25 +00:00
|
|
|
.savePointer2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, l
|
|
|
|
ld [wCurrentTileBlockMapViewPointer], a ; pointer to upper left corner of current tile block map section
|
|
|
|
ld a, h
|
|
|
|
ld [wCurrentTileBlockMapViewPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jp .loadNewMap
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkNorthMap
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wYCoord]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .checkSouthMap
|
|
|
|
ld a, [wMapConn1Ptr]
|
|
|
|
ld [wCurMap], a
|
|
|
|
ld a, [wNorthConnectedMapYAlignment] ; new Y coordinate upon entering north map
|
|
|
|
ld [wYCoord], a
|
|
|
|
ld a, [wXCoord]
|
|
|
|
ld c, a
|
|
|
|
ld a, [wNorthConnectedMapXAlignment] ; X adjustment upon entering north map
|
2014-05-31 01:30:25 +00:00
|
|
|
add c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld [wXCoord], a
|
|
|
|
ld a, [wNorthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
|
|
|
|
ld l, a
|
|
|
|
ld a, [wNorthConnectedMapViewPointer + 1]
|
|
|
|
ld h, a
|
|
|
|
ld b, 0
|
2014-05-31 01:30:25 +00:00
|
|
|
srl c
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, l
|
|
|
|
ld [wCurrentTileBlockMapViewPointer], a ; pointer to upper left corner of current tile block map section
|
|
|
|
ld a, h
|
|
|
|
ld [wCurrentTileBlockMapViewPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jp .loadNewMap
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkSouthMap
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
|
|
|
ld a, [wCurrentMapHeight2]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .didNotEnterConnectedMap
|
|
|
|
ld a, [wMapConn2Ptr]
|
|
|
|
ld [wCurMap], a
|
|
|
|
ld a, [wSouthConnectedMapYAlignment] ; new Y coordinate upon entering south map
|
|
|
|
ld [wYCoord], a
|
|
|
|
ld a, [wXCoord]
|
|
|
|
ld c, a
|
|
|
|
ld a, [wSouthConnectedMapXAlignment] ; X adjustment upon entering south map
|
2014-05-31 01:30:25 +00:00
|
|
|
add c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld [wXCoord], a
|
|
|
|
ld a, [wSouthConnectedMapViewPointer] ; pointer to upper left corner of map without adjustment for X position
|
|
|
|
ld l, a
|
|
|
|
ld a, [wSouthConnectedMapViewPointer + 1]
|
|
|
|
ld h, a
|
|
|
|
ld b, 0
|
2014-05-31 01:30:25 +00:00
|
|
|
srl c
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, l
|
|
|
|
ld [wCurrentTileBlockMapViewPointer], a ; pointer to upper left corner of current tile block map section
|
|
|
|
ld a, h
|
|
|
|
ld [wCurrentTileBlockMapViewPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
.loadNewMap ; load the connected map that was entered
|
|
|
|
call LoadMapHeader
|
2015-08-09 05:32:44 +00:00
|
|
|
call PlayDefaultMusicFadeOutCurrent
|
2015-08-12 09:16:56 +00:00
|
|
|
ld b, SET_PAL_OVERWORLD
|
|
|
|
call RunPaletteCommand
|
2014-05-31 01:30:25 +00:00
|
|
|
; Since the sprite set shouldn't change, this will just update VRAM slots at
|
|
|
|
; $C2XE without loading any tile patterns.
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall InitMapSprites
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadTileBlockMap
|
|
|
|
jp OverworldLoopLessDelay
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.didNotEnterConnectedMap
|
|
|
|
jp OverworldLoop
|
|
|
|
|
|
|
|
; function to play a sound when changing maps
|
2016-06-12 00:24:04 +00:00
|
|
|
PlayMapChangeSound::
|
2014-06-25 20:58:27 +00:00
|
|
|
aCoord 8, 8 ; upper left tile of the 4x4 square the player's sprite is standing on
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $0b ; door tile in tileset 0
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .didNotGoThroughDoor
|
|
|
|
ld a, SFX_GO_INSIDE
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .playSound
|
|
|
|
.didNotGoThroughDoor
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, SFX_GO_OUTSIDE
|
2014-05-31 01:30:25 +00:00
|
|
|
.playSound
|
|
|
|
call PlaySound
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapPalOffset]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
|
|
|
ret nz
|
2014-09-13 07:50:56 +00:00
|
|
|
jp GBFadeOutToBlack
|
2014-05-31 01:30:25 +00:00
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckIfInOutsideMap::
|
2014-05-31 01:30:25 +00:00
|
|
|
; If the player is in an outside map (a town or route), set the z flag
|
2015-08-31 02:38:41 +00:00
|
|
|
ld a, [wCurMapTileset]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a ; most towns/routes have tileset 0 (OVERWORLD)
|
|
|
|
ret z
|
|
|
|
cp PLATEAU ; Route 23 / Indigo Plateau
|
|
|
|
ret
|
|
|
|
|
|
|
|
; this function is an extra check that sometimes has to pass in order to warp, beyond just standing on a warp
|
|
|
|
; the "sometimes" qualification is necessary because of CheckWarpsNoCollision's behavior
|
|
|
|
; depending on the map, either "function 1" or "function 2" is used for the check
|
|
|
|
; "function 1" passes when the player is at the edge of the map and is facing towards the outside of the map
|
|
|
|
; "function 2" passes when the the tile in front of the player is among a certain set
|
|
|
|
; sets carry if the check passes, otherwise clears carry
|
2016-06-12 00:24:04 +00:00
|
|
|
ExtraWarpCheck::
|
2015-08-31 02:38:41 +00:00
|
|
|
ld a, [wCurMap]
|
2019-01-01 20:06:23 +00:00
|
|
|
cp SS_ANNE_3F
|
2014-05-31 01:30:25 +00:00
|
|
|
jr z, .useFunction1
|
2019-01-01 20:06:23 +00:00
|
|
|
cp ROCKET_HIDEOUT_B1F
|
2014-05-31 01:30:25 +00:00
|
|
|
jr z, .useFunction2
|
2019-01-01 20:06:23 +00:00
|
|
|
cp ROCKET_HIDEOUT_B2F
|
2014-05-31 01:30:25 +00:00
|
|
|
jr z, .useFunction2
|
2019-01-01 20:06:23 +00:00
|
|
|
cp ROCKET_HIDEOUT_B4F
|
2014-05-31 01:30:25 +00:00
|
|
|
jr z, .useFunction2
|
2019-01-01 20:06:23 +00:00
|
|
|
cp ROCK_TUNNEL_1F
|
2014-05-31 01:30:25 +00:00
|
|
|
jr z, .useFunction2
|
2015-08-31 02:38:41 +00:00
|
|
|
ld a, [wCurMapTileset]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a ; outside tileset (OVERWORLD)
|
|
|
|
jr z, .useFunction2
|
|
|
|
cp SHIP ; S.S. Anne tileset
|
|
|
|
jr z, .useFunction2
|
|
|
|
cp SHIP_PORT ; Vermilion Port tileset
|
|
|
|
jr z, .useFunction2
|
|
|
|
cp PLATEAU ; Indigo Plateau tileset
|
|
|
|
jr z, .useFunction2
|
|
|
|
.useFunction1
|
2014-09-13 07:50:56 +00:00
|
|
|
ld hl, IsPlayerFacingEdgeOfMap
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .doBankswitch
|
|
|
|
.useFunction2
|
2014-09-13 07:50:56 +00:00
|
|
|
ld hl, IsWarpTileInFrontOfPlayer
|
2014-05-31 01:30:25 +00:00
|
|
|
.doBankswitch
|
2014-09-13 07:50:56 +00:00
|
|
|
ld b, BANK(IsWarpTileInFrontOfPlayer)
|
2014-05-31 01:30:25 +00:00
|
|
|
jp Bankswitch
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
MapEntryAfterBattle::
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall IsPlayerStandingOnWarp ; for enabling warp testing after collisions
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapPalOffset]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, GBFadeInFromWhite
|
2014-05-31 01:30:25 +00:00
|
|
|
jp LoadGBPal
|
|
|
|
|
|
|
|
HandleBlackOut::
|
|
|
|
; For when all the player's pokemon faint.
|
|
|
|
; Does not print the "blacked out" message.
|
|
|
|
|
2014-09-13 07:50:56 +00:00
|
|
|
call GBFadeOutToBlack
|
2014-05-31 01:30:25 +00:00
|
|
|
ld a, $08
|
|
|
|
call StopMusic
|
|
|
|
ld hl, wd72e
|
|
|
|
res 5, [hl]
|
2020-07-04 02:11:35 +00:00
|
|
|
ld a, BANK(ResetStatusAndHalveMoneyOnBlackout) ; also BANK(SpecialWarpIn) and BANK(SpecialEnterMap)
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadedROMBank], a
|
2014-09-14 18:29:18 +00:00
|
|
|
ld [MBC1RomBank], a
|
2014-09-13 07:50:56 +00:00
|
|
|
call ResetStatusAndHalveMoneyOnBlackout
|
|
|
|
call SpecialWarpIn
|
2015-08-09 05:32:44 +00:00
|
|
|
call PlayDefaultMusicFadeOutCurrent
|
2014-09-13 07:50:56 +00:00
|
|
|
jp SpecialEnterMap
|
2014-05-31 01:30:25 +00:00
|
|
|
|
|
|
|
StopMusic::
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wAudioFadeOutControl], a
|
2020-07-03 20:37:47 +00:00
|
|
|
ld a, SFX_STOP_ALL_MUSIC
|
2015-08-09 05:32:44 +00:00
|
|
|
ld [wNewSoundID], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call PlaySound
|
|
|
|
.wait
|
2015-08-09 05:32:44 +00:00
|
|
|
ld a, [wAudioFadeOutControl]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
|
|
|
jr nz, .wait
|
|
|
|
jp StopAllSounds
|
|
|
|
|
2014-09-13 07:50:56 +00:00
|
|
|
HandleFlyWarpOrDungeonWarp::
|
2014-05-31 01:30:25 +00:00
|
|
|
call UpdateSprites
|
|
|
|
call Delay3
|
|
|
|
xor a
|
2014-08-09 05:39:13 +00:00
|
|
|
ld [wBattleResult], a
|
2014-09-13 07:50:56 +00:00
|
|
|
ld [wWalkBikeSurfState], a
|
2015-08-31 02:38:41 +00:00
|
|
|
ld [wIsInBattle], a
|
2014-09-13 07:50:56 +00:00
|
|
|
ld [wMapPalOffset], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ld hl, wd732
|
2014-09-13 07:50:56 +00:00
|
|
|
set 2, [hl] ; fly warp or dungeon warp
|
|
|
|
res 5, [hl] ; forced to ride bike
|
2014-06-16 20:03:05 +00:00
|
|
|
call LeaveMapAnim
|
2020-07-04 02:11:35 +00:00
|
|
|
ld a, BANK(SpecialWarpIn)
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadedROMBank], a
|
2015-07-03 19:37:53 +00:00
|
|
|
ld [MBC1RomBank], a
|
2014-09-13 07:50:56 +00:00
|
|
|
call SpecialWarpIn
|
|
|
|
jp SpecialEnterMap
|
2014-05-31 01:30:25 +00:00
|
|
|
|
2014-06-16 20:03:05 +00:00
|
|
|
LeaveMapAnim::
|
2020-07-07 01:18:22 +00:00
|
|
|
farjp _LeaveMapAnim
|
2014-05-31 01:30:25 +00:00
|
|
|
|
|
|
|
LoadPlayerSpriteGraphics::
|
|
|
|
; Load sprite graphics based on whether the player is standing, biking, or surfing.
|
|
|
|
|
|
|
|
; 0: standing
|
|
|
|
; 1: biking
|
|
|
|
; 2: surfing
|
|
|
|
|
2014-09-13 07:50:56 +00:00
|
|
|
ld a, [wWalkBikeSurfState]
|
2014-05-31 01:30:25 +00:00
|
|
|
dec a
|
|
|
|
jr z, .ridingBike
|
|
|
|
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hTilesetType]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
|
|
|
jr nz, .determineGraphics
|
|
|
|
jr .startWalking
|
|
|
|
|
|
|
|
.ridingBike
|
|
|
|
; If the bike can't be used,
|
|
|
|
; start walking instead.
|
|
|
|
call IsBikeRidingAllowed
|
|
|
|
jr c, .determineGraphics
|
|
|
|
|
|
|
|
.startWalking
|
|
|
|
xor a
|
2014-09-13 07:50:56 +00:00
|
|
|
ld [wWalkBikeSurfState], a
|
|
|
|
ld [wWalkBikeSurfStateCopy], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jp LoadWalkingPlayerSpriteGraphics
|
|
|
|
|
|
|
|
.determineGraphics
|
2014-09-13 07:50:56 +00:00
|
|
|
ld a, [wWalkBikeSurfState]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
|
|
|
jp z, LoadWalkingPlayerSpriteGraphics
|
|
|
|
dec a
|
|
|
|
jp z, LoadBikePlayerSpriteGraphics
|
|
|
|
dec a
|
|
|
|
jp z, LoadSurfingPlayerSpriteGraphics
|
|
|
|
jp LoadWalkingPlayerSpriteGraphics
|
|
|
|
|
|
|
|
IsBikeRidingAllowed::
|
|
|
|
; The bike can be used on Route 23 and Indigo Plateau,
|
|
|
|
; or maps with tilesets in BikeRidingTilesets.
|
|
|
|
; Return carry if biking is allowed.
|
|
|
|
|
2015-08-31 02:38:41 +00:00
|
|
|
ld a, [wCurMap]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp ROUTE_23
|
|
|
|
jr z, .allowed
|
|
|
|
cp INDIGO_PLATEAU
|
|
|
|
jr z, .allowed
|
|
|
|
|
2015-08-31 02:38:41 +00:00
|
|
|
ld a, [wCurMapTileset]
|
2014-05-31 01:30:25 +00:00
|
|
|
ld b, a
|
|
|
|
ld hl, BikeRidingTilesets
|
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
|
|
|
cp b
|
|
|
|
jr z, .allowed
|
|
|
|
inc a
|
|
|
|
jr nz, .loop
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.allowed
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2020-07-03 15:51:00 +00:00
|
|
|
INCLUDE "data/tilesets/bike_riding_tilesets.asm"
|
2014-05-31 01:30:25 +00:00
|
|
|
|
|
|
|
; load the tile pattern data of the current tileset into VRAM
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadTilesetTilePatternData::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wTilesetGfxPtr]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wTilesetGfxPtr + 1]
|
|
|
|
ld h, a
|
|
|
|
ld de, vTileset
|
|
|
|
ld bc, $600
|
|
|
|
ld a, [wTilesetBank]
|
2014-05-31 01:30:25 +00:00
|
|
|
jp FarCopyData2
|
|
|
|
|
|
|
|
; this loads the current maps complete tile map (which references blocks, not individual tiles) to C6E8
|
|
|
|
; it can also load partial tile maps of connected maps into a border of length 3 around the current map
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadTileBlockMap::
|
2014-05-31 01:30:25 +00:00
|
|
|
; fill C6E8-CBFB with the background tile
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wOverworldMap
|
|
|
|
ld a, [wMapBackgroundTile]
|
|
|
|
ld d, a
|
2019-07-07 04:44:21 +00:00
|
|
|
ld bc, wOverworldMapEnd - wOverworldMap
|
2014-05-31 01:30:25 +00:00
|
|
|
.backgroundTileLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, d
|
|
|
|
ld [hli], a
|
2014-05-31 01:30:25 +00:00
|
|
|
dec bc
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, c
|
2014-05-31 01:30:25 +00:00
|
|
|
or b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .backgroundTileLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
; load tile map of current map (made of tile block IDs)
|
|
|
|
; a 3-byte border at the edges of the map is kept so that there is space for map connections
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wOverworldMap
|
|
|
|
ld a, [wCurMapWidth]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hMapWidth], a
|
2016-06-12 18:35:21 +00:00
|
|
|
add MAP_BORDER * 2 ; east and west
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hMapStride], a ; map width + border
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, 0
|
|
|
|
ld c, a
|
2014-05-31 01:30:25 +00:00
|
|
|
; make space for north border (next 3 lines)
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
|
|
|
add hl, bc
|
|
|
|
add hl, bc
|
|
|
|
ld c, MAP_BORDER
|
|
|
|
add hl, bc ; this puts us past the (west) border
|
|
|
|
ld a, [wMapDataPtr] ; tile map pointer
|
|
|
|
ld e, a
|
|
|
|
ld a, [wMapDataPtr + 1]
|
|
|
|
ld d, a ; de = tile map pointer
|
|
|
|
ld a, [wCurMapHeight]
|
|
|
|
ld b, a
|
2014-05-31 01:30:25 +00:00
|
|
|
.rowLoop ; copy one row each iteration
|
|
|
|
push hl
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hMapWidth] ; map width (without border)
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
2014-05-31 01:30:25 +00:00
|
|
|
.rowInnerLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hli], a
|
2014-05-31 01:30:25 +00:00
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .rowInnerLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
; add the map width plus the border to the base address of the current row to get the next row's address
|
|
|
|
pop hl
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hMapStride] ; map width + border
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .rowLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.northConnection
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapConn1Ptr]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .southConnection
|
2014-05-31 01:30:25 +00:00
|
|
|
call SwitchToMapRomBank
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNorthConnectionStripSrc]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wNorthConnectionStripSrc + 1]
|
|
|
|
ld h, a
|
|
|
|
ld a, [wNorthConnectionStripDest]
|
|
|
|
ld e, a
|
|
|
|
ld a, [wNorthConnectionStripDest + 1]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wNorthConnectionStripWidth]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hNorthSouthConnectionStripWidth], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNorthConnectedMapWidth]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hNorthSouthConnectedMapWidth], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadNorthSouthConnectionsTileMap
|
|
|
|
.southConnection
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapConn2Ptr]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .westConnection
|
2014-05-31 01:30:25 +00:00
|
|
|
call SwitchToMapRomBank
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wSouthConnectionStripSrc]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wSouthConnectionStripSrc + 1]
|
|
|
|
ld h, a
|
|
|
|
ld a, [wSouthConnectionStripDest]
|
|
|
|
ld e, a
|
|
|
|
ld a, [wSouthConnectionStripDest + 1]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wSouthConnectionStripWidth]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hNorthSouthConnectionStripWidth], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wSouthConnectedMapWidth]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hNorthSouthConnectedMapWidth], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadNorthSouthConnectionsTileMap
|
|
|
|
.westConnection
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapConn3Ptr]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .eastConnection
|
2014-05-31 01:30:25 +00:00
|
|
|
call SwitchToMapRomBank
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wWestConnectionStripSrc]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wWestConnectionStripSrc + 1]
|
|
|
|
ld h, a
|
|
|
|
ld a, [wWestConnectionStripDest]
|
|
|
|
ld e, a
|
|
|
|
ld a, [wWestConnectionStripDest + 1]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wWestConnectionStripHeight]
|
|
|
|
ld b, a
|
|
|
|
ld a, [wWestConnectedMapWidth]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hEastWestConnectedMapWidth], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadEastWestConnectionsTileMap
|
|
|
|
.eastConnection
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapConn4Ptr]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .done
|
2014-05-31 01:30:25 +00:00
|
|
|
call SwitchToMapRomBank
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wEastConnectionStripSrc]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wEastConnectionStripSrc + 1]
|
|
|
|
ld h, a
|
|
|
|
ld a, [wEastConnectionStripDest]
|
|
|
|
ld e, a
|
|
|
|
ld a, [wEastConnectionStripDest + 1]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wEastConnectionStripHeight]
|
|
|
|
ld b, a
|
|
|
|
ld a, [wEastConnectedMapWidth]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hEastWestConnectedMapWidth], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadEastWestConnectionsTileMap
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadNorthSouthConnectionsTileMap::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, MAP_BORDER
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop
|
|
|
|
push de
|
|
|
|
push hl
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hNorthSouthConnectionStripWidth]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
2014-05-31 01:30:25 +00:00
|
|
|
.innerLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .innerLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
|
|
|
pop de
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hNorthSouthConnectedMapWidth]
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry1
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry1
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMapWidth]
|
2016-06-12 18:35:21 +00:00
|
|
|
add MAP_BORDER * 2
|
2014-05-31 01:30:25 +00:00
|
|
|
add e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
jr nc, .noCarry2
|
2014-05-31 01:30:25 +00:00
|
|
|
inc d
|
|
|
|
.noCarry2
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .loop
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadEastWestConnectionsTileMap::
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
|
|
|
push de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, MAP_BORDER
|
2014-05-31 01:30:25 +00:00
|
|
|
.innerLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .innerLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
pop de
|
|
|
|
pop hl
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hEastWestConnectedMapWidth]
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry1
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry1
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMapWidth]
|
2016-06-12 18:35:21 +00:00
|
|
|
add MAP_BORDER * 2
|
2014-05-31 01:30:25 +00:00
|
|
|
add e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
jr nc, .noCarry2
|
2014-05-31 01:30:25 +00:00
|
|
|
inc d
|
|
|
|
.noCarry2
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, LoadEastWestConnectionsTileMap
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to check if there is a sign or sprite in front of the player
|
2014-09-14 18:29:18 +00:00
|
|
|
; if so, it is stored in [hSpriteIndexOrTextID]
|
|
|
|
; if not, [hSpriteIndexOrTextID] is set to 0
|
2016-06-12 00:24:04 +00:00
|
|
|
IsSpriteOrSignInFrontOfPlayer::
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSpriteIndexOrTextID], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNumSigns]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .extendRangeOverCounter
|
2014-05-31 01:30:25 +00:00
|
|
|
; if there are signs
|
2014-09-13 07:50:56 +00:00
|
|
|
predef GetTileAndCoordsInFrontOfPlayer ; get the coordinates in front of the player in de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wSignCoords
|
|
|
|
ld a, [wNumSigns]
|
|
|
|
ld b, a
|
|
|
|
ld c, 0
|
2014-05-31 01:30:25 +00:00
|
|
|
.signLoop
|
|
|
|
inc c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; sign Y
|
2014-05-31 01:30:25 +00:00
|
|
|
cp d
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .yCoordMatched
|
2014-05-31 01:30:25 +00:00
|
|
|
inc hl
|
|
|
|
jr .retry
|
|
|
|
.yCoordMatched
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; sign X
|
2014-05-31 01:30:25 +00:00
|
|
|
cp e
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .retry
|
2014-05-31 01:30:25 +00:00
|
|
|
.xCoordMatched
|
|
|
|
; found sign
|
|
|
|
push hl
|
|
|
|
push bc
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wSignTextIDs
|
|
|
|
ld b, 0
|
2014-05-31 01:30:25 +00:00
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSpriteIndexOrTextID], a ; store sign text ID
|
2014-05-31 01:30:25 +00:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
.retry
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .signLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
; check if the player is front of a counter in a pokemon center, pokemart, etc. and if so, extend the range at which he can talk to the NPC
|
|
|
|
.extendRangeOverCounter
|
2014-09-13 07:50:56 +00:00
|
|
|
predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player in c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wTilesetTalkingOverTiles ; list of tiles that extend talking range (counter tiles)
|
|
|
|
ld b, 3
|
|
|
|
ld d, $20 ; talking range in pixels (long range)
|
2014-05-31 01:30:25 +00:00
|
|
|
.counterTilesLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, IsSpriteInFrontOfPlayer2 ; jumps if the tile in front of the player is a counter tile
|
2014-05-31 01:30:25 +00:00
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .counterTilesLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
|
|
|
|
; part of the above function, but sometimes its called on its own, when signs are irrelevant
|
2014-09-14 18:29:18 +00:00
|
|
|
; the caller must zero [hSpriteIndexOrTextID]
|
2016-06-12 00:24:04 +00:00
|
|
|
IsSpriteInFrontOfPlayer::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld d, $10 ; talking range in pixels (normal range)
|
2016-06-12 00:24:04 +00:00
|
|
|
IsSpriteInFrontOfPlayer2::
|
2015-07-20 00:52:26 +00:00
|
|
|
lb bc, $3c, $40 ; Y and X position of player sprite
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1FacingDirection]
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfPlayerFacingUp
|
2015-07-04 05:44:12 +00:00
|
|
|
cp SPRITE_FACING_UP
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .checkIfPlayerFacingDown
|
2014-05-31 01:30:25 +00:00
|
|
|
; facing up
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, b
|
2014-05-31 01:30:25 +00:00
|
|
|
sub d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
|
|
|
ld a, PLAYER_DIR_UP
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .doneCheckingDirection
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfPlayerFacingDown
|
2015-07-04 05:44:12 +00:00
|
|
|
cp SPRITE_FACING_DOWN
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .checkIfPlayerFacingRight
|
2014-05-31 01:30:25 +00:00
|
|
|
; facing down
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, b
|
2014-05-31 01:30:25 +00:00
|
|
|
add d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
|
|
|
ld a, PLAYER_DIR_DOWN
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .doneCheckingDirection
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkIfPlayerFacingRight
|
2015-07-04 05:44:12 +00:00
|
|
|
cp SPRITE_FACING_RIGHT
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .playerFacingLeft
|
2014-05-31 01:30:25 +00:00
|
|
|
; facing right
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, c
|
2014-05-31 01:30:25 +00:00
|
|
|
add d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld a, PLAYER_DIR_RIGHT
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .doneCheckingDirection
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
.playerFacingLeft
|
|
|
|
; facing left
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, c
|
2014-05-31 01:30:25 +00:00
|
|
|
sub d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld a, PLAYER_DIR_LEFT
|
2014-05-31 01:30:25 +00:00
|
|
|
.doneCheckingDirection
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wPlayerDirection], a
|
|
|
|
ld a, [wNumSprites] ; number of sprites
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
; if there are sprites
|
2020-07-05 21:29:11 +00:00
|
|
|
ld hl, wSprite01StateData1
|
2017-12-30 00:54:27 +00:00
|
|
|
ld d, a
|
|
|
|
ld e, $01
|
2014-05-31 01:30:25 +00:00
|
|
|
.spriteLoop
|
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; image (0 if no sprite)
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .nextSprite
|
2014-05-31 01:30:25 +00:00
|
|
|
inc l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; sprite visibility
|
2014-05-31 01:30:25 +00:00
|
|
|
inc a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .nextSprite
|
2014-05-31 01:30:25 +00:00
|
|
|
inc l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; Y location
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .nextSprite
|
2014-05-31 01:30:25 +00:00
|
|
|
inc l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl] ; X location
|
2014-05-31 01:30:25 +00:00
|
|
|
cp c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .foundSpriteInFrontOfPlayer
|
2014-05-31 01:30:25 +00:00
|
|
|
.nextSprite
|
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, l
|
|
|
|
add $10
|
|
|
|
ld l, a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc e
|
|
|
|
dec d
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .spriteLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
.foundSpriteInFrontOfPlayer
|
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, l
|
|
|
|
and $f0
|
2014-05-31 01:30:25 +00:00
|
|
|
inc a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a ; hl = $c1x1
|
|
|
|
set 7, [hl] ; set flag to make the sprite face the player
|
|
|
|
ld a, e
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSpriteIndexOrTextID], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to check if the player will jump down a ledge and check if the tile ahead is passable (when not surfing)
|
|
|
|
; sets the carry flag if there is a collision, and unsets it if there isn't a collision
|
2016-06-12 00:24:04 +00:00
|
|
|
CollisionCheckOnLand::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd736]
|
|
|
|
bit 6, a ; is the player jumping?
|
|
|
|
jr nz, .noCollision
|
2014-05-31 01:30:25 +00:00
|
|
|
; if not jumping a ledge
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wSimulatedJoypadStatesIndex]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .noCollision ; no collisions when the player's movements are being controlled by the game
|
|
|
|
ld a, [wPlayerDirection] ; the direction that the player is trying to go in
|
|
|
|
ld d, a
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1CollisionData]
|
2014-05-31 01:30:25 +00:00
|
|
|
and d ; check if a sprite is in the direction the player is trying to go
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .collision
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSpriteIndexOrTextID], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call IsSpriteInFrontOfPlayer ; check for sprite collisions again? when does the above check fail to detect a sprite collision?
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hSpriteIndexOrTextID]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a ; was there a sprite collision?
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .collision
|
2014-05-31 01:30:25 +00:00
|
|
|
; if no sprite collision
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, TilePairCollisionsLand
|
2014-05-31 01:30:25 +00:00
|
|
|
call CheckForJumpingAndTilePairCollisions
|
2017-12-30 00:54:27 +00:00
|
|
|
jr c, .collision
|
2014-05-31 01:30:25 +00:00
|
|
|
call CheckTilePassable
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nc, .noCollision
|
2014-05-31 01:30:25 +00:00
|
|
|
.collision
|
2019-07-28 04:21:39 +00:00
|
|
|
ld a, [wChannelSoundIDs + Ch5]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp SFX_COLLISION ; check if collision sound is already playing
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .setCarry
|
|
|
|
ld a, SFX_COLLISION
|
2014-05-31 01:30:25 +00:00
|
|
|
call PlaySound ; play collision sound (if it's not already playing)
|
|
|
|
.setCarry
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
.noCollision
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
; function that checks if the tile in front of the player is passable
|
|
|
|
; clears carry if it is, sets carry if not
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckTilePassable::
|
2014-09-13 07:50:56 +00:00
|
|
|
predef GetTileAndCoordsInFrontOfPlayer ; get tile in front of player
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wTileInFrontOfPlayer] ; tile in front of player
|
|
|
|
ld c, a
|
|
|
|
ld hl, wTilesetCollisionPtr ; pointer to list of passable tiles
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a ; hl now points to passable tiles
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
cp $ff
|
|
|
|
jr z, .tileNotPassable
|
2014-05-31 01:30:25 +00:00
|
|
|
cp c
|
|
|
|
ret z
|
|
|
|
jr .loop
|
|
|
|
.tileNotPassable
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
; check if the player is going to jump down a small ledge
|
|
|
|
; and check for collisions that only occur between certain pairs of tiles
|
|
|
|
; Input: hl - address of directional collision data
|
|
|
|
; sets carry if there is a collision and unsets carry if not
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckForJumpingAndTilePairCollisions::
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
2014-09-13 07:50:56 +00:00
|
|
|
predef GetTileAndCoordsInFrontOfPlayer ; get the tile in front of the player
|
2014-05-31 01:30:25 +00:00
|
|
|
push de
|
|
|
|
push bc
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall HandleLedges ; check if the player is trying to jump a ledge
|
2014-05-31 01:30:25 +00:00
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd736]
|
|
|
|
bit 6, a ; is the player jumping?
|
2014-05-31 01:30:25 +00:00
|
|
|
ret nz
|
|
|
|
; if not jumping
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckForTilePairCollisions2::
|
2014-06-25 20:58:27 +00:00
|
|
|
aCoord 8, 9 ; tile the player is on
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wTilePlayerStandingOn], a
|
2014-05-31 01:30:25 +00:00
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
CheckForTilePairCollisions::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wTileInFrontOfPlayer]
|
|
|
|
ld c, a
|
2014-05-31 01:30:25 +00:00
|
|
|
.tilePairCollisionLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMapTileset] ; tileset number
|
|
|
|
ld b, a
|
|
|
|
ld a, [hli]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp $ff
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .noMatch
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .tilesetMatches
|
2014-05-31 01:30:25 +00:00
|
|
|
inc hl
|
|
|
|
.retry
|
|
|
|
inc hl
|
|
|
|
jr .tilePairCollisionLoop
|
|
|
|
.tilesetMatches
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wTilePlayerStandingOn] ; tile the player is on
|
|
|
|
ld b, a
|
|
|
|
ld a, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .currentTileMatchesFirstInPair
|
2014-05-31 01:30:25 +00:00
|
|
|
inc hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .currentTileMatchesSecondInPair
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .retry
|
|
|
|
.currentTileMatchesFirstInPair
|
|
|
|
inc hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .foundMatch
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .tilePairCollisionLoop
|
|
|
|
.currentTileMatchesSecondInPair
|
|
|
|
dec hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
2014-05-31 01:30:25 +00:00
|
|
|
cp c
|
|
|
|
inc hl
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .tilePairCollisionLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.foundMatch
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
.noMatch
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
; FORMAT: tileset number, tile 1, tile 2
|
|
|
|
; terminated by 0xFF
|
|
|
|
; these entries indicate that the player may not cross between tile 1 and tile 2
|
|
|
|
; it's mainly used to simulate differences in elevation
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
TilePairCollisionsLand::
|
2014-05-31 01:30:25 +00:00
|
|
|
db CAVERN, $20, $05
|
|
|
|
db CAVERN, $41, $05
|
|
|
|
db FOREST, $30, $2E
|
|
|
|
db CAVERN, $2A, $05
|
|
|
|
db CAVERN, $05, $21
|
|
|
|
db FOREST, $52, $2E
|
|
|
|
db FOREST, $55, $2E
|
|
|
|
db FOREST, $56, $2E
|
|
|
|
db FOREST, $20, $2E
|
|
|
|
db FOREST, $5E, $2E
|
|
|
|
db FOREST, $5F, $2E
|
|
|
|
db $FF
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
TilePairCollisionsWater::
|
2014-05-31 01:30:25 +00:00
|
|
|
db FOREST, $14, $2E
|
|
|
|
db FOREST, $48, $2E
|
|
|
|
db CAVERN, $14, $05
|
|
|
|
db $FF
|
|
|
|
|
|
|
|
; this builds a tile map from the tile block map based on the current X/Y coordinates of the player's character
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadCurrentMapView::
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadedROMBank]
|
2014-05-31 01:30:25 +00:00
|
|
|
push af
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wTilesetBank] ; tile data ROM bank
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadedROMBank], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [MBC1RomBank], a ; switch to ROM bank that contains tile data
|
|
|
|
ld a, [wCurrentTileBlockMapViewPointer] ; address of upper left corner of current map view
|
|
|
|
ld e, a
|
|
|
|
ld a, [wCurrentTileBlockMapViewPointer + 1]
|
|
|
|
ld d, a
|
|
|
|
ld hl, wTileMapBackup
|
|
|
|
ld b, $05
|
2014-05-31 01:30:25 +00:00
|
|
|
.rowLoop ; each loop iteration fills in one row of tile blocks
|
|
|
|
push hl
|
|
|
|
push de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, $06
|
2014-05-31 01:30:25 +00:00
|
|
|
.rowInnerLoop ; loop to draw each tile block of the current row
|
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
|
|
|
ld c, a ; tile block number
|
2014-05-31 01:30:25 +00:00
|
|
|
call DrawTileBlock
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .rowInnerLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
; update tile block map pointer to next row's address
|
|
|
|
pop de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMapWidth]
|
2016-06-12 18:35:21 +00:00
|
|
|
add MAP_BORDER * 2
|
2014-05-31 01:30:25 +00:00
|
|
|
add e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
jr nc, .noCarry
|
2014-05-31 01:30:25 +00:00
|
|
|
inc d
|
|
|
|
.noCarry
|
|
|
|
; update tile map pointer to next row's address
|
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $60
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry2
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry2
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .rowLoop
|
|
|
|
ld hl, wTileMapBackup
|
2020-07-04 05:00:45 +00:00
|
|
|
ld bc, $0
|
2014-05-31 01:30:25 +00:00
|
|
|
.adjustForYCoordWithinTileBlock
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wYBlockCoord]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .adjustForXCoordWithinTileBlock
|
2020-07-04 05:00:45 +00:00
|
|
|
ld bc, $30
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
2014-05-31 01:30:25 +00:00
|
|
|
.adjustForXCoordWithinTileBlock
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wXBlockCoord]
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .copyToVisibleAreaBuffer
|
2020-07-04 05:00:45 +00:00
|
|
|
ld bc, $2
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
2014-05-31 01:30:25 +00:00
|
|
|
.copyToVisibleAreaBuffer
|
2015-08-14 09:46:12 +00:00
|
|
|
coord de, 0, 0 ; base address for the tiles that are directly transferred to VRAM during V-blank
|
2015-07-14 05:21:03 +00:00
|
|
|
ld b, SCREEN_HEIGHT
|
2014-05-31 01:30:25 +00:00
|
|
|
.rowLoop2
|
2015-07-14 05:21:03 +00:00
|
|
|
ld c, SCREEN_WIDTH
|
2014-05-31 01:30:25 +00:00
|
|
|
.rowInnerLoop2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .rowInnerLoop2
|
|
|
|
ld a, $04
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry3
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry3
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .rowLoop2
|
2014-05-31 01:30:25 +00:00
|
|
|
pop af
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadedROMBank], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [MBC1RomBank], a ; restore previous ROM bank
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
AdvancePlayerSprite::
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1YStepVector]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1XStepVector]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld hl, wWalkCounter ; walking animation counter
|
2014-05-31 01:30:25 +00:00
|
|
|
dec [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .afterUpdateMapCoords
|
2014-05-31 01:30:25 +00:00
|
|
|
; if it's the end of the animation, update the player's map coordinates
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wYCoord]
|
2014-05-31 01:30:25 +00:00
|
|
|
add b
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wYCoord], a
|
|
|
|
ld a, [wXCoord]
|
2014-05-31 01:30:25 +00:00
|
|
|
add c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wXCoord], a
|
2014-05-31 01:30:25 +00:00
|
|
|
.afterUpdateMapCoords
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wWalkCounter] ; walking animation counter
|
|
|
|
cp $07
|
|
|
|
jp nz, .scrollBackgroundAndSprites
|
2014-05-31 01:30:25 +00:00
|
|
|
; if this is the first iteration of the animation
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, c
|
|
|
|
cp $01
|
|
|
|
jr nz, .checkIfMovingWest
|
2014-05-31 01:30:25 +00:00
|
|
|
; moving east
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
|
|
|
ld e, a
|
|
|
|
and $e0
|
|
|
|
ld d, a
|
|
|
|
ld a, e
|
|
|
|
add $02
|
|
|
|
and $1f
|
2014-05-31 01:30:25 +00:00
|
|
|
or d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wMapViewVRAMPointer], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .adjustXCoordWithinBlock
|
|
|
|
.checkIfMovingWest
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $ff
|
|
|
|
jr nz, .checkIfMovingSouth
|
2014-05-31 01:30:25 +00:00
|
|
|
; moving west
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
|
|
|
ld e, a
|
|
|
|
and $e0
|
|
|
|
ld d, a
|
|
|
|
ld a, e
|
|
|
|
sub $02
|
|
|
|
and $1f
|
2014-05-31 01:30:25 +00:00
|
|
|
or d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wMapViewVRAMPointer], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .adjustXCoordWithinBlock
|
|
|
|
.checkIfMovingSouth
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, b
|
|
|
|
cp $01
|
|
|
|
jr nz, .checkIfMovingNorth
|
2014-05-31 01:30:25 +00:00
|
|
|
; moving south
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
|
|
|
add $40
|
|
|
|
ld [wMapViewVRAMPointer], a
|
|
|
|
jr nc, .adjustXCoordWithinBlock
|
|
|
|
ld a, [wMapViewVRAMPointer + 1]
|
2014-05-31 01:30:25 +00:00
|
|
|
inc a
|
2017-12-30 00:54:27 +00:00
|
|
|
and $03
|
|
|
|
or $98
|
|
|
|
ld [wMapViewVRAMPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .adjustXCoordWithinBlock
|
|
|
|
.checkIfMovingNorth
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $ff
|
|
|
|
jr nz, .adjustXCoordWithinBlock
|
2014-05-31 01:30:25 +00:00
|
|
|
; moving north
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
|
|
|
sub $40
|
|
|
|
ld [wMapViewVRAMPointer], a
|
|
|
|
jr nc, .adjustXCoordWithinBlock
|
|
|
|
ld a, [wMapViewVRAMPointer + 1]
|
2014-05-31 01:30:25 +00:00
|
|
|
dec a
|
2017-12-30 00:54:27 +00:00
|
|
|
and $03
|
|
|
|
or $98
|
|
|
|
ld [wMapViewVRAMPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
.adjustXCoordWithinBlock
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, c
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .pointlessJump ; mistake?
|
2014-05-31 01:30:25 +00:00
|
|
|
.pointlessJump
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wXBlockCoord
|
|
|
|
ld a, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
add c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a
|
|
|
|
cp $02
|
|
|
|
jr nz, .checkForMoveToWestBlock
|
2014-05-31 01:30:25 +00:00
|
|
|
; moved into the tile block to the east
|
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a
|
|
|
|
ld hl, wXOffsetSinceLastSpecialWarp
|
2014-05-31 01:30:25 +00:00
|
|
|
inc [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wCurrentTileBlockMapViewPointer
|
2014-05-31 01:30:25 +00:00
|
|
|
call MoveTileBlockMapPointerEast
|
|
|
|
jr .updateMapView
|
|
|
|
.checkForMoveToWestBlock
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $ff
|
|
|
|
jr nz, .adjustYCoordWithinBlock
|
2014-05-31 01:30:25 +00:00
|
|
|
; moved into the tile block to the west
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $01
|
|
|
|
ld [hl], a
|
|
|
|
ld hl, wXOffsetSinceLastSpecialWarp
|
2014-05-31 01:30:25 +00:00
|
|
|
dec [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wCurrentTileBlockMapViewPointer
|
2014-05-31 01:30:25 +00:00
|
|
|
call MoveTileBlockMapPointerWest
|
|
|
|
jr .updateMapView
|
|
|
|
.adjustYCoordWithinBlock
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wYBlockCoord
|
|
|
|
ld a, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
add b
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a
|
|
|
|
cp $02
|
|
|
|
jr nz, .checkForMoveToNorthBlock
|
2014-05-31 01:30:25 +00:00
|
|
|
; moved into the tile block to the south
|
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a
|
|
|
|
ld hl, wYOffsetSinceLastSpecialWarp
|
2014-05-31 01:30:25 +00:00
|
|
|
inc [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wCurrentTileBlockMapViewPointer
|
|
|
|
ld a, [wCurMapWidth]
|
2014-05-31 01:30:25 +00:00
|
|
|
call MoveTileBlockMapPointerSouth
|
|
|
|
jr .updateMapView
|
|
|
|
.checkForMoveToNorthBlock
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $ff
|
|
|
|
jr nz, .updateMapView
|
2014-05-31 01:30:25 +00:00
|
|
|
; moved into the tile block to the north
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $01
|
|
|
|
ld [hl], a
|
|
|
|
ld hl, wYOffsetSinceLastSpecialWarp
|
2014-05-31 01:30:25 +00:00
|
|
|
dec [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wCurrentTileBlockMapViewPointer
|
|
|
|
ld a, [wCurMapWidth]
|
2014-05-31 01:30:25 +00:00
|
|
|
call MoveTileBlockMapPointerNorth
|
|
|
|
.updateMapView
|
|
|
|
call LoadCurrentMapView
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1YStepVector]
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $01
|
|
|
|
jr nz, .checkIfMovingNorth2
|
2014-05-31 01:30:25 +00:00
|
|
|
; if moving south
|
|
|
|
call ScheduleSouthRowRedraw
|
|
|
|
jr .scrollBackgroundAndSprites
|
|
|
|
.checkIfMovingNorth2
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $ff
|
|
|
|
jr nz, .checkIfMovingEast2
|
2014-05-31 01:30:25 +00:00
|
|
|
; if moving north
|
|
|
|
call ScheduleNorthRowRedraw
|
|
|
|
jr .scrollBackgroundAndSprites
|
|
|
|
.checkIfMovingEast2
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1XStepVector]
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $01
|
|
|
|
jr nz, .checkIfMovingWest2
|
2014-05-31 01:30:25 +00:00
|
|
|
; if moving east
|
|
|
|
call ScheduleEastColumnRedraw
|
|
|
|
jr .scrollBackgroundAndSprites
|
|
|
|
.checkIfMovingWest2
|
2017-12-30 00:54:27 +00:00
|
|
|
cp $ff
|
|
|
|
jr nz, .scrollBackgroundAndSprites
|
2014-05-31 01:30:25 +00:00
|
|
|
; if moving west
|
|
|
|
call ScheduleWestColumnRedraw
|
|
|
|
.scrollBackgroundAndSprites
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1YStepVector]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1XStepVector]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
2014-05-31 01:30:25 +00:00
|
|
|
sla b
|
|
|
|
sla c
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hSCY]
|
2014-05-31 01:30:25 +00:00
|
|
|
add b
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSCY], a ; update background scroll Y
|
|
|
|
ldh a, [hSCX]
|
2014-05-31 01:30:25 +00:00
|
|
|
add c
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSCX], a ; update background scroll X
|
2014-05-31 01:30:25 +00:00
|
|
|
; shift all the sprites in the direction opposite of the player's motion
|
|
|
|
; so that the player appears to move relative to them
|
2020-07-05 21:29:11 +00:00
|
|
|
ld hl, wSprite01StateData1YPixels
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNumSprites] ; number of sprites
|
2014-05-31 01:30:25 +00:00
|
|
|
and a ; are there any sprites?
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .done
|
|
|
|
ld e, a
|
2014-05-31 01:30:25 +00:00
|
|
|
.spriteShiftLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
sub b
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hli], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
sub c
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a
|
|
|
|
ld a, $0e
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
2014-05-31 01:30:25 +00:00
|
|
|
dec e
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .spriteShiftLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.done
|
|
|
|
ret
|
|
|
|
|
|
|
|
; the following four functions are used to move the pointer to the upper left
|
|
|
|
; corner of the tile block map in the direction of motion
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
MoveTileBlockMapPointerEast::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
|
|
|
add $01
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret nc
|
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
2014-05-31 01:30:25 +00:00
|
|
|
inc a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
MoveTileBlockMapPointerWest::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
|
|
|
sub $01
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret nc
|
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
2014-05-31 01:30:25 +00:00
|
|
|
dec a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
MoveTileBlockMapPointerSouth::
|
2017-12-30 00:54:27 +00:00
|
|
|
add MAP_BORDER * 2
|
|
|
|
ld b, a
|
|
|
|
ld a, [de]
|
2014-05-31 01:30:25 +00:00
|
|
|
add b
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret nc
|
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
2014-05-31 01:30:25 +00:00
|
|
|
inc a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
MoveTileBlockMapPointerNorth::
|
2017-12-30 00:54:27 +00:00
|
|
|
add MAP_BORDER * 2
|
|
|
|
ld b, a
|
|
|
|
ld a, [de]
|
2014-05-31 01:30:25 +00:00
|
|
|
sub b
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret nc
|
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
2014-05-31 01:30:25 +00:00
|
|
|
dec a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; the following 6 functions are used to tell the V-blank handler to redraw
|
|
|
|
; the portion of the map that was newly exposed due to the player's movement
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ScheduleNorthRowRedraw::
|
2015-07-18 20:52:03 +00:00
|
|
|
coord hl, 0, 0
|
2015-08-14 09:46:12 +00:00
|
|
|
call CopyToRedrawRowOrColumnSrcTiles
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer + 1]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest + 1], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, REDRAW_ROW
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnMode], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
CopyToRedrawRowOrColumnSrcTiles::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wRedrawRowOrColumnSrcTiles
|
|
|
|
ld c, 2 * SCREEN_WIDTH
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .loop
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ScheduleSouthRowRedraw::
|
2015-07-18 20:52:03 +00:00
|
|
|
coord hl, 0, 16
|
2015-08-14 09:46:12 +00:00
|
|
|
call CopyToRedrawRowOrColumnSrcTiles
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wMapViewVRAMPointer + 1]
|
|
|
|
ld h, a
|
2020-07-04 05:00:45 +00:00
|
|
|
ld bc, $200
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, h
|
2016-06-12 18:35:21 +00:00
|
|
|
and $03
|
|
|
|
or $98
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest + 1], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, l
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, REDRAW_ROW
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnMode], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ScheduleEastColumnRedraw::
|
2015-07-18 20:52:03 +00:00
|
|
|
coord hl, 18, 0
|
2014-05-31 01:30:25 +00:00
|
|
|
call ScheduleColumnRedrawHelper
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
|
|
|
ld c, a
|
2016-06-12 18:35:21 +00:00
|
|
|
and $e0
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
|
|
|
ld a, c
|
2016-06-12 18:35:21 +00:00
|
|
|
add 18
|
|
|
|
and $1f
|
2014-05-31 01:30:25 +00:00
|
|
|
or b
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer + 1]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest + 1], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, REDRAW_COL
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnMode], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ScheduleColumnRedrawHelper::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wRedrawRowOrColumnSrcTiles
|
|
|
|
ld c, SCREEN_HEIGHT
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, 19
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .loop
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ScheduleWestColumnRedraw::
|
2015-07-18 20:52:03 +00:00
|
|
|
coord hl, 0, 0
|
2014-05-31 01:30:25 +00:00
|
|
|
call ScheduleColumnRedrawHelper
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapViewVRAMPointer + 1]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnDest + 1], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, REDRAW_COL
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hRedrawRowOrColumnMode], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to write the tiles that make up a tile block to memory
|
|
|
|
; Input: c = tile block ID, hl = destination address
|
2016-06-12 00:24:04 +00:00
|
|
|
DrawTileBlock::
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wTilesetBlocksPtr] ; pointer to tiles
|
|
|
|
ld l, a
|
|
|
|
ld a, [wTilesetBlocksPtr + 1]
|
|
|
|
ld h, a
|
|
|
|
ld a, c
|
2014-05-31 01:30:25 +00:00
|
|
|
swap a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
2016-06-12 18:35:21 +00:00
|
|
|
and $f0
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld a, b
|
2016-06-12 18:35:21 +00:00
|
|
|
and $0f
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a ; bc = tile block ID * 0x10
|
|
|
|
add hl, bc
|
|
|
|
ld d, h
|
|
|
|
ld e, l ; de = address of the tile block's tiles
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, $04 ; 4 loop iterations
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop ; each loop iteration, write 4 tile numbers
|
|
|
|
push bc
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
|
|
|
ld [hli], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [de]
|
|
|
|
ld [hl], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2020-07-04 05:00:45 +00:00
|
|
|
ld bc, $15
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
2014-05-31 01:30:25 +00:00
|
|
|
pop bc
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .loop
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to update joypad state and simulate button presses
|
2016-06-12 00:24:04 +00:00
|
|
|
JoypadOverworld::
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2020-07-05 21:29:11 +00:00
|
|
|
ld [wSpritePlayerStateData1YStepVector], a
|
|
|
|
ld [wSpritePlayerStateData1XStepVector], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call RunMapScript
|
|
|
|
call Joypad
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wFlags_D733]
|
|
|
|
bit 3, a ; check if a trainer wants a challenge
|
|
|
|
jr nz, .notForcedDownwards
|
|
|
|
ld a, [wCurMap]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp ROUTE_17 ; Cycling Road
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .notForcedDownwards
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hJoyHeld]
|
2016-06-12 18:35:21 +00:00
|
|
|
and D_DOWN | D_UP | D_LEFT | D_RIGHT | B_BUTTON | A_BUTTON
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .notForcedDownwards
|
|
|
|
ld a, D_DOWN
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hJoyHeld], a ; on the cycling road, if there isn't a trainer and the player isn't pressing buttons, simulate a down press
|
2014-05-31 01:30:25 +00:00
|
|
|
.notForcedDownwards
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd730]
|
|
|
|
bit 7, a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret z
|
|
|
|
; if simulating button presses
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hJoyHeld]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, a
|
|
|
|
ld a, [wOverrideSimulatedJoypadStatesMask] ; bit mask for button presses that override simulated ones
|
2014-05-31 01:30:25 +00:00
|
|
|
and b
|
|
|
|
ret nz ; return if the simulated button presses are overridden
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wSimulatedJoypadStatesIndex
|
2014-05-31 01:30:25 +00:00
|
|
|
dec [hl]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl]
|
|
|
|
cp $ff
|
|
|
|
jr z, .doneSimulating ; if the end of the simulated button presses has been reached
|
|
|
|
ld hl, wSimulatedJoypadStatesEnd
|
2014-05-31 01:30:25 +00:00
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hl]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hJoyHeld], a ; store simulated button press in joypad state
|
2014-05-31 01:30:25 +00:00
|
|
|
and a
|
|
|
|
ret nz
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hJoyPressed], a
|
|
|
|
ldh [hJoyReleased], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
2016-06-12 18:35:21 +00:00
|
|
|
|
2014-05-31 01:30:25 +00:00
|
|
|
; if done simulating button presses
|
|
|
|
.doneSimulating
|
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wWastedByteCD3A], a
|
|
|
|
ld [wSimulatedJoypadStatesIndex], a
|
|
|
|
ld [wSimulatedJoypadStatesEnd], a
|
|
|
|
ld [wJoyIgnore], a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hJoyHeld], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wd736
|
|
|
|
ld a, [hl]
|
2016-06-12 18:35:21 +00:00
|
|
|
and $f8
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a
|
|
|
|
ld hl, wd730
|
|
|
|
res 7, [hl]
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to check the tile ahead to determine if the character should get on land or keep surfing
|
|
|
|
; sets carry if there is a collision and clears carry otherwise
|
|
|
|
; It seems that this function has a bug in it, but due to luck, it doesn't
|
|
|
|
; show up. After detecting a sprite collision, it jumps to the code that
|
|
|
|
; checks if the next tile is passable instead of just directly jumping to the
|
|
|
|
; "collision detected" code. However, it doesn't store the next tile in c,
|
|
|
|
; so the old value of c is used. 2429 is always called before this function,
|
|
|
|
; and 2429 always sets c to 0xF0. There is no 0xF0 background tile, so it
|
|
|
|
; is considered impassable and it is detected as a collision.
|
2016-06-12 00:24:04 +00:00
|
|
|
CollisionCheckOnWater::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd730]
|
|
|
|
bit 7, a
|
|
|
|
jp nz, .noCollision ; return and clear carry if button presses are being simulated
|
|
|
|
ld a, [wPlayerDirection] ; the direction that the player is trying to go in
|
|
|
|
ld d, a
|
2020-07-05 21:29:11 +00:00
|
|
|
ld a, [wSpritePlayerStateData1CollisionData]
|
2014-05-31 01:30:25 +00:00
|
|
|
and d ; check if a sprite is in the direction the player is trying to go
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .checkIfNextTileIsPassable ; bug?
|
|
|
|
ld hl, TilePairCollisionsWater
|
2014-05-31 01:30:25 +00:00
|
|
|
call CheckForJumpingAndTilePairCollisions
|
2017-12-30 00:54:27 +00:00
|
|
|
jr c, .collision
|
2014-09-13 07:50:56 +00:00
|
|
|
predef GetTileAndCoordsInFrontOfPlayer ; get tile in front of player (puts it in c and [wTileInFrontOfPlayer])
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wTileInFrontOfPlayer] ; tile in front of player
|
|
|
|
cp $14 ; water tile
|
|
|
|
jr z, .noCollision ; keep surfing if it's a water tile
|
|
|
|
cp $32 ; either the left tile of the S.S. Anne boarding platform or the tile on eastern coastlines (depending on the current tileset)
|
|
|
|
jr z, .checkIfVermilionDockTileset
|
|
|
|
cp $48 ; tile on right on coast lines in Safari Zone
|
|
|
|
jr z, .noCollision ; keep surfing
|
2014-05-31 01:30:25 +00:00
|
|
|
; check if the [land] tile in front of the player is passable
|
|
|
|
.checkIfNextTileIsPassable
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wTilesetCollisionPtr ; pointer to list of passable tiles
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
cp $ff
|
|
|
|
jr z, .collision
|
2014-05-31 01:30:25 +00:00
|
|
|
cp c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .stopSurfing ; stop surfing if the tile is passable
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .loop
|
|
|
|
.collision
|
2019-07-28 04:21:39 +00:00
|
|
|
ld a, [wChannelSoundIDs + Ch5]
|
2016-06-12 18:35:21 +00:00
|
|
|
cp SFX_COLLISION ; check if collision sound is already playing
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .setCarry
|
|
|
|
ld a, SFX_COLLISION
|
2014-05-31 01:30:25 +00:00
|
|
|
call PlaySound ; play collision sound (if it's not already playing)
|
|
|
|
.setCarry
|
|
|
|
scf
|
|
|
|
jr .done
|
|
|
|
.noCollision
|
|
|
|
and a
|
|
|
|
.done
|
|
|
|
ret
|
|
|
|
.stopSurfing
|
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wWalkBikeSurfState], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadPlayerSpriteGraphics
|
2014-09-10 03:55:19 +00:00
|
|
|
call PlayDefaultMusic
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .noCollision
|
|
|
|
.checkIfVermilionDockTileset
|
2015-08-31 02:38:41 +00:00
|
|
|
ld a, [wCurMapTileset] ; tileset
|
2014-05-31 01:30:25 +00:00
|
|
|
cp SHIP_PORT ; Vermilion Dock tileset
|
|
|
|
jr nz, .noCollision ; keep surfing if it's not the boarding platform tile
|
|
|
|
jr .stopSurfing ; if it is the boarding platform tile, stop surfing
|
|
|
|
|
|
|
|
; function to run the current map's script
|
2016-06-12 00:24:04 +00:00
|
|
|
RunMapScript::
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall TryPushingBoulder
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wFlags_0xcd60]
|
|
|
|
bit 1, a ; play boulder dust animation
|
|
|
|
jr z, .afterBoulderEffect
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall DoBoulderDustAnimation
|
2014-05-31 01:30:25 +00:00
|
|
|
.afterBoulderEffect
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
2014-09-10 03:55:19 +00:00
|
|
|
call RunNPCMovementScript
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMap] ; current map number
|
2014-05-31 01:30:25 +00:00
|
|
|
call SwitchToMapRomBank ; change to the ROM bank the map's data is in
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wMapScriptPtr
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld de, .return
|
2014-05-31 01:30:25 +00:00
|
|
|
push de
|
2017-06-09 21:54:09 +00:00
|
|
|
jp hl ; jump to script
|
2014-05-31 01:30:25 +00:00
|
|
|
.return
|
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadWalkingPlayerSpriteGraphics::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, RedSprite
|
|
|
|
ld hl, vNPCSprites
|
2014-05-31 01:30:25 +00:00
|
|
|
jr LoadPlayerSpriteGraphicsCommon
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadSurfingPlayerSpriteGraphics::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, SeelSprite
|
|
|
|
ld hl, vNPCSprites
|
2014-05-31 01:30:25 +00:00
|
|
|
jr LoadPlayerSpriteGraphicsCommon
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadBikePlayerSpriteGraphics::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, RedCyclingSprite
|
|
|
|
ld hl, vNPCSprites
|
2014-05-31 01:30:25 +00:00
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadPlayerSpriteGraphicsCommon::
|
2014-05-31 01:30:25 +00:00
|
|
|
push de
|
|
|
|
push hl
|
2015-08-05 21:20:29 +00:00
|
|
|
lb bc, BANK(RedSprite), $0c
|
2014-05-31 01:30:25 +00:00
|
|
|
call CopyVideoData
|
|
|
|
pop hl
|
|
|
|
pop de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $c0
|
2014-05-31 01:30:25 +00:00
|
|
|
add e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
jr nc, .noCarry
|
2014-05-31 01:30:25 +00:00
|
|
|
inc d
|
|
|
|
.noCarry
|
2017-12-30 00:54:27 +00:00
|
|
|
set 3, h
|
2015-08-05 21:20:29 +00:00
|
|
|
lb bc, BANK(RedSprite), $0c
|
2014-05-31 01:30:25 +00:00
|
|
|
jp CopyVideoData
|
|
|
|
|
|
|
|
; function to load data from the map header
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadMapHeader::
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall MarkTownVisitedAndLoadMissableObjects
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMapTileset]
|
|
|
|
ld [wUnusedD119], a
|
|
|
|
ld a, [wCurMap]
|
2014-05-31 01:30:25 +00:00
|
|
|
call SwitchToMapRomBank
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMapTileset]
|
|
|
|
ld b, a
|
|
|
|
res 7, a
|
|
|
|
ld [wCurMapTileset], a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hPreviousTileset], a
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 7, b
|
2014-05-31 01:30:25 +00:00
|
|
|
ret nz
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, MapHeaderPointers
|
|
|
|
ld a, [wCurMap]
|
2014-05-31 01:30:25 +00:00
|
|
|
sla a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nc, .noCarry1
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry1
|
|
|
|
add l
|
2017-12-30 00:54:27 +00:00
|
|
|
ld l, a
|
|
|
|
jr nc, .noCarry2
|
2014-05-31 01:30:25 +00:00
|
|
|
inc h
|
|
|
|
.noCarry2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a ; hl = base of map header
|
2014-05-31 01:30:25 +00:00
|
|
|
; copy the first 10 bytes (the fixed area) of the map data to D367-D370
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wCurMapTileset
|
|
|
|
ld c, $0a
|
2014-05-31 01:30:25 +00:00
|
|
|
.copyFixedHeaderLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .copyFixedHeaderLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
; initialize all the connected maps to disabled at first, before loading the actual values
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $ff
|
|
|
|
ld [wMapConn1Ptr], a
|
|
|
|
ld [wMapConn2Ptr], a
|
|
|
|
ld [wMapConn3Ptr], a
|
|
|
|
ld [wMapConn4Ptr], a
|
2014-05-31 01:30:25 +00:00
|
|
|
; copy connection data (if any) to WRAM
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wMapConnections]
|
|
|
|
ld b, a
|
2014-05-31 01:30:25 +00:00
|
|
|
.checkNorth
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 3, b
|
|
|
|
jr z, .checkSouth
|
|
|
|
ld de, wMapConn1Ptr
|
2014-05-31 01:30:25 +00:00
|
|
|
call CopyMapConnectionHeader
|
|
|
|
.checkSouth
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 2, b
|
|
|
|
jr z, .checkWest
|
|
|
|
ld de, wMapConn2Ptr
|
2014-05-31 01:30:25 +00:00
|
|
|
call CopyMapConnectionHeader
|
|
|
|
.checkWest
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 1, b
|
|
|
|
jr z, .checkEast
|
|
|
|
ld de, wMapConn3Ptr
|
2014-05-31 01:30:25 +00:00
|
|
|
call CopyMapConnectionHeader
|
|
|
|
.checkEast
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 0, b
|
|
|
|
jr z, .getObjectDataPointer
|
|
|
|
ld de, wMapConn4Ptr
|
2014-05-31 01:30:25 +00:00
|
|
|
call CopyMapConnectionHeader
|
|
|
|
.getObjectDataPointer
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [wObjectDataPointerTemp], a
|
|
|
|
ld a, [hli]
|
|
|
|
ld [wObjectDataPointerTemp + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wObjectDataPointerTemp]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wObjectDataPointerTemp + 1]
|
|
|
|
ld h, a ; hl = base of object data
|
|
|
|
ld de, wMapBackgroundTile
|
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
.loadWarpData
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [wNumberOfWarps], a
|
2014-09-13 07:50:56 +00:00
|
|
|
and a
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .loadSignData
|
|
|
|
ld c, a
|
|
|
|
ld de, wWarpEntries
|
2014-05-31 01:30:25 +00:00
|
|
|
.warpLoop ; one warp per loop iteration
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, $04
|
2014-05-31 01:30:25 +00:00
|
|
|
.warpInnerLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .warpInnerLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .warpLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.loadSignData
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli] ; number of signs
|
|
|
|
ld [wNumSigns], a
|
2014-05-31 01:30:25 +00:00
|
|
|
and a ; are there any signs?
|
2017-12-30 00:54:27 +00:00
|
|
|
jr z, .loadSpriteData ; if not, skip this
|
|
|
|
ld c, a
|
|
|
|
ld de, wSignTextIDs
|
|
|
|
ld a, d
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSignCoordPointer], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, e
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSignCoordPointer + 1], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, wSignCoords
|
2014-05-31 01:30:25 +00:00
|
|
|
.signLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
push de
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hSignCoordPointer]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld d, a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hSignCoordPointer + 1]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, d
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSignCoordPointer], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, e
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSignCoordPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
pop de
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .signLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.loadSpriteData
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd72e]
|
|
|
|
bit 5, a ; did a battle happen immediately before this?
|
|
|
|
jp nz, .finishUp ; if so, skip this because battles don't destroy this data
|
|
|
|
ld a, [hli]
|
|
|
|
ld [wNumSprites], a ; save the number of sprites
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
|
|
|
; zero C110-C1FF and C210-C2FF
|
2020-07-05 21:29:11 +00:00
|
|
|
ld hl, wSprite01StateData1
|
|
|
|
ld de, wSprite01StateData2
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, $f0
|
2014-05-31 01:30:25 +00:00
|
|
|
.zeroSpriteDataLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hli], a
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc e
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .zeroSpriteDataLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
; initialize all C100-C1FF sprite entries to disabled (other than player's)
|
2020-07-05 21:29:11 +00:00
|
|
|
ld hl, wSprite01StateData1ImageIndex
|
2020-07-04 05:00:45 +00:00
|
|
|
ld de, $10
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, $0f
|
2014-05-31 01:30:25 +00:00
|
|
|
.disableSpriteEntriesLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], $ff
|
|
|
|
add hl, de
|
2014-05-31 01:30:25 +00:00
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .disableSpriteEntriesLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
2020-07-05 21:29:11 +00:00
|
|
|
ld de, wSprite01StateData1
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wNumSprites] ; number of sprites
|
2014-05-31 01:30:25 +00:00
|
|
|
and a ; are there any sprites?
|
2017-12-30 00:54:27 +00:00
|
|
|
jp z, .finishUp ; if there are no sprites, skip the rest
|
|
|
|
ld b, a
|
|
|
|
ld c, $00
|
2014-05-31 01:30:25 +00:00
|
|
|
.loadSpriteLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a ; store picture ID at C1X0
|
2014-05-31 01:30:25 +00:00
|
|
|
inc d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $04
|
2014-05-31 01:30:25 +00:00
|
|
|
add e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a ; store Y position at C2X4
|
2014-05-31 01:30:25 +00:00
|
|
|
inc e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a ; store X position at C2X5
|
2014-05-31 01:30:25 +00:00
|
|
|
inc e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a ; store movement byte 1 at C2X6
|
|
|
|
ld a, [hli]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadSpriteTemp1], a ; save movement byte 2
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadSpriteTemp2], a ; save text ID and flags byte
|
2014-05-31 01:30:25 +00:00
|
|
|
push bc
|
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld b, $00
|
|
|
|
ld hl, wMapSpriteData
|
|
|
|
add hl, bc
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadSpriteTemp1]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hli], a ; store movement byte 2 in byte 0 of sprite entry
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadSpriteTemp2]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a ; this appears pointless, since the value is overwritten immediately after
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadSpriteTemp2]
|
|
|
|
ldh [hLoadSpriteTemp1], a
|
2017-12-30 00:54:27 +00:00
|
|
|
and $3f
|
|
|
|
ld [hl], a ; store text ID in byte 1 of sprite entry
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadSpriteTemp1]
|
2017-12-30 00:54:27 +00:00
|
|
|
bit 6, a
|
|
|
|
jr nz, .trainerSprite
|
|
|
|
bit 7, a
|
|
|
|
jr nz, .itemBallSprite
|
2014-05-31 01:30:25 +00:00
|
|
|
jr .regularSprite
|
|
|
|
.trainerSprite
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadSpriteTemp1], a ; save trainer class
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadSpriteTemp2], a ; save trainer number (within class)
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wMapSpriteExtraData
|
|
|
|
add hl, bc
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadSpriteTemp1]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hli], a ; store trainer class in byte 0 of the entry
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadSpriteTemp2]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a ; store trainer number in byte 1 of the entry
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
|
|
|
jr .nextSprite
|
|
|
|
.itemBallSprite
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadSpriteTemp1], a ; save item number
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wMapSpriteExtraData
|
|
|
|
add hl, bc
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadSpriteTemp1]
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hli], a ; store item number in byte 0 of the entry
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hl], a ; zero byte 1, since it is not used
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
|
|
|
jr .nextSprite
|
|
|
|
.regularSprite
|
|
|
|
push hl
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, wMapSpriteExtraData
|
|
|
|
add hl, bc
|
2014-05-31 01:30:25 +00:00
|
|
|
; zero both bytes, since regular sprites don't use this extra space
|
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [hli], a
|
|
|
|
ld [hl], a
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl
|
|
|
|
.nextSprite
|
|
|
|
pop bc
|
|
|
|
dec d
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $0a
|
2014-05-31 01:30:25 +00:00
|
|
|
add e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc c
|
|
|
|
inc c
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jp nz, .loadSpriteLoop
|
2014-05-31 01:30:25 +00:00
|
|
|
.finishUp
|
2014-09-13 07:50:56 +00:00
|
|
|
predef LoadTilesetHeader
|
2020-07-07 01:18:22 +00:00
|
|
|
callfar LoadWildData
|
2014-05-31 01:30:25 +00:00
|
|
|
pop hl ; restore hl from before going to the warp/sign/sprite data (this value was saved for seemingly no purpose)
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wCurMapHeight] ; map height in 4x4 tile blocks
|
2014-05-31 01:30:25 +00:00
|
|
|
add a ; double it
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wCurrentMapHeight2], a ; store map height in 2x2 tile blocks
|
|
|
|
ld a, [wCurMapWidth] ; map width in 4x4 tile blocks
|
2014-05-31 01:30:25 +00:00
|
|
|
add a ; double it
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wCurrentMapWidth2], a ; map width in 2x2 tile blocks
|
|
|
|
ld a, [wCurMap]
|
|
|
|
ld c, a
|
|
|
|
ld b, $00
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadedROMBank]
|
2014-05-31 01:30:25 +00:00
|
|
|
push af
|
|
|
|
ld a, BANK(MapSongBanks)
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadedROMBank], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [MBC1RomBank], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ld hl, MapSongBanks
|
2017-12-30 00:54:27 +00:00
|
|
|
add hl, bc
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld [wMapMusicSoundID], a ; music 1
|
|
|
|
ld a, [hl]
|
|
|
|
ld [wMapMusicROMBank], a ; music 2
|
2014-05-31 01:30:25 +00:00
|
|
|
pop af
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadedROMBank], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [MBC1RomBank], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to copy map connection data from ROM to WRAM
|
|
|
|
; Input: hl = source, de = destination
|
2016-06-12 00:24:04 +00:00
|
|
|
CopyMapConnectionHeader::
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, $0b
|
2014-05-31 01:30:25 +00:00
|
|
|
.loop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc de
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .loop
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to load map data
|
2016-06-12 00:24:04 +00:00
|
|
|
LoadMapData::
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hLoadedROMBank]
|
2014-05-31 01:30:25 +00:00
|
|
|
push af
|
|
|
|
call DisableLCD
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, $98
|
|
|
|
ld [wMapViewVRAMPointer + 1], a
|
2014-05-31 01:30:25 +00:00
|
|
|
xor a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wMapViewVRAMPointer], a
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hSCY], a
|
|
|
|
ldh [hSCX], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [wWalkCounter], a
|
|
|
|
ld [wUnusedD119], a
|
|
|
|
ld [wWalkBikeSurfStateCopy], a
|
|
|
|
ld [wSpriteSetID], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadTextBoxTilePatterns
|
|
|
|
call LoadMapHeader
|
2020-07-07 01:18:22 +00:00
|
|
|
farcall InitMapSprites ; load tile pattern data for sprites
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadTileBlockMap
|
|
|
|
call LoadTilesetTilePatternData
|
|
|
|
call LoadCurrentMapView
|
|
|
|
; copy current map view to VRAM
|
2015-07-18 20:52:03 +00:00
|
|
|
coord hl, 0, 0
|
2017-12-30 00:54:27 +00:00
|
|
|
ld de, vBGMap0
|
|
|
|
ld b, 18
|
2014-05-31 01:30:25 +00:00
|
|
|
.vramCopyLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, 20
|
2014-05-31 01:30:25 +00:00
|
|
|
.vramCopyInnerLoop
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld [de], a
|
2014-05-31 01:30:25 +00:00
|
|
|
inc e
|
|
|
|
dec c
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .vramCopyInnerLoop
|
|
|
|
ld a, 32 - 20
|
2014-05-31 01:30:25 +00:00
|
|
|
add e
|
2017-12-30 00:54:27 +00:00
|
|
|
ld e, a
|
|
|
|
jr nc, .noCarry
|
2014-05-31 01:30:25 +00:00
|
|
|
inc d
|
|
|
|
.noCarry
|
|
|
|
dec b
|
2017-12-30 00:54:27 +00:00
|
|
|
jr nz, .vramCopyLoop
|
|
|
|
ld a, $01
|
|
|
|
ld [wUpdateSpritesEnabled], a
|
2014-05-31 01:30:25 +00:00
|
|
|
call EnableLCD
|
2015-08-12 09:16:56 +00:00
|
|
|
ld b, SET_PAL_OVERWORLD
|
|
|
|
call RunPaletteCommand
|
2014-05-31 01:30:25 +00:00
|
|
|
call LoadPlayerSpriteGraphics
|
2017-12-30 00:54:27 +00:00
|
|
|
ld a, [wd732]
|
|
|
|
and 1 << 4 | 1 << 3 ; fly warp or dungeon warp
|
|
|
|
jr nz, .restoreRomBank
|
|
|
|
ld a, [wFlags_D733]
|
|
|
|
bit 1, a
|
|
|
|
jr nz, .restoreRomBank
|
2015-08-09 05:32:44 +00:00
|
|
|
call UpdateMusic6Times
|
|
|
|
call PlayDefaultMusicFadeOutCurrent
|
2014-05-31 01:30:25 +00:00
|
|
|
.restoreRomBank
|
|
|
|
pop af
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hLoadedROMBank], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [MBC1RomBank], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
; function to switch to the ROM bank that a map is stored in
|
|
|
|
; Input: a = map number
|
2016-06-12 00:24:04 +00:00
|
|
|
SwitchToMapRomBank::
|
2014-05-31 01:30:25 +00:00
|
|
|
push hl
|
|
|
|
push bc
|
2017-12-30 00:54:27 +00:00
|
|
|
ld c, a
|
|
|
|
ld b, $00
|
2020-07-04 02:11:35 +00:00
|
|
|
ld a, BANK(MapHeaderBanks)
|
2014-05-31 01:30:25 +00:00
|
|
|
call BankswitchHome ; switch to ROM bank 3
|
2017-12-30 00:54:27 +00:00
|
|
|
ld hl, MapHeaderBanks
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh [hMapROMBank], a ; save map ROM bank
|
2014-05-31 01:30:25 +00:00
|
|
|
call BankswitchBack
|
2020-07-06 23:03:05 +00:00
|
|
|
ldh a, [hMapROMBank]
|
|
|
|
ldh [hLoadedROMBank], a
|
2017-12-30 00:54:27 +00:00
|
|
|
ld [MBC1RomBank], a ; switch to map ROM bank
|
2014-05-31 01:30:25 +00:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
IgnoreInputForHalfSecond:
|
2014-09-14 18:29:18 +00:00
|
|
|
ld a, 30
|
|
|
|
ld [wIgnoreInputCounter], a
|
2014-05-31 01:30:25 +00:00
|
|
|
ld hl, wd730
|
|
|
|
ld a, [hl]
|
2016-06-12 18:35:21 +00:00
|
|
|
or %00100110
|
2014-09-14 18:29:18 +00:00
|
|
|
ld [hl], a ; set ignore input bit
|
2014-05-31 01:30:25 +00:00
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ResetUsingStrengthOutOfBattleBit:
|
2014-05-31 01:30:25 +00:00
|
|
|
ld hl, wd728
|
|
|
|
res 0, [hl]
|
|
|
|
ret
|
|
|
|
|
2016-06-12 00:24:04 +00:00
|
|
|
ForceBikeOrSurf::
|
2014-05-31 01:30:25 +00:00
|
|
|
ld b, BANK(RedSprite)
|
|
|
|
ld hl, LoadPlayerSpriteGraphics
|
|
|
|
call Bankswitch
|
2014-09-10 03:55:19 +00:00
|
|
|
jp PlayDefaultMusic ; update map/player state?
|