From f983c91eb0efe7bc9fe8de0ae5b6ec7aa2436fbe Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 10 Nov 2017 14:32:30 +1100 Subject: [PATCH] Add display type column (resolves #683) --- .../BizHawk.Client.Common.csproj | 1 + .../WatchList/WatchDisplayTypeComparer.cs | 44 +++++++++++++++++++ .../tools/Watch/WatchList/WatchList.cs | 15 +++++++ .../tools/Watch/RamWatch.Designer.cs | 11 ++++- .../tools/Watch/RamWatch.cs | 43 +++++++++++++++++- 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 BizHawk.Client.Common/tools/Watch/WatchList/WatchDisplayTypeComparer.cs diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index 805f752786..ad62cb179f 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -268,6 +268,7 @@ + diff --git a/BizHawk.Client.Common/tools/Watch/WatchList/WatchDisplayTypeComparer.cs b/BizHawk.Client.Common/tools/Watch/WatchList/WatchDisplayTypeComparer.cs new file mode 100644 index 0000000000..59ca6ad1ba --- /dev/null +++ b/BizHawk.Client.Common/tools/Watch/WatchList/WatchDisplayTypeComparer.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; + +namespace BizHawk.Client.Common +{ + /// + /// This class hold a collection + /// + public sealed partial class WatchList + { + /// + /// Nested private class that defines how to compare two es based on their full display type + /// + private sealed class WatchFullDisplayTypeComparer + : WatchEqualityComparer, IComparer + { + /// + /// Compares two es and determines which has greater size. + /// If they are equal, comparison will done on the display type and then on endianness + /// + /// First + /// Second + /// 0 for equality, 1 if x comes first; -1 if y comes first + public int Compare(Watch x, Watch y) + { + if (Equals(x, y)) + { + return 0; + } + + if (x.Size.Equals(y.Size)) + { + if (x.Type.Equals(y.Type)) + { + return x.BigEndian.CompareTo(y.BigEndian); + } + + return x.Type.CompareTo(y.Type); + } + + return x.Size.CompareTo(y.Size); + } + } + } +} diff --git a/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs b/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs index 37d4b0da37..833e3595e8 100644 --- a/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs +++ b/BizHawk.Client.Common/tools/Watch/WatchList/WatchList.cs @@ -26,11 +26,13 @@ namespace BizHawk.Client.Common public const string PREV = "PrevColumn"; public const string CHANGES = "ChangesColumn"; public const string DIFF = "DiffColumn"; + public const string TYPE = "TypeColumn"; public const string DOMAIN = "DomainColumn"; public const string NOTES = "NotesColumn"; private static readonly WatchDomainComparer DomainComparer = new WatchDomainComparer(); private static readonly WatchAddressComparer AddressComparer = new WatchAddressComparer(); + private static readonly WatchFullDisplayTypeComparer DisplayTypeComparer = new WatchFullDisplayTypeComparer(); private static readonly WatchValueComparer ValueComparer = new WatchValueComparer(); private static readonly WatchPreviousValueComparer PreviousValueComparer = new WatchPreviousValueComparer(); private static readonly WatchValueDifferenceComparer ValueDifferenceComparer = new WatchValueDifferenceComparer(); @@ -297,6 +299,19 @@ namespace BizHawk.Client.Common break; + case TYPE: + if (reverse) + { + _watchList.Sort(DisplayTypeComparer); + _watchList.Reverse(); + } + else + { + _watchList.Sort(DisplayTypeComparer); + } + + break; + case NOTES: if (reverse) { diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs index 293d08a104..7daaf35e86 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.Designer.cs @@ -114,6 +114,7 @@ this.PrevColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ChangesColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.DiffColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.TypeColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.DomainColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.NotesColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.ListViewContextMenu.SuspendLayout(); @@ -850,6 +851,7 @@ this.PrevColumn, this.ChangesColumn, this.DiffColumn, + this.TypeColumn, this.DomainColumn, this.NotesColumn}); this.WatchListView.ContextMenuStrip = this.ListViewContextMenu; @@ -907,6 +909,12 @@ this.DiffColumn.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.DiffColumn.Width = 59; // + // TypeColumn + // + this.TypeColumn.Name = "TypeColumn"; + this.TypeColumn.Text = "Type"; + this.TypeColumn.Width = 55; + // // DomainColumn // this.DomainColumn.Name = "DomainColumn"; @@ -959,6 +967,7 @@ private System.Windows.Forms.ColumnHeader PrevColumn; private System.Windows.Forms.ColumnHeader ChangesColumn; private System.Windows.Forms.ColumnHeader DiffColumn; + private System.Windows.Forms.ColumnHeader TypeColumn; private System.Windows.Forms.ColumnHeader DomainColumn; private System.Windows.Forms.ColumnHeader NotesColumn; private MenuStripEx RamWatchMenu; @@ -1040,4 +1049,4 @@ private System.Windows.Forms.ToolStripMenuItem WriteBreakpointContextMenuItem; private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem; } -} \ No newline at end of file +} diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 3382d14e04..8d017a8d14 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -73,8 +73,9 @@ namespace BizHawk.Client.EmuHawk new Column { Name = WatchList.PREV, Visible = false, Index = 2, Width = 59 }, new Column { Name = WatchList.CHANGES, Visible = true, Index = 3, Width = 55 }, new Column { Name = WatchList.DIFF, Visible = false, Index = 4, Width = 59 }, - new Column { Name = WatchList.DOMAIN, Visible = true, Index = 5, Width = 55 }, - new Column { Name = WatchList.NOTES, Visible = true, Index = 6, Width = 128 }, + new Column { Name = WatchList.TYPE, Visible = false, Index = 5, Width = 55 }, + new Column { Name = WatchList.DOMAIN, Visible = true, Index = 6, Width = 55 }, + new Column { Name = WatchList.NOTES, Visible = true, Index = 7, Width = 128 }, }; } @@ -428,6 +429,39 @@ namespace BizHawk.Client.EmuHawk } } + private string ComputeDisplayType(Watch w) + { + String s = w.Size == WatchSize.Byte ? "1" : (w.Size == WatchSize.Word ? "2" : "4"); + switch (w.Type) + { + case Common.DisplayType.Binary: + s += "b"; + break; + case Common.DisplayType.FixedPoint_12_4: + s += "F"; + break; + case Common.DisplayType.FixedPoint_16_16: + s += "F6"; + break; + case Common.DisplayType.FixedPoint_20_12: + s += "F2"; + break; + case Common.DisplayType.Float: + s += "f"; + break; + case Common.DisplayType.Hex: + s += "h"; + break; + case Common.DisplayType.Signed: + s += "s"; + break; + case Common.DisplayType.Unsigned: + s += "u"; + break; + } + return s + (w.BigEndian ? "B" : "L"); + } + private string GetColumnValue(string name, int index) { switch (name) @@ -444,6 +478,8 @@ namespace BizHawk.Client.EmuHawk return _watches[index].ChangeCount.ToString(); case WatchList.DIFF: return _watches[index].Diff; + case WatchList.TYPE: + return ComputeDisplayType(_watches[index]); case WatchList.DOMAIN: return _watches[index].Domain.Name; case WatchList.NOTES: @@ -619,6 +655,9 @@ namespace BizHawk.Client.EmuHawk case WatchList.DIFF: text = _watches[index].Diff; break; + case WatchList.TYPE: + text = ComputeDisplayType(_watches[index]); + break; case WatchList.DOMAIN: text = _watches[index].Domain.Name; break;