Provide some base implementations on `Watch`

This commit is contained in:
YoshiRulz 2025-03-26 04:45:21 +10:00
parent 9e454bda6d
commit b2a0ad0857
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
5 changed files with 11 additions and 19 deletions

View File

@ -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());

View File

@ -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());

View File

@ -90,11 +90,6 @@ namespace BizHawk.Client.Common
/// </summary>
public override string Diff => "";
/// <summary>
/// Ignore that stuff
/// </summary>
public override uint MaxValue => 0;
/// <summary>
/// Ignore that stuff
/// </summary>

View File

@ -502,7 +502,15 @@ namespace BizHawk.Client.Common
/// <summary>
/// Gets the maximum possible value
/// </summary>
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()
};
/// <summary>
/// Gets the current value
@ -517,7 +525,8 @@ namespace BizHawk.Client.Common
/// <summary>
/// Returns true if the Watch is valid, false otherwise
/// </summary>
public abstract bool IsValid { get; }
public virtual bool IsValid
=> Domain.Size is 0 || Address <= Domain.Size - unchecked((long) Size);
/// <summary>
/// Try to sets the value into the <see cref="MemoryDomain"/>

View File

@ -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());