1 package net.mograsim.logic.model.modeladapter.componentadapters;
3 import java.util.HashMap;
6 import net.mograsim.logic.core.LogicObserver;
7 import net.mograsim.logic.core.timeline.Timeline;
8 import net.mograsim.logic.core.wires.CoreWire;
9 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
10 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
11 import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedModelComponent;
12 import net.mograsim.logic.model.model.wires.Pin;
13 import net.mograsim.logic.model.model.wires.PinUsage;
14 import net.mograsim.logic.model.modeladapter.CoreModelParameters;
15 import net.mograsim.logic.model.util.ObservableAtomicReference;
17 public class SimpleRectangularHardcodedModelComponentAdapter implements ComponentAdapter<SimpleRectangularHardcodedModelComponent>
20 public Class<SimpleRectangularHardcodedModelComponent> getSupportedClass()
22 return SimpleRectangularHardcodedModelComponent.class;
26 public void createAndLinkComponent(Timeline timeline, CoreModelParameters params,
27 SimpleRectangularHardcodedModelComponent modelComponent, Map<Pin, CoreWire> logicWiresPerPin)
29 Map<String, ReadEnd> readEnds = new HashMap<>();
30 Map<String, ReadWriteEnd> readWriteEnds = new HashMap<>();
32 ObservableAtomicReference<Object> state = new ObservableAtomicReference<>();
34 Runnable recalculate = () -> state.updateAndGet(s -> modelComponent.recalculate(s, readEnds, readWriteEnds));
35 LogicObserver logicObs = c -> recalculate.run();
37 modelComponent.setCoreModelBindingAndResetState(state, recalculate);
39 for (Pin pin : modelComponent.getPins().values())
41 CoreWire wire = logicWiresPerPin.get(pin);
43 if (pin.usage != PinUsage.INPUT)
45 // TODO do this prettier
46 CoreWire pseudoWire = new CoreWire(timeline, wire.width, params.gateProcessTime);
47 CoreWire.fuse(wire, pseudoWire);
48 readWriteEnds.put(pin.name, pseudoWire.createReadWriteEnd());
50 end = wire.createReadOnlyEnd();
51 readEnds.put(pin.name, end);
52 if (pin.usage != PinUsage.OUTPUT)
53 end.registerObserver(logicObs);