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();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-11 17:57:58 +00:00
|
|
|
|
AddressBox.SetHexProperties(_watchList[0].Domain.Size);
|
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
|
|
|
|
|
2013-09-21 17:34:24 +00:00
|
|
|
|
ValueBox.ByteSize = _watchList[0].Size;
|
|
|
|
|
ValueBox.Type = _watchList[0].Type;
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-17 16:27:39 +00:00
|
|
|
|
}
|