Browse code

Added mirroring to the PPU

neauoire authored on 29/04/2021 17:10:07
Showing 4 changed files
... ...
@@ -19,8 +19,8 @@
19 19
 |0100 ( -> )
20 20
 	
21 21
 	( theme ) 
22
-	#0c5f .System/r DEO2
23
-	#022f .System/g DEO2 
22
+	#025f .System/r DEO2
23
+	#0c2f .System/g DEO2 
24 24
 	#0da4 .System/b DEO2 
25 25
 
26 26
 	( find screen center )
... ...
@@ -28,25 +28,78 @@
28 28
 	.Screen/height DEI2 #0002 DIV2 .center/y POK2
29 29
 
30 30
 	( draw )
31
+	;draw-table JSR2
31 32
 	;draw-sprites JSR2
33
+	;draw-circle JSR2
32 34
 	
33 35
 BRK
34 36
 
35 37
 @draw-sprites ( -- )
36 38
 	
37 39
 	;preview_icn .Screen/addr DEO2
38
-
39
-	#00 #ff
40
+	#00 #00
40 41
 	&loop
41 42
 		( move ) OVR #0f AND #40 SFT #02 DIV #00 SWP 
42 43
 			.center/x PEK2 #0040 SUB2 ADD2 .Screen/x DEO2
43 44
 		( move ) OVR #f0 AND #02 DIV #00 SWP 
44
-			.center/y PEK2 #0018 SUB2 ADD2 .Screen/y DEO2
45
+			.center/y PEK2 #0040 SUB2 ADD2 .Screen/y DEO2
45 46
 		( draw ) OVR .Screen/color DEO
47
+		( incr ) SWP #01 ADD SWP
48
+		DUP2 NEQ ,&loop JNZ
49
+	POP2
50
+	
51
+RTN
52
+
53
+@draw-table ( -- )
54
+	
55
+	#00 #10
56
+	&loop
57
+		OVR #08 MUL #00 SWP ;font_hex ADD2 .Screen/addr DEO2
58
+
59
+		( x-axis ) 
60
+		OVR #08 MUL #00 SWP 
61
+		.center/x PEK2 #0040 SUB2 ADD2 .Screen/x DEO2
62
+		.center/y PEK2 #0050 SUB2 .Screen/y DEO2
63
+		( draw ) #21 .Screen/color DEO
64
+
65
+		( y-axis )
66
+		OVR #08 MUL #00 SWP 
67
+		.center/y PEK2 #0040 SUB2 ADD2 .Screen/y DEO2
68
+		.center/x PEK2 #0050 SUB2 .Screen/x DEO2
69
+		( draw ) #21 .Screen/color DEO
70
+
46 71
 		( incr ) SWP #01 ADD SWP
47 72
 		DUP2 LTH ,&loop JNZ
48 73
 	POP2
74
+
75
+RTN
76
+
77
+@draw-circle ( -- )
49 78
 	
79
+	;preview_icn .Screen/addr DEO2
80
+
81
+	.center/x PEK2 #0048 ADD2 .Screen/x DEO2
82
+	.center/y PEK2 #0030 ADD2 .Screen/y DEO2
83
+	#21 .Screen/color DEO
84
+	.center/x PEK2 #0050 ADD2 .Screen/x DEO2
85
+	#61 .Screen/color DEO
86
+	.center/x PEK2 #0048 ADD2 .Screen/x DEO2
87
+	.center/y PEK2 #0038 ADD2 .Screen/y DEO2
88
+	#a1 .Screen/color DEO
89
+	.center/x PEK2 #0050 ADD2 .Screen/x DEO2
90
+	#f1 .Screen/color DEO
91
+
50 92
 RTN
51 93
 
52
-@preview_icn  [ 183c 66db db66 3c18 0000 183c 3c18 0000 ]
53 94
\ No newline at end of file
95
+@preview_icn  [ 
96
+	0f38 675f dfbf bfbf 0007 1820 2344 4848 ]
97
+
98
+@font_hex [
99
+	007c 8282 8282 827c 0030 1010 1010 1010
100
+	007c 8202 7c80 80fe 007c 8202 1c02 827c
101
+	000c 1424 4484 fe04 00fe 8080 7c02 827c
102
+	007c 8280 fc82 827c 007c 8202 1e02 0202
103
+	007c 8282 7c82 827c 007c 8282 7e02 827c
104
+	007c 8202 7e82 827e 00fc 8282 fc82 82fc
105
+	007c 8280 8080 827c 00fc 8282 8282 82fc
106
+	007c 8280 f080 827c 007c 8280 f080 8080 ]
54 107
\ No newline at end of file
... ...
@@ -224,11 +224,13 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
224 224
 		Uint16 y = mempeek16(d->dat, 0xa);
225 225
 		Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)];
226 226
 		Uint8 *layer = d->dat[0xe] >> 4 & 0x1 ? ppu.fg : ppu.bg;
227
-		switch(d->dat[0xe] >> 5) {
228
-		case 0: putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3); break;
229
-		case 1: puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf); break;
230
-		case 2: putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf); break;
231
-		}
227
+		Uint8 mode = d->dat[0xe] >> 5;
228
+		if(!mode)
229
+			putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3);
230
+		else if(mode % 2)
231
+			puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, d->dat[0xe] >> 6 & 0x1, d->dat[0xe] >> 7 & 0x1);
232
+		else
233
+			putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, d->dat[0xe] >> 6 & 0x1, d->dat[0xe] >> 7 & 0x1);
232 234
 		reqdraw = 1;
233 235
 	}
234 236
 }
... ...
@@ -80,26 +80,34 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
80 80
 }
81 81
 
82 82
 void
83
-puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
83
+puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
84 84
 {
85 85
 	Uint16 v, h;
86 86
 	for(v = 0; v < 8; v++)
87 87
 		for(h = 0; h < 8; h++) {
88 88
 			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
89 89
 			if(ch1 == 1 || (color != 0x05 && color != 0x0a && color != 0x0f))
90
-				putpixel(p, layer, x + h, y + v, ch1 ? color % 4 : color / 4);
90
+				putpixel(p,
91
+					layer,
92
+					x + (flipx ? 7 - h : h),
93
+					y + (flipy ? 7 - v : v),
94
+					ch1 ? color % 4 : color / 4);
91 95
 		}
92 96
 }
93 97
 
94 98
 void
95
-putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
99
+putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)
96 100
 {
97 101
 	Uint16 v, h;
98 102
 	for(v = 0; v < 8; v++)
99 103
 		for(h = 0; h < 8; h++) {
100 104
 			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1) * color;
101 105
 			Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1) * color;
102
-			putpixel(p, layer, x + h, y + v, (((ch1 + ch2 * 2) + color / 4) & 0x3));
106
+			putpixel(p,
107
+				layer,
108
+				x + (flipx ? 7 - h : h),
109
+				y + (flipy ? 7 - v : v),
110
+				(((ch1 + ch2 * 2) + color / 4) & 0x3));
103 111
 		}
104 112
 }
105 113
 
... ...
@@ -118,8 +126,8 @@ drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr)
118 126
 	Uint8 i, x, y, b;
119 127
 	for(i = 0; i < 0x20; ++i) { /* memory */
120 128
 		x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
121
-		puticn(p, p->bg, x, y, font[(b >> 4) & 0xf], 1 + (ptr == i) * 0x7);
122
-		puticn(p, p->bg, x + 8, y, font[b & 0xf], 1 + (ptr == i) * 0x7);
129
+		puticn(p, p->bg, x, y, font[(b >> 4) & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
130
+		puticn(p, p->bg, x + 8, y, font[b & 0xf], 1 + (ptr == i) * 0x7, 0, 0);
123 131
 	}
124 132
 	for(x = 0; x < 0x20; ++x) {
125 133
 		drawpixel(p, x, p->height / 2, 2);
... ...
@@ -26,7 +26,7 @@ typedef struct Ppu {
26 26
 int initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad);
27 27
 void putcolors(Ppu *p, Uint8 *addr);
28 28
 void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color);
29
-void puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
30
-void putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
29
+void puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
30
+void putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
31 31
 void drawppu(Ppu *p);
32 32
 void drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr);