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%2FGUIram4.java;h=c34c50c259f7eb76c0e4000e1b2551db40a46b84;hb=574918bb58faa3c617911ed4f629f90066668364;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..c34c50c2 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,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.BitVector; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent; import net.mograsim.logic.ui.model.wires.GUIWire; @@ -9,6 +10,11 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint; public class GUIram4 extends SimpleRectangularSubmodelComponent { + private GUIram2 cell00; + private GUIram2 cell01; + private GUIram2 cell10; + private GUIram2 cell11; + public GUIram4(ViewModelModifiable model) { super(model, 1, "GUIram4"); @@ -47,10 +53,10 @@ public class GUIram4 extends SimpleRectangularSubmodelComponent GUIdemux2 demuxA = new GUIdemux2 (submodelModifiable); GUIdemux2 demuxB = new GUIdemux2 (submodelModifiable); GUIand41 weAndB = new GUIand41 (submodelModifiable); - GUIram2 cell00 = new GUIram2 (submodelModifiable); - GUIram2 cell01 = new GUIram2 (submodelModifiable); - GUIram2 cell10 = new GUIram2 (submodelModifiable); - GUIram2 cell11 = new GUIram2 (submodelModifiable); + cell00 = new GUIram2 (submodelModifiable); + cell01 = new GUIram2 (submodelModifiable); + cell10 = new GUIram2 (submodelModifiable); + cell11 = new GUIram2 (submodelModifiable); GUIand41 andB00 = new GUIand41 (submodelModifiable); GUIandor414 andorB01 = new GUIandor414(submodelModifiable); GUIandor414 andorB10 = new GUIandor414(submodelModifiable); @@ -279,5 +285,111 @@ 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("c10", cell01); + addHighLevelStateSubcomponentID("c01", 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("c11.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) + { + switch (subcomponentID) + { + case "c0000": + case "c0001": + case "c0010": + case "c0011": + cell00.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState); + break; + case "c1000": + case "c1001": + case "c1010": + case "c1011": + cell01.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState); + break; + case "c0100": + case "c0101": + case "c0110": + case "c0111": + cell10.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState); + break; + case "c1100": + case "c1101": + case "c1110": + case "c1111": + cell11.setHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID, newState); + break; + default: + super.setSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID, newState); + break; + } + } + + @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) + { + switch (subcomponentID) + { + case "c0000": + case "c0001": + case "c0010": + case "c0011": + return cell00.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID); + case "c0100": + case "c0101": + case "c0110": + case "c0111": + return cell01.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID); + case "c1000": + case "c1001": + case "c1010": + case "c1011": + return cell10.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID); + case "c1100": + case "c1101": + case "c1110": + case "c1111": + return cell11.getHighLevelState('c' + subcomponentID.substring(3, 5) + "." + subcomponentHighLevelStateID); + default: + return super.getSubcomponentHighLevelState(subcomponentID, subcomponentHighLevelStateID); + } } } \ No newline at end of file