System: Use game code for automatic region detection

This commit is contained in:
Connor McLaughlin 2019-12-05 17:09:10 +10:00
parent eeea5125f7
commit 8b9d44f4dc
4 changed files with 32 additions and 16 deletions

View File

@ -140,18 +140,34 @@ std::optional<ConsoleRegion> GameList::GetRegionForCode(std::string_view code)
prefix.push_back(static_cast<char>(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<ConsoleRegion> GameList::GetRegionForImage(CDImage* cdi)
{
std::string code = GetGameCodeForImage(cdi);
if (code.empty())
return std::nullopt;
return GetRegionForCode(code);
}
std::optional<ConsoleRegion> GameList::GetRegionForPath(const char* image_path)
{
std::unique_ptr<CDImage> cdi = CDImage::Open(image_path);
if (!cdi)
return {};
return GetRegionForImage(cdi.get());
}
void GameList::AddDirectory(const char* path, bool recursive)
{
ScanDirectory(path, recursive);

View File

@ -46,6 +46,8 @@ public:
static std::string GetGameCodeForImage(CDImage* cdi);
static std::string GetGameCodeForPath(const char* image_path);
static std::optional<ConsoleRegion> GetRegionForCode(std::string_view code);
static std::optional<ConsoleRegion> GetRegionForImage(CDImage* cdi);
static std::optional<ConsoleRegion> GetRegionForPath(const char* image_path);
const DatabaseMap& GetDatabase() const { return m_database; }
const EntryList& GetEntries() const { return m_entries; }

View File

@ -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<ConsoleRegion> 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<ConsoleRegion> detected_region = GetRegionForCDImage(media.get());
m_region = detected_region.value_or(ConsoleRegion::NTSC_U);
std::optional<ConsoleRegion> 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));
}
}
}
}

View File

@ -29,9 +29,6 @@ class System
public:
~System();
/// Detects region for the specified image file.
static std::optional<ConsoleRegion> GetRegionForCDImage(const CDImage* image);
/// Returns true if the filename is a PlayStation executable we can inject.
static bool IsPSExe(const char* filename);