From c494e42cf2bdee38e842002f2a38e4108f869378 Mon Sep 17 00:00:00 2001 From: neauoire Date: Wed, 29 Sep 2021 20:54:27 -0700 Subject: [PATCH] Drawing is pixel-perfect again --- src/devices/ppu.c | 24 ++++++++++++++++-------- src/uxnemu.c | 1 - 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/devices/ppu.c b/src/devices/ppu.c index 5d61045..a492a13 100644 --- a/src/devices/ppu.c +++ b/src/devices/ppu.c @@ -24,12 +24,6 @@ static Uint8 blending[5][16] = { {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}, {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; -static Uint16 -ppu_row(Ppu *p, Uint16 x, Uint16 y) -{ - return (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16); -} - static void ppu_clear(Ppu *p) { @@ -46,9 +40,22 @@ Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y) { int row = (x + y * p->width) / 0x2; - int shift = (1 - (x & 0x1)) * 0x4; - return p->pixels[row] & 0x3; + if(x % 2) { + if(p->pixels[row] & 0x0c) { + return (p->pixels[row] >> 0x2) & 0x3; + } else { + return (p->pixels[row] >> 0x0) & 0x3; + } + } else { + if(p->pixels[row] & 0xc0) { + return (p->pixels[row] >> 0x6) & 0x3; + } else { + return (p->pixels[row] >> 0x4) & 0x3; + } + } + + return 0; } void @@ -65,6 +72,7 @@ ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color) next |= color << (4 + (layer * 2)); } p->pixels[row] = next; + p->reqdraw = 1; } void diff --git a/src/uxnemu.c b/src/uxnemu.c index 88cd5aa..1bcc3a5 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -410,7 +410,6 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) } if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */ if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */ - ppu.reqdraw = 1; break; } }