diff --git a/src/common/audio/ConvolutionBuffer.cxx b/src/common/audio/ConvolutionBuffer.cxx index 99f28f121..5ef22ef6e 100644 --- a/src/common/audio/ConvolutionBuffer.cxx +++ b/src/common/audio/ConvolutionBuffer.cxx @@ -23,7 +23,7 @@ ConvolutionBuffer::ConvolutionBuffer(uInt32 size) mySize(size) { myData = make_unique(mySize); - memset(myData.get(), 0, mySize * sizeof(float)); + std::fill_n(myData.get(), mySize, 0.f); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/audio/LanczosResampler.cxx b/src/common/audio/LanczosResampler.cxx index 4ed1e55a4..02c760c51 100644 --- a/src/common/audio/LanczosResampler.cxx +++ b/src/common/audio/LanczosResampler.cxx @@ -141,7 +141,7 @@ void LanczosResampler::fillFragment(float* fragment, uInt32 length) } if (!myCurrentFragment) { - memset(fragment, 0, sizeof(float) * length); + std::fill_n(fragment, length, 0.f); return; } diff --git a/src/common/audio/SimpleResampler.cxx b/src/common/audio/SimpleResampler.cxx index bba43ddf2..e3efd2df6 100644 --- a/src/common/audio/SimpleResampler.cxx +++ b/src/common/audio/SimpleResampler.cxx @@ -44,7 +44,7 @@ void SimpleResampler::fillFragment(float* fragment, uInt32 length) } if (!myCurrentFragment) { - memset(fragment, 0, sizeof(float) * length); + std::fill_n(fragment, length, 0.f); return; } diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index f123fa9e6..d39aad9be 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -74,7 +74,6 @@ using std::make_shared; using std::array; using std::vector; using std::runtime_error; -using std::memcpy; // Common array types using IntArray = std::vector; @@ -85,6 +84,12 @@ using ShortArray = std::vector; using StringList = std::vector; using ByteBuffer = std::unique_ptr; +// We use KB a lot; let's make a literal for it +constexpr size_t operator "" _KB(unsigned long long size) +{ + return static_cast(size * 1024); +} + static const string EmptyString(""); // This is defined by some systems, but Stella has other uses for it diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 7dea78cd1..9ee8a7576 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -507,9 +507,9 @@ bool CartDebug::addDirective(CartDebug::DisasmType type, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int CartDebug::getBank(uInt16 addr) +int CartDebug::getBank(uInt16 address) { - return myConsole.cartridge().getBank(addr); + return myConsole.cartridge().getBank(address); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/CartDebug.hxx b/src/debugger/CartDebug.hxx index 61a3d66bf..304763304 100644 --- a/src/debugger/CartDebug.hxx +++ b/src/debugger/CartDebug.hxx @@ -257,6 +257,8 @@ class CartDebug : public DebuggerSystem using LabelToAddr = std::map>; + using AddrTypeArray = std::array; + struct DirectiveTag { DisasmType type; uInt16 start; @@ -277,7 +279,7 @@ class CartDebug : public DebuggerSystem }; // Address type information determined by Distella - uInt8 myDisLabels[0x1000], myDisDirectives[0x1000]; + AddrTypeArray myDisLabels, myDisDirectives; // Information on equates used in the disassembly struct ReservedEquates { diff --git a/src/debugger/DiStella.cxx b/src/debugger/DiStella.cxx index 8944382c5..81d0342ed 100644 --- a/src/debugger/DiStella.cxx +++ b/src/debugger/DiStella.cxx @@ -23,7 +23,8 @@ using Common::Base; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DiStella::DiStella(const CartDebug& dbg, CartDebug::DisassemblyList& list, CartDebug::BankInfo& info, const DiStella::Settings& s, - uInt8* labels, uInt8* directives, + CartDebug::AddrTypeArray& labels, + CartDebug::AddrTypeArray& directives, CartDebug::ReservedEquates& reserved) : myDbg(dbg), myList(list), @@ -57,8 +58,8 @@ DiStella::DiStella(const CartDebug& dbg, CartDebug::DisassemblyList& list, } myAppData.length = info.size; - memset(myLabels, 0, 0x1000); - memset(myDirectives, 0, 0x1000); + myLabels.fill(0); + myDirectives.fill(0); // Process any directives first, as they override automatic code determination processDirectives(info.directiveList); diff --git a/src/debugger/DiStella.hxx b/src/debugger/DiStella.hxx index 87017ec5b..5ed4e8a33 100644 --- a/src/debugger/DiStella.hxx +++ b/src/debugger/DiStella.hxx @@ -67,7 +67,8 @@ class DiStella */ DiStella(const CartDebug& dbg, CartDebug::DisassemblyList& list, CartDebug::BankInfo& info, const DiStella::Settings& settings, - uInt8* labels, uInt8* directives, + CartDebug::AddrTypeArray& labels, + CartDebug::AddrTypeArray& directives, CartDebug::ReservedEquates& reserved); private: @@ -136,7 +137,8 @@ class DiStella the directives take priority The address mark type is defined in CartDebug.hxx */ - uInt8 *myLabels, *myDirectives; + CartDebug::AddrTypeArray& myLabels; + CartDebug::AddrTypeArray& myDirectives; /** Enumeration of the 6502 addressing modes diff --git a/src/debugger/TrapArray.hxx b/src/debugger/TrapArray.hxx index 76985e10e..18ba3d634 100644 --- a/src/debugger/TrapArray.hxx +++ b/src/debugger/TrapArray.hxx @@ -22,38 +22,38 @@ class TrapArray { -public: - TrapArray() : myInitialized(false) {} + public: + TrapArray() : myInitialized(false) {} - bool isSet(const uInt16 address) const { return myCount[address]; } - bool isClear(const uInt16 address) const { return myCount[address] == 0; } + bool isSet(const uInt16 address) const { return myCount[address]; } + bool isClear(const uInt16 address) const { return myCount[address] == 0; } - void add(const uInt16 address) { myCount[address]++; } - void remove(const uInt16 address) { myCount[address]--; } - //void toggle(uInt16 address) { myCount[address] ? remove(address) : add(address); } // TODO condition + void add(const uInt16 address) { myCount[address]++; } + void remove(const uInt16 address) { myCount[address]--; } + // void toggle(uInt16 address) { myCount[address] ? remove(address) : add(address); } // TODO condition - void initialize() { - if(!myInitialized) - memset(myCount, 0, sizeof(myCount)); - myInitialized = true; - } - void clearAll() { myInitialized = false; memset(myCount, 0, sizeof(myCount)); } + void initialize() { + if(!myInitialized) + myCount.fill(0); + myInitialized = true; + } + void clearAll() { myInitialized = false; myCount.fill(0); } - bool isInitialized() const { return myInitialized; } + bool isInitialized() const { return myInitialized; } -private: - // The actual counts - uInt8 myCount[0x10000]; + private: + // The actual counts + std::array myCount; - // Indicates whether we should treat this array as initialized - bool myInitialized; + // Indicates whether we should treat this array as initialized + bool myInitialized; -private: - // Following constructors and assignment operators not supported - TrapArray(const TrapArray&) = delete; - TrapArray(TrapArray&&) = delete; - TrapArray& operator=(const TrapArray&) = delete; - TrapArray& operator=(TrapArray&&) = delete; + private: + // Following constructors and assignment operators not supported + TrapArray(const TrapArray&) = delete; + TrapArray(TrapArray&&) = delete; + TrapArray& operator=(const TrapArray&) = delete; + TrapArray& operator=(TrapArray&&) = delete; }; #endif diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index cd2780478..2845645cb 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -123,7 +123,7 @@ void Cartridge::createCodeAccessBase(uInt32 size) { #ifdef DEBUGGER_SUPPORT myCodeAccessBase = make_unique(size); - memset(myCodeAccessBase.get(), CartDebug::ROW, size); + std::fill_n(myCodeAccessBase.get(), size, CartDebug::ROW); #else myCodeAccessBase = nullptr; #endif @@ -136,7 +136,7 @@ void Cartridge::initializeRAM(uInt8* arr, uInt32 size, uInt8 val) const for(uInt32 i = 0; i < size; ++i) arr[i] = mySystem->randGenerator().next(); else - memset(arr, val, size); + std::fill_n(arr, size, val); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart.hxx b/src/emucore/Cart.hxx index 0b411fa87..6da1e72c7 100644 --- a/src/emucore/Cart.hxx +++ b/src/emucore/Cart.hxx @@ -153,17 +153,14 @@ class Cartridge : public Device virtual bool bank(uInt16) { return false; } /** - Get the current bank. Carts which have only one bank (either real - or virtual) always report that bank as zero. - */ - virtual uInt16 getBank() const { return 0; } + Get the current bank for the provided address. Carts which have only + one bank (either real or virtual) always report that bank as zero. - /** - Get the current bank for the provided address. - - @param addr The address to get the bank for + @param address Query the bank used for this specific address + Derived classes are free to ignore this; it only + makes sense in some situations. */ - virtual uInt16 getBank(uInt16 addr) const { return getBank(); } + virtual uInt16 getBank(uInt16 address = 0) const { return 0; } /** Query the number of 'banks' supported by the cartridge. Note that diff --git a/src/emucore/Cart0840.cxx b/src/emucore/Cart0840.cxx index af6c0d703..9676a244a 100644 --- a/src/emucore/Cart0840.cxx +++ b/src/emucore/Cart0840.cxx @@ -25,8 +25,8 @@ Cartridge0840::Cartridge0840(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(8192u, size)); - createCodeAccessBase(8192); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -145,7 +145,7 @@ bool Cartridge0840::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge0840::getBank() const +uInt16 Cartridge0840::getBank(uInt16) const { return myBankOffset >> 12; } @@ -166,8 +166,8 @@ bool Cartridge0840::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* Cartridge0840::getImage(uInt32& size) const { - size = 8192; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart0840.hxx b/src/emucore/Cart0840.hxx index eef306fba..2fa2abec4 100644 --- a/src/emucore/Cart0840.hxx +++ b/src/emucore/Cart0840.hxx @@ -72,8 +72,10 @@ class Cartridge0840 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -151,13 +153,13 @@ class Cartridge0840 : public Cartridge private: // The 8K ROM image of the cartridge - uInt8 myImage[8192]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; // Previous Device's page access - System::PageAccess myHotSpotPageAccess[8]; + std::array myHotSpotPageAccess; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/Cart2K.cxx b/src/emucore/Cart2K.cxx index 8b1b7b3f4..35555edc6 100644 --- a/src/emucore/Cart2K.cxx +++ b/src/emucore/Cart2K.cxx @@ -24,7 +24,7 @@ Cartridge2K::Cartridge2K(const ByteBuffer& image, uInt32 size, : Cartridge(settings, md5) { // Size can be a maximum of 2K - if(size > 2048) size = 2048; + if(size > 2_KB) size = 2_KB; // Set image size to closest power-of-two for the given size mySize = 1; @@ -36,10 +36,10 @@ Cartridge2K::Cartridge2K(const ByteBuffer& image, uInt32 size, // Initialize ROM with illegal 6502 opcode that causes a real 6502 to jam myImage = make_unique(mySize); - memset(myImage.get(), 0x02, mySize); + std::fill_n(myImage.get(), mySize, 0x02); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), size); + std::copy_n(image.get(), size, myImage.get()); createCodeAccessBase(mySize); // Set mask for accessing the image buffer diff --git a/src/emucore/Cart3E.cxx b/src/emucore/Cart3E.cxx index 57d527e20..a50b9772b 100644 --- a/src/emucore/Cart3E.cxx +++ b/src/emucore/Cart3E.cxx @@ -30,14 +30,14 @@ Cartridge3E::Cartridge3E(const ByteBuffer& image, uInt32 size, myImage = make_unique(mySize); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), mySize); - createCodeAccessBase(mySize + 32768); + std::copy_n(image.get(), mySize, myImage.get()); + createCodeAccessBase(mySize + myRAM.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge3E::reset() { - initializeRAM(myRAM, 32768); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); // We'll map the startup bank into the first segment upon reset @@ -198,9 +198,9 @@ bool Cartridge3E::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge3E::getBank(uInt16 addr) const +uInt16 Cartridge3E::getBank(uInt16 address) const { - if (addr & 0x800) + if (address & 0x800) return 255; // 256 - 1 // 2K slices, fixed bank else return myCurrentBank; @@ -248,7 +248,7 @@ bool Cartridge3E::save(Serializer& out) const try { out.putShort(myCurrentBank); - out.putByteArray(myRAM, 32768); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -265,7 +265,7 @@ bool Cartridge3E::load(Serializer& in) try { myCurrentBank = in.getShort(); - in.getByteArray(myRAM, 32768); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/Cart3E.hxx b/src/emucore/Cart3E.hxx index 935cd8008..04cdace86 100644 --- a/src/emucore/Cart3E.hxx +++ b/src/emucore/Cart3E.hxx @@ -101,8 +101,10 @@ class Cartridge3E : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank(uInt16 addr) const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -183,7 +185,7 @@ class Cartridge3E : public Cartridge ByteBuffer myImage; // RAM contents. For now every ROM gets all 32K of potential RAM - uInt8 myRAM[32 * 1024]; + std::array myRAM; // Size of the ROM image uInt32 mySize; diff --git a/src/emucore/Cart3EPlus.cxx b/src/emucore/Cart3EPlus.cxx index 0c2cc303d..4b607f0d6 100644 --- a/src/emucore/Cart3EPlus.cxx +++ b/src/emucore/Cart3EPlus.cxx @@ -29,14 +29,14 @@ Cartridge3EPlus::Cartridge3EPlus(const ByteBuffer& image, uInt32 size, myImage = make_unique(mySize); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), mySize); - createCodeAccessBase(mySize + RAM_TOTAL_SIZE); + std::copy_n(image.get(), mySize, myImage.get()); + createCodeAccessBase(mySize + myRAM.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge3EPlus::reset() { - initializeRAM(myRAM, RAM_TOTAL_SIZE); + initializeRAM(myRAM.data(), myRAM.size()); // Remember startup bank (0 per spec, rather than last per 3E scheme). // Set this to go to 3rd 1K Bank. @@ -44,8 +44,8 @@ void Cartridge3EPlus::reset() // Initialise bank values for all ROM/RAM access // This is used to reverse-lookup from address to bank location - for(uInt32 b = 0; b < 8; ++b) - bankInUse[b] = BANK_UNDEFINED; // bank is undefined and inaccessible! + for(auto& b: bankInUse) + b = BANK_UNDEFINED; // bank is undefined and inaccessible! initializeBankState(); @@ -67,8 +67,8 @@ void Cartridge3EPlus::install(System& system) // Initialise bank values for all ROM/RAM access // This is used to reverse-lookup from address to bank location - for(uInt32 b = 0; b < 8; ++b) - bankInUse[b] = BANK_UNDEFINED; // bank is undefined and inaccessible! + for(auto& b: bankInUse) + b = BANK_UNDEFINED; // bank is undefined and inaccessible! initializeBankState(); @@ -79,9 +79,9 @@ void Cartridge3EPlus::install(System& system) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge3EPlus::getBank(uInt16 addr) const +uInt16 Cartridge3EPlus::getBank(uInt16 address) const { - return bankInUse[(addr & 0xFFF) >> 10]; // 1K slices + return bankInUse[(address & 0xFFF) >> 10]; // 1K slices } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -90,7 +90,6 @@ uInt16 Cartridge3EPlus::bankCount() const return mySize >> 10; // 1K slices } - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 Cartridge3EPlus::peek(uInt16 address) { @@ -319,8 +318,8 @@ bool Cartridge3EPlus::save(Serializer& out) const { try { - out.putShortArray(bankInUse, 8); - out.putByteArray(myRAM, RAM_TOTAL_SIZE); + out.putShortArray(bankInUse.data(), bankInUse.size()); + out.putByteArray(myRAM.data(), myRAM.size()); } catch (...) { @@ -335,8 +334,8 @@ bool Cartridge3EPlus::load(Serializer& in) { try { - in.getShortArray(bankInUse, 8); - in.getByteArray(myRAM, RAM_TOTAL_SIZE); + in.getShortArray(bankInUse.data(), bankInUse.size()); + in.getByteArray(myRAM.data(), myRAM.size()); } catch (...) { diff --git a/src/emucore/Cart3EPlus.hxx b/src/emucore/Cart3EPlus.hxx index 09cdc57fb..305b3377f 100644 --- a/src/emucore/Cart3EPlus.hxx +++ b/src/emucore/Cart3EPlus.hxx @@ -72,8 +72,10 @@ class Cartridge3EPlus: public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank(uInt16 addr) const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -164,7 +166,7 @@ class Cartridge3EPlus: public Cartridge // are consecutive. This allows us to determine on a read/write exactly where the data is. static constexpr uInt16 BANK_UNDEFINED = 0x8000; // bank is undefined and inaccessible - uInt16 bankInUse[8]; // bank being used for ROM/RAM (eight 512 byte areas) + std::array bankInUse; // bank being used for ROM/RAM (eight 512 byte areas) static constexpr uInt16 BANK_SWITCH_HOTSPOT_RAM = 0x3E; // writes to this address cause bankswitching static constexpr uInt16 BANK_SWITCH_HOTSPOT_ROM = 0x3F; // writes to this address cause bankswitching @@ -188,9 +190,9 @@ class Cartridge3EPlus: public Cartridge static constexpr uInt16 RAM_WRITE_OFFSET = 0x200; - ByteBuffer myImage; // Pointer to a dynamically allocated ROM image of the cartridge - uInt32 mySize; // Size of the ROM image - uInt8 myRAM[RAM_TOTAL_SIZE]; + ByteBuffer myImage; // Pointer to a dynamically allocated ROM image of the cartridge + uInt32 mySize; // Size of the ROM image + std::array myRAM; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/Cart3F.cxx b/src/emucore/Cart3F.cxx index 98666b0ca..f68875e87 100644 --- a/src/emucore/Cart3F.cxx +++ b/src/emucore/Cart3F.cxx @@ -30,7 +30,7 @@ Cartridge3F::Cartridge3F(const ByteBuffer& image, uInt32 size, myImage = make_unique(mySize); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), mySize); + std::copy_n(image.get(), mySize, myImage.get()); createCodeAccessBase(mySize); } @@ -125,9 +125,9 @@ bool Cartridge3F::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge3F::getBank(uInt16 addr) const +uInt16 Cartridge3F::getBank(uInt16 address) const { - if (addr & 0x800) + if (address & 0x800) return (mySize >> 11) - 1; // 2K slices, fixed bank else return myCurrentBank; diff --git a/src/emucore/Cart3F.hxx b/src/emucore/Cart3F.hxx index 29c9d9421..1b2017363 100644 --- a/src/emucore/Cart3F.hxx +++ b/src/emucore/Cart3F.hxx @@ -78,8 +78,10 @@ class Cartridge3F : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank(uInt16 addr) const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. diff --git a/src/emucore/Cart4A50.cxx b/src/emucore/Cart4A50.cxx index 68b109e2d..02de19e30 100644 --- a/src/emucore/Cart4A50.cxx +++ b/src/emucore/Cart4A50.cxx @@ -36,11 +36,11 @@ Cartridge4A50::Cartridge4A50(const ByteBuffer& image, uInt32 size, { // Copy the ROM image into my buffer // Supported file sizes are 32/64/128K, which are duplicated if necessary - if(size < 65536) size = 32768; - else if(size < 131072) size = 65536; - else size = 131072; - for(uInt32 slice = 0; slice < 131072 / size; ++slice) - memcpy(myImage + (slice*size), image.get(), size); + if(size < 64_KB) size = 32_KB; + else if(size < 128_KB) size = 64_KB; + else size = 128_KB; + for(uInt32 slice = 0; slice < 128_KB / size; ++slice) + std::copy_n(image.get(), size, myImage.begin() + (slice*size)); // We use System::PageAccess.codeAccessBase, but don't allow its use // through a pointer, since the address space of 4A50 carts can change @@ -49,13 +49,13 @@ Cartridge4A50::Cartridge4A50(const ByteBuffer& image, uInt32 size, // // Instead, access will be through the getAccessFlags and setAccessFlags // methods below - createCodeAccessBase(131072 + 32768); + createCodeAccessBase(myImage.size() + myRAM.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge4A50::reset() { - initializeRAM(myRAM, 32768); + initializeRAM(myRAM.data(), myRAM.size()); mySliceLow = mySliceMiddle = mySliceHigh = 0; myIsRomLow = myIsRomMiddle = myIsRomHigh = true; @@ -359,7 +359,7 @@ bool Cartridge4A50::patch(uInt16 address, uInt8 value) const uInt8* Cartridge4A50::getImage(uInt32& size) const { size = mySize; - return myImage; + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -368,7 +368,7 @@ bool Cartridge4A50::save(Serializer& out) const try { // The 32K bytes of RAM - out.putByteArray(myRAM, 32768); + out.putByteArray(myRAM.data(), myRAM.size()); // Index pointers out.putShort(mySliceLow); @@ -398,7 +398,7 @@ bool Cartridge4A50::load(Serializer& in) { try { - in.getByteArray(myRAM, 32768); + in.getByteArray(myRAM.data(), myRAM.size()); // Index pointers mySliceLow = in.getShort(); diff --git a/src/emucore/Cart4A50.hxx b/src/emucore/Cart4A50.hxx index 2bf24823b..d36f50603 100644 --- a/src/emucore/Cart4A50.hxx +++ b/src/emucore/Cart4A50.hxx @@ -219,10 +219,10 @@ class Cartridge4A50 : public Cartridge private: // The 128K ROM image of the cartridge - uInt8 myImage[131072]; + std::array myImage; // The 32K of RAM on the cartridge - uInt8 myRAM[32768]; + std::array myRAM; // (Actual) Size of the ROM image uInt32 mySize; diff --git a/src/emucore/Cart4K.cxx b/src/emucore/Cart4K.cxx index 1940214a0..55440af1a 100644 --- a/src/emucore/Cart4K.cxx +++ b/src/emucore/Cart4K.cxx @@ -24,8 +24,8 @@ Cartridge4K::Cartridge4K(const ByteBuffer& image, uInt32 size, : Cartridge(settings, md5) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(4096u, size)); - createCodeAccessBase(4096); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -61,8 +61,8 @@ bool Cartridge4K::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* Cartridge4K::getImage(uInt32& size) const { - size = 4096; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart4K.hxx b/src/emucore/Cart4K.hxx index f876b650f..fb16ce2fa 100644 --- a/src/emucore/Cart4K.hxx +++ b/src/emucore/Cart4K.hxx @@ -124,7 +124,7 @@ class Cartridge4K : public Cartridge private: // The 4K ROM image for the cartridge - uInt8 myImage[4096]; + std::array myImage; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/Cart4KSC.cxx b/src/emucore/Cart4KSC.cxx index 3e744b26c..cc5389748 100644 --- a/src/emucore/Cart4KSC.cxx +++ b/src/emucore/Cart4KSC.cxx @@ -24,14 +24,14 @@ Cartridge4KSC::Cartridge4KSC(const ByteBuffer& image, uInt32 size, : Cartridge(settings, md5) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(4096u, size)); - createCodeAccessBase(4096); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge4KSC::reset() { - initializeRAM(myRAM, 128); + initializeRAM(myRAM.data(), myRAM.size()); myBankChanged = true; } @@ -120,8 +120,8 @@ bool Cartridge4KSC::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* Cartridge4KSC::getImage(uInt32& size) const { - size = 4096; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -129,7 +129,7 @@ bool Cartridge4KSC::save(Serializer& out) const { try { - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -145,7 +145,7 @@ bool Cartridge4KSC::load(Serializer& in) { try { - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/Cart4KSC.hxx b/src/emucore/Cart4KSC.hxx index f2823cdc9..3b005c743 100644 --- a/src/emucore/Cart4KSC.hxx +++ b/src/emucore/Cart4KSC.hxx @@ -133,10 +133,10 @@ class Cartridge4KSC : public Cartridge private: // The 4K ROM image of the cartridge - uInt8 myImage[4096]; + std::array myImage; // The 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartAR.cxx b/src/emucore/CartAR.cxx index 548bc7f85..75a667d0e 100644 --- a/src/emucore/CartAR.cxx +++ b/src/emucore/CartAR.cxx @@ -34,11 +34,11 @@ CartridgeAR::CartridgeAR(const ByteBuffer& image, uInt32 size, // Create a load image buffer and copy the given image myLoadImages = make_unique(mySize); myNumberOfLoadImages = mySize / 8448; - memcpy(myLoadImages.get(), image.get(), size); + std::copy_n(image.get(), size, myLoadImages.get()); // Add header if image doesn't include it if(size < 8448) - memcpy(myLoadImages.get()+8192, ourDefaultHeader, 256); + std::copy_n(ourDefaultHeader.data(), ourDefaultHeader.size(), myLoadImages.get()+myImage.size()); // We use System::PageAccess.codeAccessBase, but don't allow its use // through a pointer, since the AR scheme doesn't support bankswitching @@ -54,9 +54,9 @@ void CartridgeAR::reset() { // Initialize RAM #if 0 // TODO - figure out actual behaviour of the real cart - initializeRAM(myImage, 6*1024); + initializeRAM(myImage.data(), myImage.size()); #else - memset(myImage, 0, 6 * 1024); + myImage.fill(0); #endif // Initialize SC BIOS ROM @@ -316,10 +316,10 @@ void CartridgeAR::initializeROM() ourDummyROMCode[281] = mySystem->randGenerator().next(); // Initialize ROM with illegal 6502 opcode that causes a real 6502 to jam - memset(myImage + (3<<11), 0x02, 2048); + std::fill_n(myImage.begin() + (3<<11), 2048, 0x02); // Copy the "dummy" Supercharger BIOS code into the ROM area - memcpy(myImage + (3<<11), ourDummyROMCode, sizeof(ourDummyROMCode)); + std::copy_n(ourDummyROMCode.data(), ourDummyROMCode.size(), myImage.data() + (3<<11)); // Finally set 6502 vectors to point to initial load code at 0xF80A of BIOS myImage[(3<<11) + 2044] = 0x0A; @@ -348,16 +348,14 @@ void CartridgeAR::loadIntoRAM(uInt8 load) for(image = 0; image < myNumberOfLoadImages; ++image) { // Is this the correct load? - if(myLoadImages[(image * 8448) + 8192 + 5] == load) + if(myLoadImages[(image * 8448) + myImage.size() + 5] == load) { // Copy the load's header - memcpy(myHeader, myLoadImages.get() + (image * 8448) + 8192, 256); + std::copy_n(myLoadImages.get() + (image * 8448) + myImage.size(), myHeader.size(), myHeader.data()); // Verify the load's header - if(checksum(myHeader, 8) != 0x55) - { + if(checksum(myHeader.data(), 8) != 0x55) cerr << "WARNING: The Supercharger header checksum is invalid...\n"; - } // Load all of the pages from the load bool invalidPageChecksumSeen = false; @@ -376,9 +374,7 @@ void CartridgeAR::loadIntoRAM(uInt8 load) // Copy page to Supercharger RAM (don't allow a copy into ROM area) if(bank < 3) - { - memcpy(myImage + (bank * 2048) + (page * 256), src, 256); - } + std::copy_n(src, 256, myImage.data() + (bank * 2048) + (page * 256)); } // Copy the bank switching byte and starting address into the 2600's @@ -407,7 +403,7 @@ bool CartridgeAR::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeAR::getBank() const +uInt16 CartridgeAR::getBank(uInt16) const { return myCurrentBank; } @@ -438,13 +434,13 @@ bool CartridgeAR::save(Serializer& out) const try { // Indicates the offest within the image for the corresponding bank - out.putIntArray(myImageOffset, 2); + out.putIntArray(myImageOffset.data(), myImageOffset.size()); // The 6K of RAM and 2K of ROM contained in the Supercharger - out.putByteArray(myImage, 8192); + out.putByteArray(myImage.data(), myImage.size()); // The 256 byte header for the current 8448 byte load - out.putByteArray(myHeader, 256); + out.putByteArray(myHeader.data(), myHeader.size()); // All of the 8448 byte loads associated with the game // Note that the size of this array is myNumberOfLoadImages * 8448 @@ -483,13 +479,13 @@ bool CartridgeAR::load(Serializer& in) try { // Indicates the offest within the image for the corresponding bank - in.getIntArray(myImageOffset, 2); + in.getIntArray(myImageOffset.data(), myImageOffset.size()); // The 6K of RAM and 2K of ROM contained in the Supercharger - in.getByteArray(myImage, 8192); + in.getByteArray(myImage.data(), myImage.size()); // The 256 byte header for the current 8448 byte load - in.getByteArray(myHeader, 256); + in.getByteArray(myHeader.data(), myHeader.size()); // All of the 8448 byte loads associated with the game // Note that the size of this array is myNumberOfLoadImages * 8448 @@ -523,7 +519,7 @@ bool CartridgeAR::load(Serializer& in) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 CartridgeAR::ourDummyROMCode[] = { +std::array CartridgeAR::ourDummyROMCode = { 0xa5, 0xfa, 0x85, 0x80, 0x4c, 0x18, 0xf8, 0xff, 0xff, 0xff, 0x78, 0xd8, 0xa0, 0x00, 0xa2, 0x00, 0x94, 0x00, 0xe8, 0xd0, 0xfb, 0x4c, 0x50, 0xf8, @@ -564,7 +560,7 @@ uInt8 CartridgeAR::ourDummyROMCode[] = { }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const uInt8 CartridgeAR::ourDefaultHeader[256] = { +const std::array CartridgeAR::ourDefaultHeader = { 0xac, 0xfa, 0x0f, 0x18, 0x62, 0x00, 0x24, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c, diff --git a/src/emucore/CartAR.hxx b/src/emucore/CartAR.hxx index f78536a22..cb0debd89 100644 --- a/src/emucore/CartAR.hxx +++ b/src/emucore/CartAR.hxx @@ -79,8 +79,10 @@ class CartridgeAR : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -185,13 +187,13 @@ class CartridgeAR : public Cartridge private: // Indicates the offset within the image for the corresponding bank - uInt32 myImageOffset[2]; + std::array myImageOffset; // The 6K of RAM and 2K of ROM contained in the Supercharger - uInt8 myImage[8192]; + std::array myImage; // The 256 byte header for the current 8448 byte load - uInt8 myHeader[256]; + std::array myHeader; // Size of the ROM image uInt32 mySize; @@ -221,11 +223,11 @@ class CartridgeAR : public Cartridge uInt16 myCurrentBank; // Fake SC-BIOS code to simulate the Supercharger load bars - static uInt8 ourDummyROMCode[294]; + static std::array ourDummyROMCode; // Default 256-byte header to use if one isn't included in the ROM // This data comes from z26 - static const uInt8 ourDefaultHeader[256]; + static const std::array ourDefaultHeader; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartBF.cxx b/src/emucore/CartBF.cxx index 85974c3f9..d937a9184 100644 --- a/src/emucore/CartBF.cxx +++ b/src/emucore/CartBF.cxx @@ -25,8 +25,8 @@ CartridgeBF::CartridgeBF(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(262144u, size)); - createCodeAccessBase(262144); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -105,7 +105,7 @@ bool CartridgeBF::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeBF::getBank() const +uInt16 CartridgeBF::getBank(uInt16) const { return myBankOffset >> 12; } @@ -126,8 +126,8 @@ bool CartridgeBF::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeBF::getImage(uInt32& size) const { - size = 64 * 4096; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartBF.hxx b/src/emucore/CartBF.hxx index 59853b68a..1c4c8c91b 100644 --- a/src/emucore/CartBF.hxx +++ b/src/emucore/CartBF.hxx @@ -73,8 +73,10 @@ class CartridgeBF : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,7 +154,7 @@ class CartridgeBF : public Cartridge private: // The 256K ROM image of the cartridge - uInt8 myImage[64 * 4096]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt32 myBankOffset; diff --git a/src/emucore/CartBFSC.cxx b/src/emucore/CartBFSC.cxx index d51b3f22f..509293b25 100644 --- a/src/emucore/CartBFSC.cxx +++ b/src/emucore/CartBFSC.cxx @@ -25,14 +25,14 @@ CartridgeBFSC::CartridgeBFSC(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(262144u, size)); - createCodeAccessBase(262144); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeBFSC::reset() { - initializeRAM(myRAM, 128); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(15); // Upon reset we switch to the startup bank @@ -144,7 +144,7 @@ bool CartridgeBFSC::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeBFSC::getBank() const +uInt16 CartridgeBFSC::getBank(uInt16) const { return myBankOffset >> 12; } @@ -176,8 +176,8 @@ bool CartridgeBFSC::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeBFSC::getImage(uInt32& size) const { - size = 64 * 4096; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -186,7 +186,7 @@ bool CartridgeBFSC::save(Serializer& out) const try { out.putInt(myBankOffset); - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -203,7 +203,7 @@ bool CartridgeBFSC::load(Serializer& in) try { myBankOffset = in.getInt(); - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartBFSC.hxx b/src/emucore/CartBFSC.hxx index 34d701d82..69dea9880 100644 --- a/src/emucore/CartBFSC.hxx +++ b/src/emucore/CartBFSC.hxx @@ -73,8 +73,10 @@ class CartridgeBFSC : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,10 +154,10 @@ class CartridgeBFSC : public Cartridge private: // The 256K ROM image of the cartridge - uInt8 myImage[64 * 4096]; + std::array myImage; // The 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; // Indicates the offset into the ROM image (aligns to current bank) uInt32 myBankOffset; diff --git a/src/emucore/CartBUS.cxx b/src/emucore/CartBUS.cxx index 84057ddd7..1df765931 100644 --- a/src/emucore/CartBUS.cxx +++ b/src/emucore/CartBUS.cxx @@ -49,25 +49,27 @@ CartridgeBUS::CartridgeBUS(const ByteBuffer& image, uInt32 size, myFractionalClocks(0.0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(32768u, size)); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); - // even though the ROM is 32K, only 28K is accessible to the 6507 - createCodeAccessBase(4096 * 7); + // Even though the ROM is 32K, only 28K is accessible to the 6507 + createCodeAccessBase(28_KB); // Pointer to the program ROM (28K @ 0 byte offset) // which starts after the 2K BUS Driver and 2K C Code - myProgramImage = myImage + 4096; + myProgramImage = myImage.data() + 4_KB; // Pointer to BUS driver in RAM - myBusDriverImage = myBUSRAM; + myBusDriverImage = myBUSRAM.data(); // Pointer to the display RAM - myDisplayImage = myBUSRAM + DSRAM; + myDisplayImage = myBUSRAM.data() + DSRAM; // Create Thumbulator ARM emulator bool devSettings = settings.getBool("dev.settings"); myThumbEmulator = make_unique( - reinterpret_cast(myImage), reinterpret_cast(myBUSRAM), 32768, + reinterpret_cast(myImage.data()), + reinterpret_cast(myBUSRAM.data()), + myImage.size(), devSettings ? settings.getBool("dev.thumb.trapfatal") : false, Thumbulator::ConfigureFor::BUS, this ); @@ -77,7 +79,7 @@ CartridgeBUS::CartridgeBUS(const ByteBuffer& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeBUS::reset() { - initializeRAM(myBUSRAM+2048, 8192-2048); + initializeRAM(myBUSRAM.data() + 2_KB, 6_KB); // BUS always starts in bank 6 initializeStartBank(6); @@ -96,10 +98,9 @@ void CartridgeBUS::reset() void CartridgeBUS::setInitialState() { // Copy initial BUS driver to Harmony RAM - memcpy(myBusDriverImage, myImage, 0x0800); + std::copy_n(myImage.begin(), 0x0800, myBusDriverImage); - for (int i=0; i < 3; ++i) - myMusicWaveformSize[i] = 27; + myMusicWaveformSize.fill(27); // Assuming mode starts out with Fast Fetch off and 3-Voice music, // need to confirm with Chris @@ -449,7 +450,7 @@ bool CartridgeBUS::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeBUS::getBank() const +uInt16 CartridgeBUS::getBank(uInt16) const { return myBankOffset >> 12; } @@ -478,8 +479,8 @@ bool CartridgeBUS::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeBUS::getImage(uInt32& size) const { - size = 32768; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -547,7 +548,7 @@ bool CartridgeBUS::save(Serializer& out) const out.putShort(myBankOffset); // Harmony RAM - out.putByteArray(myBUSRAM, 8192); + out.putByteArray(myBUSRAM.data(), myBUSRAM.size()); // Addresses for bus override logic out.putShort(myBusOverdriveAddress); @@ -560,9 +561,9 @@ bool CartridgeBUS::save(Serializer& out) const out.putLong(myARMCycles); // Audio info - out.putIntArray(myMusicCounters, 3); - out.putIntArray(myMusicFrequencies, 3); - out.putByteArray(myMusicWaveformSize, 3); + out.putIntArray(myMusicCounters.data(), myMusicCounters.size()); + out.putIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); + out.putByteArray(myMusicWaveformSize.data(), myMusicWaveformSize.size()); // Indicates current mode out.putByte(myMode); @@ -588,7 +589,7 @@ bool CartridgeBUS::load(Serializer& in) myBankOffset = in.getShort(); // Harmony RAM - in.getByteArray(myBUSRAM, 8192); + in.getByteArray(myBUSRAM.data(), myBUSRAM.size()); // Addresses for bus override logic myBusOverdriveAddress = in.getShort(); @@ -601,9 +602,9 @@ bool CartridgeBUS::load(Serializer& in) myARMCycles = in.getLong(); // Audio info - in.getIntArray(myMusicCounters, 3); - in.getIntArray(myMusicFrequencies, 3); - in.getByteArray(myMusicWaveformSize, 3); + in.getIntArray(myMusicCounters.data(), myMusicCounters.size()); + in.getIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); + in.getByteArray(myMusicWaveformSize.data(), myMusicWaveformSize.size()); // Indicates current mode myMode = in.getByte(); diff --git a/src/emucore/CartBUS.hxx b/src/emucore/CartBUS.hxx index e4cc7b634..760e8f1f7 100644 --- a/src/emucore/CartBUS.hxx +++ b/src/emucore/CartBUS.hxx @@ -90,8 +90,10 @@ class CartridgeBUS : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -209,7 +211,7 @@ class CartridgeBUS : public Cartridge private: // The 32K ROM image of the cartridge - uInt8 myImage[32768]; + std::array myImage; // Pointer to the 28K program ROM image of the cartridge uInt8* myProgramImage; @@ -224,7 +226,7 @@ class CartridgeBUS : public Cartridge // $0000 - 2K BUS driver // $0800 - 4K Display Data // $1800 - 2K C Variable & Stack - uInt8 myBUSRAM[8192]; + std::array myBUSRAM; // Pointer to the Thumb ARM emulator object unique_ptr myThumbEmulator; @@ -249,13 +251,13 @@ class CartridgeBUS : public Cartridge uInt64 myARMCycles; // The music mode counters - uInt32 myMusicCounters[3]; + std::array myMusicCounters; // The music frequency - uInt32 myMusicFrequencies[3]; + std::array myMusicFrequencies; // The music waveform sizes - uInt8 myMusicWaveformSize[3]; + std::array myMusicWaveformSize; // Fractional DPC music OSC clocks unused during the last update double myFractionalClocks; diff --git a/src/emucore/CartCDF.cxx b/src/emucore/CartCDF.cxx index 756d4ddd1..977ea8fce 100644 --- a/src/emucore/CartCDF.cxx +++ b/src/emucore/CartCDF.cxx @@ -65,27 +65,29 @@ CartridgeCDF::CartridgeCDF(const ByteBuffer& image, uInt32 size, myFractionalClocks(0.0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(32768u, size)); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); // even though the ROM is 32K, only 28K is accessible to the 6507 createCodeAccessBase(4096 * 7); // Pointer to the program ROM (28K @ 0 byte offset) // which starts after the 2K CDF Driver and 2K C Code - myProgramImage = myImage + 4096; + myProgramImage = myImage.data() + 4096; // Pointer to CDF driver in RAM - myBusDriverImage = myCDFRAM; + myBusDriverImage = myCDFRAM.data(); // Pointer to the display RAM - myDisplayImage = myCDFRAM + DSRAM; + myDisplayImage = myCDFRAM.data() + DSRAM; setupVersion(); // Create Thumbulator ARM emulator bool devSettings = settings.getBool("dev.settings"); myThumbEmulator = make_unique( - reinterpret_cast(myImage), reinterpret_cast(myCDFRAM), 32768, + reinterpret_cast(myImage.data()), + reinterpret_cast(myCDFRAM.data()), + myImage.size(), devSettings ? settings.getBool("dev.thumb.trapfatal") : false, thumulatorConfiguration(myCDFSubtype), this); setInitialState(); @@ -94,7 +96,7 @@ CartridgeCDF::CartridgeCDF(const ByteBuffer& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCDF::reset() { - initializeRAM(myCDFRAM+2048, 8192-2048); + initializeRAM(myCDFRAM.data()+2048, myCDFRAM.size()-2048); // CDF always starts in bank 6 initializeStartBank(6); @@ -112,10 +114,9 @@ void CartridgeCDF::reset() void CartridgeCDF::setInitialState() { // Copy initial CDF driver to Harmony RAM - memcpy(myBusDriverImage, myImage, 0x0800); + std::copy_n(myImage.begin(), 0x0800, myBusDriverImage); - for (int i=0; i < 3; ++i) - myMusicWaveformSize[i] = 27; + myMusicWaveformSize.fill(27); // Assuming mode starts out with Fast Fetch off and 3-Voice music, // need to confirm with Chris @@ -421,7 +422,7 @@ bool CartridgeCDF::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeCDF::getBank() const +uInt16 CartridgeCDF::getBank(uInt16) const { return myBankOffset >> 12; } @@ -450,12 +451,11 @@ bool CartridgeCDF::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeCDF::getImage(uInt32& size) const { - size = 32768; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::thumbCallback(uInt8 function, uInt32 value1, uInt32 value2) { switch (function) @@ -484,7 +484,6 @@ uInt32 CartridgeCDF::thumbCallback(uInt8 function, uInt32 value1, uInt32 value2) return 0; } - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeCDF::save(Serializer& out) const { @@ -504,12 +503,12 @@ bool CartridgeCDF::save(Serializer& out) const out.putShort(myJMPoperandAddress); // Harmony RAM - out.putByteArray(myCDFRAM, 8192); + out.putByteArray(myCDFRAM.data(), myCDFRAM.size()); // Audio info - out.putIntArray(myMusicCounters, 3); - out.putIntArray(myMusicFrequencies, 3); - out.putByteArray(myMusicWaveformSize, 3); + out.putIntArray(myMusicCounters.data(), myMusicCounters.size()); + out.putIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); + out.putByteArray(myMusicWaveformSize.data(), myMusicWaveformSize.size()); // Save cycles and clocks out.putLong(myAudioCycles); @@ -544,12 +543,12 @@ bool CartridgeCDF::load(Serializer& in) myJMPoperandAddress = in.getShort(); // Harmony RAM - in.getByteArray(myCDFRAM, 8192); + in.getByteArray(myCDFRAM.data(), myCDFRAM.size()); // Audio info - in.getIntArray(myMusicCounters, 3); - in.getIntArray(myMusicFrequencies, 3); - in.getByteArray(myMusicWaveformSize, 3); + in.getIntArray(myMusicCounters.data(), myMusicCounters.size()); + in.getIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); + in.getByteArray(myMusicWaveformSize.data(), myMusicWaveformSize.size()); // Get cycles and clocks myAudioCycles = in.getLong(); @@ -604,13 +603,12 @@ uInt32 CartridgeCDF::getDatastreamIncrement(uInt8 index) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::getWaveform(uInt8 index) const { - uInt32 result; uInt16 address = myWaveformBase + index * 4; - result = myCDFRAM[address + 0] + // low byte - (myCDFRAM[address + 1] << 8) + - (myCDFRAM[address + 2] << 16) + - (myCDFRAM[address + 3] << 24); // high byte + uInt32 result = myCDFRAM[address + 0] + // low byte + (myCDFRAM[address + 1] << 8) + + (myCDFRAM[address + 2] << 16) + + (myCDFRAM[address + 3] << 24); // high byte result -= (0x40000000 + DSRAM); @@ -623,13 +621,12 @@ uInt32 CartridgeCDF::getWaveform(uInt8 index) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::getSample() { - uInt32 result; uInt16 address = myWaveformBase; - result = myCDFRAM[address + 0] + // low byte - (myCDFRAM[address + 1] << 8) + - (myCDFRAM[address + 2] << 16) + - (myCDFRAM[address + 3] << 24); // high byte + uInt32 result = myCDFRAM[address + 0] + // low byte + (myCDFRAM[address + 1] << 8) + + (myCDFRAM[address + 2] << 16) + + (myCDFRAM[address + 3] << 24); // high byte return result; } diff --git a/src/emucore/CartCDF.hxx b/src/emucore/CartCDF.hxx index 340097b83..8ef3b88ab 100644 --- a/src/emucore/CartCDF.hxx +++ b/src/emucore/CartCDF.hxx @@ -98,8 +98,10 @@ class CartridgeCDF : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -211,7 +213,7 @@ class CartridgeCDF : public Cartridge private: // The 32K ROM image of the cartridge - uInt8 myImage[32768]; + std::array myImage; // Pointer to the 28K program ROM image of the cartridge uInt8* myProgramImage; @@ -226,7 +228,7 @@ class CartridgeCDF : public Cartridge // $0000 - 2K CDF driver // $0800 - 4K Display Data // $1800 - 2K C Variable & Stack - uInt8 myCDFRAM[8192]; + std::array myCDFRAM; // Pointer to the Thumb ARM emulator object unique_ptr myThumbEmulator; @@ -257,13 +259,13 @@ class CartridgeCDF : public Cartridge r14 = timer base */ // The music counters, ARM FIQ shadow registers r8, r9, r10 - uInt32 myMusicCounters[3]; + std::array myMusicCounters; // The music frequency, ARM FIQ shadow registers r11, r12, r13 - uInt32 myMusicFrequencies[3]; + std::array myMusicFrequencies; // The music waveform sizes - uInt8 myMusicWaveformSize[3]; + std::array myMusicWaveformSize; // Fractional CDF music, OSC clocks unused during the last update double myFractionalClocks; diff --git a/src/emucore/CartCM.cxx b/src/emucore/CartCM.cxx index b0c93623d..4690b4541 100644 --- a/src/emucore/CartCM.cxx +++ b/src/emucore/CartCM.cxx @@ -28,14 +28,14 @@ CartridgeCM::CartridgeCM(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(16384u, size)); - createCodeAccessBase(16384); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCM::reset() { - initializeRAM(myRAM, 2048); + initializeRAM(myRAM.data(), myRAM.size()); // On powerup, the last bank of ROM is enabled and RAM is disabled mySWCHA = 0xFF; @@ -153,7 +153,7 @@ bool CartridgeCM::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeCM::getBank() const +uInt16 CartridgeCM::getBank(uInt16) const { return myBankOffset >> 12; } @@ -182,8 +182,8 @@ bool CartridgeCM::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeCM::getImage(uInt32& size) const { - size = 16384; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -194,7 +194,7 @@ bool CartridgeCM::save(Serializer& out) const out.putShort(myBankOffset); out.putByte(mySWCHA); out.putByte(myCompuMate->column()); - out.putByteArray(myRAM, 2048); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -213,7 +213,7 @@ bool CartridgeCM::load(Serializer& in) myBankOffset = in.getShort(); mySWCHA = in.getByte(); myCompuMate->column() = in.getByte(); - in.getByteArray(myRAM, 2048); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartCM.hxx b/src/emucore/CartCM.hxx index de57c2e40..f1225d410 100644 --- a/src/emucore/CartCM.hxx +++ b/src/emucore/CartCM.hxx @@ -147,8 +147,10 @@ class CartridgeCM : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -241,10 +243,10 @@ class CartridgeCM : public Cartridge shared_ptr myCompuMate; // The 16K ROM image of the cartridge - uInt8 myImage[16384]; + std::array myImage; // The 2K of RAM - uInt8 myRAM[2048]; + std::array myRAM; // Current copy of SWCHA (controls ROM/RAM accesses) uInt8 mySWCHA; diff --git a/src/emucore/CartCTY.cxx b/src/emucore/CartCTY.cxx index f320e787b..48484dc82 100644 --- a/src/emucore/CartCTY.cxx +++ b/src/emucore/CartCTY.cxx @@ -35,27 +35,27 @@ CartridgeCTY::CartridgeCTY(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(32768u, size)); - createCodeAccessBase(32768); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); // Default to no tune data in case user is utilizing an old ROM - memset(myTuneData, 0, 28*1024); + myTuneData.fill(0); // Extract tune data if it exists - if(size > 32768u) - memcpy(myTuneData, image.get() + 32768u, size - 32768u); + if(size > myImage.size()) + std::copy_n(image.get() + myImage.size(), size - myImage.size(), myTuneData.begin()); // Point to the first tune - myFrequencyImage = myTuneData; + myFrequencyImage = myTuneData.data(); - for(uInt8 i = 0; i < 3; ++i) - myMusicCounters[i] = myMusicFrequencies[i] = 0; + myMusicCounters.fill(0); + myMusicFrequencies.fill(0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCTY::reset() { - initializeRAM(myRAM, 64); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(1); myRAM[0] = myRAM[1] = myRAM[2] = myRAM[3] = 0xFF; @@ -255,7 +255,7 @@ bool CartridgeCTY::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeCTY::getBank() const +uInt16 CartridgeCTY::getBank(uInt16) const { return myBankOffset >> 12; } @@ -287,8 +287,8 @@ bool CartridgeCTY::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeCTY::getImage(uInt32& size) const { - size = 32768; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -297,7 +297,7 @@ bool CartridgeCTY::save(Serializer& out) const try { out.putShort(getBank()); - out.putByteArray(myRAM, 64); + out.putByteArray(myRAM.data(), myRAM.size()); out.putByte(myOperationType); out.putShort(myTunePosition); @@ -305,9 +305,9 @@ bool CartridgeCTY::save(Serializer& out) const out.putInt(myRandomNumber); out.putLong(myAudioCycles); out.putDouble(myFractionalClocks); - out.putIntArray(myMusicCounters, 3); - out.putIntArray(myMusicFrequencies, 3); - out.putLong(myFrequencyImage - myTuneData); + out.putIntArray(myMusicCounters.data(), myMusicCounters.size()); + out.putIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); + out.putLong(myFrequencyImage - myTuneData.data()); // FIXME - storing pointer diff! } catch(...) { @@ -325,7 +325,7 @@ bool CartridgeCTY::load(Serializer& in) { // Remember what bank we were in bank(in.getShort()); - in.getByteArray(myRAM, 64); + in.getByteArray(myRAM.data(), myRAM.size()); myOperationType = in.getByte(); myTunePosition = in.getShort(); @@ -333,9 +333,9 @@ bool CartridgeCTY::load(Serializer& in) myRandomNumber = in.getInt(); myAudioCycles = in.getLong(); myFractionalClocks = in.getDouble(); - in.getIntArray(myMusicCounters, 3); - in.getIntArray(myMusicFrequencies, 3); - myFrequencyImage = myTuneData + in.getLong(); + in.getIntArray(myMusicCounters.data(), myMusicCounters.size()); + in.getIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); + myFrequencyImage = myTuneData.data() + in.getLong(); } catch(...) { @@ -437,7 +437,7 @@ void CartridgeCTY::loadTune(uInt8 index) // Each tune is offset by 4096 bytes // Instead of copying non-modifiable data around (as would happen on the // Harmony), we simply point to the appropriate tune - myFrequencyImage = myTuneData + (index << 12); + myFrequencyImage = myTuneData.data() + (index << 12); // Reset to beginning of tune myTunePosition = 0; @@ -501,17 +501,18 @@ void CartridgeCTY::loadScore(uInt8 index) Serializer serializer(myEEPROMFile, Serializer::Mode::ReadOnly); if(serializer) { - uInt8 scoreRAM[256]; + std::array scoreRAM; try { - serializer.getByteArray(scoreRAM, 256); + serializer.getByteArray(scoreRAM.data(), scoreRAM.size()); } catch(...) { - memset(scoreRAM, 0, 256); + scoreRAM.fill(0); } + // Grab 60B slice @ given index (first 4 bytes are ignored) - memcpy(myRAM+4, scoreRAM + (index << 6) + 4, 60); + std::copy_n(scoreRAM.begin() + (index << 6) + 4, 60, myRAM.begin() + 4); } } @@ -522,24 +523,24 @@ void CartridgeCTY::saveScore(uInt8 index) if(serializer) { // Load score RAM - uInt8 scoreRAM[256]; + std::array scoreRAM; try { - serializer.getByteArray(scoreRAM, 256); + serializer.getByteArray(scoreRAM.data(), scoreRAM.size()); } catch(...) { - memset(scoreRAM, 0, 256); + scoreRAM.fill(0); } // Add 60B RAM to score table @ given index (first 4 bytes are ignored) - memcpy(scoreRAM + (index << 6) + 4, myRAM+4, 60); + std::copy_n(myRAM.begin() + 4, 60, scoreRAM.begin() + (index << 6) + 4); // Save score RAM serializer.rewind(); try { - serializer.putByteArray(scoreRAM, 256); + serializer.putByteArray(scoreRAM.data(), scoreRAM.size()); } catch(...) { @@ -556,11 +557,10 @@ void CartridgeCTY::wipeAllScores() if(serializer) { // Erase score RAM - uInt8 scoreRAM[256]; - memset(scoreRAM, 0, 256); + std::array scoreRAM = {}; try { - serializer.putByteArray(scoreRAM, 256); + serializer.putByteArray(scoreRAM.data(), scoreRAM.size()); } catch(...) { diff --git a/src/emucore/CartCTY.hxx b/src/emucore/CartCTY.hxx index 32f229f14..512787e09 100644 --- a/src/emucore/CartCTY.hxx +++ b/src/emucore/CartCTY.hxx @@ -145,8 +145,10 @@ class CartridgeCTY : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -258,13 +260,13 @@ class CartridgeCTY : public Cartridge private: // The 32K ROM image of the cartridge - uInt8 myImage[32768]; + std::array myImage; // The 28K ROM image of the music - uInt8 myTuneData[28*1024]; + std::array myTuneData; // The 64 bytes of RAM accessible at $1000 - $1080 - uInt8 myRAM[64]; + std::array myRAM; // Operation type (written to $1000, used by hotspot $1FF4) uInt8 myOperationType; @@ -277,10 +279,10 @@ class CartridgeCTY : public Cartridge uInt16 myTunePosition; // The music mode counters - uInt32 myMusicCounters[3]; + std::array myMusicCounters; // The music frequency - uInt32 myMusicFrequencies[3]; + std::array myMusicFrequencies; // Flags that last byte peeked was A9 (LDA #) bool myLDAimmediate; diff --git a/src/emucore/CartCV.cxx b/src/emucore/CartCV.cxx index 0153b1aaf..6f8821616 100644 --- a/src/emucore/CartCV.cxx +++ b/src/emucore/CartCV.cxx @@ -24,36 +24,35 @@ CartridgeCV::CartridgeCV(const ByteBuffer& image, uInt32 size, : Cartridge(settings, md5), mySize(size) { - if(mySize == 2048) + if(mySize == myImage.size()) { // Copy the ROM data into my buffer - memcpy(myImage, image.get(), 2048); + std::copy_n(image.get(), myImage.size(), myImage.begin()); } - else if(mySize == 4096) + else if(mySize == 4_KB) { // The game has something saved in the RAM // Useful for MagiCard program listings // Copy the ROM data into my buffer - memcpy(myImage, image.get() + 2048, 2048); + std::copy_n(image.get() + myImage.size(), myImage.size(), myImage.begin()); // Copy the RAM image into a buffer for use in reset() - myInitialRAM = make_unique(1024); - memcpy(myInitialRAM.get(), image.get(), 1024); + std::copy_n(image.get(), myInitialRAM.size(), myInitialRAM.begin()); } - createCodeAccessBase(2048+1024); + createCodeAccessBase(myImage.size() + myRAM.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCV::reset() { - if(myInitialRAM) + if(mySize == 4_KB) { // Copy the RAM image into my buffer - memcpy(myRAM, myInitialRAM.get(), 1024); + myRAM = myInitialRAM; } else - initializeRAM(myRAM, 1024); + initializeRAM(myRAM.data(), myRAM.size()); myBankChanged = true; } @@ -131,8 +130,8 @@ bool CartridgeCV::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeCV::getImage(uInt32& size) const { - size = 2048; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -140,7 +139,7 @@ bool CartridgeCV::save(Serializer& out) const { try { - out.putByteArray(myRAM, 1024); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -156,7 +155,7 @@ bool CartridgeCV::load(Serializer& in) { try { - in.getByteArray(myRAM, 1024); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartCV.hxx b/src/emucore/CartCV.hxx index c22c8f4fa..7bca6e900 100644 --- a/src/emucore/CartCV.hxx +++ b/src/emucore/CartCV.hxx @@ -136,18 +136,17 @@ class CartridgeCV : public Cartridge bool poke(uInt16 address, uInt8 value) override; private: - // Pointer to the initial RAM data from the cart - // This doesn't always exist, so we don't pre-allocate it - ByteBuffer myInitialRAM; + // The 2k ROM image for the cartridge + std::array myImage; // Initial size of the cart data uInt32 mySize; - // The 2k ROM image for the cartridge - uInt8 myImage[2048]; - // The 1024 bytes of RAM - uInt8 myRAM[1024]; + std::array myRAM; + + // Initial RAM data from the cart (doesn't always exist) + std::array myInitialRAM; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartCVPlus.cxx b/src/emucore/CartCVPlus.cxx index 495322dac..67ad2da2b 100644 --- a/src/emucore/CartCVPlus.cxx +++ b/src/emucore/CartCVPlus.cxx @@ -30,14 +30,14 @@ CartridgeCVPlus::CartridgeCVPlus(const ByteBuffer& image, uInt32 size, myImage = make_unique(mySize); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), mySize); - createCodeAccessBase(mySize + 1024); + std::copy_n(image.get(), mySize, myImage.get()); + createCodeAccessBase(mySize + myRAM.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCVPlus::reset() { - initializeRAM(myRAM, 1024); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); // We'll map the startup bank into the first segment upon reset @@ -144,7 +144,7 @@ bool CartridgeCVPlus::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeCVPlus::getBank() const +uInt16 CartridgeCVPlus::getBank(uInt16) const { return myCurrentBank; } @@ -187,7 +187,7 @@ bool CartridgeCVPlus::save(Serializer& out) const try { out.putShort(myCurrentBank); - out.putByteArray(myRAM, 1024); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -204,7 +204,7 @@ bool CartridgeCVPlus::load(Serializer& in) try { myCurrentBank = in.getShort(); - in.getByteArray(myRAM, 1024); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartCVPlus.hxx b/src/emucore/CartCVPlus.hxx index eddda563e..701a781f2 100644 --- a/src/emucore/CartCVPlus.hxx +++ b/src/emucore/CartCVPlus.hxx @@ -84,8 +84,10 @@ class CartridgeCVPlus : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -166,7 +168,7 @@ class CartridgeCVPlus : public Cartridge ByteBuffer myImage; // The 1024 bytes of RAM - uInt8 myRAM[1024]; + std::array myRAM; // Size of the ROM image uInt32 mySize; diff --git a/src/emucore/CartDASH.cxx b/src/emucore/CartDASH.cxx index 7472b4d58..81ed2ec57 100644 --- a/src/emucore/CartDASH.cxx +++ b/src/emucore/CartDASH.cxx @@ -29,14 +29,14 @@ CartridgeDASH::CartridgeDASH(const ByteBuffer& image, uInt32 size, myImage = make_unique(mySize); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), mySize); - createCodeAccessBase(mySize + RAM_TOTAL_SIZE); + std::copy_n(image.get(), mySize, myImage.get()); + createCodeAccessBase(mySize + myRAM.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeDASH::reset() { - initializeRAM(myRAM, RAM_TOTAL_SIZE); + initializeRAM(myRAM.data(), myRAM.size()); // Remember startup bank (0 per spec, rather than last per 3E scheme). // Set this to go to 3rd 1K Bank. @@ -311,9 +311,9 @@ bool CartridgeDASH::save(Serializer& out) const { try { - out.putShortArray(bankInUse, 8); - out.putShortArray(segmentInUse, 4); - out.putByteArray(myRAM, RAM_TOTAL_SIZE); + out.putShortArray(bankInUse.data(), bankInUse.size()); + out.putShortArray(segmentInUse.data(), segmentInUse.size()); + out.putByteArray(myRAM.data(), myRAM.size()); } catch (...) { @@ -328,9 +328,9 @@ bool CartridgeDASH::load(Serializer& in) { try { - in.getShortArray(bankInUse, 8); - in.getShortArray(segmentInUse, 4); - in.getByteArray(myRAM, RAM_TOTAL_SIZE); + in.getShortArray(bankInUse.data(), bankInUse.size()); + in.getShortArray(segmentInUse.data(), segmentInUse.size()); + in.getByteArray(myRAM.data(), myRAM.size()); } catch (...) { diff --git a/src/emucore/CartDASH.hxx b/src/emucore/CartDASH.hxx index 7c109e32b..261a347cc 100644 --- a/src/emucore/CartDASH.hxx +++ b/src/emucore/CartDASH.hxx @@ -236,8 +236,8 @@ class CartridgeDASH: public Cartridge // are consecutive. This allows us to determine on a read/write exactly where the data is. static constexpr uInt16 BANK_UNDEFINED = 0x8000; // bank is undefined and inaccessible - uInt16 bankInUse[8]; // bank being used for ROM/RAM (eight 512 byte areas) - uInt16 segmentInUse[4]; // set by bank methods, to know which hotspot was accessed + std::array bankInUse; // bank being used for ROM/RAM (eight 512 byte areas) + std::array segmentInUse; // set by bank methods, to know which hotspot was accessed static constexpr uInt16 BANK_SWITCH_HOTSPOT_RAM = 0x3E; // writes to this address cause bankswitching static constexpr uInt16 BANK_SWITCH_HOTSPOT_ROM = 0x3F; // writes to this address cause bankswitching @@ -262,8 +262,8 @@ class CartridgeDASH: public Cartridge static constexpr uInt16 RAM_WRITE_OFFSET = 0x800; ByteBuffer myImage; // Pointer to a dynamically allocated ROM image of the cartridge - uInt32 mySize; // Size of the ROM image - uInt8 myRAM[RAM_TOTAL_SIZE]; + uInt32 mySize; // Size of the ROM image + std::array myRAM; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartDF.cxx b/src/emucore/CartDF.cxx index 60e9635de..b8ec1f727 100644 --- a/src/emucore/CartDF.cxx +++ b/src/emucore/CartDF.cxx @@ -25,8 +25,8 @@ CartridgeDF::CartridgeDF(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(131072u, size)); - createCodeAccessBase(131072); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -101,7 +101,7 @@ bool CartridgeDF::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeDF::getBank() const +uInt16 CartridgeDF::getBank(uInt16) const { return myBankOffset >> 12; } @@ -122,8 +122,8 @@ bool CartridgeDF::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeDF::getImage(uInt32& size) const { - size = 131072; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartDF.hxx b/src/emucore/CartDF.hxx index 9a8a6182a..2d721abc1 100644 --- a/src/emucore/CartDF.hxx +++ b/src/emucore/CartDF.hxx @@ -73,8 +73,10 @@ class CartridgeDF : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,7 +154,7 @@ class CartridgeDF : public Cartridge private: // The 128K ROM image of the cartridge - uInt8 myImage[32 * 4096]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt32 myBankOffset; diff --git a/src/emucore/CartDFSC.cxx b/src/emucore/CartDFSC.cxx index 67b763679..fa8c980b2 100644 --- a/src/emucore/CartDFSC.cxx +++ b/src/emucore/CartDFSC.cxx @@ -25,14 +25,14 @@ CartridgeDFSC::CartridgeDFSC(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(131072u, size)); - createCodeAccessBase(131072); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeDFSC::reset() { - initializeRAM(myRAM, 128); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(15); // Upon reset we switch to the startup bank @@ -144,7 +144,7 @@ bool CartridgeDFSC::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeDFSC::getBank() const +uInt16 CartridgeDFSC::getBank(uInt16) const { return myBankOffset >> 12; } @@ -176,8 +176,8 @@ bool CartridgeDFSC::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeDFSC::getImage(uInt32& size) const { - size = 131072; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -186,7 +186,7 @@ bool CartridgeDFSC::save(Serializer& out) const try { out.putInt(myBankOffset); - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -203,7 +203,7 @@ bool CartridgeDFSC::load(Serializer& in) try { myBankOffset = in.getInt(); - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartDFSC.hxx b/src/emucore/CartDFSC.hxx index 8ffe7e955..cc2776b25 100644 --- a/src/emucore/CartDFSC.hxx +++ b/src/emucore/CartDFSC.hxx @@ -73,8 +73,10 @@ class CartridgeDFSC : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,10 +154,10 @@ class CartridgeDFSC : public Cartridge private: // The 128K ROM image of the cartridge - uInt8 myImage[32 * 4096]; + std::array myImage; // The 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; // Indicates the offset into the ROM image (aligns to current bank) uInt32 myBankOffset; diff --git a/src/emucore/CartDPC.cxx b/src/emucore/CartDPC.cxx index 616f16d87..1f52d71bf 100644 --- a/src/emucore/CartDPC.cxx +++ b/src/emucore/CartDPC.cxx @@ -29,27 +29,26 @@ CartridgeDPC::CartridgeDPC(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Make a copy of the entire image - memcpy(myImage, image.get(), std::min(size, 8192u + 2048u + 256u)); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); createCodeAccessBase(8192); // Pointer to the program ROM (8K @ 0 byte offset) - myProgramImage = myImage; + myProgramImage = myImage.data(); // Pointer to the display ROM (2K @ 8K offset) myDisplayImage = myProgramImage + 8192; // Initialize the DPC data fetcher registers - for(int i = 0; i < 8; ++i) - { - myTops[i] = myBottoms[i] = myFlags[i] = 0; - myCounters[i] = 0; - } + myTops.fill(0); + myBottoms.fill(0); + myFlags.fill(0); + myCounters.fill(0); // None of the data fetchers are in music mode - myMusicMode[0] = myMusicMode[1] = myMusicMode[2] = false; + myMusicMode.fill(false); // Initialize the DPC's random number generator register (must be non-zero) - myRandomNumber = 1; + myRandomNumber = 1; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -405,7 +404,7 @@ bool CartridgeDPC::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeDPC::getBank() const +uInt16 CartridgeDPC::getBank(uInt16) const { return myBankOffset >> 12; } @@ -435,7 +434,7 @@ bool CartridgeDPC::patch(uInt16 address, uInt8 value) const uInt8* CartridgeDPC::getImage(uInt32& size) const { size = mySize; - return myImage; + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -447,20 +446,20 @@ bool CartridgeDPC::save(Serializer& out) const out.putShort(myBankOffset); // The top registers for the data fetchers - out.putByteArray(myTops, 8); + out.putByteArray(myTops.data(), myTops.size()); // The bottom registers for the data fetchers - out.putByteArray(myBottoms, 8); + out.putByteArray(myBottoms.data(), myBottoms.size()); // The counter registers for the data fetchers - out.putShortArray(myCounters, 8); + out.putShortArray(myCounters.data(), myCounters.size()); // The flag registers for the data fetchers - out.putByteArray(myFlags, 8); + out.putByteArray(myFlags.data(), myFlags.size()); // The music mode flags for the data fetchers - for(int i = 0; i < 3; ++i) - out.putBool(myMusicMode[i]); + for(const auto& mode: myMusicMode) + out.putBool(mode); // The random number generator register out.putByte(myRandomNumber); @@ -486,20 +485,20 @@ bool CartridgeDPC::load(Serializer& in) myBankOffset = in.getShort(); // The top registers for the data fetchers - in.getByteArray(myTops, 8); + in.getByteArray(myTops.data(), myTops.size()); // The bottom registers for the data fetchers - in.getByteArray(myBottoms, 8); + in.getByteArray(myBottoms.data(), myBottoms.size()); // The counter registers for the data fetchers - in.getShortArray(myCounters, 8); + in.getShortArray(myCounters.data(), myCounters.size()); // The flag registers for the data fetchers - in.getByteArray(myFlags, 8); + in.getByteArray(myFlags.data(), myFlags.size()); // The music mode flags for the data fetchers - for(int i = 0; i < 3; ++i) - myMusicMode[i] = in.getBool(); + for(auto& mode: myMusicMode) + mode = in.getBool(); // The random number generator register myRandomNumber = in.getByte(); diff --git a/src/emucore/CartDPC.hxx b/src/emucore/CartDPC.hxx index 711319d7d..444dbbeda 100644 --- a/src/emucore/CartDPC.hxx +++ b/src/emucore/CartDPC.hxx @@ -77,8 +77,10 @@ class CartridgeDPC : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -170,7 +172,7 @@ class CartridgeDPC : public Cartridge private: // The ROM image - uInt8 myImage[8192 + 2048 + 256]; + std::array myImage; // (Actual) Size of the ROM image uInt32 mySize; @@ -182,19 +184,19 @@ class CartridgeDPC : public Cartridge uInt8* myDisplayImage; // The top registers for the data fetchers - uInt8 myTops[8]; + std::array myTops; // The bottom registers for the data fetchers - uInt8 myBottoms[8]; + std::array myBottoms; // The counter registers for the data fetchers - uInt16 myCounters[8]; + std::array myCounters; // The flag registers for the data fetchers - uInt8 myFlags[8]; + std::array myFlags; // The music mode DF5, DF6, & DF7 enabled flags - bool myMusicMode[3]; + std::array myMusicMode; // The random number generator register uInt8 myRandomNumber; diff --git a/src/emucore/CartDPCPlus.cxx b/src/emucore/CartDPCPlus.cxx index 4a18befa4..14ad928eb 100644 --- a/src/emucore/CartDPCPlus.cxx +++ b/src/emucore/CartDPCPlus.cxx @@ -29,7 +29,7 @@ CartridgeDPCPlus::CartridgeDPCPlus(const ByteBuffer& image, uInt32 size, const string& md5, const Settings& settings) : Cartridge(settings, md5), - mySize(std::min(size, 32768u)), + mySize(std::min(size, myImage.size())), myFastFetch(false), myLDAimmediate(false), myParameterPointer(0), @@ -41,16 +41,16 @@ CartridgeDPCPlus::CartridgeDPCPlus(const ByteBuffer& image, uInt32 size, { // Image is always 32K, but in the case of ROM > 29K, the image is // copied to the end of the buffer - if(mySize < 32768u) - memset(myImage, 0, 32768); - memcpy(myImage + (32768u - mySize), image.get(), size); + if(mySize < myImage.size()) + myImage.fill(0); + std::copy_n(image.get(), size, myImage.begin() + (myImage.size() - mySize)); createCodeAccessBase(4096 * 6); // Pointer to the program ROM (24K @ 3072 byte offset; ignore first 3K) - myProgramImage = myImage + 0xC00; + myProgramImage = myImage.data() + 0xC00; // Pointer to the display RAM - myDisplayImage = myDPCRAM + 0xC00; + myDisplayImage = myDPCRAM.data() + 0xC00; // Pointer to the Frequency RAM myFrequencyImage = myDisplayImage + 0x1000; @@ -58,9 +58,9 @@ CartridgeDPCPlus::CartridgeDPCPlus(const ByteBuffer& image, uInt32 size, // Create Thumbulator ARM emulator bool devSettings = settings.getBool("dev.settings"); myThumbEmulator = make_unique - (reinterpret_cast(myImage), - reinterpret_cast(myDPCRAM), - 32768, + (reinterpret_cast(myImage.data()), + reinterpret_cast(myDPCRAM.data()), + myImage.size(), devSettings ? settings.getBool("dev.thumb.trapfatal") : false, Thumbulator::ConfigureFor::DPCplus, this); @@ -89,21 +89,20 @@ void CartridgeDPCPlus::reset() void CartridgeDPCPlus::setInitialState() { // Reset various ROM and RAM locations - memset(myDPCRAM, 0, 8192); + myDPCRAM.fill(0); // Copy initial DPC display data and Frequency table state to Harmony RAM - memcpy(myDisplayImage, myProgramImage + 0x6000, 0x1400); + std::copy_n(myProgramImage + 0x6000, 0x1400, myDisplayImage); // Initialize the DPC data fetcher registers - for(int i = 0; i < 8; ++i) - { - myTops[i] = myBottoms[i] = myFractionalIncrements[i] = 0; - myFractionalCounters[i] = 0; - myCounters[i] = 0; - } + myTops.fill(0); + myBottoms.fill(0); + myFractionalIncrements.fill(0); + myFractionalCounters.fill(0); + myCounters.fill(0); // Set waveforms to first waveform entry - myMusicWaveforms[0] = myMusicWaveforms[1] = myMusicWaveforms[2] = 0; + myMusicWaveforms.fill(0); // Initialize the DPC's random number generator register (must be non-zero) myRandomNumber = 0x2B435044; // "DPC+" @@ -603,7 +602,7 @@ bool CartridgeDPCPlus::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeDPCPlus::getBank() const +uInt16 CartridgeDPCPlus::getBank(uInt16) const { return myBankOffset >> 12; } @@ -633,7 +632,7 @@ bool CartridgeDPCPlus::patch(uInt16 address, uInt8 value) const uInt8* CartridgeDPCPlus::getImage(uInt32& size) const { size = mySize; - return myImage + (32768u - mySize); + return myImage.data() + (myImage.size() - mySize); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -645,38 +644,38 @@ bool CartridgeDPCPlus::save(Serializer& out) const out.putShort(myBankOffset); // Harmony RAM - out.putByteArray(myDPCRAM, 8192); + out.putByteArray(myDPCRAM.data(), myDPCRAM.size()); // The top registers for the data fetchers - out.putByteArray(myTops, 8); + out.putByteArray(myTops.data(), myTops.size()); // The bottom registers for the data fetchers - out.putByteArray(myBottoms, 8); + out.putByteArray(myBottoms.data(), myBottoms.size()); // The counter registers for the data fetchers - out.putShortArray(myCounters, 8); + out.putShortArray(myCounters.data(), myCounters.size()); // The counter registers for the fractional data fetchers - out.putIntArray(myFractionalCounters, 8); + out.putIntArray(myFractionalCounters.data(), myFractionalCounters.size()); // The fractional registers for the data fetchers - out.putByteArray(myFractionalIncrements, 8); + out.putByteArray(myFractionalIncrements.data(), myFractionalIncrements.size()); // The Fast Fetcher Enabled flag out.putBool(myFastFetch); out.putBool(myLDAimmediate); // Control Byte to update - out.putByteArray(myParameter, 8); + out.putByteArray(myParameter.data(), myParameter.size()); // The music counters - out.putIntArray(myMusicCounters, 3); + out.putIntArray(myMusicCounters.data(), myMusicCounters.size()); // The music frequencies - out.putIntArray(myMusicFrequencies, 3); + out.putIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); // The music waveforms - out.putShortArray(myMusicWaveforms, 3); + out.putShortArray(myMusicWaveforms.data(), myMusicWaveforms.size()); // The random number generator register out.putInt(myRandomNumber); @@ -706,38 +705,38 @@ bool CartridgeDPCPlus::load(Serializer& in) myBankOffset = in.getShort(); // Harmony RAM - in.getByteArray(myDPCRAM, 8192); + in.getByteArray(myDPCRAM.data(), myDPCRAM.size()); // The top registers for the data fetchers - in.getByteArray(myTops, 8); + in.getByteArray(myTops.data(), myTops.size()); // The bottom registers for the data fetchers - in.getByteArray(myBottoms, 8); + in.getByteArray(myBottoms.data(), myBottoms.size()); // The counter registers for the data fetchers - in.getShortArray(myCounters, 8); + in.getShortArray(myCounters.data(), myCounters.size()); // The counter registers for the fractional data fetchers - in.getIntArray(myFractionalCounters, 8); + in.getIntArray(myFractionalCounters.data(), myFractionalCounters.size()); // The fractional registers for the data fetchers - in.getByteArray(myFractionalIncrements, 8); + in.getByteArray(myFractionalIncrements.data(), myFractionalIncrements.size()); // The Fast Fetcher Enabled flag myFastFetch = in.getBool(); myLDAimmediate = in.getBool(); // Control Byte to update - in.getByteArray(myParameter, 8); + in.getByteArray(myParameter.data(), myParameter.size()); // The music mode counters for the data fetchers - in.getIntArray(myMusicCounters, 3); + in.getIntArray(myMusicCounters.data(), myMusicCounters.size()); // The music mode frequency addends for the data fetchers - in.getIntArray(myMusicFrequencies, 3); + in.getIntArray(myMusicFrequencies.data(), myMusicFrequencies.size()); // The music waveforms - in.getShortArray(myMusicWaveforms, 3); + in.getShortArray(myMusicWaveforms.data(), myMusicWaveforms.size()); // The random number generator register myRandomNumber = in.getInt(); diff --git a/src/emucore/CartDPCPlus.hxx b/src/emucore/CartDPCPlus.hxx index fd02eca2b..c91a58f2a 100644 --- a/src/emucore/CartDPCPlus.hxx +++ b/src/emucore/CartDPCPlus.hxx @@ -92,8 +92,10 @@ class CartridgeDPCPlus : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -198,7 +200,7 @@ class CartridgeDPCPlus : public Cartridge private: // The ROM image and size - uInt8 myImage[32768]; + std::array myImage; uInt32 mySize; // Pointer to the 24K program ROM image of the cartridge @@ -211,7 +213,7 @@ class CartridgeDPCPlus : public Cartridge // 3K DPC+ driver // 4K Display Data // 1K Frequency Data - uInt8 myDPCRAM[8192]; + std::array myDPCRAM; // Pointer to the Thumb ARM emulator object unique_ptr myThumbEmulator; @@ -220,19 +222,19 @@ class CartridgeDPCPlus : public Cartridge uInt8* myFrequencyImage; // The top registers for the data fetchers - uInt8 myTops[8]; + std::array myTops; // The bottom registers for the data fetchers - uInt8 myBottoms[8]; + std::array myBottoms; // The counter registers for the data fetchers - uInt16 myCounters[8]; + std::array myCounters; // The counter registers for the fractional data fetchers - uInt32 myFractionalCounters[8]; + std::array myFractionalCounters; // The fractional increments for the data fetchers - uInt8 myFractionalIncrements[8]; + std::array myFractionalIncrements; // The Fast Fetcher Enabled flag bool myFastFetch; @@ -241,19 +243,19 @@ class CartridgeDPCPlus : public Cartridge bool myLDAimmediate; // Parameter for special functions - uInt8 myParameter[8]; + std::array myParameter; // Parameter pointer for special functions uInt8 myParameterPointer; // The music mode counters - uInt32 myMusicCounters[3]; + std::array myMusicCounters; // The music frequency - uInt32 myMusicFrequencies[3]; + std::array myMusicFrequencies; // The music waveforms - uInt16 myMusicWaveforms[3]; + std::array myMusicWaveforms; // The random number generator register uInt32 myRandomNumber; diff --git a/src/emucore/CartE0.cxx b/src/emucore/CartE0.cxx index e6f2e7a30..ee177b1ab 100644 --- a/src/emucore/CartE0.cxx +++ b/src/emucore/CartE0.cxx @@ -24,8 +24,8 @@ CartridgeE0::CartridgeE0(const ByteBuffer& image, uInt32 size, : Cartridge(settings, md5) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(8192u, size)); - createCodeAccessBase(8192); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -75,9 +75,9 @@ void CartridgeE0::install(System& system) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeE0::getBank(uInt16 addr) const +uInt16 CartridgeE0::getBank(uInt16 address) const { - return myCurrentSlice[(addr & 0xFFF) >> 10]; // 1K slices + return myCurrentSlice[(address & 0xFFF) >> 10]; // 1K slices } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -203,8 +203,8 @@ bool CartridgeE0::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeE0::getImage(uInt32& size) const { - size = 8192; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -212,7 +212,7 @@ bool CartridgeE0::save(Serializer& out) const { try { - out.putShortArray(myCurrentSlice, 4); + out.putShortArray(myCurrentSlice.data(), myCurrentSlice.size()); } catch(...) { @@ -228,7 +228,7 @@ bool CartridgeE0::load(Serializer& in) { try { - in.getShortArray(myCurrentSlice, 4); + in.getShortArray(myCurrentSlice.data(), myCurrentSlice.size()); } catch(...) { diff --git a/src/emucore/CartE0.hxx b/src/emucore/CartE0.hxx index 1797badd0..40af37922 100644 --- a/src/emucore/CartE0.hxx +++ b/src/emucore/CartE0.hxx @@ -75,8 +75,10 @@ class CartridgeE0 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank(uInt16 addr) const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -175,11 +177,11 @@ class CartridgeE0 : public Cartridge void segmentTwo(uInt16 slice); private: - // Indicates the slice mapped into each of the four segments - uInt16 myCurrentSlice[4]; - // The 8K ROM image of the cartridge - uInt8 myImage[8192]; + std::array myImage; + + // Indicates the slice mapped into each of the four segments + std::array myCurrentSlice; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartEF.cxx b/src/emucore/CartEF.cxx index 594701774..06fb84945 100644 --- a/src/emucore/CartEF.cxx +++ b/src/emucore/CartEF.cxx @@ -25,8 +25,8 @@ CartridgeEF::CartridgeEF(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(65536u, size)); - createCodeAccessBase(65536); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -101,7 +101,7 @@ bool CartridgeEF::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeEF::getBank() const +uInt16 CartridgeEF::getBank(uInt16) const { return myBankOffset >> 12; } @@ -122,8 +122,8 @@ bool CartridgeEF::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeEF::getImage(uInt32& size) const { - size = 65536; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartEF.hxx b/src/emucore/CartEF.hxx index 8bee49b90..06622b00f 100644 --- a/src/emucore/CartEF.hxx +++ b/src/emucore/CartEF.hxx @@ -73,8 +73,10 @@ class CartridgeEF : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,7 +154,7 @@ class CartridgeEF : public Cartridge private: // The 64K ROM image of the cartridge - uInt8 myImage[65536]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartEFSC.cxx b/src/emucore/CartEFSC.cxx index 1f88c1ea9..f9622de5e 100644 --- a/src/emucore/CartEFSC.cxx +++ b/src/emucore/CartEFSC.cxx @@ -25,14 +25,14 @@ CartridgeEFSC::CartridgeEFSC(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(65536u, size)); - createCodeAccessBase(65536); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeEFSC::reset() { - initializeRAM(myRAM, 128); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(15); // Upon reset we switch to the startup bank @@ -144,7 +144,7 @@ bool CartridgeEFSC::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeEFSC::getBank() const +uInt16 CartridgeEFSC::getBank(uInt16) const { return myBankOffset >> 12; } @@ -176,8 +176,8 @@ bool CartridgeEFSC::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeEFSC::getImage(uInt32& size) const { - size = 65536; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -186,7 +186,7 @@ bool CartridgeEFSC::save(Serializer& out) const try { out.putShort(myBankOffset); - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -203,7 +203,7 @@ bool CartridgeEFSC::load(Serializer& in) try { myBankOffset = in.getShort(); - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartEFSC.hxx b/src/emucore/CartEFSC.hxx index d948e54ff..c4c90f475 100644 --- a/src/emucore/CartEFSC.hxx +++ b/src/emucore/CartEFSC.hxx @@ -74,8 +74,10 @@ class CartridgeEFSC : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -153,10 +155,10 @@ class CartridgeEFSC : public Cartridge private: // The 64K ROM image of the cartridge - uInt8 myImage[65536]; + std::array myImage; // The 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartF0.cxx b/src/emucore/CartF0.cxx index b6d178a06..d4004c999 100644 --- a/src/emucore/CartF0.cxx +++ b/src/emucore/CartF0.cxx @@ -25,8 +25,8 @@ CartridgeF0::CartridgeF0(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(65536u, size)); - createCodeAccessBase(65536); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -109,7 +109,7 @@ bool CartridgeF0::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeF0::getBank() const +uInt16 CartridgeF0::getBank(uInt16) const { return myBankOffset >> 12; } @@ -130,8 +130,8 @@ bool CartridgeF0::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeF0::getImage(uInt32& size) const { - size = 65536; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartF0.hxx b/src/emucore/CartF0.hxx index ad9b6aa30..a4e6fae09 100644 --- a/src/emucore/CartF0.hxx +++ b/src/emucore/CartF0.hxx @@ -73,8 +73,10 @@ class CartridgeF0 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -158,7 +160,7 @@ class CartridgeF0 : public Cartridge private: // The 64K ROM image of the cartridge - uInt8 myImage[65536]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartF4.cxx b/src/emucore/CartF4.cxx index 47d5dee96..b50679ff1 100644 --- a/src/emucore/CartF4.cxx +++ b/src/emucore/CartF4.cxx @@ -26,8 +26,8 @@ CartridgeF4::CartridgeF4(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(32768u, size)); - createCodeAccessBase(32768); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -105,7 +105,7 @@ bool CartridgeF4::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeF4::getBank() const +uInt16 CartridgeF4::getBank(uInt16) const { return myBankOffset >> 12; } @@ -126,8 +126,8 @@ bool CartridgeF4::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeF4::getImage(uInt32& size) const { - size = 32768; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartF4.hxx b/src/emucore/CartF4.hxx index 3685320c6..090f49dea 100644 --- a/src/emucore/CartF4.hxx +++ b/src/emucore/CartF4.hxx @@ -72,8 +72,10 @@ class CartridgeF4 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -151,7 +153,7 @@ class CartridgeF4 : public Cartridge private: // The 32K ROM image of the cartridge - uInt8 myImage[32768]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartF4SC.cxx b/src/emucore/CartF4SC.cxx index b55a1955f..8b282075c 100644 --- a/src/emucore/CartF4SC.cxx +++ b/src/emucore/CartF4SC.cxx @@ -25,14 +25,14 @@ CartridgeF4SC::CartridgeF4SC(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(32768u, size)); - createCodeAccessBase(32768); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF4SC::reset() { - initializeRAM(myRAM, 128); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); // Upon reset we switch to the startup bank @@ -144,7 +144,7 @@ bool CartridgeF4SC::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeF4SC::getBank() const +uInt16 CartridgeF4SC::getBank(uInt16) const { return myBankOffset >> 12; } @@ -176,8 +176,8 @@ bool CartridgeF4SC::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeF4SC::getImage(uInt32& size) const { - size = 32768; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -186,7 +186,7 @@ bool CartridgeF4SC::save(Serializer& out) const try { out.putShort(myBankOffset); - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -203,7 +203,7 @@ bool CartridgeF4SC::load(Serializer& in) try { myBankOffset = in.getShort(); - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartF4SC.hxx b/src/emucore/CartF4SC.hxx index bc37769e2..d20b58d74 100644 --- a/src/emucore/CartF4SC.hxx +++ b/src/emucore/CartF4SC.hxx @@ -73,8 +73,10 @@ class CartridgeF4SC : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,10 +154,10 @@ class CartridgeF4SC : public Cartridge private: // The 32K ROM image of the cartridge - uInt8 myImage[32768]; + std::array myImage; // The 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartF6.cxx b/src/emucore/CartF6.cxx index fc804ead4..d4b54a63a 100644 --- a/src/emucore/CartF6.cxx +++ b/src/emucore/CartF6.cxx @@ -25,8 +25,8 @@ CartridgeF6::CartridgeF6(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(16384u, size)); - createCodeAccessBase(16384); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -145,7 +145,7 @@ bool CartridgeF6::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeF6::getBank() const +uInt16 CartridgeF6::getBank(uInt16) const { return myBankOffset >> 12; } @@ -166,8 +166,8 @@ bool CartridgeF6::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeF6::getImage(uInt32& size) const { - size = 16384; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartF6.hxx b/src/emucore/CartF6.hxx index 16791909e..515eaf1e4 100644 --- a/src/emucore/CartF6.hxx +++ b/src/emucore/CartF6.hxx @@ -72,8 +72,10 @@ class CartridgeF6 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -151,7 +153,7 @@ class CartridgeF6 : public Cartridge private: // The 16K ROM image of the cartridge - uInt8 myImage[16384]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartF6SC.cxx b/src/emucore/CartF6SC.cxx index 618eea54e..95ca133ed 100644 --- a/src/emucore/CartF6SC.cxx +++ b/src/emucore/CartF6SC.cxx @@ -25,14 +25,14 @@ CartridgeF6SC::CartridgeF6SC(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(16384u, size)); - createCodeAccessBase(16384); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF6SC::reset() { - initializeRAM(myRAM, 128); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); // Upon reset we switch to the startup bank @@ -184,7 +184,7 @@ bool CartridgeF6SC::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeF6SC::getBank() const +uInt16 CartridgeF6SC::getBank(uInt16) const { return myBankOffset >> 12; } @@ -216,8 +216,8 @@ bool CartridgeF6SC::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeF6SC::getImage(uInt32& size) const { - size = 16384; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -226,7 +226,7 @@ bool CartridgeF6SC::save(Serializer& out) const try { out.putShort(myBankOffset); - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -243,7 +243,7 @@ bool CartridgeF6SC::load(Serializer& in) try { myBankOffset = in.getShort(); - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartF6SC.hxx b/src/emucore/CartF6SC.hxx index 0a50dc451..ed83b05e5 100644 --- a/src/emucore/CartF6SC.hxx +++ b/src/emucore/CartF6SC.hxx @@ -73,8 +73,10 @@ class CartridgeF6SC : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,10 +154,10 @@ class CartridgeF6SC : public Cartridge private: // The 16K ROM image of the cartridge - uInt8 myImage[16384]; + std::array myImage; // The 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartF8.cxx b/src/emucore/CartF8.cxx index 63e504848..08d40651b 100644 --- a/src/emucore/CartF8.cxx +++ b/src/emucore/CartF8.cxx @@ -25,8 +25,8 @@ CartridgeF8::CartridgeF8(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(8192u, size)); - createCodeAccessBase(8192); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -126,7 +126,7 @@ bool CartridgeF8::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeF8::getBank() const +uInt16 CartridgeF8::getBank(uInt16) const { return myBankOffset >> 12; } @@ -147,8 +147,8 @@ bool CartridgeF8::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeF8::getImage(uInt32& size) const { - size = 8192; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartF8.hxx b/src/emucore/CartF8.hxx index 9e83db236..a9fe62bb5 100644 --- a/src/emucore/CartF8.hxx +++ b/src/emucore/CartF8.hxx @@ -72,8 +72,10 @@ class CartridgeF8 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -151,7 +153,7 @@ class CartridgeF8 : public Cartridge private: // The 8K ROM image of the cartridge - uInt8 myImage[8192]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartF8SC.cxx b/src/emucore/CartF8SC.cxx index f579eaa09..82d005897 100644 --- a/src/emucore/CartF8SC.cxx +++ b/src/emucore/CartF8SC.cxx @@ -25,14 +25,14 @@ CartridgeF8SC::CartridgeF8SC(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(8192u, size)); - createCodeAccessBase(8192); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF8SC::reset() { - initializeRAM(myRAM, 128); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(1); // Upon reset we switch to the startup bank @@ -164,7 +164,7 @@ bool CartridgeF8SC::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeF8SC::getBank() const +uInt16 CartridgeF8SC::getBank(uInt16) const { return myBankOffset >> 12; } @@ -196,8 +196,8 @@ bool CartridgeF8SC::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeF8SC::getImage(uInt32& size) const { - size = 8192; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -206,7 +206,7 @@ bool CartridgeF8SC::save(Serializer& out) const try { out.putShort(myBankOffset); - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -223,7 +223,7 @@ bool CartridgeF8SC::load(Serializer& in) try { myBankOffset = in.getShort(); - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartF8SC.hxx b/src/emucore/CartF8SC.hxx index 3907b2b43..460bdb7fa 100644 --- a/src/emucore/CartF8SC.hxx +++ b/src/emucore/CartF8SC.hxx @@ -73,8 +73,10 @@ class CartridgeF8SC : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,10 +154,10 @@ class CartridgeF8SC : public Cartridge private: // The 8K ROM image of the cartridge - uInt8 myImage[8192]; + std::array myImage; // The 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartFA.cxx b/src/emucore/CartFA.cxx index c70f067ba..f69bd9409 100644 --- a/src/emucore/CartFA.cxx +++ b/src/emucore/CartFA.cxx @@ -25,14 +25,14 @@ CartridgeFA::CartridgeFA(const ByteBuffer& image, uInt32 size, myBankOffset(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(12288u, size)); - createCodeAccessBase(12288); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeFA::reset() { - initializeRAM(myRAM, 256); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(2); // Upon reset we switch to the startup bank @@ -174,7 +174,7 @@ bool CartridgeFA::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeFA::getBank() const +uInt16 CartridgeFA::getBank(uInt16) const { return myBankOffset >> 12; } @@ -206,8 +206,8 @@ bool CartridgeFA::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeFA::getImage(uInt32& size) const { - size = 12288; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -216,7 +216,7 @@ bool CartridgeFA::save(Serializer& out) const try { out.putShort(myBankOffset); - out.putByteArray(myRAM, 256); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -233,7 +233,7 @@ bool CartridgeFA::load(Serializer& in) try { myBankOffset = in.getShort(); - in.getByteArray(myRAM, 256); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartFA.hxx b/src/emucore/CartFA.hxx index 5bcb1cf3f..04422ca01 100644 --- a/src/emucore/CartFA.hxx +++ b/src/emucore/CartFA.hxx @@ -73,8 +73,10 @@ class CartridgeFA : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,10 +154,10 @@ class CartridgeFA : public Cartridge private: // The 12K ROM image of the cartridge - uInt8 myImage[12288]; + std::array myImage; // The 256 bytes of RAM on the cartridge - uInt8 myRAM[256]; + std::array myRAM; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartFA2.cxx b/src/emucore/CartFA2.cxx index 0dc35c0dd..5fe0b7e2a 100644 --- a/src/emucore/CartFA2.cxx +++ b/src/emucore/CartFA2.cxx @@ -31,20 +31,20 @@ CartridgeFA2::CartridgeFA2(const ByteBuffer& image, uInt32 size, { // 29/32K version of FA2 has valid data @ 1K - 29K const uInt8* img_ptr = image.get(); - if(size >= 29 * 1024) - img_ptr += 1024; + if(size >= 29_KB) + img_ptr += 1_KB; else if(size < mySize) mySize = size; // Copy the ROM image into my buffer - memcpy(myImage, img_ptr, mySize); + std::copy_n(img_ptr, mySize, myImage.begin()); createCodeAccessBase(mySize); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeFA2::reset() { - initializeRAM(myRAM, 256); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); // Upon reset we switch to the startup bank @@ -93,7 +93,7 @@ uInt8 CartridgeFA2::peek(uInt16 address) { case 0x0FF4: // Load/save RAM to/from Harmony cart flash - if(mySize == 28*1024 && !bankLocked()) + if(mySize == 28_KB && !bankLocked()) return ramReadWrite(); break; @@ -130,7 +130,7 @@ uInt8 CartridgeFA2::peek(uInt16 address) case 0x0FFB: // Set the current bank to the seventh 4k bank // This is only available on 28K ROMs - if(mySize == 28*1024) bank(6); + if(mySize == 28_KB) bank(6); break; default: @@ -151,7 +151,7 @@ bool CartridgeFA2::poke(uInt16 address, uInt8 value) { case 0x0FF4: // Load/save RAM to/from Harmony cart flash - if(mySize == 28*1024 && !bankLocked()) + if(mySize == 28_KB && !bankLocked()) ramReadWrite(); return false; @@ -188,7 +188,7 @@ bool CartridgeFA2::poke(uInt16 address, uInt8 value) case 0x0FFB: // Set the current bank to the seventh 4k bank // This is only available on 28K ROMs - if(mySize == 28*1024) bank(6); + if(mySize == 28_KB) bank(6); return false; default: @@ -241,7 +241,7 @@ bool CartridgeFA2::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeFA2::getBank() const +uInt16 CartridgeFA2::getBank(uInt16) const { return myBankOffset >> 12; } @@ -249,7 +249,7 @@ uInt16 CartridgeFA2::getBank() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt16 CartridgeFA2::bankCount() const { - return (mySize / 4096); + return (mySize / 4_KB); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -274,7 +274,7 @@ bool CartridgeFA2::patch(uInt16 address, uInt8 value) const uInt8* CartridgeFA2::getImage(uInt32& size) const { size = mySize; - return myImage; + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -283,7 +283,7 @@ bool CartridgeFA2::save(Serializer& out) const try { out.putShort(myBankOffset); - out.putByteArray(myRAM, 256); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -300,7 +300,7 @@ bool CartridgeFA2::load(Serializer& in) try { myBankOffset = in.getShort(); - in.getByteArray(myRAM, 256); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -356,11 +356,11 @@ uInt8 CartridgeFA2::ramReadWrite() { try { - serializer.getByteArray(myRAM, 256); + serializer.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { - memset(myRAM, 0, 256); + myRAM.fill(0); } myRamAccessTimeout += 500; // Add 0.5 ms delay for read } @@ -368,7 +368,7 @@ uInt8 CartridgeFA2::ramReadWrite() { try { - serializer.putByteArray(myRAM, 256); + serializer.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -408,9 +408,8 @@ void CartridgeFA2::flash(uInt8 operation) { try { - uInt8 buf[256]; - memset(buf, 0, 256); - serializer.putByteArray(buf, 256); + std::array buf = {}; + serializer.putByteArray(buf.data(), buf.size()); } catch(...) { @@ -420,18 +419,18 @@ void CartridgeFA2::flash(uInt8 operation) { try { - serializer.getByteArray(myRAM, 256); + serializer.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { - memset(myRAM, 0, 256); + myRAM.fill(0); } } else if(operation == 2) // write { try { - serializer.putByteArray(myRAM, 256); + serializer.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartFA2.hxx b/src/emucore/CartFA2.hxx index acc201d1e..c4b43d72b 100644 --- a/src/emucore/CartFA2.hxx +++ b/src/emucore/CartFA2.hxx @@ -85,8 +85,10 @@ class CartridgeFA2 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -191,13 +193,13 @@ class CartridgeFA2 : public Cartridge private: // The 24K/28K ROM image of the cartridge - uInt8 myImage[28 * 1024]; + std::array myImage; // Actual usable size of the ROM image uInt32 mySize; // The 256 bytes of RAM on the cartridge - uInt8 myRAM[256]; + std::array myRAM; // The time after which the first request of a load/save operation // will actually be completed diff --git a/src/emucore/CartFE.cxx b/src/emucore/CartFE.cxx index 5c99e4ab9..e811bb966 100644 --- a/src/emucore/CartFE.cxx +++ b/src/emucore/CartFE.cxx @@ -27,8 +27,8 @@ CartridgeFE::CartridgeFE(const ByteBuffer& image, uInt32 size, myLastAccessWasFE(false) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(8192u, size)); - createCodeAccessBase(8192); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -110,7 +110,7 @@ bool CartridgeFE::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeFE::getBank() const +uInt16 CartridgeFE::getBank(uInt16) const { return myBankOffset >> 12; } @@ -131,8 +131,8 @@ bool CartridgeFE::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeFE::getImage(uInt32& size) const { - size = 8192; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartFE.hxx b/src/emucore/CartFE.hxx index 6158c4cfb..1ea11d6a0 100644 --- a/src/emucore/CartFE.hxx +++ b/src/emucore/CartFE.hxx @@ -115,8 +115,10 @@ class CartridgeFE : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -201,7 +203,7 @@ class CartridgeFE : public Cartridge private: // The 8K ROM image of the cartridge - uInt8 myImage[8192]; + std::array myImage; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartMDM.cxx b/src/emucore/CartMDM.cxx index ade4407cb..f2bf265b6 100644 --- a/src/emucore/CartMDM.cxx +++ b/src/emucore/CartMDM.cxx @@ -30,7 +30,7 @@ CartridgeMDM::CartridgeMDM(const ByteBuffer& image, uInt32 size, myImage = make_unique(mySize); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), mySize); + std::copy_n(image.get(), mySize, myImage.get()); createCodeAccessBase(mySize); } @@ -124,7 +124,7 @@ bool CartridgeMDM::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeMDM::getBank() const +uInt16 CartridgeMDM::getBank(uInt16) const { return myBankOffset >> 12; } diff --git a/src/emucore/CartMDM.hxx b/src/emucore/CartMDM.hxx index abeaee3a2..af19471d5 100644 --- a/src/emucore/CartMDM.hxx +++ b/src/emucore/CartMDM.hxx @@ -84,8 +84,10 @@ class CartridgeMDM : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -169,7 +171,7 @@ class CartridgeMDM : public Cartridge uInt32 mySize; // Previous Device's page access - System::PageAccess myHotSpotPageAccess[8]; + std::array myHotSpotPageAccess; // Indicates the offset into the ROM image (aligns to current bank) uInt32 myBankOffset; diff --git a/src/emucore/CartMNetwork.cxx b/src/emucore/CartMNetwork.cxx index f930daaeb..ad4c28021 100644 --- a/src/emucore/CartMNetwork.cxx +++ b/src/emucore/CartMNetwork.cxx @@ -35,8 +35,8 @@ void CartridgeMNetwork::initialize(const ByteBuffer& image, uInt32 size) myImage = make_unique(size); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), std::min(romSize(), size)); - createCodeAccessBase(romSize() + RAM_SIZE); + std::copy_n(image.get(), std::min(romSize(), size), myImage.get()); + createCodeAccessBase(romSize() + myRAM.size()); myRAMSlice = bankCount() - 1; } @@ -44,7 +44,7 @@ void CartridgeMNetwork::initialize(const ByteBuffer& image, uInt32 size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeMNetwork::reset() { - initializeRAM(myRAM, RAM_SIZE); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); uInt32 ramBank = randomStartBank() ? @@ -162,9 +162,9 @@ void CartridgeMNetwork::bankRAM(uInt16 bank) // Setup the page access methods for the current bank // Set the page accessing method for the 256 bytes of RAM reading pages - setAccess(0x1800, 0x100, 1024 + offset, myRAM, romSize() + BANK_SIZE / 2, System::PageAccessType::WRITE); + setAccess(0x1800, 0x100, 1024 + offset, myRAM.data(), romSize() + BANK_SIZE / 2, System::PageAccessType::WRITE); // Set the page accessing method for the 256 bytes of RAM reading pages - setAccess(0x1900, 0x100, 1024 + offset, myRAM, romSize() + BANK_SIZE / 2, System::PageAccessType::READ); + setAccess(0x1900, 0x100, 1024 + offset, myRAM.data(), romSize() + BANK_SIZE / 2, System::PageAccessType::READ); myBankChanged = true; } @@ -188,17 +188,17 @@ bool CartridgeMNetwork::bank(uInt16 slice) else { // Set the page accessing method for the 1K slice of RAM writing pages - setAccess(0x1000, BANK_SIZE / 2, 0, myRAM, romSize(), System::PageAccessType::WRITE); + setAccess(0x1000, BANK_SIZE / 2, 0, myRAM.data(), romSize(), System::PageAccessType::WRITE); // Set the page accessing method for the 1K slice of RAM reading pages - setAccess(0x1000 + BANK_SIZE / 2, BANK_SIZE / 2, 0, myRAM, romSize(), System::PageAccessType::READ); + setAccess(0x1000 + BANK_SIZE / 2, BANK_SIZE / 2, 0, myRAM.data(), romSize(), System::PageAccessType::READ); } return myBankChanged = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeMNetwork::getBank(uInt16 addr) const +uInt16 CartridgeMNetwork::getBank(uInt16 address) const { - return myCurrentSlice[(addr & 0xFFF) >> 11]; // 2K slices + return myCurrentSlice[(address & 0xFFF) >> 11]; // 2K slices } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -243,9 +243,9 @@ bool CartridgeMNetwork::save(Serializer& out) const { try { - out.putShortArray(myCurrentSlice, NUM_SEGMENTS); + out.putShortArray(myCurrentSlice.data(), myCurrentSlice.size()); out.putShort(myCurrentRAM); - out.putByteArray(myRAM, RAM_SIZE); + out.putByteArray(myRAM.data(), myRAM.size()); } catch(...) { @@ -261,9 +261,9 @@ bool CartridgeMNetwork::load(Serializer& in) { try { - in.getShortArray(myCurrentSlice, NUM_SEGMENTS); + in.getShortArray(myCurrentSlice.data(), myCurrentSlice.size()); myCurrentRAM = in.getShort(); - in.getByteArray(myRAM, RAM_SIZE); + in.getByteArray(myRAM.data(), myRAM.size()); } catch(...) { diff --git a/src/emucore/CartMNetwork.hxx b/src/emucore/CartMNetwork.hxx index f4b9a4635..fed4d8789 100644 --- a/src/emucore/CartMNetwork.hxx +++ b/src/emucore/CartMNetwork.hxx @@ -100,8 +100,10 @@ class CartridgeMNetwork : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank(uInt16 addr) const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -203,10 +205,10 @@ class CartridgeMNetwork : public Cartridge uInt32 mySize; // The 2K of RAM - uInt8 myRAM[RAM_SIZE]; + std::array myRAM; // Indicates which slice is in the segment - uInt16 myCurrentSlice[NUM_SEGMENTS]; + std::array myCurrentSlice; // Indicates which 256 byte bank of RAM is being used uInt16 myCurrentRAM; diff --git a/src/emucore/CartSB.cxx b/src/emucore/CartSB.cxx index bd1cc8568..776c20140 100644 --- a/src/emucore/CartSB.cxx +++ b/src/emucore/CartSB.cxx @@ -29,7 +29,7 @@ CartridgeSB::CartridgeSB(const ByteBuffer& image, uInt32 size, myImage = make_unique(mySize); // Copy the ROM image into my buffer - memcpy(myImage.get(), image.get(), mySize); + std::copy_n(image.get(), mySize, myImage.get()); createCodeAccessBase(mySize); } @@ -129,7 +129,7 @@ bool CartridgeSB::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeSB::getBank() const +uInt16 CartridgeSB::getBank(uInt16) const { return myBankOffset >> 12; } diff --git a/src/emucore/CartSB.hxx b/src/emucore/CartSB.hxx index c29559b7f..f89b0db38 100644 --- a/src/emucore/CartSB.hxx +++ b/src/emucore/CartSB.hxx @@ -73,8 +73,10 @@ class CartridgeSB : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -159,7 +161,7 @@ class CartridgeSB : public Cartridge uInt32 myBankOffset; // Previous Device's page access - System::PageAccess myHotSpotPageAccess[8]; + std::array myHotSpotPageAccess; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/CartUA.cxx b/src/emucore/CartUA.cxx index f31e8b24a..336b19d1c 100644 --- a/src/emucore/CartUA.cxx +++ b/src/emucore/CartUA.cxx @@ -27,8 +27,8 @@ CartridgeUA::CartridgeUA(const ByteBuffer& image, uInt32 size, mySwappedHotspots(swapHotspots) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(8192u, size)); - createCodeAccessBase(8192); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -143,7 +143,7 @@ bool CartridgeUA::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeUA::getBank() const +uInt16 CartridgeUA::getBank(uInt16) const { return myBankOffset >> 12; } @@ -164,8 +164,8 @@ bool CartridgeUA::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeUA::getImage(uInt32& size) const { - size = 8192; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartUA.hxx b/src/emucore/CartUA.hxx index c1ed54ab0..817f509b0 100644 --- a/src/emucore/CartUA.hxx +++ b/src/emucore/CartUA.hxx @@ -73,8 +73,10 @@ class CartridgeUA : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -152,10 +154,10 @@ class CartridgeUA : public Cartridge private: // The 8K ROM image of the cartridge - uInt8 myImage[8192]; + std::array myImage; // Previous Device's page access - System::PageAccess myHotSpotPageAccess[2]; + std::array myHotSpotPageAccess; // Indicates the offset into the ROM image (aligns to current bank) uInt16 myBankOffset; diff --git a/src/emucore/CartWD.cxx b/src/emucore/CartWD.cxx index 0cf2eb986..fa9782a98 100644 --- a/src/emucore/CartWD.cxx +++ b/src/emucore/CartWD.cxx @@ -24,20 +24,20 @@ CartridgeWD::CartridgeWD(const ByteBuffer& image, uInt32 size, const string& md5, const Settings& settings) : Cartridge(settings, md5), - mySize(std::min(8195u, size)), + mySize(std::min(8_KB + 3, size)), myCyclesAtBankswitchInit(0), myPendingBank(0), myCurrentBank(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), mySize); - createCodeAccessBase(8192); + std::copy_n(image.get(), mySize, myImage.begin()); + createCodeAccessBase(8_KB); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeWD::reset() { - initializeRAM(myRAM, 64); + initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); myCyclesAtBankswitchInit = 0; @@ -212,8 +212,8 @@ void CartridgeWD::segmentThree(uInt8 slice, bool map3bytes) // Make a copy of the address space pointed to by the slice // Then map in the extra 3 bytes, if required - memcpy(mySegment3, myImage+offset, 1024); - if(mySize == 8195 && map3bytes) + std::copy_n(myImage.begin()+offset, mySegment3.size(), mySegment3.begin()); + if(mySize == 8_KB + 3 && map3bytes) { mySegment3[0x3FC] = myImage[0x2000+0]; mySegment3[0x3FD] = myImage[0x2000+1]; @@ -231,7 +231,7 @@ void CartridgeWD::segmentThree(uInt8 slice, bool map3bytes) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeWD::getBank() const +uInt16 CartridgeWD::getBank(uInt16) const { return myCurrentBank; } @@ -261,7 +261,7 @@ bool CartridgeWD::patch(uInt16 address, uInt8 value) const uInt8* CartridgeWD::getImage(uInt32& size) const { size = mySize; - return myImage; + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -270,7 +270,7 @@ bool CartridgeWD::save(Serializer& out) const try { out.putShort(myCurrentBank); - out.putByteArray(myRAM, 64); + out.putByteArray(myRAM.data(), myRAM.size()); out.putLong(myCyclesAtBankswitchInit); out.putShort(myPendingBank); } @@ -289,7 +289,7 @@ bool CartridgeWD::load(Serializer& in) try { myCurrentBank = in.getShort(); - in.getByteArray(myRAM, 64); + in.getByteArray(myRAM.data(), myRAM.size()); myCyclesAtBankswitchInit = in.getLong(); myPendingBank = in.getShort(); diff --git a/src/emucore/CartWD.hxx b/src/emucore/CartWD.hxx index fee93ce30..a70db8d78 100644 --- a/src/emucore/CartWD.hxx +++ b/src/emucore/CartWD.hxx @@ -101,8 +101,10 @@ class CartridgeWD : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -211,19 +213,19 @@ class CartridgeWD : public Cartridge private: // The 8K ROM image of the cartridge - uInt8 myImage[8195]; + std::array myImage; // Indicates the actual size of the ROM image (either 8K or 8K + 3) uInt32 mySize; // The 64 bytes RAM of the cartridge - uInt8 myRAM[64]; + std::array myRAM; // The 1K ROM mirror of segment 3 (sometimes contains extra 3 bytes) - uInt8 mySegment3[1024]; + std::array mySegment3; // Indicates the offset for each of the four segments - uInt16 myOffset[4]; + std::array myOffset; // Indicates the cycle at which a bankswitch was initiated uInt64 myCyclesAtBankswitchInit; diff --git a/src/emucore/CartX07.cxx b/src/emucore/CartX07.cxx index fe2104e3f..1f14952f3 100644 --- a/src/emucore/CartX07.cxx +++ b/src/emucore/CartX07.cxx @@ -27,8 +27,8 @@ CartridgeX07::CartridgeX07(const ByteBuffer& image, uInt32 size, myCurrentBank(0) { // Copy the ROM image into my buffer - memcpy(myImage, image.get(), std::min(65536u, size)); - createCodeAccessBase(65536); + std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); + createCodeAccessBase(myImage.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -123,7 +123,7 @@ bool CartridgeX07::bank(uInt16 bank) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 CartridgeX07::getBank() const +uInt16 CartridgeX07::getBank(uInt16) const { return myCurrentBank; } @@ -144,8 +144,8 @@ bool CartridgeX07::patch(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8* CartridgeX07::getImage(uInt32& size) const { - size = 65536; - return myImage; + size = myImage.size(); + return myImage.data(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartX07.hxx b/src/emucore/CartX07.hxx index 81959a79b..aeb00138f 100644 --- a/src/emucore/CartX07.hxx +++ b/src/emucore/CartX07.hxx @@ -82,8 +82,10 @@ class CartridgeX07 : public Cartridge /** Get the current bank. + + @param address The address to use when querying the bank */ - uInt16 getBank() const override; + uInt16 getBank(uInt16 address = 0) const override; /** Query the number of banks supported by the cartridge. @@ -161,7 +163,7 @@ class CartridgeX07 : public Cartridge private: // The 64K ROM image of the cartridge - uInt8 myImage[65536]; + std::array myImage; // Indicates which bank is currently active uInt16 myCurrentBank; diff --git a/src/emucore/FBSurface.cxx b/src/emucore/FBSurface.cxx index 669df6f32..988953f26 100644 --- a/src/emucore/FBSurface.cxx +++ b/src/emucore/FBSurface.cxx @@ -45,7 +45,7 @@ void FBSurface::readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect uInt8* src = reinterpret_cast(myPixels + rect.y() * myPitch + rect.x()); if(rect.empty()) - memcpy(buffer, src, width() * height() * 4); + std::copy_n(src, width() * height() * 4, buffer); else { uInt32 w = std::min(rect.w(), width()); @@ -55,7 +55,7 @@ void FBSurface::readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect uInt8* dst = buffer; while(h--) { - memcpy(dst, src, w * 4); + std::copy_n(src, w * 4, dst); src += myPitch * 4; dst += pitch * 4; } diff --git a/src/emucore/M6532.cxx b/src/emucore/M6532.cxx index 044cd1d87..d9bc051a5 100644 --- a/src/emucore/M6532.cxx +++ b/src/emucore/M6532.cxx @@ -57,13 +57,11 @@ void M6532::reset() // Initialize the 128 bytes of memory bool devSettings = mySettings.getBool("dev.settings"); if(mySettings.getString(devSettings ? "dev.console" : "plr.console") == "7800") - for(uInt32 t = 0; t < 128; ++t) - myRAM[t] = RAM_7800[t]; + std::copy_n(RAM_7800, 128, myRAM.begin()); else if(mySettings.getBool(devSettings ? "dev.ramrandom" : "plr.ramrandom")) - for(uInt32 t = 0; t < 128; ++t) - myRAM[t] = mySystem->randGenerator().next(); + for(uInt32 t = 0; t < 128; ++t) myRAM[t] = mySystem->randGenerator().next(); else - memset(myRAM, 0, 128); + myRAM.fill(0); myTimer = mySystem->randGenerator().next() & 0xff; myDivider = 1024; @@ -368,7 +366,7 @@ bool M6532::save(Serializer& out) const { try { - out.putByteArray(myRAM, 128); + out.putByteArray(myRAM.data(), myRAM.size()); out.putInt(myTimer); out.putInt(mySubTimer); @@ -401,7 +399,7 @@ bool M6532::load(Serializer& in) { try { - in.getByteArray(myRAM, 128); + in.getByteArray(myRAM.data(), myRAM.size()); myTimer = in.getInt(); mySubTimer = in.getInt(); @@ -467,15 +465,10 @@ uInt32 M6532::timerClocks() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void M6532::createAccessBases() { - myRAMAccessBase = make_unique(RAM_SIZE); - memset(myRAMAccessBase.get(), CartDebug::NONE, RAM_SIZE); - myStackAccessBase = make_unique(STACK_SIZE); - memset(myStackAccessBase.get(), CartDebug::NONE, STACK_SIZE); - myIOAccessBase = make_unique(IO_SIZE); - memset(myIOAccessBase.get(), CartDebug::NONE, IO_SIZE); - - myZPAccessDelay = make_unique(RAM_SIZE); - memset(myZPAccessDelay.get(), ZP_DELAY, RAM_SIZE); + myRAMAccessBase.fill(CartDebug::NONE); + myStackAccessBase.fill(CartDebug::NONE); + myIOAccessBase.fill(CartDebug::NONE); + myZPAccessDelay.fill(ZP_DELAY); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/M6532.hxx b/src/emucore/M6532.hxx index f6330cba4..2eed285e4 100644 --- a/src/emucore/M6532.hxx +++ b/src/emucore/M6532.hxx @@ -128,7 +128,7 @@ class M6532 : public Device @return Pointer to RAM array. */ - const uInt8* getRAM() const { return myRAM; } + const uInt8* getRAM() const { return myRAM.data(); } private: @@ -169,7 +169,7 @@ class M6532 : public Device const Settings& mySettings; // An amazing 128 bytes of RAM - uInt8 myRAM[128]; + std::array myRAM; // Current value of the timer uInt8 myTimer; @@ -217,19 +217,19 @@ class M6532 : public Device static constexpr uInt8 TimerBit = 0x80, PA7Bit = 0x40; #ifdef DEBUGGER_SUPPORT - // The arrays containing information about every byte of RIOT - // indicating whether and how (RW) it is used. - ByteBuffer myRAMAccessBase; - ByteBuffer myStackAccessBase; - ByteBuffer myIOAccessBase; - // The array used to skip the first ZP access tracking - ByteBuffer myZPAccessDelay; - static constexpr uInt16 RAM_SIZE = 0x80, RAM_MASK = RAM_SIZE - 1, STACK_SIZE = RAM_SIZE, STACK_MASK = RAM_MASK, STACK_BIT = 0x100, IO_SIZE = 0x20, IO_MASK = IO_SIZE - 1, IO_BIT = 0x200, ZP_DELAY = 1; + + // The arrays containing information about every byte of RIOT + // indicating whether and how (RW) it is used. + std::array myRAMAccessBase; + std::array myStackAccessBase; + std::array myIOAccessBase; + // The array used to skip the first ZP access tracking + std::array myZPAccessDelay; #endif // DEBUGGER_SUPPORT private: diff --git a/src/emucore/MT24LC256.cxx b/src/emucore/MT24LC256.cxx index 51eda6c65..59ae4ecff 100644 --- a/src/emucore/MT24LC256.cxx +++ b/src/emucore/MT24LC256.cxx @@ -78,7 +78,7 @@ MT24LC256::MT24LC256(const string& filename, const System& system, if(uInt32(in.tellg()) == FLASH_SIZE) { in.seekg(0, std::ios::beg); - in.read(reinterpret_cast(myData), FLASH_SIZE); + in.read(reinterpret_cast(myData.data()), myData.size()); myDataFileExists = true; } } @@ -99,7 +99,7 @@ MT24LC256::~MT24LC256() { ofstream out(myDataFile, std::ios_base::binary); if(out.is_open()) - out.write(reinterpret_cast(myData), FLASH_SIZE); + out.write(reinterpret_cast(myData.data()), myData.size()); } } @@ -150,13 +150,13 @@ void MT24LC256::update() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::systemReset() { - std::fill(myPageHit, myPageHit + PAGE_NUM, false); + myPageHit.fill(false); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MT24LC256::eraseAll() { - memset(myData, INIT_VALUE, FLASH_SIZE); + myData.fill(INIT_VALUE); myDataChanged = true; } @@ -167,7 +167,7 @@ void MT24LC256::eraseCurrent() { if(myPageHit[page]) { - memset(myData + page * PAGE_SIZE, INIT_VALUE, PAGE_SIZE); + std::fill_n(myData.begin() + page * PAGE_SIZE, PAGE_SIZE, INIT_VALUE); myDataChanged = true; } } @@ -193,7 +193,7 @@ void MT24LC256::jpee_init() jpee_smallmode = 0; jpee_logmode = -1; if(!myDataFileExists) - memset(myData, INIT_VALUE, FLASH_SIZE); + myData.fill(INIT_VALUE); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/MT24LC256.hxx b/src/emucore/MT24LC256.hxx index 533f6662c..2a2009764 100644 --- a/src/emucore/MT24LC256.hxx +++ b/src/emucore/MT24LC256.hxx @@ -94,10 +94,10 @@ class MT24LC256 Controller::onMessageCallback myCallback; // The EEPROM data - uInt8 myData[FLASH_SIZE]; + std::array myData; // Track which pages are used - bool myPageHit[PAGE_NUM]; + std::array myPageHit; // Cached state of the SDA and SCL pins on the last write bool mySDA, mySCL; @@ -125,7 +125,7 @@ class MT24LC256 Int32 jpee_sizemask, jpee_pagemask, jpee_smallmode, jpee_logmode; Int32 jpee_pptr, jpee_state, jpee_nb; uInt32 jpee_address, jpee_ad_known; - uInt8 jpee_packet[70]; + std::array jpee_packet; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 18281ca80..c7bde5422 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -58,7 +58,7 @@ TIASurface::TIASurface(OSystem& system) myBaseTiaSurface = myFB.allocateSurface(TIAConstants::frameBufferWidth*2, TIAConstants::frameBufferHeight); - memset(myRGBFramebuffer, 0, sizeof(myRGBFramebuffer)); + myRGBFramebuffer.fill(0); // Enable/disable threading in the NTSC TV effects renderer myNTSCFilter.enableThreading(myOSystem.settings().getBool("threads")); @@ -216,7 +216,7 @@ void TIASurface::enablePhosphor(bool enable, int blend) myPhosphorPercent = blend / 100.0f; myFilter = Filter(enable ? uInt8(myFilter) | 0x01 : uInt8(myFilter) & 0x10); - memset(myRGBFramebuffer, 0, sizeof(myRGBFramebuffer)); + myRGBFramebuffer.fill(0); // Precalculate the average colors for the 'phosphor' effect if(myUsePhosphor) @@ -266,7 +266,7 @@ void TIASurface::enableNTSC(bool enable) sl_attr.blendalpha = myOSystem.settings().getInt("tv.scanlines"); mySLineSurface->applyAttributes(); - memset(myRGBFramebuffer, 0, sizeof(myRGBFramebuffer)); + myRGBFramebuffer.fill(0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -317,8 +317,7 @@ inline uInt32 TIASurface::averageBuffers(uInt32 bufOfs) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIASurface::render() { - uInt32 width = myTIA->width(); - uInt32 height = myTIA->height(); + uInt32 width = myTIA->width(), height = myTIA->height(); uInt32 *out, outPitch; myTiaSurface->basePtr(out, outPitch); @@ -346,10 +345,11 @@ void TIASurface::render() case Filter::Phosphor: { uInt8* tiaIn = myTIA->frameBuffer(); - uInt32* rgbIn = myRGBFramebuffer; + uInt32* rgbIn = myRGBFramebuffer.data(); if (mySaveSnapFlag) - memcpy(myPrevRGBFramebuffer, myRGBFramebuffer, width * height * sizeof(uInt32)); + std::copy_n(myRGBFramebuffer.begin(), width * height, + myPrevRGBFramebuffer.begin()); uInt32 bufofs = 0, screenofsY = 0, pos; for(uInt32 y = height; y ; --y) @@ -377,9 +377,10 @@ void TIASurface::render() case Filter::BlarggPhosphor: { if(mySaveSnapFlag) - memcpy(myPrevRGBFramebuffer, myRGBFramebuffer, height * outPitch * sizeof(uInt32)); + std::copy_n(myRGBFramebuffer.begin(), height * outPitch, + myPrevRGBFramebuffer.begin()); - myNTSCFilter.render(myTIA->frameBuffer(), width, height, out, outPitch << 2, myRGBFramebuffer); + myNTSCFilter.render(myTIA->frameBuffer(), width, height, out, outPitch << 2, myRGBFramebuffer.data()); break; } } diff --git a/src/emucore/TIASurface.hxx b/src/emucore/TIASurface.hxx index d4f980010..e7d72dfe0 100644 --- a/src/emucore/TIASurface.hxx +++ b/src/emucore/TIASurface.hxx @@ -185,10 +185,10 @@ class TIASurface ///////////////////////////////////////////////////////////// // Phosphor mode items (aka reduced flicker on 30Hz screens) // RGB frame buffer - uInt32 myRGBFramebuffer[AtariNTSC::outWidth(TIAConstants::frameBufferWidth) * - TIAConstants::frameBufferHeight]; - uInt32 myPrevRGBFramebuffer[AtariNTSC::outWidth(TIAConstants::frameBufferWidth) * - TIAConstants::frameBufferHeight]; + std::array myRGBFramebuffer; + std::array myPrevRGBFramebuffer; // Use phosphor effect bool myUsePhosphor; diff --git a/src/emucore/tia/DelayQueue.hxx b/src/emucore/tia/DelayQueue.hxx index e36e9639d..ec7072352 100644 --- a/src/emucore/tia/DelayQueue.hxx +++ b/src/emucore/tia/DelayQueue.hxx @@ -52,7 +52,7 @@ class DelayQueue : public Serializable private: DelayQueueMember myMembers[length]; uInt8 myIndex; - uInt8 myIndices[0xFF]; + std::array myIndices; private: DelayQueue(const DelayQueue&) = delete; @@ -70,7 +70,7 @@ template DelayQueue::DelayQueue() : myIndex(0) { - memset(myIndices, 0xFF, 0xFF); + myIndices.fill(0xFF); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -99,7 +99,7 @@ void DelayQueue::reset() myMembers[i].clear(); myIndex = 0; - memset(myIndices, 0xFF, 0xFF); + myIndices.fill(0xFF); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -131,7 +131,7 @@ bool DelayQueue::save(Serializer& out) const myMembers[i].save(out); out.putByte(myIndex); - out.putByteArray(myIndices, 0xFF); + out.putByteArray(myIndices.data(), myIndices.size()); } catch(...) { @@ -154,7 +154,7 @@ bool DelayQueue::load(Serializer& in) myMembers[i].load(in); myIndex = in.getByte(); - in.getByteArray(myIndices, 0xFF); + in.getByteArray(myIndices.data(), myIndices.size()); } catch(...) { diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 3713cf98c..18c702eba 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -146,7 +146,7 @@ void TIA::reset() myHctrDelta = 0; myXAtRenderingStart = 0; - memset(myShadowRegisters, 0, 64); + myShadowRegisters.fill(0); myBackground.reset(); myPlayfield.reset(); @@ -177,9 +177,9 @@ void TIA::reset() myFramesSinceLastRender = 0; // Blank the various framebuffers; they may contain graphical garbage - memset(myBackBuffer, 0, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); - memset(myFrontBuffer, 0, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); - memset(myFramebuffer, 0, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); + myBackBuffer.fill(0); + myFrontBuffer.fill(0); + myFramebuffer.fill(0); applyDeveloperSettings(); @@ -273,7 +273,7 @@ bool TIA::save(Serializer& out) const out.putLong(myTimestamp); - out.putByteArray(myShadowRegisters, 64); + out.putByteArray(myShadowRegisters.data(), myShadowRegisters.size()); out.putLong(myCyclesAtFrameStart); @@ -344,7 +344,7 @@ bool TIA::load(Serializer& in) myTimestamp = in.getLong(); - in.getByteArray(myShadowRegisters, 64); + in.getByteArray(myShadowRegisters.data(), myShadowRegisters.size()); myCyclesAtFrameStart = in.getLong(); @@ -790,9 +790,9 @@ bool TIA::saveDisplay(Serializer& out) const { try { - out.putByteArray(myFramebuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); - out.putByteArray(myBackBuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); - out.putByteArray(myFrontBuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); + out.putByteArray(myFramebuffer.data(), myFramebuffer.size()); + out.putByteArray(myBackBuffer.data(), myBackBuffer.size()); + out.putByteArray(myFrontBuffer.data(), myFrontBuffer.size()); out.putInt(myFramesSinceLastRender); } catch(...) @@ -810,9 +810,9 @@ bool TIA::loadDisplay(Serializer& in) try { // Reset frame buffer pointer and data - in.getByteArray(myFramebuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); - in.getByteArray(myBackBuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); - in.getByteArray(myFrontBuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); + in.getByteArray(myFramebuffer.data(), myFramebuffer.size()); + in.getByteArray(myBackBuffer.data(), myBackBuffer.size()); + in.getByteArray(myFrontBuffer.data(), myFrontBuffer.size()); myFramesSinceLastRender = in.getInt(); } catch(...) @@ -885,7 +885,7 @@ void TIA::renderToFrameBuffer() myFramesSinceLastRender = 0; - memcpy(myFramebuffer, myFrontBuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); + myFramebuffer = myFrontBuffer; myFrameBufferScanlines = myFrontBufferScanlines; } @@ -1225,14 +1225,14 @@ void TIA::onFrameComplete() myCyclesAtFrameStart = mySystem->cycles(); if (myXAtRenderingStart > 0) - memset(myBackBuffer, 0, myXAtRenderingStart); + std::fill_n(myBackBuffer.begin(), myXAtRenderingStart, 0); // Blank out any extra lines not drawn this frame const Int32 missingScanlines = myFrameManager->missingScanlines(); if (missingScanlines > 0) - memset(myBackBuffer + TIAConstants::H_PIXEL * myFrameManager->getY(), 0, missingScanlines * TIAConstants::H_PIXEL); + std::fill_n(myBackBuffer.begin() + TIAConstants::H_PIXEL * myFrameManager->getY(), missingScanlines * TIAConstants::H_PIXEL, 0); - memcpy(myFrontBuffer, myBackBuffer, TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight); + myFrontBuffer = myBackBuffer; myFrontBufferScanlines = scanlinesLastFrame(); @@ -1355,7 +1355,7 @@ void TIA::applyRsync() myHctrDelta = TIAConstants::H_CLOCKS - 3 - myHctr; if (myFrameManager->isRendering()) - memset(myBackBuffer + myFrameManager->getY() * TIAConstants::H_PIXEL + x, 0, TIAConstants::H_PIXEL - x); + std::fill_n(myBackBuffer.begin() + myFrameManager->getY() * TIAConstants::H_PIXEL + x, TIAConstants::H_PIXEL - x, 0); myHctr = TIAConstants::H_CLOCKS - 3; } @@ -1394,9 +1394,8 @@ void TIA::cloneLastLine() if (!myFrameManager->isRendering() || y == 0) return; - uInt8* buffer = myBackBuffer; - - memcpy(buffer + y * TIAConstants::H_PIXEL, buffer + (y-1) * TIAConstants::H_PIXEL, TIAConstants::H_PIXEL); + std::copy_n(myBackBuffer.begin() + (y-1) * TIAConstants::H_PIXEL, TIAConstants::H_PIXEL, + myBackBuffer.begin() + y * TIAConstants::H_PIXEL); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1499,7 +1498,7 @@ void TIA::flushLineCache() void TIA::clearHmoveComb() { if (myFrameManager->isRendering() && myHstate == HState::blank) - memset(myBackBuffer + myFrameManager->getY() * TIAConstants::H_PIXEL, myColorHBlank, 8); + std::fill_n(myBackBuffer.begin() + myFrameManager->getY() * TIAConstants::H_PIXEL, 8, myColorHBlank); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1867,10 +1866,8 @@ void TIA::toggleCollBLPF() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::createAccessBase() { - myAccessBase = make_unique(TIA_SIZE); - memset(myAccessBase.get(), CartDebug::NONE, TIA_SIZE); - myAccessDelay = make_unique(TIA_SIZE); - memset(myAccessDelay.get(), TIA_DELAY, TIA_SIZE); + myAccessBase.fill(CartDebug::NONE); + myAccessDelay.fill(TIA_DELAY); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 6c7f1aaee..aab7a483e 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -237,12 +237,12 @@ class TIA : public Device Return the buffer that holds the currently drawing TIA frame (the TIA output widget needs this). */ - uInt8* outputBuffer() { return myBackBuffer; } + uInt8* outputBuffer() { return myBackBuffer.data(); } /** Returns a pointer to the internal frame buffer. */ - uInt8* frameBuffer() { return static_cast(myFramebuffer); } + uInt8* frameBuffer() { return myFramebuffer.data(); } /** Answers dimensional info about the framebuffer. @@ -743,12 +743,12 @@ class TIA : public Device LatchedInput myInput1; // Pointer to the internal color-index-based frame buffer - uInt8 myFramebuffer[TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight]; + std::array myFramebuffer; // The frame is rendered to the backbuffer and only copied to the framebuffer // upon completion - uInt8 myBackBuffer[TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight]; - uInt8 myFrontBuffer[TIAConstants::H_PIXEL * TIAConstants::frameBufferHeight]; + std::array myBackBuffer; + std::array myFrontBuffer; // We snapshot frame statistics when the back buffer is copied to the front buffer // and when the front buffer is copied to the frame buffer @@ -859,7 +859,7 @@ class TIA : public Device * The "shadow registers" track the last written register value for the * debugger. */ - uInt8 myShadowRegisters[64]; + std::array myShadowRegisters; /** * Indicates if color loss should be enabled or disabled. Color loss @@ -880,18 +880,18 @@ class TIA : public Device bool myEnableJitter; uInt8 myJitterFactor; + static constexpr uInt16 + TIA_SIZE = 0x40, TIA_MASK = TIA_SIZE - 1, TIA_READ_MASK = 0x0f, TIA_BIT = 0x080, TIA_DELAY = 2; + #ifdef DEBUGGER_SUPPORT // The arrays containing information about every byte of TIA // indicating whether and how (RW) it is used. - ByteBuffer myAccessBase; + std::array myAccessBase; // The array used to skip the first two TIA access trackings - ByteBuffer myAccessDelay; + std::array myAccessDelay; #endif // DEBUGGER_SUPPORT - static constexpr uInt16 - TIA_SIZE = 0x40, TIA_MASK = TIA_SIZE - 1, TIA_READ_MASK = 0x0f, TIA_BIT = 0x080, TIA_DELAY = 2; - private: TIA() = delete; TIA(const TIA&) = delete;