add 1x sprite preview over tiles

This commit is contained in:
Jeremy Penner 2019-08-06 22:47:15 -04:00
parent ba62a080e9
commit ca1abba60b
6 changed files with 96 additions and 66 deletions

BIN
game.exe

Binary file not shown.

BIN
game.prj

Binary file not shown.

View file

@ -5,12 +5,21 @@ var spriteindex
var refresh-needed var refresh-needed
: refresh 1 refresh-needed ! ; : refresh 1 refresh-needed ! ;
array preview 128 allot
: color! >r dup r@ @ = if drop else r@ ! refresh then rdrop ; : color! >r dup r@ @ = if drop else r@ ! refresh then rdrop ;
: +sprite! spriteindex spritecount +!cycle refresh ; : +sprite! spriteindex spritecount +!cycle refresh ;
: draw-palette 0 0x11 for i 79 i 3 << drawfatbox next ; : draw-palette 0 0x11 for i 79 i 3 << drawfatbox next ;
: draw-preview
0 18 for
i preview tile>buf
spriteindex @ preview spr>buf
i 3 % 2 * 65 + i 3 / 16 * preview paintbuf
next ;
: mousepos>sprpos 3 >> swap 3 >> swap ; : mousepos>sprpos 3 >> swap 3 >> swap ;
: mousexys mousepos mousepos>sprpos spriteindex @ ; : mousexys mousepos mousepos>sprpos spriteindex @ ;
@ -52,6 +61,7 @@ var jiles-old-draw
: jiles-draw : jiles-draw
refresh-needed @ if refresh-needed @ if
mousehide mousehide
draw-preview
spriteindex @ drawfatsprite spriteindex @ drawfatsprite
lcolor @ 77 0 drawfatbox lcolor @ 77 0 drawfatbox
rcolor @ 78 0 drawfatbox rcolor @ 78 0 drawfatbox

View file

@ -346,6 +346,7 @@ void f_drawfatsprite() {
int x, y; int x, y;
DROP(1); DROP(1);
setAllPlanes();
for ( y = 0; y < 16; y ++ ) { for ( y = 0; y < 16; y ++ ) {
for ( x = 0; x < 16; x ++ ) { for ( x = 0; x < 16; x ++ ) {
int color = getsprpixel(x, y, spr); int color = getsprpixel(x, y, spr);
@ -422,6 +423,28 @@ void f_spritecount() {
PUSHI(NUM_SPRITES); PUSHI(NUM_SPRITES);
} }
void f_tile2buf() {
unsigned int *buf = TOP().p;
unsigned int itile = ST1().u;
DROP(2);
writeTile(buf, &tiles[itile * TILE_STRIDE]);
}
void f_spr2buf() {
unsigned int *buf = TOP().p;
unsigned int isprite = ST1().u;
DROP(2);
overlaySprite(buf, &sprites[isprite * SPRITE_STRIDE], 0, 0);
}
void f_paintbuf() {
unsigned int *buf = TOP().p;
int y = ST1().i;
int x = ST2().i;
DROP(3);
paintBuffer(buf, x + (y * 40));
}
/* INIT */ /* INIT */
void game_f_init(char *exe, char *bootjor) { void game_f_init(char *exe, char *bootjor) {
f_init(exe); f_init(exe);
@ -457,6 +480,9 @@ void game_f_init(char *exe, char *bootjor) {
CDEF("getpixel", f_getpixel); CDEF("getpixel", f_getpixel);
CDEF("spritecount", f_spritecount); CDEF("spritecount", f_spritecount);
CDEF("savegfx", f_savegfx); CDEF("savegfx", f_savegfx);
CDEF("tile>buf", f_tile2buf);
CDEF("spr>buf", f_spr2buf);
CDEF("paintbuf", f_paintbuf);
f_loadjor(bootjor); f_loadjor(bootjor);

118
tiles.c
View file

@ -74,57 +74,18 @@ void loadMap(unsigned char *map, unsigned int w, unsigned int h) {
memset(screen.dirty, D_BGTILE, PAGE_TILES_COUNT * 2); memset(screen.dirty, D_BGTILE, PAGE_TILES_COUNT * 2);
} }
int prepareBuffer(int pageX, int pageY) { void writeTile(unsigned int *buf, unsigned int far *tile) {
unsigned char *dirty = &screen.dirty[screen.currentPage][pageX + (pageY * PAGE_TILES_W)];
int i; int i;
if (!isBufIndex(*dirty)) {
unsigned int startX = screen.scrollX >> 4;
unsigned int startY = screen.scrollY >> 4;
unsigned char tile = screen.map[startX + pageX + ((startY + pageY) * screen.w)];
unsigned char ibuffer = screen.nextBuffer;
screen.nextBuffer = nextBufferIndex(ibuffer);
*dirty = ibuffer;
if ((tile & 0xf0) == 0xf0) {
unsigned int val = (tile & 0x01) ? 0xffff : 0x0000;
for (i = 0; i < 16; i ++) {
screen.buffer[ibuffer][i] = val;
}
val = (tile & 0x02) ? 0xffff : 0x0000;
for (i = 16; i < 32; i ++) {
screen.buffer[ibuffer][i] = val;
}
val = (tile & 0x04) ? 0xffff : 0x0000;
for (i = 32; i < 48; i ++) {
screen.buffer[ibuffer][i] = val;
}
val = (tile & 0x08) ? 0xffff : 0x0000;
for (i = 48; i < 64; i ++) {
screen.buffer[ibuffer][i] = val;
}
} else {
for (i = 0; i < BUF_WSIZE; i ++) { for (i = 0; i < BUF_WSIZE; i ++) {
screen.buffer[ibuffer][i] = (&screen.memTiles[tile * BUF_WSIZE])[i]; buf[i] = tile[i];
} }
}
screen.bufferOffset[ibuffer] = screen.pageOffset[screen.currentPage]
+ (pageX << 1) + (pageY * PAGE_STRIDE * 16);
}
return *dirty;
} }
void drawSpriteToBuf(unsigned int far *sprite, int pageX, int pageY, int shift, int yStart) { void overlaySprite(unsigned int *buf, unsigned int far *sprite, int shift, int yStart) {
unsigned int *buf;
unsigned int far *mask; unsigned int far *mask;
unsigned int maskval; unsigned int maskval;
int y, h, plane; int y, h, plane;
if (pageX < 0 || pageY < 0 ||
pageX >= PAGE_TILES_W || pageY >= PAGE_TILES_H ||
shift >= 16 || shift <= -16 ||
yStart <= -16 || yStart >= 16) {
return;
}
buf = screen.buffer[prepareBuffer(pageX, pageY)];
if (yStart < 0) { if (yStart < 0) {
sprite = &sprite[-yStart]; sprite = &sprite[-yStart];
h = yStart + 16; h = yStart + 16;
@ -155,6 +116,37 @@ void drawSpriteToBuf(unsigned int far *sprite, int pageX, int pageY, int shift,
} }
} }
int prepareBuffer(int pageX, int pageY) {
unsigned char *dirty = &screen.dirty[screen.currentPage][pageX + (pageY * PAGE_TILES_W)];
int i;
if (!isBufIndex(*dirty)) {
unsigned int startX = screen.scrollX >> 4;
unsigned int startY = screen.scrollY >> 4;
unsigned char tile = screen.map[startX + pageX + ((startY + pageY) * screen.w)];
unsigned char ibuffer = screen.nextBuffer;
screen.nextBuffer = nextBufferIndex(ibuffer);
*dirty = ibuffer;
writeTile(screen.buffer[ibuffer], &screen.memTiles[tile * BUF_WSIZE]);
screen.bufferOffset[ibuffer] = screen.pageOffset[screen.currentPage]
+ (pageX << 1) + (pageY * PAGE_STRIDE * 16);
}
return *dirty;
}
void drawSpriteToBuf(unsigned int far *sprite, int pageX, int pageY, int shift, int yStart) {
unsigned int *buf;
if (pageX < 0 || pageY < 0 ||
pageX >= PAGE_TILES_W || pageY >= PAGE_TILES_H ||
shift >= 16 || shift <= -16 ||
yStart <= -16 || yStart >= 16) {
return;
}
buf = screen.buffer[prepareBuffer(pageX, pageY)];
overlaySprite(buf, sprite, shift, yStart);
}
void drawSprite(unsigned int far *sprite, int x, int y) { void drawSprite(unsigned int far *sprite, int x, int y) {
int pageX = (int)(x - (screen.scrollX & 0xfff0)) >> 4; int pageX = (int)(x - (screen.scrollX & 0xfff0)) >> 4;
int pageY = (int)(y - (screen.scrollY & 0xfff0)) >> 4; int pageY = (int)(y - (screen.scrollY & 0xfff0)) >> 4;
@ -195,6 +187,25 @@ void scroll(int newX, int newY) {
screen.scrollY = newY; screen.scrollY = newY;
} }
void paintBufferPlane(unsigned int *buf, unsigned int vidOffset, int stride, int plane) {
unsigned int drawOffset = vidOffset >> 1;
unsigned int y, bmp;
for (y = 0; y < 16; y ++) {
bmp = buf[y + (BUF_WSTRIDE * plane)];
WVID[drawOffset] = (bmp << 8) | (bmp >> 8);
drawOffset += stride >> 1;
}
}
void paintBuffer(unsigned int *buf, unsigned int vidOffset) {
int plane;
setWriteMode(0);
for (plane = 0; plane < 4; plane ++) {
setPlane(plane);
paintBufferPlane(buf, vidOffset, 40, plane);
}
}
void drawScreen() { void drawScreen() {
unsigned int startX = screen.scrollX >> 4; unsigned int startX = screen.scrollX >> 4;
unsigned int startY = screen.scrollY >> 4; unsigned int startY = screen.scrollY >> 4;
@ -213,10 +224,8 @@ void drawScreen() {
for (x = startX; x < startX + PAGE_TILES_W; x ++) { for (x = startX; x < startX + PAGE_TILES_W; x ++) {
if (dirty[di++] == D_BGTILE) { if (dirty[di++] == D_BGTILE) {
char tile = screen.map[x + (y * screen.w)]; char tile = screen.map[x + (y * screen.w)];
if ((tile & 0xf0) != 0xf0) {
blitTile(screen.tilesOffset + (tile << 5), drawOffset); blitTile(screen.tilesOffset + (tile << 5), drawOffset);
} }
}
drawOffset += 2; drawOffset += 2;
} }
drawOffset += PAGE_STRIDE * 15; drawOffset += PAGE_STRIDE * 15;
@ -225,29 +234,10 @@ void drawScreen() {
for(plane = 0; plane < 4; plane ++) { for(plane = 0; plane < 4; plane ++) {
setPlane(plane); setPlane(plane);
for (di = screen.firstBuffer; di != screen.nextBuffer; di = nextBufferIndex(di)) { for (di = screen.firstBuffer; di != screen.nextBuffer; di = nextBufferIndex(di)) {
drawOffset = screen.bufferOffset[di] >> 1; paintBufferPlane(screen.buffer[di], screen.bufferOffset[di], PAGE_STRIDE, plane);
for (y = 0; y < 16; y ++) {
bmp = screen.buffer[di][y + (BUF_WSTRIDE * plane)];
WVID[drawOffset] = (bmp << 8) | (bmp >> 8);
drawOffset += PAGE_STRIDE >> 1;
}
} }
} }
setAllPlanes(); setAllPlanes();
di = 0;
drawOffset = screen.pageOffset[screen.currentPage];
for (y = startY; y < startY + PAGE_TILES_H; y ++) {
for (x = startX; x < startX + PAGE_TILES_W; x ++) {
if (dirty[di++] == D_BGTILE) {
char tile = screen.map[x + (y * screen.w)];
if ((tile & 0xf0) == 0xf0) {
blitSolidBlock(drawOffset, tile & 0x0f);
}
}
drawOffset += 2;
}
drawOffset += PAGE_STRIDE * 15;
}
setDisplayOffset(scrollOffset); setDisplayOffset(scrollOffset);
setHorizontalPan(screen.scrollX & 0x07); setHorizontalPan(screen.scrollX & 0x07);

View file

@ -12,6 +12,10 @@ void drawScreen();
void blit32x32(unsigned int offsetFrom, unsigned int offsetTo); void blit32x32(unsigned int offsetFrom, unsigned int offsetTo);
void writeTile(unsigned int *buf, unsigned int far *tile);
void overlaySprite(unsigned int *buf, unsigned int far *sprite, int shift, int yStart);
void paintBuffer(unsigned int *buf, unsigned int vidOffset);
#define PAGE_TILES_W 21 #define PAGE_TILES_W 21
#define PAGE_TILES_H 14 #define PAGE_TILES_H 14
#define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W) #define PAGE_TILES_COUNT (PAGE_TILES_H * PAGE_TILES_W)