X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=net.mograsim.logic.ui.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2Fmodel%2Fcomponents%2Fmi%2Fnandbased%2FGUI_rsLatch.java;h=a7f80256f653dd2cac520e34e6ae8f6ca40c9843;hb=c2ba1e811b4ebd9e14377e25fadaf5774a28830e;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..a7f80256 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,7 @@ 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; @@ -54,18 +55,41 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent @Override public void setHighLevelState(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; - 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 + 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).join(wire_Q.getWireValues().getBit(0).not()); + return null; + default: + return super.getHighLevelState(stateID); + } } } \ No newline at end of file