297075a8daf6728f23a9a19ee8a7bb8cca2d35eb
[Mograsim.git] /
1 package net.mograsim.logic.model.examples;
2
3 import java.util.ArrayList;
4 import java.util.Comparator;
5 import java.util.List;
6
7 import net.mograsim.logic.model.SimpleLogicUIStandalone;
8 import net.mograsim.logic.model.am2900.Am2900Loader;
9 import net.mograsim.logic.model.am2900.machine.Am2900MachineDefinition;
10 import net.mograsim.logic.model.model.LogicModelModifiable;
11 import net.mograsim.logic.model.model.components.ModelComponent;
12 import net.mograsim.logic.model.model.components.atomic.ModelBitDisplay;
13 import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch;
14 import net.mograsim.logic.model.model.wires.ModelWire;
15 import net.mograsim.logic.model.model.wires.Pin;
16 import net.mograsim.logic.model.model.wires.PinUsage;
17
18 public class ModelComponentTestbench
19 {
20         public static void main(String[] args)
21         {
22                 SimpleLogicUIStandalone.executeVisualisation(ModelComponentTestbench::createTestbench);
23         }
24
25         @SuppressWarnings("unused") // for ModelWires being created
26         public static void createTestbench(LogicModelModifiable model)
27         {
28                 Am2900Loader.setup();
29                 ModelComponent comp = new Am2900MachineDefinition().createNew(model).getAm2900();
30
31                 List<String> inputPinNames = new ArrayList<>();
32                 List<String> outputPinNames = new ArrayList<>();
33                 for (Pin p : comp.getPins().values())
34                         if (p.usage == PinUsage.INPUT)
35                                 inputPinNames.add(p.name);
36                         else
37                                 outputPinNames.add(p.name);
38
39                 inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
40                 outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
41
42                 comp.moveTo(100, 0);
43                 for (int i = 0; i < inputPinNames.size(); i++)
44                 {
45                         String pinName = inputPinNames.get(i);
46                         ModelManualSwitch sw = new ModelManualSwitch(model, comp.getPin(pinName).logicWidth);
47                         sw.moveTo(0, 20 * i);
48                         new ModelWire(model, comp.getPin(pinName), sw.getOutputPin());
49                 }
50                 for (int i = 0; i < outputPinNames.size(); i++)
51                 {
52                         String pinName = outputPinNames.get(i);
53                         ModelBitDisplay bd = new ModelBitDisplay(model, comp.getPin(pinName).logicWidth);
54                         bd.moveTo(200, 20 * i);
55                         new ModelWire(model, comp.getPin(pinName), bd.getInputPin());
56                 }
57         }
58 }