X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fstandard%2Fmemory%2FWordAddressableMemory.java;fp=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fstandard%2Fmemory%2FWordAddressableMemory.java;h=4a54ad9f4cede9d8533829aa9250f58444616cea;hb=7d05144c25daa53e60fc9ed9fd503546a86567f8;hp=0000000000000000000000000000000000000000;hpb=8bed58cd47f4e53a0a83e066d38864aa6875502f;p=Mograsim.git diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemory.java new file mode 100644 index 00000000..4a54ad9f --- /dev/null +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemory.java @@ -0,0 +1,48 @@ +package net.mograsim.machine.standard.memory; + +import java.math.BigInteger; + +import net.mograsim.logic.core.types.Bit; +import net.mograsim.logic.core.types.BitVector; +import net.mograsim.machine.GenericMemory; +import net.mograsim.machine.MainMemory; +import net.mograsim.machine.MainMemoryDefinition; + +public class WordAddressableMemory extends GenericMemory implements MainMemory +{ + private final int cellWidth; + private final MainMemoryDefinition definition; + + public WordAddressableMemory(MainMemoryDefinition definition) + { + super(definition); + this.cellWidth = definition.getCellWidth(); + this.definition = definition; + } + + @Override + public BitVector getCell(long address) + { + BitVector data = super.getCell(address); + return data == null ? BitVector.of(Bit.ZERO, cellWidth) : data; + } + + @Override + public BigInteger getCellAsBigInteger(long address) + { + BitVector data = getCell(address); + return data == null ? BigInteger.valueOf(0) : data.getUnsignedValue(); + } + + @Override + public void setCellAsBigInteger(long address, BigInteger data) + { + setCell(address, BitVector.from(data, cellWidth)); + } + + @Override + public MainMemoryDefinition getDefinition() + { + return definition; + } +}