mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-28 08:33:34 +00:00
git pushMerge branch 'CPU' of https://github.com/AnonymusRaccoon/ComSquare
This commit is contained in:
+3
-3
@@ -9,6 +9,8 @@ add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||
|
||||
# make unit tests
|
||||
add_executable(unit_tests
|
||||
tests/CPU/testAddressingMode.cpp
|
||||
tests/tests.cpp
|
||||
tests/CPU/testCPU.cpp
|
||||
tests/testMemoryBus.cpp
|
||||
tests/tests.hpp
|
||||
@@ -50,9 +52,7 @@ add_executable(unit_tests
|
||||
sources/CPU/Instructions/CommonInstructions.hpp
|
||||
sources/Exceptions/InvalidOpcode.hpp
|
||||
sources/CPU/Instructions/Interrupts.cpp
|
||||
sources/CPU/Instructions/MathematicalOperations.cpp
|
||||
tests/CPU/testAddressingMode.cpp
|
||||
tests/tests.cpp)
|
||||
sources/CPU/Instructions/MathematicalOperations.cpp)
|
||||
|
||||
# include criterion & coverage
|
||||
target_link_libraries(unit_tests criterion -lgcov)
|
||||
|
||||
@@ -14,9 +14,9 @@ namespace ComSquare::Cartridge
|
||||
{
|
||||
Cartridge::Cartridge(const std::string &romPath)
|
||||
{
|
||||
if (romPath.empty())
|
||||
return;
|
||||
try {
|
||||
if (romPath.empty())
|
||||
throw InvalidRomException("Path is empty.");
|
||||
size_t size = Cartridge::getRomSize(romPath);
|
||||
FILE *rom = fopen(romPath.c_str(), "rb");
|
||||
|
||||
@@ -49,7 +49,6 @@ namespace ComSquare::Cartridge
|
||||
|
||||
uint8_t Cartridge::read_internal(uint24_t addr)
|
||||
{
|
||||
std::cout << "Reading a addr: " << std::hex << addr << " romStart: " << std::hex << _romStart << std::endl;
|
||||
if (addr >= this->_size)
|
||||
throw InvalidAddress("Cartridge read", addr);
|
||||
return this->_data[addr + this->_romStart];
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Created by anonymus-raccoon on 1/27/20.
|
||||
//
|
||||
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include "SNES.hpp"
|
||||
|
||||
namespace ComSquare
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
using namespace ComSquare;
|
||||
|
||||
|
||||
Test(AddrModeInit, LegitBus)
|
||||
{
|
||||
auto pair = Init();
|
||||
cr_assert_eq(pair.first.get(), pair.second.cpu->_bus.get(), "Warning, the CPU's bus is not the same the SNES's bus. Next tests of the CPU may fail.");
|
||||
}
|
||||
|
||||
Test(AddrMode, Immediate)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
+43
-43
@@ -29,7 +29,7 @@ Test(BusAccessor, GetWramStart)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x7E0000);
|
||||
accessor = pair.first->getAccessor(0x7E0000);
|
||||
cr_assert_eq(accessor.get(), pair.second.wram.get());
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ Test(BusAccessor, GetWramEnd)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x7FFFFF);
|
||||
accessor = pair.first->getAccessor(0x7FFFFF);
|
||||
cr_assert_eq(accessor.get(), pair.second.wram.get());
|
||||
}
|
||||
|
||||
@@ -47,14 +47,14 @@ Test(BusAccessor, GetWramMirror)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::MemoryShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first.getAccessor(0x2F11FF));
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first->getAccessor(0x2F11FF));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.wram.get());
|
||||
}
|
||||
|
||||
Test(BusAccessor, GetOpenBus)
|
||||
{
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = pair.first.getAccessor(0x897654);
|
||||
std::shared_ptr<Memory::IMemory> accessor = pair.first->getAccessor(0x897654);
|
||||
cr_assert_eq(accessor.get(), nullptr);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ Test(BusAccessor, GetSramStart)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::RectangleShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first.getAccessor(0x700000));
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first->getAccessor(0x700000));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.sram.get());
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ Test(BusAccessor, GetSramEnd)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::RectangleShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first.getAccessor(0x7D7FFF));
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first->getAccessor(0x7D7FFF));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.sram.get());
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ Test(BusAccessor, GetSramMirror)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IRectangleMemory> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::IRectangleMemory>(pair.first.getAccessor(0xF00123));
|
||||
accessor = std::static_pointer_cast<Memory::IRectangleMemory>(pair.first->getAccessor(0xF00123));
|
||||
cr_assert_eq(accessor.get(), pair.second.sram.get());
|
||||
}
|
||||
|
||||
@@ -91,8 +91,8 @@ Test(BusAccessor, GetSramMirror)
|
||||
// std::shared_ptr<Memory::RectangleShadow> accessor = nullptr;
|
||||
//
|
||||
// // TODO implement the SRam accessor for the FE/FF.
|
||||
// //std::cout << pair.first.getAccessor(0xFE0123) << std::endl;
|
||||
// accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first.getAccessor(0xFE0123));
|
||||
// //std::cout << pair.first->getAccessor(0xFE0123) << std::endl;
|
||||
// accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first->getAccessor(0xFE0123));
|
||||
// cr_assert_eq(accessor->_initial.get(), pair.second.sram.get());
|
||||
//}
|
||||
|
||||
@@ -101,7 +101,7 @@ Test(BusAccessor, GetAPUStart)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x002140);
|
||||
accessor = pair.first->getAccessor(0x002140);
|
||||
cr_assert_eq(accessor.get(), pair.second.apu.get());
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ Test(BusAccessor, GetAPUEnd)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x002143);
|
||||
accessor = pair.first->getAccessor(0x002143);
|
||||
cr_assert_eq(accessor.get(), pair.second.apu.get());
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ Test(BusAccessor, GetAPUMirror)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::MemoryShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first.getAccessor(0xAB2143));
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first->getAccessor(0xAB2143));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.apu.get());
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ Test(BusAccessor, GetCPUStart)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x004200);
|
||||
accessor = pair.first->getAccessor(0x004200);
|
||||
cr_assert_eq(accessor.get(), pair.second.cpu.get());
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ Test(BusAccessor, GetCPUEnd)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x00421F);
|
||||
accessor = pair.first->getAccessor(0x00421F);
|
||||
cr_assert_eq(accessor.get(), pair.second.cpu.get());
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ Test(BusAccessor, GetPPU1Start)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x00213E);
|
||||
accessor = pair.first->getAccessor(0x00213E);
|
||||
cr_assert_eq(accessor.get(), pair.second.ppu.get());
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ Test(BusAccessor, GetPPU1End)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x00213F);
|
||||
accessor = pair.first->getAccessor(0x00213F);
|
||||
cr_assert_eq(accessor.get(), pair.second.ppu.get());
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ Test(BusAccessor, GetCPU)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x004212);
|
||||
accessor = pair.first->getAccessor(0x004212);
|
||||
cr_assert_eq(accessor.get(), pair.second.cpu.get());
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ Test(BusAccessor, GetPPU1Mirror)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::MemoryShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first.getAccessor(0x80213F));
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first->getAccessor(0x80213F));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.ppu.get());
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ Test(BusAccessor, GetCPU2Mirror)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::MemoryShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first.getAccessor(0x804212));
|
||||
accessor = std::static_pointer_cast<Memory::MemoryShadow>(pair.first->getAccessor(0x804212));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.cpu.get());
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ Test(BusAccessor, GetRomStart)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0x808000);
|
||||
accessor = pair.first->getAccessor(0x808000);
|
||||
cr_assert_eq(accessor.get(), pair.second.cartridge.get());
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ Test(BusAccessor, GetRomEnd)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::IMemory> accessor = nullptr;
|
||||
|
||||
accessor = pair.first.getAccessor(0xFFFFFF);
|
||||
accessor = pair.first->getAccessor(0xFFFFFF);
|
||||
cr_assert_eq(accessor.get(), pair.second.cartridge.get());
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ Test(BusAccessor, GetRomMirror)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::RectangleShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first.getAccessor(0x694200));
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first->getAccessor(0x694200));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get());
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ Test(BusAccessor, GetRomMirror2)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::RectangleShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first.getAccessor(0x01FEDC));
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first->getAccessor(0x01FEDC));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get());
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ Test(BusAccessor, GetRomMirror3)
|
||||
auto pair = Init();
|
||||
std::shared_ptr<Memory::RectangleShadow> accessor = nullptr;
|
||||
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first.getAccessor(0xDE1248));
|
||||
accessor = std::static_pointer_cast<Memory::RectangleShadow>(pair.first->getAccessor(0xDE1248));
|
||||
cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get());
|
||||
}
|
||||
|
||||
@@ -242,8 +242,8 @@ Test(BusRead, ReadOutside, .init = cr_redirect_stdout)
|
||||
auto pair = Init();
|
||||
uint8_t data;
|
||||
|
||||
pair.first._openBus = 123;
|
||||
data = pair.first.read(0x002000);
|
||||
pair.first->_openBus = 123;
|
||||
data = pair.first->read(0x002000);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -252,8 +252,8 @@ Test(BusRead, ReadOutside2, .init = cr_redirect_stdout)
|
||||
auto pair = Init();
|
||||
uint8_t data;
|
||||
|
||||
pair.first._openBus = 123;
|
||||
data = pair.first.read(0xBF2FFF);
|
||||
pair.first->_openBus = 123;
|
||||
data = pair.first->read(0xBF2FFF);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -262,8 +262,8 @@ Test(BusRead, ReadOutside3, .init = cr_redirect_stdout)
|
||||
auto pair = Init();
|
||||
uint8_t data;
|
||||
|
||||
pair.first._openBus = 123;
|
||||
data = pair.first.read(0x127654);
|
||||
pair.first->_openBus = 123;
|
||||
data = pair.first->read(0x127654);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ Test(BusRead, ReadAPU)
|
||||
uint8_t data;
|
||||
|
||||
pair.second.apu->_registers.port0 = 123;
|
||||
data = pair.first.read(0x002140);
|
||||
data = pair.first->read(0x002140);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ Test(BusRead, ReadROM)
|
||||
uint8_t data;
|
||||
|
||||
pair.second.cartridge->_data[5] = 123;
|
||||
data = pair.first.read(0x808005);
|
||||
data = pair.first->read(0x808005);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ Test(BusRead, ReadROMStart)
|
||||
uint8_t data;
|
||||
|
||||
pair.second.cartridge->_data[0] = 123;
|
||||
data = pair.first.read(0x808000);
|
||||
data = pair.first->read(0x808000);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ Test(BusRead, ReadCPU)
|
||||
uint8_t data;
|
||||
|
||||
pair.second.cpu->_internalRegisters.wrio = 123;
|
||||
data = pair.first.read(0x004201);
|
||||
data = pair.first->read(0x004201);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ Test(BusRead, ReadPPU)
|
||||
uint8_t data;
|
||||
|
||||
pair.second.ppu->mpy.mpyl = 123;
|
||||
data = pair.first.read(0x002134);
|
||||
data = pair.first->read(0x002134);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ Test(BusRead, ReadSRAM)
|
||||
uint8_t data;
|
||||
|
||||
pair.second.sram->_data[7] = 123;
|
||||
data = pair.first.read(0x700007);
|
||||
data = pair.first->read(0x700007);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ Test(BusRead, ReadWRAM)
|
||||
uint8_t data;
|
||||
|
||||
pair.second.wram->_data[3] = 123;
|
||||
data = pair.first.read(0x7E0003);
|
||||
data = pair.first->read(0x7E0003);
|
||||
cr_assert_eq(data, 123);
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ Test(BusWrite, WriteAPU)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
pair.first.write(0x002143, 123);
|
||||
pair.first->write(0x002143, 123);
|
||||
cr_assert_eq(pair.second.apu->_registers.port3, 123);
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ Test(BusWrite, WritePPU)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
pair.first.write(0x002106, 123);
|
||||
pair.first->write(0x002106, 123);
|
||||
cr_assert_eq(pair.second.ppu->mosaic.raw, 123);
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ Test(BusWrite, WriteCPU)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
pair.first.write(0x00420D, 123);
|
||||
pair.first->write(0x00420D, 123);
|
||||
cr_assert_eq(pair.second.cpu->_internalRegisters.memsel, 123);
|
||||
}
|
||||
|
||||
@@ -371,14 +371,14 @@ Test(BusWrite, WriteROM)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
cr_assert_throw(pair.first.write(0x808005, 123), InvalidAction);
|
||||
cr_assert_throw(pair.first->write(0x808005, 123), InvalidAction);
|
||||
}
|
||||
|
||||
Test(BusWrite, WriteWRAM)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
pair.first.write(0x7E0002, 123);
|
||||
pair.first->write(0x7E0002, 123);
|
||||
cr_assert_eq(pair.second.wram->_data[2], 123);
|
||||
}
|
||||
|
||||
@@ -386,6 +386,6 @@ Test(BusWrite, WriteSRAM)
|
||||
{
|
||||
auto pair = Init();
|
||||
|
||||
pair.first.write(0x700009, 123);
|
||||
pair.first->write(0x700009, 123);
|
||||
cr_assert_eq(pair.second.sram->_data[9], 123);
|
||||
}
|
||||
+6
-4
@@ -3,22 +3,24 @@
|
||||
//
|
||||
|
||||
#include <criterion/criterion.h>
|
||||
#include <iostream>
|
||||
#include <zconf.h>
|
||||
#include "tests.hpp"
|
||||
#include "../sources/Renderer/NoRenderer.hpp"
|
||||
#include "../sources/SNES.hpp"
|
||||
|
||||
using namespace ComSquare;
|
||||
|
||||
std::pair<Memory::MemoryBus, SNES> Init()
|
||||
std::pair<std::shared_ptr<Memory::MemoryBus>, SNES> Init()
|
||||
{
|
||||
Memory::MemoryBus bus;
|
||||
std::shared_ptr<Memory::MemoryBus> bus = std::make_shared<Memory::MemoryBus>();
|
||||
Renderer::NoRenderer norenderer(0, 0, 0);
|
||||
SNES snes(std::make_shared<Memory::MemoryBus>(bus), "", norenderer);
|
||||
SNES snes(bus, "../tests/my_cartridge", norenderer);
|
||||
snes.cartridge->_size = 100;
|
||||
snes.cartridge->_data = new uint8_t[snes.cartridge->_size];
|
||||
snes.cartridge->header.mappingMode = Cartridge::LoRom;
|
||||
snes.sram->_size = 10;
|
||||
snes.sram->_data = new uint8_t[snes.cartridge->_size];
|
||||
bus.mapComponents(snes);
|
||||
bus->mapComponents(snes);
|
||||
return std::make_pair(bus, snes);
|
||||
}
|
||||
+1
-1
@@ -10,6 +10,6 @@
|
||||
#define class struct
|
||||
|
||||
#include "../sources/Memory/MemoryBus.hpp"
|
||||
std::pair<ComSquare::Memory::MemoryBus, ComSquare::SNES> Init();
|
||||
std::pair<std::shared_ptr<ComSquare::Memory::MemoryBus>, ComSquare::SNES> Init();
|
||||
|
||||
#endif //COMSQUARE_TESTS_HPP
|
||||
|
||||
Reference in New Issue
Block a user