~rabbits/uxn-playdate

6327979733e1b5e20dec82473e630877ba3cdeb1 — Devine Lu Linvega 12 days ago d130754
Merged dei/deo switches into main
1 files changed, 44 insertions(+), 68 deletions(-)

M src/main.c
M src/main.c => src/main.c +44 -68
@@ 78,69 78,12 @@ system_cmd(Uint8 *ram, Uint16 addr)
	}
}

static void
system_deo(Uint8 *d, Uint8 port)
{
	switch(port) {
	case 0x3:
		system_cmd(u.ram, PEEK16(d + 0x2));
		break;
	}
}

static void
console_deo(Uint8 *d, Uint8 port)
{
	if(port == 0x8)
		pd->system->logToConsole("%c", d[port]);
}

Uint8
screen_dei(Uint8 *d, Uint8 port)
{
	switch(port) {
	case 0x2: return 0x1;
	case 0x3: return 0x90;
	case 0x4: return 0x00;
	case 0x5: return 0xf0;
	default: return d[port];
	}
}

void
screen_deo(Uint8 *d, Uint8 port)
{
	switch(port) {
	case 0xe: {
		Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa);
		Uint8 fg = !!(d[0xe] & 0x40);
		ppu_pixel(&ppu, fg, x, y, d[0xe] & 0x3);
		if(d[0x6] & 0x01) POKE16(d + 0x8, x + 1); /* auto x+1 */
		if(d[0x6] & 0x02) POKE16(d + 0xa, y + 1); /* auto y+1 */
		pd->graphics->markUpdatedRows(y, y);
		break;
	}
	case 0xf: {
		Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa), dx, dy, addr = PEEK16(d + 0xc);
		Uint8 i, n = d[0x6] >> 4, twobpp = !!(d[0xf] & 0x80);
		Uint8 fg = !!(d[0xf] & 0x40);
		dx = (d[0x6] & 0x01) << 3;
		dy = (d[0x6] & 0x02) << 2;
		if(addr >= 0xff00)
			return;
		for(i = 0; i <= n; i++) {
			if(!(d[0xf] & 0xf))
				screen_wipe(&ppu, fg, x + dy * i, y + dx * i);
			else
				screen_blit(&ppu, fg, x + dy * i, y + dx * i, &u.ram[addr], d[0xf] & 0xf, d[0xf] & 0x10, d[0xf] & 0x20, twobpp);
			addr += (d[0x6] & 0x04) << (1 + twobpp);
		}
		POKE16(d + 0xc, addr);   /* auto addr+length */
		POKE16(d + 0x8, x + dx); /* auto x+8 */
		POKE16(d + 0xa, y + dy); /* auto y+8 */
		pd->graphics->markUpdatedRows(y, y + 7 + n * 8);
		break;
	}
	default: return d[port];
	}
}



@@ 169,9 112,12 @@ audio_deo(Uint8 *d, Uint8 port)
static Uint8
emu_dei(Uxn *u, Uint8 addr)
{
	Uint8 p = addr & 0x0f, d = addr & 0xf0;
	switch(d) {
	case 0x20: return screen_dei(&u->dev[d], p);
	Uint8 *d = &u->dev[addr & 0xf0];
	switch(addr) {
	case 0x22: return 0x1;
	case 0x23: return 0x90;
	case 0x24: return 0x00;
	case 0x25: return 0xf0;
	}
	return u->dev[addr];
}


@@ 179,14 125,44 @@ emu_dei(Uxn *u, Uint8 addr)
static void
emu_deo(Uxn *u, Uint8 addr, Uint8 v)
{
	Uint8 p = addr & 0x0f, d = addr & 0xf0;
	Uint16 mask = 0x1 << (d >> 4);
	Uint8 *d = &u->dev[addr & 0xf0];
	u->dev[addr] = v;
	switch(d) {
	case 0x00: system_deo(&u->dev[d], p); break;
	case 0x10: console_deo(&u->dev[d], p); break;
	case 0x20: screen_deo(&u->dev[d], p); break;
	case 0x30: audio_deo(&u->dev[d], p); break;
	switch(addr) {
	/* system */
	case 0x03: system_cmd(u->ram, PEEK16(d + 0x2)); break;
	/* console */
	case 0x18: pd->system->logToConsole("%c", d[0x8]); break;
	/* screen */
	case 0x2e: {
		Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa);
		Uint8 fg = !!(d[0xe] & 0x40);
		ppu_pixel(&ppu, fg, x, y, d[0xe] & 0x3);
		if(d[0x6] & 0x01) POKE16(d + 0x8, x + 1); /* auto x+1 */
		if(d[0x6] & 0x02) POKE16(d + 0xa, y + 1); /* auto y+1 */
		pd->graphics->markUpdatedRows(y, y);
		break;
	}
	case 0x2f: {
		Uint16 x = PEEK16(d + 0x8), y = PEEK16(d + 0xa), dx, dy, addr = PEEK16(d + 0xc);
		Uint8 i, n = d[0x6] >> 4, twobpp = !!(d[0xf] & 0x80);
		Uint8 fg = !!(d[0xf] & 0x40);
		dx = (d[0x6] & 0x01) << 3;
		dy = (d[0x6] & 0x02) << 2;
		if(addr >= 0xff00)
			return;
		for(i = 0; i <= n; i++) {
			if(!(d[0xf] & 0xf))
				screen_wipe(&ppu, fg, x + dy * i, y + dx * i);
			else
				screen_blit(&ppu, fg, x + dy * i, y + dx * i, &u->ram[addr], d[0xf] & 0xf, d[0xf] & 0x10, d[0xf] & 0x20, twobpp);
			addr += (d[0x6] & 0x04) << (1 + twobpp);
		}
		POKE16(d + 0xc, addr);   /* auto addr+length */
		POKE16(d + 0x8, x + dx); /* auto x+8 */
		POKE16(d + 0xa, y + dy); /* auto y+8 */
		pd->graphics->markUpdatedRows(y, y + 7 + n * 8);
		break;
	}
	}
}