bugfixes: TIF loading, sprite display
This commit is contained in:
parent
aeb1f47f51
commit
c2d648d284
82
testbed.c
82
testbed.c
|
@ -386,11 +386,12 @@ int tifLoad(FILE *f, TifImageMeta_t meta, unsigned int *planeBuf, int maxY, int
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
unsigned char rowData[MAX_WIDTH >> 1];
|
unsigned char rowData[MAX_WIDTH >> 1];
|
||||||
unsigned int planeStride = (meta.width >> 4) * yRepeat;
|
unsigned int planeStride = (meta.width >> 4) * yRepeat;
|
||||||
unsigned int *b = planeBuf - 1;
|
unsigned int *bp = planeBuf;
|
||||||
unsigned int *g = b + planeStride;
|
unsigned int *gp = bp + planeStride;
|
||||||
unsigned int *r = g + planeStride;
|
unsigned int *rp = gp + planeStride;
|
||||||
unsigned int *i = r + planeStride;
|
unsigned int *ip = rp + planeStride;
|
||||||
unsigned int *m = i + planeStride;
|
unsigned int *mp = ip + planeStride;
|
||||||
|
unsigned char bv, gv, rv, iv;
|
||||||
|
|
||||||
if (meta.width > MAX_WIDTH || (meta.width % 16) != 0 || planes < 4 || planes > 5) {
|
if (meta.width > MAX_WIDTH || (meta.width % 16) != 0 || planes < 4 || planes > 5) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -402,30 +403,31 @@ int tifLoad(FILE *f, TifImageMeta_t meta, unsigned int *planeBuf, int maxY, int
|
||||||
fseek(f, offset, SEEK_SET);
|
fseek(f, offset, SEEK_SET);
|
||||||
|
|
||||||
for (irow = 0; irow < meta.rowsPerStrip; irow ++) {
|
for (irow = 0; irow < meta.rowsPerStrip; irow ++) {
|
||||||
fread(rowData, 1, meta.width >> 1, f);
|
int ipixelpairLim = meta.width >> 1;
|
||||||
for (ipixelpair = 0; ipixelpair < meta.width >> 1; ipixelpair ++) {
|
fread(rowData, 1, ipixelpairLim, f);
|
||||||
|
bv = gv = rv = iv = 0;
|
||||||
|
for (ipixelpair = 0; ipixelpair < ipixelpairLim; ipixelpair ++) {
|
||||||
unsigned char pixelpair = rowData[ipixelpair];
|
unsigned char pixelpair = rowData[ipixelpair];
|
||||||
int bpair = (pixelpair & 0x01) | (pixelpair & 0x10) >> 3;
|
int bpair = (pixelpair & 0x01) | (pixelpair & 0x10) >> 3;
|
||||||
int gpair = (pixelpair & 0x02) >> 1 | (pixelpair & 0x20) >> 4;
|
int gpair = (pixelpair & 0x02) >> 1 | (pixelpair & 0x20) >> 4;
|
||||||
int rpair = (pixelpair & 0x04) >> 2 | (pixelpair & 0x40) >> 5;
|
int rpair = (pixelpair & 0x04) >> 2 | (pixelpair & 0x40) >> 5;
|
||||||
int ipair = (pixelpair & 0x08) >> 3 | (pixelpair & 0x80) >> 6;
|
int ipair = (pixelpair & 0x08) >> 3 | (pixelpair & 0x80) >> 6;
|
||||||
int shift = (ipixelpair % 8) << 1;
|
int shift = (3 - (ipixelpair % 4)) << 1;
|
||||||
if (shift == 0) {
|
|
||||||
*++b = bpair;
|
bv |= bpair << shift;
|
||||||
*++g = gpair;
|
gv |= gpair << shift;
|
||||||
*++r = rpair;
|
rv |= rpair << shift;
|
||||||
*++i = ipair;
|
iv |= ipair << shift;
|
||||||
|
|
||||||
|
if (shift == 0 || ipixelpair == ipixelpairLim - 1) {
|
||||||
|
*bp++ = bv;
|
||||||
|
*gp++ = gv;
|
||||||
|
*rp++ = rv;
|
||||||
|
*ip++ = iv;
|
||||||
if (planes == 5) {
|
if (planes == 5) {
|
||||||
*++m = bpair & gpair & rpair & ipair;
|
*mp++ = bv & gv & rv & iv;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*b |= bpair << shift;
|
|
||||||
*g |= gpair << shift;
|
|
||||||
*r |= rpair << shift;
|
|
||||||
*i |= ipair << shift;
|
|
||||||
if (planes == 5) {
|
|
||||||
*m |= (bpair & gpair & rpair & ipair) << shift;
|
|
||||||
}
|
}
|
||||||
|
bv = gv = rv = iv = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
|
@ -433,10 +435,11 @@ int tifLoad(FILE *f, TifImageMeta_t meta, unsigned int *planeBuf, int maxY, int
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
if (y % yRepeat == 0) {
|
if (y % yRepeat == 0) {
|
||||||
b += planeStride * (planes - 1);
|
bp += planeStride * (planes - 1);
|
||||||
g += planeStride * (planes - 1);
|
gp += planeStride * (planes - 1);
|
||||||
r += planeStride * (planes - 1);
|
rp += planeStride * (planes - 1);
|
||||||
i += planeStride * (planes - 1);
|
ip += planeStride * (planes - 1);
|
||||||
|
mp += planeStride * (planes - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -509,11 +512,11 @@ int prepareBuffer(int pageX, int pageY) {
|
||||||
unsigned int startY = screen.scrollY >> 4;
|
unsigned int startY = screen.scrollY >> 4;
|
||||||
unsigned char tile = screen.map[startX + pageX + ((startY + pageY) * screen.w)];
|
unsigned char tile = screen.map[startX + pageX + ((startY + pageY) * screen.w)];
|
||||||
unsigned char ibuffer = screen.nextBuffer;
|
unsigned char ibuffer = screen.nextBuffer;
|
||||||
screen.nextBuffer = nextBufferIndex(screen.nextBuffer);
|
screen.nextBuffer = nextBufferIndex(ibuffer);
|
||||||
*dirty = ibuffer;
|
*dirty = ibuffer;
|
||||||
memcpy(screen.buffer[ibuffer], &screen.memTiles[tile * BUF_WSIZE], BUF_WSIZE);
|
memcpy(screen.buffer[ibuffer], &screen.memTiles[tile * BUF_WSIZE], BUF_WSIZE << 1);
|
||||||
screen.bufferOffset[ibuffer] = screen.pageOffset[screen.currentPage]
|
screen.bufferOffset[ibuffer] = screen.pageOffset[screen.currentPage]
|
||||||
+ (pageX << 1) + (pageY * PAGE_STRIDE);
|
+ (pageX << 1) + (pageY * PAGE_STRIDE * 16);
|
||||||
}
|
}
|
||||||
return *dirty;
|
return *dirty;
|
||||||
}
|
}
|
||||||
|
@ -558,12 +561,10 @@ void drawSpriteToBuf(unsigned int *sprite, int pageX, int pageY, int shift, int
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawSprite(unsigned int *sprite, int x, int y) {
|
void drawSprite(unsigned int *sprite, int x, int y) {
|
||||||
unsigned int startX = screen.scrollX >> 4;
|
int pageX = (x - (screen.scrollX & 0xfff0)) >> 4;
|
||||||
unsigned int startY = screen.scrollY >> 4;
|
int pageY = (y - (screen.scrollY & 0xfff0)) >> 4;
|
||||||
int pageX = (x - startX) >> 4;
|
int pageOffsetX = x & 0x0f;
|
||||||
int pageY = (y - startY) >> 4;
|
int pageOffsetY = y & 0x0f;
|
||||||
int pageOffsetX = x - (pageX << 4);
|
|
||||||
int pageOffsetY = y - (pageY << 4);
|
|
||||||
|
|
||||||
drawSpriteToBuf(sprite, pageX, pageY, pageOffsetX, pageOffsetY);
|
drawSpriteToBuf(sprite, pageX, pageY, pageOffsetX, pageOffsetY);
|
||||||
drawSpriteToBuf(sprite, pageX + 1, pageY, pageOffsetX - 16, pageOffsetY);
|
drawSpriteToBuf(sprite, pageX + 1, pageY, pageOffsetX - 16, pageOffsetY);
|
||||||
|
@ -572,15 +573,14 @@ void drawSprite(unsigned int *sprite, int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void scroll(int x, int y) {
|
void scroll(int x, int y) {
|
||||||
unsigned int startX = screen.scrollX >> 4;
|
|
||||||
unsigned int startY = screen.scrollY >> 4;
|
|
||||||
x = min(max(x, 0), (screen.w << 4) - 320);
|
x = min(max(x, 0), (screen.w << 4) - 320);
|
||||||
y = min(max(y, 0), (screen.h << 4) - 176);
|
y = min(max(y, 0), (screen.h << 4) - 176);
|
||||||
screen.scrollX = x;
|
if ((screen.scrollX & 0xfff0) != (x & 0xfff0) ||
|
||||||
screen.scrollY = y;
|
(screen.scrollY & 0xfff0) != (y & 0xfff0)) {
|
||||||
if (startX != (x >> 4) || startY != (y >> 4)) {
|
|
||||||
memset(screen.dirty, D_BGTILE, 2 * PAGE_TILES_COUNT);
|
memset(screen.dirty, D_BGTILE, 2 * PAGE_TILES_COUNT);
|
||||||
}
|
}
|
||||||
|
screen.scrollX = x;
|
||||||
|
screen.scrollY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawScreen() {
|
void drawScreen() {
|
||||||
|
@ -695,7 +695,7 @@ int main() {
|
||||||
if (keyPressed(K_RIGHT)) x += 1;
|
if (keyPressed(K_RIGHT)) x += 1;
|
||||||
if (keyPressed(K_UP)) y -= 1;
|
if (keyPressed(K_UP)) y -= 1;
|
||||||
if (keyPressed(K_DOWN)) y += 1;
|
if (keyPressed(K_DOWN)) y += 1;
|
||||||
scroll(x + 152, y + 90);
|
scroll(x - 152, y - 90);
|
||||||
drawSprite(sprites[0], 50, 50);
|
drawSprite(sprites[0], 50, 50);
|
||||||
drawSprite(sprites[1], x, y);
|
drawSprite(sprites[1], x, y);
|
||||||
drawScreen();
|
drawScreen();
|
||||||
|
|
BIN
testbed.exe
BIN
testbed.exe
Binary file not shown.
Loading…
Reference in a new issue