Added mirroring to the PPU

This commit is contained in:
neauoire 2021-04-29 10:10:07 -07:00
parent ec3c5a691b
commit 49182d1335
4 changed files with 83 additions and 20 deletions

View File

@ -19,8 +19,8 @@
|0100 ( -> )
( theme )
#0c5f .System/r DEO2
#022f .System/g DEO2
#025f .System/r DEO2
#0c2f .System/g DEO2
#0da4 .System/b DEO2
( find screen center )
@ -28,25 +28,78 @@
.Screen/height DEI2 #0002 DIV2 .center/y POK2
( draw )
;draw-table JSR2
;draw-sprites JSR2
;draw-circle JSR2
BRK
@draw-sprites ( -- )
;preview_icn .Screen/addr DEO2
#00 #ff
#00 #00
&loop
( move ) OVR #0f AND #40 SFT #02 DIV #00 SWP
.center/x PEK2 #0040 SUB2 ADD2 .Screen/x DEO2
( move ) OVR #f0 AND #02 DIV #00 SWP
.center/y PEK2 #0018 SUB2 ADD2 .Screen/y DEO2
.center/y PEK2 #0040 SUB2 ADD2 .Screen/y DEO2
( draw ) OVR .Screen/color DEO
( incr ) SWP #01 ADD SWP
DUP2 LTH ,&loop JNZ
DUP2 NEQ ,&loop JNZ
POP2
RTN
@preview_icn [ 183c 66db db66 3c18 0000 183c 3c18 0000 ]
@draw-table ( -- )
#00 #10
&loop
OVR #08 MUL #00 SWP ;font_hex ADD2 .Screen/addr DEO2
( x-axis )
OVR #08 MUL #00 SWP
.center/x PEK2 #0040 SUB2 ADD2 .Screen/x DEO2
.center/y PEK2 #0050 SUB2 .Screen/y DEO2
( draw ) #21 .Screen/color DEO
( y-axis )
OVR #08 MUL #00 SWP
.center/y PEK2 #0040 SUB2 ADD2 .Screen/y DEO2
.center/x PEK2 #0050 SUB2 .Screen/x DEO2
( draw ) #21 .Screen/color DEO
( incr ) SWP #01 ADD SWP
DUP2 LTH ,&loop JNZ
POP2
RTN
@draw-circle ( -- )
;preview_icn .Screen/addr DEO2
.center/x PEK2 #0048 ADD2 .Screen/x DEO2
.center/y PEK2 #0030 ADD2 .Screen/y DEO2
#21 .Screen/color DEO
.center/x PEK2 #0050 ADD2 .Screen/x DEO2
#61 .Screen/color DEO
.center/x PEK2 #0048 ADD2 .Screen/x DEO2
.center/y PEK2 #0038 ADD2 .Screen/y DEO2
#a1 .Screen/color DEO
.center/x PEK2 #0050 ADD2 .Screen/x DEO2
#f1 .Screen/color DEO
RTN
@preview_icn [
0f38 675f dfbf bfbf 0007 1820 2344 4848 ]
@font_hex [
007c 8282 8282 827c 0030 1010 1010 1010
007c 8202 7c80 80fe 007c 8202 1c02 827c
000c 1424 4484 fe04 00fe 8080 7c02 827c
007c 8280 fc82 827c 007c 8202 1e02 0202
007c 8282 7c82 827c 007c 8282 7e02 827c
007c 8202 7e82 827e 00fc 8282 fc82 82fc
007c 8280 8080 827c 00fc 8282 8282 82fc
007c 8280 f080 827c 007c 8280 f080 8080 ]

View File

@ -224,11 +224,13 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
Uint16 y = mempeek16(d->dat, 0xa);
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
Uint8 *layer = d->dat[0xe] >> 4 & 0x1 ? ppu.fg : ppu.bg;
switch(d->dat[0xe] >> 5) {
case 0: putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3); break;
case 1: puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf); break;
case 2: putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf); break;
}
Uint8 mode = d->dat[0xe] >> 5;
if(!mode)
putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3);
else if(mode % 2)
puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, d->dat[0xe] >> 6 & 0x1, d->dat[0xe] >> 7 & 0x1);
else
putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, d->dat[0xe] >> 6 & 0x1, d->dat[0xe] >> 7 & 0x1);
reqdraw = 1;
}
}

View File

@ -80,26 +80,34 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
}
void
puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
{
Uint16 v, h;
for(v = 0; v < 8; v++)
for(h = 0; h < 8; h++) {
Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
if(ch1 == 1 || (color != 0x05 && color != 0x0a && color != 0x0f))
putpixel(p, layer, x + h, y + v, ch1 ? color % 4 : color / 4);
putpixel(p,
layer,
x + (flipx ? 7 - h : h),
y + (flipy ? 7 - v : v),
ch1 ? color % 4 : color / 4);
}
}
void
putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
{
Uint16 v, h;
for(v = 0; v < 8; v++)
for(h = 0; h < 8; h++) {
Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1) * color;
Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1) * color;
putpixel(p, layer, x + h, y + v, (((ch1 + ch2 * 2) + color / 4) & 0x3));
putpixel(p,
layer,
x + (flipx ? 7 - h : h),
y + (flipy ? 7 - v : v),
(((ch1 + ch2 * 2) + color / 4) & 0x3));
}
}
@ -118,8 +126,8 @@ drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr)
Uint8 i, x, y, b;
for(i = 0; i < 0x20; ++i) { /* memory */
x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
puticn(p, p->bg, x, y, font[(b >> 4) & 0xf], 1 + (ptr == i) * 0x7);
puticn(p, p->bg, x + 8, y, font[b & 0xf], 1 + (ptr == i) * 0x7);
puticn(p, p->bg, x, y, font[(b >> 4) & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
puticn(p, p->bg, x + 8, y, font[b & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
}
for(x = 0; x < 0x20; ++x) {
drawpixel(p, x, p->height / 2, 2);

View File

@ -26,7 +26,7 @@ typedef struct Ppu {
int initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad);
void putcolors(Ppu *p, Uint8 *addr);
void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color);
void puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
void putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
void puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void drawppu(Ppu *p);
void drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr);