misc cleanups in Client.Common
This commit is contained in:
parent
0ffac58ce8
commit
18762c75ee
|
@ -11,15 +11,15 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public Controller(ControllerDefinition definition)
|
||||
{
|
||||
_type = definition;
|
||||
for (int i = 0; i < _type.FloatControls.Count; i++)
|
||||
Definition = definition;
|
||||
for (int i = 0; i < Definition.FloatControls.Count; i++)
|
||||
{
|
||||
_floatButtons[_type.FloatControls[i]] = _type.FloatRanges[i].Mid;
|
||||
_floatRanges[_type.FloatControls[i]] = _type.FloatRanges[i];
|
||||
_floatButtons[Definition.FloatControls[i]] = Definition.FloatRanges[i].Mid;
|
||||
_floatRanges[Definition.FloatControls[i]] = Definition.FloatRanges[i];
|
||||
}
|
||||
}
|
||||
|
||||
public ControllerDefinition Definition => _type;
|
||||
public ControllerDefinition Definition { get; private set; }
|
||||
|
||||
public bool IsPressed(string button)
|
||||
{
|
||||
|
@ -37,10 +37,8 @@ namespace BizHawk.Client.Common
|
|||
private readonly Dictionary<string, ControllerDefinition.FloatRange> _floatRanges = new WorkingDictionary<string, ControllerDefinition.FloatRange>();
|
||||
private readonly Dictionary<string, AnalogBind> _floatBinds = new Dictionary<string, AnalogBind>();
|
||||
|
||||
private ControllerDefinition _type;
|
||||
|
||||
/// <summary>don't do this</summary>
|
||||
public void ForceType(ControllerDefinition newType) { _type = newType; }
|
||||
public void ForceType(ControllerDefinition newType) => Definition = newType;
|
||||
|
||||
public bool this[string button] => IsPressed(button);
|
||||
|
||||
|
@ -154,9 +152,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
public void ApplyAxisConstraints(string constraintClass)
|
||||
{
|
||||
_type.ApplyAxisConstraints(constraintClass, _floatButtons);
|
||||
}
|
||||
=> Definition.ApplyAxisConstraints(constraintClass, _floatButtons);
|
||||
|
||||
/// <summary>
|
||||
/// merges pressed logical buttons from the supplied controller, effectively ORing it with the current state
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace BizHawk.Client.Common
|
|||
var ipsHeader = new byte[5];
|
||||
patch.Read(ipsHeader, 0, 5);
|
||||
|
||||
string header = "PATCH";
|
||||
const string header = "PATCH";
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (ipsHeader[i] != header[i])
|
||||
|
@ -21,7 +21,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
// header verified, loop over patch entries
|
||||
uint eof = ('E' * 0x10000) + ('O' * 0x100) + 'F';
|
||||
const uint eof = ('E' * 0x10000) + ('O' * 0x100) + 'F';
|
||||
|
||||
var ret = new MemoryStream(rom.Length);
|
||||
ret.Write(rom, 0, rom.Length);
|
||||
|
|
|
@ -49,28 +49,15 @@ namespace BizHawk.Client.Common
|
|||
int idx = text.IndexOf('*');
|
||||
string type = text.Substring(0, idx);
|
||||
string token = text.Substring(idx + 1);
|
||||
IOpenAdvanced ioa;
|
||||
|
||||
if (type == OpenAdvancedTypes.OpenRom)
|
||||
var ioa = type switch
|
||||
{
|
||||
ioa = new OpenAdvanced_OpenRom();
|
||||
}
|
||||
else if (type == OpenAdvancedTypes.Libretro)
|
||||
{
|
||||
ioa = new OpenAdvanced_Libretro();
|
||||
}
|
||||
else if (type == OpenAdvancedTypes.LibretroNoGame)
|
||||
{
|
||||
ioa = new OpenAdvanced_LibretroNoGame();
|
||||
}
|
||||
else if (type == OpenAdvancedTypes.MAME)
|
||||
{
|
||||
ioa = new OpenAdvanced_MAME();
|
||||
}
|
||||
else
|
||||
{
|
||||
ioa = null;
|
||||
}
|
||||
OpenAdvancedTypes.OpenRom => (IOpenAdvanced)new OpenAdvanced_OpenRom(),
|
||||
OpenAdvancedTypes.Libretro => new OpenAdvanced_Libretro(),
|
||||
OpenAdvancedTypes.LibretroNoGame => new OpenAdvanced_LibretroNoGame(),
|
||||
OpenAdvancedTypes.MAME => new OpenAdvanced_MAME(),
|
||||
_ => null
|
||||
};
|
||||
|
||||
if (ioa == null)
|
||||
{
|
||||
|
@ -83,7 +70,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public static string Serialize(IOpenAdvanced ioa)
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
var sw = new StringWriter();
|
||||
sw.Write("{0}*", ioa.TypeName);
|
||||
ioa.Serialize(sw);
|
||||
return sw.ToString();
|
||||
|
|
|
@ -171,18 +171,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
// determine the number of parent directories in path and return result
|
||||
int x = path.HowMany('\\');
|
||||
if (x > 0)
|
||||
{
|
||||
return path.HowMany("..\\");
|
||||
}
|
||||
|
||||
return 0;
|
||||
return x > 0 ? path.HowMany("..\\") : 0;
|
||||
}
|
||||
|
||||
public static bool IsRecent(string path)
|
||||
{
|
||||
return path == "%recent%";
|
||||
}
|
||||
public static bool IsRecent(string path) => path == "%recent%";
|
||||
|
||||
public static string GetLuaPath()
|
||||
{
|
||||
|
|
|
@ -40,28 +40,10 @@ namespace BizHawk.Client.Common
|
|||
[JsonIgnore]
|
||||
public string MostRecent => recentlist.Any() ? recentlist[0] : "";
|
||||
|
||||
public string this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (recentlist.Any())
|
||||
{
|
||||
return recentlist[index];
|
||||
}
|
||||
public string this[int index] => recentlist.Any() ? recentlist[index] : "";
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
return recentlist.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
public IEnumerator<string> GetEnumerator() => recentlist.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace BizHawk.Client.Common.cheats
|
|||
code = code.Remove(0, 2);
|
||||
|
||||
var addrStr = code.Remove(0, 2);
|
||||
addrStr = addrStr + code.Remove(2, 2);
|
||||
addrStr += code.Remove(2, 2);
|
||||
|
||||
result.Value = int.Parse(valueStr, NumberStyles.HexNumber);
|
||||
result.Address = int.Parse(addrStr, NumberStyles.HexNumber);
|
||||
|
|
|
@ -19,35 +19,35 @@ namespace BizHawk.Client.Common.cheats
|
|||
}
|
||||
|
||||
var parseString = code.Remove(0, 2);
|
||||
switch (code.Length)
|
||||
return code.Length switch
|
||||
{
|
||||
case 9:
|
||||
// Sample Code of 1-Byte:
|
||||
// FFF761:64
|
||||
// Becomes:
|
||||
// Address: F761
|
||||
// Value: 64
|
||||
return new DecodeResult
|
||||
{
|
||||
Address = int.Parse(parseString.Remove(4, 3), NumberStyles.HexNumber),
|
||||
Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber),
|
||||
Size = WatchSize.Byte
|
||||
};
|
||||
case 11:
|
||||
// Sample Code of 2-Byte:
|
||||
// FFF761:6411
|
||||
// Becomes:
|
||||
// Address: F761
|
||||
// Value: 6411
|
||||
return new DecodeResult
|
||||
{
|
||||
Address = int.Parse(parseString.Remove(4, 5), NumberStyles.HexNumber),
|
||||
Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber),
|
||||
Size = WatchSize.Word
|
||||
};
|
||||
default:
|
||||
return new InvalidCheatCode("Action Replay/Pro Action Replay Codes need to be either 9 or 11 characters.");
|
||||
}
|
||||
9 =>
|
||||
// Sample Code of 1-Byte:
|
||||
// FFF761:64
|
||||
// Becomes:
|
||||
// Address: F761
|
||||
// Value: 64
|
||||
new DecodeResult
|
||||
{
|
||||
Address = int.Parse(parseString.Remove(4, 3), NumberStyles.HexNumber)
|
||||
, Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber)
|
||||
, Size = WatchSize.Byte
|
||||
},
|
||||
11 =>
|
||||
// Sample Code of 2-Byte:
|
||||
// FFF761:6411
|
||||
// Becomes:
|
||||
// Address: F761
|
||||
// Value: 6411
|
||||
new DecodeResult
|
||||
{
|
||||
Address = int.Parse(parseString.Remove(4, 5), NumberStyles.HexNumber)
|
||||
, Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber)
|
||||
, Size = WatchSize.Word
|
||||
},
|
||||
_ => new InvalidCheatCode(
|
||||
"Action Replay/Pro Action Replay Codes need to be either 9 or 11 characters.")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,12 +50,7 @@ namespace BizHawk.Client.Common
|
|||
throw new InvalidOperationException("Config Error", ex);
|
||||
}
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
|
||||
return config;
|
||||
return config ?? new T();
|
||||
}
|
||||
|
||||
public static void Save(string filepath, object config)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Linq;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
|
@ -29,47 +29,16 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
public float GetFloat(string name)
|
||||
{
|
||||
if (_floatOverrides.ContainsKey(name))
|
||||
{
|
||||
return _floatOverrides[name];
|
||||
}
|
||||
=> _floatOverrides.ContainsKey(name)
|
||||
? _floatOverrides[name]
|
||||
: 0.0F;
|
||||
|
||||
|
||||
return 0.0F;
|
||||
}
|
||||
public IEnumerable<string> Overrides => _overrides.Select(kvp => kvp.Key);
|
||||
|
||||
public IEnumerable<string> Overrides
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var kvp in _overrides)
|
||||
{
|
||||
yield return kvp.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IEnumerable<string> FloatOverrides => _floatOverrides.Select(kvp => kvp.Key);
|
||||
|
||||
public IEnumerable<string> FloatOverrides
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var kvp in _floatOverrides)
|
||||
{
|
||||
yield return kvp.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> InversedButtons
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var name in _inverses)
|
||||
{
|
||||
yield return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IEnumerable<string> InversedButtons => _inverses;
|
||||
|
||||
public void SetFloat(string name, float value)
|
||||
{
|
||||
|
|
|
@ -56,12 +56,7 @@ namespace BizHawk.Client.Common
|
|||
[LuaMethod("trim", "returns a string that trims whitespace on the left and right ends of the string")]
|
||||
public static string Trim(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return str.Trim();
|
||||
return string.IsNullOrEmpty(str) ? null : str.Trim();
|
||||
}
|
||||
|
||||
[LuaMethodExample("local stbizrep = bizstring.replace( \"Some string\", \"Some\", \"Replaced\" );")]
|
||||
|
|
|
@ -220,7 +220,7 @@ __Types and notation__
|
|||
}
|
||||
}
|
||||
|
||||
private string TypeCleanup(string str)
|
||||
private static string TypeCleanup(string str)
|
||||
{
|
||||
return str
|
||||
.Replace("System", "")
|
||||
|
|
|
@ -61,18 +61,18 @@
|
|||
|
||||
public void Toggle()
|
||||
{
|
||||
if (State == RunState.Paused)
|
||||
switch (State)
|
||||
{
|
||||
State = RunState.Running;
|
||||
}
|
||||
else if (State == RunState.Disabled)
|
||||
{
|
||||
State = RunState.Running;
|
||||
FrameWaiting = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State = RunState.Disabled;
|
||||
case RunState.Paused:
|
||||
State = RunState.Running;
|
||||
break;
|
||||
case RunState.Disabled:
|
||||
State = RunState.Running;
|
||||
FrameWaiting = false;
|
||||
break;
|
||||
default:
|
||||
State = RunState.Disabled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,22 +60,13 @@ namespace BizHawk.Client.Common
|
|||
|
||||
protected static Color? ToColor(object o)
|
||||
{
|
||||
if (o == null)
|
||||
return o switch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (o is double d)
|
||||
{
|
||||
return Color.FromArgb((int)(long)d);
|
||||
}
|
||||
|
||||
if (o is string s)
|
||||
{
|
||||
return Color.FromName(s);
|
||||
}
|
||||
|
||||
return null;
|
||||
double d => Color.FromArgb((int) (long) d),
|
||||
string s => Color.FromName(s),
|
||||
null => null,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
protected void Log(object message)
|
||||
|
|
|
@ -80,12 +80,7 @@ namespace BizHawk.Client.Common
|
|||
get
|
||||
{
|
||||
var key = systemId + (pal ? "_PAL" : "");
|
||||
if (Rates.ContainsKey(key))
|
||||
{
|
||||
return Rates[key];
|
||||
}
|
||||
|
||||
return 60.0;
|
||||
return Rates.ContainsKey(key) ? Rates[key] : 60.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
int index = 1;
|
||||
var sb = new StringBuilder();
|
||||
List<Subtitle> subs = new List<Subtitle>();
|
||||
var subs = new List<Subtitle>();
|
||||
foreach (var subtitle in this)
|
||||
{
|
||||
subs.Add(new Subtitle(subtitle));
|
||||
|
|
|
@ -50,16 +50,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public bool StartsFromSavestate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Header.ContainsKey(HeaderKeys.STARTSFROMSAVESTATE))
|
||||
{
|
||||
return bool.Parse(Header[HeaderKeys.STARTSFROMSAVESTATE]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
get => Header.ContainsKey(HeaderKeys.STARTSFROMSAVESTATE) && bool.Parse(Header[HeaderKeys.STARTSFROMSAVESTATE]);
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
|
@ -75,16 +66,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public bool StartsFromSaveRam
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Header.ContainsKey(HeaderKeys.STARTSFROMSAVERAM))
|
||||
{
|
||||
return bool.Parse(Header[HeaderKeys.STARTSFROMSAVERAM]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
get => Header.ContainsKey(HeaderKeys.STARTSFROMSAVERAM) && bool.Parse(Header[HeaderKeys.STARTSFROMSAVERAM]);
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
|
@ -106,16 +88,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public string GameName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Header.ContainsKey(HeaderKeys.GAMENAME))
|
||||
{
|
||||
return Header[HeaderKeys.GAMENAME];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
get => Header.ContainsKey(HeaderKeys.GAMENAME) ? Header[HeaderKeys.GAMENAME] : "";
|
||||
set
|
||||
{
|
||||
if (Header[HeaderKeys.GAMENAME] != value)
|
||||
|
@ -128,16 +101,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public string SystemID
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Header.ContainsKey(HeaderKeys.PLATFORM))
|
||||
{
|
||||
return Header[HeaderKeys.PLATFORM];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
get => Header.ContainsKey(HeaderKeys.PLATFORM) ? Header[HeaderKeys.PLATFORM] : "";
|
||||
set
|
||||
{
|
||||
if (Header[HeaderKeys.PLATFORM] != value)
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
var neshawkName = ((CoreAttribute)Attribute.GetCustomAttribute(typeof(NES), typeof(CoreAttribute))).CoreName;
|
||||
Result.Movie.HeaderEntries[HeaderKeys.CORE] = neshawkName;
|
||||
var emulator = "FCEUX";
|
||||
const string emulator = "FCEUX";
|
||||
var platform = "NES"; // TODO: FDS?
|
||||
|
||||
var syncSettings = new NES.NESSyncSettings();
|
||||
|
|
|
@ -342,14 +342,10 @@ namespace BizHawk.Client.Common.movie.import
|
|||
}
|
||||
|
||||
// LSNES frames don't start or end with a |.
|
||||
int start = 1;
|
||||
int end = sections.Length;
|
||||
int playerOffset = 0;
|
||||
|
||||
for (int section = start; section < end; section++)
|
||||
for (int player = 1; player < end; player++)
|
||||
{
|
||||
// The player number is one less than the section number for the reasons explained above.
|
||||
int player = section + playerOffset;
|
||||
string prefix = $"P{player} ";
|
||||
|
||||
// Gameboy doesn't currently have a prefix saying which player the input is for.
|
||||
|
@ -360,12 +356,12 @@ namespace BizHawk.Client.Common.movie.import
|
|||
|
||||
// Only count lines with that have the right number of buttons and are for valid players.
|
||||
if (
|
||||
sections[section].Length == buttons.Length)
|
||||
sections[player].Length == buttons.Length)
|
||||
{
|
||||
for (int button = 0; button < buttons.Length; button++)
|
||||
{
|
||||
// Consider the button pressed so long as its spot is not occupied by a ".".
|
||||
controllers[prefix + buttons[button]] = sections[section][button] != '.';
|
||||
controllers[prefix + buttons[button]] = sections[player][button] != '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,14 +155,12 @@ namespace BizHawk.Client.Common.movie.import
|
|||
Skip the first two sections of the split, which consist of everything before the starting | and the command.
|
||||
Do not use the section after the last |. In other words, get the sections for the players.
|
||||
*/
|
||||
int start = 2;
|
||||
int end = sections.Length - 1;
|
||||
int playerOffset = -1;
|
||||
|
||||
for (int section = start; section < end; section++)
|
||||
for (int section = 2; section < end; section++)
|
||||
{
|
||||
// The player number is one less than the section number for the reasons explained above.
|
||||
int player = section + playerOffset;
|
||||
int player = section - 1;
|
||||
string prefix = $"P{player} ";
|
||||
|
||||
// Only count lines with that have the right number of buttons and are for valid players.
|
||||
|
|
|
@ -45,17 +45,14 @@ namespace BizHawk.Client.Common
|
|||
.GetConstructor(new Type[] { })
|
||||
?.Invoke(new object[] { });
|
||||
|
||||
if (importer == null)
|
||||
{
|
||||
return ImportResult.Error($"No importer found for file type {ext}");
|
||||
}
|
||||
|
||||
return importer.Import(path);
|
||||
return importer == null
|
||||
? ImportResult.Error($"No importer found for file type {ext}")
|
||||
: importer.Import(path);
|
||||
}
|
||||
|
||||
private static Type ImporterForExtension(string ext)
|
||||
{
|
||||
return Importers.FirstOrDefault(i => string.Equals(i.Value.Extension, ext, StringComparison.OrdinalIgnoreCase)).Key;
|
||||
return Importers.First(i => string.Equals(i.Value.Extension, ext, StringComparison.OrdinalIgnoreCase)).Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,22 +34,13 @@ namespace BizHawk.Client.Common.movie.import
|
|||
|
||||
// 004 4-byte little-endian unsigned int: version number
|
||||
uint versionNumber = r.ReadUInt32();
|
||||
string version;
|
||||
switch (versionNumber)
|
||||
var version = versionNumber switch
|
||||
{
|
||||
case 1:
|
||||
version = "1.43";
|
||||
break;
|
||||
case 4:
|
||||
version = "1.51";
|
||||
break;
|
||||
case 5:
|
||||
version = "1.52";
|
||||
break;
|
||||
default:
|
||||
version = "Unknown";
|
||||
break;
|
||||
}
|
||||
1 => "1.43",
|
||||
4 => "1.51",
|
||||
5 => "1.52",
|
||||
_ => "Unknown"
|
||||
};
|
||||
|
||||
Result.Movie.Comments.Add($"{EmulationOrigin} Snes9x version {version}");
|
||||
Result.Movie.Comments.Add($"{MovieOrigin} .SMV");
|
||||
|
|
|
@ -28,83 +28,53 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public void SetControllersAsMnemonic(string mnemonic)
|
||||
{
|
||||
if (ControlType == "Null Controller")
|
||||
switch (ControlType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "Lynx Controller")
|
||||
{
|
||||
SetLynxControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "SNES Controller")
|
||||
{
|
||||
SetSNESControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "Commodore 64 Controller")
|
||||
{
|
||||
SetC64ControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "GBA Controller")
|
||||
{
|
||||
SetGBAControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "Atari 7800 ProLine Joystick Controller")
|
||||
{
|
||||
SetAtari7800AsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "Dual Gameboy Controller")
|
||||
{
|
||||
SetDualGameBoyControllerAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "WonderSwan Controller")
|
||||
{
|
||||
SetWonderSwanControllerAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "Nintendo 64 Controller")
|
||||
{
|
||||
SetN64ControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "Saturn Controller")
|
||||
{
|
||||
SetSaturnControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "PSP Controller")
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
|
||||
if (ControlType == "GPGX Genesis Controller")
|
||||
{
|
||||
if (IsGenesis6Button())
|
||||
case "Null Controller":
|
||||
return;
|
||||
case "Lynx Controller":
|
||||
SetLynxControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "SNES Controller":
|
||||
SetSNESControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "Commodore 64 Controller":
|
||||
SetC64ControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "GBA Controller":
|
||||
SetGBAControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "Atari 7800 ProLine Joystick Controller":
|
||||
SetAtari7800AsMnemonic(mnemonic);
|
||||
return;
|
||||
case "Dual Gameboy Controller":
|
||||
SetDualGameBoyControllerAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "WonderSwan Controller":
|
||||
SetWonderSwanControllerAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "Nintendo 64 Controller":
|
||||
SetN64ControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "Saturn Controller":
|
||||
SetSaturnControllersAsMnemonic(mnemonic);
|
||||
return;
|
||||
case "PSP Controller":
|
||||
// TODO
|
||||
return;
|
||||
case "GPGX Genesis Controller":
|
||||
{
|
||||
SetGenesis6ControllersAsMnemonic(mnemonic);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetGenesis3ControllersAsMnemonic(mnemonic);
|
||||
}
|
||||
if (IsGenesis6Button())
|
||||
{
|
||||
SetGenesis6ControllersAsMnemonic(mnemonic);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetGenesis3ControllersAsMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var c = new MnemonicChecker(mnemonic);
|
||||
|
@ -118,41 +88,42 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
return;
|
||||
}
|
||||
else if (mnemonic[1] == 'P')
|
||||
|
||||
switch (mnemonic[1])
|
||||
{
|
||||
Force("Power", true);
|
||||
}
|
||||
else if (mnemonic[1] == 'E')
|
||||
{
|
||||
Force("FDS Eject", true);
|
||||
}
|
||||
else if (mnemonic[1] == '0')
|
||||
{
|
||||
Force("FDS Insert 0", true);
|
||||
}
|
||||
else if (mnemonic[1] == '1')
|
||||
{
|
||||
Force("FDS Insert 1", true);
|
||||
}
|
||||
else if (mnemonic[1] == '2')
|
||||
{
|
||||
Force("FDS Insert 2", true);
|
||||
}
|
||||
else if (mnemonic[1] == '3')
|
||||
{
|
||||
Force("FDS Insert 3", true);
|
||||
}
|
||||
else if (mnemonic[1] == 'c')
|
||||
{
|
||||
Force("VS Coin 1", true);
|
||||
}
|
||||
else if (mnemonic[1] == 'C')
|
||||
{
|
||||
Force("VS Coin 2", true);
|
||||
}
|
||||
else if (mnemonic[1] != '.')
|
||||
{
|
||||
Force("Reset", true);
|
||||
case 'P':
|
||||
Force("Power", true);
|
||||
break;
|
||||
case 'E':
|
||||
Force("FDS Eject", true);
|
||||
break;
|
||||
case '0':
|
||||
Force("FDS Insert 0", true);
|
||||
break;
|
||||
case '1':
|
||||
Force("FDS Insert 1", true);
|
||||
break;
|
||||
case '2':
|
||||
Force("FDS Insert 2", true);
|
||||
break;
|
||||
case '3':
|
||||
Force("FDS Insert 3", true);
|
||||
break;
|
||||
case 'c':
|
||||
Force("VS Coin 1", true);
|
||||
break;
|
||||
case 'C':
|
||||
Force("VS Coin 2", true);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (mnemonic[1] != '.')
|
||||
{
|
||||
Force("Reset", true);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,9 +166,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int ctr = start;
|
||||
if (mnemonic.Length < srcindex + ctr + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
if (mnemonic.Length < srcIndex + ctr + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -210,17 +181,17 @@ namespace BizHawk.Client.Common
|
|||
|
||||
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
|
||||
{
|
||||
Force(prefix + button, c[srcindex + ctr++]);
|
||||
Force(prefix + button, c[srcIndex + ctr++]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ControlType == "SMS Controller")
|
||||
{
|
||||
int srcindex = BkmMnemonicConstants.Players[ControlType] * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = BkmMnemonicConstants.Players[ControlType] * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int ctr = start;
|
||||
foreach (var command in BkmMnemonicConstants.Commands[ControlType].Keys)
|
||||
{
|
||||
Force(command, c[srcindex + ctr++]);
|
||||
Force(command, c[srcIndex + ctr++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,10 +199,7 @@ namespace BizHawk.Client.Common
|
|||
private readonly WorkingDictionary<string, bool> _myBoolButtons = new WorkingDictionary<string, bool>();
|
||||
private readonly WorkingDictionary<string, float> _myFloatControls = new WorkingDictionary<string, float>();
|
||||
|
||||
private bool IsGenesis6Button()
|
||||
{
|
||||
return Definition.BoolButtons.Contains("P1 X");
|
||||
}
|
||||
private bool IsGenesis6Button() => Definition.BoolButtons.Contains("P1 X");
|
||||
|
||||
private void Force(string button, bool state)
|
||||
{
|
||||
|
@ -247,7 +215,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
private void SetGBAControllersAsMnemonic(string mnemonic)
|
||||
{
|
||||
MnemonicChecker c = new MnemonicChecker(mnemonic);
|
||||
var c = new MnemonicChecker(mnemonic);
|
||||
_myBoolButtons.Clear();
|
||||
if (mnemonic.Length < 2)
|
||||
{
|
||||
|
@ -268,7 +236,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
private void SetGenesis6ControllersAsMnemonic(string mnemonic)
|
||||
{
|
||||
MnemonicChecker c = new MnemonicChecker(mnemonic);
|
||||
var c = new MnemonicChecker(mnemonic);
|
||||
_myBoolButtons.Clear();
|
||||
|
||||
if (mnemonic.Length < 2)
|
||||
|
@ -292,9 +260,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
|
||||
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
if (mnemonic.Length < srcIndex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -302,14 +270,14 @@ namespace BizHawk.Client.Common
|
|||
int start = 3;
|
||||
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
|
||||
{
|
||||
Force($"P{player} {button}", c[srcindex + start++]);
|
||||
Force($"P{player} {button}", c[srcIndex + start++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetGenesis3ControllersAsMnemonic(string mnemonic)
|
||||
{
|
||||
MnemonicChecker c = new MnemonicChecker(mnemonic);
|
||||
var c = new MnemonicChecker(mnemonic);
|
||||
_myBoolButtons.Clear();
|
||||
|
||||
if (mnemonic.Length < 2)
|
||||
|
@ -333,9 +301,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Count + 1);
|
||||
|
||||
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Count - 1)
|
||||
if (mnemonic.Length < srcIndex + 3 + BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Count - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -343,7 +311,7 @@ namespace BizHawk.Client.Common
|
|||
int start = 3;
|
||||
foreach (string button in BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Keys)
|
||||
{
|
||||
Force($"P{player} {button}", c[srcindex + start++]);
|
||||
Force($"P{player} {button}", c[srcIndex + start++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -369,9 +337,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
|
||||
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
if (mnemonic.Length < srcIndex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -379,7 +347,7 @@ namespace BizHawk.Client.Common
|
|||
int start = 3;
|
||||
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys)
|
||||
{
|
||||
Force($"P{player} {button}", c[srcindex + start++]);
|
||||
Force($"P{player} {button}", c[srcIndex + start++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -401,9 +369,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
|
||||
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
if (mnemonic.Length < srcIndex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -411,14 +379,14 @@ namespace BizHawk.Client.Common
|
|||
int start = 3;
|
||||
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys)
|
||||
{
|
||||
Force(button, c[srcindex + start++]);
|
||||
Force(button, c[srcIndex + start++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetN64ControllersAsMnemonic(string mnemonic)
|
||||
{
|
||||
MnemonicChecker c = new MnemonicChecker(mnemonic);
|
||||
var c = new MnemonicChecker(mnemonic);
|
||||
_myBoolButtons.Clear();
|
||||
|
||||
if (mnemonic.Length < 2)
|
||||
|
@ -460,7 +428,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
private void SetSaturnControllersAsMnemonic(string mnemonic)
|
||||
{
|
||||
MnemonicChecker c = new MnemonicChecker(mnemonic);
|
||||
var c = new MnemonicChecker(mnemonic);
|
||||
_myBoolButtons.Clear();
|
||||
|
||||
if (mnemonic.Length < 2)
|
||||
|
@ -479,9 +447,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
|
||||
if (mnemonic.Length < srcindex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
if (mnemonic.Length < srcIndex + 3 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -489,14 +457,14 @@ namespace BizHawk.Client.Common
|
|||
int start = 3;
|
||||
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
|
||||
{
|
||||
Force($"P{player} {button}", c[srcindex + start++]);
|
||||
Force($"P{player} {button}", c[srcIndex + start++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAtari7800AsMnemonic(string mnemonic)
|
||||
{
|
||||
MnemonicChecker c = new MnemonicChecker(mnemonic);
|
||||
var c = new MnemonicChecker(mnemonic);
|
||||
_myBoolButtons.Clear();
|
||||
|
||||
if (mnemonic.Length < 5)
|
||||
|
@ -526,16 +494,16 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int start = 6;
|
||||
if (mnemonic.Length < srcindex + start + BkmMnemonicConstants.Buttons[ControlType].Count)
|
||||
if (mnemonic.Length < srcIndex + start + BkmMnemonicConstants.Buttons[ControlType].Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
|
||||
{
|
||||
Force($"P{player} {button}", c[srcindex + start++]);
|
||||
Force($"P{player} {button}", c[srcIndex + start++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -575,9 +543,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++)
|
||||
{
|
||||
int srcindex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
int srcIndex = (player - 1) * (BkmMnemonicConstants.Buttons[ControlType].Count + 1);
|
||||
|
||||
if (mnemonic.Length < srcindex + 1 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
if (mnemonic.Length < srcIndex + 1 + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -585,14 +553,14 @@ namespace BizHawk.Client.Common
|
|||
int start = 1;
|
||||
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys)
|
||||
{
|
||||
Force($"P{player} {button}", c[srcindex + start++]);
|
||||
Force($"P{player} {button}", c[srcIndex + start++]);
|
||||
}
|
||||
}
|
||||
|
||||
int startk = 13;
|
||||
int startKey = 13;
|
||||
foreach (string button in BkmMnemonicConstants.Buttons["Commodore 64 Keyboard"].Keys)
|
||||
{
|
||||
Force(button, c[startk++]);
|
||||
Force(button, c[startKey++]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,16 +22,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public string SavestateBinaryBase64Blob
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ContainsKey(HeaderKeys.SAVESTATEBINARYBASE64BLOB))
|
||||
{
|
||||
return this[HeaderKeys.SAVESTATEBINARYBASE64BLOB];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
get => ContainsKey(HeaderKeys.SAVESTATEBINARYBASE64BLOB)
|
||||
? this[HeaderKeys.SAVESTATEBINARYBASE64BLOB]
|
||||
: null;
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
|
@ -48,7 +41,6 @@ namespace BizHawk.Client.Common
|
|||
public new string this[string key]
|
||||
{
|
||||
get => ContainsKey(key) ? base[key] : "";
|
||||
|
||||
set
|
||||
{
|
||||
if (ContainsKey(key))
|
||||
|
|
|
@ -31,12 +31,7 @@ namespace BizHawk.Client.Common
|
|||
return double.PositiveInfinity;
|
||||
}
|
||||
|
||||
if (Loaded)
|
||||
{
|
||||
return _log.Count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return Loaded ? _log.Count : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -395,12 +395,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public Guid BranchGuidByIndex(int index)
|
||||
{
|
||||
if (index >= Branches.Count)
|
||||
{
|
||||
return Guid.Empty;
|
||||
}
|
||||
|
||||
return Branches[index].UniqueIdentifier;
|
||||
return index >= Branches.Count
|
||||
? Guid.Empty
|
||||
: Branches[index].UniqueIdentifier;
|
||||
}
|
||||
|
||||
public int BranchIndexByHash(Guid uuid)
|
||||
|
|
|
@ -44,17 +44,12 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return obj switch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj is TasMovieMarker marker)
|
||||
{
|
||||
return Frame == marker.Frame;
|
||||
}
|
||||
|
||||
return false;
|
||||
null => false,
|
||||
TasMovieMarker marker => Frame == marker.Frame,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
public static bool operator ==(TasMovieMarker marker, int frame)
|
||||
|
|
|
@ -87,24 +87,15 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public string AddressStr => _watch.AddressString;
|
||||
|
||||
public string ValueStr
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (_watch.Size)
|
||||
public string ValueStr =>
|
||||
_watch.Size switch
|
||||
{
|
||||
default:
|
||||
case WatchSize.Separator:
|
||||
return "";
|
||||
case WatchSize.Byte:
|
||||
return (_watch as ByteWatch).FormatValue((byte)_val);
|
||||
case WatchSize.Word:
|
||||
return (_watch as WordWatch).FormatValue((ushort)_val);
|
||||
case WatchSize.DWord:
|
||||
return (_watch as DWordWatch).FormatValue((uint)_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
WatchSize.Byte => ((ByteWatch) _watch).FormatValue((byte)_val),
|
||||
WatchSize.Word => ((WordWatch) _watch).FormatValue((ushort)_val),
|
||||
WatchSize.DWord => ((DWordWatch) _watch).FormatValue((uint)_val),
|
||||
WatchSize.Separator => "",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
public string CompareStr
|
||||
{
|
||||
|
@ -112,25 +103,21 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (_compare.HasValue)
|
||||
{
|
||||
switch (_watch.Size)
|
||||
return _watch.Size switch
|
||||
{
|
||||
default:
|
||||
case WatchSize.Separator:
|
||||
return "";
|
||||
case WatchSize.Byte:
|
||||
return (_watch as ByteWatch).FormatValue((byte)_compare.Value);
|
||||
case WatchSize.Word:
|
||||
return (_watch as WordWatch).FormatValue((ushort)_compare.Value);
|
||||
case WatchSize.DWord:
|
||||
return (_watch as DWordWatch).FormatValue((uint)_compare.Value);
|
||||
}
|
||||
WatchSize.Byte => ((ByteWatch) _watch).FormatValue((byte)_compare.Value),
|
||||
WatchSize.Word => ((WordWatch) _watch).FormatValue((ushort)_compare.Value),
|
||||
WatchSize.DWord => ((DWordWatch) _watch).FormatValue((uint)_compare.Value),
|
||||
WatchSize.Separator => "",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public CompareType ComparisonType { get; private set; }
|
||||
public CompareType ComparisonType { get; }
|
||||
|
||||
public void Enable(bool handleChange = true)
|
||||
{
|
||||
|
@ -170,15 +157,10 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
private string GetStringForPulse(int val)
|
||||
{
|
||||
if (_watch.Type == DisplayType.Hex)
|
||||
{
|
||||
return val.ToString("X8");
|
||||
}
|
||||
|
||||
return val.ToString();
|
||||
}
|
||||
private string GetStringForPulse(int val) =>
|
||||
_watch.Type == DisplayType.Hex
|
||||
? val.ToString("X8")
|
||||
: val.ToString();
|
||||
|
||||
public void Pulse()
|
||||
{
|
||||
|
@ -239,13 +221,13 @@ namespace BizHawk.Client.Common
|
|||
switch (_watch.Size)
|
||||
{
|
||||
case WatchSize.Byte:
|
||||
_watch.Poke((_watch as ByteWatch).FormatValue((byte)_val));
|
||||
_watch.Poke(((ByteWatch)_watch).FormatValue((byte)_val));
|
||||
break;
|
||||
case WatchSize.Word:
|
||||
_watch.Poke((_watch as WordWatch).FormatValue((ushort)_val));
|
||||
_watch.Poke(((WordWatch)_watch).FormatValue((ushort)_val));
|
||||
break;
|
||||
case WatchSize.DWord:
|
||||
_watch.Poke((_watch as DWordWatch).FormatValue((uint)_val));
|
||||
_watch.Poke(((DWordWatch)_watch).FormatValue((uint)_val));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +363,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void SetType(DisplayType type)
|
||||
{
|
||||
if (_watch.IsDiplayTypeAvailable(type))
|
||||
if (_watch.IsDisplayTypeAvailable(type))
|
||||
{
|
||||
_watch.Type = type;
|
||||
Changes();
|
||||
|
|
|
@ -80,13 +80,7 @@ namespace BizHawk.Client.Common
|
|||
public bool AttemptToLoadCheatFile()
|
||||
{
|
||||
var file = new FileInfo(_defaultFileName);
|
||||
|
||||
if (file.Exists)
|
||||
{
|
||||
return Load(file.FullName, false);
|
||||
}
|
||||
|
||||
return false;
|
||||
return file.Exists && Load(file.FullName, false);
|
||||
}
|
||||
|
||||
public void NewList(string defaultFileName, bool autosave = false)
|
||||
|
@ -297,12 +291,9 @@ namespace BizHawk.Client.Common
|
|||
case WatchSize.Byte:
|
||||
return activeCheat.Value;
|
||||
case WatchSize.Word:
|
||||
if (size == WatchSize.Byte)
|
||||
{
|
||||
return GetByteValue(domain, addr);
|
||||
}
|
||||
|
||||
return activeCheat.Value;
|
||||
return size == WatchSize.Byte
|
||||
? GetByteValue(domain, addr)
|
||||
: activeCheat.Value;
|
||||
case WatchSize.DWord:
|
||||
if (size == WatchSize.Byte)
|
||||
{
|
||||
|
|
|
@ -162,25 +162,15 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
int before = _watchList.Count;
|
||||
|
||||
switch (_compareTo)
|
||||
_watchList = _compareTo switch
|
||||
{
|
||||
default:
|
||||
case Compare.Previous:
|
||||
_watchList = ComparePrevious(_watchList).ToList();
|
||||
break;
|
||||
case Compare.SpecificValue:
|
||||
_watchList = CompareSpecificValue(_watchList).ToList();
|
||||
break;
|
||||
case Compare.SpecificAddress:
|
||||
_watchList = CompareSpecificAddress(_watchList).ToList();
|
||||
break;
|
||||
case Compare.Changes:
|
||||
_watchList = CompareChanges(_watchList).ToList();
|
||||
break;
|
||||
case Compare.Difference:
|
||||
_watchList = CompareDifference(_watchList).ToList();
|
||||
break;
|
||||
}
|
||||
Compare.Previous => ComparePrevious(_watchList).ToList(),
|
||||
Compare.SpecificValue => CompareSpecificValue(_watchList).ToList(),
|
||||
Compare.SpecificAddress => CompareSpecificAddress(_watchList).ToList(),
|
||||
Compare.Changes => CompareChanges(_watchList).ToList(),
|
||||
Compare.Difference => CompareDifference(_watchList).ToList(),
|
||||
_ => ComparePrevious(_watchList).ToList()
|
||||
};
|
||||
|
||||
if (_settings.PreviousType == PreviousType.LastSearch)
|
||||
{
|
||||
|
@ -201,20 +191,15 @@ namespace BizHawk.Client.Common
|
|||
? _watchList.BinarySearch(w => w.Address, address)
|
||||
: _watchList.FirstOrDefault(w => w.Address == address), 1);
|
||||
|
||||
switch (_compareTo)
|
||||
return _compareTo switch
|
||||
{
|
||||
default:
|
||||
case Compare.Previous:
|
||||
return !ComparePrevious(listOfOne).Any();
|
||||
case Compare.SpecificValue:
|
||||
return !CompareSpecificValue(listOfOne).Any();
|
||||
case Compare.SpecificAddress:
|
||||
return !CompareSpecificAddress(listOfOne).Any();
|
||||
case Compare.Changes:
|
||||
return !CompareChanges(listOfOne).Any();
|
||||
case Compare.Difference:
|
||||
return !CompareDifference(listOfOne).Any();
|
||||
}
|
||||
Compare.Previous => !ComparePrevious(listOfOne).Any(),
|
||||
Compare.SpecificValue => !CompareSpecificValue(listOfOne).Any(),
|
||||
Compare.SpecificAddress => !CompareSpecificAddress(listOfOne).Any(),
|
||||
Compare.Changes => !CompareChanges(listOfOne).Any(),
|
||||
Compare.Difference => !CompareDifference(listOfOne).Any(),
|
||||
_ => !ComparePrevious(listOfOne).Any()
|
||||
};
|
||||
}
|
||||
|
||||
public int Count => _watchList.Count;
|
||||
|
@ -497,48 +482,28 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
default:
|
||||
case ComparisonOperator.Equal:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(w.Previous));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(w.Previous));
|
||||
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(w.Previous))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(w.Previous));
|
||||
case ComparisonOperator.NotEqual:
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) != SignExtendAsNeeded(w.Previous));
|
||||
|
||||
case ComparisonOperator.GreaterThan:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(w.Previous));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > SignExtendAsNeeded(w.Previous));
|
||||
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(w.Previous))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > SignExtendAsNeeded(w.Previous));
|
||||
case ComparisonOperator.GreaterThanEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(w.Previous));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= SignExtendAsNeeded(w.Previous));
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(w.Previous))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= SignExtendAsNeeded(w.Previous));
|
||||
|
||||
case ComparisonOperator.LessThan:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(w.Previous));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < SignExtendAsNeeded(w.Previous));
|
||||
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(w.Previous))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < SignExtendAsNeeded(w.Previous));
|
||||
case ComparisonOperator.LessThanEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(w.Previous));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= SignExtendAsNeeded(w.Previous));
|
||||
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(w.Previous))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= SignExtendAsNeeded(w.Previous));
|
||||
case ComparisonOperator.DifferentBy:
|
||||
if (DifferentBy.HasValue)
|
||||
{
|
||||
|
@ -573,48 +538,31 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
default:
|
||||
case ComparisonOperator.Equal:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(compareValue));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(CompareValue.Value));
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(compareValue))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(CompareValue.Value));
|
||||
case ComparisonOperator.NotEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) != ToFloat(compareValue));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) != SignExtendAsNeeded(compareValue));
|
||||
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) != ToFloat(compareValue))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) != SignExtendAsNeeded(compareValue));
|
||||
case ComparisonOperator.GreaterThan:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(compareValue));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > SignExtendAsNeeded(compareValue));
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(compareValue))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > SignExtendAsNeeded(compareValue));
|
||||
case ComparisonOperator.GreaterThanEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(compareValue));
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= SignExtendAsNeeded(compareValue));
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(compareValue))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= SignExtendAsNeeded(compareValue));
|
||||
case ComparisonOperator.LessThan:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(compareValue));
|
||||
}
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(compareValue))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < SignExtendAsNeeded(compareValue));
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < SignExtendAsNeeded(compareValue));
|
||||
case ComparisonOperator.LessThanEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(compareValue));
|
||||
}
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(compareValue))
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= SignExtendAsNeeded(compareValue));
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= SignExtendAsNeeded(compareValue));
|
||||
case ComparisonOperator.DifferentBy:
|
||||
if (DifferentBy.HasValue)
|
||||
{
|
||||
|
@ -735,47 +683,29 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
default:
|
||||
case ComparisonOperator.Equal:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) - ToFloat(w.Previous) == compareValue);
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) == compareValue);
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) - ToFloat(w.Previous) == compareValue)
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) == compareValue);
|
||||
case ComparisonOperator.NotEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous != compareValue);
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) != compareValue);
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous != compareValue)
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) != compareValue);
|
||||
case ComparisonOperator.GreaterThan:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous > compareValue);
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) > compareValue);
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous > compareValue)
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) > compareValue);
|
||||
case ComparisonOperator.GreaterThanEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous >= compareValue);
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) >= compareValue);
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous >= compareValue)
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) >= compareValue);
|
||||
case ComparisonOperator.LessThan:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous < compareValue);
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) < compareValue);
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous < compareValue)
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) < compareValue);
|
||||
case ComparisonOperator.LessThanEqual:
|
||||
if (_settings.Type == DisplayType.Float)
|
||||
{
|
||||
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous <= compareValue);
|
||||
}
|
||||
|
||||
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) <= compareValue);
|
||||
return _settings.Type == DisplayType.Float
|
||||
? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous <= compareValue)
|
||||
: watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) <= compareValue);
|
||||
case ComparisonOperator.DifferentBy:
|
||||
if (DifferentBy.HasValue)
|
||||
{
|
||||
|
@ -802,7 +732,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region Private parts
|
||||
|
||||
private float ToFloat(long val)
|
||||
private static float ToFloat(long val)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes((int)val);
|
||||
return BitConverter.ToSingle(bytes, 0);
|
||||
|
@ -815,48 +745,35 @@ namespace BizHawk.Client.Common
|
|||
return val;
|
||||
}
|
||||
|
||||
switch (_settings.Size)
|
||||
return _settings.Size switch
|
||||
{
|
||||
default:
|
||||
case WatchSize.Byte:
|
||||
return (sbyte)val;
|
||||
case WatchSize.Word:
|
||||
return (short)val;
|
||||
case WatchSize.DWord:
|
||||
return (int)val;
|
||||
}
|
||||
WatchSize.Byte => (sbyte) val,
|
||||
WatchSize.Word => (short) val,
|
||||
WatchSize.DWord => (int) val,
|
||||
_ => (sbyte) val
|
||||
};
|
||||
}
|
||||
|
||||
private long GetValue(long addr)
|
||||
{
|
||||
// do not return sign extended variables from here.
|
||||
switch (_settings.Size)
|
||||
return _settings.Size switch
|
||||
{
|
||||
default:
|
||||
case WatchSize.Byte:
|
||||
var theByte = _settings.Domain.PeekByte(addr % Domain.Size);
|
||||
return theByte;
|
||||
|
||||
case WatchSize.Word:
|
||||
var theWord = _settings.Domain.PeekUshort(addr % Domain.Size, _settings.BigEndian);
|
||||
return theWord;
|
||||
|
||||
case WatchSize.DWord:
|
||||
var theDWord = _settings.Domain.PeekUint(addr % Domain.Size, _settings.BigEndian);
|
||||
return theDWord;
|
||||
}
|
||||
WatchSize.Byte => _settings.Domain.PeekByte(addr % Domain.Size),
|
||||
WatchSize.Word => _settings.Domain.PeekUshort(addr % Domain.Size, _settings.BigEndian),
|
||||
WatchSize.DWord => _settings.Domain.PeekUint(addr % Domain.Size, _settings.BigEndian),
|
||||
_ => _settings.Domain.PeekByte(addr % Domain.Size)
|
||||
};
|
||||
}
|
||||
|
||||
private bool CanDoCompareType(Compare compareType)
|
||||
{
|
||||
switch (_settings.Mode)
|
||||
return _settings.Mode switch
|
||||
{
|
||||
default:
|
||||
case Settings.SearchMode.Detailed:
|
||||
return true;
|
||||
case Settings.SearchMode.Fast:
|
||||
return compareType != Compare.Changes;
|
||||
}
|
||||
Settings.SearchMode.Detailed => true,
|
||||
Settings.SearchMode.Fast => (compareType != Compare.Changes),
|
||||
_ => true
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -181,18 +181,14 @@ namespace BizHawk.Client.Common
|
|||
// TODO: Implements IFormattable
|
||||
public string FormatValue(byte val)
|
||||
{
|
||||
switch (Type)
|
||||
return Type switch
|
||||
{
|
||||
default:
|
||||
case DisplayType.Unsigned:
|
||||
return val.ToString();
|
||||
case DisplayType.Signed:
|
||||
return ((sbyte)val).ToString();
|
||||
case DisplayType.Hex:
|
||||
return $"{val:X2}";
|
||||
case DisplayType.Binary:
|
||||
return Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " ");
|
||||
}
|
||||
DisplayType.Unsigned => val.ToString(),
|
||||
DisplayType.Signed => ((sbyte) val).ToString(),
|
||||
DisplayType.Hex => $"{val:X2}",
|
||||
DisplayType.Binary => Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " "),
|
||||
_ => val.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace BizHawk.Client.Common
|
|||
/// <exception cref="ArgumentException">Occurs when a <see cref="DisplayType"/> is incompatible with the <see cref="WatchSize"/></exception>
|
||||
protected Watch(MemoryDomain domain, long address, WatchSize size, DisplayType type, bool bigEndian, string note)
|
||||
{
|
||||
if (IsDiplayTypeAvailable(type))
|
||||
if (IsDisplayTypeAvailable(type))
|
||||
{
|
||||
_domain = domain;
|
||||
Address = address;
|
||||
|
@ -136,18 +136,14 @@ namespace BizHawk.Client.Common
|
|||
/// <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 = 0, long prev = 0, int changeCount = 0)
|
||||
{
|
||||
switch (size)
|
||||
return size switch
|
||||
{
|
||||
default:
|
||||
case WatchSize.Separator:
|
||||
return SeparatorWatch.NewSeparatorWatch(note);
|
||||
case WatchSize.Byte:
|
||||
return new ByteWatch(domain, address, type, bigEndian, note, (byte)value, (byte)prev, changeCount);
|
||||
case WatchSize.Word:
|
||||
return new WordWatch(domain, address, type, bigEndian, note, (ushort)value, (ushort)prev, changeCount);
|
||||
case WatchSize.DWord:
|
||||
return new DWordWatch(domain, address, type, bigEndian, note, (uint)value, (uint)prev, changeCount);
|
||||
}
|
||||
WatchSize.Separator => SeparatorWatch.NewSeparatorWatch(note),
|
||||
WatchSize.Byte => new ByteWatch(domain, address, type, bigEndian, note, (byte) value, (byte) prev, changeCount),
|
||||
WatchSize.Word => new WordWatch(domain, address, type, bigEndian, note, (ushort) value, (ushort) prev, changeCount),
|
||||
WatchSize.DWord => new DWordWatch(domain, address, type, bigEndian, note, (uint) value, (uint) prev, changeCount),
|
||||
_ => SeparatorWatch.NewSeparatorWatch(note)
|
||||
};
|
||||
}
|
||||
|
||||
#region Operators
|
||||
|
@ -455,14 +451,14 @@ namespace BizHawk.Client.Common
|
|||
/// <returns>True if both object are equals; otherwise, false</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Watch)
|
||||
if (obj is Watch watch)
|
||||
{
|
||||
return Equals((Watch)obj);
|
||||
return Equals(watch);
|
||||
}
|
||||
|
||||
if (obj is Cheat)
|
||||
if (obj is Cheat cheat)
|
||||
{
|
||||
return Equals((Cheat)obj);
|
||||
return Equals(cheat);
|
||||
}
|
||||
|
||||
return base.Equals(obj);
|
||||
|
@ -482,7 +478,7 @@ namespace BizHawk.Client.Common
|
|||
/// used for the current <see cref="Watch"/>
|
||||
/// </summary>
|
||||
/// <param name="type"><see cref="DisplayType"/> you want to check</param>
|
||||
public bool IsDiplayTypeAvailable(DisplayType type)
|
||||
public bool IsDisplayTypeAvailable(DisplayType type)
|
||||
{
|
||||
return AvailableTypes().Any(d => d == type);
|
||||
}
|
||||
|
@ -501,10 +497,7 @@ namespace BizHawk.Client.Common
|
|||
/// It's used by the "Display on screen" option in the RamWatch window
|
||||
/// </summary>
|
||||
/// <returns>A well formatted string representation</returns>
|
||||
public virtual string ToDisplayString()
|
||||
{
|
||||
return $"{Notes}: {ValueString}";
|
||||
}
|
||||
public virtual string ToDisplayString() => $"{Notes}: {ValueString}";
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -565,18 +558,9 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
public long Address { get; }
|
||||
|
||||
private string AddressFormatStr
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_domain != null)
|
||||
{
|
||||
return $"X{(_domain.Size - 1).NumHexDigits()}";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
private string AddressFormatStr => _domain != null
|
||||
? $"X{(_domain.Size - 1).NumHexDigits()}"
|
||||
: "";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address in the <see cref="MemoryDomain"/> formatted as string
|
||||
|
@ -603,7 +587,7 @@ namespace BizHawk.Client.Common
|
|||
get => _type;
|
||||
set
|
||||
{
|
||||
if (IsDiplayTypeAvailable(value))
|
||||
if (IsDisplayTypeAvailable(value))
|
||||
{
|
||||
_type = value;
|
||||
}
|
||||
|
@ -658,122 +642,88 @@ namespace BizHawk.Client.Common
|
|||
// TODO: Replace all the following stuff by implementing ISerializable
|
||||
public static string DisplayTypeToString(DisplayType type)
|
||||
{
|
||||
switch (type)
|
||||
return type switch
|
||||
{
|
||||
default:
|
||||
return type.ToString();
|
||||
case DisplayType.FixedPoint_12_4:
|
||||
return "Fixed Point 12.4";
|
||||
case DisplayType.FixedPoint_20_12:
|
||||
return "Fixed Point 20.12";
|
||||
case DisplayType.FixedPoint_16_16:
|
||||
return "Fixed Point 16.16";
|
||||
}
|
||||
DisplayType.FixedPoint_12_4 => "Fixed Point 12.4",
|
||||
DisplayType.FixedPoint_20_12 => "Fixed Point 20.12",
|
||||
DisplayType.FixedPoint_16_16 => "Fixed Point 16.16",
|
||||
_ => type.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
public static DisplayType StringToDisplayType(string name)
|
||||
{
|
||||
switch (name)
|
||||
return name switch
|
||||
{
|
||||
default:
|
||||
return (DisplayType)Enum.Parse(typeof(DisplayType), name);
|
||||
case "Fixed Point 12.4":
|
||||
return DisplayType.FixedPoint_12_4;
|
||||
case "Fixed Point 20.12":
|
||||
return DisplayType.FixedPoint_20_12;
|
||||
case "Fixed Point 16.16":
|
||||
return DisplayType.FixedPoint_16_16;
|
||||
}
|
||||
"Fixed Point 12.4" => DisplayType.FixedPoint_12_4,
|
||||
"Fixed Point 20.12" => DisplayType.FixedPoint_20_12,
|
||||
"Fixed Point 16.16" => DisplayType.FixedPoint_16_16,
|
||||
_ => (DisplayType) Enum.Parse(typeof(DisplayType), name)
|
||||
};
|
||||
}
|
||||
|
||||
public char SizeAsChar
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Size)
|
||||
return Size switch
|
||||
{
|
||||
default:
|
||||
case WatchSize.Separator:
|
||||
return 'S';
|
||||
case WatchSize.Byte:
|
||||
return 'b';
|
||||
case WatchSize.Word:
|
||||
return 'w';
|
||||
case WatchSize.DWord:
|
||||
return 'd';
|
||||
}
|
||||
WatchSize.Separator => 'S',
|
||||
WatchSize.Byte => 'b',
|
||||
WatchSize.Word => 'w',
|
||||
WatchSize.DWord => 'd',
|
||||
_ => 'S'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static WatchSize SizeFromChar(char c)
|
||||
{
|
||||
switch (c)
|
||||
return c switch
|
||||
{
|
||||
default:
|
||||
case 'S':
|
||||
return WatchSize.Separator;
|
||||
case 'b':
|
||||
return WatchSize.Byte;
|
||||
case 'w':
|
||||
return WatchSize.Word;
|
||||
case 'd':
|
||||
return WatchSize.DWord;
|
||||
}
|
||||
'S' => WatchSize.Separator,
|
||||
'b' => WatchSize.Byte,
|
||||
'w' => WatchSize.Word,
|
||||
'd' => WatchSize.DWord,
|
||||
_ => WatchSize.Separator
|
||||
};
|
||||
}
|
||||
|
||||
public char TypeAsChar
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Type)
|
||||
return Type switch
|
||||
{
|
||||
default:
|
||||
case DisplayType.Separator:
|
||||
return '_';
|
||||
case DisplayType.Unsigned:
|
||||
return 'u';
|
||||
case DisplayType.Signed:
|
||||
return 's';
|
||||
case DisplayType.Hex:
|
||||
return 'h';
|
||||
case DisplayType.Binary:
|
||||
return 'b';
|
||||
case DisplayType.FixedPoint_12_4:
|
||||
return '1';
|
||||
case DisplayType.FixedPoint_20_12:
|
||||
return '2';
|
||||
case DisplayType.FixedPoint_16_16:
|
||||
return '3';
|
||||
case DisplayType.Float:
|
||||
return 'f';
|
||||
}
|
||||
DisplayType.Separator => '_',
|
||||
DisplayType.Unsigned => 'u',
|
||||
DisplayType.Signed => 's',
|
||||
DisplayType.Hex => 'h',
|
||||
DisplayType.Binary => 'b',
|
||||
DisplayType.FixedPoint_12_4 => '1',
|
||||
DisplayType.FixedPoint_20_12 => '2',
|
||||
DisplayType.FixedPoint_16_16 => '3',
|
||||
DisplayType.Float => 'f',
|
||||
_ => '_'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static DisplayType DisplayTypeFromChar(char c)
|
||||
{
|
||||
switch (c)
|
||||
return c switch
|
||||
{
|
||||
default:
|
||||
case '_':
|
||||
return DisplayType.Separator;
|
||||
case 'u':
|
||||
return DisplayType.Unsigned;
|
||||
case 's':
|
||||
return DisplayType.Signed;
|
||||
case 'h':
|
||||
return DisplayType.Hex;
|
||||
case 'b':
|
||||
return DisplayType.Binary;
|
||||
case '1':
|
||||
return DisplayType.FixedPoint_12_4;
|
||||
case '2':
|
||||
return DisplayType.FixedPoint_20_12;
|
||||
case '3':
|
||||
return DisplayType.FixedPoint_16_16;
|
||||
case 'f':
|
||||
return DisplayType.Float;
|
||||
}
|
||||
'_' => DisplayType.Separator,
|
||||
'u' => DisplayType.Unsigned,
|
||||
's' => DisplayType.Signed,
|
||||
'h' => DisplayType.Hex,
|
||||
'b' => DisplayType.Binary,
|
||||
'1' => DisplayType.FixedPoint_12_4,
|
||||
'2' => DisplayType.FixedPoint_20_12,
|
||||
'3' => DisplayType.FixedPoint_16_16,
|
||||
'f' => DisplayType.Float,
|
||||
_ => DisplayType.Separator
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (ReferenceEquals(x, null))
|
||||
{
|
||||
if (ReferenceEquals(y, null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ReferenceEquals(y, null);
|
||||
}
|
||||
|
||||
if (ReferenceEquals(y, null))
|
||||
|
@ -33,12 +28,7 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(x, y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ReferenceEquals(x, y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -46,10 +36,7 @@ namespace BizHawk.Client.Common
|
|||
/// </summary>
|
||||
/// <param name="obj">Watch to get hash</param>
|
||||
/// <returns>int that can serves as a unique representation of current Watch</returns>
|
||||
public int GetHashCode(Watch obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
public int GetHashCode(Watch obj) => obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,10 +55,7 @@ namespace BizHawk.Client.Common
|
|||
/// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="WordWatch"/>
|
||||
/// </summary>
|
||||
/// <returns>An enumeration that contains all valid <see cref="DisplayType"/></returns>
|
||||
public override IEnumerable<DisplayType> AvailableTypes()
|
||||
{
|
||||
return ValidTypes;
|
||||
}
|
||||
public override IEnumerable<DisplayType> AvailableTypes() => ValidTypes;
|
||||
|
||||
/// <summary>
|
||||
/// Reset the previous value; set it to the current one
|
||||
|
@ -193,20 +190,19 @@ namespace BizHawk.Client.Common
|
|||
// TODO: Implements IFormattable
|
||||
public string FormatValue(ushort val)
|
||||
{
|
||||
switch (Type)
|
||||
return Type switch
|
||||
{
|
||||
default:
|
||||
case DisplayType.Unsigned:
|
||||
return val.ToString();
|
||||
case DisplayType.Signed:
|
||||
return ((short)val).ToString();
|
||||
case DisplayType.Hex:
|
||||
return $"{val:X4}";
|
||||
case DisplayType.FixedPoint_12_4:
|
||||
return $"{val / 16.0:F4}";
|
||||
case DisplayType.Binary:
|
||||
return Convert.ToString(val, 2).PadLeft(16, '0').Insert(8, " ").Insert(4, " ").Insert(14, " ");
|
||||
}
|
||||
DisplayType.Unsigned => val.ToString(),
|
||||
DisplayType.Signed => ((short) val).ToString(), DisplayType.Hex => $"{val:X4}",
|
||||
DisplayType.FixedPoint_12_4 => $"{val / 16.0:F4}",
|
||||
DisplayType.Binary => Convert
|
||||
.ToString(val, 2)
|
||||
.PadLeft(16, '0')
|
||||
.Insert(8, " ")
|
||||
.Insert(4, " ")
|
||||
.Insert(14, " "),
|
||||
_ => val.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -341,6 +341,7 @@
|
|||
<s:Boolean x:Key="/Default/UserDictionary/Words/=inrate/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ints/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=INTV/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Inversed/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Joypad/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=jumplist/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Justifier/@EntryIndexedValue">True</s:Boolean>
|
||||
|
|
Loading…
Reference in New Issue