Faster screen drawing

This commit is contained in:
Devine Lu Linvega 2024-01-10 17:41:35 -08:00
parent e247b86471
commit 71c8d44051
3 changed files with 56 additions and 66 deletions

View File

@ -20,8 +20,7 @@ static int tids[8];
static Uint16 link_vectors[8]; static Uint16 link_vectors[8];
static Uint8 *link_ram; static Uint8 *link_ram;
static void static void *
*
link_eval(void *x) link_eval(void *x)
{ {
int tid = *((int *)x); int tid = *((int *)x);

View File

@ -217,6 +217,10 @@ screen_redraw(Uxn *u)
} }
} }
/* screen registers */
static Uint16 rX, rY, rA, rMX, rMY, rMA, rML, rDX, rDY;
Uint8 Uint8
screen_dei(Uxn *u, Uint8 addr) screen_dei(Uxn *u, Uint8 addr)
{ {
@ -225,6 +229,12 @@ screen_dei(Uxn *u, Uint8 addr)
case 0x23: return uxn_screen.width; case 0x23: return uxn_screen.width;
case 0x24: return uxn_screen.height >> 8; case 0x24: return uxn_screen.height >> 8;
case 0x25: return uxn_screen.height; case 0x25: return uxn_screen.height;
case 0x28: return rX >> 8;
case 0x29: return rX;
case 0x2a: return rY >> 8;
case 0x2b: return rY;
case 0x2c: return rA >> 8;
case 0x2d: return rA;
default: return u->dev[addr]; default: return u->dev[addr];
} }
} }
@ -232,83 +242,64 @@ 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_x, *port_y, *port_addr;
Uint16 x, y, dx, dy, dxy, dyx, addr, addr_incr;
switch(port) { switch(port) {
case 0x3: { case 0x3: screen_resize(PEEK2(d + 2), uxn_screen.height, uxn_screen.scale); return;
Uint8 *port_width = d + 0x2; case 0x5: screen_resize(uxn_screen.width, PEEK2(d + 4), uxn_screen.scale); return;
screen_resize(PEEK2(port_width), uxn_screen.height, uxn_screen.scale); case 0x6: rMX = d[0x6] & 0x1, rMY = d[0x6] & 0x2, rMA = d[0x6] & 0x4, rML = d[0x6] >> 4, rDX = rMX << 3, rDY = rMY << 2; return;
} break; case 0x8:
case 0x5: { case 0x9: rX = (d[0x8] << 8) | d[0x9]; return;
Uint8 *port_height = d + 0x4; case 0xa:
screen_resize(uxn_screen.width, PEEK2(port_height), uxn_screen.scale); case 0xb: rY = (d[0xa] << 8) | d[0xb]; return;
} break; case 0xc:
case 0xd: rA = (d[0xc] << 8) | d[0xd]; return;
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_y = d + 0xa;
x = PEEK2(port_x);
y = PEEK2(port_y);
/* fill mode */ /* fill mode */
if(ctrl & 0x80) { if(ctrl & 0x80) {
Uint16 x2 = uxn_screen.width, y2 = uxn_screen.height; Uint16 x1, y1, x2, y2;
if(ctrl & 0x10) x2 = x, x = 0; if(ctrl & 0x10)
if(ctrl & 0x20) y2 = y, y = 0; x1 = 0, x2 = rX;
if(!x && !y && x2 == uxn_screen.width && y2 == uxn_screen.height)
screen_fill(layer, color);
else else
screen_rect(layer, x, y, x2, y2, color); x1 = rX, x2 = uxn_screen.width;
screen_change(x, y, x2, y2); if(ctrl & 0x20)
y1 = 0, y2 = rY;
else
y1 = rY, y2 = uxn_screen.height;
screen_rect(layer, x1, y1, x2, y2, color);
screen_change(x1, y1, x2, y2);
} }
/* pixel mode */ /* pixel mode */
else { else {
Uint16 w = uxn_screen.width, h = uxn_screen.height; Uint16 w = uxn_screen.width;
if(x < w && y < h) if(rX < w && rY < uxn_screen.height)
layer[x + y * w] = color; layer[rX + rY * w] = color;
screen_change(x, y, x + 1, y + 1); screen_change(rX, rY, rX + 1, rY + 1);
if(d[0x6] & 0x1) POKE2(port_x, x + 1); if(rMX) rX++;
if(d[0x6] & 0x2) POKE2(port_y, y + 1); if(rMY) rY++;
} }
break; return;
} }
case 0xf: { case 0xf: {
Uint8 i; Uint8 i;
Uint8 ctrl = d[0xf]; Uint8 ctrl = d[0xf];
Uint8 move = d[0x6];
Uint8 length = move >> 4;
Uint8 twobpp = !!(ctrl & 0x80); Uint8 twobpp = !!(ctrl & 0x80);
Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg;
Uint8 color = ctrl & 0xf; Uint8 color = ctrl & 0xf;
int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1; Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg;
int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1; int fx = ctrl & 0x10 ? -1 : 1;
port_x = d + 0x8, port_y = d + 0xa; int fy = ctrl & 0x20 ? -1 : 1;
port_addr = d + 0xc; Uint16 dxy = rDX * fy, dyx = rDY * fx, addr_incr = rMA << (1 + twobpp);
x = PEEK2(port_x), dx = (move & 0x1) << 3, dxy = dx * fy; if(twobpp)
y = PEEK2(port_y), dy = (move & 0x2) << 2, dyx = dy * fx; for(i = 0; i <= rML; i++, rA += addr_incr)
addr = PEEK2(port_addr), addr_incr = (move & 0x4) << (1 + twobpp); screen_2bpp(layer, &ram[rA], rX + dyx * i, rY + dxy * i, color, fx, fy);
if(twobpp) { else
for(i = 0; i <= length; i++) { for(i = 0; i <= rML; i++, rA += addr_incr)
screen_2bpp(layer, &ram[addr], x + dyx * i, y + dxy * i, color, fx, fy); screen_1bpp(layer, &ram[rA], rX + dyx * i, rY + dxy * i, color, fx, fy);
addr += addr_incr; screen_change(rX, rY, rX + dyx * rML + 8, rY + dxy * rML + 8);
} if(rMX) rX += rDX * fx;
} else { if(rMY) rY += rDY * fy;
for(i = 0; i <= length; i++) { return;
screen_1bpp(layer, &ram[addr], x + dyx * i, y + dxy * i, color, fx, fy);
addr += addr_incr;
}
}
screen_change(x, y, x + dyx * length + 8, y + dxy * length + 8);
if(move & 0x1) {
x = x + dx * fx;
POKE2(port_x, x);
}
if(move & 0x2) {
y = y + dy * fy;
POKE2(port_y, y);
}
if(move & 0x4) POKE2(port_addr, addr); /* auto addr+length */
break;
} }
} }
} }