From 808ad8cf22b03bae661e462410a13cdc836a080b Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 8 Aug 2021 11:41:46 +0200 Subject: Update screen_talk function to use updated PPU --- src/main.c | 104 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 61 insertions(+), 43 deletions(-) diff --git a/src/main.c b/src/main.c index 0e56897..06d2d5b 100644 --- a/src/main.c +++ b/src/main.c @@ -135,27 +135,45 @@ screen_talk(Device *d, u8 b0, u8 w) { u8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; u8 *layer = d->dat[0xe] >> 4 & 0x1 ? ppu.fg : ppu.bg; u8 mode = d->dat[0xe] >> 5; + u8 color = d->dat[0xf] & 0xf; if(!mode) { ppu_pixel(layer, x, y, d->dat[0xe] & 0x3); } else if(mode-- & 0x1) { - ppu_1bpp(layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); + u8 flipx = mode & 0x2; + u8 flipy = mode & 0x4; + ppu_1bpp(layer, x, y, addr, color, flipx, flipy); } else { - ppu_2bpp(layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); + u8 flipx = mode & 0x2; + u8 flipy = mode & 0x4; + ppu_2bpp(layer, x, y, addr, color, flipx, flipy); + } + } else if(w && b0 == 0xf) { + u16 x = mempeek16(d->dat, 0x8); + u16 y = mempeek16(d->dat, 0xa); + u8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; + u8 *layer = d->dat[0xf] >> 6 & 0x1 ? ppu.fg : ppu.bg; + u8 color = d->dat[0xf] & 0xf; + u8 flipx = (d->dat[0xf] >> 0x4) & 0x1; + u8 flipy = (d->dat[0xf] >> 0x5) & 0x1; + if(d->dat[0xf] >> 0x7 & 0x1) { + ppu_2bpp(layer, x, y, addr, color, flipx, flipy); + } else { + ppu_1bpp(layer, x, y, addr, color, flipx, flipy); } } } static void audio_talk(Device *d, u8 b0, u8 w) { - AudioChannel *c = &channels[d - devaudio]; - if(!w) { - if(b0 == 0x2) { - mempoke16(d->dat, 0x2, c->pos); - c->pos <<= 12; // fixed point. + AudioChannel *c = &channels[d - devaudio]; + if(!w) { + if(b0 == 0x2) { + mempoke16(d->dat, 0x2, c->pos); + c->pos <<= 12; // fixed point. } else if(b0 == 0x4) { - // d->dat[0x4] = apu_get_vu(c); + // d->dat[0x4] = apu_get_vu(c); } - } else if(b0 == 0xf) { + } else if(b0 == 0xf) { u16 length = mempeek16(d->dat, 0xa); u8 *data = &d->mem[mempeek16(d->dat, 0xc)]; u8 pitch = d->dat[0xf] & 0x7f; @@ -163,20 +181,20 @@ audio_talk(Device *d, u8 b0, u8 w) { u32 vol = MAX(d->dat[0xe] >> 4, d->dat[0xe] & 0xf) * 4 / 3; bool loop = !(d->dat[0xf] & 0x80); update_channel(c, data, length, pitch, adsr, vol, loop); - } + } } void datetime_talk(Device *d, u8 b0, u8 w) { - (void)d; - (void)b0; - (void)w; + (void)d; + (void)b0; + (void)w; } void file_talk(Device *d, u8 b0, u8 w) { - u8 read = b0 == 0xd; - if(w && (read || b0 == 0xf)) { + u8 read = b0 == 0xd; + if(w && (read || b0 == 0xf)) { char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)]; u16 result = 0, length = mempeek16(d->dat, 0xa); u16 offset = mempeek16(d->dat, 0x4); @@ -187,7 +205,7 @@ file_talk(Device *d, u8 b0, u8 w) { } File file = fs_open_file(name, mode); if (file.index != FS_NULL) { - if(fs_seek(&file, offset, SEEK_SET) != -1) { + if(fs_seek(&file, offset, SEEK_SET) != -1) { if (read) { result = fs_read(&d->mem[addr], length, &file); } else { @@ -195,8 +213,8 @@ file_talk(Device *d, u8 b0, u8 w) { } } } - mempoke16(d->dat, 0x2, result); - } + mempoke16(d->dat, 0x2, result); + } } void @@ -219,10 +237,10 @@ init_uxn(Uxn *u) { portuxn(u, 0x5, "audio2", audio_talk); portuxn(u, 0x6, "audio3", audio_talk); portuxn(u, 0x7, "---", nil_talk); - devctrl = portuxn(u, 0x8, "controller", nil_talk); - devmouse = portuxn(u, 0x9, "mouse", nil_talk); - portuxn(u, 0xa, "file", file_talk); - portuxn(u, 0xb, "datetime", datetime_talk); + devctrl = portuxn(u, 0x8, "controller", nil_talk); + devmouse = portuxn(u, 0x9, "mouse", nil_talk); + portuxn(u, 0xa, "file", file_talk); + portuxn(u, 0xb, "datetime", datetime_talk); portuxn(u, 0xc, "---", nil_talk); portuxn(u, 0xd, "---", nil_talk); portuxn(u, 0xe, "---", nil_talk); @@ -235,33 +253,33 @@ IWRAM_CODE void handle_input(Uxn *u) { poll_keys(); - if (key_tap(KEY_SELECT)) { - // Reset control variables on method switch. - switch (ctrl_methods[ctrl_idx]) { - case CONTROL_CONTROLLER: { + if (key_tap(KEY_SELECT)) { + // Reset control variables on method switch. + switch (ctrl_methods[ctrl_idx]) { + case CONTROL_CONTROLLER: { devctrl->dat[2] = 0; evaluxn(u, mempeek16(devctrl->dat, 0)); devctrl->dat[3] = 0; } break; - case CONTROL_MOUSE: { - devmouse->dat[6] = 0; - devmouse->dat[7] = 0; + case CONTROL_MOUSE: { + devmouse->dat[6] = 0; + devmouse->dat[7] = 0; mempoke16(devmouse->dat, 0x2, -10); mempoke16(devmouse->dat, 0x4, -10); evaluxn(u, mempeek16(devmouse->dat, 0)); } break; - case CONTROL_KEYBOARD: { + case CONTROL_KEYBOARD: { toggle_keyboard(); } break; - } + } - // Update ctrl_idx. - ctrl_idx = (ctrl_idx + 1 > (int)LEN(ctrl_methods) - 1) ? 0 : ctrl_idx + 1; + // Update ctrl_idx. + ctrl_idx = (ctrl_idx + 1 > (int)LEN(ctrl_methods) - 1) ? 0 : ctrl_idx + 1; - // Initialize controller variables here. - if (ctrl_methods[ctrl_idx] == CONTROL_KEYBOARD) { - toggle_keyboard(); - } + // Initialize controller variables here. + if (ctrl_methods[ctrl_idx] == CONTROL_KEYBOARD) { + toggle_keyboard(); + } } if (ctrl_methods[ctrl_idx] == CONTROL_CONTROLLER) { @@ -313,7 +331,7 @@ handle_input(Uxn *u) { devctrl->dat[3] = 0; } else if (ctrl_methods[ctrl_idx] == CONTROL_MOUSE) { // Detect "mouse key press". - u8 flag = devmouse->dat[6]; + u8 flag = devmouse->dat[6]; if (key_tap(KEY_B)) { flag |= 0x01; } else if (key_released(KEY_B)) { @@ -327,11 +345,11 @@ handle_input(Uxn *u) { // Handle chording. devmouse->dat[6] = flag; - if(flag == 0x10 && (devmouse->dat[6] & 0x01)) { - devmouse->dat[7] = 0x01; + if(flag == 0x10 && (devmouse->dat[6] & 0x01)) { + devmouse->dat[7] = 0x01; } - if(flag == 0x01 && (devmouse->dat[6] & 0x10)) { - devmouse->dat[7] = 0x10; + if(flag == 0x01 && (devmouse->dat[6] & 0x10)) { + devmouse->dat[7] = 0x10; } // Detect mouse movement. @@ -349,7 +367,7 @@ handle_input(Uxn *u) { // Eval mouse. mempoke16(devmouse->dat, 0x2, mouse.x); mempoke16(devmouse->dat, 0x4, mouse.y); - evaluxn(u, mempeek16(devmouse->dat, 0)); + evaluxn(u, mempeek16(devmouse->dat, 0)); } else if (ctrl_methods[ctrl_idx] == CONTROL_KEYBOARD) { if (key_tap(KEY_LEFT)) { update_cursor(cursor_position - 1); -- cgit v1.2.1