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;
|
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2011-02-17 16:27:39 +00:00
|
|
|
|
{
|
2011-06-19 23:39:25 +00:00
|
|
|
|
public partial class RamPoke : Form
|
|
|
|
|
{
|
2013-11-29 19:55:05 +00:00
|
|
|
|
// TODO: don't use textboxes as labels
|
2013-09-14 03:13:22 +00:00
|
|
|
|
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-11-25 02:08:45 +00:00
|
|
|
|
public void SetWatch(IEnumerable<Watch> watches)
|
2013-09-14 03:13:22 +00:00
|
|
|
|
{
|
2013-11-25 02:08:45 +00:00
|
|
|
|
_watchList = watches.ToList();
|
2013-09-14 03:13:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-11-29 19:55:05 +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-11-25 02:08:45 +00:00
|
|
|
|
var hasMixedSizes = _watchList.Select(x => x.Size).Distinct().Count() > 1;
|
|
|
|
|
var hasMixedTypes = _watchList.Select(x => x.Type).Distinct().Count() > 1;
|
|
|
|
|
var 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-11-29 19:55:05 +00:00
|
|
|
|
|
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));
|
2014-04-25 20:29:18 +00:00
|
|
|
|
ValueHexLabel.Text = _watchList[0].Type == Watch.DisplayType.Hex ? "0x" : string.Empty;
|
|
|
|
|
ValueBox.Text = _watchList[0].ValueString.Replace(" ", string.Empty);
|
2013-09-14 03:13:22 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 19:55:05 +00:00
|
|
|
|
private void Ok_Click(object sender, EventArgs e)
|
2011-06-19 23:39:25 +00:00
|
|
|
|
{
|
2013-11-29 19:55:05 +00:00
|
|
|
|
var success = _watchList.All(watch => watch.Poke(ValueBox.Text));
|
2013-11-25 02:08:45 +00:00
|
|
|
|
OutputLabel.Text = success ? "Value successfully written."
|
|
|
|
|
: "An error occured when writing Value.";
|
2011-06-19 23:39:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-17 16:27:39 +00:00
|
|
|
|
}
|