improved bank origin detection (fixes #428)

This commit is contained in:
Thomas Jentzsch 2022-04-11 09:14:01 +02:00
parent 47710cdbcd
commit cdecb9165e
3 changed files with 8 additions and 5 deletions

View File

@ -290,7 +290,7 @@ bool CartDebug::disassemble(int bank, uInt16 PC, bool force)
// If the offset has changed, all old addresses must be 'converted' // If the offset has changed, all old addresses must be 'converted'
// For example, if the list contains any $fxxx and the address space is now // For example, if the list contains any $fxxx and the address space is now
// $bxxx, it must be changed // $bxxx, it must be changed
uInt16 offset = (PC - (PC % 0x1000)); uInt16 offset = myConsole.cartridge().bankOrigin(bank, PC);
AddressList& addresses = info.addressList; AddressList& addresses = info.addressList;
for(auto& i: addresses) for(auto& i: addresses)
i = (i & 0xFFF) + offset; i = (i & 0xFFF) + offset;

View File

@ -180,10 +180,10 @@ string Cartridge::getAccessCounters() const
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt16 Cartridge::bankOrigin(uInt16 bank) const uInt16 Cartridge::bankOrigin(uInt16 bank, uInt16 PC) const
{ {
// isolate the high 3 address bits, count them and // Isolate the high 3 address bits, count them, include the PC if provided
// select the most frequent to define the bank origin // and select the most frequent to define the bank origin
// TODO: origin for banks smaller than 4K // TODO: origin for banks smaller than 4K
constexpr int intervals = 0x8000 / 0x100; constexpr int intervals = 0x8000 / 0x100;
const uInt32 offset = bank * bankSize(); const uInt32 offset = bank * bankSize();
@ -196,6 +196,8 @@ uInt16 Cartridge::bankOrigin(uInt16 bank) const
//addrMask; //addrMask;
count.fill(0); count.fill(0);
if(PC)
count[PC >> 13]++;
for(uInt16 addr = 0x0000; addr < bankSize(bank); ++addr) for(uInt16 addr = 0x0000; addr < bankSize(bank); ++addr)
{ {
const Device::AccessFlags flags = myRomAccessBase[offset + addr]; const Device::AccessFlags flags = myRomAccessBase[offset + addr];

View File

@ -189,9 +189,10 @@ class Cartridge : public Device
Determine the bank's origin Determine the bank's origin
@param bank The bank to query @param bank The bank to query
@param PC The current PC
@return The origin of the bank @return The origin of the bank
*/ */
uInt16 bankOrigin(uInt16 bank) const; uInt16 bankOrigin(uInt16 bank, uInt16 PC = 0) const;
#endif #endif
public: public: