Show Windows console when isviewer is present.

This commit is contained in:
Giovanni Bajo 2021-09-05 20:49:46 +00:00 committed by Simon Eriksson
parent 95f8dd1f02
commit 87ed667c38
5 changed files with 54 additions and 17 deletions

View file

@ -307,6 +307,7 @@ set(OS_POSIX_SOURCES
set(OS_WINAPI_SOURCES
${PROJECT_SOURCE_DIR}/os/winapi/alloc.c
${PROJECT_SOURCE_DIR}/os/winapi/console.c
${PROJECT_SOURCE_DIR}/os/winapi/cpuid.c
${PROJECT_SOURCE_DIR}/os/winapi/gl_config.c
${PROJECT_SOURCE_DIR}/os/winapi/gl_window.c

View file

@ -21,6 +21,9 @@
#include "os/common/rom_file.h"
#include "os/common/save_file.h"
#include "os/cpuid.h"
#ifdef _WIN32
#include "os/winapi/console.h"
#endif
#include "pi/is_viewer.h"
#include "thread.h"
#include <stdlib.h>
@ -177,6 +180,9 @@ int cen64_main(int argc, const char **argv) {
return EXIT_FAILURE;
} else {
is_in = &is;
#ifdef _WIN32
show_console();
#endif
}
}

31
os/winapi/console.c Normal file
View file

@ -0,0 +1,31 @@
//
// os/winapi/console.c
//
// Functions for manipulating the console.
//
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
// Copyright (C) 2015, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//
#include "cen64.h"
#include <windows.h>
// "Hides" the console window (after waiting for input).
void hide_console(void) {
printf("\n");
system("PAUSE");
FreeConsole();
}
// "Unhides" the console window.
void show_console(void) {
if (AttachConsole(ATTACH_PARENT_PROCESS) == 0)
AllocConsole();
freopen("CONOUT$", "wb", stdout);
freopen("CONOUT$", "wb", stderr);
}

16
os/winapi/console.h Normal file
View file

@ -0,0 +1,16 @@
//
// os/winapi/console.h: Console manipulation functions
//
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
// Copyright (C) 2015, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//
#ifndef CEN64_OS_WINAPI_CONSOLE
#define CEN64_OS_WINAPI_CONSOLE
void show_console(void);
void hide_console(void);
#endif

View file

@ -30,20 +30,3 @@ int WINAPI WinMain(HINSTANCE hInstance,
return status;
}
// "Hides" the console window (after waiting for input).
void hide_console(void) {
printf("\n");
system("PAUSE");
FreeConsole();
}
// "Unhides" the console window.
void show_console(void) {
AllocConsole();
freopen("CONOUT$", "wb", stdout);
freopen("CONOUT$", "wb", stderr);
}