Browse code

(ppu) Minor optimisation

neauoire authored on 24/12/2021 17:29:26
Showing 1 changed files
... ...
@@ -12,6 +12,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 12
 WITH REGARD TO THIS SOFTWARE.
13 13
 */
14 14
 
15
+/* byte: p0-bg | p0-fg | p1-bg | p1-fg */
16
+
15 17
 static Uint8 blending[5][16] = {
16 18
 	{0, 0, 0, 0, 1, 0, 1, 1, 2, 2, 0, 2, 3, 3, 3, 0},
17 19
 	{0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3},
... ...
@@ -46,7 +48,7 @@ ppu_resize(Ppu *p, Uint16 width, Uint16 height)
46 48
 	p->pixels = pixels;
47 49
 	p->width = width;
48 50
 	p->height = height;
49
-	ppu_clear(p, 0x00);
51
+	ppu_clear(p, CLEAR_BOTH);
50 52
 }
51 53
 
52 54
 void
... ...
@@ -61,11 +63,11 @@ Uint8
61 63
 ppu_read(Ppu *p, Uint16 x, Uint16 y)
62 64
 {
63 65
 	if(x < p->width && y < p->height) {
64
-		Uint32 row = (x + y * p->width) / 2;
65
-		Uint8 shift = !(x & 0x1) << 2;
66
+		Uint32 row = (x + y * p->width) >> 1;
67
+		Uint8 shift = (x & 0x1) << 2;
66 68
 		Uint8 pix = p->pixels[row] >> shift;
67 69
 		if(pix & 0x0c)
68
-			pix = pix >> 2;
70
+			pix >>= 2;
69 71
 		return pix & 0x3;
70 72
 	}
71 73
 	return 0x0;
... ...
@@ -75,8 +77,8 @@ void
75 77
 ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color)
76 78
 {
77 79
 	if(x < p->width && y < p->height) {
78
-		Uint32 row = (x + y * p->width) / 2;
79
-		Uint8 shift = (!(x & 0x1) << 2) + (layer << 1);
80
+		Uint32 row = (x + y * p->width) >> 1;
81
+		Uint8 shift = ((x & 0x1) << 2) + (layer << 1);
80 82
 		Uint8 pix = p->pixels[row];
81 83
 		Uint8 mask = ~(0x3 << shift);
82 84
 		Uint8 pixnew = (pix & mask) + (color << shift);