0488e8946bb98b77cd77ba5eb85256745f8b2aa4
[Mograsim.git] /
1 package net.mograsim.logic.model.am2900.machine;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import net.mograsim.logic.model.am2900.machine.registers.InstrRegister;
8 import net.mograsim.logic.model.am2900.machine.registers.muInstrRegister;
9 import net.mograsim.logic.model.am2900.machine.registers.am2901.Am2901RegisterGroup;
10 import net.mograsim.logic.model.am2900.machine.registers.am2904.Am2904RegisterGroup;
11 import net.mograsim.logic.model.am2900.machine.registers.am2910.Am2910RegisterGroup;
12 import net.mograsim.logic.model.model.LogicModelModifiable;
13 import net.mograsim.machine.ISASchema;
14 import net.mograsim.machine.MachineDefinition;
15 import net.mograsim.machine.registers.Register;
16 import net.mograsim.machine.registers.RegisterGroup;
17
18 //we can't use the Singleton pattern here because a MachineDefinition needs a public parameterless constructor
19 //(used for detecting installed machines in plugin.core)
20 public class AbstractAm2900MachineDefinition implements MachineDefinition
21 {
22         public static final String SIMPLE_AM2900_MACHINE_ID = "Am2900Simple";
23         public static final String STRICT_AM2900_MACHINE_ID = "Am2900Strict";
24
25         public static final List<Register> unsortedRegisters;
26         public static final List<RegisterGroup> registerGroups;
27
28         static
29         {
30                 List<Register> unsortedRegistersModifiable = new ArrayList<>();
31                 unsortedRegistersModifiable.add(muInstrRegister.instance);
32                 unsortedRegistersModifiable.add(InstrRegister.instance);
33                 // TODO PC/BZ...
34                 unsortedRegisters = Collections.unmodifiableList(unsortedRegistersModifiable);
35                 List<RegisterGroup> registerGroupsModifiable = new ArrayList<>();
36                 registerGroupsModifiable.add(Am2901RegisterGroup.instance);
37                 registerGroupsModifiable.add(Am2904RegisterGroup.instance);
38                 registerGroupsModifiable.add(Am2910RegisterGroup.instance);
39                 registerGroups = Collections.unmodifiableList(registerGroupsModifiable);
40         }
41
42         public final boolean strict;
43
44         protected AbstractAm2900MachineDefinition(boolean strict)
45         {
46                 this.strict = strict;
47         }
48
49         @Override
50         public String getId()
51         {
52                 return strict ? STRICT_AM2900_MACHINE_ID : SIMPLE_AM2900_MACHINE_ID;
53         }
54
55         @Override
56         public Am2900Machine createNew()
57         {
58                 return createNew(new LogicModelModifiable());
59         }
60
61         public Am2900Machine createNew(LogicModelModifiable model)
62         {
63                 return new Am2900Machine(model, this);
64         }
65
66         @Override
67         public ISASchema getISASchema()
68         {
69                 // TODO Auto-generated method stub
70                 return null;
71         }
72
73         @Override
74         public List<Register> getUnsortedRegisters()
75         {
76                 return unsortedRegisters;
77         }
78
79         @Override
80         public List<RegisterGroup> getRegisterGroups()
81         {
82                 return registerGroups;
83         }
84
85         @Override
86         public int getAddressBits()
87         {
88                 return 16;
89         }
90
91         @Override
92         public Am2900MainMemoryDefinition getMainMemoryDefinition()
93         {
94                 return Am2900MainMemoryDefinition.instance;
95         }
96
97         @Override
98         public int hashCode()
99         {
100                 return strict ? 12345 : 54321;
101         }
102
103         @Override
104         public boolean equals(Object obj)
105         {
106                 return obj != null && obj instanceof AbstractAm2900MachineDefinition
107                                 && ((AbstractAm2900MachineDefinition) obj).strict == this.strict;
108         }
109
110         @Override
111         public Am2900MicroInstructionMemoryDefinition getMicroInstructionMemoryDefinition()
112         {
113                 return Am2900MicroInstructionMemoryDefinition.instance;
114         }
115
116 }