@@ -10,124 +10,72 @@ internal interface IMiniWatch
1010 {
1111 long Address { get ; }
1212 uint Previous { get ; }
13+
14+ uint GetValue ( MemoryDomain domain , bool bigEndian ) ;
15+
1316 void SetPreviousToCurrent ( MemoryDomain domain , bool bigEndian ) ;
1417 bool IsValid ( MemoryDomain domain ) ;
1518 }
1619
17- internal class MiniByteWatch : IMiniWatch
20+ internal abstract class MiniWatchBase : IMiniWatch
1821 {
1922 public long Address { get ; }
20- private protected byte _previous ;
2123
22- public MiniByteWatch ( MemoryDomain domain , long addr )
24+ public uint Previous { get ; protected set ; }
25+
26+ protected MiniWatchBase ( long addr , uint prevValue )
2327 {
2428 Address = addr ;
25- _previous = GetByte ( Address , domain ) ;
29+ Previous = prevValue ;
2630 }
2731
28- public uint Previous => _previous ;
32+ public uint GetValue ( MemoryDomain domain , bool bigEndian )
33+ => IsValid ( domain ) ? GetValueInner ( Address , domain , bigEndian : bigEndian ) : default ;
34+
35+ protected abstract uint GetValueInner ( long address , MemoryDomain domain , bool bigEndian ) ;
2936
3037 public bool IsValid ( MemoryDomain domain )
31- {
32- return IsValid ( Address , domain ) ;
33- }
38+ => IsValid ( Address , domain ) ;
39+
40+ protected abstract bool IsValid ( long address , MemoryDomain domain ) ;
3441
3542 public virtual void SetPreviousToCurrent ( MemoryDomain domain , bool bigEndian )
36- {
37- _previous = GetByte ( Address , domain ) ;
38- }
43+ => Previous = GetValueInner ( Address , domain , bigEndian : bigEndian ) ;
44+ }
3945
40- public static bool IsValid ( long address , MemoryDomain domain )
41- {
42- return address < domain . Size ;
43- }
46+ internal class MiniByteWatch : MiniWatchBase
47+ {
48+ public MiniByteWatch ( MemoryDomain domain , long addr )
49+ : base ( addr : addr , prevValue : domain . PeekByte ( addr ) ) { }
4450
45- public static byte GetByte ( long address , MemoryDomain domain )
46- {
47- if ( ! IsValid ( address , domain ) )
48- {
49- return 0 ;
50- }
51+ protected override uint GetValueInner ( long address , MemoryDomain domain , bool bigEndian )
52+ => domain . PeekByte ( address ) ;
5153
52- return domain . PeekByte ( address ) ;
53- }
54+ protected override bool IsValid ( long address , MemoryDomain domain )
55+ => 0L <= address && address < domain . Size ;
5456 }
5557
56- internal class MiniWordWatch : IMiniWatch
58+ internal class MiniWordWatch : MiniWatchBase
5759 {
58- public long Address { get ; }
59- private protected ushort _previous ;
60-
6160 public MiniWordWatch ( MemoryDomain domain , long addr , bool bigEndian )
62- {
63- Address = addr ;
64- _previous = GetUshort ( Address , domain , bigEndian ) ;
65- }
61+ : base ( addr : addr , prevValue : domain . PeekUshort ( addr , bigEndian : bigEndian ) ) { }
6662
67- public uint Previous => _previous ;
63+ protected override uint GetValueInner ( long address , MemoryDomain domain , bool bigEndian )
64+ => domain . PeekUshort ( address , bigEndian ) ;
6865
69- public virtual void SetPreviousToCurrent ( MemoryDomain domain , bool bigEndian )
70- {
71- _previous = GetUshort ( Address , domain , bigEndian ) ;
72- }
73-
74- public bool IsValid ( MemoryDomain domain )
75- {
76- return IsValid ( Address , domain ) ;
77- }
78-
79- public static bool IsValid ( long address , MemoryDomain domain )
80- {
81- return address < ( domain . Size - 1 ) ;
82- }
83-
84- public static ushort GetUshort ( long address , MemoryDomain domain , bool bigEndian )
85- {
86- if ( ! IsValid ( address , domain ) )
87- {
88- return 0 ;
89- }
90-
91- return domain . PeekUshort ( address , bigEndian ) ;
92- }
66+ protected override bool IsValid ( long address , MemoryDomain domain )
67+ => 0L <= address && address <= domain . Size - sizeof ( ushort ) ;
9368 }
9469
95- internal class MiniDWordWatch : IMiniWatch
70+ internal class MiniDWordWatch : MiniWatchBase
9671 {
97- public long Address { get ; }
98- private protected uint _previous ;
99-
10072 public MiniDWordWatch ( MemoryDomain domain , long addr , bool bigEndian )
101- {
102- Address = addr ;
103- _previous = GetUint ( Address , domain , bigEndian ) ;
104- }
73+ : base ( addr : addr , prevValue : domain . PeekUint ( addr , bigEndian : bigEndian ) ) { }
10574
106- public uint Previous => _previous ;
75+ protected override uint GetValueInner ( long address , MemoryDomain domain , bool bigEndian )
76+ => domain . PeekUint ( address , bigEndian ) ;
10777
108- public virtual void SetPreviousToCurrent ( MemoryDomain domain , bool bigEndian )
109- {
110- _previous = GetUint ( Address , domain , bigEndian ) ;
111- }
112-
113- public bool IsValid ( MemoryDomain domain )
114- {
115- return IsValid ( Address , domain ) ;
116- }
117-
118- public static bool IsValid ( long address , MemoryDomain domain )
119- {
120- return address < ( domain . Size - 3 ) ;
121- }
122-
123- public static uint GetUint ( long address , MemoryDomain domain , bool bigEndian )
124- {
125- if ( ! IsValid ( address , domain ) )
126- {
127- return 0 ;
128- }
129-
130- return domain . PeekUint ( address , bigEndian ) ;
131- }
78+ protected override bool IsValid ( long address , MemoryDomain domain )
79+ => 0L <= address && address <= domain . Size - sizeof ( uint ) ;
13280 }
13381}
0 commit comments