2019-02-27 19:49:26 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Controls;
|
|
|
|
|
using Mesen.GUI.Config;
|
2019-03-23 21:56:35 -04:00
|
|
|
|
using Mesen.GUI.Debugger.Code;
|
2019-04-28 22:19:52 -04:00
|
|
|
|
using Mesen.GUI.Debugger.Labels;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class ctrlDisassemblyView : BaseControl
|
|
|
|
|
{
|
2019-04-07 12:25:14 -04:00
|
|
|
|
private BaseStyleProvider _styleProvider;
|
2019-03-23 21:56:35 -04:00
|
|
|
|
private IDisassemblyManager _manager;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
|
|
|
|
|
public ctrlDisassemblyView()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-03-23 21:56:35 -04:00
|
|
|
|
if(IsDesignMode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InitShortcuts();
|
|
|
|
|
|
|
|
|
|
BreakpointManager.BreakpointsChanged += BreakpointManager_BreakpointsChanged;
|
2019-04-28 22:19:52 -04:00
|
|
|
|
LabelManager.OnLabelUpdated += OnLabelUpdated;
|
2019-03-23 21:56:35 -04:00
|
|
|
|
}
|
2019-04-28 22:19:52 -04:00
|
|
|
|
|
2019-03-23 21:56:35 -04:00
|
|
|
|
protected override void OnHandleDestroyed(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnHandleDestroyed(e);
|
2019-04-28 22:19:52 -04:00
|
|
|
|
LabelManager.OnLabelUpdated -= OnLabelUpdated;
|
2019-03-23 21:56:35 -04:00
|
|
|
|
BreakpointManager.BreakpointsChanged -= BreakpointManager_BreakpointsChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 22:19:52 -04:00
|
|
|
|
private void OnLabelUpdated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ctrlCode.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 21:56:35 -04:00
|
|
|
|
private void BreakpointManager_BreakpointsChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ctrlCode.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-07 12:25:14 -04:00
|
|
|
|
public void Initialize(IDisassemblyManager manager, BaseStyleProvider styleProvider)
|
|
|
|
|
{
|
|
|
|
|
_manager = manager;
|
|
|
|
|
_styleProvider = styleProvider;
|
|
|
|
|
|
|
|
|
|
ctrlCode.StyleProvider = _styleProvider;
|
|
|
|
|
ctrlCode.ShowContentNotes = false;
|
|
|
|
|
ctrlCode.ShowMemoryValues = true;
|
|
|
|
|
ctrlCode.ExtendedMarginWidth = manager.ByteCodeSize * 4;
|
|
|
|
|
ctrlCode.AddressSize = manager.AddressSize;
|
|
|
|
|
|
|
|
|
|
_manager.RefreshCode();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 21:56:35 -04:00
|
|
|
|
private void InitShortcuts()
|
|
|
|
|
{
|
|
|
|
|
mnuToggleBreakpoint.InitShortcut(this, nameof(DebuggerShortcutsConfig.CodeWindow_ToggleBreakpoint));
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetActiveAddress(int? address)
|
|
|
|
|
{
|
2019-03-30 22:11:21 -04:00
|
|
|
|
if(_styleProvider.ActiveAddress == address) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-27 19:49:26 -05:00
|
|
|
|
|
|
|
|
|
_styleProvider.ActiveAddress = address;
|
|
|
|
|
if(address.HasValue && address.Value >= 0) {
|
|
|
|
|
ctrlCode.ScrollToAddress(address.Value);
|
|
|
|
|
}
|
2019-03-30 22:11:21 -04:00
|
|
|
|
|
|
|
|
|
ctrlCode.Invalidate();
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-24 12:05:51 -04:00
|
|
|
|
public void ScrollToAddress(uint address)
|
|
|
|
|
{
|
|
|
|
|
ctrlCode.ScrollToAddress((int)address);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 22:11:21 -04:00
|
|
|
|
public void UpdateCode()
|
2019-02-27 19:49:26 -05:00
|
|
|
|
{
|
|
|
|
|
int centerLineIndex = ctrlCode.GetLineIndexAtPosition(0) + ctrlCode.GetNumberVisibleLines() / 2;
|
|
|
|
|
int centerLineAddress;
|
|
|
|
|
int scrollOffset = -1;
|
|
|
|
|
do {
|
|
|
|
|
//Save the address at the center of the debug view
|
2019-03-23 21:56:35 -04:00
|
|
|
|
centerLineAddress = _manager.Provider.GetLineAddress(centerLineIndex);
|
2019-02-27 19:49:26 -05:00
|
|
|
|
centerLineIndex--;
|
|
|
|
|
scrollOffset++;
|
|
|
|
|
} while(centerLineAddress < 0 && centerLineIndex > 0);
|
|
|
|
|
|
2019-03-23 21:56:35 -04:00
|
|
|
|
_manager.RefreshCode();
|
|
|
|
|
ctrlCode.DataProvider = _manager.Provider;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
|
|
|
|
|
if(centerLineAddress >= 0) {
|
|
|
|
|
//Scroll to the same address as before, to prevent the code view from changing due to setting or banking changes, etc.
|
2019-03-23 21:56:35 -04:00
|
|
|
|
int lineIndex = _manager.Provider.GetLineIndex((UInt32)centerLineAddress) + scrollOffset;
|
2019-02-27 19:49:26 -05:00
|
|
|
|
ctrlCode.ScrollToLineIndex(lineIndex, eHistoryType.None, false, true);
|
|
|
|
|
}
|
2019-04-07 18:16:52 -04:00
|
|
|
|
GoToActiveAddress();
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
2019-03-30 21:47:30 -04:00
|
|
|
|
|
|
|
|
|
public ctrlScrollableTextbox CodeViewer { get { return ctrlCode; } }
|
|
|
|
|
|
|
|
|
|
public void GoToAddress(int address)
|
|
|
|
|
{
|
|
|
|
|
ctrlCode.ScrollToAddress(address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GoToActiveAddress()
|
|
|
|
|
{
|
|
|
|
|
if(_styleProvider.ActiveAddress.HasValue) {
|
|
|
|
|
ctrlCode.ScrollToAddress(_styleProvider.ActiveAddress.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleBreakpoint()
|
2019-02-27 19:49:26 -05:00
|
|
|
|
{
|
2019-03-23 21:56:35 -04:00
|
|
|
|
_manager.ToggleBreakpoint(ctrlCode.SelectedLine);
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 21:47:30 -04:00
|
|
|
|
public void EnableDisableBreakpoint()
|
|
|
|
|
{
|
|
|
|
|
_manager.EnableDisableBreakpoint(ctrlCode.SelectedLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void mnuToggleBreakpoint_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ToggleBreakpoint();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 21:56:35 -04:00
|
|
|
|
private void ctrlCode_MouseDown(object sender, MouseEventArgs e)
|
2019-02-27 19:49:26 -05:00
|
|
|
|
{
|
2019-03-23 21:56:35 -04:00
|
|
|
|
if(e.X < 20) {
|
|
|
|
|
int lineIndex = ctrlCode.GetLineIndexAtPosition(e.Y);
|
|
|
|
|
_manager.ToggleBreakpoint(lineIndex);
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-31 00:20:54 -04:00
|
|
|
|
|
|
|
|
|
private void ctrlCode_TextZoomChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-03-31 09:11:56 -04:00
|
|
|
|
ConfigManager.Config.Debug.Debugger.TextZoom = ctrlCode.TextZoom;
|
2019-03-31 00:20:54 -04:00
|
|
|
|
ConfigManager.ApplyChanges();
|
|
|
|
|
}
|
2019-02-27 19:49:26 -05:00
|
|
|
|
}
|
|
|
|
|
}
|