From c1922ac13c2e0d66aa72e0dbfd475a8fb7a044de Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 25 Jan 2021 09:25:36 +0100 Subject: [PATCH] fixed #756 (CDFJ rom size always 512KB) --- src/emucore/CartCDF.cxx | 16 ++++++++-------- src/emucore/CartCDF.hxx | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/emucore/CartCDF.cxx b/src/emucore/CartCDF.cxx index 0e2a1536c..56a48164d 100644 --- a/src/emucore/CartCDF.cxx +++ b/src/emucore/CartCDF.cxx @@ -65,18 +65,18 @@ namespace { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeCDF::CartridgeCDF(const ByteBuffer& image, size_t size, const string& md5, const Settings& settings) - : Cartridge(settings, md5), - myImage{make_unique(512_KB)} + : Cartridge(settings, md5) { // Copy the ROM image into my buffer - std::fill_n(myImage.get(), 512_KB, 0); - std::copy_n(image.get(), std::min(512_KB, size), myImage.get()); + mySize = std::min(size, 512_KB); + myImage = make_unique(mySize); + std::copy_n(image.get(), mySize, myImage.get()); // Detect cart version setupVersion(); // The lowest 2K is not accessible to the debugger - createRomAccessArrays(isCDFJplus() ? 510_KB : 28_KB); + createRomAccessArrays(isCDFJplus() ? mySize - 2_KB : 28_KB); // Pointer to the program ROM // which starts after the 2K driver (and 2K C Code for CDF) @@ -105,7 +105,7 @@ CartridgeCDF::CartridgeCDF(const ByteBuffer& image, size_t size, myThumbEmulator = make_unique( reinterpret_cast(myImage.get()), reinterpret_cast(myRAM.data()), - static_cast(512_KB), + static_cast(mySize), cBase, cStart, cStack, devSettings ? settings.getBool("dev.thumb.trapfatal") : false, thumulatorConfiguration(myCDFSubtype), @@ -485,7 +485,7 @@ bool CartridgeCDF::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const ByteBuffer& CartridgeCDF::getImage(size_t& size) const { - size = 512_KB; + size = mySize; return myImage; } @@ -810,7 +810,7 @@ uInt32 CartridgeCDF::ramSize() const uInt32 CartridgeCDF::romSize() const { - return uInt32(isCDFJplus() ? 512_KB : 32_KB); + return uInt32(isCDFJplus() ? mySize : 32_KB); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartCDF.hxx b/src/emucore/CartCDF.hxx index ec900ee21..ce16232b9 100644 --- a/src/emucore/CartCDF.hxx +++ b/src/emucore/CartCDF.hxx @@ -266,7 +266,10 @@ class CartridgeCDF : public Cartridge private: // The ROM image of the cartridge - ByteBuffer myImage; + ByteBuffer myImage{nullptr}; + + // The size of the ROM image + size_t mySize{0}; // Pointer to the program ROM image of the cartridge uInt8* myProgramImage{nullptr};