5f42d10c74c40df908e0b934e8fd9703b4783304
[Mograsim.git] / net.mograsim.machine / src / net / mograsim / machine / MemoryDefinition.java
1 package net.mograsim.machine;
2
3 public interface MemoryDefinition {
4
5         /**
6          * The number of bits that the main memory uses to address cells. Note that this
7          * does not need to equal {@link MachineDefinition#getAddressBits()}.
8          * 
9          * @return the number of bits used to address a memory cell
10          * @author Christian Femers
11          */
12         int getMemoryAddressBits();
13
14         /**
15          * The minimal address possible to address/use. This is usually 0.
16          * 
17          * @return the minimal possible address.
18          * @author Christian Femers
19          */
20         long getMinimalAddress();
21
22         /**
23          * The maximal address possible to address/use.
24          * 
25          * @return the maximal possible address as <b>unsigned long</b>
26          * @author Christian Femers
27          */
28         long getMaximalAddress();
29         
30         /**
31          * The size of the MainMemory as the amount of addressable memory cells.
32          * 
33          * @return the amount of addressable memory cells
34          */
35         default long size()
36         {
37                 return getMaximalAddress() - getMinimalAddress();
38         }
39         
40         public static MemoryDefinition create(int memoryAddressBits, long minimalAddress, long maximalAddress)
41         {
42                 return new StandardMemoryDefinition(memoryAddressBits, minimalAddress, maximalAddress);
43         }
44 }