From 87ed667c389fb1a2738a7c760461b843f5523bfa Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Sun, 5 Sep 2021 20:49:46 +0000 Subject: [PATCH] Show Windows console when isviewer is present. --- CMakeLists.txt | 1 + cen64.c | 6 ++++++ os/winapi/console.c | 31 +++++++++++++++++++++++++++++++ os/winapi/console.h | 16 ++++++++++++++++ os/winapi/main.c | 17 ----------------- 5 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 os/winapi/console.c create mode 100644 os/winapi/console.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e942856..04f5caa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cen64.c b/cen64.c index 0aa7ec3..a9784a1 100644 --- a/cen64.c +++ b/cen64.c @@ -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 @@ -177,6 +180,9 @@ int cen64_main(int argc, const char **argv) { return EXIT_FAILURE; } else { is_in = &is; + #ifdef _WIN32 + show_console(); + #endif } } diff --git a/os/winapi/console.c b/os/winapi/console.c new file mode 100644 index 0000000..d7fa170 --- /dev/null +++ b/os/winapi/console.c @@ -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 + +// "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); +} diff --git a/os/winapi/console.h b/os/winapi/console.h new file mode 100644 index 0000000..548bbd7 --- /dev/null +++ b/os/winapi/console.h @@ -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 diff --git a/os/winapi/main.c b/os/winapi/main.c index 6b79c82..2d4e8d1 100644 --- a/os/winapi/main.c +++ b/os/winapi/main.c @@ -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); -} -