0b6a26f82acbe3e7c00f0cc03d7b55e17eb44071
[Mograsim.git] /
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 //      private static final MnemonicFamily am2904StatusInstructions = new MnemonicFamily(
40 //                      new String[] { "MI_Zero", "MI_NotZero", "MI_UGTEQ", "MI_ULT", "MI_UGT", "MI_ULTEQ", "MI_SGTEQ", "MI_SLT", "MI_SGT", "MI_SLTEQ",
41 //                                      "MA_Zero", "MA_NotZero", "MA_UGTEQ", "MA_ULT", "MA_UGT", "MA_ULTEQ", "MA_SGTEQ", "MA_SLT", "MA_SGT", "MA_SLTEQ" },
42 //                      new long[] { 0b01_0101, 0b01_0100, 0b01_1101, 0b01_1100, 0b01_1110, 0b01_1111, 0b01_0010, 0b01_0011, 0b01_0000, 0b01_0001,
43 //                                      0b10_0101, 0b10_0100, 0b10_1101, 0b10_1100, 0b10_1110, 0b10_1111, 0b10_0010, 0b10_0011, 0b10_0000, 0b10_0001 },
44 //                      6);
45         // TODO: Maybe "X" and "notX" are swapped.
46         private static final MnemonicFamily am2904StatusInstructions = new MnemonicFamilyBuilder(6).addX().setXDefault()
47                         .add("LoadM_LoadY_µ_NxorOVRorZ", "Set_Set_µ_NxnorOVRornotZ", "Swap_Swap_µ_NxorOVR", "Reset_Reset_µ_NxnorOVR",
48                                         "Load_LoadForShiftThroughOvr_µ_Z", "Load_Invert_µ_notZ", "LoadOvrRetain_Load_µ_OVR", "LoadOvrRetain_Load_µ_notOVR",
49                                         "ResetZ_LoadCarryInvert_µ_CorZ", "SetZ_LoadCarryInvert_µ_notCandnotZ", "ResetC_Load_µ_C", "SetC_Load_µ_notC",
50                                         "ResetN_Load_µ_notCorZ", "SetN_Load_µ_CandnotZ", "ResetOvr_Load_IM_NxorN", "SetOvr_Load_IM_NxnorN",
51                                         "Load_Load_µ_NxorOVRorZ", "Load_Load_µ_NxnorOVRornotZ", "Load_Load_µ_NxorOVR", "Load_Load_µ_NxnorOVR", "Load_Load_µ_Z",
52                                         "Load_Load_µ_notZ", "Load_Load_µ_OVR", "Load_Load_µ_notOVR", "LoadCarryInvert_LoadCarryInvert_µ_CorZ",
53                                         "LoadCarryInvert_LoadCarryInvert_µ_notCandnotZ", "Load_Load_µ_C", "Load_Load_µ_notC", "Load_Load_µ_notCorZ",
54                                         "Load_Load_µ_CandnotZ", "Load_Load_µ_N", "Load_Load_µ_notN", "Load_Load_M_NxorOVRorZ", "Load_Load_M_NxnorOVRornotZ",
55                                         "Load_Load_M_NxorOVR", "Load_Load_M_NxnorOVR", "Load_Load_M_Z", "Load_Load_M_notZ", "Load_Load_M_OVR",
56                                         "Load_Load_M_notOVR", "LoadCarryInvert_LoadCarryInvert_M_CorZ", "LoadCarryInvert_LoadCarryInvert_M_notCandnotZ",
57                                         "Load_Load_M_C", "Load_Load_M_notC", "Load_Load_M_notCorZ", "Load_Load_M_CandnotZ", "Load_Load_M_N", "Load_Load_M_notN",
58                                         "Load_Load_I_NxorOVRorZ", "Load_Load_I_NxnorOVRornotZ", "Load_Load_I_NxorOVR", "Load_Load_I_NxnorOVR", "Load_Load_I_Z",
59                                         "Load_Load_I_notZ", "Load_Load_I_OVR", "Load_Load_I_notOVR", "LoadCarryInvert_LoadCarryInvert_I_notCorZ",
60                                         "LoadCarryInvert_LoadCarryInvert_I_CandnotZ", "Load_Load_I_C", "Load_Load_I_notC", "Load_Load_I_notCorZ",
61                                         "Load_Load_I_CandnotZ", "Load_Load_I_N", "Load_Load_I_notN")
62                         .build();
63         private static final BooleanClassification ccen = new BooleanClassification(true, "PS", "C");
64         private static final MnemonicFamily am2910Instructions = new MnemonicFamilyBuilder(4).addX()
65                         .add("JZ", "CJS", "JMAP", "CJP", "PUSH", "JSRP", "CJV", "JRP", "RFCT", "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB")
66                         .setDefault("CONT").build();
67
68         private static final IntegerClassification constant_12bit = new IntegerClassification(0, 12);
69         private static final IntegerClassification constant_16bit = new IntegerClassification(0, 16);
70         private static final BooleanClassification hE = new BooleanClassification(true, "H", "E");
71         private static final BooleanClassification hI = new BooleanClassification(true, "H", "I");
72         private static final BooleanClassification hL = new BooleanClassification(true, "H", "L");
73         private static final BooleanClassification rW = new BooleanClassification(true, "R", "W");
74
75         private static final ParameterClassification[] classes = { interruptEnable, interruptInstructions, kmux, constant_16bit,
76                         am2901SrcInstructions, am2901FuncInstructions, am2901DestInstructions, register, registerSelect, register, registerSelect, abus,
77                         dbus, am2904CarryInstructions, am2904ShiftInstructions, hL, hL, am2904StatusInstructions, ccen, am2910Instructions,
78                         constant_12bit, hL, hE, hI, hE, hL, rW };
79
80         private static final String[] paramDesc = { "Allow interrupts?", "Interrupt instructions; omitted for simplicity",
81                         "Get D-input from data bus/constant value", "Constant value", "Operand sources for ALU operation", "ALU operation",
82                         "Destination of ALU calculation", "Register for A-operand", "Get A-operand from instruction register/micro instruction?",
83                         "Register for B-operand", "Get B-operand from instruction register/micro instruction?",
84                         "Put data from Y-output on address bus?", "Put data from Y-output on data bus?", "Source for carry-in", "Shift instructions",
85                         "Modify micro status register?", "Modify macro status register?", "Operations on the status register",
86                         "Is conditional jump enabled?", "Instructions for the micro instruction pointer", "Absolute address of a micro instruction",
87                         "Load instruction pointer from data bus?", "Put instruction pointer on data bus?", "Increment instruction pointer?",
88                         "Put instruction pointer on address bus?", "Load instruction register from data bus?", "Read from/Write to main memory?" };
89
90         @Override
91         public ParameterClassification[] getParameterClassifications()
92         {
93                 return Arrays.copyOf(classes, classes.length);
94         }
95
96         @Override
97         public ParameterClassification getParameterClassification(int index)
98         {
99                 return classes[index];
100         }
101
102         @Override
103         public Optional<String> getParameterDescription(int index)
104         {
105                 return Optional.of(paramDesc[index]);
106         }
107
108         private Am2900MicroInstructionDefinition()
109         {
110         }
111 }