1 package net.mograsim.machine.mi;
3 import java.util.HashSet;
5 import net.mograsim.machine.MemoryDefinition;
6 import net.mograsim.machine.MemoryObserver;
7 import net.mograsim.machine.standard.memory.MemoryException;
9 class StandardMicroprogramMemory implements MicroprogramMemory
11 private MicroInstruction[] data;
12 private MemoryDefinition definition;
13 private HashSet<MemoryObserver> observers;
15 StandardMicroprogramMemory(MemoryDefinition definition)
17 if(definition.size() > Integer.MAX_VALUE)
18 throw new MemoryException("Size of MicroprogramMemory must be an int, not a long");
19 this.definition = definition;
20 data = new MicroInstruction[(int) definition.size()];
23 private int translate(long address)
25 return (int) (address - definition.getMinimalAddress());
29 public MicroInstruction getCell(long address)
31 return data[translate(address)];
35 public void setCell(long address, MicroInstruction data)
37 this.data[translate(address)] = data;
41 public void registerObserver(MemoryObserver ob)
47 public void deregisterObserver(MemoryObserver ob)
53 public void notifyObservers(long address)
55 observers.forEach(ob -> ob.update(address));
59 public MemoryDefinition getDefinition()