2011-01-20 04:33:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2011-01-21 03:20:45 +00:00
|
|
|
|
using System.Globalization;
|
2011-01-20 04:33:16 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public partial class RamWatchNewWatch : Form
|
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
public Watch Watch = new Watch();
|
|
|
|
|
public bool SelectionWasMade = false;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public Point location = new Point();
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
private bool DoNotResetAddress = false;
|
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public RamWatchNewWatch()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
public void SetWatch(Watch watch, string message = "New Watch")
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
DoNotResetAddress = true; //Hack for the drop down event changing when initializing the drop down
|
|
|
|
|
Watch = new Watch(watch);
|
2011-06-19 23:39:25 +00:00
|
|
|
|
this.Text = message;
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
NotesBox.Text = watch.Notes;
|
|
|
|
|
setTypeRadio();
|
|
|
|
|
setSignedRadio();
|
|
|
|
|
setEndianBox();
|
|
|
|
|
setDomainSelection();
|
|
|
|
|
setAddressBox();
|
2012-09-04 00:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
#region Events
|
2012-06-02 21:48:09 +00:00
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
private void RamWatchNewWatch_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (location.X > 0 && location.Y > 0)
|
2012-09-04 00:33:47 +00:00
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
this.Location = location;
|
2012-09-04 00:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
populateMemoryDomainComboBox();
|
|
|
|
|
DoNotResetAddress = false;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
SelectionWasMade = false;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OK_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Put user settings in the watch file
|
2012-09-10 02:03:24 +00:00
|
|
|
|
SelectionWasMade = true;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
if (InputValidate.IsValidHexNumber(AddressBox.Text))
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Not a valid address (enter a valid Hex number)", "Invalid Address", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
AddressBox.Focus();
|
|
|
|
|
AddressBox.SelectAll();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SignedRadio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.Signed = Watch.DISPTYPE.SIGNED;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
else if (UnsignedRadio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.Signed = Watch.DISPTYPE.UNSIGNED;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
else if (HexRadio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.Signed = Watch.DISPTYPE.HEX;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
|
|
|
|
if (Byte1Radio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.Type = Watch.TYPE.BYTE;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
else if (Byte2Radio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.Type = Watch.TYPE.WORD;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
else if (Byte4Radio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.Type = Watch.TYPE.DWORD;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
|
|
|
|
if (BigEndianRadio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.BigEndian = true;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
else if (LittleEndianRadio.Checked)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
Watch.BigEndian = false;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2012-09-10 02:03:24 +00:00
|
|
|
|
|
|
|
|
|
Watch.Domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
|
|
|
|
|
Watch.Notes = NotesBox.Text;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddressBox_Leave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AddressBox.Text = AddressBox.Text.Replace(" ", "");
|
|
|
|
|
if (!InputValidate.IsValidHexNumber(AddressBox.Text))
|
|
|
|
|
{
|
|
|
|
|
AddressBox.Focus();
|
|
|
|
|
AddressBox.SelectAll();
|
|
|
|
|
ToolTip t = new ToolTip();
|
2012-09-10 02:03:24 +00:00
|
|
|
|
t.Show("Must be a valid hexadecimal vaue", AddressBox, 5000);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Watch.Address = int.Parse(AddressBox.Text, NumberStyles.HexNumber);
|
|
|
|
|
AddressBox.Text = String.Format("{0:X" + getNumDigits(Watch.Domain.Size - 1) + "}", Watch.Address);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
//Do nothing
|
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
private void DomainComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
if (!DoNotResetAddress)
|
|
|
|
|
{
|
|
|
|
|
Watch.Domain = Global.Emulator.MemoryDomains[DomainComboBox.SelectedIndex];
|
|
|
|
|
int x = getNumDigits(Watch.Domain.Size);
|
|
|
|
|
Watch.Address = 0;
|
|
|
|
|
Watch.Value = 0;
|
|
|
|
|
setAddressBox();
|
|
|
|
|
AddressBox.MaxLength = getNumDigits(Watch.Domain.Size);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Helpers
|
|
|
|
|
|
|
|
|
|
private void setTypeRadio()
|
|
|
|
|
{
|
|
|
|
|
switch (Watch.Type)
|
|
|
|
|
{
|
|
|
|
|
case Watch.TYPE.BYTE:
|
|
|
|
|
Byte1Radio.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.TYPE.WORD:
|
|
|
|
|
Byte2Radio.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.TYPE.DWORD:
|
|
|
|
|
Byte4Radio.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
2012-09-04 00:33:47 +00:00
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
private void setEndianBox()
|
|
|
|
|
{
|
|
|
|
|
if (Watch.BigEndian == true)
|
|
|
|
|
{
|
|
|
|
|
BigEndianRadio.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LittleEndianRadio.Checked = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setDomainSelection()
|
|
|
|
|
{
|
|
|
|
|
//Counts should always be the same, but just in case, let's check
|
|
|
|
|
int max;
|
|
|
|
|
if (Global.Emulator.MemoryDomains.Count < DomainComboBox.Items.Count)
|
|
|
|
|
{
|
|
|
|
|
max = Global.Emulator.MemoryDomains.Count;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
max = DomainComboBox.Items.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
|
{
|
|
|
|
|
if (Watch.Domain.ToString() == DomainComboBox.Items[i].ToString())
|
|
|
|
|
{
|
|
|
|
|
DomainComboBox.SelectedIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void populateMemoryDomainComboBox()
|
2012-09-04 00:33:47 +00:00
|
|
|
|
{
|
|
|
|
|
DomainComboBox.Items.Clear();
|
|
|
|
|
if (Global.Emulator.MemoryDomains.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++)
|
|
|
|
|
{
|
|
|
|
|
string str = Global.Emulator.MemoryDomains[x].ToString();
|
|
|
|
|
DomainComboBox.Items.Add(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-10 02:03:24 +00:00
|
|
|
|
setDomainSelection();
|
2012-09-04 00:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
private void setAddressBox()
|
2012-09-04 00:33:47 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
AddressBox.Text = String.Format("{0:X" + getNumDigits(Watch.Domain.Size - 1) + "}", Watch.Address);
|
2012-09-04 00:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
private void setSignedRadio()
|
2012-09-04 00:33:47 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
switch (Watch.Signed)
|
2012-09-04 00:33:47 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
case Watch.DISPTYPE.SIGNED:
|
|
|
|
|
SignedRadio.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.DISPTYPE.UNSIGNED:
|
|
|
|
|
UnsignedRadio.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.DISPTYPE.HEX:
|
|
|
|
|
HexRadio.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2012-09-04 00:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-10 02:03:24 +00:00
|
|
|
|
private int getNumDigits(Int32 i)
|
2012-09-04 00:33:47 +00:00
|
|
|
|
{
|
2012-09-10 02:03:24 +00:00
|
|
|
|
if (i < 0x10000) return 4;
|
|
|
|
|
if (i < 0x1000000) return 6;
|
|
|
|
|
if (i < 0x10000000) return 7;
|
|
|
|
|
else return 8;
|
2012-09-04 00:33:47 +00:00
|
|
|
|
}
|
2012-09-10 02:03:24 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
2011-01-20 04:33:16 +00:00
|
|
|
|
}
|