Adding documentation and implementations for Ram, VRam, SRam

This commit is contained in:
AnonymusRaccoon
2020-01-28 14:04:53 +01:00
parent 8698642636
commit 87ecd6c23d
7 changed files with 111 additions and 4 deletions
+29
View File
@@ -0,0 +1,29 @@
//
// Created by anonymus-raccoon on 1/28/20.
//
#include "Ram.hpp"
#include "../Exceptions/InvalidAddress.hpp"
namespace ComSquare::Ram
{
Ram::Ram(size_t size)
: _size(size)
{
this->_data = new uint8_t[size];
}
uint8_t Ram::read(uint24_t addr)
{
if (addr >= this->_size)
throw InvalidAddress("Ram read", addr);
return this->_data[addr];
}
void Ram::write(uint24_t addr, uint8_t data)
{
if (addr >= this->_size)
throw InvalidAddress("Ram write", addr);
this->_data[addr] = data;
}
}
+34
View File
@@ -0,0 +1,34 @@
//
// Created by anonymus-raccoon on 1/28/20.
//
#ifndef COMSQUARE_RAM_HPP
#define COMSQUARE_RAM_HPP
#include "../Memory/IMemory.hpp"
namespace ComSquare::Ram
{
class Ram : IMemory {
private:
//! @brief The ram. (Can be used for WRam, SRam, VRam etc)
uint8_t *_data;
//! @brief The size of the ram.
size_t _size;
public:
//! @brief Load a rom from it's path.
explicit Ram(size_t size);
//! @brief Read from the ram.
//! @param addr The address to read from. The address 0x0 should refer to the first byte of this ram.
//! @throw InvalidAddress will be thrown if the address is more than the size of the ram.
//! @return Return the data at the address.
uint8_t read(uint24_t addr) override;
//! @brief Write data to the ram.
//! @param addr The address to write to. The address 0x0 should refer to the first byte of this ram.
//! @param data The data to write.
//! @throw InvalidAddress will be thrown if the address is more than the size of the ram.
void write(uint24_t addr, uint8_t data) override;
};
}
#endif //COMSQUARE_RAM_HPP