From 2b7cb1bb7d01c0acd29c955e80ef9e06c075a1e9 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 29 Oct 2019 13:59:08 -0500 Subject: [PATCH] BizHawk.Emulation.Common - cleanups -> C#6/7isms, fix some typos, variable naming, spaces to tabs --- .../BasicServiceProvider.cs | 11 +- .../Base Implementations/CodeDataLog.cs | 16 +- .../ControllerDefinition.cs | 24 +- .../MemoryCallbackSystem.cs | 12 +- .../Base Implementations/MemoryDomainImpls.cs | 23 +- .../Base Implementations/MemoryDomainList.cs | 34 +- .../Base Implementations/NullEmulator.cs | 4 +- .../Base Implementations/NullSound.cs | 2 +- .../Base Implementations/TraceBuffer.cs | 7 +- BizHawk.Emulation.Common/CoreAttribute.cs | 14 +- BizHawk.Emulation.Common/CoreComms.cs | 6 +- BizHawk.Emulation.Common/DSKIdentifier.cs | 772 +++++++++--------- BizHawk.Emulation.Common/Database/Database.cs | 50 +- .../EmulationExceptions.cs | 22 +- BizHawk.Emulation.Common/Extensions.cs | 100 +-- .../Interfaces/Services/ICycleTiming.cs | 9 +- .../Interfaces/Services/IDebuggable.cs | 4 +- .../Interfaces/Services/IDisassemblable.cs | 6 +- .../Interfaces/Services/ISaveRam.cs | 4 +- .../Interfaces/Services/ISettable.cs | 8 +- .../Properties/AssemblyInfo.cs | 1 - BizHawk.Emulation.Common/SaveController.cs | 4 +- BizHawk.Emulation.Common/ServiceAttributes.cs | 2 +- BizHawk.Emulation.Common/ServiceInjector.cs | 16 +- .../Sound/Utilities/DCFilter.cs | 47 +- .../Utilities/ISynchronizingAudioBuffer.cs | 3 +- BizHawk.Emulation.Common/SystemLookup.cs | 18 +- BizHawk.sln.DotSettings | 12 + 28 files changed, 550 insertions(+), 681 deletions(-) diff --git a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs index 3e3414dac7..52df2946eb 100644 --- a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs +++ b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs @@ -66,8 +66,7 @@ namespace BizHawk.Emulation.Common public object GetService(Type t) { - object service; - if (_services.TryGetValue(t, out service)) + if (_services.TryGetValue(t, out var service)) { return service; } @@ -86,12 +85,6 @@ namespace BizHawk.Emulation.Common return _services.ContainsKey(t); } - public IEnumerable AvailableServices - { - get - { - return _services.Select(d => d.Key); - } - } + public IEnumerable AvailableServices =>_services.Select(d => d.Key); } } diff --git a/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs b/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs index 626354c7b7..b7051b3ab7 100644 --- a/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs +++ b/BizHawk.Emulation.Common/Base Implementations/CodeDataLog.cs @@ -62,9 +62,9 @@ namespace BizHawk.Emulation.Common /// /// Whether the CDL is tracking a block with the given name /// - public bool Has(string blockname) + public bool Has(string blockName) { - return ContainsKey(blockname); + return ContainsKey(blockName); } /// @@ -121,17 +121,17 @@ namespace BizHawk.Emulation.Common foreach (var kvp in other) { - byte[] fromdata = kvp.Value; - byte[] todata = this[kvp.Key]; + byte[] fromData = kvp.Value; + byte[] toData = this[kvp.Key]; - if (fromdata.Length != todata.Length) + if (fromData.Length != toData.Length) { throw new InvalidDataException("Memory regions must be the same size!"); } - for (int i = 0; i < todata.Length; i++) + for (int i = 0; i < toData.Length; i++) { - todata[i] |= fromdata[i]; + toData[i] |= fromData[i]; } } } @@ -201,7 +201,7 @@ namespace BizHawk.Emulation.Common } else { - throw new InvalidDataException("File is not a Bizhawk CDL file!"); + throw new InvalidDataException("File is not a BizHawk CDL file!"); } int count = br.ReadInt32(); diff --git a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index f6488b134a..00fd8c1ba0 100644 --- a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -82,23 +82,23 @@ namespace BizHawk.Emulation.Common { case AxisConstraintType.Circular: { - string xaxis = constraint.Params[0] as string; - string yaxis = constraint.Params[1] as string; + string xAxis = constraint.Params[0] as string ?? ""; + string yAxis = constraint.Params[1] as string ?? ""; float range = (float)constraint.Params[2]; - if (!floatButtons.ContainsKey(xaxis)) break; - if (!floatButtons.ContainsKey(yaxis)) break; - double xval = floatButtons[xaxis]; - double yval = floatButtons[yaxis]; - double length = Math.Sqrt((xval * xval) + (yval * yval)); + if (!floatButtons.ContainsKey(xAxis)) break; + if (!floatButtons.ContainsKey(yAxis)) break; + double xVal = floatButtons[xAxis]; + double yVal = floatButtons[yAxis]; + double length = Math.Sqrt((xVal * xVal) + (yVal * yVal)); if (length > range) { double ratio = range / length; - xval *= ratio; - yval *= ratio; + xVal *= ratio; + yVal *= ratio; } - floatButtons[xaxis] = (float)xval; - floatButtons[yaxis] = (float)yval; + floatButtons[xAxis] = (float)xVal; + floatButtons[yAxis] = (float)yVal; break; } } @@ -167,7 +167,7 @@ namespace BizHawk.Emulation.Common List list = new List(FloatControls); list.AddRange(BoolButtons); - // starts with console buttons, then each plasyer's buttons individually + // starts with console buttons, then each player's buttons individually List[] ret = new List[PlayerCount + 1]; for (int i = 0; i < ret.Length; i++) { diff --git a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs index 3b984eedde..b612eb6861 100644 --- a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs @@ -70,11 +70,11 @@ namespace BizHawk.Emulation.Common private static void Call(ObservableCollection cbs, uint addr, uint value, uint flags, string scope) { - for (int i = 0; i < cbs.Count; i++) + foreach (var cb in cbs) { - if (!cbs[i].Address.HasValue || (cbs[i].Scope == scope && cbs[i].Address == (addr & cbs[i].AddressMask))) + if (!cb.Address.HasValue || (cb.Scope == scope && cb.Address == (addr & cb.AddressMask))) { - cbs[i].Callback(addr, value, flags); + cb.Callback(addr, value, flags); } } } @@ -134,17 +134,17 @@ namespace BizHawk.Emulation.Common public bool HasReadsForScope(string scope) { - return _reads.Where(e => e.Scope == scope).Any(); + return _reads.Any(e => e.Scope == scope); } public bool HasWritesForScope(string scope) { - return _writes.Where(e => e.Scope == scope).Any(); + return _writes.Any(e => e.Scope == scope); } public bool HasExecutesForScope(string scope) { - return _execs.Where(e => e.Scope == scope).Any(); + return _execs.Any(e => e.Scope == scope); } private bool UpdateHasVariables() diff --git a/BizHawk.Emulation.Common/Base Implementations/MemoryDomainImpls.cs b/BizHawk.Emulation.Common/Base Implementations/MemoryDomainImpls.cs index 6a80b62c62..d7f0f22453 100644 --- a/BizHawk.Emulation.Common/Base Implementations/MemoryDomainImpls.cs +++ b/BizHawk.Emulation.Common/Base Implementations/MemoryDomainImpls.cs @@ -5,22 +5,13 @@ namespace BizHawk.Emulation.Common { public class MemoryDomainDelegate : MemoryDomain { - private Func _peek; private Action _poke; - public Func Peek - { - get { return _peek; } - set { _peek = value; } - } + public Func Peek { get; set; } public Action Poke { - get - { - return _poke; - } - + get => _poke; set { _poke = value; @@ -30,7 +21,7 @@ namespace BizHawk.Emulation.Common public override byte PeekByte(long addr) { - return _peek(addr); + return Peek(addr); } public override void PokeByte(long addr, byte val) @@ -43,7 +34,7 @@ namespace BizHawk.Emulation.Common Name = name; EndianType = endian; Size = size; - _peek = peek; + Peek = peek; _poke = poke; Writable = poke != null; WordSize = wordSize; @@ -56,11 +47,7 @@ namespace BizHawk.Emulation.Common public byte[] Data { - get - { - return _data; - } - + get => _data; set { _data = value; diff --git a/BizHawk.Emulation.Common/Base Implementations/MemoryDomainList.cs b/BizHawk.Emulation.Common/Base Implementations/MemoryDomainList.cs index dfb67ec775..6def6abe23 100644 --- a/BizHawk.Emulation.Common/Base Implementations/MemoryDomainList.cs +++ b/BizHawk.Emulation.Common/Base Implementations/MemoryDomainList.cs @@ -24,13 +24,7 @@ namespace BizHawk.Emulation.Common { } - public MemoryDomain this[string name] - { - get - { - return this.FirstOrDefault(x => x.Name == name); - } - } + public MemoryDomain this[string name] => this.FirstOrDefault(x => x.Name == name); public MemoryDomain MainMemory { @@ -44,24 +38,10 @@ namespace BizHawk.Emulation.Common return this.First(); } - set - { - _mainMemory = value; - } + set => _mainMemory = value; } - public bool HasSystemBus - { - get - { - if (_systemBus != null) - { - return true; - } - - return this.Any(x => x.Name == "System Bus"); - } - } + public bool HasSystemBus => _systemBus != null || this.Any(x => x.Name == "System Bus"); public MemoryDomain SystemBus { @@ -82,10 +62,7 @@ namespace BizHawk.Emulation.Common return MainMemory; } - set - { - _systemBus = value; - } + set => _systemBus = value; } /// @@ -96,8 +73,7 @@ namespace BizHawk.Emulation.Common var domains = this.ToDictionary(m => m.Name); foreach (var src in other) { - MemoryDomain dst; - if (domains.TryGetValue(src.Name, out dst)) + if (domains.TryGetValue(src.Name, out var dst)) { TryMerge(dst, src, (d, s) => d.Data = s.Data); TryMerge(dst, src, (d, s) => d.Data = s.Data); diff --git a/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs b/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs index 0983f9651c..3792f583f1 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs @@ -33,7 +33,7 @@ namespace BizHawk.Emulation.Common public ControllerDefinition ControllerDefinition => NullController.Instance.Definition; - public bool FrameAdvance(IController controller, bool render, bool rendersound) + public bool FrameAdvance(IController controller, bool render, bool renderSound) { if (render == false) { @@ -249,7 +249,7 @@ namespace BizHawk.Emulation.Common var ms = new MemoryStream(); gz.CopyTo(ms); _data = ms.ToArray(); - for (int i = 0; i < 3800; i++) // compenstate for sample start point + for (int i = 0; i < 3800; i++) // compensate for sample start point { Next(); } diff --git a/BizHawk.Emulation.Common/Base Implementations/NullSound.cs b/BizHawk.Emulation.Common/Base Implementations/NullSound.cs index 27afd57ecc..1598dd5d1f 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullSound.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullSound.cs @@ -27,7 +27,7 @@ namespace BizHawk.Emulation.Common : this() { _spfNumerator = spf; - _spfDenominator = 1; + _spfDenominator = 1; } /// diff --git a/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs b/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs index 75d64f56c9..3f288cdce6 100644 --- a/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs +++ b/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs @@ -6,12 +6,7 @@ /// public class TraceBuffer : ITraceable { - public TraceBuffer() - { - Header = "Instructions"; - } - - public string Header { get; set; } + public string Header { get; set; } = "Instructions"; public ITraceSink Sink { private get; set; } diff --git a/BizHawk.Emulation.Common/CoreAttribute.cs b/BizHawk.Emulation.Common/CoreAttribute.cs index 5d6ddcc496..d0b7012fb7 100644 --- a/BizHawk.Emulation.Common/CoreAttribute.cs +++ b/BizHawk.Emulation.Common/CoreAttribute.cs @@ -23,12 +23,12 @@ namespace BizHawk.Emulation.Common SingleInstance = singleInstance; } - public string CoreName { get; private set; } - public string Author { get; private set; } - public bool Ported { get; private set; } - public bool Released { get; private set; } - public string PortedVersion { get; private set; } - public string PortedUrl { get; private set; } - public bool SingleInstance { get; private set; } + public string CoreName { get; } + public string Author { get; } + public bool Ported { get; } + public bool Released { get; } + public string PortedVersion { get; } + public string PortedUrl { get; } + public bool SingleInstance { get; } } } diff --git a/BizHawk.Emulation.Common/CoreComms.cs b/BizHawk.Emulation.Common/CoreComms.cs index 04a124cd26..9259c6b479 100644 --- a/BizHawk.Emulation.Common/CoreComms.cs +++ b/BizHawk.Emulation.Common/CoreComms.cs @@ -36,16 +36,16 @@ namespace BizHawk.Emulation.Common /// /// Gets a message to show. reasonably annoying (dialog box), shouldn't be used most of the time /// - public Action ShowMessage { get; private set; } + public Action ShowMessage { get; } /// /// Gets a message to show. less annoying (OSD message). Should be used for ignorable helpful messages /// - public Action Notify { get; private set; } + public Action Notify { get; } public Func RequestGLContext { get; set; } public Action ReleaseGLContext { get; set; } public Action ActivateGLContext { get; set; } - public Action DeactivateGLContext { get; set; } // this shouldnt be necessary.. frontend should be changing context before it does anything.. but for now.. + public Action DeactivateGLContext { get; set; } // this shouldn't be necessary.. frontend should be changing context before it does anything.. but for now.. } } diff --git a/BizHawk.Emulation.Common/DSKIdentifier.cs b/BizHawk.Emulation.Common/DSKIdentifier.cs index b40c6ffdf5..6a3e85a0a6 100644 --- a/BizHawk.Emulation.Common/DSKIdentifier.cs +++ b/BizHawk.Emulation.Common/DSKIdentifier.cs @@ -1,421 +1,417 @@ - -using System.Linq; -using System.Text; +using System.Text; namespace BizHawk.Emulation.Common { - /// - /// A slightly convoluted way of determining the required System based on a *.dsk file - /// This is here because (for probably good reason) there does not appear to be a route - /// to BizHawk.Emulation.Cores from Bizhawk.Emultion.Common - /// - public class DSKIdentifier - { - /// - /// Default fallthrough to AppleII - /// - public string IdentifiedSystem = "AppleII"; - private string PossibleIdent = ""; + /// + /// A slightly convoluted way of determining the required System based on a *.dsk file + /// This is here because (for probably good reason) there does not appear to be a route + /// to BizHawk.Emulation.Cores from BizHawk.Emulation.Common + /// + public class DSKIdentifier + { + /// + /// Default fallthrough to AppleII + /// + public string IdentifiedSystem = "AppleII"; + private string PossibleIdent = ""; - private byte[] data; - - // dsk header - public byte NumberOfTracks { get; set; } - public byte NumberOfSides { get; set; } - public int[] TrackSizes { get; set; } + private readonly byte[] data; - // state - public int CylinderCount; - public int SideCount; - public int BytesPerTrack; + // dsk header + public byte NumberOfTracks { get; set; } + public byte NumberOfSides { get; set; } + public int[] TrackSizes { get; set; } - public Track[] Tracks = null; + // state + public int CylinderCount; + public int SideCount; + public int BytesPerTrack; - public DSKIdentifier(byte[] imageData) - { - data = imageData; - ParseDskImage(); - } + public Track[] Tracks = null; - private void ParseDskImage() - { - string ident = Encoding.ASCII.GetString(data, 0, 16).ToUpper(); - if (ident.Contains("MV - CPC")) - { - ParseDSK(); - } - else if (ident.Contains("EXTENDED CPC DSK")) - { - ParseEDSK(); - } - else - { - // fall through - return; - } + public DSKIdentifier(byte[] imageData) + { + data = imageData; + ParseDskImage(); + } - CalculateFormat(); - } + private void ParseDskImage() + { + string ident = Encoding.ASCII.GetString(data, 0, 16).ToUpper(); + if (ident.Contains("MV - CPC")) + { + ParseDSK(); + } + else if (ident.Contains("EXTENDED CPC DSK")) + { + ParseEDSK(); + } + else + { + // fall through + return; + } - private void CalculateFormat() - { - // uses some of the work done here: https://github.com/damieng/DiskImageManager - var trk = Tracks[0]; + CalculateFormat(); + } - // look for standard speccy bootstart - if (trk.Sectors[0].SectorData != null && trk.Sectors[0].SectorData.Length > 0) - { - if (trk.Sectors[0].SectorData[0] == 0 && trk.Sectors[0].SectorData[1] == 0 - && trk.Sectors[0].SectorData[2] == 40) - { - PossibleIdent = "ZXSpectrum"; - } - } + private void CalculateFormat() + { + // uses some of the work done here: https://github.com/damieng/DiskImageManager + var trk = Tracks[0]; - // search for PLUS3DOS string - foreach (var t in Tracks) - { - foreach (var s in t.Sectors) - { - if (s.SectorData == null || s.SectorData.Length == 0) - continue; + // look for standard speccy bootstart + if (trk.Sectors[0].SectorData != null && trk.Sectors[0].SectorData.Length > 0) + { + if (trk.Sectors[0].SectorData[0] == 0 && trk.Sectors[0].SectorData[1] == 0 + && trk.Sectors[0].SectorData[2] == 40) + { + PossibleIdent = "ZXSpectrum"; + } + } - string str = Encoding.ASCII.GetString(s.SectorData, 0, s.SectorData.Length).ToUpper(); - if (str.Contains("PLUS3DOS")) - { - IdentifiedSystem = "ZXSpectrum"; - return; - } - } - } + // search for PLUS3DOS string + foreach (var t in Tracks) + { + foreach (var s in t.Sectors) + { + if (s.SectorData == null || s.SectorData.Length == 0) + continue; - // check for bootable status - if (trk.Sectors[0].SectorData != null && trk.Sectors[0].SectorData.Length > 0) - { - int chksm = trk.Sectors[0].GetChecksum256(); + string str = Encoding.ASCII.GetString(s.SectorData, 0, s.SectorData.Length).ToUpper(); + if (str.Contains("PLUS3DOS")) + { + IdentifiedSystem = "ZXSpectrum"; + return; + } + } + } - switch(chksm) - { - case 3: - IdentifiedSystem = "ZXSpectrum"; - return; - case 1: - case 255: - // different Amstrad PCW boot records - // just return CPC for now - IdentifiedSystem = "AmstradCPC"; - return; - } + // check for bootable status + if (trk.Sectors[0].SectorData != null && trk.Sectors[0].SectorData.Length > 0) + { + int chksm = trk.Sectors[0].GetChecksum256(); - switch(trk.GetLowestSectorID()) - { - case 65: - case 193: - IdentifiedSystem = "AmstradCPC"; - return; - } - } + switch (chksm) + { + case 3: + IdentifiedSystem = "ZXSpectrum"; + return; + case 1: + case 255: + // different Amstrad PCW boot records + // just return CPC for now + IdentifiedSystem = "AmstradCPC"; + return; + } - // at this point the disk is not standard bootable - // try format analysis - if (trk.Sectors.Length == 9 && trk.Sectors[0].SectorSize == 2) - { - switch(trk.GetLowestSectorID()) - { - case 1: - switch(trk.Sectors[0].GetChecksum256()) - { - case 3: - IdentifiedSystem = "ZXSpectrum"; - return; - case 1: - case 255: - // different Amstrad PCW checksums - // just return CPC for now - IdentifiedSystem = "AmstradCPC"; - return; - } - break; - case 65: - case 193: - IdentifiedSystem = "AmstradCPC"; - return; - } - } + switch (trk.GetLowestSectorID()) + { + case 65: + case 193: + IdentifiedSystem = "AmstradCPC"; + return; + } + } - // could be an odd format disk - switch (trk.GetLowestSectorID()) - { - case 1: - if (trk.Sectors.Length == 8) - { - // CPC IBM - IdentifiedSystem = "AmstradCPC"; - return; - } - break; - case 65: - case 193: - // possible CPC custom - PossibleIdent = "AmstradCPC"; - break; - } + // at this point the disk is not standard bootable + // try format analysis + if (trk.Sectors.Length == 9 && trk.Sectors[0].SectorSize == 2) + { + switch (trk.GetLowestSectorID()) + { + case 1: + switch (trk.Sectors[0].GetChecksum256()) + { + case 3: + IdentifiedSystem = "ZXSpectrum"; + return; + case 1: + case 255: + // different Amstrad PCW checksums + // just return CPC for now + IdentifiedSystem = "AmstradCPC"; + return; + } + break; + case 65: + case 193: + IdentifiedSystem = "AmstradCPC"; + return; + } + } - // other custom ZX Spectrum formats - if (NumberOfSides == 1 && trk.Sectors.Length == 10) - { - if (trk.Sectors[0].SectorData.Length > 10) - { - if (trk.Sectors[0].SectorData[2] == 42 && trk.Sectors[0].SectorData[8] == 12) - { - switch (trk.Sectors[0].SectorData[5]) - { - case 0: - if (trk.Sectors[1].SectorID == 8) - { - switch (Tracks[1].Sectors[0].SectorID) - { - case 7: - IdentifiedSystem = "ZXSpectrum"; - return; - default: - PossibleIdent = "ZXSpectrum"; - break; - } - } - else - { - PossibleIdent = "ZXSpectrum"; - } - break; - case 1: - if (trk.Sectors[1].SectorID == 8) - { - switch (Tracks[1].Sectors[0].SectorID) - { - case 7: - case 1: - IdentifiedSystem = "ZXSpectrum"; - return; - } - } - else - { - PossibleIdent = "ZXSpectrum"; - } - break; - } - } + // could be an odd format disk + switch (trk.GetLowestSectorID()) + { + case 1: + if (trk.Sectors.Length == 8) + { + // CPC IBM + IdentifiedSystem = "AmstradCPC"; + return; + } + break; + case 65: + case 193: + // possible CPC custom + PossibleIdent = "AmstradCPC"; + break; + } - if (trk.Sectors[0].SectorData[7] == 3 && - trk.Sectors[0].SectorData[9] == 23 && - trk.Sectors[0].SectorData[2] == 40) - { - IdentifiedSystem = "ZXSpectrum"; - return; - } - } - } + // other custom ZX Spectrum formats + if (NumberOfSides == 1 && trk.Sectors.Length == 10) + { + if (trk.Sectors[0].SectorData.Length > 10) + { + if (trk.Sectors[0].SectorData[2] == 42 && trk.Sectors[0].SectorData[8] == 12) + { + switch (trk.Sectors[0].SectorData[5]) + { + case 0: + if (trk.Sectors[1].SectorID == 8) + { + switch (Tracks[1].Sectors[0].SectorID) + { + case 7: + IdentifiedSystem = "ZXSpectrum"; + return; + default: + PossibleIdent = "ZXSpectrum"; + break; + } + } + else + { + PossibleIdent = "ZXSpectrum"; + } + break; + case 1: + if (trk.Sectors[1].SectorID == 8) + { + switch (Tracks[1].Sectors[0].SectorID) + { + case 7: + case 1: + IdentifiedSystem = "ZXSpectrum"; + return; + } + } + else + { + PossibleIdent = "ZXSpectrum"; + } + break; + } + } - // last chance. use the possible value - if (IdentifiedSystem == "AppleII" && PossibleIdent != "") - { - IdentifiedSystem = "ZXSpectrum"; - } - } + if (trk.Sectors[0].SectorData[7] == 3 && + trk.Sectors[0].SectorData[9] == 23 && + trk.Sectors[0].SectorData[2] == 40) + { + IdentifiedSystem = "ZXSpectrum"; + return; + } + } + } - private void ParseDSK() - { - NumberOfTracks = data[0x30]; - NumberOfSides = data[0x31]; - TrackSizes = new int[NumberOfTracks * NumberOfSides]; - Tracks = new Track[NumberOfTracks * NumberOfSides]; - int pos = 0x32; - for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) - { - TrackSizes[i] = (ushort)(data[pos] | data[pos + 1] << 8); - } - pos = 0x100; - for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) - { - if (TrackSizes[i] == 0) - { - Tracks[i] = new Track(); - Tracks[i].Sectors = new Sector[0]; - continue; - } - int p = pos; - Tracks[i] = new Track(); - Tracks[i].TrackIdent = Encoding.ASCII.GetString(data, p, 12); - p += 16; - Tracks[i].TrackNumber = data[p++]; - Tracks[i].SideNumber = data[p++]; - p += 2; - Tracks[i].SectorSize = data[p++]; - Tracks[i].NumberOfSectors = data[p++]; - Tracks[i].GAP3Length = data[p++]; - Tracks[i].FillerByte = data[p++]; - int dpos = pos + 0x100; - Tracks[i].Sectors = new Sector[Tracks[i].NumberOfSectors]; - for (int s = 0; s < Tracks[i].NumberOfSectors; s++) - { - Tracks[i].Sectors[s] = new Sector(); + // last chance. use the possible value + if (IdentifiedSystem == "AppleII" && PossibleIdent != "") + { + IdentifiedSystem = "ZXSpectrum"; + } + } - Tracks[i].Sectors[s].TrackNumber = data[p++]; - Tracks[i].Sectors[s].SideNumber = data[p++]; - Tracks[i].Sectors[s].SectorID = data[p++]; - Tracks[i].Sectors[s].SectorSize = data[p++]; - Tracks[i].Sectors[s].Status1 = data[p++]; - Tracks[i].Sectors[s].Status2 = data[p++]; - Tracks[i].Sectors[s].ActualDataByteLength = (ushort)(data[p] | data[p + 1] << 8); - p += 2; - if (Tracks[i].Sectors[s].SectorSize == 0) - { - Tracks[i].Sectors[s].ActualDataByteLength = TrackSizes[i]; - } - else if (Tracks[i].Sectors[s].SectorSize > 6) - { - Tracks[i].Sectors[s].ActualDataByteLength = TrackSizes[i]; - } - else if (Tracks[i].Sectors[s].SectorSize == 6) - { - Tracks[i].Sectors[s].ActualDataByteLength = 0x1800; - } - else - { - Tracks[i].Sectors[s].ActualDataByteLength = 0x80 << Tracks[i].Sectors[s].SectorSize; - } - Tracks[i].Sectors[s].SectorData = new byte[Tracks[i].Sectors[s].ActualDataByteLength]; - for (int b = 0; b < Tracks[i].Sectors[s].ActualDataByteLength; b++) - { - Tracks[i].Sectors[s].SectorData[b] = data[dpos + b]; - } - dpos += Tracks[i].Sectors[s].ActualDataByteLength; - } - pos += TrackSizes[i]; - } - } + private void ParseDSK() + { + NumberOfTracks = data[0x30]; + NumberOfSides = data[0x31]; + TrackSizes = new int[NumberOfTracks * NumberOfSides]; + Tracks = new Track[NumberOfTracks * NumberOfSides]; + int pos = 0x32; + for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) + { + TrackSizes[i] = (ushort)(data[pos] | data[pos + 1] << 8); + } + pos = 0x100; + for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) + { + if (TrackSizes[i] == 0) + { + Tracks[i] = new Track(); + Tracks[i].Sectors = new Sector[0]; + continue; + } + int p = pos; + Tracks[i] = new Track(); + Tracks[i].TrackIdent = Encoding.ASCII.GetString(data, p, 12); + p += 16; + Tracks[i].TrackNumber = data[p++]; + Tracks[i].SideNumber = data[p++]; + p += 2; + Tracks[i].SectorSize = data[p++]; + Tracks[i].NumberOfSectors = data[p++]; + Tracks[i].GAP3Length = data[p++]; + Tracks[i].FillerByte = data[p++]; + int dpos = pos + 0x100; + Tracks[i].Sectors = new Sector[Tracks[i].NumberOfSectors]; + for (int s = 0; s < Tracks[i].NumberOfSectors; s++) + { + Tracks[i].Sectors[s] = new Sector(); - private void ParseEDSK() - { - NumberOfTracks = data[0x30]; - NumberOfSides = data[0x31]; - TrackSizes = new int[NumberOfTracks * NumberOfSides]; - Tracks = new Track[NumberOfTracks * NumberOfSides]; - int pos = 0x34; - for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) - { - TrackSizes[i] = data[pos++] * 256; - } - pos = 0x100; - for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) - { - if (TrackSizes[i] == 0) - { - Tracks[i] = new Track(); - Tracks[i].Sectors = new Sector[0]; - continue; - } - int p = pos; - Tracks[i] = new Track(); - Tracks[i].TrackIdent = Encoding.ASCII.GetString(data, p, 12); - p += 16; - Tracks[i].TrackNumber = data[p++]; - Tracks[i].SideNumber = data[p++]; - Tracks[i].DataRate = data[p++]; - Tracks[i].RecordingMode = data[p++]; - Tracks[i].SectorSize = data[p++]; - Tracks[i].NumberOfSectors = data[p++]; - Tracks[i].GAP3Length = data[p++]; - Tracks[i].FillerByte = data[p++]; - int dpos = pos + 0x100; - Tracks[i].Sectors = new Sector[Tracks[i].NumberOfSectors]; - for (int s = 0; s < Tracks[i].NumberOfSectors; s++) - { - Tracks[i].Sectors[s] = new Sector(); + Tracks[i].Sectors[s].TrackNumber = data[p++]; + Tracks[i].Sectors[s].SideNumber = data[p++]; + Tracks[i].Sectors[s].SectorID = data[p++]; + Tracks[i].Sectors[s].SectorSize = data[p++]; + Tracks[i].Sectors[s].Status1 = data[p++]; + Tracks[i].Sectors[s].Status2 = data[p++]; + Tracks[i].Sectors[s].ActualDataByteLength = (ushort)(data[p] | data[p + 1] << 8); + p += 2; + if (Tracks[i].Sectors[s].SectorSize == 0) + { + Tracks[i].Sectors[s].ActualDataByteLength = TrackSizes[i]; + } + else if (Tracks[i].Sectors[s].SectorSize > 6) + { + Tracks[i].Sectors[s].ActualDataByteLength = TrackSizes[i]; + } + else if (Tracks[i].Sectors[s].SectorSize == 6) + { + Tracks[i].Sectors[s].ActualDataByteLength = 0x1800; + } + else + { + Tracks[i].Sectors[s].ActualDataByteLength = 0x80 << Tracks[i].Sectors[s].SectorSize; + } + Tracks[i].Sectors[s].SectorData = new byte[Tracks[i].Sectors[s].ActualDataByteLength]; + for (int b = 0; b < Tracks[i].Sectors[s].ActualDataByteLength; b++) + { + Tracks[i].Sectors[s].SectorData[b] = data[dpos + b]; + } + dpos += Tracks[i].Sectors[s].ActualDataByteLength; + } + pos += TrackSizes[i]; + } + } - Tracks[i].Sectors[s].TrackNumber = data[p++]; - Tracks[i].Sectors[s].SideNumber = data[p++]; - Tracks[i].Sectors[s].SectorID = data[p++]; - Tracks[i].Sectors[s].SectorSize = data[p++]; - Tracks[i].Sectors[s].Status1 = data[p++]; - Tracks[i].Sectors[s].Status2 = data[p++]; - Tracks[i].Sectors[s].ActualDataByteLength = (ushort)(data[p] | data[p + 1] << 8); - p += 2; - Tracks[i].Sectors[s].SectorData = new byte[Tracks[i].Sectors[s].ActualDataByteLength]; - for (int b = 0; b < Tracks[i].Sectors[s].ActualDataByteLength; b++) - { - Tracks[i].Sectors[s].SectorData[b] = data[dpos + b]; - } - if (Tracks[i].Sectors[s].SectorSize <= 7) - { - int specifiedSize = 0x80 << Tracks[i].Sectors[s].SectorSize; - if (specifiedSize < Tracks[i].Sectors[s].ActualDataByteLength) - { - if (Tracks[i].Sectors[s].ActualDataByteLength % specifiedSize != 0) - { - Tracks[i].Sectors[s].ContainsMultipleWeakSectors = true; - } - } - } - dpos += Tracks[i].Sectors[s].ActualDataByteLength; - } - pos += TrackSizes[i]; - } - } + private void ParseEDSK() + { + NumberOfTracks = data[0x30]; + NumberOfSides = data[0x31]; + TrackSizes = new int[NumberOfTracks * NumberOfSides]; + Tracks = new Track[NumberOfTracks * NumberOfSides]; + int pos = 0x34; + for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) + { + TrackSizes[i] = data[pos++] * 256; + } + pos = 0x100; + for (int i = 0; i < NumberOfTracks * NumberOfSides; i++) + { + if (TrackSizes[i] == 0) + { + Tracks[i] = new Track(); + Tracks[i].Sectors = new Sector[0]; + continue; + } + int p = pos; + Tracks[i] = new Track(); + Tracks[i].TrackIdent = Encoding.ASCII.GetString(data, p, 12); + p += 16; + Tracks[i].TrackNumber = data[p++]; + Tracks[i].SideNumber = data[p++]; + Tracks[i].DataRate = data[p++]; + Tracks[i].RecordingMode = data[p++]; + Tracks[i].SectorSize = data[p++]; + Tracks[i].NumberOfSectors = data[p++]; + Tracks[i].GAP3Length = data[p++]; + Tracks[i].FillerByte = data[p++]; + int dpos = pos + 0x100; + Tracks[i].Sectors = new Sector[Tracks[i].NumberOfSectors]; + for (int s = 0; s < Tracks[i].NumberOfSectors; s++) + { + Tracks[i].Sectors[s] = new Sector(); - #region Internal Classes + Tracks[i].Sectors[s].TrackNumber = data[p++]; + Tracks[i].Sectors[s].SideNumber = data[p++]; + Tracks[i].Sectors[s].SectorID = data[p++]; + Tracks[i].Sectors[s].SectorSize = data[p++]; + Tracks[i].Sectors[s].Status1 = data[p++]; + Tracks[i].Sectors[s].Status2 = data[p++]; + Tracks[i].Sectors[s].ActualDataByteLength = (ushort)(data[p] | data[p + 1] << 8); + p += 2; + Tracks[i].Sectors[s].SectorData = new byte[Tracks[i].Sectors[s].ActualDataByteLength]; + for (int b = 0; b < Tracks[i].Sectors[s].ActualDataByteLength; b++) + { + Tracks[i].Sectors[s].SectorData[b] = data[dpos + b]; + } + if (Tracks[i].Sectors[s].SectorSize <= 7) + { + int specifiedSize = 0x80 << Tracks[i].Sectors[s].SectorSize; + if (specifiedSize < Tracks[i].Sectors[s].ActualDataByteLength) + { + if (Tracks[i].Sectors[s].ActualDataByteLength % specifiedSize != 0) + { + Tracks[i].Sectors[s].ContainsMultipleWeakSectors = true; + } + } + } + dpos += Tracks[i].Sectors[s].ActualDataByteLength; + } + pos += TrackSizes[i]; + } + } - public class Track - { - public string TrackIdent { get; set; } - public byte TrackNumber { get; set; } - public byte SideNumber { get; set; } - public byte DataRate { get; set; } - public byte RecordingMode { get; set; } - public byte SectorSize { get; set; } - public byte NumberOfSectors { get; set; } - public byte GAP3Length { get; set; } - public byte FillerByte { get; set; } - public Sector[] Sectors { get; set; } + #region Internal Classes - public byte GetLowestSectorID() - { - byte res = 0xFF; - foreach (var s in Sectors) - { - if (s.SectorID < res) - res = s.SectorID; - } - return res; - } - } + public class Track + { + public string TrackIdent { get; set; } + public byte TrackNumber { get; set; } + public byte SideNumber { get; set; } + public byte DataRate { get; set; } + public byte RecordingMode { get; set; } + public byte SectorSize { get; set; } + public byte NumberOfSectors { get; set; } + public byte GAP3Length { get; set; } + public byte FillerByte { get; set; } + public Sector[] Sectors { get; set; } - public class Sector - { - public byte TrackNumber { get; set; } - public byte SideNumber { get; set; } - public byte SectorID { get; set; } - public byte SectorSize { get; set; } - public byte Status1 { get; set; } - public byte Status2 { get; set; } - public int ActualDataByteLength { get; set; } - public byte[] SectorData { get; set; } - public bool ContainsMultipleWeakSectors { get; set; } + public byte GetLowestSectorID() + { + byte res = 0xFF; + foreach (var s in Sectors) + { + if (s.SectorID < res) + res = s.SectorID; + } + return res; + } + } - public int GetChecksum256() - { - int res = 0; - for (int i = 0; i < SectorData.Length; i++) - { - res += SectorData[i] % 256; - } - return res; - } - } + public class Sector + { + public byte TrackNumber { get; set; } + public byte SideNumber { get; set; } + public byte SectorID { get; set; } + public byte SectorSize { get; set; } + public byte Status1 { get; set; } + public byte Status2 { get; set; } + public int ActualDataByteLength { get; set; } + public byte[] SectorData { get; set; } + public bool ContainsMultipleWeakSectors { get; set; } - #endregion + public int GetChecksum256() + { + int res = 0; + for (int i = 0; i < SectorData.Length; i++) + { + res += SectorData[i] % 256; + } + return res; + } + } - - } + #endregion + } } diff --git a/BizHawk.Emulation.Common/Database/Database.cs b/BizHawk.Emulation.Common/Database/Database.cs index dabf010125..efdd513bb3 100644 --- a/BizHawk.Emulation.Common/Database/Database.cs +++ b/BizHawk.Emulation.Common/Database/Database.cs @@ -117,7 +117,7 @@ namespace BizHawk.Emulation.Common var line = reader.ReadLine() ?? ""; try { - if (line.StartsWith(";")) + if (line.StartsWith(";")) { continue; // comment } @@ -140,7 +140,7 @@ namespace BizHawk.Emulation.Common Hash = RemoveHashType(items[0].ToUpper()) }; - // remove a hash type identifier. well don't really need them for indexing (theyre just there for human purposes) + // remove a hash type identifier. well don't really need them for indexing (they're just there for human purposes) switch (items[1].Trim()) { case "B": @@ -238,8 +238,8 @@ namespace BizHawk.Emulation.Common break; case ".SFC": - case ".SMC": - game.System = "SNES"; + case ".SMC": + game.System = "SNES"; break; case ".GB": @@ -299,30 +299,30 @@ namespace BizHawk.Emulation.Common case ".D64": case ".T64": case ".G64": - case ".CRT": + case ".CRT": game.System = "C64"; break; - case ".TZX": - case ".PZX": - case ".CSW": - case ".WAV": - game.System = "ZXSpectrum"; - break; + case ".TZX": + case ".PZX": + case ".CSW": + case ".WAV": + game.System = "ZXSpectrum"; + break; - case ".CDT": - game.System = "AmstradCPC"; - break; + case ".CDT": + game.System = "AmstradCPC"; + break; - case ".TAP": - byte[] head = romData.Take(8).ToArray(); - if (System.Text.Encoding.Default.GetString(head).Contains("C64-TAPE")) - game.System = "C64"; - else - game.System = "ZXSpectrum"; - break; + case ".TAP": + byte[] head = romData.Take(8).ToArray(); + if (System.Text.Encoding.Default.GetString(head).Contains("C64-TAPE")) + game.System = "C64"; + else + game.System = "ZXSpectrum"; + break; - case ".Z64": + case ".Z64": case ".V64": case ".N64": game.System = "N64"; @@ -346,9 +346,9 @@ namespace BizHawk.Emulation.Common break; case ".DSK": - var dId = new DSKIdentifier(romData); - game.System = dId.IdentifiedSystem; - break; + var dId = new DSKIdentifier(romData); + game.System = dId.IdentifiedSystem; + break; case ".PO": case ".DO": diff --git a/BizHawk.Emulation.Common/EmulationExceptions.cs b/BizHawk.Emulation.Common/EmulationExceptions.cs index e61d82bf38..585dafc742 100644 --- a/BizHawk.Emulation.Common/EmulationExceptions.cs +++ b/BizHawk.Emulation.Common/EmulationExceptions.cs @@ -20,19 +20,19 @@ namespace BizHawk.Emulation.Common } } - public class NoAvailableCoreException : Exception - { - public NoAvailableCoreException() - : base("System is currently NOT emulated") - { - } + public class NoAvailableCoreException : Exception + { + public NoAvailableCoreException() + : base("System is currently NOT emulated") + { + } - public NoAvailableCoreException(string message) - : base ($"System is currently NOT emulated: {message}") - { + public NoAvailableCoreException(string message) + : base($"System is currently NOT emulated: {message}") + { - } - } + } + } public class CGBNotSupportedException : Exception { diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index 75e9a5d69b..d732222a88 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -44,12 +44,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasSoundProvider(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static ISoundProvider AsSoundProvider(this IEmulator core) @@ -70,12 +65,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasMemoryDomains(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static IMemoryDomains AsMemoryDomains(this IEmulator core) @@ -85,12 +75,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasSaveRam(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static ISaveRam AsSaveRam(this IEmulator core) @@ -100,12 +85,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasSavestates(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static IStatable AsStatable(this IEmulator core) @@ -115,12 +95,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool CanPollInput(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static IInputPollable AsInputPollable(this IEmulator core) @@ -130,13 +105,8 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool InputCallbacksAvailable(this IEmulator core) { - if (core == null) - { - return false; - } - // TODO: this is a pretty ugly way to handle this - var pollable = core.ServiceProvider.GetService(); + var pollable = core?.ServiceProvider.GetService(); if (pollable != null) { try @@ -155,12 +125,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasDriveLight(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static IDriveLight AsDriveLight(this IEmulator core) @@ -170,12 +135,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool CanDebug(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static IDebuggable AsDebuggable(this IEmulator core) @@ -185,12 +145,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool CpuTraceAvailable(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static ITraceable AsTracer(this IEmulator core) @@ -200,13 +155,8 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool MemoryCallbacksAvailable(this IEmulator core) { - if (core == null) - { - return false; - } - // TODO: this is a pretty ugly way to handle this - var debuggable = (IDebuggable)core.ServiceProvider.GetService(); + var debuggable = (IDebuggable) core?.ServiceProvider.GetService(); if (debuggable != null) { try @@ -251,7 +201,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions return core.ServiceProvider.HasService(); } - public static IDisassemblable AsDissassembler(this IEmulator core) + public static IDisassemblable AsDisassembler(this IEmulator core) { return core.ServiceProvider.GetService(); } @@ -284,12 +234,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool CanCDLog(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static ICodeDataLogger AsCodeDataLogger(this IEmulator core) @@ -304,22 +249,12 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool UsesLinkCable(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static bool CanGenerateGameDBEntries(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static ICreateGameDBEntries AsGameDBEntryGenerator(this IEmulator core) @@ -329,12 +264,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static bool HasBoardInfo(this IEmulator core) { - if (core == null) - { - return false; - } - - return core.ServiceProvider.HasService(); + return core != null && core.ServiceProvider.HasService(); } public static IBoardInfo AsBoardInfo(this IEmulator core) diff --git a/BizHawk.Emulation.Common/Interfaces/Services/ICycleTiming.cs b/BizHawk.Emulation.Common/Interfaces/Services/ICycleTiming.cs index 5fd648e9f7..9982216981 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/ICycleTiming.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/ICycleTiming.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BizHawk.Emulation.Common +namespace BizHawk.Emulation.Common { public interface ICycleTiming { @@ -12,6 +6,7 @@ namespace BizHawk.Emulation.Common /// Total elapsed emulation time relative to /// long CycleCount { get; } + /// /// Clock Rate in hz for /// diff --git a/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs b/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs index 977ff10ae8..748d93fe90 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/IDebuggable.cs @@ -46,8 +46,8 @@ namespace BizHawk.Emulation.Common public class RegisterValue { - public ulong Value { get; private set; } - public byte BitSize { get; private set; } + public ulong Value { get; } + public byte BitSize { get; } public RegisterValue(ulong val, byte bitSize) { diff --git a/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs b/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs index a95ed0d625..378b7090e2 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs @@ -42,11 +42,7 @@ namespace BizHawk.Emulation.Common public virtual string Cpu { - get - { - return _cpu; - } - + get => _cpu; set { if (!AvailableCpus.Contains(value)) diff --git a/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs b/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs index a1e7b1e2b9..0415e61bd5 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/ISaveRam.cs @@ -22,9 +22,9 @@ /// /// Gets a value indicating whether or not SaveRAM has been modified since the last save /// TODO: This is not the best interface. What defines a "save"? I suppose a Clone(), right? at least specify that here. - /// Clone() should probably take an optionthat says whether to clear the dirty flag. + /// Clone() should probably take an option that says whether to clear the dirty flag. /// And anyway, cores might not know if they can even track a functional dirty flag -- we should convey that fact somehow - /// (reminder: do that with flags, so we dont have to change the interface 10000 times) + /// (reminder: do that with flags, so we don't have to change the interface 10000 times) /// Dirty SaveRAM can in principle be determined by the frontend in that case, but it could possibly be too slow for the file menu dropdown or other things /// bool SaveRamModified { get; } diff --git a/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs b/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs index fcfaa211dc..ec92488bf1 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/ISettable.cs @@ -71,10 +71,10 @@ namespace BizHawk.Emulation.Common else { var tt = impl.GetGenericArguments(); - var settingtype = tt[0]; - var synctype = tt[1]; - HasSettings = settingtype != typeof(object); // object is used for a placeholder where an emu doesn't have both s and ss - HasSyncSettings = synctype != typeof(object); + var settingType = tt[0]; + var syncType = tt[1]; + HasSettings = settingType != typeof(object); // object is used for a placeholder where an emu doesn't have both s and ss + HasSyncSettings = syncType != typeof(object); if (HasSettings) { diff --git a/BizHawk.Emulation.Common/Properties/AssemblyInfo.cs b/BizHawk.Emulation.Common/Properties/AssemblyInfo.cs index 454bd38dfc..35d9fed2fb 100644 --- a/BizHawk.Emulation.Common/Properties/AssemblyInfo.cs +++ b/BizHawk.Emulation.Common/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/BizHawk.Emulation.Common/SaveController.cs b/BizHawk.Emulation.Common/SaveController.cs index d54e99f62c..8db556f656 100644 --- a/BizHawk.Emulation.Common/SaveController.cs +++ b/BizHawk.Emulation.Common/SaveController.cs @@ -45,8 +45,8 @@ namespace BizHawk.Emulation.Common public void DeSerialize(BinaryReader b) { _buttons.Clear(); - int numbuttons = b.ReadInt32(); - for (int i = 0; i < numbuttons; i++) + int numButtons = b.ReadInt32(); + for (int i = 0; i < numButtons; i++) { string k = b.ReadString(); float v = b.ReadSingle(); diff --git a/BizHawk.Emulation.Common/ServiceAttributes.cs b/BizHawk.Emulation.Common/ServiceAttributes.cs index f2a5ec87ad..768539b0ae 100644 --- a/BizHawk.Emulation.Common/ServiceAttributes.cs +++ b/BizHawk.Emulation.Common/ServiceAttributes.cs @@ -28,6 +28,6 @@ namespace BizHawk.Emulation.Common NotApplicableTypes = types?.AsEnumerable() ?? Enumerable.Empty(); } - public IEnumerable NotApplicableTypes { get; private set; } + public IEnumerable NotApplicableTypes { get; } } } diff --git a/BizHawk.Emulation.Common/ServiceInjector.cs b/BizHawk.Emulation.Common/ServiceInjector.cs index 15ffb76f85..a80973a932 100644 --- a/BizHawk.Emulation.Common/ServiceInjector.cs +++ b/BizHawk.Emulation.Common/ServiceInjector.cs @@ -18,11 +18,11 @@ namespace BizHawk.Emulation.Common Type targetType = target.GetType(); object[] tmp = new object[1]; - foreach (var propinfo in + foreach (var propInfo in targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute)) .Concat(targetType.GetPropertiesWithAttrib(typeof(OptionalServiceAttribute)))) { - propinfo.GetSetMethod(true).Invoke(target, tmp); + propInfo.GetSetMethod(true).Invoke(target, tmp); } } @@ -35,21 +35,21 @@ namespace BizHawk.Emulation.Common Type targetType = target.GetType(); object[] tmp = new object[1]; - foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute))) + foreach (var propInfo in targetType.GetPropertiesWithAttrib(typeof(RequiredServiceAttribute))) { - tmp[0] = source.GetService(propinfo.PropertyType); + tmp[0] = source.GetService(propInfo.PropertyType); if (tmp[0] == null) { return false; } - propinfo.GetSetMethod(true).Invoke(target, tmp); + propInfo.GetSetMethod(true).Invoke(target, tmp); } - foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(OptionalServiceAttribute))) + foreach (var propInfo in targetType.GetPropertiesWithAttrib(typeof(OptionalServiceAttribute))) { - tmp[0] = source.GetService(propinfo.PropertyType); - propinfo.GetSetMethod(true).Invoke(target, tmp); + tmp[0] = source.GetService(propInfo.PropertyType); + propInfo.GetSetMethod(true).Invoke(target, tmp); } return true; diff --git a/BizHawk.Emulation.Common/Sound/Utilities/DCFilter.cs b/BizHawk.Emulation.Common/Sound/Utilities/DCFilter.cs index 19067916d7..0fb52e423a 100644 --- a/BizHawk.Emulation.Common/Sound/Utilities/DCFilter.cs +++ b/BizHawk.Emulation.Common/Sound/Utilities/DCFilter.cs @@ -15,44 +15,44 @@ namespace BizHawk.Emulation.Common private int _accumL; private int _accumR; - private static int DepthFromFilterwidth(int filterwidth) + private static int DepthFromFilterWidth(int filterWidth) { int ret = -2; - while (filterwidth > 0) + while (filterWidth > 0) { - filterwidth >>= 1; + filterWidth >>= 1; ret++; } return ret; } - public DCFilter(ISoundProvider input, int filterwidth) + public DCFilter(ISoundProvider input, int filterWidth) { if (input == null) { throw new ArgumentNullException(); } - if (filterwidth < 8 || filterwidth > 65536) + if (filterWidth < 8 || filterWidth > 65536) { throw new ArgumentOutOfRangeException(); } - _depth = DepthFromFilterwidth(filterwidth); + _depth = DepthFromFilterWidth(filterWidth); _soundProvider = input; } // Detached mode - public DCFilter(int filterwidth) + public DCFilter(int filterWidth) { - if (filterwidth < 8 || filterwidth > 65536) + if (filterWidth < 8 || filterWidth > 65536) { throw new ArgumentOutOfRangeException(); } - _depth = DepthFromFilterwidth(filterwidth); + _depth = DepthFromFilterWidth(filterWidth); _soundProvider = null; } @@ -67,12 +67,12 @@ namespace BizHawk.Emulation.Common PushThroughSamples(samples, samples, length); } - private void PushThroughSamples(short[] samplesin, short[] samplesout, int length) + private void PushThroughSamples(short[] samplesIn, short[] samplesOut, int length) { for (int i = 0; i < length; i += 2) { - int l = samplesin[i] << 12; - int r = samplesin[i + 1] << 12; + int l = samplesIn[i] << 12; + int r = samplesIn[i + 1] << 12; _accumL -= _accumL >> _depth; _accumR -= _accumR >> _depth; _accumL += l - _latchL; @@ -86,28 +86,28 @@ namespace BizHawk.Emulation.Common // check for clipping if (bigL > 32767) { - samplesout[i] = 32767; + samplesOut[i] = 32767; } else if (bigL < -32768) { - samplesout[i] = -32768; + samplesOut[i] = -32768; } else { - samplesout[i] = (short)bigL; + samplesOut[i] = (short)bigL; } if (bigR > 32767) { - samplesout[i + 1] = 32767; + samplesOut[i + 1] = 32767; } else if (bigR < -32768) { - samplesout[i + 1] = -32768; + samplesOut[i + 1] = -32768; } else { - samplesout[i + 1] = (short)bigR; + samplesOut[i + 1] = (short)bigR; } } } @@ -125,15 +125,12 @@ namespace BizHawk.Emulation.Common public void GetSamplesSync(out short[] samples, out int nsamp) { - short[] sampin; - int nsampin; + _soundProvider.GetSamplesSync(out var sampIn, out var nsampIn); - _soundProvider.GetSamplesSync(out sampin, out nsampin); - - short[] ret = new short[nsampin * 2]; - PushThroughSamples(sampin, ret, nsampin * 2); + short[] ret = new short[nsampIn * 2]; + PushThroughSamples(sampIn, ret, nsampIn * 2); samples = ret; - nsamp = nsampin; + nsamp = nsampIn; } public SyncSoundMode SyncMode => _soundProvider.SyncMode; diff --git a/BizHawk.Emulation.Common/Sound/Utilities/ISynchronizingAudioBuffer.cs b/BizHawk.Emulation.Common/Sound/Utilities/ISynchronizingAudioBuffer.cs index 28558763d5..06f782f64f 100644 --- a/BizHawk.Emulation.Common/Sound/Utilities/ISynchronizingAudioBuffer.cs +++ b/BizHawk.Emulation.Common/Sound/Utilities/ISynchronizingAudioBuffer.cs @@ -75,8 +75,7 @@ namespace BizHawk.Emulation.Common } done++; - short left, right; - _adjustobuf.Dequeue(out left, out right); + _adjustobuf.Dequeue(out var left, out var right); buf[ctr++] = left; buf[ctr++] = right; } diff --git a/BizHawk.Emulation.Common/SystemLookup.cs b/BizHawk.Emulation.Common/SystemLookup.cs index 88f7fe8e6c..929abce021 100644 --- a/BizHawk.Emulation.Common/SystemLookup.cs +++ b/BizHawk.Emulation.Common/SystemLookup.cs @@ -22,19 +22,19 @@ namespace BizHawk.Emulation.Common new SystemInfo { SystemId = "PSX", FullName = "Playstation" }, new SystemInfo { SystemId = "SMS", FullName = "Sega Master System" }, - new SystemInfo { SystemId = "GEN", FullName = "Sega Genesis/Megadrive" }, + new SystemInfo { SystemId = "GEN", FullName = "Sega Genesis/Mega Drive" }, new SystemInfo { SystemId = "SAT", FullName = "Sega Saturn" }, new SystemInfo { SystemId = "PCE", FullName = "PC Engine/TurboGrafx 16" }, - new SystemInfo { SystemId = "Coleco", FullName = "Colecovision" }, + new SystemInfo { SystemId = "Coleco", FullName = "ColecoVision" }, new SystemInfo { SystemId = "TI83", FullName = "TI-83 Calculator" }, new SystemInfo { SystemId = "WSWAN", FullName = "WonderSwan" }, new SystemInfo { SystemId = "C64", FullName = "Commodore 64" }, new SystemInfo { SystemId = "AppleII", FullName = "Apple II" }, - new SystemInfo { SystemId = "INTV", FullName = "Intellivision" }, - new SystemInfo { SystemId = "ZXSpectrum", FullName = "Sinclair ZX Spectrum" }, - new SystemInfo { SystemId = "AmstradCPC", FullName = "Amstrad CPC" }, + new SystemInfo { SystemId = "INTV", FullName = "IntelliVision" }, + new SystemInfo { SystemId = "ZXSpectrum", FullName = "Sinclair ZX Spectrum" }, + new SystemInfo { SystemId = "AmstradCPC", FullName = "Amstrad CPC" }, new SystemInfo { SystemId = "ChannelF", FullName = "Fairchild Channel F"}, }; @@ -43,13 +43,7 @@ namespace BizHawk.Emulation.Common get { var system = _systems.FirstOrDefault(s => s.SystemId == systemId); - - if (system != null) - { - return system; - } - - return new SystemInfo { SystemId = "Unknown", FullName = "Unknown" }; + return system ?? new SystemInfo { SystemId = "Unknown", FullName = "Unknown" }; } } diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index 9583238608..1473f6e06c 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -183,6 +183,7 @@ True True True + True True True True @@ -194,14 +195,18 @@ True True True + True True True True + True True + True True True True True + True True True True @@ -212,6 +217,7 @@ True True True + True True True True @@ -232,6 +238,7 @@ True True True + True True True True @@ -241,6 +248,9 @@ True True True + True + True + True True True True @@ -251,11 +261,13 @@ True True True + True True True True True True + True True True True