Virtual 4001 CPU - Memory.cpp


IF YOU HAVE JUST ARRIVED HERE, PLEASE SEE: http://megalomaniacbore.blogspot.co.uk/2014/04/virtual-cpu-in-c-4001-cpu.html


//------------ Memory.cpp ---------------------
#include "Memory.h"

namespace CPU_4001
{

Memory::Memory()
:
c_MaxAddress(255), // The maximum constant
m_MemorySpace (new byte[c_MaxAddress]) // The memory
{
Clear(); // Our only function, clears the memory
// in C++ we allocate the variables in the
// constructor header, NOT here in the 
// Constructor body!
}

Memory::~Memory()
{
if ( m_MemorySpace != nullptr )
{
delete[] m_MemorySpace;
m_MemorySpace = nullptr;
}
}

void Memory::Clear()
{
for (byte i = 0; i < c_MaxAddress; ++i)
{
m_MemorySpace[i] = 0;
}
}

const byte& Memory::Read(const byte& p_Address)
{
return m_MemorySpace[p_Address];
}

void Memory::Write(const byte& p_Address, const byte& p_Value)
{
m_MemorySpace[p_Address] = p_Value;
}
}

No comments:

Post a Comment