import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
import net.mograsim.logic.model.serializing.IdentifierGetter;
import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
+import net.mograsim.machine.MainMemoryDefinition;
+import net.mograsim.machine.standard.memory.WordAddressableMemoryComponent;
import net.mograsim.preferences.Preferences;
public class GUIMemoryWA extends GUIComponent
{
- private final static String paramAddr = "addrBits", paramWordWidth = "wordWidth", paramMaxAddr = "maxAddr", paramMinAddr = "minAddr";
- private final int addressBits, wordWidth;
- public final long maximalAddress, minimalAddress;
+ private final MainMemoryDefinition definition;
private final Pin addrPin, dataPin, rWPin;
+ private WordAddressableMemoryComponent memory;
private final static int width = 100, height = 300;
+
+ private final static String addrKey = "addrBits", cellWidthKey = "cellWidth", minAddrKey = "minAddr", maxAddrKey = "maxAddr";
- public GUIMemoryWA(ViewModelModifiable model, int addressBits, int wordWidth, long maximalAddress, long minimalAddress, String name)
+ public GUIMemoryWA(ViewModelModifiable model, MainMemoryDefinition definition, String name)
{
super(model, name);
- this.addressBits = addressBits;
- this.wordWidth = wordWidth;
- this.maximalAddress = maximalAddress;
- this.minimalAddress = minimalAddress;
+ this.definition = definition;
setSize(width, height);
- addPin(addrPin = new Pin(this, "A", addressBits, 0, 10));
- addPin(dataPin = new Pin(this, "D", wordWidth, 0, 30));
+ addPin(addrPin = new Pin(this, "A", definition.getMemoryAddressBits(), 0, 10));
+ addPin(dataPin = new Pin(this, "D", definition.getCellWidth(), 0, 30));
addPin(rWPin = new Pin(this, "RW", 1, 0, 50));
}
{
return rWPin;
}
+
+ public void setLogicModelBinding(WordAddressableMemoryComponent memory)
+ {
+ this.memory = memory;
+ }
+
+ public MainMemoryDefinition getDefinition()
+ {
+ return definition;
+ }
+
+ public WordAddressableMemoryComponent getMemory()
+ {
+ return memory;
+ }
@Override
public void render(GeneralGC gc, Rectangle visibleRegion)
@Override
public JsonElement getParamsForSerializing(IdentifierGetter idGetter)
{
- JsonObject obj = new JsonObject();
- obj.addProperty(paramAddr, addressBits);
- obj.addProperty(paramWordWidth, wordWidth);
- obj.addProperty(paramMaxAddr, maximalAddress);
- obj.addProperty(paramMinAddr, minimalAddress);
- return obj;
+ JsonObject o = new JsonObject();
+ o.addProperty(addrKey, definition.getMemoryAddressBits());
+ o.addProperty(cellWidthKey, definition.getCellWidth());
+ o.addProperty(maxAddrKey, definition.getMaximalAddress());
+ o.addProperty(minAddrKey, definition.getMinimalAddress());
+ return o;
}
static
ViewLogicModelAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());
IndirectGUIComponentCreator.setComponentSupplier(GUIAndGate.class.getCanonicalName(), (m, p, n) ->
{
- JsonObject obj = p.getAsJsonObject();
- return new GUIMemoryWA(m, obj.get(paramAddr).getAsInt(), obj.get(paramWordWidth).getAsInt(), obj.get(paramMaxAddr).getAsLong(),
- obj.get(paramMinAddr).getAsLong(), n);
+ JsonObject o = (JsonObject) p;
+ int addressBits = o.get(addrKey).getAsInt();
+ int cellWidth = o.get(cellWidthKey).getAsInt();
+ long maxAddr = o.get(maxAddrKey).getAsLong();
+ long minAddr = o.get(minAddrKey).getAsLong();
+ return new GUIMemoryWA(m, MainMemoryDefinition.create(addressBits, cellWidth, minAddr, maxAddr), n);
});
}
}