Can now draw to surfaces other than the display.

This commit is contained in:
Scott Duensing 2019-10-03 20:09:18 -05:00
parent daea38b790
commit 040d99935c
9 changed files with 232 additions and 144 deletions

View file

@ -27,8 +27,8 @@ void jlDisplayPresent(void) {
} }
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) { void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
(void)sta; (void)source;
(void)cx1; (void)cx1;
(void)cy1; (void)cy1;
(void)cx2; (void)cx2;
@ -36,8 +36,8 @@ void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2)
} }
void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) { void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) {
(void)sta; (void)source;
(void)cx1; (void)cx1;
(void)cy1; (void)cy1;
(void)cx2; (void)cx2;
@ -45,14 +45,14 @@ void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2,
} }
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlStaT *sta) { void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source) {
(void)startX; (void)startX;
(void)startY; (void)startY;
(void)width; (void)width;
(void)height; (void)height;
(void)mapData; (void)mapData;
(void)stride; (void)stride;
(void)sta; (void)source;
} }
@ -60,7 +60,7 @@ void jlDrawClear(void) {
} }
byte jlDrawGetPixel(jint16 x, jint16 y) { byte jlDrawPixelGet(jint16 x, jint16 y) {
(void)x; (void)x;
(void)y; (void)y;
@ -68,12 +68,25 @@ byte jlDrawGetPixel(jint16 x, jint16 y) {
} }
void jlDrawPoint(jint16 x, jint16 y) { void jlDrawPixelSet(jint16 x, jint16 y) {
(void)x; (void)x;
(void)y; (void)y;
} }
jlSurfaceT jlDrawSurfaceGet(void) {
return _jlDrawTarget;
}
void jlDrawSurfaceSet(jlSurfaceT target) {
_jlDrawTarget = target;
if (target == NULL) {
_jlDrawTargetActual = NULL;
}
}
jint16 jlGameGetAxis(byte which) { jint16 jlGameGetAxis(byte which) {
(void)which; (void)which;

View file

@ -27,8 +27,8 @@ void jlDisplayPresent(void) {
} }
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) { void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
(void)sta; (void)source;
(void)cx1; (void)cx1;
(void)cy1; (void)cy1;
(void)cx2; (void)cx2;
@ -36,8 +36,8 @@ void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2)
} }
void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) { void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) {
(void)sta; (void)source;
(void)cx1; (void)cx1;
(void)cy1; (void)cy1;
(void)cx2; (void)cx2;
@ -45,14 +45,14 @@ void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2,
} }
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlStaT *sta) { void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source) {
(void)startX; (void)startX;
(void)startY; (void)startY;
(void)width; (void)width;
(void)height; (void)height;
(void)mapData; (void)mapData;
(void)stride; (void)stride;
(void)sta; (void)source;
} }
@ -60,7 +60,7 @@ void jlDrawClear(void) {
} }
byte jlDrawGetPixel(jint16 x, jint16 y) { byte jlDrawPixelGet(jint16 x, jint16 y) {
(void)x; (void)x;
(void)y; (void)y;
@ -68,12 +68,25 @@ byte jlDrawGetPixel(jint16 x, jint16 y) {
} }
void jlDrawPoint(jint16 x, jint16 y) { void jlDrawPixelSet(jint16 x, jint16 y) {
(void)x; (void)x;
(void)y; (void)y;
} }
jlSurfaceT jlDrawSurfaceGet(void) {
return _jlDrawTarget;
}
void jlDrawSurfaceSet(jlSurfaceT target) {
_jlDrawTarget = target;
if (target == NULL) {
_jlDrawTargetActual = NULL;
}
}
jint16 jlGameGetAxis(byte which) { jint16 jlGameGetAxis(byte which) {
(void)which; (void)which;

View file

@ -107,7 +107,20 @@ void jlDisplayPresent(void) {
void jlDrawClear(void) { void jlDrawClear(void) {
memset(SHRPIXELS, _jlDrawColorNibbles, 32000); memset(_jlDrawTargetActual, _jlDrawColorNibbles, 32000);
}
jlSurfaceT jlDrawSurfaceGet(void) {
return _jlDrawTarget;
}
void jlDrawSurfaceSet(jlSurfaceT target) {
_jlDrawTarget = target;
if (target == NULL) {
_jlDrawTargetActual = (jlSurfaceT)0x012000L;
}
} }
@ -288,7 +301,7 @@ bool jlUtilMustExit(void) {
void jlUtilShutdown(void) { void jlUtilShutdown(void) {
// Clear the display. // Clear the display.
jlDrawColor(0); jlDrawColorSet(0);
jlDrawClear(); jlDrawClear();
// Restore Border // Restore Border
@ -346,9 +359,10 @@ void jlUtilStartup(char *appTitle) {
jlPaletteDefault(); jlPaletteDefault();
// Clear the display. // Clear the display.
jlDrawColor(0); jlDrawSurfaceSet(JOEY_DISPLAY);
jlDrawColorSet(0);
jlDrawClear(); jlDrawClear();
jlDrawColor(15); jlDrawColorSet(15);
jlDisplayPresent(); jlDisplayPresent();
} }

View file

@ -154,11 +154,13 @@ void jlDisplayPresent(void) {
} }
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) { void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
int o1; int o1;
int o2; int o2;
int x; int x;
int y; int y;
jlPixelPairT *pixels = (jlPixelPairT *)source;
jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
// We mask off unused bits in the source tile location so they can be used to hold other data. // We mask off unused bits in the source tile location so they can be used to hold other data.
o1 = ((cy1 & 0x1f) * 8 * 160) + ((cx1 & 0x3f) * 4); o1 = ((cy1 & 0x1f) * 8 * 160) + ((cx1 & 0x3f) * 4);
@ -166,7 +168,7 @@ void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2)
for (y=0; y<8; y++) { for (y=0; y<8; y++) {
for (x=0; x<4; x++) { for (x=0; x<4; x++) {
_jlBackingStore->pixels[o2++] = sta->pixels[o1++]; target[o2++] = pixels[o1++];
} }
o1 += 156; o1 += 156;
o2 += 156; o2 += 156;
@ -174,15 +176,17 @@ void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2)
} }
void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) { void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) {
int mo; // Mask offset int mo; // Mask offset
int so; // Source Pixel Offset int so; // Source Pixel Offset
int to; // Target Pixel Offset int to; // Target Pixel Offset
int x; int x;
int y; int y;
jlPixelPairT m; // Mask jlPixelPairT m; // Mask
jlPixelPairT s; // Source Pixel jlPixelPairT s; // Source Pixel
jlPixelPairT t; // Target Pixel jlPixelPairT t; // Target Pixel
jlPixelPairT *pixels = (jlPixelPairT *)source;
jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
// We mask off unused bits in the source tile location so they can be used to hold other data. // We mask off unused bits in the source tile location so they can be used to hold other data.
mo = ((cy1 & 0x1f) * 8 * 160) + (((cx1 & 0x3f) + offset) * 4); mo = ((cy1 & 0x1f) * 8 * 160) + (((cx1 & 0x3f) + offset) * 4);
@ -191,12 +195,12 @@ void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2,
for (y=0; y<8; y++) { for (y=0; y<8; y++) {
for (x=0; x<4; x++) { for (x=0; x<4; x++) {
m = sta->pixels[mo++]; m = pixels[mo++];
s = sta->pixels[so++]; s = pixels[so++];
t = _jlBackingStore->pixels[to]; t = target[to];
t.r = (t.r & m.r) | s.r; t.r = (t.r & m.r) | s.r;
t.l = (t.l & m.l) | s.l; t.l = (t.l & m.l) | s.l;
_jlBackingStore->pixels[to++] = t; target[to++] = t;
} }
mo += 156; mo += 156;
so += 156; so += 156;
@ -205,7 +209,7 @@ void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2,
} }
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlStaT *sta) { void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source) {
// startX = start tile for drawing // startX = start tile for drawing
// startY = start tile for drawing // startY = start tile for drawing
// width = tiles to draw horizontally // width = tiles to draw horizontally
@ -223,7 +227,7 @@ void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, by
for (x=startX; x<width; x++) { for (x=startX; x<width; x++) {
tileX = mapData[offset++]; tileX = mapData[offset++];
tileY = mapData[offset++]; tileY = mapData[offset++];
jlDrawBlit8x8(sta, tileX, tileY, x, y); jlDrawBlit8x8(source, tileX, tileY, x, y);
} }
offset += stride; offset += stride;
} }
@ -231,18 +235,21 @@ void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, by
void jlDrawClear(void) { void jlDrawClear(void) {
memset(_jlBackingStore->pixels, _jlDrawColorNibbles, 32000); jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
memset(target, _jlDrawColorNibbles, 32000);
} }
byte jlDrawGetPixel(jint16 x, jint16 y) { byte jlDrawPixelGet(jint16 x, jint16 y) {
jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
int p = x / 2 + y * 160; int p = x / 2 + y * 160;
return (jlUtilIsOdd(x) ? _jlBackingStore->pixels[p].l : _jlBackingStore->pixels[p].r); return (jlUtilIsOdd(x) ? target[p].l : target[p].r);
} }
void jlDrawPoint(jint16 x, jint16 y) { void jlDrawPixelSet(jint16 x, jint16 y) {
jlPixelPairT *pixelPair = _jlBackingStore->pixels + (y * 160) + (x / 2); jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
jlPixelPairT *pixelPair = target + (y * 160) + (x / 2);
if (jlUtilIsOdd(x)) { if (jlUtilIsOdd(x)) {
pixelPair->l = _jlDrawColor; pixelPair->l = _jlDrawColor;
} else { } else {
@ -251,6 +258,19 @@ void jlDrawPoint(jint16 x, jint16 y) {
} }
jlSurfaceT jlDrawSurfaceGet(void) {
return _jlDrawTarget;
}
void jlDrawSurfaceSet(jlSurfaceT target) {
_jlDrawTarget = target;
if (target == NULL) {
_jlDrawTargetActual = (jlSurfaceT)_jlBackingStore->pixels;
}
}
jint16 jlGameGetAxis(byte which) { jint16 jlGameGetAxis(byte which) {
SDL_GameControllerAxis axis; SDL_GameControllerAxis axis;
short int unscaled; short int unscaled;
@ -600,9 +620,10 @@ void jlUtilStartup(char *appTitle) {
// Create backing store // Create backing store
jlStaCreate(_jlBackingStore); jlStaCreate(_jlBackingStore);
jlPaletteDefault(); jlPaletteDefault();
jlDrawColor(0); jlDrawSurfaceSet(JOEY_DISPLAY);
jlDrawColorSet(0);
jlDrawClear(); jlDrawClear();
jlDrawColor(15); jlDrawColorSet(15);
jlDisplayPresent(); jlDisplayPresent();
// Start 1/10th second timer // Start 1/10th second timer

View file

@ -27,8 +27,8 @@ void jlDisplayPresent(void) {
} }
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) { void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
(void)sta; (void)source;
(void)cx1; (void)cx1;
(void)cy1; (void)cy1;
(void)cx2; (void)cx2;
@ -36,8 +36,8 @@ void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2)
} }
void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) { void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) {
(void)sta; (void)source;
(void)cx1; (void)cx1;
(void)cy1; (void)cy1;
(void)cx2; (void)cx2;
@ -45,14 +45,14 @@ void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2,
} }
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlStaT *sta) { void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source) {
(void)startX; (void)startX;
(void)startY; (void)startY;
(void)width; (void)width;
(void)height; (void)height;
(void)mapData; (void)mapData;
(void)stride; (void)stride;
(void)sta; (void)source;
} }
@ -60,7 +60,7 @@ void jlDrawClear(void) {
} }
byte jlDrawGetPixel(jint16 x, jint16 y) { byte jlDrawPixelGet(jint16 x, jint16 y) {
(void)x; (void)x;
(void)y; (void)y;
@ -68,12 +68,25 @@ byte jlDrawGetPixel(jint16 x, jint16 y) {
} }
void jlDrawPoint(jint16 x, jint16 y) { void jlDrawPixelSet(jint16 x, jint16 y) {
(void)x; (void)x;
(void)y; (void)y;
} }
jlSurfaceT jlDrawSurfaceGet(void) {
return _jlDrawTarget;
}
void jlDrawSurfaceSet(jlSurfaceT target) {
_jlDrawTarget = target;
if (target == NULL) {
_jlDrawTargetActual = NULL;
}
}
jint16 jlGameGetAxis(byte which) { jint16 jlGameGetAxis(byte which) {
(void)which; (void)which;

View file

@ -61,10 +61,12 @@ typedef struct {
} _jlScanDataT; } _jlScanDataT;
byte _jlDrawColor = 15; // Color in lower nibble only jlSurfaceT _jlDrawTarget = JOEY_DISPLAY;
byte _jlDrawColorNibbles = (15 << 4) + 15; // Color in both nibbles jlSurfaceT _jlDrawTargetActual = NULL;
byte _jlBorderColor = 0; byte _jlDrawColor = 15; // Color in lower nibble only
char _jlTempString[1024]; // Used internally for pathname operations byte _jlDrawColorNibbles = (15 << 4) + 15; // Color in both nibbles
byte _jlBorderColor = 0;
char _jlTempString[1024]; // Used internally for pathname operations
static jlColorT _jlDefaultPalette[16]; static jlColorT _jlDefaultPalette[16];
@ -81,6 +83,8 @@ _jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed
#ifdef JOEY_DEBUG #ifdef JOEY_DEBUG
//***TODO*** These are really terrible examples of memory management routines.
static jlMemoryBlockT _jlMemoryBlocks[JOEY_MEM_BLOCKS]; static jlMemoryBlockT _jlMemoryBlocks[JOEY_MEM_BLOCKS];
static long _jlTotalAllocated = 0; static long _jlTotalAllocated = 0;
static long _jlTotalAllocations = 0; static long _jlTotalAllocations = 0;
@ -198,14 +202,14 @@ void _jlDrawCircleClipped(jint16 x0, jint16 y0, jint16 radius) {
jint16 err = dx - (jint16)(radius << 1); jint16 err = dx - (jint16)(radius << 1);
while (x >= y) { while (x >= y) {
if ((x0 + x < 320) && (y0 + y < 200)) jlDrawPoint(x0 + x, y0 + y); if ((x0 + x < 320) && (y0 + y < 200)) jlDrawPixelSet(x0 + x, y0 + y);
if ((x0 + y < 320) && (y0 + x < 200)) jlDrawPoint(x0 + y, y0 + x); if ((x0 + y < 320) && (y0 + x < 200)) jlDrawPixelSet(x0 + y, y0 + x);
if ((x0 - y < 320) && (y0 + x < 200)) jlDrawPoint(x0 - y, y0 + x); if ((x0 - y < 320) && (y0 + x < 200)) jlDrawPixelSet(x0 - y, y0 + x);
if ((x0 - x < 320) && (y0 + y < 200)) jlDrawPoint(x0 - x, y0 + y); if ((x0 - x < 320) && (y0 + y < 200)) jlDrawPixelSet(x0 - x, y0 + y);
if ((x0 - x < 320) && (y0 - y < 200)) jlDrawPoint(x0 - x, y0 - y); if ((x0 - x < 320) && (y0 - y < 200)) jlDrawPixelSet(x0 - x, y0 - y);
if ((x0 - x < 320) && (y0 - x < 200)) jlDrawPoint(x0 - y, y0 - x); if ((x0 - x < 320) && (y0 - x < 200)) jlDrawPixelSet(x0 - y, y0 - x);
if ((x0 + y < 320) && (y0 - x < 200)) jlDrawPoint(x0 + y, y0 - x); if ((x0 + y < 320) && (y0 - x < 200)) jlDrawPixelSet(x0 + y, y0 - x);
if ((x0 + x < 320) && (y0 - y < 200)) jlDrawPoint(x0 + x, y0 - y); if ((x0 + x < 320) && (y0 - y < 200)) jlDrawPixelSet(x0 + x, y0 - y);
if (err <= 0) { if (err <= 0) {
y++; y++;
@ -237,14 +241,14 @@ void jlDrawCircle(jint16 x0, jint16 y0, jint16 radius) {
} }
while (x >= y) { while (x >= y) {
jlDrawPoint(x0 + x, y0 + y); jlDrawPixelSet(x0 + x, y0 + y);
jlDrawPoint(x0 + y, y0 + x); jlDrawPixelSet(x0 + y, y0 + x);
jlDrawPoint(x0 - y, y0 + x); jlDrawPixelSet(x0 - y, y0 + x);
jlDrawPoint(x0 - x, y0 + y); jlDrawPixelSet(x0 - x, y0 + y);
jlDrawPoint(x0 - x, y0 - y); jlDrawPixelSet(x0 - x, y0 - y);
jlDrawPoint(x0 - y, y0 - x); jlDrawPixelSet(x0 - y, y0 - x);
jlDrawPoint(x0 + y, y0 - x); jlDrawPixelSet(x0 + y, y0 - x);
jlDrawPoint(x0 + x, y0 - y); jlDrawPixelSet(x0 + x, y0 - y);
if (err <= 0) { if (err <= 0) {
y++; y++;
@ -259,7 +263,12 @@ void jlDrawCircle(jint16 x0, jint16 y0, jint16 radius) {
} }
void jlDrawColor(byte index) { byte jlDrawColorGet(void) {
return _jlDrawColor;
}
void jlDrawColorSet(byte index) {
_jlDrawColor = index; _jlDrawColor = index;
_jlDrawColorNibbles = (byte)((index << 4) + index); _jlDrawColorNibbles = (byte)((index << 4) + index);
} }
@ -277,20 +286,20 @@ void jlDrawEllipse(jint16 x0, jint16 y0, jint16 x1, jint16 y1) {
a *= 8*a; b1 = 8*b*b; a *= 8*a; b1 = 8*b*b;
do { do {
jlDrawPoint(x1, y0); /* I. Quadrant */ jlDrawPixelSet(x1, y0); /* I. Quadrant */
jlDrawPoint(x0, y0); /* II. Quadrant */ jlDrawPixelSet(x0, y0); /* II. Quadrant */
jlDrawPoint(x0, y1); /* III. Quadrant */ jlDrawPixelSet(x0, y1); /* III. Quadrant */
jlDrawPoint(x1, y1); /* IV. Quadrant */ jlDrawPixelSet(x1, y1); /* IV. Quadrant */
e2 = 2*err; e2 = 2*err;
if (e2 <= dy) { y0++; y1--; err += dy += a; } /* y step */ if (e2 <= dy) { y0++; y1--; err += dy += a; } /* y step */
if (e2 >= dx || 2*err > dy) { x0++; x1--; err += dx += b1; } /* x step */ if (e2 >= dx || 2*err > dy) { x0++; x1--; err += dx += b1; } /* x step */
} while (x0 <= x1); } while (x0 <= x1);
while (y0-y1 < b) { /* too early stop of flat ellipses a=1 */ while (y0-y1 < b) { /* too early stop of flat ellipses a=1 */
jlDrawPoint(x0-1, y0); /* -> finish tip of ellipse */ jlDrawPixelSet(x0-1, y0); /* -> finish tip of ellipse */
jlDrawPoint(x1+1, y0++); jlDrawPixelSet(x1+1, y0++);
jlDrawPoint(x0-1, y1); jlDrawPixelSet(x0-1, y1);
jlDrawPoint(x1+1, y1--); jlDrawPixelSet(x1+1, y1--);
} }
} }
@ -314,8 +323,8 @@ void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart
for (x=startX; x<endX; x++) { for (x=startX; x<endX; x++) {
if (how) { if (how) {
// Unrolled contents to reduce comparison complexity. // Unrolled contents to reduce comparison complexity.
if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawGetPixel(x, y) == _jlDrawFillColor)) { if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawPixelGet(x, y) == _jlDrawFillColor)) {
jlDrawPoint(x, y); jlDrawPixelSet(x, y);
if (regionStart < 0) regionStart = x; if (regionStart < 0) regionStart = x;
} else if (regionStart >= 0) { } else if (regionStart >= 0) {
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, false)); jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, false));
@ -323,8 +332,8 @@ void _jlDrawFillAddLine(jint16 startX, jint16 endX, jint16 y, jint16 ignoreStart
} }
} else { } else {
// Unrolled contents to reduce comparison complexity. // Unrolled contents to reduce comparison complexity.
if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawGetPixel(x, y) != _jlDrawFillColor)) { if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawPixelGet(x, y) != _jlDrawFillColor)) {
jlDrawPoint(x, y); jlDrawPixelSet(x, y);
if (regionStart < 0) regionStart = x; if (regionStart < 0) regionStart = x;
} else if (regionStart >= 0) { } else if (regionStart >= 0) {
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, false)); jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(regionStart, x, y, dir, regionStart == startX, false));
@ -350,7 +359,7 @@ void _jlDrawFill(jint16 x, jint16 y, bool how) {
// how == true; Fill on top of _jlDrawFillColor // how == true; Fill on top of _jlDrawFillColor
// how == false; Fill on top of any color until we encounter _jlDrawFillColor // how == false; Fill on top of any color until we encounter _jlDrawFillColor
jlDrawPoint(x, y); jlDrawPixelSet(x, y);
jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(x, x+1, y, 0, true, true)); jlUtilStackPush(_jlFillStackTop, _jlDrawFillNewSegment(x, x+1, y, 0, true, true));
while ((r = jlUtilStackPop(_jlFillStackTop)) != NULL) { while ((r = jlUtilStackPop(_jlFillStackTop)) != NULL) {
@ -358,16 +367,16 @@ void _jlDrawFill(jint16 x, jint16 y, bool how) {
endX = r->EndX; endX = r->EndX;
if (r->ScanLeft) { if (r->ScanLeft) {
if (how) { if (how) {
while (startX > 0 && (jlDrawGetPixel(startX-1, r->Y) == _jlDrawFillColor)) jlDrawPoint(--startX, r->Y); while (startX > 0 && (jlDrawPixelGet(startX-1, r->Y) == _jlDrawFillColor)) jlDrawPixelSet(--startX, r->Y);
} else { } else {
while (startX > 0 && (jlDrawGetPixel(startX-1, r->Y) != _jlDrawFillColor)) jlDrawPoint(--startX, r->Y); while (startX > 0 && (jlDrawPixelGet(startX-1, r->Y) != _jlDrawFillColor)) jlDrawPixelSet(--startX, r->Y);
} }
} }
if (r->ScanRight) { if (r->ScanRight) {
if (how) { if (how) {
while(endX < width && (jlDrawGetPixel(endX, r->Y) == _jlDrawFillColor)) jlDrawPoint(endX++, r->Y); while(endX < width && (jlDrawPixelGet(endX, r->Y) == _jlDrawFillColor)) jlDrawPixelSet(endX++, r->Y);
} else { } else {
while(endX < width && (jlDrawGetPixel(endX, r->Y) == _jlDrawFillColor)) jlDrawPoint(endX++, r->Y); while(endX < width && (jlDrawPixelGet(endX, r->Y) == _jlDrawFillColor)) jlDrawPixelSet(endX++, r->Y);
} }
} }
r->StartX--; r->StartX--;
@ -380,7 +389,7 @@ void _jlDrawFill(jint16 x, jint16 y, bool how) {
void jlDrawFill(jint16 x, jint16 y) { void jlDrawFill(jint16 x, jint16 y) {
_jlDrawFillColor = jlDrawGetPixel(x, y); _jlDrawFillColor = jlDrawPixelGet(x, y);
_jlDrawFill(x, y, true); _jlDrawFill(x, y, true);
} }
@ -391,11 +400,6 @@ void jlDrawFillTo(jint16 x, jint16 y, byte color) {
} }
byte jlDrawGetColor(void) {
return _jlDrawColor;
}
void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) { void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
jint16 x; jint16 x;
jint16 y; jint16 y;
@ -429,7 +433,7 @@ void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
balance = dy - dx; balance = dy - dx;
dx <<= 1; dx <<= 1;
while (x != x2) { while (x != x2) {
jlDrawPoint(x, y); jlDrawPixelSet(x, y);
if (balance >= 0) { if (balance >= 0) {
y += incY; y += incY;
balance -= dx; balance -= dx;
@ -437,13 +441,13 @@ void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
balance += dy; balance += dy;
x += incX; x += incX;
} }
jlDrawPoint(x, y); jlDrawPixelSet(x, y);
} else { } else {
dx <<= 1; dx <<= 1;
balance = dx - dy; balance = dx - dy;
dy <<= 1; dy <<= 1;
while (y != y2) { while (y != y2) {
jlDrawPoint(x, y); jlDrawPixelSet(x, y);
if (balance >= 0) { if (balance >= 0) {
x += incX; x += incX;
balance -= dy; balance -= dy;
@ -451,7 +455,7 @@ void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
balance += dx; balance += dx;
y += incY; y += incY;
} }
jlDrawPoint(x, y); jlDrawPixelSet(x, y);
} }
} }
@ -684,7 +688,7 @@ void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) {
case COMMAND_COLOR: case COMMAND_COLOR:
x1 = vec->data[p++]; x1 = vec->data[p++];
jlDrawColor((byte)x1); jlDrawColorSet((byte)x1);
break; break;
case COMMAND_CLEAR: case COMMAND_CLEAR:
@ -697,7 +701,7 @@ void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) {
x1 = ox + vec->data[p++]; x1 = ox + vec->data[p++];
x1 = x1 + (jint16)(vec->data[p++] << 8); x1 = x1 + (jint16)(vec->data[p++] << 8);
y1 = oy + vec->data[p++]; y1 = oy + vec->data[p++];
jlDrawPoint(x1, y1); jlDrawPixelSet(x1, y1);
} }
break; break;

View file

@ -29,11 +29,23 @@
#include <limits.h> #include <limits.h>
#ifndef bool
typedef unsigned char bool;
#define true 1
#define false 0
#endif
typedef unsigned char byte;
#define JINT16_MIN -32768 #define JINT16_MIN -32768
#define JINT16_MAX 32767 #define JINT16_MAX 32767
#define JUINT16_MIN 0 #define JUINT16_MIN 0
#define JUINT16_MAX 65535 #define JUINT16_MAX 65535
#define JOEY_DISPLAY (byte *)NULL
// Determine platform and settings // Determine platform and settings
#ifdef __linux__ #ifdef __linux__
@ -115,19 +127,15 @@ typedef unsigned long juint32;
#endif #endif
#ifndef bool typedef byte *jlSurfaceT;
#define bool unsigned char
#define true 1
#define false 0
#endif
#define byte unsigned char
extern byte _jlDrawColor; extern jlSurfaceT _jlDrawTarget;
extern byte _jlDrawColorNibbles; extern jlSurfaceT _jlDrawTargetActual;
extern byte _jlBorderColor; extern byte _jlDrawColor;
extern char _jlTempString[1024]; extern byte _jlDrawColorNibbles;
extern byte _jlBorderColor;
extern char _jlTempString[1024];
enum _jlBorderColorsE { enum _jlBorderColorsE {
@ -150,7 +158,6 @@ enum _jlBorderColorsE {
}; };
typedef enum _jlBorderColorsE jlBorderColorsE; typedef enum _jlBorderColorsE jlBorderColorsE;
typedef struct { typedef struct {
byte b : 4; byte b : 4;
byte g : 4; byte g : 4;
@ -218,26 +225,29 @@ void *_jlRealloc(void *pointer, size_t size);
#define jlByteSwap(twoBytes) ((juint16)((twoBytes) & 0xff) >> 8) | (juint16)((twoBytes) << 8) #define jlByteSwap(twoBytes) ((juint16)((twoBytes) & 0xff) >> 8) | (juint16)((twoBytes) << 8)
#define jlStaSurfaceGet(sta) ((jlSurfaceT)sta->pixels)
void jlDisplayBorder(jlBorderColorsE color); void jlDisplayBorder(jlBorderColorsE color);
void jlDisplayPresent(void); void jlDisplayPresent(void);
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2); void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2);
void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset); void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset);
void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlStaT *sta); void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source);
void jlDrawBox(jint16 x1, jint16 y1, jint16 x2, jint16 y2); void jlDrawBox(jint16 x1, jint16 y1, jint16 x2, jint16 y2);
void jlDrawBoxFilled(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 jlDrawCircle(jint16 x, jint16 y, jint16 radius);
void jlDrawClear(void); void jlDrawClear(void);
void jlDrawColor(byte index); byte jlDrawColorGet(void);
void jlDrawColorSet(byte index);
void jlDrawEllipse(jint16 x1, jint16 y1, jint16 x2, jint16 y2); void jlDrawEllipse(jint16 x1, jint16 y1, jint16 x2, jint16 y2);
void jlDrawFill(jint16 x, jint16 y); void jlDrawFill(jint16 x, jint16 y);
void jlDrawFillTo(jint16 x, jint16 y, byte color); 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 jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2);
void jlDrawPoint(jint16 x, jint16 y); byte jlDrawPixelGet(jint16 x, jint16 y);
void jlDrawPixelSet(jint16 x, jint16 y);
jlSurfaceT jlDrawSurfaceGet(void);
void jlDrawSurfaceSet(jlSurfaceT target);
jint16 jlGameGetAxis(byte which); jint16 jlGameGetAxis(byte which);
bool jlGameGetButton(byte which); bool jlGameGetButton(byte which);
@ -299,24 +309,24 @@ bool _jlVecLoad(jlVecT **vec, char *filename);
#ifdef JOEY_IIGS #ifdef JOEY_IIGS
// Inlined functions - asm code // Inlined functions - asm code
extern void asmB88(juint32 surface, byte *p, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2); extern void asmB88(jlSurfaceT target, jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2);
extern void asmB88a(juint32 surface, byte *p, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte alphaOffset); extern void asmB88a(jlSurfaceT target, jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte alphaOffset);
extern void asmDrawBM(juint32 surface, jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, byte *sta); extern void asmDrawBM(jlSurfaceT target, jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlSurfaceT source);
//extern void asmDrawLine(juint32 surface, jint16 color, jint16 x1, jint16 y1, jint16 x2, jint16 y2); //extern void asmDrawLine(jlSurfaceT target, jint16 color, jint16 x1, jint16 y1, jint16 x2, jint16 y2);
extern jint16 asmGetPoint(juint32 surface, jint16 x, jint16 y); extern jint16 asmGetPoint(jlSurfaceT target, jint16 x, jint16 y);
extern juint16 asmGetVbl(void); extern juint16 asmGetVbl(void);
extern void asmNSwap(byte *mem, jint16 count, jint16 old, jint16 new); extern void asmNSwap(byte *mem, jint16 count, jint16 old, jint16 new);
extern void asmPoint(juint32 surface, jint16 color, jint16 x, jint16 y); extern void asmPoint(jlSurfaceT target, jint16 color, jint16 x, jint16 y);
// Inlined functions // Inlined functions
#define jlDrawBlit8x8(sta, cx1, cy1, cx2, cy2) asmB88(0x012000, (byte *)sta->pixels, cx1, cy1, cx2, cy2) #define jlDrawBlit8x8(source, cx1, cy1, cx2, cy2) asmB88(_jlDrawTargetActual, source, cx1, cy1, cx2, cy2)
#define jlDrawBlit8x8a(sta, cx1, cy1, cx2, cy2, offset) asmB88a(0x012000, (byte *)sta->pixels, cx1, cy1, cx2, cy2, offset) #define jlDrawBlit8x8a(source, cx1, cy1, cx2, cy2, offset) asmB88a(_jlDrawTargetActual, source, cx1, cy1, cx2, cy2, offset)
#define jlDrawBlitMap(startX, startY, width, height, mapData, stride, sta) asmDrawBM(0x012000, startX, startY, width, height, (byte *)mapData, stride, (byte *)sta->pixels) #define jlDrawBlitMap(startX, startY, width, height, mapData, stride, source) asmDrawBM(_jlDrawTargetActual, startX, startY, width, height, (byte *)mapData, stride, source)
#define jlDrawGetPixel(x, y) asmGetPoint(0x012000, x, y) #define jlDrawPixelGet(x, y) asmGetPoint(_jlDrawTargetActual, x, y)
#define jlDrawPoint(x, y) asmPoint(0x012000, _jlDrawColorNibbles, x, y) #define jlDrawPixelSet(x, y) asmPoint(_jlDrawTargetActual, _jlDrawColorNibbles, x, y)
//#define jlDrawLine(x1, y1, x2, y2) asmDrawLine(0x012000, _jlDrawColor, x1, y1, x2, y2) //#define jlDrawLine(x1, y1, x2, y2) asmDrawLine(_jlDrawTargetActual, _jlDrawColor, x1, y1, x2, y2)
#define jlUtilNibbleSwap(mem, count, old, new) asmNSwap(mem, count, (jint16)old, (jint16)new) #define jlUtilNibbleSwap(mem, count, old, new) asmNSwap(mem, count, (jint16)old, (jint16)new)
#define jlUtilTimer asmGetVbl #define jlUtilTimer asmGetVbl
#ifdef JOEY_DEBUG #ifdef JOEY_DEBUG
void _jlDebugBorder(jlBorderColorsE color); void _jlDebugBorder(jlBorderColorsE color);

View file

@ -48,7 +48,7 @@ void printAt(jlStaT *font, jint16 cx, jint16 cy, const char *what, ...) {
for (counter=0; counter<(int)strlen(msg); counter++) { for (counter=0; counter<(int)strlen(msg); counter++) {
x = (msg[counter] - ' ') % 40; x = (msg[counter] - ' ') % 40;
y = (msg[counter] - ' ') / 40; y = (msg[counter] - ' ') / 40;
jlDrawBlit8x8(font, x, y, counter + cx, cy); jlDrawBlit8x8(jlStaSurfaceGet(font), x, y, counter + cx, cy);
} }
} }
@ -69,7 +69,7 @@ int main(void) {
if (!jlStaLoad(font, "font")) jlUtilDie("Unable to load font.sta!"); if (!jlStaLoad(font, "font")) jlUtilDie("Unable to load font.sta!");
jlStaDisplay(kanga); jlStaDisplay(kanga);
jlDrawColor(1); jlDrawColorSet(1);
jlDrawBox(0, 0, 319, 199); jlDrawBox(0, 0, 319, 199);
jlSoundMusicPlay("music"); jlSoundMusicPlay("music");
@ -81,7 +81,7 @@ int main(void) {
printAt(font, 1, y++, "X = %d ", jlGameGetAxis(0)); printAt(font, 1, y++, "X = %d ", jlGameGetAxis(0));
printAt(font, 1, y++, "Y = %d ", jlGameGetAxis(1)); printAt(font, 1, y++, "Y = %d ", jlGameGetAxis(1));
printAt(font, 1, y++, "T = %d ", jlUtilTimer()); printAt(font, 1, y++, "T = %d ", jlUtilTimer());
jlDrawColor((byte)color); jlDrawColorSet((byte)color);
jlDrawLine(0, y2, 319, 199-y2); jlDrawLine(0, y2, 319, 199-y2);
y2 += dy; y2 += dy;
if (y2 == 199 || y2 == 0) dy = -dy; if (y2 == 199 || y2 == 0) dy = -dy;

View file

@ -173,7 +173,7 @@ int main(int argc, char *argv[]) {
if (args == 1) { if (args == 1) {
EMIT_COMMAND; EMIT_COMMAND;
EMIT_BYTE; EMIT_BYTE;
jlDrawColor((byte)data[i]); jlDrawColorSet((byte)data[i]);
} }
break; break;
@ -195,7 +195,7 @@ int main(int argc, char *argv[]) {
x1 = data[i++]; x1 = data[i++];
EMIT_BYTE; EMIT_BYTE;
y1 = data[i++]; y1 = data[i++];
jlDrawPoint(x1, y1); jlDrawPixelSet(x1, y1);
} }
} }
break; break;