Moved emu_error to device

This commit is contained in:
Devine Lu Linvega 2023-04-10 14:32:54 -07:00
parent ed588f9190
commit bdd6c19576
4 changed files with 37 additions and 46 deletions

View File

@ -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 void
system_inspect(Uxn *u) system_inspect(Uxn *u)
{ {
@ -80,24 +106,3 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
break; 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;
}

View File

@ -12,6 +12,7 @@ WITH REGARD TO THIS SOFTWARE.
#define RAM_PAGES 0x10 #define RAM_PAGES 0x10
#define PEEK16(d) ((d)[0] << 8 | (d)[1]) #define PEEK16(d) ((d)[0] << 8 | (d)[1])
int system_error(char *msg, const char *err);
int system_load(Uxn *u, char *filename); int system_load(Uxn *u, char *filename);
void system_deo(Uxn *u, Uint8 *d, Uint8 port); void system_deo(Uxn *u, Uint8 *d, Uint8 port);
void system_inspect(Uxn *u); void system_inspect(Uxn *u);

View File

@ -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 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}; 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 Uint8
uxn_dei(Uxn *u, Uint8 addr) uxn_dei(Uxn *u, Uint8 addr)
{ {
@ -92,7 +85,7 @@ emu_start(Uxn *u, char *rom)
if(!uxn_screen.width || !uxn_screen.height) if(!uxn_screen.width || !uxn_screen.height)
screen_resize(&uxn_screen, WIDTH, HEIGHT); screen_resize(&uxn_screen, WIDTH, HEIGHT);
if(!uxn_eval(u, PAGE_PROGRAM)) if(!uxn_eval(u, PAGE_PROGRAM))
return emu_error("boot", "Failed to start rom."); return system_error("boot", "Failed to start rom.");
return 1; return 1;
} }
@ -188,7 +181,7 @@ display_start(char *title)
visual = DefaultVisual(display, 0); 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); 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) 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); XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask);
wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True); wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
XSetWMProtocols(display, window, &wmDelete, 1); XSetWMProtocols(display, window, &wmDelete, 1);
@ -209,15 +202,15 @@ main(int argc, char **argv)
struct pollfd fds[3]; struct pollfd fds[3];
static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}}; static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
if(argc < 2) if(argc < 2)
return emu_error("usage", "uxn11 game.rom args"); return system_error("usage", "uxn11 game.rom args");
rom_path = argv[1]; rom_path = argv[1];
if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)))) if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
return emu_error("boot", "Failed"); return system_error("boot", "Failed");
/* start sequence */ /* start sequence */
if(!emu_start(&u, rom_path)) if(!emu_start(&u, rom_path))
return emu_error("start", rom_path); return system_error("start", rom_path);
if(!display_start(rom_path)) if(!display_start(rom_path))
return emu_error("display", "Failed"); return system_error("display", "Failed");
/* console vector */ /* console vector */
for(i = 2; i < argc; i++) { for(i = 2; i < argc; i++) {
char *p = argv[i]; char *p = argv[i];

View File

@ -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 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}; 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 Uint8
uxn_dei(Uxn *u, Uint8 addr) uxn_dei(Uxn *u, Uint8 addr)
{ {
@ -55,11 +48,11 @@ main(int argc, char **argv)
Uxn u; Uxn u;
int i; int i;
if(argc < 2) 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)))) 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])) if(!system_load(&u, argv[1]))
return emu_error("Load", "Failed"); return system_error("load", "Failed");
if(!uxn_eval(&u, PAGE_PROGRAM)) if(!uxn_eval(&u, PAGE_PROGRAM))
return u.dev[0x0f] & 0x7f; return u.dev[0x0f] & 0x7f;
for(i = 2; i < argc; i++) { for(i = 2; i < argc; i++) {
@ -69,8 +62,7 @@ main(int argc, char **argv)
} }
while(!u.dev[0x0f]) { while(!u.dev[0x0f]) {
int c = fgetc(stdin); int c = fgetc(stdin);
if(c != EOF) if(c != EOF) console_input(&u, (Uint8)c);
console_input(&u, (Uint8)c);
} }
return u.dev[0x0f] & 0x7f; return u.dev[0x0f] & 0x7f;
} }