Made Am2910 components usable in Editor
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / components / am2910 / GUIAm2910InstrPLA.java
1 package net.mograsim.logic.model.am2900.components.am2910;
2
3 import static net.mograsim.logic.core.types.Bit.ONE;
4 import static net.mograsim.logic.core.types.Bit.U;
5 import static net.mograsim.logic.core.types.Bit.X;
6 import static net.mograsim.logic.core.types.Bit.ZERO;
7
8 import java.util.Map;
9
10 import net.mograsim.logic.core.types.Bit;
11 import net.mograsim.logic.core.wires.Wire.ReadEnd;
12 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
13 import net.mograsim.logic.model.model.ViewModelModifiable;
14 import net.mograsim.logic.model.model.components.atomic.SimpleRectangularHardcodedGUIComponent;
15 import net.mograsim.logic.model.model.wires.Pin;
16 import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator;
17 import net.mograsim.logic.model.snippets.symbolrenderers.PinNamesSymbolRenderer.PinNamesParams.Position;
18
19 public class GUIAm2910InstrPLA extends SimpleRectangularHardcodedGUIComponent
20 {
21         public GUIAm2910InstrPLA(ViewModelModifiable model, String name)
22         {
23                 super(model, name, "Instr.\nPLA");
24                 setSize(30, 85);
25                 addPin(new Pin(this, "PASS", 1, 0, 5), Usage.INPUT, Position.RIGHT);
26                 addPin(new Pin(this, "I3", 1, 0, 20), Usage.INPUT, Position.RIGHT);
27                 addPin(new Pin(this, "I2", 1, 0, 30), Usage.INPUT, Position.RIGHT);
28                 addPin(new Pin(this, "I1", 1, 0, 40), Usage.INPUT, Position.RIGHT);
29                 addPin(new Pin(this, "I0", 1, 0, 50), Usage.INPUT, Position.RIGHT);
30                 addPin(new Pin(this, "R=0", 1, 15, 0), Usage.INPUT, Position.BOTTOM);
31                 addPin(new Pin(this, "_PL", 1, 5, 85), Usage.OUTPUT, Position.TOP);
32                 addPin(new Pin(this, "_MAP", 1, 15, 85), Usage.OUTPUT, Position.TOP);
33                 addPin(new Pin(this, "_VECT", 1, 25, 85), Usage.OUTPUT, Position.TOP);
34                 addPin(new Pin(this, "RWE", 1, 30, 5), Usage.OUTPUT, Position.LEFT);
35                 addPin(new Pin(this, "RDEC", 1, 30, 15), Usage.OUTPUT, Position.LEFT);
36                 addPin(new Pin(this, "YD", 1, 30, 25), Usage.OUTPUT, Position.LEFT);
37                 addPin(new Pin(this, "YR", 1, 30, 35), Usage.OUTPUT, Position.LEFT);
38                 addPin(new Pin(this, "YF", 1, 30, 45), Usage.OUTPUT, Position.LEFT);
39                 addPin(new Pin(this, "YmuPC", 1, 30, 55), Usage.OUTPUT, Position.LEFT);
40                 addPin(new Pin(this, "STKI0", 1, 30, 65), Usage.OUTPUT, Position.LEFT);
41                 addPin(new Pin(this, "STKI1", 1, 30, 75), Usage.OUTPUT, Position.LEFT);
42         }
43
44         @Override
45         protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
46         {
47                 ReadEnd PASS = readEnds.get("PASS");
48                 ReadEnd I3 = readEnds.get("I3");
49                 ReadEnd I2 = readEnds.get("I2");
50                 ReadEnd I1 = readEnds.get("I1");
51                 ReadEnd I0 = readEnds.get("I0");
52                 ReadEnd Req0 = readEnds.get("R=0");
53                 ReadWriteEnd _PL = readWriteEnds.get("_PL");
54                 ReadWriteEnd _MAP = readWriteEnds.get("_MAP");
55                 ReadWriteEnd _VECT = readWriteEnds.get("_VECT");
56                 ReadWriteEnd RWE = readWriteEnds.get("RWE");
57                 ReadWriteEnd RDEC = readWriteEnds.get("RDEC");
58                 ReadWriteEnd YD = readWriteEnds.get("YD");
59                 ReadWriteEnd YR = readWriteEnds.get("YR");
60                 ReadWriteEnd YF = readWriteEnds.get("YF");
61                 ReadWriteEnd YmuPC = readWriteEnds.get("YmuPC");
62                 ReadWriteEnd STKI0 = readWriteEnds.get("STKI0");
63                 ReadWriteEnd STKI1 = readWriteEnds.get("STKI1");
64
65                 Bit PASSVal = PASS.getValue();
66                 Bit I3Val = I3.getValue();
67                 Bit I2Val = I2.getValue();
68                 Bit I1Val = I1.getValue();
69                 Bit I0Val = I0.getValue();
70                 Bit Req0Val = Req0.getValue();
71
72                 if (!I3Val.isBinary() || !I2Val.isBinary() || !I1Val.isBinary() || !I0Val.isBinary())
73                         if ((I3Val == U || I3Val.isBinary()) || (I2Val == U || I2Val.isBinary()) || (I1Val == U || I1Val.isBinary())
74                                         || (I0Val == U || I0Val.isBinary()))
75                         {
76                                 _PL.feedSignals(U);
77                                 _MAP.feedSignals(U);
78                                 _VECT.feedSignals(U);
79                                 RWE.feedSignals(U);
80                                 RDEC.feedSignals(U);
81                                 YD.feedSignals(U);
82                                 YR.feedSignals(U);
83                                 YF.feedSignals(U);
84                                 YmuPC.feedSignals(U);
85                                 STKI0.feedSignals(U);
86                                 STKI1.feedSignals(U);
87                         } else
88                         {
89                                 _PL.feedSignals(X);
90                                 _MAP.feedSignals(X);
91                                 _VECT.feedSignals(X);
92                                 RWE.feedSignals(X);
93                                 RDEC.feedSignals(X);
94                                 YD.feedSignals(X);
95                                 YR.feedSignals(X);
96                                 YF.feedSignals(X);
97                                 YmuPC.feedSignals(X);
98                                 STKI0.feedSignals(X);
99                                 STKI1.feedSignals(X);
100                         }
101                 else
102                 {
103                         int I = (I3Val == ONE ? 8 : 0) + (I2Val == ONE ? 4 : 0) + (I1Val == ONE ? 2 : 0) + (I0Val == ONE ? 1 : 0);
104                         Bit _PLVal = ONE;
105                         Bit _MAPVal = ONE;
106                         Bit _VECTVal = ONE;
107                         if (I == 2)
108                                 _MAPVal = ZERO;
109                         else if (I == 6)
110                                 _VECTVal = ZERO;
111                         else
112                                 _PLVal = ZERO;
113                         _PL.feedSignals(_PLVal);
114                         _MAP.feedSignals(_MAPVal);
115                         _VECT.feedSignals(_VECTVal);
116                         if (I == 8 || I == 9 || I == 15)
117                         {
118                                 RWE.feedSignals(Req0Val);
119                                 RDEC.feedSignals(Req0Val);// "forward" X/U/Z
120                         } else if (I == 4)
121                         {
122                                 RWE.feedSignals(PASSVal);
123                                 RDEC.feedSignals(PASSVal == ONE ? ZERO : PASSVal);// "forward" X/U/Z
124                         } else
125                         {
126                                 RWE.feedSignals(ZERO);
127                                 RDEC.feedSignals(ZERO);
128                         }
129                         if (!PASSVal.isBinary())
130                         {
131                                 YD.feedSignals(PASSVal);// "forward" X/U/Z
132                                 YR.feedSignals(PASSVal);// "forward" X/U/Z
133                                 YF.feedSignals(PASSVal);// "forward" X/U/Z
134                                 YmuPC.feedSignals(PASSVal);// "forward" X/U/Z
135                         } else
136                         {
137                                 Bit YDVal = ZERO;
138                                 Bit YRVal = ZERO;
139                                 Bit YFVal = ZERO;
140                                 Bit YmuPCVal = ZERO;
141                                 switch (I + (PASSVal == ONE ? 16 : 0))
142                                 {
143                                 case 0:
144                                 case 0 + 16:
145                                         break;
146                                 case 2:
147                                 case 1 + 16:
148                                 case 2 + 16:
149                                 case 3 + 16:
150                                 case 5 + 16:
151                                 case 6 + 16:
152                                 case 7 + 16:
153                                 case 11 + 16:
154                                         YDVal = ONE;
155                                         break;
156                                 case 5:
157                                 case 7:
158                                         YRVal = ONE;
159                                         break;
160                                 case 13:
161                                 case 10 + 16:
162                                         YFVal = ONE;
163                                         break;
164                                 case 1:
165                                 case 3:
166                                 case 4:
167                                 case 6:
168                                 case 10:
169                                 case 11:
170                                 case 12:
171                                 case 14:
172                                 case 4 + 16:
173                                 case 12 + 16:
174                                 case 13 + 16:
175                                 case 14 + 16:
176                                 case 15 + 16:
177                                         YmuPCVal = ONE;
178                                         break;
179                                 case 8:
180                                 case 8 + 16:
181                                         YFVal = Req0Val.not();// "forward" X/U/Z
182                                         YmuPCVal = Req0Val;// "forward" X/U/Z
183                                         break;
184                                 case 9:
185                                 case 9 + 16:
186                                         YDVal = Req0Val.not();// "forward" X/U/Z
187                                         YmuPCVal = Req0Val;// "forward" X/U/Z
188                                         break;
189                                 case 15:
190                                         YFVal = Req0Val.not();// "forward" X/U/Z
191                                         YDVal = Req0Val;// "forward" X/U/Z
192                                         break;
193                                 default:
194                                         throw new IllegalStateException("shouldn't happen");
195                                 }
196                                 YD.feedSignals(YDVal);
197                                 YR.feedSignals(YRVal);
198                                 YF.feedSignals(YFVal);
199                                 YmuPC.feedSignals(YmuPCVal);
200                                 Bit STKI0Val;
201                                 Bit STKI1Val;
202                                 switch (I + (PASSVal == ONE ? 16 : 0))
203                                 {
204                                 case 1:
205                                 case 2:
206                                 case 3:
207                                 case 6:
208                                 case 7:
209                                 case 9:
210                                 case 10:
211                                 case 11:
212                                 case 12:
213                                 case 13:
214                                 case 14:
215                                 case 2 + 16:
216                                 case 3 + 16:
217                                 case 6 + 16:
218                                 case 7 + 16:
219                                 case 9 + 16:
220                                 case 12 + 16:
221                                 case 14 + 16:
222                                         // HOLD
223                                         STKI1Val = ZERO;
224                                         STKI0Val = ZERO;
225                                         break;
226                                 case 4:
227                                 case 5:
228                                 case 1 + 16:
229                                 case 4 + 16:
230                                 case 5 + 16:
231                                         // PUSH
232                                         STKI1Val = ZERO;
233                                         STKI0Val = ONE;
234                                         break;
235                                 case 0:
236                                 case 0 + 16:
237                                         // CLEAR
238                                         STKI1Val = ONE;
239                                         STKI0Val = ZERO;
240                                         break;
241                                 case 10 + 16:
242                                 case 11 + 16:
243                                 case 13 + 16:
244                                 case 15 + 16:
245                                         // POP
246                                         STKI1Val = ONE;
247                                         STKI0Val = ONE;
248                                         break;
249                                 case 8:
250                                 case 15:
251                                 case 8 + 16:
252                                         STKI1Val = Req0Val;// "forward" X/U/Z
253                                         STKI0Val = Req0Val;// "forward" X/U/Z
254                                         break;
255                                 default:
256                                         throw new IllegalStateException("shouldn't happen");
257                                 }
258                                 STKI0.feedSignals(STKI0Val);
259                                 STKI1.feedSignals(STKI1Val);
260                         }
261                 }
262                 return null;
263         }
264
265         static
266         {
267                 IndirectGUIComponentCreator.setComponentSupplier(GUIAm2910InstrPLA.class.getCanonicalName(),
268                                 (m, p, n) -> new GUIAm2910InstrPLA(m, n));
269         }
270 }