From 385200e1d69571aa3aadde858af77c526394f2b9 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 15 Dec 2024 14:06:35 +0100 Subject: [PATCH] cpu --- data/data_8270000.s | 21 --------------------- src/code_800C9CC.c | 5 +++-- src/cpu.c | 16 ++++++++++++++-- src/file_system.c | 4 ++-- src/flash.c | 2 +- src/random.c | 2 +- src/reg_control.c | 26 +++++++++++++------------- src/text.c | 13 +++++++++++++ sym_ewram2.txt | 22 ---------------------- sym_ewram_init.txt | 9 ++++++++- sym_iwram.txt | 11 ++++++++++- 11 files changed, 65 insertions(+), 66 deletions(-) diff --git a/data/data_8270000.s b/data/data_8270000.s index a284d861b..a3c2946d3 100644 --- a/data/data_8270000.s +++ b/data/data_8270000.s @@ -3,27 +3,6 @@ .global gUnknown_8270000 gUnknown_8270000: @ 8270000 @ replacing .incbin "baserom.gba", 0x00270000, 0x2724 -.byte 0x01, 0x00, 0x00, 0x00 -.byte 0x95, 0x1b, 0x00, 0x03 -.byte 0xa5, 0x1c, 0x00, 0x03 -.byte 0xd9, 0x1d, 0x00, 0x03 -.byte 0xad, 0x1e, 0x00, 0x03 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0xff, 0xff -.byte 0xff, 0xff, 0xff, 0xff - -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x41, 0x3e -.byte 0x42, 0x3c, 0x44, 0x3b -.byte 0x48, 0x37, 0x40, 0x30 -.byte 0x46, 0x38, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00 diff --git a/src/code_800C9CC.c b/src/code_800C9CC.c index 115b2e7c1..2287df3b2 100644 --- a/src/code_800C9CC.c +++ b/src/code_800C9CC.c @@ -3,8 +3,9 @@ #include "random.h" #include "reg_control.h" -EWRAM_DATA_2 u32 gUnknown_203B0B8 = {0}; -EWRAM_DATA_2 u16 gRawKeyInput = {0}; +// Todo: Figure out if this file could be merged with bg_control and cpu? +EWRAM_INIT u32 gUnknown_203B0B8 = {0}; +extern u16 gRawKeyInput; void sub_800CB20(void) { diff --git a/src/cpu.c b/src/cpu.c index d0c6a2338..6610c04a2 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -3,14 +3,26 @@ #include "cpu.h" EWRAM_DATA u32 gUnknown_202D800 = {0}; -extern u16 gUnknown_203B0BE[]; + +EWRAM_INIT u16 gRawKeyInput = {0}; // Not used here, but has to be declare along with sBldCntTable for alignment. Perhaps this file should be merged with bg_control and code_800C9CC. +// Despite being in EWRAM, these never change. +static EWRAM_INIT u16 sBldCntTable[] = { + (BLDCNT_TGT1_BG0 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD), + (BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD), + (BLDCNT_TGT1_BG2 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD), + (BLDCNT_TGT1_BG3 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG0 | BLDCNT_TGT2_BG1 | BLDCNT_TGT2_BG2 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD), + (BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD), + (BLDCNT_TGT1_BG1 | BLDCNT_TGT1_BG2 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG3 | BLDCNT_TGT2_OBJ | BLDCNT_TGT2_BD), + (0), +}; + extern u16 *gUnknown_2026E3C; extern u8 gUnknown_2026E38; void sub_800CDA8(u32 r0) { gUnknown_202D800 = r0; - gBldCnt = gUnknown_203B0BE[r0]; + gBldCnt = sBldCntTable[r0]; } u32 sub_800CDC8(void) diff --git a/src/file_system.c b/src/file_system.c index 396265b9b..5f2be8f5a 100644 --- a/src/file_system.c +++ b/src/file_system.c @@ -5,7 +5,7 @@ EWRAM_DATA u32 gUnknown_202D2A4 = {0}; EWRAM_DATA OpenedFile gFileCache[64] = {0}; -static EWRAM_DATA_2 u32 sFileCacheCursorPosition = {0}; +static EWRAM_INIT u32 sFileCacheCursorPosition = {0}; #include "data/file_system.h" @@ -146,4 +146,4 @@ void CloseFile(OpenedFile *openedFile) return; } } -} \ No newline at end of file +} diff --git a/src/flash.c b/src/flash.c index fcb08e555..172f2be94 100644 --- a/src/flash.c +++ b/src/flash.c @@ -3,7 +3,7 @@ #include "flash.h" #include "memory.h" -EWRAM_DATA_2 bool8 gFlashEnabled = {0}; +EWRAM_INIT bool8 gFlashEnabled = {0}; extern FlashIntrFunc *GetInterruptHandler(s32); diff --git a/src/random.c b/src/random.c index d57aa516a..25768d74b 100644 --- a/src/random.c +++ b/src/random.c @@ -2,7 +2,7 @@ #include "globaldata.h" #include "random.h" -EWRAM_DATA_2 s32 gPRNGSequenceNum = {0}; +EWRAM_INIT s32 gPRNGSequenceNum = {1}; void SeedRng(u8 *seed) { diff --git a/src/reg_control.c b/src/reg_control.c index 6384be504..ad0d9d5f5 100644 --- a/src/reg_control.c +++ b/src/reg_control.c @@ -16,19 +16,19 @@ EWRAM_DATA IntrCallback gIntrCallbacks[6] = {0}; EWRAM_DATA unkStruct_202D648 gUnknown_202D608[8] = {0}; EWRAM_DATA unkStruct_202D648 gUnknown_202D648[8] = {0}; -EWRAM_DATA_2 u8 gInterruptsEnabled = {0}; -EWRAM_DATA_2 bool8 gUnknown_203B099 = {0}; -EWRAM_DATA_2 bool8 gUnknown_203B09A = {0}; -EWRAM_DATA_2 bool8 gUnknown_203B09B = {0}; -EWRAM_DATA_2 u32 gUnknown_203B09C = {0}; -EWRAM_DATA_2 u32 gUnknown_203B0A0 = {0}; -EWRAM_DATA_2 u32 gUnknown_203B0A4 = {0}; // Written to but never read -EWRAM_DATA_2 s16 gUnknown_203B0A8 = {0}; -EWRAM_DATA_2 s16 gUnknown_203B0AA = {0}; -EWRAM_DATA_2 s16 gUnknown_203B0AC = {0}; -EWRAM_DATA_2 s16 gUnknown_203B0AE = {0}; -EWRAM_DATA_2 s16 gUnknown_203B0B0 = {0}; // Written to but never read -EWRAM_DATA_2 s16 gUnknown_203B0B2 = {0}; // Written to but never read +EWRAM_INIT u8 gInterruptsEnabled = {0}; +EWRAM_INIT bool8 gUnknown_203B099 = {0}; +EWRAM_INIT bool8 gUnknown_203B09A = {0}; +EWRAM_INIT bool8 gUnknown_203B09B = {0}; +EWRAM_INIT u32 gUnknown_203B09C = {0}; +EWRAM_INIT u32 gUnknown_203B0A0 = {0}; +EWRAM_INIT u32 gUnknown_203B0A4 = {0}; // Written to but never read +EWRAM_INIT s16 gUnknown_203B0A8 = {0}; +EWRAM_INIT s16 gUnknown_203B0AA = {0}; +EWRAM_INIT s16 gUnknown_203B0AC = {0}; +EWRAM_INIT s16 gUnknown_203B0AE = {-1}; +EWRAM_INIT s16 gUnknown_203B0B0 = {-1}; // Written to but never read +EWRAM_INIT s16 gUnknown_203B0B2 = {-1}; // Written to but never read // code_800D090.c extern void sub_800D6AC(void); diff --git a/src/text.c b/src/text.c index 185598174..31e40a212 100644 --- a/src/text.c +++ b/src/text.c @@ -41,6 +41,19 @@ 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[]; +// 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! + +// This variable is only used in InitGraphics function, which could or could not belong to text.c +EWRAM_INIT u8 gUnknown_203B090 = 0; + static void SaveUnkTextStructAndXXX_8006438(const UnkTextStruct2 *a0, bool8 a1, bool8 a2, UnkTextStruct2_sub *a3); static void sub_8006554(UnkTextStruct1 *a0, u32 *a1, u32 *a2, u16 *a3, u32 a4, const UnkTextStruct2 *a5, bool8 a6, u32 a7, UnkTextStruct2_sub *a8, u8 a9); static void sub_800677C(UnkTextStruct1 *a0, s32 a1, u16 *a2, u8 a3); diff --git a/sym_ewram2.txt b/sym_ewram2.txt index b5ed0c6a7..92de4d813 100644 --- a/sym_ewram2.txt +++ b/sym_ewram2.txt @@ -1,30 +1,8 @@ .align 2 -.include "src/random.o" -gUnknown_203B080: /* 203B080 (sub_8053540 - sub_806806C) */ - .space 0x4 -gUnknown_203B084: /* 203B084 (sub_8053430 - sub_806806C) */ - .space 0x4 -gUnknown_203B088: /* 203B088 (xxx_draw_string_80144C4) */ - .space 0x4 - -gUnknown_203B08C: /* 203B08C (xxx_draw_string_80524F0) */ - .space 0x4 - -gUnknown_203B090: /* 203B090 (InitGraphics) */ - .space 0x4 - -.include "src/file_system.o" -.include "src/main.o" -.include "src/reg_control.o" -.include "src/flash.o" -.include "src/code_800C9CC.o" - -gUnknown_203B0BE: /* 203B0BE (sub_800CDA8) */ - .space 0xE gUnknown_203B0CC: /* 203B0CC (sub_800DE8C - sub_800DC14) */ .space 0x4 diff --git a/sym_ewram_init.txt b/sym_ewram_init.txt index 3fc574f77..52fc1154d 100644 --- a/sym_ewram_init.txt +++ b/sym_ewram_init.txt @@ -4,4 +4,11 @@ .include "src/other_random.o" .include "src/sprite.o" .include "src/code_800558C.o" - \ No newline at end of file +.include "src/random.o" +.include "src/text.o" +.include "src/file_system.o" +.include "src/main.o" +.include "src/reg_control.o" +.include "src/flash.o" +.include "src/code_800C9CC.o" +.include "src/cpu.o" diff --git a/sym_iwram.txt b/sym_iwram.txt index e0b7064f9..b07326724 100644 --- a/sym_iwram.txt +++ b/sym_iwram.txt @@ -46,6 +46,15 @@ gGroundEffects: /* 3001B8C */ .space 0x4 gGroundEvents: /* 3001B90 */ - .space 0x2470 + .space 0x4 + +gUnkIwramFunc1Buffer: /* 3001B94 */ + .space 0x110 +gUnkIwramFunc2Buffer: /* 3001CA4 */ + .space 0x134 +gUnkIwramFunc3Buffer: /* 3001DD8 */ + .space 0xD4 +gUnkIwramFunc4Buffer: /* 3001EAC */ + .space 0x2154 .include "src/code_80001DC.o"