Skip to content

Commit

Permalink
Identify Mapobject routines and player/follower templates
Browse files Browse the repository at this point in the history
  • Loading branch information
vulcandth committed Jun 3, 2023
1 parent 1589b29 commit b737079
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 116 deletions.
6 changes: 5 additions & 1 deletion constants/map_object_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ DEF OBJECT_1D rb ; 1d
DEF OBJECT_1E rb ; 1e
DEF OBJECT_1F rb ; 1f
DEF OBJECT_RANGE rb ; 20
rb_skip 7
DEF OBJECT_21 rb ; 21
rb_skip 6
DEF OBJECT_LENGTH EQU _RS
DEF NUM_OBJECT_STRUCTS EQU 10
DEF PLAYER_STRUCT EQU 1
DEF FOLLOWER_STRUCT EQU 2

rsreset
DEF CMDQUEUE_UNK0 rb 16
Expand All @@ -56,6 +59,7 @@ DEF MAPOBJECT_EVENT_FLAG rw
rb_skip 2
DEF MAPOBJECT_LENGTH EQU _RS
DEF NUM_OBJECTS EQU 16
DEF PLAYER_OBJECT EQU 0

DEF MAPOBJECT_SCREEN_WIDTH EQU (SCREEN_WIDTH / 2) + 2
DEF MAPOBJECT_SCREEN_HEIGHT EQU (SCREEN_HEIGHT / 2) + 2
Expand Down
3 changes: 3 additions & 0 deletions constants/script_constants.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
; object constants
DEF PLAYER EQU 0
DEF FOLLOWER EQU 1

; Script IDs
const_def
Expand Down
2 changes: 1 addition & 1 deletion engine/debug/field/follow_npc_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FieldDebug_FollowNPCTest:
ret

.asm_fc9a5:
callab Function8047
callab SpawnFollower
ld a, 1
call Function15ed
ld a, 1
Expand Down
163 changes: 89 additions & 74 deletions engine/dumps/bank02.asm
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
INCLUDE "constants.asm"

SECTION "engine/dumps/bank02.asm@Function8000", ROMX

Function8000:
ld a, $00
ld hl, Data8022
call Function1656
call Function1668
ld a, $01
ldh [hConnectedMapWidth], a
ld de, wPlayerSprite
ld a, $00
ldh [hConnectionStripLength], a
SECTION "engine/dumps/bank02.asm@SpawnPlayer", ROMX

SpawnPlayer:
ld a, PLAYER
ld hl, PlayerObjectTemplate
call CopyPlayerObjectTemplate
call Spawn_ConvertCoords
ld a, PLAYER_STRUCT
ldh [hObjectStructIndex], a
ld de, wPlayerStruct
ld a, PLAYER_OBJECT
ldh [hMapObjectIndex], a
ld bc, wMapObjects
call Function813d
ld a, $00
call CopyMapObjectToObjectStruct
ld a, PLAYER_OBJECT
call Function1908
ret

Data8022:
db $01, $00, $00, $10, $ee, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00
PlayerObjectTemplate:
object_event -4, -4, SPRITE_GOLD, $10, 14, 14, 0, 0, 0, 0, 0, 0, 0, 0
db $00, $00

Function8031:
call Function8047
call SpawnFollower
ld a, [wUsedSprites+1]
ld [wMap1ObjectSprite], a
ld a, $01
call Function1602
ld b, $00
ld c, $01
ld b, PLAYER
ld c, FOLLOWER
call StartFollow
ret

Function8047:
ld a, $01
ld hl, Data805d
call Function1656
SpawnFollower:
ld a, FOLLOWER
ld hl, FollowerObjectTemplate
call CopyPlayerObjectTemplate
ld a, [wPlayerMapX]
ld [wMap1ObjectXCoord], a
ld a, [wPlayerMapY]
dec a
ld [wMap1ObjectYCoord], a
ret

Data805d:
db $4d, $00, $00, $18, $ff, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00
FollowerObjectTemplate:
object_event -4, -4, SPRITE_RHYDON, $18, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0
db $00, $00

Function806c:
ld a, $01
Expand All @@ -60,14 +60,14 @@ Function806c:
Function807b:
ld a, $01
ld hl, Data8089
call Function1656
call CopyPlayerObjectTemplate
ld a, $01
call Function1668
call Spawn_ConvertCoords
ret

Data8089:
db $01, $00, $00, $17, $ee, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00
object_event -4, -4, SPRITE_GOLD, $17, 14, 14, 0, 0, 0, 0, 0, 0, 0, 0
db $00, $00

_InitializeVisibleSprites:
ld bc, wMap2Object
Expand Down Expand Up @@ -154,7 +154,7 @@ Function80eb:
.done
ld d, h
ld e, l
call Function813d
call CopyMapObjectToObjectStruct
ld a, [wVramState]
bit 7, a
ret z
Expand Down Expand Up @@ -191,94 +191,109 @@ Function8131:
ld [hl], $00
ret

Function813d:
ldh a, [hConnectionStripLength]
ld hl, $0001
CopyMapObjectToObjectStruct:
ldh a, [hMapObjectIndex]
ld hl, OBJECT_MAP_OBJECT_INDEX
add hl, de
ld [hl], a
ldh a, [hConnectedMapWidth]
ld hl, $0000

ldh a, [hObjectStructIndex]
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
add hl, bc
ld [hl], a
ld hl, $0008

ld hl, OBJECT_DIRECTION
add hl, de
ld [hl], $00
ld hl, $0002

ld hl, MAPOBJECT_Y_COORD
add hl, bc
ld a, [hl]
ld hl, $0015
ld hl, OBJECT_INIT_Y
add hl, de
ld [hl], a
ld hl, $0011

ld hl, OBJECT_MAP_Y
add hl, de
ld [hl], a
ld hl, wYCoord
sub [hl]
and $0f
and $f
swap a
ld hl, $0019
ld hl, OBJECT_SPRITE_X_OFFSET
add hl, de
ld [hl], a
ld hl, $0003

ld hl, MAPOBJECT_X_COORD
add hl, bc
ld a, [hl]
ld hl, $0014
ld hl, OBJECT_INIT_X
add hl, de
ld [hl], a
ld hl, $0010

ld hl, OBJECT_MAP_X
add hl, de
ld [hl], a
ld hl, wXCoord
sub [hl]
and $0f
and $f
swap a
ld hl, $0018
ld hl, OBJECT_SPRITE_Y
add hl, de
ld [hl], a
ld hl, $0004

ld hl, MAPOBJECT_MOVEMENT
add hl, bc
ld a, [hl]
ld hl, $0003
ld hl, OBJECT_MOVEMENT_TYPE
add hl, de
ld [hl], a
call Function81ce
ld hl, $000d

call InitObjectFlags

ld hl, OBJECT_FACING
add hl, de
ld [hl], $ff
ld hl, $000a
ld [hl], -1

ld hl, OBJECT_STEP_DURATION
add hl, de
ld [hl], $00
ld hl, $0007
ld [hl], 0

ld hl, OBJECT_WALKING
add hl, de
ld [hl], $00
ld hl, $0001
ld [hl], 0

ld hl, MAPOBJECT_SPRITE
add hl, bc
ld a, [hl]
ld hl, $0000
ld hl, OBJECT_SPRITE
add hl, de
ld [hl], a

call Function820d
ld hl, $0002
ld hl, OBJECT_SPRITE_TILE
add hl, de
ld [hl], a
ld hl, $0005

ld hl, MAPOBJECT_RADIUS
add hl, bc
ld a, [hl]
call Function81f8
ld hl, $000b

ld hl, MAPOBJECT_SCRIPT_POINTER + 1
add hl, bc
ld a, [hl]
ld hl, $0021
ld hl, OBJECT_21
add hl, de
ld [hl], a
and a
ret

Function81ce:
ld hl, $0004
InitObjectFlags:
ld hl, OBJECT_FLAGS1
add hl, de
ld [hl], $70
ldh a, [hConnectedMapWidth]
ldh a, [hObjectStructIndex]
push hl
ld hl, wCenteredObject
cp [hl]
Expand All @@ -293,10 +308,10 @@ Function81ce:
.sub_81e8
set 1, [hl]
.sub_81ea
ld hl, $0005
ld hl, OBJECT_FLAGS2
add hl, de
ld [hl], $00
ldh a, [hConnectedMapWidth]
ldh a, [hObjectStructIndex]
cp $01
ret z
set 4, [hl]
Expand All @@ -307,26 +322,26 @@ Function81f8:
swap a
and $0f
inc a
ld hl, $0016
ld hl, OBJECT_RADIUS
add hl, de
ld [hl], a
pop af
and $0f
inc a
ld hl, $0017
ld hl, OBJECT_SPRITE_X
add hl, de
ld [hl], a
ret

Function820d:
push af
ldh a, [hConnectionStripLength]
cp $00
jr nz, .sub_8218
ldh a, [hMapObjectIndex]
cp PLAYER_OBJECT
jr nz, .not_player
pop af
ld a, $00
ret
.sub_8218
.not_player
cp $01
jr nz, .sub_8220
pop af
Expand Down
14 changes: 7 additions & 7 deletions engine/overworld/object_collision.asm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _CheckObjectCollision:
ld bc, wObjectStructs
xor a
.loop
ldh [hObjectStructIndexBuffer], a
ldh [hObjectStructIndex], a
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
Expand All @@ -57,7 +57,7 @@ _CheckObjectCollision:
jr nz, .check_last_position
ldh a, [hEventCollisionException]
ld l, a
ldh a, [hObjectStructIndexBuffer]
ldh a, [hObjectStructIndex]
cp l
jr nz, .collision
.check_last_position
Expand All @@ -73,15 +73,15 @@ _CheckObjectCollision:
jr nz, .next
ldh a, [hEventCollisionException]
ld l, a
ldh a, [hObjectStructIndexBuffer]
ldh a, [hObjectStructIndex]
cp l
jr nz, .collision
.next
ld hl, OBJECT_LENGTH
add hl, bc
ld b, h
ld c, l
ldh a, [hObjectStructIndexBuffer]
ldh a, [hObjectStructIndex]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
Expand All @@ -104,7 +104,7 @@ _CheckPlayerObjectCollision:
xor a

.loop
ldh [hObjectStructIndexBuffer], a
ldh [hObjectStructIndex], a
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
Expand All @@ -122,7 +122,7 @@ _CheckPlayerObjectCollision:
jr nz, .check_last_position

; skip the player sprite
ldh a, [hObjectStructIndexBuffer]
ldh a, [hObjectStructIndex]
cp PLAYER_OBJECT_INDEX
jr z, .next
jr .collision
Expand All @@ -145,7 +145,7 @@ _CheckPlayerObjectCollision:
add hl, bc
ld b, h
ld c, l
ldh a, [hObjectStructIndexBuffer]
ldh a, [hObjectStructIndex]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
Expand Down
Loading

0 comments on commit b737079

Please sign in to comment.