commit 6307e2e
Devine Lu Linvega
·
2026-01-10 00:36:11 +0000 UTC
parent c02e8ed
Cache sprite flags
1 files changed,
+18,
-14
+18,
-14
1@@ -599,24 +599,28 @@ screen_deo_sprite(void)
2 const int ctrl = dev[0x2f];
3 const int blend = ctrl & 0xf;
4 const int opaque = blend % 5;
5- const int flipx = ctrl & 0x10, fx = flipx ? -1 : 1, qfx = flipx ? 0 : 7;
6- const int flipy = ctrl & 0x20, fy = flipy ? -1 : 1, qfy = flipy ? 7 : 0;
7- const int dyx = fx * rDY;
8- const int dxy = fy * rDX;
9+ const int flipx = ctrl & 0x10;
10+ const int flipy = ctrl & 0x20;
11 const int layer_mask = (ctrl & 0x40) ? 0x3 : 0xc;
12 const Uint8 *table = (ctrl & 0x40) ? blending[blend][1] : blending[blend][0];
13 const int is_2bpp = (ctrl & 0x80) != 0;
14 const int addr_incr = rMA << (is_2bpp ? 2 : 1);
15 const int stride = screen_wmar2;
16- for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr) {
17+ const int dx = flipx ? -rDY : rDY;
18+ const int dy = flipy ? -rDX : rDX;
19+ const int qfx = flipx ? 0 : 7;
20+ const int qfy = flipy ? 7 : 0;
21+ const int qx_step = flipx ? 1 : -1;
22+ const int src_stride = flipy ? -1 : 1;
23+ for(i = 0; i <= rML; i++, x += dx, y += dy, rA += addr_incr) {
24 const Uint16 x0 = x + 8, y0 = y + 8;
25 if(x0 + 8 >= stride || y0 + 8 >= screen_hmar2) continue;
26 Uint8 *dst = &screen_layers[x0 + y0 * stride];
27 const Uint8 *src = &ram[rA + qfy];
28- for(row = 0; row < 8; row++, dst += stride, src += fy) {
29- int qx = qfx;
30+ for(row = 0; row < 8; row++, dst += stride, src += src_stride) {
31 const int ch1 = *src, ch2 = is_2bpp ? (src[8] << 1) : 0;
32- for(px = 0; px < 8; px++, qx -= fx) {
33+ int qx = qfx;
34+ for(px = 0; px < 8; px++, qx += qx_step) {
35 int color = ((ch1 >> qx) & 1) | ((ch2 >> qx) & 2);
36 if(opaque || color)
37 dst[px] = (dst[px] & layer_mask) | table[color];
38@@ -624,14 +628,14 @@ screen_deo_sprite(void)
39 }
40 }
41 if(!screen_reqdraw) {
42- int x1 = (fx < 0) ? x : rX;
43- int x2 = (fx < 0) ? rX : x;
44- int y1 = (fy < 0) ? y : rY;
45- int y2 = (fy < 0) ? rY : y;
46+ int x1 = flipx ? x : rX;
47+ int x2 = flipx ? rX : x;
48+ int y1 = flipy ? y : rY;
49+ int y2 = flipy ? rY : y;
50 screen_change(x1 - 8, y1 - 8, x2 + 8, y2 + 8);
51 }
52- if(rMX) rX += rDX * fx;
53- if(rMY) rY += rDY * fy;
54+ if(rMX) rX += flipx ? -rDX : rDX;
55+ if(rMY) rY += flipy ? -rDY : rDY;
56 }
57
58 /* clang-format off */