commit 94f314280c5490fe1149a50f34ca2e85423c073f
parent d6a966e1135f5c14a948cb681806151fa24b3fc7
Author: neauoire <aliceffekt@gmail.com>
Date: Sun, 12 Nov 2023 16:46:44 -0800
(Screen) Cache row during sprite drawing
Diffstat:
1 file changed, 35 insertions(+), 32 deletions(-)
diff --git a/src/devices/screen.c b/src/devices/screen.c
@@ -49,43 +49,50 @@ screen_fill(Uint8 *layer, int color)
void
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;
- for(y = y1; y < y2 && y < height; y++)
- for(x = x1; x < x2 && x < width; x++)
- layer[x + y * width] = color;
+ int x, y, w, h;
+ if(!x1 && !y1) {
+ screen_fill(layer, 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
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;
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
for(y = y1 + ymod; y != ymax; y += fy) {
- Uint16 c = *ch1++ | (*ch2++ << 8);
- for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
- Uint8 ch = (c & 1) | ((c >> 7) & 2);
- if((opaque || ch) && x < width && y < height)
- layer[x + y * width] = blending[ch][color];
- }
+ int row = y * w, c = *ch1++ | (*ch2++ << 8);
+ if(y < h)
+ for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
+ Uint8 ch = (c & 1) | ((c >> 7) & 2);
+ if((opaque || ch) && x < w)
+ layer[x + row] = blending[ch][color];
+ }
}
}
static void
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];
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
for(y = y1 + ymod; y != ymax; y += fy) {
- Uint16 c = *ch1++;
- for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
- Uint8 ch = c & 1;
- if((opaque || ch) && x < width && y < height)
- layer[x + y * width] = blending[ch][color];
- }
+ int row = y * w, c = *ch1++;
+ if(y < h)
+ for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
+ Uint8 ch = c & 1;
+ if((opaque || ch) && x < w)
+ layer[x + row] = blending[ch][color];
+ }
}
}
@@ -212,29 +219,27 @@ screen_dei(Uxn *u, Uint8 addr)
void
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;
switch(port) {
case 0x3: {
Uint8 *port_width = d + 0x2;
screen_resize(PEEK2(port_width), uxn_screen.height);
} break;
- case 0x5:
- port_height = d + 0x4;
+ case 0x5: {
+ Uint8 *port_height = d + 0x4;
screen_resize(uxn_screen.width, PEEK2(port_height));
- break;
+ } break;
case 0xe: {
Uint8 ctrl = d[0xe];
Uint8 color = ctrl & 0x3;
Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg;
- port_x = d + 0x8;
- port_y = d + 0xa;
+ port_x = d + 0x8, port_y = d + 0xa;
x = PEEK2(port_x);
y = PEEK2(port_y);
/* fill mode */
if(ctrl & 0x80) {
- Uint16 x2 = uxn_screen.width;
- Uint16 y2 = uxn_screen.height;
+ Uint16 x2 = uxn_screen.width, y2 = uxn_screen.height;
if(ctrl & 0x10) x2 = x, x = 0;
if(ctrl & 0x20) y2 = y, y = 0;
screen_rect(layer, x, y, x2, y2, color);
@@ -242,10 +247,9 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
}
/* pixel mode */
else {
- Uint16 width = uxn_screen.width;
- Uint16 height = uxn_screen.height;
- if(x < width && y < height)
- layer[x + y * width] = color;
+ Uint16 w = uxn_screen.width, h = uxn_screen.height;
+ if(x < w && y < h)
+ layer[x + y * w] = color;
screen_change(x, y, x + 1, y + 1);
if(d[0x6] & 0x1) POKE2(port_x, x + 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;
int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1;
int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1;
- port_x = d + 0x8;
- port_y = d + 0xa;
+ port_x = d + 0x8, port_y = d + 0xa;
port_addr = d + 0xc;
x = PEEK2(port_x), dx = (move & 0x1) << 3, dxy = dx * fy;
y = PEEK2(port_y), dy = (move & 0x2) << 2, dyx = dy * fx;