Browse code

Removed device vector variable

neauoire authored on 08/01/2022 00:46:50
Showing 8 changed files
... ...
@@ -18,7 +18,7 @@ controller_down(Device *d, Uint8 mask)
18 18
 {
19 19
 	if(mask) {
20 20
 		d->dat[2] |= mask;
21
-		uxn_eval(d->u, d->vector);
21
+		uxn_eval(d->u, GETVECTOR(d));
22 22
 	}
23 23
 }
24 24
 
... ...
@@ -27,7 +27,7 @@ controller_up(Device *d, Uint8 mask)
27 27
 {
28 28
 	if(mask) {
29 29
 		d->dat[2] &= (~mask);
30
-		uxn_eval(d->u, d->vector);
30
+		uxn_eval(d->u, GETVECTOR(d));
31 31
 	}
32 32
 }
33 33
 
... ...
@@ -36,7 +36,7 @@ controller_key(Device *d, Uint8 key)
36 36
 {
37 37
 	if(key) {
38 38
 		d->dat[3] = key;
39
-		uxn_eval(d->u, d->vector);
39
+		uxn_eval(d->u, GETVECTOR(d));
40 40
 		d->dat[3] = 0x00;
41 41
 	}
42 42
 }
... ...
@@ -46,7 +46,7 @@ controller_special(Device *d, Uint8 key)
46 46
 {
47 47
 	if(key) {
48 48
 		d->dat[4] = key;
49
-		uxn_eval(d->u, d->vector);
49
+		uxn_eval(d->u, GETVECTOR(d));
50 50
 		d->dat[4] = 0x00;
51 51
 	}
52 52
 }
53 53
\ No newline at end of file
... ...
@@ -146,9 +146,6 @@ file_deo(Device *d, Uint8 port)
146 146
 {
147 147
 	Uint16 a, b, res;
148 148
 	switch(port) {
149
-	case 0x1:
150
-		DEVPEEK16(d->vector, 0x0);
151
-		break;
152 149
 	case 0x5:
153 150
 		DEVPEEK16(a, 0x4);
154 151
 		DEVPEEK16(b, 0xa);
... ...
@@ -17,14 +17,14 @@ void
17 17
 mouse_down(Device *d, Uint8 mask)
18 18
 {
19 19
 	d->dat[6] |= mask;
20
-	uxn_eval(d->u, d->vector);
20
+	uxn_eval(d->u, GETVECTOR(d));
21 21
 }
22 22
 
23 23
 void
24 24
 mouse_up(Device *d, Uint8 mask)
25 25
 {
26 26
 	d->dat[6] &= (~mask);
27
-	uxn_eval(d->u, d->vector);
27
+	uxn_eval(d->u, GETVECTOR(d));
28 28
 }
29 29
 
30 30
 void
... ...
@@ -32,7 +32,7 @@ mouse_pos(Device *d, Uint16 x, Uint16 y)
32 32
 {
33 33
 	DEVPOKE16(0x2, x);
34 34
 	DEVPOKE16(0x4, y);
35
-	uxn_eval(d->u, d->vector);
35
+	uxn_eval(d->u, GETVECTOR(d));
36 36
 }
37 37
 
38 38
 void
... ...
@@ -40,7 +40,7 @@ mouse_scroll(Device *d, Uint16 x, Uint16 y)
40 40
 {
41 41
 	DEVPOKE16(0xa, x);
42 42
 	DEVPOKE16(0xc, -y);
43
-	uxn_eval(d->u, d->vector);
43
+	uxn_eval(d->u, GETVECTOR(d));
44 44
 	DEVPOKE16(0xa, 0);
45 45
 	DEVPOKE16(0xc, 0);
46 46
 }
... ...
@@ -127,7 +127,6 @@ void
127 127
 screen_deo(Device *d, Uint8 port)
128 128
 {
129 129
 	switch(port) {
130
-	case 0x1: DEVPEEK16(d->vector, 0x0); break;
131 130
 	case 0x5:
132 131
 		if(!FIXED_SIZE) {
133 132
 			Uint16 w, h;
... ...
@@ -28,12 +28,14 @@ int
28 28
 uxn_halt(Uxn *u, Uint8 error, Uint16 addr)
29 29
 {
30 30
 	Device *d = &u->dev[0];
31
-	Uint16 vec = d->vector;
31
+	Uint16 vec = GETVECTOR(d);
32 32
 	DEVPOKE16(0x4, addr);
33 33
 	d->dat[0x6] = error;
34
-	uxn_eval(&supervisor, supervisor.dev[0].vector);
34
+	uxn_eval(&supervisor, GETVECTOR(&supervisor.dev[0]));
35 35
 	if(vec) {
36
-		d->vector = 0; /* need to rearm to run System/vector again */
36
+		/* need to rearm to run System/vector again */
37
+		d->dat[0] = 0;
38
+		d->dat[1] = 0;
37 39
 		if(error != 2) /* working stack overflow has special treatment */
38 40
 			vec += 0x0004;
39 41
 		return uxn_eval(u, vec);
... ...
@@ -58,7 +60,6 @@ void
58 60
 system_deo(Device *d, Uint8 port)
59 61
 {
60 62
 	switch(port) {
61
-	case 0x1: DEVPEEK16(d->vector, 0x0); break;
62 63
 	case 0x2: d->u->wst->ptr = d->dat[port]; break;
63 64
 	case 0x3: d->u->rst->ptr = d->dat[port]; break;
64 65
 	default: system_deo_special(d, port);
... ...
@@ -27,6 +27,7 @@ typedef unsigned int Uint32;
27 27
 
28 28
 #define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; }
29 29
 #define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
30
+#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
30 31
 
31 32
 /* clang-format on */
32 33
 
... ...
@@ -37,7 +38,6 @@ typedef struct {
37 38
 typedef struct Device {
38 39
 	struct Uxn *u;
39 40
 	Uint8 *dat, *mem;
40
-	Uint16 vector;
41 41
 	Uint8 (*dei)(struct Device *d, Uint8);
42 42
 	void (*deo)(struct Device *d, Uint8);
43 43
 } Device;
... ...
@@ -60,8 +60,6 @@ system_deo_special(Device *d, Uint8 port)
60 60
 static void
61 61
 console_deo(Device *d, Uint8 port)
62 62
 {
63
-	if(port == 0x1)
64
-		DEVPEEK16(d->vector, 0x0);
65 63
 	if(port > 0x7)
66 64
 		write(port - 0x7, (char *)&d->dat[port], 1);
67 65
 }
... ...
@@ -75,7 +73,8 @@ nil_dei(Device *d, Uint8 port)
75 73
 static void
76 74
 nil_deo(Device *d, Uint8 port)
77 75
 {
78
-	if(port == 0x1) DEVPEEK16(d->vector, 0x0);
76
+	(void)d;
77
+	(void)port;
79 78
 }
80 79
 
81 80
 #pragma mark - Generics
... ...
@@ -84,7 +83,7 @@ static int
84 83
 console_input(Uxn *u, char c)
85 84
 {
86 85
 	devconsole->dat[0x2] = c;
87
-	return uxn_eval(u, devconsole->vector);
86
+	return uxn_eval(u, GETVECTOR(devconsole));
88 87
 }
89 88
 
90 89
 static void
... ...
@@ -180,8 +180,6 @@ system_deo_special(Device *d, Uint8 port)
180 180
 static void
181 181
 console_deo(Device *d, Uint8 port)
182 182
 {
183
-	if(port == 0x1)
184
-		DEVPEEK16(d->vector, 0x0);
185 183
 	if(port > 0x7)
186 184
 		write(port - 0x7, (char *)&d->dat[port], 1);
187 185
 }
... ...
@@ -228,7 +226,8 @@ nil_dei(Device *d, Uint8 port)
228 226
 static void
229 227
 nil_deo(Device *d, Uint8 port)
230 228
 {
231
-	if(port == 0x1) DEVPEEK16(d->vector, 0x0);
229
+	(void)d;
230
+	(void)port;
232 231
 }
233 232
 
234 233
 /* Boot */
... ...
@@ -409,7 +408,7 @@ static int
409 408
 console_input(Uxn *u, char c)
410 409
 {
411 410
 	devconsole->dat[0x2] = c;
412
-	return uxn_eval(u, devconsole->vector);
411
+	return uxn_eval(u, GETVECTOR(devconsole));
413 412
 }
414 413
 
415 414
 static int
... ...
@@ -483,8 +482,8 @@ run(Uxn *u)
483 482
 				console_input(u, event.cbutton.button);
484 483
 		}
485 484
 		if(devsystem->dat[0xe])
486
-			uxn_eval(&supervisor, supervisor.dev[2].vector);
487
-		uxn_eval(u, devscreen->vector);
485
+			uxn_eval(&supervisor, GETVECTOR(&supervisor.dev[2]));
486
+		uxn_eval(u, GETVECTOR(devscreen));
488 487
 		if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe])
489 488
 			redraw();
490 489
 		if(!BENCH) {