From 7377477f234d007f527c4ec37c23a91fed6b29f8 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 5 May 2023 17:21:46 -0700 Subject: [PATCH] Implemented scaling --- src/devices/screen.c | 17 +++++++++-------- src/devices/screen.h | 2 ++ src/uxn11.c | 1 - 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/devices/screen.c b/src/devices/screen.c index fafa24c..c992100 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -84,7 +84,7 @@ screen_resize(Uint16 width, Uint16 height) return; bg = realloc(uxn_screen.bg, width * height), fg = realloc(uxn_screen.fg, width * height); - pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32)); + pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32) * SCALE * SCALE); if(!bg || !fg || !pixels) return; uxn_screen.bg = bg; @@ -101,17 +101,18 @@ screen_redraw(void) { Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg; Uint32 palette[16], *pixels = uxn_screen.pixels; - 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; + 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; 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 + y * w; - pixels[i] = palette[fg[i] << 2 | bg[i]]; + i = x / SCALE + y / SCALE * w; + j = x + y * w * SCALE; + pixels[j] = palette[fg[i] << 2 | bg[i]]; } uxn_screen.x1 = uxn_screen.y1 = 0xffff; uxn_screen.x2 = uxn_screen.y2 = 0; diff --git a/src/devices/screen.h b/src/devices/screen.h index ab3d688..ead618a 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -22,3 +22,5 @@ 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 3 diff --git a/src/uxn11.c b/src/uxn11.c index dafacb7..638f469 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -33,7 +33,6 @@ static Window window; char *rom_path; -#define SCALE 1 #define WIDTH (64 * 8) #define HEIGHT (40 * 8) #define PAD 4