mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-01 01:38:05 +00:00
Reverting
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 1/28/20.
|
||||
//
|
||||
|
||||
#include <cstring>
|
||||
#include "Ram.hpp"
|
||||
#include "../Exceptions/InvalidAddress.hpp"
|
||||
|
||||
namespace ComSquare::Ram
|
||||
{
|
||||
Ram::Ram(size_t size)
|
||||
: _size(size)
|
||||
{
|
||||
this->_data = new uint8_t[size];
|
||||
}
|
||||
|
||||
Ram::~Ram()
|
||||
{
|
||||
delete[] this->_data;
|
||||
}
|
||||
|
||||
uint8_t Ram::read_internal(uint24_t addr)
|
||||
{
|
||||
if (addr >= this->_size)
|
||||
throw InvalidAddress("Ram read", addr);
|
||||
return this->_data[addr];
|
||||
}
|
||||
|
||||
void Ram::write_internal(uint24_t addr, uint8_t data)
|
||||
{
|
||||
if (addr >= this->_size)
|
||||
throw InvalidAddress("Ram write", addr);
|
||||
this->_data[addr] = data;
|
||||
}
|
||||
|
||||
void Ram::memset(uint24_t start, uint24_t end, uint8_t value)
|
||||
{
|
||||
if (end >= this->_size)
|
||||
throw InvalidAddress("Ram memset end", end);
|
||||
if (start >= end)
|
||||
throw InvalidAddress("Ram memset start", start);
|
||||
std::memset(&this->_data[start], value, sizeof(uint8_t) * (end - start));
|
||||
}
|
||||
}
|
||||
+13
-30
@@ -5,59 +5,42 @@
|
||||
#ifndef COMSQUARE_RAM_HPP
|
||||
#define COMSQUARE_RAM_HPP
|
||||
|
||||
#include <cstring>
|
||||
#include "../Memory/IRectangleMemory.hpp"
|
||||
#include "../Exceptions/InvalidAddress.hpp"
|
||||
|
||||
namespace ComSquare::Ram
|
||||
{
|
||||
template<typename T>
|
||||
class Ram : public Memory::IRectangleMemory {
|
||||
private:
|
||||
private:
|
||||
//! @brief The ram. (Can be used for WRam, SRam, VRam etc)
|
||||
T *_data;
|
||||
uint8_t *_data;
|
||||
//! @brief The size of the ram.
|
||||
size_t _size;
|
||||
public:
|
||||
//! @brief Create a ram of the given size (in bytes).
|
||||
explicit Ram(size_t size)
|
||||
: _size(size)
|
||||
{
|
||||
this->_data = new T[size];
|
||||
std::memset(this->_data, 0, size * sizeof(T));
|
||||
}
|
||||
//! @brief Load a rom from it's path.
|
||||
explicit Ram(size_t size);
|
||||
//! @brief The ram can't be copied.
|
||||
Ram(const Ram &) = delete;
|
||||
//! @brief The ram can't be assigned.
|
||||
Ram &operator=(Ram &) = delete;
|
||||
//! @brief Destructor that free the ram.
|
||||
~Ram()
|
||||
{
|
||||
delete[] this->_data;
|
||||
}
|
||||
~Ram();
|
||||
//! @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.
|
||||
T read_internal(uint24_t addr) override
|
||||
{
|
||||
if (addr >= this->_size)
|
||||
throw InvalidAddress("Ram read", addr);
|
||||
return this->_data[addr];
|
||||
}
|
||||
uint8_t read_internal(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_internal(uint24_t addr, T data) override
|
||||
{
|
||||
if (addr >= this->_size)
|
||||
throw InvalidAddress("Ram write", addr);
|
||||
this->_data[addr] = data;
|
||||
}
|
||||
};
|
||||
void write_internal(uint24_t addr, uint8_t data) override;
|
||||
|
||||
typedef Ram<uint8_t> BasicRam;
|
||||
//! @brief replace values between two addresses with a value
|
||||
//! @param start start address to replace
|
||||
//! @param end end address to replace
|
||||
//! @param value replace value
|
||||
void memset(uint24_t start, uint24_t end, uint8_t value);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //COMSQUARE_RAM_HPP
|
||||
|
||||
Reference in New Issue
Block a user