Move TraceBuffer from CoreComm to IDebugable and refactor accordingly

This commit is contained in:
adelikat 2014-12-05 00:05:40 +00:00
parent 02f5206382
commit 309088211c
29 changed files with 183 additions and 95 deletions

View File

@ -1103,7 +1103,7 @@ namespace BizHawk.Client.EmuHawk
TAStudioMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["TAStudio"].Bindings; TAStudioMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["TAStudio"].Bindings;
VirtualPadMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Virtual Pad"].Bindings; VirtualPadMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Virtual Pad"].Bindings;
TraceLoggerMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Trace Logger"].Bindings; TraceLoggerMenuItem.ShortcutKeyDisplayString = Global.Config.HotkeyBindings["Trace Logger"].Bindings;
TraceLoggerMenuItem.Enabled = Global.Emulator.CoreComm.CpuTraceAvailable; TraceLoggerMenuItem.Enabled = Global.Emulator.CpuTraceAvailable();
TAStudioMenuItem.Enabled = Global.Emulator.HasSavestates() && Global.Emulator.CanPollInput(); TAStudioMenuItem.Enabled = Global.Emulator.HasSavestates() && Global.Emulator.CanPollInput();

View File

@ -9,6 +9,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Emulation.Cores.Atari.Atari2600; using BizHawk.Emulation.Cores.Atari.Atari2600;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -111,7 +112,7 @@ namespace BizHawk.Client.EmuHawk
// TODO: some kind of method like PauseAndRelinquishControl() which will set a flag preventing unpausing by the user, and then a ResumeControl() method that is done on close // TODO: some kind of method like PauseAndRelinquishControl() which will set a flag preventing unpausing by the user, and then a ResumeControl() method that is done on close
//GlobalWin.MainForm.PauseEmulator(); //GlobalWin.MainForm.PauseEmulator();
Global.CoreComm.Tracer.Enabled = true; (_core as IDebuggable).Tracer.Enabled = true;
if (Global.Config.Atari2600DebuggerSettings.UseWindowPosition) if (Global.Config.Atari2600DebuggerSettings.UseWindowPosition)
{ {
@ -145,8 +146,8 @@ namespace BizHawk.Client.EmuHawk
private void Shutdown() private void Shutdown()
{ {
//TODO: add a Mainform.ResumeControl() call //TODO: add a Mainform.ResumeControl() call
Global.CoreComm.Tracer.TakeContents(); (_core as IDebuggable).Tracer.TakeContents();
Global.CoreComm.Tracer.Enabled = false; (_core as IDebuggable).Tracer.Enabled = false;
} }
public void Restart() public void Restart()
@ -214,7 +215,7 @@ namespace BizHawk.Client.EmuHawk
private void UpdateTraceLog() private void UpdateTraceLog()
{ {
var instructions = Global.CoreComm.Tracer.TakeContents().Split('\n'); var instructions = (_core as IDebuggable).Tracer.TakeContents().Split('\n');
if (!string.IsNullOrWhiteSpace(instructions[0])) if (!string.IsNullOrWhiteSpace(instructions[0]))
{ {
_instructions.AddRange(instructions.Where(str => !string.IsNullOrEmpty(str))); _instructions.AddRange(instructions.Where(str => !string.IsNullOrEmpty(str)));

View File

@ -464,7 +464,7 @@ namespace BizHawk.Client.EmuHawk
public void LoadTraceLogger() public void LoadTraceLogger()
{ {
if (Global.Emulator.CoreComm.CpuTraceAvailable) if (Global.Emulator.CpuTraceAvailable())
{ {
Load<TraceLogger>(); Load<TraceLogger>();
} }

View File

@ -6,13 +6,18 @@ using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.WinFormExtensions;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class TraceLogger : Form, IToolForm public partial class TraceLogger : Form, IToolForm
{ {
private readonly ITracer Tracer;
// Refresh rate slider // Refresh rate slider
// Make faster, such as not saving to disk until the logging is stopped, dont' add to Instructions list every frame, etc // Make faster, such as not saving to disk until the logging is stopped, dont' add to Instructions list every frame, etc
private readonly List<string> _instructions = new List<string>(); private readonly List<string> _instructions = new List<string>();
@ -30,6 +35,15 @@ namespace BizHawk.Client.EmuHawk
TopMost = Global.Config.TraceLoggerSettings.TopMost; TopMost = Global.Config.TraceLoggerSettings.TopMost;
Closing += (o, e) => SaveConfigSettings(); Closing += (o, e) => SaveConfigSettings();
if (Global.Emulator.CpuTraceAvailable())
{
Tracer = Global.Emulator.GetDebugger().Tracer;
}
else
{
Close();
}
} }
public bool UpdateBefore public bool UpdateBefore
@ -44,7 +58,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveConfigSettings() private void SaveConfigSettings()
{ {
Global.CoreComm.Tracer.Enabled = false; Tracer.Enabled = false;
Global.Config.TraceLoggerSettings.Wndx = Location.X; Global.Config.TraceLoggerSettings.Wndx = Location.X;
Global.Config.TraceLoggerSettings.Wndy = Location.Y; Global.Config.TraceLoggerSettings.Wndy = Location.Y;
Global.Config.TraceLoggerSettings.Width = Size.Width; Global.Config.TraceLoggerSettings.Width = Size.Width;
@ -73,7 +87,7 @@ namespace BizHawk.Client.EmuHawk
ClearList(); ClearList();
LoggingEnabled.Checked = true; LoggingEnabled.Checked = true;
Global.CoreComm.Tracer.Enabled = true; Tracer.Enabled = true;
SetTracerBoxTitle(); SetTracerBoxTitle();
Restart(); Restart();
} }
@ -109,7 +123,7 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
if (Global.Emulator.CoreComm.CpuTraceAvailable) if (Global.Emulator.CpuTraceAvailable())
{ {
ClearList(); ClearList();
TraceView.Columns[0].Text = Global.Emulator.CoreComm.TraceHeader; TraceView.Columns[0].Text = Global.Emulator.CoreComm.TraceHeader;
@ -132,13 +146,13 @@ namespace BizHawk.Client.EmuHawk
{ {
using (var sw = new StreamWriter(_logFile.FullName, true)) using (var sw = new StreamWriter(_logFile.FullName, true))
{ {
sw.Write(Global.CoreComm.Tracer.TakeContents()); sw.Write(Tracer.TakeContents());
} }
} }
private void LogToWindow() private void LogToWindow()
{ {
var instructions = Global.CoreComm.Tracer.TakeContents().Split('\n'); var instructions = Tracer.TakeContents().Split('\n');
if (!string.IsNullOrWhiteSpace(instructions[0])) if (!string.IsNullOrWhiteSpace(instructions[0]))
{ {
_instructions.AddRange(instructions); _instructions.AddRange(instructions);
@ -154,7 +168,7 @@ namespace BizHawk.Client.EmuHawk
private void SetTracerBoxTitle() private void SetTracerBoxTitle()
{ {
if (Global.CoreComm.Tracer.Enabled) if (Tracer.Enabled)
{ {
if (ToFileRadio.Checked) if (ToFileRadio.Checked)
{ {
@ -351,7 +365,7 @@ namespace BizHawk.Client.EmuHawk
private void LoggingEnabled_CheckedChanged(object sender, EventArgs e) private void LoggingEnabled_CheckedChanged(object sender, EventArgs e)
{ {
Global.CoreComm.Tracer.Enabled = LoggingEnabled.Checked; Tracer.Enabled = LoggingEnabled.Checked;
SetTracerBoxTitle(); SetTracerBoxTitle();
} }

View File

@ -55,6 +55,7 @@
<Compile Include="Base Implementations\NullController.cs" /> <Compile Include="Base Implementations\NullController.cs" />
<Compile Include="Base Implementations\NullEmulator.cs" /> <Compile Include="Base Implementations\NullEmulator.cs" />
<Compile Include="Base Implementations\NullSound.cs" /> <Compile Include="Base Implementations\NullSound.cs" />
<Compile Include="Base Implementations\TraceBuffer.cs" />
<Compile Include="CoreAttributes.cs" /> <Compile Include="CoreAttributes.cs" />
<Compile Include="CoreComms.cs" /> <Compile Include="CoreComms.cs" />
<Compile Include="Database\CRC32.cs" /> <Compile Include="Database\CRC32.cs" />
@ -78,6 +79,7 @@
<Compile Include="Interfaces\ISoundProvider.cs" /> <Compile Include="Interfaces\ISoundProvider.cs" />
<Compile Include="Interfaces\IStatable.cs" /> <Compile Include="Interfaces\IStatable.cs" />
<Compile Include="Interfaces\ISyncSoundProvider.cs" /> <Compile Include="Interfaces\ISyncSoundProvider.cs" />
<Compile Include="Interfaces\ITracer.cs" />
<Compile Include="Interfaces\IVideoProvider.cs" /> <Compile Include="Interfaces\IVideoProvider.cs" />
<Compile Include="MemoryDomain.cs" /> <Compile Include="MemoryDomain.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -9,11 +9,6 @@ namespace BizHawk.Emulation.Common
{ {
public ICoreFileProvider CoreFileProvider; public ICoreFileProvider CoreFileProvider;
/// <summary>
/// if this is set, then the cpu should dump trace info to CpuTraceStream
/// </summary>
public TraceBuffer Tracer = new TraceBuffer();
public MemoryCallbackSystem MemoryCallbackSystem = new MemoryCallbackSystem(); public MemoryCallbackSystem MemoryCallbackSystem = new MemoryCallbackSystem();
public double VsyncRate public double VsyncRate
@ -32,8 +27,6 @@ namespace BizHawk.Emulation.Common
public int ScreenLogicalOffsetX, ScreenLogicalOffsetY; public int ScreenLogicalOffsetX, ScreenLogicalOffsetY;
public bool CpuTraceAvailable = false;
public string TraceHeader = "Instructions"; public string TraceHeader = "Instructions";
// size hint to a/v out resizer. this probably belongs in VideoProvider? but it's somewhat different than VirtualWidth... // size hint to a/v out resizer. this probably belongs in VideoProvider? but it's somewhat different than VirtualWidth...
@ -69,53 +62,6 @@ namespace BizHawk.Emulation.Common
public Func<bool> DispSnowyNullEmulator; public Func<bool> DispSnowyNullEmulator;
} }
public class TraceBuffer
{
public string TakeContents()
{
string s = buffer.ToString();
buffer.Clear();
return s;
}
public string Contents
{
get
{
return buffer.ToString();
}
}
public void Put(string content)
{
if (logging)
{
buffer.AppendLine(content);
}
}
public TraceBuffer()
{
buffer = new StringBuilder();
}
public bool Enabled
{
get
{
return logging;
}
set
{
logging = value;
}
}
private readonly StringBuilder buffer;
private bool logging;
}
public class MemoryCallbackSystem public class MemoryCallbackSystem
{ {
private readonly List<Action> _reads = new List<Action>(); private readonly List<Action> _reads = new List<Action>();

View File

@ -37,6 +37,36 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return core == null || core is NullEmulator; return core == null || core is NullEmulator;
} }
public static bool CpuTraceAvailable(this IEmulator core)
{
// TODO: this is a pretty ugly way to handle this
var debuggable = (IDebuggable)core.ServiceProvider.GetService<IDebuggable>();
if (debuggable != null)
{
try
{
var tracer = debuggable.Tracer;
return true;
}
catch(NotImplementedException)
{
return false;
}
}
return false;
}
public static bool CanDebug(this IEmulator core)
{
return core.ServiceProvider.HasService<IDebuggable>();
}
public static IDebuggable GetDebugger(this IEmulator core)
{
return (IDebuggable)core.ServiceProvider.GetService<IDebuggable>();
}
// TODO: a better place for these // TODO: a better place for these
public static bool IsImplemented(this MethodInfo info) public static bool IsImplemented(this MethodInfo info)
{ {

View File

@ -16,5 +16,7 @@ namespace BizHawk.Emulation.Common
/// <param name="register"></param> /// <param name="register"></param>
/// <param name="value"></param> /// <param name="value"></param>
void SetCpuRegister(string register, int value); void SetCpuRegister(string register, int value);
ITracer Tracer { get; }
} }
} }

View File

@ -119,5 +119,11 @@ namespace BizHawk.Emulation.Cores.Calculators
break; break;
} }
} }
public ITracer Tracer
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
} }
} }

View File

@ -126,6 +126,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
break; break;
} }
} }
public ITracer Tracer
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
} }
static public class C64Util static public class C64Util

View File

@ -414,9 +414,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
_tia.Execute(1); _tia.Execute(1);
_tia.Execute(1); _tia.Execute(1);
M6532.Timer.Tick(); M6532.Timer.Tick();
if (CoreComm.Tracer.Enabled) if (Tracer.Enabled)
{ {
CoreComm.Tracer.Put(Cpu.TraceState()); Tracer.Put(Cpu.TraceState());
} }
Cpu.ExecuteOne(); Cpu.ExecuteOne();
_mapper.ClockCpu(); _mapper.ClockCpu();

View File

@ -55,5 +55,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
break; break;
} }
} }
public ITracer Tracer { get; private set; }
} }
} }

View File

@ -24,6 +24,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
[CoreConstructor("A26")] [CoreConstructor("A26")]
public Atari2600(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings) public Atari2600(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings)
{ {
Tracer = new TraceBuffer();
ServiceProvider = new BasicServiceProvider(this); ServiceProvider = new BasicServiceProvider(this);
InputCallbacks = new InputCallbackSystem(); InputCallbacks = new InputCallbackSystem();
Ram = new byte[128]; Ram = new byte[128];
@ -31,7 +32,6 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
Settings = (A2600Settings)settings ?? new A2600Settings(); Settings = (A2600Settings)settings ?? new A2600Settings();
SyncSettings = (A2600SyncSettings)syncSettings ?? new A2600SyncSettings(); SyncSettings = (A2600SyncSettings)syncSettings ?? new A2600SyncSettings();
CoreComm.CpuTraceAvailable = true;
Rom = rom; Rom = rom;
_game = game; _game = game;

View File

@ -53,5 +53,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
break; break;
} }
} }
public ITracer Tracer
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
} }
} }

View File

@ -66,6 +66,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision
private readonly InputCallbackSystem _inputCallbacks = new InputCallbackSystem(); private readonly InputCallbackSystem _inputCallbacks = new InputCallbackSystem();
public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } } public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } }
public ITracer Tracer
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
public MemoryDomainList MemoryDomains { get { return memoryDomains; } } public MemoryDomainList MemoryDomains { get { return memoryDomains; } }
MemoryDomainList memoryDomains; MemoryDomainList memoryDomains;
const ushort RamSizeMask = 0x03FF; const ushort RamSizeMask = 0x03FF;

View File

@ -48,10 +48,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
public GBA(CoreComm comm, byte[] file) public GBA(CoreComm comm, byte[] file)
{ {
ServiceProvider = new BasicServiceProvider(this); ServiceProvider = new BasicServiceProvider(this);
Tracer = new TraceBuffer();
CoreComm = comm; CoreComm = comm;
comm.VsyncNum = 262144; comm.VsyncNum = 262144;
comm.VsyncDen = 4389; comm.VsyncDen = 4389;
comm.CpuTraceAvailable = true;
comm.TraceHeader = " -Addr--- -Opcode- -Instruction------------------- -R0----- -R1----- -R2----- -R3----- -R4----- -R5----- -R6----- -R7----- -R8----- -R9----- -R10---- -R11---- -R12---- -R13(SP) -R14(LR) -R15(PC) -CPSR--- -SPSR---"; comm.TraceHeader = " -Addr--- -Opcode- -Instruction------------------- -R0----- -R1----- -R2----- -R3----- -R4----- -R5----- -R6----- -R7----- -R8----- -R9----- -R10---- -R11---- -R12---- -R13(SP) -R14(LR) -R15(PC) -CPSR--- -SPSR---";
comm.NominalWidth = 240; comm.NominalWidth = 240;
comm.NominalHeight = 160; comm.NominalHeight = 160;
@ -80,7 +81,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
if (Controller["Power"]) if (Controller["Power"])
LibMeteor.libmeteor_hardreset(); LibMeteor.libmeteor_hardreset();
// due to the design of the tracing api, we have to poll whether it's active each frame // due to the design of the tracing api, we have to poll whether it's active each frame
LibMeteor.libmeteor_settracecallback(CoreComm.Tracer.Enabled ? tracecallback : null); LibMeteor.libmeteor_settracecallback(Tracer.Enabled ? tracecallback : null);
if (!coredead) if (!coredead)
LibMeteor.libmeteor_frameadvance(); LibMeteor.libmeteor_frameadvance();
if (IsLagFrame) if (IsLagFrame)
@ -96,6 +97,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
// TODO: optimize managed to unmanaged using the ActiveChanged event // TODO: optimize managed to unmanaged using the ActiveChanged event
public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { return _inputCallbacks; } } public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { return _inputCallbacks; } }
public ITracer Tracer { get; private set; }
public string SystemId { get { return "GBA"; } } public string SystemId { get { return "GBA"; } }
public bool DeterministicEmulation { get { return true; } } public bool DeterministicEmulation { get { return true; } }
@ -416,7 +420,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
void Trace(string msg) void Trace(string msg)
{ {
CoreComm.Tracer.Put(msg); Tracer.Put(msg);
} }
GBAGPUMemoryAreas IGBAGPUViewable.GetMemoryAreas() GBAGPUMemoryAreas IGBAGPUViewable.GetMemoryAreas()

View File

@ -65,6 +65,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
if (!LibVBANext.LoadRom(Core, file, (uint)file.Length, biosfile, (uint)biosfile.Length, FES)) if (!LibVBANext.LoadRom(Core, file, (uint)file.Length, biosfile, (uint)biosfile.Length, FES))
throw new InvalidOperationException("LoadRom() returned false!"); throw new InvalidOperationException("LoadRom() returned false!");
Tracer = new TraceBuffer();
CoreComm.VsyncNum = 262144; CoreComm.VsyncNum = 262144;
CoreComm.VsyncDen = 4389; CoreComm.VsyncDen = 4389;
CoreComm.NominalWidth = 240; CoreComm.NominalWidth = 240;
@ -79,8 +81,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
InitRegisters(); InitRegisters();
InitCallbacks(); InitCallbacks();
CoreComm.CpuTraceAvailable = true;
// todo: hook me up as a setting // todo: hook me up as a setting
SetupColors(); SetupColors();
} }
@ -117,6 +117,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
// TODO: optimize managed to unmanaged using the ActiveChanged event // TODO: optimize managed to unmanaged using the ActiveChanged event
public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { return _inputCallbacks; } } public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { return _inputCallbacks; } }
public ITracer Tracer { get; private set; }
public string SystemId { get { return "GBA"; } } public string SystemId { get { return "GBA"; } }
public bool DeterministicEmulation { get; private set; } public bool DeterministicEmulation { get; private set; }
@ -284,7 +286,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
fetchcb = new LibVBANext.AddressCallback((addr) => CoreComm.MemoryCallbackSystem.CallExecute(addr)); fetchcb = new LibVBANext.AddressCallback((addr) => CoreComm.MemoryCallbackSystem.CallExecute(addr));
readcb = new LibVBANext.AddressCallback((addr) => CoreComm.MemoryCallbackSystem.CallRead(addr)); readcb = new LibVBANext.AddressCallback((addr) => CoreComm.MemoryCallbackSystem.CallRead(addr));
writecb = new LibVBANext.AddressCallback((addr) => CoreComm.MemoryCallbackSystem.CallWrite(addr)); writecb = new LibVBANext.AddressCallback((addr) => CoreComm.MemoryCallbackSystem.CallWrite(addr));
tracecb = new LibVBANext.TraceCallback((addr, opcode) => CoreComm.Tracer.Put(Trace(addr, opcode))); tracecb = new LibVBANext.TraceCallback((addr, opcode) => Tracer.Put(Trace(addr, opcode)));
_inputCallbacks.ActiveChanged += SyncPadCallback; _inputCallbacks.ActiveChanged += SyncPadCallback;
} }
@ -305,7 +307,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
LibVBANext.SetFetchCallback(Core, CoreComm.MemoryCallbackSystem.HasExecutes ? fetchcb : null); LibVBANext.SetFetchCallback(Core, CoreComm.MemoryCallbackSystem.HasExecutes ? fetchcb : null);
LibVBANext.SetReadCallback(Core, CoreComm.MemoryCallbackSystem.HasReads ? readcb : null); LibVBANext.SetReadCallback(Core, CoreComm.MemoryCallbackSystem.HasReads ? readcb : null);
LibVBANext.SetWriteCallback(Core, CoreComm.MemoryCallbackSystem.HasWrites ? writecb : null); LibVBANext.SetWriteCallback(Core, CoreComm.MemoryCallbackSystem.HasWrites ? writecb : null);
LibVBANext.SetTraceCallback(Core, CoreComm.Tracer.Enabled ? tracecb : null); LibVBANext.SetTraceCallback(Core, Tracer.Enabled ? tracecb : null);
} }
LibVBANext.StandardCallback scanlinecb; LibVBANext.StandardCallback scanlinecb;

View File

@ -139,13 +139,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
public Gameboy(CoreComm comm, GameInfo game, byte[] file, object Settings, object SyncSettings, bool deterministic) public Gameboy(CoreComm comm, GameInfo game, byte[] file, object Settings, object SyncSettings, bool deterministic)
{ {
ServiceProvider = new BasicServiceProvider(this); ServiceProvider = new BasicServiceProvider(this);
Tracer = new TraceBuffer();
CoreComm = comm; CoreComm = comm;
comm.VsyncNum = 262144; comm.VsyncNum = 262144;
comm.VsyncDen = 4389; comm.VsyncDen = 4389;
comm.RomStatusAnnotation = null; comm.RomStatusAnnotation = null;
comm.RomStatusDetails = null; comm.RomStatusDetails = null;
comm.CpuTraceAvailable = true;
comm.NominalWidth = 160; comm.NominalWidth = 160;
comm.NominalHeight = 144; comm.NominalHeight = 144;
@ -274,6 +274,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ITracer Tracer { get; private set; }
/// <summary> /// <summary>
/// true if the emulator is currently emulating CGB /// true if the emulator is currently emulating CGB
/// </summary> /// </summary>
@ -316,7 +318,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
LibGambatte.gambatte_reset(GambatteState, GetCurrentTime()); LibGambatte.gambatte_reset(GambatteState, GetCurrentTime());
RefreshMemoryCallbacks(); RefreshMemoryCallbacks();
if (CoreComm.Tracer.Enabled) if (Tracer.Enabled)
tracecb = MakeTrace; tracecb = MakeTrace;
else else
tracecb = null; tracecb = null;
@ -675,7 +677,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
System.Runtime.InteropServices.Marshal.Copy(_s, s, 0, 13); System.Runtime.InteropServices.Marshal.Copy(_s, s, 0, 13);
ushort unused; ushort unused;
CoreComm.Tracer.Put(string.Format( Tracer.Put(string.Format(
"{13} SP:{2:x2} A:{3:x2} B:{4:x2} C:{5:x2} D:{6:x2} E:{7:x2} F:{8:x2} H:{9:x2} L:{10:x2} {11} Cy:{0}", "{13} SP:{2:x2} A:{3:x2} B:{4:x2} C:{5:x2} D:{6:x2} E:{7:x2} F:{8:x2} H:{9:x2} L:{10:x2} {11} Cy:{0}",
s[0], s[0],
s[1] & 0xffff, s[1] & 0xffff,

View File

@ -65,7 +65,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
comm.VsyncDen = L.CoreComm.VsyncDen; comm.VsyncDen = L.CoreComm.VsyncDen;
comm.RomStatusAnnotation = null; comm.RomStatusAnnotation = null;
comm.RomStatusDetails = "LEFT:\r\n" + L.CoreComm.RomStatusDetails + "RIGHT:\r\n" + R.CoreComm.RomStatusDetails; comm.RomStatusDetails = "LEFT:\r\n" + L.CoreComm.RomStatusDetails + "RIGHT:\r\n" + R.CoreComm.RomStatusDetails;
comm.CpuTraceAvailable = false; // TODO
comm.NominalWidth = L.CoreComm.NominalWidth + R.CoreComm.NominalWidth; comm.NominalWidth = L.CoreComm.NominalWidth + R.CoreComm.NominalWidth;
comm.NominalHeight = L.CoreComm.NominalHeight; comm.NominalHeight = L.CoreComm.NominalHeight;
comm.UsesLinkCable = true; comm.UsesLinkCable = true;
@ -88,6 +87,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
private InputCallbackSystem _inputCallbacks = new InputCallbackSystem(); private InputCallbackSystem _inputCallbacks = new InputCallbackSystem();
public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } } public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } }
public ITracer Tracer
{
[FeatureNotImplemented]
get { throw new NotImplementedException(); }
}
public IVideoProvider VideoProvider { get { return this; } } public IVideoProvider VideoProvider { get { return this; } }
public ISoundProvider SoundProvider { get { return null; } } public ISoundProvider SoundProvider { get { return null; } }
public ISyncSoundProvider SyncSoundProvider { get { return this; } } public ISyncSoundProvider SyncSoundProvider { get { return this; } }

View File

@ -58,5 +58,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ITracer Tracer
{
[FeatureNotImplemented]
get
{
throw new NotImplementedException();
}
}
} }
} }

View File

@ -245,8 +245,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
bool hardResetSignal; bool hardResetSignal;
public void FrameAdvance(bool render, bool rendersound) public void FrameAdvance(bool render, bool rendersound)
{ {
if (CoreComm.Tracer.Enabled) if (Tracer.Enabled)
cpu.TraceCallback = (s) => CoreComm.Tracer.Put(s); cpu.TraceCallback = (s) => Tracer.Put(s);
else else
cpu.TraceCallback = null; cpu.TraceCallback = null;

View File

@ -39,7 +39,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
this.SyncSettings = (NESSyncSettings)SyncSettings ?? new NESSyncSettings(); this.SyncSettings = (NESSyncSettings)SyncSettings ?? new NESSyncSettings();
this.ControllerSettings = this.SyncSettings.Controls; this.ControllerSettings = this.SyncSettings.Controls;
CoreComm = comm; CoreComm = comm;
CoreComm.CpuTraceAvailable = true; Tracer = new TraceBuffer();
BootGodDB.Initialize(); BootGodDB.Initialize();
videoProvider = new MyVideoProvider(this); videoProvider = new MyVideoProvider(this);
Init(game, rom, fdsbios); Init(game, rom, fdsbios);
@ -925,6 +925,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
} }
} }
public ITracer Tracer { get; private set; }
NESSettings Settings = new NESSettings(); NESSettings Settings = new NESSettings();
NESSyncSettings SyncSettings = new NESSyncSettings(); NESSyncSettings SyncSettings = new NESSyncSettings();

View File

@ -393,6 +393,15 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ITracer Tracer
{
[FeatureNotImplemented]
get
{
throw new NotImplementedException();
}
}
#endregion #endregion
public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { throw new NotImplementedException(); } } public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { throw new NotImplementedException(); } }

View File

@ -146,7 +146,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
CoreComm.VsyncDen = 4 * 341 * 312; CoreComm.VsyncDen = 4 * 341 * 312;
} }
CoreComm.CpuTraceAvailable = true; Tracer = new TraceBuffer();
api.CMD_power(); api.CMD_power();
@ -249,6 +249,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
// TODO: optimize managed to unmanaged using the ActiveChanged event // TODO: optimize managed to unmanaged using the ActiveChanged event
public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { return _inputCallbacks; } } public IInputCallbackSystem InputCallbacks { [FeatureNotImplemented]get { return _inputCallbacks; } }
public ITracer Tracer { get; private set; }
[FeatureNotImplemented] [FeatureNotImplemented]
public void SetCpuRegister(string register, int value) public void SetCpuRegister(string register, int value)
{ {
@ -348,7 +350,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
void snes_trace(string msg) void snes_trace(string msg)
{ {
CoreComm.Tracer.Put(msg); Tracer.Put(msg);
} }
public SnesColors.ColorType CurrPalette { get; private set; } public SnesColors.ColorType CurrPalette { get; private set; }
@ -596,7 +598,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
savestatebuff = ms.ToArray(); savestatebuff = ms.ToArray();
} }
if (!nocallbacks && CoreComm.Tracer.Enabled) if (!nocallbacks && Tracer.Enabled)
api.QUERY_set_trace_callback(tracecb); api.QUERY_set_trace_callback(tracecb);
else else
api.QUERY_set_trace_callback(null); api.QUERY_set_trace_callback(null);

View File

@ -69,8 +69,8 @@ namespace BizHawk.Emulation.Cores.PCEngine
public PCEngine(CoreComm comm, GameInfo game, byte[] rom, object Settings, object syncSettings) public PCEngine(CoreComm comm, GameInfo game, byte[] rom, object Settings, object syncSettings)
{ {
ServiceProvider = new BasicServiceProvider(this); ServiceProvider = new BasicServiceProvider(this);
Tracer = new TraceBuffer();
CoreComm = comm; CoreComm = comm;
CoreComm.CpuTraceAvailable = true;
switch (game.System) switch (game.System)
{ {
@ -93,10 +93,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
public string BoardName { get { return null; } } public string BoardName { get { return null; } }
public ITracer Tracer { get; private set; }
public PCEngine(CoreComm comm, GameInfo game, Disc disc, object Settings, object syncSettings) public PCEngine(CoreComm comm, GameInfo game, Disc disc, object Settings, object syncSettings)
{ {
CoreComm = comm; CoreComm = comm;
CoreComm.CpuTraceAvailable = true; Tracer = new TraceBuffer();
CoreComm.UsesDriveLed = true; CoreComm.UsesDriveLed = true;
systemid = "PCECD"; systemid = "PCECD";
Type = NecSystemType.TurboCD; Type = NecSystemType.TurboCD;
@ -156,7 +158,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
PSG = new HuC6280PSG(); PSG = new HuC6280PSG();
SCSI = new ScsiCDBus(this, disc); SCSI = new ScsiCDBus(this, disc);
Cpu.Logger = (s) => CoreComm.Tracer.Put(s); Cpu.Logger = (s) => Tracer.Put(s);
if (TurboGrafx) if (TurboGrafx)
{ {
@ -217,7 +219,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
RomData = rom; RomData = rom;
RomLength = RomData.Length; RomLength = RomData.Length;
// user request: current value of the SF2MapperLatch on the tracelogger // user request: current value of the SF2MapperLatch on the tracelogger
Cpu.Logger = (s) => CoreComm.Tracer.Put(string.Format("{0:X1}:{1}", SF2MapperLatch, s)); Cpu.Logger = (s) => Tracer.Put(string.Format("{0:X1}:{1}", SF2MapperLatch, s));
} }
else else
{ {
@ -317,7 +319,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
CheckSpriteLimit(); CheckSpriteLimit();
PSG.BeginFrame(Cpu.TotalExecutedCycles); PSG.BeginFrame(Cpu.TotalExecutedCycles);
Cpu.Debug = CoreComm.Tracer.Enabled; Cpu.Debug = Tracer.Enabled;
if (SuperGrafx) if (SuperGrafx)
VPC.ExecFrame(render); VPC.ExecFrame(render);

View File

@ -292,6 +292,15 @@ namespace BizHawk.Emulation.Cores.Sega.Genesis
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ITracer Tracer
{
[FeatureNotImplemented]
get
{
throw new NotImplementedException();
}
}
int vdpcallback(int level) // Musashi handler int vdpcallback(int level) // Musashi handler
{ {
InterruptCallback(level); InterruptCallback(level);

View File

@ -104,7 +104,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
IsGameGear = game.System == "GG"; IsGameGear = game.System == "GG";
IsSG1000 = game.System == "SG"; IsSG1000 = game.System == "SG";
RomData = rom; RomData = rom;
CoreComm.CpuTraceAvailable = true; Tracer = new TraceBuffer();
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);
@ -213,6 +213,8 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; private set; }
public ITracer Tracer { get; private set; }
string DetermineRegion(string gameRegion) string DetermineRegion(string gameRegion)
{ {
if (gameRegion == null) if (gameRegion == null)
@ -321,12 +323,12 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
lagged = true; lagged = true;
Frame++; Frame++;
PSG.BeginFrame(Cpu.TotalExecutedCycles); PSG.BeginFrame(Cpu.TotalExecutedCycles);
Cpu.Debug = CoreComm.Tracer.Enabled; Cpu.Debug = Tracer.Enabled;
if (!IsGameGear) if (!IsGameGear)
PSG.StereoPanning = Settings.ForceStereoSeparation ? ForceStereoByte : (byte) 0xFF; PSG.StereoPanning = Settings.ForceStereoSeparation ? ForceStereoByte : (byte) 0xFF;
if (Cpu.Debug && Cpu.Logger == null) // TODO, lets not do this on each frame. But lets refactor CoreComm/CoreComm first if (Cpu.Debug && Cpu.Logger == null) // TODO, lets not do this on each frame. But lets refactor CoreComm/CoreComm first
Cpu.Logger = (s) => CoreComm.Tracer.Put(s); Cpu.Logger = (s) => Tracer.Put(s);
if (IsGameGear == false) if (IsGameGear == false)
Cpu.NonMaskableInterrupt = Controller["Pause"]; Cpu.NonMaskableInterrupt = Controller["Pause"];

View File

@ -387,6 +387,16 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } } public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } }
private readonly TraceBuffer _tracer = new TraceBuffer();
public ITracer Tracer
{
get
{
return _tracer;
}
}
#endregion #endregion
// TODO: use render and rendersound // TODO: use render and rendersound

View File

@ -132,6 +132,15 @@ namespace BizHawk.Emulation.Cores.WonderSwan
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; private set; }
public ITracer Tracer
{
[FeatureNotImplemented]
get
{
throw new NotImplementedException();
}
}
public void Dispose() public void Dispose()
{ {
if (Core != IntPtr.Zero) if (Core != IntPtr.Zero)