diff --git a/Makefile b/Makefile index 96ed5a0f1..cb9e085c3 100755 --- a/Makefile +++ b/Makefile @@ -265,7 +265,10 @@ $(BUILD_DIR)/sym_iwram.ld: sym_iwram.txt $(BUILD_DIR)/sym_ewram_init.ld: sym_ewram_init.txt $(RAMSCRGEN) ewram_init $< ENGLISH > $@ -$(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_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 $(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..bd4cc80e1 100644 --- a/asm/code_8272724.s +++ b/asm/code_8272724.s @@ -3,9 +3,6 @@ .syntax unified - .section .rodata - - .space 0x3C .text @@ -145,6 +142,7 @@ _08272860: pop {r0} bx r0 thumb_func_end sub_8272774 + thumb_func_start sub_8272870 sub_8272870: @@ -314,6 +312,7 @@ _08272994: pop {r0} bx r0 thumb_func_end sub_8272884 + thumb_func_start sub_82729A4 sub_82729A4: @@ -429,7 +428,7 @@ _08272A5A: pop {r0} bx r0 thumb_func_end sub_82729B8 - + thumb_func_start sub_8272A78 sub_8272A78: push {lr} diff --git a/include/gba/defines.h b/include/gba/defines.h index 557c4ed00..e00d5c0ee 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -10,6 +10,7 @@ #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..d7a5f4d8b 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -37,7 +37,7 @@ SECTIONS { { iwram_start = .; INCLUDE "sym_iwram.ld" - . = 0x8000; + iwram_end = .; } > IWRAM /* BEGIN ROM DATA */ @@ -342,10 +342,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,19 +745,27 @@ SECTIONS { EWRAM_INIT_ROM_START = LOADADDR(ewram_init); - unk_code_section : + iwram_init : + ALIGN(4) + { + iwram_init_start = .; + + INCLUDE "sym_iwram_init.ld" + src/code_8272724.o(iwram_init); + asm/code_8272724.o(.text); + + iwram_init_end = .; + } > IWRAM AT>ROM + + IWRAM_INIT_ROM_START = LOADADDR(iwram_init); + + iwram_lib (NOLOAD) : ALIGN(4) { - unk_code = .; - asm/code_8272724.o(.rodata); - src/code_8272724.o(.text); - asm/code_8272724.o(.text); - unk_code_end = .; - } > ROM =0 - - unk_code_section_size = (unk_code_end - unk_code); - unk_code_ram_end = unk_code_ram + unk_code_section_size; - end = unk_code_ram_end; + end = .; /* This is needed for the libc.a function _sbrk */ + . = 0x2090; + gUnknown_3004000 = .; /* Used by sub_80001E0 */ + } > IWRAM unk_data 0x8300000 : ALIGN(4) diff --git a/src/code_80001DC.c b/src/code_80001DC.c index 5b4068230..6bcdcc9bc 100644 --- a/src/code_80001DC.c +++ b/src/code_80001DC.c @@ -1,6 +1,6 @@ #include "global.h" -IWRAM_DATA u32 gUnknown_3004000 = {0}; +extern u32 gUnknown_3004000; // 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/code_8272724.c b/src/code_8272724.c index 6487650eb..895eb4bcd 100644 --- a/src/code_8272724.c +++ b/src/code_8272724.c @@ -4,13 +4,15 @@ extern void sub_8272774(UnkTextStruct1 *r0, u32 r1); extern void sub_8272884(UnkTextStruct1 *r0, u32 r1); -void sub_8272760(u32 r0) +IWRAM_INIT void sub_8272760(u32 r0) { sub_8272774(gUnknown_2027370, r0); } +// Note: when decompiling make sure to add IWRAM_INIT before the function declaration just like in sub_8272760's case, so the compiler knows there to put the functions. + // TODO once sub_8272774 is decomped -//void sub_8272870(u32 r0) +//IWRAM_INIT void sub_8272870(u32 r0) //{ // sub_8272884(gUnknown_2027370, r0); //} 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/src/main.c b/src/main.c index 09f5fe5ed..f4a0e812f 100644 --- a/src/main.c +++ b/src/main.c @@ -22,12 +22,12 @@ extern u8 ewram_end[]; // Force a second storage in the asm extern u8 ewram_init_start[]; extern u8 ewram_init_end[]; extern u8 iwram_start[]; -extern u8 iwramClearEnd[]; -extern u8 unk_code[]; -extern u8 unk_code_ram[]; -extern u8 unk_code_ram_end[]; +extern u8 iwram_end[]; +extern u8 iwram_init_start[]; +extern u8 iwram_init_end[]; extern const u8 EWRAM_INIT_ROM_START[]; +extern const u8 IWRAM_INIT_ROM_START[]; UNUSED static const char sStringRomUserData[] = "PKD ROM USER DATA 000000"; @@ -56,12 +56,12 @@ void AgbMain(void) CpuSet(&value, ewram_start, CPU_SET_SRC_FIXED | CPU_SET_32BIT | (((ewram_end - ewram_start) / 4) & 0x1FFFFF)); } - if (unk_code_ram_end - unk_code_ram > 0) - CpuCopy32(unk_code, unk_code_ram, unk_code_ram_end - unk_code_ram); + if (iwram_init_end - iwram_init_start > 0) + CpuCopy32(IWRAM_INIT_ROM_START, iwram_init_start, iwram_init_end - iwram_init_start); - if (iwramClearEnd - iwram_start > 0) { + if (iwram_end - iwram_start > 0) { memset(value, 0, sizeof(value)); - CpuSet(&value, iwram_start, CPU_SET_SRC_FIXED | CPU_SET_32BIT | (((iwramClearEnd - iwram_start) / 4) & 0x1FFFFF)); + CpuSet(&value, iwram_start, CPU_SET_SRC_FIXED | CPU_SET_32BIT | (((iwram_end - iwram_start) / 4) & 0x1FFFFF)); } REG_WIN0H = 0; diff --git a/src/text.c b/src/text.c index 31e40a212..7506488a3 100644 --- a/src/text.c +++ b/src/text.c @@ -41,15 +41,16 @@ EWRAM_DATA static u32 sTextShadowMask = 0; // Some text color info is stored; re EWRAM_DATA static u8 sDrawTextShadow = 0; EWRAM_DATA ALIGNED(4) u16 gUnknown_202B038[4][32][32] = {0}; -extern ALIGNED(4) u8 gUnkIwramFunc1Buffer[]; -extern ALIGNED(4) u8 gUnkIwramFunc2Buffer[]; -extern ALIGNED(4) u8 gUnkIwramFunc3Buffer[]; -extern ALIGNED(4) u8 gUnkIwramFunc4Buffer[]; +extern void sub_8272760(s32 a0); +extern void sub_8272870(s32 a0); +extern void sub_82729A4(s32 a0); +extern void sub_8272A78(s32 a0); + // Despite these not being used anywhere in this file, file order and usage point to these variables being declared here -EWRAM_INIT void (*gUnknown_203B080)(s32 a0) = (void *) &gUnkIwramFunc1Buffer[1]; // + 1 because the function is in thumb! -EWRAM_INIT void (*gUnknown_203B084)(s32 a0) = (void *) &gUnkIwramFunc2Buffer[1]; // + 1 because the function is in thumb! -EWRAM_INIT void (*gUnknown_203B088)(s32 a0) = (void *) &gUnkIwramFunc3Buffer[1]; // + 1 because the function is in thumb! -EWRAM_INIT void (*gUnknown_203B08C)(s32 a0) = (void *) &gUnkIwramFunc4Buffer[1]; // + 1 because the function is in thumb! +EWRAM_INIT void (*gUnknown_203B080)(s32 a0) = sub_8272760; +EWRAM_INIT void (*gUnknown_203B084)(s32 a0) = sub_8272870; +EWRAM_INIT void (*gUnknown_203B088)(s32 a0) = sub_82729A4; +EWRAM_INIT void (*gUnknown_203B08C)(s32 a0) = sub_8272A78; // This variable is only used in InitGraphics function, which could or could not belong to text.c EWRAM_INIT u8 gUnknown_203B090 = 0; diff --git a/sym_iwram.txt b/sym_iwram.txt index b07326724..5c61b39d2 100644 --- a/sym_iwram.txt +++ b/sym_iwram.txt @@ -16,45 +16,3 @@ 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_init.txt b/sym_iwram_init.txt new file mode 100644 index 000000000..e6acf0ab6 --- /dev/null +++ b/sym_iwram_init.txt @@ -0,0 +1,14 @@ + .align 2 + +.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"