commit 038eaf0

neauoire  ·  2022-04-05 17:37:40 +0000 UTC
parent c990a2a
Removed global devices
1 files changed,  +11, -13
+11, -13
 1@@ -20,8 +20,6 @@ static Display *display;
 2 static Visual *visual;
 3 static Window window;
 4 
 5-static Device *devscreen, *devctrl, *devmouse;
 6-
 7 #define WIDTH (64 * 8)
 8 #define HEIGHT (40 * 8)
 9 
10@@ -144,26 +142,26 @@ processEvent(Uxn *u)
11 		KeySym sym;
12 		char buf[7];
13 		XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
14-		controller_down(u, devctrl->dat, get_button(sym));
15-		controller_key(u, devctrl->dat, sym < 0x80 ? sym : buf[0]);
16+		controller_down(u, u->dev[0x8].dat, get_button(sym));
17+		controller_key(u, u->dev[0x8].dat, sym < 0x80 ? sym : buf[0]);
18 	} break;
19 	case KeyRelease: {
20 		KeySym sym;
21 		char buf[7];
22 		XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
23-		controller_up(u, devctrl->dat, get_button(sym));
24+		controller_up(u, u->dev[0x8].dat, get_button(sym));
25 	} break;
26 	case ButtonPress: {
27 		XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
28-		mouse_down(u, devmouse->dat, 0x1 << (e->button - 1));
29+		mouse_down(u, u->dev[0x9].dat, 0x1 << (e->button - 1));
30 	} break;
31 	case ButtonRelease: {
32 		XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
33-		mouse_up(u, devmouse->dat, 0x1 << (e->button - 1));
34+		mouse_up(u, u->dev[0x9].dat, 0x1 << (e->button - 1));
35 	} break;
36 	case MotionNotify: {
37 		XMotionEvent *e = (XMotionEvent *)&ev;
38-		mouse_pos(u, devmouse->dat, e->x, e->y);
39+		mouse_pos(u, u->dev[0x9].dat, e->x, e->y);
40 	} break;
41 	}
42 }
43@@ -194,14 +192,14 @@ start(Uxn *u, char *rom)
44 
45 	/* system   */ uxn_port(u, 0x0, nil_dei, nil_deo);
46 	/* console  */ uxn_port(u, 0x1, nil_dei, nil_deo);
47-	/* screen   */ devscreen = uxn_port(u, 0x2, nil_dei, nil_deo);
48+	/* screen   */ uxn_port(u, 0x2, nil_dei, nil_deo);
49 	/* empty    */ uxn_port(u, 0x3, nil_dei, nil_deo);
50 	/* empty    */ uxn_port(u, 0x4, nil_dei, nil_deo);
51 	/* empty    */ uxn_port(u, 0x5, nil_dei, nil_deo);
52 	/* empty    */ uxn_port(u, 0x6, nil_dei, nil_deo);
53 	/* empty    */ uxn_port(u, 0x7, nil_dei, nil_deo);
54-	/* control  */ devctrl = uxn_port(u, 0x8, nil_dei, nil_deo);
55-	/* mouse    */ devmouse = uxn_port(u, 0x9, nil_dei, nil_deo);
56+	/* control  */ uxn_port(u, 0x8, nil_dei, nil_deo);
57+	/* mouse    */ uxn_port(u, 0x9, nil_dei, nil_deo);
58 	/* file0    */ uxn_port(u, 0xa, nil_dei, nil_deo);
59 	/* file1    */ uxn_port(u, 0xb, nil_dei, nil_deo);
60 	/* datetime */ uxn_port(u, 0xc, nil_dei, nil_deo);
61@@ -264,8 +262,8 @@ main(int argc, char **argv)
62 		while(XPending(display))
63 			processEvent(&u);
64 		if(poll(&fds[1], 1, 0)) {
65-			read(fds[1].fd, expirations, 8);    /* Indicate we handled the timer */
66-			uxn_eval(&u, GETVECTOR(devscreen)); /* Call the vector once, even if the timer fired multiple times */
67+			read(fds[1].fd, expirations, 8);      /* Indicate we handled the timer */
68+			uxn_eval(&u, GETVEC(u.dev[0x2].dat)); /* Call the vector once, even if the timer fired multiple times */
69 		}
70 		if(uxn_screen.fg.changed || uxn_screen.bg.changed)
71 			redraw();