Browse code

Minor cleanup

neauoire authored on 09/04/2021 15:02:55
Showing 3 changed files
... ...
@@ -215,7 +215,8 @@ screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
215 215
 	if(b0 == 0x0c) {
216 216
 		Uint16 x = (m[ptr] << 8) + m[ptr + 1];
217 217
 		Uint16 y = (m[ptr + 2] << 8) + m[ptr + 3];
218
-		putpixel(&ppu, b1 >> 4 & 0xf ? ppu.fg : ppu.bg, x, y, b1 & 0xf);
218
+		Uint8 *layer = b1 >> 4 & 0xf ? ppu.fg : ppu.bg;
219
+		putpixel(&ppu, layer, x, y, b1 & 0xf);
219 220
 		reqdraw = 1;
220 221
 	}
221 222
 	return b1;
... ...
@@ -227,19 +228,11 @@ sprite_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
227 228
 	Uint8 *m = u->ram.dat;
228 229
 	ptr += 8;
229 230
 	if(b0 == 0x0e) {
230
-		Uint16 v, h;
231 231
 		Uint16 x = (m[ptr] << 8) + m[ptr + 1];
232 232
 		Uint16 y = (m[ptr + 2] << 8) + m[ptr + 3];
233
-		Uint8 blend = b1 & 0xf;
234
-		Uint8 *layer = ((b1 >> 4) & 0xf) % 2 ? ppu.fg : ppu.bg;
233
+		Uint8 *layer = (b1 >> 4) & 0xf ? ppu.fg : ppu.bg;
235 234
 		Uint8 *sprite = &m[(m[ptr + 4] << 8) + m[ptr + 5]];
236
-		for(v = 0; v < 8; v++)
237
-			for(h = 0; h < 8; h++) {
238
-				Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
239
-				if(ch1 == 0 && (blend == 0x05 || blend == 0x0a || blend == 0x0f))
240
-					continue;
241
-				putpixel(&ppu, layer, x + h, y + v, ch1 ? blend % 4 : blend / 4);
242
-			}
235
+		putsprite(&ppu, layer, x, y, sprite, b1 & 0xf);
243 236
 		reqdraw = 1;
244 237
 	}
245 238
 	return b1;
... ...
@@ -325,7 +318,7 @@ system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
325 318
 {
326 319
 	Uint8 *m = u->ram.dat;
327 320
 	m[PAGE_DEVICE + b0] = b1;
328
-	loadtheme(&ppu, &m[PAGE_DEVICE + 0x0008]);
321
+	getcolors(&ppu, &m[PAGE_DEVICE + 0x0008]);
329 322
 	reqdraw = 1;
330 323
 	(void)ptr;
331 324
 	return b1;
... ...
@@ -110,7 +110,20 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
110 110
 }
111 111
 
112 112
 void
113
-loadtheme(Ppu *p, Uint8 *addr)
113
+putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
114
+{
115
+	Uint16 v, h;
116
+	for(v = 0; v < 8; v++)
117
+		for(h = 0; h < 8; h++) {
118
+			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
119
+			if(ch1 == 0 && (color == 0x05 || color == 0x0a || color == 0x0f))
120
+				continue;
121
+			putpixel(p, layer, x + h, y + v, ch1 ? color % 4 : color / 4);
122
+		}
123
+}
124
+
125
+void
126
+getcolors(Ppu *p, Uint8 *addr)
114 127
 {
115 128
 	int i;
116 129
 	for(i = 0; i < 4; ++i) {
... ...
@@ -13,9 +13,7 @@ WITH REGARD TO THIS SOFTWARE.
13 13
 */
14 14
 
15 15
 typedef unsigned char Uint8;
16
-typedef signed char Sint8;
17 16
 typedef unsigned short Uint16;
18
-typedef signed short Sint16;
19 17
 typedef unsigned int Uint32;
20 18
 
21 19
 typedef struct Ppu {
... ...
@@ -27,5 +25,6 @@ typedef struct Ppu {
27 25
 int initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad);
28 26
 void drawppu(Ppu *p);
29 27
 void drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr);
30
-void loadtheme(Ppu *p, Uint8 *addr);
31
-void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color);
32 28
\ No newline at end of file
29
+void getcolors(Ppu *p, Uint8 *addr);
30
+void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color);
31
+void putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
33 32
\ No newline at end of file