From 14263f3a028beeca88c224dbca1b1cbd771ca44b Mon Sep 17 00:00:00 2001 From: neauoire Date: Tue, 1 Aug 2023 20:39:16 -0700 Subject: [PATCH] Updated screen device --- src/devices/screen.c | 49 +++++++++++++++++++++++++++----------------- src/devices/screen.h | 4 ++-- src/uxn11.c | 6 ++++++ 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/devices/screen.c b/src/devices/screen.c index c992100..40253c1 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -25,8 +25,12 @@ static Uint8 blending[4][16] = { {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}}; static void -screen_change(int x1, int y1, int x2, int y2) +screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2) { + if(x1 > uxn_screen.width && x2 > x1) return; + if(y1 > uxn_screen.height && y2 > y1) return; + if(x1 > x2) x1 = 0; + if(y1 > y2) y1 = 0; if(x1 < uxn_screen.x1) uxn_screen.x1 = x1; if(y1 < uxn_screen.y1) uxn_screen.y1 = y1; if(x2 > uxn_screen.x2) uxn_screen.x2 = x2; @@ -45,7 +49,7 @@ screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color) static void screen_blit(Uint8 *layer, Uint8 *ram, Uint16 addr, int x1, int y1, int color, int flipx, int flipy, int twobpp) { - int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5) || !color; + int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5); for(v = 0; v < 8; v++) { Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0); Uint16 y = y1 + (flipy ? 7 - v : v); @@ -79,21 +83,30 @@ void screen_resize(Uint16 width, Uint16 height) { Uint8 *bg, *fg; - Uint32 *pixels; + Uint32 *pixels = NULL; if(width < 0x8 || height < 0x8 || width >= 0x400 || height >= 0x400) return; - bg = realloc(uxn_screen.bg, width * height), - fg = realloc(uxn_screen.fg, width * height); - pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32) * SCALE * SCALE); - if(!bg || !fg || !pixels) + if(uxn_screen.width == width && uxn_screen.height == height) return; + 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); + return; + } + 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_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0); - screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0); + screen_fill(uxn_screen.bg, 0, 0, width, height, 0); + screen_fill(uxn_screen.fg, 0, 0, width, height, 0); + emu_resize(width, height); } void @@ -101,21 +114,19 @@ screen_redraw(void) { Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg; Uint32 palette[16], *pixels = uxn_screen.pixels; - int i, j, x, y, w = uxn_screen.width, h = uxn_screen.height; - int x1 = uxn_screen.x1 * SCALE; - int y1 = uxn_screen.y1 * SCALE; - int x2 = (uxn_screen.x2 > w ? w : uxn_screen.x2) * SCALE; - int y2 = (uxn_screen.y2 > h ? h : uxn_screen.y2) * SCALE; + int i, x, y, w = uxn_screen.width, h = uxn_screen.height; + int x1 = uxn_screen.x1; + int y1 = uxn_screen.y1; + int x2 = uxn_screen.x2 > w ? w : uxn_screen.x2; + int y2 = uxn_screen.y2 > h ? h : uxn_screen.y2; for(i = 0; i < 16; i++) palette[i] = uxn_screen.palette[(i >> 2) ? (i >> 2) : (i & 3)]; for(y = y1; y < y2; y++) for(x = x1; x < x2; x++) { - i = x / SCALE + y / SCALE * w; - j = x + y * w * SCALE; - pixels[j] = palette[fg[i] << 2 | bg[i]]; + i = x + y * w; + pixels[i] = palette[fg[i] << 2 | bg[i]]; } - uxn_screen.x1 = uxn_screen.y1 = 0xffff; - uxn_screen.x2 = uxn_screen.y2 = 0; + uxn_screen.x1 = uxn_screen.y1 = uxn_screen.x2 = uxn_screen.y2 = 0; } Uint8 diff --git a/src/devices/screen.h b/src/devices/screen.h index 70e97e5..6a417a3 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -17,10 +17,10 @@ typedef struct UxnScreen { } UxnScreen; extern UxnScreen uxn_screen; +extern int emu_resize(int width, int height); + void screen_palette(Uint8 *addr); void screen_resize(Uint16 width, Uint16 height); void screen_redraw(void); Uint8 screen_dei(Uxn *u, Uint8 addr); void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); - -#define SCALE 1 diff --git a/src/uxn11.c b/src/uxn11.c index f603fd8..2f62325 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -36,6 +36,7 @@ char *rom_path; #define WIDTH (64 * 8) #define HEIGHT (40 * 8) #define PAD 2 +#define SCALE 1 #define CONINBUFSIZE 256 Uint16 deo_mask[] = {0xff28, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000}; @@ -74,6 +75,11 @@ emu_deo(Uxn *u, Uint8 addr) } } +int +emu_resize(int width, int height) { + +} + static int emu_start(Uxn *u, char *rom) {