From 66f92ad1822474f928f4c78e49b520fa18bf53a5 Mon Sep 17 00:00:00 2001 From: nhmall Date: Mon, 25 Mar 2024 22:30:08 -0400 Subject: [PATCH] startup sequence and iflags values early_init() calls decl_globals_init() which zeros out a number structures: ZERO(flags); ZERO(iflags); ZERO(a11y); ZERO(disp); ZERO(u); ZERO(ubirthday); ZERO(urealtime); Setting values in any of those during startup prior to the early_init() call was futile, and the values would get overwritten. Such was the case with the setting of iflags.colorcount during Windows startup, so do it after early_init() has been called. --- sys/windows/consoletty.c | 9 --------- sys/windows/windmain.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sys/windows/consoletty.c b/sys/windows/consoletty.c index 749d24ca7..9a8c390a6 100644 --- a/sys/windows/consoletty.c +++ b/sys/windows/consoletty.c @@ -997,10 +997,6 @@ tty_startup(int *wid, int *hgt) *wid = console.width; *hgt = console.height; set_option_mod_status("mouse_support", set_in_game); - if (iflags.colorcount == 0) { - iflags.colorcount = 16777216; - // iflags.colorcount = 256; - } } void @@ -2406,11 +2402,6 @@ void nethack_enter_consoletty(void) #ifdef VIRTUAL_TERMINAL_SEQUENCES char buf[BUFSZ], *bp, *localestr; BOOL success; - - if (iflags.colorcount == 0) { - iflags.colorcount = 16777216; - // iflags.colorcount = 256; - } #endif /* VIRTUAL_TERMINAL_SEQUENCES */ #if 0 /* set up state needed by early_raw_print() */ diff --git a/sys/windows/windmain.c b/sys/windows/windmain.c index 62073a12b..dfd5fc846 100644 --- a/sys/windows/windmain.c +++ b/sys/windows/windmain.c @@ -499,6 +499,9 @@ MAIN(int argc, char *argv[]) char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ]; char failbuf[BUFSZ]; int getlock_result = 0; + HWND hwnd; + HDC hdc; + int bpp; #ifdef _MSC_VER _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); @@ -513,6 +516,16 @@ MAIN(int argc, char *argv[]) #endif /* WIN32CON */ early_init(argc, argv); + /* setting iflags.colorcount has to be after early_init() + * because it zeros out all of iflags */ + hwnd = GetDesktopWindow(); + hdc = GetDC(hwnd); + if (hdc) { + bpp = GetDeviceCaps(hdc, BITSPIXEL); + iflags.colorcount = (bpp >= 16) ? 16777216 : (bpp >= 8) ? 256 : 16; + ReleaseDC(hwnd, hdc); + } + #ifdef _MSC_VER #ifdef DEBUG /* set these appropriately for VS debugging */