commit c990a2a

neauoire  ·  2022-04-05 17:30:17 +0000 UTC
parent 574c425
Removed a few indirections
6 files changed,  +29, -39
+7, -13
 1@@ -151,18 +151,12 @@ file_delete(UxnFile *c)
 2 	return unlink(c->current_filename);
 3 }
 4 
 5-static UxnFile *
 6-file_instance(Device *d)
 7-{
 8-	return &uxn_file[d - &d->u->dev[DEV_FILE0]];
 9-}
10-
11 /* IO */
12 
13 void
14-file_deo(Device *d, Uint8 port)
15+file_deo(Uint8 id, Device *d, Uint8 port)
16 {
17-	UxnFile *c = file_instance(d);
18+	UxnFile *c = &uxn_file[id];
19 	Uint16 addr, len, res;
20 	switch(port) {
21 	case 0x5:
22@@ -202,18 +196,18 @@ file_deo(Device *d, Uint8 port)
23 }
24 
25 Uint8
26-file_dei(Device *d, Uint8 port)
27+file_dei(Uint8 id, Uint8 *d, Uint8 port)
28 {
29-	UxnFile *c = file_instance(d);
30+	UxnFile *c = &uxn_file[id];
31 	Uint16 res;
32 	switch(port) {
33 	case 0xc:
34 	case 0xd:
35-		res = file_read(c, &d->dat[port], 1);
36-		DEVPOKE16(0x2, res);
37+		res = file_read(c, &d[port], 1);
38+		POKDEV(0x2, res);
39 		break;
40 	}
41-	return d->dat[port];
42+	return d[port];
43 }
44 
45 /* Boot */
+2, -2
1@@ -13,6 +13,6 @@ WITH REGARD TO THIS SOFTWARE.
2 #define POLYFILEY 2
3 #define DEV_FILE0 0xa
4 
5-void file_deo(Device *d, Uint8 port);
6-Uint8 file_dei(Device *d, Uint8 port);
7+void file_deo(Uint8 id, Device *d, Uint8 port);
8+Uint8 file_dei(Uint8 id, Uint8 *d, Uint8 port);
9 int load_rom(Uxn *u, char *filename);
+0, -5
 1@@ -9,11 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 2 WITH REGARD TO THIS SOFTWARE.
 3 */
 4 
 5-typedef struct SystemDevice {
 6-	Device device;
 7-	struct UxnScreen *screen;
 8-} SystemDevice;
 9-
10 void system_inspect(Uxn *u);
11 void system_deo(Uxn *u, Uint8 *d, Uint8 port);
12 void system_deo_special(Uint8 *d, Uint8 port);
+1, -0
1@@ -110,6 +110,7 @@ uxn_boot(Uxn *u, Uint8 *ram)
2 	u->ram = ram;
3 	u->wst = (Stack*)(ram + 0x10000);
4 	u->rst = (Stack*)(ram + 0x10100);
5+	u->dpg = (Uint8*)(ram + 0x10200);
6 	return 1;
7 }
8 
+1, -1
1@@ -41,7 +41,7 @@ typedef struct Device {
2 } Device;
3 
4 typedef struct Uxn {
5-	Uint8 *ram;
6+	Uint8 *ram, *dpg;
7 	Stack *wst, *rst;
8 	Uint8 (*dei)(struct Uxn *u, Uint8 address);
9 	void (*deo)(struct Uxn *u, Uint8 address, Uint8 value);
+18, -18
  1@@ -42,9 +42,9 @@ system_deo_special(Uint8 *d, Uint8 port)
  2 static int
  3 console_input(Uxn *u, char c)
  4 {
  5-	Device *d = &u->dev[1];
  6-	d->dat[0x2] = c;
  7-	return uxn_eval(u, GETVEC(d->dat));
  8+	Uint8 *d = u->dev[1].dat;
  9+	d[0x2] = c;
 10+	return uxn_eval(u, GETVEC(d));
 11 }
 12 
 13 static void
 14@@ -65,8 +65,8 @@ uxn11_dei(struct Uxn *u, Uint8 addr)
 15 	Device *d = &u->dev[addr >> 4];
 16 	switch(addr & 0xf0) {
 17 	case 0x20: return screen_dei(d->dat, p); break;
 18-	case 0xa0: return file_dei(d, p); break;
 19-	case 0xb0: return file_dei(d, p); break;
 20+	case 0xa0: return file_dei(0, d->dat, p); break;
 21+	case 0xb0: return file_dei(1, d->dat, p); break;
 22 	case 0xc0: return datetime_dei(d->dat, p); break;
 23 	}
 24 	return d->dat[p];
 25@@ -82,8 +82,8 @@ uxn11_deo(Uxn *u, Uint8 addr, Uint8 v)
 26 	case 0x00: system_deo(u, d->dat, p); break;
 27 	case 0x10: console_deo(d->dat, p); break;
 28 	case 0x20: screen_deo(u->ram, d->dat, p); break;
 29-	case 0xa0: file_deo(d, p); break;
 30-	case 0xb0: file_deo(d, p); break;
 31+	case 0xa0: file_deo(0, d, p); break;
 32+	case 0xb0: file_deo(1, d, p); break;
 33 	}
 34 }
 35 
 36@@ -126,7 +126,7 @@ get_button(KeySym sym)
 37 }
 38 
 39 static void
 40-processEvent(void)
 41+processEvent(Uxn *u)
 42 {
 43 	XEvent ev;
 44 	XNextEvent(display, &ev);
 45@@ -144,26 +144,26 @@ processEvent(void)
 46 		KeySym sym;
 47 		char buf[7];
 48 		XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
 49-		controller_down(devctrl->u, devctrl->dat, get_button(sym));
 50-		controller_key(devctrl->u, devctrl->dat, sym < 0x80 ? sym : buf[0]);
 51+		controller_down(u, devctrl->dat, get_button(sym));
 52+		controller_key(u, devctrl->dat, sym < 0x80 ? sym : buf[0]);
 53 	} break;
 54 	case KeyRelease: {
 55 		KeySym sym;
 56 		char buf[7];
 57 		XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
 58-		controller_up(devctrl->u, devctrl->dat, get_button(sym));
 59+		controller_up(u, devctrl->dat, get_button(sym));
 60 	} break;
 61 	case ButtonPress: {
 62 		XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
 63-		mouse_down(devmouse->u, devmouse->dat, 0x1 << (e->button - 1));
 64+		mouse_down(u, devmouse->dat, 0x1 << (e->button - 1));
 65 	} break;
 66 	case ButtonRelease: {
 67 		XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
 68-		mouse_up(devmouse->u, devmouse->dat, 0x1 << (e->button - 1));
 69+		mouse_up(u, devmouse->dat, 0x1 << (e->button - 1));
 70 	} break;
 71 	case MotionNotify: {
 72 		XMotionEvent *e = (XMotionEvent *)&ev;
 73-		mouse_pos(devmouse->u, devmouse->dat, e->x, e->y);
 74+		mouse_pos(u, devmouse->dat, e->x, e->y);
 75 	} break;
 76 	}
 77 }
 78@@ -184,7 +184,7 @@ nil_deo(Device *d, Uint8 port)
 79 static int
 80 start(Uxn *u, char *rom)
 81 {
 82-	if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8))))
 83+	if(!uxn_boot(u, (Uint8 *)calloc(0x10300, sizeof(Uint8))))
 84 		return error("Boot", "Failed");
 85 	if(!load_rom(u, rom))
 86 		return error("Load", "Failed");
 87@@ -202,8 +202,8 @@ start(Uxn *u, char *rom)
 88 	/* empty    */ uxn_port(u, 0x7, nil_dei, nil_deo);
 89 	/* control  */ devctrl = uxn_port(u, 0x8, nil_dei, nil_deo);
 90 	/* mouse    */ devmouse = uxn_port(u, 0x9, nil_dei, nil_deo);
 91-	/* file0    */ uxn_port(u, 0xa, file_dei, file_deo);
 92-	/* file1    */ uxn_port(u, 0xb, file_dei, file_deo);
 93+	/* file0    */ uxn_port(u, 0xa, nil_dei, nil_deo);
 94+	/* file1    */ uxn_port(u, 0xb, nil_dei, nil_deo);
 95 	/* datetime */ uxn_port(u, 0xc, nil_dei, nil_deo);
 96 	/* empty    */ uxn_port(u, 0xd, nil_dei, nil_deo);
 97 	/* reserved */ uxn_port(u, 0xe, nil_dei, nil_deo);
 98@@ -262,7 +262,7 @@ main(int argc, char **argv)
 99 		if(poll(fds, 2, 1000) <= 0)
100 			continue;
101 		while(XPending(display))
102-			processEvent();
103+			processEvent(&u);
104 		if(poll(&fds[1], 1, 0)) {
105 			read(fds[1].fd, expirations, 8);    /* Indicate we handled the timer */
106 			uxn_eval(&u, GETVECTOR(devscreen)); /* Call the vector once, even if the timer fired multiple times */