Skip to content

Commit

Permalink
Match NRandInRange
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyZac committed Jul 4, 2024
1 parent f6069e3 commit ea88cb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/sly1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ segments:
#--------------------------------------------------------
- [0xF69C4, asm] # TBD #MARK: libs

- [0xF76F8, c, sce/rand]
- [0xF76F8, asm, sce/rand]

- [0xF7738, asm]

Expand Down
5 changes: 4 additions & 1 deletion config/symbol_addrs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ RadSmooth = 0x1EA728; // type:func
RadSmoothA = 0x1EA798; // type:func
PosSmooth = 0x1EA818; // type:func
SmoothMatrix = 0x1EA918; // type:func
NRandInRange = 0x1EAA70; // type:func
NRandInRange__Fii = 0x1EAA70; // type:func
GRandInRange = 0x1EAAE0; // type:func
GRandGaussian = 0x1EAB48; // type:func
FFloatsNear = 0x1EAC68; // type:func
Expand Down Expand Up @@ -336,6 +336,9 @@ __main__Fv = 0x1fae18; // type:func
srand = 0x1F66F8; // type:func
rand = 0x1F6708; // type:func

g_rng = 0x276680; // size:0x5c
g_prng = 0x27696c; // size:0x4


// gcc/dp-bit.c
dpcmp = 0x1FD308; // type:func
Expand Down
20 changes: 19 additions & 1 deletion src/P2/util.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <util.h>
#include <sce/rand.h>

static const float PI = 3.14159265359f;

Expand Down Expand Up @@ -26,7 +27,24 @@ INCLUDE_ASM(const s32, "P2/util", PosSmooth);

INCLUDE_ASM(const s32, "P2/util", SmoothMatrix);

INCLUDE_ASM(const s32, "P2/util", NRandInRange);
const int PRIME_MOD = 0x95675;

// Generates a random integer in the range [nLow, nHi]
int NRandInRange(int nLow, int nHi) {

if (nLow == nHi)
{
return nLow;
}

int randVal = rand();
randVal = randVal % PRIME_MOD;

int range = (nHi - nLow) + 1;

// Return a value within the range [nLow, nHi]
return nLow + (randVal % range);
}

INCLUDE_ASM(const s32, "P2/util", GRandInRange);

Expand Down

0 comments on commit ea88cb1

Please sign in to comment.