Removed old devices and counters bytes

This commit is contained in:
neauoire 2021-04-04 08:34:18 -07:00
parent edd7abdca5
commit e791dbd640
3 changed files with 24 additions and 26 deletions

View File

@ -612,22 +612,22 @@ main(int argc, char **argv)
if(!init()) if(!init())
return error("Init", "Failed"); return error("Init", "Failed");
portuxn(&u, "console", console_poke); portuxn(&u, 0x00, "console", console_poke);
devscreen = portuxn(&u, "screen", screen_poke); devscreen = portuxn(&u, 0x01, "screen", screen_poke);
portuxn(&u, "sprite", sprite_poke); portuxn(&u, 0x02, "sprite", sprite_poke);
devctrl = portuxn(&u, "controller", ppnil); devctrl = portuxn(&u, 0x03, "controller", ppnil);
devkey = portuxn(&u, "key", ppnil); devkey = portuxn(&u, 0x04, "key", ppnil);
devmouse = portuxn(&u, "mouse", ppnil); devmouse = portuxn(&u, 0x05, "mouse", ppnil);
portuxn(&u, "file", file_poke); portuxn(&u, 0x06, "file", file_poke);
devaudio = portuxn(&u, "audio", audio_poke); devaudio = portuxn(&u, 0x07, "audio", audio_poke);
portuxn(&u, "midi", ppnil); portuxn(&u, 0x08, "midi", ppnil);
portuxn(&u, "datetime", datetime_poke); portuxn(&u, 0x09, "datetime", datetime_poke);
portuxn(&u, "---", ppnil); portuxn(&u, 0x0a, "---", ppnil);
portuxn(&u, "---", ppnil); portuxn(&u, 0x0b, "---", ppnil);
portuxn(&u, "---", ppnil); portuxn(&u, 0x0c, "---", ppnil);
portuxn(&u, "---", ppnil); portuxn(&u, 0x0d, "---", ppnil);
portuxn(&u, "---", ppnil); portuxn(&u, 0x0e, "---", ppnil);
portuxn(&u, "system", system_poke); portuxn(&u, 0x0f, "system", system_poke);
/* Write screen size to dev/screen */ /* Write screen size to dev/screen */
u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff; u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff;

View File

@ -18,7 +18,7 @@ WITH REGARD TO THIS SOFTWARE.
/* clang-format off */ /* clang-format off */
void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); } void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); }
int getflag(Uint8 *a, char flag) { return *a & flag; } int getflag(Uint8 *a, char flag) { return *a & flag; }
Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].poke(u, PAGE_DEVICE + id * 0x10, b0, b1) : b1; } Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < 0x10 ? u->dev[id].poke(u, PAGE_DEVICE + id * 0x10, b0, b1) : b1; }
void push8(Stack *s, Uint8 a) { if (s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; } void push8(Stack *s, Uint8 a) { if (s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
Uint8 pop8(Stack *s) { if (s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; } Uint8 pop8(Stack *s) { if (s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; }
@ -118,7 +118,7 @@ void (*ops[])(Uxn *u) = {
int int
haltuxn(Uxn *u, char *name, int id) haltuxn(Uxn *u, char *name, int id)
{ {
printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->counter); printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->ram.ptr);
return 0; return 0;
} }
@ -164,7 +164,6 @@ evaluxn(Uxn *u, Uint16 vec)
Uint8 instr = u->ram.dat[u->ram.ptr++]; Uint8 instr = u->ram.dat[u->ram.ptr++];
if(!stepuxn(u, instr)) if(!stepuxn(u, instr))
return 0; return 0;
u->counter++;
} }
return 1; return 1;
} }
@ -191,11 +190,11 @@ loaduxn(Uxn *u, char *filepath)
} }
Device * Device *
portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)) portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1))
{ {
Device *d = &u->dev[u->devices++]; Device *d = &u->dev[id];
d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10; d->addr = PAGE_DEVICE + id * 0x10;
d->poke = pofn; d->poke = pofn;
printf("Device #%d: %s, at 0x%04x \n", u->devices - 1, name, d->addr); printf("Device #%d: %s, at 0x%04x \n", id - 1, name, d->addr);
return d; return d;
} }

View File

@ -38,8 +38,7 @@ typedef struct Device {
} Device; } Device;
typedef struct Uxn { typedef struct Uxn {
Uint8 literal, status, devices; Uint8 literal, status;
Uint16 counter;
Stack wst, rst, *src, *dst; Stack wst, rst, *src, *dst;
Memory ram; Memory ram;
Device dev[16]; Device dev[16];
@ -50,4 +49,4 @@ int getflag(Uint8 *status, char flag);
int loaduxn(Uxn *c, char *filepath); int loaduxn(Uxn *c, char *filepath);
int bootuxn(Uxn *c); int bootuxn(Uxn *c);
int evaluxn(Uxn *u, Uint16 vec); int evaluxn(Uxn *u, Uint16 vec);
Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8)); Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8));