X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fstandard%2Fmemory%2FModelWordAddressableMemory.java;h=a1112e68f6741c748a145f338ede9b0c0a708aae;hb=0c404f876557865fb7361ca458ac90caf41afe19;hp=986dbe5028f7b736696e2d91c789092853f8ef42;hpb=7d05144c25daa53e60fc9ed9fd503546a86567f8;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 986dbe50..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,18 +1,27 @@ 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; -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.MainMemory; import net.mograsim.machine.MainMemoryDefinition; import net.mograsim.machine.ModelMemory; -public abstract class ModelWordAddressableMemory extends ModelMemory +public abstract class ModelWordAddressableMemory extends ModelMemory { private final Pin addrPin, dataPin, rWPin; 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); @@ -22,6 +31,60 @@ public abstract class ModelWordAddressableMemory extends Mode 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 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((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); + } + + @Override + public String getIDForSerializing(IdentifyParams idParams) + { + return null; + } + + @Override + public Object getParamsForSerializing(IdentifyParams idParams) + { + return null; + } + }); + init(); } @@ -54,4 +117,9 @@ public abstract class ModelWordAddressableMemory extends Mode { return memory; } -} + + static + { + LogicCoreAdapter.addComponentAdapter(new WordAddressableMemoryAdapter()); + } +} \ No newline at end of file