1 package net.mograsim.logic.model.examples;
3 import java.util.ArrayList;
4 import java.util.Comparator;
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;
18 public class ModelComponentTestbench
20 public static void main(String[] args)
22 SimpleLogicUIStandalone.executeVisualisation(ModelComponentTestbench::createTestbench);
25 @SuppressWarnings("unused") // for ModelWires being created
26 public static void createTestbench(LogicModelModifiable model)
29 ModelComponent comp = new Am2900MachineDefinition().createNew(model).getAm2900();
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);
37 outputPinNames.add(p.name);
39 inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
40 outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
43 for (int i = 0; i < inputPinNames.size(); i++)
45 String pinName = inputPinNames.get(i);
46 ModelManualSwitch sw = new ModelManualSwitch(model, comp.getPin(pinName).logicWidth);
48 new ModelWire(model, comp.getPin(pinName), sw.getOutputPin());
50 for (int i = 0; i < outputPinNames.size(); i++)
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());