X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FTriStateBuffer.java;h=1f8f85a5c4d56051a18d393a9b9e9a67a28192d4;hb=ecc651406020231ff0ebc8d1bfc6f916693f69c6;hp=f4f1b4913f467f0aa0bf8d758033a4af8244b6e8;hpb=67c1d352795802dae0c045cedeed82c883819d4e;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/TriStateBuffer.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/TriStateBuffer.java index f4f1b491..1f8f85a5 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/TriStateBuffer.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/TriStateBuffer.java @@ -1,51 +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.Wire.ReadEnd; -import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; - -public class TriStateBuffer extends BasicComponent -{ - ReadEnd in, enable; - ReadWriteEnd out; - - public TriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable) - { - super(timeline, processTime); - if (in.length() != out.length()) - throw new IllegalArgumentException( - "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length()); - if (enable.length() != 1) - throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length() + "."); - this.in = in; - in.addObserver(this); - this.enable = enable; - enable.addObserver(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); - } - -} +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.Wire.ReadEnd; +import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; + +public class TriStateBuffer extends BasicComponent +{ + ReadEnd in, enable; + ReadWriteEnd out; + + public TriStateBuffer(Timeline timeline, int processTime, ReadEnd in, ReadWriteEnd out, ReadEnd enable) + { + super(timeline, processTime); + if (in.length() != out.length()) + throw new IllegalArgumentException( + "Tri-state output must have the same amount of bits as the input. Input: " + in.length() + " Output: " + out.length()); + if (enable.length() != 1) + throw new IllegalArgumentException("Tri-state enable must have exactly one bit, not " + enable.length() + "."); + 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); + } + +}