From a313e5c872383eb1648683fbad1dcb7e419098b3 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Wed, 26 Mar 2025 04:45:21 +1000 Subject: [PATCH] Provide some base implementations on `Watch` --- src/BizHawk.Client.Common/tools/Watch/ByteWatch.cs | 4 ---- src/BizHawk.Client.Common/tools/Watch/DWordWatch.cs | 4 ---- .../tools/Watch/SeparatorWatch.cs | 5 ----- src/BizHawk.Client.Common/tools/Watch/Watch.cs | 13 +++++++++++-- src/BizHawk.Client.Common/tools/Watch/WordWatch.cs | 4 ---- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/BizHawk.Client.Common/tools/Watch/ByteWatch.cs b/src/BizHawk.Client.Common/tools/Watch/ByteWatch.cs index d2480d7c45..224e1a4e99 100644 --- a/src/BizHawk.Client.Common/tools/Watch/ByteWatch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/ByteWatch.cs @@ -99,10 +99,6 @@ namespace BizHawk.Client.Common public override string Diff => $"{_value - _previous:+#;-#;0}"; - public override bool IsValid => Domain.Size == 0 || Address < Domain.Size; - - public override uint MaxValue => byte.MaxValue; - public override int Value => GetByte(); public override string ValueString => FormatValue(GetByte()); diff --git a/src/BizHawk.Client.Common/tools/Watch/DWordWatch.cs b/src/BizHawk.Client.Common/tools/Watch/DWordWatch.cs index 9096a72911..986b6022ab 100644 --- a/src/BizHawk.Client.Common/tools/Watch/DWordWatch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/DWordWatch.cs @@ -100,10 +100,6 @@ namespace BizHawk.Client.Common public override string Diff => $"{_value - (long)_previous:+#;-#;0}"; - public override bool IsValid => Domain.Size == 0 || Address < (Domain.Size - 3); - - public override uint MaxValue => uint.MaxValue; - public override int Value => (int)GetDWord(); public override string ValueString => FormatValue(GetDWord()); diff --git a/src/BizHawk.Client.Common/tools/Watch/SeparatorWatch.cs b/src/BizHawk.Client.Common/tools/Watch/SeparatorWatch.cs index 58dca2a42d..4cc21bb0fb 100644 --- a/src/BizHawk.Client.Common/tools/Watch/SeparatorWatch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/SeparatorWatch.cs @@ -90,11 +90,6 @@ namespace BizHawk.Client.Common /// public override string Diff => ""; - /// - /// Ignore that stuff - /// - public override uint MaxValue => 0; - /// /// Ignore that stuff /// diff --git a/src/BizHawk.Client.Common/tools/Watch/Watch.cs b/src/BizHawk.Client.Common/tools/Watch/Watch.cs index c9a2c79990..c196beada7 100644 --- a/src/BizHawk.Client.Common/tools/Watch/Watch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/Watch.cs @@ -502,7 +502,15 @@ namespace BizHawk.Client.Common /// /// Gets the maximum possible value /// - public abstract uint MaxValue { get; } + public uint MaxValue + => Size switch + { + WatchSize.Separator => 0, + WatchSize.Byte => byte.MaxValue, + WatchSize.Word => ushort.MaxValue, + WatchSize.DWord => uint.MaxValue, + _ => throw new InvalidOperationException(), + }; /// /// Gets the current value @@ -517,7 +525,8 @@ namespace BizHawk.Client.Common /// /// Returns true if the Watch is valid, false otherwise /// - public abstract bool IsValid { get; } + public virtual bool IsValid + => Domain.Size is 0 || Address <= Domain.Size - unchecked((long) Size); /// /// Try to sets the value into the diff --git a/src/BizHawk.Client.Common/tools/Watch/WordWatch.cs b/src/BizHawk.Client.Common/tools/Watch/WordWatch.cs index 15f8fb446a..10fcaa6bd0 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WordWatch.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WordWatch.cs @@ -98,10 +98,6 @@ namespace BizHawk.Client.Common public override string Diff => $"{_value - _previous:+#;-#;0}"; - public override bool IsValid => Domain.Size == 0 || Address < (Domain.Size - 1); - - public override uint MaxValue => ushort.MaxValue; - public override int Value => GetWord(); public override string ValueString => FormatValue(GetWord());