X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fmi%2FStandardMPROM.java;h=3d8a8cb1cfe7c99a2708162d0f151ec090bd9c2d;hp=48df1656494c910ad6276bd2471b1c9123301df7;hb=b5d55c59d7069171bd928e4a945d9185ee4bc2b0;hpb=f098cd47d06be0cc654532a5fad0e5e89f0ef93c diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMPROM.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMPROM.java index 48df1656..3d8a8cb1 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMPROM.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMPROM.java @@ -1,73 +1,18 @@ package net.mograsim.machine.mi; -import java.math.BigInteger; -import java.util.HashSet; - import net.mograsim.logic.core.types.BitVector; -import net.mograsim.machine.standard.memory.MemoryException; +import net.mograsim.machine.standard.memory.StandardBitVectorMemory; -public class StandardMPROM implements MPROM +public class StandardMPROM extends StandardBitVectorMemory implements MPROM { - private BitVector[] data; - private MPROMDefinition definition; - private HashSet observers = new HashSet<>(); - public StandardMPROM(MPROMDefinition definition) { - if (definition.size() > Integer.MAX_VALUE) - throw new MemoryException("Size of MPROM must be an int, not a long"); - this.definition = definition; - data = new BitVector[(int) definition.size()]; - } - - private int translate(long address) - { - return (int) (address - definition.getMinimalAddress()); - } - - @Override - public BitVector getCell(long address) - { - int translatedAddress = translate(address); - BitVector cell = data[translatedAddress]; - if (cell == null) - cell = data[translatedAddress] = BitVector.from(address * 16, definition.getMicroInstructionMemoryAddressBits()); - return cell; - } - - @Override - public BigInteger getCellAsBigInteger(long address) - { - return getCell(address).getUnsignedValue(); - } - - @Override - public void setCell(long address, BitVector data) - { - this.data[translate(address)] = data; - notifyMemoryChanged(address); - } - - @Override - public void registerCellModifiedListener(MemoryCellModifiedListener ob) - { - observers.add(ob); - } - - @Override - public void deregisterCellModifiedListener(MemoryCellModifiedListener ob) - { - observers.remove(ob); - } - - private void notifyMemoryChanged(long address) - { - observers.forEach(ob -> ob.update(address)); + super(definition); } @Override - public MPROMDefinition getDefinition() + protected BitVector getDefaultValue(long address) { - return definition; + return BitVector.from(address * 16, getDefinition().getCellWidth()); } }