From 25b53c7fa3307c559fd374e224c9906047d18ac1 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 23 Jul 2011 08:21:21 +0000 Subject: [PATCH] win32: some minor clarifications to console behaviour. console behaviour is now verified to be pretty dang good in cygwin/msys bash as well as cmd.exe so long as you launch with "cmd /c desmume.exe". --- desmume/src/windows/console.cpp | 14 +++++++++++--- desmume/src/windows/main.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/desmume/src/windows/console.cpp b/desmume/src/windows/console.cpp index 90201c4be..e8e9774b9 100644 --- a/desmume/src/windows/console.cpp +++ b/desmume/src/windows/console.cpp @@ -46,10 +46,15 @@ void OpenConsole() //is FILE_TYPE_PIPE (3) for pipe //i think it is FILE_TYPE_CHAR (2) for console + //SOMETHING LIKE THIS MIGHT BE NEEDED ONE DAY + //disable stdout buffering unless we know for sure we've been redirected to the disk + //the runtime will be smart and set buffering when we may have in fact chosen to pipe the output to a console and dont want it buffered + //if(GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) != FILE_TYPE_DISK) + // setvbuf(stdout,NULL,_IONBF,0); + //stdout is already connected to something. keep using it and dont let the console interfere bool shouldRedirectStdout = fileType == FILE_TYPE_UNKNOWN; - //attach to an existing console (if we can; this is circuitous because AttachConsole wasnt added until XP) //remember to abstract this late bound function notion if we end up having to do this anywhere else bool attached = false; @@ -78,6 +83,7 @@ void OpenConsole() { freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); + freopen("CONIN$", "r", stdin); } sprintf(buf,"%s OUTPUT", EMU_DESMUME_NAME_AND_VERSION()); @@ -92,9 +98,11 @@ void OpenConsole() SetConsoleWindowInfo(hConsole, TRUE, &srect); SetConsoleCP(GetACP()); SetConsoleOutputCP(GetACP()); - if(attached) printlog("\n"); + //if(attached) printlog("\n"); printlog("%s\n",EMU_DESMUME_NAME_AND_VERSION()); - printlog("- compiled: %s %s\n\n",__DATE__,__TIME__); + printlog("- compiled: %s %s\n",__DATE__,__TIME__); + if(attached) printf("\nuse cmd /c desmume.exe to get more sensible console behaviour\n"); + printlog("\n"); } void CloseConsole() { diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index d037fd958..cd4c4c8e6 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -3102,19 +3102,35 @@ int WINAPI WinMain (HINSTANCE hThisInstance, GetINIPath(); - #if !defined(PUBLIC_RELEASE) || defined(DEVELOPER) - static const bool defaultConsoleEnable = true; - #else - static const bool defaultConsoleEnable = false; - #endif - - if(GetPrivateProfileBool("Display", "Show Console", defaultConsoleEnable, IniName)) - OpenConsole(); // Init debug console + #if !defined(PUBLIC_RELEASE) || defined(DEVELOPER) + static const bool defaultConsoleEnable = true; + #else + static const bool defaultConsoleEnable = false; + #endif + if(GetPrivateProfileBool("Display", "Show Console", defaultConsoleEnable, IniName)) + OpenConsole(); // Init debug console + + //-------------------------------- int ret = _main(); + //-------------------------------- + + printf("returning from main\n"); timeEndPeriod (wmTimerRes); + //dump any console input to keep the shell from processing it after desmume exits. + //(we would be unique in doing this, as every other program has this "problem", but I am saving the code for future reference) + //for(;;) + //{ + // INPUT_RECORD ir; + // DWORD nEventsRead; + // BOOL ret = PeekConsoleInput(GetStdHandle(STD_INPUT_HANDLE),&ir,1,&nEventsRead); + // printf("%d %d %d\n",ir.Event.KeyEvent.uChar,nEventsRead,ret); + // if(nEventsRead==0) break; + // ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE),&ir,1,&nEventsRead); + //} + CloseConsole(); return ret;