-package era.mi.gui;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import era.mi.logic.Simulation;
-import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;
-import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
-
-/**
- * Standalone simulation visualizer.
- *
- * @author Daniel Kirschten
- */
-public class LogicUIStandalone
-{
- private final Display display;
- private final Shell shell;
- private final LogicUICanvas ui;
-
- public LogicUIStandalone()
- {
- display = new Display();
- shell = new Shell(display);
- shell.setLayout(new FillLayout());
- ui = new LogicUICanvas(shell, SWT.NONE);
-
- ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
- userInput.buttonDrag = 3;
- userInput.buttonZoom = 2;
- userInput.enableUserInput();
- new ZoomableCanvasOverlay(ui, null).enableScale();
- }
-
- public LogicUICanvas getLogicUICanvas()
- {
- return ui;
- }
-
- /**
- * Start the simulation timeline, and open the UI shell. Returns when the shell is closed.
- */
- public void run()
- {
- AtomicBoolean running = new AtomicBoolean(true);
- Thread simulationThread = new Thread(() ->
- {
- while (running.get())
- {
- // always execute to keep timeline from "hanging behind" for too long
- Simulation.TIMELINE.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
- long sleepTime;
- if (Simulation.TIMELINE.hasNext())
- sleepTime = Simulation.TIMELINE.nextEventTime() - System.currentTimeMillis();
- else
- sleepTime = 10;
- try
- {
- if (sleepTime > 0)
- Thread.sleep(sleepTime);
- }
- catch (InterruptedException e)
- {
- } // it is normal execution flow to be interrupted
- }
- });
- simulationThread.start();
- Simulation.TIMELINE.addEventAddedListener(event ->
- {
- if (event.getTiming() <= System.currentTimeMillis())
- simulationThread.interrupt();
- });
-
- shell.open();
- while (!shell.isDisposed())
- if (!display.readAndDispatch())
- display.sleep();
- running.set(false);
- simulationThread.interrupt();
- }
+package era.mi.gui;\r
+\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.layout.FillLayout;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.Shell;\r
+\r
+import era.mi.logic.timeline.Timeline;\r
+import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay;\r
+import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;\r
+\r
+/**\r
+ * Standalone simulation visualizer.\r
+ * \r
+ * @author Daniel Kirschten\r
+ */\r
+public class LogicUIStandalone\r
+{\r
+ private final Display display;\r
+ private final Shell shell;\r
+ private final LogicUICanvas ui;\r
+ private Timeline timeline;\r
+\r
+ public LogicUIStandalone(Timeline timeline)\r
+ {\r
+ this.timeline = timeline;\r
+ display = new Display();\r
+ shell = new Shell(display);\r
+ shell.setLayout(new FillLayout());\r
+ ui = new LogicUICanvas(shell, SWT.NONE);\r
+\r
+ ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);\r
+ userInput.buttonDrag = 3;\r
+ userInput.buttonZoom = 2;\r
+ userInput.enableUserInput();\r
+ new ZoomableCanvasOverlay(ui, null).enableScale();\r
+ }\r
+\r
+ public LogicUICanvas getLogicUICanvas()\r
+ {\r
+ return ui;\r
+ }\r
+\r
+ /**\r
+ * Start the simulation timeline, and open the UI shell. Returns when the shell is closed.\r
+ */\r
+ public void run()\r
+ {\r
+ AtomicBoolean running = new AtomicBoolean(true);\r
+ Thread simulationThread = new Thread(() ->\r
+ {\r
+ while (running.get())\r
+ {\r
+ // always execute to keep timeline from "hanging behind" for too long\r
+ timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);\r
+ long sleepTime;\r
+ if (timeline.hasNext())\r
+ sleepTime = timeline.nextEventTime() - System.currentTimeMillis();\r
+ else\r
+ sleepTime = 10;\r
+ try\r
+ {\r
+ if (sleepTime > 0)\r
+ Thread.sleep(sleepTime);\r
+ }\r
+ catch (InterruptedException e)\r
+ {\r
+ } // it is normal execution flow to be interrupted\r
+ }\r
+ });\r
+ simulationThread.start();\r
+ timeline.addEventAddedListener(event ->\r
+ {\r
+ if (event.getTiming() <= System.currentTimeMillis())\r
+ simulationThread.interrupt();\r
+ });\r
+\r
+ shell.open();\r
+ while (!shell.isDisposed())\r
+ if (!display.readAndDispatch())\r
+ display.sleep();\r
+ running.set(false);\r
+ simulationThread.interrupt();\r
+ }\r
}
\ No newline at end of file
import java.util.List;\r
\r
import era.mi.logic.components.gates.AndGate;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
private final List<ReadEnd> connectedWireEnds;\r
private final List<Point> wireEndConnectionPoints;\r
\r
- public GUIAndGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+ public GUIAndGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
{\r
- super(processTime, out, in);\r
+ super(timeline, processTime, out, in);\r
\r
List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
List<Point> wireEndConnectionPointsModifiable = new ArrayList<>();\r
import java.util.Map;\r
\r
import era.mi.logic.components.ManualSwitch;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
private final List<ReadEnd> connectedWireEnds;\r
private final List<Point> wireEndConnectionPoints;\r
\r
- public GUIManualSwitch(ReadWriteEnd output)\r
+ public GUIManualSwitch(Timeline timeline, ReadWriteEnd output)\r
{\r
- super(output);\r
+ super(timeline, output);\r
\r
this.we = output;\r
\r
import java.util.List;\r
\r
import era.mi.logic.components.Merger;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
private final List<ReadEnd> connectedWireEnds;\r
private final List<Point> WireEndConnectionPoints;\r
\r
- public GUIMerger(ReadWriteEnd union, ReadEnd... inputs)\r
+ public GUIMerger(Timeline timeline, ReadWriteEnd union, ReadEnd... inputs)\r
{\r
- super(union, inputs);\r
+ super(timeline, union, inputs);\r
\r
List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
import java.util.List;\r
\r
import era.mi.logic.components.Mux;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
private final List<ReadEnd> connectedWireEnds;\r
private final List<Point> WireEndConnectionPoints;\r
\r
- public GUIMux(int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
+ public GUIMux(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
{\r
- super(processTime, out, select, inputs);\r
+ super(timeline, processTime, out, select, inputs);\r
\r
double height = inputs.length * 5;\r
if (height < 10)\r
import java.util.List;\r
\r
import era.mi.logic.components.gates.NotGate;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
private final List<ReadEnd> connectedWireEnds;\r
private final List<Point> WireEndConnectionPoints;\r
\r
- public GUINotGate(int processTime, ReadEnd in, ReadWriteEnd out)\r
+ public GUINotGate(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out)\r
{\r
- super(processTime, in, out);\r
+ super(timeline, processTime, in, out);\r
\r
List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
import java.util.List;\r
\r
import era.mi.logic.components.gates.OrGate;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
private final List<ReadEnd> connectedWireEnds;\r
private final List<Point> WireEndConnectionPoints;\r
\r
- public GUIOrGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+ public GUIOrGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
{\r
- super(processTime, out, in);\r
+ super(timeline, processTime, out, in);\r
\r
List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
import java.util.List;\r
\r
import era.mi.logic.components.Splitter;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import net.haspamelodica.swt.helper.gcs.GeneralGC;\r
private final List<ReadEnd> connectedWireEnds;\r
private final List<Point> WireEndConnectionPoints;\r
\r
- public GUISplitter(ReadEnd input, ReadWriteEnd... outputs)\r
+ public GUISplitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs)\r
{\r
- super(input, outputs);\r
+ super(timeline, input, outputs);\r
\r
List<ReadEnd> connectedWireEndsModifiable = new ArrayList<>();\r
List<Point> WireEndConnectionPointsModifiable = new ArrayList<>();\r
import era.mi.gui.components.GUINotGate;\r
import era.mi.gui.components.GUIOrGate;\r
import era.mi.gui.wires.WireConnectionPoint;\r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire;\r
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;\r
\r
private static final int WIRE_DELAY = 10;\r
private static final int OR_DELAY = 50;\r
private static final int NOT_DELAY = 50;\r
+ private static final Timeline t = new Timeline(11);\r
\r
public static void main(String[] args)\r
{\r
- LogicUIStandalone ui = new LogicUIStandalone();\r
+ LogicUIStandalone ui = new LogicUIStandalone(t);\r
addComponentsAndWires(ui.getLogicUICanvas());\r
ui.run();\r
}\r
\r
public static void addComponentsAndWires(LogicUICanvas ui)\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire r = new Wire(1, WIRE_DELAY);\r
- Wire s = new Wire(1, WIRE_DELAY);\r
- Wire t2 = new Wire(1, WIRE_DELAY);\r
- Wire t1 = new Wire(1, WIRE_DELAY);\r
- Wire q = new Wire(1, WIRE_DELAY);\r
- Wire nq = new Wire(1, WIRE_DELAY);\r
+ Wire r = new Wire(t, 1, WIRE_DELAY);\r
+ Wire s = new Wire(t, 1, WIRE_DELAY);\r
+ Wire t2 = new Wire(t, 1, WIRE_DELAY);\r
+ Wire t1 = new Wire(t, 1, WIRE_DELAY);\r
+ Wire q = new Wire(t, 1, WIRE_DELAY);\r
+ Wire nq = new Wire(t, 1, WIRE_DELAY);\r
\r
- GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(r.createReadWriteEnd()), 100, 100);\r
- GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(s.createReadWriteEnd()), 100, 200);\r
- GUIOrGate or1 = ui.addComponent(new GUIOrGate(OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()), 160, 102.5);\r
- GUIOrGate or2 = ui.addComponent(new GUIOrGate(OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()), 160, 192.5);\r
- GUINotGate not1 = ui.addComponent(new GUINotGate(NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);\r
- GUINotGate not2 = ui.addComponent(new GUINotGate(NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);\r
+ GUIManualSwitch rIn = ui.addComponent(new GUIManualSwitch(t, r.createReadWriteEnd()), 100, 100);\r
+ GUIManualSwitch sIn = ui.addComponent(new GUIManualSwitch(t, s.createReadWriteEnd()), 100, 200);\r
+ GUIOrGate or1 = ui.addComponent(new GUIOrGate(t, OR_DELAY, t1.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd()),\r
+ 160, 102.5);\r
+ GUIOrGate or2 = ui.addComponent(new GUIOrGate(t, OR_DELAY, t2.createReadWriteEnd(), q.createReadOnlyEnd(), s.createReadOnlyEnd()),\r
+ 160, 192.5);\r
+ GUINotGate not1 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), q.createReadWriteEnd()), 200, 107.5);\r
+ GUINotGate not2 = ui.addComponent(new GUINotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), nq.createReadWriteEnd()), 200, 197.5);\r
\r
WireConnectionPoint p1 = ui.addComponent(new WireConnectionPoint(q, 3), 250, 112.5);\r
WireConnectionPoint p2 = ui.addComponent(new WireConnectionPoint(nq, 3), 250, 202.5);\r
import era.mi.gui.LogicUICanvas;
import era.mi.gui.examples.RSLatchGUIExample;
-import era.mi.logic.Simulation;
+import era.mi.logic.timeline.Timeline;
import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
public class LogicUIPart
@PostConstruct
public void create(Composite parent)
{
+ Timeline timeline = new Timeline(11);
LogicUICanvas ui = new LogicUICanvas(parent, SWT.NONE);
RSLatchGUIExample.addComponentsAndWires(ui);
ui.addTransformListener((x, y, z) -> part.setDirty(z < 1));
while (!ui.isDisposed())
{
// always execute to keep timeline from "hanging behind" for too long
- Simulation.TIMELINE.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
+ timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
long sleepTime;
- if (Simulation.TIMELINE.hasNext())
- sleepTime = Simulation.TIMELINE.nextEventTime() - System.currentTimeMillis();
+ if (timeline.hasNext())
+ sleepTime = timeline.nextEventTime() - System.currentTimeMillis();
else
sleepTime = 10;
try
}
});
simulationThread.start();
- Simulation.TIMELINE.addEventAddedListener(event ->
+ timeline.addEventAddedListener(event ->
{
if (event.getTiming() <= System.currentTimeMillis())
simulationThread.interrupt();
+++ /dev/null
-package era.mi.logic;
-
-import era.mi.logic.timeline.Timeline;
-
-public class Simulation
-{
- public final static Timeline TIMELINE = new Timeline(11);
-
-}
\ No newline at end of file
package era.mi.logic.components;\r
\r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.WireObserver;\r
* \r
* @author Fabian Stemmler\r
*/\r
-public abstract class BasicComponent implements WireObserver, Component\r
+public abstract class BasicComponent extends Component implements WireObserver\r
{\r
private int processTime;\r
\r
* \r
* @author Fabian Stemmler\r
*/\r
- public BasicComponent(int processTime)\r
+ public BasicComponent(Timeline timeline, int processTime)\r
{\r
+ super(timeline);\r
this.processTime = processTime > 0 ? processTime : 1;\r
}\r
\r
@Override\r
public void update(ReadEnd initiator, BitVector oldValues)\r
{\r
- Simulation.TIMELINE.addEvent(e -> compute(), processTime);\r
+ timeline.addEvent(e -> compute(), processTime);\r
}\r
\r
protected abstract void compute();\r
\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.types.BitVector;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
private final ReadEnd in;\r
private BitVector displayedValue;\r
\r
- public BitDisplay(ReadEnd in)\r
+ public BitDisplay(Timeline timeline, ReadEnd in)\r
{\r
- super(1);\r
+ super(timeline, 1);\r
this.in = in;\r
in.addObserver(this);\r
compute();\r
\r
import java.util.List;\r
\r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.timeline.TimelineEvent;\r
import era.mi.logic.timeline.TimelineEventHandler;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
\r
-public class Clock implements TimelineEventHandler, Component\r
+public class Clock extends Component implements TimelineEventHandler\r
{\r
private boolean toggle = false;\r
private ReadWriteEnd out;\r
* @param out {@link Wire} the clock's impulses are fed into\r
* @param delta ticks between rising and falling edge\r
*/\r
- public Clock(ReadWriteEnd out, int delta)\r
+ public Clock(Timeline timeline, ReadWriteEnd out, int delta)\r
{\r
+ super(timeline);\r
this.delta = delta;\r
this.out = out;\r
addToTimeline();\r
\r
private void addToTimeline()\r
{\r
- Simulation.TIMELINE.addEvent(this, delta);\r
+ timeline.addEvent(this, delta);\r
}\r
\r
@Override\r
\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
\r
-public interface Component\r
+public abstract class Component\r
{\r
+ protected Timeline timeline;\r
+\r
+ public Component(Timeline timeline)\r
+ {\r
+ this.timeline = timeline;\r
+ }\r
\r
/**\r
* Returns immutable list of all inputs to the {@link Component} (including e.g. the select bits to a MUX). Intended for visualization\r
* in the UI.\r
*/\r
- public List<ReadEnd> getAllInputs();\r
+ public abstract List<ReadEnd> getAllInputs();\r
\r
/**\r
* Returns immutable list of all outputs to the {@link Component}. Intended for visualization in the UI.\r
*/\r
- public List<ReadWriteEnd> getAllOutputs();\r
+ public abstract List<ReadWriteEnd> getAllOutputs();\r
}\r
\r
import java.util.List;\r
\r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import era.mi.logic.wires.WireObserver;\r
\r
-public class Connector implements WireObserver, Component\r
+public class Connector extends Component implements WireObserver\r
{\r
private boolean connected;\r
private final ReadWriteEnd a;\r
private final ReadWriteEnd b;\r
\r
- public Connector(ReadWriteEnd a, ReadWriteEnd b)\r
+ public Connector(Timeline timeline, ReadWriteEnd a, ReadWriteEnd b)\r
{\r
+ super(timeline);\r
if (a.length() != b.length())\r
throw new IllegalArgumentException(String.format("WireArray width does not match: %d, %d", a.length(), b.length()));\r
this.a = a;\r
public void update(ReadEnd initiator, BitVector oldValues)\r
{\r
if (connected)\r
- Simulation.TIMELINE.addEvent(e -> update(initiator), 1);\r
+ timeline.addEvent(e -> update(initiator), 1);\r
}\r
\r
private void update(ReadEnd initiator)\r
\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
* @param select Indexes the output array to which the input is mapped. Must have enough bits to index all outputs.\r
* @param outputs One of these outputs receives the input signal, depending on the select bits\r
*/\r
- public Demux(int processTime, ReadEnd in, ReadEnd select, ReadWriteEnd... outputs)\r
+ public Demux(Timeline timeline, int processTime, ReadEnd in, ReadEnd select, ReadWriteEnd... outputs)\r
{\r
- super(processTime);\r
+ super(timeline, processTime);\r
outputSize = in.length();\r
\r
this.in = in;\r
\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
* @author Christian Femers\r
*\r
*/\r
-public class ManualSwitch implements Component\r
+public class ManualSwitch extends Component\r
{\r
private ReadWriteEnd output;\r
private boolean isOn;\r
\r
- public ManualSwitch(ReadWriteEnd output)\r
+ public ManualSwitch(Timeline timeline, ReadWriteEnd output)\r
{\r
+ super(timeline);\r
if (output.length() != 1)\r
throw new IllegalArgumentException("Switch output can be only a single wire");\r
this.output = output;\r
\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector;\r
import era.mi.logic.wires.Wire;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import era.mi.logic.wires.WireObserver;\r
\r
-public class Merger implements WireObserver, Component\r
+public class Merger extends Component implements WireObserver\r
{\r
private ReadWriteEnd out;\r
private ReadEnd[] inputs;\r
* @param union The output of merging n {@link Wire}s into one. Must have length = a1.length() + a2.length() + ... + an.length().\r
* @param inputs The inputs to be merged into the union\r
*/\r
- public Merger(ReadWriteEnd union, ReadEnd... inputs)\r
+ public Merger(Timeline timeline, ReadWriteEnd union, ReadEnd... inputs)\r
{\r
+ super(timeline);\r
this.inputs = inputs;\r
this.out = union;\r
this.beginningIndex = new int[inputs.length];\r
import java.util.Collections;\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
* @param select Indexes the input array which is to be mapped to the output. Must have enough bits to index all inputs.\r
* @param inputs One of these inputs is mapped to the output, depending on the select bits\r
*/\r
- public Mux(int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
+ public Mux(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd select, ReadEnd... inputs)\r
{\r
- super(processTime);\r
+ super(timeline, processTime);\r
outputSize = out.length();\r
\r
this.inputs = inputs.clone();\r
\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
import era.mi.logic.wires.WireObserver;\r
\r
-public class Splitter implements WireObserver, Component\r
+public class Splitter extends Component implements WireObserver\r
{\r
private ReadEnd input;\r
private ReadWriteEnd[] outputs;\r
\r
- public Splitter(ReadEnd input, ReadWriteEnd... outputs)\r
+ public Splitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs)\r
{\r
+ super(timeline);\r
this.input = input;\r
this.outputs = outputs;\r
input.addObserver(this);\r
\r
import java.util.List;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
ReadEnd in, enable;\r
ReadWriteEnd out;\r
\r
- public TriStateBuffer(int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable)\r
+ public TriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable)\r
{\r
- super(processTime);\r
+ super(timeline, processTime);\r
if (in.length() != out.length())\r
throw new IllegalArgumentException(\r
"Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length());\r
package era.mi.logic.components.gates;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector.BitVectorMutator;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
\r
public class AndGate extends MultiInputGate\r
{\r
- public AndGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+ public AndGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
{\r
- super(processTime, BitVectorMutator::and, out, in);\r
+ super(timeline, processTime, BitVectorMutator::and, out, in);\r
}\r
}\r
import java.util.List;\r
\r
import era.mi.logic.components.BasicComponent;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector.BitVectorMutator;\r
import era.mi.logic.types.MutationOperation;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
protected final int length;\r
protected MutationOperation op;\r
\r
- protected MultiInputGate(int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in)\r
+ protected MultiInputGate(Timeline timeline, int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in)\r
{\r
- super(processTime);\r
+ super(timeline, processTime);\r
this.op = op;\r
length = out.length();\r
this.in = in.clone();\r
import java.util.List;\r
\r
import era.mi.logic.components.BasicComponent;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
\r
private ReadEnd in;\r
private ReadWriteEnd out;\r
\r
- public NotGate(int processTime, ReadEnd in, ReadWriteEnd out)\r
+ public NotGate(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out)\r
{\r
- super(processTime);\r
+ super(timeline, processTime);\r
this.in = in;\r
in.addObserver(this);\r
this.out = out;\r
package era.mi.logic.components.gates;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector.BitVectorMutator;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
\r
public class OrGate extends MultiInputGate\r
{\r
- public OrGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+ public OrGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
{\r
- super(processTime, BitVectorMutator::or, out, in);\r
+ super(timeline, processTime, BitVectorMutator::or, out, in);\r
}\r
}\r
package era.mi.logic.components.gates;\r
\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.BitVector.BitVectorMutator;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
import era.mi.logic.wires.Wire.ReadWriteEnd;\r
*/\r
public class XorGate extends MultiInputGate\r
{\r
- public XorGate(int processTime, ReadWriteEnd out, ReadEnd... in)\r
+ public XorGate(Timeline timeline, int processTime, ReadWriteEnd out, ReadEnd... in)\r
{\r
- super(processTime, BitVectorMutator::xor, out, in);\r
+ super(timeline, processTime, BitVectorMutator::xor, out, in);\r
}\r
\r
}\r
\r
import org.junit.jupiter.api.Test;\r
\r
-import era.mi.logic.Simulation;\r
import era.mi.logic.components.Connector;\r
import era.mi.logic.components.Demux;\r
import era.mi.logic.components.Merger;\r
import era.mi.logic.components.gates.NotGate;\r
import era.mi.logic.components.gates.OrGate;\r
import era.mi.logic.components.gates.XorGate;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.types.BitVector;\r
import era.mi.logic.wires.Wire;\r
\r
class ComponentTest\r
{\r
+ private Timeline t = new Timeline(11);\r
\r
@Test\r
void circuitExampleTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(1, 1), b = new Wire(1, 1), c = new Wire(1, 10), d = new Wire(2, 1), e = new Wire(1, 1), f = new Wire(1, 1),\r
- g = new Wire(1, 1), h = new Wire(2, 1), i = new Wire(2, 1), j = new Wire(1, 1), k = new Wire(1, 1);\r
- new AndGate(1, f.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
- new NotGate(1, f.createReadOnlyEnd(), g.createReadWriteEnd());\r
- new Merger(h.createReadWriteEnd(), c.createReadOnlyEnd(), g.createReadOnlyEnd());\r
- new Mux(1, i.createReadWriteEnd(), e.createReadOnlyEnd(), h.createReadOnlyEnd(), d.createReadOnlyEnd());\r
- new Splitter(i.createReadOnlyEnd(), k.createReadWriteEnd(), j.createReadWriteEnd());\r
+ Wire a = new Wire(t, 1, 1), b = new Wire(t, 1, 1), c = new Wire(t, 1, 10), d = new Wire(t, 2, 1), e = new Wire(t, 1, 1),\r
+ f = new Wire(t, 1, 1), g = new Wire(t, 1, 1), h = new Wire(t, 2, 1), i = new Wire(t, 2, 1), j = new Wire(t, 1, 1),\r
+ k = new Wire(t, 1, 1);\r
+ new AndGate(t, 1, f.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
+ new NotGate(t, 1, f.createReadOnlyEnd(), g.createReadWriteEnd());\r
+ new Merger(t, h.createReadWriteEnd(), c.createReadOnlyEnd(), g.createReadOnlyEnd());\r
+ new Mux(t, 1, i.createReadWriteEnd(), e.createReadOnlyEnd(), h.createReadOnlyEnd(), d.createReadOnlyEnd());\r
+ new Splitter(t, i.createReadOnlyEnd(), k.createReadWriteEnd(), j.createReadWriteEnd());\r
\r
a.createReadWriteEnd().feedSignals(Bit.ZERO);\r
b.createReadWriteEnd().feedSignals(Bit.ONE);\r
d.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE);\r
e.createReadWriteEnd().feedSignals(Bit.ZERO);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertEquals(Bit.ONE, j.getValue());\r
assertEquals(Bit.ZERO, k.getValue());\r
@Test\r
void splitterTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(3, 1), b = new Wire(2, 1), c = new Wire(3, 1), in = new Wire(8, 1);\r
+ t.reset();\r
+ Wire a = new Wire(t, 3, 1), b = new Wire(t, 2, 1), c = new Wire(t, 3, 1), in = new Wire(t, 8, 1);\r
in.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
- new Splitter(in.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(), c.createReadWriteEnd());\r
+ new Splitter(t, in.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(), c.createReadWriteEnd());\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(a.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO);\r
assertBitArrayEquals(b.getValues(), Bit.ONE, Bit.ZERO);\r
@Test\r
void mergerTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(3, 1), b = new Wire(2, 1), c = new Wire(3, 1), out = new Wire(8, 1);\r
+ t.reset();\r
+ Wire a = new Wire(t, 3, 1), b = new Wire(t, 2, 1), c = new Wire(t, 3, 1), out = new Wire(t, 8, 1);\r
a.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO);\r
b.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO);\r
c.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE);\r
\r
- new Merger(out.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
+ new Merger(t, out.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(out.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
}\r
@Test\r
void triStateBufferTest()\r
{\r
- Wire a = new Wire(1, 1), b = new Wire(1, 1), en = new Wire(1, 1), notEn = new Wire(1, 1);\r
- new NotGate(1, en.createReadOnlyEnd(), notEn.createReadWriteEnd());\r
- new TriStateBuffer(1, a.createReadOnlyEnd(), b.createReadWriteEnd(), en.createReadOnlyEnd());\r
- new TriStateBuffer(1, b.createReadOnlyEnd(), a.createReadWriteEnd(), notEn.createReadOnlyEnd());\r
+ Wire a = new Wire(t, 1, 1), b = new Wire(t, 1, 1), en = new Wire(t, 1, 1), notEn = new Wire(t, 1, 1);\r
+ new NotGate(t, 1, en.createReadOnlyEnd(), notEn.createReadWriteEnd());\r
+ new TriStateBuffer(t, 1, a.createReadOnlyEnd(), b.createReadWriteEnd(), en.createReadOnlyEnd());\r
+ new TriStateBuffer(t, 1, b.createReadOnlyEnd(), a.createReadWriteEnd(), notEn.createReadOnlyEnd());\r
\r
ReadWriteEnd enI = en.createReadWriteEnd(), aI = a.createReadWriteEnd(), bI = b.createReadWriteEnd();\r
enI.feedSignals(Bit.ONE);\r
aI.feedSignals(Bit.ONE);\r
bI.feedSignals(Bit.Z);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertEquals(Bit.ONE, b.getValue());\r
\r
bI.feedSignals(Bit.ZERO);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertEquals(Bit.X, b.getValue());\r
assertEquals(Bit.ONE, a.getValue());\r
aI.clearSignals();\r
enI.feedSignals(Bit.ZERO);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertEquals(Bit.ZERO, a.getValue());\r
\r
@Test\r
void muxTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), out = new Wire(4, 1);\r
+ t.reset();\r
+ Wire a = new Wire(t, 4, 3), b = new Wire(t, 4, 6), c = new Wire(t, 4, 4), select = new Wire(t, 2, 5), out = new Wire(t, 4, 1);\r
ReadWriteEnd selectIn = select.createReadWriteEnd();\r
\r
selectIn.feedSignals(Bit.ZERO, Bit.ZERO);\r
a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
c.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
\r
- new Mux(1, out.createReadWriteEnd(), select.createReadOnlyEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
- Simulation.TIMELINE.executeAll();\r
+ new Mux(t, 1, out.createReadWriteEnd(), select.createReadOnlyEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(),\r
+ c.createReadOnlyEnd());\r
+ t.executeAll();\r
\r
assertBitArrayEquals(out.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
selectIn.feedSignals(Bit.ZERO, Bit.ONE);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(out.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
\r
selectIn.feedSignals(Bit.ONE, Bit.ONE);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(out.getValues(), Bit.Z, Bit.Z, Bit.Z, Bit.Z);\r
\r
@Test\r
void demuxTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(4, 3), b = new Wire(4, 6), c = new Wire(4, 4), select = new Wire(2, 5), in = new Wire(4, 1);\r
+ t.reset();\r
+ Wire a = new Wire(t, 4, 3), b = new Wire(t, 4, 6), c = new Wire(t, 4, 4), select = new Wire(t, 2, 5), in = new Wire(t, 4, 1);\r
ReadWriteEnd selectIn = select.createReadWriteEnd();\r
\r
selectIn.feedSignals(Bit.ZERO, Bit.ZERO);\r
in.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
\r
- new Demux(1, in.createReadOnlyEnd(), select.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(), c.createReadWriteEnd());\r
- Simulation.TIMELINE.executeAll();\r
+ new Demux(t, 1, in.createReadOnlyEnd(), select.createReadOnlyEnd(), a.createReadWriteEnd(), b.createReadWriteEnd(),\r
+ c.createReadWriteEnd());\r
+ t.executeAll();\r
\r
assertBitArrayEquals(a.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
assertBitArrayEquals(b.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
assertBitArrayEquals(c.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
selectIn.feedSignals(Bit.ZERO, Bit.ONE);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(a.getValues(), Bit.Z, Bit.Z, Bit.Z, Bit.Z);\r
assertBitArrayEquals(b.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
assertBitArrayEquals(c.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO);\r
\r
selectIn.feedSignals(Bit.ONE, Bit.ONE);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(a.getValues(), Bit.Z, Bit.Z, Bit.Z, Bit.Z);\r
assertBitArrayEquals(b.getValues(), Bit.U, Bit.U, Bit.U, Bit.U);\r
@Test\r
void andTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(4, 1), b = new Wire(4, 3), c = new Wire(4, 1);\r
- new AndGate(1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
+ t.reset();\r
+ Wire a = new Wire(t, 4, 1), b = new Wire(t, 4, 3), c = new Wire(t, 4, 1);\r
+ new AndGate(t, 1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO);\r
b.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(c.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ZERO);\r
}\r
@Test\r
void orTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(4, 1), b = new Wire(4, 3), c = new Wire(4, 1);\r
- new OrGate(1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
+ t.reset();\r
+ Wire a = new Wire(t, 4, 1), b = new Wire(t, 4, 3), c = new Wire(t, 4, 1);\r
+ new OrGate(t, 1, c.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd());\r
a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO);\r
b.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(c.getValues(), Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ONE);\r
}\r
@Test\r
void xorTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(3, 1), b = new Wire(3, 2), c = new Wire(3, 1), d = new Wire(3, 1);\r
- new XorGate(1, d.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
+ t.reset();\r
+ Wire a = new Wire(t, 3, 1), b = new Wire(t, 3, 2), c = new Wire(t, 3, 1), d = new Wire(t, 3, 1);\r
+ new XorGate(t, 1, d.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd());\r
a.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ONE);\r
b.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE);\r
c.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(d.getValues(), Bit.ZERO, Bit.ONE, Bit.ONE);\r
}\r
@Test\r
void notTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire a = new Wire(3, 1), b = new Wire(3, 2);\r
- new NotGate(1, a.createReadOnlyEnd(), b.createReadWriteEnd());\r
+ t.reset();\r
+ Wire a = new Wire(t, 3, 1), b = new Wire(t, 3, 2);\r
+ new NotGate(t, 1, a.createReadOnlyEnd(), b.createReadWriteEnd());\r
a.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ONE);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertBitArrayEquals(b.getValues(), Bit.ONE, Bit.ZERO, Bit.ZERO);\r
}\r
@Test\r
void rsLatchCircuitTest()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire r = new Wire(1, 1), s = new Wire(1, 1), t1 = new Wire(1, 15), t2 = new Wire(1, 1), q = new Wire(1, 1), nq = new Wire(1, 1);\r
+ t.reset();\r
+ Wire r = new Wire(t, 1, 1), s = new Wire(t, 1, 1), t1 = new Wire(t, 1, 15), t2 = new Wire(t, 1, 1), q = new Wire(t, 1, 1),\r
+ nq = new Wire(t, 1, 1);\r
\r
- new OrGate(1, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
- new OrGate(1, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
- new NotGate(1, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
- new NotGate(1, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
+ new OrGate(t, 1, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
+ new OrGate(t, 1, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
+ new NotGate(t, 1, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
+ new NotGate(t, 1, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
\r
ReadWriteEnd sIn = s.createReadWriteEnd(), rIn = r.createReadWriteEnd();\r
\r
sIn.feedSignals(Bit.ONE);\r
rIn.feedSignals(Bit.ZERO);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertEquals(Bit.ONE, q.getValue());\r
assertEquals(Bit.ZERO, nq.getValue());\r
\r
sIn.feedSignals(Bit.ZERO);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
assertEquals(Bit.ONE, q.getValue());\r
assertEquals(Bit.ZERO, nq.getValue());\r
\r
rIn.feedSignals(Bit.ONE);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertEquals(Bit.ZERO, q.getValue());\r
assertEquals(Bit.ONE, nq.getValue());\r
@Test\r
void numericValueTest()\r
{\r
- Simulation.TIMELINE.reset();\r
+ t.reset();\r
\r
- Wire a = new Wire(4, 1);\r
+ Wire a = new Wire(t, 4, 1);\r
a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ONE, Bit.ONE);\r
\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
\r
assertEquals(15, a.getUnsignedValue());\r
assertEquals(-1, a.getSignedValue());\r
@Test\r
void multipleInputs()\r
{\r
- Simulation.TIMELINE.reset();\r
- Wire w = new Wire(2, 1);\r
+ t.reset();\r
+ Wire w = new Wire(t, 2, 1);\r
ReadWriteEnd wI1 = w.createReadWriteEnd(), wI2 = w.createReadWriteEnd();\r
wI1.feedSignals(Bit.ONE, Bit.Z);\r
wI2.feedSignals(Bit.Z, Bit.X);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.X);\r
\r
wI2.feedSignals(Bit.ZERO, Bit.Z);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
assertBitArrayEquals(w.getValues(), Bit.X, Bit.Z);\r
\r
wI2.feedSignals(Bit.Z, Bit.Z);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z);\r
\r
wI2.feedSignals(Bit.ONE, Bit.Z);\r
ReadEnd rE = w.createReadOnlyEnd();\r
rE.addObserver((i, oldValues) -> fail("WireEnd notified observer, although value did not change."));\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
rE.close();\r
wI1.feedSignals(Bit.X, Bit.X);\r
- Simulation.TIMELINE.executeAll();\r
+ t.executeAll();\r
wI1.addObserver((i, oldValues) -> fail("WireEnd notified observer, although it was closed."));\r
wI1.close();\r
assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z);\r
{\r
// Nur ein Experiment, was über mehrere 'passive' Bausteine hinweg passieren würde\r
\r
- Simulation.TIMELINE.reset();\r
+ t.reset();\r
\r
- Wire a = new Wire(1, 2);\r
- Wire b = new Wire(1, 2);\r
- Wire c = new Wire(1, 2);\r
+ Wire a = new Wire(t, 1, 2);\r
+ Wire b = new Wire(t, 1, 2);\r
+ Wire c = new Wire(t, 1, 2);\r
ReadWriteEnd aI = a.createReadWriteEnd();\r
ReadWriteEnd bI = b.createReadWriteEnd();\r
ReadWriteEnd cI = c.createReadWriteEnd();\r
\r
- TestBitDisplay test = new TestBitDisplay(c.createReadOnlyEnd());\r
- TestBitDisplay test2 = new TestBitDisplay(a.createReadOnlyEnd());\r
+ TestBitDisplay test = new TestBitDisplay(t, c.createReadOnlyEnd());\r
+ TestBitDisplay test2 = new TestBitDisplay(t, a.createReadOnlyEnd());\r
LongConsumer print = time -> System.out.format("Time %2d\n a: %s\n b: %s\n c: %s\n", time, a, b, c);\r
\r
cI.feedSignals(Bit.ONE);\r
cI.feedSignals(Bit.Z);\r
test.assertAfterSimulationIs(print, Bit.Z);\r
\r
- new Connector(b.createReadWriteEnd(), c.createReadWriteEnd()).connect();\r
+ new Connector(t, b.createReadWriteEnd(), c.createReadWriteEnd()).connect();\r
test.assertAfterSimulationIs(print, Bit.Z);\r
System.err.println("ONE");\r
bI.feedSignals(Bit.ONE);\r
bI.feedSignals(Bit.Z);\r
test.assertAfterSimulationIs(print, Bit.Z);\r
\r
- new Connector(a.createReadWriteEnd(), b.createReadWriteEnd()).connect();\r
+ new Connector(t, a.createReadWriteEnd(), b.createReadWriteEnd()).connect();\r
System.err.println("Z 2");\r
aI.feedSignals(Bit.Z);\r
test.assertAfterSimulationIs(print, Bit.Z);\r
import javax.swing.JPanel;\r
import javax.swing.WindowConstants;\r
\r
-import era.mi.logic.Simulation;\r
import era.mi.logic.components.ManualSwitch;\r
import era.mi.logic.components.gates.NotGate;\r
import era.mi.logic.components.gates.OrGate;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.timeline.Timeline.ExecutionResult;\r
import era.mi.logic.wires.Wire;\r
\r
private static final int OR_DELAY = 100;\r
private static final int NOT_DELAY = 100;\r
\r
- Wire r = new Wire(1, WIRE_DELAY);\r
- Wire s = new Wire(1, WIRE_DELAY);\r
- Wire t1 = new Wire(1, WIRE_DELAY);\r
- Wire t2 = new Wire(1, WIRE_DELAY);\r
- Wire q = new Wire(1, WIRE_DELAY);\r
- Wire nq = new Wire(1, WIRE_DELAY);\r
+ private Timeline t = new Timeline(11);\r
\r
- ManualSwitch rIn = new ManualSwitch(r.createReadWriteEnd());\r
- ManualSwitch sIn = new ManualSwitch(s.createReadWriteEnd());\r
+ Wire r = new Wire(t, 1, WIRE_DELAY);\r
+ Wire s = new Wire(t, 1, WIRE_DELAY);\r
+ Wire t1 = new Wire(t, 1, WIRE_DELAY);\r
+ Wire t2 = new Wire(t, 1, WIRE_DELAY);\r
+ Wire q = new Wire(t, 1, WIRE_DELAY);\r
+ Wire nq = new Wire(t, 1, WIRE_DELAY);\r
\r
- OrGate or1 = new OrGate(OR_DELAY, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
- OrGate or2 = new OrGate(OR_DELAY, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
- NotGate not1 = new NotGate(NOT_DELAY, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
- NotGate not2 = new NotGate(NOT_DELAY, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
+ ManualSwitch rIn = new ManualSwitch(t, r.createReadWriteEnd());\r
+ ManualSwitch sIn = new ManualSwitch(t, s.createReadWriteEnd());\r
+\r
+ OrGate or1 = new OrGate(t, OR_DELAY, t2.createReadWriteEnd(), r.createReadOnlyEnd(), nq.createReadOnlyEnd());\r
+ OrGate or2 = new OrGate(t, OR_DELAY, t1.createReadWriteEnd(), s.createReadOnlyEnd(), q.createReadOnlyEnd());\r
+ NotGate not1 = new NotGate(t, NOT_DELAY, t2.createReadOnlyEnd(), q.createReadWriteEnd());\r
+ NotGate not2 = new NotGate(t, NOT_DELAY, t1.createReadOnlyEnd(), nq.createReadWriteEnd());\r
\r
Map<ManualSwitch, Rectangle> switchMap = new HashMap<>();\r
\r
});\r
}\r
\r
+ public Timeline getTimeline()\r
+ {\r
+ return t;\r
+ };\r
+\r
@Override\r
public void paint(Graphics some_g)\r
{\r
\r
while (f.isVisible())\r
{\r
- ExecutionResult er = Simulation.TIMELINE.executeUpTo((lastFrame - begin) * 3, lastFrame + 14);\r
-// if (Simulation.TIMELINE.hasNext()) \r
-// Simulation.TIMELINE.executeNext();\r
+ ExecutionResult er = gt.getTimeline().executeUpTo((lastFrame - begin) * 3, lastFrame + 14);\r
+// if (t.hasNext()) \r
+// t.executeNext();\r
if (er != ExecutionResult.NOTHING_DONE)\r
gt.repaint(12);\r
try\r
\r
import java.util.function.LongConsumer;\r
\r
-import era.mi.logic.Simulation;\r
import era.mi.logic.components.BitDisplay;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.wires.Wire.ReadEnd;\r
\r
public final class TestBitDisplay extends BitDisplay\r
{\r
\r
- public TestBitDisplay(ReadEnd in)\r
+ public TestBitDisplay(Timeline timeline, ReadEnd in)\r
{\r
- super(in);\r
+ super(timeline, in);\r
}\r
\r
public void assertDisplays(Bit... expected)\r
\r
public void assertAfterSimulationIs(Bit... expected)\r
{\r
- Simulation.TIMELINE.executeAll();\r
+ timeline.executeAll();\r
assertDisplays(expected);\r
}\r
\r
public void assertAfterSimulationIs(LongConsumer r, Bit... expected)\r
{\r
- while (Simulation.TIMELINE.hasNext())\r
+ while (timeline.hasNext())\r
{\r
- Simulation.TIMELINE.executeNext();\r
- r.accept(Simulation.TIMELINE.getSimulationTime());\r
+ timeline.executeNext();\r
+ r.accept(timeline.getSimulationTime());\r
}\r
assertDisplays(expected);\r
}\r
*
* @param timestamp the simulation timestamp up to which the events will be processed
* @param stopMillis the System.currentTimeMillis() when simulation definitely needs to stop. A value of -1 means no timeout.
- * @return if it was possible to fulfil the goal in the given real world time.
+ * @return if it was possible to fulfill the goal in the given real world time.
* @author Christian Femers
*/
public ExecutionResult executeUpTo(long timestamp, long stopMillis)
import java.util.ArrayList;\r
import java.util.List;\r
\r
-import era.mi.logic.Simulation;\r
+import era.mi.logic.timeline.Timeline;\r
import era.mi.logic.types.Bit;\r
import era.mi.logic.types.BitVector;\r
import era.mi.logic.types.BitVector.BitVectorMutator;\r
private List<ReadEnd> attached = new ArrayList<ReadEnd>();\r
public final int length;\r
private List<ReadWriteEnd> inputs = new ArrayList<ReadWriteEnd>();\r
+ private Timeline timeline;\r
\r
- public Wire(int length, int travelTime)\r
+ public Wire(Timeline timeline, int length, int travelTime)\r
{\r
if (length < 1)\r
throw new IllegalArgumentException(\r
String.format("Tried to create an array of wires with length %d, but a length of less than 1 makes no sense.", length));\r
+ this.timeline = timeline;\r
this.length = length;\r
this.travelTime = travelTime;\r
initValues();\r
String.format("Attempted to input %d bits instead of %d bits.", newValues.length(), length));\r
if (!open)\r
throw new RuntimeException("Attempted to write to closed WireArrayEnd.");\r
- Simulation.TIMELINE.addEvent(e -> setValues(newValues), travelTime);\r
+ timeline.addEvent(e -> setValues(newValues), travelTime);\r
}\r
\r
/**\r
{\r
if (!open)\r
throw new RuntimeException("Attempted to write to closed WireArrayEnd.");\r
- Simulation.TIMELINE.addEvent(e -> setValues(startingBit, bitVector), travelTime);\r
+ timeline.addEvent(e -> setValues(startingBit, bitVector), travelTime);\r
}\r
\r
private void setValues(int startingBit, BitVector newValues)\r