Prefixed uxn functions

This commit is contained in:
neauoire 2021-08-01 14:46:43 -07:00
parent 5045a4ca52
commit 4f822f55f3
7 changed files with 67 additions and 73 deletions

View File

@ -320,7 +320,7 @@ See etc/mkuxn-fast.moon for instructions.
#pragma mark - Core
int
evaluxn(Uxn *u, Uint16 vec)
uxn_eval(Uxn *u, Uint16 vec)
{
Uint8 instr;
if(u->dev[0].dat[0xf])
@ -361,9 +361,9 @@ evaluxn(Uxn *u, Uint16 vec)
#ifndef NO_STACK_CHECKS
error:
if(u->wst.error)
return haltuxn(u, u->wst.error, "Working-stack", instr);
return uxn_halt(u, u->wst.error, "Working-stack", instr);
else
return haltuxn(u, u->rst.error, "Return-stack", instr);
return uxn_halt(u, u->rst.error, "Return-stack", instr);
#endif
}

View File

@ -228,7 +228,7 @@ See etc/mkuxn-fast.moon for instructions.
#pragma mark - Core
int
evaluxn(Uxn *u, Uint16 vec)
uxn_eval(Uxn *u, Uint16 vec)
{
Uint8 instr;
if(u->dev[0].dat[0xf])
@ -257,9 +257,9 @@ evaluxn(Uxn *u, Uint16 vec)
#ifndef NO_STACK_CHECKS
error:
if(u->wst.error)
return haltuxn(u, u->wst.error, "Working-stack", instr);
return uxn_halt(u, u->wst.error, "Working-stack", instr);
else
return haltuxn(u, u->rst.error, "Return-stack", instr);
return uxn_halt(u, u->rst.error, "Return-stack", instr);
#endif
}

View File

@ -39,7 +39,7 @@ Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(
#pragma mark - Core
int
evaluxn(Uxn *u, Uint16 vec)
uxn_eval(Uxn *u, Uint16 vec)
{
Uint8 instr;
if(u->dev[0].dat[0xf])
@ -4021,14 +4021,14 @@ evaluxn(Uxn *u, Uint16 vec)
#ifndef NO_STACK_CHECKS
error:
if(u->wst.error)
return haltuxn(u, u->wst.error, "Working-stack", instr);
return uxn_halt(u, u->wst.error, "Working-stack", instr);
else
return haltuxn(u, u->rst.error, "Return-stack", instr);
return uxn_halt(u, u->rst.error, "Return-stack", instr);
#endif
}
int
bootuxn(Uxn *u)
uxn_boot(Uxn *u)
{
unsigned int i;
char *cptr = (char *)u;
@ -4038,7 +4038,7 @@ bootuxn(Uxn *u)
}
Device *
portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
{
Device *d = &u->dev[id];
d->addr = id * 0x10;

View File

@ -116,8 +116,8 @@ void (*ops[])(Uxn *u) = {
#pragma mark - Core
void
opcuxn(Uxn *u, Uint8 instr)
int
uxn_step(Uxn *u, Uint8 instr)
{
Uint8 op = instr & 0x3f, freturn = instr & 0x40, fkeep = instr & 0x80;
u->src = freturn ? &u->rst : &u->wst;
@ -129,21 +129,15 @@ opcuxn(Uxn *u, Uint8 instr)
pop8 = pop8_nokeep;
}
(*ops[op])(u);
}
int
stepuxn(Uxn *u, Uint8 instr)
{
opcuxn(u, instr);
if(u->wst.error)
return haltuxn(u, u->wst.error, "Working-stack", instr);
return uxn_halt(u, u->wst.error, "Working-stack", instr);
if(u->rst.error)
return haltuxn(u, u->rst.error, "Return-stack", instr);
return uxn_halt(u, u->rst.error, "Return-stack", instr);
return 1;
}
int
evaluxn(Uxn *u, Uint16 vec)
uxn_eval(Uxn *u, Uint16 vec)
{
if(u->dev[0].dat[0xf])
return 0;
@ -152,13 +146,13 @@ evaluxn(Uxn *u, Uint16 vec)
u->rst.error = 0;
if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8;
while(u->ram.ptr)
if(!stepuxn(u, u->ram.dat[u->ram.ptr++]))
if(!uxn_step(u, u->ram.dat[u->ram.ptr++]))
return 0;
return 1;
}
int
bootuxn(Uxn *u)
uxn_boot(Uxn *u)
{
unsigned int i;
char *cptr = (char *)u;
@ -168,7 +162,7 @@ bootuxn(Uxn *u)
}
Device *
portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
{
Device *d = &u->dev[id];
d->addr = id * 0x10;

View File

@ -43,7 +43,7 @@ struct Uxn;
void mempoke16(Uint8 *m, Uint16 a, Uint16 b);
Uint16 mempeek16(Uint8 *m, Uint16 a);
int bootuxn(Uxn *c);
int evaluxn(Uxn *u, Uint16 vec);
int haltuxn(Uxn *u, Uint8 error, char *name, int id);
Device *portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *, Uint8, Uint8));
int uxn_boot(Uxn *c);
int uxn_eval(Uxn *u, Uint16 vec);
int uxn_halt(Uxn *u, Uint8 error, char *name, int id);
Device *uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *, Uint8, Uint8));

View File

@ -114,7 +114,7 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
static const char *errors[] = {"underflow", "overflow", "division by zero"};
int
haltuxn(Uxn *u, Uint8 error, char *name, int id)
uxn_halt(Uxn *u, Uint8 error, char *name, int id)
{
fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr);
u->ram.ptr = 0;
@ -124,11 +124,11 @@ haltuxn(Uxn *u, Uint8 error, char *name, int id)
static void
run(Uxn *u)
{
if(!evaluxn(u, PAGE_PROGRAM))
if(!uxn_eval(u, PAGE_PROGRAM))
error("Reset", "Failed");
else if(mempeek16(devconsole->dat, 0))
while(read(0, &devconsole->dat[0x2], 1) > 0)
evaluxn(u, mempeek16(devconsole->dat, 0));
uxn_eval(u, mempeek16(devconsole->dat, 0));
}
static int
@ -149,27 +149,27 @@ main(int argc, char **argv)
if(argc < 2)
return error("Input", "Missing");
if(!bootuxn(&u))
if(!uxn_boot(&u))
return error("Boot", "Failed");
if(!loaduxn(&u, argv[1]))
return error("Load", "Failed");
devsystem = portuxn(&u, 0x0, "system", system_talk);
devconsole = portuxn(&u, 0x1, "console", console_talk);
portuxn(&u, 0x2, "empty", nil_talk);
portuxn(&u, 0x3, "empty", nil_talk);
portuxn(&u, 0x4, "empty", nil_talk);
portuxn(&u, 0x5, "empty", nil_talk);
portuxn(&u, 0x6, "empty", nil_talk);
portuxn(&u, 0x7, "empty", nil_talk);
portuxn(&u, 0x8, "empty", nil_talk);
portuxn(&u, 0x9, "empty", nil_talk);
portuxn(&u, 0xa, "file", file_talk);
portuxn(&u, 0xb, "datetime", datetime_talk);
portuxn(&u, 0xc, "empty", nil_talk);
portuxn(&u, 0xd, "empty", nil_talk);
portuxn(&u, 0xe, "empty", nil_talk);
portuxn(&u, 0xf, "empty", nil_talk);
devsystem = uxn_port(&u, 0x0, "system", system_talk);
devconsole = uxn_port(&u, 0x1, "console", console_talk);
uxn_port(&u, 0x2, "empty", nil_talk);
uxn_port(&u, 0x3, "empty", nil_talk);
uxn_port(&u, 0x4, "empty", nil_talk);
uxn_port(&u, 0x5, "empty", nil_talk);
uxn_port(&u, 0x6, "empty", nil_talk);
uxn_port(&u, 0x7, "empty", nil_talk);
uxn_port(&u, 0x8, "empty", nil_talk);
uxn_port(&u, 0x9, "empty", nil_talk);
uxn_port(&u, 0xa, "file", file_talk);
uxn_port(&u, 0xb, "datetime", datetime_talk);
uxn_port(&u, 0xc, "empty", nil_talk);
uxn_port(&u, 0xd, "empty", nil_talk);
uxn_port(&u, 0xe, "empty", nil_talk);
uxn_port(&u, 0xf, "empty", nil_talk);
run(&u);

View File

@ -414,7 +414,7 @@ stdin_handler(void *p)
static const char *errors[] = {"underflow", "overflow", "division by zero"};
int
haltuxn(Uxn *u, Uint8 error, char *name, int id)
uxn_halt(Uxn *u, Uint8 error, char *name, int id)
{
fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr);
u->ram.ptr = 0;
@ -424,7 +424,7 @@ haltuxn(Uxn *u, Uint8 error, char *name, int id)
static void
run(Uxn *u)
{
evaluxn(u, 0x0100);
uxn_eval(u, 0x0100);
redraw(u);
while(1) {
SDL_Event event;
@ -440,19 +440,19 @@ run(Uxn *u)
case SDL_KEYDOWN:
case SDL_KEYUP:
doctrl(u, &event, event.type == SDL_KEYDOWN);
evaluxn(u, mempeek16(devctrl->dat, 0));
uxn_eval(u, mempeek16(devctrl->dat, 0));
devctrl->dat[3] = 0;
break;
case SDL_MOUSEWHEEL:
devmouse->dat[7] = event.wheel.y;
evaluxn(u, mempeek16(devmouse->dat, 0));
uxn_eval(u, mempeek16(devmouse->dat, 0));
devmouse->dat[7] = 0;
break;
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
domouse(&event);
evaluxn(u, mempeek16(devmouse->dat, 0));
uxn_eval(u, mempeek16(devmouse->dat, 0));
break;
case SDL_WINDOWEVENT:
if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
@ -461,11 +461,11 @@ run(Uxn *u)
default:
if(event.type == stdin_event) {
devconsole->dat[0x2] = event.cbutton.button;
evaluxn(u, mempeek16(devconsole->dat, 0));
uxn_eval(u, mempeek16(devconsole->dat, 0));
}
}
}
evaluxn(u, mempeek16(devscreen->dat, 0));
uxn_eval(u, mempeek16(devscreen->dat, 0));
if(reqdraw || devsystem->dat[0xe])
redraw(u);
if(!bench) {
@ -496,29 +496,29 @@ main(int argc, char **argv)
if(argc < 2)
return error("usage", "uxnemu file.rom");
if(!bootuxn(&u))
if(!uxn_boot(&u))
return error("Boot", "Failed to start uxn.");
if(!loaduxn(&u, argv[1]))
return error("Load", "Failed to open rom.");
if(!init())
return error("Init", "Failed to initialize emulator.");
devsystem = portuxn(&u, 0x0, "system", system_talk);
devconsole = portuxn(&u, 0x1, "console", console_talk);
devscreen = portuxn(&u, 0x2, "screen", screen_talk);
devaudio0 = portuxn(&u, 0x3, "audio0", audio_talk);
portuxn(&u, 0x4, "audio1", audio_talk);
portuxn(&u, 0x5, "audio2", audio_talk);
portuxn(&u, 0x6, "audio3", audio_talk);
portuxn(&u, 0x7, "---", nil_talk);
devctrl = portuxn(&u, 0x8, "controller", nil_talk);
devmouse = portuxn(&u, 0x9, "mouse", nil_talk);
portuxn(&u, 0xa, "file", file_talk);
portuxn(&u, 0xb, "datetime", datetime_talk);
portuxn(&u, 0xc, "---", nil_talk);
portuxn(&u, 0xd, "---", nil_talk);
portuxn(&u, 0xe, "---", nil_talk);
portuxn(&u, 0xf, "---", nil_talk);
devsystem = uxn_port(&u, 0x0, "system", system_talk);
devconsole = uxn_port(&u, 0x1, "console", console_talk);
devscreen = uxn_port(&u, 0x2, "screen", screen_talk);
devaudio0 = uxn_port(&u, 0x3, "audio0", audio_talk);
uxn_port(&u, 0x4, "audio1", audio_talk);
uxn_port(&u, 0x5, "audio2", audio_talk);
uxn_port(&u, 0x6, "audio3", audio_talk);
uxn_port(&u, 0x7, "---", nil_talk);
devctrl = uxn_port(&u, 0x8, "controller", nil_talk);
devmouse = uxn_port(&u, 0x9, "mouse", nil_talk);
uxn_port(&u, 0xa, "file", file_talk);
uxn_port(&u, 0xb, "datetime", datetime_talk);
uxn_port(&u, 0xc, "---", nil_talk);
uxn_port(&u, 0xd, "---", nil_talk);
uxn_port(&u, 0xe, "---", nil_talk);
uxn_port(&u, 0xf, "---", nil_talk);
/* Write screen size to dev/screen */
mempoke16(devscreen->dat, 2, ppu.width);