2015-11-30 02:34:59 +00:00
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
HandleNewMap: ; 1045b0
|
2015-11-30 02:34:59 +00:00
|
|
|
call Clearwc7e8
|
|
|
|
call ResetMapBufferEventFlags
|
|
|
|
call ResetFlashIfOutOfCave
|
2017-12-24 18:46:34 +00:00
|
|
|
call GetCurrentMapSceneID
|
2015-11-30 02:34:59 +00:00
|
|
|
call ResetBikeFlags
|
2016-01-06 12:44:50 +00:00
|
|
|
ld a, MAPCALLBACK_NEWMAP
|
2015-11-30 02:34:59 +00:00
|
|
|
call RunMapCallback
|
2016-05-17 12:40:42 +00:00
|
|
|
InitCommandQueue: ; 1045c4
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall ClearCmdQueue
|
2016-01-06 21:59:56 +00:00
|
|
|
ld a, MAPCALLBACK_CMDQUEUE
|
2015-11-30 02:34:59 +00:00
|
|
|
call RunMapCallback
|
|
|
|
call GetMapHeaderTimeOfDayNybble
|
2015-12-15 01:06:41 +00:00
|
|
|
ld [wMapTimeOfDay], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
EnterMapConnection: ; 1045d6
|
|
|
|
; Return carry if a connection has been entered.
|
|
|
|
ld a, [wPlayerStepDirection]
|
|
|
|
and a
|
2016-05-17 12:40:42 +00:00
|
|
|
jp z, .south
|
|
|
|
cp UP
|
|
|
|
jp z, .north
|
|
|
|
cp LEFT
|
|
|
|
jp z, .west
|
|
|
|
cp RIGHT
|
|
|
|
jp z, .east
|
2015-11-30 02:34:59 +00:00
|
|
|
ret
|
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.west
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [WestConnectedMapGroup]
|
|
|
|
ld [MapGroup], a
|
|
|
|
ld a, [WestConnectedMapNumber]
|
|
|
|
ld [MapNumber], a
|
|
|
|
ld a, [WestConnectionStripXOffset]
|
|
|
|
ld [XCoord], a
|
|
|
|
ld a, [WestConnectionStripYOffset]
|
|
|
|
ld hl, YCoord
|
|
|
|
add [hl]
|
|
|
|
ld [hl], a
|
|
|
|
ld c, a
|
|
|
|
ld hl, WestConnectionWindow
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
srl c
|
|
|
|
jr z, .skip_to_load
|
|
|
|
ld a, [WestConnectedMapWidth]
|
|
|
|
add 6
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
|
|
|
|
.loop
|
|
|
|
add hl, de
|
|
|
|
dec c
|
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
.skip_to_load
|
|
|
|
ld a, l
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, h
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor + 1], a
|
2016-05-17 12:40:42 +00:00
|
|
|
jp .done
|
2015-11-30 02:34:59 +00:00
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.east
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [EastConnectedMapGroup]
|
|
|
|
ld [MapGroup], a
|
|
|
|
ld a, [EastConnectedMapNumber]
|
|
|
|
ld [MapNumber], a
|
|
|
|
ld a, [EastConnectionStripXOffset]
|
|
|
|
ld [XCoord], a
|
|
|
|
ld a, [EastConnectionStripYOffset]
|
|
|
|
ld hl, YCoord
|
|
|
|
add [hl]
|
|
|
|
ld [hl], a
|
|
|
|
ld c, a
|
|
|
|
ld hl, EastConnectionWindow
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
srl c
|
2016-05-17 12:40:42 +00:00
|
|
|
jr z, .skip_to_load2
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [EastConnectedMapWidth]
|
|
|
|
add 6
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.loop2
|
2015-11-30 02:34:59 +00:00
|
|
|
add hl, de
|
|
|
|
dec c
|
2016-05-17 12:40:42 +00:00
|
|
|
jr nz, .loop2
|
2015-11-30 02:34:59 +00:00
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.skip_to_load2
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, l
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, h
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor + 1], a
|
2016-05-17 12:40:42 +00:00
|
|
|
jp .done
|
2015-11-30 02:34:59 +00:00
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.north
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [NorthConnectedMapGroup]
|
|
|
|
ld [MapGroup], a
|
|
|
|
ld a, [NorthConnectedMapNumber]
|
|
|
|
ld [MapNumber], a
|
|
|
|
ld a, [NorthConnectionStripYOffset]
|
|
|
|
ld [YCoord], a
|
|
|
|
ld a, [NorthConnectionStripXOffset]
|
|
|
|
ld hl, XCoord
|
|
|
|
add [hl]
|
|
|
|
ld [hl], a
|
|
|
|
ld c, a
|
|
|
|
ld hl, NorthConnectionWindow
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld b, 0
|
|
|
|
srl c
|
|
|
|
add hl, bc
|
|
|
|
ld a, l
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, h
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor + 1], a
|
2016-05-17 12:40:42 +00:00
|
|
|
jp .done
|
2015-11-30 02:34:59 +00:00
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.south
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [SouthConnectedMapGroup]
|
|
|
|
ld [MapGroup], a
|
|
|
|
ld a, [SouthConnectedMapNumber]
|
|
|
|
ld [MapNumber], a
|
|
|
|
ld a, [SouthConnectionStripYOffset]
|
|
|
|
ld [YCoord], a
|
|
|
|
ld a, [SouthConnectionStripXOffset]
|
|
|
|
ld hl, XCoord
|
|
|
|
add [hl]
|
|
|
|
ld [hl], a
|
|
|
|
ld c, a
|
|
|
|
ld hl, SouthConnectionWindow
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld b, 0
|
|
|
|
srl c
|
|
|
|
add hl, bc
|
|
|
|
ld a, l
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, h
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor + 1], a
|
2016-05-17 12:40:42 +00:00
|
|
|
.done
|
2015-11-30 02:34:59 +00:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
; 1046c6
|
|
|
|
|
|
|
|
LoadWarpData: ; 1046c6
|
|
|
|
call .SaveDigWarp
|
|
|
|
call .SetSpawn
|
|
|
|
ld a, [wNextWarp]
|
|
|
|
ld [WarpNumber], a
|
|
|
|
ld a, [wNextMapGroup]
|
|
|
|
ld [MapGroup], a
|
|
|
|
ld a, [wNextMapNumber]
|
|
|
|
ld [MapNumber], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.SaveDigWarp: ; 1046df (41:46df)
|
2017-12-24 18:08:38 +00:00
|
|
|
call GetMapEnvironment
|
2015-11-30 02:34:59 +00:00
|
|
|
call CheckOutdoorMap
|
|
|
|
ret nz
|
|
|
|
ld a, [wNextMapGroup]
|
|
|
|
ld b, a
|
|
|
|
ld a, [wNextMapNumber]
|
|
|
|
ld c, a
|
2017-12-24 18:08:38 +00:00
|
|
|
call GetAnyMapEnvironment
|
2015-11-30 02:34:59 +00:00
|
|
|
call CheckIndoorMap
|
|
|
|
ret nz
|
|
|
|
ld a, [wPrevMapGroup]
|
|
|
|
cp GROUP_MOUNT_MOON_SQUARE
|
|
|
|
jr nz, .not_mt_moon_or_tin_tower
|
|
|
|
ld a, [wPrevMapNumber]
|
|
|
|
cp MAP_MOUNT_MOON_SQUARE
|
|
|
|
ret z
|
|
|
|
cp MAP_TIN_TOWER_ROOF
|
|
|
|
ret z
|
|
|
|
.not_mt_moon_or_tin_tower
|
|
|
|
ld a, [wPrevWarp]
|
2017-12-10 00:41:03 +00:00
|
|
|
ld [wDigWarpNumber], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [wPrevMapGroup]
|
|
|
|
ld [wDigMapGroup], a
|
|
|
|
ld a, [wPrevMapNumber]
|
|
|
|
ld [wDigMapNumber], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.SetSpawn: ; 104718 (41:4718)
|
2017-12-24 18:08:38 +00:00
|
|
|
call GetMapEnvironment
|
2015-11-30 02:34:59 +00:00
|
|
|
call CheckOutdoorMap
|
|
|
|
ret nz
|
|
|
|
ld a, [wNextMapGroup]
|
|
|
|
ld b, a
|
|
|
|
ld a, [wNextMapNumber]
|
|
|
|
ld c, a
|
2017-12-24 18:08:38 +00:00
|
|
|
call GetAnyMapEnvironment
|
2015-11-30 02:34:59 +00:00
|
|
|
call CheckIndoorMap
|
|
|
|
ret nz
|
|
|
|
ld a, [wNextMapGroup]
|
|
|
|
ld b, a
|
|
|
|
ld a, [wNextMapNumber]
|
|
|
|
ld c, a
|
|
|
|
call GetAnyMapTileset
|
|
|
|
ld a, c
|
|
|
|
cp TILESET_POKECENTER
|
|
|
|
jr z, .pokecenter_pokecom
|
|
|
|
cp TILESET_POKECOM_CENTER
|
|
|
|
jr z, .pokecenter_pokecom
|
|
|
|
ret
|
|
|
|
.pokecenter_pokecom
|
|
|
|
ld a, [wPrevMapGroup]
|
|
|
|
ld [wLastSpawnMapGroup], a
|
|
|
|
ld a, [wPrevMapNumber]
|
|
|
|
ld [wLastSpawnMapNumber], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
LoadMapTimeOfDay: ; 104750
|
|
|
|
ld hl, VramState
|
|
|
|
res 6, [hl]
|
|
|
|
ld a, $1
|
|
|
|
ld [wSpriteUpdatesEnabled], a
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall ReplaceTimeOfDayPals
|
|
|
|
farcall UpdateTimeOfDayPal
|
2015-11-30 02:34:59 +00:00
|
|
|
call OverworldTextModeSwitch
|
2016-05-17 12:40:42 +00:00
|
|
|
call .ClearBGMap
|
|
|
|
call .PushAttrMap
|
2015-11-30 02:34:59 +00:00
|
|
|
ret
|
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.ClearBGMap: ; 104770 (41:4770)
|
2017-12-25 18:40:10 +00:00
|
|
|
ld a, HIGH(VBGMap0)
|
2015-11-30 02:34:59 +00:00
|
|
|
ld [wBGMapAnchor + 1], a
|
2017-12-25 18:40:10 +00:00
|
|
|
xor a ; LOW(VBGMap0)
|
2015-11-30 02:34:59 +00:00
|
|
|
ld [wBGMapAnchor], a
|
|
|
|
ld [hSCY], a
|
|
|
|
ld [hSCX], a
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall ApplyBGMapAnchorToObjects
|
2016-05-17 12:40:42 +00:00
|
|
|
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [rVBK]
|
|
|
|
push af
|
|
|
|
ld a, $1
|
|
|
|
ld [rVBK], a
|
2016-05-17 12:40:42 +00:00
|
|
|
|
2015-11-30 02:34:59 +00:00
|
|
|
xor a
|
2015-12-19 19:48:30 +00:00
|
|
|
ld bc, VBGMap1 - VBGMap0
|
2015-11-30 02:34:59 +00:00
|
|
|
hlbgcoord 0, 0
|
|
|
|
call ByteFill
|
2016-05-17 12:40:42 +00:00
|
|
|
|
2015-11-30 02:34:59 +00:00
|
|
|
pop af
|
|
|
|
ld [rVBK], a
|
2016-05-17 12:40:42 +00:00
|
|
|
|
2017-12-09 17:24:50 +00:00
|
|
|
ld a, "<BLACK>"
|
2015-12-19 19:48:30 +00:00
|
|
|
ld bc, VBGMap1 - VBGMap0
|
2015-11-30 02:34:59 +00:00
|
|
|
hlbgcoord 0, 0
|
|
|
|
call ByteFill
|
|
|
|
ret
|
|
|
|
|
2016-05-17 12:40:42 +00:00
|
|
|
.PushAttrMap: ; 1047a3 (41:47a3)
|
2015-11-30 02:34:59 +00:00
|
|
|
decoord 0, 0
|
|
|
|
call .copy
|
|
|
|
ld a, [hCGB]
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
|
|
|
|
decoord 0, 0, AttrMap
|
|
|
|
ld a, $1
|
|
|
|
ld [rVBK], a
|
2016-04-10 19:01:49 +00:00
|
|
|
.copy
|
2015-11-30 02:34:59 +00:00
|
|
|
hlbgcoord 0, 0
|
|
|
|
ld c, SCREEN_WIDTH
|
|
|
|
ld b, SCREEN_HEIGHT
|
|
|
|
.row
|
|
|
|
push bc
|
|
|
|
.column
|
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hli], a
|
|
|
|
dec c
|
|
|
|
jr nz, .column
|
2015-12-22 23:03:00 +00:00
|
|
|
ld bc, BG_MAP_WIDTH - SCREEN_WIDTH
|
2015-11-30 02:34:59 +00:00
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec b
|
|
|
|
jr nz, .row
|
|
|
|
ld a, $0
|
|
|
|
ld [rVBK], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
LoadGraphics: ; 1047cf
|
|
|
|
call LoadTileset
|
2017-12-26 17:50:32 +00:00
|
|
|
call LoadTilesetGFX
|
2015-11-30 02:34:59 +00:00
|
|
|
xor a
|
|
|
|
ld [hMapAnims], a
|
|
|
|
xor a
|
|
|
|
ld [hTileAnimFrame], a
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall RefreshSprites
|
2015-11-30 02:34:59 +00:00
|
|
|
call LoadFontsExtra
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall LoadOverworldFont
|
2015-11-30 02:34:59 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
LoadMapPalettes: ; 1047eb
|
2015-12-22 23:03:00 +00:00
|
|
|
ld b, SCGB_MAPPALS
|
2015-11-30 02:34:59 +00:00
|
|
|
jp GetSGBLayout
|
|
|
|
; 1047f0
|
|
|
|
|
|
|
|
RefreshMapSprites: ; 1047f0
|
|
|
|
call ClearSprites
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall ReturnFromMapSetupScript
|
2015-11-30 02:34:59 +00:00
|
|
|
call GetMovementPermissions
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall RefreshPlayerSprite
|
|
|
|
farcall CheckReplaceKrisSprite
|
2015-11-30 02:34:59 +00:00
|
|
|
ld hl, wPlayerSpriteSetupFlags
|
|
|
|
bit 6, [hl]
|
|
|
|
jr nz, .skip
|
|
|
|
ld hl, VramState
|
|
|
|
set 0, [hl]
|
2016-05-10 16:31:49 +00:00
|
|
|
call SafeUpdateSprites
|
2015-11-30 02:34:59 +00:00
|
|
|
.skip
|
|
|
|
ld a, [wPlayerSpriteSetupFlags]
|
2015-12-22 23:03:00 +00:00
|
|
|
and %00011100
|
2015-11-30 02:34:59 +00:00
|
|
|
ld [wPlayerSpriteSetupFlags], a
|
|
|
|
ret
|
|
|
|
|
|
|
|
CheckMovingOffEdgeOfMap:: ; 104820 (41:4820)
|
|
|
|
ld a, [wPlayerStepDirection]
|
|
|
|
cp STANDING
|
|
|
|
ret z
|
|
|
|
and a ; DOWN
|
|
|
|
jr z, .down
|
|
|
|
cp UP
|
|
|
|
jr z, .up
|
|
|
|
cp LEFT
|
|
|
|
jr z, .left
|
|
|
|
cp RIGHT
|
|
|
|
jr z, .right
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.down
|
2016-01-11 07:28:09 +00:00
|
|
|
ld a, [PlayerStandingMapY]
|
2015-11-30 02:34:59 +00:00
|
|
|
sub 4
|
|
|
|
ld b, a
|
|
|
|
ld a, [MapHeight]
|
|
|
|
add a
|
|
|
|
cp b
|
|
|
|
jr z, .ok
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.up
|
2016-01-11 07:28:09 +00:00
|
|
|
ld a, [PlayerStandingMapY]
|
2015-11-30 02:34:59 +00:00
|
|
|
sub 4
|
|
|
|
cp -1
|
|
|
|
jr z, .ok
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.left
|
2016-01-11 07:28:09 +00:00
|
|
|
ld a, [PlayerStandingMapX]
|
2016-05-04 15:46:23 +00:00
|
|
|
sub 4
|
2015-11-30 02:34:59 +00:00
|
|
|
cp -1
|
|
|
|
jr z, .ok
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.right
|
2016-01-11 07:28:09 +00:00
|
|
|
ld a, [PlayerStandingMapX]
|
2015-11-30 02:34:59 +00:00
|
|
|
sub 4
|
|
|
|
ld b, a
|
|
|
|
ld a, [MapWidth]
|
|
|
|
add a
|
|
|
|
cp b
|
|
|
|
jr z, .ok
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.ok
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
GetCoordOfUpperLeftCorner:: ; 10486d
|
|
|
|
ld hl, OverworldMap
|
|
|
|
ld a, [XCoord]
|
|
|
|
bit 0, a
|
|
|
|
jr nz, .increment_then_halve1
|
|
|
|
srl a
|
|
|
|
add $1
|
|
|
|
jr .resume
|
|
|
|
|
|
|
|
.increment_then_halve1
|
|
|
|
add $1
|
|
|
|
srl a
|
|
|
|
|
|
|
|
.resume
|
|
|
|
ld c, a
|
|
|
|
ld b, $0
|
|
|
|
add hl, bc
|
|
|
|
ld a, [MapWidth]
|
|
|
|
add $6
|
|
|
|
ld c, a
|
|
|
|
ld b, $0
|
|
|
|
ld a, [YCoord]
|
|
|
|
bit 0, a
|
|
|
|
jr nz, .increment_then_halve2
|
|
|
|
srl a
|
|
|
|
add $1
|
|
|
|
jr .resume2
|
|
|
|
|
|
|
|
.increment_then_halve2
|
|
|
|
add $1
|
|
|
|
srl a
|
|
|
|
|
|
|
|
.resume2
|
|
|
|
call AddNTimes
|
|
|
|
ld a, l
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, h
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wOverworldMapAnchor + 1], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [YCoord]
|
|
|
|
and $1
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wMetatileStandingY], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ld a, [XCoord]
|
|
|
|
and $1
|
2015-12-14 01:33:56 +00:00
|
|
|
ld [wMetatileStandingX], a
|
2015-11-30 02:34:59 +00:00
|
|
|
ret
|
|
|
|
; 1048ba
|