diff --git a/BizHawk.Client.Common/RomLoader.cs b/BizHawk.Client.Common/RomLoader.cs index c1798cf099..6870f7ebfc 100644 --- a/BizHawk.Client.Common/RomLoader.cs +++ b/BizHawk.Client.Common/RomLoader.cs @@ -225,7 +225,7 @@ namespace BizHawk.Client.Common case "GEN": var genesis = new GPGX( nextComm, null, disc, "GEN", GetCoreSettings(), GetCoreSyncSettings()); - nextEmulator = genesis; + nextEmulator = genesis; break; case "SAT": nextEmulator = new Yabause(nextComm, disc, GetCoreSyncSettings()); @@ -318,11 +318,10 @@ namespace BizHawk.Client.Common { // need to get rid of this hack at some point ((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", String.Empty)); // Dirty hack to get around archive filenames (since we are just getting the directory path, it is safe to mangle the filename - var snes = new LibsnesCore(nextComm, GetCoreSettings(), GetCoreSyncSettings()); - nextEmulator = snes; var romData = isXml ? null : rom.FileData; var xmlData = isXml ? rom.FileData : null; - snes.Load(game, romData, Deterministic, xmlData); + var snes = new LibsnesCore(game, romData, Deterministic, xmlData, nextComm, GetCoreSettings(), GetCoreSyncSettings()); + nextEmulator = snes; } break; @@ -333,8 +332,8 @@ namespace BizHawk.Client.Common break; case "A26": nextEmulator = new Atari2600( - nextComm, - game, + nextComm, + game, rom.FileData, GetCoreSettings(), GetCoreSyncSettings()); @@ -384,9 +383,8 @@ namespace BizHawk.Client.Common { game.System = "SNES"; game.AddOption("SGB"); - var snes = new LibsnesCore(nextComm, GetCoreSettings(), GetCoreSyncSettings()); + var snes = new LibsnesCore(game, rom.FileData, Deterministic, null, nextComm, GetCoreSettings(), GetCoreSyncSettings()); nextEmulator = snes; - snes.Load(game, rom.FileData, Deterministic, null); } catch { @@ -450,7 +448,7 @@ namespace BizHawk.Client.Common } // Specific hack here, as we get more cores of the same system, this isn't scalable - if (ex is LibQuickNES.UnsupportedMapperException) + if (ex is UnsupportedMapperException) { return LoadRom(path, nextComm, forceAccurateCore: true); } @@ -473,4 +471,4 @@ namespace BizHawk.Client.Common } } } -} \ No newline at end of file +} diff --git a/BizHawk.Emulation.Common/EmulationExceptions.cs b/BizHawk.Emulation.Common/EmulationExceptions.cs index dfaacced90..75c4360c5e 100644 --- a/BizHawk.Emulation.Common/EmulationExceptions.cs +++ b/BizHawk.Emulation.Common/EmulationExceptions.cs @@ -9,4 +9,26 @@ namespace BizHawk.Emulation.Common } } + + public class UnsupportedMapperException : InvalidOperationException + { + public UnsupportedMapperException(string message) + : base(message) + { + + } + } + + public class CGBNotSupportedException : Exception + { + public CGBNotSupportedException() + : base("Core does not support CGB only games!") + { + } + + public CGBNotSupportedException(string message) + : base(message) + { + } + } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 0e6a29012a..68c1061077 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -109,7 +109,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy GambatteState = LibGambatte.gambatte_create(); if (GambatteState == IntPtr.Zero) - throw new Exception("gambatte_create() returned null???"); + throw new InvalidOperationException("gambatte_create() returned null???"); try { @@ -128,7 +128,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy flags |= LibGambatte.LoadFlags.MULTICART_COMPAT; if (LibGambatte.gambatte_load(GambatteState, romdata, (uint)romdata.Length, GetCurrentTime(), flags) != 0) - throw new Exception("gambatte_load() returned non-zero (is this not a gb or gbc rom?)"); + throw new InvalidOperationException("gambatte_load() returned non-zero (is this not a gb or gbc rom?)"); // set real default colors (before anyone mucks with them at all) PutSettings(Settings ?? new GambatteSettings()); @@ -352,7 +352,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy static void ThrowExceptionForBadRom(byte[] romdata) { if (romdata.Length < 0x148) - throw new Exception("ROM is far too small to be a valid GB\\GBC rom!"); + throw new ArgumentException("ROM is far too small to be a valid GB\\GBC rom!"); switch (romdata[0x147]) { @@ -365,9 +365,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy case 0x08: break; case 0x09: break; - case 0x0b: throw new Exception("\"MM01\" Mapper not supported!"); - case 0x0c: throw new Exception("\"MM01\" Mapper not supported!"); - case 0x0d: throw new Exception("\"MM01\" Mapper not supported!"); + case 0x0b: throw new UnsupportedMapperException("\"MM01\" Mapper not supported!"); + case 0x0c: throw new UnsupportedMapperException("\"MM01\" Mapper not supported!"); + case 0x0d: throw new UnsupportedMapperException("\"MM01\" Mapper not supported!"); case 0x0f: break; case 0x10: break; @@ -375,9 +375,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy case 0x12: break; case 0x13: break; - case 0x15: throw new Exception("\"MBC4\" Mapper not supported!"); - case 0x16: throw new Exception("\"MBC4\" Mapper not supported!"); - case 0x17: throw new Exception("\"MBC4\" Mapper not supported!"); + case 0x15: throw new UnsupportedMapperException("\"MBC4\" Mapper not supported!"); + case 0x16: throw new UnsupportedMapperException("\"MBC4\" Mapper not supported!"); + case 0x17: throw new UnsupportedMapperException("\"MBC4\" Mapper not supported!"); case 0x19: break; case 0x1a: break; @@ -386,14 +386,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy case 0x1d: break; // rumble case 0x1e: break; // rumble - case 0x20: throw new Exception("\"MBC6\" Mapper not supported!"); - case 0x22: throw new Exception("\"MBC7\" Mapper not supported!"); + case 0x20: throw new UnsupportedMapperException("\"MBC6\" Mapper not supported!"); + case 0x22: throw new UnsupportedMapperException("\"MBC7\" Mapper not supported!"); - case 0xfc: throw new Exception("\"Pocket Camera\" Mapper not supported!"); - case 0xfd: throw new Exception("\"Bandai TAMA5\" Mapper not supported!"); - case 0xfe: throw new Exception("\"HuC3\" Mapper not supported!"); + case 0xfc: throw new UnsupportedMapperException("\"Pocket Camera\" Mapper not supported!"); + case 0xfd: throw new UnsupportedMapperException("\"Bandai TAMA5\" Mapper not supported!"); + case 0xfe: throw new UnsupportedMapperException("\"HuC3\" Mapper not supported!"); case 0xff: break; - default: throw new Exception(string.Format("Unknown mapper: {0:x2}", romdata[0x147])); + default: throw new UnsupportedMapperException(string.Format("Unknown mapper: {0:x2}", romdata[0x147])); } return; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/LibQuickNES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/LibQuickNES.cs index 8a24442114..823f57cd97 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/LibQuickNES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/LibQuickNES.cs @@ -215,15 +215,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES [DllImport(dllname, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr qn_get_mapper(IntPtr e, ref int number); - public class UnsupportedMapperException : InvalidOperationException - { - public UnsupportedMapperException(string message) - : base(message) - { - - } - } - /// /// handle "string error" as returned by some quicknes functions /// @@ -235,7 +226,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES string s = Marshal.PtrToStringAnsi(p); if (s == "Unsupported mapper" || s == "Not an iNES file") // Not worth making a new exception for the iNES error, they ultimately are the same problem { - throw new UnsupportedMapperException("Quicknes unsupported mapper"); + throw new Emulation.Common.UnsupportedMapperException("Quicknes unsupported mapper"); } else { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 8c320047f1..4cd714ae6c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -259,19 +259,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES return exePath; } - public LibsnesCore(CoreComm comm, object Settings, object SyncSettings) - { - this.Settings = (SnesSettings)Settings ?? new SnesSettings(); - this.SyncSettings = (SnesSyncSettings)SyncSettings ?? new SnesSyncSettings(); - CoreComm = comm; - - api = new LibsnesApi(GetExePath()); - api.CMD_init(); - api.ReadHook = ReadHook; - api.ExecHook = ExecHook; - api.WriteHook = WriteHook; - } - void ReadHook(uint addr) { CoreComm.MemoryCallbackSystem.CallRead(addr); @@ -327,15 +314,27 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES else return api.CMD_load_cartridge_super_game_boy(CurrLoadParams.rom_xml, CurrLoadParams.rom_data, CurrLoadParams.rom_size, CurrLoadParams.dmg_xml, CurrLoadParams.dmg_data, CurrLoadParams.dmg_size); } - public void Load(GameInfo game, byte[] romData, bool deterministicEmulation, byte[] xmlData) + public LibsnesCore(GameInfo game, byte[] romData, bool deterministicEmulation, byte[] xmlData, CoreComm comm, object Settings, object SyncSettings) { byte[] sgbRomData = null; if (game["SGB"]) { + if ((romData[0x143] & 0xc0) == 0xc0) + throw new CGBNotSupportedException(); sgbRomData = CoreComm.CoreFileProvider.GetFirmware("SNES", "Rom_SGB", true, "SGB Rom is required for SGB emulation."); game.FirmwareHash = sgbRomData.HashSHA1(); } - + + this.Settings = (SnesSettings)Settings ?? new SnesSettings(); + this.SyncSettings = (SnesSyncSettings)SyncSettings ?? new SnesSyncSettings(); + CoreComm = comm; + + api = new LibsnesApi(GetExePath()); + api.CMD_init(); + api.ReadHook = ReadHook; + api.ExecHook = ExecHook; + api.WriteHook = WriteHook; + ScanlineHookManager = new MyScanlineHookManager(this); api.CMD_init();