From 8c212fed3e5398fb38b580160ea530015f0a2eab Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 2 Jan 2024 11:29:02 -0800 Subject: [PATCH] Housekeeping --- src/devices/audio.h | 2 -- src/devices/console.h | 2 -- src/devices/controller.h | 2 -- src/devices/datetime.c | 6 ++---- src/devices/datetime.h | 2 -- src/devices/file.h | 2 -- src/devices/mouse.c | 17 +++++------------ src/devices/mouse.h | 2 -- src/devices/screen.c | 40 ++++++++++++++++++---------------------- src/devices/screen.h | 2 -- src/devices/system.h | 2 -- src/uxncli.c | 2 +- src/uxnemu.c | 2 +- 13 files changed, 27 insertions(+), 56 deletions(-) diff --git a/src/devices/audio.h b/src/devices/audio.h index 57886b8..0f7c2ad 100644 --- a/src/devices/audio.h +++ b/src/devices/audio.h @@ -12,8 +12,6 @@ WITH REGARD TO THIS SOFTWARE. typedef signed int Sint32; #define AUDIO_VERSION 1 -#define AUDIO_DEIMASK 0x0014 -#define AUDIO_DEOMASK 0x8000 #define AUDIO_BUFSIZE 256.0f #define SAMPLE_FREQUENCY 44100.0f diff --git a/src/devices/console.h b/src/devices/console.h index eaa64f5..7c83708 100644 --- a/src/devices/console.h +++ b/src/devices/console.h @@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE. */ #define CONSOLE_VERSION 1 -#define CONSOLE_DEIMASK 0x0000 -#define CONSOLE_DEOMASK 0x0300 #define CONSOLE_STD 0x1 #define CONSOLE_ARG 0x2 diff --git a/src/devices/controller.h b/src/devices/controller.h index bbc68e1..d4d835e 100644 --- a/src/devices/controller.h +++ b/src/devices/controller.h @@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE. */ #define CONTROL_VERSION 1 -#define CONTROL_DEIMASK 0x0000 -#define CONTROL_DEOMASK 0x0000 void controller_down(Uxn *u, Uint8 *d, Uint8 mask); void controller_up(Uxn *u, Uint8 *d, Uint8 mask); diff --git a/src/devices/datetime.c b/src/devices/datetime.c index 685f8e3..1968467 100644 --- a/src/devices/datetime.c +++ b/src/devices/datetime.c @@ -18,10 +18,8 @@ Uint8 datetime_dei(Uxn *u, Uint8 addr) { time_t seconds = time(NULL); - struct tm zt = {0}; - struct tm *t = localtime(&seconds); - if(t == NULL) - t = &zt; + struct tm zt = {0}, *t = localtime(&seconds); + if(t == NULL) t = &zt; switch(addr) { case 0xc0: return (t->tm_year + 1900) >> 8; case 0xc1: return (t->tm_year + 1900); diff --git a/src/devices/datetime.h b/src/devices/datetime.h index f74c0a0..4ae7a6c 100644 --- a/src/devices/datetime.h +++ b/src/devices/datetime.h @@ -10,7 +10,5 @@ WITH REGARD TO THIS SOFTWARE. */ #define DATETIME_VERSION 1 -#define DATETIME_DEIMASK 0x07ff -#define DATETIME_DEOMASK 0x0000 Uint8 datetime_dei(Uxn *u, Uint8 addr); diff --git a/src/devices/file.h b/src/devices/file.h index b29b482..5b06409 100644 --- a/src/devices/file.h +++ b/src/devices/file.h @@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE. */ #define FILE_VERSION 1 -#define FILE_DEIMASK 0x0000 -#define FILE_DEOMASK 0xa260 #define POLYFILEY 2 #define DEV_FILE0 0xa diff --git a/src/devices/mouse.c b/src/devices/mouse.c index 4b6df1a..ccb8aab 100644 --- a/src/devices/mouse.c +++ b/src/devices/mouse.c @@ -29,23 +29,16 @@ mouse_up(Uxn *u, Uint8 *d, Uint8 mask) void mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y) { - *(d + 2) = x >> 8; - *(d + 3) = x; - *(d + 4) = y >> 8; - *(d + 5) = y; + *(d + 2) = x >> 8, *(d + 3) = x; + *(d + 4) = y >> 8, *(d + 5) = y; uxn_eval(u, PEEK2(d)); } void mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y) { - *(d + 0xa) = x >> 8; - *(d + 0xb) = x; - *(d + 0xc) = -y >> 8; - *(d + 0xd) = -y; + *(d + 0xa) = x >> 8, *(d + 0xb) = x; + *(d + 0xc) = -y >> 8, *(d + 0xd) = -y; uxn_eval(u, PEEK2(d)); - *(d + 0xa) = 0; - *(d + 0xb) = 0; - *(d + 0xc) = 0; - *(d + 0xd) = 0; + *(d + 0xa) = *(d + 0xb) = *(d + 0xc) = *(d + 0xd) = 0; } diff --git a/src/devices/mouse.h b/src/devices/mouse.h index e848e7b..3af21f0 100644 --- a/src/devices/mouse.h +++ b/src/devices/mouse.h @@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE. */ #define MOUSE_VERSION 1 -#define MOUSE_DEIMASK 0x0000 -#define MOUSE_DEOMASK 0x0000 void mouse_down(Uxn *u, Uint8 *d, Uint8 mask); void mouse_up(Uxn *u, Uint8 *d, Uint8 mask); diff --git a/src/devices/screen.c b/src/devices/screen.c index 733eae5..e388634 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -216,36 +216,32 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) Uint8 *port_x, *port_y, *port_addr; Uint16 x, y, dx, dy, dxy, dyx, addr, addr_incr; switch(port) { - case 0x3: { - Uint8 *port_width = d + 0x2; - screen_resize(PEEK2(port_width), uxn_screen.height); - } break; - case 0x5: { - Uint8 *port_height = d + 0x4; - screen_resize(uxn_screen.width, PEEK2(port_height)); - } break; + case 0x3: screen_resize(PEEK2(d + 2), uxn_screen.height); break; + case 0x5: screen_resize(uxn_screen.width, PEEK2(d + 4)); break; case 0xe: { Uint8 ctrl = d[0xe]; Uint8 color = ctrl & 0x3; - Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg; + Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg; port_x = d + 0x8, port_y = d + 0xa; - x = PEEK2(port_x); - y = PEEK2(port_y); + Uint16 x = PEEK2(port_x), y = PEEK2(port_y); /* fill mode */ if(ctrl & 0x80) { - Uint16 x2 = uxn_screen.width, y2 = uxn_screen.height; - if(ctrl & 0x10) x2 = x, x = 0; - if(ctrl & 0x20) y2 = y, y = 0; - if(!x && !y && x2 == uxn_screen.width && y2 == uxn_screen.height) - screen_fill(layer, color); + Uint16 x2, y2; + if(ctrl & 0x10) + x2 = x, x = 0; else - screen_rect(layer, x, y, x2, y2, color); + x2 = uxn_screen.width; + if(ctrl & 0x20) + y2 = y, y = 0; + else + y2 = uxn_screen.height; + screen_rect(layer, x, y, x2, y2, color); screen_change(x, y, x2, y2); } /* pixel mode */ else { - Uint16 w = uxn_screen.width, h = uxn_screen.height; - if(x < w && y < h) + Uint16 w = uxn_screen.width; + if(x < w && y < uxn_screen.height) layer[x + y * w] = color; screen_change(x, y, x + 1, y + 1); if(d[0x6] & 0x1) POKE2(port_x, x + 1); @@ -259,8 +255,8 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) Uint8 move = d[0x6]; Uint8 length = move >> 4; Uint8 twobpp = !!(ctrl & 0x80); - Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg; Uint8 color = ctrl & 0xf; + Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg; int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1; int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1; port_x = d + 0x8, port_y = d + 0xa; @@ -281,11 +277,11 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) } screen_change(x, y, x + dyx * length + 8, y + dxy * length + 8); if(move & 0x1) { - x = x + dx * fx; + x += dx * fx; POKE2(port_x, x); } if(move & 0x2) { - y = y + dy * fy; + y += dy * fy; POKE2(port_y, y); } if(move & 0x4) POKE2(port_addr, addr); /* auto addr+length */ diff --git a/src/devices/screen.h b/src/devices/screen.h index 0262804..8fd449f 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE. */ #define SCREEN_VERSION 1 -#define SCREEN_DEIMASK 0x003c -#define SCREEN_DEOMASK 0xc028 typedef struct UxnScreen { int width, height, x1, y1, x2, y2; diff --git a/src/devices/system.h b/src/devices/system.h index 227e8b7..cae4111 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE. */ #define SYSTEM_VERSION 2 -#define SYSTEM_DEIMASK 0x0030 -#define SYSTEM_DEOMASK 0xff38 #define RAM_PAGES 0x10 diff --git a/src/uxncli.c b/src/uxncli.c index 68b6774..b78f623 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -72,7 +72,7 @@ main(int argc, char **argv) return system_error("usage", "uxncli [-v] file.rom [args..]"); /* Read flags */ if(argv[i][0] == '-' && argv[i][1] == 'v') - return system_version("Uxncli - Console Varvara Emulator", "11 Nov 2023"); + return system_version("Uxncli - Console Varvara Emulator", "2 Jan 2024"); if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) return system_error("Init", "Failed to initialize uxn."); /* Game Loop */ diff --git a/src/uxnemu.c b/src/uxnemu.c index 558b663..4549773 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -105,7 +105,7 @@ emu_deo(Uxn *u, Uint8 addr, Uint8 value) if(p > 0x7 && p < 0xe) screen_palette(&u->dev[0x8]); break; case 0x10: console_deo(&u->dev[d], p); break; - case 0x20: screen_deo(u->ram, &u->dev[d], p); break; + case 0x20: screen_deo(u->ram, &u->dev[0x20], p); break; case 0x30: audio_deo(0, &u->dev[d], p, u); break; case 0x40: audio_deo(1, &u->dev[d], p, u); break; case 0x50: audio_deo(2, &u->dev[d], p, u); break;