Skip to content

Commit ea88cb1

Browse files
committed
Match NRandInRange
1 parent f6069e3 commit ea88cb1

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

config/sly1.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ segments:
315315
#--------------------------------------------------------
316316
- [0xF69C4, asm] # TBD #MARK: libs
317317

318-
- [0xF76F8, c, sce/rand]
318+
- [0xF76F8, asm, sce/rand]
319319

320320
- [0xF7738, asm]
321321

config/symbol_addrs.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ RadSmooth = 0x1EA728; // type:func
287287
RadSmoothA = 0x1EA798; // type:func
288288
PosSmooth = 0x1EA818; // type:func
289289
SmoothMatrix = 0x1EA918; // type:func
290-
NRandInRange = 0x1EAA70; // type:func
290+
NRandInRange__Fii = 0x1EAA70; // type:func
291291
GRandInRange = 0x1EAAE0; // type:func
292292
GRandGaussian = 0x1EAB48; // type:func
293293
FFloatsNear = 0x1EAC68; // type:func
@@ -336,6 +336,9 @@ __main__Fv = 0x1fae18; // type:func
336336
srand = 0x1F66F8; // type:func
337337
rand = 0x1F6708; // type:func
338338

339+
g_rng = 0x276680; // size:0x5c
340+
g_prng = 0x27696c; // size:0x4
341+
339342

340343
// gcc/dp-bit.c
341344
dpcmp = 0x1FD308; // type:func

src/P2/util.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <util.h>
2+
#include <sce/rand.h>
23

34
static const float PI = 3.14159265359f;
45

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

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

29-
INCLUDE_ASM(const s32, "P2/util", NRandInRange);
30+
const int PRIME_MOD = 0x95675;
31+
32+
// Generates a random integer in the range [nLow, nHi]
33+
int NRandInRange(int nLow, int nHi) {
34+
35+
if (nLow == nHi)
36+
{
37+
return nLow;
38+
}
39+
40+
int randVal = rand();
41+
randVal = randVal % PRIME_MOD;
42+
43+
int range = (nHi - nLow) + 1;
44+
45+
// Return a value within the range [nLow, nHi]
46+
return nLow + (randVal % range);
47+
}
3048

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

0 commit comments

Comments
 (0)