From eb80784d79af72bf3743634a3a2aa6281f86213c Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 15 Dec 2021 06:36:44 +1000 Subject: [PATCH] Add option to split RAM Watch entries (resolves #1024) squashed PR #3032 --- .../tools/Watch/Watch.cs | 3 ++ .../tools/Watch/WatchSize.cs | 2 +- .../Properties/Resources.cs | 1 + src/BizHawk.Client.EmuHawk/images/Split.png | Bin 0 -> 405 bytes .../tools/Watch/RamWatch.Designer.cs | 30 ++++++++++++ .../tools/Watch/RamWatch.cs | 43 ++++++++++++++++++ 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/BizHawk.Client.EmuHawk/images/Split.png diff --git a/src/BizHawk.Client.Common/tools/Watch/Watch.cs b/src/BizHawk.Client.Common/tools/Watch/Watch.cs index 18de8dd363..298f8eeed3 100644 --- a/src/BizHawk.Client.Common/tools/Watch/Watch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/Watch.cs @@ -638,5 +638,8 @@ namespace BizHawk.Client.Common _ => WatchDisplayType.Separator }; } + + public bool IsSplittable => Size is WatchSize.Word or WatchSize.DWord + && Type is WatchDisplayType.Hex or WatchDisplayType.Binary; } } diff --git a/src/BizHawk.Client.Common/tools/Watch/WatchSize.cs b/src/BizHawk.Client.Common/tools/Watch/WatchSize.cs index 57e4965396..0cdbf99b88 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WatchSize.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WatchSize.cs @@ -3,7 +3,7 @@ /// /// This enum specify the size of a /// - public enum WatchSize + public enum WatchSize : int { /// /// One byte (8 bits) diff --git a/src/BizHawk.Client.EmuHawk/Properties/Resources.cs b/src/BizHawk.Client.EmuHawk/Properties/Resources.cs index d762d2a511..a2a7f662f7 100644 --- a/src/BizHawk.Client.EmuHawk/Properties/Resources.cs +++ b/src/BizHawk.Client.EmuHawk/Properties/Resources.cs @@ -167,6 +167,7 @@ namespace BizHawk.Client.EmuHawk.Properties internal static readonly Bitmap Shark = ReadEmbeddedBitmap("Shark"); internal static readonly Icon SmsIcon = ReadEmbeddedIcon("sms-icon"); internal static readonly Bitmap Snes9X = ReadEmbeddedBitmap("snes9x"); + internal static readonly Bitmap Split = ReadEmbeddedBitmap("Split"); internal static readonly Bitmap Square = ReadEmbeddedBitmap("Square"); internal static readonly Bitmap SSE = ReadEmbeddedBitmap("SSE"); internal static readonly Bitmap SSW = ReadEmbeddedBitmap("SSW"); diff --git a/src/BizHawk.Client.EmuHawk/images/Split.png b/src/BizHawk.Client.EmuHawk/images/Split.png new file mode 100644 index 0000000000000000000000000000000000000000..14959a67a11292169f545e80af0e6d063b5b4145 GIT binary patch literal 405 zcmV;G0c!qj({qXer>hJs8&hWCy@UF!0ufy%D!tbiV z@20)%ptOHm*;bm(O{0}T#VXeg~?Ha(N%fDM{c?`WyLF3u_{-yDO9W}RH`RXq$g0KB~6_r zOq(T2m?KD*BS(@VMvo#zjv+&eAw!8EL52VT0C-M0p8x;=1awkPQvf_XJi>l|761SM zgGod|RCoc6!9^0nKmY{50S0#q8eGDn!FB%sEULnW69>BSOR-$3IZgy$MUot@qX<<= za#GmDVAa`bW#`)+LVc3SG$09qF-KEC608{kNx&W WatchSize.Word, + WatchSize.Word => WatchSize.Byte, + _ => throw new Exception() + }; + var a = Watch.GenerateWatch(ab.Domain, ab.Address, newSize, ab.Type, ab.BigEndian, ab.Notes); + var b = Watch.GenerateWatch(ab.Domain, ab.Address + (int) newSize, newSize, ab.Type, ab.BigEndian, ab.Notes); + return ab.BigEndian ? (a, b) : (b, a); + } + + private void SplitWatchAt(int index) + { + var ab = _watches[index]; + if (!ab.IsSplittable) return; + var (a, b) = SplitWatch(ab); + _watches[index] = a; + _watches.Insert(index + 1, b); + } + + private void SplitWatchMenuItem_Click(object sender, EventArgs e) + { + var indices = SelectedIndices.ToList(); + for (var indexIndex = indices.Count - 1; indexIndex >= 0; indexIndex--) SplitWatchAt(indices[indexIndex]); + Changes(); + UpdateWatchCount(); + WatchListView.RowCount = _watches.Count; + GeneralUpdate(); + } + private void PokeAddressMenuItem_Click(object sender, EventArgs e) { if (SelectedWatches.Any()) @@ -1034,6 +1072,8 @@ namespace BizHawk.Client.EmuHawk } } + private bool MaySplitAllSelected => SelectedIndices.Any() && SelectedWatches.All(static w => w.IsSplittable); + private void ListViewContextMenu_Opening(object sender, CancelEventArgs e) { var indexes = WatchListView.SelectedRows.ToList(); @@ -1041,6 +1081,7 @@ namespace BizHawk.Client.EmuHawk EditContextMenuItem.Visible = RemoveContextMenuItem.Visible = DuplicateContextMenuItem.Visible = + SplitContextMenuItem.Visible = PokeContextMenuItem.Visible = FreezeContextMenuItem.Visible = Separator4.Visible = @@ -1062,6 +1103,8 @@ namespace BizHawk.Client.EmuHawk Debuggable.MemoryCallbacksAvailable() && SelectedWatches.All(w => w.Domain.Name == (MemoryDomains != null ? MemoryDomains.SystemBus.Name : "")); + SplitContextMenuItem.Enabled = MaySplitAllSelected; + PokeContextMenuItem.Enabled = FreezeContextMenuItem.Visible = SelectedIndices.Any()