028de6ea1bf692568dedcfccec27b7afce49ca25
[Mograsim.git] / net.mograsim.logic.model.am2900 / test / net / mograsim / logic / model / am2900 / am2910 / Am2910Testbench.java
1 package net.mograsim.logic.model.am2900.am2910;
2
3 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
4 import net.mograsim.logic.core.types.Bit;
5 import net.mograsim.logic.core.types.BitVector;
6 import net.mograsim.logic.model.SimpleLogicUIStandalone;
7 import net.mograsim.logic.model.SimpleLogicUIStandalone.VisualisationObjects;
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.GUIBitDisplay;
11 import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
12 import net.mograsim.logic.model.model.wires.GUIWire;
13 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
14
15 public class Am2910Testbench
16 {
17         public static void main(String[] args)
18         {
19                 SimpleLogicUIStandalone.executeVisualisation(Am2910Testbench::create, Am2910Testbench::beforeRun);
20         }
21
22         @SuppressWarnings("unused") // for GUIWires being created
23         public static void create(ViewModelModifiable model)
24         {
25                 GUIComponent am2910 = IndirectGUIComponentCreator.createComponent(model, "file:components/am2910/GUIAm2910.json", "Am2910");
26                 GUIManualSwitch C = new GUIManualSwitch(model, 1, "C");
27                 GUIManualSwitch D = new GUIManualSwitch(model, 12, "D");
28                 GUIManualSwitch _RLD = new GUIManualSwitch(model, 1, "_RLD");
29                 GUIManualSwitch _CC = new GUIManualSwitch(model, 1, "_CC");
30                 GUIManualSwitch _CCEN = new GUIManualSwitch(model, 1, "_CCEN");
31                 GUIManualSwitch I = new GUIManualSwitch(model, 4, "I");
32                 GUIManualSwitch CI = new GUIManualSwitch(model, 1, "CI");
33                 GUIManualSwitch _OE = new GUIManualSwitch(model, 1, "_OE");
34                 GUIBitDisplay _FULL = new GUIBitDisplay(model, 1, "_FULL");
35                 GUIBitDisplay _PL = new GUIBitDisplay(model, 1, "_PL");
36                 GUIBitDisplay _MAP = new GUIBitDisplay(model, 1, "_MAP");
37                 GUIBitDisplay _VECT = new GUIBitDisplay(model, 1, "_VECT");
38                 GUIBitDisplay Y = new GUIBitDisplay(model, 12, "Y");
39
40                 C.moveTo(35, -35);
41                 D.moveTo(10, -20);
42                 _RLD.moveTo(-30, -1.5);
43                 _CC.moveTo(-30, 20);
44                 _CCEN.moveTo(-30, 40);
45                 I.moveTo(-30, 60);
46                 CI.moveTo(75, 45);
47                 _FULL.moveTo(80, 6.5);
48                 _PL.moveTo(30, 85);
49                 _MAP.moveTo(30, 105);
50                 _VECT.moveTo(30, 125);
51                 Y.moveTo(40, 65);
52                 _OE.moveTo(60, 85);
53
54                 new GUIWire(model, C.getOutputPin(), am2910.getPin("C"), new Point(60, -27.5));
55                 new GUIWire(model, D.getOutputPin(), am2910.getPin("D"), new Point(36, -12.5));
56                 new GUIWire(model, _RLD.getOutputPin(), am2910.getPin("_RLD"), new Point[0]);
57                 new GUIWire(model, _CC.getOutputPin(), am2910.getPin("_CC"));
58                 new GUIWire(model, _CCEN.getOutputPin(), am2910.getPin("_CCEN"));
59                 new GUIWire(model, I.getOutputPin(), am2910.getPin("I"));
60                 new GUIWire(model, CI.getOutputPin(), am2910.getPin("CI"), new Point(100, 52.5), new Point(100, 40));
61                 new GUIWire(model, am2910.getPin("_FULL"), _FULL.getInputPin(), new Point[0]);
62                 new GUIWire(model, am2910.getPin("_PL"), _PL.getInputPin(), new Point(13, 92.5));
63                 new GUIWire(model, am2910.getPin("_MAP"), _MAP.getInputPin(), new Point(19, 112.5));
64                 new GUIWire(model, am2910.getPin("_VECT"), _VECT.getInputPin(), new Point(25, 132.5));
65                 new GUIWire(model, am2910.getPin("Y"), Y.getInputPin(), new Point(38, 72.5));
66                 new GUIWire(model, am2910.getPin("_OE"), _OE.getOutputPin());
67         }
68
69         public static void beforeRun(VisualisationObjects vis)
70         {
71                 vis.model.getComponentsByName().values().forEach(c ->
72                 {
73                         if (c instanceof GUIManualSwitch)
74                         {
75                                 GUIManualSwitch cCasted = (GUIManualSwitch) c;
76                                 cCasted.setHighLevelState("out", BitVector.of(Bit.ZERO, cCasted.logicWidth));
77                         }
78                 });
79         }
80 }