take care of odd ROM sizes (fixes #653)

This commit is contained in:
thrust26 2020-06-05 18:04:08 +02:00
parent 6b14a13f15
commit baa47aec57
1 changed files with 3 additions and 2 deletions

View File

@ -278,7 +278,7 @@ bool CartridgeEnhanced::bank(uInt16 bank, uInt16 segment)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 CartridgeEnhanced::getBank(uInt16 address) const
{
return myCurrentSegOffset[(address & ROM_MASK) >> myBankShift] >> myBankShift;
return myCurrentSegOffset[std::min((address & ROM_MASK) >> myBankShift, romBankCount() - 1)] >> myBankShift;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -290,7 +290,8 @@ uInt16 CartridgeEnhanced::getSegmentBank(uInt16 segment) const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 CartridgeEnhanced::romBankCount() const
{
return uInt16(mySize >> myBankShift);
// take care of too small ROMs
return uInt16(mySize + ((1 << myBankShift) - 1)) >> myBankShift;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -