From 031f63a13c3e78c1c022b6eed4bac0ad909e9a9a Mon Sep 17 00:00:00 2001 From: neauoire Date: Thu, 13 Jan 2022 08:25:59 -0800 Subject: [PATCH] Print stack with DEO on 0x0f --- build.sh | 6 ++---- mkfile | 7 +++---- src/devices/system.c | 20 ++++++++++++++++++++ src/devices/system.h | 5 +++++ src/uxncli.c | 1 - src/uxnemu.c | 3 +-- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/build.sh b/build.sh index a1884d3..e61df47 100755 --- a/build.sh +++ b/build.sh @@ -60,8 +60,6 @@ then clang-format -i src/devices/controller.c clang-format -i src/devices/datetime.h clang-format -i src/devices/datetime.c - clang-format -i src/devices/debug.h - clang-format -i src/devices/debug.c clang-format -i src/uxnasm.c clang-format -i src/uxnemu.c clang-format -i src/uxncli.c @@ -100,8 +98,8 @@ fi echo "Building.." ${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm -${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/devices/debug.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu -${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/devices/debug.c src/uxncli.c -o bin/uxncli +${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/audio.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu +${CC} ${CFLAGS} ${CORE} src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli if [ -d "$HOME/bin" ] then diff --git a/mkfile b/mkfile index 8e269bd..bf42d9f 100644 --- a/mkfile +++ b/mkfile @@ -9,7 +9,6 @@ HFILES=\ src/devices/audio.h\ src/devices/controller.h\ src/devices/datetime.h\ - src/devices/debug.h\ src/devices/file.h\ src/devices/mouse.h\ src/devices/screen.h\ @@ -34,19 +33,19 @@ bin: %.rom:Q: %.tal bin/uxnasm bin/uxnasm $stem.tal $target >/dev/null -bin/uxncli: file.$O datetime.$O debug.$O system.$O uxncli.$O uxn.$O +bin/uxncli: file.$O datetime.$O system.$O uxncli.$O uxn.$O $LD $LDFLAGS -o $target $prereq bin/uxnasm: uxnasm.$O $LD $LDFLAGS -o $target $prereq -bin/uxnemu: audio.$O controller.$O datetime.$O debug.$O file.$O mouse.$O screen.$O system.$O uxn.$O uxnemu.$O +bin/uxnemu: audio.$O controller.$O datetime.$O file.$O mouse.$O screen.$O system.$O uxn.$O uxnemu.$O $LD $LDFLAGS -o $target $prereq (uxnasm|uxncli|uxnemu|uxn)\.$O:R: src/\1.c $CC $CFLAGS -Isrc -o $target src/$stem1.c -(audio|controller|datetime|debug|file|mouse|screen|system)\.$O:R: src/devices/\1.c +(audio|controller|datetime|file|mouse|screen|system)\.$O:R: src/devices/\1.c $CC $CFLAGS -Isrc -o $target src/devices/$stem1.c nuke:V: clean diff --git a/src/devices/system.c b/src/devices/system.c index 4d9bbec..c807ff1 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -22,6 +22,22 @@ static const char *errors[] = { "Working-stack division by zero", "Return-stack division by zero"}; +static void +inspect(Stack *s, char *name) +{ + Uint8 x, y; + fprintf(stderr, "\n%s\n", name); + for(y = 0; y < 0x04; y++) { + for(x = 0; x < 0x08; x++) { + Uint8 p = y * 0x08 + x; + fprintf(stderr, + p == s->ptr ? "[%02x]" : " %02x ", + s->dat[p]); + } + fprintf(stderr, "\n"); + } +} + int uxn_halt(Uxn *u, Uint8 error, Uint16 addr) { @@ -59,6 +75,10 @@ system_deo(Device *d, Uint8 port) switch(port) { case 0x2: d->u->wst.ptr = d->dat[port]; break; case 0x3: d->u->rst.ptr = d->dat[port]; break; + case 0xe: + inspect(&d->u->wst, "Working-stack"); + inspect(&d->u->rst, "Return-stack"); + break; default: system_deo_special(d, port); } } diff --git a/src/devices/system.h b/src/devices/system.h index 35f81a6..cca011e 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -9,6 +9,11 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ +typedef struct SystemDevice { + Device device; + struct UxnScreen *screen; +} SystemDevice; + Uint8 system_dei(Device *d, Uint8 port); void system_deo(Device *d, Uint8 port); void system_deo_special(Device *d, Uint8 port); diff --git a/src/uxncli.c b/src/uxncli.c index ffa3352..12a7f65 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -5,7 +5,6 @@ #include "devices/system.h" #include "devices/file.h" #include "devices/datetime.h" -#include "devices/debug.h" /* Copyright (c) 2021 Devine Lu Linvega diff --git a/src/uxnemu.c b/src/uxnemu.c index 5560d6b..2361167 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -15,7 +15,6 @@ #include "devices/controller.h" #include "devices/mouse.h" #include "devices/datetime.h" -#include "devices/debug.h" #pragma GCC diagnostic pop #pragma clang diagnostic pop @@ -280,7 +279,7 @@ start(Uxn *u, char *rom) /* unused */ uxn_port(u, 0xc, nil_dei, nil_deo); /* unused */ uxn_port(u, 0xd, nil_dei, nil_deo); /* unused */ uxn_port(u, 0xe, nil_dei, nil_deo); - /* unused */ uxn_port(u, 0xf, debug_dei, debug_deo); + /* unused */ uxn_port(u, 0xf, nil_dei, nil_deo); if(!uxn_eval(u, PAGE_PROGRAM)) return error("Boot", "Failed to start rom."); return 1;