From b143e989e0c2772476f7cd22569a2a379d8687ac Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 16:28:53 +0100 Subject: [PATCH 1/2] decompile GroundMap_GetStationScript --- asm/ground_map.s | 65 ------------------------------------------------ ld_script.txt | 1 - src/ground_map.c | 27 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 66 deletions(-) delete mode 100644 asm/ground_map.s diff --git a/asm/ground_map.s b/asm/ground_map.s deleted file mode 100644 index f64662c0e..000000000 --- a/asm/ground_map.s +++ /dev/null @@ -1,65 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start GroundMap_GetStationScript -GroundMap_GetStationScript: - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x4 - mov r8, r0 - adds r4, r1, 0 - adds r6, r2, 0 - adds r5, r3, 0 - lsls r4, 16 - asrs r4, 16 - lsls r6, 16 - asrs r6, 16 - lsls r5, 24 - asrs r5, 24 - adds r0, r4, 0 - bl ChangeScriptFile - ldr r1, _080A4BE0 - adds r0, r4, 0 - bl GetGroundScript - mov r9, r0 - ldr r1, _080A4BE4 - str r5, [sp] - movs r0, 0 - adds r2, r4, 0 - adds r3, r6, 0 - bl Log - lsls r1, r6, 3 - mov r2, r9 - ldr r0, [r2, 0x4] - adds r0, r1 - lsls r1, r5, 2 - adds r1, r5 - lsls r1, 3 - ldr r0, [r0, 0x4] - adds r0, r1 - ldr r0, [r0, 0x24] - ldr r0, [r0] - ldr r0, [r0, 0x8] - mov r1, r8 - str r0, [r1] - movs r0, 0x2 - strh r0, [r1, 0x4] - strh r6, [r1, 0x6] - strb r5, [r1, 0x8] - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080A4BE0: .4byte gUnknown_8117560 -_080A4BE4: .4byte gUnknown_811756C - thumb_func_end GroundMap_GetStationScript diff --git a/ld_script.txt b/ld_script.txt index 7e04d3d29..9779e0fbb 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -341,7 +341,6 @@ SECTIONS { src/code_80A26CC.o(.text); asm/code_80A26CC_1.o(.text); src/ground_map.o(.text); - asm/ground_map.o(.text); src/ground_map_1.o(.text); asm/ground_map_1.o(.text); src/ground_map_2.o(.text); diff --git a/src/ground_map.c b/src/ground_map.c index 8899cb91f..4289d438b 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -65,3 +65,30 @@ void sub_80A4B54(void) nullsub_122(); } + +bool8 ChangeScriptFile(s32 a0); +const struct GroundScriptHeader *GetGroundScript(s32 a0, DebugLocation *); + +extern DebugLocation gUnknown_8117560; +extern const u8 gUnknown_811756C[]; + +void GroundMap_GetStationScript(ScriptInfoSmall *r0, s32 _groundScriptId, s32 _groupId, s32 _sectorId) +{ + const struct GroundScriptHeader *scriptHeader; + s32 groundScriptId = (s16) _groundScriptId; + s32 groupId = (s16) _groupId; + s32 sectorId = (s8) _sectorId; + + ChangeScriptFile(groundScriptId); + scriptHeader = GetGroundScript(groundScriptId, &gUnknown_8117560); + Log(0, gUnknown_811756C, groundScriptId, groupId, sectorId); + { + const struct GroundScriptGroup *groups = &scriptHeader->groups[groupId]; + const struct GroundScriptSector *sectors = &groups->sectors[sectorId]; + r0->ptr = sectors->station[0]->script; + } + + r0->state = 2; + r0->group = groupId; + r0->sector = sectorId; +} From 253108611cf64e33ec2265ae64e8974469e708f6 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 2 Dec 2024 16:32:38 +0100 Subject: [PATCH 2/2] remove ground_map_1.c --- ld_script.txt | 1 - src/ground_map.c | 126 ++++++++++++++++++++++++++++++++++++++++++--- src/ground_map_1.c | 121 ------------------------------------------- 3 files changed, 120 insertions(+), 128 deletions(-) delete mode 100644 src/ground_map_1.c diff --git a/ld_script.txt b/ld_script.txt index 9779e0fbb..0b0e64673 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -341,7 +341,6 @@ SECTIONS { src/code_80A26CC.o(.text); asm/code_80A26CC_1.o(.text); src/ground_map.o(.text); - src/ground_map_1.o(.text); asm/ground_map_1.o(.text); src/ground_map_2.o(.text); src/ground_sprite.o(.text); diff --git a/src/ground_map.c b/src/ground_map.c index 4289d438b..7fe89d226 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -1,6 +1,7 @@ #include "global.h" #include "debug.h" #include "event_flag.h" +#include "ground_main.h" #include "ground_map.h" #include "ground_map_2.h" #include "ground_script.h" @@ -9,6 +10,24 @@ IWRAM_DATA GroundMapAction *gGroundMapAction = {0}; IWRAM_DATA unkStruct_3001B70 *gGroundMapDungeon_3001B70 = {0}; +extern GroundMapAction *gGroundMapAction; + +extern const u8 gUnknown_8117594[]; +extern const u8 gUnknown_81175EC[]; +extern const DebugLocation gUnknown_81175E0; +extern const DebugLocation gUnknown_8117644; +extern const u8 gUnknown_8117650[]; +extern const DebugLocation gUnknown_8117698; + +bool8 ChangeScriptFile(s32 a0); +const struct GroundScriptHeader *GetGroundScript(s32 a0, DebugLocation *); + +extern DebugLocation gUnknown_8117560; +extern const u8 gUnknown_811756C[]; + +extern u8 sub_809D678(void *); +extern bool8 GroundScriptNotify(void *, s32); + extern const CallbackData gGroundScriptNullCallbacks; extern const DebugLocation gUnknown_8117538[]; @@ -66,12 +85,6 @@ void sub_80A4B54(void) nullsub_122(); } -bool8 ChangeScriptFile(s32 a0); -const struct GroundScriptHeader *GetGroundScript(s32 a0, DebugLocation *); - -extern DebugLocation gUnknown_8117560; -extern const u8 gUnknown_811756C[]; - void GroundMap_GetStationScript(ScriptInfoSmall *r0, s32 _groundScriptId, s32 _groupId, s32 _sectorId) { const struct GroundScriptHeader *scriptHeader; @@ -92,3 +105,104 @@ void GroundMap_GetStationScript(ScriptInfoSmall *r0, s32 _groundScriptId, s32 _g r0->group = groupId; r0->sector = sectorId; } + +static void GroundMap_GetFirstStationScript(ScriptInfoSmall *script, s16 r1) +{ + GroundMap_GetStationScript(script, r1, 0, 0); +} + +void GroundMap_ExecuteEvent(s16 scriptIndex, u32 param_2) +{ + ScriptInfoSmall script; + s32 index_s32; + u8 iVar2; + + index_s32 = scriptIndex; + iVar2 = param_2; + + Log(0,gUnknown_8117594, index_s32, iVar2); // "GroundMap ExecuteEvent %3d %d + GetFunctionScript(NULL, &script, index_s32); + if (iVar2 != 0) + script.state = 5; + + GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_81175E0); +} + +void GroundMap_ExecuteStation(s16 param_1, s16 param_2, s8 param_3, u32 param_4) +{ + ScriptInfoSmall script; + s32 iVar1; + s32 iVar2; + s32 iVar3; + u8 iVar4; + + iVar1 = param_1; + iVar2 = param_2; + iVar3 = param_3; + iVar4 = param_4; + + Log(0, gUnknown_81175EC, iVar1, iVar2, iVar3, iVar4); // GroundMap ExecuteStation %3d %3d %3d %d + GroundMap_GetStationScript(&script, iVar1, iVar2, iVar3); + if (iVar4 != 0) + script.state = 5; + + GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_8117644); +} + +void GroundMap_ExecuteEnter(s16 param_1) +{ + ScriptInfoSmall script; + s32 iVar1; + + iVar1 = param_1; + + Log(0, gUnknown_8117650, iVar1); // GroundMap ExecuteEnter %3d + GroundMap_GetFirstStationScript(&script, iVar1); + script.state = 2; + script.group = 0; + script.sector = 0; + GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_8117698); +} + +UNUSED static u8 sub_80A4D14(void) +{ + return sub_809D678(&gGroundMapAction->action); +} + +bool8 GroundMapNotifyAll(s16 param_1) +{ + s32 iVar1 = param_1; + return GroundScriptNotify(&gGroundMapAction->action, iVar1); +} + +bool8 sub_80A4D48(s16 index) +{ + if (index == -1) return TRUE; + if (gGroundConversion_811BAF4[index].unk0 == 5) return FALSE; + if (gGroundConversion_811BAF4[index].unk0 != 8) return TRUE; + return FALSE; +} + +s32 GetAdjustedGroundMap(s16 param_1) +{ + s32 iVar5; + + iVar5 = param_1; + + switch(iVar5) + { + case 9: + case 0xC: + iVar5 = (s16)(iVar5 + ((GetScriptVarValue(NULL, BASE_KIND) * 6) + GetScriptVarValue(NULL, BASE_LEVEL))); + break; + case 2: + if (sub_80023E4(6)) { + iVar5 = 3; + } + break; + default: + break; + } + + return iVar5; +} diff --git a/src/ground_map_1.c b/src/ground_map_1.c deleted file mode 100644 index 032b87125..000000000 --- a/src/ground_map_1.c +++ /dev/null @@ -1,121 +0,0 @@ -#include "global.h" -#include "debug.h" -#include "event_flag.h" -#include "ground_main.h" -#include "ground_map_1.h" -#include "ground_script.h" - -extern GroundMapAction *gGroundMapAction; - -extern const u8 gUnknown_8117594[]; -extern const u8 gUnknown_81175EC[]; -extern const DebugLocation gUnknown_81175E0; -extern const DebugLocation gUnknown_8117644; -extern const u8 gUnknown_8117650[]; -extern const DebugLocation gUnknown_8117698; - -extern void GroundMap_GetStationScript(ScriptInfoSmall *, s16, u32, u32); - -extern u8 sub_809D678(void *); -extern bool8 GroundScriptNotify(void *, s32); - -static void GroundMap_GetFirstStationScript(ScriptInfoSmall *script, s16 r1) -{ - GroundMap_GetStationScript(script, r1, 0, 0); -} - -void GroundMap_ExecuteEvent(s16 scriptIndex, u32 param_2) -{ - ScriptInfoSmall script; - s32 index_s32; - u8 iVar2; - - index_s32 = scriptIndex; - iVar2 = param_2; - - Log(0,gUnknown_8117594, index_s32, iVar2); // "GroundMap ExecuteEvent %3d %d - GetFunctionScript(NULL, &script, index_s32); - if (iVar2 != 0) - script.state = 5; - - GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_81175E0); -} - -void GroundMap_ExecuteStation(s16 param_1, s16 param_2, s8 param_3, u32 param_4) -{ - ScriptInfoSmall script; - s32 iVar1; - s32 iVar2; - s32 iVar3; - u8 iVar4; - - iVar1 = param_1; - iVar2 = param_2; - iVar3 = param_3; - iVar4 = param_4; - - Log(0, gUnknown_81175EC, iVar1, iVar2, iVar3, iVar4); // GroundMap ExecuteStation %3d %3d %3d %d - GroundMap_GetStationScript(&script, iVar1, iVar2, iVar3); - if (iVar4 != 0) - script.state = 5; - - GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_8117644); -} - -void GroundMap_ExecuteEnter(s16 param_1) -{ - ScriptInfoSmall script; - s32 iVar1; - - iVar1 = param_1; - - Log(0, gUnknown_8117650, iVar1); // GroundMap ExecuteEnter %3d - GroundMap_GetFirstStationScript(&script, iVar1); - script.state = 2; - script.group = 0; - script.sector = 0; - GroundScript_ExecutePP(&gGroundMapAction->action, 0, &script, &gUnknown_8117698); -} - -UNUSED static u8 sub_80A4D14(void) -{ - return sub_809D678(&gGroundMapAction->action); -} - -bool8 GroundMapNotifyAll(s16 param_1) -{ - s32 iVar1 = param_1; - return GroundScriptNotify(&gGroundMapAction->action, iVar1); -} - -bool8 sub_80A4D48(s16 index) -{ - if (index == -1) return TRUE; - if (gGroundConversion_811BAF4[index].unk0 == 5) return FALSE; - if (gGroundConversion_811BAF4[index].unk0 != 8) return TRUE; - return FALSE; -} - -s32 GetAdjustedGroundMap(s16 param_1) -{ - s32 iVar5; - - iVar5 = param_1; - - switch(iVar5) - { - case 9: - case 0xC: - iVar5 = (s16)(iVar5 + ((GetScriptVarValue(NULL, BASE_KIND) * 6) + GetScriptVarValue(NULL, BASE_LEVEL))); - break; - case 2: - if (sub_80023E4(6)) { - iVar5 = 3; - } - break; - default: - break; - } - - return iVar5; -}