Browse code

Removed zoom and debugger from PPU

neauoire authored on 09/04/2021 14:30:45
Showing 3 changed files
... ...
@@ -25,6 +25,8 @@ static Ppu ppu;
25 25
 static Apu apu;
26 26
 static Device *devsystem, *devscreen, *devmouse, *devkey, *devctrl, *devapu;
27 27
 
28
+Uint8 zoom = 0, debug = 0, reqdraw = 0;
29
+
28 30
 int
29 31
 clamp(int val, int min, int max)
30 32
 {
... ...
@@ -48,27 +50,27 @@ void
48 50
 redraw(Uint32 *dst, Uxn *u)
49 51
 {
50 52
 	drawppu(&ppu);
51
-	if(ppu.debugger)
53
+	if(debug)
52 54
 		drawdebugger(&ppu, u->wst.dat, u->wst.ptr);
53 55
 	SDL_UpdateTexture(gTexture, NULL, dst, ppu.width * sizeof(Uint32));
54 56
 	SDL_RenderClear(gRenderer);
55 57
 	SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
56 58
 	SDL_RenderPresent(gRenderer);
57
-	ppu.reqdraw = 0;
59
+	reqdraw = 0;
58 60
 }
59 61
 
60 62
 void
61 63
 toggledebug(Uxn *u)
62 64
 {
63
-	ppu.debugger = !ppu.debugger;
65
+	debug = !debug;
64 66
 	redraw(ppu.output, u);
65 67
 }
66 68
 
67 69
 void
68 70
 togglezoom(Uxn *u)
69 71
 {
70
-	ppu.zoom = ppu.zoom == 3 ? 1 : ppu.zoom + 1;
71
-	SDL_SetWindowSize(gWindow, ppu.width * ppu.zoom, ppu.height * ppu.zoom);
72
+	zoom = zoom == 3 ? 1 : zoom + 1;
73
+	SDL_SetWindowSize(gWindow, ppu.width * zoom, ppu.height * zoom);
72 74
 	redraw(ppu.output, u);
73 75
 }
74 76
 
... ...
@@ -97,7 +99,7 @@ init(Uxn *u)
97 99
 		return error("PPU", "Init failure");
98 100
 	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
99 101
 		return error("Init", SDL_GetError());
100
-	gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ppu.width * ppu.zoom, ppu.height * ppu.zoom, SDL_WINDOW_SHOWN);
102
+	gWindow = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ppu.width * zoom, ppu.height * zoom, SDL_WINDOW_SHOWN);
101 103
 	if(gWindow == NULL)
102 104
 		return error("Window", SDL_GetError());
103 105
 	gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
... ...
@@ -127,8 +129,8 @@ domouse(Uxn *u, SDL_Event *event)
127 129
 {
128 130
 	Uint8 flag = 0x00;
129 131
 	Uint16 addr = devmouse->addr + 2;
130
-	Uint16 x = clamp(event->motion.x / ppu.zoom - ppu.pad, 0, ppu.hor * 8 - 1);
131
-	Uint16 y = clamp(event->motion.y / ppu.zoom - ppu.pad, 0, ppu.ver * 8 - 1);
132
+	Uint16 x = clamp(event->motion.x / zoom - ppu.pad, 0, ppu.hor * 8 - 1);
133
+	Uint16 y = clamp(event->motion.y / zoom - ppu.pad, 0, ppu.ver * 8 - 1);
132 134
 	mempoke16(u, addr + 0, x);
133 135
 	mempoke16(u, addr + 2, y);
134 136
 	u->ram.dat[addr + 5] = 0x00;
... ...
@@ -214,7 +216,7 @@ screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
214 216
 		Uint16 x = (m[ptr] << 8) + m[ptr + 1];
215 217
 		Uint16 y = (m[ptr + 2] << 8) + m[ptr + 3];
216 218
 		putpixel(&ppu, b1 >> 4 & 0xf ? ppu.fg : ppu.bg, x, y, b1 & 0xf);
217
-		ppu.reqdraw = 1;
219
+		reqdraw = 1;
218 220
 	}
219 221
 	return b1;
220 222
 }
... ...
@@ -238,7 +240,7 @@ sprite_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
238 240
 					continue;
239 241
 				putpixel(&ppu, layer, x + h, y + v, ch1 ? blend % 4 : blend / 4);
240 242
 			}
241
-		ppu.reqdraw = 1;
243
+		reqdraw = 1;
242 244
 	}
243 245
 	return b1;
244 246
 }
... ...
@@ -324,6 +326,7 @@ system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
324 326
 	Uint8 *m = u->ram.dat;
325 327
 	m[PAGE_DEVICE + b0] = b1;
326 328
 	loadtheme(&ppu, &m[PAGE_DEVICE + 0x0008]);
329
+	reqdraw = 1;
327 330
 	(void)ptr;
328 331
 	return b1;
329 332
 }
... ...
@@ -376,7 +379,7 @@ start(Uxn *u)
376 379
 		}
377 380
 		evaluxn(u, devscreen->vector);
378 381
 		SDL_UnlockAudioDevice(audio_id);
379
-		if(ppu.reqdraw)
382
+		if(reqdraw)
380 383
 			redraw(ppu.output, u);
381 384
 		elapsed = (SDL_GetPerformanceCounter() - start) / (double)SDL_GetPerformanceFrequency() * 1000.0f;
382 385
 		SDL_Delay(clamp(16.666f - elapsed, 0, 1000));
... ...
@@ -388,7 +391,7 @@ int
388 391
 main(int argc, char **argv)
389 392
 {
390 393
 	Uxn u;
391
-	ppu.zoom = 2;
394
+	zoom = 2;
392 395
 
393 396
 	if(argc < 2)
394 397
 		return error("Input", "Missing");
... ...
@@ -120,7 +120,6 @@ loadtheme(Ppu *p, Uint8 *addr)
120 120
 			b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f;
121 121
 		p->colors[i] = (r << 20) + (r << 16) + (g << 12) + (g << 8) + (b << 4) + b;
122 122
 	}
123
-	p->reqdraw = 1;
124 123
 }
125 124
 
126 125
 void
... ...
@@ -19,7 +19,7 @@ typedef signed short Sint16;
19 19
 typedef unsigned int Uint32;
20 20
 
21 21
 typedef struct Ppu {
22
-	Uint8 reqdraw, zoom, debugger, *bg, *fg;
22
+	Uint8 *bg, *fg;
23 23
 	Uint16 hor, ver, pad, width, height;
24 24
 	Uint32 *output, colors[4];
25 25
 } Ppu;