X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.machine%2Fsrc%2Fnet%2Fmograsim%2Fmachine%2Fstandard%2Fmemory%2FGUIMemoryWA.java;h=52229267b28be309c8d09cea360a02a681fc73d5;hb=c202aac61021b9d12e4ac6495001bcd012cecde0;hp=1632c8eb739ec2fded080d903dc991684844f490;hpb=9aeb97636520d2226d3d9919ddf38c0e6d0171b7;p=Mograsim.git diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java index 1632c8eb..52229267 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/GUIMemoryWA.java @@ -2,9 +2,6 @@ package net.mograsim.machine.standard.memory; import org.eclipse.swt.graphics.Color; -import com.google.gson.Gson; -import com.google.gson.JsonElement; - import net.haspamelodica.swt.helper.gcs.GeneralGC; import net.haspamelodica.swt.helper.swtobjectwrappers.Font; import net.haspamelodica.swt.helper.swtobjectwrappers.Point; @@ -13,29 +10,30 @@ import net.mograsim.logic.model.model.ViewModelModifiable; import net.mograsim.logic.model.model.components.GUIComponent; import net.mograsim.logic.model.model.components.atomic.GUIAndGate; import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.model.wires.PinUsage; 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.DefaultMainMemoryDefinition; +import net.mograsim.logic.model.util.JsonHandler; import net.mograsim.machine.MainMemoryDefinition; -import net.mograsim.machine.standard.memory.WordAddressableMemoryComponent; import net.mograsim.preferences.Preferences; public class GUIMemoryWA extends GUIComponent { - private final MainMemoryDefinition definition; - private final Pin addrPin, dataPin, rWPin; - private WordAddressableMemoryComponent memory; - private final static int width = 100, height = 300; + private final MainMemoryDefinition definition; + private final Pin addrPin, dataPin, rWPin; + private WordAddressableMemoryComponent memory; + private final static int width = 100, height = 300; public GUIMemoryWA(ViewModelModifiable model, MainMemoryDefinition definition, String name) { super(model, name); this.definition = definition; setSize(width, height); - 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)); + //TODO check the usages + addPin(addrPin = new Pin(this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, 0, 10)); + addPin(dataPin = new Pin(this, "D", definition.getCellWidth(), PinUsage.TRISTATE, 0, 30)); + addPin(rWPin = new Pin(this, "RW", 1, PinUsage.INPUT, 0, 50)); } public Pin getAddressPin() @@ -52,17 +50,17 @@ public class GUIMemoryWA extends GUIComponent { return rWPin; } - + public void setLogicModelBinding(WordAddressableMemoryComponent memory) { this.memory = memory; } - + public MainMemoryDefinition getDefinition() { return definition; } - + public WordAddressableMemoryComponent getMemory() { return memory; @@ -73,7 +71,7 @@ public class GUIMemoryWA extends GUIComponent { // TODO This is copied from SimpleRectangularGUIGate; do this via delegation instead Color foreground = Preferences.current().getColor("net.mograsim.logic.model.color.foreground"); - if (foreground != null) + if(foreground != null) gc.setForeground(foreground); gc.drawRectangle(getPosX(), getPosY(), width, height); Font oldFont = gc.getFont(); @@ -82,16 +80,21 @@ public class GUIMemoryWA extends GUIComponent String label = "RAM"; Point textExtent = gc.textExtent(label); Color textColor = Preferences.current().getColor("net.mograsim.logic.model.color.text"); - if (textColor != null) + if(textColor != null) gc.setForeground(textColor); gc.drawText(label, getPosX() + (width - textExtent.x) / 2, getPosY() + (height - textExtent.y) / 2, true); gc.setFont(oldFont); } @Override - public JsonElement getParamsForSerializing(IdentifierGetter idGetter) + public GUIMemoryWAParams getParamsForSerializing(IdentifierGetter idGetter) { - return new Gson().toJsonTree(new DefaultMainMemoryDefinition(definition)); + GUIMemoryWAParams params = new GUIMemoryWAParams(); + params.addrBits = definition.getMemoryAddressBits(); + params.cellWidth = definition.getCellWidth(); + params.minAddr = definition.getMinimalAddress(); + params.maxAddr = definition.getMaximalAddress(); + return params; } static @@ -99,7 +102,16 @@ public class GUIMemoryWA extends GUIComponent ViewLogicModelAdapter.addComponentAdapter(new WordAddressableMemoryAdapter()); IndirectGUIComponentCreator.setComponentSupplier(GUIAndGate.class.getCanonicalName(), (m, p, n) -> { - return new GUIMemoryWA(m, new Gson().fromJson(p, DefaultMainMemoryDefinition.class), n); + GUIMemoryWAParams params = JsonHandler.fromJsonTree(p, GUIMemoryWAParams.class); + return new GUIMemoryWA(m, MainMemoryDefinition.create(params.addrBits, params.cellWidth, params.minAddr, params.maxAddr), n); }); } + + public static class GUIMemoryWAParams + { + public int addrBits; + public int cellWidth; + public long minAddr; + public long maxAddr; + } }