diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index 456f150e0..26f19aaf1 100644 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -24,50 +24,10 @@ #include "sdl/sdl.h" #endif -#if defined(USE_EVDEV) - #include "evdev.h" -#endif - #ifdef USE_BREAKPAD #include "breakpad/client/linux/handler/exception_handler.h" #endif -void os_SetupInput() -{ -#if defined(USE_EVDEV) - input_evdev_init(); -#endif - -#if defined(SUPPORT_X11) - input_x11_init(); -#endif - -#if defined(USE_SDL) - input_sdl_init(); -#endif -} - -void os_TermInput() -{ -#if defined(USE_EVDEV) - input_evdev_close(); -#endif -#if defined(USE_SDL) - input_sdl_quit(); -#endif -} - -void UpdateInputState() -{ - #if defined(USE_EVDEV) - input_evdev_handle(); - #endif - - #if defined(USE_SDL) - input_sdl_handle(); - #endif -} - void os_DoEvents() { #if defined(SUPPORT_X11) @@ -76,31 +36,11 @@ void os_DoEvents() #endif } -void os_SetWindowText(const char * text) -{ - #if defined(SUPPORT_X11) - x11_window_set_text(text); - #endif - #if defined(USE_SDL) - sdl_window_set_text(text); - #endif -} - -void os_CreateWindow() -{ - #if defined(SUPPORT_X11) - x11_window_create(); - #endif - #if defined(USE_SDL) - sdl_window_create(); - #endif -} - void common_linux_setup(); // Find the user config directory. // $HOME/.config/flycast on linux -std::string find_user_config_dir() +static std::string find_user_config_dir() { std::string xdg_home; if (nowide::getenv("XDG_CONFIG_HOME") != nullptr) @@ -129,7 +69,7 @@ std::string find_user_config_dir() // Find the user data directory. // $HOME/.local/share/flycast on linux -std::string find_user_data_dir() +static std::string find_user_data_dir() { std::string xdg_home; if (nowide::getenv("XDG_DATA_HOME") != nullptr) @@ -181,7 +121,7 @@ static void addDirectoriesFromPath(std::vector& dirs, const std::st // /etc/flycast/ // /etc/xdg/flycast/ // . -std::vector find_system_config_dirs() +static std::vector find_system_config_dirs() { std::vector dirs; @@ -225,7 +165,7 @@ std::vector find_system_config_dirs() // <$FLYCAST_BIOS_PATH> // ./ // ./data -std::vector find_system_data_dirs() +static std::vector find_system_data_dirs() { std::vector dirs; @@ -328,13 +268,6 @@ int main(int argc, char* argv[]) mainui_loop(); -#if defined(SUPPORT_X11) - x11_window_destroy(); -#endif -#if defined(USE_SDL) - sdl_window_destroy(); -#endif - flycast_term(); os_UninstallFaultHandler(); diff --git a/core/linux-dist/x11.cpp b/core/linux-dist/x11.cpp index f80c1febb..a11d20a54 100644 --- a/core/linux-dist/x11.cpp +++ b/core/linux-dist/x11.cpp @@ -21,6 +21,8 @@ #define DEFAULT_WINDOW_WIDTH 640 #define DEFAULT_WINDOW_HEIGHT 480 +static void x11_window_set_text(const char *text); + static Window x11_win; Display *x11_disp; @@ -356,7 +358,7 @@ void x11_window_create() } } -void x11_window_set_text(const char* text) +static void x11_window_set_text(const char* text) { if (x11_win) { diff --git a/core/linux-dist/x11.h b/core/linux-dist/x11.h index 75c176531..7013db703 100644 --- a/core/linux-dist/x11.h +++ b/core/linux-dist/x11.h @@ -1,11 +1,10 @@ #pragma once -extern void input_x11_init(); -extern void event_x11_handle(); -extern void input_x11_handle(); -extern void x11_window_create(); -extern void x11_window_set_text(const char* text); -extern void x11_window_destroy(); +void input_x11_init(); +void event_x11_handle(); +void input_x11_handle(); +void x11_window_create(); +void x11_window_destroy(); // numbers const int KEY_1 = 10; diff --git a/core/linux/common.cpp b/core/linux/common.cpp index 00453b762..0ca150af0 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -162,7 +162,7 @@ static void linux_fix_personality() #endif } -#if defined(__unix__) && !defined(LIBRETRO) +#if defined(__unix__) && !defined(LIBRETRO) && !defined(__ANDROID__) static void sigintHandler(int) { dc_exit(); @@ -175,7 +175,7 @@ void common_linux_setup() enable_runfast(); os_InstallFaultHandler(); -#if defined(__unix__) && !defined(LIBRETRO) +#if defined(__unix__) && !defined(LIBRETRO) && !defined(__ANDROID__) // exit cleanly on ^C signal(SIGINT, sigintHandler); #endif diff --git a/core/network/ggpo.cpp b/core/network/ggpo.cpp index 40777bb22..dbcb325a2 100644 --- a/core/network/ggpo.cpp +++ b/core/network/ggpo.cpp @@ -23,10 +23,9 @@ #include "input/keyboard_device.h" #include "input/mouse.h" #include "cfg/option.h" +#include "oslib/oslib.h" #include -void UpdateInputState(); - namespace ggpo { @@ -35,7 +34,7 @@ bool inRollback; static void getLocalInput(MapleInputState inputState[4]) { if (!config::ThreadedRendering) - UpdateInputState(); + os_UpdateInputState(); std::lock_guard lock(relPosMutex); for (int player = 0; player < 4; player++) { @@ -706,7 +705,7 @@ bool nextFrame() // may call save_game_state do { if (!config::ThreadedRendering) - UpdateInputState(); + os_UpdateInputState(); Inputs inputs; inputs.kcode = ~kcode[0]; if (rt[0] >= 0x4000) diff --git a/core/nullDC.cpp b/core/nullDC.cpp index 15d2f3e8b..ef0a5b8d3 100644 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -83,6 +83,7 @@ void SaveSettings() void flycast_term() { + os_DestroyWindow(); gui_cancel_load(); lua::term(); emu.term(); diff --git a/core/oslib/oslib.cpp b/core/oslib/oslib.cpp index 3a078bae7..38e9d0d30 100644 --- a/core/oslib/oslib.cpp +++ b/core/oslib/oslib.cpp @@ -25,6 +25,20 @@ #ifndef _WIN32 #include #endif +#if defined(USE_SDL) +#include "sdl/sdl.h" +#else + #if defined(SUPPORT_X11) + #include "linux-dist/x11.h" + #endif + #if defined(USE_EVDEV) + #include "linux-dist/evdev.h" + #endif +#endif +#if defined(_WIN32) && !defined(TARGET_UWP) +#include "windows/rawinput.h" +#endif +#include "profiler/fc_profiler.h" namespace hostfs { @@ -139,6 +153,70 @@ std::string getTextureDumpPath() } +void os_CreateWindow() +{ +#if defined(USE_SDL) + sdl_window_create(); +#elif defined(SUPPORT_X11) + x11_window_create(); +#endif +} + +void os_DestroyWindow() +{ +#if defined(USE_SDL) + sdl_window_destroy(); +#elif defined(SUPPORT_X11) + x11_window_destroy(); +#endif +} + +void os_SetupInput() +{ +#if defined(USE_SDL) + input_sdl_init(); +#else + #if defined(SUPPORT_X11) + input_x11_init(); + #endif + #if defined(USE_EVDEV) + input_evdev_init(); + #endif +#endif +#if defined(_WIN32) && !defined(TARGET_UWP) + if (config::UseRawInput) + rawinput::init(); +#endif +} + +void os_TermInput() +{ +#if defined(USE_SDL) + input_sdl_quit(); +#else + #if defined(USE_EVDEV) + input_evdev_close(); + #endif +#endif +#if defined(_WIN32) && !defined(TARGET_UWP) + if (config::UseRawInput) + rawinput::term(); +#endif +} + +void os_UpdateInputState() +{ + FC_PROFILE_SCOPE; + +#if defined(USE_SDL) + input_sdl_handle(); +#else + #if defined(USE_EVDEV) + input_evdev_handle(); + #endif +#endif +} + #ifdef USE_BREAKPAD #include "rend/boxart/http_client.h" diff --git a/core/oslib/oslib.h b/core/oslib/oslib.h index 91aff2106..8744af19e 100644 --- a/core/oslib/oslib.h +++ b/core/oslib/oslib.h @@ -4,12 +4,12 @@ #include #endif -void os_SetWindowText(const char* text); - void os_DoEvents(); void os_CreateWindow(); +void os_DestroyWindow(); void os_SetupInput(); void os_TermInput(); +void os_UpdateInputState(); void os_InstallFaultHandler(); void os_UninstallFaultHandler(); void os_RunInstance(int argc, const char *argv[]); diff --git a/core/rend/gui_util.h b/core/rend/gui_util.h index 931c07bd9..fc25f3f52 100644 --- a/core/rend/gui_util.h +++ b/core/rend/gui_util.h @@ -24,6 +24,7 @@ #include "imgui_internal.h" #include "gui.h" #include "emulator.h" +#include "oslib/oslib.h" #include #include @@ -78,6 +79,7 @@ public: { progress.reset(); future = std::async(std::launch::async, [this, path] { + ThreadName _("GameLoader"); emu.loadGame(path.c_str(), &progress); }); } diff --git a/core/rend/mainui.cpp b/core/rend/mainui.cpp index c2dce96df..8191679e4 100644 --- a/core/rend/mainui.cpp +++ b/core/rend/mainui.cpp @@ -34,14 +34,12 @@ static bool mainui_enabled; u32 MainFrameCount; static bool forceReinit; -void UpdateInputState(); - bool mainui_rend_frame() { FC_PROFILE_SCOPE; os_DoEvents(); - UpdateInputState(); + os_UpdateInputState(); if (gui_is_open() || gui_state == GuiState::VJoyEdit) { diff --git a/core/sdl/sdl.cpp b/core/sdl/sdl.cpp index fb9c7d51c..48b8259f7 100644 --- a/core/sdl/sdl.cpp +++ b/core/sdl/sdl.cpp @@ -562,12 +562,6 @@ void input_sdl_handle() } } -void sdl_window_set_text(const char* text) -{ - if (window != nullptr) - SDL_SetWindowTitle(window, text); -} - static float hdpiScaling = 1.f; static inline void get_window_state() diff --git a/core/sdl/sdl.h b/core/sdl/sdl.h index a79f85f22..c60d083f2 100644 --- a/core/sdl/sdl.h +++ b/core/sdl/sdl.h @@ -6,7 +6,6 @@ void input_sdl_init(); void input_sdl_handle(); void input_sdl_quit(); void sdl_window_create(); -void sdl_window_set_text(const char* text); void sdl_window_destroy(); bool sdl_recreate_window(u32 flags); void sdl_fix_steamdeck_dpi(SDL_Window *window); diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index f39b51e90..302e07dfd 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -28,8 +28,6 @@ #include #include "cfg/option.h" #include "rend/gui.h" -#else -#include "rawinput.h" #endif #include "oslib/oslib.h" #include "stdclass.h" @@ -51,26 +49,6 @@ #include #include -void os_SetupInput() -{ - input_sdl_init(); - -#ifndef TARGET_UWP - if (config::UseRawInput) - rawinput::init(); -#endif -} - -void os_TermInput() -{ - input_sdl_quit(); - -#ifndef TARGET_UWP - if (config::UseRawInput) - rawinput::term(); -#endif -} - static void setupPath() { #ifndef TARGET_UWP @@ -110,23 +88,6 @@ static void setupPath() #endif } -void UpdateInputState() -{ - FC_PROFILE_SCOPE; - - input_sdl_handle(); -} - -void os_CreateWindow() -{ - sdl_window_create(); -} - -void os_SetWindowText(const char* text) -{ - sdl_window_set_text(text); -} - static void reserveBottomMemory() { #if defined(_WIN64) && defined(_DEBUG) @@ -433,8 +394,6 @@ int main(int argc, char* argv[]) mainui_loop(); - sdl_window_destroy(); - flycast_term(); os_UninstallFaultHandler(); diff --git a/shell/android-studio/flycast/src/main/jni/src/Android.cpp b/shell/android-studio/flycast/src/main/jni/src/Android.cpp index e07870fcd..351f6c564 100644 --- a/shell/android-studio/flycast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/flycast/src/main/jni/src/Android.cpp @@ -99,27 +99,8 @@ void os_DoEvents() { } -void os_CreateWindow() -{ -} - -void UpdateInputState() -{ -} - void common_linux_setup(); -void os_SetupInput() -{ -} -void os_TermInput() -{ -} - -void os_SetWindowText(char const *Text) -{ -} - #if defined(USE_BREAKPAD) static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) { diff --git a/shell/apple/emulator-ios/emulator/AppDelegate.mm b/shell/apple/emulator-ios/emulator/AppDelegate.mm index cc568b84f..dc5760173 100644 --- a/shell/apple/emulator-ios/emulator/AppDelegate.mm +++ b/shell/apple/emulator-ios/emulator/AppDelegate.mm @@ -23,6 +23,8 @@ #import "AppDelegate.h" #import +#include +#include #include "emulator.h" #include "log/LogManager.h" #include "cfg/option.h" @@ -50,6 +52,11 @@ static bool emulatorRunning; if (error != nil) NSLog(@"AVAudioSession.setActive: %@", error); + if (getppid() != 1) { + /* Make LLDB ignore EXC_BAD_ACCESS for debugging */ + task_set_exception_ports(mach_task_self(), EXC_MASK_BAD_ACCESS, MACH_PORT_NULL, EXCEPTION_DEFAULT, 0); + } + return YES; } diff --git a/shell/apple/emulator-ios/emulator/FlycastViewController.mm b/shell/apple/emulator-ios/emulator/FlycastViewController.mm index 4d4c66cde..018c261a9 100644 --- a/shell/apple/emulator-ios/emulator/FlycastViewController.mm +++ b/shell/apple/emulator-ios/emulator/FlycastViewController.mm @@ -54,8 +54,6 @@ std::map> IOSGamepad::controllers; std::map> IOSKeyboard::keyboards; std::map> IOSMouse::mice; -void common_linux_setup(); - static bool lockedPointer; static void updatePointerLock(Event event, void *) { @@ -210,7 +208,7 @@ static void updateAudioSession(Event event, void *) } #endif - common_linux_setup(); + os_InstallFaultHandler(); flycast_init(0, nullptr); config::ContentPath.get().clear(); diff --git a/shell/apple/emulator-ios/emulator/ios_main.mm b/shell/apple/emulator-ios/emulator/ios_main.mm index a602d3e07..0fe36432c 100644 --- a/shell/apple/emulator-ios/emulator/ios_main.mm +++ b/shell/apple/emulator-ios/emulator/ios_main.mm @@ -20,8 +20,6 @@ #import #include -#include -#include int darw_printf(const char* text,...) { @@ -40,24 +38,6 @@ int darw_printf(const char* text,...) void os_DoEvents() { } -void os_SetWindowText(const char* t) { -} - -void os_CreateWindow() { - if (getppid() != 1) { - /* Make LLDB ignore EXC_BAD_ACCESS for debugging */ - task_set_exception_ports(mach_task_self(), EXC_MASK_BAD_ACCESS, MACH_PORT_NULL, EXCEPTION_DEFAULT, 0); - } -} - -void UpdateInputState() { -} - -void os_SetupInput() { -} -void os_TermInput() { -} - std::string os_Locale(){ return [[[NSLocale preferredLanguages] objectAtIndex:0] UTF8String]; } diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index 6b3e34ab3..bf5eb401f 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -47,10 +47,6 @@ int darw_printf(const char* text, ...) return 0; } -void os_SetWindowText(const char * text) { - puts(text); -} - void os_DoEvents() { #if defined(USE_SDL) NSMenuItem *editMenuItem = [[NSApp mainMenu] itemAtIndex:1]; @@ -58,43 +54,6 @@ void os_DoEvents() { #endif } -void UpdateInputState() { -#if defined(USE_SDL) - input_sdl_handle(); -#endif -} - -void os_CreateWindow() { -#ifdef DEBUG - int ret = task_set_exception_ports( - mach_task_self(), - EXC_MASK_BAD_ACCESS, - MACH_PORT_NULL, - EXCEPTION_DEFAULT, - 0); - - if (ret != KERN_SUCCESS) { - printf("task_set_exception_ports: %s\n", mach_error_string(ret)); - } -#endif - sdl_window_create(); -} - -void os_SetupInput() -{ -#if defined(USE_SDL) - input_sdl_init(); -#endif -} - -void os_TermInput() -{ -#if defined(USE_SDL) - input_sdl_quit(); -#endif -} - -void common_linux_setup(); static int emu_flycast_init(); static void emu_flycast_term() @@ -172,7 +131,6 @@ extern "C" int SDL_main(int argc, char *argv[]) mainui_loop(); - sdl_window_destroy(); emu_flycast_term(); os_UninstallFaultHandler(); @@ -182,7 +140,7 @@ extern "C" int SDL_main(int argc, char *argv[]) static int emu_flycast_init() { LogManager::Init(); - common_linux_setup(); + os_InstallFaultHandler(); NSArray *arguments = [[NSProcessInfo processInfo] arguments]; unsigned long argc = [arguments count]; char **argv = (char **)malloc(argc * sizeof(char*)); @@ -201,6 +159,19 @@ static int emu_flycast_init() for (unsigned long i = 0; i < paramCount; i++) free(argv[i]); free(argv); + +#if defined(DEBUG) || defined(DEBUGFAST) + int ret = task_set_exception_ports( + mach_task_self(), + EXC_MASK_BAD_ACCESS, + MACH_PORT_NULL, + EXCEPTION_DEFAULT, + 0); + + if (ret != KERN_SUCCESS) { + printf("task_set_exception_ports: %s\n", mach_error_string(ret)); + } +#endif return rc; } diff --git a/shell/libretro/libretro.cpp b/shell/libretro/libretro.cpp index 78a5a7bbc..472401d79 100644 --- a/shell/libretro/libretro.cpp +++ b/shell/libretro/libretro.cpp @@ -221,7 +221,6 @@ static std::vector disk_paths; static std::vector disk_labels; static bool disc_tray_open = false; -void UpdateInputState(); static bool set_variable_visibility(void); void retro_set_video_refresh(retro_video_refresh_t cb) @@ -1170,7 +1169,7 @@ void retro_run() emu.start(); poll_cb(); - UpdateInputState(); + os_UpdateInputState(); bool fastforward = false; if (environ_cb(RETRO_ENVIRONMENT_GET_FASTFORWARDING, &fastforward)) settings.input.fastForwardMode = fastforward; @@ -3357,7 +3356,7 @@ static void UpdateInputState(u32 port) } } -void UpdateInputState() +void os_UpdateInputState() { UpdateInputState(0); UpdateInputState(1); @@ -3710,5 +3709,3 @@ void gui_display_notification(const char *msg, int duration) retromsg.frames = duration / 17; environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &retromsg); } - -void os_RunInstance(int argc, const char *argv[]) { } diff --git a/shell/switch/switch_main.cpp b/shell/switch/switch_main.cpp index bf59e3173..1c3fdcffe 100644 --- a/shell/switch/switch_main.cpp +++ b/shell/switch/switch_main.cpp @@ -17,7 +17,6 @@ #ifndef LIBRETRO #include "nswitch.h" #include "stdclass.h" -#include "sdl/sdl.h" #include "log/LogManager.h" #include "emulator.h" #include "rend/mainui.h" @@ -48,7 +47,6 @@ int main(int argc, char *argv[]) mainui_loop(); - sdl_window_destroy(); flycast_term(); socketExit(); @@ -56,28 +54,8 @@ int main(int argc, char *argv[]) return 0; } -void os_SetupInput() -{ - input_sdl_init(); -} - -void os_TermInput() -{ - input_sdl_quit(); -} - -void UpdateInputState() -{ - input_sdl_handle(); -} - void os_DoEvents() { } -void os_CreateWindow() -{ - sdl_window_create(); -} - #endif //!LIBRETRO diff --git a/tests/src/test_stubs.cpp b/tests/src/test_stubs.cpp index e87bc1459..aa3793ace 100644 --- a/tests/src/test_stubs.cpp +++ b/tests/src/test_stubs.cpp @@ -15,25 +15,10 @@ HWND getNativeHwnd() } #endif -void os_SetupInput() -{ -} -void os_TermInput() -{ -} - -void UpdateInputState() -{ -} - void os_DoEvents() { } -void os_CreateWindow() -{ -} - void os_RunInstance(int argc, const char *argv[]) { }