X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2Fmi%2Fnandbased%2FGUI_rsLatch.java;h=b190ffa8ebe51d6c75e224426bbf8c74c51a0289;hb=2fd5bc7536c065766aaa59113697d5c2ea690962;hp=c493cc4d6094adaab09728ff1d842151c9d7d49b;hpb=6c1fd50db4ade47f87011879b4a6548495eb183f;p=Mograsim.git diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java index c493cc4d..b190ffa8 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java @@ -1,13 +1,15 @@ package net.mograsim.logic.ui.model.components.mi.nandbased; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.core.types.Bit; import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.GUINandGate; -import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent; +import net.mograsim.logic.ui.model.components.atomic.GUINandGate; +import net.mograsim.logic.ui.model.components.submodels.SimpleRectangularSubmodelComponent; import net.mograsim.logic.ui.model.wires.GUIWire; import net.mograsim.logic.ui.model.wires.Pin; import net.mograsim.logic.ui.model.wires.WireCrossPoint; +import net.mograsim.logic.ui.serializing.IndirectGUIComponentCreator; public class GUI_rsLatch extends SimpleRectangularSubmodelComponent { @@ -49,23 +51,54 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, cp2, nand1.getPin("B"), new Point(65, 42.5), new Point(5, 42.5), new Point(5, 22.5)); wireQ = new GUIWire(submodelModifiable, cp1, Q, new Point(35, 17.5), new Point(35, 7.5), new Point(65, 7.5), new Point(65, 12.5)); wire_Q = new GUIWire(submodelModifiable, cp2, _Q, new Point[0]); + + addAtomicHighLevelStateID("q"); } @Override - public void setHighLevelState(String stateID, Object newState) + public void setAtomicHighLevelState(String stateID, Object newState) { - if ("q".equals(stateID)) + switch (stateID) { - // TODO force this to happen without any Timeline updates in the meantime. - // Maybe make it a requirement of setHighLevelState that the Timeline is "halted" during a call? - BitVector newStateCasted = (BitVector) newState; + case "q": + if (wireQ != null) + { + // TODO force this to happen without any Timeline updates in the meantime. + // Maybe make it a requirement of setHighLevelState that the Timeline is "halted" during a call? + Bit newStateCasted = (Bit) newState; + BitVector newStateVector = BitVector.of(newStateCasted); + if (wireQ.hasLogicModelBinding()) + wireQ.forceWireValues(newStateVector); + // We set both wires because then both outputs go to their correct state at the same time, and to avoid problems when not + // both + // inputs are 1 + if (wire_Q.hasLogicModelBinding()) + wire_Q.forceWireValues(newStateVector.not()); + } + break; + default: + // should not happen because we tell SubmodelComponent to only allow these state IDs. + throw new IllegalStateException("Illegal atomic state ID: " + stateID); + } + } + + @Override + public Object getAtomicHighLevelState(String stateID) + { + switch (stateID) + { + case "q": if (wireQ.hasLogicModelBinding()) - wireQ.forceWireValues(newStateCasted); - // We set both wires because then both outputs go to their correct state at the same time, and to avoid problems when not both - // inputs are 1 - if (wire_Q.hasLogicModelBinding()) - wire_Q.forceWireValues(newStateCasted.not()); - } else - super.setHighLevelState(stateID, newState); + return wireQ.getWireValues().getBit(0); + return null; + default: + // should not happen because we tell SubmodelComponent to only allow these state IDs. + throw new IllegalStateException("Illegal atomic state ID: " + stateID); + } + } + + static + { + IndirectGUIComponentCreator.setComponentProvider(GUI_rsLatch.class.getCanonicalName(), (m, p) -> new GUI_rsLatch(m)); } } \ No newline at end of file