From b3dd9d26dc890207d995c12222e9cb1a810595ee Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 28 Feb 2016 19:03:01 -0500 Subject: [PATCH] Misc code cleanups in Emulation.Common --- .../BasicServiceProvider.cs | 11 ++- .../CallbackBasedTraceBuffer.cs | 2 +- .../ControllerDefinition.cs | 7 ++ .../InputCallbackSystem.cs | 2 +- .../MemoryCallbackSystem.cs | 46 +++++++--- .../Base Implementations/NullEmulator.cs | 38 ++++---- BizHawk.Emulation.Common/Extensions.cs | 20 ++-- .../Interfaces/ICoreFileProvider.cs | 1 - .../Interfaces/IDebuggable.cs | 7 ++ .../Interfaces/IDisassemblable.cs | 3 + .../Interfaces/IEmulator.cs | 1 - .../Interfaces/IEmulatorService.cs | 5 +- .../Interfaces/ISettable.cs | 92 +++++++++++-------- 13 files changed, 142 insertions(+), 93 deletions(-) diff --git a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs index 73a9bd9198..959108a328 100644 --- a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs +++ b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; -using System.Text; namespace BizHawk.Emulation.Common { @@ -48,7 +46,10 @@ namespace BizHawk.Emulation.Common where T : IEmulatorService { if (provider == null) + { throw new ArgumentNullException("provider"); + } + Services[typeof(T)] = provider; } @@ -62,9 +63,11 @@ namespace BizHawk.Emulation.Common { object service; if (Services.TryGetValue(t, out service)) + { return service; - else - return null; + } + + return null; } public bool HasService() diff --git a/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs b/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs index c74b98dbbb..21e044a512 100644 --- a/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs +++ b/BizHawk.Emulation.Common/Base Implementations/CallbackBasedTraceBuffer.cs @@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Common try { - var dummy = debuggableCore.GetCpuFlagsAndRegisters(); + debuggableCore.GetCpuFlagsAndRegisters(); } catch (NotImplementedException) { diff --git a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index f4d81bf2bb..40d981a9eb 100644 --- a/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -118,10 +118,14 @@ namespace BizHawk.Emulation.Common List[] ret = new List[9]; for (int i = 0; i < ret.Length; i++) + { ret[i] = new List(); + } for (int i = 0; i < list.Count; i++) + { ret[PlayerNumber(list[i])].Add(list[i]); + } return ret; } @@ -131,7 +135,10 @@ namespace BizHawk.Emulation.Common { int player = 0; if (buttonName.Length > 3 && buttonName.StartsWith("P") && char.IsNumber(buttonName[1])) + { player = buttonName[1] - '0'; + } + return player; } diff --git a/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs b/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs index e77b687c07..7f09e4d496 100644 --- a/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Base Implementations/InputCallbackSystem.cs @@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Common foreach (var action in actions) { - this.Remove(action); + Remove(action); } var hasAny = this.Any(); diff --git a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs index 9a14debc4e..768cd09447 100644 --- a/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs +++ b/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs @@ -1,8 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace BizHawk.Emulation.Common { @@ -17,11 +15,11 @@ namespace BizHawk.Emulation.Common private readonly List Writes = new List(); private readonly List Execs = new List(); - bool empty = true; + private bool _empty = true; - private bool _hasReads = false; - private bool _hasWrites = false; - private bool _hasExecutes = false; + private bool _hasReads; + private bool _hasWrites; + private bool _hasExecutes; public bool ExecuteCallbacksAvailable { get; set; } @@ -42,9 +40,13 @@ namespace BizHawk.Emulation.Common _hasWrites = true; break; } - if (empty) + + if (_empty) + { Changes(); - empty = false; + } + + _empty = false; } private static void Call(List cbs, uint addr) @@ -119,9 +121,9 @@ namespace BizHawk.Emulation.Common if (RemoveInternal(action) > 0) { bool newEmpty = !HasReads && !HasWrites && !HasExecutes; - if (newEmpty != empty) + if (newEmpty != _empty) Changes(); - empty = newEmpty; + _empty = newEmpty; } } @@ -135,9 +137,9 @@ namespace BizHawk.Emulation.Common if (changed) { bool newEmpty = !HasReads && !HasWrites && !HasExecutes; - if (newEmpty != empty) + if (newEmpty != _empty) Changes(); - empty = newEmpty; + _empty = newEmpty; } UpdateHasVariables(); @@ -148,9 +150,9 @@ namespace BizHawk.Emulation.Common Reads.Clear(); Writes.Clear(); Execs.Clear(); - if (!empty) + if (!_empty) Changes(); - empty = true; + _empty = true; UpdateHasVariables(); } @@ -169,21 +171,37 @@ namespace BizHawk.Emulation.Common public IEnumerator GetEnumerator() { foreach (var imc in Reads) + { yield return imc; + } + foreach (var imc in Writes) + { yield return imc; + } + foreach (var imc in Execs) + { yield return imc; + } } IEnumerator IEnumerable.GetEnumerator() { foreach (var imc in Reads) + { yield return imc; + } + foreach (var imc in Writes) + { yield return imc; + } + foreach (var imc in Execs) + { yield return imc; + } } } diff --git a/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs b/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs index 3e33d65aee..2d805f91fa 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs @@ -6,7 +6,7 @@ using System.ComponentModel; namespace BizHawk.Emulation.Common { - [CoreAttributes("NullHawk", "", false, true, "", "")] + [CoreAttributes("NullHawk", "", false, true)] public class NullEmulator : IEmulator, IVideoProvider, ISyncSoundProvider, ISoundProvider, ISettable { public NullEmulator(CoreComm comm, object settings) @@ -28,7 +28,7 @@ namespace BizHawk.Emulation.Common public string BoardName { get { return null; } } - bool frameBufferClear = true; + private bool frameBufferClear = true; private readonly int[] frameBuffer = new int[256 * 192]; private readonly Random rand = new Random(); public CoreComm CoreComm { get; private set; } @@ -52,6 +52,7 @@ namespace BizHawk.Emulation.Common Array.Clear(frameBuffer, 0, 256 * 192); return; } + frameBufferClear = false; if (xmas) { @@ -63,9 +64,12 @@ namespace BizHawk.Emulation.Common } else { - for (int i = 0; i < 256 * 192; i++) - frameBuffer[i] = Colors.Luminosity((byte)rand.Next()); + for (int i = 0; i < 256*192; i++) + { + frameBuffer[i] = Colors.Luminosity((byte) rand.Next()); + } } + Frame++; } public ControllerDefinition ControllerDefinition { get { return NullController; } } @@ -83,10 +87,10 @@ namespace BizHawk.Emulation.Common public void Dispose() { } - bool xmas; - Pleg pleg; + private bool xmas; + private Pleg pleg; - short[] sampbuff = new short[735 * 2]; + private short[] sampbuff = new short[735 * 2]; public void GetSamples(out short[] samples, out int nsamp) { @@ -163,11 +167,11 @@ namespace BizHawk.Emulation.Common // ms ima adpcm const string dataz = "H4sICHbdkVQCAGJlbGxzb3V0LnJhdwDtWOdz+nQYz8BZsqmrkJBAXS1JgNZZZqueo4XW8Upt63jpqPOd486X7vf6c7zxzlHQO19pgeqdq4VA62yBBOpqIQvqKknEP8PT50VeJt/k+cwAOPD//D//z390IHx4cQH/z79lQBxgVFuJECSHdxqAznFRFu1ut/wgMS2oe4ogRYBpf7er+OvaOWGNqaa2dDDKDioBfx2Elg5lAGIxI41+JRPTfHvV7m5oF/ohnPR93CQJLkobvyq+zVUj7LjXAQckbxEb2AZQDgTvYvYkpmH9fBeANfR9k7koBfxa4RiKHefflXE9AuCmKE2eSv9gRjjhY+hPDZxjAiPNQTOKX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jYT70dYWfwBeieAsfJDFe7UUNjkRC1V8NsB/vnLrL7v62HycAgn+Fd/onVnKV0I1LkxkMH8pr873aF+gPxD088tvOZvzspZjdq3Tf0u3zgqoQUsMIcFz4LONIRaShYVLNehhJTzyD71AzygeCNu0i+QDoycMQkwfwNoPjsGACAAAA=="; - readonly static int[] AdaptationTable = { 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 }; - readonly static int[] AdaptCoeff1 = { 256, 512, 0, 192, 240, 460, 392 }; - readonly static int[] AdaptCoeff2 = { 0, -256, 0, 64, 0, -208, -232 }; + private static readonly int[] AdaptationTable = { 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 }; + private static readonly int[] AdaptCoeff1 = { 256, 512, 0, 192, 240, 460, 392 }; + private static readonly int[] AdaptCoeff2 = { 0, -256, 0, 64, 0, -208, -232 }; - byte[] data; + private byte[] data; public Bell() { @@ -181,13 +185,13 @@ namespace BizHawk.Emulation.Common Next(); } - int blockpredictor; - int sample1; - int sample2; - int delta; + private int blockpredictor; + private int sample1; + private int sample2; + private int delta; - int idx = 0; - bool top = false; + private int idx = 0; + private bool top = false; private int samplectr = 0; private const int sampleloop = 15360; diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index 9b10a1500f..9826b3215d 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IMemoryDomains AsMemoryDomains(this IEmulator core) { - return (IMemoryDomains)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool HasSaveRam(this IEmulator core) @@ -45,7 +45,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static ISaveRam AsSaveRam(this IEmulator core) { - return (ISaveRam)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool HasSavestates(this IEmulator core) @@ -60,7 +60,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IStatable AsStatable(this IEmulator core) { - return (IStatable)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool CanPollInput(this IEmulator core) @@ -75,7 +75,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IInputPollable AsInputPollable(this IEmulator core) { - return (IInputPollable)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool InputCallbacksAvailable(this IEmulator core) @@ -86,7 +86,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions } // TODO: this is a pretty ugly way to handle this - var pollable = (IInputPollable)core.ServiceProvider.GetService(); + var pollable = core.ServiceProvider.GetService(); if (pollable != null) { try @@ -115,7 +115,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IDriveLight AsDriveLight(this IEmulator core) { - return (IDriveLight)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool CanDebug(this IEmulator core) @@ -130,7 +130,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IDebuggable AsDebuggable(this IEmulator core) { - return (IDebuggable)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool CpuTraceAvailable(this IEmulator core) @@ -145,7 +145,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static ITraceable AsTracer(this IEmulator core) { - return (ITraceable)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool MemoryCallbacksAvailable(this IEmulator core) @@ -203,7 +203,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IDisassemblable AsDissassembler(this IEmulator core) { - return (IDisassemblable)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool CanPoke(this MemoryDomain d) @@ -237,7 +237,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IRegionable AsRegionable(this IEmulator core) { - return (IRegionable)core.ServiceProvider.GetService(); + return core.ServiceProvider.GetService(); } public static bool CanCDLog(this IEmulator core) diff --git a/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs b/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs index 89f2bce021..a25fbfa927 100644 --- a/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs +++ b/BizHawk.Emulation.Common/Interfaces/ICoreFileProvider.cs @@ -1,5 +1,4 @@ using System; -using System.IO; namespace BizHawk.Emulation.Common { diff --git a/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs b/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs index 15504e236e..c539991bab 100644 --- a/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs +++ b/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs @@ -39,11 +39,18 @@ namespace BizHawk.Emulation.Common public RegisterValue(ulong val, byte bitSize) { if (bitSize == 64) + { Value = val; + } else if (bitSize > 64 || bitSize == 0) + { throw new System.ArgumentOutOfRangeException("bitSize", "BitSize must be in 1..64"); + } else + { Value = val & (1UL << bitSize) - 1; + } + BitSize = bitSize; } diff --git a/BizHawk.Emulation.Common/Interfaces/IDisassemblable.cs b/BizHawk.Emulation.Common/Interfaces/IDisassemblable.cs index bdd106ec90..74a2dc6f76 100644 --- a/BizHawk.Emulation.Common/Interfaces/IDisassemblable.cs +++ b/BizHawk.Emulation.Common/Interfaces/IDisassemblable.cs @@ -44,7 +44,10 @@ namespace BizHawk.Emulation.Common set { if (!AvailableCpus.Contains(value)) + { throw new ArgumentException(); + } + _cpu = value; } } diff --git a/BizHawk.Emulation.Common/Interfaces/IEmulator.cs b/BizHawk.Emulation.Common/Interfaces/IEmulator.cs index 8f0ab5e33c..1edc5ad082 100644 --- a/BizHawk.Emulation.Common/Interfaces/IEmulator.cs +++ b/BizHawk.Emulation.Common/Interfaces/IEmulator.cs @@ -39,7 +39,6 @@ namespace BizHawk.Emulation.Common /// // note that (some?) cores expect you to call SoundProvider.GetSamples() after each FrameAdvance() // please do this, even when rendersound = false - /// /// void FrameAdvance(bool render, bool rendersound = true); diff --git a/BizHawk.Emulation.Common/Interfaces/IEmulatorService.cs b/BizHawk.Emulation.Common/Interfaces/IEmulatorService.cs index 0b9dd2fc44..2cb58f1539 100644 --- a/BizHawk.Emulation.Common/Interfaces/IEmulatorService.cs +++ b/BizHawk.Emulation.Common/Interfaces/IEmulatorService.cs @@ -17,10 +17,7 @@ namespace BizHawk.Emulation.Common /// Should be added to any field of an ICoreService that is not implemented. By Convention it should also throw a NotImplementedException /// Any feature that does not have this attribute is assumed to be implemented /// - public class FeatureNotImplemented : Attribute - { - public FeatureNotImplemented() { } - } + public class FeatureNotImplemented : Attribute { } /// /// This represents a service that would not apply to every core, instead it is a specialized service specific to a core or group of cores diff --git a/BizHawk.Emulation.Common/Interfaces/ISettable.cs b/BizHawk.Emulation.Common/Interfaces/ISettable.cs index fd5304687a..79a121196a 100644 --- a/BizHawk.Emulation.Common/Interfaces/ISettable.cs +++ b/BizHawk.Emulation.Common/Interfaces/ISettable.cs @@ -1,11 +1,48 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Reflection; namespace BizHawk.Emulation.Common { + public interface ISettable : IEmulatorService + { + // in addition to these methods, it's expected that the constructor or Load() method + // will take a Settings and SyncSettings object to set the initial state of the core + // (if those are null, default settings are to be used) + + /// + /// get the current core settings, excepting movie settings. should be a clone of the active in-core object. + /// VERY IMPORTANT: changes to the object returned by this function SHOULD NOT have any effect on emulation + /// (unless the object is later passed to PutSettings) + /// + /// a json-serializable object + TSettings GetSettings(); + + /// + /// get the current core settings that affect movie sync. these go in movie 2.0 files, so don't make the JSON too extravagant, please + /// should be a clone of the active in-core object. + /// VERY IMPORTANT: changes to the object returned by this function MUST NOT have any effect on emulation + /// (unless the object is later passed to PutSyncSettings) + /// + /// a json-serializable object + TSync GetSyncSettings(); + + /// + /// change the core settings, excepting movie settings + /// + /// an object of the same type as the return for GetSettings + /// true if a core reboot will be required to make the changes effective + bool PutSettings(TSettings o); + + /// + /// changes the movie-sync relevant settings. THIS SHOULD NEVER BE CALLED WHILE RECORDING + /// if it is called while recording, the core need not guarantee continued determinism + /// + /// an object of the same type as the return for GetSyncSettings + /// true if a core reboot will be required to make the changes effective + bool PutSyncSettings(TSync o); + } + /// /// serves as a shim between strongly typed ISettable and consumers /// @@ -62,21 +99,30 @@ namespace BizHawk.Emulation.Common public object GetSettings() { if (!HasSettings) + { throw new InvalidOperationException(); + } + return gets.Invoke(emu, tmp0); } public object GetSyncSettings() { if (!HasSyncSettings) + { throw new InvalidOperationException(); + } + return (getss.Invoke(emu, tmp0)); } public bool PutSettings(object o) { if (!HasSettings) + { throw new InvalidOperationException(); + } + tmp1[0] = o; return (bool)puts.Invoke(emu, tmp1); } @@ -84,48 +130,14 @@ namespace BizHawk.Emulation.Common public bool PutSyncSettings(object o) { if (!HasSyncSettings) + { throw new InvalidOperationException(); + } + tmp1[0] = o; return (bool)putss.Invoke(emu, tmp1); } } - public interface ISettable : IEmulatorService - { - // in addition to these methods, it's expected that the constructor or Load() method - // will take a Settings and SyncSettings object to set the initial state of the core - // (if those are null, default settings are to be used) - - /// - /// get the current core settings, excepting movie settings. should be a clone of the active in-core object. - /// VERY IMPORTANT: changes to the object returned by this function SHOULD NOT have any effect on emulation - /// (unless the object is later passed to PutSettings) - /// - /// a json-serializable object - TSettings GetSettings(); - - /// - /// get the current core settings that affect movie sync. these go in movie 2.0 files, so don't make the JSON too extravagant, please - /// should be a clone of the active in-core object. - /// VERY IMPORTANT: changes to the object returned by this function MUST NOT have any effect on emulation - /// (unless the object is later passed to PutSyncSettings) - /// - /// a json-serializable object - TSync GetSyncSettings(); - - /// - /// change the core settings, excepting movie settings - /// - /// an object of the same type as the return for GetSettings - /// true if a core reboot will be required to make the changes effective - bool PutSettings(TSettings o); - - /// - /// changes the movie-sync relevant settings. THIS SHOULD NEVER BE CALLED WHILE RECORDING - /// if it is called while recording, the core need not guarantee continued determinism - /// - /// an object of the same type as the return for GetSyncSettings - /// true if a core reboot will be required to make the changes effective - bool PutSyncSettings(TSync o); - } + }