1 package era.mi.logic.components.gates;
5 import era.mi.logic.Bit;
6 import era.mi.logic.components.BasicComponent;
7 import era.mi.logic.wires.WireArray;
8 import era.mi.logic.wires.WireArray.WireArrayEnd;
10 public abstract class MultiInputGate extends BasicComponent
12 protected WireArray[] in;
13 protected WireArray out;
14 protected WireArrayEnd outI;
15 protected final int length;
16 protected Operation op;
18 protected MultiInputGate(int processTime, Operation op, WireArray out, WireArray... in)
25 throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length));
26 for (WireArray w : in)
28 if (w.length != length)
29 throw new IllegalArgumentException("All wires connected to the gate must be of uniform length.");
33 outI = out.createInput();
37 public List<WireArray> getAllInputs()
43 public List<WireArray> getAllOutputs()
49 protected void compute()
51 Bit[] result = in[0].getValues();
52 for (int i = 1; i < in.length; i++)
53 result = op.execute(result, in[i].getValues());
54 outI.feedSignals(result);
57 protected interface Operation
59 public Bit[] execute(Bit[] a, Bit[] b);