diff --git a/platform/Windows/src.Windows/arch/archdep.c b/platform/Windows/src.Windows/arch/archdep.c index 0c338915..8458b452 100644 --- a/platform/Windows/src.Windows/arch/archdep.c +++ b/platform/Windows/src.Windows/arch/archdep.c @@ -113,12 +113,30 @@ void archdep_network_shutdown(void) WSACleanup(); } -int archdep_init(int *argc, char **argv) +static BOOL CALLBACK archdep_init_stdio_once(PINIT_ONCE once, PVOID parameter, PVOID *context) { - _fmode = O_BINARY; + (void)once; + (void)parameter; + (void)context; _setmode(_fileno(stdin), O_BINARY); _setmode(_fileno(stdout), O_BINARY); + return TRUE; +} + +void archdep_init_stdio(void) +{ + static INIT_ONCE once = INIT_ONCE_STATIC_INIT; + + /* Repeating _setmode can block behind an active MCP stdin read. */ + InitOnceExecuteOnce(&once, archdep_init_stdio_once, NULL, NULL); +} + +int archdep_init(int *argc, char **argv) +{ + _fmode = O_BINARY; + + archdep_init_stdio(); argv0 = lib_stralloc(argv[0]); diff --git a/platform/Windows/src.Windows/arch/archdep.h b/platform/Windows/src.Windows/arch/archdep.h index f1b1ecd1..356fd9e2 100644 --- a/platform/Windows/src.Windows/arch/archdep.h +++ b/platform/Windows/src.Windows/arch/archdep.h @@ -123,6 +123,7 @@ extern void archdep_workaround_nop(const char *otto); #define ARCHDEP_SOUND_OUTPUT_MODE SOUND_OUTPUT_SYSTEM +void archdep_init_stdio(void); const char *archdep_home_path(void); #endif diff --git a/src/RetroDebuggerAppInit.cpp b/src/RetroDebuggerAppInit.cpp index 1e94d1a6..228f3d71 100644 --- a/src/RetroDebuggerAppInit.cpp +++ b/src/RetroDebuggerAppInit.cpp @@ -24,6 +24,10 @@ extern "C" void RD_HideDockIcon(); #endif +#ifdef WIN32 +extern "C" void archdep_init_stdio(void); +#endif + #if MT_ENABLE_IMGUI_TEST_ENGINE #include "CImGuiTestEngine.h" #include "imgui_te_engine.h" @@ -226,6 +230,11 @@ bool C64D_IsAutomatedRunCommandLine() void MT_PreInit() { +#ifdef WIN32 + // Configure stdio before MCP can block reading stdin; VICE reuses this setup. + archdep_init_stdio(); +#endif + if (C64D_IsAutomatedRunCommandLine()) // SDL3: SDL_setenv is gone. SDL_setenv_unsafe is the direct // replacement and keeps the overwrite=0 semantics we rely on.