Browse code

Renamed PPU to Screen

neauoire authored on 28/12/2021 21:37:26
Showing 6 changed files
... ...
@@ -14,8 +14,8 @@ then
14 14
 	echo "Formatting.."
15 15
 	clang-format -i src/uxn.h
16 16
 	clang-format -i src/uxn.c
17
-	clang-format -i src/devices/ppu.h
18
-	clang-format -i src/devices/ppu.c
17
+	clang-format -i src/devices/screen.h
18
+	clang-format -i src/devices/screen.c
19 19
 	clang-format -i src/devices/apu.h
20 20
 	clang-format -i src/devices/apu.c
21 21
 	clang-format -i src/devices/file.h
... ...
@@ -62,7 +62,7 @@ fi
62 62
 
63 63
 echo "Building.."
64 64
 ${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm
65
-${CC} ${CFLAGS} ${CORE} src/devices/file.c src/devices/mouse.c src/devices/controller.c src/devices/ppu.c src/devices/apu.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu
65
+${CC} ${CFLAGS} ${CORE} src/devices/file.c src/devices/mouse.c src/devices/controller.c src/devices/screen.c src/devices/apu.c src/uxnemu.c ${UXNEMU_LDFLAGS} -o bin/uxnemu
66 66
 ${CC} ${CFLAGS} ${CORE} src/devices/file.c src/uxncli.c -o bin/uxncli
67 67
 
68 68
 if [ -d "$HOME/bin" ]
... ...
@@ -8,7 +8,7 @@ HFILES=\
8 8
 	/sys/include/npe/stdio.h\
9 9
 	src/devices/apu.h\
10 10
 	src/devices/file.h\
11
-	src/devices/ppu.h\
11
+	src/devices/screen.h\
12 12
 	src/uxn.h\
13 13
 
14 14
 CLEANFILES=$TARG $ROM
... ...
@@ -35,13 +35,13 @@ bin/uxncli: file.$O uxncli.$O uxn.$O
35 35
 bin/uxnasm: uxnasm.$O
36 36
 	$LD $LDFLAGS -o $target $prereq
37 37
 
38
-bin/uxnemu: uxnemu.$O apu.$O file.$O ppu.$O uxn.$O
38
+bin/uxnemu: uxnemu.$O apu.$O file.$O screen.$O uxn.$O
39 39
 	$LD $LDFLAGS -o $target $prereq
40 40
 
41 41
 (uxnasm|uxncli|uxnemu|uxn)\.$O:R: src/\1.c
42 42
 	$CC $CFLAGS -Isrc -o $target src/$stem1.c
43 43
 
44
-(apu|file|ppu)\.$O:R: src/devices/\1.c
44
+(apu|file|screen)\.$O:R: src/devices/\1.c
45 45
 	$CC $CFLAGS -Isrc -o $target src/devices/$stem1.c
46 46
 
47 47
 nuke:V: clean
48 48
deleted file mode 100644
... ...
@@ -1,37 +0,0 @@
1
-#include <stdlib.h>
2
-
3
-/*
4
-Copyright (c) 2021 Devine Lu Linvega
5
-Copyright (c) 2021 Andrew Alderwick
6
-
7
-Permission to use, copy, modify, and distribute this software for any
8
-purpose with or without fee is hereby granted, provided that the above
9
-copyright notice and this permission notice appear in all copies.
10
-
11
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
-WITH REGARD TO THIS SOFTWARE.
13
-*/
14
-
15
-typedef unsigned char Uint8;
16
-typedef unsigned short Uint16;
17
-typedef unsigned int Uint32;
18
-
19
-typedef struct Layer {
20
-	Uint8 *pixels;
21
-	Uint8 changed;
22
-} Layer;
23
-
24
-typedef struct Ppu {
25
-	Uint32 palette[4], *screen;
26
-	Uint16 width, height;
27
-	Layer fg, bg;
28
-} Ppu;
29
-
30
-void ppu_palette(Ppu *p, Uint8 *addr);
31
-void ppu_resize(Ppu *p, Uint16 width, Uint16 height);
32
-void ppu_clear(Ppu *p, Layer *layer);
33
-void ppu_redraw(Ppu *p, Uint32 *screen);
34
-
35
-void ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color);
36
-void ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp);
37
-void ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory);
38 0
similarity index 51%
39 1
rename from src/devices/ppu.c
40 2
rename to src/devices/screen.c
... ...
@@ -1,4 +1,5 @@
1
-#include "ppu.h"
1
+#include "../uxn.h"
2
+#include "screen.h"
2 3
 
3 4
 /*
4 5
 Copyright (c) 2021 Devine Lu Linvega
... ...
@@ -12,6 +13,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 13
 WITH REGARD TO THIS SOFTWARE.
13 14
 */
14 15
 
16
+Screen screen;
17
+
15 18
 static Uint8 blending[5][16] = {
16 19
 	{0, 0, 0, 0, 1, 0, 1, 1, 2, 2, 0, 2, 3, 3, 3, 0},
17 20
 	{0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3},
... ...
@@ -37,8 +40,39 @@ static Uint8 font[][8] = {
37 40
 	{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c},
38 41
 	{0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}};
39 42
 
43
+static void
44
+screen_write(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
45
+{
46
+	if(x < p->width && y < p->height) {
47
+		Uint32 i = x + y * p->width;
48
+		Uint8 prev = layer->pixels[i];
49
+		if(color != prev) {
50
+			layer->pixels[i] = color;
51
+			layer->changed = 1;
52
+		}
53
+	}
54
+}
55
+
56
+static void
57
+screen_blit(Screen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp)
58
+{
59
+	int v, h, opaque = blending[4][color];
60
+	for(v = 0; v < 8; ++v) {
61
+		Uint16 c = sprite[v] | (twobpp ? sprite[v + 8] : 0) << 8;
62
+		for(h = 7; h >= 0; --h, c >>= 1) {
63
+			Uint8 ch = (c & 1) | ((c >> 7) & 2);
64
+			if(opaque || ch)
65
+				screen_write(p,
66
+					layer,
67
+					x + (flipx ? 7 - h : h),
68
+					y + (flipy ? 7 - v : v),
69
+					blending[ch][color]);
70
+		}
71
+	}
72
+}
73
+
40 74
 void
41
-ppu_palette(Ppu *p, Uint8 *addr)
75
+screen_palette(Screen *p, Uint8 *addr)
42 76
 {
43 77
 	int i, shift;
44 78
 	for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) {
... ...
@@ -53,27 +87,27 @@ ppu_palette(Ppu *p, Uint8 *addr)
53 87
 }
54 88
 
55 89
 void
56
-ppu_resize(Ppu *p, Uint16 width, Uint16 height)
90
+screen_resize(Screen *p, Uint16 width, Uint16 height)
57 91
 {
58 92
 	Uint8
59 93
 		*bg = realloc(p->bg.pixels, width * height),
60 94
 		*fg = realloc(p->fg.pixels, width * height);
61 95
 	Uint32
62
-		*screen = realloc(p->screen, width * height * sizeof(Uint32));
96
+		*pixels = realloc(p->pixels, width * height * sizeof(Uint32));
63 97
 	if(bg) p->bg.pixels = bg;
64 98
 	if(fg) p->fg.pixels = fg;
65
-	if(screen) p->screen = screen;
66
-	if(bg && fg && screen) {
99
+	if(pixels) p->pixels = pixels;
100
+	if(bg && fg && pixels) {
67 101
 		p->width = width;
68 102
 		p->height = height;
69
-		p->screen = screen;
70
-		ppu_clear(p, &p->bg);
71
-		ppu_clear(p, &p->fg);
103
+		p->pixels = pixels;
104
+		screen_clear(p, &p->bg);
105
+		screen_clear(p, &p->fg);
72 106
 	}
73 107
 }
74 108
 
75 109
 void
76
-ppu_clear(Ppu *p, Layer *layer)
110
+screen_clear(Screen *p, Layer *layer)
77 111
 {
78 112
 	Uint32 i, size = p->width * p->height;
79 113
 	for(i = 0; i < size; ++i)
... ...
@@ -82,72 +116,87 @@ ppu_clear(Ppu *p, Layer *layer)
82 116
 }
83 117
 
84 118
 void
85
-ppu_redraw(Ppu *p, Uint32 *screen)
119
+screen_redraw(Screen *p, Uint32 *pixels)
86 120
 {
87 121
 	Uint32 i, size = p->width * p->height, palette[16];
88 122
 	for(i = 0; i < 16; ++i)
89 123
 		palette[i] = p->palette[(i >> 2) ? (i >> 2) : (i & 3)];
90 124
 	for(i = 0; i < size; ++i)
91
-		screen[i] = palette[p->fg.pixels[i] << 2 | p->bg.pixels[i]];
125
+		pixels[i] = palette[p->fg.pixels[i] << 2 | p->bg.pixels[i]];
92 126
 	p->fg.changed = p->bg.changed = 0;
93 127
 }
94 128
 
95 129
 void
96
-ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color)
97
-{
98
-	if(x < p->width && y < p->height) {
99
-		Uint32 i = x + y * p->width;
100
-		Uint8 prev = layer->pixels[i];
101
-		if(color != prev) {
102
-			layer->pixels[i] = color;
103
-			layer->changed = 1;
104
-		}
105
-	}
106
-}
107
-
108
-void
109
-ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp)
110
-{
111
-	int v, h, opaque = blending[4][color];
112
-	for(v = 0; v < 8; ++v) {
113
-		Uint16 c = sprite[v] | (twobpp ? sprite[v + 8] : 0) << 8;
114
-		for(h = 7; h >= 0; --h, c >>= 1) {
115
-			Uint8 ch = (c & 1) | ((c >> 7) & 2);
116
-			if(opaque || ch)
117
-				ppu_write(p,
118
-					layer,
119
-					x + (flipx ? 7 - h : h),
120
-					y + (flipy ? 7 - v : v),
121
-					blending[ch][color]);
122
-		}
123
-	}
124
-}
125
-
126
-void
127
-ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
130
+screen_debug(Screen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
128 131
 {
129 132
 	Uint8 i, x, y, b;
130 133
 	for(i = 0; i < 0x20; ++i) {
131 134
 		x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
132 135
 		/* working stack */
133
-		ppu_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0);
134
-		ppu_blit(p, &p->fg, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0);
136
+		screen_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0);
137
+		screen_blit(p, &p->fg, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0);
135 138
 		y = 0x28 + (i / 8 + 1) * 8;
136 139
 		b = memory[i];
137 140
 		/* return stack */
138
-		ppu_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 3, 0, 0, 0);
139
-		ppu_blit(p, &p->fg, x + 8, y, font[b & 0xf], 3, 0, 0, 0);
141
+		screen_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 3, 0, 0, 0);
142
+		screen_blit(p, &p->fg, x + 8, y, font[b & 0xf], 3, 0, 0, 0);
140 143
 	}
141 144
 	/* return pointer */
142
-	ppu_blit(p, &p->fg, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0, 0);
143
-	ppu_blit(p, &p->fg, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0, 0);
145
+	screen_blit(p, &p->fg, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0, 0);
146
+	screen_blit(p, &p->fg, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0, 0);
144 147
 	/* guides */
145 148
 	for(x = 0; x < 0x10; ++x) {
146
-		ppu_write(p, &p->fg, x, p->height / 2, 2);
147
-		ppu_write(p, &p->fg, p->width - x, p->height / 2, 2);
148
-		ppu_write(p, &p->fg, p->width / 2, p->height - x, 2);
149
-		ppu_write(p, &p->fg, p->width / 2, x, 2);
150
-		ppu_write(p, &p->fg, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
151
-		ppu_write(p, &p->fg, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
149
+		screen_write(p, &p->fg, x, p->height / 2, 2);
150
+		screen_write(p, &p->fg, p->width - x, p->height / 2, 2);
151
+		screen_write(p, &p->fg, p->width / 2, p->height - x, 2);
152
+		screen_write(p, &p->fg, p->width / 2, x, 2);
153
+		screen_write(p, &p->fg, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
154
+		screen_write(p, &p->fg, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
155
+	}
156
+}
157
+
158
+/* APIs */
159
+
160
+Uint8
161
+screen_dei(Device *d, Uint8 port)
162
+{
163
+	switch(port) {
164
+	case 0x2: return screen.width >> 8;
165
+	case 0x3: return screen.width;
166
+	case 0x4: return screen.height >> 8;
167
+	case 0x5: return screen.height;
168
+	default: return d->dat[port];
152 169
 	}
153 170
 }
171
+
172
+void
173
+screen_deo(Device *d, Uint8 port)
174
+{
175
+	switch(port) {
176
+	case 0x1: d->vector = peek16(d->dat, 0x0); break;
177
+	case 0x5:
178
+		/* TODO: if(!FIXED_SIZE) set_size(peek16(d->dat, 0x2), peek16(d->dat, 0x4), 1); */
179
+		break;
180
+	case 0xe: {
181
+		Uint16 x = peek16(d->dat, 0x8);
182
+		Uint16 y = peek16(d->dat, 0xa);
183
+		Uint8 layer = d->dat[0xe] & 0x40;
184
+		screen_write(&screen, layer ? &screen.fg : &screen.bg, x, y, d->dat[0xe] & 0x3);
185
+		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */
186
+		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */
187
+		break;
188
+	}
189
+	case 0xf: {
190
+		Uint16 x = peek16(d->dat, 0x8);
191
+		Uint16 y = peek16(d->dat, 0xa);
192
+		Layer *layer = (d->dat[0xf] & 0x40) ? &screen.fg : &screen.bg;
193
+		Uint8 *addr = &d->mem[peek16(d->dat, 0xc)];
194
+		Uint8 twobpp = !!(d->dat[0xf] & 0x80);
195
+		screen_blit(&screen, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp);
196
+		if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */
197
+		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8);                                /* auto x+8 */
198
+		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8);                                /* auto y+8 */
199
+		break;
200
+	}
201
+	}
202
+}
154 203
\ No newline at end of file
155 204
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+#include <stdlib.h>
2
+
3
+/*
4
+Copyright (c) 2021 Devine Lu Linvega
5
+Copyright (c) 2021 Andrew Alderwick
6
+
7
+Permission to use, copy, modify, and distribute this software for any
8
+purpose with or without fee is hereby granted, provided that the above
9
+copyright notice and this permission notice appear in all copies.
10
+
11
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
+WITH REGARD TO THIS SOFTWARE.
13
+*/
14
+
15
+#define FIXED_SIZE 0
16
+
17
+typedef struct Layer {
18
+	Uint8 *pixels;
19
+	Uint8 changed;
20
+} Layer;
21
+
22
+typedef struct Screen {
23
+	Uint32 palette[4], *pixels;
24
+	Uint16 width, height;
25
+	Layer fg, bg;
26
+} Screen;
27
+
28
+extern Screen screen;
29
+
30
+void screen_palette(Screen *p, Uint8 *addr);
31
+void screen_resize(Screen *p, Uint16 width, Uint16 height);
32
+void screen_clear(Screen *p, Layer *layer);
33
+void screen_redraw(Screen *p, Uint32 *pixels);
34
+void screen_debug(Screen *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory);
35
+
36
+Uint8 screen_dei(Device *d, Uint8 port);
37
+void screen_deo(Device *d, Uint8 port);
0 38
\ No newline at end of file
... ...
@@ -8,7 +8,7 @@
8 8
 #pragma GCC diagnostic ignored "-Wpedantic"
9 9
 #pragma clang diagnostic ignored "-Wtypedef-redefinition"
10 10
 #include <SDL.h>
11
-#include "devices/ppu.h"
11
+#include "devices/screen.h"
12 12
 #include "devices/apu.h"
13 13
 #include "devices/file.h"
14 14
 #include "devices/controller.h"
... ...
@@ -30,7 +30,6 @@ WITH REGARD TO THIS SOFTWARE.
30 30
 #define WIDTH 64 * 8
31 31
 #define HEIGHT 40 * 8
32 32
 #define PAD 4
33
-#define FIXED_SIZE 0
34 33
 #define POLYPHONY 4
35 34
 #define BENCH 0
36 35
 
... ...
@@ -39,8 +38,9 @@ static SDL_Texture *gTexture;
39 38
 static SDL_Renderer *gRenderer;
40 39
 static SDL_AudioDeviceID audio_id;
41 40
 static SDL_Rect gRect;
41
+
42 42
 /* devices */
43
-static Ppu ppu;
43
+
44 44
 static Apu apu[POLYPHONY];
45 45
 static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
46 46
 static Uint8 zoom = 1;
... ...
@@ -106,20 +106,20 @@ set_window_size(SDL_Window *window, int w, int h)
106 106
 static int
107 107
 set_size(Uint16 width, Uint16 height, int is_resize)
108 108
 {
109
-	ppu_resize(&ppu, width, height);
109
+	screen_resize(&screen, width, height);
110 110
 	gRect.x = PAD;
111 111
 	gRect.y = PAD;
112
-	gRect.w = ppu.width;
113
-	gRect.h = ppu.height;
112
+	gRect.w = screen.width;
113
+	gRect.h = screen.height;
114 114
 	if(gTexture != NULL) SDL_DestroyTexture(gTexture);
115
-	SDL_RenderSetLogicalSize(gRenderer, ppu.width + PAD * 2, ppu.height + PAD * 2);
116
-	gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, ppu.width + PAD * 2, ppu.height + PAD * 2);
115
+	SDL_RenderSetLogicalSize(gRenderer, screen.width + PAD * 2, screen.height + PAD * 2);
116
+	gTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, screen.width + PAD * 2, screen.height + PAD * 2);
117 117
 	if(gTexture == NULL || SDL_SetTextureBlendMode(gTexture, SDL_BLENDMODE_NONE))
118 118
 		return error("gTexture", SDL_GetError());
119
-	if(SDL_UpdateTexture(gTexture, NULL, ppu.screen, sizeof(Uint32)) != 0)
119
+	if(SDL_UpdateTexture(gTexture, NULL, screen.pixels, sizeof(Uint32)) != 0)
120 120
 		return error("SDL_UpdateTexture", SDL_GetError());
121 121
 	if(is_resize)
122
-		set_window_size(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom);
122
+		set_window_size(gWindow, (screen.width + PAD * 2) * zoom, (screen.height + PAD * 2) * zoom);
123 123
 	return 1;
124 124
 }
125 125
 
... ...
@@ -127,9 +127,9 @@ static void
127 127
 redraw(Uxn *u)
128 128
 {
129 129
 	if(devsystem->dat[0xe])
130
-		ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
131
-	ppu_redraw(&ppu, ppu.screen);
132
-	if(SDL_UpdateTexture(gTexture, &gRect, ppu.screen, ppu.width * sizeof(Uint32)) != 0)
130
+		screen_debug(&screen, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
131
+	screen_redraw(&screen, screen.pixels);
132
+	if(SDL_UpdateTexture(gTexture, &gRect, screen.pixels, screen.width * sizeof(Uint32)) != 0)
133 133
 		error("SDL_UpdateTexture", SDL_GetError());
134 134
 	SDL_RenderClear(gRenderer);
135 135
 	SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
... ...
@@ -197,7 +197,7 @@ system_deo(Device *d, Uint8 port)
197 197
 	case 0x3: d->u->rst.ptr = d->dat[port]; break;
198 198
 	}
199 199
 	if(port > 0x7 && port < 0xe)
200
-		ppu_palette(&ppu, &d->dat[0x8]);
200
+		screen_palette(&screen, &d->dat[0x8]);
201 201
 }
202 202
 
203 203
 static void
... ...
@@ -209,50 +209,6 @@ console_deo(Device *d, Uint8 port)
209 209
 		write(port - 0x7, (char *)&d->dat[port], 1);
210 210
 }
211 211
 
212
-static Uint8
213
-screen_dei(Device *d, Uint8 port)
214
-{
215
-	switch(port) {
216
-	case 0x2: return ppu.width >> 8;
217
-	case 0x3: return ppu.width;
218
-	case 0x4: return ppu.height >> 8;
219
-	case 0x5: return ppu.height;
220
-	default: return d->dat[port];
221
-	}
222
-}
223
-
224
-static void
225
-screen_deo(Device *d, Uint8 port)
226
-{
227
-	switch(port) {
228
-	case 0x1: d->vector = peek16(d->dat, 0x0); break;
229
-	case 0x5:
230
-		if(!FIXED_SIZE) set_size(peek16(d->dat, 0x2), peek16(d->dat, 0x4), 1);
231
-		break;
232
-	case 0xe: {
233
-		Uint16 x = peek16(d->dat, 0x8);
234
-		Uint16 y = peek16(d->dat, 0xa);
235
-		Uint8 layer = d->dat[0xe] & 0x40;
236
-		ppu_write(&ppu, layer ? &ppu.fg : &ppu.bg, x, y, d->dat[0xe] & 0x3);
237
-		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 1); /* auto x+1 */
238
-		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 1); /* auto y+1 */
239
-		break;
240
-	}
241
-	case 0xf: {
242
-		Uint16 x = peek16(d->dat, 0x8);
243
-		Uint16 y = peek16(d->dat, 0xa);
244
-		Layer *layer = (d->dat[0xf] & 0x40) ? &ppu.fg : &ppu.bg;
245
-		Uint8 *addr = &d->mem[peek16(d->dat, 0xc)];
246
-		Uint8 twobpp = !!(d->dat[0xf] & 0x80);
247
-		ppu_blit(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp);
248
-		if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */
249
-		if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8);                                /* auto x+8 */
250
-		if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8);                                /* auto y+8 */
251
-		break;
252
-	}
253
-	}
254
-}
255
-
256 212
 static Uint8
257 213
 audio_dei(Device *d, Uint8 port)
258 214
 {
... ...
@@ -370,14 +326,14 @@ static void
370 326
 set_zoom(Uint8 scale)
371 327
 {
372 328
 	zoom = clamp(scale, 1, 3);
373
-	set_window_size(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom);
329
+	set_window_size(gWindow, (screen.width + PAD * 2) * zoom, (screen.height + PAD * 2) * zoom);
374 330
 }
375 331
 
376 332
 static void
377 333
 toggle_debugger(void)
378 334
 {
379 335
 	devsystem->dat[0xe] = !devsystem->dat[0xe];
380
-	ppu_clear(&ppu, &ppu.fg);
336
+	screen_clear(&screen, &screen.fg);
381 337
 }
382 338
 
383 339
 static void
... ...
@@ -502,8 +458,8 @@ run(Uxn *u)
502 458
 			/* Mouse */
503 459
 			else if(event.type == SDL_MOUSEMOTION)
504 460
 				mouse_pos(devmouse,
505
-					clamp(event.motion.x - PAD, 0, ppu.width - 1),
506
-					clamp(event.motion.y - PAD, 0, ppu.height - 1));
461
+					clamp(event.motion.x - PAD, 0, screen.width - 1),
462
+					clamp(event.motion.y - PAD, 0, screen.height - 1));
507 463
 			else if(event.type == SDL_MOUSEBUTTONUP)
508 464
 				mouse_up(devmouse, 0x1 << (event.button.button - 1));
509 465
 			else if(event.type == SDL_MOUSEBUTTONDOWN)
... ...
@@ -537,7 +493,7 @@ run(Uxn *u)
537 493
 				console_input(u, event.cbutton.button);
538 494
 		}
539 495
 		uxn_eval(u, devscreen->vector);
540
-		if(ppu.fg.changed || ppu.bg.changed || devsystem->dat[0xe])
496
+		if(screen.fg.changed || screen.bg.changed || devsystem->dat[0xe])
541 497
 			redraw(u);
542 498
 		if(!BENCH) {
543 499
 			elapsed = (SDL_GetPerformanceCounter() - begin) / (double)SDL_GetPerformanceFrequency() * 1000.0f;