Removed unused import
[Mograsim.git] / era.mi / src / era / mi / logic / tests / Connector.java
1 package era.mi.logic.tests;
2
3 import era.mi.logic.Bit;
4 import era.mi.logic.Simulation;
5 import era.mi.logic.wires.WireArray;
6 import era.mi.logic.wires.WireArray.WireArrayInput;
7 import era.mi.logic.wires.WireArrayObserver;
8
9 public class Connector implements WireArrayObserver
10 {
11         private final WireArray a;
12 //      private final WireArray b;
13         private final WireArrayInput aI;
14         private final WireArrayInput bI;
15
16         public Connector(WireArray a, WireArray b)
17         {
18                 if (a.length != b.length)
19                         throw new IllegalArgumentException(String.format("WireArray width does not match: %d, %d", a.length, b.length));
20                 this.a = a;
21 //              this.b = b;
22                 a.addObserver(this);
23                 b.addObserver(this);
24                 aI = a.createInput();
25                 bI = b.createInput();
26         }
27
28         @Override
29         public void update(WireArray initiator, Bit[] oldValues)
30         {
31                 Simulation.TIMELINE.addEvent((e) ->
32                 {
33                         if (initiator == a)
34                                 bI.feedSignals(aI.wireValuesExcludingMe());
35                         else
36                                 aI.feedSignals(bI.wireValuesExcludingMe());
37                 }, 1);
38         }
39 }