X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fwires%2FWire.java;h=1b26a15d0ae5c379c4c60e5b73c00350667b7856;hb=2ccdd5a2ed812bc4eb864ab4fbb1adb1c723a1c9;hp=d85fc206ce65ff33214081ac5231d161472983e2;hpb=b1e7855af2dfc15b4d6c1253dd77db02925162f3;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/wires/Wire.java b/era.mi/src/era/mi/logic/wires/Wire.java index d85fc206..1b26a15d 100644 --- a/era.mi/src/era/mi/logic/wires/Wire.java +++ b/era.mi/src/era/mi/logic/wires/Wire.java @@ -60,12 +60,7 @@ public class Wire Bit[] bits = input.getInputValues(); for (int i = 0; i < length; i++) { - if (Bit.Z.equals(bits[i]) || newValues[i].equals(bits[i])) - continue; - else if (Bit.Z.equals(newValues[i])) - newValues[i] = bits[i]; - else - newValues[i] = Bit.X; + newValues[i] = newValues[i].combineWith(bits[i]); } } @@ -205,7 +200,15 @@ public class Wire */ public WireEnd createEnd() { - return new WireEnd(); + return new WireEnd(false); + } + + /** + * Create a {@link WireEnd} object, which is tied to this {@link Wire}. This {@link WireEnd} cannot written to. + */ + public WireEnd createReadOnlyEnd() + { + return new WireEnd(true); } private void registerInput(WireEnd toRegister) @@ -225,17 +228,18 @@ public class Wire private boolean open; private Bit[] inputValues; - private WireEnd() + private WireEnd(boolean readOnly) { super(); open = true; initValues(); - registerInput(this); + if (!readOnly) + registerInput(this); } private void initValues() { - inputValues = Bit.Z.makeArray(length); + inputValues = Bit.U.makeArray(length); } /** @@ -247,12 +251,10 @@ public class Wire */ public void feedSignals(Bit... newValues) { - if (newValues.length == length) - { - feedSignals(0, newValues); - } else + if (newValues.length != length) throw new IllegalArgumentException( String.format("Attempted to input %d bits instead of %d bits.", newValues.length, length)); + feedSignals(0, newValues); } /** @@ -422,11 +424,11 @@ public class Wire @Override public String toString() { - return Arrays.toString(values); + return Arrays.toString(inputValues); // return String.format("%s \nFeeding: %s", WireArray.this.toString(), Arrays.toString(inputValues)); } - public void disconnect() + public void close() { inputs.remove(this); open = false;