IIgs ASM line drawing fixed. Many bugs in stencil ASM code fixed. Still not blitting.
This commit is contained in:
parent
bfc7dc093e
commit
cd094cf23a
5 changed files with 119 additions and 97 deletions
|
@ -248,8 +248,8 @@ t equ 5 ; Temp
|
||||||
xc equ 7 ; X Counter
|
xc equ 7 ; X Counter
|
||||||
yc equ 9 ; Y Counter
|
yc equ 9 ; Y Counter
|
||||||
stenO equ 11 ; Stencil Buffer Offset
|
stenO equ 11 ; Stencil Buffer Offset
|
||||||
stenB equ 12 ; Stencil Buffer Data - bits - two bytes, but we only use one
|
stenB equ 13 ; Stencil Buffer Data - bits - two bytes, but we only use one
|
||||||
maskW equ 14 ; Actual mask bytes for pixels
|
maskW equ 15 ; Actual mask bytes for pixels
|
||||||
|
|
||||||
jsubroutine (4:surface,4:tiles,4:stencil,2:sx,2:sy,2:tx,2:ty),16
|
jsubroutine (4:surface,4:tiles,4:stencil,2:sx,2:sy,2:tx,2:ty),16
|
||||||
using GlobalData
|
using GlobalData
|
||||||
|
@ -285,11 +285,16 @@ maskW equ 14 ; Actual mask bytes for pixels
|
||||||
adc tx ; Add x position to scanline offset
|
adc tx ; Add x position to scanline offset
|
||||||
sta target ; Offset to start of target pixels
|
sta target ; Offset to start of target pixels
|
||||||
|
|
||||||
|
|
||||||
|
brk
|
||||||
|
|
||||||
; Find starting stencil byte
|
; Find starting stencil byte
|
||||||
clc
|
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
|
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
|
sta stenO ; Offset to start of mask data
|
||||||
|
|
||||||
|
|
||||||
|
@ -297,12 +302,13 @@ maskW equ 14 ; Actual mask bytes for pixels
|
||||||
sta xc
|
sta xc
|
||||||
sta yc
|
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
|
xba ; Shift it into the high byte
|
||||||
sta stenB ; Put it in to the stencil byte
|
sta stenB ; Put it in to the stencil byte
|
||||||
|
|
||||||
; Convert stencil byte to mask word (4 pixels)
|
; 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
|
lda #0 ; Initially, the mask word is all zero bits
|
||||||
sta maskW
|
sta maskW
|
||||||
nextNib lda stenB ; Load stencil byte into accumulator
|
nextNib lda stenB ; Load stencil byte into accumulator
|
||||||
|
@ -343,10 +349,6 @@ nextPix dex ; Decrement pixel counter in X
|
||||||
lda #2
|
lda #2
|
||||||
adc source
|
adc source
|
||||||
sta source
|
sta source
|
||||||
clc ; Increment to next stencil byte
|
|
||||||
lda #1
|
|
||||||
adc stenO
|
|
||||||
sta stenO
|
|
||||||
|
|
||||||
clc
|
clc
|
||||||
lda xc ; Increment X counter
|
lda xc ; Increment X counter
|
||||||
|
@ -375,7 +377,7 @@ nextPix dex ; Decrement pixel counter in X
|
||||||
sta yc
|
sta yc
|
||||||
cmp #8 ; End of Y pixels?
|
cmp #8 ; End of Y pixels?
|
||||||
bcs blitDone ; Yep!
|
bcs blitDone ; Yep!
|
||||||
brl blitTop ; Back for more
|
brl stenTop ; Back for more
|
||||||
|
|
||||||
blitDone jreturn
|
blitDone jreturn
|
||||||
end
|
end
|
||||||
|
@ -487,15 +489,6 @@ drawTop phy ; Keep Y for later
|
||||||
;
|
;
|
||||||
; Draws from (clpx0,clpy0) to (clpx1,clpy1) (output of a clipping routine).
|
; 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
|
asmDrawLine start
|
||||||
|
|
||||||
x0 equ 1
|
x0 equ 1
|
||||||
|
@ -922,7 +915,7 @@ rx_odd2 lda $beef,x
|
||||||
__o10 equ *-2
|
__o10 equ *-2
|
||||||
and #$0fff
|
and #$0fff
|
||||||
ora odd_c
|
ora odd_c
|
||||||
; sta $beef,x
|
sta $beef,x
|
||||||
__o11 equ *-2
|
__o11 equ *-2
|
||||||
|
|
||||||
dey
|
dey
|
||||||
|
@ -1503,6 +1496,7 @@ tScan anop
|
||||||
ldy #0 ; Load 0 into y register
|
ldy #0 ; Load 0 into y register
|
||||||
lda #0 ; Load 0 into accumulator
|
lda #0 ; Load 0 into accumulator
|
||||||
clc ; Clear carry flag
|
clc ; Clear carry flag
|
||||||
|
|
||||||
tSten anop
|
tSten anop
|
||||||
sta StTable,y ; Store accumulator in StencilTable+x
|
sta StTable,y ; Store accumulator in StencilTable+x
|
||||||
adc #320 ; Add 320 to accumulator (8 lines * 40 bytes)
|
adc #320 ; Add 320 to accumulator (8 lines * 40 bytes)
|
||||||
|
|
|
@ -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) {
|
byte jlDrawPixelGet(jint16 x, jint16 y) {
|
||||||
jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
|
jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual;
|
||||||
int p = x / 2 + y * 160;
|
int p = x / 2 + y * 160;
|
||||||
|
|
|
@ -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) {
|
bool _jlImgCopy(jlImgT *source, jlImgT **target) {
|
||||||
jlImgT *t = NULL;
|
jlImgT *t = NULL;
|
||||||
// Are we copying into a new image?
|
// Are we copying into a new image?
|
||||||
|
|
|
@ -239,7 +239,6 @@ void jlDisplayBorder(jlBorderColorsE color);
|
||||||
void jlDisplayPresent(void);
|
void jlDisplayPresent(void);
|
||||||
|
|
||||||
void jlDrawBlit8x8(jlSurfaceT source, jint16 sx, jint16 sy, jint16 tx, jint16 ty);
|
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 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, 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);
|
||||||
|
@ -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 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 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 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 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);
|
||||||
|
@ -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 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 jlDrawPixelGet(x, y) asmGetPoint(_jlDrawTargetActual, x, y)
|
||||||
#define jlDrawPixelSet(x, y) asmPoint(_jlDrawTargetActual, _jlDrawColorNibbles, 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 jlUtilNibbleSwap(mem, count, old, new) asmNSwap(mem, count, (jint16)old, (jint16)new)
|
||||||
#define jlUtilTimer asmGetVbl
|
#define jlUtilTimer asmGetVbl
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,40 @@ segment "testapp";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//extern jint16 asmTest(jlSurfaceT source);
|
void help(jlSurfaceT source, jlStnT *stencil, jint16 sx, jint16 sy, jint16 tx, jint16 ty) {
|
||||||
#ifdef JOEY_IIGS
|
|
||||||
extern void asmDrawLine(jlSurfaceT target, jint16 color, jint16 x1, jint16 y1, jint16 x2, jint16 y2);
|
int mo; // Mask offset
|
||||||
#else
|
int x;
|
||||||
#define asmDrawLine(s,c,x1,y1,x2,y2) jlDrawLine(x1,y1,x2,y2)
|
int y;
|
||||||
#endif
|
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!
|
// Font hacking!
|
||||||
|
@ -59,12 +87,14 @@ void printAt(jlImgT *font, jlStnT *stencil, jint16 cx, jint16 cy, const char *wh
|
||||||
ty = cy * 8;
|
ty = cy * 8;
|
||||||
|
|
||||||
for (counter=0; counter<(int)strlen(msg); counter++) {
|
for (counter=0; counter<(int)strlen(msg); counter++) {
|
||||||
//x = (msg[counter] - ' ') % 40;
|
|
||||||
//y = (msg[counter] - ' ') / 40;
|
|
||||||
x = msg[counter] % 40;
|
x = msg[counter] % 40;
|
||||||
y = msg[counter] / 40;
|
y = msg[counter] / 40;
|
||||||
if (stencil) {
|
if (stencil) {
|
||||||
|
#ifdef JOEY_PC
|
||||||
|
help(jlImgSurfaceGet(font), stencil, x, y, tx, ty);
|
||||||
|
#else
|
||||||
jlDrawBlit8x8a(jlImgSurfaceGet(font), stencil, x, y, tx, ty);
|
jlDrawBlit8x8a(jlImgSurfaceGet(font), stencil, x, y, tx, ty);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
jlDrawBlit8x8(jlImgSurfaceGet(font), x, y, tx, ty);
|
jlDrawBlit8x8(jlImgSurfaceGet(font), x, y, tx, ty);
|
||||||
}
|
}
|
||||||
|
@ -102,14 +132,13 @@ void lineTest(void) {
|
||||||
|
|
||||||
while (!jlKeyPressed()) {
|
while (!jlKeyPressed()) {
|
||||||
y = 17;
|
y = 17;
|
||||||
//printAt(font, 1, y++, "R = %d ", asmTest((jlSurfaceT)0x012000));
|
|
||||||
printAt(font, NULL, 1, y++, "Drawing %s ", what);
|
printAt(font, NULL, 1, y++, "Drawing %s ", what);
|
||||||
|
|
||||||
jlDrawColorSet((byte)color);
|
jlDrawColorSet((byte)color);
|
||||||
if (phase < 2) {
|
if (phase < 2) {
|
||||||
asmDrawLine(_jlDrawTargetActual, _jlDrawColor, x2, y2, 319-x2, 199-y2);
|
jlDrawLine(x2, y2, 319-x2, 199-y2);
|
||||||
} else {
|
} else {
|
||||||
asmDrawLine(_jlDrawTargetActual, _jlDrawColor, 319-x2, 199-y2, x2, y2);
|
jlDrawLine(319-x2, 199-y2, x2, y2);
|
||||||
}
|
}
|
||||||
ox = x2;
|
ox = x2;
|
||||||
oy = y2;
|
oy = y2;
|
||||||
|
@ -157,9 +186,9 @@ void lineTest(void) {
|
||||||
|
|
||||||
jlDrawColorSet((byte)0);
|
jlDrawColorSet((byte)0);
|
||||||
if (op < 2) {
|
if (op < 2) {
|
||||||
asmDrawLine(_jlDrawTargetActual, _jlDrawColor, ox, oy, 319-ox, 199-oy);
|
jlDrawLine(ox, oy, 319-ox, 199-oy);
|
||||||
} else {
|
} else {
|
||||||
asmDrawLine(_jlDrawTargetActual, _jlDrawColor, 319-ox, 199-oy, ox, oy);
|
jlDrawLine(319-ox, 199-oy, ox, oy);
|
||||||
}
|
}
|
||||||
|
|
||||||
color = nextColor;
|
color = nextColor;
|
||||||
|
|
Loading…
Add table
Reference in a new issue