}
@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");
STKI1.feedSignals(STKI1Val);
}
}
+ return null;
}
}
\ No newline at end of file
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;
// 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)));
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
// 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
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;
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;
}
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())
{
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