09f42937dc899b305309ba6148cd197d04739df6
[calu.git] / 3b_sim / cmem.hpp
1 #ifndef __CMEM_H__
2 #define __CMEM_H__
3
4 #include "cdat.hpp"
5 #include <vector>
6 #include <stdexcept>
7
8
9 typedef int MEMORY_ADDRESS;
10
11
12 /**
13  * Name:    CMem
14  * Purpose: Class representing the memory of our emulated machine
15  */
16 template <typename T>
17 class CMem
18 {
19 private:
20         //MAX_MEMORY-1 zugreifbare Speicherzellen
21         const int MAX_MEMORY;
22         std::vector<T> m_memory;
23 public:
24         /* aligns to BIT_LEN words, aka. does calc direct memorycell from address */
25         void set(const MEMORY_ADDRESS address, const T data);
26         T get(const MEMORY_ADDRESS address) const;
27
28         /* doesn't align, user has to do */
29         void setDirect(const MEMORY_ADDRESS address, const T data);
30         T getDirect(const MEMORY_ADDRESS address) const;
31         CMem(int size) : MAX_MEMORY(size), m_memory(size,(T)NULL) {};
32 };
33
34 #endif