ram watch - add IsValid method
This commit is contained in:
parent
c1caa3e346
commit
1721e4f9ea
|
@ -170,6 +170,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return Type switch
|
||||
{
|
||||
_ when !IsValid => "-",
|
||||
DisplayType.Unsigned => val.ToString(),
|
||||
DisplayType.Signed => ((sbyte) val).ToString(),
|
||||
DisplayType.Hex => $"{val:X2}",
|
||||
|
@ -184,6 +185,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public override string Diff => $"{_value - (short)_previous:+#;-#;0}";
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Watch is valid, false otherwise
|
||||
/// </summary>
|
||||
public override bool IsValid => Domain.Size == 0 || Address < Domain.Size;
|
||||
|
||||
/// <summary>
|
||||
/// Get the maximum possible value
|
||||
/// </summary>
|
||||
|
|
|
@ -194,24 +194,24 @@ namespace BizHawk.Client.Common
|
|||
// TODO: Implements IFormattable
|
||||
public string FormatValue(uint val)
|
||||
{
|
||||
switch (Type)
|
||||
string FormatFloat()
|
||||
{
|
||||
default:
|
||||
case DisplayType.Unsigned:
|
||||
return val.ToString();
|
||||
case DisplayType.Signed:
|
||||
return ((int)val).ToString();
|
||||
case DisplayType.Hex:
|
||||
return $"{val:X8}";
|
||||
case DisplayType.FixedPoint_20_12:
|
||||
return $"{(int)val / 4096.0:0.######}";
|
||||
case DisplayType.FixedPoint_16_16:
|
||||
return $"{(int)val / 65536.0:0.######}";
|
||||
case DisplayType.Float:
|
||||
var bytes = BitConverter.GetBytes(val);
|
||||
var _float = BitConverter.ToSingle(bytes, 0);
|
||||
return _float.ToString(); // adelikat: decided that we like sci notation instead of spooky rounding
|
||||
}
|
||||
var bytes = BitConverter.GetBytes(val);
|
||||
var _float = BitConverter.ToSingle(bytes, 0);
|
||||
return _float.ToString();
|
||||
};
|
||||
|
||||
return Type switch
|
||||
{
|
||||
_ when !IsValid => "-",
|
||||
DisplayType.Unsigned => val.ToString(),
|
||||
DisplayType.Signed => ((int)val).ToString(),
|
||||
DisplayType.Hex => $"{val:X8}",
|
||||
DisplayType.FixedPoint_20_12 => $"{(int)val / 4096.0:0.######}",
|
||||
DisplayType.FixedPoint_16_16 => $"{(int)val / 65536.0:0.######}",
|
||||
DisplayType.Float => FormatFloat(),
|
||||
_ => val.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -220,6 +220,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public override string Diff => $"{_value - (long)_previous:+#;-#;0}";
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Watch is valid, false otherwise
|
||||
/// </summary>
|
||||
public override bool IsValid => Domain.Size == 0 || Address < (Domain.Size - 3);
|
||||
|
||||
/// <summary>
|
||||
/// Get the maximum possible value
|
||||
/// </summary>
|
||||
|
|
|
@ -91,6 +91,11 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ignore that stuff
|
||||
/// </summary>
|
||||
public override bool IsValid => true;
|
||||
|
||||
/// <summary>
|
||||
/// Ignore that stuff
|
||||
/// </summary>
|
||||
|
|
|
@ -267,67 +267,55 @@ namespace BizHawk.Client.Common
|
|||
|
||||
protected byte GetByte()
|
||||
{
|
||||
if (_domain.Size == 0)
|
||||
if (!IsValid)
|
||||
{
|
||||
return _domain.PeekByte(Address);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _domain.PeekByte(Address % _domain.Size);
|
||||
return _domain.PeekByte(Address);
|
||||
}
|
||||
|
||||
protected ushort GetWord()
|
||||
{
|
||||
if (_domain.Size == 0)
|
||||
if (!IsValid)
|
||||
{
|
||||
return _domain.PeekUshort(Address, BigEndian);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _domain.PeekUshort(Address % _domain.Size, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
return _domain.PeekUshort(Address, BigEndian);
|
||||
}
|
||||
|
||||
protected uint GetDWord()
|
||||
{
|
||||
if (_domain.Size == 0)
|
||||
if (!IsValid)
|
||||
{
|
||||
return _domain.PeekUint(Address, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _domain.PeekUint(Address % _domain.Size, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
return _domain.PeekUint(Address, BigEndian);
|
||||
}
|
||||
|
||||
protected void PokeByte(byte val)
|
||||
{
|
||||
if (_domain.Size == 0)
|
||||
if (IsValid)
|
||||
{
|
||||
_domain.PokeByte(Address, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
_domain.PokeByte(Address % _domain.Size, val);
|
||||
}
|
||||
}
|
||||
|
||||
protected void PokeWord(ushort val)
|
||||
{
|
||||
if (_domain.Size == 0)
|
||||
if (IsValid)
|
||||
{
|
||||
_domain.PokeUshort(Address, val, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
}
|
||||
else
|
||||
{
|
||||
_domain.PokeUshort(Address % _domain.Size, val, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
_domain.PokeUshort(Address, val, BigEndian);
|
||||
}
|
||||
}
|
||||
|
||||
protected void PokeDWord(uint val)
|
||||
{
|
||||
if (_domain.Size == 0)
|
||||
if (IsValid)
|
||||
{
|
||||
_domain.PokeUint(Address, val, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
}
|
||||
else
|
||||
{
|
||||
_domain.PokeUint(Address % _domain.Size, val, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
_domain.PokeUint(Address, val, BigEndian);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,6 +460,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public abstract string ValueString { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Watch is valid, false otherwise
|
||||
/// </summary>
|
||||
public abstract bool IsValid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Try to sets the value into the <see cref="MemoryDomain"/>
|
||||
/// at the current <see cref="Watch"/> address
|
||||
|
|
|
@ -180,6 +180,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return Type switch
|
||||
{
|
||||
_ when !IsValid => "-",
|
||||
DisplayType.Unsigned => val.ToString(),
|
||||
DisplayType.Signed => ((short) val).ToString(), DisplayType.Hex => $"{val:X4}",
|
||||
DisplayType.FixedPoint_12_4 => $"{val / 16.0:F4}",
|
||||
|
@ -199,6 +200,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public override string Diff => $"{_value - (int)_previous:+#;-#;0}";
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the Watch is valid, false otherwise
|
||||
/// </summary>
|
||||
public override bool IsValid => Domain.Size == 0 || Address < (Domain.Size - 1);
|
||||
|
||||
/// <summary>
|
||||
/// Get the maximum possible value
|
||||
/// </summary>
|
||||
|
|
|
@ -70,13 +70,13 @@
|
|||
<Content Include="discohawk.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="About.cs" SubType="Form" />
|
||||
<Compile Update="About.cs" />
|
||||
<Compile Update="About.Designer.cs" DependentUpon="About.cs" />
|
||||
<EmbeddedResource Update="About.resx" DependentUpon="About.cs" />
|
||||
<Compile Update="ComparisonResults.cs" SubType="Form" />
|
||||
<Compile Update="ComparisonResults.cs" />
|
||||
<Compile Update="ComparisonResults.Designer.cs" DependentUpon="ComparisonResults.cs" />
|
||||
<EmbeddedResource Update="ComparisonResults.resx" DependentUpon="ComparisonResults.cs" />
|
||||
<Compile Update="MainDiscoForm.cs" SubType="Form" />
|
||||
<Compile Update="MainDiscoForm.cs" />
|
||||
<Compile Update="MainDiscoForm.Designer.cs" DependentUpon="MainDiscoForm.cs" />
|
||||
|
||||
<EmbeddedResource Remove="MainDiscoForm.resx" />
|
||||
|
|
|
@ -404,7 +404,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
var result = we.ShowHawkDialog(this);
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
Changes();
|
||||
if (duplicate)
|
||||
{
|
||||
_watches.AddRange(we.Watches);
|
||||
|
@ -418,6 +417,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
_watches[indexes[i]] = we.Watches[i];
|
||||
}
|
||||
}
|
||||
Changes();
|
||||
}
|
||||
|
||||
GeneralUpdate();
|
||||
|
@ -587,7 +587,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
ErrorIconButton.Visible = _watches.Where(watch => !watch.IsSeparator).Any(watch => watch.Address >= watch.Domain.Size);
|
||||
ErrorIconButton.Visible = _watches.Where(watch => !watch.IsSeparator).Any(watch => !watch.IsValid);
|
||||
|
||||
MessageLabel.Text = message;
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
color = BackColor;
|
||||
}
|
||||
else if (_watches[index].Address >= _watches[index].Domain.Size)
|
||||
else if (!_watches[index].IsValid)
|
||||
{
|
||||
color = Color.PeachPuff;
|
||||
}
|
||||
|
@ -1230,7 +1230,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void ErrorIconButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var items = _watches
|
||||
.Where(watch => watch.Address >= watch.Domain.Size)
|
||||
.Where(watch => !watch.IsValid)
|
||||
.ToList(); // enumerate because _watches is about to be changed
|
||||
|
||||
foreach (var item in items)
|
||||
|
|
Loading…
Reference in New Issue