From 76bd7f493fd9dd9e87be46086d6eaafac905646a Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sun, 9 Apr 2023 15:18:24 +0200 Subject: [PATCH] added missing PlusROM support for E7 bankswitching (fixes #965) --- Changes.txt | 2 ++ src/emucore/CartE7.cxx | 25 +++++++++++++++++++++++++ src/emucore/CartE7.hxx | 22 ++++++++++++++++++++++ src/emucore/CartEnhanced.cxx | 1 - 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Changes.txt b/Changes.txt index 779db32b2..36e866c46 100644 --- a/Changes.txt +++ b/Changes.txt @@ -30,6 +30,8 @@ * Enhanced Kid Vid support to play tape audio. + * Added missing PlusROM support for E7 bankswitching. + * Acclerated emulation up to ~15% (ARM). * Added BUS bankswitching support for some older demos. diff --git a/src/emucore/CartE7.cxx b/src/emucore/CartE7.cxx index 6d191d58b..ee9163826 100644 --- a/src/emucore/CartE7.cxx +++ b/src/emucore/CartE7.cxx @@ -41,6 +41,11 @@ void CartridgeE7::initialize(const ByteBuffer& image, size_t size) myCurrentBank.fill(0); myRAMBank = romBankCount() - 1; // NOLINT + + myPlusROM = make_unique(mySettings, *this); + + // Determine whether we have a PlusROM cart + myPlusROM->initialize(myImage, mySize); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -57,6 +62,9 @@ void CartridgeE7::reset() bank(startBank()); myBankChanged = true; + + if (myPlusROM->isValid()) + myPlusROM->reset(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -142,6 +150,15 @@ void CartridgeE7::checkSwitchBank(uInt16 address) uInt8 CartridgeE7::peek(uInt16 address) { const uInt16 peekAddress = address; + + // Is this a PlusROM? + if (myPlusROM->isValid()) + { + uInt8 value = 0; + if (myPlusROM->peekHotspot(address, value)) + return value; + } + address &= 0x0FFF; // Switch banks if necessary @@ -164,6 +181,10 @@ uInt8 CartridgeE7::peek(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeE7::poke(uInt16 address, uInt8 value) { + // Is this a PlusROM? + if (myPlusROM->isValid() && myPlusROM->pokeHotspot(address, value)) + return true; + const uInt16 pokeAddress = address; address &= 0x0FFF; @@ -309,6 +330,8 @@ bool CartridgeE7::save(Serializer& out) const out.putShortArray(myCurrentBank.data(), myCurrentBank.size()); out.putShort(myCurrentRAM); out.putByteArray(myRAM.data(), myRAM.size()); + if (myPlusROM->isValid() && !myPlusROM->save(out)) + return false; } catch(...) { @@ -327,6 +350,8 @@ bool CartridgeE7::load(Serializer& in) in.getShortArray(myCurrentBank.data(), myCurrentBank.size()); myCurrentRAM = in.getShort(); in.getByteArray(myRAM.data(), myRAM.size()); + if (myPlusROM->isValid() && !myPlusROM->load(in)) + return false; } catch(...) { diff --git a/src/emucore/CartE7.hxx b/src/emucore/CartE7.hxx index bfb631333..56cecefea 100644 --- a/src/emucore/CartE7.hxx +++ b/src/emucore/CartE7.hxx @@ -22,6 +22,7 @@ #include "System.hxx" #include "bspf.hxx" #include "Cart.hxx" +#include "PlusROM.hxx" #ifdef DEBUGGER_SUPPORT #include "CartE7Widget.hxx" #endif @@ -177,6 +178,24 @@ class CartridgeE7 : public Cartridge */ string name() const override { return "CartridgeE7"; } + /** + Answer whether this is a PlusROM cart. Note that until the + initialize method has been called, this will always return false. + + @return Whether this is actually a PlusROM cart + */ + bool isPlusROM() const override { return myPlusROM->isValid(); } + + /** + Set the callback for displaying messages + */ + void setMessageCallback(const messageCallback& callback) override + { + Cartridge::setMessageCallback(callback); + if (myPlusROM->isValid()) + myPlusROM->setMessageCallback(myMsgCallback); + } + #ifdef DEBUGGER_SUPPORT /** Get debugger widget responsible for accessing the inner workings @@ -244,6 +263,9 @@ class CartridgeE7 : public Cartridge // The number of the RAM bank (== bankCount() - 1) uInt32 myRAMBank{0}; + // Handle PlusROM functionality, if available + unique_ptr myPlusROM; + private: // Following constructors and assignment operators not supported CartridgeE7() = delete; diff --git a/src/emucore/CartEnhanced.cxx b/src/emucore/CartEnhanced.cxx index a101ec702..bcd78f5f4 100644 --- a/src/emucore/CartEnhanced.cxx +++ b/src/emucore/CartEnhanced.cxx @@ -394,7 +394,6 @@ bool CartridgeEnhanced::save(Serializer& out) const if(myPlusROM->isValid() && !myPlusROM->save(out)) return false; - } catch(...) {