From 6693c30df251b080cbb17ce68c78a65ea8d14930 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 5 Jul 2021 20:46:48 +0200 Subject: [PATCH] Fixing unit tests compilation --- sources/APU/APU.cpp | 5 -- sources/APU/APU.hpp | 26 +++--- sources/Debugger/APUDebug.cpp | 105 +++++++++++-------------- sources/Debugger/APUDebug.hpp | 22 ++---- sources/PPU/PPU.cpp | 5 -- sources/PPU/PPU.hpp | 2 - sources/Renderer/QtRenderer/QtSFML.cpp | 2 +- sources/SNES.cpp | 14 ++-- sources/SNES.hpp | 8 +- tests/CPU/testDMA.cpp | 8 +- tests/PPU/testPpuWriteFromVmain.cpp | 4 +- 11 files changed, 81 insertions(+), 120 deletions(-) diff --git a/sources/APU/APU.cpp b/sources/APU/APU.cpp index c9dfbf8..03f9a6d 100644 --- a/sources/APU/APU.cpp +++ b/sources/APU/APU.cpp @@ -19,11 +19,6 @@ namespace ComSquare::APU this->reset(); } - bool APU::isDebugger() const - { - return false; - } - std::string APU::getName() const { return "APU"; diff --git a/sources/APU/APU.hpp b/sources/APU/APU.hpp index d65257b..66d7066 100644 --- a/sources/APU/APU.hpp +++ b/sources/APU/APU.hpp @@ -2,16 +2,15 @@ // Created by Melefo on 24/01/2020. // -#ifndef COMSQUARE_APU_HPP -#define COMSQUARE_APU_HPP +#pragma once #include #include "DSP/DSP.hpp" -#include "../Memory/AMemory.hpp" -#include "../Ram/Ram.hpp" +#include "Memory/AMemory.hpp" +#include "Ram/Ram.hpp" #include "IPL/IPL.hpp" -#include "../Renderer/IRenderer.hpp" -#include "../Cartridge/Cartridge.hpp" +#include "Renderer/IRenderer.hpp" +#include "Cartridge/Cartridge.hpp" namespace ComSquare::APU { @@ -154,7 +153,7 @@ namespace ComSquare::APU //! @param addr The address to read from. The address 0x0000 should refer to the first byte of the register. //! @throw InvalidAddress will be thrown if the address is more than $FFFF (the number of register). //! @return Return the data. - uint8_t _internalRead(uint24_t addr) const; + [[nodiscard]] uint8_t _internalRead(uint24_t addr) const; //! @brief Write data to the APU ram. //! @param addr The address to write to. The address 0x0000 should refer to the first byte of register. @@ -369,7 +368,7 @@ namespace ComSquare::APU public: explicit APU(Renderer::IRenderer &renderer); APU(const APU &) = default; - APU &operator=(const APU &) = default; + APU &operator=(const APU &) = delete; ~APU() override = default; //! @brief Read from the APU ram. @@ -385,10 +384,10 @@ namespace ComSquare::APU void write(uint24_t addr, uint8_t data) override; //! @brief Get the name of this accessor (used for debug purpose) - std::string getName() const override; + [[nodiscard]] std::string getName() const override; //! @brief Get the component of this accessor (used for debug purpose) - Component getComponent() const override; + [[nodiscard]] Component getComponent() const override; //! @brief Get the name of the data at the address //! @param addr The address (in local space) @@ -396,7 +395,7 @@ namespace ComSquare::APU //! @brief Get the size of the data. This size can be lower than the mapped data. //! @return The number of bytes inside this memory. - uint24_t getSize() const override; + [[nodiscard]] uint24_t getSize() const override; //! @brief Parses rom data to uploads directly into RAM and corresponding registers void loadFromSPC(Cartridge::Cartridge &cartridge); @@ -407,10 +406,5 @@ namespace ComSquare::APU //! @brief This function is executed when the SNES is powered on or the reset button is pushed. void reset(); - - //! @brief Return true if the CPU is overloaded with debugging features. - virtual bool isDebugger() const; }; } - -#endif //COMSQUARE_APU_HPP diff --git a/sources/Debugger/APUDebug.cpp b/sources/Debugger/APUDebug.cpp index ccc6ad3..111deac 100644 --- a/sources/Debugger/APUDebug.cpp +++ b/sources/Debugger/APUDebug.cpp @@ -10,16 +10,12 @@ using namespace ComSquare::APU; namespace ComSquare::Debugger { - APUDebug::APUDebug(APU &apu, SNES &snes) : - APU(apu), - _window(new ClosableWindow(*this, &APUDebug::disableDebugger)), - _ui(), - _snes(snes) + APUDebug::APUDebug(APU &apu, SNES &snes) + : APU(apu), + _window(new ClosableWindow([&snes] { snes.disableAPUDebugging(); })), + _ui(), + _snes(snes) { - this->_window->setContextMenuPolicy(Qt::NoContextMenu); - this->_window->setAttribute(Qt::WA_QuitOnClose, false); - this->_window->setAttribute(Qt::WA_DeleteOnClose); - this->_ui.setupUi(this->_window); QMainWindow::connect(this->_ui.resumeButton, &QPushButton::clicked, this, &APUDebug::pause); QMainWindow::connect(this->_ui.stepButton, &QPushButton::clicked, this, &APUDebug::step); @@ -302,46 +298,46 @@ namespace ComSquare::Debugger std::string APUDebug::_getOperand(Operand ope) { switch (ope) { - case None: - return ""; - case A: - return Utility::to_hex(this->_internalRegisters.a); - case X: - return Utility::to_hex(this->_internalRegisters.x); - case Y: - return Utility::to_hex(this->_internalRegisters.y); - case SP: - return Utility::to_hex(this->_internalRegisters.sp); - case PSW: - return Utility::to_hex(this->_internalRegisters.psw); - case ImmediateData: - return Utility::to_hex(this->_getImmediateData()); - case IndexXAddr: - return Utility::to_hex(this->_getIndexXAddr()); - case IndexYAddr: - return Utility::to_hex(this->_getIndexYAddr()); - case AbsoluteAddr: - return Utility::to_hex(this->_getAbsoluteAddr()); - case AbsoluteBit: { - auto pair = this->_getAbsoluteBit(); - return Utility::to_hex(std::get<0>(pair)) + Utility::to_hex(std::get<1>(pair)); - } - case AbsoluteAddrByX: - return Utility::to_hex(this->_getAbsoluteAddrByX()); - case AbsoluteAddrByY: - return Utility::to_hex(this->_getAbsoluteAddrByY()); - case AbsoluteByXAddr: - return Utility::to_hex(this->_getAbsoluteByXAddr()); - case AbsoluteDirectByXAddr: - return Utility::to_hex(this->_getAbsoluteDirectByXAddr()); - case AbsoluteDirectAddrByY: - return Utility::to_hex(this->_getAbsoluteDirectAddrByY()); - case DirectAddr: - return Utility::to_hex(this->_getDirectAddr()); - case DirectAddrByX: - return Utility::to_hex(this->_getDirectAddrByX()); - case DirectAddrByY: - return Utility::to_hex(this->_getDirectAddrByY()); + case None: + return ""; + case A: + return Utility::to_hex(this->_internalRegisters.a); + case X: + return Utility::to_hex(this->_internalRegisters.x); + case Y: + return Utility::to_hex(this->_internalRegisters.y); + case SP: + return Utility::to_hex(this->_internalRegisters.sp); + case PSW: + return Utility::to_hex(this->_internalRegisters.psw); + case ImmediateData: + return Utility::to_hex(this->_getImmediateData()); + case IndexXAddr: + return Utility::to_hex(this->_getIndexXAddr()); + case IndexYAddr: + return Utility::to_hex(this->_getIndexYAddr()); + case AbsoluteAddr: + return Utility::to_hex(this->_getAbsoluteAddr()); + case AbsoluteBit: { + auto pair = this->_getAbsoluteBit(); + return Utility::to_hex(std::get<0>(pair)) + Utility::to_hex(std::get<1>(pair)); + } + case AbsoluteAddrByX: + return Utility::to_hex(this->_getAbsoluteAddrByX()); + case AbsoluteAddrByY: + return Utility::to_hex(this->_getAbsoluteAddrByY()); + case AbsoluteByXAddr: + return Utility::to_hex(this->_getAbsoluteByXAddr()); + case AbsoluteDirectByXAddr: + return Utility::to_hex(this->_getAbsoluteDirectByXAddr()); + case AbsoluteDirectAddrByY: + return Utility::to_hex(this->_getAbsoluteDirectAddrByY()); + case DirectAddr: + return Utility::to_hex(this->_getDirectAddr()); + case DirectAddrByX: + return Utility::to_hex(this->_getDirectAddrByX()); + case DirectAddrByY: + return Utility::to_hex(this->_getDirectAddrByY()); } return "UNKNOWN"; } @@ -396,17 +392,6 @@ namespace ComSquare::Debugger this->_ui.resumeButton->setText("Pause"); } - - void APUDebug::disableDebugger() - { - this->_snes.disableAPUDebugging(); - } - - bool APUDebug::isDebugger() const - { - return true; - } - void APUDebug::focus() { this->_window->activateWindow(); diff --git a/sources/Debugger/APUDebug.hpp b/sources/Debugger/APUDebug.hpp index ff00a54..838e176 100644 --- a/sources/Debugger/APUDebug.hpp +++ b/sources/Debugger/APUDebug.hpp @@ -2,12 +2,11 @@ // Created by Melefo on 19/02/2020. // -#ifndef COMSQUARE_APUDEBUG_HPP -#define COMSQUARE_APUDEBUG_HPP +#pragma once -#include "../APU/APU.hpp" -#include "../SNES.hpp" -#include "../../ui/ui_apuView.h" +#include "APU/APU.hpp" +#include "SNES.hpp" +#include "ui/ui_apuView.h" namespace ComSquare::Debugger { @@ -43,11 +42,11 @@ namespace ComSquare::Debugger std::tuple operands; }; - class APUDebug : public APU::APU, public QObject + class APUDebug : public QObject { private: //! @brief List of instructions and their information - std::array _instructions {{ + const std::array _instructions {{ {"NOP", 1, {None, None}}, {"TCALL", 1, {None, None}}, {"SET1", 2, {DirectAddr, None}}, @@ -313,7 +312,7 @@ namespace ComSquare::Debugger int _appendInstruction(int row); //! @brief The QT window for this debugger. - ClosableWindow *_window; + ClosableWindow *_window; //! @brief A widget that contain the whole UI. Ui::APUView _ui; @@ -358,12 +357,7 @@ namespace ComSquare::Debugger //! @brief Override the apu's update to disable debugging. void update(unsigned cycles) override; - //! @brief Return true if the CPU is overloaded with debugging features. - bool isDebugger() const override; - //! @brief Focus the debugger's window. void focus(); }; -} - -#endif //COMSQUARE_APUDEBUG_HPP \ No newline at end of file +} \ No newline at end of file diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 966f7a9..893ed01 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -470,11 +470,6 @@ namespace ComSquare::PPU return Ppu; } - bool PPU::isDebugger() const - { - return false; - } - uint16_t PPU::cgramRead(uint16_t addr) { return this->cgram.read(addr); diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index ad51b07..6045d4a 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -607,8 +607,6 @@ namespace ComSquare::PPU uint16_t getVramAddress() const; //! @brief Give the name of the Address register (used for debug) std::string getValueName(uint24_t addr) const; - //! @brief Return true if the CPU is overloaded with debugging features. - virtual bool isDebugger() const; //! @brief Allow others components to read the CGRAM uint16_t cgramRead(uint16_t addr); //! @brief get the bpp depending of the bgNumber and the Bgmode diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 9dec948..7eee14f 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -90,7 +90,7 @@ namespace ComSquare::Renderer void QtFullSFML::enableDebugAPU() { -// this->_snes.enableAPUDebugging(); + this->_snes.enableAPUDebugging(); } void QtFullSFML::enableDebugBus() diff --git a/sources/SNES.cpp b/sources/SNES.cpp index b7fcbfa..6ccf04d 100644 --- a/sources/SNES.cpp +++ b/sources/SNES.cpp @@ -101,21 +101,21 @@ namespace ComSquare this->_headerViewer = std::nullopt; } -// void SNES::enableAPUDebugging() -// { + void SNES::enableAPUDebugging() + { // if (this->apu->isDebugger()) // std::static_pointer_cast(this->apu)->focus(); // else { // this->apu = std::make_shared(*this->apu, *this); // this->bus.mapComponents(*this); // } -// } -// -// void SNES::disableAPUDebugging() -// { + } + + void SNES::disableAPUDebugging() + { // this->apu = std::make_shared(*this->apu); // this->bus.mapComponents(*this); -// } + } void SNES::enableMemoryBusDebugging() { diff --git a/sources/SNES.hpp b/sources/SNES.hpp index a9b376d..53185aa 100644 --- a/sources/SNES.hpp +++ b/sources/SNES.hpp @@ -102,10 +102,10 @@ namespace ComSquare void disableHeaderViewer(); //! @brief Enable the Header's debugging window. void enableHeaderViewer(); -// //! @brief Disable the APU's debugging window. -// void disableAPUDebugging(); -// //! @brief Enable the APU's debugging window. -// void enableAPUDebugging(); + //! @brief Disable the APU's debugging window. + void disableAPUDebugging(); + //! @brief Enable the APU's debugging window. + void enableAPUDebugging(); //! @brief Disable the Memory Bus's debugging window. void disableMemoryBusDebugging(); //! @brief Enable the Memory Bus's debugging window. diff --git a/tests/CPU/testDMA.cpp b/tests/CPU/testDMA.cpp index 3bd4282..dc4d600 100644 --- a/tests/CPU/testDMA.cpp +++ b/tests/CPU/testDMA.cpp @@ -52,7 +52,7 @@ TEST_CASE("RomToVRAM DMA", "[DMA]") REQUIRE(snes.cpu._dmaChannels[0]._port == 0x18); REQUIRE(snes.ppu._registers._vmadd.vmadd == 0x2400); for(unsigned i = 0; i < 0x400; i++) { - uint16_t value = snes.ppu.vram->_data[0x2000 * 2 + i * 2] | (snes.ppu.vram->_data[0x2000 * 2 + i * 2 + 1] << 8); + uint16_t value = snes.ppu.vram._data[0x2000 * 2 + i * 2] | (snes.ppu.vram._data[0x2000 * 2 + i * 2 + 1] << 8); REQUIRE(value == i); } REQUIRE(snes.cpu._dmaChannels[0].enabled == false); @@ -69,7 +69,7 @@ TEST_CASE("VramWrite DMA", "[DMA]") REQUIRE(snes.ppu._registers._vmadd.vmadd == 0x2001 + i); } for(unsigned i = 0; i < 0x400; i++) { - uint16_t value = snes.ppu.vram->_data[0x2000 * 2 + i * 2] | (snes.ppu.vram->_data[0x2000 * 2 + i * 2 + 1] << 8); + uint16_t value = snes.ppu.vram._data[0x2000 * 2 + i * 2] | (snes.ppu.vram._data[0x2000 * 2 + i * 2 + 1] << 8); REQUIRE(value == (uint16_t)i); } } @@ -86,7 +86,7 @@ TEST_CASE("VramWriteInvertedOrder DMA", "[DMA]") REQUIRE(snes.ppu._registers._vmadd.vmadd == 0x2001 + i); } for(unsigned i = 0; i < 0x400; i++) { - uint16_t value = snes.ppu.vram->_data[0x2000 * 2 + i * 2] | (snes.ppu.vram->_data[0x2000 * 2 + i * 2 + 1] << 8); + uint16_t value = snes.ppu.vram._data[0x2000 * 2 + i * 2] | (snes.ppu.vram._data[0x2000 * 2 + i * 2 + 1] << 8); REQUIRE(value == (uint16_t)i); } } @@ -133,7 +133,7 @@ TEST_CASE("WRamToVRAM DMA", "[DMA]") REQUIRE(snes.cpu._dmaChannels[0]._port == 0x18); REQUIRE(snes.ppu._registers._vmadd.vmadd == 0x0400); for(unsigned i = 0; i < 0x400; i++) { - uint16_t value = snes.ppu.vram->_data[i * 2] | (snes.ppu.vram->_data[i * 2 + 1] << 8); + uint16_t value = snes.ppu.vram._data[i * 2] | (snes.ppu.vram._data[i * 2 + 1] << 8); REQUIRE(value == i); } REQUIRE(snes.cpu._dmaChannels[0].enabled == false); diff --git a/tests/PPU/testPpuWriteFromVmain.cpp b/tests/PPU/testPpuWriteFromVmain.cpp index 34c2f9f..065809d 100644 --- a/tests/PPU/testPpuWriteFromVmain.cpp +++ b/tests/PPU/testPpuWriteFromVmain.cpp @@ -64,8 +64,8 @@ TEST_CASE("vmadd_full_data_check_ram PPU_write_2", "[PPU_write_2]") snes.bus.write(0x2118, 0xFF); snes.bus.write(0x2119, 0xFF); REQUIRE(snes.ppu._registers._vmadd.vmadd == 3); - REQUIRE(snes.ppu.vram->read(4) == 0xFF); - REQUIRE(snes.ppu.vram->read(5) == 0xF); + REQUIRE(snes.ppu.vram.read(4) == 0xFF); + REQUIRE(snes.ppu.vram.read(5) == 0xF); } TEST_CASE("vmadd_full_high_byte_null PPU_write_2", "[PPU_write_2]")