MemoryCallbacks - Change "domain" to "scope"

This commit is contained in:
adelikat 2017-08-03 20:03:40 -05:00
parent cd289c474e
commit 56859e9581
4 changed files with 42 additions and 36 deletions

View File

@ -9,9 +9,9 @@ namespace BizHawk.Client.EmuHawk
{
public Action Callback { get; set; }
public void Add(IDebuggable core, string domain, uint address, uint mask, MemoryCallbackType type)
public void Add(IDebuggable core, string scope, uint address, uint mask, MemoryCallbackType type)
{
Add(new Breakpoint(core, domain, Callback, address, mask, type));
Add(new Breakpoint(core, scope, Callback, address, mask, type));
}
public new void Clear()
@ -69,9 +69,9 @@ namespace BizHawk.Client.EmuHawk
private bool _active;
private readonly IDebuggable _core;
public Breakpoint(bool readOnly, IDebuggable core, string domain, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
public Breakpoint(bool readOnly, IDebuggable core, string scope, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{
Domain = domain;
Scope = scope;
_core = core;
Type = type;
Callback = callBack;
@ -83,9 +83,9 @@ namespace BizHawk.Client.EmuHawk
ReadOnly = readOnly;
}
public Breakpoint(IDebuggable core, string domain, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
public Breakpoint(IDebuggable core, string scope, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{
Domain = domain;
Scope = scope;
_core = core;
Type = type;
Callback = callBack;
@ -96,9 +96,9 @@ namespace BizHawk.Client.EmuHawk
Active = enabled;
}
public Breakpoint(string name, bool readOnly, IDebuggable core, string domain, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
public Breakpoint(string name, bool readOnly, IDebuggable core, string scope, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{
Domain = domain;
Scope = scope;
_core = core;
Type = type;
Callback = callBack;
@ -110,7 +110,7 @@ namespace BizHawk.Client.EmuHawk
ReadOnly = readOnly;
}
public string Domain { get; }
public string Scope { get; }
public Action Callback { get; }
public uint? Address { get; set; }
public uint? AddressMask { get; set; }
@ -163,7 +163,7 @@ namespace BizHawk.Client.EmuHawk
private void AddCallback()
{
_core.MemoryCallbacks.Add(new MemoryCallback(Domain, Type, Name, Callback, Address, AddressMask));
_core.MemoryCallbacks.Add(new MemoryCallback(Scope, Type, Name, Callback, Address, AddressMask));
}
private void RemoveCallback()

View File

@ -95,7 +95,7 @@ namespace BizHawk.Emulation.Common
public uint? AddressMask => null;
public string Domain => ""; // This will be relevant if/when the trace logger can trace anything other than the system bus
public string Scope => ""; // This will be relevant if/when the trace logger can trace anything other than the system bus
}
}
}

View File

@ -14,14 +14,14 @@ namespace BizHawk.Emulation.Common
/// <seealso cref="IMemoryCallbackSystem" />
public class MemoryCallbackSystem : IMemoryCallbackSystem
{
public MemoryCallbackSystem(string[] availableDomains)
public MemoryCallbackSystem(string[] availableScopes)
{
if (availableDomains == null)
if (availableScopes == null)
{
availableDomains = new[] { "System Bus" };
availableScopes = new[] { "System Bus" };
}
AvailableDomains = availableDomains;
AvailableScopes = availableScopes;
ExecuteCallbacksAvailable = true;
_reads.CollectionChanged += OnCollectionChanged;
@ -41,13 +41,13 @@ namespace BizHawk.Emulation.Common
public bool ExecuteCallbacksAvailable { get; }
public string[] AvailableDomains { get; }
public string[] AvailableScopes { get; }
public void Add(IMemoryCallback callback)
{
if (!AvailableDomains.Contains(callback.Domain))
if (!AvailableScopes.Contains(callback.Scope))
{
throw new InvalidOperationException($"{callback.Domain} is not currently supported for callbacks");
throw new InvalidOperationException($"{callback.Scope} is not currently supported for callbacks");
}
switch (callback.Type)
@ -74,38 +74,38 @@ namespace BizHawk.Emulation.Common
_empty = false;
}
private static void Call(ObservableCollection<IMemoryCallback> cbs, uint addr, string domain)
private static void Call(ObservableCollection<IMemoryCallback> cbs, uint addr, string scope)
{
for (int i = 0; i < cbs.Count; i++)
{
if (!cbs[i].Address.HasValue || (cbs[i].Domain == domain && cbs[i].Address == (addr & cbs[i].AddressMask)))
if (!cbs[i].Address.HasValue || (cbs[i].Scope == scope && cbs[i].Address == (addr & cbs[i].AddressMask)))
{
cbs[i].Callback();
}
}
}
public void CallReads(uint addr, string domain)
public void CallReads(uint addr, string scope)
{
if (_hasReads)
{
Call(_reads, addr, domain);
Call(_reads, addr, scope);
}
}
public void CallWrites(uint addr, string domain)
public void CallWrites(uint addr, string scope)
{
if (_hasWrites)
{
Call(_writes, addr, domain);
Call(_writes, addr, scope);
}
}
public void CallExecutes(uint addr, string domain)
public void CallExecutes(uint addr, string scope)
{
if (_hasExecutes)
{
Call(_execs, addr, domain);
Call(_execs, addr, scope);
}
}
@ -286,7 +286,7 @@ namespace BizHawk.Emulation.Common
public class MemoryCallback : IMemoryCallback
{
public MemoryCallback(string domain, MemoryCallbackType type, string name, Action callback, uint? address, uint? mask)
public MemoryCallback(string scope, MemoryCallbackType type, string name, Action callback, uint? address, uint? mask)
{
if (type == MemoryCallbackType.Execute && !address.HasValue)
{
@ -298,7 +298,7 @@ namespace BizHawk.Emulation.Common
Callback = callback;
Address = address;
AddressMask = mask ?? 0xFFFFFFFF;
Domain = domain;
Scope = scope;
}
public MemoryCallbackType Type { get; }
@ -306,6 +306,6 @@ namespace BizHawk.Emulation.Common
public Action Callback { get; }
public uint? Address { get; }
public uint? AddressMask { get; }
public string Domain { get; }
public string Scope { get; }
}
}

View File

@ -42,23 +42,29 @@ namespace BizHawk.Emulation.Common
/// If no address is specified the callback will be hooked to all addresses
/// Note: an execute callback can not be added without an address, else an InvalidOperationException will occur
/// </summary>
/// <exception cref="InvalidCastException">Thrown when the <see cref="IMemoryCallback.Domain"/> property of the <see cref="IMemoryCallback"/> is not in the <see cref="AvailableDomains"/></exception>
/// <exception cref="InvalidCastException">Thrown when the <see cref="IMemoryCallback.Scope"/> property of the <see cref="IMemoryCallback"/> is not in the <see cref="AvailableScopes"/></exception>
void Add(IMemoryCallback callback);
/// <summary>
/// Executes all Read callbacks for the given address and domain
/// </summary>
void CallReads(uint addr, string domain);
/// <param name="addr">The address to check for callbacks</param>
/// <param name="scope">The scope that the address pertains to. Must be a value in <see cref="AvailableScopes"></param>
void CallReads(uint addr, string scope);
/// <summary>
/// Executes all Write callbacks for the given address and domain
/// </summary>
void CallWrites(uint addr, string domain);
/// <param name="addr">The address to check for callbacks</param>
/// <param name="scope">The scope that the address pertains to. Must be a value in <see cref="AvailableScopes"></param>
void CallWrites(uint addr, string scope);
/// <summary>
/// Executes all Execute callbacks for the given address and domain
/// </summary>
void CallExecutes(uint addr, string domain);
/// <param name="addr">The address to check for callbacks</param>
/// <param name="scope">The scope that the address pertains to. Must be a value in <see cref="AvailableScopes"></param>
void CallExecutes(uint addr, string scope);
/// <summary>
/// Removes the given callback from the list
@ -76,10 +82,10 @@ namespace BizHawk.Emulation.Common
void Clear();
/// <summary>
/// A list of available memory domains that a the <see cref="IMemoryCallback.Domain"/> property of the <see cref="IMemoryCallback"/> can have
/// A list of available "scopes" (memory domains, cpus, etc) that a the <see cref="IMemoryCallback.Scope"/> property of the <see cref="IMemoryCallback"/> can have
/// Passing a <see cref="IMemoryCallback"/> into the <see cref="Add(IMemoryCallback)"/> method that is not in this list will result in an <seealso cref="InvalidOperationException"/>
/// </summary>
string[] AvailableDomains { get; }
string[] AvailableScopes { get; }
}
/// <summary>
@ -93,7 +99,7 @@ namespace BizHawk.Emulation.Common
Action Callback { get; }
uint? Address { get; }
uint? AddressMask { get; }
string Domain { get; }
string Scope { get; }
}
public enum MemoryCallbackType