From cdecb9165e66fa5ffa83a9f06daf64a2932c4925 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Mon, 11 Apr 2022 09:14:01 +0200 Subject: [PATCH] improved bank origin detection (fixes #428) --- src/debugger/CartDebug.cxx | 2 +- src/emucore/Cart.cxx | 8 +++++--- src/emucore/Cart.hxx | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 0db637fba..fa04d14ea 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -290,7 +290,7 @@ bool CartDebug::disassemble(int bank, uInt16 PC, bool force) // 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 // $bxxx, it must be changed - uInt16 offset = (PC - (PC % 0x1000)); + uInt16 offset = myConsole.cartridge().bankOrigin(bank, PC); AddressList& addresses = info.addressList; for(auto& i: addresses) i = (i & 0xFFF) + offset; diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index 8f6362753..ed57ff42e 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -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 - // select the most frequent to define the bank origin + // Isolate the high 3 address bits, count them, include the PC if provided + // and select the most frequent to define the bank origin // TODO: origin for banks smaller than 4K constexpr int intervals = 0x8000 / 0x100; const uInt32 offset = bank * bankSize(); @@ -196,6 +196,8 @@ uInt16 Cartridge::bankOrigin(uInt16 bank) const //addrMask; count.fill(0); + if(PC) + count[PC >> 13]++; for(uInt16 addr = 0x0000; addr < bankSize(bank); ++addr) { const Device::AccessFlags flags = myRomAccessBase[offset + addr]; diff --git a/src/emucore/Cart.hxx b/src/emucore/Cart.hxx index a5171e6f1..67e66e039 100644 --- a/src/emucore/Cart.hxx +++ b/src/emucore/Cart.hxx @@ -189,9 +189,10 @@ class Cartridge : public Device Determine the bank's origin @param bank The bank to query + @param PC The current PC @return The origin of the bank */ - uInt16 bankOrigin(uInt16 bank) const; + uInt16 bankOrigin(uInt16 bank, uInt16 PC = 0) const; #endif public: