X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2Fmemory%2FWordAddressableMemory.java;fp=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2Fmemory%2FWordAddressableMemory.java;h=0000000000000000000000000000000000000000;hb=de4ce44622b2a40c2ff4030467de8f56db917329;hp=3e83832c5eb29e5e5bad314ab4f7c2f68270af8e;hpb=026db85f46b6ea58e765ecff069545728eebdcac;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/memory/WordAddressableMemory.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/memory/WordAddressableMemory.java deleted file mode 100644 index 3e83832c..00000000 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/memory/WordAddressableMemory.java +++ /dev/null @@ -1,80 +0,0 @@ -package net.mograsim.logic.core.components.memory; - -import java.util.Arrays; -import java.util.HashMap; - -import net.mograsim.logic.core.types.Bit; -import net.mograsim.logic.core.types.BitVector; - -public class WordAddressableMemory -{ - private final int cellWidth; - private final long minimalAddress, maximalAddress; - private final int pageSize = 64; - - private HashMap pages; - - public WordAddressableMemory(int cellWidth, long minimalAddress, long maximalAddress) - { - super(); - this.cellWidth = cellWidth; - this.minimalAddress = minimalAddress; - this.maximalAddress = maximalAddress; - this.pages = new HashMap<>(); - } - - public void setCell(long address, BitVector b) - { - if (address < minimalAddress || address > maximalAddress) - throw new IndexOutOfBoundsException(String.format("Memory address out of bounds! Minimum: %d Maximum: %d Actual: %d", - minimalAddress, maximalAddress, address)); - long page = address / pageSize; - int offset = (int) (address % pageSize); - Page p = pages.get(Long.valueOf(page)); - if (p == null) - pages.put(page, p = new Page()); - p.setCell(offset, b); - } - - public BitVector getCell(long address) - { - long page = address / pageSize; - int offset = (int) (address % pageSize); - Page p = pages.get(Long.valueOf(page)); - if (p == null) - return BitVector.of(Bit.U, cellWidth); - return p.getCell(offset); - } - - private class Page - { - private BitVector[] memory; - - public Page() - { - memory = new BitVector[pageSize]; - } - - public BitVector getCell(int index) - { - BitVector b = memory[index]; - if (b == null) - return BitVector.of(Bit.U, cellWidth); - return memory[index]; - } - - public void setCell(int index, BitVector bits) - { - if (bits.length() != cellWidth) - throw new IllegalArgumentException(String.format( - "BitVector to be saved in memory cell has unexpected length. Expected: %d Actual: %d", cellWidth, bits.length())); - memory[index] = bits; - } - - @Override - public String toString() - { - return Arrays.deepToString(memory); - } - } -}