Inline remaining CFP.GetFirmware shim

This commit is contained in:
YoshiRulz 2021-07-19 09:15:05 +10:00
parent 70037ee0fc
commit 0892fb8733
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
27 changed files with 52 additions and 73 deletions

View File

@ -480,14 +480,6 @@ namespace BizHawk.Emulation.Common
public static AxisSpec With(this in AxisSpec spec, Range<int> range, int neutral) => new AxisSpec(range, neutral, spec.IsReversed, spec.Constraint);
/// <param name="msg">message to show on failure, either in an exception iff <paramref name="required"/>, or in a warning dialog otherwise</param>
/// <exception cref="MissingFirmwareException">if not found and <paramref name="required"/> is <see langword="true"/></exception>
/// <remarks>TODO inline</remarks>
public static byte[] GetFirmware(this ICoreFileProvider cfp, string sysID, string firmwareID, bool required, string msg = null)
=> required
? cfp.GetFirmwareOrThrow(new(sysID, firmwareID), msg)
: cfp.GetFirmware(new(sysID, firmwareID), msg);
public static string SystemIDToDisplayName(string sysID)
=> SystemIDDisplayNames.TryGetValue(sysID, out var dispName) ? dispName : string.Empty;
}

View File

@ -26,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Calculators
_cpu.NMICallback = NMICallback;
_cpu.MemoryCallbacks = MemoryCallbacks;
_rom = lp.Comm.CoreFileProvider.GetFirmware("TI83", "Rom", true);
_rom = lp.Comm.CoreFileProvider.GetFirmwareOrThrow(new("TI83", "Rom"));
LinkPort = new TI83LinkPort(this);
HardReset();

View File

@ -144,7 +144,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
return embeddedRom;
// Embedded ROM not found, maybe this is a peripheral ROM?
var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware("AmstradCPC", n, false)).FirstOrDefault(b => b != null && b.Length == length);
var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware(new("AmstradCPC", n))).FirstOrDefault(b => b != null && b.Length == length);
if (result == null)
{
throw new MissingFirmwareException($"At least one of these firmwares is required: {string.Join(", ", names)}");

View File

@ -31,10 +31,8 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
_disk1 = _romSet[0];
_appleIIRom = lp.Comm.CoreFileProvider.GetFirmware(
SystemId, "AppleIIe", true, "The Apple IIe BIOS firmware is required");
_diskIIRom = lp.Comm.CoreFileProvider.GetFirmware(
SystemId, "DiskII", true, "The DiskII firmware is required");
_appleIIRom = lp.Comm.CoreFileProvider.GetFirmwareOrThrow(new(SystemId, "AppleIIe"), "The Apple IIe BIOS firmware is required");
_diskIIRom = lp.Comm.CoreFileProvider.GetFirmwareOrThrow(new(SystemId, "DiskII"), "The DiskII firmware is required");
_machine = new Components(_appleIIRom, _diskIIRom);

View File

@ -241,7 +241,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private byte[] GetFirmware(int length, params string[] names)
{
var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware("C64", n, false)).FirstOrDefault(b => b != null && b.Length == length);
var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware(new("C64", n))).FirstOrDefault(b => b != null && b.Length == length);
if (result == null)
{
throw new MissingFirmwareException($"At least one of these firmwares is required: {string.Join(", ", names)}");

View File

@ -53,9 +53,9 @@ namespace BizHawk.Emulation.Cores.Computers.MSX
}
}
Bios = comm.CoreFileProvider.GetFirmware("MSX", "bios_jp", false, "BIOS Not Found, Cannot Load");
Bios = comm.CoreFileProvider.GetFirmware(new("MSX", "bios_jp"), "BIOS Not Found, Cannot Load")
?? comm.CoreFileProvider.GetFirmwareOrThrow(new("MSX", "bios_test_ext"), "BIOS Not Found, Cannot Load");
if (Bios == null) { Bios = comm.CoreFileProvider.GetFirmware("MSX", "bios_test_ext", true, "BIOS Not Found, Cannot Load"); }
//Basic = comm.CoreFileProvider.GetFirmware("MSX", "basic_test", true, "BIOS Not Found, Cannot Load");

View File

@ -208,7 +208,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
return embeddedRom;
// Embedded ROM not found, maybe this is a peripheral ROM?
var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware("ZXSpectrum", n, false)).FirstOrDefault(b => b != null && b.Length == length);
var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware(new("ZXSpectrum", n))).FirstOrDefault(b => b != null && b.Length == length);
if (result == null)
{
throw new MissingFirmwareException($"At least one of these firmwares is required: {string.Join(", ", names)}");

View File

@ -91,9 +91,9 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
_syncSettings = (A7800SyncSettings)syncSettings ?? new A7800SyncSettings();
_controllerDeck = new A7800HawkControllerDeck(_syncSettings.Port1, _syncSettings.Port2);
byte[] highscoreBios = comm.CoreFileProvider.GetFirmware("A78", "Bios_HSC", false, "Some functions may not work without the high score BIOS.");
byte[] palBios = comm.CoreFileProvider.GetFirmware("A78", "Bios_PAL", false, "The game will not run if the correct region BIOS is not available.");
byte[] ntscBios = comm.CoreFileProvider.GetFirmware("A78", "Bios_NTSC", false, "The game will not run if the correct region BIOS is not available.");
var highscoreBios = comm.CoreFileProvider.GetFirmware(new("A78", "Bios_HSC"), "Some functions may not work without the high score BIOS.");
var palBios = comm.CoreFileProvider.GetFirmware(new("A78", "Bios_PAL"), "The game will not run if the correct region BIOS is not available.");
var ntscBios = comm.CoreFileProvider.GetFirmware(new("A78", "Bios_NTSC"), "The game will not run if the correct region BIOS is not available.");
byte[] header = new byte[128];
bool is_header = false;

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
{
ServiceProvider = new BasicServiceProvider(this);
byte[] bios = comm.CoreFileProvider.GetFirmware("Lynx", "Boot", true, "Boot rom is required");
var bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("Lynx", "Boot"), "Boot rom is required");
if (bios.Length != 512)
{
throw new MissingFirmwareException("Lynx Bootrom must be 512 bytes!");

View File

@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
ser.Register<IStatable>(new StateSerializer(SyncState));
// TODO: hack to allow bios-less operation would be nice, no idea if its feasible
_biosRom = comm.CoreFileProvider.GetFirmware("Coleco", "Bios", true, "Coleco BIOS file is required.");
_biosRom = comm.CoreFileProvider.GetFirmwareOrThrow(new("Coleco", "Bios"), "Coleco BIOS file is required.");
// gamedb can overwrite the SyncSettings; this is ok
if (game["NoSkip"])

View File

@ -27,8 +27,8 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF
_tracer = new TraceBuffer { Header = CPU.TraceHeader };
byte[] bios01 = comm.CoreFileProvider.GetFirmware("ChannelF", "ChannelF_sl131253", true);
byte[] bios02 = comm.CoreFileProvider.GetFirmware("ChannelF", "ChannelF_sl131254", true);
var bios01 = comm.CoreFileProvider.GetFirmwareOrThrow(new("ChannelF", "ChannelF_sl131253"));
var bios02 = comm.CoreFileProvider.GetFirmwareOrThrow(new("ChannelF", "ChannelF_sl131254"));
BIOS01 = bios01;
BIOS02 = bios02;

View File

@ -49,14 +49,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
_syncSettings = (VectrexSyncSettings)syncSettings ?? new VectrexSyncSettings();
_controllerDeck = new VectrexHawkControllerDeck(_syncSettings.Port1, _syncSettings.Port2);
byte[] Bios = null;
byte[] Mine = null;
Bios = comm.CoreFileProvider.GetFirmware("VEC", "Bios", true, "BIOS Not Found, Cannot Load");
_bios = Bios;
Mine = comm.CoreFileProvider.GetFirmware("VEC", "Minestorm", true, "Minestorm Not Found, Cannot Load");
minestorm = Mine;
/*var Bios =*/ _bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("VEC", "Bios"), "BIOS Not Found, Cannot Load");
/*var Mine =*/ minestorm = comm.CoreFileProvider.GetFirmwareOrThrow(new("VEC", "Minestorm"), "Minestorm Not Found, Cannot Load");
Console.WriteLine("SHA1:" + rom.HashSHA1(0, rom.Length));

View File

@ -55,8 +55,8 @@ namespace BizHawk.Emulation.Cores.Intellivision
Connect();
LoadExecutiveRom(comm.CoreFileProvider.GetFirmware("INTV", "EROM", true, "Executive ROM is required."));
LoadGraphicsRom(comm.CoreFileProvider.GetFirmware("INTV", "GROM", true, "Graphics ROM is required."));
LoadExecutiveRom(comm.CoreFileProvider.GetFirmwareOrThrow(new("INTV", "EROM"), "Executive ROM is required."));
LoadGraphicsRom(comm.CoreFileProvider.GetFirmwareOrThrow(new("INTV", "GROM"), "Graphics ROM is required."));
_tracer = new TraceBuffer { Header = _cpu.TraceHeader };
ser.Register<ITraceable>(_tracer);

View File

@ -63,17 +63,8 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
_controllerDeck = new O2HawkControllerDeck("O2 Controller", "O2 Controller", is_G7400);
if (is_G7400)
{
_bios = comm.CoreFileProvider.GetFirmware("O2", "BIOS-G7400", true, "BIOS Not Found, Cannot Load")
?? throw new MissingFirmwareException("Missing G7400 Bios");
}
else
{
_bios = comm.CoreFileProvider.GetFirmware("O2", "BIOS-O2", true, "BIOS Not Found, Cannot Load")
?? throw new MissingFirmwareException("Missing Odyssey2 Bios");
}
_bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("O2", is_G7400 ? "BIOS-G7400" : "BIOS-O2"), "BIOS Not Found, Cannot Load");
Buffer.BlockCopy(rom, 0x100, header, 0, 0x50);
Console.WriteLine("MD5: " + rom.HashMD5(0, rom.Length));

View File

@ -44,9 +44,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
throw new CGBNotSupportedException();
}
sgbRomData = _syncSettings.UseSGB2
? CoreComm.CoreFileProvider.GetFirmware("SNES", "Rom_SGB2", true, "SGB2 Rom is required for SGB2 emulation.")
: CoreComm.CoreFileProvider.GetFirmware("SNES", "Rom_SGB", true, "SGB1 Rom is required for SGB1 emulation.");
sgbRomData = _syncSettings.UseSGB2
? CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("SNES", "Rom_SGB2"), "SGB2 Rom is required for SGB2 emulation.")
: CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("SNES", "Rom_SGB"), "SGB1 Rom is required for SGB1 emulation.");
game.FirmwareHash = sgbRomData.HashSHA1();
}
@ -241,7 +241,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES
}
string ret = "";
var data = CoreComm.CoreFileProvider.GetFirmware(firmwareSystem, firmwareId, required, "Game may function incorrectly without the requested firmware.");
FirmwareID fwid = new(firmwareSystem, firmwareId);
const string MISSING_FIRMWARE_MSG = "Game may function incorrectly without the requested firmware.";
var data = required
? CoreComm.CoreFileProvider.GetFirmwareOrThrow(fwid, MISSING_FIRMWARE_MSG)
: CoreComm.CoreFileProvider.GetFirmware(fwid, MISSING_FIRMWARE_MSG);
if (data != null)
{
ret = hint;

View File

@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
_settings = settings ?? new Settings();
DeterministicEmulation = deterministic;
byte[] bios = comm.CoreFileProvider.GetFirmware("GBA", "Bios", false);
var bios = comm.CoreFileProvider.GetFirmware(new("GBA", "Bios"));
DeterministicEmulation &= bios != null;
if (DeterministicEmulation != deterministic)

View File

@ -134,24 +134,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{
if (game.System == "GB")
{
Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
Bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("GB", "World"), "BIOS Not Found, Cannot Load");
ppu = new GB_PPU();
}
else
{
Bios = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
Bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("GBC", "World"), "BIOS Not Found, Cannot Load");
ppu = new GBC_PPU();
is_GBC = true;
}
}
else if (_syncSettings.ConsoleMode == GBSyncSettings.ConsoleModeType.GB)
{
Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");
Bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("GB", "World"), "BIOS Not Found, Cannot Load");
ppu = new GB_PPU();
}
else
{
Bios = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");
Bios = comm.CoreFileProvider.GetFirmwareOrThrow(new("GBC", "World"), "BIOS Not Found, Cannot Load");
ppu = new GBC_PPU();
is_GBC = true;
}

View File

@ -90,7 +90,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
if (_syncSettings.EnableBIOS)
{
bios = comm.CoreFileProvider.GetFirmware(biosSystemId, biosId, true, "BIOS Not Found, Cannot Load. Change SyncSettings to run without BIOS.");
bios = comm.CoreFileProvider.GetFirmwareOrThrow(new(biosSystemId, biosId), "BIOS Not Found, Cannot Load. Change SyncSettings to run without BIOS.");
if (LibGambatte.gambatte_loadbios(GambatteState, bios, (uint)bios.Length) != 0)
{
throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_loadbios)}() returned non-zero (bios error)");

View File

@ -82,7 +82,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Gameboy
_settings = settings ?? new Settings();
var bios = _syncSettings.UseRealBIOS && !sgb
? comm.CoreFileProvider.GetFirmware(_cgb ? "GBC" : "GB", "World", true)
? comm.CoreFileProvider.GetFirmwareOrThrow(new(_cgb ? "GBC" : "GB", "World"))
: Util.DecompressGzipFile(new MemoryStream(_cgb ? Resources.SameboyCgbBoot.Value : Resources.SameboyDmgBoot.Value));
var spc = sgb

View File

@ -130,7 +130,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
byte[] fwBytes;
bool missingAny = false;
fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "bios7", false);
fwBytes = CoreComm.CoreFileProvider.GetFirmware(new("NDS", "bios7"));
if (fwBytes != null)
File.WriteAllBytes("melon/bios7.bin", fwBytes);
else
@ -139,7 +139,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
missingAny = true;
}
fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "bios9", false);
fwBytes = CoreComm.CoreFileProvider.GetFirmware(new("NDS", "bios9"));
if (fwBytes != null)
File.WriteAllBytes("melon/bios9.bin", fwBytes);
else
@ -148,7 +148,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
missingAny = true;
}
fwBytes = CoreComm.CoreFileProvider.GetFirmware("NDS", "firmware", false);
fwBytes = CoreComm.CoreFileProvider.GetFirmware(new("NDS", "firmware"));
if (fwBytes != null)
File.WriteAllBytes("melon/firmware.bin", fwBytes);
else

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
var ser = new BasicServiceProvider(this);
ServiceProvider = ser;
byte[] fdsBios = comm.CoreFileProvider.GetFirmware("NES", "Bios_FDS", false);
var fdsBios = comm.CoreFileProvider.GetFirmware(new("NES", "Bios_FDS"));
if (fdsBios != null && fdsBios.Length == 40976)
{
comm.ShowMessage("Your FDS BIOS is a bad dump. BizHawk will attempt to use it, but no guarantees! You should find a new one.");

View File

@ -54,7 +54,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
throw new CGBNotSupportedException();
}
sgbRomData = CoreComm.CoreFileProvider.GetFirmware("SNES", "Rom_SGB", true, "SGB Rom is required for SGB emulation.");
sgbRomData = CoreComm.CoreFileProvider.GetFirmwareOrThrow(new("SNES", "Rom_SGB"), "SGB Rom is required for SGB emulation.");
game.FirmwareHash = sgbRomData.HashSHA1();
}
@ -327,7 +327,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
}
string ret;
var data = CoreComm.CoreFileProvider.GetFirmware("SNES", firmwareId, false, "Game may function incorrectly without the requested firmware.");
var data = CoreComm.CoreFileProvider.GetFirmware(new("SNES", firmwareId), "Game may function incorrectly without the requested firmware.");
if (data != null)
{
ret = hint;

View File

@ -35,9 +35,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.PicoDrive
SystemId = "GEN"
})
{
var biosg = comm.CoreFileProvider.GetFirmware("32X", "G", false);
var biosm = comm.CoreFileProvider.GetFirmware("32X", "M", false);
var bioss = comm.CoreFileProvider.GetFirmware("32X", "S", false);
var biosg = comm.CoreFileProvider.GetFirmware(new("32X", "G"));
var biosm = comm.CoreFileProvider.GetFirmware(new("32X", "M"));
var bioss = comm.CoreFileProvider.GetFirmware(new("32X", "S"));
var has32xBios = biosg != null && biosm != null && bioss != null;
if (deterministic && !has32xBios)
throw new InvalidOperationException("32X BIOS files are required for deterministic mode");
@ -68,9 +68,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.PicoDrive
}
if (cd != null)
{
_exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmware("GEN", "CD_BIOS_EU", true), "cd.eu");
_exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmware("GEN", "CD_BIOS_US", true), "cd.us");
_exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmware("GEN", "CD_BIOS_JP", true), "cd.jp");
_exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmwareOrThrow(new("GEN", "CD_BIOS_EU")), "cd.eu");
_exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmwareOrThrow(new("GEN", "CD_BIOS_US")), "cd.us");
_exe.AddReadonlyFile(comm.CoreFileProvider.GetFirmwareOrThrow(new("GEN", "CD_BIOS_JP")), "cd.jp");
_exe.AddReadonlyFile(gpgx.GPGX.GetCDData(cd), "toc");
_cd = cd;
_cdReader = new DiscSectorReader(_cd);

View File

@ -161,7 +161,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
}
else if (game.System == "SMS" && !game["GG_in_SMS"])
{
BiosRom = comm.CoreFileProvider.GetFirmware("SMS", _region.ToString(), false);
BiosRom = comm.CoreFileProvider.GetFirmware(new("SMS", _region.ToString()));
if (BiosRom == null)
{

View File

@ -234,7 +234,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
if (firmwareID != null)
{
// this path will be the most common PEBKAC error, so be a bit more vocal about the problem
srcdata = CoreComm.CoreFileProvider.GetFirmware("GEN", firmwareID, false, "GPGX firmwares are usually required.");
srcdata = CoreComm.CoreFileProvider.GetFirmware(new("GEN", firmwareID), "GPGX firmwares are usually required.");
if (srcdata == null)
{
Console.WriteLine("Frontend couldn't satisfy firmware request GEN:{0}", firmwareID);

View File

@ -47,7 +47,7 @@ namespace BizHawk.Emulation.Cores.Sony.PS2
SkipMemoryConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck),
}, new[] { _cdCallback });
var bios = lp.Comm.CoreFileProvider.GetFirmware("PS2", "BIOS", true);
var bios = lp.Comm.CoreFileProvider.GetFirmwareOrThrow(new("PS2", "BIOS"));
_exe.AddReadonlyFile(new byte[0x840000], "MEMCARD0");
var worked = _core.Initialize(bios,

View File

@ -182,7 +182,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
}
//TODO - known bad firmwares are a no-go. we should refuse to boot them. (that's the mednafen policy)
byte[] firmware = comm.CoreFileProvider.GetFirmware("PSX", firmwareRegion, true, "A PSX `" + firmwareRegion + "` region bios file is required");
var firmware = comm.CoreFileProvider.GetFirmwareOrThrow(new("PSX", firmwareRegion), $"A PSX `{firmwareRegion}` region bios file is required");
//create the instance
fixed (byte* pFirmware = firmware)