mirror of https://git.sr.ht/~rabbits/uxn
(Screen) Cache row during sprite drawing
This commit is contained in:
parent
d6a966e113
commit
94f314280c
|
@ -49,43 +49,50 @@ screen_fill(Uint8 *layer, int color)
|
||||||
void
|
void
|
||||||
screen_rect(Uint8 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, int color)
|
screen_rect(Uint8 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, int color)
|
||||||
{
|
{
|
||||||
int x, y, width = uxn_screen.width, height = uxn_screen.height;
|
int x, y, w, h;
|
||||||
for(y = y1; y < y2 && y < height; y++)
|
if(!x1 && !y1) {
|
||||||
for(x = x1; x < x2 && x < width; x++)
|
screen_fill(layer, color);
|
||||||
layer[x + y * width] = color;
|
return;
|
||||||
|
}
|
||||||
|
w = uxn_screen.width, h = uxn_screen.height;
|
||||||
|
for(y = y1; y < y2 && y < h; y++)
|
||||||
|
for(x = x1; x < x2 && x < w; x++)
|
||||||
|
layer[x + y * w] = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
|
screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
|
||||||
{
|
{
|
||||||
int width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
|
int w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
|
||||||
Uint8 *ch1 = &ram[addr], *ch2 = ch1 + 8;
|
Uint8 *ch1 = &ram[addr], *ch2 = ch1 + 8;
|
||||||
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
|
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
|
||||||
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
|
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
|
||||||
for(y = y1 + ymod; y != ymax; y += fy) {
|
for(y = y1 + ymod; y != ymax; y += fy) {
|
||||||
Uint16 c = *ch1++ | (*ch2++ << 8);
|
int row = y * w, c = *ch1++ | (*ch2++ << 8);
|
||||||
for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
|
if(y < h)
|
||||||
Uint8 ch = (c & 1) | ((c >> 7) & 2);
|
for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
|
||||||
if((opaque || ch) && x < width && y < height)
|
Uint8 ch = (c & 1) | ((c >> 7) & 2);
|
||||||
layer[x + y * width] = blending[ch][color];
|
if((opaque || ch) && x < w)
|
||||||
}
|
layer[x + row] = blending[ch][color];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
|
screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
|
||||||
{
|
{
|
||||||
int width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
|
int w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
|
||||||
Uint8 *ch1 = &ram[addr];
|
Uint8 *ch1 = &ram[addr];
|
||||||
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
|
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
|
||||||
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
|
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
|
||||||
for(y = y1 + ymod; y != ymax; y += fy) {
|
for(y = y1 + ymod; y != ymax; y += fy) {
|
||||||
Uint16 c = *ch1++;
|
int row = y * w, c = *ch1++;
|
||||||
for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
|
if(y < h)
|
||||||
Uint8 ch = c & 1;
|
for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
|
||||||
if((opaque || ch) && x < width && y < height)
|
Uint8 ch = c & 1;
|
||||||
layer[x + y * width] = blending[ch][color];
|
if((opaque || ch) && x < w)
|
||||||
}
|
layer[x + row] = blending[ch][color];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,29 +219,27 @@ screen_dei(Uxn *u, Uint8 addr)
|
||||||
void
|
void
|
||||||
screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
||||||
{
|
{
|
||||||
Uint8 *port_height, *port_x, *port_y, *port_addr;
|
Uint8 *port_x, *port_y, *port_addr;
|
||||||
Uint16 x, y, dx, dy, dxy, dyx, addr, addr_incr;
|
Uint16 x, y, dx, dy, dxy, dyx, addr, addr_incr;
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x3: {
|
case 0x3: {
|
||||||
Uint8 *port_width = d + 0x2;
|
Uint8 *port_width = d + 0x2;
|
||||||
screen_resize(PEEK2(port_width), uxn_screen.height);
|
screen_resize(PEEK2(port_width), uxn_screen.height);
|
||||||
} break;
|
} break;
|
||||||
case 0x5:
|
case 0x5: {
|
||||||
port_height = d + 0x4;
|
Uint8 *port_height = d + 0x4;
|
||||||
screen_resize(uxn_screen.width, PEEK2(port_height));
|
screen_resize(uxn_screen.width, PEEK2(port_height));
|
||||||
break;
|
} break;
|
||||||
case 0xe: {
|
case 0xe: {
|
||||||
Uint8 ctrl = d[0xe];
|
Uint8 ctrl = d[0xe];
|
||||||
Uint8 color = ctrl & 0x3;
|
Uint8 color = ctrl & 0x3;
|
||||||
Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg;
|
Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg;
|
||||||
port_x = d + 0x8;
|
port_x = d + 0x8, port_y = d + 0xa;
|
||||||
port_y = d + 0xa;
|
|
||||||
x = PEEK2(port_x);
|
x = PEEK2(port_x);
|
||||||
y = PEEK2(port_y);
|
y = PEEK2(port_y);
|
||||||
/* fill mode */
|
/* fill mode */
|
||||||
if(ctrl & 0x80) {
|
if(ctrl & 0x80) {
|
||||||
Uint16 x2 = uxn_screen.width;
|
Uint16 x2 = uxn_screen.width, y2 = uxn_screen.height;
|
||||||
Uint16 y2 = uxn_screen.height;
|
|
||||||
if(ctrl & 0x10) x2 = x, x = 0;
|
if(ctrl & 0x10) x2 = x, x = 0;
|
||||||
if(ctrl & 0x20) y2 = y, y = 0;
|
if(ctrl & 0x20) y2 = y, y = 0;
|
||||||
screen_rect(layer, x, y, x2, y2, color);
|
screen_rect(layer, x, y, x2, y2, color);
|
||||||
|
@ -242,10 +247,9 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
||||||
}
|
}
|
||||||
/* pixel mode */
|
/* pixel mode */
|
||||||
else {
|
else {
|
||||||
Uint16 width = uxn_screen.width;
|
Uint16 w = uxn_screen.width, h = uxn_screen.height;
|
||||||
Uint16 height = uxn_screen.height;
|
if(x < w && y < h)
|
||||||
if(x < width && y < height)
|
layer[x + y * w] = color;
|
||||||
layer[x + y * width] = color;
|
|
||||||
screen_change(x, y, x + 1, y + 1);
|
screen_change(x, y, x + 1, y + 1);
|
||||||
if(d[0x6] & 0x1) POKE2(port_x, x + 1);
|
if(d[0x6] & 0x1) POKE2(port_x, x + 1);
|
||||||
if(d[0x6] & 0x2) POKE2(port_y, y + 1);
|
if(d[0x6] & 0x2) POKE2(port_y, y + 1);
|
||||||
|
@ -262,8 +266,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
|
||||||
Uint8 color = ctrl & 0xf;
|
Uint8 color = ctrl & 0xf;
|
||||||
int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1;
|
int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1;
|
||||||
int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1;
|
int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1;
|
||||||
port_x = d + 0x8;
|
port_x = d + 0x8, port_y = d + 0xa;
|
||||||
port_y = d + 0xa;
|
|
||||||
port_addr = d + 0xc;
|
port_addr = d + 0xc;
|
||||||
x = PEEK2(port_x), dx = (move & 0x1) << 3, dxy = dx * fy;
|
x = PEEK2(port_x), dx = (move & 0x1) << 3, dxy = dx * fy;
|
||||||
y = PEEK2(port_y), dy = (move & 0x2) << 2, dyx = dy * fx;
|
y = PEEK2(port_y), dy = (move & 0x2) << 2, dyx = dy * fx;
|
||||||
|
|
Loading…
Reference in New Issue