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 6b6466a
Show file tree
Hide file tree
Showing 4 changed files with 57 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
34 changes: 34 additions & 0 deletions include/sce/rand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "common.h"

struct RNG {
undefined4 field0_0x0;
undefined4 field1_0x4;
undefined4 field2_0x8;
undefined4 field3_0xc;
undefined4 field4_0x10;
undefined4 field5_0x14;
undefined4 field6_0x18;
undefined4 field7_0x1c;
undefined4 field8_0x20;
undefined4 field9_0x24;
undefined4 field10_0x28;
undefined4 field11_0x2c;
undefined4 field12_0x30;
undefined4 field13_0x34;
undefined4 field14_0x38;
undefined4 field15_0x3c;
undefined4 field16_0x40;
undefined4 field17_0x44;
undefined4 field18_0x48;
undefined4 field19_0x4c;
undefined4 field20_0x50;
undefined4 field21_0x54;
uint next;
};

extern "C" void srand(uint seed);

extern "C" uint rand();

extern struct RNG g_rng;
extern struct RNG *g_prng;
19 changes: 18 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,23 @@ 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 6b6466a

Please sign in to comment.