bin deleted and ignored.
[Mograsim.git] / era.mi / src / era / mi / logic / components / TriState.java
1 package era.mi.logic.components;
2
3 import era.mi.logic.Bit;
4 import era.mi.logic.wires.WireArray;
5 import era.mi.logic.wires.WireArray.WireArrayInput;
6
7 public class TriState extends BasicComponent{
8         WireArray in, enable;
9         WireArrayInput outI;
10         
11         public TriState(int processTime, WireArray in, WireArray out, WireArray enable) {
12                 super(processTime);
13                 if(in.length != out.length)
14                         throw new IllegalArgumentException("Tri-state output must have the same amount of bits as the input. Input: " + in.length + " Output: " + out.length);
15                 if(enable.length != 1)
16                         throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length + ".");
17                 this.in = in;
18                 in.addObserver(this);
19                 this.enable = enable;
20                 enable.addObserver(this);
21                 outI = out.createInput();
22         }
23         
24         @Override
25         protected void compute()
26         {
27                 if(enable.getValue() == Bit.ONE)
28                         outI.feedSignals(in.getValues());
29                 else
30                         outI.clearSignals();
31         }
32
33 }