... | ... |
@@ -26,9 +26,11 @@ WITH REGARD TO THIS SOFTWARE. |
26 | 26 |
#define POKE(x, y) { if(bs) { u->ram[(x)] = (y) >> 8; u->ram[(x) + 1] = (y); } else { u->ram[(x)] = y; } } |
27 | 27 |
#define PEEK16(o, x) { o = (u->ram[(x)] << 8) + u->ram[(x) + 1]; } |
28 | 28 |
#define PEEK(o, x) { if(bs) { PEEK16(o, x) } else { o = u->ram[(x)]; } } |
29 |
-#define DEVR(o, d, x) { dev = (d); o = dev->dei(dev, (x) & 0x0f); if(bs) { o = (o << 8) + dev->dei(dev, ((x) + 1) & 0x0f); } } |
|
30 |
-#define DEVW8(x, y) { dev->dat[(x) & 0xf] = y; dev->deo(dev, (x) & 0x0f); } |
|
31 |
-#define DEVW(d, x, y) { dev = (d); if(bs) { DEVW8((x), (y) >> 8); DEVW8((x) + 1, (y)); } else { DEVW8((x), (y)) } } |
|
29 |
+ |
|
30 |
+#define DEVROLD(o, d, x) { dev = (d); o = dev->dei(dev, (x) & 0x0f); if(bs) { o = (o << 8) + dev->dei(dev, ((x) + 1) & 0x0f); } } |
|
31 |
+#define DEVW8OLD(x, y) { dev->dat[(x) & 0xf] = y; dev->deo(dev, (x) & 0x0f); } |
|
32 |
+#define DEVWOLD(d, x, y) { dev = (d); if(bs) { DEVW8OLD((x), (y) >> 8); DEVW8OLD((x) + 1, (y)); } else { DEVW8OLD((x), (y)) } } |
|
33 |
+ |
|
32 | 34 |
#define WARP(x) { if(bs) pc = (x); else pc += (Sint8)(x); } |
33 | 35 |
#define LIMIT 0x40000 /* around 3 ms */ |
34 | 36 |
|
... | ... |
@@ -40,7 +42,7 @@ uxn_eval(Uxn *u, Uint16 pc) |
40 | 42 |
Uint8 kptr, *sp; |
41 | 43 |
Stack *src, *dst; |
42 | 44 |
Device *dev; |
43 |
- if(!pc || u->dev[0].dat[0xf]) return 0; |
|
45 |
+ if(!pc || u->devold[0].dat[0xf]) return 0; |
|
44 | 46 |
while((instr = u->ram[pc++])) { |
45 | 47 |
if(!limit--) { |
46 | 48 |
if(!uxn_interrupt()) { |
... | ... |
@@ -90,8 +92,8 @@ uxn_eval(Uxn *u, Uint16 pc) |
90 | 92 |
case 0x13: /* STR */ POP8(a) POP(b) c = pc + (Sint8)a; POKE(c, b) break; |
91 | 93 |
case 0x14: /* LDA */ POP16(a) PEEK(b, a) PUSH(src, b) break; |
92 | 94 |
case 0x15: /* STA */ POP16(a) POP(b) POKE(a, b) break; |
93 |
- case 0x16: /* DEI */ POP8(a) DEVR(b, &u->dev[a >> 4], a) PUSH(src, b) break; |
|
94 |
- case 0x17: /* DEO */ POP8(a) POP(b) DEVW(&u->dev[a >> 4], a, b) break; |
|
95 |
+ case 0x16: /* DEI */ POP8(a) DEVROLD(b, &u->devold[a >> 4], a) PUSH(src, b) break; |
|
96 |
+ case 0x17: /* DEO */ POP8(a) POP(b) DEVWOLD(&u->devold[a >> 4], a, b) break; |
|
95 | 97 |
/* Arithmetic */ |
96 | 98 |
case 0x18: /* ADD */ POP(a) POP(b) PUSH(src, b + a) break; |
97 | 99 |
case 0x19: /* SUB */ POP(a) POP(b) PUSH(src, b - a) break; |
... | ... |
@@ -129,7 +131,7 @@ uxn_boot(Uxn *u, Uint8 *ram, Dei *dei, Deo *deo) |
129 | 131 |
Device * |
130 | 132 |
uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(Device *d, Uint8 port)) |
131 | 133 |
{ |
132 |
- Device *d = &u->dev[id]; |
|
134 |
+ Device *d = &u->devold[id]; |
|
133 | 135 |
d->u = u; |
134 | 136 |
d->dei = deifn; |
135 | 137 |
d->deo = deofn; |
... | ... |
@@ -69,7 +69,7 @@ nil_deo(Device *d, Uint8 port) |
69 | 69 |
static int |
70 | 70 |
console_input(Uxn *u, char c) |
71 | 71 |
{ |
72 |
- Device *d = &u->dev[1]; |
|
72 |
+ Device *d = &u->devold[1]; |
|
73 | 73 |
d->dat[0x2] = c; |
74 | 74 |
return uxn_eval(u, GETVECTOR(d)); |
75 | 75 |
} |
... | ... |
@@ -77,7 +77,7 @@ console_input(Uxn *u, char c) |
77 | 77 |
static void |
78 | 78 |
run(Uxn *u) |
79 | 79 |
{ |
80 |
- Device *d = &u->dev[0]; |
|
80 |
+ Device *d = &u->devold[0]; |
|
81 | 81 |
while(!d->dat[0xf]) { |
82 | 82 |
int c = fgetc(stdin); |
83 | 83 |
if(c != EOF) |
... | ... |
@@ -386,7 +386,7 @@ do_shortcut(Uxn *u, SDL_Event *event) |
386 | 386 |
static int |
387 | 387 |
console_input(Uxn *u, char c) |
388 | 388 |
{ |
389 |
- Device *d = &u->dev[1]; |
|
389 |
+ Device *d = &u->devold[1]; |
|
390 | 390 |
d->dat[0x2] = c; |
391 | 391 |
return uxn_eval(u, GETVECTOR(d)); |
392 | 392 |
} |
... | ... |
@@ -413,22 +413,22 @@ handle_events(Uxn *u) |
413 | 413 |
} |
414 | 414 |
/* Mouse */ |
415 | 415 |
else if(event.type == SDL_MOUSEMOTION) |
416 |
- mouse_pos(u, u->dev[9].dat, clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1)); |
|
416 |
+ mouse_pos(u, u->devold[9].dat, clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1)); |
|
417 | 417 |
else if(event.type == SDL_MOUSEBUTTONUP) |
418 |
- mouse_up(u, u->dev[9].dat, SDL_BUTTON(event.button.button)); |
|
418 |
+ mouse_up(u, u->devold[9].dat, SDL_BUTTON(event.button.button)); |
|
419 | 419 |
else if(event.type == SDL_MOUSEBUTTONDOWN) |
420 |
- mouse_down(u, u->dev[9].dat, SDL_BUTTON(event.button.button)); |
|
420 |
+ mouse_down(u, u->devold[9].dat, SDL_BUTTON(event.button.button)); |
|
421 | 421 |
else if(event.type == SDL_MOUSEWHEEL) |
422 |
- mouse_scroll(u, u->dev[9].dat, event.wheel.x, event.wheel.y); |
|
422 |
+ mouse_scroll(u, u->devold[9].dat, event.wheel.x, event.wheel.y); |
|
423 | 423 |
/* Controller */ |
424 | 424 |
else if(event.type == SDL_TEXTINPUT) |
425 |
- controller_key(u, u->dev[8].dat, event.text.text[0]); |
|
425 |
+ controller_key(u, u->devold[8].dat, event.text.text[0]); |
|
426 | 426 |
else if(event.type == SDL_KEYDOWN) { |
427 | 427 |
int ksym; |
428 | 428 |
if(get_key(&event)) |
429 |
- controller_key(u, u->dev[8].dat, get_key(&event)); |
|
429 |
+ controller_key(u, u->devold[8].dat, get_key(&event)); |
|
430 | 430 |
else if(get_button(&event)) |
431 |
- controller_down(u, u->dev[8].dat, get_button(&event)); |
|
431 |
+ controller_down(u, u->devold[8].dat, get_button(&event)); |
|
432 | 432 |
else |
433 | 433 |
do_shortcut(u, &event); |
434 | 434 |
ksym = event.key.keysym.sym; |
... | ... |
@@ -436,17 +436,17 @@ handle_events(Uxn *u) |
436 | 436 |
return 1; |
437 | 437 |
} |
438 | 438 |
} else if(event.type == SDL_KEYUP) |
439 |
- controller_up(u, u->dev[8].dat, get_button(&event)); |
|
439 |
+ controller_up(u, u->devold[8].dat, get_button(&event)); |
|
440 | 440 |
else if(event.type == SDL_JOYAXISMOTION) { |
441 | 441 |
Uint8 vec = get_vector_joystick(&event); |
442 | 442 |
if(!vec) |
443 |
- controller_up(u, u->dev[8].dat, (3 << (!event.jaxis.axis * 2)) << 4); |
|
443 |
+ controller_up(u, u->devold[8].dat, (3 << (!event.jaxis.axis * 2)) << 4); |
|
444 | 444 |
else |
445 |
- controller_down(u, u->dev[8].dat, (1 << ((vec + !event.jaxis.axis * 2) - 1)) << 4); |
|
445 |
+ controller_down(u, u->devold[8].dat, (1 << ((vec + !event.jaxis.axis * 2) - 1)) << 4); |
|
446 | 446 |
} else if(event.type == SDL_JOYBUTTONDOWN) |
447 |
- controller_down(u, u->dev[8].dat, get_button_joystick(&event)); |
|
447 |
+ controller_down(u, u->devold[8].dat, get_button_joystick(&event)); |
|
448 | 448 |
else if(event.type == SDL_JOYBUTTONUP) |
449 |
- controller_up(u, u->dev[8].dat, get_button_joystick(&event)); |
|
449 |
+ controller_up(u, u->devold[8].dat, get_button_joystick(&event)); |
|
450 | 450 |
/* Console */ |
451 | 451 |
else if(event.type == stdin_event) |
452 | 452 |
console_input(u, event.cbutton.button); |
... | ... |
@@ -457,7 +457,7 @@ handle_events(Uxn *u) |
457 | 457 |
static int |
458 | 458 |
run(Uxn *u) |
459 | 459 |
{ |
460 |
- Device *devsys = &u->dev[0]; |
|
460 |
+ Device *devsys = &u->devold[0]; |
|
461 | 461 |
Uint64 now = SDL_GetPerformanceCounter(), frame_end, frame_interval = SDL_GetPerformanceFrequency() / 60; |
462 | 462 |
for(;;) { |
463 | 463 |
/* .System/halt */ |