0a06914bbeaf25dfa3ec978e717a93a075e6dc08
[Mograsim.git] / net.mograsim.logic.ui.am2900 / test / net / mograsim / logic / ui / am2900 / Am2901Testbench.java
1 package net.mograsim.logic.ui.am2900;
2
3 import net.mograsim.logic.ui.SimpleLogicUIStandalone;
4 import net.mograsim.logic.ui.model.ViewModelModifiable;
5 import net.mograsim.logic.ui.model.components.GUIComponent;
6 import net.mograsim.logic.ui.model.components.atomic.GUIAndGate;
7 import net.mograsim.logic.ui.model.components.atomic.GUIBitDisplay;
8 import net.mograsim.logic.ui.model.components.atomic.GUIManualSwitch;
9 import net.mograsim.logic.ui.model.components.atomic.GUINotGate;
10 import net.mograsim.logic.ui.model.components.atomic.TextComponent;
11 import net.mograsim.logic.ui.model.components.mi.nandbased.GUIdff;
12 import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901;
13 import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent;
14 import net.mograsim.logic.ui.model.wires.Pin;
15 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
16 import net.mograsim.logic.ui.util.ModellingTool;
17
18 public class Am2901Testbench
19 {
20         public static void main(String[] args)
21         {
22                 SimpleLogicUIStandalone.executeVisualisation(Am2901Testbench::createTestbench);
23         }
24
25         public static void createTestbench(ViewModelModifiable model)
26         {
27                 SimpleRectangularSubmodelComponent comp = new GUIAm2901(model);
28                 ModellingTool tool = ModellingTool.createFor(model);
29
30                 comp.moveTo(240, 0);
31
32                 GUIManualSwitch enable = new GUIManualSwitch(model);
33                 WireCrossPoint wcp0 = new WireCrossPoint(model, 1);
34                 GUINotGate not1 = new GUINotGate(model, 1);
35                 GUINotGate not2 = new GUINotGate(model, 1);
36                 GUINotGate not3 = new GUINotGate(model, 1);
37                 GUIAndGate and = new GUIAndGate(model, 1);
38                 tool.connect(wcp0, enable, "");
39                 tool.connect(wcp0, and, "A");
40                 tool.connect(wcp0, not1, "A");
41                 tool.connect(not1, not2, "Y", "A");
42                 tool.connect(not2, not3, "Y", "A");
43                 tool.connect(not3, and, "Y", "B");
44                 enable.moveTo(20, -32.5);
45                 wcp0.moveTo(35, -26);
46                 not1.moveTo(50, -20);
47                 not2.moveTo(80, -20);
48                 not3.moveTo(110, -20);
49                 and.moveTo(135, -30);
50                 Pin last = and.getPin("Y");
51
52                 for (int i = 0; i < comp.getInputPinNames().size(); i++)
53                 {
54                         double x = 55 + 70 * (i % 2);
55                         double y = 10 * i;
56
57                         WireCrossPoint wcp = new WireCrossPoint(model, 1);
58                         GUIComponent d_ff = new GUIdff(model);
59                         GUIManualSwitch sw = new GUIManualSwitch(model);
60
61                         tool.connect(last, wcp);
62                         tool.connect(wcp, d_ff, "C");
63                         tool.connect(sw, d_ff, "", "D");
64                         tool.connect(d_ff, comp, "Q", comp.getInputPinNames().get(i));
65                         last = wcp.getPin();
66
67                         TextComponent label = new TextComponent(model, comp.getInputPinNames().get(i));
68
69                         sw.moveTo(x, y + 7.5);
70                         wcp.moveTo(160, y);
71                         d_ff.moveTo(170, y);
72                         label.moveTo(x - 25, y + 15);
73                 }
74
75                 for (int i = 0; i < comp.getOutputPinNames().size(); i++)
76                 {
77                         double x = 300 + 75 * (i % 2);
78                         double y = 10 * i - 2.5;
79                         GUIBitDisplay bd = new GUIBitDisplay(model);
80                         bd.moveTo(x, y);
81                         tool.connect(bd.getInputPin(), comp, comp.getOutputPinNames().get(i));
82
83                         TextComponent label = new TextComponent(model, comp.getOutputPinNames().get(i));
84                         label.moveTo(x + 50, y + 8);
85                 }
86         }
87 }