From 7de563a3340379435f3fda3361123a76f42d46e0 Mon Sep 17 00:00:00 2001 From: Banjo Kazooie Date: Fri, 29 Jul 2022 20:26:57 -0500 Subject: [PATCH] core2/code_9C170.c done --- progress/progress_core2.svg | 6 +- progress/progress_total.svg | 6 +- src/core2/code_9C170.c | 238 +++++++++++++++++++++++++++++------- subyaml/core2.us.v10.yaml | 4 +- 4 files changed, 200 insertions(+), 54 deletions(-) diff --git a/progress/progress_core2.svg b/progress/progress_core2.svg index 77482a67..40d7f44e 100644 --- a/progress/progress_core2.svg +++ b/progress/progress_core2.svg @@ -9,7 +9,7 @@ - + @@ -17,7 +17,7 @@ core2 - 74.8489% - 74.8489% + 75.2473% + 75.2473% \ No newline at end of file diff --git a/progress/progress_total.svg b/progress/progress_total.svg index d1a306bf..09d1c91e 100644 --- a/progress/progress_total.svg +++ b/progress/progress_total.svg @@ -9,7 +9,7 @@ - + @@ -17,7 +17,7 @@ Banjo-Kazooie (us.v10) - 80.3613% - 80.3613% + 80.5899% + 80.5899% \ No newline at end of file diff --git a/src/core2/code_9C170.c b/src/core2/code_9C170.c index 20e69077..7754950f 100644 --- a/src/core2/code_9C170.c +++ b/src/core2/code_9C170.c @@ -53,12 +53,23 @@ extern f64 D_80378D90; extern f32 D_80378D98; extern f64 D_80378DA0; extern f32 D_80378DA8; +extern f64 D_80378DB0; +extern f64 D_80378DB8; +extern f64 D_80378DC0; extern f64 D_80378DC8; extern f64 D_80378DD0; extern f32 D_80378DD8; extern f32 D_80378DDC; extern f32 D_80378DE0; +// [f64] 1e-06 +// [f32] 0.005f +// [f64] 2e-05 +// [f32] 0.0001 +// [f64] 0.01 0.1 +// 1e-07 0.0333333 +// 0.0001 [f32] 1e+08 0.01 +// 0.01 /* .code */ void func_80323240(struct56s *arg0, f32 arg1, f32 arg2[3]){ if(arg1 < 0.0f) @@ -76,7 +87,7 @@ f32 func_803232AC(f32 *arg0, f32 arg1, f32 arg2, s32 arg3, f32 arg4) { f32 var_f20; var_f22 = 0.0f; - if ((arg2 - arg1) < D_80378D90) { + if ((arg2 - arg1) < 1e-6) { return 0.0f; } var_f20 = arg1; @@ -93,10 +104,6 @@ f32 func_803232AC(f32 *arg0, f32 arg1, f32 arg2, s32 arg3, f32 arg4) { } -#ifndef NONMATCHING //requires .rodata defined -f32 func_803233F8(struct56s *arg0); -#pragma GLOBAL_ASM("asm/nonmatchings/core2/code_9C170/func_803233F8.s") -#else f32 func_803233F8(struct56s *arg0) { f32 temp_f0; f32 temp_f26; @@ -105,7 +112,7 @@ f32 func_803233F8(struct56s *arg0) { s32 temp_s0; f32 *var_a0; - var_f22 = D_80378D98; + var_f22 = 0.005f; var_f24 = 0.0f; temp_s0 = arg0->unk0; var_a0 = arg0->unk8; @@ -114,11 +121,10 @@ f32 func_803233F8(struct56s *arg0) { var_f24 = func_803232AC(var_a0, 0.0f, 1.0f, temp_s0, var_f22); var_f22 *= 0.75; } - while((D_80378DA0 < var_f22) && (mlAbsF(var_f24 - temp_f26) > 0.5)); + while((2e-05 < var_f22) && (mlAbsF(var_f24 - temp_f26) > 0.5)); arg0->unk4 = (s32) var_f24; return var_f24; } -#endif f32 func_803234FC(struct56s *arg0, f32 arg1, f32 arg2) { s32 var_a3; @@ -126,7 +132,7 @@ f32 func_803234FC(struct56s *arg0, f32 arg1, f32 arg2) { var_a3 = arg0->unk0; var_a0 = arg0->unk8; - return func_803232AC(var_a0, arg1, arg2, var_a3, D_80378DA8); + return func_803232AC(var_a0, arg1, arg2, var_a3, 0.0001f); } f32 func_80323540(struct56s *arg0, f32 arg1, f32 arg2, f32 arg3) { @@ -140,16 +146,141 @@ f32 func_80323540(struct56s *arg0, f32 arg1, f32 arg2, f32 arg3) { return func_803232AC(var_a0, arg1, arg2, var_a3, temp_f8); } +f32 func_8032358C(struct56s *arg0, f32 arg1[3]) { + s32 count; + s32 i; + f32 (*i_ptr)[3]; + f32 (*end)[3]; -f32 func_8032358C(struct56s *arg0, f32[3]); -#pragma GLOBAL_ASM("asm/nonmatchings/core2/code_9C170/func_8032358C.s") + count = arg0->unk0; + i_ptr = arg0->unk8[0]; + end = i_ptr + count; + for( i = 0; i_ptr != end; i_ptr++, i++){ + if( ((*i_ptr)[0] == arg1[0]) && ((*i_ptr)[1] == arg1[1]) && ((*i_ptr)[2] == arg1[2])) { + return (f32) (i) / (f32) (count - 1); + } + + } + return -1.0f; +} -f32 func_803237E8(struct56s *arg0); -#pragma GLOBAL_ASM("asm/nonmatchings/core2/code_9C170/func_803237E8.s") +f32 func_803237E8(struct56s *arg0) { + s32 count; + s32 i; + f32 (*i_ptr)[3]; + f32 (*end)[3]; -f32 func_80323A48(f32 *, s32, f32, f32, f32); -#pragma GLOBAL_ASM("asm/nonmatchings/core2/code_9C170/func_80323A48.s") + count = arg0->unk0; + i_ptr = arg0->unk8[0]; + end = i_ptr + count - 1; + for( i = 0; i_ptr != end; i_ptr++, i++){ + if( ((*i_ptr)[0] == (*end)[0]) && ((*i_ptr)[1] == (*end)[1]) && ((*i_ptr)[2] == (*end)[2])) { + return (f32) (i) / (f32) (count - 1); + } + + } + return 1.0f; +} +f32 func_80323A48(f32 arg0[3], s32 arg1, f32 arg2, f32 arg3, f32 arg4) { + f32 spF4[3]; + f32 spE8[3]; + f32 spDC[3]; + f32 spD0[3]; + f32 spC4[3]; + f64 spB8; + f64 var_f22; + f64 var_f24; + f64 var_f26; + f64 var_f28; + s32 sp94; + + + if (arg3 == 0.0f) { + return arg2; + } + + var_f26 = 0.0; + var_f28 = 0.01; + if (arg3 < 0.0f) { + arg3 = -arg3; + var_f28 = -var_f28; + } + + spB8 = (f64) arg2; + func_80341180(spB8, arg1, 3, arg0, &spF4); + // sp78 = (f64) arg3; + + do{ + var_f24 = spB8 + var_f28; + if (var_f28 > 0.0) { + if (var_f24 >= 1.0) { + if (arg4 == 1.0) { + var_f24 = arg4; + func_80341180(var_f24, arg1, 3, arg0, spDC); + var_f22 = var_f26 + func_80258708(spF4, spDC); + } else { + var_f24 += arg4; + var_f24 = var_f24 - (s32)var_f24; + func_80341180(1.0f, arg1, 3, arg0, spDC); + ml_vec3f_diff_copy(spD0, spDC, spF4); + func_80341180(arg4, arg1, 3, arg0, &spE8); + func_80341180(var_f24, arg1, 3, arg0, &spDC); + ml_vec3f_diff_copy(spC4, spDC, spE8); + func_80258CDC(spD0, spC4); + var_f22 = var_f26 + gu_sqrtf(spD0[0]*spD0[0] + spD0[1]*spD0[1] + spD0[2]*spD0[2]); + } + } else { + func_80341180(var_f24, arg1, 3, arg0, spDC); + var_f22 = var_f26 + func_80258708(spF4, spDC); + } + } else { + if (arg4 == 1.0) { + if (var_f24 < 0.0) { + var_f24 = 0; + func_80341180(var_f24, arg1, 3, arg0, &spDC); + var_f22 = var_f26 + func_80258708(&spF4, &spDC); + } else { + func_80341180(var_f24, arg1, 3, arg0, &spDC); + var_f22 = var_f26 + func_80258708(&spF4, &spDC); + } + } else if (var_f24 < arg4) { + var_f24 -= arg4; + var_f24 = (var_f24 - (s32)var_f24); + var_f24 += 1.0; + func_80341180(arg4, arg1, 3, arg0, &spDC); + ml_vec3f_diff_copy(&spD0, &spDC, &spF4); + func_80341180(1.0f, arg1, 3, arg0, &spE8); + func_80341180((f32) var_f24, arg1, 3, arg0, &spDC); + ml_vec3f_diff_copy(&spC4, &spDC, &spE8); + func_80258CDC(&spD0, &spC4); + var_f22 = var_f26 + gu_sqrtf(spD0[0]*spD0[0] + spD0[1]*spD0[1] + spD0[2]*spD0[2]); + } else { + func_80341180(var_f24, arg1, 3, arg0, &spDC); + var_f22 = var_f26 + func_80258708(&spF4, &spDC); + } + } + + sp94 = (mlAbsF(arg3 - var_f22) < 0.1); + if ((var_f22 < arg3) || sp94) { + var_f26 = var_f22; + spB8 = var_f24; + ml_vec3f_copy(&spF4, &spDC); + if (arg4 == 1.0) { + if (var_f28 > 0.0) { + if (spB8 == arg4) { + break; + } + } else if (spB8 == 0.0) { + break; + } + } + } else { + var_f28 *= 0.5; + } + } while(!sp94 && (1e-7 < mlAbsF(var_f28))); + return (f32) spB8; +} f32 func_80323F74(struct56s * arg0, f32 arg1, f32 arg2) { s32 sp2C; @@ -180,7 +311,7 @@ f32 func_80324078(struct56s *arg0, f32 arg1, f32 arg2) { s32 sp24; sp24 = arg0->unk0; - return func_80323A48(arg0->unk8, sp24, arg1, (f32) (arg2 * D_80378DC8), func_803237E8(arg0)); + return func_80323A48(arg0->unk8, sp24, arg1, (f32) (arg2 * (1.0/30.0)), func_803237E8(arg0)); } f32 func_803240E0(struct56s *arg0, f32 arg1, f32 arg2, bool *arg3) { @@ -199,32 +330,28 @@ f32 func_803240E0(struct56s *arg0, f32 arg1, f32 arg2, bool *arg3) { return temp_f2; } - -#ifndef NONMATCHING -#pragma GLOBAL_ASM("asm/nonmatchings/core2/code_9C170/func_8032417C.s") -#else -extern f64 D_80378DD0; -extern f32 func_80323A48(f32 *, s32, f32, f32, f32); void func_8032417C(struct56s *arg0, f32 arg1, f32 arg2[3], f32 arg3[3]) { s32 sp64; + f32 *sp60; + f32 var_f0; f32 sp50[3]; f32 sp44[3]; - f32 var_f0; - if ((arg1 + D_80378DD0) >= 1.0) { - arg1 -= D_80378DD0; - } sp64 = arg0->unk0; - func_80341180(arg1, sp64, 3, arg0->unk8, sp50); - var_f0 = func_80323A48(arg0->unk8, sp64, arg1, 5.0f, func_803237E8(arg0)); - func_80341180(var_f0, sp64, 3, arg0->unk8, sp44); + sp60 = arg0->unk8; + + if ((arg1 + 0.0001) >= 1.0) { + arg1 -= 0.0001; + } + func_80341180(arg1, sp64, 3, sp60, sp50); + var_f0 = func_80323A48(sp60, sp64, arg1, 5.0f, func_803237E8(arg0)); + func_80341180(var_f0, sp64, 3, sp60, sp44); ml_vec3f_diff_copy(arg2, sp44, sp50); ml_vec3f_normalize(arg2); func_8025727C(sp44[0], sp44[1], sp44[2], sp50[0], sp50[1], sp50[2], &arg3[0], &arg3[1]); arg3[0] = mlNormalizeAngle(-arg3[0]); arg3[2] = 0.0f; } -#endif f32 func_8032429C(struct56s *this, f32 arg1[3], f32 min, f32 max, f32 step){ f32 sp74[3]; @@ -237,7 +364,7 @@ f32 func_8032429C(struct56s *this, f32 arg1[3], f32 min, f32 max, f32 step){ min = max_f(0.0f, min); max = min_f(1.0f, max); - f24 = D_80378DD8; + f24 = 1e+8f; f28 = min; f20 = min; do{ @@ -260,33 +387,52 @@ f32 func_8032429C(struct56s *this, f32 arg1[3], f32 min, f32 max, f32 step){ return f28; } -#ifndef NONMATCHING //needs .rodata defined ? -#pragma GLOBAL_ASM("asm/nonmatchings/core2/code_9C170/func_803243D0.s") -#else f32 func_803243D0(struct56s *arg0, f32 arg1[3]){ - f32 sp64[3]; - f32 sp58[3]; f32 tmp_f0; f32 tmp_f20; + f32 tmp_f22; + f32 tmp_f24; + f32 sp64[3]; + f32 sp58[3]; + tmp_f0 = func_8032358C(arg0, arg1); if(0.0f <= tmp_f0){ return tmp_f0; } else{ - tmp_f20 = D_80378DE0; - tmp_f0 = func_8032429C(arg0, arg1, 0.0f, 1.0f, D_80378DDC); - tmp_f0 = func_8032429C(arg0, arg1, tmp_f0 - tmp_f20, tmp_f0 + tmp_f20, tmp_f20 = (tmp_f20/10.0)*2); - tmp_f0 = func_8032429C(arg0, arg1, tmp_f0 - tmp_f20, tmp_f0 + tmp_f20, tmp_f20 = (tmp_f20/10.0)*2); - tmp_f0 = func_8032429C(arg0, arg1, tmp_f0 - tmp_f20, tmp_f0 + tmp_f20, tmp_f20 = (tmp_f20/10.0)*2); - tmp_f0 = func_8032429C(arg0, arg1, tmp_f0 - tmp_f20, tmp_f0 + tmp_f20, tmp_f20 = (tmp_f20/10.0)*2); - tmp_f0 = func_8032429C(arg0, arg1, tmp_f0 - tmp_f20, tmp_f0 + tmp_f20, tmp_f20 = (tmp_f20/10.0)*2); - tmp_f20 = tmp_f0; + tmp_f20 = 0.01f; + tmp_f0 = func_8032429C(arg0, arg1, 0.0f, 1.0f, tmp_f20); + + tmp_f22 = tmp_f0 - tmp_f20; + tmp_f24 = tmp_f0 + tmp_f20; + tmp_f20 = (tmp_f20/10.0)*2; + tmp_f0 = func_8032429C(arg0, arg1, tmp_f22, tmp_f24, tmp_f20); + + tmp_f22 = tmp_f0 - tmp_f20; + tmp_f24 = tmp_f0 + tmp_f20; + tmp_f20 = (tmp_f20/10.0)*2; + tmp_f0 = func_8032429C(arg0, arg1, tmp_f22, tmp_f24, tmp_f20); + + tmp_f22 = tmp_f0 - tmp_f20; + tmp_f24 = tmp_f0 + tmp_f20; + tmp_f20 = (tmp_f20/10.0)*2; + tmp_f0 = func_8032429C(arg0, arg1, tmp_f22, tmp_f24, tmp_f20); + + tmp_f22 = tmp_f0 - tmp_f20; + tmp_f24 = tmp_f0 + tmp_f20; + tmp_f20 = (tmp_f20/10.0)*2; + tmp_f0 = func_8032429C(arg0, arg1, tmp_f22, tmp_f24, tmp_f20); + + tmp_f22 = tmp_f0 - tmp_f20; + tmp_f24 = tmp_f0 + tmp_f20; + tmp_f20 = (tmp_f20/10.0)*2; + tmp_f0 = func_8032429C(arg0, arg1, tmp_f22, tmp_f24, tmp_f20); + func_80323240(arg0, tmp_f0, sp64); func_80323240(arg0, 1.0f, sp58); if(ml_vec3f_distance_squared(arg1, sp64) < ml_vec3f_distance_squared(arg1, sp58)){ - return tmp_f20; + return tmp_f0; } return 1.0f; } } -#endif diff --git a/subyaml/core2.us.v10.yaml b/subyaml/core2.us.v10.yaml index f9294863..25656203 100644 --- a/subyaml/core2.us.v10.yaml +++ b/subyaml/core2.us.v10.yaml @@ -306,7 +306,7 @@ segments: - [0x9B180, c, code_9B180] #DONE - [0x9B650, c, code_9B650] - [0x9B990, c, code_9B990] #DONE - - [0x9C170, c, code_9C170] + - [0x9C170, c, code_9C170] #DONE - [0x9D640, c, code_9D640] #DONE - [0x9D760, c, code_9D760] #DONE - [0x9D860, c, timedfuncqueue] #DONE @@ -743,7 +743,7 @@ segments: - [0xF1A00, bin, data_F1A00] - [0xF1DC0, .rodata, code_9A9D0] - [0xF1DF0, .rodata, code_9B180] - - [0xF1E00, bin, data_F1E00] + - [0xF1E10, .rodata, code_9C170] - [0xF1E60, .rodata, code_9E370] - [0xF1EC0, bin, data_F1EC0] - [0xF1F30, .rodata, code_AD110]