Renamed byte/bool/true/false/new to make C++ based tools happy.

This commit is contained in:
Scott Duensing 2021-04-19 19:20:07 -05:00
parent 379ba1318a
commit 9a897ec8ef
6 changed files with 214 additions and 194 deletions

View file

@ -29,8 +29,6 @@
#include <sound.h>
#include <MIDISynth.h>
#include <Orca.h>
#undef false
#undef true
#include "joey.h"
@ -76,17 +74,17 @@ extern pascal void NTPContinueMusic(void) inline(0x14DE, dispatcher);
char _jlKeyCheck(char key);
static byte *KEYBOARD = (byte *)0x00C000L;
static byte *KEYSTROBE = (byte *)0x00C010L;
static byte *BUTTON0 = (byte *)0x00C061L;
static byte *BUTTON1 = (byte *)0x00C062L;
static jbyte *KEYBOARD = (jbyte *)0x00C000L;
static jbyte *KEYSTROBE = (jbyte *)0x00C010L;
static jbyte *BUTTON0 = (jbyte *)0x00C061L;
static jbyte *BUTTON1 = (jbyte *)0x00C062L;
static jlPixelPairT *SHRPIXELS = (jlPixelPairT *)0x012000L; // Shadow of 0xE12000
static byte *SHRSCB = (byte *)0x019D00L; // Shadow of 0xE19D00
static jbyte *SHRSCB = (jbyte *)0x019D00L; // Shadow of 0xE19D00
static jlColorT *SHRCOLORS = (jlColorT *)0x019E00L; // Shadow of 0xE19E00
static byte *BORDER = (byte *)0xE0C034L;
static jbyte *BORDER = (jbyte *)0xE0C034L;
static byte _jlBorderSaved;
static jbyte _jlBorderSaved;
static jint16 _jlHertz;
@ -129,7 +127,7 @@ void jlDrawSurfaceSet(jlSurfaceT target) {
}
int jlGameGetAxis(byte which) {
int jlGameGetAxis(jbyte which) {
jint16 r;
if (which == 0) {
@ -142,20 +140,20 @@ int jlGameGetAxis(byte which) {
}
bool jlGameGetButton(byte which) {
if (which > 0) return (bool)(*BUTTON1 > 127);
return (bool)(*BUTTON0 > 127);
jbool jlGameGetButton(jbyte which) {
if (which > 0) return (jbool)(*BUTTON1 > 127);
return (jbool)(*BUTTON0 > 127);
}
bool _jlImgCreate(jlImgT **img) {
jbool _jlImgCreate(jlImgT **img) {
jlImgT *t = NULL;
// Are we loading into a new image?
if (*img == NULL) {
t = (jlImgT *)jlMalloc(sizeof(jlImgT));
if (t == NULL) {
return false;
return jfalse;
}
*img = t;
}
@ -167,7 +165,7 @@ bool _jlImgCreate(jlImgT **img) {
memcpy(t->palette, SHRCOLORS, sizeof(t->palette));
memcpy(t->pixels, SHRPIXELS, sizeof(t->pixels));
*img = t;
return true;
return jtrue;
}
@ -200,11 +198,11 @@ char _jlKeyCheck(char key) {
}
bool jlKeyPressed(void) {
bool result = false;
jbool jlKeyPressed(void) {
jbool result = jfalse;
// On other platforms we should call jlIdle() here.
if ((*KEYBOARD & 0x80) != 0) {
result = (_jlKeyCheck(*KEYBOARD & 0x7F) != 0);
result = (_jlKeyCheck(*KEYBOARD & 0x7F) != 0) ? jtrue : jfalse;
}
return result;
}
@ -220,7 +218,7 @@ char jlKeyRead(void) {
}
void jlPaletteSet(byte index, byte r, byte g, byte b) {
void jlPaletteSet(jbyte index, jbyte r, jbyte g, jbyte b) {
SHRCOLORS[index].r = r;
SHRCOLORS[index].g = g;
SHRCOLORS[index].b = b;
@ -237,8 +235,8 @@ void jlSoundModContinue(void) {
}
bool jlSoundModIsPlaying(void) {
return (NTPGetPlayingMusic() != 0xFFFF);
jbool jlSoundModIsPlaying(void) {
return (NTPGetPlayingMusic() != 0xFFFF) ? jtrue : jfalse;
}
@ -256,7 +254,7 @@ void jlSoundModPlay(char *name) {
JOEY_CHECK_TOOL_ERROR("NTPStartup")
NTPLoadOneMusic((Pointer)&file);
JOEY_CHECK_TOOL_ERROR("NTPLoadOneMusic")
NTPPlayMusic(false);
NTPPlayMusic(jfalse);
JOEY_CHECK_TOOL_ERROR("NTPPlayMusic")
}

View file

@ -124,7 +124,7 @@ void jlDrawClear(void) {
}
byte jlDrawPixelGet(jint16 x, jint16 y) {
jbyte jlDrawPixelGet(jint16 x, jint16 y) {
jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
int p = x / 2 + y * 160;
return (jlUtilIsOdd(x) ? target[p].l : target[p].r);
@ -153,14 +153,14 @@ void jlDrawSurfaceSet(jlSurfaceT target) {
}
bool _jlImgCreate(jlImgT **img) {
jbool _jlImgCreate(jlImgT **img) {
jlImgT *t = NULL;
// Are we loading into a new image?
if (*img == NULL) {
t = (jlImgT *)jlMalloc(sizeof(jlImgT));
if (t == NULL) {
return false;
return jfalse;
}
*img = t;
}
@ -175,7 +175,7 @@ bool _jlImgCreate(jlImgT **img) {
memcpy(t->pixels, _jlBackingStore->pixels, sizeof(t->pixels));
}
*img = t;
return true;
return jtrue;
}
@ -185,7 +185,7 @@ void jlImgDisplay(jlImgT *img) {
}
void jlPaletteSet(byte index, byte r, byte g, byte b) {
void jlPaletteSet(jbyte index, jbyte r, jbyte g, jbyte b) {
_jlBackingStore->palette[index].r = r;
_jlBackingStore->palette[index].g = g;
_jlBackingStore->palette[index].b = b;

View file

@ -40,7 +40,7 @@ static SDL_Window *_jlWindow = NULL;
static SDL_Renderer *_jlRenderer = NULL;
static SDL_Texture *_jlTexture = NULL; // Video card representation in ARGB
static SDL_PixelFormat *_jlPixelFormat = NULL; // Pixel format of _jlTexture
static bool _jlIsRunning = true;
static jbool _jlIsRunning = jtrue;
static jint16 _jlNumKeysDown = 0;
static char _jlLastKey = 0;
static Mix_Music *_jlMusicHandle = NULL;
@ -159,7 +159,7 @@ void jlDisplayPresent(void) {
}
jint16 jlGameGetAxis(byte which) {
jint16 jlGameGetAxis(jbyte which) {
SDL_GameControllerAxis axis;
short int unscaled;
short int max = SHRT_MIN;
@ -191,10 +191,10 @@ jint16 jlGameGetAxis(byte which) {
}
bool jlGameGetButton(byte which) {
jbool jlGameGetButton(jbyte which) {
SDL_GameControllerButton button;
int x;
bool pressed = false;
jbool pressed = jfalse;
jlUtilIdle();
@ -206,7 +206,7 @@ bool jlGameGetButton(byte which) {
for (x=0; x<_jlControllerCount; x++) {
if (SDL_GameControllerGetButton(_jlControllers[x], button)) {
pressed = true;
pressed = jtrue;
break;
}
}
@ -215,7 +215,7 @@ bool jlGameGetButton(byte which) {
}
bool jlKeyPressed(void) {
jbool jlKeyPressed(void) {
jlUtilIdle();
return (_jlNumKeysDown > 0);
}
@ -237,13 +237,13 @@ void jlSoundFree(jlSoundT *sound) {
}
bool jlSoundIsPlaying(jlSoundT *sound) {
jbool jlSoundIsPlaying(jlSoundT *sound) {
return (Mix_Playing(sound->channel) > 0);
}
bool _jlSoundLoad(jlSoundT **sound, char *filename) {
bool result = false;
jbool _jlSoundLoad(jlSoundT **sound, char *filename) {
jbool result = jfalse;
Mix_Chunk *sample;
sample = Mix_LoadWAV(jlUtilMakePathname(filename, "ogg"));
if (sample) {
@ -254,7 +254,7 @@ bool _jlSoundLoad(jlSoundT **sound, char *filename) {
if (t != NULL) {
t->data = (void *)sample;
*sound = t;
result = true;
result = jtrue;
}
}
return result;
@ -266,8 +266,8 @@ void jlSoundModContinue(void) {
}
bool jlSoundModIsPlaying(void) {
return (bool)Mix_PlayingMusic();
jbool jlSoundModIsPlaying(void) {
return (jbool)Mix_PlayingMusic();
}
@ -381,7 +381,7 @@ void jlUtilIdle(void) {
break;
case SDL_QUIT:
_jlIsRunning = false;
_jlIsRunning = jfalse;
break;
}
}
@ -392,7 +392,7 @@ void jlUtilIdle(void) {
}
bool jlUtilMustExit(void) {
jbool jlUtilMustExit(void) {
return !_jlIsRunning;
}

View file

@ -62,30 +62,30 @@ typedef struct {
jint16 EndX;
jint16 Y;
signed char Dir; // 'signed' needs to be specified for ORCA/C
bool ScanLeft;
bool ScanRight;
bool padding; // Aligns structure on x86
jbool ScanLeft;
jbool ScanRight;
jbool padding; // Aligns structure on x86
} _jlScanDataT;
jlSurfaceT _jlDrawTarget = JOEY_DISPLAY;
jlSurfaceT _jlDrawTargetActual = NULL;
byte _jlDrawColor = 15; // Color in lower nibble only
byte _jlDrawColorNibbles = (15 << 4) + 15; // Color in both nibbles
byte _jlBorderColor = 0;
jbyte _jlDrawColor = 15; // Color in lower nibble only
jbyte _jlDrawColorNibbles = (15 << 4) + 15; // Color in both nibbles
jbyte _jlBorderColor = 0;
char _jlTempString[1024]; // Used internally for pathname operations
static jlColorT _jlDefaultPalette[16];
static jlStackT *_jlFillStackTop = NULL;
static byte _jlDrawFillColor = 0;
static jbyte _jlDrawFillColor = 0;
static juint32 _jlSeed = 0;
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);
void _jlDrawFill(jint16 x, jint16 y, jbool how);
void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart, jint16 ignoreEnd, char dir, jbool isNextInDir, jbool how);
_jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed char dir, jbool scanLeft, jbool scanRight);
#ifdef JOEY_DEBUG
@ -93,12 +93,12 @@ _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 bool _jlMemoryStarted = false;
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;
@ -125,7 +125,7 @@ void *_jlMalloc(size_t size, jint16 line, char *file) {
if (!_jlMemoryStarted) {
memset(_jlMemoryBlocks, 0, sizeof(_jlMemoryBlocks));
_jlMemoryStarted = true;
_jlMemoryStarted = jtrue;
}
_jlTotalAllocations++;
@ -182,7 +182,7 @@ void *_jlRealloc(void *pointer, size_t size) {
#ifndef JL_HAS_DISPLAYBORDER
void jlDisplayBorder(jlBorderColorsE color) {
_jlBorderColor = (byte)color;
_jlBorderColor = (jbyte)color;
}
#endif
@ -219,7 +219,7 @@ void jlDrawBlit8x8a(jlSurfaceT source, jlStnT *stencil, jint16 sx, jint16 sy, ji
#ifndef JL_HAS_DRAWBLITMAP
//***FIX*** This no longer does what we want since blitting source addresses are now in pixels. Fix!
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source) {
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, jbyte *mapData, juint16 stride, jlSurfaceT source) {
// startX = start tile for drawing - in pixels
// startY = start tile for drawing - in pixels
// width = tiles to draw horizontally - in tiles
@ -229,8 +229,8 @@ void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, by
// tiles = surface to fetch tile data from
jint16 x;
jint16 y;
byte tileX;
byte tileY;
jbyte tileX;
jbyte tileY;
juint16 offset = 0;
jint16 endX = width * 8 + startX;
jint16 endY = height * 8 + startY;
@ -346,16 +346,16 @@ void jlDrawClear(void) {
#ifndef JL_HAS_DRAWCOLORGET
byte jlDrawColorGet(void) {
jbyte jlDrawColorGet(void) {
return _jlDrawColor;
}
#endif
#ifndef JL_HAS_DRAWCOLORSET
void jlDrawColorSet(byte index) {
void jlDrawColorSet(jbyte index) {
_jlDrawColor = index;
_jlDrawColorNibbles = (byte)((index << 4) + index);
_jlDrawColorNibbles = (jbyte)((index << 4) + index);
}
#endif
@ -393,7 +393,7 @@ void jlDrawEllipse(jint16 x0, jint16 y0, jint16 x1, jint16 y1) {
#if !defined(JL_HAS_DRAWFILL) && !defined(JL_HASDRAWFILLTO)
_jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed char dir, bool scanLeft, bool scanRight) {
_jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed char dir, jbool scanLeft, jbool scanRight) {
_jlScanDataT *s = (_jlScanDataT *)jlMalloc(sizeof(_jlScanDataT));
s->StartX = startX;
s->EndX = endX;
@ -405,7 +405,7 @@ _jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed
}
void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart, jint16 ignoreEnd, char dir, bool isNextInDir, bool how) {
void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart, jint16 ignoreEnd, char dir, jbool isNextInDir, jbool how) {
jint16 regionStart = -1;
jint16 x;
@ -416,7 +416,7 @@ void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart
jlDrawPixelSet(x, y);
if (regionStart < 0) regionStart = x;
} else if (regionStart >= 0) {
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, false));
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, jfalse));
regionStart = -1;
}
} else {
@ -425,20 +425,20 @@ void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart
jlDrawPixelSet(x, y);
if (regionStart < 0) regionStart = x;
} else if (regionStart >= 0) {
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, false));
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, jfalse));
regionStart = -1;
}
}
if (!isNextInDir && x < ignoreEnd && x >= ignoreStart) x = ignoreEnd-1;
}
if (regionStart >= 0) {
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, true));
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, jtrue));
}
}
// Stole this from http://www.adammil.net/blog/v126_A_More_Efficient_Flood_Fill.html
void _jlDrawFill(jint16 x, jint16 y, bool how) {
void _jlDrawFill(jint16 x, jint16 y, jbool how) {
jint16 height = 200;
jint16 width = 320;
_jlScanDataT *r;
@ -450,7 +450,7 @@ void _jlDrawFill(jint16 x, jint16 y, bool how) {
jlDrawPixelSet(x, y);
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(x, x+1, y, 0, true, true));
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(x, x+1, y, 0, jtrue, jtrue));
while ((r = jlUtilStackPop(_jlFillStackTop)) != NULL) {
startX = r->StartX;
endX = r->EndX;
@ -481,15 +481,15 @@ void _jlDrawFill(jint16 x, jint16 y, bool how) {
#ifndef JL_HAS_DRAWFILL
void jlDrawFill(jint16 x, jint16 y) {
_jlDrawFillColor = jlDrawPixelGet(x, y);
_jlDrawFill(x, y, true);
_jlDrawFill(x, y, jtrue);
}
#endif
#ifndef JL_HAS_DRAWFILLTO
void jlDrawFillTo(jint16 x, jint16 y, byte color) {
void jlDrawFillTo(jint16 x, jint16 y, jbyte color) {
_jlDrawFillColor = color;
_jlDrawFill(x, y, false);
_jlDrawFill(x, y, jfalse);
}
#endif
@ -557,7 +557,7 @@ void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
#ifndef JL_HAS_DRAWPIXELGET
byte jlDrawPixelGet(jint16 x, jint16 y) {
jbyte jlDrawPixelGet(jint16 x, jint16 y) {
(void)x;
(void)y;
return 0;
@ -589,7 +589,7 @@ void jlDrawSurfaceSet(jlSurfaceT target) {
#ifndef JL_HAS_GAMEGETAXIS
jint16 jlGameGetAxis(byte which) {
jint16 jlGameGetAxis(jbyte which) {
(void)which;
return 0;
}
@ -597,35 +597,34 @@ jint16 jlGameGetAxis(byte which) {
#ifndef JL_HAS_GAMEGETBUTTON
bool jlGameGetButton(byte which) {
jbool jlGameGetButton(jbyte which) {
(void)which;
return false;
return jfalse;
}
#endif
#ifndef JL_HAS_IMGCOPY
bool _jlImgCopy(jlImgT *source, jlImgT **target) {
jbool _jlImgCopy(jlImgT *source, jlImgT **target) {
jlImgT *t = NULL;
// Are we copying into a new image?
if (*target == NULL) {
t = (jlImgT *)jlMalloc(sizeof(jlImgT));
if (t == NULL) {
return false;
return jfalse;
}
*target = t;
}
t = (jlImgT *)*target;
memcpy(*target, source, sizeof(jlImgT));
return true;
return jtrue;
}
#endif
#ifndef JL_HAS_IMGCREATE
bool _jlImgCreate(jlImgT **img) {
jbool _jlImgCreate(jlImgT **img) {
(void)img;
return false;
return jfalse;
}
#endif
@ -647,10 +646,10 @@ void jlImgFree(jlImgT *img) {
#ifndef JL_HAS_IMGLOAD
bool _jlImgLoad(jlImgT **img, char *filename) {
bool result = false;
jlImgT *s = NULL;
FILE *f = NULL;
jbool _jlImgLoad(jlImgT **img, char *filename) {
jbool result = jfalse;
jlImgT *s = NULL;
FILE *f = NULL;
// Are we loading into a new image?
if (*img == NULL) {
@ -662,12 +661,16 @@ bool _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?
if ((s->id[0] == 'I') && (s->id[1] == 'M') && (s->id[2] == 'G') && (s->version <= 0)) {
result = true;
result = jtrue;
}
}
fclose(f);
@ -678,14 +681,18 @@ bool _jlImgLoad(jlImgT **img, char *filename) {
#ifndef JL_HAS_IMGSAVE
bool jlImgSave(jlImgT *img, char *filename) {
bool result = false;
FILE *f;
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 = true;
result = jtrue;
}
}
return result;
@ -694,8 +701,8 @@ bool jlImgSave(jlImgT *img, char *filename) {
#ifndef JL_HAS_KEYPRESSED
bool jlKeyPressed(void) {
return false;
jbool jlKeyPressed(void) {
return jfalse;
}
#endif
@ -719,7 +726,7 @@ void jlKeyWaitForAny(void) {
#ifndef JL_HAS_PALETTEDEFAULT
void jlPaletteDefault(void) {
byte i;
jbyte i;
// Set palette.
_jlDefaultPalette[ 0].r = 0; _jlDefaultPalette[ 0].g = 0; _jlDefaultPalette[ 0].b = 0; // 000000 Black
_jlDefaultPalette[ 1].r = 0; _jlDefaultPalette[ 1].g = 0; _jlDefaultPalette[ 1].b = 10; // 0000AA Blue
@ -745,7 +752,7 @@ void jlPaletteDefault(void) {
#ifndef JL_HAS_PALETTESET
void jlPaletteSet(byte index, byte r, byte g, byte b) {
void jlPaletteSet(jbyte index, jbyte r, jbyte g, jbyte b) {
(void)index;
(void)r;
(void)g;
@ -770,18 +777,18 @@ void jlSoundFree(jlSoundT *sound) {
#ifndef JL_HAS_SOUNDISPLAYING
bool jlSoundIsPlaying(jlSoundT *sound) {
jbool jlSoundIsPlaying(jlSoundT *sound) {
(void)sound;
return false;
return jfalse;
}
#endif
#ifndef JL_HAS_SOUNDLOAD
bool _jlSoundLoad(jlSoundT **sound, char *filename) {
jbool _jlSoundLoad(jlSoundT **sound, char *filename) {
(void)sound;
(void)filename;
return false;
return jfalse;
}
#endif
@ -794,8 +801,8 @@ void jlSoundMidiContinue(void) {
#ifndef JL_HAS_SOUNDMIDIISPLAYING
bool jlSoundMidiIsPlaying(void) {
return false;
jbool jlSoundMidiIsPlaying(void) {
return jfalse;
}
#endif
@ -829,8 +836,8 @@ void jlSoundModContinue(void) {
#ifndef JL_HAS_SOUNDMODISPLAYING
bool jlSoundModIsPlaying(void) {
return false;
jbool jlSoundModIsPlaying(void) {
return jfalse;
}
#endif
@ -873,10 +880,10 @@ void jlStnFree(jlStnT *stn) {
#ifndef JL_HAS_STNLOAD
bool _jlStnLoad(jlStnT **stn, char *filename) {
bool result = false;
jlStnT *s = NULL;
FILE *f = NULL;
jbool _jlStnLoad(jlStnT **stn, char *filename) {
jbool result = jfalse;
jlStnT *s = NULL;
FILE *f = NULL;
// Are we loading into a new stencil?
if (*stn == NULL) {
@ -888,12 +895,16 @@ bool _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?
if ((s->id[0] == 'S') && (s->id[1] == 'T') && (s->id[2] == 'N') && (s->version <= 0)) {
result = true;
result = jtrue;
}
}
fclose(f);
@ -950,9 +961,9 @@ void jlUtilIdle(void) {
#ifndef JL_HAS_UTILINPUTREAD
bool jlUtilInputRead(byte *key) {
jbool jlUtilInputRead(jbyte *key) {
static bool debounceController = false;
static jbool debounceController = jfalse;
*key = 0;
@ -1009,7 +1020,7 @@ bool jlUtilInputRead(byte *key) {
break;
}
return true;
return jtrue;
}
// Joystick
@ -1023,16 +1034,16 @@ bool jlUtilInputRead(byte *key) {
// Debounce Joystick Input
if (debounceController) {
*key = 0;
return false;
return jfalse;
} else {
if (*key != 0) {
debounceController = true;
return true;
debounceController = jtrue;
return jtrue;
}
}
debounceController = false;
debounceController = jfalse;
return false;
return jfalse;
}
#endif
@ -1059,20 +1070,20 @@ char *jlUtilMakePathname(char *filename, char *extension) {
#ifndef JL_HAS_UTILMUSTEXIT
bool jlUtilMustExit(void) {
return false;
jbool jlUtilMustExit(void) {
return jfalse;
}
#endif
#ifndef JL_HAS_UTILNIBBLESWAP
void jlUtilNibbleSwap(byte *mem, jint16 count, byte old, byte new) {
void jlUtilNibbleSwap(jbyte *mem, jint16 count, jbyte oldValue, jbyte newValue) {
int x;
jlPixelPairT *b;
for (x=0; x<count; x++) {
b = (jlPixelPairT *)&mem[x];
if (b->l == old) b->l = new;
if (b->r == old) b->r = new;
if (b->l == oldValue) b->l = newValue;
if (b->r == oldValue) b->r = newValue;
}
}
#endif
@ -1180,7 +1191,7 @@ void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) {
case COMMAND_COLOR:
x1 = vec->data[p++];
jlDrawColorSet((byte)x1);
jlDrawColorSet((jbyte)x1);
break;
case COMMAND_CLEAR:
@ -1229,7 +1240,7 @@ void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) {
y1 = vec->data[p++];
x2 = vec->data[p++];
y2 = vec->data[p++];
jlPaletteSet((byte)x1,(byte)y1, (byte)x2, (byte)y2);
jlPaletteSet((jbyte)x1,(jbyte)y1, (jbyte)x2, (jbyte)y2);
}
break;
@ -1270,7 +1281,7 @@ void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) {
x1 = x1 + (jint16)(vec->data[p++] << 8);
y1 = oy + vec->data[p++];
x2 =vec->data[p++];
jlDrawFillTo(x1, y1, (byte)x2);
jlDrawFillTo(x1, y1, (jbyte)x2);
}
break;
@ -1292,11 +1303,11 @@ void jlVecFree(jlVecT *vec) {
#ifndef JL_HAS_VECLOAD
bool _jlVecLoad(jlVecT **vec, char *filename) {
bool result = false;
jlVecT *v = NULL;
FILE *f = NULL;
long size;
jbool _jlVecLoad(jlVecT **vec, char *filename) {
jbool result = jfalse;
jlVecT *v = NULL;
FILE *f = NULL;
long size;
// Are we loading into a new image?
if (*vec != NULL) {
@ -1309,22 +1320,26 @@ bool _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);
fseek(f, 0, SEEK_SET);
v->length = (juint16)((unsigned long)size - (sizeof(char) * 3) + (sizeof(byte)));
v->length = (juint16)((unsigned long)size - (sizeof(char) * 3) + (sizeof(jbyte)));
// Load header.
v->id[0] = (char)fgetc(f);
v->id[1] = (char)fgetc(f);
v->id[2] = (char)fgetc(f);
v->version = (byte)fgetc(f);
v->version = (jbyte)fgetc(f);
// Is this a valid image file?
if ((v->id[0] == 'V') && (v->id[1] == 'E') && (v->id[2] == 'C') && (v->version <= 0)) {
v->data = (byte *)jlMalloc(sizeof(byte) * v->length);
if (fread(v->data, sizeof(byte), v->length, f) > 0) {
result = true;
v->data = (jbyte *)jlMalloc(sizeof(jbyte) * v->length);
if (fread(v->data, sizeof(jbyte), v->length, f) > 0) {
result = jtrue;
} else {
jlFree(v->data);
}

View file

@ -22,6 +22,11 @@
#ifndef H_JOEY_
#define H_JOEY_
#ifdef __cplusplus
extern "C" {
#endif
#define JOEY_DEBUG
@ -29,14 +34,12 @@
#include <limits.h>
#ifndef bool
typedef unsigned char bool;
#define true 1
#define false 0
#endif
typedef unsigned char jbool;
#define jtrue 1
#define jfalse 0
typedef unsigned char byte;
typedef unsigned char jbyte;
#define JINT16_MIN -32768
@ -49,7 +52,7 @@ typedef unsigned char byte;
#define JUINT32_MIN 0
#define JUINT32_MAX 4294967295
#define JOEY_DISPLAY (byte *)NULL
#define JOEY_DISPLAY (jbyte *)NULL
#define JOEY_INPUT_NONE 0
#define JOEY_INPUT_UP 1
@ -256,14 +259,14 @@ typedef unsigned long juint32;
#endif
typedef byte *jlSurfaceT;
typedef jbyte *jlSurfaceT;
extern jlSurfaceT _jlDrawTarget;
extern jlSurfaceT _jlDrawTargetActual;
extern byte _jlDrawColor;
extern byte _jlDrawColorNibbles;
extern byte _jlBorderColor;
extern jbyte _jlDrawColor;
extern jbyte _jlDrawColorNibbles;
extern jbyte _jlBorderColor;
extern char _jlTempString[1024];
@ -288,15 +291,15 @@ enum _jlBorderColorsE {
typedef enum _jlBorderColorsE jlBorderColorsE;
typedef struct {
byte b : 4;
byte g : 4;
byte r : 4;
byte reserved : 4;
jbyte b : 4;
jbyte g : 4;
jbyte r : 4;
jbyte reserved : 4;
} jlColorT;
typedef struct {
byte l : 4;
byte r : 4;
jbyte l : 4;
jbyte r : 4;
} jlPixelPairT;
typedef struct {
@ -306,27 +309,27 @@ typedef struct {
typedef struct {
char id[3];
byte version;
jbyte version;
jlColorT palette[16]; // 4 bits reserved, 4 bits red, 4 green, 4 blue
jlPixelPairT pixels[32000]; // 320x200, 4 bits per pixel
} jlImgT;
typedef struct {
char id[3];
byte version;
byte pixels[8000]; // 320x200, 1 bit per pixel stencil buffer
char id[3];
jbyte version;
jbyte pixels[8000]; // 320x200, 1 bit per pixel stencil buffer
} jlStnT;
typedef struct _jlStackS {
struct _jlStackS *previous;
void *data;
void *data;
} jlStackT;
typedef struct {
char id[3];
byte version;
jbyte version;
juint16 length;
byte *data;
jbyte *data;
} jlVecT;
@ -364,56 +367,56 @@ void jlDisplayPresent(void);
void jlDrawBlit8x8(jlSurfaceT source, jint16 sx, jint16 sy, jint16 tx, jint16 ty);
void jlDrawBlit8x8a(jlSurfaceT source, jlStnT *stencil, jint16 sx, jint16 sy, jint16 tx, jint16 ty);
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source);
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, jbyte *mapData, juint16 stride, jlSurfaceT source);
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);
byte jlDrawColorGet(void);
void jlDrawColorSet(byte index);
jbyte jlDrawColorGet(void);
void jlDrawColorSet(jbyte index);
void jlDrawEllipse(jint16 x1, jint16 y1, jint16 x2, jint16 y2);
void jlDrawFill(jint16 x, jint16 y);
void jlDrawFillTo(jint16 x, jint16 y, byte color);
void jlDrawFillTo(jint16 x, jint16 y, jbyte color);
void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2);
byte jlDrawPixelGet(jint16 x, jint16 y);
jbyte jlDrawPixelGet(jint16 x, jint16 y);
void jlDrawPixelSet(jint16 x, jint16 y);
jlSurfaceT jlDrawSurfaceGet(void);
void jlDrawSurfaceSet(jlSurfaceT target);
jint16 jlGameGetAxis(byte which);
bool jlGameGetButton(byte which);
jint16 jlGameGetAxis(jbyte which);
jbool jlGameGetButton(jbyte which);
#define jlImgCopy(source, target) _jlImgCopy(source, (jlImgT **)&(target)) // Syntatic Sugar
bool _jlImgCopy(jlImgT *source, jlImgT **target);
jbool _jlImgCopy(jlImgT *source, jlImgT **target);
#define jlImgCreate(img) _jlImgCreate((jlImgT **)&(img)) // Syntatic Sugar
bool _jlImgCreate(jlImgT **img);
jbool _jlImgCreate(jlImgT **img);
void jlImgDisplay(jlImgT *img);
void jlImgFree(jlImgT *img);
#define jlImgLoad(img, filename) _jlImgLoad((jlImgT **)&(img), filename) // Syntatic Sugar
bool _jlImgLoad(jlImgT **img, char *filename);
bool jlImgSave(jlImgT *img, char *filename);
jbool _jlImgLoad(jlImgT **img, char *filename);
jbool jlImgSave(jlImgT *img, char *filename);
#define jlImgSurfaceGet(img) ((jlSurfaceT)img->pixels)
bool jlKeyPressed(void);
jbool jlKeyPressed(void);
char jlKeyRead(void);
void jlKeyWaitForAny(void);
void jlPaletteDefault(void); //***TODO*** Treat palettes like we do "surfaces" - allow changing STAs or display
void jlPaletteSet(byte index, byte r, byte g, byte b); //***TODO*** Really need a matching "get"
void jlPaletteSet(jbyte index, jbyte r, jbyte g, jbyte b); //***TODO*** Really need a matching "get"
void jlPaletteSetFromImg(jlImgT *img);
void jlSoundFree(jlSoundT *sound);
bool jlSoundIsPlaying(jlSoundT *sound);
jbool jlSoundIsPlaying(jlSoundT *sound);
#define jlSoundLoad(sound, filename) _jlSoundLoad((jlSoundT **)&(sound), filename) // Syntatic Sugar
bool _jlSoundLoad(jlSoundT **sound, char *filename);
jbool _jlSoundLoad(jlSoundT **sound, char *filename);
void jlSoundMidiContinue(void);
bool jlSoundMidiIsPlaying(void);
jbool jlSoundMidiIsPlaying(void);
void jlSoundMidiPause(void);
void jlSoundMidiPlay(char *name);
void jlSoundMidiStop(void);
void jlSoundModContinue(void);
bool jlSoundModIsPlaying(void);
jbool jlSoundModIsPlaying(void);
void jlSoundModPause(void);
void jlSoundModPlay(char *name);
void jlSoundModStop(void);
@ -421,16 +424,16 @@ void jlSoundPlay(jlSoundT *sound);
void jlStnFree(jlStnT *stn);
#define jlStnLoad(stn, filename) _jlStnLoad((jlStnT **)&(stn), filename) // Syntatic Sugar
bool _jlStnLoad(jlStnT **stn, char *filename);
jbool _jlStnLoad(jlStnT **stn, char *filename);
#define jlUtilByteSwap(twoBytes) ((juint16)((twoBytes) & 0xff) >> 8) | (juint16)((twoBytes) << 8)
void jlUtilDie(const char *why, ...) __attribute__((noreturn));
void jlUtilIdle(void);
bool jlUtilInputRead(byte *key);
#define jlUtilIsOdd(x) (((x & 1) == 1) ? true : false)
jbool jlUtilInputRead(jbyte *key);
#define jlUtilIsOdd(x) (((x & 1) == 1) ? jtrue : jfalse)
char *jlUtilMakePathname(char *filename, char *extension);
bool jlUtilMustExit(void);
void jlUtilNibbleSwap(byte *mem, jint16 count, byte old, byte new);
jbool jlUtilMustExit(void);
void jlUtilNibbleSwap(jbyte *mem, jint16 count, jbyte oldValue, jbyte newValue);
juint16 jlUtilRandom(void);
juint32 jlUtilRandomSeedGet(void);
void jlUtilRandomSeedSet(juint32 seed);
@ -446,7 +449,7 @@ void jlUtilTitleSet(char *title);
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);
jbool _jlVecLoad(jlVecT **vec, char *filename);
// Must be provided by application
@ -470,18 +473,18 @@ void joeyMain(void);
#ifdef JOEY_IIGS
// Inlined functions - asm code
extern void asmB88(jlSurfaceT target, jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2);
extern void asmB88a(jlSurfaceT target, jlSurfaceT source, byte *stencil, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2);
extern void asmDrawBM(jlSurfaceT target, jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source);
extern void asmB88a(jlSurfaceT target, jlSurfaceT source, jbyte *stencil, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2);
extern void asmDrawBM(jlSurfaceT target, jint16 startX, jint16 startY, jint16 width, jint16 height, jbyte *mapData, juint16 stride, jlSurfaceT source);
extern void asmDrawLine(jlSurfaceT target, jint16 color, jint16 x1, jint16 y1, jint16 x2, jint16 y2);
extern jint16 asmGetPoint(jlSurfaceT target, jint16 x, jint16 y);
extern juint16 asmGetVbl(void);
extern void asmNSwap(byte *mem, jint16 count, jint16 old, jint16 new);
extern void asmNSwap(jbyte *mem, jint16 count, jint16 old, jint16 new);
extern void asmPoint(jlSurfaceT target, jint16 color, jint16 x, jint16 y);
// Inlined functions
#define jlDrawBlit8x8(source, cx1, cy1, cx2, cy2) asmB88(_jlDrawTargetActual, source, cx1, cy1, cx2, cy2)
#define jlDrawBlit8x8a(source, stencil, cx1, cy1, cx2, cy2) asmB88a(_jlDrawTargetActual, source, (byte *)stencil->pixels, cx1, cy1, cx2, cy2)
#define jlDrawBlitMap(startX, startY, width, height, mapData, stride, source) asmDrawBM(_jlDrawTargetActual, startX, startY, width, height, (byte *)mapData, stride, source)
#define jlDrawBlit8x8a(source, stencil, cx1, cy1, cx2, cy2) asmB88a(_jlDrawTargetActual, source, (jbyte *)stencil->pixels, cx1, cy1, cx2, cy2)
#define jlDrawBlitMap(startX, startY, width, height, mapData, stride, source) asmDrawBM(_jlDrawTargetActual, startX, startY, width, height, (jbyte *)mapData, stride, source)
#define jlDrawPixelGet(x, y) asmGetPoint(_jlDrawTargetActual, x, y)
#define jlDrawPixelSet(x, y) asmPoint(_jlDrawTargetActual, _jlDrawColorNibbles, x, y)
#define jlDrawLine(x1, y1, x2, y2) asmDrawLine(_jlDrawTargetActual, _jlDrawColor, x1, y1, x2, y2)
@ -494,4 +497,8 @@ void _jlDebugBorder(jlBorderColorsE color);
#endif // JOEY_IIGS
#ifdef __cplusplus
}
#endif
#endif // H_JOEY_

View file

@ -43,7 +43,7 @@ void help(jlSurfaceT source, jlStnT *stencil, jint16 sx, jint16 sy, jint16 tx, j
int mo; // Mask offset
int x;
int y;
byte b; // Mask bit index
jbyte b; // Mask bit index
printf("\n");
@ -221,7 +221,7 @@ void lineTest(void) {
y = 17;
fontPrint(font, NULL, 1, y++, "Drawing %s ", what);
jlDrawColorSet((byte)color);
jlDrawColorSet((jbyte)color);
if (phase < 2) {
jlDrawLine(x2, y2, 319-x2, 199-y2);
} else {
@ -271,7 +271,7 @@ void lineTest(void) {
jlDisplayPresent();
jlDrawColorSet((byte)0);
jlDrawColorSet((jbyte)0);
if (op < 2) {
jlDrawLine(ox, oy, 319-ox, 199-oy);
} else {
@ -323,7 +323,7 @@ void showStencil(void) {
juint16 temp;
jint16 count;
jint16 index;
byte bit;
jbyte bit;
if (!jlStnLoad(stencil, "biff")) jlUtilDie("Unable to load biff.stn!");