in atari_py/ale_interface/src/emucore/Cart3E.cxx [209:273]
void Cartridge3E::bank(uInt16 bank)
{
if(bankLocked) return;
if(bank < 256)
{
// Make sure the bank they're asking for is reasonable
if((uInt32)bank * 2048 < mySize)
{
myCurrentBank = bank;
}
else
{
// Oops, the bank they're asking for isn't valid so let's wrap it
// around to a valid bank number
myCurrentBank = bank % (mySize / 2048);
}
uInt32 offset = myCurrentBank * 2048;
uInt16 shift = mySystem->pageShift();
// Setup the page access methods for the current bank
System::PageAccess access;
access.device = this;
access.directPokeBase = 0;
// Map ROM image into the system
for(uInt32 address = 0x1000; address < 0x1800; address += (1 << shift))
{
access.directPeekBase = &myImage[offset + (address & 0x07FF)];
mySystem->setPageAccess(address >> shift, access);
}
}
else
{
bank -= 256;
bank %= 32;
myCurrentBank = bank + 256;
uInt32 offset = bank * 1024;
uInt16 shift = mySystem->pageShift();
uInt32 address;
// Setup the page access methods for the current bank
System::PageAccess access;
access.device = this;
access.directPokeBase = 0;
// Map read-port RAM image into the system
for(address = 0x1000; address < 0x1400; address += (1 << shift))
{
access.directPeekBase = &myRam[offset + (address & 0x03FF)];
mySystem->setPageAccess(address >> shift, access);
}
access.directPeekBase = 0;
// Map write-port RAM image into the system
for(address = 0x1400; address < 0x1800; address += (1 << shift))
{
access.directPokeBase = &myRam[offset + (address & 0x03FF)];
mySystem->setPageAccess(address >> shift, access);
}
}
}