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.TimelineEventHandler;
/**
* A basic component that recomputes all outputs (with a delay), when it is updated.
}
@Override
- public void update(LogicObservable initiator)
+ public final void update(LogicObservable initiator)
{
- timeline.addEvent(e -> compute(), processTime);
+ TimelineEventHandler delayedUpdates = compute();
+ if (delayedUpdates != null)
+ timeline.addEvent(delayedUpdates, processTime);
}
- protected abstract void compute();
+ protected abstract TimelineEventHandler compute();
}
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.TimelineEventHandler;
import net.mograsim.logic.core.types.Bit;
import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
}
@Override
- protected void compute()
+ protected TimelineEventHandler compute()
{
- displayedValue = in.getValues();
- notifyObservers();
+ BitVector newValues = in.getValues();
+ return e ->
+ {
+ displayedValue = newValues;
+ notifyObservers();
+ };
}
public BitVector getDisplayedValue()
import java.util.List;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.CoreWire;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
}
@Override
- public void compute()
+ public TimelineEventHandler compute()
{
int selectValue = select.hasNumericValue() ? (int) select.getUnsignedValue() : -1;
if (selectValue >= outputs.length)
selectValue = -1;
- if (selected != selectValue && selected != -1)
- outputs[selected].clearSignals();
+ boolean hasOldSelection = selected != selectValue && selected != -1;
+ int oldSelection = selected;
+ boolean hasNewSelection = selectValue != -1;
+ int newSelection = selectValue;
+ BitVector inputValues = in.getValues();
selected = selectValue;
- if (selectValue != -1)
- outputs[selectValue].feedSignals(in.getValues());
+ return e ->
+ {
+ if (hasOldSelection)
+ outputs[oldSelection].clearSignals();
+ if (hasNewSelection)
+ outputs[newSelection].feedSignals(inputValues);
+ };
}
@Override
import java.util.List;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.CoreWire;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
}
@Override
- public void compute()
+ public TimelineEventHandler compute()
{
int selectValue;
if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length)
{
- out.clearSignals();
- return;
+ return e -> out.clearSignals();
}
- ReadEnd active = inputs[selectValue];
- out.feedSignals(active.getValues());
+ BitVector activeValues = inputs[selectValue].getValues();
+ return e -> out.feedSignals(activeValues);
}
@Override
import java.util.List;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
}
@Override
- protected void compute()
+ protected TimelineEventHandler compute()
{
if (enable.getValue() == Bit.ONE)
- out.feedSignals(in.getValues());
- else
- out.clearSignals();
+ {
+ BitVector inValues = in.getValues();
+ return e -> out.feedSignals(inValues);
+ }
+ return e -> out.clearSignals();
}
@Override
import net.mograsim.logic.core.components.BasicCoreComponent;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
}
@Override
- protected void compute()
+ protected TimelineEventHandler compute()
{
- out.feedSignals(in.getValues().not());
+ BitVector values = in.getValues().not();
+ return e -> out.feedSignals(values);
}
public ReadEnd getIn()
import net.mograsim.logic.core.components.BasicCoreComponent;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
import net.mograsim.logic.core.types.MutationOperation;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
}
@Override
- protected void compute()
+ public TimelineEventHandler compute()
{
BitVectorMutator mutator = BitVectorMutator.empty();
for (ReadEnd w : in)
op.apply(mutator, w.getValues());
- out.feedSignals(invert ? mutator.toBitVector().not() : mutator.toBitVector());
+ return e -> out.feedSignals(invert ? mutator.toBitVector().not() : mutator.toBitVector());
}
}
import net.mograsim.logic.core.components.CoreBitDisplay;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
import net.mograsim.logic.core.types.Bit;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
}
@Override
- protected void compute()
+ protected TimelineEventHandler compute()
{
- super.compute();
- System.out.println("update: value is " + getDisplayedValue());
+ TimelineEventHandler handler = super.compute();
+ return e ->
+ {
+ handler.handle(e);
+ System.out.println("update: value is " + getDisplayedValue());
+ };
}
}
import net.mograsim.logic.core.components.BasicCoreComponent;
import net.mograsim.logic.core.timeline.Timeline;
+import net.mograsim.logic.core.timeline.TimelineEventHandler;
import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.types.BitVector;
import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
import net.mograsim.machine.MainMemoryDefinition;
}
@Override
- protected void compute()
+ protected TimelineEventHandler compute()
{
if (!address.hasNumericValue())
{
if (read.equals(rWBit.getValue()))
- data.feedSignals(Bit.U.toVector(data.width()));
- else
- data.clearSignals();
- return;
+ return e -> data.feedSignals(Bit.U.toVector(data.width()));
+ return e -> data.clearSignals();
}
long addressed = address.getUnsignedValue();
if (read.equals(rWBit.getValue()))
- data.feedSignals(memory.getCell(addressed));
+ {
+ BitVector storedData = memory.getCell(addressed);
+ return e -> data.feedSignals(storedData);
+ }
else
{
- data.clearSignals();
- memory.setCell(addressed, data.getValues());
+ BitVector transData = data.getValues();
+ return e ->
+ {
+ data.clearSignals();
+ memory.setCell(addressed, transData);
+ };
}
}