1 package net.mograsim.logic.core.components;
\r
3 import java.util.List;
\r
5 import net.mograsim.logic.core.timeline.Timeline;
\r
6 import net.mograsim.logic.core.types.Bit;
\r
7 import net.mograsim.logic.core.wires.Wire.ReadEnd;
\r
8 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
\r
10 public class TriStateBuffer extends BasicComponent
\r
15 public TriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable)
\r
17 super(timeline, processTime);
\r
18 if (in.length() != out.length())
\r
19 throw new IllegalArgumentException(
\r
20 "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length());
\r
21 if (enable.length() != 1)
\r
22 throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length() + ".");
\r
24 in.registerObserver(this);
\r
25 this.enable = enable;
\r
26 enable.registerObserver(this);
\r
31 protected void compute()
\r
33 if (enable.getValue() == Bit.ONE)
\r
34 out.feedSignals(in.getValues());
\r
40 public List<ReadEnd> getAllInputs()
\r
42 return List.of(in, enable);
\r
46 public List<ReadWriteEnd> getAllOutputs()
\r
48 return List.of(out);
\r