From 35193272f00f69b81b37c99974a38167f51d5cbf Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Fri, 2 Aug 2019 17:54:43 -0500 Subject: [PATCH] Added jlUtilRandom() and friends. --- joeylib/src/joey.c | 17 +++++++++++++++++ joeylib/src/joey.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/joeylib/src/joey.c b/joeylib/src/joey.c index 76e72bf..360572c 100644 --- a/joeylib/src/joey.c +++ b/joeylib/src/joey.c @@ -70,6 +70,7 @@ char _jlTempString[1024]; // Used internally for pathname ope static jlColorT _jlDefaultPalette[16]; static jlStackT *_jlFillStackTop = NULL; static byte _jlDrawFillColor = 0; +static juint32 _jlSeed = 0; void _jlDrawCircleClipped(jint16 x0, jint16 y0, jint16 radius); @@ -610,6 +611,22 @@ char *jlUtilMakePathname(char *filename, char *extension) { } +juint16 jlUtilRandom(void) { + _jlSeed = _jlSeed * 1103515245 + 12345; + return _jlSeed / 65536; +} + + +juint32 jlUtilRandomSeedGet(void) { + return _jlSeed; +} + + +void jlUtilRandomSeedSet(juint32 seed) { + _jlSeed = seed; +} + + void *_jlUtilStackPop(jlStackT **stack) { void *d = NULL; jlStackT *s; diff --git a/joeylib/src/joey.h b/joeylib/src/joey.h index b7b8220..5b4d74b 100644 --- a/joeylib/src/joey.h +++ b/joeylib/src/joey.h @@ -29,6 +29,12 @@ #include +#define JINT16_MIN -32768 +#define JINT16_MAX 32767 +#define JUINT16_MIN 0 +#define JUINT16_MAX 65535 + + // Determine platform and settings #ifdef __linux__ @@ -272,6 +278,9 @@ void jlUtilIdle(void); char *jlUtilMakePathname(char *filename, char *extension); bool jlUtilMustExit(void); void jlUtilNibbleSwap(byte *mem, jint16 count, byte old, byte new); +juint16 jlUtilRandom(void); +juint32 jlUtilRandomSeedGet(void); +void jlUtilRandomSeedSet(juint32 seed); void jlUtilShutdown(void) __attribute__((noreturn)); #define jlUtilStackPop(stack) _jlUtilStackPop((jlStackT **)&(stack)) // Syntatic Sugar void *_jlUtilStackPop(jlStackT **stack);