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=b3c41749fec941a414e64a3a0e9ff0ff599ff502;hpb=58babf45ae7d259a296656451d796dbe601377a4;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 b3c41749..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,18 +1,27 @@ 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.machine.Machine; +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; -public abstract class ModelMicroInstructionMemory extends ModelMemory +public abstract class ModelMicroInstructionMemory extends ModelMemory { private final Pin addrPin, dataPin; 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); @@ -21,6 +30,60 @@ public abstract class ModelMicroInstructionMemory extends Mod 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(); } @@ -48,4 +111,9 @@ public abstract class ModelMicroInstructionMemory extends Mod { this.memory = memory; } -} + + static + { + LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter()); + } +} \ No newline at end of file