0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-25 15:25:12 +00:00

(screen) Cache temp values

This commit is contained in:
Devine Lu Linvega 2024-01-03 08:30:36 -08:00
parent 1796eb938f
commit 6ba21f8470
2 changed files with 40 additions and 37 deletions

View file

@ -198,6 +198,10 @@ screen_redraw(Uxn *u)
pixels[i] = palette[fg[i] << 2 | bg[i]]; pixels[i] = palette[fg[i] << 2 | bg[i]];
} }
/* cache */
static Uint16 rX, rY, rA;
Uint8 Uint8
screen_dei(Uxn *u, Uint8 addr) screen_dei(Uxn *u, Uint8 addr)
{ {
@ -206,6 +210,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];
} }
} }
@ -213,42 +223,43 @@ 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 dx, dy, dxy, dyx, addr_incr;
Uint16 x, y, dx, dy, dxy, dyx, addr, addr_incr;
switch(port) { switch(port) {
case 0x3: screen_resize(PEEK2(d + 2), uxn_screen.height); break; case 0x3: screen_resize(PEEK2(d + 2), uxn_screen.height); break;
case 0x5: screen_resize(uxn_screen.width, PEEK2(d + 4)); break; case 0x5: screen_resize(uxn_screen.width, PEEK2(d + 4)); break;
case 0x8:
case 0x9: rX = (d[0x8] << 8) | d[0x9]; break;
case 0xa:
case 0xb: rY = (d[0xa] << 8) | d[0xb]; break;
case 0xc:
case 0xd: rA = (d[0xc] << 8) | d[0xd]; 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_y = d + 0xa;
/* fill mode */ /* fill mode */
if(ctrl & 0x80) { if(ctrl & 0x80) {
Uint16 x2, y2; Uint16 x1, y1, x2, y2;
if(ctrl & 0x10) if(ctrl & 0x10)
x = 0, x2 = PEEK2(port_x); x1 = 0, x2 = rX;
else else
x = PEEK2(port_x), x2 = uxn_screen.width; x1 = rX, x2 = uxn_screen.width;
if(ctrl & 0x20) if(ctrl & 0x20)
y = 0, y2 = PEEK2(port_y); y1 = 0, y2 = rY;
else else
y = PEEK2(port_y), y2 = uxn_screen.height; y1 = rY, y2 = uxn_screen.height;
screen_rect(layer, x, y, x2, y2, color); screen_rect(layer, x1, y1, x2, y2, color);
screen_change(x, y, x2, y2); screen_change(x1, y1, x2, y2);
} }
/* pixel mode */ /* pixel mode */
else { else {
Uint8 move = d[0x6]; Uint8 move = d[0x6];
Uint16 w = uxn_screen.width; Uint16 w = uxn_screen.width;
x = PEEK2(port_x); if(rX < w && rY < uxn_screen.height)
y = PEEK2(port_y); layer[rX + rY * w] = color;
if(x < w && y < uxn_screen.height) screen_change(rX, rY, rX + 1, rY + 1);
layer[x + y * w] = color; if(move & 0x1) rX++;
screen_change(x, y, x + 1, y + 1); if(move & 0x2) rY++;
if(move & 0x1) POKE2(port_x, x + 1);
if(move & 0x2) POKE2(port_y, y + 1);
} }
break; break;
} }
@ -260,35 +271,27 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
Uint8 twobpp = !!(ctrl & 0x80); Uint8 twobpp = !!(ctrl & 0x80);
Uint8 color = ctrl & 0xf; Uint8 color = ctrl & 0xf;
Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg; Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg;
Uint16 addr = rA;
int fx = ctrl & 0x10 ? -1 : 1; int fx = ctrl & 0x10 ? -1 : 1;
int fy = ctrl & 0x20 ? -1 : 1; int fy = ctrl & 0x20 ? -1 : 1;
port_x = d + 0x8; dx = (move & 0x1) << 3, dxy = dx * fy;
port_y = d + 0xa; dy = (move & 0x2) << 2, dyx = dy * fx;
port_addr = d + 0xc; addr_incr = (move & 0x4) << (1 + twobpp);
x = PEEK2(port_x), dx = (move & 0x1) << 3, dxy = dx * fy;
y = PEEK2(port_y), dy = (move & 0x2) << 2, dyx = dy * fx;
addr = PEEK2(port_addr), addr_incr = (move & 0x4) << (1 + twobpp);
if(twobpp) { if(twobpp) {
for(i = 0; i <= length; i++) { for(i = 0; i <= length; i++) {
screen_2bpp(layer, &ram[addr], x + dyx * i, y + dxy * i, color, fx, fy); screen_2bpp(layer, &ram[addr], rX + dyx * i, rY + dxy * i, color, fx, fy);
addr += addr_incr; addr += addr_incr;
} }
} else { } else {
for(i = 0; i <= length; i++) { for(i = 0; i <= length; i++) {
screen_1bpp(layer, &ram[addr], x + dyx * i, y + dxy * i, color, fx, fy); screen_1bpp(layer, &ram[addr], rX + dyx * i, rY + dxy * i, color, fx, fy);
addr += addr_incr; addr += addr_incr;
} }
} }
screen_change(x, y, x + dyx * length + 8, y + dxy * length + 8); screen_change(rX, rY, rX + dyx * length + 8, rY + dxy * length + 8);
if(move & 0x1) { if(move & 0x1) rX += dx * fx;
x += dx * fx; if(move & 0x2) rY += dy * fy;
POKE2(port_x, x); if(move & 0x4) rA = addr; /* auto addr+length */
}
if(move & 0x2) {
y += dy * fy;
POKE2(port_y, y);
}
if(move & 0x4) POKE2(port_addr, addr); /* auto addr+length */
break; break;
} }
} }

View file

@ -497,7 +497,7 @@ main(int argc, char **argv)
/* flags */ /* flags */
if(argc > 1 && argv[i][0] == '-') { if(argc > 1 && argv[i][0] == '-') {
if(!strcmp(argv[i], "-v")) if(!strcmp(argv[i], "-v"))
return system_error("Uxnemu - Varvara Emulator(GUI)", "2 Jan 2024."); return system_error("Uxnemu - Varvara Emulator(GUI)", "3 Jan 2024.");
else if(!strcmp(argv[i], "-2x")) else if(!strcmp(argv[i], "-2x"))
set_zoom(2, 0); set_zoom(2, 0);
else if(!strcmp(argv[i], "-3x")) else if(!strcmp(argv[i], "-3x"))