Ported screen to new device

This commit is contained in:
Devine Lu Linvega 2023-01-01 13:34:20 -08:00
parent 7afe1f39c7
commit bf4ee03d27
4 changed files with 40 additions and 40 deletions

View File

@ -144,52 +144,52 @@ screen_dei(Uint8 *d, Uint8 port)
} }
void void
screen_deo(Device *d, Uint8 port) screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
{ {
switch(port) { switch(port) {
case 0x3: case 0x3:
if(!FIXED_SIZE) { if(!FIXED_SIZE) {
Uint16 w; Uint16 w;
DEVPEEK16(w, 0x2); PEKDEV(w, 0x2);
screen_resize(&uxn_screen, clamp(w, 1, 1024), uxn_screen.height); screen_resize(&uxn_screen, clamp(w, 1, 1024), uxn_screen.height);
} }
break; break;
case 0x5: case 0x5:
if(!FIXED_SIZE) { if(!FIXED_SIZE) {
Uint16 h; Uint16 h;
DEVPEEK16(h, 0x4); PEKDEV(h, 0x4);
screen_resize(&uxn_screen, uxn_screen.width, clamp(h, 1, 1024)); screen_resize(&uxn_screen, uxn_screen.width, clamp(h, 1, 1024));
} }
break; break;
case 0xe: { case 0xe: {
Uint16 x, y; Uint16 x, y;
Uint8 layer = d->dat[0xe] & 0x40; Uint8 layer = d[0xe] & 0x40;
DEVPEEK16(x, 0x8); PEKDEV(x, 0x8);
DEVPEEK16(y, 0xa); PEKDEV(y, 0xa);
screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d->dat[0xe] & 0x3); screen_write(&uxn_screen, layer ? &uxn_screen.fg : &uxn_screen.bg, x, y, d[0xe] & 0x3);
if(d->dat[0x6] & 0x01) DEVPOKE16(0x8, x + 1); /* auto x+1 */ if(d[0x6] & 0x01) POKDEV(0x8, x + 1); /* auto x+1 */
if(d->dat[0x6] & 0x02) DEVPOKE16(0xa, y + 1); /* auto y+1 */ if(d[0x6] & 0x02) POKDEV(0xa, y + 1); /* auto y+1 */
break; break;
} }
case 0xf: { case 0xf: {
Uint16 x, y, dx, dy, addr; Uint16 x, y, dx, dy, addr;
Uint8 i, n, twobpp = !!(d->dat[0xf] & 0x80); Uint8 i, n, twobpp = !!(d[0xf] & 0x80);
Layer *layer = (d->dat[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg; Layer *layer = (d[0xf] & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
DEVPEEK16(x, 0x8); PEKDEV(x, 0x8);
DEVPEEK16(y, 0xa); PEKDEV(y, 0xa);
DEVPEEK16(addr, 0xc); PEKDEV(addr, 0xc);
n = d->dat[0x6] >> 4; n = d[0x6] >> 4;
dx = (d->dat[0x6] & 0x01) << 3; dx = (d[0x6] & 0x01) << 3;
dy = (d->dat[0x6] & 0x02) << 2; dy = (d[0x6] & 0x02) << 2;
if(addr > 0x10000 - ((n + 1) << (3 + twobpp))) if(addr > 0x10000 - ((n + 1) << (3 + twobpp)))
return; return;
for(i = 0; i <= n; i++) { 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); 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->dat[0x6] & 0x04) << (1 + twobpp); addr += (d[0x6] & 0x04) << (1 + twobpp);
} }
DEVPOKE16(0xc, addr); /* auto addr+length */ POKDEV(0xc, addr); /* auto addr+length */
DEVPOKE16(0x8, x + dx); /* auto x+8 */ POKDEV(0x8, x + dx); /* auto x+8 */
DEVPOKE16(0xa, y + dy); /* auto y+8 */ POKDEV(0xa, y + dy); /* auto y+8 */
break; break;
} }
} }

View File

@ -32,5 +32,5 @@ void screen_redraw(UxnScreen *p, Uint32 *pixels);
void screen_mono(UxnScreen *p, Uint32 *pixels); void screen_mono(UxnScreen *p, Uint32 *pixels);
Uint8 screen_dei(Uint8 *d, Uint8 port); 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); int clamp(int val, int min, int max);

View File

@ -37,8 +37,8 @@ console_input(Uxn *u, char c)
static void static void
console_deo(Uint8 *d, Uint8 port) console_deo(Uint8 *d, Uint8 port)
{ {
FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr : FILE *fd = port == 0x8 ? stdout : port == 0x9 ? stderr
0; : 0;
if(fd) { if(fd) {
fputc(d[port], fd); fputc(d[port], fd);
fflush(fd); fflush(fd);

View File

@ -212,7 +212,7 @@ emu_dei(Uxn *u, Uint8 addr)
static void static void
emu_deo(Uxn *u, Uint8 addr, Uint8 v) 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); Uint16 mask = 0x1 << (d >> 4);
u->dev[addr] = v; u->dev[addr] = v;
switch(d) { switch(d) {
@ -222,7 +222,7 @@ Uint8 p = addr & 0x0f, d = addr & 0xf0;
screen_palette(&uxn_screen, &u->dev[0x8]); screen_palette(&uxn_screen, &u->dev[0x8]);
break; break;
case 0x10: console_deo(&u->dev[d], p); 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 0xa0: file_deo(0, u->ram, &u->dev[d], p); break;
case 0xb0: file_deo(1, 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 */ /* Mouse */
else if(event.type == SDL_MOUSEMOTION) 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) 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) 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) 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 */ /* Controller */
else if(event.type == SDL_TEXTINPUT) 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) { else if(event.type == SDL_KEYDOWN) {
int ksym; int ksym;
if(get_key(&event)) 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)) 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 else
do_shortcut(u, &event); do_shortcut(u, &event);
ksym = event.key.keysym.sym; ksym = event.key.keysym.sym;
@ -429,17 +429,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->devold[8].dat, get_button(&event)); controller_up(u, &u->dev[0x80], 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->devold[8].dat, (3 << (!event.jaxis.axis * 2)) << 4); controller_up(u, &u->dev[0x80], (3 << (!event.jaxis.axis * 2)) << 4);
else 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) } 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) 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 */ /* 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);