Browse code

Moved get_pixel to ppu.c

neauoire authored on 29/09/2021 23:01:54
Showing 3 changed files
... ...
@@ -35,8 +35,15 @@ ppu_clear(Ppu *p)
35 35
 		p->dat[i] = 0;
36 36
 }
37 37
 
38
+Uint8
39
+ppu_read(Ppu *p, Uint16 x, Uint16 y)
40
+{
41
+	unsigned int i = x / PPW + y * p->stride, shift = x % PPW * 4;
42
+	return (p->dat[i] >> shift) & 0xf;
43
+}
44
+
38 45
 void
39
-ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color)
46
+ppu_write(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color)
40 47
 {
41 48
 	unsigned int v, i = x / PPW + y * p->stride, shift = x % PPW * 4;
42 49
 	if(x >= p->width || y >= p->height)
... ...
@@ -60,7 +67,7 @@ ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 f
60 67
 		for(h = 0; h < 8; h++) {
61 68
 			Uint8 ch1 = (sprite[v] >> (7 - h)) & 0x1;
62 69
 			if(ch1 || blending[4][color])
63
-				ppu_pixel(p,
70
+				ppu_write(p,
64 71
 					fg,
65 72
 					x + (flipx ? 7 - h : h),
66 73
 					y + (flipy ? 7 - v : v),
... ...
@@ -78,7 +85,7 @@ ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 f
78 85
 			Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1);
79 86
 			Uint8 ch = ch1 + ch2 * 2;
80 87
 			if(ch || blending[4][color])
81
-				ppu_pixel(p,
88
+				ppu_write(p,
82 89
 					fg,
83 90
 					x + (flipx ? 7 - h : h),
84 91
 					y + (flipy ? 7 - v : v),
... ...
@@ -26,8 +26,9 @@ typedef struct Ppu {
26 26
 	unsigned int i0, i1, redraw, *dat, stride;
27 27
 } Ppu;
28 28
 
29
+Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y);
30
+void ppu_write(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color);
29 31
 void ppu_frame(Ppu *p);
30
-int ppu_set_size(Ppu *p, Uint16 width, Uint16 height);
31
-void ppu_pixel(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 color);
32 32
 void ppu_1bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
33 33
 void ppu_2bpp(Ppu *p, int fg, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
34
+int ppu_set_size(Ppu *p, Uint16 width, Uint16 height);
... ...
@@ -206,22 +206,15 @@ draw_inspect(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
206 206
 		ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 3, 0, 0);
207 207
 	}
208 208
 	for(x = 0; x < 0x10; ++x) { /* guides */
209
-		ppu_pixel(p, 1, x, p->height / 2, 2);
210
-		ppu_pixel(p, 1, p->width - x, p->height / 2, 2);
211
-		ppu_pixel(p, 1, p->width / 2, p->height - x, 2);
212
-		ppu_pixel(p, 1, p->width / 2, x, 2);
213
-		ppu_pixel(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
214
-		ppu_pixel(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
209
+		ppu_write(p, 1, x, p->height / 2, 2);
210
+		ppu_write(p, 1, p->width - x, p->height / 2, 2);
211
+		ppu_write(p, 1, p->width / 2, p->height - x, 2);
212
+		ppu_write(p, 1, p->width / 2, x, 2);
213
+		ppu_write(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
214
+		ppu_write(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
215 215
 	}
216 216
 }
217 217
 
218
-static Uint8
219
-get_pixel(int x, int y)
220
-{
221
-	unsigned int i = x / PPW + y * ppu.stride, shift = x % PPW * 4;
222
-	return (ppu.dat[i] >> shift) & 0xf;
223
-}
224
-
225 218
 static void
226 219
 redraw(Uxn *u)
227 220
 {
... ...
@@ -237,7 +230,7 @@ redraw(Uxn *u)
237 230
 	}
238 231
 	for(y = y0; y < y1; ++y)
239 232
 		for(x = 0; x < ppu.width; ++x)
240
-			ppu_screen[x + y * ppu.width] = palette[get_pixel(x, y)];
233
+			ppu_screen[x + y * ppu.width] = palette[ppu_read(&ppu, x, y)];
241 234
 	SDL_UpdateTexture(gTexture, &up, ppu_screen + y0 * ppu.width, ppu.width * sizeof(Uint32));
242 235
 	SDL_RenderClear(gRenderer);
243 236
 	SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
... ...
@@ -404,7 +397,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
404 397
 			Uint16 x = peek16(d->dat, 0x8);
405 398
 			Uint16 y = peek16(d->dat, 0xa);
406 399
 			Uint8 layer = d->dat[0xe] & 0x40;
407
-			ppu_pixel(&ppu, layer, x, y, d->dat[0xe] & 0x3);
400
+			ppu_write(&ppu, layer, x, y, d->dat[0xe] & 0x3);
408 401
 			if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */
409 402
 			if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */
410 403
 			break;