X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fwires%2FWire.java;h=db932536f8293df625e9322bda99c7100ef41b73;hb=2427bceeaf96fefbd92ea04d7ebbb52606a7b2ff;hp=d85fc206ce65ff33214081ac5231d161472983e2;hpb=7c7b279981f4686d4fe165cf327ff5b52d71c5f6;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..db932536 100644 --- a/era.mi/src/era/mi/logic/wires/Wire.java +++ b/era.mi/src/era/mi/logic/wires/Wire.java @@ -5,9 +5,9 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; -import era.mi.logic.Bit; import era.mi.logic.Simulation; import era.mi.logic.Util; +import era.mi.logic.types.Bit; /** * Represents an array of wires that can store n bits of information. @@ -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].join(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;