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%2FGUIram4.java;h=35d3df5993b98bd8d63c8360fa2b00b0d7734224;hb=2fd5bc7536c065766aaa59113697d5c2ea690962;hp=419836baa01d318e8b820cf18715f575e6d9f5dd;hpb=b37ba7609a925cc945bbac0f6ead619d07912238;p=Mograsim.git diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram4.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram4.java index 419836ba..35d3df59 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram4.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram4.java @@ -1,11 +1,13 @@ package net.mograsim.logic.ui.model.components.mi.nandbased; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent; +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 GUIram4 extends SimpleRectangularSubmodelComponent { @@ -279,5 +281,86 @@ public class GUIram4 extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, andorA11.getPin("Y3"), QA3 , new Point(200, 760), new Point(200, 890), new Point(320, 890), new Point(320, 250)); new GUIWire(submodelModifiable, andorA11.getPin("Y4"), QA4 , new Point(195, 770), new Point(195, 895), new Point(325, 895), new Point(325, 350)); //@formatter:on + + addHighLevelStateSubcomponentID("c00", cell00); + addHighLevelStateSubcomponentID("c01", cell01); + addHighLevelStateSubcomponentID("c10", cell10); + addHighLevelStateSubcomponentID("c11", cell11); + addAtomicHighLevelStateID("q"); + } + + @Override + public void setAtomicHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q": + BitVector newStateCasted = (BitVector) newState; + setHighLevelState("c00.q", newStateCasted.subVector(0, 16)); + setHighLevelState("c01.q", newStateCasted.subVector(16, 32)); + setHighLevelState("c10.q", newStateCasted.subVector(32, 48)); + setHighLevelState("c11.q", newStateCasted.subVector(48, 64)); + break; + default: + // should not happen because we tell SubmodelComponent to only allow these state IDs. + throw new IllegalStateException("Illegal atomic state ID: " + stateID); + } + } + + @Override + protected void setSubcomponentHighLevelState(String subcomponentID, String subcomponentHighLevelStateID, Object newState) + { + if (checkSubcomponentID(subcomponentID)) + setHighLevelState(translateDirectCellAccess(subcomponentID, subcomponentHighLevelStateID), newState); + else + super.setSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID, newState); + + } + + @Override + public Object getAtomicHighLevelState(String stateID) + { + switch (stateID) + { + case "q": + BitVector q00 = (BitVector) getHighLevelState("c00.q"); + BitVector q01 = (BitVector) getHighLevelState("c01.q"); + BitVector q10 = (BitVector) getHighLevelState("c10.q"); + BitVector q11 = (BitVector) getHighLevelState("c11.q"); + return q00.concat(q01).concat(q10).concat(q11); + default: + // should not happen because we tell SubmodelComponent to only allow these state IDs. + throw new IllegalStateException("Illegal atomic state ID: " + stateID); + } + } + + @Override + protected Object getSubcomponentHighLevelState(String subcomponentID, String subcomponentHighLevelStateID) + { + if (checkSubcomponentID(subcomponentID)) + return getHighLevelState(translateDirectCellAccess(subcomponentID, subcomponentHighLevelStateID)); + return super.getSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID); + } + + private static String translateDirectCellAccess(String subcomponentID, String subcomponentHighLevelStateID) + { + return 'c' + subcomponentID.substring(3, 5) + "." + subcomponentID.substring(0, 3) + '.' + subcomponentHighLevelStateID; + } + + private static boolean checkSubcomponentID(String subcomponentID) + { + if (subcomponentID.length() != 5 || subcomponentID.charAt(0) != 'c') + return false; + char addr3 = subcomponentID.charAt(1); + char addr2 = subcomponentID.charAt(2); + char addr1 = subcomponentID.charAt(3); + char addr0 = subcomponentID.charAt(4); + return (addr3 == '0' || addr3 == '1') || (addr2 == '0' || addr2 == '1') || (addr1 == '0' || addr1 == '1') + || (addr0 == '0' || addr0 == '1'); + } + + static + { + IndirectGUIComponentCreator.setComponentProvider(GUIram4.class.getCanonicalName(), (m, p) -> new GUIram4(m)); } } \ No newline at end of file