1 package net.mograsim.logic.model.am2900.am2901;
3 import java.util.ArrayList;
4 import java.util.Comparator;
7 import net.mograsim.logic.model.SimpleLogicUIStandalone;
8 import net.mograsim.logic.model.model.ViewModelModifiable;
9 import net.mograsim.logic.model.model.components.GUIComponent;
10 import net.mograsim.logic.model.model.components.atomic.GUIAndGate;
11 import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
12 import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
13 import net.mograsim.logic.model.model.components.atomic.GUINotGate;
14 import net.mograsim.logic.model.model.components.atomic.TextComponent;
15 import net.mograsim.logic.model.model.wires.Pin;
16 import net.mograsim.logic.model.model.wires.WireCrossPoint;
17 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
18 import net.mograsim.logic.model.util.ModellingTool;
20 public class Am2901Testbench
22 public static void main(String[] args)
24 SimpleLogicUIStandalone.executeVisualisation(Am2901Testbench::createTestbench);
27 public static void createTestbench(ViewModelModifiable model)
29 GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901");
30 ModellingTool tool = ModellingTool.createFor(model);
34 GUIManualSwitch enable = new GUIManualSwitch(model, 1);
35 WireCrossPoint wcp0 = new WireCrossPoint(model, 1);
36 GUINotGate not1 = new GUINotGate(model, 1);
37 GUINotGate not2 = new GUINotGate(model, 1);
38 GUINotGate not3 = new GUINotGate(model, 1);
39 GUIAndGate and = new GUIAndGate(model, 1);
40 tool.connect(wcp0, enable, "");
41 tool.connect(wcp0, and, "A");
42 tool.connect(wcp0, not1, "A");
43 tool.connect(not1, not2, "Y", "A");
44 tool.connect(not2, not3, "Y", "A");
45 tool.connect(not3, and, "Y", "B");
46 enable.moveTo(20, -32.5);
50 not3.moveTo(110, -20);
52 Pin last = and.getPin("Y");
54 // guess which pins are outputs and which are inputs
55 // TODO this code exists four times... but it seems too "hacky" to put it in a helper class
56 List<String> inputPinNames = new ArrayList<>();
57 List<String> outputPinNames = new ArrayList<>();
58 for (Pin p : comp.getPins().values())
60 inputPinNames.add(p.name);
62 outputPinNames.add(p.name);
64 inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
65 outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
67 for (int i = 0; i < inputPinNames.size(); i++)
69 double x = 55 + 70 * (i % 2);
72 WireCrossPoint wcp = new WireCrossPoint(model, 1);
73 GUIComponent d_ff = IndirectGUIComponentCreator.createComponent(model, "GUIdff");
74 GUIManualSwitch sw = new GUIManualSwitch(model, 1);
76 tool.connect(last, wcp);
77 tool.connect(wcp, d_ff, "C");
78 tool.connect(sw, d_ff, "", "D");
79 tool.connect(d_ff, comp, "Q", inputPinNames.get(i));
82 TextComponent label = new TextComponent(model, inputPinNames.get(i));
84 sw.moveTo(x, y + 7.5);
87 label.moveTo(x - 48, y + 8);
90 for (int i = 0; i < outputPinNames.size(); i++)
92 double x = 300 + 75 * (i % 2);
93 double y = 10 * i - 2.5;
94 GUIBitDisplay bd = new GUIBitDisplay(model, 1);
96 tool.connect(bd.getInputPin(), comp, outputPinNames.get(i));
98 TextComponent label = new TextComponent(model, outputPinNames.get(i));
99 label.moveTo(x + 25, y);