add Get/SetCpuFlagsAndRegisters to MOS6502X, and have cores point to that, instead of the same boilerplate in each core

This commit is contained in:
adelikat 2020-02-16 17:44:52 -06:00
parent 384f514445
commit 969642b6c7
7 changed files with 69 additions and 266 deletions

View File

@ -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<string, RegisterValue> GetCpuFlagsAndRegisters()
{
get { return "6502: PC, machine code, mnemonic, operands, registers (A, X, Y, P, SP), flags (NVTBDIZCR)"; }
return new Dictionary<string, RegisterValue>
{
["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)

View File

@ -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<string, RegisterValue> IDebuggable.GetCpuFlagsAndRegisters()
{
return new Dictionary<string, RegisterValue>
{
["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<string, RegisterValue> 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)
{

View File

@ -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<string, RegisterValue> GetCpuFlagsAndRegisters()
{
return new Dictionary<string, RegisterValue>
{
["A"] = Cpu.A,
["X"] = Cpu.X,
["Y"] = Cpu.Y,
["S"] = Cpu.S,
["PC"] = Cpu.PC,
public IDictionary<string, RegisterValue> 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;
}

View File

@ -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<string, RegisterValue> GetCpuFlagsAndRegisters()
{
return new Dictionary<string, RegisterValue>
{
["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<string, RegisterValue> 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;
}

View File

@ -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<string, RegisterValue> GetCpuFlagsAndRegisters()
{
return new Dictionary<string, RegisterValue>
{
["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<string, RegisterValue> 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;
}
}

View File

@ -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);

View File

@ -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<string, RegisterValue> GetCpuFlagsAndRegisters()
{
return new Dictionary<string, RegisterValue>
{
["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<string, RegisterValue> 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;
}