Browse code

Optimization in putchr

neauoire authored on 01/08/2021 04:29:40
Showing 1 changed files
... ...
@@ -35,7 +35,7 @@ puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint
35 35
 	for(v = 0; v < 8; v++)
36 36
 		for(h = 0; h < 8; h++) {
37 37
 			Uint8 ch1 = (sprite[v] >> (7 - h)) & 0x1;
38
-			if(ch1 == 1 || (color != 0x05 && color != 0x0a && color != 0x0f))
38
+			if(ch1 || (color != 0x05 && color != 0x0a && color != 0x0f))
39 39
 				putpixel(p,
40 40
 					layer,
41 41
 					x + (flipx ? 7 - h : h),
... ...
@@ -50,14 +50,15 @@ putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint
50 50
 	Uint16 v, h;
51 51
 	for(v = 0; v < 8; v++)
52 52
 		for(h = 0; h < 8; h++) {
53
-			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1) * color;
54
-			Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1) * color;
55
-			if(ch1 + ch2 || (color != 0x05 && color != 0x0a && color != 0x0f))
53
+			Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
54
+			Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1);
55
+			Uint8 id = ch1 + ch2 * 2;
56
+			if(id || color > 0x7)
56 57
 				putpixel(p,
57 58
 					layer,
58 59
 					x + (flipx ? 7 - h : h),
59 60
 					y + (flipy ? 7 - v : v),
60
-					((ch1 ? (color & 0x3) : (color >> 0x2)) + (ch2 ? (color & 0x3) : (color >> 0x2)) * 2) & 0x3);
61
+					(id < 2 ? id : color / 2 + id * (color % 8)) & 0x3);
61 62
 		}
62 63
 }
63 64