aeffbd2c303b34508b2576da4956e7805a732aae
[Mograsim.git] /
1 package net.mograsim.machine.mi.components;
2
3 import net.mograsim.logic.model.model.LogicModelModifiable;
4 import net.mograsim.logic.model.model.wires.Pin;
5 import net.mograsim.logic.model.model.wires.PinUsage;
6 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
7 import net.mograsim.machine.ModelMemory;
8 import net.mograsim.machine.mi.MicroInstructionMemory;
9 import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
10
11 public abstract class ModelMicroInstructionMemory extends ModelMemory
12 {
13         private final Pin addrPin, dataPin;
14         private CoreMicroInstructionMemory memory;
15         private final MicroInstructionMemoryDefinition definition;
16
17         public ModelMicroInstructionMemory(LogicModelModifiable model, MicroInstructionMemoryDefinition definition, String name)
18         {
19                 super(model, 120, 150, name, "MPM", false);
20                 this.definition = definition;
21                 addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, getWidth(), 30));
22                 addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionDefinition().sizeInBits(), PinUsage.OUTPUT, getWidth(),
23                                 50));
24
25                 init();
26         }
27
28         public MicroInstructionMemoryDefinition getDefinition()
29         {
30                 return definition;
31         }
32
33         public Pin getAddressPin()
34         {
35                 return addrPin;
36         }
37
38         public Pin getDataPin()
39         {
40                 return dataPin;
41         }
42
43         public CoreMicroInstructionMemory getCoreMemory()
44         {
45                 return memory;
46         }
47
48         public void setCoreModelBinding(CoreMicroInstructionMemory memory)
49         {
50                 this.memory = memory;
51         }
52
53         @Override
54         public void setHighLevelState(String stateID, Object newState)
55         {
56                 if (stateID.equals("memory_binding"))
57                         memory.setMemory((MicroInstructionMemory) newState);
58                 else
59                         super.setHighLevelState(stateID, newState);
60         }
61
62         @Override
63         public Object getHighLevelState(String stateID)
64         {
65                 if (stateID.equals("memory_binding"))
66                         return memory.getMemory();
67                 return super.getHighLevelState(stateID);
68         }
69
70         static
71         {
72                 LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter());
73         }
74 }