0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-05 22:05:04 +00:00

(screen) Added fill() function

This commit is contained in:
neauoire 2023-11-11 20:44:15 -08:00
parent dd1f3e0725
commit 0d055306a8
3 changed files with 22 additions and 19 deletions

View file

@ -38,6 +38,14 @@ screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2)
if(y2 > uxn_screen.y2) uxn_screen.y2 = y2; if(y2 > uxn_screen.y2) uxn_screen.y2 = y2;
} }
void
screen_fill(Uint8 *layer, int color)
{
int i, length = uxn_screen.width * uxn_screen.height;
for(i = 0; i < length; i++)
layer[i] = color;
}
void void
screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color) screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color)
{ {
@ -137,24 +145,18 @@ screen_resize(Uint16 width, Uint16 height)
return; return;
if(uxn_screen.width == width && uxn_screen.height == height) if(uxn_screen.width == width && uxn_screen.height == height)
return; return;
bg = malloc(width * height), bg = malloc(width * height), fg = malloc(width * height);
fg = malloc(width * height);
if(bg && fg) if(bg && fg)
pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32)); pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32));
if(!bg || !fg || !pixels) { if(!bg || !fg || !pixels) {
free(bg); free(bg), free(fg);
free(fg);
return; return;
} }
free(uxn_screen.bg); free(uxn_screen.bg), free(uxn_screen.fg);
free(uxn_screen.fg); uxn_screen.bg = bg, uxn_screen.fg = fg;
uxn_screen.bg = bg;
uxn_screen.fg = fg;
uxn_screen.pixels = pixels; uxn_screen.pixels = pixels;
uxn_screen.width = width; uxn_screen.width = width, uxn_screen.height = height;
uxn_screen.height = height; screen_fill(uxn_screen.bg, 0), screen_fill(uxn_screen.fg, 0);
screen_rect(uxn_screen.bg, 0, 0, width, height, 0);
screen_rect(uxn_screen.fg, 0, 0, width, height, 0);
emu_resize(width, height); emu_resize(width, height);
screen_change(0, 0, width, height); screen_change(0, 0, width, height);
} }
@ -194,13 +196,13 @@ 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_width, *port_height, *port_x, *port_y, *port_addr; Uint8 *port_height, *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: {
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; port_height = d + 0x4;
screen_resize(uxn_screen.width, PEEK2(port_height)); screen_resize(uxn_screen.width, PEEK2(port_height));

View file

@ -22,6 +22,7 @@ typedef struct UxnScreen {
extern UxnScreen uxn_screen; extern UxnScreen uxn_screen;
extern int emu_resize(int width, int height); extern int emu_resize(int width, int height);
void screen_fill(Uint8 *layer, int color);
void screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color); void screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
void screen_palette(Uint8 *addr); void screen_palette(Uint8 *addr);
void screen_resize(Uint16 width, Uint16 height); void screen_resize(Uint16 width, Uint16 height);

View file

@ -178,7 +178,7 @@ static void
set_debugger(Uxn *u, int value) set_debugger(Uxn *u, int value)
{ {
u->dev[0x0e] = value; u->dev[0x0e] = value;
screen_rect(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0); screen_fill(uxn_screen.fg, 0);
screen_redraw(u); screen_redraw(u);
} }
@ -253,8 +253,8 @@ static void
emu_restart(Uxn *u, char *rom, int soft) emu_restart(Uxn *u, char *rom, int soft)
{ {
screen_resize(WIDTH, HEIGHT); screen_resize(WIDTH, HEIGHT);
screen_rect(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0); screen_fill(uxn_screen.bg, 0);
screen_rect(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0); screen_fill(uxn_screen.fg, 0);
system_reboot(u, rom, soft); system_reboot(u, rom, soft);
SDL_SetWindowTitle(emu_window, boot_rom); SDL_SetWindowTitle(emu_window, boot_rom);
} }