| ... | ... |
@@ -339,8 +339,9 @@ doctrl(Uxn *u, SDL_Event *event, int z) |
| 339 | 339 |
#pragma mark - Devices |
| 340 | 340 |
|
| 341 | 341 |
Uint8 |
| 342 |
-console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 342 |
+console_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 343 | 343 |
{
|
| 344 |
+ Uint8 *m = u->ram.dat; |
|
| 344 | 345 |
switch(b0) {
|
| 345 | 346 |
case 0x08: printf("%c", b1); break;
|
| 346 | 347 |
case 0x09: printf("0x%02x\n", b1); break;
|
| ... | ... |
@@ -354,8 +355,9 @@ console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 354 | 355 |
} |
| 355 | 356 |
|
| 356 | 357 |
Uint8 |
| 357 |
-screen_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 358 |
+screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 358 | 359 |
{
|
| 360 |
+ Uint8 *m = u->ram.dat; |
|
| 359 | 361 |
ptr += 8; |
| 360 | 362 |
if(b0 == 0x0c) {
|
| 361 | 363 |
Uint16 x = (m[ptr] << 8) + m[ptr + 1]; |
| ... | ... |
@@ -367,8 +369,9 @@ screen_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 367 | 369 |
} |
| 368 | 370 |
|
| 369 | 371 |
Uint8 |
| 370 |
-sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 372 |
+sprite_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 371 | 373 |
{
|
| 374 |
+ Uint8 *m = u->ram.dat; |
|
| 372 | 375 |
ptr += 8; |
| 373 | 376 |
if(b0 == 0x0e) {
|
| 374 | 377 |
Uint16 x = (m[ptr] << 8) + m[ptr + 1]; |
| ... | ... |
@@ -386,8 +389,9 @@ sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 386 | 389 |
} |
| 387 | 390 |
|
| 388 | 391 |
Uint8 |
| 389 |
-file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 392 |
+file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 390 | 393 |
{
|
| 394 |
+ Uint8 *m = u->ram.dat; |
|
| 391 | 395 |
char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]]; |
| 392 | 396 |
Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3]; |
| 393 | 397 |
if(b0 == 0x0d) {
|
| ... | ... |
@@ -409,8 +413,9 @@ file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 409 | 413 |
} |
| 410 | 414 |
|
| 411 | 415 |
Uint8 |
| 412 |
-system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 416 |
+system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 413 | 417 |
{
|
| 418 |
+ Uint8 *m = u->ram.dat; |
|
| 414 | 419 |
loadtheme(&m[PAGE_DEVICE + 0x00f8]); |
| 415 | 420 |
(void)ptr; |
| 416 | 421 |
(void)b0; |
| ... | ... |
@@ -418,9 +423,9 @@ system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
| 418 | 423 |
} |
| 419 | 424 |
|
| 420 | 425 |
Uint8 |
| 421 |
-ppnil(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 426 |
+ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) |
|
| 422 | 427 |
{
|
| 423 |
- (void)m; |
|
| 428 |
+ (void)u; |
|
| 424 | 429 |
(void)ptr; |
| 425 | 430 |
(void)b0; |
| 426 | 431 |
return b1; |
| ... | ... |
@@ -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->ram.dat, PAGE_DEVICE + id * 0x10, b0, b1) : b1; }
|
|
| 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; }
|
|
| 22 | 22 |
void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = (a & 0xff00) == PAGE_DEVICE ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; }
|
| 23 | 23 |
Uint8 mempeek8(Uxn *u, Uint16 a) { return u->ram.dat[a]; }
|
| 24 | 24 |
void mempoke16(Uxn *u, Uint16 a, Uint16 b) { mempoke8(u, a, b >> 8); mempoke8(u, a + 1, b); }
|
| ... | ... |
@@ -224,7 +224,7 @@ loaduxn(Uxn *u, char *filepath) |
| 224 | 224 |
} |
| 225 | 225 |
|
| 226 | 226 |
Device * |
| 227 |
-portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)) |
|
| 227 |
+portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)) |
|
| 228 | 228 |
{
|
| 229 | 229 |
Device *d = &u->dev[u->devices++]; |
| 230 | 230 |
d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10; |
| ... | ... |
@@ -32,12 +32,14 @@ typedef struct {
|
| 32 | 32 |
Uint8 dat[65536]; |
| 33 | 33 |
} Memory; |
| 34 | 34 |
|
| 35 |
+struct Uxn; |
|
| 36 |
+ |
|
| 35 | 37 |
typedef struct Device {
|
| 36 | 38 |
Uint16 addr; |
| 37 |
- Uint8 (*poke)(Uint8 *, Uint16, Uint8, Uint8); |
|
| 39 |
+ Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8); |
|
| 38 | 40 |
} Device; |
| 39 | 41 |
|
| 40 |
-typedef struct {
|
|
| 42 |
+typedef struct Uxn {
|
|
| 41 | 43 |
Uint8 literal, status, devices; |
| 42 | 44 |
Uint16 counter, vreset, vframe, verror; |
| 43 | 45 |
Stack wst, rst, *src, *dst; |
| ... | ... |
@@ -50,4 +52,4 @@ int getflag(Uint8 *status, char flag); |
| 50 | 52 |
int loaduxn(Uxn *c, char *filepath); |
| 51 | 53 |
int bootuxn(Uxn *c); |
| 52 | 54 |
int evaluxn(Uxn *u, Uint16 vec); |
| 53 |
-Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uint8 *, Uint16, Uint8, Uint8)); |
|
| 55 |
+Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8)); |