uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 68d706be25a2b8cba779c00b5523b21c95a7c5d5
parent 0fd68e96f0ebfd880675f33128978d91a0b91ff6
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sun,  1 Jan 2023 12:12:59 -0800

Will connect devices to devold while I migrate to new router

Diffstat:
Msrc/devices/file.c | 2+-
Msrc/uxn.c | 16+++++++++-------
Msrc/uxn.h | 2+-
Msrc/uxncli.c | 4++--
Msrc/uxnemu.c | 28++++++++++++++--------------
5 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/src/devices/file.c b/src/devices/file.c @@ -154,7 +154,7 @@ file_delete(UxnFile *c) static UxnFile * file_instance(Device *d) { - return &uxn_file[d - &d->u->dev[DEV_FILE0]]; + return &uxn_file[d - &d->u->devold[DEV_FILE0]]; } /* IO */ diff --git a/src/uxn.c b/src/uxn.c @@ -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 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 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 DEVW(d, x, y) { dev = (d); if(bs) { DEVW8((x), (y) >> 8); DEVW8((x) + 1, (y)); } else { DEVW8((x), (y)) } } + +#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 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 LIMIT 0x40000 /* around 3 ms */ @@ -40,7 +42,7 @@ uxn_eval(Uxn *u, Uint16 pc) Uint8 kptr, *sp; Stack *src, *dst; 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++])) { if(!limit--) { 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 0x14: /* LDA */ POP16(a) PEEK(b, a) PUSH(src, 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 0x17: /* DEO */ POP8(a) POP(b) DEVW(&u->dev[a >> 4], a, 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) DEVWOLD(&u->devold[a >> 4], a, b) break; /* Arithmetic */ case 0x18: /* ADD */ 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 * 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->dei = deifn; d->deo = deofn; diff --git a/src/uxn.h b/src/uxn.h @@ -48,7 +48,7 @@ typedef struct Device { typedef struct Uxn { Uint8 *ram; Stack wst, rst; - Device dev[16]; + Device devold[16]; Uint8 (*dei)(struct Uxn *u, Uint8 addr); void (*deo)(struct Uxn *u, Uint8 addr, Uint8 value); } Uxn; diff --git a/src/uxncli.c b/src/uxncli.c @@ -69,7 +69,7 @@ nil_deo(Device *d, Uint8 port) static int console_input(Uxn *u, char c) { - Device *d = &u->dev[1]; + Device *d = &u->devold[1]; d->dat[0x2] = c; return uxn_eval(u, GETVECTOR(d)); } @@ -77,7 +77,7 @@ console_input(Uxn *u, char c) static void run(Uxn *u) { - Device *d = &u->dev[0]; + Device *d = &u->devold[0]; while(!d->dat[0xf]) { int c = fgetc(stdin); if(c != EOF) diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -386,7 +386,7 @@ do_shortcut(Uxn *u, SDL_Event *event) static int console_input(Uxn *u, char c) { - Device *d = &u->dev[1]; + Device *d = &u->devold[1]; d->dat[0x2] = c; return uxn_eval(u, GETVECTOR(d)); } @@ -413,22 +413,22 @@ handle_events(Uxn *u) } /* Mouse */ 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) - 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) - 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) - 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 */ 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) { int ksym; 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)) - controller_down(u, u->dev[8].dat, get_button(&event)); + controller_down(u, u->devold[8].dat, get_button(&event)); else do_shortcut(u, &event); ksym = event.key.keysym.sym; @@ -436,17 +436,17 @@ handle_events(Uxn *u) return 1; } } 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) { Uint8 vec = get_vector_joystick(&event); 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 - 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) - 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) - controller_up(u, u->dev[8].dat, get_button_joystick(&event)); + controller_up(u, u->devold[8].dat, get_button_joystick(&event)); /* Console */ else if(event.type == stdin_event) console_input(u, event.cbutton.button); @@ -457,7 +457,7 @@ handle_events(Uxn *u) static int run(Uxn *u) { - Device *devsys = &u->dev[0]; + Device *devsys = &u->devold[0]; Uint64 now = SDL_GetPerformanceCounter(), frame_end, frame_interval = SDL_GetPerformanceFrequency() / 60; for(;;) { /* .System/halt */