1 package net.mograsim.machine.standard.memory;
3 import net.haspamelodica.swt.helper.gcs.GeneralGC;
4 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
5 import net.mograsim.logic.model.model.ViewModelModifiable;
6 import net.mograsim.logic.model.model.components.GUIComponent;
7 import net.mograsim.logic.model.model.components.atomic.GUIAndGate;
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.ViewLogicModelAdapter;
11 import net.mograsim.logic.model.serializing.IdentifierGetter;
12 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
13 import net.mograsim.logic.model.snippets.Renderer;
14 import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer;
15 import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer;
16 import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer.CenteredTextParams;
17 import net.mograsim.logic.model.util.JsonHandler;
18 import net.mograsim.machine.MainMemoryDefinition;
20 public class GUIMemoryWA extends GUIComponent
22 private final MainMemoryDefinition definition;
23 private final Pin addrPin, dataPin, rWPin;
24 private WordAddressableMemoryComponent memory;
25 private final static int width = 100, height = 300;
26 private Renderer symbolRenderer;
27 private Renderer outlineRenderer;
29 public GUIMemoryWA(ViewModelModifiable model, MainMemoryDefinition definition, String name)
32 this.definition = definition;
34 CenteredTextParams renderer1Params = new CenteredTextParams();
35 renderer1Params.text = "RAM";
36 renderer1Params.fontHeight = 24;
37 this.symbolRenderer = new CenteredTextSymbolRenderer(this, renderer1Params);
38 this.outlineRenderer = new DefaultOutlineRenderer(this);
40 setSize(width, height);
41 //TODO check the usages
42 addPin(addrPin = new Pin(this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, 0, 10));
43 addPin(dataPin = new Pin(this, "D", definition.getCellWidth(), PinUsage.TRISTATE, 0, 30));
44 addPin(rWPin = new Pin(this, "RW", 1, PinUsage.INPUT, 0, 50));
47 public Pin getAddressPin()
52 public Pin getDataPin()
57 public Pin getReadWritePin()
62 public void setLogicModelBinding(WordAddressableMemoryComponent memory)
67 public MainMemoryDefinition getDefinition()
72 public WordAddressableMemoryComponent getMemory()
78 public void render(GeneralGC gc, Rectangle visibleRegion)
80 symbolRenderer.render(gc, visibleRegion);
81 outlineRenderer.render(gc, visibleRegion);
85 public GUIMemoryWAParams getParamsForSerializing(IdentifierGetter idGetter)
87 GUIMemoryWAParams params = new GUIMemoryWAParams();
88 params.addrBits = definition.getMemoryAddressBits();
89 params.cellWidth = definition.getCellWidth();
90 params.minAddr = definition.getMinimalAddress();
91 params.maxAddr = definition.getMaximalAddress();
97 ViewLogicModelAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());
98 IndirectGUIComponentCreator.setComponentSupplier(GUIAndGate.class.getCanonicalName(), (m, p, n) ->
100 GUIMemoryWAParams params = JsonHandler.fromJsonTree(p, GUIMemoryWAParams.class);
101 return new GUIMemoryWA(m, MainMemoryDefinition.create(params.addrBits, params.cellWidth, params.minAddr, params.maxAddr), n);
105 public static class GUIMemoryWAParams
108 public int cellWidth;