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