1 package net.mograsim.machine.mi.components;
3 import java.util.ArrayList;
5 import java.util.function.Consumer;
7 import net.mograsim.logic.model.model.LogicModelModifiable;
8 import net.mograsim.logic.model.model.wires.Pin;
9 import net.mograsim.logic.model.model.wires.PinUsage;
10 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
11 import net.mograsim.logic.model.serializing.IdentifyParams;
12 import net.mograsim.logic.model.snippets.HighLevelStateHandler;
13 import net.mograsim.machine.ModelMemory;
14 import net.mograsim.machine.mi.MPROM;
15 import net.mograsim.machine.mi.MPROMDefinition;
17 public abstract class ModelMPROM extends ModelMemory
19 private final Pin addrPin, dataPin;
20 private CoreMPROM memory;
21 private final MPROMDefinition definition;
23 private final List<Consumer<Object>> memoryBindingListeners;
25 public ModelMPROM(LogicModelModifiable model, MPROMDefinition definition, String name)
27 super(model, 30, 80, name, "MPROM", false);
28 this.definition = definition;
29 addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, getWidth(), 30));
30 addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionMemoryAddressBits(), PinUsage.OUTPUT, getWidth(), 50));
32 memoryBindingListeners = new ArrayList<>();
34 setHighLevelStateHandler(new HighLevelStateHandler()
37 public Object get(String stateID)
39 if (stateID.equals("memory_binding"))
40 return memory.getMemory();
41 throw new IllegalArgumentException("No high level state with ID " + stateID);
45 public void set(String stateID, Object newState)
47 if (stateID.equals("memory_binding"))
49 memory.setMemory((MPROM) newState);
50 memoryBindingListeners.forEach(l -> l.accept(newState));
52 throw new IllegalArgumentException("No high level state with ID " + stateID);
56 public void addListener(String stateID, Consumer<Object> stateChanged)
58 if (stateID.equals("memory_binding"))
59 memoryBindingListeners.add(stateChanged);
61 throw new IllegalArgumentException("No high level state with ID " + stateID);
65 public void removeListener(String stateID, Consumer<Object> stateChanged)
67 if (stateID.equals("memory_binding"))
68 memoryBindingListeners.remove(stateChanged);
70 throw new IllegalArgumentException("No high level state with ID " + stateID);
74 public String getIDForSerializing(IdentifyParams idParams)
80 public Object getParamsForSerializing(IdentifyParams idParams)
89 public MPROMDefinition getDefinition()
94 public Pin getAddressPin()
99 public Pin getDataPin()
104 public CoreMPROM getCoreMemory()
109 public void setCoreModelBinding(CoreMPROM memory)
111 this.memory = memory;
116 LogicCoreAdapter.addComponentAdapter(new MPROMAdapter());