/// <summary>Handle register changes so the client can be notified about asynchronous changes like interrupts.</summary> private Action<IProcessor, IRegister> RegisterChanged(IDispatcherItem item) => (processor, register) => { if (register.Type == Registers.Interrupt) { var guid = item.Guid.ToString(); Clients.Group(guid).ProcessorInterrupt(processor.Registers[Registers.Interrupt].Value); } };
/// <summary>Notifies, simulation step finished.</summary> /// <param name="item">Processor which was simulated</param> /// <param name="stepSize">Simulated step size.</param> /// <param name="ramChanges">Changes done to the ram during the simulation step.</param> /// <param name="registerChanges">Changes done to the registers during the simulation step.</param> private void NotifyFinishedStep(IDispatcherItem item, SimulationStepSize stepSize, IReadOnlyDictionary<byte, byte> ramChanges, IReadOnlyDictionary<Registers, IRegister> registerChanges) { Action<IDispatcherItem, SimulationStepSize, IReadOnlyDictionary<byte, byte>, IReadOnlyDictionary<Registers, IRegister>> handler; lock (eventLock) { handler = finishedStep; } if (handler != null) { //Call handler outside of the lock, so called handle methods will not caue a deadlock. //This is safe because delegates are immutable. handler(item, stepSize, ramChanges, registerChanges); } }
/// <summary>Called, when a reset or halt was processed.</summary> /// <param name="item">Processor, which was resetted/halted.</param> private void StateChanged(IDispatcherItem item, StateChange stateChange) { var group = Clients.Group(item.Guid.ToString()); switch (stateChange) { case StateChange.SoftReset: group.Reset(); break; case StateChange.Halt: group.Halt(); break; case StateChange.HardReset: group.HardReset(); break; } }
/// <summary>Called, when a simulation step was processed.</summary> /// <param name="item">Processor which was simulated</param> /// <param name="stepSize">Simulated step size.</param> /// <param name="ramChanges">Changes done to the ram during the simulation step.</param> /// <param name="registerChanges">Changes done to the registers during the simulation step.</param> private void FinishedStep(IDispatcherItem item, SimulationStepSize stepSize, IReadOnlyDictionary<byte, byte> ramChanges, IReadOnlyDictionary<Registers, IRegister> registerChanges) { var guid = item.Guid.ToString(); Clients.Group(guid).UpdateProcessor(stepSize, ramChanges, registerChanges); }
/// <summary>Notifies, when a reset or halt request finished execution.</summary> /// <param name="item">Processor, which changed.</param> private void NotifyStateChanged(IDispatcherItem item, StateChange stateChange) { Action<IDispatcherItem, StateChange> handler; lock (eventLock) { handler = stateChanged; } if (handler != null) { handler(item, stateChange); } }