commit d690545

Devie Lu Linvega  ·  2025-12-23 16:44:51 +0000 UTC
parent 57fc038
Cleanup
2 files changed,  +54, -54
+53, -54
  1@@ -509,6 +509,53 @@ screen_redraw(void)
  2 	uxn_screen.x1 = uxn_screen.y1 = uxn_screen.x2 = uxn_screen.y2 = 0;
  3 }
  4 
  5+static void
  6+emu_repaint(void)
  7+{
  8+	const int x = uxn_screen.x1 * uxn_screen.zoom;
  9+	const int y = uxn_screen.y1 * uxn_screen.zoom;
 10+	const int w = uxn_screen.x2 * uxn_screen.zoom - x;
 11+	const int h = uxn_screen.y2 * uxn_screen.zoom - y;
 12+	screen_redraw();
 13+	XPutImage(display, window, DefaultGC(display, 0), ximage, x, y, x, y, w, h);
 14+}
 15+
 16+static void
 17+emu_repaint_all(void)
 18+{
 19+	uxn_screen.x1 = uxn_screen.y1 = 0;
 20+	uxn_screen.x2 = uxn_screen.width;
 21+	uxn_screen.y2 = uxn_screen.height;
 22+	emu_repaint();
 23+}
 24+
 25+void
 26+emu_resize(void)
 27+{
 28+	const int width = uxn_screen.width * uxn_screen.zoom;
 29+	const int height = uxn_screen.height * uxn_screen.zoom;
 30+	XResizeWindow(display, window, width, height);
 31+	uxn_screen.pixels = realloc(uxn_screen.pixels,
 32+		uxn_screen.width * uxn_screen.height * sizeof(unsigned int) * uxn_screen.zoom * uxn_screen.zoom);
 33+	if(ximage)
 34+		free(ximage);
 35+	ximage = XCreateImage(display, DefaultVisual(display, 0), DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, width, height, 32, 0);
 36+	emu_repaint_all();
 37+}
 38+
 39+static void
 40+screen_update()
 41+{
 42+	if(screen_vector)
 43+		uxn_eval(screen_vector);
 44+	if(uxn_screen.resized)
 45+		emu_resize(), uxn_screen.resized = 0;
 46+	if(uxn_screen.redraw)
 47+		emu_repaint_all(), uxn_screen.redraw = 0;
 48+	else if(screen_changed())
 49+		emu_repaint();
 50+}
 51+
 52 /* screen registers */
 53 
 54 static int rX, rY, rA, rMX, rMY, rMA, rML, rDX, rDY;
 55@@ -1041,40 +1088,6 @@ emu_deo(const Uint8 port, const Uint8 value)
 56 	}
 57 }
 58 
 59-static void
 60-emu_repaint(void)
 61-{
 62-	const int x = uxn_screen.x1 * uxn_screen.zoom;
 63-	const int y = uxn_screen.y1 * uxn_screen.zoom;
 64-	const int w = uxn_screen.x2 * uxn_screen.zoom - x;
 65-	const int h = uxn_screen.y2 * uxn_screen.zoom - y;
 66-	screen_redraw();
 67-	XPutImage(display, window, DefaultGC(display, 0), ximage, x, y, x, y, w, h);
 68-}
 69-
 70-static void
 71-emu_repaint_all(void)
 72-{
 73-	uxn_screen.x1 = uxn_screen.y1 = 0;
 74-	uxn_screen.x2 = uxn_screen.width;
 75-	uxn_screen.y2 = uxn_screen.height;
 76-	emu_repaint();
 77-}
 78-
 79-void
 80-emu_resize(void)
 81-{
 82-	const int width = uxn_screen.width * uxn_screen.zoom;
 83-	const int height = uxn_screen.height * uxn_screen.zoom;
 84-	XResizeWindow(display, window, width, height);
 85-	uxn_screen.pixels = realloc(uxn_screen.pixels,
 86-		uxn_screen.width * uxn_screen.height * sizeof(unsigned int) * uxn_screen.zoom * uxn_screen.zoom);
 87-	if(ximage)
 88-		free(ximage);
 89-	ximage = XCreateImage(display, DefaultVisual(display, 0), DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, width, height, 32, 0);
 90-	emu_repaint_all();
 91-}
 92-
 93 static void
 94 emu_restart(unsigned int soft)
 95 {
 96@@ -1084,13 +1097,6 @@ emu_restart(unsigned int soft)
 97 	uxn_eval(0x100);
 98 }
 99 
100-static void
101-emu_rescale(void)
102-{
103-	uxn_screen.zoom = uxn_screen.zoom >= 3 ? 1 : uxn_screen.zoom + 1;
104-	uxn_screen.resized = 1;
105-}
106-
107 static Uint8
108 get_button(KeySym sym)
109 {
110@@ -1175,7 +1181,7 @@ emu_event(void)
111 		KeySym sym;
112 		XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
113 		switch(sym) {
114-		case XK_F1: emu_rescale(); break;
115+		case XK_F1: uxn_screen.zoom = (uxn_screen.zoom % 3) + 1, uxn_screen.resized = 1; break;
116 		case XK_F2: emu_deo(0xe, 0x1); break;
117 		case XK_F4: emu_restart(0); break;
118 		case XK_F5: emu_restart(1); break;
119@@ -1233,14 +1239,7 @@ emu_run(void)
120 			emu_event();
121 		if(poll(&fds[1], 1, 0)) {
122 			(void)read(fds[1].fd, expirations, 8);
123-			if(screen_vector)
124-				uxn_eval(screen_vector);
125-			if(uxn_screen.resized)
126-				emu_resize(), uxn_screen.resized = 0;
127-			if(uxn_screen.redraw)
128-				emu_repaint_all(), uxn_screen.redraw = 0;
129-			else if(screen_changed())
130-				emu_repaint();
131+			screen_update();
132 		}
133 		has_input = fds[2].revents & POLLIN;
134 		has_eof = fds[2].revents & POLLHUP;
135@@ -1252,10 +1251,6 @@ emu_run(void)
136 				console_input(0, CONSOLE_STD);
137 		}
138 	}
139-	if(ximage)
140-		XDestroyImage(ximage);
141-	XDestroyWindow(display, window);
142-	XCloseDisplay(display);
143 }
144 
145 int
146@@ -1281,6 +1276,10 @@ main(int argc, char **argv)
147 	if(!display_init())
148 		return !fprintf(stdout, "Could not open display.\n");
149 	emu_run();
150+	if(ximage)
151+		XDestroyImage(ximage);
152+	XDestroyWindow(display, window);
153+	XCloseDisplay(display);
154 	console_close();
155 	return dev[0x0f] & 0x7f;
156 }
+1, -0
1@@ -636,6 +636,7 @@ emu_dei(const Uint8 port)
2 	/* Console */
3 	case CMD_LIVE:
4 	case CMD_EXIT: check_child(); break;
5+	/* DateTime */
6 	case 0xc0: datetime_update(); return (datetime_t->tm_year + 1900) >> 8;
7 	case 0xc1: datetime_update(); return (datetime_t->tm_year + 1900);
8 	case 0xc2: datetime_update(); return datetime_t->tm_mon;