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