commit 6761181

Devine Lu Linvega  ·  2026-01-03 17:42:56 +0000 UTC
parent 65f1d70
Fixed bug where EOF was hammering console/vector
1 files changed,  +8, -9
+8, -9
 1@@ -9,7 +9,7 @@
 2 #include <poll.h>
 3 
 4 /*
 5-Copyright (c) 2021-2025 Devine Lu Linvega, Andrew Alderwick, 
 6+Copyright (c) 2021-2026 Devine Lu Linvega, Andrew Alderwick, 
 7 Andrew Richards, Eiríkr Åsheim, Sigrid Solveig Haflínudóttir
 8 
 9 Permission to use, copy, modify, and distribute this software for any
10@@ -531,7 +531,6 @@ screen_draw_pixel(void)
11 {
12 	int layer_mask, color, px;
13 	const int ctrl = dev[0x2e];
14-	const int len = screen_wmar2;
15 	if(ctrl & 0x40)
16 		layer_mask = 0x3, color = (ctrl & 0x3) << 2;
17 	else
18@@ -550,7 +549,7 @@ screen_draw_pixel(void)
19 		screen_reqdraw = 1;
20 		x1 = x1 + 8, y1 = y1 + 8;
21 		const int hor = (x2 + 8) - x1, ver = (y2 + 8) - y1;
22-		for(ay = y1 * len, by = ay + ver * len; ay < by; ay += len) {
23+		for(ay = y1 * screen_wmar2, by = ay + ver * screen_wmar2; ay < by; ay += screen_wmar2) {
24 			Uint8 *dst = &screen_layers[ay + x1];
25 			for(px = 0; px < hor; px++)
26 				dst[px] = (dst[px] & layer_mask) | color;
27@@ -560,7 +559,7 @@ screen_draw_pixel(void)
28 	else {
29 		const unsigned int x = rX, y = rY;
30 		if(x < screen_width && y < screen_height) {
31-			Uint8 *dst = &screen_layers[(x + 8) + (y + 8) * len];
32+			Uint8 *dst = &screen_layers[(x + 8) + (y + 8) * screen_wmar2];
33 			*dst = (*dst & layer_mask) | color;
34 		}
35 		screen_reqdraw = 1;
36@@ -1227,7 +1226,7 @@ emu_init(void)
37 static void
38 emu_run(void)
39 {
40-	int has_input, has_eof;
41+	int has_input, has_eof, has_sent = 1;
42 	char expirations[8], coninp[CONINBUFSIZE];
43 	static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
44 	struct pollfd fds[3];
45@@ -1252,9 +1251,9 @@ emu_run(void)
46 		if(has_input || has_eof) {
47 			int i = 1, n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);
48 			for(i = 0, coninp[n] = 0; i < n; i++)
49-				console_input(coninp[i], CONSOLE_STD);
50-			if(n == 0)
51-				console_input(0, CONSOLE_END);
52+				console_input(coninp[i], CONSOLE_STD), has_sent = 1;
53+			if(n == 0 && has_sent)
54+				console_input(0, CONSOLE_END), has_sent = 0;
55 		}
56 	}
57 	if(ximage)
58@@ -1269,7 +1268,7 @@ main(int argc, char **argv)
59 {
60 	int i = 1;
61 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
62-		return !fprintf(stdout, "%s - Varvara Emulator, 2 Jan 2026.\n", argv[0]);
63+		return !fprintf(stdout, "%s - Varvara Emulator, 3 Jan 2026.\n", argv[0]);
64 	else if(argc == 1)
65 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
66 	else if(!system_boot(argv[i++], argc > 2))