X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fmi%2FStandardMicroInstructionMemory.java;h=94905a5b86108ad2b44ab57e0127ff01948f3428;hb=76c2b3eab6cec47490bb75713356152deb5d07ed;hp=519c9b3af9e1c31a92d1232695b2de2bc29f2540;hpb=7d05144c25daa53e60fc9ed9fd503546a86567f8;p=Mograsim.git diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionMemory.java index 519c9b3a..94905a5b 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionMemory.java @@ -1,15 +1,17 @@ package net.mograsim.machine.mi; import java.util.HashSet; +import java.util.Set; -import net.mograsim.machine.MemoryObserver; import net.mograsim.machine.standard.memory.MemoryException; public class StandardMicroInstructionMemory implements MicroInstructionMemory { private MicroInstruction[] data; private MicroInstructionMemoryDefinition definition; - private HashSet observers = new HashSet<>(); + private HashSet observers = new HashSet<>(); + private Set activeInstructionListeners = new HashSet<>(); + private long activeInstruction = -1; public StandardMicroInstructionMemory(MicroInstructionMemoryDefinition definition) { @@ -30,8 +32,7 @@ public class StandardMicroInstructionMemory implements MicroInstructionMemory int translatedAddress = translate(address); MicroInstruction actual = data[translatedAddress]; if (actual == null) - actual = data[translatedAddress] = definition.getMicroInstructionDefinition() - .createDefaultInstruction(() -> notifyObservers(address)); + actual = data[translatedAddress] = definition.getMicroInstructionDefinition().createDefaultInstruction(); return actual; } @@ -39,31 +40,57 @@ public class StandardMicroInstructionMemory implements MicroInstructionMemory public void setCell(long address, MicroInstruction data) { this.data[translate(address)] = data; - notifyObservers(address); + notifyMemoryChanged(address); } @Override - public void registerObserver(MemoryObserver ob) + public void registerCellModifiedListener(MemoryCellModifiedListener ob) { observers.add(ob); } @Override - public void deregisterObserver(MemoryObserver ob) + public void deregisterCellModifiedListener(MemoryCellModifiedListener ob) { observers.remove(ob); } @Override - public void notifyObservers(long address) + public void registerActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob) + { + activeInstructionListeners.add(ob); + } + + @Override + public void deregisterActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob) + { + activeInstructionListeners.remove(ob); + } + + private void notifyMemoryChanged(long address) { observers.forEach(ob -> ob.update(address)); } + private void notifyActiveInstructionChanged(long address) + { + activeInstructionListeners.forEach(o -> o.activeMicroInstructionChanged(address)); + } + @Override public MicroInstructionMemoryDefinition getDefinition() { return definition; } + @Override + public void setActiveInstruction(long address) + { + if (address != activeInstruction) + { + activeInstruction = address; + notifyActiveInstructionChanged(address); + } + } + }