1 package net.mograsim.logic.model.am2900.am2901;
3 import java.util.ArrayList;
4 import java.util.Comparator;
7 import net.mograsim.logic.core.types.Bit;
8 import net.mograsim.logic.core.types.BitVector;
9 import net.mograsim.logic.model.SimpleLogicUIStandalone;
10 import net.mograsim.logic.model.SimpleLogicUIStandalone.VisualisationObjects;
11 import net.mograsim.logic.model.am2900.Am2900Loader;
12 import net.mograsim.logic.model.model.LogicModelModifiable;
13 import net.mograsim.logic.model.model.components.ModelComponent;
14 import net.mograsim.logic.model.model.components.atomic.ModelAndGate;
15 import net.mograsim.logic.model.model.components.atomic.ModelBitDisplay;
16 import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch;
17 import net.mograsim.logic.model.model.components.atomic.ModelNotGate;
18 import net.mograsim.logic.model.model.components.atomic.ModelTextComponent;
19 import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
20 import net.mograsim.logic.model.model.wires.Pin;
21 import net.mograsim.logic.model.model.wires.PinUsage;
22 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
23 import net.mograsim.logic.model.util.ModellingTool;
26 public class Am2901Testbench
28 public static void main(String[] args)
31 SimpleLogicUIStandalone.executeVisualisation(Am2901Testbench::createTestbench, Am2901Testbench::beforeRun);
34 public static void createTestbench(LogicModelModifiable model)
36 ModelComponent comp = IndirectModelComponentCreator.createComponent(model, "Am2901");
37 ModellingTool tool = ModellingTool.createFor(model);
41 ModelManualSwitch enable = new ModelManualSwitch(model, 1);
42 ModelWireCrossPoint wcp0 = new ModelWireCrossPoint(model, 1);
43 ModelNotGate not1 = new ModelNotGate(model, 1);
44 ModelNotGate not2 = new ModelNotGate(model, 1);
45 ModelNotGate not3 = new ModelNotGate(model, 1);
46 ModelAndGate and = new ModelAndGate(model, 1);
47 tool.connect(wcp0, enable, "");
48 tool.connect(wcp0, and, "A");
49 tool.connect(wcp0, not1, "A");
50 tool.connect(not1, not2, "Y", "A");
51 tool.connect(not2, not3, "Y", "A");
52 tool.connect(not3, and, "Y", "B");
53 enable.moveTo(20, -32.5);
57 not3.moveTo(110, -20);
59 Pin last = and.getPin("Y");
61 List<String> inputPinNames = new ArrayList<>();
62 List<String> outputPinNames = new ArrayList<>();
63 for (Pin p : comp.getPins().values())
64 if (p.usage == PinUsage.INPUT)
65 inputPinNames.add(p.name);
67 outputPinNames.add(p.name);
69 inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
70 outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
72 for (int i = 0; i < inputPinNames.size(); i++)
74 double x = 55 + 70 * (i % 2);
77 ModelWireCrossPoint wcp = new ModelWireCrossPoint(model, 1);
78 ModelComponent d_ff = IndirectModelComponentCreator.createComponent(model, "dff");
79 ModelManualSwitch sw = new ModelManualSwitch(model, 1);
81 tool.connect(last, wcp);
82 tool.connect(wcp, d_ff, "C");
83 tool.connect(sw, d_ff, "", "D");
84 tool.connect(d_ff, comp, "Q", inputPinNames.get(i));
87 ModelTextComponent label = new ModelTextComponent(model, inputPinNames.get(i));
89 sw.moveTo(x, y + 7.5);
92 label.moveTo(x - 48, y + 8);
95 for (int i = 0; i < outputPinNames.size(); i++)
97 double x = 300 + 75 * (i % 2);
98 double y = 10 * i - 2.5;
99 ModelBitDisplay bd = new ModelBitDisplay(model, 1);
101 tool.connect(bd.getInputPin(), comp, outputPinNames.get(i));
103 ModelTextComponent label = new ModelTextComponent(model, outputPinNames.get(i));
104 label.moveTo(x + 25, y);
108 public static void beforeRun(VisualisationObjects vis)
110 vis.model.getComponentsByName().values().forEach(c ->
112 if (c instanceof ModelManualSwitch)
114 ModelManualSwitch cCasted = (ModelManualSwitch) c;
115 cCasted.setHighLevelState("out", BitVector.of(Bit.ZERO, cCasted.logicWidth));