Can now draw to surfaces other than the display.
This commit is contained in:
parent
daea38b790
commit
040d99935c
9 changed files with 232 additions and 144 deletions
|
@ -27,8 +27,8 @@ void jlDisplayPresent(void) {
|
|||
}
|
||||
|
||||
|
||||
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
|
||||
(void)sta;
|
||||
void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
|
||||
(void)source;
|
||||
(void)cx1;
|
||||
(void)cy1;
|
||||
(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)sta;
|
||||
void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) {
|
||||
(void)source;
|
||||
(void)cx1;
|
||||
(void)cy1;
|
||||
(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)startY;
|
||||
(void)width;
|
||||
(void)height;
|
||||
(void)mapData;
|
||||
(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)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)y;
|
||||
}
|
||||
|
||||
|
||||
jlSurfaceT jlDrawSurfaceGet(void) {
|
||||
return _jlDrawTarget;
|
||||
}
|
||||
|
||||
|
||||
void jlDrawSurfaceSet(jlSurfaceT target) {
|
||||
_jlDrawTarget = target;
|
||||
if (target == NULL) {
|
||||
_jlDrawTargetActual = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jint16 jlGameGetAxis(byte which) {
|
||||
(void)which;
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ void jlDisplayPresent(void) {
|
|||
}
|
||||
|
||||
|
||||
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
|
||||
(void)sta;
|
||||
void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
|
||||
(void)source;
|
||||
(void)cx1;
|
||||
(void)cy1;
|
||||
(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)sta;
|
||||
void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) {
|
||||
(void)source;
|
||||
(void)cx1;
|
||||
(void)cy1;
|
||||
(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)startY;
|
||||
(void)width;
|
||||
(void)height;
|
||||
(void)mapData;
|
||||
(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)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)y;
|
||||
}
|
||||
|
||||
|
||||
jlSurfaceT jlDrawSurfaceGet(void) {
|
||||
return _jlDrawTarget;
|
||||
}
|
||||
|
||||
|
||||
void jlDrawSurfaceSet(jlSurfaceT target) {
|
||||
_jlDrawTarget = target;
|
||||
if (target == NULL) {
|
||||
_jlDrawTargetActual = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jint16 jlGameGetAxis(byte which) {
|
||||
(void)which;
|
||||
|
||||
|
|
|
@ -107,7 +107,20 @@ void jlDisplayPresent(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) {
|
||||
// Clear the display.
|
||||
jlDrawColor(0);
|
||||
jlDrawColorSet(0);
|
||||
jlDrawClear();
|
||||
|
||||
// Restore Border
|
||||
|
@ -346,9 +359,10 @@ void jlUtilStartup(char *appTitle) {
|
|||
jlPaletteDefault();
|
||||
|
||||
// Clear the display.
|
||||
jlDrawColor(0);
|
||||
jlDrawSurfaceSet(JOEY_DISPLAY);
|
||||
jlDrawColorSet(0);
|
||||
jlDrawClear();
|
||||
jlDrawColor(15);
|
||||
jlDrawColorSet(15);
|
||||
|
||||
jlDisplayPresent();
|
||||
}
|
||||
|
|
|
@ -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 o2;
|
||||
int x;
|
||||
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.
|
||||
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 (x=0; x<4; x++) {
|
||||
_jlBackingStore->pixels[o2++] = sta->pixels[o1++];
|
||||
target[o2++] = pixels[o1++];
|
||||
}
|
||||
o1 += 156;
|
||||
o2 += 156;
|
||||
|
@ -174,7 +176,7 @@ 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 so; // Source Pixel Offset
|
||||
int to; // Target Pixel Offset
|
||||
|
@ -183,6 +185,8 @@ void jlDrawBlit8x8a(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2,
|
|||
jlPixelPairT m; // Mask
|
||||
jlPixelPairT s; // Source 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.
|
||||
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 (x=0; x<4; x++) {
|
||||
m = sta->pixels[mo++];
|
||||
s = sta->pixels[so++];
|
||||
t = _jlBackingStore->pixels[to];
|
||||
m = pixels[mo++];
|
||||
s = pixels[so++];
|
||||
t = target[to];
|
||||
t.r = (t.r & m.r) | s.r;
|
||||
t.l = (t.l & m.l) | s.l;
|
||||
_jlBackingStore->pixels[to++] = t;
|
||||
target[to++] = t;
|
||||
}
|
||||
mo += 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
|
||||
// startY = start tile for drawing
|
||||
// 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++) {
|
||||
tileX = mapData[offset++];
|
||||
tileY = mapData[offset++];
|
||||
jlDrawBlit8x8(sta, tileX, tileY, x, y);
|
||||
jlDrawBlit8x8(source, tileX, tileY, x, y);
|
||||
}
|
||||
offset += stride;
|
||||
}
|
||||
|
@ -231,18 +235,21 @@ void jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, by
|
|||
|
||||
|
||||
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;
|
||||
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) {
|
||||
jlPixelPairT *pixelPair = _jlBackingStore->pixels + (y * 160) + (x / 2);
|
||||
void jlDrawPixelSet(jint16 x, jint16 y) {
|
||||
jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
|
||||
jlPixelPairT *pixelPair = target + (y * 160) + (x / 2);
|
||||
if (jlUtilIsOdd(x)) {
|
||||
pixelPair->l = _jlDrawColor;
|
||||
} 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) {
|
||||
SDL_GameControllerAxis axis;
|
||||
short int unscaled;
|
||||
|
@ -600,9 +620,10 @@ void jlUtilStartup(char *appTitle) {
|
|||
// Create backing store
|
||||
jlStaCreate(_jlBackingStore);
|
||||
jlPaletteDefault();
|
||||
jlDrawColor(0);
|
||||
jlDrawSurfaceSet(JOEY_DISPLAY);
|
||||
jlDrawColorSet(0);
|
||||
jlDrawClear();
|
||||
jlDrawColor(15);
|
||||
jlDrawColorSet(15);
|
||||
jlDisplayPresent();
|
||||
|
||||
// Start 1/10th second timer
|
||||
|
|
|
@ -27,8 +27,8 @@ void jlDisplayPresent(void) {
|
|||
}
|
||||
|
||||
|
||||
void jlDrawBlit8x8(jlStaT *sta, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
|
||||
(void)sta;
|
||||
void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2) {
|
||||
(void)source;
|
||||
(void)cx1;
|
||||
(void)cy1;
|
||||
(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)sta;
|
||||
void jlDrawBlit8x8a(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte offset) {
|
||||
(void)source;
|
||||
(void)cx1;
|
||||
(void)cy1;
|
||||
(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)startY;
|
||||
(void)width;
|
||||
(void)height;
|
||||
(void)mapData;
|
||||
(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)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)y;
|
||||
}
|
||||
|
||||
|
||||
jlSurfaceT jlDrawSurfaceGet(void) {
|
||||
return _jlDrawTarget;
|
||||
}
|
||||
|
||||
|
||||
void jlDrawSurfaceSet(jlSurfaceT target) {
|
||||
_jlDrawTarget = target;
|
||||
if (target == NULL) {
|
||||
_jlDrawTargetActual = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jint16 jlGameGetAxis(byte which) {
|
||||
(void)which;
|
||||
|
||||
|
|
|
@ -61,6 +61,8 @@ typedef struct {
|
|||
} _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;
|
||||
|
@ -81,6 +83,8 @@ _jlScanDataT *_jlDrawFillNewSegment(jint16 startX, jint16 endX, jint16 y, signed
|
|||
|
||||
#ifdef JOEY_DEBUG
|
||||
|
||||
//***TODO*** These are really terrible examples of memory management routines.
|
||||
|
||||
static jlMemoryBlockT _jlMemoryBlocks[JOEY_MEM_BLOCKS];
|
||||
static long _jlTotalAllocated = 0;
|
||||
static long _jlTotalAllocations = 0;
|
||||
|
@ -198,14 +202,14 @@ void _jlDrawCircleClipped(jint16 x0, jint16 y0, jint16 radius) {
|
|||
jint16 err = dx - (jint16)(radius << 1);
|
||||
|
||||
while (x >= y) {
|
||||
if ((x0 + x < 320) && (y0 + y < 200)) jlDrawPoint(x0 + x, y0 + y);
|
||||
if ((x0 + y < 320) && (y0 + x < 200)) jlDrawPoint(x0 + y, y0 + x);
|
||||
if ((x0 - y < 320) && (y0 + x < 200)) jlDrawPoint(x0 - y, y0 + x);
|
||||
if ((x0 - x < 320) && (y0 + y < 200)) jlDrawPoint(x0 - x, y0 + y);
|
||||
if ((x0 - x < 320) && (y0 - y < 200)) jlDrawPoint(x0 - x, y0 - y);
|
||||
if ((x0 - x < 320) && (y0 - x < 200)) jlDrawPoint(x0 - y, y0 - x);
|
||||
if ((x0 + y < 320) && (y0 - x < 200)) jlDrawPoint(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 + y < 320) && (y0 + x < 200)) jlDrawPixelSet(x0 + y, y0 + x);
|
||||
if ((x0 - y < 320) && (y0 + x < 200)) jlDrawPixelSet(x0 - y, y0 + x);
|
||||
if ((x0 - x < 320) && (y0 + y < 200)) jlDrawPixelSet(x0 - x, y0 + y);
|
||||
if ((x0 - x < 320) && (y0 - y < 200)) jlDrawPixelSet(x0 - x, y0 - y);
|
||||
if ((x0 - x < 320) && (y0 - x < 200)) jlDrawPixelSet(x0 - y, y0 - x);
|
||||
if ((x0 + y < 320) && (y0 - x < 200)) jlDrawPixelSet(x0 + y, y0 - x);
|
||||
if ((x0 + x < 320) && (y0 - y < 200)) jlDrawPixelSet(x0 + x, y0 - y);
|
||||
|
||||
if (err <= 0) {
|
||||
y++;
|
||||
|
@ -237,14 +241,14 @@ void jlDrawCircle(jint16 x0, jint16 y0, jint16 radius) {
|
|||
}
|
||||
|
||||
while (x >= y) {
|
||||
jlDrawPoint(x0 + x, y0 + y);
|
||||
jlDrawPoint(x0 + y, y0 + x);
|
||||
jlDrawPoint(x0 - y, y0 + x);
|
||||
jlDrawPoint(x0 - x, y0 + y);
|
||||
jlDrawPoint(x0 - x, y0 - y);
|
||||
jlDrawPoint(x0 - y, y0 - x);
|
||||
jlDrawPoint(x0 + y, y0 - x);
|
||||
jlDrawPoint(x0 + x, y0 - y);
|
||||
jlDrawPixelSet(x0 + x, y0 + y);
|
||||
jlDrawPixelSet(x0 + y, y0 + x);
|
||||
jlDrawPixelSet(x0 - y, y0 + x);
|
||||
jlDrawPixelSet(x0 - x, y0 + y);
|
||||
jlDrawPixelSet(x0 - x, y0 - y);
|
||||
jlDrawPixelSet(x0 - y, y0 - x);
|
||||
jlDrawPixelSet(x0 + y, y0 - x);
|
||||
jlDrawPixelSet(x0 + x, y0 - y);
|
||||
|
||||
if (err <= 0) {
|
||||
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;
|
||||
_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;
|
||||
|
||||
do {
|
||||
jlDrawPoint(x1, y0); /* I. Quadrant */
|
||||
jlDrawPoint(x0, y0); /* II. Quadrant */
|
||||
jlDrawPoint(x0, y1); /* III. Quadrant */
|
||||
jlDrawPoint(x1, y1); /* IV. Quadrant */
|
||||
jlDrawPixelSet(x1, y0); /* I. Quadrant */
|
||||
jlDrawPixelSet(x0, y0); /* II. Quadrant */
|
||||
jlDrawPixelSet(x0, y1); /* III. Quadrant */
|
||||
jlDrawPixelSet(x1, y1); /* IV. Quadrant */
|
||||
e2 = 2*err;
|
||||
if (e2 <= dy) { y0++; y1--; err += dy += a; } /* y step */
|
||||
if (e2 >= dx || 2*err > dy) { x0++; x1--; err += dx += b1; } /* x step */
|
||||
} while (x0 <= x1);
|
||||
|
||||
while (y0-y1 < b) { /* too early stop of flat ellipses a=1 */
|
||||
jlDrawPoint(x0-1, y0); /* -> finish tip of ellipse */
|
||||
jlDrawPoint(x1+1, y0++);
|
||||
jlDrawPoint(x0-1, y1);
|
||||
jlDrawPoint(x1+1, y1--);
|
||||
jlDrawPixelSet(x0-1, y0); /* -> finish tip of ellipse */
|
||||
jlDrawPixelSet(x1+1, y0++);
|
||||
jlDrawPixelSet(x0-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++) {
|
||||
if (how) {
|
||||
// Unrolled contents to reduce comparison complexity.
|
||||
if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawGetPixel(x, y) == _jlDrawFillColor)) {
|
||||
jlDrawPoint(x, y);
|
||||
if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawPixelGet(x, y) == _jlDrawFillColor)) {
|
||||
jlDrawPixelSet(x, y);
|
||||
if (regionStart < 0) regionStart = x;
|
||||
} else if (regionStart >= 0) {
|
||||
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 {
|
||||
// Unrolled contents to reduce comparison complexity.
|
||||
if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawGetPixel(x, y) != _jlDrawFillColor)) {
|
||||
jlDrawPoint(x, y);
|
||||
if ((isNextInDir || x < ignoreStart || x >= ignoreEnd) && (jlDrawPixelGet(x, y) != _jlDrawFillColor)) {
|
||||
jlDrawPixelSet(x, y);
|
||||
if (regionStart < 0) regionStart = x;
|
||||
} else if (regionStart >= 0) {
|
||||
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 == 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));
|
||||
while ((r = jlUtilStackPop(_jlFillStackTop)) != NULL) {
|
||||
|
@ -358,16 +367,16 @@ void _jlDrawFill(jint16 x, jint16 y, bool how) {
|
|||
endX = r->EndX;
|
||||
if (r->ScanLeft) {
|
||||
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 {
|
||||
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 (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 {
|
||||
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--;
|
||||
|
@ -380,7 +389,7 @@ void _jlDrawFill(jint16 x, jint16 y, bool how) {
|
|||
|
||||
|
||||
void jlDrawFill(jint16 x, jint16 y) {
|
||||
_jlDrawFillColor = jlDrawGetPixel(x, y);
|
||||
_jlDrawFillColor = jlDrawPixelGet(x, y);
|
||||
_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) {
|
||||
jint16 x;
|
||||
jint16 y;
|
||||
|
@ -429,7 +433,7 @@ void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
|
|||
balance = dy - dx;
|
||||
dx <<= 1;
|
||||
while (x != x2) {
|
||||
jlDrawPoint(x, y);
|
||||
jlDrawPixelSet(x, y);
|
||||
if (balance >= 0) {
|
||||
y += incY;
|
||||
balance -= dx;
|
||||
|
@ -437,13 +441,13 @@ void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
|
|||
balance += dy;
|
||||
x += incX;
|
||||
}
|
||||
jlDrawPoint(x, y);
|
||||
jlDrawPixelSet(x, y);
|
||||
} else {
|
||||
dx <<= 1;
|
||||
balance = dx - dy;
|
||||
dy <<= 1;
|
||||
while (y != y2) {
|
||||
jlDrawPoint(x, y);
|
||||
jlDrawPixelSet(x, y);
|
||||
if (balance >= 0) {
|
||||
x += incX;
|
||||
balance -= dy;
|
||||
|
@ -451,7 +455,7 @@ void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) {
|
|||
balance += dx;
|
||||
y += incY;
|
||||
}
|
||||
jlDrawPoint(x, y);
|
||||
jlDrawPixelSet(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -684,7 +688,7 @@ void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) {
|
|||
|
||||
case COMMAND_COLOR:
|
||||
x1 = vec->data[p++];
|
||||
jlDrawColor((byte)x1);
|
||||
jlDrawColorSet((byte)x1);
|
||||
break;
|
||||
|
||||
case COMMAND_CLEAR:
|
||||
|
@ -697,7 +701,7 @@ void jlVecDisplay(jlVecT *vec, jint16 ox, jint16 oy) {
|
|||
x1 = ox + vec->data[p++];
|
||||
x1 = x1 + (jint16)(vec->data[p++] << 8);
|
||||
y1 = oy + vec->data[p++];
|
||||
jlDrawPoint(x1, y1);
|
||||
jlDrawPixelSet(x1, y1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -29,11 +29,23 @@
|
|||
#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_MAX 32767
|
||||
#define JUINT16_MIN 0
|
||||
#define JUINT16_MAX 65535
|
||||
|
||||
#define JOEY_DISPLAY (byte *)NULL
|
||||
|
||||
|
||||
// Determine platform and settings
|
||||
#ifdef __linux__
|
||||
|
@ -115,15 +127,11 @@ typedef unsigned long juint32;
|
|||
#endif
|
||||
|
||||
|
||||
#ifndef bool
|
||||
#define bool unsigned char
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#define byte unsigned char
|
||||
typedef byte *jlSurfaceT;
|
||||
|
||||
|
||||
extern jlSurfaceT _jlDrawTarget;
|
||||
extern jlSurfaceT _jlDrawTargetActual;
|
||||
extern byte _jlDrawColor;
|
||||
extern byte _jlDrawColorNibbles;
|
||||
extern byte _jlBorderColor;
|
||||
|
@ -150,7 +158,6 @@ enum _jlBorderColorsE {
|
|||
};
|
||||
typedef enum _jlBorderColorsE jlBorderColorsE;
|
||||
|
||||
|
||||
typedef struct {
|
||||
byte b : 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 jlStaSurfaceGet(sta) ((jlSurfaceT)sta->pixels)
|
||||
|
||||
|
||||
void jlDisplayBorder(jlBorderColorsE color);
|
||||
void jlDisplayPresent(void);
|
||||
|
||||
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 jlDrawBlitMap(jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, jlStaT *sta);
|
||||
void jlDrawBlit8x8(jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2);
|
||||
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, 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);
|
||||
void jlDrawColor(byte index);
|
||||
byte jlDrawColorGet(void);
|
||||
void jlDrawColorSet(byte 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);
|
||||
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);
|
||||
byte 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);
|
||||
|
@ -299,22 +309,22 @@ bool _jlVecLoad(jlVecT **vec, char *filename);
|
|||
|
||||
#ifdef JOEY_IIGS
|
||||
// Inlined functions - asm code
|
||||
extern void asmB88(juint32 surface, byte *p, 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 asmDrawBM(juint32 surface, jint16 startX, jint16 startY, jint16 width, jint16 height, byte *mapData, juint16 stride, byte *sta);
|
||||
//extern void asmDrawLine(juint32 surface, jint16 color, jint16 x1, jint16 y1, jint16 x2, jint16 y2);
|
||||
extern jint16 asmGetPoint(juint32 surface, jint16 x, jint16 y);
|
||||
extern void asmB88(jlSurfaceT target, jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2);
|
||||
extern void asmB88a(jlSurfaceT target, jlSurfaceT source, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2, byte alphaOffset);
|
||||
extern void asmDrawBM(jlSurfaceT target, jint16 startX, jint16 startY, jint16 width, jint16 height, byte *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 asmPoint(juint32 surface, jint16 color, jint16 x, jint16 y);
|
||||
extern void asmPoint(jlSurfaceT target, jint16 color, jint16 x, jint16 y);
|
||||
|
||||
// Inlined functions
|
||||
#define jlDrawBlit8x8(sta, cx1, cy1, cx2, cy2) asmB88(0x012000, (byte *)sta->pixels, cx1, cy1, cx2, cy2)
|
||||
#define jlDrawBlit8x8a(sta, cx1, cy1, cx2, cy2, offset) asmB88a(0x012000, (byte *)sta->pixels, 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 jlDrawGetPixel(x, y) asmGetPoint(0x012000, x, y)
|
||||
#define jlDrawPoint(x, y) asmPoint(0x012000, _jlDrawColorNibbles, x, y)
|
||||
//#define jlDrawLine(x1, y1, x2, y2) asmDrawLine(0x012000, _jlDrawColor, x1, y1, x2, y2)
|
||||
#define jlDrawBlit8x8(source, cx1, cy1, cx2, cy2) asmB88(_jlDrawTargetActual, source, cx1, cy1, cx2, cy2)
|
||||
#define jlDrawBlit8x8a(source, cx1, cy1, cx2, cy2, offset) asmB88a(_jlDrawTargetActual, source, cx1, cy1, cx2, cy2, offset)
|
||||
#define jlDrawBlitMap(startX, startY, width, height, mapData, stride, source) asmDrawBM(_jlDrawTargetActual, startX, startY, width, height, (byte *)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)
|
||||
#define jlUtilNibbleSwap(mem, count, old, new) asmNSwap(mem, count, (jint16)old, (jint16)new)
|
||||
#define jlUtilTimer asmGetVbl
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ void printAt(jlStaT *font, jint16 cx, jint16 cy, const char *what, ...) {
|
|||
for (counter=0; counter<(int)strlen(msg); counter++) {
|
||||
x = (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!");
|
||||
|
||||
jlStaDisplay(kanga);
|
||||
jlDrawColor(1);
|
||||
jlDrawColorSet(1);
|
||||
jlDrawBox(0, 0, 319, 199);
|
||||
|
||||
jlSoundMusicPlay("music");
|
||||
|
@ -81,7 +81,7 @@ int main(void) {
|
|||
printAt(font, 1, y++, "X = %d ", jlGameGetAxis(0));
|
||||
printAt(font, 1, y++, "Y = %d ", jlGameGetAxis(1));
|
||||
printAt(font, 1, y++, "T = %d ", jlUtilTimer());
|
||||
jlDrawColor((byte)color);
|
||||
jlDrawColorSet((byte)color);
|
||||
jlDrawLine(0, y2, 319, 199-y2);
|
||||
y2 += dy;
|
||||
if (y2 == 199 || y2 == 0) dy = -dy;
|
||||
|
|
|
@ -173,7 +173,7 @@ int main(int argc, char *argv[]) {
|
|||
if (args == 1) {
|
||||
EMIT_COMMAND;
|
||||
EMIT_BYTE;
|
||||
jlDrawColor((byte)data[i]);
|
||||
jlDrawColorSet((byte)data[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -195,7 +195,7 @@ int main(int argc, char *argv[]) {
|
|||
x1 = data[i++];
|
||||
EMIT_BYTE;
|
||||
y1 = data[i++];
|
||||
jlDrawPoint(x1, y1);
|
||||
jlDrawPixelSet(x1, y1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue