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