Skip to content

Commit

Permalink
Add considering addresses for current bank. This is important for typ…
Browse files Browse the repository at this point in the history
…es where the 4K ROM address space is segmented into smaller slices, so there can be more than one bank at a time.

This addresses #536.
  • Loading branch information
thrust26 committed Sep 7, 2019
1 parent ba3015a commit d7c4b1a
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/cheat/BankRomCheat.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions src/debugger/CartDebug.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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());
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
5 changes: 4 additions & 1 deletion src/debugger/CartDebug.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/Debugger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/DebuggerParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/gui/Cart3FWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void Cartridge3FWidget::loadConfig()
const CartState& state = static_cast<const CartState&>(cart.getState());
const CartState& oldstate = static_cast<const CartState&>(cart.getOldState());

myBank->setSelectedIndex(myCart.getBank(), state.bank != oldstate.bank);
myBank->setSelectedIndex(myCart.getBank(0), state.bank != oldstate.bank);

CartDebugWidget::loadConfig();
}
Expand Down
3 changes: 2 additions & 1 deletion src/debugger/gui/RomListWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/debugger/gui/RomWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
7 changes: 7 additions & 0 deletions src/emucore/Cart.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/emucore/Cart3E.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/Cart3E.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/emucore/Cart3EPlus.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 10 additions & 0 deletions src/emucore/Cart3EPlus.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions src/emucore/Cart3F.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/Cart3F.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions src/emucore/CartE0.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 11 additions & 0 deletions src/emucore/CartE0.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/emucore/CartMNetwork.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/CartMNetwork.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/M6502.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/yacc/YaccParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit d7c4b1a

Please sign in to comment.