From a1e0af83b9e7f5877108710f440e4ce09c014b34 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Thu, 17 Oct 2019 19:26:29 -0500 Subject: [PATCH] Update JoeyLib Utility Functions --- JoeyLib-Utility-Functions.md | 52 ++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/JoeyLib-Utility-Functions.md b/JoeyLib-Utility-Functions.md index 4a17faf..76c3e32 100644 --- a/JoeyLib-Utility-Functions.md +++ b/JoeyLib-Utility-Functions.md @@ -1,3 +1,9 @@ +#### jlUtilByteSwap +```c +juint16 jlUtilByteSwap(juint16 twoBytes); +``` +Swaps the two bytes stored in `twoBytes` and returns them. + #### jlUtilDie ```c void jlUtilDie(const char *why); @@ -16,18 +22,54 @@ bool jlUtilIsOdd(int x); ``` Fast even/odd macro. If `x` is odd, it returns `true`. If `x` is even, it returns `false`. +#### jlUtilMakePathname +```c +char *jlUtilMakePathname(char *filename, char *extension); +``` +Returns a temporary character array that consists of the game data directory name, target specific path specifier, the provided `filename`, and the `extension` concatenated into one string. DO NOT free the returned string! If you need to preserve the value returned, `strdup` it to another string. + #### jlUtilMustExit ```c bool jlUtilMustExit(void); ``` You MUST call `jlUtilMustExit` in any game loop that prevents your application from exiting. If `jlUtilMustExit` returns `true` your application MUST exit safely. This is used on platforms where operating system events may need to terminate your application. +#### jlUtilNibbleSwap +```c +void jlUtilNibbleSwap(byte *mem, jint16 count, byte old, byte new); +``` +Swaps all occurrences of the nibble `old` in the block of memory `mem` to `new` for `count` bytes. Useful for swapping colors on display surfaces. + +#### jlUtilRandom +```c +juint16 jlUtilRandom(void); +``` +Returns a random unsigned 16 bit value that is consistent across target platforms. + +#### jlUtilRandomSeedGet +```c +juint32 jlUtilRandomSeedGet(void); +``` +Returns the internal "seed" of the random number generator in its current state. Useful for saving the state of the random number generator. + +#### jlUtilRandomSeedSet +```c +void jlUtilRandomSeedSet(juint32 seed); +``` +Specifies the internal "seed" to use for the next random number. + #### jlUtilShutdown ```c void jlUtilShutdown(void); ``` Cleanly shuts down JoeyLib. You should free any resources you have allocated before shutting down. If `JOEY_DEBUG` is defined, various memory statistics will be recorded in a file named `JLSTATS`. This function does not return. +#### jlUtilSleep +```c +void jlUtilSleep(juint16 tenths); +``` +Pauses program execution for `tenths` one-tenth seconds. + #### jlUtilStackPop ```c void *jlUtilStackPop(jlStackT stack); @@ -48,6 +90,12 @@ Starts up JoeyLib and initializes the library. `appName` is the name of your ap #### jlUtilTimer ```c -unsigned int jlUtilTimer(void); +juint16 jlUtilTimer(void); ``` -Provides a "wall clock" timer that is consistent across platforms. The value returned increments (roughly) every 1/10th of a second. When it reaches `MAX_INT`, it will roll over to zero. \ No newline at end of file +Provides a "wall clock" timer that is consistent across platforms. The value returned increments (roughly) every 1/10th of a second. When it reaches `JUINT16_MAX`, it will roll over to zero. + +#### jlUtilTimeSpan +```c +juint16 jlUtilTimeSpan(juint16 past, juint16 current); +``` +Returns the difference, in tenths of a second, between `past` and `current` (which are assumed to be values returned by `jlUtilTimer`). Handles zero rollover.