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 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() public new void Clear()
@ -69,9 +69,9 @@ namespace BizHawk.Client.EmuHawk
private bool _active; private bool _active;
private readonly IDebuggable _core; 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; _core = core;
Type = type; Type = type;
Callback = callBack; Callback = callBack;
@ -83,9 +83,9 @@ namespace BizHawk.Client.EmuHawk
ReadOnly = readOnly; 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; _core = core;
Type = type; Type = type;
Callback = callBack; Callback = callBack;
@ -96,9 +96,9 @@ namespace BizHawk.Client.EmuHawk
Active = enabled; 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; _core = core;
Type = type; Type = type;
Callback = callBack; Callback = callBack;
@ -110,7 +110,7 @@ namespace BizHawk.Client.EmuHawk
ReadOnly = readOnly; ReadOnly = readOnly;
} }
public string Domain { get; } public string Scope { get; }
public Action Callback { get; } public Action Callback { get; }
public uint? Address { get; set; } public uint? Address { get; set; }
public uint? AddressMask { get; set; } public uint? AddressMask { get; set; }
@ -163,7 +163,7 @@ namespace BizHawk.Client.EmuHawk
private void AddCallback() 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() private void RemoveCallback()

View File

@ -95,7 +95,7 @@ namespace BizHawk.Emulation.Common
public uint? AddressMask => null; 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" /> /// <seealso cref="IMemoryCallbackSystem" />
public class MemoryCallbackSystem : 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; ExecuteCallbacksAvailable = true;
_reads.CollectionChanged += OnCollectionChanged; _reads.CollectionChanged += OnCollectionChanged;
@ -41,13 +41,13 @@ namespace BizHawk.Emulation.Common
public bool ExecuteCallbacksAvailable { get; } public bool ExecuteCallbacksAvailable { get; }
public string[] AvailableDomains { get; } public string[] AvailableScopes { get; }
public void Add(IMemoryCallback callback) 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) switch (callback.Type)
@ -74,38 +74,38 @@ namespace BizHawk.Emulation.Common
_empty = false; _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++) 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(); cbs[i].Callback();
} }
} }
} }
public void CallReads(uint addr, string domain) public void CallReads(uint addr, string scope)
{ {
if (_hasReads) 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) 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) if (_hasExecutes)
{ {
Call(_execs, addr, domain); Call(_execs, addr, scope);
} }
} }
@ -286,7 +286,7 @@ namespace BizHawk.Emulation.Common
public class MemoryCallback : IMemoryCallback 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) if (type == MemoryCallbackType.Execute && !address.HasValue)
{ {
@ -298,7 +298,7 @@ namespace BizHawk.Emulation.Common
Callback = callback; Callback = callback;
Address = address; Address = address;
AddressMask = mask ?? 0xFFFFFFFF; AddressMask = mask ?? 0xFFFFFFFF;
Domain = domain; Scope = scope;
} }
public MemoryCallbackType Type { get; } public MemoryCallbackType Type { get; }
@ -306,6 +306,6 @@ namespace BizHawk.Emulation.Common
public Action Callback { get; } public Action Callback { get; }
public uint? Address { get; } public uint? Address { get; }
public uint? AddressMask { 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 /// 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 /// Note: an execute callback can not be added without an address, else an InvalidOperationException will occur
/// </summary> /// </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); void Add(IMemoryCallback callback);
/// <summary> /// <summary>
/// Executes all Read callbacks for the given address and domain /// Executes all Read callbacks for the given address and domain
/// </summary> /// </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> /// <summary>
/// Executes all Write callbacks for the given address and domain /// Executes all Write callbacks for the given address and domain
/// </summary> /// </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> /// <summary>
/// Executes all Execute callbacks for the given address and domain /// Executes all Execute callbacks for the given address and domain
/// </summary> /// </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> /// <summary>
/// Removes the given callback from the list /// Removes the given callback from the list
@ -76,10 +82,10 @@ namespace BizHawk.Emulation.Common
void Clear(); void Clear();
/// <summary> /// <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"/> /// 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> /// </summary>
string[] AvailableDomains { get; } string[] AvailableScopes { get; }
} }
/// <summary> /// <summary>
@ -93,7 +99,7 @@ namespace BizHawk.Emulation.Common
Action Callback { get; } Action Callback { get; }
uint? Address { get; } uint? Address { get; }
uint? AddressMask { get; } uint? AddressMask { get; }
string Domain { get; } string Scope { get; }
} }
public enum MemoryCallbackType public enum MemoryCallbackType