X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fmi%2Fcomponents%2FModelMicroInstructionMemory.java;h=25c0b68be125811dab186e9111080b66d0e3a6c9;hb=c356c613955c3ea57d2379fb76f9bd07f1e30170;hp=aeffbd2c303b34508b2576da4956e7805a732aae;hpb=26cacc7d4e6dd00d52546754ecc478b129f84339;p=Mograsim.git diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java index aeffbd2c..25c0b68b 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java @@ -1,9 +1,15 @@ package net.mograsim.machine.mi.components; +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; import net.mograsim.logic.model.modeladapter.LogicCoreAdapter; +import net.mograsim.logic.model.serializing.IdentifyParams; +import net.mograsim.logic.model.snippets.HighLevelStateHandler; import net.mograsim.machine.ModelMemory; import net.mograsim.machine.mi.MicroInstructionMemory; import net.mograsim.machine.mi.MicroInstructionMemoryDefinition; @@ -14,6 +20,8 @@ public abstract class ModelMicroInstructionMemory extends ModelMemory private CoreMicroInstructionMemory memory; private final MicroInstructionMemoryDefinition definition; + private final List> memoryBindingListeners; + public ModelMicroInstructionMemory(LogicModelModifiable model, MicroInstructionMemoryDefinition definition, String name) { super(model, 120, 150, name, "MPM", false); @@ -22,6 +30,60 @@ public abstract class ModelMicroInstructionMemory extends ModelMemory addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionDefinition().sizeInBits(), PinUsage.OUTPUT, getWidth(), 50)); + memoryBindingListeners = new ArrayList<>(); + + setHighLevelStateHandler(new HighLevelStateHandler() + { + @Override + public Object get(String stateID) + { + if (stateID.equals("memory_binding")) + return memory.getMemory(); + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + + @Override + public void set(String stateID, Object newState) + { + if (stateID.equals("memory_binding")) + { + memory.setMemory((MicroInstructionMemory) 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); + } + + @Override + public String getIDForSerializing(IdentifyParams idParams) + { + return null; + } + + @Override + public Object getParamsForSerializing(IdentifyParams idParams) + { + return null; + } + }); + init(); } @@ -50,23 +112,6 @@ public abstract class ModelMicroInstructionMemory extends ModelMemory this.memory = memory; } - @Override - public void setHighLevelState(String stateID, Object newState) - { - if (stateID.equals("memory_binding")) - memory.setMemory((MicroInstructionMemory) newState); - else - super.setHighLevelState(stateID, newState); - } - - @Override - public Object getHighLevelState(String stateID) - { - if (stateID.equals("memory_binding")) - return memory.getMemory(); - return super.getHighLevelState(stateID); - } - static { LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter());