Watch classes - refactor, simplify, and cleanup code
This commit is contained in:
parent
c2fa9070a3
commit
f576cb14b0
|
@ -1,286 +1,254 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common.NumberExtensions;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// This class holds a byte (8 bits) <see cref="Watch"/>
|
||||
/// </summary>
|
||||
public sealed class ByteWatch : Watch
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private byte _previous;
|
||||
private byte _value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region cTor(s)
|
||||
|
||||
/// <summary>
|
||||
/// Inialize a new instance of <see cref="ByteWatch"/>
|
||||
/// </summary>
|
||||
/// <param name="domain"><see cref="MemoryDomain"/> where you want to track</param>
|
||||
/// <param name="address">The address you want to track</param>
|
||||
/// <param name="type">How you you want to display the value See <see cref="DisplayType"/></param>
|
||||
/// <param name="bigEndian">Specify the endianess. true for big endian</param>
|
||||
/// <param name="note">A custom note about the <see cref="Watch"/></param>
|
||||
/// <param name="value">Current value</param>
|
||||
/// <param name="previous">Previous value</param>
|
||||
/// <param name="changeCount">How many times value has changed</param>
|
||||
/// <exception cref="ArgumentException">Occurs when a <see cref="DisplayType"/> is incompatible with <see cref="WatchSize.Byte"/></exception>
|
||||
internal ByteWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, byte value, byte previous, int changeCount)
|
||||
: base(domain, address, WatchSize.Byte, type, bigEndian, note)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
_value = GetByte();
|
||||
}
|
||||
else
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
_previous = previous;
|
||||
_changecount = changeCount;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Enumerate which <see cref="DisplayType"/> are valid for a <see cref="ByteWatch"/>
|
||||
/// </summary>
|
||||
public static IEnumerable<DisplayType> ValidTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return DisplayType.Unsigned;
|
||||
yield return DisplayType.Signed;
|
||||
yield return DisplayType.Hex;
|
||||
yield return DisplayType.Binary;
|
||||
}
|
||||
}
|
||||
|
||||
#region Implements
|
||||
|
||||
/// <summary>
|
||||
/// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="ByteWatch"/>
|
||||
/// </summary>
|
||||
/// <returns>An enumartion that contains all valid <see cref="DisplayType"/></returns>
|
||||
public override IEnumerable<DisplayType> AvailableTypes()
|
||||
{
|
||||
return ValidTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the previous value; set it to the current one
|
||||
/// </summary>
|
||||
public override void ResetPrevious()
|
||||
{
|
||||
_previous = GetByte();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to sets the value into the <see cref="MemoryDomain"/>
|
||||
/// at the current <see cref="Watch"/> address
|
||||
/// </summary>
|
||||
/// <param name="value">Value to set</param>
|
||||
/// <returns>True if value successfully sets; othewise, false</returns>
|
||||
public override bool Poke(string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte val = 0;
|
||||
switch (Type)
|
||||
{
|
||||
case DisplayType.Unsigned:
|
||||
if (value.IsUnsigned())
|
||||
{
|
||||
val = (byte)int.Parse(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case DisplayType.Signed:
|
||||
if (value.IsSigned())
|
||||
{
|
||||
val = (byte)(sbyte)int.Parse(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case DisplayType.Hex:
|
||||
if (value.IsHex())
|
||||
{
|
||||
val = (byte)int.Parse(value, NumberStyles.HexNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case DisplayType.Binary:
|
||||
if (value.IsBinary())
|
||||
{
|
||||
val = (byte)Convert.ToInt32(value, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Global.CheatList.Contains(Domain, _address))
|
||||
{
|
||||
var cheat = Global.CheatList.FirstOrDefault(c => c.Address == _address && c.Domain == Domain);
|
||||
|
||||
if (cheat != (Cheat)null)
|
||||
{
|
||||
cheat.PokeValue(val);
|
||||
PokeByte(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PokeByte(val);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the Watch (read it from <see cref="MemoryDomain"/>
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
switch (Global.Config.RamWatchDefinePrevious)
|
||||
{
|
||||
case PreviousType.Original:
|
||||
return;
|
||||
case PreviousType.LastChange:
|
||||
var temp = _value;
|
||||
_value = GetByte();
|
||||
if (_value != temp)
|
||||
{
|
||||
_previous = _value;
|
||||
_changecount++;
|
||||
}
|
||||
|
||||
break;
|
||||
case PreviousType.LastFrame:
|
||||
_previous = _value;
|
||||
_value = GetByte();
|
||||
if (_value != Previous)
|
||||
{
|
||||
_changecount++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Implements
|
||||
|
||||
// TODO: Implements IFormattable
|
||||
public string FormatValue(byte val)
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
default:
|
||||
case DisplayType.Unsigned:
|
||||
return val.ToString();
|
||||
case DisplayType.Signed:
|
||||
return ((sbyte)val).ToString();
|
||||
case DisplayType.Hex:
|
||||
return val.ToHexString(2);
|
||||
case DisplayType.Binary:
|
||||
return Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " ");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#region Implements
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of difference
|
||||
/// between current value and the previous one
|
||||
/// </summary>
|
||||
public override string Diff
|
||||
{
|
||||
get
|
||||
{
|
||||
string diff = "";
|
||||
int diffVal = _value - _previous;
|
||||
if (diffVal > 0)
|
||||
{
|
||||
diff = "+";
|
||||
}
|
||||
else if (diffVal < 0)
|
||||
{
|
||||
diff = "-";
|
||||
}
|
||||
|
||||
return $"{diff}{FormatValue((byte)Math.Abs(diffVal))}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the maximum possible value
|
||||
/// </summary>
|
||||
public override uint MaxValue => byte.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Get the current value
|
||||
/// </summary>
|
||||
public override int Value => GetByte();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value
|
||||
/// but with stuff I don't understand
|
||||
/// </summary>
|
||||
/// <remarks>zero 15-nov-2015 - bypass LIAR LOGIC, see fdc9ea2aa922876d20ba897fb76909bf75fa6c92 https://github.com/TASVideos/BizHawk/issues/326 </remarks>
|
||||
public override int ValueNoFreeze => GetByte(true);
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the current value
|
||||
/// </summary>
|
||||
public override string ValueString => FormatValue(GetByte());
|
||||
|
||||
/// <summary>
|
||||
/// Get the previous value
|
||||
/// </summary>
|
||||
public override int Previous => _previous;
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the previous value
|
||||
/// </summary>
|
||||
public override string PreviousStr => FormatValue(_previous);
|
||||
|
||||
#endregion Implements
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common.NumberExtensions;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// This class holds a byte (8 bits) <see cref="Watch"/>
|
||||
/// </summary>
|
||||
public sealed class ByteWatch : Watch
|
||||
{
|
||||
private byte _previous;
|
||||
private byte _value;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ByteWatch"/> class.
|
||||
/// </summary>
|
||||
/// <param name="domain"><see cref="MemoryDomain"/> where you want to track</param>
|
||||
/// <param name="address">The address you want to track</param>
|
||||
/// <param name="type">How you you want to display the value See <see cref="DisplayType"/></param>
|
||||
/// <param name="bigEndian">Specify the endianess. true for big endian</param>
|
||||
/// <param name="note">A custom note about the <see cref="Watch"/></param>
|
||||
/// <param name="value">Current value</param>
|
||||
/// <param name="previous">Previous value</param>
|
||||
/// <param name="changeCount">How many times value has changed</param>
|
||||
/// <exception cref="ArgumentException">Occurs when a <see cref="DisplayType"/> is incompatible with <see cref="WatchSize.Byte"/></exception>
|
||||
internal ByteWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, byte value, byte previous, int changeCount)
|
||||
: base(domain, address, WatchSize.Byte, type, bigEndian, note)
|
||||
{
|
||||
_value = value == 0 ? GetByte() : value;
|
||||
_previous = previous;
|
||||
ChangeCount = changeCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enumeration of <see cref="DisplayType"/> that are valid for a <see cref="ByteWatch"/>
|
||||
/// </summary>
|
||||
public static IEnumerable<DisplayType> ValidTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return DisplayType.Unsigned;
|
||||
yield return DisplayType.Signed;
|
||||
yield return DisplayType.Hex;
|
||||
yield return DisplayType.Binary;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="ByteWatch"/>
|
||||
/// </summary>
|
||||
/// <returns>An enumeration that contains all valid <see cref="DisplayType"/></returns>
|
||||
public override IEnumerable<DisplayType> AvailableTypes()
|
||||
{
|
||||
return ValidTypes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the previous value; set it to the current one
|
||||
/// </summary>
|
||||
public override void ResetPrevious()
|
||||
{
|
||||
_previous = GetByte();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to sets the value into the <see cref="MemoryDomain"/>
|
||||
/// at the current <see cref="Watch"/> address
|
||||
/// </summary>
|
||||
/// <param name="value">Value to set</param>
|
||||
/// <returns>True if value successfully sets; otherwise, false</returns>
|
||||
public override bool Poke(string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte val = 0;
|
||||
switch (Type)
|
||||
{
|
||||
case DisplayType.Unsigned:
|
||||
if (value.IsUnsigned())
|
||||
{
|
||||
val = (byte)int.Parse(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case DisplayType.Signed:
|
||||
if (value.IsSigned())
|
||||
{
|
||||
val = (byte)(sbyte)int.Parse(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case DisplayType.Hex:
|
||||
if (value.IsHex())
|
||||
{
|
||||
val = (byte)int.Parse(value, NumberStyles.HexNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case DisplayType.Binary:
|
||||
if (value.IsBinary())
|
||||
{
|
||||
val = (byte)Convert.ToInt32(value, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (Global.CheatList.Contains(Domain, Address))
|
||||
{
|
||||
var cheat = Global.CheatList.FirstOrDefault(c => c.Address == Address && c.Domain == Domain);
|
||||
|
||||
if (cheat != (Cheat)null)
|
||||
{
|
||||
cheat.PokeValue(val);
|
||||
PokeByte(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PokeByte(val);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the Watch (read it from <see cref="MemoryDomain"/>
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
switch (Global.Config.RamWatchDefinePrevious)
|
||||
{
|
||||
case PreviousType.Original:
|
||||
return;
|
||||
case PreviousType.LastChange:
|
||||
var temp = _value;
|
||||
_value = GetByte();
|
||||
if (_value != temp)
|
||||
{
|
||||
_previous = _value;
|
||||
ChangeCount++;
|
||||
}
|
||||
|
||||
break;
|
||||
case PreviousType.LastFrame:
|
||||
_previous = _value;
|
||||
_value = GetByte();
|
||||
if (_value != Previous)
|
||||
{
|
||||
ChangeCount++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Implements IFormattable
|
||||
public string FormatValue(byte val)
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
default:
|
||||
case DisplayType.Unsigned:
|
||||
return val.ToString();
|
||||
case DisplayType.Signed:
|
||||
return ((sbyte)val).ToString();
|
||||
case DisplayType.Hex:
|
||||
return val.ToHexString(2);
|
||||
case DisplayType.Binary:
|
||||
return Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " ");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of difference
|
||||
/// between current value and the previous one
|
||||
/// </summary>
|
||||
public override string Diff
|
||||
{
|
||||
get
|
||||
{
|
||||
string diff = "";
|
||||
int diffVal = _value - _previous;
|
||||
if (diffVal > 0)
|
||||
{
|
||||
diff = "+";
|
||||
}
|
||||
else if (diffVal < 0)
|
||||
{
|
||||
diff = "-";
|
||||
}
|
||||
|
||||
return $"{diff}{FormatValue((byte)Math.Abs(diffVal))}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the maximum possible value
|
||||
/// </summary>
|
||||
public override uint MaxValue => byte.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Get the current value
|
||||
/// </summary>
|
||||
public override int Value => GetByte();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value
|
||||
/// but with stuff I don't understand
|
||||
/// </summary>
|
||||
/// <remarks>zero 15-nov-2015 - bypass LIAR LOGIC, see fdc9ea2aa922876d20ba897fb76909bf75fa6c92 https://github.com/TASVideos/BizHawk/issues/326 </remarks>
|
||||
public override int ValueNoFreeze => GetByte(true);
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the current value
|
||||
/// </summary>
|
||||
public override string ValueString => FormatValue(GetByte());
|
||||
|
||||
/// <summary>
|
||||
/// Get the previous value
|
||||
/// </summary>
|
||||
public override int Previous => _previous;
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the previous value
|
||||
/// </summary>
|
||||
public override string PreviousStr => FormatValue(_previous);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,19 +36,19 @@
|
|||
Binary,
|
||||
|
||||
/// <summary>
|
||||
/// Display the value as fractionnal number. 12 before coma and 4 after
|
||||
/// Display the value as fractional number. 12 before coma and 4 after
|
||||
/// Used only by <see cref="WordWatch"/> as it is 16 bits length
|
||||
/// </summary>
|
||||
FixedPoint_12_4,
|
||||
|
||||
/// <summary>
|
||||
/// Display the value as fractionnal number. 20 before coma and 12 after
|
||||
/// Display the value as fractional number. 20 before coma and 12 after
|
||||
/// Used only by <see cref="DWordWatch"/> as it is 32 bits length
|
||||
/// </summary>
|
||||
FixedPoint_20_12,
|
||||
|
||||
/// <summary>
|
||||
/// Display the value as fractionnal number. 16 before coma and 16 after
|
||||
/// Display the value as fractional number. 16 before coma and 16 after
|
||||
/// Used only by <see cref="DWordWatch"/> as it is 32 bits length
|
||||
/// </summary>
|
||||
FixedPoint_16_16,
|
||||
|
|
|
@ -14,17 +14,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public sealed class DWordWatch : Watch
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private uint _value;
|
||||
private uint _previous;
|
||||
|
||||
#endregion
|
||||
|
||||
#region cTor(s)
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new instance of <see cref="DWordWatch"/>
|
||||
/// Initializes a new instance of the <see cref="DWordWatch"/> class
|
||||
/// </summary>
|
||||
/// <param name="domain"><see cref="MemoryDomain"/> where you want to track</param>
|
||||
/// <param name="address">The address you want to track</param>
|
||||
|
@ -38,23 +32,11 @@ namespace BizHawk.Client.Common
|
|||
internal DWordWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, uint value, uint previous, int changeCount)
|
||||
: base(domain, address, WatchSize.DWord, type, bigEndian, note)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
_value = GetDWord();
|
||||
}
|
||||
else
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
_value = value == 0 ? GetDWord() : value;
|
||||
_previous = previous;
|
||||
_changecount = changeCount;
|
||||
ChangeCount = changeCount;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="DisplayType"/> for a <see cref="DWordWatch"/>
|
||||
/// </summary>
|
||||
|
@ -72,8 +54,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
#region Implements
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of <see cref="DisplayType"/> that can be used for a <see cref="DWordWatch"/>
|
||||
/// </summary>
|
||||
|
@ -173,9 +153,9 @@ namespace BizHawk.Client.Common
|
|||
break;
|
||||
}
|
||||
|
||||
if (Global.CheatList.Contains(Domain, _address))
|
||||
if (Global.CheatList.Contains(Domain, Address))
|
||||
{
|
||||
var cheat = Global.CheatList.FirstOrDefault(c => c.Address == _address && c.Domain == Domain);
|
||||
var cheat = Global.CheatList.FirstOrDefault(c => c.Address == Address && c.Domain == Domain);
|
||||
if (cheat != (Cheat)null)
|
||||
{
|
||||
cheat.PokeValue((int)val);
|
||||
|
@ -208,7 +188,7 @@ namespace BizHawk.Client.Common
|
|||
if (_value != temp)
|
||||
{
|
||||
_previous = _value;
|
||||
_changecount++;
|
||||
ChangeCount++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -217,15 +197,13 @@ namespace BizHawk.Client.Common
|
|||
_value = GetDWord();
|
||||
if (_value != Previous)
|
||||
{
|
||||
_changecount++;
|
||||
ChangeCount++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Implements
|
||||
|
||||
// TODO: Implements IFormattable
|
||||
public string FormatValue(uint val)
|
||||
{
|
||||
|
@ -245,17 +223,10 @@ namespace BizHawk.Client.Common
|
|||
case DisplayType.Float:
|
||||
var bytes = BitConverter.GetBytes(val);
|
||||
var _float = BitConverter.ToSingle(bytes, 0);
|
||||
////return string.Format("{0:0.######}", _float);
|
||||
return _float.ToString(); // adelikat: decided that we like sci notation instead of spooky rounding
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#region Implements
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of difference
|
||||
/// between current value and the previous one
|
||||
|
@ -292,9 +263,5 @@ namespace BizHawk.Client.Common
|
|||
/// Get a string representation of the previous value
|
||||
/// </summary>
|
||||
public override string PreviousStr => FormatValue(_previous);
|
||||
|
||||
#endregion Implements
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
|
|||
public sealed class SeparatorWatch : Watch
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize a new separator instance
|
||||
/// Initializes a new instance of the <see cref="SeparatorWatch"/> class.
|
||||
/// </summary>
|
||||
internal SeparatorWatch()
|
||||
: base(null, 0, WatchSize.Separator, DisplayType.Separator, true, "")
|
||||
|
@ -30,8 +30,6 @@ namespace BizHawk.Client.Common
|
|||
yield return DisplayType.Separator;
|
||||
}
|
||||
|
||||
#region Stuff to ignore
|
||||
|
||||
/// <summary>
|
||||
/// Ignore that stuff
|
||||
/// </summary>
|
||||
|
@ -98,7 +96,5 @@ namespace BizHawk.Client.Common
|
|||
public override void Update()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,27 +15,16 @@ namespace BizHawk.Client.Common
|
|||
/// This is an abstract class
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Note={Notes}, Value={ValueString}")]
|
||||
public abstract partial class Watch
|
||||
public abstract class Watch
|
||||
: IEquatable<Watch>,
|
||||
IEquatable<Cheat>,
|
||||
IComparable<Watch>
|
||||
{
|
||||
#region Fields
|
||||
|
||||
protected long _address;
|
||||
protected MemoryDomain _domain;
|
||||
protected DisplayType _type;
|
||||
protected WatchSize _size;
|
||||
protected bool _bigEndian;
|
||||
protected string _notes;
|
||||
protected int _changecount = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region cTor(s)
|
||||
private MemoryDomain _domain;
|
||||
private DisplayType _type;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a new instance of <see cref="Watch"/>
|
||||
/// Initializes a new instance of the <see cref="Watch"/> class
|
||||
/// </summary>
|
||||
/// <param name="domain"><see cref="MemoryDomain"/> where you want to track</param>
|
||||
/// <param name="address">The address you want to track</param>
|
||||
|
@ -49,20 +38,18 @@ namespace BizHawk.Client.Common
|
|||
if (IsDiplayTypeAvailable(type))
|
||||
{
|
||||
_domain = domain;
|
||||
_address = address;
|
||||
_size = size;
|
||||
Address = address;
|
||||
Size = size;
|
||||
_type = type;
|
||||
_bigEndian = bigEndian;
|
||||
_notes = note;
|
||||
BigEndian = bigEndian;
|
||||
Notes = note;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException(string.Format("DisplayType {0} is invalid for this type of Watch", type), nameof(type));
|
||||
throw new ArgumentException($"DisplayType {type} is invalid for this type of Watch", nameof(type));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Static
|
||||
|
@ -71,7 +58,7 @@ namespace BizHawk.Client.Common
|
|||
/// Generate sa <see cref="Watch"/> from a given string
|
||||
/// String is tab separate
|
||||
/// </summary>
|
||||
/// <param name="line">Entire string, tab seperated for each value Order is:
|
||||
/// <param name="line">Entire string, tab separated for each value Order is:
|
||||
/// <list type="number">
|
||||
/// <item>
|
||||
/// <term>0x00</term>
|
||||
|
@ -119,9 +106,9 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
WatchSize size = SizeFromChar(parts[1][0]);
|
||||
DisplayType type = DisplayTypeFromChar(parts[2][0]);
|
||||
bool bigEndian = parts[3] == "0" ? false : true;
|
||||
bool bigEndian = parts[3] != "0";
|
||||
MemoryDomain domain = domains[parts[4]];
|
||||
string notes = parts[5].Trim(new char[] { '\r', '\n' });
|
||||
string notes = parts[5].Trim('\r', '\n');
|
||||
|
||||
return GenerateWatch(
|
||||
domain,
|
||||
|
@ -131,10 +118,8 @@ namespace BizHawk.Client.Common
|
|||
bigEndian,
|
||||
notes);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -151,7 +136,7 @@ namespace BizHawk.Client.Common
|
|||
/// <param name="prev">Previous value</param>
|
||||
/// <param name="changeCount">Number of changes occurs in current <see cref="Watch"/></param>
|
||||
/// <returns>New <see cref="Watch"/> instance. True type is depending of size parameter</returns>
|
||||
public static Watch GenerateWatch(MemoryDomain domain, long address, WatchSize size, DisplayType type, bool bigEndian, string note, long value, long prev, int changeCount)
|
||||
public static Watch GenerateWatch(MemoryDomain domain, long address, WatchSize size, DisplayType type, bool bigEndian, string note = "", long value = 0, long prev = 0, int changeCount = 0)
|
||||
{
|
||||
switch (size)
|
||||
{
|
||||
|
@ -167,37 +152,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a new <see cref="Watch"/> instance
|
||||
/// Can be either <see cref="ByteWatch"/>, <see cref="WordWatch"/>, <see cref="DWordWatch"/> or <see cref="SeparatorWatch"/>
|
||||
/// </summary>
|
||||
/// <param name="domain">The <see cref="MemoryDomain"/> where you want to watch</param>
|
||||
/// <param name="address">The address into the <see cref="MemoryDomain"/></param>
|
||||
/// <param name="size">The size</param>
|
||||
/// <param name="type">How the watch will be displayed</param>
|
||||
/// <param name="bigEndian">Endianess (true for big endian)</param>
|
||||
/// <param name="note">A customp note about your watch</param>
|
||||
/// <returns>New <see cref="Watch"/> instance. True type is depending of size parameter</returns>
|
||||
public static Watch GenerateWatch(MemoryDomain domain, long address, WatchSize size, DisplayType type, bool bigEndian, string note)
|
||||
{
|
||||
return GenerateWatch(domain, address, size, type, bigEndian, note, 0, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a new <see cref="Watch"/> instance
|
||||
/// Can be either <see cref="ByteWatch"/>, <see cref="WordWatch"/>, <see cref="DWordWatch"/> or <see cref="SeparatorWatch"/>
|
||||
/// </summary>
|
||||
/// <param name="domain">The <see cref="MemoryDomain"/> where you want to watch</param>
|
||||
/// <param name="address">The address into the <see cref="MemoryDomain"/></param>
|
||||
/// <param name="size">The size</param>
|
||||
/// <param name="type">How the watch will be displayed</param>
|
||||
/// <param name="bigEndian">Endianess (true for big endian)</param>
|
||||
/// <returns>New <see cref="Watch"/> instance. True type is depending of size parameter</returns>
|
||||
public static Watch GenerateWatch(MemoryDomain domain, long address, WatchSize size, DisplayType type, bool bigEndian)
|
||||
{
|
||||
return GenerateWatch(domain, address, size, type, bigEndian, "", 0, 0, 0);
|
||||
}
|
||||
|
||||
#region Operators
|
||||
|
||||
/// <summary>
|
||||
|
@ -208,12 +162,12 @@ namespace BizHawk.Client.Common
|
|||
/// <returns>True if both watch are equals; otherwise, false</returns>
|
||||
public static bool operator ==(Watch a, Watch b)
|
||||
{
|
||||
if (object.ReferenceEquals(a, null) || object.ReferenceEquals(b, null))
|
||||
if (ReferenceEquals(a, null) || ReferenceEquals(b, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (object.ReferenceEquals(a, b))
|
||||
if (ReferenceEquals(a, b))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -229,16 +183,11 @@ namespace BizHawk.Client.Common
|
|||
/// <returns>True if they are equals; otherwise, false</returns>
|
||||
public static bool operator ==(Watch a, Cheat b)
|
||||
{
|
||||
if (object.ReferenceEquals(a, null) || object.ReferenceEquals(b, null))
|
||||
if (ReferenceEquals(a, null) || ReferenceEquals(b, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (object.ReferenceEquals(a, b))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return a.Equals(b);
|
||||
}
|
||||
|
||||
|
@ -321,7 +270,7 @@ namespace BizHawk.Client.Common
|
|||
/// <summary>
|
||||
/// Gets a list a <see cref="DisplayType"/> that can be used for this <see cref="Watch"/>
|
||||
/// </summary>
|
||||
/// <returns>An enumartion that contains all valid <see cref="DisplayType"/></returns>
|
||||
/// <returns>An enumeration that contains all valid <see cref="DisplayType"/></returns>
|
||||
public abstract IEnumerable<DisplayType> AvailableTypes();
|
||||
|
||||
/// <summary>
|
||||
|
@ -340,61 +289,61 @@ namespace BizHawk.Client.Common
|
|||
|
||||
protected byte GetByte(bool bypassFreeze = false)
|
||||
{
|
||||
if (!bypassFreeze && Global.CheatList.IsActive(_domain, _address))
|
||||
if (!bypassFreeze && Global.CheatList.IsActive(_domain, Address))
|
||||
{
|
||||
// LIAR logic
|
||||
return Global.CheatList.GetByteValue(_domain, _address) ?? 0;
|
||||
return Global.CheatList.GetByteValue(_domain, Address) ?? 0;
|
||||
}
|
||||
|
||||
if (_domain.Size == 0)
|
||||
{
|
||||
return _domain.PeekByte(_address);
|
||||
return _domain.PeekByte(Address);
|
||||
}
|
||||
|
||||
return _domain.PeekByte(_address % _domain.Size);
|
||||
return _domain.PeekByte(Address % _domain.Size);
|
||||
}
|
||||
|
||||
protected ushort GetWord(bool bypassFreeze = false)
|
||||
{
|
||||
if (!bypassFreeze && Global.CheatList.IsActive(_domain, _address))
|
||||
if (!bypassFreeze && Global.CheatList.IsActive(_domain, Address))
|
||||
{
|
||||
// LIAR logic
|
||||
return (ushort)(Global.CheatList.GetCheatValue(_domain, _address, WatchSize.Word) ?? 0);
|
||||
return (ushort)(Global.CheatList.GetCheatValue(_domain, Address, WatchSize.Word) ?? 0);
|
||||
}
|
||||
|
||||
if (_domain.Size == 0)
|
||||
{
|
||||
return _domain.PeekUshort(_address, _bigEndian);
|
||||
return _domain.PeekUshort(Address, BigEndian);
|
||||
}
|
||||
|
||||
return _domain.PeekUshort(_address % _domain.Size, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
|
||||
return _domain.PeekUshort(Address % _domain.Size, BigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
|
||||
}
|
||||
|
||||
protected uint GetDWord(bool bypassFreeze = false)
|
||||
{
|
||||
if (!bypassFreeze && Global.CheatList.IsActive(_domain, _address))
|
||||
if (!bypassFreeze && Global.CheatList.IsActive(_domain, Address))
|
||||
{
|
||||
// LIAR logic
|
||||
return (uint)(Global.CheatList.GetCheatValue(_domain, _address, WatchSize.DWord) ?? 0);
|
||||
return (uint)(Global.CheatList.GetCheatValue(_domain, Address, WatchSize.DWord) ?? 0);
|
||||
}
|
||||
|
||||
if (_domain.Size == 0)
|
||||
{
|
||||
return _domain.PeekUint(_address, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
|
||||
return _domain.PeekUint(Address, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
}
|
||||
|
||||
return _domain.PeekUint(_address % _domain.Size, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
|
||||
return _domain.PeekUint(Address % _domain.Size, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
}
|
||||
|
||||
protected void PokeByte(byte val)
|
||||
{
|
||||
if (_domain.Size == 0)
|
||||
{
|
||||
_domain.PokeByte(_address, val);
|
||||
_domain.PokeByte(Address, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
_domain.PokeByte(_address % _domain.Size, val);
|
||||
_domain.PokeByte(Address % _domain.Size, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,11 +351,11 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (_domain.Size == 0)
|
||||
{
|
||||
_domain.PokeUshort(_address, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
|
||||
_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 stil lisn't correct since it could be the last byte of the domain
|
||||
_domain.PokeUshort(Address % _domain.Size, val, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,11 +363,11 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (_domain.Size == 0)
|
||||
{
|
||||
_domain.PokeUint(_address, val, _bigEndian); // TODO: % size stil lisn't correct since it could be the last byte of the domain
|
||||
_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 stil lisn't correct since it could be the last byte of the domain
|
||||
_domain.PokeUint(Address % _domain.Size, val, BigEndian); // TODO: % size still isn't correct since it could be the last byte of the domain
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,45 +378,43 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public void ClearChangeCount()
|
||||
{
|
||||
_changecount = 0;
|
||||
}
|
||||
|
||||
ChangeCount = 0;
|
||||
}
|
||||
|
||||
#region IEquatable<Watch>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines if this <see cref="Watch"/> is equals to another
|
||||
/// </summary>
|
||||
/// <param name="obj">The <see cref="Watch"/> to compare</param>
|
||||
/// <param name="other">The <see cref="Watch"/> to compare</param>
|
||||
/// <returns>True if both object are equals; otherwise, false</returns>
|
||||
public bool Equals(Watch other)
|
||||
{
|
||||
if (object.ReferenceEquals(other, null))
|
||||
if (ReferenceEquals(other, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _domain == other._domain &&
|
||||
_address == other._address &&
|
||||
_size == other._size;
|
||||
}
|
||||
}
|
||||
|
||||
return _domain == other._domain &&
|
||||
Address == other.Address &&
|
||||
Size == other.Size;
|
||||
}
|
||||
|
||||
#endregion IEquatable<Watch>
|
||||
|
||||
|
||||
#region IEquatable<Cheat>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines if this <see cref="Watch"/> is equals to an instance of <see cref="Cheat"/>
|
||||
/// </summary>
|
||||
/// <param name="obj">The <see cref="Cheat"/> to compare</param>
|
||||
/// <param name="other">The <see cref="Cheat"/> to compare</param>
|
||||
/// <returns>True if both object are equals; otherwise, false</returns>
|
||||
public bool Equals(Cheat other)
|
||||
{
|
||||
return !object.ReferenceEquals(other, null) &&
|
||||
_domain == other.Domain &&
|
||||
_address == other.Address &&
|
||||
_size == other.Size;
|
||||
return !ReferenceEquals(other, null)
|
||||
&& _domain == other.Domain
|
||||
&& Address == other.Address
|
||||
&& Size == other.Size;
|
||||
}
|
||||
|
||||
#endregion IEquatable<Cheat>
|
||||
|
@ -475,7 +422,7 @@ namespace BizHawk.Client.Common
|
|||
#region IComparable<Watch>
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Watch"/> together and determine wich one comes first.
|
||||
/// Compares two <see cref="Watch"/> together and determine which one comes first.
|
||||
/// First we look the address and then the size
|
||||
/// </summary>
|
||||
/// <param name="other">The other <see cref="Watch"/> to compare to</param>
|
||||
|
@ -493,17 +440,12 @@ namespace BizHawk.Client.Common
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (object.ReferenceEquals(other, null))
|
||||
if (Address.Equals(other.Address))
|
||||
{
|
||||
return 1;
|
||||
return ((int)Size).CompareTo((int)other.Size);
|
||||
}
|
||||
|
||||
if (_address.Equals(other._address))
|
||||
{
|
||||
return ((int)_size).CompareTo((int)other._size);
|
||||
}
|
||||
|
||||
return _address.CompareTo(other._address);
|
||||
return Address.CompareTo(other.Address);
|
||||
}
|
||||
|
||||
#endregion IComparable<Watch>
|
||||
|
@ -534,7 +476,7 @@ namespace BizHawk.Client.Common
|
|||
/// <returns><see cref="int"/> that can serves as a unique representation of current Watch</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Domain.GetHashCode() + (int)(Address);
|
||||
return Domain.GetHashCode() + (int)Address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -542,7 +484,6 @@ namespace BizHawk.Client.Common
|
|||
/// used for the current <see cref="Watch"/>
|
||||
/// </summary>
|
||||
/// <param name="type"><see cref="DisplayType"/> you want to check</param>
|
||||
/// <returns></returns>
|
||||
public bool IsDiplayTypeAvailable(DisplayType type)
|
||||
{
|
||||
return AvailableTypes().Any(d => d == type);
|
||||
|
@ -554,7 +495,7 @@ namespace BizHawk.Client.Common
|
|||
/// <returns>A <see cref="string"/> representation of the current <see cref="Watch"/></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{(Domain == null && Address == 0 ? "0" : Address.ToHexString((Domain.Size - 1).NumHexDigits()))}\t{SizeAsChar}\t{TypeAsChar}\t{Convert.ToInt32(BigEndian)}\t{DomainName}\t{Notes.Trim('\r', '\n')}";
|
||||
return $"{(Domain == null && Address == 0 ? "0" : Address.ToHexString((Domain?.Size ?? 0xFF - 1).NumHexDigits()))}\t{SizeAsChar}\t{TypeAsChar}\t{Convert.ToInt32(BigEndian)}\t{Domain?.Name}\t{Notes.Trim('\r', '\n')}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -574,18 +515,18 @@ namespace BizHawk.Client.Common
|
|||
#region Abstracts
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of difference
|
||||
/// Gets a string representation of difference
|
||||
/// between current value and the previous one
|
||||
/// </summary>
|
||||
public abstract string Diff { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the maximum possible value
|
||||
/// Gets the maximum possible value
|
||||
/// </summary>
|
||||
public abstract uint MaxValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the current value
|
||||
/// Gets the current value
|
||||
/// </summary>
|
||||
public abstract int Value { get; }
|
||||
|
||||
|
@ -597,7 +538,7 @@ namespace BizHawk.Client.Common
|
|||
public abstract int ValueNoFreeze { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the current value
|
||||
/// Gets a string representation of the current value
|
||||
/// </summary>
|
||||
public abstract string ValueString { get; }
|
||||
|
||||
|
@ -606,16 +547,16 @@ namespace BizHawk.Client.Common
|
|||
/// at the current <see cref="Watch"/> address
|
||||
/// </summary>
|
||||
/// <param name="value">Value to set</param>
|
||||
/// <returns>True if value successfully sets; othewise, false</returns>
|
||||
/// <returns>True if value successfully sets; otherwise, false</returns>
|
||||
public abstract bool Poke(string value);
|
||||
|
||||
/// <summary>
|
||||
/// Get the previous value
|
||||
/// Gets the previous value
|
||||
/// </summary>
|
||||
public abstract int Previous { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the previous value
|
||||
/// Gets a string representation of the previous value
|
||||
/// </summary>
|
||||
public abstract string PreviousStr { get; }
|
||||
|
||||
|
@ -624,11 +565,8 @@ namespace BizHawk.Client.Common
|
|||
/// <summary>
|
||||
/// Gets the address in the <see cref="MemoryDomain"/>
|
||||
/// </summary>
|
||||
public long Address => _address;
|
||||
public long Address { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the format tha should be used by string.Format()
|
||||
/// </summary>
|
||||
private string AddressFormatStr
|
||||
{
|
||||
get
|
||||
|
@ -645,28 +583,18 @@ namespace BizHawk.Client.Common
|
|||
/// <summary>
|
||||
/// Gets the address in the <see cref="MemoryDomain"/> formatted as string
|
||||
/// </summary>
|
||||
public string AddressString => _address.ToString(AddressFormatStr);
|
||||
public string AddressString => Address.ToString(AddressFormatStr);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the endianess of current <see cref="Watch"/>
|
||||
/// Gets or sets a value indicating the endianess of current <see cref="Watch"/>
|
||||
/// True for big endian, flase for little endian
|
||||
/// </summary>
|
||||
public bool BigEndian
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bigEndian;
|
||||
}
|
||||
set
|
||||
{
|
||||
_bigEndian = value;
|
||||
}
|
||||
}
|
||||
public bool BigEndian { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of time tha value of current <see cref="Watch"/> has changed
|
||||
/// Gets or sets the number of times that value of current <see cref="Watch"/> value has changed
|
||||
/// </summary>
|
||||
public int ChangeCount => _changecount;
|
||||
public int ChangeCount { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the way current <see cref="Watch"/> is displayed
|
||||
|
@ -678,6 +606,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (IsDiplayTypeAvailable(value))
|
||||
|
@ -686,13 +615,13 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException(string.Format("DisplayType {0} is invalid for this type of Watch", value));
|
||||
throw new ArgumentException($"DisplayType {value} is invalid for this type of Watch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets current <see cref="MemoryDomain"/>
|
||||
/// Gets the current <see cref="MemoryDomain"/>
|
||||
/// </summary>
|
||||
public MemoryDomain Domain
|
||||
{
|
||||
|
@ -715,72 +644,25 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the domain name of the current <see cref="MemoryDomain"/>
|
||||
/// It's the same of doing myWatch.Domain.Name
|
||||
/// Gets a value indicating whether the current address is
|
||||
/// within in the range of current <see cref="MemoryDomain"/>
|
||||
/// </summary>
|
||||
public string DomainName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_domain != null)
|
||||
{
|
||||
return _domain.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value that defined if the current address is
|
||||
/// well in the range of current <see cref="MemoryDomain"/>
|
||||
/// </summary>
|
||||
public bool IsOutOfRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return !IsSeparator && (_domain.Size != 0 && _address >= _domain.Size);
|
||||
}
|
||||
}
|
||||
public bool IsOutOfRange => !IsSeparator && _domain.Size != 0 && Address >= _domain.Size;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value that defined if the current <see cref="Watch"/> is actually a <see cref="SeparatorWatch"/>
|
||||
/// </summary>
|
||||
public bool IsSeparator
|
||||
{
|
||||
get
|
||||
{
|
||||
return this is SeparatorWatch;
|
||||
}
|
||||
}
|
||||
public bool IsSeparator => this is SeparatorWatch;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets notes for current <see cref="Watch"/>
|
||||
/// </summary>
|
||||
public string Notes
|
||||
{
|
||||
get
|
||||
{
|
||||
return _notes;
|
||||
}
|
||||
set
|
||||
{
|
||||
_notes = value;
|
||||
}
|
||||
}
|
||||
public string Notes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current size of the watch
|
||||
/// </summary>
|
||||
public WatchSize Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
}
|
||||
public WatchSize Size { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -9,17 +9,16 @@ namespace BizHawk.Client.Common
|
|||
public sealed partial class WatchList
|
||||
{
|
||||
/// <summary>
|
||||
/// Netsed private class that define how to compare two <see cref="Watch"/>
|
||||
/// Nested private class that define how to compare two <see cref="Watch"/>
|
||||
/// based on their address
|
||||
/// </summary>
|
||||
private sealed class WatchAddressComparer
|
||||
: WatchEqualityComparer,
|
||||
IComparer<Watch>
|
||||
: WatchEqualityComparer, IComparer<Watch>
|
||||
{
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Watch"/> between them
|
||||
/// and determines wich one comes first.
|
||||
/// If they are equals, comapraison will done one the domain and next on size
|
||||
/// and determines which one comes first.
|
||||
/// If they are equals, comparison will done one the domain and next on size
|
||||
/// </summary>
|
||||
/// <param name="x">First <see cref="Watch"/></param>
|
||||
/// <param name="y">Second <see cref="Watch"/></param>
|
||||
|
@ -30,21 +29,18 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
else if (x.Address.Equals(y.Address))
|
||||
|
||||
if (x.Address.Equals(y.Address))
|
||||
{
|
||||
if (x.Domain.Name.Equals(y.Domain.Name))
|
||||
{
|
||||
return x.Size.CompareTo(y.Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.Domain.Name.CompareTo(y.Domain.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.Address.CompareTo(y.Address);
|
||||
|
||||
return x.Domain.Name.CompareTo(y.Domain.Name);
|
||||
}
|
||||
|
||||
return x.Address.CompareTo(y.Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
|
|||
public sealed partial class WatchList
|
||||
{
|
||||
/// <summary>
|
||||
/// Netsed private class that define how to compare two <see cref="Watch"/>
|
||||
/// Nested private class that define how to compare two <see cref="Watch"/>
|
||||
/// based on the number of changes
|
||||
/// </summary>
|
||||
private sealed class WatchChangeCountComparer
|
||||
|
|
|
@ -9,17 +9,16 @@ namespace BizHawk.Client.Common
|
|||
public sealed partial class WatchList
|
||||
{
|
||||
/// <summary>
|
||||
/// Netsed private class that define how to compare two <see cref="Watch"/>
|
||||
/// Nested private class that define how to compare two <see cref="Watch"/>
|
||||
/// based on their domain
|
||||
/// </summary>
|
||||
private sealed class WatchDomainComparer
|
||||
: WatchEqualityComparer,
|
||||
IComparer<Watch>
|
||||
: WatchEqualityComparer, IComparer<Watch>
|
||||
{
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Watch"/> between them
|
||||
/// and determines wich one comes first.
|
||||
/// If they are equals, comapraison will done one the address and next on size
|
||||
/// and determines which one comes first.
|
||||
/// If they are equals, comparison will done one the address and next on size
|
||||
/// </summary>
|
||||
/// <param name="x">First <see cref="Watch"/></param>
|
||||
/// <param name="y">Second <see cref="Watch"/></param>
|
||||
|
@ -30,21 +29,18 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
else if (x.Domain.Name.Equals(y.Domain.Name))
|
||||
|
||||
if (x.Domain.Name.Equals(y.Domain.Name))
|
||||
{
|
||||
if (x.Address.Equals(y.Address))
|
||||
{
|
||||
return x.Size.CompareTo(y.Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.Address.CompareTo(y.Address);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.Domain.Name.CompareTo(y.Domain.Name);
|
||||
|
||||
return x.Address.CompareTo(y.Address);
|
||||
}
|
||||
|
||||
return x.Domain.Name.CompareTo(y.Domain.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
|
|||
public sealed partial class WatchList
|
||||
{
|
||||
/// <summary>
|
||||
/// Netsed private class that define how to compare two <see cref="Watch"/>
|
||||
/// Nested private class that define how to compare two <see cref="Watch"/>
|
||||
/// based on their note
|
||||
/// </summary>
|
||||
private sealed class WatchNoteComparer
|
||||
|
@ -18,8 +18,8 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Watch"/> between them
|
||||
/// and determines wich one comes first.
|
||||
/// If they are equals, comapraison will done one the address and next on size
|
||||
/// and determines which one comes first.
|
||||
/// If they are equals, comparison will done one the address and next on size
|
||||
/// </summary>
|
||||
/// <param name="x">First <see cref="Watch"/></param>
|
||||
/// <param name="y">Second <see cref="Watch"/></param>
|
||||
|
|
|
@ -9,17 +9,16 @@ namespace BizHawk.Client.Common
|
|||
public sealed partial class WatchList
|
||||
{
|
||||
/// <summary>
|
||||
/// Netsed private class that define how to compare two <see cref="Watch"/>
|
||||
/// Nested private class that define how to compare two <see cref="Watch"/>
|
||||
/// based on their previous value
|
||||
/// </summary>
|
||||
private sealed class WatchPreviousValueComparer
|
||||
: WatchEqualityComparer,
|
||||
IComparer<Watch>
|
||||
: WatchEqualityComparer, IComparer<Watch>
|
||||
{
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Watch"/> between them
|
||||
/// and determines wich one comes first.
|
||||
/// If they are equals, comapraison will done one the address and next on size
|
||||
/// and determines which one comes first.
|
||||
/// If they are equals, comparison will done one the address and next on size
|
||||
/// </summary>
|
||||
/// <param name="x">First <see cref="Watch"/></param>
|
||||
/// <param name="y">Second <see cref="Watch"/></param>
|
||||
|
@ -30,21 +29,18 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
else if (x.Previous.Equals(y.Previous))
|
||||
|
||||
if (x.Previous.Equals(y.Previous))
|
||||
{
|
||||
if (x.Address.Equals(y.Address))
|
||||
{
|
||||
return x.Size.CompareTo(y.Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.Address.CompareTo(y.Address);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.Previous.CompareTo(y.Previous);
|
||||
|
||||
return x.Address.CompareTo(y.Address);
|
||||
}
|
||||
|
||||
return x.Previous.CompareTo(y.Previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace BizHawk.Client.Common
|
|||
public sealed partial class WatchList
|
||||
{
|
||||
/// <summary>
|
||||
/// Netsed private class that define how to compare two <see cref="Watch"/>
|
||||
/// Nested private class that define how to compare two <see cref="Watch"/>
|
||||
/// based on their values
|
||||
/// </summary>
|
||||
private sealed class WatchValueComparer
|
||||
|
@ -18,8 +18,8 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Watch"/> between them
|
||||
/// and determines wich one comes first.
|
||||
/// If they are equals, comapraison will done one the address and next on size
|
||||
/// and determines which one comes first.
|
||||
/// If they are equals, comparison will done one the address and next on size
|
||||
/// </summary>
|
||||
/// <param name="x">First <see cref="Watch"/></param>
|
||||
/// <param name="y">Second <see cref="Watch"/></param>
|
||||
|
|
|
@ -10,18 +10,21 @@
|
|||
/// Use this for <see cref="ByteWatch"/>
|
||||
/// </summary>
|
||||
Byte = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 2 bytes (16 bits)
|
||||
/// Use this for <see cref="WordWatch"/>
|
||||
/// </summary>
|
||||
Word = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 4 bytes (32 bits)
|
||||
/// Use this for <see cref="DWordWatch"/>
|
||||
/// </summary>
|
||||
DWord = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Special case used for a separator in ramwatch
|
||||
/// Special case used for a separator in ram tools
|
||||
/// Use this for <see cref="SeparatorWatch"/>
|
||||
/// </summary>
|
||||
Separator = 0
|
||||
|
|
|
@ -14,17 +14,11 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public sealed class WordWatch : Watch
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private ushort _previous;
|
||||
private ushort _value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region cTor(s)
|
||||
|
||||
/// <summary>
|
||||
/// Inialize a new instance of <see cref="WordWatch"/>
|
||||
/// Initializes a new instance of the <see cref="WordWatch"/> class
|
||||
/// </summary>
|
||||
/// <param name="domain"><see cref="MemoryDomain"/> where you want to track</param>
|
||||
/// <param name="address">The address you want to track</param>
|
||||
|
@ -38,24 +32,13 @@ namespace BizHawk.Client.Common
|
|||
internal WordWatch(MemoryDomain domain, long address, DisplayType type, bool bigEndian, string note, ushort value, ushort previous, int changeCount)
|
||||
: base(domain, address, WatchSize.Word, type, bigEndian, note)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
_value = GetWord();
|
||||
}
|
||||
else
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
_value = value == 0 ? GetWord() : value;
|
||||
_previous = previous;
|
||||
_changecount = changeCount;
|
||||
ChangeCount = changeCount;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Enumerate wich <see cref="DisplayType"/> are valid for a <see cref="WordWatch"/>
|
||||
/// Gets an Enumeration of <see cref="DisplayType"/>s that are valid for a <see cref="WordWatch"/>
|
||||
/// </summary>
|
||||
public static IEnumerable<DisplayType> ValidTypes
|
||||
{
|
||||
|
@ -69,12 +52,10 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
#region Implements
|
||||
|
||||
/// <summary>
|
||||
/// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="WordWatch"/>
|
||||
/// </summary>
|
||||
/// <returns>An enumartion that contains all valid <see cref="DisplayType"/></returns>
|
||||
/// <returns>An enumeration that contains all valid <see cref="DisplayType"/></returns>
|
||||
public override IEnumerable<DisplayType> AvailableTypes()
|
||||
{
|
||||
return ValidTypes;
|
||||
|
@ -93,7 +74,7 @@ namespace BizHawk.Client.Common
|
|||
/// at the current <see cref="Watch"/> address
|
||||
/// </summary>
|
||||
/// <param name="value">Value to set</param>
|
||||
/// <returns>True if value successfully sets; othewise, false</returns>
|
||||
/// <returns>True if value successfully sets; otherwise, false</returns>
|
||||
public override bool Poke(string value)
|
||||
{
|
||||
try
|
||||
|
@ -158,9 +139,9 @@ namespace BizHawk.Client.Common
|
|||
break;
|
||||
}
|
||||
|
||||
if (Global.CheatList.Contains(Domain, _address))
|
||||
if (Global.CheatList.Contains(Domain, Address))
|
||||
{
|
||||
var cheat = Global.CheatList.FirstOrDefault(c => c.Address == _address && c.Domain == Domain);
|
||||
var cheat = Global.CheatList.FirstOrDefault(c => c.Address == Address && c.Domain == Domain);
|
||||
if (cheat != (Cheat)null)
|
||||
{
|
||||
cheat.PokeValue(val);
|
||||
|
@ -194,7 +175,7 @@ namespace BizHawk.Client.Common
|
|||
if (_value != temp)
|
||||
{
|
||||
_previous = temp;
|
||||
_changecount++;
|
||||
ChangeCount++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -203,15 +184,13 @@ namespace BizHawk.Client.Common
|
|||
_value = GetWord();
|
||||
if (_value != Previous)
|
||||
{
|
||||
_changecount++;
|
||||
ChangeCount++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Implements
|
||||
|
||||
// TODO: Implements IFormattable
|
||||
public string FormatValue(ushort val)
|
||||
{
|
||||
|
@ -225,18 +204,12 @@ namespace BizHawk.Client.Common
|
|||
case DisplayType.Hex:
|
||||
return val.ToHexString(4);
|
||||
case DisplayType.FixedPoint_12_4:
|
||||
return string.Format("{0:F4}", val / 16.0);
|
||||
return $"{val / 16.0:F4}";
|
||||
case DisplayType.Binary:
|
||||
return Convert.ToString(val, 2).PadLeft(16, '0').Insert(8, " ").Insert(4, " ").Insert(14, " ");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#region Implements
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of difference
|
||||
/// between current value and the previous one
|
||||
|
@ -256,79 +229,39 @@ namespace BizHawk.Client.Common
|
|||
diff = "-";
|
||||
}
|
||||
|
||||
return string.Format("{0}{1}", diff, FormatValue((ushort)Math.Abs(diffVal)));
|
||||
return $"{diff}{FormatValue((ushort)Math.Abs(diffVal))}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the maximum possible value
|
||||
/// </summary>
|
||||
public override uint MaxValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return ushort.MaxValue;
|
||||
}
|
||||
}
|
||||
public override uint MaxValue => ushort.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value
|
||||
/// </summary>
|
||||
public override int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetWord();
|
||||
}
|
||||
}
|
||||
public override int Value => GetWord();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current value
|
||||
/// but with stuff I don't understand
|
||||
/// </summary>
|
||||
public override int ValueNoFreeze
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetWord(true);
|
||||
}
|
||||
}
|
||||
public override int ValueNoFreeze => GetWord(true);
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the current value
|
||||
/// </summary>
|
||||
public override string ValueString
|
||||
{
|
||||
get
|
||||
{
|
||||
return FormatValue(GetWord());
|
||||
}
|
||||
}
|
||||
public override string ValueString => FormatValue(GetWord());
|
||||
|
||||
/// <summary>
|
||||
/// Get the previous value
|
||||
/// </summary>
|
||||
public override int Previous
|
||||
{
|
||||
get
|
||||
{
|
||||
return _previous;
|
||||
}
|
||||
}
|
||||
public override int Previous => _previous;
|
||||
|
||||
/// <summary>
|
||||
/// Get a string representation of the previous value
|
||||
/// </summary>
|
||||
public override string PreviousStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return FormatValue(_previous);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Implements
|
||||
|
||||
#endregion
|
||||
public override string PreviousStr => FormatValue(_previous);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,15 @@
|
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLastIndexOfIsCultureSpecific_002E3/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1101/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1108/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1115/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1116/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1117/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1122/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1126/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1200/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1309/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1402/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1502/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1516/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1600/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1601/@EntryIndexedValue">DO_NOT_SHOW</s:String>
|
||||
|
|
Loading…
Reference in New Issue