commit 3371b95

Devie Lu Linvega  ·  2025-12-24 19:21:42 +0000 UTC
parent e5b128a
Precompute above/below blending table
1 files changed,  +21, -28
+21, -28
 1@@ -412,24 +412,23 @@ static int screen_x1, screen_y1, screen_x2, screen_y2, screen_reqsize, screen_re
 2 static unsigned int screen_vector, *screen_pixels, screen_palette[16];
 3 static Uint8 *screen_layers;
 4 
 5-static const Uint8 blending[16][4] = {
 6-	{0, 0, 1, 2},
 7-	{0, 1, 2, 3},
 8-	{0, 2, 3, 1},
 9-	{0, 3, 1, 2},
10-	{1, 0, 1, 2},
11-	{0, 1, 2, 3},
12-	{1, 2, 3, 1},
13-	{1, 3, 1, 2},
14-	{2, 0, 1, 2},
15-	{2, 1, 2, 3},
16-	{0, 2, 3, 1},
17-	{2, 3, 1, 2},
18-	{3, 0, 1, 2},
19-	{3, 1, 2, 3},
20-	{3, 2, 3, 1},
21-	{0, 3, 1, 2},
22-};
23+static const Uint8 blending[16][2][4] = {
24+	{{0, 0, 1, 2}, {0, 0, 4, 8}},
25+	{{0, 1, 2, 3}, {0, 4, 8, 12}},
26+	{{0, 2, 3, 1}, {0, 8, 12, 4}},
27+	{{0, 3, 1, 2}, {0, 12, 4, 8}},
28+	{{1, 0, 1, 2}, {4, 0, 4, 8}},
29+	{{0, 1, 2, 3}, {0, 4, 8, 12}},
30+	{{1, 2, 3, 1}, {4, 8, 12, 4}},
31+	{{1, 3, 1, 2}, {4, 12, 4, 8}},
32+	{{2, 0, 1, 2}, {8, 0, 4, 8}},
33+	{{2, 1, 2, 3}, {8, 4, 8, 12}},
34+	{{0, 2, 3, 1}, {0, 8, 12, 4}},
35+	{{2, 3, 1, 2}, {8, 12, 4, 8}},
36+	{{3, 0, 1, 2}, {12, 0, 4, 8}},
37+	{{3, 1, 2, 3}, {12, 4, 8, 12}},
38+	{{3, 2, 3, 1}, {12, 8, 12, 4}},
39+	{{0, 3, 1, 2}, {0, 12, 4, 8}}};
40 
41 static void
42 screen_change(const int x1, const int y1, const int x2, const int y2)
43@@ -581,7 +580,7 @@ screen_draw_sprite(void)
44 	const int dxy = fy * rDX, dyx = fx * rDY;
45 	const int wmar = MAR(screen_width), wmar2 = MAR2(screen_width);
46 	const int hmar2 = MAR2(screen_height);
47-	const Uint8 *table = blending[blend];
48+	const Uint8 *table = blending[blend][!!above];
49 	int i, x1, x2, y1, y2, ax, ay, bx, by, qx, qy, x = rX, y = rY;
50 	if(ctrl & 0x80) {
51 		const int addr_incr = rMA << 2;
52@@ -597,10 +596,7 @@ screen_draw_sprite(void)
53 						const int color = (ch1 >> qx & 1) | (ch2 >> qx & 2);
54 						if(opaque || color) {
55 							const int src = screen_layers[ax] & layer_mask;
56-							if(above)
57-								screen_layers[ax] = src | table[color] << 2;
58-							else
59-								screen_layers[ax] = src | table[color];
60+							screen_layers[ax] = src | table[color];
61 						}
62 					}
63 				}
64@@ -619,10 +615,7 @@ screen_draw_sprite(void)
65 						const int color = ch1 >> qx & 1;
66 						if(opaque || color) {
67 							const int src = screen_layers[ax] & layer_mask;
68-							if(above)
69-								screen_layers[ax] = src | table[color] << 2;
70-							else
71-								screen_layers[ax] = src | table[color];
72+							screen_layers[ax] = src | table[color];
73 						}
74 					}
75 				}
76@@ -1236,7 +1229,7 @@ main(int argc, char **argv)
77 {
78 	int i = 1;
79 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
80-		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 23 Dec 2025.\n");
81+		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 24 Dec 2025.\n");
82 	else if(argc == 1)
83 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
84 	else if(!system_boot(argv[i++], argc > 2))