commit da48ec5
Devie Lu Linvega
·
2025-12-23 17:41:27 +0000 UTC
parent aec2e45
Cleanup
1 files changed,
+39,
-44
+39,
-44
1@@ -28,22 +28,17 @@ typedef unsigned short Uint16;
2 static XImage *ximage;
3 static Display *display;
4 static Window window;
5-static Uint8 *ram, dev[0x100], ptr[2], stk[2][0x100];
6-
7-Uint8 emu_dei(const Uint8 port);
8-void emu_deo(const Uint8 port, const Uint8 value);
9
10 /* clang-format off */
11
12+#define BANKS 0x10
13+#define BANKS_CAP BANKS * 0x10000
14 #define WIDTH (64 * 8)
15 #define HEIGHT (40 * 8)
16
17 #define clamp(v, a, b) { if(v < a) v = a; else if(v >= b) v = b; }
18 #define twos(v) (v & 0x8000 ? (int)v - 0x10000 : (int)v)
19
20-#define BANKS 0x10
21-#define BANKS_CAP BANKS * 0x10000
22-
23 #define PEEK2(d) (*(d) << 8 | (d)[1])
24 #define POKE2(d, v) { *(d) = (v) >> 8; (d)[1] = (v); }
25
26@@ -78,8 +73,11 @@ void emu_deo(const Uint8 port, const Uint8 value);
27 #define DEI(i,r) r[0] = emu_dei(i); if(_2) r[1] = emu_dei(i + 1); PUT(r)
28 #define PEK(i,r,m) r[0] = ram[i]; if(_2) r[1] = ram[(i + 1) & m]; PUT(r)
29
30-static unsigned int
31-uxn_eval(unsigned short pc)
32+Uint8 *ram, dev[0x100], ptr[2], stk[2][0x100], emu_dei(const Uint8 port);
33+void emu_deo(const Uint8 port, const Uint8 value);
34+
35+unsigned int
36+uxn_eval(Uint16 pc)
37 {
38 unsigned int a, b, c, x[2], y[2], z[2], cycles = 0x80000000;
39 step:
40@@ -180,26 +178,26 @@ static void
41 system_expansion(const Uint16 exp)
42 {
43 Uint8 *aptr = ram + exp;
44- unsigned short length = PEEK2(aptr + 1), limit;
45+ Uint16 length = PEEK2(aptr + 1), limit;
46 unsigned int bank = PEEK2(aptr + 3) * 0x10000;
47 unsigned int addr = PEEK2(aptr + 5);
48 if(ram[exp] == 0x0) {
49 unsigned int dst_value = ram[exp + 7];
50- unsigned short a = addr;
51+ Uint16 a = addr;
52 if(bank < BANKS_CAP)
53 for(limit = a + length; a != limit; a++)
54 ram[bank + a] = dst_value;
55 } else if(ram[exp] == 0x1) {
56 unsigned int dst_bank = PEEK2(aptr + 7) * 0x10000;
57 unsigned int dst_addr = PEEK2(aptr + 9);
58- unsigned short a = addr, c = dst_addr;
59+ Uint16 a = addr, c = dst_addr;
60 if(bank < BANKS_CAP && dst_bank < BANKS_CAP)
61 for(limit = a + length; a != limit; c++, a++)
62 ram[dst_bank + c] = ram[bank + a];
63 } else if(ram[exp] == 0x2) {
64 unsigned int dst_bank = PEEK2(aptr + 7) * 0x10000;
65 unsigned int dst_addr = PEEK2(aptr + 9);
66- unsigned short a = addr + length - 1, c = dst_addr + length - 1;
67+ Uint16 a = addr + length - 1, c = dst_addr + length - 1;
68 if(bank < BANKS_CAP && dst_bank < BANKS_CAP)
69 for(limit = addr - 1; a != limit; a--, c--)
70 ram[dst_bank + c] = ram[bank + a];
71@@ -409,12 +407,12 @@ console_input(int c, unsigned int type)
72 #define MAR2(x) (x + 0x10)
73
74 typedef struct UxnScreen {
75- int width, height, zoom, resized, redraw, x1, y1, x2, y2;
76- unsigned int palette[16], *pixels;
77+ int width, height, zoom, resized, full, x1, y1, x2, y2;
78+ unsigned int palette[16];
79 Uint8 *bg;
80 } UxnScreen;
81
82-static unsigned int screen_vector;
83+static unsigned int screen_vector, *screen_pixels;
84 static UxnScreen uxn_screen;
85
86 static const Uint8 blending[16][4] = {
87@@ -459,28 +457,25 @@ screen_palette(void)
88 }
89 for(i = 0; i < 16; i++)
90 uxn_screen.palette[i] = colors[(i >> 2) ? (i >> 2) : (i & 3)];
91- uxn_screen.redraw = 1;
92+ uxn_screen.full = 1;
93 }
94
95 static void
96 screen_resize(int width, int height)
97 {
98- int length;
99- clamp(width, 8, 0x800);
100- clamp(height, 8, 0x800);
101- if(width == uxn_screen.width && height == uxn_screen.height)
102- return;
103- length = MAR2(width) * MAR2(height);
104- uxn_screen.bg = realloc(uxn_screen.bg, length);
105- memset(uxn_screen.bg, 0, length);
106- uxn_screen.width = width;
107- uxn_screen.height = height;
108- uxn_screen.resized = 1;
109- uxn_screen.redraw = 1;
110+ if(width != uxn_screen.width || height != uxn_screen.height) {
111+ int length = MAR2(width) * MAR2(height);
112+ uxn_screen.bg = realloc(uxn_screen.bg, length);
113+ memset(uxn_screen.bg, 0, length);
114+ uxn_screen.width = width;
115+ uxn_screen.height = height;
116+ uxn_screen.resized = 1;
117+ uxn_screen.full = 1;
118+ }
119 }
120
121 static void
122-emu_repaint(void)
123+scree_redraw(void)
124 {
125 const int ax = uxn_screen.x1 * uxn_screen.zoom;
126 const int ay = uxn_screen.y1 * uxn_screen.zoom;
127@@ -494,12 +489,12 @@ emu_repaint(void)
128 for(k = 0; k < uxn_screen.zoom; k++) {
129 const int oo = ((ys + k) * uxn_screen.width + x) * uxn_screen.zoom;
130 for(l = 0; l < uxn_screen.zoom; l++)
131- uxn_screen.pixels[oo + l] = c;
132+ screen_pixels[oo + l] = c;
133 }
134 }
135 }
136 XPutImage(display, window, DefaultGC(display, 0), ximage, ax, ay, ax, ay, aw, ah);
137- uxn_screen.x1 = uxn_screen.y1 = uxn_screen.x2 = uxn_screen.y2 = uxn_screen.redraw = 0;
138+ uxn_screen.x1 = uxn_screen.y1 = uxn_screen.x2 = uxn_screen.y2 = uxn_screen.full = 0;
139 }
140
141 static void
142@@ -512,24 +507,24 @@ screen_update()
143 const int height = uxn_screen.height * uxn_screen.zoom;
144 const int length = uxn_screen.width * uxn_screen.height * sizeof(unsigned int) * uxn_screen.zoom * uxn_screen.zoom;
145 XResizeWindow(display, window, width, height);
146- uxn_screen.pixels = realloc(uxn_screen.pixels, length);
147+ screen_pixels = realloc(screen_pixels, length);
148 if(ximage)
149 free(ximage);
150- ximage = XCreateImage(display, DefaultVisual(display, 0), DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, width, height, 32, 0);
151- uxn_screen.redraw = 1;
152+ ximage = XCreateImage(display, DefaultVisual(display, 0), DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)screen_pixels, width, height, 32, 0);
153+ uxn_screen.full = 1;
154 uxn_screen.resized = 0;
155 }
156- if(uxn_screen.redraw) {
157+ if(uxn_screen.full) {
158 uxn_screen.x1 = uxn_screen.y1 = 0;
159 uxn_screen.x2 = uxn_screen.width;
160 uxn_screen.y2 = uxn_screen.height;
161- emu_repaint();
162+ scree_redraw();
163 } else if(uxn_screen.x2 > uxn_screen.x1 && uxn_screen.y2 > uxn_screen.y1) {
164 clamp(uxn_screen.x1, 0, uxn_screen.width);
165 clamp(uxn_screen.y1, 0, uxn_screen.height);
166 clamp(uxn_screen.x2, 0, uxn_screen.width);
167 clamp(uxn_screen.y2, 0, uxn_screen.height);
168- emu_repaint();
169+ scree_redraw();
170 }
171 }
172
173@@ -555,7 +550,7 @@ screen_draw_pixel(void)
174 y1 = 0, y2 = rY;
175 else
176 y1 = rY, y2 = uxn_screen.height;
177- uxn_screen.redraw = 1;
178+ uxn_screen.full = 1;
179 x1 = MAR(x1), y1 = MAR(y1);
180 hor = MAR(x2) - x1, ver = MAR(y2) - y1;
181 for(ay = y1 * len, by = ay + ver * len; ay < by; ay += len)
182@@ -571,7 +566,7 @@ screen_draw_pixel(void)
183 const int src = uxn_screen.bg[ax];
184 uxn_screen.bg[ax] = above ? (src & 0x3) | color : (src & 0xc) | color;
185 }
186- if(!uxn_screen.redraw) screen_change(rX, rY, rX + 1, rY + 1);
187+ if(!uxn_screen.full) screen_change(rX, rY, rX + 1, rY + 1);
188 if(rMX) rX++;
189 if(rMY) rY++;
190 }
191@@ -640,7 +635,7 @@ screen_draw_sprite(void)
192 y1 = y, y2 = rY;
193 else
194 y1 = rY, y2 = y;
195- if(!uxn_screen.redraw) screen_change(x1 - 8, y1 - 8, x2 + 8, y2 + 8);
196+ if(!uxn_screen.full) screen_change(x1 - 8, y1 - 8, x2 + 8, y2 + 8);
197 if(rMX) rX += rDX * fx;
198 if(rMY) rY += rDY * fy;
199 }
200@@ -1033,8 +1028,8 @@ emu_deo(const Uint8 port, const Uint8 value)
201 case 0x1f: console_start_fork(); return;
202 /* Screen */
203 case 0x21: screen_vector = PEEK2(&dev[0x20]); return;
204- case 0x23: screen_resize(PEEK2(&dev[0x22]), uxn_screen.height); return;
205- case 0x25: screen_resize(uxn_screen.width, PEEK2(&dev[0x24])); return;
206+ case 0x23: screen_resize(PEEK2(&dev[0x22]) & 0xfff, uxn_screen.height & 0xfff); return;
207+ case 0x25: screen_resize(uxn_screen.width & 0xfff, PEEK2(&dev[0x24]) & 0xfff); return;
208 case 0x26: rMX = dev[0x26] & 0x1, rMY = dev[0x26] & 0x2, rMA = dev[0x26] & 0x4, rML = dev[0x26] >> 4, rDX = rMX << 3, rDY = rMY << 2; return;
209 case 0x28:
210 case 0x29: rX = (dev[0x28] << 8) | dev[0x29], rX = twos(rX); return;
211@@ -1149,7 +1144,7 @@ emu_event(void)
212 XNextEvent(display, &ev);
213 switch(ev.type) {
214 case Expose:
215- uxn_screen.redraw = 1;
216+ uxn_screen.full = 1;
217 break;
218 case ClientMessage:
219 dev[0x0f] = 0x80;