Add new cycle and event based simulator for better performance and associated unit tests

This commit is contained in:
Stone_Red
2026-03-26 01:16:24 +01:00
parent b1b71a2392
commit aa6d13a46c
17 changed files with 1386 additions and 793 deletions
@@ -0,0 +1,29 @@
namespace StoneRed.LogicSimulator.Simulation;
/// <summary>
/// Represents a digital logic simulator.
/// </summary>
public interface ICircuitSimulator
{
int GateCount { get; }
int AddGate(GateKind kind);
int AddLutGate(int inputCount, int[] table);
void ConnectGates(int fromGate, int toGate, int toInputBit);
void RegisterMacroGate(string name, CircuitDefinition definition);
bool ComputeLut(string name, int maxSteps = 4096);
MacroInstance AddMacroGate(string name);
/// <summary>
/// Returns the circuit to its initial state (all signals at 0) and
/// kickstarts the simulation logic (evaluating gates like NOT).
/// This is automatically called on the first Step if not called manually.
/// </summary>
void Reset();
void SetSource(int gateId, bool value);
bool GetOutput(int gateId);
void Step();
int RunUntilStable(int maxSteps = 1024);
bool TryRunUntilStable(int maxSteps, out int steps);
IDisposable WatchGate(int gateId, Action<int, int> callback);
}