Changes to support JoeyDev.

This commit is contained in:
Scott Duensing 2021-05-14 19:48:39 -05:00
parent 5bf7816f11
commit 6f88d4ae69
5 changed files with 260 additions and 52 deletions

65
joeylib/src/jDev.c Normal file
View file

@ -0,0 +1,65 @@
/*
* JoeyLib
* Copyright (C) 2018-2019 Scott Duensing <scott@kangaroopunch.com>
*
* 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<JOEY_MEM_BLOCKS; i++) {
if (_jlMemoryBlocks[i].addr != NULL) {
free(_jlMemoryBlocks[i].addr);
}
}
}
}

76
joeylib/src/jDev.h Normal file
View file

@ -0,0 +1,76 @@
/*
* JoeyLib
* Copyright (C) 2018-2019 Scott Duensing <scott@kangaroopunch.com>
*
* 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 <stdarg.h>
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 <tcclib.h>
// 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_

View file

@ -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<JOEY_MEM_BLOCKS; i++) {
if (_jlMemoryBlocks[i].addr != NULL) {
fprintf(f, "Unfreed Block: %ld bytes, %d @ %s\n", (long int)_jlMemoryBlocks[i].size, _jlMemoryBlocks[i].line, _jlMemoryBlocks[i].file);
jlUtilSay("Unfreed Block: %ld bytes, %d @ %s", (long int)_jlMemoryBlocks[i].size, _jlMemoryBlocks[i].line, _jlMemoryBlocks[i].file);
}
}
}
//fprintf(f, "jlBorderSaved %d %d\n", jlBorderSaved.rtcReserved, jlBorderSaved.border);
fprintf(f, "\n%s\n", msg);
fclose(f);
jlUtilSay("");
jlUtilSay("%s", msg);
}
#else
(void)why;
#ifdef JOEY_TOOLS
#ifndef JL_HAS_UTILMUSTEXIT
_jlIsRunning = jfalse;
#endif
#else
exit(0);
#endif
}
#endif
@ -1052,18 +1050,35 @@ jbool jlUtilInputRead(jbyte *key) {
char *jlUtilMakePathname(char *filename, char *extension) {
char temp[2];
// If JOEY_TOOLS is defined, we use the filename as-is and just append the extension.
// However, if JOEY_DEV_DATA_PATH is defined, we pre-pend the name with the data path and add the extension.
// Otherwise, we pre-pend with 'data' and add the extension.
temp[0] = JOEY_PATH_SEPARATOR;
temp[1] = 0;
_jlTempString[0] = 0;
#ifdef JOEY_TOOLS
(void)temp;
#ifdef JOEY_DEV_DATA_PATH
// Running *UNDER* JoeyDev as a JoeyLib app. JOEY_DEV_DATA_PATH defined.
strcat(_jlTempString, JOEY_DEV_DATA_PATH);
#endif
#else
// Standard use case - compiled application.
strcat(_jlTempString, "data");
strcat(_jlTempString, temp);
#endif
// Add extension.
strcat(_jlTempString, filename);
if (extension != NULL) {
strcat(_jlTempString, ".");
strcat(_jlTempString, extension);
}
printf("%s\n", _jlTempString);
return _jlTempString;
}
#endif
@ -1071,7 +1086,7 @@ char *jlUtilMakePathname(char *filename, char *extension) {
#ifndef JL_HAS_UTILMUSTEXIT
jbool jlUtilMustExit(void) {
return jfalse;
return !_jlIsRunning;
}
#endif
@ -1111,6 +1126,41 @@ void jlUtilRandomSeedSet(juint32 seed) {
#endif
#ifndef JL_HAS_UTILSAY
__attribute__((__format__ (__printf__, 1, 0)))
void jlUtilSay(char *format, ...) {
#ifdef JOEY_DEBUG
FILE *f = NULL;
va_list va;
va_list va2;
static jbool firstWrite = jtrue;
// Start over every run.
if (firstWrite) {
remove("JLSTATS");
firstWrite = jfalse;
}
va_start(va, format);
va_copy(va2, va);
f = fopen("JLSTATS", "wt+"); // This doesn't use jlUtilMakePathname
if (f != NULL) {
vfprintf(f, format, va);
fclose(f);
}
printf(format, va);
va_end(va2);
va_end(va);
#else
(void)format;
#endif
}
#endif
#ifndef JL_HAS_UTILSLEEP
void jlUtilSleep(juint16 sixtieths) {
juint16 t = jlUtilTimer();
@ -1320,11 +1370,7 @@ jbool _jlVecLoad(jlVecT **vec, char *filename) {
*vec = v;
v = (jlVecT *)*vec;
// Load into it.
#ifdef JOEY_TOOLS
f = fopen(filename, "rb");
#else
f = fopen(jlUtilMakePathname(filename, "vec"), "rb");
#endif
if (f != NULL) {
fseek(f, 0, SEEK_END);
size = ftell(f);
@ -1349,3 +1395,4 @@ jbool _jlVecLoad(jlVecT **vec, char *filename) {
return result;
}
#endif

View file

@ -22,6 +22,7 @@
#ifndef H_JOEY_
#define H_JOEY_
#ifdef __cplusplus
extern "C" {
#endif
@ -31,7 +32,6 @@ extern "C" {
#include <stdlib.h>
#include <limits.h>
typedef unsigned char jbool;
@ -66,8 +66,6 @@ typedef unsigned char jbyte;
// Determine platform and settings
#ifdef __linux__
#include <linux/limits.h>
#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_

View file

@ -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 \