Added a state to SimpleRectangularHardcodedGUIComponent.recalculate
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 10 Aug 2019 12:56:13 +0000 (14:56 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 10 Aug 2019 12:56:13 +0000 (14:56 +0200)
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/am2910/GUIAm2910InstrPLA.java
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java
net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/SimpleRectangularHardcodedGUIComponent.java
net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/componentadapters/SimpleRectangularHardcodedGUIComponentAdapter.java

index 20ae560..b112d03 100644 (file)
@@ -41,7 +41,7 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
        }
 
        @Override
-       protected void recalculate(Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
+       protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
        {
                ReadEnd PASS = readEnds.get("PASS");
                ReadEnd I3 = readEnds.get("I3");
@@ -258,5 +258,6 @@ public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
                                STKI1.feedSignals(STKI1Val);
                        }
                }
+               return null;
        }
 }
\ No newline at end of file
index f2acc61..90ceb28 100644 (file)
@@ -10,6 +10,8 @@ import net.mograsim.logic.model.model.ViewModelModifiable;
 import net.mograsim.logic.model.model.components.GUIComponent;
 import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay;
 import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch;
+import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent;
+import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent.Usage;
 import net.mograsim.logic.model.model.wires.GUIWire;
 import net.mograsim.logic.model.model.wires.Pin;
 
@@ -30,14 +32,20 @@ public class GUIComponentTestbench
                // TODO this code exists four times... but it seems too "hacky" to put it in a helper class
                List<String> inputPinNames = new ArrayList<>();
                List<String> outputPinNames = new ArrayList<>();
-               for (Pin p : comp.getPins().values())
-                       if (p.getRelX() == 0)
-                               inputPinNames.add(p.name);
-                       else
-                               outputPinNames.add(p.name);
-
-               outputPinNames.remove("R=0");
-               inputPinNames.add("R=0");
+               if (comp instanceof SimpleRectangularHardcodedGUIComponent)
+               {
+                       SimpleRectangularHardcodedGUIComponent compCasted = (SimpleRectangularHardcodedGUIComponent) comp;
+                       for (Pin p : comp.getPins().values())
+                               if (compCasted.getPinUsage(p) == Usage.INPUT)
+                                       inputPinNames.add(p.name);
+                               else
+                                       outputPinNames.add(p.name);
+               } else
+                       for (Pin p : comp.getPins().values())
+                               if (p.getRelX() == 0)
+                                       inputPinNames.add(p.name);
+                               else
+                                       outputPinNames.add(p.name);
 
                inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
                outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY)));
@@ -45,15 +53,23 @@ public class GUIComponentTestbench
                comp.moveTo(100, 0);
                for (int i = 0; i < inputPinNames.size(); i++)
                {
-                       GUIManualSwitch sw = new GUIManualSwitch(model);
-                       sw.moveTo(0, 20 * i);
-                       new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin());
+                       String pinName = inputPinNames.get(i);
+                       if (comp.getPin(pinName).logicWidth == 1)
+                       {
+                               GUIManualSwitch sw = new GUIManualSwitch(model);
+                               sw.moveTo(0, 20 * i);
+                               new GUIWire(model, comp.getPin(pinName), sw.getOutputPin());
+                       }
                }
                for (int i = 0; i < outputPinNames.size(); i++)
                {
-                       GUIBitDisplay bd = new GUIBitDisplay(model);
-                       bd.moveTo(200, 20 * i);
-                       new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin());
+                       String pinName = outputPinNames.get(i);
+                       if (comp.getPin(pinName).logicWidth == 1)
+                       {
+                               GUIBitDisplay bd = new GUIBitDisplay(model);
+                               bd.moveTo(200, 20 * i);
+                               new GUIWire(model, comp.getPin(pinName), bd.getInputPin());
+                       }
                }
        }
 }
\ No newline at end of file
index bad9b94..1ced6d4 100644 (file)
@@ -72,7 +72,7 @@ public abstract class SimpleRectangularHardcodedGUIComponent extends GUIComponen
 
        // logic
 
-       protected abstract void recalculate(Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds);
+       protected abstract Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds);
 
        // "graphical" operations
 
index 409805d..04d0736 100644 (file)
@@ -2,7 +2,7 @@ package net.mograsim.logic.model.modeladapter.componentadapters;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.function.BiConsumer;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
 
 import net.mograsim.logic.core.LogicObserver;
@@ -15,12 +15,13 @@ import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcod
 import net.mograsim.logic.model.model.wires.Pin;
 import net.mograsim.logic.model.modeladapter.LogicModelParameters;
 
+//TODO support HighLevelStates
 public class SimpleRectangularHardcodedGUIComponentAdapter implements ComponentAdapter<SimpleRectangularHardcodedGUIComponent>
 {
-       private final Function<SimpleRectangularHardcodedGUIComponent, BiConsumer<Map<String, ReadEnd>, Map<String, ReadWriteEnd>>> recalculateFunctionGenerator;
+       private final Function<SimpleRectangularHardcodedGUIComponent, RecalculateFunction> recalculateFunctionGenerator;
 
        public SimpleRectangularHardcodedGUIComponentAdapter(
-                       Function<SimpleRectangularHardcodedGUIComponent, BiConsumer<Map<String, ReadEnd>, Map<String, ReadWriteEnd>>> recalculateFunctionGenerator)
+                       Function<SimpleRectangularHardcodedGUIComponent, RecalculateFunction> recalculateFunctionGenerator)
        {
                this.recalculateFunctionGenerator = recalculateFunctionGenerator;
        }
@@ -35,11 +36,13 @@ public class SimpleRectangularHardcodedGUIComponentAdapter implements ComponentA
        public void createAndLinkComponent(Timeline timeline, LogicModelParameters params, SimpleRectangularHardcodedGUIComponent guiComponent,
                        Map<Pin, Wire> logicWiresPerPin)
        {
-               BiConsumer<Map<String, ReadEnd>, Map<String, ReadWriteEnd>> recalculate = recalculateFunctionGenerator.apply(guiComponent);
+               RecalculateFunction recalculate = recalculateFunctionGenerator.apply(guiComponent);
                Map<String, ReadEnd> readEnds = new HashMap<>();
                Map<String, ReadWriteEnd> readWriteEnds = new HashMap<>();
 
-               LogicObserver logicObs = c -> recalculate.accept(readEnds, readWriteEnds);
+               AtomicReference<Object> state = new AtomicReference<>();
+
+               LogicObserver logicObs = c -> state.set(recalculate.recalculate(state.get(), readEnds, readWriteEnds));
 
                for (Pin pin : guiComponent.getPins().values())
                {
@@ -57,4 +60,9 @@ public class SimpleRectangularHardcodedGUIComponentAdapter implements ComponentA
                                end.registerObserver(logicObs);
                }
        }
+
+       public static interface RecalculateFunction
+       {
+               public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds);
+       }
 }
\ No newline at end of file