Unified the status order Z-C-N-OVR everywhere in the Am2904 tests
[Mograsim.git] / net.mograsim.logic.model.am2900 / test / net / mograsim / logic / model / am2900 / am2904 / TestableAm2904.java
1 package net.mograsim.logic.model.am2900.am2904;
2
3 import java.util.Collections;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import net.mograsim.logic.model.am2900.TestableCircuit;
8
9 public interface TestableAm2904 extends TestableCircuit
10 {
11
12         void setInstruction(Am2904_Inst inst);
13
14         void setCarry(Am2904_Carry carry);
15
16         void setShiftCode(String val_4_bit);
17
18         void setI10(Am2904_ShiftDir dir);
19
20         void setCX(String val_1_bit);
21
22         void setY(String z_c_n_ovr);
23
24         void setIZ(String val_1_bit);
25
26         void setIC(String val_1_bit);
27
28         void setIOVR(String val_1_bit);
29
30         void setIN(String val_1_bit);
31
32         default void setI(String z_c_n_ovr)
33         {
34                 setIZ(z_c_n_ovr.substring(0, 1));
35                 setIC(z_c_n_ovr.substring(1, 2));
36                 setIN(z_c_n_ovr.substring(2, 3));
37                 setIOVR(z_c_n_ovr.substring(3, 4));
38         }
39
40         void set_CEM(String val_1_bit);
41
42         void set_CEµ(String val_1_bit);
43
44         void set_OEY(String val_1_bit);
45
46         void set_OECT(String val_1_bit);
47
48         void set_SE(String val_1_bit);
49
50         void set_EZ(String val_1_bit);
51
52         void set_EC(String val_1_bit);
53
54         void set_EOVR(String val_1_bit);
55
56         void set_EN(String val_1_bit);
57
58         default void set_E(String z_c_n_ovr)
59         {
60                 set_EZ(z_c_n_ovr.substring(0, 1));
61                 set_EC(z_c_n_ovr.substring(1, 2));
62                 set_EN(z_c_n_ovr.substring(2, 3));
63                 set_EOVR(z_c_n_ovr.substring(3, 4));
64         }
65
66         void setSIO0(String val_1_bit);
67
68         void setSIO3(String val_1_bit);
69
70         void setQIO0(String val_1_bit);
71
72         void setQIO3(String val_1_bit);
73
74         void setDirectly(Register r, String val_1_bit);
75
76         String getC0();
77
78         String getCT();
79
80         String getY();
81
82         String getSIO0();
83
84         String getSIO3();
85
86         String getQIO0();
87
88         String getQIO3();
89
90         String getDirectly(Register r);
91
92         enum Am2904_ShiftDir
93         {
94                 RIGHT, LEFT;
95         }
96
97         enum Am2904_Carry
98         {
99                 CI0, CI1, CX, USE_SR;
100         }
101
102         /**
103          * Pattern:<br>
104          * [microSR]_[machineSR]_[condCodeSource]_[condCode]<br>
105          * <ul>
106          * <li>Load = load from I inputs (Am2904s)</li>
107          * <li>condCodeSource = µ, M, I (and a special case: I and M)</li>
108          * <li>condCode = the boolean term defining the CT output</li>
109          * </ul>
110          */
111         enum Am2904_Inst
112         {
113                 // @formatter:off
114                 LoadM_LoadY_µ_NxorOVRorZ(0_00),
115                 Set_Set_µ_NxnorOVRornotZ(0_01),
116                 Swap_Swap_µ_NxorOVR(0_02),
117                 Reset_Reset_µ_NxnorOVR(0_03),
118                 Load_LoadForShiftThroughOvr_µ_Z(0_04),
119                 Load_Invert_µ_notZ(0_05),
120                 LoadOvrRetain_Load_µ_OVR(0_06),
121                 LoadOvrRetain_Load_µ_notOVR(0_07),
122                 ResetZ_LoadCarryInvert_µ_CorZ(0_10),
123                 SetZ_LoadCarryInvert_µ_notCandnotZ(0_11),
124                 ResetC_Load_µ_C(0_12),
125                 SetC_Load_µ_notC(0_13),
126                 ResetN_Load_µ_notCorZ(0_14),
127                 SetN_Load_µ_CandnotZ(0_15),
128                 ResetOvr_Load_IM_NxorN(0_16),
129                 SetOvr_Load_IM_NxnorN(0_17),
130                 Load_Load_µ_NxorOVRorZ(0_20),
131                 Load_Load_µ_NxnorOVRornotZ(0_21),
132                 Load_Load_µ_NxorOVR(0_22),
133                 Load_Load_µ_NxnorOVR(0_23),
134                 Load_Load_µ_Z(0_24),
135                 Load_Load_µ_notZ(0_25),
136                 Load_Load_µ_OVR(0_26),
137                 Load_Load_µ_notOVR(0_27),
138                 LoadCarryInvert_LoadCarryInvert_µ_CorZ(0_30),
139                 LoadCarryInvert_LoadCarryInvert_µ_notCandnotZ(0_31),
140                 Load_Load_µ_C(0_32),
141                 Load_Load_µ_notC(0_33),
142                 Load_Load_µ_notCorZ(0_34),
143                 Load_Load_µ_CandnotZ(0_35),
144                 Load_Load_µ_N(0_36),
145                 Load_Load_µ_notN(0_37),
146                 Load_Load_M_NxorOVRorZ(0_40),
147                 Load_Load_M_NxnorOVRornotZ(0_41),
148                 Load_Load_M_NxorOVR(0_42),
149                 Load_Load_M_NxnorOVR(0_43),
150                 Load_Load_M_Z(0_44),
151                 Load_Load_M_notZ(0_45),
152                 Load_Load_M_OVR(0_46),
153                 Load_Load_M_notOVR(0_47),
154                 LoadCarryInvert_LoadCarryInvert_M_CorZ(0_50),
155                 LoadCarryInvert_LoadCarryInvert_M_notCandnotZ(0_51),
156                 Load_Load_M_C(0_52),
157                 Load_Load_M_notC(0_53),
158                 Load_Load_M_notCorZ(0_54),
159                 Load_Load_M_CandnotZ(0_55),
160                 Load_Load_M_N(0_56),
161                 Load_Load_M_notN(0_57),
162                 Load_Load_I_NxorOVRorZ(0_60),
163                 Load_Load_I_NxnorOVRornotZ(0_61),
164                 Load_Load_I_NxorOVR(0_62),
165                 Load_Load_I_NxnorOVR(0_63),
166                 Load_Load_I_Z(0_64),
167                 Load_Load_I_notZ(0_65),
168                 Load_Load_I_OVR(0_66),
169                 Load_Load_I_notOVR(0_67),
170                 LoadCarryInvert_LoadCarryInvert_I_notCorZ(0_70),
171                 LoadCarryInvert_LoadCarryInvert_I_CandnotZ(0_71),
172                 Load_Load_I_C(0_72),
173                 Load_Load_I_notC(0_73),
174                 Load_Load_I_notCorZ(0_74),
175                 Load_Load_I_CandnotZ(0_75),
176                 Load_Load_I_N(0_76),
177                 Load_Load_I_notN(0_77);
178                 // @formatter:on
179
180                 public final int code;
181
182                 private Am2904_Inst(int code)
183                 {
184                         this.code = code;
185                 }
186
187                 private static final Map<Integer, Am2904_Inst> instCodes;
188
189                 static
190                 {
191                         Map<Integer, Am2904_Inst> instCodesMod = new HashMap<>();
192                         Am2904_Inst[] vals = values();
193                         for (Am2904_Inst inst : vals)
194                         {
195                                 assert inst.code == inst.ordinal();
196                                 instCodesMod.put(inst.code, inst);
197                         }
198                         if (instCodesMod.size() != 64)
199                                 throw new IllegalStateException("There must be exactly 64 Am2904 instruction codes, but was " + instCodesMod.size());
200                         instCodes = Collections.unmodifiableMap(instCodesMod);
201                 }
202
203                 public static Am2904_Inst getInstFor(int I_543210)
204                 {
205                         Am2904_Inst inst = instCodes.get(I_543210);
206                         if (inst != null)
207                                 return inst;
208                         throw new IllegalArgumentException("Invaild Am2904 instruction code: " + I_543210);
209                 }
210
211                 public int getBlock()
212                 {
213                         return code >> 4;
214                 }
215
216                 public boolean isLoadCarryInvert()
217                 {
218                         return (code & 0b001_110) == 0b001_000;
219                 }
220         }
221
222         enum Register
223         {
224                 µZ, µC, µN, µOVR, MZ, MC, MN, MOVR;
225         }
226 }