diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index ea9a26525..0171adcab 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -140,18 +140,34 @@ std::optional GameList::GetRegionForCode(std::string_view code) prefix.push_back(static_cast(ch)); } - // TODO: PAPX? - if (prefix == "sces" || prefix == "sced" || prefix == "sles" || prefix == "sled") return ConsoleRegion::PAL; - else if (prefix == "scps" || prefix == "scpd" || prefix == "slps" || prefix == "slpd") + else if (prefix == "scps" || prefix == "slps" || prefix == "slpm") return ConsoleRegion::NTSC_J; - else if (prefix == "scus" || prefix == "slus") + else if (prefix == "scus" || prefix == "slus" || prefix == "papx") return ConsoleRegion::NTSC_U; else return std::nullopt; } +std::optional GameList::GetRegionForImage(CDImage* cdi) +{ + std::string code = GetGameCodeForImage(cdi); + if (code.empty()) + return std::nullopt; + + return GetRegionForCode(code); +} + +std::optional GameList::GetRegionForPath(const char* image_path) +{ + std::unique_ptr cdi = CDImage::Open(image_path); + if (!cdi) + return {}; + + return GetRegionForImage(cdi.get()); +} + void GameList::AddDirectory(const char* path, bool recursive) { ScanDirectory(path, recursive); diff --git a/src/core/game_list.h b/src/core/game_list.h index bcc60dfd3..8b07c9d11 100644 --- a/src/core/game_list.h +++ b/src/core/game_list.h @@ -46,6 +46,8 @@ public: static std::string GetGameCodeForImage(CDImage* cdi); static std::string GetGameCodeForPath(const char* image_path); static std::optional GetRegionForCode(std::string_view code); + static std::optional GetRegionForImage(CDImage* cdi); + static std::optional GetRegionForPath(const char* image_path); const DatabaseMap& GetDatabase() const { return m_database; } const EntryList& GetEntries() const { return m_entries; } diff --git a/src/core/system.cpp b/src/core/system.cpp index 8aa4a3dae..7687fcd84 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -8,6 +8,7 @@ #include "cpu_code_cache.h" #include "cpu_core.h" #include "dma.h" +#include "game_list.h" #include "gpu.h" #include "host_interface.h" #include "interrupt_controller.h" @@ -39,12 +40,6 @@ System::System(HostInterface* host_interface) : m_host_interface(host_interface) System::~System() = default; -std::optional System::GetRegionForCDImage(const CDImage* image) -{ - // TODO: Implement me. - return ConsoleRegion::NTSC_U; -} - bool System::IsPSExe(const char* filename) { const StaticString filename_str(filename); @@ -115,12 +110,18 @@ bool System::Boot(const char* filename) if (m_region == ConsoleRegion::Auto) { - std::optional detected_region = GetRegionForCDImage(media.get()); - m_region = detected_region.value_or(ConsoleRegion::NTSC_U); + std::optional detected_region = GameList::GetRegionForImage(media.get()); if (detected_region) + { + m_region = detected_region.value(); Log_InfoPrintf("Auto-detected %s region for '%s'", Settings::GetConsoleRegionName(m_region), filename); + } else - Log_WarningPrintf("Could not determine region for CD. Defaulting to NTSC-U."); + { + m_region = ConsoleRegion::NTSC_U; + Log_WarningPrintf("Could not determine region for CD. Defaulting to %s.", + Settings::GetConsoleRegionName(m_region)); + } } } } diff --git a/src/core/system.h b/src/core/system.h index a5935bc34..f46dbd6cf 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -29,9 +29,6 @@ class System public: ~System(); - /// Detects region for the specified image file. - static std::optional GetRegionForCDImage(const CDImage* image); - /// Returns true if the filename is a PlayStation executable we can inject. static bool IsPSExe(const char* filename);