From 969642b6c7fcb65f46ee1d784658aa0bb557043c Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 16 Feb 2020 17:44:52 -0600 Subject: [PATCH] add Get/SetCpuFlagsAndRegisters to MOS6502X, and have cores point to that, instead of the same boilerplate in each core --- .../CPUs/MOS 6502X/MOS6502X.cs | 49 ++++++++++++++- .../Commodore64/MOS/Chip6510.IDebuggable.cs | 48 +------------- .../Atari/2600/Atari2600.IDebuggable.cs | 62 ++----------------- .../Atari/A7800Hawk/A7800Hawk.IDebuggable.cs | 58 ++--------------- .../Consoles/Nintendo/NES/NES.IDebuggable.cs | 62 ++----------------- .../Consoles/Nintendo/NES/NES.cs | 1 - .../SubNESHawk/SubNESHawk.IDebuggable.cs | 55 ++-------------- 7 files changed, 69 insertions(+), 266 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/MOS 6502X/MOS6502X.cs b/BizHawk.Emulation.Cores/CPUs/MOS 6502X/MOS6502X.cs index f3f9b8bdc9..da33d3c1dc 100644 --- a/BizHawk.Emulation.Cores/CPUs/MOS 6502X/MOS6502X.cs +++ b/BizHawk.Emulation.Cores/CPUs/MOS 6502X/MOS6502X.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using BizHawk.Common; @@ -44,9 +45,53 @@ namespace BizHawk.Emulation.Cores.Components.M6502 FlagI = true; } - public string TraceHeader + public string TraceHeader => "6502: PC, machine code, mnemonic, operands, registers (A, X, Y, P, SP), flags (NVTBDIZCR)"; + + public IDictionary GetCpuFlagsAndRegisters() { - get { return "6502: PC, machine code, mnemonic, operands, registers (A, X, Y, P, SP), flags (NVTBDIZCR)"; } + return new Dictionary + { + ["A"] = A, + ["X"] = X, + ["Y"] = Y, + ["S"] = S, + ["PC"] = PC, + ["Flag C"] = FlagC, + ["Flag Z"] = FlagZ, + ["Flag I"] = FlagI, + ["Flag D"] = FlagD, + ["Flag B"] = FlagB, + ["Flag V"] = FlagV, + ["Flag N"] = FlagN, + ["Flag T"] = FlagT + }; + } + + public void SetCpuRegister(string register, int value) + { + switch (register) + { + default: + throw new InvalidOperationException(); + case "A": + A = (byte)value; + break; + case "X": + X = (byte)value; + break; + case "Y": + Y = (byte)value; + break; + case "S": + S = (byte)value; + break; + case "PC": + PC = (ushort)value; + break; + case "Flag I": + FlagI = value > 0; + break; + } } public TraceInfo State(bool disassemble = true) diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.IDebuggable.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.IDebuggable.cs index 7dbe83fd05..a35ee6f996 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.IDebuggable.cs @@ -1,55 +1,13 @@ -using System; -using System.Collections.Generic; - +using System.Collections.Generic; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS { public sealed partial class Chip6510 : IDebuggable { - IDictionary IDebuggable.GetCpuFlagsAndRegisters() - { - return new Dictionary - { - ["A"] = _cpu.A, - ["X"] = _cpu.X, - ["Y"] = _cpu.Y, - ["S"] = _cpu.S, - ["PC"] = _cpu.PC, - ["Flag C"] = _cpu.FlagC, - ["Flag Z"] = _cpu.FlagZ, - ["Flag I"] = _cpu.FlagI, - ["Flag D"] = _cpu.FlagD, - ["Flag B"] = _cpu.FlagB, - ["Flag V"] = _cpu.FlagV, - ["Flag N"] = _cpu.FlagN, - ["Flag T"] = _cpu.FlagT - }; - } + IDictionary IDebuggable.GetCpuFlagsAndRegisters() => _cpu.GetCpuFlagsAndRegisters(); - void IDebuggable.SetCpuRegister(string register, int value) - { - switch (register) - { - default: - throw new InvalidOperationException(); - case "A": - _cpu.A = (byte)value; - break; - case "X": - _cpu.X = (byte)value; - break; - case "Y": - _cpu.Y = (byte)value; - break; - case "S": - _cpu.S = (byte)value; - break; - case "PC": - _cpu.PC = (ushort)value; - break; - } - } + void IDebuggable.SetCpuRegister(string register, int value) => _cpu.SetCpuRegister(register, value); bool IDebuggable.CanStep(StepType type) { diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs index a69b9be7ea..71cf6cf984 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs @@ -1,73 +1,21 @@ using System; using System.Collections.Generic; - using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Atari.Atari2600 { public partial class Atari2600 : IDebuggable { - public IDictionary GetCpuFlagsAndRegisters() - { - return new Dictionary - { - ["A"] = Cpu.A, - ["X"] = Cpu.X, - ["Y"] = Cpu.Y, - ["S"] = Cpu.S, - ["PC"] = Cpu.PC, + public IDictionary GetCpuFlagsAndRegisters() => Cpu.GetCpuFlagsAndRegisters(); - ["Flag C"] = Cpu.FlagC, - ["Flag Z"] = Cpu.FlagZ, - ["Flag I"] = Cpu.FlagI, - ["Flag D"] = Cpu.FlagD, - - ["Flag B"] = Cpu.FlagB, - ["Flag V"] = Cpu.FlagV, - ["Flag N"] = Cpu.FlagN, - ["Flag T"] = Cpu.FlagT - }; - } - - public void SetCpuRegister(string register, int value) - { - switch (register) - { - default: - throw new InvalidOperationException(); - case "A": - Cpu.A = (byte)value; - break; - case "X": - Cpu.X = (byte)value; - break; - case "Y": - Cpu.Y = (byte)value; - break; - case "S": - Cpu.S = (byte)value; - break; - case "PC": - Cpu.PC = (ushort)value; - break; - case "Flag I": - Cpu.FlagI = value > 0; - break; - } - } + public void SetCpuRegister(string register, int value) => Cpu.SetCpuRegister(register, value); public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); - public bool CanStep(StepType type) - { - return false; - } - + public bool CanStep(StepType type) => false; + [FeatureNotImplemented] - public void Step(StepType type) - { - throw new NotImplementedException(); - } + public void Step(StepType type) => throw new NotImplementedException(); public long TotalExecutedCycles => Cpu.TotalExecutedCycles; } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IDebuggable.cs index 00cfe7e28a..3047666248 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/A7800Hawk/A7800Hawk.IDebuggable.cs @@ -1,71 +1,21 @@ using System; using System.Collections.Generic; - using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Atari.A7800Hawk { public partial class A7800Hawk : IDebuggable { - public IDictionary GetCpuFlagsAndRegisters() - { - return new Dictionary - { - ["A"] = cpu.A, - ["X"] = cpu.X, - ["Y"] = cpu.Y, - ["S"] = cpu.S, - ["PC"] = cpu.PC, - ["Flag C"] = cpu.FlagC, - ["Flag Z"] = cpu.FlagZ, - ["Flag I"] = cpu.FlagI, - ["Flag D"] = cpu.FlagD, - ["Flag B"] = cpu.FlagB, - ["Flag V"] = cpu.FlagV, - ["Flag N"] = cpu.FlagN, - ["Flag T"] = cpu.FlagT - }; - } + public IDictionary GetCpuFlagsAndRegisters() => cpu.GetCpuFlagsAndRegisters(); - public void SetCpuRegister(string register, int value) - { - switch (register) - { - default: - throw new InvalidOperationException(); - case "A": - cpu.A = (byte)value; - break; - case "X": - cpu.X = (byte)value; - break; - case "Y": - cpu.Y = (byte)value; - break; - case "S": - cpu.S = (byte)value; - break; - case "PC": - cpu.PC = (ushort)value; - break; - case "Flag I": - cpu.FlagI = value > 0; - break; - } - } + public void SetCpuRegister(string register, int value) => cpu.SetCpuRegister(register, value); public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); - public bool CanStep(StepType type) - { - return false; - } + public bool CanStep(StepType type) => false; [FeatureNotImplemented] - public void Step(StepType type) - { - throw new NotImplementedException(); - } + public void Step(StepType type) => throw new NotImplementedException(); public long TotalExecutedCycles => cpu.TotalExecutedCycles; } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IDebuggable.cs index 58b920f85e..d19298777b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IDebuggable.cs @@ -1,72 +1,22 @@ using System; using System.Collections.Generic; - using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES { public partial class NES : IDebuggable { - public IDictionary GetCpuFlagsAndRegisters() - { - return new Dictionary - { - ["A"] = cpu.A, - ["X"] = cpu.X, - ["Y"] = cpu.Y, - ["S"] = cpu.S, - ["PC"] = cpu.PC, - ["Flag C"] = cpu.FlagC, - ["Flag Z"] = cpu.FlagZ, - ["Flag I"] = cpu.FlagI, - ["Flag D"] = cpu.FlagD, - ["Flag B"] = cpu.FlagB, - ["Flag V"] = cpu.FlagV, - ["Flag N"] = cpu.FlagN, - ["Flag T"] = cpu.FlagT - }; - } + public IDictionary GetCpuFlagsAndRegisters() => cpu.GetCpuFlagsAndRegisters(); - public void SetCpuRegister(string register, int value) - { - switch (register) - { - default: - throw new InvalidOperationException(); - case "A": - cpu.A = (byte)value; - break; - case "X": - cpu.X = (byte)value; - break; - case "Y": - cpu.Y = (byte)value; - break; - case "S": - cpu.S = (byte)value; - break; - case "PC": - cpu.PC = (ushort)value; - break; - case "Flag I": - cpu.FlagI = value > 0; - break; - } - } + public void SetCpuRegister(string register, int value) => cpu.SetCpuRegister(register, value); - public bool CanStep(StepType type) - { - return false; - } + public bool CanStep(StepType type) => false; - public IMemoryCallbackSystem MemoryCallbacks { get; private set; } + public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(new[] { "System Bus" }); [FeatureNotImplemented] - public void Step(StepType type) { throw new NotImplementedException(); } + public void Step(StepType type) => throw new NotImplementedException(); - public long TotalExecutedCycles - { - get { return cpu.TotalExecutedCycles; } - } + public long TotalExecutedCycles => cpu.TotalExecutedCycles; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 6bd3f998d1..f756a4b265 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -36,7 +36,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ControllerSettings = SyncSettings.Controls; CoreComm = comm; - MemoryCallbacks = new MemoryCallbackSystem(new[] { "System Bus" }); BootGodDB.Initialize(); videoProvider = new MyVideoProvider(this); Init(game, rom, fdsbios); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IDebuggable.cs index d833c87b41..ee9c48d405 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SubNESHawk/SubNESHawk.IDebuggable.cs @@ -1,68 +1,21 @@ using System; using System.Collections.Generic; - using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk { public partial class SubNESHawk : IDebuggable { - public IDictionary GetCpuFlagsAndRegisters() - { - return new Dictionary - { - ["A"] = subnes.cpu.A, - ["X"] = subnes.cpu.X, - ["Y"] = subnes.cpu.Y, - ["S"] = subnes.cpu.S, - ["PC"] = subnes.cpu.PC, - ["Flag C"] = subnes.cpu.FlagC, - ["Flag Z"] = subnes.cpu.FlagZ, - ["Flag I"] = subnes.cpu.FlagI, - ["Flag D"] = subnes.cpu.FlagD, - ["Flag B"] = subnes.cpu.FlagB, - ["Flag V"] = subnes.cpu.FlagV, - ["Flag N"] = subnes.cpu.FlagN, - ["Flag T"] = subnes.cpu.FlagT - }; - } + public IDictionary GetCpuFlagsAndRegisters() => subnes.GetCpuFlagsAndRegisters(); - public void SetCpuRegister(string register, int value) - { - switch (register) - { - default: - throw new InvalidOperationException(); - case "A": - subnes.cpu.A = (byte)value; - break; - case "X": - subnes.cpu.X = (byte)value; - break; - case "Y": - subnes.cpu.Y = (byte)value; - break; - case "S": - subnes.cpu.S = (byte)value; - break; - case "PC": - subnes.cpu.PC = (ushort)value; - break; - case "Flag I": - subnes.cpu.FlagI = value > 0; - break; - } - } + public void SetCpuRegister(string register, int value) => subnes.SetCpuRegister(register, value); - public bool CanStep(StepType type) - { - return false; - } + public bool CanStep(StepType type) => false; public IMemoryCallbackSystem MemoryCallbacks => subnes.MemoryCallbacks; [FeatureNotImplemented] - public void Step(StepType type) { throw new NotImplementedException(); } + public void Step(StepType type) => throw new NotImplementedException(); public long TotalExecutedCycles => subnes.cpu.TotalExecutedCycles; }