diff --git a/BizHawk.MultiClient/tools/Watch/NewRamPoke.Designer.cs b/BizHawk.MultiClient/tools/Watch/NewRamPoke.Designer.cs index b5ecc3b756..c85a53cd44 100644 --- a/BizHawk.MultiClient/tools/Watch/NewRamPoke.Designer.cs +++ b/BizHawk.MultiClient/tools/Watch/NewRamPoke.Designer.cs @@ -43,6 +43,8 @@ this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.DomainLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 @@ -57,7 +59,7 @@ // 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, 163); + this.OK.Location = new System.Drawing.Point(12, 169); this.OK.Name = "OK"; this.OK.Size = new System.Drawing.Size(65, 23); this.OK.TabIndex = 35; @@ -69,7 +71,7 @@ // 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(136, 163); + this.Cancel.Location = new System.Drawing.Point(136, 169); this.Cancel.Name = "Cancel"; this.Cancel.Size = new System.Drawing.Size(65, 23); this.Cancel.TabIndex = 40; @@ -118,7 +120,7 @@ // DisplayTypeLabel // this.DisplayTypeLabel.AutoSize = true; - this.DisplayTypeLabel.Location = new System.Drawing.Point(81, 101); + this.DisplayTypeLabel.Location = new System.Drawing.Point(81, 118); this.DisplayTypeLabel.Name = "DisplayTypeLabel"; this.DisplayTypeLabel.Size = new System.Drawing.Size(52, 13); this.DisplayTypeLabel.TabIndex = 24; @@ -127,7 +129,7 @@ // SizeLabel // this.SizeLabel.AutoSize = true; - this.SizeLabel.Location = new System.Drawing.Point(82, 83); + this.SizeLabel.Location = new System.Drawing.Point(82, 101); this.SizeLabel.Name = "SizeLabel"; this.SizeLabel.Size = new System.Drawing.Size(28, 13); this.SizeLabel.TabIndex = 23; @@ -136,7 +138,7 @@ // BigEndianLabel // this.BigEndianLabel.AutoSize = true; - this.BigEndianLabel.Location = new System.Drawing.Point(82, 119); + this.BigEndianLabel.Location = new System.Drawing.Point(82, 135); this.BigEndianLabel.Name = "BigEndianLabel"; this.BigEndianLabel.Size = new System.Drawing.Size(58, 13); this.BigEndianLabel.TabIndex = 41; @@ -156,7 +158,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(39, 119); + this.label2.Location = new System.Drawing.Point(39, 135); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(43, 13); this.label2.TabIndex = 44; @@ -165,7 +167,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(11, 101); + this.label3.Location = new System.Drawing.Point(11, 118); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(71, 13); this.label3.TabIndex = 43; @@ -174,19 +176,39 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(52, 83); + this.label4.Location = new System.Drawing.Point(52, 101); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(30, 13); this.label4.TabIndex = 42; this.label4.Text = "Size:"; // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(36, 84); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(46, 13); + this.label5.TabIndex = 46; + this.label5.Text = "Domain:"; + // + // DomainLabel + // + this.DomainLabel.AutoSize = true; + this.DomainLabel.Location = new System.Drawing.Point(82, 84); + this.DomainLabel.Name = "DomainLabel"; + this.DomainLabel.Size = new System.Drawing.Size(70, 13); + this.DomainLabel.TabIndex = 45; + this.DomainLabel.Text = "Main Memory"; + // // NewRamPoke // this.AcceptButton = this.OK; 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, 202); + this.ClientSize = new System.Drawing.Size(213, 208); + this.Controls.Add(this.label5); + this.Controls.Add(this.DomainLabel); this.Controls.Add(this.label2); this.Controls.Add(this.label3); this.Controls.Add(this.label4); @@ -229,5 +251,7 @@ private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label DomainLabel; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/Watch/NewRamPoke.cs b/BizHawk.MultiClient/tools/Watch/NewRamPoke.cs index a0ae0910cb..e5dfe10fd8 100644 --- a/BizHawk.MultiClient/tools/Watch/NewRamPoke.cs +++ b/BizHawk.MultiClient/tools/Watch/NewRamPoke.cs @@ -21,12 +21,7 @@ namespace BizHawk.MultiClient public void SetWatch(List watches) { - if (watches != null) - { - _watchList = watches; - } - - SetTitle(); + _watchList = watches; } private void UnSupportedConfiguration() @@ -64,10 +59,12 @@ namespace BizHawk.MultiClient 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; + 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(); } private void SetValueBoxProperties() @@ -144,7 +141,7 @@ namespace BizHawk.MultiClient private void SetTitle() { - Text = "Ram Poke - " + _watchList[0].Domain; + Text = "Ram Poke - " + _watchList[0].Domain.Name; } #region Events @@ -157,9 +154,23 @@ namespace BizHawk.MultiClient private void OK_Click(object sender, EventArgs e) { - //TODO + bool success = true; + foreach (var watch in _watchList) + { + if (!watch.Poke(ValueBox.Text)) + { + success = false; + } + } - OutputLabel.Text = ValueBox.Text + " written to " + AddressBox.Text; + if (success) + { + OutputLabel.Text = "Value successfully written."; + } + else + { + OutputLabel.Text = "An error occured when writing Value."; + } } private void ValueBox_KeyPress(object sender, KeyPressEventArgs e) @@ -168,7 +179,15 @@ namespace BizHawk.MultiClient { return; } - + + if (e.KeyChar == '.') + { + if (ValueBox.Text.Contains('.')) + { + e.Handled = true; + } + } + switch(_watchList[0].Type) { case Watch.DisplayType.Signed: diff --git a/BizHawk.MultiClient/tools/Watch/NewRamWatch.cs b/BizHawk.MultiClient/tools/Watch/NewRamWatch.cs index 0d30c352ae..ab72902cda 100644 --- a/BizHawk.MultiClient/tools/Watch/NewRamWatch.cs +++ b/BizHawk.MultiClient/tools/Watch/NewRamWatch.cs @@ -526,23 +526,26 @@ namespace BizHawk.MultiClient private void PokeAddress() { - NewRamPoke poke = new NewRamPoke() - { - InitialLocation = GetPromptPoint() - }; - if (SelectedWatches.Any()) { - poke.SetWatch(SelectedWatches); - } + NewRamPoke poke = new NewRamPoke() + { + InitialLocation = GetPromptPoint() + }; - Global.Sound.StopSound(); - var result = poke.ShowDialog(); - if (result == DialogResult.OK) - { - UpdateValues(); + if (SelectedWatches.Any()) + { + poke.SetWatch(SelectedWatches); + } + + Global.Sound.StopSound(); + var result = poke.ShowDialog(); + if (result == DialogResult.OK) + { + UpdateValues(); + } + Global.Sound.StartSound(); } - Global.Sound.StartSound(); } private List SelectedWatches diff --git a/BizHawk.MultiClient/tools/Watch/Watch.cs b/BizHawk.MultiClient/tools/Watch/Watch.cs index 30a8b6acf2..85b26b5648 100644 --- a/BizHawk.MultiClient/tools/Watch/Watch.cs +++ b/BizHawk.MultiClient/tools/Watch/Watch.cs @@ -50,7 +50,7 @@ namespace BizHawk.MultiClient public abstract string ValueString { get; } public abstract WatchSize Size { get; } - public abstract void Poke(int value); + public abstract bool Poke(string value); public virtual DisplayType Type { get { return _type; } set { _type = value; } } public virtual bool BigEndian { get { return _bigEndian; } set { _bigEndian = value; } } @@ -342,9 +342,9 @@ namespace BizHawk.MultiClient get { return DisplayType.Separator; } } - public override void Poke(int value) + public override bool Poke(string value) { - /*Do Nothing*/ + return false; } } @@ -413,9 +413,62 @@ namespace BizHawk.MultiClient } } - public override void Poke(int value) + public override bool Poke(string value) { - PokeByte((byte)value); //TODO: display types + try + { + byte val = 0; + switch (Type) + { + case DisplayType.Unsigned: + if (InputValidate.IsValidUnsignedNumber(value)) + { + val = (byte)int.Parse(value); + } + else + { + return false; + } + break; + case DisplayType.Signed: + if (InputValidate.IsValidSignedNumber(value)) + { + val = (byte)(sbyte)int.Parse(value); + } + else + { + return false; + } + break; + case DisplayType.Hex: + if (InputValidate.IsValidHexNumber(value)) + { + val = (byte)int.Parse(value, NumberStyles.HexNumber); + } + else + { + return false; + } + break; + case DisplayType.Binary: + if (InputValidate.IsValidBinaryNumber(value)) + { + val = (byte)Convert.ToInt32(value, 2); + } + else + { + return false; + } + break; + } + + PokeByte(val); + return true; + } + catch + { + return false; + } } } @@ -549,9 +602,71 @@ namespace BizHawk.MultiClient } } - public override void Poke(int value) + public override bool Poke(string value) { - PokeWord((ushort)value); //TODO: display types + try + { + ushort val = 0; + switch (Type) + { + case DisplayType.Unsigned: + if (InputValidate.IsValidUnsignedNumber(value)) + { + val = (ushort)int.Parse(value); + } + else + { + return false; + } + break; + case DisplayType.Signed: + if (InputValidate.IsValidSignedNumber(value)) + { + val = (ushort)(short)int.Parse(value); + } + else + { + return false; + } + break; + case DisplayType.Hex: + if (InputValidate.IsValidHexNumber(value)) + { + val = (ushort)int.Parse(value, NumberStyles.HexNumber); + } + else + { + return false; + } + break; + case DisplayType.Binary: + if (InputValidate.IsValidBinaryNumber(value)) + { + val = (ushort)Convert.ToInt32(value, 2); + } + else + { + return false; + } + break; + case DisplayType.FixedPoint_12_4: + if (InputValidate.IsValidFixedPointNumber(value)) + { + //TODO + } + else + { + return false; + } + break; + } + PokeWord(val); + return true; + } + catch + { + return false; + } } } @@ -675,9 +790,71 @@ namespace BizHawk.MultiClient } } - public override void Poke(int value) + public override bool Poke(string value) { - PokeDWord((uint)value); //TODO: display types + try + { + uint val = 0; + switch (Type) + { + case DisplayType.Unsigned: + if (InputValidate.IsValidUnsignedNumber(value)) + { + val = (uint)int.Parse(value); + } + else + { + return false; + } + break; + case DisplayType.Signed: + if (InputValidate.IsValidSignedNumber(value)) + { + val = (uint)int.Parse(value); + } + else + { + return false; + } + break; + case DisplayType.Hex: + if (InputValidate.IsValidHexNumber(value)) + { + val = (uint)int.Parse(value, NumberStyles.HexNumber); + } + else + { + return false; + } + break; + case DisplayType.FixedPoint_20_12: + if (InputValidate.IsValidFixedPointNumber(value)) + { + //TODO + } + else + { + return false; + } + break; + case DisplayType.Float: + if (InputValidate.IsValidDecimalNumber(value)) + { + //TODO + } + else + { + return false; + } + break; + } + PokeDWord(val); + return true; + } + catch + { + return false; + } } } diff --git a/BizHawk.MultiClient/tools/Watch/WatchEditor.cs b/BizHawk.MultiClient/tools/Watch/WatchEditor.cs index d445cba14e..20db7124c2 100644 --- a/BizHawk.MultiClient/tools/Watch/WatchEditor.cs +++ b/BizHawk.MultiClient/tools/Watch/WatchEditor.cs @@ -300,11 +300,13 @@ namespace BizHawk.MultiClient size = Watch.WatchSize.DWord; break; } + string tempNotes = (_watchList[i] as IWatchDetails).Notes; _watchList[i] = Watch.GenerateWatch( _watchList[i].Domain, _watchList.Count == 1 ? AddressBox.ToInt() : _watchList[i].Address.Value, size, details: true); + (_watchList[i] as IWatchDetails).Notes = tempNotes; } } if (_changedDisplayType) diff --git a/BizHawk.Util/InputValidate.cs b/BizHawk.Util/InputValidate.cs index 11d33beec8..071c436a5c 100644 --- a/BizHawk.Util/InputValidate.cs +++ b/BizHawk.Util/InputValidate.cs @@ -158,7 +158,7 @@ namespace BizHawk 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 + if (bc[0] != 48 && bc[0] != 49) //0 or 1 { return false; } @@ -168,7 +168,7 @@ namespace BizHawk public static bool IsValidBinaryNumber(char c) { - return (c == 47 || c == 48); + return (c == 48 || c == 49); } /// @@ -178,21 +178,30 @@ namespace BizHawk /// public static bool IsValidFixedPointNumber(string Str) { + if (StringHelpers.HowMany(Str, '.') > 1) + { + return false; + } + 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) + if (bc[x] > 58) return false; - if (bc[0] < 46) + if (bc[x] == 46) + continue; + + if (bc[0] < 48) { - if (bc[0] == 45 && x == 0) + if (bc[x] == 45 && x == 0) continue; else return false; @@ -204,9 +213,9 @@ namespace BizHawk public static bool IsValidFixedPointNumber(char c) { - if (c == 46) return true; + if (c == 46 || c == 45) return true; - if (c < 47 || c > 58) + if (c < 48 || c > 58) return false; return true; @@ -219,6 +228,11 @@ namespace BizHawk /// public static bool IsValidDecimalNumber(string Str) { + if (StringHelpers.HowMany(Str, '.') > 1) + { + return false; + } + char[] input = (Str.Trim().ToCharArray()); ASCIIEncoding AE = new ASCIIEncoding(); // Check each character in the new label to determine if it is a number. @@ -228,12 +242,12 @@ namespace BizHawk byte[] bc = AE.GetBytes(input[x].ToString()); // Determine if the ASCII code is within the valid range of numerical values. - if (bc[0] > 58) + if (bc[x] > 58) return false; - if (bc[0] < 46) + if (bc[x] < 48) { - if (bc[0] == 45 && x == 0) + if (bc[x] == 45 && x == 0) continue; else return false; @@ -245,7 +259,7 @@ namespace BizHawk public static bool IsValidDecimalNumber(char c) { - if (c < 45 || c > 58) //45 = dash, 46 = dot + if (c < 48 || c > 58) //45 = dash, 46 = dot return false; return true;