From a1ef70781eef5efec55af94ebeaf2e6b0472e69f Mon Sep 17 00:00:00 2001 From: Lol Bozo Date: Sun, 4 Aug 2024 14:29:43 -0400 Subject: [PATCH 1/4] A Few Util function matches Matched RadSmooth, RadSmoothA, GRandInRange, GModPositive, and SgnCompareG --- config/symbol_addrs.txt | 19 ++++++---- include/sce/math.h | 15 +++++--- src/P2/util.c | 80 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 94 insertions(+), 20 deletions(-) diff --git a/config/symbol_addrs.txt b/config/symbol_addrs.txt index 61976544..615fdcdf 100644 --- a/config/symbol_addrs.txt +++ b/config/symbol_addrs.txt @@ -766,14 +766,14 @@ g_ui = 0x275BC0; //////////////////////////////////////////////////////////////// RadNormalize__Ff = 0x1EA408; // type:func GLimitAbs = 0x1EA480; // type:func -GSmooth = 0x1EA4B8; // type:func -GSmoothA = 0x1EA620; // type:func -RadSmooth = 0x1EA728; // type:func -RadSmoothA = 0x1EA798; // type:func +GSmooth__FfffP3SMPPf = 0x1EA4B8; // type:func +GSmoothA__FffffP4SMPAPf = 0x1EA620; // type:func +RadSmooth__FfffP3SMPPf = 0x1EA728; // type:func +RadSmoothA__FffffP4SMPAPf = 0x1EA798; // type:func PosSmooth = 0x1EA818; // type:func SmoothMatrix = 0x1EA918; // type:func NRandInRange__Fii = 0x1EAA70; // type:func -GRandInRange = 0x1EAAE0; // type:func +GRandInRange__Fff = 0x1EAAE0; // type:func GRandGaussian = 0x1EAB48; // type:func FFloatsNear__Ffff = 0x1EAC68; // type:func CSolveQuadratic = 0x1EACA0; // type:func @@ -782,11 +782,11 @@ CalculateSinCos__FfPfT1 = 0x1EAD88; // type:func GTrunc = 0x1EAE78; // type:func GTrunc1 = 0x1EAF28; // type:func GModPositive__Fff = 0x1EAFE0; // type:func -FitClq = 0x1EB018; // type:func +FitClq__FffffP3CLQ = 0x1EB018; // type:func FCheckLm__FP2LMf = 0x1EB050; // type:func FCheckAlm = 0x1EB080; // type:func GLimitLm__FP2LMf = 0x1EB0F8; // type:func -SgnCompareG = 0x1EB128; // type:func +SgnCompareG__FPfT0 = 0x1EB128; // type:func Force__FPv = 0x1EB160; // type:func MinimizeRange = 0x1EB168; // type:func @@ -858,6 +858,11 @@ __main__Fv = 0x1fae18; // type:func //////////////////////////////////////////////////////////////// atan2f = 0x205778; // type:func +//////////////////////////////////////////////////////////////// +// sce/ee/gcc/src/newlib/libm/math/wf_atan2.c +//////////////////////////////////////////////////////////////// +fmodf = 0x2058a0; // type:func + //////////////////////////////////////////////////////////////// // sce/eecdvd.c diff --git a/include/sce/math.h b/include/sce/math.h index c1d32cf5..4290f5ad 100644 --- a/include/sce/math.h +++ b/include/sce/math.h @@ -1,10 +1,15 @@ -""" -@file math.h - -@brief Library math functions. -""" +/** + * @file math.h + * + * @brief Library math functions. + */ +#ifndef MATH_H +#define MATH_H extern "C" { float atan2f(float x, float y); + float fmodf(float x, float y); } + +#endif // MATH_H \ No newline at end of file diff --git a/src/P2/util.c b/src/P2/util.c index 8db3c324..3276fae0 100644 --- a/src/P2/util.c +++ b/src/P2/util.c @@ -1,5 +1,6 @@ #include #include +#include static const float PI = 3.14159265359f; @@ -15,14 +16,30 @@ float RadNormalize(float rad) INCLUDE_ASM(const s32, "P2/util", GLimitAbs); -INCLUDE_ASM(const s32, "P2/util", GSmooth); +INCLUDE_ASM(const s32, "P2/util", GSmooth__FfffP3SMPPf); -INCLUDE_ASM(const s32, "P2/util", GSmoothA); +INCLUDE_ASM(const s32, "P2/util", GSmoothA__FffffP4SMPAPf); INCLUDE_ASM(const s32, "P2/util", func_001EA720); -INCLUDE_ASM(const s32, "P2/util", RadSmooth); +float RadSmooth(float radCur, float radTarget, float dt, SMP *psmp, float *pdradNext) +{ + float fVar1; + + fVar1 = RadNormalize(radTarget - radCur); + fVar1 = GSmooth(0.0, fVar1, dt, psmp, pdradNext); + fVar1 = RadNormalize(radCur + fVar1); + return fVar1; +} -INCLUDE_ASM(const s32, "P2/util", RadSmoothA); +float RadSmoothA(float radCur, float dradCur, float radTarget, float dt, SMPA *psmpa, float *pdradNext) +{ + float fVar1; + + fVar1 = RadNormalize(radTarget - radCur); + fVar1 = GSmoothA(0.0, dradCur, fVar1, dt, psmpa, pdradNext); + fVar1 = RadNormalize(radCur + fVar1); + return fVar1; +} INCLUDE_ASM(const s32, "P2/util", PosSmooth); @@ -47,7 +64,23 @@ int NRandInRange(int nLow, int nHi) return nLow + (randVal % range); } -INCLUDE_ASM(const s32, "P2/util", GRandInRange); +float GRandInRange(float gHi,float gLow) +{ + int rand_result; + float delta; + float result; + if (gHi != gLow) + { + rand_result = rand(); + delta = gLow - gHi; + result = gHi + delta * (float)rand_result * 4.656613e-10f; + } + else + { + result = gHi; + } + return result; +} INCLUDE_ASM(const s32, "P2/util", GRandGaussian); @@ -78,9 +111,25 @@ INCLUDE_ASM(const s32, "P2/util", GTrunc); INCLUDE_ASM(const s32, "P2/util", GTrunc1); -INCLUDE_ASM(const s32, "P2/util", GModPositive__Fff); +float GModPositive(float gDividend, float gDivisor) +{ + float result = fmodf(gDividend, gDivisor); + if (result < 0.0f) + { + result += gDivisor; + } + return result; +} -INCLUDE_ASM(const s32, "P2/util", FitClq); +void FitClq(float g0, float g1, float u, float gU, CLQ *pclq) +{ + float fVar1; + + pclq->u = g0; + fVar1 = ((gU - g0) / u - (g1 - g0)) / (u - 1.0f); + pclq->w = fVar1; + pclq->v = (g1 - g0) - fVar1; +} int FCheckLm(LM* plm, float g) { @@ -102,7 +151,22 @@ float GLimitLm(struct LM* plm, float g) return g; } -INCLUDE_ASM(const s32, "P2/util", SgnCompareG); +int SgnCompareG(float *pg1,float *pg2) +{ + int iVar1; + + iVar1 = 1; + if (*pg1 > *pg2) + { + return iVar1; + } + iVar1 = -1; + if(*pg2 > *pg1) + { + return iVar1; + } + return 0; +} void Force(void *pv) { From be7581cdedd4980106c6e40f817695d87fc3f13e Mon Sep 17 00:00:00 2001 From: Lol Bozo Date: Sun, 4 Aug 2024 19:53:55 -0400 Subject: [PATCH 2/4] Binoc Function Names Updated the names of some Binoc functions --- config/symbol_addrs.txt | 6 +++--- src/P2/binoc.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/symbol_addrs.txt b/config/symbol_addrs.txt index 615fdcdf..2600aeb6 100644 --- a/config/symbol_addrs.txt +++ b/config/symbol_addrs.txt @@ -78,9 +78,9 @@ snd_SendIOPCommandNoWait = 0x11e8c8; // type:func //////////////////////////////////////////////////////////////// InitBei = 0x130F48; // type:func GEvaluateBei = 0x131000; // type:func -FUN_001310f0 = 0x1310F0; // type:func -FUN_00131140 = 0x131140; // type:func -FUN_00131198 = 0x131198; // type:func +InitBinoc__FP5BINOC5BLOTK = 0x1310F0; // type:func +ResetBinoc__FP5BINOC = 0x131140; // type:func +PostBinocLoad__FP5BINOC = 0x131198; // type:func DrawBinocCompass = 0x1316E8; // type:func DrawBinocZoom = 0x131F60; // type:func DrawBinocReticle = 0x132500; // type:func diff --git a/src/P2/binoc.c b/src/P2/binoc.c index 028b633c..20e50439 100644 --- a/src/P2/binoc.c +++ b/src/P2/binoc.c @@ -4,11 +4,11 @@ INCLUDE_ASM(const s32, "P2/binoc", InitBei); INCLUDE_ASM(const s32, "P2/binoc", GEvaluateBei); -INCLUDE_ASM(const s32, "P2/binoc", FUN_001310f0); +INCLUDE_ASM(const s32, "P2/binoc", InitBinoc__FP5BINOC5BLOTK); -INCLUDE_ASM(const s32, "P2/binoc", FUN_00131140); +INCLUDE_ASM(const s32, "P2/binoc", ResetBinoc__FP5BINOC); -INCLUDE_ASM(const s32, "P2/binoc", FUN_00131198); +INCLUDE_ASM(const s32, "P2/binoc", PostBinocLoad__FP5BINOC); INCLUDE_ASM(const s32, "P2/binoc", DrawBinocCompass); From 2ae08c6f6f020538990fcc8d9e88375a1d21f707 Mon Sep 17 00:00:00 2001 From: Lol Bozo Date: Sun, 4 Aug 2024 21:37:24 -0400 Subject: [PATCH 3/4] Binary Input Stream Match Matched CBinaryInputStream::Align --- src/P2/bis.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/P2/bis.c b/src/P2/bis.c index 37d8f332..a7047186 100644 --- a/src/P2/bis.c +++ b/src/P2/bis.c @@ -69,7 +69,12 @@ INCLUDE_ASM(const s32, "P2/bis", Decompress__18CBinaryInputStream); INCLUDE_ASM(const s32, "P2/bis", Read__18CBinaryInputStreamiPv); -INCLUDE_ASM(const s32, "P2/bis", Align__18CBinaryInputStreami); +void CBinaryInputStream::Align(int n) +{ + int iVar1 = ((int)m_pb + (n - 1)) & -n; + m_cb -= (iVar1 - (int)m_pb); + m_pb = (byte*)iVar1; +} uchar CBinaryInputStream::U8Read() { From 990f7168c37585af7c122ff22d751f4095c619ba Mon Sep 17 00:00:00 2001 From: Zac Date: Mon, 5 Aug 2024 02:13:05 +0000 Subject: [PATCH 4/4] Minor text fixes --- include/sce/math.h | 2 +- src/P2/bis.c | 6 +++--- src/P2/util.c | 54 +++++++++++++++++++++++----------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/sce/math.h b/include/sce/math.h index 4290f5ad..7c88bc09 100644 --- a/include/sce/math.h +++ b/include/sce/math.h @@ -12,4 +12,4 @@ extern "C" float fmodf(float x, float y); } -#endif // MATH_H \ No newline at end of file +#endif // MATH_H diff --git a/src/P2/bis.c b/src/P2/bis.c index a7047186..85c8d482 100644 --- a/src/P2/bis.c +++ b/src/P2/bis.c @@ -71,9 +71,9 @@ INCLUDE_ASM(const s32, "P2/bis", Read__18CBinaryInputStreamiPv); void CBinaryInputStream::Align(int n) { - int iVar1 = ((int)m_pb + (n - 1)) & -n; - m_cb -= (iVar1 - (int)m_pb); - m_pb = (byte*)iVar1; + int pbAligned = ((int)m_pb + (n - 1)) & -n; + m_cb -= (pbAligned - (int)m_pb); + m_pb = (byte*)pbAligned; } uchar CBinaryInputStream::U8Read() diff --git a/src/P2/util.c b/src/P2/util.c index 3276fae0..be73c27e 100644 --- a/src/P2/util.c +++ b/src/P2/util.c @@ -6,7 +6,7 @@ static const float PI = 3.14159265359f; float RadNormalize(float rad) { - if ((rad < -PI) || (PI < rad)) + if ((rad < -PI) || (PI < rad)) { float modpos = GModPositive(rad + PI, 2 * PI); rad = modpos - PI; @@ -23,22 +23,22 @@ INCLUDE_ASM(const s32, "P2/util", func_001EA720); float RadSmooth(float radCur, float radTarget, float dt, SMP *psmp, float *pdradNext) { - float fVar1; - - fVar1 = RadNormalize(radTarget - radCur); - fVar1 = GSmooth(0.0, fVar1, dt, psmp, pdradNext); - fVar1 = RadNormalize(radCur + fVar1); - return fVar1; + float result; + + result = RadNormalize(radTarget - radCur); + result = GSmooth(0.0, result, dt, psmp, pdradNext); + result = RadNormalize(radCur + result); + return result; } float RadSmoothA(float radCur, float dradCur, float radTarget, float dt, SMPA *psmpa, float *pdradNext) { - float fVar1; + float result; - fVar1 = RadNormalize(radTarget - radCur); - fVar1 = GSmoothA(0.0, dradCur, fVar1, dt, psmpa, pdradNext); - fVar1 = RadNormalize(radCur + fVar1); - return fVar1; + result = RadNormalize(radTarget - radCur); + result = GSmoothA(0.0, dradCur, result, dt, psmpa, pdradNext); + result = RadNormalize(radCur + result); + return result; } INCLUDE_ASM(const s32, "P2/util", PosSmooth); @@ -48,7 +48,7 @@ INCLUDE_ASM(const s32, "P2/util", SmoothMatrix); const int PRIME_MOD = 0x95675; // Generates a random integer in the range [nLow, nHi] -int NRandInRange(int nLow, int nHi) +int NRandInRange(int nLow, int nHi) { if (nLow == nHi) { @@ -91,13 +91,13 @@ int FFloatsNear(float g1,float g2,float gEpsilon) g1 = g1 > 0.0f ? g1 : -g1; g2 = g2 > 0.0f ? g2 : -g2; x = g1 > x ? g1 : x; - + g2 = g2 / x; if(g2 < gEpsilon) { return 1; - } + } return 0; } @@ -113,12 +113,12 @@ INCLUDE_ASM(const s32, "P2/util", GTrunc1); float GModPositive(float gDividend, float gDivisor) { - float result = fmodf(gDividend, gDivisor); - if (result < 0.0f) - { - result += gDivisor; - } - return result; + float result = fmodf(gDividend, gDivisor); + if (result < 0.0f) + { + result += gDivisor; + } + return result; } void FitClq(float g0, float g1, float u, float gU, CLQ *pclq) @@ -153,17 +153,17 @@ float GLimitLm(struct LM* plm, float g) int SgnCompareG(float *pg1,float *pg2) { - int iVar1; - - iVar1 = 1; + int result; + + result = 1; if (*pg1 > *pg2) { - return iVar1; + return result; } - iVar1 = -1; + result = -1; if(*pg2 > *pg1) { - return iVar1; + return result; } return 0; }