commit bdd6c19
Devine Lu Linvega
·
2023-04-10 21:32:54 +0000 UTC
parent ed588f9
Moved emu_error to device
4 files changed,
+37,
-46
+26,
-21
1@@ -45,6 +45,32 @@ system_cmd(Uint8 *ram, Uint16 addr)
2 }
3 }
4
5+int
6+system_error(char *msg, const char *err)
7+{
8+ fprintf(stderr, "%s: %s\n", msg, err);
9+ return 1;
10+}
11+
12+int
13+uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
14+{
15+ Uint8 *d = &u->dev[0x00];
16+ Uint16 handler = PEEK2(d);
17+ if(handler) {
18+ u->wst->ptr = 4;
19+ u->wst->dat[0] = addr >> 0x8;
20+ u->wst->dat[1] = addr & 0xff;
21+ u->wst->dat[2] = instr;
22+ u->wst->dat[3] = err;
23+ return uxn_eval(u, handler);
24+ } else {
25+ system_inspect(u);
26+ fprintf(stderr, "%s %s, by %02x at 0x%04x.\n", (instr & 0x40) ? "Return-stack" : "Working-stack", errors[err - 1], instr, addr);
27+ }
28+ return 0;
29+}
30+
31 void
32 system_inspect(Uxn *u)
33 {
34@@ -80,24 +106,3 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
35 break;
36 }
37 }
38-
39-/* Error */
40-
41-int
42-uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
43-{
44- Uint8 *d = &u->dev[0x00];
45- Uint16 handler = PEEK2(d);
46- if(handler) {
47- u->wst->ptr = 4;
48- u->wst->dat[0] = addr >> 0x8;
49- u->wst->dat[1] = addr & 0xff;
50- u->wst->dat[2] = instr;
51- u->wst->dat[3] = err;
52- return uxn_eval(u, handler);
53- } else {
54- system_inspect(u);
55- fprintf(stderr, "%s %s, by %02x at 0x%04x.\n", (instr & 0x40) ? "Return-stack" : "Working-stack", errors[err - 1], instr, addr);
56- }
57- return 0;
58-}
+1,
-0
1@@ -12,6 +12,7 @@ WITH REGARD TO THIS SOFTWARE.
2 #define RAM_PAGES 0x10
3 #define PEEK16(d) ((d)[0] << 8 | (d)[1])
4
5+int system_error(char *msg, const char *err);
6 int system_load(Uxn *u, char *filename);
7 void system_deo(Uxn *u, Uint8 *d, Uint8 port);
8 void system_inspect(Uxn *u);
+6,
-13
1@@ -43,13 +43,6 @@ char *rom_path;
2 Uint16 deo_mask[] = {0xff08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
3 Uint16 dei_mask[] = {0x0000, 0x0000, 0x003c, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
4
5-static int
6-emu_error(char *msg, const char *err)
7-{
8- fprintf(stderr, "%s: %s\n", msg, err);
9- return 0;
10-}
11-
12 Uint8
13 uxn_dei(Uxn *u, Uint8 addr)
14 {
15@@ -92,7 +85,7 @@ emu_start(Uxn *u, char *rom)
16 if(!uxn_screen.width || !uxn_screen.height)
17 screen_resize(&uxn_screen, WIDTH, HEIGHT);
18 if(!uxn_eval(u, PAGE_PROGRAM))
19- return emu_error("boot", "Failed to start rom.");
20+ return system_error("boot", "Failed to start rom.");
21 return 1;
22 }
23
24@@ -188,7 +181,7 @@ display_start(char *title)
25 visual = DefaultVisual(display, 0);
26 window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2, 1, 0, 0);
27 if(visual->class != TrueColor)
28- return emu_error("init", "True-color visual failed");
29+ return system_error("init", "True-color visual failed");
30 XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask);
31 wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
32 XSetWMProtocols(display, window, &wmDelete, 1);
33@@ -209,15 +202,15 @@ main(int argc, char **argv)
34 struct pollfd fds[3];
35 static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
36 if(argc < 2)
37- return emu_error("usage", "uxn11 game.rom args");
38+ return system_error("usage", "uxn11 game.rom args");
39 rom_path = argv[1];
40 if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
41- return emu_error("boot", "Failed");
42+ return system_error("boot", "Failed");
43 /* start sequence */
44 if(!emu_start(&u, rom_path))
45- return emu_error("start", rom_path);
46+ return system_error("start", rom_path);
47 if(!display_start(rom_path))
48- return emu_error("display", "Failed");
49+ return system_error("display", "Failed");
50 /* console vector */
51 for(i = 2; i < argc; i++) {
52 char *p = argv[i];
+4,
-12
1@@ -21,13 +21,6 @@ WITH REGARD TO THIS SOFTWARE.
2 Uint16 deo_mask[] = {0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
3 Uint16 dei_mask[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000};
4
5-static int
6-emu_error(char *msg, const char *err)
7-{
8- fprintf(stderr, "Error %s: %s\n", msg, err);
9- return 1;
10-}
11-
12 Uint8
13 uxn_dei(Uxn *u, Uint8 addr)
14 {
15@@ -55,11 +48,11 @@ main(int argc, char **argv)
16 Uxn u;
17 int i;
18 if(argc < 2)
19- return emu_error("Usage", "uxncli game.rom args");
20+ return system_error("usage", "uxncli game.rom args");
21 if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
22- return emu_error("Boot", "Failed");
23+ return system_error("boot", "Failed");
24 if(!system_load(&u, argv[1]))
25- return emu_error("Load", "Failed");
26+ return system_error("load", "Failed");
27 if(!uxn_eval(&u, PAGE_PROGRAM))
28 return u.dev[0x0f] & 0x7f;
29 for(i = 2; i < argc; i++) {
30@@ -69,8 +62,7 @@ main(int argc, char **argv)
31 }
32 while(!u.dev[0x0f]) {
33 int c = fgetc(stdin);
34- if(c != EOF)
35- console_input(&u, (Uint8)c);
36+ if(c != EOF) console_input(&u, (Uint8)c);
37 }
38 return u.dev[0x0f] & 0x7f;
39 }