From 15ad1d32343fe9f95b53e1180d176211a4c7440e Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 28 Sep 2013 20:20:43 +0000 Subject: [PATCH] Ram Search - fix some problems with specific value, float is still broken but fixed points should now work --- BizHawk.MultiClient/tools/Watch/RamSearch.cs | 52 ++++++++++++++++++- .../tools/Watch/WatchEditor.cs | 4 +- .../tools/Watch/WatchValueBox.cs | 17 ++++-- BizHawk.Util/HexTextBox.cs | 14 ++--- 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/BizHawk.MultiClient/tools/Watch/RamSearch.cs b/BizHawk.MultiClient/tools/Watch/RamSearch.cs index 0644bff254..197d0cf861 100644 --- a/BizHawk.MultiClient/tools/Watch/RamSearch.cs +++ b/BizHawk.MultiClient/tools/Watch/RamSearch.cs @@ -225,8 +225,56 @@ namespace BizHawk.MultiClient UpdateUndoToolBarButtons(); } + private int? CompareToValue + { + get + { + if (PreviousValueRadio.Checked) + { + return null; + } + else if (SpecificValueRadio.Checked) + { + return SpecificValueBox.ToRawInt(); + } + else if (SpecificAddressRadio.Checked) + { + return SpecificAddressBox.ToRawInt(); + } + else if (NumberOfChangesRadio.Checked) + { + return NumberOfChangesBox.ToRawInt(); + } + else if (DifferenceRadio.Checked) + { + return DifferenceBox.ToRawInt(); + } + else + { + return null; + } + } + } + + private int? DifferentByValue + { + get + { + if (DifferentByRadio.Checked) + { + return DifferentByBox.ToRawInt(); + } + else + { + return null; + } + } + } + private void DoSearch() { + Searches.CompareValue = CompareToValue; + Searches.DifferentBy = DifferentByValue; int removed = Searches.DoSearch(); SetTotal(); WatchListView.ItemCount = Searches.Count; @@ -1176,7 +1224,7 @@ namespace BizHawk.MultiClient private void CompareToValue_TextChanged(object sender, EventArgs e) { - SetCompareValue((sender as INumberBox).ToInt()); + SetCompareValue((sender as INumberBox).ToRawInt()); } #endregion @@ -1234,7 +1282,7 @@ namespace BizHawk.MultiClient { if (!String.IsNullOrWhiteSpace(DifferentByBox.Text)) { - Searches.DifferentBy = DifferentByBox.ToInt(); + Searches.DifferentBy = DifferentByBox.ToRawInt(); } else { diff --git a/BizHawk.MultiClient/tools/Watch/WatchEditor.cs b/BizHawk.MultiClient/tools/Watch/WatchEditor.cs index 633c9acfce..2a7921526c 100644 --- a/BizHawk.MultiClient/tools/Watch/WatchEditor.cs +++ b/BizHawk.MultiClient/tools/Watch/WatchEditor.cs @@ -217,7 +217,7 @@ namespace BizHawk.MultiClient default: case Mode.New: var domain = Global.Emulator.MemoryDomains.FirstOrDefault(d => d.Name == DomainDropDown.SelectedItem.ToString()); - var address = AddressBox.ToInt(); + var address = AddressBox.ToRawInt(); var notes = NotesBox.Text; var type = Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()); var bigendian = BigEndianCheckBox.Checked; @@ -285,7 +285,7 @@ namespace BizHawk.MultiClient string tempNotes = _watchList[i].Notes; _watchList[i] = Watch.GenerateWatch( _watchList[i].Domain, - _watchList.Count == 1 ? AddressBox.ToInt() : _watchList[i].Address.Value, + _watchList.Count == 1 ? AddressBox.ToRawInt() : _watchList[i].Address.Value, size, _watchList[i].Type, _watchList[i].Notes, diff --git a/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs b/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs index 569281cb69..de93ce4674 100644 --- a/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs +++ b/BizHawk.MultiClient/tools/Watch/WatchValueBox.cs @@ -177,7 +177,7 @@ namespace BizHawk.MultiClient { if (e.KeyCode == Keys.Up) { - int val = ToInt(); + int val = ToRawInt(); val++; switch (_type) @@ -195,7 +195,7 @@ namespace BizHawk.MultiClient } else if (e.KeyCode == Keys.Down) { - int val = ToInt(); + int val = ToRawInt(); val--; switch (_type) @@ -225,7 +225,7 @@ namespace BizHawk.MultiClient } } - public int ToInt() + public int ToRawInt() { if (String.IsNullOrWhiteSpace(Text)) { @@ -236,11 +236,22 @@ namespace BizHawk.MultiClient switch (_type) { default: + case Watch.DisplayType.Signed: return int.Parse(Text); + case Watch.DisplayType.Unsigned: + return (int)uint.Parse(Text); case Watch.DisplayType.Binary: return Convert.ToInt32(Text, 2); case Watch.DisplayType.Hex: return int.Parse(Text, NumberStyles.HexNumber); + case Watch.DisplayType.FixedPoint_12_4: + return (int)(double.Parse(Text) * 16.0); + case Watch.DisplayType.FixedPoint_20_12: + return (int)(double.Parse(Text) * 4096.0); + case Watch.DisplayType.Float: + float val = float.Parse(Text); + byte[] bytes = BitConverter.GetBytes(val); + return BitConverter.ToInt32(bytes, 0); } } } diff --git a/BizHawk.Util/HexTextBox.cs b/BizHawk.Util/HexTextBox.cs index 64652fadba..7ed0a7dc07 100644 --- a/BizHawk.Util/HexTextBox.cs +++ b/BizHawk.Util/HexTextBox.cs @@ -6,7 +6,7 @@ namespace BizHawk { public interface INumberBox { - int ToInt(); + int ToRawInt(); } public class HexTextBox : TextBox, INumberBox @@ -34,7 +34,7 @@ namespace BizHawk { if (InputValidate.IsValidHexNumber(Text)) { - int val = ToInt(); + int val = ToRawInt(); val++; string formatstr = "{0:X" + MaxLength.ToString() + "}"; Text = String.Format(formatstr, val); @@ -44,7 +44,7 @@ namespace BizHawk { if (InputValidate.IsValidHexNumber(Text)) { - int val = ToInt(); + int val = ToRawInt(); val--; string formatstr = "{0:X" + MaxLength.ToString() + "}"; Text = String.Format(formatstr, val); @@ -64,7 +64,7 @@ namespace BizHawk } } - public int ToInt() + public int ToRawInt() { if (String.IsNullOrWhiteSpace(Text)) { @@ -102,7 +102,7 @@ namespace BizHawk { if (InputValidate.IsValidUnsignedNumber(Text)) { - int val = ToInt(); + int val = ToRawInt(); val++; Text = val.ToString(); } @@ -111,7 +111,7 @@ namespace BizHawk { if (InputValidate.IsValidUnsignedNumber(Text)) { - int val = ToInt(); + int val = ToRawInt(); val--; Text = val.ToString(); } @@ -130,7 +130,7 @@ namespace BizHawk } } - public int ToInt() + public int ToRawInt() { if (String.IsNullOrWhiteSpace(Text)) {