From 2bcb7025c39903dbaa5c9634af823e7d5197b322 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 9 Jun 2021 17:07:26 -0500 Subject: [PATCH] Updated to be happy with the JoeyDev changes. --- joeylib/build.sh | 8 ++++-- joeylib/joeylib.pro | 2 ++ joeylib/src/jIIgs.c | 51 ++++++++++++++++++---------------- joeylib/src/jSDL2.c | 44 +++++++++++++++--------------- joeylib/src/joey.c | 65 ++++++++++++++++++++++++++++++++++---------- joeylib/src/joey.h | 4 --- joeylib/src/test.c | 7 ++--- scripts/installer.sh | 20 ++++++++++---- 8 files changed, 125 insertions(+), 76 deletions(-) diff --git a/joeylib/build.sh b/joeylib/build.sh index f41f22b..1dd91da 100755 --- a/joeylib/build.sh +++ b/joeylib/build.sh @@ -76,13 +76,15 @@ function doIIgsBuild() { iix compile jIIgs.c keep=31:/out/joey/jIIgsc iix compile joey.c keep=31:/out/joey/joey - iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.A - iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.ROOT + iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsc.root iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsc.a iix makelib 31:/out/joey/joeylib +31:/out/joey/joey.a + iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.A + iix makelib 31:/out/joey/joeylib +31:/out/joey/jIIgsasm.ROOT iix compile test.c keep=31:/out/joey/test - iix -DKeepType=S16 link +L 31:/out/joey/test 31:/out/joey/joeylib keep=31:/out/joey/test > test.map +# iix -DKeepType=S16 link +L 31:/out/joey/joeylib 31:/out/joey/test keep=31:/out/joey/test > test.map + iix -DKeepType=S16 link +L 31:/out/joey/jIIgsc 31:/out/joey/joey 31:/out/joey/jIIgsasm 31:/out/joey/test keep=31:/out/joey/test > test.map iix dumpobj +D 31:/out/joey/test &> test.dis || true diff --git a/joeylib/joeylib.pro b/joeylib/joeylib.pro index 9d6d5a6..c24203a 100644 --- a/joeylib/joeylib.pro +++ b/joeylib/joeylib.pro @@ -67,6 +67,8 @@ OTHER_FILES += \ src/jIIgs.c \ src/jIIgs.asm \ src/jIIgs.macro \ + src/jDev.h \ + src/jDev.c \ joey.pri dmalloc { diff --git a/joeylib/src/jIIgs.c b/joeylib/src/jIIgs.c index e7a759e..eeae4e7 100644 --- a/joeylib/src/jIIgs.c +++ b/joeylib/src/jIIgs.c @@ -31,6 +31,7 @@ #include +#define JOEY_MAIN #include "joey.h" @@ -146,12 +147,12 @@ jbool jlGameGetButton(jbyte which) { } -jbool _jlImgCreate(jlImgT **img) { +jbool _jlImgCreate(jlImgT **img, jint16 line, char *file) { jlImgT *t = NULL; // Are we loading into a new image? if (*img == NULL) { - t = (jlImgT *)jlMalloc(sizeof(jlImgT)); + t = (jlImgT *)jlMallocEx(sizeof(jlImgT), line, file); if (t == NULL) { return jfalse; } @@ -265,7 +266,7 @@ void jlSoundModStop(void) { } -int main(void) { +void main(void) { handle tempHandle; ptr ZeroPagePtr; @@ -344,31 +345,33 @@ int main(void) { jlDisplayPresent(); // Run the main loop. - joeyMain(); + if (!setjmp(_jlJumpBuffer)) { + joeyMain(); - // Clear the display. - jlDrawColorSet(0); - jlDrawClear(); + // Clear the display. + jlDrawColorSet(0); + jlDrawClear(); - // Restore Border - jlDisplayBorder((jlBorderColorsE)_jlBorderSaved); - jlDisplayPresent(); + // Restore Border + jlDisplayBorder((jlBorderColorsE)_jlBorderSaved); + jlDisplayPresent(); - // SHR Off - asmGrOff(); + // SHR Off + asmGrOff(); - asmStop(); + asmStop(); - // Shutdown tools - NTPShutDown(); // NinjaTracker - UnloadOneTool(222); - MSShutDown(); // MIDI Synth - UnloadOneTool(35); - SoundShutDown(); // Sound Tool Set - MTShutDown(); // Misc Tools - DisposeAll(userid()); - MMShutDown(userid()); // Memory Manager - TLShutDown(); // Tool Locator + // Shutdown tools + NTPShutDown(); // NinjaTracker + UnloadOneTool(222); + MSShutDown(); // MIDI Synth + UnloadOneTool(35); + SoundShutDown(); // Sound Tool Set + MTShutDown(); // Misc Tools + DisposeAll(userid()); + MMShutDown(userid()); // Memory Manager + TLShutDown(); // Tool Locator - jlUtilDie("Clean Exit."); + jlUtilDie("Clean Exit."); + } } diff --git a/joeylib/src/jSDL2.c b/joeylib/src/jSDL2.c index 147a80e..f89b865 100644 --- a/joeylib/src/jSDL2.c +++ b/joeylib/src/jSDL2.c @@ -414,16 +414,13 @@ void jlUtilTitleSet(char *title) { } -int main(int argc, char *argv[]) { +int main(void) { int flags; int result; int joysticks; int x; - (void)argc; - (void)argv; - // Start low-level tools if (SDL_Init(SDL_INIT_EVERYTHING) == -1) { jlUtilDie(SDL_GetError()); @@ -460,25 +457,28 @@ int main(int argc, char *argv[]) { jPixBufStart(); // Run the main loop. - joeyMain(); + if (!setjmp(_jlJumpBuffer)) { + joeyMain(); - jPixBufStop(); + jPixBufStop(); - SDL_RemoveTimer(_jlTimerId); - for (x=0; x<_jlControllerCount; x++) { - SDL_GameControllerClose(_jlControllers[x]); + SDL_RemoveTimer(_jlTimerId); + for (x=0; x<_jlControllerCount; x++) { + SDL_GameControllerClose(_jlControllers[x]); + } + _jlControllerCount = 0; + jlFree(_jlControllers); + //***TODO*** Sound effects stop? + jlSoundModStop(); + jlSoundMidiStop(); + Mix_CloseAudio(); + Mix_Quit(); + SDL_FreeFormat(_jlPixelFormat); + SDL_DestroyTexture(_jlTexture); + SDL_DestroyRenderer(_jlRenderer); + SDL_DestroyWindow(_jlWindow); + SDL_Quit(); + + jlUtilDie("Clean Exit."); } - _jlControllerCount = 0; - jlFree(_jlControllers); - //***TODO*** Sound effects stop? - jlSoundModStop(); - jlSoundMidiStop(); - Mix_CloseAudio(); - Mix_Quit(); - SDL_FreeFormat(_jlPixelFormat); - SDL_DestroyTexture(_jlTexture); - SDL_DestroyRenderer(_jlRenderer); - SDL_DestroyWindow(_jlWindow); - SDL_Quit(); - jlUtilDie("Clean Exit."); } diff --git a/joeylib/src/joey.c b/joeylib/src/joey.c index 170d3a4..da2ea86 100644 --- a/joeylib/src/joey.c +++ b/joeylib/src/joey.c @@ -23,10 +23,8 @@ #include #include #include -#include -#define JOEY_MAIN #include "joey.h" @@ -99,13 +97,13 @@ _jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed //***TODO*** These are really terrible examples of memory management routines. -jlMemoryBlockT _jlMemoryBlocks[JOEY_MEM_BLOCKS]; -long _jlTotalAllocated = 0; -long _jlTotalAllocations = 0; -long _jlTotalFrees = 0; -long _jlHighWaterMark = 0; -long _jlBlocksNeeded = 0; -jbool _jlMemoryStarted = jfalse; +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; void _jlFree(void **pointer) { jint16 i; @@ -124,6 +122,16 @@ void _jlFree(void **pointer) { free(*pointer); } + + /* + jlUtilSay("Free:"); + jlUtilSay("_jlTotalAllocated = %ld", _jlTotalAllocated); + jlUtilSay("_jlTotalAllocations = %ld", _jlTotalAllocations); + jlUtilSay("_jlTotalFrees = %ld", _jlTotalFrees); + jlUtilSay("_jlHighWaterMark = %ld", _jlHighWaterMark); + jlUtilSay("_jlBlocksNeeded = %ld", _jlBlocksNeeded); + jlUtilSay("-----------------------------------------------"); + */ } void *_jlMalloc(size_t size, jint16 line, char *file) { @@ -153,6 +161,16 @@ void *_jlMalloc(size_t size, jint16 line, char *file) { _jlHighWaterMark = _jlTotalAllocated; } + /* + jlUtilSay("Malloc:"); + jlUtilSay("_jlTotalAllocated = %ld", _jlTotalAllocated); + jlUtilSay("_jlTotalAllocations = %ld", _jlTotalAllocations); + jlUtilSay("_jlTotalFrees = %ld", _jlTotalFrees); + jlUtilSay("_jlHighWaterMark = %ld", _jlHighWaterMark); + jlUtilSay("_jlBlocksNeeded = %ld", _jlBlocksNeeded); + jlUtilSay("-----------------------------------------------"); + */ + return _jlMemoryBlocks[i].addr; } @@ -180,6 +198,16 @@ void *_jlRealloc(void *pointer, size_t size) { _jlHighWaterMark = _jlTotalAllocated; } + /* + jlUtilSay("Realloc:"); + jlUtilSay("_jlTotalAllocated = %ld", _jlTotalAllocated); + jlUtilSay("_jlTotalAllocations = %ld", _jlTotalAllocations); + jlUtilSay("_jlTotalFrees = %ld", _jlTotalFrees); + jlUtilSay("_jlHighWaterMark = %ld", _jlHighWaterMark); + jlUtilSay("_jlBlocksNeeded = %ld", _jlBlocksNeeded); + jlUtilSay("-----------------------------------------------"); + */ + return _jlMemoryBlocks[i].addr; } @@ -1142,8 +1170,10 @@ void jlUtilSay(char *format, ...) { #ifdef JOEY_DEBUG FILE *f = NULL; va_list va; - va_list va2; static jbool firstWrite = jtrue; +#if defined(va_copy) + va_list va2; +#endif // Start over every run. if (firstWrite) { @@ -1152,17 +1182,24 @@ void jlUtilSay(char *format, ...) { } va_start(va, format); - va_copy(va2, va); - f = fopen("JLSTATS", "wt+"); // This doesn't use jlUtilMakePathname +#if defined(va_copy) + va_copy(va2, va); +#endif + + f = fopen("JLSTATS", "a+"); // This doesn't use jlUtilMakePathname if (f != NULL) { vfprintf(f, format, va); + fprintf(f, "\n"); fclose(f); } - printf(format, va); - +#if defined(va_copy) + vprintf(format, va2); + printf("\n"); va_end(va2); +#endif + va_end(va); #else (void)format; diff --git a/joeylib/src/joey.h b/joeylib/src/joey.h index 816fb12..84ec7f8 100644 --- a/joeylib/src/joey.h +++ b/joeylib/src/joey.h @@ -429,11 +429,7 @@ void jlStnFree(jlStnT *stn); jbool _jlStnLoad(jlStnT **stn, char *filename, jint16 line, char *file); #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) diff --git a/joeylib/src/test.c b/joeylib/src/test.c index 5b6b3b6..2121a5c 100644 --- a/joeylib/src/test.c +++ b/joeylib/src/test.c @@ -179,14 +179,13 @@ void grid(void) { for (i=0; i<320; i+=8) { jlDrawLine(i, 0, i, 199); } + for (i=0; i<200; i+=8) { jlDrawLine(0, i, 319, i); } - while (!jlKeyPressed()) { - jlDisplayPresent(); - } - jlKeyRead(); + jlDisplayPresent(); + jlKeyWaitForAny(); } diff --git a/scripts/installer.sh b/scripts/installer.sh index 3270277..d73d9fb 100755 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -64,6 +64,9 @@ function buildMacOSXSDK() { if [[ ! -z ${G_AUTOMATED} ]]; then XCODE=${G_XCODE_FILE} + if [[ ! -e "${XCODE}" ]]; then + return 0 + fi else if [[ ! -e "${OSX}/SDK" ]]; then tFileBrowser XCODE "Please locate your XCode XIP" .xip .. @@ -477,6 +480,9 @@ function installIIgs() { if [[ ! -e "${IIGS}/ORCA/Languages/cc" ]]; then if [[ ! -z ${G_AUTOMATED} ]]; then ORCA=${G_ORCA_FILE} + if [[ ! -e "${ORCA}" ]]; then + return 0 + fi else tFileBrowser ORCA "Please locate your 'OPUS ][ The Software' ISO" .iso .. if [[ -z ${ORCA} || "${ORCA}" == "" ]]; then @@ -488,6 +494,9 @@ function installIIgs() { if [[ ! -d GoldenGate ]]; then if [[ ! -z ${G_AUTOMATED} ]]; then GGATE=${G_GOLDEN_GATE_FILE} + if [[ ! -e "${GGATE}" ]]; then + return 0 + fi else tFileBrowser GGATE "Please locate your 'Golden Gate' MSI" .msi .. if [[ -z ${GGATE} || "${GGATE}" == "" ]]; then @@ -530,7 +539,7 @@ function installIIgs() { purple "Upgrading ORCA/C" fetchGitHubRelease RESULT byteworksinc ORCA-C 2mg #***TODO*** This fails with a mmap error sometimes - no idea why - #"${IIGS}/opus-extractor" -v -s / ${RESULT} "${IIGS}/ORCA" + "${IIGS}/opus-extractor" -v -s / ${RESULT} "${IIGS}/ORCA" pushd ${GOLDEN_GATE} &> /dev/null #find . -type d -exec chmod 755 {} \; @@ -990,12 +999,13 @@ function start() { uuid-dev \ wget \ xz-utils - if [[ ! -z ${G_AUTOMATED} ]]; then - DOINSTALL=1 - fi if [[ "${MISSING}" != "" ]]; then - if (whiptail --title "${G_TITLE}" --yesno "Some required packages are missing.\n\nInstall them now?" 9 40); then + if [[ ! -z ${G_AUTOMATED} ]]; then DOINSTALL=1 + else + if (whiptail --title "${G_TITLE}" --yesno "Some required packages are missing.\n\nInstall them now?" 9 40); then + DOINSTALL=1 + fi fi if [[ "${DOINSTALL}" == "1" ]]; then TEMP=" ${MISSING//[^ ]}"