X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FClock.java;fp=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FClock.java;h=0000000000000000000000000000000000000000;hb=0a04a4ed66ecebd4254541c4977599f6052c115a;hp=b691d7e7183608b75b456615c5347f619de8bead;hpb=9b4850366c29fbd800ee8df1858c398d8c35a0c0;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/Clock.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/Clock.java deleted file mode 100644 index b691d7e7..00000000 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/Clock.java +++ /dev/null @@ -1,91 +0,0 @@ -package net.mograsim.logic.core.components; - -import java.util.Collection; -import java.util.HashSet; -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.TimelineEvent; -import net.mograsim.logic.core.timeline.TimelineEventHandler; -import net.mograsim.logic.core.types.Bit; -import net.mograsim.logic.core.wires.Wire; -import net.mograsim.logic.core.wires.Wire.ReadEnd; -import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; - -public class Clock extends Component implements TimelineEventHandler, LogicObservable -{ - private Collection observers; - private boolean toggle = false; - private ReadWriteEnd out; - private int delta; - - /** - * - * @param out {@link Wire} the clock's impulses are fed into - * @param delta ticks between rising and falling edge - */ - public Clock(Timeline timeline, ReadWriteEnd out, int delta) - { - super(timeline); - this.delta = delta; - this.out = out; - this.observers = new HashSet<>(); - addToTimeline(); - } - - @Override - public void handle(TimelineEvent e) - { - addToTimeline(); - out.feedSignals(toggle ? Bit.ONE : Bit.ZERO); - toggle = !toggle; - notifyObservers(); - } - - public ReadWriteEnd getOut() - { - return out; - } - - public boolean isOn() - { - return !toggle; - } - - private void addToTimeline() - { - timeline.addEvent(this, delta); - } - - @Override - public List getAllInputs() - { - return List.of(); - } - - @Override - public List getAllOutputs() - { - return List.of(out); - } - - @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)); - } -}