mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-27 08:05:41 +00:00
System: Use region from exe/psf when booting
This commit is contained in:
parent
253b115b11
commit
b62f31fd96
|
@ -479,8 +479,39 @@ DiscRegion GetRegionForImage(CDImage* cdi)
|
|||
return GetRegionForCode(code);
|
||||
}
|
||||
|
||||
DiscRegion GetRegionForExe(const char* path)
|
||||
{
|
||||
auto fp = FileSystem::OpenManagedCFile(path, "rb");
|
||||
if (!fp)
|
||||
return DiscRegion::Other;
|
||||
|
||||
std::fseek(fp.get(), 0, SEEK_END);
|
||||
const u32 file_size = static_cast<u32>(std::ftell(fp.get()));
|
||||
std::fseek(fp.get(), 0, SEEK_SET);
|
||||
|
||||
BIOS::PSEXEHeader header;
|
||||
if (std::fread(&header, sizeof(header), 1, fp.get()) != 1)
|
||||
return DiscRegion::Other;
|
||||
|
||||
return BIOS::GetPSExeDiscRegion(header);
|
||||
}
|
||||
|
||||
DiscRegion GetRegionForPsf(const char* path)
|
||||
{
|
||||
PSFLoader::File psf;
|
||||
if (!psf.Load(path))
|
||||
return DiscRegion::Other;
|
||||
|
||||
return psf.GetRegion();
|
||||
}
|
||||
|
||||
std::optional<DiscRegion> GetRegionForPath(const char* image_path)
|
||||
{
|
||||
if (IsExeFileName(image_path))
|
||||
return GetRegionForExe(image_path);
|
||||
else if (IsPsfFileName(image_path))
|
||||
return GetRegionForPsf(image_path);
|
||||
|
||||
std::unique_ptr<CDImage> cdi = CDImage::Open(image_path);
|
||||
if (!cdi)
|
||||
return {};
|
||||
|
@ -578,11 +609,12 @@ bool Boot(const SystemBootParameters& params)
|
|||
psf_boot = (!exe_boot && IsPsfFileName(params.filename.c_str()));
|
||||
if (exe_boot || psf_boot)
|
||||
{
|
||||
// TODO: Pull region from PSF
|
||||
if (s_region == ConsoleRegion::Auto)
|
||||
{
|
||||
Log_InfoPrintf("Defaulting to NTSC-U/C region for executable.");
|
||||
s_region = ConsoleRegion::NTSC_U;
|
||||
const DiscRegion file_region =
|
||||
(exe_boot ? GetRegionForExe(params.filename.c_str()) : GetRegionForPsf(params.filename.c_str()));
|
||||
Log_InfoPrintf("EXE/PSF Region: %s", Settings::GetDiscRegionDisplayName(file_region));
|
||||
s_region = GetConsoleRegionForDiscRegion(file_region);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -651,6 +683,8 @@ bool Boot(const SystemBootParameters& params)
|
|||
s_region = ConsoleRegion::NTSC_U;
|
||||
}
|
||||
|
||||
Log_InfoPrintf("Console Region: %s", Settings::GetConsoleRegionDisplayName(s_region));
|
||||
|
||||
// Load BIOS image.
|
||||
std::optional<BIOS::Image> bios_image = g_host_interface->GetBIOSImage(s_region);
|
||||
if (!bios_image)
|
||||
|
|
|
@ -77,6 +77,8 @@ std::string GetGameCodeForPath(const char* image_path);
|
|||
DiscRegion GetRegionForCode(std::string_view code);
|
||||
DiscRegion GetRegionFromSystemArea(CDImage* cdi);
|
||||
DiscRegion GetRegionForImage(CDImage* cdi);
|
||||
DiscRegion GetRegionForExe(const char* path);
|
||||
DiscRegion GetRegionForPsf(const char* path);
|
||||
std::optional<DiscRegion> GetRegionForPath(const char* image_path);
|
||||
std::string_view GetTitleForPath(const char* path);
|
||||
|
||||
|
|
Loading…
Reference in a new issue