commit be5bded
Devie Lu Linvega
·
2025-12-27 01:06:42 +0000 UTC
parent c59cb0f
Cache screen sizes with margin
1 files changed,
+19,
-19
+19,
-19
1@@ -406,12 +406,13 @@ console_close(void)
2
3 #define MAR(x) (x + 0x8)
4 #define MAR2(x) (x + 0x10)
5+static int screen_zoom = 1;
6
7 static Uint8 *screen_layers;
8-static int screen_zoom = 1;
9-static int screen_width, screen_height;
10-static int screen_x1, screen_y1, screen_x2, screen_y2, screen_reqsize, screen_reqdraw;
11-static unsigned int screen_vector, *screen_pixels, screen_palette[16];
12+static int screen_width, screen_height, screen_wmar2, screen_hmar2;
13+static int screen_reqsize, screen_reqdraw;
14+static int screen_x1, screen_y1, screen_x2, screen_y2;
15+static int screen_vector, *screen_pixels, screen_palette[16];
16 static int rX, rY, rA, rMX, rMY, rMA, rML, rDX, rDY;
17
18 void emu_redraw(void), emu_resize(void);
19@@ -464,11 +465,12 @@ static void
20 screen_resize(int width, int height)
21 {
22 if(width != screen_width || height != screen_height) {
23- int length = MAR2(width) * MAR2(height);
24+ int length;
25+ screen_width = width, screen_wmar2 = MAR2(width);
26+ screen_height = height, screen_hmar2 = MAR2(height);
27+ length = screen_wmar2 * screen_hmar2;
28 screen_layers = realloc(screen_layers, length);
29 memset(screen_layers, 0, length);
30- screen_width = width;
31- screen_height = height;
32 screen_reqsize = screen_reqdraw = 1;
33 }
34 }
35@@ -479,7 +481,7 @@ screen_redraw(void)
36 int i, x, y, k, l;
37 for(y = screen_y1; y < screen_y2; y++) {
38 const int ys = y * screen_zoom;
39- for(x = screen_x1, i = MAR(x) + MAR(y) * MAR2(screen_width); x < screen_x2; x++, i++) {
40+ for(x = screen_x1, i = MAR(x) + MAR(y) * screen_wmar2; x < screen_x2; x++, i++) {
41 const int c = screen_palette[screen_layers[i]];
42 for(k = 0; k < screen_zoom; k++) {
43 const int oo = ((ys + k) * screen_width + x) * screen_zoom;
44@@ -521,7 +523,7 @@ screen_draw_pixel(void)
45 {
46 int layer_mask, color;
47 const int ctrl = dev[0x2e];
48- const int len = MAR2(screen_width);
49+ const int len = screen_wmar2;
50 if(ctrl & 0x40)
51 layer_mask = 0x3, color = (ctrl & 0x3) << 2;
52 else
53@@ -566,8 +568,6 @@ screen_draw_sprite(void)
54 const int fx = ctrl & 0x10 ? -1 : 1, fy = ctrl & 0x20 ? -1 : 1;
55 const int qfx = fx > 0 ? 7 : 0, qfy = fy < 0 ? 7 : 0;
56 const int dxy = fy * rDX, dyx = fx * rDY;
57- const int wmar = MAR(screen_width), wmar2 = MAR2(screen_width);
58- const int hmar2 = MAR2(screen_height);
59 int i, x1, x2, y1, y2, ax, ay, bx, by, qx, qy, x = rX, y = rY, layer_mask;
60 if(ctrl & 0x40)
61 layer_mask = 0x3, table = blending[blend][1];
62@@ -576,11 +576,11 @@ screen_draw_sprite(void)
63 if(ctrl & 0x80) {
64 const int addr_incr = rMA << 2;
65 for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr) {
66- const Uint16 xmar = MAR(x), ymar2 = MAR2(y);
67- if(xmar < wmar && ymar2 < hmar2) {
68- const Uint16 xmar2 = MAR2(x), ymar = MAR(y);
69+ const Uint16 ymar2 = MAR2(y), xmar2 = MAR2(x);
70+ if(xmar2 < screen_wmar2 && ymar2 < screen_hmar2) {
71+ const Uint16 xmar = MAR(x), ymar = MAR(y);
72 const Uint8 *sprite = &ram[rA];
73- for(ay = ymar * wmar2, by = ymar2 * wmar2, qy = qfy; ay < by; ay += wmar2, qy += fy) {
74+ for(ay = ymar * screen_wmar2, by = ymar2 * screen_wmar2, qy = qfy; ay < by; ay += screen_wmar2, qy += fy) {
75 const int ch1 = sprite[qy];
76 const int ch2 = sprite[qy + 8] << 1;
77 for(ax = xmar + ay, bx = xmar2 + ay, qx = qfx; ax < bx; ax++, qx -= fx) {
78@@ -594,11 +594,11 @@ screen_draw_sprite(void)
79 } else {
80 const int addr_incr = rMA << 1;
81 for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr) {
82- const Uint16 xmar = MAR(x), ymar2 = MAR2(y);
83- if(xmar < wmar && ymar2 < hmar2) {
84- const Uint16 xmar2 = MAR2(x), ymar = MAR(y);
85+ const Uint16 ymar2 = MAR2(y), xmar2 = MAR2(x);
86+ if(xmar2 < screen_wmar2 && ymar2 < screen_hmar2) {
87+ const Uint16 xmar = MAR(x), ymar = MAR(y);
88 const Uint8 *sprite = &ram[rA];
89- for(ay = ymar * wmar2, by = ymar2 * wmar2, qy = qfy; ay < by; ay += wmar2, qy += fy) {
90+ for(ay = ymar * screen_wmar2, by = ymar2 * screen_wmar2, qy = qfy; ay < by; ay += screen_wmar2, qy += fy) {
91 const int ch1 = sprite[qy];
92 for(ax = xmar + ay, bx = xmar2 + ay, qx = qfx; ax < bx; ax++, qx -= fx) {
93 const int color = ch1 >> qx & 1;