SMS: support cpu trace logging
This commit is contained in:
parent
0ca3fc3167
commit
6d4af4968d
|
@ -1,3 +1,5 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.CPUs.Z80
|
namespace BizHawk.Emulation.CPUs.Z80
|
||||||
{
|
{
|
||||||
public partial class Z80A
|
public partial class Z80A
|
||||||
|
@ -11,6 +13,9 @@ namespace BizHawk.Emulation.CPUs.Z80
|
||||||
private int pendingCycles;
|
private int pendingCycles;
|
||||||
public int PendingCycles { get { return pendingCycles; } set { pendingCycles = value; } }
|
public int PendingCycles { get { return pendingCycles; } set { pendingCycles = value; } }
|
||||||
|
|
||||||
|
public bool Debug;
|
||||||
|
public Action<string> Logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs the CPU for a particular number of clock cycles.
|
/// Runs the CPU for a particular number of clock cycles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -30,13 +35,18 @@ namespace BizHawk.Emulation.CPUs.Z80
|
||||||
{
|
{
|
||||||
Interruptable = true;
|
Interruptable = true;
|
||||||
|
|
||||||
if (halted)
|
if (halted)
|
||||||
{
|
{
|
||||||
++RegR;
|
|
||||||
totalExecutedCycles += 4; pendingCycles -= 4;
|
|
||||||
} else {
|
|
||||||
++RegR;
|
|
||||||
|
|
||||||
|
++RegR;
|
||||||
|
totalExecutedCycles += 4; pendingCycles -= 4;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (Debug)
|
||||||
|
Logger(State());
|
||||||
|
|
||||||
|
++RegR;
|
||||||
switch (ReadMemory(RegPC.Word++))
|
switch (ReadMemory(RegPC.Word++))
|
||||||
{
|
{
|
||||||
case 0x00: // NOP
|
case 0x00: // NOP
|
||||||
|
@ -11631,5 +11641,28 @@ namespace BizHawk.Emulation.CPUs.Z80
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO, not super thrilled with the existing Z80 disassembler, lets see if we can find something decent to replace it with
|
||||||
|
Disassembler Disassembler = new Disassembler();
|
||||||
|
|
||||||
|
public string State()
|
||||||
|
{
|
||||||
|
ushort tempPC = RegPC.Word;
|
||||||
|
//ushort pc = RegPC.Word;
|
||||||
|
//string str = disasm.Disassemble(() => ReadMemory(pc++));
|
||||||
|
string a = string.Format("{0:X4} {1:X2} {2} ", RegPC.Word, ReadMemory(RegPC.Word), Disassembler.Disassemble(() => ReadMemory(tempPC++)).PadRight(41));
|
||||||
|
string b = string.Format("AF:{0:X4} BC:{1:X4} DE:{2:X4} HL:{3:X4} IX:{4:X4} IY:{5:X4} SP:{6:X4} Cy:{7}", RegAF.Word, RegBC.Word, RegDE.Word, RegHL.Word, RegIX.Word, RegIY.Word, RegSP.Word, TotalExecutedCycles);
|
||||||
|
string val = a + b + " ";
|
||||||
|
|
||||||
|
if (RegFlagC) val = val + "C";
|
||||||
|
if (RegFlagN) val = val + "N";
|
||||||
|
if (RegFlagP) val = val + "P";
|
||||||
|
if (RegFlag3) val = val + "3";
|
||||||
|
if (RegFlagH) val = val + "H";
|
||||||
|
if (RegFlag5) val = val + "5";
|
||||||
|
if (RegFlagZ) val = val + "Z";
|
||||||
|
if (RegFlagS) val = val + "S";
|
||||||
|
return val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -84,7 +84,8 @@ namespace BizHawk.Emulation.Consoles.Sega
|
||||||
IsGameGear = game.System == "GG";
|
IsGameGear = game.System == "GG";
|
||||||
RomData = rom;
|
RomData = rom;
|
||||||
CoreOutputComm = new CoreOutputComm();
|
CoreOutputComm = new CoreOutputComm();
|
||||||
|
CoreOutputComm.CpuTraceAvailable = true;
|
||||||
|
|
||||||
if (RomData.Length % BankSize != 0)
|
if (RomData.Length % BankSize != 0)
|
||||||
Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
|
Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
|
||||||
RomBanks = (byte)(RomData.Length / BankSize);
|
RomBanks = (byte)(RomData.Length / BankSize);
|
||||||
|
@ -194,6 +195,9 @@ namespace BizHawk.Emulation.Consoles.Sega
|
||||||
lagged = true;
|
lagged = true;
|
||||||
Controller.UpdateControls(Frame++);
|
Controller.UpdateControls(Frame++);
|
||||||
PSG.BeginFrame(Cpu.TotalExecutedCycles);
|
PSG.BeginFrame(Cpu.TotalExecutedCycles);
|
||||||
|
Cpu.Debug = CoreInputComm.Tracer.Enabled;
|
||||||
|
if (Cpu.Debug && Cpu.Logger == null) // TODO, lets not do this on each frame. But lets refactor CoreInputComm/CoreOutputComm first
|
||||||
|
Cpu.Logger = (s) => CoreInputComm.Tracer.Put(s);
|
||||||
|
|
||||||
if (IsGameGear == false)
|
if (IsGameGear == false)
|
||||||
Cpu.NonMaskableInterrupt = Controller["Pause"];
|
Cpu.NonMaskableInterrupt = Controller["Pause"];
|
||||||
|
|
Loading…
Reference in New Issue