diff --git a/frontend/drivers/platform_bsd.c b/frontend/drivers/platform_bsd.c index 8c663c6d25..5653659327 100644 --- a/frontend/drivers/platform_bsd.c +++ b/frontend/drivers/platform_bsd.c @@ -80,5 +80,7 @@ frontend_ctx_driver_t frontend_ctx_bsd = { frontend_bsd_get_signal_handler_state, frontend_bsd_set_signal_handler_state, frontend_bsd_destroy_signal_handler_state, + NULL, /* attach_console */ + NULL, /* detach_console */ "bsd", }; diff --git a/frontend/drivers/platform_ctr.c b/frontend/drivers/platform_ctr.c index 4c9e8f333b..ed2cbbbcbb 100644 --- a/frontend/drivers/platform_ctr.c +++ b/frontend/drivers/platform_ctr.c @@ -422,5 +422,7 @@ frontend_ctx_driver_t frontend_ctx_ctr = { NULL, /* get_signal_handler_state */ NULL, /* set_signal_handler_state */ NULL, /* destroy_signal_handler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "ctr", }; diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index 1a9a38b1f9..07b113b557 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -714,5 +714,7 @@ frontend_ctx_driver_t frontend_ctx_darwin = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_signal_handler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "darwin", }; diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c index cfad3f4497..51a4a31a0c 100644 --- a/frontend/drivers/platform_emscripten.c +++ b/frontend/drivers/platform_emscripten.c @@ -206,5 +206,7 @@ frontend_ctx_driver_t frontend_ctx_emscripten = { NULL, /* get_signal_handler_state */ NULL, /* set_signal_handler_state */ NULL, /* destroy_signal_handler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "emscripten" }; diff --git a/frontend/drivers/platform_gx.c b/frontend/drivers/platform_gx.c index 10cd30dd26..a6f6edd8e0 100644 --- a/frontend/drivers/platform_gx.c +++ b/frontend/drivers/platform_gx.c @@ -536,5 +536,7 @@ frontend_ctx_driver_t frontend_ctx_gx = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_signal_handler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "gx", }; diff --git a/frontend/drivers/platform_linux.c b/frontend/drivers/platform_linux.c index 998c9b48d5..e4534614b2 100644 --- a/frontend/drivers/platform_linux.c +++ b/frontend/drivers/platform_linux.c @@ -2089,6 +2089,8 @@ frontend_ctx_driver_t frontend_ctx_linux = { frontend_linux_get_signal_handler_state, frontend_linux_set_signal_handler_state, frontend_linux_destroy_signal_handler_state, + NULL, /* attach_console */ + NULL, /* detach_console */ #ifdef ANDROID "android" #else diff --git a/frontend/drivers/platform_null.c b/frontend/drivers/platform_null.c index 4dc3800c23..9f1b4b8730 100644 --- a/frontend/drivers/platform_null.c +++ b/frontend/drivers/platform_null.c @@ -40,5 +40,7 @@ frontend_ctx_driver_t frontend_ctx_null = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_sighandler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "null", }; diff --git a/frontend/drivers/platform_ps3.c b/frontend/drivers/platform_ps3.c index 2ba7f95aa4..e735f16a41 100644 --- a/frontend/drivers/platform_ps3.c +++ b/frontend/drivers/platform_ps3.c @@ -568,5 +568,7 @@ frontend_ctx_driver_t frontend_ctx_ps3 = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_sighandler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "ps3", }; diff --git a/frontend/drivers/platform_psp.c b/frontend/drivers/platform_psp.c index 14c42d2d1c..00b258b4ba 100644 --- a/frontend/drivers/platform_psp.c +++ b/frontend/drivers/platform_psp.c @@ -506,6 +506,8 @@ frontend_ctx_driver_t frontend_ctx_psp = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_sighandler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ #ifdef VITA "vita", #else diff --git a/frontend/drivers/platform_qnx.c b/frontend/drivers/platform_qnx.c index 7f886ebf01..2f04242894 100644 --- a/frontend/drivers/platform_qnx.c +++ b/frontend/drivers/platform_qnx.c @@ -90,5 +90,7 @@ frontend_ctx_driver_t frontend_ctx_qnx = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_sighandler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "qnx", }; diff --git a/frontend/drivers/platform_win32.c b/frontend/drivers/platform_win32.c index a70c032993..9ed921f0b0 100644 --- a/frontend/drivers/platform_win32.c +++ b/frontend/drivers/platform_win32.c @@ -320,6 +320,25 @@ static uint64_t frontend_win32_get_mem_used(void) return ((frontend_win32_get_mem_total() - mem_info.ullAvailPhys)); } +static void frontend_win32_attach_console(void) +{ +#ifdef _WIN32 + AllocConsole(); + AttachConsole( GetCurrentProcessId()) ; + freopen( "CON", "w", stdout ); + freopen( "CON", "w", stderr ); +#endif +} + +static void frontend_win32_detach_console(void) +{ +#if defined(_WIN32) && !defined(_XBOX) + HWND wnd = GetConsoleWindow(); + FreeConsole(); + PostMessage(wnd, WM_CLOSE, 0, 0); +#endif +} + frontend_ctx_driver_t frontend_ctx_win32 = { frontend_win32_environment_get, frontend_win32_init, @@ -342,5 +361,7 @@ frontend_ctx_driver_t frontend_ctx_win32 = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_sighandler_state */ + frontend_win32_attach_console, /* attach_console */ + frontend_win32_detach_console, /* detach_console */ "win32" }; diff --git a/frontend/drivers/platform_xdk.cpp b/frontend/drivers/platform_xdk.cpp index 3ffbd42302..77d00abc82 100644 --- a/frontend/drivers/platform_xdk.cpp +++ b/frontend/drivers/platform_xdk.cpp @@ -1413,5 +1413,7 @@ frontend_ctx_driver_t frontend_ctx_xdk = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_sighandler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "xdk", }; diff --git a/frontend/drivers/platform_xenon.c b/frontend/drivers/platform_xenon.c index c1a588af77..795c47f9d1 100644 --- a/frontend/drivers/platform_xenon.c +++ b/frontend/drivers/platform_xenon.c @@ -89,5 +89,7 @@ frontend_ctx_driver_t frontend_ctx_qnx = { NULL, /* get_sighandler_state */ NULL, /* set_sighandler_state */ NULL, /* destroy_sighandler_state */ + NULL, /* attach_console */ + NULL, /* detach_console */ "xenon", }; diff --git a/frontend/frontend_driver.c b/frontend/frontend_driver.c index 52143a664e..7a922bc394 100644 --- a/frontend/frontend_driver.c +++ b/frontend/frontend_driver.c @@ -361,6 +361,22 @@ void frontend_driver_set_signal_handler_state(int value) frontend->set_signal_handler_state(value); } +void frontend_driver_attach_console(void) +{ + frontend_ctx_driver_t *frontend = frontend_get_ptr(); + if (!frontend || !frontend->attach_console) + return; + frontend->attach_console(); +} + +void frontend_driver_detach_console(void) +{ + frontend_ctx_driver_t *frontend = frontend_get_ptr(); + if (!frontend || !frontend->detach_console) + return; + frontend->detach_console(); +} + void frontend_driver_destroy_signal_handler_state(void) { frontend_ctx_driver_t *frontend = frontend_get_ptr(); diff --git a/frontend/frontend_driver.h b/frontend/frontend_driver.h index b20751aee0..04e3d079d3 100644 --- a/frontend/frontend_driver.h +++ b/frontend/frontend_driver.h @@ -82,6 +82,8 @@ typedef struct frontend_ctx_driver int (*get_signal_handler_state)(void); void (*set_signal_handler_state)(int value); void (*destroy_signal_handler_state)(void); + void (*attach_console)(void); + void (*detach_console)(void); const char *ident; @@ -169,6 +171,10 @@ void frontend_driver_set_signal_handler_state(int value); void frontend_driver_destroy_signal_handler_state(void); +void frontend_driver_attach_console(void); + +void frontend_driver_detach_console(void); + RETRO_END_DECLS #endif diff --git a/retroarch.c b/retroarch.c index 8ca41aebc2..f544a67ff2 100644 --- a/retroarch.c +++ b/retroarch.c @@ -766,9 +766,7 @@ static void retroarch_parse_input(int argc, char *argv[]) break; case 'D': -#if defined(_WIN32) && !defined(_XBOX) - FreeConsole(); -#endif + frontend_driver_detach_console(); break; case RA_OPT_MENU: diff --git a/verbosity.c b/verbosity.c index 8dc0df8bd6..c9fa5728ca 100644 --- a/verbosity.c +++ b/verbosity.c @@ -43,6 +43,10 @@ #include "config.h" #endif +#ifdef RARCH_INTERNAL +#include "frontend/frontend_driver.h" +#endif + #include "file_path_special.h" #include "verbosity.h" @@ -54,21 +58,16 @@ static bool main_verbosity = false; void verbosity_enable(void) { main_verbosity = true; -#ifdef _WIN32 - AllocConsole(); - AttachConsole( GetCurrentProcessId()) ; - freopen( "CON", "w", stdout ); - freopen( "CON", "w", stderr ); +#ifdef RARCH_INTERNAL + frontend_driver_attach_console(); #endif } void verbosity_disable(void) { main_verbosity = false; -#ifdef _WIN32 - HWND wnd = GetConsoleWindow(); - FreeConsole(); - PostMessage(wnd, WM_CLOSE, 0, 0); +#ifdef RARCH_INTERNAL + frontend_driver_detach_console(); #endif }