From 1251692827df9b66ebf434e985c04ee4f515076e Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Sun, 12 Sep 2021 11:37:05 -0400 Subject: [PATCH 1/6] Created a font.h --- src/font.c | 144 +++--------------------------------------- src/font.h | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/stacks.h | 2 +- 3 files changed, 180 insertions(+), 138 deletions(-) create mode 100644 src/font.h diff --git a/src/font.c b/src/font.c index b5d2fd84..98fac4c6 100644 --- a/src/font.c +++ b/src/font.c @@ -1,16 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C3C00 */ -#include "memory.h" -#include "video.h" -#include "stacks.h" - -#include "structs.h" -#include "types.h" -#include "macros.h" -#include "asset_sections.h" -#include "libultra_internal.h" -#include "f3ddkr.h" +#include "font.h" /************ .data ************/ @@ -40,7 +31,7 @@ s8 D_800E36E8 = 0; // Descending powers of 10 s32 gDescPowsOf10[9] = { - 1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10 + 1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, }; s8 D_800E3710[48] = { @@ -52,145 +43,35 @@ s8 D_800E3710[48] = { 2, TRUE, -2, TRUE, -1, 4, TRUE, -1, TRUE, 0, -1, 0, 0, 0, 0, // End of Data - 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, }; -OSDevMgr __osPiDevMgr = { 0, NULL, NULL, NULL, NULL, NULL, NULL }; +OSDevMgr __osPiDevMgr = { 0, NULL, NULL, NULL, NULL, NULL, NULL, }; /*******************************/ /************ .bss ************/ s32 gNumberOfFonts; - -/* Size: 8 bytes */ -typedef struct FontCharData { - u8 unk0; - u8 unk1; - u8 unk2; - u8 unk3; - u8 unk4; - u8 unk5; - u8 unk6; - u8 unk7; -} FontCharData; - -/* Size: 0x400 bytes */ -typedef struct FontData { -/* 0x000 */ s32 unk0; -/* 0x004 */ char name[0x1C]; -/* 0x020 */ u16 unk20; -/* 0x022 */ u16 unk22; -/* 0x024 */ u16 unk24; -/* 0x026 */ u16 unk26; -/* 0x028 */ u8 unk28[24]; -/* 0x040 */ s16 unk40[32]; -/* 0x080 */ TextureHeader *texturePointers[32]; -/* 0x100 */ FontCharData unk100[96]; -} FontData; - FontData *gFonts; - -typedef struct unk8012A7E8_24 { - u8 unk00; - u8 unk01; - char *unk4; - s16 unk8; - s16 unkA; - s16 unkC; - s16 unkE; - u8 unk10; - u8 unk11; - u8 unk12; - u8 unk13; - u8 unk14; - u8 unk15; - u8 unk16; - u8 unk17; - u8 unk18; - u8 unk19; - struct unk8012A7E8_24 *unk1C; -} unk8012A7E8_24; - -/* Size: 0x28 bytes */ -typedef struct unk8012A7E8 { - s16 xpos; - s16 ypos; - s16 unk4; - s16 unk6; - s16 unk8; - s16 unkA; - s16 unkC; - s16 unkE; - u8 unk10; - u8 unk11; - u8 unk12; - u8 unk13; - u8 colorRed; - u8 colorGreen; - u8 colorBlue; - u8 colorAlpha; - u8 bgRed; - u8 bgGreen; - u8 bgBlue; - u8 bgAlpha; - u8 opacity; - u8 font; - u16 unk1E; - s16 unk20; - s16 unk22; - unk8012A7E8_24 *unk24; -} unk8012A7E8; - unk8012A7E8 (*D_8012A7E8)[1]; - -/* Size: 0x20 bytes */ -typedef struct unk8012A7EC { - u8 unk0; - u8 unk1; - u8 unk2; - u8 unk3; - s32 unk4; - s32 unk8; - s32 unkC; - u8 unk10; - u8 unk11; - u8 unk12; - u8 unk13; - u8 unk14; - u8 unk15; - u8 unk16; - u8 unk17; - s32 unk18; - s32 unk1C; -} unk8012A7EC; unk8012A7EC (*D_8012A7EC)[1]; - s32 D_8012A7F0; s8 D_8012A7F4; s32 D_8012A7F8; s32 D_8012A7FC; /******************************/ - -void func_800C5B58(Gfx **dlist, s32 *arg1, s32 *arg2, s32 arg3); -void parse_string_with_number(unsigned char *input, char *output, s32 number); -void func_800C4170(s32 arg0); - -#define unk8012A7E8_COUNT 8 -#define unk8012A7EC_COUNT 64 -#define unk8012A7E8_TOTAL_SIZE (sizeof(unk8012A7E8) * unk8012A7E8_COUNT) -#define unk8012A7EC_TOTAL_SIZE (sizeof(unk8012A7EC) * unk8012A7EC_COUNT) void load_fonts(void) { - u8 *fontAssetData; + s32 *fontAssetData; s32 i; fontAssetData = load_asset_section_from_rom(ASSET_BINARY_44); gFonts = (FontData*)(fontAssetData); // ??? - gNumberOfFonts = *((s32*)fontAssetData); - gFonts = (FontData*)(fontAssetData + 4); + gNumberOfFonts = *(fontAssetData); + gFonts = (FontData*)(fontAssetData + 1); for (i = 0; i < gNumberOfFonts; i++) { gFonts[i].unk28[0] = 0; @@ -345,8 +226,6 @@ void set_text_background_color(s32 red, s32 green, s32 blue, s32 alpha) { (*D_8012A7E8)[0].bgAlpha = alpha; } -void func_800C45A4(Gfx **dlist, unk8012A7E8 *arg1, u8 *text, s32 alignmentFlags, f32 arg4); - // Unused? void func_800C4404(Gfx** displayList, char *text, s32 alignmentFlags) { func_800C45A4(displayList, &(*D_8012A7E8)[0], text, alignmentFlags, 1.0f); @@ -557,14 +436,6 @@ void func_800C5494(s32 arg0) { } } -typedef struct unk800C54E8 { - u8 pad0[0xC]; - s16 unkC; - s16 unkE; - u8 pad10[9]; - u8 unk19; -} unk800C54E8; - // Unused void func_800C54E8(s32 arg0, unk800C54E8 *arg1, s32 arg2, s32 arg3, s32 arg4) { FontData *fontData; @@ -679,7 +550,6 @@ void s32_to_string(char** outString, s32 number) { (*outString)++; } #else -void s32_to_string(char**, s32); GLOBAL_ASM("asm/non_matchings/font/s32_to_string.s") #endif diff --git a/src/font.h b/src/font.h new file mode 100644 index 00000000..2b4323ec --- /dev/null +++ b/src/font.h @@ -0,0 +1,172 @@ +#ifndef _FONT_H_ +#define _FONT_H_ + +#include "memory.h" +#include "video.h" +#include "stacks.h" + +#include "asset_loading.h" +#include "structs.h" +#include "types.h" +#include "macros.h" +#include "asset_sections.h" +#include "libultra_internal.h" +#include "f3ddkr.h" + +typedef struct unk8012A7E8_24 { + u8 unk00; + u8 unk01; + char *unk4; + s16 unk8; + s16 unkA; + s16 unkC; + s16 unkE; + u8 unk10; + u8 unk11; + u8 unk12; + u8 unk13; + u8 unk14; + u8 unk15; + u8 unk16; + u8 unk17; + u8 unk18; + u8 unk19; + struct unk8012A7E8_24 *unk1C; +} unk8012A7E8_24; + +/* Size: 0x28 bytes */ +typedef struct unk8012A7E8 { + s16 xpos; + s16 ypos; + s16 unk4; + s16 unk6; + s16 unk8; + s16 unkA; + s16 unkC; + s16 unkE; + u8 unk10; + u8 unk11; + u8 unk12; + u8 unk13; + u8 colorRed; + u8 colorGreen; + u8 colorBlue; + u8 colorAlpha; + u8 bgRed; + u8 bgGreen; + u8 bgBlue; + u8 bgAlpha; + u8 opacity; + u8 font; + u16 unk1E; + s16 unk20; + s16 unk22; + unk8012A7E8_24 *unk24; +} unk8012A7E8; + +/* Size: 0x20 bytes */ +typedef struct unk8012A7EC { + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + s32 unk4; + s32 unk8; + s32 unkC; + u8 unk10; + u8 unk11; + u8 unk12; + u8 unk13; + u8 unk14; + u8 unk15; + u8 unk16; + u8 unk17; + s32 unk18; + s32 unk1C; +} unk8012A7EC; + +typedef struct unk800C54E8 { + u8 pad0[0xC]; + s16 unkC; + s16 unkE; + u8 pad10[9]; + u8 unk19; +} unk800C54E8; + +/* Size: 8 bytes */ +typedef struct FontCharData { + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + u8 unk4; + u8 unk5; + u8 unk6; + u8 unk7; +} FontCharData; + +/* Size: 0x400 bytes */ +typedef struct FontData { +/* 0x000 */ s32 unk0; +/* 0x004 */ char name[0x1C]; +/* 0x020 */ u16 unk20; +/* 0x022 */ u16 unk22; +/* 0x024 */ u16 unk24; +/* 0x026 */ u16 unk26; +/* 0x028 */ u8 unk28[24]; +/* 0x040 */ s16 unk40[32]; +/* 0x080 */ TextureHeader *texturePointers[32]; +/* 0x100 */ FontCharData unk100[96]; +} FontData; + +#define unk8012A7E8_COUNT 8 +#define unk8012A7EC_COUNT 64 +#define unk8012A7E8_TOTAL_SIZE (sizeof(unk8012A7E8) * unk8012A7E8_COUNT) +#define unk8012A7EC_TOTAL_SIZE (sizeof(unk8012A7EC) * unk8012A7EC_COUNT) + +f32 func_8009E9B0(s32 arg0, Gfx **arg1, s32 *arg2, s32 *arg3); //menu.c +void func_8009E9A0(void); //menu.c +void func_8009E9A8(void); //menu.c +//TextureHeader *load_texture(s32 arg0); //texture_sprites.c NON_MATCHING + +void load_fonts(void); +void func_800C4164(s32 arg0); +void set_text_font(s32 arg0); +void func_800C5B58(Gfx **dlist, s32 *arg1, s32 *arg2, s32 arg3); +void set_text_color(s32 red, s32 green, s32 blue, s32 alpha, s32 opacity); +void set_text_background_color(s32 red, s32 green, s32 blue, s32 alpha); +void func_800C4404(Gfx** displayList, char *text, s32 alignmentFlags); +void draw_text(Gfx** displayList, s32 xpos, s32 ypos, char *text, s32 alignmentFlags); +void func_800C44C0(Gfx** displayList, s32 arg1, char *text, s32 alignmentFlags); +void func_800C4510(Gfx** displayList, s32 arg1, s32 xpos, s32 ypos, char *text, s32 alignmentFlags); +void func_800C4EDC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4); +void func_800C4F7C(s32 arg0, s32 font); +void func_800C4FBC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4); +void func_800C5000(s32 arg0, s32 red, s32 green, s32 blue, s32 alpha, s32 opacity); +void func_800C5050(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4); +void func_800C5094(s32 arg0, s32 arg1, s32 arg2); +void func_800C50D8(s32 arg0); +void func_800C510C(s32 arg0, s32 arg1, s32 arg2, s32 arg3); +void func_800C5428(s32 arg0, unk8012A7E8_24 *arg1); +void func_800C5494(s32 arg0); +void func_800C54E8(s32 arg0, unk800C54E8 *arg1, s32 arg2, s32 arg3, s32 arg4); +void func_800C55F4(s32 arg0); +void func_800C5620(s32 arg0); +void func_800C564C(s32 arg0); +void func_800C5678(s32 arg0); +void func_800C56A4(s32 arg0); +void func_800C56D0(s32 arg0); +void func_800C56FC(s32 arg0, s32 arg1, s32 arg2); +void render_fill_rectangle(Gfx **dlist, s32 ulx, s32 uly, s32 lrx, s32 lry); +void func_800C5B58(Gfx **dlist, s32 *arg1, s32 *arg2, s32 arg3); +void parse_string_with_number(unsigned char *input, char *output, s32 number); + +void s32_to_string(char** outString, s32 number); //Non Matching +TextureHeader *func_800C4318(s32 font, u8 arg1); //Non Matching +void func_800C4170(s32 arg0); //Non Matching +void func_800C422C(s32 arg0); //Non Matching +void func_800C45A4(Gfx **dlist, unk8012A7E8 *arg1, u8 *text, s32 alignmentFlags, f32 arg4); //Non Matching +s32 func_800C4DA0(u8 *text, s32 x, s32 font); //Non Matching +//void func_800C5168(s32, s16, s16, s32, s32, s32); //Non Matching + +#endif diff --git a/src/stacks.h b/src/stacks.h index f2f55f9f..767fa2a9 100644 --- a/src/stacks.h +++ b/src/stacks.h @@ -10,4 +10,4 @@ extern s32 D_80129BB0[256]; extern s32 D_80129FB0[3]; extern s32 D_80129FBC; -#endif \ No newline at end of file +#endif From eadc711a1d79636e744568b771266540bbd35ca1 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Sun, 12 Sep 2021 11:49:24 -0400 Subject: [PATCH 2/6] Create game_text.h --- src/game_text.c | 24 +----------------------- src/game_text.h | 43 +++++++++++++++++++++++++++++++++++++++++++ src/menu.c | 2 +- 3 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 src/game_text.h diff --git a/src/game_text.c b/src/game_text.c index 60675404..aa1d6368 100644 --- a/src/game_text.c +++ b/src/game_text.c @@ -1,12 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C29F0 */ -#include "types.h" -#include "macros.h" -#include "f3ddkr.h" -#include "asset_sections.h" -#include "memory.h" -#include "PR/libultra.h" +#include "game_text.h" /************ .data ************/ @@ -20,16 +15,6 @@ s32 D_800E3680 = 1; /************ .bss ************/ -typedef struct unk8012A7C8 { - u8 *unk0; - u8 *unk4; -} unk8012A7C8; - -typedef struct unk8012A798 { - u8 *unk0; - u8 *unk4; -} unk8012A798; - u8 *D_8012A780; s8 D_8012A784; s8 D_8012A785; @@ -65,13 +50,6 @@ s32 D_8012A7DC; /*****************************/ -extern u32 osTvType; - -void func_800C2F1C(s32); -void func_8005A3B0(void); -void func_800C31EC(s32); -s8 func_8000C8B4(s32); - void func_800C29F0(void) { D_8012A7C8.unk0 = (u8 *)allocate_from_main_pool_safe(0x780, COLOR_TAG_GREEN); D_8012A7C8.unk4 = D_8012A7C8.unk0 + 0x3C0; diff --git a/src/game_text.h b/src/game_text.h new file mode 100644 index 00000000..846210f6 --- /dev/null +++ b/src/game_text.h @@ -0,0 +1,43 @@ +#ifndef _GAME_TEXT_H_ +#define _GAME_TEXT_H_ + +#include "types.h" +#include "macros.h" +#include "f3ddkr.h" +#include "asset_sections.h" +#include "memory.h" +#include "font.h" +#include "PR/libultra.h" + +typedef struct unk8012A7C8 { + u8 *unk0; + u8 *unk4; +} unk8012A7C8; + +typedef struct unk8012A798 { + u8 *unk0; + u8 *unk4; +} unk8012A798; + +extern u32 osTvType; + +void func_8005A3B0(void); //unknown_043920.c +s32 func_8000C8B4(s32 arg0); //unknown_00BC20.c +void func_8009CFB0(void); //menu.c +s32 func_8009CFEC(u32 arg0); //menu.c + +void func_800C29F0(void); +void func_800C2AB4(void); +void func_800C2AF4(s32 arg0); +void func_800C2F1C(s32 arg0); +void func_800C3048(void); +void func_800C30CC(void); +void func_800C3140(s32 arg0); +void func_800C314C(void); +void func_800C3158(s32 arg0, f32 arg1); +s32 func_800C3400(void); +void func_800C3440(s32 arg0); + +void func_800C31EC(s32); //Non Matching + +#endif diff --git a/src/menu.c b/src/menu.c index 61032a69..fecd8a46 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1565,7 +1565,7 @@ s32 music_is_playing(void); void set_text_color(s32 red, s32 green, s32 blue, s32 alpha, s32 opacity); void func_80082FAC(void); void func_8009ABAC(void); -void func_800C31EC(s32); +void func_800C31EC(s32); //game_text.h void update_controller_sticks(void); void func_80078D00(Gfx**, void *element, s32, s32, f32, f32, u32, s32); From 928ece073fd9e713507fa96bcd91880a4b3b2112 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Sun, 12 Sep 2021 11:59:27 -0400 Subject: [PATCH 3/6] create gzip.h --- src/asset_loading.h | 1 + src/gzip.c | 19 +------------------ src/gzip.h | 30 ++++++++++++++++++++++++++++++ src/textures_sprites.c | 1 + src/unknown_06B2B0.c | 1 + 5 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 src/gzip.h diff --git a/src/asset_loading.h b/src/asset_loading.h index 140bb0bc..d0ec4648 100644 --- a/src/asset_loading.h +++ b/src/asset_loading.h @@ -2,6 +2,7 @@ #define _UNKNOWN_0777A0_H_ #include "types.h" +#include "gzip.h" void func_80076BA0(void); s32 *load_asset_section_from_rom(u32 assetIndex); diff --git a/src/gzip.c b/src/gzip.c index eb172417..74b4a7a7 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -1,22 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C6170 */ -#include "memory.h" -#include "types.h" -#include "macros.h" - -typedef struct huft { - u8 e; /* number of extra bits or operation */ - u8 b; /* number of bits in this code or subcode */ - union { - u16 n; /* literal, length base, or distance base */ - struct huft *t; /* pointer to next level of table */ - } v; -} huft; - -/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ -#define BMAX 16 /* maximum bit length of any code (16 for explode) */ -#define N_MAX 288 /* maximum number of codes in any set */ +#include "gzip.h" /************ .data ************/ @@ -60,8 +45,6 @@ s32 get_asset_uncompressed_size(s32 assetIndex, s32 assetOffset) { return byteswap32(D_800E3764); } -s32 gzip_inflate_block(void); - /** * Decompresses gzip data. * Returns the pointer to the decompressed data. diff --git a/src/gzip.h b/src/gzip.h new file mode 100644 index 00000000..b64b9006 --- /dev/null +++ b/src/gzip.h @@ -0,0 +1,30 @@ +#ifndef _GZIP_H_ +#define _GZIP_H_ + +#include "memory.h" +#include "types.h" +#include "macros.h" + +typedef struct huft { + u8 e; /* number of extra bits or operation */ + u8 b; /* number of bits in this code or subcode */ + union { + u16 n; /* literal, length base, or distance base */ + struct huft *t; /* pointer to next level of table */ + } v; +} huft; + +/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ +#define BMAX 16 /* maximum bit length of any code (16 for explode) */ +#define N_MAX 288 /* maximum number of codes in any set */ + +void func_800C6170(void); +s32 byteswap32(u8 *arg0); +s32 get_asset_uncompressed_size(s32 assetIndex, s32 assetOffset); +u8 *gzip_inflate(u8 *compressedInput, u8 *decompressedOutput); + + +s32 gzip_inflate_block(void); // Non Matching +void gzip_huft_build(u32 *b, u32 n, u32 s, u16 *d, u16 *e, huft **t, s32 *m); // Non Matching + +#endif diff --git a/src/textures_sprites.c b/src/textures_sprites.c index f8116524..c8824f49 100644 --- a/src/textures_sprites.c +++ b/src/textures_sprites.c @@ -2,6 +2,7 @@ /* RAM_POS: 0x8007AC70 */ #include "textures_sprites.h" +#include "gzip.h" /************ .data ************/ diff --git a/src/unknown_06B2B0.c b/src/unknown_06B2B0.c index b2f7f69f..807c5208 100644 --- a/src/unknown_06B2B0.c +++ b/src/unknown_06B2B0.c @@ -14,6 +14,7 @@ #include "menu.h" #include "video.h" #include "lib/src/mips1/sc/sched.h" +#include "gzip.h" /************ .rodata ************/ From 1be1d00092c6ed6fa7e994b8d04fd1de412c07a5 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Sun, 12 Sep 2021 12:12:01 -0400 Subject: [PATCH 4/6] Create main.h --- src/main.c | 17 ++++++----------- src/main.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 src/main.h diff --git a/src/main.c b/src/main.c index d7164f05..09b7d5fb 100644 --- a/src/main.c +++ b/src/main.c @@ -1,9 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80065D40 */ -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" +#include "main.h" /************ .rodata ************/ @@ -16,12 +14,12 @@ const char D_800E6ED0[] = "WARNING: Stack overflow/underflow!!!\n"; /************ .bss ************/ -s32 *D_8011D750; // stack pointer for thread 1 +s32 *gThread1StackPointer; // stack pointer for thread 1 s32 D_8011D754; s32 D_8011D758[2048]; s32 *D_8011F758; s32 D_8011F75C; -OSThread *D_8011F760; // OSThread for thread 1 +OSThread *gThread1; // OSThread for thread 1 s32 D_8011F764; s32 D_8011F768[106]; OSThread *D_8011F910; // OSThread for thread 3 @@ -30,19 +28,16 @@ s32 D_8011F918[1130]; /******************************/ -void func_80065D98(s32 arg0); -void thread3_main(s32 arg0); - void main(void) { osInitialize(); - osCreateThread(&D_8011F760, 1, &func_80065D98, 0, &D_8011D750, 0); - osStartThread(&D_8011F760); + osCreateThread(&gThread1, 1, (OSId) &func_80065D98, 0, &gThread1StackPointer, (OSPri) 0); + osStartThread(&gThread1); } #ifdef NON_MATCHING void func_80065D98(s32 arg0) { func_800B6F50(); - osCreateThread(&D_8011F910, 3, &thread3_main, 0, &D_8011F758, 10); + osCreateThread(&D_8011F910, 3, (OSId) &thread3_main, 0, &D_8011F758, (OSPri) 10); D_8011D758[2049] = 0; D_8011D758[2048] = 0; D_8011D758[1] = 0; diff --git a/src/main.h b/src/main.h new file mode 100644 index 00000000..340ad3f4 --- /dev/null +++ b/src/main.h @@ -0,0 +1,15 @@ +#ifndef _MAIN_H_ +#define _MAIN_H_ + +#include "types.h" +#include "macros.h" +#include "libultra_internal.h" + +void thread3_main(s32 arg0); //unknown_06B2B0.c + +void main(void); + +void func_80065D98(s32 arg0); //Non Matching +//void func_80065E30(void); //Non Matching + +#endif From df9c8eca3b2092b39cbce5cfdb98c4a7bba46843 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Sun, 12 Sep 2021 12:33:03 -0400 Subject: [PATCH 5/6] Finish memory.h --- src/memory.c | 70 ++---------------------------------------- src/memory.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ src/unknown_00BC20.c | 5 +-- 3 files changed, 76 insertions(+), 72 deletions(-) diff --git a/src/memory.c b/src/memory.c index a81d60a3..2fd5252f 100644 --- a/src/memory.c +++ b/src/memory.c @@ -3,13 +3,6 @@ #include "memory.h" -#include "structs.h" -#include "types.h" -#include "macros.h" - -#define RAM_END 0x80400000 -#define MAIN_POOL_SLOT_COUNT 1600 - /************ .rodata ************/ const char D_800E7210[] = "*** mmAlloc: size = 0 ***\n"; @@ -31,36 +24,6 @@ const char D_800E7488[] = "Unable to record %d slots, colours overflowed table.\ /************ .bss ************/ -/* Size: 0x8 bytes */ -typedef struct unk80070BE4_8_0 { - s16 unk0; - s16 unk2; - s32 unk4; -} unk80070BE4_8_0; - -/* Size: 0x14 bytes */ -typedef struct MemoryPoolSlot { -/* 0x00 */ unk80070BE4_8_0 *unk0; -/* 0x04 */ s32 size; -/* 0x08 */ s16 flags; - // 0x00 = Slot is free - // 0x01 = Slot is being used? - // 0x02 = ??? - // 0x04 = ??? -/* 0x0A */ s16 prevIndex; -/* 0x0C */ s16 nextIndex; -/* 0x0E */ s16 index; -/* 0x10 */ u32 colorTag; -} MemoryPoolSlot; - -/* Size: 0x10 bytes */ -typedef struct MemoryPool { -/* 0x00 */ s32 maxNumSlots; -/* 0x04 */ s32 curNumSlots; -/* 0x08 */ MemoryPoolSlot *slots; -/* 0x0C */ s32 size; -} MemoryPool; - MemoryPool gMemoryPools[4]; #ifndef _ALIGN16 @@ -69,15 +32,7 @@ MemoryPool gMemoryPools[4]; s32 gNumberOfMemoryPools; s32 D_801235C4; - -/* Size: 0x8 bytes */ -typedef struct FreeQueueSlot { - void *dataAddress; - u8 unk4; -} FreeQueueSlot; - FreeQueueSlot gFreeQueue[256]; - s32 gFreeQueueCount; s32 gFreeQueueState; s32 D_80123DD0[64]; @@ -89,24 +44,6 @@ extern MemoryPoolSlot D_8012D3F0; /******************************/ -/* Unknown size */ -typedef struct unk800B7D10 { - u8 pad0[0x14]; - s32 unk14; -} unk800B7D10; - -unk800B7D10 *get_stack_pointer(void); -MemoryPoolSlot *allocate_from_memory_pool(s32, s32, u32); - -MemoryPoolSlot *new_memory_pool(MemoryPoolSlot *arg0, s32 size, s32 numSlots); -void set_free_queue_state(s32); -void *allocate_from_main_pool_safe(s32, u32); -s32 *func_8006F510(void); -void func_8006F53C(s32*); -void func_80071440(void *dataAddress); -s32 get_memory_pool_index_containing_address(u8 *address); -void free_memory_pool_slot(s32 poolIndex, s32 slotIndex); - /** * Creates the main memory pool. * Starts at 0x8012D3F0. Ends at 0x80400000. Contains 1600 allocation slots. @@ -292,8 +229,6 @@ void *allocate_at_address_in_main_pool(s32 size, u8 *address, u32 colorTag) { GLOBAL_ASM("asm/non_matchings/memory/allocate_at_address_in_main_pool.s") #endif -void free_slot_containing_address(u8 *address); - /** * Sets the state of the free queue. State is either 0, 1, or 2. * The free queue will get flushed if the state is set to 0. @@ -399,8 +334,8 @@ void func_80071314(void) { GLOBAL_ASM("asm/non_matchings/memory/free_slot_containing_address.s") #endif -void func_80071440(void *data) { - gFreeQueue[gFreeQueueCount].dataAddress = data; +void func_80071440(void *dataAddress) { + gFreeQueue[gFreeQueueCount].dataAddress = dataAddress; gFreeQueue[gFreeQueueCount].unk4 = gFreeQueueState; gFreeQueueCount++; } @@ -650,7 +585,6 @@ void render_memory_color_tags(void) { } #ifdef NON_MATCHING - // Unused. Does nothing? void func_80071C74(void) { s32 i, flags; diff --git a/src/memory.h b/src/memory.h index 9c6677df..b87247c2 100644 --- a/src/memory.h +++ b/src/memory.h @@ -1,7 +1,12 @@ #ifndef _MEMORY_H_ #define _MEMORY_H_ +#include "structs.h" #include "types.h" +#include "macros.h" + +#define RAM_END 0x80400000 +#define MAIN_POOL_SLOT_COUNT 1600 // Animation related? #define COLOR_TAG_RED 0xFF0000FF @@ -24,8 +29,76 @@ // ??? #define COLOR_TAG_BLACK 0x000000FF +/* Size: 0x8 bytes */ +typedef struct unk80070BE4_8_0 { + s16 unk0; + s16 unk2; + s32 unk4; +} unk80070BE4_8_0; + +/* Size: 0x14 bytes */ +typedef struct MemoryPoolSlot { +/* 0x00 */ unk80070BE4_8_0 *unk0; +/* 0x04 */ s32 size; +/* 0x08 */ s16 flags; + // 0x00 = Slot is free + // 0x01 = Slot is being used? + // 0x02 = ??? + // 0x04 = ??? +/* 0x0A */ s16 prevIndex; +/* 0x0C */ s16 nextIndex; +/* 0x0E */ s16 index; +/* 0x10 */ u32 colorTag; +} MemoryPoolSlot; + +/* Size: 0x10 bytes */ +typedef struct MemoryPool { +/* 0x00 */ s32 maxNumSlots; +/* 0x04 */ s32 curNumSlots; +/* 0x08 */ MemoryPoolSlot *slots; +/* 0x0C */ s32 size; +} MemoryPool; + +/* Size: 0x8 bytes */ +typedef struct FreeQueueSlot { + void *dataAddress; + u8 unk4; //FreeQueueState? +} FreeQueueSlot; + +/* Unknown size */ +typedef struct unk800B7D10 { + u8 pad0[0x14]; + s32 unk14; +} unk800B7D10; + +unk800B7D10 *get_stack_pointer(void); // Non Matching with own file +s32 *func_8006F510(void); // Non Matching unknown_070110 +void func_8006F53C(s32*); // Non Matching unknown_070110 + +void init_main_memory_pool(void); +MemoryPoolSlot *new_sub_memory_pool(s32 poolDataSize, s32 numSlots); void *allocate_from_main_pool_safe(s32 size, u32 colorTag); +MemoryPoolSlot *allocate_from_main_pool(s32 size, u32 colorTag); +void *allocate_from_pool_containing_slots(MemoryPoolSlot *slots, s32 size); +void set_free_queue_state(s32 state); void free_from_memory_pool(void *data); +void clear_free_queue(void); +void func_80071440(void *dataAddress); s32 func_80071478(u8 *address); +s32 func_80071538(u8 *address); +s32 get_memory_pool_index_containing_address(u8 *address); +u8 *align16(u8 *address); +u8 *align8(u8 *address); +u8 *align4(u8 *address); +void print_memory_color_tags(void); +void render_memory_color_tags(void); +void func_80071CE8(void); + +MemoryPoolSlot *allocate_from_memory_pool(s32 memoryPoolIndex, s32 size, u32 colorTag); // Non Matching +MemoryPoolSlot *new_memory_pool(MemoryPoolSlot *slots, s32 poolSize, s32 numSlots); // Non Matching +void free_memory_pool_slot(s32 poolIndex, s32 slotIndex); // Non Matching +void *allocate_at_address_in_main_pool(s32 size, u8 *address, u32 colorTag); // Non Matching +void free_slot_containing_address(u8 *address); // Non Matching +s32 get_memory_color_tag_count(s32 arg0); // Non Matching #endif diff --git a/src/unknown_00BC20.c b/src/unknown_00BC20.c index b7b19d87..9b8b3b06 100644 --- a/src/unknown_00BC20.c +++ b/src/unknown_00BC20.c @@ -9,6 +9,7 @@ #include "structs.h" #include "f3ddkr.h" #include "asset_sections.h" +#include "asset_loading.h" /************ .data ************/ @@ -296,10 +297,6 @@ void calc_dynamic_lighting_for_object_1(unk8001D6E4_arg1 *, ObjectModel *, s16, void calc_dynamic_lighting_for_object_2(unk8001D6E4_arg1 *, ObjectModel *, s16, f32); void func_8000C460(void); - -void *new_sub_memory_pool(s32, u32); -void *allocate_from_main_pool_safe(s32, u32); -s32 *load_asset_section_from_rom(s32); void gParticlePtrList_addObject(Object *); void gParticlePtrList_flush(void); void func_8001D258(f32, f32, s32, s32, s32); From 07c27f44f28f9c774f52a200b8ddc880f755f0c3 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Sun, 12 Sep 2021 12:39:26 -0400 Subject: [PATCH 6/6] Cleanup extern variable into a more descriptive name and type --- lib/src/unknown_0CE200.c | 3 ++- src/memory.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/unknown_0CE200.c b/lib/src/unknown_0CE200.c index 2792e57b..da2a628a 100644 --- a/lib/src/unknown_0CE200.c +++ b/lib/src/unknown_0CE200.c @@ -4,6 +4,7 @@ #include "types.h" #include "macros.h" #include "libultra_internal.h" +#include "memory.h" s32 D_800E38D0 = 0; @@ -31,7 +32,7 @@ s32 __osBaseCounter; s32 D_8012D22C; s32 D_8012D230[4]; s32 D_8012D240[108]; -s32 D_8012D3F0; +MemoryPoolSlot *gMainMemoryPool; GLOBAL_ASM("lib/asm/non_matchings/unknown_0CE200/__osSiCreateAccessQueue.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0CE200/__osSiGetAccess.s") diff --git a/src/memory.c b/src/memory.c index 2fd5252f..4b2a51e9 100644 --- a/src/memory.c +++ b/src/memory.c @@ -40,7 +40,7 @@ s32 D_80123ED0[64]; s32 D_80123FD0[8]; s32 D_80123FF0[8]; -extern MemoryPoolSlot D_8012D3F0; +extern MemoryPoolSlot *gMainMemoryPool; /******************************/ @@ -52,7 +52,7 @@ void init_main_memory_pool(void) { gNumberOfMemoryPools = -1; if(1) { // Create the main memory pool. - new_memory_pool(&D_8012D3F0, RAM_END - (s32)(&D_8012D3F0), MAIN_POOL_SLOT_COUNT); + new_memory_pool(&gMainMemoryPool, RAM_END - (s32)(&gMainMemoryPool), MAIN_POOL_SLOT_COUNT); } set_free_queue_state(2); gFreeQueueCount = 0;