From 5a7cc59e83d04ea37bd4594aa1e0bceea06903e9 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 21 Oct 2025 10:42:13 +0200 Subject: [PATCH 01/13] start cleaning up ground lives header --- include/ground_lives.h | 36 ++++++++++++- src/code_809D148.c | 4 +- src/ground_event.c | 3 +- src/ground_lives.c | 23 ++++----- src/ground_main.c | 6 +-- src/ground_object.c | 115 ++++++++++++++++++++--------------------- src/ground_script.c | 87 +++++++++++-------------------- src/textbox.c | 5 -- 8 files changed, 135 insertions(+), 144 deletions(-) diff --git a/include/ground_lives.h b/include/ground_lives.h index 016b8acc2..458ea84ad 100644 --- a/include/ground_lives.h +++ b/include/ground_lives.h @@ -4,11 +4,43 @@ #include "structs/str_position.h" #include "structs/str_ground_script.h" #include "structs/str_ground_lives.h" +#include "structs/str_pokemon.h" +#include "structs/str_dungeon_location.h" -// ground_lives.s +void AllocGroundLives(void); +void DeleteGroundLives(void); +void FreeGroundLives(void); +void GroundLives_Select(s32 scriptID, s32 group, s32 sector); +void GroundLives_Cancel(s32 scriptID, s32 sector); +void GroundLives_CancelBlank_1(void); +void GroundLives_CancelBlank_2(void); s32 sub_80A7AE8(s16); -s32 sub_80A8FD8(s32 id_, PixelPos *pixelPos); +s32 sub_80A7DDC(s16 *a0, s16 *speciesDst); +void sub_80A86C8(s32 id_, u32 flags); +void sub_80A87AC(s32 id_, s32 a1); +bool8 sub_80A87E0(s32 id_, Pokemon *a1); +Action *sub_80A882C(s32 id_); bool8 GroundLives_ExecuteScript(s32 id_, ActionUnkIds *a1, ScriptInfoSmall *scriptInfo); +bool8 GroundLives_ExecutePlayerScriptActionLives(s32 id1_, s32 id2_); +bool8 GroundLivesNotifyAll(s32 a0_); +bool8 GroundLivesCancelAll(void); +s32 sub_80A8BBC(s32 id_); +s32 sub_80A8BD8(s32 id_, u32 *a1); +s32 sub_80A8BFC(s32 id_); +s32 sub_80A8C2C(s32 a0); +s32 sub_80A8C4C(s32 id_, DungeonLocation *dungLoc); +bool8 GroundLives_IsStarterMon(s32 id_); +bool8 IsStarterMonster(s32 monsterId_); +bool8 sub_80A8D20(void); +Pokemon *sub_80A8D54(s32 a0); +Pokemon *sub_80A8E9C(s32 id_); +void sub_80A8EC0(u8 *buffer, s32 a1); +void sub_80A8F50(u8 *buffer, s32 a1_, s32 size); +s32 sub_80A8F9C(s32 id_, PixelPos *pixelPos); +s32 sub_80A8FD8(s32 id_, PixelPos *pixelPos); +s32 sub_80A9050(s32 id_, s8 *a1); +s32 sub_80A9090(s32 id_, s32 a1_); s16 GetFriendAreaDialogueId(s32 id_); +s32 GetLivesCollision_80A92A0(s32 id_, u32 flags, PixelPos *pixelPos1, PixelPos *pixelPos2); #endif // GUARD_GROUND_LIVES_H diff --git a/src/code_809D148.c b/src/code_809D148.c index 8a9183282..c042e4efe 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -6,6 +6,7 @@ #include "memory.h" #include "other_random.h" #include "ground_script.h" +#include "ground_lives.h" struct unkStruct_20399E8 { @@ -188,7 +189,6 @@ u8 sub_809D248(PixelPos *r0) } // Todo: move these to appropriate header files -extern s32 sub_80A8FD8(s16 a0, PixelPos *a1); extern s32 sub_80AC448(s16 a0, PixelPos *a1); extern s32 sub_80AD360(s16 a0, PixelPos *a1); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); @@ -205,7 +205,7 @@ void sub_809D25C(void) switch (gUnknown_20399E8.unk0) { case 1: - val = sub_80A8FD8(gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80A8FD8((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); if (val == (u16) -1) gUnknown_20399E8.unk0 = 0; break; diff --git a/src/ground_event.c b/src/ground_event.c index 9ad0a9489..3d731e9cb 100644 --- a/src/ground_event.c +++ b/src/ground_event.c @@ -2,6 +2,7 @@ #include "globaldata.h" #include "ground_event.h" #include "ground_script.h" +#include "ground_lives.h" #include "debug.h" #include "memory.h" @@ -19,8 +20,6 @@ typedef struct GroundEvent IWRAM_INIT GroundEvent *gGroundEvents = NULL; -extern void GroundLives_CancelBlank_2(void); - void DeleteGroundEvents(void); void GroundEvent_Delete(s32); const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); diff --git a/src/ground_lives.c b/src/ground_lives.c index 2858fa264..582292bfc 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -1,9 +1,9 @@ #include "global.h" #include "globaldata.h" +#include "ground_lives.h" #include "ground_script.h" #include "ground_sprite.h" #include "ground_event.h" -#include "ground_lives.h" #include "ground_main.h" #include "memory.h" #include "event_flag.h" @@ -101,7 +101,6 @@ struct GroundLiveTypeData extern const struct GroundLiveTypeData gGroundLivesTypeData_811E63C[]; -extern void DeleteGroundLives(void); extern s32 sub_8002984(s32 _direction1, u32 caseID); extern u8 sub_809D248(PixelPos *r0); extern s16 HandleAction(Action *action, const DebugLocation *debug); @@ -137,6 +136,9 @@ extern void sub_809D170(s32 r0, s32 r1); extern void sub_80A74E4(struct UnkGroundSpriteStruct *ptr); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); +static s32 sub_80A7B94(s16 *a0); +static s32 GroundLives_Add(s32 id_, const GroundLivesData *ptr, s32 group_, s32 sector_); +static void GroundLives_Delete(s32 id_); static s16 CallbackLivesGetIndex(void *livesPtr_); static void CallbackLivesGetSize(void *livesPtr_, PixelPos *out); static void CallbackLivesSetHitboxPos(void *livesPtr_, PixelPos *posOrNull); @@ -158,15 +160,12 @@ static void CallbackLivesClearFlags(void *livesPtr_, u32 flags); static void CallbackLivesSpriteRelated_80AB238(void *livesPtr_, s32 a1); static s32 CallbackLivesMoveRelative(void *livesPtr_, PixelPos *pos); bool8 sub_80A9750(struct GroundLive *ptr, u16 a1); -void GroundLives_Delete(s32); -s32 GroundLives_Add(s32 id_, const GroundLivesData *ptr, s32 group_, s32 sector_); void sub_80AB5A4(void); s32 sub_80A9F20(struct GroundLive *livesPtr, PixelPos *pixelPos); bool8 sub_80AA3F8(struct GroundLive *livesPtr, s32 a1); void sub_80AB5D4(struct GroundLive *livesPtr); s32 sub_80ABA00(s32); void sub_80AAF68(struct GroundLive *livesPtr, u32 unused); -s32 sub_80A7B94(s16 *a0); static const CallbackData gGroundLivesCallbacks = { .maybeId = 1, @@ -404,7 +403,7 @@ UNUSED static s16 sub_80A7B40(s32 a0_) return -1; } -s32 sub_80A7B94(s16 *a0) +static s32 sub_80A7B94(s16 *a0) { s32 id = *a0; const struct GroundLiveTypeData *dataPtr = &gGroundLivesTypeData_811E63C[id]; @@ -706,7 +705,7 @@ s32 sub_80A7DDC(s16 *a0, s16 *speciesDst) return ret; } -s32 GroundLives_Add(s32 id_, const GroundLivesData *ptr, s32 group_, s32 sector_) +static s32 GroundLives_Add(s32 id_, const GroundLivesData *ptr, s32 group_, s32 sector_) { s32 id = (s16) id_; s32 group = (s16) group_; @@ -945,7 +944,7 @@ s32 GroundLives_Add(s32 id_, const GroundLivesData *ptr, s32 group_, s32 sector_ return id; } -void GroundLives_Delete(s32 id_) +static void GroundLives_Delete(s32 id_) { s32 id = (s16) id_; struct GroundLive *livesPtr = &gGroundLives->array[id]; @@ -982,7 +981,7 @@ void sub_80A86C8(s32 id_, u32 flags) } } -void sub_80A8750(s32 id_, u32 flags) +static void sub_80A8750(s32 id_, u32 flags) { s32 id = (s16) id_; struct GroundLive *livesPtr = &gGroundLives->array[id]; @@ -1121,7 +1120,7 @@ bool8 GroundLives_ExecutePlayerScriptActionLives(s32 id1_, s32 id2_) return FALSE; } -bool8 sub_80A8A5C(s32 id1_, s32 id2_) +static bool8 sub_80A8A5C(s32 id1_, s32 id2_) { s32 id1 = (s16) id1_; s32 id2 = (s16) id2_; @@ -1143,7 +1142,7 @@ bool8 sub_80A8A5C(s32 id1_, s32 id2_) return FALSE; } -bool8 sub_80A8ACC(s32 id1_, s32 id2_) +static bool8 sub_80A8ACC(s32 id1_, s32 id2_) { s32 id1 = (s16) id1_; s32 id2 = (s16) id2_; @@ -1363,7 +1362,7 @@ Pokemon *sub_80A8E9C(s32 id_) return sub_80A8D54(livesPtr->unk2); } -void sub_80A8EC0(u8 *buffer,s32 a1) +void sub_80A8EC0(u8 *buffer, s32 a1) { s16 sp = a1; s16 species; diff --git a/src/ground_main.c b/src/ground_main.c index 8fe0f3c0f..d37d070ca 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -24,6 +24,7 @@ #include "script_item.h" #include "unk_ds_only_feature.h" #include "textbox.h" +#include "ground_lives.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -70,7 +71,6 @@ extern bool8 sub_809AFAC(void); extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); -extern void FreeGroundLives(void); extern void FreeGroundObjects(void); extern void FreeGroundEffects(void); extern void FreeGroundEvents(void); @@ -85,7 +85,6 @@ extern void sub_809D0AC(void); extern void sub_809D490(void); extern void sub_80A62F0(void); extern void AllocGroundEvents(void); -extern void AllocGroundLives(void); extern void AllocGroundObjects(void); extern void AllocGroundEffects(void); extern void nullsub_124(void); @@ -109,7 +108,6 @@ extern void sub_80A73EC(void); extern void sub_8099750(void); extern void sub_809D0BC(void); extern void DeleteGroundEvents(void); -extern void DeleteGroundLives(void); extern void DeleteGroundObjects(void); extern void DeleteGroundEffects(void); extern void nullsub_16(void); @@ -735,8 +733,6 @@ static inline bool8 sub_80990EC_sub(struct DungeonSetupInfo *iVar1, u32 iVar2) return flag; } -extern void sub_80A8EC0(u8 *, u32); - u8 sub_80990EC(struct DungeonSetupInfo *param_1, s16 param_2) { const DungeonInfo *iVar1; diff --git a/src/ground_object.c b/src/ground_object.c index 23f14416b..9b3b4968e 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -107,7 +107,7 @@ static const CallbackData gGroundObjectCallbacks = { }; const u8 gGroundObjectFileName[]; #define FAKE_FILENAME gGroundObjectFileName - + @@ -171,39 +171,39 @@ static const struct ScriptCommand gUnknown_8118350[] = { }; const s16 gUnknown_81183A0[] = { --1, -0x800, -0x801, -0x1000, -0x1001, +-1, +0x800, +0x801, +0x1000, +0x1001, 0x1002, 0x1003, -0x800, -0x801, -0x802, +0x800, +0x801, +0x802, 0x803, -0x804, -0x805, -0x806, +0x804, +0x805, +0x806, 0x807, -0x808, -0x809, -0x80A, -0x80B, -0x80C, -0x80D, -0x80E, -0x80F, +0x808, +0x809, +0x80A, +0x80B, +0x80C, +0x80D, +0x80E, +0x80F, 0}; -void AllocGroundObjects(void) +void AllocGroundObjects(void) { GroundObject *ptr; s32 index; gGroundObjects = MemoryAlloc(sizeof(GroundObject) * NUM_GROUND_OBJECTS, 6); - + for(index = 0, ptr = &gGroundObjects[index]; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) { ptr->kind |= -1; @@ -215,7 +215,7 @@ void DeleteGroundObjects(void) { GroundObject *ptr; s32 index; - + ptr = &gGroundObjects[0]; for(index = 0; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) { @@ -327,7 +327,7 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s { s32 sVar3; s32 sVar4; - + int index; s32 kind; GroundObject *parent; @@ -336,13 +336,13 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s register s32 sector; bool8 bVar12; struct GroundObjectTypeData *typeDataPtr; - + id = (s16)id_; group = (s16)group_; sector = (s8)sector_; - - + + kind = objectData->kind; if (kind == 0x1a) { if (GetScriptVarValue(NULL,BASE_LEVEL) < 2) { @@ -359,20 +359,20 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s kind = (s16)sVar3; } } - + typeDataPtr = &gGroundObjectTypes[kind]; - + if (id < 0) { - + switch(kind) { case 0xD: case 0xE: id = GroundObject_Find(kind); break; - + } - + if (id < 0) { for(index = 0, parent = gGroundObjects; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), parent++) { @@ -382,11 +382,11 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s break; } } - + } if (id < 0) { return -1; - } + } } parent = &gGroundObjects[id]; Log(0,"GroundObject Add id %3d kind %3d[%3d] type %3d group %3d sector %3d",id,kind,objectData->kind,typeDataPtr->unk0,group,sector); @@ -441,7 +441,7 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s parent->flags = 0x2000185; break; } - + if (typeDataPtr->unk2 == '\0') { parent->unkC.x = objectData->width << 0xb; parent->unkC.y = objectData->height << 0xb; @@ -450,13 +450,13 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s parent->unkC.x = typeDataPtr->unk2 << 0xb; parent->unkC.y = typeDataPtr->unk3 << 0xb; } - + parent->unk14.x = parent->unkC.x / 2; parent->unk14.y = parent->unkC.y / 2; parent->direction1 = objectData->unk1; - + SetUnkInGroundEvent(&objectData->pos, &parent->unk20); - + if (bVar12) { parent->direction = parent->direction1; parent->unk124.x = parent->unk20.x - parent->unk14.x; @@ -472,17 +472,17 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s parent->unk140 = 0; sub_80A75CC(&(parent->unk144),id,parent->kind, parent->flags); } - + InitActionWithParams(&parent->action,&gGroundObjectCallbacks,parent,group,sector); - + // What an ugly way of coding that... - SetPredefinedScript(&parent->action,1, (objectData->scripts[1] != NULL) ? objectData->scripts[1] + SetPredefinedScript(&parent->action,1, (objectData->scripts[1] != NULL) ? objectData->scripts[1] : (SpriteHasPokemonSize_80A66A4(&parent->unk144)) ? gUnknown_8118350 : gUnknown_81182F4); - SetPredefinedScript(&parent->action,2,(objectData->scripts[2] != NULL) ? objectData->scripts[2] + SetPredefinedScript(&parent->action,2,(objectData->scripts[2] != NULL) ? objectData->scripts[2] : gFunctionScriptTable[4].script); - SetPredefinedScript(&parent->action,3,(objectData->scripts[3] != NULL) ? objectData->scripts[3] + SetPredefinedScript(&parent->action,3,(objectData->scripts[3] != NULL) ? objectData->scripts[3] : gFunctionScriptTable[8].script); - + if (objectData->scripts[0] != NULL) { SetPredefinedScript(&parent->action,0,objectData->scripts[0]); ExecutePredefinedScript(&parent->action,NULL,0,DEBUG_LOC_PTR(gGroundObjectFileName, 0x283, "GroundObject_Add")); @@ -493,10 +493,10 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s void sub_80A6688(struct UnkGroundSpriteStruct *, s32); -void GroundObject_Delete(s32 index_) { +void GroundObject_Delete(s32 index_) { s32 index = (s16)index_; - GroundObject *parent = &gGroundObjects[index]; - + GroundObject *parent = &gGroundObjects[index]; + Log(0, "GroundObject Delete id %3d", index); sub_80A7658(&parent->unk144); InitAction2(&parent->action); @@ -577,7 +577,7 @@ bool8 GroundObjectsNotifyAll(s32 index_) s32 counter; GroundObject *parent = &gGroundObjects[0]; bool8 flag = FALSE; - + for(counter = 0; counter < NUM_GROUND_OBJECTS; counter = (s16)(counter + 1), parent++) { if(parent->kind != -1) @@ -592,7 +592,7 @@ bool8 GroundObjectsCancelAll(void) s32 counter; GroundObject *parent = &gGroundObjects[0]; bool8 flag = FALSE; - + for(counter = 0; counter < NUM_GROUND_OBJECTS; counter = (s16)(counter + 1), parent++) { if(parent->kind != -1) @@ -644,8 +644,8 @@ s16 sub_80AC448(s32 index_, PixelPos *pos) pos->y = 0; } else { - pos->x = parent->unk124.x + parent->unk14.x; - pos->y = parent->unk124.y + parent->unk14.y; + pos->x = parent->unk124.x + parent->unk14.x; + pos->y = parent->unk124.y + parent->unk14.y; } return parent->kind; @@ -660,7 +660,7 @@ s16 sub_80AC49C(s32 index_, PixelPos *pos) GroundObject *parent = &gGroundObjects[index]; TryMoveObjectRelative_80AC6AC(parent, pos); - + return parent->kind; } @@ -690,7 +690,7 @@ s32 sub_80AC554(s32 flag, PixelPos *param_2,PixelPos *param_3) { s32 i; GroundObject *parent; - + parent = &gGroundObjects[0]; for(i = 0; i < NUM_GROUND_OBJECTS; i = (s16)(i + 1), parent++) { if ((parent->kind != -1)) @@ -709,7 +709,6 @@ s32 sub_80AC554(s32 flag, PixelPos *param_2,PixelPos *param_3) } bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); -s32 GetLivesCollision_80A92A0(s32 id, u32 flags, PixelPos *, PixelPos *); s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPos *param_3) { @@ -746,7 +745,7 @@ s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1,PixelPos *param_2) s32 ret = GetObjectCollision_80AC5F4(param_1,&local_1c,&local_14); if (ret == 0) { (param_1->unk124) = local_1c; - param_1->unk12C = local_14; + param_1->unk12C = local_14; return 0; } return ret; @@ -808,7 +807,7 @@ s32 TryMoveRelative_80AC720(GroundObject *param_1,PixelPos *param_2) return ret; } -static s16 CallbackObjectGetIndex(void *ptr) +static s16 CallbackObjectGetIndex(void *ptr) { struct GroundObject *groundObject = ptr; return groundObject->id; @@ -1027,7 +1026,7 @@ void GroundObject_Action(void) void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); extern bool8 sub_80A66D4(struct UnkGroundSpriteStruct *ptr); -void sub_80ACAD4(void) +void sub_80ACAD4(void) { GroundObject *objectPtr; int i; @@ -1038,7 +1037,7 @@ void sub_80ACAD4(void) minus1 = (s16) minus1; if (objectPtr->kind != (s16) minus1) { PixelPos pos = {objectPtr->unk124.x + (objectPtr->unk14).x, objectPtr->unk124.y + (objectPtr->unk14).y}; - s32 num = objectPtr->unk134.x + objectPtr->unk134.y; + s32 num = objectPtr->unk134.x + objectPtr->unk134.y; if ((sub_80A66D4(&objectPtr->unk144))) { objectPtr->directionRelated = 0; sub_80A6EFC(&objectPtr->unk144,objectPtr->unk13E & 0x1f00,(s8)objectPtr->unk13E); diff --git a/src/ground_script.c b/src/ground_script.c index 6b97d2971..38e3edfe4 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -56,19 +56,15 @@ void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); void GroundMap_GetStationScript(ScriptInfoSmall *out, s16, s32, s32); void GroundObject_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); void GroundEffect_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); -void GroundLives_Select(s32, s32 group, s32 sector); void GroundObject_Select(s32, s32 group, s32 sector); void GroundEffect_Select(s32, s32 group, s32 sector); void GroundEvent_Select(s32, s32 group, s32 sector); -void GroundLives_Cancel(s32 group, s32 sector); void GroundObject_Cancel(s32 group, s32 sector); void GroundEffect_Cancel(s32 group, s32 sector); void GroundEvent_Cancel(s32 group, s32 sector); -void GroundLives_CancelBlank_1(void); void GroundObject_CancelBlank(void); void GroundEffect_CancelBlank(void); void GroundWeather_Select(s16); -u32 GroundLives_ExecutePlayerScriptActionLives(); s16 GroundObject_Add(s16 id, GroundObjectData*, s16 group, s8 sector); s16 GroundEffect_Add(s16 id, GroundEffectData*, s16 group, s8 sector); @@ -99,20 +95,11 @@ void sub_809D1E4(s32, s32, s32); void sub_809D208(s32, PixelPos*, s32); void sub_809D220(s32, s32, s32); void GroundScriptLockJumpZero(s16); -void sub_80A87AC(s32, s32); -void sub_80A8BD8(s16, s32*); -u32 sub_80A8C2C(); -u32 GroundLives_IsStarterMon(); -Pokemon *sub_80A8D54(s16); -s16 sub_80A8F9C(s32, PixelPos*); -u32 sub_80A9050(); -u32 sub_80A9090(); s16 sub_80AC448(s16, PixelPos*); s32 sub_80AC49C(s16, PixelPos*); s16 sub_80AD360(s16, PixelPos*); s16 sub_80AD3B4(s16, PixelPos*); void DeleteGroundEvents(void); -void DeleteGroundLives(void); void DeleteGroundObjects(void); void DeleteGroundEffects(void); s32 ExecuteScriptCommand(Action *action); @@ -130,17 +117,13 @@ u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); extern u8 GroundObjectsCancelAll(void); extern u8 GroundEffectsCancelAll(void); -extern u8 GroundLivesCancelAll(void); extern u8 IsTextboxOpen_809A750(void); -extern Action *sub_80A882C(s32); extern Action *GroundObject_GetAction(s32); extern Action *sub_80AD158(s32); extern void sub_809AB4C(s32, s32); extern void sub_809ABB4(s32, s32); extern void sub_809AC18(s32, s32); -extern s16 sub_80A8BBC(s32 id_); -bool8 GroundLivesNotifyAll(s16); bool8 GroundObjectsNotifyAll(s16); bool8 GroundEffectsNotifyAll(s16); @@ -151,18 +134,11 @@ void ResetMailbox(void); void sub_80963FC(void); void sub_8096488(void); bool8 sub_80964B4(void); -s16 sub_80A8C4C(); bool8 sub_8097640(); u8 sub_80964E4(); -s32 sub_80A8E9C(); -u8 sub_80A8D20(); -bool8 sub_80A87E0(); -s16 sub_80A8BFC(s16); -void sub_80A8F50(const u8 *buffer, s32, s32 size); void sub_80A56A0(s32, s32); void sub_80A56F0(PixelPos *); void sub_80A5704(PixelPos *); -void sub_80A86C8(s16, s32); void sub_80AC1B0(s16, s32); void sub_80AD0C8(s16, s32); s32 sub_80A5984(); @@ -1172,7 +1148,7 @@ s16 HandleAction(Action *action, DebugLocation *debug) if (val == 1) { s32 id = (s16)cmd.arg1; if (id != -1) { - Pokemon *mon = sub_80A8D54(id); + Pokemon *mon = sub_80A8D54((s16) id); s32 i; for (i = 0; i < POKEMON_NAME_LENGTH; i++) { mon->name[i] = sPokeNameBuffer[i]; @@ -1768,7 +1744,7 @@ s32 ExecuteScriptCommand(Action *action) } case 0x21: { s32 ret; - s32 unk; + u32 unk; PixelPos pos1; PixelPos pos2; PixelPos pos3; @@ -1985,7 +1961,7 @@ s32 ExecuteScriptCommand(Action *action) case 0x3d: { int i; if ((s16)curCmd.arg1 != -1) { - Pokemon *mon = sub_80A8D54(curCmd.arg1); + Pokemon *mon = sub_80A8D54((s16) curCmd.arg1); if (mon != NULL) { for (i = 0; i < POKEMON_NAME_LENGTH; i++) { sPokeNameBuffer[i] = mon->name[i]; @@ -2760,19 +2736,19 @@ s32 ExecuteScriptCommand(Action *action) } case 0xbd: { if (sub_80026CC(curCmd.arg1)) { - scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); + scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xbf: { if (HasItemInInventory(curCmd.argShort) > 0) { - scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); + scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xbe: { if (action->unk8.unk0 == 1) { - if ((s8)GroundLives_IsStarterMon(action->unk8.unk2)) { + if (GroundLives_IsStarterMon(action->unk8.unk2)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } } @@ -3129,7 +3105,7 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) { u8 text[0x100]; DungeonLocation dungLocation; - s32 ret = sub_80A8C4C(action->unkC.unk2, &dungLocation); + s32 ret = (s16) sub_80A8C4C(action->unkC.unk2, &dungLocation); if (ret != 0) { s32 dialogueId; @@ -3188,7 +3164,7 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) } return 0; case 0x11: - return sub_80A8D20() == 0 ? 0 : 1; + return sub_80A8D20() != FALSE; case 0x12: { s32 held = gRealInputs.held; @@ -3200,10 +3176,8 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) case 0x13: { - Pokemon *ptr; - - ptr = sub_80A8D54(r2); - if(ptr) + Pokemon *ptr = sub_80A8D54((s16) r2); + if (ptr) return PokemonFlag2(ptr); } return 0; @@ -3745,17 +3719,13 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) case 0x3C: { s32 index; - index = 0; - for(index = 0; index < 0x18; index = (s16)(index + 1)) - { + for (index = 0; index < 0x18; index = (s16)(index + 1)) { sub_80A86C8(index, 0x400000); } - for (index = 0; index < 0x10; index = (s16)(index + 1)) - { + for (index = 0; index < 0x10; index = (s16)(index + 1)) { sub_80AC1B0(index, 0x400000); } - for (index = 0; index < 0x10; index = (s16)(index + 1)) - { + for (index = 0; index < 0x10; index = (s16)(index + 1)) { sub_80AD0C8(index, 0x400000); } } @@ -3912,27 +3882,28 @@ void GroundScript_Unlock(void) s32 index; bool8 cond; - if(gAnyScriptLocked == 0) return; + if (gAnyScriptLocked == 0) return; gAnyScriptLocked = 0; index = 0; for (index = 0; index < SCRIPT_LOCKS_ARR_COUNT; index++) { - if(gScriptLocks[index] != 0) { + if (gScriptLocks[index] != 0) { Log(1, "GroundScript unlock %3d", index); - cond = GroundMapNotifyAll(index); - cond |= GroundLivesNotifyAll(index); - cond |= GroundObjectsNotifyAll(index); - cond |= GroundEffectsNotifyAll(index); + cond = GroundMapNotifyAll((s16) index); + cond |= GroundLivesNotifyAll((s16) index); + cond |= GroundObjectsNotifyAll((s16) index); + cond |= GroundEffectsNotifyAll((s16) index); - if(gScriptLockConds[index] != 0) { + if (gScriptLockConds[index] != 0) { if (cond) { - GroundMapNotifyAll(index | 0x80); - GroundLivesNotifyAll(index | 0x80); - GroundObjectsNotifyAll(index | 0x80); - GroundEffectsNotifyAll(index | 0x80); + GroundMapNotifyAll((s16) (index | 0x80)); + GroundLivesNotifyAll((s16) (index | 0x80)); + GroundObjectsNotifyAll((s16) (index | 0x80)); + GroundEffectsNotifyAll((s16) (index | 0x80)); gScriptLocks[index] = gScriptLockConds[index] = 0; } - } else { + } + else { gScriptLocks[index] = 0; } } @@ -4003,21 +3974,21 @@ static const ScriptCommand *ResolveJump(Action *action, s32 r1) static void sub_80A2500(s32 param_1, ActionUnkIds *param_2) { if (param_2->unk0 == 1) { - sub_809AB4C((s16) param_1, sub_80A8BBC(param_2->unk2)); + sub_809AB4C((s16) param_1, (s16) sub_80A8BBC(param_2->unk2)); } } static void sub_80A252C(s32 param_1, ActionUnkIds *param_2) { if (param_2->unk0 == 1) { - sub_809ABB4((s16) param_1, sub_80A8BBC(param_2->unk2)); + sub_809ABB4((s16) param_1, (s16) sub_80A8BBC(param_2->unk2)); } } static void sub_80A2558(s32 param_1, ActionUnkIds *param_2) { if (param_2->unk0 == 1) { - sub_809AC18((s16) param_1, sub_80A8BBC(param_2->unk2)); + sub_809AC18((s16) param_1, (s16) sub_80A8BBC(param_2->unk2)); } } diff --git a/src/textbox.c b/src/textbox.c index 29baf7de5..736292b10 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -115,11 +115,6 @@ static IWRAM_INIT struct Textbox *sTextbox = { NULL }; extern bool8 sub_802FCF0(void); bool8 IsTextboxOpen_809B40C(struct TextboxText *); -extern void sub_80A8EC0(u8 *, u32); -Pokemon *sub_80A8D54(s16); -void sub_80A7DDC(s16 *, s16*); -u8 IsStarterMonster(s16); -s16 sub_80A8BFC(s32); void sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); bool8 sub_809B18C(s32 *sp); extern void GroundScriptLock(s16 index, s32 r1); From 782e0b817bfc3b4ac5b569207c473a596a1a4e26 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 21 Oct 2025 12:39:54 +0200 Subject: [PATCH 02/13] ground sprite ground lives externs --- include/ground_event.h | 8 +++++ include/ground_lives.h | 2 ++ include/ground_sprite.h | 15 ++++++-- include/ground_sprite_monster.h | 12 +++++++ src/ground_effect.c | 36 +++++++++---------- src/ground_event.c | 11 +++--- src/ground_lives.c | 63 +++++++++++++++------------------ src/ground_main.c | 13 ++----- src/ground_object.c | 18 ++++------ src/ground_script.c | 4 +-- src/ground_sprite.c | 4 +-- src/ground_sprite_monster.c | 1 + 12 files changed, 98 insertions(+), 89 deletions(-) create mode 100644 include/ground_sprite_monster.h diff --git a/include/ground_event.h b/include/ground_event.h index 84b2347be..bec4c6f95 100644 --- a/include/ground_event.h +++ b/include/ground_event.h @@ -2,7 +2,15 @@ #define GUARD_GROUND_EVENT_H #include "structs/str_position.h" +#include "structs/str_ground_script.h" +void AllocGroundEvents(void); +void DeleteGroundEvents(void); +void FreeGroundEvents(void); +void GroundEvent_Select(s32 scriptID, s32 group, s32 sector); +void GroundEvent_Cancel(s32 scriptID, s32 sector); +bool8 sub_80ADC64(s32 id, ScriptInfoSmall *dst); s16 FindGroundEvent(u32 flags, PixelPos *arg1, PixelPos *arg2); +void nullsub_124(void); #endif // GUARD_GROUND_EVENT_H diff --git a/include/ground_lives.h b/include/ground_lives.h index 458ea84ad..ff91636fe 100644 --- a/include/ground_lives.h +++ b/include/ground_lives.h @@ -42,5 +42,7 @@ s32 sub_80A9050(s32 id_, s8 *a1); s32 sub_80A9090(s32 id_, s32 a1_); s16 GetFriendAreaDialogueId(s32 id_); s32 GetLivesCollision_80A92A0(s32 id_, u32 flags, PixelPos *pixelPos1, PixelPos *pixelPos2); +void GroundLives_Action(void); +void sub_80ABA7C(void); #endif // GUARD_GROUND_LIVES_H diff --git a/include/ground_sprite.h b/include/ground_sprite.h index a6f9bdf54..87f7c4766 100644 --- a/include/ground_sprite.h +++ b/include/ground_sprite.h @@ -63,15 +63,24 @@ typedef struct unkStruct_3001B7C unkStruct_3001B7C_sub108 unk108[UNK_3001B7C_SUB108_COUNT]; } unkStruct_3001B7C; -void GroundSprite_Reset(s32); -void GroundSprite_ExtendPaletteAdd(struct UnkGroundSpriteStruct *ptr, u16); -void GroundSprite_ExtendPaletteDelete(struct UnkGroundSpriteStruct *ptr); +void sub_80A62F0(void); +void GroundSprite_Reset(s32 a0); +void sub_80A658C(void); +void sub_80A6688(struct UnkGroundSpriteStruct *ptr, s32 a0); +bool8 SpriteHasPokemonSize_80A66A4(struct UnkGroundSpriteStruct *ptr); +bool8 sub_80A66D4(struct UnkGroundSpriteStruct *ptr); bool8 IsOnscreen_80A675C(struct UnkGroundSpriteStruct *ptr, PixelPos *pixPosArg); void sub_80A67CC(struct UnkGroundSpriteStruct *ptr, struct UnkGroundSpriteSubStructx48 *a1, s32 a2); void sub_80A68A0(struct UnkGroundSpriteStruct *ptr); +void GroundSprite_ExtendPaletteAdd(struct UnkGroundSpriteStruct *ptr, u16 a1); +void GroundSprite_ExtendPaletteDelete(struct UnkGroundSpriteStruct *ptr); +void sub_80A6E68(void); +void sub_80A6E80(void); +void sub_80A6EC8(struct UnkGroundSpriteStruct *ptr, s32 a1); void sub_80A6EFC(struct UnkGroundSpriteStruct *ptr, s32 a1_, s32 a2_); void sub_80A7040(struct UnkGroundSpriteStruct *ptr, s32 a1_, s32 a2_, s32 a3); bool8 sub_80A7094(struct UnkGroundSpriteStruct *ptr, PixelPos *r10, PixelPos *posArg, s32 a3); bool8 sub_80A7310(struct UnkGroundSpriteStruct *ptr, PixelPos *posArg1, PixelPos *posArg2, s32 a3); +void sub_80A73EC(void); #endif // GUARD_GROUND_SPRITE_H diff --git a/include/ground_sprite_monster.h b/include/ground_sprite_monster.h new file mode 100644 index 000000000..0f685af09 --- /dev/null +++ b/include/ground_sprite_monster.h @@ -0,0 +1,12 @@ +#ifndef GUARD_GROUND_SPRITE_MONSTER_H +#define GUARD_GROUND_SPRITE_MONSTER_H + +#include "ground_sprite.h" +#include "structs/str_position.h" + +void sub_80A7428(struct UnkGroundSpriteStruct *ptr, s32 a1_, s32 monsterId_, s32 a3); +void sub_80A74E4(struct UnkGroundSpriteStruct *ptr); +void sub_80A74F0(struct UnkGroundSpriteStruct *ptr, s32 a1_, s32 a2_, s32 a3); +void sub_80A7524(struct UnkGroundSpriteStruct *ptr, s32 monsterId_, PixelPos *pixelPosArg, s32 a3); + +#endif // GUARD_GROUND_SPRITE_MONSTER_H diff --git a/src/ground_effect.c b/src/ground_effect.c index 96199ba05..aa1a262a8 100644 --- a/src/ground_effect.c +++ b/src/ground_effect.c @@ -58,13 +58,11 @@ bool8 GetCurrentDungeonBounds(PixelPos *, PixelPos *); void sub_80A7688(struct UnkGroundSpriteStruct *ptr, s32 unused, s32 a2_, s32 a3); extern void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); void sub_80A7714(struct UnkGroundSpriteStruct *); -void sub_80A6688(struct UnkGroundSpriteStruct *, s32); extern bool8 GroundScriptNotify(Action*, s32); extern bool8 GroundScript_Cancel(Action *r0); s32 sub_80AD3E0(GroundEffect *, PixelPos *); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); -bool8 sub_80A66D4(struct UnkGroundSpriteStruct *ptr); void sub_80A7720(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); @@ -112,7 +110,9 @@ static const CallbackData gGroundEffectCallbacks = { }; extern const u8 gUnknown_81185D8[]; #define FAKE_FILENAME gUnknown_81185D8 - + + + @@ -165,10 +165,10 @@ void AllocGroundEffects(void) { s32 index; GroundEffect* current; - + gGroundEffects = MemoryAlloc(NUM_GROUND_EFFECTS * sizeof(GroundEffect), 6); current = gGroundEffects; - for (index = 0; index < NUM_GROUND_EFFECTS; index = (s16) (index + 0x1), current++) { + for (index = 0; index < NUM_GROUND_EFFECTS; index = (s16) (index + 0x1), current++) { current->kind = -1; } DeleteGroundEffects(); @@ -179,9 +179,9 @@ void DeleteGroundEffects(void) { s32 index; GroundEffect* current; - + current = gGroundEffects; - for (index = 0; index < NUM_GROUND_EFFECTS; index = (s16) (index + 0x1), current++) { + for (index = 0; index < NUM_GROUND_EFFECTS; index = (s16) (index + 0x1), current++) { if(current->kind != -1) GroundEffect_Delete(index); } @@ -319,7 +319,7 @@ s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData,s32 _group,s32 } if (id < 0) { return -1; - } + } parent = &gGroundEffects[id]; Log(0,"GroundEffect Add id %3d kind %3d type %3d group %3d sector %3d",id,effectData->kind,puVar4->type,group,sector); @@ -384,7 +384,7 @@ s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData,s32 _group,s32 if (puVar4->type == 1) { script = gFunctionScriptTable[58].script; } - if (script == NULL) + if (script == NULL) return id; } SetPredefinedScript(&parent->action,0,script); @@ -412,7 +412,7 @@ void sub_80AD0C8(s32 _id, s32 flags) if(parent->kind != -1) { - parent->flags |= flags; + parent->flags |= flags; sub_80A6688(&parent->unk144, parent->flags); } } @@ -476,7 +476,7 @@ bool8 GroundEffectsNotifyAll(s32 index_) s32 counter; GroundEffect *parent = &gGroundEffects[0]; bool8 flag = FALSE; - + for(counter = 0; counter < NUM_GROUND_EFFECTS; counter = (s16)(counter + 1), parent++) { if(parent->kind != -1) @@ -491,7 +491,7 @@ bool8 GroundEffectsCancelAll(void) s32 counter; GroundEffect *parent = &gGroundEffects[0]; bool8 flag = FALSE; - + for(counter = 0; counter < NUM_GROUND_EFFECTS; counter = (s16)(counter + 1), parent++) { if(parent->kind != -1) @@ -543,8 +543,8 @@ s16 sub_80AD360(s32 index_, PixelPos *pos) pos->y = 0; } else { - pos->x = parent->unk124.x + parent->unk14.x; - pos->y = parent->unk124.y + parent->unk14.y; + pos->x = parent->unk124.x + parent->unk14.x; + pos->y = parent->unk124.y + parent->unk14.y; } return parent->kind; @@ -556,7 +556,7 @@ s16 sub_80AD3B4(s32 index_, PixelPos *pos) GroundEffect *parent = &gGroundEffects[index]; sub_80AD3E0(parent, pos); - + return parent->kind; } @@ -571,7 +571,7 @@ s32 sub_80AD3E0(GroundEffect *param_1,PixelPos *param_2) } else { param_1->unk124 = local_1c; - param_1->unk12C = local_14; + param_1->unk12C = local_14; return 0; } } @@ -604,7 +604,7 @@ s32 sub_80AD430(GroundEffect *param_1,PixelPos *param_2) return 0; } -static s16 CallbackEffectGetIndex(void *ptr) +static s16 CallbackEffectGetIndex(void *ptr) { struct GroundEffect *groundObject = ptr; return groundObject->id; @@ -829,7 +829,7 @@ void sub_80AD7AC(void) if (objectPtr->kind != (s16)minus1) { PixelPos pos = {objectPtr->unk124.x + (objectPtr->unk14).x, objectPtr->unk124.y + (objectPtr->unk14).y}; - s32 num = objectPtr->unk134.x + objectPtr->unk134.y; + s32 num = objectPtr->unk134.x + objectPtr->unk134.y; if ((sub_80A66D4(&objectPtr->unk144))) { objectPtr->directionRelated = FALSE; diff --git a/src/ground_event.c b/src/ground_event.c index 3d731e9cb..c2fdbe423 100644 --- a/src/ground_event.c +++ b/src/ground_event.c @@ -5,6 +5,7 @@ #include "ground_lives.h" #include "debug.h" #include "memory.h" +#include "ground_script_file.h" typedef struct GroundEvent { @@ -20,10 +21,8 @@ typedef struct GroundEvent IWRAM_INIT GroundEvent *gGroundEvents = NULL; -void DeleteGroundEvents(void); -void GroundEvent_Delete(s32); -const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); -s32 GroundEvent_Add(s32 id, const GroundEventData*, s32 group, s32 sector); +static s32 GroundEvent_Add(s32 id, const GroundEventData *eventData, s32 group, s32 sector); +static void GroundEvent_Delete(s32 id); void AllocGroundEvents(void) { @@ -118,7 +117,7 @@ void GroundEvent_Cancel(s32 scriptID, s32 sector) } } -s32 GroundEvent_Add(s32 id, const GroundEventData *eventData, s32 group, s32 sector) +static s32 GroundEvent_Add(s32 id, const GroundEventData *eventData, s32 group, s32 sector) { s32 i; s32 scriptID_s32 = (s16) id; @@ -179,7 +178,7 @@ s32 GroundEvent_Add(s32 id, const GroundEventData *eventData, s32 group, s32 sec return scriptID_s32; } -void GroundEvent_Delete(s32 id) +static void GroundEvent_Delete(s32 id) { s32 scriptID_s32 = (s16) id; GroundEvent *ptr = &gGroundEvents[scriptID_s32]; diff --git a/src/ground_lives.c b/src/ground_lives.c index 582292bfc..dadc8920b 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -17,6 +17,7 @@ #include "code_8002774.h" #include "friend_area_dialogue.h" #include "ground_lives_helper.h" +#include "ground_sprite_monster.h" struct GroundLivesMeta_Sub1 { @@ -104,12 +105,8 @@ extern const struct GroundLiveTypeData gGroundLivesTypeData_811E63C[]; extern s32 sub_8002984(s32 _direction1, u32 caseID); extern u8 sub_809D248(PixelPos *r0); extern s16 HandleAction(Action *action, const DebugLocation *debug); -extern void sub_80A7524(struct UnkGroundSpriteStruct *ptr, s32 monsterId_, PixelPos *pixelPosArg, s32 a3); -extern bool8 sub_80A66D4(struct UnkGroundSpriteStruct *ptr); -extern void sub_80A74F0(struct UnkGroundSpriteStruct *ptr, s32 a1_, s32 a2_, s32 a3); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); -extern void sub_80A6EC8(struct UnkGroundSpriteStruct *ptr, s32 a1); extern s32 sub_80AC554(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); extern s32 sub_80AC448(s32 id_, PixelPos *pixelPos); extern bool8 sub_80A595C(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); @@ -124,21 +121,21 @@ extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _ extern bool8 sub_809D678(Action *action); extern bool8 GroundObject_GetScript(s32 a0, ScriptInfoSmall *scriptInfo, s32 a2); extern void GroundObject_ExecuteScript(s32, void *, ScriptInfoSmall *); -extern bool8 sub_80ADC64(s32 id, ScriptInfoSmall *dst); extern bool8 GroundScriptNotify(Action *param_1, s32 param_2); extern bool8 GroundScript_Cancel(Action *r0); extern Pokemon *sub_80A8D54(s32); -extern void sub_80A6688(struct UnkGroundSpriteStruct *ptr, s32 a0); extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); -extern void sub_80A7428(struct UnkGroundSpriteStruct *ptr, s32 a1_, s32 monsterId_, s32 a3); extern void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); extern void sub_809D170(s32 r0, s32 r1); -extern void sub_80A74E4(struct UnkGroundSpriteStruct *ptr); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); static s32 sub_80A7B94(s16 *a0); static s32 GroundLives_Add(s32 id_, const GroundLivesData *ptr, s32 group_, s32 sector_); static void GroundLives_Delete(s32 id_); +static bool8 sub_80A9750(struct GroundLive *ptr, u16 a1); +static s32 sub_80A9F20(struct GroundLive *livesPtr, PixelPos *pixelPosArg); +static bool8 sub_80AA3F8(struct GroundLive *livesPtr, s32 a1_); +static void sub_80AAF68(struct GroundLive *livesPtr, u32 unused); static s16 CallbackLivesGetIndex(void *livesPtr_); static void CallbackLivesGetSize(void *livesPtr_, PixelPos *out); static void CallbackLivesSetHitboxPos(void *livesPtr_, PixelPos *posOrNull); @@ -159,13 +156,9 @@ static void CallbackLivesSetFlags(void *livesPtr_, u32 flags); static void CallbackLivesClearFlags(void *livesPtr_, u32 flags); static void CallbackLivesSpriteRelated_80AB238(void *livesPtr_, s32 a1); static s32 CallbackLivesMoveRelative(void *livesPtr_, PixelPos *pos); -bool8 sub_80A9750(struct GroundLive *ptr, u16 a1); -void sub_80AB5A4(void); -s32 sub_80A9F20(struct GroundLive *livesPtr, PixelPos *pixelPos); -bool8 sub_80AA3F8(struct GroundLive *livesPtr, s32 a1); -void sub_80AB5D4(struct GroundLive *livesPtr); -s32 sub_80ABA00(s32); -void sub_80AAF68(struct GroundLive *livesPtr, u32 unused); +static void sub_80AB5A4(void); +static void sub_80AB5D4(struct GroundLive *livesPtr); +static s32 sub_80ABA00(s32 a0); static const CallbackData gGroundLivesCallbacks = { .maybeId = 1, @@ -1591,7 +1584,7 @@ s32 GetLivesCollision_80A92A0(s32 id_, u32 flags, PixelPos *pixelPos1, PixelPos return -1; } -s32 sub_80A9344(s32 id_, u32 flags, PixelPos *pixelPos1, PixelPos *pixelPos2) +static s32 sub_80A9344(s32 id_, u32 flags, PixelPos *pixelPos1, PixelPos *pixelPos2) { s32 i; struct GroundLive *livesPtr; @@ -1614,7 +1607,7 @@ s32 sub_80A9344(s32 id_, u32 flags, PixelPos *pixelPos1, PixelPos *pixelPos2) return -1; } -u8 sub_80A93F0(s32 id_, s32 a1_) +static u8 sub_80A93F0(s32 id_, s32 a1_) { s32 id = (s16) id_; s32 a1 = (u8) a1_; @@ -1626,7 +1619,7 @@ u8 sub_80A93F0(s32 id_, s32 a1_) return sub_80A5934(a1, &pixPos1, &pixPos2); } -s32 sub_80A9488(struct GroundLive *livesPtr, PixelPos *posArg1, PixelPos *posArg2) +static s32 sub_80A9488(struct GroundLive *livesPtr, PixelPos *posArg1, PixelPos *posArg2) { PixelPos pixPos1 = {posArg1->x / 2048, posArg1->y / 2048}; PixelPos posTemp = {((posArg2->x - 1) / 2048), ((posArg2->y - 1) / 2048)}; @@ -1656,7 +1649,7 @@ s32 sub_80A9488(struct GroundLive *livesPtr, PixelPos *posArg1, PixelPos *posArg return 0; } -s32 sub_80A95AC(struct GroundLive *livesPtr, PixelPos *posArg1, PixelPos *posArg2) +static s32 sub_80A95AC(struct GroundLive *livesPtr, PixelPos *posArg1, PixelPos *posArg2) { PixelPos pixPos1 = {posArg1->x / 2048, posArg1->y / 2048}; PixelPos posTemp = {((posArg2->x - 1) / 2048), ((posArg2->y - 1) / 2048)}; @@ -1710,7 +1703,7 @@ s32 sub_80A95AC(struct GroundLive *livesPtr, PixelPos *posArg1, PixelPos *posArg return 0; } -bool8 sub_80A9750(struct GroundLive *livesPtr, u16 a1) +static bool8 sub_80A9750(struct GroundLive *livesPtr, u16 a1) { s32 r2; u16 f1 = a1 & 0xFF; @@ -1817,7 +1810,7 @@ bool8 sub_80A9750(struct GroundLive *livesPtr, u16 a1) return FALSE; } -s32 sub_80A9F20(struct GroundLive *livesPtr, PixelPos *pixelPosArg) +static s32 sub_80A9F20(struct GroundLive *livesPtr, PixelPos *pixelPosArg) { s32 ret; PixelPos pixPos1, pixPos2; @@ -1845,7 +1838,7 @@ s32 sub_80A9F20(struct GroundLive *livesPtr, PixelPos *pixelPosArg) } } -s32 sub_80A9F94(struct GroundLive *livesPtr, PixelPos *pixelPosArg) +static s32 sub_80A9F94(struct GroundLive *livesPtr, PixelPos *pixelPosArg) { s32 ret; bool8 changed; @@ -1898,7 +1891,7 @@ s32 sub_80A9F94(struct GroundLive *livesPtr, PixelPos *pixelPosArg) } } -s32 sub_80AA074(struct GroundLive *livesPtr, PixelPos *pixelPosArg) +static s32 sub_80AA074(struct GroundLive *livesPtr, PixelPos *pixelPosArg) { s32 ret; PixelPos pixPos1, pixPos2; @@ -1949,7 +1942,7 @@ s32 sub_80AA074(struct GroundLive *livesPtr, PixelPos *pixelPosArg) return ret; } -s32 sub_80AA180(struct GroundLive *livesPtr, u32 flags, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) +static s32 sub_80AA180(struct GroundLive *livesPtr, u32 flags, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) { PixelPos pixPos1, pixPos2; @@ -2003,7 +1996,7 @@ s32 sub_80AA180(struct GroundLive *livesPtr, u32 flags, PixelPos *pixelPosArg1, return 0; } -s32 sub_80AA2BC(struct GroundLive *livesPtr, u32 flags, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) +static s32 sub_80AA2BC(struct GroundLive *livesPtr, u32 flags, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) { PixelPos pixPos1, pixPos2, pixPos3; PixelPos posTemp; @@ -2042,7 +2035,7 @@ s32 sub_80AA2BC(struct GroundLive *livesPtr, u32 flags, PixelPos *pixelPosArg1, return 0; } -bool8 sub_80AA3F8(struct GroundLive *livesPtr, s32 a1_) +static bool8 sub_80AA3F8(struct GroundLive *livesPtr, s32 a1_) { s32 i; s32 a1 = (s8) a1_; @@ -2131,7 +2124,7 @@ bool8 sub_80AA3F8(struct GroundLive *livesPtr, s32 a1_) return FALSE; } -s32 sub_80AA660(struct GroundLive *livesPtr, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) +static s32 sub_80AA660(struct GroundLive *livesPtr, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) { s32 id = (s16) sub_80AC4C8(0x100, pixelPosArg1, pixelPosArg2); @@ -2143,7 +2136,7 @@ s32 sub_80AA660(struct GroundLive *livesPtr, PixelPos *pixelPosArg1, PixelPos *p return 0; } -bool8 sub_80AA690(struct GroundLive *livesPtr, s32 a1_) +static bool8 sub_80AA690(struct GroundLive *livesPtr, s32 a1_) { s32 i; s32 a1 = (s8) a1_; @@ -2183,7 +2176,7 @@ bool8 sub_80AA690(struct GroundLive *livesPtr, s32 a1_) return FALSE; } -s32 sub_80AA7B0(struct GroundLive *livesPtr, s16 *a1, u32 flags, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) +static s32 sub_80AA7B0(struct GroundLive *livesPtr, s16 *a1, u32 flags, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2) { PixelPos pixPos1 = *pixelPosArg1; PixelPos pixPos3 = *pixelPosArg2; @@ -2211,7 +2204,7 @@ s32 sub_80AA7B0(struct GroundLive *livesPtr, s16 *a1, u32 flags, PixelPos *pixel return 0; } -bool8 sub_80AA8BC(struct GroundLive *livesPtr, s16 *a1, s32 dir_) +static bool8 sub_80AA8BC(struct GroundLive *livesPtr, s16 *a1, s32 dir_) { s32 i; s32 dir = (s8) dir_; @@ -2288,7 +2281,7 @@ bool8 sub_80AA8BC(struct GroundLive *livesPtr, s16 *a1, s32 dir_) return FALSE; } -void sub_80AAAE8(struct GroundLive *livesPtr, u32 a1, s32 dir_, s32 unused) +static void sub_80AAAE8(struct GroundLive *livesPtr, u32 a1, s32 dir_, s32 unused) { s32 unk; s32 dir = (s8) dir_; @@ -2508,7 +2501,7 @@ void sub_80AAAE8(struct GroundLive *livesPtr, u32 a1, s32 dir_, s32 unused) } } -void sub_80AAF68(struct GroundLive *livesPtr, u32 unused) +static void sub_80AAF68(struct GroundLive *livesPtr, u32 unused) { if (livesPtr->flags & 0x4000) { if (sub_80A93F0(livesPtr->id, 1)) { @@ -2866,7 +2859,7 @@ void GroundLives_Action(void) } } -void sub_80AB5A4(void) +static void sub_80AB5A4(void) { struct GroundLivesMeta_Sub1 *loopPtr; s32 i; @@ -2882,7 +2875,7 @@ void sub_80AB5A4(void) } } -void sub_80AB5D4(struct GroundLive *livesPtr) +static void sub_80AB5D4(struct GroundLive *livesPtr) { struct GroundLivesMeta_Sub1 *metaPtr = &gGroundLivesMeta->unk0[livesPtr->unk13C]; @@ -3059,7 +3052,7 @@ void sub_80AB5D4(struct GroundLive *livesPtr) } } -s32 sub_80ABA00(s32 a0) +static s32 sub_80ABA00(s32 a0) { s32 i; s32 ret = 0; diff --git a/src/ground_main.c b/src/ground_main.c index d37d070ca..c54f864a2 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -25,6 +25,8 @@ #include "unk_ds_only_feature.h" #include "textbox.h" #include "ground_lives.h" +#include "ground_event.h" +#include "ground_sprite.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -64,7 +66,6 @@ extern void sub_8095494(DungeonMailSeed *param_1, u8 index); extern u16 gUnknown_2026E4E; // TODO: Move these externs to headers -extern void GroundSprite_Reset(s32); extern s16 sub_8098FCC(u32 unused); extern s16 sub_80A2654(s16 r0); extern bool8 sub_809AFAC(void); @@ -73,8 +74,6 @@ extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); extern void FreeGroundObjects(void); extern void FreeGroundEffects(void); -extern void FreeGroundEvents(void); -extern void sub_80A658C(void); extern void sub_809D508(void); extern void nullsub_119(void); extern void sub_8099768(void); @@ -83,12 +82,8 @@ extern void sub_8099648(void); extern void sub_809975C(void); extern void sub_809D0AC(void); extern void sub_809D490(void); -extern void sub_80A62F0(void); -extern void AllocGroundEvents(void); extern void AllocGroundObjects(void); extern void AllocGroundEffects(void); -extern void nullsub_124(void); -extern void GroundLives_Action(void); extern void GroundObject_Action(void); extern void GroundEffect_Action(void); extern void sub_809B474(void); @@ -96,7 +91,6 @@ extern void GroundScript_Unlock(); extern void sub_809D25C(void); extern void sub_80A59DC(void); extern void sub_809B614(void); -extern void sub_80A6E80(void); extern void sub_8099BE4(void); extern void sub_8099744(void); extern void WaitForNextFrameAndAdvanceRNG(void); @@ -104,16 +98,13 @@ extern void LoadBufferedInputs(void); extern void nullsub_120(void); extern void sub_80A5E70(void); extern void sub_809B638(void); -extern void sub_80A73EC(void); extern void sub_8099750(void); extern void sub_809D0BC(void); -extern void DeleteGroundEvents(void); extern void DeleteGroundObjects(void); extern void DeleteGroundEffects(void); extern void nullsub_16(void); extern void UpdateAdventureAchievements(void); extern void xxx_call_update_bg_sound_input(void); -extern void sub_80A6E68(void); extern void sub_80060EC(void); extern void sub_809977C(void); extern void UpdateFadeInTile(s32); diff --git a/src/ground_object.c b/src/ground_object.c index 9b3b4968e..ddca38a9f 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -6,6 +6,7 @@ #include "event_flag.h" #include "ground_script.h" #include "ground_sprite.h" +#include "ground_lives.h" #include "memory.h" typedef struct GroundObject { @@ -57,7 +58,6 @@ void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_ extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); void sub_80A75CC(void *, s32, s32, s32); -bool8 SpriteHasPokemonSize_80A66A4(struct UnkGroundSpriteStruct *ptr); s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 sector_); @@ -490,10 +490,8 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s return id; } - -void sub_80A6688(struct UnkGroundSpriteStruct *, s32); - -void GroundObject_Delete(s32 index_) { +void GroundObject_Delete(s32 index_) +{ s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; @@ -716,13 +714,12 @@ s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPo PixelPos iVar1 = { (param_3->x - 1) / 2048, (param_3->y - 1) / 2048 }; PixelPos local_20 = { (iVar1.x - local_28.x) + 1, (iVar1.y - local_28.y) + 1 }; - if (param_1->flags & 1) - { - if(CheckMapCollision_80A585C(&local_28,&local_20)) + if (param_1->flags & 1) { + if (CheckMapCollision_80A585C(&local_28,&local_20)) return 1; } - if (((param_1->flags & 4))) { - if(((s16)GetLivesCollision_80A92A0(-1,4,param_2,param_3) >= 0)) + if (param_1->flags & 4) { + if ((s16) GetLivesCollision_80A92A0(-1,4,param_2,param_3) >= 0) return 4; } return 0; @@ -1024,7 +1021,6 @@ void GroundObject_Action(void) } void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); -extern bool8 sub_80A66D4(struct UnkGroundSpriteStruct *ptr); void sub_80ACAD4(void) { diff --git a/src/ground_script.c b/src/ground_script.c index 38e3edfe4..5b4bac483 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -50,6 +50,7 @@ #include "ground_map_conversion_table.h" #include "unk_ds_only_feature.h" #include "textbox.h" +#include "ground_event.h" void GroundMap_Select(s16); void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); @@ -58,10 +59,8 @@ void GroundObject_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); void GroundEffect_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); void GroundObject_Select(s32, s32 group, s32 sector); void GroundEffect_Select(s32, s32 group, s32 sector); -void GroundEvent_Select(s32, s32 group, s32 sector); void GroundObject_Cancel(s32 group, s32 sector); void GroundEffect_Cancel(s32 group, s32 sector); -void GroundEvent_Cancel(s32 group, s32 sector); void GroundObject_CancelBlank(void); void GroundEffect_CancelBlank(void); void GroundWeather_Select(s16); @@ -99,7 +98,6 @@ s16 sub_80AC448(s16, PixelPos*); s32 sub_80AC49C(s16, PixelPos*); s16 sub_80AD360(s16, PixelPos*); s16 sub_80AD3B4(s16, PixelPos*); -void DeleteGroundEvents(void); void DeleteGroundObjects(void); void DeleteGroundEffects(void); s32 ExecuteScriptCommand(Action *action); diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 399829cde..786541f2a 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -1,13 +1,14 @@ #include "global.h" #include "globaldata.h" +#include "ground_sprite.h" #include "structs/axdata.h" #include "effect_main.h" #include "debug.h" #include "def_filearchives.h" #include "file_system.h" #include "ground_map.h" -#include "ground_sprite.h" #include "ground_sprite_data.h" +#include "ground_lives.h" #include "memory.h" #include "sprite.h" #include "effect_sub_1.h" @@ -29,7 +30,6 @@ static EWRAM_INIT OpenedFile *gUnknown_203B4B4 = {NULL}; // code_8098BDC.s extern void sub_809971C(u16, const u8 *, s16); extern void sub_80997F4(u16, u16); -extern void sub_80ABA7C(void); extern void sub_80ACAD4(void); extern void sub_80AD7AC(void); extern void sub_800E970(void); diff --git a/src/ground_sprite_monster.c b/src/ground_sprite_monster.c index 149f30c73..ea417ae6b 100644 --- a/src/ground_sprite_monster.c +++ b/src/ground_sprite_monster.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "ground_sprite_monster.h" #include "def_filearchives.h" #include "file_system.h" #include "ground_sprite.h" From 1ba6dd86c77c582606a4dcee42ba93f8b226307e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 21 Oct 2025 14:13:57 +0200 Subject: [PATCH 03/13] ground effect externs --- include/ground_effect.h | 23 +++++++++++++++++++++++ src/code_809D148.c | 4 ++-- src/ground_effect.c | 31 +++++++++++++++---------------- src/ground_main.c | 5 +---- src/ground_script.c | 27 ++++++++------------------- src/ground_sprite.c | 2 +- 6 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 include/ground_effect.h diff --git a/include/ground_effect.h b/include/ground_effect.h new file mode 100644 index 000000000..d13f99abf --- /dev/null +++ b/include/ground_effect.h @@ -0,0 +1,23 @@ +#ifndef GUARD_GROUND_EFFECT_H +#define GUARD_GROUND_EFFECT_H + +#include "structs/str_ground_script.h" + +void AllocGroundEffects(void); +void DeleteGroundEffects(void); +void FreeGroundEffects(void); +void GroundEffect_Select(s32 scriptID, s32 group, s32 sector); +void GroundEffect_Cancel(s32 scriptID, s32 sector); +void GroundEffect_CancelBlank(void); +s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData, s32 _group, s32 _sector); +void sub_80AD0C8(s32 _id, s32 flags); +Action *sub_80AD158(s32 index_); +bool8 GroundEffect_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script); +bool8 GroundEffectsNotifyAll(s32 index_); +bool8 GroundEffectsCancelAll(void); +s16 sub_80AD360(s32 index_, PixelPos *pos); +s16 sub_80AD3B4(s32 index_, PixelPos *pos); +void GroundEffect_Action(void); +void sub_80AD7AC(void); + +#endif // GUARD_GROUND_EFFECT_H diff --git a/src/code_809D148.c b/src/code_809D148.c index c042e4efe..c8703c807 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -7,6 +7,7 @@ #include "other_random.h" #include "ground_script.h" #include "ground_lives.h" +#include "ground_effect.h" struct unkStruct_20399E8 { @@ -190,7 +191,6 @@ u8 sub_809D248(PixelPos *r0) // Todo: move these to appropriate header files extern s32 sub_80AC448(s16 a0, PixelPos *a1); -extern s32 sub_80AD360(s16 a0, PixelPos *a1); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); void sub_809D25C(void) @@ -215,7 +215,7 @@ void sub_809D25C(void) gUnknown_20399E8.unk0 = 0; break; case 3: - val = sub_80AD360(gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80AD360((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); if (val == (u16) -1) gUnknown_20399E8.unk0 = 0; break; diff --git a/src/ground_effect.c b/src/ground_effect.c index aa1a262a8..661d5c800 100644 --- a/src/ground_effect.c +++ b/src/ground_effect.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "ground_effect.h" #include "data_script.h" #include "ground_script.h" #include "ground_sprite.h" @@ -49,9 +50,6 @@ extern struct GroundEffectTypeData gGroundEffectTypes[]; extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); -void GroundEffect_Delete(s32); -void DeleteGroundEffects(void); -s32 GroundEffect_Add(s32 _id,const GroundEffectData *effectData,s32 _group,s32 _sector); const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); bool8 GetCurrentDungeonBounds(PixelPos *, PixelPos *); @@ -60,12 +58,14 @@ extern void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand void sub_80A7714(struct UnkGroundSpriteStruct *); extern bool8 GroundScriptNotify(Action*, s32); extern bool8 GroundScript_Cancel(Action *r0); -s32 sub_80AD3E0(GroundEffect *, PixelPos *); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); void sub_80A7720(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); +extern s16 HandleAction(Action *action, DebugLocation *debug); +static void GroundEffect_Delete(s32 _id); +static s32 sub_80AD3E0(GroundEffect *param_1, PixelPos *param_2); static s16 CallbackEffectGetIndex(void *ptr); static void CallbackEffectGetSize(void *effectPtr_, PixelPos *out); static void CallbackEffectSetHitboxPos(void *effectPtr_, PixelPos *posOrNull); @@ -174,7 +174,6 @@ void AllocGroundEffects(void) DeleteGroundEffects(); } - void DeleteGroundEffects(void) { s32 index; @@ -271,7 +270,8 @@ void GroundEffect_CancelBlank(void) } } -UNUSED s32 GroundEffect_Find(s32 a0_) { +UNUSED static s32 GroundEffect_Find(s32 a0_) +{ s32 index; s32 a0; GroundEffect *ptr; @@ -289,7 +289,7 @@ UNUSED s32 GroundEffect_Find(s32 a0_) { return -1; } -s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData,s32 _group,s32 _sector) +s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData, s32 _group, s32 _sector) { struct GroundEffectTypeData *puVar4; s32 group; @@ -393,7 +393,7 @@ s32 GroundEffect_Add(s32 _id, const GroundEffectData *effectData,s32 _group,s32 return id; } -void GroundEffect_Delete(s32 _id) +static void GroundEffect_Delete(s32 _id) { s32 id = (s16)_id; GroundEffect *parent = &gGroundEffects[id]; @@ -452,7 +452,7 @@ UNUSED static bool8 sub_80AD18C(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_ return FALSE; } -bool8 GroundEffect_ExecuteScript(s32 index_, void *a1, ScriptInfoSmall *script) +bool8 GroundEffect_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script) { s32 index = (s16)index_; GroundEffect *parent = &gGroundEffects[index]; @@ -560,7 +560,7 @@ s16 sub_80AD3B4(s32 index_, PixelPos *pos) return parent->kind; } -s32 sub_80AD3E0(GroundEffect *param_1,PixelPos *param_2) +static s32 sub_80AD3E0(GroundEffect *param_1, PixelPos *param_2) { PixelPos local_1c = {param_2->x - param_1->unk14.x, param_2->y - param_1->unk14.y}; PixelPos local_14 = {param_2->x + param_1->unk14.x, param_2->y + param_1->unk14.y}; @@ -576,7 +576,7 @@ s32 sub_80AD3E0(GroundEffect *param_1,PixelPos *param_2) } } -s32 sub_80AD430(GroundEffect *param_1,PixelPos *param_2) +static s32 sub_80AD430(GroundEffect *param_1, PixelPos *param_2) { PixelPos iVar2 = {param_1->unk124.x + param_2->x, param_1->unk124.y + param_2->y}; PixelPos uVar4 = {param_1->unk12C.x + param_2->x, param_1->unk12C.y + param_2->y}; @@ -693,7 +693,8 @@ static void CallbackEffectSetDirection(void *livesPtr_, s32 direction) } } -static void CallbackEffectSetEventIndex(void *livesPtr_, u16 a1) { +static void CallbackEffectSetEventIndex(void *livesPtr_, u16 a1) +{ struct GroundEffect *livesPtr = livesPtr_; u32 r1; @@ -717,7 +718,8 @@ static void CallbackEffectSetEventIndex(void *livesPtr_, u16 a1) { livesPtr->directionRelated = TRUE; } -static void CallbackEffectSetUnk_80AD670(void *objectPtr_, s32 a1_, s32 a2) { +static void CallbackEffectSetUnk_80AD670(void *objectPtr_, s32 a1_, s32 a2) +{ struct GroundEffect *livesPtr = objectPtr_; s32 a1Match = (s16) a1_; @@ -786,8 +788,6 @@ static s32 CallbackEffectMoveRelative(void *livesPtr_, PixelPos *pos) return sub_80AD430(livesPtr, pos); } -extern s16 HandleAction(Action *action, DebugLocation *debug); - void GroundEffect_Action(void) { GroundEffect *objectPtr; @@ -822,7 +822,6 @@ void sub_80AD7AC(void) s32 i; s32 minus1; - for (objectPtr = &gGroundEffects[0], i = 0, minus1 = -1; i < NUM_GROUND_EFFECTS; i = (s16)(i + 1), objectPtr++) { minus1 = (s16)minus1; diff --git a/src/ground_main.c b/src/ground_main.c index c54f864a2..3cace7b8b 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -27,6 +27,7 @@ #include "ground_lives.h" #include "ground_event.h" #include "ground_sprite.h" +#include "ground_effect.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -73,7 +74,6 @@ extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); extern void FreeGroundObjects(void); -extern void FreeGroundEffects(void); extern void sub_809D508(void); extern void nullsub_119(void); extern void sub_8099768(void); @@ -83,9 +83,7 @@ extern void sub_809975C(void); extern void sub_809D0AC(void); extern void sub_809D490(void); extern void AllocGroundObjects(void); -extern void AllocGroundEffects(void); extern void GroundObject_Action(void); -extern void GroundEffect_Action(void); extern void sub_809B474(void); extern void GroundScript_Unlock(); extern void sub_809D25C(void); @@ -101,7 +99,6 @@ extern void sub_809B638(void); extern void sub_8099750(void); extern void sub_809D0BC(void); extern void DeleteGroundObjects(void); -extern void DeleteGroundEffects(void); extern void nullsub_16(void); extern void UpdateAdventureAchievements(void); extern void xxx_call_update_bg_sound_input(void); diff --git a/src/ground_script.c b/src/ground_script.c index 5b4bac483..432e61ba2 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -51,21 +51,17 @@ #include "unk_ds_only_feature.h" #include "textbox.h" #include "ground_event.h" +#include "ground_effect.h" void GroundMap_Select(s16); void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); void GroundMap_GetStationScript(ScriptInfoSmall *out, s16, s32, s32); void GroundObject_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); -void GroundEffect_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); void GroundObject_Select(s32, s32 group, s32 sector); -void GroundEffect_Select(s32, s32 group, s32 sector); void GroundObject_Cancel(s32 group, s32 sector); -void GroundEffect_Cancel(s32 group, s32 sector); void GroundObject_CancelBlank(void); -void GroundEffect_CancelBlank(void); void GroundWeather_Select(s16); s16 GroundObject_Add(s16 id, GroundObjectData*, s16 group, s8 sector); -s16 GroundEffect_Add(s16 id, GroundEffectData*, s16 group, s8 sector); // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files @@ -96,10 +92,7 @@ void sub_809D220(s32, s32, s32); void GroundScriptLockJumpZero(s16); s16 sub_80AC448(s16, PixelPos*); s32 sub_80AC49C(s16, PixelPos*); -s16 sub_80AD360(s16, PixelPos*); -s16 sub_80AD3B4(s16, PixelPos*); void DeleteGroundObjects(void); -void DeleteGroundEffects(void); s32 ExecuteScriptCommand(Action *action); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); @@ -114,16 +107,13 @@ s32 sub_80A14E8(Action *, u8, u32, s32); u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); extern u8 GroundObjectsCancelAll(void); -extern u8 GroundEffectsCancelAll(void); extern u8 IsTextboxOpen_809A750(void); extern Action *GroundObject_GetAction(s32); -extern Action *sub_80AD158(s32); extern void sub_809AB4C(s32, s32); extern void sub_809ABB4(s32, s32); extern void sub_809AC18(s32, s32); bool8 GroundObjectsNotifyAll(s16); -bool8 GroundEffectsNotifyAll(s16); void sub_8098C58(void); void sub_8098CC8(void); @@ -138,7 +128,6 @@ void sub_80A56A0(s32, s32); void sub_80A56F0(PixelPos *); void sub_80A5704(PixelPos *); void sub_80AC1B0(s16, s32); -void sub_80AD0C8(s16, s32); s32 sub_80A5984(); void sub_80A59A0(s32, s32 *, u16); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); @@ -1651,7 +1640,7 @@ s32 ExecuteScriptCommand(Action *action) sector = (s8)curCmd.argByte < 0 ? scriptData->script.sector : (s8)curCmd.argByte; &eff; }); - res = GroundEffect_Add(-1, eff, group, sector); + res = (s16) GroundEffect_Add(-1, eff, (s16) group, (s8) sector); if (res >= 0) { action->callbacks->getHitboxCenter(action->parentObject, &pos); sub_80AD3B4(res, &pos); @@ -2456,7 +2445,7 @@ s32 ExecuteScriptCommand(Action *action) } case 0x98: { s32 id = action->callbacks->getIndex(action->parentObject); - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_809D170(1, id); break; @@ -2472,7 +2461,7 @@ s32 ExecuteScriptCommand(Action *action) case 0x99: { s32 id = action->callbacks->getIndex(action->parentObject); PixelPos unk; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_80A8FD8(id, &unk); sub_809D158(0, &unk); @@ -2495,7 +2484,7 @@ s32 ExecuteScriptCommand(Action *action) case 0x9b: { s32 id = action->callbacks->getIndex(action->parentObject); if (id < 0) break; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_809D1A8(1, id, curCmd.argShort); return 2; @@ -2511,7 +2500,7 @@ s32 ExecuteScriptCommand(Action *action) case 0x9c: { s32 id = action->callbacks->getIndex(action->parentObject); PixelPos unk; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_80A8FD8(id, &unk); sub_809D190(0, &unk, curCmd.argShort); @@ -2589,7 +2578,7 @@ s32 ExecuteScriptCommand(Action *action) case 0xa2: { s32 id = action->callbacks->getIndex(action->parentObject); PixelPos unk; - switch(action->unk8.unk0) { + switch (action->unk8.unk0) { case 1: sub_80A8FD8(id, &unk); sub_809D208(0, &unk, curCmd.argShort); @@ -3751,7 +3740,7 @@ s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) sp_308.height = 1; sp_308.pos = (CompactPos) {0}; sp_308.script = gFunctionScriptTable[406].script; // MOVE_DEBUG_CAMERA - ret = GroundEffect_Add(-1, &sp_308, r2, r3); + ret = (s16) GroundEffect_Add(-1, &sp_308, (s16) r2, (s8) r3); if(ret < 0) break; r7 = sub_80AD158(ret); sub_80A579C(&sp_340, &sp_348); diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 786541f2a..fb35720a3 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -13,6 +13,7 @@ #include "sprite.h" #include "effect_sub_1.h" #include "pokemon.h" +#include "ground_effect.h" static IWRAM_INIT unkStruct_3001B7C *gUnknown_3001B7C = {NULL}; @@ -31,7 +32,6 @@ static EWRAM_INIT OpenedFile *gUnknown_203B4B4 = {NULL}; extern void sub_809971C(u16, const u8 *, s16); extern void sub_80997F4(u16, u16); extern void sub_80ACAD4(void); -extern void sub_80AD7AC(void); extern void sub_800E970(void); extern u8 sub_809D248(PixelPos *r0); From 1e49003ec9e1c80cb67a3c15b6ccc5ddc40bfae5 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 21 Oct 2025 14:56:12 +0200 Subject: [PATCH 04/13] ground object externs --- include/ground_object.h | 27 ++++++++++++++ src/code_809D148.c | 4 +-- src/ground_lives.c | 7 +--- src/ground_main.c | 5 +-- src/ground_object.c | 78 ++++++++++++++++------------------------- src/ground_script.c | 14 +------- src/ground_sprite.c | 2 +- 7 files changed, 63 insertions(+), 74 deletions(-) create mode 100644 include/ground_object.h diff --git a/include/ground_object.h b/include/ground_object.h new file mode 100644 index 000000000..976f466ef --- /dev/null +++ b/include/ground_object.h @@ -0,0 +1,27 @@ +#ifndef GUARD_GROUND_OBJECT_H +#define GUARD_GROUND_OBJECT_H + +#include "structs/str_ground_script.h" + +void AllocGroundObjects(void); +void DeleteGroundObjects(void); +void FreeGroundObjects(void); +void GroundObject_Select(s32 scriptID, s32 group, s32 sector); +void GroundObject_Cancel(s32 scriptID, s32 sector); +void GroundObject_CancelBlank(void); +s32 GroundObject_Add(s32 id_, const GroundObjectData *objectData, s32 group_, s32 sector_); +void sub_80AC1B0(s32 index_, s32 flag); +Action *GroundObject_GetAction(s32 index_); +bool8 GroundObject_GetScript(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_); +bool8 GroundObject_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script); +bool8 GroundObjectsNotifyAll(s32 index_); +bool8 GroundObjectsCancelAll(void); +s16 GroundObject_GetFlags(s32 index_, s32 *flags); +s16 sub_80AC448(s32 index_, PixelPos *pos); +s16 sub_80AC49C(s32 index_, PixelPos *pos); +s32 sub_80AC4C8(s32 index, PixelPos *a0, PixelPos *a1); +s32 sub_80AC554(s32 flag, PixelPos *param_2,PixelPos *param_3); +void GroundObject_Action(void); +void sub_80ACAD4(void); + +#endif // GUARD_GROUND_OBJECT_H diff --git a/src/code_809D148.c b/src/code_809D148.c index c8703c807..7c4fbcacf 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -8,6 +8,7 @@ #include "ground_script.h" #include "ground_lives.h" #include "ground_effect.h" +#include "ground_object.h" struct unkStruct_20399E8 { @@ -190,7 +191,6 @@ u8 sub_809D248(PixelPos *r0) } // Todo: move these to appropriate header files -extern s32 sub_80AC448(s16 a0, PixelPos *a1); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); void sub_809D25C(void) @@ -210,7 +210,7 @@ void sub_809D25C(void) gUnknown_20399E8.unk0 = 0; break; case 2: - val = sub_80AC448(gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80AC448((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); if (val == (u16) -1) gUnknown_20399E8.unk0 = 0; break; diff --git a/src/ground_lives.c b/src/ground_lives.c index dadc8920b..720217325 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -18,6 +18,7 @@ #include "friend_area_dialogue.h" #include "ground_lives_helper.h" #include "ground_sprite_monster.h" +#include "ground_object.h" struct GroundLivesMeta_Sub1 { @@ -107,20 +108,14 @@ extern u8 sub_809D248(PixelPos *r0); extern s16 HandleAction(Action *action, const DebugLocation *debug); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); -extern s32 sub_80AC554(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); -extern s32 sub_80AC448(s32 id_, PixelPos *pixelPos); extern bool8 sub_80A595C(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); -extern void GroundObject_GetFlags(s32 id, s32 *a1); extern PixelPos SetVecFromDirectionSpeed(s32 r1, u32 r2); extern u8 sub_80A5934(s32 param_1, PixelPos *, PixelPos *); extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); extern bool8 sub_80A58C8(PixelPos *, PixelPos *); -extern s32 sub_80AC4C8(u32 a0, PixelPos *, PixelPos *); extern bool8 sub_809B1C0(s32 a0, u32 kind, Pokemon *a2); extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); extern bool8 sub_809D678(Action *action); -extern bool8 GroundObject_GetScript(s32 a0, ScriptInfoSmall *scriptInfo, s32 a2); -extern void GroundObject_ExecuteScript(s32, void *, ScriptInfoSmall *); extern bool8 GroundScriptNotify(Action *param_1, s32 param_2); extern bool8 GroundScript_Cancel(Action *r0); extern Pokemon *sub_80A8D54(s32); diff --git a/src/ground_main.c b/src/ground_main.c index 3cace7b8b..011c1331b 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -28,6 +28,7 @@ #include "ground_event.h" #include "ground_sprite.h" #include "ground_effect.h" +#include "ground_object.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -73,7 +74,6 @@ extern bool8 sub_809AFAC(void); extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); -extern void FreeGroundObjects(void); extern void sub_809D508(void); extern void nullsub_119(void); extern void sub_8099768(void); @@ -82,8 +82,6 @@ extern void sub_8099648(void); extern void sub_809975C(void); extern void sub_809D0AC(void); extern void sub_809D490(void); -extern void AllocGroundObjects(void); -extern void GroundObject_Action(void); extern void sub_809B474(void); extern void GroundScript_Unlock(); extern void sub_809D25C(void); @@ -98,7 +96,6 @@ extern void sub_80A5E70(void); extern void sub_809B638(void); extern void sub_8099750(void); extern void sub_809D0BC(void); -extern void DeleteGroundObjects(void); extern void nullsub_16(void); extern void UpdateAdventureAchievements(void); extern void xxx_call_update_bg_sound_input(void); diff --git a/src/ground_object.c b/src/ground_object.c index ddca38a9f..047e6f5d4 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "ground_object.h" #include "structs/str_ground_script.h" #include "debug.h" #include "data_script.h" @@ -48,20 +49,24 @@ struct GroundObjectTypeData extern struct GroundObjectTypeData gGroundObjectTypes[]; void DeleteGroundObjects(void); -void GroundObject_Delete(s32); const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); void sub_80A7658(struct UnkGroundSpriteStruct *); extern bool8 GroundScriptNotify(Action*, s32); extern bool8 GroundScript_Cancel(Action *r0); +extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); +extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); +extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); +extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); +extern s16 HandleAction(Action *action, DebugLocation *debug); +extern void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); void sub_80A75CC(void *, s32, s32, s32); - -s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 sector_); - +static void GroundObject_Delete(s32 index_); +static s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1, PixelPos *param_2); static s16 CallbackObjectGetIndex(void *ptr); static void CallbackObjectGetSize(void *objectPtr_, PixelPos *out); static void CallbackObjectSetHitboxPos(void *objectPtr_, PixelPos *posOrNull); @@ -144,11 +149,6 @@ const u8 gGroundObjectFileName[]; - - - - - @@ -170,7 +170,7 @@ static const struct ScriptCommand gUnknown_8118350[] = { JUMP_LABEL(0), }; -const s16 gUnknown_81183A0[] = { +static const s16 gUnknown_81183A0[] = { -1, 0x800, 0x801, @@ -198,15 +198,13 @@ const s16 gUnknown_81183A0[] = { void AllocGroundObjects(void) { - GroundObject *ptr; s32 index; gGroundObjects = MemoryAlloc(sizeof(GroundObject) * NUM_GROUND_OBJECTS, 6); - for(index = 0, ptr = &gGroundObjects[index]; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) - { - ptr->kind |= -1; + for (index = 0, ptr = &gGroundObjects[index]; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) { + ptr->kind = -1; } DeleteGroundObjects(); } @@ -217,9 +215,8 @@ void DeleteGroundObjects(void) s32 index; ptr = &gGroundObjects[0]; - for(index = 0; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) - { - if(ptr->kind != -1) + for (index = 0; index < NUM_GROUND_OBJECTS; index = (s16)(index + 1), ptr++) { + if (ptr->kind != -1) GroundObject_Delete(index); } } @@ -323,7 +320,7 @@ static s32 GroundObject_Find(s32 kind) return -1; } -s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 sector_) +s32 GroundObject_Add(s32 id_, const GroundObjectData *objectData, s32 group_, s32 sector_) { s32 sVar3; s32 sVar4; @@ -490,7 +487,7 @@ s32 GroundObject_Add(s32 id_,const GroundObjectData *objectData,s32 group_,s32 s return id; } -void GroundObject_Delete(s32 index_) +static void GroundObject_Delete(s32 index_) { s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; @@ -506,20 +503,18 @@ void sub_80AC1B0(s32 index_, s32 flag) s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; - if(parent->kind != -1) - { + if (parent->kind != -1) { parent->flags |= flag; sub_80A6688(&parent->unk144, parent->flags); } } -void sub_80AC1F4(s32 index_, s32 flag) +static void sub_80AC1F4(s32 index_, s32 flag) { s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; - if(parent->kind != -1) - { + if (parent->kind != -1) { parent->flags &= (0x337fffff ^ flag); sub_80A6688(&parent->unk144, parent->flags); } @@ -530,15 +525,12 @@ Action *GroundObject_GetAction(s32 index_) s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; - if(parent->kind != -1) + if (parent->kind != -1) return &parent->action; else return NULL; } -extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); - - bool8 GroundObject_GetScript(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_) { s32 index = (s16)index_; @@ -551,7 +543,7 @@ bool8 GroundObject_GetScript(s32 index_, ScriptInfoSmall *scriptInfo, s32 a2_) return FALSE; } -bool8 GroundObject_ExecuteScript(s32 index_, void *a1, ScriptInfoSmall *script) +bool8 GroundObject_ExecuteScript(s32 index_, ActionUnkIds *a1, ScriptInfoSmall *script) { s32 index = (s16)index_; GroundObject *parent = &gGroundObjects[index]; @@ -649,9 +641,6 @@ s16 sub_80AC448(s32 index_, PixelPos *pos) return parent->kind; } -extern s32 TryMoveObjectRelative_80AC6AC(GroundObject *, PixelPos *); - - s16 sub_80AC49C(s32 index_, PixelPos *pos) { s32 index = (s16)index_; @@ -662,7 +651,8 @@ s16 sub_80AC49C(s32 index_, PixelPos *pos) return parent->kind; } -s32 sub_80AC4C8(s32 index, PixelPos *a0, PixelPos *a1) { +s32 sub_80AC4C8(s32 index, PixelPos *a0, PixelPos *a1) +{ GroundObject *parent = &gGroundObjects[0]; s32 counter; @@ -706,9 +696,7 @@ s32 sub_80AC554(s32 flag, PixelPos *param_2,PixelPos *param_3) return -1; } -bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); - -s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPos *param_3) +static s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPos *param_3) { PixelPos local_28 = { param_2->x / 2048 , param_2->y / 2048 }; PixelPos iVar1 = { (param_3->x - 1) / 2048, (param_3->y - 1) / 2048 }; @@ -725,7 +713,7 @@ s32 GetObjectCollision_80AC5F4(GroundObject *param_1, PixelPos *param_2, PixelPo return 0; } -s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1,PixelPos *param_2) +static s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1, PixelPos *param_2) { PixelPos local_1c; PixelPos local_14; @@ -749,7 +737,7 @@ s32 TryMoveObjectRelative_80AC6AC(GroundObject *param_1,PixelPos *param_2) } } -s32 TryMoveRelative_80AC720(GroundObject *param_1,PixelPos *param_2) +static s32 TryMoveRelative_80AC720(GroundObject *param_1,PixelPos *param_2) { s32 ret; bool8 bVar1; @@ -893,7 +881,8 @@ static void CallbackObjectSetDirection(void *livesPtr_, s32 direction) } } -static void CallbackObjectSetEventIndex(void *livesPtr_, u16 a1) { +static void CallbackObjectSetEventIndex(void *livesPtr_, u16 a1) +{ struct GroundObject *livesPtr = livesPtr_; u32 r1; @@ -917,8 +906,8 @@ static void CallbackObjectSetEventIndex(void *livesPtr_, u16 a1) { livesPtr->directionRelated = 1; } - -static void CallbackObjectSetUnk_80AC998(void *objectPtr_, s32 a1_, s32 a2) { +static void CallbackObjectSetUnk_80AC998(void *objectPtr_, s32 a1_, s32 a2) +{ struct GroundObject *livesPtr = objectPtr_; s32 a1Match = (s16) a1_; @@ -935,9 +924,6 @@ static void CallbackObjectSetUnk_80AC998(void *objectPtr_, s32 a1_, s32 a2) { livesPtr->unk140 = a1; } -extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); -extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); - static bool8 CallbackObjectSpriteRelatedCheck_80AC9B8(void *objectPtr_) { struct GroundObject *livesPtr = objectPtr_; @@ -990,8 +976,6 @@ static s32 CallbackObjectMoveRelative(void *livesPtr_, PixelPos *pos) return TryMoveRelative_80AC720(livesPtr, pos); } -extern s16 HandleAction(Action *action, DebugLocation *debug); - void GroundObject_Action(void) { GroundObject *objectPtr; @@ -1020,8 +1004,6 @@ void GroundObject_Action(void) } } -void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); - void sub_80ACAD4(void) { GroundObject *objectPtr; diff --git a/src/ground_script.c b/src/ground_script.c index 432e61ba2..8e9099dde 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -52,16 +52,12 @@ #include "textbox.h" #include "ground_event.h" #include "ground_effect.h" +#include "ground_object.h" void GroundMap_Select(s16); void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); void GroundMap_GetStationScript(ScriptInfoSmall *out, s16, s32, s32); -void GroundObject_ExecuteScript(s32, ActionUnkIds *, ScriptInfoSmall *); -void GroundObject_Select(s32, s32 group, s32 sector); -void GroundObject_Cancel(s32 group, s32 sector); -void GroundObject_CancelBlank(void); void GroundWeather_Select(s16); -s16 GroundObject_Add(s16 id, GroundObjectData*, s16 group, s8 sector); // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files @@ -90,9 +86,6 @@ void sub_809D1E4(s32, s32, s32); void sub_809D208(s32, PixelPos*, s32); void sub_809D220(s32, s32, s32); void GroundScriptLockJumpZero(s16); -s16 sub_80AC448(s16, PixelPos*); -s32 sub_80AC49C(s16, PixelPos*); -void DeleteGroundObjects(void); s32 ExecuteScriptCommand(Action *action); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); @@ -106,15 +99,11 @@ bool8 sub_809D234(void); s32 sub_80A14E8(Action *, u8, u32, s32); u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); -extern u8 GroundObjectsCancelAll(void); extern u8 IsTextboxOpen_809A750(void); -extern Action *GroundObject_GetAction(s32); extern void sub_809AB4C(s32, s32); extern void sub_809ABB4(s32, s32); extern void sub_809AC18(s32, s32); -bool8 GroundObjectsNotifyAll(s16); - void sub_8098C58(void); void sub_8098CC8(void); bool8 sub_80961D8(void); @@ -127,7 +116,6 @@ u8 sub_80964E4(); void sub_80A56A0(s32, s32); void sub_80A56F0(PixelPos *); void sub_80A5704(PixelPos *); -void sub_80AC1B0(s16, s32); s32 sub_80A5984(); void sub_80A59A0(s32, s32 *, u16); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); diff --git a/src/ground_sprite.c b/src/ground_sprite.c index fb35720a3..2cb580a3d 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -14,6 +14,7 @@ #include "effect_sub_1.h" #include "pokemon.h" #include "ground_effect.h" +#include "ground_object.h" static IWRAM_INIT unkStruct_3001B7C *gUnknown_3001B7C = {NULL}; @@ -31,7 +32,6 @@ static EWRAM_INIT OpenedFile *gUnknown_203B4B4 = {NULL}; // code_8098BDC.s extern void sub_809971C(u16, const u8 *, s16); extern void sub_80997F4(u16, u16); -extern void sub_80ACAD4(void); extern void sub_800E970(void); extern u8 sub_809D248(PixelPos *r0); From 3b789a37c135c9133a6123d28c7ca5f441df635e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 21 Oct 2025 15:40:41 +0200 Subject: [PATCH 05/13] ground_script externs --- include/ground_script.h | 20 ++++++++++++++------ src/code_809D148.c | 1 - src/ground_effect.c | 14 +++++++------- src/ground_lives.c | 6 ------ src/ground_lives_helper.c | 2 +- src/ground_main.c | 5 +---- src/ground_map.c | 5 ----- src/ground_object.c | 10 +++++----- src/ground_script.c | 36 ++++++++++++++++++------------------ src/textbox.c | 2 -- 10 files changed, 46 insertions(+), 55 deletions(-) diff --git a/include/ground_script.h b/include/ground_script.h index 80792b88c..9a742ad6c 100644 --- a/include/ground_script.h +++ b/include/ground_script.h @@ -25,16 +25,24 @@ static inline void SetUnkInGroundEvent(const CompactPos *posPtr, PixelPos *dst) #include "debug.h" +void sub_809D490(void); void sub_809D4B0(void); -void InitScriptData(ScriptData *a0); -u8 GroundScriptCheckLockCondition(Action *param_1, s16 param_2); +void sub_809D508(void); +void InitActionWithParams(Action *action, const CallbackData *callbacks, void *parent, s32 group, s32 sector); void InitAction2(Action *action); -void GetFunctionScript(Action *param_1, ScriptInfoSmall *script, s16 index); +bool8 sub_809D678(Action *action); bool8 sub_809D684(Action *action, ScriptInfoSmall *scriptInfo); -bool8 GroundScriptLockCond(Action *param_1, s16 index, s32 param_3); +void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); +bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); +void GetFunctionScript(Action *param_1, ScriptInfoSmall *script, s16 index); bool8 ActionResetScriptData(Action *param_1, const DebugLocation *unused); bool8 GroundScript_ExecutePP(Action *action, ActionUnkIds *param_2, ScriptInfoSmall *param_3, const DebugLocation *unused); -bool8 ExecutePredefinedScript(Action *param_1, ActionUnkIds *param_2, s16 index, DebugLocation *debug); -void InitActionWithParams(Action *action, const CallbackData *callbacks, void *parent, s32 group, s32 sector); +bool8 ExecutePredefinedScript(Action *param_1, ActionUnkIds *param_2, s16 index, const DebugLocation *debug); +bool8 GroundScript_Cancel(Action *r0); +bool8 GroundScriptNotify(Action *param_1, s32 param_2); +void GroundScriptLockJumpZero(s16 index); +void GroundScriptLock(s16 index, s32 r1); +s16 HandleAction(Action *action, const DebugLocation *debug); +void GroundScript_Unlock(void); #endif // GUARD_GROUND_SCRIPT_H diff --git a/src/code_809D148.c b/src/code_809D148.c index 7c4fbcacf..549bd1939 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -32,7 +32,6 @@ struct unkStruct_20399E8 static EWRAM_DATA struct unkStruct_20399E8 gUnknown_20399E8 = {0}; void sub_809D0BC(void); -void sub_809D4B0(void); void sub_809D158(s32 r0, const PixelPos *r1); void sub_809D0AC(void) diff --git a/src/ground_effect.c b/src/ground_effect.c index 661d5c800..fdb38fba6 100644 --- a/src/ground_effect.c +++ b/src/ground_effect.c @@ -48,20 +48,13 @@ struct GroundEffectTypeData extern struct GroundEffectTypeData gGroundEffectTypes[]; -extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); - - const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); bool8 GetCurrentDungeonBounds(PixelPos *, PixelPos *); void sub_80A7688(struct UnkGroundSpriteStruct *ptr, s32 unused, s32 a2_, s32 a3); -extern void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); void sub_80A7714(struct UnkGroundSpriteStruct *); -extern bool8 GroundScriptNotify(Action*, s32); -extern bool8 GroundScript_Cancel(Action *r0); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); void sub_80A7720(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); -extern s16 HandleAction(Action *action, DebugLocation *debug); static void GroundEffect_Delete(s32 _id); @@ -143,6 +136,13 @@ extern const u8 gUnknown_81185D8[]; + + + + + + + diff --git a/src/ground_lives.c b/src/ground_lives.c index 720217325..0655005cc 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -105,7 +105,6 @@ extern const struct GroundLiveTypeData gGroundLivesTypeData_811E63C[]; extern s32 sub_8002984(s32 _direction1, u32 caseID); extern u8 sub_809D248(PixelPos *r0); -extern s16 HandleAction(Action *action, const DebugLocation *debug); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A595C(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); @@ -114,13 +113,8 @@ extern u8 sub_80A5934(s32 param_1, PixelPos *, PixelPos *); extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); extern bool8 sub_80A58C8(PixelPos *, PixelPos *); extern bool8 sub_809B1C0(s32 a0, u32 kind, Pokemon *a2); -extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); -extern bool8 sub_809D678(Action *action); -extern bool8 GroundScriptNotify(Action *param_1, s32 param_2); -extern bool8 GroundScript_Cancel(Action *r0); extern Pokemon *sub_80A8D54(s32); extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); -extern void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); extern void sub_809D170(s32 r0, s32 r1); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); diff --git a/src/ground_lives_helper.c b/src/ground_lives_helper.c index 1feb63568..f894d7727 100644 --- a/src/ground_lives_helper.c +++ b/src/ground_lives_helper.c @@ -5,12 +5,12 @@ #include "input.h" #include "game_options.h" #include "ground_main.h" +#include "ground_script.h" extern void nullsub_104(void); extern void sub_809C6CC(u16 param_1); extern bool8 sub_809B260(s32 *a0); extern void GroundMap_ExecuteEvent(s32, s32); -extern void GroundScriptLockJumpZero(s32 index); void nullsub_117(void) { diff --git a/src/ground_main.c b/src/ground_main.c index 011c1331b..799db1773 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -29,6 +29,7 @@ #include "ground_sprite.h" #include "ground_effect.h" #include "ground_object.h" +#include "ground_script.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -49,7 +50,6 @@ EWRAM_INIT bool8 gUnknown_203B49C = {0}; EWRAM_INIT u8 gUnknown_203B49D = {0}; extern void sub_809B57C(); -extern void GroundScript_Unlock(); extern void sub_809D25C(); extern void sub_80A59DC(); extern void sub_809B614(); @@ -74,14 +74,12 @@ extern bool8 sub_809AFAC(void); extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); -extern void sub_809D508(void); extern void nullsub_119(void); extern void sub_8099768(void); extern void nullsub_103(void); extern void sub_8099648(void); extern void sub_809975C(void); extern void sub_809D0AC(void); -extern void sub_809D490(void); extern void sub_809B474(void); extern void GroundScript_Unlock(); extern void sub_809D25C(void); @@ -106,7 +104,6 @@ extern void sub_8098C58(void); extern void sub_8001D88(void); extern u32 GroundMainGameCancelRequest(u32 r0); extern void sub_80999D4(s32); -extern void sub_809D4B0(void); extern void sub_8005838(s32, s32); u32 xxx_script_related_8098468(s32 param_1) diff --git a/src/ground_map.c b/src/ground_map.c index c8d7d8f82..a795b4e25 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -52,14 +52,9 @@ extern const CallbackData gGroundScriptNullCallbacks; extern u8 sub_809D248(PixelPos *r0); -extern bool8 sub_809D678(Action *); -extern bool8 GroundScriptNotify(Action*, s32); - extern u8 sub_80A46C0(GroundBg *, u32, s32, s32); extern u8 sub_80A4660(GroundBg *, u32, s32, s32); -extern s16 HandleAction(Action *action, const DebugLocation *debug); - void GroundMap_SelectDungeon(s32 mapId, const DungeonLocation *loc, u32 param_2); void sub_80A56D8(const PixelPos*); diff --git a/src/ground_object.c b/src/ground_object.c index 047e6f5d4..7970d9848 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -52,14 +52,9 @@ void DeleteGroundObjects(void); const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); void sub_80A7658(struct UnkGroundSpriteStruct *); -extern bool8 GroundScriptNotify(Action*, s32); -extern bool8 GroundScript_Cancel(Action *r0); -extern bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index); -void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); -extern s16 HandleAction(Action *action, DebugLocation *debug); extern void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); @@ -149,6 +144,11 @@ const u8 gGroundObjectFileName[]; + + + + + diff --git a/src/ground_script.c b/src/ground_script.c index 8e9099dde..3e6e2318a 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -86,7 +86,6 @@ void sub_809D1E4(s32, s32, s32); void sub_809D208(s32, PixelPos*, s32); void sub_809D220(s32, s32, s32); void GroundScriptLockJumpZero(s16); -s32 ExecuteScriptCommand(Action *action); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); bool8 sub_8098DCC(u32 speed); @@ -96,7 +95,6 @@ bool8 sub_809B260(void *dst); bool8 sub_809B18C(s32 *sp); bool8 sub_809AFFC(u8 *); bool8 sub_809D234(void); -s32 sub_80A14E8(Action *, u8, u32, s32); u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); extern u8 IsTextboxOpen_809A750(void); @@ -170,6 +168,8 @@ static const ScriptCommand gUnknown_81164E4[] = { {0xEF, 0, 0, 0, 0, NULL}, }; +static s32 ExecuteScriptCommand(Action *action); +static s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3); static const ScriptCommand *FindLabel(Action *action, s32 r1); static const ScriptCommand *ResolveJump(Action *action, s32 r1); static void sub_80A2500(s32 param_1, ActionUnkIds *param_2); @@ -222,7 +222,7 @@ static Action *sub_809D52C(ActionUnkIds *a0) return NULL; } -void InitScriptData(ScriptData *a0) +static void InitScriptData(ScriptData *a0) { s32 i; @@ -246,7 +246,7 @@ void InitScriptData(ScriptData *a0) } } -void InitAction(Action *a0) +static void InitAction(Action *a0) { s32 i; @@ -277,7 +277,7 @@ void InitActionWithParams(Action *action, const CallbackData *callbacks, void *p action->sector = sector_s32; action->unk8.unk0 = callbacks->maybeId; - if(callbacks->getIndex) + if (callbacks->getIndex) action->unk8.unk2 = callbacks->getIndex(parent); else action->unk8.unk2 = 0; @@ -333,15 +333,15 @@ bool8 sub_809D684(Action *action, ScriptInfoSmall *scriptInfo) return 0; } -void SetPredefinedScript(Action *param_1, s16 index, ScriptCommand *param_3) +void SetPredefinedScript(Action *param_1, s16 index, const ScriptCommand *param_3) { param_1->predefinedScripts[index] = param_3; } -bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s16 _index) +bool8 GetPredefinedScript(Action *param_1, ScriptInfoSmall *script, s32 _index) { const ScriptCommand *scriptPtr; - s32 index = _index; + s32 index = (s16) _index; scriptPtr = param_1->predefinedScripts[index]; script->ptr = scriptPtr; @@ -373,7 +373,7 @@ bool8 ActionResetScriptData(Action *param_1, const DebugLocation *unused) return TRUE; } -bool8 ActionResetScriptDataForDeletion(Action *param_1, DebugLocation *unused) +static bool8 ActionResetScriptDataForDeletion(Action *param_1, const DebugLocation *unused) { InitScriptData(¶m_1->scriptData); InitScriptData(¶m_1->scriptData2); @@ -442,7 +442,7 @@ bool8 GroundScript_ExecutePP(Action *action, ActionUnkIds *param_2, ScriptInfoSm return TRUE; } -bool8 ExecutePredefinedScript(Action *param_1, ActionUnkIds *param_2, s16 index, DebugLocation *debug) +bool8 ExecutePredefinedScript(Action *param_1, ActionUnkIds *param_2, s16 index, const DebugLocation *debug) { ScriptInfoSmall auStack28; @@ -450,7 +450,7 @@ bool8 ExecutePredefinedScript(Action *param_1, ActionUnkIds *param_2, s16 index, return GroundScript_ExecutePP(param_1, param_2, &auStack28, debug); } -u8 GroundScriptCheckLockCondition(Action *param_1, s16 param_2) +static u8 GroundScriptCheckLockCondition(Action *param_1, s16 param_2) { s32 param_2_s32; @@ -474,7 +474,7 @@ bool8 GroundScript_Cancel(Action *r0) return ActionResetScriptDataForDeletion(r0, DEBUG_LOC_PTR("../ground/ground_script.c", 821, "GroundScript_Cancel")); } -u8 GroundCancelAllEntities(void) +static u8 GroundCancelAllEntities(void) { u8 ret; @@ -484,13 +484,13 @@ u8 GroundCancelAllEntities(void) return ret; } -bool8 GroundScriptNotify(Action *param_1, s16 param_2) +bool8 GroundScriptNotify(Action *param_1, s32 param_2) { s16 sVar1; s16 sVar2; bool8 ret; - s32 param_2_s16 = param_2; + s32 param_2_s16 = (s16) param_2; ret = FALSE; sVar1 = param_1->scriptData.unk22; @@ -522,7 +522,7 @@ void GroundScriptLock(s16 index, s32 r1) gAnyScriptLocked = 1; } -bool8 GroundScriptLockCond(Action *param_1, s16 index, s32 param_3) +static bool8 GroundScriptLockCond(Action *param_1, s16 index, s32 param_3) { s32 index_s32 = index; gUnlockBranchLabels[index_s32] = param_3; @@ -542,7 +542,7 @@ bool8 GroundScriptLockCond(Action *param_1, s16 index, s32 param_3) return TRUE; } -s16 HandleAction(Action *action, DebugLocation *debug) +s16 HandleAction(Action *action, const DebugLocation *debug) { ScriptCommand cmd; @@ -1353,7 +1353,7 @@ s16 HandleAction(Action *action, DebugLocation *debug) // This is the only return value that does not return to the script engine caller // - Value 3 returns to the caller, but will give control back to ExecuteScriptCommand when reentering the script ("script not finished") // - Value 4 is some kind of fatal error state, no further scripting progress will happen. This code is always returned to the caller from now on. -s32 ExecuteScriptCommand(Action *action) +static s32 ExecuteScriptCommand(Action *action) { ScriptCommand curCmd; ScriptData *scriptData = &action->scriptData; @@ -3031,7 +3031,7 @@ UNUSED static bool8 GroundScript_ExecuteTrigger(s16 r0) return FALSE; } -s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) +static s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) { switch(idx) { diff --git a/src/textbox.c b/src/textbox.c index 736292b10..0bb397a58 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -117,8 +117,6 @@ bool8 IsTextboxOpen_809B40C(struct TextboxText *); void sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); bool8 sub_809B18C(s32 *sp); -extern void GroundScriptLock(s16 index, s32 r1); -extern void GroundScriptLockJumpZero(s16 index); extern u8 sub_802B2D4(void); extern void sub_802B3B8(void); extern u32 sub_802B358(void); From c6273139e62a5988936bf1354d1109e57b95c01f Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 21 Oct 2025 16:08:24 +0200 Subject: [PATCH 06/13] code 809D148 externs --- include/code_809D148.h | 23 ++++ src/code_809D148.c | 241 ++++++++++++++++++++--------------------- src/debug_field_map.c | 6 +- src/ground_lives.c | 3 +- src/ground_main.c | 8 +- src/ground_map.c | 3 +- src/ground_script.c | 12 +- src/ground_sprite.c | 2 +- 8 files changed, 147 insertions(+), 151 deletions(-) create mode 100644 include/code_809D148.h diff --git a/include/code_809D148.h b/include/code_809D148.h new file mode 100644 index 000000000..b19225237 --- /dev/null +++ b/include/code_809D148.h @@ -0,0 +1,23 @@ +#ifndef GUARD_CODE_809D148_H +#define GUARD_CODE_809D148_H + +#include "structs/str_position.h" + +void sub_809D0AC(void); +void nullsub_119(void); +void sub_809D0BC(void); +void sub_809D124(s32 r0, s32 r1, s32 r2); +void sub_809D158(s32 r0, const PixelPos *r1); +void sub_809D170(s32 r0, s32 r1); +void sub_809D190(s32 r0, PixelPos *r1, s32 r2); +void sub_809D1A8(s32 r0, s32 r1, s32 r2); +void sub_809D1CC(s32 r0, PixelPos *r1, s32 r2); +void sub_809D1E4(s32 r0, s32 r1, s32 r2); +void sub_809D208(s32 r0, PixelPos *r1, s32 r2); +void sub_809D220(s32 r0, s32 r1, s32 r2); +bool8 sub_809D234(void); +u8 sub_809D248(PixelPos *r0); +void sub_809D25C(void); +void nullsub_120(void); + +#endif // GUARD_CODE_809D148_H diff --git a/src/code_809D148.c b/src/code_809D148.c index 549bd1939..bd5689657 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -1,5 +1,6 @@ #include "global.h" #include "globaldata.h" +#include "code_809D148.h" #include "structs/str_position.h" #include "code_8002774.h" #include "math.h" @@ -29,10 +30,7 @@ struct unkStruct_20399E8 u8 unk44; }; -static EWRAM_DATA struct unkStruct_20399E8 gUnknown_20399E8 = {0}; - -void sub_809D0BC(void); -void sub_809D158(s32 r0, const PixelPos *r1); +static EWRAM_DATA struct unkStruct_20399E8 sUnknown_20399E8 = {0}; void sub_809D0AC(void) { @@ -47,146 +45,143 @@ static const PixelPos sPixelPosZero = {0, 0}; void sub_809D0BC(void) { - gUnknown_20399E8.unk3C = sPixelPosZero; - gUnknown_20399E8.unk44 = 0; + sUnknown_20399E8.unk3C = sPixelPosZero; + sUnknown_20399E8.unk44 = 0; sub_809D158(0, &sPixelPosZero); - gUnknown_20399E8.unk8 = 0; - gUnknown_20399E8.unkC = 0; - gUnknown_20399E8.unk10 = 0; - gUnknown_20399E8.unk4 = -1; - gUnknown_20399E8.unk24 = 0; - gUnknown_20399E8.unk28 = 0; - gUnknown_20399E8.unk2C = 0; - gUnknown_20399E8.unk30 = 0; - gUnknown_20399E8.unk34 = 0; - gUnknown_20399E8.unk38 = 0; + sUnknown_20399E8.unk8 = 0; + sUnknown_20399E8.unkC = 0; + sUnknown_20399E8.unk10 = 0; + sUnknown_20399E8.unk4 = -1; + sUnknown_20399E8.unk24 = 0; + sUnknown_20399E8.unk28 = 0; + sUnknown_20399E8.unk2C = 0; + sUnknown_20399E8.unk30 = 0; + sUnknown_20399E8.unk34 = 0; + sUnknown_20399E8.unk38 = 0; } -void sub_809D100(s32 r0) +UNUSED static void sub_809D100(s32 r0) { - if(gUnknown_20399E8.unk24 != r0) - { - gUnknown_20399E8.unk24 = r0; - gUnknown_20399E8.unk28 = 0; - gUnknown_20399E8.unk2C = 0; - gUnknown_20399E8.unk30 = 0; - gUnknown_20399E8.unk34 = 0; - gUnknown_20399E8.unk38 = 0; + if (sUnknown_20399E8.unk24 != r0) { + sUnknown_20399E8.unk24 = r0; + sUnknown_20399E8.unk28 = 0; + sUnknown_20399E8.unk2C = 0; + sUnknown_20399E8.unk30 = 0; + sUnknown_20399E8.unk34 = 0; + sUnknown_20399E8.unk38 = 0; } } void sub_809D124(s32 r0, s32 r1, s32 r2) { - if(gUnknown_20399E8.unk24 != r0) - { - gUnknown_20399E8.unk24 = r0; - gUnknown_20399E8.unk30 = 0; - gUnknown_20399E8.unk34 = 0; - gUnknown_20399E8.unk38 = 0; + if (sUnknown_20399E8.unk24 != r0) { + sUnknown_20399E8.unk24 = r0; + sUnknown_20399E8.unk30 = 0; + sUnknown_20399E8.unk34 = 0; + sUnknown_20399E8.unk38 = 0; } - gUnknown_20399E8.unk28 = r1; - gUnknown_20399E8.unk2C = r2; + sUnknown_20399E8.unk28 = r1; + sUnknown_20399E8.unk2C = r2; } -void sub_809D148(s32 r0) +UNUSED static void sub_809D148(s32 r0) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 0; - + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 0; } void sub_809D158(s32 r0, const PixelPos *r1) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 0; - gUnknown_20399E8.unk1C = *r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 0; + sUnknown_20399E8.unk1C = *r1; } void sub_809D170(s32 r0, s32 r1) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 0; - gUnknown_20399E8.unk4 = r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 0; + sUnknown_20399E8.unk4 = r1; } -void sub_809D180(s32 r0, s32 r1) +UNUSED static void sub_809D180(s32 r0, s32 r1) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 1; - gUnknown_20399E8.unkC = r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 1; + sUnknown_20399E8.unkC = r1; } void sub_809D190(s32 r0, PixelPos *r1, s32 r2) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 1; - gUnknown_20399E8.unkC = r2; - gUnknown_20399E8.unk14 = *r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 1; + sUnknown_20399E8.unkC = r2; + sUnknown_20399E8.unk14 = *r1; } void sub_809D1A8(s32 r0, s32 r1, s32 r2) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 1; - gUnknown_20399E8.unkC = r2; - gUnknown_20399E8.unk4 = r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 1; + sUnknown_20399E8.unkC = r2; + sUnknown_20399E8.unk4 = r1; } -void sub_809D1BC(s32 r0, s32 r1) +UNUSED static void sub_809D1BC(s32 r0, s32 r1) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 2; - gUnknown_20399E8.unk10 = r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 2; + sUnknown_20399E8.unk10 = r1; } void sub_809D1CC(s32 r0, PixelPos *r1, s32 r2) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 2; - gUnknown_20399E8.unk10 = r2; - gUnknown_20399E8.unk14 = *r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 2; + sUnknown_20399E8.unk10 = r2; + sUnknown_20399E8.unk14 = *r1; } void sub_809D1E4(s32 r0, s32 r1, s32 r2) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 2; - gUnknown_20399E8.unk10 = r2; - gUnknown_20399E8.unk4 = r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 2; + sUnknown_20399E8.unk10 = r2; + sUnknown_20399E8.unk4 = r1; } -void sub_809D1F8(s32 r0, s32 r1) +UNUSED static void sub_809D1F8(s32 r0, s32 r1) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 3; - gUnknown_20399E8.unkC = r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 3; + sUnknown_20399E8.unkC = r1; } void sub_809D208(s32 r0, PixelPos *r1, s32 r2) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 3; - gUnknown_20399E8.unkC = r2; - gUnknown_20399E8.unk14 = *r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 3; + sUnknown_20399E8.unkC = r2; + sUnknown_20399E8.unk14 = *r1; } void sub_809D220(s32 r0, s32 r1, s32 r2) { - gUnknown_20399E8.unk0 = r0; - gUnknown_20399E8.unk8 = 3; - gUnknown_20399E8.unkC = r2; - gUnknown_20399E8.unk4 = r1; + sUnknown_20399E8.unk0 = r0; + sUnknown_20399E8.unk8 = 3; + sUnknown_20399E8.unkC = r2; + sUnknown_20399E8.unk4 = r1; } bool8 sub_809D234(void) { - return gUnknown_20399E8.unk8 != 0; + return sUnknown_20399E8.unk8 != 0; } u8 sub_809D248(PixelPos *r0) { - *r0 = gUnknown_20399E8.unk3C; - return gUnknown_20399E8.unk44; + *r0 = sUnknown_20399E8.unk3C; + return sUnknown_20399E8.unk44; } // Todo: move these to appropriate header files @@ -201,88 +196,88 @@ void sub_809D25C(void) PixelPos sp1C; u16 val; // For some reason I have to compare with 0xFFFF instead of -1. Maybe it has to do with return value of the functions? - switch (gUnknown_20399E8.unk0) + switch (sUnknown_20399E8.unk0) { case 1: - val = sub_80A8FD8((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80A8FD8((s16) sUnknown_20399E8.unk4, &sUnknown_20399E8.unk1C); if (val == (u16) -1) - gUnknown_20399E8.unk0 = 0; + sUnknown_20399E8.unk0 = 0; break; case 2: - val = sub_80AC448((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80AC448((s16) sUnknown_20399E8.unk4, &sUnknown_20399E8.unk1C); if (val == (u16) -1) - gUnknown_20399E8.unk0 = 0; + sUnknown_20399E8.unk0 = 0; break; case 3: - val = sub_80AD360((s16) gUnknown_20399E8.unk4, &gUnknown_20399E8.unk1C); + val = sub_80AD360((s16) sUnknown_20399E8.unk4, &sUnknown_20399E8.unk1C); if (val == (u16) -1) - gUnknown_20399E8.unk0 = 0; + sUnknown_20399E8.unk0 = 0; break; } - switch (gUnknown_20399E8.unk8) + switch (sUnknown_20399E8.unk8) { case 1: - sp4.x = gUnknown_20399E8.unk1C.x - gUnknown_20399E8.unk14.x; - sp4.y = gUnknown_20399E8.unk1C.y - gUnknown_20399E8.unk14.y; - sub_800290C(&sp4, gUnknown_20399E8.unkC); + sp4.x = sUnknown_20399E8.unk1C.x - sUnknown_20399E8.unk14.x; + sp4.y = sUnknown_20399E8.unk1C.y - sUnknown_20399E8.unk14.y; + sub_800290C(&sp4, sUnknown_20399E8.unkC); if (sp4.x == 0 && sp4.y == 0) { - gUnknown_20399E8.unk8 = 0; + sUnknown_20399E8.unk8 = 0; } else { - gUnknown_20399E8.unk14.x += sp4.x; - gUnknown_20399E8.unk14.y += sp4.y; + sUnknown_20399E8.unk14.x += sp4.x; + sUnknown_20399E8.unk14.y += sp4.y; } break; case 3: - r2 = (gUnknown_20399E8.unk1C.x - gUnknown_20399E8.unk14.x) / 256; - r1 = (gUnknown_20399E8.unk1C.y - gUnknown_20399E8.unk14.y) / 256; - gUnknown_20399E8.unk10 = (F248ToInt(FP24_8_Hypot(IntToF248(r2), IntToF248(r1))) << 8) / gUnknown_20399E8.unkC; - if (gUnknown_20399E8.unk10 <= 0) - gUnknown_20399E8.unk10 = 1; - gUnknown_20399E8.unk8 = 2; + r2 = (sUnknown_20399E8.unk1C.x - sUnknown_20399E8.unk14.x) / 256; + r1 = (sUnknown_20399E8.unk1C.y - sUnknown_20399E8.unk14.y) / 256; + sUnknown_20399E8.unk10 = (F248ToInt(FP24_8_Hypot(IntToF248(r2), IntToF248(r1))) << 8) / sUnknown_20399E8.unkC; + if (sUnknown_20399E8.unk10 <= 0) + sUnknown_20399E8.unk10 = 1; + sUnknown_20399E8.unk8 = 2; // Breakthrough case 2: - sub_8002934(&spC, &gUnknown_20399E8.unk14, &gUnknown_20399E8.unk1C, gUnknown_20399E8.unk10, 1); - gUnknown_20399E8.unk14 = spC; - if (--gUnknown_20399E8.unk10 <= 0) - gUnknown_20399E8.unk8 = 0; + sub_8002934(&spC, &sUnknown_20399E8.unk14, &sUnknown_20399E8.unk1C, sUnknown_20399E8.unk10, 1); + sUnknown_20399E8.unk14 = spC; + if (--sUnknown_20399E8.unk10 <= 0) + sUnknown_20399E8.unk8 = 0; break; default: - gUnknown_20399E8.unk14 = gUnknown_20399E8.unk1C; + sUnknown_20399E8.unk14 = sUnknown_20399E8.unk1C; break; } - switch (gUnknown_20399E8.unk24) + switch (sUnknown_20399E8.unk24) { default: - gUnknown_20399E8.unk34 = 0; - gUnknown_20399E8.unk38 = 0; + sUnknown_20399E8.unk34 = 0; + sUnknown_20399E8.unk38 = 0; break; case 1: - if (--gUnknown_20399E8.unk30 <= 0) + if (--sUnknown_20399E8.unk30 <= 0) { - gUnknown_20399E8.unk30 = 4; - gUnknown_20399E8.unk34 = OtherRandRange(-2, 2) << 0xA; - gUnknown_20399E8.unk38 = OtherRandRange(-2, 2) << 0xA; + sUnknown_20399E8.unk30 = 4; + sUnknown_20399E8.unk34 = OtherRandRange(-2, 2) << 0xA; + sUnknown_20399E8.unk38 = OtherRandRange(-2, 2) << 0xA; } break; case 2: - if (--gUnknown_20399E8.unk30 <= 0) + if (--sUnknown_20399E8.unk30 <= 0) { - gUnknown_20399E8.unk30 = gUnknown_20399E8.unk2C; - gUnknown_20399E8.unk34 = (OtherRandRange(-2, 2) * gUnknown_20399E8.unk28) << 0x8; - gUnknown_20399E8.unk38 = (OtherRandRange(-2, 2) * gUnknown_20399E8.unk28) << 0x8; + sUnknown_20399E8.unk30 = sUnknown_20399E8.unk2C; + sUnknown_20399E8.unk34 = (OtherRandRange(-2, 2) * sUnknown_20399E8.unk28) << 0x8; + sUnknown_20399E8.unk38 = (OtherRandRange(-2, 2) * sUnknown_20399E8.unk28) << 0x8; } break; } if (sub_80A579C(&sp14, &sp1C)) { - r2 = gUnknown_20399E8.unk14.x + gUnknown_20399E8.unk34 - 0x80; - r3 = gUnknown_20399E8.unk14.y + gUnknown_20399E8.unk38 - 2944; + r2 = sUnknown_20399E8.unk14.x + sUnknown_20399E8.unk34 - 0x80; + r3 = sUnknown_20399E8.unk14.y + sUnknown_20399E8.unk38 - 2944; if (r2 < sp14.x) r2 = sp14.x; @@ -294,9 +289,9 @@ void sub_809D25C(void) if (r3 >= sp1C.y) r3 = sp1C.y - 1; - gUnknown_20399E8.unk3C.x = (r2 - 30976) / 256; - gUnknown_20399E8.unk3C.y = (r3 - 20480) / 256; - gUnknown_20399E8.unk44 = 1; + sUnknown_20399E8.unk3C.x = (r2 - 30976) / 256; + sUnknown_20399E8.unk3C.y = (r3 - 20480) / 256; + sUnknown_20399E8.unk44 = 1; } } diff --git a/src/debug_field_map.c b/src/debug_field_map.c index a21e8f643..6d6cffe2c 100644 --- a/src/debug_field_map.c +++ b/src/debug_field_map.c @@ -18,18 +18,14 @@ #include "ground_lives_helper.h" #include "input.h" #include "structs/str_position.h" +#include "code_809D148.h" -extern void sub_809D0AC(void); extern void sub_8012A18(s32 unused); -extern void sub_809D0BC(void); extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); extern void GroundMap_Select(s16); extern void sub_80999E8(s32 a0); -extern void nullsub_120(void); extern void sub_80A59DC(void); -extern void sub_809D25C(void); extern PixelPos SetVecFromDirectionSpeed(s8 r1, u32 r2); -extern void sub_809D158(s32, PixelPos*); UNUSED static void DebugMapViewer(void) { diff --git a/src/ground_lives.c b/src/ground_lives.c index 0655005cc..dfd0178c8 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -19,6 +19,7 @@ #include "ground_lives_helper.h" #include "ground_sprite_monster.h" #include "ground_object.h" +#include "code_809D148.h" struct GroundLivesMeta_Sub1 { @@ -104,7 +105,6 @@ struct GroundLiveTypeData extern const struct GroundLiveTypeData gGroundLivesTypeData_811E63C[]; extern s32 sub_8002984(s32 _direction1, u32 caseID); -extern u8 sub_809D248(PixelPos *r0); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A595C(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); @@ -115,7 +115,6 @@ extern bool8 sub_80A58C8(PixelPos *, PixelPos *); extern bool8 sub_809B1C0(s32 a0, u32 kind, Pokemon *a2); extern Pokemon *sub_80A8D54(s32); extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); -extern void sub_809D170(s32 r0, s32 r1); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); static s32 sub_80A7B94(s16 *a0); diff --git a/src/ground_main.c b/src/ground_main.c index 799db1773..35097ef6b 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -30,6 +30,7 @@ #include "ground_effect.h" #include "ground_object.h" #include "ground_script.h" +#include "code_809D148.h" EWRAM_DATA u32 gUnknown_20398A8 = {0}; EWRAM_DATA s32 gUnknown_20398AC = {0}; @@ -56,7 +57,6 @@ extern void sub_809B614(); extern void sub_809CA20(); extern void sub_80A6E80(); extern void sub_8099BE4(); -extern void nullsub_120(); extern void sub_809B638(); extern void nullsub_106(); extern void sub_80A73EC(); @@ -74,26 +74,20 @@ extern bool8 sub_809AFAC(void); extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); -extern void nullsub_119(void); extern void sub_8099768(void); extern void nullsub_103(void); extern void sub_8099648(void); extern void sub_809975C(void); -extern void sub_809D0AC(void); extern void sub_809B474(void); -extern void GroundScript_Unlock(); -extern void sub_809D25C(void); extern void sub_80A59DC(void); extern void sub_809B614(void); extern void sub_8099BE4(void); extern void sub_8099744(void); extern void WaitForNextFrameAndAdvanceRNG(void); extern void LoadBufferedInputs(void); -extern void nullsub_120(void); extern void sub_80A5E70(void); extern void sub_809B638(void); extern void sub_8099750(void); -extern void sub_809D0BC(void); extern void nullsub_16(void); extern void UpdateAdventureAchievements(void); extern void xxx_call_update_bg_sound_input(void); diff --git a/src/ground_map.c b/src/ground_map.c index a795b4e25..38b90b974 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -11,6 +11,7 @@ #include "ground_map_conversion_table.h" #include "code_800558C.h" #include "constants/dungeon.h" +#include "code_809D148.h" IWRAM_INIT GroundMapAction *gGroundMapAction = {NULL}; IWRAM_INIT GroundBg *gGroundMapDungeon_3001B70 = {NULL}; @@ -50,8 +51,6 @@ extern const DebugLocation gUnknown_8117770; extern const CallbackData gGroundScriptNullCallbacks; -extern u8 sub_809D248(PixelPos *r0); - extern u8 sub_80A46C0(GroundBg *, u32, s32, s32); extern u8 sub_80A4660(GroundBg *, u32, s32, s32); diff --git a/src/ground_script.c b/src/ground_script.c index 3e6e2318a..d6dfbec65 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -53,6 +53,7 @@ #include "ground_event.h" #include "ground_effect.h" #include "ground_object.h" +#include "code_809D148.h" void GroundMap_Select(s16); void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); @@ -75,16 +76,6 @@ void sub_809AFC8(bool8, s32, s32, const char*); u32 sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); bool8 sub_809B1C0(s32, s32, char[12]); void sub_809B1D4(u8, s32, s32, const char*); -void sub_809D0BC(void); -void sub_809D124(s32, s32, s32); -void sub_809D158(s32, PixelPos*); -void sub_809D170(s32, s32); -void sub_809D190(s32, PixelPos*, s32); -void sub_809D1A8(s32, s32, s32); -void sub_809D1CC(s32, PixelPos*, s32); -void sub_809D1E4(s32, s32, s32); -void sub_809D208(s32, PixelPos*, s32); -void sub_809D220(s32, s32, s32); void GroundScriptLockJumpZero(s16); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); @@ -94,7 +85,6 @@ void sub_8099220(void *param_1, s32 param_2); bool8 sub_809B260(void *dst); bool8 sub_809B18C(s32 *sp); bool8 sub_809AFFC(u8 *); -bool8 sub_809D234(void); u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); extern u8 IsTextboxOpen_809A750(void); diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 2cb580a3d..6904b4c61 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -15,6 +15,7 @@ #include "pokemon.h" #include "ground_effect.h" #include "ground_object.h" +#include "code_809D148.h" static IWRAM_INIT unkStruct_3001B7C *gUnknown_3001B7C = {NULL}; @@ -33,7 +34,6 @@ static EWRAM_INIT OpenedFile *gUnknown_203B4B4 = {NULL}; extern void sub_809971C(u16, const u8 *, s16); extern void sub_80997F4(u16, u16); extern void sub_800E970(void); -extern u8 sub_809D248(PixelPos *r0); static bool8 sub_80A68F8(struct UnkGroundSpriteStruct *ptr, struct UnkGroundSpriteSubStructx48 *a1, s32 a2); static bool8 sub_80A6CF4(struct UnkGroundSpriteSubStructx48 *a0); From 7b5748676c7efd7b786eab046160e478437d671a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 21 Oct 2025 20:17:09 +0200 Subject: [PATCH 07/13] ground main includes --- data/data_8115EB8.s | 7 ------- include/code_8099360.h | 9 +-------- include/ground_main.h | 28 +++++++++++++++++-------- ld_script.ld | 1 - src/code_8099360.c | 2 -- src/event_flag.c | 2 +- src/ground_main.c | 46 +++++++++++++++++++++++------------------- src/ground_script.c | 6 +----- src/main_loops.c | 3 --- src/run_dungeon.c | 1 + src/save_write.c | 1 + src/textbox.c | 1 - src/wonder_mail.c | 2 +- src/wonder_mail_2.c | 1 + 14 files changed, 52 insertions(+), 58 deletions(-) delete mode 100644 data/data_8115EB8.s diff --git a/data/data_8115EB8.s b/data/data_8115EB8.s deleted file mode 100644 index 791fcad46..000000000 --- a/data/data_8115EB8.s +++ /dev/null @@ -1,7 +0,0 @@ - .section .rodata - - .global gUnknown_8115EB8 -gUnknown_8115EB8: @ 8115EB8 - .string "pksdir0" - .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xb2, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0xba, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x00, 0xbf, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcf, 0x00, 0x00, 0x00, 0xa2, 0x00, 0x00, 0x00, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - diff --git a/include/code_8099360.h b/include/code_8099360.h index 6c6c46187..22fc816c0 100644 --- a/include/code_8099360.h +++ b/include/code_8099360.h @@ -1,17 +1,10 @@ #ifndef GUARD_CODE_8099360_H #define GUARD_CODE_8099360_H -bool8 sub_8099360(u8 *); -bool8 sub_8099394(u8 *); -void sub_80993C0(bool8); -void sub_80993D8(void); -void sub_80993E4(void); - void sub_8099648(void); void nullsub_103(void); void sub_809965C(void); - -extern void sub_8099690(u32); +void sub_8099690(u32 param_1); // code_8099360.s diff --git a/include/ground_main.h b/include/ground_main.h index dd88469b4..bac7c1713 100644 --- a/include/ground_main.h +++ b/include/ground_main.h @@ -1,18 +1,30 @@ #ifndef GUARD_GROUND_MAIN_H #define GUARD_GROUND_MAIN_H -#include "structs/str_pokemon.h" -#include "structs/str_wonder_mail.h" - -bool8 sub_8098F88(void); -const char *GetCurrentGroundPlaceName(void); +#include "structs/str_dungeon_setup.h" +u32 xxx_script_related_8098468(s32 param_1); +void sub_8098C58(void); +void sub_8098CC8(void); bool8 GroundMainGroundRequest(s32 r0, s32 r1, s32 r2); -bool8 GroundMainRescueRequest(s32 r0, s32 r1); +bool8 sub_8098D80(u32 speed); +bool8 sub_8098DCC(u32 speed); +bool8 GroundMainRescueRequest(s32 dungeonId_, s32 r1); bool32 GroundMainGameEndRequest(u32 r0); bool32 GroundMainGameCancelRequest(u32 r0); -bool8 sub_8098D80(u32 speed); +bool8 sub_8098F88(void); +bool8 GetScriptMode(void); +const char *GetCurrentGroundPlaceName(void); +u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); +u8 sub_80991E0(struct DungeonSetupInfo *param_1, s16 *param_2); +void sub_8099220(struct DungeonSetupInfo *param_1, s32 param_2); +void sub_809927C(u8 param_1); bool8 sub_80992E0(s16 *param_1, s16 *param_2); -bool8 sub_8099328(u8 *); +bool8 sub_8099328(u8 *dungeonId); +bool8 sub_8099360(u8 *dungeonId); +bool8 sub_8099394(u8 *param); +void sub_80993C0(bool8 param); +void sub_80993D8(void); +void sub_80993E4(void); #endif // GUARD_GROUND_MAIN_H diff --git a/ld_script.ld b/ld_script.ld index be10097fb..c3eb14ea0 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -721,7 +721,6 @@ SECTIONS { src/strings.o(.rodata); data/data_810AE24_2.o(.rodata); src/position_util.o(.rodata); - data/data_8115EB8.o(.rodata); src/ground_main.o(.rodata); src/debug_field_map.o(.rodata); src/code_8099360.o(.rodata); diff --git a/src/code_8099360.c b/src/code_8099360.c index 0b8a395f5..7e5d53aed 100644 --- a/src/code_8099360.c +++ b/src/code_8099360.c @@ -9,8 +9,6 @@ #include "file_system.h" #include "palette_fade_util.h" -extern u8 gUnknown_20398B8; - void sub_8099648(void) { InitPaletteFadeTable(); diff --git a/src/event_flag.c b/src/event_flag.c index ebae0151c..3393c9114 100644 --- a/src/event_flag.c +++ b/src/event_flag.c @@ -16,13 +16,13 @@ #include "pokemon.h" #include "pokemon_3.h" #include "ground_place.h" +#include "ground_main.h" #include "script_vars_info.h" EWRAM_DATA u8 gScriptVarBuffer[SCRIPT_VAR_BUFFER_LEN] = {0}; // NDS=020876DC #include "data/event_flag.h" -extern bool8 GetScriptMode(void); extern bool8 HasCompletedAllMazes(void); extern void sub_809733C(u32, u32); extern void sub_80973A8(u32, u32); diff --git a/src/ground_main.c b/src/ground_main.c index 35097ef6b..743f0fc2a 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -1,4 +1,6 @@ #include "global.h" +#include "globaldata.h" +#include "ground_main.h" #include "constants/dungeon.h" #include "constants/move_id.h" #include "structs/str_wonder_mail.h" @@ -12,7 +14,6 @@ #include "ground_place.h" #include "debug.h" #include "event_flag.h" -#include "ground_main.h" #include "ground_map.h" #include "ground_map_1.h" #include "play_time.h" @@ -61,22 +62,18 @@ extern void sub_809B638(); extern void nullsub_106(); extern void sub_80A73EC(); -extern void sub_8098CC8(); extern void ClearAllItems_8091FB4(); extern void sub_8095494(DungeonMailSeed *param_1, u8 index); extern u16 gUnknown_2026E4E; // TODO: Move these externs to headers -extern s16 sub_8098FCC(u32 unused); extern s16 sub_80A2654(s16 r0); extern bool8 sub_809AFAC(void); extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); extern void sub_8099768(void); -extern void nullsub_103(void); -extern void sub_8099648(void); extern void sub_809975C(void); extern void sub_809B474(void); extern void sub_80A59DC(void); @@ -94,11 +91,21 @@ extern void xxx_call_update_bg_sound_input(void); extern void sub_80060EC(void); extern void sub_809977C(void); extern void UpdateFadeInTile(s32); -extern void sub_8098C58(void); extern void sub_8001D88(void); -extern u32 GroundMainGameCancelRequest(u32 r0); extern void sub_80999D4(s32); extern void sub_8005838(s32, s32); +extern void sub_80A4B38(void); +extern void sub_80A4B54(void); + +static s16 sub_8098FCC(u32 unused); + +UNUSED static const u8 sUnusedConstData[] = { + 0, 0, 0, 0, 0x01, 0, 0, 0, 0x69, 0, 0, 0, 0x09, 0, 0, 0, 0x0c, 0, 0, 0, 0x01, 0, 0, 0, 0xb2, 0, 0, 0, + 0xb4, 0, 0, 0, 0xb6, 0, 0, 0, 0xb8, 0, 0, 0, 0xba, 0, 0, 0, 0xbc, 0, 0, 0, 0xbf, 0, 0, 0, 0xc1, 0, 0, 0, 0xc3, + 0, 0, 0, 0xc6, 0, 0, 0, 0xc9, 0, 0, 0, 0xcc, 0, 0, 0, 0xcf, 0, 0, 0, 0xa2, 0, 0, 0, 0xa2, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; u32 xxx_script_related_8098468(s32 param_1) { @@ -426,7 +433,7 @@ u32 xxx_script_related_8098468(s32 param_1) } } -void sub_8098BDC(void) +UNUSED static void sub_8098BDC(void) { sub_809B57C(); GroundScript_Unlock(); @@ -650,7 +657,7 @@ const char *GetCurrentGroundPlaceName(void) return GetGroundPlaceName(GetScriptVarValue(NULL, GROUND_PLACE)); } -s16 sub_8098FCC(u32 unused) +static s16 sub_8098FCC(u32 unused) { s32 iVar4; s32 iVar5; @@ -709,23 +716,24 @@ static inline bool8 sub_80990EC_sub(struct DungeonSetupInfo *iVar1, u32 iVar2) return flag; } -u8 sub_80990EC(struct DungeonSetupInfo *param_1, s16 param_2) +u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2) { const DungeonInfo *iVar1; u8 auStack_98 [24]; u8 nameBuffer [24]; u8 dungeonIndex; + s32 param2 = (s16) param_2; - iVar1 = GetDungeonInfo_80A2608(param_2); + iVar1 = GetDungeonInfo_80A2608(param2); dungeonIndex = iVar1->dungeonIndex; param_1->sub0.unk0.id = dungeonIndex; param_1->sub0.unk0.floor = 1; param_1->sub0.unkC = 0; - switch (sub_80A2750(param_2)) { + switch (sub_80A2750(param2)) { case 1: - if (sub_80990EC_sub(param_1, param_2)) { + if (sub_80990EC_sub(param_1, param2)) { param_1->sub0.unkC = 1; sub_80A8EC0(auStack_98, 0x5b); BoundedCopyStringtoBuffer(nameBuffer, auStack_98, POKEMON_NAME_LENGTH); @@ -761,7 +769,7 @@ u8 sub_80990EC(struct DungeonSetupInfo *param_1, s16 param_2) return iVar1->unk11; } -u8 sub_80991E0(struct DungeonSetupInfo *param_1,short *param_2) +u8 sub_80991E0(struct DungeonSetupInfo *param_1, s16 *param_2) { *param_2 = gUnknown_20398C4; if (gUnknown_203B49C) { @@ -773,11 +781,10 @@ u8 sub_80991E0(struct DungeonSetupInfo *param_1,short *param_2) } } -void sub_8099220(struct DungeonSetupInfo *param_1, s16 param_2) +void sub_8099220(struct DungeonSetupInfo *param_1, s32 param_2) { - s32 param_2_s32 = (s16)param_2; - if (param_1 != NULL) - { + s32 param_2_s32 = (s16) param_2; + if (param_1 != NULL) { gUnknown_203B49C = TRUE; gUnknown_203B49D = 0; gUnknown_20398C4 = param_2_s32; @@ -870,9 +877,6 @@ void sub_80993C0(bool8 param) gUnknown_20398B8 = (param == FALSE); } -extern void sub_80A4B38(void); -extern void sub_80A4B54(void); - void sub_80993D8(void) { sub_80A4B38(); diff --git a/src/ground_script.c b/src/ground_script.c index d6dfbec65..d7af35d93 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -79,21 +79,17 @@ void sub_809B1D4(u8, s32, s32, const char*); void GroundScriptLockJumpZero(s16); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); -bool8 sub_8098DCC(u32 speed); -void sub_8099220(void *param_1, s32 param_2); + bool8 sub_809B260(void *dst); bool8 sub_809B18C(s32 *sp); bool8 sub_809AFFC(u8 *); -u8 sub_80990EC(struct DungeonSetupInfo *param_1, s32 param_2); extern u8 IsTextboxOpen_809A750(void); extern void sub_809AB4C(s32, s32); extern void sub_809ABB4(s32, s32); extern void sub_809AC18(s32, s32); -void sub_8098C58(void); -void sub_8098CC8(void); bool8 sub_80961D8(void); void ResetMailbox(void); void sub_80963FC(void); diff --git a/src/main_loops.c b/src/main_loops.c index 369a99e7a..f28ecdd31 100644 --- a/src/main_loops.c +++ b/src/main_loops.c @@ -85,10 +85,7 @@ static void LoadAndRunDungeon_Async(DungeonSetupStruct *r0); static u32 xxx_script_related_8001334(u32 r0); static void MainLoops_RunFrameActions(u32 unused); -extern u8 sub_80990EC(DungeonSetupInfo *param_1, s32 param_2); extern bool8 sub_8096A08(u8 dungeon, Pokemon *pokemon); -extern u8 sub_80991E0(DungeonSetupInfo *param_1,short *param_2); -extern u32 xxx_script_related_8098468(u32); extern void IncrementNumAdventures(void); extern void sub_8096BD0(void); diff --git a/src/run_dungeon.c b/src/run_dungeon.c index 298789329..96ecec69b 100644 --- a/src/run_dungeon.c +++ b/src/run_dungeon.c @@ -60,6 +60,7 @@ #include "dungeon_mon_spawn.h" #include "dungeon_action_execution.h" #include "dungeon_8041AD0.h" +#include "ground_main.h" EWRAM_INIT struct UnkStruct_203B414 *gUnknown_203B414 = NULL; EWRAM_INIT Dungeon *gDungeon = NULL; diff --git a/src/save_write.c b/src/save_write.c index 055a43ee8..567da8792 100644 --- a/src/save_write.c +++ b/src/save_write.c @@ -6,6 +6,7 @@ #include "save_write.h" #include "string_format.h" #include "menu_input.h" +#include "ground_main.h" // size: 0x20 typedef struct SavePakWrite diff --git a/src/textbox.c b/src/textbox.c index 0bb397a58..93488b063 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -139,7 +139,6 @@ bool8 CreateHelperPelipperMenu(s16); u32 sub_802E90C(); void sub_802E918(); u32 sub_80282DC(u8 *r0); -void sub_809927C(u8); void sub_80282FC(void); extern u8 CreateThankYouMailPelipper(void); extern u8 sub_802E864(void); diff --git a/src/wonder_mail.c b/src/wonder_mail.c index 816662a19..1b2527b66 100644 --- a/src/wonder_mail.c +++ b/src/wonder_mail.c @@ -23,12 +23,12 @@ #include "wonder_mail_4.h" #include "wonder_mail_5.h" #include "naming_screen.h" +#include "ground_main.h" static EWRAM_INIT WonderMailStruct_203B2C0 *sUnknown_203B2C0 = {NULL}; extern void sub_8011C28(u32); -extern void sub_809927C(u8); extern u32 sub_8031050(); extern void sub_80310B4(); extern void nullsub_130(void); diff --git a/src/wonder_mail_2.c b/src/wonder_mail_2.c index a31c34c03..7a88243fe 100644 --- a/src/wonder_mail_2.c +++ b/src/wonder_mail_2.c @@ -18,6 +18,7 @@ #include "save_write.h" #include "string_format.h" #include "text_1.h" +#include "ground_main.h" struct unkStruct_203B2C8 { From 32f1d3bd078bf530c269fdd0cbc3940f1ea32bfc Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 23 Oct 2025 11:52:22 +0200 Subject: [PATCH 08/13] ground weather --- data/data_8115F5C_2_1.s | 15 ---- include/ground_map.h | 1 + include/ground_map_1.h | 31 ------- include/ground_weather.h | 14 +++ ld_script.ld | 3 +- src/debug_field_map.c | 1 - src/ground_main.c | 1 - src/ground_map.c | 38 ++++---- src/ground_script.c | 3 +- src/{ground_map_1.c => ground_weather.c} | 107 +++++++++++++---------- sym_iwram_init.txt | 2 +- 11 files changed, 104 insertions(+), 112 deletions(-) delete mode 100644 include/ground_map_1.h create mode 100644 include/ground_weather.h rename src/{ground_map_1.c => ground_weather.c} (68%) diff --git a/data/data_8115F5C_2_1.s b/data/data_8115F5C_2_1.s index 9c49edd39..d943e0c5c 100644 --- a/data/data_8115F5C_2_1.s +++ b/data/data_8115F5C_2_1.s @@ -188,19 +188,4 @@ gUnknown_8117770: @ 8117770 .4byte GroundMap_FileText .byte 0x7f, 0x05, 0x00, 0x00 .4byte GroundMap_Action_Text -.string "pksdir0\0" -.align 2,0 -.global gUnknown_8117784 -gUnknown_8117784: @ 8117784 -.byte 0x0d, 0x00, 0x01, 0x00, 0x80, 0x03, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0xbc, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -.global gGroundWeatherSelect -gGroundWeatherSelect: @ 811779C -.string "GroundWeather Select %3d %3d\0" -.align 2,0 - -.global gUnknown_81177BC -gUnknown_81177BC: @ 81177BC -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 diff --git a/include/ground_map.h b/include/ground_map.h index 2f9df06a1..2190f08a0 100644 --- a/include/ground_map.h +++ b/include/ground_map.h @@ -18,5 +18,6 @@ void GroundMap_ExecuteStation(s32 _map, s32 _group, s32 _sector, bool32 _setScri bool8 GroundMapNotifyAll(s16); bool8 sub_80A4D48(s16 index); void GroundMap_Action(void); +void sub_80A5E70(void); #endif // GUARD_GROUND_MAP_H diff --git a/include/ground_map_1.h b/include/ground_map_1.h deleted file mode 100644 index c725b3a82..000000000 --- a/include/ground_map_1.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef GUARD_GROUND_MAP_1_H -#define GUARD_GROUND_MAP_1_H - -// size: 0x24 -#include "structs/str_position.h" - -typedef struct unkStruct_3001B74 -{ - s16 unk0; - u8 unk2; - s32 unk4; - s32 unk8; - PixelPos unkC; - u32 unk14; - u32 unk18; - u32 unk1C; - u32 unk20; -} unkStruct_3001B74; - -void GroundWeather_Select(s16); -void nullsub_121(void); -void nullsub_122(void); -void nullsub_123(void); - -void sub_80A5E70(void); -void sub_80A5E8C(u8); -void sub_80A5EBC(void); -void sub_80A5EDC(u8); -void sub_80A60D8(void); - -#endif // GUARD_GROUND_MAP_1_H diff --git a/include/ground_weather.h b/include/ground_weather.h new file mode 100644 index 000000000..81eeb3a58 --- /dev/null +++ b/include/ground_weather.h @@ -0,0 +1,14 @@ +#ifndef GUARD_GROUND_WEATHER_H +#define GUARD_GROUND_WEATHER_H + +void sub_80A5E8C(bool8 param_1); +void sub_80A5EBC(void); +void sub_80A5EDC(bool8 param_1); +void nullsub_121(void); +void nullsub_122(void); +void GroundWeather_Select(s16 param_1); +void nullsub_123(void); +void sub_80A60D8(void); +void sub_80A62D0(void); + +#endif /* GUARD_GROUND_WEATHER_H */ diff --git a/ld_script.ld b/ld_script.ld index c3eb14ea0..8413b66df 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -346,7 +346,7 @@ SECTIONS { src/ground_place.o(.text); src/ground_bg.o(.text); src/ground_map.o(.text); - src/ground_map_1.o(.text); + src/ground_weather.o(.text); src/ground_sprite.o(.text); src/ground_sprite_data.o(.text); src/ground_sprite_monster.o(.text); @@ -735,6 +735,7 @@ SECTIONS { src/ground_place.o(.rodata); src/ground_bg.o(.rodata); data/data_8115F5C_2_1.o(.rodata); + src/ground_weather.o(.rodata); src/ground_sprite.o(.rodata); src/ground_sprite_data.o(.rodata); src/ground_sprite_monster.o(.rodata); diff --git a/src/debug_field_map.c b/src/debug_field_map.c index 6d6cffe2c..cec6be9ea 100644 --- a/src/debug_field_map.c +++ b/src/debug_field_map.c @@ -10,7 +10,6 @@ #include "text_2.h" #include "text_3.h" #include "ground_map.h" -#include "ground_map_1.h" #include "palette_util.h" #include "string_format.h" #include "sprite.h" diff --git a/src/ground_main.c b/src/ground_main.c index 743f0fc2a..f0d99e8ad 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -15,7 +15,6 @@ #include "debug.h" #include "event_flag.h" #include "ground_map.h" -#include "ground_map_1.h" #include "play_time.h" #include "pokemon.h" #include "text_util.h" diff --git a/src/ground_map.c b/src/ground_map.c index 38b90b974..a728a7287 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -4,9 +4,9 @@ #include "ground_bg.h" #include "ground_main.h" #include "ground_map.h" -#include "ground_map_1.h" #include "ground_script.h" #include "ground_script_file.h" +#include "ground_weather.h" #include "memory.h" #include "ground_map_conversion_table.h" #include "code_800558C.h" @@ -56,6 +56,7 @@ extern u8 sub_80A4660(GroundBg *, u32, s32, s32); void GroundMap_SelectDungeon(s32 mapId, const DungeonLocation *loc, u32 param_2); void sub_80A56D8(const PixelPos*); +extern void sub_80A62D0(void); void AllocGroundMapAction(void) { @@ -1217,7 +1218,7 @@ void sub_80A59A0(s32 param_1, PixelPos *param_2, u32 param_3) void GroundMap_Action(void) { nullsub_123(); - HandleAction((Action *)gGroundMapAction, &gUnknown_8117770); + HandleAction(&gGroundMapAction->action, &gUnknown_8117770); } void sub_80A59DC(void) @@ -1231,9 +1232,9 @@ void sub_80A59DC(void) } switch (gGroundMapAction->groundMapId) { - case 0xA2: - case 0xA3: - case 0xDF: { + case MAP_PERSONALITY_TEST_CYAN: + case MAP_PERSONALITY_TEST_PURPLE: + case MAP_PERSONALITY_TEST_MULTICOLOR: { PixelPos pixPos2; gGroundMapAction->unkF4 += 2; @@ -1249,8 +1250,8 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 1, &pixPos2); break; } - case 0xA8: - case 0xAA: { + case MAP_FUGITIVES_SNOW_ROAD: + case MAP_FUGITIVES_BLIZZARD_ROAD: { PixelPos pixPos2; gGroundMapAction->unkF0 += gGroundMapAction->unkE8.x; @@ -1262,7 +1263,7 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos2); break; } - case 0xAE: { + case MAP_NIGHTMARE: { PixelPos pixPos2; gGroundMapAction->unkF0 += gGroundMapAction->unkE8.x; @@ -1275,14 +1276,14 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 1, &pixPos2); break; } - case 0xAB: { + case MAP_SUMMIT_SUNSET: { PixelPos pixPos2 = pixPos; sub_80A4580(gGroundMapDungeon_3001B70, 0, &pixPos2); SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos2); break; } - case 0xAF: { + case MAP_NIGHT_SKY_1: { PixelPos pixPos2; SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos); @@ -1298,7 +1299,7 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 1, &pixPos2); break; } - case 0xB0: { + case MAP_NIGHT_SKY_2: { PixelPos pixPos2; gGroundMapAction->unkF0 += gGroundMapAction->unkE8.x; @@ -1313,7 +1314,7 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos2); break; } - case 0xBA: { + case MAP_SILENT_CHASM_ENTRY: { PixelPos pixPos2; SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 1, &pixPos); @@ -1326,7 +1327,7 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos2); break; } - case 4: { + case MAP_PELIPPER_POST_OFFICE: { PixelPos pixPos2; SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos); @@ -1339,7 +1340,7 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 1, &pixPos2); break; } - case 0xE0: { + case MAP_TITLE_SCREEN: { PixelPos pixPos2; SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos); @@ -1351,7 +1352,7 @@ void sub_80A59DC(void) SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 1, &pixPos2); break; } - case 0xA1: { + case MAP_FRIEND_AREA_FINAL_ISLAND: { PixelPos pixPos2; SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, &pixPos); @@ -1370,3 +1371,10 @@ void sub_80A59DC(void) sub_80A60D8(); } +void sub_80A5E70(void) +{ + if (gGroundMapDungeon_3001B70 != NULL) + sub_80A49E8(gGroundMapDungeon_3001B70); + + sub_80A62D0(); +} diff --git a/src/ground_script.c b/src/ground_script.c index d7af35d93..ffc6e2894 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -23,7 +23,6 @@ #include "ground_lives.h" #include "ground_main.h" #include "ground_map.h" -#include "ground_map_1.h" #include "ground_script.h" #include "ground_sprite.h" #include "input.h" @@ -53,12 +52,12 @@ #include "ground_event.h" #include "ground_effect.h" #include "ground_object.h" +#include "ground_weather.h" #include "code_809D148.h" void GroundMap_Select(s16); void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); void GroundMap_GetStationScript(ScriptInfoSmall *out, s16, s32, s32); -void GroundWeather_Select(s16); // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files diff --git a/src/ground_map_1.c b/src/ground_weather.c similarity index 68% rename from src/ground_map_1.c rename to src/ground_weather.c index 06bac87f5..cd6458ca8 100644 --- a/src/ground_map_1.c +++ b/src/ground_weather.c @@ -1,31 +1,46 @@ #include "global.h" +#include "globaldata.h" +#include "ground_weather.h" #include "code_800558C.h" #include "debug.h" #include "event_flag.h" #include "ground_bg.h" #include "ground_map.h" -#include "ground_map_1.h" #include "memory.h" +typedef struct unkStruct_3001B74 +{ + s16 unk0; + u8 unk2; + s32 unk4; + s32 unk8; + PixelPos unkC; + u32 unk14; + u32 unk18; + u32 unk1C; + u32 unk20; +} unkStruct_3001B74; + IWRAM_INIT unkStruct_3001B74 *gUnknown_3001B74 = {NULL}; IWRAM_INIT GroundBg *gUnknown_3001B78 = {NULL}; -extern const SubStruct_52C gUnknown_8117784; extern const s16 gUnknown_811E5F4[][2]; -extern const u8 gGroundWeatherSelect[]; -extern const PixelPos gUnknown_81177BC; -static void sub_80A62D0(void); +static const SubStruct_52C gUnknown_8117784 = { + .unk0 = 13, + .unk2 = 1, + .unk4 = 0x380, + .unk6 = 0x80, + .unk8 = 0x80, + .unkA = 0, + .numLayers = 1, + .unkE = 0xbc, + .unk10 = 0x5e, + .unk12 = 0, + .unk14 = NULL, +}; -void sub_80A5E70(void) -{ - if (gGroundMapDungeon_3001B70 != NULL) - sub_80A49E8(gGroundMapDungeon_3001B70); - - sub_80A62D0(); -} - -void sub_80A5E8C(u8 param_1) +void sub_80A5E8C(bool8 param_1) { gUnknown_3001B74 = MemoryAlloc(sizeof(unkStruct_3001B74), 6); gUnknown_3001B74->unk0 = -1; @@ -40,7 +55,7 @@ void sub_80A5EBC(void) gUnknown_3001B74 = NULL; } -void sub_80A5EDC(u8 param_1) +void sub_80A5EDC(bool8 param_1) { SetScriptVarValue(NULL, WEATHER_KIND, -1); gUnknown_3001B74->unk0 = -1; @@ -48,8 +63,7 @@ void sub_80A5EDC(u8 param_1) if (gUnknown_3001B78 != NULL) { GroundBg_FreeAll(gUnknown_3001B78); - MemoryFree(gUnknown_3001B78); - gUnknown_3001B78 = NULL; + FREE_AND_SET_NULL(gUnknown_3001B78); } if (param_1) { @@ -73,7 +87,7 @@ void GroundWeather_Select(s16 param_1) iVar2 = param_1; iVar3 = iVar2; - Log(0, gGroundWeatherSelect, iVar2, gUnknown_3001B74->unk2); + Log(0, "GroundWeather Select %3d %3d", iVar2, gUnknown_3001B74->unk2); SetScriptVarValue(NULL, WEATHER_KIND, iVar2); gUnknown_3001B74->unk0 = iVar2; @@ -144,7 +158,7 @@ void sub_80A60D8(void) switch ((s16)(gUnknown_3001B74->unk0 + 1)) { case 10: { - PixelPos localArray; + PixelPos pixPos; gUnknown_3001B74->unk4 += 2; gUnknown_3001B74->unk8 += 1; @@ -153,70 +167,73 @@ void sub_80A60D8(void) sub_80A4580(gUnknown_3001B78, 0, &gUnknown_3001B74->unkC); gUnknown_3001B74->unk4 &= 3; gUnknown_3001B74->unk8 &= 3; - sub_80A56C0(&localArray); - localArray.x -= gUnknown_3001B74->unkC.x; - localArray.y += gUnknown_3001B74->unkC.y; - sub_80A4580(gUnknown_3001B78, 0, &localArray); - SetCameraPositionForLayer(gUnknown_3001B78, 0, &localArray); + sub_80A56C0(&pixPos); + pixPos.x -= gUnknown_3001B74->unkC.x; + pixPos.y += gUnknown_3001B74->unkC.y; + sub_80A4580(gUnknown_3001B78, 0, &pixPos); + SetCameraPositionForLayer(gUnknown_3001B78, 0, &pixPos); break; } case 11: case 12: case 13: case 14: { - PixelPos localArray; + PixelPos pixPos; - sub_80A56C0(&localArray); - SetCameraPositionForLayer(gUnknown_3001B78,0,&localArray); + sub_80A56C0(&pixPos); + SetCameraPositionForLayer(gUnknown_3001B78,0,&pixPos); break; } case 15: { - PixelPos localArray; + PixelPos pixPos; gUnknown_3001B74->unk4++; gUnknown_3001B74->unkC.x += gUnknown_3001B74->unk4 / 4; sub_80A4580(gUnknown_3001B78, 0, &gUnknown_3001B74->unkC); gUnknown_3001B74->unk4 &= 3; - sub_80A56C0(&localArray); - localArray.x -= gUnknown_3001B74->unkC.x; - localArray.y = 0; - sub_80A4580(gUnknown_3001B78, 0, &localArray); - SetCameraPositionForLayer(gUnknown_3001B78, 0, &localArray); + sub_80A56C0(&pixPos); + pixPos.x -= gUnknown_3001B74->unkC.x; + pixPos.y = 0; + sub_80A4580(gUnknown_3001B78, 0, &pixPos); + SetCameraPositionForLayer(gUnknown_3001B78, 0, &pixPos); break; } case 16: { - PixelPos localArray; + PixelPos pixPos; gUnknown_3001B74->unk4 += 2; gUnknown_3001B74->unkC.x += gUnknown_3001B74->unk4 / 4; sub_80A4580(gUnknown_3001B78, 0, &gUnknown_3001B74->unkC); gUnknown_3001B74->unk4 &= 3; - sub_80A56C0(&localArray); - localArray.x -= gUnknown_3001B74->unkC.x; - localArray.y = 0; - sub_80A4580(gUnknown_3001B78, 0, &localArray); - SetCameraPositionForLayer(gUnknown_3001B78, 0, &localArray); + sub_80A56C0(&pixPos); + pixPos.x -= gUnknown_3001B74->unkC.x; + pixPos.y = 0; + sub_80A4580(gUnknown_3001B78, 0, &pixPos); + SetCameraPositionForLayer(gUnknown_3001B78, 0, &pixPos); break; } default: { - PixelPos localArray; + PixelPos pixPos; const s16 *puVar1 = gUnknown_811E5F4[gUnknown_3001B74->unk0]; if (puVar1[0] == 0) { - sub_80A56C0(&localArray); - SetCameraPositionForLayer(gUnknown_3001B78,0,&localArray); + sub_80A56C0(&pixPos); + SetCameraPositionForLayer(gUnknown_3001B78,0,&pixPos); break; } } // NOTE: Fallthrough needed here. - case 0: - SetCameraPositionForLayer(gUnknown_3001B78, 0, &gUnknown_81177BC); + case 0: { + static const PixelPos pixPos = {0, 0}; + + SetCameraPositionForLayer(gUnknown_3001B78, 0, &pixPos); break; + } } sub_80A4764(gUnknown_3001B78); } -static void sub_80A62D0(void) +void sub_80A62D0(void) { if (gUnknown_3001B74->unk2 != 0) sub_80A49E8(gUnknown_3001B78); diff --git a/sym_iwram_init.txt b/sym_iwram_init.txt index fad124f42..f22a3d294 100644 --- a/sym_iwram_init.txt +++ b/sym_iwram_init.txt @@ -6,7 +6,7 @@ .include "src/textbox.o" .include "src/unk_ds_only_feature.o" .include "src/ground_map.o" -.include "src/ground_map_1.o" +.include "src/ground_weather.o" .include "src/ground_sprite.o" .include "src/ground_lives.o" .include "src/ground_object.o" From b82cc398e2dc464cbcc50d42039b7254219e805c Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 23 Oct 2025 13:02:56 +0200 Subject: [PATCH 09/13] move some ground map data to src --- data/data_8115F5C_2_1.s | 142 ---------------------------------------- ld_script.ld | 1 + src/ground_map.c | 53 +++++---------- 3 files changed, 17 insertions(+), 179 deletions(-) diff --git a/data/data_8115F5C_2_1.s b/data/data_8115F5C_2_1.s index d943e0c5c..6e3e6375a 100644 --- a/data/data_8115F5C_2_1.s +++ b/data/data_8115F5C_2_1.s @@ -46,146 +46,4 @@ gUnknown_81173C0: @ 81173C0 .byte 0xd9, 0x00, 0x00, 0x00, 0x1d, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, 0x1a, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x00, 0x00, 0x00, 0x35, 0x64, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.global GroundMap_FileText -GroundMap_FileText: @ 8117510 -.string "../ground/ground_map.c\0" -.align 2,0 - -.global GroundMap_Reset_Text -GroundMap_Reset_Text: @ Reset -.string "GroundMap_Reset\0" -.align 2,0 - -.global gUnknown_8117538 -gUnknown_8117538: @ 8117538 -.4byte GroundMap_FileText -.byte 0xf8, 0x00, 0x00, 0x00 -.4byte GroundMap_Reset_Text - -.global GroundMap_GetStationScript_Text -GroundMap_GetStationScript_Text: @ GetStationScript -.string "GroundMap_GetStationScript\0" -.align 2,0 - -.global gUnknown_8117560 -gUnknown_8117560: @ 8117560 -.4byte GroundMap_FileText -.byte 0x38, 0x01, 0x00, 0x00 -.4byte GroundMap_GetStationScript_Text - -.global gUnknown_811756C -gUnknown_811756C: @ 811756C -.string "GroundMap ExecuteStation %3d %3d %3d\0" -.align 2,0 - -.global gUnknown_8117594 -gUnknown_8117594: @ 8117594 -.string "GroundMap ExecuteEvent %3d %d ==================\0" -.align 2,0 - -.global GroundMap_ExecuteEventText -GroundMap_ExecuteEventText: @ ExecuteEventText -.string "GroundMap_ExecuteEvent\0" -.align 2,0 - -.global gUnknown_81175E0 -gUnknown_81175E0: @ 81175E0 -.4byte GroundMap_FileText -.byte 0x7D, 0x01, 0x00, 0x00 -.4byte GroundMap_ExecuteEventText - -.global gUnknown_81175EC -gUnknown_81175EC: @ 81175EC -.string "GroundMap ExecuteStation %3d %3d %3d %d ==================\0" -.align 2,0 - -.global GroundMap_ExecuteStationText -GroundMap_ExecuteStationText: @ ExecuteStationText -.string "GroundMap_ExecuteStation\0" -.align 2,0 - -.global gUnknown_8117644 -gUnknown_8117644: @ 8117644 -.4byte GroundMap_FileText -.4byte 0x199 -.4byte GroundMap_ExecuteStationText - -.global gUnknown_8117650 -gUnknown_8117650: @ 8117650 -.string "GroundMap ExecuteEnter %3d ==================\0" -.align 2,0 - -.global GroundMap_ExecuteEnterText -GroundMap_ExecuteEnterText: @ ExecuteEnterText -.string "GroundMap_ExecuteEnter\0" -.align 2,0 - -.global gUnknown_8117698 -gUnknown_8117698: @ 8117698 -.4byte GroundMap_FileText -.4byte 0x1B3 -.4byte GroundMap_ExecuteEnterText - -.global gUnknown_81176A4 -gUnknown_81176A4: @ 81176A4 -.string "GroundMap Select %3d\0" -.align 2,0 - -.global GroundMap_SelectText -GroundMap_SelectText: @ SelectText -.string "GroundMap_Select\0" -.align 2,0 - -.global gUnknown_81176D0 -gUnknown_81176D0: @ 81176D0 -.4byte GroundMap_FileText -.4byte 0x249 -.4byte GroundMap_SelectText - -.global gUnknown_81176DC -gUnknown_81176DC: @ 81176DC -.string "select map type error %d %d\0" -.align 2,0 - -.global gUnknown_81176F8 -gUnknown_81176F8: @ 81176F8 -.4byte 0 -.4byte 0 - -.global gUnknown_8117700 -gUnknown_8117700: @ 8117700 -.string "GroundMap SelectDungeon %3d\0" -.align 2,0 - -.global GroundMap_SelectDungeonText -GroundMap_SelectDungeonText: @ SelectDungeonText -.string "GroundMap_SelectDungeon\0" -.align 2,0 - -.global gUnknown_8117734 -gUnknown_8117734: @ 8117734 -.4byte GroundMap_FileText -.4byte 0x2C6 -.4byte GroundMap_SelectDungeonText - -.global gUnknown_8117740 -gUnknown_8117740: @ 8117740 -.string "map type error %d\0" -.align 2,0 - -.global gUnknown_8117754 -gUnknown_8117754: @ 8117754 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 - -.global GroundMap_Action_Text -GroundMap_Action_Text: @ Action -.string "GroundMap_Action\0" -.align 2,0 - -.global gUnknown_8117770 -gUnknown_8117770: @ 8117770 -.4byte GroundMap_FileText -.byte 0x7f, 0x05, 0x00, 0x00 -.4byte GroundMap_Action_Text diff --git a/ld_script.ld b/ld_script.ld index 8413b66df..91ce60a6e 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -735,6 +735,7 @@ SECTIONS { src/ground_place.o(.rodata); src/ground_bg.o(.rodata); data/data_8115F5C_2_1.o(.rodata); + src/ground_map.o(.rodata); src/ground_weather.o(.rodata); src/ground_sprite.o(.rodata); src/ground_sprite_data.o(.rodata); diff --git a/src/ground_map.c b/src/ground_map.c index a728a7287..a7fbcd0a5 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -28,27 +28,6 @@ struct MapToDungeonStruct }; extern const struct MapToDungeonStruct gUnknown_81173C0[]; - -extern const DebugLocation gUnknown_8117538[]; -extern const DebugLocation gUnknown_8117560; -extern const u8 gUnknown_811756C[]; -extern const u8 gUnknown_8117594[]; -extern const DebugLocation gUnknown_81175E0; -extern const u8 gUnknown_81175EC[]; -extern const DebugLocation gUnknown_8117644; -extern const u8 gUnknown_8117650[]; -extern const DebugLocation gUnknown_8117698; -extern const u8 gUnknown_81176A4[]; -extern const DebugLocation gUnknown_81176D0; -extern const u8 gUnknown_81176DC[]; -extern const PixelPos gUnknown_81176F8; -extern const u8 gUnknown_8117700[]; -extern const DebugLocation gUnknown_8117734; -extern const u8 gUnknown_8117740[]; -extern const PixelPos gUnknown_8117754; -extern const DebugLocation gUnknown_8117770; - - extern const CallbackData gGroundScriptNullCallbacks; extern u8 sub_80A46C0(GroundBg *, u32, s32, s32); @@ -79,7 +58,7 @@ void GroundMap_Reset(void) { ClearScriptVarArray(NULL, MAP_LOCAL); ClearScriptVarArray(NULL, MAP_LOCAL_DOOR); - ActionResetScriptData((Action *)gGroundMapAction, gUnknown_8117538); + ActionResetScriptData(&gGroundMapAction->action, DEBUG_LOC_PTR("../ground/ground_map.c", 0xF8, "GroundMap_Reset")); if (gGroundMapDungeon_3001B70 != NULL) { GroundBg_FreeAll(gGroundMapDungeon_3001B70); @@ -113,8 +92,8 @@ void GroundMap_GetStationScript(ScriptInfoSmall *r0, s32 _groundScriptId, s32 _g s32 sectorId = (s8) _sectorId; ChangeScriptFile(groundScriptId); - scriptHeader = GetGroundScript(groundScriptId, &gUnknown_8117560); - Log(0, gUnknown_811756C, groundScriptId, groupId, sectorId); + scriptHeader = GetGroundScript(groundScriptId, DEBUG_LOC_PTR("../ground/ground_map.c", 0x138, "GroundMap_GetStationScript")); + Log(0, "GroundMap ExecuteStation %3d %3d %3d", groundScriptId, groupId, sectorId); { const struct GroundScriptGroup *groups = &scriptHeader->groups[groupId]; const struct GroundScriptSector *sectors = &groups->sectors[sectorId]; @@ -141,12 +120,12 @@ void GroundMap_ExecuteEvent(s16 scriptIndex, u32 param_2) index_s32 = scriptIndex; iVar2 = param_2; - Log(0, gUnknown_8117594, index_s32, iVar2); // "GroundMap ExecuteEvent %3d %d + Log(0, "GroundMap ExecuteEvent %3d %d ==================", index_s32, iVar2); GetFunctionScript(NULL, &script, index_s32); if (iVar2 != 0) script.state = 5; - GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_81175E0); + GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, DEBUG_LOC_PTR("../ground/ground_map.c", 0x17D, "GroundMap_ExecuteEvent")); } void GroundMap_ExecuteStation(s32 _map, s32 _group, s32 _sector, bool32 _setScriptState) @@ -162,12 +141,12 @@ void GroundMap_ExecuteStation(s32 _map, s32 _group, s32 _sector, bool32 _setScri sector = (s8)_sector; setScriptState = (bool8)_setScriptState; - Log(0, gUnknown_81175EC, map, group, sector, setScriptState); // GroundMap ExecuteStation %3d %3d %3d %d + Log(0, "GroundMap ExecuteStation %3d %3d %3d %d ==================", map, group, sector, setScriptState); GroundMap_GetStationScript(&script, map, group, sector); if (setScriptState != 0) script.state = 5; - GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_8117644); + GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, DEBUG_LOC_PTR("../ground/ground_map.c", 0x199, "GroundMap_ExecuteStation")); } void GroundMap_ExecuteEnter(s16 param_1) @@ -177,12 +156,12 @@ void GroundMap_ExecuteEnter(s16 param_1) iVar1 = param_1; - Log(0, gUnknown_8117650, iVar1); // GroundMap ExecuteEnter %3d + Log(0, "GroundMap ExecuteEnter %3d ==================", iVar1); GroundMap_GetFirstStationScript(&script, iVar1); script.state = 2; script.group = 0; script.sector = 0; - GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_8117698); + GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, DEBUG_LOC_PTR("../ground/ground_map.c", 0x1B3, "GroundMap_ExecuteEnter")); } UNUSED static bool8 sub_80A4D14(void) @@ -228,7 +207,7 @@ void GroundMap_Select(s32 mapId_) const GroundConversionStruct *ptr; s32 mapId = (s16) mapId_; - Log(0, gUnknown_81176A4,mapId); + Log(0, "GroundMap Select %3d", mapId); ClearScriptVarArray(NULL, MAP_LOCAL); ClearScriptVarArray(NULL, MAP_LOCAL_DOOR); sub_80A5EDC(0); @@ -265,7 +244,7 @@ void GroundMap_Select(s32 mapId_) return; } case -1: - FatalError(&gUnknown_81176D0,gUnknown_81176DC,mapId,ptr->unk0); + FatalError(DEBUG_LOC_PTR("../ground/ground_map.c", 0x249, "GroundMap_Select"),"select map type error %d %d",mapId,ptr->unk0); break; default: GroundBg_Init(gGroundMapDungeon_3001B70, &gUnknown_8117324); @@ -332,7 +311,7 @@ void GroundMap_Select(s32 mapId_) GroundWeather_Select(ptr->unk6); } - sub_80A56D8(&gUnknown_81176F8); + sub_80A56D8(&(const PixelPos) {0}); } void GroundMap_SelectDungeon(s32 mapId_, const DungeonLocation *loc, u32 param_2) @@ -340,7 +319,7 @@ void GroundMap_SelectDungeon(s32 mapId_, const DungeonLocation *loc, u32 param_2 const GroundConversionStruct *ptr; s32 mapId = (s16) mapId_; - Log('\0', gUnknown_8117700, mapId); + Log('\0', "GroundMap SelectDungeon %3d", mapId); ClearScriptVarArray(NULL, MAP_LOCAL); ClearScriptVarArray(NULL, MAP_LOCAL_DOOR); sub_80A5EDC('\0'); @@ -359,7 +338,7 @@ void GroundMap_SelectDungeon(s32 mapId_, const DungeonLocation *loc, u32 param_2 ptr = &gGroundMapConversionTable[mapId]; if (ptr->unk0 != 0xA && ptr->unk0 != 0xB) { - FatalError(&gUnknown_8117734, gUnknown_8117740, mapId); + FatalError(DEBUG_LOC_PTR("../ground/ground_map.c", 0x2C6, "GroundMap_SelectDungeon"), "map type error %d", mapId); } GroundBg_Init(gGroundMapDungeon_3001B70, &gUnknown_8117354); @@ -373,7 +352,7 @@ void GroundMap_SelectDungeon(s32 mapId_, const DungeonLocation *loc, u32 param_2 gGroundMapAction->unkF8.y = 0; gGroundMapAction->unk100 = gGroundMapAction->unk104 = gGroundMapAction->unk108 = gGroundMapAction->unk10C = 0; - sub_80A56D8(&gUnknown_8117754); + sub_80A56D8(&(const PixelPos) {0, 0}); } NAKED @@ -1218,7 +1197,7 @@ void sub_80A59A0(s32 param_1, PixelPos *param_2, u32 param_3) void GroundMap_Action(void) { nullsub_123(); - HandleAction(&gGroundMapAction->action, &gUnknown_8117770); + HandleAction(&gGroundMapAction->action, DEBUG_LOC_PTR("../ground/ground_map.c", 0x57F, "GroundMap_Action")); } void sub_80A59DC(void) From db39c95592816e8b9a69ca59f9af5885811cc6a7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 23 Oct 2025 15:19:47 +0200 Subject: [PATCH 10/13] move ground map data to C --- data/data_8115F5C_2_1.s | 49 --------- ld_script.ld | 1 - src/ground_map.c | 214 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 199 insertions(+), 65 deletions(-) delete mode 100644 data/data_8115F5C_2_1.s diff --git a/data/data_8115F5C_2_1.s b/data/data_8115F5C_2_1.s deleted file mode 100644 index 6e3e6375a..000000000 --- a/data/data_8115F5C_2_1.s +++ /dev/null @@ -1,49 +0,0 @@ -.section .rodata - - -.align 2,0 - - - -.string "pksdir0\0" -.align 2,0 - -.global gUnknown_8117324 -gUnknown_8117324: @ 8117324 -@ replacing .incbin "baserom.gba", 0x00117324, 0x18 -.byte 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x80, 0x03, 0xb0, 0x04, 0x01, 0x00, 0x01, 0x00, 0xbc, 0x00, 0x5e, 0x00, 0x00, 0x00 -.4byte sub_80A5204 - -.global gUnknown_811733C -gUnknown_811733C: @ 811733C -@ replacing .incbin "baserom.gba", 0x0011733c, 0x18 -.byte 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x04, 0xb0, 0x04, 0x00, 0x00, 0x02, 0x00, 0xbc, 0x00, 0x5e, 0x00, 0x00, 0x00 -.4byte sub_80A5204 - -.global gUnknown_8117354 -gUnknown_8117354: @ 8117354 -@ replacing .incbin "baserom.gba", 0x00117354, 0x18 -.byte 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x02, 0xb0, 0x04, 0x01, 0x00, 0x01, 0x00, 0xbc, 0x00, 0x5e, 0x00, 0x00, 0x00 -.4byte sub_80A5204 - -.global gGroundScriptNullCallbacks -gGroundScriptNullCallbacks: @ 811736C -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -.global gUnknown_81173C0 -gUnknown_81173C0: @ 81173C0 -.byte 0xb3, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x00, 0x00, 0x00, 0x02, 0x64, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x00, 0x03, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x00, 0x00, 0x00, 0x04, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x00, 0x00, 0x00 -.byte 0x05, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x00, 0x00, 0x00, 0x06, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0xc5, 0x00, 0x00, 0x00, 0x0a, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x00, 0x00, 0x00, 0x0b, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x0c, 0x64, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0xca, 0x00, 0x00, 0x00, 0x0d, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x00, 0x00, 0x00, 0x0e, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcd, 0x00, 0x00, 0x00 -.byte 0x0f, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0x00, 0x00, 0x00, 0x10, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x11, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0xd1, 0x00, 0x00, 0x00, 0x12, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd2, 0x00, 0x00, 0x00, 0x13, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00, 0x14, 0x64, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x22, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x25, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0x00, 0x00, 0x00 -.byte 0x23, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x3c, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x00, 0x00, 0x00, 0x17, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -.byte 0xd9, 0x00, 0x00, 0x00, 0x1d, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, 0x1a, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x00, 0x00, 0x00, 0x35, 0x64, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - - diff --git a/ld_script.ld b/ld_script.ld index 91ce60a6e..cfdedf3d6 100755 --- a/ld_script.ld +++ b/ld_script.ld @@ -734,7 +734,6 @@ SECTIONS { src/code_80A26CC.o(.rodata); src/ground_place.o(.rodata); src/ground_bg.o(.rodata); - data/data_8115F5C_2_1.o(.rodata); src/ground_map.o(.rodata); src/ground_weather.o(.rodata); src/ground_sprite.o(.rodata); diff --git a/src/ground_map.c b/src/ground_map.c index a7fbcd0a5..678165b09 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -1,4 +1,5 @@ #include "global.h" +#include "globaldata.h" #include "debug.h" #include "event_flag.h" #include "ground_bg.h" @@ -11,14 +12,63 @@ #include "ground_map_conversion_table.h" #include "code_800558C.h" #include "constants/dungeon.h" +#include "constants/ground_map.h" #include "code_809D148.h" +extern u8 sub_80A46C0(GroundBg *, u32, s32, s32); +extern u8 sub_80A4660(GroundBg *, u32, s32, s32); + +void GroundMap_SelectDungeon(s32 mapId, const DungeonLocation *loc, u32 param_2); +void sub_80A56D8(const PixelPos*); + IWRAM_INIT GroundMapAction *gGroundMapAction = {NULL}; IWRAM_INIT GroundBg *gGroundMapDungeon_3001B70 = {NULL}; -extern const SubStruct_52C gUnknown_8117324; -extern const SubStruct_52C gUnknown_811733C; -extern const SubStruct_52C gUnknown_8117354; +static void sub_80A5204(void *, const void *, BmaHeader *, s32); + +static const SubStruct_52C gUnknown_8117324 = { + .unk0 = 0, + .unk2 = 13, + .unk4 = 0, + .unk6 = 0x380, + .unk8 = 0x4B0, + .unkA = 1, + .numLayers = 1, + .unkE = 0xbc, + .unk10 = 0x5e, + .unk12 = 0, + .unk14 = sub_80A5204, +}; + +static const SubStruct_52C gUnknown_811733C = { + .unk0 = 0, + .unk2 = 14, + .unk4 = 0, + .unk6 = 0x400, + .unk8 = 0x4B0, + .unkA = 0, + .numLayers = 2, + .unkE = 0xbc, + .unk10 = 0x5e, + .unk12 = 0, + .unk14 = sub_80A5204, +}; + +static const SubStruct_52C gUnknown_8117354 = { + .unk0 = 0, + .unk2 = 12, + .unk4 = 0, + .unk6 = 0x200, + .unk8 = 0x4B0, + .unkA = 1, + .numLayers = 1, + .unkE = 0xbc, + .unk10 = 0x5e, + .unk12 = 0, + .unk14 = sub_80A5204, +}; + +static const CallbackData sGroundScriptNullCallbacks = {0}; struct MapToDungeonStruct { @@ -27,21 +77,155 @@ struct MapToDungeonStruct u32 unk8; }; -extern const struct MapToDungeonStruct gUnknown_81173C0[]; -extern const CallbackData gGroundScriptNullCallbacks; - -extern u8 sub_80A46C0(GroundBg *, u32, s32, s32); -extern u8 sub_80A4660(GroundBg *, u32, s32, s32); - -void GroundMap_SelectDungeon(s32 mapId, const DungeonLocation *loc, u32 param_2); -void sub_80A56D8(const PixelPos*); -extern void sub_80A62D0(void); +static const struct MapToDungeonStruct sMapToDungeonTable[] = { + { + .id = MAP_TINY_WOODS_END, + .loc = { .id = DUNGEON_TINY_WOODS, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_THUNDERWAVE_CAVE_END, + .loc = { .id = DUNGEON_THUNDERWAVE_CAVE, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MT_STEEL_END, + .loc = { .id = DUNGEON_MT_STEEL, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_SINISTER_WOODS_END, + .loc = { .id = DUNGEON_SINISTER_WOODS, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_SILENT_CHASM_END, + .loc = { .id = DUNGEON_SILENT_CHASM, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MT_THUNDER_MID, + .loc = { .id = DUNGEON_MT_THUNDER, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MT_THUNDER_END, + .loc = { .id = DUNGEON_MT_THUNDER_PEAK, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MT_BLAZE_MID, + .loc = { .id = DUNGEON_MT_BLAZE, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MT_BLAZE_END, + .loc = { .id = DUNGEON_MT_BLAZE_PEAK, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_FROSTY_FOREST_MID, + .loc = { .id = DUNGEON_FROSTY_FOREST, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_FROSTY_FOREST_END, + .loc = { .id = DUNGEON_FROSTY_GROTTO, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MT_FREEZE_MID, + .loc = { .id = DUNGEON_MT_FREEZE, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MT_FREEZE_END, + .loc = { .id = DUNGEON_MT_FREEZE_PEAK, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MAGMA_CAVERN_MID, + .loc = { .id = DUNGEON_MAGMA_CAVERN, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_MAGMA_CAVERN_END, + .loc = { .id = DUNGEON_MAGMA_CAVERN_PIT, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_SKY_TOWER_MID, + .loc = { .id = DUNGEON_SKY_TOWER, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_SKY_TOWER_END, + .loc = { .id = DUNGEON_SKY_TOWER_SUMMIT, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D14, + .loc = { .id = DUNGEON_STORMY_SEA, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D15, + .loc = { .id = DUNGEON_SILVER_TRENCH, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D16, + .loc = { .id = DUNGEON_FIERY_FIELD, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D17, + .loc = { .id = DUNGEON_LIGHTNING_FIELD, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D18, + .loc = { .id = DUNGEON_NORTHWIND_FIELD, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D19, + .loc = { .id = DUNGEON_MT_FARAWAY, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D20, + .loc = { .id = DUNGEON_WESTERN_CAVE, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D21, + .loc = { .id = DUNGEON_NORTHERN_RANGE, .floor = 100 }, + .unk8 = 0, + }, + { + .id = MAP_D23, + .loc = { .id = DUNGEON_WISH_CAVE, .floor = 20 }, + .unk8 = 0, + }, + { + .id = MAP_D25, + .loc = { .id = DUNGEON_HOWLING_FOREST, .floor = 100 }, + .unk8 = 0, + }, + // -1 = table's end + { + .id = -1, + .loc = { .id = DUNGEON_TINY_WOODS, .floor = 100 }, + .unk8 = 0, + }, +}; void AllocGroundMapAction(void) { gGroundMapAction = MemoryAlloc(sizeof(GroundMapAction), 6); gGroundMapAction->groundMapId = -1; - InitActionWithParams(&gGroundMapAction->action, &gGroundScriptNullCallbacks, 0, -1, -1); + InitActionWithParams(&gGroundMapAction->action, &sGroundScriptNullCallbacks, 0, -1, -1); sub_80A5E8C(0); GroundMap_Reset(); } @@ -235,7 +419,7 @@ void GroundMap_Select(s32 mapId_) break; case 0xA: case 0xB: { - const struct MapToDungeonStruct *mapToDungPtr = &gUnknown_81173C0[0]; + const struct MapToDungeonStruct *mapToDungPtr = sMapToDungeonTable; while (mapToDungPtr->id != -1 && mapToDungPtr->id != mapId) { mapToDungPtr++; } @@ -356,7 +540,7 @@ void GroundMap_SelectDungeon(s32 mapId_, const DungeonLocation *loc, u32 param_2 } NAKED -void sub_80A5204(void) +static void sub_80A5204(void *a, const void *b, BmaHeader *c, s32 d) { asm_unified( " push {r4-r7,lr} \n" From 46065e589914f083a3a50d6c4bf746c714e12ee2 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 23 Oct 2025 15:53:08 +0200 Subject: [PATCH 11/13] ground map includes --- include/ground_bg.h | 4 +++- include/ground_map.h | 29 +++++++++++++++++++++-------- src/code_809D148.c | 4 +--- src/debug_field_map.c | 2 -- src/ground_effect.c | 2 +- src/ground_lives.c | 4 +--- src/ground_lives_helper.c | 2 +- src/ground_main.c | 2 -- src/ground_map.c | 25 +++++++++---------------- src/ground_object.c | 4 ++-- src/ground_script.c | 8 -------- src/textbox.c | 2 +- 12 files changed, 40 insertions(+), 48 deletions(-) diff --git a/include/ground_bg.h b/include/ground_bg.h index 6c668f339..e61af5728 100644 --- a/include/ground_bg.h +++ b/include/ground_bg.h @@ -16,10 +16,12 @@ void GetCameraPositionForLayer(GroundBg *groundBg, s32 id, PixelPos *dstPos); void SetCameraPositionForLayer(GroundBg *groundBg, s32 id, const PixelPos *srcPos); void sub_80A4580(GroundBg *groundBg, s32 id, PixelPos *pixPos); void sub_80A4608(GroundBg *groundBg, PixelPos *dstPos); +void GetDungeonBounds(GroundBg *groundBg, PixelPos *dstPos1, PixelPos *dstPos2); +u8 sub_80A4660(GroundBg *groundBg, u8 bits, PixelPos *pixPos1, PixelPos *boundary); +u8 sub_80A46C0(GroundBg *groundBg, u8 bits, PixelPos *pixPos1, PixelPos *boundary); u16 sub_80A4720(GroundBg *groundBg, s32 id, PixelPos *pixPos); void sub_80A4740(GroundBg *groundBg, s32 id, PixelPos *pixPos, u32 dstVal); void sub_80A4764(GroundBg *groundBg); void sub_80A49E8(GroundBg *groundBg); -void GetDungeonBounds(GroundBg *groundBg, PixelPos *dstPos1, PixelPos *dstPos2); #endif // GUARD_GROUND_BG_H diff --git a/include/ground_map.h b/include/ground_map.h index 2190f08a0..ea4d91f4c 100644 --- a/include/ground_map.h +++ b/include/ground_map.h @@ -2,21 +2,34 @@ #define GUARD_GROUND_MAP_H #include "structs/str_position.h" +#include "structs/str_ground_script.h" +#include "structs/str_dungeon_location.h" -void GroundMap_Reset(void); void AllocGroundMapAction(void); void FreeGroundMapAction(void); +void GroundMap_Reset(void); void sub_80A4B38(void); void sub_80A4B54(void); -void sub_80A56C0(PixelPos *pos); -s16 GetAdjustedGroundMap(s32 mapId); -s16 GetGroundMapID(void); - -void GroundMap_ExecuteEnter(s16); -void GroundMap_ExecuteEvent(s16 scriptIndex, u32); +void GroundMap_GetStationScript(ScriptInfoSmall *r0, s32 _groundScriptId, s32 _groupId, s32 _sectorId); +void GroundMap_ExecuteEvent(s16 scriptIndex, u32 param_2); void GroundMap_ExecuteStation(s32 _map, s32 _group, s32 _sector, bool32 _setScriptState); -bool8 GroundMapNotifyAll(s16); +void GroundMap_ExecuteEnter(s16 param_1); +bool8 GroundMapNotifyAll(s16 param_1); bool8 sub_80A4D48(s16 index); +s16 GetAdjustedGroundMap(s32 mapId); +void GroundMap_Select(s32 mapId_); +void GroundMap_SelectDungeon(s32 mapId_, const DungeonLocation *loc, u32 param_2); +void sub_80A56A0(u8 param_1, u8 param_2); +void sub_80A56C0(PixelPos *pos); +void sub_80A56F0(PixelPos *pos); +void sub_80A5704(PixelPos *pos); +s16 GetGroundMapID(void); +bool8 GetCurrentDungeonBounds(PixelPos *pos1, PixelPos *pos2); +bool8 sub_80A579C(PixelPos *pos1, PixelPos *pos2); +bool8 CheckMapCollision_80A585C(PixelPos *pixPos1, PixelPos *boundary); +bool8 sub_80A58C8(PixelPos *pixPos1, PixelPos *boundary); +u8 sub_80A5934(u8 param_1, PixelPos *param_2, PixelPos *param_3); + void GroundMap_Action(void); void sub_80A5E70(void); diff --git a/src/code_809D148.c b/src/code_809D148.c index bd5689657..65b19a83d 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -10,6 +10,7 @@ #include "ground_lives.h" #include "ground_effect.h" #include "ground_object.h" +#include "ground_map.h" struct unkStruct_20399E8 { @@ -184,9 +185,6 @@ u8 sub_809D248(PixelPos *r0) return sUnknown_20399E8.unk44; } -// Todo: move these to appropriate header files -extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); - void sub_809D25C(void) { s32 r2, r1, r3; diff --git a/src/debug_field_map.c b/src/debug_field_map.c index cec6be9ea..474bc00af 100644 --- a/src/debug_field_map.c +++ b/src/debug_field_map.c @@ -20,8 +20,6 @@ #include "code_809D148.h" extern void sub_8012A18(s32 unused); -extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); -extern void GroundMap_Select(s16); extern void sub_80999E8(s32 a0); extern void sub_80A59DC(void); extern PixelPos SetVecFromDirectionSpeed(s8 r1, u32 r2); diff --git a/src/ground_effect.c b/src/ground_effect.c index fdb38fba6..ea1276127 100644 --- a/src/ground_effect.c +++ b/src/ground_effect.c @@ -4,6 +4,7 @@ #include "data_script.h" #include "ground_script.h" #include "ground_sprite.h" +#include "ground_map.h" #include "debug.h" #include "memory.h" @@ -49,7 +50,6 @@ struct GroundEffectTypeData extern struct GroundEffectTypeData gGroundEffectTypes[]; const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); -bool8 GetCurrentDungeonBounds(PixelPos *, PixelPos *); void sub_80A7688(struct UnkGroundSpriteStruct *ptr, s32 unused, s32 a2_, s32 a3); void sub_80A7714(struct UnkGroundSpriteStruct *); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); diff --git a/src/ground_lives.c b/src/ground_lives.c index dfd0178c8..58d5f692f 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -19,6 +19,7 @@ #include "ground_lives_helper.h" #include "ground_sprite_monster.h" #include "ground_object.h" +#include "ground_map.h" #include "code_809D148.h" struct GroundLivesMeta_Sub1 @@ -110,11 +111,8 @@ extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A595C(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); extern PixelPos SetVecFromDirectionSpeed(s32 r1, u32 r2); extern u8 sub_80A5934(s32 param_1, PixelPos *, PixelPos *); -extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); -extern bool8 sub_80A58C8(PixelPos *, PixelPos *); extern bool8 sub_809B1C0(s32 a0, u32 kind, Pokemon *a2); extern Pokemon *sub_80A8D54(s32); -extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); static s32 sub_80A7B94(s16 *a0); diff --git a/src/ground_lives_helper.c b/src/ground_lives_helper.c index f894d7727..a4b1386d4 100644 --- a/src/ground_lives_helper.c +++ b/src/ground_lives_helper.c @@ -6,11 +6,11 @@ #include "game_options.h" #include "ground_main.h" #include "ground_script.h" +#include "ground_map.h" extern void nullsub_104(void); extern void sub_809C6CC(u16 param_1); extern bool8 sub_809B260(s32 *a0); -extern void GroundMap_ExecuteEvent(s32, s32); void nullsub_117(void) { diff --git a/src/ground_main.c b/src/ground_main.c index f0d99e8ad..6d5409290 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -93,8 +93,6 @@ extern void UpdateFadeInTile(s32); extern void sub_8001D88(void); extern void sub_80999D4(s32); extern void sub_8005838(s32, s32); -extern void sub_80A4B38(void); -extern void sub_80A4B54(void); static s16 sub_8098FCC(u32 unused); diff --git a/src/ground_map.c b/src/ground_map.c index 678165b09..ba4322291 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -1,10 +1,10 @@ #include "global.h" #include "globaldata.h" +#include "ground_map.h" #include "debug.h" #include "event_flag.h" #include "ground_bg.h" #include "ground_main.h" -#include "ground_map.h" #include "ground_script.h" #include "ground_script_file.h" #include "ground_weather.h" @@ -15,16 +15,11 @@ #include "constants/ground_map.h" #include "code_809D148.h" -extern u8 sub_80A46C0(GroundBg *, u32, s32, s32); -extern u8 sub_80A4660(GroundBg *, u32, s32, s32); - -void GroundMap_SelectDungeon(s32 mapId, const DungeonLocation *loc, u32 param_2); -void sub_80A56D8(const PixelPos*); - IWRAM_INIT GroundMapAction *gGroundMapAction = {NULL}; IWRAM_INIT GroundBg *gGroundMapDungeon_3001B70 = {NULL}; static void sub_80A5204(void *, const void *, BmaHeader *, s32); +static void sub_80A56D8(const PixelPos *pos); static const SubStruct_52C gUnknown_8117324 = { .unk0 = 0, @@ -1218,7 +1213,7 @@ void sub_80A56C0(PixelPos *pos) GetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, pos); } -void sub_80A56D8(const PixelPos *pos) +static void sub_80A56D8(const PixelPos *pos) { SetCameraPositionForLayer(gGroundMapDungeon_3001B70, 0, pos); } @@ -1307,7 +1302,7 @@ bool8 sub_80A579C(PixelPos *pos1, PixelPos *pos2) return FALSE; } -bool8 CheckMapCollision_80A585C(PixelPos *pixPos1,PixelPos *boundary) +bool8 CheckMapCollision_80A585C(PixelPos *pixPos1, PixelPos *boundary) { u8 *currPtr; int i, j; @@ -1331,7 +1326,7 @@ bool8 CheckMapCollision_80A585C(PixelPos *pixPos1,PixelPos *boundary) return FALSE; } -bool8 sub_80A58C8(PixelPos *pixPos1,PixelPos *boundary) +bool8 sub_80A58C8(PixelPos *pixPos1, PixelPos *boundary) { u8 *currPtr; int i, j; @@ -1355,16 +1350,14 @@ bool8 sub_80A58C8(PixelPos *pixPos1,PixelPos *boundary) return FALSE; } -u8 sub_80A5934(s32 param_1, s32 param_2, s32 param_3) +u8 sub_80A5934(u8 param_1, PixelPos *param_2, PixelPos *param_3) { - u32 param_1_u32 = (u8)param_1; - return sub_80A4660(gGroundMapDungeon_3001B70, param_1_u32, param_2, param_3); + return sub_80A4660(gGroundMapDungeon_3001B70, param_1, param_2, param_3); } -u8 sub_80A595C(s32 param_1, s32 param_2, s32 param_3) +u8 sub_80A595C(u8 param_1, PixelPos *param_2, PixelPos *param_3) { - u32 param_1_u32 = (u8)param_1; - return sub_80A46C0(gGroundMapDungeon_3001B70, param_1_u32, param_2, param_3); + return sub_80A46C0(gGroundMapDungeon_3001B70, param_1, param_2, param_3); } u16 sub_80A5984(s32 param_1, PixelPos *param_2) diff --git a/src/ground_object.c b/src/ground_object.c index 7970d9848..f80ee70ed 100644 --- a/src/ground_object.c +++ b/src/ground_object.c @@ -8,6 +8,7 @@ #include "ground_script.h" #include "ground_sprite.h" #include "ground_lives.h" +#include "ground_map.h" #include "memory.h" typedef struct GroundObject { @@ -54,10 +55,8 @@ const struct GroundScriptHeader *GetGroundScript(s16 a0, DebugLocation *); void sub_80A7658(struct UnkGroundSpriteStruct *); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); -extern bool8 CheckMapCollision_80A585C(PixelPos *, PixelPos *); extern void sub_80A7664(struct UnkGroundSpriteStruct *ptr, PixelPos *pixelPos, s32 a2); -extern bool8 GetCurrentDungeonBounds(PixelPos *a0, PixelPos *a1); void sub_80A75CC(void *, s32, s32, s32); static void GroundObject_Delete(s32 index_); @@ -153,6 +152,7 @@ const u8 gGroundObjectFileName[]; + static const struct ScriptCommand gUnknown_81182F4[] = { diff --git a/src/ground_script.c b/src/ground_script.c index ffc6e2894..2a553e9cd 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -55,10 +55,6 @@ #include "ground_weather.h" #include "code_809D148.h" -void GroundMap_Select(s16); -void GroundMap_SelectDungeon(s32, DungeonLocation*, u32); -void GroundMap_GetStationScript(ScriptInfoSmall *out, s16, s32, s32); - // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files char sub_8002984(s32, u8); @@ -96,12 +92,8 @@ void sub_8096488(void); bool8 sub_80964B4(void); bool8 sub_8097640(); u8 sub_80964E4(); -void sub_80A56A0(s32, s32); -void sub_80A56F0(PixelPos *); -void sub_80A5704(PixelPos *); s32 sub_80A5984(); void sub_80A59A0(s32, s32 *, u16); -extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); // For gScriptLocks, gScriptLockConds, gUnlockBranchLabels #define SCRIPT_LOCKS_ARR_COUNT 129 diff --git a/src/textbox.c b/src/textbox.c index 93488b063..710d348f4 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -23,6 +23,7 @@ #include "flash.h" #include "friend_list_menu.h" #include "ground_lives.h" +#include "ground_map.h" #include "ground_main.h" #include "ground_script.h" #include "gulpin_shop_801FB50.h" @@ -124,7 +125,6 @@ void sub_8096BD0(void); bool8 DrawCredits(s32 creditsCategoryIndex, s32); u32 sub_8035574(); void sub_803565C(void); -void GroundMap_ExecuteEvent(s16, u32); bool8 sub_8015080(u8 *buffer, const MenuItem *menuItems); s32 sub_801516C(); void sub_80151A4(); From 4d11518c2170e8263f7b247fff8b5bfa5b46df44 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 23 Oct 2025 15:59:41 +0200 Subject: [PATCH 12/13] ground map externs --- include/ground_map.h | 5 ++++- src/debug_field_map.c | 1 - src/ground_lives.c | 2 -- src/ground_main.c | 6 ------ src/ground_map.c | 5 ++--- src/ground_script.c | 9 +++------ 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/ground_map.h b/include/ground_map.h index ea4d91f4c..1286a32e4 100644 --- a/include/ground_map.h +++ b/include/ground_map.h @@ -29,8 +29,11 @@ bool8 sub_80A579C(PixelPos *pos1, PixelPos *pos2); bool8 CheckMapCollision_80A585C(PixelPos *pixPos1, PixelPos *boundary); bool8 sub_80A58C8(PixelPos *pixPos1, PixelPos *boundary); u8 sub_80A5934(u8 param_1, PixelPos *param_2, PixelPos *param_3); - +u8 sub_80A595C(u8 param_1, PixelPos *param_2, PixelPos *param_3); +u16 sub_80A5984(s32 param_1, PixelPos *param_2); +void sub_80A59A0(s32 param_1, PixelPos *param_2, u16 param_3); void GroundMap_Action(void); +void sub_80A59DC(void); void sub_80A5E70(void); #endif // GUARD_GROUND_MAP_H diff --git a/src/debug_field_map.c b/src/debug_field_map.c index 474bc00af..4f129fb44 100644 --- a/src/debug_field_map.c +++ b/src/debug_field_map.c @@ -21,7 +21,6 @@ extern void sub_8012A18(s32 unused); extern void sub_80999E8(s32 a0); -extern void sub_80A59DC(void); extern PixelPos SetVecFromDirectionSpeed(s8 r1, u32 r2); UNUSED static void DebugMapViewer(void) diff --git a/src/ground_lives.c b/src/ground_lives.c index 58d5f692f..a5ab5cd25 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -108,9 +108,7 @@ extern const struct GroundLiveTypeData gGroundLivesTypeData_811E63C[]; extern s32 sub_8002984(s32 _direction1, u32 caseID); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); -extern bool8 sub_80A595C(u32 a0, PixelPos *pixelPosArg1, PixelPos *pixelPosArg2); extern PixelPos SetVecFromDirectionSpeed(s32 r1, u32 r2); -extern u8 sub_80A5934(s32 param_1, PixelPos *, PixelPos *); extern bool8 sub_809B1C0(s32 a0, u32 kind, Pokemon *a2); extern Pokemon *sub_80A8D54(s32); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); diff --git a/src/ground_main.c b/src/ground_main.c index 6d5409290..3ffde5ae8 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -52,12 +52,8 @@ EWRAM_INIT u8 gUnknown_203B49D = {0}; extern void sub_809B57C(); extern void sub_809D25C(); -extern void sub_80A59DC(); -extern void sub_809B614(); extern void sub_809CA20(); extern void sub_80A6E80(); -extern void sub_8099BE4(); -extern void sub_809B638(); extern void nullsub_106(); extern void sub_80A73EC(); @@ -75,13 +71,11 @@ extern bool8 sub_8099B94(void); extern void sub_8099768(void); extern void sub_809975C(void); extern void sub_809B474(void); -extern void sub_80A59DC(void); extern void sub_809B614(void); extern void sub_8099BE4(void); extern void sub_8099744(void); extern void WaitForNextFrameAndAdvanceRNG(void); extern void LoadBufferedInputs(void); -extern void sub_80A5E70(void); extern void sub_809B638(void); extern void sub_8099750(void); extern void nullsub_16(void); diff --git a/src/ground_map.c b/src/ground_map.c index ba4322291..0de14f94b 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -1365,10 +1365,9 @@ u16 sub_80A5984(s32 param_1, PixelPos *param_2) return sub_80A4720(gGroundMapDungeon_3001B70, param_1, param_2); } -void sub_80A59A0(s32 param_1, PixelPos *param_2, u32 param_3) +void sub_80A59A0(s32 param_1, PixelPos *param_2, u16 param_3) { - u32 param_3_u32 = (u16)param_3; - sub_80A4740(gGroundMapDungeon_3001B70, param_1, param_2, param_3_u32); + sub_80A4740(gGroundMapDungeon_3001B70, param_1, param_2, param_3); } void GroundMap_Action(void) diff --git a/src/ground_script.c b/src/ground_script.c index 2a553e9cd..9898f766f 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -92,8 +92,6 @@ void sub_8096488(void); bool8 sub_80964B4(void); bool8 sub_8097640(); u8 sub_80964E4(); -s32 sub_80A5984(); -void sub_80A59A0(s32, s32 *, u16); // For gScriptLocks, gScriptLockConds, gUnlockBranchLabels #define SCRIPT_LOCKS_ARR_COUNT 129 @@ -3683,10 +3681,9 @@ static s32 sub_80A14E8(Action *action, u8 idx, u32 r2, s32 r3) } return 0; case 0x3D: { - s32 sp_338[2]; - sp_338[0] = r2; - sp_338[1] = r3; - sub_80A59A0(0, sp_338, sub_80A5984(1, sp_338)); + PixelPos sp_338 = {r2, r3}; + + sub_80A59A0(0, &sp_338, sub_80A5984(1, &sp_338)); return 0; } case 0x3E: From 05d70f94ee75804f3b307dc0c3a2cc2104ad6783 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 23 Oct 2025 16:43:08 +0200 Subject: [PATCH 13/13] textbox externs --- include/memory.h | 2 +- include/naming_screen.h | 2 +- include/textbox.h | 20 ++++++++++++++ src/ground_lives.c | 2 +- src/ground_lives_helper.c | 2 +- src/ground_main.c | 5 ---- src/ground_script.c | 28 +++---------------- src/memory.c | 6 ++--- src/naming_screen.c | 2 +- src/script_item.c | 2 +- src/textbox.c | 57 ++++++++++++++++++++------------------- 11 files changed, 63 insertions(+), 65 deletions(-) diff --git a/include/memory.h b/include/memory.h index ca1b4baca..da84ee09e 100644 --- a/include/memory.h +++ b/include/memory.h @@ -7,7 +7,7 @@ void MemoryClear8(void *dest, s32 size); void MemoryClear16(u16 *dest, s32 size); void MemoryFill8(void *dest, u8 value, s32 size); void MemoryFill16(u16 *dest, u16 value, s32 size); -void MemoryCopy8(void *dest, void *src, s32 size); +void MemoryCopy8(void *dest, const void *src, s32 size); void MemoryCopy32(u32 *dest, const u32 *src, s32 size); void *MemoryAlloc(s32 size, s32 group); diff --git a/include/naming_screen.h b/include/naming_screen.h index b8a70ee79..4a965e610 100644 --- a/include/naming_screen.h +++ b/include/naming_screen.h @@ -4,7 +4,7 @@ u32 NamingScreen_Init(u32 type, u8 *defaultText); u32 NamingScreen_HandleInput(void); void NamingScreen_Free(void); -s32 GetStrWidth(u8 *buffer, s32 size); +s32 GetStrWidth(const u8 *buffer, s32 size); s32 GetMaxPokeNameWidth(void); #endif diff --git a/include/textbox.h b/include/textbox.h index 20bae4349..0328e8e36 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -2,6 +2,7 @@ #define GUARD_TEXTBOX_H #include "structs/str_position.h" +#include "structs/menu.h" enum { @@ -15,16 +16,35 @@ enum void TextboxInit(void); void TextboxFree(void); void TextboxResetAll(void); +void sub_809A6E4(u16 r0); +void sub_809A6F8(u16 r0); void SetAutoPressTextboxFrames(s32 frames); void SetAutoPressTextboxMidEndMsgFrames(s32 endMsgFrames, s32 midMsgFrames); +bool8 IsTextboxOpen_809A750(void); +bool8 sub_809A768(void); bool8 ScriptClearTextbox(void); bool8 ScriptClearTextbox2(void); void ResetTextboxPortrait(s16 id_); +bool8 sub_809AB4C(s32 a0_, s32 a1_); +bool8 sub_809ABB4(s32 id_, s32 a1_); +bool8 sub_809AC18(s32 a0_, s32 a1_); bool8 ScriptSetPortraitInfo(s32 portraitId_, s32 spriteId_, s32 placementId_); bool8 ScriptSetPortraitPosDelta(s32 portraitId_, PixelPos *newPosDelta); bool8 ScriptPrintText(s32 scriptMsgType, s32 speakerId_, const char *text); bool8 ScriptPrintTextOnBg(const char *text); bool8 ScriptPrintTextOnBg2(const char *text); bool8 ScriptPrintTextOnBgAuto(s32 unused, const char *text); +bool8 sub_809AFAC(void); +void sub_809AFC8(s32 a0_, s32 a1, s32 a2_, const char *text); +bool8 sub_809AFFC(u8 *a0); +void sub_809B028(const MenuItem * menuItems, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); +bool8 sub_809B18C(s32 *sp); +bool8 sub_809B1C0(s32 a0, u32 kind, void *a2); +bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, void *a3); +bool8 sub_809B260(s32 *a0); +void sub_809B474(void); +void sub_809B57C(void); +void sub_809B614(void); +void sub_809B638(void); #endif // GUARD_WONDER_MAIL_H diff --git a/src/ground_lives.c b/src/ground_lives.c index a5ab5cd25..0589dd29b 100644 --- a/src/ground_lives.c +++ b/src/ground_lives.c @@ -20,6 +20,7 @@ #include "ground_sprite_monster.h" #include "ground_object.h" #include "ground_map.h" +#include "textbox.h" #include "code_809D148.h" struct GroundLivesMeta_Sub1 @@ -109,7 +110,6 @@ extern s32 sub_8002984(s32 _direction1, u32 caseID); extern bool8 sub_80A66F8(struct UnkGroundSpriteStruct *ptr); extern bool8 sub_80A671C(struct UnkGroundSpriteStruct *ptr); extern PixelPos SetVecFromDirectionSpeed(s32 r1, u32 r2); -extern bool8 sub_809B1C0(s32 a0, u32 kind, Pokemon *a2); extern Pokemon *sub_80A8D54(s32); extern const struct GroundScriptHeader *GetGroundScript(s16 a0, const DebugLocation *); diff --git a/src/ground_lives_helper.c b/src/ground_lives_helper.c index a4b1386d4..b7f62c7c7 100644 --- a/src/ground_lives_helper.c +++ b/src/ground_lives_helper.c @@ -7,10 +7,10 @@ #include "ground_main.h" #include "ground_script.h" #include "ground_map.h" +#include "textbox.h" extern void nullsub_104(void); extern void sub_809C6CC(u16 param_1); -extern bool8 sub_809B260(s32 *a0); void nullsub_117(void) { diff --git a/src/ground_main.c b/src/ground_main.c index 3ffde5ae8..bcf6247c8 100644 --- a/src/ground_main.c +++ b/src/ground_main.c @@ -50,7 +50,6 @@ EWRAM_DATA u8 gUnknown_2039950 = 0; EWRAM_INIT bool8 gUnknown_203B49C = {0}; EWRAM_INIT u8 gUnknown_203B49D = {0}; -extern void sub_809B57C(); extern void sub_809D25C(); extern void sub_809CA20(); extern void sub_80A6E80(); @@ -64,19 +63,15 @@ extern u16 gUnknown_2026E4E; // TODO: Move these externs to headers extern s16 sub_80A2654(s16 r0); -extern bool8 sub_809AFAC(void); extern bool8 sub_80048BC(void); extern u8 sub_80023E4(u32); extern bool8 sub_8099B94(void); extern void sub_8099768(void); extern void sub_809975C(void); -extern void sub_809B474(void); -extern void sub_809B614(void); extern void sub_8099BE4(void); extern void sub_8099744(void); extern void WaitForNextFrameAndAdvanceRNG(void); extern void LoadBufferedInputs(void); -extern void sub_809B638(void); extern void sub_8099750(void); extern void nullsub_16(void); extern void UpdateAdventureAchievements(void); diff --git a/src/ground_script.c b/src/ground_script.c index 9898f766f..3a25886fc 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -59,32 +59,12 @@ // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files char sub_8002984(s32, u8); bool8 sub_802FCF0(void); - - void sub_809733C(s16, bool8); void sub_80973A8(s16, bool8); void sub_80975A8(s16, bool8); -u32 sub_809A6E4(); -u32 sub_809A6F8(); -u32 sub_809A768(); -void sub_809AFC8(bool8, s32, s32, const char*); -u32 sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); -bool8 sub_809B1C0(s32, s32, char[12]); -void sub_809B1D4(u8, s32, s32, const char*); void GroundScriptLockJumpZero(s16); bool8 sub_8099B94(void); PixelPos SetVecFromDirectionSpeed(s8, s32); - - -bool8 sub_809B260(void *dst); -bool8 sub_809B18C(s32 *sp); -bool8 sub_809AFFC(u8 *); - -extern u8 IsTextboxOpen_809A750(void); -extern void sub_809AB4C(s32, s32); -extern void sub_809ABB4(s32, s32); -extern void sub_809AC18(s32, s32); - bool8 sub_80961D8(void); void ResetMailbox(void); void sub_80963FC(void); @@ -1372,7 +1352,7 @@ static s32 ExecuteScriptCommand(Action *action) } case 0x04: { if (curCmd.arg1 == -1) { - if (!(u8)sub_802FCF0() && (u8)sub_809B1C0(12,0,0)) { + if (!(u8)sub_802FCF0() && sub_809B1C0(12,0,NULL)) { sub_80A87AC(0, 11); action->scriptData.branchDiscriminant = 0; } else { @@ -1388,7 +1368,7 @@ static s32 ExecuteScriptCommand(Action *action) } case 0x06: { if (curCmd.arg1 == -1) { - if ((s8)sub_809B1C0(36, 0, 0)) { + if (sub_809B1C0(36, 0, NULL)) { sub_80A87AC(0, 11); action->scriptData.branchDiscriminant = 0; return 2; @@ -1769,7 +1749,7 @@ static s32 ExecuteScriptCommand(Action *action) break; } case 0x2c: { - if (!(s8)sub_809A768()) break; + if (!sub_809A768()) break; sub_80A87AC(0, 10); if (GroundScriptCheckLockCondition(action, 0)) return 2; break; @@ -1900,7 +1880,7 @@ static s32 ExecuteScriptCommand(Action *action) break; } case 0x3c: { - sub_809B1D4(curCmd.argByte, curCmd.arg1, curCmd.arg2, curCmd.argPtr); + sub_809B1D4(curCmd.argByte, curCmd.arg1, curCmd.arg2, (void *) curCmd.argPtr); sub_80A87AC(0, 11); return 2; } diff --git a/src/memory.c b/src/memory.c index 796870090..94f448b4c 100644 --- a/src/memory.c +++ b/src/memory.c @@ -130,10 +130,10 @@ UNUSED static void MemoryFill32(u32 *dest, u32 value, s32 size) #endif // arm9.bin::02010BB4 -void MemoryCopy8(void *dest, void *src, s32 size) +void MemoryCopy8(void *dest, const void *src, s32 size) { u8 *dCur = dest; - u8 *sCur = src; + const u8 *sCur = src; while (size > 0) { size -= 1; @@ -141,7 +141,7 @@ void MemoryCopy8(void *dest, void *src, s32 size) } } -UNUSED static void MemoryCopy16(u16 *dest, u16 *src, s32 size) +UNUSED static void MemoryCopy16(u16 *dest, const u16 *src, s32 size) { while (size > 0) { size -= 2; diff --git a/src/naming_screen.c b/src/naming_screen.c index c61b00c99..1b0f7c4ed 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -873,7 +873,7 @@ static void UpdateLetterWidths(void) } } -s32 GetStrWidth(u8 *buffer, s32 size) +s32 GetStrWidth(const u8 *buffer, s32 size) { s32 i; s32 width = 0; diff --git a/src/script_item.c b/src/script_item.c index 8db7a8480..14d6ee4dc 100644 --- a/src/script_item.c +++ b/src/script_item.c @@ -7,9 +7,9 @@ #include "memory.h" #include "string_format.h" #include "code_800D090.h" +#include "textbox.h" extern bool8 ScriptPrintText(s32 a0, s32 a1_, const char *text); -extern u8 IsTextboxOpen_809A750(void); // These are only written to. struct ScriptItemsData diff --git a/src/textbox.c b/src/textbox.c index 710d348f4..13f6d33f3 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -90,6 +90,12 @@ enum { TEXTBOX_TYPE_ON_BG_AUTO, // Prints text on a bg, waits 32 frames and then fades out the text }; +union MonOrStringPtr +{ + u8 *str; + Pokemon *mon; +}; + struct Textbox { // size: 0x5A8 @@ -103,7 +109,7 @@ struct Textbox u32 unk420; u32 unk424; u32 unk428; - u8 *unk42C; + union MonOrStringPtr unk42C; s32 unk430; s32 unk434; u32 fill438; @@ -114,7 +120,6 @@ struct Textbox static IWRAM_INIT struct Textbox *sTextbox = { NULL }; extern bool8 sub_802FCF0(void); -bool8 IsTextboxOpen_809B40C(struct TextboxText *); void sub_809B028(const MenuItem *, s32 a1_, s32 a2, s32 a3, s32 a4_, const char *text); bool8 sub_809B18C(s32 *sp); @@ -150,11 +155,6 @@ extern u32 ThankYouMailPelipperCallback(void); extern u32 HelperPelipperCallback(void); extern u32 sub_802E890(void); extern u32 sub_802DFD8(void); -void sub_809B57C(void); -bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, u8 *a3); - -u8 *sub_809B428(u8 *a0, s32 a1, u8 *a2); -bool8 sub_809B648(void); #define TEXTBOX_FLAG_UNUSED_x2 0x2 // Unused, but set for almost all flag sets #define TEXTBOX_FLAG_INSTANT_TEXT 0x20 @@ -241,6 +241,9 @@ static void ResetAllTextboxPortraits(void); static bool8 ScriptPrintTextInternal(struct TextboxText *ptr, u32 flags_, s32 a2_, const char *text); static u32 SetTextboxType(u32 textboxType, bool8 unused); static void ResetTextbox(void); +static bool8 IsTextboxOpen_809B40C(struct TextboxText *a0); +static u8 *sub_809B428(u8 *a0, s32 a1, u8 *a2); +static bool8 sub_809B648(void); static void sub_809C39C(void); static void sub_809C3D8(void); static void sub_809C504(void); @@ -269,7 +272,7 @@ void TextboxInit(void) sTextbox->unk420 = 0; sTextbox->unk424 = 0; sTextbox->unk428 = 0; - sTextbox->unk42C = NULL; + sTextbox->unk42C.str = NULL; sTextbox->unk430 = -1; sTextbox->unk434 = -1; ResetAllTextboxPortraits(); @@ -336,7 +339,7 @@ void sub_809A6F8(u16 r0) gUnknown_20399DC &= ~r0; } -u16 sub_809A70C(u16 r0) +UNUSED static u16 sub_809A70C(u16 r0) { return gUnknown_20399DC; } @@ -359,14 +362,14 @@ void SetAutoPressTextboxMidEndMsgFrames(s32 endMsgFrames, s32 midMsgFrames) SetDialogueBoxAutoPressFrames(endMsgFrames, midMsgFrames); } -u8 IsTextboxOpen_809A750(void) +bool8 IsTextboxOpen_809A750(void) { return IsTextboxOpen_809B40C(&sTextbox->text); } -u32 sub_809A768(void) +bool8 sub_809A768(void) { - return 0; + return FALSE; } // I think these two functions are functionally equivalent. @@ -860,12 +863,12 @@ bool8 sub_809B18C(s32 *sp) return (sTextbox->unk420 == 3); } -bool8 sub_809B1C0(s32 a0, u32 kind, u8 *a2) +bool8 sub_809B1C0(s32 a0, u32 kind, void *a2) { return sub_809B1D4(a0, kind, 0, a2); } -bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, u8 *a3) +bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, void *a3) { switch (a0) { case 0xB: @@ -888,7 +891,7 @@ bool8 sub_809B1D4(s32 a0, u32 kind, s32 a2, u8 *a3) sTextbox->unk420 = 1; sTextbox->unk424 = kind; sTextbox->unk428 = a2; - sTextbox->unk42C = a3; + sTextbox->unk42C.str = a3; sTextbox->unk430 = -1; return TRUE; } @@ -959,7 +962,7 @@ static bool8 ScriptPrintTextInternal(struct TextboxText *textboxText, u32 flags_ return TRUE; } -bool8 IsTextboxOpen_809B40C(struct TextboxText *a0) +static bool8 IsTextboxOpen_809B40C(struct TextboxText *a0) { switch (a0->unk4) { case 0: @@ -971,7 +974,7 @@ bool8 IsTextboxOpen_809B40C(struct TextboxText *a0) } // It seems this function is effectively unused. It could be different in Blue however. The u8 * arguments most likely are pointers to some text drawing structures. -u8 *sub_809B428(u8 *a0, s32 a1, u8 *a2) +static u8 *sub_809B428(u8 *a0, s32 a1, u8 *a2) { switch (a0[2]) { case 0x49: @@ -1102,7 +1105,7 @@ void sub_809B638(void) xxx_call_update_bg_vram(); } -void nullsub_210(void) +UNUSED static void nullsub_210(void) { } @@ -1300,7 +1303,7 @@ static const struct unkStruct_3001B64_unk418 gUnknown_8116318 = .unkC = sub_801B6AC, }; -bool8 sub_809B648(void) +static bool8 sub_809B648(void) { switch (sTextbox->unk414) { case 2: @@ -1339,10 +1342,10 @@ bool8 sub_809B648(void) if (sTextbox->unk420 == 1) { ResetTextbox(); if (sTextbox->unk424 == 0) { - CreateConfirmNameMenu(0, sTextbox->unk42C); + CreateConfirmNameMenu(0, sTextbox->unk42C.str); } else { - CreateConfirmNameMenu(2, sTextbox->unk42C); + CreateConfirmNameMenu(2, sTextbox->unk42C.str); } return 1; } @@ -1368,7 +1371,7 @@ bool8 sub_809B648(void) case 5: if (sTextbox->unk420 == 1) { ResetTextbox(); - CreateConfirmNameMenu(1, sTextbox->unk42C); + CreateConfirmNameMenu(1, sTextbox->unk42C.str); } else { s32 var = sub_8016080(); @@ -1390,7 +1393,7 @@ bool8 sub_809B648(void) case 6: if (sTextbox->unk420 == 1) { ResetTextbox(); - NamingScreen_Init(4,sTextbox->unk42C); + NamingScreen_Init(4,sTextbox->unk42C.str); } else { s32 var = NamingScreen_HandleInput(); @@ -1412,12 +1415,12 @@ bool8 sub_809B648(void) } return 1; case 7: - sub_801D014((void *) sTextbox->unk42C); + sub_801D014(sTextbox->unk42C.mon); sTextbox->unk418 = &gUnknown_81161A8; PlayMenuSoundEffect(4); return 1; case 8: - sub_801D014((void *) sTextbox->unk42C); + sub_801D014(sTextbox->unk42C.mon); sTextbox->unk418 = &gUnknown_81161B8; PlayMenuSoundEffect(4); return 1; @@ -1425,7 +1428,7 @@ bool8 sub_809B648(void) ResetTextbox(); if (sTextbox->unk420 == 1) { ResetTextbox(); - if (!sub_8015080(sTextbox->unk42C, gUnknown_811610C)) { + if (!sub_8015080(sTextbox->unk42C.str, gUnknown_811610C)) { sTextbox->unk430 = -1; return 0; } @@ -1449,7 +1452,7 @@ bool8 sub_809B648(void) ResetTextbox(); if (sTextbox->unk420 == 1) { ResetTextbox(); - if (!sub_8015080(sTextbox->unk42C, sEmptyMenuItems)) { + if (!sub_8015080(sTextbox->unk42C.str, sEmptyMenuItems)) { sTextbox->unk430 = -1; return 0; }