--- /dev/null
- protected void compute()
+package net.mograsim.machine.standard.memory;
+
+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.MainMemoryDefinition;
+
+/**
+ * A memory component that only allows access to words of a specific width
+ */
+public class CoreWordAddressableMemory extends BasicCoreComponent
+{
+ private final WordAddressableMemory memory;
+ private final static Bit read = Bit.ONE;
+
+ private ReadWriteEnd data;
+ private ReadEnd rWBit, address, clock;
+
+ /**
+ * @param data The bits of this ReadEnd are the value that is written to/read from memory; The bit width of this wire is the width of
+ * a memory word
+ * @param rWBit The value of the 0th bit dictates the mode: 0: Write, 1: Read
+ * @param address The bits of this ReadEnd address the memory cell to read/write
+ */
+ public CoreWordAddressableMemory(Timeline timeline, int processTime, MainMemoryDefinition definition, ReadWriteEnd data,
+ ReadEnd rWBit, ReadEnd address, ReadEnd clock)
+ {
+ super(timeline, processTime);
+ if(data.width() != definition.getCellWidth())
+ throw new IllegalArgumentException(String.format("Bit width of data wire does not match main memory definition. Expected: %d Actual: %d", definition.getCellWidth(), data.width()));
+ if(rWBit.width() != 1)
+ throw new IllegalArgumentException(String.format("Bit width of read/write mode select wire is unexpected. Expected: 1 Actual: %d", rWBit.width()));
+ if(address.width() != definition.getMemoryAddressBits())
+ throw new IllegalArgumentException(String.format("Bit width of address wire does not match main memory definition. Expected: %d Actual: %d", definition.getMemoryAddressBits(), address.width()));
+ this.data = data;
+ this.rWBit = rWBit;
+ this.address = address;
+ this.clock = clock;
+ data.registerObserver(this);
+ rWBit.registerObserver(this);
+ address.registerObserver(this);
+ clock.registerObserver(this);
+
+ memory = new WordAddressableMemory(definition);
+ }
+
+ @Override
- return;
++ protected TimelineEventHandler compute()
+ {
+ if(clock.getValue() != Bit.ONE)
- data.feedSignals(Bit.U.toVector(data.width()));
- else
- data.clearSignals();
- return;
++ return null;
++
+ if (!address.hasNumericValue())
+ {
+ if (read.equals(rWBit.getValue()))
- data.feedSignals(memory.getCell(addressed));
++ return e -> data.feedSignals(Bit.U.toVector(data.width()));
++ return e -> data.clearSignals();
+ }
+ long addressed = address.getUnsignedValue();
+ if (read.equals(rWBit.getValue()))
- data.clearSignals();
- memory.setCell(addressed, data.getValues());
++ {
++ BitVector storedData = memory.getCell(addressed);
++ return e -> data.feedSignals(storedData);
++ }
+ else
+ {
++ BitVector transData = data.getValues();
++ return e ->
++ {
++ data.clearSignals();
++ memory.setCell(addressed, transData);
++ };
+ }
+ }
+
+ @Override
+ public List<ReadEnd> getAllInputs()
+ {
+ return List.of(data, rWBit, address);
+ }
+
+ @Override
+ public List<ReadWriteEnd> getAllOutputs()
+ {
+ return List.of(data);
+ }
+}
import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
import net.mograsim.logic.model.model.LogicModelModifiable;
import net.mograsim.logic.model.model.components.ModelComponent;
- import net.mograsim.logic.model.model.components.atomic.ModelAndGate;
import net.mograsim.logic.model.model.wires.Pin;
import net.mograsim.logic.model.model.wires.PinUsage;
import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
import net.mograsim.logic.model.snippets.Renderer;
import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer;
- import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer;
- import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer.CenteredTextParams;
+ import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer;
+ import net.mograsim.logic.model.snippets.symbolrenderers.SimpleRectangularLikeSymbolRenderer.SimpleRectangularLikeParams;
import net.mograsim.logic.model.util.JsonHandler;
import net.mograsim.machine.MainMemoryDefinition;
public class ModelMemoryWA extends ModelComponent
{
private final MainMemoryDefinition definition;
- private final Pin addrPin, dataPin, rWPin;
- private WordAddressableMemoryComponent memory;
+ private final Pin addrPin, dataPin, rWPin, clock;
- private CoreWordAddressableMemory memory;
++ private CoreWordAddressableMemory memory;
private final static int width = 100, height = 300;
private Renderer symbolRenderer;
private Renderer outlineRenderer;
public ModelMemoryWA(LogicModelModifiable model, MainMemoryDefinition definition, String name)
{
- super(model, name,false);
+ super(model, name, false);
this.definition = definition;
- CenteredTextParams renderer1Params = new CenteredTextParams();
- renderer1Params.text = "RAM";
- renderer1Params.fontHeight = 24;
- this.symbolRenderer = new CenteredTextSymbolRenderer(this, renderer1Params);
+ SimpleRectangularLikeParams rendererParams = new SimpleRectangularLikeParams();
+ rendererParams.centerText = "RAM";
+ rendererParams.centerTextHeight = 24;
+ rendererParams.horizontalComponentCenter = width / 100;
+ rendererParams.pinLabelHeight = 17.5;
+ rendererParams.pinLabelMargin = 2.5;
+ this.symbolRenderer = new SimpleRectangularLikeSymbolRenderer(this, rendererParams);
this.outlineRenderer = new DefaultOutlineRenderer(this);
setSize(width, height);
addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, 0, 10));
addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, 0, 30));
addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, 0, 50));
-
+ addPin(clock = new Pin(model, this, "C", 1, PinUsage.INPUT, 0, 70));
+
init();
}
{
return rWPin;
}
+
+ public Pin getClockPin()
+ {
+ return clock;
+ }
- public void setCoreModelBinding(WordAddressableMemoryComponent memory)
+ public void setCoreModelBinding(CoreWordAddressableMemory memory)
{
this.memory = memory;
}
return definition;
}
- public WordAddressableMemoryComponent getMemory()
+ public CoreWordAddressableMemory getMemory()
{
return memory;
}
static
{
LogicCoreAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());
- IndirectModelComponentCreator.setComponentSupplier(ModelAndGate.class.getCanonicalName(), (m, p, n) ->
+ IndirectModelComponentCreator.setComponentSupplier(ModelMemoryWA.class.getCanonicalName(), (m, p, n) ->
{
ModelMemoryWAParams params = JsonHandler.fromJsonTree(p, ModelMemoryWAParams.class);
return new ModelMemoryWA(m, MainMemoryDefinition.create(params.addrBits, params.cellWidth, params.minAddr, params.maxAddr), n);