uxn

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

commit bf4ee03d2794a5a56e59e354a72a9293ada0e3b1
parent 7afe1f39c70b279ae47e2ea8995c494eb0c56680
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Sun,  1 Jan 2023 13:34:20 -0800

Ported screen to new device

Diffstat:
Msrc/devices/screen.c | 44++++++++++++++++++++++----------------------
Msrc/devices/screen.h | 2+-
Msrc/uxncli.c | 4++--
Msrc/uxnemu.c | 30+++++++++++++++---------------
4 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/devices/screen.c b/src/devices/screen.c @@ -144,52 +144,52 @@ screen_dei(Uint8 *d, Uint8 port) } void -screen_deo(Device *d, Uint8 port) +screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) { switch(port) { case 0x3: if(!FIXED_SIZE) { Uint16 w; - DEVPEEK16(w, 0x2); + PEKDEV(w, 0x2); screen_resize(&uxn_screen, clamp(w, 1, 1024), uxn_screen.height); } break; case 0x5: if(!FIXED_SIZE) { Uint16 h; - DEVPEEK16(h, 0x4); + PEKDEV(h, 0x4); screen_resize(&uxn_screen, uxn_screen.width, clamp(h, 1, 1024)); } break; case 0xe: { Uint16 x, y; - Uint8 layer = d->dat[0xe] & 0x40; - DEVPEEK16(x, 0x8); - DEVPEEK16(y, 0xa); - screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d->dat[0xe] & 0x3); - if(d->dat[0x6] & 0x01) DEVPOKE16(0x8, x + 1); /* auto x+1 */ - if(d->dat[0x6] & 0x02) DEVPOKE16(0xa, y + 1); /* auto y+1 */ + Uint8 layer = d[0xe] & 0x40; + PEKDEV(x, 0x8); + PEKDEV(y, 0xa); + screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d[0xe] & 0x3); + if(d[0x6] & 0x01) POKDEV(0x8, x + 1); /* auto x+1 */ + if(d[0x6] & 0x02) POKDEV(0xa, y + 1); /* auto y+1 */ break; } case 0xf: { Uint16 x, y, dx, dy, addr; - Uint8 i, n, twobpp = !!(d->dat[0xf] & 0x80); - Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; - DEVPEEK16(x, 0x8); - DEVPEEK16(y, 0xa); - DEVPEEK16(addr, 0xc); - n = d->dat[0x6] >> 4; - dx = (d->dat[0x6] & 0x01) << 3; - dy = (d->dat[0x6] & 0x02) << 2; + Uint8 i, n, twobpp = !!(d[0xf] & 0x80); + Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; + PEKDEV(x, 0x8); + PEKDEV(y, 0xa); + PEKDEV(addr, 0xc); + n = d[0x6] >> 4; + dx = (d[0x6] & 0x01) << 3; + dy = (d[0x6] & 0x02) << 2; if(addr > 0x10000 - ((n + 1) << (3 + twobpp))) return; for(i = 0; i <= n; i++) { - screen_blit(&uxn_screen, layer, x + dy * i, y + dx * i, &d->u->ram[addr], d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp); - addr += (d->dat[0x6] & 0x04) << (1 + twobpp); + screen_blit(&uxn_screen, layer, x + dy * i, y + dx * i, &ram[addr], d[0xf] & 0xf, d[0xf] & 0x10, d[0xf] & 0x20, twobpp); + addr += (d[0x6] & 0x04) << (1 + twobpp); } - DEVPOKE16(0xc, addr); /* auto addr+length */ - DEVPOKE16(0x8, x + dx); /* auto x+8 */ - DEVPOKE16(0xa, y + dy); /* auto y+8 */ + POKDEV(0xc, addr); /* auto addr+length */ + POKDEV(0x8, x + dx); /* auto x+8 */ + POKDEV(0xa, y + dy); /* auto y+8 */ break; } } diff --git a/src/devices/screen.h b/src/devices/screen.h @@ -32,5 +32,5 @@ void screen_redraw(UxnScreen *p, Uint32 *pixels); void screen_mono(UxnScreen *p, Uint32 *pixels); Uint8 screen_dei(Uint8 *d, Uint8 port); -void screen_deo(Device *d, Uint8 port); +void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); int clamp(int val, int min, int max); diff --git a/src/uxncli.c b/src/uxncli.c @@ -37,8 +37,8 @@ console_input(Uxn *u, char c) static void console_deo(Uint8 *d, Uint8 port) { - FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr : - 0; + FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr + : 0; if(fd) { fputc(d[port], fd); fflush(fd); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -200,7 +200,7 @@ emu_dei(Uxn *u, Uint8 addr) { Uint8 p = addr & 0x0f, d = addr & 0xf0; switch(d) { - case 0x20: return screen_dei(&u->dev[d], p); + case 0x20: return screen_dei(&u->dev[d], p); case 0xa0: return file_dei(0, &u->dev[d], p); case 0xb0: return file_dei(1, &u->dev[d], p); case 0xc0: return datetime_dei(&u->dev[d], p); @@ -212,7 +212,7 @@ emu_dei(Uxn *u, Uint8 addr) static void emu_deo(Uxn *u, Uint8 addr, Uint8 v) { -Uint8 p = addr & 0x0f, d = addr & 0xf0; + Uint8 p = addr & 0x0f, d = addr & 0xf0; Uint16 mask = 0x1 << (d >> 4); u->dev[addr] = v; switch(d) { @@ -222,7 +222,7 @@ Uint8 p = addr & 0x0f, d = addr & 0xf0; screen_palette(&uxn_screen, &u->dev[0x8]); break; case 0x10: console_deo(&u->dev[d], p); break; - /* case 0x20: screen_deo(u->ram, &u->dev[d], p); break; */ + case 0x20: screen_deo(u->ram, &u->dev[d], p); break; case 0xa0: file_deo(0, u->ram, &u->dev[d], p); break; case 0xb0: file_deo(1, u->ram, &u->dev[d], p); break; } @@ -406,22 +406,22 @@ handle_events(Uxn *u) } /* Mouse */ else if(event.type == SDL_MOUSEMOTION) - 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)); + mouse_pos(u, &u->dev[0x90], 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->devold[9].dat, SDL_BUTTON(event.button.button)); + mouse_up(u, &u->dev[0x90], SDL_BUTTON(event.button.button)); else if(event.type == SDL_MOUSEBUTTONDOWN) - mouse_down(u, u->devold[9].dat, SDL_BUTTON(event.button.button)); + mouse_down(u, &u->dev[0x90], SDL_BUTTON(event.button.button)); else if(event.type == SDL_MOUSEWHEEL) - mouse_scroll(u, u->devold[9].dat, event.wheel.x, event.wheel.y); + mouse_scroll(u, &u->dev[0x90], event.wheel.x, event.wheel.y); /* Controller */ else if(event.type == SDL_TEXTINPUT) - controller_key(u, u->devold[8].dat, event.text.text[0]); + controller_key(u, &u->dev[0x80], event.text.text[0]); else if(event.type == SDL_KEYDOWN) { int ksym; if(get_key(&event)) - controller_key(u, u->devold[8].dat, get_key(&event)); + controller_key(u, &u->dev[0x80], get_key(&event)); else if(get_button(&event)) - controller_down(u, u->devold[8].dat, get_button(&event)); + controller_down(u, &u->dev[0x80], get_button(&event)); else do_shortcut(u, &event); ksym = event.key.keysym.sym; @@ -429,17 +429,17 @@ handle_events(Uxn *u) return 1; } } else if(event.type == SDL_KEYUP) - controller_up(u, u->devold[8].dat, get_button(&event)); + controller_up(u, &u->dev[0x80], get_button(&event)); else if(event.type == SDL_JOYAXISMOTION) { Uint8 vec = get_vector_joystick(&event); if(!vec) - controller_up(u, u->devold[8].dat, (3 << (!event.jaxis.axis * 2)) << 4); + controller_up(u, &u->dev[0x80], (3 << (!event.jaxis.axis * 2)) << 4); else - controller_down(u, u->devold[8].dat, (1 << ((vec + !event.jaxis.axis * 2) - 1)) << 4); + controller_down(u, &u->dev[0x80], (1 << ((vec + !event.jaxis.axis * 2) - 1)) << 4); } else if(event.type == SDL_JOYBUTTONDOWN) - controller_down(u, u->devold[8].dat, get_button_joystick(&event)); + controller_down(u, &u->dev[0x80], get_button_joystick(&event)); else if(event.type == SDL_JOYBUTTONUP) - controller_up(u, u->devold[8].dat, get_button_joystick(&event)); + controller_up(u, &u->dev[0x80], get_button_joystick(&event)); /* Console */ else if(event.type == stdin_event) console_input(u, event.cbutton.button);