differentiate ROM read/write access (done for Atari standard and 3E bankswitching)

This commit is contained in:
thrust26 2020-04-01 22:14:22 +02:00
parent 96131e2f7f
commit 8b550a3a11
18 changed files with 115 additions and 81 deletions

View File

@ -1347,7 +1347,7 @@ string CartDebug::saveRom()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string CartDebug::saveAccessFile()
{
const string& rom = myConsole.properties().get(PropType::Cart_Name) + ".cvs";
const string& rom = myConsole.properties().get(PropType::Cart_Name) + ".csv";
FilesystemNode node(myOSystem.defaultSaveDir() + rom);
ofstream out(node.getPath());

View File

@ -142,19 +142,32 @@ void Cartridge::createRomAccessArrays(size_t size)
string Cartridge::getAccessCounters() const
{
ostringstream out;
size_t romSize;
uInt32 offset = 0;
getImage(romSize);
for(uInt16 bank = 0; bank < bankCount(); ++bank)
{
uInt32 offset = bank * bankSize();
uInt16 origin = bankOrigin(bank);
uInt16 bankSize = this->bankSize(bank);
out << "Bank " << bank << " / 0.." << bankCount() - 1 << ":\n";
for(uInt16 addr = 0; addr < bankSize(); ++addr)
out << "Bank " << bank << " / 0.." << bankCount() - 1 << " reads:\n";
for(uInt16 addr = 0; addr < bankSize; ++addr)
{
out << Common::Base::HEX4 << (addr | origin) << ","
<< Common::Base::toString(myRomAccessBase[offset + addr], Common::Base::Fmt::_10_8) << ", ";
<< Common::Base::toString(myRomAccessCounter[offset + addr], Common::Base::Fmt::_10_8) << ", ";
}
out << "\n";
out << "Bank " << bank << " / 0.." << bankCount() - 1 << " writes:\n";
for(uInt16 addr = 0; addr < bankSize; ++addr)
{
out << Common::Base::HEX4 << (addr | origin) << ","
<< Common::Base::toString(myRomAccessCounter[offset + addr + romSize], Common::Base::Fmt::_10_8) << ", ";
}
out << "\n";
offset += bankSize;
}
return out.str();
@ -165,20 +178,30 @@ uInt16 Cartridge::bankOrigin(uInt16 bank) const
{
// isolate the high 3 address bits, count them and
// select the most frequent to define the bank origin
std::array<uInt16, 8> count;
const int intervals = 0x8000 / 0x100;
uInt32 offset = bank * bankSize();
//uInt16 addrMask = (4_KB - 1) & ~(bankSize(bank) - 1);
//int addrShift = 0;
std::array<uInt16, intervals> count; // up to 128 256 byte interval origins
//if(addrMask)
// addrShift = log(addrMask) / log(2);
//addrMask;
count.fill(0);
for(uInt16 addr = 0x0000; addr < bankSize(bank); ++addr)
{
Device::AccessFlags flags = myRomAccessBase[offset + addr];
// only count really accessed addresses
if (flags & ~Device::ROW)
if(flags & ~Device::ROW)
{
//uInt16 addrBit = addr >> addrShift;
count[(flags & Device::HADDR) >> 13]++;
}
}
uInt16 max = 0, maxIdx = 0;
for(int idx = 0; idx < 8; ++idx)
for(int idx = 0; idx < intervals; ++idx)
{
if(count[idx] > max)
{
@ -186,7 +209,7 @@ uInt16 Cartridge::bankOrigin(uInt16 bank) const
maxIdx = idx;
}
}
return maxIdx << 13 | 0x1000;
return maxIdx << 13 | 0x1000 | (offset & 0xfff);
}
#endif

View File

@ -77,6 +77,8 @@ void Cartridge2K::install(System& system)
{
access.directPeekBase = &myImage[addr & myMask];
access.romAccessBase = &myRomAccessBase[addr & myMask];
access.romPeekCounter = &myRomAccessCounter[addr & 0x0FFF];
access.romPokeCounter = &myRomAccessCounter[(addr & 0x0FFF) + mySize];
mySystem->setPageAccess(addr, access);
}
}

View File

@ -60,6 +60,8 @@ void Cartridge3E::install(System& system)
{
access.directPeekBase = &myImage[(mySize - 2048) + (addr & 0x07FF)];
access.romAccessBase = &myRomAccessBase[(mySize - 2048) + (addr & 0x07FF)];
access.romPeekCounter = &myRomAccessCounter[(mySize - 2048) + (addr & 0x07FF)];
access.romPokeCounter = &myRomAccessCounter[(mySize - 2048) + (addr & 0x07FF) + mySize];
mySystem->setPageAccess(addr, access);
}
@ -159,6 +161,8 @@ bool Cartridge3E::bank(uInt16 bank)
{
access.directPeekBase = &myImage[offset + (addr & 0x07FF)];
access.romAccessBase = &myRomAccessBase[offset + (addr & 0x07FF)];
access.romPeekCounter = &myRomAccessCounter[offset + (addr & 0x07FF)];
access.romPokeCounter = &myRomAccessCounter[offset + (addr & 0x07FF) + mySize];
mySystem->setPageAccess(addr, access);
}
}
@ -178,6 +182,8 @@ bool Cartridge3E::bank(uInt16 bank)
{
access.directPeekBase = &myRAM[offset + (addr & 0x03FF)];
access.romAccessBase = &myRomAccessBase[mySize + offset + (addr & 0x03FF)];
access.romPeekCounter = &myRomAccessCounter[mySize + offset + (addr & 0x03FF)];
access.romPokeCounter = &myRomAccessCounter[mySize + offset + (addr & 0x03FF) + mySize];
mySystem->setPageAccess(addr, access);
}
@ -190,6 +196,8 @@ bool Cartridge3E::bank(uInt16 bank)
for(uInt16 addr = 0x1400; addr < 0x1800; addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[mySize + offset + (addr & 0x03FF)];
access.romPeekCounter = &myRomAccessCounter[mySize + offset + (addr & 0x03FF)];
access.romPokeCounter = &myRomAccessCounter[mySize + offset + (addr & 0x03FF) + mySize];
mySystem->setPageAccess(addr, access);
}
}

View File

@ -47,7 +47,8 @@ void Cartridge4K::install(System& system)
{
access.directPeekBase = &myImage[addr & 0x0FFF];
access.romAccessBase = &myRomAccessBase[addr & 0x0FFF];
access.romAccessCounter = &myRomAccessCounter[addr & 0x0FFF];
access.romPeekCounter = &myRomAccessCounter[addr & 0x0FFF];
access.romPokeCounter = &myRomAccessCounter[(addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
}

View File

@ -89,6 +89,8 @@ bool CartridgeF4::bank(uInt16 bank)
addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -98,6 +100,8 @@ bool CartridgeF4::bank(uInt16 bank)
{
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
return myBankChanged = true;

View File

@ -52,6 +52,8 @@ void CartridgeF4SC::install(System& system)
for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[addr & 0x007F];
access.romPeekCounter = &myRomAccessCounter[addr & 0x007F];
access.romPokeCounter = &myRomAccessCounter[(addr & 0x07F) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -61,6 +63,8 @@ void CartridgeF4SC::install(System& system)
{
access.directPeekBase = &myRAM[addr & 0x007F];
access.romAccessBase = &myRomAccessBase[0x80 + (addr & 0x007F)];
access.romPeekCounter = &myRomAccessCounter[0x80 + (addr & 0x007F)];
access.romPokeCounter = &myRomAccessCounter[0x80 + (addr & 0x007F) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -128,6 +132,8 @@ bool CartridgeF4SC::bank(uInt16 bank)
addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -137,6 +143,8 @@ bool CartridgeF4SC::bank(uInt16 bank)
{
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
return myBankChanged = true;

View File

@ -129,6 +129,8 @@ bool CartridgeF6::bank(uInt16 bank)
addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -138,6 +140,8 @@ bool CartridgeF6::bank(uInt16 bank)
{
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
return myBankChanged = true;

View File

@ -52,6 +52,8 @@ void CartridgeF6SC::install(System& system)
for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[addr & 0x007F];
access.romPeekCounter = &myRomAccessCounter[addr & 0x007F];
access.romPokeCounter = &myRomAccessCounter[(addr & 0x07F) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -61,6 +63,8 @@ void CartridgeF6SC::install(System& system)
{
access.directPeekBase = &myRAM[addr & 0x007F];
access.romAccessBase = &myRomAccessBase[0x80 + (addr & 0x007F)];
access.romPeekCounter = &myRomAccessCounter[0x80 + (addr & 0x007F)];
access.romPokeCounter = &myRomAccessCounter[0x80 + (addr & 0x007F) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -168,6 +172,8 @@ bool CartridgeF6SC::bank(uInt16 bank)
addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -177,6 +183,8 @@ bool CartridgeF6SC::bank(uInt16 bank)
{
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
return myBankChanged = true;

View File

@ -110,6 +110,8 @@ bool CartridgeF8::bank(uInt16 bank)
addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + addr & 0x0FFF];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + addr & 0x0FFF + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -119,6 +121,8 @@ bool CartridgeF8::bank(uInt16 bank)
{
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[addr & 0x0FFF];
access.romPokeCounter = &myRomAccessCounter[addr & 0x0FFF + myImage.size()];
mySystem->setPageAccess(addr, access);
}
return myBankChanged = true;

View File

@ -52,6 +52,8 @@ void CartridgeF8SC::install(System& system)
for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[addr & 0x007F];
access.romPeekCounter = &myRomAccessCounter[addr & 0x007F];
access.romPokeCounter = &myRomAccessCounter[(addr & 0x07F) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -61,6 +63,8 @@ void CartridgeF8SC::install(System& system)
{
access.directPeekBase = &myRAM[addr & 0x007F];
access.romAccessBase = &myRomAccessBase[0x80 + (addr & 0x007F)];
access.romPeekCounter = &myRomAccessCounter[0x80 + (addr & 0x007F)];
access.romPokeCounter = &myRomAccessCounter[0x80 + (addr & 0x007F) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -148,6 +152,8 @@ bool CartridgeF8SC::bank(uInt16 bank)
addr += System::PAGE_SIZE)
{
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
@ -157,6 +163,8 @@ bool CartridgeF8SC::bank(uInt16 bank)
{
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myImage.size()];
mySystem->setPageAccess(addr, access);
}
return myBankChanged = true;

View File

@ -146,13 +146,6 @@ class Device : public Serializable
*/
virtual void setAccessFlags(uInt16 address, AccessFlags flags) { }
/**
Query the given address for its access counter
@param address The address to query for
*/
virtual AccessCounter getAccessCounter(uInt16 address) const { return 0; }
/**
Increase the given address's access counter

View File

@ -497,17 +497,6 @@ void M6532::setAccessFlags(uInt16 address, Device::AccessFlags flags)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Device::AccessCounter M6532::getAccessCounter(uInt16 address) const
{
if (address & IO_BIT)
return myIOAccessCounter[address & IO_MASK];
else if (address & STACK_BIT)
return myStackAccessCounter[address & STACK_MASK];
else
return myRAMAccessCounter[address & RAM_MASK];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void M6532::increaseAccessCounter(uInt16 address, bool isWrite)
{

View File

@ -169,13 +169,6 @@ class M6532 : public Device
*/
void setAccessFlags(uInt16 address, Device::AccessFlags flags) override;
/**
Query the given address for its access counter
@param address The address to query for
*/
Device::AccessCounter getAccessCounter(uInt16 address) const override;
/**
Increase the given address's access counter

View File

@ -110,10 +110,11 @@ uInt8 System::peek(uInt16 addr, Device::AccessFlags flags)
else
access.device->setAccessFlags(addr, flags);
// Increase access counter
if(access.romAccessCounter)
*(access.romAccessCounter + (addr & PAGE_MASK)) += 1;
else
access.device->increaseAccessCounter(addr);
if (flags != Device::NONE)
if(access.romPeekCounter)
*(access.romPeekCounter + (addr & PAGE_MASK)) += 1;
else
access.device->increaseAccessCounter(addr);
#endif
// See if this page uses direct accessing or not
@ -144,10 +145,11 @@ void System::poke(uInt16 addr, uInt8 value, Device::AccessFlags flags)
else
access.device->setAccessFlags(addr, flags);
// Increase access counter
if(access.romAccessCounter)
*(access.romAccessCounter + (addr & PAGE_MASK)) += 1;
else
access.device->increaseAccessCounter(addr, true);
if (flags != Device::NONE)
if(access.romPokeCounter)
*(access.romPokeCounter + (addr & PAGE_MASK)) += 1;
else
access.device->increaseAccessCounter(addr, true);
#endif
// See if this page uses direct accessing or not
@ -192,28 +194,30 @@ void System::setAccessFlags(uInt16 addr, Device::AccessFlags flags)
access.device->setAccessFlags(addr, flags);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Device::AccessCounter System::getAccessCounter(uInt16 addr) const
{
const PageAccess& access = getPageAccess(addr);
if(access.romAccessCounter)
return *(access.romAccessCounter + (addr & PAGE_MASK));
else
return access.device->getAccessCounter(addr);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void System::increaseAccessCounter(uInt16 addr, bool isWrite)
{
const PageAccess& access = getPageAccess(addr);
if(access.romAccessCounter)
*(access.romAccessCounter + (addr & PAGE_MASK)) += 1;
else
access.device->increaseAccessCounter(addr, isWrite);
}
if(isWrite)
{
if(access.romPokeCounter)
{
*(access.romPokeCounter + (addr & PAGE_MASK)) += 1;
return;
}
}
else
{
if(access.romPeekCounter)
{
*(access.romPeekCounter + (addr & PAGE_MASK)) += 1;
return;
}
}
access.device->increaseAccessCounter(addr, isWrite);
}
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -240,13 +240,6 @@ class System : public Serializable
Device::AccessFlags getAccessFlags(uInt16 address) const;
void setAccessFlags(uInt16 address, Device::AccessFlags flags);
/**
Query the given address for its access counter
@param address The address to query for
*/
Device::AccessCounter getAccessCounter(uInt16 address) const;
/**
Increase the given address's access counter
@ -302,7 +295,12 @@ class System : public Serializable
/**
TODO
*/
Device::AccessCounter* romAccessCounter{nullptr};
Device::AccessCounter* romPeekCounter{nullptr};
/**
TODO
*/
Device::AccessCounter* romPokeCounter{nullptr};
/**
Pointer to the device associated with this page or to the system's

View File

@ -1980,12 +1980,6 @@ void TIA::setAccessFlags(uInt16 address, Device::AccessFlags flags)
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Device::AccessCounter TIA::getAccessCounter(uInt16 address) const
{
return myAccessCounter[address & TIA_MASK];
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void TIA::increaseAccessCounter(uInt16 address, bool isWrite)
{

View File

@ -703,13 +703,6 @@ class TIA : public Device
*/
void setAccessFlags(uInt16 address, Device::AccessFlags flags) override;
/**
Query the given address for its access counter
@param address The address to query for
*/
Device::AccessCounter getAccessCounter(uInt16 address) const override;
/**
Increase the given address's access counter