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=7a1409e8b198cc9b40aa8a3997f2a5c0c7c046de;hb=bfd483ea32de08383550ba6903f77c11c33ea36d;hp=7dcea02278823d679dd6c8f801729184832aaee7;hpb=bece76750849d1c9374aaa3772dcad552527f60b;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 7dcea022..7a1409e8 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 @@ -1,9 +1,15 @@ package net.mograsim.logic.model.am2900.components; -import static net.mograsim.logic.core.types.Bit.*; +import static net.mograsim.logic.core.types.Bit.ONE; +import static net.mograsim.logic.core.types.Bit.U; +import static net.mograsim.logic.core.types.Bit.X; +import static net.mograsim.logic.core.types.Bit.Z; +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; @@ -12,6 +18,8 @@ import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent; import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.model.wires.PinUsage; +import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position; public class GUIram5_12 extends SimpleRectangularHardcodedGUIComponent @@ -20,16 +28,16 @@ public class GUIram5_12 extends SimpleRectangularHardcodedGUIComponent { super(model, name, "RAM\n5 x 12 Bit"); setSize(40, 40); - addPin(new Pin(this, "A", 3, 10, 0), Usage.INPUT, Position.BOTTOM); - addPin(new Pin(this, "B", 3, 30, 0), Usage.INPUT, Position.BOTTOM); - addPin(new Pin(this, "WE", 1, 0, 5), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "C", 1, 0, 15), Usage.INPUT, Position.RIGHT); - addPin(new Pin(this, "Y", 12, 0, 30), Usage.OUTPUT, Position.RIGHT); - addPin(new Pin(this, "D", 12, 20, 40), Usage.INPUT, Position.TOP); + addPin(new Pin(this, "A", 3, PinUsage.INPUT, 10, 0), Position.BOTTOM); + addPin(new Pin(this, "B", 3, PinUsage.INPUT, 30, 0), Position.BOTTOM); + addPin(new Pin(this, "WE", 1, PinUsage.INPUT, 0, 5), Position.RIGHT); + addPin(new Pin(this, "C", 1, PinUsage.INPUT, 0, 15), Position.RIGHT); + addPin(new Pin(this, "Y", 12, PinUsage.OUTPUT, 0, 30), Position.RIGHT); + addPin(new Pin(this, "D", 12, PinUsage.INPUT, 20, 40), Position.TOP); } @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) @@ -73,7 +81,39 @@ public class GUIram5_12 extends SimpleRectangularHardcodedGUIComponent for (int i = 0; i < 3; i++) if (bits[i] == Z) return -1; - // TODO maybe this is the wrong way around 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)); + } } \ No newline at end of file