1 package era.mi.logic.components;
3 import java.util.Arrays;
4 import java.util.Collections;
7 import era.mi.logic.Bit;
8 import era.mi.logic.Simulation;
9 import era.mi.logic.timeline.TimelineEvent;
10 import era.mi.logic.timeline.TimelineEventHandler;
11 import era.mi.logic.wires.WireArray;
12 import era.mi.logic.wires.WireArray.WireArrayInput;
14 public class Clock implements TimelineEventHandler, Component
16 private boolean toggle = false;
17 private WireArrayInput outI;
22 * @param out {@link WireArray} the clock's impulses are fed into
23 * @param delta ticks between rising and falling edge
25 public Clock(WireArray out, int delta)
28 this.outI = out.createInput();
29 Simulation.TIMELINE.addEvent(this, 50);
33 public void handle(TimelineEvent e)
36 outI.feedSignals(new Bit[] { toggle ? Bit.ONE : Bit.ZERO });
40 public WireArray getOut()
45 private void addToTimeline()
47 Simulation.TIMELINE.addEvent(this, delta);
51 public List<WireArray> getAllInputs()
53 return Collections.unmodifiableList(Arrays.asList());
57 public List<WireArray> getAllOutputs()
59 return Collections.unmodifiableList(Arrays.asList(outI.owner));