commit 725bc38
neauoire
·
2022-04-05 18:42:50 +0000 UTC
parent dba7b1f
Removed Devices
8 files changed,
+56,
-66
+1,
-1
1@@ -1,4 +1,4 @@
2-# Uxn
3+# Uxn11
4
5 An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C.
6
M
build.sh
+8,
-3
1@@ -1,7 +1,12 @@
2 #!/bin/sh -e
3
4-clang-format -i src/uxn11.c
5-clang-format -i src/devices/*
6+if [ "${1}" = '--format' ];
7+then
8+ echo "Formatting.."
9+ clang-format -i src/uxn11.c
10+ clang-format -i src/devices/*
11+fi
12+
13
14 echo "Cleaning.."
15 rm -f ./bin/*
16@@ -9,7 +14,7 @@ rm -f ./bin/*
17 echo "Building.."
18 mkdir -p bin
19
20-if [ "${1}" = '--install' ];
21+if [ "${1}" = '--install' ];
22 then
23 echo "Installing.."
24 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,
-14
1@@ -154,43 +154,43 @@ file_delete(UxnFile *c)
2 /* IO */
3
4 void
5-file_deo(Uint8 id, Uint8 *ram, Device *d, Uint8 port)
6+file_deo(Uint8 id, Uint8 *ram, Uint8 *d, Uint8 port)
7 {
8 UxnFile *c = &uxn_file[id];
9 Uint16 addr, len, res;
10 switch(port) {
11 case 0x5:
12- DEVPEEK16(addr, 0x4);
13- DEVPEEK16(len, 0xa);
14+ PEKDEV(addr, 0x4);
15+ PEKDEV(len, 0xa);
16 if(len > 0x10000 - addr)
17 len = 0x10000 - addr;
18 res = file_stat(c, &ram[addr], len);
19- DEVPOKE16(0x2, res);
20+ POKDEV(0x2, res);
21 break;
22 case 0x6:
23 res = file_delete(c);
24- DEVPOKE16(0x2, res);
25+ POKDEV(0x2, res);
26 break;
27 case 0x9:
28- DEVPEEK16(addr, 0x8);
29+ PEKDEV(addr, 0x8);
30 res = file_init(c, (char *)&ram[addr], 0x10000 - addr);
31- DEVPOKE16(0x2, res);
32+ POKDEV(0x2, res);
33 break;
34 case 0xd:
35- DEVPEEK16(addr, 0xc);
36- DEVPEEK16(len, 0xa);
37+ PEKDEV(addr, 0xc);
38+ PEKDEV(len, 0xa);
39 if(len > 0x10000 - addr)
40 len = 0x10000 - addr;
41 res = file_read(c, &ram[addr], len);
42- DEVPOKE16(0x2, res);
43+ POKDEV(0x2, res);
44 break;
45 case 0xf:
46- DEVPEEK16(addr, 0xe);
47- DEVPEEK16(len, 0xa);
48+ PEKDEV(addr, 0xe);
49+ PEKDEV(len, 0xa);
50 if(len > 0x10000 - addr)
51 len = 0x10000 - addr;
52- res = file_write(c, &ram[addr], len, d->dat[0x7]);
53- DEVPOKE16(0x2, res);
54+ res = file_write(c, &ram[addr], len, d[0x7]);
55+ POKDEV(0x2, res);
56 break;
57 }
58 }
+1,
-1
1@@ -13,6 +13,6 @@ WITH REGARD TO THIS SOFTWARE.
2 #define POLYFILEY 2
3 #define DEV_FILE0 0xa
4
5-void file_deo(Uint8 id, Uint8 *ram, Device *d, Uint8 port);
6+void file_deo(Uint8 id, Uint8 *ram, Uint8 *d, Uint8 port);
7 Uint8 file_dei(Uint8 id, Uint8 *d, Uint8 port);
8 int load_rom(Uxn *u, char *filename);
+4,
-4
1@@ -32,7 +32,7 @@ uxn_eval(Uxn *u, Uint16 pc)
2 unsigned int a, b, c, j, k, bs, instr, errcode;
3 Uint8 kptr, *sp;
4 Stack *src, *dst;
5- if(!pc || u->dev[0].dat[0xf]) return 0;
6+ if(!pc || u->dev[0x0f]) return 0;
7 while((instr = u->ram[pc++])) {
8 /* Return Mode */
9 if(instr & 0x40) {
10@@ -108,8 +108,8 @@ uxn_boot(Uxn *u, Uint8 *ram)
11 for(i = 0; i < sizeof(*u); i++)
12 cptr[i] = 0x00;
13 u->ram = ram;
14- u->wst = (Stack*)(ram + 0x10000);
15- u->rst = (Stack*)(ram + 0x10100);
16- u->dpg = (Uint8*)(ram + 0x10200);
17+ u->wst = (Stack *)(ram + 0x10000);
18+ u->rst = (Stack *)(ram + 0x10100);
19+ u->dev = (Uint8 *)(ram + 0x10200);
20 return 1;
21 }
+2,
-11
1@@ -19,10 +19,6 @@ typedef unsigned int Uint32;
2
3 /* clang-format off */
4
5-#define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; }
6-#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
7-#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
8-
9 #define GETVEC(d) ((d)[0] << 8 | (d)[1])
10 #define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
11 #define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }
12@@ -30,19 +26,14 @@ typedef unsigned int Uint32;
13 /* clang-format on */
14
15 typedef struct {
16- Uint8 dat[255],ptr;
17+ Uint8 dat[255], ptr;
18 } Stack;
19
20-typedef struct Device {
21- Uint8 dat[16];
22-} Device;
23-
24 typedef struct Uxn {
25- Uint8 *ram, *dpg;
26+ Uint8 *ram, *dev;
27 Stack *wst, *rst;
28 Uint8 (*dei)(struct Uxn *u, Uint8 address);
29 void (*deo)(struct Uxn *u, Uint8 address, Uint8 value);
30- Device dev[16];
31 } Uxn;
32
33 int uxn_boot(Uxn *u, Uint8 *ram);
+25,
-31
1@@ -40,8 +40,8 @@ system_deo_special(Uint8 *d, Uint8 port)
2 static int
3 console_input(Uxn *u, char c)
4 {
5- Uint8 *d = u->dev[1].dat;
6- d[0x2] = c;
7+ Uint8 *d = &u->dev[0x10];
8+ d[0x02] = c;
9 return uxn_eval(u, GETVEC(d));
10 }
11
12@@ -59,33 +59,27 @@ console_deo(Uint8 *d, Uint8 port)
13 static Uint8
14 uxn11_dei(struct Uxn *u, Uint8 addr)
15 {
16- Uint8 p = addr & 0x0f;
17- Device *d = &u->dev[addr >> 4];
18- switch(addr & 0xf0) {
19- case 0x20: return screen_dei(d->dat, p); break;
20- case 0x80: return u->dpg[0x80 + p]; break;
21- case 0x90: return u->dpg[0x90 + p]; break;
22- case 0xa0: return file_dei(0, d->dat, p); break;
23- case 0xb0: return file_dei(1, d->dat, p); break;
24- case 0xc0: return datetime_dei(d->dat, p); break;
25+ Uint8 p = addr & 0x0f, d = addr & 0xf0;
26+ switch(d) {
27+ case 0x20: return screen_dei(&u->dev[d], p); break;
28+ case 0xa0: return file_dei(0, &u->dev[d], p); break;
29+ case 0xb0: return file_dei(1, &u->dev[d], p); break;
30+ case 0xc0: return datetime_dei(&u->dev[d], p); break;
31 }
32- return d->dat[p];
33+ return u->dev[addr];
34 }
35
36 static void
37 uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
38 {
39- Uint8 p = addr & 0x0f;
40- Device *d = &u->dev[addr >> 4];
41- d->dat[p] = v;
42- switch(addr & 0xf0) {
43- case 0x00: system_deo(u, d->dat, p); break;
44- case 0x10: console_deo(d->dat, p); break;
45- case 0x20: screen_deo(u->ram, d->dat, p); break;
46- case 0x80: u->dpg[0x80 + p] = v; break;
47- case 0x90: u->dpg[0x90 + p] = v; break;
48- case 0xa0: file_deo(0, u->ram, d, p); break;
49- case 0xb0: file_deo(1, u->ram, d, p); break;
50+ Uint8 p = addr & 0x0f, d = addr & 0xf0;
51+ u->dev[addr] = v;
52+ switch(d) {
53+ case 0x00: system_deo(u, &u->dev[d], p); break;
54+ case 0x10: console_deo(&u->dev[d], p); break;
55+ case 0x20: screen_deo(u->ram, &u->dev[d], p); break;
56+ case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
57+ case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break;
58 }
59 }
60
61@@ -146,26 +140,26 @@ processEvent(Uxn *u)
62 KeySym sym;
63 char buf[7];
64 XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
65- controller_down(u, &u->dpg[0x80], get_button(sym));
66- controller_key(u, &u->dpg[0x80], sym < 0x80 ? sym : buf[0]);
67+ controller_down(u, &u->dev[0x80], get_button(sym));
68+ controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : buf[0]);
69 } break;
70 case KeyRelease: {
71 KeySym sym;
72 char buf[7];
73 XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
74- controller_up(u, &u->dpg[0x80], get_button(sym));
75+ controller_up(u, &u->dev[0x80], get_button(sym));
76 } break;
77 case ButtonPress: {
78 XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
79- mouse_down(u, &u->dpg[0x90], 0x1 << (e->button - 1));
80+ mouse_down(u, &u->dev[0x90], 0x1 << (e->button - 1));
81 } break;
82 case ButtonRelease: {
83 XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
84- mouse_up(u, &u->dpg[0x90], 0x1 << (e->button - 1));
85+ mouse_up(u, &u->dev[0x90], 0x1 << (e->button - 1));
86 } break;
87 case MotionNotify: {
88 XMotionEvent *e = (XMotionEvent *)&ev;
89- mouse_pos(u, &u->dpg[0x90], e->x, e->y);
90+ mouse_pos(u, &u->dev[0x90], e->x, e->y);
91 } break;
92 }
93 }
94@@ -235,8 +229,8 @@ main(int argc, char **argv)
95 while(XPending(display))
96 processEvent(&u);
97 if(poll(&fds[1], 1, 0)) {
98- read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */
99- uxn_eval(&u, GETVEC(u.dev[0x2].dat)); /* Call the vector once, even if the timer fired multiple times */
100+ read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */
101+ uxn_eval(&u, GETVEC(&u.dev[0x20])); /* Call the vector once, even if the timer fired multiple times */
102 }
103 if(uxn_screen.fg.changed || uxn_screen.bg.changed)
104 redraw();
+1,
-1
1@@ -25,7 +25,7 @@ error(char *msg, const char *err)
2 }
3
4 void
5-system_deo_special(Device *d, Uint8 port)
6+system_deo_special(Uint8 *d, Uint8 port)
7 {
8 (void)d;
9 (void)port;