Refactor GPGX trace logger - make a CallbackBasedTraceBuffer abstract class in Base Implementations with an abstract method CreateTrace, and inherit it as a GPGXTraceBuffer.
This commit is contained in:
parent
75df712563
commit
f9c9994161
|
@ -0,0 +1,109 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
||||||
|
|
||||||
|
namespace BizHawk.Emulation.Common
|
||||||
|
{
|
||||||
|
public abstract class CallbackBasedTraceBuffer : ITraceable
|
||||||
|
{
|
||||||
|
public CallbackBasedTraceBuffer(IDebuggable debuggableCore, IMemoryDomains memoryDomains, IDisassemblable disassembler)
|
||||||
|
{
|
||||||
|
if (!debuggableCore.MemoryCallbacksAvailable())
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Memory callbacks are required");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dummy = debuggableCore.GetCpuFlagsAndRegisters();
|
||||||
|
}
|
||||||
|
catch (NotImplementedException)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("GetCpuFlagsAndRegisters is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
Header = "Instructions";
|
||||||
|
DebuggableCore = debuggableCore;
|
||||||
|
MemoryDomains = memoryDomains;
|
||||||
|
Disassembler = disassembler;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly IMemoryDomains MemoryDomains;
|
||||||
|
protected readonly IDisassemblable Disassembler;
|
||||||
|
protected readonly IDebuggable DebuggableCore;
|
||||||
|
|
||||||
|
protected readonly List<TraceInfo> Buffer = new List<TraceInfo>();
|
||||||
|
|
||||||
|
private bool _enabled;
|
||||||
|
|
||||||
|
public abstract void TraceFromCallback();
|
||||||
|
|
||||||
|
public bool Enabled
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_enabled = value;
|
||||||
|
DebuggableCore.MemoryCallbacks.Remove(TraceFromCallback);
|
||||||
|
|
||||||
|
if (_enabled)
|
||||||
|
{
|
||||||
|
DebuggableCore.MemoryCallbacks.Add(new TracingMemoryCallback(TraceFromCallback));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Header { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<TraceInfo> Contents
|
||||||
|
{
|
||||||
|
get { return Buffer; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<TraceInfo> TakeContents()
|
||||||
|
{
|
||||||
|
var contents = Buffer.ToList();
|
||||||
|
Buffer.Clear();
|
||||||
|
return contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Put(TraceInfo content)
|
||||||
|
{
|
||||||
|
if (Enabled)
|
||||||
|
{
|
||||||
|
Buffer.Add(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TracingMemoryCallback : IMemoryCallback
|
||||||
|
{
|
||||||
|
public TracingMemoryCallback(Action callback)
|
||||||
|
{
|
||||||
|
Callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemoryCallbackType Type
|
||||||
|
{
|
||||||
|
get { return MemoryCallbackType.Execute; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "Trace Logging"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Callback { get; private set; }
|
||||||
|
|
||||||
|
public uint? Address
|
||||||
|
{
|
||||||
|
get { return null; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,6 +55,7 @@
|
||||||
<Link>VersionInfo.cs</Link>
|
<Link>VersionInfo.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Base Implementations\BasicServiceProvider.cs" />
|
<Compile Include="Base Implementations\BasicServiceProvider.cs" />
|
||||||
|
<Compile Include="Base Implementations\CallbackBasedTraceBuffer.cs" />
|
||||||
<Compile Include="Base Implementations\ControllerDefinition.cs" />
|
<Compile Include="Base Implementations\ControllerDefinition.cs" />
|
||||||
<Compile Include="Base Implementations\InputCallbackSystem.cs" />
|
<Compile Include="Base Implementations\InputCallbackSystem.cs" />
|
||||||
<Compile Include="Base Implementations\MemoryCallbackSystem.cs" />
|
<Compile Include="Base Implementations\MemoryCallbackSystem.cs" />
|
||||||
|
|
|
@ -817,7 +817,9 @@
|
||||||
<Compile Include="Consoles\Sega\gpgx\GPGX.IStatable.cs">
|
<Compile Include="Consoles\Sega\gpgx\GPGX.IStatable.cs">
|
||||||
<DependentUpon>GPGX.cs</DependentUpon>
|
<DependentUpon>GPGX.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Consoles\Sega\gpgx\GPGX.ITraceable.cs" />
|
<Compile Include="Consoles\Sega\gpgx\GPGX.ITraceable.cs">
|
||||||
|
<DependentUpon>GPGX.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Consoles\Sega\gpgx\GPGX.IVideoProvider.cs">
|
<Compile Include="Consoles\Sega\gpgx\GPGX.IVideoProvider.cs">
|
||||||
<DependentUpon>GPGX.cs</DependentUpon>
|
<DependentUpon>GPGX.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
|
||||||
using BizHawk.Common.NumberExtensions;
|
using BizHawk.Common.NumberExtensions;
|
||||||
|
|
||||||
namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
||||||
|
@ -12,43 +11,15 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
||||||
{
|
{
|
||||||
private readonly ITraceable Tracer;
|
private readonly ITraceable Tracer;
|
||||||
|
|
||||||
// TODO: move this to BaseImplementations and make the TraceFromCallback settable by the core
|
public class GPGXTraceBuffer : CallbackBasedTraceBuffer
|
||||||
public class CallbackBasedTraceBuffer : ITraceable
|
|
||||||
{
|
{
|
||||||
public CallbackBasedTraceBuffer(IDebuggable debuggableCore)
|
public GPGXTraceBuffer(IDebuggable debuggableCore, IMemoryDomains memoryDomains, IDisassemblable disassembler)
|
||||||
|
: base(debuggableCore, memoryDomains, disassembler)
|
||||||
{
|
{
|
||||||
if (!debuggableCore.MemoryCallbacksAvailable())
|
Header = "M68K Instructions";
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Memory callbacks are required");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var dummy = debuggableCore.GetCpuFlagsAndRegisters();
|
|
||||||
}
|
|
||||||
catch(NotImplementedException)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("GetCpuFlagsAndRegisters is required");
|
|
||||||
}
|
|
||||||
|
|
||||||
Header = "Instructions";
|
|
||||||
DebuggableCore = debuggableCore;
|
|
||||||
|
|
||||||
// TODO: refactor
|
|
||||||
MemoryDomains = (debuggableCore as IEmulator).ServiceProvider.GetService<IMemoryDomains>();
|
|
||||||
Disassembler = (debuggableCore as IEmulator).ServiceProvider.GetService<IDisassemblable>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: think about this
|
public override void TraceFromCallback()
|
||||||
private readonly IMemoryDomains MemoryDomains;
|
|
||||||
private readonly IDisassemblable Disassembler;
|
|
||||||
private readonly IDebuggable DebuggableCore;
|
|
||||||
|
|
||||||
private readonly List<TraceInfo> Buffer = new List<TraceInfo>();
|
|
||||||
|
|
||||||
private bool _enabled;
|
|
||||||
|
|
||||||
private void TraceFromCallback()
|
|
||||||
{
|
{
|
||||||
var regs = DebuggableCore.GetCpuFlagsAndRegisters();
|
var regs = DebuggableCore.GetCpuFlagsAndRegisters();
|
||||||
uint pc = (uint)regs["M68K PC"].Value;
|
uint pc = (uint)regs["M68K PC"].Value;
|
||||||
|
@ -57,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
||||||
|
|
||||||
var traceInfo = new TraceInfo
|
var traceInfo = new TraceInfo
|
||||||
{
|
{
|
||||||
Disassembly = string.Format("{0:X6}: {1,-32}", pc, disasm)
|
Disassembly = string.Format("{0:X6}: {1}", pc, disasm)
|
||||||
};
|
};
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
@ -90,72 +61,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
||||||
|
|
||||||
Buffer.Add(traceInfo);
|
Buffer.Add(traceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Enabled
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_enabled = value;
|
|
||||||
DebuggableCore.MemoryCallbacks.Remove(TraceFromCallback);
|
|
||||||
|
|
||||||
if (_enabled)
|
|
||||||
{
|
|
||||||
DebuggableCore.MemoryCallbacks.Add(new TracingMemoryCallback(TraceFromCallback));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Header { get; set; }
|
|
||||||
|
|
||||||
public IEnumerable<TraceInfo> Contents
|
|
||||||
{
|
|
||||||
get { return Buffer; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<TraceInfo> TakeContents()
|
|
||||||
{
|
|
||||||
var contents = Buffer.ToList();
|
|
||||||
Buffer.Clear();
|
|
||||||
return contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Put(TraceInfo content)
|
|
||||||
{
|
|
||||||
if (Enabled)
|
|
||||||
{
|
|
||||||
Buffer.Add(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TracingMemoryCallback : IMemoryCallback
|
|
||||||
{
|
|
||||||
public TracingMemoryCallback(Action callback)
|
|
||||||
{
|
|
||||||
Callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemoryCallbackType Type
|
|
||||||
{
|
|
||||||
get { return MemoryCallbackType.Execute; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get { return "Trace Logging"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action Callback { get; private set; }
|
|
||||||
|
|
||||||
public uint? Address
|
|
||||||
{
|
|
||||||
get { return null; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
|
||||||
InitMemCallbacks();
|
InitMemCallbacks();
|
||||||
KillMemCallbacks();
|
KillMemCallbacks();
|
||||||
|
|
||||||
Tracer = new CallbackBasedTraceBuffer(this);
|
Tracer = new GPGXTraceBuffer(this, MemoryDomains, this);
|
||||||
(ServiceProvider as BasicServiceProvider).Register<ITraceable>(Tracer);
|
(ServiceProvider as BasicServiceProvider).Register<ITraceable>(Tracer);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
Loading…
Reference in New Issue