diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp index 837146d..6ff8d2b 100644 --- a/sources/Memory/MemoryBus.cpp +++ b/sources/Memory/MemoryBus.cpp @@ -48,12 +48,14 @@ namespace ComSquare void MemoryBus::_mirrorComponents(SNES &console, int i) { this->_memoryAccessors.push_back(Memory::MemoryShadow::createShadow(console.wram, i, i + 0x2000)); + this->_memoryAccessors.push_back(Memory::MemoryShadow::createShadow(console.ppu, i + 0x2100, i + 0x2140)); + this->_memoryAccessors.push_back(Memory::MemoryShadow::createShadow(console.apu, i + 0x2140, i + 0x2144)); this->_memoryAccessors.push_back(Memory::MemoryShadow::createShadow(console.cpu, i + 0x4200, i + 0x4220)); } void MemoryBus::mapComponents(SNES &console) { - // The WRam is always mapped in the bank 7E and 7F, no matter the memory mapping mode. + // The WRam and PU registers are always mapped at the same address no matter the mapping mode. console.wram->setMemoryRegion(0x7E0000, 0x7FFFFF); this->_memoryAccessors.push_back(console.wram); @@ -67,14 +69,15 @@ namespace ComSquare this->_memoryAccessors.push_back(console.cpu); // TODO implement DMA & HDMA (4220 to 4300) + // TODO implement Joys. - //Mirror the first $2000 bits of the WRam to all banks of the Q1 & Q3. - for (uint24_t i = 0; i < 0x400000; i += 0x10000) { + // Map to the quarter 1. + for (uint24_t i = 0; i < 0x400000; i += 0x10000) this->_mirrorComponents(console, i); - } - for (uint24_t i = 0x800000; i < 0xC00000; i += 0x10000) { - this->_memoryAccessors.push_back(Memory::MemoryShadow::createShadow(console.wram, i, i + 0x2000)); - this->_memoryAccessors.push_back(Memory::MemoryShadow::createShadow(console.cpu, i + 0x4200, i + 0x4220)); - } + // Map to the quarter 3. + for (uint24_t i = 0x800000; i < 0xC00000; i += 0x10000) + this->_mirrorComponents(console, i); + + // TODO should map sram, cartridge etc via the mapping mode of the cartridge. } } \ No newline at end of file diff --git a/sources/Memory/MemoryBus.hpp b/sources/Memory/MemoryBus.hpp index 3ad6c01..2494e56 100644 --- a/sources/Memory/MemoryBus.hpp +++ b/sources/Memory/MemoryBus.hpp @@ -23,7 +23,7 @@ namespace ComSquare std::shared_ptr getAccessor(uint24_t addr); //! @brief The last value read via the memory bus. uint8_t _openbus = 0; - //! @brief Mirror components to other banks. (Used by the mapComponents method). + //! @brief WRam, CPU, PPU & ALU registers are mirrored to all banks of Q1 & Q3. This function is used for the mirroring. //! @param console All the components. //! @param i Base address for the mirrors. inline void _mirrorComponents(struct SNES &console, int i);