X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fstandard%2Fmemory%2FModelWordAddressableMemory.java;fp=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fstandard%2Fmemory%2FModelWordAddressableMemory.java;h=a1112e68f6741c748a145f338ede9b0c0a708aae;hb=69ec19d54ceb6d5abbb8b4faa55284af22174859;hp=b2498498133d6599ae8930780529a3a992ab81b4;hpb=f1933b06b5fe800902131e4dc34f002ac3fa17f0;p=Mograsim.git diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java index b2498498..a1112e68 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java @@ -1,5 +1,9 @@ package net.mograsim.machine.standard.memory; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.model.wires.PinUsage; @@ -16,6 +20,8 @@ public abstract class ModelWordAddressableMemory extends ModelMemory private CoreWordAddressableMemory memory; private MainMemoryDefinition definition; + private final List> memoryBindingListeners; + public ModelWordAddressableMemory(LogicModelModifiable model, MainMemoryDefinition definition, String name) { super(model, 120, 150, name, "RAM", false); @@ -25,10 +31,12 @@ public abstract class ModelWordAddressableMemory extends ModelMemory addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, getWidth(), 50)); addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, getWidth(), 70)); + memoryBindingListeners = new ArrayList<>(); + setHighLevelStateHandler(new HighLevelStateHandler() { @Override - public Object getHighLevelState(String stateID) + public Object get(String stateID) { if (stateID.equals("memory_binding")) return memory.getMemory(); @@ -36,10 +44,30 @@ public abstract class ModelWordAddressableMemory extends ModelMemory } @Override - public void setHighLevelState(String stateID, Object newState) + public void set(String stateID, Object newState) { if (stateID.equals("memory_binding")) + { memory.setMemory((MainMemory) newState); + memoryBindingListeners.forEach(l -> l.accept(newState)); + } else + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + + @Override + public void addListener(String stateID, Consumer stateChanged) + { + if (stateID.equals("memory_binding")) + memoryBindingListeners.add(stateChanged); + else + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + + @Override + public void removeListener(String stateID, Consumer stateChanged) + { + if (stateID.equals("memory_binding")) + memoryBindingListeners.remove(stateChanged); else throw new IllegalArgumentException("No high level state with ID " + stateID); }