From 5fd85abaa77b32d53e9a264e3346f8d2e4630a56 Mon Sep 17 00:00:00 2001 From: AnonymusRaccoon Date: Wed, 5 Feb 2020 15:18:22 +0100 Subject: [PATCH] Finishing the LoRom mapping --- sources/Memory/MemoryBus.cpp | 6 +++++- sources/Memory/RectangleShadow.cpp | 3 ++- sources/Ram/Ram.cpp | 4 ++-- sources/Ram/Ram.hpp | 8 ++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sources/Memory/MemoryBus.cpp b/sources/Memory/MemoryBus.cpp index b920e3c..6a2ecf5 100644 --- a/sources/Memory/MemoryBus.cpp +++ b/sources/Memory/MemoryBus.cpp @@ -57,7 +57,7 @@ namespace ComSquare::Memory void MemoryBus::mapComponents(SNES &console) { // The WRam and PU registers are always mapped at the same address no matter the mapping mode. - console.wram->setMemoryRegion(0x7E0000, 0x7FFFFF); + console.wram->setMemoryRegion(0x7E, 0x7F, 0x0000, 0xFFFF); this->_memoryAccessors.push_back(console.wram); console.ppu->setMemoryRegion(0x2100, 0x2140); @@ -88,6 +88,10 @@ 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)); + + 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)); } } } \ No newline at end of file diff --git a/sources/Memory/RectangleShadow.cpp b/sources/Memory/RectangleShadow.cpp index 4840283..2da6c26 100644 --- a/sources/Memory/RectangleShadow.cpp +++ b/sources/Memory/RectangleShadow.cpp @@ -16,12 +16,13 @@ namespace ComSquare::Memory uint8_t RectangleShadow::read_internal(uint24_t addr) { - // TODO implement read/write bank offset. + addr += this->_bankOffset << 16u; return this->_initial->read_internal(addr); } void RectangleShadow::write_internal(uint24_t addr, uint8_t data) { + addr += this->_bankOffset << 16u; this->_initial->write_internal(addr, data); } diff --git a/sources/Ram/Ram.cpp b/sources/Ram/Ram.cpp index d29182e..ac1ad4a 100644 --- a/sources/Ram/Ram.cpp +++ b/sources/Ram/Ram.cpp @@ -18,14 +18,14 @@ namespace ComSquare::Ram delete[] this->_data; } - uint8_t Ram::read(uint24_t addr) + uint8_t Ram::read_internal(uint24_t addr) { if (addr >= this->_size) throw InvalidAddress("Ram read", addr); return this->_data[addr]; } - void Ram::write(uint24_t addr, uint8_t data) + void Ram::write_internal(uint24_t addr, uint8_t data) { if (addr >= this->_size) throw InvalidAddress("Ram write", addr); diff --git a/sources/Ram/Ram.hpp b/sources/Ram/Ram.hpp index e4eca02..1b15255 100644 --- a/sources/Ram/Ram.hpp +++ b/sources/Ram/Ram.hpp @@ -5,11 +5,11 @@ #ifndef COMSQUARE_RAM_HPP #define COMSQUARE_RAM_HPP -#include "../Memory/IMemory.hpp" +#include "../Memory/IRectangleMemory.hpp" namespace ComSquare::Ram { - class Ram : public Memory::IMemory { + class Ram : public Memory::IRectangleMemory { private: //! @brief The ram. (Can be used for WRam, SRam, VRam etc) uint8_t *_data; @@ -24,12 +24,12 @@ namespace ComSquare::Ram //! @param addr The address to read from. The address 0x0 should refer to the first byte of this ram. //! @throw InvalidAddress will be thrown if the address is more than the size of the ram. //! @return Return the data at the address. - uint8_t read(uint24_t addr) override; + uint8_t read_internal(uint24_t addr) override; //! @brief Write data to the ram. //! @param addr The address to write to. The address 0x0 should refer to the first byte of this ram. //! @param data The data to write. //! @throw InvalidAddress will be thrown if the address is more than the size of the ram. - void write(uint24_t addr, uint8_t data) override; + void write_internal(uint24_t addr, uint8_t data) override; }; }