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