2013-09-14 19:07:11 +00:00
|
|
|
|
using System;
|
2013-09-22 01:53:20 +00:00
|
|
|
|
using System.Collections;
|
2013-09-14 19:07:11 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-09-22 12:50:47 +00:00
|
|
|
|
using System.IO;
|
2013-09-14 19:07:11 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
|
|
|
|
class RamSearchEngine
|
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
public enum ComparisonOperator { Equal, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, NotEqual, DifferentBy };
|
2013-09-21 23:55:17 +00:00
|
|
|
|
public enum Compare { Previous, SpecificValue, SpecificAddress, Changes, Difference }
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
private List<IMiniWatch> _watchList = new List<IMiniWatch>();
|
2013-09-16 01:24:06 +00:00
|
|
|
|
private Settings _settings;
|
2013-09-14 19:07:11 +00:00
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
public Compare CompareTo = Compare.Previous;
|
|
|
|
|
public int? CompareValue = null;
|
|
|
|
|
public ComparisonOperator Operator = ComparisonOperator.Equal;
|
|
|
|
|
public int? DifferentBy = null;
|
2013-09-21 14:09:37 +00:00
|
|
|
|
|
2013-09-14 19:07:11 +00:00
|
|
|
|
#region Constructors
|
2013-09-16 01:24:06 +00:00
|
|
|
|
|
|
|
|
|
public RamSearchEngine(Settings settings)
|
2013-09-14 19:07:11 +00:00
|
|
|
|
{
|
2013-09-16 01:24:06 +00:00
|
|
|
|
_settings = settings;
|
2013-09-14 19:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2013-09-22 01:53:20 +00:00
|
|
|
|
#region API
|
2013-09-14 23:30:23 +00:00
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2013-09-19 23:45:29 +00:00
|
|
|
|
_watchList.Clear();
|
|
|
|
|
switch (_settings.Size)
|
2013-09-14 23:30:23 +00:00
|
|
|
|
{
|
2013-09-19 23:45:29 +00:00
|
|
|
|
default:
|
|
|
|
|
case Watch.WatchSize.Byte:
|
2013-09-20 01:18:55 +00:00
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
2013-09-20 01:18:55 +00:00
|
|
|
|
for (int i = 0; i < _settings.Domain.Size; i++)
|
|
|
|
|
{
|
|
|
|
|
_watchList.Add(new MiniByteWatchDetailed(_settings.Domain, i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _settings.Domain.Size; i++)
|
|
|
|
|
{
|
|
|
|
|
_watchList.Add(new MiniByteWatch(_settings.Domain, i));
|
|
|
|
|
}
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.Word:
|
2013-09-20 01:18:55 +00:00
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _settings.Domain.Size; i += (_settings.CheckMisAligned ? 1 : 2))
|
|
|
|
|
{
|
|
|
|
|
_watchList.Add(new MiniWordWatchDetailed(_settings.Domain, i, _settings.BigEndian));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
2013-09-20 01:18:55 +00:00
|
|
|
|
for (int i = 0; i < _settings.Domain.Size; i += (_settings.CheckMisAligned ? 1 : 2))
|
|
|
|
|
{
|
|
|
|
|
_watchList.Add(new MiniWordWatch(_settings.Domain, i, _settings.BigEndian));
|
|
|
|
|
}
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.DWord:
|
2013-09-20 01:18:55 +00:00
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < _settings.Domain.Size; i += (_settings.CheckMisAligned ? 1 : 4))
|
|
|
|
|
{
|
|
|
|
|
_watchList.Add(new MiniDWordWatchDetailed(_settings.Domain, i, _settings.BigEndian));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
2013-09-20 01:18:55 +00:00
|
|
|
|
for (int i = 0; i < _settings.Domain.Size; i += (_settings.CheckMisAligned ? 1 : 4))
|
|
|
|
|
{
|
|
|
|
|
_watchList.Add(new MiniDWordWatch(_settings.Domain, i, _settings.BigEndian));
|
|
|
|
|
}
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2013-09-14 23:30:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-14 19:07:11 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Exposes the current watch state based on index
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Watch this[int index]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-09-20 01:18:55 +00:00
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
|
|
|
|
return Watch.GenerateWatch(
|
|
|
|
|
_settings.Domain,
|
|
|
|
|
_watchList[index].Address,
|
|
|
|
|
_settings.Size,
|
|
|
|
|
_settings.Type,
|
|
|
|
|
_settings.BigEndian,
|
|
|
|
|
_watchList[index].Previous,
|
|
|
|
|
(_watchList[index] as IMiniWatchDetails).ChangeCount
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Watch.GenerateWatch(
|
|
|
|
|
_settings.Domain,
|
|
|
|
|
_watchList[index].Address,
|
|
|
|
|
_settings.Size,
|
|
|
|
|
_settings.Type,
|
|
|
|
|
_settings.BigEndian,
|
|
|
|
|
_watchList[index].Previous,
|
|
|
|
|
0
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-09-14 19:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 01:53:20 +00:00
|
|
|
|
public int DoSearch()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
{
|
2013-09-22 01:53:20 +00:00
|
|
|
|
int before = _watchList.Count;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
switch (CompareTo)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case RamSearchEngine.Compare.Previous:
|
|
|
|
|
ComparePrevious();
|
|
|
|
|
break;
|
|
|
|
|
case RamSearchEngine.Compare.SpecificValue:
|
|
|
|
|
CompareSpecificValue();
|
|
|
|
|
break;
|
|
|
|
|
case RamSearchEngine.Compare.SpecificAddress:
|
|
|
|
|
CompareSpecificAddress();
|
|
|
|
|
break;
|
|
|
|
|
case RamSearchEngine.Compare.Changes:
|
|
|
|
|
CompareChanges();
|
|
|
|
|
break;
|
|
|
|
|
case RamSearchEngine.Compare.Difference:
|
2013-09-22 17:00:05 +00:00
|
|
|
|
CompareDifference();
|
|
|
|
|
break;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_settings.PreviousType == Watch.PreviousType.LastSearch)
|
|
|
|
|
{
|
2013-09-22 01:53:20 +00:00
|
|
|
|
SetPrevousToCurrent();
|
2013-09-21 23:55:17 +00:00
|
|
|
|
}
|
2013-09-22 01:53:20 +00:00
|
|
|
|
|
|
|
|
|
return before - _watchList.Count;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 19:07:11 +00:00
|
|
|
|
public int Count
|
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
get { return _watchList.Count; }
|
2013-09-14 19:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string DomainName
|
|
|
|
|
{
|
2013-09-16 01:24:06 +00:00
|
|
|
|
get { return _settings.Domain.Name; }
|
2013-09-14 19:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 23:30:23 +00:00
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2013-09-20 01:18:55 +00:00
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
foreach (IMiniWatchDetails watch in _watchList)
|
2013-09-20 01:18:55 +00:00
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
watch.Update(_settings.PreviousType, _settings.Domain);
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-09-22 17:00:05 +00:00
|
|
|
|
return;
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
2013-09-14 23:30:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 23:45:29 +00:00
|
|
|
|
public void SetType(Watch.DisplayType type)
|
|
|
|
|
{
|
|
|
|
|
if (Watch.AvailableTypes(_settings.Size).Contains(type))
|
|
|
|
|
{
|
|
|
|
|
_settings.Type = type;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetEndian(bool bigendian)
|
|
|
|
|
{
|
|
|
|
|
_settings.BigEndian = bigendian;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
public void SetPreviousType(Watch.PreviousType type)
|
|
|
|
|
{
|
2013-09-20 15:33:46 +00:00
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Fast)
|
|
|
|
|
{
|
|
|
|
|
if (type == Watch.PreviousType.LastFrame || type == Watch.PreviousType.LastChange)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-21 14:09:37 +00:00
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
_settings.PreviousType = type;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 01:53:20 +00:00
|
|
|
|
public void SetPrevousToCurrent()
|
|
|
|
|
{
|
|
|
|
|
_watchList.ForEach(x => x.SetPreviousToCurrent(_settings.Domain, _settings.BigEndian));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearChangeCounts()
|
|
|
|
|
{
|
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
|
|
|
|
foreach (IMiniWatchDetails watch in _watchList.Cast<IMiniWatchDetails>())
|
|
|
|
|
{
|
|
|
|
|
watch.ClearChangeCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 13:30:18 +00:00
|
|
|
|
public void RemoveRange(List<int> addresses)
|
2013-09-22 01:53:20 +00:00
|
|
|
|
{
|
|
|
|
|
_watchList = _watchList.Where(x => !addresses.Contains(x.Address)).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 12:50:47 +00:00
|
|
|
|
public void AddRange(List<int> addresses, bool append)
|
|
|
|
|
{
|
|
|
|
|
if (!append)
|
|
|
|
|
{
|
|
|
|
|
_watchList.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(_settings.Size)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case Watch.WatchSize.Byte:
|
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
|
|
|
|
foreach(var addr in addresses) { _watchList.Add(new MiniByteWatchDetailed(_settings.Domain, addr)); }
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach(var addr in addresses) { _watchList.Add(new MiniByteWatch(_settings.Domain, addr)); }
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.Word:
|
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
|
|
|
|
foreach (var addr in addresses) { _watchList.Add(new MiniWordWatchDetailed(_settings.Domain, addr, _settings.BigEndian)); }
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var addr in addresses) { _watchList.Add(new MiniWordWatch(_settings.Domain, addr, _settings.BigEndian)); }
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Watch.WatchSize.DWord:
|
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed)
|
|
|
|
|
{
|
|
|
|
|
foreach (var addr in addresses) { _watchList.Add(new MiniDWordWatchDetailed(_settings.Domain, addr, _settings.BigEndian)); }
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var addr in addresses) { _watchList.Add(new MiniDWordWatch(_settings.Domain, addr, _settings.BigEndian)); }
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 23:30:23 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Comparisons
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
private void ComparePrevious()
|
2013-09-14 23:30:23 +00:00
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
switch (Operator)
|
|
|
|
|
{
|
|
|
|
|
case ComparisonOperator.Equal:
|
2013-09-21 23:55:17 +00:00
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) == x.Previous).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.NotEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) != x.Previous).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThan:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) > x.Previous).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) >= x.Previous).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThan:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) < x.Previous).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) <= x.Previous).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.DifferentBy:
|
|
|
|
|
if (DifferentBy.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) + DifferentBy.Value == x.Previous) || (GetValue(x.Address) - DifferentBy.Value == x.Previous)).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
2013-09-21 14:09:37 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-14 23:30:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
private void CompareSpecificValue()
|
2013-09-14 23:30:23 +00:00
|
|
|
|
{
|
2013-09-21 23:55:17 +00:00
|
|
|
|
if (CompareValue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch (Operator)
|
|
|
|
|
{
|
|
|
|
|
case ComparisonOperator.Equal:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) == CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.NotEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) != CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThan:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) > CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) >= CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThan:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) < CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => GetValue(x.Address) <= CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.DifferentBy:
|
|
|
|
|
if (DifferentBy.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) + DifferentBy.Value == CompareValue.Value) || (GetValue(x.Address) - DifferentBy.Value == CompareValue.Value)).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
2013-09-14 23:30:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
private void CompareSpecificAddress()
|
2013-09-14 23:30:23 +00:00
|
|
|
|
{
|
2013-09-21 23:55:17 +00:00
|
|
|
|
if (CompareValue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch (Operator)
|
|
|
|
|
{
|
|
|
|
|
case ComparisonOperator.Equal:
|
|
|
|
|
_watchList = _watchList.Where(x => x.Address == CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.NotEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => x.Address != CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThan:
|
|
|
|
|
_watchList = _watchList.Where(x => x.Address > CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => x.Address >= CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThan:
|
|
|
|
|
_watchList = _watchList.Where(x => x.Address < CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => x.Address <= CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.DifferentBy:
|
|
|
|
|
if (DifferentBy.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_watchList = _watchList.Where(x => (x.Address + DifferentBy.Value == CompareValue.Value) || (x.Address - DifferentBy.Value == CompareValue.Value)).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
2013-09-14 23:30:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
public void CompareChanges()
|
2013-09-14 23:30:23 +00:00
|
|
|
|
{
|
2013-09-21 23:55:17 +00:00
|
|
|
|
if (_settings.Mode == Settings.SearchMode.Detailed && CompareValue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch (Operator)
|
|
|
|
|
{
|
|
|
|
|
case ComparisonOperator.Equal:
|
|
|
|
|
_watchList = _watchList
|
2013-09-22 15:54:31 +00:00
|
|
|
|
.Cast<IMiniWatchDetails>()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
.Where(x => x.ChangeCount == CompareValue.Value)
|
|
|
|
|
.Cast<IMiniWatch>()
|
|
|
|
|
.ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.NotEqual:
|
|
|
|
|
_watchList = _watchList
|
2013-09-22 15:54:31 +00:00
|
|
|
|
.Cast<IMiniWatchDetails>()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
.Where(x => x.ChangeCount != CompareValue.Value)
|
|
|
|
|
.Cast<IMiniWatch>()
|
|
|
|
|
.ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThan:
|
|
|
|
|
_watchList = _watchList
|
2013-09-22 15:54:31 +00:00
|
|
|
|
.Cast<IMiniWatchDetails>()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
.Where(x => x.ChangeCount > CompareValue.Value)
|
|
|
|
|
.Cast<IMiniWatch>()
|
|
|
|
|
.ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThanEqual:
|
|
|
|
|
_watchList = _watchList
|
2013-09-22 15:54:31 +00:00
|
|
|
|
.Cast<IMiniWatchDetails>()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
.Where(x => x.ChangeCount >= CompareValue.Value)
|
|
|
|
|
.Cast<IMiniWatch>()
|
|
|
|
|
.ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThan:
|
|
|
|
|
_watchList = _watchList
|
2013-09-22 15:54:31 +00:00
|
|
|
|
.Cast<IMiniWatchDetails>()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
.Where(x => x.ChangeCount < CompareValue.Value)
|
|
|
|
|
.Cast<IMiniWatch>()
|
|
|
|
|
.ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThanEqual:
|
|
|
|
|
_watchList = _watchList
|
2013-09-22 15:54:31 +00:00
|
|
|
|
.Cast<IMiniWatchDetails>()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
.Where(x => x.ChangeCount <= CompareValue.Value)
|
|
|
|
|
.Cast<IMiniWatch>()
|
|
|
|
|
.ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.DifferentBy:
|
|
|
|
|
if (DifferentBy.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_watchList = _watchList
|
2013-09-22 15:54:31 +00:00
|
|
|
|
.Cast<IMiniWatchDetails>()
|
2013-09-21 23:55:17 +00:00
|
|
|
|
.Where(x => (x.ChangeCount + DifferentBy.Value == CompareValue.Value) || (x.ChangeCount - DifferentBy.Value == CompareValue.Value))
|
|
|
|
|
.Cast<IMiniWatch>()
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidCastException();
|
|
|
|
|
}
|
2013-09-14 23:30:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
private void CompareDifference()
|
2013-09-14 23:30:23 +00:00
|
|
|
|
{
|
2013-09-22 15:54:31 +00:00
|
|
|
|
if (CompareValue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch (Operator)
|
|
|
|
|
{
|
|
|
|
|
case ComparisonOperator.Equal:
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) - x.Previous) == CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.NotEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) - x.Previous) != CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThan:
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) - x.Previous) > CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.GreaterThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) - x.Previous) >= CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThan:
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) - x.Previous) < CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.LessThanEqual:
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) - x.Previous) <= CompareValue.Value).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case ComparisonOperator.DifferentBy:
|
|
|
|
|
if (DifferentBy.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_watchList = _watchList.Where(x => (GetValue(x.Address) - x.Previous + DifferentBy.Value == CompareValue) || (GetValue(x.Address) - x.Previous - DifferentBy.Value == x.Previous)).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidCastException();
|
|
|
|
|
}
|
2013-09-14 23:30:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 19:07:11 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private parts
|
2013-09-21 14:09:37 +00:00
|
|
|
|
|
|
|
|
|
private int GetValue(int addr)
|
|
|
|
|
{
|
|
|
|
|
switch (_settings.Size)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case Watch.WatchSize.Byte:
|
|
|
|
|
return _settings.Domain.PeekByte(addr);
|
|
|
|
|
case Watch.WatchSize.Word:
|
2013-09-22 17:00:05 +00:00
|
|
|
|
return _settings.Domain.PeekWord(addr, _settings.BigEndian ? Endian.Big : Endian.Little);
|
2013-09-21 14:09:37 +00:00
|
|
|
|
case Watch.WatchSize.DWord:
|
2013-09-22 17:00:05 +00:00
|
|
|
|
return (int)_settings.Domain.PeekDWord(addr, _settings.BigEndian ? Endian.Big : Endian.Little);
|
2013-09-21 14:09:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 19:07:11 +00:00
|
|
|
|
#endregion
|
2013-09-16 01:24:06 +00:00
|
|
|
|
|
|
|
|
|
#region Classes
|
2013-09-20 01:18:55 +00:00
|
|
|
|
|
|
|
|
|
private interface IMiniWatch
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
|
|
|
|
int Address { get; }
|
2013-09-20 01:18:55 +00:00
|
|
|
|
int Previous { get; }
|
2013-09-21 23:55:17 +00:00
|
|
|
|
void SetPreviousToCurrent(MemoryDomain domain, bool bigendian);
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private interface IMiniWatchDetails
|
|
|
|
|
{
|
|
|
|
|
int ChangeCount { get; }
|
2013-09-22 15:54:31 +00:00
|
|
|
|
|
2013-09-22 01:53:20 +00:00
|
|
|
|
void ClearChangeCount();
|
2013-09-21 14:09:37 +00:00
|
|
|
|
void Update(Watch.PreviousType type, MemoryDomain domain);
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
private class MiniByteWatch : IMiniWatch
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
|
|
|
|
public int Address { get; private set; }
|
2013-09-20 01:18:55 +00:00
|
|
|
|
private byte _previous;
|
2013-09-19 23:45:29 +00:00
|
|
|
|
|
|
|
|
|
public MiniByteWatch(MemoryDomain domain, int addr)
|
|
|
|
|
{
|
|
|
|
|
Address = addr;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
SetPreviousToCurrent(domain, false);
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
public int Previous
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
2013-09-20 01:18:55 +00:00
|
|
|
|
get { return _previous; }
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
2013-09-21 23:55:17 +00:00
|
|
|
|
|
|
|
|
|
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
|
|
|
|
|
{
|
|
|
|
|
_previous = domain.PeekByte(Address);
|
|
|
|
|
}
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
private class MiniWordWatch : IMiniWatch
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
|
|
|
|
public int Address { get; private set; }
|
2013-09-20 01:18:55 +00:00
|
|
|
|
private ushort _previous;
|
2013-09-19 23:45:29 +00:00
|
|
|
|
|
|
|
|
|
public MiniWordWatch(MemoryDomain domain, int addr, bool bigEndian)
|
|
|
|
|
{
|
|
|
|
|
Address = addr;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
SetPreviousToCurrent(domain, bigEndian);
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
public int Previous
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
2013-09-20 01:18:55 +00:00
|
|
|
|
get { return _previous; }
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
|
|
|
|
|
{
|
|
|
|
|
_previous = domain.PeekWord(Address, bigendian ? Endian.Big : Endian.Little);
|
|
|
|
|
}
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
public class MiniDWordWatch : IMiniWatch
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
|
|
|
|
public int Address { get; private set; }
|
2013-09-20 01:18:55 +00:00
|
|
|
|
private uint _previous;
|
2013-09-19 23:45:29 +00:00
|
|
|
|
|
|
|
|
|
public MiniDWordWatch(MemoryDomain domain, int addr, bool bigEndian)
|
|
|
|
|
{
|
|
|
|
|
Address = addr;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
SetPreviousToCurrent(domain, bigEndian);
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Previous
|
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
get { return (int)_previous; }
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
2013-09-21 23:55:17 +00:00
|
|
|
|
|
|
|
|
|
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
|
|
|
|
|
{
|
|
|
|
|
_previous = domain.PeekDWord(Address, bigendian ? Endian.Big : Endian.Little);
|
|
|
|
|
}
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
private sealed class MiniByteWatchDetailed : IMiniWatch, IMiniWatchDetails
|
2013-09-20 01:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
public int Address { get; private set; }
|
|
|
|
|
private byte _previous;
|
|
|
|
|
int _changecount = 0;
|
|
|
|
|
|
|
|
|
|
public MiniByteWatchDetailed(MemoryDomain domain, int addr)
|
|
|
|
|
{
|
|
|
|
|
Address = addr;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
SetPreviousToCurrent(domain, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
|
|
|
|
|
{
|
|
|
|
|
_previous = domain.PeekByte(Address);
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Previous
|
|
|
|
|
{
|
|
|
|
|
get { return _previous; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ChangeCount
|
|
|
|
|
{
|
|
|
|
|
get { return _changecount; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 14:09:37 +00:00
|
|
|
|
public void Update(Watch.PreviousType type, MemoryDomain domain)
|
2013-09-20 01:18:55 +00:00
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
byte value = domain.PeekByte(Address);
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case Watch.PreviousType.Original:
|
|
|
|
|
if (value != Previous)
|
|
|
|
|
{
|
|
|
|
|
_changecount++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Watch.PreviousType.LastSearch:
|
|
|
|
|
if (value != _previous)
|
|
|
|
|
{
|
|
|
|
|
_changecount++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Watch.PreviousType.LastFrame:
|
|
|
|
|
value = domain.PeekByte(Address);
|
|
|
|
|
if (value != Previous)
|
|
|
|
|
{
|
|
|
|
|
_changecount++;
|
|
|
|
|
}
|
|
|
|
|
_previous = value;
|
|
|
|
|
break;
|
|
|
|
|
case Watch.PreviousType.LastChange:
|
|
|
|
|
//TODO: this feature requires yet another variable, ugh
|
|
|
|
|
if (value != Previous)
|
|
|
|
|
{
|
|
|
|
|
_changecount++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
2013-09-22 01:53:20 +00:00
|
|
|
|
|
|
|
|
|
public void ClearChangeCount()
|
|
|
|
|
{
|
|
|
|
|
_changecount = 0;
|
|
|
|
|
}
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
private sealed class MiniWordWatchDetailed : IMiniWatch, IMiniWatchDetails
|
2013-09-20 01:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
public int Address { get; private set; }
|
|
|
|
|
private ushort _previous;
|
|
|
|
|
int _changecount = 0;
|
|
|
|
|
|
|
|
|
|
public MiniWordWatchDetailed(MemoryDomain domain, int addr, bool bigEndian)
|
|
|
|
|
{
|
|
|
|
|
Address = addr;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
SetPreviousToCurrent(domain, bigEndian);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
|
|
|
|
|
{
|
|
|
|
|
_previous = domain.PeekWord(Address, bigendian ? Endian.Big : Endian.Little);
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Previous
|
|
|
|
|
{
|
|
|
|
|
get { return _previous; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ChangeCount
|
|
|
|
|
{
|
|
|
|
|
get { return _changecount; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 14:09:37 +00:00
|
|
|
|
public void Update(Watch.PreviousType type, MemoryDomain domain)
|
2013-09-20 01:18:55 +00:00
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
ushort value;
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case Watch.PreviousType.LastChange:
|
|
|
|
|
break;
|
|
|
|
|
case Watch.PreviousType.LastFrame:
|
|
|
|
|
value = domain.PeekByte(Address); //TODO: need big endian passed in
|
|
|
|
|
if (value != Previous)
|
|
|
|
|
{
|
|
|
|
|
_changecount++;
|
|
|
|
|
_previous = value;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
2013-09-22 01:53:20 +00:00
|
|
|
|
|
|
|
|
|
public void ClearChangeCount()
|
|
|
|
|
{
|
|
|
|
|
_changecount = 0;
|
|
|
|
|
}
|
2013-09-20 01:18:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
public sealed class MiniDWordWatchDetailed : IMiniWatch, IMiniWatchDetails
|
2013-09-20 01:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
public int Address { get; private set; }
|
|
|
|
|
private uint _previous;
|
|
|
|
|
int _changecount = 0;
|
|
|
|
|
|
|
|
|
|
public MiniDWordWatchDetailed(MemoryDomain domain, int addr, bool bigEndian)
|
|
|
|
|
{
|
|
|
|
|
Address = addr;
|
2013-09-21 23:55:17 +00:00
|
|
|
|
SetPreviousToCurrent(domain, bigEndian);
|
|
|
|
|
}
|
2013-09-20 01:18:55 +00:00
|
|
|
|
|
2013-09-21 23:55:17 +00:00
|
|
|
|
public void SetPreviousToCurrent(MemoryDomain domain, bool bigendian)
|
|
|
|
|
{
|
|
|
|
|
_previous = domain.PeekDWord(Address, bigendian ? Endian.Big : Endian.Little);
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-20 01:18:55 +00:00
|
|
|
|
public int Previous
|
|
|
|
|
{
|
|
|
|
|
get { return (int)_previous; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ChangeCount
|
|
|
|
|
{
|
|
|
|
|
get { return _changecount; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-21 14:09:37 +00:00
|
|
|
|
public void Update(Watch.PreviousType type, MemoryDomain domain)
|
2013-09-19 23:45:29 +00:00
|
|
|
|
{
|
2013-09-21 14:09:37 +00:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case Watch.PreviousType.LastChange:
|
|
|
|
|
break;
|
|
|
|
|
case Watch.PreviousType.LastFrame:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
2013-09-22 01:53:20 +00:00
|
|
|
|
|
|
|
|
|
public void ClearChangeCount()
|
|
|
|
|
{
|
|
|
|
|
_changecount = 0;
|
|
|
|
|
}
|
2013-09-19 23:45:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-16 01:24:06 +00:00
|
|
|
|
public class Settings
|
|
|
|
|
{
|
|
|
|
|
/*Require restart*/
|
|
|
|
|
public enum SearchMode { Fast, Detailed }
|
2013-09-21 14:09:37 +00:00
|
|
|
|
|
2013-09-16 01:24:06 +00:00
|
|
|
|
public SearchMode Mode = SearchMode.Detailed;
|
|
|
|
|
public MemoryDomain Domain = Global.Emulator.MainMemory;
|
|
|
|
|
public Watch.WatchSize Size = Watch.WatchSize.Byte;
|
|
|
|
|
public bool CheckMisAligned = false;
|
|
|
|
|
|
|
|
|
|
/*Can be changed mid-search*/
|
|
|
|
|
public Watch.DisplayType Type = Watch.DisplayType.Unsigned;
|
|
|
|
|
public bool BigEndian = false;
|
2013-09-20 01:18:55 +00:00
|
|
|
|
public Watch.PreviousType PreviousType = Watch.PreviousType.LastSearch;
|
2013-09-16 01:24:06 +00:00
|
|
|
|
}
|
2013-09-20 01:18:55 +00:00
|
|
|
|
|
2013-09-16 01:24:06 +00:00
|
|
|
|
#endregion
|
2013-09-14 19:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|