1 package net.mograsim.logic.ui.am2900;
3 import java.util.ArrayList;
6 import net.mograsim.logic.model.SimpleLogicUIStandalone;
7 import net.mograsim.logic.model.model.ViewModelModifiable;
8 import net.mograsim.logic.model.model.components.GUIComponent;
9 import net.mograsim.logic.model.model.components.atomic.GUIAndGate;
10 import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
11 import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
12 import net.mograsim.logic.model.model.components.atomic.GUINotGate;
13 import net.mograsim.logic.model.model.components.atomic.TextComponent;
14 import net.mograsim.logic.model.model.wires.Pin;
15 import net.mograsim.logic.model.model.wires.WireCrossPoint;
16 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
17 import net.mograsim.logic.model.util.ModellingTool;
19 public class Am2901Testbench
21 public static void main(String[] args)
23 SimpleLogicUIStandalone.executeVisualisation(Am2901Testbench::createTestbench);
26 public static void createTestbench(ViewModelModifiable model)
28 GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901");
29 ModellingTool tool = ModellingTool.createFor(model);
33 GUIManualSwitch enable = new GUIManualSwitch(model);
34 WireCrossPoint wcp0 = new WireCrossPoint(model, 1);
35 GUINotGate not1 = new GUINotGate(model, 1);
36 GUINotGate not2 = new GUINotGate(model, 1);
37 GUINotGate not3 = new GUINotGate(model, 1);
38 GUIAndGate and = new GUIAndGate(model, 1);
39 tool.connect(wcp0, enable, "");
40 tool.connect(wcp0, and, "A");
41 tool.connect(wcp0, not1, "A");
42 tool.connect(not1, not2, "Y", "A");
43 tool.connect(not2, not3, "Y", "A");
44 tool.connect(not3, and, "Y", "B");
45 enable.moveTo(20, -32.5);
49 not3.moveTo(110, -20);
51 Pin last = and.getPin("Y");
53 // guess which pins are outputs and which are inputs
54 // TODO this code exists three times... but it seems too "hacky" to put it in a helper class
55 List<String> inputPinNames = new ArrayList<>();
56 List<String> outputPinNames = new ArrayList<>();
57 for (Pin p : comp.getPins().values())
59 inputPinNames.add(p.name);
61 outputPinNames.add(p.name);
63 for (int i = 0; i < inputPinNames.size(); i++)
65 double x = 55 + 70 * (i % 2);
68 WireCrossPoint wcp = new WireCrossPoint(model, 1);
69 GUIComponent d_ff = IndirectGUIComponentCreator.createComponent(model, "GUIdff");
70 GUIManualSwitch sw = new GUIManualSwitch(model);
72 tool.connect(last, wcp);
73 tool.connect(wcp, d_ff, "C");
74 tool.connect(sw, d_ff, "", "D");
75 tool.connect(d_ff, comp, "Q", inputPinNames.get(i));
78 TextComponent label = new TextComponent(model, inputPinNames.get(i));
80 sw.moveTo(x, y + 7.5);
83 label.moveTo(x - 25, y + 15);
86 for (int i = 0; i < outputPinNames.size(); i++)
88 double x = 300 + 75 * (i % 2);
89 double y = 10 * i - 2.5;
90 GUIBitDisplay bd = new GUIBitDisplay(model);
92 tool.connect(bd.getInputPin(), comp, outputPinNames.get(i));
94 TextComponent label = new TextComponent(model, outputPinNames.get(i));
95 label.moveTo(x + 50, y + 8);