X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model.am2900%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fam2900%2Fcomponents%2FGUIram5_12.java;h=adce29a08f1f19ac43e24ddbadd5068026b5181d;hb=6d3f5892ac40a8a28291a5bf117d345c83061a1b;hp=173b2ee94f30c130cfb8641648937c0594b10941;hpb=bbe38c55aaa999d025f534245f9207a88643f6e5;p=Mograsim.git diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java index 173b2ee9..adce29a0 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/components/GUIram5_12.java @@ -8,6 +8,8 @@ import static net.mograsim.logic.core.types.Bit.ZERO; import java.util.Arrays; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.mograsim.logic.core.types.Bit; import net.mograsim.logic.core.types.BitVector; @@ -35,7 +37,7 @@ public class GUIram5_12 extends SimpleRectangularHardcodedGUIComponent } @Override - protected Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) + public Object recalculate(Object lastState, Map readEnds, Map readWriteEnds) { BitVector[] memC = (BitVector[]) lastState; if (memC == null) @@ -83,6 +85,34 @@ public class GUIram5_12 extends SimpleRectangularHardcodedGUIComponent return (bits[0] == ONE ? 4 : 0) + (bits[1] == ONE ? 2 : 0) + (bits[2] == ONE ? 1 : 0); } + Pattern stateIDPattern = Pattern.compile("c(0[10][10]|100)"); + + @Override + protected Object getHighLevelState(Object state, String stateID) + { + Matcher m = stateIDPattern.matcher(stateID); + if (m.matches()) + return ((BitVector[]) state)[Integer.parseInt(m.group(1), 2)]; + return super.getHighLevelState(state, stateID); + } + + @Override + protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState) + { + Matcher m = stateIDPattern.matcher(stateID); + if (m.matches()) + { + int addr = Integer.parseInt(m.group(1), 2); + BitVector newHighLevelStateCasted = (BitVector) newHighLevelState; + if (newHighLevelStateCasted.length() != 12) + throw new IllegalArgumentException("Expected BitVector of length 12, not " + newHighLevelStateCasted.length()); + BitVector[] memC = (BitVector[]) lastState; + memC[addr] = newHighLevelStateCasted; + return memC; + } + return super.setHighLevelState(lastState, stateID, newHighLevelState); + } + static { IndirectGUIComponentCreator.setComponentSupplier(GUIram5_12.class.getCanonicalName(), (m, p, n) -> new GUIram5_12(m, n));