Browse code

Removed poke16

neauoire authored on 03/01/2022 21:23:57
Showing 7 changed files
... ...
@@ -144,12 +144,35 @@ file_delete(void)
144 144
 void
145 145
 file_deo(Device *d, Uint8 port)
146 146
 {
147
+	Uint16 a, b, res;
147 148
 	switch(port) {
148 149
 	case 0x1: d->vector = peek16(d->dat, 0x0); break;
149
-	case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
150
-	case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
151
-	case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
152
-	case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
153
-	case 0x6: poke16(d->dat, 0x2, file_delete()); break;
150
+	case 0x9:
151
+		DEVPEEK16(a, 0x8);
152
+		res = file_init(&d->mem[a]);
153
+		DEVPOKE16(0x2, res);
154
+		break;
155
+	case 0xd:
156
+		DEVPEEK16(a, 0xc);
157
+		DEVPEEK16(b, 0xa);
158
+		res = file_read(&d->mem[a], b);
159
+		DEVPOKE16(0x2, res);
160
+		break;
161
+	case 0xf:
162
+		DEVPEEK16(a, 0xe);
163
+		DEVPEEK16(b, 0xa);
164
+		res = file_write(&d->mem[a], b, d->dat[0x7]);
165
+		DEVPOKE16(0x2, res);
166
+		break;
167
+	case 0x5:
168
+		DEVPEEK16(a, 0x4);
169
+		DEVPEEK16(b, 0xa);
170
+		res = file_stat(&d->mem[a], b);
171
+		DEVPOKE16(0x2, res);
172
+		break;
173
+	case 0x6:
174
+		res = file_delete();
175
+		DEVPOKE16(0x2, res);
176
+		break;
154 177
 	}
155 178
 }
156 179
\ No newline at end of file
... ...
@@ -30,17 +30,17 @@ mouse_up(Device *d, Uint8 mask)
30 30
 void
31 31
 mouse_pos(Device *d, Uint16 x, Uint16 y)
32 32
 {
33
-	poke16(d->dat, 0x2, x);
34
-	poke16(d->dat, 0x4, y);
33
+	DEVPOKE16(0x2, x);
34
+	DEVPOKE16(0x4, y);
35 35
 	uxn_eval(d->u, d->vector);
36 36
 }
37 37
 
38 38
 void
39 39
 mouse_scroll(Device *d, Uint16 x, Uint16 y)
40 40
 {
41
-	poke16(d->dat, 0xa, x);
42
-	poke16(d->dat, 0xc, -y);
41
+	DEVPOKE16(0xa, x);
42
+	DEVPOKE16(0xc, -y);
43 43
 	uxn_eval(d->u, d->vector);
44
-	poke16(d->dat, 0xa, 0);
45
-	poke16(d->dat, 0xc, 0);
44
+	DEVPOKE16(0xa, 0);
45
+	DEVPOKE16(0xc, 0);
46 46
 }
... ...
@@ -172,29 +172,36 @@ void
172 172
 screen_deo(Device *d, Uint8 port)
173 173
 {
174 174
 	switch(port) {
175
-	case 0x1: d->vector = peek16(d->dat, 0x0); break;
175
+	case 0x1: DEVPEEK16(d->vector, 0x0); break;
176 176
 	case 0x5:
177
-		if(!FIXED_SIZE) set_size(peek16(d->dat, 0x2), peek16(d->dat, 0x4), 1);
177
+		if(!FIXED_SIZE) {
178
+			Uint16 w, h;
179
+			DEVPEEK16(w, 0x2);
180
+			DEVPEEK16(h, 0x4);
181
+			set_size(w, h, 1);
182
+		}
178 183
 		break;
179 184
 	case 0xe: {
180
-		Uint16 x = peek16(d->dat, 0x8);
181
-		Uint16 y = peek16(d->dat, 0xa);
185
+		Uint16 x, y;
182 186
 		Uint8 layer = d->dat[0xe] & 0x40;
187
+		DEVPEEK16(x, 0x8);
188
+		DEVPEEK16(y, 0xa);
183 189
 		screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d->dat[0xe] & 0x3);
184
-		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */
185
-		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */
190
+		if(d->dat[0x6] & 0x01) DEVPOKE16(0x8, x + 1); /* auto x+1 */
191
+		if(d->dat[0x6] & 0x02) DEVPOKE16(0xa, y + 1); /* auto y+1 */
186 192
 		break;
187 193
 	}
188 194
 	case 0xf: {
189
-		Uint16 x = peek16(d->dat, 0x8);
190
-		Uint16 y = peek16(d->dat, 0xa);
191
-		Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
192
-		Uint8 *addr = &d->mem[peek16(d->dat, 0xc)];
195
+		Uint16 x, y, addr;
193 196
 		Uint8 twobpp = !!(d->dat[0xf] & 0x80);
194
-		screen_blit(&uxn_screen, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp);
195
-		if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */
196
-		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8);                                /* auto x+8 */
197
-		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8);                                /* auto y+8 */
197
+		Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
198
+		DEVPEEK16(x, 0x8);
199
+		DEVPEEK16(y, 0xa);
200
+		DEVPEEK16(addr, 0xc);
201
+		screen_blit(&uxn_screen, layer, x, y, &d->mem[addr], d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp);
202
+		if(d->dat[0x6] & 0x04) DEVPOKE16(0xc, addr + 8 + twobpp * 8); /* auto addr+length */
203
+		if(d->dat[0x6] & 0x01) DEVPOKE16(0x8, x + 8);                 /* auto x+8 */
204
+		if(d->dat[0x6] & 0x02) DEVPOKE16(0xa, y + 8);                 /* auto y+8 */
198 205
 		break;
199 206
 	}
200 207
 	}
... ...
@@ -31,7 +31,6 @@ WITH REGARD TO THIS SOFTWARE.
31 31
 #define DEVW(d, x, y) { dev = (d); if(bs) { DEVW8((x), (y) >> 8); DEVW8((x) + 1, (y)); } else { DEVW8((x), (y)) } }
32 32
 #define WARP(x) { if(bs) u->ram.ptr = (x); else u->ram.ptr += (Sint8)(x); }
33 33
 
34
-void poke16(Uint8 *m, Uint16 a, Uint16 b) { m[a] = b >> 8; m[a + 1] = b; }
35 34
 Uint16 peek16(Uint8 *m, Uint16 a) { Uint16 r = m[a] << 8; return r + m[a + 1]; }
36 35
 
37 36
 int
... ...
@@ -17,6 +17,13 @@ typedef unsigned int Uint32;
17 17
 
18 18
 #define PAGE_PROGRAM 0x0100
19 19
 
20
+/* clang-format off */
21
+
22
+#define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; }
23
+#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
24
+
25
+/* clang-format on */
26
+
20 27
 typedef struct {
21 28
 	Uint8 ptr;
22 29
 	Uint8 dat[256];
... ...
@@ -41,7 +48,6 @@ typedef struct Uxn {
41 48
 	Device dev[16];
42 49
 } Uxn;
43 50
 
44
-void poke16(Uint8 *m, Uint16 a, Uint16 b);
45 51
 Uint16 peek16(Uint8 *m, Uint16 a);
46 52
 
47 53
 int uxn_boot(Uxn *c, Uint8 *memory);
... ...
@@ -72,7 +72,7 @@ static void
72 72
 console_deo(Device *d, Uint8 port)
73 73
 {
74 74
 	if(port == 0x1)
75
-		d->vector = peek16(d->dat, 0x0);
75
+		DEVPEEK16(d->vector, 0x0);
76 76
 	if(port > 0x7)
77 77
 		write(port - 0x7, (char *)&d->dat[port], 1);
78 78
 }
... ...
@@ -110,7 +110,7 @@ nil_dei(Device *d, Uint8 port)
110 110
 static void
111 111
 nil_deo(Device *d, Uint8 port)
112 112
 {
113
-	if(port == 0x1) d->vector = peek16(d->dat, 0x0);
113
+	if(port == 0x1) DEVPEEK16(d->vector, 0x0);
114 114
 }
115 115
 
116 116
 #pragma mark - Generics
... ...
@@ -135,8 +135,9 @@ static void
135 135
 run(Uxn *u)
136 136
 {
137 137
 	Uint16 vec;
138
+	Device *d = devconsole;
138 139
 	while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) {
139
-		vec = peek16(devconsole->dat, 0);
140
+		DEVPEEK16(vec, 0);
140 141
 		if(!vec) vec = u->ram.ptr; /* continue after last BRK */
141 142
 		uxn_eval(u, vec);
142 143
 	}
... ...
@@ -194,7 +194,7 @@ static void
194 194
 console_deo(Device *d, Uint8 port)
195 195
 {
196 196
 	if(port == 0x1)
197
-		d->vector = peek16(d->dat, 0x0);
197
+		DEVPEEK16(d->vector, 0x0);
198 198
 	if(port > 0x7)
199 199
 		write(port - 0x7, (char *)&d->dat[port], 1);
200 200
 }
... ...
@@ -206,7 +206,7 @@ audio_dei(Device *d, Uint8 port)
206 206
 	if(!audio_id) return d->dat[port];
207 207
 	switch(port) {
208 208
 	case 0x4: return audio_get_vu(c);
209
-	case 0x2: poke16(d->dat, 0x2, c->i); /* fall through */
209
+	case 0x2: DEVPOKE16(0x2, c->i); /* fall through */
210 210
 	default: return d->dat[port];
211 211
 	}
212 212
 }
... ...
@@ -262,7 +262,7 @@ nil_dei(Device *d, Uint8 port)
262 262
 static void
263 263
 nil_deo(Device *d, Uint8 port)
264 264
 {
265
-	if(port == 0x1) d->vector = peek16(d->dat, 0x0);
265
+	if(port == 0x1) DEVPEEK16(d->vector, 0x0);
266 266
 }
267 267
 
268 268
 /* Boot */