From 2efae9d4a69a1d5e382163cec34f1d148f37fb60 Mon Sep 17 00:00:00 2001 From: David Benepe Date: Sat, 7 Aug 2021 23:46:05 -0500 Subject: [PATCH] Decompiled 6 functions from unknown_032760 --- .../unknown_032760/func_80031F88.s | 117 ------ .../unknown_032760/func_80033A14.s | 139 ------- include/structs.h | 30 +- src/unknown_032760.c | 340 ++++++++++++++++-- src/unknown_032760.h | 83 ++++- src/unknown_0348C0.c | 6 - 6 files changed, 418 insertions(+), 297 deletions(-) delete mode 100644 asm/non_matchings/unknown_032760/func_80033A14.s diff --git a/asm/non_matchings/unknown_032760/func_80031F88.s b/asm/non_matchings/unknown_032760/func_80031F88.s index 9c1a7bef..8552f765 100644 --- a/asm/non_matchings/unknown_032760/func_80031F88.s +++ b/asm/non_matchings/unknown_032760/func_80031F88.s @@ -170,120 +170,3 @@ glabel func_80031F88 /* 032E08 80032208 03E00008 */ jr $ra /* 032E0C 8003220C 00C01025 */ move $v0, $a2 -/* 032E10 80032210 03E00008 */ jr $ra -/* 032E14 80032214 A0800004 */ sb $zero, 4($a0) - -/* 032E18 80032218 240E0001 */ li $t6, 1 -/* 032E1C 8003221C 03E00008 */ jr $ra -/* 032E20 80032220 A08E0004 */ sb $t6, 4($a0) - -/* 032E24 80032224 908E0004 */ lbu $t6, 4($a0) -/* 032E28 80032228 24010001 */ li $at, 1 -/* 032E2C 8003222C 15C10003 */ bne $t6, $at, .L8003223C -/* 032E30 80032230 240F0001 */ li $t7, 1 -/* 032E34 80032234 03E00008 */ jr $ra -/* 032E38 80032238 A0800004 */ sb $zero, 4($a0) - -.L8003223C: -/* 032E3C 8003223C A08F0004 */ sb $t7, 4($a0) -/* 032E40 80032240 03E00008 */ jr $ra -/* 032E44 80032244 00000000 */ nop - -/* 032E48 80032248 18C00012 */ blez $a2, .L80032294 -/* 032E4C 8003224C 00000000 */ nop -/* 032E50 80032250 8C8F001C */ lw $t7, 0x1c($a0) -/* 032E54 80032254 00057400 */ sll $t6, $a1, 0x10 -/* 032E58 80032258 01CFC023 */ subu $t8, $t6, $t7 -/* 032E5C 8003225C 0306001A */ div $zero, $t8, $a2 -/* 032E60 80032260 A486003C */ sh $a2, 0x3c($a0) -/* 032E64 80032264 14C00002 */ bnez $a2, .L80032270 -/* 032E68 80032268 00000000 */ nop -/* 032E6C 8003226C 0007000D */ break 7 -.L80032270: -/* 032E70 80032270 2401FFFF */ li $at, -1 -/* 032E74 80032274 14C10004 */ bne $a2, $at, .L80032288 -/* 032E78 80032278 3C018000 */ lui $at, 0x8000 -/* 032E7C 8003227C 17010002 */ bne $t8, $at, .L80032288 -/* 032E80 80032280 00000000 */ nop -/* 032E84 80032284 0006000D */ break 6 -.L80032288: -/* 032E88 80032288 0000C812 */ mflo $t9 -/* 032E8C 8003228C AC99002C */ sw $t9, 0x2c($a0) -/* 032E90 80032290 00000000 */ nop -.L80032294: -/* 032E94 80032294 8FA20010 */ lw $v0, 0x10($sp) -/* 032E98 80032298 00000000 */ nop -/* 032E9C 8003229C 18400012 */ blez $v0, .L800322E8 -/* 032EA0 800322A0 00000000 */ nop -/* 032EA4 800322A4 8C890020 */ lw $t1, 0x20($a0) -/* 032EA8 800322A8 00074400 */ sll $t0, $a3, 0x10 -/* 032EAC 800322AC 01095023 */ subu $t2, $t0, $t1 -/* 032EB0 800322B0 0142001A */ div $zero, $t2, $v0 -/* 032EB4 800322B4 A482003E */ sh $v0, 0x3e($a0) -/* 032EB8 800322B8 14400002 */ bnez $v0, .L800322C4 -/* 032EBC 800322BC 00000000 */ nop -/* 032EC0 800322C0 0007000D */ break 7 -.L800322C4: -/* 032EC4 800322C4 2401FFFF */ li $at, -1 -/* 032EC8 800322C8 14410004 */ bne $v0, $at, .L800322DC -/* 032ECC 800322CC 3C018000 */ lui $at, 0x8000 -/* 032ED0 800322D0 15410002 */ bne $t2, $at, .L800322DC -/* 032ED4 800322D4 00000000 */ nop -/* 032ED8 800322D8 0006000D */ break 6 -.L800322DC: -/* 032EDC 800322DC 00005812 */ mflo $t3 -/* 032EE0 800322E0 AC8B0030 */ sw $t3, 0x30($a0) -/* 032EE4 800322E4 00000000 */ nop -.L800322E8: -/* 032EE8 800322E8 8FA20018 */ lw $v0, 0x18($sp) -/* 032EEC 800322EC 8FAC0014 */ lw $t4, 0x14($sp) -/* 032EF0 800322F0 18400012 */ blez $v0, .L8003233C -/* 032EF4 800322F4 00000000 */ nop -/* 032EF8 800322F8 8C8E0024 */ lw $t6, 0x24($a0) -/* 032EFC 800322FC 000C6C00 */ sll $t5, $t4, 0x10 -/* 032F00 80032300 01AE7823 */ subu $t7, $t5, $t6 -/* 032F04 80032304 01E2001A */ div $zero, $t7, $v0 -/* 032F08 80032308 A4820040 */ sh $v0, 0x40($a0) -/* 032F0C 8003230C 14400002 */ bnez $v0, .L80032318 -/* 032F10 80032310 00000000 */ nop -/* 032F14 80032314 0007000D */ break 7 -.L80032318: -/* 032F18 80032318 2401FFFF */ li $at, -1 -/* 032F1C 8003231C 14410004 */ bne $v0, $at, .L80032330 -/* 032F20 80032320 3C018000 */ lui $at, 0x8000 -/* 032F24 80032324 15E10002 */ bne $t7, $at, .L80032330 -/* 032F28 80032328 00000000 */ nop -/* 032F2C 8003232C 0006000D */ break 6 -.L80032330: -/* 032F30 80032330 0000C012 */ mflo $t8 -/* 032F34 80032334 AC980034 */ sw $t8, 0x34($a0) -/* 032F38 80032338 00000000 */ nop -.L8003233C: -/* 032F3C 8003233C 03E00008 */ jr $ra -/* 032F40 80032340 00000000 */ nop - -/* 032F44 80032344 18C00012 */ blez $a2, .L80032390 -/* 032F48 80032348 00000000 */ nop -/* 032F4C 8003234C 8C8F0028 */ lw $t7, 0x28($a0) -/* 032F50 80032350 00057400 */ sll $t6, $a1, 0x10 -/* 032F54 80032354 01CFC023 */ subu $t8, $t6, $t7 -/* 032F58 80032358 0306001A */ div $zero, $t8, $a2 -/* 032F5C 8003235C A4860042 */ sh $a2, 0x42($a0) -/* 032F60 80032360 14C00002 */ bnez $a2, .L8003236C -/* 032F64 80032364 00000000 */ nop -/* 032F68 80032368 0007000D */ break 7 -.L8003236C: -/* 032F6C 8003236C 2401FFFF */ li $at, -1 -/* 032F70 80032370 14C10004 */ bne $a2, $at, .L80032384 -/* 032F74 80032374 3C018000 */ lui $at, 0x8000 -/* 032F78 80032378 17010002 */ bne $t8, $at, .L80032384 -/* 032F7C 8003237C 00000000 */ nop -/* 032F80 80032380 0006000D */ break 6 -.L80032384: -/* 032F84 80032384 0000C812 */ mflo $t9 -/* 032F88 80032388 AC990038 */ sw $t9, 0x38($a0) -/* 032F8C 8003238C 00000000 */ nop -.L80032390: -/* 032F90 80032390 03E00008 */ jr $ra -/* 032F94 80032394 00000000 */ nop - diff --git a/asm/non_matchings/unknown_032760/func_80033A14.s b/asm/non_matchings/unknown_032760/func_80033A14.s deleted file mode 100644 index ee3e0fac..00000000 --- a/asm/non_matchings/unknown_032760/func_80033A14.s +++ /dev/null @@ -1,139 +0,0 @@ -.late_rodata -glabel jpt_800E5F80 -.word L80033A70, L80033AA4, L80033AE4, L80033B48, L80033BB4 - -.text -glabel func_80033A14 -/* 034614 80033A14 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 034618 80033A18 AFBF0024 */ sw $ra, 0x24($sp) -/* 03461C 80033A1C AFB00020 */ sw $s0, 0x20($sp) -/* 034620 80033A20 E7B50018 */ swc1 $f21, 0x18($sp) -/* 034624 80033A24 E7B4001C */ swc1 $f20, 0x1c($sp) -/* 034628 80033A28 8C8E0028 */ lw $t6, 0x28($a0) -/* 03462C 80033A2C 908F0003 */ lbu $t7, 3($a0) -/* 034630 80033A30 448E2000 */ mtc1 $t6, $f4 -/* 034634 80033A34 3C014780 */ li $at, 0x47800000 # 65536.000000 -/* 034638 80033A38 44814000 */ mtc1 $at, $f8 -/* 03463C 80033A3C 468021A0 */ cvt.s.w $f6, $f4 -/* 034640 80033A40 25F8FFFF */ addiu $t8, $t7, -1 -/* 034644 80033A44 2F010005 */ sltiu $at, $t8, 5 -/* 034648 80033A48 00808025 */ move $s0, $a0 -/* 03464C 80033A4C 10200067 */ beqz $at, .L80033BEC -/* 034650 80033A50 46083503 */ div.s $f20, $f6, $f8 -/* 034654 80033A54 0018C080 */ sll $t8, $t8, 2 -/* 034658 80033A58 3C01800E */ lui $at, %hi(jpt_800E5F80) # $at, 0x800e -/* 03465C 80033A5C 00380821 */ addu $at, $at, $t8 -/* 034660 80033A60 8C385F80 */ lw $t8, %lo(jpt_800E5F80)($at) -/* 034664 80033A64 00000000 */ nop -/* 034668 80033A68 03000008 */ jr $t8 -/* 03466C 80033A6C 00000000 */ nop -glabel L80033A70 -/* 034670 80033A70 3C018012 */ lui $at, %hi(D_8011D4C0) # $at, 0x8012 -/* 034674 80033A74 C42CD4C0 */ lwc1 $f12, %lo(D_8011D4C0)($at) -/* 034678 80033A78 0C0326B4 */ jal sqrtf -/* 03467C 80033A7C 00000000 */ nop -/* 034680 80033A80 C610006C */ lwc1 $f16, 0x6c($s0) -/* 034684 80033A84 3C013F80 */ li $at, 0x3F800000 # 1.000000 -/* 034688 80033A88 46100482 */ mul.s $f18, $f0, $f16 -/* 03468C 80033A8C 44815000 */ mtc1 $at, $f10 -/* 034690 80033A90 00000000 */ nop -/* 034694 80033A94 46125081 */ sub.s $f2, $f10, $f18 -/* 034698 80033A98 4602A502 */ mul.s $f20, $f20, $f2 -/* 03469C 80033A9C 10000054 */ b .L80033BF0 -/* 0346A0 80033AA0 8FBF0024 */ lw $ra, 0x24($sp) -glabel L80033AA4 -/* 0346A4 80033AA4 3C018012 */ lui $at, %hi(D_8011D4C0) # $at, 0x8012 -/* 0346A8 80033AA8 C42CD4C0 */ lwc1 $f12, %lo(D_8011D4C0)($at) -/* 0346AC 80033AAC 0C0326B4 */ jal sqrtf -/* 0346B0 80033AB0 00000000 */ nop -/* 0346B4 80033AB4 C604006C */ lwc1 $f4, 0x6c($s0) -/* 0346B8 80033AB8 00000000 */ nop -/* 0346BC 80033ABC 46040302 */ mul.s $f12, $f0, $f4 -/* 0346C0 80033AC0 0C0326B4 */ jal sqrtf -/* 0346C4 80033AC4 00000000 */ nop -/* 0346C8 80033AC8 3C013F80 */ li $at, 0x3F800000 # 1.000000 -/* 0346CC 80033ACC 44813000 */ mtc1 $at, $f6 -/* 0346D0 80033AD0 00000000 */ nop -/* 0346D4 80033AD4 46003201 */ sub.s $f8, $f6, $f0 -/* 0346D8 80033AD8 4608A502 */ mul.s $f20, $f20, $f8 -/* 0346DC 80033ADC 10000044 */ b .L80033BF0 -/* 0346E0 80033AE0 8FBF0024 */ lw $ra, 0x24($sp) -glabel L80033AE4 -/* 0346E4 80033AE4 3C018012 */ lui $at, %hi(D_8011D4C0) # $at, 0x8012 -/* 0346E8 80033AE8 C42CD4C0 */ lwc1 $f12, %lo(D_8011D4C0)($at) -/* 0346EC 80033AEC 0C0326B4 */ jal sqrtf -/* 0346F0 80033AF0 00000000 */ nop -/* 0346F4 80033AF4 C610006C */ lwc1 $f16, 0x6c($s0) -/* 0346F8 80033AF8 3C014680 */ li $at, 0x46800000 # 16384.000000 -/* 0346FC 80033AFC 46100282 */ mul.s $f10, $f0, $f16 -/* 034700 80033B00 44819000 */ mtc1 $at, $f18 -/* 034704 80033B04 00000000 */ nop -/* 034708 80033B08 46125102 */ mul.s $f4, $f10, $f18 -/* 03470C 80033B0C 4459F800 */ cfc1 $t9, $31 -/* 034710 80033B10 00000000 */ nop -/* 034714 80033B14 37210003 */ ori $at, $t9, 3 -/* 034718 80033B18 38210002 */ xori $at, $at, 2 -/* 03471C 80033B1C 44C1F800 */ ctc1 $at, $31 -/* 034720 80033B20 00000000 */ nop -/* 034724 80033B24 460021A4 */ cvt.w.s $f6, $f4 -/* 034728 80033B28 44043000 */ mfc1 $a0, $f6 -/* 03472C 80033B2C 44D9F800 */ ctc1 $t9, $31 -/* 034730 80033B30 00044400 */ sll $t0, $a0, 0x10 -/* 034734 80033B34 0C01C1FE */ jal func_800707F8 -/* 034738 80033B38 00082403 */ sra $a0, $t0, 0x10 -/* 03473C 80033B3C 4600A502 */ mul.s $f20, $f20, $f0 -/* 034740 80033B40 1000002B */ b .L80033BF0 -/* 034744 80033B44 8FBF0024 */ lw $ra, 0x24($sp) -glabel L80033B48 -/* 034748 80033B48 3C018012 */ lui $at, %hi(D_8011D4C0) # $at, 0x8012 -/* 03474C 80033B4C C42CD4C0 */ lwc1 $f12, %lo(D_8011D4C0)($at) -/* 034750 80033B50 0C0326B4 */ jal sqrtf -/* 034754 80033B54 00000000 */ nop -/* 034758 80033B58 C608006C */ lwc1 $f8, 0x6c($s0) -/* 03475C 80033B5C 3C014680 */ li $at, 0x46800000 # 16384.000000 -/* 034760 80033B60 46080402 */ mul.s $f16, $f0, $f8 -/* 034764 80033B64 44815000 */ mtc1 $at, $f10 -/* 034768 80033B68 00000000 */ nop -/* 03476C 80033B6C 460A8482 */ mul.s $f18, $f16, $f10 -/* 034770 80033B70 444AF800 */ cfc1 $t2, $31 -/* 034774 80033B74 00000000 */ nop -/* 034778 80033B78 35410003 */ ori $at, $t2, 3 -/* 03477C 80033B7C 38210002 */ xori $at, $at, 2 -/* 034780 80033B80 44C1F800 */ ctc1 $at, $31 -/* 034784 80033B84 00000000 */ nop -/* 034788 80033B88 46009124 */ cvt.w.s $f4, $f18 -/* 03478C 80033B8C 44042000 */ mfc1 $a0, $f4 -/* 034790 80033B90 44CAF800 */ ctc1 $t2, $31 -/* 034794 80033B94 00045C00 */ sll $t3, $a0, 0x10 -/* 034798 80033B98 0C01C1FE */ jal func_800707F8 -/* 03479C 80033B9C 000B2403 */ sra $a0, $t3, 0x10 -/* 0347A0 80033BA0 46000182 */ mul.s $f6, $f0, $f0 -/* 0347A4 80033BA4 00000000 */ nop -/* 0347A8 80033BA8 4606A502 */ mul.s $f20, $f20, $f6 -/* 0347AC 80033BAC 1000000F */ b .L80033BEC -/* 0347B0 80033BB0 00000000 */ nop -glabel L80033BB4 -/* 0347B4 80033BB4 3C018012 */ lui $at, %hi(D_8011D4C0) # $at, 0x8012 -/* 0347B8 80033BB8 C42CD4C0 */ lwc1 $f12, %lo(D_8011D4C0)($at) -/* 0347BC 80033BBC 0C0326B4 */ jal sqrtf -/* 0347C0 80033BC0 00000000 */ nop -/* 0347C4 80033BC4 C610006C */ lwc1 $f16, 0x6c($s0) -/* 0347C8 80033BC8 3C013F80 */ li $at, 0x3F800000 # 1.000000 -/* 0347CC 80033BCC 46100282 */ mul.s $f10, $f0, $f16 -/* 0347D0 80033BD0 44814000 */ mtc1 $at, $f8 -/* 0347D4 80033BD4 00000000 */ nop -/* 0347D8 80033BD8 460A4081 */ sub.s $f2, $f8, $f10 -/* 0347DC 80033BDC 46021082 */ mul.s $f2, $f2, $f2 -/* 0347E0 80033BE0 00000000 */ nop -/* 0347E4 80033BE4 4602A502 */ mul.s $f20, $f20, $f2 -/* 0347E8 80033BE8 00000000 */ nop -.L80033BEC: -/* 0347EC 80033BEC 8FBF0024 */ lw $ra, 0x24($sp) -.L80033BF0: -/* 0347F0 80033BF0 4600A006 */ mov.s $f0, $f20 -/* 0347F4 80033BF4 C7B4001C */ lwc1 $f20, 0x1c($sp) -/* 0347F8 80033BF8 C7B50018 */ lwc1 $f21, 0x18($sp) -/* 0347FC 80033BFC 8FB00020 */ lw $s0, 0x20($sp) -/* 034800 80033C00 03E00008 */ jr $ra -/* 034804 80033C04 27BD0028 */ addiu $sp, $sp, 0x28 - diff --git a/include/structs.h b/include/structs.h index c8baaee8..bd83a040 100644 --- a/include/structs.h +++ b/include/structs.h @@ -379,6 +379,12 @@ typedef struct LevelModel { /* 0x38 */ u32 minimapColor; } LevelModel; +/* Size: 8 bytes. */ +typedef struct LevelObjectEntryCommon { + u16 id; // Upper 9 bits = Object ID to load, Lower 7 bits = Total entry length. + s16 x, y, z; // Position in level +} LevelObjectEntryCommon; + typedef struct Object_3C { u8 pad0[0x8]; s8 unk8; @@ -391,7 +397,9 @@ typedef struct Object_40 { f32 unk4; f32 unk8; f32 unkC; - u8 pad10[0x43]; + u8 pad10[0x2D]; + u8 unk3D; + u8 pad3E[0x15]; s8 unk53; s8 unk54; s8 unk55; //size of array pointed by Object->unk68 @@ -413,6 +421,24 @@ typedef struct Object_4C { s8 unk17; } Object_4C; +typedef struct Object_54 { + s32 unk0; + u8 unk4; + u8 unk5; + u8 unk6; + u8 unk7; + s16 unk8; + s16 unkA; + s16 unkC; + u8 unkE; + u8 unkF; + u8 unk10; + u8 unk11; + s16 unk12; + s16 unk14; + s16 unk16; +} Object_54; + typedef struct Object_5C { u8 pad0[0x100]; void *unk100; @@ -541,7 +567,7 @@ typedef struct Object { /* 0x004A */ s16 unk4A; /* 0x004C */ Object_4C *unk4C; //player + 0x318 /* 0x0050 */ void *unk50; //player + 0x2F4 - /* 0x0054 */ void *unk54; //player + 0x2C0 + /* 0x0054 */ Object_54 *unk54; //player + 0x2C0 /* 0x0058 */ void *unk58; //player + 0x304 /* 0x005C */ Object_5C *unk5C; diff --git a/src/unknown_032760.c b/src/unknown_032760.c index 5a32d736..73ccca02 100644 --- a/src/unknown_032760.c +++ b/src/unknown_032760.c @@ -3,17 +3,18 @@ #include "unknown_032760.h" +#include "memory.h" #include "types.h" #include "macros.h" /************ .data ************/ -TextureHeader **D_800DC950 = NULL; -s32 D_800DC954 = 0; +unk800DC950 **D_800DC950 = NULL; +unk800DC954 *D_800DC954 = NULL; s32 D_800DC958 = 0; s32 D_800DC95C = 0; -s32 D_800DC960 = 0; -s32 D_800DC964 = 0; +unk800DC960 *D_800DC960 = NULL; +unk800DC964 *D_800DC964 = NULL; s32 D_800DC968 = 0; // Currently unknown, might be a different type. /*******************************/ @@ -27,22 +28,90 @@ f32 D_8011D4CC; /*******************************/ +f32 func_800707F8(s16); +f32 sqrtf(f32); + +void func_800337E4(void); +f32 func_80033A14(unk800DC950 *arg0); +f32 func_80033C08(unk800DC950 *arg0); + void func_80031B60(void) { - if (D_800DC950 != 0) { + if (D_800DC950 != NULL) { free_from_memory_pool(D_800DC950); - D_800DC950 = 0; - D_800DC954 = 0; - D_800DC960 = 0; - D_800DC964 = 0; + D_800DC950 = NULL; + D_800DC954 = NULL; + D_800DC960 = NULL; + D_800DC964 = NULL; } D_800DC95C = 0; D_800DC958 = 0; } +#ifdef NON_MATCHING +// Regalloc issues +void func_80031BB8(s32 count) { + s32 i; + func_80031B60(); + D_800DC958 = count; + D_800DC950 = allocate_from_main_pool_safe(D_800DC958 * (sizeof(s32*) + sizeof(unk800DC954) + sizeof(unk800DC960) + sizeof(unk800DC964)), COLOR_TAG_MAGENTA); + D_800DC954 = &D_800DC950[D_800DC958]; + D_800DC960 = &D_800DC954[D_800DC958]; + D_800DC964 = &D_800DC960[D_800DC958]; + for (i = 0; i < D_800DC958; i++) { + D_800DC950[i] = &D_800DC954[i].unk0; + } +} +#else GLOBAL_ASM("asm/non_matchings/unknown_032760/func_80031BB8.s") +#endif + GLOBAL_ASM("asm/non_matchings/unknown_032760/func_80031CAC.s") + GLOBAL_ASM("asm/non_matchings/unknown_032760/func_80031F88.s") +// Unused. +void func_80032210(unk800DC950 *arg0) { + arg0->unk4 = 0; +} + +// Unused. +void func_80032218(unk800DC950 *arg0) { + arg0->unk4 = 1; +} + +// Unused. +void func_80032224(unk800DC950 *arg0) { + if (arg0->unk4 == 1) { + arg0->unk4 = 0; + return; + } + arg0->unk4 = 1; +} + +// Unused. +void func_80032248(unk800DC950 *arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6) { + if (arg2 > 0) { + arg0->unk3C = arg2; + arg0->unk2C = ((arg1 << 0x10) - arg0->unk1C) / arg2; + } + if (arg4 > 0) { + arg0->unk3E = arg4; + arg0->unk30 = ((arg3 << 0x10) - arg0->unk20) / arg4; + } + if (arg6 > 0) { + arg0->unk34 = ((arg5 << 0x10) - arg0->unk24) / arg6; + arg0->unk40 = arg6; + } +} + +// Unused. +void func_80032344(unk800DC950 *arg0, s32 arg1, s32 arg2) { + if (arg2 > 0) { + arg0->unk42 = arg2; + arg0->unk38 = ((arg1 << 0x10) - arg0->unk28) / arg2; + } +} + void func_80032398(s32 arg0) { s32 i; for (i = 0; i < D_800DC95C; i++) { @@ -52,20 +121,20 @@ void func_80032398(s32 arg0) { GLOBAL_ASM("asm/non_matchings/unknown_032760/func_80032424.s") -void func_80032BAC(TextureHeader *texInput) { - TextureHeader *tex = NULL; +void func_80032BAC(unk800DC950 *arg0) { + unk800DC950 *entry = NULL; s32 i; - for(i = 0; (i < D_800DC95C) && (tex == NULL); i++) { - if (texInput == D_800DC950[i]) { - tex = D_800DC950[i]; + for(i = 0; (i < D_800DC95C) && (entry == NULL); i++) { + if (arg0 == D_800DC950[i]) { + entry = D_800DC950[i]; } } - if (tex != NULL) { + if (entry != NULL) { D_800DC95C--; for (i--; i < D_800DC95C; i++) { D_800DC950[i] = D_800DC950[i + 1]; } - D_800DC950[D_800DC95C] = tex; + D_800DC950[D_800DC95C] = entry; } } @@ -73,20 +142,239 @@ s32 func_80032C6C(void) { return D_800DC95C; } + +#ifdef NON_MATCHING + +// Close to matching. Should be functionally equivalent. +void func_80032C7C(Object *object) { + s16 sp82; + s16 sp80; + s16 sp7E; + s32 i; // sp68 + s32 sp64; + f32 f20; + f32 temp; + s16 phi_a0, phi_a1; + unk800DC950 *entry; + + if (object->descriptor_ptr->unk3D == 0) { + switch(object->descriptor_ptr->unk53) { // Model type + case 0: // 3D Model + sp64 = 2; + break; + case 1: // 2D Billboard + case 2: // Vehicle Part + case 3: + sp64 = 4; + break; + default: + sp64 = 0; + break; + } + + sp82 = object->x_position; + sp80 = object->y_position; + sp7E = object->z_position; + D_800DC968 = 0; + for (i = 0; i < D_800DC95C; i++) { + entry = D_800DC950[i]; + if ((entry->unk2 & sp64) && (entry->unk4 == 1) && (sp82 >= entry->unk50) && + (entry->unk56 >= sp82) && (sp80 >= entry->unk52) && (entry->unk58 >= sp80) && + (sp7E >= entry->unk54) && (entry->unk5A >= sp7E)) { + if (entry->unk0 == 0) { + if (entry->unk28 >= 0x10000) { + D_800DC960[D_800DC968].unk0 = entry->unk0; + D_800DC960[D_800DC968].unk4 = entry->unk1C >> 0x10; + D_800DC960[D_800DC968].unk8 = entry->unk20 >> 0x10; + D_800DC960[D_800DC968].unkC = entry->unk24 >> 0x10; + D_800DC960[D_800DC968].unk10 = entry->unk28 >> 0x10; + D_800DC968 = D_800DC968 + 1; + } + } else { + D_8011D4C4 = entry->unk10 - object->x_position; + D_8011D4C8 = entry->unk14 - object->y_position; + D_8011D4CC = entry->unk18 - object->z_position; + if (entry->unk0 == 2) { + D_8011D4C8 = 0.0f; + } + D_8011D4C0 = (D_8011D4C4 * D_8011D4C4) + (D_8011D4C8 * D_8011D4C8) + (D_8011D4CC * D_8011D4CC); + if (D_8011D4C0 < entry->unk68) { + if (entry->unk1 == 2) { + f20 = func_80033C08(entry); + } else { + f20 = 1.0f; + } + if (f20 > 0.0f) { + f20 *= func_80033A14(entry); + if (f20 > 0.0f) { + if (object->descriptor_ptr->unk71 != 0) { + if (D_8011D4C0 > 0.0f) { + temp = 1.0f / sqrtf(D_8011D4C0); + D_8011D4C4 *= temp; + D_8011D4C8 *= temp; + D_8011D4CC *= temp; + } else { + D_8011D4C4 = 0.0f; + D_8011D4C8 = 0.0f; + D_8011D4CC = -1.0f; + } + D_800DC964[D_800DC968].unk0 = D_8011D4C4; + D_800DC964[D_800DC968].unk4 = D_8011D4C8; + D_800DC964[D_800DC968].unk8 = D_8011D4CC; + } + D_800DC960[D_800DC968].unk0 = entry; + D_800DC960[D_800DC968].unk4 = entry->unk1C >> 0x10; + D_800DC960[D_800DC968].unk8 = entry->unk20 >> 0x10; + D_800DC960[D_800DC968].unkC = entry->unk24 >> 0x10; + D_800DC960[D_800DC968].unk10 = (u8)f20; + D_800DC968++; + } + } + } + } + } + } + + if (object->descriptor_ptr->unk71 != 0) { + if (D_800DC968 == 0) { + object->unk54->unk7 = 0; + object->unk54->unk11 = 0; + } else if (D_800DC968 == 1) { + object->unk54->unk4 = D_800DC960[0].unk4; + object->unk54->unk5 = D_800DC960[0].unk8; + object->unk54->unk6 = D_800DC960[0].unkC; + object->unk54->unk7 = D_800DC960[0].unk10; + object->unk54->unk11 = 0; + object->unk54->unk8 = D_800DC964[0].unk0 * 8192.0f; + object->unk54->unkA = D_800DC964[0].unk4 * 8192.0f; + object->unk54->unkC = D_800DC964[0].unk8 * 8192.0f; + } else { + if (D_800DC960[1].unk10 < D_800DC960[0].unk10) { + phi_a0 = 0; + phi_a1 = 1; + } else { + phi_a0 = 1; + phi_a1 = 0; + } + for(i = 2; i < D_800DC968; i++) { + if (D_800DC960[phi_a1].unk10 < D_800DC960[i + 2].unk10) { + if (D_800DC960[phi_a0].unk10 < D_800DC960[i + 2].unk10) { + phi_a1 = phi_a0; + phi_a0 = i; + } else { + phi_a1 = i; + } + } + } + object->unk54->unk4 = D_800DC960[phi_a0].unk4; + object->unk54->unk5 = D_800DC960[phi_a0].unk8; + object->unk54->unk6 = D_800DC960[phi_a0].unkC; + object->unk54->unk7 = D_800DC960[phi_a0].unk10; + object->unk54->unk8 = D_800DC964[phi_a0].unk0 * 8192.0f; + object->unk54->unkA = D_800DC964[phi_a0].unk4 * 8192.0f; + object->unk54->unkC = D_800DC964[phi_a0].unk8 * 8192.0f; + object->unk54->unkE = D_800DC960[phi_a1].unk4; + object->unk54->unkF = D_800DC960[phi_a1].unk8; + object->unk54->unk10 = D_800DC960[phi_a1].unkC; + object->unk54->unk11 = D_800DC960[phi_a1].unk10; + object->unk54->unk12 = D_800DC964[phi_a1].unk0 * 8192.0f; + object->unk54->unk14 = D_800DC964[phi_a1].unk4 * 8192.0f; + object->unk54->unk16 = D_800DC964[phi_a1].unk8 * 8192.0f; + } + } else { + if (D_800DC968 > 0) { + if (D_800DC968 >= 2) { + func_800337E4(); + } + object->unk54->unk4 = D_800DC960[0].unk4; + object->unk54->unk5 = D_800DC960[0].unk8; + object->unk54->unk6 = D_800DC960[0].unkC; + object->unk54->unk7 = D_800DC960[0].unk10; + } else { + object->unk54->unk4 = 0xFF; + object->unk54->unk5 = 0xFF; + object->unk54->unk6 = 0xFF; + object->unk54->unk7 = 0; + } + } + } +} +#else GLOBAL_ASM("asm/non_matchings/unknown_032760/func_80032C7C.s") +#endif + +#ifdef NON_MATCHING + +// Has regalloc issues +void func_800337E4(void) { + s32 i; + s32 temp; + + for(i = 1; i < D_800DC968; i++) { + if (D_800DC960[i].unk10 >= 2) { + if (D_800DC960[0].unk10 >= D_800DC960[i].unk10) { + temp = (D_800DC960[i].unk10 << 0x10); + temp /= D_800DC960[0].unk10; + D_800DC960[0].unk4 = D_800DC960[0].unk4 + ((D_800DC960[i].unk4 * temp) >> 0x10);; + D_800DC960[0].unk8 = D_800DC960[0].unk8 + ((D_800DC960[i].unk8 * temp) >> 0x10); + D_800DC960[0].unkC = D_800DC960[0].unkC + ((D_800DC960[i].unkC * temp) >> 0x10); + } else { + temp = (D_800DC960[0].unk10 << 0x10); + temp /= D_800DC960[i].unk10; + D_800DC960[0].unk4 = D_800DC960[i].unk4 + ((D_800DC960[0].unk4 * temp) >> 0x10); + D_800DC960[0].unk8 = D_800DC960[i].unk8 + ((D_800DC960[0].unk8 * temp) >> 0x10); + D_800DC960[0].unkC = D_800DC960[i].unkC + ((D_800DC960[0].unkC * temp) >> 0x10); + D_800DC960[0].unk10 = D_800DC960[i].unk10; + } + if (D_800DC960[0].unk4 >= 0x100) { + D_800DC960[0].unk4 = 0xFF; + } + if (D_800DC960[0].unk8 >= 0x100) { + D_800DC960[0].unk8 = 0xFF; + } + if (D_800DC960[0].unkC >= 0x100) { + D_800DC960[0].unkC = 0xFF; + } + } + } +} +#else GLOBAL_ASM("asm/non_matchings/unknown_032760/func_800337E4.s") -GLOBAL_ASM("asm/non_matchings/unknown_032760/func_80033A14.s") +#endif -typedef struct unk80033C08 { - u8 pad0[0x7C]; - f32 unk7C; - f32 unk80; - f32 unk84; -} unk80033C08; +f32 func_80033A14(unk800DC950 *arg0) { + f32 out; + f32 temp; + + out = arg0->unk28 / 65536.0f; + switch (arg0->unk3) { + case 1: + temp = 1.0f - (sqrtf(D_8011D4C0) * arg0->unk6C); + out *= temp; + break; + case 2: + temp = 1.0f - sqrtf(sqrtf(D_8011D4C0) * arg0->unk6C); + out *= temp; + break; + case 3: + temp = func_800707F8(sqrtf(D_8011D4C0) * arg0->unk6C * 16384.0f); + out *= temp; + break; + case 4: + temp = func_800707F8(sqrtf(D_8011D4C0) * arg0->unk6C * 16384.0f); + temp *= temp; + out *= temp; + break; + case 5: + temp = 1.0f - (sqrtf(D_8011D4C0) * arg0->unk6C); + temp *= temp; + out *= temp; + break; + } + return out; +} -f32 sqrtf(f32); - -f32 func_80033C08(unk80033C08 *arg0) { +f32 func_80033C08(unk800DC950 *arg0) { f32 temp_f2; f32 phi_f12; diff --git a/src/unknown_032760.h b/src/unknown_032760.h index 3ca8a4b7..bedf8787 100644 --- a/src/unknown_032760.h +++ b/src/unknown_032760.h @@ -4,12 +4,81 @@ #include "types.h" #include "structs.h" -extern TextureHeader **D_800DC950; -extern s32 D_800DC954; -extern s32 D_800DC958; -extern s32 D_800DC95C; -extern s32 D_800DC960; -extern s32 D_800DC964; -extern s32 D_800DC968; +typedef struct unk800DC950 { + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; + u8 unk4; + u8 unk5; + s16 unk6; + s16 unk8; + s16 unkA; + s32 unkC; + f32 unk10; + f32 unk14; + f32 unk18; + s32 unk1C; + s32 unk20; + s32 unk24; + s32 unk28; + s32 unk2C; + s32 unk30; + s32 unk34; + s32 unk38; + s16 unk3C; + s16 unk3E; + s16 unk40; + s16 unk42; + s32 unk44; + s16 unk48; + s16 unk4A; + s16 unk4C; + s16 unk4E; + s16 unk50; + s16 unk52; + s16 unk54; + s16 unk56; + s16 unk58; + s16 unk5A; + f32 unk5C; + f32 unk60; + f32 unk64; + f32 unk68; + f32 unk6C; + s16 unk70; + s16 unk72; + s16 unk74; + s16 unk76; + s16 unk78; + s16 unk7A; + f32 unk7C; + f32 unk80; + f32 unk84; +} unk800DC950; + +/* Size: 0x88 bytes */ +typedef struct unk800DC954 { + unk800DC950 unk0; + u8 unk20[0x68]; +} unk800DC954; + +/* Size: 0x14 bytes */ +typedef struct unk800DC960 { + s32 unk0; + s32 unk4; + s32 unk8; + s32 unkC; + s32 unk10; +} unk800DC960; + +/* Size: 12 bytes */ +typedef struct unk800DC964 { + f32 unk0; + f32 unk4; + f32 unk8; +} unk800DC964; + +extern unk800DC950 **D_800DC950; #endif \ No newline at end of file diff --git a/src/unknown_0348C0.c b/src/unknown_0348C0.c index 0c5d5c75..62d97790 100644 --- a/src/unknown_0348C0.c +++ b/src/unknown_0348C0.c @@ -119,12 +119,6 @@ s16 D_8011D4E2; /******************************/ -/* Size: 8 bytes. */ -typedef struct LevelObjectEntryCommon { - u16 id; // Upper 9 bits = Object ID to load, Lower 7 bits = Total entry length. - s16 x, y, z; // Position in level -} LevelObjectEntryCommon; - extern u32 osTvType; Settings* get_settings();