Emulation.Common - misc cleanups in Base Implementations
This commit is contained in:
parent
f0b5ee4789
commit
17fe836926
|
@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Common
|
||||||
/// <seealso cref="IEmulatorServiceProvider"/>
|
/// <seealso cref="IEmulatorServiceProvider"/>
|
||||||
public class BasicServiceProvider : IEmulatorServiceProvider
|
public class BasicServiceProvider : IEmulatorServiceProvider
|
||||||
{
|
{
|
||||||
private readonly Dictionary<Type, object> Services = new Dictionary<Type, object>();
|
private readonly Dictionary<Type, object> _services = new Dictionary<Type, object>();
|
||||||
|
|
||||||
public BasicServiceProvider(IEmulator core)
|
public BasicServiceProvider(IEmulator core)
|
||||||
{
|
{
|
||||||
|
@ -31,14 +31,14 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
foreach (Type service in services)
|
foreach (Type service in services)
|
||||||
{
|
{
|
||||||
Services.Add(service, core);
|
_services.Add(service, core);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the actual instantiated type and any types in the hierarchy
|
// add the actual instantiated type and any types in the hierarchy
|
||||||
// except for object because that would be dumb (or would it?)
|
// except for object because that would be dumb (or would it?)
|
||||||
while (coreType != typeof(object))
|
while (coreType != typeof(object))
|
||||||
{
|
{
|
||||||
Services.Add(coreType, core);
|
_services.Add(coreType, core);
|
||||||
coreType = coreType.BaseType;
|
coreType = coreType.BaseType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ namespace BizHawk.Emulation.Common
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the core can call this to register an additional service
|
/// the core can call this to register an additional service
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The <seealso cref="IEmulatorService"/> to register</typeparam>
|
||||||
public void Register<T>(T provider)
|
public void Register<T>(T provider)
|
||||||
where T : IEmulatorService
|
where T : IEmulatorService
|
||||||
{
|
{
|
||||||
|
@ -54,7 +55,7 @@ namespace BizHawk.Emulation.Common
|
||||||
throw new ArgumentNullException(nameof(provider));
|
throw new ArgumentNullException(nameof(provider));
|
||||||
}
|
}
|
||||||
|
|
||||||
Services[typeof(T)] = provider;
|
_services[typeof(T)] = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetService<T>()
|
public T GetService<T>()
|
||||||
|
@ -66,7 +67,7 @@ namespace BizHawk.Emulation.Common
|
||||||
public object GetService(Type t)
|
public object GetService(Type t)
|
||||||
{
|
{
|
||||||
object service;
|
object service;
|
||||||
if (Services.TryGetValue(t, out service))
|
if (_services.TryGetValue(t, out service))
|
||||||
{
|
{
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
@ -82,14 +83,14 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
public bool HasService(Type t)
|
public bool HasService(Type t)
|
||||||
{
|
{
|
||||||
return Services.ContainsKey(t);
|
return _services.ContainsKey(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Type> AvailableServices
|
public IEnumerable<Type> AvailableServices
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return Services.Select(d => d.Key);
|
return _services.Select(d => d.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ using BizHawk.Emulation.Common.IEmulatorExtensions;
|
||||||
namespace BizHawk.Emulation.Common
|
namespace BizHawk.Emulation.Common
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An implementation of ITraceable that is implementation using only methods
|
/// An implementation of <seealso cref="ITraceable"/> that is implementation using only methods
|
||||||
/// from IDebuggable, IMemoryDomains, and IDisassemblable
|
/// from <seealso cref="IDebuggable"/>, <seealso cref="IMemoryDomains"/>, and <seealso cref="IDisassemblable"/>
|
||||||
/// Useful for ported cores that have these hooks but no trace logging hook,
|
/// Useful for ported cores that have these hooks but no trace logging hook,
|
||||||
/// This allows for a traceable implementation without the need for additional API
|
/// This allows for a traceable implementation without the need for additional API
|
||||||
/// Note that this technique will always be significantly slower than a direct implementation
|
/// Note that this technique will always be significantly slower than a direct implementation
|
||||||
|
@ -18,7 +18,7 @@ namespace BizHawk.Emulation.Common
|
||||||
/// <seealso cref="IDisassemblable"/>
|
/// <seealso cref="IDisassemblable"/>
|
||||||
public abstract class CallbackBasedTraceBuffer : ITraceable
|
public abstract class CallbackBasedTraceBuffer : ITraceable
|
||||||
{
|
{
|
||||||
public CallbackBasedTraceBuffer(IDebuggable debuggableCore, IMemoryDomains memoryDomains, IDisassemblable disassembler)
|
protected CallbackBasedTraceBuffer(IDebuggable debuggableCore, IMemoryDomains memoryDomains, IDisassemblable disassembler)
|
||||||
{
|
{
|
||||||
if (!debuggableCore.MemoryCallbacksAvailable())
|
if (!debuggableCore.MemoryCallbacksAvailable())
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
protected readonly List<TraceInfo> Buffer = new List<TraceInfo>();
|
protected readonly List<TraceInfo> Buffer = new List<TraceInfo>();
|
||||||
|
|
||||||
public abstract void TraceFromCallback();
|
protected abstract void TraceFromCallback();
|
||||||
|
|
||||||
private ITraceSink _sink;
|
private ITraceSink _sink;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
public ITraceSink Sink
|
public ITraceSink Sink
|
||||||
{
|
{
|
||||||
get
|
private get
|
||||||
{
|
{
|
||||||
return _sink;
|
return _sink;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ namespace BizHawk.Emulation.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Header { get; set; }
|
public string Header { get; protected set; }
|
||||||
|
|
||||||
public class TracingMemoryCallback : IMemoryCallback
|
public class TracingMemoryCallback : IMemoryCallback
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,14 +22,14 @@ namespace BizHawk.Emulation.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Pin()
|
public void Pin()
|
||||||
{
|
{
|
||||||
if (Pins.Count != 0)
|
if (_pins.Count != 0)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("incremental astrological examination");
|
throw new InvalidOperationException("incremental astrological examination");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var kvp in this)
|
foreach (var kvp in this)
|
||||||
{
|
{
|
||||||
Pins[kvp.Key] = GCHandle.Alloc(kvp.Value, GCHandleType.Pinned);
|
_pins[kvp.Key] = GCHandle.Alloc(kvp.Value, GCHandleType.Pinned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ namespace BizHawk.Emulation.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Unpin()
|
public void Unpin()
|
||||||
{
|
{
|
||||||
foreach (var pin in Pins.Values)
|
foreach (var pin in _pins.Values)
|
||||||
{
|
{
|
||||||
pin.Free();
|
pin.Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pins.Clear();
|
_pins.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -51,13 +51,13 @@ namespace BizHawk.Emulation.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IntPtr GetPin(string key)
|
public IntPtr GetPin(string key)
|
||||||
{
|
{
|
||||||
return Pins[key].AddrOfPinnedObject();
|
return _pins[key].AddrOfPinnedObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pinned managed arrays
|
/// Pinned managed arrays
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly Dictionary<string, GCHandle> Pins = new Dictionary<string, GCHandle>();
|
private readonly Dictionary<string, GCHandle> _pins = new Dictionary<string, GCHandle>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the CDL is tracking a block with the given name
|
/// Whether the CDL is tracking a block with the given name
|
||||||
|
@ -146,10 +146,10 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
public void Save(Stream s)
|
public void Save(Stream s)
|
||||||
{
|
{
|
||||||
_Save(s, true);
|
SaveInternal(s, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, long> _Save(Stream s, bool forReal)
|
private Dictionary<string, long> SaveInternal(Stream s, bool forReal)
|
||||||
{
|
{
|
||||||
var ret = new Dictionary<string, long>();
|
var ret = new Dictionary<string, long>();
|
||||||
var w = new BinaryWriter(s);
|
var w = new BinaryWriter(s);
|
||||||
|
@ -184,7 +184,7 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
public Dictionary<string, long> GetBlockMap()
|
public Dictionary<string, long> GetBlockMap()
|
||||||
{
|
{
|
||||||
return _Save(new MemoryStream(), false);
|
return SaveInternal(new MemoryStream(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load(Stream s)
|
public void Load(Stream s)
|
||||||
|
|
|
@ -86,7 +86,7 @@ namespace BizHawk.Emulation.Common
|
||||||
float range = (float)constraint.Params[2];
|
float range = (float)constraint.Params[2];
|
||||||
double xval = floatButtons[xaxis];
|
double xval = floatButtons[xaxis];
|
||||||
double yval = floatButtons[yaxis];
|
double yval = floatButtons[yaxis];
|
||||||
double length = Math.Sqrt(xval * xval + yval * yval);
|
double length = Math.Sqrt((xval * xval) + (yval * yval));
|
||||||
if (length > range)
|
if (length > range)
|
||||||
{
|
{
|
||||||
double ratio = range / length;
|
double ratio = range / length;
|
||||||
|
@ -154,7 +154,7 @@ namespace BizHawk.Emulation.Common
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Puts the controls in a logical order such as by controller number,
|
/// Gets a list of controls put in a logical order such as by controller number,
|
||||||
/// This is a default implementation that should work most of the time
|
/// This is a default implementation that should work most of the time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual IEnumerable<IEnumerable<string>> ControlsOrdered
|
public virtual IEnumerable<IEnumerable<string>> ControlsOrdered
|
||||||
|
@ -170,9 +170,9 @@ namespace BizHawk.Emulation.Common
|
||||||
ret[i] = new List<string>();
|
ret[i] = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < list.Count; i++)
|
foreach (string btn in list)
|
||||||
{
|
{
|
||||||
ret[PlayerNumber(list[i])].Add(list[i]);
|
ret[PlayerNumber(btn)].Add(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace BizHawk.Emulation.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: these just happen to be all the add/remove methods the client uses, to be thorough the others should be overriden as well
|
||||||
public void RemoveAll(IEnumerable<Action> actions)
|
public void RemoveAll(IEnumerable<Action> actions)
|
||||||
{
|
{
|
||||||
var hadAny = this.Any();
|
var hadAny = this.Any();
|
||||||
|
@ -53,8 +54,6 @@ namespace BizHawk.Emulation.Common
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: these just happen to be all the add/remove methods the client uses, to be thorough the others should be overriden as well
|
|
||||||
|
|
||||||
public delegate void ActiveChangedEventHandler();
|
public delegate void ActiveChangedEventHandler();
|
||||||
public event ActiveChangedEventHandler ActiveChanged;
|
public event ActiveChangedEventHandler ActiveChanged;
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,7 @@ namespace BizHawk.Emulation.Common
|
||||||
{
|
{
|
||||||
private readonly long _spfNumerator;
|
private readonly long _spfNumerator;
|
||||||
private readonly long _spfDenominator;
|
private readonly long _spfDenominator;
|
||||||
private long _remainder = 0;
|
private long _remainder;
|
||||||
private short[] _buff = new short[0];
|
private short[] _buff = new short[0];
|
||||||
|
|
||||||
private NullSound()
|
private NullSound()
|
||||||
|
@ -32,7 +32,7 @@ namespace BizHawk.Emulation.Common
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="NullSound"/> class
|
/// Initializes a new instance of the <see cref="NullSound"/> class
|
||||||
/// that exactly matches a given framerate when in sync mode
|
/// that exactly matches a given frame rate when in sync mode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public NullSound(long fpsNum, long fpsDen)
|
public NullSound(long fpsNum, long fpsDen)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
public string Header { get; set; }
|
public string Header { get; set; }
|
||||||
|
|
||||||
public ITraceSink Sink { get; set; }
|
public ITraceSink Sink { private get; set; }
|
||||||
|
|
||||||
public bool Enabled => Sink != null;
|
public bool Enabled => Sink != null;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx64
|
||||||
Header = "M68K: PC, machine code, mnemonic, operands, registers (D0-D7, A0-A7, SR, USP), flags (XNZVC)";
|
Header = "M68K: PC, machine code, mnemonic, operands, registers (D0-D7, A0-A7, SR, USP), flags (XNZVC)";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void TraceFromCallback()
|
protected override void TraceFromCallback()
|
||||||
{
|
{
|
||||||
var regs = DebuggableCore.GetCpuFlagsAndRegisters();
|
var regs = DebuggableCore.GetCpuFlagsAndRegisters();
|
||||||
uint pc = (uint)regs["M68K PC"].Value;
|
uint pc = (uint)regs["M68K PC"].Value;
|
||||||
|
|
Loading…
Reference in New Issue