mirror of https://github.com/stella-emu/stella.git
refactor CartSB
This commit is contained in:
parent
4390a779af
commit
53387c4b13
|
@ -26,10 +26,11 @@ CartridgeSBWidget::CartridgeSBWidget(
|
||||||
: CartDebugWidget(boss, lfont, nfont, x, y, w, h),
|
: CartDebugWidget(boss, lfont, nfont, x, y, w, h),
|
||||||
myCart(cart)
|
myCart(cart)
|
||||||
{
|
{
|
||||||
size_t size = myCart.mySize;
|
|
||||||
|
|
||||||
VariantList items;
|
VariantList items;
|
||||||
ostringstream info, bank;
|
ostringstream info, bank;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
myCart.getImage(size);
|
||||||
info << "SB SUPERbanking, 32 or 64 4K banks\n"
|
info << "SB SUPERbanking, 32 or 64 4K banks\n"
|
||||||
<< "Hotspots are from $800 to $"
|
<< "Hotspots are from $800 to $"
|
||||||
<< Common::Base::HEX2 << (0x800 + myCart.bankCount() - 1) << ", including\n"
|
<< Common::Base::HEX2 << (0x800 + myCart.bankCount() - 1) << ", including\n"
|
||||||
|
|
|
@ -21,30 +21,14 @@
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
CartridgeSB::CartridgeSB(const ByteBuffer& image, size_t size,
|
CartridgeSB::CartridgeSB(const ByteBuffer& image, size_t size,
|
||||||
const string& md5, const Settings& settings)
|
const string& md5, const Settings& settings)
|
||||||
: Cartridge(settings, md5),
|
: CartridgeEnhanced(image, size, md5, settings)
|
||||||
mySize(size)
|
|
||||||
{
|
{
|
||||||
// Allocate array for the ROM image
|
|
||||||
myImage = make_unique<uInt8[]>(mySize);
|
|
||||||
|
|
||||||
// Copy the ROM image into my buffer
|
|
||||||
std::copy_n(image.get(), mySize, myImage.get());
|
|
||||||
createRomAccessArrays(mySize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
void CartridgeSB::reset()
|
|
||||||
{
|
|
||||||
initializeStartBank(bankCount() - 1);
|
|
||||||
|
|
||||||
// Upon reset we switch to the startup bank
|
|
||||||
bank(startBank());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void CartridgeSB::install(System& system)
|
void CartridgeSB::install(System& system)
|
||||||
{
|
{
|
||||||
mySystem = &system;
|
CartridgeEnhanced::install(system);
|
||||||
|
|
||||||
// Get the page accessing methods for the hot spots since they overlap
|
// Get the page accessing methods for the hot spots since they overlap
|
||||||
// areas within the TIA we'll need to forward requests to the TIA
|
// areas within the TIA we'll need to forward requests to the TIA
|
||||||
|
@ -62,19 +46,27 @@ void CartridgeSB::install(System& system)
|
||||||
// Set the page accessing methods for the hot spots
|
// Set the page accessing methods for the hot spots
|
||||||
for(uInt16 addr = 0x0800; addr < 0x0FFF; addr += System::PAGE_SIZE)
|
for(uInt16 addr = 0x0800; addr < 0x0FFF; addr += System::PAGE_SIZE)
|
||||||
mySystem->setPageAccess(addr, access);
|
mySystem->setPageAccess(addr, access);
|
||||||
|
|
||||||
// Install pages for startup bank
|
|
||||||
bank(startBank());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool CartridgeSB::checkSwitchBank(uInt16 address, uInt8)
|
||||||
|
{
|
||||||
|
// Switch banks if necessary
|
||||||
|
if((address & 0x1800) == 0x0800)
|
||||||
|
{
|
||||||
|
bank(address & startBank());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
uInt8 CartridgeSB::peek(uInt16 address)
|
uInt8 CartridgeSB::peek(uInt16 address)
|
||||||
{
|
{
|
||||||
address &= (0x17FF + (mySize >> 12));
|
address &= (0x17FF + bankCount());
|
||||||
|
|
||||||
// Switch banks if necessary
|
checkSwitchBank(address);
|
||||||
if ((address & 0x1800) == 0x0800)
|
|
||||||
bank(address & startBank());
|
|
||||||
|
|
||||||
if(!(address & 0x1000))
|
if(!(address & 0x1000))
|
||||||
{
|
{
|
||||||
|
@ -90,11 +82,9 @@ uInt8 CartridgeSB::peek(uInt16 address)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool CartridgeSB::poke(uInt16 address, uInt8 value)
|
bool CartridgeSB::poke(uInt16 address, uInt8 value)
|
||||||
{
|
{
|
||||||
address &= (0x17FF + (mySize >> 12));
|
address &= (0x17FF + bankCount());
|
||||||
|
|
||||||
// Switch banks if necessary
|
checkSwitchBank(address);
|
||||||
if((address & 0x1800) == 0x0800)
|
|
||||||
bank(address & startBank());
|
|
||||||
|
|
||||||
if(!(address & 0x1000))
|
if(!(address & 0x1000))
|
||||||
{
|
{
|
||||||
|
@ -105,87 +95,3 @@ bool CartridgeSB::poke(uInt16 address, uInt8 value)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
bool CartridgeSB::bank(uInt16 bank)
|
|
||||||
{
|
|
||||||
if(bankLocked()) return false;
|
|
||||||
|
|
||||||
// Remember what bank we're in
|
|
||||||
myBankOffset = bank << 12;
|
|
||||||
|
|
||||||
// Setup the page access methods for the current bank
|
|
||||||
System::PageAccess access(this, System::PageAccessType::READ);
|
|
||||||
|
|
||||||
// Map ROM image into the system
|
|
||||||
for(uInt16 addr = 0x1000; addr < 0x2000; addr += System::PAGE_SIZE)
|
|
||||||
{
|
|
||||||
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
|
|
||||||
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
|
|
||||||
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
|
|
||||||
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myAccessSize];
|
|
||||||
mySystem->setPageAccess(addr, access);
|
|
||||||
}
|
|
||||||
return myBankChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
uInt16 CartridgeSB::getBank(uInt16) const
|
|
||||||
{
|
|
||||||
return myBankOffset >> 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
uInt16 CartridgeSB::bankCount() const
|
|
||||||
{
|
|
||||||
return uInt16(mySize >> 12);
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
bool CartridgeSB::patch(uInt16 address, uInt8 value)
|
|
||||||
{
|
|
||||||
myImage[myBankOffset + (address & 0x0FFF)] = value;
|
|
||||||
return myBankChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
const uInt8* CartridgeSB::getImage(size_t& size) const
|
|
||||||
{
|
|
||||||
size = mySize;
|
|
||||||
return myImage.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
bool CartridgeSB::save(Serializer& out) const
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
out.putInt(myBankOffset);
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
cerr << "ERROR: CartridgeSB::save" << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
bool CartridgeSB::load(Serializer& in)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
myBankOffset = in.getInt();
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
cerr << "ERROR: CartridgeSB::load" << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remember what bank we were in
|
|
||||||
bank(myBankOffset >> 12);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#define CARTRIDGESB_HXX
|
#define CARTRIDGESB_HXX
|
||||||
|
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
#include "Cart.hxx"
|
#include "CartEnhanced.hxx"
|
||||||
#include "System.hxx"
|
#include "System.hxx"
|
||||||
#ifdef DEBUGGER_SUPPORT
|
#ifdef DEBUGGER_SUPPORT
|
||||||
#include "CartSBWidget.hxx"
|
#include "CartSBWidget.hxx"
|
||||||
|
@ -31,9 +31,9 @@
|
||||||
(32 banks) and $800 - $83F (64 banks). All mirrors up to $FFF are
|
(32 banks) and $800 - $83F (64 banks). All mirrors up to $FFF are
|
||||||
also used ($900, $A00, ...).
|
also used ($900, $A00, ...).
|
||||||
|
|
||||||
@author Fred X. Quimby
|
@author Fred X. Quimby, Thomas Jentzsch
|
||||||
*/
|
*/
|
||||||
class CartridgeSB : public Cartridge
|
class CartridgeSB : public CartridgeEnhanced
|
||||||
{
|
{
|
||||||
friend class CartridgeSBWidget;
|
friend class CartridgeSBWidget;
|
||||||
|
|
||||||
|
@ -51,11 +51,6 @@ class CartridgeSB : public Cartridge
|
||||||
virtual ~CartridgeSB() = default;
|
virtual ~CartridgeSB() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
Reset device to its power-on state
|
|
||||||
*/
|
|
||||||
void reset() override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Install cartridge in the specified system. Invoked by the system
|
Install cartridge in the specified system. Invoked by the system
|
||||||
when the cartridge is attached to it.
|
when the cartridge is attached to it.
|
||||||
|
@ -64,58 +59,6 @@ class CartridgeSB : public Cartridge
|
||||||
*/
|
*/
|
||||||
void install(System& system) override;
|
void install(System& system) override;
|
||||||
|
|
||||||
/**
|
|
||||||
Install pages for the specified bank in the system.
|
|
||||||
|
|
||||||
@param bank The bank that should be installed in the system
|
|
||||||
*/
|
|
||||||
bool bank(uInt16 bank) override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Get the current bank.
|
|
||||||
|
|
||||||
@param address The address to use when querying the bank
|
|
||||||
*/
|
|
||||||
uInt16 getBank(uInt16 address = 0) const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Query the number of banks supported by the cartridge.
|
|
||||||
*/
|
|
||||||
uInt16 bankCount() const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Patch the cartridge ROM.
|
|
||||||
|
|
||||||
@param address The ROM address to patch
|
|
||||||
@param value The value to place into the address
|
|
||||||
@return Success or failure of the patch operation
|
|
||||||
*/
|
|
||||||
bool patch(uInt16 address, uInt8 value) override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Access the internal ROM image for this cartridge.
|
|
||||||
|
|
||||||
@param size Set to the size of the internal ROM image data
|
|
||||||
@return A pointer to the internal ROM image data
|
|
||||||
*/
|
|
||||||
const uInt8* getImage(size_t& size) const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Save the current state of this cart to the given Serializer.
|
|
||||||
|
|
||||||
@param out The Serializer object to use
|
|
||||||
@return False on any errors, else true
|
|
||||||
*/
|
|
||||||
bool save(Serializer& out) const override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Load the current state of this cart from the given Serializer.
|
|
||||||
|
|
||||||
@param in The Serializer object to use
|
|
||||||
@return False on any errors, else true
|
|
||||||
*/
|
|
||||||
bool load(Serializer& in) override;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get a descriptor for the device name (used in error checking).
|
Get a descriptor for the device name (used in error checking).
|
||||||
|
|
||||||
|
@ -153,13 +96,13 @@ class CartridgeSB : public Cartridge
|
||||||
bool poke(uInt16 address, uInt8 value) override;
|
bool poke(uInt16 address, uInt8 value) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The 128-256K ROM image and size of the cartridge
|
bool checkSwitchBank(uInt16 address, uInt8 value = 0) override;
|
||||||
ByteBuffer myImage;
|
|
||||||
size_t mySize{0};
|
|
||||||
|
|
||||||
// Indicates the offset into the ROM image (aligns to current bank)
|
uInt16 hotspot() const override { return 0x0840; }
|
||||||
uInt32 myBankOffset{0};
|
|
||||||
|
|
||||||
|
uInt16 getStartBank() const override { return bankCount() - 1; }
|
||||||
|
|
||||||
|
private:
|
||||||
// Previous Device's page access
|
// Previous Device's page access
|
||||||
std::array<System::PageAccess, 8> myHotSpotPageAccess;
|
std::array<System::PageAccess, 8> myHotSpotPageAccess;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue