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=3d2d8ce2fea10f6dcc8d9c9d6000790b64103749;hb=74bced7a3a38f65c65f3395cc422eb98e34da0b8;hp=b42a05ffd8f484eea97784d4e8fdb972f1b2be53;hpb=b37ba7609a925cc945bbac0f6ead619d07912238;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 b42a05ff..3d2d8ce2 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,6 +1,8 @@ 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; @@ -10,6 +12,8 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint; public class GUI_rsLatch extends SimpleRectangularSubmodelComponent { + private GUIWire wireQ, wire_Q; + public GUI_rsLatch(ViewModelModifiable model) { super(model, 1, "_rsLatch"); @@ -44,7 +48,48 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, nand2.getPin("Y"), cp2, new Point(65, 22.5)); new GUIWire(submodelModifiable, cp1, nand2.getPin("A"), new Point[0]); new GUIWire(submodelModifiable, cp2, nand1.getPin("B"), new Point(65, 42.5), new Point(5, 42.5), new Point(5, 22.5)); - 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)); - new GUIWire(submodelModifiable, cp2, _Q, new Point[0]); + 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]); + } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + 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: + super.setHighLevelState(stateID, newState); + break; + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "q": + if (wireQ.hasLogicModelBinding()) + return wireQ.getWireValues().getBit(0); + return null; + default: + return super.getHighLevelState(stateID); + } } } \ No newline at end of file