diff --git a/src/emucore/Cart0840.cxx b/src/emucore/Cart0840.cxx index f10dbb7b2..e071f61a2 100644 --- a/src/emucore/Cart0840.cxx +++ b/src/emucore/Cart0840.cxx @@ -21,25 +21,14 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cartridge0840::Cartridge0840(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 Cartridge0840::reset() -{ - // Upon reset we switch to the startup bank - initializeStartBank(0); - bank(startBank()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge0840::install(System& system) { - mySystem = &system; + CartridgeEnhanced::install(system); // 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 @@ -56,32 +45,34 @@ void Cartridge0840::install(System& system) System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x0800; addr < 0x0FFF; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); +} - // Install pages for bank 0 - bank(startBank()); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Cartridge0840::checkSwitchBank(uInt16 address, uInt8) +{ + // Switch banks if necessary + switch(address & 0x1840) + { + case 0x0800: + // Set the current bank to the lower 4k bank + bank(0); + return true; + + case 0x0840: + // Set the current bank to the upper 4k bank + bank(1); + return true; + + default: + break; + } + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 Cartridge0840::peek(uInt16 address) { - address &= 0x1840; - - // Switch banks if necessary - switch(address) - { - case 0x0800: - // Set the current bank to the lower 4k bank - bank(0); - break; - - case 0x0840: - // Set the current bank to the upper 4k bank - bank(1); - break; - - default: - break; - } + checkSwitchBank(address); // Because of the way we've set up accessing above, we can only // get here when the addresses are from 0x800 - 0xFFF @@ -92,24 +83,7 @@ uInt8 Cartridge0840::peek(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge0840::poke(uInt16 address, uInt8 value) { - address &= 0x1840; - - // Switch banks if necessary - switch(address) - { - case 0x0800: - // Set the current bank to the lower 4k bank - bank(0); - break; - - case 0x0840: - // Set the current bank to the upper 4k bank - bank(1); - break; - - default: - break; - } + checkSwitchBank(address); // Because of the way accessing is set up, we will may get here by // doing a write to 0x800 - 0xFFF or cart; we ignore the cart write @@ -121,85 +95,3 @@ bool Cartridge0840::poke(uInt16 address, uInt8 value) return false; } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge0840::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)]; - mySystem->setPageAccess(addr, access); - } - return myBankChanged = true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge0840::getBank(uInt16) const -{ - return myBankOffset >> 12; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge0840::bankCount() const -{ - return 2; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge0840::patch(uInt16 address, uInt8 value) -{ - myImage[myBankOffset + (address & 0x0fff)] = value; - return myBankChanged = true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const uInt8* Cartridge0840::getImage(size_t& size) const -{ - size = myImage.size(); - return myImage.data(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge0840::save(Serializer& out) const -{ - try - { - out.putShort(myBankOffset); - } - catch(...) - { - cerr << "ERROR: Cartridge0840::save" << endl; - return false; - } - - return true; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge0840::load(Serializer& in) -{ - try - { - myBankOffset = in.getShort(); - } - catch(...) - { - cerr << "ERROR: Cartridge0840::load" << endl; - return false; - } - - // Remember what bank we were in - bank(myBankOffset); - - return true; -} diff --git a/src/emucore/Cart0840.hxx b/src/emucore/Cart0840.hxx index 87d372f59..af1977485 100644 --- a/src/emucore/Cart0840.hxx +++ b/src/emucore/Cart0840.hxx @@ -19,7 +19,7 @@ #define CARTRIDGE0840_HXX #include "bspf.hxx" -#include "Cart.hxx" +#include "CartEnhanced.hxx" #include "System.hxx" #ifdef DEBUGGER_SUPPORT #include "Cart0840Widget.hxx" @@ -30,9 +30,9 @@ are two 4K banks, which are switched by accessing $0800 (bank 0) and $0840 (bank 1). - @author Fred X. Quimby + @author Fred X. Quimby, Thomas Jentzsch */ -class Cartridge0840 : public Cartridge +class Cartridge0840 : public CartridgeEnhanced { friend class Cartridge0840Widget; @@ -50,11 +50,6 @@ class Cartridge0840 : public Cartridge virtual ~Cartridge0840() = 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. @@ -63,58 +58,6 @@ class Cartridge0840 : 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). @@ -152,12 +95,11 @@ class Cartridge0840 : public Cartridge bool poke(uInt16 address, uInt8 value) override; private: - // The 8K ROM image of the cartridge - std::array myImage; + bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - // Indicates the offset into the ROM image (aligns to current bank) - uInt16 myBankOffset{0}; + uInt16 hotspot() const override { return 0x0840; } + private: // Previous Device's page access std::array myHotSpotPageAccess; diff --git a/src/emucore/CartBF.hxx b/src/emucore/CartBF.hxx index 08b54d731..23c51f760 100644 --- a/src/emucore/CartBF.hxx +++ b/src/emucore/CartBF.hxx @@ -73,7 +73,7 @@ class CartridgeBF : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - uInt16 romHotspot() const override { return 0x1F80; } + uInt16 hotspot() const override { return 0x1F80; } uInt16 getStartBank() const override { return 1; } diff --git a/src/emucore/CartDF.hxx b/src/emucore/CartDF.hxx index 5b2025285..3c33e8bff 100644 --- a/src/emucore/CartDF.hxx +++ b/src/emucore/CartDF.hxx @@ -73,7 +73,7 @@ class CartridgeDF : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - uInt16 romHotspot() const override { return 0x1FC0; } + uInt16 hotspot() const override { return 0x1FC0; } uInt16 getStartBank() const override { return 15; } diff --git a/src/emucore/CartE0.hxx b/src/emucore/CartE0.hxx index 08fc82806..7c1fe18e3 100644 --- a/src/emucore/CartE0.hxx +++ b/src/emucore/CartE0.hxx @@ -86,7 +86,7 @@ class CartridgeE0 : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 = 0) override; - uInt16 romHotspot() const override { return 0x1FE0; } + uInt16 hotspot() const override { return 0x1FE0; } private: // log(ROM bank segment size) / log(2) diff --git a/src/emucore/CartEF.hxx b/src/emucore/CartEF.hxx index 1461e954d..ff71b9909 100644 --- a/src/emucore/CartEF.hxx +++ b/src/emucore/CartEF.hxx @@ -73,7 +73,7 @@ class CartridgeEF : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - uInt16 romHotspot() const override { return 0x1FE0; } + uInt16 hotspot() const override { return 0x1FE0; } uInt16 getStartBank() const override { return 1; } diff --git a/src/emucore/CartEnhanced.cxx b/src/emucore/CartEnhanced.cxx index adcd8bc0e..a29cdcb6f 100644 --- a/src/emucore/CartEnhanced.cxx +++ b/src/emucore/CartEnhanced.cxx @@ -102,7 +102,7 @@ uInt8 CartridgeEnhanced::peek(uInt16 address) { uInt16 peekAddress = address; - if (romHotspot()) + if (hotspot()) checkSwitchBank(address & 0x0FFF); address &= myBankMask; @@ -146,13 +146,13 @@ bool CartridgeEnhanced::bank(uInt16 bank, uInt16 segment) // Remember what bank is in which segment uInt32 bankOffset = myCurrentSegOffset[segment] = bank << myBankShift; uInt16 segmentOffset = segment << myBankShift; - uInt16 romHotspot = this->romHotspot(); + uInt16 hotspot = this->hotspot(); uInt16 hotSpotAddr; uInt16 fromAddr = (segmentOffset + 0x1000 + myRamSize * 2) & ~System::PAGE_MASK; uInt16 toAddr = (segmentOffset + 0x1000 + myBankSize) & ~System::PAGE_MASK; - if(romHotspot) - hotSpotAddr = (romHotspot & ~System::PAGE_MASK); + if(hotspot) + hotSpotAddr = (hotspot & ~System::PAGE_MASK); else hotSpotAddr = 0xFFFF; // none diff --git a/src/emucore/CartEnhanced.hxx b/src/emucore/CartEnhanced.hxx index 703cd320f..a78b725e7 100644 --- a/src/emucore/CartEnhanced.hxx +++ b/src/emucore/CartEnhanced.hxx @@ -203,9 +203,9 @@ class CartridgeEnhanced : public Cartridge /** Get the hotspot in ROM address space. - @return The first hotspot address in ROM space or 0 + @return The first hotspot address (ususally in ROM) space or 0 */ - virtual uInt16 romHotspot() const { return 0; } + virtual uInt16 hotspot() const { return 0; } // TODO: handle cases where there the hotspots cover multiple pages private: diff --git a/src/emucore/CartF0.hxx b/src/emucore/CartF0.hxx index e885cd934..0d5837066 100644 --- a/src/emucore/CartF0.hxx +++ b/src/emucore/CartF0.hxx @@ -70,7 +70,7 @@ class CartridgeF0 : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - uInt16 romHotspot() const override { return 0x1FF0; } + uInt16 hotspot() const override { return 0x1FF0; } uInt16 getStartBank() const override { return 15; } diff --git a/src/emucore/CartF4.hxx b/src/emucore/CartF4.hxx index 5b54af54d..d44e96640 100644 --- a/src/emucore/CartF4.hxx +++ b/src/emucore/CartF4.hxx @@ -69,7 +69,7 @@ class CartridgeF4 : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - uInt16 romHotspot() const override { return 0x1FF4; } + uInt16 hotspot() const override { return 0x1FF4; } private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartF6.hxx b/src/emucore/CartF6.hxx index 2f183ad7b..16faeebab 100644 --- a/src/emucore/CartF6.hxx +++ b/src/emucore/CartF6.hxx @@ -69,7 +69,7 @@ class CartridgeF6 : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - uInt16 romHotspot() const override { return 0x1FF6; } + uInt16 hotspot() const override { return 0x1FF6; } private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartF8.hxx b/src/emucore/CartF8.hxx index 23863fa57..29b308808 100644 --- a/src/emucore/CartF8.hxx +++ b/src/emucore/CartF8.hxx @@ -69,7 +69,7 @@ class CartridgeF8 : public CartridgeEnhanced private: bool checkSwitchBank(uInt16 address, uInt8 value = 0) override; - uInt16 romHotspot() const override { return 0x1FF8; } + uInt16 hotspot() const override { return 0x1FF8; } uInt16 getStartBank() const override { return 1; }