Skip to content

Commit

Permalink
a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
red031000 committed Apr 20, 2024
1 parent 38d9d2d commit c775797
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 115 deletions.
126 changes: 14 additions & 112 deletions arm9/asm/map_object_s.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,6 @@

.text

thumb_func_start MapObject_SetPositionVecFromObjectEvent
MapObject_SetPositionVecFromObjectEvent: ; 0x02057DFC
push {r3-r6, lr}
sub sp, #0xc
add r6, r1, #0x0
add r4, r0, #0x0
add r0, r6, #0x0
bl sub_02058C98
add r5, r0, #0x0
mov r0, #0x2
lsl r1, r5, #0x10
lsl r0, r0, #0xe
add r0, r1, r0
str r0, [sp, #0x0]
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetInitialX
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetPreviousX
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetCurrentX
add r0, r6, #0x0
bl sub_02058CA0
asr r1, r0, #0x3
str r0, [sp, #0x4]
asr r0, r1, #0xb
lsr r0, r0, #0x14
add r0, r1, r0
asr r5, r0, #0xc
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetInitialHeight
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetPreviousHeight
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetCurrentHeight
add r0, r6, #0x0
bl sub_02058CA8
add r5, r0, #0x0
mov r0, #0x2
lsl r1, r5, #0x10
lsl r0, r0, #0xe
add r0, r1, r0
str r0, [sp, #0x8]
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetInitialY
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetPreviousY
add r0, r4, #0x0
add r1, r5, #0x0
bl MapObject_SetCurrentY
add r0, r4, #0x0
add r1, sp, #0x0
bl MapObject_SetPositionVec
add sp, #0xc
pop {r3-r6, pc}
.balign 4

thumb_func_start sub_02057E90
sub_02057E90: ; 0x02057E90
push {r3-r5, lr}
add r4, r1, #0x0
ldr r1, _02057EDC ; =0x00001801
add r5, r0, #0x0
bl MapObject_SetFlagsBits
add r0, r5, #0x0
bl sub_020581F8
cmp r0, #0x1
bne _02057EAE
add r0, r5, #0x0
mov r1, #0x1
bl sub_020589B0
_02057EAE:
add r0, r5, #0x0
add r1, r4, #0x0
bl sub_02058570
add r0, r5, #0x0
bl MapObject_GetInitialFacingDirection
add r1, r0, #0x0
add r0, r5, #0x0
bl MapObject_SetFacingDirectionDirect
add r0, r5, #0x0
bl MapObject_GetInitialFacingDirection
add r1, r0, #0x0
add r0, r5, #0x0
bl MapObject_SetNextFacingDirection
add r0, r5, #0x0
bl MapObject_ClearHeldMovement
pop {r3-r5, pc}
nop
_02057EDC: .word 0x00001801

thumb_func_start sub_02057EE0
sub_02057EE0: ; 0x02057EE0
push {r3-r5, lr}
Expand Down Expand Up @@ -499,8 +401,8 @@ sub_020581B4: ; 0x020581B4
_020581F6:
pop {r4, pc}

thumb_func_start sub_020581F8
sub_020581F8: ; 0x020581F8
thumb_func_start MapObject_ScriptIdIsFFFF
MapObject_ScriptIdIsFFFF: ; 0x020581F8
push {r3, lr}
bl MapObject_GetScript
lsl r0, r0, #0x10
Expand Down Expand Up @@ -529,7 +431,7 @@ sub_02058214: ; 0x02058214
_02058228:
add r0, r5, #0x0
mov r1, #0x0
bl sub_020589B0
bl MapObject_SetFlag25
add r0, r5, #0x0
add r1, r6, #0x0
bl sub_0205844C
Expand Down Expand Up @@ -560,7 +462,7 @@ sub_02058258: ; 0x02058258
_0205826E:
add r0, r5, #0x0
mov r1, #0x1
bl sub_020589B0
bl MapObject_SetFlag25
add r0, r6, #0x0
bl ObjectEvent_GetScript
add r1, r0, #0x0
Expand Down Expand Up @@ -1142,8 +1044,8 @@ sub_02058564: ; 0x02058564
bl sub_0200CAB4
pop {r3, pc}

thumb_func_start sub_02058570
sub_02058570: ; 0x02058570
thumb_func_start MapObject_SetManager
MapObject_SetManager: ; 0x02058570
add r0, #0xb4
str r1, [r0, #0x0]
bx lr
Expand Down Expand Up @@ -1851,8 +1753,8 @@ _020589A4:
pop {r3, pc}
.balign 4

thumb_func_start sub_020589B0
sub_020589B0: ; 0x020589B0
thumb_func_start MapObject_SetFlag25
MapObject_SetFlag25: ; 0x020589B0
push {r3, lr}
cmp r1, #0x1
bne _020589C0
Expand Down Expand Up @@ -2420,8 +2322,8 @@ ObjectEvent_SetXCoord: ; 0x02058C94
strh r1, [r0, #0x18]
bx lr

thumb_func_start sub_02058C98
sub_02058C98: ; 0x02058C98
thumb_func_start ObjectEvent_GetXCoord
ObjectEvent_GetXCoord: ; 0x02058C98
ldrh r0, [r0, #0x18]
bx lr

Expand All @@ -2430,8 +2332,8 @@ ObjectEvent_SetHeight: ; 0x02058C9C
str r1, [r0, #0x1c]
bx lr

thumb_func_start sub_02058CA0
sub_02058CA0: ; 0x02058CA0
thumb_func_start ObjectEvent_GetHeight
ObjectEvent_GetHeight: ; 0x02058CA0
ldr r0, [r0, #0x1c]
bx lr

Expand All @@ -2440,8 +2342,8 @@ ObjectEvent_SetYCoord: ; 0x02058CA4
strh r1, [r0, #0x1a]
bx lr

thumb_func_start sub_02058CA8
sub_02058CA8: ; 0x02058CA8
thumb_func_start ObjectEvent_GetYCoord
ObjectEvent_GetYCoord: ; 0x02058CA8
ldrh r0, [r0, #0x1a]
bx lr

Expand Down
47 changes: 44 additions & 3 deletions arm9/src/map_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ static LocalMapObject *MapObjectManager_GetFirstInactiveObject(MapObjectManager
static LocalMapObject *sub_02057C98(MapObjectManager *manager, u32 id, u32 mapNo);
static void sub_02057CF0(MapObjectManager *manager, LocalMapObject *object);
static void MapObject_InitFromObjectEvent(LocalMapObject *object, ObjectEvent *objectEvent, FieldSystem *fieldSystem);
static void MapObject_SetPositionVecFromObjectEvent(LocalMapObject *object, ObjectEvent *objectEvent);
static void sub_02057E90(LocalMapObject *object, MapObjectManager *manager);

extern BOOL sub_020580F4(MapObjectManager *manager, LocalMapObject **object, s32 *index, MapObjectFlagBits bits);

Expand Down Expand Up @@ -137,7 +139,7 @@ extern void MapObject_SetCurrentX(LocalMapObject *object, u32 currentX);
extern void MapObject_SetCurrentHeight(LocalMapObject *object, u32 currentHeight);
extern void MapObject_SetCurrentY(LocalMapObject *object, u32 currentY);
extern void MapObject_SetPositionVec(LocalMapObject *object, VecFx32 *coords);
extern void sub_02058570(LocalMapObject *object, MapObjectManager *manager);
extern void MapObject_SetManager(LocalMapObject *object, MapObjectManager *manager);
extern void sub_02057EE0(LocalMapObject *object);
extern void MapObject_ClearHeldMovement(LocalMapObject *object);
extern void sub_0205866C(LocalMapObject *object);
Expand All @@ -161,7 +163,11 @@ extern u16 ObjectEvent_GetInitialFacingDirection(ObjectEvent *objectEvent);
extern u32 ObjectEvent_GetParam(ObjectEvent *objectEvent, u32 param);
extern u32 ObjectEvent_GetXRange(ObjectEvent *objectEvent);
extern u32 ObjectEvent_GetYRange(ObjectEvent *objectEvent);
extern void MapObject_SetPositionVecFromObjectEvent(LocalMapObject *object, ObjectEvent *objectEvent);
extern u16 ObjectEvent_GetXCoord(ObjectEvent *objectEvent);
extern u16 ObjectEvent_GetYCoord(ObjectEvent *objectEvent);
extern u32 ObjectEvent_GetHeight(ObjectEvent *objectEvent);
extern BOOL MapObject_ScriptIdIsFFFF(LocalMapObject *object);
extern void MapObject_SetFlag25(LocalMapObject *object, BOOL flag);

MapObjectManager *MapObjectManager_Init(FieldSystem *fieldSystem, u32 objectCount, u32 priority) {
MapObjectManager *ret = MapObjectManager_New(objectCount);
Expand Down Expand Up @@ -494,7 +500,7 @@ static void LocalMapObject_InitFromSavedMapObject(LocalMapObject *localObject, S
static void sub_02057AEC(MapObjectManager *manager, LocalMapObject *object) {
sub_02057B34(object);
MapObject_ConvertXYToPositionVec(object);
sub_02058570(object, manager);
MapObject_SetManager(object, manager);
sub_02057EE0(object);
MapObject_ClearHeldMovement(object);
sub_020581B4(object);
Expand Down Expand Up @@ -622,3 +628,38 @@ static void MapObject_InitFromObjectEvent(LocalMapObject *object, ObjectEvent *o

MapObject_SetPositionVecFromObjectEvent(object, objectEvent);
}

static void MapObject_SetPositionVecFromObjectEvent(LocalMapObject *object, ObjectEvent *objectEvent) {
VecFx32 coords;

u16 x = ObjectEvent_GetXCoord(objectEvent);
coords.x = x * FX32_CONST(16) + FX32_CONST(8);
MapObject_SetInitialX(object, x);
MapObject_SetPreviousX(object, x);
MapObject_SetCurrentX(object, x);

coords.y = ObjectEvent_GetHeight(objectEvent);
u32 height = (coords.y >> 3) / FX32_ONE;
MapObject_SetInitialHeight(object, height);
MapObject_SetPreviousHeight(object, height);
MapObject_SetCurrentHeight(object, height);

u16 y = ObjectEvent_GetYCoord(objectEvent);
coords.z = y * FX32_CONST(16) + FX32_CONST(8);
MapObject_SetInitialY(object, y);
MapObject_SetPreviousY(object, y);
MapObject_SetCurrentY(object, y);

MapObject_SetPositionVec(object, &coords);
}

static void sub_02057E90(LocalMapObject *object, MapObjectManager *manager) { //setup facing and flags? also sets manager?
MapObject_SetFlagsBits(object, (MapObjectFlagBits)(MAPOBJECTFLAG_UNK12 | MAPOBJECTFLAG_UNK11 | MAPOBJECTFLAG_ACTIVE));
if (MapObject_ScriptIdIsFFFF(object) == TRUE) {
MapObject_SetFlag25(object, TRUE);
}
MapObject_SetManager(object, manager);
MapObject_SetFacingDirectionDirect(object, MapObject_GetInitialFacingDirection(object));
MapObject_SetNextFacingDirection(object, MapObject_GetInitialFacingDirection(object));
MapObject_ClearHeldMovement(object);
}
1 change: 1 addition & 0 deletions include/nitro/FX_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef s64 fx64c;
#define FX_F32_TO_FX16(x) ((fx16)(((x) > 0) ? \
((x) * (1 << FX16_INT_SHIFT) + 0.5f ) : \
((x) * (1 << FX16_INT_SHIFT) - 0.5f )))
#define FX_FX32_TO_F32(x) ((f32)((x) / (f32)(1 << FX32_INT_SHIFT)))
#define FX_F32_TO_FX32(x) ((fx32)(((x) > 0) ? \
((x) * (1 << FX32_INT_SHIFT) + 0.5f ) : \
((x) * (1 << FX32_INT_SHIFT) - 0.5f )))
Expand Down

0 comments on commit c775797

Please sign in to comment.