From 55178e8347db232329236d3db24806eb59568724 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 30 Apr 2023 11:32:11 -0700 Subject: [PATCH] Added ZOOM support --- src/devices/screen.c | 11 +++++++---- src/devices/screen.h | 2 ++ src/uxn11.c | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/devices/screen.c b/src/devices/screen.c index b2ad302..7dc3c15 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -75,7 +75,7 @@ screen_resize(UxnScreen *p, Uint16 width, Uint16 height) return; bg = realloc(p->bg.pixels, width * height), fg = realloc(p->fg.pixels, width * height); - pixels = realloc(p->pixels, width * height * sizeof(Uint32)); + pixels = realloc(p->pixels, width * height * sizeof(Uint32) * ZOOM * ZOOM); if(!bg || !fg || !pixels) return; p->bg.pixels = bg; @@ -90,12 +90,15 @@ screen_resize(UxnScreen *p, Uint16 width, Uint16 height) void screen_redraw(UxnScreen *p) { - Uint32 i, size = p->width * p->height, palette[16], *pixels = p->pixels; Uint8 *fg = p->fg.pixels, *bg = p->bg.pixels; + Uint32 i, j, x, y, w = p->width * ZOOM, h = p->height * ZOOM, palette[16], *pixels = p->pixels; for(i = 0; i < 16; i++) palette[i] = p->palette[(i >> 2) ? (i >> 2) : (i & 3)]; - for(i = 0; i < size; i++) - pixels[i] = palette[fg[i] << 2 | bg[i]]; + for(y = 0; y < h; y++) + for(x = 0; x < w; x++) { + j = ((x / ZOOM) + (y / ZOOM) * p->width); + pixels[x + y * w] = palette[fg[j] << 2 | bg[j]]; + } p->fg.changed = p->bg.changed = 0; } diff --git a/src/devices/screen.h b/src/devices/screen.h index b70fd6e..4fd7193 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -10,6 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +#define ZOOM 2 + typedef struct Layer { Uint8 *pixels, changed; } Layer; diff --git a/src/uxn11.c b/src/uxn11.c index f728071..4ee081b 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -72,7 +72,7 @@ static void emu_draw(void) { screen_redraw(&uxn_screen); - XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, uxn_screen.width, uxn_screen.height); + XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, PAD, PAD, uxn_screen.width * ZOOM, uxn_screen.height * ZOOM); } static int @@ -166,7 +166,7 @@ emu_event(Uxn *u) } break; case MotionNotify: { XMotionEvent *e = (XMotionEvent *)&ev; - mouse_pos(u, &u->dev[0x90], e->x - PAD, e->y - PAD); + mouse_pos(u, &u->dev[0x90], (e->x - PAD) / ZOOM, (e->y - PAD) / ZOOM); } break; } } @@ -177,7 +177,7 @@ display_start(char *title) Atom wmDelete; display = XOpenDisplay(NULL); visual = DefaultVisual(display, 0); - window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2, 1, 0, 0); + window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width * ZOOM + PAD * 2, uxn_screen.height * ZOOM + PAD * 2, 1, 0, 0); if(visual->class != TrueColor) return system_error("init", "True-color visual failed"); XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask); @@ -185,7 +185,7 @@ display_start(char *title) XSetWMProtocols(display, window, &wmDelete, 1); XStoreName(display, window, title); XMapWindow(display, window); - ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width, uxn_screen.height, 32, 0); + ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width * ZOOM, uxn_screen.height * ZOOM, 32, 0); hide_cursor(); return 1; }