diff --git a/assets/JoeyLib Logo.xcf b/assets/JoeyLib Logo.xcf index 4f59288..ac0acd0 100644 Binary files a/assets/JoeyLib Logo.xcf and b/assets/JoeyLib Logo.xcf differ diff --git a/assets/STAtemplate.xcf b/assets/STAtemplate.xcf index 3be25e1..74f736f 100644 Binary files a/assets/STAtemplate.xcf and b/assets/STAtemplate.xcf differ diff --git a/joeylib/src/font.xcf b/joeylib/src/font.xcf index fd60997..83235de 100644 Binary files a/joeylib/src/font.xcf and b/joeylib/src/font.xcf differ diff --git a/joeylib/src/jIIgs.asm b/joeylib/src/jIIgs.asm index 5091297..d0d6169 100644 --- a/joeylib/src/jIIgs.asm +++ b/joeylib/src/jIIgs.asm @@ -48,16 +48,13 @@ yc equ 9 ; Y Counter using GlobalData ; Find offset into tile memory - lda sx ; Multiply sx by 4 to get offset (two pixels per byte) - asl a - asl a +; Divide source horizontal position by two since there are two pixels per byte + lda sx ; Load X source position into accumulator + lsr a sta t clc - lda sy ; Multiply sy by 16 to get index into scanline table - asl a - asl a - asl a - asl a ; y screen location is now in the accumulator + lda sy ; Load sy to get index into scanline table + asl a ; Multiply by two to get offset into scanline table (two bytes per entry in table) tay clc lda ScTable,y ; Load byte offset of y position from table @@ -141,16 +138,13 @@ stenB equ 13 ; Stencil bit pattern using GlobalData ; Find offset into tile memory - lda sx ; Multiply sx by 4 to get offset (two pixels per byte) - asl a - asl a +; Divide source horizontal position by two since there are two pixels per byte + lda sx ; Load X source position into accumulator + lsr a ; Shift Right - divide by 2 sta t clc - lda sy ; Multiply sy by 16 to get index into scanline table - asl a - asl a - asl a - asl a ; y screen location is now in the accumulator + lda sy ; Load sy to get index into scanline table + asl a ; Multiply by two to get offset into scanline table (two bytes per entry in table) tay clc lda ScTable,y ; Load byte offset of y position from table @@ -172,6 +166,7 @@ stenB equ 13 ; Stencil bit pattern sta target ; Offset to start of target pixels ; Find starting stencil byte +;***FIX*** Does not handle non-byte boundaries! clc lda sy ; Vertical cell position asl a ; Multiply by two to get offset into stencil table (two bytes per entry in table) @@ -272,6 +267,9 @@ asmBorder start ;---------------------------------------- ; Draw a block of tiles from a region of tile data +; +; ***FIX*** This no longer does what we want since +; blitting source addresses are now in pixels. Fix! ;---------------------------------------- asmDrawBM start diff --git a/joeylib/src/jSDL2.c b/joeylib/src/jSDL2.c index e205a93..75ad766 100644 --- a/joeylib/src/jSDL2.c +++ b/joeylib/src/jSDL2.c @@ -162,8 +162,9 @@ void jlDrawBlit8x8(jlSurfaceT source, jint16 sx, jint16 sy, jint16 tx, jint16 ty 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 = ((sy & 0x1f) * 8 * 160) + ((sx & 0x3f) * 4); // This is in tiles + if (jlUtilIsOdd(sx)) sx--; // sx must be even because there are two pixels per byte + o1 = sy * 160 + (int)(sx * 0.5); // This is in pixels... + if (jlUtilIsOdd(tx)) tx--; // tx must be even because there are two pixels per byte o2 = ty * 160 + (int)(tx * 0.5); // This is in pixels... @@ -178,47 +179,61 @@ 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) { - int mo; // Mask offset int so; // Source Pixel Offset int to; // Target Pixel Offset + int i; int x; int y; - byte b; // Mask bit index + int pos; 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 = ((sy & 0x1f) * 8 * 40) + (sx & 0x3f); // This is in tiles - so = ((sy & 0x1f) * 8 * 160) + ((sx & 0x3f) * 4); // This is in tiles + if (jlUtilIsOdd(sx)) sx--; // sx must be even because there are two pixels per byte + so = sy * 160 + (int)(sx * 0.5); // This is in pixels... + if (jlUtilIsOdd(tx)) tx--; // tx must be even because there are two pixels per byte to = ty * 160 + (int)(tx * 0.5); // This is in pixels... + // Color = <-- 40 tiles, 80 bytes, 160 pixels --> + // Stencil = <-- 20 bytes, 160 bits --> + + i = so / 8; + pos = 7 - (so % 8); + for (y=0; y<8; y++) { - b = 7; for (x=0; x<4; x++) { + t = target[to]; s = pixels[so++]; + i = ((sy + y) * 320 + (sx + x * 2)); + pos = 7 - (i % 8); + i /= 8; + //***FIX*** Another endian order issue. Left & Right are swapped. - if ((stencil->pixels[mo] & (1 << b--)) != 0) { + if ((stencil->pixels[i] & (1 << pos)) != 0) { t.r = s.r; } - if ((stencil->pixels[mo] & (1 << b--)) != 0) { + i = ((sy + y) * 320 + (sx + x * 2 + 1)); + pos = 7 - (i % 8); + i /= 8; + + if ((stencil->pixels[i] & (1 << pos)) != 0) { t.l = s.l; } target[to++] = t; } - mo += 40; so += 156; to += 156; } } +//***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) { // startX = start tile for drawing - in pixels // startY = start tile for drawing - in pixels diff --git a/joeylib/src/kanga.xcf b/joeylib/src/kanga.xcf index a15fd9d..6118b2f 100644 Binary files a/joeylib/src/kanga.xcf and b/joeylib/src/kanga.xcf differ diff --git a/joeylib/src/test.c b/joeylib/src/test.c index 8c236be..0f0eb40 100644 --- a/joeylib/src/test.c +++ b/joeylib/src/test.c @@ -88,8 +88,8 @@ 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) * 8; + y = (msg[counter] / 40) * 8; if (stencil) { #ifdef JOEY_PC help(jlImgSurfaceGet(font), stencil, x, y, tx, ty); @@ -109,9 +109,8 @@ void blitTest(void) { jlStnT *stencil = NULL; jint16 y; jint16 x; - bool doOnce = true; - if (!jlImgLoad(font, "font")) jlUtilDie("Unable to load font.sta!"); + if (!jlImgLoad(font, "font")) jlUtilDie("Unable to load font.img!"); if (!jlStnLoad(stencil, "font")) jlUtilDie("Unable to load font.stn!"); jlImgDisplay(font); @@ -127,19 +126,11 @@ void blitTest(void) { jlDisplayPresent(); jlKeyWaitForAny(); - /* y = 91; while (!jlKeyPressed()) { for (x=0; x<319-8; x++) { - - if (doOnce) { - jlDrawBlit8x8a(jlImgSurfaceGet(font), stencil, 0, 2, 24, 24); - jlDrawBlit8x8(jlImgSurfaceGet(font), 0, 2, 40, 24); - doOnce = false; - } - - jlDrawBlit8x8(jlImgSurfaceGet(font), 1, 0, x, y); - printAt(font, NULL, 1, 1, "Drawing at %d x %d ", x, y); + jlDrawBlit8x8(jlImgSurfaceGet(font), 8, 0, x, y); + printAt(font, NULL, 1, 6, "Drawing at %d x %d ", x, y); jlDisplayPresent(); jlDrawBlit8x8(jlImgSurfaceGet(font), 0, 0, x, y); jlUtilSleep(1); @@ -149,7 +140,6 @@ void blitTest(void) { } } jlKeyRead(); - */ jlStnFree(stencil); jlImgFree(font); @@ -204,8 +194,8 @@ void lineTest(void) { jint16 nextColor = 1; char what[32]; - if (!jlImgLoad(kanga, "kanga")) jlUtilDie("Unable to load kanga.sta!"); - if (!jlImgLoad(font, "font")) jlUtilDie("Unable to load font.sta!"); + if (!jlImgLoad(kanga, "kanga")) jlUtilDie("Unable to load kanga.img!"); + if (!jlImgLoad(font, "font")) jlUtilDie("Unable to load font.img!"); jlImgDisplay(kanga); jlDrawColorSet(1); @@ -292,13 +282,69 @@ void lineTest(void) { } +void showStencil(void) { + jlStnT *stencil = NULL; + jint16 y; + jint16 x; + jint16 count; + juint16 index; + byte bit; + + if (!jlStnLoad(stencil, "font")) jlUtilDie("Unable to load font.stn!"); + + jlDrawColorSet(0); + jlDrawClear(); + jlDrawColorSet(15); + + // Draw stencil to screen linerally + index = -1; + count = 0; + for (y=0; y<200; y++) { + for (x=0; x<320; x++) { + count--; + if (count < 0) { + count = 7; + index++; + bit = stencil->pixels[index]; + } + if (bit & (1 << count)) { + jlDrawPixelSet(x, y); + } + } + jlDisplayPresent(); + } + jlKeyWaitForAny(); + + jlDrawColorSet(0); + jlDrawClear(); + jlDrawColorSet(15); + + // Draw stencil by pixel location + for (y=0; y<200; y++) { + for (x=0; x<320; x++) { + index = (y * 320 + x); + count = 7 - (index % 8); + index /= 8; + bit = stencil->pixels[index]; + if (bit & (1 << count)) { + jlDrawPixelSet(x, y); + } + } + jlDisplayPresent(); + } + jlKeyWaitForAny(); + +} + + int main(void) { jlUtilStartup("JoeyLib Test"); - //blitTest(); - exerciseAPI(); + blitTest(); + //exerciseAPI(); //grid(); //lineTest(); + //showStencil(); jlUtilShutdown(); }