diff --git a/.gitignore b/.gitignore index d874ce5..03634be 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ src/SDL2/ src/music src/music.w src/*.dis +src/*.map diff --git a/build-IIgs.sh b/build-IIgs.sh index 890e32b..cccc645 100755 --- a/build-IIgs.sh +++ b/build-IIgs.sh @@ -1,9 +1,11 @@ #!/bin/bash -e -if [ -d ${JOEY}/sdks/iix/IIgs/out/joey ]; then - rm -rf ${JOEY}/sdks/iix/IIgs/out/joey +OUT=${JOEY}/sdks/iix/IIgs/out/joey + +if [ -d ${OUT} ]; then + rm -rf ${OUT} fi -mkdir -p ${JOEY}/sdks/iix/IIgs/out/joey +mkdir -p ${OUT} pushd ${JOEY}/joeylib/src iix assemble jIIgs.asm keep=31:/out/joey/jIIgsasm @@ -23,28 +25,36 @@ iix dumpobj +D 31:/out/joey/test &> test.dis || true php ${JOEY}/sdks/iix/ntconverter.php *.mod popd -rm JLSTATS || true -rm /tmp/import.po || true - -AC=${JOEY}/sdks/iix/ac/ -CADIUS=${JOEY}/sdks/iix/cadius/cadius.sh -IMPORT=/tmp/import.po - -${AC}/import.sh ${JOEY}/sdks/iix/IIgs/out/joey/test S16 -${AC}/import.sh ${JOEY}/joeylib/src/kanga.sta -${AC}/import.sh ${JOEY}/joeylib/src/font.sta -${AC}/import.sh ${JOEY}/joeylib/src/music MUS -${AC}/import.sh ${JOEY}/joeylib/src/music.w BIN - cp -f ${JOEY}/joeylib/lib/IIgs/Tool221#ba0000 ${JOEY}/dist/IIgs/. cp -f ${JOEY}/joeylib/src/joey.h ${JOEY}/dist/. -cp -f ${JOEY}/sdks/iix/IIgs/out/joey/joeylib ${JOEY}/dist/IIgs/joeylib#b20000 +cp -f ${OUT}/joeylib ${JOEY}/dist/IIgs/joeylib#b20000 if [ ! -z $1 ]; then + CADIUS=${JOEY}/sdks/iix/cadius-git/bin/release/cadius + IMPORT=/tmp/import.po + VOL=Import + + rm ${OUT}/JLSTATS 2> /dev/null || true + rm ${IMPORT} 2> /dev/null || true + + cp ${OUT}/test ${OUT}/Test#B30000 + cp ${JOEY}/joeylib/src/kanga.sta ${OUT}/kanga.sta#060000 + cp ${JOEY}/joeylib/src/font.sta ${OUT}/font.sta#060000 + cp ${JOEY}/joeylib/src/music ${OUT}/music#D50000 + cp ${JOEY}/joeylib/src/music.w ${OUT}/music.w#060000 + + ${CADIUS} createvolume ${IMPORT} ${VOL} 32MB > /dev/null + ${CADIUS} createfolder ${IMPORT} ${VOL}/data > /dev/null + ${CADIUS} addfile ${IMPORT} ${VOL} ${OUT}/Test#b30000 > /dev/null + ${CADIUS} addfile ${IMPORT} ${VOL}/data ${OUT}/kanga.sta#060000 > /dev/null + ${CADIUS} addfile ${IMPORT} ${VOL}/data ${OUT}/font.sta#060000 > /dev/null + ${CADIUS} addfile ${IMPORT} ${VOL}/data ${OUT}/music#D50000 > /dev/null + ${CADIUS} addfile ${IMPORT} ${VOL}/data ${OUT}/music.w#060000 > /dev/null + pushd ${JOEY}/sdks/iix/gsplus ./gsplus -config IIgsTest.cfg || true popd echo "" - ${AC}/export.sh JLSTATS - cat JLSTATS + ${CADIUS} extractfile ${IMPORT} ${VOL}/JLSTATS ${OUT} > /dev/null + cat ${OUT}/JLSTATS#040000 2> /dev/null fi diff --git a/joeylib.pro b/joeylib.pro index 1f77d5c..1cc8248 100644 --- a/joeylib.pro +++ b/joeylib.pro @@ -43,5 +43,3 @@ SDL_MIXER_LIBS = \ LIBS += \ $$SDL_LIBS \ $$SDL_MIXER_LIBS - -DISTFILES += diff --git a/src/jIIgs.asm b/src/jIIgs.asm index 4629804..c85e5c1 100644 --- a/src/jIIgs.asm +++ b/src/jIIgs.asm @@ -25,9 +25,9 @@ SHRShad gequ $012000 -savedDBR data ; Storage for Data Bank Register - ds 2 ; 16 bits - end ; Used by jIIgs.macro +;savedDBR data ; Storage for Data Bank Register +; ds 2 ; 16 bits +; end ; Used by jIIgs.macro ScanTable data ds 400 ; 400 bytes for scanline offsets diff --git a/src/jIIgs.c b/src/jIIgs.c index 670ea5e..276ccd4 100644 --- a/src/jIIgs.c +++ b/src/jIIgs.c @@ -45,13 +45,13 @@ typedef struct { } _jlPascalStringT; -extern void asmBorder(int c); +extern void asmBorder(jint16 c); extern void asmGrOff(void); extern void asmGrOn(void); //extern int asmJoy(int which); extern int asmJoy(void); extern void asmSlam(void); -extern void asmStart(int myID, int hertzBy10); +extern void asmStart(jint16 myID, jint16 hertzBy10); extern void asmStop(void); @@ -78,11 +78,11 @@ static byte *BORDER = (byte *)0xE0C034; static byte _jlBorderSaved; -static int _jlMyID; -static int _jlMemID; -static int _jlMusicMemID; +static jint16 _jlMyID; +static jint16 _jlMemID; +static jint16 _jlMusicMemID; static Handle _jlSHRShadowHandle; -static int _jlHertz; +static jint16 _jlHertz; #ifdef JOEY_DEBUG @@ -115,10 +115,10 @@ void jlDrawClear(void) { int jlGameGetAxis(byte which) { - static bool xRead = true; - static bool yRead = true; - static int paddles = 0; - int r; + static bool xRead = true; + static bool yRead = true; + static jint16 paddles = 0; + jint16 r; if (which == 0) { if (xRead) { @@ -227,9 +227,10 @@ void jlSoundMusicPause(void) { void jlSoundMusicPlay(char *name) { + char *temp = jlUtilMakePathname(name, NULL); _jlPascalStringT file; - strcpy(file.text, name); - file.length = strlen(name); + strcpy(file.text, temp); + file.length = strlen(temp); NTStartUp(_jlMusicMemID); JOEY_CHECK_TOOL_ERROR("NTStartup") NTLoadOneMusic((Pointer)&file); @@ -308,9 +309,9 @@ void jlUtilShutdown(void) { } -void jlUtilStartup(char *appName) { +void jlUtilStartup(char *appTitle) { - (void)appName; + (void)appTitle; // Unused on IIgs // Start up neded tools TLStartUp(); diff --git a/src/jIIgs.macro b/src/jIIgs.macro index 0f52cc7..94db906 100644 --- a/src/jIIgs.macro +++ b/src/jIIgs.macro @@ -1,3 +1,24 @@ +;---------------------------------------- +; JoeyLib +; Copyright (C) 2018 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. +;---------------------------------------- + ; ; Based on M16.cc from ORCA/C ; @@ -47,8 +68,8 @@ ; === START OF OUR MODIFICATION === phb ; Push Data Bank Register phb ; Push Data Bank Register - pla ; Pull Accumulator - sta >savedDBR ; Store Accumulator in savedDBR (Data Bank Register) +; pla ; Pull Accumulator +; sta >savedDBR ; Store Accumulator in savedDBR (Data Bank Register) phk ; Push K (Program Bank Register) plb ; Pull Data Bank Register ; === END OF OUR MODIFICATION === @@ -61,9 +82,9 @@ &lab anop ; === START OF OUR MODIFICATION === - using savedDBR - lda >savedDBR ; Load our saved Data Bank Register - pha ; Push the C Accumulator +; using savedDBR +; lda >savedDBR ; Load our saved Data Bank Register +; pha ; Push the C Accumulator plb ; Pull Data Bank Register plb ; Pull Data Bank Register ; === END OF OUR MODIFICATION === diff --git a/src/jPC.c b/src/jPC.c index 8f5b620..ef0c8e4 100644 --- a/src/jPC.c +++ b/src/jPC.c @@ -36,12 +36,12 @@ static jlStaT *_jlBackingStore = NULL; // 4 bit representatio static SDL_Texture *_jlTexture = NULL; // Video card representation in ARGB static SDL_PixelFormat *_jlPixelFormat = NULL; // Pixel format of _jlTexture static bool _jlIsRunning = true; -static int _jlNumKeysDown = 0; +static jint16 _jlNumKeysDown = 0; static char _jlLastKey = 0; static Mix_Music *_jlMusicHandle = NULL; static SDL_GameController **_jlControllers = NULL; -static int _jlControllerCount = 0; -static unsigned int _jlTimerValue = 0; +static jint16 _jlControllerCount = 0; +static juint16 _jlTimerValue = 0; static SDL_TimerID _jlTimerId = 0; @@ -155,7 +155,7 @@ void jlDisplayPresent(void) { } -void jlDrawBlit8x8(jlStaT *sta, int cx1, int cy1, int cx2, int cy2) { +void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) { int o1; int o2; int x; @@ -179,13 +179,13 @@ void jlDrawClear(void) { } -byte jlDrawGetPixel(int x, int y) { +byte jlDrawGetPixel(jint16 x, jint16 y) { int p = x / 2 + y * 160; return (jlUtilIsOdd(x) ? _jlBackingStore->pixels[p].l : _jlBackingStore->pixels[p].r); } -void jlDrawPoint(int x, int y) { +void jlDrawPoint(jint16 x, jint16 y) { jlPixelPairT *pixelPair = _jlBackingStore->pixels + (y * 160) + (x / 2); if (jlUtilIsOdd(x)) { pixelPair->l = _jlDrawColor; @@ -195,7 +195,7 @@ void jlDrawPoint(int x, int y) { } -int jlGameGetAxis(byte which) { +jint16 jlGameGetAxis(byte which) { SDL_GameControllerAxis axis; short int unscaled; short int max = SHRT_MIN; @@ -288,7 +288,7 @@ bool jlSoundIsPlaying(jlSoundT *sound) { bool _jlSoundLoad(jlSoundT **sound, char *filename) { bool result = false; Mix_Chunk *sample; - sample = Mix_LoadWAV(filename); + sample = Mix_LoadWAV(jlUtilMakePathname(filename, "ogg")); if (sample) { if (*sound != NULL) { jlSoundFree(*sound); @@ -321,16 +321,14 @@ void jlSoundMusicPause(void) { void jlSoundMusicPlay(char *name) { - char temp[256]; if (_jlMusicHandle != NULL) { jlSoundMusicStop(); } - snprintf(temp, 256, "%s.mod", name); - _jlMusicHandle = Mix_LoadMUS(temp); + _jlMusicHandle = Mix_LoadMUS(jlUtilMakePathname(name, "mod")); if (_jlMusicHandle != NULL) { Mix_PlayMusic(_jlMusicHandle, 1); } else { - printf("Unable to load %s\n", temp); + printf("Unable to load %s\n", jlUtilMakePathname(name, "mod")); } } @@ -347,7 +345,7 @@ void jlSoundMusicStop(void) { void jlSoundPlay(jlSoundT *sound) { - sound->channel = Mix_PlayChannel(-1, (Mix_Chunk *)sound->data, 0); + sound->channel = (jint16)Mix_PlayChannel(-1, (Mix_Chunk *)sound->data, 0); } @@ -484,7 +482,7 @@ void jlUtilShutdown(void) { } -void jlUtilStartup(char *appName) { +void jlUtilStartup(char *appTitle) { int flags; int result; @@ -516,7 +514,7 @@ void jlUtilStartup(char *appName) { } // Create a window and renderer using SDL - _jlWindow = SDL_CreateWindow(appName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 400, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + _jlWindow = SDL_CreateWindow(appTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 400, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); _jlRenderer = SDL_CreateRenderer(_jlWindow, -1, SDL_RENDERER_SOFTWARE); _jlTexture = SDL_CreateTexture(_jlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 200); _jlPixelFormat = SDL_AllocFormat(SDL_GetWindowPixelFormat(_jlWindow)); @@ -541,6 +539,6 @@ Uint32 _jlUtilTimer(Uint32 interval, void *param) { } -unsigned int jlUtilTimer(void) { +juint16 jlUtilTimer(void) { return _jlTimerValue; } diff --git a/src/joey.c b/src/joey.c index 46f3b10..d514716 100644 --- a/src/joey.c +++ b/src/joey.c @@ -50,9 +50,9 @@ typedef struct { - int StartX; - int EndX; - int Y; + jint16 StartX; + jint16 EndX; + jint16 Y; signed char Dir; // 'signed' needs to be specified for ORCA/C bool ScanLeft; bool ScanRight; @@ -60,9 +60,11 @@ typedef struct { } _jlScanDataT; -byte _jlDrawColor = 15; // Color in lower nibble only -byte _jlDrawColorNibbles = (15 << 4) + 15; // Color in both nibbles -byte _jlBorderColor = 0; +byte _jlDrawColor = 15; // Color in lower nibble only +byte _jlDrawColorNibbles = (15 << 4) + 15; // Color in both nibbles +byte _jlBorderColor = 0; +char *_jlAppName = NULL; +char _jlTempString[1024]; static jlColorT _jlDefaultPalette[16]; @@ -70,10 +72,10 @@ static jlStackT *_jlFillStackTop = NULL; static byte _jlDrawFillColor = 0; -void _jlDrawCircleClipped(int x0, int y0, int radius); -void _jlDrawFill(int x, int y, bool how); -void _jlDrawFillAddLine(int startX, int endX, int y, int ignoreStart, int ignoreEnd, char dir, bool isNextInDir, bool how); -_jlScanDataT *_jlDrawFillNewSegment(int startX, int endX, int y, signed char dir, bool scanLeft, bool scanRight); +void _jlDrawCircleClipped(jint16 x0, jint16 y0, jint16 radius); +void _jlDrawFill(jint16 x, jint16 y, bool how); +void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart, jint16 ignoreEnd, char dir, bool isNextInDir, bool how); +_jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed char dir, bool scanLeft, bool scanRight); #ifdef JOEY_DEBUG @@ -87,7 +89,7 @@ static long _jlBlocksNeeded = 0; static bool _jlMemoryStarted = false; void _jlFree(void **pointer) { - int i; + jint16 i; _jlTotalFrees++; if (*pointer != NULL) { @@ -106,8 +108,8 @@ void _jlFree(void **pointer) { } } -void *_jlMalloc(size_t size, int line, char *file) { - int i; +void *_jlMalloc(size_t size, jint16 line, char *file) { + jint16 i; if (!_jlMemoryStarted) { memset(_jlMemoryBlocks, 0, sizeof(_jlMemoryBlocks)); @@ -137,7 +139,7 @@ void *_jlMalloc(size_t size, int line, char *file) { } void *_jlRealloc(void *pointer, size_t size) { - int i = 0; + jint16 i = 0; size_t diff = 0; if (pointer != NULL) { @@ -169,7 +171,7 @@ void jlDisplayBorder(jlBorderColorsE color) { } -void jlDrawBox(int x1, int y1, int x2, int y2) { +void jlDrawBox(jint16 x1, jint16 y1, jint16 x2, jint16 y2) { jlDrawLine(x1, y1, x2, y1); jlDrawLine(x2, y1, x2, y2); jlDrawLine(x2, y2, x1, y2); @@ -177,20 +179,20 @@ void jlDrawBox(int x1, int y1, int x2, int y2) { } -void jlDrawBoxFilled(int x1, int y1, int x2, int y2) { - int y; +void jlDrawBoxFilled(jint16 x1, jint16 y1, jint16 x2, jint16 y2) { + jint16 y; for (y=y1; y<=y2; y++) { jlDrawLine(x1, y, x2, y); } } -void _jlDrawCircleClipped(int x0, int y0, int radius) { - int x = radius-1; - int y = 0; - int dx = 1; - int dy = 1; - int err = dx - (radius << 1); +void _jlDrawCircleClipped(jint16 x0, jint16 y0, jint16 radius) { + jint16 x = radius-1; + jint16 y = 0; + jint16 dx = 1; + jint16 dy = 1; + jint16 err = dx - (jint16)(radius << 1); while (x >= y) { if ((x0 + x < 320) && (y0 + y < 200)) jlDrawPoint(x0 + x, y0 + y); @@ -217,12 +219,12 @@ void _jlDrawCircleClipped(int x0, int y0, int radius) { } -void jlDrawCircle(int x0, int y0, int radius) { - int x = radius-1; - int y = 0; - int dx = 1; - int dy = 1; - int err = dx - (radius << 1); +void jlDrawCircle(jint16 x0, jint16 y0, jint16 radius) { + jint16 x = radius-1; + jint16 y = 0; + jint16 dx = 1; + jint16 dy = 1; + jint16 err = dx - (jint16)(radius << 1); // Is any of this going to be off the screen? //***TODO*** All our drawing primitives should do this. @@ -263,10 +265,10 @@ void jlDrawColor(byte index) { // http://members.chello.at/~easyfilter/bresenham.html -void jlDrawEllipse(int x0, int y0, int x1, int y1) { - int a = abs(x1-x0), b = abs(y1-y0), b1 = b&1; /* values of diameter */ - long dx = 4*(1-a)*b*b, dy = 4*(b1+1)*a*a; /* error increment */ - long err = dx+dy+b1*a*a, e2; /* error of 1.step */ +void jlDrawEllipse(jint16 x0, jint16 y0, jint16 x1, jint16 y1) { + jint16 a = (jint16)abs(x1-x0), b = (jint16)abs(y1-y0), b1 = b&1; /* values of diameter */ + long dx = 4*(1-a)*b*b, dy = 4*(b1+1)*a*a; /* error increment */ + long err = dx+dy+b1*a*a, e2; /* error of 1.step */ if (x0 > x1) { x0 = x1; x1 += a; } /* if called with swapped points */ if (y0 > y1) y0 = y1; /* .. exchange them */ @@ -292,7 +294,7 @@ void jlDrawEllipse(int x0, int y0, int x1, int y1) { } -_jlScanDataT *_jlDrawFillNewSegment(int startX, int endX, int y, signed char dir, bool scanLeft, bool scanRight) { +_jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed char dir, bool scanLeft, bool scanRight) { _jlScanDataT *s = (_jlScanDataT *)jlMalloc(sizeof(_jlScanDataT)); s->StartX = startX; s->EndX = endX; @@ -304,9 +306,9 @@ _jlScanDataT *_jlDrawFillNewSegment(int startX, int endX, int y, signed char dir } -void _jlDrawFillAddLine(int startX, int endX, int y, int ignoreStart, int ignoreEnd, char dir, bool isNextInDir, bool how) { - int regionStart = -1; - int x; +void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart, jint16 ignoreEnd, char dir, bool isNextInDir, bool how) { + jint16 regionStart = -1; + jint16 x; for (x=startX; x= x1) { dx = x2 - x1; @@ -449,6 +456,7 @@ void jlDrawLine(int x1, int y1, int x2, int y2) { void jlKeyWaitForAny(void) { + //***TODO*** I don't think this does what we think it does. while (!jlKeyPressed() && !jlUtilMustExit()) ; jlKeyRead(); while (jlKeyPressed() && !jlUtilMustExit()) ; @@ -518,7 +526,7 @@ bool _jlStaLoad(jlStaT **sta, char *filename) { } s = (jlStaT *)*sta; // Load into it. - f = fopen(filename, "rb"); + f = fopen(jlUtilMakePathname(filename, "sta"), "rb"); if (f != NULL) { if (fread(s, sizeof(jlStaT), 1, f) > 0) { // Is this a valid image file? @@ -536,7 +544,7 @@ bool jlStaSave(jlStaT *sta, char *filename) { bool result = false; FILE *f; - f = fopen(filename, "wb"); + f = fopen(jlUtilMakePathname(filename, "sta"), "wb"); if (f != NULL) { if (fwrite(sta, sizeof(jlStaT), 1, f) > 0) { result = true; @@ -549,7 +557,7 @@ bool jlStaSave(jlStaT *sta, char *filename) { __attribute__((__format__ (__printf__, 1, 0))) void jlUtilDie(const char *why, ...) { #ifdef JOEY_DEBUG - int i; + jint16 i; FILE *f = NULL; char msg[80]; // Very short messages (screen width). Be careful! va_list va; @@ -558,7 +566,7 @@ void jlUtilDie(const char *why, ...) { vsprintf(msg, why, va); va_end(va); - f = fopen("JLSTATS", "wt"); + f = fopen("JLSTATS", "wt"); // This doesn't use jlUtilMakePathname if (f != NULL) { fprintf(f, "JoeyLib Statistics\n\n"); fprintf(f, " Allocations: %ld\n", _jlTotalAllocations); @@ -583,6 +591,25 @@ void jlUtilDie(const char *why, ...) { } +char *jlUtilMakePathname(char *filename, char *extension) { + char temp[2]; + + temp[0] = JOEY_PATH_SEPARATOR; + temp[1] = 0; + _jlTempString[0] = 0; + + strcat(_jlTempString, "data"); + strcat(_jlTempString, temp); + strcat(_jlTempString, filename); + if (extension != NULL) { + strcat(_jlTempString, "."); + strcat(_jlTempString, extension); + } + + return _jlTempString; +} + + void *_jlUtilStackPop(jlStackT **stack) { void *d = NULL; jlStackT *s; @@ -605,15 +632,15 @@ void _jlUtilStackPush(jlStackT **stack, void *data) { } -void jlVecDisplay(jlVecT *vec, int ox, int oy) { - int command; - int count; - int i; - int x1; - int y1; - int x2; - int y2; - long p = 0; +void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) { + jint16 command; + jint16 count; + jint16 i; + jint16 x1; + jint16 y1; + jint16 x2; + jint16 y2; + long p = 0; while (p < vec->length) { command = vec->data[p++]; @@ -631,7 +658,7 @@ void jlVecDisplay(jlVecT *vec, int ox, int oy) { case COMMAND_PLOT: count = vec->data[p++]; for (i=0; idata[p++] * VEC_SCALE_UP); + x1 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y1 = oy + vec->data[p++]; jlDrawPoint(x1, y1); } @@ -639,10 +666,10 @@ void jlVecDisplay(jlVecT *vec, int ox, int oy) { case COMMAND_LINE: count = vec->data[p++]; - x1 = ox + (int)(vec->data[p++] * VEC_SCALE_UP); + x1 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y1 = oy + vec->data[p++]; for (i=2; idata[p++] * VEC_SCALE_UP); + x2 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y2 = oy + vec->data[p++]; jlDrawLine(x1, y1, x2, y2); x1 = x2; @@ -653,7 +680,7 @@ void jlVecDisplay(jlVecT *vec, int ox, int oy) { case COMMAND_FILL: count = vec->data[p++]; for (i=0; idata[p++] * VEC_SCALE_UP); + x1 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y1 = oy + vec->data[p++]; jlDrawFill(x1, y1); } @@ -677,9 +704,9 @@ void jlVecDisplay(jlVecT *vec, int ox, int oy) { case COMMAND_HBOX: count = vec->data[p++]; for (i=0; idata[p++] * VEC_SCALE_UP); + x1 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y1 = oy + vec->data[p++]; - x2 = ox + (int)(vec->data[p++] * VEC_SCALE_UP); + x2 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y2 = oy + vec->data[p++]; jlDrawBox(x1, y1, x2, y2); } @@ -688,9 +715,9 @@ void jlVecDisplay(jlVecT *vec, int ox, int oy) { case COMMAND_FBOX: count = vec->data[p++]; for (i=0; idata[p++] * VEC_SCALE_UP); + x1 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y1 = oy + vec->data[p++]; - x2 = ox + (int)(vec->data[p++] * VEC_SCALE_UP); + x2 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y2 = oy + vec->data[p++]; jlDrawBoxFilled(x1, y1, x2, y2); } @@ -699,7 +726,7 @@ void jlVecDisplay(jlVecT *vec, int ox, int oy) { case COMMAND_FILLTO: count = vec->data[p++]; for (i=0; idata[p++] * VEC_SCALE_UP); + x1 = ox + (jint16)(vec->data[p++] * VEC_SCALE_UP); y1 = oy + vec->data[p++]; x2 =vec->data[p++]; jlDrawFillTo(x1, y1, (byte)x2); @@ -737,12 +764,12 @@ bool _jlVecLoad(jlVecT **vec, char *filename) { *vec = v; v = (jlVecT *)*vec; // Load into it. - f = fopen(filename, "rb"); + f = fopen(jlUtilMakePathname(filename, "vec"), "rb"); if (f != NULL) { fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); - v->length = (unsigned int)((unsigned long)size - (sizeof(char) * 3) + (sizeof(byte))); + v->length = (juint16)((unsigned long)size - (sizeof(char) * 3) + (sizeof(byte))); // Load header. v->id[0] = (char)fgetc(f); v->id[1] = (char)fgetc(f); diff --git a/src/joey.h b/src/joey.h index 3db6cb1..7402330 100644 --- a/src/joey.h +++ b/src/joey.h @@ -28,6 +28,77 @@ #include +// Determine platform and settings +#ifdef __linux__ + +#define JOEY_LINUX +#define JOEY_PC +#define JOEY_LITLE_ENDIAN +#define JOEY_PATH_SEPARATOR '/' +#define segment(x) +typedef short jint16; +typedef unsigned short juint16; + +#elif _WIN32 + +#define JOEY_WINDOWS +#define JOEY_PC +#define JOEY_LITLE_ENDIAN +#define JOEY_PATH_SEPARATOR '\\' +#define segment(x) +typedef short jint16; +typedef unsigned short juint16; + +#elif __APPLE__ + +#define JOEY_MACOS +#define JOEY_PC +#define JOEY_LITLE_ENDIAN +#define JOEY_PATH_SEPARATOR '/' +#define segment(x) +typedef short jint16; +typedef unsigned short juint16; + +#elif __ORCAC__ + +#define JOEY_IIGS +#define JOEY_LITLE_ENDIAN +#define JOEY_PATH_SEPARATOR '/' +#define __attribute__(x) +typedef int jint16; +typedef unsigned int juint16; +#ifdef JOEY_LIBRARY +#pragma noroot +segment "joeylib"; +#endif +#pragma memorymodel 1 +#pragma optimize -1 +#pragma lint -1 +#pragma debug 0 + +#elif AMIGA + +#define JOEY_AMIGA +#define JOEY_BIG_ENDIAN +#define JOEY_PATH_SEPARATOR '/' +#define __attribute__(x) +#define segment(x) +typedef int jint16; +typedef unsigned int juint16; + +#else + +#define JOEY_ST +#define JOEY_BIG_ENDIAN +#define JOEY_PATH_SEPARATOR '/' +#define __attribute__(x) +#define segment(x) +typedef int jint16; +typedef unsigned int juint16; + +#endif + + #ifndef bool #define bool unsigned char #define true 1 @@ -37,9 +108,10 @@ #define byte unsigned char -extern byte _jlDrawColor; -extern byte _jlDrawColorNibbles; -extern byte _jlBorderColor; +extern byte _jlDrawColor; +extern byte _jlDrawColorNibbles; +extern byte _jlBorderColor; +extern char _jlTempString[1024]; enum _jlBorderColorsE { @@ -76,8 +148,8 @@ typedef struct { } jlPixelPairT; typedef struct { - void *data; - int channel; + void *data; + jint16 channel; } jlSoundT; typedef struct { @@ -93,10 +165,10 @@ typedef struct _jlStackS { } jlStackT; typedef struct { - char id[3]; - byte version; - unsigned int length; - byte *data; + char id[3]; + byte version; + juint16 length; + byte *data; } jlVecT; @@ -109,14 +181,14 @@ typedef struct { void *addr; char *file; size_t size; - int line; + jint16 line; } jlMemoryBlockT; #define jlFree(p) _jlFree((void **)&(p)) void _jlFree(void **pointer); #define jlMalloc(s) _jlMalloc(s, __LINE__, __FILE__) -void *_jlMalloc(size_t size, int line, char *file); +void *_jlMalloc(size_t size, jint16 line, char *file); #define jlRealloc(p, s) _jlRealloc(p, s) void *_jlRealloc(void *pointer, size_t size); @@ -129,90 +201,45 @@ void *_jlRealloc(void *pointer, size_t size); #endif -// Determine platform and settings -#ifdef __linux__ - -#define JOEY_LINUX -#define JOEY_PC -#define JOEY_LITLE_ENDIAN -#define segment(x) - -#elif _WIN32 - -#define JOEY_WINDOWS -#define JOEY_PC -#define JOEY_LITLE_ENDIAN -#define segment(x) - -#elif __APPLE__ - -#define JOEY_MACOS -#define JOEY_PC -#define JOEY_LITLE_ENDIAN -#define segment(x) - -#elif __ORCAC__ - -#define JOEY_IIGS -#define JOEY_LITLE_ENDIAN -#define __attribute__(x) -#ifdef JOEY_LIBRARY -#pragma noroot -segment "joeylib"; -#endif -#pragma memorymodel 1 -#pragma optimize -1 -#pragma lint -1 -#pragma debug 0 - -#elif AMIGA - -#define JOEY_AMIGA -#define JOEY_BIG_ENDIAN -#define __attribute__(x) -#define segment(x) - -#else - -#define JOEY_ST -#define JOEY_BIG_ENDIAN -#define __attribute__(x) -#define segment(x) - -#endif - - void jlDisplayBorder(jlBorderColorsE color); void jlDisplayPresent(void); -void jlDrawBlit8x8(jlStaT *sta, int cx1, int cy1, int cx2, int cy2); -void jlDrawBox(int x1, int y1, int x2, int y2); -void jlDrawBoxFilled(int x1, int y1, int x2, int y2); -void jlDrawCircle(int x, int y, int radius); + +void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2); +void jlDrawBox(jint16 x1, jint16 y1, jint16 x2, jint16 y2); +void jlDrawBoxFilled(jint16 x1, jint16 y1, jint16 x2, jint16 y2); +void jlDrawCircle(jint16 x, jint16 y, jint16 radius); void jlDrawClear(void); void jlDrawColor(byte index); -void jlDrawEllipse(int x1, int y1, int x2, int y2); -void jlDrawFill(int x, int y); -void jlDrawFillTo(int x, int y, byte color); -byte jlDrawGetPixel(int x, int y); -void jlDrawLine(int x1, int y1, int x2, int y2); -void jlDrawPoint(int x, int y); -int jlGameGetAxis(byte which); +void jlDrawEllipse(jint16 x1, jint16 y1, jint16 x2, jint16 y2); +void jlDrawFill(jint16 x, jint16 y); +void jlDrawFillTo(jint16 x, jint16 y, byte color); +byte jlDrawGetColor(void); +byte jlDrawGetPixel(jint16 x, jint16 y); +void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2); +void jlDrawPoint(jint16 x, jint16 y); + +jint16 jlGameGetAxis(byte which); bool jlGameGetButton(byte which); + bool jlKeyPressed(void); char jlKeyRead(void); void jlKeyWaitForAny(void); + void jlPaletteDefault(void); void jlPaletteSet(byte index, byte r, byte g, byte b); + void jlSoundFree(jlSoundT *sound); bool jlSoundIsPlaying(jlSoundT *sound); #define jlSoundLoad(sound, filename) _jlSoundLoad((jlSoundT **)&(sound), filename) // Syntatic Sugar bool _jlSoundLoad(jlSoundT **sound, char *filename); + void jlSoundMusicContinue(void); bool jlSoundMusicIsPlaying(void); void jlSoundMusicPause(void); void jlSoundMusicPlay(char *name); void jlSoundMusicStop(void); void jlSoundPlay(jlSoundT *sound); + #define jlStaCopy(source, target) _jlStaCopy(source, (jlStaT **)&(target)) // Syntatic Sugar bool _jlStaCopy(jlStaT *source, jlStaT **target); #define jlStaCreate(sta) _jlStaCreate((jlStaT **)&(sta)) // Syntatic Sugar @@ -222,18 +249,22 @@ void jlStaFree(jlStaT *sta); #define jlStaLoad(sta, filename) _jlStaLoad((jlStaT **)&(sta), filename) // Syntatic Sugar bool _jlStaLoad(jlStaT **sta, char *filename); bool jlStaSave(jlStaT *sta, char *filename); + void jlUtilDie(const char *why, ...) __attribute__((noreturn)); void jlUtilIdle(void); -#define jlUtilIsOdd(x) (((x & 1) == 1) ? true:false) +#define jlUtilIsOdd(x) (((x & 1) == 1) ? true : false) +char *jlUtilMakePathname(char *filename, char *extension); bool jlUtilMustExit(void); void jlUtilShutdown(void) __attribute__((noreturn)); #define jlUtilStackPop(stack) _jlUtilStackPop((jlStackT **)&(stack)) // Syntatic Sugar void *_jlUtilStackPop(jlStackT **stack); #define jlUtilStackPush(stack, data) _jlUtilStackPush((jlStackT **)&(stack), data) // Syntatic Sugar void _jlUtilStackPush(jlStackT **stack, void *data); -void jlUtilStartup(char *appName); -unsigned int jlUtilTimer(void); -void jlVecDisplay(jlVecT *vec, int x, int y); +void jlUtilStartup(char *appTitle); +juint16 jlUtilTimer(void); +#define jlUtilTimeSpan(past, current) (past < current ? current - past : 65536 - past - current) + +void jlVecDisplay(jlVecT *vec, jint16 x, jint16 y); void jlVecFree(jlVecT *vec); #define jlVecLoad(vec, filename) _jlVecLoad((jlVecT **)&(vec), filename) // Syntatic Sugar bool _jlVecLoad(jlVecT **vec, char *filename); @@ -241,10 +272,10 @@ bool _jlVecLoad(jlVecT **vec, char *filename); #ifdef JOEY_IIGS // Inlined functions - asm code -extern void asmB88(byte *p, int cx1, int cy1, int cx2, int cy2); -extern void asmPoint(int color, int x, int y); -extern int asmGetPoint(int x, int y); -extern unsigned int asmGetVbl(void); +extern void asmB88(byte *p, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2); +extern void asmPoint(jint16 color, jint16 x, jint16 y); +extern jint16 asmGetPoint(jint16 x, jint16 y); +extern juint16 asmGetVbl(void); // Inlined functions #define jlDrawBlit8x8(sta, cx1, cy1, cx2, cy2) asmB88((byte *)sta->pixels, cx1, cy1, cx2, cy2); diff --git a/src/test.c b/src/test.c index c565e00..180922f 100644 --- a/src/test.c +++ b/src/test.c @@ -35,11 +35,11 @@ segment "testapp"; // Font hacking! __attribute__((__format__ (__printf__, 4, 0))) -void printAt(jlStaT *font, int cx, int cy, const char *what, ...) { - int x; - int y; - int counter; - char msg[40]; // Very short messages (screen width). Be careful! +void printAt(jlStaT *font, jint16 cx, jint16 cy, const char *what, ...) { + jint16 x; + jint16 y; + jint16 counter; + char msg[40]; // Very short messages (screen width). Be careful! va_list va; va_start(va, what); @@ -47,8 +47,8 @@ void printAt(jlStaT *font, int cx, int cy, const char *what, ...) { va_end(va); for (counter=0; counter<(int)strlen(msg); counter++) { - y = (msg[counter] - ' ') / 40; x = (msg[counter] - ' ') % 40; + y = (msg[counter] - ' ') / 40; jlDrawBlit8x8(font, x, y, counter + cx, cy); } } @@ -58,12 +58,12 @@ int main(void) { jlStaT *kanga = NULL; jlStaT *font = NULL; - int y; + jint16 y; jlUtilStartup("JoeyLib Test"); - jlStaLoad(kanga, "kanga.sta"); - jlStaLoad(font, "font.sta"); + jlStaLoad(kanga, "kanga"); + jlStaLoad(font, "font"); jlStaDisplay(kanga); jlDrawColor(1);