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