From 0c53d4011fc15d7d6f4f5eec81b1d46be0a666bb Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 18 Dec 2024 11:28:07 +0100 Subject: [PATCH] start iwram init --- Makefile | 8 +++++++- asm/code_8272724.s | 3 --- include/gba/defines.h | 2 ++ ld_script.txt | 20 +++++++++++++++++--- src/code_80001DC.c | 2 +- src/code_80035F0.c | 4 ++++ src/code_8023144.c | 2 +- src/code_8023868.c | 2 +- src/code_809A560.c | 2 +- src/code_809C5C4.c | 2 +- src/ground_effect.c | 3 +++ src/ground_event.c | 3 +++ src/ground_lives.c | 4 ++++ src/ground_map.c | 4 ++-- src/ground_map_2.c | 4 ++-- src/ground_object.c | 3 +++ src/ground_sprite.c | 2 +- sym_iwram.txt | 38 -------------------------------------- sym_iwram_2.txt | 14 ++++++++++++++ sym_iwram_init.txt | 16 ++++++++++++++++ 20 files changed, 83 insertions(+), 55 deletions(-) create mode 100644 src/code_80035F0.c create mode 100644 src/ground_effect.c create mode 100644 src/ground_event.c create mode 100644 src/ground_lives.c create mode 100644 src/ground_object.c create mode 100644 sym_iwram_2.txt create mode 100644 sym_iwram_init.txt diff --git a/Makefile b/Makefile index 96ed5a0f1..aed3690d2 100755 --- a/Makefile +++ b/Makefile @@ -261,11 +261,17 @@ $(BUILD_DIR)/sym_ewram.ld: sym_ewram.txt $(BUILD_DIR)/sym_iwram.ld: sym_iwram.txt $(RAMSCRGEN) iwram_data $< ENGLISH > $@ + +$(BUILD_DIR)/sym_iwram_2.ld: sym_iwram_2.txt + $(RAMSCRGEN) iwram_data_2 $< ENGLISH > $@ $(BUILD_DIR)/sym_ewram_init.ld: sym_ewram_init.txt $(RAMSCRGEN) ewram_init $< ENGLISH > $@ + +$(BUILD_DIR)/sym_iwram_init.ld: sym_iwram_init.txt + $(RAMSCRGEN) iwram_init $< ENGLISH > $@ -$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_ewram_init.ld $(BUILD_DIR)/sym_iwram.ld +$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_ewram_init.ld $(BUILD_DIR)/sym_iwram.ld $(BUILD_DIR)/sym_iwram_2.ld $(BUILD_DIR)/sym_iwram_init.ld cd $(BUILD_DIR) && sed -e "s#tools/#../../tools/#g" ../../ld_script.txt >ld_script.ld $(ELF): $(LD_SCRIPT) $(ALL_OBJECTS) $(LIBC) libagbsyscall tools diff --git a/asm/code_8272724.s b/asm/code_8272724.s index b1dd9d491..9df41ac75 100644 --- a/asm/code_8272724.s +++ b/asm/code_8272724.s @@ -3,9 +3,6 @@ .syntax unified - .section .rodata - - .space 0x3C .text diff --git a/include/gba/defines.h b/include/gba/defines.h index 557c4ed00..63eedb947 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -7,9 +7,11 @@ #define FALSE 0 #define IWRAM_DATA __attribute__((section("iwram_data"))) +#define IWRAM_DATA_2 __attribute__((section("iwram_data_2"))) #define EWRAM_DATA __attribute__((section("ewram_data"))) #define EWRAM_LIB __attribute__((section("ewram_lib"))) // Used only for agb flash and m4a #define EWRAM_INIT __attribute__((section("ewram_init"))) +#define IWRAM_INIT __attribute__((section("iwram_init"))) #define UNUSED __attribute__((unused)) #define NAKED __attribute__((naked)) diff --git a/ld_script.txt b/ld_script.txt index c1b64ce3d..9332833b2 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -37,7 +37,6 @@ SECTIONS { { iwram_start = .; INCLUDE "sym_iwram.ld" - . = 0x8000; } > IWRAM /* BEGIN ROM DATA */ @@ -342,10 +341,14 @@ SECTIONS { src/ground_sprite.o(.text); asm/ground_sprite.o(.text); src/code_80A7714.o(.text); + src/ground_lives.o(.text); asm/ground_lives.o(.text); + src/ground_object.o(.text); asm/ground_object.o(.text); + src/ground_effect.o(.text); asm/ground_effect.o(.text); src/ground_link.o(.text); + src/ground_event.o(.text); asm/ground_event.o(.text); src/m4a_1.o(.text); src/m4a.o(.text); @@ -741,15 +744,26 @@ SECTIONS { EWRAM_INIT_ROM_START = LOADADDR(ewram_init); + iwram_init : + ALIGN(4) + { + INCLUDE "sym_iwram_init.ld" + } > IWRAM AT>ROM + + unk_code = LOADADDR(iwram_init); unk_code_section : ALIGN(4) { - unk_code = .; - asm/code_8272724.o(.rodata); src/code_8272724.o(.text); asm/code_8272724.o(.text); unk_code_end = .; } > ROM =0 + + iwram_data_2 (NOLOAD) : + ALIGN(4) + { + INCLUDE "sym_iwram_2.ld" + } > IWRAM unk_code_section_size = (unk_code_end - unk_code); unk_code_ram_end = unk_code_ram + unk_code_section_size; diff --git a/src/code_80001DC.c b/src/code_80001DC.c index 5b4068230..3e89e6888 100644 --- a/src/code_80001DC.c +++ b/src/code_80001DC.c @@ -1,6 +1,6 @@ #include "global.h" -IWRAM_DATA u32 gUnknown_3004000 = {0}; +IWRAM_DATA_2 u32 gUnknown_3004000 = {0}; // unused, returns stack pointer u32 sub_80001DC() { diff --git a/src/code_80035F0.c b/src/code_80035F0.c new file mode 100644 index 000000000..d521f7d86 --- /dev/null +++ b/src/code_80035F0.c @@ -0,0 +1,4 @@ +#include "global.h" + +IWRAM_INIT u16 gUnknown_3001B58 = 0; +IWRAM_INIT u16 gUnknown_3001B5A = 0; diff --git a/src/code_8023144.c b/src/code_8023144.c index 3ffd6fdff..81dfb5e1c 100644 --- a/src/code_8023144.c +++ b/src/code_8023144.c @@ -21,7 +21,7 @@ EWRAM_INIT s32 gUnknown_203B2A4 = 1; EWRAM_INIT u16 gUnknown_203B2A8 = 0; EWRAM_INIT u16 gUnknown_203B2AA = 0; -static IWRAM_DATA unkStruct_3001B5C *gUnknown_3001B5C = {NULL}; +static IWRAM_INIT unkStruct_3001B5C *gUnknown_3001B5C = {NULL}; #include "data/code_8023144.h" diff --git a/src/code_8023868.c b/src/code_8023868.c index fa10220d9..154e1821a 100644 --- a/src/code_8023868.c +++ b/src/code_8023868.c @@ -7,7 +7,7 @@ #include "text_util.h" //static // MAKE STATIC WHEN code_8023868.s IS DONE -IWRAM_DATA struct unkStruct_3001B60 *gUnknown_3001B60 = {0}; +IWRAM_INIT struct unkStruct_3001B60 *gUnknown_3001B60 = {NULL}; #include "data/code_8023868.h" diff --git a/src/code_809A560.c b/src/code_809A560.c index b365cb808..14c17dbe8 100644 --- a/src/code_809A560.c +++ b/src/code_809A560.c @@ -4,7 +4,7 @@ #include "string_format.h" #include "structs/str_3001B64.h" -IWRAM_DATA struct unkStruct_3001B64 *gUnknown_3001B64 = {0}; +IWRAM_INIT struct unkStruct_3001B64 *gUnknown_3001B64 = {NULL}; extern u16 gUnknown_20399DC; extern u16 gUnknown_20399DE; diff --git a/src/code_809C5C4.c b/src/code_809C5C4.c index cf3f9e4ab..f59351647 100644 --- a/src/code_809C5C4.c +++ b/src/code_809C5C4.c @@ -24,7 +24,7 @@ struct unkStruct_3001B68 u8 unk20; }; -IWRAM_DATA struct unkStruct_3001B68 *gUnknown_3001B68 = {0}; +IWRAM_INIT struct unkStruct_3001B68 *gUnknown_3001B68 = {NULL}; struct unkStruct_20399E0 diff --git a/src/ground_effect.c b/src/ground_effect.c new file mode 100644 index 000000000..71b0f71d1 --- /dev/null +++ b/src/ground_effect.c @@ -0,0 +1,3 @@ +#include "global.h" + +IWRAM_INIT void *gGroundEffects = NULL; diff --git a/src/ground_event.c b/src/ground_event.c new file mode 100644 index 000000000..88e328de0 --- /dev/null +++ b/src/ground_event.c @@ -0,0 +1,3 @@ +#include "global.h" + +IWRAM_INIT void *gGroundEvents = NULL; diff --git a/src/ground_lives.c b/src/ground_lives.c new file mode 100644 index 000000000..6f03b8fe7 --- /dev/null +++ b/src/ground_lives.c @@ -0,0 +1,4 @@ +#include "global.h" + +IWRAM_INIT void *gGroundLivesMeta = NULL; +IWRAM_INIT void *gGroundLives = NULL; diff --git a/src/ground_map.c b/src/ground_map.c index 7fe89d226..d12193986 100644 --- a/src/ground_map.c +++ b/src/ground_map.c @@ -7,8 +7,8 @@ #include "ground_script.h" #include "memory.h" -IWRAM_DATA GroundMapAction *gGroundMapAction = {0}; -IWRAM_DATA unkStruct_3001B70 *gGroundMapDungeon_3001B70 = {0}; +IWRAM_INIT GroundMapAction *gGroundMapAction = {NULL}; +IWRAM_INIT unkStruct_3001B70 *gGroundMapDungeon_3001B70 = {NULL}; extern GroundMapAction *gGroundMapAction; diff --git a/src/ground_map_2.c b/src/ground_map_2.c index b528a9328..4e3732615 100644 --- a/src/ground_map_2.c +++ b/src/ground_map_2.c @@ -7,8 +7,8 @@ extern u16 gUnknown_2026E4E; -IWRAM_DATA unkStruct_3001B74 *gUnknown_3001B74 = {0}; -IWRAM_DATA unkStruct_3001B70 *gUnknown_3001B78 = {0}; +IWRAM_INIT unkStruct_3001B74 *gUnknown_3001B74 = {NULL}; +IWRAM_INIT unkStruct_3001B70 *gUnknown_3001B78 = {NULL}; extern const u8 gUnknown_8117784[]; extern const s16 gUnknown_811E5F4[][2]; diff --git a/src/ground_object.c b/src/ground_object.c new file mode 100644 index 000000000..d52fae479 --- /dev/null +++ b/src/ground_object.c @@ -0,0 +1,3 @@ +#include "global.h" + +IWRAM_INIT void *gGroundObjects = NULL; diff --git a/src/ground_sprite.c b/src/ground_sprite.c index 7fe9f301a..0a6eabb6e 100644 --- a/src/ground_sprite.c +++ b/src/ground_sprite.c @@ -9,7 +9,7 @@ #include "memory.h" #include "sprite.h" -IWRAM_DATA unkStruct_3001B7C *gUnknown_3001B7C = {0}; +IWRAM_INIT unkStruct_3001B7C *gUnknown_3001B7C = {NULL}; EWRAM_DATA unkStruct_2039DB0 gUnknown_2039DB0 = {0}; EWRAM_DATA u32 sUnknown_2039DBC = {0}; // Unused, for alignment diff --git a/sym_iwram.txt b/sym_iwram.txt index b07326724..e7d6e10a2 100644 --- a/sym_iwram.txt +++ b/sym_iwram.txt @@ -17,44 +17,6 @@ gUnknown_3001018: /* 3001018 */ .include "src/code_8094D28.o" iwramClearEnd: -unk_code_ram: /* 3001B58 */ -gUnknown_3001B58: /* 3001B58 */ - .space 0x2 -gUnknown_3001B5A: /* 3001B5A */ - .space 0x2 -.include "src/code_8023144.o" -.include "src/code_8023868.o" -.include "src/code_809A560.o" -.include "src/code_809C5C4.o" -.include "src/ground_map.o" -.include "src/ground_map_2.o" -.include "src/ground_sprite.o" - -gGroundLivesMeta: /* 3001B80 */ - .space 0x4 - -gGroundLives: /* 3001B84 */ - .space 0x4 - -gGroundObjects: /* 3001B88 */ - .space 0x4 - -gGroundEffects: /* 3001B8C */ - .space 0x4 - -gGroundEvents: /* 3001B90 */ - .space 0x4 - -gUnkIwramFunc1Buffer: /* 3001B94 */ - .space 0x110 -gUnkIwramFunc2Buffer: /* 3001CA4 */ - .space 0x134 -gUnkIwramFunc3Buffer: /* 3001DD8 */ - .space 0xD4 -gUnkIwramFunc4Buffer: /* 3001EAC */ - .space 0x2154 - -.include "src/code_80001DC.o" diff --git a/sym_iwram_2.txt b/sym_iwram_2.txt new file mode 100644 index 000000000..9fad78cbc --- /dev/null +++ b/sym_iwram_2.txt @@ -0,0 +1,14 @@ + .align 2 + + + +gUnkIwramFunc1Buffer: /* 3001B94 */ + .space 0x110 +gUnkIwramFunc2Buffer: /* 3001CA4 */ + .space 0x134 +gUnkIwramFunc3Buffer: /* 3001DD8 */ + .space 0xD4 +gUnkIwramFunc4Buffer: /* 3001EAC */ + .space 0x2154 + +.include "src/code_80001DC.o" diff --git a/sym_iwram_init.txt b/sym_iwram_init.txt new file mode 100644 index 000000000..51831f76f --- /dev/null +++ b/sym_iwram_init.txt @@ -0,0 +1,16 @@ + .align 2 + +unk_code_ram: /* 3001B58 */ + +.include "src/code_80035F0.o" +.include "src/code_8023144.o" +.include "src/code_8023868.o" +.include "src/code_809A560.o" +.include "src/code_809C5C4.o" +.include "src/ground_map.o" +.include "src/ground_map_2.o" +.include "src/ground_sprite.o" +.include "src/ground_lives.o" +.include "src/ground_object.o" +.include "src/ground_effect.o" +.include "src/ground_event.o"