X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FManualSwitch.java;h=e5cdf1be639bdd839c0e2b4ee91f030629833d1e;hb=6345e8d7c88792fb1f92eb490e43b0decc15bf0f;hp=7f4f2659f9dcab1ffd6d4aaba24d4055ebf318ce;hpb=c9e5a301f6925386a62e77a84ba4d9b1b6f43aae;p=Mograsim.git 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 7f4f2659..e5cdf1be 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