diff options
-rw-r--r-- | asm/field_map_obj.s | 133 | ||||
-rw-r--r-- | include/data/field_map_obj/callback_subroutine_pointers.h | 2 | ||||
-rw-r--r-- | include/field_map_obj.h | 56 | ||||
-rw-r--r-- | src/field_map_obj.c | 252 |
4 files changed, 76 insertions, 367 deletions
diff --git a/asm/field_map_obj.s b/asm/field_map_obj.s index c8c402217..a16c355e5 100644 --- a/asm/field_map_obj.s +++ b/asm/field_map_obj.s @@ -6,139 +6,6 @@ .text -.ifndef NONMATCHING - thumb_func_start sub_805F3EC -sub_805F3EC: @ 805F3EC - movs r0, 0 - bx lr - thumb_func_end sub_805F3EC - - thumb_func_start sub_805F3F0 -sub_805F3F0: @ 805F3F0 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - lsls r2, 24 - lsrs r2, 24 - ldr r1, _0805F434 @ =gUnknown_0836DC09 - ldrb r0, [r4, 0x6] - adds r0, r1 - ldrb r0, [r0] - adds r1, r4, 0 - adds r1, 0x21 - ldrb r1, [r1] - bl state_to_direction - bl GetFaceDirectionAnimId - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - adds r0, r4, 0 - adds r1, r5, 0 - bl FieldObjectSetRegularAnim - ldrb r0, [r4] - movs r1, 0x2 - orrs r0, r1 - strb r0, [r4] - movs r0, 0x2 - strh r0, [r5, 0x30] - movs r0, 0x1 - pop {r4,r5} - pop {r1} - bx r1 - .align 2, 0 -_0805F434: .4byte gUnknown_0836DC09 - thumb_func_end sub_805F3F0 - - thumb_func_start sub_805F438 -sub_805F438: @ 805F438 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x4 - adds r4, r0, 0 - adds r7, r1, 0 - mov r8, r3 - lsls r2, 24 - lsrs r6, r2, 24 - ldr r1, _0805F4EC @ =gUnknown_0836DC09 - ldrb r0, [r4, 0x6] - adds r0, r1 - ldrb r0, [r0] - adds r1, r4, 0 - adds r1, 0x21 - ldrb r1, [r1] - adds r2, r6, 0 - bl state_to_direction - adds r6, r0, 0 - mov r5, sp - adds r5, 0x2 - adds r0, r4, 0 - adds r1, r6, 0 - mov r2, sp - adds r3, r5, 0 - bl FieldObjectMoveDestCoords - adds r0, r6, 0 - bl GetGoSpeed0AnimId - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - adds r0, r4, 0 - adds r1, r7, 0 - bl FieldObjectSetRegularAnim - mov r0, sp - movs r2, 0 - ldrsh r1, [r0, r2] - movs r0, 0 - ldrsh r2, [r5, r0] - adds r0, r4, 0 - adds r3, r6, 0 - bl npc_block_way - lsls r0, 24 - cmp r0, 0 - bne _0805F4BE - mov r1, r8 - cmp r1, 0 - beq _0805F4D2 - mov r0, sp - movs r2, 0 - ldrsh r0, [r0, r2] - movs r2, 0 - ldrsh r1, [r5, r2] - bl MapGridGetMetatileBehaviorAt - lsls r0, 24 - lsrs r0, 24 - bl _call_via_r8 - lsls r0, 24 - cmp r0, 0 - bne _0805F4D2 -_0805F4BE: - adds r0, r6, 0 - bl GetFaceDirectionAnimId - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - adds r0, r4, 0 - adds r1, r7, 0 - bl FieldObjectSetRegularAnim -_0805F4D2: - ldrb r0, [r4] - movs r1, 0x2 - orrs r0, r1 - strb r0, [r4] - movs r0, 0x2 - strh r0, [r7, 0x30] - movs r0, 0x1 - add sp, 0x4 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_0805F4EC: .4byte gUnknown_0836DC09 - thumb_func_end sub_805F438 -.endif - thumb_func_start sub_805F4F0 sub_805F4F0: @ 805F4F0 push {r4-r7,lr} diff --git a/include/data/field_map_obj/callback_subroutine_pointers.h b/include/data/field_map_obj/callback_subroutine_pointers.h index d24a47184..06c89cc70 100644 --- a/include/data/field_map_obj/callback_subroutine_pointers.h +++ b/include/data/field_map_obj/callback_subroutine_pointers.h @@ -394,7 +394,7 @@ u8 (*const gUnknown_08375588[])(struct MapObject *, struct Sprite *) = { sub_805F3C4 }; -u8 (*const gUnknown_08375594[])(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)) = { +u8 (*const gUnknown_08375594[])(struct MapObject *, struct Sprite *, u8, bool8(u8)) = { sub_805F3EC, sub_805F3F0, sub_805F438, diff --git a/include/field_map_obj.h b/include/field_map_obj.h index d2a1a9b1f..e394dda8a 100644 --- a/include/field_map_obj.h +++ b/include/field_map_obj.h @@ -54,17 +54,15 @@ u8 sub_805CCAC(s16 a0, s16 a1, s16 a2, s16 a3); u8 sub_805CCE8(s16 a0, s16 a1, s16 a2, s16 a3); u8 sub_805CD24(s16 a0, s16 a1, s16 a2, s16 a3); -u8 sub_805F3EC(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F3F0(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F438(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F4F0(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F5A8(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F660(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 cph_IM_DIFFERENT(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F760(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 oac_hopping(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F3EC(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); -u8 sub_805F3EC(struct MapObject *, struct Sprite *, u8, bool8 (*const)(u8)); +u8 sub_805F3EC(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 sub_805F3F0(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 sub_805F438(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 sub_805F4F0(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 sub_805F5A8(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 sub_805F660(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 cph_IM_DIFFERENT(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 sub_805F760(struct MapObject *, struct Sprite *, u8, bool8(u8)); +u8 oac_hopping(struct MapObject *, struct Sprite *, u8, bool8(u8)); extern struct CameraSomething gUnknown_03004880; extern u16 gUnknown_03004898; @@ -318,7 +316,7 @@ u8 get_go_fast_image_anim_num(u8); u8 get_go_faster_image_anim_num(u8); u8 sub_805FD78(u8); -int state_to_direction(u8, u8, u8); +u32 state_to_direction(u8, u8, u32); void sub_805AA98(); void sub_805AAB0(void); @@ -379,14 +377,14 @@ u8 sub_805FDF8(u8); u8 sub_805FE08(u8); void npc_set_running_behaviour_etc(struct MapObject *, u8); u8 npc_running_behaviour_by_direction(u8); -u8 npc_block_way(struct MapObject *, s16, s16, u8); +u8 npc_block_way(struct MapObject *, s16, s16, u32); u8 sub_8060024(struct MapObject *, s16, s16, u8); u8 sub_8060234(u8, u8, u8); void sub_8060288(u8, u8, u8); void sub_8060388(s16, s16, s16 *, s16 *); void sub_80603CC(s16 x, s16 y, s16 *pInt, s16 *pInt1); void GetFieldObjectMovingCameraOffset(s16 *, s16 *); -void FieldObjectMoveDestCoords(struct MapObject *pObject, u8 unk_19, s16 *pInt, s16 *pInt1); +void FieldObjectMoveDestCoords(struct MapObject *pObject, u32 unk_19, s16 *pInt, s16 *pInt1); bool8 FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(struct MapObject *); bool8 FieldObjectIsSpecialAnimActive(struct MapObject *); bool8 FieldObjectSetSpecialAnim(struct MapObject *, u8); @@ -396,21 +394,21 @@ void FieldObjectClearAnim(struct MapObject *); bool8 FieldObjectCheckIfSpecialAnimFinishedOrInactive(struct MapObject *); u8 FieldObjectClearAnimIfSpecialAnimFinished(struct MapObject *); u8 FieldObjectGetSpecialAnim(struct MapObject *); -u8 GetFaceDirectionAnimId(u8); -u8 GetSimpleGoAnimId(u8); -u8 GetGoSpeed0AnimId(u8 a); -u8 sub_8060744(u8 a); -u8 d2s_08064034(u8 a); -u8 sub_806079C(u8 a); -u8 sub_80607F4(u8 a); -u8 GetJumpLedgeAnimId(u8 a); -u8 sub_806084C(u8); -u8 sub_8060878(u8); -u8 sub_80608D0(u8); -u8 GetStepInPlaceDelay32AnimId(u8 a); -u8 GetStepInPlaceDelay16AnimId(u8); -u8 GetStepInPlaceDelay8AnimId(u8 a); -u8 GetStepInPlaceDelay4AnimId(u8 a); +u8 GetFaceDirectionAnimId(u32); +u8 GetSimpleGoAnimId(u32); +u8 GetGoSpeed0AnimId(u32); +u8 sub_8060744(u32); +u8 d2s_08064034(u32); +u8 sub_806079C(u32); +u8 sub_80607F4(u32); +u8 GetJumpLedgeAnimId(u32); +u8 sub_806084C(u32); +u8 sub_8060878(u32); +u8 sub_80608D0(u32); +u8 GetStepInPlaceDelay32AnimId(u32); +u8 GetStepInPlaceDelay16AnimId(u32); +u8 GetStepInPlaceDelay8AnimId(u32); +u8 GetStepInPlaceDelay4AnimId(u32); u8 FieldObjectFaceOppositeDirection(struct MapObject *, u8); u8 sub_80609D8(u8); u8 sub_8060A04(u8); diff --git a/src/field_map_obj.c b/src/field_map_obj.c index 0e7cd7896..d76fd523b 100644 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c @@ -5030,32 +5030,32 @@ u8 sub_805F3C4(struct MapObject *mapObject, struct Sprite *sprite) return 0; } -#ifdef NONMATCHING +//#ifdef NONMATCHING -u8 sub_805F3EC(struct MapObject *mapObject, struct Sprite *sprite, u8 a2, u8 *a3(u8)) +bool8 sub_805F3EC(struct MapObject *mapObject, struct Sprite *sprite, u8 a2, bool8 a3(u8)) { return 0; } -u8 sub_805F3F0(struct MapObject *mapObject, struct Sprite *sprite, u8 a2, u8 *a3(u8)) +bool8 sub_805F3F0(struct MapObject *mapObject, struct Sprite *sprite, u8 a2, bool8 a3(u8)) { - int direction; - direction = state_to_direction(gUnknown_0836DC09[mapObject->animPattern], mapObject->mapobj_unk_21, a2); - FieldObjectSetRegularAnim(mapObject, sprite, GetFaceDirectionAnimId(direction)); + FieldObjectSetRegularAnim(mapObject, sprite, GetFaceDirectionAnimId(state_to_direction(gUnknown_0836DC09[mapObject->animPattern], mapObject->mapobj_unk_21, a2))); mapObject->mapobj_bit_1 = 1; sprite->data1 = 2; return 1; } -u8 sub_805F438(struct MapObject *mapObject, struct Sprite *sprite, u8 a2, u8 *a3(u8)) +bool8 sub_805F438(struct MapObject *mapObject, struct Sprite *sprite, u8 a2, bool8 a3(u8)) { + u32 direction; s16 x; s16 y; - int direction; - direction = state_to_direction(gUnknown_0836DC09[mapObject->animPattern], mapObject->mapobj_unk_21, a2); + + direction = a2; + direction = state_to_direction(gUnknown_0836DC09[mapObject->animPattern], mapObject->mapobj_unk_21, direction); FieldObjectMoveDestCoords(mapObject, direction, &x, &y); FieldObjectSetRegularAnim(mapObject, sprite, GetGoSpeed0AnimId(direction)); - if (!npc_block_way(mapObject, x, y, direction) || (a3 != NULL && !a3(MapGridGetMetatileBehaviorAt(x, y)))) + if (npc_block_way(mapObject, x, y, direction) || (a3 != NULL && !a3(MapGridGetMetatileBehaviorAt(x, y)))) { FieldObjectSetRegularAnim(mapObject, sprite, GetFaceDirectionAnimId(direction)); } @@ -5063,7 +5063,7 @@ u8 sub_805F438(struct MapObject *mapObject, struct Sprite *sprite, u8 a2, u8 *a3 sprite->data1 = 2; return 1; } -#endif +//#endif asm(".section .text_fmocb2_c\n"); @@ -5367,8 +5367,10 @@ bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *mapObject, s16 x, static bool8 DoesObjectCollideWithObjectAt(struct MapObject *mapObject, s16 x, s16 y); bool8 IsMetatileDirectionallyImpassable(struct MapObject *mapObject, s16 x, s16 y, u8 direction); -u8 npc_block_way(struct MapObject *mapObject, s16 x, s16 y, u8 direction) +u8 npc_block_way(struct MapObject *mapObject, s16 x, s16 y, u32 dirn) { + u8 direction; + direction = dirn; if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) return 1; else if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(mapObject, x, y, direction)) @@ -5563,11 +5565,12 @@ void GetFieldObjectMovingCameraOffset(s16 *x, s16 *y) } } -void FieldObjectMoveDestCoords(struct MapObject *mapObject, u8 direction, s16 *x, s16 *y) +void FieldObjectMoveDestCoords(struct MapObject *mapObject, u32 direction, s16 *x, s16 *y) { + u8 newDirn = direction; *x = mapObject->coords2.x; *y = mapObject->coords2.y; - MoveCoords(direction, x, y); + MoveCoords(newDirn, x, y); } bool8 FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(struct MapObject *mapObject) @@ -5681,193 +5684,34 @@ void meta_step(struct MapObject *mapObject, struct Sprite *sprite, u8 (*callback FieldObjectUpdateSubpriority(mapObject, sprite); } - -u8 GetFaceDirectionAnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756C8, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 GetSimpleGoAnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756CD, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 GetGoSpeed0AnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756D2, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_8060744(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756D7, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 d2s_08064034(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756DC, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_806079C(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756E1, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_80607C8(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756E6, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_80607F4(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756EB, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 GetJumpLedgeAnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756F0, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_806084C(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756F5, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_8060878(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756FA, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_80608A4(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_083756FF, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 sub_80608D0(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_08375704, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 GetStepInPlaceDelay32AnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_08375709, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 GetStepInPlaceDelay16AnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_0837570E, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 GetStepInPlaceDelay8AnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_08375713, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} - -u8 GetStepInPlaceDelay4AnimId(u8 index) -{ - u8 directions[5]; - memcpy(directions, gUnknown_08375718, 5); - if (index >= 5) - { - index = 0; - } - return directions[index]; -} +#define dirn_to_anim(name, table)\ +u8 name(u32 idx)\ +{\ + u8 direction;\ + u8 animIds[sizeof(table)];\ + direction = idx;\ + memcpy(animIds, (table), sizeof(table));\ + if (direction > DIR_EAST) direction = 0;\ + return animIds[direction];\ +} + +dirn_to_anim(GetFaceDirectionAnimId, gUnknown_083756C8) +dirn_to_anim(GetSimpleGoAnimId, gUnknown_083756CD) +dirn_to_anim(GetGoSpeed0AnimId, gUnknown_083756D2) +dirn_to_anim(sub_8060744, gUnknown_083756D7) +dirn_to_anim(d2s_08064034, gUnknown_083756DC) +dirn_to_anim(sub_806079C, gUnknown_083756E1) +dirn_to_anim(sub_80607C8, gUnknown_083756E6) +dirn_to_anim(sub_80607F4, gUnknown_083756EB) +dirn_to_anim(GetJumpLedgeAnimId, gUnknown_083756F0) +dirn_to_anim(sub_806084C, gUnknown_083756F5) +dirn_to_anim(sub_8060878, gUnknown_083756FA) +dirn_to_anim(sub_80608A4, gUnknown_083756FF) +dirn_to_anim(sub_80608D0, gUnknown_08375704) +dirn_to_anim(GetStepInPlaceDelay32AnimId, gUnknown_08375709) +dirn_to_anim(GetStepInPlaceDelay16AnimId, gUnknown_0837570E) +dirn_to_anim(GetStepInPlaceDelay8AnimId, gUnknown_08375713) +dirn_to_anim(GetStepInPlaceDelay4AnimId, gUnknown_08375718) u8 FieldObjectFaceOppositeDirection(struct MapObject *mapObject, u8 direction) { @@ -6001,11 +5845,11 @@ int zffu_offset_calc(u8 a0, u8 a1) } #ifdef NONMATCHING -int state_to_direction(u8 a0, u8 a1, u8 a2) +u32 state_to_direction(u8 a0, u8 a1, u32 a2) { int zffuOffset; asm_comment("For some reason, r2 is being backed up to r3 and restored ahead of the zffu call."); - if (a1 == 0 || a2 == 0 || a1 > 4 || a2 > 4) + if (a1 == 0 || (u8)a2 == 0 || a1 > 4 || (u8)a2 > 4) { return 0; } @@ -6014,7 +5858,7 @@ int state_to_direction(u8 a0, u8 a1, u8 a2) } #else __attribute__((naked)) -int state_to_direction(u8 a0, u8 a1, u8 a2) +u32 state_to_direction(u8 a0, u8 a1, u32 a2) { asm(".syntax unified\n\ push {r4,lr}\n\ |