From dbc773b26382044d227ce9581b4172429c3be055 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Fri, 23 May 2025 17:03:51 -0700 Subject: [PATCH 1/2] add ground_link data and cleanup macro --- data/data_8115F5C_1.s | 19 ------------------- include/ground_script.h | 15 +++++++++------ ld_script.ld | 1 + src/ground_link.c | 39 ++++----------------------------------- 4 files changed, 14 insertions(+), 60 deletions(-) diff --git a/data/data_8115F5C_1.s b/data/data_8115F5C_1.s index 1dbf12f9a..8059f3343 100644 --- a/data/data_8115F5C_1.s +++ b/data/data_8115F5C_1.s @@ -262,22 +262,3 @@ gUnknown_8118758: @ 8118758 .4byte gUnknown_81185D8 .4byte 0x56A .4byte GroundEffect_Action_Text -.string "pksdir0\0" -.align 2,0 -@ Ground Link - -.global GroundLink_FileText -GroundLink_FileText: @ FileText -.string "../ground/ground_link.c\0" -.align 2,0 - -.global GroundLink_SelectText -GroundLink_SelectText: @ SelectText -.string "GroundLink_Select\0" -.align 2,0 - -.global gUnknown_8118798 -gUnknown_8118798: @ 8118798 -.4byte GroundLink_FileText -.byte 0x4D, 0x00, 0x00, 0x00 -.4byte GroundLink_SelectText diff --git a/include/ground_script.h b/include/ground_script.h index 03ac2c2c5..01ecbf53e 100644 --- a/include/ground_script.h +++ b/include/ground_script.h @@ -2,6 +2,7 @@ #define GUARD_GROUND_SCRIPT_H #include "structs/str_position.h" +#include "number_util.h" // size: 0x10 typedef struct ScriptCommand @@ -204,17 +205,19 @@ struct GroundScriptHeader { static inline void SetUnkInGroundEvent(const CompactPos *posPtr, PixelPos *dst) { if (!(posPtr->xFlags & 4)) { - s32 x = posPtr->xTiles << 11; - dst->x = x; + s32 xAdd = IntToF248(4).raw; + + dst->x = IntToF248(posPtr->xTiles * 8).raw; if (posPtr->xFlags & 2) { - dst->x += 0x400; + dst->x += xAdd; } } if (!(posPtr->yFlags & 4)) { - s32 y = posPtr->yTiles << 11; - dst->y = y; + s32 yAdd = IntToF248(4).raw; + + dst->y = IntToF248(posPtr->yTiles * 8).raw; if (posPtr->yFlags & 2) { - dst->y += 0x400; + dst->y += yAdd; } } } diff --git a/ld_script.ld b/ld_script.ld index daa6b5ad4..f47f67798 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -703,6 +703,7 @@ SECTIONS { src/ground_script_file.o(.rodata); src/ground_lives.o(.rodata); data/data_8115F5C_1.o(.rodata); + src/ground_link.o(.rodata); src/ground_event.o(.rodata); src/unk_dungeon_load_maybe.o(.rodata); data/data_8115F5C_3.o(.rodata); diff --git a/src/ground_link.c b/src/ground_link.c index f6a553b3c..7189454ac 100644 --- a/src/ground_link.c +++ b/src/ground_link.c @@ -1,4 +1,5 @@ #include "global.h" +#include "globaldata.h" #include "ground_link.h" #include "debug.h" #include "ground_script.h" @@ -20,7 +21,7 @@ void sub_80AD874(void) void GroundLink_Select(s16 r0) { - const struct GroundScriptHeader *gs = GetGroundScript(r0, &gUnknown_8118798); + const struct GroundScriptHeader *gs = GetGroundScript(r0, DEBUG_LOC_PTR("../ground/ground_link.c", 77, "GroundLink_Select")); gCurrentGroundLink = gs->links; } @@ -35,23 +36,7 @@ s32 GroundLink_GetPos(s32 _arg0, PixelPos *pos) s32 arg0 = (s16)(_arg0); const struct GroundLink *ptr = &gCurrentGroundLink[arg0]; - if (!(ptr->pos.xFlags & 4)) { - s32 xAdd = IntToF248(4).raw; - - pos->x = IntToF248(ptr->pos.xTiles * 8).raw; - if (ptr->pos.xFlags & 2) { - pos->x += xAdd; - } - } - - if (!(ptr->pos.yFlags & 4)) { - s32 yAdd = IntToF248(4).raw; - - pos->y = IntToF248(ptr->pos.yTiles * 8).raw; - if (ptr->pos.yFlags & 2) { - pos->y += yAdd; - } - } + SetUnkInGroundEvent(&ptr->pos, pos); return ptr->ret; } @@ -62,24 +47,8 @@ s32 GroundLink_GetArea(s32 _arg0, PixelPos *arg1, PixelPos *arg2, PixelPos *arg3 const struct GroundLink *ptr = &gCurrentGroundLink[arg0]; *arg1 = *arg3; - if (!(ptr->pos.xFlags & 4)) - { - s32 xAdd = IntToF248(4).raw; - arg1->x = IntToF248(ptr->pos.xTiles * 8).raw; - if (ptr->pos.xFlags & 2) - arg1->x += xAdd; - } - - if (!(ptr->pos.yFlags & 4)) - { - s32 yAdd = IntToF248(4).raw; - - arg1->y = IntToF248(ptr->pos.yTiles * 8).raw; - if (ptr->pos.yFlags & 2) { - arg1->y += yAdd; - } - } + SetUnkInGroundEvent(&ptr->pos, arg1); arg2->x = arg1->x + IntToF248(ptr->width * 8).raw; arg2->y = arg1->y + IntToF248(ptr->height * 8).raw; From 87583b9c5ec8b45dbc7857b2ffe223afd94649b5 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sun, 25 May 2025 09:35:44 -0700 Subject: [PATCH 2/2] revert change to macro and add comment --- include/ground_script.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/ground_script.h b/include/ground_script.h index 01ecbf53e..23203ace7 100644 --- a/include/ground_script.h +++ b/include/ground_script.h @@ -202,22 +202,21 @@ struct GroundScriptHeader { const struct GroundLink *links; }; +// NOTE: F248 macros can match but has to be written this way to match in Blue static inline void SetUnkInGroundEvent(const CompactPos *posPtr, PixelPos *dst) { if (!(posPtr->xFlags & 4)) { - s32 xAdd = IntToF248(4).raw; - - dst->x = IntToF248(posPtr->xTiles * 8).raw; + s32 x = posPtr->xTiles << 11; + dst->x = x; if (posPtr->xFlags & 2) { - dst->x += xAdd; + dst->x += 0x400; } } if (!(posPtr->yFlags & 4)) { - s32 yAdd = IntToF248(4).raw; - - dst->y = IntToF248(posPtr->yTiles * 8).raw; + s32 y = posPtr->yTiles << 11; + dst->y = y; if (posPtr->yFlags & 2) { - dst->y += yAdd; + dst->y += 0x400; } } }