Clean up `IDebuggable` impl. for GBHawkLink{,3x,4x}

This commit is contained in:
James Groom 2023-11-18 03:37:17 +10:00 committed by GitHub
parent b36f4aa4ef
commit ed5a708f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 69 deletions

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.StringExtensions; using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -8,27 +8,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
{ {
public partial class GBHawkLink : IDebuggable public partial class GBHawkLink : IDebuggable
{ {
private const string PFX_L = "Left ";
private const string PFX_R = "Right ";
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters() public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
{ {
var left = L.GetCpuFlagsAndRegisters() Dictionary<string, RegisterValue> dict = new();
.Select(reg => new KeyValuePair<string, RegisterValue>("Left " + reg.Key, reg.Value)); 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;
var right = R.GetCpuFlagsAndRegisters() return dict;
.Select(reg => new KeyValuePair<string, RegisterValue>("Right " + reg.Key, reg.Value));
return left.Union(right).ToDictionary(pair => pair.Key, pair => pair.Value);
} }
public void SetCpuRegister(string register, int value) public void SetCpuRegister(string register, int value)
{ {
if (register.StartsWithOrdinal("Left ")) 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);
L.SetCpuRegister(register.Replace("Left ", ""), value);
}
else if (register.StartsWithOrdinal("Right "))
{
R.SetCpuRegister(register.Replace("Right ", ""), value);
}
} }
public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" });

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.StringExtensions; using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -8,34 +8,26 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
{ {
public partial class GBHawkLink3x : IDebuggable 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<string, RegisterValue> GetCpuFlagsAndRegisters() public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
{ {
var left = L.GetCpuFlagsAndRegisters() Dictionary<string, RegisterValue> dict = new();
.Select(reg => new KeyValuePair<string, RegisterValue>("Left " + reg.Key, reg.Value)); 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;
var center = C.GetCpuFlagsAndRegisters() foreach (var ref in R.GetCpuFlagsAndRegisters()) dict[PFX_R + reg.Key] = reg.Value;
.Select(reg => new KeyValuePair<string, RegisterValue>("Center " + reg.Key, reg.Value)); return dict;
var right = R.GetCpuFlagsAndRegisters()
.Select(reg => new KeyValuePair<string, RegisterValue>("Right " + reg.Key, reg.Value));
return left.Union(center).Union(right).ToDictionary(pair => pair.Key, pair => pair.Value);
} }
public void SetCpuRegister(string register, int value) public void SetCpuRegister(string register, int value)
{ {
if (register.StartsWithOrdinal("Left ")) 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);
L.SetCpuRegister(register.Replace("Left ", ""), value); else if (register.StartsWithOrdinal(PFX_R)) R.SetCpuRegister(register.Substring(PFX_R.Length), value);
}
else if (register.StartsWithOrdinal("Center "))
{
C.SetCpuRegister(register.Replace("Center ", ""), value);
}
else if (register.StartsWithOrdinal("Right "))
{
R.SetCpuRegister(register.Replace("Right ", ""), value);
}
} }
public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" });

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.StringExtensions; using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -8,41 +8,30 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x
{ {
public partial class GBHawkLink4x : IDebuggable 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<string, RegisterValue> GetCpuFlagsAndRegisters() public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
{ {
var a = A.GetCpuFlagsAndRegisters() Dictionary<string, RegisterValue> dict = new();
.Select(reg => new KeyValuePair<string, RegisterValue>("A " + reg.Key, reg.Value)); 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;
var b = B.GetCpuFlagsAndRegisters() foreach (var ref in C.GetCpuFlagsAndRegisters()) dict[PFX_C + reg.Key] = reg.Value;
.Select(reg => new KeyValuePair<string, RegisterValue>("B " + reg.Key, reg.Value)); foreach (var ref in D.GetCpuFlagsAndRegisters()) dict[PFX_D + reg.Key] = reg.Value;
return dict;
var c = C.GetCpuFlagsAndRegisters()
.Select(reg => new KeyValuePair<string, RegisterValue>("C " + reg.Key, reg.Value));
var d = D.GetCpuFlagsAndRegisters()
.Select(reg => new KeyValuePair<string, RegisterValue>("D " + reg.Key, reg.Value));
return a.Union(b).Union(c).Union(d).ToDictionary(pair => pair.Key, pair => pair.Value);
} }
public void SetCpuRegister(string register, int value) public void SetCpuRegister(string register, int value)
{ {
if (register.StartsWithOrdinal("A ")) 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);
A.SetCpuRegister(register.Replace("A ", ""), 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);
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);
}
} }
public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" });