mirror of https://github.com/stella-emu/stella.git
intermediate commit for refactoring 3E (something got broken in disassembly before)
This commit is contained in:
parent
4f8ae57779
commit
56cbc4dc6f
|
@ -23,7 +23,8 @@
|
|||
Cartridge3E::Cartridge3E(const ByteBuffer& image, size_t size,
|
||||
const string& md5, const Settings& settings)
|
||||
: Cartridge(settings, md5),
|
||||
mySize(size)
|
||||
mySize(size),
|
||||
myRomBanks(256/*uInt16(size) >> 11*/)
|
||||
{
|
||||
// Allocate array for the ROM image
|
||||
myImage = make_unique<uInt8[]>(mySize);
|
||||
|
@ -80,10 +81,10 @@ uInt8 Cartridge3E::peek(uInt16 address)
|
|||
|
||||
if(address < 0x0040) // TIA access
|
||||
return mySystem->tia().peek(address);
|
||||
else if(myCurrentBank >= 256)
|
||||
else if(myCurrentBank >= myRomBanks)
|
||||
{
|
||||
// Reading from the write port triggers an unwanted write
|
||||
return peekRAM(myRAM[(address & 0x03FF) + ((myCurrentBank - 256) << 10)], peekAddress);
|
||||
return peekRAM(myRAM[(address & 0x03FF) + ((myCurrentBank - myRomBanks) << 10)], peekAddress);
|
||||
}
|
||||
|
||||
// Make compiler happy; should never get here
|
||||
|
@ -103,15 +104,15 @@ bool Cartridge3E::poke(uInt16 address, uInt8 value)
|
|||
if(address == 0x003F)
|
||||
bank(value);
|
||||
else if(address == 0x003E)
|
||||
bank(value + 256);
|
||||
bank(value + myRomBanks);
|
||||
|
||||
return mySystem->tia().poke(address, value);
|
||||
}
|
||||
else if(myCurrentBank >= 256)
|
||||
else if(myCurrentBank >= myRomBanks)
|
||||
{
|
||||
if(address & 0x0400)
|
||||
{
|
||||
pokeRAM(myRAM[(address & 0x03FF) + ((myCurrentBank - 256) << 10)],
|
||||
pokeRAM(myRAM[(address & 0x03FF) + ((myCurrentBank - myRomBanks) << 10)],
|
||||
pokeAddress, value);
|
||||
return true;
|
||||
}
|
||||
|
@ -133,7 +134,7 @@ bool Cartridge3E::bank(uInt16 bank)
|
|||
{
|
||||
if(bankLocked()) return false;
|
||||
|
||||
if(bank < 256)
|
||||
if(bank < myRomBanks)
|
||||
{
|
||||
// Make sure the bank they're asking for is reasonable
|
||||
if((uInt32(bank) << 11) < mySize)
|
||||
|
@ -164,9 +165,9 @@ bool Cartridge3E::bank(uInt16 bank)
|
|||
}
|
||||
else
|
||||
{
|
||||
bank -= 256;
|
||||
bank %= 32;
|
||||
myCurrentBank = bank + 256;
|
||||
bank -= myRomBanks;
|
||||
bank %= myRamBanks;
|
||||
myCurrentBank = bank + myRomBanks;
|
||||
|
||||
uInt32 offset = bank << 10;
|
||||
|
||||
|
@ -204,7 +205,7 @@ bool Cartridge3E::bank(uInt16 bank)
|
|||
uInt16 Cartridge3E::getBank(uInt16 address) const
|
||||
{
|
||||
if (address & 0x800)
|
||||
return 255; // 256 - 1 // 2K slices, fixed bank
|
||||
return myRomBanks - 1; // 2K slices, fixed bank
|
||||
else
|
||||
return myCurrentBank;
|
||||
}
|
||||
|
@ -217,7 +218,7 @@ uInt16 Cartridge3E::bankCount() const
|
|||
// If the RAM banks were simply appended to the number of actual
|
||||
// ROM banks, bank numbers would be ambiguous (ie, would bank 128 be
|
||||
// the last bank of ROM, or one of the banks of RAM?)
|
||||
return 256 + 32;
|
||||
return myRomBanks + myRamBanks;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -227,10 +228,10 @@ bool Cartridge3E::patch(uInt16 address, uInt8 value)
|
|||
|
||||
if(address < 0x0800)
|
||||
{
|
||||
if(myCurrentBank < 256)
|
||||
if(myCurrentBank < myRomBanks)
|
||||
myImage[(address & 0x07FF) + (myCurrentBank << 11)] = value;
|
||||
else
|
||||
myRAM[(address & 0x03FF) + ((myCurrentBank - 256) << 10)] = value;
|
||||
myRAM[(address & 0x03FF) + ((myCurrentBank - myRomBanks) << 10)] = value;
|
||||
}
|
||||
else
|
||||
myImage[(address & 0x07FF) + mySize - 2048] = value;
|
||||
|
|
|
@ -190,6 +190,12 @@ class Cartridge3E : public Cartridge
|
|||
// Size of the ROM image
|
||||
size_t mySize{0};
|
||||
|
||||
// Size of the ROM image
|
||||
uInt16 myRomBanks{0};
|
||||
|
||||
// Size of the ROM image
|
||||
uInt16 myRamBanks{32};
|
||||
|
||||
// Indicates which bank is currently active for the first segment
|
||||
uInt16 myCurrentBank{0};
|
||||
|
||||
|
|
|
@ -146,40 +146,89 @@ bool CartridgeEnhanced::poke(uInt16 address, uInt8 value)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool CartridgeEnhanced::bank(uInt16 bank, uInt16 segment)
|
||||
bool CartridgeEnhanced::bank(uInt16 bank, uInt16 segment, bool isRAM)
|
||||
{
|
||||
if(bankLocked()) return false;
|
||||
|
||||
// Remember what bank is in which segment
|
||||
uInt32 bankOffset = myCurrentSegOffset[segment] = bank << myBankShift;
|
||||
uInt16 segmentOffset = segment << myBankShift;
|
||||
uInt16 hotspot = this->hotspot();
|
||||
uInt16 hotSpotAddr;
|
||||
uInt16 fromAddr = (segmentOffset + 0x1000 + myRamSize * 2) & ~System::PAGE_MASK;
|
||||
// for ROMs < 4_KB, the whole address space will be mapped.
|
||||
uInt16 toAddr = (segmentOffset + 0x1000 + (mySize < 4_KB ? 0x1000 : myBankSize)) & ~System::PAGE_MASK;
|
||||
|
||||
if(hotspot)
|
||||
hotSpotAddr = (hotspot & ~System::PAGE_MASK);
|
||||
else
|
||||
hotSpotAddr = 0xFFFF; // none
|
||||
|
||||
System::PageAccess access(this, System::PageAccessType::READ);
|
||||
|
||||
// Setup the page access methods for the current bank
|
||||
for(uInt16 addr = fromAddr; addr < toAddr; addr += System::PAGE_SIZE)
|
||||
if(!isRAM)
|
||||
{
|
||||
uInt32 offset = bankOffset + (addr & myBankMask);
|
||||
// Setup ROM bank
|
||||
// Remember what bank is in which segment
|
||||
uInt32 bankOffset = myCurrentSegOffset[segment] = bank << myBankShift;
|
||||
|
||||
if(myDirectPeek && addr != hotSpotAddr)
|
||||
access.directPeekBase = &myImage[offset];
|
||||
uInt16 hotspot = this->hotspot();
|
||||
uInt16 hotSpotAddr;
|
||||
uInt16 fromAddr = (segmentOffset + 0x1000 + myRamSize * 2) & ~System::PAGE_MASK;
|
||||
// for ROMs < 4_KB, the whole address space will be mapped.
|
||||
uInt16 toAddr = (segmentOffset + 0x1000 + (mySize < 4_KB ? 0x1000 : myBankSize)) & ~System::PAGE_MASK;
|
||||
|
||||
if(hotspot)
|
||||
hotSpotAddr = (hotspot & ~System::PAGE_MASK);
|
||||
else
|
||||
access.directPeekBase = nullptr;
|
||||
access.romAccessBase = &myRomAccessBase[offset];
|
||||
access.romPeekCounter = &myRomAccessCounter[offset];
|
||||
access.romPokeCounter = &myRomAccessCounter[offset + myAccessSize];
|
||||
mySystem->setPageAccess(addr, access);
|
||||
hotSpotAddr = 0xFFFF; // none
|
||||
|
||||
System::PageAccess access(this, System::PageAccessType::READ);
|
||||
// Setup the page access methods for the current bank
|
||||
for(uInt16 addr = fromAddr; addr < toAddr; addr += System::PAGE_SIZE)
|
||||
{
|
||||
uInt32 offset = bankOffset + (addr & myBankMask);
|
||||
|
||||
if(myDirectPeek && addr != hotSpotAddr)
|
||||
access.directPeekBase = &myImage[offset];
|
||||
else
|
||||
access.directPeekBase = nullptr;
|
||||
access.romAccessBase = &myRomAccessBase[offset];
|
||||
access.romPeekCounter = &myRomAccessCounter[offset];
|
||||
access.romPokeCounter = &myRomAccessCounter[offset + myAccessSize];
|
||||
mySystem->setPageAccess(addr, access);
|
||||
}
|
||||
}
|
||||
/*else
|
||||
{
|
||||
// Setup RAM bank
|
||||
// TODO: define offsets on init
|
||||
uInt16 myWriteBankOffset = myBankSize >> 1;
|
||||
uInt16 myReadBankOffset = 0;
|
||||
|
||||
// Remember what bank is in which segment
|
||||
uInt32 bankOffset = myCurrentSegOffset[segment] = bank << myBankShift;
|
||||
|
||||
// Set the page accessing method for the RAM writing pages
|
||||
uInt16 fromAddr = (segmentOffset + myWriteBankOffset + 0x1000) & ~System::PAGE_MASK;
|
||||
uInt16 toAddr = (segmentOffset + myWriteBankOffset + 0x1000 + myBankSize >> 1) & ~System::PAGE_MASK;
|
||||
System::PageAccess access(this, System::PageAccessType::WRITE);
|
||||
|
||||
for(uInt16 addr = fromAddr; addr < toAddr; addr += System::PAGE_SIZE)
|
||||
{
|
||||
uInt32 offset = bankOffset + (addr & myBankMask);
|
||||
|
||||
access.romAccessBase = &myRomAccessBase[offset];
|
||||
access.romPeekCounter = &myRomAccessCounter[offset];
|
||||
access.romPokeCounter = &myRomAccessCounter[offset + myAccessSize];
|
||||
mySystem->setPageAccess(addr, access);
|
||||
}
|
||||
|
||||
// Set the page accessing method for the RAM reading pages
|
||||
fromAddr = (segmentOffset + myReadBankOffset + 0x1000) & ~System::PAGE_MASK;
|
||||
toAddr = (segmentOffset + myReadBankOffset + 0x1000 + myBankSize >> 1) & ~System::PAGE_MASK;
|
||||
|
||||
access.type = System::PageAccessType::READ;
|
||||
for(uInt16 addr = fromAddr; addr < toAddr; addr += System::PAGE_SIZE)
|
||||
{
|
||||
uInt32 offset = bankOffset + (addr & myBankMask);
|
||||
|
||||
|
||||
|
||||
uInt16 offset = addr & myRamMask;
|
||||
access.directPeekBase = &myBankRAM[offset];
|
||||
access.romAccessBase = &myRomAccessBase[offset];
|
||||
access.romPeekCounter = &myRomAccessCounter[offset];
|
||||
access.romPokeCounter = &myRomAccessCounter[offset + myAccessSize];
|
||||
mySystem->setPageAccess(addr, access);
|
||||
}
|
||||
}*/
|
||||
|
||||
return myBankChanged = true;
|
||||
}
|
||||
|
|
|
@ -60,28 +60,34 @@ class CartridgeEnhanced : public Cartridge
|
|||
/**
|
||||
Install pages for the specified bank in the system.
|
||||
|
||||
@param bank The bank that should be installed in the system
|
||||
@param bank The bank that should be installed in the system
|
||||
@param segment The segment the bank should be using
|
||||
@param isRAM True if the bank is a RAM bank
|
||||
|
||||
@return true, if bank has changed
|
||||
*/
|
||||
bool bank(uInt16 bank, uInt16 segment);
|
||||
bool bank(uInt16 bank, uInt16 segment, bool isRAM = false);
|
||||
|
||||
/**
|
||||
Install pages for the specified bank in the system.
|
||||
|
||||
@param bank The bank that should be installed in the system
|
||||
@param bank The bank that should be installed in the system
|
||||
|
||||
@return true, if bank has changed
|
||||
*/
|
||||
bool bank(uInt16 bank) override { return this->bank(bank, 0); }
|
||||
|
||||
/**
|
||||
Get the current bank.
|
||||
|
||||
@param address The address to use when querying the bank
|
||||
@param address The address to use when querying the bank
|
||||
*/
|
||||
uInt16 getBank(uInt16 address = 0) const override;
|
||||
|
||||
/**
|
||||
Get the current bank for a bank segment.
|
||||
|
||||
@param segment The segment to get the bank for
|
||||
@param segment The segment to get the bank for
|
||||
*/
|
||||
uInt16 getSegmentBank(uInt16 segment = 0) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue