Brought changes for the screen device

This commit is contained in:
Devine Lu Linvega 2023-04-13 21:58:12 -07:00
parent f4f29dea0b
commit 04096fc172
1 changed files with 48 additions and 42 deletions

View File

@ -24,26 +24,13 @@ static Uint8 blending[4][16] = {
{1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1}, {1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1},
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}}; {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
static void
screen_pixel(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
{
if(x >= p->width || y >= p->height)
return;
layer->pixels[x + y * p->width] = color;
}
static void static void
screen_fill(UxnScreen *p, Layer *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color) screen_fill(UxnScreen *p, Layer *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color)
{ {
int x, y; int x, y;
if(x2 >= p->width) x2 = p->width; for(y = y1; y < y2 && y < p->height; y++)
if(y2 >= p->height) y2 = p->height; for(x = x1; x < x2 && x < p->width; x++)
if(x1 >= x2 || y1 >= y2)
return;
for(y = y1; y < y2; y++)
for(x = x1; x < x2; x++)
layer->pixels[x + y * p->width] = color; layer->pixels[x + y * p->width] = color;
layer->changed = 1;
} }
static void static void
@ -54,15 +41,14 @@ screen_blit(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8
Uint16 c = sprite[v] | (twobpp ? (sprite[v + 8] << 8) : 0); Uint16 c = sprite[v] | (twobpp ? (sprite[v + 8] << 8) : 0);
for(h = 7; h >= 0; --h, c >>= 1) { for(h = 7; h >= 0; --h, c >>= 1) {
Uint8 ch = (c & 1) | ((c >> 7) & 2); Uint8 ch = (c & 1) | ((c >> 7) & 2);
if(opaque || ch) if(opaque || ch) {
screen_pixel(p, Uint16 xx = x + (flipx ? 7 - h : h);
layer, Uint16 yy = y + (flipy ? 7 - v : v);
x + (flipx ? 7 - h : h), if(xx < p->width && yy < p->height)
y + (flipy ? 7 - v : v), layer->pixels[xx + yy * p->width] = blending[ch][color];
blending[ch][color]); }
} }
} }
layer->changed = 1;
} }
void void
@ -135,13 +121,26 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
screen_resize(&uxn_screen, uxn_screen.width, PEEK2(d + 4)); screen_resize(&uxn_screen, uxn_screen.width, PEEK2(d + 4));
break; break;
case 0xe: { case 0xe: {
Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa); Uint8 ctrl = d[0xe];
Layer *layer = (d[0xe] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; Uint8 color = ctrl & 0x3;
if(d[0xe] & 0x80) { Uint16 x = PEEK2(d + 0x8);
Uint8 xflip = d[0xe] & 0x10, yflip = d[0xe] & 0x20; Uint16 y = PEEK2(d + 0xa);
screen_fill(&uxn_screen, layer, xflip ? 0 : x, yflip ? 0 : y, xflip ? x : uxn_screen.width, yflip ? y : uxn_screen.height, d[0xe] & 0x3); Layer *layer = (ctrl & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
} else { /* fill mode */
screen_pixel(&uxn_screen, layer, x, y, d[0xe] & 0x3); if(ctrl & 0x80) {
Uint16 x2 = uxn_screen.width;
Uint16 y2 = uxn_screen.height;
if(ctrl & 0x10) x2 = x, x = 0;
if(ctrl & 0x20) y2 = y, y = 0;
screen_fill(&uxn_screen, layer, x, y, x2, y2, color);
layer->changed = 1;
}
/* pixel mode */
else {
Uint16 width = uxn_screen.width;
Uint16 height = uxn_screen.height;
if(x < width && y < height)
layer->pixels[x + y * width] = color;
layer->changed = 1; layer->changed = 1;
if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */ if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */
if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */ if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */
@ -149,25 +148,32 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
break; break;
} }
case 0xf: { case 0xf: {
Uint16 x = PEEK2(d + 0x8), y = PEEK2(d + 0xa), dx, dy, addr = PEEK2(d + 0xc); Uint8 i;
Uint8 i, n = d[0x6] >> 4, twobpp = !!(d[0xf] & 0x80); Uint8 ctrl = d[0xf];
Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; Uint8 move = d[0x6];
dx = (d[0x6] & 0x01) << 3; Uint8 length = move >> 4;
dy = (d[0x6] & 0x02) << 2; Uint8 twobpp = !!(ctrl & 0x80);
if(addr > 0x10000 - ((n + 1) << (3 + twobpp))) Uint16 x = PEEK2(d + 0x8);
Uint16 y = PEEK2(d + 0xa);
Uint16 addr = PEEK2(d + 0xc);
Uint16 dx = (move & 0x1) << 3;
Uint16 dy = (move & 0x2) << 2;
Layer *layer = (ctrl & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
if(addr > 0x10000 - ((length + 1) << (3 + twobpp)))
return; return;
for(i = 0; i <= n; i++) { for(i = 0; i <= length; i++) {
if(!(d[0xf] & 0xf)) { if(!(ctrl & 0xf)) {
Uint16 ex = x + dy * i, ey = y + dx * i; Uint16 ex = x + dy * i, ey = y + dx * i;
screen_fill(&uxn_screen, layer, ex, ey, ex + 8, ey + 8, 0); screen_fill(&uxn_screen, layer, ex, ey, ex + 8, ey + 8, 0);
} else { } else {
screen_blit(&uxn_screen, layer, x + dy * i, y + dx * i, &ram[addr], d[0xf] & 0xf, d[0xf] & 0x10, d[0xf] & 0x20, twobpp); screen_blit(&uxn_screen, layer, x + dy * i, y + dx * i, &ram[addr], ctrl & 0xf, ctrl & 0x10, ctrl & 0x20, twobpp);
addr += (d[0x6] & 0x04) << (1 + twobpp); addr += (move & 0x04) << (1 + twobpp);
} }
} }
if(d[0x6] & 0x1) POKE2(d + 0x8, x + dx); /* auto x+8 */ layer->changed = 1;
if(d[0x6] & 0x2) POKE2(d + 0xa, y + dy); /* auto y+8 */ if(move & 0x1) POKE2(d + 0x8, x + dx); /* auto x+8 */
if(d[0x6] & 0x4) POKE2(d + 0xc, addr); /* auto addr+length */ if(move & 0x2) POKE2(d + 0xa, y + dy); /* auto y+8 */
if(move & 0x4) POKE2(d + 0xc, addr); /* auto addr+length */
break; break;
} }
} }