If Quicknes throws an unsupported mapper exception, catch it and load in NesHawk instead

This commit is contained in:
adelikat 2014-05-12 00:14:45 +00:00
parent fd5c40d3f4
commit ec5414c9d8
2 changed files with 33 additions and 4 deletions

View File

@ -129,7 +129,7 @@ namespace BizHawk.Client.Common
return false;
}
public bool LoadRom(string path, CoreComm nextComm)
public bool LoadRom(string path, CoreComm nextComm, bool forceAccurateCore = false) // forceAccurateCore is currently just for Quicknes vs Neshawk but could be used for other situations
{
if (path == null)
{
@ -339,7 +339,7 @@ namespace BizHawk.Client.Common
nextEmulator = new TI83(nextComm, game, rom.RomData);
break;
case "NES":
if (!Global.Config.NES_InQuickNES)
if (!Global.Config.NES_InQuickNES || forceAccurateCore)
{
nextEmulator = new NES(
nextComm,
@ -431,8 +431,21 @@ namespace BizHawk.Client.Common
{
string system = null;
if (game != null)
{
system = game.System;
ThrowLoadError("A core accepted the rom, but throw an exception while loading it:\n\n" + ex, system);
}
// Specific hack here, as we get more cores of the same system, this isn't scalable
if (ex is LibQuickNES.UnsupportedMapperException)
{
LoadRom(path, nextComm, forceAccurateCore: true);
return true;
}
else
{
ThrowLoadError("A core accepted the rom, but throw an exception while loading it:\n\n" + ex, system);
}
return false;
}

View File

@ -224,6 +224,15 @@ 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)
{
}
}
/// <summary>
/// handle "string error" as returned by some quicknes functions
/// </summary>
@ -233,7 +242,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
if (p == IntPtr.Zero)
return;
string s = Marshal.PtrToStringAnsi(p);
throw new InvalidOperationException("LibQuickNES error: " + s);
if (s == "Unsupported mapper")
{
throw new UnsupportedMapperException("Quicknes unsupported mapper");
}
else
{
throw new InvalidOperationException("LibQuickNES error: " + s);
}
}
}
}