commit 02632b8
Devine Lu Linvega
·
2026-02-18 04:22:16 +0000 UTC
parent 4aa0753
Unrolled the sprite routine a bit more
1 files changed,
+40,
-28
+40,
-28
1@@ -522,51 +522,63 @@ screen_deo_sprite(void)
2 const int ctrl = dev[0x2f];
3 const int flipx = ctrl & 0x10, flipy = ctrl & 0x20;
4 const int dx = flipx ? -rDY : rDY, dy = flipy ? -rDX : rDX;
5- const int row_start = flipx ? 0 : 7, row_delta = flipx ? 1 : -1;
6- const int col_start = flipy ? 7 : 0, col_delta = flipy ? -1 : 1;
7 const int layer = ctrl & 0x40, layer_mask = layer ? 0x3 : 0xc;
8- const int stride = screen_wmar2;
9 const int blend = ctrl & 0xf;
10- const Uint8 opaque_mask = blend % 5;
11+ const int opaque_mask = blend % 5;
12+ const int shift_right = flipx ? 0 : 1;
13+ const int row_step = flipy ? -1 : 1;
14+ const int row_start = flipy ? 7 : 0;
15 const Uint8 *table = blend_lut[blend][layer >> 6];
16 if(ctrl & 0x80) {
17 const int addr_incr = rMA << 2;
18 for(i = 0; i <= rML; i++, x += dx, y += dy, rA += addr_incr) {
19 const Uint16 x0 = x + 8, y0 = y + 8;
20- if(x0 + 8 >= stride || y0 + 8 >= screen_hmar2) continue;
21- Uint8 *dst = screen_layers + y0 * stride + x0;
22- const Uint8 *col = &ram[rA + col_start];
23- for(j = 0; j < 8; j++, dst += stride, col += col_delta) {
24- Uint8 *d = dst;
25- const int ch1 = *col, ch2 = col[8];
26- for(int k = 0, row = row_start; k < 8; k++, d++, row += row_delta) {
27- const int color = ((ch1 >> row) & 1) | (((ch2 >> row) & 1) << 1);
28- if(opaque_mask || color)
29- *d = (*d & layer_mask) | table[color];
30- }
31+ if(x0 + 8 >= screen_wmar2 || y0 + 8 >= screen_hmar2) continue;
32+ Uint8 *dst = screen_layers + y0 * screen_wmar2 + x0;
33+ const Uint8 *rowptr = &ram[rA + row_start];
34+ for(j = 0; j < 8; j++, dst += screen_wmar2, rowptr += row_step) {
35+ Uint8 *d = dst, bits1 = rowptr[0], bits2 = rowptr[8];
36+ if(shift_right)
37+ for(int k = 0; k < 8; k++, d++, bits1 <<= 1, bits2 <<= 1) {
38+ int color = ((bits1 >> 7) & 1) | ((bits2 >> 6) & 2);
39+ if(opaque_mask || color)
40+ *d = (*d & layer_mask) | table[color];
41+ }
42+ else
43+ for(int k = 0; k < 8; k++, d++, bits1 >>= 1, bits2 >>= 1) {
44+ int color = (bits1 & 1) | ((bits2 & 1) << 1);
45+ if(opaque_mask || color)
46+ *d = (*d & layer_mask) | table[color];
47+ }
48 }
49 }
50 } else {
51 const int addr_incr = rMA << 1;
52 for(i = 0; i <= rML; i++, x += dx, y += dy, rA += addr_incr) {
53 const Uint16 x0 = x + 8, y0 = y + 8;
54- if(x0 + 8 >= stride || y0 + 8 >= screen_hmar2) continue;
55- Uint8 *dst = screen_layers + y0 * stride + x0;
56- const Uint8 *col = &ram[rA + col_start];
57- for(j = 0; j < 8; j++, dst += stride, col += col_delta) {
58- Uint8 *d = dst;
59- const int ch1 = *col;
60- for(int k = 0, row = row_start; k < 8; k++, d++, row += row_delta) {
61- const int color = (ch1 >> row) & 1;
62- if(opaque_mask || color)
63- *d = (*d & layer_mask) | table[color];
64- }
65+ if(x0 + 8 >= screen_wmar2 || y0 + 8 >= screen_hmar2) continue;
66+ Uint8 *dst = screen_layers + y0 * screen_wmar2 + x0;
67+ const Uint8 *rowptr = &ram[rA + row_start];
68+ for(j = 0; j < 8; j++, dst += screen_wmar2, rowptr += row_step) {
69+ Uint8 *d = dst, bits = rowptr[0];
70+ if(shift_right)
71+ for(int k = 0; k < 8; k++, d++, bits <<= 1) {
72+ int color = (bits >> 7) & 1;
73+ if(opaque_mask || color)
74+ *d = (*d & layer_mask) | table[color];
75+ }
76+ else
77+ for(int k = 0; k < 8; k++, d++, bits >>= 1) {
78+ int color = bits & 1;
79+ if(opaque_mask || color)
80+ *d = (*d & layer_mask) | table[color];
81+ }
82 }
83 }
84 }
85 if(!screen_reqdraw) {
86- int x1 = flipx ? x : rX, x2 = flipx ? rX : x;
87- int y1 = flipy ? y : rY, y2 = flipy ? rY : y;
88+ int x1 = flipx ? x : rX, y1 = flipy ? y : rY;
89+ int x2 = flipx ? rX : x, y2 = flipy ? rY : y;
90 screen_change(x1 - 8, y1 - 8, x2 + 8, y2 + 8);
91 }
92 if(rMX) rX += flipx ? -rDX : rDX;