commit cbdfc73

Devine Lu Linvega  ·  2026-01-07 17:55:20 +0000 UTC
parent 9f3c70e
Save time on cold ports
1 files changed,  +59, -26
+59, -26
  1@@ -989,35 +989,67 @@ datetime_update(void)
  2 
  3 #define CONINBUFSIZE 256
  4 
  5+typedef Uint8 (*dei_handler)(void);
  6+
  7+/* clang-format off */
  8+
  9+Uint8 system_dei_wst(void) { return ptr[0]; }
 10+Uint8 system_dei_rst(void) { return ptr[1]; }
 11+Uint8 console_dei_childlive(void) { check_child(); return dev[CMD_LIVE]; }
 12+Uint8 console_dei_childexit(void) { check_child(); return dev[CMD_EXIT]; }
 13+Uint8 screen_dei_rxhb(void) { return rX >> 8; }
 14+Uint8 screen_dei_rxlb(void) { return rX; }
 15+Uint8 screen_dei_ryhb(void) { return rY >> 8; }
 16+Uint8 screen_dei_rylb(void) { return rY; }
 17+Uint8 screen_dei_rahb(void) { return rA >> 8; }
 18+Uint8 screen_dei_ralb(void) { return rA; }
 19+Uint8 datetime_dei_yhb(void) { datetime_update(); return (datetime_t->tm_year + 1900) >> 8; }
 20+Uint8 datetime_dei_ylb(void) { datetime_update(); return (datetime_t->tm_year + 1900); }
 21+Uint8 datetime_dei_mon(void) { datetime_update(); return datetime_t->tm_mon; }
 22+Uint8 datetime_dei_day(void) { datetime_update(); return datetime_t->tm_mday; }
 23+Uint8 datetime_dei_hou(void) { datetime_update(); return datetime_t->tm_hour; }
 24+Uint8 datetime_dei_min(void) { datetime_update(); return datetime_t->tm_min; }
 25+Uint8 datetime_dei_sec(void) { datetime_update(); return datetime_t->tm_sec; }
 26+Uint8 datetime_dei_wday(void) { datetime_update(); return datetime_t->tm_wday; }
 27+Uint8 datetime_dei_ydayhb(void) { datetime_update(); return datetime_t->tm_yday >> 8; }
 28+Uint8 datetime_dei_ydaylb(void) { datetime_update(); return datetime_t->tm_yday; }
 29+Uint8 datetime_dei_dst(void) { datetime_update(); return datetime_t->tm_isdst; }
 30+
 31+static dei_handler dei_handlers[256];
 32+
 33+/* clang-format on */
 34+
 35+void
 36+init_devices(void)
 37+{
 38+	dei_handlers[0x04] = system_dei_wst;
 39+	dei_handlers[0x05] = system_dei_rst;
 40+	dei_handlers[0x15] = console_dei_childlive;
 41+	dei_handlers[0x16] = console_dei_childexit;
 42+	dei_handlers[0x28] = screen_dei_rxhb;
 43+	dei_handlers[0x29] = screen_dei_rxlb;
 44+	dei_handlers[0x2a] = screen_dei_ryhb;
 45+	dei_handlers[0x2b] = screen_dei_rylb;
 46+	dei_handlers[0x2c] = screen_dei_rahb;
 47+	dei_handlers[0x2d] = screen_dei_ralb;
 48+	dei_handlers[0xc0] = datetime_dei_yhb;
 49+	dei_handlers[0xc1] = datetime_dei_ylb;
 50+	dei_handlers[0xc2] = datetime_dei_mon;
 51+	dei_handlers[0xc3] = datetime_dei_day;
 52+	dei_handlers[0xc4] = datetime_dei_hou;
 53+	dei_handlers[0xc5] = datetime_dei_min;
 54+	dei_handlers[0xc6] = datetime_dei_sec;
 55+	dei_handlers[0xc7] = datetime_dei_wday;
 56+	dei_handlers[0xc8] = datetime_dei_ydayhb;
 57+	dei_handlers[0xc9] = datetime_dei_ydaylb;
 58+	dei_handlers[0xca] = datetime_dei_dst;
 59+}
 60+
 61 Uint8
 62 emu_dei(const Uint8 port)
 63 {
 64-	switch(port) {
 65-	/* System */
 66-	case 0x04: return ptr[0];
 67-	case 0x05: return ptr[1];
 68-	/* Console */
 69-	case CMD_LIVE:
 70-	case CMD_EXIT: check_child(); break;
 71-	/* Screen */
 72-	case 0x28: return rX >> 8;
 73-	case 0x29: return rX;
 74-	case 0x2a: return rY >> 8;
 75-	case 0x2b: return rY;
 76-	case 0x2c: return rA >> 8;
 77-	case 0x2d: return rA;
 78-	case 0xc0: datetime_update(); return (datetime_t->tm_year + 1900) >> 8;
 79-	case 0xc1: datetime_update(); return (datetime_t->tm_year + 1900);
 80-	case 0xc2: datetime_update(); return datetime_t->tm_mon;
 81-	case 0xc3: datetime_update(); return datetime_t->tm_mday;
 82-	case 0xc4: datetime_update(); return datetime_t->tm_hour;
 83-	case 0xc5: datetime_update(); return datetime_t->tm_min;
 84-	case 0xc6: datetime_update(); return datetime_t->tm_sec;
 85-	case 0xc7: datetime_update(); return datetime_t->tm_wday;
 86-	case 0xc8: datetime_update(); return datetime_t->tm_yday >> 8;
 87-	case 0xc9: datetime_update(); return datetime_t->tm_yday;
 88-	case 0xca: datetime_update(); return datetime_t->tm_isdst;
 89-	}
 90+	if(dei_handlers[port])
 91+		return dei_handlers[port]();
 92 	return dev[port];
 93 }
 94 
 95@@ -1266,6 +1298,7 @@ int
 96 main(int argc, char **argv)
 97 {
 98 	int i = 1;
 99+	init_devices();
100 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
101 		return !fprintf(stdout, "%s - Varvara Emulator, 7 Jan 2026.\n", argv[0]);
102 	else if(argc == 1)