uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 0d055306a86b2645ce6131c1dd18b5066503e104
parent dd1f3e07256091a46f2d83b44da744d8b5152d50
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat, 11 Nov 2023 20:44:15 -0800

(screen) Added fill() function

Diffstat:
Msrc/devices/screen.c | 34++++++++++++++++++----------------
Msrc/devices/screen.h | 1+
Msrc/uxnemu.c | 6+++---
3 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/src/devices/screen.c b/src/devices/screen.c @@ -39,6 +39,14 @@ screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 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 screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color) { int x, y, width = uxn_screen.width, height = uxn_screen.height; @@ -137,24 +145,18 @@ screen_resize(Uint16 width, Uint16 height) return; if(uxn_screen.width == width && uxn_screen.height == height) return; - bg = malloc(width * height), - fg = malloc(width * height); + bg = malloc(width * height), fg = malloc(width * height); if(bg && fg) pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32)); if(!bg || !fg || !pixels) { - free(bg); - free(fg); + free(bg), free(fg); return; } - free(uxn_screen.bg); - free(uxn_screen.fg); - uxn_screen.bg = bg; - uxn_screen.fg = fg; + free(uxn_screen.bg), free(uxn_screen.fg); + uxn_screen.bg = bg, uxn_screen.fg = fg; uxn_screen.pixels = pixels; - uxn_screen.width = width; - uxn_screen.height = height; - screen_rect(uxn_screen.bg, 0, 0, width, height, 0); - screen_rect(uxn_screen.fg, 0, 0, width, height, 0); + uxn_screen.width = width, uxn_screen.height = height; + screen_fill(uxn_screen.bg, 0), screen_fill(uxn_screen.fg, 0); emu_resize(width, height); screen_change(0, 0, width, height); } @@ -194,13 +196,13 @@ screen_dei(Uxn *u, Uint8 addr) void 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; switch(port) { - case 0x3: - port_width = d + 0x2; + case 0x3: { + Uint8 *port_width = d + 0x2; screen_resize(PEEK2(port_width), uxn_screen.height); - break; + } break; case 0x5: port_height = d + 0x4; screen_resize(uxn_screen.width, PEEK2(port_height)); diff --git a/src/devices/screen.h b/src/devices/screen.h @@ -22,6 +22,7 @@ typedef struct UxnScreen { extern UxnScreen uxn_screen; 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_palette(Uint8 *addr); void screen_resize(Uint16 width, Uint16 height); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -178,7 +178,7 @@ static void set_debugger(Uxn *u, int 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); } @@ -253,8 +253,8 @@ static void emu_restart(Uxn *u, char *rom, int soft) { screen_resize(WIDTH, HEIGHT); - screen_rect(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0); - screen_rect(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0); + screen_fill(uxn_screen.bg, 0); + screen_fill(uxn_screen.fg, 0); system_reboot(u, rom, soft); SDL_SetWindowTitle(emu_window, boot_rom); }