X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fmi%2FAssignableMicroInstructionMemory.java;h=a366ae0aa27834886c4744cb23c21fc6d2be1d62;hb=73e8cb804627bb71b3ac92796ecf4e29fb848521;hp=5fe753eb6175f9b544e0a4ede4448fd41594008c;hpb=d094b43f1697af4586f135790919f866cc53a9a5;p=Mograsim.git diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/AssignableMicroInstructionMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/AssignableMicroInstructionMemory.java index 5fe753eb..a366ae0a 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/AssignableMicroInstructionMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/AssignableMicroInstructionMemory.java @@ -3,24 +3,31 @@ package net.mograsim.machine.mi; import java.util.HashSet; import java.util.Set; -import net.mograsim.machine.MemoryObserver; +import net.mograsim.machine.Memory.MemoryCellModifiedListener; +import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener; -public class AssignableMicroInstructionMemory implements MicroInstructionMemory, MemoryObserver +public class AssignableMicroInstructionMemory + implements MicroInstructionMemory, MemoryCellModifiedListener, ActiveMicroInstructionChangedListener { - private Set observers = new HashSet<>(); - MicroInstructionMemory real = null; + + private Set observers = new HashSet<>(); + private Set activeInstructionListeners = new HashSet<>(); + private Set reassignmentListeners = new HashSet<>(); + private MicroInstructionMemory real = null; public AssignableMicroInstructionMemory(StandardMicroInstructionMemory standardMicroInstructionMemory) { real = standardMicroInstructionMemory; - real.registerObserver(this); + real.registerCellModifiedListener(this); } public void bind(MicroInstructionMemory real) { - this.real.deregisterObserver(this); + this.real.deregisterCellModifiedListener(this); this.real = real; - real.registerObserver(this); + real.registerCellModifiedListener(this); + notifyMemoryChanged(-1); + notifyMemoryReassigned(real); } @Override @@ -36,23 +43,39 @@ public class AssignableMicroInstructionMemory implements MicroInstructionMemory, } @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(o -> o.update(address)); } + private void notifyActiveInstructionChanged(long address) + { + activeInstructionListeners.forEach(o -> o.activeMicroInstructionChanged(address)); + } + @Override public MicroInstructionMemoryDefinition getDefinition() { @@ -62,6 +85,38 @@ public class AssignableMicroInstructionMemory implements MicroInstructionMemory, @Override public void update(long address) { - notifyObservers(address); + notifyMemoryChanged(address); + } + + @Override + public void setActiveInstruction(long address) + { + real.setActiveInstruction(address); + } + + @Override + public void activeMicroInstructionChanged(long address) + { + notifyActiveInstructionChanged(address); + } + + public void registerMemoryReassignedListener(MIMemoryReassignedListener listener) + { + reassignmentListeners.add(listener); + } + + public void deregisterMemoryReassignedListener(MIMemoryReassignedListener listener) + { + reassignmentListeners.remove(listener); + } + + private void notifyMemoryReassigned(MicroInstructionMemory newAssignee) + { + reassignmentListeners.forEach(l -> l.reassigned(newAssignee)); + } + + public static interface MIMemoryReassignedListener + { + public void reassigned(MicroInstructionMemory newAssignee); } }