X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fmi%2Fcomponents%2FCoreMicroInstructionMemory.java;fp=net.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fmi%2Fcomponents%2FCoreMicroInstructionMemory.java;h=29793c5c3bb159958a0cfe225ea996282f162004;hb=7b8035a065c7b64f38850907d519f9a7dfb67e24;hp=0000000000000000000000000000000000000000;hpb=d09827f6dc03fa3cded8e996b4ce45fdae3755ca;p=Mograsim.git diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java b/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java new file mode 100644 index 00000000..29793c5c --- /dev/null +++ b/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java @@ -0,0 +1,61 @@ +package net.mograsim.machine.mi.components; + +import java.util.List; + +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.mi.MicroInstructionMemory; + +public class CoreMicroInstructionMemory extends BasicCoreComponent +{ + private final ReadWriteEnd data; + private final ReadEnd address, clock; + private final MicroInstructionMemory memory; + + + public CoreMicroInstructionMemory(Timeline timeline, int processTime, MicroInstructionMemory memory, ReadWriteEnd data, ReadEnd address, ReadEnd clock) + { + super(timeline, processTime); + this.memory = memory; + this.data = data; + this.address = address; + this.clock = clock; + } + + public MicroInstructionMemory getMemory() + { + return memory; + } + + @Override + public List getAllInputs() + { + return List.of(address, clock); + } + + @Override + public List getAllOutputs() + { + return List.of(data); + } + + @Override + protected TimelineEventHandler compute() + { + if(clock.getValue() != Bit.ONE) + return null; + + if (!address.hasNumericValue()) + { + return e -> data.feedSignals(Bit.U.toVector(data.width())); + } + long addressed = address.getUnsignedValue(); + BitVector storedData = memory.getCell(addressed).toBitVector(); + return e -> data.feedSignals(storedData); + } +}