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