Will connect devices to devold while I migrate to new router

This commit is contained in:
Devine Lu Linvega 2023-01-01 12:12:59 -08:00
parent 0fd68e96f0
commit 68d706be25
5 changed files with 27 additions and 25 deletions

View File

@ -154,7 +154,7 @@ file_delete(UxnFile *c)
static UxnFile * static UxnFile *
file_instance(Device *d) file_instance(Device *d)
{ {
return &uxn_file[d - &d->u->dev[DEV_FILE0]]; return &uxn_file[d - &d->u->devold[DEV_FILE0]];
} }
/* IO */ /* IO */

View File

@ -26,9 +26,11 @@ WITH REGARD TO THIS SOFTWARE.
#define POKE(x, y) { if(bs) { u->ram[(x)] = (y) >> 8; u->ram[(x) + 1] = (y); } else { u->ram[(x)] = y; } } #define POKE(x, y) { if(bs) { u->ram[(x)] = (y) >> 8; u->ram[(x) + 1] = (y); } else { u->ram[(x)] = y; } }
#define PEEK16(o, x) { o = (u->ram[(x)] << 8) + u->ram[(x) + 1]; } #define PEEK16(o, x) { o = (u->ram[(x)] << 8) + u->ram[(x) + 1]; }
#define PEEK(o, x) { if(bs) { PEEK16(o, x) } else { o = u->ram[(x)]; } } #define PEEK(o, x) { if(bs) { PEEK16(o, x) } else { o = u->ram[(x)]; } }
#define DEVR(o, d, x) { dev = (d); o = dev->dei(dev, (x) & 0x0f); if(bs) { o = (o << 8) + dev->dei(dev, ((x) + 1) & 0x0f); } }
#define DEVW8(x, y) { dev->dat[(x) & 0xf] = y; dev->deo(dev, (x) & 0x0f); } #define DEVROLD(o, d, x) { dev = (d); o = dev->dei(dev, (x) & 0x0f); if(bs) { o = (o << 8) + dev->dei(dev, ((x) + 1) & 0x0f); } }
#define DEVW(d, x, y) { dev = (d); if(bs) { DEVW8((x), (y) >> 8); DEVW8((x) + 1, (y)); } else { DEVW8((x), (y)) } } #define DEVW8OLD(x, y) { dev->dat[(x) & 0xf] = y; dev->deo(dev, (x) & 0x0f); }
#define DEVWOLD(d, x, y) { dev = (d); if(bs) { DEVW8OLD((x), (y) >> 8); DEVW8OLD((x) + 1, (y)); } else { DEVW8OLD((x), (y)) } }
#define WARP(x) { if(bs) pc = (x); else pc += (Sint8)(x); } #define WARP(x) { if(bs) pc = (x); else pc += (Sint8)(x); }
#define LIMIT 0x40000 /* around 3 ms */ #define LIMIT 0x40000 /* around 3 ms */
@ -40,7 +42,7 @@ uxn_eval(Uxn *u, Uint16 pc)
Uint8 kptr, *sp; Uint8 kptr, *sp;
Stack *src, *dst; Stack *src, *dst;
Device *dev; Device *dev;
if(!pc || u->dev[0].dat[0xf]) return 0; if(!pc || u->devold[0].dat[0xf]) return 0;
while((instr = u->ram[pc++])) { while((instr = u->ram[pc++])) {
if(!limit--) { if(!limit--) {
if(!uxn_interrupt()) { if(!uxn_interrupt()) {
@ -90,8 +92,8 @@ uxn_eval(Uxn *u, Uint16 pc)
case 0x13: /* STR */ POP8(a) POP(b) c = pc + (Sint8)a; POKE(c, b) break; case 0x13: /* STR */ POP8(a) POP(b) c = pc + (Sint8)a; POKE(c, b) break;
case 0x14: /* LDA */ POP16(a) PEEK(b, a) PUSH(src, b) break; case 0x14: /* LDA */ POP16(a) PEEK(b, a) PUSH(src, b) break;
case 0x15: /* STA */ POP16(a) POP(b) POKE(a, b) break; case 0x15: /* STA */ POP16(a) POP(b) POKE(a, b) break;
case 0x16: /* DEI */ POP8(a) DEVR(b, &u->dev[a >> 4], a) PUSH(src, b) break; case 0x16: /* DEI */ POP8(a) DEVROLD(b, &u->devold[a >> 4], a) PUSH(src, b) break;
case 0x17: /* DEO */ POP8(a) POP(b) DEVW(&u->dev[a >> 4], a, b) break; case 0x17: /* DEO */ POP8(a) POP(b) DEVWOLD(&u->devold[a >> 4], a, b) break;
/* Arithmetic */ /* Arithmetic */
case 0x18: /* ADD */ POP(a) POP(b) PUSH(src, b + a) break; case 0x18: /* ADD */ POP(a) POP(b) PUSH(src, b + a) break;
case 0x19: /* SUB */ POP(a) POP(b) PUSH(src, b - a) break; 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)
Device * Device *
uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(Device *d, Uint8 port)) uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *d, Uint8 port), void (*deofn)(Device *d, Uint8 port))
{ {
Device *d = &u->dev[id]; Device *d = &u->devold[id];
d->u = u; d->u = u;
d->dei = deifn; d->dei = deifn;
d->deo = deofn; d->deo = deofn;

View File

@ -48,7 +48,7 @@ typedef struct Device {
typedef struct Uxn { typedef struct Uxn {
Uint8 *ram; Uint8 *ram;
Stack wst, rst; Stack wst, rst;
Device dev[16]; Device devold[16];
Uint8 (*dei)(struct Uxn *u, Uint8 addr); Uint8 (*dei)(struct Uxn *u, Uint8 addr);
void (*deo)(struct Uxn *u, Uint8 addr, Uint8 value); void (*deo)(struct Uxn *u, Uint8 addr, Uint8 value);
} Uxn; } Uxn;

View File

@ -69,7 +69,7 @@ nil_deo(Device *d, Uint8 port)
static int static int
console_input(Uxn *u, char c) console_input(Uxn *u, char c)
{ {
Device *d = &u->dev[1]; Device *d = &u->devold[1];
d->dat[0x2] = c; d->dat[0x2] = c;
return uxn_eval(u, GETVECTOR(d)); return uxn_eval(u, GETVECTOR(d));
} }
@ -77,7 +77,7 @@ console_input(Uxn *u, char c)
static void static void
run(Uxn *u) run(Uxn *u)
{ {
Device *d = &u->dev[0]; Device *d = &u->devold[0];
while(!d->dat[0xf]) { while(!d->dat[0xf]) {
int c = fgetc(stdin); int c = fgetc(stdin);
if(c != EOF) if(c != EOF)

View File

@ -386,7 +386,7 @@ do_shortcut(Uxn *u, SDL_Event *event)
static int static int
console_input(Uxn *u, char c) console_input(Uxn *u, char c)
{ {
Device *d = &u->dev[1]; Device *d = &u->devold[1];
d->dat[0x2] = c; d->dat[0x2] = c;
return uxn_eval(u, GETVECTOR(d)); return uxn_eval(u, GETVECTOR(d));
} }
@ -413,22 +413,22 @@ handle_events(Uxn *u)
} }
/* Mouse */ /* Mouse */
else if(event.type == SDL_MOUSEMOTION) else if(event.type == SDL_MOUSEMOTION)
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)); 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));
else if(event.type == SDL_MOUSEBUTTONUP) else if(event.type == SDL_MOUSEBUTTONUP)
mouse_up(u, u->dev[9].dat, SDL_BUTTON(event.button.button)); mouse_up(u, u->devold[9].dat, SDL_BUTTON(event.button.button));
else if(event.type == SDL_MOUSEBUTTONDOWN) else if(event.type == SDL_MOUSEBUTTONDOWN)
mouse_down(u, u->dev[9].dat, SDL_BUTTON(event.button.button)); mouse_down(u, u->devold[9].dat, SDL_BUTTON(event.button.button));
else if(event.type == SDL_MOUSEWHEEL) else if(event.type == SDL_MOUSEWHEEL)
mouse_scroll(u, u->dev[9].dat, event.wheel.x, event.wheel.y); mouse_scroll(u, u->devold[9].dat, event.wheel.x, event.wheel.y);
/* Controller */ /* Controller */
else if(event.type == SDL_TEXTINPUT) else if(event.type == SDL_TEXTINPUT)
controller_key(u, u->dev[8].dat, event.text.text[0]); controller_key(u, u->devold[8].dat, event.text.text[0]);
else if(event.type == SDL_KEYDOWN) { else if(event.type == SDL_KEYDOWN) {
int ksym; int ksym;
if(get_key(&event)) if(get_key(&event))
controller_key(u, u->dev[8].dat, get_key(&event)); controller_key(u, u->devold[8].dat, get_key(&event));
else if(get_button(&event)) else if(get_button(&event))
controller_down(u, u->dev[8].dat, get_button(&event)); controller_down(u, u->devold[8].dat, get_button(&event));
else else
do_shortcut(u, &event); do_shortcut(u, &event);
ksym = event.key.keysym.sym; ksym = event.key.keysym.sym;
@ -436,17 +436,17 @@ handle_events(Uxn *u)
return 1; return 1;
} }
} else if(event.type == SDL_KEYUP) } else if(event.type == SDL_KEYUP)
controller_up(u, u->dev[8].dat, get_button(&event)); controller_up(u, u->devold[8].dat, get_button(&event));
else if(event.type == SDL_JOYAXISMOTION) { else if(event.type == SDL_JOYAXISMOTION) {
Uint8 vec = get_vector_joystick(&event); Uint8 vec = get_vector_joystick(&event);
if(!vec) if(!vec)
controller_up(u, u->dev[8].dat, (3 << (!event.jaxis.axis * 2)) << 4); controller_up(u, u->devold[8].dat, (3 << (!event.jaxis.axis * 2)) << 4);
else else
controller_down(u, u->dev[8].dat, (1 << ((vec + !event.jaxis.axis * 2) - 1)) << 4); controller_down(u, u->devold[8].dat, (1 << ((vec + !event.jaxis.axis * 2) - 1)) << 4);
} else if(event.type == SDL_JOYBUTTONDOWN) } else if(event.type == SDL_JOYBUTTONDOWN)
controller_down(u, u->dev[8].dat, get_button_joystick(&event)); controller_down(u, u->devold[8].dat, get_button_joystick(&event));
else if(event.type == SDL_JOYBUTTONUP) else if(event.type == SDL_JOYBUTTONUP)
controller_up(u, u->dev[8].dat, get_button_joystick(&event)); controller_up(u, u->devold[8].dat, get_button_joystick(&event));
/* Console */ /* Console */
else if(event.type == stdin_event) else if(event.type == stdin_event)
console_input(u, event.cbutton.button); console_input(u, event.cbutton.button);
@ -457,7 +457,7 @@ handle_events(Uxn *u)
static int static int
run(Uxn *u) run(Uxn *u)
{ {
Device *devsys = &u->dev[0]; Device *devsys = &u->devold[0];
Uint64 now = SDL_GetPerformanceCounter(), frame_end, frame_interval = SDL_GetPerformanceFrequency() / 60; Uint64 now = SDL_GetPerformanceCounter(), frame_end, frame_interval = SDL_GetPerformanceFrequency() / 60;
for(;;) { for(;;) {
/* .System/halt */ /* .System/halt */