c2272bd90ba2b18f44874b818f7c516ee33151b3
[Mograsim.git] / plugins / net.mograsim.logic.model.am2900 / src / net / mograsim / logic / model / am2900 / machine / Am2900MicroInstructionDefinition.java
1 package net.mograsim.logic.model.am2900.machine;
2
3 import java.util.Arrays;
4 import java.util.Optional;
5
6 import net.mograsim.machine.mi.MicroInstructionDefinition;
7 import net.mograsim.machine.mi.parameters.BooleanClassification;
8 import net.mograsim.machine.mi.parameters.IntegerClassification;
9 import net.mograsim.machine.mi.parameters.MnemonicFamily;
10 import net.mograsim.machine.mi.parameters.MnemonicFamily.MnemonicFamilyBuilder;
11 import net.mograsim.machine.mi.parameters.ParameterClassification;
12
13 public class Am2900MicroInstructionDefinition implements MicroInstructionDefinition
14 {
15         public static final Am2900MicroInstructionDefinition instance = new Am2900MicroInstructionDefinition();
16
17         private static final BooleanClassification interruptEnable = new BooleanClassification(false, "IE", "Dis");
18         // not implemented, because not documented.
19         private static final MnemonicFamily interruptInstructions = new MnemonicFamilyBuilder(4).addX().setXDefault().build();
20         private static final BooleanClassification kmux = new BooleanClassification("D", "K");
21         private static final MnemonicFamily am2901SrcInstructions = new MnemonicFamilyBuilder(3).addX().setXDefault()
22                         .add("AQ", "AB", "ZQ", "ZB", "ZA", "DA", "DQ", "DZ").build();
23         private static final MnemonicFamily am2901FuncInstructions = new MnemonicFamilyBuilder(3).addX().setXDefault()
24                         .add("ADD", "SUBR", "SUBS", "OR", "AND", "NOTRS", "EXOR", "EXNOR").build();
25         private static final MnemonicFamily am2901DestInstructions = new MnemonicFamilyBuilder(3).addX()
26                         .add("QREG", "NOP", "RAMA", "RAMF", "RAMQD", "RAMD", "RAMQU", "RAMU").setDefault("NOP").build();
27         private static final IntegerClassification register = new IntegerClassification(0, 4);
28         private static final BooleanClassification registerSelect = new BooleanClassification("MR", "IR");
29         private static final BooleanClassification abus = new BooleanClassification(true, "H", "AB");
30         private static final BooleanClassification dbus = new BooleanClassification(true, "H", "DB");
31         private static final MnemonicFamily am2904CarryInstructions = new MnemonicFamilyBuilder(2).addX().setXDefault()
32                         .add("CI0", "CI1", "CIX", "CIC").build();
33         private static final MnemonicFamily am2904ShiftInstructions = new MnemonicFamilyBuilder(4).addX().setXDefault()
34                         .add("RSL", "RSH", "RSCONI", "RSDH", "RSDC", "RSDN", "RSDL", "RSDCO", "RSRCO", "RSRCIO", "RSR", "RSDIC", "RSDRCI", "RSDRCO",
35                                         "RSDXOR", "RSDR")
36                         .add("LSLCO", "LSHCO", "LSL", "LSH", "LSDLCO", "LSDHCO", "LSDL", "LSDH", "LSCRO", "LSCRIO", "LSR", "LSLICI", "LSDCIO", "LSDRCO",
37                                         "LSDCI", "LDSR")
38                         .build();
39         // TODO: Maybe "X" and "notX" are swapped.
40         private static final MnemonicFamily am2904StatusInstructions = new MnemonicFamilyBuilder(6).addX().setXDefault()
41                         .add(new String[] { "LOAD", "MI_Zero", "MI_NotZero", "MI_UGTEQ", "MI_ULT", "MI_UGT", "MI_ULTEQ", "MI_SGTEQ", "MI_SLT", "MI_SGT",
42                                         "MI_SLTEQ", "MA_Zero", "MA_NotZero", "MA_UGTEQ", "MA_ULT", "MA_UGT", "MA_ULTEQ", "MA_SGTEQ", "MA_SLT", "MA_SGT",
43                                         "MA_SLTEQ" },
44                                         new long[] { 0b01_0000, 0b01_0101, 0b01_0100, 0b01_1101, 0b01_1100, 0b01_1110, 0b01_1111, 0b01_0010, 0b01_0011,
45                                                         0b01_0000, 0b01_0001, 0b10_0101, 0b10_0100, 0b10_1101, 0b10_1100, 0b10_1110, 0b10_1111, 0b10_0010, 0b10_0011,
46                                                         0b10_0000, 0b10_0001 })
47                         .add("LoadM_LoadY_\u00b5_NxorOVRorZ", "Set_Set_\u00b5_NxnorOVRornotZ", "Swap_Swap_\u00b5_NxorOVR",
48                                         "Reset_Reset_\u00b5_NxnorOVR", "Load_LoadForShiftThroughOvr_\u00b5_Z", "Load_Invert_\u00b5_notZ",
49                                         "LoadOvrRetain_Load_\u00b5_OVR", "LoadOvrRetain_Load_\u00b5_notOVR", "ResetZ_LoadCarryInvert_\u00b5_CorZ",
50                                         "SetZ_LoadCarryInvert_\u00b5_notCandnotZ", "ResetC_Load_\u00b5_C", "SetC_Load_\u00b5_notC",
51                                         "ResetN_Load_\u00b5_notCorZ", "SetN_Load_\u00b5_CandnotZ", "ResetOvr_Load_IM_NxorN", "SetOvr_Load_IM_NxnorN",
52                                         "Load_Load_\u00b5_NxorOVRorZ", "Load_Load_\u00b5_NxnorOVRornotZ", "Load_Load_\u00b5_NxorOVR",
53                                         "Load_Load_\u00b5_NxnorOVR", "Load_Load_\u00b5_Z", "Load_Load_\u00b5_notZ", "Load_Load_\u00b5_OVR",
54                                         "Load_Load_\u00b5_notOVR", "LoadCarryInvert_LoadCarryInvert_\u00b5_CorZ",
55                                         "LoadCarryInvert_LoadCarryInvert_\u00b5_notCandnotZ", "Load_Load_\u00b5_C", "Load_Load_\u00b5_notC",
56                                         "Load_Load_\u00b5_notCorZ", "Load_Load_\u00b5_CandnotZ", "Load_Load_\u00b5_N", "Load_Load_\u00b5_notN",
57                                         "Load_Load_M_NxorOVRorZ", "Load_Load_M_NxnorOVRornotZ", "Load_Load_M_NxorOVR", "Load_Load_M_NxnorOVR", "Load_Load_M_Z",
58                                         "Load_Load_M_notZ", "Load_Load_M_OVR", "Load_Load_M_notOVR", "LoadCarryInvert_LoadCarryInvert_M_CorZ",
59                                         "LoadCarryInvert_LoadCarryInvert_M_notCandnotZ", "Load_Load_M_C", "Load_Load_M_notC", "Load_Load_M_notCorZ",
60                                         "Load_Load_M_CandnotZ", "Load_Load_M_N", "Load_Load_M_notN", "Load_Load_I_NxorOVRorZ", "Load_Load_I_NxnorOVRornotZ",
61                                         "Load_Load_I_NxorOVR", "Load_Load_I_NxnorOVR", "Load_Load_I_Z", "Load_Load_I_notZ", "Load_Load_I_OVR",
62                                         "Load_Load_I_notOVR", "LoadCarryInvert_LoadCarryInvert_I_notCorZ", "LoadCarryInvert_LoadCarryInvert_I_CandnotZ",
63                                         "Load_Load_I_C", "Load_Load_I_notC", "Load_Load_I_notCorZ", "Load_Load_I_CandnotZ", "Load_Load_I_N", "Load_Load_I_notN")
64                         .build();
65         // 00b5 = micro symbol
66         private static final BooleanClassification ccen = new BooleanClassification(true, "PS", "C");
67         private static final MnemonicFamily am2910Instructions = new MnemonicFamilyBuilder(4).addX()
68                         .add("JZ", "CJS", "JMAP", "CJP", "PUSH", "JSRP", "CJV", "JRP", "RFCT", "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB")
69                         .setDefault("CONT").build();
70
71         private static final IntegerClassification constant_12bit = new IntegerClassification(0, 12);
72         private static final IntegerClassification constant_16bit = new IntegerClassification(0, 16);
73         private static final BooleanClassification hE = new BooleanClassification(true, "H", "E");
74         private static final BooleanClassification hI = new BooleanClassification(true, "H", "I");
75         private static final BooleanClassification hL = new BooleanClassification(true, "H", "L");
76         private static final BooleanClassification rW = new BooleanClassification(true, "R", "W");
77
78         private static final ParameterClassification[] classes = { interruptEnable, interruptInstructions, kmux, constant_16bit,
79                         am2901SrcInstructions, am2901FuncInstructions, am2901DestInstructions, register, registerSelect, register, registerSelect, abus,
80                         dbus, am2904CarryInstructions, am2904ShiftInstructions, hL, hL, am2904StatusInstructions, ccen, am2910Instructions,
81                         constant_12bit, hL, hE, hI, hE, hL, rW };
82
83         private static final String[] paramTitle = { "IE", "I", "KMUX", "K", "01 Src", "01 Func", "01 Dest", "01 RA", "01 ASel", "01 RB",
84                         "01 BSel", "_ABus", "_DBus", "04 Cin", "04 Shift", "04 _CE\u00b5", "_CEM", "04 Op", "10 _CCEN", "10 I", "D", "BZ _LD", "BZ _ED",
85                         "BZ _INC", "BZ _EA", "IR _LD", "_MWE" };
86
87         private static final String[] paramDesc = { "Allow interrupts?", "Interrupt instructions; omitted for simplicity",
88                         "Get D-input from data bus/constant value", "Constant value", "Operand sources for ALU operation", "ALU operation",
89                         "Destination of ALU calculation", "Register for A-operand", "Get A-operand from instruction register/micro instruction?",
90                         "Register for B-operand", "Get B-operand from instruction register/micro instruction?",
91                         "Put data from Y-output on address bus?", "Put data from Y-output on data bus?", "Source for carry-in", "Shift instructions",
92                         "Modify micro status register?", "Modify macro status register?", "Operations on the status register",
93                         "Is conditional jump enabled?", "Instructions for the micro instruction pointer", "Absolute address of a micro instruction",
94                         "Load instruction pointer from data bus?", "Put instruction pointer on data bus?", "Increment instruction pointer?",
95                         "Put instruction pointer on address bus?", "Load instruction register from data bus?", "Read from/Write to main memory?" };
96
97         @Override
98         public ParameterClassification[] getParameterClassifications()
99         {
100                 return Arrays.copyOf(classes, classes.length);
101         }
102
103         @Override
104         public ParameterClassification getParameterClassification(int index)
105         {
106                 return classes[index];
107         }
108
109         @Override
110         public Optional<String> getParameterTitle(int index)
111         {
112                 return Optional.of(paramTitle[index]);
113         }
114
115         @Override
116         public Optional<String> getParameterDescription(int index)
117         {
118                 return Optional.of(paramDesc[index]);
119         }
120
121         private Am2900MicroInstructionDefinition()
122         {
123         }
124 }