commit 9e5dbc0

neauoire  ·  2023-11-12 19:58:08 +0000 UTC
parent 0123b40
Faster 1bpp drawing
1 files changed,  +11, -11
+11, -11
 1@@ -73,16 +73,16 @@ screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16
 2 }
 3 
 4 static void
 5-screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int flipx, int flipy)
 6+screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
 7 {
 8-	int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
 9+	int width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
10 	Uint8 *ch1 = &ram[addr];
11-	for(v = 0; v < 8; v++) {
12+	Uint16 y, ymod = (fy < 0 ? 8 : 0), ymax = y1 + ymod + fy * 8;
13+	Uint16 x, xmod = (fx > 0 ? 8 : 0), xmax = x1 + xmod - fx * 8;
14+	for(y = y1 + ymod; y != ymax; y += fy) {
15 		Uint16 c = *ch1++;
16-		Uint16 y = (y1 + (flipy ? 7 - v : v));
17-		for(h = 7; h >= 0; --h, c >>= 1) {
18-			Uint8 ch = (c & 1) | ((c >> 7) & 2);
19-			Uint16 x = (x1 + (flipx ? 7 - h : h));
20+		for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) {
21+			Uint8 ch = c & 1;
22 			if((opaque || ch) && x < width && y < height)
23 				layer[x + y * width] = blending[ch][color];
24 		}
25@@ -109,8 +109,8 @@ static Uint8 arrow[] = {
26 static void
27 draw_byte(Uint8 b, Uint16 x, Uint16 y, Uint8 color)
28 {
29-	screen_1bpp(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 0, 0);
30-	screen_1bpp(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 0, 0);
31+	screen_1bpp(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 1, 1);
32+	screen_1bpp(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 1, 1);
33 	screen_change(x, y, x + 0x10, y + 0x8);
34 }
35 
36@@ -132,7 +132,7 @@ screen_debugger(Uxn *u)
37                                             0x2;
38 		draw_byte(u->rst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x10, color);
39 	}
40-	screen_1bpp(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0);
41+	screen_1bpp(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 1, 1);
42 	for(i = 0; i < 0x20; i++)
43 		draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
44 }
45@@ -275,7 +275,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
46 			}
47 		} else {
48 			for(i = 0; i <= length; i++) {
49-				screen_1bpp(layer, ram, addr, x + dyx * i, y + dxy * i, color, flipx, flipy);
50+				screen_1bpp(layer, ram, addr, x + dyx * i, y + dxy * i, color, fx, fy);
51 				addr += addr_incr;
52 			}
53 		}