From e5b6921c7d75f84ee9cbb0649e3b61caf4f81121 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 21 Feb 2016 11:12:56 -0500 Subject: [PATCH] GPGX - trace logging support, the output is very bad, needs to be cleaned up --- .../BizHawk.Emulation.Cores.csproj | 23 ++-- .../Consoles/Sega/gpgx/GPGX.ITraceable.cs | 121 ++++++++++++++++++ .../Consoles/Sega/gpgx/GPGX.cs | 5 +- 3 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.ITraceable.cs diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 2095bf3957..e729bc31ad 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -771,37 +771,38 @@ - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs - GPGX.cs + GPGX.cs + - GPGX.cs + GPGX.cs diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.ITraceable.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.ITraceable.cs new file mode 100644 index 0000000000..ccda3d7885 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.ITraceable.cs @@ -0,0 +1,121 @@ +using BizHawk.Emulation.Common; +using System; +using System.Text; +using BizHawk.Emulation.Common.IEmulatorExtensions; + +namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx +{ + public partial class GPGX + { + private readonly ITraceable Tracer; + + // TODO: move this to BaseImplementations and make the TraceFromCallback settable by the core + public class CallbackBasedTraceBuffer : ITraceable + { + public CallbackBasedTraceBuffer(IDebuggable debuggableCore) + { + if (!debuggableCore.MemoryCallbacksAvailable()) + { + throw new InvalidOperationException("Memory callbacks are required"); + } + + try + { + var dummy = debuggableCore.GetCpuFlagsAndRegisters(); + } + catch(NotImplementedException) + { + throw new InvalidOperationException("GetCpuFlagsAndRegisters is required"); + } + + Buffer = new StringBuilder(); + Header = "Instructions"; + DebuggableCore = debuggableCore; + + } + + private readonly IDebuggable DebuggableCore; + + private readonly StringBuilder Buffer; + + private bool _enabled; + + private void TraceFromCallback() + { + var regs = DebuggableCore.GetCpuFlagsAndRegisters(); + foreach(var r in regs) + { + Buffer.Append(string.Format("{0} {1}", r.Key, r.Value.Value)); + } + + Buffer.AppendLine(); + } + + 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 string Contents + { + get { return Buffer.ToString(); } + } + + public string TakeContents() + { + string s = Buffer.ToString(); + Buffer.Clear(); + return s; + } + + public void Put(string content) + { + if (_enabled) + { + Buffer.AppendLine(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; } + } + } + } + } +} diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs index 7f6f48326a..7cc3449241 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs @@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx )] public partial class GPGX : IEmulator, ISyncSoundProvider, IVideoProvider, ISaveRam, IStatable, IRegionable, IInputPollable, IDebuggable, IDriveLight, ICodeDataLogger, IDisassemblable - { + { static GPGX AttachedCore = null; DiscSystem.Disc CD; @@ -161,6 +161,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx InitMemCallbacks(); KillMemCallbacks(); + + Tracer = new CallbackBasedTraceBuffer(this); + (ServiceProvider as BasicServiceProvider).Register(Tracer); } catch {