From 476a2b2c562f40694306b9641505b41c73ae9681 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Tue, 9 Jun 2020 11:19:49 -0230 Subject: [PATCH] Make sure to use correct 'virtual' size of ROM when creating the internal buffer. --- src/emucore/CartEnhanced.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/emucore/CartEnhanced.cxx b/src/emucore/CartEnhanced.cxx index 5295364f1..c462cbcc8 100644 --- a/src/emucore/CartEnhanced.cxx +++ b/src/emucore/CartEnhanced.cxx @@ -52,7 +52,8 @@ CartridgeEnhanced::CartridgeEnhanced(const ByteBuffer& image, size_t size, } } else - mySize = size; + // Make sure to use size defined by the bankswitching scheme + mySize = std::max(size, bsSize); // Initialize ROM with all 0's, to fill areas that the ROM may not cover size_t bufSize = std::max(mySize, System::PAGE_SIZE); @@ -73,7 +74,9 @@ CartridgeEnhanced::CartridgeEnhanced(const ByteBuffer& image, size_t size, // TODO: should we mirror here too?? // Directly copy the ROM image into the buffer - std::copy_n(image.get(), mySize, myImage.get()); + // Only copy up to the amount of data the ROM provides; extra unused + // space will be filled with 0's from above + std::copy_n(image.get(), std::min(mySize, size), myImage.get()); } else {