Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iwram init #300

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions asm/code_8272724.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

.syntax unified

.section .rodata

.space 0x3C

.text

Expand Down Expand Up @@ -145,6 +142,7 @@ _08272860:
pop {r0}
bx r0
thumb_func_end sub_8272774


thumb_func_start sub_8272870
sub_8272870:
Expand Down Expand Up @@ -314,6 +312,7 @@ _08272994:
pop {r0}
bx r0
thumb_func_end sub_8272884


thumb_func_start sub_82729A4
sub_82729A4:
Expand Down Expand Up @@ -429,7 +428,7 @@ _08272A5A:
pop {r0}
bx r0
thumb_func_end sub_82729B8

thumb_func_start sub_8272A78
sub_8272A78:
push {lr}
Expand Down
1 change: 1 addition & 0 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
36 changes: 24 additions & 12 deletions ld_script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SECTIONS {
{
iwram_start = .;
INCLUDE "sym_iwram.ld"
. = 0x8000;
iwram_end = .;
} > IWRAM

/* BEGIN ROM DATA */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/code_80001DC.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "global.h"

IWRAM_DATA u32 gUnknown_3004000 = {0};
extern u32 gUnknown_3004000;

// unused, returns stack pointer
u32 sub_80001DC() {
Expand Down
4 changes: 4 additions & 0 deletions src/code_80035F0.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "global.h"

IWRAM_INIT u16 gUnknown_3001B58 = 0;
IWRAM_INIT u16 gUnknown_3001B5A = 0;
2 changes: 1 addition & 1 deletion src/code_8023144.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/code_8023868.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/code_809A560.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/code_809C5C4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/code_8272724.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
//}
3 changes: 3 additions & 0 deletions src/ground_effect.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "global.h"

IWRAM_INIT void *gGroundEffects = NULL;
3 changes: 3 additions & 0 deletions src/ground_event.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "global.h"

IWRAM_INIT void *gGroundEvents = NULL;
4 changes: 4 additions & 0 deletions src/ground_lives.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "global.h"

IWRAM_INIT void *gGroundLivesMeta = NULL;
IWRAM_INIT void *gGroundLives = NULL;
4 changes: 2 additions & 2 deletions src/ground_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/ground_map_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 3 additions & 0 deletions src/ground_object.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "global.h"

IWRAM_INIT void *gGroundObjects = NULL;
2 changes: 1 addition & 1 deletion src/ground_sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 0 additions & 42 deletions sym_iwram.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 14 additions & 0 deletions sym_iwram_init.txt
Original file line number Diff line number Diff line change
@@ -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"
Loading