commit 8530f2f

neauoire  ·  2023-08-30 19:15:52 +0000 UTC
parent 74c830c
(screen.c) Faster DEI/DEO
2 files changed,  +43, -21
+12, -6
 1@@ -29,17 +29,23 @@ mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
 2 void
 3 mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
 4 {
 5-	POKE2(d + 0x2, x);
 6-	POKE2(d + 0x4, y);
 7+	*(d + 2) = x >> 8;
 8+	*(d + 3) = x;
 9+	*(d + 4) = y >> 8;
10+	*(d + 5) = y;
11 	uxn_eval(u, PEEK2(d));
12 }
13 
14 void
15 mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
16 {
17-	POKE2(d + 0xa, x);
18-	POKE2(d + 0xc, -y);
19+	*(d + 0xa) = x >> 8;
20+	*(d + 0xb) = x;
21+	*(d + 0xc) = -y >> 8;
22+	*(d + 0xd) = -y;
23 	uxn_eval(u, PEEK2(d));
24-	POKE2(d + 0xa, 0);
25-	POKE2(d + 0xc, 0);
26+	*(d + 0xa) = 0;
27+	*(d + 0xb) = 0;
28+	*(d + 0xc) = 0;
29+	*(d + 0xd) = 0;
30 }
+31, -15
 1@@ -120,7 +120,7 @@ screen_resize(Uint16 width, Uint16 height)
 2 {
 3 	Uint8 *bg, *fg;
 4 	Uint32 *pixels = NULL;
 5-	if(width < 0x8 || height < 0x8 || width >= 0x400 || height >= 0x400)
 6+	if(width < 0x8 || height < 0x8 || width >= 0x800 || height >= 0x800)
 7 		return;
 8 	if(uxn_screen.width == width && uxn_screen.height == height)
 9 		return;
10@@ -180,19 +180,25 @@ screen_dei(Uxn *u, Uint8 addr)
11 void
12 screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
13 {
14+	Uint8 *port_width, *port_height, *port_x, *port_y, *port_addr;
15+	Uint16 x, y, dx, dy, dxy, dyx, addr, addr_incr;
16 	switch(port) {
17 	case 0x3:
18-		screen_resize(PEEK2(d + 2), uxn_screen.height);
19+		port_width = d + 0x2;
20+		screen_resize(PEEK2(port_width), uxn_screen.height);
21 		break;
22 	case 0x5:
23-		screen_resize(uxn_screen.width, PEEK2(d + 4));
24+		port_height = d + 0x4;
25+		screen_resize(uxn_screen.width, PEEK2(port_height));
26 		break;
27 	case 0xe: {
28 		Uint8 ctrl = d[0xe];
29 		Uint8 color = ctrl & 0x3;
30-		Uint16 x = PEEK2(d + 0x8);
31-		Uint16 y = PEEK2(d + 0xa);
32 		Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg;
33+		port_x = d + 0x8;
34+		port_y = d + 0xa;
35+		x = PEEK2(port_x);
36+		y = PEEK2(port_y);
37 		/* fill mode */
38 		if(ctrl & 0x80) {
39 			Uint16 x2 = uxn_screen.width;
40@@ -208,9 +214,11 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
41 			Uint16 height = uxn_screen.height;
42 			if(x < width && y < height)
43 				layer[x + y * width] = color;
44-			screen_change(x, y, x + 1, y + 1);
45-			if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */
46-			if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */
47+			x += 1;
48+			y += 1;
49+			screen_change(x, y, x, y);
50+			if(d[0x6] & 0x1) POKE2(port_x, x);
51+			if(d[0x6] & 0x2) POKE2(port_y, y);
52 		}
53 		break;
54 	}
55@@ -222,20 +230,28 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
56 		Uint8 twobpp = !!(ctrl & 0x80);
57 		Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg;
58 		Uint8 color = ctrl & 0xf;
59-		Uint16 x = PEEK2(d + 0x8), dx = (move & 0x1) << 3;
60-		Uint16 y = PEEK2(d + 0xa), dy = (move & 0x2) << 2;
61-		Uint16 addr = PEEK2(d + 0xc), addr_incr = (move & 0x4) << (1 + twobpp);
62 		int flipx = (ctrl & 0x10), fx = flipx ? -1 : 1;
63 		int flipy = (ctrl & 0x20), fy = flipy ? -1 : 1;
64-		Uint16 dyx = dy * fx, dxy = dx * fy;
65+		port_x = d + 0x8;
66+		port_y = d + 0xa;
67+		port_addr = d + 0xc;
68+		x = PEEK2(port_x), dx = (move & 0x1) << 3, dxy = dx * fy;
69+		y = PEEK2(port_y), dy = (move & 0x2) << 2, dyx = dy * fx;
70+		addr = PEEK2(port_addr), addr_incr = (move & 0x4) << (1 + twobpp);
71 		for(i = 0; i <= length; i++) {
72 			screen_blit(layer, ram, addr, x + dyx * i, y + dxy * i, color, flipx, flipy, twobpp);
73 			addr += addr_incr;
74 		}
75 		screen_change(x, y, x + dyx * length + 8, y + dxy * length + 8);
76-		if(move & 0x1) POKE2(d + 0x8, x + dx * fx); /* auto x+8 */
77-		if(move & 0x2) POKE2(d + 0xa, y + dy * fy); /* auto y+8 */
78-		if(move & 0x4) POKE2(d + 0xc, addr);        /* auto addr+length */
79+		if(move & 0x1) {
80+			x = x + dx * fx;
81+			POKE2(port_x, x);
82+		}
83+		if(move & 0x2) {
84+			y = y + dy * fy;
85+			POKE2(port_y, y);
86+		}
87+		if(move & 0x4) POKE2(port_addr, addr); /* auto addr+length */
88 		break;
89 	}
90 	}