2011-02-17 16:27:39 +00:00
|
|
|
|
using System;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-02-17 16:27:39 +00:00
|
|
|
|
using System.Drawing;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
using System.Linq;
|
2011-02-17 16:27:39 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public partial class RamPoke : Form
|
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
//TODO: don't use textboxes as labels
|
|
|
|
|
|
|
|
|
|
private List<Watch> _watchList = new List<Watch>();
|
|
|
|
|
|
|
|
|
|
public Point InitialLocation = new Point(0, 0);
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
|
|
|
|
public RamPoke()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
public void SetWatch(List<Watch> watches)
|
|
|
|
|
{
|
|
|
|
|
_watchList = watches;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UnSupportedConfiguration()
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
MessageBox.Show("Ram Poke does not support mixed types", "Unsupported Options", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
Close();
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RamPoke_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
_watchList = _watchList.Where(x => !x.IsSeparator).ToList(); //Weed out separators just in case
|
2011-09-17 14:38:21 +00:00
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (_watchList.Count == 0)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
ValueBox.Enabled = false;
|
|
|
|
|
return;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2013-09-14 03:13:22 +00:00
|
|
|
|
|
|
|
|
|
if (InitialLocation.X > 0 || InitialLocation.Y > 0)
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
Location = InitialLocation;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (_watchList.Count > 1)
|
2013-04-14 23:56:45 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
bool hasMixedSizes = _watchList.Select(x => x.Size).Distinct().Count() > 1;
|
|
|
|
|
bool hasMixedTypes = _watchList.Select(x => x.Type).Distinct().Count() > 1;
|
|
|
|
|
bool hasMixedEndian = _watchList.Select(x => x.BigEndian).Distinct().Count() > 1;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (hasMixedSizes || hasMixedTypes || hasMixedEndian)
|
|
|
|
|
{
|
|
|
|
|
UnSupportedConfiguration();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-14 21:31:00 +00:00
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
AddressBox.Text = _watchList.Select(a => a.AddressString).Distinct().Aggregate((addrStr, nextStr) => addrStr + ("," + nextStr));
|
|
|
|
|
ValueHexLabel.Text = _watchList[0].Type == Watch.DisplayType.Hex ? "0x" : String.Empty;
|
|
|
|
|
ValueBox.Text = _watchList[0].ValueString.Replace(" ", "");
|
|
|
|
|
DomainLabel.Text = _watchList[0].Domain.Name;
|
|
|
|
|
SizeLabel.Text = _watchList[0].Size.ToString();
|
|
|
|
|
DisplayTypeLabel.Text = Watch.DisplayTypeToString(_watchList[0].Type);
|
|
|
|
|
BigEndianLabel.Text = _watchList[0].BigEndian ? "Big Endian" : "Little Endian";
|
|
|
|
|
SetTitle();
|
2012-09-14 21:31:00 +00:00
|
|
|
|
SetValueBoxProperties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetValueBoxProperties()
|
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
switch(_watchList[0].Type)
|
2012-09-14 21:31:00 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
default:
|
|
|
|
|
ValueBox.MaxLength = 8;
|
2012-09-14 21:31:00 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Binary:
|
|
|
|
|
switch (_watchList[0].Size)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case Watch.WatchSize.Byte:
|
|
|
|
|
ValueBox.MaxLength = 8;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.Word:
|
|
|
|
|
ValueBox.MaxLength = 16;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-09-14 21:31:00 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Hex:
|
|
|
|
|
switch (_watchList[0].Size)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case Watch.WatchSize.Byte:
|
|
|
|
|
ValueBox.MaxLength = 2;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.Word:
|
|
|
|
|
ValueBox.MaxLength = 4;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.DWord:
|
|
|
|
|
ValueBox.MaxLength = 8;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-09-14 21:31:00 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Signed:
|
|
|
|
|
switch (_watchList[0].Size)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case Watch.WatchSize.Byte:
|
|
|
|
|
ValueBox.MaxLength = 4;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.Word:
|
|
|
|
|
ValueBox.MaxLength = 6;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.DWord:
|
|
|
|
|
ValueBox.MaxLength = 11;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Unsigned:
|
|
|
|
|
switch (_watchList[0].Size)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case Watch.WatchSize.Byte:
|
|
|
|
|
ValueBox.MaxLength = 3;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.Word:
|
|
|
|
|
ValueBox.MaxLength = 5;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.DWord:
|
|
|
|
|
ValueBox.MaxLength = 10;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Float:
|
|
|
|
|
case Watch.DisplayType.FixedPoint_12_4:
|
|
|
|
|
case Watch.DisplayType.FixedPoint_20_12:
|
|
|
|
|
ValueBox.MaxLength = 32;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
private void SetTitle()
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
Text = "Ram Poke - " + _watchList[0].Domain.Name;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
#region Events
|
|
|
|
|
|
2011-06-19 23:39:25 +00:00
|
|
|
|
private void Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
DialogResult = DialogResult.Cancel;
|
2013-04-14 23:56:45 +00:00
|
|
|
|
Close();
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OK_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
bool success = true;
|
|
|
|
|
foreach (var watch in _watchList)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (!watch.Poke(ValueBox.Text))
|
|
|
|
|
{
|
|
|
|
|
success = false;
|
|
|
|
|
}
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (success)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
OutputLabel.Text = "Value successfully written.";
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
OutputLabel.Text = "An error occured when writing Value.";
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
private void ValueBox_KeyPress(object sender, KeyPressEventArgs e)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
return;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (e.KeyChar == '.')
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (ValueBox.Text.Contains('.'))
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2013-09-14 03:13:22 +00:00
|
|
|
|
else if (e.KeyChar == '-')
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
if (ValueBox.Text.Contains('-'))
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
switch(_watchList[0].Type)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Signed:
|
|
|
|
|
if (!InputValidate.IsValidSignedNumber(e.KeyChar))
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
e.Handled = true;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Unsigned:
|
|
|
|
|
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
e.Handled = true;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Hex:
|
2011-06-19 23:39:25 +00:00
|
|
|
|
if (!InputValidate.IsValidHexNumber(e.KeyChar))
|
2012-09-03 23:42:00 +00:00
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
e.Handled = true;
|
2012-09-03 23:42:00 +00:00
|
|
|
|
}
|
2011-06-19 23:39:25 +00:00
|
|
|
|
break;
|
2013-09-14 03:13:22 +00:00
|
|
|
|
case Watch.DisplayType.Binary:
|
|
|
|
|
if (!InputValidate.IsValidBinaryNumber(e.KeyChar))
|
2012-09-03 23:45:41 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
e.Handled = true;
|
2012-09-03 23:45:41 +00:00
|
|
|
|
}
|
2013-09-14 03:13:22 +00:00
|
|
|
|
break;
|
|
|
|
|
case Watch.DisplayType.FixedPoint_12_4:
|
|
|
|
|
case Watch.DisplayType.FixedPoint_20_12:
|
|
|
|
|
if (!InputValidate.IsValidFixedPointNumber(e.KeyChar))
|
2012-09-03 23:45:41 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
e.Handled = true;
|
2012-09-03 23:45:41 +00:00
|
|
|
|
}
|
2013-09-14 03:13:22 +00:00
|
|
|
|
break;
|
|
|
|
|
case Watch.DisplayType.Float:
|
|
|
|
|
if (!InputValidate.IsValidDecimalNumber(e.KeyChar))
|
2012-09-03 23:45:41 +00:00
|
|
|
|
{
|
2013-09-14 03:13:22 +00:00
|
|
|
|
e.Handled = true;
|
2012-09-03 23:45:41 +00:00
|
|
|
|
}
|
2013-09-14 03:13:22 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2011-09-17 16:39:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-13 02:59:32 +00:00
|
|
|
|
|
2013-09-14 03:13:22 +00:00
|
|
|
|
#endregion
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
2011-02-17 16:27:39 +00:00
|
|
|
|
}
|