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