From d775067037af32ba8b57145a828434c0dcc12761 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 3 Jul 2020 19:49:29 -0500 Subject: [PATCH] move BreakpointList to Client.Common --- .../BreakpointList.cs} | 358 +++++++++--------- .../tools/Debugger/BreakpointControl.cs | 4 +- 2 files changed, 181 insertions(+), 181 deletions(-) rename src/{BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs => BizHawk.Client.Common/BreakpointList.cs} (93%) diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs b/src/BizHawk.Client.Common/BreakpointList.cs similarity index 93% rename from src/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs rename to src/BizHawk.Client.Common/BreakpointList.cs index 06a85969b1..b9d8bce616 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/Breakpoint.cs +++ b/src/BizHawk.Client.Common/BreakpointList.cs @@ -1,179 +1,179 @@ -using System; -using System.Collections.Generic; - -using BizHawk.Emulation.Common; - -namespace BizHawk.Client.EmuHawk -{ - public class BreakpointList : List - { - public MemoryCallbackDelegate Callback { get; set; } - - public void Add(IDebuggable core, string scope, uint address, uint mask, MemoryCallbackType type) - { - Add(new Breakpoint(core, scope, Callback, address, mask, type)); - } - - public new void Clear() - { - foreach (var breakpoint in this) - { - breakpoint.ReadOnly = false; - breakpoint.Active = false; - } - - base.Clear(); - } - - public new bool Remove(Breakpoint b) - { - var breakpoint = Find(x => x == b); - if (breakpoint != null) - { - breakpoint.ReadOnly = false; - breakpoint.Active = false; - } - - return base.Remove(b); - } - - public new void RemoveAt(int index) - { - if (index < Count) - { - var breakpoint = this[index]; - breakpoint.ReadOnly = false; - breakpoint.Active = false; - base.RemoveAt(index); - } - } - - public new int RemoveAll(Predicate match) - { - var removeCount = 0; - foreach (var breakpoint in this) - { - if (match(breakpoint)) - { - Remove(breakpoint); - removeCount++; - } - } - - return removeCount; - } - } - - public class Breakpoint - { - private bool _active; - private readonly IDebuggable _core; - - public Breakpoint(bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) - { - Scope = scope; - _core = core; - Type = type; - Callback = callBack; - Address = address; - AddressMask = mask; - Name = "Pause"; - - Active = enabled; - ReadOnly = readOnly; - } - - public Breakpoint(IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) - { - Scope = scope; - _core = core; - Type = type; - Callback = callBack; - Address = address; - AddressMask = mask; - Name = "Pause"; - - Active = enabled; - } - - public Breakpoint(string name, bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) - { - Scope = scope; - _core = core; - Type = type; - Callback = callBack; - Address = address; - AddressMask = mask; - Name = name; - - Active = enabled; - ReadOnly = readOnly; - } - - public string Scope { get; } - public MemoryCallbackDelegate Callback { get; } - public uint? Address { get; set; } - public uint? AddressMask { get; set; } - public MemoryCallbackType Type { get; set; } - public string Name { get; } - - internal bool ReadOnly { get; set; } - - // Adds an existing callback - public Breakpoint(IDebuggable core, IMemoryCallback callback) - { - _core = core; - _active = true; - Callback = callback.Callback; - Address = callback.Address; - AddressMask = callback.AddressMask; - Type = callback.Type; - Name = callback.Name; - - // We don't know where this callback came from so don't let the user mess with it - // Most likely it came from lua and doing so could cause some bad things to happen - ReadOnly = true; - } - - public bool Active - { - get => _active; - set - { - if (!ReadOnly) - { - if (!value) - { - RemoveCallback(); - } - - if (!_active && value) // If inactive and changing to active - { - AddCallback(); - } - - _active = value; - } - } - } - - private void AddCallback() - { - _core.MemoryCallbacks.Add(new MemoryCallback(Scope, Type, Name, Callback, Address, AddressMask)); - } - - private void RemoveCallback() - { - _core.MemoryCallbacks.Remove(Callback); - } - - public void ResetCallback() - { - if (Active) - { - RemoveCallback(); - AddCallback(); - } - } - } -} +using System; +using System.Collections.Generic; + +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.Common +{ + public class BreakpointList : List + { + public MemoryCallbackDelegate Callback { get; set; } + + public void Add(IDebuggable core, string scope, uint address, uint mask, MemoryCallbackType type) + { + Add(new Breakpoint(core, scope, Callback, address, mask, type)); + } + + public new void Clear() + { + foreach (var breakpoint in this) + { + breakpoint.ReadOnly = false; + breakpoint.Active = false; + } + + base.Clear(); + } + + public new bool Remove(Breakpoint b) + { + var breakpoint = Find(x => x == b); + if (breakpoint != null) + { + breakpoint.ReadOnly = false; + breakpoint.Active = false; + } + + return base.Remove(b); + } + + public new void RemoveAt(int index) + { + if (index < Count) + { + var breakpoint = this[index]; + breakpoint.ReadOnly = false; + breakpoint.Active = false; + base.RemoveAt(index); + } + } + + public new int RemoveAll(Predicate match) + { + var removeCount = 0; + foreach (var breakpoint in this) + { + if (match(breakpoint)) + { + Remove(breakpoint); + removeCount++; + } + } + + return removeCount; + } + } + + public class Breakpoint + { + private bool _active; + private readonly IDebuggable _core; + + public Breakpoint(bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) + { + Scope = scope; + _core = core; + Type = type; + Callback = callBack; + Address = address; + AddressMask = mask; + Name = "Pause"; + + Active = enabled; + ReadOnly = readOnly; + } + + public Breakpoint(IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) + { + Scope = scope; + _core = core; + Type = type; + Callback = callBack; + Address = address; + AddressMask = mask; + Name = "Pause"; + + Active = enabled; + } + + public Breakpoint(string name, bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) + { + Scope = scope; + _core = core; + Type = type; + Callback = callBack; + Address = address; + AddressMask = mask; + Name = name; + + Active = enabled; + ReadOnly = readOnly; + } + + public string Scope { get; } + public MemoryCallbackDelegate Callback { get; } + public uint? Address { get; set; } + public uint? AddressMask { get; set; } + public MemoryCallbackType Type { get; set; } + public string Name { get; } + + public bool ReadOnly { get; set; } + + // Adds an existing callback + public Breakpoint(IDebuggable core, IMemoryCallback callback) + { + _core = core; + _active = true; + Callback = callback.Callback; + Address = callback.Address; + AddressMask = callback.AddressMask; + Type = callback.Type; + Name = callback.Name; + + // We don't know where this callback came from so don't let the user mess with it + // Most likely it came from lua and doing so could cause some bad things to happen + ReadOnly = true; + } + + public bool Active + { + get => _active; + set + { + if (!ReadOnly) + { + if (!value) + { + RemoveCallback(); + } + + if (!_active && value) // If inactive and changing to active + { + AddCallback(); + } + + _active = value; + } + } + } + + private void AddCallback() + { + _core.MemoryCallbacks.Add(new MemoryCallback(Scope, Type, Name, Callback, Address, AddressMask)); + } + + private void RemoveCallback() + { + _core.MemoryCallbacks.Remove(Callback); + } + + public void ResetCallback() + { + if (Active) + { + RemoveCallback(); + AddCallback(); + } + } + } +} diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs index 46b3787a3b..c06cbb91cd 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; - +using BizHawk.Client.Common; using BizHawk.Client.EmuHawk.Properties; using BizHawk.Common.NumberExtensions; using BizHawk.Emulation.Common; @@ -144,7 +144,7 @@ namespace BizHawk.Client.EmuHawk { var b = CreateAddBreakpointDialog(BreakpointOperation.Add); - if (b.ShowHawkDialog() == DialogResult.OK) + if (b.ShowHawkDialog().IsOk()) { _breakpoints.Add(Core, MemoryDomains.SystemBus.Name, b.Address, b.AddressMask, b.BreakType); }