Skip to content

Commit b2a0ad0

Browse files
committed
Provide some base implementations on Watch
1 parent 9e454bd commit b2a0ad0

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

src/BizHawk.Client.Common/tools/Watch/ByteWatch.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ public string FormatValue(byte val)
9999

100100
public override string Diff => $"{_value - _previous:+#;-#;0}";
101101

102-
public override bool IsValid => Domain.Size == 0 || Address < Domain.Size;
103-
104-
public override uint MaxValue => byte.MaxValue;
105-
106102
public override int Value => GetByte();
107103

108104
public override string ValueString => FormatValue(GetByte());

src/BizHawk.Client.Common/tools/Watch/DWordWatch.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ public string FormatValue(uint val)
100100

101101
public override string Diff => $"{_value - (long)_previous:+#;-#;0}";
102102

103-
public override bool IsValid => Domain.Size == 0 || Address < (Domain.Size - 3);
104-
105-
public override uint MaxValue => uint.MaxValue;
106-
107103
public override int Value => (int)GetDWord();
108104

109105
public override string ValueString => FormatValue(GetDWord());

src/BizHawk.Client.Common/tools/Watch/SeparatorWatch.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ public override void ResetPrevious()
9090
/// </summary>
9191
public override string Diff => "";
9292

93-
/// <summary>
94-
/// Ignore that stuff
95-
/// </summary>
96-
public override uint MaxValue => 0;
97-
9893
/// <summary>
9994
/// Ignore that stuff
10095
/// </summary>

src/BizHawk.Client.Common/tools/Watch/Watch.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,15 @@ public override string ToString()
502502
/// <summary>
503503
/// Gets the maximum possible value
504504
/// </summary>
505-
public abstract uint MaxValue { get; }
505+
public uint MaxValue
506+
=> Size switch
507+
{
508+
WatchSize.Separator => 0,
509+
WatchSize.Byte => byte.MaxValue,
510+
WatchSize.Word => ushort.MaxValue,
511+
WatchSize.DWord => uint.MaxValue,
512+
_ => throw new InvalidOperationException()
513+
};
506514

507515
/// <summary>
508516
/// Gets the current value
@@ -517,7 +525,8 @@ public override string ToString()
517525
/// <summary>
518526
/// Returns true if the Watch is valid, false otherwise
519527
/// </summary>
520-
public abstract bool IsValid { get; }
528+
public virtual bool IsValid
529+
=> Domain.Size is 0 || Address <= Domain.Size - unchecked((long) Size);
521530

522531
/// <summary>
523532
/// Try to sets the value into the <see cref="MemoryDomain"/>

src/BizHawk.Client.Common/tools/Watch/WordWatch.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ public string FormatValue(ushort val)
9898

9999
public override string Diff => $"{_value - _previous:+#;-#;0}";
100100

101-
public override bool IsValid => Domain.Size == 0 || Address < (Domain.Size - 1);
102-
103-
public override uint MaxValue => ushort.MaxValue;
104-
105101
public override int Value => GetWord();
106102

107103
public override string ValueString => FormatValue(GetWord());

0 commit comments

Comments
 (0)