diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs index 56e271f6cf..80d0a335ea 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; + using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; @@ -8,27 +8,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink { public partial class GBHawkLink : IDebuggable { + private const string PFX_L = "Left "; + + private const string PFX_R = "Right "; + public IDictionary GetCpuFlagsAndRegisters() { - var left = L.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("Left " + reg.Key, reg.Value)); - - var right = R.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("Right " + reg.Key, reg.Value)); - - return left.Union(right).ToDictionary(pair => pair.Key, pair => pair.Value); + Dictionary dict = new(); + foreach (var ref in L.GetCpuFlagsAndRegisters()) dict[PFX_L + reg.Key] = reg.Value; + foreach (var ref in R.GetCpuFlagsAndRegisters()) dict[PFX_R + reg.Key] = reg.Value; + return dict; } public void SetCpuRegister(string register, int value) { - if (register.StartsWithOrdinal("Left ")) - { - L.SetCpuRegister(register.Replace("Left ", ""), value); - } - else if (register.StartsWithOrdinal("Right ")) - { - R.SetCpuRegister(register.Replace("Right ", ""), value); - } + if (register.StartsWithOrdinal(PFX_L)) L.SetCpuRegister(register.Substring(PFX_L.Length), value); + else if (register.StartsWithOrdinal(PFX_R)) R.SetCpuRegister(register.Substring(PFX_R.Length), value); } public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs index e4e6efbbec..7ac2bdf049 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; + using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; @@ -8,34 +8,26 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x { public partial class GBHawkLink3x : IDebuggable { + private const string PFX_C = "Center "; + + private const string PFX_L = "Left "; + + private const string PFX_R = "Right "; + public IDictionary GetCpuFlagsAndRegisters() { - var left = L.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("Left " + reg.Key, reg.Value)); - - var center = C.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("Center " + reg.Key, reg.Value)); - - var right = R.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("Right " + reg.Key, reg.Value)); - - return left.Union(center).Union(right).ToDictionary(pair => pair.Key, pair => pair.Value); + Dictionary dict = new(); + foreach (var ref in L.GetCpuFlagsAndRegisters()) dict[PFX_L + reg.Key] = reg.Value; + foreach (var ref in C.GetCpuFlagsAndRegisters()) dict[PFX_C + reg.Key] = reg.Value; + foreach (var ref in R.GetCpuFlagsAndRegisters()) dict[PFX_R + reg.Key] = reg.Value; + return dict; } public void SetCpuRegister(string register, int value) { - if (register.StartsWithOrdinal("Left ")) - { - L.SetCpuRegister(register.Replace("Left ", ""), value); - } - else if (register.StartsWithOrdinal("Center ")) - { - C.SetCpuRegister(register.Replace("Center ", ""), value); - } - else if (register.StartsWithOrdinal("Right ")) - { - R.SetCpuRegister(register.Replace("Right ", ""), value); - } + if (register.StartsWithOrdinal(PFX_C)) C.SetCpuRegister(register.Substring(PFX_C.Length), value); + else if (register.StartsWithOrdinal(PFX_L)) L.SetCpuRegister(register.Substring(PFX_L.Length), value); + else if (register.StartsWithOrdinal(PFX_R)) R.SetCpuRegister(register.Substring(PFX_R.Length), value); } public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs index eacf34597b..bd093f37fa 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; + using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; @@ -8,41 +8,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x { public partial class GBHawkLink4x : IDebuggable { + private const string PFX_A = "A "; + + private const string PFX_B = "B "; + + private const string PFX_C = "C "; + + private const string PFX_D = "D "; + public IDictionary GetCpuFlagsAndRegisters() { - var a = A.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("A " + reg.Key, reg.Value)); - - var b = B.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("B " + reg.Key, reg.Value)); - - var c = C.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("C " + reg.Key, reg.Value)); - - var d = D.GetCpuFlagsAndRegisters() - .Select(reg => new KeyValuePair("D " + reg.Key, reg.Value)); - - return a.Union(b).Union(c).Union(d).ToDictionary(pair => pair.Key, pair => pair.Value); + Dictionary dict = new(); + foreach (var ref in A.GetCpuFlagsAndRegisters()) dict[PFX_A + reg.Key] = reg.Value; + foreach (var ref in B.GetCpuFlagsAndRegisters()) dict[PFX_B + reg.Key] = reg.Value; + foreach (var ref in C.GetCpuFlagsAndRegisters()) dict[PFX_C + reg.Key] = reg.Value; + foreach (var ref in D.GetCpuFlagsAndRegisters()) dict[PFX_D + reg.Key] = reg.Value; + return dict; } public void SetCpuRegister(string register, int value) { - if (register.StartsWithOrdinal("A ")) - { - A.SetCpuRegister(register.Replace("A ", ""), value); - } - else if (register.StartsWithOrdinal("B ")) - { - B.SetCpuRegister(register.Replace("B ", ""), value); - } - else if (register.StartsWithOrdinal("C ")) - { - C.SetCpuRegister(register.Replace("C ", ""), value); - } - else if (register.StartsWithOrdinal("D ")) - { - D.SetCpuRegister(register.Replace("D ", ""), value); - } + if (register.StartsWithOrdinal(PFX_A)) A.SetCpuRegister(register.Substring(PFX_A.Length), value); + else if (register.StartsWithOrdinal(PFX_B)) B.SetCpuRegister(register.Substring(PFX_B.Length), value); + else if (register.StartsWithOrdinal(PFX_C)) C.SetCpuRegister(register.Substring(PFX_C.Length), value); + else if (register.StartsWithOrdinal(PFX_D)) D.SetCpuRegister(register.Substring(PFX_D.Length), value); } public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" });