|
|
|
|
@ -39,31 +39,11 @@ system_inspect(Uxn *u)
|
|
|
|
|
system_print(u->rst, "rst"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) |
|
|
|
|
{ |
|
|
|
|
Uint8 *d = &u->dev[0x00]; |
|
|
|
|
Uint16 handler = GETVEC(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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* MMU */ |
|
|
|
|
/* RAM */ |
|
|
|
|
|
|
|
|
|
Uint8 * |
|
|
|
|
mmu_init(Mmu *m, Uint16 pages) |
|
|
|
|
system_init(Mmu *m, Uint16 pages) |
|
|
|
|
{ |
|
|
|
|
m->length = pages; |
|
|
|
|
m->pages = (Uint8 *)calloc(0x10000 * pages, sizeof(Uint8)); |
|
|
|
|
return m->pages; |
|
|
|
|
} |
|
|
|
|
@ -82,6 +62,20 @@ mmu_eval(Uint8 *ram, Uint16 addr)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
system_load(Uxn *u, char *filename) |
|
|
|
|
{ |
|
|
|
|
int l, i = 0; |
|
|
|
|
FILE *f = fopen(filename, "rb"); |
|
|
|
|
if(!f) |
|
|
|
|
return 0; |
|
|
|
|
l = fread(&u->ram[PAGE_PROGRAM], 1, 0x10000 - PAGE_PROGRAM, f); |
|
|
|
|
while(l && ++i < RAM_PAGES) |
|
|
|
|
l = fread(u->ram + 0x10000 * i, 1, 0x10000, f); |
|
|
|
|
fclose(f); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* IO */ |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -98,3 +92,25 @@ 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 = GETVEC(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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|