using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace Mesen.GUI.Debugger { public enum BreakpointAddressType { AnyAddress, SingleAddress, AddressRange, } public class Breakpoint { public bool BreakOnRead = false; public bool BreakOnWrite = false; public bool BreakOnReadVram = false; public bool BreakOnWriteVram = false; public bool BreakOnExec = true; public bool Enabled = true; public UInt32 Address; public UInt32 StartAddress; public UInt32 EndAddress; public BreakpointAddressType AddressType = BreakpointAddressType.SingleAddress; public bool IsAbsoluteAddress = false; public string Condition = ""; public string GetAddressString() { switch(AddressType) { case BreakpointAddressType.AnyAddress: return ""; case BreakpointAddressType.SingleAddress: if(IsAbsoluteAddress) { return "[$" + Address.ToString("X4") + "]"; } else { return "$" + Address.ToString("X4"); } case BreakpointAddressType.AddressRange: if(IsAbsoluteAddress) { return $"[${StartAddress.ToString("X4")} - [${EndAddress.ToString("X4")}]"; } else { return $"${StartAddress.ToString("X4")} - ${EndAddress.ToString("X4")}"; } } return string.Empty; } public void SetEnabled(bool enabled) { Enabled = enabled; BreakpointManager.RefreshBreakpoints(this); } public BreakpointType Type { get { BreakpointType type = BreakpointType.Global; if(BreakOnRead) { type |= BreakpointType.Read; } if(BreakOnWrite) { type |= BreakpointType.Write; } if(BreakOnExec) { type |= BreakpointType.Execute; } if(BreakOnReadVram) { type |= BreakpointType.ReadVram; } if(BreakOnWriteVram) { type |= BreakpointType.WriteVram; } return type; } } public InteropBreakpoint ToInteropBreakpoint() { InteropBreakpoint bp = new InteropBreakpoint() { Type = Type, IsAbsoluteAddress = IsAbsoluteAddress }; switch(AddressType) { case BreakpointAddressType.AnyAddress: bp.StartAddress = -1; bp.EndAddress = -1; break; case BreakpointAddressType.SingleAddress: bp.StartAddress = (Int32)Address; bp.EndAddress = -1; break; case BreakpointAddressType.AddressRange: bp.StartAddress = (Int32)StartAddress; bp.EndAddress = (Int32)EndAddress; break; } bp.Condition = new byte[1000]; byte[] condition = Encoding.UTF8.GetBytes(Condition); Array.Copy(condition, bp.Condition, condition.Length); return bp; } } }