diff --git a/core/emulator.cpp b/core/emulator.cpp index 5d7fadb30..3872bd47c 100644 --- a/core/emulator.cpp +++ b/core/emulator.cpp @@ -447,6 +447,7 @@ void Emulator::loadGame(const char *path, LoadProgress *progress) { hostfs::FileInfo info = hostfs::storage().getFileInfo(settings.content.path); settings.content.fileName = info.name; + settings.content.title = get_file_basename(info.name); } } else @@ -504,6 +505,8 @@ void Emulator::loadGame(const char *path, LoadProgress *progress) InitDrive(""); } } + if (settings.content.path.empty()) + settings.content.title = "Dreamcast BIOS"; if (progress) progress->progress = 1.0f; @@ -761,8 +764,6 @@ void Emulator::setNetworkState(bool online) settings.input.fastForwardMode &= !online; } -EventManager EventManager::Instance; - void EventManager::registerEvent(Event event, Callback callback, void *param) { unregisterEvent(event, callback, param); diff --git a/core/emulator.h b/core/emulator.h index 09800e2a0..e72737c63 100644 --- a/core/emulator.h +++ b/core/emulator.h @@ -54,25 +54,28 @@ public: using Callback = void (*)(Event, void *); static void listen(Event event, Callback callback, void *param = nullptr) { - Instance.registerEvent(event, callback, param); + instance().registerEvent(event, callback, param); } static void unlisten(Event event, Callback callback, void *param = nullptr) { - Instance.unregisterEvent(event, callback, param); + instance().unregisterEvent(event, callback, param); } static void event(Event event) { - Instance.broadcastEvent(event); + instance().broadcastEvent(event); } private: EventManager() = default; + static EventManager& instance() { + static EventManager _instance; + return _instance; + } void registerEvent(Event event, Callback callback, void *param); void unregisterEvent(Event event, Callback callback, void *param); void broadcastEvent(Event event); - static EventManager Instance; std::map>> callbacks; }; diff --git a/core/hw/naomi/naomi_cart.cpp b/core/hw/naomi/naomi_cart.cpp index b10bf3e75..a2978a9ea 100644 --- a/core/hw/naomi/naomi_cart.cpp +++ b/core/hw/naomi/naomi_cart.cpp @@ -627,8 +627,10 @@ void naomi_cart_LoadRom(const std::string& path, const std::string& fileName, Lo bool systemSP = memcmp(bootId.boardName, "SystemSP", 8) == 0; std::string gameId = trim_trailing_ws(std::string(bootId.gameTitle[systemSP ? 1 : 0], &bootId.gameTitle[systemSP ? 1 : 0][32])); std::string romName; - if (CurrentCartridge->game != nullptr) + if (CurrentCartridge->game != nullptr) { romName = CurrentCartridge->game->name; + settings.content.title = CurrentCartridge->game->description; + } if (gameId == "SAMPLE GAME MAX LONG NAME-") { // Use better game names @@ -885,7 +887,7 @@ void* NaomiCartridge::GetDmaPtr(u32& size) { if ((DmaOffset & 0x1fffffff) >= RomSize) { - INFO_LOG(NAOMI, "Error: DmaOffset >= RomSize"); + INFO_LOG(NAOMI, "Error: DmaOffset (%x) >= RomSize (%x)", DmaOffset, RomSize); size = 0; return nullptr; } diff --git a/core/sdl/sdl.cpp b/core/sdl/sdl.cpp index 85cf106a2..6cb4c8dc6 100644 --- a/core/sdl/sdl.cpp +++ b/core/sdl/sdl.cpp @@ -88,6 +88,14 @@ static void sdl_close_joystick(SDL_JoystickID instance) gamepad->close(); } +static void setWindowTitleGame() +{ + if (settings.naomi.slave) + SDL_SetWindowTitle(window, ("Flycast - Multiboard Slave " + cfgLoadStr("naomi", "BoardId", "")).c_str()); + else + SDL_SetWindowTitle(window, ("Flycast - " + settings.content.title).c_str()); +} + static void captureMouse(bool capture) { if (window == nullptr || !gameRunning) @@ -98,7 +106,7 @@ static void captureMouse(bool capture) SDL_SetRelativeMouseMode(SDL_FALSE); else SDL_ShowCursor(SDL_ENABLE); - SDL_SetWindowTitle(window, "Flycast"); + setWindowTitleGame(); mouseCaptured = false; } else @@ -118,12 +126,15 @@ static void emuEventCallback(Event event, void *) { switch (event) { + case Event::Terminate: + SDL_SetWindowTitle(window, "Flycast"); + break; case Event::Pause: gameRunning = false; if (!config::UseRawInput) SDL_SetRelativeMouseMode(SDL_FALSE); SDL_ShowCursor(SDL_ENABLE); - SDL_SetWindowTitle(window, "Flycast"); + setWindowTitleGame(); break; case Event::Resume: gameRunning = true; @@ -199,6 +210,9 @@ void input_sdl_init() SDL_SetRelativeMouseMode(SDL_FALSE); + // Event::Start is called on a background thread, so we can't use it to change the window title (macOS) + // However it's followed by Event::Resume which is fine. + EventManager::listen(Event::Terminate, emuEventCallback); EventManager::listen(Event::Pause, emuEventCallback); EventManager::listen(Event::Resume, emuEventCallback); @@ -234,6 +248,9 @@ void input_sdl_init() void input_sdl_quit() { + EventManager::unlisten(Event::Terminate, emuEventCallback); + EventManager::unlisten(Event::Pause, emuEventCallback); + EventManager::unlisten(Event::Resume, emuEventCallback); SDLGamepad::closeAllGamepads(); SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } diff --git a/core/types.h b/core/types.h index b0cc7b388..21b9ab3d5 100644 --- a/core/types.h +++ b/core/types.h @@ -178,6 +178,7 @@ struct settings_t std::string path; std::string gameId; std::string fileName; + std::string title; } content; struct {