-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathIMiniWatch.cs
More file actions
94 lines (70 loc) · 3.06 KB
/
IMiniWatch.cs
File metadata and controls
94 lines (70 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common.RamSearchEngine
{
/// <summary>
/// Represents a Ram address for watching in the <see cref="RamSearchEngine" />
/// With the minimal details necessary for searching
/// </summary>
internal interface IMiniWatch
{
long Address { get; }
ulong Previous { get; }
ulong GetValue(MemoryDomain domain, bool bigEndian);
void SetPreviousToCurrent(MemoryDomain domain, bool bigEndian);
bool IsValid(MemoryDomain domain);
}
internal abstract class MiniWatchBase : IMiniWatch
{
public long Address { get; }
public ulong Previous { get; protected set; }
protected MiniWatchBase(long addr, ulong prevValue)
{
Address = addr;
Previous = prevValue;
}
public ulong GetValue(MemoryDomain domain, bool bigEndian)
=> IsValid(domain) ? GetValueInner(Address, domain, bigEndian: bigEndian) : default;
protected abstract ulong GetValueInner(long address, MemoryDomain domain, bool bigEndian);
public bool IsValid(MemoryDomain domain)
=> IsValid(Address, domain);
protected abstract bool IsValid(long address, MemoryDomain domain);
public virtual void SetPreviousToCurrent(MemoryDomain domain, bool bigEndian)
=> Previous = GetValueInner(Address, domain, bigEndian: bigEndian);
}
internal class MiniByteWatch : MiniWatchBase
{
public MiniByteWatch(MemoryDomain domain, long addr)
: base(addr: addr, prevValue: domain.PeekByte(addr)) {}
protected override ulong GetValueInner(long address, MemoryDomain domain, bool bigEndian)
=> domain.PeekByte(address);
protected override bool IsValid(long address, MemoryDomain domain)
=> 0L <= address && address < domain.Size;
}
internal class MiniWordWatch : MiniWatchBase
{
public MiniWordWatch(MemoryDomain domain, long addr, bool bigEndian)
: base(addr: addr, prevValue: domain.PeekUshort(addr, bigEndian: bigEndian)) {}
protected override ulong GetValueInner(long address, MemoryDomain domain, bool bigEndian)
=> domain.PeekUshort(address, bigEndian);
protected override bool IsValid(long address, MemoryDomain domain)
=> 0L <= address && address <= domain.Size - sizeof(ushort);
}
internal class MiniDWordWatch : MiniWatchBase
{
public MiniDWordWatch(MemoryDomain domain, long addr, bool bigEndian)
: base(addr: addr, prevValue: domain.PeekUint(addr, bigEndian: bigEndian)) {}
protected override ulong GetValueInner(long address, MemoryDomain domain, bool bigEndian)
=> domain.PeekUint(address, bigEndian);
protected override bool IsValid(long address, MemoryDomain domain)
=> 0L <= address && address <= domain.Size - sizeof(uint);
}
internal class MiniQWordWatch : MiniWatchBase
{
public MiniQWordWatch(MemoryDomain domain, long addr, bool bigEndian)
: base(addr: addr, prevValue: domain.PeekUint(addr, bigEndian: bigEndian)) {}
protected override ulong GetValueInner(long address, MemoryDomain domain, bool bigEndian)
=> domain.PeekUlong(address, bigEndian);
protected override bool IsValid(long address, MemoryDomain domain)
=> 0L <= address && address <= domain.Size - sizeof(ulong);
}
}