commit e00870a
Devine Lu Linvega
·
2026-02-11 16:41:04 +0000 UTC
parent a0c384b
Undid the uxn struct
1 files changed,
+110,
-114
+110,
-114
1@@ -27,18 +27,14 @@ typedef unsigned char Uint8;
2 typedef unsigned short Uint16;
3 typedef void (*deo_handler)(void);
4 typedef Uint8 (*dei_handler)(void);
5-typedef struct {
6- Uint8 *ram, dev[0x100], stk[2][0x100], ptr[2];
7-} Uxn;
8
9-static Uxn uxn;
10 static Display *emu_dpy;
11 static Window emu_win;
12 static XImage *emu_img;
13 static int emu_x11;
14 static int emu_timer;
15 static unsigned int uxn_eval(Uint16 pc);
16-
17+static Uint8 *ram, dev[0x100], stk[2][0x100], ptr[2];
18 static int console_vector, screen_vector, controller_vector, mouse_vector;
19 static int rX, rY, rA, rMX, rMY, rMA, rML, rDX, rDY, rL1, rL2;
20
21@@ -66,10 +62,10 @@ static void
22 system_print(char *name, int r)
23 {
24 Uint8 i;
25- fprintf(stderr, "%s%c", name, uxn.ptr[r] - 8 ? ' ' : '|');
26- for(i = uxn.ptr[r] - 8; i != uxn.ptr[r]; i++)
27- fprintf(stderr, "%02x%c", uxn.stk[r][i], i == 0xff ? '|' : ' ');
28- fprintf(stderr, "<%02x\n", uxn.ptr[r]);
29+ fprintf(stderr, "%s%c", name, ptr[r] - 8 ? ' ' : '|');
30+ for(i = ptr[r] - 8; i != ptr[r]; i++)
31+ fprintf(stderr, "%02x%c", stk[r][i], i == 0xff ? '|' : ' ');
32+ fprintf(stderr, "<%02x\n", ptr[r]);
33 }
34
35 static unsigned int
36@@ -77,9 +73,9 @@ system_load(const char *rom_path)
37 {
38 FILE *f = fopen(rom_path, "rb");
39 if(f) {
40- unsigned int i = 0, l = fread(uxn.ram + 0x100, 0x10000 - 0x100, 1, f);
41+ unsigned int i = 0, l = fread(ram + 0x100, 0x10000 - 0x100, 1, f);
42 while(l && ++i < BANKS)
43- l = fread(uxn.ram + i * 0x10000, 0x10000, 1, f);
44+ l = fread(ram + i * 0x10000, 0x10000, 1, f);
45 fclose(f);
46 }
47 return !!f;
48@@ -88,23 +84,23 @@ system_load(const char *rom_path)
49 static unsigned int
50 system_boot(char *rom_path, const unsigned int has_args)
51 {
52- uxn.ram = (Uint8 *)calloc(BANKS_CAP, sizeof(Uint8));
53+ ram = (Uint8 *)calloc(BANKS_CAP, sizeof(Uint8));
54 system_boot_path = rom_path;
55- uxn.dev[0x17] = has_args;
56- return uxn.ram && system_load(rom_path);
57+ dev[0x17] = has_args;
58+ return ram && system_load(rom_path);
59 }
60
61 static unsigned int
62 system_reboot(const unsigned int soft)
63 {
64- memset(uxn.dev, 0, 0x100);
65- memset(uxn.stk[0], 0, 0x100);
66- memset(uxn.stk[1], 0, 0x100);
67+ memset(dev, 0, 0x100);
68+ memset(stk[0], 0, 0x100);
69+ memset(stk[1], 0, 0x100);
70 if(soft)
71- memset(uxn.ram + 0x100, 0, 0xff00);
72+ memset(ram + 0x100, 0, 0xff00);
73 else
74- memset(uxn.ram, 0, 0x10000);
75- uxn.ptr[0] = uxn.ptr[1] = 0;
76+ memset(ram, 0, 0x10000);
77+ ptr[0] = ptr[1] = 0;
78 console_vector = screen_vector = controller_vector = mouse_vector = 0;
79 rX = rY = rA = rMX = rMY = rMA = rML = rDX = rDY = rL1 = rL2 = 0;
80 return system_load(system_boot_path);
81@@ -113,29 +109,29 @@ system_reboot(const unsigned int soft)
82 static void
83 system_deo_expansion(void)
84 {
85- const Uint16 exp = peek2(uxn.dev + 2);
86- Uint8 *aptr = uxn.ram + exp;
87+ const Uint16 exp = peek2(dev + 2);
88+ Uint8 *aptr = ram + exp;
89 Uint16 length = peek2(aptr + 1);
90 unsigned int bank = peek2(aptr + 3) * 0x10000;
91 unsigned int addr = peek2(aptr + 5);
92- if(uxn.ram[exp] == 0x0) {
93+ if(ram[exp] == 0x0) {
94 if(bank < BANKS_CAP)
95- memset(uxn.ram + bank + addr, uxn.ram[exp + 7], length);
96- } else if(uxn.ram[exp] == 1 || uxn.ram[exp] == 2) {
97+ memset(ram + bank + addr, ram[exp + 7], length);
98+ } else if(ram[exp] == 1 || ram[exp] == 2) {
99 unsigned int dst_bank = peek2(aptr + 7) * 0x10000;
100 unsigned int dst_addr = peek2(aptr + 9);
101 if(bank < BANKS_CAP && dst_bank < BANKS_CAP)
102- memmove(uxn.ram + dst_bank + dst_addr, uxn.ram + bank + addr, length);
103+ memmove(ram + dst_bank + dst_addr, ram + bank + addr, length);
104 } else
105- fprintf(stderr, "Unknown command: %s\n", &uxn.ram[exp]);
106+ fprintf(stderr, "Unknown command: %s\n", &ram[exp]);
107 }
108
109 /* clang-format off */
110
111-static Uint8 system_dei_wst(void) { return uxn.ptr[0]; }
112-static Uint8 system_dei_rst(void) { return uxn.ptr[1]; }
113-static void system_deo_wst(void) { uxn.ptr[0] = uxn.dev[4]; }
114-static void system_deo_rst(void) { uxn.ptr[1] = uxn.dev[5]; }
115+static Uint8 system_dei_wst(void) { return ptr[0]; }
116+static Uint8 system_dei_rst(void) { return ptr[1]; }
117+static void system_deo_wst(void) { ptr[0] = dev[4]; }
118+static void system_deo_rst(void) { ptr[1] = dev[5]; }
119 static void system_deo_print(void) { system_print("WST", 0), system_print("RST", 1); }
120
121 /* clang-format on */
122@@ -152,7 +148,7 @@ static unsigned int
123 console_input(int c, unsigned int type)
124 {
125 if(c == EOF) c = 0, type = CONSOLE_END;
126- uxn.dev[0x12] = c, uxn.dev[0x17] = type;
127+ dev[0x12] = c, dev[0x17] = type;
128 if(console_vector) uxn_eval(console_vector);
129 return type != CONSOLE_END;
130 }
131@@ -220,16 +216,16 @@ start_fork_pipe(void)
132 {
133 pid_t pid;
134 pid_t parent_pid = getpid();
135- int addr = peek2(&uxn.dev[CMD_ADDR]);
136+ int addr = peek2(&dev[CMD_ADDR]);
137 fflush(stdout);
138 if(child_mode & 0x08) {
139- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0x00;
140+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0x00;
141 return;
142 }
143 if(child_mode & 0x01) {
144 /* parent writes to child's stdin */
145 if(pipe(to_child_fd) == -1) {
146- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0xff;
147+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0xff;
148 fprintf(stderr, "Pipe error to child.\n");
149 return;
150 }
151@@ -237,16 +233,16 @@ start_fork_pipe(void)
152 if(child_mode & (0x04 | 0x02)) {
153 /* parent reads from child's stdout and/or stderr */
154 if(pipe(from_child_fd) == -1) {
155- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0xff;
156+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0xff;
157 fprintf(stderr, "Pipe error from child.\n");
158 return;
159 }
160 }
161
162- fork_args[2] = (char *)&uxn.ram[addr];
163+ fork_args[2] = (char *)&ram[addr];
164 pid = fork();
165 if(pid < 0) { /* failure */
166- uxn.dev[CMD_EXIT] = uxn.dev[CMD_LIVE] = 0xff;
167+ dev[CMD_EXIT] = dev[CMD_LIVE] = 0xff;
168 fprintf(stderr, "Fork failure.\n");
169 } else if(pid == 0) { /* child */
170
171@@ -273,8 +269,8 @@ start_fork_pipe(void)
172 exit(1);
173 } else { /*parent*/
174 child_pid = pid;
175- uxn.dev[CMD_LIVE] = 0x01;
176- uxn.dev[CMD_EXIT] = 0x00;
177+ dev[CMD_LIVE] = 0x01;
178+ dev[CMD_EXIT] = 0x00;
179 if(child_mode & 0x01) {
180 saved_out = dup(1);
181 dup2(to_child_fd[1], 1);
182@@ -294,12 +290,12 @@ check_child(void)
183 int wstatus;
184 if(child_pid) {
185 if(waitpid(child_pid, &wstatus, WNOHANG)) {
186- uxn.dev[CMD_LIVE] = 0xff;
187- uxn.dev[CMD_EXIT] = WEXITSTATUS(wstatus);
188+ dev[CMD_LIVE] = 0xff;
189+ dev[CMD_EXIT] = WEXITSTATUS(wstatus);
190 clean_after_child();
191 } else {
192- uxn.dev[CMD_LIVE] = 0x01;
193- uxn.dev[CMD_EXIT] = 0x00;
194+ dev[CMD_LIVE] = 0x01;
195+ dev[CMD_EXIT] = 0x00;
196 }
197 }
198 }
199@@ -311,8 +307,8 @@ kill_child(void)
200 if(child_pid) {
201 kill(child_pid, 9);
202 if(waitpid(child_pid, &wstatus, WNOHANG)) {
203- uxn.dev[CMD_LIVE] = 0xff;
204- uxn.dev[CMD_EXIT] = WEXITSTATUS(wstatus);
205+ dev[CMD_LIVE] = 0xff;
206+ dev[CMD_EXIT] = WEXITSTATUS(wstatus);
207 clean_after_child();
208 }
209 }
210@@ -323,7 +319,7 @@ console_deo_fork(void)
211 {
212 fflush(stderr);
213 kill_child();
214- child_mode = uxn.dev[CMD_MODE];
215+ child_mode = dev[CMD_MODE];
216 start_fork_pipe();
217 }
218
219@@ -335,13 +331,13 @@ console_close(void)
220
221 /* clang-format off */
222
223-static Uint8 console_dei_childlive(void) { check_child(); return uxn.dev[CMD_LIVE]; }
224-static Uint8 console_dei_childexit(void) { check_child(); return uxn.dev[CMD_EXIT]; }
225-static void console_deo_vector(void) { console_vector = peek2(&uxn.dev[0x10]); }
226-static void console_deo_stdout(void) { fputc(uxn.dev[0x18], stdout), fflush(stdout); }
227-static void console_deo_stderr(void) { fputc(uxn.dev[0x19], stderr), fflush(stderr); }
228-static void console_deo_hb(void) { fprintf(stderr, "%02x", uxn.dev[0x1a]); }
229-static void console_deo_lb(void) { fprintf(stderr, "%02x", uxn.dev[0x1b]); }
230+static Uint8 console_dei_childlive(void) { check_child(); return dev[CMD_LIVE]; }
231+static Uint8 console_dei_childexit(void) { check_child(); return dev[CMD_EXIT]; }
232+static void console_deo_vector(void) { console_vector = peek2(&dev[0x10]); }
233+static void console_deo_stdout(void) { fputc(dev[0x18], stdout), fflush(stdout); }
234+static void console_deo_stderr(void) { fputc(dev[0x19], stderr), fflush(stderr); }
235+static void console_deo_hb(void) { fprintf(stderr, "%02x", dev[0x1a]); }
236+static void console_deo_lb(void) { fprintf(stderr, "%02x", dev[0x1b]); }
237
238 /* clang-format on */
239
240@@ -389,9 +385,9 @@ system_deo_colorize(void)
241 unsigned int i, shift, colors[4];
242 for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) {
243 Uint8
244- r = uxn.dev[0x8 + i / 2] >> shift & 0xf,
245- g = uxn.dev[0xa + i / 2] >> shift & 0xf,
246- b = uxn.dev[0xc + i / 2] >> shift & 0xf;
247+ r = dev[0x8 + i / 2] >> shift & 0xf,
248+ g = dev[0xa + i / 2] >> shift & 0xf,
249+ b = dev[0xc + i / 2] >> shift & 0xf;
250 colors[i] = 0x0f000000 | r << 16 | g << 8 | b;
251 colors[i] |= colors[i] << 4;
252 }
253@@ -406,9 +402,9 @@ screen_resize(int width, int height)
254 if(width != screen_width || height != screen_height) {
255 int length;
256 screen_width = width, screen_wmar2 = width + 0x10;
257- uxn.dev[0x22] = screen_width >> 8, uxn.dev[0x23] = screen_width;
258+ dev[0x22] = screen_width >> 8, dev[0x23] = screen_width;
259 screen_height = height, screen_hmar2 = height + 0x10;
260- uxn.dev[0x24] = screen_height >> 8, uxn.dev[0x25] = screen_height;
261+ dev[0x24] = screen_height >> 8, dev[0x25] = screen_height;
262 length = screen_wmar2 * screen_hmar2;
263 screen_layers = realloc(screen_layers, length);
264 memset(screen_layers, 0, length);
265@@ -484,7 +480,7 @@ screen_update(void)
266 static void
267 screen_deo_pixel(void)
268 {
269- const int ctrl = uxn.dev[0x2e];
270+ const int ctrl = dev[0x2e];
271 const int hi = ctrl & 0x40;
272 const Uint8 mask = hi ? 0x3 : 0xc;
273 const Uint8 color = hi ? ((ctrl & 0x3) << 2) : (ctrl & 0x3);
274@@ -523,7 +519,7 @@ static void
275 screen_deo_sprite(void)
276 {
277 int i, j, x = rX, y = rY;
278- const int ctrl = uxn.dev[0x2f];
279+ const int ctrl = dev[0x2f];
280 const int flipx = ctrl & 0x10, flipy = ctrl & 0x20;
281 const int dx = flipx ? -rDY : rDY, dy = flipy ? -rDX : rDX;
282 const int row_start = flipx ? 0 : 7, row_delta = flipx ? 1 : -1;
283@@ -539,7 +535,7 @@ screen_deo_sprite(void)
284 const Uint16 x0 = x + 8, y0 = y + 8;
285 if(x0 + 8 >= stride || y0 + 8 >= screen_hmar2) continue;
286 Uint8 *dst = screen_layers + y0 * stride + x0;
287- const Uint8 *col = &uxn.ram[rA + col_start];
288+ const Uint8 *col = &ram[rA + col_start];
289 for(j = 0; j < 8; j++, dst += stride, col += col_delta) {
290 Uint8 *d = dst;
291 const int ch1 = *col, ch2 = is_2bpp ? col[8] : 0;
292@@ -567,13 +563,13 @@ static Uint8 screen_dei_ryhb(void) { return rY >> 8; }
293 static Uint8 screen_dei_rylb(void) { return rY; }
294 static Uint8 screen_dei_rahb(void) { return rA >> 8; }
295 static Uint8 screen_dei_ralb(void) { return rA; }
296-static void screen_deo_vector(void) { screen_vector = peek2(&uxn.dev[0x20]); }
297-static void screen_deo_width(void) { screen_resize(peek2(&uxn.dev[0x22]) & 0xfff, screen_height & 0xfff); }
298-static void screen_deo_height(void) { screen_resize(screen_width & 0xfff, peek2(&uxn.dev[0x24]) & 0xfff); }
299-static void screen_deo_auto(void) { 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; }
300-static void screen_deo_x(void) { rX = (uxn.dev[0x28] << 8) | uxn.dev[0x29], rX = TWOS(rX); }
301-static void screen_deo_y(void) { rY = (uxn.dev[0x2a] << 8) | uxn.dev[0x2b], rY = TWOS(rY); }
302-static void screen_deo_addr(void) { rA = (uxn.dev[0x2c] << 8) | uxn.dev[0x2d]; }
303+static void screen_deo_vector(void) { screen_vector = peek2(&dev[0x20]); }
304+static void screen_deo_width(void) { screen_resize(peek2(&dev[0x22]) & 0xfff, screen_height & 0xfff); }
305+static void screen_deo_height(void) { screen_resize(screen_width & 0xfff, peek2(&dev[0x24]) & 0xfff); }
306+static void screen_deo_auto(void) { rMX = dev[0x26] & 0x1, rMY = dev[0x26] & 0x2, rMA = dev[0x26] & 0x4, rML = dev[0x26] >> 4, rDX = rMX << 3, rDY = rMY << 2; }
307+static void screen_deo_x(void) { rX = (dev[0x28] << 8) | dev[0x29], rX = TWOS(rX); }
308+static void screen_deo_y(void) { rY = (dev[0x2a] << 8) | dev[0x2b], rY = TWOS(rY); }
309+static void screen_deo_addr(void) { rA = (dev[0x2c] << 8) | dev[0x2d]; }
310
311 /* clang-format on */
312
313@@ -584,7 +580,7 @@ static void
314 controller_down(Uint8 mask)
315 {
316 if(mask) {
317- uxn.dev[0x82] |= mask;
318+ dev[0x82] |= mask;
319 if(controller_vector) uxn_eval(controller_vector);
320 }
321 }
322@@ -593,7 +589,7 @@ static void
323 controller_up(Uint8 mask)
324 {
325 if(mask) {
326- uxn.dev[0x82] &= (~mask);
327+ dev[0x82] &= (~mask);
328 if(controller_vector) uxn_eval(controller_vector);
329 }
330 }
331@@ -602,16 +598,16 @@ static void
332 controller_key(Uint8 key)
333 {
334 if(key) {
335- uxn.dev[0x83] = key;
336+ dev[0x83] = key;
337 if(controller_vector) uxn_eval(controller_vector);
338- uxn.dev[0x83] = 0;
339+ dev[0x83] = 0;
340 }
341 }
342
343 void
344 controller_deo_vector(void)
345 {
346- controller_vector = peek2(&uxn.dev[0x80]);
347+ controller_vector = peek2(&dev[0x80]);
348 }
349
350 /*
351@@ -620,39 +616,39 @@ controller_deo_vector(void)
352 static void
353 mouse_down(Uint8 mask)
354 {
355- uxn.dev[0x96] |= mask;
356+ dev[0x96] |= mask;
357 if(mouse_vector) uxn_eval(mouse_vector);
358 }
359
360 static void
361 mouse_up(Uint8 mask)
362 {
363- uxn.dev[0x96] &= (~mask);
364+ dev[0x96] &= (~mask);
365 if(mouse_vector) uxn_eval(mouse_vector);
366 }
367
368 static void
369 mouse_pos(Uint16 x, Uint16 y)
370 {
371- uxn.dev[0x92] = x >> 8, uxn.dev[0x93] = x;
372- uxn.dev[0x94] = y >> 8, uxn.dev[0x95] = y;
373+ dev[0x92] = x >> 8, dev[0x93] = x;
374+ dev[0x94] = y >> 8, dev[0x95] = y;
375 if(mouse_vector) uxn_eval(mouse_vector);
376 }
377
378 static void
379 mouse_scroll(Uint16 x, Uint16 y)
380 {
381- uxn.dev[0x9a] = x >> 8, uxn.dev[0x9b] = x;
382- uxn.dev[0x9c] = -y >> 8, uxn.dev[0x9d] = -y;
383+ dev[0x9a] = x >> 8, dev[0x9b] = x;
384+ dev[0x9c] = -y >> 8, dev[0x9d] = -y;
385 if(mouse_vector) uxn_eval(mouse_vector);
386- uxn.dev[0x9a] = 0, uxn.dev[0x9b] = 0;
387- uxn.dev[0x9c] = 0, uxn.dev[0x9d] = 0;
388+ dev[0x9a] = 0, dev[0x9b] = 0;
389+ dev[0x9c] = 0, dev[0x9d] = 0;
390 }
391
392 void
393 mouse_deo_vector(void)
394 {
395- mouse_vector = peek2(&uxn.dev[0x90]);
396+ mouse_vector = peek2(&dev[0x90]);
397 }
398
399 /*
400@@ -800,7 +796,7 @@ static unsigned int
401 file_init(unsigned int id, Uint16 addr)
402 {
403 file_reset(id);
404- ufs[id].filepath = (char *)&uxn.ram[addr];
405+ ufs[id].filepath = (char *)&ram[addr];
406 return 0;
407 }
408
409@@ -813,7 +809,7 @@ file_not_ready(unsigned int id)
410 static unsigned int
411 file_read(unsigned int id, Uint16 addr, unsigned int len)
412 {
413- void *dest = &uxn.ram[addr];
414+ void *dest = &ram[addr];
415 struct stat st;
416 unsigned int n;
417 if(file_not_ready(id))
418@@ -859,7 +855,7 @@ file_write(unsigned int id, Uint16 addr, unsigned int len, Uint8 flags)
419 ufs[id].state = FILE_WRITE;
420 }
421 if(ufs[id].state == FILE_WRITE)
422- if((ret = fwrite(&uxn.ram[addr], 1, len, ufs[id].f)) > 0 && fflush(ufs[id].f) != 0)
423+ if((ret = fwrite(&ram[addr], 1, len, ufs[id].f)) > 0 && fflush(ufs[id].f) != 0)
424 ret = 0;
425 if(ufs[id].state == DIR_WRITE)
426 ret = is_dir_real(ufs[id].filepath);
427@@ -877,7 +873,7 @@ file_stat(unsigned int id, Uint16 addr, unsigned int len)
428 len = 0x10000 - addr;
429 err = stat(ufs[id].filepath, &st);
430 dir = S_ISDIR(st.st_mode);
431- return put_stat(&uxn.ram[addr], len, st.st_size, err, dir, 0);
432+ return put_stat(&ram[addr], len, st.st_size, err, dir, 0);
433 }
434
435 static unsigned int
436@@ -890,18 +886,18 @@ file_delete(unsigned int id)
437
438 /* clang-format off */
439
440-static void filea_deo_stat(void) { poke2(&uxn.dev[0xa2], file_stat(0, peek2(&uxn.dev[0xa4]), rL1)); }
441-static void filea_deo_delete(void) { poke2(&uxn.dev[0xa2], file_delete(0)); }
442-static void filea_deo_name(void) { poke2(&uxn.dev[0xa2], file_init(0, peek2(&uxn.dev[0xa8]))); }
443-static void filea_deo_length(void) { rL1 = peek2(&uxn.dev[0xaa]); }
444-static void filea_deo_read(void) { poke2(&uxn.dev[0xa2], file_read(0, peek2(&uxn.dev[0xac]), rL1)); }
445-static void filea_deo_write(void) { poke2(&uxn.dev[0xa2], file_write(0, peek2(&uxn.dev[0xae]), rL1, uxn.dev[0xa7])); }
446-static void fileb_deo_stat(void) { poke2(&uxn.dev[0xb2], file_stat(1, peek2(&uxn.dev[0xb4]), rL2)); }
447-static void fileb_deo_delete(void) { poke2(&uxn.dev[0xb2], file_delete(1)); }
448-static void fileb_deo_name(void) { poke2(&uxn.dev[0xb2], file_init(1, peek2(&uxn.dev[0xb8]))); }
449-static void fileb_deo_length(void) { rL2 = peek2(&uxn.dev[0xba]); }
450-static void fileb_deo_read(void) { poke2(&uxn.dev[0xb2], file_read(1, peek2(&uxn.dev[0xbc]), rL2)); }
451-static void fileb_deo_write(void) { poke2(&uxn.dev[0xb2], file_write(1, peek2(&uxn.dev[0xbe]), rL2, uxn.dev[0xb7])); }
452+static void filea_deo_stat(void) { poke2(&dev[0xa2], file_stat(0, peek2(&dev[0xa4]), rL1)); }
453+static void filea_deo_delete(void) { poke2(&dev[0xa2], file_delete(0)); }
454+static void filea_deo_name(void) { poke2(&dev[0xa2], file_init(0, peek2(&dev[0xa8]))); }
455+static void filea_deo_length(void) { rL1 = peek2(&dev[0xaa]); }
456+static void filea_deo_read(void) { poke2(&dev[0xa2], file_read(0, peek2(&dev[0xac]), rL1)); }
457+static void filea_deo_write(void) { poke2(&dev[0xa2], file_write(0, peek2(&dev[0xae]), rL1, dev[0xa7])); }
458+static void fileb_deo_stat(void) { poke2(&dev[0xb2], file_stat(1, peek2(&dev[0xb4]), rL2)); }
459+static void fileb_deo_delete(void) { poke2(&dev[0xb2], file_delete(1)); }
460+static void fileb_deo_name(void) { poke2(&dev[0xb2], file_init(1, peek2(&dev[0xb8]))); }
461+static void fileb_deo_length(void) { rL2 = peek2(&dev[0xba]); }
462+static void fileb_deo_read(void) { poke2(&dev[0xb2], file_read(1, peek2(&dev[0xbc]), rL2)); }
463+static void fileb_deo_write(void) { poke2(&dev[0xb2], file_write(1, peek2(&dev[0xbe]), rL2, dev[0xb7])); }
464
465 /* clang-format on */
466
467@@ -1017,14 +1013,14 @@ static inline Uint8
468 emu_dei(const Uint8 port)
469 {
470 dei_handler h = dei_handlers[port];
471- return h ? h() : uxn.dev[port];
472+ return h ? h() : dev[port];
473 }
474
475 static inline void
476 emu_deo(const Uint8 port, const Uint8 value)
477 {
478 deo_handler h = deo_handlers[port];
479- uxn.dev[port] = value;
480+ dev[port] = value;
481 if(h) h();
482 }
483
484@@ -1037,32 +1033,32 @@ emu_deo(const Uint8 port, const Uint8 value)
485 case 0xa0|opc:case 0xe0|opc:{const int d=1,k=*p;A *p=k;B} break;}
486 #define DEC s[--(*p)]
487 #define INC s[(*p)++]
488-#define FLIP s = uxn.stk[!r], p = &uxn.ptr[!r];
489-#define JUMP(x) b = uxn.ram[pc] << 8, b |= uxn.ram[pc + 1], pc += x + 2;
490+#define FLIP s = stk[!r], p = &ptr[!r];
491+#define JUMP(x) b = ram[pc] << 8, b |= ram[pc + 1], pc += x + 2;
492 #define DROP(o,m) o = DEC; if(m) o |= DEC << 8;
493 #define TAKE(o) if(d) o[1] = DEC; o[0] = DEC;
494 #define PUSH(i,m) { if(m) c = (i), INC = c >> 8, INC = c; else INC = i; }
495 #define GIVE(i) INC = i[0]; if(d) INC = i[1];
496 #define DEVO(o,r) emu_deo(o, r[0]); if(d) emu_deo(o + 1, r[1]);
497 #define DEVI(i,r) r[0] = emu_dei(i); if(d) r[1] = emu_dei(i + 1);
498-#define POKE(o,r,m) uxn.ram[o] = r[0]; if(d) uxn.ram[(o + 1) & m] = r[1];
499-#define PEEK(i,r,m) r[0] = uxn.ram[i]; if(d) r[1] = uxn.ram[(i + 1) & m];
500+#define POKE(o,r,m) ram[o] = r[0]; if(d) ram[(o + 1) & m] = r[1];
501+#define PEEK(i,r,m) r[0] = ram[i]; if(d) r[1] = ram[(i + 1) & m];
502
503 static unsigned
504 uxn_eval(Uint16 pc)
505 {
506 Uint16 a, b, c, x[2], y[2], z[2];
507 for(;;) {
508- Uint8 op = uxn.ram[pc++], r = (op >> 6) & 1, *s = uxn.stk[r], *p = &uxn.ptr[r];
509+ Uint8 op = ram[pc++], r = (op >> 6) & 1, *s = stk[r], *p = &ptr[r];
510 switch(op) {
511 /* BRK */ case 0x00:return 1;
512 /* JCI */ case 0x20:if(DEC) JUMP(b) else pc += 2; break;
513 /* JMI */ case 0x40:JUMP(b) break;
514 /* JSI */ case 0x60:JUMP(0) PUSH(pc,1) pc += b; break;
515- /* LI2 */ case 0xa0:INC = uxn.ram[pc++]; /* Fall-through */
516- /* LIT */ case 0x80:INC = uxn.ram[pc++]; break;
517- /* L2r */ case 0xe0:INC = uxn.ram[pc++]; /* Fall-through */
518- /* LIr */ case 0xc0:INC = uxn.ram[pc++]; break;
519+ /* LI2 */ case 0xa0:INC = ram[pc++]; /* Fall-through */
520+ /* LIT */ case 0x80:INC = ram[pc++]; break;
521+ /* L2r */ case 0xe0:INC = ram[pc++]; /* Fall-through */
522+ /* LIr */ case 0xc0:INC = ram[pc++]; break;
523 /* INC */ OPC(0x01,DROP(a,d),PUSH(a + 1,d))
524 /* POP */ OPC(0x02,*p -= 1 + d;,{})
525 /* NIP */ OPC(0x03,TAKE(x) *p -= 1 + d;,GIVE(x))
526@@ -1199,7 +1195,7 @@ emu_event(void)
527 screen_reqdraw = 1;
528 break;
529 case ClientMessage:
530- uxn.dev[0x0f] = 0x80;
531+ dev[0x0f] = 0x80;
532 break;
533 case KeyPress: {
534 KeySym sym;
535@@ -1273,7 +1269,7 @@ emu_run(void)
536 fds[0].fd = emu_x11, fds[0].events = POLLIN;
537 fds[1].fd = emu_timer, fds[1].events = POLLIN;
538 fds[2].fd = STDIN_FILENO, fds[2].events = POLLIN | POLLHUP;
539- while(!uxn.dev[0x0f]) {
540+ while(!dev[0x0f]) {
541 /* only poll stdin while it's still active */
542 if(poll(fds, stdin_active ? 3 : 2, -1) <= 0)
543 continue;
544@@ -1325,10 +1321,10 @@ main(int argc, char **argv)
545 console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
546 }
547 }
548- if(!uxn.dev[0x0f]) {
549+ if(!dev[0x0f]) {
550 if(!emu_init())
551 return !fprintf(stdout, "Could not initialize %s.\n", argv[0]);
552 emu_run();
553 }
554- return uxn.dev[0x0f] & 0x7f;
555+ return dev[0x0f] & 0x7f;
556 }