commit 369c996

Devine Lu Linvega  ·  2025-08-13 23:17:35 +0000 UTC
parent dc7b6b0
Removed fg layer
1 files changed,  +24, -12
+24, -12
 1@@ -417,7 +417,7 @@ console_input(int c, unsigned int type)
 2 typedef struct UxnScreen {
 3 	int width, height, zoom, resized, x1, y1, x2, y2;
 4 	unsigned int palette[16], *pixels;
 5-	Uint8 *fg, *bg;
 6+	Uint8 *bg;
 7 } UxnScreen;
 8 
 9 static unsigned int screen_vector;
10@@ -476,9 +476,8 @@ screen_apply(int width, int height)
11 	if(width == uxn_screen.width && height == uxn_screen.height)
12 		return;
13 	length = MAR2(width) * MAR2(height);
14-	uxn_screen.bg = realloc(uxn_screen.bg, length), uxn_screen.fg = realloc(uxn_screen.fg, length);
15+	uxn_screen.bg = realloc(uxn_screen.bg, length);
16 	memset(uxn_screen.bg, 0, length);
17-	memset(uxn_screen.fg, 0, length);
18 	uxn_screen.width = width, uxn_screen.height = height, uxn_screen.resized = 1;
19 	screen_change(0, 0, width, height);
20 }
21@@ -490,7 +489,7 @@ screen_redraw(void)
22 	for(y = uxn_screen.y1; y < uxn_screen.y2; y++) {
23 		const int ys = y * uxn_screen.zoom;
24 		for(x = uxn_screen.x1, i = MAR(x) + MAR(y) * MAR2(uxn_screen.width); x < uxn_screen.x2; x++, i++) {
25-			const int c = uxn_screen.palette[uxn_screen.fg[i] << 2 | uxn_screen.bg[i]];
26+			const int c = uxn_screen.palette[uxn_screen.bg[i]];
27 			for(k = 0; k < uxn_screen.zoom; k++) {
28 				const int oo = ((ys + k) * uxn_screen.width + x) * uxn_screen.zoom;
29 				for(l = 0; l < uxn_screen.zoom; l++)
30@@ -512,7 +511,7 @@ screen_draw_pixel(void)
31 	const int ctrl = dev[0x2e];
32 	const int color = ctrl & 0x3;
33 	const int len = MAR2(uxn_screen.width);
34-	Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg;
35+	const int above = ctrl & 0x40;
36 	/* fill mode */
37 	if(ctrl & 0x80) {
38 		int x1, y1, x2, y2, ax, bx, ay, by, hor, ver;
39@@ -528,13 +527,18 @@ screen_draw_pixel(void)
40 		x1 = MAR(x1), y1 = MAR(y1);
41 		hor = MAR(x2) - x1, ver = MAR(y2) - y1;
42 		for(ay = y1 * len, by = ay + ver * len; ay < by; ay += len)
43-			for(ax = ay + x1, bx = ax + hor; ax < bx; ax++)
44-				layer[ax] = color;
45+			for(ax = ay + x1, bx = ax + hor; ax < bx; ax++) {
46+				const int src = uxn_screen.bg[ax];
47+				uxn_screen.bg[ax] = above ? (src & 0x3) | color << 2 : (src & 0xc) | color;
48+			}
49 	}
50 	/* pixel mode */
51 	else {
52-		if(rX >= 0 && rY >= 0 && rX < len && rY < uxn_screen.height)
53-			layer[MAR(rX) + MAR(rY) * len] = color;
54+		if(rX >= 0 && rY >= 0 && rX < len && rY < uxn_screen.height) {
55+			const int ax = MAR(rX) + MAR(rY) * len;
56+			const int src = uxn_screen.bg[ax];
57+			uxn_screen.bg[ax] = above ? (src & 0x3) | color << 2 : (src & 0xc) | color;
58+		}
59 		screen_change(rX, rY, rX + 1, rY + 1);
60 		if(rMX) rX++;
61 		if(rMY) rY++;
62@@ -551,7 +555,7 @@ screen_draw_sprite(void)
63 	const int dxy = fy * rDX, dyx = fx * rDY;
64 	const int wmar = MAR(uxn_screen.width), wmar2 = MAR2(uxn_screen.width);
65 	const int hmar2 = MAR2(uxn_screen.height);
66-	Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg;
67+	const int above = ctrl & 0x40;
68 	int i, x1, x2, y1, y2, ax, ay, qx, qy, x = rX, y = rY;
69 	if(ctrl & 0x80) {
70 		const int addr_incr = rMA << 2;
71@@ -565,7 +569,11 @@ screen_draw_sprite(void)
72 					const int ch1 = sprite[qy], ch2 = sprite[qy + 8] << 1, bx = xmar2 + ay;
73 					for(ax = xmar + ay, qx = qfx; ax < bx; ax++, qx -= fx) {
74 						const int color = ((ch1 >> qx) & 1) | ((ch2 >> qx) & 2);
75-						if(opaque || color) layer[ax] = blending[color][blend];
76+						if(opaque || color) {
77+							const int src = uxn_screen.bg[ax];
78+							const int clr = blending[color][blend];
79+							uxn_screen.bg[ax] = above ? (src & 0x3) | clr << 2 : (src & 0xc) | clr;
80+						}
81 					}
82 				}
83 			}
84@@ -582,7 +590,11 @@ screen_draw_sprite(void)
85 					const int ch1 = sprite[qy], bx = xmar2 + ay;
86 					for(ax = xmar + ay, qx = qfx; ax < bx; ax++, qx -= fx) {
87 						const int color = (ch1 >> qx) & 1;
88-						if(opaque || color) layer[ax] = blending[color][blend];
89+						if(opaque || color) {
90+							const int src = uxn_screen.bg[ax];
91+							const int clr = blending[color][blend];
92+							uxn_screen.bg[ax] = above ? (src & 0x3) | clr << 2 : (src & 0xc) | clr;
93+						}
94 					}
95 				}
96 			}