Reformatted everything. Eclipse built-in Linewrapping/Comments 140 chars
[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         private final WireArray a;
11 //      private final WireArray b;
12         private final WireArrayInput aI;
13         private final WireArrayInput bI;
14
15         public Connector(WireArray a, WireArray b) {
16                 if (a.length != b.length)
17                         throw new IllegalArgumentException(String.format("WireArray width does not match: %d, %d", a.length, b.length));
18                 this.a = a;
19 //              this.b = b;
20                 a.addObserver(this);
21                 b.addObserver(this);
22                 aI = a.createInput();
23                 bI = b.createInput();
24         }
25
26         @Override
27         public void update(WireArray initiator, Bit[] oldValues) {
28                 Simulation.TIMELINE.addEvent((e) -> {
29                         if (initiator == a)
30                                 bI.feedSignals(aI.wireValuesExcludingMe());
31                         else
32                                 aI.feedSignals(bI.wireValuesExcludingMe());
33                 }, 1);
34         }
35 }