From 286b56de5a6e0c0845bf29fa0a7020d04a9ce5b0 Mon Sep 17 00:00:00 2001 From: scrimpeh Date: Sun, 28 Jun 2020 19:23:53 +0200 Subject: [PATCH] ram search - pr fixes. also remove out of range searches in ramsearch - adds a static IsValid method to IMiniWatch implementations - reverts .csproj changes - 'remove out of range' button on ram search didn't seem to actually do anything. this was fixed --- .../tools/RamSearchEngine/IMiniWatch.cs | 29 ++++++++++++++----- .../RamSearchEngine/IMiniWatchDetails.cs | 15 ++-------- .../tools/RamSearchEngine/RamSearchEngine.cs | 8 +++-- .../BizHawk.Client.DiscoHawk.csproj | 6 ++-- .../tools/Watch/RamSearch.cs | 2 +- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatch.cs b/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatch.cs index 6ae499b971..1bd7b86966 100644 --- a/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatch.cs +++ b/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatch.cs @@ -27,19 +27,24 @@ namespace BizHawk.Client.Common.RamSearchEngine public long Previous => _previous; + public bool IsValid(MemoryDomain domain) + { + return IsValid(Address, domain); + } + public void SetPreviousToCurrent(MemoryDomain domain, bool bigEndian) { _previous = GetByte(Address, domain); } - public bool IsValid(MemoryDomain domain) + public static bool IsValid(long address, MemoryDomain domain) { - return Address < domain.Size; + return address < domain.Size; } public static byte GetByte(long address, MemoryDomain domain) { - if (address >= domain.Size) + if (!IsValid(address, domain)) { return 0; } @@ -68,12 +73,17 @@ namespace BizHawk.Client.Common.RamSearchEngine public bool IsValid(MemoryDomain domain) { - return Address < (domain.Size - 1); + return IsValid(Address, domain); + } + + public static bool IsValid(long address, MemoryDomain domain) + { + return address < (domain.Size - 1); } public static ushort GetUshort(long address, MemoryDomain domain, bool bigEndian) { - if (address >= (domain.Size - 1)) + if (!IsValid(address, domain)) { return 0; } @@ -102,12 +112,17 @@ namespace BizHawk.Client.Common.RamSearchEngine public bool IsValid(MemoryDomain domain) { - return Address < (domain.Size - 3); + return IsValid(Address, domain); + } + + public static bool IsValid(long address, MemoryDomain domain) + { + return address < (domain.Size - 3); } public static uint GetUint(long address, MemoryDomain domain, bool bigEndian) { - if (address >= (domain.Size - 3)) + if (!IsValid(address, domain)) { return 0; } diff --git a/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatchDetails.cs b/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatchDetails.cs index 4b713a5306..024eae8d78 100644 --- a/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatchDetails.cs +++ b/src/BizHawk.Client.Common/tools/RamSearchEngine/IMiniWatchDetails.cs @@ -68,10 +68,7 @@ namespace BizHawk.Client.Common.RamSearchEngine public void ClearChangeCount() => ChangeCount = 0; - public bool IsValid(MemoryDomain domain) - { - return Address < domain.Size; - } + public bool IsValid(MemoryDomain domain) => MiniByteWatch.IsValid(Address, domain); } internal sealed class MiniWordWatchDetailed : IMiniWatchDetails @@ -126,10 +123,7 @@ namespace BizHawk.Client.Common.RamSearchEngine public void ClearChangeCount() => ChangeCount = 0; - public bool IsValid(MemoryDomain domain) - { - return Address < (domain.Size - 1); - } + public bool IsValid(MemoryDomain domain) => MiniWordWatch.IsValid(Address, domain); } internal sealed class MiniDWordWatchDetailed : IMiniWatchDetails @@ -184,9 +178,6 @@ namespace BizHawk.Client.Common.RamSearchEngine public void ClearChangeCount() => ChangeCount = 0; - public bool IsValid(MemoryDomain domain) - { - return Address < (domain.Size - 3); - } + public bool IsValid(MemoryDomain domain) => MiniDWordWatch.IsValid(Address, domain); } } diff --git a/src/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs b/src/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs index 67ae53a440..42e2adf824 100644 --- a/src/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs +++ b/src/BizHawk.Client.Common/tools/RamSearchEngine/RamSearchEngine.cs @@ -248,7 +248,7 @@ namespace BizHawk.Client.Common.RamSearchEngine } var addresses = watches.Select(w => w.Address); - _watchList.RemoveAll(w => addresses.Contains(w.Address)); + RemoveAddressRange(addresses); } public void RemoveRange(IEnumerable indices) @@ -262,6 +262,11 @@ namespace BizHawk.Client.Common.RamSearchEngine _watchList = _watchList.Except(removeList).ToList(); } + public void RemoveAddressRange(IEnumerable addresses) + { + _watchList.RemoveAll(w => addresses.Contains(w.Address)); + } + public void AddRange(IEnumerable addresses, bool append) { if (!append) @@ -313,7 +318,6 @@ namespace BizHawk.Client.Common.RamSearchEngine public bool UndoEnabled { get; set; } - public bool CanUndo => UndoEnabled && _history.CanUndo; public bool CanRedo => UndoEnabled && _history.CanRedo; diff --git a/src/BizHawk.Client.DiscoHawk/BizHawk.Client.DiscoHawk.csproj b/src/BizHawk.Client.DiscoHawk/BizHawk.Client.DiscoHawk.csproj index 6d35b5cc47..9019cd7be1 100755 --- a/src/BizHawk.Client.DiscoHawk/BizHawk.Client.DiscoHawk.csproj +++ b/src/BizHawk.Client.DiscoHawk/BizHawk.Client.DiscoHawk.csproj @@ -70,13 +70,13 @@ - + - + - + diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 6cf993c915..bfbeed02a4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -1490,7 +1490,7 @@ namespace BizHawk.Client.EmuHawk private void ErrorIconButton_Click(object sender, EventArgs e) { var outOfRangeAddresses = _searches.OutOfRangeAddress.ToList(); - + _searches.RemoveAddressRange(outOfRangeAddresses); SetRemovedMessage(outOfRangeAddresses.Count); UpdateList();