2013-09-03 22:39:19 +00:00
|
|
|
; Functions handling map objects.
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetSpritePalette::
|
2013-09-03 22:39:19 +00:00
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld c, a
|
2015-11-14 19:41:47 +00:00
|
|
|
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall _GetSpritePalette
|
2015-11-14 19:41:47 +00:00
|
|
|
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, c
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetSpriteVTile::
|
2013-09-03 22:39:19 +00:00
|
|
|
push hl
|
|
|
|
push bc
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wUsedSprites + 2
|
2015-07-15 19:48:44 +00:00
|
|
|
ld c, SPRITE_GFX_LIST_CAPACITY - 1
|
2013-09-03 22:39:19 +00:00
|
|
|
ld b, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hMapObjectIndexBuffer]
|
2015-07-18 19:46:38 +00:00
|
|
|
cp 0
|
2015-07-15 19:48:44 +00:00
|
|
|
jr z, .nope
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, b
|
2015-07-15 19:48:44 +00:00
|
|
|
.loop
|
2013-09-03 22:39:19 +00:00
|
|
|
cp [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
jr z, .found
|
2013-09-03 22:39:19 +00:00
|
|
|
inc hl
|
2016-05-04 15:46:23 +00:00
|
|
|
inc hl
|
2013-09-03 22:39:19 +00:00
|
|
|
dec c
|
2015-07-15 19:48:44 +00:00
|
|
|
jr nz, .loop
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wUsedSprites + 1]
|
2013-09-03 22:39:19 +00:00
|
|
|
scf
|
2015-07-15 19:48:44 +00:00
|
|
|
jr .done
|
2013-09-03 22:39:19 +00:00
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.nope
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wUsedSprites + 1]
|
2015-07-15 19:48:44 +00:00
|
|
|
jr .done
|
2013-09-03 22:39:19 +00:00
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.found
|
2013-09-03 22:39:19 +00:00
|
|
|
inc hl
|
|
|
|
xor a
|
|
|
|
ld a, [hl]
|
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.done
|
2013-09-03 22:39:19 +00:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
DoesSpriteHaveFacings::
|
2013-09-03 22:39:19 +00:00
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld b, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2013-09-03 22:39:19 +00:00
|
|
|
push af
|
2015-11-05 01:20:14 +00:00
|
|
|
ld a, BANK(_DoesSpriteHaveFacings)
|
2013-09-03 22:39:19 +00:00
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld a, b
|
2015-11-05 01:20:14 +00:00
|
|
|
call _DoesSpriteHaveFacings
|
2013-09-03 22:39:19 +00:00
|
|
|
ld c, a
|
|
|
|
|
|
|
|
pop de
|
|
|
|
ld a, d
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetPlayerStandingTile::
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPlayerStandingTile]
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetTileCollision
|
|
|
|
ld b, a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckOnWater::
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPlayerStandingTile]
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetTileCollision
|
2020-02-14 00:01:47 +00:00
|
|
|
sub WATER_TILE
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetTileCollision::
|
2013-09-03 22:39:19 +00:00
|
|
|
; Get the collision type of tile a.
|
|
|
|
|
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld hl, TileCollisionTable
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
add hl, de
|
|
|
|
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2013-09-03 22:39:19 +00:00
|
|
|
push af
|
|
|
|
ld a, BANK(TileCollisionTable)
|
|
|
|
rst Bankswitch
|
|
|
|
ld e, [hl]
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld a, e
|
|
|
|
and $f ; lo nybble only
|
|
|
|
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckGrassTile::
|
2013-09-03 22:39:19 +00:00
|
|
|
ld d, a
|
|
|
|
and $f0
|
2017-12-12 21:15:58 +00:00
|
|
|
cp HI_NYBBLE_TALL_GRASS
|
|
|
|
jr z, .grass
|
|
|
|
cp HI_NYBBLE_WATER
|
|
|
|
jr z, .water
|
2013-09-03 22:39:19 +00:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2017-12-12 21:15:58 +00:00
|
|
|
.grass
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, d
|
2017-12-12 21:15:58 +00:00
|
|
|
and LO_NYBBLE_GRASS
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
2015-11-15 19:59:38 +00:00
|
|
|
; For some reason, the above code is duplicated down here.
|
2017-12-12 21:15:58 +00:00
|
|
|
.water
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, d
|
2017-12-12 21:15:58 +00:00
|
|
|
and LO_NYBBLE_GRASS
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckSuperTallGrassTile::
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_LONG_GRASS
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_LONG_GRASS_1C
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckCutTreeTile::
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_CUT_TREE
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_CUT_TREE_1A
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckHeadbuttTreeTile::
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_HEADBUTT_TREE
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_HEADBUTT_TREE_1D
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckCounterTile::
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_COUNTER
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_COUNTER_98
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckPitTile::
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_PIT
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_PIT_68
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckIceTile::
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_ICE
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_ICE_2B
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckWhirlpoolTile::
|
2013-09-03 22:39:19 +00:00
|
|
|
nop
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_WHIRLPOOL
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_WHIRLPOOL_2C
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckWaterfallTile::
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_WATERFALL
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_CURRENT_DOWN
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckStandingOnEntrance::
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wPlayerStandingTile]
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_DOOR
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_DOOR_79
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_STAIRCASE
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
2017-12-12 21:15:58 +00:00
|
|
|
cp COLL_CAVE
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetMapObject::
|
2013-09-03 22:39:19 +00:00
|
|
|
; Return the location of map object a in bc.
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wMapObjects
|
2019-11-03 17:25:59 +00:00
|
|
|
ld bc, MAPOBJECT_LENGTH
|
2013-09-03 22:39:19 +00:00
|
|
|
call AddNTimes
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckObjectVisibility::
|
2015-07-15 19:48:44 +00:00
|
|
|
; Sets carry if the object is not visible on the screen.
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapObjectIndexBuffer], a
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetMapObject
|
2015-07-18 19:46:38 +00:00
|
|
|
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-19 08:58:31 +00:00
|
|
|
cp -1
|
2015-07-15 19:48:44 +00:00
|
|
|
jr z, .not_visible
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hObjectStructIndexBuffer], a
|
2015-07-15 19:48:44 +00:00
|
|
|
call GetObjectStruct
|
2013-09-03 22:39:19 +00:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.not_visible
|
2013-09-03 22:39:19 +00:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CheckObjectTime::
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, MAPOBJECT_HOUR
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
cp -1
|
|
|
|
jr nz, .check_hour
|
|
|
|
ld hl, MAPOBJECT_TIMEOFDAY
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
cp -1
|
|
|
|
jr z, .timeofday_always
|
|
|
|
ld hl, .TimeOfDayValues_191e
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wTimeOfDay]
|
2013-09-03 22:39:19 +00:00
|
|
|
add l
|
|
|
|
ld l, a
|
2015-07-15 19:48:44 +00:00
|
|
|
jr nc, .ok
|
2013-09-03 22:39:19 +00:00
|
|
|
inc h
|
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.ok
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, MAPOBJECT_TIMEOFDAY
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
and [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
jr nz, .timeofday_always
|
2013-09-03 22:39:19 +00:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.timeofday_always
|
2013-09-03 22:39:19 +00:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.TimeOfDayValues_191e:
|
2018-01-25 23:10:41 +00:00
|
|
|
; entries correspond to TimeOfDay values
|
|
|
|
db MORN
|
|
|
|
db DAY
|
|
|
|
db NITE
|
2013-09-03 22:39:19 +00:00
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.check_hour
|
|
|
|
ld hl, MAPOBJECT_HOUR
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, MAPOBJECT_TIMEOFDAY
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
|
|
|
ld hl, hHours
|
|
|
|
ld a, d
|
|
|
|
cp e
|
2015-07-15 19:48:44 +00:00
|
|
|
jr z, .yes
|
|
|
|
jr c, .check_timeofday
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [hl]
|
|
|
|
cp d
|
2015-07-15 19:48:44 +00:00
|
|
|
jr nc, .yes
|
2013-09-03 22:39:19 +00:00
|
|
|
cp e
|
2015-07-15 19:48:44 +00:00
|
|
|
jr c, .yes
|
|
|
|
jr z, .yes
|
|
|
|
jr .no
|
2013-09-03 22:39:19 +00:00
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.check_timeofday
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, e
|
|
|
|
cp [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
jr c, .no
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [hl]
|
|
|
|
cp d
|
2015-07-15 19:48:44 +00:00
|
|
|
jr nc, .yes
|
|
|
|
jr .no
|
2013-09-03 22:39:19 +00:00
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.yes
|
2013-09-03 22:39:19 +00:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.no
|
2013-09-03 22:39:19 +00:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2020-06-22 20:30:13 +00:00
|
|
|
CopyMapObjectStruct:: ; unreferenced
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapObjectIndexBuffer], a
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetMapObject
|
2015-07-18 19:46:38 +00:00
|
|
|
call CopyObjectStruct
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2020-06-22 20:30:13 +00:00
|
|
|
UnmaskCopyMapObjectStruct::
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapObjectIndexBuffer], a
|
2015-11-02 02:17:46 +00:00
|
|
|
call UnmaskObject
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hMapObjectIndexBuffer]
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetMapObject
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall CopyObjectStruct
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
ApplyDeletionToMapObject::
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh [hMapObjectIndexBuffer], a
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetMapObject
|
2015-07-18 19:46:38 +00:00
|
|
|
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-19 08:58:31 +00:00
|
|
|
cp -1
|
2015-11-02 16:15:32 +00:00
|
|
|
ret z ; already hidden
|
2015-07-19 08:58:31 +00:00
|
|
|
ld [hl], -1
|
2013-09-03 22:39:19 +00:00
|
|
|
push af
|
2016-01-11 07:36:39 +00:00
|
|
|
call .CheckStopFollow
|
2013-09-03 22:39:19 +00:00
|
|
|
pop af
|
2015-07-15 19:48:44 +00:00
|
|
|
call GetObjectStruct
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall DeleteMapObject
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2016-04-10 18:42:14 +00:00
|
|
|
.CheckStopFollow:
|
2015-11-02 16:15:32 +00:00
|
|
|
ld hl, wObjectFollow_Leader
|
2013-09-03 22:39:19 +00:00
|
|
|
cp [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
jr z, .ok
|
2015-11-02 16:15:32 +00:00
|
|
|
ld hl, wObjectFollow_Follower
|
2013-09-03 22:39:19 +00:00
|
|
|
cp [hl]
|
|
|
|
ret nz
|
2015-07-15 19:48:44 +00:00
|
|
|
.ok
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall StopFollow
|
2015-07-15 19:48:44 +00:00
|
|
|
ld a, -1
|
2015-11-02 16:15:32 +00:00
|
|
|
ld [wObjectFollow_Leader], a
|
|
|
|
ld [wObjectFollow_Follower], a
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
DeleteObjectStruct::
|
2016-01-11 07:36:39 +00:00
|
|
|
call ApplyDeletionToMapObject
|
2015-11-02 02:17:46 +00:00
|
|
|
call MaskObject
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CopyPlayerObjectTemplate::
|
2013-09-03 22:39:19 +00:00
|
|
|
push hl
|
|
|
|
call GetMapObject
|
|
|
|
ld d, b
|
|
|
|
ld e, c
|
2015-07-19 08:58:31 +00:00
|
|
|
ld a, -1
|
2013-09-03 22:39:19 +00:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
pop hl
|
2019-11-03 17:25:59 +00:00
|
|
|
ld bc, MAPOBJECT_LENGTH - 1
|
2013-09-03 22:39:19 +00:00
|
|
|
call CopyBytes
|
|
|
|
ret
|
|
|
|
|
2020-06-21 20:27:43 +00:00
|
|
|
Function19b8: ; unreferenced
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetMapObject
|
2015-07-18 19:46:38 +00:00
|
|
|
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
push af
|
2015-07-19 08:58:31 +00:00
|
|
|
ld [hl], -1
|
2013-09-03 22:39:19 +00:00
|
|
|
inc hl
|
2019-11-03 17:25:59 +00:00
|
|
|
ld bc, MAPOBJECT_LENGTH - 1
|
2013-09-03 22:39:19 +00:00
|
|
|
xor a
|
|
|
|
call ByteFill
|
|
|
|
pop af
|
2015-07-19 08:58:31 +00:00
|
|
|
cp -1
|
2013-09-03 22:39:19 +00:00
|
|
|
ret z
|
|
|
|
cp $d
|
|
|
|
ret nc
|
|
|
|
ld b, a
|
2015-11-02 16:15:32 +00:00
|
|
|
ld a, [wObjectFollow_Leader]
|
2013-09-03 22:39:19 +00:00
|
|
|
cp b
|
2015-07-15 19:48:44 +00:00
|
|
|
jr nz, .ok
|
|
|
|
ld a, -1
|
2015-11-02 16:15:32 +00:00
|
|
|
ld [wObjectFollow_Leader], a
|
2013-09-03 22:39:19 +00:00
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.ok
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, b
|
2015-07-15 19:48:44 +00:00
|
|
|
call GetObjectStruct
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall DeleteMapObject
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
LoadMovementDataPointer::
|
2017-12-24 18:46:34 +00:00
|
|
|
; Load the movement data pointer for object a.
|
|
|
|
ld [wMovementObject], a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2019-04-19 15:35:27 +00:00
|
|
|
ld [wMovementDataBank], a
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, l
|
2019-04-19 15:35:27 +00:00
|
|
|
ld [wMovementDataAddress], a
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, h
|
2019-04-19 15:35:27 +00:00
|
|
|
ld [wMovementDataAddress + 1], a
|
2017-12-24 18:46:34 +00:00
|
|
|
ld a, [wMovementObject]
|
2015-11-02 16:15:32 +00:00
|
|
|
call CheckObjectVisibility
|
2013-09-03 22:39:19 +00:00
|
|
|
ret c
|
2015-11-12 04:38:57 +00:00
|
|
|
|
2015-11-02 16:15:32 +00:00
|
|
|
ld hl, OBJECT_MOVEMENTTYPE
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
2015-11-06 21:42:38 +00:00
|
|
|
ld [hl], SPRITEMOVEDATA_SCRIPTED
|
2015-11-12 04:38:57 +00:00
|
|
|
|
2015-11-15 04:02:38 +00:00
|
|
|
ld hl, OBJECT_STEP_TYPE
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
2015-12-29 18:15:58 +00:00
|
|
|
ld [hl], STEP_TYPE_00
|
2015-11-12 04:38:57 +00:00
|
|
|
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wVramState
|
2013-09-03 22:39:19 +00:00
|
|
|
set 7, [hl]
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
FindFirstEmptyObjectStruct::
|
2015-11-01 01:05:02 +00:00
|
|
|
; Returns the index of the first empty object struct in A and its address in HL, then sets carry.
|
|
|
|
; If all object structs are occupied, A = 0 and Z is set.
|
|
|
|
; Preserves BC and DE.
|
2013-09-03 22:39:19 +00:00
|
|
|
push bc
|
|
|
|
push de
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wObjectStructs
|
2019-11-03 17:25:59 +00:00
|
|
|
ld de, OBJECT_LENGTH
|
2015-07-15 19:48:44 +00:00
|
|
|
ld c, NUM_OBJECT_STRUCTS
|
|
|
|
.loop
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2015-11-01 01:05:02 +00:00
|
|
|
jr z, .break
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, de
|
|
|
|
dec c
|
2015-07-15 19:48:44 +00:00
|
|
|
jr nz, .loop
|
2013-09-03 22:39:19 +00:00
|
|
|
xor a
|
2015-07-15 19:48:44 +00:00
|
|
|
jr .done
|
2013-09-03 22:39:19 +00:00
|
|
|
|
2015-11-01 01:05:02 +00:00
|
|
|
.break
|
|
|
|
ld a, NUM_OBJECT_STRUCTS
|
2013-09-03 22:39:19 +00:00
|
|
|
sub c
|
|
|
|
scf
|
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.done
|
2013-09-03 22:39:19 +00:00
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetSpriteMovementFunction::
|
2015-11-02 16:15:32 +00:00
|
|
|
ld hl, OBJECT_MOVEMENTTYPE
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-11-06 21:42:38 +00:00
|
|
|
cp NUM_SPRITEMOVEDATA
|
2015-07-15 19:48:44 +00:00
|
|
|
jr c, .ok
|
2013-09-03 22:39:19 +00:00
|
|
|
xor a
|
|
|
|
|
2015-07-15 19:48:44 +00:00
|
|
|
.ok
|
2018-05-23 16:48:14 +00:00
|
|
|
ld hl, SpriteMovementData + SPRITEMOVEATTR_MOVEMENT
|
2013-09-03 22:39:19 +00:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2018-05-23 16:48:14 +00:00
|
|
|
rept NUM_SPRITEMOVEDATA_FIELDS
|
2017-12-09 05:50:59 +00:00
|
|
|
add hl, de
|
2015-07-20 15:28:05 +00:00
|
|
|
endr
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetInitialFacing::
|
2013-09-03 22:39:19 +00:00
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2018-05-23 16:48:14 +00:00
|
|
|
ld hl, SpriteMovementData + SPRITEMOVEATTR_FACING
|
|
|
|
rept NUM_SPRITEMOVEDATA_FIELDS
|
2017-12-09 05:50:59 +00:00
|
|
|
add hl, de
|
2015-07-20 15:28:05 +00:00
|
|
|
endr
|
2015-11-06 21:42:38 +00:00
|
|
|
ld a, BANK(SpriteMovementData)
|
2013-09-03 22:39:19 +00:00
|
|
|
call GetFarByte
|
|
|
|
add a
|
2016-05-04 15:46:23 +00:00
|
|
|
add a
|
2018-05-23 16:48:14 +00:00
|
|
|
maskbits NUM_DIRECTIONS, 2
|
2013-09-03 22:39:19 +00:00
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
CopySpriteMovementData::
|
2013-09-03 22:39:19 +00:00
|
|
|
ld l, a
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2013-09-03 22:39:19 +00:00
|
|
|
push af
|
2015-11-06 21:42:38 +00:00
|
|
|
ld a, BANK(SpriteMovementData)
|
2013-09-03 22:39:19 +00:00
|
|
|
rst Bankswitch
|
|
|
|
ld a, l
|
|
|
|
push bc
|
|
|
|
|
2015-11-16 05:52:53 +00:00
|
|
|
call .CopyData
|
2013-09-03 22:39:19 +00:00
|
|
|
|
|
|
|
pop bc
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.CopyData:
|
2015-11-02 16:15:32 +00:00
|
|
|
ld hl, OBJECT_MOVEMENTTYPE
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-16 05:52:53 +00:00
|
|
|
|
2013-09-03 22:39:19 +00:00
|
|
|
push de
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2018-05-23 16:48:14 +00:00
|
|
|
ld hl, SpriteMovementData + SPRITEMOVEATTR_FACING
|
|
|
|
rept NUM_SPRITEMOVEDATA_FIELDS
|
2015-07-29 22:22:23 +00:00
|
|
|
add hl, de
|
2015-07-20 15:28:05 +00:00
|
|
|
endr
|
2013-09-03 22:39:19 +00:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop de
|
2015-11-16 05:52:53 +00:00
|
|
|
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
|
|
|
rlca
|
|
|
|
rlca
|
2018-05-23 16:48:14 +00:00
|
|
|
maskbits NUM_DIRECTIONS, 2
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, OBJECT_FACING
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-16 05:52:53 +00:00
|
|
|
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-11-14 19:41:47 +00:00
|
|
|
ld hl, OBJECT_ACTION
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-16 05:52:53 +00:00
|
|
|
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-10-30 03:32:11 +00:00
|
|
|
ld hl, OBJECT_FLAGS1
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-16 05:52:53 +00:00
|
|
|
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-10-30 03:32:11 +00:00
|
|
|
ld hl, OBJECT_FLAGS2
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-16 05:52:53 +00:00
|
|
|
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, OBJECT_PALETTE
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
_GetMovementByte::
|
2015-11-12 04:38:57 +00:00
|
|
|
; Switch to the movement data bank
|
2018-08-25 18:28:22 +00:00
|
|
|
ldh a, [hROMBank]
|
2013-09-03 22:39:19 +00:00
|
|
|
push af
|
|
|
|
ld a, [hli]
|
|
|
|
rst Bankswitch
|
2015-11-12 04:38:57 +00:00
|
|
|
; Load the current script byte as given by OBJECT_MOVEMENT_BYTE_INDEX, and increment OBJECT_MOVEMENT_BYTE_INDEX
|
2013-09-03 22:39:19 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld d, [hl]
|
2015-11-12 04:38:57 +00:00
|
|
|
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
add [hl]
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
2015-07-15 19:48:44 +00:00
|
|
|
adc 0
|
2013-09-03 22:39:19 +00:00
|
|
|
ld d, a
|
|
|
|
inc [hl]
|
|
|
|
ld a, [de]
|
|
|
|
ld h, a
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld a, h
|
|
|
|
ret
|
|
|
|
|
2020-06-21 20:27:43 +00:00
|
|
|
SetVramState_Bit0:: ; unreferenced
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wVramState
|
2013-09-03 22:39:19 +00:00
|
|
|
set 0, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-06-21 20:27:43 +00:00
|
|
|
ResetVramState_Bit0:: ; unreferenced
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wVramState
|
2013-09-03 22:39:19 +00:00
|
|
|
res 0, [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
UpdateSprites::
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wVramState]
|
2013-09-03 22:39:19 +00:00
|
|
|
bit 0, a
|
|
|
|
ret z
|
2015-11-16 05:52:53 +00:00
|
|
|
|
2017-12-24 17:47:30 +00:00
|
|
|
farcall Function55e0
|
|
|
|
farcall _UpdateSprites
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetObjectStruct::
|
2019-11-03 17:25:59 +00:00
|
|
|
ld bc, OBJECT_LENGTH
|
2018-01-23 22:39:09 +00:00
|
|
|
ld hl, wObjectStructs
|
2013-09-03 22:39:19 +00:00
|
|
|
call AddNTimes
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
DoesObjectHaveASprite::
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, OBJECT_SPRITE
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
SetSpriteDirection::
|
2015-11-14 19:41:47 +00:00
|
|
|
; preserves other flags
|
2013-09-03 22:39:19 +00:00
|
|
|
push af
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, OBJECT_FACING
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-15 19:48:44 +00:00
|
|
|
and %11110011
|
2013-09-03 22:39:19 +00:00
|
|
|
ld e, a
|
|
|
|
pop af
|
2018-05-23 16:48:14 +00:00
|
|
|
maskbits NUM_DIRECTIONS, 2
|
2013-09-03 22:39:19 +00:00
|
|
|
or e
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
GetSpriteDirection::
|
2015-07-15 19:48:44 +00:00
|
|
|
ld hl, OBJECT_FACING
|
2013-09-03 22:39:19 +00:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2018-05-23 16:48:14 +00:00
|
|
|
maskbits NUM_DIRECTIONS, 2
|
2013-09-03 22:39:19 +00:00
|
|
|
ret
|