From: Daniel Kirschten Date: Sat, 10 Aug 2019 16:32:19 +0000 (+0200) Subject: GUIBitDisplay and GUIManualSwitch now support logicWidth != 1 X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=8c26f70ef8444eae412b35805de3fd43fe3ef345;p=Mograsim.git GUIBitDisplay and GUIManualSwitch now support logicWidth != 1 --- diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java index 9ec98ede..26238fe6 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java @@ -8,6 +8,7 @@ import net.mograsim.logic.core.LogicObservable; import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.timeline.Timeline; import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.core.wires.Wire.ReadEnd; import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; @@ -26,49 +27,50 @@ public class ManualSwitch extends Component implements LogicObservable { super(timeline); observers = new ArrayList<>(); - if (output.length() != 1) - throw new IllegalArgumentException("Switch output can be only a single wire"); this.output = output; } - public void switchOn() + public void switchFullOn() { - setState(true); + setState(BitVector.of(Bit.ONE, output.length())); } - public void switchOff() + public void switchFullOff() { - setState(false); + setState(BitVector.of(Bit.ZERO, output.length())); } public void toggle() { - setState(!isOn()); + if (isFullOn()) + switchFullOff(); + else + switchFullOn(); } - public void setState(boolean isOn) + public void setState(Bit bit) { - setToValueOf(isOn ? Bit.ONE : Bit.ZERO); + setState(BitVector.of(bit)); } - public void setToValueOf(Bit bit) + public void setState(BitVector bits) { - if (!bit.isBinary()) - throw new IllegalArgumentException("Cannot set ManualSwitch to the value of Bit " + bit); - if (bit == output.getInputValue()) + if (bits.length() != output.length()) + throw new IllegalArgumentException("Incorrect bit vector length"); + if (bits.equals(output.getInputValues())) return; - output.feedSignals(bit); + output.feedSignals(bits); notifyObservers(); } - public boolean isOn() + public boolean isFullOn() { - return output.getInputValue() == Bit.ONE; + return BitVector.of(Bit.ONE, output.length()).equals(output.getInputValues()); } - public Bit getValue() + public BitVector getValues() { - return output.getInputValue(); + return output.getInputValues(); } @Override diff --git a/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/GUITest.java b/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/GUITest.java index 544b064f..86eb115d 100644 --- a/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/GUITest.java +++ b/net.mograsim.logic.core/test/net/mograsim/logic/core/tests/GUITest.java @@ -66,7 +66,7 @@ public class GUITest extends JPanel { if (dim.getValue().contains(e.getPoint())) { - dim.getKey().switchOff(); + dim.getKey().switchFullOff(); repaint(); } } @@ -79,7 +79,7 @@ public class GUITest extends JPanel { if (dim.getValue().contains(e.getPoint())) { - dim.getKey().switchOn(); + dim.getKey().switchFullOn(); repaint(); } } @@ -220,7 +220,7 @@ public class GUITest extends JPanel switchMap.put(ms, r); } - g.setColor(ms.isOn() ? Color.getHSBColor(.3f, .5f, 1f) : Color.WHITE); + g.setColor(ms.isFullOn() ? Color.getHSBColor(.3f, .5f, 1f) : Color.WHITE); g.fillRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); setBlack(g); g.drawRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); diff --git a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java index 7f42c019..b745891d 100644 --- a/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java +++ b/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/GUIComponentTestbench.java @@ -54,22 +54,16 @@ public class GUIComponentTestbench for (int i = 0; i < inputPinNames.size(); i++) { String pinName = inputPinNames.get(i); - if (comp.getPin(pinName).logicWidth == 1) - { - GUIManualSwitch sw = new GUIManualSwitch(model); - sw.moveTo(0, 20 * i); - new GUIWire(model, comp.getPin(pinName), sw.getOutputPin()); - } + GUIManualSwitch sw = new GUIManualSwitch(model, comp.getPin(pinName).logicWidth); + sw.moveTo(0, 20 * i); + new GUIWire(model, comp.getPin(pinName), sw.getOutputPin()); } for (int i = 0; i < outputPinNames.size(); i++) { String pinName = outputPinNames.get(i); - if (comp.getPin(pinName).logicWidth == 1) - { - GUIBitDisplay bd = new GUIBitDisplay(model); - bd.moveTo(200, 20 * i); - new GUIWire(model, comp.getPin(pinName), bd.getInputPin()); - } + GUIBitDisplay bd = new GUIBitDisplay(model, comp.getPin(pinName).logicWidth); + bd.moveTo(200, 20 * i); + new GUIWire(model, comp.getPin(pinName), bd.getInputPin()); } } } \ No newline at end of file diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java index 34154e60..731147ce 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/Am2901Testbench.java @@ -31,7 +31,7 @@ public class Am2901Testbench comp.moveTo(240, 0); - GUIManualSwitch enable = new GUIManualSwitch(model); + GUIManualSwitch enable = new GUIManualSwitch(model, 1); WireCrossPoint wcp0 = new WireCrossPoint(model, 1); GUINotGate not1 = new GUINotGate(model, 1); GUINotGate not2 = new GUINotGate(model, 1); @@ -71,7 +71,7 @@ public class Am2901Testbench WireCrossPoint wcp = new WireCrossPoint(model, 1); GUIComponent d_ff = IndirectGUIComponentCreator.createComponent(model, "GUIdff"); - GUIManualSwitch sw = new GUIManualSwitch(model); + GUIManualSwitch sw = new GUIManualSwitch(model, 1); tool.connect(last, wcp); tool.connect(wcp, d_ff, "C"); @@ -91,7 +91,7 @@ public class Am2901Testbench { double x = 300 + 75 * (i % 2); double y = 10 * i - 2.5; - GUIBitDisplay bd = new GUIBitDisplay(model); + GUIBitDisplay bd = new GUIBitDisplay(model, 1); bd.moveTo(x, y); tool.connect(bd.getInputPin(), comp, outputPinNames.get(i)); diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java index 7d44f8b5..8985e53f 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestableAm2901Impl.java @@ -117,7 +117,7 @@ public class TestableAm2901Impl implements TestableAm2901 HashMap idSwitchMap = new HashMap<>(); for (String id : inputPinNames) { - GUIManualSwitch sw = new GUIManualSwitch(viewModel); + GUIManualSwitch sw = new GUIManualSwitch(viewModel, 1); new GUIWire(viewModel, am2901.getPin(id), sw.getOutputPin()); idSwitchMap.put(id, sw); } @@ -125,7 +125,7 @@ public class TestableAm2901Impl implements TestableAm2901 HashMap idDisplayMap = new HashMap<>(); for (String id : outputPinNames) { - GUIBitDisplay bd = new GUIBitDisplay(viewModel); + GUIBitDisplay bd = new GUIBitDisplay(viewModel, 1); // bd.addRedrawListener(() -> System.out.println(id + " " + bd.getBitDisplay().getDisplayedValue())); new GUIWire(viewModel, am2901.getPin(id), bd.getInputPin()); idDisplayMap.put(id, bd); @@ -168,53 +168,53 @@ public class TestableAm2901Impl implements TestableAm2901 public void setDest(Am2901_Dest dest) { var bits = of(dest.ordinal(), 3); - I8.setToValueOf(bits.getLSBit(2)); - I7.setToValueOf(bits.getLSBit(1)); - I6.setToValueOf(bits.getLSBit(0)); + I8.setState(bits.getLSBit(2)); + I7.setState(bits.getLSBit(1)); + I6.setState(bits.getLSBit(0)); } @Override public void setFunc(Am2901_Func func) { var bits = of(func.ordinal(), 3); - I5.setToValueOf(bits.getLSBit(2)); - I4.setToValueOf(bits.getLSBit(1)); - I3.setToValueOf(bits.getLSBit(0)); + I5.setState(bits.getLSBit(2)); + I4.setState(bits.getLSBit(1)); + I3.setState(bits.getLSBit(0)); } @Override public void setSrc(Am2901_Src src) { var bits = of(src.ordinal(), 3); - I2.setToValueOf(bits.getLSBit(2)); - I1.setToValueOf(bits.getLSBit(1)); - I0.setToValueOf(bits.getLSBit(0)); + I2.setState(bits.getLSBit(2)); + I1.setState(bits.getLSBit(1)); + I0.setState(bits.getLSBit(0)); } @Override public void setReg_A(String val_4_bit) { var bits = BitVector.parse(val_4_bit); - A3.setToValueOf(bits.getLSBit(3)); - A2.setToValueOf(bits.getLSBit(2)); - A1.setToValueOf(bits.getLSBit(1)); - A0.setToValueOf(bits.getLSBit(0)); + A3.setState(bits.getLSBit(3)); + A2.setState(bits.getLSBit(2)); + A1.setState(bits.getLSBit(1)); + A0.setState(bits.getLSBit(0)); } @Override public void setReg_B(String val_4_bit) { var bits = BitVector.parse(val_4_bit); - B3.setToValueOf(bits.getLSBit(3)); - B2.setToValueOf(bits.getLSBit(2)); - B1.setToValueOf(bits.getLSBit(1)); - B0.setToValueOf(bits.getLSBit(0)); + B3.setState(bits.getLSBit(3)); + B2.setState(bits.getLSBit(2)); + B1.setState(bits.getLSBit(1)); + B0.setState(bits.getLSBit(0)); } @Override public void setCarryIn(String val_1_bit) { - Cn.setToValueOf(Bit.parse(val_1_bit)); + Cn.setState(Bit.parse(val_1_bit)); } @Override @@ -227,40 +227,40 @@ public class TestableAm2901Impl implements TestableAm2901 public void setD(String val_4_bit) { var bits = BitVector.parse(val_4_bit); - D4.setToValueOf(bits.getLSBit(3)); - D3.setToValueOf(bits.getLSBit(2)); - D2.setToValueOf(bits.getLSBit(1)); - D1.setToValueOf(bits.getLSBit(0)); + D4.setState(bits.getLSBit(3)); + D3.setState(bits.getLSBit(2)); + D2.setState(bits.getLSBit(1)); + D1.setState(bits.getLSBit(0)); } @Override public void setQ_0(String val_1_bit) { - IQn.setToValueOf(Bit.parse(val_1_bit)); + IQn.setState(Bit.parse(val_1_bit)); } @Override public void setQ_3(String val_1_bit) { - IQn_3.setToValueOf(Bit.parse(val_1_bit)); + IQn_3.setState(Bit.parse(val_1_bit)); } @Override public void setRAM_0(String val_1_bit) { - IRAMn.setToValueOf(Bit.parse(val_1_bit)); + IRAMn.setState(Bit.parse(val_1_bit)); } @Override public void setRAM_3(String val_1_bit) { - IRAMn_3.setToValueOf(Bit.parse(val_1_bit)); + IRAMn_3.setState(Bit.parse(val_1_bit)); } @Override public void clockOn(boolean isClockOn) { - C.setState(isClockOn); + C.setState(isClockOn ? Bit.ONE : Bit.ZERO); } @Override diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/ClickableSubmodelComponentsTest.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/ClickableSubmodelComponentsTest.java index 4ac98e3f..41212009 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/ClickableSubmodelComponentsTest.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/ClickableSubmodelComponentsTest.java @@ -23,8 +23,8 @@ public class ClickableSubmodelComponentsTest setSubmodelScale(.4); setOutputPins("O0"); - GUIManualSwitch sw = new GUIManualSwitch(submodelModifiable); - GUIBitDisplay bd = new GUIBitDisplay(submodelModifiable); + GUIManualSwitch sw = new GUIManualSwitch(submodelModifiable, 1); + GUIBitDisplay bd = new GUIBitDisplay(submodelModifiable, 1); sw.moveTo(10, 5); bd.moveTo(50, 5); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/RSLatchExample.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/RSLatchExample.java index 005b39ac..58f75550 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/RSLatchExample.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/examples/RSLatchExample.java @@ -19,9 +19,9 @@ public class RSLatchExample @SuppressWarnings("unused") // for GUIWires being created public static void createRSLatchExample(ViewModelModifiable model) { - GUIManualSwitch rIn = new GUIManualSwitch(model); + GUIManualSwitch rIn = new GUIManualSwitch(model, 1); rIn.moveTo(100, 100); - GUIManualSwitch sIn = new GUIManualSwitch(model); + GUIManualSwitch sIn = new GUIManualSwitch(model, 1); sIn.moveTo(100, 200); GUIOrGate or1 = new GUIOrGate(model, 1); diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java index c837fd44..b82d5265 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIBitDisplay.java @@ -28,18 +28,18 @@ public class GUIBitDisplay extends GUIComponent private final LogicObserver logicObs; private BitDisplay bitDisplay; - public GUIBitDisplay(ViewModelModifiable model) + public GUIBitDisplay(ViewModelModifiable model, int logicWidth) { - this(model, null); + this(model, logicWidth, null); } - public GUIBitDisplay(ViewModelModifiable model, String name) + public GUIBitDisplay(ViewModelModifiable model, int logicWidth, String name) { super(model, name); logicObs = (i) -> model.requestRedraw(); setSize(width, height); - addPin(this.inputPin = new Pin(this, "", 1, 0, height / 2)); + addPin(this.inputPin = new Pin(this, "", logicWidth, 0, height / 2)); } @Override @@ -89,6 +89,7 @@ public class GUIBitDisplay extends GUIComponent static { ViewLogicModelAdapter.addComponentAdapter(new BitDisplayAdapter()); - IndirectGUIComponentCreator.setComponentSupplier(GUIBitDisplay.class.getCanonicalName(), (m, p, n) -> new GUIBitDisplay(m, n)); + IndirectGUIComponentCreator.setComponentSupplier(GUIBitDisplay.class.getCanonicalName(), + (m, p, n) -> new GUIBitDisplay(m, p.getAsInt(), n)); } } \ No newline at end of file diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java index 611d3410..1d385162 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/GUIManualSwitch.java @@ -9,7 +9,7 @@ import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.core.LogicObservable; import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.components.ManualSwitch; -import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.core.types.BitVectorFormatter; import net.mograsim.logic.core.wires.Wire.ReadEnd; import net.mograsim.logic.model.model.ViewModelModifiable; @@ -32,18 +32,18 @@ public class GUIManualSwitch extends GUIComponent private ManualSwitch logicSwitch; private ReadEnd end; - public GUIManualSwitch(ViewModelModifiable model) + public GUIManualSwitch(ViewModelModifiable model, int logicWidth) { - this(model, null); + this(model, logicWidth, null); } - public GUIManualSwitch(ViewModelModifiable model, String name) + public GUIManualSwitch(ViewModelModifiable model, int logicWidth, String name) { super(model, name); logicObs = (i) -> model.requestRedraw(); setSize(width, height); - addPin(this.outputPin = new Pin(this, "", 1, width, height / 2)); + addPin(this.outputPin = new Pin(this, "", logicWidth, width, height / 2)); } @Override @@ -88,7 +88,7 @@ public class GUIManualSwitch extends GUIComponent { case "out": if (logicSwitch != null) - return logicSwitch.getValue(); + return logicSwitch.getValues(); return null; default: return super.getHighLevelState(stateID); @@ -102,7 +102,7 @@ public class GUIManualSwitch extends GUIComponent { case "out": if (logicSwitch != null) - logicSwitch.setToValueOf((Bit) newState); + logicSwitch.setState((BitVector) newState); break; default: super.setHighLevelState(stateID, newState); @@ -143,6 +143,7 @@ public class GUIManualSwitch extends GUIComponent static { ViewLogicModelAdapter.addComponentAdapter(new ManualSwitchAdapter()); - IndirectGUIComponentCreator.setComponentSupplier(GUIManualSwitch.class.getName(), (m, p, n) -> new GUIManualSwitch(m, n)); + IndirectGUIComponentCreator.setComponentSupplier(GUIManualSwitch.class.getName(), + (m, p, n) -> new GUIManualSwitch(m, p.getAsInt(), n)); } } \ No newline at end of file diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java index 03cdbb4b..42fada84 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java @@ -41,9 +41,9 @@ public class SimulationPreview implements IThemePreview params.gateProcessTime = 50; params.wireTravelTime = 10; - GUIManualSwitch rIn = new GUIManualSwitch(model); + GUIManualSwitch rIn = new GUIManualSwitch(model, 1); rIn.moveTo(10, 10); - GUIManualSwitch sIn = new GUIManualSwitch(model); + GUIManualSwitch sIn = new GUIManualSwitch(model, 1); sIn.moveTo(10, 70); GUIOrGate or1 = new GUIOrGate(model, 1); diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java index 26d95cf7..00b19566 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java @@ -100,13 +100,13 @@ public class LogicUIPart extends ViewPart comp.moveTo(100, 0); for (int i = 0; i < inputPinNames.size(); i++) { - GUIManualSwitch sw = new GUIManualSwitch(model); + GUIManualSwitch sw = new GUIManualSwitch(model, 1); sw.moveTo(0, 20 * i); new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin()); } for (int i = 0; i < outputPinNames.size(); i++) { - GUIBitDisplay bd = new GUIBitDisplay(model); + GUIBitDisplay bd = new GUIBitDisplay(model, 1); bd.moveTo(200, 20 * i); new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin()); }