Merge branch 'wire_array_inputs_update'
[Mograsim.git] / era.mi / src / era / mi / logic / components / Clock.java
1 package era.mi.logic.components;
2
3 import era.mi.logic.Bit;
4 import era.mi.logic.Simulation;
5 import era.mi.logic.timeline.TimelineEvent;
6 import era.mi.logic.timeline.TimelineEventHandler;
7 import era.mi.logic.wires.WireArray;
8 import era.mi.logic.wires.WireArray.WireArrayInput;
9
10 public class Clock implements TimelineEventHandler
11 {
12         private boolean toggle = false;
13         private WireArrayInput outI;
14         
15         public Clock(WireArray out)
16         {
17                 this.outI = out.createInput();
18         }
19
20         @Override
21         public void handle(TimelineEvent e)
22         {
23                 Simulation.TIMELINE.addEvent(this, 50);
24                 outI.feedSignals(new Bit[] { toggle ? Bit.ONE : Bit.ZERO });
25                 toggle = !toggle;
26         }
27
28         public WireArray getOut()
29         {
30                 return outI.owner;
31         }
32 }