commit 646d79fff5f653271dbc87f7cd37a31424f71642
parent c77799dac2d10a89f5d85931c4b0aa21162c2603
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date: Wed, 5 Jan 2022 13:28:22 +0000
Factor out common parts of system_dei/deo.
Diffstat:
5 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/build.sh b/build.sh
@@ -14,6 +14,7 @@ then
echo "Formatting.."
clang-format -i src/uxn.h
clang-format -i src/uxn.c
+ clang-format -i src/devices/system.h
clang-format -i src/devices/system.c
clang-format -i src/devices/screen.h
clang-format -i src/devices/screen.c
diff --git a/src/devices/system.c b/src/devices/system.c
@@ -1,4 +1,5 @@
#include "../uxn.h"
+#include "system.h"
#include <stdio.h>
@@ -27,3 +28,25 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr)
fprintf(stderr, "Halted: %s#%04x, at 0x%04x\n", errors[error], u->ram[addr], addr);
return 0;
}
+
+/* IO */
+
+Uint8
+system_dei(Device *d, Uint8 port)
+{
+ switch(port) {
+ case 0x2: return d->u->wst.ptr;
+ case 0x3: return d->u->rst.ptr;
+ default: return d->dat[port];
+ }
+}
+
+void
+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;
+ default: system_deo_special(d, port);
+ }
+}
diff --git a/src/devices/system.h b/src/devices/system.h
@@ -0,0 +1,14 @@
+/*
+Copyright (c) 2022 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
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE.
+*/
+
+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
@@ -3,6 +3,7 @@
#include <unistd.h>
#include <time.h>
#include "uxn.h"
+#include "devices/system.h"
#include "devices/file.h"
/*
@@ -45,26 +46,12 @@ inspect(Stack *s, char *name)
#pragma mark - Devices
-static Uint8
-system_dei(Device *d, Uint8 port)
+void
+system_deo_special(Device *d, Uint8 port)
{
- switch(port) {
- case 0x2: return d->u->wst.ptr;
- case 0x3: return d->u->rst.ptr;
- default: return d->dat[port];
- }
-}
-
-static void
-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:
+ if(port == 0xe) {
inspect(&d->u->wst, "Working-stack");
inspect(&d->u->rst, "Return-stack");
- break;
}
}
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -8,6 +8,7 @@
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma clang diagnostic ignored "-Wtypedef-redefinition"
#include <SDL.h>
+#include "devices/system.h"
#include "devices/screen.h"
#include "devices/audio.h"
#include "devices/file.h"
@@ -169,23 +170,9 @@ init(void)
#pragma mark - Devices
-static Uint8
-system_dei(Device *d, Uint8 port)
-{
- switch(port) {
- case 0x2: return d->u->wst.ptr;
- case 0x3: return d->u->rst.ptr;
- default: return d->dat[port];
- }
-}
-
-static void
-system_deo(Device *d, Uint8 port)
+void
+system_deo_special(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;
- }
if(port > 0x7 && port < 0xe)
screen_palette(&uxn_screen, &d->dat[0x8]);
}