update some snes core internal firmware request infrastructure to use the new firmware match system. should be no actual functionality change

This commit is contained in:
goyuken 2013-12-09 21:41:18 +00:00
parent 66691bf9ab
commit 1d0db18244
4 changed files with 60 additions and 32 deletions

View File

@ -25,40 +25,52 @@ namespace BizHawk.Client.EmuHawk
MessageBox.Show(parent, msg, "Load Warning");
}
void FirmwareWarn(string sysID, string firmwareID, bool required, string msg = null)
{
if (required)
{
string fullmsg = string.Format(
"Couldn't find required firmware \"{0}:{1}\". This is fatal{2}", sysID, firmwareID, msg != null ? ": " + msg : ".");
throw new Exception(fullmsg);
}
else
{
if (msg != null)
{
string fullmsg = string.Format(
"Couldn't find firmware \"{0}:{1}\". Will attempt to continue: {2}", sysID, firmwareID, msg);
ShowMessage(msg);
}
}
}
public string GetFirmwarePath(string sysID, string firmwareID, bool required, string msg = null)
{
string path = firmware.Request(sysID, firmwareID);
if (path != null && !File.Exists(path))
path = null;
if (path == null)
FirmwareWarn(sysID, firmwareID, required, msg);
return path;
}
public byte[] GetFirmware(string sysID, string firmwareID, bool required, string msg = null)
{
byte[] ret = null;
string path = firmware.Request(sysID, firmwareID);
string path = GetFirmwarePath(sysID, firmwareID, required, msg);
if (path != null && File.Exists(path))
{
try
{
ret = File.ReadAllBytes(path);
}
catch (IOException)
{
}
catch (IOException) { }
}
if (ret == null)
{
if (required)
{
string fullmsg = string.Format(
"Couldn't find required firmware \"{0}:{1}\". This is fatal{2}", sysID, firmwareID, msg != null ? ": " + msg : ".");
throw new Exception(fullmsg);
}
else
{
if (msg != null)
{
string fullmsg = string.Format(
"Couldn't find firmware \"{0}:{1}\". Will attempt to continue: {2}", sysID, firmwareID, msg);
ShowMessage(msg);
}
}
}
if (ret == null && path != null)
FirmwareWarn(sysID, firmwareID, required, msg);
return ret;
}
}

View File

@ -3152,7 +3152,7 @@ namespace BizHawk.Client.EmuHawk
((CoreFileProvider)nextComm.CoreFileProvider).SubfileDirectory = Path.GetDirectoryName(path.Replace("|", "")); //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);
var snes = new LibsnesCore(nextComm, EmuLoadHelper);
nextEmulator = snes;
byte[] romData = isXml ? null : rom.FileData;
byte[] xmlData = isXml ? rom.FileData : null;
@ -3250,7 +3250,7 @@ namespace BizHawk.Client.EmuHawk
game.System = "SNES";
game.AddOption("SGB");
nextComm.SNES_ExePath = SNES_Prepare(Global.Config.SNESProfile);
var snes = new LibsnesCore(nextComm);
var snes = new LibsnesCore(nextComm, EmuLoadHelper);
nextEmulator = snes;
snes.Load(game, rom.FileData, EmuLoadHelper, deterministicemulation, null);
}

View File

@ -13,5 +13,6 @@ namespace BizHawk.Emulation.Common
void ShowMessage(string msg);
byte[] GetFirmware(string sysID, string firmwareID, bool required, string msg = null);
string GetFirmwarePath(string sysID, string firmwareID, bool required, string msg = null);
}
}

View File

@ -181,16 +181,29 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
return "";
}
//build romfilename
string test = Path.Combine(CoreComm.SNES_FirmwaresPath ?? "", hint);
// not MSU-1. ok.
//does it exist?
if (!File.Exists(test))
string firmwareID;
switch (hint)
{
System.Windows.Forms.MessageBox.Show("The SNES core is referencing a firmware file which could not be found. Please make sure it's in your configured SNES firmwares folder. The referenced filename is: " + hint);
return "";
case "cx4.rom": firmwareID = "CX4"; break;
case "dsp1.rom": firmwareID = "DSP1"; break;
case "dsp1b.rom": firmwareID = "DSP1b"; break;
case "dsp2.rom": firmwareID = "DSP2"; break;
case "dsp3.rom": firmwareID = "DSP3"; break;
case "dsp4.rom": firmwareID = "DSP4"; break;
case "st010.rom": firmwareID = "ST010"; break;
case "st011.rom": firmwareID = "ST011"; break;
case "st018.rom": firmwareID = "ST018"; break;
default:
EmuLoadHelper.ShowMessage(string.Format("Unrecognized SNES firmware request \"{0}\".", hint));
return "";
}
//build romfilename
string test = EmuLoadHelper.GetFirmwarePath("SNES", firmwareID, false, "Game may function incorrectly without the requested firmware.");
Console.WriteLine("Served libsnes request for firmware \"{0}\" with \"{1}\"", hint, test);
//return the path we built
@ -215,9 +228,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public LibsnesApi api;
System.Xml.XmlDocument romxml;
public LibsnesCore(CoreComm comm)
public LibsnesCore(CoreComm comm, IEmuLoadHelper EmuLoadHelper)
{
CoreComm = comm;
this.EmuLoadHelper = EmuLoadHelper;
api = new LibsnesApi(CoreComm.SNES_ExePath);
api.CMD_init();
api.ReadHook = ReadHook;
@ -916,6 +930,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
#endregion
public CoreComm CoreComm { get; private set; }
private IEmuLoadHelper EmuLoadHelper;
// ----- Client Debugging API stuff -----
unsafe MemoryDomain MakeMemoryDomain(string name, LibsnesApi.SNES_MEMORY id, MemoryDomain.Endian endian)