From 0e2276fc7af769e3d22533a5474e031df20b4dec Mon Sep 17 00:00:00 2001 From: Albert Liu <45282415+ggrtk@users.noreply.github.com> Date: Fri, 25 Dec 2020 07:33:33 -0800 Subject: [PATCH] BIOS: Add support for loading PS2 BIOSes --- src/core/bios.cpp | 6 ++++-- src/core/bios.h | 3 ++- src/core/host_interface.cpp | 4 ++-- src/core/host_interface.h | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/bios.cpp b/src/core/bios.cpp index 9a86d3e73..3a47775f3 100644 --- a/src/core/bios.cpp +++ b/src/core/bios.cpp @@ -101,9 +101,11 @@ std::optional LoadImageFromFile(const char* filename) const u32 size = static_cast(std::ftell(fp.get())); std::fseek(fp.get(), 0, SEEK_SET); - if (size != BIOS_SIZE) + // Apparently some PS1/PS2 BIOS revisions found on the PS3 are neither 512KB nor 4MB, so just check within this range + if (size < BIOS_SIZE || size > BIOS_SIZE_PS2) { - Log_ErrorPrintf("BIOS image '%s' mismatch, expecting %u bytes, got %u bytes", filename, BIOS_SIZE, size); + Log_ErrorPrintf("BIOS image '%s' mismatch, expecting between %u and %u bytes, got %u bytes", filename, BIOS_SIZE, + BIOS_SIZE_PS2, size); return std::nullopt; } diff --git a/src/core/bios.h b/src/core/bios.h index ee298399f..3367407f0 100644 --- a/src/core/bios.h +++ b/src/core/bios.h @@ -9,7 +9,8 @@ namespace BIOS { enum : u32 { BIOS_BASE = 0x1FC00000, - BIOS_SIZE = 0x80000 + BIOS_SIZE = 0x80000, + BIOS_SIZE_PS2 = 0x400000 }; using Image = std::vector; diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 4092ecc19..c946bbdd7 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -304,7 +304,7 @@ std::optional> HostInterface::FindBIOSImageInDirectory(ConsoleRe for (const FILESYSTEM_FIND_DATA& fd : results) { - if (fd.Size != BIOS::BIOS_SIZE) + if (fd.Size < BIOS::BIOS_SIZE || fd.Size > BIOS::BIOS_SIZE_PS2) { Log_WarningPrintf("Skipping '%s': incorrect size", fd.FileName.c_str()); continue; @@ -353,7 +353,7 @@ HostInterface::FindBIOSImagesInDirectory(const char* directory) for (FILESYSTEM_FIND_DATA& fd : files) { - if (fd.Size != BIOS::BIOS_SIZE) + if (fd.Size < BIOS::BIOS_SIZE || fd.Size > BIOS::BIOS_SIZE_PS2) continue; std::string full_path( diff --git a/src/core/host_interface.h b/src/core/host_interface.h index c984f7d91..557c8d1b6 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -126,7 +126,7 @@ public: std::optional> GetBIOSImage(ConsoleRegion region); /// Searches for a BIOS image for the specified region in the specified directory. If no match is found, the first - /// 512KB BIOS image will be used. + /// BIOS image within 512KB and 4MB will be used. std::optional> FindBIOSImageInDirectory(ConsoleRegion region, const char* directory); /// Returns a list of filenames and descriptions for BIOS images in a directory.