commit 402e2ad
Devine Lu Linvega
·
2026-01-07 23:43:39 +0000 UTC
parent cda5d55
Const a few things
1 files changed,
+23,
-14
+23,
-14
1@@ -463,10 +463,10 @@ static const Uint8 blending[16][2][4] = {
2 static void
3 screen_change(const int x1, const int y1, const int x2, const int y2)
4 {
5- if(x1 < screen_x1) screen_x1 = x1;
6- if(y1 < screen_y1) screen_y1 = y1;
7- if(x2 > screen_x2) screen_x2 = x2;
8- if(y2 > screen_y2) screen_y2 = y2;
9+ screen_x1 = x1 < screen_x1 ? x1 : screen_x1;
10+ screen_y1 = y1 < screen_y1 ? y1 : screen_y1;
11+ screen_x2 = x2 > screen_x2 ? x2 : screen_x2;
12+ screen_y2 = y2 > screen_y2 ? y2 : screen_y2;
13 }
14
15 static void
16@@ -517,12 +517,13 @@ screen_redraw(void)
17 }
18 } else {
19 int i, k, l;
20+ const int stride = screen_width * screen_zoom;
21 for(y = screen_y1; y < screen_y2; y++) {
22 const int ys = y * screen_zoom;
23 for(x = screen_x1, i = (x + 8) + (y + 8) * screen_wmar2; x < screen_x2; x++, i++) {
24 const int c = screen_palette[screen_layers[i]];
25 for(k = 0; k < screen_zoom; k++) {
26- const int oo = (ys + k) * screen_width * screen_zoom + x * screen_zoom;
27+ const int oo = (ys + k) * stride + x * screen_zoom;
28 for(l = 0; l < screen_zoom; l++)
29 screen_pixels[oo + l] = c;
30 }
31@@ -539,7 +540,13 @@ screen_update(void)
32 if(screen_vector)
33 uxn_eval(screen_vector);
34 if(screen_reqsize) {
35- screen_pixels = realloc(screen_pixels, screen_width * screen_height * sizeof(unsigned int) * screen_zoom * screen_zoom);
36+ static int pixel_capacity;
37+ /* TODO: Recalculate only once on change */
38+ int need = screen_width * screen_height * screen_zoom * screen_zoom;
39+ if(need > pixel_capacity) {
40+ pixel_capacity = need;
41+ screen_pixels = realloc(screen_pixels, need * sizeof(unsigned int));
42+ }
43 screen_reqsize = 0;
44 emu_resize();
45 }
46@@ -641,31 +648,33 @@ screen_deo_sprite(void)
47 layer_mask = 0xc, table = blending[blend][0];
48 if(ctrl & 0x80) {
49 const int addr_incr = rMA << 2;
50+ const int stride = screen_wmar2;
51 for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr) {
52 const Uint16 xmar2 = x + 16, ymar2 = y + 16, xmar = x + 8, ymar = y + 8;
53- if(xmar2 == xmar + 8 && ymar2 == ymar + 8 && xmar2 < screen_wmar2 && ymar2 < screen_hmar2) {
54- Uint8 *dst = &screen_layers[xmar + ymar * screen_wmar2];
55+ if(xmar2 == xmar + 8 && ymar2 == ymar + 8 && xmar2 < stride && ymar2 < screen_hmar2) {
56+ Uint8 *dst = &screen_layers[xmar + ymar * stride];
57 const Uint8 *sch1 = &ram[rA + qfy], *sch2 = sch1 + 8;
58 if(opaque)
59- for(row = 0; row < 8; row++, dst += screen_wmar2, sch1 += fy, sch2 += fy)
60+ for(row = 0; row < 8; row++, dst += stride, sch1 += fy, sch2 += fy)
61 PUT_PIXELS(n, 1, 1, *sch1, *sch2 << 1)
62 else
63- for(row = 0; row < 8; row++, dst += screen_wmar2, sch1 += fy, sch2 += fy)
64+ for(row = 0; row < 8; row++, dst += stride, sch1 += fy, sch2 += fy)
65 PUT_PIXELS(n, 0, 1, *sch1, *sch2 << 1)
66 }
67 }
68 } else {
69 const int addr_incr = rMA << 1;
70+ const int stride = screen_wmar2;
71 for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr) {
72 const Uint16 xmar2 = x + 16, ymar2 = y + 16, xmar = x + 8, ymar = y + 8;
73- if(xmar2 == xmar + 8 && ymar2 == ymar + 8 && xmar2 < screen_wmar2 && ymar2 < screen_hmar2) {
74- Uint8 *dst = &screen_layers[xmar + ymar * screen_wmar2];
75+ if(xmar2 == xmar + 8 && ymar2 == ymar + 8 && xmar2 < stride && ymar2 < screen_hmar2) {
76+ Uint8 *dst = &screen_layers[xmar + ymar * stride];
77 const Uint8 *sch1 = &ram[rA + qfy];
78 if(opaque)
79- for(row = 0; row < 8; row++, dst += screen_wmar2, sch1 += fy)
80+ for(row = 0; row < 8; row++, dst += stride, sch1 += fy)
81 PUT_PIXELS(n, 1, 0, *sch1, 0)
82 else
83- for(row = 0; row < 8; row++, dst += screen_wmar2, sch1 += fy)
84+ for(row = 0; row < 8; row++, dst += stride, sch1 += fy)
85 PUT_PIXELS(n, 0, 0, *sch1, 0)
86 }
87 }