X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FCoreTriStateBuffer.java;fp=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FCoreTriStateBuffer.java;h=6568d1bfe13c897e6345ea8a9da1ec94540d1fcf;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=0000000000000000000000000000000000000000;hpb=9b4850366c29fbd800ee8df1858c398d8c35a0c0;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreTriStateBuffer.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreTriStateBuffer.java new file mode 100644 index 00000000..6568d1bf --- /dev/null +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreTriStateBuffer.java @@ -0,0 +1,51 @@ +package net.mograsim.logic.core.components; + +import java.util.List; + +import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.wires.CoreWire.ReadEnd; +import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd; + +public class CoreTriStateBuffer extends BasicCoreComponent +{ + ReadEnd in, enable; + ReadWriteEnd out; + + public CoreTriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable) + { + super(timeline, processTime); + if (in.width() != out.width()) + throw new IllegalArgumentException( + "Tri-state output must have the same amount of bits as the input. Input: " + in.width() + " Output: " + out.width()); + if (enable.width() != 1) + throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.width() + "."); + this.in = in; + in.registerObserver(this); + this.enable = enable; + enable.registerObserver(this); + this.out = out; + } + + @Override + protected void compute() + { + if (enable.getValue() == Bit.ONE) + out.feedSignals(in.getValues()); + else + out.clearSignals(); + } + + @Override + public List getAllInputs() + { + return List.of(in, enable); + } + + @Override + public List getAllOutputs() + { + return List.of(out); + } + +}