fixed odd ROM sizes for 3E+ (fixed #960

This commit is contained in:
Thomas Jentzsch 2023-03-15 13:57:30 +01:00
parent 93ea39d615
commit 45157e8eb2
4 changed files with 22 additions and 9 deletions

View File

@ -24,7 +24,7 @@ Cartridge3EPlus::Cartridge3EPlus(const ByteBuffer& image, size_t size,
string_view md5, const Settings& settings,
size_t bsSize)
: Cartridge3E(image, size, md5, settings,
bsSize == 0 ? BSPF::nextMultipleOf(size, 1_KB) : bsSize)
bsSize == 0 ? std::max(4_KB, BSPF::nextMultipleOf(size, 1_KB)) : bsSize)
{
myBankShift = BANK_SHIFT;
myRamSize = RAM_SIZE;

View File

@ -133,6 +133,12 @@ class Cartridge3EPlus: public Cartridge3E
bool checkSwitchBank(uInt16 address, uInt8 value) override;
/**
Get the number of segments supported by the cartridge.
*/
uInt16 calcNumSegments() const override { return 4; }
private:
// log(ROM bank segment size) / log(2)
static constexpr uInt16 BANK_SHIFT = 10; // = 1K = 0x0400

View File

@ -213,7 +213,7 @@ class CartridgeE7 : public Cartridge
private:
// Size of RAM in the cart
static constexpr uInt32 RAM_SIZE = 0x800; // 1K + 4 * 256B = 2K
// Number of segment within the 4K address space
// Number of segments within the 4K address space
static constexpr uInt32 NUM_SEGMENTS = 2;
/**

View File

@ -37,11 +37,11 @@ CartridgeEnhanced::CartridgeEnhanced(const ByteBuffer& image, size_t size,
<< "), truncating " << (size - bsSize) << " bytes\n";
Logger::info(buf.str());
}
else if(size < mySize)
else if(size < bsSize)
{
ostringstream buf;
buf << "ROM smaller than expected (" << mySize << " > " << size
<< "), appending " << (mySize - size) << " bytes\n";
buf << "ROM smaller than expected (" << bsSize << " > " << size
<< "), appending " << (bsSize - size) << " bytes\n";
Logger::info(buf.str());
}
@ -72,10 +72,7 @@ void CartridgeEnhanced::install(System& system)
// calculate bank switching and RAM sizes and masks
myBankSize = 1 << myBankShift; // e.g. = 2 ^ 12 = 4K = 0x1000
myBankMask = myBankSize - 1; // e.g. = 0x0FFF
// Either the bankswitching supports multiple segments
// or the ROM is < 4K (-> 1 segment)
myBankSegs = std::min(1 << (MAX_BANK_SHIFT - myBankShift),
static_cast<int>(mySize) / myBankSize); // e.g. = 1
myBankSegs = calcNumSegments();
// ROM has an offset if RAM inside a bank (e.g. for F8SC)
myRomOffset = myRamBankCount > 0U ? 0U : static_cast<uInt16>(myRamSize * 2);
myRamMask = ramSize - 1; // e.g. = 0xFFFF (doesn't matter for RAM size 0)
@ -339,6 +336,16 @@ uInt16 CartridgeEnhanced::ramBankCount() const
return myRamBankCount;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 CartridgeEnhanced::calcNumSegments() const
{
// Either the bankswitching supports multiple segments
// or the ROM is < 4K (-> 1 segment)
return std::min(1 << (MAX_BANK_SHIFT - myBankShift),
static_cast<int>(mySize) / myBankSize); // e.g. = 1
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CartridgeEnhanced::isRamBank(uInt16 address) const
{