2016-11-21 22:34:47 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2016-11-22 18:28:59 -05:00
|
|
|
|
using System.Text.RegularExpressions;
|
2016-11-21 22:34:47 -05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger
|
|
|
|
|
{
|
|
|
|
|
public partial class frmEditLabel : BaseConfigForm
|
|
|
|
|
{
|
2016-11-22 23:07:28 -05:00
|
|
|
|
private CodeLabel _originalLabel;
|
2018-08-21 19:06:22 -04:00
|
|
|
|
private const int _maxInternalRamAddress = 0x1FFF;
|
|
|
|
|
private const int _maxRegisterAddress = 0xFFFF;
|
|
|
|
|
private int _maxPrgRomAddress = 0;
|
|
|
|
|
private int _maxWorkRamAddress = 0;
|
|
|
|
|
private int _maxSaveRamAddress = 0;
|
2016-11-21 22:34:47 -05:00
|
|
|
|
|
2016-11-22 23:07:28 -05:00
|
|
|
|
public frmEditLabel(CodeLabel label, CodeLabel originalLabel = null)
|
2016-11-21 22:34:47 -05:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2016-11-22 23:07:28 -05:00
|
|
|
|
_originalLabel = originalLabel;
|
2016-11-21 22:34:47 -05:00
|
|
|
|
|
|
|
|
|
Entity = label;
|
|
|
|
|
|
2018-08-21 19:06:22 -04:00
|
|
|
|
_maxPrgRomAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.PrgRom) - 1);
|
|
|
|
|
_maxWorkRamAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.WorkRam) - 1);
|
|
|
|
|
_maxSaveRamAddress = Math.Max(0, InteropEmu.DebugGetMemorySize(DebugMemoryType.SaveRam) - 1);
|
|
|
|
|
|
2016-11-22 22:38:14 -05:00
|
|
|
|
AddBinding("AddressType", cboRegion);
|
|
|
|
|
AddBinding("Address", txtAddress);
|
2016-11-21 22:34:47 -05:00
|
|
|
|
AddBinding("Label", txtLabel);
|
|
|
|
|
AddBinding("Comment", txtComment);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 22:38:14 -05:00
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnShown(e);
|
|
|
|
|
txtLabel.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-21 19:06:22 -04:00
|
|
|
|
private int GetMaxAddress(AddressType type)
|
|
|
|
|
{
|
|
|
|
|
switch(type) {
|
|
|
|
|
case AddressType.InternalRam: return _maxInternalRamAddress;
|
|
|
|
|
case AddressType.PrgRom: return _maxPrgRomAddress;
|
|
|
|
|
case AddressType.WorkRam: return _maxWorkRamAddress;
|
|
|
|
|
case AddressType.SaveRam: return _maxSaveRamAddress;
|
|
|
|
|
case AddressType.Register: return _maxRegisterAddress;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 22:34:47 -05:00
|
|
|
|
protected override bool ValidateInput()
|
|
|
|
|
{
|
2016-11-22 23:07:28 -05:00
|
|
|
|
UpdateObject();
|
2016-11-22 18:28:59 -05:00
|
|
|
|
|
2018-08-21 19:06:22 -04:00
|
|
|
|
UInt32 address = ((CodeLabel)Entity).Address;
|
|
|
|
|
AddressType type = ((CodeLabel)Entity).AddressType;
|
2016-11-22 23:07:28 -05:00
|
|
|
|
CodeLabel sameLabel = LabelManager.GetLabel(txtLabel.Text);
|
2018-08-21 19:06:22 -04:00
|
|
|
|
CodeLabel sameAddress = LabelManager.GetLabel(address, type);
|
|
|
|
|
|
|
|
|
|
int maxAddress = GetMaxAddress(type);
|
|
|
|
|
|
|
|
|
|
if(maxAddress <= 0) {
|
|
|
|
|
lblRange.Text = "(unavailable)";
|
|
|
|
|
} else {
|
|
|
|
|
lblRange.Text = "($0000 - $" + maxAddress.ToString("X4") + ")";
|
|
|
|
|
}
|
2016-11-22 23:07:28 -05:00
|
|
|
|
|
2018-08-21 19:06:22 -04:00
|
|
|
|
return
|
|
|
|
|
address < maxAddress &&
|
2016-11-22 23:07:28 -05:00
|
|
|
|
(sameLabel == null || sameLabel == _originalLabel)
|
|
|
|
|
&& (sameAddress == null || sameAddress == _originalLabel)
|
|
|
|
|
&& (_originalLabel != null || txtLabel.Text.Length > 0 || txtComment.Text.Length > 0)
|
2017-03-09 23:50:20 -05:00
|
|
|
|
&& !txtComment.Text.Contains('\x1')
|
2016-12-02 21:57:59 -05:00
|
|
|
|
&& (txtLabel.Text.Length == 0 || Regex.IsMatch(txtLabel.Text, "^[@_a-zA-Z]+[@_a-zA-Z0-9]*$"));
|
2016-11-21 22:34:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnFormClosed(FormClosedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
txtLabel.Text = txtLabel.Text.Replace("$", "");
|
|
|
|
|
base.OnFormClosed(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
|
|
|
|
{
|
|
|
|
|
if(keyData == (Keys.Control | Keys.Enter)) {
|
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
return base.ProcessCmdKey(ref msg, keyData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|