From 17d6e866a07807a417270c409a7648b07acca290 Mon Sep 17 00:00:00 2001 From: goyuken Date: Mon, 10 Feb 2014 15:26:18 +0000 Subject: [PATCH] pce: refactor CD loading to move bios determination out of RomLoader --- BizHawk.Client.Common/CoreFileProvider.cs | 32 +++++++++++-- BizHawk.Client.Common/RomLoader.cs | 48 +------------------ .../Interfaces/ICoreFileProvider.cs | 2 + .../Consoles/PC Engine/PCEngine.cs | 41 +++++++++++++++- 4 files changed, 70 insertions(+), 53 deletions(-) diff --git a/BizHawk.Client.Common/CoreFileProvider.cs b/BizHawk.Client.Common/CoreFileProvider.cs index 2ff417b2f6..be1252ecf0 100644 --- a/BizHawk.Client.Common/CoreFileProvider.cs +++ b/BizHawk.Client.Common/CoreFileProvider.cs @@ -75,24 +75,46 @@ namespace BizHawk.Client.Common return path; } - public byte[] GetFirmware(string sysID, string firmwareID, bool required, string msg = null) + private byte[] GetFirmwareWithPath(string sysID, string firmwareID, bool required, string msg, out string path) { byte[] ret = null; - var path = GetFirmwarePath(sysID, firmwareID, required, msg); - if (path != null && File.Exists(path)) + var path_ = GetFirmwarePath(sysID, firmwareID, required, msg); + if (path_ != null && File.Exists(path_)) { try { - ret = File.ReadAllBytes(path); + ret = File.ReadAllBytes(path_); } catch (IOException) { } } - if (ret == null && path != null) + if (ret == null && path_ != null) { FirmwareWarn(sysID, firmwareID, required, msg); } + path = path_; + return ret; + } + + public byte[] GetFirmware(string sysID, string firmwareID, bool required, string msg = null) + { + string unused; + return GetFirmwareWithPath(sysID, firmwareID, required, msg, out unused); + } + + public byte[] GetFirmwareWithGameInfo(string sysID, string firmwareID, bool required, out GameInfo gi, string msg = null) + { + string path; + byte[] ret = GetFirmwareWithPath(sysID, firmwareID, required, msg, out path); + if (ret != null && path != null) + { + gi = Database.GetGameInfo(ret, path); + } + else + { + gi = null; + } return ret; } diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index 48595764c8..981a69858d 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -223,53 +223,7 @@ namespace BizHawk.Client.Common break; case "PCE": case "PCECD": - var biosPath = Global.FirmwareManager.Request("PCECD", "Bios"); - if (!File.Exists(biosPath)) - { - ThrowLoadError("PCE-CD System Card not found. Please check the BIOS settings in Config->Firmwares.", game.System); - return false; - } - - rom = new RomGame(new HawkFile(biosPath)); - - if (rom.GameInfo.Status == RomStatus.BadDump) - { - ThrowLoadError( - "The PCE-CD System Card you have selected is known to be a bad dump. This may cause problems playing PCE-CD games.\n\n" - + "It is recommended that you find a good dump of the system card. Sorry to be the bearer of bad news!", - game.System); - return false; - } - else if (rom.GameInfo.NotInDatabase) - { - ThrowLoadError( - "The PCE-CD System Card you have selected is not recognized in our database. That might mean it's a bad dump, or isn't the correct rom.", - game.System); - return false; - } - else if (rom.GameInfo["BIOS"] == false) - { - ThrowLoadError( - "The PCE-CD System Card you have selected is not a BIOS image. You may have selected the wrong rom.", - game.System); - return false; - } - - if (rom.GameInfo["SuperSysCard"]) - { - game.AddOption("SuperSysCard"); - } - - if (game["NeedSuperSysCard"] && game["SuperSysCard"] == false) - { - ThrowLoadError( - "This game requires a version 3.0 System card and won't run with the system card you've selected. Try selecting a 3.0 System Card in Config->Paths->PC Engine.", - game.System); - return false; - } - - game.FirmwareHash = Util.Hash_SHA1(rom.RomData); - nextEmulator = new PCEngine(nextComm, game, disc, rom.RomData, GetCoreSettings()); + nextEmulator = new PCEngine(nextComm, game, disc, GetCoreSettings()); break; } } diff --git a/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs b/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs index e722bdca2d..167bc67183 100644 --- a/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs +++ b/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs @@ -47,6 +47,8 @@ namespace BizHawk.Emulation.Common /// byte[] GetFirmware(string sysID, string firmwareID, bool required, string msg = null); + byte[] GetFirmwareWithGameInfo(string sysID, string firmwareID, bool required, out GameInfo gi, string msg = null); + #endregion } diff --git a/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs b/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs index a059cd1e2f..d5f6af6b16 100644 --- a/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs +++ b/BizHawk.Emulation.Cores/Consoles/PC Engine/PCEngine.cs @@ -76,7 +76,7 @@ namespace BizHawk.Emulation.Cores.PCEngine public string BoardName { get { return null; } } - public PCEngine(CoreComm comm, GameInfo game, Disc disc, byte[] rom, object Settings) + public PCEngine(CoreComm comm, GameInfo game, Disc disc, object Settings) { CoreComm = comm; CoreComm.CpuTraceAvailable = true; @@ -85,6 +85,45 @@ namespace BizHawk.Emulation.Cores.PCEngine Type = NecSystemType.TurboCD; this.disc = disc; this.Settings = (PCESettings)Settings ?? new PCESettings(); + + GameInfo biosInfo; + byte[] rom = CoreComm.CoreFileProvider.GetFirmwareWithGameInfo("PCECD", "Bios", true, out biosInfo, + "PCE-CD System Card not found. Please check the BIOS settings in Config->Firmwares."); + + if (biosInfo.Status == RomStatus.BadDump) + { + CoreComm.ShowMessage( + "The PCE-CD System Card you have selected is known to be a bad dump. This may cause problems playing PCE-CD games.\n\n" + + "It is recommended that you find a good dump of the system card. Sorry to be the bearer of bad news!"); + throw new Exception(); + } + else if (biosInfo.NotInDatabase) + { + CoreComm.ShowMessage( + "The PCE-CD System Card you have selected is not recognized in our database. That might mean it's a bad dump, or isn't the correct rom."); + throw new Exception(); + } + else if (biosInfo["BIOS"] == false) + { + CoreComm.ShowMessage( + "The PCE-CD System Card you have selected is not a BIOS image. You may have selected the wrong rom."); + throw new Exception(); + } + + if (biosInfo["SuperSysCard"]) + { + game.AddOption("SuperSysCard"); + } + + if (game["NeedSuperSysCard"] && game["SuperSysCard"] == false) + { + CoreComm.ShowMessage( + "This game requires a version 3.0 System card and won't run with the system card you've selected. Try selecting a 3.0 System Card in the firmware configuration."); + throw new Exception(); + } + + game.FirmwareHash = Util.Hash_SHA1(rom); + Init(game, rom); // the default RomStatusDetails don't do anything with Disc CoreComm.RomStatusDetails = string.Format("{0}\r\nDisk partial hash:{1}", game.Name, disc.GetHash());