Reverting

This commit is contained in:
AnonymusRaccoon
2020-02-13 18:37:43 +01:00
parent 41355191aa
commit ae5cae8f28
6 changed files with 80 additions and 40 deletions

View File

@@ -33,6 +33,7 @@ add_executable(unit_tests
sources/Exceptions/InvalidRom.hpp
sources/Models/Int24.hpp
sources/Models/Int24.hpp
sources/Ram/Ram.cpp
sources/Ram/Ram.hpp
sources/Memory/MemoryShadow.cpp
sources/Memory/MemoryShadow.hpp
@@ -93,6 +94,7 @@ add_executable(ComSquare
sources/Exceptions/InvalidRom.hpp
sources/Models/Int24.hpp
sources/Models/Int24.hpp
sources/Ram/Ram.cpp
sources/Ram/Ram.hpp
sources/Memory/MemoryShadow.cpp
sources/Memory/MemoryShadow.hpp

44
sources/Ram/Ram.cpp Normal file
View File

@@ -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));
}
}

View File

@@ -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:
//! @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

View File

@@ -13,8 +13,8 @@ namespace ComSquare
cpu(new CPU::CPU(bus, cartridge->header)),
ppu(new PPU::PPU(bus, renderer)),
apu(new APU::APU()),
wram(new Ram::BasicRam(16384)),
sram(new Ram::BasicRam(this->cartridge->header.sramSize))
wram(new Ram::Ram(16384)),
sram(new Ram::Ram(this->cartridge->header.sramSize))
{
bus->mapComponents(*this);
renderer.setWindowName(this->cartridge->header.gameName);

View File

@@ -27,9 +27,9 @@ namespace ComSquare
//! @brief Audio Processing Unit if the SNES
std::shared_ptr<APU::APU> apu;
//! @brief Work Ram shared by all the components.
std::shared_ptr<Ram::BasicRam> wram;
std::shared_ptr<Ram::Ram> wram;
//! @brief Save Ram residing inside the Cartridge in a real SNES.
std::shared_ptr<Ram::BasicRam> sram;
std::shared_ptr<Ram::Ram> sram;
//! @brief Create all the components using a common memory bus for all of them.
SNES(const std::shared_ptr<Memory::MemoryBus> &bus, const std::string &ramPath, Renderer::IRenderer &renderer);
SNES(const SNES &) = default;

View File

@@ -9,9 +9,20 @@
#include "../../sources/SNES.hpp"
#include "../../sources/Memory/MemoryBus.hpp"
using namespace ComSquare;
Test(SEP, setall)
{
auto pair = Init();
pair.second.cpu.SEP()
}
//
//Test(SEP, setall)
//{
// auto pair = Init();
// pair.second.wram->_data[0] = 0xFF;
// pair.second.cpu->SEP(0x0);
// auto data = pair.second.cpu->_registers.p.flags;
// cr_assert_eq(data, 0xFF, "The flag should be 0xFF but it was %b", data);
//}
//
//Test(SEP, setsome)
//{
// auto pair = Init();
// pair.second.wram->_data[0] = 0b10110101;
// pair.second.cpu->SEP(0x0);
// cr_assert_eq(pair.second.cpu->_registers.p.flags, 0xFF);
//}