7490b361f0cfe714c66cb6876fe5eaf4b209e0d1
[Mograsim.git] /
1 package net.mograsim.machine.standard.memory;
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.MainMemory;
8 import net.mograsim.machine.MainMemoryDefinition;
9 import net.mograsim.machine.ModelMemory;
10
11 public abstract class ModelWordAddressableMemory extends ModelMemory
12 {
13         private final Pin addrPin, dataPin, rWPin;
14         private CoreWordAddressableMemory memory;
15         private MainMemoryDefinition definition;
16
17         public ModelWordAddressableMemory(LogicModelModifiable model, MainMemoryDefinition definition, String name)
18         {
19                 super(model, 120, 150, name, "RAM", false);
20                 this.definition = definition;
21
22                 addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, getWidth(), 30));
23                 addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, getWidth(), 50));
24                 addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, getWidth(), 70));
25
26                 init();
27         }
28
29         public MainMemoryDefinition getDefinition()
30         {
31                 return definition;
32         }
33
34         public Pin getAddressPin()
35         {
36                 return addrPin;
37         }
38
39         public Pin getDataPin()
40         {
41                 return dataPin;
42         }
43
44         public Pin getReadWritePin()
45         {
46                 return rWPin;
47         }
48
49         public void setCoreModelBinding(CoreWordAddressableMemory memory)
50         {
51                 this.memory = memory;
52         }
53
54         public CoreWordAddressableMemory getCoreMemory()
55         {
56                 return memory;
57         }
58
59         @Override
60         public void setHighLevelState(String stateID, Object newState)
61         {
62                 if (stateID.equals("memory_binding"))
63                         memory.setMemory((MainMemory) newState);
64                 else
65                         super.setHighLevelState(stateID, newState);
66         }
67
68         @Override
69         public Object getHighLevelState(String stateID)
70         {
71                 if (stateID.equals("memory_binding"))
72                         return memory.getMemory();
73                 return super.getHighLevelState(stateID);
74         }
75
76         static
77         {
78                 LogicCoreAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());
79         }
80 }