public void Add(IMemoryCallback callback) { if (!AvailableScopes.Contains(callback.Scope)) { throw new InvalidOperationException($"{callback.Scope} is not currently supported for callbacks"); } if (!callback.Address.HasValue) { throw new NotImplementedException("Wildcard callbacks (no address specified) not currently implemented."); } var container = new CallbackContainer(callback); if (container.Callback.Type == MemoryCallbackType.Execute) { _executeCallback = RunExecCallback; _execPcs[callback.Address.Value] = callback; LibmGBA.BizSetExecCallback(_executeCallback); } else { LibmGBA.BizSetMemCallback(container.CallDelegate); container.ID = LibmGBA.BizSetWatchpoint(_mgba.Core, callback.Address.Value, container.WatchPointType); } _callbacks.Add(container); }
public void Remove(MemoryCallbackDelegate action) { var cbToRemove = _callbacks.SingleOrDefault(container => container.Callback.Callback == action); if (cbToRemove != null) { if (cbToRemove.Callback.Type == MemoryCallbackType.Execute) { _callbacks.Remove(cbToRemove); if (_callbacks.All(cb => cb.Callback.Type != MemoryCallbackType.Execute)) { _executeCallback = null; LibmGBA.BizSetExecCallback(null); } } else if (LibmGBA.BizClearWatchpoint(_mgba.Core, cbToRemove.ID)) { _callbacks.Remove(cbToRemove); } } }