diff --git a/src/cheat/BankRomCheat.cxx b/src/cheat/BankRomCheat.cxx index e0417d6a1..eae9304b4 100644 --- a/src/cheat/BankRomCheat.cxx +++ b/src/cheat/BankRomCheat.cxx @@ -47,7 +47,7 @@ bool BankRomCheat::enable() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool BankRomCheat::disable() { - int oldBank = myOSystem.console().cartridge().getBank(); + int oldBank = myOSystem.console().cartridge().getBank(address); myOSystem.console().cartridge().bank(bank); for(int i = 0; i < count; ++i) @@ -63,7 +63,7 @@ void BankRomCheat::evaluate() { if(!myEnabled) { - int oldBank = myOSystem.console().cartridge().getBank(); + int oldBank = myOSystem.console().cartridge().getBank(address); myOSystem.console().cartridge().bank(bank); for(int i = 0; i < count; ++i) diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 0ea5ee036..7dea78cd1 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -244,7 +244,7 @@ bool CartDebug::disassemble(bool force) if(changed) { // Are we disassembling from ROM or ZP RAM? - BankInfo& info = (PC & 0x1000) ? myBankInfo[getBank()] : + BankInfo& info = (PC & 0x1000) ? myBankInfo[getBank(PC)] : myBankInfo[myBankInfo.size()-1]; // If the offset has changed, all old addresses must be 'converted' @@ -384,7 +384,8 @@ bool CartDebug::addDirective(CartDebug::DisasmType type, return false; if(bank < 0) // Do we want the current bank or ZP RAM? - bank = (myDebugger.cpuDebug().pc() & 0x1000) ? getBank() : int(myBankInfo.size())-1; + bank = (myDebugger.cpuDebug().pc() & 0x1000) ? + getBank(myDebugger.cpuDebug().pc()) : int(myBankInfo.size())-1; bank = std::min(bank, bankCount()); BankInfo& info = myBankInfo[bank]; @@ -506,9 +507,15 @@ bool CartDebug::addDirective(CartDebug::DisasmType type, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int CartDebug::getBank() +int CartDebug::getBank(uInt16 addr) { - return myConsole.cartridge().getBank(); + return myConsole.cartridge().getBank(addr); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +int CartDebug::getPCBank() +{ + return myConsole.cartridge().getBank(myDebugger.cpuDebug().pc()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/CartDebug.hxx b/src/debugger/CartDebug.hxx index 205c89dff..61a3d66bf 100644 --- a/src/debugger/CartDebug.hxx +++ b/src/debugger/CartDebug.hxx @@ -173,7 +173,10 @@ class CartDebug : public DebuggerSystem Get the current bank in use by the cartridge (non-const because of use in YaccParser) */ - int getBank(); + int getBank(uInt16 addr); + + + int getPCBank(); /** Get the total number of banks supported by the cartridge. diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index f8de366d7..9724c0ba2 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -331,7 +331,7 @@ int Debugger::trace() int targetPC = myCpuDebug->pc() + 3; // return address // set temporary breakpoint at target PC (if not existing already) - Int8 bank = myCartDebug->getBank(); + Int8 bank = myCartDebug->getBank(targetPC); if(!checkBreakPoint(targetPC, bank)) { // add temporary breakpoint and remove later diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index 0e818f079..3d61958a9 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -738,7 +738,7 @@ void DebuggerParser::executeBreak() addr = args[0]; if(argCount < 2) - bank = debugger.cartDebug().getBank(); + bank = debugger.cartDebug().getBank(addr); else { bank = args[1]; diff --git a/src/debugger/gui/Cart3FWidget.cxx b/src/debugger/gui/Cart3FWidget.cxx index 954869911..c25f9c1a8 100644 --- a/src/debugger/gui/Cart3FWidget.cxx +++ b/src/debugger/gui/Cart3FWidget.cxx @@ -65,7 +65,7 @@ void Cartridge3FWidget::loadConfig() const CartState& state = static_cast(cart.getState()); const CartState& oldstate = static_cast(cart.getOldState()); - myBank->setSelectedIndex(myCart.getBank(), state.bank != oldstate.bank); + myBank->setSelectedIndex(myCart.getBank(0), state.bank != oldstate.bank); CartDebugWidget::loadConfig(); } diff --git a/src/debugger/gui/RomListWidget.cxx b/src/debugger/gui/RomListWidget.cxx index d3ab5e5dc..0b1b4bd79 100644 --- a/src/debugger/gui/RomListWidget.cxx +++ b/src/debugger/gui/RomListWidget.cxx @@ -492,7 +492,8 @@ void RomListWidget::drawWidget(bool hilite) // Draw checkboxes for correct lines (takes scrolling into account) myCheckList[i]->setState(instance().debugger(). - checkBreakPoint(dlist[pos].address, instance().debugger().cartDebug().getBank())); + checkBreakPoint(dlist[pos].address, + instance().debugger().cartDebug().getBank(dlist[pos].address))); myCheckList[i]->setDirty(); myCheckList[i]->draw(); diff --git a/src/debugger/gui/RomWidget.cxx b/src/debugger/gui/RomWidget.cxx index ece627c7e..6bcbb28c4 100644 --- a/src/debugger/gui/RomWidget.cxx +++ b/src/debugger/gui/RomWidget.cxx @@ -171,7 +171,7 @@ void RomWidget::toggleBreak(int disasm_line) if(list[disasm_line].address != 0 && list[disasm_line].bytes != "") instance().debugger().toggleBreakPoint(list[disasm_line].address, - instance().debugger().cartDebug().getBank()); + instance().debugger().cartDebug().getBank(list[disasm_line].address)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart.hxx b/src/emucore/Cart.hxx index efd529158..e66048f77 100644 --- a/src/emucore/Cart.hxx +++ b/src/emucore/Cart.hxx @@ -146,6 +146,13 @@ class Cartridge : public Device */ virtual uInt16 getBank() const { return 0; } + /** + Get the current bank for the provided address. + + @param address The address to get the bank for + */ + virtual uInt16 getBank(uInt16 addr) const { return getBank(); } + /** Query the number of 'banks' supported by the cartridge. Note that this information is cart-specific, where each cart basically defines diff --git a/src/emucore/Cart3E.cxx b/src/emucore/Cart3E.cxx index 80778a501..e77648090 100644 --- a/src/emucore/Cart3E.cxx +++ b/src/emucore/Cart3E.cxx @@ -185,9 +185,12 @@ bool Cartridge3E::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge3E::getBank() const +uInt16 Cartridge3E::getBank(uInt16 addr) const { - return myCurrentBank; + if(addr & 0x800) + return (mySize >> 11) - 1; // 2K slices, fixed bank + else + return 255; // 256 - 1 } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart3E.hxx b/src/emucore/Cart3E.hxx index 6ec025013..935cd8008 100644 --- a/src/emucore/Cart3E.hxx +++ b/src/emucore/Cart3E.hxx @@ -102,7 +102,7 @@ class Cartridge3E : public Cartridge /** Get the current bank. */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 addr) const override; /** Query the number of banks supported by the cartridge. diff --git a/src/emucore/Cart3EPlus.cxx b/src/emucore/Cart3EPlus.cxx index a40c1e3ea..0c2cc303d 100644 --- a/src/emucore/Cart3EPlus.cxx +++ b/src/emucore/Cart3EPlus.cxx @@ -78,6 +78,19 @@ void Cartridge3EPlus::install(System& system) bankROM((3 << BANK_BITS) | 0); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt16 Cartridge3EPlus::getBank(uInt16 addr) const +{ + return bankInUse[(addr & 0xFFF) >> 10]; // 1K slices +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt16 Cartridge3EPlus::bankCount() const +{ + return mySize >> 10; // 1K slices +} + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 Cartridge3EPlus::peek(uInt16 address) { diff --git a/src/emucore/Cart3EPlus.hxx b/src/emucore/Cart3EPlus.hxx index 5de961d2a..09cdc57fb 100644 --- a/src/emucore/Cart3EPlus.hxx +++ b/src/emucore/Cart3EPlus.hxx @@ -70,6 +70,16 @@ class Cartridge3EPlus: public Cartridge */ void install(System& system) override; + /** + Get the current bank. + */ + uInt16 getBank(uInt16 addr) const override; + + /** + Query the number of banks supported by the cartridge. + */ + uInt16 bankCount() const override; + /** Patch the cartridge ROM. diff --git a/src/emucore/Cart3F.cxx b/src/emucore/Cart3F.cxx index 10fef4677..1006b362e 100644 --- a/src/emucore/Cart3F.cxx +++ b/src/emucore/Cart3F.cxx @@ -125,15 +125,18 @@ bool Cartridge3F::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge3F::getBank() const +uInt16 Cartridge3F::getBank(uInt16 addr) const { - return myCurrentBank; + if (addr & 0x800) + return (mySize >> 11) - 1; // 2K slices, fixed bank + else + return myCurrentBank; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt16 Cartridge3F::bankCount() const { - return mySize >> 11; + return mySize >> 11; // 2K slices } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart3F.hxx b/src/emucore/Cart3F.hxx index 8982de2ac..29c9d9421 100644 --- a/src/emucore/Cart3F.hxx +++ b/src/emucore/Cart3F.hxx @@ -79,7 +79,7 @@ class Cartridge3F : public Cartridge /** Get the current bank. */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 addr) const override; /** Query the number of banks supported by the cartridge. diff --git a/src/emucore/CartE0.cxx b/src/emucore/CartE0.cxx index 0f337a0f5..e6f2e7a30 100644 --- a/src/emucore/CartE0.cxx +++ b/src/emucore/CartE0.cxx @@ -74,6 +74,18 @@ void CartridgeE0::install(System& system) mySystem->setPageAccess(addr, access); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt16 CartridgeE0::getBank(uInt16 addr) const +{ + return myCurrentSlice[(addr & 0xFFF) >> 10]; // 1K slices +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt16 CartridgeE0::bankCount() const +{ + return 8; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CartridgeE0::peek(uInt16 address) { diff --git a/src/emucore/CartE0.hxx b/src/emucore/CartE0.hxx index c5b6cbde8..1797badd0 100644 --- a/src/emucore/CartE0.hxx +++ b/src/emucore/CartE0.hxx @@ -72,6 +72,17 @@ class CartridgeE0 : public Cartridge */ void install(System& system) override; + + /** + Get the current bank. + */ + uInt16 getBank(uInt16 addr) const override; + + /** + Query the number of banks supported by the cartridge. + */ + uInt16 bankCount() const override; + /** Patch the cartridge ROM. diff --git a/src/emucore/CartMNetwork.cxx b/src/emucore/CartMNetwork.cxx index 7c29f3924..f930daaeb 100644 --- a/src/emucore/CartMNetwork.cxx +++ b/src/emucore/CartMNetwork.cxx @@ -196,9 +196,9 @@ bool CartridgeMNetwork::bank(uInt16 slice) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeMNetwork::getBank() const +uInt16 CartridgeMNetwork::getBank(uInt16 addr) const { - return myCurrentSlice[0]; + return myCurrentSlice[(addr & 0xFFF) >> 11]; // 2K slices } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartMNetwork.hxx b/src/emucore/CartMNetwork.hxx index c8441be24..f4b9a4635 100644 --- a/src/emucore/CartMNetwork.hxx +++ b/src/emucore/CartMNetwork.hxx @@ -101,7 +101,7 @@ class CartridgeMNetwork : public Cartridge /** Get the current bank. */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 addr) const override; /** Query the number of banks supported by the cartridge. diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index 71b16ee6a..a90e7742f 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -281,7 +281,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) if(myBreakPoints.isInitialized()) { - uInt8 bank = mySystem->cart().getBank(); + uInt8 bank = mySystem->cart().getBank(PC); if(myBreakPoints.check(PC, bank)) { diff --git a/src/yacc/YaccParser.cxx b/src/yacc/YaccParser.cxx index da2cd9f47..21473454d 100644 --- a/src/yacc/YaccParser.cxx +++ b/src/yacc/YaccParser.cxx @@ -180,7 +180,7 @@ int const_to_int(char* ch) CartMethod getCartSpecial(char* ch) { if(BSPF::equalsIgnoreCase(ch, "_bank")) - return &CartDebug::getBank; + return &CartDebug::getPCBank; else if(BSPF::equalsIgnoreCase(ch, "__lastread")) return &CartDebug::lastReadBaseAddress; else if(BSPF::equalsIgnoreCase(ch, "__lastwrite"))