From 7fc1c54d4c1474c045687a7d71a8c61bfcf25f9a Mon Sep 17 00:00:00 2001 From: thrust26 Date: Thu, 30 Nov 2017 17:26:58 +0100 Subject: [PATCH] more E7 refactoring/cleanup --- src/emucore/CartE7.cxx | 13 ------------- src/emucore/CartE7.hxx | 13 ------------- src/emucore/CartE78K.cxx | 13 ------------- src/emucore/CartE78K.hxx | 13 ------------- src/emucore/CartMNetwork.cxx | 25 +++++++++++++++++++++---- src/emucore/CartMNetwork.hxx | 14 ++++++++++++-- 6 files changed, 33 insertions(+), 58 deletions(-) diff --git a/src/emucore/CartE7.cxx b/src/emucore/CartE7.cxx index 3752e28b8..5815b3222 100644 --- a/src/emucore/CartE7.cxx +++ b/src/emucore/CartE7.cxx @@ -39,16 +39,3 @@ void CartridgeE7::checkSwitchBank(uInt16 address) bankRAM(address & 0x0003); } } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeE7::bankCount() const -{ - return BANK_COUNT; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 CartridgeE7::romSize() const -{ - return bankCount() * BANK_SIZE; -} - diff --git a/src/emucore/CartE7.hxx b/src/emucore/CartE7.hxx index fa2d809e5..8552076c3 100644 --- a/src/emucore/CartE7.hxx +++ b/src/emucore/CartE7.hxx @@ -46,11 +46,6 @@ class CartridgeE7 : public CartridgeMNetwork virtual ~CartridgeE7() = default; public: - /** - Query the number of banks supported by the cartridge. - */ - uInt16 bankCount() const override; - /** Get a descriptor for the device name (used in error checking). @@ -71,19 +66,11 @@ class CartridgeE7 : public CartridgeMNetwork #endif private: - /** - Query the size of the BS type. - */ - uInt32 romSize() const override; - /** Check hotspots and switch bank if triggered. */ void checkSwitchBank(uInt16 address) override; - // Number of banks - static constexpr uInt32 BANK_COUNT = 8; - private: // Following constructors and assignment operators not supported CartridgeE7() = delete; diff --git a/src/emucore/CartE78K.cxx b/src/emucore/CartE78K.cxx index 7d9604a76..3cfff2bfe 100644 --- a/src/emucore/CartE78K.cxx +++ b/src/emucore/CartE78K.cxx @@ -39,16 +39,3 @@ void CartridgeE78K::checkSwitchBank(uInt16 address) bankRAM(address & 0x0003); } } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeE78K::bankCount() const -{ - return BANK_COUNT; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 CartridgeE78K::romSize() const -{ - return bankCount() * BANK_SIZE; -} - diff --git a/src/emucore/CartE78K.hxx b/src/emucore/CartE78K.hxx index 9bdd562ec..1a9abfbc3 100644 --- a/src/emucore/CartE78K.hxx +++ b/src/emucore/CartE78K.hxx @@ -44,11 +44,6 @@ class CartridgeE78K : public CartridgeMNetwork virtual ~CartridgeE78K() = default; public: - /** - Query the number of banks supported by the cartridge. - */ - uInt16 bankCount() const override; - /** Get a descriptor for the device name (used in error checking). @@ -69,19 +64,11 @@ class CartridgeE78K : public CartridgeMNetwork #endif private: - /** - Query the size of the BS type. - */ - uInt32 romSize() const override; - /** Check hotspots and switch bank if triggered. */ void checkSwitchBank(uInt16 address) override; - // Number of banks - static constexpr uInt32 BANK_COUNT = 4; - private: // Following constructors and assignment operators not supported CartridgeE78K() = delete; diff --git a/src/emucore/CartMNetwork.cxx b/src/emucore/CartMNetwork.cxx index e35d47089..ece1723a9 100644 --- a/src/emucore/CartMNetwork.cxx +++ b/src/emucore/CartMNetwork.cxx @@ -22,6 +22,7 @@ CartridgeMNetwork::CartridgeMNetwork(const BytePtr& image, uInt32 size, const Settings& settings) : Cartridge(settings), + mySize(size), myCurrentRAM(0) { } @@ -29,8 +30,11 @@ CartridgeMNetwork::CartridgeMNetwork(const BytePtr& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeMNetwork::initialize(const BytePtr& image, uInt32 size) { + // Allocate array for the ROM image + myImage = make_unique(size); + // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(romSize(), size)); + memcpy(myImage.get(), image.get(), std::min(romSize(), size)); createCodeAccessBase(romSize() + RAM_SIZE); // Remember startup bank @@ -94,7 +98,7 @@ void CartridgeMNetwork::install(System& system) // Setup the second segment to always point to the last ROM slice setAccess(0x1A00, 0x1FE0U & (~System::PAGE_MASK - 0x1A00), - myRAMSlice * BANK_SIZE, myImage, myRAMSlice * BANK_SIZE, System::PA_READ, BANK_SIZE - 1); + myRAMSlice * BANK_SIZE, myImage.get(), myRAMSlice * BANK_SIZE, System::PA_READ, BANK_SIZE - 1); myCurrentSlice[1] = myRAMSlice; // Install some default banks for the RAM and first segment @@ -187,7 +191,7 @@ bool CartridgeMNetwork::bank(uInt16 slice) uInt16 offset = slice << 11; // * BANK_SIZE (2048) // Map ROM image into first segment - setAccess(0x1000, BANK_SIZE, offset, myImage, offset, System::PA_READ); + setAccess(0x1000, BANK_SIZE, offset, myImage.get(), offset, System::PA_READ); } else { @@ -239,7 +243,7 @@ bool CartridgeMNetwork::patch(uInt16 address, uInt8 value) const uInt8* CartridgeMNetwork::getImage(uInt32& size) const { size = bankCount() * BANK_SIZE; - return myImage; + return myImage.get(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -283,3 +287,16 @@ bool CartridgeMNetwork::load(Serializer& in) return true; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt16 CartridgeMNetwork::bankCount() const +{ + return mySize >> 11; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt32 CartridgeMNetwork::romSize() const +{ + return bankCount() * BANK_SIZE; +} + diff --git a/src/emucore/CartMNetwork.hxx b/src/emucore/CartMNetwork.hxx index 832221c55..f1a5c2b4f 100644 --- a/src/emucore/CartMNetwork.hxx +++ b/src/emucore/CartMNetwork.hxx @@ -101,6 +101,11 @@ class CartridgeMNetwork : public Cartridge */ uInt16 getBank() const override; + /** + Query the number of banks supported by the cartridge. + */ + uInt16 bankCount() const override; + /** Patch the cartridge ROM. @@ -176,7 +181,7 @@ class CartridgeMNetwork : public Cartridge /** Query the size of the BS type. */ - virtual uInt32 romSize() const = 0; + uInt32 romSize() const; /** Check hotspots and switch bank if triggered. @@ -187,8 +192,13 @@ class CartridgeMNetwork : public Cartridge uInt16 codeOffset, System::PageAccessType type, uInt16 addrMask = 0); private: + // Pointer to a dynamically allocated ROM image of the cartridge + BytePtr myImage; // The 16K ROM image of the cartridge (works for E78K too) - uInt8 myImage[BANK_SIZE * 8]; + //uInt8 myImage[BANK_SIZE * 8]; + + // Size of the ROM image + uInt32 mySize; // The 2K of RAM uInt8 myRAM[RAM_SIZE];