| ... | ... |
@@ -612,22 +612,22 @@ main(int argc, char **argv) |
| 612 | 612 |
if(!init()) |
| 613 | 613 |
return error("Init", "Failed");
|
| 614 | 614 |
|
| 615 |
- portuxn(&u, "console", console_poke); |
|
| 616 |
- devscreen = portuxn(&u, "screen", screen_poke); |
|
| 617 |
- portuxn(&u, "sprite", sprite_poke); |
|
| 618 |
- devctrl = portuxn(&u, "controller", ppnil); |
|
| 619 |
- devkey = portuxn(&u, "key", ppnil); |
|
| 620 |
- devmouse = portuxn(&u, "mouse", ppnil); |
|
| 621 |
- portuxn(&u, "file", file_poke); |
|
| 622 |
- devaudio = portuxn(&u, "audio", audio_poke); |
|
| 623 |
- portuxn(&u, "midi", ppnil); |
|
| 624 |
- portuxn(&u, "datetime", datetime_poke); |
|
| 625 |
- portuxn(&u, "---", ppnil); |
|
| 626 |
- portuxn(&u, "---", ppnil); |
|
| 627 |
- portuxn(&u, "---", ppnil); |
|
| 628 |
- portuxn(&u, "---", ppnil); |
|
| 629 |
- portuxn(&u, "---", ppnil); |
|
| 630 |
- portuxn(&u, "system", system_poke); |
|
| 615 |
+ portuxn(&u, 0x00, "console", console_poke); |
|
| 616 |
+ devscreen = portuxn(&u, 0x01, "screen", screen_poke); |
|
| 617 |
+ portuxn(&u, 0x02, "sprite", sprite_poke); |
|
| 618 |
+ devctrl = portuxn(&u, 0x03, "controller", ppnil); |
|
| 619 |
+ devkey = portuxn(&u, 0x04, "key", ppnil); |
|
| 620 |
+ devmouse = portuxn(&u, 0x05, "mouse", ppnil); |
|
| 621 |
+ portuxn(&u, 0x06, "file", file_poke); |
|
| 622 |
+ devaudio = portuxn(&u, 0x07, "audio", audio_poke); |
|
| 623 |
+ portuxn(&u, 0x08, "midi", ppnil); |
|
| 624 |
+ portuxn(&u, 0x09, "datetime", datetime_poke); |
|
| 625 |
+ portuxn(&u, 0x0a, "---", ppnil); |
|
| 626 |
+ portuxn(&u, 0x0b, "---", ppnil); |
|
| 627 |
+ portuxn(&u, 0x0c, "---", ppnil); |
|
| 628 |
+ portuxn(&u, 0x0d, "---", ppnil); |
|
| 629 |
+ portuxn(&u, 0x0e, "---", ppnil); |
|
| 630 |
+ portuxn(&u, 0x0f, "system", system_poke); |
|
| 631 | 631 |
|
| 632 | 632 |
/* Write screen size to dev/screen */ |
| 633 | 633 |
u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff; |
| ... | ... |
@@ -18,7 +18,7 @@ WITH REGARD TO THIS SOFTWARE. |
| 18 | 18 |
/* clang-format off */ |
| 19 | 19 |
void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); }
|
| 20 | 20 |
int getflag(Uint8 *a, char flag) { return *a & flag; }
|
| 21 |
-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; }
|
|
| 21 |
+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; }
|
|
| 22 | 22 |
|
| 23 | 23 |
void push8(Stack *s, Uint8 a) { if (s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; }
|
| 24 | 24 |
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) = {
|
| 118 | 118 |
int |
| 119 | 119 |
haltuxn(Uxn *u, char *name, int id) |
| 120 | 120 |
{
|
| 121 |
- printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->counter);
|
|
| 121 |
+ printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->ram.ptr);
|
|
| 122 | 122 |
return 0; |
| 123 | 123 |
} |
| 124 | 124 |
|
| ... | ... |
@@ -164,7 +164,6 @@ evaluxn(Uxn *u, Uint16 vec) |
| 164 | 164 |
Uint8 instr = u->ram.dat[u->ram.ptr++]; |
| 165 | 165 |
if(!stepuxn(u, instr)) |
| 166 | 166 |
return 0; |
| 167 |
- u->counter++; |
|
| 168 | 167 |
} |
| 169 | 168 |
return 1; |
| 170 | 169 |
} |
| ... | ... |
@@ -191,11 +190,11 @@ loaduxn(Uxn *u, char *filepath) |
| 191 | 190 |
} |
| 192 | 191 |
|
| 193 | 192 |
Device * |
| 194 |
-portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)) |
|
| 193 |
+portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)) |
|
| 195 | 194 |
{
|
| 196 |
- Device *d = &u->dev[u->devices++]; |
|
| 197 |
- d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10; |
|
| 195 |
+ Device *d = &u->dev[id]; |
|
| 196 |
+ d->addr = PAGE_DEVICE + id * 0x10; |
|
| 198 | 197 |
d->poke = pofn; |
| 199 |
- printf("Device #%d: %s, at 0x%04x \n", u->devices - 1, name, d->addr);
|
|
| 198 |
+ printf("Device #%d: %s, at 0x%04x \n", id - 1, name, d->addr);
|
|
| 200 | 199 |
return d; |
| 201 | 200 |
} |
| ... | ... |
@@ -38,8 +38,7 @@ typedef struct Device {
|
| 38 | 38 |
} Device; |
| 39 | 39 |
|
| 40 | 40 |
typedef struct Uxn {
|
| 41 |
- Uint8 literal, status, devices; |
|
| 42 |
- Uint16 counter; |
|
| 41 |
+ Uint8 literal, status; |
|
| 43 | 42 |
Stack wst, rst, *src, *dst; |
| 44 | 43 |
Memory ram; |
| 45 | 44 |
Device dev[16]; |
| ... | ... |
@@ -50,4 +49,4 @@ int getflag(Uint8 *status, char flag); |
| 50 | 49 |
int loaduxn(Uxn *c, char *filepath); |
| 51 | 50 |
int bootuxn(Uxn *c); |
| 52 | 51 |
int evaluxn(Uxn *u, Uint16 vec); |
| 53 |
-Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8)); |
|
| 52 |
+Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8)); |