Finished MPROM support. Fixes #10
[Mograsim.git] / plugins / net.mograsim.machine / src / net / mograsim / machine / standard / memory / StandardBitVectorMemory.java
1 package net.mograsim.machine.standard.memory;
2
3 import java.math.BigInteger;
4
5 import net.mograsim.logic.core.types.Bit;
6 import net.mograsim.logic.core.types.BitVector;
7 import net.mograsim.machine.BitVectorMemory;
8 import net.mograsim.machine.BitVectorMemoryDefinition;
9 import net.mograsim.machine.GenericMemory;
10
11 public class StandardBitVectorMemory<D extends BitVectorMemoryDefinition> extends GenericMemory<BitVector, D> implements BitVectorMemory
12 {
13         public StandardBitVectorMemory(D definition)
14         {
15                 super(definition);
16         }
17
18         @Override
19         public BitVector getCell(long address)
20         {
21                 BitVector cell = super.getCell(address);
22                 if (cell == null)
23                         setCell(address, cell = getDefaultValue(address));
24                 return cell;
25         }
26
27         @Override
28         public BigInteger getCellAsBigInteger(long address)
29         {
30                 return getCell(address).getUnsignedValue();
31         }
32
33         @Override
34         public void setCell(long address, BitVector data)
35         {
36                 if (data.isBinary())
37                         super.setCell(address, data);
38         }
39
40         @Override
41         public void setCellAsBigInteger(long address, BigInteger data)
42         {
43                 setCell(address, BitVector.from(data, getDefinition().getCellWidth()));
44         }
45
46         protected BitVector getDefaultValue(@SuppressWarnings("unused") /* this method is inteded to be overridden */ long address)
47         {
48                 return BitVector.of(Bit.U, getDefinition().getCellWidth());
49         }
50 }