1 package era.mi.logic.components;
3 import era.mi.logic.Bit;
4 import era.mi.logic.wires.WireArray;
5 import era.mi.logic.wires.WireArray.WireArrayInput;
6 import era.mi.logic.wires.WireArrayObserver;
8 public class Splitter implements WireArrayObserver
10 private WireArray input;
11 private WireArrayInput[] outputs;
13 public Splitter(WireArray input, WireArray... outputs)
16 this.outputs = WireArray.extractInputs(outputs);
17 input.addObserver(this);
19 for(WireArray out : outputs)
22 if(input.length != length)
23 throw new IllegalArgumentException("The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length().");
26 protected void compute()
29 Bit[] inputBits = input.getValues();
30 for(int i = 0; i < outputs.length; i++)
32 Bit[] outputBits = new Bit[outputs[i].owner.length];
33 System.arraycopy(inputBits, startIndex, outputBits, 0, outputs[i].owner.length);
34 outputs[i].feedSignals(outputBits);
35 startIndex += outputs[i].owner.length;
40 public void update(WireArray initiator, Bit[] oldValues)