commit 1f662d2

neauoire  ·  2023-08-05 17:35:53 +0000 UTC
parent 0446dca
(screen.c) Inlined sprite drawing function
1 files changed,  +15, -20
+15, -20
 1@@ -46,24 +46,6 @@ screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color)
 2 			layer[x + y * width] = color;
 3 }
 4 
 5-static void
 6-screen_blit(Uint8 *layer, Uint8 *ram, Uint16 addr, int x1, int y1, int color, int flipx, int flipy, int twobpp)
 7-{
 8-	int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
 9-	for(v = 0; v < 8; v++) {
10-		Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0);
11-		Uint16 y = y1 + (flipy ? 7 - v : v);
12-		for(h = 7; h >= 0; --h, c >>= 1) {
13-			Uint8 ch = (c & 1) | ((c >> 7) & 2);
14-			if(opaque || ch) {
15-				Uint16 x = x1 + (flipx ? 7 - h : h);
16-				if(x < width && y < height)
17-					layer[x + y * width] = blending[ch][color];
18-			}
19-		}
20-	}
21-}
22-
23 void
24 screen_palette(Uint8 *addr)
25 {
26@@ -185,15 +167,28 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
27 		Uint8 length = move >> 4;
28 		Uint8 twobpp = !!(ctrl & 0x80);
29 		Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg;
30-		Uint8 color = ctrl & 0xf;
31+		Uint8 color = ctrl & 0xf, opaque = color % 5;
32 		Uint16 x = PEEK2(d + 0x8), dx = (move & 0x1) << 3;
33 		Uint16 y = PEEK2(d + 0xa), dy = (move & 0x2) << 2;
34 		Uint16 addr = PEEK2(d + 0xc), addr_incr = (move & 0x4) << (1 + twobpp);
35 		int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1;
36 		int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1;
37+		int v, h, width = uxn_screen.width, height = uxn_screen.height;
38 		Uint16 dyx = dy * fx, dxy = dx * fy;
39 		for(i = 0; i <= length; i++) {
40-			screen_blit(layer, ram, addr, x + dyx * i, y + dxy * i, color, flipx, flipy, twobpp);
41+			Uint16 x1 = x + dyx * i, y1 = y + dxy * i;
42+			for(v = 0; v < 8; v++) {
43+				Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0);
44+				Uint16 y = y1 + (flipy ? 7 - v : v);
45+				for(h = 7; h >= 0; --h, c >>= 1) {
46+					Uint8 ch = (c & 1) | ((c >> 7) & 2);
47+					if(opaque || ch) {
48+						Uint16 x = x1 + (flipx ? 7 - h : h);
49+						if(x < width && y < height)
50+							layer[x + y * width] = blending[ch][color];
51+					}
52+				}
53+			}
54 			addr += addr_incr;
55 		}
56 		screen_change(x, y, x + dyx * length + 8, y + dxy * length + 8);