pokecrystal-board/home/map.asm

2394 lines
33 KiB
NASM
Raw Normal View History

; Functions dealing with rendering and interacting with maps.
Clearwc7e8:: ; 210f
2015-02-10 15:14:41 -08:00
ld hl, wc7e8
2016-01-06 04:44:50 -08:00
ld bc, 24
ld a, $0
call ByteFill
ret
; 211b
CheckTriggers:: ; 211b
; Checks wCurrentMapTriggerPointer. If it's empty, returns -1 in a. Otherwise, returns the active trigger ID in a.
push hl
ld hl, wCurrentMapTriggerPointer
ld a, [hli]
ld h, [hl]
ld l, a
or h
ld a, [hl]
jr nz, .triggerexists
ld a, -1
.triggerexists
pop hl
ret
; 212a
GetCurrentMapTrigger:: ; 212a
; Grabs the wram map trigger pointer for the current map and loads it into wCurrentMapTriggerPointer.
; If there are no triggers, both bytes of wCurrentMapTriggerPointer are wiped clean.
; Copy the current map group and number into bc. This is needed for GetMapTrigger.
ld a, [MapGroup]
ld b, a
ld a, [MapNumber]
ld c, a
; Blank out wCurrentMapTriggerPointer; this is the default scenario.
xor a
ld [wCurrentMapTriggerPointer], a
ld [wCurrentMapTriggerPointer + 1], a
call GetMapTrigger
ret c ; The map is not in the trigger table
; Load the trigger table pointer from de into wCurrentMapTriggerPointer
ld a, e
ld [wCurrentMapTriggerPointer], a
ld a, d
ld [wCurrentMapTriggerPointer + 1], a
xor a
ret
; 2147
GetMapTrigger:: ; 2147
; Searches the trigger table for the map group and number loaded in bc, and returns the wram pointer in de.
; If the map is not in the trigger table, returns carry.
push bc
ld a, [hROMBank]
push af
ld a, BANK(MapTriggers)
rst Bankswitch
ld hl, MapTriggers
.loop
push hl
ld a, [hli] ; map group, or terminator
cp -1
jr z, .end ; the current map is not in the trigger table
cp b
jr nz, .next ; map group did not match
ld a, [hli] ; map number
cp c
jr nz, .next ; map number did not match
jr .found ; we found our map
.next
pop hl
ld de, 4 ; size of an entry in the trigger table
add hl, de
jr .loop
.end
scf
jr .done
.found
ld e, [hl]
inc hl
ld d, [hl]
.done
pop hl
pop bc
ld a, b
rst Bankswitch
pop bc
ret
; 2173
2015-11-11 11:12:46 -08:00
OverworldTextModeSwitch:: ; 2173
2015-11-05 11:06:03 -08:00
call LoadMapPart
call FarCallSwapTextboxPalettes
ret
; 217a
2015-11-05 11:06:03 -08:00
LoadMapPart:: ; 217a
ld a, [hROMBank]
push af
ld a, [TilesetBlocksBank]
rst Bankswitch
2015-11-05 11:06:03 -08:00
call LoadMetatiles
ld a, $60
hlcoord 0, 0
2015-11-02 09:54:27 -08:00
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
2015-12-14 08:12:18 -08:00
ld a, BANK(_LoadMapPart)
rst Bankswitch
2015-12-14 08:12:18 -08:00
call _LoadMapPart
pop af
rst Bankswitch
ret
; 2198
2015-11-05 11:06:03 -08:00
LoadMetatiles:: ; 2198
2015-12-14 08:12:18 -08:00
; de <- wOverworldMapAnchor
2015-12-13 17:33:56 -08:00
ld a, [wOverworldMapAnchor]
ld e, a
2015-12-13 17:33:56 -08:00
ld a, [wOverworldMapAnchor + 1]
ld d, a
2015-11-05 11:06:03 -08:00
ld hl, wMisc
2015-12-14 08:12:18 -08:00
ld b, WMISC_HEIGHT / 4 ; 5
2015-12-14 08:12:18 -08:00
.row
push de
push hl
2015-12-14 08:12:18 -08:00
ld c, WMISC_WIDTH / 4 ; 6
2015-12-14 08:12:18 -08:00
.col
push de
push hl
2015-12-14 08:12:18 -08:00
; Load the current map block.
; If the current map block is a border block, load the border block.
ld a, [de]
and a
2015-11-05 11:06:03 -08:00
jr nz, .ok
ld a, [MapBorderBlock]
2015-11-05 11:06:03 -08:00
.ok
2015-12-14 08:12:18 -08:00
; Load the current wMisc address into de.
ld e, l
ld d, h
2015-12-14 08:12:18 -08:00
; Set hl to the address of the current metatile data ([TilesetBlocksAddress] + (a) tiles).
2017-12-12 20:05:30 -08:00
; This is buggy; it wraps around past 128 blocks.
; To fix, uncomment the line below.
add a ; Comment or delete this line to fix the above bug.
ld l, a
ld h, 0
2017-12-12 20:05:30 -08:00
; add hl, hl
2015-12-14 08:12:18 -08:00
add hl, hl
add hl, hl
add hl, hl
ld a, [TilesetBlocksAddress]
add l
ld l, a
ld a, [TilesetBlocksAddress + 1]
adc h
ld h, a
2015-12-14 08:12:18 -08:00
; copy the 4x4 metatile
rept 3
rept 4
ld a, [hli]
ld [de], a
inc de
endr
ld a, e
2015-12-14 08:12:18 -08:00
add WMISC_WIDTH - 4
ld e, a
jr nc, .next\@
inc d
.next\@
endr
rept 4
ld a, [hli]
ld [de], a
inc de
endr
2015-12-14 08:12:18 -08:00
; Next metatile
pop hl
2015-11-05 11:06:03 -08:00
ld de, 4
add hl, de
pop de
inc de
dec c
2015-12-14 08:12:18 -08:00
jp nz, .col
; Next metarow
pop hl
2015-12-14 08:12:18 -08:00
ld de, WMISC_WIDTH * 4
add hl, de
pop de
ld a, [MapWidth]
2015-11-05 11:06:03 -08:00
add 6
add e
ld e, a
2015-11-05 11:06:03 -08:00
jr nc, .ok2
inc d
2015-11-05 11:06:03 -08:00
.ok2
dec b
2015-12-14 08:12:18 -08:00
jp nz, .row
ret
; 222a
2015-11-11 20:38:57 -08:00
ReturnToMapFromSubmenu:: ; 222a
ld a, MAPSETUP_SUBMENU
ld [hMapEntryMethod], a
2014-01-26 19:07:19 -08:00
callba RunMapSetupScript
xor a
ld [hMapEntryMethod], a
ret
; 2238
2015-10-24 16:49:19 -07:00
CheckWarpTile:: ; 2238
2015-11-12 08:10:19 -08:00
call GetDestinationWarpNumber
ret nc
2015-11-12 08:10:19 -08:00
push bc
2015-12-14 08:12:18 -08:00
callba CheckDirectionalWarp
pop bc
ret nc
2015-11-12 08:10:19 -08:00
call CopyWarpData
scf
ret
; 224a
2015-11-12 08:10:19 -08:00
WarpCheck:: ; 224a
call GetDestinationWarpNumber
ret nc
2015-11-12 08:10:19 -08:00
call CopyWarpData
ret
; 2252
2015-11-12 08:10:19 -08:00
GetDestinationWarpNumber:: ; 2252
2015-12-14 08:12:18 -08:00
callba CheckWarpCollision
ret nc
ld a, [hROMBank]
push af
call SwitchToMapScriptHeaderBank
2015-11-12 08:10:19 -08:00
call .GetDestinationWarpNumber
pop de
ld a, d
rst Bankswitch
ret
; 2266
.GetDestinationWarpNumber: ; 2266
ld a, [PlayerStandingMapY]
sub $4
ld e, a
ld a, [PlayerStandingMapX]
sub $4
ld d, a
2015-10-24 16:49:19 -07:00
ld a, [wCurrMapWarpCount]
and a
ret z
2015-11-12 08:10:19 -08:00
ld c, a
2015-10-24 16:49:19 -07:00
ld hl, wCurrMapWarpHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
2015-11-12 08:10:19 -08:00
.loop
push hl
ld a, [hli]
cp e
2015-11-12 08:10:19 -08:00
jr nz, .next
ld a, [hli]
cp d
2015-11-12 08:10:19 -08:00
jr nz, .next
jr .found_warp
2015-11-12 08:10:19 -08:00
.next
pop hl
2015-11-12 08:10:19 -08:00
ld a, 5
add l
ld l, a
2015-11-12 08:10:19 -08:00
jr nc, .okay
inc h
2015-11-12 08:10:19 -08:00
.okay
dec c
2015-11-12 08:10:19 -08:00
jr nz, .loop
xor a
ret
2015-11-12 08:10:19 -08:00
.found_warp
pop hl
2015-11-12 08:10:19 -08:00
call .IncreaseHLTwice
ret nc ; never encountered
2015-10-24 16:49:19 -07:00
ld a, [wCurrMapWarpCount]
inc a
sub c
ld c, a
scf
ret
.IncreaseHLTwice:
inc hl
2016-01-06 04:44:50 -08:00
inc hl
scf
ret
; 22a7
2015-11-12 08:10:19 -08:00
CopyWarpData:: ; 22a7
ld a, [hROMBank]
push af
call SwitchToMapScriptHeaderBank
2015-11-12 08:10:19 -08:00
call .CopyWarpData
pop af
rst Bankswitch
scf
ret
; 22b4
.CopyWarpData: ; 22b4
push bc
2015-10-24 16:49:19 -07:00
ld hl, wCurrMapWarpHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
ld a, c
dec a
2015-11-12 08:10:19 -08:00
ld bc, 5 ; warp size
call AddNTimes
2015-11-12 08:10:19 -08:00
ld bc, 2 ; warp number
add hl, bc
ld a, [hli]
cp $ff
2015-11-12 08:10:19 -08:00
jr nz, .skip
ld hl, BackupWarpNumber
ld a, [hli]
2015-11-12 08:10:19 -08:00
.skip
pop bc
2015-11-12 08:10:19 -08:00
ld [wNextWarp], a
ld a, [hli]
2015-11-12 08:10:19 -08:00
ld [wNextMapGroup], a
ld a, [hli]
2015-11-12 08:10:19 -08:00
ld [wNextMapNumber], a
ld a, c
2015-11-12 08:10:19 -08:00
ld [wPrevWarp], a
ld a, [MapGroup]
2015-11-12 08:10:19 -08:00
ld [wPrevMapGroup], a
ld a, [MapNumber]
2015-11-12 08:10:19 -08:00
ld [wPrevMapNumber], a
scf
ret
; 22ee
CheckOutdoorMap:: ; 22ee
cp ROUTE
ret z
cp TOWN
ret
; 22f4
CheckIndoorMap:: ; 22f4
cp INDOOR
ret z
cp CAVE
ret z
cp DUNGEON
ret z
cp GATE
ret
; 2300
2016-01-12 09:46:18 -08:00
; XXX
cp INDOOR
ret z
cp GATE
ret z
2015-11-12 08:10:19 -08:00
cp PERM_5
ret
; 2309
LoadMapAttributes:: ; 2309
2015-11-12 08:10:19 -08:00
call CopyMapHeaders
call SwitchToMapScriptHeaderBank
2015-11-12 08:10:19 -08:00
call ReadMapScripts
xor a
2015-07-26 00:11:33 -07:00
call ReadMapEventHeader
ret
; 2317
2015-11-12 08:10:19 -08:00
LoadMapAttributes_SkipPeople:: ; 2317
call CopyMapHeaders
call SwitchToMapScriptHeaderBank
2015-11-12 08:10:19 -08:00
call ReadMapScripts
ld a, $1
2015-07-26 00:11:33 -07:00
call ReadMapEventHeader
ret
; 2326
2015-11-12 08:10:19 -08:00
CopyMapHeaders:: ; 2326
call PartiallyCopyMapHeader
call SwitchToMapBank
call GetSecondaryMapHeaderPointer
2015-11-12 08:10:19 -08:00
call CopySecondMapHeader
call GetMapConnections
ret
; 2336
2015-07-26 00:11:33 -07:00
ReadMapEventHeader:: ; 2336
push af
ld hl, MapEventHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
2016-01-06 04:44:50 -08:00
inc hl
2015-07-26 00:11:33 -07:00
call ReadWarps
call ReadCoordEvents
call ReadSignposts
2015-11-12 08:10:19 -08:00
pop af
and a
ret nz
2015-11-12 08:10:19 -08:00
2015-07-26 00:11:33 -07:00
call ReadObjectEvents
ret
; 234f
2015-11-12 08:10:19 -08:00
ReadMapScripts:: ; 234f
ld hl, MapScriptHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
2015-10-24 16:49:19 -07:00
call ReadMapTriggers
call ReadMapCallbacks
ret
; 235c
2015-11-12 08:10:19 -08:00
CopySecondMapHeader:: ; 235c
ld de, MapHeader
2015-11-12 08:10:19 -08:00
ld c, 12 ; size of the second map header
.loop
ld a, [hli]
ld [de], a
inc de
dec c
2015-11-12 08:10:19 -08:00
jr nz, .loop
ret
; 2368
2015-11-12 08:10:19 -08:00
GetMapConnections:: ; 2368
ld a, $ff
ld [NorthConnectedMapGroup], a
ld [SouthConnectedMapGroup], a
ld [WestConnectedMapGroup], a
ld [EastConnectedMapGroup], a
ld a, [MapConnections]
ld b, a
2015-11-12 08:10:19 -08:00
bit NORTH_F, b
jr z, .no_north
ld de, NorthMapConnection
call GetMapConnection
2015-11-12 08:10:19 -08:00
.no_north
2015-11-12 08:10:19 -08:00
bit SOUTH_F, b
jr z, .no_south
ld de, SouthMapConnection
call GetMapConnection
2015-11-12 08:10:19 -08:00
.no_south
2015-11-12 08:10:19 -08:00
bit WEST_F, b
jr z, .no_west
ld de, WestMapConnection
call GetMapConnection
2015-11-12 08:10:19 -08:00
.no_west
2015-11-12 08:10:19 -08:00
bit EAST_F, b
jr z, .no_east
ld de, EastMapConnection
call GetMapConnection
2015-11-12 08:10:19 -08:00
.no_east
ret
; 23a3
GetMapConnection:: ; 23a3
; Load map connection struct at hl into de.
ld c, SouthMapConnection - NorthMapConnection
.loop
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop
ret
; 23ac
2015-10-24 16:49:19 -07:00
ReadMapTriggers:: ; 23ac
2015-10-24 07:34:19 -07:00
ld a, [hli] ; trigger count
ld c, a
2015-10-24 16:49:19 -07:00
ld [wCurrMapTriggerCount], a ; current map trigger count
ld a, l
2015-10-24 16:49:19 -07:00
ld [wCurrMapTriggerHeaderPointer], a ; map trigger pointer
ld a, h
2015-12-15 07:55:56 -08:00
ld [wCurrMapTriggerHeaderPointer + 1], a
ld a, c
and a
ret z
2015-10-24 07:34:19 -07:00
ld bc, 4 ; size of a map trigger header entry
call AddNTimes
ret
; 23c3
2015-10-24 16:49:19 -07:00
ReadMapCallbacks:: ; 23c3
ld a, [hli]
ld c, a
2015-10-24 16:49:19 -07:00
ld [wCurrMapCallbackCount], a
ld a, l
2015-10-24 16:49:19 -07:00
ld [wCurrMapCallbackHeaderPointer], a
ld a, h
2015-10-24 16:49:19 -07:00
ld [wCurrMapCallbackHeaderPointer + 1], a
ld a, c
and a
ret z
2015-10-24 07:34:19 -07:00
ld bc, 3
call AddNTimes
ret
; 23da
2015-07-26 00:11:33 -07:00
ReadWarps:: ; 23da
ld a, [hli]
ld c, a
2015-10-24 16:49:19 -07:00
ld [wCurrMapWarpCount], a
ld a, l
2015-10-24 16:49:19 -07:00
ld [wCurrMapWarpHeaderPointer], a
ld a, h
2016-01-12 09:46:18 -08:00
ld [wCurrMapWarpHeaderPointer + 1], a
ld a, c
and a
ret z
2016-01-12 09:46:18 -08:00
ld bc, 5
call AddNTimes
ret
; 23f1
2015-07-26 00:11:33 -07:00
ReadCoordEvents:: ; 23f1
ld a, [hli]
ld c, a
2016-01-06 04:44:50 -08:00
ld [wCurrentMapXYTriggerCount], a
ld a, l
2016-01-06 04:44:50 -08:00
ld [wCurrentMapXYTriggerHeaderPointer], a
ld a, h
2016-01-06 04:44:50 -08:00
ld [wCurrentMapXYTriggerHeaderPointer + 1], a
2015-11-12 08:10:19 -08:00
ld a, c
and a
ret z
2015-11-12 08:10:19 -08:00
ld bc, 8
call AddNTimes
ret
; 2408
2015-07-26 00:11:33 -07:00
ReadSignposts:: ; 2408
ld a, [hli]
ld c, a
ld [wCurrentMapSignpostCount], a
ld a, l
2015-11-12 08:10:19 -08:00
ld [wCurrentMapSignpostHeaderPointer], a
ld a, h
2015-11-12 08:10:19 -08:00
ld [wCurrentMapSignpostHeaderPointer + 1], a
ld a, c
and a
ret z
2015-11-12 08:10:19 -08:00
ld bc, 5
call AddNTimes
ret
; 241f
2015-07-26 00:11:33 -07:00
ReadObjectEvents:: ; 241f
push hl
2015-11-12 08:10:19 -08:00
call ClearObjectStructs
pop de
2015-11-12 08:10:19 -08:00
ld hl, Map1Object
ld a, [de]
inc de
2015-11-12 08:10:19 -08:00
ld [wCurrentMapPersonEventCount], a
ld a, e
2015-11-12 08:10:19 -08:00
ld [wCurrentMapPersonEventHeaderPointer], a
ld a, d
2015-11-12 08:10:19 -08:00
ld [wCurrentMapPersonEventHeaderPointer + 1], a
ld a, [wCurrentMapPersonEventCount]
call CopyMapObjectHeaders
; get NUM_OBJECTS - [wCurrentMapPersonEventCount]
ld a, [wCurrentMapPersonEventCount]
ld c, a
2015-11-12 08:10:19 -08:00
ld a, NUM_OBJECTS ; - 1
sub c
2015-11-12 08:10:19 -08:00
jr z, .skip
; jr c, .skip
; stupid waste of time and space
ld bc, 1
add hl, bc
2015-11-12 08:10:19 -08:00
; Fill the remaining sprite IDs and y coords with 0 and -1, respectively.
; Bleeds into wObjectMasks due to a bug. Uncomment the above subtraction
; to fix.
ld bc, OBJECT_LENGTH
.loop
ld [hl], 0
inc hl
2015-11-12 08:10:19 -08:00
ld [hl], -1
dec hl
add hl, bc
dec a
2015-11-12 08:10:19 -08:00
jr nz, .loop
2015-11-12 08:10:19 -08:00
.skip
ld h, d
ld l, e
ret
; 2457
2015-11-12 08:10:19 -08:00
CopyMapObjectHeaders:: ; 2457
and a
ret z
2015-11-12 08:10:19 -08:00
ld c, a
2015-11-12 08:10:19 -08:00
.loop
push bc
push hl
ld a, $ff
ld [hli], a
2015-11-12 08:10:19 -08:00
ld b, MAPOBJECT_E - MAPOBJECT_SPRITE
.loop2
ld a, [de]
inc de
ld [hli], a
dec b
2015-11-12 08:10:19 -08:00
jr nz, .loop2
pop hl
2015-11-12 08:10:19 -08:00
ld bc, OBJECT_LENGTH
add hl, bc
pop bc
dec c
2015-11-12 08:10:19 -08:00
jr nz, .loop
ret
; 2471
2015-11-12 08:10:19 -08:00
ClearObjectStructs:: ; 2471
2015-11-02 08:15:32 -08:00
ld hl, Object1Struct
2015-07-26 00:11:33 -07:00
ld bc, OBJECT_STRUCT_LENGTH * (NUM_OBJECT_STRUCTS - 1)
xor a
call ByteFill
2015-11-12 08:10:19 -08:00
; Just to make sure (this is rather pointless)
2015-11-02 08:15:32 -08:00
ld hl, Object1Struct
2015-07-26 00:11:33 -07:00
ld de, OBJECT_STRUCT_LENGTH
ld c, NUM_OBJECT_STRUCTS - 1
xor a
2015-11-12 08:10:19 -08:00
.loop
ld [hl], a
add hl, de
dec c
2015-11-12 08:10:19 -08:00
jr nz, .loop
ret
; 248a
RestoreFacingAfterWarp:: ; 248a
call GetMapScriptHeaderBank
rst Bankswitch
ld hl, MapEventHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
2015-11-12 08:10:19 -08:00
inc hl ; get to the warp coords
inc hl ; get to the warp coords
inc hl ; get to the warp coords
ld a, [WarpNumber]
dec a
ld c, a
2015-11-12 08:10:19 -08:00
ld b, 0
ld a, 5
call AddNTimes
ld a, [hli]
ld [YCoord], a
ld a, [hli]
ld [XCoord], a
2015-11-12 08:10:19 -08:00
; destination warp number
ld a, [hli]
cp $ff
2015-11-12 08:10:19 -08:00
jr nz, .skip
call .backup
2015-11-12 08:10:19 -08:00
.skip
callba GetCoordOfUpperLeftCorner
ret
; 24ba
2015-11-12 08:10:19 -08:00
.backup
ld a, [wPrevWarp]
ld [BackupWarpNumber], a
ld a, [wPrevMapGroup]
ld [BackupMapGroup], a
2015-11-12 08:10:19 -08:00
ld a, [wPrevMapNumber]
ld [BackupMapNumber], a
ret
; 24cd
LoadBlockData:: ; 24cd
ld hl, OverworldMap
ld bc, OverworldMapEnd - OverworldMap
ld a, 0
call ByteFill
call ChangeMap
call FillMapConnections
2016-01-06 04:44:50 -08:00
ld a, MAPCALLBACK_TILES
call RunMapCallback
ret
; 24e4
ChangeMap:: ; 24e4
ld a, [hROMBank]
push af
ld hl, OverworldMap
ld a, [MapWidth]
2015-11-02 09:54:27 -08:00
ld [hConnectedMapWidth], a
add $6
2015-11-02 09:54:27 -08:00
ld [hConnectionStripLength], a
ld c, a
ld b, 0
add hl, bc
add hl, bc
add hl, bc
ld c, 3
add hl, bc
ld a, [MapBlockDataBank]
rst Bankswitch
ld a, [MapBlockDataPointer]
ld e, a
ld a, [MapBlockDataPointer+1]
ld d, a
ld a, [MapHeight]
ld b, a
2016-01-12 09:46:18 -08:00
.row
push hl
2015-11-02 09:54:27 -08:00
ld a, [hConnectedMapWidth]
ld c, a
2016-01-12 09:46:18 -08:00
.col
ld a, [de]
inc de
ld [hli], a
dec c
2016-01-12 09:46:18 -08:00
jr nz, .col
pop hl
2015-11-02 09:54:27 -08:00
ld a, [hConnectionStripLength]
add l
ld l, a
2016-01-12 09:46:18 -08:00
jr nc, .okay
inc h
2016-01-12 09:46:18 -08:00
.okay
dec b
2016-01-12 09:46:18 -08:00
jr nz, .row
pop af
rst Bankswitch
ret
; 2524
FillMapConnections:: ; 2524
; North
ld a, [NorthConnectedMapGroup]
cp $ff
jr z, .South
ld b, a
ld a, [NorthConnectedMapNumber]
ld c, a
call GetAnyMapBlockdataBank
ld a, [NorthConnectionStripPointer]
ld l, a
ld a, [NorthConnectionStripPointer + 1]
ld h, a
ld a, [NorthConnectionStripLocation]
ld e, a
ld a, [NorthConnectionStripLocation + 1]
ld d, a
2015-11-02 09:54:27 -08:00
ld a, [NorthConnectionStripLength]
ld [hConnectionStripLength], a
ld a, [NorthConnectedMapWidth]
ld [hConnectedMapWidth], a
call FillNorthConnectionStrip
.South:
ld a, [SouthConnectedMapGroup]
cp $ff
jr z, .West
ld b, a
ld a, [SouthConnectedMapNumber]
ld c, a
call GetAnyMapBlockdataBank
ld a, [SouthConnectionStripPointer]
ld l, a
ld a, [SouthConnectionStripPointer + 1]
ld h, a
ld a, [SouthConnectionStripLocation]
ld e, a
ld a, [SouthConnectionStripLocation + 1]
ld d, a
2015-11-02 09:54:27 -08:00
ld a, [SouthConnectionStripLength]
ld [hConnectionStripLength], a
ld a, [SouthConnectedMapWidth]
ld [hConnectedMapWidth], a
call FillSouthConnectionStrip
.West:
ld a, [WestConnectedMapGroup]
cp $ff
jr z, .East
ld b, a
ld a, [WestConnectedMapNumber]
ld c, a
call GetAnyMapBlockdataBank
ld a, [WestConnectionStripPointer]
ld l, a
ld a, [WestConnectionStripPointer + 1]
ld h, a
ld a, [WestConnectionStripLocation]
ld e, a
ld a, [WestConnectionStripLocation + 1]
ld d, a
ld a, [WestConnectionStripLength]
ld b, a
ld a, [WestConnectedMapWidth]
2015-11-02 09:54:27 -08:00
ld [hConnectionStripLength], a
call FillWestConnectionStrip
.East:
ld a, [EastConnectedMapGroup]
cp $ff
jr z, .Done
ld b, a
ld a, [EastConnectedMapNumber]
ld c, a
call GetAnyMapBlockdataBank
ld a, [EastConnectionStripPointer]
ld l, a
ld a, [EastConnectionStripPointer + 1]
ld h, a
ld a, [EastConnectionStripLocation]
ld e, a
ld a, [EastConnectionStripLocation + 1]
ld d, a
ld a, [EastConnectionStripLength]
ld b, a
ld a, [EastConnectedMapWidth]
2015-11-02 09:54:27 -08:00
ld [hConnectionStripLength], a
call FillEastConnectionStrip
.Done:
ret
; 25d3
FillNorthConnectionStrip::
FillSouthConnectionStrip:: ; 25d3
ld c, 3
.y
push de
push hl
2015-11-02 09:54:27 -08:00
ld a, [hConnectionStripLength]
ld b, a
.x
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .x
pop hl
2015-11-02 09:54:27 -08:00
ld a, [hConnectedMapWidth]
ld e, a
ld d, 0
add hl, de
pop de
ld a, [MapWidth]
add 6
add e
ld e, a
2016-01-12 09:46:18 -08:00
jr nc, .okay
inc d
2016-01-12 09:46:18 -08:00
.okay
dec c
jr nz, .y
ret
; 25f6
FillWestConnectionStrip::
FillEastConnectionStrip:: ; 25f6
2016-01-12 09:46:18 -08:00
.loop
ld a, [MapWidth]
add 6
2015-11-02 09:54:27 -08:00
ld [hConnectedMapWidth], a
push de
push hl
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
inc de
pop hl
2015-11-02 09:54:27 -08:00
ld a, [hConnectionStripLength]
ld e, a
ld d, 0
add hl, de
pop de
2015-11-02 09:54:27 -08:00
ld a, [hConnectedMapWidth]
add e
ld e, a
2016-01-12 09:46:18 -08:00
jr nc, .okay
inc d
2016-01-12 09:46:18 -08:00
.okay
dec b
2016-01-12 09:46:18 -08:00
jr nz, .loop
ret
; 261b
LoadMapStatus:: ; 261b
2015-02-10 15:14:41 -08:00
ld [MapStatus], a
ret
; 261f
CallScript:: ; 261f
; Call a script at a:hl.
ld [ScriptBank], a
ld a, l
ld [ScriptPos], a
ld a, h
ld [ScriptPos + 1], a
2015-11-05 12:08:00 -08:00
ld a, PLAYEREVENT_MAPSCRIPT
ld [ScriptRunning], a
scf
ret
; 2631
2015-11-05 12:08:00 -08:00
CallMapScript:: ; 2631
; Call a script at hl in the current bank if there isn't already a script running
ld a, [ScriptRunning]
and a
ret nz
call GetMapScriptHeaderBank
jr CallScript
; 263b
RunMapCallback:: ; 263b
; Will run the first callback found in the map header with execution index equal to a.
ld b, a
ld a, [hROMBank]
push af
call SwitchToMapScriptHeaderBank
2015-11-05 12:08:00 -08:00
call .FindCallback
jr nc, .done
call GetMapScriptHeaderBank
ld b, a
ld d, h
ld e, l
call ExecuteCallbackScript
.done
pop af
rst Bankswitch
ret
; 2653
2015-11-05 12:08:00 -08:00
.FindCallback: ; 2653
2015-10-24 16:49:19 -07:00
ld a, [wCurrMapCallbackCount]
ld c, a
and a
ret z
2015-10-24 16:49:19 -07:00
ld hl, wCurrMapCallbackHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
or h
ret z
ld de, 3
.loop
ld a, [hl]
cp b
2015-11-05 12:08:00 -08:00
jr z, .found
add hl, de
dec c
jr nz, .loop
xor a
ret
2015-11-05 12:08:00 -08:00
.found
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
scf
ret
; 2674
ExecuteCallbackScript:: ; 2674
2015-11-05 12:08:00 -08:00
; Do map callback de and return to script bank b.
callba CallCallback
ld a, [ScriptMode]
push af
ld hl, ScriptFlags
ld a, [hl]
push af
set 1, [hl]
callba EnableScriptMode
callba ScriptEvents
pop af
ld [ScriptFlags], a
pop af
ld [ScriptMode], a
ret
; 269a
MapTextbox:: ; 269a
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
push hl
call SpeechTextBox
call SafeUpdateSprites
ld a, 1
ld [hOAMUpdate], a
2015-11-25 07:16:29 -08:00
call ApplyTilemap
pop hl
call PrintTextBoxText
xor a
ld [hOAMUpdate], a
pop af
rst Bankswitch
ret
; 26b7
Call_a_de:: ; 26b7
; Call a:de.
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call .de
pop af
rst Bankswitch
ret
.de
push de
ret
; 26c7
GetMovementData:: ; 26c7
2015-11-11 20:38:57 -08:00
; Initialize the movement data for person c at b:hl
ld a, [hROMBank]
push af
ld a, b
rst Bankswitch
ld a, c
2015-11-11 20:38:57 -08:00
call LoadMovementDataPointer
pop hl
ld a, h
rst Bankswitch
ret
; 26d4
GetScriptByte:: ; 0x26d4
; Return byte at ScriptBank:ScriptPos in a.
push hl
push bc
ld a, [hROMBank]
push af
ld a, [ScriptBank]
rst Bankswitch
ld hl, ScriptPos
ld c, [hl]
inc hl
ld b, [hl]
ld a, [bc]
inc bc
ld [hl], b
dec hl
ld [hl], c
ld b, a
pop af
rst Bankswitch
ld a, b
pop bc
pop hl
ret
; 0x26ef
ObjectEvent:: ; 0x26ef
jumptextfaceplayer ObjectEventText
; 0x26f2
ObjectEventText::
text_jump _ObjectEventText
db "@"
; 0x26f7
BGEvent:: ; 26f7
jumptext BGEventText
; 26fa
BGEventText:: ; 26fa
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c46fc
db "@"
; 26ff
CoordinatesEvent:: ; 26ff
jumptext CoordinatesEventText
; 2702
CoordinatesEventText:: ; 2702
2013-12-01 14:54:09 -08:00
text_jump UnknownText_0x1c4706
db "@"
; 2707
2015-11-01 18:17:46 -08:00
CheckObjectMask:: ; 2707
2015-11-02 08:15:32 -08:00
ld a, [hMapObjectIndexBuffer]
ld e, a
ld d, $0
2015-11-01 18:17:46 -08:00
ld hl, wObjectMasks
add hl, de
ld a, [hl]
ret
; 2712
2015-11-01 18:17:46 -08:00
MaskObject:: ; 2712
2015-11-02 08:15:32 -08:00
ld a, [hMapObjectIndexBuffer]
ld e, a
ld d, $0
2015-11-01 18:17:46 -08:00
ld hl, wObjectMasks
add hl, de
2016-01-06 04:44:50 -08:00
ld [hl], -1 ; , masked
ret
; 271e
2015-11-01 18:17:46 -08:00
UnmaskObject:: ; 271e
2015-11-02 08:15:32 -08:00
ld a, [hMapObjectIndexBuffer]
ld e, a
ld d, $0
2015-11-01 18:17:46 -08:00
ld hl, wObjectMasks
add hl, de
2015-11-01 18:17:46 -08:00
ld [hl], 0 ; unmasked
ret
; 272a
2015-11-12 21:49:27 -08:00
ScrollMapDown:: ; 272a
hlcoord 0, 0
ld de, BGMapBuffer
2015-11-12 21:49:27 -08:00
call BackupBGMapRow
ld c, 2 * SCREEN_WIDTH
call FarCallScrollBGMapPalettes
ld a, [wBGMapAnchor]
ld e, a
ld a, [wBGMapAnchor + 1]
ld d, a
2015-11-12 21:49:27 -08:00
call UpdateBGMapRow
ld a, $1
ld [hBGMapUpdate], a
ret
; 2748
2015-11-12 21:49:27 -08:00
ScrollMapUp:: ; 2748
hlcoord 0, SCREEN_HEIGHT - 2
ld de, BGMapBuffer
2015-11-12 21:49:27 -08:00
call BackupBGMapRow
ld c, 2 * SCREEN_WIDTH
call FarCallScrollBGMapPalettes
ld a, [wBGMapAnchor]
ld l, a
ld a, [wBGMapAnchor + 1]
ld h, a
ld bc, $0200
add hl, bc
2015-11-12 21:49:27 -08:00
; cap d at VBGMap1 / $100
ld a, h
2015-11-12 21:49:27 -08:00
and %00000011
or VBGMap0 / $100
ld e, l
ld d, a
2015-11-12 21:49:27 -08:00
call UpdateBGMapRow
ld a, $1
ld [hBGMapUpdate], a
ret
; 2771
2015-12-13 17:33:56 -08:00
ScrollMapRight:: ; 2771
hlcoord 0, 0
ld de, BGMapBuffer
2015-11-12 21:49:27 -08:00
call BackupBGMapColumn
ld c, 2 * SCREEN_HEIGHT
call FarCallScrollBGMapPalettes
ld a, [wBGMapAnchor]
ld e, a
ld a, [wBGMapAnchor + 1]
ld d, a
2015-11-12 21:49:27 -08:00
call UpdateBGMapColumn
ld a, $1
ld [hBGMapUpdate], a
ret
; 278f
2015-12-13 17:33:56 -08:00
ScrollMapLeft:: ; 278f
2015-11-12 21:49:27 -08:00
hlcoord SCREEN_WIDTH - 2, 0
ld de, BGMapBuffer
2015-11-12 21:49:27 -08:00
call BackupBGMapColumn
ld c, 2 * SCREEN_HEIGHT
call FarCallScrollBGMapPalettes
ld a, [wBGMapAnchor]
ld e, a
2015-11-12 21:49:27 -08:00
and %11100000
ld b, a
ld a, e
2015-11-12 21:49:27 -08:00
add SCREEN_HEIGHT
and %00011111
or b
ld e, a
ld a, [wBGMapAnchor + 1]
ld d, a
2015-11-12 21:49:27 -08:00
call UpdateBGMapColumn
ld a, $1
ld [hBGMapUpdate], a
ret
; 27b7
2015-11-12 21:49:27 -08:00
BackupBGMapRow:: ; 27b7
ld c, 2 * SCREEN_WIDTH
.loop
ld a, [hli]
ld [de], a
inc de
dec c
2015-11-12 21:49:27 -08:00
jr nz, .loop
ret
; 27c0
2015-11-12 21:49:27 -08:00
BackupBGMapColumn:: ; 27c0
ld c, SCREEN_HEIGHT
.loop
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
inc de
2015-11-12 21:49:27 -08:00
ld a, SCREEN_WIDTH - 1
add l
ld l, a
2015-11-12 21:49:27 -08:00
jr nc, .skip
inc h
2015-11-12 21:49:27 -08:00
.skip
dec c
2015-11-12 21:49:27 -08:00
jr nz, .loop
ret
; 27d3
2015-11-12 21:49:27 -08:00
UpdateBGMapRow:: ; 27d3
ld hl, BGMapBufferPtrs
push de
2015-11-12 21:49:27 -08:00
call .iteration
pop de
ld a, $20
add e
ld e, a
2015-11-12 21:49:27 -08:00
.iteration
ld c, 10
.loop
ld a, e
ld [hli], a
ld a, d
ld [hli], a
ld a, e
inc a
2016-01-06 04:44:50 -08:00
inc a
and $1f
ld b, a
ld a, e
and $e0
or b
ld e, a
dec c
2015-11-12 21:49:27 -08:00
jr nz, .loop
ld a, SCREEN_WIDTH
ld [hFFDC], a
ret
; 27f8
2015-11-12 21:49:27 -08:00
UpdateBGMapColumn:: ; 27f8
ld hl, BGMapBufferPtrs
2015-11-12 21:49:27 -08:00
ld c, SCREEN_HEIGHT
.loop
ld a, e
ld [hli], a
ld a, d
ld [hli], a
ld a, $20
add e
ld e, a
2015-11-12 21:49:27 -08:00
jr nc, .skip
inc d
2015-11-12 21:49:27 -08:00
; cap d at VBGMap1 / $100
ld a, d
and $3
2015-11-12 21:49:27 -08:00
or VBGMap0 / $100
ld d, a
2015-11-12 21:49:27 -08:00
.skip
dec c
2015-11-12 21:49:27 -08:00
jr nz, .loop
ld a, SCREEN_HEIGHT
ld [hFFDC], a
ret
; 2816
2015-11-12 21:49:27 -08:00
; unreferenced
ld hl, BGMapBuffer
2016-06-06 15:23:00 -07:00
ld bc, BGMapBufferEnd - BGMapBuffer
xor a
call ByteFill
ret
; 2821
2015-11-12 21:49:27 -08:00
LoadTileset:: ; 2821
ld hl, TilesetAddress
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [TilesetBank]
ld e, a
2015-11-12 21:49:27 -08:00
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
2015-11-12 21:49:27 -08:00
ld a, e
ld de, wDecompressScratch
call FarDecompress
2015-11-12 21:49:27 -08:00
ld hl, wDecompressScratch
ld de, VTiles2
2015-11-05 16:13:09 -08:00
ld bc, $60 tiles
call CopyBytes
2015-11-12 21:49:27 -08:00
ld a, [rVBK]
push af
ld a, $1
ld [rVBK], a
2015-11-12 21:49:27 -08:00
2017-12-09 11:22:58 -08:00
ld hl, wDecompressScratch + $60 tiles
ld de, VTiles2
2015-11-05 16:13:09 -08:00
ld bc, $60 tiles
call CopyBytes
2015-11-12 21:49:27 -08:00
pop af
ld [rVBK], a
2015-11-12 21:49:27 -08:00
pop af
ld [rSVBK], a
2015-11-12 21:49:27 -08:00
ld a, [wTileset]
cp TILESET_JOHTO_1
jr z, .load_roof
cp TILESET_JOHTO_2
jr z, .load_roof
cp TILESET_BATTLE_TOWER_OUTSIDE
jr z, .load_roof
jr .skip_roof
.load_roof
2013-10-10 23:31:51 -07:00
callba LoadMapGroupRoof
2015-11-12 21:49:27 -08:00
.skip_roof
xor a
ld [hTileAnimFrame], a
ret
; 2879
BufferScreen:: ; 2879
2015-12-13 17:33:56 -08:00
ld hl, wOverworldMapAnchor
ld a, [hli]
ld h, [hl]
ld l, a
2015-12-14 08:12:18 -08:00
ld de, wScreenSave
ld c, $5
ld b, $6
2016-01-12 09:46:18 -08:00
.row
push bc
push hl
2016-01-12 09:46:18 -08:00
.col
ld a, [hli]
ld [de], a
inc de
dec b
2016-01-12 09:46:18 -08:00
jr nz, .col
pop hl
ld a, [MapWidth]
add $6
ld c, a
ld b, $0
add hl, bc
pop bc
dec c
2016-01-12 09:46:18 -08:00
jr nz, .row
ret
; 289d
SaveScreen:: ; 289d
2015-12-13 17:33:56 -08:00
ld hl, wOverworldMapAnchor
ld a, [hli]
ld h, [hl]
ld l, a
2015-12-14 08:12:18 -08:00
ld de, wScreenSave
ld a, [MapWidth]
2015-12-14 08:12:18 -08:00
add 6
2015-11-02 08:15:32 -08:00
ld [hMapObjectIndexBuffer], a
ld a, [wPlayerStepDirection]
and a
2015-11-12 21:49:27 -08:00
jr z, .down
cp UP
jr z, .up
cp LEFT
jr z, .left
cp RIGHT
jr z, .right
ret
2015-11-12 21:49:27 -08:00
.up
2015-12-14 08:12:18 -08:00
ld de, wScreenSave + 6
2015-11-02 08:15:32 -08:00
ld a, [hMapObjectIndexBuffer]
ld c, a
ld b, $0
add hl, bc
2015-11-12 21:49:27 -08:00
jr .vertical
2015-11-12 21:49:27 -08:00
.down
2015-12-14 08:12:18 -08:00
ld de, wScreenSave
2015-11-12 21:49:27 -08:00
.vertical
2015-12-14 08:12:18 -08:00
ld b, 6
ld c, 4
jr SaveScreen_LoadNeighbor
2015-11-12 21:49:27 -08:00
.left
2015-12-14 08:12:18 -08:00
ld de, wScreenSave + 1
inc hl
2015-11-12 21:49:27 -08:00
jr .horizontal
2015-11-12 21:49:27 -08:00
.right
2015-12-14 08:12:18 -08:00
ld de, wScreenSave
2015-11-12 21:49:27 -08:00
.horizontal
2015-12-14 08:12:18 -08:00
ld b, 5
ld c, 5
jr SaveScreen_LoadNeighbor
2014-01-26 19:07:19 -08:00
LoadNeighboringBlockData:: ; 28e3
2015-12-13 17:33:56 -08:00
ld hl, wOverworldMapAnchor
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [MapWidth]
2015-12-14 08:12:18 -08:00
add 6
2015-11-12 21:49:27 -08:00
ld [hConnectionStripLength], a
2015-12-14 08:12:18 -08:00
ld de, wScreenSave
ld b, 6
ld c, 5
2015-12-14 08:12:18 -08:00
SaveScreen_LoadNeighbor:: ; 28f7
.row
push bc
push hl
push de
2015-12-14 08:12:18 -08:00
.col
ld a, [de]
inc de
ld [hli], a
dec b
2015-12-14 08:12:18 -08:00
jr nz, .col
pop de
ld a, e
2015-12-14 08:12:18 -08:00
add 6
ld e, a
2015-11-12 21:49:27 -08:00
jr nc, .okay
inc d
2015-11-12 21:49:27 -08:00
.okay
pop hl
2015-11-12 21:49:27 -08:00
ld a, [hConnectionStripLength]
ld c, a
2015-12-14 08:12:18 -08:00
ld b, 0
add hl, bc
pop bc
dec c
2015-12-14 08:12:18 -08:00
jr nz, .row
ret
; 2914
2015-11-19 15:07:20 -08:00
GetMovementPermissions:: ; 2914
xor a
ld [TilePermissions], a
2016-01-06 04:44:50 -08:00
call .LeftRight
call .UpDown
2015-11-12 21:49:27 -08:00
; get coords of current tile
ld a, [PlayerStandingMapX]
ld d, a
ld a, [PlayerStandingMapY]
ld e, a
2015-11-12 21:49:27 -08:00
call GetCoordTile
ld [PlayerStandingTile], a
2016-01-06 04:44:50 -08:00
call .CheckHiNybble
ret nz
2015-11-12 21:49:27 -08:00
ld a, [PlayerStandingTile]
and 7
2016-01-06 04:44:50 -08:00
ld hl, .MovementPermissionsData
add l
ld l, a
ld a, 0
adc h
ld h, a
ld a, [hl]
ld hl, TilePermissions
or [hl]
ld [hl], a
ret
; 2945
.MovementPermissionsData: ; 2945
db DOWN_MASK
db UP_MASK
db LEFT_MASK
db RIGHT_MASK
db DOWN_MASK | RIGHT_MASK
db UP_MASK | RIGHT_MASK
db DOWN_MASK | LEFT_MASK
db UP_MASK | LEFT_MASK
; 294d
.UpDown:
ld a, [PlayerStandingMapX]
ld d, a
ld a, [PlayerStandingMapY]
ld e, a
2015-11-12 21:49:27 -08:00
push de
inc e
2015-11-12 21:49:27 -08:00
call GetCoordTile
ld [TileDown], a
2016-01-06 04:44:50 -08:00
call .Down
2015-11-12 21:49:27 -08:00
pop de
dec e
2015-11-12 21:49:27 -08:00
call GetCoordTile
ld [TileUp], a
2016-01-06 04:44:50 -08:00
call .Up
ret
; 296c
.LeftRight:
ld a, [PlayerStandingMapX]
ld d, a
ld a, [PlayerStandingMapY]
ld e, a
2015-11-12 21:49:27 -08:00
push de
dec d
2015-11-12 21:49:27 -08:00
call GetCoordTile
ld [TileLeft], a
2016-01-06 04:44:50 -08:00
call .Left
2015-11-12 21:49:27 -08:00
pop de
inc d
2015-11-12 21:49:27 -08:00
call GetCoordTile
ld [TileRight], a
2016-01-06 04:44:50 -08:00
call .Right
ret
; 298b
.Down:
2016-01-06 04:44:50 -08:00
call .CheckHiNybble
ret nz
ld a, [TileDown]
2015-11-12 21:49:27 -08:00
and 7
cp $2
2016-01-06 04:44:50 -08:00
jr z, .ok_down
cp $6
2016-01-06 04:44:50 -08:00
jr z, .ok_down
cp $7
ret nz
2016-01-06 04:44:50 -08:00
.ok_down
ld a, [TilePermissions]
2015-11-12 21:49:27 -08:00
or FACE_DOWN
ld [TilePermissions], a
ret
; 29a8
.Up:
2016-01-06 04:44:50 -08:00
call .CheckHiNybble
ret nz
ld a, [TileUp]
2015-11-12 21:49:27 -08:00
and 7
cp $3
2016-01-06 04:44:50 -08:00
jr z, .ok_up
cp $4
2016-01-06 04:44:50 -08:00
jr z, .ok_up
cp $5
ret nz
2016-01-06 04:44:50 -08:00
.ok_up
ld a, [TilePermissions]
2015-11-12 21:49:27 -08:00
or FACE_UP
ld [TilePermissions], a
ret
; 29c5
.Right:
2016-01-06 04:44:50 -08:00
call .CheckHiNybble
ret nz
ld a, [TileRight]
2015-11-12 21:49:27 -08:00
and 7
cp $1
2016-01-06 04:44:50 -08:00
jr z, .ok_right
cp $5
2016-01-06 04:44:50 -08:00
jr z, .ok_right
cp $7
ret nz
2016-01-06 04:44:50 -08:00
.ok_right
ld a, [TilePermissions]
2015-11-12 21:49:27 -08:00
or FACE_RIGHT
ld [TilePermissions], a
ret
; 29e2
.Left:
2016-01-06 04:44:50 -08:00
call .CheckHiNybble
ret nz
ld a, [TileLeft]
2015-11-12 21:49:27 -08:00
and 7
cp $0
2016-01-06 04:44:50 -08:00
jr z, .ok_left
cp $4
2016-01-06 04:44:50 -08:00
jr z, .ok_left
cp $6
ret nz
2016-01-06 04:44:50 -08:00
.ok_left
ld a, [TilePermissions]
2015-11-12 21:49:27 -08:00
or FACE_LEFT
ld [TilePermissions], a
ret
; 29ff
.CheckHiNybble:
and $f0
cp $b0
ret z
cp $c0
ret
; 2a07
GetFacingTileCoord:: ; 2a07
; Return map coordinates in (d, e) and tile id in a
; of the tile the player is facing.
ld a, [PlayerDirection]
and %1100
srl a
srl a
ld l, a
ld h, 0
2016-01-06 04:44:50 -08:00
add hl, hl
add hl, hl
ld de, .Directions
add hl, de
ld d, [hl]
inc hl
ld e, [hl]
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [PlayerStandingMapX]
add d
ld d, a
ld a, [PlayerStandingMapY]
add e
ld e, a
ld a, [hl]
ret
.Directions:
; x, y
db 0, 1
dw TileDown
db 0, -1
dw TileUp
db -1, 0
dw TileLeft
db 1, 0
dw TileRight
; 2a3c
2015-11-12 21:49:27 -08:00
GetCoordTile:: ; 2a3c
; Get the collision byte for tile d, e
call GetBlockLocation
ld a, [hl]
and a
jr z, .nope
ld l, a
ld h, $0
2016-01-06 04:44:50 -08:00
add hl, hl
add hl, hl
ld a, [TilesetCollisionAddress]
ld c, a
ld a, [TilesetCollisionAddress + 1]
ld b, a
add hl, bc
rr d
jr nc, .nocarry
inc hl
.nocarry
rr e
jr nc, .nocarry2
inc hl
2016-01-06 04:44:50 -08:00
inc hl
.nocarry2
ld a, [TilesetCollisionBank]
call GetFarByte
ret
.nope
ld a, -1
ret
; 2a66
GetBlockLocation:: ; 2a66
ld a, [MapWidth]
add 6
ld c, a
ld b, 0
2016-03-27 09:47:28 -07:00
ld hl, OverworldMap + 1
add hl, bc
ld a, e
srl a
jr z, .nope
and a
.loop
srl a
jr nc, .ok
add hl, bc
.ok
sla c
rl b
and a
jr nz, .loop
.nope
ld c, d
srl c
ld b, 0
add hl, bc
ret
; 2a8b
CheckFacingSign:: ; 2a8b
call GetFacingTileCoord
; Load facing into b.
ld b, a
; Convert the coordinates at de to within-boundaries coordinates.
ld a, d
sub 4
ld d, a
ld a, e
sub 4
ld e, a
; If there are no signposts, we don't need to be here.
ld a, [wCurrentMapSignpostCount]
and a
ret z
2015-11-12 08:10:19 -08:00
ld c, a
ld a, [hROMBank]
push af
call SwitchToMapScriptHeaderBank
call CheckIfFacingTileCoordIsSign
pop hl
ld a, h
rst Bankswitch
ret
; 2aaa
CheckIfFacingTileCoordIsSign:: ; 2aaa
; Checks to see if you are facing a signpost. If so, copies it into EngineBuffer1 and sets carry.
2015-11-12 08:10:19 -08:00
ld hl, wCurrentMapSignpostHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
.loop
push hl
ld a, [hli]
cp e
jr nz, .next
ld a, [hli]
cp d
jr nz, .next
jr .copysign
.next
pop hl
ld a, 5 ; signpost event length
add l
ld l, a
jr nc, .nocarry
inc h
.nocarry
dec c
jr nz, .loop
xor a
ret
.copysign
pop hl
2016-01-06 04:44:50 -08:00
ld de, wCurSignpostYCoord
ld bc, 5 ; signpost event length
call CopyBytes
scf
ret
; 2ad4
2016-01-06 04:44:50 -08:00
CheckCurrentMapXYTriggers:: ; 2ad4
; If there are no xy triggers, we don't need to be here.
2016-01-06 04:44:50 -08:00
ld a, [wCurrentMapXYTriggerCount]
and a
ret z
; Copy the trigger count into c.
ld c, a
ld a, [hROMBank]
push af
call SwitchToMapScriptHeaderBank
2016-01-06 04:44:50 -08:00
call .TriggerCheck
pop hl
ld a, h
rst Bankswitch
ret
.TriggerCheck:
; Checks to see if you are standing on an xy-trigger. If yes, copies the trigger to EngineBuffer1 and sets carry.
2016-01-06 04:44:50 -08:00
ld hl, wCurrentMapXYTriggerHeaderPointer
ld a, [hli]
ld h, [hl]
ld l, a
; Load the active trigger ID into b
call CheckTriggers
ld b, a
; Load your current coordinates into de. This will be used to check if your position is in the xy-trigger table for the current map.
ld a, [PlayerStandingMapX]
sub 4
ld d, a
ld a, [PlayerStandingMapY]
sub 4
ld e, a
.loop
push hl
ld a, [hli]
cp b
jr z, .got_id
cp -1
jr nz, .next
.got_id
ld a, [hli]
cp e
jr nz, .next
ld a, [hli]
cp d
jr nz, .next
jr .copytrigger
.next
pop hl
ld a, $8 ; xy-trigger size
add l
ld l, a
jr nc, .nocarry
inc h
.nocarry
dec c
jr nz, .loop
xor a
ret
.copytrigger
pop hl
2016-01-06 04:44:50 -08:00
ld de, wCurCoordEventTriggerID
2015-11-12 08:10:19 -08:00
ld bc, 8 ; xy-trigger size
call CopyBytes
scf
ret
; 2b29
FadeToMenu:: ; 2b29
xor a
ld [hBGMapMode], a
2015-11-11 13:11:08 -08:00
call LoadStandardMenuDataHeader
2015-11-26 18:05:32 -08:00
callba FadeOutPalettes
call ClearSprites
2015-10-24 07:34:19 -07:00
call DisableSpriteUpdates
ret
; 2b3c
CloseSubmenu:: ; 2b3c
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
2015-12-18 17:07:09 -08:00
call ReloadTilesetAndPalettes
call UpdateSprites
2015-09-09 16:27:07 -07:00
call Call_ExitMenu
2015-12-09 08:38:40 -08:00
call ret_d90
2016-01-06 04:44:50 -08:00
jr FinishExitMenu
; 2b4d
2015-11-17 14:56:49 -08:00
ExitAllMenus:: ; 2b4d
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
2015-09-09 16:27:07 -07:00
call Call_ExitMenu
2015-12-18 17:07:09 -08:00
call ReloadTilesetAndPalettes
call UpdateSprites
2015-12-09 08:38:40 -08:00
call ret_d90
2016-01-06 04:44:50 -08:00
FinishExitMenu:: ; 2b5c
ld b, SCGB_MAPPALS
call GetSGBLayout
2015-12-14 08:12:18 -08:00
callba LoadOW_BGPal7
2015-12-11 13:59:40 -08:00
call WaitBGMap2
2015-11-26 18:05:32 -08:00
callba FadeInPalettes
2015-10-24 07:34:19 -07:00
call EnableSpriteUpdates
ret
; 2b74
2015-12-18 17:07:09 -08:00
ReturnToMapWithSpeechTextbox:: ; 0x2b74
push af
ld a, $1
2015-11-25 07:16:29 -08:00
ld [wSpriteUpdatesEnabled], a
2015-11-11 20:38:57 -08:00
call ClearBGPalettes
call ClearSprites
2015-12-18 17:07:09 -08:00
call ReloadTilesetAndPalettes
hlcoord 0, 12
2015-11-05 11:06:03 -08:00
lb bc, 4, 18
call TextBox
ld hl, VramState
set 0, [hl]
call UpdateSprites
2015-12-11 13:59:40 -08:00
call WaitBGMap2
ld b, SCGB_MAPPALS
call GetSGBLayout
2015-12-14 08:12:18 -08:00
callba LoadOW_BGPal7
call UpdateTimePals
call DelayFrame
ld a, $1
2015-11-05 11:06:03 -08:00
ld [hMapAnims], a
pop af
ret
; 0x2bae
2015-12-18 17:07:09 -08:00
ReloadTilesetAndPalettes:: ; 2bae
call DisableLCD
call ClearSprites
2015-11-04 17:20:14 -08:00
callba RefreshSprites
2015-11-04 13:14:27 -08:00
call LoadStandardFont
call LoadFontsExtra
ld a, [hROMBank]
push af
ld a, [MapGroup]
ld b, a
ld a, [MapNumber]
ld c, a
call SwitchToAnyMapBank
2015-12-14 08:12:18 -08:00
callba UpdateTimeOfDayPal
2015-11-11 11:12:46 -08:00
call OverworldTextModeSwitch
2015-11-12 21:49:27 -08:00
call LoadTileset
2014-05-21 13:21:46 -07:00
ld a, 9
call SkipMusic
pop af
rst Bankswitch
call EnableLCD
ret
; 2be5
GetMapHeaderPointer:: ; 2be5
ld a, [MapGroup]
ld b, a
ld a, [MapNumber]
ld c, a
GetAnyMapHeaderPointer:: ; 0x2bed
; Prior to calling this function, you must have switched banks so that
; MapGroupPointers is visible.
; inputs:
; b = map group, c = map number
; XXX de = ???
; outputs:
; hl points to the map header
push bc ; save map number for later
; get pointer to map group
dec b
ld c, b
ld b, 0
ld hl, MapGroupPointers
add hl, bc
2016-01-06 04:44:50 -08:00
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
pop bc ; restore map number
; find the cth map header
dec c
ld b, 0
ld a, 9
call AddNTimes
ret
; 0x2c04
GetMapHeaderMember:: ; 0x2c04
; Extract data from the current map's header.
; inputs:
; de = offset of desired data within the mapheader
; outputs:
; bc = data from the current map's header
; (e.g., de = $0003 would return a pointer to the secondary map header)
ld a, [MapGroup]
ld b, a
ld a, [MapNumber]
ld c, a
GetAnyMapHeaderMember:: ; 0x2c0c
; bankswitch
ld a, [hROMBank]
push af
ld a, BANK(MapGroupPointers)
rst Bankswitch
call GetAnyMapHeaderPointer
add hl, de
ld c, [hl]
inc hl
ld b, [hl]
; bankswitch back
pop af
rst Bankswitch
ret
; 0x2c1c
SwitchToMapBank:: ; 2c1c
ld a, [MapGroup]
ld b, a
ld a, [MapNumber]
ld c, a
SwitchToAnyMapBank:: ; 2c24
call GetAnyMapBank
rst Bankswitch
ret
; 2c29
GetMapBank:: ; 2c29
ld a, [MapGroup]
ld b, a
ld a, [MapNumber]
ld c, a
GetAnyMapBank:: ; 2c31
push hl
push de
2015-11-02 11:37:02 -08:00
ld de, 0
call GetAnyMapHeaderMember
ld a, c
pop de
pop hl
ret
; 2c3d
2015-11-12 08:10:19 -08:00
PartiallyCopyMapHeader:: ; 2c3d
; Copy second map header bank, tileset, permission, and second map header address
; from the current map's map header.
ld a, [hROMBank]
push af
2014-12-26 15:31:48 -08:00
ld a, BANK(MapGroupPointers)
rst Bankswitch
2015-11-12 08:10:19 -08:00
call GetMapHeaderPointer
2015-11-12 08:10:19 -08:00
ld de, wSecondMapHeaderBank
ld bc, MapHeader - wSecondMapHeaderBank
call CopyBytes
2015-11-12 08:10:19 -08:00
pop af
rst Bankswitch
ret
; 2c52
SwitchToMapScriptHeaderBank:: ; 2c52
ld a, [MapScriptHeaderBank]
rst Bankswitch
ret
; 2c57
GetMapScriptHeaderBank:: ; 2c57
ld a, [MapScriptHeaderBank]
ret
; 2c5b
GetAnyMapBlockdataBank:: ; 2c5b
; Return the blockdata bank for group b map c.
push hl
push de
push bc
push bc
ld de, 3 ; second map header pointer
call GetAnyMapHeaderMember
ld l, c
ld h, b
pop bc
push hl
ld de, 0 ; second map header bank
call GetAnyMapHeaderMember
pop hl
ld de, 3 ; blockdata bank
add hl, de
ld a, c
call GetFarByte
rst Bankswitch
pop bc
pop de
pop hl
ret
; 2c7d
GetSecondaryMapHeaderPointer:: ; 0x2c7d
; returns the current map's secondary map header pointer in hl.
push bc
push de
2015-11-12 08:10:19 -08:00
ld de, 3 ; secondary map header pointer (offset within header)
call GetMapHeaderMember
ld l, c
ld h, b
pop de
pop bc
ret
; 2c8a
GetMapPermission:: ; 2c8a
push hl
push de
push bc
2015-11-12 08:10:19 -08:00
ld de, 2 ; permission
call GetMapHeaderMember
ld a, c
pop bc
pop de
pop hl
ret
; 2c98
2016-01-06 04:44:50 -08:00
ret ; XXX
; 2c99
GetAnyMapPermission:: ; 2c99
push hl
push de
push bc
2015-11-12 08:10:19 -08:00
ld de, 2 ; permission
call GetAnyMapHeaderMember
ld a, c
pop bc
pop de
pop hl
ret
; 2ca7
GetAnyMapTileset:: ; 2ca7
2015-11-12 08:10:19 -08:00
ld de, 1 ; tileset
call GetAnyMapHeaderMember
ld a, c
ret
; 2caf
GetWorldMapLocation:: ; 0x2caf
; given a map group/id in bc, return its location on the Pokégear map.
push hl
push de
push bc
2015-11-12 08:10:19 -08:00
ld de, 5 ; landmark
call GetAnyMapHeaderMember
ld a, c
2015-11-12 08:10:19 -08:00
pop bc
pop de
pop hl
ret
; 0x2cbd
2014-05-21 13:21:46 -07:00
GetMapHeaderMusic:: ; 2cbd
push hl
push bc
2014-05-21 13:21:46 -07:00
ld de, 6 ; music
call GetMapHeaderMember
ld a, c
2014-05-21 13:21:46 -07:00
cp MUSIC_MAHOGANY_MART
jr z, .mahoganymart
2017-12-10 17:50:08 -08:00
bit RADIO_TOWER_MUSIC_F, c
2014-05-21 13:21:46 -07:00
jr nz, .radiotower
2013-10-01 17:47:54 -07:00
callba Function8b342
ld e, c
2014-05-21 13:21:46 -07:00
ld d, 0
.done
pop bc
pop hl
ret
2014-05-21 13:21:46 -07:00
.radiotower
ld a, [StatusFlags2]
bit 0, a
2014-05-21 13:21:46 -07:00
jr z, .clearedradiotower
ld de, MUSIC_ROCKET_OVERTURE
jr .done
2014-05-21 13:21:46 -07:00
.clearedradiotower
; the rest of the byte
ld a, c
2017-12-10 17:50:08 -08:00
and RADIO_TOWER_MUSIC - 1
ld e, a
2014-05-21 13:21:46 -07:00
ld d, 0
jr .done
2014-05-21 13:21:46 -07:00
.mahoganymart
ld a, [StatusFlags2]
bit 7, a
2014-05-21 13:21:46 -07:00
jr z, .clearedmahogany
ld de, MUSIC_ROCKET_HIDEOUT
jr .done
2014-05-21 13:21:46 -07:00
.clearedmahogany
ld de, MUSIC_CHERRYGROVE_CITY
jr .done
; 2cff
GetMapHeaderTimeOfDayNybble:: ; 2cff
call GetPhoneServiceTimeOfDayByte
and $f
ret
; 2d05
GetMapHeaderPhoneServiceNybble:: ; 2d05
call GetPhoneServiceTimeOfDayByte
and $f0
swap a
ret
; 2d0d
GetPhoneServiceTimeOfDayByte:: ; 2d0d
push hl
push bc
2015-11-12 08:10:19 -08:00
ld de, 7 ; phone service and time of day
call GetMapHeaderMember
ld a, c
2015-11-12 08:10:19 -08:00
pop bc
pop hl
ret
; 2d19
2015-11-12 08:10:19 -08:00
GetFishingGroup:: ; 2d19
push de
push hl
push bc
2015-11-12 08:10:19 -08:00
ld de, 8 ; fishing group
call GetMapHeaderMember
ld a, c
2015-11-12 08:10:19 -08:00
pop bc
pop hl
pop de
ret
; 2d27
LoadTilesetHeader:: ; 2d27
push hl
push bc
2013-12-11 14:23:33 -08:00
ld hl, Tilesets
ld bc, TilesetHeaderEnd - TilesetHeader
2015-11-12 08:10:19 -08:00
ld a, [wTileset]
call AddNTimes
2013-12-11 14:23:33 -08:00
ld de, TilesetBank
ld bc, TilesetHeaderEnd - TilesetHeader
2013-12-11 14:23:33 -08:00
ld a, BANK(Tilesets)
call FarCopyBytes
2013-12-11 14:23:33 -08:00
pop bc
pop hl
ret
; 2d43