Browse code

Revert "ppu: keep track of modified rows and only redraw those in drawppu"

This reverts commit 3c64c8c1a4ab7f28ad18c4ae9b3564b758ae2fa9.

neauoire authored on 19/05/2021 16:13:41
Showing 3 changed files
... ...
@@ -41,11 +41,13 @@ readpixel(Uint8 *sprite, Uint8 h, Uint8 v)
41 41
 void
42 42
 clear(Ppu *p)
43 43
 {
44
-	int sz = p->height * p->width, rows = sz / 4;
45
-	memset(p->output, p->colors[0], sz);
46
-	memset(p->fg, 0, rows);
47
-	memset(p->bg, 0, rows);
48
-	memset(p->up, 0xff, p->ver);
44
+	int i, sz = p->height * p->width, rows = sz / 4;
45
+	for(i = 0; i < sz; ++i)
46
+		p->output[i] = p->colors[0];
47
+	for(i = 0; i < rows; i++) {
48
+		p->fg[i] = 0;
49
+		p->bg[i] = 0;
50
+	}
49 51
 }
50 52
 
51 53
 void
... ...
@@ -64,12 +66,9 @@ putcolors(Ppu *p, Uint8 *addr)
64 66
 void
65 67
 putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
66 68
 {
67
-	if(x >= p->hor * 8 || y >= p->ver * 8)
68
-		return;
69
-	int row = (y % 8) + ((x / 8 + y / 8 * p->hor) * 16);
70
-	if(row > (p->hor * p->ver * 16) - 8)
69
+	Uint16 row = (y % 8) + ((x / 8 + y / 8 * p->hor) * 16), col = 7 - (x % 8);
70
+	if(x >= p->hor * 8 || y >= p->ver * 8 || row > (p->hor * p->ver * 16) - 8)
71 71
 		return;
72
-	int col = 7 - (x % 8);
73 72
 	if(color == 0 || color == 2)
74 73
 		layer[row] &= ~(1UL << col);
75 74
 	else
... ...
@@ -78,8 +77,6 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
78 77
 		layer[row + 8] &= ~(1UL << col);
79 78
 	else
80 79
 		layer[row + 8] |= 1UL << col;
81
-
82
-	p->up[y / 8] |= 1<<(y % 8);
83 80
 }
84 81
 
85 82
 void
... ...
@@ -146,25 +143,18 @@ void
146 143
 drawppu(Ppu *p)
147 144
 {
148 145
 	Uint16 x, y;
149
-	for(y = 0; y < p->ver; ++y) {
150
-		if(p->up[y] == 0)
151
-			continue;
146
+	for(y = 0; y < p->ver; ++y)
152 147
 		for(x = 0; x < p->hor; ++x) {
153 148
 			Uint8 v, h;
154 149
 			Uint16 key = (y * p->hor + x) * 16;
155
-			for(v = 0; v < 8; v++) {
156
-				if((p->up[y] & (1<<v)) == 0)
157
-					continue;
150
+			for(v = 0; v < 8; v++)
158 151
 				for(h = 0; h < 8; h++) {
159 152
 					Uint8 color = readpixel(&p->fg[key], h, v);
160 153
 					if(color == 0)
161 154
 						color = readpixel(&p->bg[key], h, v);
162 155
 					drawpixel(p, x * 8 + p->pad + 7 - h, y * 8 + p->pad + v, color);
163 156
 				}
164
-			}
165 157
 		}
166
-		p->up[y] = 0;
167
-	}
168 158
 }
169 159
 
170 160
 int
... ...
@@ -181,8 +171,6 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad)
181 171
 		return 0;
182 172
 	if(!(p->fg = malloc(p->width * p->height * sizeof(Uint8) / 4)))
183 173
 		return 0;
184
-	if(!(p->up = malloc(p->ver)))
185
-		return 0;
186 174
 	clear(p);
187 175
 	return 1;
188 176
 }
... ...
@@ -18,7 +18,7 @@ typedef unsigned short Uint16;
18 18
 typedef unsigned int Uint32;
19 19
 
20 20
 typedef struct Ppu {
21
-	Uint8 *bg, *fg, *up;
21
+	Uint8 *bg, *fg;
22 22
 	Uint16 hor, ver, pad, width, height;
23 23
 	Uint32 *output, colors[4];
24 24
 } Ppu;
... ...
@@ -86,7 +86,6 @@ quit(void)
86 86
 	free(ppu.output);
87 87
 	free(ppu.fg);
88 88
 	free(ppu.bg);
89
-	free(ppu.up);
90 89
 	SDL_UnlockAudioDevice(audio_id);
91 90
 	SDL_DestroyTexture(gTexture);
92 91
 	gTexture = NULL;