mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-05 02:49:50 +00:00
Making the RAM a template
This commit is contained in:
+3
-8
@@ -33,7 +33,6 @@ add_executable(unit_tests
|
|||||||
sources/Exceptions/InvalidRom.hpp
|
sources/Exceptions/InvalidRom.hpp
|
||||||
sources/Models/Int24.hpp
|
sources/Models/Int24.hpp
|
||||||
sources/Models/Int24.hpp
|
sources/Models/Int24.hpp
|
||||||
sources/Ram/Ram.cpp
|
|
||||||
sources/Ram/Ram.hpp
|
sources/Ram/Ram.hpp
|
||||||
sources/Memory/MemoryShadow.cpp
|
sources/Memory/MemoryShadow.cpp
|
||||||
sources/Memory/MemoryShadow.hpp
|
sources/Memory/MemoryShadow.hpp
|
||||||
@@ -48,8 +47,6 @@ add_executable(unit_tests
|
|||||||
sources/Cartridge/InterruptVectors.hpp
|
sources/Cartridge/InterruptVectors.hpp
|
||||||
sources/Memory/RectangleShadow.cpp
|
sources/Memory/RectangleShadow.cpp
|
||||||
sources/Memory/RectangleShadow.hpp
|
sources/Memory/RectangleShadow.hpp
|
||||||
sources/CPU/Instructions/CommonInstructions.cpp
|
|
||||||
sources/CPU/Instructions/CommonInstructions.hpp
|
|
||||||
sources/Exceptions/InvalidOpcode.hpp
|
sources/Exceptions/InvalidOpcode.hpp
|
||||||
sources/CPU/Instructions/Interrupts.cpp
|
sources/CPU/Instructions/Interrupts.cpp
|
||||||
sources/CPU/Instructions/MathematicalOperations.cpp
|
sources/CPU/Instructions/MathematicalOperations.cpp
|
||||||
@@ -61,7 +58,8 @@ add_executable(unit_tests
|
|||||||
sources/CPU/Instructions/MemoryInstructions.cpp
|
sources/CPU/Instructions/MemoryInstructions.cpp
|
||||||
tests/CPU/Math/testADC.cpp
|
tests/CPU/Math/testADC.cpp
|
||||||
tests/CPU/testStore.cpp
|
tests/CPU/testStore.cpp
|
||||||
)
|
sources/CPU/Instructions/InternalInstruction.cpp
|
||||||
|
tests/CPU/testInternal.cpp)
|
||||||
|
|
||||||
# include criterion & coverage
|
# include criterion & coverage
|
||||||
target_link_libraries(unit_tests criterion -lgcov)
|
target_link_libraries(unit_tests criterion -lgcov)
|
||||||
@@ -95,7 +93,6 @@ add_executable(ComSquare
|
|||||||
sources/Exceptions/InvalidRom.hpp
|
sources/Exceptions/InvalidRom.hpp
|
||||||
sources/Models/Int24.hpp
|
sources/Models/Int24.hpp
|
||||||
sources/Models/Int24.hpp
|
sources/Models/Int24.hpp
|
||||||
sources/Ram/Ram.cpp
|
|
||||||
sources/Ram/Ram.hpp
|
sources/Ram/Ram.hpp
|
||||||
sources/Memory/MemoryShadow.cpp
|
sources/Memory/MemoryShadow.cpp
|
||||||
sources/Memory/MemoryShadow.hpp
|
sources/Memory/MemoryShadow.hpp
|
||||||
@@ -110,12 +107,10 @@ add_executable(ComSquare
|
|||||||
sources/Cartridge/InterruptVectors.hpp
|
sources/Cartridge/InterruptVectors.hpp
|
||||||
sources/Memory/RectangleShadow.cpp
|
sources/Memory/RectangleShadow.cpp
|
||||||
sources/Memory/RectangleShadow.hpp
|
sources/Memory/RectangleShadow.hpp
|
||||||
sources/CPU/Instructions/CommonInstructions.cpp
|
|
||||||
sources/CPU/Instructions/CommonInstructions.hpp
|
|
||||||
sources/Exceptions/InvalidOpcode.hpp
|
sources/Exceptions/InvalidOpcode.hpp
|
||||||
sources/CPU/Instructions/Interrupts.cpp
|
sources/CPU/Instructions/Interrupts.cpp
|
||||||
sources/CPU/Instructions/MathematicalOperations.cpp
|
sources/CPU/Instructions/MathematicalOperations.cpp
|
||||||
sources/CPU/Instructions/MemoryInstructions.cpp)
|
sources/CPU/Instructions/MemoryInstructions.cpp sources/CPU/Instructions/InternalInstruction.cpp)
|
||||||
|
|
||||||
target_link_libraries(ComSquare
|
target_link_libraries(ComSquare
|
||||||
sfml-graphics
|
sfml-graphics
|
||||||
|
|||||||
+3
-2
@@ -8,7 +8,6 @@
|
|||||||
#include "../Memory/IMemory.hpp"
|
#include "../Memory/IMemory.hpp"
|
||||||
#include "../Memory/MemoryBus.hpp"
|
#include "../Memory/MemoryBus.hpp"
|
||||||
#include "../Models/Int24.hpp"
|
#include "../Models/Int24.hpp"
|
||||||
#include "Instructions/CommonInstructions.hpp"
|
|
||||||
#include "../Cartridge/Cartridge.hpp"
|
#include "../Cartridge/Cartridge.hpp"
|
||||||
|
|
||||||
namespace ComSquare::CPU
|
namespace ComSquare::CPU
|
||||||
@@ -263,7 +262,7 @@ namespace ComSquare::CPU
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! @brief The main CPU
|
//! @brief The main CPU
|
||||||
class CPU : public CommonInstructions, public Memory::IMemory {
|
class CPU : public Memory::IMemory {
|
||||||
private:
|
private:
|
||||||
//! @brief All the registers of the CPU
|
//! @brief All the registers of the CPU
|
||||||
Registers _registers{};
|
Registers _registers{};
|
||||||
@@ -358,6 +357,8 @@ namespace ComSquare::CPU
|
|||||||
void LDX(uint24_t addr);
|
void LDX(uint24_t addr);
|
||||||
//! @brief Load the Y index register from memory.
|
//! @brief Load the Y index register from memory.
|
||||||
void LDY(uint24_t addr);
|
void LDY(uint24_t addr);
|
||||||
|
//! @brief Set status bits.
|
||||||
|
void SEP(uint24_t addr);
|
||||||
public:
|
public:
|
||||||
explicit CPU(std::shared_ptr<Memory::MemoryBus> bus, Cartridge::Header &cartridgeHeader);
|
explicit CPU(std::shared_ptr<Memory::MemoryBus> bus, Cartridge::Header &cartridgeHeader);
|
||||||
CPU(const CPU &) = default;
|
CPU(const CPU &) = default;
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by anonymus-raccoon on 2/5/20.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "CommonInstructions.hpp"
|
|
||||||
|
|
||||||
namespace ComSquare::CPU
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by anonymus-raccoon on 2/5/20.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef COMSQUARE_COMMONINSTRUCTIONS_HPP
|
|
||||||
#define COMSQUARE_COMMONINSTRUCTIONS_HPP
|
|
||||||
|
|
||||||
namespace ComSquare::CPU
|
|
||||||
{
|
|
||||||
//! @brief The shared states of the Main's CPU and the APU's CPU.
|
|
||||||
class CommonInstructions {
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //COMSQUARE_COMMONINSTRUCTIONS_HPP
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by anonymus-raccoon on 2/13/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../CPU.hpp"
|
||||||
|
|
||||||
|
namespace ComSquare::CPU
|
||||||
|
{
|
||||||
|
void CPU::SEP(uint24_t addr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
//
|
|
||||||
// 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];
|
|
||||||
std::memset(this->_data, 0, size * sizeof(uint8_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+30
-7
@@ -5,36 +5,59 @@
|
|||||||
#ifndef COMSQUARE_RAM_HPP
|
#ifndef COMSQUARE_RAM_HPP
|
||||||
#define COMSQUARE_RAM_HPP
|
#define COMSQUARE_RAM_HPP
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include "../Memory/IRectangleMemory.hpp"
|
#include "../Memory/IRectangleMemory.hpp"
|
||||||
|
#include "../Exceptions/InvalidAddress.hpp"
|
||||||
|
|
||||||
namespace ComSquare::Ram
|
namespace ComSquare::Ram
|
||||||
{
|
{
|
||||||
|
template<typename T>
|
||||||
class Ram : public Memory::IRectangleMemory {
|
class Ram : public Memory::IRectangleMemory {
|
||||||
private:
|
private:
|
||||||
//! @brief The ram. (Can be used for WRam, SRam, VRam etc)
|
//! @brief The ram. (Can be used for WRam, SRam, VRam etc)
|
||||||
uint8_t *_data;
|
T *_data;
|
||||||
//! @brief The size of the ram.
|
//! @brief The size of the ram.
|
||||||
size_t _size;
|
size_t _size;
|
||||||
public:
|
public:
|
||||||
//! @brief Load a rom from it's path.
|
//! @brief Create a ram of the given size (in bytes).
|
||||||
explicit Ram(size_t size);
|
explicit Ram(size_t size)
|
||||||
|
: _size(size)
|
||||||
|
{
|
||||||
|
this->_data = new T[size];
|
||||||
|
std::memset(this->_data, 0, size * sizeof(T));
|
||||||
|
}
|
||||||
//! @brief The ram can't be copied.
|
//! @brief The ram can't be copied.
|
||||||
Ram(const Ram &) = delete;
|
Ram(const Ram &) = delete;
|
||||||
//! @brief The ram can't be assigned.
|
//! @brief The ram can't be assigned.
|
||||||
Ram &operator=(Ram &) = delete;
|
Ram &operator=(Ram &) = delete;
|
||||||
//! @brief Destructor that free the ram.
|
//! @brief Destructor that free the ram.
|
||||||
~Ram();
|
~Ram()
|
||||||
|
{
|
||||||
|
delete[] this->_data;
|
||||||
|
}
|
||||||
//! @brief Read from the 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.
|
//! @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.
|
//! @throw InvalidAddress will be thrown if the address is more than the size of the ram.
|
||||||
//! @return Return the data at the address.
|
//! @return Return the data at the address.
|
||||||
uint8_t read_internal(uint24_t addr) override;
|
T read_internal(uint24_t addr) override
|
||||||
|
{
|
||||||
|
if (addr >= this->_size)
|
||||||
|
throw InvalidAddress("Ram read", addr);
|
||||||
|
return this->_data[addr];
|
||||||
|
}
|
||||||
//! @brief Write data to the ram.
|
//! @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 addr The address to write to. The address 0x0 should refer to the first byte of this ram.
|
||||||
//! @param data The data to write.
|
//! @param data The data to write.
|
||||||
//! @throw InvalidAddress will be thrown if the address is more than the size of the ram.
|
//! @throw InvalidAddress will be thrown if the address is more than the size of the ram.
|
||||||
void write_internal(uint24_t addr, uint8_t data) override;
|
void write_internal(uint24_t addr, T data) override
|
||||||
|
{
|
||||||
|
if (addr >= this->_size)
|
||||||
|
throw InvalidAddress("Ram write", addr);
|
||||||
|
this->_data[addr] = data;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef Ram<uint8_t> BasicRam;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //COMSQUARE_RAM_HPP
|
#endif //COMSQUARE_RAM_HPP
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ namespace ComSquare
|
|||||||
cpu(new CPU::CPU(bus, cartridge->header)),
|
cpu(new CPU::CPU(bus, cartridge->header)),
|
||||||
ppu(new PPU::PPU(bus, renderer)),
|
ppu(new PPU::PPU(bus, renderer)),
|
||||||
apu(new APU::APU()),
|
apu(new APU::APU()),
|
||||||
wram(new Ram::Ram(16384)),
|
wram(new Ram::BasicRam(16384)),
|
||||||
sram(new Ram::Ram(this->cartridge->header.sramSize))
|
sram(new Ram::BasicRam(this->cartridge->header.sramSize))
|
||||||
{
|
{
|
||||||
bus->mapComponents(*this);
|
bus->mapComponents(*this);
|
||||||
renderer.setWindowName(this->cartridge->header.gameName);
|
renderer.setWindowName(this->cartridge->header.gameName);
|
||||||
|
|||||||
+2
-2
@@ -27,9 +27,9 @@ namespace ComSquare
|
|||||||
//! @brief Audio Processing Unit if the SNES
|
//! @brief Audio Processing Unit if the SNES
|
||||||
std::shared_ptr<APU::APU> apu;
|
std::shared_ptr<APU::APU> apu;
|
||||||
//! @brief Work Ram shared by all the components.
|
//! @brief Work Ram shared by all the components.
|
||||||
std::shared_ptr<Ram::Ram> wram;
|
std::shared_ptr<Ram::BasicRam> wram;
|
||||||
//! @brief Save Ram residing inside the Cartridge in a real SNES.
|
//! @brief Save Ram residing inside the Cartridge in a real SNES.
|
||||||
std::shared_ptr<Ram::Ram> sram;
|
std::shared_ptr<Ram::BasicRam> sram;
|
||||||
//! @brief Create all the components using a common memory bus for all of them.
|
//! @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 std::shared_ptr<Memory::MemoryBus> &bus, const std::string &ramPath, Renderer::IRenderer &renderer);
|
||||||
SNES(const SNES &) = default;
|
SNES(const SNES &) = default;
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// Created by anonymus-raccoon on 2/13/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <criterion/criterion.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <bitset>
|
||||||
|
#include "../tests.hpp"
|
||||||
|
#include "../../sources/SNES.hpp"
|
||||||
|
#include "../../sources/Memory/MemoryBus.hpp"
|
||||||
|
using namespace ComSquare;
|
||||||
|
|
||||||
|
Test(SEP, setall)
|
||||||
|
{
|
||||||
|
auto pair = Init();
|
||||||
|
pair.second.cpu.SEP()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user