diff --git a/include/functions.h b/include/functions.h index 18f0d04e..22dabec7 100644 --- a/include/functions.h +++ b/include/functions.h @@ -14,7 +14,6 @@ void func_80004CC0(OSThread *, s32, s32); void func_80004CF4(void *); // types unknown void func_80004D20(void *); // types unknown void func_800052B4(void); -void func_800053B4(void *, s32); // types unknown void func_80005328(void *); // types unknown // C030.s diff --git a/include/variables.h b/include/variables.h index 9cd23644..ddc00799 100644 --- a/include/variables.h +++ b/include/variables.h @@ -49,6 +49,7 @@ typedef enum { extern u8 gPool[]; extern Gfx* gDisplayListHead; +extern u64 _binary_assets_us_F3DEX2_bin_start[]; extern u8 D_1000000[]; extern u8 D_3000000[]; diff --git a/linker_scripts/us/symbol_addrs.txt b/linker_scripts/us/symbol_addrs.txt index ab401a3e..00bfb9fe 100644 --- a/linker_scripts/us/symbol_addrs.txt +++ b/linker_scripts/us/symbol_addrs.txt @@ -253,3 +253,6 @@ D_87B000F4 = 0x87B000F4; D_86402848 = 0x86402848; gCurrentGameState = 0x80075668; // size:0x4 D_800AE540 = 0x800AE540; // size:0x1200 +D_80068080 = 0x80068080; +D_8007ED20 = 0x8007ED20; +D_800A60C0 = 0x800A60C0; diff --git a/src/1CF30.c b/src/1CF30.c index 7cc968a5..78b54541 100644 --- a/src/1CF30.c +++ b/src/1CF30.c @@ -379,7 +379,7 @@ void func_8001E884(s32 arg0, s32 arg1, s32 arg2) { unk_D_800AC870* func_8001E94C(s32 arg0, s32 arg1) { D_800AC870 = main_pool_alloc_with_func(sizeof(*D_800AC870), arg1, 'PRNT', func_8001E7C0); bzero(D_800AC870, sizeof(*D_800AC870)); - D_800AC870->unk_48 = func_800044F4(_3BA190_ROM_START, _3CB130_ROM_START, 1, 1); + D_800AC870->unk_48 = ASSET_LOAD2(func_800044F4, _3BA190, 1, 1); func_8001E9F0(arg0); return D_800AC870; diff --git a/src/3FB0.c b/src/3FB0.c index 4fbe1ad6..e30609e3 100644 --- a/src/3FB0.c +++ b/src/3FB0.c @@ -1,87 +1,376 @@ #include "3FB0.h" -#include "memory.h" -#include "memmap.h" +#include "include/functions.h" +#include "src/3FB0.h" +#include "src/D470.h" +#include "src/dma.h" +#include "src/dp_intro.h" +#include "src/memory.h" +#include "src/util.h" +#include "lib/ultralib/include/PR/leo.h" + +typedef enum { + JPEG_MARKER_START_OF_FRAME = 0xC0, + JPEG_MARKER_HUFFMAN_TABLE = 0xC4, + JPEG_MARKER_RESTART0 = 0xD0, + JPEG_MARKER_RESTART7 = 0xD7, + JPEG_MARKER_START_OF_IMAGE = 0xD8, + JPEG_MARKER_END_OF_IMAGE = 0xD9, + JPEG_MARKER_START_OF_SCAN = 0xDA, + JPEG_MARKER_QUANTIZATION_TABLE = 0xDB, +} JpegStreamMarker; + +static u8 D_800A60C0[0x200]; +static OSMesgQueue D_800A62C0; +static OSMesg D_800A62D8; + +s32 func_800033B0(u8* arg0) { + return ((arg0[0] << 8) | arg0[1]) & 0xFFFF; +} + +void func_800033C8(unk_func_80003680_sp300* arg0, u8* arg1) { + s32 temp_v0_2; + s32 var_s2; + s32 var_v0; + u8 temp_t6; + s32 temp_v0; + + var_s2 = 1; + arg0->unk_01 = 0; + + while (var_s2 != 0) { + // JPEG data consists of streams, which are identified by a marker. + // Each marker is in the form [0xFF, 0xID] where ID identifies the type of stream. + if (*arg1++ == 0xFF) { + temp_v0 = *arg1++; + switch (temp_v0) { + case 0: + break; + + case JPEG_MARKER_END_OF_IMAGE: + var_s2 = 0; + break; + + case JPEG_MARKER_QUANTIZATION_TABLE: + arg0->quantization_table = arg1 + 2; + arg1 += func_800033B0(arg1); + break; + + case JPEG_MARKER_HUFFMAN_TABLE: + arg0->huffman_table = arg1 + 2; + arg1 += func_800033B0(arg1); + break; + + case JPEG_MARKER_START_OF_FRAME: + arg0->start_of_frame = arg1 + 2; + arg1 += func_800033B0(arg1); + break; + + case JPEG_MARKER_START_OF_SCAN: + arg1 += func_800033B0(arg1); + arg0->start_of_scan = arg1; + break; + + case JPEG_MARKER_START_OF_IMAGE: + break; + + default: + if ((temp_v0 >= JPEG_MARKER_RESTART0) && (temp_v0 <= JPEG_MARKER_RESTART7)) { + arg0->unk_01 = 1; + } else { + arg1 += func_800033B0(arg1); + } + break; + } + } + } + + // Checking the second component's ID, + // this seems weird as it will break entirely if number of components is less than 3. + // Looking at every JPEG used in the Stadium rom, no JPEGs use this ID, they're all 0x22. + if (arg0->start_of_frame[7] == 0x21) { + arg0->unk_00 = 0; + } else { + arg0->unk_00 = 2; + } + + arg0->width = (arg0->start_of_frame[3] << 8) | arg0->start_of_frame[4]; + arg0->height = (arg0->start_of_frame[1] << 8) | arg0->start_of_frame[2]; +} + +extern u64 D_80065FC0[]; +extern u64 D_80068080[]; +extern u64 D_8007ED20[]; + +void func_80003558(UnkStruct80001380* arg0, unk_func_80003680_sp90* arg1) { + arg0->task.t.type = 4; + arg0->task.t.flags = 0; + arg0->task.t.ucode_boot = D_80065FC0; + arg0->task.t.ucode_boot_size = (u32)_binary_assets_us_F3DEX2_bin_start - (u32)D_80065FC0; + arg0->task.t.ucode = D_80068080; + arg0->task.t.ucode_size = 0x1000; + arg0->task.t.ucode_data = D_8007ED20; + arg0->task.t.ucode_data_size = 0x800; + arg0->task.t.dram_stack = NULL; + arg0->task.t.dram_stack_size = 0; + arg0->task.t.output_buff = NULL; + arg0->task.t.output_buff_size = NULL; + arg0->task.t.data_ptr = arg1; + arg0->task.t.data_size = 0x20; + arg0->task.t.yield_data_ptr = D_800A60C0; + arg0->task.t.yield_data_size = 0x200; + + osCreateMesgQueue(&arg0->queue, &arg0->mesg, 1); +} + +void func_80003608(unk_func_80003680_sp27* arg0, unk_func_80003680_spB0* arg1, unk_func_80003680_sp300* arg2) { + arg0->unk_00 = arg2->start_of_scan; + arg0->unk_04 = arg2->unk_00; + arg0->unk_05 = 2; + arg0->unk_08 = &arg1[0]; + arg0->unk_0C = &arg1[2]; + arg0->unk_10 = &arg1[1]; + arg0->unk_14 = &arg1[3]; + arg0->unk_18 = arg2->unk_01; +} + +void func_80003648(unk_func_80003680_sp90* arg0, u8(arg1)[2][0x80], unk_func_80003680_sp300* arg2) { + arg0->unk_00 = 0; + arg0->unk_08 = arg2->unk_00; + arg0->unk_04 = 1; + arg0->unk_0C = (u32)&arg1[0] & 0x1FFFFFFF; + arg0->unk_10 = (u32)&arg1[1] & 0x1FFFFFFF; + arg0->unk_14 = (u32)&arg1[1] & 0x1FFFFFFF; +} + +s32 func_80003680(u32 addr, s32 arg1, u8* arg2) { + UNUSED s32 pad; + UnkStruct80001380 sp318; + unk_func_80003680_sp300 sp300; + u8 sp200[2][0x80]; + unk_func_80003680_spB0 spB0[4]; + u8* temp_s0; + u8* temp_s3; + unk_func_80003680_sp90 sp90; + unk_func_80003680_sp27 sp74; + unk_func_80003680_sp60 sp60; + u32 var_s1; + s32 i; + s32 j; + s32 var_s4 = 0; + s32 var_s2 = 0; + + temp_s3 = Util_Malloc(0x110); + temp_s0 = Util_Malloc(0x210); + + func_800033C8(&sp300, arg2); + func_8000BD70(sp300.quantization_table, sp200, 2); + func_8000C02C(sp300.huffman_table, spB0, temp_s3, temp_s0, 4); + + Util_Free(temp_s0); + Util_Free(temp_s3); + + func_80003608(&sp74, &spB0, &sp300); + func_80003648(&sp90, &sp200, &sp300); + func_80003558(&sp318, &sp90); + + while (func_80001C90() == 0) {} + + for (i = 0; i < sp300.height; i += 16) { + for (j = 0; j < sp300.width; j += 16) { + if (arg1 < (var_s2 + 0x300)) { + return 0; + } + + if (func_8000C280(&sp74, addr, 1, var_s4, &sp60) != 0) { + return 0; + } + + sp90.unk_00 = addr & 0x1FFFFFFF; + func_800053B4(&sp318, 1); + var_s4 = 1; + func_800049AC(&sp318); + + addr += 0x200; + var_s2 += 0x200; + } + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800033B0.s") + return var_s2; +} + +void func_80003860(void) { + osCreateMesgQueue(&D_800A62C0, &D_800A62D8, 1); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800033C8.s") +void func_80003890(u8* in_header, u8* memory) { + UNUSED s32 pad2; + PERSSZP* header = in_header; + u32* sp2C = (u32*)header + 6; + UNUSED s32 pad; + s32 sp24 = header->decompressed_size2 - header->decompressed_size1; + u32 var_v0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003558.s") + osInvalICache(memory, header->decompressed_size2); + osInvalDCache(memory, header->decompressed_size2); -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003608.s") + Yay0_Decompress(in_header + header->header_size, memory); + + for (var_v0 = 0; var_v0 < header->unk_14; var_v0++) { + *(u32*)(memory + sp2C[1]) = sp2C[0]; + sp2C += 2; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003648.s") + if (sp24 != 0) { + bzero(memory + header->decompressed_size1, sp24); + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003680.s") + osWritebackDCache(memory, header->decompressed_size2); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003860.s") +void func_80003964(u8* arg0, s32 arg1, s32 arg2, s32 arg3) { + s32 var_s0; + OSMesgQueue* mesq = &D_800A62C0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003890.s") + for (; arg2 > 0; arg2 -= var_s0) { + if (arg2 >= 0x1000) { + var_s0 = 0x1000; + } else { + var_s0 = arg2; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003964.s") + func_80000F80(arg3, arg0, arg1, var_s0, mesq, 0); + osRecvMesg(mesq, NULL, 1); -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003A14.s") + arg0 += var_s0; + arg1 += var_s0; + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003B04.s") +s32 func_80003A14(u8* arg0, s16 arg1, s16 arg2, s32 arg3) { + OSMesg sp44; + OSMesgQueue* mesq = &D_800A62C0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003B30.s") + for (; arg2 > 0;) { + func_8000100C(arg3, arg0, arg1, mesq, 0); + osRecvMesg(mesq, &sp44, 1); -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003BE0.s") + if ((arg3 == 1) && (func_8000CFB0(arg1) != 0)) { + return -1; + } -s32 func_80003680(u32 addr, u32 arg1, u32 arg2, UnkInputStruct80003C80* arg3); + arg0 += 0x80; + arg1++; + arg2--; + } -s32 func_80003C80(s32 arg0, UnkInputStruct80003C80* arg1, s32 side) { - s32 addr = main_pool_alloc(arg1->unkC + 0x100, side); + return 0; +} + +void func_80003B04(s16 arg0) { + func_8000CDB8(arg0 << 7); +} + +void func_80003B30(u8* arg0, u8* arg1, u8* arg2, s32 arg3) { + s32 var_s0; + s32 var_s1; + OSMesgQueue* mesq = &D_800A62C0; + + for (var_s1 = arg2 - arg1; var_s1 > 0; var_s1 -= var_s0) { + if (var_s1 >= 0x1000) { + var_s0 = 0x1000; + } else { + var_s0 = var_s1; + } + + func_80000E80(arg3, arg0, arg1, var_s0, mesq, 0); + osRecvMesg(mesq, NULL, 1); + + arg0 += var_s0; + arg1 += var_s0; + } +} + +void func_80003BE0(u8* arg0, u8* arg1, u8* arg2) { + s32 var_s0; + s32 var_s1; + OSMesgQueue* mesq = &D_800A62C0; + + for (var_s1 = arg2 - arg1; var_s1 > 0; var_s1 -= var_s0) { + if (var_s1 >= 0x1000) { + var_s0 = 0x1000; + } else { + var_s0 = var_s1; + } + + func_80000F0C(arg0, arg1, var_s0, mesq, 0); + osRecvMesg(mesq, NULL, 1); + + arg0 += var_s0; + arg1 += var_s0; + } +} + +void* func_80003C80(u8* addr, PRESJPEG* arg1, s32 side) { + s32 new_addr = main_pool_alloc(arg1->unk_0C + 0x100, side); + + if (new_addr != NULL) { + s32 size = func_80003680(new_addr, arg1->unk_0C + 0x100, (u32)arg1 + arg1->unk_08); - if (addr != 0) { - s32 size = func_80003680(addr, arg1->unkC + 0x100, (u32)arg1 + arg1->unk8, arg1); if (size == 0) { - main_pool_try_free(addr); - addr = NULL; + main_pool_try_free(new_addr); + new_addr = NULL; } else if (side == 0) { - main_pool_realloc(addr, size); + main_pool_realloc(new_addr, size); } } - main_pool_try_free(arg0); - return addr; -} -void func_80003890(s32, void*); + main_pool_try_free(addr); -s32 func_80003D18(s32 arg0, UnkInputStruct80003D18* arg1, s32 side) { - s32 vaddr = main_pool_alloc(arg1->unk10, side); + return new_addr; +} + +s32 func_80003D18(s32 arg0, PERSSZP* arg1, s32 side) { + s32 vaddr = main_pool_alloc(arg1->decompressed_size2, side); if (vaddr != NULL) { func_80003890(arg1, vaddr); } + main_pool_try_free(arg0); + return vaddr; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003D64.s") +u32* func_80003D64(u8* arg0, s32 arg1, u32 arg2, s32 arg3) { + u32* sp1C = main_pool_alloc(arg2, arg3); -void func_80003B30(u8*, u8*, u8*, s32); + if (sp1C != NULL) { + Util_Memcpy(sp1C, arg0 + arg1, arg2 >> 2); + } + + main_pool_try_free(arg0); + + return sp1C; +} void* func_80003DC4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { u32* addr; u32* newaddr; u32* ret; - s32 pad; + UNUSED s32 pad; int side; side = (arg2 == 0) ? MEMORY_POOL_RIGHT : MEMORY_POOL_LEFT; - addr = main_pool_alloc(0x18, side); + if (addr != NULL) { func_80003B30(addr, romStart, romStart + 0x18, arg3); - // is PERS-SZP? if ((addr[0] == 'PERS') && (addr[1] == '-SZP')) { newaddr = main_pool_alloc(ALIGN16(romEnd - romStart), side); if (newaddr != NULL) { func_80003B30(newaddr, romStart, romEnd, arg3); ret = func_80003D18(newaddr, newaddr, arg2); } - // is PRESJPEG? } else if ((addr[0] == 'PRES') && (addr[1] == 'JPEG')) { newaddr = main_pool_alloc(ALIGN16(romEnd - romStart), side); if (newaddr != NULL) { @@ -97,20 +386,95 @@ void* func_80003DC4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { } main_pool_try_free(addr); } + return ret; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80003F54.s") +void* func_80003F54(unk_func_800041C0* arg0, s32 arg1) { + s32 sp44; + u32* sp40; + PERSSZP* temp_s0; + s32 var_s0; + u8* temp_v0; + + if (arg1 == 0) { + var_s0 = 1; + } else { + var_s0 = 0; + } + + LeoLBAToByte(arg0->unk_00, arg0->unk_02, &sp44); + sp44 = ALIGN16(sp44); + + temp_v0 = main_pool_alloc(sp44, var_s0); + + if (temp_v0 != NULL) { + temp_s0 = arg0->unk_04 + temp_v0; + + func_80001098(0, temp_v0, arg0->unk_00, arg0->unk_02, &D_800A62C0, 0); + osRecvMesg(&D_800A62C0, NULL, 1); + + if (((u32*)temp_s0->magic)[0] == 'PERS' && (((u32*)temp_s0->magic)[1] == '-SZP')) { + sp40 = func_80003D18(temp_v0, temp_s0, arg1); + } else if (((u32*)temp_s0->magic)[0] == 'PRES' && (((u32*)temp_s0->magic)[1] == 'JPEG')) { + sp40 = func_80003C80(temp_v0, temp_s0, arg1); + } else { + sp40 = func_80003D64(temp_v0, arg0->unk_04, arg0->unk_08, arg1); + } + } + + return sp40; +} + +unk_func_800041C0* func_80004098(unk_func_800041C0* arg0, s32 arg1, s32 arg2) { + arg0->unk_00 = arg1; + arg0->unk_02 = arg2 - arg1; + arg0->unk_04 = 0; + + LeoLBAToByte(arg0->unk_00, arg0->unk_02, &arg0->unk_08); + + return arg0; +} + +unk_func_800041C0* func_800040EC(unk_func_800041C0* arg0, u32 arg1, u32 offset, u32 size) { + s32 sp2C; + s32 sp28; + s32 sp24; + + LeoByteToLBA(arg1, offset + 1, &sp28); + sp28 -= 1; + LeoByteToLBA(arg1, offset + size, &sp24); + sp24 -= 1; + + if (sp28 > 0) { + LeoLBAToByte(arg1, sp28, &sp2C); + } else { + sp2C = 0; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80004098.s") + arg0->unk_00 = sp28 + arg1; + arg0->unk_02 = (sp24 - sp28) + 1; + arg0->unk_04 = offset - sp2C; + arg0->unk_08 = size; -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800040EC.s") + return arg0; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800041C0.s") +void func_800041C0(s32 arg0, s32 arg1, s32 arg2) { + unk_func_800041C0 sp1C; + + func_80004098(&sp1C, arg0, arg1); + func_80003F54(&sp1C, arg2); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80004200.s") +void func_80004200(u32 block_addr, u32 addr) { + u32 base = addr & 0xFF000000; + u32 sp1C = addr & 0xFFFFFF; -void func_80004200(s32, s32); + if ((base == 0x82000000) && (Memmap_GetSegmentBaseVaddr(sp1C) == block_addr)) { + Memmap_ClearSegmentMemmap(sp1C); + } +} s32 func_80004258(s32 id, u8* rom_start, u8* rom_end, s32 arg3) { s32 vaddr = func_80003DC4(rom_start, rom_end, arg3, 0); @@ -122,7 +486,18 @@ s32 func_80004258(s32 id, u8* rom_start, u8* rom_end, s32 arg3) { return vaddr; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800042E0.s") +struct MainPoolBlock* func_800042E0(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + UNUSED s32 pad; + unk_func_800041C0 sp28; + struct MainPoolBlock* temp_v0 = func_80003F54(func_80004098(&sp28, arg1, arg2), arg3); + + if ((temp_v0 != NULL) && (arg0 > 0)) { + Memmap_SetSegmentMap(arg0, temp_v0, main_pool_get_block_dist(temp_v0)); + main_pool_set_func(temp_v0, arg0 + 0x82000000, func_80004200); + } + + return temp_v0; +} void func_80004364(u32 base_addr, u32 addr) { u32 sp1C; @@ -137,7 +512,7 @@ void func_80004364(u32 base_addr, u32 addr) { } void func_800043BC(s32 arg0, Fragment* addr) { - s32 pad; + UNUSED s32 pad; u32 sp20 = main_pool_get_block_dist(addr); main_pool_set_func(addr, arg0 + 0x81000000, &func_80004364); @@ -160,15 +535,23 @@ void* func_80004454(s32 arg0, u8* romStart, u8* romEnd) { return addr; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800044A8.s") +void* func_800044A8(s32 arg0, s32 arg1, s32 arg2) { + Fragment* sp2C; + unk_func_800041C0 sp20; + + sp2C = func_80003F54(func_80004098(&sp20, arg1, arg2), 0); + if (sp2C != NULL) { + func_800043BC(arg0, sp2C); + } + return sp2C; +} void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { - u32* ret; - unsigned long sp28_2; - unsigned long sp28; + u32* ret = NULL; + u32 sp28; + u32 sp28_2; u16* newaddr; - ret = NULL; switch (arg2) { case 0: newaddr = func_80003DC4(romStart, romEnd, 0, 0); @@ -177,13 +560,14 @@ void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { newaddr[0] |= 1; } break; + case 1: newaddr = func_80003DC4(romStart, romStart + 0x20, 0, 0); ret = newaddr; if (newaddr != NULL) { - sp28_2 = (ret[3] * 0x10) + 0x10; + sp28 = (ret[3] * 0x10) + 0x10; main_pool_try_free(ret); - newaddr = func_80003DC4(romStart, romStart + sp28_2, 0, 0); + newaddr = func_80003DC4(romStart, romStart + sp28, 0, 0); ret = newaddr; if (newaddr != NULL) { *newaddr |= 2; @@ -193,13 +577,14 @@ void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { } } break; + case 2: newaddr = func_80003DC4(romStart, romStart + 0x20, 1, 0); ret = newaddr; if (newaddr != NULL) { - sp28 = (ret[3] * 0x10) + 0x10; + sp28_2 = (ret[3] * 0x10) + 0x10; main_pool_try_free(ret); - newaddr = func_80003DC4(romStart, romStart + sp28, 1, 0); + newaddr = func_80003DC4(romStart, romStart + sp28_2, 1, 0); ret = newaddr; if ((newaddr != NULL) && (arg3 == 1)) { *newaddr |= 4; @@ -207,20 +592,113 @@ void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { } break; } + if (ret != NULL) { ret[1] = romStart; } + return ret; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80004660.s") +void* func_80004660(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + BinArchive* var_a0; + unk_func_800041C0 sp20; -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800047A4.s") + switch (arg2) { + default: + break; -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_800047C4.s") + case 0: + func_80004098(&sp20, arg0, arg1); + var_a0 = func_80003F54(&sp20, 0); + if (var_a0 != NULL) { + main_pool_realloc(var_a0, var_a0->total_size); + var_a0->unk_00 |= 1; + } + break; + + case 1: + func_80004098(&sp20, arg0, arg0 + 1); + var_a0 = func_80003F54(&sp20, 0); + if (var_a0 != NULL) { + main_pool_realloc(var_a0, (var_a0->num_files * sizeof(BinArchiveFile)) + sizeof(BinArchive)); + var_a0->unk_00 |= 2; + if (arg3 == 1) { + var_a0->unk_00 |= 4; + } + } + break; + + case 2: + func_80004098(&sp20, arg0, arg0 + 1); + var_a0 = func_80003F54(&sp20, 1); + if (arg3 == 1) { + var_a0->unk_00 |= 4; + } + break; + } + + if (var_a0 != NULL) { + var_a0->unk_00 |= 0x80; + var_a0->unk_04 = arg0; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_80004804.s") + return var_a0; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_8000484C.s") +void func_800047A4(void* arg0) { + main_pool_try_free(arg0); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/3FB0/func_8000495C.s") +Fragment* func_800047C4(BinArchive* arg0, BinArchiveFile* arg1) { + u8* temp_a0 = arg0->unk_04 + arg1->offset; + + return func_80003DC4(temp_a0, arg1->size + temp_a0, 0, 0); +} + +void* func_80004804(BinArchive* arg0, BinArchiveFile* arg1) { + unk_func_800041C0 sp1C; + + func_800040EC(&sp1C, arg0->unk_04, arg1->offset, arg1->size); + return func_80003F54(&sp1C, 0); +} + +void* func_8000484C(BinArchive* archive, s32 file_number) { + Fragment* var_a2 = NULL; + UNUSED s32 pad; + BinArchiveFile* sp18 = (u8*)archive + sizeof(BinArchive) + (file_number * sizeof(BinArchiveFile)); + + if (file_number < archive->num_files) { + if (archive->unk_00 & 1) { + var_a2 = (u8*)archive + sp18->offset; + } else if (!(archive->unk_00 & 4) && (sp18->unk_08 != NULL)) { + var_a2 = sp18->unk_08; + } else { + if (archive->unk_00 & 0x80) { + var_a2 = func_80004804(archive, sp18); + } else { + var_a2 = func_800047C4(archive, sp18); + } + + if (var_a2 != NULL) { + if ((((u32*)var_a2->magic)[0] == 'FRAG') && (((u32*)var_a2->magic)[1] == 'MENT')) { + func_800043BC(archive->unk_02, var_a2); + } + + sp18->unk_08 = var_a2; + } + } + } + + return var_a2; +} + +s32 func_8000495C(BinArchive* archive, s32 file_number) { + BinArchiveFile* sp18 = (u8*)archive + sizeof(BinArchive) + (file_number * sizeof(BinArchiveFile)); + s32 var_v1 = 0; + + if (file_number < archive->num_files) { + var_v1 = sp18->unk_08; + } + return var_v1; +} diff --git a/src/3FB0.h b/src/3FB0.h index 10332535..1ce71e02 100644 --- a/src/3FB0.h +++ b/src/3FB0.h @@ -2,30 +2,114 @@ #define _3FB0_H_ #include "global.h" +#include "5580.h" +#include "C970.h" +#include "CE80.h" +#include "src/memmap.h" typedef struct ret_func_8000484C { /* 0x00 */ char unk00[0x90]; /* 0x90 */ s32 unk_90; } ret_func_8000484C; // size >= 0x94 -// PERS-SZP header -typedef struct UnkInputStruct80003D18 { - char filler0[0x10]; - u32 unk10; -} UnkInputStruct80003D18; - -// PERSJPEG header -typedef struct UnkInputStruct80003C80 { - char filler0[0x8]; - u32 unk8; - u32 unkC; -} UnkInputStruct80003C80; - -s32 func_80003C80(s32 arg0, UnkInputStruct80003C80* arg1, s32 side); -s32 func_80003D18(s32 arg0, UnkInputStruct80003D18* arg1, s32 side); +typedef struct PERSSZP { + /* 0x00 */ char magic[0x8]; // PERS-SZP + /* 0x08 */ u32 header_size; + /* 0x0C */ u32 decompressed_size1; // How do these differ? + /* 0x10 */ u32 decompressed_size2; + /* 0x14 */ u32 unk_14; +} PERSSZP; // sze = 0x18 + +typedef struct PRESJPEG { + /* 0x00 */ char magic[0x8]; // PRESJPEG + /* 0x08 */ u32 unk_08; + /* 0x0C */ u32 unk_0C; +} PRESJPEG; // size = 0x10 + +typedef struct Yay0 { + /* 0x00 */ char magic[0x4]; // Yay0 + /* 0x04 */ u32 decompressed_size; + /* 0x08 */ u32 link_table_offset; + /* 0x0C */ u32 byte_chunk_offset; +} Yay0; // size = 0x10 + +typedef struct BinArchive { + /* 0x00 */ u16 unk_00; + /* 0x02 */ u16 unk_02; + /* 0x04 */ u32 unk_04; + /* 0x08 */ u32 total_size; + /* 0x0C */ u32 num_files; +} BinArchive; // size = 0x10 + +typedef struct BinArchiveFile { + /* 0x00 */ u32 offset; + /* 0x04 */ u32 size; + /* 0x08 */ u32 unk_08; + /* 0x0C */ char unk0C[0x4]; +} BinArchiveFile; // size = 0x10 + +typedef struct unk_func_800041C0 { + /* 0x00 */ u16 unk_00; + /* 0x02 */ u16 unk_02; + /* 0x04 */ s32 unk_04; + /* 0x08 */ s32 unk_08; +} unk_func_800041C0; // size >= 0x8 + +typedef struct unk_func_80003680_sp300 { + /* 0x00 */ u8 unk_00; + /* 0x01 */ u8 unk_01; + /* 0x02 */ char unk02[0x2]; + /* 0x04 */ s16 width; + /* 0x06 */ s16 height; + /* 0x08 */ u8* quantization_table; + /* 0x0C */ u8* huffman_table; + /* 0x10 */ u8* start_of_frame; + /* 0x14 */ u8* start_of_scan; +} unk_func_80003680_sp300; // size = 0x18 + +typedef struct unk_func_80003680_sp90 { + /* 0x00 */ s32 unk_00; + /* 0x04 */ s32 unk_04; + /* 0x08 */ s32 unk_08; + /* 0x0C */ s32 unk_0C; + /* 0x10 */ s32 unk_10; + /* 0x14 */ s32 unk_14; +} unk_func_80003680_sp90; // size >= 0x18 + +s32 func_800033B0(u8* arg0); +void func_800033C8(unk_func_80003680_sp300* arg0, u8* arg1); +void func_80003558(UnkStruct80001380* arg0, unk_func_80003680_sp90* arg1); +void func_80003608(unk_func_80003680_sp27* arg0, unk_func_80003680_spB0* arg1, unk_func_80003680_sp300* arg2); +void func_80003648(unk_func_80003680_sp90* arg0, u8(arg1)[2][0x80], unk_func_80003680_sp300* arg2); +s32 func_80003680(u32 addr, s32 arg1, u8* arg2); +void func_80003860(void); +void func_80003890(u8* in_header, u8* memory); +void func_80003964(u8* arg0, s32 arg1, s32 arg2, s32 arg3); +s32 func_80003A14(u8* arg0, s16 arg1, s16 arg2, s32 arg3); +void func_80003B04(s16 arg0); +void func_80003B30(u8* arg0, u8* arg1, u8* arg2, s32 arg3); +void func_80003BE0(u8* arg0, u8* arg1, u8* arg2); +void* func_80003C80(u8* addr, PRESJPEG* arg1, s32 side); +s32 func_80003D18(s32 arg0, PERSSZP* arg1, s32 side); +u32* func_80003D64(u8* arg0, s32 arg1, u32 arg2, s32 arg3); void* func_80003DC4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3); +void* func_80003F54(unk_func_800041C0* arg0, s32 arg1); +unk_func_800041C0* func_80004098(unk_func_800041C0* arg0, s32 arg1, s32 arg2); +unk_func_800041C0* func_800040EC(unk_func_800041C0* arg0, u32 arg1, u32 offset, u32 size); +void func_800041C0(s32 arg0, s32 arg1, s32 arg2); +void func_80004200(u32 block_addr, u32 addr); s32 func_80004258(s32 id, u8* rom_start, u8* rom_end, s32 arg3); +struct MainPoolBlock* func_800042E0(s32 arg0, s32 arg1, s32 arg2, s32 arg3); +void func_80004364(u32 base_addr, u32 addr); +void func_800043BC(s32 arg0, Fragment* addr); void* func_80004454(s32 arg0, u8* romStart, u8* romEnd); +void* func_800044A8(s32 arg0, s32 arg1, s32 arg2); void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3); +void* func_80004660(s32 arg0, s32 arg1, s32 arg2, s32 arg3); +void func_800047A4(void* arg0); +Fragment* func_800047C4(BinArchive* arg0, BinArchiveFile* arg1); +void* func_80004804(BinArchive* arg0, BinArchiveFile* arg1); +void* func_8000484C(BinArchive* archive, s32 file_number); +s32 func_8000495C(BinArchive* archive, s32 file_number); #endif // _3FB0_H_ diff --git a/src/5580.h b/src/5580.h index 08308bdf..637cf7bf 100644 --- a/src/5580.h +++ b/src/5580.h @@ -3,7 +3,15 @@ #include "global.h" +typedef struct UnkStruct80001380 { + /* 0x00 */ OSMesg mesg; + /* 0x04 */ OSMesgQueue queue; + /* 0x1C */ OSTask task; +} UnkStruct80001380; // size >= 0x7C + +void func_800049AC(UnkStruct80001380*); void func_80005370(struct UnkStruct800AA660*); +void func_800053B4(UnkStruct80001380*, s32); #endif // _5580_H_ diff --git a/src/C970.c b/src/C970.c index 3507a622..a0c299cf 100644 --- a/src/C970.c +++ b/src/C970.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "C970.h" #pragma GLOBAL_ASM("asm/us/nonmatchings/C970/func_8000BD70.s") diff --git a/src/C970.h b/src/C970.h new file mode 100644 index 00000000..d1310b86 --- /dev/null +++ b/src/C970.h @@ -0,0 +1,13 @@ +#ifndef _C970_H_ +#define _C970_H_ + +#include "global.h" + +typedef struct unk_func_80003680_spB0 { + /* 0x00 */ char unk00[0x54]; +} unk_func_80003680_spB0; // size = 0x54 + +void func_8000BD70(u8* in_quantization_tables, u8* out_quantization_tables, s32 num_tables); +void func_8000C02C(u8* in_huffman_table, unk_func_80003680_spB0*, u8*, u8*, s32); + +#endif // _C970_H_ diff --git a/src/CE80.c b/src/CE80.c index a1c707c9..8dc53dfd 100644 --- a/src/CE80.c +++ b/src/CE80.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "CE80.h" #pragma GLOBAL_ASM("asm/us/nonmatchings/CE80/func_8000C280.s") diff --git a/src/CE80.h b/src/CE80.h new file mode 100644 index 00000000..6a78ac13 --- /dev/null +++ b/src/CE80.h @@ -0,0 +1,30 @@ +#ifndef _CE80_H_ +#define _CE80_H_ + +#include "global.h" +#include "C970.h" + +typedef struct unk_func_80003680_sp27 { + /* 0x00 */ s32 unk_00; + /* 0x04 */ s8 unk_04; + /* 0x05 */ s8 unk_05; + /* 0x08 */ unk_func_80003680_spB0* unk_08; + /* 0x0C */ unk_func_80003680_spB0* unk_0C; + /* 0x10 */ unk_func_80003680_spB0* unk_10; + /* 0x14 */ unk_func_80003680_spB0* unk_14; + /* 0x18 */ s8 unk_18; +} unk_func_80003680_sp27; // size == 0x1C + +typedef struct unk_func_80003680_sp60 { + /* 0x00 */ s32 unk_00; + /* 0x04 */ s8 unk_04; + /* 0x05 */ s8 unk_05; + /* 0x08 */ s32 unk_08; + /* 0x0C */ s16 unk_0C; + /* 0x0E */ s16 unk_0E; + /* 0x10 */ s16 unk_10; +} unk_func_80003680_sp60; // size = 0x14 + +s32 func_8000C280(unk_func_80003680_sp27*, u32, s32, u8, unk_func_80003680_sp60*); + +#endif // _CE80_H_ diff --git a/src/D470.c b/src/D470.c index 1df9c318..7516355a 100644 --- a/src/D470.c +++ b/src/D470.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "D470.h" #pragma GLOBAL_ASM("asm/us/nonmatchings/D470/func_8000C870.s") diff --git a/src/D470.h b/src/D470.h new file mode 100644 index 00000000..dcc1b1b3 --- /dev/null +++ b/src/D470.h @@ -0,0 +1,9 @@ +#ifndef _D470_H_ +#define _D470_H_ + +#include "global.h" + +void func_8000CDB8(s32); +s32 func_8000CFB0(s32); + +#endif // _D470_H_ diff --git a/src/dp_intro.c b/src/dp_intro.c index b83c7072..44499408 100644 --- a/src/dp_intro.c +++ b/src/dp_intro.c @@ -2,6 +2,7 @@ #include #include "global.h" #include "dp_intro.h" +#include "5580.h" #include "6BC0.h" #include "crash_screen.h" #include "profiler.h" @@ -9,12 +10,6 @@ // dp_intro.c -struct UnkStruct80001380 { - OSMesg mesg; - OSMesgQueue queue; - OSTask task; -}; - struct UnkArray4 { u8 unk0; u8 unk1; @@ -62,9 +57,7 @@ struct UnkStruct80083CA0_2 { extern struct UnkStruct80083CA0_2 D_80083CA0; -extern struct UnkStruct80001380 D_800846C0; - -extern void func_800049AC(); +extern UnkStruct80001380 D_800846C0; extern struct UnkArray4 D_8008472C; extern struct UnkArray4 D_8008473C; @@ -72,7 +65,6 @@ extern struct UnkArray4 D_8008474C; extern s32 D_80068B70; -extern u64 _binary_assets_us_F3DEX2_bin_start[]; extern u64 F3DEX2_data_bin[]; // F3DEX2_data.bin extern u64 D_80084860[0x1]; extern u64 D_80085870[0x1]; @@ -105,7 +97,7 @@ extern u64 D_80084760[0x100 / sizeof(u64)]; void func_80001AD4(u16 color); void func_80001C1C(struct UnkArray4* arg0, u8 arg1, u8 arg2, u8 arg3, u8 arg4, s32 arg5, s32 arg6, s32 arg7); -void func_80001380(struct UnkStruct80001380* arg0) { +void func_80001380(UnkStruct80001380* arg0) { arg0->task.t.type = 1; arg0->task.t.flags = 0; arg0->task.t.ucode_boot = D_80084760; @@ -123,7 +115,7 @@ void func_80001380(struct UnkStruct80001380* arg0) { osCreateMesgQueue(&arg0->queue, &arg0->mesg, 1); } -void func_80001444(struct UnkStruct80001380* arg0, struct UnkArray4* arg1, s32 arg2) { +void func_80001444(UnkStruct80001380* arg0, struct UnkArray4* arg1, s32 arg2) { arg0->task.t.data_ptr = (void*)(uintptr_t)arg1->unk4; arg0->task.t.data_size = arg1->unk8; func_800053B4(arg0, arg2); diff --git a/src/heap.c b/src/heap.c index 3680438f..76b3c697 100644 --- a/src/heap.c +++ b/src/heap.c @@ -1,3 +1,3 @@ #include "global.h" -u8 gPool[0x80600000-0x80100000]; // unk determinate size. Large generic size to compile. +u8 gPool[0x80600000 - 0x80100000]; // unk determinate size. Large generic size to compile. diff --git a/src/memmap.h b/src/memmap.h index 5b828ed0..a6d23ac1 100644 --- a/src/memmap.h +++ b/src/memmap.h @@ -30,7 +30,7 @@ struct RelocTable { typedef struct Fragment { /* 0x00 */ u32 inst[2]; // MIPS instructions to jump to the main function, typically something like "j 0x8xx00020; nop" - /* 0x08 */ char str[8]; // "FRAGMENT" + /* 0x08 */ char magic[8]; // "FRAGMENT" /* 0x10 */ u32 entrypoint; // typically 0x20 /* 0x14 */ u32 relocOffset; // relocOffset /* 0x18 */ u32 sizeInRom; diff --git a/yamls/us/rom.yaml b/yamls/us/rom.yaml index 765a82b1..e6ab1abc 100644 --- a/yamls/us/rom.yaml +++ b/yamls/us/rom.yaml @@ -377,7 +377,8 @@ - [0x7BAC0, .rodata, rsp] - [0x7BB10, rodata] - [0x7BB20, .rodata, util] - - [0x7BB50, rodata] + - [0x7BB50, .rodata, 3FB0] + - [0x7BBC0, rodata] - [0x7BBE0, .rodata, crash_screen] - [0x7BFA0, .rodata, profiler] - [0x7BFC0, .rodata, gb_tower] @@ -449,6 +450,8 @@ - {vram: 0x80083CA0, type: bss, name: unk_bss} - {vram: 0x800A6070, type: .bss, name: memory_main} - {vram: 0x800A60B0, type: bss, name: unk_bss_4} + - {vram: 0x800A60C0, type: .bss, name: 3FB0} + - {vram: 0x800A62E0, type: bss, name: unk_bss_8} - {vram: 0x800A7320, type: .bss, name: controller} - {vram: 0x800A7420, type: bss, name: unk_bss_3} - {vram: 0x800A7450, type: .bss, name: stage_loader} @@ -460,6 +463,7 @@ - {vram: 0x800FF990, type: .bss, name: 4B940} - {vram: 0x800FF9B0, type: .bss, name: 4BDC0} - {vram: 0x800FF9C0, type: bss, name: unk_bss_10} + # libleo - {vram: 0x80100740, type: .bss, name: libleo/driverominit}