commit defceb7

neauoire  ·  2022-03-30 17:37:47 +0000 UTC
parent 461bb5a
Stacks are mapped in ram
8 files changed,  +40, -29
+16, -0
 1@@ -2,6 +2,22 @@
 2 
 3 An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C. 
 4 
 5+## Uxn11/System
 6+
 7+This emulator's system device supports changing a stack's location to a page of memory. The default memory mapping is as follows:
 8+
 9+- `0000-ffff`, as **RAM**.
10+- `10000-100ff`, as **working stack**.
11+- `10100-101ff`, as **return stack**.
12+
13+To use the last page of ram(`0xff00`) to host the working stack:
14+
15+```
16+#ff .System/wst DEO
17+```
18+
19+The stack mapping is 254 bytes of data, a byte for the pointer and a byte for an error code.
20+
21 ## Graphical
22 
23 All you need is X11.
+10, -5
 1@@ -8,11 +8,16 @@ rm -f ./bin/*
 2 echo "Building.."
 3 mkdir -p bin
 4 
 5-# Build(debug)
 6-gcc -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 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
 7-
 8-# Build(release)
 9-# gcc 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 -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxn11 -lX11
10+if [ "${1}" = '--install' ]; 
11+then
12+	echo "Installing.."
13+	gcc 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 -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxn11 -lX11
14+	gcc src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -D_POSIX_C_SOURCE=199309L -DNDEBUG -Os -g0 -s -o bin/uxncli
15+	cp bin/uxn11 ~/bin
16+else
17+	gcc -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 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
18+	gcc -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 src/uxn.c src/devices/system.c src/devices/file.c src/devices/datetime.c src/uxncli.c -o bin/uxncli
19+fi
20 
21 echo "Running.."
22 bin/uxn11 ~/roms/left.rom # etc/mouse.rom
+4, -14
 1@@ -37,8 +37,8 @@ system_print(Stack *s, char *name)
 2 void
 3 system_inspect(Uxn *u)
 4 {
 5-	system_print(&u->wst, "wst");
 6-	system_print(&u->rst, "rst");
 7+	system_print(u->wst, "wst");
 8+	system_print(u->rst, "rst");
 9 }
10 
11 int
12@@ -51,22 +51,12 @@ uxn_halt(Uxn *u, Uint8 error, Uint16 addr)
13 
14 /* IO */
15 
16-Uint8
17-system_dei(Device *d, Uint8 port)
18-{
19-	switch(port) {
20-	case 0x2: return d->u->wst.ptr;
21-	case 0x3: return d->u->rst.ptr;
22-	default: return d->dat[port];
23-	}
24-}
25-
26 void
27 system_deo(Device *d, Uint8 port)
28 {
29 	switch(port) {
30-	case 0x2: d->u->wst.ptr = d->dat[port]; break;
31-	case 0x3: d->u->rst.ptr = d->dat[port]; break;
32+	case 0x2: d->u->wst = (Stack*)(d->u->ram + (d->dat[port] ? (d->dat[port] * 0x100) : 0x10000)); break;
33+	case 0x3: d->u->rst = (Stack*)(d->u->ram + (d->dat[port] ? (d->dat[port] * 0x100) : 0x10100)); break;
34 	case 0xe: system_inspect(d->u); break;
35 	default: system_deo_special(d, port);
36 	}
+0, -2
1@@ -15,7 +15,5 @@ typedef struct SystemDevice {
2 } SystemDevice;
3 
4 void system_inspect(Uxn *u);
5-
6-Uint8 system_dei(Device *d, Uint8 port);
7 void system_deo(Device *d, Uint8 port);
8 void system_deo_special(Device *d, Uint8 port);
+4, -2
 1@@ -38,9 +38,9 @@ uxn_eval(Uxn *u, Uint16 pc)
 2 	while((instr = u->ram[pc++])) {
 3 		/* Return Mode */
 4 		if(instr & 0x40) {
 5-			src = &u->rst; dst = &u->wst;
 6+			src = u->rst; dst = u->wst;
 7 		} else {
 8-			src = &u->wst; dst = &u->rst;
 9+			src = u->wst; dst = u->rst;
10 		}
11 		/* Keep Mode */
12 		if(instr & 0x80) {
13@@ -110,6 +110,8 @@ uxn_boot(Uxn *u, Uint8 *ram)
14 	for(i = 0; i < sizeof(*u); i++)
15 		cptr[i] = 0x00;
16 	u->ram = ram;
17+	u->wst = (Stack*)(ram + 0x10000);
18+	u->rst = (Stack*)(ram + 0x10100);
19 	return 1;
20 }
21 
+2, -2
 1@@ -26,7 +26,7 @@ typedef unsigned int Uint32;
 2 /* clang-format on */
 3 
 4 typedef struct {
 5-	Uint8 ptr, dat[255];
 6+	Uint8 dat[255],ptr;
 7 } Stack;
 8 
 9 typedef struct Device {
10@@ -38,7 +38,7 @@ typedef struct Device {
11 
12 typedef struct Uxn {
13 	Uint8 *ram;
14-	Stack wst, rst;
15+	Stack *wst, *rst;
16 	Device dev[16];
17 } Uxn;
18 
+2, -2
 1@@ -155,12 +155,12 @@ processEvent(void)
 2 static int
 3 start(Uxn *u, char *rom)
 4 {
 5-	if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
 6+	if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8))))
 7 		return error("Boot", "Failed");
 8 	if(!load_rom(u, rom))
 9 		return error("Load", "Failed");
10 	fprintf(stderr, "Loaded %s\n", rom);
11-	/* system   */ uxn_port(u, 0x0, system_dei, system_deo);
12+	/* system   */ uxn_port(u, 0x0, nil_dei, system_deo);
13 	/* console  */ uxn_port(u, 0x1, nil_dei, console_deo);
14 	/* screen   */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
15 	/* empty    */ uxn_port(u, 0x3, nil_dei, nil_deo);
+2, -2
 1@@ -83,9 +83,9 @@ uxn_interrupt(void)
 2 static int
 3 start(Uxn *u)
 4 {
 5-	if(!uxn_boot(u, (Uint8 *)calloc(0x10000, sizeof(Uint8))))
 6+	if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8))))
 7 		return error("Boot", "Failed");
 8-	/* system   */ uxn_port(u, 0x0, system_dei, system_deo);
 9+	/* system   */ uxn_port(u, 0x0, nil_dei, system_deo);
10 	/* console  */ uxn_port(u, 0x1, nil_dei, console_deo);
11 	/* empty    */ uxn_port(u, 0x2, nil_dei, nil_deo);
12 	/* empty    */ uxn_port(u, 0x3, nil_dei, nil_deo);