1 package net.mograsim.machine.mi.components;
5 import net.mograsim.logic.core.components.BasicCoreComponent;
6 import net.mograsim.logic.core.timeline.Timeline;
7 import net.mograsim.logic.core.timeline.TimelineEventHandler;
8 import net.mograsim.logic.core.types.Bit;
9 import net.mograsim.logic.core.types.BitVector;
10 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
11 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
12 import net.mograsim.machine.mi.MicroInstructionMemory;
14 public class CoreMicroInstructionMemory extends BasicCoreComponent
16 private final ReadWriteEnd data;
17 private final ReadEnd address;
18 private final MicroInstructionMemory memory;
20 public CoreMicroInstructionMemory(Timeline timeline, int processTime, MicroInstructionMemory memory, ReadWriteEnd data, ReadEnd address)
22 super(timeline, processTime);
25 this.address = address;
26 memory.registerObserver(a -> update());
27 address.registerObserver(this);
30 public MicroInstructionMemory getMemory()
36 public List<ReadEnd> getAllInputs()
38 return List.of(address);
42 public List<ReadWriteEnd> getAllOutputs()
48 protected TimelineEventHandler compute()
50 if (!address.getValues().isBinary())
52 return e -> data.feedSignals(Bit.U.toVector(data.width()));// TODO don't always feed U, but decide to feed X or U.
54 long addressed = address.getValues().getUnsignedValueLong();
55 BitVector storedData = memory.getCell(addressed).toBitVector();
56 return e -> data.feedSignals(storedData);