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".
This commit is contained in:
parent
d1309e73ac
commit
25b53c7fa3
|
@ -46,10 +46,15 @@ void OpenConsole()
|
||||||
//is FILE_TYPE_PIPE (3) for pipe
|
//is FILE_TYPE_PIPE (3) for pipe
|
||||||
//i think it is FILE_TYPE_CHAR (2) for console
|
//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
|
//stdout is already connected to something. keep using it and dont let the console interfere
|
||||||
bool shouldRedirectStdout = fileType == FILE_TYPE_UNKNOWN;
|
bool shouldRedirectStdout = fileType == FILE_TYPE_UNKNOWN;
|
||||||
|
|
||||||
|
|
||||||
//attach to an existing console (if we can; this is circuitous because AttachConsole wasnt added until XP)
|
//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
|
//remember to abstract this late bound function notion if we end up having to do this anywhere else
|
||||||
bool attached = false;
|
bool attached = false;
|
||||||
|
@ -78,6 +83,7 @@ void OpenConsole()
|
||||||
{
|
{
|
||||||
freopen("CONOUT$", "w", stdout);
|
freopen("CONOUT$", "w", stdout);
|
||||||
freopen("CONOUT$", "w", stderr);
|
freopen("CONOUT$", "w", stderr);
|
||||||
|
freopen("CONIN$", "r", stdin);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf,"%s OUTPUT", EMU_DESMUME_NAME_AND_VERSION());
|
sprintf(buf,"%s OUTPUT", EMU_DESMUME_NAME_AND_VERSION());
|
||||||
|
@ -92,9 +98,11 @@ void OpenConsole()
|
||||||
SetConsoleWindowInfo(hConsole, TRUE, &srect);
|
SetConsoleWindowInfo(hConsole, TRUE, &srect);
|
||||||
SetConsoleCP(GetACP());
|
SetConsoleCP(GetACP());
|
||||||
SetConsoleOutputCP(GetACP());
|
SetConsoleOutputCP(GetACP());
|
||||||
if(attached) printlog("\n");
|
//if(attached) printlog("\n");
|
||||||
printlog("%s\n",EMU_DESMUME_NAME_AND_VERSION());
|
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() {
|
void CloseConsole() {
|
||||||
|
|
|
@ -3102,19 +3102,35 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
|
||||||
|
|
||||||
GetINIPath();
|
GetINIPath();
|
||||||
|
|
||||||
#if !defined(PUBLIC_RELEASE) || defined(DEVELOPER)
|
#if !defined(PUBLIC_RELEASE) || defined(DEVELOPER)
|
||||||
static const bool defaultConsoleEnable = true;
|
static const bool defaultConsoleEnable = true;
|
||||||
#else
|
#else
|
||||||
static const bool defaultConsoleEnable = false;
|
static const bool defaultConsoleEnable = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(GetPrivateProfileBool("Display", "Show Console", defaultConsoleEnable, IniName))
|
if(GetPrivateProfileBool("Display", "Show Console", defaultConsoleEnable, IniName))
|
||||||
OpenConsole(); // Init debug console
|
OpenConsole(); // Init debug console
|
||||||
|
|
||||||
|
//--------------------------------
|
||||||
int ret = _main();
|
int ret = _main();
|
||||||
|
//--------------------------------
|
||||||
|
|
||||||
|
printf("returning from main\n");
|
||||||
|
|
||||||
timeEndPeriod (wmTimerRes);
|
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();
|
CloseConsole();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue