diff --git a/joeylib/src/jIIgs.asm b/joeylib/src/jIIgs.asm index af33dea..1b33319 100644 --- a/joeylib/src/jIIgs.asm +++ b/joeylib/src/jIIgs.asm @@ -248,8 +248,8 @@ t equ 5 ; Temp xc equ 7 ; X Counter yc equ 9 ; Y Counter stenO equ 11 ; Stencil Buffer Offset -stenB equ 12 ; Stencil Buffer Data - bits - two bytes, but we only use one -maskW equ 14 ; Actual mask bytes for pixels +stenB equ 13 ; Stencil Buffer Data - bits - two bytes, but we only use one +maskW equ 15 ; Actual mask bytes for pixels jsubroutine (4:surface,4:tiles,4:stencil,2:sx,2:sy,2:tx,2:ty),16 using GlobalData @@ -285,11 +285,16 @@ maskW equ 14 ; Actual mask bytes for pixels adc tx ; Add x position to scanline offset sta target ; Offset to start of target pixels + + brk + ; Find starting stencil byte clc - ldy ty ; Vertical cell position + lda sy ; Vertical cell position + asl a ; Multiply by two to get offset into stencil table (two bytes per entry in table) + tay ; Move to Y lda StTable,y ; Load offset location of start of this row in the stencil buffer - adc tx ; Add x position to address offset + adc sx ; Add x position to address offset sta stenO ; Offset to start of mask data @@ -297,12 +302,13 @@ maskW equ 14 ; Actual mask bytes for pixels sta xc sta yc -blitTop lda [stenO] ; Load byte at stencil offset +stenTop ldy stenO ; Load byte at stencil offset + lda [stencil],y xba ; Shift it into the high byte sta stenB ; Put it in to the stencil byte ; Convert stencil byte to mask word (4 pixels) - ldx #4 ; How many pixels to process? +blitTop ldx #4 ; How many pixels to process? lda #0 ; Initially, the mask word is all zero bits sta maskW nextNib lda stenB ; Load stencil byte into accumulator @@ -343,10 +349,6 @@ nextPix dex ; Decrement pixel counter in X lda #2 adc source sta source - clc ; Increment to next stencil byte - lda #1 - adc stenO - sta stenO clc lda xc ; Increment X counter @@ -375,7 +377,7 @@ nextPix dex ; Decrement pixel counter in X sta yc cmp #8 ; End of Y pixels? bcs blitDone ; Yep! - brl blitTop ; Back for more + brl stenTop ; Back for more blitDone jreturn end @@ -487,15 +489,6 @@ drawTop phy ; Keep Y for later ; ; Draws from (clpx0,clpy0) to (clpx1,clpy1) (output of a clipping routine). ; -asmTest start -result equ 1 - jsubroutine (4:surface),2 - lda surface ; Should be $2000 - lda surface+1 - sta result - jreturn 2:result - end - asmDrawLine start x0 equ 1 @@ -922,7 +915,7 @@ rx_odd2 lda $beef,x __o10 equ *-2 and #$0fff ora odd_c -; sta $beef,x + sta $beef,x __o11 equ *-2 dey @@ -1503,6 +1496,7 @@ tScan anop ldy #0 ; Load 0 into y register lda #0 ; Load 0 into accumulator clc ; Clear carry flag + tSten anop sta StTable,y ; Store accumulator in StencilTable+x adc #320 ; Add 320 to accumulator (8 lines * 40 bytes) diff --git a/joeylib/src/jSDL2.c b/joeylib/src/jSDL2.c index 82cc8c0..e205a93 100644 --- a/joeylib/src/jSDL2.c +++ b/joeylib/src/jSDL2.c @@ -252,6 +252,66 @@ void jlDrawClear(void) { } +void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) { + jint16 x; + jint16 y; + jint16 dx; + jint16 dy; + jint16 incX; + jint16 incY; + jint16 balance; + + if (x2 >= x1) { + dx = x2 - x1; + incX = 1; + } else { + dx = x1 - x2; + incX = -1; + } + + if (y2 >= y1) { + dy = y2 - y1; + incY = 1; + } else { + dy = y1 - y2; + incY = -1; + } + + x = x1; + y = y1; + + if (dx >= dy) { + dy <<= 1; + balance = dy - dx; + dx <<= 1; + while (x != x2) { + jlDrawPixelSet(x, y); + if (balance >= 0) { + y += incY; + balance -= dx; + } + balance += dy; + x += incX; + } + jlDrawPixelSet(x, y); + } else { + dx <<= 1; + balance = dx - dy; + dy <<= 1; + while (y != y2) { + jlDrawPixelSet(x, y); + if (balance >= 0) { + x += incX; + balance -= dy; + } + balance += dx; + y += incY; + } + jlDrawPixelSet(x, y); + } +} + + byte jlDrawPixelGet(jint16 x, jint16 y) { jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual; int p = x / 2 + y * 160; diff --git a/joeylib/src/joey.c b/joeylib/src/joey.c index abefe17..d669f00 100644 --- a/joeylib/src/joey.c +++ b/joeylib/src/joey.c @@ -400,66 +400,6 @@ void jlDrawFillTo(jint16 x, jint16 y, byte color) { } -void jlDrawLine(jint16 x1, jint16 y1, jint16 x2, jint16 y2) { - jint16 x; - jint16 y; - jint16 dx; - jint16 dy; - jint16 incX; - jint16 incY; - jint16 balance; - - if (x2 >= x1) { - dx = x2 - x1; - incX = 1; - } else { - dx = x1 - x2; - incX = -1; - } - - if (y2 >= y1) { - dy = y2 - y1; - incY = 1; - } else { - dy = y1 - y2; - incY = -1; - } - - x = x1; - y = y1; - - if (dx >= dy) { - dy <<= 1; - balance = dy - dx; - dx <<= 1; - while (x != x2) { - jlDrawPixelSet(x, y); - if (balance >= 0) { - y += incY; - balance -= dx; - } - balance += dy; - x += incX; - } - jlDrawPixelSet(x, y); - } else { - dx <<= 1; - balance = dx - dy; - dy <<= 1; - while (y != y2) { - jlDrawPixelSet(x, y); - if (balance >= 0) { - x += incX; - balance -= dy; - } - balance += dx; - y += incY; - } - jlDrawPixelSet(x, y); - } -} - - bool _jlImgCopy(jlImgT *source, jlImgT **target) { jlImgT *t = NULL; // Are we copying into a new image? diff --git a/joeylib/src/joey.h b/joeylib/src/joey.h index e1b0d33..2cd1a5d 100644 --- a/joeylib/src/joey.h +++ b/joeylib/src/joey.h @@ -239,7 +239,6 @@ void jlDisplayBorder(jlBorderColorsE color); void jlDisplayPresent(void); void jlDrawBlit8x8(jlSurfaceT source, jint16 sx, jint16 sy, jint16 tx, jint16 ty); -//void jlDrawBlit8x8a(jlSurfaceT source, jint16 sx, jint16 sy, jint16 tx, jint16 ty, byte offset); 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 jlDrawBox(jint16 x1, jint16 y1, jint16 x2, jint16 y2); @@ -326,7 +325,7 @@ bool _jlVecLoad(jlVecT **vec, char *filename); 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 asmDrawLine(jlSurfaceT target, 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(jlSurfaceT target, jint16 x, jint16 y); extern juint16 asmGetVbl(void); extern void asmNSwap(byte *mem, jint16 count, jint16 old, jint16 new); @@ -338,7 +337,7 @@ extern void asmPoint(jlSurfaceT target, jint16 color, jint16 x, jint16 y); #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 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 diff --git a/joeylib/src/test.c b/joeylib/src/test.c index 6c1ba35..6b89f3b 100644 --- a/joeylib/src/test.c +++ b/joeylib/src/test.c @@ -32,12 +32,40 @@ segment "testapp"; #endif -//extern jint16 asmTest(jlSurfaceT source); -#ifdef JOEY_IIGS -extern void asmDrawLine(jlSurfaceT target, jint16 color, jint16 x1, jint16 y1, jint16 x2, jint16 y2); -#else -#define asmDrawLine(s,c,x1,y1,x2,y2) jlDrawLine(x1,y1,x2,y2) -#endif +void help(jlSurfaceT source, jlStnT *stencil, jint16 sx, jint16 sy, jint16 tx, jint16 ty) { + + int mo; // Mask offset + int x; + int y; + byte b; // Mask bit index + + printf("\n"); + + mo = ((sy & 0x1f) * 8 * 40) + (sx & 0x3f); // This is in tiles + + printf("Offset: %04x sx: %02x sy: %02x\n", mo, sx, sy); + + for (y=0; y<8; y++) { + b = 7; + printf("Byte: %02x ", stencil->pixels[mo]); + for (x=0; x<4; x++) { + if ((stencil->pixels[mo] & (1 << b--)) != 0) { + printf("X"); + } else { + printf("."); + } + if ((stencil->pixels[mo] & (1 << b--)) != 0) { + printf("X"); + } else { + printf("."); + } + } + mo += 40; + printf("\n"); + } + + jlDrawBlit8x8a(source, stencil, sx, sy, tx, ty); +} // Font hacking! @@ -59,12 +87,14 @@ void printAt(jlImgT *font, jlStnT *stencil, jint16 cx, jint16 cy, const char *wh ty = cy * 8; for (counter=0; counter<(int)strlen(msg); counter++) { - //x = (msg[counter] - ' ') % 40; - //y = (msg[counter] - ' ') / 40; x = msg[counter] % 40; y = msg[counter] / 40; if (stencil) { +#ifdef JOEY_PC + help(jlImgSurfaceGet(font), stencil, x, y, tx, ty); +#else jlDrawBlit8x8a(jlImgSurfaceGet(font), stencil, x, y, tx, ty); +#endif } else { jlDrawBlit8x8(jlImgSurfaceGet(font), x, y, tx, ty); } @@ -102,14 +132,13 @@ void lineTest(void) { while (!jlKeyPressed()) { y = 17; - //printAt(font, 1, y++, "R = %d ", asmTest((jlSurfaceT)0x012000)); printAt(font, NULL, 1, y++, "Drawing %s ", what); jlDrawColorSet((byte)color); if (phase < 2) { - asmDrawLine(_jlDrawTargetActual, _jlDrawColor, x2, y2, 319-x2, 199-y2); + jlDrawLine(x2, y2, 319-x2, 199-y2); } else { - asmDrawLine(_jlDrawTargetActual, _jlDrawColor, 319-x2, 199-y2, x2, y2); + jlDrawLine(319-x2, 199-y2, x2, y2); } ox = x2; oy = y2; @@ -157,9 +186,9 @@ void lineTest(void) { jlDrawColorSet((byte)0); if (op < 2) { - asmDrawLine(_jlDrawTargetActual, _jlDrawColor, ox, oy, 319-ox, 199-oy); + jlDrawLine(ox, oy, 319-ox, 199-oy); } else { - asmDrawLine(_jlDrawTargetActual, _jlDrawColor, 319-ox, 199-oy, ox, oy); + jlDrawLine(319-ox, 199-oy, ox, oy); } color = nextColor;