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