GUIAm2904ShiftInstrDecode now outputs X for Don't Care instead of Z
[Mograsim.git] / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / components / am2904 / GUIAm2904ShiftInstrDecode.java
1 package net.mograsim.logic.model.am2900.components.am2904;
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 GUIAm2904ShiftInstrDecode extends SimpleRectangularHardcodedGUIComponent
20 {
21         public GUIAm2904ShiftInstrDecode(ViewModelModifiable model, String name)
22         {
23                 super(model, name, "Shift \ninstruction\ndecode");
24                 setSize(60, 70);
25                 addPin(new Pin(this, "I", 5, 0, 35), Usage.INPUT, Position.RIGHT);
26                 // SIO0 MUX:
27                 // 000: 0
28                 // 001: 1
29                 // 01x: SIOn
30                 // 10x: QIOn
31                 // 11x: MC
32                 addPin(new Pin(this, "SIO0_MUX", 3, 60, 5), Usage.OUTPUT, Position.LEFT);
33                 // SIOn MUX:
34                 // 000: 0
35                 // 001: 1
36                 // 010: SIO0
37                 // 011: QIO0
38                 // 100: MC
39                 // 101: MN
40                 // 110: IC
41                 // 111: IN xor IVOR
42                 addPin(new Pin(this, "SIOn_MUX", 3, 60, 15), Usage.OUTPUT, Position.LEFT);
43                 // QIO0 MUX:
44                 // 000: 0
45                 // 001: 1
46                 // 01x: SIOn
47                 // 10x: QIOn
48                 // 11x: MC
49                 addPin(new Pin(this, "QIO0_MUX", 3, 60, 25), Usage.OUTPUT, Position.LEFT);
50                 // QIOn MUX:
51                 // 000: 0
52                 // 001: 1
53                 // 01x: SIO0
54                 // 10x: QIO0
55                 // 11x: MN
56                 addPin(new Pin(this, "QIOn_MUX", 3, 60, 35), Usage.OUTPUT, Position.LEFT);
57                 addPin(new Pin(this, "LSHIFT", 1, 60, 45), Usage.OUTPUT, Position.LEFT);
58                 // 00: SIO0
59                 // 01: QIO0
60                 // 1x: SIOn
61                 addPin(new Pin(this, "MC_MUX", 2, 60, 55), Usage.OUTPUT, Position.LEFT);
62                 addPin(new Pin(this, "MC_EN", 1, 60, 65), Usage.OUTPUT, Position.LEFT);
63         }
64
65         @Override
66         protected Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
67         {
68                 Bit[] IBits = readEnds.get("I").getValues().getBits();
69                 readWriteEnds.get("LSHIFT").feedSignals(IBits[0]);
70                 // TODO move the following loop to BitVector.
71                 int IAsInt = 0;
72                 for (int i = 0; i < 5; i++)
73                         switch (IBits[4 - i])
74                         {
75                         case ONE:
76                                 IAsInt |= 1 << i;
77                                 break;
78                         case U:
79                                 readWriteEnds.get("SIO0_MUX").feedSignals(U, U, U);
80                                 readWriteEnds.get("SIOn_MUX").feedSignals(U, U, U);
81                                 readWriteEnds.get("QIO0_MUX").feedSignals(U, U, U);
82                                 readWriteEnds.get("QIOn_MUX").feedSignals(U, U, U);
83                                 readWriteEnds.get("MC_MUX").feedSignals(U, U);
84                                 readWriteEnds.get("MC_EN").feedSignals(U);
85                                 return null;
86                         case X:
87                         case Z:
88                                 readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);
89                                 readWriteEnds.get("SIOn_MUX").feedSignals(X, X, X);
90                                 readWriteEnds.get("QIO0_MUX").feedSignals(X, X, X);
91                                 readWriteEnds.get("QIOn_MUX").feedSignals(X, X, X);
92                                 readWriteEnds.get("MC_MUX").feedSignals(X, X);
93                                 readWriteEnds.get("MC_EN").feedSignals(X);
94                                 return null;
95                         case ZERO:
96                                 break;
97                         default:
98                                 throw new IllegalArgumentException("Unknown enum constant: " + IBits[i]);
99                         }
100                 if (IAsInt < 16)
101                 {
102                         readWriteEnds.get("SIO0_MUX").feedSignals(X, X, X);
103                         readWriteEnds.get("QIO0_MUX").feedSignals(X, X, X);
104                         switch (IAsInt)
105                         {
106                         case 0:
107                         case 2:
108                         case 6:
109                         case 7:
110                                 readWriteEnds.get("SIOn_MUX").feedSignals(ZERO, ZERO, ZERO);
111                                 break;
112                         case 1:
113                         case 3:
114                                 readWriteEnds.get("SIOn_MUX").feedSignals(ZERO, ZERO, ONE);
115                                 break;
116                         case 4:
117                         case 9:
118                         case 12:
119                                 readWriteEnds.get("SIOn_MUX").feedSignals(ONE, ZERO, ZERO);
120                                 break;
121                         case 5:
122                                 readWriteEnds.get("SIOn_MUX").feedSignals(ONE, ZERO, ONE);
123                                 break;
124                         case 8:
125                         case 10:
126                                 readWriteEnds.get("SIOn_MUX").feedSignals(ZERO, ONE, ZERO);
127                                 break;
128                         case 11:
129                                 readWriteEnds.get("SIOn_MUX").feedSignals(ONE, ONE, ZERO);
130                                 break;
131                         case 13:
132                         case 15:
133                                 readWriteEnds.get("SIOn_MUX").feedSignals(ZERO, ONE, ONE);
134                                 break;
135                         case 14:
136                                 readWriteEnds.get("SIOn_MUX").feedSignals(ONE, ONE, ONE);
137                                 break;
138                         default:
139                                 throw new IllegalStateException("can't happen");
140                         }
141                         switch (IAsInt)
142                         {
143                         case 0:
144                                 readWriteEnds.get("QIOn_MUX").feedSignals(ZERO, ZERO, ZERO);
145                                 break;
146                         case 1:
147                                 readWriteEnds.get("QIOn_MUX").feedSignals(ZERO, ZERO, ONE);
148                                 break;
149                         case 2:
150                                 readWriteEnds.get("QIOn_MUX").feedSignals(ONE, ONE, X);
151                                 break;
152                         case 3:
153                         case 4:
154                         case 5:
155                         case 6:
156                         case 7:
157                         case 11:
158                         case 12:
159                         case 13:
160                         case 14:
161                         case 15:
162                                 readWriteEnds.get("QIOn_MUX").feedSignals(ZERO, ONE, X);
163                                 break;
164                         case 8:
165                         case 9:
166                         case 10:
167                                 readWriteEnds.get("QIOn_MUX").feedSignals(ONE, ZERO, X);
168                                 break;
169                         default:
170                                 throw new IllegalStateException("can't happen");
171                         }
172                 } else
173                 {
174                         readWriteEnds.get("SIOn_MUX").feedSignals(X, X, X);
175                         readWriteEnds.get("QIOn_MUX").feedSignals(X, X, X);
176                         switch (IAsInt)
177                         {
178                         case 16:
179                         case 18:
180                                 readWriteEnds.get("SIO0_MUX").feedSignals(ZERO, ZERO, ZERO);
181                                 break;
182                         case 17:
183                         case 19:
184                                 readWriteEnds.get("SIO0_MUX").feedSignals(ZERO, ZERO, ONE);
185                                 break;
186                         case 20:
187                         case 21:
188                         case 22:
189                         case 23:
190                         case 28:
191                         case 29:
192                         case 30:
193                         case 31:
194                                 readWriteEnds.get("SIO0_MUX").feedSignals(ONE, ZERO, X);
195                                 break;
196                         case 24:
197                         case 26:
198                                 readWriteEnds.get("SIO0_MUX").feedSignals(ONE, ONE, X);
199                                 break;
200                         case 25:
201                         case 27:
202                                 readWriteEnds.get("SIO0_MUX").feedSignals(ZERO, ONE, X);
203                                 break;
204                         default:
205                                 throw new IllegalStateException("can't happen");
206                         }
207                         switch (IAsInt)
208                         {
209                         case 16:
210                         case 18:
211                         case 20:
212                         case 22:
213                         case 27:
214                                 readWriteEnds.get("QIO0_MUX").feedSignals(ZERO, ZERO, ZERO);
215                                 break;
216                         case 17:
217                         case 19:
218                         case 21:
219                         case 23:
220                                 readWriteEnds.get("QIO0_MUX").feedSignals(ZERO, ZERO, ONE);
221                                 break;
222                         case 24:
223                         case 25:
224                         case 26:
225                                 readWriteEnds.get("SIO0_MUX").feedSignals(ONE, ZERO, X);
226                                 break;
227                         case 28:
228                         case 30:
229                                 readWriteEnds.get("SIO0_MUX").feedSignals(ONE, ONE, X);
230                                 break;
231                         case 29:
232                         case 31:
233                                 readWriteEnds.get("QIO0_MUX").feedSignals(ZERO, ONE, X);
234                                 break;
235                         default:
236                                 throw new IllegalStateException("can't happen");
237                         }
238                 }
239                 // MC
240                 switch (IAsInt)
241                 {
242                 case 0:
243                 case 1:
244                 case 3:
245                 case 4:
246                 case 5:
247                 case 6:
248                 case 10:
249                 case 11:
250                 case 14:
251                 case 15:
252                 case 18:
253                 case 19:
254                 case 22:
255                 case 23:
256                 case 26:
257                 case 27:
258                 case 30:
259                 case 31:
260                         readWriteEnds.get("MC_EN").feedSignals(ZERO);
261                         readWriteEnds.get("MC_MUX").feedSignals(X, X);
262                         break;
263                 case 2:
264                 case 8:
265                 case 9:
266                         readWriteEnds.get("MC_EN").feedSignals(ONE);
267                         readWriteEnds.get("MC_MUX").feedSignals(ZERO, ZERO);
268                         break;
269                 case 7:
270                 case 12:
271                 case 13:
272                         readWriteEnds.get("MC_EN").feedSignals(ONE);
273                         readWriteEnds.get("MC_MUX").feedSignals(ZERO, ONE);
274                         break;
275                 case 16:
276                 case 17:
277                 case 20:
278                 case 21:
279                 case 24:
280                 case 25:
281                 case 28:
282                 case 29:
283                         readWriteEnds.get("MC_EN").feedSignals(ONE);
284                         readWriteEnds.get("MC_MUX").feedSignals(ONE, X);
285                         break;
286                 default:
287                         throw new IllegalStateException("can't happen");
288                 }
289                 return null;
290         }
291
292         static
293         {
294                 IndirectGUIComponentCreator.setComponentSupplier(GUIAm2904ShiftInstrDecode.class.getCanonicalName(),
295                                 (m, p, n) -> new GUIAm2904ShiftInstrDecode(m, n));
296         }
297 }