From 05784992951a1fd2e53a33c6b05bdda1b5099d3c Mon Sep 17 00:00:00 2001 From: Banjo Kazooie Date: Sun, 7 Jul 2024 20:02:35 -0500 Subject: [PATCH] add non-matching functions --- asm/core1/code_1E820.s | 57 -------------------------- src/core2/code_98CB0.c | 91 +++++++++++++++++++++++------------------- src/core2/code_B9770.c | 71 ++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 98 deletions(-) delete mode 100644 asm/core1/code_1E820.s diff --git a/asm/core1/code_1E820.s b/asm/core1/code_1E820.s deleted file mode 100644 index 0b10453e..00000000 --- a/asm/core1/code_1E820.s +++ /dev/null @@ -1,57 +0,0 @@ -.include "macro.inc" - -/* assembler directives */ -.set noat /* allow manual use of $at */ -.set noreorder /* don't insert nops after branches */ -.set gp=64 /* allow use of 64-bit general purpose registers */ - -.section .text, "ax" - -glabel func_8025C240 -/* F37A70 8025C240 3C048027 */ lui $a0, %hi(D_80276E70) -/* F37A74 8025C244 DC846E70 */ ld $a0, %lo(D_80276E70)($a0) -/* F37A78 8025C248 3C018027 */ lui $at, %hi(D_80276E70) -/* F37A7C 8025C24C 000437FC */ dsll32 $a2, $a0, 31 -/* F37A80 8025C250 00042FF8 */ dsll $a1, $a0, 31 -/* F37A84 8025C254 000637FA */ dsrl $a2, $a2, 31 -/* F37A88 8025C258 0005283E */ dsrl32 $a1, $a1, 0 -/* F37A8C 8025C25C 0004233C */ dsll32 $a0, $a0, 12 -/* F37A90 8025C260 00C53025 */ or $a2, $a2, $a1 -/* F37A94 8025C264 0004203E */ dsrl32 $a0, $a0, 0 -/* F37A98 8025C268 00C43026 */ xor $a2, $a2, $a0 -/* F37A9C 8025C26C 0006253A */ dsrl $a0, $a2, 20 -/* F37AA0 8025C270 30840FFF */ andi $a0, $a0, 0xFFF -/* F37AA4 8025C274 00862026 */ xor $a0, $a0, $a2 -/* F37AA8 8025C278 0004103C */ dsll32 $v0, $a0, 0 -/* F37AAC 8025C27C FC246E70 */ sd $a0, %lo(D_80276E70)($at) -/* F37AB0 8025C280 03E00008 */ jr $ra -/* F37AB4 8025C284 0002103F */ dsra32 $v0, $v0, 0 -endlabel func_8025C240 - -glabel func_8025C288 -/* F37AB8 8025C288 64840001 */ daddiu $a0, $a0, 0x1 -/* F37ABC 8025C28C 3C018027 */ lui $at, %hi(D_80276E70) -/* F37AC0 8025C290 FC246E70 */ sd $a0, %lo(D_80276E70)($at) -/* F37AC4 8025C294 03E00008 */ jr $ra -/* F37AC8 8025C298 24040000 */ addiu $a0, $zero, 0x0 -endlabel func_8025C288 - -glabel func_8025C29C -/* F37ACC 8025C29C DC870000 */ ld $a3, 0x0($a0) -/* F37AD0 8025C2A0 000737FC */ dsll32 $a2, $a3, 31 -/* F37AD4 8025C2A4 00072FF8 */ dsll $a1, $a3, 31 -/* F37AD8 8025C2A8 000637FA */ dsrl $a2, $a2, 31 -/* F37ADC 8025C2AC 0005283E */ dsrl32 $a1, $a1, 0 -/* F37AE0 8025C2B0 00073B3C */ dsll32 $a3, $a3, 12 -/* F37AE4 8025C2B4 00C53025 */ or $a2, $a2, $a1 -/* F37AE8 8025C2B8 0007383E */ dsrl32 $a3, $a3, 0 -/* F37AEC 8025C2BC 00C73026 */ xor $a2, $a2, $a3 -/* F37AF0 8025C2C0 00063D3A */ dsrl $a3, $a2, 20 -/* F37AF4 8025C2C4 30E70FFF */ andi $a3, $a3, 0xFFF -/* F37AF8 8025C2C8 00E63826 */ xor $a3, $a3, $a2 -/* F37AFC 8025C2CC 0007103C */ dsll32 $v0, $a3, 0 -/* F37B00 8025C2D0 FC870000 */ sd $a3, 0x0($a0) -/* F37B04 8025C2D4 03E00008 */ jr $ra -/* F37B08 8025C2D8 0002103F */ dsra32 $v0, $v0, 0 -/* F37B0C 8025C2DC 00000000 */ nop -endlabel func_8025C29C diff --git a/src/core2/code_98CB0.c b/src/core2/code_98CB0.c index 1a8a0013..21e5e79f 100644 --- a/src/core2/code_98CB0.c +++ b/src/core2/code_98CB0.c @@ -41,49 +41,58 @@ u8 D_803831F8[0x21]; //copy of D_803831D0 /* .code */ +#ifndef NONMATCHING #pragma GLOBAL_ASM("asm/nonmatchings/core2/code_98CB0/func_8031FC40.s") -// void func_8031FC40(void) { -// s32 scrambled_ptr; -// s32 temp_a1; -// s32 temp_lo; -// s32 temp_t0; -// s32 temp_t1; -// s32 temp_t6; -// s32 temp_t9; -// s32 var_a0; -// s32 var_t3; -// u32 var_v0; -// u32 var_v1; -// u8 temp_a3; +#else +void func_8031FC40(void) { + s32 scrambled_ptr; + s32 *unscrambled_ptr; + s32 temp_a1; + s32 temp_lo; + s32 temp_t0; + s32 temp_t1; + s32 temp_a2; + s32 temp_t9; + s32 var_a0; + u8* b_ptr; + s32 var_t3; + u32 var_v0 = 0x17536C34; + u32 var_v1 = 0; + + //obsucre address + temp_t0 = (((s32)&D_803831A0.unk8 & 0xE0000000) >> 15) + + (((s32)&D_803831A0.unk8 & 0x1FC00000) >> 22) + + (((s32)&D_803831A0.unk8 & 0x00300000) << 10) + + (((s32)&D_803831A0.unk8 & 0x000F0000) << 7) + + (((s32)&D_803831A0.unk8 & 0x0000E000) << 14) + + (((s32)&D_803831A0.unk8 & 0x00001800) >> 4) + + (((s32)&D_803831A0.unk8 & 0x00000780) << 10) + + (((s32)&D_803831A0.unk8 & 0x00000060) << 4) + + (((s32)&D_803831A0.unk8 & 0x00000018) << 18) + + (((s32)&D_803831A0.unk8 & 0x00000007) << 11); + + //unobscure address + temp_t9 = (temp_t0 & 0x38000000) / (1 << 24); + temp_t1 = ((temp_t0 & 0x1E0600) << 0xB) | ((s32) (temp_t0 & 0x603800) / 8); + temp_a1 = (((temp_t0 & 0x1C07F) << 0xF) + ((u32) (temp_t0 & 0xC7800000) >> 0x11)) | (temp_t9 + ((s32) (temp_t0 & 0x180) >> 6)); \ + var_a0 = ((temp_a1 & 0x3FE000) << 7) + | (((temp_t1 >> 8) & 7) + ((temp_a1 << 0xA) & 0xFF800)) + | ((((u32) (temp_t1 & 0xF0000000) >> 0x15) + (temp_a1 & 0xE0000000)) ^ ((s32) ((temp_t1 /0x40) & 0xF000) >> 9)); + + //calculate checksum + temp_a1 = 0x25; + for(var_v1 = 0; var_v1 < temp_a1; var_v1++){ + b_ptr = (u8*)(var_a0 + var_v1); + var_v0 = (((var_v0 - *b_ptr) & 0x1F) << 0xF) ^ ((*b_ptr* 0x1B) + (var_v0 >> 0xB)); + } + + scrambled_ptr = (((s32) &D_803831A0 & 0x55555555) * 2) + ((u32) ((s32) &D_803831A0 & 0xAAAAAAAA) >> 1); + unscrambled_ptr = (((scrambled_ptr & 0x55555555) * 2) | ((u32) (scrambled_ptr & 0xAAAAAAAA) >> 1)); + *unscrambled_ptr = var_v0; + if(!var_a0); +} +#endif -// temp_t0 = (((s32) &D_803831A0.unk8 & 0xE0000000) >> 0xF) -// + (((s32) &D_803831A0.unk8 & 0x1FC00000) >> 0x16) -// + (((s32) &D_803831A0.unk8 & 0x300000) << 0xA) -// + (((s32) &D_803831A0.unk8 & 0xF0000) << 7) -// + (((s32) &D_803831A0.unk8 & 0xE000) << 0xE) -// + (((s32) &D_803831A0.unk8 & 0x1800) >> 4) -// + (((s32) &D_803831A0.unk8 & 0x780) << 0xA) -// + (((s32) &D_803831A0.unk8 & 0x60) << 4) -// + (((s32) &D_803831A0.unk8 & 0x18) << 0x12) -// + (((s32) &D_803831A0.unk8 & 7) << 0xB); -// temp_t9 = (temp_t0 & 0x38000000); -// var_v0 = 0x17536C34; -// var_t3 = temp_t9 >> 0x18; -// if (temp_t9 < 0) { -// var_t3 = (s32) (0xFFFFFF + temp_t9) >> 0x18; -// } -// temp_a1 = (((temp_t0 & 0x1C07F) << 0xF) + ((u32) (temp_t0 & 0xC7800000) >> 0x11)) | (var_t3 + ((s32) (temp_t0 & 0x180) >> 6)); -// temp_t1 = ((temp_t0 & 0x1E0600) << 0xB) | ((s32) (temp_t0 & 0x603800) >> 3); -// var_a0 = ((temp_a1 & 0x3FE000) << 7) -// | (((temp_t1 >> 8) & 7) + ((temp_a1 << 0xA) & 0xFF800)) -// | ((((u32) (temp_t1 & 0xF0000000) >> 0x15) + (temp_a1 & 0xE0000000)) ^ ((s32) ((temp_t1 >> 6) & 0xF000) >> 9)); -// for(var_v1 = 0; var_v1 < 0x25; var_v1++){ -// u8 byte = *(u8*)(var_a0 + var_v1); -// var_v0 = ((byte * 0x1B) + (var_v0 >> 0xB)) ^ (((var_v0 - byte) & 0x1F) << 0xF); -// } -// scrambled_ptr = (((s32) &D_803831A0 & 0x55555555) * 2) + ((u32) ((s32) &D_803831A0 & 0xAAAAAAAA) >> 1); -// *(s32 *)(((scrambled_ptr & 0x55555555) * 2) | ((u32) (scrambled_ptr & 0xAAAAAAAA) >> 1)) = var_v0; -// } u32 func_8031FE40(void) { diff --git a/src/core2/code_B9770.c b/src/core2/code_B9770.c index 7d550971..ccf3d0af 100644 --- a/src/core2/code_B9770.c +++ b/src/core2/code_B9770.c @@ -260,8 +260,79 @@ f32 glspline_catmull_rom_interpolate(f32 x, s32 knotCount, f32 *knotList) { return (((((sp24[2] * x) + sp24[1]) * x) + sp24[0]) * x) + (1.0*knotList[1]); } +#ifndef NONMATCHING void func_80340BE4(f32 arg0, s32 arg1, s32 arg2, s32 arg3, f32 * arg4, f32 arg5[3]); #pragma GLOBAL_ASM("asm/nonmatchings/core2/code_B9770/func_80340BE4.s") +#else +void func_80340BE4(f32 x, s32 length, s32 stride, s32 width, f32 *arg4, f32 *dst){ + s32 spD0; + s32 max_interval; + s32 i; + s32 var_a3; + f32 temp_f2; + f32 f3; + f32 f1; + f32 f2; + f32 sp94[3][3]; + + max_interval = length - 1; + if (length < 4) { + /* not enough points in spline to perform catmull-rom interpolation*/ + ml_vec3f_copy(sp94[0], arg4); + ml_vec3f_copy(sp94[1], arg4); + ml_vec3f_copy(sp94[2], arg4 + stride); + if (length - 1 == 1) { + ml_vec3f_copy(sp94[3], arg4 + stride); + } else { + ml_vec3f_copy(sp94[3], arg4 + 2*stride); + } + func_80340BE4(x, 4, 3, 3, sp94, dst); + return; + } + + temp_f2 = func_80340700(x, 0.0f, 1.0f) * max_interval; + var_a3 = (s32)temp_f2; + var_a3 = ((length - 1) < var_a3) ? (length - 1) : var_a3; + x = temp_f2 - (f32) var_a3; + if (0 == var_a3) { + /* desired point in interval[0,1], duplicate P0 to left */ + arg4 = arg4 + 0; + for(var_a3 = var_a3; var_a3 < width; var_a3++){ + f3 = -0.5*arg4[var_a3] + 1.5*arg4[var_a3] + -1.5*arg4[stride + var_a3] + 0.5*arg4[2*stride + var_a3]; + f1 = 1.0*arg4[var_a3] + -2.5*arg4[var_a3] + 2.0*arg4[stride + var_a3] + -0.5*arg4[2*stride + var_a3]; + f2 = -0.5*arg4[var_a3] + 0.0*arg4[var_a3] + 0.5*arg4[stride + var_a3] + 0.0*arg4[2*stride + var_a3]; + dst[var_a3] = ((((f3 * x) + f1)* x + f2) * x) + (1.0*arg4[var_a3]); + } + return; + } + spD0 = var_a3 - 1; + if (length == (var_a3 + 1)) { + arg4 = arg4 + spD0*stride; + for(var_a3 = 0; var_a3 < width; var_a3++){ + /* desired point in interval[n, inf], linearly interpret */ + dst[var_a3] = arg4[var_a3]; + } + } else if (length == (spD0 + 2)) { + /* desired point in interval[n-1, n], duplicate Pn to right */ + for(var_a3 = 0; var_a3 < width; var_a3++){ + f3 = -0.5*arg4[spD0*stride + var_a3] + 1.5*arg4[(spD0 + 1)* stride + var_a3] + -1.5*arg4[(spD0 + 2)* stride + var_a3] + 0.5*arg4[(spD0 + 2)* stride + var_a3]; + f1 = 1.0*arg4[spD0*stride + var_a3] + -2.5*arg4[(spD0 + 1)* stride + var_a3] + 2.0*arg4[(spD0 + 2)* stride + var_a3] + -0.5*arg4[(spD0 + 2)* stride + var_a3]; + f2 = -0.5*arg4[spD0*stride + var_a3] + 0.0*arg4[(spD0 + 1)* stride + var_a3] + 0.5*arg4[(spD0 + 2)* stride + var_a3] + 0.0*arg4[(spD0 + 2)* stride + var_a3]; + dst[var_a3] = ((((f3 * x) + f1)* x + f2) * x) + (1.0*arg4[((spD0 + 1) * stride) + var_a3]); + } + } else { + /* normal conditions */ + for(var_a3 = 0; var_a3 < width; var_a3++){ + f3 = -0.5*arg4[spD0*stride + var_a3] + 1.5*arg4[(spD0 + 1)*stride + var_a3] + -1.5*arg4[(spD0 + 2)* stride + var_a3] + 0.5*arg4[(spD0 + 3)* stride + var_a3]; + f1 = 1.0*arg4[spD0*stride + var_a3] + -2.5*arg4[(spD0 + 1)*stride + var_a3] + 2.0*arg4[(spD0 + 2)* stride + var_a3] + -0.5*arg4[(spD0 + 3)* stride + var_a3]; + f2 = -0.5*arg4[spD0*stride + var_a3] + 0.0*arg4[(spD0 + 1)*stride + var_a3] + 0.5*arg4[(spD0 + 2)* stride + var_a3] + 0.0*arg4[(spD0 + 3)* stride + var_a3]; + // var_f8 = + dst[var_a3] = ((((f3 * x) + f1)* x + f2) * x) + (1.0*arg4[(spD0 + 1)*stride + var_a3]); + } + } + +} +#endif void func_80341180(f32 arg0, s32 arg1, s32 arg2, f32 arg3[3], f32 arg4[3]){ func_80340BE4(arg0, arg1, arg2, arg2, arg3, arg4);