diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index b497bd039..35b90d2f6 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -199,6 +199,11 @@ void HostInterface::AddFormattedOSDMessage(float duration, const char* format, . AddOSDMessage(std::move(message), duration); } +std::string HostInterface::GetBIOSDirectory() const +{ + return GetUserDirectoryRelativePath("bios"); +} + std::optional> HostInterface::GetBIOSImage(ConsoleRegion region) { const std::string* bios_path; @@ -221,12 +226,13 @@ std::optional> HostInterface::GetBIOSImage(ConsoleRegion region) if (bios_path->empty()) { // auto-detect - return FindBIOSImageInDirectory(region, GetUserDirectoryRelativePath("bios").c_str()); + return FindBIOSImageInDirectory(region, GetBIOSDirectory().c_str()); } // try the configured path std::optional image = BIOS::LoadImageFromFile( - GetUserDirectoryRelativePath("bios" FS_OSPATH_SEPARATOR_STR "%s", bios_path->c_str()).c_str()); + StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", GetBIOSDirectory().c_str(), bios_path->c_str()) + .c_str()); if (!image.has_value()) { g_host_interface->ReportFormattedError( diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 5073dc979..72743b510 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -118,6 +118,9 @@ public: virtual TinyString TranslateString(const char* context, const char* str) const; virtual std::string TranslateStdString(const char* context, const char* str) const; + /// Returns the path to the directory to search for BIOS images. + virtual std::string GetBIOSDirectory() const; + /// Loads the BIOS image for the specified region. std::optional> GetBIOSImage(ConsoleRegion region); diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index 121bf67e3..24b953722 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -252,40 +252,33 @@ bool LibretroHostInterface::retro_load_game(const struct retro_game_info* game) bp.filename = game->path; bp.media_playlist_index = m_next_disc_index.value_or(0); bp.force_software_renderer = !m_hw_render_callback_valid; - + struct retro_input_descriptor desc[] = { -#define JOYP(port) \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" }, \ - { port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" }, \ - { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" }, \ - { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" }, \ - { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" }, \ - { port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }, +#define JOYP(port) \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select"}, \ + {port, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start"}, \ + {port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X"}, \ + {port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y"}, \ + {port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X"}, \ + {port, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y"}, - JOYP(0) - JOYP(1) - JOYP(2) - JOYP(3) - JOYP(4) - JOYP(5) - JOYP(6) - JOYP(7) + JOYP(0) JOYP(1) JOYP(2) JOYP(3) JOYP(4) JOYP(5) JOYP(6) JOYP(7) - { 0 }, + {0}, }; g_retro_environment_callback(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); @@ -653,17 +646,21 @@ bool LibretroHostInterface::HasCoreVariablesChanged() return (g_retro_environment_callback(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &changed) && changed); } +std::string LibretroHostInterface::GetBIOSDirectory() const +{ + // Assume BIOS files are located in system directory. + const char* system_directory = nullptr; + if (!g_retro_environment_callback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_directory) || !system_directory) + return GetProgramDirectoryRelativePath("system"); + else + return system_directory; +} + void LibretroHostInterface::LoadSettings() { LibretroSettingsInterface si; HostInterface::LoadSettings(si); - // Assume BIOS files are located in system directory. - const char* system_directory = nullptr; - if (!g_retro_environment_callback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_directory) || !system_directory) - system_directory = "bios"; - g_settings.bios_path = StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "scph1001.bin", system_directory); - // Ensure we don't use the standalone memcard directory in shared mode. for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) g_settings.memory_card_paths[i] = GetSharedMemoryCardPath(i); diff --git a/src/duckstation-libretro/libretro_host_interface.h b/src/duckstation-libretro/libretro_host_interface.h index 07e0e23fb..c0671c7a0 100644 --- a/src/duckstation-libretro/libretro_host_interface.h +++ b/src/duckstation-libretro/libretro_host_interface.h @@ -28,6 +28,7 @@ public: std::string GetGameMemoryCardPath(const char* game_code, u32 slot) const override; std::string GetShaderCacheBasePath() const override; std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override; + std::string GetBIOSDirectory() const override; // Called by frontend void retro_get_system_av_info(struct retro_system_av_info* info);