2013-09-03 15:39:19 -07:00
|
|
|
; Functions handling map objects.
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
GetSpritePalette:: ; 17ff
|
2013-09-03 15:39:19 -07:00
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld c, a
|
2015-11-14 11:41:47 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
callba _GetSpritePalette
|
2015-11-14 11:41:47 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, c
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
; 180e
|
|
|
|
|
|
|
|
|
2015-11-14 11:41:47 -08:00
|
|
|
GetSpriteVTile:: ; 180e
|
2013-09-03 15:39:19 -07:00
|
|
|
push hl
|
|
|
|
push bc
|
2015-02-10 15:14:41 -08:00
|
|
|
ld hl, UsedSprites + 2
|
2015-07-15 12:48:44 -07:00
|
|
|
ld c, SPRITE_GFX_LIST_CAPACITY - 1
|
2013-09-03 15:39:19 -07:00
|
|
|
ld b, a
|
2015-11-02 08:15:32 -08:00
|
|
|
ld a, [hMapObjectIndexBuffer]
|
2015-07-18 12:46:38 -07:00
|
|
|
cp 0
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .nope
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, b
|
2015-07-15 12:48:44 -07:00
|
|
|
.loop
|
2013-09-03 15:39:19 -07:00
|
|
|
cp [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .found
|
2015-07-20 19:18:18 -07:00
|
|
|
rept 2
|
2013-09-03 15:39:19 -07:00
|
|
|
inc hl
|
2015-07-20 19:18:18 -07:00
|
|
|
endr
|
2013-09-03 15:39:19 -07:00
|
|
|
dec c
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nz, .loop
|
2015-02-10 15:14:41 -08:00
|
|
|
ld a, [UsedSprites + 1]
|
2013-09-03 15:39:19 -07:00
|
|
|
scf
|
2015-07-15 12:48:44 -07:00
|
|
|
jr .done
|
2013-09-03 15:39:19 -07:00
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.nope
|
2015-02-10 15:14:41 -08:00
|
|
|
ld a, [UsedSprites + 1]
|
2015-07-15 12:48:44 -07:00
|
|
|
jr .done
|
2013-09-03 15:39:19 -07:00
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.found
|
2013-09-03 15:39:19 -07:00
|
|
|
inc hl
|
|
|
|
xor a
|
|
|
|
ld a, [hl]
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.done
|
2013-09-03 15:39:19 -07:00
|
|
|
pop bc
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
; 1836
|
|
|
|
|
2015-11-04 17:20:14 -08:00
|
|
|
DoesSpriteHaveFacings:: ; 1836
|
2013-09-03 15:39:19 -07:00
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld b, a
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
2015-11-04 17:20:14 -08:00
|
|
|
ld a, BANK(_DoesSpriteHaveFacings)
|
2013-09-03 15:39:19 -07:00
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld a, b
|
2015-11-04 17:20:14 -08:00
|
|
|
call _DoesSpriteHaveFacings
|
2013-09-03 15:39:19 -07:00
|
|
|
ld c, a
|
|
|
|
|
|
|
|
pop de
|
|
|
|
ld a, d
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
; 184a
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Function184a:: ; 184a
|
2015-11-14 20:02:38 -08:00
|
|
|
ld a, [PlayerNextTile]
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetTileCollision
|
|
|
|
ld b, a
|
|
|
|
ret
|
|
|
|
; 1852
|
|
|
|
|
2015-07-23 00:41:52 -07:00
|
|
|
CheckOnWater:: ; 1852
|
2015-11-14 20:02:38 -08:00
|
|
|
ld a, [PlayerNextTile]
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetTileCollision
|
|
|
|
sub 1
|
|
|
|
ret z
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
; 185d
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
GetTileCollision:: ; 185d
|
2013-09-03 15:39:19 -07:00
|
|
|
; Get the collision type of tile a.
|
|
|
|
|
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld hl, TileCollisionTable
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
add hl, de
|
|
|
|
|
|
|
|
ld a, [hROMBank]
|
|
|
|
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
|
|
|
|
; 1875
|
|
|
|
|
|
|
|
|
2015-11-15 11:59:38 -08:00
|
|
|
CheckGrassTile:: ; 1875
|
|
|
|
; and %00110111
|
|
|
|
; cp $10
|
|
|
|
; ret c
|
|
|
|
; cp $30
|
|
|
|
; jr nc, .okay
|
|
|
|
; scf
|
|
|
|
; ret
|
|
|
|
; .okay
|
|
|
|
; xor a
|
|
|
|
; ret
|
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld d, a
|
|
|
|
and $f0
|
|
|
|
cp $10
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .ok_10
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $20
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .ok_20
|
2013-09-03 15:39:19 -07:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok_10
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, d
|
|
|
|
and 7
|
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
2015-11-15 11:59:38 -08:00
|
|
|
; For some reason, the above code is duplicated down here.
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok_20
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, d
|
|
|
|
and 7
|
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
; 188e
|
|
|
|
|
2015-07-23 00:41:52 -07:00
|
|
|
CheckSuperTallGrassTile:: ; 188e
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $14
|
|
|
|
ret z
|
|
|
|
cp $1c
|
|
|
|
ret
|
|
|
|
; 1894
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckCutTreeTile:: ; 1894
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $12
|
|
|
|
ret z
|
|
|
|
cp $1a
|
|
|
|
ret
|
|
|
|
; 189a
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckHeadbuttTreeTile:: ; 189a
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $15
|
|
|
|
ret z
|
|
|
|
cp $1d
|
|
|
|
ret
|
|
|
|
; 18a0
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckCounterTile:: ; 18a0
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $90
|
|
|
|
ret z
|
|
|
|
cp $98
|
|
|
|
ret
|
|
|
|
; 18a6
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckPitTile:: ; 18a6
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $60
|
|
|
|
ret z
|
|
|
|
cp $68
|
|
|
|
ret
|
|
|
|
; 18ac
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckIceTile:: ; 18ac
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $23
|
|
|
|
ret z
|
|
|
|
cp $2b
|
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
; 18b4
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckWhirlpoolTile:: ; 18b4
|
2013-09-03 15:39:19 -07:00
|
|
|
nop
|
|
|
|
cp $24
|
|
|
|
ret z
|
|
|
|
cp $2c
|
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
; 18bd
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckWaterfallTile:: ; 18bd
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $33
|
|
|
|
ret z
|
|
|
|
cp $3b
|
|
|
|
ret
|
|
|
|
; 18c3
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
CheckStandingOnEntrance:: ; 18c3
|
2015-11-14 20:02:38 -08:00
|
|
|
ld a, [PlayerNextTile]
|
2013-09-03 15:39:19 -07:00
|
|
|
cp $71 ; door
|
|
|
|
ret z
|
|
|
|
cp $79
|
|
|
|
ret z
|
|
|
|
cp $7a ; stairs
|
|
|
|
ret z
|
|
|
|
cp $7b ; cave
|
|
|
|
ret
|
|
|
|
; 18d2
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
GetMapObject:: ; 18d2
|
2013-09-03 15:39:19 -07:00
|
|
|
; Return the location of map object a in bc.
|
|
|
|
ld hl, MapObjects
|
2015-07-15 12:48:44 -07:00
|
|
|
ld bc, OBJECT_LENGTH
|
2013-09-03 15:39:19 -07:00
|
|
|
call AddNTimes
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ret
|
|
|
|
; 18de
|
|
|
|
|
|
|
|
|
2015-11-02 08:15:32 -08:00
|
|
|
CheckObjectVisibility:: ; 18de
|
2015-07-15 12:48:44 -07:00
|
|
|
; Sets carry if the object is not visible on the screen.
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [hMapObjectIndexBuffer], a
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetMapObject
|
2015-07-18 12:46:38 -07:00
|
|
|
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-19 01:58:31 -07:00
|
|
|
cp -1
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .not_visible
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [hObjectStructIndexBuffer], a
|
2015-07-15 12:48:44 -07:00
|
|
|
call GetObjectStruct
|
2013-09-03 15:39:19 -07:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.not_visible
|
2013-09-03 15:39:19 -07:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
; 18f5
|
|
|
|
|
2015-11-01 18:17:46 -08:00
|
|
|
CheckObjectTime:: ; 18f5
|
2015-07-15 12:48:44 -07:00
|
|
|
ld hl, MAPOBJECT_HOUR
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
cp -1
|
|
|
|
jr nz, .check_hour
|
|
|
|
ld hl, MAPOBJECT_TIMEOFDAY
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
cp -1
|
|
|
|
jr z, .timeofday_always
|
|
|
|
ld hl, .TimeOfDayValues_191e
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [TimeOfDay]
|
|
|
|
add l
|
|
|
|
ld l, a
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nc, .ok
|
2013-09-03 15:39:19 -07:00
|
|
|
inc h
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
ld hl, MAPOBJECT_TIMEOFDAY
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
and [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nz, .timeofday_always
|
2013-09-03 15:39:19 -07:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.timeofday_always
|
2013-09-03 15:39:19 -07:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.TimeOfDayValues_191e
|
|
|
|
db 1 << MORN ; 1
|
|
|
|
db 1 << DAY ; 2
|
|
|
|
db 1 << NITE ; 4
|
2013-09-03 15:39:19 -07:00
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.check_hour
|
|
|
|
ld hl, MAPOBJECT_HOUR
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld d, [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
ld hl, MAPOBJECT_TIMEOFDAY
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld e, [hl]
|
|
|
|
ld hl, hHours
|
|
|
|
ld a, d
|
|
|
|
cp e
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .yes
|
|
|
|
jr c, .check_timeofday
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hl]
|
|
|
|
cp d
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nc, .yes
|
2013-09-03 15:39:19 -07:00
|
|
|
cp e
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .yes
|
|
|
|
jr z, .yes
|
|
|
|
jr .no
|
2013-09-03 15:39:19 -07:00
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.check_timeofday
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, e
|
|
|
|
cp [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .no
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hl]
|
|
|
|
cp d
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nc, .yes
|
|
|
|
jr .no
|
2013-09-03 15:39:19 -07:00
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.yes
|
2013-09-03 15:39:19 -07:00
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.no
|
2013-09-03 15:39:19 -07:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
; 194d
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Function194d:: ; 194d
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [hMapObjectIndexBuffer], a
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetMapObject
|
2015-07-18 12:46:38 -07:00
|
|
|
call CopyObjectStruct
|
2013-09-03 15:39:19 -07:00
|
|
|
ret
|
|
|
|
; 1956
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-18 12:46:38 -07:00
|
|
|
_CopyObjectStruct:: ; 1956
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [hMapObjectIndexBuffer], a
|
2015-11-01 18:17:46 -08:00
|
|
|
call UnmaskObject
|
2015-11-02 08:15:32 -08:00
|
|
|
ld a, [hMapObjectIndexBuffer]
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetMapObject
|
2015-07-18 12:46:38 -07:00
|
|
|
callba CopyObjectStruct
|
2013-09-03 15:39:19 -07:00
|
|
|
ret
|
|
|
|
; 1967
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Function1967:: ; 1967
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [hMapObjectIndexBuffer], a
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetMapObject
|
2015-07-18 12:46:38 -07:00
|
|
|
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-19 01:58:31 -07:00
|
|
|
cp -1
|
2015-11-02 08:15:32 -08:00
|
|
|
ret z ; already hidden
|
2015-07-19 01:58:31 -07:00
|
|
|
ld [hl], -1
|
2013-09-03 15:39:19 -07:00
|
|
|
push af
|
|
|
|
call Function1985
|
|
|
|
pop af
|
2015-07-15 12:48:44 -07:00
|
|
|
call GetObjectStruct
|
2013-09-03 15:39:19 -07:00
|
|
|
callba Function4357
|
|
|
|
ret
|
|
|
|
; 1985
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Function1985:: ; 1985
|
2015-11-02 08:15:32 -08:00
|
|
|
ld hl, wObjectFollow_Leader
|
2013-09-03 15:39:19 -07:00
|
|
|
cp [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .ok
|
2015-11-02 08:15:32 -08:00
|
|
|
ld hl, wObjectFollow_Follower
|
2013-09-03 15:39:19 -07:00
|
|
|
cp [hl]
|
|
|
|
ret nz
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok
|
2015-11-02 08:15:32 -08:00
|
|
|
callba StopFollow
|
2015-07-15 12:48:44 -07:00
|
|
|
ld a, -1
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [wObjectFollow_Leader], a
|
|
|
|
ld [wObjectFollow_Follower], a
|
2013-09-03 15:39:19 -07:00
|
|
|
ret
|
|
|
|
; 199f
|
|
|
|
|
2015-07-18 12:46:38 -07:00
|
|
|
DeleteObjectStruct:: ; 199f
|
2013-09-03 15:39:19 -07:00
|
|
|
call Function1967
|
2015-11-01 18:17:46 -08:00
|
|
|
call MaskObject
|
2013-09-03 15:39:19 -07:00
|
|
|
ret
|
|
|
|
; 19a6
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Function19a6:: ; 19a6
|
2013-09-03 15:39:19 -07:00
|
|
|
push hl
|
|
|
|
call GetMapObject
|
|
|
|
ld d, b
|
|
|
|
ld e, c
|
2015-07-19 01:58:31 -07:00
|
|
|
ld a, -1
|
2013-09-03 15:39:19 -07:00
|
|
|
ld [de], a
|
|
|
|
inc de
|
|
|
|
pop hl
|
2015-07-15 12:48:44 -07:00
|
|
|
ld bc, OBJECT_LENGTH - 1
|
2013-09-03 15:39:19 -07:00
|
|
|
call CopyBytes
|
|
|
|
ret
|
|
|
|
; 19b8
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Function19b8:: ; 19b8
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetMapObject
|
2015-07-18 12:46:38 -07:00
|
|
|
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
push af
|
2015-07-19 01:58:31 -07:00
|
|
|
ld [hl], -1
|
2013-09-03 15:39:19 -07:00
|
|
|
inc hl
|
2015-07-15 12:48:44 -07:00
|
|
|
ld bc, OBJECT_LENGTH - 1
|
2013-09-03 15:39:19 -07:00
|
|
|
xor a
|
|
|
|
call ByteFill
|
|
|
|
pop af
|
2015-07-19 01:58:31 -07:00
|
|
|
cp -1
|
2013-09-03 15:39:19 -07:00
|
|
|
ret z
|
|
|
|
cp $d
|
|
|
|
ret nc
|
|
|
|
ld b, a
|
2015-11-02 08:15:32 -08:00
|
|
|
ld a, [wObjectFollow_Leader]
|
2013-09-03 15:39:19 -07:00
|
|
|
cp b
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nz, .ok
|
|
|
|
ld a, -1
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [wObjectFollow_Leader], a
|
2013-09-03 15:39:19 -07:00
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, b
|
2015-07-15 12:48:44 -07:00
|
|
|
call GetObjectStruct
|
2013-09-03 15:39:19 -07:00
|
|
|
callba Function4357
|
|
|
|
ret
|
|
|
|
; 19e9
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-11 20:38:57 -08:00
|
|
|
LoadMovementDataPointer:: ; 19e9
|
|
|
|
; Load the movement data pointer for person a.
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [wMovementPerson], a
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hROMBank]
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [wMovementDataPointer], a
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, l
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [wMovementDataPointer + 1], a
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, h
|
2015-11-02 08:15:32 -08:00
|
|
|
ld [wMovementDataPointer + 2], a
|
|
|
|
ld a, [wMovementPerson]
|
|
|
|
call CheckObjectVisibility
|
2013-09-03 15:39:19 -07:00
|
|
|
ret c
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2015-11-02 08:15:32 -08:00
|
|
|
ld hl, OBJECT_MOVEMENTTYPE
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
2015-11-06 13:42:38 -08:00
|
|
|
ld [hl], SPRITEMOVEDATA_SCRIPTED
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2015-11-14 20:02:38 -08:00
|
|
|
ld hl, OBJECT_STEP_TYPE
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
2015-07-15 12:48:44 -07:00
|
|
|
ld [hl], 0
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld hl, VramState
|
|
|
|
set 7, [hl]
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
; 1a13
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-31 18:05:02 -07:00
|
|
|
FindFirstEmptyObjectStruct:: ; 1a13
|
|
|
|
; 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 15:39:19 -07:00
|
|
|
push bc
|
|
|
|
push de
|
2014-06-19 17:23:53 -07:00
|
|
|
ld hl, ObjectStructs
|
2015-07-15 12:48:44 -07:00
|
|
|
ld de, OBJECT_STRUCT_LENGTH
|
|
|
|
ld c, NUM_OBJECT_STRUCTS
|
|
|
|
.loop
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
2015-10-31 18:05:02 -07:00
|
|
|
jr z, .break
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, de
|
|
|
|
dec c
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nz, .loop
|
2013-09-03 15:39:19 -07:00
|
|
|
xor a
|
2015-07-15 12:48:44 -07:00
|
|
|
jr .done
|
2013-09-03 15:39:19 -07:00
|
|
|
|
2015-10-31 18:05:02 -07:00
|
|
|
.break
|
|
|
|
ld a, NUM_OBJECT_STRUCTS
|
2013-09-03 15:39:19 -07:00
|
|
|
sub c
|
|
|
|
scf
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.done
|
2013-09-03 15:39:19 -07:00
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
; 1a2f
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-06 13:42:38 -08:00
|
|
|
GetSpriteMovementFunction:: ; 1a2f
|
2015-11-02 08:15:32 -08:00
|
|
|
ld hl, OBJECT_MOVEMENTTYPE
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-11-06 13:42:38 -08:00
|
|
|
cp NUM_SPRITEMOVEDATA
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .ok
|
2013-09-03 15:39:19 -07:00
|
|
|
xor a
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok
|
2015-11-06 13:42:38 -08:00
|
|
|
ld hl, SpriteMovementData
|
2013-09-03 15:39:19 -07:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2015-11-06 13:42:38 -08:00
|
|
|
rept SPRITEMOVEDATA_FIELDS
|
2015-07-20 08:28:05 -07:00
|
|
|
add hl,de
|
|
|
|
endr
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hl]
|
|
|
|
ret
|
|
|
|
; 1a47
|
|
|
|
|
2015-11-13 15:59:49 -08:00
|
|
|
GetInitialFacing:: ; 1a47
|
2013-09-03 15:39:19 -07:00
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2015-11-06 13:42:38 -08:00
|
|
|
ld hl, SpriteMovementData + 1 ; init facing
|
|
|
|
rept SPRITEMOVEDATA_FIELDS
|
2015-07-20 08:28:05 -07:00
|
|
|
add hl,de
|
|
|
|
endr
|
2015-11-06 13:42:38 -08:00
|
|
|
ld a, BANK(SpriteMovementData)
|
2013-09-03 15:39:19 -07:00
|
|
|
call GetFarByte
|
2015-07-20 19:18:18 -07:00
|
|
|
rept 2
|
2013-09-03 15:39:19 -07:00
|
|
|
add a
|
2015-07-20 19:18:18 -07:00
|
|
|
endr
|
2013-09-03 15:39:19 -07:00
|
|
|
and $c
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
; 1a61
|
|
|
|
|
|
|
|
|
2015-11-15 21:52:53 -08:00
|
|
|
CopySpriteMovementData:: ; 1a61
|
2013-09-03 15:39:19 -07:00
|
|
|
ld l, a
|
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
2015-11-06 13:42:38 -08:00
|
|
|
ld a, BANK(SpriteMovementData)
|
2013-09-03 15:39:19 -07:00
|
|
|
rst Bankswitch
|
|
|
|
ld a, l
|
|
|
|
push bc
|
|
|
|
|
2015-11-15 21:52:53 -08:00
|
|
|
call .CopyData
|
2013-09-03 15:39:19 -07:00
|
|
|
|
|
|
|
pop bc
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ret
|
|
|
|
; 1a71
|
|
|
|
|
2015-11-15 21:52:53 -08:00
|
|
|
.CopyData ; 1a71
|
2015-11-02 08:15:32 -08:00
|
|
|
ld hl, OBJECT_MOVEMENTTYPE
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-15 21:52:53 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
push de
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2015-11-06 13:42:38 -08:00
|
|
|
ld hl, SpriteMovementData + 1 ; init facing
|
|
|
|
rept SPRITEMOVEDATA_FIELDS
|
2015-07-29 15:22:23 -07:00
|
|
|
add hl, de
|
2015-07-20 08:28:05 -07:00
|
|
|
endr
|
2013-09-03 15:39:19 -07:00
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop de
|
2015-11-15 21:52:53 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
|
|
|
rlca
|
|
|
|
rlca
|
2015-11-15 21:52:53 -08:00
|
|
|
and %00001100
|
2015-07-15 12:48:44 -07:00
|
|
|
ld hl, OBJECT_FACING
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-15 21:52:53 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-11-14 11:41:47 -08:00
|
|
|
ld hl, OBJECT_ACTION
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-15 21:52:53 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-10-29 20:32:11 -07:00
|
|
|
ld hl, OBJECT_FLAGS1
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-15 21:52:53 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-10-29 20:32:11 -07:00
|
|
|
ld hl, OBJECT_FLAGS2
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
2015-11-15 21:52:53 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
2015-07-15 12:48:44 -07:00
|
|
|
ld hl, OBJECT_PALETTE
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
; 1aae
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
Function1aae:: ; 1aae
|
2015-11-11 20:38:57 -08:00
|
|
|
; Switch to the movement data bank
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hROMBank]
|
|
|
|
push af
|
|
|
|
ld a, [hli]
|
|
|
|
rst Bankswitch
|
2015-11-11 20:38:57 -08:00
|
|
|
; Load the current script byte as given by OBJECT_MOVEMENT_BYTE_INDEX, and increment OBJECT_MOVEMENT_BYTE_INDEX
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [hli]
|
|
|
|
ld d, [hl]
|
2015-11-11 20:38:57 -08:00
|
|
|
ld hl, OBJECT_MOVEMENT_BYTE_INDEX
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
add [hl]
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
2015-07-15 12:48:44 -07:00
|
|
|
adc 0
|
2013-09-03 15:39:19 -07:00
|
|
|
ld d, a
|
|
|
|
inc [hl]
|
|
|
|
ld a, [de]
|
|
|
|
ld h, a
|
|
|
|
pop af
|
|
|
|
rst Bankswitch
|
|
|
|
|
|
|
|
ld a, h
|
|
|
|
ret
|
|
|
|
; 1ac6
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
SetVramState_Bit0:: ; 1ac6
|
2013-09-03 15:39:19 -07:00
|
|
|
ld hl, VramState
|
|
|
|
set 0, [hl]
|
|
|
|
ret
|
|
|
|
; 1acc
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
ResetVramState_Bit0:: ; 1acc
|
2013-09-03 15:39:19 -07:00
|
|
|
ld hl, VramState
|
|
|
|
res 0, [hl]
|
|
|
|
ret
|
|
|
|
; 1ad2
|
|
|
|
|
|
|
|
|
2015-07-22 12:57:02 -07:00
|
|
|
UpdateSprites:: ; 1ad2
|
2013-09-03 15:39:19 -07:00
|
|
|
ld a, [VramState]
|
|
|
|
bit 0, a
|
|
|
|
ret z
|
2015-11-15 21:52:53 -08:00
|
|
|
|
2013-09-03 15:39:19 -07:00
|
|
|
callba Function55e0
|
2015-11-15 18:28:15 -08:00
|
|
|
callba _UpdateSprites
|
2013-09-03 15:39:19 -07:00
|
|
|
ret
|
|
|
|
; 1ae5
|
|
|
|
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
GetObjectStruct:: ; 1ae5
|
|
|
|
ld bc, OBJECT_STRUCT_LENGTH
|
2014-06-19 17:23:53 -07:00
|
|
|
ld hl, ObjectStructs
|
2013-09-03 15:39:19 -07:00
|
|
|
call AddNTimes
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
ret
|
|
|
|
; 1af1
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
GetObjectSprite:: ; 1af1
|
|
|
|
ld hl, OBJECT_SPRITE
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
; 1af8
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
SetSpriteDirection:: ; 1af8
|
2015-11-14 11:41:47 -08:00
|
|
|
; preserves other flags
|
2013-09-03 15:39:19 -07:00
|
|
|
push af
|
2015-07-15 12:48:44 -07:00
|
|
|
ld hl, OBJECT_FACING
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
and %11110011
|
2013-09-03 15:39:19 -07:00
|
|
|
ld e, a
|
|
|
|
pop af
|
2015-07-15 12:48:44 -07:00
|
|
|
and %00001100
|
2013-09-03 15:39:19 -07:00
|
|
|
or e
|
|
|
|
ld [hl], a
|
|
|
|
ret
|
|
|
|
; 1b07
|
|
|
|
|
|
|
|
|
2014-02-01 17:26:39 -08:00
|
|
|
GetSpriteDirection:: ; 1b07
|
2015-07-15 12:48:44 -07:00
|
|
|
ld hl, OBJECT_FACING
|
2013-09-03 15:39:19 -07:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
and %00001100
|
2013-09-03 15:39:19 -07:00
|
|
|
ret
|
|
|
|
; 1b0f
|