From 0a9e649d1a2f7b9267d38b53b5090dace6283719 Mon Sep 17 00:00:00 2001 From: David Benepe Date: Sat, 10 Jul 2021 14:50:50 -0500 Subject: [PATCH] Minor documentation progress with _00BC20, _043920, _060450, and _0C4800 --- .../unknown_00BC20/func_8000C8F8.s | 2 +- .../{func_80060058.s => free_object_model.s} | 2 +- .../unknown_05F690/func_8005F850.s | 90 ------------ .../unknown_05F690/func_8005F99C.s | 4 +- .../unknown_05F690/func_8005FF40.s | 2 +- .../unknown_05F690/func_80061A00.s | 2 +- include/structs.h | 77 ++++++++++ src/memory.h | 10 ++ src/unknown_00BC20.c | 18 --- src/unknown_043920.c | 1 + src/unknown_060450.c | 138 ++++++++++++++---- src/unknown_0C4800.c | 35 +++-- 12 files changed, 223 insertions(+), 158 deletions(-) rename asm/non_matchings/unknown_05F690/{func_80060058.s => free_object_model.s} (99%) delete mode 100644 asm/non_matchings/unknown_05F690/func_8005F850.s diff --git a/asm/non_matchings/unknown_00BC20/func_8000C8F8.s b/asm/non_matchings/unknown_00BC20/func_8000C8F8.s index b3e27a1f..3986cbf8 100644 --- a/asm/non_matchings/unknown_00BC20/func_8000C8F8.s +++ b/asm/non_matchings/unknown_00BC20/func_8000C8F8.s @@ -107,7 +107,7 @@ glabel func_8000C8F8 /* 00D680 8000CA80 10E0004A */ beqz $a3, .L8000CBAC /* 00D684 8000CA84 8FBF0024 */ lw $ra, 0x24($sp) /* 00D688 8000CA88 AFA6003C */ sw $a2, 0x3c($sp) -/* 00D68C 8000CA8C 0C031877 */ jal func_800C61DC +/* 00D68C 8000CA8C 0C031877 */ jal get_asset_uncompressed_size /* 00D690 8000CA90 AFA70054 */ sw $a3, 0x54($sp) /* 00D694 8000CA94 8FAD0048 */ lw $t5, 0x48($sp) /* 00D698 8000CA98 8FA70054 */ lw $a3, 0x54($sp) diff --git a/asm/non_matchings/unknown_05F690/func_80060058.s b/asm/non_matchings/unknown_05F690/free_object_model.s similarity index 99% rename from asm/non_matchings/unknown_05F690/func_80060058.s rename to asm/non_matchings/unknown_05F690/free_object_model.s index aa2f5826..119f1644 100644 --- a/asm/non_matchings/unknown_05F690/func_80060058.s +++ b/asm/non_matchings/unknown_05F690/free_object_model.s @@ -1,4 +1,4 @@ -glabel func_80060058 +glabel free_object_model /* 060C58 80060058 27BDFFD8 */ addiu $sp, $sp, -0x28 /* 060C5C 8006005C AFBF0024 */ sw $ra, 0x24($sp) /* 060C60 80060060 AFB20020 */ sw $s2, 0x20($sp) diff --git a/asm/non_matchings/unknown_05F690/func_8005F850.s b/asm/non_matchings/unknown_05F690/func_8005F850.s deleted file mode 100644 index f3ac26ad..00000000 --- a/asm/non_matchings/unknown_05F690/func_8005F850.s +++ /dev/null @@ -1,90 +0,0 @@ -glabel func_8005F850 -/* 060450 8005F850 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 060454 8005F854 AFBF0014 */ sw $ra, 0x14($sp) -/* 060458 8005F858 3C0500FF */ lui $a1, (0x00FF00FF >> 16) # lui $a1, 0xff -/* 06045C 8005F85C 34A500FF */ ori $a1, (0x00FF00FF & 0xFFFF) # ori $a1, $a1, 0xff -/* 060460 8005F860 0C01C327 */ jal allocate_from_main_pool_safe -/* 060464 8005F864 24040230 */ li $a0, 560 -/* 060468 8005F868 3C018012 */ lui $at, %hi(D_8011D624) # $at, 0x8012 -/* 06046C 8005F86C 3C0500FF */ lui $a1, (0x00FF00FF >> 16) # lui $a1, 0xff -/* 060470 8005F870 AC22D624 */ sw $v0, %lo(D_8011D624)($at) -/* 060474 8005F874 34A500FF */ ori $a1, (0x00FF00FF & 0xFFFF) # ori $a1, $a1, 0xff -/* 060478 8005F878 0C01C327 */ jal allocate_from_main_pool_safe -/* 06047C 8005F87C 24040190 */ li $a0, 400 -/* 060480 8005F880 3C018012 */ lui $at, %hi(D_8011D628) # $at, 0x8012 -/* 060484 8005F884 AC22D628 */ sw $v0, %lo(D_8011D628)($at) -/* 060488 8005F888 3C018012 */ lui $at, %hi(D_8011D62C) # $at, 0x8012 -/* 06048C 8005F88C AC20D62C */ sw $zero, %lo(D_8011D62C)($at) -/* 060490 8005F890 3C018012 */ lui $at, %hi(D_8011D634) # $at, 0x8012 -/* 060494 8005F894 AC20D634 */ sw $zero, %lo(D_8011D634)($at) -/* 060498 8005F898 0C01DB16 */ jal load_asset_section_from_rom -/* 06049C 8005F89C 2404001C */ li $a0, 28 -/* 0604A0 8005F8A0 3C058012 */ lui $a1, %hi(D_8011D630) # $a1, 0x8012 -/* 0604A4 8005F8A4 3C078012 */ lui $a3, %hi(D_8011D620) # $a3, 0x8012 -/* 0604A8 8005F8A8 24E7D620 */ addiu $a3, %lo(D_8011D620) # addiu $a3, $a3, -0x29e0 -/* 0604AC 8005F8AC 24A5D630 */ addiu $a1, %lo(D_8011D630) # addiu $a1, $a1, -0x29d0 -/* 0604B0 8005F8B0 00007080 */ sll $t6, $zero, 2 -/* 0604B4 8005F8B4 ACE20000 */ sw $v0, ($a3) -/* 0604B8 8005F8B8 ACA00000 */ sw $zero, ($a1) -/* 0604BC 8005F8BC 004E7821 */ addu $t7, $v0, $t6 -/* 0604C0 8005F8C0 8DF80000 */ lw $t8, ($t7) -/* 0604C4 8005F8C4 2406FFFF */ li $a2, -1 -/* 0604C8 8005F8C8 00402025 */ move $a0, $v0 -/* 0604CC 8005F8CC 10D80009 */ beq $a2, $t8, .L8005F8F4 -/* 0604D0 8005F8D0 00001825 */ move $v1, $zero -/* 0604D4 8005F8D4 24790001 */ addiu $t9, $v1, 1 -.L8005F8D8: -/* 0604D8 8005F8D8 00194080 */ sll $t0, $t9, 2 -/* 0604DC 8005F8DC 00884821 */ addu $t1, $a0, $t0 -/* 0604E0 8005F8E0 ACB90000 */ sw $t9, ($a1) -/* 0604E4 8005F8E4 8D2A0000 */ lw $t2, ($t1) -/* 0604E8 8005F8E8 03201825 */ move $v1, $t9 -/* 0604EC 8005F8EC 14CAFFFA */ bne $a2, $t2, .L8005F8D8 -/* 0604F0 8005F8F0 24790001 */ addiu $t9, $v1, 1 -.L8005F8F4: -/* 0604F4 8005F8F4 246BFFFF */ addiu $t3, $v1, -1 -/* 0604F8 8005F8F8 ACAB0000 */ sw $t3, ($a1) -/* 0604FC 8005F8FC 0C01DB16 */ jal load_asset_section_from_rom -/* 060500 8005F900 2404001E */ li $a0, 30 -/* 060504 8005F904 3C018012 */ lui $at, %hi(D_8011D638) # $at, 0x8012 -/* 060508 8005F908 AC22D638 */ sw $v0, %lo(D_8011D638)($at) -/* 06050C 8005F90C 0C01DB16 */ jal load_asset_section_from_rom -/* 060510 8005F910 2404001F */ li $a0, 31 -/* 060514 8005F914 3C018012 */ lui $at, %hi(D_8011D63C) # $at, 0x8012 -/* 060518 8005F918 3C0500FF */ lui $a1, (0x00FF00FF >> 16) # lui $a1, 0xff -/* 06051C 8005F91C AC22D63C */ sw $v0, %lo(D_8011D63C)($at) -/* 060520 8005F920 34A500FF */ ori $a1, (0x00FF00FF & 0xFFFF) # ori $a1, $a1, 0xff -/* 060524 8005F924 0C01C327 */ jal allocate_from_main_pool_safe -/* 060528 8005F928 24040C00 */ li $a0, 3072 -/* 06052C 8005F92C 3C018012 */ lui $at, %hi(D_8011D644) # $at, 0x8012 -/* 060530 8005F930 3C05800E */ lui $a1, %hi(D_800DCEA4) # $a1, 0x800e -/* 060534 8005F934 8CA5CEA4 */ lw $a1, %lo(D_800DCEA4)($a1) -/* 060538 8005F938 AC22D644 */ sw $v0, %lo(D_8011D644)($at) -/* 06053C 8005F93C 3C018012 */ lui $at, %hi(D_8011D640) # $at, 0x8012 -/* 060540 8005F940 AC20D640 */ sw $zero, %lo(D_8011D640)($at) -/* 060544 8005F944 00002025 */ move $a0, $zero -/* 060548 8005F948 18A00009 */ blez $a1, .L8005F970 -/* 06054C 8005F94C 00001825 */ move $v1, $zero -/* 060550 8005F950 3C028002 */ lui $v0, %hi(func_80024D54) # $v0, 0x8002 -/* 060554 8005F954 24424D54 */ addiu $v0, %lo(func_80024D54) # addiu $v0, $v0, 0x4d54 -.L8005F958: -/* 060558 8005F958 00436021 */ addu $t4, $v0, $v1 -/* 06055C 8005F95C 918D0000 */ lbu $t5, ($t4) -/* 060560 8005F960 24630001 */ addiu $v1, $v1, 1 -/* 060564 8005F964 0065082A */ slt $at, $v1, $a1 -/* 060568 8005F968 1420FFFB */ bnez $at, .L8005F958 -/* 06056C 8005F96C 008D2021 */ addu $a0, $a0, $t5 -.L8005F970: -/* 060570 8005F970 3C0E800E */ lui $t6, %hi(D_800DCEA0) # $t6, 0x800e -/* 060574 8005F974 8DCECEA0 */ lw $t6, %lo(D_800DCEA0)($t6) -/* 060578 8005F978 00000000 */ nop -/* 06057C 8005F97C 108E0004 */ beq $a0, $t6, .L8005F990 -/* 060580 8005F980 8FBF0014 */ lw $ra, 0x14($sp) -/* 060584 8005F984 0C017097 */ jal func_8005C25C -/* 060588 8005F988 00000000 */ nop -/* 06058C 8005F98C 8FBF0014 */ lw $ra, 0x14($sp) -.L8005F990: -/* 060590 8005F990 27BD0018 */ addiu $sp, $sp, 0x18 -/* 060594 8005F994 03E00008 */ jr $ra -/* 060598 8005F998 00000000 */ nop - diff --git a/asm/non_matchings/unknown_05F690/func_8005F99C.s b/asm/non_matchings/unknown_05F690/func_8005F99C.s index 5b029d4b..aea23239 100644 --- a/asm/non_matchings/unknown_05F690/func_8005F99C.s +++ b/asm/non_matchings/unknown_05F690/func_8005F99C.s @@ -72,7 +72,7 @@ glabel func_8005F99C /* 060698 8005FA98 2404001D */ li $a0, 29 /* 06069C 8005FA9C 01305023 */ subu $t2, $t1, $s0 /* 0606A0 8005FAA0 AFAA0048 */ sw $t2, 0x48($sp) -/* 0606A4 8005FAA4 0C031877 */ jal func_800C61DC +/* 0606A4 8005FAA4 0C031877 */ jal get_asset_uncompressed_size /* 0606A8 8005FAA8 02002825 */ move $a1, $s0 /* 0606AC 8005FAAC 24440080 */ addiu $a0, $v0, 0x80 /* 0606B0 8005FAB0 3C05FF00 */ lui $a1, (0xFF0000FF >> 16) # lui $a1, 0xff00 @@ -209,7 +209,7 @@ glabel func_8005F99C /* 0608A0 8005FCA0 10000004 */ b .L8005FCB4 /* 0608A4 8005FCA4 A0600020 */ sb $zero, 0x20($v1) .L8005FCA8: -/* 0608A8 8005FCA8 0C018016 */ jal func_80060058 +/* 0608A8 8005FCA8 0C018016 */ jal free_object_model /* 0608AC 8005FCAC 02402025 */ move $a0, $s2 /* 0608B0 8005FCB0 00001025 */ move $v0, $zero .L8005FCB4: diff --git a/asm/non_matchings/unknown_05F690/func_8005FF40.s b/asm/non_matchings/unknown_05F690/func_8005FF40.s index 19f439b7..b89ac863 100644 --- a/asm/non_matchings/unknown_05F690/func_8005FF40.s +++ b/asm/non_matchings/unknown_05F690/func_8005FF40.s @@ -42,7 +42,7 @@ glabel func_8005FF40 /* 060BD0 8005FFD0 10C8001D */ beq $a2, $t0, .L80060048 /* 060BD4 8005FFD4 00A02025 */ move $a0, $a1 /* 060BD8 8005FFD8 AFA60018 */ sw $a2, 0x18($sp) -/* 060BDC 8005FFDC 0C018016 */ jal func_80060058 +/* 060BDC 8005FFDC 0C018016 */ jal free_object_model /* 060BE0 8005FFE0 AFA70020 */ sw $a3, 0x20($sp) /* 060BE4 8005FFE4 3C038012 */ lui $v1, %hi(D_8011D634) # $v1, 0x8012 /* 060BE8 8005FFE8 2463D634 */ addiu $v1, %lo(D_8011D634) # addiu $v1, $v1, -0x29cc diff --git a/asm/non_matchings/unknown_05F690/func_80061A00.s b/asm/non_matchings/unknown_05F690/func_80061A00.s index e867378a..29dc1014 100644 --- a/asm/non_matchings/unknown_05F690/func_80061A00.s +++ b/asm/non_matchings/unknown_05F690/func_80061A00.s @@ -57,7 +57,7 @@ glabel func_80061A00 /* 0626C8 80061AC8 8C520000 */ lw $s2, ($v0) /* 0626CC 80061ACC 8C490004 */ lw $t1, 4($v0) /* 0626D0 80061AD0 02402825 */ move $a1, $s2 -/* 0626D4 80061AD4 0C031877 */ jal func_800C61DC +/* 0626D4 80061AD4 0C031877 */ jal get_asset_uncompressed_size /* 0626D8 80061AD8 01329823 */ subu $s3, $t1, $s2 /* 0626DC 80061ADC 24440080 */ addiu $a0, $v0, 0x80 /* 0626E0 80061AE0 3C05FF00 */ lui $a1, (0xFF0000FF >> 16) # lui $a1, 0xff00 diff --git a/include/structs.h b/include/structs.h index a43d8baa..4506e0b5 100644 --- a/include/structs.h +++ b/include/structs.h @@ -253,6 +253,83 @@ typedef struct { /* 0x4C */ u32 unk4C; } dkr_wave_t; +/* Size: 8 bytes */ +typedef struct TextureInfo { +/* 0x00 */ TextureHeader *texture; +/* 0x04 */ u8 width; +/* 0x05 */ u8 height; +/* 0x06 */ u8 format; +/* 0x07 */ u8 unk7; +} TextureInfo; + +/* Size: 10 bytes */ +typedef struct Vertex { +/* 0x00 */ s16 x; +/* 0x02 */ s16 y; +/* 0x04 */ s16 z; +/* 0x06 */ u8 r; +/* 0x07 */ u8 g; +/* 0x08 */ u8 b; +/* 0x09 */ u8 a; +} Vertex; + +/* Size: 4 bytes */ +typedef struct TexCoords { + s16 u, v; +} TexCoords; + +/* Size: 16 bytes */ +typedef struct Triangle { +/* 0x00 */ u8 drawBackface; // 0x40 = Draw backface, 0x00 = Cull backface +/* 0x01 */ u8 vi0; // First vertex index +/* 0x02 */ u8 vi1; // Second vertex index +/* 0x03 */ u8 vi2; // Third vertex index +/* 0x04 */ TexCoords uv0; // Texture coordinates for the first vertex +/* 0x08 */ TexCoords uv1; // Texture coordinates for the second vertex +/* 0x0C */ TexCoords uv2; // Texture coordinates for the third vertex +} Triangle; + +/* Size: 12 bytes */ +typedef struct TriangleBatchInfo { +/* 0x00 */ u8 textureIndex; // 0xFF = No texture +/* 0x02 */ s16 verticesOffset; +/* 0x04 */ s16 facesOffset; +/* 0x06 */ u8 unk6; +/* 0x08 */ u32 flags; + // 0x00000010 = Depth write + // 0x00000100 = Hidden/Invisible geometry + // 0x00000200 = ??? Used in func_80060AC8 + // 0x00008000 = Environment mapping + // 0x00010000 = Texture is animated +} TriangleBatchInfo; + +/* Size: 8 bytes */ +typedef struct ObjectModel_44 { +/* 0x00 */ s32 *anim; +/* 0x04 */ s32 unk4; +} ObjectModel_44; + +typedef struct ObjectModel { +/* 0x00 */ TextureInfo *textures; +/* 0x04 */ Vertex *vertices; +/* 0x08 */ Triangle *triangles; +/* 0x0C */ s32 *unkC; +/* 0x10 */ s32 *unk10; + u8 pad0[0x0E]; +/* 0x22 */ s16 numberOfTextures; +/* 0x24 */ s16 numberOfVertices; +/* 0x26 */ s16 numberOfTriangles; +/* 0x28 */ s16 numberOfBatches; + u8 pad2A[6]; +/* 0x30 */ s16 unk30; + u8 pad32[6]; +/* 0x38 */ TriangleBatchInfo *batches; +/* 0x3C */ u8 pad3C[4]; +/* 0x40 */ s32 *unk40; +/* 0x44 */ ObjectModel_44 *animations; +/* 0x48 */ s16 numberOfAnimations; +} ObjectModel; + typedef struct Object_3C { u8 pad0[0x8]; s8 unk8; diff --git a/src/memory.h b/src/memory.h index 8ee632b8..f4675390 100644 --- a/src/memory.h +++ b/src/memory.h @@ -1,15 +1,25 @@ #ifndef _MEMORY_H_ #define _MEMORY_H_ +// Animation related? #define COLOR_TAG_RED 0xFF0000FF +// Object related? #define COLOR_TAG_GREEN 0x00FF00FF +// ??? #define COLOR_TAG_BLUE 0x0000FFFF +// ??? #define COLOR_TAG_YELLOW 0xFFFF00FF +// ??? #define COLOR_TAG_MAGENTA 0xFF00FFFF +// Audio related? #define COLOR_TAG_CYAN 0x00FFFFFF +// ??? #define COLOR_TAG_WHITE 0xFFFFFFFF +// ??? #define COLOR_TAG_GRAY 0x7F7F7FFF +// ??? #define COLOR_TAG_ORANGE 0xFF7F7FFF +// ??? #define COLOR_TAG_BLACK 0x000000FF #endif \ No newline at end of file diff --git a/src/unknown_00BC20.c b/src/unknown_00BC20.c index 077e0204..4453206e 100644 --- a/src/unknown_00BC20.c +++ b/src/unknown_00BC20.c @@ -279,24 +279,6 @@ extern s16 D_8011D5AC; extern s32 osTvType; -/* Size: 12 bytes */ -typedef struct TriangleBatchInfo { -/* 0x00 */ u8 textureIndex; // 0xFF = No texture -/* 0x02 */ s16 verticesOffset; -/* 0x04 */ s16 facesOffset; -/* 0x06 */ u8 unk6; -/* 0x08 */ u32 flags; - // 0x00000100 = Hidden geometry - // 0x00008000 = Environment mapping -} TriangleBatchInfo; - -typedef struct ObjectModel { - u8 pad0[0x28]; -/* 0x28 */ s16 numberOfBatches; - u8 pad2A[14]; -/* 0x38 */ TriangleBatchInfo *batches; -} ObjectModel; - typedef struct unk8001D6E4_arg1_40 { u8 pad0[0x71]; /* 0x71 */ u8 unk71; diff --git a/src/unknown_043920.c b/src/unknown_043920.c index c9fa0aa6..54a19d15 100644 --- a/src/unknown_043920.c +++ b/src/unknown_043920.c @@ -614,6 +614,7 @@ GLOBAL_ASM("asm/non_matchings/unknown_043920/func_8005A424.s") GLOBAL_ASM("asm/non_matchings/unknown_043920/func_8005A6F0.s") GLOBAL_ASM("asm/non_matchings/unknown_043920/func_8005B818.s") +// This gets called if an anti-piracy checksum fails in func_8005F850. void func_8005C25C(void) { D_800DCB9C[0] = 0.05f; } diff --git a/src/unknown_060450.c b/src/unknown_060450.c index 8fcb8f2f..c554c834 100644 --- a/src/unknown_060450.c +++ b/src/unknown_060450.c @@ -3,6 +3,9 @@ #include "types.h" #include "macros.h" +#include "structs.h" +#include "memory.h" +#include "asset_sections.h" /************ .data ************/ @@ -24,52 +27,124 @@ const char D_800E6BE0[] = "MOD Error: Tryed to deallocate non-existent model!!\n /************ .bss ************/ -s32 D_8011D620; -s32 D_8011D624; -s32 D_8011D628; +/* 8 Bytes */ +typedef struct unk8011D624 { + s32 unk0; + ObjectModel *model; +} unk8011D624; + +s32 *D_8011D620; +unk8011D624 *D_8011D624; // Array of unk8011D624 +s32 *D_8011D628; s32 D_8011D62C; s32 D_8011D630; s32 D_8011D634; -s32 D_8011D638; -s32 D_8011D63C; +s16 *D_8011D638; +s32 *D_8011D63C; s32 D_8011D640; s32 D_8011D644; s32 D_8011D648[66]; /******************************/ -GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_8005F850.s") +void func_80024D54(void); + +void func_8005F850(void) { + s32 i; + s32 checksum; + + D_8011D624 = allocate_from_main_pool_safe(0x230, COLOR_TAG_GREEN); + D_8011D628 = allocate_from_main_pool_safe(0x190, COLOR_TAG_GREEN); + D_8011D62C = 0; + D_8011D634 = 0; + D_8011D620 = load_asset_section_from_rom(ASSET_OBJECT_MODELS_TABLE); + D_8011D630 = 0; + while (D_8011D620[D_8011D630] != -1) { + D_8011D630++; + } + D_8011D630--; + D_8011D638 = load_asset_section_from_rom(ASSET_ANIMATION_IDS); + D_8011D63C = load_asset_section_from_rom(ASSET_OBJECT_ANIMATIONS_TABLE); + D_8011D644 = allocate_from_main_pool_safe(0xC00, COLOR_TAG_GREEN); + D_8011D640 = 0; + checksum = 0; + for (i = 0; i < D_800DCEA4; i++) { + checksum += *(u8*)(((s32)&func_80024D54) + i); + } + if (checksum != D_800DCEA0) { + func_8005C25C(); + } +} + GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_8005F99C.s") GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_8005FCD0.s") -GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_8005FF40.s") -#if 1 -void func_80060058(void *arg0) { +#if 0 +void free_object_model(ObjectModel *model); +void free_from_memory_pool(void*); + +// Causes crashes after playing a little, and I don't know why. +void func_8005FF40(ObjectModel **modelPtr) { s32 i; - for (i = 0; i < arg0->unk22; i++) { - if (arg0->unk0[i].unk0 != NULL) { - func_8007B2BC(arg0->unk0[i].unk0); + s32 modelIndex; + ObjectModel *model; + + if (modelPtr != NULL) { + model = *modelPtr; + model->unk30--; + if (model->unk30 > 0) { + free_from_memory_pool(model); + return; + } + modelIndex = -1; + for (i = 0; i < D_8011D62C; i++) { + if (model == D_8011D624[i].model) { + modelIndex = i; + } + } + if (modelIndex != -1) { + free_object_model(model); + D_8011D628[D_8011D634] = modelIndex; + D_8011D634++; + D_8011D624[modelIndex].unk0 = -1; + D_8011D624[modelIndex].model = (ObjectModel *)-1; + free_from_memory_pool(modelPtr); } } - if (arg0->unkC != NULL) { - free_from_memory_pool(arg0->unkC); - } - if (arg0->unk10 != NULL) { - free_from_memory_pool(arg0->unk10); - } - if (arg0->unk40 != NULL) { - free_from_memory_pool(arg0->unk40); - } - if (arg0->unk44 != NULL) { - for (i = 0; i < arg0->unk48; i++) { - free_from_memory_pool((u8*)arg0->unk44[i] - 4); - } - free_from_memory_pool(arg0->unk44); - } - free_from_memory_pool(arg0); } #else -GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_80060058.s") +GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_8005FF40.s") +#endif + +#ifdef NON_MATCHING +// Regalloc issues. +void free_object_model(ObjectModel *model) { + s32 i; + for (i = 0; i < model->numberOfTextures; i++) { + if (model->textures[i].texture != NULL) { + func_8007B2BC(model->textures[i].texture); + } + } + if (model->unkC != NULL) { + free_from_memory_pool(model->unkC); + } + if (model->unk10 != NULL) { + free_from_memory_pool(model->unk10); + } + if (model->unk40 != NULL) { + free_from_memory_pool(model->unk40); + } + if (model->animations != NULL) { + // Small issue with this loop too. + for (i = 0; i < model->numberOfAnimations; i++) { + free_from_memory_pool(model->animations[i].unk0 - 1); + } + free_from_memory_pool(model->animations); + } + free_from_memory_pool(model); +} +#else +GLOBAL_ASM("asm/non_matchings/unknown_05F690/free_object_model.s") #endif GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_8006017C.s") @@ -82,5 +157,8 @@ void func_800619F4(s32 arg0) { D_8011D640 = arg0; } +// s32 func_80061A00(ObjectModel *model, s32 animTableIndex) +// Returns 0 if successful, or 1 if an error occured. GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_80061A00.s") -GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_80061C0C.s") \ No newline at end of file + +GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_80061C0C.s") diff --git a/src/unknown_0C4800.c b/src/unknown_0C4800.c index 3651d975..abea2bc1 100644 --- a/src/unknown_0C4800.c +++ b/src/unknown_0C4800.c @@ -313,8 +313,7 @@ GLOBAL_ASM("asm/non_matchings/unknown_0B8920/func_800C4DA0.s") void func_800C4EDC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { if (arg0 > 0 && arg0 < 8) { - // How is temp supposed to be setup for all of these functions? This is driving me nuts. - unk8012A7E8 *temp = &D_8012A7E8[arg0]; // Issue with temp + unk8012A7E8 *temp = &D_8012A7E8[arg0]; temp->unk0 = 0; temp->unk2 = 0; if (arg1 < arg3) { @@ -374,7 +373,7 @@ void func_800C5050(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { if (arg0 <= 0 || arg0 >= 8) { return; } - temp = &D_8012A7E8[arg0]; // Issue with temp + temp = &D_8012A7E8[arg0]; temp->unk18 = arg1; temp->unk19 = arg2; temp->unk1A = arg3; @@ -387,7 +386,7 @@ void func_800C5094(s32 arg0, s32 arg1, s32 arg2) { if (arg0 <= 0 || arg0 >= 8) { return; } - temp = &D_8012A7E8[arg0]; // Issue with temp + temp = &D_8012A7E8[arg0]; temp->unk20 += arg1; temp->unk22 += arg2; } @@ -398,13 +397,12 @@ void func_800C50D8(s32 arg0) { if (arg0 <= 0 || arg0 >= 8) { return; } - temp = &D_8012A7E8[arg0]; // Issue with temp + temp = &D_8012A7E8[arg0]; temp->unk20 = 0; temp->unk22 = 0; } // Unused? -// This function is OK void func_800C510C(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { func_800C5168(arg0, (*D_8012A7E8)[arg0].unk0, (*D_8012A7E8)[arg0].unk2, arg1, arg2, arg3); } @@ -541,7 +539,6 @@ void func_800C580C(char** outString, s32 number) { } #endif -//GLOBAL_ASM("asm/non_matchings/unknown_0B8920/func_800C5AA0.s") void func_800C5AA0(Gfx **dlist, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { u32 temp_v0 = get_video_width_and_height_as_s32(); if (arg3 >= 0 && arg1 < (temp_v0 & 0xFFFF) && arg4 >= 0 && arg2 < (temp_v0 >> 16)) { @@ -612,13 +609,16 @@ void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgC } } +// I would guess that there is a file boundary right here. void func_800C6170(void) { D_800E3760 = allocate_from_main_pool_safe(0x2800, COLOR_TAG_BLACK); D_800E3764 = allocate_from_main_pool_safe(0x10, COLOR_TAG_BLACK); } -// Returns the little-endian value from a byte array. +/** + * Converts a little endian value to big endian. + */ s32 byteswap32(u8* arg0) { s32 value; value = *arg0++; @@ -628,20 +628,27 @@ s32 byteswap32(u8* arg0) { return value; } -s32 func_800C61DC(s32 arg0, s32 arg1) { - load_asset_to_address(arg0, D_800E3764, arg1, 8); +/** + * Returns the uncompressed size of a gzip compressed asset. + */ +s32 get_asset_uncompressed_size(s32 assetIndex, s32 assetOffset) { + load_asset_to_address(assetIndex, D_800E3764, assetOffset, 8); return byteswap32(D_800E3764); } s32 gzip_inflate_block(void); -u8* gzip_inflate(u8* arg0, u8* arg1) { - gzip_inflate_input = arg0 + 5; // The compression header is 5 bytes. - gzip_inflate_output = arg1; +/** + * Decompresses gzip data. + * Returns the pointer to the decompressed data. + */ +u8* gzip_inflate(u8* compressedInput, u8* decompressedOutput) { + gzip_inflate_input = compressedInput + 5; // The compression header is 5 bytes. + gzip_inflate_output = decompressedOutput; gzip_num_bits = 0; gzip_bit_buffer = 0; while(gzip_inflate_block() != 0) {} // Keep calling gzip_inflate_block() until it returns 0. - return arg1; + return decompressedOutput; } GLOBAL_ASM("asm/non_matchings/unknown_0B8920/gzip_huft_build.s")