diff --git a/src/devices/system.c b/src/devices/system.c index 317744e..dcb85fb 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -45,6 +45,32 @@ system_cmd(Uint8 *ram, Uint16 addr) } } +int +system_error(char *msg, const char *err) +{ + fprintf(stderr, "%s: %s\n", msg, err); + return 1; +} + +int +uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) +{ + Uint8 *d = &u->dev[0x00]; + Uint16 handler = PEEK2(d); + if(handler) { + u->wst->ptr = 4; + u->wst->dat[0] = addr >> 0x8; + u->wst->dat[1] = addr & 0xff; + u->wst->dat[2] = instr; + u->wst->dat[3] = err; + return uxn_eval(u, handler); + } else { + system_inspect(u); + fprintf(stderr, "%s %s, by %02x at 0x%04x.\n", (instr & 0x40) ? "Return-stack" : "Working-stack", errors[err - 1], instr, addr); + } + return 0; +} + void system_inspect(Uxn *u) { @@ -80,24 +106,3 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port) break; } } - -/* Error */ - -int -uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) -{ - Uint8 *d = &u->dev[0x00]; - Uint16 handler = PEEK2(d); - if(handler) { - u->wst->ptr = 4; - u->wst->dat[0] = addr >> 0x8; - u->wst->dat[1] = addr & 0xff; - u->wst->dat[2] = instr; - u->wst->dat[3] = err; - return uxn_eval(u, handler); - } else { - system_inspect(u); - fprintf(stderr, "%s %s, by %02x at 0x%04x.\n", (instr & 0x40) ? "Return-stack" : "Working-stack", errors[err - 1], instr, addr); - } - return 0; -} diff --git a/src/devices/system.h b/src/devices/system.h index 6fc31e1..cbd9217 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -12,6 +12,7 @@ WITH REGARD TO THIS SOFTWARE. #define RAM_PAGES 0x10 #define PEEK16(d) ((d)[0] << 8 | (d)[1]) +int system_error(char *msg, const char *err); int system_load(Uxn *u, char *filename); void system_deo(Uxn *u, Uint8 *d, Uint8 port); void system_inspect(Uxn *u); diff --git a/src/uxn11.c b/src/uxn11.c index 7e82e71..dab0bbf 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -43,13 +43,6 @@ char *rom_path; Uint16 deo_mask[] = {0xff08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000}; Uint16 dei_mask[] = {0x0000, 0x0000, 0x003c, 0x0014, 0x0014, 0x0014, 0x0014, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000}; -static int -emu_error(char *msg, const char *err) -{ - fprintf(stderr, "%s: %s\n", msg, err); - return 0; -} - Uint8 uxn_dei(Uxn *u, Uint8 addr) { @@ -92,7 +85,7 @@ emu_start(Uxn *u, char *rom) if(!uxn_screen.width || !uxn_screen.height) screen_resize(&uxn_screen, WIDTH, HEIGHT); if(!uxn_eval(u, PAGE_PROGRAM)) - return emu_error("boot", "Failed to start rom."); + return system_error("boot", "Failed to start rom."); return 1; } @@ -188,7 +181,7 @@ display_start(char *title) visual = DefaultVisual(display, 0); window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width + PAD * 2, uxn_screen.height + PAD * 2, 1, 0, 0); if(visual->class != TrueColor) - return emu_error("init", "True-color visual failed"); + return system_error("init", "True-color visual failed"); XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask); wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True); XSetWMProtocols(display, window, &wmDelete, 1); @@ -209,15 +202,15 @@ main(int argc, char **argv) struct pollfd fds[3]; static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}}; if(argc < 2) - return emu_error("usage", "uxn11 game.rom args"); + return system_error("usage", "uxn11 game.rom args"); rom_path = argv[1]; if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)))) - return emu_error("boot", "Failed"); + return system_error("boot", "Failed"); /* start sequence */ if(!emu_start(&u, rom_path)) - return emu_error("start", rom_path); + return system_error("start", rom_path); if(!display_start(rom_path)) - return emu_error("display", "Failed"); + return system_error("display", "Failed"); /* console vector */ for(i = 2; i < argc; i++) { char *p = argv[i]; diff --git a/src/uxncli.c b/src/uxncli.c index 9898ce6..009467b 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -21,13 +21,6 @@ WITH REGARD TO THIS SOFTWARE. Uint16 deo_mask[] = {0x6a08, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000}; Uint16 dei_mask[] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000}; -static int -emu_error(char *msg, const char *err) -{ - fprintf(stderr, "Error %s: %s\n", msg, err); - return 1; -} - Uint8 uxn_dei(Uxn *u, Uint8 addr) { @@ -55,11 +48,11 @@ main(int argc, char **argv) Uxn u; int i; if(argc < 2) - return emu_error("Usage", "uxncli game.rom args"); + return system_error("usage", "uxncli game.rom args"); if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)))) - return emu_error("Boot", "Failed"); + return system_error("boot", "Failed"); if(!system_load(&u, argv[1])) - return emu_error("Load", "Failed"); + return system_error("load", "Failed"); if(!uxn_eval(&u, PAGE_PROGRAM)) return u.dev[0x0f] & 0x7f; for(i = 2; i < argc; i++) { @@ -69,8 +62,7 @@ main(int argc, char **argv) } while(!u.dev[0x0f]) { int c = fgetc(stdin); - if(c != EOF) - console_input(&u, (Uint8)c); + if(c != EOF) console_input(&u, (Uint8)c); } return u.dev[0x0f] & 0x7f; }