Browse code

(Screen) Cached row only written when visible

neauoire authored on 13/11/2023 00:54:19
Showing 1 changed files
... ...
@@ -49,28 +49,28 @@ screen_fill(Uint8 *layer, int color)
49 49
 void
50 50
 screen_rect(Uint8 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, int color)
51 51
 {
52
-	int x, y, w, h;
52
+	int row, x, y, w, h;
53 53
 	if(!x1 && !y1) {
54 54
 		screen_fill(layer, color);
55 55
 		return;
56 56
 	}
57 57
 	w = uxn_screen.width, h = uxn_screen.height;
58 58
 	for(y = y1; y < y2 && y < h; y++)
59
-		for(x = x1; x < x2 && x < w; x++)
60
-			layer[x + y * w] = color;
59
+		for(x = x1, row = y * w; x < x2 && x < w; x++)
60
+			layer[x + row] = color;
61 61
 }
62 62
 
63 63
 static void
64 64
 screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
65 65
 {
66
-	int w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
66
+	int row, w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
67 67
 	Uint8 *ch1 = &ram[addr], *ch2 = ch1 + 8;
68 68
 	Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
69 69
 	Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
70 70
 	for(y = y1 + ymod; y != ymax; y += fy) {
71
-		int row = y * w, c = *ch1++ | (*ch2++ << 8);
71
+		int c = *ch1++ | (*ch2++ << 8);
72 72
 		if(y < h)
73
-			for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
73
+			for(x = x1 + xmod, row = y * w; x != xmax; x -= fx, c >>= 1) {
74 74
 				Uint8 ch = (c & 1) | ((c >> 7) & 2);
75 75
 				if((opaque || ch) && x < w)
76 76
 					layer[x + row] = blending[ch][color];
... ...
@@ -81,14 +81,14 @@ screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16
81 81
 static void
82 82
 screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
83 83
 {
84
-	int w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
84
+	int row, w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
85 85
 	Uint8 *ch1 = &ram[addr];
86 86
 	Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
87 87
 	Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
88 88
 	for(y = y1 + ymod; y != ymax; y += fy) {
89
-		int row = y * w, c = *ch1++;
89
+		int c = *ch1++;
90 90
 		if(y < h)
91
-			for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
91
+			for(x = x1 + xmod, row = y * w; x != xmax; x -= fx, c >>= 1) {
92 92
 				Uint8 ch = c & 1;
93 93
 				if((opaque || ch) && x < w)
94 94
 					layer[x + row] = blending[ch][color];