Misc code cleanups in Emulation.Common
This commit is contained in:
parent
a87096fb85
commit
b3dd9d26dc
|
@ -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,8 +63,10 @@ namespace BizHawk.Emulation.Common
|
|||
{
|
||||
object service;
|
||||
if (Services.TryGetValue(t, out service))
|
||||
{
|
||||
return service;
|
||||
else
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
try
|
||||
{
|
||||
var dummy = debuggableCore.GetCpuFlagsAndRegisters();
|
||||
debuggableCore.GetCpuFlagsAndRegisters();
|
||||
}
|
||||
catch (NotImplementedException)
|
||||
{
|
||||
|
|
|
@ -118,10 +118,14 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
List<string>[] ret = new List<string>[9];
|
||||
for (int i = 0; i < ret.Length; i++)
|
||||
{
|
||||
ret[i] = new List<string>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
this.Remove(action);
|
||||
Remove(action);
|
||||
}
|
||||
|
||||
var hasAny = this.Any();
|
||||
|
|
|
@ -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<IMemoryCallback> Writes = new List<IMemoryCallback>();
|
||||
private readonly List<IMemoryCallback> Execs = new List<IMemoryCallback>();
|
||||
|
||||
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<IMemoryCallback> 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,23 +171,39 @@ namespace BizHawk.Emulation.Common
|
|||
public IEnumerator<IMemoryCallback> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MemoryCallback : IMemoryCallback
|
||||
{
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
|
|||
|
||||
public static IMemoryDomains AsMemoryDomains(this IEmulator core)
|
||||
{
|
||||
return (IMemoryDomains)core.ServiceProvider.GetService<IMemoryDomains>();
|
||||
return core.ServiceProvider.GetService<IMemoryDomains>();
|
||||
}
|
||||
|
||||
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<ISaveRam>();
|
||||
return core.ServiceProvider.GetService<ISaveRam>();
|
||||
}
|
||||
|
||||
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<IStatable>();
|
||||
return core.ServiceProvider.GetService<IStatable>();
|
||||
}
|
||||
|
||||
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<IInputPollable>();
|
||||
return core.ServiceProvider.GetService<IInputPollable>();
|
||||
}
|
||||
|
||||
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<IInputPollable>();
|
||||
var pollable = core.ServiceProvider.GetService<IInputPollable>();
|
||||
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<IDriveLight>();
|
||||
return core.ServiceProvider.GetService<IDriveLight>();
|
||||
}
|
||||
|
||||
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<IDebuggable>();
|
||||
return core.ServiceProvider.GetService<IDebuggable>();
|
||||
}
|
||||
|
||||
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<ITraceable>();
|
||||
return core.ServiceProvider.GetService<ITraceable>();
|
||||
}
|
||||
|
||||
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<IDisassemblable>();
|
||||
return core.ServiceProvider.GetService<IDisassemblable>();
|
||||
}
|
||||
|
||||
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<IRegionable>();
|
||||
return core.ServiceProvider.GetService<IRegionable>();
|
||||
}
|
||||
|
||||
public static bool CanCDLog(this IEmulator core)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace BizHawk.Emulation.Common
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,10 @@ namespace BizHawk.Emulation.Common
|
|||
set
|
||||
{
|
||||
if (!AvailableCpus.Contains(value))
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
_cpu = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ namespace BizHawk.Emulation.Common
|
|||
/// <summary>
|
||||
// note that (some?) cores expect you to call SoundProvider.GetSamples() after each FrameAdvance()
|
||||
// please do this, even when rendersound = false
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
void FrameAdvance(bool render, bool rendersound = true);
|
||||
|
||||
|
|
|
@ -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
|
||||
/// </summary>
|
||||
public class FeatureNotImplemented : Attribute
|
||||
{
|
||||
public FeatureNotImplemented() { }
|
||||
}
|
||||
public class FeatureNotImplemented : Attribute { }
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
|
|
|
@ -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<TSettings, TSync> : 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)
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
/// <returns>a json-serializable object</returns>
|
||||
TSettings GetSettings();
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
/// <returns>a json-serializable object</returns>
|
||||
TSync GetSyncSettings();
|
||||
|
||||
/// <summary>
|
||||
/// change the core settings, excepting movie settings
|
||||
/// </summary>
|
||||
/// <param name="o">an object of the same type as the return for GetSettings</param>
|
||||
/// <returns>true if a core reboot will be required to make the changes effective</returns>
|
||||
bool PutSettings(TSettings o);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="o">an object of the same type as the return for GetSyncSettings</param>
|
||||
/// <returns>true if a core reboot will be required to make the changes effective</returns>
|
||||
bool PutSyncSettings(TSync o);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// serves as a shim between strongly typed ISettable and consumers
|
||||
/// </summary>
|
||||
|
@ -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<TSettings, TSync> : 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)
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
/// <returns>a json-serializable object</returns>
|
||||
TSettings GetSettings();
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
/// <returns>a json-serializable object</returns>
|
||||
TSync GetSyncSettings();
|
||||
|
||||
/// <summary>
|
||||
/// change the core settings, excepting movie settings
|
||||
/// </summary>
|
||||
/// <param name="o">an object of the same type as the return for GetSettings</param>
|
||||
/// <returns>true if a core reboot will be required to make the changes effective</returns>
|
||||
bool PutSettings(TSettings o);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="o">an object of the same type as the return for GetSyncSettings</param>
|
||||
/// <returns>true if a core reboot will be required to make the changes effective</returns>
|
||||
bool PutSyncSettings(TSync o);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue