commit 416f37c

Devine Lu Linvega  ·  2023-04-10 17:08:40 +0000 UTC
parent 5917f40
Removed GETVEC macro
9 files changed,  +65, -33
+2, -2
 1@@ -2,8 +2,8 @@
 2 
 3 RELEASE_FLAGS="-Os -DNDEBUG -g0 -s"
 4 DEBUG_FLAGS="-std=c89 -D_POSIX_C_SOURCE=199309L -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined"
 5-EMU_INC="src/uxn.c src/devices/system.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11"
 6-CLI_INC="src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli"
 7+EMU_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/screen.c src/devices/controller.c src/devices/mouse.c src/devices/file.c src/devices/datetime.c src/uxn11.c -o bin/uxn11 -lX11"
 8+CLI_INC="src/uxn.c src/devices/system.c src/devices/console.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli"
 9 
10 # find X11 libs on various systems
11 if [ -e /usr/X11R6 ]; then
+35, -0
 1@@ -0,0 +1,35 @@
 2+#include <stdio.h>
 3+#include <stdlib.h>
 4+
 5+#include "../uxn.h"
 6+#include "console.h"
 7+
 8+/*
 9+Copyright (c) 2022-2023 Devine Lu Linvega, Andrew Alderwick
10+
11+Permission to use, copy, modify, and distribute this software for any
12+purpose with or without fee is hereby granted, provided that the above
13+copyright notice and this permission notice appear in all copies.
14+
15+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16+WITH REGARD TO THIS SOFTWARE.
17+*/
18+
19+int
20+console_input(Uxn *u, char c)
21+{
22+	Uint8 *d = &u->dev[0x10];
23+	d[0x02] = c;
24+	return uxn_eval(u, PEEK2(d));
25+}
26+
27+void
28+console_deo(Uint8 *d, Uint8 port)
29+{
30+	FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr :
31+													0;
32+	if(fd) {
33+		fputc(d[port], fd);
34+		fflush(fd);
35+	}
36+}
+13, -0
 1@@ -0,0 +1,13 @@
 2+/*
 3+Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
 4+
 5+Permission to use, copy, modify, and distribute this software for any
 6+purpose with or without fee is hereby granted, provided that the above
 7+copyright notice and this permission notice appear in all copies.
 8+
 9+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+WITH REGARD TO THIS SOFTWARE.
11+*/
12+
13+int console_input(Uxn *u, char c);
14+void console_deo(Uint8 *d, Uint8 port);
+3, -3
 1@@ -17,7 +17,7 @@ controller_down(Uxn *u, Uint8 *d, Uint8 mask)
 2 {
 3 	if(mask) {
 4 		d[2] |= mask;
 5-		uxn_eval(u, GETVEC(d));
 6+		uxn_eval(u, PEEK2(d));
 7 	}
 8 }
 9 
10@@ -26,7 +26,7 @@ controller_up(Uxn *u, Uint8 *d, Uint8 mask)
11 {
12 	if(mask) {
13 		d[2] &= (~mask);
14-		uxn_eval(u, GETVEC(d));
15+		uxn_eval(u, PEEK2(d));
16 	}
17 }
18 
19@@ -35,7 +35,7 @@ controller_key(Uxn *u, Uint8 *d, Uint8 key)
20 {
21 	if(key) {
22 		d[3] = key;
23-		uxn_eval(u, GETVEC(d));
24+		uxn_eval(u, PEEK2(d));
25 		d[3] = 0x00;
26 	}
27 }
+4, -4
 1@@ -16,14 +16,14 @@ void
 2 mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
 3 {
 4 	d[6] |= mask;
 5-	uxn_eval(u, GETVEC(d));
 6+	uxn_eval(u, PEEK2(d));
 7 }
 8 
 9 void
10 mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
11 {
12 	d[6] &= (~mask);
13-	uxn_eval(u, GETVEC(d));
14+	uxn_eval(u, PEEK2(d));
15 }
16 
17 void
18@@ -31,7 +31,7 @@ mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
19 {
20 	POKDEV(0x2, x);
21 	POKDEV(0x4, y);
22-	uxn_eval(u, GETVEC(d));
23+	uxn_eval(u, PEEK2(d));
24 }
25 
26 void
27@@ -39,7 +39,7 @@ mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
28 {
29 	POKDEV(0xa, x);
30 	POKDEV(0xc, -y);
31-	uxn_eval(u, GETVEC(d));
32+	uxn_eval(u, PEEK2(d));
33 	POKDEV(0xa, 0);
34 	POKDEV(0xc, 0);
35 }
+1, -1
1@@ -89,7 +89,7 @@ int
2 uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
3 {
4 	Uint8 *d = &u->dev[0x00];
5-	Uint16 handler = GETVEC(d);
6+	Uint16 handler = PEEK2(d);
7 	if(handler) {
8 		u->wst->ptr = 4;
9 		u->wst->dat[0] = addr >> 0x8;
+3, -1
 1@@ -19,7 +19,9 @@ typedef unsigned int Uint32;
 2 
 3 /* clang-format off */
 4 
 5-#define GETVEC(d) ((d)[0] << 8 | (d)[1])
 6+#define POKE2(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
 7+#define PEEK2(d) ((d)[0] << 8 | (d)[1])
 8+
 9 #define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
10 #define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }
11 
+3, -21
 1@@ -9,6 +9,7 @@
 2 
 3 #include "uxn.h"
 4 #include "devices/system.h"
 5+#include "devices/console.h"
 6 #include "devices/screen.h"
 7 #include "devices/controller.h"
 8 #include "devices/mouse.h"
 9@@ -46,25 +47,6 @@ emu_error(char *msg, const char *err)
10 	return 0;
11 }
12 
13-static int
14-console_input(Uxn *u, char c)
15-{
16-	Uint8 *d = &u->dev[0x10];
17-	d[0x02] = c;
18-	return uxn_eval(u, GETVEC(d));
19-}
20-
21-static void
22-console_deo(Uint8 *d, Uint8 port)
23-{
24-	FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr :
25-													0;
26-	if(fd) {
27-		fputc(d[port], fd);
28-		fflush(fd);
29-	}
30-}
31-
32 static Uint8
33 emu_dei(Uxn *u, Uint8 addr)
34 {
35@@ -260,8 +242,8 @@ main(int argc, char **argv)
36 		while(XPending(display))
37 			emu_event(&u);
38 		if(poll(&fds[1], 1, 0)) {
39-			read(fds[1].fd, expirations, 8);    /* Indicate we handled the timer */
40-			uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
41+			read(fds[1].fd, expirations, 8);   /* Indicate we handled the timer */
42+			uxn_eval(&u, PEEK2(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
43 		}
44 		if((fds[2].revents & POLLIN) != 0) {
45 			n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);
+1, -1
1@@ -31,7 +31,7 @@ console_input(Uxn *u, char c)
2 {
3 	Uint8 *d = &u->dev[0x10];
4 	d[0x02] = c;
5-	return uxn_eval(u, GETVEC(d));
6+	return uxn_eval(u, PEEK2(d));
7 }
8 
9 static void