misc cleanups in Emulation.Common

This commit is contained in:
adelikat 2020-02-26 16:32:00 -06:00
parent 3018abe1f8
commit 13bc770063
10 changed files with 56 additions and 72 deletions

View File

@ -205,12 +205,7 @@ namespace BizHawk.Emulation.Common
} }
// Hack for things like gameboy/ti-83 as opposed to genesis with no controllers plugged in // Hack for things like gameboy/ti-83 as opposed to genesis with no controllers plugged in
if (allNames.Any(b => b.StartsWith("Up"))) return allNames.Any(b => b.StartsWith("Up")) ? 1 : 0;
{
return 1;
}
return 0;
} }
} }

View File

@ -143,7 +143,7 @@ namespace BizHawk.Emulation.Common
HasExecutes = _execs.Count > 0; HasExecutes = _execs.Count > 0;
_hasAny = HasReads || HasWrites || HasExecutes; _hasAny = HasReads || HasWrites || HasExecutes;
return (HasReads != hadReads || HasWrites != hadWrites || HasExecutes != hadExecutes); return HasReads != hadReads || HasWrites != hadWrites || HasExecutes != hadExecutes;
} }
private int RemoveInternal(MemoryCallbackDelegate action) private int RemoveInternal(MemoryCallbackDelegate action)

View File

@ -8,16 +8,16 @@ namespace BizHawk.Emulation.Common
// with it without knowing what else is connected // with it without knowing what else is connected
public static class ControllerDefinitionMerger public static class ControllerDefinitionMerger
{ {
private static string Allocate(string input, ref int plr, ref int plrnext) private static string Allocate(string input, ref int plr, ref int playerNext)
{ {
int offset = int.Parse(input.Substring(0, 1)); int offset = int.Parse(input.Substring(0, 1));
int currplr = plr + offset; int currentPlayer = plr + offset;
if (currplr >= plrnext) if (currentPlayer >= playerNext)
{ {
plrnext = currplr + 1; playerNext = currentPlayer + 1;
} }
return $"P{currplr} {input.Substring(1)}"; return $"P{currentPlayer} {input.Substring(1)}";
} }
/// <summary> /// <summary>
@ -28,27 +28,27 @@ namespace BizHawk.Emulation.Common
ControllerDefinition ret = new ControllerDefinition(); ControllerDefinition ret = new ControllerDefinition();
unmergers = new List<ControlDefUnMerger>(); unmergers = new List<ControlDefUnMerger>();
int plr = 1; int plr = 1;
int plrnext = 1; int playerNext = 1;
foreach (var def in controllers) foreach (var def in controllers)
{ {
Dictionary<string, string> remaps = new Dictionary<string, string>(); var remaps = new Dictionary<string, string>();
foreach (string s in def.BoolButtons) foreach (string s in def.BoolButtons)
{ {
string r = Allocate(s, ref plr, ref plrnext); string r = Allocate(s, ref plr, ref playerNext);
ret.BoolButtons.Add(r); ret.BoolButtons.Add(r);
remaps[s] = r; remaps[s] = r;
} }
foreach (string s in def.FloatControls) foreach (string s in def.FloatControls)
{ {
string r = Allocate(s, ref plr, ref plrnext); string r = Allocate(s, ref plr, ref playerNext);
ret.FloatControls.Add(r); ret.FloatControls.Add(r);
remaps[s] = r; remaps[s] = r;
} }
ret.FloatRanges.AddRange(def.FloatRanges); ret.FloatRanges.AddRange(def.FloatRanges);
plr = plrnext; plr = playerNext;
unmergers.Add(new ControlDefUnMerger(remaps)); unmergers.Add(new ControlDefUnMerger(remaps));
} }

View File

@ -1,4 +1,5 @@
using System.Text; using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
@ -404,16 +405,7 @@ namespace BizHawk.Emulation.Common
public byte[] SectorData { get; set; } public byte[] SectorData { get; set; }
public bool ContainsMultipleWeakSectors { get; set; } public bool ContainsMultipleWeakSectors { get; set; }
public int GetChecksum256() public int GetChecksum256() => SectorData.Sum(b => b % 256);
{
int res = 0;
foreach (var b in SectorData)
{
res += b % 256;
}
return res;
}
} }
#endregion #endregion

View File

@ -136,30 +136,28 @@ namespace BizHawk.Emulation.Common
var game = new CompactGameInfo var game = new CompactGameInfo
{ {
Hash = RemoveHashType(items[0].ToUpper()) Hash = RemoveHashType(items[0].ToUpper()),
// remove a hash type identifier. well don't really need them for indexing (they're just there for human purposes)
Status = items[1].Trim()
switch
{
"B" => RomStatus.BadDump,
"V" => RomStatus.BadDump,
"T" => RomStatus.TranslatedRom,
"O" => RomStatus.Overdump,
"I" => RomStatus.Bios,
"D" => RomStatus.Homebrew,
"H" => RomStatus.Hack,
"U" => RomStatus.Unknown,
_ => RomStatus.GoodDump
},
Name = items[2],
System = items[3],
MetaData = items.Length >= 6 ? items[5] : null,
Region = items.Length >= 7 ? items[6] : "",
ForcedCore = items.Length >= 8 ? items[7].ToLowerInvariant() : "",
}; };
// remove a hash type identifier. well don't really need them for indexing (they're just there for human purposes)
game.Status = items[1].Trim()
switch
{
"B" => RomStatus.BadDump,
"V" => RomStatus.BadDump,
"T" => RomStatus.TranslatedRom,
"O" => RomStatus.Overdump,
"I" => RomStatus.Bios,
"D" => RomStatus.Homebrew,
"H" => RomStatus.Hack,
"U" => RomStatus.Unknown,
_ => RomStatus.GoodDump
};
game.Name = items[2];
game.System = items[3];
game.MetaData = items.Length >= 6 ? items[5] : null;
game.Region = items.Length >= 7 ? items[6] : "";
game.ForcedCore = items.Length >= 8 ? items[7].ToLowerInvariant() : "";
if (DB.ContainsKey(game.Hash)) if (DB.ContainsKey(game.Hash))
{ {
Console.WriteLine("gamedb: Multiple hash entries {0}, duplicate detected on \"{1}\" and \"{2}\"", game.Hash, game.Name, DB[game.Hash].Name); Console.WriteLine("gamedb: Multiple hash entries {0}, duplicate detected on \"{1}\" and \"{2}\"", game.Hash, game.Name, DB[game.Hash].Name);

View File

@ -2,6 +2,8 @@
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable StringLiteralTypo // ReSharper disable StringLiteralTypo
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
@ -11,10 +13,10 @@ namespace BizHawk.Emulation.Common
{ {
// FDS has two OK variants (http://tcrf.net/Family_Computer_Disk_System) // FDS has two OK variants (http://tcrf.net/Family_Computer_Disk_System)
var fdsNintendo = File("57FE1BDEE955BB48D357E463CCBF129496930B62", 8192, "disksys-nintendo.rom", "Bios (Nintendo)"); var fdsNintendo = File("57FE1BDEE955BB48D357E463CCBF129496930B62", 8192, "disksys-nintendo.rom", "Bios (Nintendo)");
var fdsTwinfc = File("E4E41472C454F928E53EB10E0509BF7D1146ECC1", 8192, "disksys-nintendo.rom", "Bios (TwinFC)"); var fdsTwinFc = File("E4E41472C454F928E53EB10E0509BF7D1146ECC1", 8192, "disksys-nintendo.rom", "Bios (TwinFC)");
Firmware("NES", "Bios_FDS", "Bios"); Firmware("NES", "Bios_FDS", "Bios");
Option("NES", "Bios_FDS", fdsNintendo); Option("NES", "Bios_FDS", fdsNintendo);
Option("NES", "Bios_FDS", fdsTwinfc); Option("NES", "Bios_FDS", fdsTwinFc);
FirmwareAndOption("973E10840DB683CF3FAF61BD443090786B3A9F04", 262144, "SNES", "Rom_SGB", "sgb.sfc", "Super GameBoy Rom"); // World (Rev B) ? FirmwareAndOption("973E10840DB683CF3FAF61BD443090786B3A9F04", 262144, "SNES", "Rom_SGB", "sgb.sfc", "Super GameBoy Rom"); // World (Rev B) ?
FirmwareAndOption("A002F4EFBA42775A31185D443F3ED1790B0E949A", 3072, "SNES", "CX4", "cx4.rom", "CX4 Rom"); FirmwareAndOption("A002F4EFBA42775A31185D443F3ED1790B0E949A", 3072, "SNES", "CX4", "cx4.rom", "CX4 Rom");
@ -57,12 +59,6 @@ namespace BizHawk.Emulation.Common
FirmwareAndOption("D3B78C3DBAC55F5199F33F3FE0036439811F7FB3", 16384, "C64", "Drive1541II", "drive-1541ii.bin", "1541-II Disk Drive Rom"); FirmwareAndOption("D3B78C3DBAC55F5199F33F3FE0036439811F7FB3", 16384, "C64", "Drive1541II", "drive-1541ii.bin", "1541-II Disk Drive Rom");
// ZX Spectrum // ZX Spectrum
/* These are now shipped with bizhawk
FirmwareAndOption("5EA7C2B824672E914525D1D5C419D71B84A426A2", 16384, "ZXSpectrum", "48ROM", "48.ROM", "Spectrum 48K ROM");
FirmwareAndOption("16375D42EA109B47EDDED7A16028DE7FDB3013A1", 32768, "ZXSpectrum", "128ROM", "128.ROM", "Spectrum 128K ROM");
FirmwareAndOption("8CAFB292AF58617907B9E6B9093D3588A75849B8", 32768, "ZXSpectrum", "PLUS2ROM", "PLUS2.ROM", "Spectrum 128K +2 ROM");
FirmwareAndOption("929BF1A5E5687EBD8D7245F9B513A596C0EC21A4", 65536, "ZXSpectrum", "PLUS3ROM", "PLUS3.ROM", "Spectrum 128K +3 ROM");
*/
FirmwareAndOption("A584272F21DC82C14B7D4F1ED440E23A976E71F0", 32768, "ZXSpectrum", "PentagonROM", "pentagon.rom", "Russian Pentagon Clone ROM"); FirmwareAndOption("A584272F21DC82C14B7D4F1ED440E23A976E71F0", 32768, "ZXSpectrum", "PentagonROM", "pentagon.rom", "Russian Pentagon Clone ROM");
FirmwareAndOption("282EB7BC819AAD2A12FD954E76F7838A4E1A7929", 16384, "ZXSpectrum", "TRDOSROM", "trdos.rom", "TRDOS ROM"); FirmwareAndOption("282EB7BC819AAD2A12FD954E76F7838A4E1A7929", 16384, "ZXSpectrum", "TRDOSROM", "trdos.rom", "TRDOS ROM");
@ -350,7 +346,7 @@ namespace BizHawk.Emulation.Common
private static void FirmwareAndOption(string hash, long size, string systemId, string id, string name, string descr) private static void FirmwareAndOption(string hash, long size, string systemId, string id, string name, string descr)
{ {
Firmware(systemId, id, descr); Firmware(systemId, id, descr);
File(hash, size, name, descr, ""); File(hash, size, name, descr);
_OptionWork(hash, size, systemId, id); _OptionWork(hash, size, systemId, id);
} }
@ -381,13 +377,13 @@ namespace BizHawk.Emulation.Common
public enum FirmwareOptionStatus public enum FirmwareOptionStatus
{ {
//This is what we want you to use to get checkmarks, and for TASing // This is what we want you to use to get checkmarks, and for TASing
Ideal, Ideal,
//This will work with our core // This will work with our core
Acceptable, Acceptable,
//This is a good file, but it doesn't work with our core // This is a good file, but it doesn't work with our core
Unacceptable, Unacceptable,
//I know this is weird, you'd think the file is bad //I know this is weird, you'd think the file is bad
@ -410,13 +406,8 @@ namespace BizHawk.Emulation.Common
public static FirmwareRecord LookupFirmwareRecord(string sysId, string firmwareId) public static FirmwareRecord LookupFirmwareRecord(string sysId, string firmwareId)
{ {
var found = return FirmwareRecords
from fr in FirmwareRecords .FirstOrDefault(fr => fr.FirmwareId == firmwareId && fr.SystemId == sysId);
where fr.FirmwareId == firmwareId
&& fr.SystemId == sysId
select fr;
return found.FirstOrDefault();
} }
} // static class FirmwareDatabase } // static class FirmwareDatabase
} }

View File

@ -151,7 +151,7 @@ namespace BizHawk.Emulation.Common
public static bool MemoryCallbacksAvailable(this IEmulator core) public static bool MemoryCallbacksAvailable(this IEmulator core)
{ {
// TODO: this is a pretty ugly way to handle this // TODO: this is a pretty ugly way to handle this
var debuggable = (IDebuggable) core?.ServiceProvider.GetService<IDebuggable>(); var debuggable = core?.ServiceProvider.GetService<IDebuggable>();
if (debuggable != null) if (debuggable != null)
{ {
try try

View File

@ -1,4 +1,6 @@
namespace BizHawk.Emulation.Common using System;
namespace BizHawk.Emulation.Common
{ {
public enum SyncSoundMode public enum SyncSoundMode
{ {

View File

@ -1,6 +1,9 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// ReSharper disable UnusedMember.Local
// ReSharper disable UnusedMember.Global
// ReSharper disable IdentifierTypo
// ReSharper disable StyleCop.SA1300 // ReSharper disable StyleCop.SA1300
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
@ -22,7 +25,7 @@ namespace BizHawk.Emulation.Common
/// <summary> /// <summary>
/// quality of the resampler. values other than those listed are valid, provided they are between MIN and MAX /// quality of the resampler. values other than those listed are valid, provided they are between MIN and MAX
/// </summary> /// </summary>
public enum Quality : int public enum Quality
{ {
QUALITY_MAX = 10, QUALITY_MAX = 10,
QUALITY_MIN = 0, QUALITY_MIN = 0,

View File

@ -231,6 +231,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=bytestream/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=bytestream/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Byteswap/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Byteswap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CCITT/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=CCITT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=checkmarks/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=checksums/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=checksums/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=chromeless/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=chromeless/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Clicky/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Clicky/@EntryIndexedValue">True</s:Boolean>
@ -327,6 +328,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Letterboxing/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Letterboxing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Libretro/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Libretro/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Libsnes/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Libsnes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=libspeexdsp/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lightgun/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Lightgun/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lmsv/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Lmsv/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Loadstate/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Loadstate/@EntryIndexedValue">True</s:Boolean>
@ -404,6 +406,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=regs/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=regs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Renderers/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Renderers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resample/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resample/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Resampler/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resampling/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resampling/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resizer/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resizer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=resync/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=resync/@EntryIndexedValue">True</s:Boolean>