From bdae8567693ca37d72bde22bd47b9ff6bdf4bf43 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 18 Dec 2024 12:09:22 +0100 Subject: [PATCH] iwram init done --- Makefile | 7 ++----- asm/code_8272724.s | 4 +++- include/gba/defines.h | 1 - ld_script.txt | 26 ++++++++++++-------------- src/code_80001DC.c | 2 +- src/main.c | 16 ++++++++-------- src/text.c | 17 +++++++++-------- sym_iwram.txt | 4 ---- sym_iwram_2.txt | 14 -------------- sym_iwram_init.txt | 2 -- 10 files changed, 35 insertions(+), 58 deletions(-) delete mode 100644 sym_iwram_2.txt diff --git a/Makefile b/Makefile index aed3690d2..cb9e085c3 100755 --- a/Makefile +++ b/Makefile @@ -261,17 +261,14 @@ $(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 $(BUILD_DIR)/sym_iwram_2.ld $(BUILD_DIR)/sym_iwram_init.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_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 9df41ac75..bd4cc80e1 100644 --- a/asm/code_8272724.s +++ b/asm/code_8272724.s @@ -142,6 +142,7 @@ _08272860: pop {r0} bx r0 thumb_func_end sub_8272774 + thumb_func_start sub_8272870 sub_8272870: @@ -311,6 +312,7 @@ _08272994: pop {r0} bx r0 thumb_func_end sub_8272884 + thumb_func_start sub_82729A4 sub_82729A4: @@ -426,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 63eedb947..e00d5c0ee 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -7,7 +7,6 @@ #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"))) diff --git a/ld_script.txt b/ld_script.txt index 9332833b2..78903bc2a 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -37,6 +37,7 @@ SECTIONS { { iwram_start = .; INCLUDE "sym_iwram.ld" + iwram_end = .; } > IWRAM /* BEGIN ROM DATA */ @@ -747,28 +748,25 @@ SECTIONS { iwram_init : ALIGN(4) { + iwram_init_start = .; + INCLUDE "sym_iwram_init.ld" + src/code_8272724.o(.text); + asm/code_8272724.o(.text); + + iwram_init_end = .; } > IWRAM AT>ROM - unk_code = LOADADDR(iwram_init); - unk_code_section : - ALIGN(4) - { - src/code_8272724.o(.text); - asm/code_8272724.o(.text); - unk_code_end = .; - } > ROM =0 + IWRAM_INIT_ROM_START = LOADADDR(iwram_init); - iwram_data_2 (NOLOAD) : + iwram_lib (NOLOAD) : ALIGN(4) { - INCLUDE "sym_iwram_2.ld" + end = .; /* This is needed for the libc.a function _sbrk */ + . = 0x2090; + gUnknown_3004000 = .; /* Used by sub_80001E0 */ } > IWRAM - 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; - unk_data 0x8300000 : ALIGN(4) { diff --git a/src/code_80001DC.c b/src/code_80001DC.c index 3e89e6888..6bcdcc9bc 100644 --- a/src/code_80001DC.c +++ b/src/code_80001DC.c @@ -1,6 +1,6 @@ #include "global.h" -IWRAM_DATA_2 u32 gUnknown_3004000 = {0}; +extern u32 gUnknown_3004000; // unused, returns stack pointer u32 sub_80001DC() { 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 e7d6e10a2..5c61b39d2 100644 --- a/sym_iwram.txt +++ b/sym_iwram.txt @@ -16,7 +16,3 @@ gUnknown_3001018: /* 3001018 */ .include "src/code_8094D28.o" -iwramClearEnd: - - - diff --git a/sym_iwram_2.txt b/sym_iwram_2.txt deleted file mode 100644 index 9fad78cbc..000000000 --- a/sym_iwram_2.txt +++ /dev/null @@ -1,14 +0,0 @@ - .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 index 51831f76f..e6acf0ab6 100644 --- a/sym_iwram_init.txt +++ b/sym_iwram_init.txt @@ -1,7 +1,5 @@ .align 2 -unk_code_ram: /* 3001B58 */ - .include "src/code_80035F0.o" .include "src/code_8023144.o" .include "src/code_8023868.o"