Fixed a bug in Am2900; created dlatch8/80; relayouted some components
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / BasicCoreComponent.java
1 package net.mograsim.logic.core.components;
2
3 import net.mograsim.logic.core.LogicObservable;
4 import net.mograsim.logic.core.LogicObserver;
5 import net.mograsim.logic.core.timeline.Timeline;
6 import net.mograsim.logic.core.timeline.TimelineEventHandler;
7
8 /**
9  * A basic component that recomputes all outputs (with a delay), when it is updated.
10  * 
11  * @author Fabian Stemmler
12  */
13 public abstract class BasicCoreComponent extends CoreComponent implements LogicObserver
14 {
15         private int processTime;
16
17         /**
18          * 
19          * @param processTime Amount of time this component takes to update its outputs. Must be more than 0, otherwise 1 is assumed.
20          * 
21          * @author Fabian Stemmler
22          */
23         public BasicCoreComponent(Timeline timeline, int processTime)
24         {
25                 super(timeline);
26                 this.processTime = processTime > 0 ? processTime : 1;
27         }
28
29         @Override
30         public final void update(LogicObservable initiator)
31         {
32                 update();
33         }
34
35         public void update()
36         {
37                 TimelineEventHandler delayedUpdates = compute();
38                 if (delayedUpdates != null)
39                         timeline.addEvent(delayedUpdates, processTime);
40         }
41
42         protected abstract TimelineEventHandler compute();
43 }