uxn

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

commit ac6e4fed108e412c763ebd1212e8a19f3b7e86f8
parent c8707a8ccaf03eb32bd52aa72072c1e72a938a94
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Thu, 15 Sep 2022 09:11:20 -0700

Toggle monochromatic mode

Diffstat:
Msrc/devices/screen.c | 20++++++++++++++++++--
Msrc/devices/screen.h | 2++
Msrc/uxnemu.c | 4++++
3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/devices/screen.c b/src/devices/screen.c @@ -24,6 +24,9 @@ static Uint8 blending[5][16] = { {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}, {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; +static Uint32 palette_mono[] = { + 0x0f000000, 0x0fffffff}; + static void screen_write(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) { @@ -103,8 +106,14 @@ screen_redraw(UxnScreen *p, Uint32 *pixels) Uint32 i, size = p->width * p->height, palette[16]; 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[p->fg.pixels[i] << 2 | p->bg.pixels[i]]; + if(p->mono) { + for(i = 0; i < size; i++) + pixels[i] = palette_mono[(p->fg.pixels[i] << 2 | p->bg.pixels[i]) & 0x1]; + } else { + for(i = 0; i < size; i++) + pixels[i] = palette[p->fg.pixels[i] << 2 | p->bg.pixels[i]]; + } + p->fg.changed = p->bg.changed = 0; } @@ -114,6 +123,13 @@ clamp(int val, int min, int max) return (val >= min) ? (val <= max) ? val : max : min; } +void +screen_mono(UxnScreen *p, Uint32 *pixels) +{ + p->mono = !p->mono; + screen_redraw(p, pixels); +} + /* IO */ Uint8 diff --git a/src/devices/screen.h b/src/devices/screen.h @@ -20,6 +20,7 @@ typedef struct UxnScreen { Uint32 palette[4], *pixels; Uint16 width, height; Layer fg, bg; + Uint8 mono; } UxnScreen; extern UxnScreen uxn_screen; @@ -28,6 +29,7 @@ void screen_palette(UxnScreen *p, Uint8 *addr); void screen_resize(UxnScreen *p, Uint16 width, Uint16 height); void screen_clear(UxnScreen *p, Layer *layer); void screen_redraw(UxnScreen *p, Uint32 *pixels); +void screen_mono(UxnScreen *p, Uint32 *pixels); Uint8 screen_dei(Device *d, Uint8 port); void screen_deo(Device *d, Uint8 port); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -363,6 +363,10 @@ do_shortcut(Uxn *u, SDL_Event *event) capture_screen(); else if(event->key.keysym.sym == SDLK_F4) restart(u); + else if(event->key.keysym.sym == SDLK_F5) { + screen_mono(&uxn_screen, uxn_screen.pixels); + redraw(); + } } static int