X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fmi%2Fcomponents%2FCoreMicroInstructionMemory.java;h=b01802c0367186c341449906e38ecf8d75e91809;hb=76c2b3eab6cec47490bb75713356152deb5d07ed;hp=739402803fbf4420583034761bb77635296fa512;hpb=7d05144c25daa53e60fc9ed9fd503546a86567f8;p=Mograsim.git diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java index 73940280..b01802c0 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/CoreMicroInstructionMemory.java @@ -9,24 +9,50 @@ 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.Memory.MemoryCellModifiedListener; import net.mograsim.machine.mi.MicroInstructionMemory; +import net.mograsim.machine.mi.MicroInstructionMemoryDefinition; public class CoreMicroInstructionMemory extends BasicCoreComponent { private final ReadWriteEnd data; private final ReadEnd address; - private final MicroInstructionMemory memory; + private final MicroInstructionMemoryDefinition definition; + private final MemoryCellModifiedListener memObs; + private MicroInstructionMemory memory; - public CoreMicroInstructionMemory(Timeline timeline, int processTime, MicroInstructionMemory memory, ReadWriteEnd data, ReadEnd address) + public CoreMicroInstructionMemory(Timeline timeline, int processTime, MicroInstructionMemoryDefinition definition, ReadWriteEnd data, + ReadEnd address) { super(timeline, processTime); - this.memory = memory; + if (data.width() != definition.getMicroInstructionDefinition().sizeInBits()) + throw new IllegalArgumentException( + String.format("Bit width of data wire does not match microinstruction memory definition. Expected: %d Actual: %d", + definition.getMicroInstructionDefinition().sizeInBits(), data.width())); + if (address.width() != definition.getMemoryAddressBits()) + throw new IllegalArgumentException( + String.format("Bit width of address wire does not match microinstruction memory definition. Expected: %d Actual: %d", + definition.getMemoryAddressBits(), address.width())); + this.data = data; this.address = address; - memory.registerObserver(a -> update()); + this.definition = definition; + this.memObs = a -> update(); address.registerObserver(this); } + public void setMemory(MicroInstructionMemory memory) + { + if (memory != null && !memory.getDefinition().equals(definition)) + throw new IllegalArgumentException("Memory of incorrect memory definition given"); + if (this.memory != null) + this.memory.registerCellModifiedListener(memObs); + this.memory = memory; + if (memory != null) + memory.registerCellModifiedListener(memObs); + update(); + } + public MicroInstructionMemory getMemory() { return memory; @@ -47,12 +73,11 @@ public class CoreMicroInstructionMemory extends BasicCoreComponent @Override protected TimelineEventHandler compute() { - if (!address.getValues().isBinary()) - { + if (memory == null || !address.getValues().isBinary()) return e -> data.feedSignals(Bit.U.toVector(data.width()));// TODO don't always feed U, but decide to feed X or U. - } long addressed = address.getValues().getUnsignedValueLong(); BitVector storedData = memory.getCell(addressed).toBitVector(); + memory.setActiveInstruction(addressed); return e -> data.feedSignals(storedData); } -} +} \ No newline at end of file