Fixing rectangle memory endPage inclusivness

This commit is contained in:
Zoe Roux
2021-02-04 11:13:04 +01:00
parent 2e1ede5016
commit 04f9b9a8fc
5 changed files with 16 additions and 15 deletions

View File

@@ -13,7 +13,7 @@ namespace ComSquare::Memory
uint8_t bank = addr >> 16u; uint8_t bank = addr >> 16u;
uint16_t page = addr; uint16_t page = addr;
unsigned bankCount = bank - this->_startBank; unsigned bankCount = bank - this->_startBank;
unsigned pageCount = this->_endPage - this->_startPage; unsigned pageCount = this->_endPage + 1 - this->_startPage;
if (bank < this->_startBank || bank > this->_endBank) if (bank < this->_startBank || bank > this->_endBank)
throw InvalidAddress("Rectangle memory: Invalid Bank", addr); throw InvalidAddress("Rectangle memory: Invalid Bank", addr);

View File

@@ -21,7 +21,7 @@ namespace ComSquare::Memory
uint24_t RectangleShadow::getRelativeAddress(uint24_t addr) const uint24_t RectangleShadow::getRelativeAddress(uint24_t addr) const
{ {
uint24_t base = ARectangleMemory::getRelativeAddress(addr); uint24_t base = ARectangleMemory::getRelativeAddress(addr);
return base + this->_bankOffset * (this->_endPage - this->_startPage); return base + this->_bankOffset * (1 + this->_endPage - this->_startPage);
} }
uint8_t RectangleShadow::read(uint24_t addr) const uint8_t RectangleShadow::read(uint24_t addr) const
@@ -34,7 +34,7 @@ namespace ComSquare::Memory
return this->_initial->write(addr, data); return this->_initial->write(addr, data);
} }
RectangleShadow *RectangleShadow::setBankOffset(uint8_t bankOffset) RectangleShadow *RectangleShadow::setBankOffset(int bankOffset)
{ {
this->_bankOffset = bankOffset; this->_bankOffset = bankOffset;
return this; return this;

View File

@@ -15,7 +15,7 @@ namespace ComSquare::Memory
//! @brief Memory to shadow from. //! @brief Memory to shadow from.
std::shared_ptr<IMemory> _initial; std::shared_ptr<IMemory> _initial;
//! @brief The number of banks to add to the memory before accessing it from the initial data. //! @brief The number of banks to add to the memory before accessing it from the initial data.
uint8_t _bankOffset = 0; int _bankOffset = 0;
public: public:
//! @brief Create a shadow for the memory given as parameter. //! @brief Create a shadow for the memory given as parameter.
explicit RectangleShadow(std::shared_ptr<IMemory> initial, uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage); explicit RectangleShadow(std::shared_ptr<IMemory> initial, uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage);
@@ -52,6 +52,7 @@ namespace ComSquare::Memory
//! @return nullptr if isMirror is false, the source otherwise. //! @return nullptr if isMirror is false, the source otherwise.
std::shared_ptr<IMemory> getMirrored() const override; std::shared_ptr<IMemory> getMirrored() const override;
RectangleShadow *setBankOffset(uint8_t bankOffset); //! @brief Set the number of bank this component do not shadow. Referring to the first byte of this component will refer to the first byte of the bank at (bankOffset + start of initial memory).
RectangleShadow *setBankOffset(int bankOffset);
}; };
} }

View File

@@ -13,8 +13,8 @@ Test(DMA, RomToVRAM)
snes.cartridge->_size = 4000000; snes.cartridge->_size = 4000000;
snes.cartridge->_data = new uint8_t[snes.cartridge->_size]; snes.cartridge->_data = new uint8_t[snes.cartridge->_size];
for (unsigned i = 0; i < 0x400; i++) { for (unsigned i = 0; i < 0x400; i++) {
snes.cartridge->_data[0x9bded + i * 2] = i; snes.cartridge->_data[0x9be00 + i * 2] = i;
snes.cartridge->_data[0x9bded + i * 2 + 1] = i >> 8; snes.cartridge->_data[0x9be00 + i * 2 + 1] = i >> 8;
} }
// Transferring $800 bytes from ROM ($13BE00) to VRam ($2000) via DMA channel 0 // Transferring $800 bytes from ROM ($13BE00) to VRam ($2000) via DMA channel 0

View File

@@ -12,7 +12,7 @@ using namespace ComSquare;
Test(RectangleMemory, HorizontalRamRead) Test(RectangleMemory, HorizontalRamRead)
{ {
Ram::Ram ram(0xFF, Component::Rom, "Rom"); Ram::Ram ram(0xFF, Component::Rom, "Rom");
ram.setMemoryRegion(0x00, 0xFF, 0x0000, 0x0001); ram.setMemoryRegion(0x00, 0xFF, 0x0000, 0x0000);
for (int i = 0x00; i < 0xFF; i++) for (int i = 0x00; i < 0xFF; i++)
ram._data[i] = i; ram._data[i] = i;
for (uint24_t i = 0x000000; i < 0xFF0000; i += 0x010000) { for (uint24_t i = 0x000000; i < 0xFF0000; i += 0x010000) {
@@ -24,7 +24,7 @@ Test(RectangleMemory, HorizontalRamRead)
Test(RectangleMemory, HorizontalRamWrite) Test(RectangleMemory, HorizontalRamWrite)
{ {
Ram::Ram ram(0xFF, Component::Rom, "Rom"); Ram::Ram ram(0xFF, Component::Rom, "Rom");
ram.setMemoryRegion(0x00, 0xFF, 0x0000, 0x0001); ram.setMemoryRegion(0x00, 0xFF, 0x0000, 0x0000);
for (uint24_t i = 0x000000; i < 0xFF0000; i += 0x010000) for (uint24_t i = 0x000000; i < 0xFF0000; i += 0x010000)
ram.write(ram.getRelativeAddress(i), i >> 16u); ram.write(ram.getRelativeAddress(i), i >> 16u);
for (int i = 0x00; i < 0xFF; i++) for (int i = 0x00; i < 0xFF; i++)
@@ -34,7 +34,7 @@ Test(RectangleMemory, HorizontalRamWrite)
Test(RectangleMemory, DualLineRamRead) Test(RectangleMemory, DualLineRamRead)
{ {
Ram::Ram ram(0xFF * 2, Component::Rom, "Rom"); Ram::Ram ram(0xFF * 2, Component::Rom, "Rom");
ram.setMemoryRegion(0x00, 0xFF, 0x0000, 0x0002); ram.setMemoryRegion(0x00, 0xFF, 0x0000, 0x0001);
for (int i = 0x00; i < 0xFF * 2; i++) for (int i = 0x00; i < 0xFF * 2; i++)
ram._data[i] = i; ram._data[i] = i;
for (uint24_t i = 0x000000, v = 0; v < 0xFF * 2; i += 0x010000, v += 2) { for (uint24_t i = 0x000000, v = 0; v < 0xFF * 2; i += 0x010000, v += 2) {
@@ -48,8 +48,8 @@ Test(RectangleMemory, DualLineRamRead)
Test(RectangleMemory, HorizontalRamShadowRead) Test(RectangleMemory, HorizontalRamShadowRead)
{ {
std::shared_ptr<Ram::Ram> ram = std::make_shared<Ram::Ram>(0xFF, Component::Rom, "Rom"); std::shared_ptr<Ram::Ram> ram = std::make_shared<Ram::Ram>(0xFF, Component::Rom, "Rom");
ram->setMemoryRegion(0x00, 0xFF, 0x0000, 0x0001); ram->setMemoryRegion(0x00, 0xFF, 0x0000, 0x0000);
Memory::RectangleShadow shadow(ram, 0x00, 0xFF, 0x8000, 0x8001); Memory::RectangleShadow shadow(ram, 0x00, 0xFF, 0x8000, 0x8000);
for (int i = 0x00; i < 0xFF; i++) for (int i = 0x00; i < 0xFF; i++)
ram->_data[i] = i; ram->_data[i] = i;
for (uint24_t i = 0x008000; i < 0xFF8000; i += 0x010000) { for (uint24_t i = 0x008000; i < 0xFF8000; i += 0x010000) {
@@ -60,8 +60,8 @@ Test(RectangleMemory, HorizontalRamShadowRead)
Test(RectangleMemory, HorizontalRamShadowReadWithBankOffset) Test(RectangleMemory, HorizontalRamShadowReadWithBankOffset)
{ {
std::shared_ptr<Ram::Ram> ram = std::make_shared<Ram::Ram>(0xFF, Component::Rom, "Rom"); std::shared_ptr<Ram::Ram> ram = std::make_shared<Ram::Ram>(0xFF, Component::Rom, "Rom");
ram->setMemoryRegion(0x00, 0xFF, 0x0000, 0x0001); ram->setMemoryRegion(0x00, 0xFF, 0x0000, 0x0000);
Memory::RectangleShadow shadow(ram, 0x80, 0xFF, 0x8000, 0x8001); Memory::RectangleShadow shadow(ram, 0x80, 0xFF, 0x8000, 0x8000);
for (int i = 0x00; i < 0xFF; i++) for (int i = 0x00; i < 0xFF; i++)
ram->_data[i] = i; ram->_data[i] = i;
shadow.setBankOffset(0x80); shadow.setBankOffset(0x80);
@@ -79,7 +79,7 @@ Test(RectangleMemory, ShadowOffsetCartridge)
for (int i = 0x00; i < 0x3fff80; i++) for (int i = 0x00; i < 0x3fff80; i++)
ram->_data[i] = i; ram->_data[i] = i;
shadow.setBankOffset(0x40); shadow.setBankOffset(0x40);
for (uint24_t i = 0xC00000; i < 0xEF7FFF; i += 0x1) { for (uint24_t i = 0xC00000; i <= 0xEF7FFF; i += 0x1) {
if ((uint16_t)i > 0x7FFFu) if ((uint16_t)i > 0x7FFFu)
i += 0x010000 - 0x8000; i += 0x010000 - 0x8000;
uint8_t v = shadow.read(shadow.getRelativeAddress(i)); uint8_t v = shadow.read(shadow.getRelativeAddress(i));