X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FCoreBitDisplay.java;fp=plugins%2Fnet.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FCoreBitDisplay.java;h=345bc0ab091ef9a353c5a2f0b1e050e203f33acf;hb=7d05144c25daa53e60fc9ed9fd503546a86567f8;hp=0000000000000000000000000000000000000000;hpb=8bed58cd47f4e53a0a83e066d38864aa6875502f;p=Mograsim.git diff --git a/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreBitDisplay.java b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreBitDisplay.java new file mode 100644 index 00000000..345bc0ab --- /dev/null +++ b/plugins/net.mograsim.logic.core/src/net/mograsim/logic/core/components/CoreBitDisplay.java @@ -0,0 +1,81 @@ +package net.mograsim.logic.core.components; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import net.mograsim.logic.core.LogicObservable; +import net.mograsim.logic.core.LogicObserver; +import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.core.timeline.TimelineEventHandler; +import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.types.BitVector; +import net.mograsim.logic.core.wires.CoreWire.ReadEnd; +import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd; + +public class CoreBitDisplay extends BasicCoreComponent implements LogicObservable +{ + private Collection observers; + private final ReadEnd in; + private BitVector displayedValue; + + public CoreBitDisplay(Timeline timeline, ReadEnd in) + { + super(timeline, 1); + observers = new ArrayList<>(); + this.in = in; + in.registerObserver(this); + compute(); + } + + @Override + protected TimelineEventHandler compute() + { + BitVector newValues = in.getValues(); + return e -> + { + displayedValue = newValues; + notifyObservers(); + }; + } + + public BitVector getDisplayedValue() + { + return displayedValue; + } + + public boolean isDisplaying(Bit... values) + { + return displayedValue.equals(BitVector.of(values)); + } + + @Override + public List getAllInputs() + { + return List.of(in); + } + + @Override + public List getAllOutputs() + { + return List.of(); + } + + @Override + public void registerObserver(LogicObserver ob) + { + observers.add(ob); + } + + @Override + public void deregisterObserver(LogicObserver ob) + { + observers.remove(ob); + } + + @Override + public void notifyObservers() + { + observers.forEach(ob -> ob.update(this)); + } +}