diff --git a/asm/non_matchings/asset_loading/load_asset_section_from_rom.s b/asm/non_matchings/asset_loading/load_compressed_asset_from_rom.s similarity index 97% rename from asm/non_matchings/asset_loading/load_asset_section_from_rom.s rename to asm/non_matchings/asset_loading/load_compressed_asset_from_rom.s index fed9dfc3..8f14ac04 100644 --- a/asm/non_matchings/asset_loading/load_asset_section_from_rom.s +++ b/asm/non_matchings/asset_loading/load_compressed_asset_from_rom.s @@ -1,4 +1,4 @@ -glabel func_80076CF0 +glabel load_compressed_asset_from_rom /* 0778F0 80076CF0 27BDFFC8 */ addiu $sp, $sp, -0x38 /* 0778F4 80076CF4 3C028012 */ lui $v0, %hi(gAssetsLookupTable) # $v0, 0x8012 /* 0778F8 80076CF8 8C424290 */ lw $v0, %lo(gAssetsLookupTable)($v0) @@ -60,7 +60,7 @@ glabel func_80076CF0 /* 0779D0 80076DD0 AFA70024 */ sw $a3, 0x24($sp) /* 0779D4 80076DD4 8FA50024 */ lw $a1, 0x24($sp) /* 0779D8 80076DD8 8FA4001C */ lw $a0, 0x1c($sp) -/* 0779DC 80076DDC 0C031886 */ jal func_800C6218 +/* 0779DC 80076DDC 0C031886 */ jal gzip_inflate /* 0779E0 80076DE0 00000000 */ nop /* 0779E4 80076DE4 8FA20024 */ lw $v0, 0x24($sp) /* 0779E8 80076DE8 00000000 */ nop diff --git a/asm/non_matchings/unknown_00BC20/func_8000C8F8.s b/asm/non_matchings/unknown_00BC20/func_8000C8F8.s index f3d8dec3..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) @@ -120,7 +120,7 @@ glabel func_8000C8F8 /* 00D6B4 8000CAB4 02003025 */ move $a2, $s0 /* 00D6B8 8000CAB8 8FA40034 */ lw $a0, 0x34($sp) /* 00D6BC 8000CABC 8FA50048 */ lw $a1, 0x48($sp) -/* 00D6C0 8000CAC0 0C031886 */ jal func_800C6218 +/* 00D6C0 8000CAC0 0C031886 */ jal gzip_inflate /* 00D6C4 8000CAC4 00000000 */ nop /* 00D6C8 8000CAC8 8FA4003C */ lw $a0, 0x3c($sp) /* 00D6CC 8000CACC 0C01C450 */ jal free_from_memory_pool diff --git a/asm/non_matchings/unknown_0255E0/func_8002C0C4.s b/asm/non_matchings/unknown_0255E0/func_8002C0C4.s index 236dd4b9..a173bb6e 100644 --- a/asm/non_matchings/unknown_0255E0/func_8002C0C4.s +++ b/asm/non_matchings/unknown_0255E0/func_8002C0C4.s @@ -84,7 +84,7 @@ glabel func_8002C0C4 /* 02CDE4 8002C1E4 0C01DB9A */ jal load_asset_to_address /* 02CDE8 8002C1E8 02603825 */ move $a3, $s3 /* 02CDEC 8002C1EC 8E250000 */ lw $a1, ($s1) -/* 02CDF0 8002C1F0 0C031886 */ jal func_800C6218 +/* 02CDF0 8002C1F0 0C031886 */ jal gzip_inflate /* 02CDF4 8002C1F4 02002025 */ move $a0, $s0 /* 02CDF8 8002C1F8 8E840000 */ lw $a0, ($s4) /* 02CDFC 8002C1FC 0C01C450 */ jal free_from_memory_pool 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 cd971863..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 @@ -94,7 +94,7 @@ glabel func_8005F99C /* 0606EC 8005FAEC 0C01DB9A */ jal load_asset_to_address /* 0606F0 8005FAF0 00008825 */ move $s1, $zero /* 0606F4 8005FAF4 8FA40030 */ lw $a0, 0x30($sp) -/* 0606F8 8005FAF8 0C031886 */ jal func_800C6218 +/* 0606F8 8005FAF8 0C031886 */ jal gzip_inflate /* 0606FC 8005FAFC 02402825 */ move $a1, $s2 /* 060700 8005FB00 8E4D0000 */ lw $t5, ($s2) /* 060704 8005FB04 8E4F0004 */ lw $t7, 4($s2) @@ -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 d632fa6f..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 @@ -107,7 +107,7 @@ glabel func_80061A00 /* 062784 80061B84 02002025 */ move $a0, $s0 /* 062788 80061B88 03314021 */ addu $t0, $t9, $s1 /* 06278C 80061B8C 8D050000 */ lw $a1, ($t0) -/* 062790 80061B90 0C031886 */ jal func_800C6218 +/* 062790 80061B90 0C031886 */ jal gzip_inflate /* 062794 80061B94 00000000 */ nop /* 062798 80061B98 8EA90044 */ lw $t1, 0x44($s5) /* 06279C 80061B9C 26940004 */ addiu $s4, $s4, 4 diff --git a/asm/non_matchings/unknown_07B870/func_8007AE74.s b/asm/non_matchings/unknown_07B870/func_8007AE74.s index eb5b5813..d1fded8f 100644 --- a/asm/non_matchings/unknown_07B870/func_8007AE74.s +++ b/asm/non_matchings/unknown_07B870/func_8007AE74.s @@ -137,7 +137,7 @@ glabel func_8007AE74 /* 07BC68 8007B068 01603825 */ move $a3, $t3 /* 07BC6C 8007B06C 8FA40034 */ lw $a0, 0x34($sp) /* 07BC70 8007B070 02602825 */ move $a1, $s3 -/* 07BC74 8007B074 0C031886 */ jal func_800C6218 +/* 07BC74 8007B074 0C031886 */ jal gzip_inflate /* 07BC78 8007B078 24840020 */ addiu $a0, $a0, 0x20 /* 07BC7C 8007B07C 8FAD003C */ lw $t5, 0x3c($sp) /* 07BC80 8007B080 00000000 */ nop 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/asset_loading.c b/src/asset_loading.c index ac36aad3..6a194238 100644 --- a/src/asset_loading.c +++ b/src/asset_loading.c @@ -63,8 +63,9 @@ s32 *load_asset_section_from_rom(u32 assetIndex) { } #ifdef NON_MATCHING +// Unused. // This has regalloc & stack issues. -u8 *func_80076CF0(u32 assetIndex, s32 arg1) { +u8 *load_compressed_asset_from_rom(u32 assetIndex, s32 arg1) { s32 size; s32 sp2C; s32 start; @@ -96,11 +97,11 @@ u8 *func_80076CF0(u32 assetIndex, s32 arg1) { } temp_a1 = (temp_v0_3 + sp2C) - size; dmacopy(temp_a0, temp_a1, size); - func_800C6218(temp_a1, temp_v0_3); + gzip_inflate(temp_a1, temp_v0_3); return temp_v0_3; } #else -GLOBAL_ASM("asm/non_matchings/asset_loading/load_asset_section_from_rom.s") +GLOBAL_ASM("asm/non_matchings/asset_loading/load_compressed_asset_from_rom.s") #endif /** diff --git a/src/camera.c b/src/camera.c index a7a30b11..3f735388 100644 --- a/src/camera.c +++ b/src/camera.c @@ -279,7 +279,9 @@ s32 func_80066220(void) { return D_80120CE4; } -void func_80066230(s32 arg0, s32 arg1) { +void func_80066CDC(Gfx **dlist, s32 arg1); + +void func_80066230(Gfx **dlist, s32 arg1) { unk80120AC0 *someStruct; s16 sp2A; s16 sp28; @@ -307,7 +309,7 @@ void func_80066230(s32 arg0, s32 arg1) { someStruct->y_position = 0.0f; someStruct->z_position = 0.0f; func_8001D5E0(0.0f, 0.0f, -1.0f); - func_80066CDC(arg0, arg1); + func_80066CDC(dlist, arg1); someStruct->unk38 = sp24; someStruct->unk0 = sp2A; someStruct->unk2 = sp28; @@ -549,7 +551,153 @@ void func_80066C80(s32 *arg0, s32 *arg1, s32 *arg2, s32 *arg3) { } +#ifdef NON_MATCHING + +// Still a work-in-progress but it doesn't seem to cause any problems, +// which is why it is labeled under NON_MATCHING + +#define SCISSOR_INTERLACE G_SC_NON_INTERLACE + +void func_80066CDC(Gfx **dlist, s32 arg1) { + u32 sp58; + u32 sp54; + u32 sp4C; + u32 temp_a2; + u32 temp_a3; + u32 temp_t0; + u32 temp_t1; + u32 widthAndHeight; + u32 temp_v0_6; + u32 phi_a1; + u32 phi_t3; + u32 phi_t5; + u32 phi_t4; + + if (func_8000E184() && !D_80120CE0) { + D_80120CE4 = 1; + } + widthAndHeight = get_video_width_and_height_as_s32(); + temp_t0 = widthAndHeight >> 16; + temp_a3 = temp_t0 >> 1; + if (gScreenViewports[D_80120CE4].flags & 1) { + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, + gScreenViewports[D_80120CE4].unk20, + gScreenViewports[D_80120CE4].unk24, + gScreenViewports[D_80120CE4].unk28, + gScreenViewports[D_80120CE4].unk2C + ) + func_80068158(dlist, 0, 0, 0, 0); + if (arg1 != 0) { + func_80067D3C(dlist, arg1); + } + return; + } + temp_t1 = widthAndHeight & 0xFFFF; + if (D_80120CE0 == 2) { + D_80120CE0 = 3; + } + temp_a2 = temp_t1 >> 1; + sp54 = temp_a2; + sp58 = temp_a3; + if (osTvType == 0) { + sp58 = 0x91; + } + + switch(D_80120CE0) { + case 0: + phi_t3 = sp58; + if (osTvType == 0) { + phi_t3 = sp58 - 0x12; + } + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, temp_t1, temp_t0) + sp4C = temp_a2; + break; + case 1: + if (D_80120CE4 == 0) { + temp_v0_6 = temp_t0 >> 2; + phi_t3 = temp_v0_6; + if (osTvType == 0) { + phi_t3 = temp_v0_6 - 0xC; + } + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, temp_t1, (temp_a3 - (temp_t0 >> 7))) + } else { + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, (temp_a3 + (temp_t0 >> 7)), temp_t1, (temp_t0 - (temp_t0 >> 7))) + phi_t3 = temp_a3 + (temp_t0 >> 2); + } + sp4C = temp_a2; + break; + case 2: + if (D_80120CE4 == 0) { + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, 0, temp_a2 - (temp_t1 >> 8), temp_t0) + phi_a1 = temp_t1 >> 2; + } else { + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, temp_a2 + (temp_t1 >> 8), 0, temp_t1 - (temp_t1 >> 8), temp_t0) + phi_a1 = temp_a2 + (temp_t1 >> 2); + } + sp4C = phi_a1; + phi_t3 = sp58; + break; + case 3: + sp58 = sp58 >> 1; + sp54 = temp_a2 >> 1; + switch(D_80120CE4) { + case 0: + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0.0f, 0.0f, + (temp_a2 - (temp_t1 >> 8)), (temp_a3 - (temp_t0 >> 7))) + phi_t5 = 0; + phi_t4 = 0; + case 1: + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, (temp_a2 + (temp_t1 >> 8)), 0, + ((temp_a2 * 2) - (temp_t1 >> 8)), (temp_a3 - (temp_t0 >> 7))) + phi_t5 = 0; + phi_t4 = temp_a2; + break; + case 2: + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, 0, temp_a3 + (temp_t0 >> 7), + temp_a2 - (temp_t1 >> 8), (temp_a3 * 2) - (temp_t0 >> 7)) + phi_t5 = temp_a3; + phi_t4 = 0; + break; + case 3: + gDPSetScissor((*dlist)++, SCISSOR_INTERLACE, temp_a2 + (temp_t1 >> 8), temp_a3 + (temp_t0 >> 7), + (temp_a2 * 2) - (temp_t1 >> 8), (temp_a3 * 2) - (temp_t0 >> 7)) + phi_t5 = temp_a3; + phi_t4 = temp_a2; + break; + default: + phi_t5 = 0; + phi_t4 = 0; + break; + } + phi_t3 = phi_t5 + sp58; + sp4C = phi_t4 + sp54; + if (osTvType == 0) { + phi_t3 -= 6; + if (D_80120CE4 < 2) { + phi_t3 -= 0x14; + } + } + break; + default: + //phi_t3 = sp50; + phi_t3 = sp54; + break; + } + + if (osTvType == 0) { + sp4C -= 4; + } + func_80068158(dlist, sp54, sp58, sp4C, phi_t3); + if (arg1 != 0) { + func_80067D3C(dlist, arg1); + } +} + +#else GLOBAL_ASM("asm/non_matchings/camera/func_80066CDC.s") +#endif + + GLOBAL_ASM("asm/non_matchings/camera/func_80067A3C.s") GLOBAL_ASM("asm/non_matchings/camera/func_80067D3C.s") 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 46e5cec3..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,25 +27,126 @@ 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") + +#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; + 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); + } + } +} +#else GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_8005FF40.s") -GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_80060058.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") GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_80060910.s") GLOBAL_ASM("asm/non_matchings/unknown_05F690/func_80060AC8.s") @@ -53,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 28a6e28f..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* func_800C6218(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") diff --git a/src/video.c b/src/video.c index 4100d0f0..8e5a268b 100644 --- a/src/video.c +++ b/src/video.c @@ -125,6 +125,8 @@ s32 get_video_width_and_height_as_s32(void) { return (gVideoFbHeights[gVideoCurrFbIndex] << 16) | gVideoFbWidths[gVideoCurrFbIndex]; } +void memory_copy(u8 *src, u8 *dst, s32 numBytes); + void init_vi_settings(void) { s32 viModeTableIndex; OSViMode *tvViMode; @@ -307,7 +309,6 @@ void swap_framebuffers(void) { #ifdef NON_MATCHING // regalloc issues -// They made their own (worse) version of memcpy, despite the fact that they already had bcopy? void memory_copy(u8 *src, u8 *dst, s32 numBytes) { s32 i; for(i = 0; i < numBytes; i++){