uxn

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

commit 5e3a93ba2680807f0abebde80ab23818e40d8a97
parent e17c610d735f45e7397d750ec82f791d0fdb496b
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Thu, 23 Jan 2025 09:31:44 -0800

Improved stack debugger printout

Diffstat:
Msrc/devices/controller.c | 16+++++++++++++---
Msrc/devices/controller.h | 2++
Msrc/devices/mouse.c | 19+++++++++++++++----
Msrc/devices/mouse.h | 2++
Msrc/devices/screen.c | 21++++++++++++---------
Msrc/devices/screen.h | 2+-
Msrc/devices/system.c | 11+++++------
Msrc/uxncli.c | 9++++++---
Msrc/uxnemu.c | 2++
9 files changed, 58 insertions(+), 26 deletions(-)

diff --git a/src/devices/controller.c b/src/devices/controller.c @@ -12,12 +12,14 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +static int controller_vector; + void controller_down(Uint8 mask) { if(mask) { uxn.dev[0x82] |= mask; - uxn_eval(PEEK2(&uxn.dev[0x80])); + uxn_eval(controller_vector); } } @@ -26,7 +28,7 @@ controller_up(Uint8 mask) { if(mask) { uxn.dev[0x82] &= (~mask); - uxn_eval(PEEK2(&uxn.dev[0x80])); + uxn_eval(controller_vector); } } @@ -35,7 +37,15 @@ controller_key(Uint8 key) { if(key) { uxn.dev[0x83] = key; - uxn_eval(PEEK2(&uxn.dev[0x80])); + uxn_eval(controller_vector); uxn.dev[0x83] = 0; } } + +void +controller_deo(Uint8 addr) +{ + switch(addr) { + case 0x81: controller_vector = PEEK2(&uxn.dev[0x80]); break; + } +} diff --git a/src/devices/controller.h b/src/devices/controller.h @@ -12,3 +12,5 @@ WITH REGARD TO THIS SOFTWARE. void controller_down(Uint8 mask); void controller_up(Uint8 mask); void controller_key(Uint8 key); + +void controller_deo(Uint8 addr); diff --git a/src/devices/mouse.c b/src/devices/mouse.c @@ -1,5 +1,6 @@ #include "../uxn.h" #include "mouse.h" +#include <stdio.h> /* Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick @@ -12,18 +13,20 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +static int mouse_vector; + void mouse_down(Uint8 mask) { uxn.dev[0x96] |= mask; - uxn_eval(PEEK2(&uxn.dev[0x90])); + uxn_eval(mouse_vector); } void mouse_up(Uint8 mask) { uxn.dev[0x96] &= (~mask); - uxn_eval(PEEK2(&uxn.dev[0x90])); + uxn_eval(mouse_vector); } void @@ -31,7 +34,7 @@ mouse_pos(Uint16 x, Uint16 y) { uxn.dev[0x92] = x >> 8, uxn.dev[0x93] = x; uxn.dev[0x94] = y >> 8, uxn.dev[0x95] = y; - uxn_eval(PEEK2(&uxn.dev[0x90])); + uxn_eval(mouse_vector); } void @@ -39,7 +42,15 @@ mouse_scroll(Uint16 x, Uint16 y) { uxn.dev[0x9a] = x >> 8, uxn.dev[0x9b] = x; uxn.dev[0x9c] = -y >> 8, uxn.dev[0x9d] = -y; - uxn_eval(PEEK2(&uxn.dev[0x90])); + uxn_eval(mouse_vector); uxn.dev[0x9a] = 0, uxn.dev[0x9b] = 0; uxn.dev[0x9c] = 0, uxn.dev[0x9d] = 0; } + +void +mouse_deo(Uint8 addr) +{ + switch(addr) { + case 0x91: mouse_vector = PEEK2(&uxn.dev[0x90]); break; + } +} diff --git a/src/devices/mouse.h b/src/devices/mouse.h @@ -13,3 +13,5 @@ void mouse_down(Uint8 mask); void mouse_up(Uint8 mask); void mouse_pos(Uint16 x, Uint16 y); void mouse_scroll(Uint16 x, Uint16 y); + +void mouse_deo(Uint8 addr); diff --git a/src/devices/screen.c b/src/devices/screen.c @@ -180,46 +180,49 @@ screen_deo(Uint8 addr) } case 0x2f: { int ctrl = uxn.dev[0x2f]; - int twobpp = !!(ctrl & 0x80); int blend = ctrl & 0xf, opaque = blend % 5; int fx = ctrl & 0x10 ? -1 : 1, fy = ctrl & 0x20 ? -1 : 1; - int i, x1, x2, y1, y2, ax, ay, qx, qy, x = rX, y = rY; - int dxy = rDX * fy, dyx = rDY * fx, addr_incr = rMA << (1 + twobpp); + int qfx = fx > 0 ? 7 : 0, qfy = fy < 0 ? 7 : 0; + int dxy = fy * rDX, dyx = fx * rDY; int wmar = MAR(uxn_screen.width), wmar2 = MAR2(uxn_screen.width); int hmar2 = MAR2(uxn_screen.height); + int i, x1, x2, y1, y2, ax, ay, qx, qy, x = rX, y = rY; Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg; - if(twobpp) + if(ctrl & 0x80) { + int addr_incr = rMA << 2; for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr) { Uint16 xmar = MAR(x), ymar = MAR(y); Uint16 xmar2 = MAR2(x), ymar2 = MAR2(y); if(xmar < wmar && ymar2 < hmar2) { Uint8 *sprite = &uxn.ram[rA]; int by = ymar2 * wmar2; - for(ay = ymar * wmar2, qy = fy < 0 ? 7 : 0; ay < by; ay += wmar2, qy += fy) { + for(ay = ymar * wmar2, qy = qfy; ay < by; ay += wmar2, qy += fy) { int ch1 = sprite[qy], ch2 = sprite[qy + 8] << 1, bx = xmar2 + ay; - for(ax = xmar + ay, qx = fx > 0 ? 7 : 0; ax < bx; ax++, qx -= fx) { + for(ax = xmar + ay, qx = qfx; ax < bx; ax++, qx -= fx) { int color = ((ch1 >> qx) & 1) | ((ch2 >> qx) & 2); if(opaque || color) layer[ax] = blending[color][blend]; } } } } - else + } else { + int addr_incr = rMA << 1; for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr) { Uint16 xmar = MAR(x), ymar = MAR(y); Uint16 xmar2 = MAR2(x), ymar2 = MAR2(y); if(xmar < wmar && ymar2 < hmar2) { Uint8 *sprite = &uxn.ram[rA]; int by = ymar2 * wmar2; - for(ay = ymar * wmar2, qy = fy < 0 ? 7 : 0; ay < by; ay += wmar2, qy += fy) { + for(ay = ymar * wmar2, qy = qfy; ay < by; ay += wmar2, qy += fy) { int ch1 = sprite[qy], bx = xmar2 + ay; - for(ax = xmar + ay, qx = fx > 0 ? 7 : 0; ax < bx; ax++, qx -= fx) { + for(ax = xmar + ay, qx = qfx; ax < bx; ax++, qx -= fx) { int color = (ch1 >> qx) & 1; if(opaque || color) layer[ax] = blending[color][blend]; } } } } + } if(fx < 0) x1 = x, x2 = rX; else diff --git a/src/devices/screen.h b/src/devices/screen.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick +Copyright (c) 2021-2025 Devine Lu Linvega, Andrew Alderwick Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/devices/system.c b/src/devices/system.c @@ -1,8 +1,6 @@ #include <stdio.h> -#include <stdlib.h> #include "../uxn.h" - #include "system.h" /* @@ -19,12 +17,13 @@ WITH REGARD TO THIS SOFTWARE. char *boot_path; static void -system_print(Stack *s) +system_print(char *name, Stack *s) { Uint8 i; + fprintf(stderr, "%s ", name); for(i = s->ptr - 8; i != (Uint8)(s->ptr); i++) fprintf(stderr, "%02x%c", s->dat[i], i == 0xff ? '|' : ' '); - fprintf(stderr, "< \n"); + fprintf(stderr, "<%02x\n", s->ptr); } static int @@ -116,8 +115,8 @@ system_deo(Uint8 port) uxn.rst.ptr = uxn.dev[5]; break; case 0xe: - fprintf(stderr, "WST "), system_print(&uxn.wst); - fprintf(stderr, "RST "), system_print(&uxn.rst); + system_print("WST", &uxn.wst); + system_print("RST", &uxn.rst); break; } } diff --git a/src/uxncli.c b/src/uxncli.c @@ -19,6 +19,7 @@ WITH REGARD TO THIS SOFTWARE. */ Uxn uxn; +int console_vector; Uint8 emu_dei(Uint8 addr) @@ -47,12 +48,14 @@ main(int argc, char **argv) { int i = 1; if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v') - return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 21 Jan 2025.\n"); + return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 23 Jan 2025.\n"); else if(argc == 1) return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]); else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2)) return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]); - console_arguments(i, argc, argv); - while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1)); + if(console_vector) { + console_arguments(i, argc, argv); + while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1)); + } return uxn.dev[0x0f] & 0x7f; } diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -103,6 +103,8 @@ emu_deo(Uint8 addr, Uint8 value) case 0x40: audio_deo(1, &uxn.dev[d], p); break; case 0x50: audio_deo(2, &uxn.dev[d], p); break; case 0x60: audio_deo(3, &uxn.dev[d], p); break; + case 0x80: controller_deo(addr); break; + case 0x90: mouse_deo(addr); break; case 0xa0: file_deo(addr); break; case 0xb0: file_deo(addr); break; }