86c60044c330d075141e3fde6ae28ef1a7eb76a8
[Mograsim.git] /
1 package net.mograsim.logic.model.am2900.machine;
2
3 import net.mograsim.logic.core.components.CoreClock;
4 import net.mograsim.logic.core.timeline.Timeline;
5 import net.mograsim.logic.core.types.Bit;
6 import net.mograsim.logic.core.types.BitVector;
7 import net.mograsim.logic.model.am2900.components.ModelAm2900MainMemory;
8 import net.mograsim.logic.model.am2900.components.ModelAm2900MicroInstructionMemory;
9 import net.mograsim.logic.model.model.LogicModel;
10 import net.mograsim.logic.model.model.LogicModelModifiable;
11 import net.mograsim.logic.model.model.components.ModelComponent;
12 import net.mograsim.logic.model.modeladapter.CoreModelParameters;
13 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
14 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
15 import net.mograsim.machine.Machine;
16 import net.mograsim.machine.MachineDefinition;
17 import net.mograsim.machine.MainMemory;
18 import net.mograsim.machine.Register;
19 import net.mograsim.machine.mi.AssignableMicroInstructionMemory;
20 import net.mograsim.machine.mi.MicroInstruction;
21 import net.mograsim.machine.mi.MicroInstructionDefinition;
22 import net.mograsim.machine.mi.StandardMicroInstructionMemory;
23 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
24 import net.mograsim.machine.mi.parameters.ParameterClassification;
25 import net.mograsim.machine.standard.memory.WordAddressableMemory;
26
27 public class Am2900Machine implements Machine
28 {
29         private Am2900MachineDefinition machineDefinition;
30         private LogicModelModifiable logicModel;
31         private ModelComponent am2900;
32         private Timeline timeline;
33         private MainMemory mainMemory;
34         private AssignableMicroInstructionMemory instMemory;
35         private CoreClock clock;
36
37         public Am2900Machine(LogicModelModifiable model, Am2900MachineDefinition am2900MachineDefinition)
38         {
39                 this.machineDefinition = am2900MachineDefinition;
40                 this.logicModel = model;
41                 this.am2900 = IndirectModelComponentCreator.createComponent(logicModel,
42                                 "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json", "Am2900");
43                 CoreModelParameters params = new CoreModelParameters();
44                 params.gateProcessTime = 50;
45                 params.wireTravelTime = 10;
46                 mainMemory = new WordAddressableMemory(am2900MachineDefinition.getMainMemoryDefinition());
47                 instMemory = new AssignableMicroInstructionMemory(
48                                 new StandardMicroInstructionMemory(am2900MachineDefinition.getMicroInstructionMemoryDefinition()));
49                 logicModel.getComponentBySubmodelPath("Am2900.Am2900MainMemory#0", ModelAm2900MainMemory.class).setMachine(this);
50                 logicModel.getComponentBySubmodelPath("Am2900.Am2900MicroInstructionMemory#0", ModelAm2900MicroInstructionMemory.class)
51                                 .setMachine(this);
52                 timeline = LogicCoreAdapter.convert(logicModel, params);
53         }
54
55         @Override
56         public MachineDefinition getDefinition()
57         {
58                 return machineDefinition;
59         }
60
61         @Override
62         public void reset()
63         {
64                 logicModel.getComponentByName("Am2900").setHighLevelState("c.out", BitVector.of(Bit.ZERO));
65                 MicroInstructionDefinition muiDef = getDefinition().getMicroInstructionMemoryDefinition().getMicroInstructionDefinition();
66                 ParameterClassification[] paramClassifications = muiDef.getParameterClassifications();
67                 MicroInstructionParameter[] defaultParams = muiDef.createDefaultInstruction().getParameters();
68                 defaultParams[19] = paramClassifications[19].parse("JZ");
69                 MicroInstruction jzMI = MicroInstruction.create(defaultParams);
70                 logicModel.getComponentByName("Am2900").setHighLevelState("muir_2.q", jzMI.toBitVector());
71         }
72
73         @Override
74         public LogicModel getModel()
75         {
76                 return logicModel;
77         }
78
79         public ModelComponent getAm2900()
80         {
81                 return am2900;
82         }
83
84         @Override
85         public Timeline getTimeline()
86         {
87                 return timeline;
88         }
89
90         @Override
91         public CoreClock getClock()
92         {
93                 return clock;
94         }
95
96         @Override
97         public BitVector getRegister(Register r)
98         {
99                 // TODO Auto-generated method stub
100                 return null;
101         }
102
103         @Override
104         public void setRegister(Register r, BitVector value)
105         {
106                 // TODO Auto-generated method stub
107
108         }
109
110         @Override
111         public MainMemory getMainMemory()
112         {
113                 return mainMemory;
114         }
115
116         @Override
117         public AssignableMicroInstructionMemory getMicroInstructionMemory()
118         {
119                 return instMemory;
120         }
121 }