commit e0a9562
Devine Lu Linvega
·
2025-05-16 16:43:13 +0000 UTC
parent 6007c24
(uxn11) Cleanup
1 files changed,
+111,
-115
+111,
-115
1@@ -30,18 +30,14 @@ typedef struct {
2 Uint8 dat[0x100], ptr;
3 } Stack;
4
5-typedef struct Uxn {
6- Uint8 *ram, dev[0x100];
7- Stack wst, rst;
8-} Uxn;
9-
10 static XImage *ximage;
11 static Display *display;
12 static Window window;
13
14 Uint8 emu_dei(Uint8 addr);
15 void emu_deo(Uint8 addr, Uint8 value);
16-static Uxn uxn;
17+static Uint8 *ram, dev[0x100];
18+static Stack wst, rst;
19
20 /* clang-format off */
21
22@@ -58,47 +54,47 @@ static Uxn uxn;
23 case 0x20|opc: {const int _2=1,_r=0;init body;} break;\
24 case 0x40|opc: {const int _2=0,_r=1;init body;} break;\
25 case 0x60|opc: {const int _2=1,_r=1;init body;} break;\
26- case 0x80|opc: {const int _2=0,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
27- case 0xa0|opc: {const int _2=1,_r=0,k=uxn.wst.ptr;init uxn.wst.ptr=k;body;} break;\
28- case 0xc0|opc: {const int _2=0,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
29- case 0xe0|opc: {const int _2=1,_r=1,k=uxn.rst.ptr;init uxn.rst.ptr=k;body;} break;\
30+ case 0x80|opc: {const int _2=0,_r=0,k=wst.ptr;init wst.ptr=k;body;} break;\
31+ case 0xa0|opc: {const int _2=1,_r=0,k=wst.ptr;init wst.ptr=k;body;} break;\
32+ case 0xc0|opc: {const int _2=0,_r=1,k=rst.ptr;init rst.ptr=k;body;} break;\
33+ case 0xe0|opc: {const int _2=1,_r=1,k=rst.ptr;init rst.ptr=k;body;} break;\
34 }
35
36 /* Microcode */
37
38-#define REM if(_r) uxn.rst.ptr -= 1 + _2; else uxn.wst.ptr -= 1 + _2;
39-#define JMI c = uxn.ram[pc] << 8 | uxn.ram[pc+1], pc += 2;
40+#define REM if(_r) rst.ptr -= 1 + _2; else wst.ptr -= 1 + _2;
41+#define JMI c = ram[pc] << 8 | ram[pc+1], pc += 2;
42 #define JMP(x) { if(_2) pc = x; else pc += (signed char)x; }
43-#define DEC(s) uxn.s.dat[--uxn.s.ptr]
44+#define DEC(s) s.dat[--s.ptr]
45 #define PO1(o) { if(_r) o = DEC(rst); else o = DEC(wst); }
46 #define PO2(o) { PO1(o) if(_r) o |= DEC(rst) << 8; else o |= DEC(wst) << 8; }
47 #define POx(o) { if(_2) PO2(o) else PO1(o) }
48 #define GOT(o) { if(_2) PO1(o[1]) PO1(o[0]) }
49-#define INC(s) uxn.s.dat[uxn.s.ptr++]
50+#define INC(s) s.dat[s.ptr++]
51 #define RP1(i) { if(_r) INC(wst) = i; else INC(rst) = i; }
52 #define PU1(i) { if(_r) INC(rst) = i; else INC(wst) = i; }
53 #define PUx(i) { if(_2) { c = (i); PU1(c >> 8) PU1(c) } else PU1(i) }
54 #define PUT(i) { PU1(i[0]) if(_2) PU1(i[1]) }
55 #define DEI(i,o) o[0] = emu_dei(i); if(_2) o[1] = emu_dei(i + 1); PUT(o)
56 #define DEO(i,j) emu_deo(i, j[0]); if(_2) emu_deo(i + 1, j[1]);
57-#define PEK(i,o,m) o[0] = uxn.ram[i]; if(_2) o[1] = uxn.ram[(i + 1) & m]; PUT(o)
58-#define POK(i,j,m) uxn.ram[i] = j[0]; if(_2) uxn.ram[(i + 1) & m] = j[1];
59+#define PEK(i,o,m) o[0] = ram[i]; if(_2) o[1] = ram[(i + 1) & m]; PUT(o)
60+#define POK(i,j,m) ram[i] = j[0]; if(_2) ram[(i + 1) & m] = j[1];
61
62 int
63 uxn_eval(Uint16 pc)
64 {
65 Uint32 a, b, c, x[2], y[2], z[2], step;
66- if(uxn.dev[0x0f]) return 0;
67+ if(dev[0x0f]) return 0;
68 for(step = 0x80000000; step; step--) {
69- switch(uxn.ram[pc++]) {
70+ switch(ram[pc++]) {
71 /* BRK */ case 0x00: return 1;
72 /* JCI */ case 0x20: if(DEC(wst)) { JMI pc += c; break; } pc += 2; break;
73 /* JMI */ case 0x40: JMI pc += c; break;
74 /* JSI */ case 0x60: JMI INC(rst) = pc >> 8, INC(rst) = pc, pc += c; break;
75- /* LI2 */ case 0xa0: INC(wst) = uxn.ram[pc++]; /* fall-through */
76- /* LIT */ case 0x80: INC(wst) = uxn.ram[pc++]; break;
77- /* L2r */ case 0xe0: INC(rst) = uxn.ram[pc++]; /* fall-through */
78- /* LIr */ case 0xc0: INC(rst) = uxn.ram[pc++]; break;
79+ /* LI2 */ case 0xa0: INC(wst) = ram[pc++]; /* fall-through */
80+ /* LIT */ case 0x80: INC(wst) = ram[pc++]; break;
81+ /* L2r */ case 0xe0: INC(rst) = ram[pc++]; /* fall-through */
82+ /* LIr */ case 0xc0: INC(rst) = ram[pc++]; break;
83 /* INC */ OPC(0x01,POx(a),PUx(a + 1))
84 /* POP */ OPC(0x02,REM ,{})
85 /* NIP */ OPC(0x03,GOT(x) REM ,PUT(x))
86@@ -153,13 +149,13 @@ system_print(char *name, Stack *s)
87 }
88
89 static int
90-system_load(Uint8 *ram, char *rom_path)
91+system_load(char *rom_path)
92 {
93 FILE *f = fopen(rom_path, "rb");
94 if(f) {
95- int i = 0, l = fread(ram, 0x10000 - 0x100, 1, f);
96+ int i = 0, l = fread(ram + 0x100, 0x10000 - 0x100, 1, f);
97 while(l && ++i < RAM_PAGES)
98- l = fread(ram + 0x10000 * i - 0x100, 0x10000, 1, f);
99+ l = fread(ram + 0x100 + 0x10000 * i - 0x100, 0x10000, 1, f);
100 fclose(f);
101 }
102 return !!f;
103@@ -168,10 +164,10 @@ system_load(Uint8 *ram, char *rom_path)
104 static int
105 system_boot(char *rom_path, int has_args)
106 {
107- uxn.ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8));
108+ ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8));
109 system_boot_path = rom_path;
110- uxn.dev[0x17] = has_args;
111- if(uxn.ram && system_load(uxn.ram + 0x100, rom_path))
112+ dev[0x17] = has_args;
113+ if(ram && system_load(rom_path))
114 return uxn_eval(0x100);
115 return 0;
116 }
117@@ -180,10 +176,10 @@ static int
118 system_reboot(int soft)
119 {
120 int i;
121- for(i = 0x0; i < 0x100; i++) uxn.dev[i] = 0;
122- for(i = soft ? 0x100 : 0; i < 0x10000; i++) uxn.ram[i] = 0;
123- uxn.wst.ptr = uxn.rst.ptr = 0;
124- if(system_load(uxn.ram + 0x100, system_boot_path))
125+ for(i = 0x0; i < 0x100; i++) dev[i] = 0;
126+ for(i = soft ? 0x100 : 0; i < 0x10000; i++) ram[i] = 0;
127+ wst.ptr = rst.ptr = 0;
128+ if(system_load(system_boot_path))
129 return uxn_eval(0x100);
130 return 0;
131 }
132@@ -191,26 +187,26 @@ system_reboot(int soft)
133 static void
134 system_expansion(Uint16 addr)
135 {
136- Uint8 *aptr = uxn.ram + addr;
137+ Uint8 *aptr = ram + addr;
138 Uint16 value, length = PEEK2(aptr + 1);
139- if(uxn.ram[addr] == 0x0) {
140+ if(ram[addr] == 0x0) {
141 Uint32 a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
142 Uint32 b = a + length;
143- value = uxn.ram[addr + 7];
144- for(; a < b; uxn.ram[a++] = value);
145- } else if(uxn.ram[addr] == 0x1) {
146+ value = ram[addr + 7];
147+ for(; a < b; ram[a++] = value);
148+ } else if(ram[addr] == 0x1) {
149 Uint32 a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
150 Uint32 b = a + length;
151 Uint32 c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9);
152- for(; a < b; uxn.ram[c++] = uxn.ram[a++]);
153- } else if(uxn.ram[addr] == 0x2) {
154+ for(; a < b; ram[c++] = ram[a++]);
155+ } else if(ram[addr] == 0x2) {
156 Uint32 a = PEEK2(aptr + 3) * 0x10000 + PEEK2(aptr + 5);
157 Uint32 b = a + length;
158 Uint32 c = PEEK2(aptr + 7) * 0x10000 + PEEK2(aptr + 9);
159 Uint32 d = c + length;
160- for(; b >= a; uxn.ram[--d] = uxn.ram[--b]);
161+ for(; b >= a; ram[--d] = ram[--b]);
162 } else
163- fprintf(stderr, "Unknown command: %s\n", &uxn.ram[addr]);
164+ fprintf(stderr, "Unknown command: %s\n", &ram[addr]);
165 }
166
167 /*
168@@ -286,16 +282,16 @@ start_fork_pipe(void)
169 {
170 pid_t pid;
171 pid_t parent_pid = getpid();
172- int addr = PEEK2(&uxn.dev[CMD_ADDR]);
173+ int addr = PEEK2(&dev[CMD_ADDR]);
174 fflush(stdout);
175 if(child_mode & 0x08) {
176- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0x00;
177+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0x00;
178 return;
179 }
180 if(child_mode & 0x01) {
181 /* parent writes to child's stdin */
182 if(pipe(to_child_fd) == -1) {
183- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0xff;
184+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0xff;
185 fprintf(stderr, "Pipe error to child.\n");
186 return;
187 }
188@@ -303,16 +299,16 @@ start_fork_pipe(void)
189 if(child_mode & (0x04 | 0x02)) {
190 /* parent reads from child's stdout and/or stderr */
191 if(pipe(from_child_fd) == -1) {
192- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0xff;
193+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0xff;
194 fprintf(stderr, "Pipe error from child.\n");
195 return;
196 }
197 }
198
199- fork_args[2] = (char *)&uxn.ram[addr];
200+ fork_args[2] = (char *)&ram[addr];
201 pid = fork();
202 if(pid < 0) { /* failure */
203- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0xff;
204+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0xff;
205 fprintf(stderr, "Fork failure.\n");
206 } else if(pid == 0) { /* child */
207
208@@ -339,8 +335,8 @@ start_fork_pipe(void)
209 exit(1);
210 } else { /*parent*/
211 child_pid = pid;
212- uxn.dev[CMD_LIVE] = 0x01;
213- uxn.dev[CMD_EXIT] = 0x00;
214+ dev[CMD_LIVE] = 0x01;
215+ dev[CMD_EXIT] = 0x00;
216 if(child_mode & 0x01) {
217 saved_out = dup(1);
218 dup2(to_child_fd[1], 1);
219@@ -360,12 +356,12 @@ check_child(void)
220 int wstatus;
221 if(child_pid) {
222 if(waitpid(child_pid, &wstatus, WNOHANG)) {
223- uxn.dev[CMD_LIVE] = 0xff;
224- uxn.dev[CMD_EXIT] = WEXITSTATUS(wstatus);
225+ dev[CMD_LIVE] = 0xff;
226+ dev[CMD_EXIT] = WEXITSTATUS(wstatus);
227 clean_after_child();
228 } else {
229- uxn.dev[CMD_LIVE] = 0x01;
230- uxn.dev[CMD_EXIT] = 0x00;
231+ dev[CMD_LIVE] = 0x01;
232+ dev[CMD_EXIT] = 0x00;
233 }
234 }
235 }
236@@ -377,8 +373,8 @@ kill_child(void)
237 if(child_pid) {
238 kill(child_pid, 9);
239 if(waitpid(child_pid, &wstatus, WNOHANG)) {
240- uxn.dev[CMD_LIVE] = 0xff;
241- uxn.dev[CMD_EXIT] = WEXITSTATUS(wstatus);
242+ dev[CMD_LIVE] = 0xff;
243+ dev[CMD_EXIT] = WEXITSTATUS(wstatus);
244 clean_after_child();
245 }
246 }
247@@ -389,7 +385,7 @@ console_start_fork(void)
248 {
249 fflush(stderr);
250 kill_child();
251- child_mode = uxn.dev[CMD_MODE];
252+ child_mode = dev[CMD_MODE];
253 start_fork_pipe();
254 }
255
256@@ -403,7 +399,7 @@ static int
257 console_input(int c, int type)
258 {
259 if(c == EOF) c = 0, type = 4;
260- uxn.dev[0x12] = c, uxn.dev[0x17] = type;
261+ dev[0x12] = c, dev[0x17] = type;
262 if(console_vector) uxn_eval(console_vector);
263 return type != 4;
264 }
265@@ -457,9 +453,9 @@ screen_palette(void)
266 int i, shift, colors[4];
267 for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) {
268 Uint8
269- r = (uxn.dev[0x8 + i / 2] >> shift) & 0xf,
270- g = (uxn.dev[0xa + i / 2] >> shift) & 0xf,
271- b = (uxn.dev[0xc + i / 2] >> shift) & 0xf;
272+ r = (dev[0x8 + i / 2] >> shift) & 0xf,
273+ g = (dev[0xa + i / 2] >> shift) & 0xf,
274+ b = (dev[0xc + i / 2] >> shift) & 0xf;
275 colors[i] = 0x0f000000 | r << 16 | g << 8 | b;
276 colors[i] |= colors[i] << 4;
277 }
278@@ -511,7 +507,7 @@ static int rX, rY, rA, rMX, rMY, rMA, rML, rDX, rDY;
279 static void
280 screen_draw_pixel(void)
281 {
282- int ctrl = uxn.dev[0x2e];
283+ int ctrl = dev[0x2e];
284 int color = ctrl & 0x3;
285 int len = MAR2(uxn_screen.width);
286 Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg;
287@@ -546,7 +542,7 @@ screen_draw_pixel(void)
288 static void
289 screen_draw_sprite(void)
290 {
291- int ctrl = uxn.dev[0x2f];
292+ int ctrl = dev[0x2f];
293 int blend = ctrl & 0xf, opaque = blend % 5;
294 int fx = ctrl & 0x10 ? -1 : 1, fy = ctrl & 0x20 ? -1 : 1;
295 int qfx = fx > 0 ? 7 : 0, qfy = fy < 0 ? 7 : 0;
296@@ -561,7 +557,7 @@ screen_draw_sprite(void)
297 Uint16 xmar = MAR(x), ymar = MAR(y);
298 Uint16 xmar2 = MAR2(x), ymar2 = MAR2(y);
299 if(xmar < wmar && ymar2 < hmar2) {
300- Uint8 *sprite = &uxn.ram[rA];
301+ Uint8 *sprite = &ram[rA];
302 int by = ymar2 * wmar2;
303 for(ay = ymar * wmar2, qy = qfy; ay < by; ay += wmar2, qy += fy) {
304 int ch1 = sprite[qy], ch2 = sprite[qy + 8] << 1, bx = xmar2 + ay;
305@@ -578,7 +574,7 @@ screen_draw_sprite(void)
306 Uint16 xmar = MAR(x), ymar = MAR(y);
307 Uint16 xmar2 = MAR2(x), ymar2 = MAR2(y);
308 if(xmar < wmar && ymar2 < hmar2) {
309- Uint8 *sprite = &uxn.ram[rA];
310+ Uint8 *sprite = &ram[rA];
311 int by = ymar2 * wmar2;
312 for(ay = ymar * wmar2, qy = qfy; ay < by; ay += wmar2, qy += fy) {
313 int ch1 = sprite[qy], bx = xmar2 + ay;
314@@ -612,7 +608,7 @@ static void
315 controller_down(Uint8 mask)
316 {
317 if(mask) {
318- uxn.dev[0x82] |= mask;
319+ dev[0x82] |= mask;
320 if(controller_vector) uxn_eval(controller_vector);
321 }
322 }
323@@ -621,7 +617,7 @@ static void
324 controller_up(Uint8 mask)
325 {
326 if(mask) {
327- uxn.dev[0x82] &= (~mask);
328+ dev[0x82] &= (~mask);
329 if(controller_vector) uxn_eval(controller_vector);
330 }
331 }
332@@ -630,9 +626,9 @@ static void
333 controller_key(Uint8 key)
334 {
335 if(key) {
336- uxn.dev[0x83] = key;
337+ dev[0x83] = key;
338 if(controller_vector) uxn_eval(controller_vector);
339- uxn.dev[0x83] = 0;
340+ dev[0x83] = 0;
341 }
342 }
343
344@@ -644,33 +640,33 @@ static unsigned int mouse_vector;
345 static void
346 mouse_down(Uint8 mask)
347 {
348- uxn.dev[0x96] |= mask;
349+ dev[0x96] |= mask;
350 if(mouse_vector) uxn_eval(mouse_vector);
351 }
352
353 static void
354 mouse_up(Uint8 mask)
355 {
356- uxn.dev[0x96] &= (~mask);
357+ dev[0x96] &= (~mask);
358 if(mouse_vector) uxn_eval(mouse_vector);
359 }
360
361 static void
362 mouse_pos(Uint16 x, Uint16 y)
363 {
364- uxn.dev[0x92] = x >> 8, uxn.dev[0x93] = x;
365- uxn.dev[0x94] = y >> 8, uxn.dev[0x95] = y;
366+ dev[0x92] = x >> 8, dev[0x93] = x;
367+ dev[0x94] = y >> 8, dev[0x95] = y;
368 if(mouse_vector) uxn_eval(mouse_vector);
369 }
370
371 static void
372 mouse_scroll(Uint16 x, Uint16 y)
373 {
374- uxn.dev[0x9a] = x >> 8, uxn.dev[0x9b] = x;
375- uxn.dev[0x9c] = -y >> 8, uxn.dev[0x9d] = -y;
376+ dev[0x9a] = x >> 8, dev[0x9b] = x;
377+ dev[0x9c] = -y >> 8, dev[0x9d] = -y;
378 if(mouse_vector) uxn_eval(mouse_vector);
379- uxn.dev[0x9a] = 0, uxn.dev[0x9b] = 0;
380- uxn.dev[0x9c] = 0, uxn.dev[0x9d] = 0;
381+ dev[0x9a] = 0, dev[0x9b] = 0;
382+ dev[0x9c] = 0, dev[0x9d] = 0;
383 }
384
385 /*
386@@ -822,7 +818,7 @@ static int
387 file_init(int id, Uint16 addr)
388 {
389 file_reset(id);
390- ufs[id].filepath = (char *)&uxn.ram[addr];
391+ ufs[id].filepath = (char *)&ram[addr];
392 return 0;
393 }
394
395@@ -839,7 +835,7 @@ file_not_ready(int id)
396 static int
397 file_read(int id, Uint16 addr, int len)
398 {
399- void *dest = &uxn.ram[addr];
400+ void *dest = &ram[addr];
401 if(file_not_ready(id))
402 return 0;
403 if(ufs[id].state != FILE_READ && ufs[id].state != DIR_READ) {
404@@ -871,7 +867,7 @@ file_write(int id, Uint16 addr, int len, Uint8 flags)
405 ufs[id].state = FILE_WRITE;
406 }
407 if(ufs[id].state == FILE_WRITE)
408- if((ret = fwrite(&uxn.ram[addr], 1, len, ufs[id].f)) > 0 && fflush(ufs[id].f) != 0)
409+ if((ret = fwrite(&ram[addr], 1, len, ufs[id].f)) > 0 && fflush(ufs[id].f) != 0)
410 ret = 0;
411 if(ufs[id].state == DIR_WRITE)
412 ret = is_dir_real(ufs[id].filepath);
413@@ -887,7 +883,7 @@ file_stat(int id, Uint16 addr, int len)
414 return 0;
415 err = stat(ufs[id].filepath, &st);
416 dir = S_ISDIR(st.st_mode);
417- return put_stat(&uxn.ram[addr], len, st.st_size, err, dir, 0);
418+ return put_stat(&ram[addr], len, st.st_size, err, dir, 0);
419 }
420
421 static int
422@@ -901,7 +897,7 @@ file_delete(int id)
423 static void
424 file_success(int port, int value)
425 {
426- POKE2(&uxn.dev[port], value);
427+ POKE2(&dev[port], value);
428 }
429
430 /* file registers */
431@@ -932,7 +928,7 @@ datetime_dei(Uint8 addr)
432 case 0xc8: return t->tm_yday >> 8;
433 case 0xc9: return t->tm_yday;
434 case 0xca: return t->tm_isdst;
435- default: return uxn.dev[addr];
436+ default: return dev[addr];
437 }
438 }
439
440@@ -946,8 +942,8 @@ emu_dei(Uint8 addr)
441 {
442 switch(addr) {
443 /* System */
444- case 0x04: return uxn.wst.ptr;
445- case 0x05: return uxn.rst.ptr;
446+ case 0x04: return wst.ptr;
447+ case 0x05: return rst.ptr;
448 /* Console */
449 case CMD_LIVE:
450 case CMD_EXIT: check_child(); break;
451@@ -965,61 +961,61 @@ emu_dei(Uint8 addr)
452 }
453 if((addr & 0xf0) == 0xc0)
454 return datetime_dei(addr);
455- return uxn.dev[addr];
456+ return dev[addr];
457 }
458
459 void
460 emu_deo(Uint8 addr, Uint8 value)
461 {
462- uxn.dev[addr] = value;
463+ dev[addr] = value;
464 switch(addr) {
465 /* System */
466- case 0x03: system_expansion(PEEK2(uxn.dev + 2)); return;
467- case 0x04: uxn.wst.ptr = uxn.dev[4]; return;
468- case 0x05: uxn.rst.ptr = uxn.dev[5]; return;
469+ case 0x03: system_expansion(PEEK2(dev + 2)); return;
470+ case 0x04: wst.ptr = dev[4]; return;
471+ case 0x05: rst.ptr = dev[5]; return;
472 case 0x08:
473 case 0x09:
474 case 0x0a:
475 case 0x0b:
476 case 0x0c:
477 case 0x0d: screen_palette(); return;
478- case 0x0e: system_print("WST", &uxn.wst), system_print("RST", &uxn.rst); return;
479+ case 0x0e: system_print("WST", &wst), system_print("RST", &rst); return;
480 /* Console */
481- case 0x11: console_vector = PEEK2(&uxn.dev[0x10]); return;
482- case 0x18: fputc(uxn.dev[0x18], stdout), fflush(stdout); return;
483- case 0x19: fputc(uxn.dev[0x19], stderr), fflush(stderr); return;
484+ case 0x11: console_vector = PEEK2(&dev[0x10]); return;
485+ case 0x18: fputc(dev[0x18], stdout), fflush(stdout); return;
486+ case 0x19: fputc(dev[0x19], stderr), fflush(stderr); return;
487 case 0x1f: console_start_fork(); return;
488 /* Screen */
489- case 0x21: screen_vector = PEEK2(&uxn.dev[0x20]); return;
490- case 0x23: screen_apply(PEEK2(&uxn.dev[0x22]), uxn_screen.height); return;
491- case 0x25: screen_apply(uxn_screen.width, PEEK2(&uxn.dev[0x24])); return;
492- case 0x26: rMX = uxn.dev[0x26] & 0x1, rMY = uxn.dev[0x26] & 0x2, rMA = uxn.dev[0x26] & 0x4, rML = uxn.dev[0x26] >> 4, rDX = rMX << 3, rDY = rMY << 2; return;
493+ case 0x21: screen_vector = PEEK2(&dev[0x20]); return;
494+ case 0x23: screen_apply(PEEK2(&dev[0x22]), uxn_screen.height); return;
495+ case 0x25: screen_apply(uxn_screen.width, PEEK2(&dev[0x24])); return;
496+ case 0x26: rMX = dev[0x26] & 0x1, rMY = dev[0x26] & 0x2, rMA = dev[0x26] & 0x4, rML = dev[0x26] >> 4, rDX = rMX << 3, rDY = rMY << 2; return;
497 case 0x28:
498- case 0x29: rX = (uxn.dev[0x28] << 8) | uxn.dev[0x29], rX = twos(rX); return;
499+ case 0x29: rX = (dev[0x28] << 8) | dev[0x29], rX = twos(rX); return;
500 case 0x2a:
501- case 0x2b: rY = (uxn.dev[0x2a] << 8) | uxn.dev[0x2b], rY = twos(rY); return;
502+ case 0x2b: rY = (dev[0x2a] << 8) | dev[0x2b], rY = twos(rY); return;
503 case 0x2c:
504- case 0x2d: rA = (uxn.dev[0x2c] << 8) | uxn.dev[0x2d]; return;
505+ case 0x2d: rA = (dev[0x2c] << 8) | dev[0x2d]; return;
506 case 0x2e: screen_draw_pixel(); return;
507 case 0x2f: screen_draw_sprite(); return;
508 /* Controller */
509- case 0x81: controller_vector = PEEK2(&uxn.dev[0x80]); return;
510+ case 0x81: controller_vector = PEEK2(&dev[0x80]); return;
511 /* Mouse */
512- case 0x91: mouse_vector = PEEK2(&uxn.dev[0x90]); return;
513+ case 0x91: mouse_vector = PEEK2(&dev[0x90]); return;
514 /* File 1 */
515- case 0xab: rL1 = PEEK2(&uxn.dev[0xaa]); return;
516- case 0xa5: file_success(0xa2, file_stat(0, PEEK2(&uxn.dev[0xa4]), rL1)); return;
517+ case 0xab: rL1 = PEEK2(&dev[0xaa]); return;
518+ case 0xa5: file_success(0xa2, file_stat(0, PEEK2(&dev[0xa4]), rL1)); return;
519 case 0xa6: file_success(0xa2, file_delete(0)); return;
520- case 0xa9: file_success(0xa2, file_init(0, PEEK2(&uxn.dev[0xa8]))); return;
521- case 0xad: file_success(0xa2, file_read(0, PEEK2(&uxn.dev[0xac]), rL1)); return;
522- case 0xaf: file_success(0xa2, file_write(0, PEEK2(&uxn.dev[0xae]), rL1, uxn.dev[0xa7])); return;
523+ case 0xa9: file_success(0xa2, file_init(0, PEEK2(&dev[0xa8]))); return;
524+ case 0xad: file_success(0xa2, file_read(0, PEEK2(&dev[0xac]), rL1)); return;
525+ case 0xaf: file_success(0xa2, file_write(0, PEEK2(&dev[0xae]), rL1, dev[0xa7])); return;
526 /* File 2 */
527- case 0xbb: rL2 = PEEK2(&uxn.dev[0xba]); return;
528- case 0xb5: file_success(0xb2, file_stat(1, PEEK2(&uxn.dev[0xb4]), rL2)); return;
529+ case 0xbb: rL2 = PEEK2(&dev[0xba]); return;
530+ case 0xb5: file_success(0xb2, file_stat(1, PEEK2(&dev[0xb4]), rL2)); return;
531 case 0xb6: file_success(0xb2, file_delete(1)); return;
532- case 0xb9: file_success(0xb2, file_init(1, PEEK2(&uxn.dev[0xb8]))); return;
533- case 0xbd: file_success(0xb2, file_read(1, PEEK2(&uxn.dev[0xbc]), rL2)); return;
534- case 0xbf: file_success(0xb2, file_write(1, PEEK2(&uxn.dev[0xbe]), rL2, uxn.dev[0xb7])); return;
535+ case 0xb9: file_success(0xb2, file_init(1, PEEK2(&dev[0xb8]))); return;
536+ case 0xbd: file_success(0xb2, file_read(1, PEEK2(&dev[0xbc]), rL2)); return;
537+ case 0xbf: file_success(0xb2, file_write(1, PEEK2(&dev[0xbe]), rL2, dev[0xb7])); return;
538 }
539 }
540
541@@ -1094,7 +1090,7 @@ emu_event(void)
542 screen_change(0, 0, 9000, 9000);
543 break;
544 case ClientMessage:
545- uxn.dev[0x0f] = 0x80;
546+ dev[0x0f] = 0x80;
547 break;
548 case KeyPress: {
549 KeySym sym;
550@@ -1198,7 +1194,7 @@ emu_run(void)
551 fds[2].fd = STDIN_FILENO;
552 fds[0].events = fds[1].events = fds[2].events = POLLIN;
553 /* main loop */
554- while(!uxn.dev[0x0f]) {
555+ while(!dev[0x0f]) {
556 if(poll(fds, 3, 1000) <= 0)
557 continue;
558 while(XPending(display))
559@@ -1244,5 +1240,5 @@ main(int argc, char **argv)
560 emu_run();
561 console_close();
562 XDestroyImage(ximage), XDestroyWindow(display, window), XCloseDisplay(display);
563- return uxn.dev[0x0f] & 0x7f;
564+ return dev[0x0f] & 0x7f;
565 }