From fb3438aac705534ddfb64e6adbf056511530301f Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Tue, 9 Jun 2020 12:32:14 -0230 Subject: [PATCH] Make sure 3E+ ROMs are always internally sized as a multiple 1024 bytes. --- src/common/bspf.hxx | 6 ++++++ src/emucore/Cart3E.cxx | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 24fe8d0a7..a887bf80a 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -140,6 +140,12 @@ namespace BSPF return power2; } + // Get next multiple of the given value + // Note that this only works when multiple is a power of two + inline size_t nextMultipleOf(size_t size, size_t multiple) { + return (size + multiple - 1) & ~(multiple - 1); + } + // Make 2D-arrays using std::array less verbose template using array2D = std::array, ROW>; diff --git a/src/emucore/Cart3E.cxx b/src/emucore/Cart3E.cxx index 263c8b2e9..b03175477 100644 --- a/src/emucore/Cart3E.cxx +++ b/src/emucore/Cart3E.cxx @@ -22,7 +22,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cartridge3E::Cartridge3E(const ByteBuffer& image, size_t size, const string& md5, const Settings& settings) - : CartridgeEnhanced(image, size, BSPF::nextPowerOfTwo(size), md5, settings) + : CartridgeEnhanced(image, size, BSPF::nextMultipleOf(size, 1_KB), md5, settings) { myBankShift = BANK_SHIFT; myRamSize = RAM_SIZE;