From 6cc5cd5c3a89e4724738f14f6873919bb5807f4f Mon Sep 17 00:00:00 2001 From: AnonymusRaccoon Date: Thu, 6 Feb 2020 18:30:30 +0100 Subject: [PATCH] Solving some tests --- sources/Memory/MemoryBus.cpp | 4 +++- sources/Memory/RectangleShadow.hpp | 2 +- tests/testMemoryBus.cpp | 37 ++++++++++++++++-------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp index f3d6caa..24dd473 100644 --- a/sources/Memory/MemoryBus.cpp +++ b/sources/Memory/MemoryBus.cpp @@ -87,10 +87,12 @@ namespace ComSquare::Memory this->_memoryAccessors.emplace_back(new Memory::RectangleShadow(console.cartridge, 0x00, 0x7D, 0x8000, 0xFFFF)); // Mirror on the lower half of the Q2. this->_memoryAccessors.emplace_back((new Memory::RectangleShadow(console.cartridge, 0x40, 0x6F, 0x0000, 0x7FFF))->setBankOffset(0x40)); + // Mirror on the lower half of the Q4 + this->_memoryAccessors.emplace_back((new Memory::RectangleShadow(console.cartridge, 0xC0, 0xF0, 0x0000, 0x7FFF))->setBankOffset(0x40)); console.sram->setMemoryRegion(0x70, 0x7D, 0x0000, 0x7FFF); this->_memoryAccessors.push_back(console.sram); - this->_memoryAccessors.emplace_back(new Memory::RectangleShadow(console.sram, 0xFE, 0xFF, 0x0000, 0x7FFF)); + this->_memoryAccessors.emplace_back(new Memory::RectangleShadow(console.sram, 0xF0, 0xFD, 0x0000, 0x7FFF)); } // TODO should implement HiRom. } diff --git a/sources/Memory/RectangleShadow.hpp b/sources/Memory/RectangleShadow.hpp index 40b37da..c418f24 100644 --- a/sources/Memory/RectangleShadow.hpp +++ b/sources/Memory/RectangleShadow.hpp @@ -16,7 +16,7 @@ namespace ComSquare::Memory //! @brief Memory to shadow from. std::shared_ptr _initial; //! @brief The number of banks to add to the memory before accessing it from the initial data. - uint8_t _bankOffset; + uint8_t _bankOffset = 0; public: //! @brief Create a shadow for the memory given as parameter. explicit RectangleShadow(std::shared_ptr initial, uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage); diff --git a/tests/testMemoryBus.cpp b/tests/testMemoryBus.cpp index 714ae05..d6f027e 100644 --- a/tests/testMemoryBus.cpp +++ b/tests/testMemoryBus.cpp @@ -60,13 +60,11 @@ Test(BusAccessor, GetWramMirror) cr_assert_eq(accessor->_initial.get(), pair.second.wram.get()); } -Test(BusAccessor, GetWramMirror2) +Test(BusAccessor, GetOpenBus) { auto pair = Init(); - std::shared_ptr accessor = nullptr; - - accessor = pair.first.getAccessor(0x897654); - cr_assert_eq(accessor.get(), pair.second.wram.get()); + std::shared_ptr accessor = pair.first.getAccessor(0x897654); + cr_assert_eq(accessor.get(), nullptr); } Test(BusAccessor, GetSramStart) @@ -90,19 +88,24 @@ Test(BusAccessor, GetSramEnd) Test(BusAccessor, GetSramMirror) { auto pair = Init(); - std::shared_ptr accessor = nullptr; + std::shared_ptr accessor = nullptr; - accessor = pair.first.getAccessor(0xF00123); - cr_assert_eq(accessor.get(), pair.second.sram.get()); + accessor = std::static_pointer_cast(pair.first.getAccessor(0xF00123)); + // TODO the page of the rectangle accessor seems a bit buggy and here the rom is returned as the accessor. + std::cout << std::hex << accessor->_initial->getStart() << std::endl; + std::cout << std::hex << pair.second.sram.get() << std::endl; + cr_assert_eq(accessor->_initial.get(), pair.second.sram.get()); } Test(BusAccessor, GetSramMirror2) { auto pair = Init(); - std::shared_ptr accessor = nullptr; + std::shared_ptr accessor = nullptr; - accessor = pair.first.getAccessor(0xFE0123); - cr_assert_eq(accessor.get(), pair.second.sram.get()); + // TODO implement the SRam accessor for the FE/FF. + std::cout << pair.first.getAccessor(0xFE0123) << std::endl; + accessor = std::static_pointer_cast(pair.first.getAccessor(0xFE0123)); + cr_assert_eq(accessor->_initial.get(), pair.second.sram.get()); } Test(BusAccessor, GetAPUStart) @@ -225,19 +228,19 @@ Test(BusAccessor, GetRomMirror) Test(BusAccessor, GetRomMirror2) { auto pair = Init(); - std::shared_ptr accessor = nullptr; + std::shared_ptr accessor = nullptr; - accessor = pair.first.getAccessor(0x01FEDC); - cr_assert_eq(accessor.get(), pair.second.cartridge.get()); + accessor = std::static_pointer_cast(pair.first.getAccessor(0x01FEDC)); + cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get()); } Test(BusAccessor, GetRomMirror3) { auto pair = Init(); - std::shared_ptr accessor = nullptr; + std::shared_ptr accessor = nullptr; - accessor = pair.first.getAccessor(0xDE1248); - cr_assert_eq(accessor.get(), pair.second.cartridge.get()); + accessor = std::static_pointer_cast(pair.first.getAccessor(0xDE1248)); + cr_assert_eq(accessor->_initial.get(), pair.second.cartridge.get()); } ////////////////////////////