From 70b1ad485719ce1854020222131a0c0daa5a16cd Mon Sep 17 00:00:00 2001 From: scnorton Date: Sun, 17 Sep 2017 15:33:26 -0400 Subject: [PATCH] Remaining functions --- asm/field_map_obj.s | 280 -------------------------------------- include/map_obj_8097404.h | 2 + include/sprite.h | 2 + ld_script.txt | 1 - src/field_map_obj.c | 106 +++++++++++++++ 5 files changed, 110 insertions(+), 281 deletions(-) delete mode 100755 asm/field_map_obj.s diff --git a/asm/field_map_obj.s b/asm/field_map_obj.s deleted file mode 100755 index f3a044d44..000000000 --- a/asm/field_map_obj.s +++ /dev/null @@ -1,280 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_8096468 -sub_8096468: @ 8096468 - push {r4,lr} - adds r4, r1, 0 - bl sub_8097FA4 - movs r0, 0x1 - strh r0, [r4, 0x32] - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8096468 - - thumb_func_start sub_809647C -sub_809647C: @ 809647C - push {r4,lr} - adds r4, r1, 0 - ldrb r0, [r0, 0x1B] - bl sub_8098044 - movs r0, 0 - strh r0, [r4, 0x26] - movs r0, 0x1 - strh r0, [r4, 0x32] - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_809647C - - thumb_func_start sub_8096494 -sub_8096494: @ 8096494 - push {r4,lr} - adds r2, r0, 0 - adds r4, r1, 0 - movs r1, 0x26 - ldrsh r0, [r4, r1] - cmp r0, 0 - beq _080964A6 - movs r0, 0 - b _080964B0 -_080964A6: - ldrb r0, [r2, 0x1B] - bl sub_8098044 - movs r0, 0x1 - strh r0, [r4, 0x32] -_080964B0: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8096494 - - thumb_func_start sub_80964B8 -sub_80964B8: @ 80964B8 - movs r0, 0x1 - bx lr - thumb_func_end sub_80964B8 - - thumb_func_start sub_80964BC -@ bool8 sub_80964BC(struct npc_state *fieldObject, struct obj *object) -sub_80964BC: @ 80964BC - adds r1, 0x2C - ldrb r0, [r1] - movs r2, 0x40 - orrs r0, r2 - strb r0, [r1] - movs r0, 0x1 - bx lr - thumb_func_end sub_80964BC - - thumb_func_start npc_obj_transfer_image_anim_pause_flag -@ void npc_obj_transfer_image_anim_pause_flag(struct npc_state *fieldObject, struct obj *object) -npc_obj_transfer_image_anim_pause_flag: @ 80964CC - push {lr} - ldrb r0, [r0, 0x1] - lsls r0, 29 - cmp r0, 0 - bge _080964E2 - adds r0, r1, 0 - adds r0, 0x2C - ldrb r1, [r0] - movs r2, 0x40 - orrs r1, r2 - strb r1, [r0] -_080964E2: - pop {r0} - bx r0 - thumb_func_end npc_obj_transfer_image_anim_pause_flag - - thumb_func_start sub_80964E8 -@ void sub_80964E8(struct npc_state *fieldObject, struct obj *object) -sub_80964E8: @ 80964E8 - push {r4,lr} - adds r4, r0, 0 - ldrb r3, [r4, 0x1] - lsls r0, r3, 28 - cmp r0, 0 - bge _08096510 - adds r2, r1, 0 - adds r2, 0x2C - ldrb r1, [r2] - movs r0, 0x41 - negs r0, r0 - ands r0, r1 - strb r0, [r2] - movs r0, 0x5 - negs r0, r0 - ands r0, r3 - movs r1, 0x9 - negs r1, r1 - ands r0, r1 - strb r0, [r4, 0x1] -_08096510: - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_80964E8 - - thumb_func_start sub_8096518 -@ void sub_8096518(struct npc_state *fieldObject, struct obj *object) -sub_8096518: @ 8096518 - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - bl sub_8096530 - adds r0, r4, 0 - adds r1, r5, 0 - bl npc_update_obj_anim_flag - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_8096518 - - thumb_func_start sub_8096530 -sub_8096530: @ 8096530 - push {r4-r6,lr} - adds r5, r0, 0 - adds r4, r1, 0 - ldrb r1, [r5, 0x1] - movs r0, 0x41 - negs r0, r0 - ands r0, r1 - strb r0, [r5, 0x1] - ldrb r0, [r5, 0x5] - bl GetFieldObjectGraphicsInfo - adds r6, r0, 0 - adds r0, r4, 0 - adds r0, 0x3E - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _08096594 - ldrh r1, [r4, 0x24] - ldrh r0, [r4, 0x20] - adds r1, r0 - adds r0, r4, 0 - adds r0, 0x28 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - ldr r2, =gSpriteCoordOffsetX - adds r0, r1 - ldrh r2, [r2] - adds r0, r2 - lsls r0, 16 - lsrs r3, r0, 16 - ldrh r1, [r4, 0x26] - ldrh r0, [r4, 0x22] - adds r1, r0 - adds r0, r4, 0 - adds r0, 0x29 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - ldr r2, =gSpriteCoordOffsetY - adds r0, r1 - ldrh r2, [r2] - adds r0, r2 - b _080965BC - .pool -_08096594: - ldrh r1, [r4, 0x24] - ldrh r0, [r4, 0x20] - adds r1, r0 - adds r0, r4, 0 - adds r0, 0x28 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - adds r0, r1 - lsls r0, 16 - lsrs r3, r0, 16 - ldrh r1, [r4, 0x26] - ldrh r0, [r4, 0x22] - adds r1, r0 - adds r0, r4, 0 - adds r0, 0x29 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - adds r0, r1 -_080965BC: - lsls r0, 16 - lsrs r2, r0, 16 - ldrh r0, [r6, 0x8] - adds r0, r3 - lsls r0, 16 - lsrs r1, r0, 16 - ldrh r0, [r6, 0xA] - adds r0, r2 - lsls r0, 16 - lsrs r4, r0, 16 - lsls r0, r3, 16 - asrs r0, 16 - cmp r0, 0xFF - bgt _080965E4 - lsls r0, r1, 16 - asrs r0, 16 - movs r1, 0x10 - negs r1, r1 - cmp r0, r1 - bge _080965EC -_080965E4: - ldrb r0, [r5, 0x1] - movs r1, 0x40 - orrs r0, r1 - strb r0, [r5, 0x1] -_080965EC: - lsls r0, r2, 16 - asrs r0, 16 - cmp r0, 0xAF - bgt _08096600 - lsls r0, r4, 16 - asrs r0, 16 - movs r1, 0x10 - negs r1, r1 - cmp r0, r1 - bge _08096608 -_08096600: - ldrb r0, [r5, 0x1] - movs r1, 0x40 - orrs r0, r1 - strb r0, [r5, 0x1] -_08096608: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8096530 - - thumb_func_start npc_update_obj_anim_flag -@ void npc_update_obj_anim_flag(struct npc_state *fieldObject, struct obj *object) -npc_update_obj_anim_flag: @ 8096610 - push {lr} - adds r2, r1, 0 - adds r2, 0x3E - ldrb r1, [r2] - movs r3, 0x5 - negs r3, r3 - ands r3, r1 - strb r3, [r2] - ldrb r1, [r0, 0x1] - movs r0, 0x60 - ands r0, r1 - cmp r0, 0 - beq _08096632 - movs r1, 0x4 - adds r0, r3, 0 - orrs r0, r1 - strb r0, [r2] -_08096632: - pop {r0} - bx r0 - thumb_func_end npc_update_obj_anim_flag - - .align 2, 0 @ Don't pad with nop. diff --git a/include/map_obj_8097404.h b/include/map_obj_8097404.h index fd5616330..27ffd18cb 100644 --- a/include/map_obj_8097404.h +++ b/include/map_obj_8097404.h @@ -26,5 +26,7 @@ void obj_anim_image_set_and_seek(struct Sprite *, u8, u8); bool8 sub_80979BC(struct Sprite *); void sub_8097750(struct Sprite *); bool8 sub_8097758(struct Sprite *); +void sub_8097FA4(struct MapObject *); +void sub_8098044(u8); #endif //GUARD_MAP_OBJ_8097404_H diff --git a/include/sprite.h b/include/sprite.h index 7b3c9fb5a..838b0d7c0 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -240,6 +240,8 @@ struct OamMatrix extern const struct OamData gDummyOamData; extern const union AnimCmd *const gDummySpriteAnimTable[]; extern const union AffineAnimCmd *const gDummySpriteAffineAnimTable[]; +extern s16 gSpriteCoordOffsetX; +extern s16 gSpriteCoordOffsetY; extern struct Sprite gSprites[]; diff --git a/ld_script.txt b/ld_script.txt index 0cff77ca8..81e4fc3ab 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -97,7 +97,6 @@ SECTIONS { asm/field_door.o(.text); asm/field_player_avatar.o(.text); src/field_map_obj.o(.text); - asm/field_map_obj.o(.text); asm/field_ground_effect.o(.text); asm/map_obj_8097404.o(.text); asm/field_message_box.o(.text); diff --git a/src/field_map_obj.c b/src/field_map_obj.c index d4c00685f..a79f78434 100755 --- a/src/field_map_obj.c +++ b/src/field_map_obj.c @@ -122,6 +122,8 @@ static bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject *, s16, s16) static bool8 IsMetatileDirectionallyImpassable(struct MapObject *, s16, s16, u8); static bool8 CheckForCollisionBetweenFieldObjects(struct MapObject *, s16, s16); static bool8 sub_809558C(struct MapObject *, struct Sprite *); +static void sub_8096530(struct MapObject *, struct Sprite *); +static void npc_update_obj_anim_flag(struct MapObject *, struct Sprite *); // ROM data @@ -4972,3 +4974,107 @@ an_walk_any_2_macro(sub_8096368, sub_8096330, npc_obj_ministep_stop_on_arrival, an_walk_any_2_macro(sub_80963A8, sub_8096330, npc_obj_ministep_stop_on_arrival, DIR_NORTH, 1) an_walk_any_2_macro(sub_80963E8, sub_8096330, npc_obj_ministep_stop_on_arrival, DIR_WEST, 1) an_walk_any_2_macro(sub_8096428, sub_8096330, npc_obj_ministep_stop_on_arrival, DIR_EAST, 1) + +bool8 sub_8096468(struct MapObject *mapObject, struct Sprite *sprite) +{ + sub_8097FA4(mapObject); + sprite->data2 = 1; + return TRUE; +} + +bool8 sub_809647C(struct MapObject *mapObject, struct Sprite *sprite) +{ + sub_8098044(mapObject->mapobj_unk_1B); + sprite->pos2.y = 0; + sprite->data2 = 1; + return TRUE; +} + +bool8 sub_8096494(struct MapObject *mapObject, struct Sprite *sprite) +{ + if (sprite->pos2.y == 0) + { + sub_8098044(mapObject->mapobj_unk_1B); + sprite->data2 = 1; + return TRUE; + } + return FALSE; +} + +bool8 sub_80964B8(struct MapObject *mapObject, struct Sprite *sprite) +{ + return TRUE; +} + +bool8 sub_80964BC(struct MapObject *mapObject, struct Sprite *sprite) +{ + sprite->animPaused = TRUE; + return TRUE; +} + +void npc_obj_transfer_image_anim_pause_flag(struct MapObject *mapObject, struct Sprite *sprite) +{ + if (mapObject->mapobj_bit_10) + { + sprite->animPaused = TRUE; + } +} + +void sub_80964E8(struct MapObject *mapObject, struct Sprite *sprite) +{ + if (mapObject->mapobj_bit_11) + { + sprite->animPaused = FALSE; + mapObject->mapobj_bit_10 = FALSE; + mapObject->mapobj_bit_11 = FALSE; + } +} + +void sub_8096518(struct MapObject *mapObject, struct Sprite *sprite) +{ + sub_8096530(mapObject, sprite); + npc_update_obj_anim_flag(mapObject, sprite); +} + +static void sub_8096530(struct MapObject *mapObject, struct Sprite *sprite) +{ + u16 x; + u16 y; + u16 x2; + u16 y2; + const struct MapObjectGraphicsInfo *graphicsInfo; + + mapObject->mapobj_bit_14 = FALSE; + graphicsInfo = GetFieldObjectGraphicsInfo(mapObject->graphicsId); + if (sprite->coordOffsetEnabled) + { + x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX + gSpriteCoordOffsetX; + y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY + gSpriteCoordOffsetY; + } + else + { + x = sprite->pos1.x + sprite->pos2.x + sprite->centerToCornerVecX; + y = sprite->pos1.y + sprite->pos2.y + sprite->centerToCornerVecY; + } + x2 = graphicsInfo->width; + x2 += x; + y2 = y; + y2 += graphicsInfo->height; + if ((s16)x >= 0x100 || (s16)x2 < -0x10) + { + mapObject->mapobj_bit_14 = TRUE; + } + if ((s16)y >= 0xB0 || (s16)y2 < -0x10) + { + mapObject->mapobj_bit_14 = TRUE; + } +} + +static void npc_update_obj_anim_flag(struct MapObject *mapObject, struct Sprite *sprite) +{ + sprite->invisible = FALSE; + if (mapObject->mapobj_bit_13 || mapObject->mapobj_bit_14) + { + sprite->invisible = TRUE; + } +}