X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=3b_sim%2Fcmem.cpp;h=3b8010dcc6f6ef399a98dd3975600b51e078036f;hb=c77b000ed58c343e3b4d10b42d558b609bdc2551;hp=22c80e6722b2b5f0340bd290133d96c5b57540af;hpb=12d2a7c14a42e01b6caf2a097db32404a403d213;p=calu.git diff --git a/3b_sim/cmem.cpp b/3b_sim/cmem.cpp index 22c80e6..3b8010d 100644 --- a/3b_sim/cmem.cpp +++ b/3b_sim/cmem.cpp @@ -3,7 +3,7 @@ using namespace std; template -void CMem::set(const MEMORY_ADDRESS address, const T& data) +void CMem::set(const MEMORY_ADDRESS address, const T data) { if(address >= MAX_MEMORY) { stringstream error; @@ -11,7 +11,7 @@ void CMem::set(const MEMORY_ADDRESS address, const T& data) throw out_of_range(error.str()); } - MEMORY_ADDRESS temp = address; + MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT; auto iter = m_memory.begin(); while(temp > 0) { ++iter; @@ -25,6 +25,39 @@ void CMem::set(const MEMORY_ADDRESS address, const T& data) template T CMem::get(const MEMORY_ADDRESS address) const +{ + if(address >= MAX_MEMORY) { + stringstream error; + error << "memoryaddress " << address << " out of range"; + throw out_of_range(error.str()); + } + MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT; + return m_memory[temp]; +} + +template +void CMem::setDirect(const MEMORY_ADDRESS address, const T data) +{ + if(address >= MAX_MEMORY) { + stringstream error; + error << "memoryaddress " << address << " out of range"; + throw out_of_range(error.str()); + } + + MEMORY_ADDRESS temp = address; + auto iter = m_memory.begin(); + while(temp > 0) { + ++iter; + temp--; + } + + iter = m_memory.insert(iter, data); + ++iter; + m_memory.erase(iter); +} + +template +T CMem::getDirect(const MEMORY_ADDRESS address) const { if(address >= MAX_MEMORY) { stringstream error; @@ -35,4 +68,4 @@ T CMem::get(const MEMORY_ADDRESS address) const } -template class CMem; +template class CMem;