Misc. refactors, reverting some code style "fixes"

This commit is contained in:
YoshiRulz 2024-05-30 06:51:36 +10:00
parent ea15126fe1
commit 01bea49ee0
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
26 changed files with 53 additions and 77 deletions

View File

@ -6,6 +6,7 @@ using System.Windows.Forms;
using BizHawk.Bizware.Graphics; using BizHawk.Bizware.Graphics;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
@ -50,13 +51,9 @@ namespace BizHawk.Client.EmuHawk
string framesDir = ""; string framesDir = "";
foreach (var line in lines) foreach (var line in lines)
{ {
int idx = line.IndexOf('='); const string KEY = "framesdir=";
string key = line[..idx]; if (line.StartsWithOrdinal(KEY)) framesDir = line.Substring(startIndex: KEY.Length);
string value = line[(idx + 1)..]; // and continue
if (key == "framesdir")
{
framesDir = value;
}
} }
_mFramesDirectory = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(_mSynclessConfigFile)), framesDir); _mFramesDirectory = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(_mSynclessConfigFile)), framesDir);

View File

@ -136,7 +136,7 @@ namespace BizHawk.Client.EmuHawk
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
string errMsg = ex.Message; string errMsg = ex.Message;
errMsg = errMsg[(errMsg.IndexOf('-') + 2)..]; errMsg = errMsg.Substring(startIndex: errMsg.IndexOf('-') + 2);
// Balloon is bugged on first invocation // Balloon is bugged on first invocation
_errorBalloon.Show($"Error parsing RegEx: {errMsg}", tb); _errorBalloon.Show($"Error parsing RegEx: {errMsg}", tb);

View File

@ -27,7 +27,9 @@ namespace BizHawk.Client.EmuHawk
private readonly HashSet<Control> _wantingMouseFocus = new HashSet<Control>(); private readonly HashSet<Control> _wantingMouseFocus = new HashSet<Control>();
public static Input Instance { get; set; } #pragma warning disable CA2211 // public field
public static Input Instance;
#pragma warning restore CA2211
private readonly Thread _updateThread; private readonly Thread _updateThread;

View File

@ -124,7 +124,7 @@ namespace BizHawk.Client.EmuHawk
// end of the path has ; // end of the path has ;
var end = exePath.IndexOf(';'); var end = exePath.IndexOf(';');
if (end < 0) break; if (end < 0) break;
exePath = exePath[index..end]; exePath = exePath.Substring(startIndex: index, length: end - index);
} }
buffer.AddRange(Encoding.ASCII.GetBytes(exePath)); buffer.AddRange(Encoding.ASCII.GetBytes(exePath));

View File

@ -184,7 +184,7 @@ namespace BizHawk.Client.EmuHawk
lvFirmwares.Groups.Add( lvFirmwares.Groups.Add(
key: sysID, key: sysID,
headerText: SystemGroupNames.TryGetValue(sysID, out var name) ? name : "FIX ME (FirmwaresConfig.cs)"); headerText: SystemGroupNames.TryGetValue(sysID, out var name) ? name : "FIX ME (FirmwaresConfig.cs)");
return lvFirmwares.Groups[^1]; return lvFirmwares.Groups[lvFirmwares.Groups.Count - 1];
} }
// we'll use this font for displaying the hash, so they don't look all jagged in a long list // we'll use this font for displaying the hash, so they don't look all jagged in a long list

View File

@ -192,7 +192,9 @@ namespace BizHawk.Client.EmuHawk
try try
{ {
lines.Add(line[..i], int.Parse(line[(i + 1)..])); lines.Add(
line.Substring(startIndex: 0, length: i),
int.Parse(line.Substring(startIndex: i + 1)));
} }
catch (FormatException) catch (FormatException)
{ {

View File

@ -162,7 +162,9 @@ namespace BizHawk.Client.EmuHawk
try try
{ {
lines.Add(line[..i], int.Parse(line[(i + 1)..])); lines.Add(
line.Substring(startIndex: 0, length: i),
int.Parse(line.Substring(startIndex: i + 1)));
} }
catch (FormatException) catch (FormatException)
{ {

View File

@ -23,7 +23,7 @@ namespace BizHawk.Client.EmuHawk.ForDebugging
public FirmwareAutopatchDebugToolForm() public FirmwareAutopatchDebugToolForm()
{ {
static string LabelFragment(string hash) static string LabelFragment(string hash)
=> $"{hash[..8]}... {FirmwareDatabase.FirmwareFilesByHash[hash].RecommendedName}"; => $"{hash.Substring(startIndex: 0, length: 8)}... {FirmwareDatabase.FirmwareFilesByHash[hash].RecommendedName}";
List<(string Label, FirmwarePatchOption PatchOption)> patches = FirmwareDatabase.AllPatches List<(string Label, FirmwarePatchOption PatchOption)> patches = FirmwareDatabase.AllPatches
.Select(static fpo => ($"{LabelFragment(fpo.BaseHash)} --> {LabelFragment(fpo.TargetHash)}", fpo)).ToList(); .Select(static fpo => ($"{LabelFragment(fpo.BaseHash)} --> {LabelFragment(fpo.TargetHash)}", fpo)).ToList();
patches.Sort(static (a, b) => string.CompareOrdinal(a.Label, b.Label)); patches.Sort(static (a, b) => string.CompareOrdinal(a.Label, b.Label));

View File

@ -451,7 +451,7 @@ namespace BizHawk.Client.EmuHawk
{ {
var indices = SelectedIndices.ToList(); var indices = SelectedIndices.ToList();
if (indices.Count == 0 if (indices.Count == 0
|| indices[^1] == MainForm.CheatList.Count - 1) // at end already || indices[indices.Count - 1] == MainForm.CheatList.Count - 1) // at end already
{ {
return; return;
} }

View File

@ -1395,10 +1395,7 @@ namespace BizHawk.Client.EmuHawk
} }
// and add HighlightedAddress if present // and add HighlightedAddress if present
if (_highlightedAddress.HasValue) if (_highlightedAddress is long l) addresses[addresses.Length - 1] = l;
{
addresses[^1] = _highlightedAddress.Value;
}
// these need to be sorted. it's not just for HighlightedAddress, _secondaryHighlightedAddresses can even be jumbled // these need to be sorted. it's not just for HighlightedAddress, _secondaryHighlightedAddresses can even be jumbled
Array.Sort(addresses); Array.Sort(addresses);

View File

@ -386,7 +386,7 @@ namespace BizHawk.Client.EmuHawk
{ {
while (LuaImp.ScriptList.Count > 0) while (LuaImp.ScriptList.Count > 0)
{ {
RemoveLuaFile(LuaImp.ScriptList[^1]); RemoveLuaFile(LuaImp.ScriptList[LuaImp.ScriptList.Count - 1]);
} }
} }
@ -1028,7 +1028,7 @@ namespace BizHawk.Client.EmuHawk
{ {
var indices = LuaListView.SelectedRows.ToList(); var indices = LuaListView.SelectedRows.ToList();
if (indices.Count == 0 if (indices.Count == 0
|| indices[^1] == LuaImp.ScriptList.Count - 1) // at end already || indices[indices.Count - 1] == LuaImp.ScriptList.Count - 1) // at end already
{ {
return; return;
} }
@ -1333,7 +1333,7 @@ namespace BizHawk.Client.EmuHawk
var split = words[0].Split(Path.DirectorySeparatorChar); var split = words[0].Split(Path.DirectorySeparatorChar);
luaListTemp.Add(LuaImp.ScriptList[i]); luaListTemp.Add(LuaImp.ScriptList[i]);
luaListTemp[i].Name = split[^1]; luaListTemp[i].Name = split[split.Length - 1];
} }
// Script, Path // Script, Path

View File

@ -58,10 +58,7 @@ namespace BizHawk.Client.EmuHawk
key = key.Replace($"{box.Text}|", ""); key = key.Replace($"{box.Text}|", "");
} }
} }
SelectedZone.InputKey = key.Substring(startIndex: 0, length: key.Length - 1); // drop final char
key = key[..^1];
SelectedZone.InputKey = key;
} }
private void PositionBoxes() private void PositionBoxes()

View File

@ -28,7 +28,7 @@ namespace BizHawk.Client.EmuHawk
} }
key = key.Replace("LogKey:", "").Replace("#", ""); key = key.Replace("LogKey:", "").Replace("#", "");
key = key[..^1]; key = key.Substring(startIndex: 0, length: key.Length - 1); // drop last char
_inputKey = key; _inputKey = key;
Length = length; Length = length;
@ -41,7 +41,7 @@ namespace BizHawk.Client.EmuHawk
logGenerator.GenerateLogEntry(); // Reference and create all buttons. logGenerator.GenerateLogEntry(); // Reference and create all buttons.
string movieKey = logGenerator.GenerateLogKey().Replace("LogKey:", "").Replace("#", ""); string movieKey = logGenerator.GenerateLogKey().Replace("LogKey:", "").Replace("#", "");
movieKey = movieKey[..^1]; movieKey = movieKey.Substring(startIndex: 0, length: movieKey.Length - 1); // drop last char
if (key == movieKey) if (key == movieKey)
{ {
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
@ -239,7 +239,7 @@ namespace BizHawk.Client.EmuHawk
var lg = _movieSession.Movie.LogGeneratorInstance(_movieSession.MovieController); var lg = _movieSession.Movie.LogGeneratorInstance(_movieSession.MovieController);
string key = lg.GenerateLogKey(); string key = lg.GenerateLogKey();
key = key.Replace("LogKey:", "").Replace("#", ""); key = key.Replace("LogKey:", "").Replace("#", "");
key = key[..^1]; key = key.Substring(startIndex: 0, length: key.Length - 1); // drop last char
string[] emuKeys = key.Split('|'); string[] emuKeys = key.Split('|');
string[] macroKeys = _inputKey.Split('|'); string[] macroKeys = _inputKey.Split('|');
foreach (var macro in macroKeys) foreach (var macro in macroKeys)

View File

@ -302,7 +302,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (p[i] == lastValue) if (p[i] == lastValue)
{ {
_counts[^1]++; _counts[_counts.Count - 1]++;
} }
else else
{ {
@ -335,7 +335,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (p[i] == lastValue) if (p[i] == lastValue)
{ {
_counts[^1]++; _counts[_counts.Count - 1]++;
} }
else else
{ {

View File

@ -1313,7 +1313,7 @@ namespace BizHawk.Client.EmuHawk
else if (e.KeyCode == Keys.OemMinus || e.KeyCode == Keys.Subtract) else if (e.KeyCode == Keys.OemMinus || e.KeyCode == Keys.Subtract)
{ {
_axisTypedValue = _axisTypedValue.StartsWith('-') _axisTypedValue = _axisTypedValue.StartsWith('-')
? _axisTypedValue[1..] ? _axisTypedValue.Substring(startIndex: 1)
: $"-{_axisTypedValue}"; : $"-{_axisTypedValue}";
} }
else if (e.KeyCode == Keys.Back) else if (e.KeyCode == Keys.Back)
@ -1323,7 +1323,7 @@ namespace BizHawk.Client.EmuHawk
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo); _axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
} }
_axisTypedValue = _axisTypedValue[..^1]; _axisTypedValue = _axisTypedValue.Substring(startIndex: 0, length: _axisTypedValue.Length - 1); // drop last char
if (_axisTypedValue == "" || _axisTypedValue == "-") if (_axisTypedValue == "" || _axisTypedValue == "-")
{ {
value = 0f; value = 0f;

View File

@ -468,7 +468,7 @@ namespace BizHawk.Client.EmuHawk
{ {
_tasClipboard.Clear(); _tasClipboard.Clear();
int linesToPaste = lines.Length; int linesToPaste = lines.Length;
if (lines[^1] == "") linesToPaste--; if (lines[lines.Length - 1].Length is 0) linesToPaste--;
for (int i = 0; i < linesToPaste; i++) for (int i = 0; i < linesToPaste; i++)
{ {
var line = ControllerFromMnemonicStr(lines[i]); var line = ControllerFromMnemonicStr(lines[i]);
@ -510,7 +510,7 @@ namespace BizHawk.Client.EmuHawk
{ {
_tasClipboard.Clear(); _tasClipboard.Clear();
int linesToPaste = lines.Length; int linesToPaste = lines.Length;
if (lines[^1] == "") linesToPaste--; if (lines[lines.Length - 1].Length is 0) linesToPaste--;
for (int i = 0; i < linesToPaste; i++) for (int i = 0; i < linesToPaste; i++)
{ {
var line = ControllerFromMnemonicStr(lines[i]); var line = ControllerFromMnemonicStr(lines[i]);

View File

@ -449,17 +449,16 @@ namespace BizHawk.Client.EmuHawk
BoolPatterns[i] = new AutoPatternBool(1, 1); BoolPatterns[i] = new AutoPatternBool(1, 1);
} }
BoolPatterns[^2] = new AutoPatternBool(1, 0); BoolPatterns[BoolPatterns.Length - 2] = new(1, 0);
BoolPatterns[^1] = new AutoPatternBool( BoolPatterns[BoolPatterns.Length - 1] = new(Config.AutofireOn, Config.AutofireOff);
Config.AutofireOn, Config.AutofireOff);
for (int i = fStart; i < AxisPatterns.Length - 2; i++) for (int i = fStart; i < AxisPatterns.Length - 2; i++)
{ {
AxisPatterns[i] = new AutoPatternAxis(new[] { 1 }); AxisPatterns[i] = new AutoPatternAxis(new[] { 1 });
} }
AxisPatterns[^2] = new AutoPatternAxis(new[] { 1 }); AxisPatterns[AxisPatterns.Length - 2] = new([ 1 ]);
AxisPatterns[^1] = new AutoPatternAxis(1, Config.AutofireOn, 0, Config.AutofireOff); AxisPatterns[AxisPatterns.Length - 1] = new(1, Config.AutofireOn, 0, Config.AutofireOff);
SetUpToolStripColumns(); SetUpToolStripColumns();
} }

View File

@ -928,7 +928,7 @@ namespace BizHawk.Client.EmuHawk
{ {
var indices = SelectedIndices.ToList(); var indices = SelectedIndices.ToList();
if (indices.Count == 0 if (indices.Count == 0
|| indices[^1] == _watches.Count - 1) // at end already || indices[indices.Count - 1] == _watches.Count - 1) // at end already
{ {
return; return;
} }

View File

@ -39,7 +39,9 @@ namespace BizHawk.Common
} }
// -------------- Logging Action Configuration -------------- // -------------- Logging Action Configuration --------------
public static readonly Action<string> LogAction = DefaultLogger; #pragma warning disable CA2211 // public field
public static Action<string> LogAction = DefaultLogger;
#pragma warning restore CA2211
// NOTEs are only logged if the domain is enabled. // NOTEs are only logged if the domain is enabled.
// ERRORs are logged regardless. // ERRORs are logged regardless.

View File

@ -24,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
{ {
string dis = DisassembleExt( string dis = DisassembleExt(
0, 0,
out int unused, out _,
addr => md.PeekByte(addr + i), addr => md.PeekByte(addr + i),
addr => md.PeekUshort(addr + i, bigEndian: false)); addr => md.PeekUshort(addr + i, bigEndian: false));
w.WriteLine("0x{0:x8}: {1}", i, dis); w.WriteLine("0x{0:x8}: {1}", i, dis);

View File

@ -100,9 +100,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
offsets.Add((int)trackMem.Length); offsets.Add((int)trackMem.Length);
densities.Add(trackDensities[trackIndex]); densities.Add(trackDensities[trackIndex]);
var data = trackData[trackIndex];
var buffer = Enumerable.Repeat(dataFillerValue, trackMaxLength).ToArray(); var buffer = Enumerable.Repeat(dataFillerValue, trackMaxLength).ToArray();
var dataBytes = data.Select(d => unchecked(d)).ToArray(); var dataBytes = trackData[trackIndex];
Array.Copy(dataBytes, buffer, dataBytes.Length); Array.Copy(dataBytes, buffer, dataBytes.Length);
trackMemWriter.Write((ushort)dataBytes.Length); trackMemWriter.Write((ushort)dataBytes.Length);
trackMemWriter.Write(buffer); trackMemWriter.Write(buffer);

View File

@ -46,9 +46,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte // if this is detected just return the kempston byte
if (lowByte == 0x1f) if (lowByte == 0x1f)
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null) //TODO lines swapped?
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine; if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
InputRead = true; InputRead = true;
} }
else else

View File

@ -46,14 +46,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte // if this is detected just return the kempston byte
if (lowByte == 0x1f) if (lowByte == 0x1f)
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null) InputRead = true;
{ if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
InputRead = true; }
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
InputRead = true;
}
else else
{ {
if (KeyboardDevice.ReadPort(port, ref result)) if (KeyboardDevice.ReadPort(port, ref result))

View File

@ -27,14 +27,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte // if this is detected just return the kempston byte
if (lowByte == 0x1f) if (lowByte == 0x1f)
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null) InputRead = true;
{ if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
InputRead = true; }
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
InputRead = true;
}
else else
{ {
if (KeyboardDevice.ReadPort(port, ref result)) if (KeyboardDevice.ReadPort(port, ref result))

View File

@ -27,13 +27,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte // if this is detected just return the kempston byte
if (lowByte == 0x1f) if (lowByte == 0x1f)
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null) InputRead = true;
{ if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
InputRead = true;
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
InputRead = true;
} }
else if (UPDDiskDevice.ReadPort(port, ref result)) else if (UPDDiskDevice.ReadPort(port, ref result))
{ {

View File

@ -22,14 +22,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte // if this is detected just return the kempston byte
if (lowByte == 0x1f) if (lowByte == 0x1f)
{ {
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
{
InputRead = true;
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
// not a lag frame // not a lag frame
InputRead = true; InputRead = true;
if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
} }
// Even ports always address the ULA // Even ports always address the ULA
else if (lowBitReset) else if (lowBitReset)