From b0c840437a0b96f4ca874cea864028ad553de1c5 Mon Sep 17 00:00:00 2001 From: neauoire Date: Tue, 5 Apr 2022 09:22:33 -0700 Subject: [PATCH] Removed screen as Device --- src/devices/screen.c | 48 ++++++++++++++++++++++---------------------- src/devices/screen.h | 4 ++-- src/uxn.h | 1 + src/uxn11.c | 6 +++--- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/devices/screen.c b/src/devices/screen.c index a261051..ddebf9d 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -117,64 +117,64 @@ clamp(int val, int min, int max) /* IO */ Uint8 -screen_dei(Device *d, Uint8 port) +screen_dei(Uint8 *d, Uint8 port) { switch(port) { case 0x2: return uxn_screen.width >> 8; case 0x3: return uxn_screen.width; case 0x4: return uxn_screen.height >> 8; case 0x5: return uxn_screen.height; - default: return d->dat[port]; + default: return d[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 index 8a19abb..3e9c648 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -29,6 +29,6 @@ void screen_resize(UxnScreen *p, Uint16 width, Uint16 height); void screen_clear(UxnScreen *p, Layer *layer); void screen_redraw(UxnScreen *p, Uint32 *pixels); -Uint8 screen_dei(Device *d, Uint8 port); -void screen_deo(Device *d, Uint8 port); +Uint8 screen_dei(Uint8 *d, Uint8 port); +void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); int clamp(int val, int min, int max); diff --git a/src/uxn.h b/src/uxn.h index e86b071..fab0d3b 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -25,6 +25,7 @@ typedef unsigned int Uint32; #define GETVEC(d) ((d)[0] << 8 | (d)[1]) #define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); } +#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; } /* clang-format on */ diff --git a/src/uxn11.c b/src/uxn11.c index 8cffed8..e23cb12 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -64,7 +64,7 @@ uxn11_dei(struct Uxn *u, Uint8 addr) Uint8 p = addr & 0x0f; Device *d = &u->dev[addr >> 4]; switch(addr & 0xf0) { - case 0x20: return screen_dei(d, p); break; + case 0x20: return screen_dei(d->dat, p); break; case 0xa0: return file_dei(d, p); break; case 0xb0: return file_dei(d, p); break; case 0xc0: return datetime_dei(d->dat, p); break; @@ -81,7 +81,7 @@ uxn11_deo(Uxn *u, Uint8 addr, Uint8 v) switch(addr & 0xf0) { case 0x00: system_deo(d, p); break; case 0x10: console_deo(d, p); break; - case 0x20: screen_deo(d, p); break; + case 0x20: screen_deo(u->ram, d->dat, p); break; case 0xa0: file_deo(d, p); break; case 0xb0: file_deo(d, p); break; } @@ -194,7 +194,7 @@ start(Uxn *u, char *rom) /* system */ uxn_port(u, 0x0, nil_dei, system_deo); /* console */ uxn_port(u, 0x1, nil_dei, console_deo); - /* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo); + /* screen */ devscreen = uxn_port(u, 0x2, nil_dei, nil_deo); /* empty */ uxn_port(u, 0x3, nil_dei, nil_deo); /* empty */ uxn_port(u, 0x4, nil_dei, nil_deo); /* empty */ uxn_port(u, 0x5, nil_dei, nil_deo);