diff --git a/src/debugger/gui/CartX07Widget.cxx b/src/debugger/gui/CartX07Widget.cxx index 78fd70d3b..0c6bc5b95 100644 --- a/src/debugger/gui/CartX07Widget.cxx +++ b/src/debugger/gui/CartX07Widget.cxx @@ -103,7 +103,7 @@ string CartridgeX07Widget::bankState() { ostringstream& buf = buffer(); - buf << "Bank = " << std::dec << myCart.myCurrentBank; + buf << "Bank = " << std::dec << myCart.getBank(); return buf.str(); } diff --git a/src/emucore/CartX07.cxx b/src/emucore/CartX07.cxx index 96bf5e4ed..ac40b6ac6 100644 --- a/src/emucore/CartX07.cxx +++ b/src/emucore/CartX07.cxx @@ -23,25 +23,14 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeX07::CartridgeX07(const ByteBuffer& image, size_t size, const string& md5, const Settings& settings) - : Cartridge(settings, md5) + : CartridgeEnhanced(image, size, md5, settings) { - // Copy the ROM image into my buffer - std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); - createRomAccessArrays(myImage.size()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CartridgeX07::reset() -{ - // Upon reset we switch to the startup bank - initializeStartBank(0); - bank(startBank()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeX07::install(System& system) { - mySystem = &system; + CartridgeEnhanced::install(system); // Set the page accessing methods for the hot spots // The hotspots use almost all addresses below 0x1000, so we simply grab them @@ -49,31 +38,42 @@ void CartridgeX07::install(System& system) System::PageAccess access(this, System::PageAccessType::READWRITE); for(uInt16 addr = 0x00; addr < 0x1000; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); +} - // Install pages for the startup bank - bank(startBank()); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CartridgeX07::checkSwitchBank(uInt16 address, uInt8) +{ + // Switch banks if necessary + if((address & 0x180f) == 0x080d) + { + bank((address & 0xf0) >> 4); + return true; + } + else if((address & 0x1880) == 0) + { + if((getBank() & 0xe) == 0xe) + { + bank(((address & 0x40) >> 6) | 0xe); + return true; + } + } + + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CartridgeX07::peek(uInt16 address) { - uInt8 value = 0; - + uInt8 value = 0; // JTZ: is this correct? // Check for RAM or TIA mirroring uInt16 lowAddress = address & 0x3ff; + if(lowAddress & 0x80) value = mySystem->m6532().peek(address); else if(!(lowAddress & 0x200)) value = mySystem->tia().peek(address); - // Switch banks if necessary - if((address & 0x180f) == 0x080d) - bank((address & 0xf0) >> 4); - else if((address & 0x1880) == 0) - { - if((myCurrentBank & 0xe) == 0xe) - bank(((address & 0x40) >> 6) | (myCurrentBank & 0xe)); - } + checkSwitchBank(address); return value; } @@ -83,103 +83,13 @@ bool CartridgeX07::poke(uInt16 address, uInt8 value) { // Check for RAM or TIA mirroring uInt16 lowAddress = address & 0x3ff; + if(lowAddress & 0x80) mySystem->m6532().poke(address, value); else if(!(lowAddress & 0x200)) mySystem->tia().poke(address, value); - // Switch banks if necessary - if((address & 0x180f) == 0x080d) - bank((address & 0xf0) >> 4); - else if((address & 0x1880) == 0) - { - if((myCurrentBank & 0xe) == 0xe) - bank(((address & 0x40) >> 6) | (myCurrentBank & 0xe)); - } + checkSwitchBank(address); + return false; } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeX07::bank(uInt16 bank) -{ - if(bankLocked()) return false; - - // Remember what bank we're in - myCurrentBank = (bank & 0x0f); - uInt32 offset = myCurrentBank << 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[offset + (addr & 0x0FFF)]; - access.romAccessBase = &myRomAccessBase[offset + (addr & 0x0FFF)]; - access.romPeekCounter = &myRomAccessCounter[offset + (addr & 0x0FFF)]; - access.romPokeCounter = &myRomAccessCounter[offset + (addr & 0x0FFF) + myAccessSize]; - mySystem->setPageAccess(addr, access); - } - return myBankChanged = true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeX07::getBank(uInt16) const -{ - return myCurrentBank; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeX07::bankCount() const -{ - return 16; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeX07::patch(uInt16 address, uInt8 value) -{ - myImage[(myCurrentBank << 12) + (address & 0x0FFF)] = value; - return myBankChanged = true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const uInt8* CartridgeX07::getImage(size_t& size) const -{ - size = myImage.size(); - return myImage.data(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeX07::save(Serializer& out) const -{ - try - { - out.putShort(myCurrentBank); - } - catch(...) - { - cerr << "ERROR: CartridgeX07::save" << endl; - return false; - } - - return true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CartridgeX07::load(Serializer& in) -{ - try - { - myCurrentBank = in.getShort(); - } - catch(...) - { - cerr << "ERROR: CartridgeX07::load" << endl; - return false; - } - - // Remember what bank we were in - bank(myCurrentBank); - - return true; -} diff --git a/src/emucore/CartX07.hxx b/src/emucore/CartX07.hxx index 0beff0e0b..3cde4efdf 100644 --- a/src/emucore/CartX07.hxx +++ b/src/emucore/CartX07.hxx @@ -21,7 +21,7 @@ class System; #include "bspf.hxx" -#include "Cart.hxx" +#include "CartEnhanced.hxx" #ifdef DEBUGGER_SUPPORT #include "CartX07Widget.hxx" #endif @@ -40,9 +40,9 @@ class System; Note that the latter will hit on almost any TIA access. - @author Eckhard Stolberg + @author Eckhard Stolberg, Thomas Jentzsch */ -class CartridgeX07 : public Cartridge +class CartridgeX07 : public CartridgeEnhanced { friend class CartridgeX07Widget; @@ -60,11 +60,6 @@ class CartridgeX07 : public Cartridge virtual ~CartridgeX07() = default; public: - /** - Reset device to its power-on state - */ - void reset() override; - /** Install cartridge in the specified system. Invoked by the system when the cartridge is attached to it. @@ -73,58 +68,6 @@ class CartridgeX07 : public Cartridge */ 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). @@ -162,11 +105,7 @@ class CartridgeX07 : public Cartridge bool poke(uInt16 address, uInt8 value) override; private: - // The 64K ROM image of the cartridge - std::array myImage; - - // Indicates which bank is currently active - uInt16 myCurrentBank{0}; + bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; private: // Following constructors and assignment operators not supported