package net.mograsim.logic.model.am2900.components.am2910;
-import net.haspamelodica.swt.helper.gcs.GeneralGC;
-import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import static net.mograsim.logic.core.types.Bit.ONE;
+import static net.mograsim.logic.core.types.Bit.U;
+import static net.mograsim.logic.core.types.Bit.X;
+import static net.mograsim.logic.core.types.Bit.ZERO;
+
+import java.util.Map;
+
+import net.mograsim.logic.core.types.Bit;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
import net.mograsim.logic.model.model.ViewModelModifiable;
-import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent;
import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
-import net.mograsim.logic.model.modeladapter.componentadapters.Am2910InstrPLAAdapter;
-import net.mograsim.logic.model.snippets.Renderer;
-import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer;
-import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer;
-import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer.CenteredTextParams;
-import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer;
-import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams;
import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
-public class GUIAm2910InstrPLA extends GUIComponent
+public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
{
- private final Renderer renderer1;
- private final Renderer renderer2;
- private final Renderer renderer3;
-
public GUIAm2910InstrPLA(ViewModelModifiable model, String name)
{
- super(model, name);
+ super(model, name, "Instr.\nPLA");
setSize(30, 85);
- addPin(new Pin(this, "PASS", 1, 0, 5));
- addPin(new Pin(this, "I3", 1, 0, 20));
- addPin(new Pin(this, "I2", 1, 0, 30));
- addPin(new Pin(this, "I1", 1, 0, 40));
- addPin(new Pin(this, "I0", 1, 0, 50));
- addPin(new Pin(this, "R=0", 1, 15, 0));
- addPin(new Pin(this, "_PL", 1, 5, 85));
- addPin(new Pin(this, "_MAP", 1, 15, 85));
- addPin(new Pin(this, "_VECT", 1, 25, 85));
- addPin(new Pin(this, "RWE", 1, 30, 5));
- addPin(new Pin(this, "RDEC", 1, 30, 15));
- addPin(new Pin(this, "YD", 1, 30, 25));
- addPin(new Pin(this, "YR", 1, 30, 35));
- addPin(new Pin(this, "YF", 1, 30, 45));
- addPin(new Pin(this, "YmuPC", 1, 30, 55));
- addPin(new Pin(this, "STKI0", 1, 30, 65));
- addPin(new Pin(this, "STKI1", 1, 30, 75));
- this.renderer1 = new DefaultOutlineRenderer(this);
- CenteredTextParams renderer2Params = new CenteredTextParams();
- renderer2Params.text = "Instr.\nPLA";
- renderer2Params.fontHeight = 5;
- this.renderer2 = new CenteredTextSymbolRenderer(this, renderer2Params);
- PinNamesParams renderer3Params = new PinNamesParams();
- renderer3Params.pinLabelHeight = 3.5;
- renderer3Params.pinLabelMargin = .5;
- PinNamesSymbolRenderer pinNamesRenderer;
- this.renderer3 = pinNamesRenderer = new PinNamesSymbolRenderer(this, renderer3Params);
- pinNamesRenderer.setPinPosition("PASS", Position.RIGHT);
- pinNamesRenderer.setPinPosition("I3", Position.RIGHT);
- pinNamesRenderer.setPinPosition("I2", Position.RIGHT);
- pinNamesRenderer.setPinPosition("I1", Position.RIGHT);
- pinNamesRenderer.setPinPosition("I0", Position.RIGHT);
- pinNamesRenderer.setPinPosition("R=0", Position.BOTTOM);
- pinNamesRenderer.setPinPosition("_PL", Position.TOP);
- pinNamesRenderer.setPinPosition("_MAP", Position.TOP);
- pinNamesRenderer.setPinPosition("_VECT", Position.TOP);
- pinNamesRenderer.setPinPosition("RWE", Position.LEFT);
- pinNamesRenderer.setPinPosition("RDEC", Position.LEFT);
- pinNamesRenderer.setPinPosition("YD", Position.LEFT);
- pinNamesRenderer.setPinPosition("YR", Position.LEFT);
- pinNamesRenderer.setPinPosition("YF", Position.LEFT);
- pinNamesRenderer.setPinPosition("YmuPC", Position.LEFT);
- pinNamesRenderer.setPinPosition("STKI0", Position.LEFT);
- pinNamesRenderer.setPinPosition("STKI1", Position.LEFT);
+ addPin(new Pin(this, "PASS", 1, 0, 5), Usage.INPUT, Position.RIGHT);
+ addPin(new Pin(this, "I3", 1, 0, 20), Usage.INPUT, Position.RIGHT);
+ addPin(new Pin(this, "I2", 1, 0, 30), Usage.INPUT, Position.RIGHT);
+ addPin(new Pin(this, "I1", 1, 0, 40), Usage.INPUT, Position.RIGHT);
+ addPin(new Pin(this, "I0", 1, 0, 50), Usage.INPUT, Position.RIGHT);
+ addPin(new Pin(this, "R=0", 1, 15, 0), Usage.INPUT, Position.BOTTOM);
+ addPin(new Pin(this, "_PL", 1, 5, 85), Usage.OUTPUT, Position.TOP);
+ addPin(new Pin(this, "_MAP", 1, 15, 85), Usage.OUTPUT, Position.TOP);
+ addPin(new Pin(this, "_VECT", 1, 25, 85), Usage.OUTPUT, Position.TOP);
+ addPin(new Pin(this, "RWE", 1, 30, 5), Usage.OUTPUT, Position.LEFT);
+ addPin(new Pin(this, "RDEC", 1, 30, 15), Usage.OUTPUT, Position.LEFT);
+ addPin(new Pin(this, "YD", 1, 30, 25), Usage.OUTPUT, Position.LEFT);
+ addPin(new Pin(this, "YR", 1, 30, 35), Usage.OUTPUT, Position.LEFT);
+ addPin(new Pin(this, "YF", 1, 30, 45), Usage.OUTPUT, Position.LEFT);
+ addPin(new Pin(this, "YmuPC", 1, 30, 55), Usage.OUTPUT, Position.LEFT);
+ addPin(new Pin(this, "STKI0", 1, 30, 65), Usage.OUTPUT, Position.LEFT);
+ addPin(new Pin(this, "STKI1", 1, 30, 75), Usage.OUTPUT, Position.LEFT);
}
@Override
- public void render(GeneralGC gc, Rectangle visibleRegion)
+ protected void recalculate(Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
{
- renderer1.render(gc, visibleRegion);
- renderer2.render(gc, visibleRegion);
- renderer3.render(gc, visibleRegion);
- }
+ ReadEnd PASS = readEnds.get("PASS");
+ ReadEnd I3 = readEnds.get("I3");
+ ReadEnd I2 = readEnds.get("I2");
+ ReadEnd I1 = readEnds.get("I1");
+ ReadEnd I0 = readEnds.get("I0");
+ ReadEnd Req0 = readEnds.get("R=0");
+ ReadWriteEnd _PL = readWriteEnds.get("_PL");
+ ReadWriteEnd _MAP = readWriteEnds.get("_MAP");
+ ReadWriteEnd _VECT = readWriteEnds.get("_VECT");
+ ReadWriteEnd RWE = readWriteEnds.get("RWE");
+ ReadWriteEnd RDEC = readWriteEnds.get("RDEC");
+ ReadWriteEnd YD = readWriteEnds.get("YD");
+ ReadWriteEnd YR = readWriteEnds.get("YR");
+ ReadWriteEnd YF = readWriteEnds.get("YF");
+ ReadWriteEnd YmuPC = readWriteEnds.get("YmuPC");
+ ReadWriteEnd STKI0 = readWriteEnds.get("STKI0");
+ ReadWriteEnd STKI1 = readWriteEnds.get("STKI1");
- static
- {
- ViewLogicModelAdapter.addComponentAdapter(new Am2910InstrPLAAdapter());
+ Bit PASSVal = PASS.getValue();
+ Bit I3Val = I3.getValue();
+ Bit I2Val = I2.getValue();
+ Bit I1Val = I1.getValue();
+ Bit I0Val = I0.getValue();
+ Bit Req0Val = Req0.getValue();
+
+ if (!I3Val.isBinary() || !I2Val.isBinary() || !I1Val.isBinary() || !I0Val.isBinary())
+ if ((I3Val == U || I3Val.isBinary()) || (I2Val == U || I2Val.isBinary()) || (I1Val == U || I1Val.isBinary())
+ || (I0Val == U || I0Val.isBinary()))
+ {
+ _PL.feedSignals(U);
+ _MAP.feedSignals(U);
+ _VECT.feedSignals(U);
+ RWE.feedSignals(U);
+ RDEC.feedSignals(U);
+ YD.feedSignals(U);
+ YR.feedSignals(U);
+ YF.feedSignals(U);
+ YmuPC.feedSignals(U);
+ STKI0.feedSignals(U);
+ STKI1.feedSignals(U);
+ } else
+ {
+ _PL.feedSignals(X);
+ _MAP.feedSignals(X);
+ _VECT.feedSignals(X);
+ RWE.feedSignals(X);
+ RDEC.feedSignals(X);
+ YD.feedSignals(X);
+ YR.feedSignals(X);
+ YF.feedSignals(X);
+ YmuPC.feedSignals(X);
+ STKI0.feedSignals(X);
+ STKI1.feedSignals(X);
+ }
+ else
+ {
+ int I = (I3Val == ONE ? 8 : 0) + (I2Val == ONE ? 4 : 0) + (I1Val == ONE ? 2 : 0) + (I0Val == ONE ? 1 : 0);
+ Bit _PLVal = ONE;
+ Bit _MAPVal = ONE;
+ Bit _VECTVal = ONE;
+ if (I == 2)
+ _MAPVal = ZERO;
+ else if (I == 6)
+ _VECTVal = ZERO;
+ else
+ _PLVal = ZERO;
+ _PL.feedSignals(_PLVal);
+ _MAP.feedSignals(_MAPVal);
+ _VECT.feedSignals(_VECTVal);
+ if (I == 8 || I == 9 || I == 15)
+ {
+ RWE.feedSignals(Req0Val);
+ RDEC.feedSignals(Req0Val);// "forward" X/U/Z
+ } else if (I == 4)
+ {
+ RWE.feedSignals(PASSVal);
+ RDEC.feedSignals(PASSVal == ONE ? ZERO : PASSVal);// "forward" X/U/Z
+ } else
+ {
+ RWE.feedSignals(ZERO);
+ RDEC.feedSignals(ZERO);
+ }
+ if (!PASSVal.isBinary())
+ {
+ YD.feedSignals(PASSVal);// "forward" X/U/Z
+ YR.feedSignals(PASSVal);// "forward" X/U/Z
+ YF.feedSignals(PASSVal);// "forward" X/U/Z
+ YmuPC.feedSignals(PASSVal);// "forward" X/U/Z
+ } else
+ {
+ Bit YDVal = ZERO;
+ Bit YRVal = ZERO;
+ Bit YFVal = ZERO;
+ Bit YmuPCVal = ZERO;
+ switch (I + (PASSVal == ONE ? 16 : 0))
+ {
+ case 0:
+ case 0 + 16:
+ break;
+ case 2:
+ case 1 + 16:
+ case 2 + 16:
+ case 3 + 16:
+ case 5 + 16:
+ case 6 + 16:
+ case 7 + 16:
+ case 11 + 16:
+ YDVal = ONE;
+ break;
+ case 5:
+ case 7:
+ YRVal = ONE;
+ break;
+ case 13:
+ case 10 + 16:
+ YFVal = ONE;
+ break;
+ case 1:
+ case 3:
+ case 4:
+ case 6:
+ case 10:
+ case 11:
+ case 12:
+ case 14:
+ case 4 + 16:
+ case 12 + 16:
+ case 13 + 16:
+ case 14 + 16:
+ case 15 + 16:
+ YmuPCVal = ONE;
+ break;
+ case 8:
+ case 8 + 16:
+ YFVal = Req0Val.not();// "forward" X/U/Z
+ YmuPCVal = Req0Val;// "forward" X/U/Z
+ break;
+ case 9:
+ case 9 + 16:
+ YDVal = Req0Val.not();// "forward" X/U/Z
+ YmuPCVal = Req0Val;// "forward" X/U/Z
+ break;
+ case 15:
+ YFVal = Req0Val.not();// "forward" X/U/Z
+ YDVal = Req0Val;// "forward" X/U/Z
+ break;
+ default:
+ throw new IllegalStateException("shouldn't happen");
+ }
+ YD.feedSignals(YDVal);
+ YR.feedSignals(YRVal);
+ YF.feedSignals(YFVal);
+ YmuPC.feedSignals(YmuPCVal);
+ Bit STKI0Val;
+ Bit STKI1Val;
+ switch (I + (PASSVal == ONE ? 16 : 0))
+ {
+ case 1:
+ case 2:
+ case 3:
+ case 6:
+ case 7:
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ case 14:
+ case 2 + 16:
+ case 3 + 16:
+ case 6 + 16:
+ case 7 + 16:
+ case 9 + 16:
+ case 12 + 16:
+ case 14 + 16:
+ STKI1Val = ZERO;
+ STKI0Val = ZERO;
+ break;
+ case 4:
+ case 5:
+ case 1 + 16:
+ case 4 + 16:
+ case 5 + 16:
+ STKI1Val = ZERO;
+ STKI0Val = ONE;
+ break;
+ case 0:
+ case 0 + 16:
+ STKI1Val = ONE;
+ STKI0Val = ZERO;
+ break;
+ case 10 + 16:
+ case 11 + 16:
+ case 13 + 16:
+ case 15 + 16:
+ STKI1Val = ONE;
+ STKI0Val = ONE;
+ break;
+ case 8:
+ case 15:
+ case 8 + 16:
+ STKI1Val = Req0Val;// "forward" X/U/Z
+ STKI0Val = Req0Val;// "forward" X/U/Z
+ break;
+ default:
+ throw new IllegalStateException("shouldn't happen");
+ }
+ STKI0.feedSignals(STKI0Val);
+ STKI1.feedSignals(STKI1Val);
+ }
+ }
}
}
\ No newline at end of file
+++ /dev/null
-package net.mograsim.logic.model.modeladapter.componentadapters;
-
-import static net.mograsim.logic.core.types.Bit.ONE;
-import static net.mograsim.logic.core.types.Bit.U;
-import static net.mograsim.logic.core.types.Bit.X;
-import static net.mograsim.logic.core.types.Bit.ZERO;
-
-import java.util.Map;
-
-import net.mograsim.logic.core.LogicObserver;
-import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.core.types.Bit;
-import net.mograsim.logic.core.wires.Wire;
-import net.mograsim.logic.core.wires.Wire.ReadEnd;
-import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
-import net.mograsim.logic.model.am2900.components.am2910.GUIAm2910InstrPLA;
-import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.modeladapter.LogicModelParameters;
-
-public class Am2910InstrPLAAdapter implements ComponentAdapter<GUIAm2910InstrPLA>
-{
- @Override
- public Class<GUIAm2910InstrPLA> getSupportedClass()
- {
- return GUIAm2910InstrPLA.class;
- }
-
- @Override
- public void createAndLinkComponent(Timeline timeline, LogicModelParameters params, GUIAm2910InstrPLA guiComponent,
- Map<Pin, Wire> logicWiresPerPin)
- {
- ReadEnd PASS = logicWiresPerPin.get(guiComponent.getPin("PASS")).createReadOnlyEnd();
- ReadEnd I3 = logicWiresPerPin.get(guiComponent.getPin("I3")).createReadOnlyEnd();
- ReadEnd I2 = logicWiresPerPin.get(guiComponent.getPin("I2")).createReadOnlyEnd();
- ReadEnd I1 = logicWiresPerPin.get(guiComponent.getPin("I1")).createReadOnlyEnd();
- ReadEnd I0 = logicWiresPerPin.get(guiComponent.getPin("I0")).createReadOnlyEnd();
- ReadEnd Req0 = logicWiresPerPin.get(guiComponent.getPin("R=0")).createReadOnlyEnd();
- ReadWriteEnd _PL = logicWiresPerPin.get(guiComponent.getPin("_PL")).createReadWriteEnd();
- ReadWriteEnd _MAP = logicWiresPerPin.get(guiComponent.getPin("_MAP")).createReadWriteEnd();
- ReadWriteEnd _VECT = logicWiresPerPin.get(guiComponent.getPin("_VECT")).createReadWriteEnd();
- ReadWriteEnd RWE = logicWiresPerPin.get(guiComponent.getPin("RWE")).createReadWriteEnd();
- ReadWriteEnd RDEC = logicWiresPerPin.get(guiComponent.getPin("RDEC")).createReadWriteEnd();
- ReadWriteEnd YD = logicWiresPerPin.get(guiComponent.getPin("YD")).createReadWriteEnd();
- ReadWriteEnd YR = logicWiresPerPin.get(guiComponent.getPin("YR")).createReadWriteEnd();
- ReadWriteEnd YF = logicWiresPerPin.get(guiComponent.getPin("YF")).createReadWriteEnd();
- ReadWriteEnd YmuPC = logicWiresPerPin.get(guiComponent.getPin("YmuPC")).createReadWriteEnd();
- ReadWriteEnd STKI0 = logicWiresPerPin.get(guiComponent.getPin("STKI0")).createReadWriteEnd();
- ReadWriteEnd STKI1 = logicWiresPerPin.get(guiComponent.getPin("STKI1")).createReadWriteEnd();
-
- LogicObserver updateOutputs = o ->
- {
- Bit PASSVal = PASS.getValue();
- Bit I3Val = I3.getValue();
- Bit I2Val = I2.getValue();
- Bit I1Val = I1.getValue();
- Bit I0Val = I0.getValue();
- Bit Req0Val = Req0.getValue();
-
- if (!I3Val.isBinary() || !I2Val.isBinary() || !I1Val.isBinary() || !I0Val.isBinary())
- if ((I3Val == U || I3Val.isBinary()) || (I2Val == U || I2Val.isBinary()) || (I1Val == U || I1Val.isBinary())
- || (I0Val == U || I0Val.isBinary()))
- {
- _PL.feedSignals(U);
- _MAP.feedSignals(U);
- _VECT.feedSignals(U);
- RWE.feedSignals(U);
- RDEC.feedSignals(U);
- YD.feedSignals(U);
- YR.feedSignals(U);
- YF.feedSignals(U);
- YmuPC.feedSignals(U);
- STKI0.feedSignals(U);
- STKI1.feedSignals(U);
- } else
- {
- _PL.feedSignals(X);
- _MAP.feedSignals(X);
- _VECT.feedSignals(X);
- RWE.feedSignals(X);
- RDEC.feedSignals(X);
- YD.feedSignals(X);
- YR.feedSignals(X);
- YF.feedSignals(X);
- YmuPC.feedSignals(X);
- STKI0.feedSignals(X);
- STKI1.feedSignals(X);
- }
- else
- {
- int I = (I3Val == ONE ? 8 : 0) + (I2Val == ONE ? 4 : 0) + (I1Val == ONE ? 2 : 0) + (I0Val == ONE ? 1 : 0);
- Bit _PLVal = ONE;
- Bit _MAPVal = ONE;
- Bit _VECTVal = ONE;
- if (I == 2)
- _MAPVal = ZERO;
- else if (I == 6)
- _VECTVal = ZERO;
- else
- _PLVal = ZERO;
- _PL.feedSignals(_PLVal);
- _MAP.feedSignals(_MAPVal);
- _VECT.feedSignals(_VECTVal);
- if (I == 8 || I == 9 || I == 15)
- {
- RWE.feedSignals(Req0Val);
- RDEC.feedSignals(Req0Val);// "forward" X/U/Z
- } else if (I == 4)
- {
- RWE.feedSignals(PASSVal);
- RDEC.feedSignals(PASSVal == ONE ? ZERO : PASSVal);// "forward" X/U/Z
- } else
- {
- RWE.feedSignals(ZERO);
- RDEC.feedSignals(ZERO);
- }
- if (!PASSVal.isBinary())
- {
- YD.feedSignals(PASSVal);// "forward" X/U/Z
- YR.feedSignals(PASSVal);// "forward" X/U/Z
- YF.feedSignals(PASSVal);// "forward" X/U/Z
- YmuPC.feedSignals(PASSVal);// "forward" X/U/Z
- } else
- {
- Bit YDVal = ZERO;
- Bit YRVal = ZERO;
- Bit YFVal = ZERO;
- Bit YmuPCVal = ZERO;
- switch (I + (PASSVal == ONE ? 16 : 0))
- {
- case 0:
- case 0 + 16:
- break;
- case 2:
- case 1 + 16:
- case 2 + 16:
- case 3 + 16:
- case 5 + 16:
- case 6 + 16:
- case 7 + 16:
- case 11 + 16:
- YDVal = ONE;
- break;
- case 5:
- case 7:
- YRVal = ONE;
- break;
- case 13:
- case 10 + 16:
- YFVal = ONE;
- break;
- case 1:
- case 3:
- case 4:
- case 6:
- case 10:
- case 11:
- case 12:
- case 14:
- case 4 + 16:
- case 12 + 16:
- case 13 + 16:
- case 14 + 16:
- case 15 + 16:
- YmuPCVal = ONE;
- break;
- case 8:
- case 8 + 16:
- YFVal = Req0Val.not();// "forward" X/U/Z
- YmuPCVal = Req0Val;// "forward" X/U/Z
- break;
- case 9:
- case 9 + 16:
- YDVal = Req0Val.not();// "forward" X/U/Z
- YmuPCVal = Req0Val;// "forward" X/U/Z
- break;
- case 15:
- YFVal = Req0Val.not();// "forward" X/U/Z
- YDVal = Req0Val;// "forward" X/U/Z
- break;
- default:
- throw new IllegalStateException("shouldn't happen");
- }
- YD.feedSignals(YDVal);
- YR.feedSignals(YRVal);
- YF.feedSignals(YFVal);
- YmuPC.feedSignals(YmuPCVal);
- Bit STKI0Val;
- Bit STKI1Val;
- switch (I + (PASSVal == ONE ? 16 : 0))
- {
- case 1:
- case 2:
- case 3:
- case 6:
- case 7:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 2 + 16:
- case 3 + 16:
- case 6 + 16:
- case 7 + 16:
- case 9 + 16:
- case 12 + 16:
- case 14 + 16:
- STKI1Val = ZERO;
- STKI0Val = ZERO;
- break;
- case 4:
- case 5:
- case 1 + 16:
- case 4 + 16:
- case 5 + 16:
- STKI1Val = ZERO;
- STKI0Val = ONE;
- break;
- case 0:
- case 0 + 16:
- STKI1Val = ONE;
- STKI0Val = ZERO;
- break;
- case 10 + 16:
- case 11 + 16:
- case 13 + 16:
- case 15 + 16:
- STKI1Val = ONE;
- STKI0Val = ONE;
- break;
- case 8:
- case 15:
- case 8 + 16:
- STKI1Val = Req0Val;// "forward" X/U/Z
- STKI0Val = Req0Val;// "forward" X/U/Z
- break;
- default:
- throw new IllegalStateException("shouldn't happen");
- }
- STKI0.feedSignals(STKI0Val);
- STKI1.feedSignals(STKI1Val);
- }
- }
- };
-
- PASS.registerObserver(updateOutputs);
- I3.registerObserver(updateOutputs);
- I2.registerObserver(updateOutputs);
- I1.registerObserver(updateOutputs);
- I0.registerObserver(updateOutputs);
- Req0.registerObserver(updateOutputs);
- }
-}
\ No newline at end of file
--- /dev/null
+package net.mograsim.logic.model.model.components.atomic;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.haspamelodica.swt.helper.gcs.GeneralGC;
+import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
+import net.mograsim.logic.core.wires.Wire.ReadEnd;
+import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
+import net.mograsim.logic.model.model.ViewModelModifiable;
+import net.mograsim.logic.model.model.components.GUIComponent;
+import net.mograsim.logic.model.model.wires.Pin;
+import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter;
+import net.mograsim.logic.model.modeladapter.componentadapters.SimpleRectangularHardcodedGUIComponentAdapter;
+import net.mograsim.logic.model.snippets.outlinerenderers.DefaultOutlineRenderer;
+import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer;
+import net.mograsim.logic.model.snippets.symbolrenderers.CenteredTextSymbolRenderer.CenteredTextParams;
+import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer;
+import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams;
+import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
+
+public abstract class SimpleRectangularHardcodedGUIComponent extends GUIComponent
+{
+ private static final double centerTextHeight = 5;
+ private static final double pinNamesHeight = 3.5;
+ private static final double pinNamesMargin = .5;
+
+ // TODO maybe make this more general?
+ private final Map<Pin, Usage> pinUsages;
+
+ private final DefaultOutlineRenderer outlineRenderer;
+ private final CenteredTextSymbolRenderer centerTextRenderer;
+ private final PinNamesSymbolRenderer pinNamesRenderer;
+
+ // creation and destruction
+
+ public SimpleRectangularHardcodedGUIComponent(ViewModelModifiable model, String name, String centerText)
+ {
+ super(model, name);
+ pinUsages = new HashMap<>();
+ this.outlineRenderer = new DefaultOutlineRenderer(this);
+ CenteredTextParams centeredTextParams = new CenteredTextParams();
+ centeredTextParams.text = centerText;
+ centeredTextParams.fontHeight = centerTextHeight;
+ this.centerTextRenderer = new CenteredTextSymbolRenderer(this, centeredTextParams);
+ PinNamesParams pinNamesParams = new PinNamesParams();
+ pinNamesParams.pinLabelHeight = pinNamesHeight;
+ pinNamesParams.pinLabelMargin = pinNamesMargin;
+ this.pinNamesRenderer = new PinNamesSymbolRenderer(this, pinNamesParams);
+ addPinRemovedListener(this::pinRemoved);
+ }
+
+ // pins
+
+ protected void addPin(Pin pin, Usage usage, Position namePosition)
+ {
+ super.addPin(pin); // do this first to catch errors
+ pinUsages.put(pin, usage);
+ pinNamesRenderer.setPinPosition(pin, namePosition);
+ }
+
+ private void pinRemoved(Pin pin)
+ {
+ pinUsages.remove(pin);
+ pinNamesRenderer.setPinPosition(pin, null);
+ }
+
+ public Usage getPinUsage(Pin pin)
+ {
+ return pinUsages.get(pin);
+ }
+
+ // logic
+
+ protected abstract void recalculate(Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds);
+
+ // "graphical" operations
+
+ @Override
+ public void render(GeneralGC gc, Rectangle visibleRegion)
+ {
+ outlineRenderer.render(gc, visibleRegion);
+ centerTextRenderer.render(gc, visibleRegion);
+ pinNamesRenderer.render(gc, visibleRegion);
+ }
+
+ // operations no longer supported
+
+ @Override
+ protected void addPin(Pin pin)
+ {
+ throw new UnsupportedOperationException("Can't add pins without setting usage, call addPin(Pin, Usage [, Position]) instead");
+ }
+
+ public static enum Usage
+ {
+ INPUT, OUTPUT, TRISTATE;
+ }
+
+ static
+ {
+ ViewLogicModelAdapter.addComponentAdapter(new SimpleRectangularHardcodedGUIComponentAdapter(c -> c::recalculate));
+ }
+}
\ No newline at end of file