From 1456c337d67378f8efb78a7066d6538e24a6beb4 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Sat, 31 Aug 2019 22:46:54 +0200 Subject: [PATCH] GUIram5_12 now has HighLevelStates --- .../model/am2900/components/GUIram5_12.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 abc8355d..a8c397c3 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; @@ -83,6 +85,32 @@ 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() != 3) + throw new IllegalArgumentException("Expected BitVector of length 3, not " + newHighLevelStateCasted.length()); + return ((BitVector[]) lastState)[addr] = newHighLevelStateCasted; + } + return super.setHighLevelState(lastState, stateID, newHighLevelState); + } + static { IndirectGUIComponentCreator.setComponentSupplier(GUIram5_12.class.getCanonicalName(), (m, p, n) -> new GUIram5_12(m, n)); -- 2.17.1