37d931536371c6b97881ae5e579bc5f5268c1e77
[Mograsim.git] /
1 package net.mograsim.logic.model.am2900.machine;
2
3 import java.util.Collections;
4 import java.util.HashSet;
5 import java.util.Set;
6
7 import net.mograsim.logic.model.am2900.machine.registers.NumberedRegister;
8 import net.mograsim.logic.model.am2900.machine.registers.QRegister;
9 import net.mograsim.logic.model.model.LogicModelModifiable;
10 import net.mograsim.machine.ISASchema;
11 import net.mograsim.machine.MachineDefinition;
12 import net.mograsim.machine.Register;
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 Set<Register> allRegisters;
22
23         static
24         {
25                 Set<Register> allRegistersModifiable = new HashSet<>();
26                 allRegistersModifiable.add(QRegister.instance);
27                 allRegistersModifiable.addAll(NumberedRegister.instancesCorrectOrder);
28                 allRegisters = Collections.unmodifiableSet(allRegistersModifiable);
29         }
30
31         public final boolean strict;
32
33         protected AbstractAm2900MachineDefinition(boolean strict)
34         {
35                 this.strict = strict;
36         }
37
38         @Override
39         public String getId()
40         {
41                 return strict ? STRICT_AM2900_MACHINE_ID : SIMPLE_AM2900_MACHINE_ID;
42         }
43
44         @Override
45         public Am2900Machine createNew()
46         {
47                 return createNew(new LogicModelModifiable());
48         }
49
50         public Am2900Machine createNew(LogicModelModifiable model)
51         {
52                 return new Am2900Machine(model, this);
53         }
54
55         @Override
56         public ISASchema getISASchema()
57         {
58                 // TODO Auto-generated method stub
59                 return null;
60         }
61
62         @Override
63         public Set<Register> getRegisters()
64         {
65                 return allRegisters;
66         }
67
68         @Override
69         public int getAddressBits()
70         {
71                 return 16;
72         }
73
74         @Override
75         public Am2900MainMemoryDefinition getMainMemoryDefinition()
76         {
77                 return Am2900MainMemoryDefinition.instance;
78         }
79
80         @Override
81         public int hashCode()
82         {
83                 return strict ? 12345 : 54321;
84         }
85
86         @Override
87         public boolean equals(Object obj)
88         {
89                 return obj != null && obj instanceof AbstractAm2900MachineDefinition
90                                 && ((AbstractAm2900MachineDefinition) obj).strict == this.strict;
91         }
92
93         @Override
94         public Am2900MicroInstructionMemoryDefinition getMicroInstructionMemoryDefinition()
95         {
96                 return Am2900MicroInstructionMemoryDefinition.instance;
97         }
98
99 }