From 74bced7a3a38f65c65f3395cc422eb98e34da0b8 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Wed, 26 Jun 2019 23:02:59 +0200 Subject: [PATCH] Implemented set/getHighLevelState for most components --- .../components/mi/nandbased/GUI_rsLatch.java | 46 ++++-- .../model/components/mi/nandbased/GUIdff.java | 30 +++- .../components/mi/nandbased/GUIdlatch.java | 30 +++- .../components/mi/nandbased/GUIdlatch4.java | 69 ++++++++- .../components/mi/nandbased/GUIram2.java | 83 ++++++++++- .../components/mi/nandbased/GUIram4.java | 137 +++++++++++++++++- .../mi/nandbased/am2901/GUIAm2901.java | 56 ++++++- .../mi/nandbased/am2901/GUIAm2901QReg.java | 69 ++++++++- .../net/mograsim/logic/ui/LogicUICanvas.java | 28 +++- .../ui/model/components/GUIComponent.java | 6 + .../ui/model/components/GUIManualSwitch.java | 22 ++- .../logic/ui/model/wires/GUIWire.java | 9 ++ 12 files changed, 546 insertions(+), 39 deletions(-) diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java index c493cc4d..3d2d8ce2 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUI_rsLatch.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.Bit; import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.ui.model.ViewModelModifiable; import net.mograsim.logic.ui.model.components.GUINandGate; @@ -54,18 +55,41 @@ public class GUI_rsLatch extends SimpleRectangularSubmodelComponent @Override public void setHighLevelState(String stateID, Object newState) { - if ("q".equals(stateID)) + switch (stateID) { - // TODO force this to happen without any Timeline updates in the meantime. - // Maybe make it a requirement of setHighLevelState that the Timeline is "halted" during a call? - BitVector newStateCasted = (BitVector) newState; - if (wireQ.hasLogicModelBinding()) - wireQ.forceWireValues(newStateCasted); - // We set both wires because then both outputs go to their correct state at the same time, and to avoid problems when not both - // inputs are 1 - if (wire_Q.hasLogicModelBinding()) - wire_Q.forceWireValues(newStateCasted.not()); - } else + case "q": + if (wireQ != null) + { + // TODO force this to happen without any Timeline updates in the meantime. + // Maybe make it a requirement of setHighLevelState that the Timeline is "halted" during a call? + Bit newStateCasted = (Bit) newState; + BitVector newStateVector = BitVector.of(newStateCasted); + if (wireQ.hasLogicModelBinding()) + wireQ.forceWireValues(newStateVector); + // We set both wires because then both outputs go to their correct state at the same time, and to avoid problems when not + // both + // inputs are 1 + if (wire_Q.hasLogicModelBinding()) + wire_Q.forceWireValues(newStateVector.not()); + } + break; + default: super.setHighLevelState(stateID, newState); + break; + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "q": + if (wireQ.hasLogicModelBinding()) + return wireQ.getWireValues().getBit(0); + return null; + default: + return super.getHighLevelState(stateID); + } } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdff.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdff.java index 40f33310..8f183dcc 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdff.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdff.java @@ -10,6 +10,8 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint; public class GUIdff extends SimpleRectangularSubmodelComponent { + private GUI_rsLatch _rsLatch; + public GUIdff(ViewModelModifiable model) { super(model, 1, "GUIdff"); @@ -30,7 +32,7 @@ public class GUIdff extends SimpleRectangularSubmodelComponent GUI_rsLatch _rsLatch1 = new GUI_rsLatch(submodelModifiable); GUInand3 nand3 = new GUInand3(submodelModifiable); GUINandGate nand2 = new GUINandGate(submodelModifiable, 1); - GUI_rsLatch _rsLatch2 = new GUI_rsLatch(submodelModifiable); + GUI_rsLatch _rsLatch2 = this._rsLatch = new GUI_rsLatch(submodelModifiable); WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1); WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1); @@ -62,4 +64,30 @@ public class GUIdff extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, _rsLatch2.getPin("Q"), Q); new GUIWire(submodelModifiable, _rsLatch2.getPin("_Q"), _Q); } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q": + _rsLatch.setHighLevelState("q", newState); + break; + default: + super.setHighLevelState(stateID, newState); + break; + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "q": + return _rsLatch.getHighLevelState("q"); + default: + return super.getHighLevelState(stateID); + } + } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch.java index f6246a44..009e6f05 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch.java @@ -10,6 +10,8 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint; public class GUIdlatch extends SimpleRectangularSubmodelComponent { + private GUI_rsLatch _rsLatch; + public GUIdlatch(ViewModelModifiable model) { super(model, 1, "GUIdlatch"); @@ -29,7 +31,7 @@ public class GUIdlatch extends SimpleRectangularSubmodelComponent GUINandGate nand1 = new GUINandGate(submodelModifiable, 1); GUINandGate nand2 = new GUINandGate(submodelModifiable, 1); - GUI_rsLatch _rsLatch = new GUI_rsLatch(submodelModifiable); + _rsLatch = new GUI_rsLatch(submodelModifiable); WireCrossPoint cp1 = new WireCrossPoint(submodelModifiable, 1); WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1); @@ -51,4 +53,30 @@ public class GUIdlatch extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, _rsLatch.getPin("Q"), Q, new Point[0]); new GUIWire(submodelModifiable, _rsLatch.getPin("_Q"), _Q); } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q": + _rsLatch.setHighLevelState("q", newState); + break; + default: + super.setHighLevelState(stateID, newState); + break; + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "q": + return _rsLatch.getHighLevelState("q"); + default: + return super.getHighLevelState(stateID); + } + } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java index 440cfb40..8da90e16 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIdlatch4.java @@ -1,6 +1,8 @@ package net.mograsim.logic.ui.model.components.mi.nandbased; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.core.types.Bit; +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 +11,11 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint; public class GUIdlatch4 extends SimpleRectangularSubmodelComponent { + private GUIdlatch dlatch1; + private GUIdlatch dlatch2; + private GUIdlatch dlatch3; + private GUIdlatch dlatch4; + public GUIdlatch4(ViewModelModifiable model) { super(model, 1, "GUIdlatch4"); @@ -31,10 +38,10 @@ public class GUIdlatch4 extends SimpleRectangularSubmodelComponent Pin Q3 = getSubmodelPin("Q3"); Pin Q4 = getSubmodelPin("Q4"); - GUIdlatch dlatch1 = new GUIdlatch(submodelModifiable); - GUIdlatch dlatch2 = new GUIdlatch(submodelModifiable); - GUIdlatch dlatch3 = new GUIdlatch(submodelModifiable); - GUIdlatch dlatch4 = new GUIdlatch(submodelModifiable); + dlatch1 = new GUIdlatch(submodelModifiable); + dlatch2 = new GUIdlatch(submodelModifiable); + dlatch3 = new GUIdlatch(submodelModifiable); + dlatch4 = new GUIdlatch(submodelModifiable); WireCrossPoint cp2 = new WireCrossPoint(submodelModifiable, 1); WireCrossPoint cp3 = new WireCrossPoint(submodelModifiable, 1); @@ -64,4 +71,58 @@ public class GUIdlatch4 extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, dlatch3.getPin("Q"), Q3, new Point[0]); new GUIWire(submodelModifiable, dlatch4.getPin("Q"), Q4, new Point[0]); } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q1": + dlatch1.setHighLevelState("q", newState); + break; + case "q2": + dlatch2.setHighLevelState("q", newState); + break; + case "q3": + dlatch3.setHighLevelState("q", newState); + break; + case "q4": + dlatch4.setHighLevelState("q", newState); + break; + case "q": + BitVector newStateCasted = (BitVector) newState; + setHighLevelState("q1", newStateCasted.getBit(0)); + setHighLevelState("q2", newStateCasted.getBit(1)); + setHighLevelState("q3", newStateCasted.getBit(2)); + setHighLevelState("q4", newStateCasted.getBit(3)); + break; + default: + super.setHighLevelState(stateID, newState); + break; + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "q1": + return dlatch1.getHighLevelState("q"); + case "q2": + return dlatch2.getHighLevelState("q"); + case "q3": + return dlatch3.getHighLevelState("q"); + case "q4": + return dlatch4.getHighLevelState("q"); + case "q": + Bit q1 = (Bit) getHighLevelState("q1"); + Bit q2 = (Bit) getHighLevelState("q2"); + Bit q3 = (Bit) getHighLevelState("q3"); + Bit q4 = (Bit) getHighLevelState("q4"); + return BitVector.of(q1, q2, q3, q4); + default: + return super.getHighLevelState(stateID); + } + } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram2.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram2.java index f94ca923..3e4d013d 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram2.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/GUIram2.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 GUIram2 extends SimpleRectangularSubmodelComponent { + private GUIdlatch4 cell00; + private GUIdlatch4 cell01; + private GUIdlatch4 cell10; + private GUIdlatch4 cell11; + public GUIram2(ViewModelModifiable model) { super(model, 1, "GUIram2"); @@ -43,10 +49,10 @@ public class GUIram2 extends SimpleRectangularSubmodelComponent GUIdemux2 demuxA = new GUIdemux2 (submodelModifiable); GUIdemux2 demuxB = new GUIdemux2 (submodelModifiable); GUIand41 weAndB = new GUIand41 (submodelModifiable); - GUIdlatch4 cell00 = new GUIdlatch4 (submodelModifiable); - GUIdlatch4 cell01 = new GUIdlatch4 (submodelModifiable); - GUIdlatch4 cell10 = new GUIdlatch4 (submodelModifiable); - GUIdlatch4 cell11 = new GUIdlatch4 (submodelModifiable); + cell00 = new GUIdlatch4 (submodelModifiable); + cell01 = new GUIdlatch4 (submodelModifiable); + cell10 = new GUIdlatch4 (submodelModifiable); + cell11 = new GUIdlatch4 (submodelModifiable); GUIand41 andA00 = new GUIand41 (submodelModifiable); GUIandor414 andorA01 = new GUIandor414(submodelModifiable); GUIandor414 andorA10 = new GUIandor414(submodelModifiable); @@ -272,4 +278,73 @@ public class GUIram2 extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, andorB11.getPin("Y4"), QB4 , new Point(175, 770), new Point(175, 895), new Point(340, 895), new Point(340, 750)); //@formatter:on } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q": + BitVector newStateCasted = (BitVector) newState; + setHighLevelState("c00.q", newStateCasted.subVector(0, 4)); + setHighLevelState("c01.q", newStateCasted.subVector(4, 8)); + setHighLevelState("c10.q", newStateCasted.subVector(8, 12)); + setHighLevelState("c11.q", newStateCasted.subVector(12, 16)); + break; + default: + int indexOfDot = stateID.indexOf('.'); + if (indexOfDot != -1) + switch (stateID.substring(0, indexOfDot)) + { + case "c00": + cell00.setHighLevelState(stateID.substring(indexOfDot + 1), newState); + break; + case "c01": + cell01.setHighLevelState(stateID.substring(indexOfDot + 1), newState); + break; + case "c10": + cell10.setHighLevelState(stateID.substring(indexOfDot + 1), newState); + break; + case "c11": + cell11.setHighLevelState(stateID.substring(indexOfDot + 1), newState); + break; + default: + super.setHighLevelState(stateID, newState); + break; + } + else + super.setHighLevelState(stateID, newState); + } + } + + @Override + public Object getHighLevelState(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: + int indexOfDot = stateID.indexOf('.'); + if (indexOfDot != -1) + switch (stateID.substring(0, indexOfDot)) + { + case "c00": + return cell00.getHighLevelState(stateID.substring(indexOfDot + 1)); + case "c01": + return cell01.getHighLevelState(stateID.substring(indexOfDot + 1)); + case "c10": + return cell10.getHighLevelState(stateID.substring(indexOfDot + 1)); + case "c11": + return cell11.getHighLevelState(stateID.substring(indexOfDot + 1)); + default: + return super.getHighLevelState(stateID); + } + return super.getHighLevelState(stateID); + } + } } \ No newline at end of file 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..d982f018 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); @@ -280,4 +286,127 @@ public class GUIram4 extends SimpleRectangularSubmodelComponent 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 } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "q": + BitVector q0000 = (BitVector) getHighLevelState("c0000.q"); + BitVector q0001 = (BitVector) getHighLevelState("c0001.q"); + BitVector q0010 = (BitVector) getHighLevelState("c0010.q"); + BitVector q0011 = (BitVector) getHighLevelState("c0011.q"); + BitVector q0100 = (BitVector) getHighLevelState("c0100.q"); + BitVector q0101 = (BitVector) getHighLevelState("c0101.q"); + BitVector q0110 = (BitVector) getHighLevelState("c0110.q"); + BitVector q0111 = (BitVector) getHighLevelState("c0111.q"); + BitVector q1000 = (BitVector) getHighLevelState("c1000.q"); + BitVector q1001 = (BitVector) getHighLevelState("c1001.q"); + BitVector q1010 = (BitVector) getHighLevelState("c1010.q"); + BitVector q1011 = (BitVector) getHighLevelState("c1011.q"); + BitVector q1100 = (BitVector) getHighLevelState("c1100.q"); + BitVector q1101 = (BitVector) getHighLevelState("c1101.q"); + BitVector q1110 = (BitVector) getHighLevelState("c1110.q"); + BitVector q1111 = (BitVector) getHighLevelState("c1111.q"); + return q0000.concat(q0001).concat(q0010).concat(q0011).concat(q0100).concat(q0101).concat(q0110).concat(q0111).concat(q1000) + .concat(q1001).concat(q1010).concat(q1011).concat(q1100).concat(q1101).concat(q1110).concat(q1111); + default: + int indexOfDot = stateID.indexOf('.'); + if (indexOfDot != -1) + { + String cellID = stateID.substring(0, indexOfDot); + switch (cellID) + { + case "c0000": + case "c0001": + case "c0010": + case "c0011": + return cell00.getHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot)); + case "c0100": + case "c0101": + case "c0110": + case "c0111": + return cell01.getHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot)); + case "c1000": + case "c1001": + case "c1010": + case "c1011": + return cell10.getHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot)); + case "c1100": + case "c1101": + case "c1110": + case "c1111": + return cell11.getHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot)); + default: + return super.getHighLevelState(stateID); + } + } + return super.getHighLevelState(stateID); + } + } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q": + BitVector newStateCasted = (BitVector) newState; + setHighLevelState("c0000.q", newStateCasted.subVector(0, 4)); + setHighLevelState("c0001.q", newStateCasted.subVector(4, 8)); + setHighLevelState("c0010.q", newStateCasted.subVector(8, 12)); + setHighLevelState("c0011.q", newStateCasted.subVector(12, 16)); + setHighLevelState("c0100.q", newStateCasted.subVector(16, 20)); + setHighLevelState("c0101.q", newStateCasted.subVector(20, 24)); + setHighLevelState("c0110.q", newStateCasted.subVector(24, 28)); + setHighLevelState("c0111.q", newStateCasted.subVector(28, 32)); + setHighLevelState("c1000.q", newStateCasted.subVector(32, 36)); + setHighLevelState("c1001.q", newStateCasted.subVector(36, 40)); + setHighLevelState("c1010.q", newStateCasted.subVector(40, 44)); + setHighLevelState("c1011.q", newStateCasted.subVector(44, 48)); + setHighLevelState("c1100.q", newStateCasted.subVector(48, 52)); + setHighLevelState("c1101.q", newStateCasted.subVector(52, 56)); + setHighLevelState("c1110.q", newStateCasted.subVector(56, 60)); + setHighLevelState("c1111.q", newStateCasted.subVector(60, 64)); + break; + default: + int indexOfDot = stateID.indexOf('.'); + if (indexOfDot != -1) + { + String cellID = stateID.substring(0, indexOfDot); + switch (cellID) + { + case "c0000": + case "c0001": + case "c0010": + case "c0011": + cell00.setHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot), newState); + break; + case "c0100": + case "c0101": + case "c0110": + case "c0111": + cell01.setHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot), newState); + break; + case "c1000": + case "c1001": + case "c1010": + case "c1011": + cell10.setHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot), newState); + break; + case "c1100": + case "c1101": + case "c1110": + case "c1111": + cell11.setHighLevelState('c' + cellID.substring(3, 5) + stateID.substring(indexOfDot), newState); + break; + default: + super.setHighLevelState(stateID, newState); + break; + } + } else + super.setHighLevelState(stateID, newState); + } + } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901.java index d08145d5..b589e67e 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901.java @@ -16,6 +16,9 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint; public class GUIAm2901 extends SimpleRectangularSubmodelComponent { + private GUIram4 ram; + private GUIAm2901QReg qreg; + public GUIAm2901(ViewModelModifiable model) { super(model, 1, "GUIAm2901"); @@ -76,12 +79,12 @@ public class GUIAm2901 extends SimpleRectangularSubmodelComponent GUIAm2901ALUInclSourceDecodeInclFunctionDecode alu = new GUIAm2901ALUInclSourceDecodeInclFunctionDecode(submodelModifiable); GUIor4 Fneq0 = new GUIor4(submodelModifiable); GUINandGate notFneq0 = new GUINandGate(submodelModifiable, 1); - GUIram4 ram = new GUIram4(submodelModifiable); + ram = new GUIram4(submodelModifiable); GUIdlatch4 QAlatch = new GUIdlatch4(submodelModifiable); GUIdlatch4 QBlatch = new GUIdlatch4(submodelModifiable); GUIsel3_4 ramDsel = new GUIsel3_4(submodelModifiable); GUIsel3_4 qregDsel = new GUIsel3_4(submodelModifiable); - GUIAm2901QReg qreg = new GUIAm2901QReg(submodelModifiable); + qreg = new GUIAm2901QReg(submodelModifiable); WireCrossPoint cpC1 = new WireCrossPoint(submodelModifiable, 1); WireCrossPoint cpC2 = new WireCrossPoint(submodelModifiable, 1); @@ -340,4 +343,53 @@ public class GUIAm2901 extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, cpFneq0, notFneq0.getPin("B"), new Point(315, 455)); new GUIWire(submodelModifiable, notFneq0.getPin("Y"), Feq0, new Point[0]); } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + default: + int indexOfDot = stateID.indexOf('.'); + if (indexOfDot != -1) + { + switch (stateID.substring(0, indexOfDot)) + { + case "regs": + ram.setHighLevelState(stateID.substring(indexOfDot + 1), newState); + break; + case "qreg": + qreg.setHighLevelState(stateID.substring(indexOfDot + 1), newState); + break; + default: + super.setHighLevelState(stateID, newState); + break; + } + } else + super.setHighLevelState(stateID, newState); + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + default: + int indexOfDot = stateID.indexOf('.'); + if (indexOfDot != -1) + { + switch (stateID.substring(0, indexOfDot)) + { + case "regs": + return ram.getHighLevelState(stateID.substring(indexOfDot + 1)); + case "qreg": + return qreg.getHighLevelState(stateID.substring(indexOfDot + 1)); + default: + return super.getHighLevelState(stateID); + } + } + return super.getHighLevelState(stateID); + } + } } \ No newline at end of file diff --git a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901QReg.java b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901QReg.java index 71008b12..eaec5016 100644 --- a/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901QReg.java +++ b/net.mograsim.logic.ui.am2900/src/net/mograsim/logic/ui/model/components/mi/nandbased/am2901/GUIAm2901QReg.java @@ -1,6 +1,8 @@ package net.mograsim.logic.ui.model.components.mi.nandbased.am2901; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; +import net.mograsim.logic.core.types.Bit; +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.mi.nandbased.GUIand; @@ -11,6 +13,11 @@ import net.mograsim.logic.ui.model.wires.WireCrossPoint; public class GUIAm2901QReg extends SimpleRectangularSubmodelComponent { + private GUIdff dff1; + private GUIdff dff2; + private GUIdff dff3; + private GUIdff dff4; + public GUIAm2901QReg(ViewModelModifiable model) { super(model, 1, "GUIAm2901QReg"); @@ -35,10 +42,10 @@ public class GUIAm2901QReg extends SimpleRectangularSubmodelComponent Pin Q4 = getSubmodelPin("Q4"); GUIand and = new GUIand(submodelModifiable); - GUIdff dff1 = new GUIdff(submodelModifiable); - GUIdff dff2 = new GUIdff(submodelModifiable); - GUIdff dff3 = new GUIdff(submodelModifiable); - GUIdff dff4 = new GUIdff(submodelModifiable); + dff1 = new GUIdff(submodelModifiable); + dff2 = new GUIdff(submodelModifiable); + dff3 = new GUIdff(submodelModifiable); + dff4 = new GUIdff(submodelModifiable); WireCrossPoint cpC1 = new WireCrossPoint(submodelModifiable, 1); WireCrossPoint cpC2 = new WireCrossPoint(submodelModifiable, 1); @@ -72,4 +79,58 @@ public class GUIAm2901QReg extends SimpleRectangularSubmodelComponent new GUIWire(submodelModifiable, dff3.getPin("Q"), Q3, new Point[0]); new GUIWire(submodelModifiable, dff4.getPin("Q"), Q4, new Point[0]); } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "q1": + dff1.setHighLevelState("q", newState); + break; + case "q2": + dff2.setHighLevelState("q", newState); + break; + case "q3": + dff3.setHighLevelState("q", newState); + break; + case "q4": + dff4.setHighLevelState("q", newState); + break; + case "q": + BitVector newStateCasted = (BitVector) newState; + setHighLevelState("q1", newStateCasted.getBit(0)); + setHighLevelState("q2", newStateCasted.getBit(1)); + setHighLevelState("q3", newStateCasted.getBit(2)); + setHighLevelState("q4", newStateCasted.getBit(3)); + break; + default: + super.setHighLevelState(stateID, newState); + break; + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "q1": + return dff1.getHighLevelState("q"); + case "q2": + return dff2.getHighLevelState("q"); + case "q3": + return dff3.getHighLevelState("q"); + case "q4": + return dff4.getHighLevelState("q"); + case "q": + Bit q1 = (Bit) getHighLevelState("q1"); + Bit q2 = (Bit) getHighLevelState("q2"); + Bit q3 = (Bit) getHighLevelState("q3"); + Bit q4 = (Bit) getHighLevelState("q4"); + return BitVector.of(q1, q2, q3, q4); + default: + return super.getHighLevelState(stateID); + } + } } \ No newline at end of file diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java index 4bc4f672..08a40a45 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java @@ -104,9 +104,11 @@ public class LogicUICanvas extends ZoomableCanvas Text valueText = new Text(debugShell, SWT.SINGLE | SWT.LEAD | SWT.BORDER); valueText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); Button send = new Button(debugShell, SWT.PUSH); - Text lastError = new Text(debugShell, SWT.READ_ONLY); - lastError.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); send.setText("Send!"); + Button get = new Button(debugShell, SWT.PUSH); + get.setText("Get!"); + Text output = new Text(debugShell, SWT.READ_ONLY); + output.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Listener sendAction = e -> { try @@ -123,16 +125,30 @@ public class LogicUICanvas extends ZoomableCanvas else throw new RuntimeException("No value type selected"); target.setHighLevelState(stateIDText.getText(), value); - lastError.setText("Success!"); + output.setText("Success!"); } catch (Exception x) { - lastError.setText(x.getMessage()); + output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage())); + } + }; + Listener getAction = e -> + { + try + { + if (componentSelector.getSelectionIndex() >= componentsByItemIndex.size()) + throw new RuntimeException("No valid component selected"); + output.setText("Success! Value: \r\n" + componentsByItemIndex.get(componentSelector.getSelectionIndex()).getHighLevelState(stateIDText.getText())); + } + catch (Exception x) + { + output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage())); } }; - stateIDText.addListener(SWT.DefaultSelection, sendAction); - valueText.addListener(SWT.DefaultSelection, sendAction); send.addListener(SWT.Selection, sendAction); + valueText.addListener(SWT.DefaultSelection, sendAction); + get.addListener(SWT.Selection, getAction); + stateIDText.addListener(SWT.DefaultSelection, getAction); debugShell.open(); } diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java index a852c57a..fd48e621 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java @@ -146,6 +146,12 @@ public abstract class GUIComponent throw new IllegalArgumentException("No high level state with ID " + stateID); } + @SuppressWarnings("static-method") // this method is intended to be overridden + public Object getHighLevelState(String stateID) + { + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + // "graphical" operations /** diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java index 77decef2..e88bfdf6 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIManualSwitch.java @@ -77,12 +77,30 @@ public class GUIManualSwitch extends GUIComponent @Override public void setHighLevelState(String stateID, Object newState) { - if ("out".equals(stateID)) + switch (stateID) { + case "out": if (logicSwitch != null) logicSwitch.setToValueOf((Bit) newState); - } else + break; + default: super.setHighLevelState(stateID, newState); + break; + } + } + + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "out": + if (logicSwitch != null) + return logicSwitch.getValue(); + return null; + default: + return super.getHighLevelState(stateID); + } } private void registerLogicObs(LogicObservable observable) diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java index db6d4407..99adc4c3 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/wires/GUIWire.java @@ -327,6 +327,15 @@ public class GUIWire end.getWire().forceValues(values); } + /** + * If this {@link GUIWire} has a logic model binding, delegates to {@link ReadEnd#getValues()} for the {@link ReadEnd} corresponding to + * this {@link GUIWire}. + */ + public BitVector getWireValues() + { + return end.getValues(); + } + // listeners // @formatter:off -- 2.17.1