Merge pull request #1462 from brian-armstrong/brian/mem_callback_addr_value

Studies show that PR's with threads exceeding 40 posts suffer a 50% greater chance of never getting merged for each additional post
This commit is contained in:
zeromus 2019-06-10 02:01:06 -04:00 committed by GitHub
commit 6a548220bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 237 additions and 123 deletions

View File

@ -13,28 +13,28 @@ namespace BizHawk.Client.ApiHawk
public MemEventsApi () : base() public MemEventsApi () : base()
{ } { }
public void AddReadCallback(Action cb, uint address, string domain) public void AddReadCallback(MemoryCallbackDelegate cb, uint? address, string domain)
{ {
if (DebuggableCore.MemoryCallbacksAvailable()) if (DebuggableCore.MemoryCallbacksAvailable())
{ {
DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(domain, MemoryCallbackType.Read, "Plugin Hook", cb, address, null)); DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(domain, MemoryCallbackType.Read, "Plugin Hook", cb, address, null));
} }
} }
public void AddWriteCallback(Action cb, uint address, string domain) public void AddWriteCallback(MemoryCallbackDelegate cb, uint? address, string domain)
{ {
if (DebuggableCore.MemoryCallbacksAvailable()) if (DebuggableCore.MemoryCallbacksAvailable())
{ {
DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(domain, MemoryCallbackType.Write, "Plugin Hook", cb, address, null)); DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(domain, MemoryCallbackType.Write, "Plugin Hook", cb, address, null));
} }
} }
public void AddExecCallback(Action cb, uint address, string domain) public void AddExecCallback(MemoryCallbackDelegate cb, uint? address, string domain)
{ {
if (DebuggableCore.MemoryCallbacksAvailable() && DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable) if (DebuggableCore.MemoryCallbacksAvailable() && DebuggableCore.MemoryCallbacks.ExecuteCallbacksAvailable)
{ {
DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(domain, MemoryCallbackType.Execute, "Plugin Hook", cb, address, null)); DebuggableCore.MemoryCallbacks.Add(new MemoryCallback(domain, MemoryCallbackType.Execute, "Plugin Hook", cb, address, null));
} }
} }
public void RemoveMemoryCallback(Action cb) public void RemoveMemoryCallback(MemoryCallbackDelegate cb)
{ {
if (DebuggableCore.MemoryCallbacksAvailable()) if (DebuggableCore.MemoryCallbacksAvailable())
{ {

View File

@ -1,12 +1,14 @@
using System; using System;
namespace BizHawk.Client.ApiHawk using BizHawk.Emulation.Common;
{
public interface IMemEvents : IExternalApi namespace BizHawk.Client.ApiHawk
{ {
void AddReadCallback(Action cb, uint address, string domain); public interface IMemEvents : IExternalApi
void AddWriteCallback(Action cb, uint address, string domain); {
void AddExecCallback(Action cb, uint address, string domain); void AddReadCallback(MemoryCallbackDelegate cb, uint? address, string domain);
void RemoveMemoryCallback(Action cb); void AddWriteCallback(MemoryCallbackDelegate cb, uint? address, string domain);
} void AddExecCallback(MemoryCallbackDelegate cb, uint? address, string domain);
} void RemoveMemoryCallback(MemoryCallbackDelegate cb);
}
}

View File

@ -231,7 +231,7 @@ namespace BizHawk.Client.Common
} }
DebuggableCore.MemoryCallbacks.Add( DebuggableCore.MemoryCallbacks.Add(
new MemoryCallback(domain, MemoryCallbackType.Execute, "Lua Hook", nlf.Callback, address, null)); new MemoryCallback(domain, MemoryCallbackType.Execute, "Lua Hook", nlf.MemCallback, address, null));
return nlf.Guid.ToString(); return nlf.Guid.ToString();
} }
} }
@ -270,7 +270,7 @@ namespace BizHawk.Client.Common
} }
DebuggableCore.MemoryCallbacks.Add( DebuggableCore.MemoryCallbacks.Add(
new MemoryCallback(domain, MemoryCallbackType.Read, "Lua Hook", nlf.Callback, address, null)); new MemoryCallback(domain, MemoryCallbackType.Read, "Lua Hook", nlf.MemCallback, address, null));
return nlf.Guid.ToString(); return nlf.Guid.ToString();
} }
} }
@ -309,7 +309,7 @@ namespace BizHawk.Client.Common
} }
DebuggableCore.MemoryCallbacks.Add( DebuggableCore.MemoryCallbacks.Add(
new MemoryCallback(domain, MemoryCallbackType.Write, "Lua Hook", nlf.Callback, address, null)); new MemoryCallback(domain, MemoryCallbackType.Write, "Lua Hook", nlf.MemCallback, address, null));
return nlf.Guid.ToString(); return nlf.Guid.ToString();
} }
} }

View File

@ -24,7 +24,7 @@ namespace BizHawk.Client.Common
if (Global.Emulator.MemoryCallbacksAvailable()) if (Global.Emulator.MemoryCallbacksAvailable())
{ {
Global.Emulator.AsDebuggable().MemoryCallbacks.Remove(function.Callback); Global.Emulator.AsDebuggable().MemoryCallbacks.Remove(function.MemCallback);
} }
return base.Remove(function); return base.Remove(function);
@ -40,7 +40,7 @@ namespace BizHawk.Client.Common
if (Global.Emulator.MemoryCallbacksAvailable()) if (Global.Emulator.MemoryCallbacksAvailable())
{ {
var memoryCallbacks = Global.Emulator.AsDebuggable().MemoryCallbacks; var memoryCallbacks = Global.Emulator.AsDebuggable().MemoryCallbacks;
memoryCallbacks.RemoveAll(this.Select(w => w.Callback)); memoryCallbacks.RemoveAll(this.Select(w => w.MemCallback));
} }
Clear(); Clear();

View File

@ -1,6 +1,8 @@
using System; using System;
using NLua; using NLua;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
public class NamedLuaFunction public class NamedLuaFunction
@ -26,6 +28,11 @@ namespace BizHawk.Client.Common
logCallback($"error running function attached by the event {Event}\nError message: {ex.Message}"); logCallback($"error running function attached by the event {Event}\nError message: {ex.Message}");
} }
}; };
MemCallback = delegate
{
Callback();
};
} }
public Guid Guid { get; private set; } public Guid Guid { get; private set; }
@ -38,6 +45,8 @@ namespace BizHawk.Client.Common
public Action Callback { get; } public Action Callback { get; }
public MemoryCallbackDelegate MemCallback { get; }
public void Call(string name = null) public void Call(string name = null)
{ {
LuaSandbox.Sandbox(Lua, () => LuaSandbox.Sandbox(Lua, () =>

View File

@ -7,7 +7,7 @@ namespace BizHawk.Client.EmuHawk
{ {
public class BreakpointList : List<Breakpoint> public class BreakpointList : List<Breakpoint>
{ {
public Action Callback { get; set; } public MemoryCallbackDelegate Callback { get; set; }
public void Add(IDebuggable core, string scope, uint address, uint mask, MemoryCallbackType type) public void Add(IDebuggable core, string scope, uint address, uint mask, MemoryCallbackType type)
{ {
@ -69,7 +69,7 @@ namespace BizHawk.Client.EmuHawk
private bool _active; private bool _active;
private readonly IDebuggable _core; private readonly IDebuggable _core;
public Breakpoint(bool readOnly, IDebuggable core, string scope, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) public Breakpoint(bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{ {
Scope = scope; Scope = scope;
_core = core; _core = core;
@ -83,7 +83,7 @@ namespace BizHawk.Client.EmuHawk
ReadOnly = readOnly; ReadOnly = readOnly;
} }
public Breakpoint(IDebuggable core, string scope, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) public Breakpoint(IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{ {
Scope = scope; Scope = scope;
_core = core; _core = core;
@ -96,7 +96,7 @@ namespace BizHawk.Client.EmuHawk
Active = enabled; Active = enabled;
} }
public Breakpoint(string name, bool readOnly, IDebuggable core, string scope, Action callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true) public Breakpoint(string name, bool readOnly, IDebuggable core, string scope, MemoryCallbackDelegate callBack, uint address, uint mask, MemoryCallbackType type, bool enabled = true)
{ {
Scope = scope; Scope = scope;
_core = core; _core = core;
@ -111,7 +111,7 @@ namespace BizHawk.Client.EmuHawk
} }
public string Scope { get; } public string Scope { get; }
public Action Callback { get; } public MemoryCallbackDelegate Callback { get; }
public uint? Address { get; set; } public uint? Address { get; set; }
public uint? AddressMask { get; set; } public uint? AddressMask { get; set; }
public MemoryCallbackType Type { get; set; } public MemoryCallbackType Type { get; set; }

View File

@ -60,16 +60,16 @@ namespace BizHawk.Client.EmuHawk
: Color.White; : Color.White;
} }
private void BreakpointCallback() private void BreakpointCallback(uint addr, uint value, uint flags)
{ {
GlobalWin.MainForm.PauseEmulator(); GlobalWin.MainForm.PauseEmulator();
UpdateValues(); UpdateValues();
GlobalWin.OSD.AddMessage("Breakpoint hit"); GlobalWin.OSD.AddMessage("Breakpoint hit");
} }
private void SeekCallback() private void SeekCallback(uint addr, uint value, uint flags)
{ {
BreakpointCallback(); BreakpointCallback(addr, value, flags);
var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWith(SeekName)); var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWith(SeekName));

View File

@ -46,7 +46,7 @@ namespace BizHawk.Emulation.Common
protected readonly List<TraceInfo> Buffer = new List<TraceInfo>(); protected readonly List<TraceInfo> Buffer = new List<TraceInfo>();
protected abstract void TraceFromCallback(); protected abstract void TraceFromCallback(uint addr, uint value, uint flags);
private ITraceSink _sink; private ITraceSink _sink;
@ -80,7 +80,7 @@ namespace BizHawk.Emulation.Common
public class TracingMemoryCallback : IMemoryCallback public class TracingMemoryCallback : IMemoryCallback
{ {
public TracingMemoryCallback(Action callback) public TracingMemoryCallback(MemoryCallbackDelegate callback)
{ {
Callback = callback; Callback = callback;
} }
@ -89,7 +89,7 @@ namespace BizHawk.Emulation.Common
public string Name => "Trace Logging"; public string Name => "Trace Logging";
public Action Callback { get; } public MemoryCallbackDelegate Callback { get; }
public uint? Address => null; public uint? Address => null;

View File

@ -67,38 +67,57 @@ namespace BizHawk.Emulation.Common
} }
} }
private static void Call(ObservableCollection<IMemoryCallback> cbs, uint addr, string scope) private static void Call(ObservableCollection<IMemoryCallback> cbs, uint addr, uint value, uint flags, string scope)
{ {
for (int i = 0; i < cbs.Count; i++) for (int i = 0; i < cbs.Count; i++)
{ {
if (!cbs[i].Address.HasValue || (cbs[i].Scope == scope && cbs[i].Address == (addr & cbs[i].AddressMask))) if (!cbs[i].Address.HasValue || (cbs[i].Scope == scope && cbs[i].Address == (addr & cbs[i].AddressMask)))
{ {
cbs[i].Callback(); cbs[i].Callback(addr, value, flags);
} }
} }
} }
public void CallReads(uint addr, string scope) public void CallMemoryCallbacks(uint addr, uint value, uint flags, string scope)
{
var flagEnum = (MemoryCallbackFlags)flags;
if (flagEnum.HasFlag(MemoryCallbackFlags.AccessRead) && _hasReads)
{
Call(_reads, addr, value, flags, scope);
}
if (flagEnum.HasFlag(MemoryCallbackFlags.AccessWrite) && _hasWrites)
{
Call(_writes, addr, value, flags, scope);
}
if (flagEnum.HasFlag(MemoryCallbackFlags.AccessExecute) && _hasExecutes)
{
Call(_execs, addr, value, flags, scope);
}
}
public void CallReads(uint addr, uint value, uint flags, string scope)
{ {
if (_hasReads) if (_hasReads)
{ {
Call(_reads, addr, scope); Call(_reads, addr, value, flags, scope);
} }
} }
public void CallWrites(uint addr, string scope) public void CallWrites(uint addr, uint value, uint flags, string scope)
{ {
if (_hasWrites) if (_hasWrites)
{ {
Call(_writes, addr, scope); Call(_writes, addr, value, flags, scope);
} }
} }
public void CallExecutes(uint addr, string scope) public void CallExecutes(uint addr, uint value, uint flags, string scope)
{ {
if (_hasExecutes) if (_hasExecutes)
{ {
Call(_execs, addr, scope); Call(_execs, addr, value, flags, scope);
} }
} }
@ -136,7 +155,7 @@ namespace BizHawk.Emulation.Common
return (_hasReads != hadReads || _hasWrites != hadWrites || _hasExecutes != hadExecutes); return (_hasReads != hadReads || _hasWrites != hadWrites || _hasExecutes != hadExecutes);
} }
private int RemoveInternal(Action action) private int RemoveInternal(MemoryCallbackDelegate action)
{ {
var readsToRemove = _reads.Where(imc => imc.Callback == action).ToList(); var readsToRemove = _reads.Where(imc => imc.Callback == action).ToList();
var writesToRemove = _writes.Where(imc => imc.Callback == action).ToList(); var writesToRemove = _writes.Where(imc => imc.Callback == action).ToList();
@ -160,7 +179,7 @@ namespace BizHawk.Emulation.Common
return readsToRemove.Count + writesToRemove.Count + execsToRemove.Count; return readsToRemove.Count + writesToRemove.Count + execsToRemove.Count;
} }
public void Remove(Action action) public void Remove(MemoryCallbackDelegate action)
{ {
if (RemoveInternal(action) > 0) if (RemoveInternal(action) > 0)
{ {
@ -171,7 +190,7 @@ namespace BizHawk.Emulation.Common
} }
} }
public void RemoveAll(IEnumerable<Action> actions) public void RemoveAll(IEnumerable<MemoryCallbackDelegate> actions)
{ {
bool changed = false; bool changed = false;
foreach (var action in actions) foreach (var action in actions)
@ -286,7 +305,7 @@ namespace BizHawk.Emulation.Common
public class MemoryCallback : IMemoryCallback public class MemoryCallback : IMemoryCallback
{ {
public MemoryCallback(string scope, MemoryCallbackType type, string name, Action callback, uint? address, uint? mask) public MemoryCallback(string scope, MemoryCallbackType type, string name, MemoryCallbackDelegate callback, uint? address, uint? mask)
{ {
if (type == MemoryCallbackType.Execute && !address.HasValue) if (type == MemoryCallbackType.Execute && !address.HasValue)
{ {
@ -303,7 +322,7 @@ namespace BizHawk.Emulation.Common
public MemoryCallbackType Type { get; } public MemoryCallbackType Type { get; }
public string Name { get; } public string Name { get; }
public Action Callback { get; } public MemoryCallbackDelegate Callback { get; }
public uint? Address { get; } public uint? Address { get; }
public uint? AddressMask { get; } public uint? AddressMask { get; }
public string Scope { get; } public string Scope { get; }

View File

@ -3,6 +3,9 @@ using System.Collections.Generic;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
public delegate void MemoryCallbackDelegate(uint address, uint value, uint flags);
/// <summary> /// <summary>
/// This is a property of <seealso cref="IDebuggable"/>, and defines the means by which a client /// This is a property of <seealso cref="IDebuggable"/>, and defines the means by which a client
/// gets and sets memory callbacks in the core. A memory callback should fire any time memory is /// gets and sets memory callbacks in the core. A memory callback should fire any time memory is
@ -61,35 +64,23 @@ namespace BizHawk.Emulation.Common
void Add(IMemoryCallback callback); void Add(IMemoryCallback callback);
/// <summary> /// <summary>
/// Executes all Read callbacks for the given address and domain /// Executes all matching callbacks for the given address and domain
/// </summary> /// </summary>
/// <param name="addr">The address to check for callbacks</param> /// <param name="addr">The address to check for callbacks</param>
/// <param name="value">The value contained (or written to) addr</param>
/// <param name="flags">The callback flags relevant to this access</param>
/// <param name="scope">The scope that the address pertains to. Must be a value in <see cref="AvailableScopes"></param> /// <param name="scope">The scope that the address pertains to. Must be a value in <see cref="AvailableScopes"></param>
void CallReads(uint addr, string scope); void CallMemoryCallbacks(uint addr, uint value, uint flags, string scope);
/// <summary>
/// Executes all Write callbacks for the given address and domain
/// </summary>
/// <param name="addr">The address to check for callbacks</param>
/// <param name="scope">The scope that the address pertains to. Must be a value in <see cref="AvailableScopes"></param>
void CallWrites(uint addr, string scope);
/// <summary>
/// Executes all Execute callbacks for the given address and domain
/// </summary>
/// <param name="addr">The address to check for callbacks</param>
/// <param name="scope">The scope that the address pertains to. Must be a value in <see cref="AvailableScopes"></param>
void CallExecutes(uint addr, string scope);
/// <summary> /// <summary>
/// Removes the given callback from the list /// Removes the given callback from the list
/// </summary> /// </summary>
void Remove(Action action); void Remove(MemoryCallbackDelegate action);
/// <summary> /// <summary>
/// Removes the given callbacks from the list /// Removes the given callbacks from the list
/// </summary> /// </summary>
void RemoveAll(IEnumerable<Action> actions); void RemoveAll(IEnumerable<MemoryCallbackDelegate> actions);
/// <summary> /// <summary>
/// Removes all read,write, and execute callbacks /// Removes all read,write, and execute callbacks
@ -111,7 +102,7 @@ namespace BizHawk.Emulation.Common
{ {
MemoryCallbackType Type { get; } MemoryCallbackType Type { get; }
string Name { get; } string Name { get; }
Action Callback { get; } MemoryCallbackDelegate Callback { get; }
uint? Address { get; } uint? Address { get; }
uint? AddressMask { get; } uint? AddressMask { get; }
string Scope { get; } string Scope { get; }
@ -121,4 +112,20 @@ namespace BizHawk.Emulation.Common
{ {
Read, Write, Execute Read, Write, Execute
} }
[Flags]
public enum MemoryCallbackFlags : uint
{
SizeUnknown = 0x00 << 16,
SizeByte = 0x01 << 16,
SizeWord = 0x02 << 16,
SizeLong = 0x03 << 16,
AccessUnknown = 0x00 << 12,
AccessRead = 0x01 << 12,
AccessWrite = 0x02 << 12,
AccessExecute = 0x04 << 12,
CPUUnknown = 0x00 << 8,
CPUZero = 0x01 << 8,
DomainUnknown = 0x00,
}
} }

View File

@ -192,7 +192,8 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
if (MemoryCallbacks != null) if (MemoryCallbacks != null)
{ {
MemoryCallbacks.CallExecutes(RegisterPC, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(RegisterPC, 0, flags, "System Bus");
} }
switch (opcode) switch (opcode)

View File

@ -31,7 +31,8 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
{ {
if (MemoryCallbacks != null && !peek) if (MemoryCallbacks != null && !peek)
{ {
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
return ReadMemory(addr, peek); return ReadMemory(addr, peek);
@ -41,7 +42,8 @@ namespace BizHawk.Emulation.Cores.Components.CP1610
{ {
if (MemoryCallbacks != null && !poke) if (MemoryCallbacks != null && !poke)
{ {
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
} }
WriteMemory(addr, value, poke); WriteMemory(addr, value, poke);

View File

@ -60,7 +60,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
LagIFlag = FlagI; LagIFlag = FlagI;
if (Debug) Logger(State()); if (Debug) Logger(State());
MemoryCallbacks.CallExecutes(PC, "System Bus"); MemoryCallbacks.CallMemoryCallbacks(PC, 0, (uint)MemoryCallbackFlags.AccessExecute, "System Bus");
if (CDL != null && CDL.Active) CDLOpcode(); if (CDL != null && CDL.Active) CDLOpcode();

View File

@ -230,7 +230,8 @@ namespace BizHawk.Emulation.Cores.Components.H6280
{ {
byte page = MPR[address >> 13]; byte page = MPR[address >> 13];
var result = ReadMemory21((page << 13) | (address & 0x1FFF)); var result = ReadMemory21((page << 13) | (address & 0x1FFF));
MemoryCallbacks.CallReads(address, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(address, result, flags, "System Bus");
return result; return result;
} }
@ -238,7 +239,8 @@ namespace BizHawk.Emulation.Cores.Components.H6280
{ {
byte page = MPR[address >> 13]; byte page = MPR[address >> 13];
WriteMemory21((page << 13) | (address & 0x1FFF), value); WriteMemory21((page << 13) | (address & 0x1FFF), value);
MemoryCallbacks.CallWrites(address, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(address, value, flags, "System Bus");
} }
private ushort ReadWord(ushort address) private ushort ReadWord(ushort address)

View File

@ -183,9 +183,21 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
private void SetCallbacks() private void SetCallbacks()
{ {
_machine.Memory.ReadCallback = (addr) => MemoryCallbacks.CallReads(addr, "System Bus"); _machine.Memory.ReadCallback = (addr) =>
_machine.Memory.WriteCallback = (addr) => MemoryCallbacks.CallWrites(addr, "System Bus"); {
_machine.Memory.ExecuteCallback = (addr) => MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
};
_machine.Memory.WriteCallback = (addr) =>
{
uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
};
_machine.Memory.ExecuteCallback = (addr) =>
{
uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
};
_machine.Memory.InputCallback = InputCallbacks.Call; _machine.Memory.InputCallback = InputCallbacks.Call;
} }
} }

View File

@ -160,7 +160,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
_mapper.Bit13 = addr.Bit(13); _mapper.Bit13 = addr.Bit(13);
var temp = _mapper.ReadMemory((ushort)(addr & 0x1FFF)); var temp = _mapper.ReadMemory((ushort)(addr & 0x1FFF));
_tia.BusState = temp; _tia.BusState = temp;
MemoryCallbacks.CallReads(addr, "System Bus"); var flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
return temp; return temp;
} }
@ -180,8 +181,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
} }
_mapper.WriteMemory((ushort)(addr & 0x1FFF), value); _mapper.WriteMemory((ushort)(addr & 0x1FFF), value);
var flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallWrites(addr, "System Bus"); MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
} }
internal void PokeMemory(ushort addr, byte value) internal void PokeMemory(ushort addr, byte value)
@ -191,7 +192,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
private void ExecFetch(ushort addr) private void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); var flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
private void RebootCore() private void RebootCore()

View File

@ -291,7 +291,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
private void ExecFetch(ushort addr) private void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
private void Reset_Mapper(string m) private void Reset_Mapper(string m)

View File

@ -20,7 +20,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
{ {
public byte ReadMemory(ushort addr) public byte ReadMemory(ushort addr)
{ {
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)(Common.MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
if ((addr & 0xFCE0) == 0) if ((addr & 0xFCE0) == 0)
{ {
@ -98,7 +99,8 @@ namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
public void WriteMemory(ushort addr, byte value) public void WriteMemory(ushort addr, byte value)
{ {
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)(Common.MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
if ((addr & 0xFCE0) == 0) if ((addr & 0xFCE0) == 0)
{ {

View File

@ -20,7 +20,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
{ {
public byte ReadMemory(ushort addr) public byte ReadMemory(ushort addr)
{ {
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)MemoryCallbackFlags.AccessRead;
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
if (addr < 0x8000) if (addr < 0x8000)
{ {
@ -54,7 +55,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
public void WriteMemory(ushort addr, byte value) public void WriteMemory(ushort addr, byte value)
{ {
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)MemoryCallbackFlags.AccessWrite;
MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
if (addr < 0x8000) if (addr < 0x8000)
{ {

View File

@ -123,7 +123,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Vectrex
private void ExecFetch(ushort addr) private void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)MemoryCallbackFlags.AccessExecute;
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
private void Setup_Mapper() private void Setup_Mapper()

View File

@ -168,9 +168,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
void InitCallbacks() void InitCallbacks()
{ {
padcb = new LibVBANext.StandardCallback(() => InputCallbacks.Call()); padcb = new LibVBANext.StandardCallback(() => InputCallbacks.Call());
fetchcb = new LibVBANext.AddressCallback((addr) => MemoryCallbacks.CallExecutes(addr, "System Bus")); fetchcb = new LibVBANext.AddressCallback((addr) => {
readcb = new LibVBANext.AddressCallback((addr) => MemoryCallbacks.CallReads(addr, "System Bus")); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
writecb = new LibVBANext.AddressCallback((addr) => MemoryCallbacks.CallWrites(addr, "System Bus")); MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
});
readcb = new LibVBANext.AddressCallback((addr) =>
{
uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
});
writecb = new LibVBANext.AddressCallback((addr) =>
{
uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
});
tracecb = new LibVBANext.TraceCallback((addr, opcode) => Tracer.Put(Trace(addr, opcode))); tracecb = new LibVBANext.TraceCallback((addr, opcode) => Tracer.Put(Trace(addr, opcode)));
_inputCallbacks.ActiveChanged += SyncPadCallback; _inputCallbacks.ActiveChanged += SyncPadCallback;
_memorycallbacks.ActiveChanged += SyncMemoryCallbacks; _memorycallbacks.ActiveChanged += SyncMemoryCallbacks;

View File

@ -294,7 +294,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
private void ExecFetch(ushort addr) private void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
private void Setup_Mapper() private void Setup_Mapper()

View File

@ -29,7 +29,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{ {
public byte ReadMemory(ushort addr) public byte ReadMemory(ushort addr)
{ {
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
addr_access = addr; addr_access = addr;
if (ppu.DMA_start) if (ppu.DMA_start)
@ -157,7 +158,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
public void WriteMemory(ushort addr, byte value) public void WriteMemory(ushort addr, byte value)
{ {
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
addr_access = addr; addr_access = addr;
if (ppu.DMA_start) if (ppu.DMA_start)

View File

@ -93,8 +93,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
} }
private void ExecFetch(ushort addr) private void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
} }
} }

View File

@ -59,19 +59,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
private void ReadCallback(uint address, ulong cycleOffset) private void ReadCallback(uint address, ulong cycleOffset)
{ {
callbackCycleCount = _cycleCount + cycleOffset; callbackCycleCount = _cycleCount + cycleOffset;
MemoryCallbacks.CallReads(address, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(address, 0, flags, "System Bus");
} }
private void WriteCallback(uint address, ulong cycleOffset) private void WriteCallback(uint address, ulong cycleOffset)
{ {
callbackCycleCount = _cycleCount + cycleOffset; callbackCycleCount = _cycleCount + cycleOffset;
MemoryCallbacks.CallWrites(address, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(address, 0, flags,"System Bus");
} }
private void ExecCallback(uint address, ulong cycleOffset) private void ExecCallback(uint address, ulong cycleOffset)
{ {
callbackCycleCount = _cycleCount + cycleOffset; callbackCycleCount = _cycleCount + cycleOffset;
MemoryCallbacks.CallExecutes(address, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(address, 0, flags, "System Bus");
} }
/// <summary> /// <summary>

View File

@ -752,19 +752,22 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64.NativeApi
break; break;
if (event_breakpoint) if (event_breakpoint)
{ {
MemoryCallbackFlags flags = 0;
switch (_breakparams._type) switch (_breakparams._type)
{ {
case BreakType.Read: case BreakType.Read:
_breakparams._mcs.CallReads(_breakparams._addr, "System Bus"); flags |= MemoryCallbackFlags.AccessRead;
break; break;
case BreakType.Write: case BreakType.Write:
_breakparams._mcs.CallWrites(_breakparams._addr, "System Bus"); flags |= MemoryCallbackFlags.AccessWrite;
break; break;
case BreakType.Execute: case BreakType.Execute:
_breakparams._mcs.CallExecutes(_breakparams._addr, "System Bus"); flags |= MemoryCallbackFlags.AccessExecute;
break; break;
} }
_breakparams._mcs.CallMemoryCallbacks(_breakparams._addr, 0, (uint)flags, "System Bus");
event_breakpoint = false; event_breakpoint = false;
Resume(); Resume();
continue; continue;

View File

@ -898,7 +898,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public void ExecFetch(ushort addr) public void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.CPUZero | MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
public byte ReadMemory(ushort addr) public byte ReadMemory(ushort addr)
@ -948,7 +949,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
} }
} }
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.CPUZero | MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, ret, flags, "System Bus");
DB = ret; DB = ret;
return ret; return ret;
@ -995,7 +997,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
Board.WritePRG(addr - 0x8000, value); Board.WritePRG(addr - 0x8000, value);
} }
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.CPUZero | MemoryCallbackFlags.AccessWrite | MemoryCallbackFlags.SizeByte);
MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
} }
// the palette for each VS game needs to be chosen explicitly since there are 6 different ones. // the palette for each VS game needs to be chosen explicitly since there are 6 different ones.

View File

@ -364,7 +364,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private void ReadHook(uint addr) private void ReadHook(uint addr)
{ {
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
// we RefreshMemoryCallbacks() after the trigger in case the trigger turns itself off at that point // we RefreshMemoryCallbacks() after the trigger in case the trigger turns itself off at that point
// EDIT: for now, theres some IPC re-entrancy problem // EDIT: for now, theres some IPC re-entrancy problem
// RefreshMemoryCallbacks(); // RefreshMemoryCallbacks();
@ -372,7 +373,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private void ExecHook(uint addr) private void ExecHook(uint addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
// we RefreshMemoryCallbacks() after the trigger in case the trigger turns itself off at that point // we RefreshMemoryCallbacks() after the trigger in case the trigger turns itself off at that point
// EDIT: for now, theres some IPC re-entrancy problem // EDIT: for now, theres some IPC re-entrancy problem
// RefreshMemoryCallbacks(); // RefreshMemoryCallbacks();
@ -380,7 +382,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private void WriteHook(uint addr, byte val) private void WriteHook(uint addr, byte val)
{ {
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, val, flags, "System Bus");
// we RefreshMemoryCallbacks() after the trigger in case the trigger turns itself off at that point // we RefreshMemoryCallbacks() after the trigger in case the trigger turns itself off at that point
// EDIT: for now, theres some IPC re-entrancy problem // EDIT: for now, theres some IPC re-entrancy problem
// RefreshMemoryCallbacks(); // RefreshMemoryCallbacks();
@ -388,17 +391,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
private void ReadHook_SMP(uint addr) private void ReadHook_SMP(uint addr)
{ {
MemoryCallbacks.CallReads(addr, "SMP"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "SMP");
} }
private void ExecHook_SMP(uint addr) private void ExecHook_SMP(uint addr)
{ {
MemoryCallbacks.CallExecutes(addr, "SMP"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "SMP");
} }
private void WriteHook_SMP(uint addr, byte val) private void WriteHook_SMP(uint addr, byte val)
{ {
MemoryCallbacks.CallWrites(addr, "SMP"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, val, flags, "SMP");
} }
private enum LoadParamType private enum LoadParamType

View File

@ -72,8 +72,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk
private readonly ITraceable _tracer; private readonly ITraceable _tracer;
private void ExecFetch(ushort addr) private void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
#region ISettable #region ISettable

View File

@ -90,7 +90,8 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
private void ExecFetch(ushort addr) private void ExecFetch(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)MemoryCallbackFlags.AccessExecute;
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
} }
} }

View File

@ -298,7 +298,8 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
public byte ReadMemory(ushort addr) public byte ReadMemory(ushort addr)
{ {
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
return ReadMemoryMapper(addr); return ReadMemoryMapper(addr);
} }
@ -307,7 +308,8 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
{ {
WriteMemoryMapper(addr, value); WriteMemoryMapper(addr, value);
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, value, flags, "System Bus");
} }
public byte FetchMemory(ushort addr) public byte FetchMemory(ushort addr)
@ -317,7 +319,8 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
private void OnExecMemory(ushort addr) private void OnExecMemory(ushort addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
/// <summary> /// <summary>

View File

@ -61,9 +61,21 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
private void InitMemCallbacks() private void InitMemCallbacks()
{ {
ExecCallback = new LibGPGX.mem_cb(a => MemoryCallbacks.CallExecutes(a, "M68K BUS")); ExecCallback = new LibGPGX.mem_cb(a =>
ReadCallback = new LibGPGX.mem_cb(a => MemoryCallbacks.CallReads(a, "M68K BUS")); {
WriteCallback = new LibGPGX.mem_cb(a => MemoryCallbacks.CallWrites(a, "M68K BUS")); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(a, 0, flags, "M68K BUS");
});
ReadCallback = new LibGPGX.mem_cb(a =>
{
uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(a, 0, flags, "M68K BUS");
});
WriteCallback = new LibGPGX.mem_cb(a =>
{
uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(a, 0, flags, "M68K BUS");
});
_memoryCallbacks.ActiveChanged += RefreshMemCallbacks; _memoryCallbacks.ActiveChanged += RefreshMemCallbacks;
} }

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
Header = "M68K: PC, machine code, mnemonic, operands, registers (D0-D7, A0-A7, SR, USP), flags (XNZVC)"; Header = "M68K: PC, machine code, mnemonic, operands, registers (D0-D7, A0-A7, SR, USP), flags (XNZVC)";
} }
protected override void TraceFromCallback() protected override void TraceFromCallback(uint addr, uint value, uint flags)
{ {
var regs = DebuggableCore.GetCpuFlagsAndRegisters(); var regs = DebuggableCore.GetCpuFlagsAndRegisters();
uint pc = (uint)regs["M68K PC"].Value; uint pc = (uint)regs["M68K PC"].Value;

View File

@ -880,18 +880,20 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
void ShockMemCallback(uint address, OctoshockDll.eShockMemCb type, uint size, uint value) void ShockMemCallback(uint address, OctoshockDll.eShockMemCb type, uint size, uint value)
{ {
MemoryCallbackFlags flags = 0;
switch (type) switch (type)
{ {
case OctoshockDll.eShockMemCb.Read: case OctoshockDll.eShockMemCb.Read:
MemoryCallbacks.CallReads(address, "System Bus"); flags |= MemoryCallbackFlags.AccessRead;
break; break;
case OctoshockDll.eShockMemCb.Write: case OctoshockDll.eShockMemCb.Write:
MemoryCallbacks.CallWrites(address, "System Bus"); flags |= MemoryCallbackFlags.AccessWrite;
break; break;
case OctoshockDll.eShockMemCb.Execute: case OctoshockDll.eShockMemCb.Execute:
MemoryCallbacks.CallExecutes(address, "System Bus"); flags |= MemoryCallbackFlags.AccessExecute;
break; break;
} }
MemoryCallbacks.CallMemoryCallbacks(address, value, (uint)flags, "System Bus");
} }
void InitMemCallbacks() void InitMemCallbacks()

View File

@ -142,15 +142,18 @@ namespace BizHawk.Emulation.Cores.WonderSwan
void ReadCallback(uint addr) void ReadCallback(uint addr)
{ {
MemoryCallbacks.CallReads(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessRead);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
void WriteCallback(uint addr) void WriteCallback(uint addr)
{ {
MemoryCallbacks.CallWrites(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessWrite);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
void ExecCallback(uint addr) void ExecCallback(uint addr)
{ {
MemoryCallbacks.CallExecutes(addr, "System Bus"); uint flags = (uint)(MemoryCallbackFlags.AccessExecute);
MemoryCallbacks.CallMemoryCallbacks(addr, 0, flags, "System Bus");
} }
void ButtonCallback() void ButtonCallback()
{ {