commit 750564b

Devine Lu Linvega  ·  2024-11-20 00:48:31 +0000 UTC
parent c75f75e
(screen.c) Optimized 2bpp
2 files changed,  +26, -22
+4, -4
 1@@ -24,16 +24,16 @@
 2 	.Screen/x DEI2k #0008 ADD2 ROT DEO2
 3 	.Screen/y DEI2k #0020 SUB2 ROT DEO2
 4 	[ LIT2 36 -Screen/auto ] DEO
 5-	#81 #80 EOR <draw-portrait>
 6+	#81 <draw-portrait>
 7 	.Screen/x DEI2k #0010 SUB2 ROT DEO2
 8 	.Screen/y DEI2k #0020 SUB2 ROT DEO2
 9-	#91 #80 EOR <draw-portrait>
10+	#91 <draw-portrait>
11 	.Screen/x DEI2k #0000 SUB2 ROT DEO2
12 	.Screen/y DEI2k #0020 ADD2 ROT DEO2
13-	#b1 #80 EOR <draw-portrait>
14+	#b1 <draw-portrait>
15 	.Screen/x DEI2k #0010 ADD2 ROT DEO2
16 	.Screen/y DEI2k #0020 ADD2 ROT DEO2
17-	#a1 #80 EOR <draw-portrait>
18+	#a1 <draw-portrait>
19 	( <draw-box>
20 	.Screen/y DEI2k #0060 SUB2 ROT DEO2
21 	<draw-box> )
+22, -18
 1@@ -37,37 +37,41 @@ static Uint8 blending[4][16] = {
 2 	{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
 3 
 4 static void
 5-screen_2bpp(Uint8 *layer, Uint8 *addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
 6+screen_2bpp(Uint8 *layer, Uint8 *addr, Uint16 x1, Uint16 y1, Uint16 blend, int fx, int fy)
 7 {
 8-	int row, w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
 9-	Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
10-	Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
11-	for(y = y1 + ymod; y != ymax; y += fy, addr++) {
12-		int c = (addr[8] << 8) | addr[0];
13-		if(y < h)
14-			for(x = x1 + xmod, row = y * w; x != xmax; x -= fx, c >>= 1) {
15-				Uint8 ch = (c & 1) | ((c >> 7) & 2);
16-				if((opaque || ch) && x < w)
17-					layer[x + row] = blending[ch][color];
18-			}
19+	int x, y, opaque = (blend % 5);
20+	Uint16 top = y1, bottom = y1 + 8, left = x1, right = x1 + 8, offx = 0, offy = 0;
21+	BOUNDARY(y1, top, offy, bottom, uxn_screen.height)
22+	BOUNDARY(x1, left, offx, right, uxn_screen.width)
23+	for(y = top; y < bottom; y++) {
24+		int ptr = fy < 0 ? 7 - (y - top) : y - top + offy * fy;
25+		int ch1 = addr[ptr], ch2 = addr[ptr + 8];
26+		int row = y * uxn_screen.width;
27+		for(x = left; x < right; x++) {
28+			int shift = (fx > 0 ? 7 - (x - left) : x - left) + offx;
29+			int color = ((ch1 >> shift) & 1) | (((ch2 >> shift) & 1) << 1);
30+			if((opaque || color))
31+				layer[x + row] = blending[color][blend];
32+		}
33 	}
34 }
35 
36 static void
37-screen_1bpp(Uint8 *layer, Uint8 *addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
38+screen_1bpp(Uint8 *layer, Uint8 *addr, Uint16 x1, Uint16 y1, Uint16 blend, int fx, int fy)
39 {
40-	int x, y, opaque = (color % 5);
41+	int x, y, opaque = (blend % 5);
42 	Uint16 top = y1, bottom = y1 + 8, left = x1, right = x1 + 8, offx = 0, offy = 0;
43 	BOUNDARY(y1, top, offy, bottom, uxn_screen.height)
44 	BOUNDARY(x1, left, offx, right, uxn_screen.width)
45 	for(y = top; y < bottom; y++) {
46-		int byte = addr[fy < 0 ? 7 - (y - top) : y - top + offy * fy];
47+		int ptr = fy < 0 ? 7 - (y - top) : y - top + offy * fy;
48+		int ch1 = addr[ptr];
49 		int row = y * uxn_screen.width;
50 		for(x = left; x < right; x++) {
51 			int shift = (fx > 0 ? 7 - (x - left) : x - left) + offx;
52-			int ch = (byte >> shift) & 1;
53-			if((opaque || ch))
54-				layer[x + row] = blending[ch][color];
55+			int color = (ch1 >> shift) & 1;
56+			if((opaque || color))
57+				layer[x + row] = blending[color][blend];
58 		}
59 	}
60 }