improve bankswitching masking in CartEnhanced

This commit is contained in:
thrust26 2020-04-19 12:19:44 +02:00
parent 70cdfe6c13
commit 9e466214ba
11 changed files with 23 additions and 15 deletions

View File

@ -87,6 +87,8 @@ class Cartridge3F : public CartridgeEnhanced
private: private:
bool checkSwitchBank(uInt16 address, uInt8 value) override; bool checkSwitchBank(uInt16 address, uInt8 value) override;
uInt16 hotspot() const override { return 0x003F; }
private: private:
// log(ROM bank segment size) / log(2) // log(ROM bank segment size) / log(2)
static constexpr uInt16 BANK_SHIFT = 11; // = 2K = 0x0800 static constexpr uInt16 BANK_SHIFT = 11; // = 2K = 0x0800

View File

@ -48,6 +48,8 @@ void CartridgeE0::reset()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CartridgeE0::checkSwitchBank(uInt16 address, uInt8) bool CartridgeE0::checkSwitchBank(uInt16 address, uInt8)
{ {
address &= ROM_MASK;
// Switch banks if necessary // Switch banks if necessary
if((address >= 0x0FE0) && (address <= 0x0FE7)) if((address >= 0x0FE0) && (address <= 0x0FE7))
{ {

View File

@ -114,8 +114,9 @@ uInt8 CartridgeEnhanced::peek(uInt16 address)
{ {
uInt16 peekAddress = address; uInt16 peekAddress = address;
if (hotspot() != 0) // hotspots in TIA range are reacting to pokes only
checkSwitchBank(address & ROM_MASK); if (hotspot() >= 0x80)
checkSwitchBank(address & ADDR_MASK);
if(isRamBank(address)) if(isRamBank(address))
{ {
@ -148,7 +149,7 @@ bool CartridgeEnhanced::poke(uInt16 address, uInt8 value)
// Note: (TODO?) // Note: (TODO?)
// The checkSwitchBank() call makes no difference between ROM and e.g TIA space // The checkSwitchBank() call makes no difference between ROM and e.g TIA space
// Writing to e.g. 0xf0xx might triger a bankswitch, is (and was!) this a bug??? // Writing to e.g. 0xf0xx might triger a bankswitch, is (and was!) this a bug???
if (checkSwitchBank(address & ROM_MASK, value)) if (checkSwitchBank(address & ADDR_MASK, value))
return false; return false;
if(myRamSize > 0) if(myRamSize > 0)

View File

@ -232,6 +232,9 @@ class CartridgeEnhanced : public Cartridge
size_t mySize{0}; size_t mySize{0};
protected: protected:
// The mask for 6507 address space
static constexpr uInt16 ADDR_MASK = 0x1FFF;
// The offset into address space for accessing ROM // The offset into address space for accessing ROM
static constexpr uInt16 ROM_OFFSET = 0x1000; static constexpr uInt16 ROM_OFFSET = 0x1000;

View File

@ -28,7 +28,7 @@ CartridgeF0::CartridgeF0(const ByteBuffer& image, size_t size,
bool CartridgeF0::checkSwitchBank(uInt16 address, uInt8) bool CartridgeF0::checkSwitchBank(uInt16 address, uInt8)
{ {
// Switch banks if necessary // Switch banks if necessary
if(address == 0x0FF0) if(address == 0x1FF0)
{ {
// Switch to next bank // Switch to next bank
uInt8 nextBank = ((getBank()) + 1) & 0x0F; uInt8 nextBank = ((getBank()) + 1) & 0x0F;

View File

@ -29,9 +29,9 @@ bool CartridgeF4::checkSwitchBank(uInt16 address, uInt8)
{ {
// Switch banks if necessary // Switch banks if necessary
// Note: addresses could be calculated from hotspot and bank count // Note: addresses could be calculated from hotspot and bank count
if((address >= 0x0FF4) && (address <= 0x0FFB)) if((address >= 0x1FF4) && (address <= 0x1FFB))
{ {
bank(address - 0x0FF4); bank(address - 0x1FF4);
return true; return true;
} }
return false; return false;

View File

@ -29,9 +29,9 @@ bool CartridgeF6::checkSwitchBank(uInt16 address, uInt8)
{ {
// Switch banks if necessary // Switch banks if necessary
// Note: addresses could be calculated from hotspot and bank count // Note: addresses could be calculated from hotspot and bank count
if((address >= 0x0FF6) && (address <= 0x0FF9)) if((address >= 0x1FF6) && (address <= 0x1FF9))
{ {
bank(address - 0x0FF6); bank(address - 0x1FF6);
return true; return true;
} }
return false; return false;

View File

@ -30,12 +30,12 @@ bool CartridgeF8::checkSwitchBank(uInt16 address, uInt8)
// Switch banks if necessary // Switch banks if necessary
switch(address) switch(address)
{ {
case 0x0FF8: case 0x1FF8:
// Set the current bank to the lower 4k bank // Set the current bank to the lower 4k bank
bank(0); bank(0);
return true; return true;
case 0x0FF9: case 0x1FF9:
// Set the current bank to the upper 4k bank // Set the current bank to the upper 4k bank
bank(1); bank(1);
return true; return true;

View File

@ -30,9 +30,9 @@ CartridgeFA::CartridgeFA(const ByteBuffer& image, size_t size,
bool CartridgeFA::checkSwitchBank(uInt16 address, uInt8) bool CartridgeFA::checkSwitchBank(uInt16 address, uInt8)
{ {
// Switch banks if necessary // Switch banks if necessary
if((address >= 0x0FF8) && (address <= 0x0FFA)) if((address >= 0x1FF8) && (address <= 0x1FFA))
{ {
bank(address - 0x0FF8); bank(address - 0x1FF8);
return true; return true;
} }
return false; return false;

View File

@ -42,9 +42,9 @@ CartridgeFA2::CartridgeFA2(const ByteBuffer& image, size_t size,
bool CartridgeFA2::checkSwitchBank(uInt16 address, uInt8) bool CartridgeFA2::checkSwitchBank(uInt16 address, uInt8)
{ {
// Switch banks if necessary // Switch banks if necessary
if((address >= 0x0FF5) && (address <= 0x0FFB)) if((address >= 0x1FF5) && (address <= 0x1FFB))
{ {
bank(address - 0x0FF5); bank(address - 0x1FF5);
return true; return true;
} }
return false; return false;

View File

@ -37,7 +37,7 @@ void CartridgeFC::reset()
bool CartridgeFC::checkSwitchBank(uInt16 address, uInt8) bool CartridgeFC::checkSwitchBank(uInt16 address, uInt8)
{ {
// Switch banks if necessary // Switch banks if necessary
if(address == 0x0FFC) if(address == 0x1FFC)
{ {
// Trigger the bank switch // Trigger the bank switch
bank(myTargetBank); bank(myTargetBank);