From 939f37fb65d2057c3f370214cc2eebd3e9989f69 Mon Sep 17 00:00:00 2001 From: Fabian Stemmler Date: Fri, 13 Sep 2019 16:01:37 +0200 Subject: [PATCH] Added Clock input to CoreWordAddressableMemory --- ...mponent.java => CoreWordAddressableMemory.java} | 14 +++++++++----- .../machine/standard/memory/ModelMemoryWA.java | 14 ++++++++++---- .../memory/WordAddressableMemoryAdapter.java | 4 ++-- .../standard/memory/WordAddressableMemoryTest.java | 8 ++++++-- 4 files changed, 27 insertions(+), 13 deletions(-) rename net.mograsim.machine/src/net/mograsim/machine/standard/memory/{WordAddressableMemoryComponent.java => CoreWordAddressableMemory.java} (86%) diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryComponent.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java similarity index 86% rename from net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryComponent.java rename to net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java index 3c135ec4..f7dd9820 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryComponent.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/CoreWordAddressableMemory.java @@ -12,13 +12,13 @@ import net.mograsim.machine.MainMemoryDefinition; /** * A memory component that only allows access to words of a specific width */ -public class WordAddressableMemoryComponent extends BasicCoreComponent +public class CoreWordAddressableMemory extends BasicCoreComponent { private final WordAddressableMemory memory; private final static Bit read = Bit.ONE; private ReadWriteEnd data; - private ReadEnd rWBit, address; + 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 @@ -26,8 +26,8 @@ public class WordAddressableMemoryComponent extends BasicCoreComponent * @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 WordAddressableMemoryComponent(Timeline timeline, int processTime, MainMemoryDefinition definition, ReadWriteEnd data, - ReadEnd rWBit, ReadEnd address) + public CoreWordAddressableMemory(Timeline timeline, int processTime, MainMemoryDefinition definition, ReadWriteEnd data, + ReadEnd rWBit, ReadEnd address, ReadEnd clock) { super(timeline, processTime); if(data.width() != definition.getCellWidth()) @@ -39,16 +39,20 @@ public class WordAddressableMemoryComponent extends BasicCoreComponent 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 protected void compute() { + if(clock.getValue() != Bit.ONE) + return; if (!address.hasNumericValue()) { if (read.equals(rWBit.getValue())) diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java index 9f5b1cc9..218c6554 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelMemoryWA.java @@ -20,8 +20,8 @@ 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 final static int width = 100, height = 300; private Renderer symbolRenderer; private Renderer outlineRenderer; @@ -42,6 +42,7 @@ public class ModelMemoryWA extends ModelComponent 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(); } @@ -60,8 +61,13 @@ public class ModelMemoryWA extends ModelComponent { return rWPin; } + + public Pin getClockPin() + { + return clock; + } - public void setCoreModelBinding(WordAddressableMemoryComponent memory) + public void setCoreModelBinding(CoreWordAddressableMemory memory) { this.memory = memory; } @@ -71,7 +77,7 @@ public class ModelMemoryWA extends ModelComponent return definition; } - public WordAddressableMemoryComponent getMemory() + public CoreWordAddressableMemory getMemory() { return memory; } diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryAdapter.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryAdapter.java index 6b632613..a2272669 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryAdapter.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemoryAdapter.java @@ -19,7 +19,6 @@ public class WordAddressableMemoryAdapter implements ComponentAdapter logicWiresPerPin) @@ -27,7 +26,8 @@ public class WordAddressableMemoryAdapter implements ComponentAdapter 0; j *= 2) { -- 2.17.1