268d1572403d13bd9e98d66c7025a895aee71980
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / BitDisplay.java
1 package net.mograsim.logic.core.components;
2
3 import java.util.List;
4
5 import net.mograsim.logic.core.timeline.Timeline;
6 import net.mograsim.logic.core.types.Bit;
7 import net.mograsim.logic.core.types.BitVector;
8 import net.mograsim.logic.core.wires.Wire.ReadEnd;
9 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
10
11 public class BitDisplay extends BasicComponent
12 {
13         private final ReadEnd in;
14         private BitVector displayedValue;
15
16         public BitDisplay(Timeline timeline, ReadEnd in)
17         {
18                 super(timeline, 1);
19                 this.in = in;
20                 in.addObserver(this);
21                 compute();
22         }
23
24         @Override
25         protected void compute()
26         {
27                 displayedValue = in.getValues();
28         }
29
30         public BitVector getDisplayedValue()
31         {
32                 return displayedValue;
33         }
34
35         public boolean isDisplaying(Bit... values)
36         {
37                 return displayedValue.equals(BitVector.of(values));
38         }
39
40         @Override
41         public List<ReadEnd> getAllInputs()
42         {
43                 return List.of(in);
44         }
45
46         @Override
47         public List<ReadWriteEnd> getAllOutputs()
48         {
49                 return List.of();
50         }
51 }