Refactoring, import debugger config files

This commit is contained in:
Sour 2021-03-22 19:13:56 -04:00
parent 780539d79e
commit bf4ac20408
41 changed files with 1397 additions and 71 deletions

View file

@ -1,6 +1,6 @@
using System;
using Avalonia;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

View file

@ -5,9 +5,6 @@ using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Serialization;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Text.RegularExpressions;
using System.Reflection;

View file

@ -21,7 +21,7 @@ namespace Mesen.GUI.Config
public EmulationConfig Emulation { get; set; }
public GameboyConfig Gameboy { get; set; }
public PreferencesConfig Preferences { get; set; }
//public DebugInfo Debug;
public DebugConfig Debug;
public RecentItems RecentFiles { get; set; }
public AviRecordConfig AviRecord { get; set; }
public MovieRecordConfig MovieRecord { get; set; }

View file

@ -0,0 +1,17 @@
using Avalonia;
using Avalonia.Media;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class AssemblerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public string FontFamily = DebuggerConfig.MonospaceFontFamily;
public FontStyle FontStyle = FontStyle.Normal;
public float FontSize = DebuggerConfig.DefaultFontSize;
public int Zoom = 100;
}
}

View file

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class DebugConfig
{
//public DebuggerShortcutsConfig Shortcuts = new DebuggerShortcutsConfig();
public TraceLoggerInfo TraceLogger = new TraceLoggerInfo();
public HexEditorConfig HexEditor = new HexEditorConfig();
public EventViewerConfig EventViewer = new EventViewerConfig();
public DebuggerConfig Debugger = new DebuggerConfig();
public TilemapViewerConfig TilemapViewer = new TilemapViewerConfig();
public TileViewerConfig TileViewer = new TileViewerConfig();
public RegisterViewerConfig RegisterViewer = new RegisterViewerConfig();
public SpriteViewerConfig SpriteViewer = new SpriteViewerConfig();
public DbgIntegrationConfig DbgIntegration = new DbgIntegrationConfig();
public ScriptWindowConfig ScriptWindow = new ScriptWindowConfig();
public ProfilerConfig Profiler = new ProfilerConfig();
public AssemblerConfig Assembler = new AssemblerConfig();
public DebugLogConfig DebugLog = new DebugLogConfig();
public DebugConfig()
{
}
}
public enum RefreshSpeed
{
Low = 0,
Normal = 1,
High = 2
}
}

View file

@ -0,0 +1,10 @@
using Avalonia;
namespace Mesen.GUI.Config
{
public class DebugLogConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
}
}

View file

@ -0,0 +1,124 @@
using Avalonia;
using Avalonia.Media;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.GUI.Config
{
public class DebuggerConfig
{
public static string MonospaceFontFamily = "Consolas";
public static int DefaultFontSize = 14;
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public int? SplitterDistance = null;
public bool ShowByteCode = false;
public bool UseLowerCaseDisassembly = false;
public bool BreakOnBrk = false;
public bool BreakOnCop = false;
public bool BreakOnWdm = false;
public bool BreakOnStp = false;
public bool BreakOnUninitRead = false;
public bool GbBreakOnInvalidOamAccess = false;
public bool GbBreakOnInvalidVramAccess = false;
public bool GbBreakOnDisableLcdOutsideVblank = false;
public bool GbBreakOnInvalidOpCode = false;
public bool GbBreakOnNopLoad = false;
public bool GbBreakOnOamCorruption = false;
public bool BreakOnOpen = true;
public bool BreakOnPowerCycleReset = true;
public bool AutoResetCdl = true;
public bool ShowMemoryMappings = true;
public bool BringToFrontOnBreak = true;
public bool BringToFrontOnPause = false;
public CodeDisplayMode UnidentifiedBlockDisplay = CodeDisplayMode.Hide;
public CodeDisplayMode VerifiedDataDisplay = CodeDisplayMode.Hide;
public bool UseAltSpcOpNames = false;
public int BreakOnValue = 0;
public int BreakInCount = 1;
public BreakInMetric BreakInMetric = BreakInMetric.CpuInstructions;
public string FontFamily = DebuggerConfig.MonospaceFontFamily;
public FontStyle FontStyle = FontStyle.Normal;
public float FontSize = DebuggerConfig.DefaultFontSize;
public int TextZoom = 100;
public bool ShowSelectionLength = false;
//TODO public WatchFormatStyle WatchFormat = WatchFormatStyle.Hex;
public bool ShowCommentsInLabelList = true;
public Color CodeOpcodeColor = Color.FromRgb(22, 37, 37);
public Color CodeLabelDefinitionColor = Colors.Blue;
public Color CodeImmediateColor = Colors.Chocolate;
public Color CodeAddressColor = Colors.DarkRed;
public Color CodeCommentColor = Colors.Green;
public Color CodeEffectiveAddressColor = Colors.SteelBlue;
public Color CodeVerifiedDataColor = Color.FromRgb(255, 252, 236);
public Color CodeUnidentifiedDataColor = Color.FromRgb(255, 242, 242);
public Color CodeUnexecutedCodeColor = Color.FromRgb(225, 244, 228);
public Color CodeExecBreakpointColor = Color.FromRgb(140, 40, 40);
public Color CodeWriteBreakpointColor = Color.FromRgb(40, 120, 80);
public Color CodeReadBreakpointColor = Color.FromRgb(40, 40, 200);
public Color CodeActiveStatementColor = Colors.Yellow;
public void ApplyConfig()
{
ConfigApi.SetDebuggerFlag(DebuggerFlags.BreakOnBrk, BreakOnBrk);
ConfigApi.SetDebuggerFlag(DebuggerFlags.BreakOnCop, BreakOnCop);
ConfigApi.SetDebuggerFlag(DebuggerFlags.BreakOnWdm, BreakOnWdm);
ConfigApi.SetDebuggerFlag(DebuggerFlags.BreakOnStp, BreakOnStp);
ConfigApi.SetDebuggerFlag(DebuggerFlags.BreakOnUninitRead, BreakOnUninitRead);
ConfigApi.SetDebuggerFlag(DebuggerFlags.GbBreakOnInvalidOamAccess, GbBreakOnInvalidOamAccess);
ConfigApi.SetDebuggerFlag(DebuggerFlags.GbBreakOnInvalidVramAccess, GbBreakOnInvalidVramAccess);
ConfigApi.SetDebuggerFlag(DebuggerFlags.GbBreakOnDisableLcdOutsideVblank, GbBreakOnDisableLcdOutsideVblank);
ConfigApi.SetDebuggerFlag(DebuggerFlags.GbBreakOnInvalidOpCode, GbBreakOnInvalidOpCode);
ConfigApi.SetDebuggerFlag(DebuggerFlags.GbBreakOnNopLoad, GbBreakOnNopLoad);
ConfigApi.SetDebuggerFlag(DebuggerFlags.GbBreakOnOamCorruption, GbBreakOnOamCorruption);
ConfigApi.SetDebuggerFlag(DebuggerFlags.ShowUnidentifiedData, UnidentifiedBlockDisplay == CodeDisplayMode.Show);
ConfigApi.SetDebuggerFlag(DebuggerFlags.DisassembleUnidentifiedData, UnidentifiedBlockDisplay == CodeDisplayMode.Disassemble);
ConfigApi.SetDebuggerFlag(DebuggerFlags.ShowVerifiedData, VerifiedDataDisplay == CodeDisplayMode.Show);
ConfigApi.SetDebuggerFlag(DebuggerFlags.DisassembleVerifiedData, VerifiedDataDisplay == CodeDisplayMode.Disassemble);
ConfigApi.SetDebuggerFlag(DebuggerFlags.UseAltSpcOpNames, UseAltSpcOpNames);
ConfigApi.SetDebuggerFlag(DebuggerFlags.UseLowerCaseDisassembly, UseLowerCaseDisassembly);
ConfigApi.SetDebuggerFlag(DebuggerFlags.AutoResetCdl, AutoResetCdl);
}
}
public enum BreakInMetric
{
CpuInstructions,
PpuCycles,
Scanlines,
Frames
}
public enum CodeDisplayMode
{
Hide,
Show,
Disassemble
}
}

View file

@ -0,0 +1,404 @@
/*using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.Windows.Forms;
using Mesen.GUI.Forms;
using static Mesen.GUI.Forms.BaseForm;
namespace Mesen.GUI.Config
{
public class DebuggerShortcutsConfig
{
//Shared
[ShortcutName("Increase Font Size")]
public XmlKeys IncreaseFontSize = Keys.Control | Keys.Oemplus;
[ShortcutName("Decrease Font Size")]
public XmlKeys DecreaseFontSize = Keys.Control | Keys.OemMinus;
[ShortcutName("Reset Font Size")]
public XmlKeys ResetFontSize = Keys.Control | Keys.D0;
[ShortcutName("Go To...")]
public XmlKeys GoTo = Keys.Control | Keys.G;
[ShortcutName("Find")]
public XmlKeys Find = Keys.Control | Keys.F;
[ShortcutName("Find Next")]
public XmlKeys FindNext = Keys.F3;
[ShortcutName("Find Previous")]
public XmlKeys FindPrev = Keys.Shift | Keys.F3;
[ShortcutName("Undo")]
public XmlKeys Undo = Keys.Control | Keys.Z;
[ShortcutName("Copy")]
public XmlKeys Copy = Keys.Control | Keys.C;
[ShortcutName("Cut")]
public XmlKeys Cut = Keys.Control | Keys.X;
[ShortcutName("Paste")]
public XmlKeys Paste = Keys.Control | Keys.V;
[ShortcutName("Select All")]
public XmlKeys SelectAll = Keys.Control | Keys.A;
[ShortcutName("Refresh")]
public XmlKeys Refresh = Keys.F5;
[ShortcutName("Mark Selection as Code")]
public XmlKeys MarkAsCode = Keys.Control | Keys.D1;
[ShortcutName("Mark Selection as Data")]
public XmlKeys MarkAsData = Keys.Control | Keys.D2;
[ShortcutName("Mark Selection as Unidentified Code/Data")]
public XmlKeys MarkAsUnidentified = Keys.Control | Keys.D3;
[ShortcutName("Go to All")]
public XmlKeys GoToAll = Keys.Control | Keys.Oemcomma;
[ShortcutName("Zoom In")]
public XmlKeys ZoomIn = Keys.Control | Keys.Oemplus;
[ShortcutName("Zoom Out")]
public XmlKeys ZoomOut = Keys.Control | Keys.OemMinus;
[ShortcutName("Save as PNG")]
public XmlKeys SaveAsPng = Keys.Control | Keys.S;
[ShortcutName("Edit in Memory Viewer")]
public XmlKeys CodeWindow_EditInMemoryViewer = Keys.F1;
[ShortcutName("View in disassembly")]
public XmlKeys MemoryViewer_ViewInDisassembly = Keys.None;
[ShortcutName("Open Assembler")]
public XmlKeys OpenAssembler = Keys.Control | Keys.U;
[ShortcutName("Open Debugger")]
public XmlKeys OpenDebugger = Keys.Control | Keys.D;
[ShortcutName("Open SPC Debugger")]
public XmlKeys OpenSpcDebugger = Keys.Control | Keys.F;
[ShortcutName("Open SA-1 Debugger")]
public XmlKeys OpenSa1Debugger = Keys.None;
[ShortcutName("Open GSU Debugger")]
public XmlKeys OpenGsuDebugger = Keys.None;
[ShortcutName("Open DSP Debugger")]
public XmlKeys OpenNecDspDebugger = Keys.None;
[ShortcutName("Open CX4 Debugger")]
public XmlKeys OpenCx4Debugger = Keys.None;
[ShortcutName("Open Game Boy Debugger")]
public XmlKeys OpenGameboyDebugger = Keys.None;
[ShortcutName("Open Event Viewer")]
public XmlKeys OpenEventViewer = Keys.Control | Keys.E;
[ShortcutName("Open Memory Tools")]
public XmlKeys OpenMemoryTools = Keys.Control | Keys.M;
[ShortcutName("Open Performance Profiler")]
public XmlKeys OpenProfiler = Keys.Control | Keys.Y;
[ShortcutName("Open Script Window")]
public XmlKeys OpenScriptWindow = Keys.Control | Keys.N;
[ShortcutName("Open Trace Logger")]
public XmlKeys OpenTraceLogger = Keys.Control | Keys.J;
[ShortcutName("Open Register Viewer")]
public XmlKeys OpenRegisterViewer = Keys.Control | Keys.K;
[ShortcutName("Open Debug Log")]
public XmlKeys OpenDebugLog = Keys.Control | Keys.B;
[ShortcutName("Open Tilemap Viewer")]
public XmlKeys OpenTilemapViewer = Keys.Control | Keys.D1;
[ShortcutName("Open Tile Viewer")]
public XmlKeys OpenTileViewer = Keys.Control | Keys.D2;
[ShortcutName("Open Sprite Viewer")]
public XmlKeys OpenSpriteViewer = Keys.Control | Keys.D3;
[ShortcutName("Open Palette Viewer")]
public XmlKeys OpenPaletteViewer = Keys.Control | Keys.D4;
//Debugger window
[ShortcutName("Reset")]
public XmlKeys Reset = Keys.Control | Keys.R;
[ShortcutName("Power Cycle")]
public XmlKeys PowerCycle = Keys.Control | Keys.T;
[ShortcutName("Reload ROM")]
public XmlKeys ReloadRom = Keys.None;
[ShortcutName("Continue")]
public XmlKeys Continue = Keys.F5;
[ShortcutName("Break")]
public XmlKeys Break = Keys.Control | Keys.Alt | Keys.Cancel;
[ShortcutName("Toggle Break/Continue")]
public XmlKeys ToggleBreakContinue = Keys.Escape;
[ShortcutName("Step Into")]
public XmlKeys StepInto = Keys.F11;
[ShortcutName("Step Over")]
public XmlKeys StepOver = Keys.F10;
[ShortcutName("Step Out")]
public XmlKeys StepOut = Keys.Shift | Keys.F11;
[ShortcutName("Step Back")]
public XmlKeys StepBack = Keys.Shift | Keys.F10;
[ShortcutName("Run one CPU Cycle")]
public XmlKeys RunCpuCycle = Keys.None;
[ShortcutName("Run one PPU Cycle")]
public XmlKeys RunPpuCycle = Keys.F6;
[ShortcutName("Run one scanline")]
public XmlKeys RunPpuScanline = Keys.F7;
[ShortcutName("Run one frame")]
public XmlKeys RunPpuFrame = Keys.F8;
[ShortcutName("Break In...")]
public XmlKeys BreakIn = Keys.Control | Keys.B;
[ShortcutName("Break On...")]
public XmlKeys BreakOn = Keys.Alt | Keys.B;
[ShortcutName("Find Occurrences")]
public XmlKeys FindOccurrences = Keys.Control | Keys.Shift | Keys.F;
[ShortcutName("Go To Program Counter")]
public XmlKeys GoToProgramCounter = Keys.Alt | Keys.Multiply;
[ShortcutName("Toggle Verified Data Display")]
public XmlKeys ToggleVerifiedData = Keys.Alt | Keys.D1;
[ShortcutName("Toggle Unidentified Code/Data Display")]
public XmlKeys ToggleUnidentifiedCodeData = Keys.Alt | Keys.D2;
[ShortcutName("Code Window: Set Next Statement")]
public XmlKeys CodeWindow_SetNextStatement = Keys.Control | Keys.Shift | Keys.F10;
[ShortcutName("Code Window: Edit Subroutine")]
public XmlKeys CodeWindow_EditSubroutine = Keys.F4;
[ShortcutName("Code Window: Edit Selected Code")]
public XmlKeys CodeWindow_EditSelectedCode = Keys.None;
[ShortcutName("Code Window: Edit Source File (Source View)")]
public XmlKeys CodeWindow_EditSourceFile = Keys.F4;
[ShortcutName("Code Window: Edit Label")]
public XmlKeys CodeWindow_EditLabel = Keys.F2;
[ShortcutName("Code Window: Navigate Back")]
public XmlKeys CodeWindow_NavigateBack = Keys.Alt | Keys.Left;
[ShortcutName("Code Window: Navigate Forward")]
public XmlKeys CodeWindow_NavigateForward = Keys.Alt | Keys.Right;
[ShortcutName("Code Window: Toggle Breakpoint")]
public XmlKeys CodeWindow_ToggleBreakpoint = Keys.F9;
[ShortcutName("Code Window: Disable/Enable Breakpoint")]
public XmlKeys CodeWindow_DisableEnableBreakpoint = Keys.Control | Keys.F9;
[ShortcutName("Code Window: Switch View (Disassembly / Source View)")]
public XmlKeys CodeWindow_SwitchView = Keys.Control | Keys.Q;
[ShortcutName("Function List: Edit Label")]
public XmlKeys FunctionList_EditLabel = Keys.F2;
[ShortcutName("Function List: Add Breakpoint")]
public XmlKeys FunctionList_AddBreakpoint = Keys.None;
[ShortcutName("Function List: Find Occurrences")]
public XmlKeys FunctionList_FindOccurrences = Keys.None;
[ShortcutName("Label List: Add Label")]
public XmlKeys LabelList_Add = Keys.Insert;
[ShortcutName("Label List: Edit Label")]
public XmlKeys LabelList_Edit = Keys.F2;
[ShortcutName("Label List: Delete Label")]
public XmlKeys LabelList_Delete = Keys.Delete;
[ShortcutName("Label List: Add Breakpoint")]
public XmlKeys LabelList_AddBreakpoint = Keys.None;
[ShortcutName("Label List: Add to Watch")]
public XmlKeys LabelList_AddToWatch = Keys.None;
[ShortcutName("Label List: Find Occurrences")]
public XmlKeys LabelList_FindOccurrences = Keys.None;
[ShortcutName("Label List: View in CPU Memory")]
public XmlKeys LabelList_ViewInCpuMemory = Keys.None;
[ShortcutName("Label List: View in [memory type]")]
public XmlKeys LabelList_ViewInMemoryType = Keys.None;
[ShortcutName("Breakpoint List: Add Breakpoint")]
public XmlKeys BreakpointList_Add = Keys.Insert;
[ShortcutName("Breakpoint List: Edit Breakpoint")]
public XmlKeys BreakpointList_Edit = Keys.F2;
[ShortcutName("Breakpoint List: Go To Location")]
public XmlKeys BreakpointList_GoToLocation = Keys.None;
[ShortcutName("Breakpoint List: Delete Breakpoint")]
public XmlKeys BreakpointList_Delete = Keys.Delete;
[ShortcutName("Watch List: Delete")]
public XmlKeys WatchList_Delete = Keys.Delete;
[ShortcutName("Watch List: Move Up")]
public XmlKeys WatchList_MoveUp = Keys.Control | Keys.Up;
[ShortcutName("Watch List: Move Down")]
public XmlKeys WatchList_MoveDown = Keys.Control | Keys.Down;
[ShortcutName("Save Rom")]
public XmlKeys SaveRom = Keys.Control | Keys.S;
[ShortcutName("Save Rom As...")]
public XmlKeys SaveRomAs = Keys.None;
[ShortcutName("Save edits as IPS patch...")]
public XmlKeys SaveEditAsIps = Keys.None;
[ShortcutName("Revert PRG/CHR changes")]
public XmlKeys RevertPrgChrChanges = Keys.None;
//Memory Tools
[ShortcutName("Freeze")]
public XmlKeys MemoryViewer_Freeze = Keys.Control | Keys.Q;
[ShortcutName("Unfreeze")]
public XmlKeys MemoryViewer_Unfreeze = Keys.Control | Keys.W;
[ShortcutName("Add to Watch")]
public XmlKeys MemoryViewer_AddToWatch = Keys.None;
[ShortcutName("Edit Breakpoint")]
public XmlKeys MemoryViewer_EditBreakpoint = Keys.None;
[ShortcutName("Edit Label")]
public XmlKeys MemoryViewer_EditLabel = Keys.None;
[ShortcutName("Import")]
public XmlKeys MemoryViewer_Import = Keys.Control | Keys.O;
[ShortcutName("Export")]
public XmlKeys MemoryViewer_Export = Keys.Control | Keys.S;
[ShortcutName("View in CPU/PPU Memory")]
public XmlKeys MemoryViewer_ViewInCpuMemory = Keys.None;
[ShortcutName("View in [memory type]")]
public XmlKeys MemoryViewer_ViewInMemoryType = Keys.None;
//Script Window
[ShortcutName("Open Script")]
public XmlKeys ScriptWindow_OpenScript = Keys.Control | Keys.N;
[ShortcutName("Save Script")]
public XmlKeys ScriptWindow_SaveScript = Keys.Control | Keys.S;
[ShortcutName("Run Script")]
public XmlKeys ScriptWindow_RunScript = Keys.F5;
[ShortcutName("Stop Script")]
public XmlKeys ScriptWindow_StopScript = Keys.Escape;
public static string GetShortcutDisplay(Keys keys)
{
if(keys == Keys.None) {
return "";
} else {
string keyString = new KeysConverter().ConvertToString(keys);
return keyString.Replace("+None", "").Replace("Oemcomma", ",").Replace("Oemplus", "+").Replace("Oemtilde", "Tilde").Replace("OemMinus", "-").Replace("Cancel", "Break").Replace("Escape", "Esc");
}
}
private static Dictionary<WeakReference<ToolStripMenuItem>, string> _bindings = new Dictionary<WeakReference<ToolStripMenuItem>, string>();
private static Dictionary<WeakReference<ToolStripMenuItem>, WeakReference<Control>> _parents = new Dictionary<WeakReference<ToolStripMenuItem>, WeakReference<Control>>();
public static void RegisterMenuItem(ToolStripMenuItem item, Control parent, string fieldName)
{
var weakRef = new WeakReference<ToolStripMenuItem>(item);
_bindings[weakRef] = fieldName;
_parents[weakRef] = new WeakReference<Control>(parent);
//Remove old references
var dictCopy = new Dictionary<WeakReference<ToolStripMenuItem>, string>(_bindings);
//Iterate on a copy to avoid "collection was modified" error
foreach(var kvp in dictCopy) {
ToolStripMenuItem menuItem;
if(!kvp.Key.TryGetTarget(out menuItem)) {
_bindings.Remove(kvp.Key);
_parents.Remove(kvp.Key);
}
}
}
public static void UpdateMenus()
{
foreach(WeakReference<ToolStripMenuItem> itemRef in _bindings.Keys) {
ToolStripMenuItem item;
if(itemRef.TryGetTarget(out item)) {
string fieldName = _bindings[itemRef];
Control parent;
_parents[itemRef].TryGetTarget(out parent);
if(parent != null) {
UpdateShortcutItem(item, parent, fieldName);
}
}
}
}
public static void ClearProcessCmdKeyHandler(ToolStripMenuItem item, Control parent)
{
Form parentForm = parent.FindForm();
if(parentForm is BaseForm) {
(parentForm as BaseForm).OnProcessCmdKey -= ((ShortcutInfo)item.Tag).KeyHandler;
}
((ShortcutInfo)item.Tag).KeyHandler = null;
}
public static void UpdateShortcutItem(ToolStripMenuItem item, Control parent, string fieldName)
{
if(item.Tag == null) {
item.Tag = new ShortcutInfo() { KeyHandler = null, ShortcutKey = fieldName };
} else if(((ShortcutInfo)item.Tag).KeyHandler != null) {
ClearProcessCmdKeyHandler(item, parent);
}
Keys keys = (XmlKeys)typeof(DebuggerShortcutsConfig).GetField(fieldName).GetValue(ConfigManager.Config.Debug.Shortcuts);
item.ShortcutKeys = Keys.None;
item.ShortcutKeyDisplayString = GetShortcutDisplay(keys);
Form parentForm = parent.FindForm();
if(parentForm is BaseForm) {
ProcessCmdKeyHandler onProcessCmdKeyHandler = (Keys keyData, ref bool processed) => {
if(!processed && item.Enabled && parent.ContainsFocus && keyData == keys) {
if(parent is IShortcutParent && ((IShortcutParent)parent).SuppressShortcut) {
return;
}
item.PerformClick();
processed = true;
}
};
((ShortcutInfo)item.Tag).KeyHandler = onProcessCmdKeyHandler;
(parentForm as BaseForm).OnProcessCmdKey += onProcessCmdKeyHandler;
}
}
}
public static class ToolStripMenuItemExtensions
{
public static void InitShortcut(this ToolStripMenuItem item, Control parent, string fieldName)
{
DebuggerShortcutsConfig.UpdateShortcutItem(item, parent, fieldName);
DebuggerShortcutsConfig.RegisterMenuItem(item, parent, fieldName);
}
}
public class ShortcutInfo
{
public string ShortcutKey;
public ProcessCmdKeyHandler KeyHandler;
}
public class XmlKeys
{
private Keys _keys = Keys.None;
public XmlKeys() { }
public XmlKeys(Keys k) { _keys = k; }
public static implicit operator Keys(XmlKeys k)
{
return k._keys;
}
public static implicit operator XmlKeys(Keys k)
{
return new XmlKeys(k);
}
[XmlAttribute]
public string Value
{
get { return _keys.ToString(); }
set
{
try {
Enum.TryParse<Keys>(value, out _keys);
} catch(Exception) {
_keys = Keys.None;
}
}
}
}
public class ShortcutNameAttribute : Attribute
{
public string Name { get; private set; }
public ShortcutNameAttribute(string name)
{
this.Name = name;
}
}
public interface IShortcutParent
{
bool SuppressShortcut { get; }
}
}*/

View file

@ -1,11 +1,25 @@
using Mesen.GUI;
using Avalonia;
using Avalonia.Media;
using Mesen.GUI.Utilities;
using System.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen
namespace Mesen.GUI.Config
{
public class EventViewerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public int ImageScale = 1;
public bool RefreshOnBreakPause = true;
public bool AutoRefresh = true;
public RefreshSpeed AutoRefreshSpeed = RefreshSpeed.Normal;
public bool ShowPpuRegisterCgramWrites = true;
public bool ShowPpuRegisterVramWrites = true;
public bool ShowPpuRegisterOamWrites = true;
@ -38,26 +52,26 @@ namespace Mesen
public bool ShowDmaChannel5 = true;
public bool ShowDmaChannel6 = true;
public bool ShowDmaChannel7 = true;
public Color IrqColor = Color.FromRgb(0xFF, 0xAD, 0xAC);
public Color NmiColor = Color.FromRgb(0xFF, 0xAD, 0xAC);
public Color BreakpointColor = Color.FromRgb(0xAF, 0xFF, 0xAF);
public Color ApuRegisterReadColor = Color.FromRgb(0xF9, 0xFE, 0xAC);
public Color ApuRegisterWriteColor = Color.FromRgb(0x9F, 0x93, 0xC6);
public Color CpuRegisterReadColor = Color.FromRgb(0x18, 0x98, 0xE4);
public Color CpuRegisterWriteColor = Color.FromRgb(0xFF, 0x5E, 0x5E);
public Color WorkRamRegisterReadColor = Color.FromRgb(0x8E, 0x33, 0xFF);
public Color WorkRamRegisterWriteColor = Color.FromRgb(0x2E, 0xFF, 0x28);
public XmlColor IrqColor = Color.Yellow;
public XmlColor NmiColor = Color.Yellow;
public XmlColor BreakpointColor = Color.Yellow;
public XmlColor ApuRegisterReadColor = Color.Yellow;
public XmlColor ApuRegisterWriteColor = Color.Yellow;
public XmlColor CpuRegisterReadColor = Color.Yellow;
public XmlColor CpuRegisterWriteColor = Color.Yellow;
public XmlColor WorkRamRegisterReadColor = Color.Yellow;
public XmlColor WorkRamRegisterWriteColor = Color.Yellow;
public XmlColor PpuRegisterReadColor = Color.Yellow;
public XmlColor PpuRegisterWriteCgramColor = Color.Yellow;
public XmlColor PpuRegisterWriteVramColor = Color.Yellow;
public XmlColor PpuRegisterWriteOamColor = Color.Yellow;
public XmlColor PpuRegisterWriteBgOptionColor = Color.Yellow;
public XmlColor PpuRegisterWriteBgScrollColor = Color.Yellow;
public XmlColor PpuRegisterWriteMode7Color = Color.Yellow;
public XmlColor PpuRegisterWriteWindowColor = Color.Yellow;
public XmlColor PpuRegisterWriteOtherColor = Color.Yellow;
public Color PpuRegisterReadColor = Color.FromRgb(0x00, 0x75, 0x97);
public Color PpuRegisterWriteCgramColor = Color.FromRgb(0xC9, 0x29, 0x29);
public Color PpuRegisterWriteVramColor = Color.FromRgb(0xB4, 0x7A, 0xDA);
public Color PpuRegisterWriteOamColor = Color.FromRgb(0x53, 0xD7, 0x44);
public Color PpuRegisterWriteBgOptionColor = Color.FromRgb(0xBF, 0x80, 0x20);
public Color PpuRegisterWriteBgScrollColor = Color.FromRgb(0x4A, 0x7C, 0xD9);
public Color PpuRegisterWriteMode7Color = Color.FromRgb(0xFE, 0x78, 0x7B);
public Color PpuRegisterWriteWindowColor = Color.FromRgb(0xE2, 0x51, 0xF7);
public Color PpuRegisterWriteOtherColor = Color.FromRgb(0xD1, 0xDD, 0x42);
public EventViewerDisplayOptions GetInteropOptions()
{
@ -82,26 +96,26 @@ namespace Mesen
ShowIrq = this.ShowIrq,
ShowMarkedBreakpoints = this.ShowMarkedBreakpoints,
ShowPreviousFrameEvents = this.ShowPreviousFrameEvents,
IrqColor = (uint)this.IrqColor.Color.ToArgb(),
NmiColor = (uint)this.NmiColor.Color.ToArgb(),
BreakpointColor = (uint)this.BreakpointColor.Color.ToArgb(),
IrqColor = (uint)this.IrqColor.ToUint32(),
NmiColor = (uint)this.NmiColor.ToUint32(),
BreakpointColor = (uint)this.BreakpointColor.ToUint32(),
PpuRegisterReadColor = (uint)this.PpuRegisterReadColor.Color.ToArgb(),
PpuRegisterWriteCgramColor = (uint)this.PpuRegisterWriteCgramColor.Color.ToArgb(),
PpuRegisterWriteVramColor = (uint)this.PpuRegisterWriteVramColor.Color.ToArgb(),
PpuRegisterWriteOamColor = (uint)this.PpuRegisterWriteOamColor.Color.ToArgb(),
PpuRegisterWriteMode7Color = (uint)this.PpuRegisterWriteMode7Color.Color.ToArgb(),
PpuRegisterWriteBgOptionColor = (uint)this.PpuRegisterWriteBgOptionColor.Color.ToArgb(),
PpuRegisterWriteBgScrollColor = (uint)this.PpuRegisterWriteBgScrollColor.Color.ToArgb(),
PpuRegisterWriteWindowColor = (uint)this.PpuRegisterWriteWindowColor.Color.ToArgb(),
PpuRegisterWriteOtherColor = (uint)this.PpuRegisterWriteOtherColor.Color.ToArgb(),
PpuRegisterReadColor = (uint)this.PpuRegisterReadColor.ToUint32(),
PpuRegisterWriteCgramColor = (uint)this.PpuRegisterWriteCgramColor.ToUint32(),
PpuRegisterWriteVramColor = (uint)this.PpuRegisterWriteVramColor.ToUint32(),
PpuRegisterWriteOamColor = (uint)this.PpuRegisterWriteOamColor.ToUint32(),
PpuRegisterWriteMode7Color = (uint)this.PpuRegisterWriteMode7Color.ToUint32(),
PpuRegisterWriteBgOptionColor = (uint)this.PpuRegisterWriteBgOptionColor.ToUint32(),
PpuRegisterWriteBgScrollColor = (uint)this.PpuRegisterWriteBgScrollColor.ToUint32(),
PpuRegisterWriteWindowColor = (uint)this.PpuRegisterWriteWindowColor.ToUint32(),
PpuRegisterWriteOtherColor = (uint)this.PpuRegisterWriteOtherColor.ToUint32(),
ApuRegisterReadColor = (uint)this.ApuRegisterReadColor.Color.ToArgb(),
ApuRegisterWriteColor = (uint)this.ApuRegisterWriteColor.Color.ToArgb(),
CpuRegisterReadColor = (uint)this.CpuRegisterReadColor.Color.ToArgb(),
CpuRegisterWriteColor = (uint)this.CpuRegisterWriteColor.Color.ToArgb(),
WorkRamRegisterReadColor = (uint)this.WorkRamRegisterReadColor.Color.ToArgb(),
WorkRamRegisterWriteColor = (uint)this.WorkRamRegisterWriteColor.Color.ToArgb(),
ApuRegisterReadColor = (uint)this.ApuRegisterReadColor.ToUint32(),
ApuRegisterWriteColor = (uint)this.ApuRegisterWriteColor.ToUint32(),
CpuRegisterReadColor = (uint)this.CpuRegisterReadColor.ToUint32(),
CpuRegisterWriteColor = (uint)this.CpuRegisterWriteColor.ToUint32(),
WorkRamRegisterReadColor = (uint)this.WorkRamRegisterReadColor.ToUint32(),
WorkRamRegisterWriteColor = (uint)this.WorkRamRegisterWriteColor.ToUint32(),
ShowDmaChannels = new byte[8] {
(byte)(this.ShowDmaChannel0 ? 1 : 0),

View file

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Avalonia;
using Avalonia.Media;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class HexEditorConfig
{
public bool HighDensityTextMode = false;
public bool EnablePerByteNavigation = true;
public bool ByteEditingMode = true;
public bool AutoRefresh = true;
public RefreshSpeed AutoRefreshSpeed = RefreshSpeed.Normal;
public bool IgnoreRedundantWrites = false;
public bool HighlightCurrentRowColumn = true;
public int ColumnCount = 2;
public string FontFamily = DebuggerConfig.MonospaceFontFamily;
public FontStyle FontStyle = FontStyle.Normal;
public float FontSize = DebuggerConfig.DefaultFontSize;
public int TextZoom = 100;
public bool ShowCharacters = true;
public bool ShowLabelInfo = true;
public bool HighlightExecution = true;
public bool HighlightWrites = true;
public bool HighlightReads = true;
public int FadeSpeed = 300;
public bool HideUnusedBytes = false;
public bool HideReadBytes = false;
public bool HideWrittenBytes = false;
public bool HideExecutedBytes = false;
public bool HighlightBreakpoints = false;
public bool HighlightLabelledBytes = false;
public bool HighlightCodeBytes = false;
public bool HighlightDataBytes = false;
public Color ReadColor = Colors.Blue;
public Color WriteColor = Colors.Red;
public Color ExecColor = Colors.Green;
public Color LabelledByteColor = Colors.LightPink;
public Color CodeByteColor = Colors.DarkSeaGreen;
public Color DataByteColor = Colors.LightSteelBlue;
public SnesMemoryType MemoryType = SnesMemoryType.CpuMemory;
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public HexEditorConfig()
{
}
}
}

View file

@ -0,0 +1,10 @@
using Avalonia;
namespace Mesen.GUI.Config
{
public class ProfilerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
}
}

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Avalonia;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class RegisterViewerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public bool AutoRefresh = true;
public int RefreshScanline = 240;
public int RefreshCycle = 0;
public RegisterViewerConfig()
{
}
}
}

View file

@ -0,0 +1,53 @@
using Avalonia;
using Avalonia.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.GUI.Config
{
public class ScriptWindowConfig
{
private const int MaxRecentScripts = 10;
public List<string> RecentScripts = new List<string>();
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public string FontFamily = DebuggerConfig.MonospaceFontFamily;
public FontStyle FontStyle = FontStyle.Normal;
public float FontSize = DebuggerConfig.DefaultFontSize;
public int Zoom = 100;
public int CodeWindowHeight = 0;
public ScriptStartupBehavior ScriptStartupBehavior = ScriptStartupBehavior.ShowTutorial;
public bool SaveScriptBeforeRun = true;
public bool AutoLoadLastScript = true;
public bool AutoRestartScript = true;
public UInt32 ScriptTimeout = 1000;
public void AddRecentScript(string scriptFile)
{
string existingItem = RecentScripts.Where((file) => file == scriptFile).FirstOrDefault();
if(existingItem != null) {
RecentScripts.Remove(existingItem);
}
RecentScripts.Insert(0, scriptFile);
if(RecentScripts.Count > ScriptWindowConfig.MaxRecentScripts) {
RecentScripts.RemoveAt(ScriptWindowConfig.MaxRecentScripts);
}
//TODO ConfigManager.ApplyChanges();
}
}
public enum ScriptStartupBehavior
{
ShowTutorial = 0,
ShowBlankWindow = 1,
LoadLastScript = 2
}
}

View file

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Avalonia;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class SpriteViewerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public int ImageScale = 2;
public int SplitterDistance = 514;
public bool AutoRefresh = true;
public bool HideOffscreenSprites = false;
public int RefreshScanline = 240;
public int RefreshCycle = 0;
public RefreshSpeed AutoRefreshSpeed = RefreshSpeed.Low;
public SpriteViewerConfig()
{
}
}
}

View file

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Avalonia;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class TileViewerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public int ImageScale = 3;
public bool ShowTileGrid = false;
public SnesMemoryType Source = SnesMemoryType.VideoRam;
public TileFormat Format = TileFormat.Bpp4;
public TileLayout Layout = TileLayout.Normal;
public TileBackground Background = TileBackground.Default;
public int ColumnCount = 16;
public int Address = 0;
public int PageSize = 0x10000;
public int SelectedPalette = 0;
public bool AutoRefresh = true;
public RefreshSpeed AutoRefreshSpeed = RefreshSpeed.Low;
public int RefreshScanline = 240;
public int RefreshCycle = 0;
public TileViewerConfig()
{
}
}
}

View file

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Avalonia;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class TilemapViewerConfig
{
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public int ImageScale = 1;
public bool ShowScrollOverlay = false;
public bool ShowTileGrid = false;
public RefreshSpeed AutoRefreshSpeed = RefreshSpeed.Low;
public bool AutoRefresh = true;
public int RefreshScanline = 240;
public int RefreshCycle = 0;
public TilemapViewerConfig()
{
}
}
}

View file

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Avalonia;
using Avalonia.Media;
using Mesen.GUI.Debugger;
using Mesen.GUI.Utilities;
namespace Mesen.GUI.Config
{
public class TraceLoggerInfo
{
public TraceLoggerOptions LogOptions;
public bool AutoRefresh = true;
public int LineCount = 1000;
public Size WindowSize = new Size(0, 0);
public Point WindowLocation;
public string FontFamily = DebuggerConfig.MonospaceFontFamily;
public FontStyle FontStyle = FontStyle.Normal;
public float FontSize = DebuggerConfig.DefaultFontSize;
public int TextZoom = 100;
public TraceLoggerInfo()
{
LogOptions = new TraceLoggerOptions() {
LogCpu = true,
ShowByteCode = true,
ShowEffectiveAddresses = true,
ShowPpuFrames = false,
ShowPpuCycles = true,
ShowPpuScanline = true,
ShowRegisters = true,
UseLabels = false,
StatusFormat = StatusFlagFormat.Text
};
}
}
public class TraceLoggerOptions
{
public bool LogCpu;
public bool LogSpc;
public bool LogNecDsp;
public bool LogSa1;
public bool LogGsu;
public bool LogCx4;
public bool LogGameboy;
public bool ShowByteCode;
public bool ShowRegisters;
public bool ShowCpuCycles;
public bool ShowPpuCycles;
public bool ShowPpuScanline;
public bool ShowPpuFrames;
public bool ShowExtraInfo;
public bool IndentCode;
public bool ShowEffectiveAddresses;
public bool ShowMemoryValues;
public bool UseLabels;
public bool ExtendZeroPage;
public bool UseWindowsEol = true; //TODO
public StatusFlagFormat StatusFormat;
public bool OverrideFormat;
public string Format;
}
public enum StatusFlagFormat
{
Hexadecimal = 0,
Text = 1,
CompactText = 2
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using Mesen.GUI.Config;

View file

@ -0,0 +1,192 @@
using System;
using System.Linq;
using Avalonia.Media;
using Mesen.Debugger.Controls;
using Mesen.GUI;
using Mesen.GUI.Config;
using Mesen.GUI.Debugger;
namespace Mesen.Debugger
{
public class ByteColorProvider : IByteColorProvider
{
SnesMemoryType _memoryType;
AddressCounters[] _counters;
byte[] _cdlData;
bool[] _hasLabel;
DebugState _state = new DebugState();
bool _showExec;
bool _showWrite;
bool _showRead;
int _framesToFade;
bool _hideUnusedBytes;
bool _hideReadBytes;
bool _hideWrittenBytes;
bool _hideExecutedBytes;
bool _highlightDataBytes;
bool _highlightCodeBytes;
bool _highlightLabelledBytes;
bool _highlightBreakpoints;
ByteColors _colors = new ByteColors();
BreakpointTypeFlags[] _breakpointTypes;
public ByteColorProvider(SnesMemoryType memoryType, bool showExec, bool showWrite, bool showRead, int framesToFade, bool hideUnusedBytes, bool hideReadBytes, bool hideWrittenBytes, bool hideExecutedBytes, bool highlightDataBytes, bool highlightCodeBytes, bool highlightLabelledBytes, bool highlightBreakpoints)
{
_memoryType = memoryType;
_showExec = showExec;
_showWrite = showWrite;
_showRead = showRead;
_framesToFade = framesToFade;
_hideUnusedBytes = hideUnusedBytes;
_hideReadBytes = hideReadBytes;
_hideWrittenBytes = hideWrittenBytes;
_hideExecutedBytes = hideExecutedBytes;
_highlightDataBytes = highlightDataBytes;
_highlightCodeBytes = highlightCodeBytes;
_highlightLabelledBytes = highlightLabelledBytes;
_highlightBreakpoints = highlightBreakpoints;
}
public void Prepare(long firstByteIndex, long lastByteIndex)
{
int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1);
if(_highlightBreakpoints) {
//TODO
/*Breakpoint[] breakpoints = BreakpointManager.Breakpoints.ToArray();
_breakpointTypes = new BreakpointTypeFlags[visibleByteCount];
for(int i = 0; i < visibleByteCount; i++) {
int byteIndex = i + (int)firstByteIndex;
foreach(Breakpoint bp in breakpoints) {
if(bp.Enabled && bp.Matches((uint)byteIndex, _memoryType, null)) {
_breakpointTypes[i] = bp.BreakOnExec ? BreakpointTypeFlags.Execute : (bp.BreakOnWrite ? BreakpointTypeFlags.Write : BreakpointTypeFlags.Read);
break;
}
}
}*/
} else {
_breakpointTypes = null;
}
_counters = DebugApi.GetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
_cdlData = null;
if(_highlightDataBytes || _highlightCodeBytes) {
switch(_memoryType) {
case SnesMemoryType.CpuMemory:
case SnesMemoryType.Sa1Memory:
case SnesMemoryType.Cx4Memory:
case SnesMemoryType.GsuMemory:
case SnesMemoryType.GameboyMemory:
case SnesMemoryType.PrgRom:
case SnesMemoryType.GbPrgRom:
_cdlData = DebugApi.GetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
break;
}
}
_hasLabel = new bool[visibleByteCount];
if(_highlightLabelledBytes) {
if(_memoryType <= SnesMemoryType.SpcMemory) {
AddressInfo addr = new AddressInfo();
addr.Type = _memoryType;
for(long i = 0; i < _hasLabel.Length; i++) {
addr.Address = (int)(firstByteIndex + i);
//TODO
//_hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel(addr)?.Label);
}
} else if(_memoryType == SnesMemoryType.PrgRom || _memoryType == SnesMemoryType.WorkRam || _memoryType == SnesMemoryType.SaveRam) {
for(long i = 0; i < _hasLabel.Length; i++) {
//TODO
//_hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(firstByteIndex + i), _memoryType)?.Label);
}
}
}
_state = DebugApi.GetState();
}
public static Color DarkerColor(Color input, double brightnessPercentage)
{
if(double.IsInfinity(brightnessPercentage)) {
brightnessPercentage = 1.0;
}
if(brightnessPercentage < 0.20) {
brightnessPercentage *= 5;
} else {
brightnessPercentage = 1.0;
}
return Color.FromRgb((byte)(input.R * brightnessPercentage), (byte)(input.G * brightnessPercentage), (byte)(input.B * brightnessPercentage));
}
public ByteColors GetByteColor(long firstByteIndex, long byteIndex)
{
HexEditorConfig cfg = ConfigManager.Config.Debug.HexEditor;
const int CyclesPerFrame = 357368;
long index = byteIndex - firstByteIndex;
double framesSinceExec = (double)(_state.MasterClock - _counters[index].ExecStamp) / CyclesPerFrame;
double framesSinceWrite = (double)(_state.MasterClock - _counters[index].WriteStamp) / CyclesPerFrame;
double framesSinceRead = (double)(_state.MasterClock - _counters[index].ReadStamp) / CyclesPerFrame;
bool isRead = _counters[index].ReadCount > 0;
bool isWritten = _counters[index].WriteCount > 0;
bool isExecuted = _counters[index].ExecCount > 0;
bool isUnused = !isRead && !isWritten && !isExecuted;
byte alpha = 0;
if(isRead && _hideReadBytes || isWritten && _hideWrittenBytes || isExecuted && _hideExecutedBytes || isUnused && _hideUnusedBytes) {
alpha = 128;
}
if(isRead && !_hideReadBytes || isWritten && !_hideWrittenBytes || isExecuted && !_hideExecutedBytes || isUnused && !_hideUnusedBytes) {
alpha = 255;
}
_colors.BackColor = Colors.Transparent;
if(_cdlData != null) {
if((_cdlData[index] & (byte)CdlFlags.Code) != 0 && _highlightCodeBytes) {
//Code
_colors.BackColor = cfg.CodeByteColor;
} else if((_cdlData[index] & (byte)CdlFlags.Data) != 0 && _highlightDataBytes) {
//Data
_colors.BackColor = cfg.DataByteColor;
}
}
if(_hasLabel[index]) {
//Labels/comments
_colors.BackColor = cfg.LabelledByteColor;
}
_colors.BorderColor = Colors.Transparent;
if(_breakpointTypes != null) {
switch(_breakpointTypes[index]) {
case BreakpointTypeFlags.Execute:
_colors.BorderColor = ConfigManager.Config.Debug.Debugger.CodeExecBreakpointColor;
break;
case BreakpointTypeFlags.Write:
_colors.BorderColor = ConfigManager.Config.Debug.Debugger.CodeWriteBreakpointColor;
break;
case BreakpointTypeFlags.Read:
_colors.BorderColor = ConfigManager.Config.Debug.Debugger.CodeReadBreakpointColor;
break;
}
}
//TODO
/*if(_showExec && _counters[index].ExecStamp != 0 && framesSinceExec >= 0 && (framesSinceExec < _framesToFade || _framesToFade == 0)) {
_colors.ForeColor = Color.FromArgb(alpha, DarkerColor(cfg.ExecColor, (_framesToFade - framesSinceExec) / _framesToFade));
} else if(_showWrite && _counters[index].WriteStamp != 0 && framesSinceWrite >= 0 && (framesSinceWrite < _framesToFade || _framesToFade == 0)) {
_colors.ForeColor = Color.FromArgb(alpha, DarkerColor(cfg.WriteColor, (_framesToFade - framesSinceWrite) / _framesToFade));
} else if(_showRead && _counters[index].ReadStamp != 0 && framesSinceRead >= 0 && (framesSinceRead < _framesToFade || _framesToFade == 0)) {
_colors.ForeColor = Color.FromArgb(alpha, DarkerColor(cfg.ReadColor, (_framesToFade - framesSinceRead) / _framesToFade));
} else {
_colors.ForeColor = Color.FromArgb(alpha, 0, 0, 0);
}*/
_colors.ForeColor = Color.FromArgb(alpha, 0, 0, 0);
return _colors;
}
}
}

View file

@ -0,0 +1,62 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.Debugger.Controls
{
public class HexEditor : Control
{
public static readonly StyledProperty<byte[]> DataProperty = AvaloniaProperty.Register<HexEditor, byte[]>(nameof(Data));
public static readonly StyledProperty<int> StartByteProperty = AvaloniaProperty.Register<HexEditor, int>(nameof(StartByte), 0);
public static readonly StyledProperty<int> BytesPerRowProperty = AvaloniaProperty.Register<HexEditor, int>(nameof(BytesPerRow), 16);
public byte[] Data
{
get { return GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
public int StartByte
{
get { return GetValue(StartByteProperty); }
set { SetValue(StartByteProperty, value); }
}
public int BytesPerRow
{
get { return GetValue(BytesPerRowProperty); }
set { SetValue(BytesPerRowProperty, value); }
}
public HexEditor()
{
}
public override void Render(DrawingContext context)
{
base.Render(context);
var text = new FormattedText("Test", Typeface.Default, 12, TextAlignment.Left, TextWrapping.NoWrap, Size.Empty);
context.DrawText(Brushes.Black, new Point(0, 0), text);
}
}
public interface IByteColorProvider
{
void Prepare(long firstByteIndex, long lastByteIndex);
ByteColors GetByteColor(long firstByteIndex, long byteIndex);
}
public class ByteColors
{
public Color ForeColor { get; set; }
public Color BackColor { get; set; }
public Color BorderColor { get; set; }
}
}

View file

@ -1,6 +1,7 @@
using Avalonia.Controls;
using Mesen.GUI;
using Mesen.GUI.Debugger;
using Mesen.ViewModels;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
@ -10,7 +11,7 @@ using System.ComponentModel;
using System.Reactive.Linq;
using System.Text;
namespace Mesen.ViewModels
namespace Mesen.Debugger.ViewModels
{
public class BreakpointListViewModel : ViewModelBase
{

View file

@ -1,4 +1,5 @@
using ReactiveUI;
using Mesen.ViewModels;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -6,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.ViewModels
namespace Mesen.Debugger.ViewModels
{
public class DebuggerViewModel : ViewModelBase
{

View file

@ -1,6 +1,7 @@
using ReactiveUI;
using Mesen.ViewModels;
using ReactiveUI;
namespace Mesen.ViewModels
namespace Mesen.Debugger.ViewModels
{
public class DisassemblyViewerViewModel : ViewModelBase
{

View file

@ -0,0 +1,22 @@
using Mesen.GUI;
using Mesen.ViewModels;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.Debugger.ViewModels
{
public class HexEditorViewModel : ViewModelBase
{
public HexEditorViewModel()
{
}
}
}

View file

@ -0,0 +1,18 @@
using Mesen.ViewModels;
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mesen.Debugger.ViewModels
{
public class MemoryToolsViewModel : ViewModelBase
{
public MemoryToolsViewModel()
{
}
}
}

View file

@ -1,12 +1,13 @@
using Avalonia.Controls;
using Mesen.GUI;
using Mesen.ViewModels;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Reactive.Linq;
using System.Text;
namespace Mesen.ViewModels
namespace Mesen.Debugger.ViewModels
{
public class SnesCpuViewModel : ViewModelBase
{

View file

@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="110"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
x:Class="Mesen.Views.BreakpointListView"
x:Class="Mesen.Debugger.Views.BreakpointListView"
>
<Design.DataContext>
<vm:BreakpointListViewModel />

View file

@ -4,8 +4,9 @@ using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Mesen.ViewModels;
using Mesen.GUI.Debugger;
using Mesen.Debugger.ViewModels;
namespace Mesen.Views
namespace Mesen.Debugger.Views
{
public class BreakpointListView : UserControl
{

View file

@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
x:Class="Mesen.Views.DisassemblyView"
x:Class="Mesen.Debugger.Views.DisassemblyView"
>
<Design.DataContext>
<vm:DisassemblyViewerViewModel />

View file

@ -2,7 +2,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Mesen.Views
namespace Mesen.Debugger.Views
{
public class DisassemblyView : UserControl
{

View file

@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="110"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
x:Class="Mesen.Views.SnesCpuView"
x:Class="Mesen.Debugger.Views.SnesCpuView"
>
<Design.DataContext>
<vm:SnesCpuViewModel />

View file

@ -2,7 +2,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Mesen.Views
namespace Mesen.Debugger.Views
{
public class SnesCpuView : UserControl
{

View file

@ -4,14 +4,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:m="clr-namespace:Mesen"
xmlns:vm="using:Mesen.ViewModels"
xmlns:v="using:Mesen.Views"
xmlns:v="using:Mesen.Debugger.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:id="clr-namespace:Dock.Avalonia;assembly=Dock.Avalonia"
xmlns:idc="clr-namespace:Dock.Avalonia.Controls;assembly=Dock.Avalonia"
xmlns:dm="clr-namespace:Dock.Model;assembly=Dock.Model.Avalonia"
xmlns:dmc="clr-namespace:Dock.Model.Controls;assembly=Dock.Model.Avalonia"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="700"
x:Class="Mesen.Windows.DebuggerWindow"
x:Class="Mesen.Debugger.Windows.DebuggerWindow"
Width="1000" Height="1000"
Title="Debugger"
x:Name="Debugger"

View file

@ -12,8 +12,10 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Mesen.Debugger.ViewModels;
using Mesen.GUI.Config;
namespace Mesen.Windows
namespace Mesen.Debugger.Windows
{
public class DebuggerWindow : Window
{

View file

@ -0,0 +1,26 @@
<Window
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:m="clr-namespace:Mesen"
xmlns:vm="using:Mesen.ViewModels"
xmlns:v="using:Mesen.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:id="clr-namespace:Dock.Avalonia;assembly=Dock.Avalonia"
xmlns:idc="clr-namespace:Dock.Avalonia.Controls;assembly=Dock.Avalonia"
xmlns:dm="clr-namespace:Dock.Model;assembly=Dock.Model.Avalonia"
xmlns:dmc="clr-namespace:Dock.Model.Controls;assembly=Dock.Model.Avalonia"
xmlns:dvm="using:Mesen.Debugger.ViewModels"
xmlns:dc="using:Mesen.Debugger.Controls"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="600"
x:Class="Mesen.Debugger.Windows.MemoryToolsWindow"
Width="600" Height="600"
Title="Debugger"
x:Name="Debugger"
>
<Design.DataContext>
<dvm:MemoryToolsViewModel />
</Design.DataContext>
<dc:HexEditor />
</Window>

View file

@ -0,0 +1,33 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using Mesen.ViewModels;
using Mesen.GUI;
using ReactiveUI;
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Mesen.Debugger.Windows
{
public class MemoryToolsWindow : Window
{
public MemoryToolsWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
@ -90,7 +89,8 @@ namespace Mesen.GUI
[DllImport(DllPath)] public static extern void LoadStateFile([MarshalAs(UnmanagedType.LPUTF8Str)]string filepath);
[DllImport(DllPath, EntryPoint = "GetSaveStatePreview")] private static extern Int32 GetSaveStatePreviewWrapper([MarshalAs(UnmanagedType.LPUTF8Str)]string saveStatePath, [Out]byte[] imgData);
public static Image GetSaveStatePreview(string saveStatePath)
//TODO
/*public static Image GetSaveStatePreview(string saveStatePath)
{
if(File.Exists(saveStatePath)) {
byte[] buffer = new byte[512*478*4];
@ -103,7 +103,7 @@ namespace Mesen.GUI
}
}
return null;
}
}*/
[DllImport(DllPath)] public static extern void SetCheats([In]UInt32[] cheats, UInt32 cheatCount);
[DllImport(DllPath)] public static extern void ClearCheats();

View file

@ -51,6 +51,9 @@
<Compile Update="Controls\OptionSection.axaml.cs">
<DependentUpon>OptionSection.axaml</DependentUpon>
</Compile>
<Compile Update="Debugger\Windows\MemoryToolsWindow.axaml.cs">
<DependentUpon>MemoryToolsWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Views\ShortcutKeysTabView.axaml.cs">
<DependentUpon>ShortcutKeysTabView.axaml</DependentUpon>
</Compile>
@ -90,19 +93,19 @@
<Compile Update="Views\VideoConfigView.axaml.cs">
<DependentUpon>VideoConfigView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\BreakpointListView.axaml.cs">
<Compile Update="Debugger\Views\BreakpointListView.axaml.cs">
<DependentUpon>BreakpointListView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\AudioConfigView.axaml.cs">
<DependentUpon>AudioConfigView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\SnesCpuView.axaml.cs">
<Compile Update="Debugger\Views\SnesCpuView.axaml.cs">
<DependentUpon>SnesCpuView.axaml</DependentUpon>
</Compile>
<Compile Update="Views\DisassemblyView.axaml.cs">
<Compile Update="Debugger\Views\DisassemblyView.axaml.cs">
<DependentUpon>DisassemblyView.axaml</DependentUpon>
</Compile>
<Compile Update="Windows\DebuggerWindow.axaml.cs">
<Compile Update="Debugger\Windows\DebuggerWindow.axaml.cs">
<DependentUpon>DebuggerWindow.axaml</DependentUpon>
</Compile>
</ItemGroup>

View file

@ -44,6 +44,11 @@
<mui:MaterialIcon Kind="Bug" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Memory Tools" Click="OnMemoryToolsClick">
<MenuItem.Icon>
<mui:MaterialIcon Kind="Memory" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
<Panel>

View file

@ -12,12 +12,13 @@ using Mesen.GUI.Config;
using Mesen.GUI.Utilities;
using ReactiveUI;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Mesen.Debugger.Windows;
using Mesen.Debugger.ViewModels;
namespace Mesen.Windows
{
@ -71,6 +72,13 @@ namespace Mesen.Windows
}
}
private void OnMemoryToolsClick(object sender, RoutedEventArgs e)
{
new MemoryToolsWindow {
DataContext = new MemoryToolsViewModel(),
}.Show();
}
private void OnDebuggerClick(object sender, RoutedEventArgs e)
{
new DebuggerWindow {