New Ram Poke Dialog - progress

This commit is contained in:
adelikat 2013-09-12 01:53:00 +00:00
parent 578efed6bf
commit c4ac0439c1
4 changed files with 376 additions and 259 deletions

View File

@ -30,47 +30,36 @@
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NewRamPoke));
this.label1 = new System.Windows.Forms.Label();
this.AddressBox = new BizHawk.HexTextBox();
this.OK = new System.Windows.Forms.Button();
this.Cancel = new System.Windows.Forms.Button();
this.OutputLabel = new System.Windows.Forms.Label();
this.ValeLabel = new System.Windows.Forms.Label();
this.ValueBox = new System.Windows.Forms.TextBox();
this.ValueHexLabel = new System.Windows.Forms.Label();
this.DomainDropDown = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.BigEndianCheckBox = new System.Windows.Forms.CheckBox();
this.DisplayTypeLael = new System.Windows.Forms.Label();
this.DisplayTypeDropDown = new System.Windows.Forms.ComboBox();
this.DisplayTypeLabel = new System.Windows.Forms.Label();
this.SizeLabel = new System.Windows.Forms.Label();
this.BigEndianLabel = new System.Windows.Forms.Label();
this.AddressBox = new BizHawk.HexTextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SizeDropDown = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(11, 33);
this.label1.Location = new System.Drawing.Point(20, 33);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Address: 0x";
//
// AddressBox
//
this.AddressBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
this.AddressBox.Location = new System.Drawing.Point(73, 30);
this.AddressBox.MaxLength = 8;
this.AddressBox.Name = "AddressBox";
this.AddressBox.Size = new System.Drawing.Size(80, 20);
this.AddressBox.TabIndex = 5;
this.AddressBox.Text = "0000";
//
// OK
//
this.OK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.OK.Location = new System.Drawing.Point(12, 293);
this.OK.Location = new System.Drawing.Point(12, 163);
this.OK.Name = "OK";
this.OK.Size = new System.Drawing.Size(75, 23);
this.OK.Size = new System.Drawing.Size(65, 23);
this.OK.TabIndex = 35;
this.OK.Text = "&Poke";
this.OK.UseVisualStyleBackColor = true;
@ -80,9 +69,9 @@
//
this.Cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Cancel.Location = new System.Drawing.Point(123, 293);
this.Cancel.Location = new System.Drawing.Point(136, 163);
this.Cancel.Name = "Cancel";
this.Cancel.Size = new System.Drawing.Size(75, 23);
this.Cancel.Size = new System.Drawing.Size(65, 23);
this.Cancel.TabIndex = 40;
this.Cancel.Text = "&Close";
this.Cancel.UseVisualStyleBackColor = true;
@ -100,7 +89,7 @@
// ValeLabel
//
this.ValeLabel.AutoSize = true;
this.ValeLabel.Location = new System.Drawing.Point(11, 59);
this.ValeLabel.Location = new System.Drawing.Point(31, 59);
this.ValeLabel.Name = "ValeLabel";
this.ValeLabel.Size = new System.Drawing.Size(37, 13);
this.ValeLabel.TabIndex = 10;
@ -109,96 +98,87 @@
// ValueBox
//
this.ValueBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
this.ValueBox.Location = new System.Drawing.Point(73, 57);
this.ValueBox.Location = new System.Drawing.Point(82, 57);
this.ValueBox.MaxLength = 9;
this.ValueBox.Name = "ValueBox";
this.ValueBox.Size = new System.Drawing.Size(80, 20);
this.ValueBox.Size = new System.Drawing.Size(116, 20);
this.ValueBox.TabIndex = 10;
this.ValueBox.Text = "0000";
this.ValueBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ValueBox_KeyPress);
//
// ValueHexLabel
//
this.ValueHexLabel.AutoSize = true;
this.ValueHexLabel.Location = new System.Drawing.Point(55, 60);
this.ValueHexLabel.Location = new System.Drawing.Point(64, 60);
this.ValueHexLabel.Name = "ValueHexLabel";
this.ValueHexLabel.Size = new System.Drawing.Size(18, 13);
this.ValueHexLabel.TabIndex = 11;
this.ValueHexLabel.Text = "0x";
//
// DomainDropDown
// DisplayTypeLabel
//
this.DomainDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.DomainDropDown.FormattingEnabled = true;
this.DomainDropDown.Location = new System.Drawing.Point(12, 261);
this.DomainDropDown.Name = "DomainDropDown";
this.DomainDropDown.Size = new System.Drawing.Size(141, 21);
this.DomainDropDown.TabIndex = 30;
this.DomainDropDown.SelectedIndexChanged += new System.EventHandler(this.DomainComboBox_SelectedIndexChanged);
this.DisplayTypeLabel.AutoSize = true;
this.DisplayTypeLabel.Location = new System.Drawing.Point(81, 101);
this.DisplayTypeLabel.Name = "DisplayTypeLabel";
this.DisplayTypeLabel.Size = new System.Drawing.Size(52, 13);
this.DisplayTypeLabel.TabIndex = 24;
this.DisplayTypeLabel.Text = "Unsigned";
//
// label6
// SizeLabel
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(11, 245);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(83, 13);
this.label6.TabIndex = 13;
this.label6.Text = "Memory Domain";
this.SizeLabel.AutoSize = true;
this.SizeLabel.Location = new System.Drawing.Point(82, 83);
this.SizeLabel.Name = "SizeLabel";
this.SizeLabel.Size = new System.Drawing.Size(28, 13);
this.SizeLabel.TabIndex = 23;
this.SizeLabel.Text = "Byte";
//
// BigEndianCheckBox
// BigEndianLabel
//
this.BigEndianCheckBox.AutoSize = true;
this.BigEndianCheckBox.Location = new System.Drawing.Point(17, 184);
this.BigEndianCheckBox.Name = "BigEndianCheckBox";
this.BigEndianCheckBox.Size = new System.Drawing.Size(77, 17);
this.BigEndianCheckBox.TabIndex = 25;
this.BigEndianCheckBox.Text = "Big Endian";
this.BigEndianCheckBox.UseVisualStyleBackColor = true;
this.BigEndianLabel.AutoSize = true;
this.BigEndianLabel.Location = new System.Drawing.Point(82, 119);
this.BigEndianLabel.Name = "BigEndianLabel";
this.BigEndianLabel.Size = new System.Drawing.Size(58, 13);
this.BigEndianLabel.TabIndex = 41;
this.BigEndianLabel.Text = "Big Endian";
//
// DisplayTypeLael
// AddressBox
//
this.DisplayTypeLael.AutoSize = true;
this.DisplayTypeLael.Location = new System.Drawing.Point(14, 131);
this.DisplayTypeLael.Name = "DisplayTypeLael";
this.DisplayTypeLael.Size = new System.Drawing.Size(68, 13);
this.DisplayTypeLael.TabIndex = 24;
this.DisplayTypeLael.Text = "Display Type";
this.AddressBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
this.AddressBox.Enabled = false;
this.AddressBox.Location = new System.Drawing.Point(82, 30);
this.AddressBox.MaxLength = 8;
this.AddressBox.Name = "AddressBox";
this.AddressBox.Size = new System.Drawing.Size(116, 20);
this.AddressBox.TabIndex = 5;
this.AddressBox.Text = "0000";
//
// DisplayTypeDropDown
// label2
//
this.DisplayTypeDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.DisplayTypeDropDown.FormattingEnabled = true;
this.DisplayTypeDropDown.Items.AddRange(new object[] {
"1 Byte",
"2 Byte",
"4 Byte"});
this.DisplayTypeDropDown.Location = new System.Drawing.Point(15, 147);
this.DisplayTypeDropDown.Name = "DisplayTypeDropDown";
this.DisplayTypeDropDown.Size = new System.Drawing.Size(141, 21);
this.DisplayTypeDropDown.TabIndex = 20;
this.DisplayTypeDropDown.SelectedIndexChanged += new System.EventHandler(this.DisplayTypeDropDown_SelectedIndexChanged);
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(39, 119);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(43, 13);
this.label2.TabIndex = 44;
this.label2.Text = "Endian:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 89);
this.label3.Location = new System.Drawing.Point(11, 101);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(27, 13);
this.label3.TabIndex = 23;
this.label3.Text = "Size";
this.label3.Size = new System.Drawing.Size(71, 13);
this.label3.TabIndex = 43;
this.label3.Text = "Display Type:";
//
// SizeDropDown
// label4
//
this.SizeDropDown.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.SizeDropDown.FormattingEnabled = true;
this.SizeDropDown.Items.AddRange(new object[] {
"1 Byte",
"2 Byte",
"4 Byte"});
this.SizeDropDown.Location = new System.Drawing.Point(13, 105);
this.SizeDropDown.Name = "SizeDropDown";
this.SizeDropDown.Size = new System.Drawing.Size(141, 21);
this.SizeDropDown.TabIndex = 15;
this.SizeDropDown.SelectedIndexChanged += new System.EventHandler(this.SizeDropDown_SelectedIndexChanged);
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(52, 83);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(30, 13);
this.label4.TabIndex = 42;
this.label4.Text = "Size:";
//
// NewRamPoke
//
@ -206,14 +186,13 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.Cancel;
this.ClientSize = new System.Drawing.Size(213, 332);
this.Controls.Add(this.BigEndianCheckBox);
this.Controls.Add(this.DisplayTypeLael);
this.Controls.Add(this.DisplayTypeDropDown);
this.ClientSize = new System.Drawing.Size(213, 202);
this.Controls.Add(this.label2);
this.Controls.Add(this.label3);
this.Controls.Add(this.SizeDropDown);
this.Controls.Add(this.label6);
this.Controls.Add(this.DomainDropDown);
this.Controls.Add(this.label4);
this.Controls.Add(this.BigEndianLabel);
this.Controls.Add(this.DisplayTypeLabel);
this.Controls.Add(this.SizeLabel);
this.Controls.Add(this.ValueHexLabel);
this.Controls.Add(this.ValueBox);
this.Controls.Add(this.ValeLabel);
@ -244,12 +223,11 @@
private System.Windows.Forms.Label ValeLabel;
private System.Windows.Forms.TextBox ValueBox;
private System.Windows.Forms.Label ValueHexLabel;
private System.Windows.Forms.ComboBox DomainDropDown;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.CheckBox BigEndianCheckBox;
private System.Windows.Forms.Label DisplayTypeLael;
private System.Windows.Forms.ComboBox DisplayTypeDropDown;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox SizeDropDown;
private System.Windows.Forms.Label DisplayTypeLabel;
private System.Windows.Forms.Label SizeLabel;
private System.Windows.Forms.Label BigEndianLabel;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
}
}

View File

@ -8,14 +8,10 @@ namespace BizHawk.MultiClient
{
public partial class NewRamPoke : Form
{
//TODO: don't use textboxes as labels
private List<Watch> _watchList = new List<Watch>();
private bool _loading = true;
private string _addressFormatStr = "{0:X2}";
private bool _changedSize = false;
private bool _changedDisplayType = false;
public List<Watch> Watches { get { return _watchList; } }
public Point InitialLocation = new Point(0, 0);
public NewRamPoke()
@ -23,138 +19,127 @@ namespace BizHawk.MultiClient
InitializeComponent();
}
public void SetWatch(List<Watch> watches = null)
public void SetWatch(List<Watch> watches)
{
if (watches != null)
{
_watchList.AddRange(watches);
_watchList = watches;
}
DoMemoryDomainDropdown(_watchList.Count == 1 ? _watchList[0].Domain : Global.Emulator.MainMemory);
SetTitle();
}
private void DoMemoryDomainDropdown(MemoryDomain startDomain)
private void UnSupportedConfiguration()
{
DomainDropDown.Items.Clear();
if (Global.Emulator.MemoryDomains.Count > 0)
{
foreach (MemoryDomain domain in Global.Emulator.MemoryDomains)
{
var result = DomainDropDown.Items.Add(domain.ToString());
if (domain.Name == startDomain.Name)
{
DomainDropDown.SelectedIndex = result;
}
}
}
MessageBox.Show("Ram Poke does not support mixed types", "Unsupported Options", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
}
private void RamPoke_Load(object sender, EventArgs e)
{
_watchList = _watchList.Where(x => !x.IsSeparator).ToList(); //Weed out separators just in case
if (_watchList.Count == 0)
{
ValueBox.Enabled = false;
return;
}
if (InitialLocation.X > 0 || InitialLocation.Y > 0)
{
Location = InitialLocation;
}
if (_watchList.Count == 0)
if (_watchList.Count > 1)
{
DoMemoryDomainDropdown(Global.Emulator.MainMemory);
}
else
{
if (_watchList.Count > 1)
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;
if (hasMixedSizes || hasMixedTypes || hasMixedEndian)
{
AddressBox.Enabled = false;
AddressBox.Text = _watchList.Select(a => a.AddressString).Aggregate((addrStr, nextStr) => addrStr + ("," + nextStr));
BigEndianCheckBox.ThreeState = true;
DoMemoryDomainDropdown(Global.Emulator.MainMemory);
DomainDropDown.Enabled = false;
SetBigEndianCheckBox();
//TODO: Mixed displaytypes are a problem for a value box!
//TODO: Mixed size types are a problem
UnSupportedConfiguration();
}
else
{
ValueHexLabel.Text = _watchList[0].Type == Watch.DisplayType.Hex ? "0x" : String.Empty;
}
AddressBox.Text = _watchList[0].AddressString;
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;
SizeLabel.Text = _watchList[0].Size.ToString();
DisplayTypeLabel.Text = Watch.DisplayTypeToString(_watchList[0].Type);
BigEndianLabel.Text = _watchList[0].BigEndian ? "Big Endian" : "Little Endian";
}
private void SetValueBoxProperties()
{
switch(_watchList[0].Type)
{
default:
ValueBox.MaxLength = 8;
break;
case Watch.DisplayType.Binary:
switch (_watchList[0].Size)
{
default:
case Watch.WatchSize.Byte:
SizeDropDown.SelectedItem = SizeDropDown.Items[0];
ValueBox.MaxLength = 8;
break;
case Watch.WatchSize.Word:
SizeDropDown.SelectedItem = SizeDropDown.Items[1];
ValueBox.MaxLength = 16;
break;
}
break;
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:
SizeDropDown.SelectedItem = SizeDropDown.Items[2];
ValueBox.MaxLength = 8;
break;
}
//TODO: type
DoMemoryDomainDropdown(_watchList[0].Domain);
SetBigEndianCheckBox();
}
}
}
private void SetAddressBoxProperties()
{
if (!_loading)
{
var domain = Global.Emulator.MemoryDomains.FirstOrDefault(d => d.Name == DomainDropDown.SelectedItem.ToString());
if (domain != null)
{
AddressBox.MaxLength = IntHelpers.GetNumDigits(domain.Size - 1);
_addressFormatStr = "{0:X" + AddressBox.MaxLength.ToString() + "}";
AddressBox.Text = String.Format(_addressFormatStr, 0);
}
}
}
private void SetBigEndianCheckBox()
{
if (_watchList != null)
{
if (_watchList.Count > 1)
{
//Aggregate state
var hasBig = _watchList.Any(x => x.BigEndian);
var hasLittle = _watchList.Any(x => x.BigEndian == false);
if (hasBig && hasLittle)
break;
case Watch.DisplayType.Signed:
switch (_watchList[0].Size)
{
BigEndianCheckBox.Checked = true;
BigEndianCheckBox.CheckState = CheckState.Indeterminate;
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;
}
else if (hasBig)
break;
case Watch.DisplayType.Unsigned:
switch (_watchList[0].Size)
{
BigEndianCheckBox.Checked = true;
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;
}
else
{
BigEndianCheckBox.Checked = false;
}
}
else if (_watchList.Count == 1)
{
BigEndianCheckBox.Checked = _watchList[0].BigEndian;
return;
}
break;
case Watch.DisplayType.Float:
case Watch.DisplayType.FixedPoint_12_4:
case Watch.DisplayType.FixedPoint_20_12:
ValueBox.MaxLength = 32;
break;
}
var domain = Global.Emulator.MemoryDomains.FirstOrDefault(d => d.Name == DomainDropDown.SelectedItem.ToString());
if (domain == null)
{
domain = Global.Emulator.MainMemory;
}
BigEndianCheckBox.Checked = domain.Endian == Endian.Big ? true : false;
_loading = false;
SetAddressBoxProperties();
}
private void SetTitle()
@ -162,25 +147,6 @@ namespace BizHawk.MultiClient
Text = "Ram Poke - " + _watchList[0].Domain;
}
private void SetDisplayTypes()
{
DisplayTypeDropDown.Items.Clear();
switch (SizeDropDown.SelectedIndex)
{
default:
case 0:
DisplayTypeDropDown.Items.AddRange(ByteWatch.ValidTypes.ConvertAll<string>(e => Watch.DisplayTypeToString(e)).ToArray());
break;
case 1:
DisplayTypeDropDown.Items.AddRange(WordWatch.ValidTypes.ConvertAll<string>(e => Watch.DisplayTypeToString(e)).ToArray());
break;
case 2:
DisplayTypeDropDown.Items.AddRange(DWordWatch.ValidTypes.ConvertAll<string>(e => Watch.DisplayTypeToString(e)).ToArray());
break;
}
DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[0];
}
#region Events
private void Cancel_Click(object sender, EventArgs e)
@ -196,29 +162,54 @@ namespace BizHawk.MultiClient
OutputLabel.Text = ValueBox.Text + " written to " + AddressBox.Text;
}
private void SizeDropDown_SelectedIndexChanged(object sender, EventArgs e)
private void ValueBox_KeyPress(object sender, KeyPressEventArgs e)
{
SetDisplayTypes();
_changedSize = true;
if (!DisplayTypeDropDown.Enabled)
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
{
DisplayTypeDropDown.Enabled = true;
_changedDisplayType = true;
return;
}
switch(_watchList[0].Type)
{
case Watch.DisplayType.Signed:
if (!InputValidate.IsValidSignedNumber(e.KeyChar))
{
e.Handled = true;
}
break;
case Watch.DisplayType.Unsigned:
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
{
e.Handled = true;
}
break;
case Watch.DisplayType.Hex:
if (!InputValidate.IsValidHexNumber(e.KeyChar))
{
e.Handled = true;
}
break;
case Watch.DisplayType.Binary:
if (!InputValidate.IsValidBinaryNumber(e.KeyChar))
{
e.Handled = true;
}
break;
case Watch.DisplayType.FixedPoint_12_4:
case Watch.DisplayType.FixedPoint_20_12:
if (!InputValidate.IsValidFixedPointNumber(e.KeyChar))
{
e.Handled = true;
}
break;
case Watch.DisplayType.Float:
if (!InputValidate.IsValidDecimalNumber(e.KeyChar))
{
e.Handled = true;
}
break;
}
}
private void DisplayTypeDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
_changedDisplayType = true;
}
private void DomainComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SetAddressBoxProperties();
SetBigEndianCheckBox();
_changedSize = true;
_changedDisplayType = true;
}
#endregion

View File

@ -50,28 +50,18 @@ namespace BizHawk.MultiClient
public abstract string ValueString { get; }
public abstract WatchSize Size { get; }
public abstract void Poke(int value);
public virtual DisplayType Type { get { return _type; } set { _type = value; } }
public virtual bool BigEndian { get { return _bigEndian; } set { _bigEndian = value; } }
public MemoryDomain Domain
{
get { return _domain; }
}
public MemoryDomain Domain { get { return _domain; } }
public virtual int? Address
{
get { return _address; }
}
public virtual int? Address { get { return _address; } }
public virtual string AddressString
{
get { return _address.ToString(AddressFormatStr); }
}
public virtual string AddressString { get { return _address.ToString(AddressFormatStr); } }
public virtual bool IsSeparator
{
get { return false; }
}
public virtual bool IsSeparator { get { return false; } }
public char SizeAsChar
{
@ -209,6 +199,43 @@ namespace BizHawk.MultiClient
}
}
protected void PokeByte(byte val)
{
_domain.PokeByte(_address, val);
}
protected void PokeWord(ushort val)
{
if (_bigEndian)
{
_domain.PokeByte(_address + 0, (byte)(val >> 8));
_domain.PokeByte(_address + 1, (byte)(val));
}
else
{
_domain.PokeByte(_address + 0, (byte)(val));
_domain.PokeByte(_address + 1, (byte)(val >> 8));
}
}
protected void PokeDWord(uint val)
{
if (_bigEndian)
{
_domain.PokeByte(_address + 0, (byte)(val >> 24));
_domain.PokeByte(_address + 1, (byte)(val >> 16));
_domain.PokeByte(_address + 2, (byte)(val >> 8));
_domain.PokeByte(_address + 3, (byte)(val));
}
else
{
_domain.PokeByte(_address + 0, (byte)(val));
_domain.PokeByte(_address + 1, (byte)(val >> 8));
_domain.PokeByte(_address + 2, (byte)(val >> 16));
_domain.PokeByte(_address + 3, (byte)(val >> 24));
}
}
public static Watch GenerateWatch(MemoryDomain domain, int address, WatchSize size, bool details)
{
switch (size)
@ -267,10 +294,7 @@ namespace BizHawk.MultiClient
public static SeparatorWatch Instance
{
get
{
return new SeparatorWatch();
}
get { return new SeparatorWatch(); }
}
public override int? Address
@ -317,6 +341,11 @@ namespace BizHawk.MultiClient
{
get { return DisplayType.Separator; }
}
public override void Poke(int value)
{
/*Do Nothing*/
}
}
public class ByteWatch : Watch
@ -383,6 +412,11 @@ namespace BizHawk.MultiClient
return Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " ");
}
}
public override void Poke(int value)
{
PokeByte((byte)value); //TODO: display types
}
}
public class DetailedByteWatch : ByteWatch, IWatchDetails
@ -514,6 +548,11 @@ namespace BizHawk.MultiClient
return Convert.ToString(val, 2).PadLeft(16, '0').Insert(8, " ").Insert(4, " ").Insert(14, " ");
}
}
public override void Poke(int value)
{
PokeWord((ushort)value); //TODO: display types
}
}
public class DetailedWordWatch : WordWatch, IWatchDetails
@ -635,6 +674,11 @@ namespace BizHawk.MultiClient
return String.Format("{0:F6}", _float);
}
}
public override void Poke(int value)
{
PokeDWord((uint)value); //TODO: display types
}
}
public class DetailedDWordWatch : DWordWatch, IWatchDetails

View File

@ -73,7 +73,6 @@ namespace BizHawk
return true;
}
/// <summary>
/// validates is a Hex number 0-9, A-F (must be capital letters)
/// </summary>
@ -146,5 +145,110 @@ namespace BizHawk
}
return output.ToString();
}
public static bool IsValidBinaryNumber(string s)
{
char[] input = (s.ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] != 47 && bc[0] != 48) //0 or 1
{
return false;
}
}
return true;
}
public static bool IsValidBinaryNumber(char c)
{
return (c == 47 || c == 48);
}
/// <summary>
/// Validates all chars are 0-9 or decimal
/// </summary>
/// <param name="Str"></param>
/// <returns></returns>
public static bool IsValidFixedPointNumber(string Str)
{
char[] input = (Str.Trim().ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] > 58)
return false;
if (bc[0] < 46)
{
if (bc[0] == 45 && x == 0)
continue;
else
return false;
}
}
return true;
}
public static bool IsValidFixedPointNumber(char c)
{
if (c == 46) return true;
if (c < 47 || c > 58)
return false;
return true;
}
/// <summary>
/// Validates all chars are 0-9 or decimal or dash as the first character
/// </summary>
/// <param name="Str"></param>
/// <returns></returns>
public static bool IsValidDecimalNumber(string Str)
{
char[] input = (Str.Trim().ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] > 58)
return false;
if (bc[0] < 46)
{
if (bc[0] == 45 && x == 0)
continue;
else
return false;
}
}
return true;
}
public static bool IsValidDecimalNumber(char c)
{
if (c < 45 || c > 58) //45 = dash, 46 = dot
return false;
return true;
}
}
}