diff --git a/CMakeLists.txt b/CMakeLists.txt index db0a08a..8fbb775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,8 @@ set(SOURCES sources/APU/APU.cpp sources/Exceptions/InvalidAddress.hpp sources/Exceptions/InvalidRom.hpp - sources/Models/Int24.hpp - sources/Models/Int24.hpp + sources/Models/Ints.hpp + sources/Models/Ints.hpp sources/Ram/Ram.cpp sources/Ram/Ram.hpp sources/Memory/MemoryShadow.cpp @@ -186,16 +186,11 @@ add_executable(unit_tests EXCLUDE_FROM_ALL ) target_include_directories(unit_tests PUBLIC tests) target_compile_definitions(unit_tests PUBLIC TESTS) - +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/libs) +find_package(Catch2 REQUIRED) +target_link_libraries(unit_tests PRIVATE Catch2::Catch2WithMain) if (CMAKE_COMPILER_IS_GNUCXX) # target_link_libraries(unit_tests PRIVATE -lgcov) # target_compile_options(unit_tests PUBLIC -fprofile-arcs -ftest-coverage) endif () - -find_package(Catch2 QUIET) -if (NOT Catch2_FOUND) - set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/libs) - find_package(Catch2 REQUIRED) -endif () -target_link_libraries(unit_tests PRIVATE Catch2::Catch2) diff --git a/libs/FindCatch2.cmake b/libs/FindCatch2.cmake index 155962e..9bf8cf8 100644 --- a/libs/FindCatch2.cmake +++ b/libs/FindCatch2.cmake @@ -1,13 +1,13 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.11) +cmake_minimum_required(VERSION 3.11) -if (NOT Catch2_FOUND) - Include(FetchContent) - - FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v2.13.6) - - FetchContent_MakeAvailable(Catch2) +include(FetchContent) +FetchContent_Declare(Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.0.0-preview3 +) +FetchContent_GetProperties(Catch2) +if(NOT Catch2_POPULATED) + FetchContent_Populate(Catch2) + add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR} EXCLUDE_FROM_ALL) endif() diff --git a/sources/APU/Operand.cpp b/sources/APU/Operand.cpp index 2c2adf3..4874ec5 100644 --- a/sources/APU/Operand.cpp +++ b/sources/APU/Operand.cpp @@ -2,7 +2,7 @@ // Created by Melefo on 24/02/2020. // -#include "../Models/Int24.hpp" +#include "../Models/Ints.hpp" #include "APU.hpp" namespace ComSquare::APU diff --git a/sources/CPU/AddressingModes.cpp b/sources/CPU/AddressingModes.cpp index 7242008..698b68b 100644 --- a/sources/CPU/AddressingModes.cpp +++ b/sources/CPU/AddressingModes.cpp @@ -2,7 +2,7 @@ // Created by anonymus-raccoon on 3/20/20. // -#include "../Models/Int24.hpp" +#include "../Models/Ints.hpp" #include "CPU.hpp" namespace ComSquare::CPU diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index 99bc554..dd0dd9c 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -7,7 +7,7 @@ #include "Memory/AMemory.hpp" #include "Memory/MemoryBus.hpp" -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" #include "Models/Callback.hpp" #include "Cartridge/Cartridge.hpp" #include "Memory/AMemory.hpp" diff --git a/sources/CPU/DMA/DMA.hpp b/sources/CPU/DMA/DMA.hpp index b612966..f2ead65 100644 --- a/sources/CPU/DMA/DMA.hpp +++ b/sources/CPU/DMA/DMA.hpp @@ -5,7 +5,7 @@ #pragma once #include "Memory/MemoryBus.hpp" -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" #include #include diff --git a/sources/CPU/Instruction.hpp b/sources/CPU/Instruction.hpp index 599ff6c..03a31e4 100644 --- a/sources/CPU/Instruction.hpp +++ b/sources/CPU/Instruction.hpp @@ -5,7 +5,7 @@ #pragma once #include -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" namespace ComSquare::CPU { diff --git a/sources/CPU/Instructions/BitsInstructions.cpp b/sources/CPU/Instructions/BitsInstructions.cpp index 681da65..6664282 100644 --- a/sources/CPU/Instructions/BitsInstructions.cpp +++ b/sources/CPU/Instructions/BitsInstructions.cpp @@ -3,7 +3,7 @@ // #include -#include "../../Models/Int24.hpp" +#include "../../Models/Ints.hpp" #include "../CPU.hpp" namespace ComSquare::CPU diff --git a/sources/CPU/Registers.hpp b/sources/CPU/Registers.hpp index 95b012c..6998578 100644 --- a/sources/CPU/Registers.hpp +++ b/sources/CPU/Registers.hpp @@ -5,7 +5,7 @@ #pragma once -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" namespace ComSquare::CPU { diff --git a/sources/Cartridge/Cartridge.hpp b/sources/Cartridge/Cartridge.hpp index a0c533a..2d2f288 100644 --- a/sources/Cartridge/Cartridge.hpp +++ b/sources/Cartridge/Cartridge.hpp @@ -7,7 +7,7 @@ #include "InterruptVectors.hpp" #include "Memory/AMemory.hpp" #include "Memory/ARectangleMemory.hpp" -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" #include "Ram/Ram.hpp" #include #include diff --git a/sources/Debugger/CPU/CPUDebug.hpp b/sources/Debugger/CPU/CPUDebug.hpp index 34f6623..2a5c15f 100644 --- a/sources/Debugger/CPU/CPUDebug.hpp +++ b/sources/Debugger/CPU/CPUDebug.hpp @@ -7,7 +7,7 @@ #include "Debugger/ClosableWindow.hpp" #include "Exceptions/DebuggableError.hpp" #include "ui/ui_cpuView.h" -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" #include "Memory/MemoryBus.hpp" #include "CPU/Instruction.hpp" #include diff --git a/sources/Debugger/RegisterViewer.hpp b/sources/Debugger/RegisterViewer.hpp index 2c9c792..9ebedc7 100644 --- a/sources/Debugger/RegisterViewer.hpp +++ b/sources/Debugger/RegisterViewer.hpp @@ -6,7 +6,7 @@ #include "ClosableWindow.hpp" #include "Memory/MemoryBus.hpp" -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" #include "ui/ui_registersView.h" #include #include diff --git a/sources/Exceptions/InvalidAddress.hpp b/sources/Exceptions/InvalidAddress.hpp index fabe48d..d1bec40 100644 --- a/sources/Exceptions/InvalidAddress.hpp +++ b/sources/Exceptions/InvalidAddress.hpp @@ -5,6 +5,7 @@ #pragma once #include "DebuggableError.hpp" +#include "Models/Ints.hpp" #include #include #include @@ -22,7 +23,7 @@ namespace ComSquare InvalidAddress(std::string where, uint24_t addr) { std::stringstream stream; - stream << "Could not read/write data at address: 0x" << std::hex << addr << " from " << where; + stream << "Could not read/write data at address: " << addr << " from " << where; this->_msg = stream.str(); } const char *what() const noexcept override { return this->_msg.c_str(); } diff --git a/sources/Memory/AMemory.hpp b/sources/Memory/AMemory.hpp index 120766a..9da70d5 100644 --- a/sources/Memory/AMemory.hpp +++ b/sources/Memory/AMemory.hpp @@ -8,7 +8,7 @@ #include #include #include -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" #include "Models/Components.hpp" #include "IMemory.hpp" diff --git a/sources/Memory/ARectangleMemory.hpp b/sources/Memory/ARectangleMemory.hpp index c2efc7f..d4b011f 100644 --- a/sources/Memory/ARectangleMemory.hpp +++ b/sources/Memory/ARectangleMemory.hpp @@ -5,6 +5,7 @@ #pragma once #include "IMemory.hpp" +#include "Models/Ints.hpp" namespace ComSquare::Memory { diff --git a/sources/Memory/IMemory.hpp b/sources/Memory/IMemory.hpp index 8b59811..ef4647b 100644 --- a/sources/Memory/IMemory.hpp +++ b/sources/Memory/IMemory.hpp @@ -8,7 +8,7 @@ #include #include #include -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" #include "Models/Components.hpp" namespace ComSquare::Memory diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp index 8e026d9..c0824b2 100644 --- a/sources/Memory/MemoryBus.cpp +++ b/sources/Memory/MemoryBus.cpp @@ -27,7 +27,7 @@ namespace ComSquare::Memory IMemory *handler = this->getAccessor(addr); if (!handler) { - log(LogLevel::WARNING, "Unknown memory accessor for address $" << std::hex << addr << ". Using open bus."); + logMsg(LogLevel::WARNING, "Unknown memory accessor for address $" << std::hex << addr << ". Using open bus."); return this->_openBus; } @@ -62,7 +62,7 @@ namespace ComSquare::Memory IMemory *handler = this->getAccessor(addr); if (!handler) { - log(LogLevel::ERROR, "Unknown memory accessor for address " << std::hex << addr << ". Warning, it was a write."); + logMsg(LogLevel::ERROR, "Unknown memory accessor for address " << std::hex << addr << ". Warning, it was a write."); return; } handler->write(handler->getRelativeAddress(addr), data); diff --git a/sources/Models/Int24.hpp b/sources/Models/Int24.hpp deleted file mode 100644 index fafdc1d..0000000 --- a/sources/Models/Int24.hpp +++ /dev/null @@ -1,7 +0,0 @@ -// -// Created by anonymus-raccoon on 1/28/20. -// - -#pragma once - -typedef unsigned uint24_t; diff --git a/sources/Models/Ints.hpp b/sources/Models/Ints.hpp new file mode 100644 index 0000000..12d35a3 --- /dev/null +++ b/sources/Models/Ints.hpp @@ -0,0 +1,13 @@ +// +// Created by anonymus-raccoon on 1/28/20. +// + +#pragma once + +#include +#include + +typedef unsigned uint24_t; + + +std::ostream &operator<<(std::ostream &os, uint8_t value); \ No newline at end of file diff --git a/sources/Models/Logger.hpp b/sources/Models/Logger.hpp index eda0069..d56e1af 100644 --- a/sources/Models/Logger.hpp +++ b/sources/Models/Logger.hpp @@ -23,10 +23,10 @@ namespace ComSquare constexpr LogLevel GlobalLevel = INFO; #ifndef TESTS -#define log(level, message) \ +#define logMsg(level, message) \ if constexpr((level) >= GlobalLevel) \ std::cout << message << std::endl // NOLINT(bugprone-macro-parentheses) #else -#define log(_, msg) INFO(msg) +#define logMsg(_, msg) INFO(msg) #endif } \ No newline at end of file diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 5b6ed62..af8d550 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -58,7 +58,7 @@ namespace ComSquare::Renderer } #ifdef DEBUGGER_ENABLED catch (const DebuggableError &e) { - log(LogLevel::ERROR, "Invalid rom's instruction: " << e.what()); + logMsg(LogLevel::ERROR, "Invalid rom's instruction: " << e.what()); this->_snes.enableCPUDebuggingWithError(e); } #endif diff --git a/sources/SNES.cpp b/sources/SNES.cpp index f4a8dc5..4ff23cd 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -15,7 +15,9 @@ namespace ComSquare cpu(this->bus, cartridge.header), ppu(renderer), apu(renderer) - {} + { + this->bus.mapComponents(*this); + } SNES::SNES(const std::string &romPath, Renderer::IRenderer &renderer) : bus(), diff --git a/sources/Utility/Utility.cpp b/sources/Utility/Utility.cpp index c7a37b0..0a8d8f0 100644 --- a/sources/Utility/Utility.cpp +++ b/sources/Utility/Utility.cpp @@ -55,6 +55,9 @@ namespace ComSquare::Utility { return std::bitset<24>(i).to_string(); } +} - const std::string WHITESPACES = " \t\n\r\f\v"; +std::ostream &operator<<(std::ostream &os, uint8_t value) +{ + return os << ComSquare::Utility::to_hex(value); } \ No newline at end of file diff --git a/sources/Utility/Utility.hpp b/sources/Utility/Utility.hpp index 94b8268..b469c1f 100644 --- a/sources/Utility/Utility.hpp +++ b/sources/Utility/Utility.hpp @@ -7,7 +7,7 @@ #include #include #include -#include "Models/Int24.hpp" +#include "Models/Ints.hpp" namespace ComSquare::Utility { @@ -25,5 +25,5 @@ namespace ComSquare::Utility std::string to_binary(uint16_t i); std::string to_binary(uint24_t i); - extern const std::string WHITESPACES; + constexpr std::string_view WHITESPACES = " \t\n\r\f\v"; } \ No newline at end of file diff --git a/tests/PPU/testPpuWriteFromVmain.cpp b/tests/PPU/testPpuWriteFromVmain.cpp index 065809d..b094bbc 100644 --- a/tests/PPU/testPpuWriteFromVmain.cpp +++ b/tests/PPU/testPpuWriteFromVmain.cpp @@ -2,13 +2,13 @@ // Created by cbihan on 2/11/20. // -#include -#include +#include "Models/Ints.hpp" #include -#include "../tests.hpp" -#include "../../sources/SNES.hpp" -#include "../../sources/Memory/MemoryBus.hpp" -#include "../../sources/PPU/PPU.hpp" +#include "tests.hpp" +#include +#include "SNES.hpp" +#include "Memory/MemoryBus.hpp" +#include "PPU/PPU.hpp" using namespace ComSquare; TEST_CASE("vmain_data_full PPU_write_2", "[PPU_write_2]") diff --git a/tests/tests.hpp b/tests/tests.hpp index 3574ac9..3580280 100644 --- a/tests/tests.hpp +++ b/tests/tests.hpp @@ -11,7 +11,6 @@ #define private public #define protected public -#define class struct #include "Renderer/NoRenderer.hpp" #include "SNES.hpp"