Moved dev code out of uxn
This commit is contained in:
parent
de22c37e07
commit
220c3676e5
9
cli.c
9
cli.c
|
@ -21,13 +21,18 @@ error(char *msg, const char *err)
|
|||
}
|
||||
|
||||
void
|
||||
console_onread(void)
|
||||
console_onread(Uint8 *b)
|
||||
{
|
||||
(void)b;
|
||||
}
|
||||
|
||||
void
|
||||
console_onwrite(void)
|
||||
console_onwrite(Uint8 *b)
|
||||
{
|
||||
if(b) {
|
||||
printf("%c", *b);
|
||||
*b = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
23
uxn.c
23
uxn.c
|
@ -114,15 +114,12 @@ lituxn(Uxn *u, Uint8 instr)
|
|||
}
|
||||
|
||||
int
|
||||
devuxn(Uxn *u) /* experimental */
|
||||
devuxn(Uxn *u)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < u->devices; ++i) {
|
||||
Uint16 addr = u->dev[i].w;
|
||||
if(u->ram.dat[addr]) {
|
||||
printf("%c", u->ram.dat[addr]);
|
||||
u->ram.dat[addr] = 0;
|
||||
}
|
||||
u->dev[i].wfn(&u->ram.dat[u->dev[i].w]);
|
||||
u->dev[i].rfn(&u->ram.dat[u->dev[i].r]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -147,10 +144,8 @@ opcuxn(Uxn *u, Uint8 instr)
|
|||
}
|
||||
|
||||
int
|
||||
parse(Uxn *u) /* TODO: Rename */
|
||||
stepuxn(Uxn *u, Uint8 instr)
|
||||
{
|
||||
Uint8 instr = u->ram.dat[u->ram.ptr++];
|
||||
u->counter++;
|
||||
if(u->literal > 0)
|
||||
return lituxn(u, instr);
|
||||
else
|
||||
|
@ -162,8 +157,12 @@ evaluxn(Uxn *u, Uint16 vec)
|
|||
{
|
||||
u->ram.ptr = vec;
|
||||
setflag(&u->status, FLAG_HALT, 0);
|
||||
while(!(u->status & FLAG_HALT) && parse(u))
|
||||
;
|
||||
while(!(u->status & FLAG_HALT)) {
|
||||
Uint8 instr = u->ram.dat[u->ram.ptr++];
|
||||
if(!stepuxn(u, instr))
|
||||
return 0;
|
||||
u->counter++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -198,7 +197,7 @@ loaduxn(Uxn *u, char *filepath)
|
|||
/* to start: evaluxn(u, u->vreset); */
|
||||
|
||||
int
|
||||
portuxn(Uxn *u, Uint16 r, Uint16 w, void (*onread)(), void (*onwrite)())
|
||||
portuxn(Uxn *u, Uint16 r, Uint16 w, void (*onread)(Uint8 *), void (*onwrite)(Uint8 *))
|
||||
{
|
||||
Device *d = &u->dev[u->devices++];
|
||||
d->r = r;
|
||||
|
|
6
uxn.h
6
uxn.h
|
@ -36,8 +36,8 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
Uint16 r, w;
|
||||
void (*rfn)(void);
|
||||
void (*wfn)(void);
|
||||
void (*rfn)(Uint8 *);
|
||||
void (*wfn)(Uint8 *);
|
||||
} Device;
|
||||
|
||||
typedef struct {
|
||||
|
@ -54,4 +54,4 @@ int getflag(Uint8 *status, char flag);
|
|||
int loaduxn(Uxn *c, char *filepath);
|
||||
int bootuxn(Uxn *c);
|
||||
int evaluxn(Uxn *u, Uint16 vec);
|
||||
int portuxn(Uxn *u, Uint16 r, Uint16 w, void (*onread)(), void (*onwrite)());
|
||||
int portuxn(Uxn *u, Uint16 r, Uint16 w, void (*onread)(Uint8 *), void (*onwrite)(Uint8 *));
|
||||
|
|
Loading…
Reference in New Issue