diff --git a/joeylib/src/jDev.c b/joeylib/src/jDev.c new file mode 100644 index 0000000..71e3af5 --- /dev/null +++ b/joeylib/src/jDev.c @@ -0,0 +1,65 @@ +/* + * JoeyLib + * Copyright (C) 2018-2019 Scott Duensing + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +*/ + + + +#include "string.h" + +#include "joey.h" + + +extern jbool _jlIsRunning; +extern jlMemoryBlockT _jlMemoryBlocks[JOEY_MEM_BLOCKS]; +extern long _jlTotalAllocations; +extern long _jlTotalFrees; + + +void jlUtilSay(char *format, ...) { + va_list va; + va_start(va, format); + _jlUtilSay(JOEY_DEV_HANDLE, format, va); + va_end(va); +} + + +void SetJLMustExitHelper(void) { + printf("Setting Must Exit Flag!\n"); + _jlIsRunning = jfalse; +} + + +void main(void) { + int i; + + jPixBufStart(); + joeyMain(); + jPixBufStop(); + + jlUtilDie("Clean Exit."); + + if (_jlTotalAllocations > _jlTotalFrees) { + for (i=0; i + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef H_JDEV_ +#define H_JDEV_ + + +// DO NOT INCLUDE THIS FILE IN YOUR CODE. joey.h handles it. + + +#include + + +typedef unsigned long uint32_t; + + +// JoeyLib functions provided by JoeyGlue. +extern void _jlDisplayPresent(uint32_t handle, void *image); // void so we don't have to include joey.h +extern jint16 _jlGameGetAxis(uint32_t handle, jbyte which); +extern jbool _jlGameGetButton(uint32_t handle, jbyte which); +extern jbool _jlKeyPressed(uint32_t handle); +extern char _jlKeyRead(uint32_t handle); +//extern jbool _jlUtilMustExit(uint32_t handle); +extern void _jlUtilSay(uint32_t handle, char *format, va_list args); +extern juint16 _jlUtilTimer(uint32_t handle); +extern void _jlUtilTitleSet(uint32_t handle, char *title); + +#define jlDisplayPresent() _jlDisplayPresent(JOEY_DEV_HANDLE, _jlBackingStore) +#define jlGameGetAxis(w) _jlGameGetAxis(JOEY_DEV_HANDLE, w) +#define jlGameGetButton(w) _jlGameGetButton(JOEY_DEV_HANDLE, w) +#define jlKeyPressed() _jlKeyPressed(JOEY_DEV_HANDLE) +#define jlKeyRead() _jlKeyRead(JOEY_DEV_HANDLE) +//#define jlUtilMustExit() _jlUtilMustExit(JOEY_DEV_HANDLE) +//#define jlUtilSay(m, ...) _jlUtilSay(JOEY_DEV_HANDLE, m, __VA_ARGS__) +#define jlUtilTimer() _jlUtilTimer(JOEY_DEV_HANDLE) +#define jlUtilTitleSet(t) _jlUtilTitleSet(JOEY_DEV_HANDLE, t) + +void jlUtilSay(char *format, ...); + +void SetJLMustExitHelper(void); + + +// TCC Standard Library Replacement +#include + +// Missing Defines +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +// Missing Prototypes +int fseek(FILE *stream, long offset, int whence); +long ftell(FILE *stream); +int abs(int j); + + +#endif // H_JDEV_ diff --git a/joeylib/src/joey.c b/joeylib/src/joey.c index 6186e96..de7c14a 100644 --- a/joeylib/src/joey.c +++ b/joeylib/src/joey.c @@ -30,7 +30,9 @@ #include "joey.h" +#ifndef JOEY_DEV_HANDLE #include "stddclmr.h" +#endif #ifdef JOEY_IIGS @@ -75,6 +77,10 @@ jbyte _jlDrawColorNibbles = (15 << 4) + 15; // Color in both nibbles jbyte _jlBorderColor = 0; char _jlTempString[1024]; // Used internally for pathname operations +#ifndef JL_HAS_UTILMUSTEXIT +jbool _jlIsRunning = jtrue; +#endif + static jlColorT _jlDefaultPalette[16]; static jlStackT *_jlFillStackTop = NULL; @@ -92,13 +98,13 @@ _jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed //***TODO*** These are really terrible examples of memory management routines. -static jlMemoryBlockT _jlMemoryBlocks[JOEY_MEM_BLOCKS]; -static long _jlTotalAllocated = 0; -static long _jlTotalAllocations = 0; -static long _jlTotalFrees = 0; -static long _jlHighWaterMark = 0; -static long _jlBlocksNeeded = 0; -static jbool _jlMemoryStarted = jfalse; +jlMemoryBlockT _jlMemoryBlocks[JOEY_MEM_BLOCKS]; +long _jlTotalAllocated = 0; +long _jlTotalAllocations = 0; +long _jlTotalFrees = 0; +long _jlHighWaterMark = 0; +long _jlBlocksNeeded = 0; +jbool _jlMemoryStarted = jfalse; void _jlFree(void **pointer) { jint16 i; @@ -661,11 +667,7 @@ jbool _jlImgLoad(jlImgT **img, char *filename) { } s = (jlImgT *)*img; // Load into it. -#ifdef JOEY_TOOLS - f = fopen(filename, "rb"); -#else f = fopen(jlUtilMakePathname(filename, "img"), "rb"); -#endif if (f != NULL) { if (fread(s, sizeof(jlImgT), 1, f) > 0) { // Is this a valid image file? @@ -681,15 +683,11 @@ jbool _jlImgLoad(jlImgT **img, char *filename) { #ifndef JL_HAS_IMGSAVE -jbool jlImgSave(jlImgT *img, char *filename) { +jbool _jlImgSave(jlImgT *img, char *filename) { jbool result = jfalse; FILE *f; -#ifdef JOEY_TOOLS - f = fopen(filename, "wb"); -#else f = fopen(jlUtilMakePathname(filename, "img"), "wb"); -#endif if (f != NULL) { if (fwrite(img, sizeof(jlImgT), 1, f) > 0) { result = jtrue; @@ -895,11 +893,7 @@ jbool _jlStnLoad(jlStnT **stn, char *filename) { } s = (jlStnT *)*stn; // Load into it. -#ifdef JOEY_TOOLS - f = fopen(filename, "rb"); -#else f = fopen(jlUtilMakePathname(filename, "stn"), "rb"); -#endif if (f != NULL) { if (fread(s, sizeof(jlStnT), 1, f) > 0) { // Is this a valid stencil file? @@ -917,38 +911,42 @@ jbool _jlStnLoad(jlStnT **stn, char *filename) { #ifndef JL_HAS_UTILDIE __attribute__((__format__ (__printf__, 1, 0))) void jlUtilDie(const char *why, ...) { -#ifdef JOEY_DEBUG - jint16 i; - FILE *f = NULL; - char msg[80]; // Very short messages (screen width). Be careful! - va_list va; + jint16 i; + char msg[2048]; + va_list va; + static jbool alreadyDead = jfalse; - va_start(va, why); - vsprintf(msg, why, va); - va_end(va); + if (!alreadyDead) { + alreadyDead = jtrue; - f = fopen("JLSTATS", "wt"); // This doesn't use jlUtilMakePathname - if (f != NULL) { - fprintf(f, "JoeyLib Statistics\n\n"); - fprintf(f, " Allocations: %ld\n", _jlTotalAllocations); - fprintf(f, " Frees: %ld\n", _jlTotalFrees); - fprintf(f, " Most Used: %ldM (%ldK) (%ld bytes)\n", _jlHighWaterMark / 1048576, _jlHighWaterMark / 1024, _jlHighWaterMark); - fprintf(f, " Blocks Used: %ld (of %ld)\n", _jlBlocksNeeded, (long)JOEY_MEM_BLOCKS); + va_start(va, why); + vsprintf(msg, why, va); + va_end(va); + + jlUtilSay("JoeyLib Statistics"); + jlUtilSay(""); + jlUtilSay(" Allocations: %ld", _jlTotalAllocations); + jlUtilSay(" Frees: %ld", _jlTotalFrees); + jlUtilSay(" Most Used: %ldM (%ldK) (%ld bytes)", _jlHighWaterMark / 1048576, _jlHighWaterMark / 1024, _jlHighWaterMark); + jlUtilSay(" Blocks Used: %ld (of %ld)", _jlBlocksNeeded, (long)JOEY_MEM_BLOCKS); if (_jlTotalAllocations > _jlTotalFrees) { for (i=0; i -#include typedef unsigned char jbool; @@ -66,8 +66,6 @@ typedef unsigned char jbyte; // Determine platform and settings #ifdef __linux__ -#include - #define JOEY_LINUX #define JOEY_PC #define JOEY_LITLE_ENDIAN @@ -394,7 +392,8 @@ void jlImgDisplay(jlImgT *img); void jlImgFree(jlImgT *img); #define jlImgLoad(img, filename) _jlImgLoad((jlImgT **)&(img), filename) // Syntatic Sugar jbool _jlImgLoad(jlImgT **img, char *filename); -jbool jlImgSave(jlImgT *img, char *filename); +#define jlImgSave(img, filename) _jlImgSave(img, filename) // Needed so we can redefined it for JoeyDev +jbool _jlImgSave(jlImgT *img, char *filename); #define jlImgSurfaceGet(img) ((jlSurfaceT)img->pixels) jbool jlKeyPressed(void); @@ -427,7 +426,11 @@ void jlStnFree(jlStnT *stn); jbool _jlStnLoad(jlStnT **stn, char *filename); #define jlUtilByteSwap(twoBytes) ((juint16)((twoBytes) & 0xff) >> 8) | (juint16)((twoBytes) << 8) +#ifdef JOEY_TOOLS +void jlUtilDie(const char *why, ...); +#else void jlUtilDie(const char *why, ...) __attribute__((noreturn)); +#endif void jlUtilIdle(void); jbool jlUtilInputRead(jbyte *key); #define jlUtilIsOdd(x) (((x & 1) == 1) ? jtrue : jfalse) @@ -437,6 +440,7 @@ void jlUtilNibbleSwap(jbyte *mem, jint16 count, jbyte oldValue, jbyte n juint16 jlUtilRandom(void); juint32 jlUtilRandomSeedGet(void); void jlUtilRandomSeedSet(juint32 seed); +void jlUtilSay(char *format, ...); void jlUtilSleep(juint16 sixtieths); #define jlUtilStackPop(stack) _jlUtilStackPop((jlStackT **)&(stack)) // Syntatic Sugar void *_jlUtilStackPop(jlStackT **stack); @@ -501,4 +505,19 @@ void _jlDebugBorder(jlBorderColorsE color); } #endif + +// Must be after closing 'extern "C"' +#ifdef JOEY_DEV_HANDLE +#define JL_HAS_DISPLAYPRESENT +#define JL_HAS_GAMEGETAXIS +#define JL_HAS_GAMEGETBUTTON +#define JL_HAS_KEYPRESSED +#define JL_HAS_KEYREAD +#define JL_HAS_UTILSAY +#define JL_HAS_UTILTIMER +#include "jDev.h" +#include "jPixBuf.h" +#endif + + #endif // H_JOEY_ diff --git a/scripts/installer.sh b/scripts/installer.sh index 94c83cf..3270277 100755 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -66,7 +66,7 @@ function buildMacOSXSDK() { XCODE=${G_XCODE_FILE} else if [[ ! -e "${OSX}/SDK" ]]; then - tFileBrowser XCODE "Please locate your 'XCode 9.4.1' XIP" .xip .. + tFileBrowser XCODE "Please locate your XCode XIP" .xip .. if [[ -z ${XCODE} || "${XCODE}" == "" ]]; then return 0 fi @@ -78,7 +78,7 @@ function buildMacOSXSDK() { git clone https://github.com/tpoechtrager/osxcross.git pushd osxcross &> /dev/null ./tools/gen_sdk_package_pbzx.sh "${XCODE}" - mv -f MacOSX10.* tarballs/. + mv -f MacOSX.* tarballs/. OSX_VERSION_MIN=${G_OSX_MIN} UNATTENDED=1 ./build.sh mv -f target "${OSX}" popd &> /dev/null @@ -927,6 +927,7 @@ function start() { echo "" tBoldBox tBLUE "Examining system..." doSudo dpkg --add-architecture i386 + doSudo apt-get -y update tCheckPackages MISSING \ autoconf \ automake \