Added era.mi; Project containing provisional simulator core
[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.WireArray;
6 import era.mi.logic.timeline.TimelineEvent;
7 import era.mi.logic.timeline.TimelineEventHandler;
8
9 public class Clock implements TimelineEventHandler
10 {
11         private boolean toggle = false;
12         private WireArray w;
13         
14         public Clock(WireArray w)
15         {
16                 this.w = w;
17         }
18
19         @Override
20         public void handle(TimelineEvent e)
21         {
22                 Simulation.TIMELINE.addEvent(this, 50);
23                 w.feedSignals(new Bit[] { toggle ? Bit.ONE : Bit.ZERO });
24                 toggle = !toggle;
25         }
26
27         public WireArray getW()
28         {
29                 return w;
30         }
31 }