misc cleanups in Client.Common

This commit is contained in:
adelikat 2020-03-01 15:49:48 -06:00
parent 0ffac58ce8
commit 18762c75ee
34 changed files with 432 additions and 817 deletions

View File

@ -11,15 +11,15 @@ namespace BizHawk.Client.Common
{ {
public Controller(ControllerDefinition definition) public Controller(ControllerDefinition definition)
{ {
_type = definition; Definition = definition;
for (int i = 0; i < _type.FloatControls.Count; i++) for (int i = 0; i < Definition.FloatControls.Count; i++)
{ {
_floatButtons[_type.FloatControls[i]] = _type.FloatRanges[i].Mid; _floatButtons[Definition.FloatControls[i]] = Definition.FloatRanges[i].Mid;
_floatRanges[_type.FloatControls[i]] = _type.FloatRanges[i]; _floatRanges[Definition.FloatControls[i]] = Definition.FloatRanges[i];
} }
} }
public ControllerDefinition Definition => _type; public ControllerDefinition Definition { get; private set; }
public bool IsPressed(string button) 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, ControllerDefinition.FloatRange> _floatRanges = new WorkingDictionary<string, ControllerDefinition.FloatRange>();
private readonly Dictionary<string, AnalogBind> _floatBinds = new Dictionary<string, AnalogBind>(); private readonly Dictionary<string, AnalogBind> _floatBinds = new Dictionary<string, AnalogBind>();
private ControllerDefinition _type;
/// <summary>don't do this</summary> /// <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); public bool this[string button] => IsPressed(button);
@ -154,9 +152,7 @@ namespace BizHawk.Client.Common
} }
public void ApplyAxisConstraints(string constraintClass) public void ApplyAxisConstraints(string constraintClass)
{ => Definition.ApplyAxisConstraints(constraintClass, _floatButtons);
_type.ApplyAxisConstraints(constraintClass, _floatButtons);
}
/// <summary> /// <summary>
/// merges pressed logical buttons from the supplied controller, effectively ORing it with the current state /// merges pressed logical buttons from the supplied controller, effectively ORing it with the current state

View File

@ -10,7 +10,7 @@ namespace BizHawk.Client.Common
var ipsHeader = new byte[5]; var ipsHeader = new byte[5];
patch.Read(ipsHeader, 0, 5); patch.Read(ipsHeader, 0, 5);
string header = "PATCH"; const string header = "PATCH";
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
if (ipsHeader[i] != header[i]) if (ipsHeader[i] != header[i])
@ -21,7 +21,7 @@ namespace BizHawk.Client.Common
} }
// header verified, loop over patch entries // 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); var ret = new MemoryStream(rom.Length);
ret.Write(rom, 0, rom.Length); ret.Write(rom, 0, rom.Length);

View File

@ -49,28 +49,15 @@ namespace BizHawk.Client.Common
int idx = text.IndexOf('*'); int idx = text.IndexOf('*');
string type = text.Substring(0, idx); string type = text.Substring(0, idx);
string token = text.Substring(idx + 1); string token = text.Substring(idx + 1);
IOpenAdvanced ioa;
if (type == OpenAdvancedTypes.OpenRom) var ioa = type switch
{ {
ioa = new OpenAdvanced_OpenRom(); OpenAdvancedTypes.OpenRom => (IOpenAdvanced)new OpenAdvanced_OpenRom(),
} OpenAdvancedTypes.Libretro => new OpenAdvanced_Libretro(),
else if (type == OpenAdvancedTypes.Libretro) OpenAdvancedTypes.LibretroNoGame => new OpenAdvanced_LibretroNoGame(),
{ OpenAdvancedTypes.MAME => new OpenAdvanced_MAME(),
ioa = new OpenAdvanced_Libretro(); _ => null
} };
else if (type == OpenAdvancedTypes.LibretroNoGame)
{
ioa = new OpenAdvanced_LibretroNoGame();
}
else if (type == OpenAdvancedTypes.MAME)
{
ioa = new OpenAdvanced_MAME();
}
else
{
ioa = null;
}
if (ioa == null) if (ioa == null)
{ {
@ -83,7 +70,7 @@ namespace BizHawk.Client.Common
public static string Serialize(IOpenAdvanced ioa) public static string Serialize(IOpenAdvanced ioa)
{ {
StringWriter sw = new StringWriter(); var sw = new StringWriter();
sw.Write("{0}*", ioa.TypeName); sw.Write("{0}*", ioa.TypeName);
ioa.Serialize(sw); ioa.Serialize(sw);
return sw.ToString(); return sw.ToString();

View File

@ -171,18 +171,10 @@ namespace BizHawk.Client.Common
{ {
// determine the number of parent directories in path and return result // determine the number of parent directories in path and return result
int x = path.HowMany('\\'); int x = path.HowMany('\\');
if (x > 0) return x > 0 ? path.HowMany("..\\") : 0;
{
return path.HowMany("..\\");
}
return 0;
} }
public static bool IsRecent(string path) public static bool IsRecent(string path) => path == "%recent%";
{
return path == "%recent%";
}
public static string GetLuaPath() public static string GetLuaPath()
{ {

View File

@ -40,28 +40,10 @@ namespace BizHawk.Client.Common
[JsonIgnore] [JsonIgnore]
public string MostRecent => recentlist.Any() ? recentlist[0] : ""; public string MostRecent => recentlist.Any() ? recentlist[0] : "";
public string this[int index] public string this[int index] => recentlist.Any() ? recentlist[index] : "";
{
get
{
if (recentlist.Any())
{
return recentlist[index];
}
return ""; public IEnumerator<string> GetEnumerator() => recentlist.GetEnumerator();
} IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public IEnumerator<string> GetEnumerator()
{
return recentlist.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Clear() public void Clear()
{ {

View File

@ -36,7 +36,7 @@ namespace BizHawk.Client.Common.cheats
code = code.Remove(0, 2); code = code.Remove(0, 2);
var addrStr = 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.Value = int.Parse(valueStr, NumberStyles.HexNumber);
result.Address = int.Parse(addrStr, NumberStyles.HexNumber); result.Address = int.Parse(addrStr, NumberStyles.HexNumber);

View File

@ -19,35 +19,35 @@ namespace BizHawk.Client.Common.cheats
} }
var parseString = code.Remove(0, 2); var parseString = code.Remove(0, 2);
switch (code.Length) return code.Length switch
{ {
case 9: 9 =>
// Sample Code of 1-Byte: // Sample Code of 1-Byte:
// FFF761:64 // FFF761:64
// Becomes: // Becomes:
// Address: F761 // Address: F761
// Value: 64 // Value: 64
return new DecodeResult new DecodeResult
{ {
Address = int.Parse(parseString.Remove(4, 3), NumberStyles.HexNumber), Address = int.Parse(parseString.Remove(4, 3), NumberStyles.HexNumber)
Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber), , Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber)
Size = WatchSize.Byte , Size = WatchSize.Byte
}; },
case 11: 11 =>
// Sample Code of 2-Byte: // Sample Code of 2-Byte:
// FFF761:6411 // FFF761:6411
// Becomes: // Becomes:
// Address: F761 // Address: F761
// Value: 6411 // Value: 6411
return new DecodeResult new DecodeResult
{ {
Address = int.Parse(parseString.Remove(4, 5), NumberStyles.HexNumber), Address = int.Parse(parseString.Remove(4, 5), NumberStyles.HexNumber)
Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber), , Value = int.Parse(parseString.Remove(0, 5), NumberStyles.HexNumber)
Size = WatchSize.Word , Size = WatchSize.Word
}; },
default: _ => new InvalidCheatCode(
return new InvalidCheatCode("Action Replay/Pro Action Replay Codes need to be either 9 or 11 characters."); "Action Replay/Pro Action Replay Codes need to be either 9 or 11 characters.")
} };
} }
} }
} }

View File

@ -50,12 +50,7 @@ namespace BizHawk.Client.Common
throw new InvalidOperationException("Config Error", ex); throw new InvalidOperationException("Config Error", ex);
} }
if (config == null) return config ?? new T();
{
return new T();
}
return config;
} }
public static void Save(string filepath, object config) public static void Save(string filepath, object config)

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -29,47 +29,16 @@ namespace BizHawk.Client.Common
} }
public float GetFloat(string name) public float GetFloat(string name)
{ => _floatOverrides.ContainsKey(name)
if (_floatOverrides.ContainsKey(name)) ? _floatOverrides[name]
{ : 0.0F;
return _floatOverrides[name];
}
return 0.0F; public IEnumerable<string> Overrides => _overrides.Select(kvp => kvp.Key);
}
public IEnumerable<string> Overrides public IEnumerable<string> FloatOverrides => _floatOverrides.Select(kvp => kvp.Key);
{
get
{
foreach (var kvp in _overrides)
{
yield return kvp.Key;
}
}
}
public IEnumerable<string> FloatOverrides public IEnumerable<string> InversedButtons => _inverses;
{
get
{
foreach (var kvp in _floatOverrides)
{
yield return kvp.Key;
}
}
}
public IEnumerable<string> InversedButtons
{
get
{
foreach (var name in _inverses)
{
yield return name;
}
}
}
public void SetFloat(string name, float value) public void SetFloat(string name, float value)
{ {

View File

@ -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")] [LuaMethod("trim", "returns a string that trims whitespace on the left and right ends of the string")]
public static string Trim(string str) public static string Trim(string str)
{ {
if (string.IsNullOrEmpty(str)) return string.IsNullOrEmpty(str) ? null : str.Trim();
{
return null;
}
return str.Trim();
} }
[LuaMethodExample("local stbizrep = bizstring.replace( \"Some string\", \"Some\", \"Replaced\" );")] [LuaMethodExample("local stbizrep = bizstring.replace( \"Some string\", \"Some\", \"Replaced\" );")]

View File

@ -220,7 +220,7 @@ __Types and notation__
} }
} }
private string TypeCleanup(string str) private static string TypeCleanup(string str)
{ {
return str return str
.Replace("System", "") .Replace("System", "")

View File

@ -61,18 +61,18 @@
public void Toggle() public void Toggle()
{ {
if (State == RunState.Paused) switch (State)
{ {
State = RunState.Running; case RunState.Paused:
} State = RunState.Running;
else if (State == RunState.Disabled) break;
{ case RunState.Disabled:
State = RunState.Running; State = RunState.Running;
FrameWaiting = false; FrameWaiting = false;
} break;
else default:
{ State = RunState.Disabled;
State = RunState.Disabled; break;
} }
} }

View File

@ -60,22 +60,13 @@ namespace BizHawk.Client.Common
protected static Color? ToColor(object o) protected static Color? ToColor(object o)
{ {
if (o == null) return o switch
{ {
return null; double d => Color.FromArgb((int) (long) d),
} string s => Color.FromName(s),
null => null,
if (o is double d) _ => null
{ };
return Color.FromArgb((int)(long)d);
}
if (o is string s)
{
return Color.FromName(s);
}
return null;
} }
protected void Log(object message) protected void Log(object message)

View File

@ -80,12 +80,7 @@ namespace BizHawk.Client.Common
get get
{ {
var key = systemId + (pal ? "_PAL" : ""); var key = systemId + (pal ? "_PAL" : "");
if (Rates.ContainsKey(key)) return Rates.ContainsKey(key) ? Rates[key] : 60.0;
{
return Rates[key];
}
return 60.0;
} }
} }

View File

@ -77,7 +77,7 @@ namespace BizHawk.Client.Common
{ {
int index = 1; int index = 1;
var sb = new StringBuilder(); var sb = new StringBuilder();
List<Subtitle> subs = new List<Subtitle>(); var subs = new List<Subtitle>();
foreach (var subtitle in this) foreach (var subtitle in this)
{ {
subs.Add(new Subtitle(subtitle)); subs.Add(new Subtitle(subtitle));

View File

@ -50,16 +50,7 @@ namespace BizHawk.Client.Common
public bool StartsFromSavestate public bool StartsFromSavestate
{ {
get get => Header.ContainsKey(HeaderKeys.STARTSFROMSAVESTATE) && bool.Parse(Header[HeaderKeys.STARTSFROMSAVESTATE]);
{
if (Header.ContainsKey(HeaderKeys.STARTSFROMSAVESTATE))
{
return bool.Parse(Header[HeaderKeys.STARTSFROMSAVESTATE]);
}
return false;
}
set set
{ {
if (value) if (value)
@ -75,16 +66,7 @@ namespace BizHawk.Client.Common
public bool StartsFromSaveRam public bool StartsFromSaveRam
{ {
get get => Header.ContainsKey(HeaderKeys.STARTSFROMSAVERAM) && bool.Parse(Header[HeaderKeys.STARTSFROMSAVERAM]);
{
if (Header.ContainsKey(HeaderKeys.STARTSFROMSAVERAM))
{
return bool.Parse(Header[HeaderKeys.STARTSFROMSAVERAM]);
}
return false;
}
set set
{ {
if (value) if (value)
@ -106,16 +88,7 @@ namespace BizHawk.Client.Common
public string GameName public string GameName
{ {
get get => Header.ContainsKey(HeaderKeys.GAMENAME) ? Header[HeaderKeys.GAMENAME] : "";
{
if (Header.ContainsKey(HeaderKeys.GAMENAME))
{
return Header[HeaderKeys.GAMENAME];
}
return "";
}
set set
{ {
if (Header[HeaderKeys.GAMENAME] != value) if (Header[HeaderKeys.GAMENAME] != value)
@ -128,16 +101,7 @@ namespace BizHawk.Client.Common
public string SystemID public string SystemID
{ {
get get => Header.ContainsKey(HeaderKeys.PLATFORM) ? Header[HeaderKeys.PLATFORM] : "";
{
if (Header.ContainsKey(HeaderKeys.PLATFORM))
{
return Header[HeaderKeys.PLATFORM];
}
return "";
}
set set
{ {
if (Header[HeaderKeys.PLATFORM] != value) if (Header[HeaderKeys.PLATFORM] != value)

View File

@ -16,7 +16,7 @@ namespace BizHawk.Client.Common
{ {
var neshawkName = ((CoreAttribute)Attribute.GetCustomAttribute(typeof(NES), typeof(CoreAttribute))).CoreName; var neshawkName = ((CoreAttribute)Attribute.GetCustomAttribute(typeof(NES), typeof(CoreAttribute))).CoreName;
Result.Movie.HeaderEntries[HeaderKeys.CORE] = neshawkName; Result.Movie.HeaderEntries[HeaderKeys.CORE] = neshawkName;
var emulator = "FCEUX"; const string emulator = "FCEUX";
var platform = "NES"; // TODO: FDS? var platform = "NES"; // TODO: FDS?
var syncSettings = new NES.NESSyncSettings(); var syncSettings = new NES.NESSyncSettings();

View File

@ -342,14 +342,10 @@ namespace BizHawk.Client.Common.movie.import
} }
// LSNES frames don't start or end with a |. // LSNES frames don't start or end with a |.
int start = 1;
int end = sections.Length; 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} "; string prefix = $"P{player} ";
// Gameboy doesn't currently have a prefix saying which player the input is for. // 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. // Only count lines with that have the right number of buttons and are for valid players.
if ( if (
sections[section].Length == buttons.Length) sections[player].Length == buttons.Length)
{ {
for (int button = 0; button < buttons.Length; button++) for (int button = 0; button < buttons.Length; button++)
{ {
// Consider the button pressed so long as its spot is not occupied by a ".". // 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] != '.';
} }
} }
} }

View File

@ -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. 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. 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 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. // 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} "; string prefix = $"P{player} ";
// Only count lines with that have the right number of buttons and are for valid players. // Only count lines with that have the right number of buttons and are for valid players.

View File

@ -45,17 +45,14 @@ namespace BizHawk.Client.Common
.GetConstructor(new Type[] { }) .GetConstructor(new Type[] { })
?.Invoke(new object[] { }); ?.Invoke(new object[] { });
if (importer == null) return importer == null
{ ? ImportResult.Error($"No importer found for file type {ext}")
return ImportResult.Error($"No importer found for file type {ext}"); : importer.Import(path);
}
return importer.Import(path);
} }
private static Type ImporterForExtension(string ext) 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;
} }
} }
} }

View File

@ -34,22 +34,13 @@ namespace BizHawk.Client.Common.movie.import
// 004 4-byte little-endian unsigned int: version number // 004 4-byte little-endian unsigned int: version number
uint versionNumber = r.ReadUInt32(); uint versionNumber = r.ReadUInt32();
string version; var version = versionNumber switch
switch (versionNumber)
{ {
case 1: 1 => "1.43",
version = "1.43"; 4 => "1.51",
break; 5 => "1.52",
case 4: _ => "Unknown"
version = "1.51"; };
break;
case 5:
version = "1.52";
break;
default:
version = "Unknown";
break;
}
Result.Movie.Comments.Add($"{EmulationOrigin} Snes9x version {version}"); Result.Movie.Comments.Add($"{EmulationOrigin} Snes9x version {version}");
Result.Movie.Comments.Add($"{MovieOrigin} .SMV"); Result.Movie.Comments.Add($"{MovieOrigin} .SMV");

View File

@ -28,83 +28,53 @@ namespace BizHawk.Client.Common
/// </summary> /// </summary>
public void SetControllersAsMnemonic(string mnemonic) public void SetControllersAsMnemonic(string mnemonic)
{ {
if (ControlType == "Null Controller") switch (ControlType)
{ {
return; case "Null Controller":
} return;
case "Lynx Controller":
if (ControlType == "Lynx Controller") SetLynxControllersAsMnemonic(mnemonic);
{ return;
SetLynxControllersAsMnemonic(mnemonic); case "SNES Controller":
return; SetSNESControllersAsMnemonic(mnemonic);
} return;
case "Commodore 64 Controller":
if (ControlType == "SNES Controller") SetC64ControllersAsMnemonic(mnemonic);
{ return;
SetSNESControllersAsMnemonic(mnemonic); case "GBA Controller":
return; SetGBAControllersAsMnemonic(mnemonic);
} return;
case "Atari 7800 ProLine Joystick Controller":
if (ControlType == "Commodore 64 Controller") SetAtari7800AsMnemonic(mnemonic);
{ return;
SetC64ControllersAsMnemonic(mnemonic); case "Dual Gameboy Controller":
return; SetDualGameBoyControllerAsMnemonic(mnemonic);
} return;
case "WonderSwan Controller":
if (ControlType == "GBA Controller") SetWonderSwanControllerAsMnemonic(mnemonic);
{ return;
SetGBAControllersAsMnemonic(mnemonic); case "Nintendo 64 Controller":
return; SetN64ControllersAsMnemonic(mnemonic);
} return;
case "Saturn Controller":
if (ControlType == "Atari 7800 ProLine Joystick Controller") SetSaturnControllersAsMnemonic(mnemonic);
{ return;
SetAtari7800AsMnemonic(mnemonic); case "PSP Controller":
return; // TODO
} return;
case "GPGX Genesis Controller":
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())
{ {
SetGenesis6ControllersAsMnemonic(mnemonic); if (IsGenesis6Button())
} {
else SetGenesis6ControllersAsMnemonic(mnemonic);
{ }
SetGenesis3ControllersAsMnemonic(mnemonic); else
} {
SetGenesis3ControllersAsMnemonic(mnemonic);
}
return; return;
}
} }
var c = new MnemonicChecker(mnemonic); var c = new MnemonicChecker(mnemonic);
@ -118,41 +88,42 @@ namespace BizHawk.Client.Common
{ {
return; return;
} }
else if (mnemonic[1] == 'P')
switch (mnemonic[1])
{ {
Force("Power", true); case 'P':
} Force("Power", true);
else if (mnemonic[1] == 'E') break;
{ case 'E':
Force("FDS Eject", true); Force("FDS Eject", true);
} break;
else if (mnemonic[1] == '0') case '0':
{ Force("FDS Insert 0", true);
Force("FDS Insert 0", true); break;
} case '1':
else if (mnemonic[1] == '1') Force("FDS Insert 1", true);
{ break;
Force("FDS Insert 1", true); case '2':
} Force("FDS Insert 2", true);
else if (mnemonic[1] == '2') break;
{ case '3':
Force("FDS Insert 2", true); Force("FDS Insert 3", true);
} break;
else if (mnemonic[1] == '3') case 'c':
{ Force("VS Coin 1", true);
Force("FDS Insert 3", true); break;
} case 'C':
else if (mnemonic[1] == 'c') Force("VS Coin 2", true);
{ break;
Force("VS Coin 1", true); default:
} {
else if (mnemonic[1] == 'C') if (mnemonic[1] != '.')
{ {
Force("VS Coin 2", true); Force("Reset", true);
} }
else if (mnemonic[1] != '.')
{ break;
Force("Reset", true); }
} }
} }
@ -195,9 +166,9 @@ namespace BizHawk.Client.Common
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++) 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; int ctr = start;
if (mnemonic.Length < srcindex + ctr + BkmMnemonicConstants.Buttons[ControlType].Count - 1) if (mnemonic.Length < srcIndex + ctr + BkmMnemonicConstants.Buttons[ControlType].Count - 1)
{ {
return; return;
} }
@ -210,17 +181,17 @@ namespace BizHawk.Client.Common
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys) foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{ {
Force(prefix + button, c[srcindex + ctr++]); Force(prefix + button, c[srcIndex + ctr++]);
} }
} }
if (ControlType == "SMS Controller") 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; int ctr = start;
foreach (var command in BkmMnemonicConstants.Commands[ControlType].Keys) 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, bool> _myBoolButtons = new WorkingDictionary<string, bool>();
private readonly WorkingDictionary<string, float> _myFloatControls = new WorkingDictionary<string, float>(); private readonly WorkingDictionary<string, float> _myFloatControls = new WorkingDictionary<string, float>();
private bool IsGenesis6Button() private bool IsGenesis6Button() => Definition.BoolButtons.Contains("P1 X");
{
return Definition.BoolButtons.Contains("P1 X");
}
private void Force(string button, bool state) private void Force(string button, bool state)
{ {
@ -247,7 +215,7 @@ namespace BizHawk.Client.Common
private void SetGBAControllersAsMnemonic(string mnemonic) private void SetGBAControllersAsMnemonic(string mnemonic)
{ {
MnemonicChecker c = new MnemonicChecker(mnemonic); var c = new MnemonicChecker(mnemonic);
_myBoolButtons.Clear(); _myBoolButtons.Clear();
if (mnemonic.Length < 2) if (mnemonic.Length < 2)
{ {
@ -268,7 +236,7 @@ namespace BizHawk.Client.Common
private void SetGenesis6ControllersAsMnemonic(string mnemonic) private void SetGenesis6ControllersAsMnemonic(string mnemonic)
{ {
MnemonicChecker c = new MnemonicChecker(mnemonic); var c = new MnemonicChecker(mnemonic);
_myBoolButtons.Clear(); _myBoolButtons.Clear();
if (mnemonic.Length < 2) if (mnemonic.Length < 2)
@ -292,9 +260,9 @@ namespace BizHawk.Client.Common
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++) 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; return;
} }
@ -302,14 +270,14 @@ namespace BizHawk.Client.Common
int start = 3; int start = 3;
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys) 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) private void SetGenesis3ControllersAsMnemonic(string mnemonic)
{ {
MnemonicChecker c = new MnemonicChecker(mnemonic); var c = new MnemonicChecker(mnemonic);
_myBoolButtons.Clear(); _myBoolButtons.Clear();
if (mnemonic.Length < 2) if (mnemonic.Length < 2)
@ -333,9 +301,9 @@ namespace BizHawk.Client.Common
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++) 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; return;
} }
@ -343,7 +311,7 @@ namespace BizHawk.Client.Common
int start = 3; int start = 3;
foreach (string button in BkmMnemonicConstants.Buttons["GPGX 3-Button Controller"].Keys) 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++) 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; return;
} }
@ -379,7 +347,7 @@ namespace BizHawk.Client.Common
int start = 3; int start = 3;
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys) 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++) 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; return;
} }
@ -411,14 +379,14 @@ namespace BizHawk.Client.Common
int start = 3; int start = 3;
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys) foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys)
{ {
Force(button, c[srcindex + start++]); Force(button, c[srcIndex + start++]);
} }
} }
} }
private void SetN64ControllersAsMnemonic(string mnemonic) private void SetN64ControllersAsMnemonic(string mnemonic)
{ {
MnemonicChecker c = new MnemonicChecker(mnemonic); var c = new MnemonicChecker(mnemonic);
_myBoolButtons.Clear(); _myBoolButtons.Clear();
if (mnemonic.Length < 2) if (mnemonic.Length < 2)
@ -460,7 +428,7 @@ namespace BizHawk.Client.Common
private void SetSaturnControllersAsMnemonic(string mnemonic) private void SetSaturnControllersAsMnemonic(string mnemonic)
{ {
MnemonicChecker c = new MnemonicChecker(mnemonic); var c = new MnemonicChecker(mnemonic);
_myBoolButtons.Clear(); _myBoolButtons.Clear();
if (mnemonic.Length < 2) if (mnemonic.Length < 2)
@ -479,9 +447,9 @@ namespace BizHawk.Client.Common
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++) 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; return;
} }
@ -489,14 +457,14 @@ namespace BizHawk.Client.Common
int start = 3; int start = 3;
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys) 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) private void SetAtari7800AsMnemonic(string mnemonic)
{ {
MnemonicChecker c = new MnemonicChecker(mnemonic); var c = new MnemonicChecker(mnemonic);
_myBoolButtons.Clear(); _myBoolButtons.Clear();
if (mnemonic.Length < 5) if (mnemonic.Length < 5)
@ -526,16 +494,16 @@ namespace BizHawk.Client.Common
for (int player = 1; player <= BkmMnemonicConstants.Players[ControlType]; player++) 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; int start = 6;
if (mnemonic.Length < srcindex + start + BkmMnemonicConstants.Buttons[ControlType].Count) if (mnemonic.Length < srcIndex + start + BkmMnemonicConstants.Buttons[ControlType].Count)
{ {
return; return;
} }
foreach (string button in BkmMnemonicConstants.Buttons[ControlType].Keys) 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++) 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; return;
} }
@ -585,14 +553,14 @@ namespace BizHawk.Client.Common
int start = 1; int start = 1;
foreach (var button in BkmMnemonicConstants.Buttons[ControlType].Keys) 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) foreach (string button in BkmMnemonicConstants.Buttons["Commodore 64 Keyboard"].Keys)
{ {
Force(button, c[startk++]); Force(button, c[startKey++]);
} }
} }

View File

@ -22,16 +22,9 @@ namespace BizHawk.Client.Common
public string SavestateBinaryBase64Blob public string SavestateBinaryBase64Blob
{ {
get get => ContainsKey(HeaderKeys.SAVESTATEBINARYBASE64BLOB)
{ ? this[HeaderKeys.SAVESTATEBINARYBASE64BLOB]
if (ContainsKey(HeaderKeys.SAVESTATEBINARYBASE64BLOB)) : null;
{
return this[HeaderKeys.SAVESTATEBINARYBASE64BLOB];
}
return null;
}
set set
{ {
if (value == null) if (value == null)
@ -48,7 +41,6 @@ namespace BizHawk.Client.Common
public new string this[string key] public new string this[string key]
{ {
get => ContainsKey(key) ? base[key] : ""; get => ContainsKey(key) ? base[key] : "";
set set
{ {
if (ContainsKey(key)) if (ContainsKey(key))

View File

@ -31,12 +31,7 @@ namespace BizHawk.Client.Common
return double.PositiveInfinity; return double.PositiveInfinity;
} }
if (Loaded) return Loaded ? _log.Count : 0;
{
return _log.Count;
}
return 0;
} }
} }

View File

@ -395,12 +395,9 @@ namespace BizHawk.Client.Common
public Guid BranchGuidByIndex(int index) public Guid BranchGuidByIndex(int index)
{ {
if (index >= Branches.Count) return index >= Branches.Count
{ ? Guid.Empty
return Guid.Empty; : Branches[index].UniqueIdentifier;
}
return Branches[index].UniqueIdentifier;
} }
public int BranchIndexByHash(Guid uuid) public int BranchIndexByHash(Guid uuid)

View File

@ -44,17 +44,12 @@ namespace BizHawk.Client.Common
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj == null) return obj switch
{ {
return false; null => false,
} TasMovieMarker marker => Frame == marker.Frame,
_ => false
if (obj is TasMovieMarker marker) };
{
return Frame == marker.Frame;
}
return false;
} }
public static bool operator ==(TasMovieMarker marker, int frame) public static bool operator ==(TasMovieMarker marker, int frame)

View File

@ -87,24 +87,15 @@ namespace BizHawk.Client.Common
public string AddressStr => _watch.AddressString; public string AddressStr => _watch.AddressString;
public string ValueStr public string ValueStr =>
{ _watch.Size switch
get
{
switch (_watch.Size)
{ {
default: WatchSize.Byte => ((ByteWatch) _watch).FormatValue((byte)_val),
case WatchSize.Separator: WatchSize.Word => ((WordWatch) _watch).FormatValue((ushort)_val),
return ""; WatchSize.DWord => ((DWordWatch) _watch).FormatValue((uint)_val),
case WatchSize.Byte: WatchSize.Separator => "",
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);
}
}
}
public string CompareStr public string CompareStr
{ {
@ -112,25 +103,21 @@ namespace BizHawk.Client.Common
{ {
if (_compare.HasValue) if (_compare.HasValue)
{ {
switch (_watch.Size) return _watch.Size switch
{ {
default: WatchSize.Byte => ((ByteWatch) _watch).FormatValue((byte)_compare.Value),
case WatchSize.Separator: WatchSize.Word => ((WordWatch) _watch).FormatValue((ushort)_compare.Value),
return ""; WatchSize.DWord => ((DWordWatch) _watch).FormatValue((uint)_compare.Value),
case WatchSize.Byte: WatchSize.Separator => "",
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);
}
} }
return ""; return "";
} }
} }
public CompareType ComparisonType { get; private set; } public CompareType ComparisonType { get; }
public void Enable(bool handleChange = true) public void Enable(bool handleChange = true)
{ {
@ -170,15 +157,10 @@ namespace BizHawk.Client.Common
} }
} }
private string GetStringForPulse(int val) private string GetStringForPulse(int val) =>
{ _watch.Type == DisplayType.Hex
if (_watch.Type == DisplayType.Hex) ? val.ToString("X8")
{ : val.ToString();
return val.ToString("X8");
}
return val.ToString();
}
public void Pulse() public void Pulse()
{ {
@ -239,13 +221,13 @@ namespace BizHawk.Client.Common
switch (_watch.Size) switch (_watch.Size)
{ {
case WatchSize.Byte: case WatchSize.Byte:
_watch.Poke((_watch as ByteWatch).FormatValue((byte)_val)); _watch.Poke(((ByteWatch)_watch).FormatValue((byte)_val));
break; break;
case WatchSize.Word: case WatchSize.Word:
_watch.Poke((_watch as WordWatch).FormatValue((ushort)_val)); _watch.Poke(((WordWatch)_watch).FormatValue((ushort)_val));
break; break;
case WatchSize.DWord: case WatchSize.DWord:
_watch.Poke((_watch as DWordWatch).FormatValue((uint)_val)); _watch.Poke(((DWordWatch)_watch).FormatValue((uint)_val));
break; break;
} }
} }
@ -381,7 +363,7 @@ namespace BizHawk.Client.Common
public void SetType(DisplayType type) public void SetType(DisplayType type)
{ {
if (_watch.IsDiplayTypeAvailable(type)) if (_watch.IsDisplayTypeAvailable(type))
{ {
_watch.Type = type; _watch.Type = type;
Changes(); Changes();

View File

@ -80,13 +80,7 @@ namespace BizHawk.Client.Common
public bool AttemptToLoadCheatFile() public bool AttemptToLoadCheatFile()
{ {
var file = new FileInfo(_defaultFileName); var file = new FileInfo(_defaultFileName);
return file.Exists && Load(file.FullName, false);
if (file.Exists)
{
return Load(file.FullName, false);
}
return false;
} }
public void NewList(string defaultFileName, bool autosave = false) public void NewList(string defaultFileName, bool autosave = false)
@ -297,12 +291,9 @@ namespace BizHawk.Client.Common
case WatchSize.Byte: case WatchSize.Byte:
return activeCheat.Value; return activeCheat.Value;
case WatchSize.Word: case WatchSize.Word:
if (size == WatchSize.Byte) return size == WatchSize.Byte
{ ? GetByteValue(domain, addr)
return GetByteValue(domain, addr); : activeCheat.Value;
}
return activeCheat.Value;
case WatchSize.DWord: case WatchSize.DWord:
if (size == WatchSize.Byte) if (size == WatchSize.Byte)
{ {

View File

@ -162,25 +162,15 @@ namespace BizHawk.Client.Common
{ {
int before = _watchList.Count; int before = _watchList.Count;
switch (_compareTo) _watchList = _compareTo switch
{ {
default: Compare.Previous => ComparePrevious(_watchList).ToList(),
case Compare.Previous: Compare.SpecificValue => CompareSpecificValue(_watchList).ToList(),
_watchList = ComparePrevious(_watchList).ToList(); Compare.SpecificAddress => CompareSpecificAddress(_watchList).ToList(),
break; Compare.Changes => CompareChanges(_watchList).ToList(),
case Compare.SpecificValue: Compare.Difference => CompareDifference(_watchList).ToList(),
_watchList = CompareSpecificValue(_watchList).ToList(); _ => ComparePrevious(_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;
}
if (_settings.PreviousType == PreviousType.LastSearch) if (_settings.PreviousType == PreviousType.LastSearch)
{ {
@ -201,20 +191,15 @@ namespace BizHawk.Client.Common
? _watchList.BinarySearch(w => w.Address, address) ? _watchList.BinarySearch(w => w.Address, address)
: _watchList.FirstOrDefault(w => w.Address == address), 1); : _watchList.FirstOrDefault(w => w.Address == address), 1);
switch (_compareTo) return _compareTo switch
{ {
default: Compare.Previous => !ComparePrevious(listOfOne).Any(),
case Compare.Previous: Compare.SpecificValue => !CompareSpecificValue(listOfOne).Any(),
return !ComparePrevious(listOfOne).Any(); Compare.SpecificAddress => !CompareSpecificAddress(listOfOne).Any(),
case Compare.SpecificValue: Compare.Changes => !CompareChanges(listOfOne).Any(),
return !CompareSpecificValue(listOfOne).Any(); Compare.Difference => !CompareDifference(listOfOne).Any(),
case Compare.SpecificAddress: _ => !ComparePrevious(listOfOne).Any()
return !CompareSpecificAddress(listOfOne).Any(); };
case Compare.Changes:
return !CompareChanges(listOfOne).Any();
case Compare.Difference:
return !CompareDifference(listOfOne).Any();
}
} }
public int Count => _watchList.Count; public int Count => _watchList.Count;
@ -497,48 +482,28 @@ namespace BizHawk.Client.Common
{ {
default: default:
case ComparisonOperator.Equal: case ComparisonOperator.Equal:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(w.Previous))
return watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(w.Previous)); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(w.Previous));
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(w.Previous));
case ComparisonOperator.NotEqual: case ComparisonOperator.NotEqual:
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) != SignExtendAsNeeded(w.Previous)); return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) != SignExtendAsNeeded(w.Previous));
case ComparisonOperator.GreaterThan: case ComparisonOperator.GreaterThan:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(w.Previous))
return watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(w.Previous)); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > SignExtendAsNeeded(w.Previous));
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) > SignExtendAsNeeded(w.Previous));
case ComparisonOperator.GreaterThanEqual: case ComparisonOperator.GreaterThanEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(w.Previous))
return watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(w.Previous)); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= SignExtendAsNeeded(w.Previous));
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) >= SignExtendAsNeeded(w.Previous));
case ComparisonOperator.LessThan: case ComparisonOperator.LessThan:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(w.Previous))
return watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(w.Previous)); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < SignExtendAsNeeded(w.Previous));
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) < SignExtendAsNeeded(w.Previous));
case ComparisonOperator.LessThanEqual: case ComparisonOperator.LessThanEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(w.Previous))
return watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(w.Previous)); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= SignExtendAsNeeded(w.Previous));
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) <= SignExtendAsNeeded(w.Previous));
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy.HasValue) if (DifferentBy.HasValue)
{ {
@ -573,48 +538,31 @@ namespace BizHawk.Client.Common
{ {
default: default:
case ComparisonOperator.Equal: case ComparisonOperator.Equal:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(compareValue))
return watchList.Where(w => ToFloat(GetValue(w.Address)) == ToFloat(compareValue)); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(CompareValue.Value));
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) == SignExtendAsNeeded(CompareValue.Value));
case ComparisonOperator.NotEqual: case ComparisonOperator.NotEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) != ToFloat(compareValue))
return 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.GreaterThan: case ComparisonOperator.GreaterThan:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) > ToFloat(compareValue))
return 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.GreaterThanEqual: case ComparisonOperator.GreaterThanEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) >= ToFloat(compareValue))
return 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.LessThan: case ComparisonOperator.LessThan:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) < ToFloat(compareValue))
return 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: case ComparisonOperator.LessThanEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) <= ToFloat(compareValue))
return 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: case ComparisonOperator.DifferentBy:
if (DifferentBy.HasValue) if (DifferentBy.HasValue)
{ {
@ -735,47 +683,29 @@ namespace BizHawk.Client.Common
{ {
default: default:
case ComparisonOperator.Equal: case ComparisonOperator.Equal:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) - ToFloat(w.Previous) == compareValue)
return watchList.Where(w => ToFloat(GetValue(w.Address)) - ToFloat(w.Previous) == compareValue); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) == compareValue);
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) == compareValue);
case ComparisonOperator.NotEqual: case ComparisonOperator.NotEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous != compareValue)
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous != compareValue); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) != compareValue);
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) != compareValue);
case ComparisonOperator.GreaterThan: case ComparisonOperator.GreaterThan:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous > compareValue)
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous > compareValue); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) > compareValue);
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) > compareValue);
case ComparisonOperator.GreaterThanEqual: case ComparisonOperator.GreaterThanEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous >= compareValue)
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous >= compareValue); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) >= compareValue);
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) >= compareValue);
case ComparisonOperator.LessThan: case ComparisonOperator.LessThan:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous < compareValue)
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous < compareValue); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) < compareValue);
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) < compareValue);
case ComparisonOperator.LessThanEqual: case ComparisonOperator.LessThanEqual:
if (_settings.Type == DisplayType.Float) return _settings.Type == DisplayType.Float
{ ? watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous <= compareValue)
return watchList.Where(w => ToFloat(GetValue(w.Address)) - w.Previous <= compareValue); : watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) <= compareValue);
}
return watchList.Where(w => SignExtendAsNeeded(GetValue(w.Address)) - SignExtendAsNeeded(w.Previous) <= compareValue);
case ComparisonOperator.DifferentBy: case ComparisonOperator.DifferentBy:
if (DifferentBy.HasValue) if (DifferentBy.HasValue)
{ {
@ -802,7 +732,7 @@ namespace BizHawk.Client.Common
#region Private parts #region Private parts
private float ToFloat(long val) private static float ToFloat(long val)
{ {
var bytes = BitConverter.GetBytes((int)val); var bytes = BitConverter.GetBytes((int)val);
return BitConverter.ToSingle(bytes, 0); return BitConverter.ToSingle(bytes, 0);
@ -815,48 +745,35 @@ namespace BizHawk.Client.Common
return val; return val;
} }
switch (_settings.Size) return _settings.Size switch
{ {
default: WatchSize.Byte => (sbyte) val,
case WatchSize.Byte: WatchSize.Word => (short) val,
return (sbyte)val; WatchSize.DWord => (int) val,
case WatchSize.Word: _ => (sbyte) val
return (short)val; };
case WatchSize.DWord:
return (int)val;
}
} }
private long GetValue(long addr) private long GetValue(long addr)
{ {
// do not return sign extended variables from here. // do not return sign extended variables from here.
switch (_settings.Size) return _settings.Size switch
{ {
default: WatchSize.Byte => _settings.Domain.PeekByte(addr % Domain.Size),
case WatchSize.Byte: WatchSize.Word => _settings.Domain.PeekUshort(addr % Domain.Size, _settings.BigEndian),
var theByte = _settings.Domain.PeekByte(addr % Domain.Size); WatchSize.DWord => _settings.Domain.PeekUint(addr % Domain.Size, _settings.BigEndian),
return theByte; _ => _settings.Domain.PeekByte(addr % Domain.Size)
};
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;
}
} }
private bool CanDoCompareType(Compare compareType) private bool CanDoCompareType(Compare compareType)
{ {
switch (_settings.Mode) return _settings.Mode switch
{ {
default: Settings.SearchMode.Detailed => true,
case Settings.SearchMode.Detailed: Settings.SearchMode.Fast => (compareType != Compare.Changes),
return true; _ => true
case Settings.SearchMode.Fast: };
return compareType != Compare.Changes;
}
} }
#endregion #endregion

View File

@ -181,18 +181,14 @@ namespace BizHawk.Client.Common
// TODO: Implements IFormattable // TODO: Implements IFormattable
public string FormatValue(byte val) public string FormatValue(byte val)
{ {
switch (Type) return Type switch
{ {
default: DisplayType.Unsigned => val.ToString(),
case DisplayType.Unsigned: DisplayType.Signed => ((sbyte) val).ToString(),
return val.ToString(); DisplayType.Hex => $"{val:X2}",
case DisplayType.Signed: DisplayType.Binary => Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " "),
return ((sbyte)val).ToString(); _ => val.ToString()
case DisplayType.Hex: };
return $"{val:X2}";
case DisplayType.Binary:
return Convert.ToString(val, 2).PadLeft(8, '0').Insert(4, " ");
}
} }
/// <summary> /// <summary>

View File

@ -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> /// <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) protected Watch(MemoryDomain domain, long address, WatchSize size, DisplayType type, bool bigEndian, string note)
{ {
if (IsDiplayTypeAvailable(type)) if (IsDisplayTypeAvailable(type))
{ {
_domain = domain; _domain = domain;
Address = address; Address = address;
@ -136,18 +136,14 @@ namespace BizHawk.Client.Common
/// <returns>New <see cref="Watch"/> instance. True type is depending of size parameter</returns> /// <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) 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: WatchSize.Separator => SeparatorWatch.NewSeparatorWatch(note),
case WatchSize.Separator: WatchSize.Byte => new ByteWatch(domain, address, type, bigEndian, note, (byte) value, (byte) prev, changeCount),
return SeparatorWatch.NewSeparatorWatch(note); WatchSize.Word => new WordWatch(domain, address, type, bigEndian, note, (ushort) value, (ushort) prev, changeCount),
case WatchSize.Byte: WatchSize.DWord => new DWordWatch(domain, address, type, bigEndian, note, (uint) value, (uint) prev, changeCount),
return new ByteWatch(domain, address, type, bigEndian, note, (byte)value, (byte)prev, changeCount); _ => SeparatorWatch.NewSeparatorWatch(note)
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);
}
} }
#region Operators #region Operators
@ -455,14 +451,14 @@ namespace BizHawk.Client.Common
/// <returns>True if both object are equals; otherwise, false</returns> /// <returns>True if both object are equals; otherwise, false</returns>
public override bool Equals(object obj) 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); return base.Equals(obj);
@ -482,7 +478,7 @@ namespace BizHawk.Client.Common
/// used for the current <see cref="Watch"/> /// used for the current <see cref="Watch"/>
/// </summary> /// </summary>
/// <param name="type"><see cref="DisplayType"/> you want to check</param> /// <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); 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 /// It's used by the "Display on screen" option in the RamWatch window
/// </summary> /// </summary>
/// <returns>A well formatted string representation</returns> /// <returns>A well formatted string representation</returns>
public virtual string ToDisplayString() public virtual string ToDisplayString() => $"{Notes}: {ValueString}";
{
return $"{Notes}: {ValueString}";
}
#endregion #endregion
@ -565,18 +558,9 @@ namespace BizHawk.Client.Common
/// </summary> /// </summary>
public long Address { get; } public long Address { get; }
private string AddressFormatStr private string AddressFormatStr => _domain != null
{ ? $"X{(_domain.Size - 1).NumHexDigits()}"
get : "";
{
if (_domain != null)
{
return $"X{(_domain.Size - 1).NumHexDigits()}";
}
return "";
}
}
/// <summary> /// <summary>
/// Gets the address in the <see cref="MemoryDomain"/> formatted as string /// Gets the address in the <see cref="MemoryDomain"/> formatted as string
@ -603,7 +587,7 @@ namespace BizHawk.Client.Common
get => _type; get => _type;
set set
{ {
if (IsDiplayTypeAvailable(value)) if (IsDisplayTypeAvailable(value))
{ {
_type = value; _type = value;
} }
@ -658,122 +642,88 @@ namespace BizHawk.Client.Common
// TODO: Replace all the following stuff by implementing ISerializable // TODO: Replace all the following stuff by implementing ISerializable
public static string DisplayTypeToString(DisplayType type) public static string DisplayTypeToString(DisplayType type)
{ {
switch (type) return type switch
{ {
default: DisplayType.FixedPoint_12_4 => "Fixed Point 12.4",
return type.ToString(); DisplayType.FixedPoint_20_12 => "Fixed Point 20.12",
case DisplayType.FixedPoint_12_4: DisplayType.FixedPoint_16_16 => "Fixed Point 16.16",
return "Fixed Point 12.4"; _ => type.ToString()
case DisplayType.FixedPoint_20_12: };
return "Fixed Point 20.12";
case DisplayType.FixedPoint_16_16:
return "Fixed Point 16.16";
}
} }
public static DisplayType StringToDisplayType(string name) public static DisplayType StringToDisplayType(string name)
{ {
switch (name) return name switch
{ {
default: "Fixed Point 12.4" => DisplayType.FixedPoint_12_4,
return (DisplayType)Enum.Parse(typeof(DisplayType), name); "Fixed Point 20.12" => DisplayType.FixedPoint_20_12,
case "Fixed Point 12.4": "Fixed Point 16.16" => DisplayType.FixedPoint_16_16,
return DisplayType.FixedPoint_12_4; _ => (DisplayType) Enum.Parse(typeof(DisplayType), name)
case "Fixed Point 20.12": };
return DisplayType.FixedPoint_20_12;
case "Fixed Point 16.16":
return DisplayType.FixedPoint_16_16;
}
} }
public char SizeAsChar public char SizeAsChar
{ {
get get
{ {
switch (Size) return Size switch
{ {
default: WatchSize.Separator => 'S',
case WatchSize.Separator: WatchSize.Byte => 'b',
return 'S'; WatchSize.Word => 'w',
case WatchSize.Byte: WatchSize.DWord => 'd',
return 'b'; _ => 'S'
case WatchSize.Word: };
return 'w';
case WatchSize.DWord:
return 'd';
}
} }
} }
public static WatchSize SizeFromChar(char c) public static WatchSize SizeFromChar(char c)
{ {
switch (c) return c switch
{ {
default: 'S' => WatchSize.Separator,
case 'S': 'b' => WatchSize.Byte,
return WatchSize.Separator; 'w' => WatchSize.Word,
case 'b': 'd' => WatchSize.DWord,
return WatchSize.Byte; _ => WatchSize.Separator
case 'w': };
return WatchSize.Word;
case 'd':
return WatchSize.DWord;
}
} }
public char TypeAsChar public char TypeAsChar
{ {
get get
{ {
switch (Type) return Type switch
{ {
default: DisplayType.Separator => '_',
case DisplayType.Separator: DisplayType.Unsigned => 'u',
return '_'; DisplayType.Signed => 's',
case DisplayType.Unsigned: DisplayType.Hex => 'h',
return 'u'; DisplayType.Binary => 'b',
case DisplayType.Signed: DisplayType.FixedPoint_12_4 => '1',
return 's'; DisplayType.FixedPoint_20_12 => '2',
case DisplayType.Hex: DisplayType.FixedPoint_16_16 => '3',
return 'h'; DisplayType.Float => 'f',
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';
}
} }
} }
public static DisplayType DisplayTypeFromChar(char c) public static DisplayType DisplayTypeFromChar(char c)
{ {
switch (c) return c switch
{ {
default: '_' => DisplayType.Separator,
case '_': 'u' => DisplayType.Unsigned,
return DisplayType.Separator; 's' => DisplayType.Signed,
case 'u': 'h' => DisplayType.Hex,
return DisplayType.Unsigned; 'b' => DisplayType.Binary,
case 's': '1' => DisplayType.FixedPoint_12_4,
return DisplayType.Signed; '2' => DisplayType.FixedPoint_20_12,
case 'h': '3' => DisplayType.FixedPoint_16_16,
return DisplayType.Hex; 'f' => DisplayType.Float,
case 'b': _ => DisplayType.Separator
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;
}
} }
} }
} }

View File

@ -20,12 +20,7 @@ namespace BizHawk.Client.Common
{ {
if (ReferenceEquals(x, null)) if (ReferenceEquals(x, null))
{ {
if (ReferenceEquals(y, null)) return ReferenceEquals(y, null);
{
return true;
}
return false;
} }
if (ReferenceEquals(y, null)) if (ReferenceEquals(y, null))
@ -33,12 +28,7 @@ namespace BizHawk.Client.Common
return false; return false;
} }
if (ReferenceEquals(x, y)) return ReferenceEquals(x, y);
{
return true;
}
return false;
} }
/// <summary> /// <summary>
@ -46,10 +36,7 @@ namespace BizHawk.Client.Common
/// </summary> /// </summary>
/// <param name="obj">Watch to get hash</param> /// <param name="obj">Watch to get hash</param>
/// <returns>int that can serves as a unique representation of current Watch</returns> /// <returns>int that can serves as a unique representation of current Watch</returns>
public int GetHashCode(Watch obj) public int GetHashCode(Watch obj) => obj.GetHashCode();
{
return obj.GetHashCode();
}
} }
} }
} }

View File

@ -55,10 +55,7 @@ namespace BizHawk.Client.Common
/// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="WordWatch"/> /// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="WordWatch"/>
/// </summary> /// </summary>
/// <returns>An enumeration that contains all valid <see cref="DisplayType"/></returns> /// <returns>An enumeration that contains all valid <see cref="DisplayType"/></returns>
public override IEnumerable<DisplayType> AvailableTypes() public override IEnumerable<DisplayType> AvailableTypes() => ValidTypes;
{
return ValidTypes;
}
/// <summary> /// <summary>
/// Reset the previous value; set it to the current one /// Reset the previous value; set it to the current one
@ -193,20 +190,19 @@ namespace BizHawk.Client.Common
// TODO: Implements IFormattable // TODO: Implements IFormattable
public string FormatValue(ushort val) public string FormatValue(ushort val)
{ {
switch (Type) return Type switch
{ {
default: DisplayType.Unsigned => val.ToString(),
case DisplayType.Unsigned: DisplayType.Signed => ((short) val).ToString(), DisplayType.Hex => $"{val:X4}",
return val.ToString(); DisplayType.FixedPoint_12_4 => $"{val / 16.0:F4}",
case DisplayType.Signed: DisplayType.Binary => Convert
return ((short)val).ToString(); .ToString(val, 2)
case DisplayType.Hex: .PadLeft(16, '0')
return $"{val:X4}"; .Insert(8, " ")
case DisplayType.FixedPoint_12_4: .Insert(4, " ")
return $"{val / 16.0:F4}"; .Insert(14, " "),
case DisplayType.Binary: _ => val.ToString()
return Convert.ToString(val, 2).PadLeft(16, '0').Insert(8, " ").Insert(4, " ").Insert(14, " "); };
}
} }
/// <summary> /// <summary>

View File

@ -341,6 +341,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=inrate/@EntryIndexedValue">True</s:Boolean> <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/=ints/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=INTV/@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/=Joypad/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=jumplist/@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> <s:Boolean x:Key="/Default/UserDictionary/Words/=Justifier/@EntryIndexedValue">True</s:Boolean>