Skip to content

Commit

Permalink
Merge pull request #95 from LordBozo/Bozo-working
Browse files Browse the repository at this point in the history
Util and Binary Input Stream matches
  • Loading branch information
TheOnlyZac authored Aug 5, 2024
2 parents 3ab1b0f + 990f716 commit f85c7c3
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 31 deletions.
25 changes: 15 additions & 10 deletions config/symbol_addrs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions include/sce/math.h
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/P2/binoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/P2/bis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 pbAligned = ((int)m_pb + (n - 1)) & -n;
m_cb -= (pbAligned - (int)m_pb);
m_pb = (byte*)pbAligned;
}

uchar CBinaryInputStream::U8Read()
{
Expand Down
88 changes: 76 additions & 12 deletions src/P2/util.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <util.h>
#include <sce/rand.h>
#include <sce/math.h>

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;
Expand All @@ -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 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 result;

INCLUDE_ASM(const s32, "P2/util", RadSmoothA);
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);

Expand All @@ -31,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)
{
Expand All @@ -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);

Expand All @@ -58,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;
}

Expand All @@ -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)
{
Expand All @@ -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 result;

result = 1;
if (*pg1 > *pg2)
{
return result;
}
result = -1;
if(*pg2 > *pg1)
{
return result;
}
return 0;
}

void Force(void *pv)
{
Expand Down

0 comments on commit f85c7c3

Please sign in to comment.