From 48d1a6a3216b36499bb1cbfabf579f8482792468 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 28 Mar 2022 22:00:26 -0230 Subject: [PATCH] Second pass at fixing warning from Visual Studio (const and C-style casts). --- src/common/ZipHandler.hxx | 52 ++--- src/common/repository/KeyValueRepository.hxx | 9 +- src/emucore/AmigaMouse.hxx | 7 + src/emucore/AtariMouse.hxx | 7 + src/emucore/AtariVox.cxx | 4 +- src/emucore/Bankswitch.cxx | 10 +- src/emucore/Booster.cxx | 3 +- src/emucore/Cart.cxx | 25 ++- src/emucore/Cart0840.cxx | 6 +- src/emucore/Cart3E.cxx | 6 +- src/emucore/Cart3F.cxx | 2 +- src/emucore/Cart4A50.cxx | 6 +- src/emucore/CartAR.cxx | 18 +- src/emucore/CartAR.hxx | 2 +- src/emucore/CartARM.cxx | 2 +- src/emucore/CartBUS.cxx | 44 ++-- src/emucore/CartCDF.cxx | 56 +++--- src/emucore/CartCM.hxx | 2 +- src/emucore/CartCTY.cxx | 25 ++- src/emucore/CartCreator.cxx | 2 +- src/emucore/CartDPC.cxx | 39 ++-- src/emucore/CartDPCPlus.cxx | 43 ++-- src/emucore/CartDetector.cxx | 80 ++++---- src/emucore/CartE7.cxx | 12 +- src/emucore/CartEnhanced.cxx | 16 +- src/emucore/CartEnhanced.hxx | 2 +- src/emucore/CartF0.cxx | 2 +- src/emucore/CartFA2.cxx | 2 +- src/emucore/CartFE.cxx | 4 +- src/emucore/CartMDM.cxx | 6 +- src/emucore/CartMVC.cxx | 22 +- src/emucore/CartSB.cxx | 7 +- src/emucore/CartTVBoy.cxx | 2 +- src/emucore/CartUA.cxx | 8 +- src/emucore/CartWD.cxx | 2 +- src/emucore/CartX07.cxx | 6 +- src/emucore/Console.cxx | 55 ++--- src/emucore/ConsoleIO.hxx | 7 + src/emucore/Control.cxx | 13 +- src/emucore/ControllerDetector.cxx | 189 +++++++++--------- src/emucore/Driving.cxx | 22 +- src/emucore/Driving.hxx | 4 +- src/emucore/EmulationTiming.cxx | 12 +- src/emucore/EmulationWorker.cxx | 2 +- src/emucore/EventHandler.cxx | 38 ++-- src/emucore/FBSurface.cxx | 21 +- src/emucore/FSNode.cxx | 2 +- src/emucore/FSNode.hxx | 7 +- src/emucore/FrameBuffer.cxx | 79 ++++---- src/emucore/FrameBuffer.hxx | 2 +- src/emucore/GlobalKeyHandler.cxx | 37 ++-- src/emucore/Joystick.cxx | 6 +- src/emucore/Keyboard.cxx | 6 +- src/emucore/KidVid.cxx | 2 +- src/emucore/Lightgun.cxx | 14 +- src/emucore/M6502.cxx | 37 ++-- src/emucore/M6532.cxx | 25 ++- src/emucore/MD5.cxx | 67 +++---- src/emucore/MT24LC256.cxx | 4 +- src/emucore/OSystem.cxx | 24 +-- src/emucore/Paddles.cxx | 10 +- src/emucore/PlusROM.cxx | 10 +- src/emucore/PointingDevice.cxx | 8 +- src/emucore/ProfilingRunner.cxx | 21 +- src/emucore/ProfilingRunner.hxx | 2 +- src/emucore/Props.cxx | 6 +- src/emucore/Props.hxx | 6 + src/emucore/PropsSet.cxx | 12 +- src/emucore/Serializer.cxx | 8 +- src/emucore/Settings.cxx | 12 +- src/emucore/System.cxx | 16 +- src/emucore/TIASurface.cxx | 53 +++-- src/emucore/Thumbulator.cxx | 28 +-- src/emucore/TrakBall.hxx | 7 + src/emucore/exception/EmulationWarning.hxx | 2 +- src/emucore/exception/FatalEmulationError.hxx | 2 +- src/emucore/tia/AnalogReadout.cxx | 8 +- src/emucore/tia/Audio.cxx | 25 ++- src/emucore/tia/AudioChannel.cxx | 7 +- src/emucore/tia/Ball.cxx | 3 +- src/emucore/tia/DrawCounterDecodes.cxx | 4 +- src/emucore/tia/Player.cxx | 2 +- src/emucore/tia/Playfield.cxx | 6 +- src/emucore/tia/TIA.cxx | 71 ++++--- .../frame-manager/AbstractFrameManager.cxx | 2 +- .../tia/frame-manager/FrameLayoutDetector.cxx | 4 +- .../tia/frame-manager/FrameManager.cxx | 14 +- .../tia/frame-manager/JitterEmulation.cxx | 4 +- src/gui/Command.hxx | 16 ++ src/windows/Stella.vcxproj | 22 +- src/windows/Stella.vcxproj.filters | 6 + 91 files changed, 843 insertions(+), 770 deletions(-) diff --git a/src/common/ZipHandler.hxx b/src/common/ZipHandler.hxx index 6fea0e97e..8d248c1fc 100644 --- a/src/common/ZipHandler.hxx +++ b/src/common/ZipHandler.hxx @@ -149,7 +149,7 @@ class ZipHandler class ReaderBase { protected: - explicit ReaderBase(const uInt8* const b) : myBuf(b) { } + explicit ReaderBase(const uInt8* const b) : myBuf{b} { } uInt8 read_byte(size_t offs) const { @@ -157,26 +157,26 @@ class ZipHandler } uInt16 read_word(size_t offs) const { - return (uInt16(myBuf[offs + 1]) << 8) | - (uInt16(myBuf[offs + 0]) << 0); + return (static_cast(myBuf[offs + 1]) << 8) | + (static_cast(myBuf[offs + 0]) << 0); } uInt32 read_dword(std::size_t offs) const { - return (uInt32(myBuf[offs + 3]) << 24) | - (uInt32(myBuf[offs + 2]) << 16) | - (uInt32(myBuf[offs + 1]) << 8) | - (uInt32(myBuf[offs + 0]) << 0); + return (static_cast(myBuf[offs + 3]) << 24) | + (static_cast(myBuf[offs + 2]) << 16) | + (static_cast(myBuf[offs + 1]) << 8) | + (static_cast(myBuf[offs + 0]) << 0); } uInt64 read_qword(size_t offs) const { - return (uInt64(myBuf[offs + 7]) << 56) | - (uInt64(myBuf[offs + 6]) << 48) | - (uInt64(myBuf[offs + 5]) << 40) | - (uInt64(myBuf[offs + 4]) << 32) | - (uInt64(myBuf[offs + 3]) << 24) | - (uInt64(myBuf[offs + 2]) << 16) | - (uInt64(myBuf[offs + 1]) << 8) | - (uInt64(myBuf[offs + 0]) << 0); + return (static_cast(myBuf[offs + 7]) << 56) | + (static_cast(myBuf[offs + 6]) << 48) | + (static_cast(myBuf[offs + 5]) << 40) | + (static_cast(myBuf[offs + 4]) << 32) | + (static_cast(myBuf[offs + 3]) << 24) | + (static_cast(myBuf[offs + 2]) << 16) | + (static_cast(myBuf[offs + 1]) << 8) | + (static_cast(myBuf[offs + 0]) << 0); } string read_string(size_t offs, size_t len = string::npos) const { @@ -269,18 +269,18 @@ class ZipHandler class GeneralFlagReader { public: - explicit GeneralFlagReader(uInt16 val) : myValue(val) { } + explicit GeneralFlagReader(uInt16 val) : myValue{val} { } - bool encrypted() const { return bool(myValue & 0x0001); } - bool implode8kDict() const { return bool(myValue & 0x0002); } - bool implode3Trees() const { return bool(myValue & 0x0004); } - uInt32 deflateOption() const { return uInt32((myValue >> 1) & 0x0003); } - bool lzmaEosMark() const { return bool(myValue & 0x0002); } - bool useDescriptor() const { return bool(myValue & 0x0008); } - bool patchData() const { return bool(myValue & 0x0020); } - bool strongEncryption() const { return bool(myValue & 0x0040); } - bool utf8Encoding() const { return bool(myValue & 0x0800); } - bool directoryEncryption() const { return bool(myValue & 0x2000); } + bool encrypted() const { return static_cast(myValue & 0x0001); } + bool implode8kDict() const { return static_cast(myValue & 0x0002); } + bool implode3Trees() const { return static_cast(myValue & 0x0004); } + uInt32 deflateOption() const { return static_cast((myValue >> 1) & 0x0003); } + bool lzmaEosMark() const { return static_cast(myValue & 0x0002); } + bool useDescriptor() const { return static_cast(myValue & 0x0008); } + bool patchData() const { return static_cast(myValue & 0x0020); } + bool strongEncryption() const { return static_cast(myValue & 0x0040); } + bool utf8Encoding() const { return static_cast(myValue & 0x0800); } + bool directoryEncryption() const { return static_cast(myValue & 0x2000); } private: uInt16 myValue{0}; diff --git a/src/common/repository/KeyValueRepository.hxx b/src/common/repository/KeyValueRepository.hxx index 6e21f416e..9aa52ada6 100644 --- a/src/common/repository/KeyValueRepository.hxx +++ b/src/common/repository/KeyValueRepository.hxx @@ -28,7 +28,7 @@ class KeyValueRepositoryAtomic; class KeyValueRepository { public: - + KeyValueRepository() = default; virtual ~KeyValueRepository() = default; virtual std::map load() = 0; @@ -36,6 +36,13 @@ class KeyValueRepository virtual bool save(const std::map& values) = 0; virtual KeyValueRepositoryAtomic* atomic() { return nullptr; } + + private: + // Following constructors and assignment operators not supported + KeyValueRepository(const KeyValueRepository&) = delete; + KeyValueRepository(KeyValueRepository&&) = delete; + KeyValueRepository& operator=(const KeyValueRepository&) = delete; + KeyValueRepository& operator=(KeyValueRepository&&) = delete; }; class KeyValueRepositoryAtomic : public KeyValueRepository { diff --git a/src/emucore/AmigaMouse.hxx b/src/emucore/AmigaMouse.hxx index 98e1a6136..1295b3603 100644 --- a/src/emucore/AmigaMouse.hxx +++ b/src/emucore/AmigaMouse.hxx @@ -54,6 +54,13 @@ class AmigaMouse : public PointingDevice } static constexpr float trackballSensitivity = 0.8F; + + private: + // Following constructors and assignment operators not supported + AmigaMouse(const AmigaMouse&) = delete; + AmigaMouse(AmigaMouse&&) = delete; + AmigaMouse& operator=(const AmigaMouse&) = delete; + AmigaMouse& operator=(AmigaMouse&&) = delete; }; #endif // AMIGAMOUSE_HXX diff --git a/src/emucore/AtariMouse.hxx b/src/emucore/AtariMouse.hxx index 08fe6a4b4..fa98e1e5d 100644 --- a/src/emucore/AtariMouse.hxx +++ b/src/emucore/AtariMouse.hxx @@ -54,6 +54,13 @@ class AtariMouse : public PointingDevice } static constexpr float trackballSensitivity = 0.8F; + + private: + // Following constructors and assignment operators not supported + AtariMouse(const AtariMouse&) = delete; + AtariMouse(AtariMouse&&) = delete; + AtariMouse& operator=(const AtariMouse&) = delete; + AtariMouse& operator=(AtariMouse&&) = delete; }; #endif // ATARIMOUSE_HXX diff --git a/src/emucore/AtariVox.cxx b/src/emucore/AtariVox.cxx index 6bf6e4145..3ed388430 100644 --- a/src/emucore/AtariVox.cxx +++ b/src/emucore/AtariVox.cxx @@ -109,7 +109,7 @@ void AtariVox::clockDataIn(bool value) // If this is the first write this frame, or if it's been a long time // since the last write, start a new data byte. - uInt64 cycle = mySystem.cycles(); + const uInt64 cycle = mySystem.cycles(); if((cycle < myLastDataWriteCycle) || (cycle > myLastDataWriteCycle + 1000)) { myShiftRegister = 0; @@ -132,7 +132,7 @@ void AtariVox::clockDataIn(bool value) cerr << "AtariVox: bad stop bit" << endl; else { - uInt8 data = ((myShiftRegister >> 1) & 0xff); + const uInt8 data = ((myShiftRegister >> 1) & 0xff); mySerialPort->writeByte(data); } myShiftRegister = 0; diff --git a/src/emucore/Bankswitch.cxx b/src/emucore/Bankswitch.cxx index 15efba212..4457857e1 100644 --- a/src/emucore/Bankswitch.cxx +++ b/src/emucore/Bankswitch.cxx @@ -26,7 +26,7 @@ string Bankswitch::typeToName(Bankswitch::Type type) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Bankswitch::Type Bankswitch::nameToType(const string& name) { - auto it = ourNameToTypes.find(name); + const auto it = ourNameToTypes.find(name); if(it != ourNameToTypes.end()) return it->second; @@ -43,10 +43,10 @@ string Bankswitch::typeToDesc(Bankswitch::Type type) Bankswitch::Type Bankswitch::typeFromExtension(const FilesystemNode& file) { const string& name = file.getPath(); - string::size_type idx = name.find_last_of('.'); + const string::size_type idx = name.find_last_of('.'); if(idx != string::npos) { - auto it = ourExtensions.find(name.c_str() + idx + 1); + const auto it = ourExtensions.find(name.c_str() + idx + 1); if(it != ourExtensions.end()) return it->second; } @@ -57,11 +57,11 @@ Bankswitch::Type Bankswitch::typeFromExtension(const FilesystemNode& file) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Bankswitch::isValidRomName(const string& name, string& ext) { - string::size_type idx = name.find_last_of('.'); + const string::size_type idx = name.find_last_of('.'); if(idx != string::npos) { const char* const e = name.c_str() + idx + 1; - auto it = ourExtensions.find(e); + const auto it = ourExtensions.find(e); if(it != ourExtensions.end()) { ext = e; diff --git a/src/emucore/Booster.cxx b/src/emucore/Booster.cxx index 4024a58d4..6abb6f76f 100644 --- a/src/emucore/Booster.cxx +++ b/src/emucore/Booster.cxx @@ -42,7 +42,7 @@ void BoosterGrip::updateButtons() bool firePressed = myEvent.get(myFireEvent) != 0; // The CBS Booster-grip has two more buttons on it. These buttons are // connected to the inputs usually used by paddles. - bool triggerPressed = myEvent.get(myTriggerEvent) != 0; + const bool triggerPressed = myEvent.get(myTriggerEvent) != 0; bool boosterPressed = myEvent.get(myBoosterEvent) != 0; updateMouseButtons(firePressed, boosterPressed); @@ -51,4 +51,3 @@ void BoosterGrip::updateButtons() setPin(AnalogPin::Five, triggerPressed ? AnalogReadout::connectToVcc() : AnalogReadout::disconnect()); setPin(AnalogPin::Nine, boosterPressed ? AnalogReadout::connectToVcc() : AnalogReadout::disconnect()); } - diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index 8fa6da622..8f6362753 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -30,12 +30,12 @@ Cartridge::Cartridge(const Settings& settings, const string& md5) : mySettings{settings} { - auto to_uInt32 = [](const string& s, uInt32 pos) { + const auto to_uInt32 = [](const string& s, uInt32 pos) { return uInt32(std::stoul(s.substr(pos, 8), nullptr, 16)); }; - uInt32 seed = to_uInt32(md5, 0) ^ to_uInt32(md5, 8) ^ - to_uInt32(md5, 16) ^ to_uInt32(md5, 24); + const uInt32 seed = to_uInt32(md5, 0) ^ to_uInt32(md5, 8) ^ + to_uInt32(md5, 16) ^ to_uInt32(md5, 24); Random rand(seed); for(uInt32 i = 0; i < 256; ++i) myRWPRandomValues[i] = rand.next(); @@ -77,7 +77,7 @@ bool Cartridge::saveROM(const FilesystemNode& out) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge::bankChanged() { - bool changed = myBankChanged; + const bool changed = myBankChanged; myBankChanged = false; return changed; } @@ -132,7 +132,7 @@ void Cartridge::pokeRAM(uInt8& dest, uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge::createRomAccessArrays(size_t size) { - myAccessSize = uInt32(size); + myAccessSize = static_cast(size); #ifdef DEBUGGER_SUPPORT myRomAccessBase = make_unique(size); std::fill_n(myRomAccessBase.get(), size, Device::ROW); @@ -153,8 +153,8 @@ string Cartridge::getAccessCounters() const for(uInt16 bank = 0; bank < romBankCount(); ++bank) { - uInt16 origin = bankOrigin(bank); - uInt16 bankSize = this->bankSize(bank); + const uInt16 origin = bankOrigin(bank); + const uInt16 bankSize = this->bankSize(bank); out << "Bank " << Common::Base::toString(bank, Common::Base::Fmt::_10_8) << " / 0.." << Common::Base::toString(romBankCount() - 1, Common::Base::Fmt::_10_8) << " reads:\n"; @@ -185,13 +185,12 @@ uInt16 Cartridge::bankOrigin(uInt16 bank) const // isolate the high 3 address bits, count them and // select the most frequent to define the bank origin // TODO: origin for banks smaller than 4K - const int intervals = 0x8000 / 0x100; - uInt32 offset = bank * bankSize(); + constexpr int intervals = 0x8000 / 0x100; + const uInt32 offset = bank * bankSize(); //uInt16 addrMask = (4_KB - 1) & ~(bankSize(bank) - 1); //int addrShift = 0; std::array count; // up to 128 256 byte interval origins - //if(addrMask) // addrShift = log(addrMask) / log(2); //addrMask; @@ -199,7 +198,7 @@ uInt16 Cartridge::bankOrigin(uInt16 bank) const count.fill(0); for(uInt16 addr = 0x0000; addr < bankSize(bank); ++addr) { - Device::AccessFlags flags = myRomAccessBase[offset + addr]; + const Device::AccessFlags flags = myRomAccessBase[offset + addr]; // only count really accessed addresses if(flags & ~Device::ROW) { @@ -233,14 +232,14 @@ void Cartridge::initializeRAM(uInt8* arr, size_t size, uInt8 val) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt16 Cartridge::initializeStartBank(uInt16 defaultBank) { - int propsBank = myStartBankFromPropsFunc(); + const int propsBank = myStartBankFromPropsFunc(); if(randomStartBank()) return myStartBank = mySystem->randGenerator().next() % romBankCount(); else if(propsBank >= 0) return myStartBank = BSPF::clamp(propsBank, 0, romBankCount() - 1); else - return myStartBank = BSPF::clamp(int(defaultBank), 0, romBankCount() - 1); + return myStartBank = BSPF::clamp(static_cast(defaultBank), 0, romBankCount() - 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart0840.cxx b/src/emucore/Cart0840.cxx index 1a2d9fcf3..f85c73157 100644 --- a/src/emucore/Cart0840.cxx +++ b/src/emucore/Cart0840.cxx @@ -43,7 +43,7 @@ void Cartridge0840::install(System& system) myHotSpotPageAccess[7] = mySystem->getPageAccess(0x0F00); // Set the page accessing methods for the hot spots - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x0800; addr < 0x0FFF; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); } @@ -77,7 +77,7 @@ uInt8 Cartridge0840::peek(uInt16 address) // Because of the way we've set up accessing above, we can only // get here when the addresses are from 0x800 - 0xFFF - int hotspot = ((address & 0x0F00) >> 8) - 8; + const int hotspot = ((address & 0x0F00) >> 8) - 8; return myHotSpotPageAccess[hotspot].device->peek(address); } @@ -90,7 +90,7 @@ bool Cartridge0840::poke(uInt16 address, uInt8 value) // doing a write to 0x800 - 0xFFF or cart; we ignore the cart write if(!(address & 0x1000)) { - int hotspot = ((address & 0x0F00) >> 8) - 8; + const int hotspot = ((address & 0x0F00) >> 8) - 8; myHotSpotPageAccess[hotspot].device->poke(address, value); } diff --git a/src/emucore/Cart3E.cxx b/src/emucore/Cart3E.cxx index 8692f138e..7b737487c 100644 --- a/src/emucore/Cart3E.cxx +++ b/src/emucore/Cart3E.cxx @@ -37,7 +37,7 @@ void Cartridge3E::install(System& system) { CartridgeEnhanced::install(system); - System::PageAccess access(this, System::PageAccessType::WRITE); + const System::PageAccess access(this, System::PageAccessType::WRITE); // The hotspots ($3E and $3F) are in TIA address space, so we claim it here for(uInt16 addr = 0x00; addr < 0x40; addr += System::PAGE_SIZE) @@ -65,7 +65,7 @@ bool Cartridge3E::checkSwitchBank(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 Cartridge3E::peek(uInt16 address) { - uInt16 peekAddress = address; + const uInt16 peekAddress = address; address &= ROM_MASK; if(address < 0x0040) // TIA access @@ -77,7 +77,7 @@ uInt8 Cartridge3E::peek(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Cartridge3E::poke(uInt16 address, uInt8 value) { - uInt16 pokeAddress = address; + const uInt16 pokeAddress = address; address &= ROM_MASK; if(address < 0x0040) // TIA access diff --git a/src/emucore/Cart3F.cxx b/src/emucore/Cart3F.cxx index 28293218d..32461ebc7 100644 --- a/src/emucore/Cart3F.cxx +++ b/src/emucore/Cart3F.cxx @@ -34,7 +34,7 @@ void Cartridge3F::install(System& system) { CartridgeEnhanced::install(system); - System::PageAccess access(this, System::PageAccessType::READWRITE); + const System::PageAccess access(this, System::PageAccessType::READWRITE); // The hotspot ($3F) is in TIA address space, so we claim it here for(uInt16 addr = 0x00; addr < 0x40; addr += System::PAGE_SIZE) diff --git a/src/emucore/Cart4A50.cxx b/src/emucore/Cart4A50.cxx index 3f5e0676a..46ce05e32 100644 --- a/src/emucore/Cart4A50.cxx +++ b/src/emucore/Cart4A50.cxx @@ -65,7 +65,7 @@ void Cartridge4A50::install(System& system) mySystem = &system; // Map all of the accesses to call peek and poke (We don't yet indicate RAM areas) - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x1000; addr < 0x2000; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); @@ -83,7 +83,7 @@ uInt8 Cartridge4A50::peek(uInt16 address) if(!(address & 0x1000)) // Hotspots below 0x1000 { // Check for RAM or TIA mirroring - uInt16 lowAddress = address & 0x3ff; + const uInt16 lowAddress = address & 0x3ff; if(lowAddress & 0x80) value = mySystem->m6532().peek(address); else if(!(lowAddress & 0x200)) @@ -130,7 +130,7 @@ bool Cartridge4A50::poke(uInt16 address, uInt8 value) if(!(address & 0x1000)) // Hotspots below 0x1000 { // Check for RAM or TIA mirroring - uInt16 lowAddress = address & 0x3ff; + const uInt16 lowAddress = address & 0x3ff; if(lowAddress & 0x80) mySystem->m6532().poke(address, value); else if(!(lowAddress & 0x200)) diff --git a/src/emucore/CartAR.cxx b/src/emucore/CartAR.cxx index f0e0816ed..91e483397 100644 --- a/src/emucore/CartAR.cxx +++ b/src/emucore/CartAR.cxx @@ -28,7 +28,7 @@ CartridgeAR::CartridgeAR(const ByteBuffer& image, size_t size, { // Create a load image buffer and copy the given image myLoadImages = make_unique(mySize); - myNumberOfLoadImages = uInt8(mySize / LOAD_SIZE); + myNumberOfLoadImages = static_cast(mySize / LOAD_SIZE); std::copy_n(image.get(), size, myLoadImages.get()); // Add header if image doesn't include it @@ -75,7 +75,7 @@ void CartridgeAR::install(System& system) mySystem = &system; // Map all of the accesses to call peek and poke (we don't yet indicate RAM areas) - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x1000; addr < 0x2000; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); @@ -94,7 +94,7 @@ uInt8 CartridgeAR::peek(uInt16 addr) if(((addr & 0x1FFF) == 0x1850) && (myImageOffset[1] == RAM_SIZE)) { // Get load that's being accessed (BIOS places load number at 0x80) - uInt8 load = mySystem->peek(0x0080); + const uInt8 load = mySystem->peek(0x0080); // Read the specified load into RAM loadIntoRAM(load); @@ -113,7 +113,7 @@ uInt8 CartridgeAR::peek(uInt16 addr) // Is the data hold register being set? if(!(addr & 0x0F00) && (!myWriteEnabled || !myWritePending)) { - myDataHoldRegister = uInt8(addr); // FIXME - check cast here + myDataHoldRegister = static_cast(addr); // FIXME - check cast here myNumberOfDistinctAccesses = mySystem->m6502().distinctAccesses(); myWritePending = true; } @@ -160,7 +160,7 @@ bool CartridgeAR::poke(uInt16 addr, uInt8) // Is the data hold register being set? if(!(addr & 0x0F00) && (!myWriteEnabled || !myWritePending)) { - myDataHoldRegister = uInt8(addr); // FIXME - check cast here + myDataHoldRegister = static_cast(addr); // FIXME - check cast here myNumberOfDistinctAccesses = mySystem->m6502().distinctAccesses(); myWritePending = true; } @@ -277,7 +277,7 @@ void CartridgeAR::initializeROM() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 CartridgeAR::checksum(uInt8* s, uInt16 length) +uInt8 CartridgeAR::checksum(const uInt8* s, uInt16 length) { uInt8 sum = 0; @@ -316,8 +316,8 @@ void CartridgeAR::loadIntoRAM(uInt8 load) { uInt32 bank = myHeader[16 + j] & 0b00011; uInt32 page = (myHeader[16 + j] & 0b11100) >> 2; - uInt8* src = myLoadImages.get() + (image * LOAD_SIZE) + (j * 256); - uInt8 sum = checksum(src, 256) + myHeader[16 + j] + myHeader[64 + j]; + const uInt8* const src = myLoadImages.get() + (image * LOAD_SIZE) + (j * 256); + const uInt8 sum = checksum(src, 256) + myHeader[16 + j] + myHeader[64 + j]; if(!invalidPageChecksumSeen && (sum != 0x55)) { @@ -355,7 +355,7 @@ void CartridgeAR::loadIntoRAM(uInt8 load) bool CartridgeAR::bank(uInt16 bank, uInt16) { if(!hotspotsLocked()) - return bankConfiguration(uInt8(bank)); + return bankConfiguration(static_cast(bank)); else return false; } diff --git a/src/emucore/CartAR.hxx b/src/emucore/CartAR.hxx index 98085a7d2..88e78520a 100644 --- a/src/emucore/CartAR.hxx +++ b/src/emucore/CartAR.hxx @@ -187,7 +187,7 @@ class CartridgeAR : public Cartridge bool bankConfiguration(uInt8 configuration); // Compute the sum of the array of bytes - uInt8 checksum(uInt8* s, uInt16 length); + uInt8 checksum(const uInt8* s, uInt16 length); // Load the specified load into SC RAM void loadIntoRAM(uInt8 load); diff --git a/src/emucore/CartARM.cxx b/src/emucore/CartARM.cxx index 713923e44..98e43d0f8 100644 --- a/src/emucore/CartARM.cxx +++ b/src/emucore/CartARM.cxx @@ -35,7 +35,7 @@ void CartridgeARM::reset() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeARM::setInitialState() { - bool devSettings = mySettings.getBool("dev.settings"); + const bool devSettings = mySettings.getBool("dev.settings"); if(devSettings) { diff --git a/src/emucore/CartBUS.cxx b/src/emucore/CartBUS.cxx index aae86c48b..dce63195b 100644 --- a/src/emucore/CartBUS.cxx +++ b/src/emucore/CartBUS.cxx @@ -123,7 +123,7 @@ void CartridgeBUS::install(System& system) mySystem = &system; // Map all of the accesses to call peek and poke - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x1000; addr < 0x1040; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); @@ -140,13 +140,13 @@ void CartridgeBUS::install(System& system) inline void CartridgeBUS::updateMusicModeDataFetchers() { // Calculate the number of cycles since the last update - uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles); + const uInt32 cycles = static_cast(mySystem->cycles() - myAudioCycles); myAudioCycles = mySystem->cycles(); // Calculate the number of BUS OSC clocks since the last update - double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; - uInt32 wholeClocks = uInt32(clocks); - myFractionalClocks = clocks - double(wholeClocks); + const double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; + uInt32 wholeClocks = static_cast(clocks); + myFractionalClocks = clocks - static_cast(wholeClocks); // Let's update counters and flags of the music mode data fetchers if(wholeClocks > 0) @@ -164,7 +164,7 @@ inline void CartridgeBUS::callFunction(uInt8 value) // time for Stella as ARM code "runs in zero 6507 cycles". case 255: // call without IRQ driven audio try { - uInt32 cycles = uInt32(mySystem->cycles() - myARMCycles); + uInt32 cycles = static_cast(mySystem->cycles() - myARMCycles); myARMCycles = mySystem->cycles(); myThumbEmulator->run(cycles, value == 254); @@ -188,7 +188,7 @@ uInt8 CartridgeBUS::peek(uInt16 address) if(!(address & 0x1000)) // Hotspots below 0x1000 { // Check for RAM or TIA mirroring - uInt16 lowAddress = address & 0x3ff; + const uInt16 lowAddress = address & 0x3ff; if(lowAddress & 0x80) return mySystem->m6532().peek(address); else if(!(lowAddress & 0x200)) @@ -209,14 +209,11 @@ uInt8 CartridgeBUS::peek(uInt16 address) if (myFastJumpActive && myJMPoperandAddress == address) { - uInt32 pointer; - uInt8 value; - --myFastJumpActive; ++myJMPoperandAddress; - pointer = getDatastreamPointer(JUMPSTREAM); - value = myDisplayImage[ pointer >> 20 ]; + uInt32 pointer = getDatastreamPointer(JUMPSTREAM); + const uInt8 value = myDisplayImage[pointer >> 20]; pointer += 0x100000; // always increment by 1 setDatastreamPointer(JUMPSTREAM, pointer); @@ -251,7 +248,7 @@ uInt8 CartridgeBUS::peek(uInt16 address) if DIGITAL_AUDIO_ON { // retrieve packed sample (max size is 2K, or 4K of unpacked data) - uInt32 sampleaddress = getSample() + (myMusicCounters[0] >> 21); + const uInt32 sampleaddress = getSample() + (myMusicCounters[0] >> 21); // get sample value from ROM or RAM if (sampleaddress < 0x8000) @@ -270,11 +267,12 @@ uInt8 CartridgeBUS::peek(uInt16 address) { // using myDisplayImage[] instead of myProgramImage[] because waveforms // can be modified during runtime. - uInt32 i = myDisplayImage[(getWaveform(0) ) + (myMusicCounters[0] >> myMusicWaveformSize[0])] + - myDisplayImage[(getWaveform(1) ) + (myMusicCounters[1] >> myMusicWaveformSize[1])] + - myDisplayImage[(getWaveform(2) ) + (myMusicCounters[2] >> myMusicWaveformSize[2])]; + const uInt32 i = + myDisplayImage[(getWaveform(0) ) + (myMusicCounters[0] >> myMusicWaveformSize[0])] + + myDisplayImage[(getWaveform(1) ) + (myMusicCounters[1] >> myMusicWaveformSize[1])] + + myDisplayImage[(getWaveform(2) ) + (myMusicCounters[2] >> myMusicWaveformSize[2])]; - peekvalue = uInt8(i); + peekvalue = static_cast(i); } break; @@ -346,7 +344,7 @@ bool CartridgeBUS::poke(uInt16 address, uInt8 value) value &= busOverdrive(address); // Check for RAM or TIA mirroring - uInt16 lowAddress = address & 0x3ff; + const uInt16 lowAddress = address & 0x3ff; if(lowAddress & 0x80) mySystem->m6532().poke(address, value); else if(!(lowAddress & 0x200)) @@ -354,7 +352,7 @@ bool CartridgeBUS::poke(uInt16 address, uInt8 value) } else { - uInt32 pointer; + uInt32 pointer = 0; address &= 0x0FFF; @@ -495,11 +493,11 @@ uInt8 CartridgeBUS::busOverdrive(uInt16 address) // only overdrive if the address matches if (address == myBusOverdriveAddress) { - uInt8 map = address & 0x7f; + const uInt8 map = address & 0x7f; if (map <= 0x24) // map TIA registers VSYNC thru HMBL inclusive { uInt32 alldatastreams = getAddressMap(map); - uInt8 datastream = alldatastreams & 0x0f; // lowest nybble has the current datastream to use + const uInt8 datastream = alldatastreams & 0x0f; // lowest nybble has the current datastream to use overdrive = readFromDatastream(datastream); // rotate map nybbles for next time @@ -758,8 +756,8 @@ uInt8 CartridgeBUS::readFromDatastream(uInt8 index) // F = Fractional uInt32 pointer = getDatastreamPointer(index); - uInt16 increment = getDatastreamIncrement(index); - uInt8 value = myDisplayImage[ pointer >> 20 ]; + const uInt16 increment = getDatastreamIncrement(index); + const uInt8 value = myDisplayImage[pointer >> 20]; pointer += (increment << 12); setDatastreamPointer(index, pointer); return value; diff --git a/src/emucore/CartCDF.cxx b/src/emucore/CartCDF.cxx index 1c81ff681..acbb8610e 100644 --- a/src/emucore/CartCDF.cxx +++ b/src/emucore/CartCDF.cxx @@ -87,7 +87,7 @@ CartridgeCDF::CartridgeCDF(const ByteBuffer& image, size_t size, myDisplayImage = myRAM.data() + 2_KB; // C addresses - uInt32 cBase, cStart, cStack; + uInt32 cBase = 0, cStart = 0, cStack = 0; if (isCDFJplus()) { cBase = getUInt32(myImage.get(), 0x17F8) & 0xFFFFFFFE; // C Base Address cStart = cBase; // C Start Address @@ -163,7 +163,7 @@ void CartridgeCDF::install(System& system) mySystem = &system; // Map all of the accesses to call peek and poke - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x1000; addr < 0x1040; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); @@ -175,13 +175,13 @@ void CartridgeCDF::install(System& system) inline void CartridgeCDF::updateMusicModeDataFetchers() { // Calculate the number of cycles since the last update - uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles); + const uInt32 cycles = static_cast(mySystem->cycles() - myAudioCycles); myAudioCycles = mySystem->cycles(); // Calculate the number of CDF OSC clocks since the last update - double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; - uInt32 wholeClocks = uInt32(clocks); - myFractionalClocks = clocks - double(wholeClocks); + const double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; + uInt32 wholeClocks = static_cast(clocks); + myFractionalClocks = clocks - static_cast(wholeClocks); // Let's update counters and flags of the music mode data fetchers if(wholeClocks > 0) @@ -199,7 +199,7 @@ inline void CartridgeCDF::callFunction(uInt8 value) // time for Stella as ARM code "runs in zero 6507 cycles". case 255: // call without IRQ driven audio try { - uInt32 cycles = uInt32(mySystem->cycles() - myARMCycles); + uInt32 cycles = static_cast(mySystem->cycles() - myARMCycles); myARMCycles = mySystem->cycles(); myThumbEmulator->run(cycles, value == 254); @@ -240,13 +240,11 @@ uInt8 CartridgeCDF::peek(uInt16 address) if (myFastJumpActive && myJMPoperandAddress == address) { - uInt32 pointer; - uInt8 value; - --myFastJumpActive; ++myJMPoperandAddress; - pointer = getDatastreamPointer(myFastJumpStream); + uInt32 pointer = getDatastreamPointer(myFastJumpStream); + uInt8 value = 0; if (isCDFJplus()) { value = myDisplayImage[ pointer >> 16 ]; pointer += 0x00010000; // always increment by 1 @@ -278,7 +276,7 @@ uInt8 CartridgeCDF::peek(uInt16 address) // 1) in Fast Fetch mode // 2) peeking the operand of an LDA # instruction // 3) peek value is between myDSfetcherOffset and myDSfetcherOffset+34 inclusive - bool fastfetch; + bool fastfetch = false; if (myFastFetcherOffset) fastfetch = (FAST_FETCH_ON(myMode) && myLDAXYimmediateOperandAddress == address && peekvalue >= myRAM[myFastFetcherOffset] @@ -299,7 +297,7 @@ uInt8 CartridgeCDF::peek(uInt16 address) { // retrieve packed sample (max size is 2K, or 4K of unpacked data) - uInt32 sampleaddress = getSample() + (myMusicCounters[0] >> (isCDFJplus() ? 13 : 21)); + const uInt32 sampleaddress = getSample() + (myMusicCounters[0] >> (isCDFJplus() ? 13 : 21)); // get sample value from ROM or RAM if (sampleaddress < 0x00080000) @@ -650,7 +648,7 @@ bool CartridgeCDF::load(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::getDatastreamPointer(uInt8 index) const { - uInt16 address = myDatastreamBase + index * 4; + const uInt16 address = myDatastreamBase + index * 4; return myRAM[address + 0] + // low byte (myRAM[address + 1] << 8) + @@ -661,7 +659,7 @@ uInt32 CartridgeCDF::getDatastreamPointer(uInt8 index) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCDF::setDatastreamPointer(uInt8 index, uInt32 value) { - uInt16 address = myDatastreamBase + index * 4; + const uInt16 address = myDatastreamBase + index * 4; myRAM[address + 0] = value & 0xff; // low byte myRAM[address + 1] = (value >> 8) & 0xff; @@ -672,7 +670,7 @@ void CartridgeCDF::setDatastreamPointer(uInt8 index, uInt32 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::getDatastreamIncrement(uInt8 index) const { - uInt16 address = myDatastreamIncrementBase + index * 4; + const uInt16 address = myDatastreamIncrementBase + index * 4; return myRAM[address + 0] + // low byte (myRAM[address + 1] << 8) + @@ -683,14 +681,14 @@ uInt32 CartridgeCDF::getDatastreamIncrement(uInt8 index) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::getWaveform(uInt8 index) const { - uInt16 address = myWaveformBase + index * 4; + const uInt16 address = myWaveformBase + index * 4; uInt32 result = myRAM[address + 0] + // low byte (myRAM[address + 1] << 8) + (myRAM[address + 2] << 16) + (myRAM[address + 3] << 24); // high byte - result -= (0x40000000 + uInt32(2_KB)); + result -= (0x40000000 + static_cast(2_KB)); if (!isCDFJplus()) { if (result >= 4096) { @@ -703,12 +701,12 @@ uInt32 CartridgeCDF::getWaveform(uInt8 index) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::getSample() { - uInt16 address = myWaveformBase; + const uInt16 address = myWaveformBase; - uInt32 result = myRAM[address + 0] + // low byte - (myRAM[address + 1] << 8) + - (myRAM[address + 2] << 16) + - (myRAM[address + 3] << 24); // high byte + const uInt32 result = myRAM[address + 0] + // low byte + (myRAM[address + 1] << 8) + + (myRAM[address + 2] << 16) + + (myRAM[address + 3] << 24); // high byte return result; } @@ -733,9 +731,9 @@ uInt8 CartridgeCDF::readFromDatastream(uInt8 index) // F = Fractional uInt32 pointer = getDatastreamPointer(index); - uInt16 increment = getDatastreamIncrement(index); + const uInt16 increment = getDatastreamIncrement(index); - uInt8 value; + uInt8 value = 0; if (isCDFJplus()) { value = myDisplayImage[ pointer >> 16 ]; @@ -786,9 +784,9 @@ void CartridgeCDF::setupVersion() myFastFetcherOffset = 0; myWaveformBase = 0x01b0; - for (int i=0; i<2048; i += 4) + for (int i = 0; i < 2048; i += 4) { - uInt32 cdfjValue = getUInt32(myImage.get(), i); + const uInt32 cdfjValue = getUInt32(myImage.get(), i); if (cdfjValue == 0x135200A2) myLDXenabled = true; if (cdfjValue == 0x135200A0) @@ -877,13 +875,13 @@ bool CartridgeCDF::isCDFJplus() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::ramSize() const { - return uInt32(isCDFJplus() ? 32_KB : 8_KB); + return static_cast(isCDFJplus() ? 32_KB : 8_KB); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeCDF::romSize() const { - return uInt32(isCDFJplus() ? mySize : 32_KB); + return static_cast(isCDFJplus() ? mySize : 32_KB); } #ifdef DEBUGGER_SUPPORT diff --git a/src/emucore/CartCM.hxx b/src/emucore/CartCM.hxx index c6cf91ba8..e9df66af9 100644 --- a/src/emucore/CartCM.hxx +++ b/src/emucore/CartCM.hxx @@ -249,7 +249,7 @@ class CartridgeCM : public Cartridge ByteBuffer myImage; // The 2K of RAM - std::array myRAM; + std::array myRAM{0}; // Current copy of SWCHA (controls ROM/RAM accesses) uInt8 mySWCHA{0xFF}; // Port A all 1's diff --git a/src/emucore/CartCTY.cxx b/src/emucore/CartCTY.cxx index 54aa9b3c4..fbc685845 100644 --- a/src/emucore/CartCTY.cxx +++ b/src/emucore/CartCTY.cxx @@ -86,7 +86,7 @@ void CartridgeCTY::install(System& system) mySystem = &system; // Map all RAM accesses to call peek and poke - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); @@ -97,9 +97,9 @@ void CartridgeCTY::install(System& system) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CartridgeCTY::peek(uInt16 address) { - uInt16 peekAddress = address; + const uInt16 peekAddress = address; address &= 0x0FFF; - uInt8 peekValue = myImage[myBankOffset + address]; + const uInt8 peekValue = myImage[myBankOffset + address]; // In debugger/bank-locked mode, we ignore all hotspots and in general // anything that can change the internal state of the cart @@ -190,7 +190,7 @@ uInt8 CartridgeCTY::peek(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeCTY::poke(uInt16 address, uInt8 value) { - uInt16 pokeAddress = address; + const uInt16 pokeAddress = address; address &= 0x0FFF; if(address < 0x0040) // Write port is at $1000 - $103F (64 bytes) @@ -389,7 +389,7 @@ uInt8 CartridgeCTY::ramReadWrite() { // Opcode and value in form of XXXXYYYY (from myOperationType), where: // XXXX = index and YYYY = operation - uInt8 index = myOperationType >> 4; + const uInt8 index = myOperationType >> 4; switch(myOperationType & 0xf) { case 1: // Load tune (index = tune) @@ -421,6 +421,9 @@ uInt8 CartridgeCTY::ramReadWrite() myRamAccessTimeout = TimerManager::getTicks() + 1000000; wipeAllScores(); break; + + default: // satisfy compiler + break; } // Bit 6 is 1, busy return myImage[myBankOffset + 0xFF4] | 0x40; @@ -489,7 +492,7 @@ void CartridgeCTY::updateTune() // b NewAddress myTunePosition += 1; - uInt16 songPosition = (myTunePosition - 1) *3; + const uInt16 songPosition = (myTunePosition - 1) *3; uInt8 note = myFrequencyImage[songPosition + 0]; if (note) @@ -556,7 +559,7 @@ void CartridgeCTY::saveScore(uInt8 index) catch(...) { // Maybe add logging here that save failed? - cerr << name() << ": ERROR saving score table " << int(index) << endl; + cerr << name() << ": ERROR saving score table " << static_cast(index) << endl; } } } @@ -585,13 +588,13 @@ void CartridgeCTY::wipeAllScores() inline void CartridgeCTY::updateMusicModeDataFetchers() { // Calculate the number of cycles since the last update - uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles); + const uInt32 cycles = static_cast(mySystem->cycles() - myAudioCycles); myAudioCycles = mySystem->cycles(); // Calculate the number of CTY OSC clocks since the last update - double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; - uInt32 wholeClocks = uInt32(clocks); - myFractionalClocks = clocks - double(wholeClocks); + const double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; + const uInt32 wholeClocks = static_cast(clocks); + myFractionalClocks = clocks - static_cast(wholeClocks); // Let's update counters and flags of the music mode data fetchers if(wholeClocks > 0) diff --git a/src/emucore/CartCreator.cxx b/src/emucore/CartCreator.cxx index 27efa3f75..fbf601da3 100644 --- a/src/emucore/CartCreator.cxx +++ b/src/emucore/CartCreator.cxx @@ -83,7 +83,7 @@ unique_ptr CartCreator::create(const FilesystemNode& file, // First inspect the file extension itself // If a valid type is found, it will override the one passed into this method - Bankswitch::Type typeByName = Bankswitch::typeFromExtension(file); + const Bankswitch::Type typeByName = Bankswitch::typeFromExtension(file); if(typeByName != Bankswitch::Type::_AUTO) type = detectedType = typeByName; diff --git a/src/emucore/CartDPC.cxx b/src/emucore/CartDPC.cxx index f80ffea66..8c28974c8 100644 --- a/src/emucore/CartDPC.cxx +++ b/src/emucore/CartDPC.cxx @@ -67,7 +67,7 @@ void CartridgeDPC::install(System& system) createRomAccessArrays(8_KB); // Set the page accessing method for the DPC reading & writing pages - System::PageAccess access(this, System::PageAccessType::READWRITE); + const System::PageAccess access(this, System::PageAccessType::READWRITE); for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); } @@ -83,7 +83,7 @@ inline void CartridgeDPC::clockRandomNumberGenerator() // Using bits 7, 5, 4, & 3 of the shift register compute the input // bit for the shift register - uInt8 bit = f[((myRandomNumber >> 3) & 0x07) | + const uInt8 bit = f[((myRandomNumber >> 3) & 0x07) | ((myRandomNumber & 0x80) ? 0x08 : 0x00)]; // Update the shift register @@ -94,13 +94,13 @@ inline void CartridgeDPC::clockRandomNumberGenerator() inline void CartridgeDPC::updateMusicModeDataFetchers() { // Calculate the number of cycles since the last update - uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles); + const uInt32 cycles = static_cast(mySystem->cycles() - myAudioCycles); myAudioCycles = mySystem->cycles(); // Calculate the number of DPC OSC clocks since the last update - double clocks = ((myDpcPitch * cycles) / myClockRate) + myFractionalClocks; - uInt32 wholeClocks = uInt32(clocks); - myFractionalClocks = clocks - double(wholeClocks); + const double clocks = ((myDpcPitch * cycles) / myClockRate) + myFractionalClocks; + const uInt32 wholeClocks = static_cast(clocks); + myFractionalClocks = clocks - static_cast(wholeClocks); if(wholeClocks == 0) return; @@ -111,8 +111,8 @@ inline void CartridgeDPC::updateMusicModeDataFetchers() // Update only if the data fetcher is in music mode if(myMusicMode[x - 5]) { - Int32 top = myTops[x] + 1; - Int32 newLow = Int32(myCounters[x] & 0x00ff); + const Int32 top = myTops[x] + 1; + Int32 newLow = static_cast(myCounters[x] & 0x00ff); if(myTops[x] != 0) { @@ -129,7 +129,7 @@ inline void CartridgeDPC::updateMusicModeDataFetchers() else if(newLow <= myTops[x]) myFlags[x] = 0xff; - myCounters[x] = (myCounters[x] & 0x0700) | uInt16(newLow); + myCounters[x] = (myCounters[x] & 0x0700) | static_cast(newLow); } } } @@ -137,7 +137,7 @@ inline void CartridgeDPC::updateMusicModeDataFetchers() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CartridgeDPC::peek(uInt16 address) { - uInt16 peekAddress = address; + const uInt16 peekAddress = address; address &= 0x0FFF; @@ -146,7 +146,6 @@ uInt8 CartridgeDPC::peek(uInt16 address) if(hotspotsLocked()) return myImage[myCurrentSegOffset[0] + address]; - // Clock the random number generator. This should be done for every // cartridge access, however, we're only doing it for the DPC and // hot-spot accesses to save time. @@ -157,8 +156,8 @@ uInt8 CartridgeDPC::peek(uInt16 address) uInt8 result = 0; // Get the index of the data fetcher that's being accessed - uInt32 index = address & 0x07; - uInt32 function = (address >> 3) & 0x07; + const uInt32 index = address & 0x07; + const uInt32 function = (address >> 3) & 0x07; // Update flag register for selected data fetcher if((myCounters[index] & 0x00ff) == myTops[index]) @@ -250,7 +249,7 @@ uInt8 CartridgeDPC::peek(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeDPC::poke(uInt16 address, uInt8 value) { - uInt16 pokeAddress = address; + const uInt16 pokeAddress = address; address &= 0x0FFF; @@ -262,8 +261,8 @@ bool CartridgeDPC::poke(uInt16 address, uInt8 value) if((address >= 0x0040) && (address < 0x0080)) { // Get the index of the data fetcher that's being accessed - uInt32 index = address & 0x07; - uInt32 function = (address >> 3) & 0x07; + const uInt32 index = address & 0x07; + const uInt32 function = (address >> 3) & 0x07; switch(function) { @@ -290,14 +289,14 @@ bool CartridgeDPC::poke(uInt16 address, uInt8 value) // Data fetcher is in music mode so its low counter value // should be loaded from the top register not the poked value myCounters[index] = (myCounters[index] & 0x0700) | - uInt16(myTops[index]); + static_cast(myTops[index]); } else { // Data fetcher is either not a music mode data fetcher or it // isn't in music mode so it's low counter value should be loaded // with the poked value - myCounters[index] = (myCounters[index] & 0x0700) | uInt16(value); + myCounters[index] = (myCounters[index] & 0x0700) | static_cast(value); } break; } @@ -305,7 +304,7 @@ bool CartridgeDPC::poke(uInt16 address, uInt8 value) // DFx counter high case 0x03: { - myCounters[index] = ((uInt16(value) & 0x07) << 8) | + myCounters[index] = ((static_cast(value) & 0x07) << 8) | (myCounters[index] & 0x00ff); // Execute special code for music mode data fetchers @@ -328,9 +327,7 @@ bool CartridgeDPC::poke(uInt16 address, uInt8 value) } default: - { break; - } } } else diff --git a/src/emucore/CartDPCPlus.cxx b/src/emucore/CartDPCPlus.cxx index eb32e5eb2..75031c770 100644 --- a/src/emucore/CartDPCPlus.cxx +++ b/src/emucore/CartDPCPlus.cxx @@ -136,7 +136,7 @@ void CartridgeDPCPlus::install(System& system) mySystem = &system; // Map all of the accesses to call peek and poke - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); @@ -165,13 +165,13 @@ inline void CartridgeDPCPlus::priorClockRandomNumberGenerator() inline void CartridgeDPCPlus::updateMusicModeDataFetchers() { // Calculate the number of cycles since the last update - uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles); + const uInt32 cycles = static_cast(mySystem->cycles() - myAudioCycles); myAudioCycles = mySystem->cycles(); // Calculate the number of DPC+ OSC clocks since the last update - double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; - uInt32 wholeClocks = uInt32(clocks); - myFractionalClocks = clocks - double(wholeClocks); + const double clocks = ((20000.0 * cycles) / myClockRate) + myFractionalClocks; + const uInt32 wholeClocks = static_cast(clocks); + myFractionalClocks = clocks - static_cast(wholeClocks); // Let's update counters and flags of the music mode data fetchers if(wholeClocks > 0) @@ -183,7 +183,7 @@ inline void CartridgeDPCPlus::updateMusicModeDataFetchers() inline void CartridgeDPCPlus::callFunction(uInt8 value) { // myParameter - uInt16 ROMdata = (myParameter[1] << 8) + myParameter[0]; + const uInt16 ROMdata = (myParameter[1] << 8) + myParameter[0]; switch (value) { case 0: // Parameter Pointer reset @@ -204,7 +204,7 @@ inline void CartridgeDPCPlus::callFunction(uInt8 value) // time for Stella as ARM code "runs in zero 6507 cycles". case 255: // call without IRQ driven audio try { - uInt32 cycles = uInt32(mySystem->cycles() - myARMCycles); + uInt32 cycles = static_cast(mySystem->cycles() - myARMCycles); myARMCycles = mySystem->cycles(); myThumbEmulator->run(cycles, value == 254); @@ -235,8 +235,7 @@ uInt8 CartridgeDPCPlus::peek(uInt16 address) address &= 0x0FFF; - uInt8 peekvalue = myProgramImage[myBankOffset + address]; - uInt8 flag; + const uInt8 peekvalue = myProgramImage[myBankOffset + address]; // In debugger/bank-locked mode, we ignore all hotspots and in general // anything that can change the internal state of the cart @@ -257,11 +256,11 @@ uInt8 CartridgeDPCPlus::peek(uInt16 address) uInt8 result = 0; // Get the index of the data fetcher that's being accessed - uInt32 index = address & 0x07; - uInt32 function = (address >> 3) & 0x07; + const uInt32 index = address & 0x07; + const uInt32 function = (address >> 3) & 0x07; // Update flag for selected data fetcher - flag = (((myTops[index]-(myCounters[index] & 0x00ff)) & 0xFF) > ((myTops[index]-myBottoms[index]) & 0xFF)) ? 0xFF : 0; + const uInt8 flag = (((myTops[index]-(myCounters[index] & 0x00ff)) & 0xFF) > ((myTops[index]-myBottoms[index]) & 0xFF)) ? 0xFF : 0; switch(function) { @@ -298,11 +297,12 @@ uInt8 CartridgeDPCPlus::peek(uInt16 address) // using myDisplayImage[] instead of myProgramImage[] because waveforms // can be modified during runtime. - uInt32 i = myDisplayImage[(myMusicWaveforms[0] << 5) + (myMusicCounters[0] >> 27)] + - myDisplayImage[(myMusicWaveforms[1] << 5) + (myMusicCounters[1] >> 27)] + - myDisplayImage[(myMusicWaveforms[2] << 5) + (myMusicCounters[2] >> 27)]; + const uInt32 i = + myDisplayImage[(myMusicWaveforms[0] << 5) + (myMusicCounters[0] >> 27)] + + myDisplayImage[(myMusicWaveforms[1] << 5) + (myMusicCounters[1] >> 27)] + + myDisplayImage[(myMusicWaveforms[2] << 5) + (myMusicCounters[2] >> 27)]; - result = uInt8(i); + result = static_cast(i); break; } @@ -429,20 +429,21 @@ bool CartridgeDPCPlus::poke(uInt16 address, uInt8 value) if((address >= 0x0028) && (address < 0x0080)) { // Get the index of the data fetcher that's being accessed - uInt32 index = address & 0x07; - uInt32 function = ((address - 0x28) >> 3) & 0x0f; + const uInt32 index = address & 0x07; + const uInt32 function = ((address - 0x28) >> 3) & 0x0f; switch(function) { // DFxFRACLOW - fractional data pointer low byte case 0x00: myFractionalCounters[index] = - (myFractionalCounters[index] & myFractionalLowMask) | (uInt16(value) << 8); + (myFractionalCounters[index] & myFractionalLowMask) | (static_cast(value) << 8); break; // DFxFRACHI - fractional data pointer high byte case 0x01: - myFractionalCounters[index] = ((uInt16(value) & 0x0F) << 16) | (myFractionalCounters[index] & 0x00ffff); + myFractionalCounters[index] = ((static_cast(value) & 0x0F) << 16) | + (myFractionalCounters[index] & 0x00ffff); break; //DFxFRACINC - Fractional Increment amount @@ -508,7 +509,7 @@ bool CartridgeDPCPlus::poke(uInt16 address, uInt8 value) // DFxHI - data pointer high byte case 0x08: { - myCounters[index] = ((uInt16(value) & 0x0F) << 8) | (myCounters[index] & 0x00ff); + myCounters[index] = ((static_cast(value) & 0x0F) << 8) | (myCounters[index] & 0x00ff); break; } diff --git a/src/emucore/CartDetector.cxx b/src/emucore/CartDetector.cxx index 4a98f6eba..73116ba5d 100644 --- a/src/emucore/CartDetector.cxx +++ b/src/emucore/CartDetector.cxx @@ -54,12 +54,12 @@ Bankswitch::Type CartDetector::autodetectType(const ByteBuffer& image, size_t si else if(size == 8_KB) { // First check for *potential* F8 - uInt8 signature[2][3] = { + static constexpr uInt8 signature[2][3] = { { 0x8D, 0xF9, 0x1F }, // STA $1FF9 { 0x8D, 0xF9, 0xFF } // STA $FFF9 }; - bool f8 = searchForBytes(image, size, signature[0], 3, 2) || - searchForBytes(image, size, signature[1], 3, 2); + const bool f8 = searchForBytes(image, size, signature[0], 3, 2) || + searchForBytes(image, size, signature[1], 3, 2); if(isProbablySC(image, size)) type = Bankswitch::Type::_F8SC; @@ -309,7 +309,7 @@ bool CartDetector::isProbablyARM(const ByteBuffer& image, size_t size) { // ARM code contains the following 'loader' patterns in the first 1K // Thanks to Thomas Jentzsch of AtariAge for this advice - uInt8 signature[2][4] = { + static constexpr uInt8 signature[2][4] = { { 0xA0, 0xC1, 0x1F, 0xE0 }, { 0x00, 0x80, 0x02, 0xE0 } }; @@ -324,7 +324,7 @@ bool CartDetector::isProbably0840(const ByteBuffer& image, size_t size) { // 0840 cart bankswitching is triggered by accessing addresses 0x0800 // or 0x0840 at least twice - uInt8 signature1[3][3] = { + static constexpr uInt8 signature1[3][3] = { { 0xAD, 0x00, 0x08 }, // LDA $0800 { 0xAD, 0x40, 0x08 }, // LDA $0840 { 0x2C, 0x00, 0x08 } // BIT $0800 @@ -333,7 +333,7 @@ bool CartDetector::isProbably0840(const ByteBuffer& image, size_t size) if(searchForBytes(image, size, signature1[i], 3, 2)) return true; - uInt8 signature2[2][4] = { + static constexpr uInt8 signature2[2][4] = { { 0x0C, 0x00, 0x08, 0x4C }, // NOP $0800; JMP ... { 0x0C, 0xFF, 0x0F, 0x4C } // NOP $0FFF; JMP ... }; @@ -353,8 +353,8 @@ bool CartDetector::isProbably3E(const ByteBuffer& image, size_t size) // We expect the latter will be present at least 2 times, since there // are at least two banks - uInt8 signature1[] = { 0x85, 0x3E }; // STA $3E - uInt8 signature2[] = { 0x85, 0x3F }; // STA $3F + static constexpr uInt8 signature1[] = { 0x85, 0x3E }; // STA $3E + static constexpr uInt8 signature2[] = { 0x85, 0x3F }; // STA $3F return searchForBytes(image, size, signature1, 2) && searchForBytes(image, size, signature2, 2, 2); } @@ -363,7 +363,7 @@ bool CartDetector::isProbably3E(const ByteBuffer& image, size_t size) bool CartDetector::isProbably3EX(const ByteBuffer& image, size_t size) { // 3EX cart have at least 2 occurrences of the string "3EX" - uInt8 _3EX[] = { '3', 'E', 'X'}; + static constexpr uInt8 _3EX[] = { '3', 'E', 'X'}; return searchForBytes(image, size, _3EX, 3, 2); } @@ -371,7 +371,7 @@ bool CartDetector::isProbably3EX(const ByteBuffer& image, size_t size) bool CartDetector::isProbably3EPlus(const ByteBuffer& image, size_t size) { // 3E+ cart is identified key 'TJ3E' in the ROM - uInt8 tj3e[] = { 'T', 'J', '3', 'E' }; + static constexpr uInt8 tj3e[] = { 'T', 'J', '3', 'E' }; return searchForBytes(image, size, tj3e, 4); } @@ -382,7 +382,7 @@ bool CartDetector::isProbably3F(const ByteBuffer& image, size_t size) // in address 3F using 'STA $3F' // We expect it will be present at least 2 times, since there are // at least two banks - uInt8 signature[] = { 0x85, 0x3F }; // STA $3F + static constexpr uInt8 signature[] = { 0x85, 0x3F }; // STA $3F return searchForBytes(image, size, signature, 2, 2); } @@ -410,7 +410,7 @@ bool CartDetector::isProbably4KSC(const ByteBuffer& image, size_t size) // We check if the first 256 bytes are identical *and* if there's // an "SC" signature for one of our larger SC types at 1FFA. - uInt8 first = image[0]; + const uInt8 first = image[0]; for(uInt32 i = 1; i < 256; ++i) if(image[i] != first) return false; @@ -427,8 +427,8 @@ bool CartDetector::isProbablyBF(const ByteBuffer& image, size_t size, { // BF carts store strings 'BFBF' and 'BFSC' starting at address $FFF8 // This signature is attributed to "RevEng" of AtariAge - uInt8 bf[] = { 'B', 'F', 'B', 'F' }; - uInt8 bfsc[] = { 'B', 'F', 'S', 'C' }; + static constexpr uInt8 bf[] = { 'B', 'F', 'B', 'F' }; + static constexpr uInt8 bfsc[] = { 'B', 'F', 'S', 'C' }; if(searchForBytes(image.get()+size-8, 8, bf, 4)) { type = Bankswitch::Type::_BF; @@ -449,7 +449,7 @@ bool CartDetector::isProbablyBUS(const ByteBuffer& image, size_t size) // BUS ARM code has 2 occurrences of the string BUS // Note: all Harmony/Melody custom drivers also contain the value // 0x10adab1e (LOADABLE) if needed for future improvement - uInt8 bus[] = { 'B', 'U', 'S'}; + static constexpr uInt8 bus[] = { 'B', 'U', 'S'}; return searchForBytes(image, size, bus, 3, 2); } @@ -459,8 +459,8 @@ bool CartDetector::isProbablyCDF(const ByteBuffer& image, size_t size) // CDF ARM code has 3 occurrences of the string CDF // Note: all Harmony/Melody custom drivers also contain the value // 0x10adab1e (LOADABLE) if needed for future improvement - uInt8 cdf[] = { 'C', 'D', 'F' }; - uInt8 cdfjplus[] = { 'P', 'L', 'U', 'S', 'C', 'D', 'F', 'J' }; + static constexpr uInt8 cdf[] = { 'C', 'D', 'F' }; + static constexpr uInt8 cdfjplus[] = { 'P', 'L', 'U', 'S', 'C', 'D', 'F', 'J' }; return (searchForBytes(image, size, cdf, 3, 3) || searchForBytes(image, size, cdfjplus, 8, 1)); } @@ -468,7 +468,7 @@ bool CartDetector::isProbablyCDF(const ByteBuffer& image, size_t size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartDetector::isProbablyCTY(const ByteBuffer& image, size_t size) { - uInt8 lenin[] = { 'L', 'E', 'N', 'I', 'N' }; + static constexpr uInt8 lenin[] = { 'L', 'E', 'N', 'I', 'N' }; return searchForBytes(image, size, lenin, 5); } @@ -477,7 +477,7 @@ bool CartDetector::isProbablyCV(const ByteBuffer& image, size_t size) { // CV RAM access occurs at addresses $f3ff and $f400 // These signatures are attributed to the MESS project - uInt8 signature[2][3] = { + static constexpr uInt8 signature[2][3] = { { 0x9D, 0xFF, 0xF3 }, // STA $F3FF.X { 0x99, 0x00, 0xF4 } // STA $F400.Y }; @@ -494,8 +494,8 @@ bool CartDetector::isProbablyDF(const ByteBuffer& image, size_t size, // DF carts store strings 'DFDF' and 'DFSC' starting at address $FFF8 // This signature is attributed to "RevEng" of AtariAge - uInt8 df[] = { 'D', 'F', 'D', 'F' }; - uInt8 dfsc[] = { 'D', 'F', 'S', 'C' }; + static constexpr uInt8 df[] = { 'D', 'F', 'D', 'F' }; + static constexpr uInt8 dfsc[] = { 'D', 'F', 'S', 'C' }; if(searchForBytes(image.get()+size-8, 8, df, 4)) { type = Bankswitch::Type::_DF; @@ -516,7 +516,7 @@ bool CartDetector::isProbablyDPCplus(const ByteBuffer& image, size_t size) // DPC+ ARM code has 2 occurrences of the string DPC+ // Note: all Harmony/Melody custom drivers also contain the value // 0x10adab1e (LOADABLE) if needed for future improvement - uInt8 dpcp[] = { 'D', 'P', 'C', '+' }; + static constexpr uInt8 dpcp[] = { 'D', 'P', 'C', '+' }; return searchForBytes(image, size, dpcp, 4, 2); } @@ -529,7 +529,7 @@ bool CartDetector::isProbablyE0(const ByteBuffer& image, size_t size) // search for only certain known signatures // Thanks to "stella@casperkitty.com" for this advice // These signatures are attributed to the MESS project - uInt8 signature[8][3] = { + static constexpr uInt8 signature[8][3] = { { 0x8D, 0xE0, 0x1F }, // STA $1FE0 { 0x8D, 0xE0, 0x5F }, // STA $5FE0 { 0x8D, 0xE9, 0xFF }, // STA $FFE9 @@ -555,7 +555,7 @@ bool CartDetector::isProbablyE7(const ByteBuffer& image, size_t size) // search for only certain known signatures // Thanks to "stella@casperkitty.com" for this advice // These signatures are attributed to the MESS project - uInt8 signature[7][3] = { + static constexpr uInt8 signature[7][3] = { { 0xAD, 0xE2, 0xFF }, // LDA $FFE2 { 0xAD, 0xE5, 0xFF }, // LDA $FFE5 { 0xAD, 0xE5, 0x1F }, // LDA $1FE5 @@ -578,7 +578,7 @@ bool CartDetector::isProbablyE78K(const ByteBuffer& image, size_t size) // $FE4 to $FE6 using absolute non-indexed addressing // To eliminate false positives (and speed up processing), we // search for only certain known signatures - uInt8 signature[3][3] = { + static constexpr uInt8 signature[3][3] = { { 0xAD, 0xE4, 0xFF }, // LDA $FFE4 { 0xAD, 0xE5, 0xFF }, // LDA $FFE5 { 0xAD, 0xE6, 0xFF }, // LDA $FFE6 @@ -596,8 +596,8 @@ bool CartDetector::isProbablyEF(const ByteBuffer& image, size_t size, { // Newer EF carts store strings 'EFEF' and 'EFSC' starting at address $FFF8 // This signature is attributed to "RevEng" of AtariAge - uInt8 efef[] = { 'E', 'F', 'E', 'F' }; - uInt8 efsc[] = { 'E', 'F', 'S', 'C' }; + static constexpr uInt8 efef[] = { 'E', 'F', 'E', 'F' }; + static constexpr uInt8 efsc[] = { 'E', 'F', 'S', 'C' }; if(searchForBytes(image.get()+size-8, 8, efef, 4)) { type = Bankswitch::Type::_EF; @@ -613,7 +613,7 @@ bool CartDetector::isProbablyEF(const ByteBuffer& image, size_t size, // 0xFE0 to 0xFEF, usually with either a NOP or LDA // It's likely that the code will switch to bank 0, so that's what is tested bool isEF = false; - uInt8 signature[4][3] = { + static constexpr uInt8 signature[4][3] = { { 0x0C, 0xE0, 0xFF }, // NOP $FFE0 { 0xAD, 0xE0, 0xFF }, // LDA $FFE0 { 0x0C, 0xE0, 0x1F }, // NOP $1FE0 @@ -658,7 +658,7 @@ bool CartDetector::isProbablyFA2(const ByteBuffer& image, size_t) bool CartDetector::isProbablyFC(const ByteBuffer& image, size_t size) { // FC bankswitching uses consecutive writes to 3 hotspots - uInt8 signature[3][6] = { + static constexpr uInt8 signature[3][6] = { { 0x8d, 0xf8, 0x1f, 0x4a, 0x4a, 0x8d }, // STA $1FF8, LSR, LSR, STA... Power Play Arcade Menus, 3-D Ghost Attack { 0x8d, 0xf8, 0xff, 0x8d, 0xfc, 0xff }, // STA $FFF8, STA $FFFC Surf's Up (4K) { 0x8c, 0xf9, 0xff, 0xad, 0xfc, 0xff } // STY $FFF9, LDA $FFFC 3-D Havoc @@ -676,7 +676,7 @@ bool CartDetector::isProbablyFE(const ByteBuffer& image, size_t size) // FE bankswitching is very weird, but always seems to include a // 'JSR $xxxx' // These signatures are attributed to the MESS project - uInt8 signature[4][5] = { + static constexpr uInt8 signature[4][5] = { { 0x20, 0x00, 0xD0, 0xC6, 0xC5 }, // JSR $D000; DEC $C5 { 0x20, 0xC3, 0xF8, 0xA5, 0x82 }, // JSR $F8C3; LDA $82 { 0xD0, 0xFB, 0x20, 0x73, 0xFE }, // BNE $FB; JSR $FE73 @@ -693,7 +693,7 @@ bool CartDetector::isProbablyFE(const ByteBuffer& image, size_t size) bool CartDetector::isProbablyMDM(const ByteBuffer& image, size_t size) { // MDM cart is identified key 'MDMC' in the first 8K of ROM - uInt8 mdmc[] = { 'M', 'D', 'M', 'C' }; + static constexpr uInt8 mdmc[] = { 'M', 'D', 'M', 'C' }; return searchForBytes(image, std::min(size, 8_KB), mdmc, 4); } @@ -701,8 +701,8 @@ bool CartDetector::isProbablyMDM(const ByteBuffer& image, size_t size) bool CartDetector::isProbablyMVC(const ByteBuffer& image, size_t size) { // MVC version 0 - uInt8 sig[] = { 'M', 'V', 'C', 0 }; - int sigSize = sizeof(sig); + static constexpr uInt8 sig[] = { 'M', 'V', 'C', 0 }; + constexpr int sigSize = sizeof(sig); return searchForBytes(image, std::min(size, sigSize+1), sig, sigSize); } @@ -723,7 +723,7 @@ size_t CartDetector::isProbablyMVC(const FilesystemNode& rom) uInt8 image[frameSize]; s.getByteArray(image, frameSize); - uInt8 sig[] = { 'M', 'V', 'C', 0 }; // MVC version 0 + static constexpr uInt8 sig[] = { 'M', 'V', 'C', 0 }; // MVC version 0 return searchForBytes(image, frameSize, sig, 4) ? frameSize : 0; } return 0; @@ -733,7 +733,7 @@ size_t CartDetector::isProbablyMVC(const FilesystemNode& rom) bool CartDetector::isProbablySB(const ByteBuffer& image, size_t size) { // SB cart bankswitching switches banks by accessing address 0x0800 - uInt8 signature[2][3] = { + static constexpr uInt8 signature[2][3] = { { 0xBD, 0x00, 0x08 }, // LDA $0800,x { 0xAD, 0x00, 0x08 } // LDA $0800 }; @@ -747,7 +747,7 @@ bool CartDetector::isProbablySB(const ByteBuffer& image, size_t size) bool CartDetector::isProbablyTVBoy(const ByteBuffer& image, size_t size) { // TV Boy cart bankswitching switches banks by accessing addresses 0x1800..$187F - uInt8 signature[5] = {0x91, 0x82, 0x6c, 0xfc, 0xff}; // STA ($82),Y; JMP ($FFFC) + static constexpr uInt8 signature[5] = {0x91, 0x82, 0x6c, 0xfc, 0xff}; // STA ($82),Y; JMP ($FFFC) return searchForBytes(image, size, signature, 5); } @@ -761,7 +761,7 @@ bool CartDetector::isProbablyUA(const ByteBuffer& image, size_t size) // Other Brazilian (Atari Mania) ROM's bankswitching switches to bank 1 by accessing address 0xFC0 // using 'BIT $FA0', 'BIT $FC0' or 'STA $FC0' // Also a game (Motocross) using 'BIT $EFC0' has been found - uInt8 signature[10][3] = { + static constexpr uInt8 signature[10][3] = { { 0x8D, 0x40, 0x02 }, // STA $240 (Funky Fish, Pleiades) { 0xAD, 0x40, 0x02 }, // LDA $240 (???) { 0xBD, 0x1F, 0x02 }, // LDA $21F,X (Gingerbread Man) @@ -784,7 +784,7 @@ bool CartDetector::isProbablyUA(const ByteBuffer& image, size_t size) bool CartDetector::isProbablyWD(const ByteBuffer& image, size_t size) { // WD cart bankswitching switches banks by accessing address 0x30..0x3f - uInt8 signature[1][3] = { + static constexpr uInt8 signature[1][3] = { { 0xA5, 0x39, 0x4C } // LDA $39, JMP }; return searchForBytes(image, size, signature[0], 3); @@ -794,7 +794,7 @@ bool CartDetector::isProbablyWD(const ByteBuffer& image, size_t size) bool CartDetector::isProbablyX07(const ByteBuffer& image, size_t size) { // X07 bankswitching switches to bank 0, 1, 2, etc by accessing address 0x08xd - uInt8 signature[6][3] = { + static constexpr uInt8 signature[6][3] = { { 0xAD, 0x0D, 0x08 }, // LDA $080D { 0xAD, 0x1D, 0x08 }, // LDA $081D { 0xAD, 0x2D, 0x08 }, // LDA $082D @@ -813,7 +813,7 @@ bool CartDetector::isProbablyX07(const ByteBuffer& image, size_t size) bool CartDetector::isProbablyPlusROM(const ByteBuffer& image, size_t size) { // PlusCart uses this pattern to detect a PlusROM - uInt8 signature[3] = {0x8d, 0xf0, 0x1f}; // STA $1FF0 + static constexpr uInt8 signature[3] = {0x8d, 0xf0, 0x1f}; // STA $1FF0 return searchForBytes(image, size, signature, 3); } diff --git a/src/emucore/CartE7.cxx b/src/emucore/CartE7.cxx index 23ee75eb0..5140d1419 100644 --- a/src/emucore/CartE7.cxx +++ b/src/emucore/CartE7.cxx @@ -46,7 +46,7 @@ void CartridgeE7::reset() initializeRAM(myRAM.data(), myRAM.size()); initializeStartBank(0); - uInt32 ramBank = randomStartBank() ? + const uInt32 ramBank = randomStartBank() ? mySystem->randGenerator().next() % 4 : 0; // Install some default banks for the RAM and first segment @@ -136,7 +136,7 @@ void CartridgeE7::checkSwitchBank(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CartridgeE7::peek(uInt16 address) { - uInt16 peekAddress = address; + const uInt16 peekAddress = address; address &= 0x0FFF; // Switch banks if necessary @@ -159,7 +159,7 @@ uInt8 CartridgeE7::peek(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeE7::poke(uInt16 address, uInt8 value) { - uInt16 pokeAddress = address; + const uInt16 pokeAddress = address; address &= 0x0FFF; // Switch banks if necessary @@ -216,7 +216,7 @@ void CartridgeE7::bankRAM(uInt16 bank) // Remember what bank we're in myCurrentRAM = bank; - uInt16 offset = bank << 8; // * RAM_BANK_SIZE (256) + const uInt16 offset = bank << 8; // * RAM_BANK_SIZE (256) // Setup the page access methods for the current bank // Set the page accessing method for the 256 bytes of RAM reading pages @@ -238,7 +238,7 @@ bool CartridgeE7::bank(uInt16 bank, uInt16) // Setup the page access methods for the current bank if(bank != myRAMBank) { - uInt16 offset = bank << 11; // * BANK_SIZE (2048) + const uInt16 offset = bank << 11; // * BANK_SIZE (2048) // Map ROM image into first segment setAccess(0x1000, BANK_SIZE, offset, myImage.get(), offset, System::PageAccessType::READ); @@ -339,7 +339,7 @@ bool CartridgeE7::load(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt16 CartridgeE7::romBankCount() const { - return uInt16(mySize >> 11); + return static_cast(mySize >> 11); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartEnhanced.cxx b/src/emucore/CartEnhanced.cxx index f8201ff62..b30f3a64e 100644 --- a/src/emucore/CartEnhanced.cxx +++ b/src/emucore/CartEnhanced.cxx @@ -243,22 +243,14 @@ bool CartridgeEnhanced::bank(uInt16 bank, uInt16 segment) // Remember what bank is in this segment const uInt32 bankOffset = myCurrentSegOffset[segment] = romBank << myBankShift; const uInt16 hotspot = this->hotspot(); - uInt16 hotSpotAddr; - uInt16 plusROMAddr; + const uInt16 hotSpotAddr = (hotspot & 0x1000) ? (hotspot & ~System::PAGE_MASK) : 0xFFFF; + const uInt16 plusROMAddr = (myPlusROM->isValid()) ? (0x1FF0 & ~System::PAGE_MASK) : 0xFFFF; + // Skip extra RAM; if existing it is only mapped into first segment const uInt16 fromAddr = (ROM_OFFSET + segmentOffset + (segment == 0 ? myRomOffset : 0)) & ~System::PAGE_MASK; // for ROMs < 4_KB, the whole address space will be mapped. const uInt16 toAddr = (ROM_OFFSET + segmentOffset + (mySize < 4_KB ? 4_KB : myBankSize)) & ~System::PAGE_MASK; - if(hotspot & 0x1000) - hotSpotAddr = (hotspot & ~System::PAGE_MASK); - else - hotSpotAddr = 0xFFFF; // none - if(myPlusROM->isValid()) - plusROMAddr = (0x1FF0 & ~System::PAGE_MASK); - else - plusROMAddr = 0xFFFF; // none - System::PageAccess access(this, System::PageAccessType::READ); // Setup the page access methods for the current bank for(uInt16 addr = fromAddr; addr < toAddr; addr += System::PAGE_SIZE) @@ -335,7 +327,7 @@ uInt16 CartridgeEnhanced::getSegmentBank(uInt16 segment) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt16 CartridgeEnhanced::romBankCount() const { - return uInt16(mySize >> myBankShift); + return static_cast(mySize >> myBankShift); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartEnhanced.hxx b/src/emucore/CartEnhanced.hxx index 9cceed3a6..3aa84e54e 100644 --- a/src/emucore/CartEnhanced.hxx +++ b/src/emucore/CartEnhanced.hxx @@ -188,7 +188,7 @@ class CartridgeEnhanced : public Cartridge uInt16 myBankShift{BANK_SHIFT}; // default 12 (-> one 4K segment) // The size of a bank's segment - uInt16 myBankSize{uInt16(4_KB)}; + uInt16 myBankSize{static_cast(4_KB)}; // The mask for a bank segment uInt16 myBankMask{ROM_MASK}; diff --git a/src/emucore/CartF0.cxx b/src/emucore/CartF0.cxx index 16c227e89..979f6a009 100644 --- a/src/emucore/CartF0.cxx +++ b/src/emucore/CartF0.cxx @@ -32,7 +32,7 @@ bool CartridgeF0::checkSwitchBank(uInt16 address, uInt8) if(address == 0x1FF0) { // Switch to next bank - uInt8 nextBank = ((getBank()) + 1) & 0x0F; + const uInt8 nextBank = ((getBank()) + 1) & 0x0F; bank(nextBank); return true; } diff --git a/src/emucore/CartFA2.cxx b/src/emucore/CartFA2.cxx index 7ae3327b9..631b32976 100644 --- a/src/emucore/CartFA2.cxx +++ b/src/emucore/CartFA2.cxx @@ -143,7 +143,7 @@ uInt8 CartridgeFA2::ramReadWrite() } } // Bit 6 is 1, busy - return myImage[myCurrentSegOffset[0] + 0xFF4] | 0x40; + return myImage[myCurrentSegOffset[0] + 0xFF4] | 0x40; } else { diff --git a/src/emucore/CartFE.cxx b/src/emucore/CartFE.cxx index 463177cb2..79f3835ad 100644 --- a/src/emucore/CartFE.cxx +++ b/src/emucore/CartFE.cxx @@ -42,7 +42,7 @@ void CartridgeFE::install(System& system) // The hotspot $01FE is in a mirror of zero-page RAM // We need to claim access to it here, and deal with it in peek/poke below - System::PageAccess access(this, System::PageAccessType::READWRITE); + const System::PageAccess access(this, System::PageAccessType::READWRITE); for(uInt16 addr = 0x180; addr < 0x200; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); } @@ -63,7 +63,7 @@ bool CartridgeFE::checkSwitchBank(uInt16 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CartridgeFE::peek(uInt16 address) { - uInt8 value = (address < 0x200) ? mySystem->m6532().peek(address) : + const uInt8 value = (address < 0x200) ? mySystem->m6532().peek(address) : myImage[myCurrentSegOffset[(address & myBankMask) >> myBankShift] + (address & myBankMask)]; // Check if we hit hotspot diff --git a/src/emucore/CartMDM.cxx b/src/emucore/CartMDM.cxx index c363bc8af..258d3b34d 100644 --- a/src/emucore/CartMDM.cxx +++ b/src/emucore/CartMDM.cxx @@ -44,7 +44,7 @@ void CartridgeMDM::install(System& system) myHotSpotPageAccess[7] = mySystem->getPageAccess(0x0F00); // Set the page accessing methods for the hot spots - System::PageAccess access(this, System::PageAccessType::READWRITE); + const System::PageAccess access(this, System::PageAccessType::READWRITE); for(uInt16 addr = 0x0800; addr < 0x0BFF; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); } @@ -69,7 +69,7 @@ uInt8 CartridgeMDM::peek(uInt16 address) checkSwitchBank(address); - int hotspot = ((address & 0x0F00) >> 8) - 8; + const int hotspot = ((address & 0x0F00) >> 8) - 8; return myHotSpotPageAccess[hotspot].device->peek(address); } @@ -82,7 +82,7 @@ bool CartridgeMDM::poke(uInt16 address, uInt8 value) { checkSwitchBank(address); - int hotspot = ((address & 0x0F00) >> 8) - 8; + const int hotspot = ((address & 0x0F00) >> 8) - 8; myHotSpotPageAccess[hotspot].device->poke(address, value); } diff --git a/src/emucore/CartMVC.cxx b/src/emucore/CartMVC.cxx index 01d3952d1..4397c0a96 100755 --- a/src/emucore/CartMVC.cxx +++ b/src/emucore/CartMVC.cxx @@ -100,7 +100,7 @@ class StreamReader : public Serializable bool readField(uInt32 fnum, bool index) { if(myFile) { - size_t offset = ((fnum + 0) * CartridgeMVC::MVC_FIELD_PAD_SIZE); + const size_t offset = ((fnum + 0) * CartridgeMVC::MVC_FIELD_PAD_SIZE); if(offset + CartridgeMVC::MVC_FIELD_PAD_SIZE < myFileSize) { @@ -118,8 +118,8 @@ class StreamReader : public Serializable uInt8 readVersion() { return *myVersion++; } uInt8 readFrame() { return *myFrame++; } - uInt8 readColor() { return *myColor++; } - uInt8 readColorBK() { return *myColorBK++; } + uInt8 readColor() { return *myColor++; } + uInt8 readColorBK() { return *myColorBK++; } uInt8 readGraph() { return myGraphOverride ? *myGraphOverride++ : *myGraph++; @@ -911,7 +911,7 @@ void MovieCart::updateTransport() { if(myBufferIndex) { - uInt8 temp = ~(myA10_Count & 0x1e) & 0x1e; + const uInt8 temp = ~(myA10_Count & 0x1e) & 0x1e; if (temp == myDirectionValue) myInputs.updateDirection(temp); @@ -920,7 +920,7 @@ void MovieCart::updateTransport() } else { - uInt8 temp = ~(myA10_Count & 0x17) & 0x17; + const uInt8 temp = ~(myA10_Count & 0x17) & 0x17; if(temp == myButtonsValue) myInputs.updateTransport(temp); @@ -942,7 +942,7 @@ void MovieCart::updateTransport() return; } - uInt8 lastMainMode = myMode; + const uInt8 lastMainMode = myMode; if(myInputs.up && !myLastInputs.up) { @@ -1244,7 +1244,7 @@ void MovieCart::fill_addr_blank_lines() // frame number myStream.readFrame(); myStream.readFrame(); - uInt8 v = myStream.readFrame(); + const uInt8 v = myStream.readFrame(); // make sure we're in sync with frame data myOdd = (v & 1); @@ -1420,11 +1420,11 @@ void MovieCart::runStateMachine() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool MovieCart::process(uInt16 address) { - bool a12 = (address & (1 << 12)) ? 1:0; - bool a11 = (address & (1 << 11)) ? 1:0; + const bool a12 = (address & (1 << 12)) ? 1:0; + const bool a11 = (address & (1 << 11)) ? 1:0; // count a10 pulses - bool a10i = (address & (1 << 10)); + const bool a10i = (address & (1 << 10)); if(a10i && !myA10) myA10_Count++; myA10 = a10i; @@ -1589,7 +1589,7 @@ void CartridgeMVC::install(System& system) mySystem = &system; // Map all of the accesses to call peek and poke - System::PageAccess access(this, System::PageAccessType::READWRITE); + const System::PageAccess access(this, System::PageAccessType::READWRITE); for(uInt16 addr = 0x1000; addr < 0x2000; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); } diff --git a/src/emucore/CartSB.cxx b/src/emucore/CartSB.cxx index 05764316b..80e90cbcb 100644 --- a/src/emucore/CartSB.cxx +++ b/src/emucore/CartSB.cxx @@ -43,9 +43,8 @@ void CartridgeSB::install(System& system) myHotSpotPageAccess[6] = mySystem->getPageAccess(0x0E00); myHotSpotPageAccess[7] = mySystem->getPageAccess(0x0F00); - System::PageAccess access(this, System::PageAccessType::READ); - // Set the page accessing methods for the hot spots + const System::PageAccess access(this, System::PageAccessType::READ); for(uInt16 addr = 0x0800; addr < 0x0FFF; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); } @@ -73,7 +72,7 @@ uInt8 CartridgeSB::peek(uInt16 address) { // Because of the way we've set up accessing above, we can only // get here when the addresses are from 0x800 - 0xFFF - int hotspot = ((address & 0x0F00) >> 8) - 8; + const int hotspot = ((address & 0x0F00) >> 8) - 8; return myHotSpotPageAccess[hotspot].device->peek(address); } @@ -91,7 +90,7 @@ bool CartridgeSB::poke(uInt16 address, uInt8 value) { // Because of the way we've set up accessing above, we can only // get here when the addresses are from 0x800 - 0xFFF - int hotspot = ((address & 0x0F00) >> 8) - 8; + const int hotspot = ((address & 0x0F00) >> 8) - 8; myHotSpotPageAccess[hotspot].device->poke(address, value); } return false; diff --git a/src/emucore/CartTVBoy.cxx b/src/emucore/CartTVBoy.cxx index d09a29c9b..95a1d5acd 100644 --- a/src/emucore/CartTVBoy.cxx +++ b/src/emucore/CartTVBoy.cxx @@ -43,7 +43,7 @@ bool CartridgeTVBoy::bank(uInt16 bank, uInt16) { if(myBankingDisabled) return false; - bool banked = CartridgeEnhanced::bank(bank); + const bool banked = CartridgeEnhanced::bank(bank); // Any bankswitching locks further bankswitching, we check for bank 0 // to avoid locking on cart init. diff --git a/src/emucore/CartUA.cxx b/src/emucore/CartUA.cxx index 524b94a3f..1d6d5cd58 100644 --- a/src/emucore/CartUA.cxx +++ b/src/emucore/CartUA.cxx @@ -38,7 +38,7 @@ void CartridgeUA::install(System& system) myHotSpotPageAccess[1] = mySystem->getPageAccess(0x0220 | 0x80); // Set the page accessing methods for the hot spots - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); // Map all potential addresses // - A11, A10 and A8 are not connected to RIOT // - A9 is the fixed part of the hotspot address @@ -49,7 +49,7 @@ void CartridgeUA::install(System& system) for(uInt16 a8 = 0; a8 <= 1; ++a8) for(uInt16 a7 = 0; a7 <= 1; ++a7) { - uInt16 addr = (a11 << 11) + (a10 << 10) + (a8 << 8) + (a7 << 7); + const uInt16 addr = (a11 << 11) + (a10 << 10) + (a8 << 8) + (a7 << 7); mySystem->setPageAccess(0x0220 | addr, access); mySystem->setPageAccess(0x0240 | addr, access); @@ -89,7 +89,7 @@ uInt8 CartridgeUA::peek(uInt16 address) // Because of the way accessing is set up, we will only get here // when doing a TIA read - int hotspot = ((address & 0x80) >> 7); + const int hotspot = ((address & 0x80) >> 7); return myHotSpotPageAccess[hotspot].device->peek(address); } @@ -104,7 +104,7 @@ bool CartridgeUA::poke(uInt16 address, uInt8 value) // doing a write to TIA or cart; we ignore the cart write if (!(address & 0x1000)) { - int hotspot = ((address & 0x80) >> 7); + const int hotspot = ((address & 0x80) >> 7); myHotSpotPageAccess[hotspot].device->poke(address, value); } diff --git a/src/emucore/CartWD.cxx b/src/emucore/CartWD.cxx index 3718a0cc8..ea603711b 100644 --- a/src/emucore/CartWD.cxx +++ b/src/emucore/CartWD.cxx @@ -55,7 +55,7 @@ void CartridgeWD::install(System& system) { CartridgeEnhanced::install(system); - System::PageAccess access(this, System::PageAccessType::READ); + const System::PageAccess access(this, System::PageAccessType::READ); // The hotspots are in TIA address space, so we claim it here for(uInt16 addr = 0x00; addr < 0x40; addr += System::PAGE_SIZE) diff --git a/src/emucore/CartX07.cxx b/src/emucore/CartX07.cxx index 3398d65bc..686a089f0 100644 --- a/src/emucore/CartX07.cxx +++ b/src/emucore/CartX07.cxx @@ -36,7 +36,7 @@ void CartridgeX07::install(System& system) // Set the page accessing methods for the hot spots // The hotspots use almost all addresses below 0x1000, so we simply grab them // all and forward the TIA/RIOT calls from the peek and poke methods. - System::PageAccess access(this, System::PageAccessType::READWRITE); + const System::PageAccess access(this, System::PageAccessType::READWRITE); for(uInt16 addr = 0x00; addr < 0x1000; addr += System::PAGE_SIZE) mySystem->setPageAccess(addr, access); } @@ -67,7 +67,7 @@ uInt8 CartridgeX07::peek(uInt16 address) { uInt8 value = 0; // JTZ: is this correct? // Check for RAM or TIA mirroring - uInt16 lowAddress = address & 0x3ff; + const uInt16 lowAddress = address & 0x3ff; if(lowAddress & 0x80) value = mySystem->m6532().peek(address); @@ -83,7 +83,7 @@ uInt8 CartridgeX07::peek(uInt16 address) bool CartridgeX07::poke(uInt16 address, uInt8 value) { // Check for RAM or TIA mirroring - uInt16 lowAddress = address & 0x3ff; + const uInt16 lowAddress = address & 0x3ff; if(lowAddress & 0x80) mySystem->m6532().poke(address, value); diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 50c6a4fce..ae60d83b7 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -96,9 +96,9 @@ namespace { ); } - float unmapSpeed(int speed) + constexpr float unmapSpeed(int speed) { - float f_speed = static_cast(speed) / 100; + const float f_speed = static_cast(speed) / 100; return speed < 0 ? -1 / (f_speed - 1) : 1 + f_speed; } @@ -231,7 +231,7 @@ Console::Console(OSystem& osystem, unique_ptr& cart, // Finally, add remaining info about the console myConsoleInfo.CartName = myProperties.get(PropType::Cart_Name); myConsoleInfo.CartMD5 = myProperties.get(PropType::Cart_MD5); - bool swappedPorts = properties().get(PropType::Console_SwapPorts) == "YES"; + const bool swappedPorts = properties().get(PropType::Console_SwapPorts) == "YES"; myConsoleInfo.Control0 = myLeftControl->about(swappedPorts); myConsoleInfo.Control1 = myRightControl->about(swappedPorts); myConsoleInfo.BankSwitch = myCart->about(); @@ -472,6 +472,8 @@ void Console::setFormat(uInt32 format, bool force) message = "SECAM60 mode"; myFormatAutodetected = false; break; + default: // satisfy compiler + break; } myProperties.set(PropType::Display_Format, saveformat); @@ -497,7 +499,7 @@ void Console::setFormat(uInt32 format, bool force) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::toggleColorLoss(bool toggle) { - bool colorloss = !myTIA->colorLossEnabled(); + const bool colorloss = !myTIA->colorLossEnabled(); if(myTIA->enableColorLoss(colorloss)) { myOSystem.settings().setValue( @@ -771,7 +773,7 @@ void Console::toggleCorrectAspectRatio(bool toggle) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::setTIAProperties() { - Int32 vcenter = BSPF::clamp( + const Int32 vcenter = BSPF::clamp( static_cast(BSPF::stringToInt(myProperties.get(PropType::Display_VCenter))), TIAConstants::minVcenter, TIAConstants::maxVcenter ); @@ -880,40 +882,41 @@ void Console::setControllers(const string& romMd5) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::changeLeftController(int direction) { - int type = int(Controller::getType(myProperties.get(PropType::Controller_Left))); + int type = static_cast(Controller::getType(myProperties.get(PropType::Controller_Left))); if(!type) - type = int(Controller::getType(leftController().name())); + type = static_cast(Controller::getType(leftController().name())); type = BSPF::clampw(type + direction, - 1, int(Controller::Type::LastType) - 1); + 1, static_cast(Controller::Type::LastType) - 1); - myProperties.set(PropType::Controller_Left, Controller::getPropName(Controller::Type(type))); + myProperties.set(PropType::Controller_Left, Controller::getPropName(Controller::Type{type})); setControllers(myProperties.get(PropType::Cart_MD5)); ostringstream msg; - msg << "Left controller " << Controller::getName(Controller::Type(type)); + msg << "Left controller " << Controller::getName(Controller::Type{type}); myOSystem.frameBuffer().showTextMessage(msg.str()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::changeRightController(int direction) { - int type = int(Controller::getType(myProperties.get(PropType::Controller_Right))); + int type = static_cast(Controller::getType(myProperties.get(PropType::Controller_Right))); if(!type) - type = int(Controller::getType(rightController().name())); + type = static_cast(Controller::getType(rightController().name())); type = BSPF::clampw(type + direction, - 1, int(Controller::Type::LastType) - 1); + 1, static_cast(Controller::Type::LastType) - 1); - myProperties.set(PropType::Controller_Right, Controller::getPropName(Controller::Type(type))); + myProperties.set(PropType::Controller_Right, Controller::getPropName(Controller::Type{type})); setControllers(myProperties.get(PropType::Cart_MD5)); ostringstream msg; - msg << "Right controller " << Controller::getName(Controller::Type(type)); + msg << "Right controller " << Controller::getName(Controller::Type{type}); myOSystem.frameBuffer().showTextMessage(msg.str()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - unique_ptr Console::getControllerPort(const Controller::Type type, - const Controller::Jack port, const string& romMd5) + const Controller::Jack port, + const string& romMd5) { unique_ptr controller; @@ -1059,7 +1062,7 @@ void Console::toggleSwapPaddles(bool toggle) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::changePaddleCenterX(int direction) { - int center = + const int center = BSPF::clamp(BSPF::stringToInt(myProperties.get(PropType::Controller_PaddlesXCenter)) + direction, Paddles::MIN_ANALOG_CENTER, Paddles::MAX_ANALOG_CENTER); myProperties.set(PropType::Controller_PaddlesXCenter, std::to_string(center)); @@ -1074,7 +1077,7 @@ void Console::changePaddleCenterX(int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::changePaddleCenterY(int direction) { - int center = + const int center = BSPF::clamp(BSPF::stringToInt(myProperties.get(PropType::Controller_PaddlesYCenter)) + direction, Paddles::MIN_ANALOG_CENTER, Paddles::MAX_ANALOG_CENTER); myProperties.set(PropType::Controller_PaddlesYCenter, std::to_string(center)); @@ -1179,7 +1182,7 @@ void Console::toggleDeveloperSet(bool toggle) if(toggle) { devSettings = !devSettings; - DevSettingsHandler::SettingsSet set = devSettings + const DevSettingsHandler::SettingsSet set = devSettings ? DevSettingsHandler::SettingsSet::developer : DevSettingsHandler::SettingsSet::player; @@ -1195,7 +1198,7 @@ void Console::toggleDeveloperSet(bool toggle) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::toggleTIABit(TIABit bit, const string& bitname, bool show, bool toggle) const { - bool result = myTIA->toggleBit(bit, toggle ? 2 : 3); + const bool result = myTIA->toggleBit(bit, toggle ? 2 : 3); const string message = bitname + (result ? " enabled" : " disabled"); myOSystem.frameBuffer().showTextMessage(message); @@ -1204,7 +1207,7 @@ void Console::toggleTIABit(TIABit bit, const string& bitname, bool show, bool to // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::toggleBits(bool toggle) const { - bool enabled = myTIA->toggleBits(toggle); + const bool enabled = myTIA->toggleBits(toggle); const string message = string("TIA bits ") + (enabled ? "enabled" : "disabled"); myOSystem.frameBuffer().showTextMessage(message); @@ -1213,7 +1216,7 @@ void Console::toggleBits(bool toggle) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::toggleTIACollision(TIABit bit, const string& bitname, bool show, bool toggle) const { - bool result = myTIA->toggleCollision(bit, toggle ? 2 : 3); + const bool result = myTIA->toggleCollision(bit, toggle ? 2 : 3); const string message = bitname + (result ? " collision enabled" : " collision disabled"); myOSystem.frameBuffer().showTextMessage(message); @@ -1222,7 +1225,7 @@ void Console::toggleTIACollision(TIABit bit, const string& bitname, bool show, b // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::toggleCollisions(bool toggle) const { - bool enabled = myTIA->toggleCollisions(toggle); + const bool enabled = myTIA->toggleCollisions(toggle); const string message = string("TIA collisions ") + (enabled ? "enabled" : "disabled"); myOSystem.frameBuffer().showTextMessage(message); @@ -1231,7 +1234,7 @@ void Console::toggleCollisions(bool toggle) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::toggleFixedColors(bool toggle) const { - bool enabled = toggle ? myTIA->toggleFixedColors() : myTIA->usingFixedColors(); + const bool enabled = toggle ? myTIA->toggleFixedColors() : myTIA->usingFixedColors(); const string message = string("Fixed debug colors ") + (enabled ? "enabled" : "disabled"); myOSystem.frameBuffer().showTextMessage(message); @@ -1240,7 +1243,7 @@ void Console::toggleFixedColors(bool toggle) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::toggleJitter(bool toggle) const { - bool enabled = myTIA->toggleJitter(toggle ? 2 : 3); + const bool enabled = myTIA->toggleJitter(toggle ? 2 : 3); const string message = string("TV scanline jitter ") + (enabled ? "enabled" : "disabled"); myOSystem.settings().setValue( @@ -1253,7 +1256,7 @@ void Console::changeJitter(int direction) const { const string prefix = myOSystem.settings().getBool("dev.settings") ? "dev." : "plr."; int recovery = myOSystem.settings().getInt(prefix + "tv.jitter_recovery"); - bool enabled = direction ? recovery + direction > 0 : myTIA->toggleJitter(3); + const bool enabled = direction ? recovery + direction > 0 : myTIA->toggleJitter(3); // if disabled, enable before first before increasing recovery if(!myTIA->toggleJitter(3)) diff --git a/src/emucore/ConsoleIO.hxx b/src/emucore/ConsoleIO.hxx index 52cd4152d..3296942b3 100644 --- a/src/emucore/ConsoleIO.hxx +++ b/src/emucore/ConsoleIO.hxx @@ -39,8 +39,15 @@ class ConsoleIO */ virtual Switches& switches() const = 0; + ConsoleIO() = default; virtual ~ConsoleIO() = default; + private: + // Following constructors and assignment operators not supported + ConsoleIO(const ConsoleIO&) = delete; + ConsoleIO(ConsoleIO&&) = delete; + ConsoleIO& operator=(const ConsoleIO&) = delete; + ConsoleIO& operator=(ConsoleIO&&) = delete; }; #endif // CONSOLE_IO_HXX diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 0241ec9e6..7fd196b8c 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -105,7 +105,7 @@ bool Controller::load(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Controller::getName(const Type type) { - static const std::array NAMES = + static constexpr std::array(Controller::Type::LastType)> NAMES = { "Unknown", "Amiga mouse", "Atari mouse", "AtariVox", "Booster Grip", "CompuMate", @@ -114,13 +114,13 @@ string Controller::getName(const Type type) "Light Gun", "QuadTari" }; - return NAMES[int(type)]; + return NAMES[static_cast(type)]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Controller::getPropName(const Type type) { - static const std::array PROP_NAMES = + static constexpr std::array PROP_NAMES = { "AUTO", "AMIGAMOUSE", "ATARIMOUSE", "ATARIVOX", "BOOSTERGRIP", "COMPUMATE", @@ -129,7 +129,7 @@ string Controller::getPropName(const Type type) "LIGHTGUN", "QUADTARI" }; - return PROP_NAMES[int(type)]; + return PROP_NAMES[static_cast(type)]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -137,9 +137,9 @@ Controller::Type Controller::getType(const string& propName) { for(int i = 0; i < static_cast(Type::LastType); ++i) { - if(BSPF::equalsIgnoreCase(propName, getPropName(Type(i)))) + if (BSPF::equalsIgnoreCase(propName, getPropName(Type{i}))) { - return Type(i); + return Type{i}; } } // special case @@ -177,7 +177,6 @@ int Controller::analogDeadZoneValue(int deadZone) return deadZone * std::round(32768 / 2. / MAX_DIGITAL_DEADZONE); } - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Controller::setMouseSensitivity(int sensitivity) { diff --git a/src/emucore/ControllerDetector.cxx b/src/emucore/ControllerDetector.cxx index 57b62ebef..1af47811d 100644 --- a/src/emucore/ControllerDetector.cxx +++ b/src/emucore/ControllerDetector.cxx @@ -1,4 +1,3 @@ - //============================================================================ // // SSSS tt lll lll @@ -29,7 +28,7 @@ Controller::Type ControllerDetector::detectType( { if(type == Controller::Type::Unknown || settings.getBool("rominfo")) { - Controller::Type detectedType = autodetectPort(image, size, port, settings); + const Controller::Type detectedType = autodetectPort(image, size, port, settings); if(type != Controller::Type::Unknown && type != detectedType) { @@ -125,9 +124,9 @@ bool ControllerDetector::usesJoystickButton(const ByteBuffer& image, size_t size if(port == Controller::Jack::Left) { // check for INPT4 access - const int NUM_SIGS_0 = 24; - const int SIG_SIZE_0 = 3; - uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { + static constexpr int NUM_SIGS_0 = 24; + static constexpr int SIG_SIZE_0 = 3; + static constexpr uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { { 0x24, 0x0c, 0x10 }, // bit INPT4; bpl (joystick games only) { 0x24, 0x0c, 0x30 }, // bit INPT4; bmi (joystick games only) { 0xa5, 0x0c, 0x10 }, // lda INPT4; bpl (joystick games only) @@ -153,9 +152,9 @@ bool ControllerDetector::usesJoystickButton(const ByteBuffer& image, size_t size { 0xa6, 0x0c, 0x30 }, // ldx INPT4; bmi { 0xa5, 0x0c, 0x0a } // lda INPT4; asl (joystick games only) }; - const int NUM_SIGS_1 = 9; - const int SIG_SIZE_1 = 4; - uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { + static constexpr int NUM_SIGS_1 = 9; + static constexpr int SIG_SIZE_1 = 4; + static constexpr uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { { 0xb9, 0x0c, 0x00, 0x10 }, // lda INPT4,y; bpl (joystick games only) { 0xb9, 0x0c, 0x00, 0x30 }, // lda INPT4,y; bmi (joystick games only) { 0xb9, 0x3c, 0x00, 0x10 }, // lda INPT4,y; bpl (joystick games only) @@ -166,9 +165,9 @@ bool ControllerDetector::usesJoystickButton(const ByteBuffer& image, size_t size { 0xa5, 0x0c, 0x29, 0x80 }, // lda INPT4; and #$80 (joystick games only) { 0xa5, 0x3c, 0x29, 0x80 } // lda INPT4|$30; and #$80 (joystick games only) }; - const int NUM_SIGS_2 = 9; - const int SIG_SIZE_2 = 5; - uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { + static constexpr int NUM_SIGS_2 = 9; + static constexpr int SIG_SIZE_2 = 5; + static constexpr uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { { 0xa5, 0x0c, 0x25, 0x0d, 0x10 }, // lda INPT4; and INPT5; bpl (joystick games only) { 0xa5, 0x0c, 0x25, 0x0d, 0x30 }, // lda INPT4; and INPT5; bmi (joystick games only) { 0xa5, 0x3c, 0x25, 0x3d, 0x10 }, // lda INPT4|$30; and INPT5|$30; bpl (joystick games only) @@ -195,9 +194,9 @@ bool ControllerDetector::usesJoystickButton(const ByteBuffer& image, size_t size else if(port == Controller::Jack::Right) { // check for INPT5 and indexed INPT4 access - const int NUM_SIGS_0 = 16; - const int SIG_SIZE_0 = 3; - uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { + static constexpr int NUM_SIGS_0 = 16; + static constexpr int SIG_SIZE_0 = 3; + static constexpr uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { { 0x24, 0x0d, 0x10 }, // bit INPT5; bpl (joystick games only) { 0x24, 0x0d, 0x30 }, // bit INPT5; bmi (joystick games only) { 0xa5, 0x0d, 0x10 }, // lda INPT5; bpl (joystick games only) @@ -215,9 +214,9 @@ bool ControllerDetector::usesJoystickButton(const ByteBuffer& image, size_t size { 0xa6, 0x3d, 0x30 }, // ldx INPT5|$30; bmi (joystick games only) { 0xa6, 0x0d, 0x30 } // ldx INPT5; bmi }; - const int NUM_SIGS_1 = 7; - const int SIG_SIZE_1 = 4; - uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { + static constexpr int NUM_SIGS_1 = 7; + static constexpr int SIG_SIZE_1 = 4; + static constexpr uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { { 0xb9, 0x0c, 0x00, 0x10 }, // lda INPT4,y; bpl (joystick games only) { 0xb9, 0x0c, 0x00, 0x30 }, // lda INPT4,y; bmi (joystick games only) { 0xb9, 0x3c, 0x00, 0x10 }, // lda INPT4,y; bpl (joystick games only) @@ -226,9 +225,9 @@ bool ControllerDetector::usesJoystickButton(const ByteBuffer& image, size_t size { 0xb5, 0x3c, 0x29, 0x80 }, // lda INPT4|$30,x; and #$80 (joystick games only) { 0xa5, 0x3d, 0x29, 0x80 } // lda INPT5|$30; and #$80 (joystick games only) }; - const int NUM_SIGS_2 = 3; - const int SIG_SIZE_2 = 5; - uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { + static constexpr int NUM_SIGS_2 = 3; + static constexpr int SIG_SIZE_2 = 5; + static constexpr uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { { 0xb5, 0x38, 0x29, 0x80, 0xd0 }, // lda INPT0|$30,y; and #$80; bne (Basic Programming) { 0xa9, 0x80, 0x24, 0x0d, 0xd0 }, // lda #$80; bit INPT5; bne (bBasic) { 0xad, 0x0d, 0x00, 0x29, 0x80 } // lda.w INPT5|$30; and #$80 (joystick games only) @@ -256,9 +255,9 @@ bool ControllerDetector::usesKeyboard(const ByteBuffer& image, size_t size, if(port == Controller::Jack::Left) { // check for INPT0 *AND* INPT1 access - const int NUM_SIGS_0_0 = 6; - const int SIG_SIZE_0_0 = 3; - uInt8 signature_0_0[NUM_SIGS_0_0][SIG_SIZE_0_0] = { + static constexpr int NUM_SIGS_0_0 = 6; + static constexpr int SIG_SIZE_0_0 = 3; + static constexpr uInt8 signature_0_0[NUM_SIGS_0_0][SIG_SIZE_0_0] = { { 0x24, 0x38, 0x30 }, // bit INPT0|$30; bmi { 0xa5, 0x38, 0x10 }, // lda INPT0|$30; bpl { 0xa4, 0x38, 0x30 }, // ldy INPT0|$30; bmi @@ -266,15 +265,15 @@ bool ControllerDetector::usesKeyboard(const ByteBuffer& image, size_t size, { 0x24, 0x08, 0x30 }, // bit INPT0; bmi { 0xa6, 0x08, 0x30 } // ldx INPT0; bmi }; - const int NUM_SIGS_0_2 = 1; - const int SIG_SIZE_0_2 = 5; - uInt8 signature_0_2[NUM_SIGS_0_2][SIG_SIZE_0_2] = { + static constexpr int NUM_SIGS_0_2 = 1; + static constexpr int SIG_SIZE_0_2 = 5; + static constexpr uInt8 signature_0_2[NUM_SIGS_0_2][SIG_SIZE_0_2] = { { 0xb5, 0x38, 0x29, 0x80, 0xd0 } // lda INPT0,x; and #80; bne }; - const int NUM_SIGS_1_0 = 7; - const int SIG_SIZE_1_0 = 3; - uInt8 signature_1_0[NUM_SIGS_1_0][SIG_SIZE_1_0] = { + static constexpr int NUM_SIGS_1_0 = 7; + static constexpr int SIG_SIZE_1_0 = 3; + static constexpr uInt8 signature_1_0[NUM_SIGS_1_0][SIG_SIZE_1_0] = { { 0x24, 0x39, 0x10 }, // bit INPT1|$30; bpl { 0x24, 0x39, 0x30 }, // bit INPT1|$30; bmi { 0xa5, 0x39, 0x10 }, // lda INPT1|$30; bpl @@ -283,9 +282,9 @@ bool ControllerDetector::usesKeyboard(const ByteBuffer& image, size_t size, { 0x24, 0x09, 0x30 }, // bit INPT1; bmi { 0xa6, 0x09, 0x30 } // ldx INPT1; bmi }; - const int NUM_SIGS_1_2 = 1; - const int SIG_SIZE_1_2 = 5; - uInt8 signature_1_2[NUM_SIGS_1_2][SIG_SIZE_1_2] = { + static constexpr int NUM_SIGS_1_2 = 1; + static constexpr int SIG_SIZE_1_2 = 5; + static constexpr uInt8 signature_1_2[NUM_SIGS_1_2][SIG_SIZE_1_2] = { { 0xb5, 0x38, 0x29, 0x80, 0xd0 } // lda INPT0,x; and #80; bne }; @@ -322,9 +321,9 @@ bool ControllerDetector::usesKeyboard(const ByteBuffer& image, size_t size, else if(port == Controller::Jack::Right) { // check for INPT2 *AND* INPT3 access - const int NUM_SIGS_0_0 = 6; - const int SIG_SIZE_0_0 = 3; - uInt8 signature_0_0[NUM_SIGS_0_0][SIG_SIZE_0_0] = { + static constexpr int NUM_SIGS_0_0 = 6; + static constexpr int SIG_SIZE_0_0 = 3; + static constexpr uInt8 signature_0_0[NUM_SIGS_0_0][SIG_SIZE_0_0] = { { 0x24, 0x3a, 0x30 }, // bit INPT2|$30; bmi { 0xa5, 0x3a, 0x10 }, // lda INPT2|$30; bpl { 0xa4, 0x3a, 0x30 }, // ldy INPT2|$30; bmi @@ -332,15 +331,15 @@ bool ControllerDetector::usesKeyboard(const ByteBuffer& image, size_t size, { 0x24, 0x0a, 0x10 }, // bit INPT2; bpl { 0xa6, 0x0a, 0x30 } // ldx INPT2; bmi }; - const int NUM_SIGS_0_2 = 1; - const int SIG_SIZE_0_2 = 5; - uInt8 signature_0_2[NUM_SIGS_0_2][SIG_SIZE_0_2] = { + static constexpr int NUM_SIGS_0_2 = 1; + static constexpr int SIG_SIZE_0_2 = 5; + static constexpr uInt8 signature_0_2[NUM_SIGS_0_2][SIG_SIZE_0_2] = { { 0xb5, 0x38, 0x29, 0x80, 0xd0 } // lda INPT2,x; and #80; bne }; - const int NUM_SIGS_1_0 = 6; - const int SIG_SIZE_1_0 = 3; - uInt8 signature_1_0[NUM_SIGS_1_0][SIG_SIZE_1_0] = { + static constexpr int NUM_SIGS_1_0 = 6; + static constexpr int SIG_SIZE_1_0 = 3; + static constexpr uInt8 signature_1_0[NUM_SIGS_1_0][SIG_SIZE_1_0] = { { 0x24, 0x3b, 0x30 }, // bit INPT3|$30; bmi { 0xa5, 0x3b, 0x10 }, // lda INPT3|$30; bpl { 0xa4, 0x3b, 0x30 }, // ldy INPT3|$30; bmi @@ -348,9 +347,9 @@ bool ControllerDetector::usesKeyboard(const ByteBuffer& image, size_t size, { 0x24, 0x0b, 0x10 }, // bit INPT3; bpl { 0xa6, 0x0b, 0x30 } // ldx INPT3; bmi }; - const int NUM_SIGS_1_2 = 1; - const int SIG_SIZE_1_2 = 5; - uInt8 signature_1_2[NUM_SIGS_1_2][SIG_SIZE_1_2] = { + static constexpr int NUM_SIGS_1_2 = 1; + static constexpr int SIG_SIZE_1_2 = 5; + static constexpr uInt8 signature_1_2[NUM_SIGS_1_2][SIG_SIZE_1_2] = { { 0xb5, 0x38, 0x29, 0x80, 0xd0 } // lda INPT2,x; and #80; bne }; @@ -397,9 +396,9 @@ bool ControllerDetector::usesGenesisButton(const ByteBuffer& image, size_t size, if(port == Controller::Jack::Left) { // check for INPT1 access - const int NUM_SIGS_0 = 19; - const int SIG_SIZE_0 = 3; - uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { + static constexpr int NUM_SIGS_0 = 19; + static constexpr int SIG_SIZE_0 = 3; + static constexpr uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { { 0x24, 0x09, 0x10 }, // bit INPT1; bpl (Genesis only) { 0x24, 0x09, 0x30 }, // bit INPT1; bmi (paddle ROMS too) { 0xa5, 0x09, 0x10 }, // lda INPT1; bpl (paddle ROMS too) @@ -427,9 +426,9 @@ bool ControllerDetector::usesGenesisButton(const ByteBuffer& image, size_t size, else if(port == Controller::Jack::Right) { // check for INPT3 access - const int NUM_SIGS_0 = 10; - const int SIG_SIZE_0 = 3; - uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { + static constexpr int NUM_SIGS_0 = 10; + static constexpr int SIG_SIZE_0 = 3; + static constexpr uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { { 0x24, 0x0b, 0x10 }, // bit INPT3; bpl { 0x24, 0x0b, 0x30 }, // bit INPT3; bmi { 0xa5, 0x0b, 0x10 }, // lda INPT3; bpl @@ -455,9 +454,9 @@ bool ControllerDetector::usesPaddle(const ByteBuffer& image, size_t size, if(port == Controller::Jack::Left) { // check for INPT0 access - const int NUM_SIGS_0 = 12; - const int SIG_SIZE_0 = 3; - uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { + static constexpr int NUM_SIGS_0 = 12; + static constexpr int SIG_SIZE_0 = 3; + static constexpr uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { //{ 0x24, 0x08, 0x10 }, // bit INPT0; bpl (many joystick games too!) //{ 0x24, 0x08, 0x30 }, // bit INPT0; bmi (joystick games: Spike's Peak, Sweat, Turbo!) { 0xa5, 0x08, 0x10 }, // lda INPT0; bpl (no joystick games) @@ -474,17 +473,17 @@ bool ControllerDetector::usesPaddle(const ByteBuffer& image, size_t size, { 0xa5, 0x08, 0x4c }, // lda INPT0; jmp (only Backgammon) { 0xa4, 0x38, 0x30 } // ldy INPT0; bmi (no joystick games) }; - const int NUM_SIGS_1 = 4; - const int SIG_SIZE_1 = 4; - uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { + static constexpr int NUM_SIGS_1 = 4; + static constexpr int SIG_SIZE_1 = 4; + static constexpr uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { { 0xb9, 0x08, 0x00, 0x30 }, // lda INPT0,y; bmi (i.a. Encounter at L-5) { 0xb9, 0x38, 0x00, 0x30 }, // lda INPT0|$30,y; bmi (i.a. SW-Jedi Arena, Video Olympics) { 0xb9, 0x08, 0x00, 0x10 }, // lda INPT0,y; bpl (Drone Wars) { 0x24, 0x08, 0x30, 0x02 } // bit INPT0; bmi +2 (Picnic) }; - const int NUM_SIGS_2 = 4; - const int SIG_SIZE_2 = 5; - uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { + static constexpr int NUM_SIGS_2 = 4; + static constexpr int SIG_SIZE_2 = 5; + static constexpr uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { { 0xb5, 0x38, 0x29, 0x80, 0xd0 }, // lda INPT0|$30,x; and #$80; bne (Basic Programming) { 0x24, 0x38, 0x85, 0x08, 0x10 }, // bit INPT0|$30; sta COLUPF, bpl (Fireball) { 0xb5, 0x38, 0x49, 0xff, 0x0a }, // lda INPT0|$30,x; eor #$ff; asl (Blackjack) @@ -506,9 +505,9 @@ bool ControllerDetector::usesPaddle(const ByteBuffer& image, size_t size, else if(port == Controller::Jack::Right) { // check for INPT2 and indexed INPT0 access - const int NUM_SIGS_0 = 18; - const int SIG_SIZE_0 = 3; - uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { + static constexpr int NUM_SIGS_0 = 18; + static constexpr int SIG_SIZE_0 = 3; + static constexpr uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { { 0x24, 0x0a, 0x10 }, // bit INPT2; bpl (no joystick games) { 0x24, 0x0a, 0x30 }, // bit INPT2; bmi (no joystick games) { 0xa5, 0x0a, 0x10 }, // lda INPT2; bpl (no joystick games) @@ -528,14 +527,14 @@ bool ControllerDetector::usesPaddle(const ByteBuffer& image, size_t size, { 0xa4, 0x3a, 0x30 }, // ldy INPT2|$30; bmi (no joystick games) { 0xa5, 0x3b, 0x30 } // lda INPT3|$30; bmi (only Tac Scan, ports and paddles swapped) }; - const int NUM_SIGS_1 = 1; - const int SIG_SIZE_1 = 4; - uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { + static constexpr int NUM_SIGS_1 = 1; + static constexpr int SIG_SIZE_1 = 4; + static constexpr uInt8 signature_1[NUM_SIGS_1][SIG_SIZE_1] = { { 0xb9, 0x38, 0x00, 0x30 }, // lda INPT0|$30,y; bmi (Video Olympics) }; - const int NUM_SIGS_2 = 3; - const int SIG_SIZE_2 = 5; - uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { + static constexpr int NUM_SIGS_2 = 3; + static constexpr int SIG_SIZE_2 = 5; + static constexpr uInt8 signature_2[NUM_SIGS_2][SIG_SIZE_2] = { { 0xb5, 0x38, 0x29, 0x80, 0xd0 }, // lda INPT0|$30,x; and #$80; bne (Basic Programming) { 0x24, 0x38, 0x85, 0x08, 0x10 }, // bit INPT2|$30; sta COLUPF, bpl (Fireball, patched at runtime!) { 0xb5, 0x38, 0x49, 0xff, 0x0a } // lda INPT0|$30,x; eor #$ff; asl (Blackjack) @@ -561,9 +560,9 @@ bool ControllerDetector::usesPaddle(const ByteBuffer& image, size_t size, bool ControllerDetector::isProbablyTrakBall(const ByteBuffer& image, size_t size) { // check for TrakBall tables - const int NUM_SIGS = 3; - const int SIG_SIZE = 6; - uInt8 signature[NUM_SIGS][SIG_SIZE] = { + static constexpr int NUM_SIGS = 3; + static constexpr int SIG_SIZE = 6; + static constexpr uInt8 signature[NUM_SIGS][SIG_SIZE] = { { 0b1010, 0b1000, 0b1000, 0b1010, 0b0010, 0b0000/*, 0b0000, 0b0010*/ }, // NextTrackTbl (T. Jentzsch) { 0x00, 0x07, 0x87, 0x07, 0x88, 0x01/*, 0xff, 0x01*/ }, // .MovementTab_1 (Omegamatrix, SMX7) { 0x00, 0x01, 0x81, 0x01, 0x82, 0x03 } // .MovementTab_1 (Omegamatrix) @@ -580,9 +579,9 @@ bool ControllerDetector::isProbablyTrakBall(const ByteBuffer& image, size_t size bool ControllerDetector::isProbablyAtariMouse(const ByteBuffer& image, size_t size) { // check for Atari Mouse tables - const int NUM_SIGS = 3; - const int SIG_SIZE = 6; - uInt8 signature[NUM_SIGS][SIG_SIZE] = { + static constexpr int NUM_SIGS = 3; + static constexpr int SIG_SIZE = 6; + static constexpr uInt8 signature[NUM_SIGS][SIG_SIZE] = { { 0b0101, 0b0111, 0b0100, 0b0110, 0b1101, 0b1111/*, 0b1100, 0b1110*/ }, // NextTrackTbl (T. Jentzsch) { 0x00, 0x87, 0x07, 0x00, 0x08, 0x81/*, 0x7f, 0x08*/ }, // .MovementTab_1 (Omegamatrix, SMX7) { 0x00, 0x81, 0x01, 0x00, 0x02, 0x83 } // .MovementTab_1 (Omegamatrix) @@ -599,9 +598,9 @@ bool ControllerDetector::isProbablyAtariMouse(const ByteBuffer& image, size_t si bool ControllerDetector::isProbablyAmigaMouse(const ByteBuffer& image, size_t size) { // check for Amiga Mouse tables - const int NUM_SIGS = 4; - const int SIG_SIZE = 6; - uInt8 signature[NUM_SIGS][SIG_SIZE] = { + static constexpr int NUM_SIGS = 4; + static constexpr int SIG_SIZE = 6; + static constexpr uInt8 signature[NUM_SIGS][SIG_SIZE] = { { 0b1100, 0b1000, 0b0100, 0b0000, 0b1101, 0b1001/*, 0b0101, 0b0001*/ }, // NextTrackTbl (T. Jentzsch) { 0x00, 0x88, 0x07, 0x01, 0x08, 0x00/*, 0x7f, 0x07*/ }, // .MovementTab_1 (Omegamatrix, SMX7) { 0x00, 0x82, 0x01, 0x03, 0x02, 0x00 }, // .MovementTab_1 (Omegamatrix) @@ -622,9 +621,9 @@ bool ControllerDetector::isProbablySaveKey(const ByteBuffer& image, size_t size, // check for known SaveKey code, only supports right port if(port == Controller::Jack::Right) { - const int NUM_SIGS = 4; - const int SIG_SIZE = 9; - uInt8 signature[NUM_SIGS][SIG_SIZE] = { + static constexpr int NUM_SIGS = 4; + static constexpr int SIG_SIZE = 9; + static constexpr uInt8 signature[NUM_SIGS][SIG_SIZE] = { { // from I2C_START (i2c.inc) 0xa9, 0x08, // lda #I2C_SCL_MASK 0x8d, 0x80, 0x02, // sta SWCHA @@ -667,9 +666,9 @@ bool ControllerDetector::isProbablyLightGun(const ByteBuffer& image, size_t size if (port == Controller::Jack::Left) { // check for INPT4 after NOPs access - const int NUM_SIGS = 2; - const int SIG_SIZE = 6; - uInt8 signature[NUM_SIGS][SIG_SIZE] = { + static constexpr int NUM_SIGS = 2; + static constexpr int SIG_SIZE = 6; + static constexpr uInt8 signature[NUM_SIGS][SIG_SIZE] = { { 0xea, 0xea, 0xea, 0x24, 0x0c, 0x10 }, { 0xea, 0xea, 0xea, 0x24, 0x3c, 0x10 } }; // all pattern checked, only 'Sentinel' and 'Shooting Arcade' match @@ -683,9 +682,9 @@ bool ControllerDetector::isProbablyLightGun(const ByteBuffer& image, size_t size else if(port == Controller::Jack::Right) { // check for INPT5 after NOPs access - const int NUM_SIGS = 2; - const int SIG_SIZE = 6; - uInt8 signature[NUM_SIGS][SIG_SIZE] = { + static constexpr int NUM_SIGS = 2; + static constexpr int SIG_SIZE = 6; + static constexpr uInt8 signature[NUM_SIGS][SIG_SIZE] = { { 0xea, 0xea, 0xea, 0x24, 0x0d, 0x10 }, { 0xea, 0xea, 0xea, 0x24, 0x3d, 0x10 } }; // all pattern checked, only 'Bobby is Hungry' matches @@ -702,9 +701,9 @@ bool ControllerDetector::isProbablyQuadTari(const ByteBuffer& image, size_t size Controller::Jack port) { { - const int NUM_SIGS = 2; - const int SIG_SIZE = 8; - uInt8 signatureBoth[NUM_SIGS][SIG_SIZE] = { + static constexpr int NUM_SIGS = 2; + static constexpr int SIG_SIZE = 8; + static constexpr uInt8 signatureBoth[NUM_SIGS][SIG_SIZE] = { { 0x1B, 0x1F, 0x0B, 0x0E, 0x1E, 0x0B, 0x1C, 0x13 }, { 'Q', 'U', 'A', 'D', 'T', 'A', 'R', 'I' } }; // "QUADTARI" @@ -716,15 +715,15 @@ bool ControllerDetector::isProbablyQuadTari(const ByteBuffer& image, size_t size if(port == Controller::Jack::Left) { - const int SIG_SIZE = 5; - uInt8 signature[SIG_SIZE] = { 'Q', 'U', 'A', 'D', 'L' }; + static constexpr int SIG_SIZE = 5; + static constexpr uInt8 signature[SIG_SIZE] = { 'Q', 'U', 'A', 'D', 'L' }; return searchForBytes(image, size, signature, SIG_SIZE); } else if(port == Controller::Jack::Right) { - const int SIG_SIZE = 5; - uInt8 signature[SIG_SIZE] = { 'Q', 'U', 'A', 'D', 'R' }; + static constexpr int SIG_SIZE = 5; + static constexpr uInt8 signature[SIG_SIZE] = { 'Q', 'U', 'A', 'D', 'R' }; return searchForBytes(image, size, signature, SIG_SIZE); } @@ -737,8 +736,8 @@ bool ControllerDetector::isProbablyKidVid(const ByteBuffer& image, size_t size, { if(port == Controller::Jack::Right) { - const int SIG_SIZE = 5; - uInt8 signature[SIG_SIZE] = {0xA9, 0x03, 0x8D, 0x81, 0x02}; + static constexpr int SIG_SIZE = 5; + static constexpr uInt8 signature[SIG_SIZE] = {0xA9, 0x03, 0x8D, 0x81, 0x02}; return searchForBytes(image, size, signature, SIG_SIZE); } diff --git a/src/emucore/Driving.cxx b/src/emucore/Driving.cxx index 50b118dc9..c3d7be67a 100644 --- a/src/emucore/Driving.cxx +++ b/src/emucore/Driving.cxx @@ -76,7 +76,7 @@ void Driving::update() static constexpr std::array graytable = { 0x03, 0x01, 0x00, 0x02 }; // Determine which bits are set - uInt8 gray = graytable[myGrayIndex]; + const uInt8 gray = graytable[myGrayIndex]; setPin(DigitalPin::One, (gray & 0x1) != 0); setPin(DigitalPin::Two, (gray & 0x2) != 0); } @@ -113,7 +113,7 @@ void Driving::updateMouseButtons(bool& firePressed) void Driving::updateControllerAxes() { // Digital events (from keyboard or joystick hats & buttons) - int d_axis = myEvent.get(myXAxisValue); + const int d_axis = myEvent.get(myXAxisValue); if(myEvent.get(myCCWEvent) != 0 || d_axis < -16384) myCounterHires -= 64; @@ -121,7 +121,7 @@ void Driving::updateControllerAxes() myCounterHires += 64; // Analog events (from joystick axes) - int a_axis = myEvent.get(myAnalogEvent); + const int a_axis = myEvent.get(myAnalogEvent); if( abs(a_axis) > Controller::analogDeadZone()) { @@ -133,17 +133,18 @@ void Driving::updateControllerAxes() } // Only consider the lower-most bits (corresponding to pins 1 & 2) - myGrayIndex = Int32((myCounterHires / 256.0F) * SENSITIVITY) & 0b11; + myGrayIndex = static_cast((myCounterHires / 256.0F) * SENSITIVITY) & 0b11; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Driving::updateMouseAxes() { - #define MJ_Threshold 2 + static constexpr int MJ_Threshold = 2; + // Mouse motion and button events if(myControlID > -1) { - int m_axis = myEvent.get(Event::MouseAxisXMove); + const int m_axis = myEvent.get(Event::MouseAxisXMove); if(m_axis < -MJ_Threshold) --myCounter; else if(m_axis > MJ_Threshold) @@ -155,7 +156,7 @@ void Driving::updateMouseAxes() // mapped to a separate driving controller if(myControlIDX > -1) { - int m_axis = myEvent.get(Event::MouseAxisXMove); + const int m_axis = myEvent.get(Event::MouseAxisXMove); if(m_axis < -MJ_Threshold) --myCounter; else if(m_axis > MJ_Threshold) @@ -163,7 +164,7 @@ void Driving::updateMouseAxes() } if(myControlIDY > -1) { - int m_axis = myEvent.get(Event::MouseAxisYMove); + const int m_axis = myEvent.get(Event::MouseAxisYMove); if(m_axis < -MJ_Threshold) --myCounter; else if(m_axis > MJ_Threshold) @@ -175,9 +176,10 @@ void Driving::updateMouseAxes() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Driving::updateStelladaptorAxes() { - #define SA_Threshold 4096 + static constexpr int SA_Threshold = 4096; + // Stelladaptor is the only controller that should set this - int yaxis = myEvent.get(myYAxisValue); + const int yaxis = myEvent.get(myYAxisValue); // Only overwrite gray code when Stelladaptor input has changed // (that means real changes, not just analog signal jitter) diff --git a/src/emucore/Driving.hxx b/src/emucore/Driving.hxx index be885af5b..59560b9fe 100644 --- a/src/emucore/Driving.hxx +++ b/src/emucore/Driving.hxx @@ -106,8 +106,8 @@ class Driving : public Controller // Pre-compute the events we care about based on given port // This will eliminate test for left or right port in update() - Event::Type myCWEvent, myCCWEvent, myFireEvent, myAnalogEvent, - myXAxisValue, myYAxisValue; + Event::Type myCWEvent{}, myCCWEvent{}, myFireEvent{}, myAnalogEvent{}, + myXAxisValue{}, myYAxisValue{}; // Controller to emulate in normal mouse axis mode int myControlID{-1}; diff --git a/src/emucore/EmulationTiming.cxx b/src/emucore/EmulationTiming.cxx index f6bbc85da..57928bae4 100644 --- a/src/emucore/EmulationTiming.cxx +++ b/src/emucore/EmulationTiming.cxx @@ -22,7 +22,7 @@ namespace { constexpr uInt32 AUDIO_HALF_FRAMES_PER_FRAGMENT = 1; - uInt32 discreteDivCeil(uInt32 n, uInt32 d) + constexpr uInt32 discreteDivCeil(uInt32 n, uInt32 d) { return n / d + ((n % d == 0) ? 0 : 1); } @@ -171,12 +171,12 @@ void EmulationTiming::recalculate() switch (myConsoleTiming) { case ConsoleTiming::ntsc: - myAudioSampleRate = uInt32(round(mySpeedFactor * 262 * 76 * 60) / 38); + myAudioSampleRate = static_cast(round(mySpeedFactor * 262 * 76 * 60) / 38); break; case ConsoleTiming::pal: case ConsoleTiming::secam: - myAudioSampleRate = uInt32(round(mySpeedFactor * 312 * 76 * 50) / 38); + myAudioSampleRate = static_cast(round(mySpeedFactor * 312 * 76 * 50) / 38); break; default: @@ -186,9 +186,9 @@ void EmulationTiming::recalculate() myCyclesPerSecond = myAudioSampleRate * 38; myCyclesPerFrame = 76 * myLinesPerFrame; - myMaxCyclesPerTimeslice = uInt32(round(mySpeedFactor * myCyclesPerFrame * 2)); - myMinCyclesPerTimeslice = uInt32(round(mySpeedFactor * myCyclesPerFrame / 2)); - myAudioFragmentSize = uInt32(round(mySpeedFactor * AUDIO_HALF_FRAMES_PER_FRAGMENT * myLinesPerFrame)); + myMaxCyclesPerTimeslice = static_cast(round(mySpeedFactor * myCyclesPerFrame * 2)); + myMinCyclesPerTimeslice = static_cast(round(mySpeedFactor * myCyclesPerFrame / 2)); + myAudioFragmentSize = static_cast(round(mySpeedFactor * AUDIO_HALF_FRAMES_PER_FRAGMENT * myLinesPerFrame)); myPrebufferFragmentCount = discreteDivCeil( myPlaybackPeriod * myAudioSampleRate, diff --git a/src/emucore/EmulationWorker.cxx b/src/emucore/EmulationWorker.cxx index 68c444838..e534ea051 100644 --- a/src/emucore/EmulationWorker.cxx +++ b/src/emucore/EmulationWorker.cxx @@ -279,7 +279,7 @@ void EmulationWorker::dispatchEmulation(std::unique_lock& lock) if (myDispatchResult->getStatus() == DispatchResult::Status::ok) { // If emulation finished successfully, we are free to go for another round - duration timesliceSeconds(static_cast(totalCycles) / static_cast(myCyclesPerSecond)); + const duration timesliceSeconds(static_cast(totalCycles) / static_cast(myCyclesPerSecond)); myVirtualTime += duration_cast(timesliceSeconds); // If we aren't fast enough to keep up with the emulation, we stop immediatelly to avoid diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index eaff0e973..15feedb2e 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -164,8 +164,7 @@ void EventHandler::reset(EventHandlerState state) void EventHandler::addPhysicalJoystick(const PhysicalJoystickPtr& joy) { #ifdef JOYSTICK_SUPPORT - int ID = myPJoyHandler->add(joy); - if(ID < 0) + if(myPJoyHandler->add(joy) < 0) return; setActionMappings(EventMode::kEmulationMode); @@ -337,10 +336,10 @@ void EventHandler::handleMouseButtonEvent(MouseButton b, bool pressed, switch(b) { case MouseButton::LEFT: - myEvent.set(Event::MouseButtonLeftValue, int(pressed)); + myEvent.set(Event::MouseButtonLeftValue, static_cast(pressed)); break; case MouseButton::RIGHT: - myEvent.set(Event::MouseButtonRightValue, int(pressed)); + myEvent.set(Event::MouseButtonRightValue, static_cast(pressed)); break; default: return; @@ -1597,10 +1596,13 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) case Event::Combo14: case Event::Combo15: case Event::Combo16: - for(int i = 0, combo = event - Event::Combo1; i < EVENTS_PER_COMBO; ++i) + { + const int combo = event - Event::Combo1; + for(int i = 0; i < EVENTS_PER_COMBO; ++i) if(myComboTable[combo][i] != Event::NoType) handleEvent(myComboTable[combo][i], pressed, repeated); return; + } //////////////////////////////////////////////////////////////////////// // Events which relate to switches() @@ -1953,7 +1955,7 @@ void EventHandler::setComboMap() } // Erase the 'combo' array - auto ERASE_ALL = [&]() { + const auto ERASE_ALL = [&]() { for(int i = 0; i < COMBO_SIZE; ++i) for(int j = 0; j < EVENTS_PER_COMBO; ++j) myComboTable[i][j] = Event::NoType; @@ -2077,7 +2079,7 @@ bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode, bool updateMenus) { #ifdef JOYSTICK_SUPPORT - bool mapped = myPJoyHandler->addJoyHatMapping(event, mode, stick, button, hat, dir); + const bool mapped = myPJoyHandler->addJoyHatMapping(event, mode, stick, button, hat, dir); if (mapped && updateMenus) setActionMappings(mode); @@ -2150,7 +2152,7 @@ void EventHandler::saveComboMapping() for(int j = 0; j < EVENTS_PER_COMBO; ++j) { - int event = myComboTable[i][j]; + const int event = myComboTable[i][j]; // skip all NoType events if(event != Event::NoType) @@ -2298,7 +2300,7 @@ StringList EventHandler::getComboListForEvent(Event::Type event) const ostringstream buf; if(event >= Event::Combo1 && event <= Event::Combo16) { - int combo = event - Event::Combo1; + const int combo = event - Event::Combo1; for(uInt32 i = 0; i < EVENTS_PER_COMBO; ++i) { const Event::Type e = myComboTable[combo][i]; @@ -2328,7 +2330,7 @@ void EventHandler::setComboListForEvent(Event::Type event, const StringList& eve const int combo = event - Event::Combo1; for(uInt32 i = 0; i < EVENTS_PER_COMBO; ++i) { - uInt32 idx = BSPF::stringToInt(events[i]); + const uInt32 idx = BSPF::stringToInt(events[i]); if(idx < ourEmulActionList.size()) myComboTable[combo][i] = EventHandler::ourEmulActionList[idx].event; else @@ -2422,14 +2424,14 @@ Event::Type EventHandler::eventAtIndex(int idx, Event::Group group) const if(group == Event::Group::Menu) { - if(index < 0 || index >= int(ourMenuActionList.size())) + if(index < 0 || index >= static_cast(ourMenuActionList.size())) return Event::NoType; else return ourMenuActionList[index].event; } else { - if(index < 0 || index >= int(ourEmulActionList.size())) + if(index < 0 || index >= static_cast(ourEmulActionList.size())) return Event::NoType; else return ourEmulActionList[index].event; @@ -2443,14 +2445,14 @@ string EventHandler::actionAtIndex(int idx, Event::Group group) const if(group == Event::Group::Menu) { - if(index < 0 || index >= int(ourMenuActionList.size())) + if(index < 0 || index >= static_cast(ourMenuActionList.size())) return EmptyString; else return ourMenuActionList[index].action; } else { - if(index < 0 || index >= int(ourEmulActionList.size())) + if(index < 0 || index >= static_cast(ourEmulActionList.size())) return EmptyString; else return ourEmulActionList[index].action; @@ -2464,14 +2466,14 @@ string EventHandler::keyAtIndex(int idx, Event::Group group) const if(group == Event::Group::Menu) { - if(index < 0 || index >= int(ourMenuActionList.size())) + if(index < 0 || index >= static_cast(ourMenuActionList.size())) return EmptyString; else return ourMenuActionList[index].key; } else { - if(index < 0 || index >= int(ourEmulActionList.size())) + if(index < 0 || index >= static_cast(ourEmulActionList.size())) return EmptyString; else return ourEmulActionList[index].key; @@ -2505,7 +2507,7 @@ void EventHandler::setMouseControllerMode(const string& enable) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::changeMouseControllerMode(int direction) { - const int NUM_MODES = 3; + constexpr int NUM_MODES = 3; const string MODES[NUM_MODES] = {"always", "analog", "never"}; const string MSG[NUM_MODES] = {"all", "analog", "no"}; string usemouse = myOSystem.settings().getString("usemouse"); @@ -2579,7 +2581,7 @@ bool EventHandler::enterDebugMode() myOSystem.debugger().setStartState(); setState(EventHandlerState::DEBUGGER); - FBInitStatus fbstatus = myOSystem.createFrameBuffer(); + const FBInitStatus fbstatus = myOSystem.createFrameBuffer(); if(fbstatus != FBInitStatus::Success) { myOSystem.debugger().setQuitState(); diff --git a/src/emucore/FBSurface.cxx b/src/emucore/FBSurface.cxx index 0818401df..8aaadab29 100644 --- a/src/emucore/FBSurface.cxx +++ b/src/emucore/FBSurface.cxx @@ -34,7 +34,7 @@ void FBSurface::readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect std::copy_n(src, width() * height() * 4, buffer); else { - uInt32 w = std::min(rect.w(), width()); + const uInt32 w = std::min(rect.w(), width()); uInt32 h = std::min(rect.h(), height()); // Copy 'height' lines of width 'pitch' (in bytes for both) @@ -77,7 +77,7 @@ void FBSurface::line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, ColorId color) dx = -dx; dy = -dy; } - Int32 yd = dy > 0 ? 1 : -1; + const Int32 yd = dy > 0 ? 1 : -1; dy = abs(dy); Int32 err = dx / 2; // now draw the line @@ -102,7 +102,7 @@ void FBSurface::line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, ColorId color) dx = -dx; dy = -dy; } - Int32 xd = dx > 0 ? 1 : -1; + const Int32 xd = dx > 0 ? 1 : -1; dx = abs(dx); Int32 err = dy / 2; // now draw the line @@ -136,7 +136,7 @@ void FBSurface::vLine(uInt32 x, uInt32 y, uInt32 y2, ColorId color) if(!checkBounds(x, y) || !checkBounds(x, y2)) return; - uInt32* buffer = static_cast(myPixels + y * myPitch + x); + uInt32* buffer = myPixels + y * myPitch + x; while(y++ <= y2) { *buffer = myPalette[color]; @@ -174,7 +174,7 @@ void FBSurface::drawChar(const GUI::Font& font, uInt8 chr, chr -= desc.firstchar; // Get the bounding box of the character - int bbw, bbh, bbx, bby; + int bbw = 0, bbh = 0, bbx = 0, bby = 0; if(!desc.bbx) { bbw = desc.fbbw; @@ -300,14 +300,14 @@ void FBSurface::splitString(const GUI::Font& font, const string& s, int w, string& left, string& right) const { #ifdef GUI_SUPPORT - uInt32 pos; + uInt32 pos = 0; int w2 = 0; bool split = false; // SLOW algorithm to find the acceptable length. But it is good enough for now. for(pos = 0; pos < s.size(); ++pos) { - int charWidth = font.getCharWidth(s[pos]); + const int charWidth = font.getCharWidth(s[pos]); if(w2 + charWidth > w || s[pos] == '\n') { split = true; @@ -394,7 +394,6 @@ void FBSurface::drawString(const GUI::Font& font, const string& s, #ifdef GUI_SUPPORT const string ELLIPSIS = "\x1d"; // "..." const int leftX = x, rightX = x + w; - uInt32 i; int width = font.getStringWidth(s); string str; @@ -408,9 +407,9 @@ void FBSurface::drawString(const GUI::Font& font, const string& s, int w2 = font.getStringWidth(ELLIPSIS); // SLOW algorithm to find the acceptable length. But it is good enough for now. - for(i = 0; i < s.size(); ++i) + for(size_t i = 0; i < s.size(); ++i) { - int charWidth = font.getCharWidth(s[i]); + const int charWidth = font.getCharWidth(s[i]); if(w2 + charWidth > w) break; @@ -433,7 +432,7 @@ void FBSurface::drawString(const GUI::Font& font, const string& s, int x0 = x, x1 = 0; - for(i = 0; i < str.size(); ++i) + for(size_t i = 0; i < str.size(); ++i) { w = font.getCharWidth(str[i]); if(x + w > rightX) diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index 0860b202c..696e2c0f1 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -272,7 +272,7 @@ string FilesystemNode::getPathWithExt(const string& ext) const string s = _realNode->getPath(); - size_t pos = s.find_last_of('.'); + const size_t pos = s.find_last_of('.'); return (pos != string::npos) ? s.replace(pos, string::npos, ext) : s + ext; } diff --git a/src/emucore/FSNode.hxx b/src/emucore/FSNode.hxx index 74b4cf380..10802157d 100644 --- a/src/emucore/FSNode.hxx +++ b/src/emucore/FSNode.hxx @@ -72,6 +72,7 @@ class FilesystemNode * getPath()) will always return false or raise an assertion. */ FilesystemNode() = default; + ~FilesystemNode() = default; /** * Create a new FilesystemNode referring to the specified path. This is @@ -89,6 +90,8 @@ class FilesystemNode */ FilesystemNode(const FilesystemNode&) = default; FilesystemNode& operator=(const FilesystemNode&) = default; + FilesystemNode& operator=(FilesystemNode&&) = default; + FilesystemNode(FilesystemNode&&) = default; /** * Compare the name of this node to the name of another, testing for @@ -326,9 +329,9 @@ class AbstractFSNode */ AbstractFSNode() = default; AbstractFSNode(const AbstractFSNode&) = default; -// AbstractFSNode(AbstractFSNode&&) = default; + AbstractFSNode(AbstractFSNode&&) = delete; AbstractFSNode& operator=(const AbstractFSNode&) = default; -// AbstractFSNode& operator=(AbstractFSNode&&) = default; + AbstractFSNode& operator=(AbstractFSNode&&) = delete; virtual ~AbstractFSNode() = default; /* diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index c130dcfec..63648b55c 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -80,9 +80,9 @@ void FrameBuffer::initialize() // Get desktop resolution and supported renderers myBackend->queryHardware(myFullscreenDisplays, myWindowedDisplays, myRenderers); - int numDisplays = int(myWindowedDisplays.size()); + const size_t numDisplays = myWindowedDisplays.size(); - for(int display = 0; display < numDisplays; ++display) + for(size_t display = 0; display < numDisplays; ++display) { uInt32 query_w = myWindowedDisplays[display].w, query_h = myWindowedDisplays[display].h; @@ -128,8 +128,8 @@ void FrameBuffer::initialize() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int FrameBuffer::displayId(BufferType bufferType) const { - const int maxDisplay = int(myWindowedDisplays.size()) - 1; - int display; + const int maxDisplay = static_cast(myWindowedDisplays.size()) - 1; + int display = 0; if(bufferType == myBufferType) display = myBackend->getCurrentDisplayIndex(); @@ -169,7 +169,7 @@ void FrameBuffer::setupFonts() } else { - const int NUM_FONTS = 7; + constexpr int NUM_FONTS = 7; FontDesc FONT_DESC[NUM_FONTS] = {GUI::consoleDesc, GUI::consoleMediumDesc, GUI::stellaMediumDesc, GUI::stellaLargeDesc, GUI::stella12x24tDesc, GUI::stella14x28tDesc, GUI::stella16x32tDesc}; const string& dialogFont = myOSystem.settings().getString("dialogfont"); @@ -193,8 +193,8 @@ void FrameBuffer::setupFonts() // Determine minimal zoom level based on the default font // So what fits with default font should fit for any font. // However, we have to make sure all Dialogs are sized using the fontsize. - int zoom_h = (fd.height * 4 * 2) / GUI::stellaMediumDesc.height; - int zoom_w = (fd.maxwidth * 4 * 2) / GUI::stellaMediumDesc.maxwidth; + const int zoom_h = (fd.height * 4 * 2) / GUI::stellaMediumDesc.height; + const int zoom_w = (fd.maxwidth * 4 * 2) / GUI::stellaMediumDesc.maxwidth; // round to 25% steps, >= 200% myTIAMinZoom = std::max(std::max(zoom_w, zoom_h) / 4.F, 2.F); } @@ -253,7 +253,7 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type, // If the WINDOWED_SUPPORT macro is defined, we treat the system as the // former type; if not, as the latter type - int display = displayId(); + const int display = displayId(); #ifdef WINDOWED_SUPPORT // We assume that a desktop of at least minimum acceptable size means that // we're running on a 'large' system, and the window size requirements @@ -312,7 +312,7 @@ FBInitStatus FrameBuffer::createDisplay(const string& title, BufferType type, // Initialize video subsystem string pre_about = myBackend->about(); - FBInitStatus status = applyVideoMode(); + const FBInitStatus status = applyVideoMode(); // Only set phosphor once when ROM is started if(myOSystem.eventHandler().inTIAMode()) @@ -364,12 +364,12 @@ void FrameBuffer::update(UpdateMode mode) // - at the bottom of ::update(), to actually draw them (this must come // last, since they are always drawn on top of everything else). - bool forceRedraw = mode & UpdateMode::REDRAW; + const bool forceRedraw = mode & UpdateMode::REDRAW; bool redraw = forceRedraw; // Forced render without draw required if messages or dialogs were closed // Note: For dialogs only relevant when two or more dialogs were stacked - bool rerender = (mode & (UpdateMode::REDRAW | UpdateMode::RERENDER)) + const bool rerender = (mode & (UpdateMode::REDRAW | UpdateMode::RERENDER)) || myPendingRender; myPendingRender = false; @@ -387,7 +387,7 @@ void FrameBuffer::update(UpdateMode mode) if(myPausedCount-- <= 0) { - myPausedCount = uInt32(7 * myOSystem.frameRate()); + myPausedCount = static_cast(7 * myOSystem.frameRate()); showTextMessage("Paused", MessagePosition::MiddleCenter); myTIASurface->render(shade); } @@ -507,14 +507,14 @@ void FrameBuffer::update(UpdateMode mode) if(--frames <= 0) { RewindManager& r = myOSystem.state().rewindManager(); - uInt64 prevCycles = r.getCurrentCycles(); + const uInt64 prevCycles = r.getCurrentCycles(); success = r.unwindStates(1); // Determine playback speed, the faster the more the states are apart - Int64 frameCycles = 76 * std::max(myOSystem.console().tia().scanlinesLastFrame(), 240); - Int64 intervalFrames = r.getInterval() / frameCycles; - Int64 stateFrames = (r.getCurrentCycles() - prevCycles) / frameCycles; + const Int64 frameCycles = 76 * std::max(myOSystem.console().tia().scanlinesLastFrame(), 240); + const Int64 intervalFrames = r.getInterval() / frameCycles; + const Int64 stateFrames = (r.getCurrentCycles() - prevCycles) / frameCycles; //frames = intervalFrames + std::sqrt(std::max(stateFrames - intervalFrames, 0)); frames = std::round(std::sqrt(stateFrames)); @@ -688,7 +688,8 @@ void FrameBuffer::drawFrameStats(float framesPerSecond) { #ifdef GUI_SUPPORT const ConsoleInfo& info = myOSystem.console().about(); - int xPos = 2, yPos = 0; + constexpr int xPos = 2; + int yPos = 0; const GUI::Font& f = hidpiEnabled() ? infoFont() : font(); const int dy = f.getFontHeight() + 2; @@ -697,7 +698,7 @@ void FrameBuffer::drawFrameStats(float framesPerSecond) myStatsMsg.surface->invalidate(); // draw scanlines - ColorId color = myOSystem.console().tia().frameBufferScanlinesLastFrame() != + const ColorId color = myOSystem.console().tia().frameBufferScanlinesLastFrame() != myLastScanlines ? kDbgColorRed : myStatsMsg.color; ss @@ -888,12 +889,8 @@ inline bool FrameBuffer::drawMessage() // draw tickmark in the middle of the bar for(int i = 1; i < NUM_TICKMARKS; ++i) { - ColorId color; - int xt = x + swidth * i / NUM_TICKMARKS; - if(bwidth < xt - x) - color = kCheckColor; // kSliderColor; - else - color = kSliderBGColor; + const int xt = x + swidth * i / NUM_TICKMARKS; + const ColorId color = (bwidth < xt - x) ? kCheckColor : kSliderBGColor; myMsg.surface->vLine(xt, y + bheight / 2, y + bheight - 1, color); } // draw value text @@ -916,7 +913,7 @@ inline bool FrameBuffer::drawMessage() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameBuffer::setPauseDelay() { - myPausedCount = uInt32(2 * myOSystem.frameRate()); + myPausedCount = static_cast(2 * myOSystem.frameRate()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -947,12 +944,12 @@ void FrameBuffer::resetSurfaces() void FrameBuffer::setTIAPalette(const PaletteArray& rgb_palette) { // Create a TIA palette from the raw RGB data - PaletteArray tia_palette; + PaletteArray tia_palette = {0}; for(int i = 0; i < 256; ++i) { - uInt8 r = (rgb_palette[i] >> 16) & 0xff; - uInt8 g = (rgb_palette[i] >> 8) & 0xff; - uInt8 b = rgb_palette[i] & 0xff; + const uInt8 r = (rgb_palette[i] >> 16) & 0xff; + const uInt8 g = (rgb_palette[i] >> 8) & 0xff; + const uInt8 b = rgb_palette[i] & 0xff; tia_palette[i] = mapRGB(r, g, b); } @@ -1097,7 +1094,7 @@ void FrameBuffer::setFullscreen(bool enable) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameBuffer::toggleFullscreen(bool toggle) { - EventHandlerState state = myOSystem.eventHandler().state(); + const EventHandlerState state = myOSystem.eventHandler().state(); switch(state) { @@ -1172,8 +1169,8 @@ void FrameBuffer::changeOverscan(int direction) { if (fullScreen()) { - int oldOverscan = myOSystem.settings().getInt("tia.fs_overscan"); - int overscan = BSPF::clamp(oldOverscan + direction, 0, 10); + const int oldOverscan = myOSystem.settings().getInt("tia.fs_overscan"); + const int overscan = BSPF::clamp(oldOverscan + direction, 0, 10); if (overscan != oldOverscan) { @@ -1237,7 +1234,7 @@ FBInitStatus FrameBuffer::applyVideoMode() { // Update display size, in case windowed/fullscreen mode has changed const Settings& s = myOSystem.settings(); - int display = displayId(); + const int display = displayId(); if(s.getBool("fullscreen")) myVidModeHandler.setDisplaySize(myFullscreenDisplays[display], display); @@ -1254,7 +1251,7 @@ FBInitStatus FrameBuffer::applyVideoMode() // Changing the video mode can take some time, during which the last // sound played may get 'stuck' // So we mute the sound until the operation completes - bool oldMuteState = myOSystem.sound().mute(true); + const bool oldMuteState = myOSystem.sound().mute(true); FBInitStatus status = FBInitStatus::FailNotSupported; if(myBackend->setVideoMode(mode, @@ -1295,14 +1292,14 @@ FBInitStatus FrameBuffer::applyVideoMode() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - float FrameBuffer::maxWindowZoom() const { - int display = displayId(BufferType::Emulator); + const int display = displayId(BufferType::Emulator); float multiplier = 1; for(;;) { // Figure out the zoomed size of the window - uInt32 width = TIAConstants::viewableWidth * multiplier; - uInt32 height = TIAConstants::viewableHeight * multiplier; + const uInt32 width = TIAConstants::viewableWidth * multiplier; + const uInt32 height = TIAConstants::viewableHeight * multiplier; if((width > myAbsDesktopSize[display].w) || (height > myAbsDesktopSize[display].h)) break; @@ -1357,15 +1354,15 @@ bool FrameBuffer::grabMouseAllowed() { // Allow grabbing mouse in emulation (if enabled) and emulating a controller // that always uses the mouse - bool emulation = + const bool emulation = myOSystem.eventHandler().state() == EventHandlerState::EMULATION; - bool analog = myOSystem.hasConsole() ? + const bool analog = myOSystem.hasConsole() ? (myOSystem.console().leftController().isAnalog() || myOSystem.console().rightController().isAnalog()) : false; - bool usesLightgun = emulation && myOSystem.hasConsole() ? + const bool usesLightgun = emulation && myOSystem.hasConsole() ? myOSystem.console().leftController().type() == Controller::Type::Lightgun || myOSystem.console().rightController().type() == Controller::Type::Lightgun : false; - bool alwaysUseMouse = BSPF::equalsIgnoreCase("always", myOSystem.settings().getString("usemouse")); + const bool alwaysUseMouse = BSPF::equalsIgnoreCase("always", myOSystem.settings().getString("usemouse")); // Disable grab while cursor is shown in emulation bool cursorHidden = !(myOSystem.settings().getInt("cursor") & 1); diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index e69f12ce9..ae4722e8b 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -556,7 +556,7 @@ class FrameBuffer // Maximum gauge bar width [chars] static constexpr int GAUGEBAR_WIDTH = 30; - FullPaletteArray myFullPalette; + FullPaletteArray myFullPalette{0}; // Holds UI palette data (for each variation) static UIPaletteArray ourStandardUIPalette, ourClassicUIPalette, ourLightUIPalette, ourDarkUIPalette; diff --git a/src/emucore/GlobalKeyHandler.cxx b/src/emucore/GlobalKeyHandler.cxx index 0b3245fe1..381b63f70 100644 --- a/src/emucore/GlobalKeyHandler.cxx +++ b/src/emucore/GlobalKeyHandler.cxx @@ -67,8 +67,9 @@ bool GlobalKeyHandler::handleEvent(const Event::Type event, bool pressed, bool r if(pressed && !repeated) { const int direction = (event == Event::PreviousSettingGroup ? -1 : +1); - Group group = Group(BSPF::clampw(int(getGroup()) + direction, - 0, int(Group::NUM_GROUPS) - 1)); + const Group group = static_cast( + BSPF::clampw(static_cast(getGroup()) + direction, + 0, static_cast(Group::NUM_GROUPS) - 1)); const std::map GroupMap = { {Group::AV, {Setting::START_AV_ADJ, "Audio & Video"}}, {Group::INPUT, {Setting::START_INPUT_ADJ, "Input Devices & Ports"}}, @@ -201,7 +202,7 @@ bool GlobalKeyHandler::skipAVSetting() const const bool isCustomPalette = myOSystem.settings().getString("palette") == PaletteHandler::SETTING_CUSTOM; const bool isCustomFilter = - myOSystem.settings().getInt("tv.filter") == int(NTSCFilter::Preset::CUSTOM); + myOSystem.settings().getInt("tv.filter") == static_cast(NTSCFilter::Preset::CUSTOM); const bool hasScanlines = myOSystem.settings().getInt("tv.scanlines") > 0; const bool isSoftwareRenderer = @@ -291,25 +292,25 @@ const GlobalKeyHandler::Function GlobalKeyHandler::cycleSetting(int direction) switch(getGroup()) { case Group::AV: - mySetting = - Setting(BSPF::clampw(int(mySetting) + direction, - int(Setting::START_AV_ADJ), int(Setting::END_AV_ADJ))); + mySetting = static_cast( + BSPF::clampw(static_cast(mySetting) + direction, + static_cast(Setting::START_AV_ADJ), static_cast(Setting::END_AV_ADJ))); // skip currently non-relevant adjustments skip = skipAVSetting(); break; case Group::INPUT: - mySetting = - Setting(BSPF::clampw(int(mySetting) + direction, - int(Setting::START_INPUT_ADJ), int(Setting::END_INPUT_ADJ))); + mySetting = static_cast( + BSPF::clampw(static_cast(mySetting) + direction, + static_cast(Setting::START_INPUT_ADJ), static_cast(Setting::END_INPUT_ADJ))); // skip currently non-relevant adjustments skip = skipInputSetting(); break; case Group::DEBUG: - mySetting = - Setting(BSPF::clampw(int(mySetting) + direction, - int(Setting::START_DEBUG_ADJ), int(Setting::END_DEBUG_ADJ))); + mySetting = static_cast( + BSPF::clampw(static_cast(mySetting) + direction, + static_cast(Setting::START_DEBUG_ADJ), static_cast(Setting::END_DEBUG_ADJ))); // skip currently non-relevant adjustments skip = skipDebugSetting(); break; @@ -375,15 +376,15 @@ GlobalKeyHandler::SettingData GlobalKeyHandler::getSettingData(const Setting set // NTSC filter adjustables {Setting::NTSC_PRESET, {false, std::bind(&TIASurface::changeNTSC, &myOSystem.frameBuffer().tiaSurface(), _1)}}, {Setting::NTSC_SHARPNESS, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(), - int(NTSCFilter::Adjustables::SHARPNESS), _1)}}, + static_cast(NTSCFilter::Adjustables::SHARPNESS), _1)}}, {Setting::NTSC_RESOLUTION, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(), - int(NTSCFilter::Adjustables::RESOLUTION), _1)}}, + static_cast(NTSCFilter::Adjustables::RESOLUTION), _1)}}, {Setting::NTSC_ARTIFACTS, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(), - int(NTSCFilter::Adjustables::ARTIFACTS), _1)}}, + static_cast(NTSCFilter::Adjustables::ARTIFACTS), _1)}}, {Setting::NTSC_FRINGING, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(), - int(NTSCFilter::Adjustables::FRINGING), _1)}}, + static_cast(NTSCFilter::Adjustables::FRINGING), _1)}}, {Setting::NTSC_BLEEDING, {true, std::bind(&TIASurface::changeNTSCAdjustable, &myOSystem.frameBuffer().tiaSurface(), - int(NTSCFilter::Adjustables::BLEEDING), _1)}}, + static_cast(NTSCFilter::Adjustables::BLEEDING), _1)}}, // Other TV effects adjustables {Setting::PHOSPHOR, {true, std::bind(&Console::changePhosphor, &myOSystem.console(), _1)}}, {Setting::SCANLINES, {true, std::bind(&TIASurface::changeScanlineIntensity, &myOSystem.frameBuffer().tiaSurface(), _1)}}, @@ -448,7 +449,7 @@ GlobalKeyHandler::SettingData GlobalKeyHandler::getSettingData(const Setting set return result->second; else { - cerr << "Error: setting " << int(setting) << " missing in SettingMap!" << endl; + cerr << "Error: setting " << static_cast(setting) << " missing in SettingMap!" << endl; return SettingMap.find(Setting::VOLUME)->second; // default function! } } diff --git a/src/emucore/Joystick.cxx b/src/emucore/Joystick.cxx index 8fd44ac25..fc702df69 100644 --- a/src/emucore/Joystick.cxx +++ b/src/emucore/Joystick.cxx @@ -115,9 +115,9 @@ void Joystick::updateMouseAxes() if(myControlID > -1) { // The following code was taken from z26 - #define MJ_Threshold 2 - int mousex = myEvent.get(Event::MouseAxisXMove), - mousey = myEvent.get(Event::MouseAxisYMove); + static constexpr int MJ_Threshold = 2; + const int mousex = myEvent.get(Event::MouseAxisXMove), + mousey = myEvent.get(Event::MouseAxisYMove); if(mousex || mousey) { diff --git a/src/emucore/Keyboard.cxx b/src/emucore/Keyboard.cxx index 38b8d4afa..8911bd71d 100644 --- a/src/emucore/Keyboard.cxx +++ b/src/emucore/Keyboard.cxx @@ -93,9 +93,9 @@ void Keyboard::write(DigitalPin pin, bool value) const Event::Type col1[] = {myTwoEvent, myFiveEvent, myEightEvent, myZeroEvent}; const Event::Type col2[] = {myThreeEvent, mySixEvent, myNineEvent, myPoundEvent}; - ColumnState stateCol0 = processColumn(col0); - ColumnState stateCol1 = processColumn(col1); - ColumnState stateCol2 = processColumn(col2); + const ColumnState stateCol0 = processColumn(col0); + const ColumnState stateCol1 = processColumn(col1); + const ColumnState stateCol2 = processColumn(col2); setPin(DigitalPin::Six, stateCol2 == ColumnState::gnd ? 0 : 1); setPin(AnalogPin::Five, columnStateToAnalogSignal(stateCol1)); diff --git a/src/emucore/KidVid.cxx b/src/emucore/KidVid.cxx index e31369d85..abf8f5ca2 100644 --- a/src/emucore/KidVid.cxx +++ b/src/emucore/KidVid.cxx @@ -212,7 +212,7 @@ void KidVid::setNextSong() { myBeep = (ourSongPositions[myFilePointer] & 0x80) ? false : true; - uInt8 temp = ourSongPositions[myFilePointer] & 0x7f; + const uInt8 temp = ourSongPositions[myFilePointer] & 0x7f; mySharedData = (temp < 10); mySongCounter = ourSongStart[temp+1] - ourSongStart[temp]; diff --git a/src/emucore/Lightgun.cxx b/src/emucore/Lightgun.cxx index 591ec80b6..fc031a2d2 100644 --- a/src/emucore/Lightgun.cxx +++ b/src/emucore/Lightgun.cxx @@ -89,21 +89,21 @@ bool Lightgun::read(DigitalPin pin) if (rect.w() == 0 || rect.h() == 0) return false; - TIA& tia = mySystem.tia(); + const TIA& tia = mySystem.tia(); // scale mouse coordinates into TIA coordinates - Int32 xMouse = (myEvent.get(Event::MouseAxisXValue) - rect.x()) - * tia.width() / rect.w(); - Int32 yMouse = (myEvent.get(Event::MouseAxisYValue) - rect.y()) - * tia.height() / rect.h(); + const Int32 xMouse = (myEvent.get(Event::MouseAxisXValue) - rect.x()) + * tia.width() / rect.w(); + const Int32 yMouse = (myEvent.get(Event::MouseAxisYValue) - rect.y()) + * tia.height() / rect.h(); // get adjusted TIA coordinates Int32 xTia = tia.clocksThisLine() - TIAConstants::H_BLANK_CLOCKS + myOfsX; - Int32 yTia = tia.scanlines() - tia.startLine() + myOfsY; + const Int32 yTia = tia.scanlines() - tia.startLine() + myOfsY; if (xTia < 0) xTia += TIAConstants::H_CLOCKS; - bool enable = !((xTia - xMouse) >= 0 && (xTia - xMouse) < 15 && (yTia - yMouse) >= 0); + const bool enable = !((xTia - xMouse) >= 0 && (xTia - xMouse) < 15 && (yTia - yMouse) >= 0); return enable; } diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index 1d2d553ca..abf913adf 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -81,7 +81,7 @@ void M6502::reset() icycles = 0; // Load PC from the reset vector - PC = uInt16(mySystem->peek(0xfffc)) | (uInt16(mySystem->peek(0xfffd)) << 8); + PC = static_cast(mySystem->peek(0xfffc)) | (static_cast(mySystem->peek(0xfffd)) << 8); myLastAddress = myLastPeekAddress = myLastPokeAddress = myLastPeekBaseAddress = myLastPokeBaseAddress; myLastSrcAddressS = myLastSrcAddressA = @@ -114,7 +114,7 @@ inline uInt8 M6502::peek(uInt16 address, Device::AccessFlags flags) mySystem->incrementCycles(SYSTEM_CYCLES_PER_CPU); icycles += SYSTEM_CYCLES_PER_CPU; myFlags = flags; - uInt8 result = mySystem->peek(address, flags); + const uInt8 result = mySystem->peek(address, flags); myLastPeekAddress = address; #ifdef DEBUGGER_SUPPORT @@ -122,7 +122,7 @@ inline uInt8 M6502::peek(uInt16 address, Device::AccessFlags flags) && (myGhostReadsTrap || flags != DISASM_NONE)) { myLastPeekBaseAddress = myDebugger->getBaseAddress(myLastPeekAddress, true); // mirror handling - int cond = evalCondTraps(); + const int cond = evalCondTraps(); if(cond > -1) { myJustHitReadTrapFlag = true; @@ -158,7 +158,7 @@ inline void M6502::poke(uInt16 address, uInt8 value, Device::AccessFlags flags) if(myWriteTraps.isInitialized() && myWriteTraps.isSet(address)) { myLastPokeBaseAddress = myDebugger->getBaseAddress(myLastPokeAddress, false); // mirror handling - int cond = evalCondTraps(); + const int cond = evalCondTraps(); if(cond > -1) { myJustHitWriteTrapFlag = true; @@ -227,7 +227,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) M6532& riot = mySystem->m6532(); #endif - uInt64 previousCycles = mySystem->cycles(); + const uInt64 previousCycles = mySystem->cycles(); uInt64 currentCycles = 0; // Loop until execution is stopped or a fatal error occurs @@ -240,7 +240,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) if (myLastBreakCycle != mySystem->cycles()) { if(myJustHitReadTrapFlag || myJustHitWriteTrapFlag) { - bool read = myJustHitReadTrapFlag; + const bool read = myJustHitReadTrapFlag; myJustHitReadTrapFlag = myJustHitWriteTrapFlag = false; myLastBreakCycle = mySystem->cycles(); @@ -258,7 +258,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) if(myBreakPoints.isInitialized()) { - uInt8 bank = mySystem->cart().getBank(PC); + const uInt8 bank = mySystem->cart().getBank(PC); if(myBreakPoints.check(PC, bank)) { @@ -277,7 +277,8 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) { ostringstream msg; - msg << "BP: $" << Common::Base::HEX4 << PC << ", bank #" << std::dec << int(bank); + msg << "BP: $" << Common::Base::HEX4 << PC << ", bank #" + << std::dec << static_cast(bank); result.setDebugger(currentCycles, msg.str(), "Breakpoint"); return; } @@ -285,7 +286,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) } } - int cond = evalCondBreaks(); + const int cond = evalCondBreaks(); if(cond > -1) { ostringstream msg; @@ -306,7 +307,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) } } - int cond = evalCondSaveStates(); + const int cond = evalCondSaveStates(); if(cond > -1) { ostringstream msg; @@ -326,7 +327,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) icycles = 0; #ifdef DEBUGGER_SUPPORT - uInt16 oldPC = PC; + const uInt16 oldPC = PC; #endif // Fetch instruction at the program counter @@ -345,7 +346,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) #ifdef DEBUGGER_SUPPORT if(myReadFromWritePortBreak) { - uInt16 rwpAddr = mySystem->cart().getIllegalRAMReadAccess(); + const uInt16 rwpAddr = mySystem->cart().getIllegalRAMReadAccess(); if(rwpAddr) { ostringstream msg; @@ -357,7 +358,7 @@ inline void M6502::_execute(uInt64 cycles, DispatchResult& result) if (myWriteToReadPortBreak) { - uInt16 wrpAddr = mySystem->cart().getIllegalRAMWriteAccess(); + const uInt16 wrpAddr = mySystem->cart().getIllegalRAMWriteAccess(); if (wrpAddr) { ostringstream msg; @@ -433,7 +434,7 @@ void M6502::interruptHandler() mySystem->poke(0x0100 + SP--, PS() & (~0x10)); D = false; I = true; - PC = uInt16(mySystem->peek(0xFFFE)) | (uInt16(mySystem->peek(0xFFFF)) << 8); + PC = static_cast(mySystem->peek(0xFFFE)) | (static_cast(mySystem->peek(0xFFFF)) << 8); } else if(myExecutionStatus & NonmaskableInterruptBit) { @@ -442,7 +443,7 @@ void M6502::interruptHandler() mySystem->poke(0x0100 + SP--, (PC - 1) & 0x00ff); mySystem->poke(0x0100 + SP--, PS() & (~0x10)); D = false; - PC = uInt16(mySystem->peek(0xFFFA)) | (uInt16(mySystem->peek(0xFFFB)) << 8); + PC = static_cast(mySystem->peek(0xFFFA)) | (static_cast(mySystem->peek(0xFFFB)) << 8); } // Clear the interrupt bits in myExecutionStatus @@ -563,7 +564,7 @@ uInt32 M6502::addCondBreak(Expression* e, const string& name, bool oneShot) updateStepStateByInstruction(); - return uInt32(myCondBreaks.size() - 1); + return static_cast(myCondBreaks.size() - 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -604,7 +605,7 @@ uInt32 M6502::addCondSaveState(Expression* e, const string& name) updateStepStateByInstruction(); - return uInt32(myCondSaveStates.size() - 1); + return static_cast(myCondSaveStates.size() - 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -645,7 +646,7 @@ uInt32 M6502::addCondTrap(Expression* e, const string& name) updateStepStateByInstruction(); - return uInt32(myTrapConds.size() - 1); + return static_cast(myTrapConds.size() - 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/M6532.cxx b/src/emucore/M6532.cxx index c9d2a92ea..e5a2e7ef0 100644 --- a/src/emucore/M6532.cxx +++ b/src/emucore/M6532.cxx @@ -91,7 +91,7 @@ void M6532::update() Controller& rport = myConsole.rightController(); // Get current PA7 state - bool prevPA7 = lport.getPin(Controller::DigitalPin::Four); + const bool prevPA7 = lport.getPin(Controller::DigitalPin::Four); // Update entire port state lport.update(); @@ -99,7 +99,7 @@ void M6532::update() myConsole.switches().update(); // Get new PA7 state - bool currPA7 = lport.getPin(Controller::DigitalPin::Four); + const bool currPA7 = lport.getPin(Controller::DigitalPin::Four); // PA7 Flag is set on active transition in appropriate direction if((!myEdgeDetectPositive && prevPA7 && !currPA7) || @@ -110,8 +110,8 @@ void M6532::update() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void M6532::updateEmulation() { - uInt32 cycles = uInt32(mySystem->cycles() - myLastCycle); - uInt32 subTimer = mySubTimer; + uInt32 cycles = static_cast(mySystem->cycles() - myLastCycle); + const uInt32 subTimer = mySubTimer; // Guard against further state changes if the debugger alread forwarded emulation // state (in particular myWrappedThisCycle) @@ -122,7 +122,7 @@ void M6532::updateEmulation() if ((myInterruptFlag & TimerBit) == 0) { - uInt32 timerTicks = (cycles + subTimer) / myDivider; + const uInt32 timerTicks = (cycles + subTimer) / myDivider; if(timerTicks > myTimer) { @@ -164,7 +164,7 @@ void M6532::installDelegate(System& system, Device& device) mySystem = &system; // All accesses are to the given device - System::PageAccess access(&device, System::PageAccessType::READWRITE); + const System::PageAccess access(&device, System::PageAccessType::READWRITE); // Map all peek/poke to mirrors of RIOT address space to this class // That is, all mirrors of ZP RAM ($80 - $FF) and IO ($280 - $29F) in the @@ -194,8 +194,8 @@ uInt8 M6532::peek(uInt16 addr) { case 0x00: // SWCHA - Port A I/O Register (Joystick) { - uInt8 value = (myConsole.leftController().read() << 4) | - myConsole.rightController().read(); + const uInt8 value = (myConsole.leftController().read() << 4) | + myConsole.rightController().read(); // Each pin is high (1) by default and will only go low (0) if either // (a) External device drives the pin low @@ -235,7 +235,7 @@ uInt8 M6532::peek(uInt16 addr) case 0x07: { // PA7 Flag is always cleared after accessing TIMINT - uInt8 result = myInterruptFlag; + const uInt8 result = myInterruptFlag; myInterruptFlag &= ~PA7Bit; #ifdef DEBUGGER_SUPPORT myTimReadCycles += 7; @@ -308,6 +308,9 @@ bool M6532::poke(uInt16 addr, uInt8 value) myDDRB = value; break; } + + default: // satisfy compiler + break; } } return true; @@ -349,7 +352,7 @@ void M6532::setPinState(bool swcha) Controller& lport = myConsole.leftController(); Controller& rport = myConsole.rightController(); - uInt8 ioport = myOutA | ~myDDRA; + const uInt8 ioport = myOutA | ~myDDRA; lport.write(Controller::DigitalPin::One, ioport & 0b00010000); lport.write(Controller::DigitalPin::Two, ioport & 0b00100000); @@ -469,7 +472,7 @@ Int32 M6532::intimClocks() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 M6532::timerClocks() const { - return uInt32(mySystem->cycles() - mySetTimerCycle); + return static_cast(mySystem->cycles() - mySetTimerCycle); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/MD5.cxx b/src/emucore/MD5.cxx index 0b535db36..c6c18b72e 100644 --- a/src/emucore/MD5.cxx +++ b/src/emucore/MD5.cxx @@ -76,11 +76,11 @@ struct MD5_CTX #define S44 21 static void MD5Init(MD5_CTX*); -static void MD5Update(MD5_CTX*, const uInt8*, uInt32); +static void MD5Update(MD5_CTX*, const uInt8* const, uInt32); static void MD5Final(uInt8[16], MD5_CTX*); -static void MD5Transform(uInt32 [4], const uInt8 [64]); -static void Encode(uInt8*, uInt32*, uInt32); -static void Decode(uInt32*, const uInt8*, uInt32); +static void MD5Transform(uInt32[4], const uInt8[64]); +static void Encode(uInt8*, const uInt32* const, uInt32); +static void Decode(uInt32*, const uInt8* const, uInt32); static uInt8 PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -134,26 +134,24 @@ static void MD5Init(MD5_CTX* context) // MD5 block update operation. Continues an MD5 message-digest // operation, processing another message block, and updating the // context. -static void MD5Update(MD5_CTX* context, const uInt8* input, +static void MD5Update(MD5_CTX* context, const uInt8* const input, uInt32 inputLen) { - uInt32 i, index, partLen; + uInt32 i = 0; /* Compute number of bytes mod 64 */ - index = uInt32((context->count[0] >> 3) & 0x3F); + uInt32 index = static_cast((context->count[0] >> 3) & 0x3F); /* Update number of bits */ - if ((context->count[0] += (uInt32(inputLen) << 3)) - < (uInt32(inputLen) << 3)) + if ((context->count[0] += (inputLen << 3)) < (inputLen << 3)) context->count[1]++; - context->count[1] += (uInt32(inputLen) >> 29); + context->count[1] += (inputLen >> 29); - partLen = 64 - index; + const uInt32 partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { - memcpy (const_cast(&context->buffer[index]), - const_cast(input), partLen); + memcpy (&context->buffer[index], input, partLen); MD5Transform (context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) @@ -165,8 +163,7 @@ static void MD5Update(MD5_CTX* context, const uInt8* input, i = 0; /* Buffer remaining input */ - memcpy(const_cast(&context->buffer[index]), - const_cast(&input[i]), inputLen-i); + memcpy(&context->buffer[index], &input[i], inputLen-i); } // MD5 finalization. Ends an MD5 message-digest operation, writing the @@ -174,14 +171,13 @@ static void MD5Update(MD5_CTX* context, const uInt8* input, static void MD5Final(uInt8 digest[16], MD5_CTX* context) { uInt8 bits[8]; - uInt32 index, padLen; /* Save number of bits */ Encode (bits, context->count, 8); /* Pad out to 56 mod 64. */ - index = uInt32((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); + const uInt32 index = static_cast((context->count[0] >> 3) & 0x3f); + const uInt32 padLen = (index < 56) ? (56 - index) : (120 - index); MD5Update (context, PADDING, padLen); /* Append length (before padding) */ @@ -283,29 +279,28 @@ static void MD5Transform(uInt32 state[4], const uInt8 block[64]) // Encodes input (uInt32) into output (uInt8). Assumes len is // a multiple of 4. -static void Encode(uInt8* output, uInt32* input, uInt32 len) +static void Encode(uInt8* output, const uInt32* const input, uInt32 len) { - uInt32 i, j; - - for (i = 0, j = 0; j < len; ++i, j += 4) { - output[j] = uInt8(input[i] & 0xff); - output[j+1] = uInt8((input[i] >> 8) & 0xff); - output[j+2] = uInt8((input[i] >> 16) & 0xff); - output[j+3] = uInt8((input[i] >> 24) & 0xff); + for (uInt32 i = 0, j = 0; j < len; ++i, j += 4) { + output[j] = static_cast(input[i] & 0xff); + output[j+1] = static_cast((input[i] >> 8) & 0xff); + output[j+2] = static_cast((input[i] >> 16) & 0xff); + output[j+3] = static_cast((input[i] >> 24) & 0xff); } } // Decodes input (uInt8) into output (uInt32). Assumes len is // a multiple of 4. -static void Decode(uInt32* output, const uInt8* input, uInt32 len) +static void Decode(uInt32* output, const uInt8* const input, uInt32 len) { - uInt32 i, j; - - for (i = 0, j = 0; j < len; ++i, j += 4) - output[i] = (uInt32(input[j])) | ((uInt32(input[j+1])) << 8) | - ((uInt32(input[j+2])) << 16) | ((uInt32(input[j+3])) << 24); + for (uInt32 i = 0, j = 0; j < len; ++i, j += 4) + output[i] = (static_cast(input[j])) + | ((static_cast(input[j+1])) << 8) + | ((static_cast(input[j+2])) << 16) + | ((static_cast(input[j+3])) << 24); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string hash(const string& buffer) { std::vector vec(buffer.begin(), buffer.end()); @@ -322,10 +317,10 @@ string hash(const ByteBuffer& buffer, size_t length) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string hash(const uInt8* buffer, size_t length) { - char hex[] = "0123456789abcdef"; - MD5_CTX context; - uInt8 md5[16]; - uInt32 len32 = static_cast(length); // Always use 32-bit for now + constexpr char hex[] = "0123456789abcdef"; + MD5_CTX context{}; + uInt8 md5[16] = {0}; + const uInt32 len32 = static_cast(length); // Always use 32-bit for now MD5Init(&context); MD5Update(&context, buffer, len32); diff --git a/src/emucore/MT24LC256.cxx b/src/emucore/MT24LC256.cxx index ea9c945e5..d9c6ed709 100644 --- a/src/emucore/MT24LC256.cxx +++ b/src/emucore/MT24LC256.cxx @@ -382,8 +382,8 @@ bool MT24LC256::jpee_timercheck(int mode) { if(myTimerActive) { - uInt64 elapsed = mySystem.cycles() - myCyclesWhenTimerSet; - myTimerActive = elapsed < uInt64(5000000.0 / 838.0); + const uInt64 elapsed = mySystem.cycles() - myCyclesWhenTimerSet; + myTimerActive = elapsed < static_cast(5000000.0 / 838.0); } return myTimerActive; } diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 1e913e914..3930502b5 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -272,9 +272,9 @@ void OSystem::saveConfig() void OSystem::setConfigPaths() { // Make sure all required directories actually exist - auto buildDirIfRequired = [](FilesystemNode& path, - const FilesystemNode& initialPath, - const string& pathToAppend = EmptyString) + const auto buildDirIfRequired = [](FilesystemNode& path, + const FilesystemNode& initialPath, + const string& pathToAppend = EmptyString) { path = initialPath; if(pathToAppend != EmptyString) @@ -341,7 +341,7 @@ bool OSystem::checkUserPalette(bool outputError) const try { ByteBuffer palette; - size_t size = paletteFile().read(palette); + const size_t size = paletteFile().read(palette); // Make sure the contains enough data for the NTSC, PAL and SECAM palettes // This means 128 colours each for NTSC and PAL, at 3 bytes per pixel @@ -638,7 +638,7 @@ unique_ptr OSystem::openConsole(const FilesystemNode& romfile, string& myPropSet->getMD5(md5, props); // Local helper method - auto CMDLINE_PROPS_UPDATE = [&](const string& name, PropType prop) + const auto CMDLINE_PROPS_UPDATE = [&](const string& name, PropType prop) { const string& s = mySettings->getString(name); if(s != "") props.set(prop, s); @@ -744,7 +744,7 @@ ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, size_t& size // First check if this is a 'streaming' ROM (one where we only read // a portion of the file) - size_t sizeToRead = CartDetector::isProbablyMVC(rom); + const size_t sizeToRead = CartDetector::isProbablyMVC(rom); // Next check if rom is a valid size // TODO: We should check if ROM is < Cart::maxSize(), but only @@ -798,7 +798,7 @@ double OSystem::dispatchEmulation(EmulationWorker& emulationWorker) DispatchResult dispatchResult; // Check whether we have a frame pending for rendering... - bool framePending = tia.newFramePending(); + const bool framePending = tia.newFramePending(); // ... and copy it to the frame buffer. It is important to do this before // the worker is started to avoid racing. if (framePending) { @@ -821,7 +821,7 @@ double OSystem::dispatchEmulation(EmulationWorker& emulationWorker) if (framePending) myFrameBuffer->updateInEmulationMode(myFpsMeter.fps()); // Stop the worker and wait until it has finished - uInt64 totalCycles = emulationWorker.stop(); + const uInt64 totalCycles = emulationWorker.stop(); // Handle the dispatch result switch (dispatchResult.getStatus()) { @@ -874,7 +874,7 @@ void OSystem::mainLoop() for(;;) { - bool wasEmulation = myEventHandler->state() == EventHandlerState::EMULATION; + const bool wasEmulation = myEventHandler->state() == EventHandlerState::EMULATION; myEventHandler->poll(TimerManager::getTicks()); if(myQuitLoop) break; // Exit if the user wants to quit @@ -903,12 +903,12 @@ void OSystem::mainLoop() myFrameBuffer->update(); } - duration timeslice(timesliceSeconds); + const duration timeslice(timesliceSeconds); virtualTime += duration_cast(timeslice); - time_point now = high_resolution_clock::now(); + const time_point now = high_resolution_clock::now(); // We allow 6507 time to lag behind by one frame max - double maxLag = myConsole + const double maxLag = myConsole ? ( static_cast(myConsole->emulationTiming().cyclesPerFrame()) / static_cast(myConsole->emulationTiming().cyclesPerSecond()) diff --git a/src/emucore/Paddles.cxx b/src/emucore/Paddles.cxx index d17428fb3..4a9313fe1 100644 --- a/src/emucore/Paddles.cxx +++ b/src/emucore/Paddles.cxx @@ -185,7 +185,7 @@ void Paddles::updateA() // Only change state if the charge has actually changed if(myCharge[0] != myLastCharge[0]) { - setPin(AnalogPin::Nine, AnalogReadout::connectToVcc(MAX_RESISTANCE * (myCharge[0] / double(TRIGMAX)))); + setPin(AnalogPin::Nine, AnalogReadout::connectToVcc(MAX_RESISTANCE * (myCharge[0] / double{TRIGMAX}))); myLastCharge[0] = myCharge[0]; } } @@ -222,7 +222,7 @@ AnalogReadout::Connection Paddles::getReadOut(int lastAxis, int& newAxis, int ce const float diffFactor = dFac[DEJITTER_DIFF]; // dejitter, suppress small changes only - float dejitter = powf(baseFactor, std::abs(newAxis - lastAxis) * diffFactor); + const float dejitter = powf(baseFactor, std::abs(newAxis - lastAxis) * diffFactor); int newVal = newAxis * (1 - dejitter) + lastAxis * dejitter; // only use new dejittered value for larger differences @@ -245,7 +245,7 @@ AnalogReadout::Connection Paddles::getReadOut(int lastAxis, int& newAxis, int ce // scale result return AnalogReadout::connectToVcc(MAX_RESISTANCE * BSPF::clamp((ANALOG_MAX_VALUE - (scaledAxis * SENSITIVITY + center)) / - float(ANALOG_RANGE), 0.F, 1.F)); + float{ANALOG_RANGE}, 0.F, 1.F)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -357,7 +357,7 @@ void Paddles::updateB() // Only change state if the charge has actually changed if(myCharge[1] != myLastCharge[1]) { - setPin(AnalogPin::Five, AnalogReadout::connectToVcc(MAX_RESISTANCE * (myCharge[1] / double(TRIGMAX)))); + setPin(AnalogPin::Five, AnalogReadout::connectToVcc(MAX_RESISTANCE * (myCharge[1] / double{TRIGMAX}))); myLastCharge[1] = myCharge[1]; } } @@ -542,7 +542,7 @@ void Paddles::setDigitalSensitivity(int sensitivity) void Paddles::setDigitalPaddleRange(int range) { range = BSPF::clamp(range, MIN_MOUSE_RANGE, MAX_MOUSE_RANGE); - TRIGRANGE = int(TRIGMAX * (range / 100.0)); + TRIGRANGE = static_cast(TRIGMAX * (range / 100.0)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/PlusROM.cxx b/src/emucore/PlusROM.cxx index 7226b2b72..0edf4fb90 100644 --- a/src/emucore/PlusROM.cxx +++ b/src/emucore/PlusROM.cxx @@ -200,6 +200,8 @@ PlusROM::PlusROM(const Settings& settings, const Cartridge& cart) : mySettings{settings}, myCart{cart} { + myRxBuffer.fill(0); + myTxBuffer.fill(0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -272,6 +274,9 @@ bool PlusROM::peekHotspot(uInt16 address, uInt8& value) receive(); value = myRxWritePos - myRxReadPos; return true; + + default: // satisfy compiler + break; } #endif return false; @@ -305,6 +310,9 @@ bool PlusROM::pokeHotspot(uInt16 address, uInt8 value) case RECEIVE_BUFFER_SIZE: // Get number of unread bytes in Rx buffer receive(); break; + + default: // satisfy compiler + break; } #endif return false; @@ -466,7 +474,7 @@ void PlusROM::receive() myMsgCallback("PlusROM data received successfully"); // Request has finished sucessfully? -> consume the response, remove it // and start over - auto [responseSize, response] = (*iter)->getResponse(); + const auto [responseSize, response] = (*iter)->getResponse(); for(uInt8 i = 0; i < responseSize; i++) myRxBuffer[myRxWritePos++] = response[i]; diff --git a/src/emucore/PointingDevice.cxx b/src/emucore/PointingDevice.cxx index 6402a0561..1867b0b42 100644 --- a/src/emucore/PointingDevice.cxx +++ b/src/emucore/PointingDevice.cxx @@ -39,7 +39,7 @@ PointingDevice::PointingDevice(Jack jack, const Event& event, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 PointingDevice::read() { - int scanline = mySystem.tia().scanlines(); + const int scanline = mySystem.tia().scanlines(); // Loop over all missed changes while(myScanCountH < scanline) @@ -64,7 +64,7 @@ uInt8 PointingDevice::read() myCountH &= 0b11; myCountV &= 0b11; - uInt8 portA = ioPortA(myCountH, myCountV, myTrackBallLeft, myTrackBallDown); + const uInt8 portA = ioPortA(myCountH, myCountV, myTrackBallLeft, myTrackBallDown); setPin(DigitalPin::One, portA & 0b0001); setPin(DigitalPin::Two, portA & 0b0010); @@ -119,8 +119,8 @@ void PointingDevice::updateDirection(int counter, float& counterRemainder, bool& trackBallDir, int& trackBallLines, int& scanCount, int& firstScanOffset) { // Apply sensitivity and calculate remainder - float fTrackBallCount = counter * mySensitivity * TB_SENSITIVITY + counterRemainder; - int trackBallCount = int(std::lround(fTrackBallCount)); + const float fTrackBallCount = counter * mySensitivity * TB_SENSITIVITY + counterRemainder; + int trackBallCount = static_cast(std::lround(fTrackBallCount)); counterRemainder = fTrackBallCount - trackBallCount; if(trackBallCount) diff --git a/src/emucore/ProfilingRunner.cxx b/src/emucore/ProfilingRunner.cxx index 959ccfcf4..0ba712ab6 100644 --- a/src/emucore/ProfilingRunner.cxx +++ b/src/emucore/ProfilingRunner.cxx @@ -62,7 +62,7 @@ ProfilingRunner::ProfilingRunner(int argc, char* argv[]) ProfilingRun& run(profilingRuns[i-2]); string arg = argv[i]; - size_t splitPoint = arg.find_first_of(':'); + const size_t splitPoint = arg.find_first_of(':'); run.romFile = splitPoint == string::npos ? arg : arg.substr(0, splitPoint); @@ -81,7 +81,7 @@ bool ProfilingRunner::run() { cout << "Profiling Stella..." << endl; - for (ProfilingRun& run : profilingRuns) { + for (const ProfilingRun& run : profilingRuns) { cout << endl << "running " << run.romFile << " for " << run.runtime << " seconds..." << endl; if (!runOne(run)) return false; @@ -91,6 +91,9 @@ bool ProfilingRunner::run() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// FIXME +// Warning C6262 Function uses '301164' bytes of stack : exceeds / analyze : +// stacksize '16384'. Consider moving some data to heap. bool ProfilingRunner::runOne(const ProfilingRun& run) { FilesystemNode imageFile(run.romFile); @@ -101,7 +104,7 @@ bool ProfilingRunner::runOne(const ProfilingRun& run) } ByteBuffer image; - size_t size = imageFile.read(image); + const size_t size = imageFile.read(image); if (size == 0) { cout << "ERROR: unable to read " << run.romFile << endl; return false; @@ -141,7 +144,7 @@ bool ProfilingRunner::runOne(const ProfilingRun& run) (cout << "detecting frame layout... ").flush(); for(int i = 0; i < 60; ++i) tia.update(); - FrameLayout frameLayout = frameLayoutDetector.detectedLayout(); + const FrameLayout frameLayout = frameLayoutDetector.detectedLayout(); ConsoleTiming consoleTiming = ConsoleTiming::ntsc; switch (frameLayout) { @@ -164,9 +167,9 @@ bool ProfilingRunner::runOne(const ProfilingRun& run) system.reset(); - EmulationTiming emulationTiming(frameLayout, consoleTiming); + const EmulationTiming emulationTiming(frameLayout, consoleTiming); uInt64 cycles = 0; - uInt64 cyclesTarget = uInt64(run.runtime) * emulationTiming.cyclesPerSecond(); + const uInt64 cyclesTarget = static_cast(run.runtime) * emulationTiming.cyclesPerSecond(); DispatchResult dispatchResult; dispatchResult.setOk(0); @@ -174,7 +177,7 @@ bool ProfilingRunner::runOne(const ProfilingRun& run) uInt32 percent = 0; (cout << "0%").flush(); - time_point tp = high_resolution_clock::now(); + const time_point tp = high_resolution_clock::now(); while (cycles < cyclesTarget && dispatchResult.getStatus() == DispatchResult::Status::ok) { tia.update(dispatchResult); @@ -182,13 +185,13 @@ bool ProfilingRunner::runOne(const ProfilingRun& run) if (tia.newFramePending()) tia.renderToFrameBuffer(); - uInt32 percentNow = uInt32(std::min((100 * cycles) / cyclesTarget, static_cast(100))); + const uInt32 percentNow = uInt32(std::min((100 * cycles) / cyclesTarget, static_cast(100))); updateProgress(percent, percentNow); percent = percentNow; } - double realtimeUsed = duration_cast>(high_resolution_clock::now () - tp).count(); + const double realtimeUsed = duration_cast>(high_resolution_clock::now () - tp).count(); if (dispatchResult.getStatus() != DispatchResult::Status::ok) { cout << endl << "ERROR: emulation failed after " << cycles << " cycles"; diff --git a/src/emucore/ProfilingRunner.hxx b/src/emucore/ProfilingRunner.hxx index 289848616..ff68bfa03 100644 --- a/src/emucore/ProfilingRunner.hxx +++ b/src/emucore/ProfilingRunner.hxx @@ -36,7 +36,7 @@ class ProfilingRunner { struct ProfilingRun { string romFile; - uInt32 runtime; + uInt32 runtime{0}; }; struct IO: public ConsoleIO { diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index c00723ba0..15103f1aa 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -63,7 +63,7 @@ bool Properties::save(KeyValueRepository& repo) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Properties::set(PropType key, const string& value) { - size_t pos = static_cast(key); + const size_t pos = static_cast(key); if(pos < myProperties.size()) { myProperties[pos] = value; @@ -95,7 +95,7 @@ void Properties::set(PropType key, const string& value) case PropType::Display_PPBlend: { - int blend = BSPF::stringToInt(myProperties[pos]); + const int blend = BSPF::stringToInt(myProperties[pos]); if(blend < 0 || blend > 100) myProperties[pos] = ourDefaultProperties[pos]; break; @@ -188,7 +188,7 @@ void Properties::print() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Properties::reset(PropType key) { - size_t pos = static_cast(key); + const size_t pos = static_cast(key); myProperties[pos] = ourDefaultProperties[pos]; } diff --git a/src/emucore/Props.hxx b/src/emucore/Props.hxx index dfd946b17..f4f561798 100644 --- a/src/emucore/Props.hxx +++ b/src/emucore/Props.hxx @@ -74,6 +74,7 @@ class Properties new properties object does not claim ownership of the defaults. */ Properties(); + ~Properties() = default; /** Creates a properties list by copying another one @@ -184,6 +185,11 @@ class Properties // The text strings associated with each property type static std::array ourPropertyNames; + + private: + // Following constructors and assignment operators not supported + Properties(Properties&&) = delete; + Properties& operator=(Properties&&) = delete; }; #endif diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index 64deac5a0..5973c9d76 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -60,7 +60,7 @@ bool PropertiesSet::getMD5(const string& md5, Properties& properties, } else // Search temp list { - auto tmp = myTempProps.find(md5); + const auto tmp = myTempProps.find(md5); if(tmp != myTempProps.end()) { properties = tmp->second; @@ -75,15 +75,15 @@ bool PropertiesSet::getMD5(const string& md5, Properties& properties, int low = 0, high = DEF_PROPS_SIZE - 1; while(low <= high) { - int i = (low + high) / 2; - int cmp = BSPF::compareIgnoreCase(md5, + const int i = (low + high) / 2; + const int cmp = BSPF::compareIgnoreCase(md5, DefProps[i][static_cast(PropType::Cart_MD5)]); if(cmp == 0) // found it { for(uInt8 p = 0; p < static_cast(PropType::NumTypes); ++p) if(DefProps[i][p][0] != 0) - properties.set(PropType(p), DefProps[i][p]); + properties.set(PropType{p}, DefProps[i][p]); found = true; break; @@ -130,7 +130,7 @@ void PropertiesSet::insert(const Properties& properties, bool save) if (save) { properties.save(*myRepository->get(md5)); } else { - auto ret = myTempProps.emplace(md5, properties); + const auto ret = myTempProps.emplace(md5, properties); if(ret.second == false) { // Remove old item and insert again @@ -199,7 +199,7 @@ void PropertiesSet::print() const properties.setDefaults(); for(uInt8 p = 0; p < static_cast(PropType::NumTypes); ++p) if(DefProps[i][p][0] != 0) - properties.set(PropType(p), DefProps[i][p]); + properties.set(PropType{p}, DefProps[i][p]); list.emplace(DefProps[i][static_cast(PropType::Cart_MD5)], properties); } diff --git a/src/emucore/Serializer.cxx b/src/emucore/Serializer.cxx index 30872ce18..80376eb9b 100644 --- a/src/emucore/Serializer.cxx +++ b/src/emucore/Serializer.cxx @@ -98,10 +98,10 @@ void Serializer::rewind() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - size_t Serializer::size() { - std::streampos oldPos = myStream->tellp(); + const std::streampos oldPos = myStream->tellp(); myStream->seekp(0, std::ios::end); - size_t s = myStream->tellp(); + const size_t s = myStream->tellp(); myStream->seekp(oldPos); return s; @@ -173,7 +173,7 @@ double Serializer::getDouble() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Serializer::getString() const { - int len = getInt(); + const int len = getInt(); string str; str.resize(len); myStream->read(&str[0], len); @@ -238,7 +238,7 @@ void Serializer::putDouble(double value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Serializer::putString(const string& str) { - uInt32 len = uInt32(str.length()); + const uInt32 len = static_cast(str.length()); putInt(len); myStream->write(str.data(), len); } diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index ecec07215..cb641c16b 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -309,17 +309,13 @@ void Settings::save() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Settings::validate() { - string s; - int i; - float f; - - f = getFloat("speed"); + float f = getFloat("speed"); if (f <= 0) setValue("speed", "1.0"); - i = getInt("tia.vsizeadjust"); + int i = getInt("tia.vsizeadjust"); if(i < -5 || i > 5) setValue("tia.vsizeadjust", 0); - s = getString("tia.dbgcolors"); + string s = getString("tia.dbgcolors"); sort(s.begin(), s.end()); if(s != "bgopry") setValue("tia.dbgcolors", "roygpb"); @@ -442,7 +438,7 @@ void Settings::validate() if(i < 0) setValue("romviewer", "0"); i = getInt("loglevel"); - if(i < int(Logger::Level::MIN) || i > int(Logger::Level::MAX)) + if(i < static_cast(Logger::Level::MIN) || i > static_cast(Logger::Level::MAX)) setValue("loglevel", int(Logger::Level::INFO)); } diff --git a/src/emucore/System.cxx b/src/emucore/System.cxx index 0d7c55fc0..595964a3b 100644 --- a/src/emucore/System.cxx +++ b/src/emucore/System.cxx @@ -36,7 +36,7 @@ System::System(Random& random, M6502& m6502, M6532& m6532, myCart{mCart} { // Initialize page access table - PageAccess access(&myNullDevice, System::PageAccessType::READ); + const PageAccess access(&myNullDevice, System::PageAccessType::READ); myPageAccessTable.fill(access); myPageIsDirtyTable.fill(false); @@ -82,8 +82,8 @@ void System::consoleChanged(ConsoleTiming timing) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool System::isPageDirty(uInt16 start_addr, uInt16 end_addr) const { - uInt16 start_page = (start_addr & ADDRESS_MASK) >> PAGE_SHIFT; - uInt16 end_page = (end_addr & ADDRESS_MASK) >> PAGE_SHIFT; + const uInt16 start_page = (start_addr & ADDRESS_MASK) >> PAGE_SHIFT; + const uInt16 end_page = (end_addr & ADDRESS_MASK) >> PAGE_SHIFT; for(uInt16 page = start_page; page <= end_page; ++page) if(myPageIsDirtyTable[page]) @@ -120,11 +120,9 @@ uInt8 System::peek(uInt16 addr, Device::AccessFlags flags) #endif // See if this page uses direct accessing or not - uInt8 result; - if(access.directPeekBase) - result = *(access.directPeekBase + (addr & PAGE_MASK)); - else - result = access.device->peek(addr); + const uInt8 result = access.directPeekBase + ? *(access.directPeekBase + (addr & PAGE_MASK)) + : access.device->peek(addr); #ifdef DEBUGGER_SUPPORT if(!myDataBusLocked) @@ -137,7 +135,7 @@ uInt8 System::peek(uInt16 addr, Device::AccessFlags flags) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void System::poke(uInt16 addr, uInt8 value, Device::AccessFlags flags) { - uInt16 page = (addr & ADDRESS_MASK) >> PAGE_SHIFT; + const uInt16 page = (addr & ADDRESS_MASK) >> PAGE_SHIFT; const PageAccess& access = myPageAccessTable[page]; #ifdef DEBUGGER_SUPPORT diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 6fa649248..09b0ca027 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -66,7 +66,7 @@ TIASurface::TIASurface(OSystem& system) TIAConstants::frameBufferHeight); // Create shading surface - uInt32 data = 0xff000000; + static constexpr uInt32 data = 0xff000000; myShadeSurface = myFB.allocateSurface(1, 1, ScalingInterpolation::sharp, &data); @@ -102,7 +102,7 @@ void TIASurface::initialize(const Console& console, myPaletteHandler->setPalette(); createScanlineSurface(); - setNTSC(NTSCFilter::Preset(myOSystem.settings().getInt("tv.filter")), false); + setNTSC(static_cast(myOSystem.settings().getInt("tv.filter")), false); #if 0 cerr << "INITIALIZE:\n" @@ -131,7 +131,7 @@ void TIASurface::setPalette(const PaletteArray& tia_palette, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const FBSurface& TIASurface::baseSurface(Common::Rect& rect) const { - uInt32 tiaw = myTIA->width(), width = tiaw * 2, height = myTIA->height(); + const uInt32 tiaw = myTIA->width(), width = tiaw * 2, height = myTIA->height(); rect.setBounds(0, 0, width, height); // Fill the surface with pixels from the TIA, scaled 2x horizontally @@ -166,7 +166,7 @@ void TIASurface::setNTSC(NTSCFilter::Preset preset, bool show) const string& mode = myNTSCFilter.setPreset(preset); buf << "TV filtering (" << mode << " mode)"; } - myOSystem.settings().setValue("tv.filter", int(preset)); + myOSystem.settings().setValue("tv.filter", static_cast(preset)); if(show) myFB.showTextMessage(buf.str()); } @@ -182,15 +182,15 @@ void TIASurface::changeNTSC(int direction) if(direction == +1) { - if(preset == int(NTSCFilter::Preset::CUSTOM)) - preset = int(NTSCFilter::Preset::OFF); + if(preset == static_cast(NTSCFilter::Preset::CUSTOM)) + preset = static_cast(NTSCFilter::Preset::OFF); else preset++; } else if (direction == -1) { - if(preset == int(NTSCFilter::Preset::OFF)) - preset = int(NTSCFilter::Preset::CUSTOM); + if(preset == static_cast(NTSCFilter::Preset::OFF)) + preset = static_cast(NTSCFilter::Preset::CUSTOM); else preset--; } @@ -238,10 +238,10 @@ void TIASurface::changeScanlineIntensity(int direction) FBSurface::Attributes& attr = mySLineSurface->attributes(); attr.blendalpha += direction * 2; - attr.blendalpha = BSPF::clamp(Int32(attr.blendalpha), 0, 100); + attr.blendalpha = BSPF::clamp(static_cast(attr.blendalpha), 0, 100); mySLineSurface->applyAttributes(); - uInt32 intensity = attr.blendalpha; + const uInt32 intensity = attr.blendalpha; myOSystem.settings().setValue("tv.scanlines", intensity); enableNTSC(ntscEnabled()); @@ -273,7 +273,7 @@ TIASurface::ScanlineMask TIASurface::scanlineMaskType(int direction) { if(direction) { - i = BSPF::clampw(i + direction, 0, int(ScanlineMask::NumMasks) - 1); + i = BSPF::clampw(i + direction, 0, static_cast(ScanlineMask::NumMasks) - 1); myOSystem.settings().setValue("tv.scanmask", Masks[i]); } return ScanlineMask(i); @@ -293,7 +293,7 @@ void TIASurface::cycleScanlineMask(int direction) "Aperture Grille", "MAME" }; - int i = int(scanlineMaskType(direction)); + const int i = static_cast(scanlineMaskType(direction)); if(direction) createScanlineSurface(); @@ -310,7 +310,7 @@ void TIASurface::enablePhosphor(bool enable, int blend) if(myPhosphorHandler.initialize(enable, blend)) { myPBlend = blend; - myFilter = Filter(enable ? uInt8(myFilter) | 0x01 : uInt8(myFilter) & 0x10); + myFilter = static_cast(enable ? uInt8(myFilter) | 0x01 : uInt8(myFilter) & 0x10); myRGBFramebuffer.fill(0); } } @@ -410,9 +410,9 @@ void TIASurface::createScanlineSurface() { 0xff000000, 0xff000000, 0xff000000 }, }), }}; - const int mask = int(scanlineMaskType()); - const uInt32 pWidth = uInt32(Patterns[mask].data[0].size()); - const uInt32 pHeight = uInt32(Patterns[mask].data.size() / Patterns[mask].vRepeats); + const int mask = static_cast(scanlineMaskType()); + const uInt32 pWidth = static_cast(Patterns[mask].data[0].size()); + const uInt32 pHeight = static_cast(Patterns[mask].data.size() / Patterns[mask].vRepeats); const uInt32 vRepeats = Patterns[mask].vRepeats; // Single width pattern need no horizontal repeats const uInt32 width = pWidth > 1 ? TIAConstants::frameBufferWidth * pWidth : 1; @@ -438,9 +438,9 @@ void TIASurface::createScanlineSurface() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIASurface::enableNTSC(bool enable) { - myFilter = Filter(enable ? uInt8(myFilter) | 0x10 : uInt8(myFilter) & 0x01); + myFilter = static_cast(enable ? uInt8(myFilter) | 0x10 : uInt8(myFilter) & 0x01); - uInt32 surfaceWidth = enable ? + const uInt32 surfaceWidth = enable ? AtariNTSC::outWidth(TIAConstants::frameBufferWidth) : TIAConstants::frameBufferWidth; if (surfaceWidth != myTiaSurface->srcRect().w() || myTIA->height() != myTiaSurface->srcRect().h()) { @@ -517,7 +517,7 @@ inline uInt32 TIASurface::averageBuffers(uInt32 bufOfs) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIASurface::render(bool shade) { - uInt32 width = myTIA->width(), height = myTIA->height(); + const uInt32 width = myTIA->width(), height = myTIA->height(); uInt32 *out, outPitch; myTiaSurface->basePtr(out, outPitch); @@ -526,12 +526,12 @@ void TIASurface::render(bool shade) { case Filter::Normal: { - uInt8* tiaIn = myTIA->frameBuffer(); + const uInt8* tiaIn = myTIA->frameBuffer(); - uInt32 bufofs = 0, screenofsY = 0, pos; + uInt32 bufofs = 0, screenofsY = 0; for(uInt32 y = 0; y < height; ++y) { - pos = screenofsY; + uInt32 pos = screenofsY; for (uInt32 x = width / 2; x; --x) { out[pos++] = myPalette[tiaIn[bufofs++]]; @@ -544,17 +544,17 @@ void TIASurface::render(bool shade) case Filter::Phosphor: { - uInt8* tiaIn = myTIA->frameBuffer(); + const uInt8* tiaIn = myTIA->frameBuffer(); uInt32* rgbIn = myRGBFramebuffer.data(); if (mySaveSnapFlag) std::copy_n(myRGBFramebuffer.begin(), width * height, myPrevRGBFramebuffer.begin()); - uInt32 bufofs = 0, screenofsY = 0, pos; + uInt32 bufofs = 0, screenofsY = 0; for(uInt32 y = height; y ; --y) { - pos = screenofsY; + uInt32 pos = screenofsY; for(uInt32 x = width / 2; x ; --x) { // Store back into displayed frame buffer (for next frame) @@ -616,8 +616,7 @@ void TIASurface::renderForSnapshot() // Furthermore, toggling the variable 'mySaveSnapFlag' in different places // is brittle, especially since rendering can happen in a different thread. - uInt32 width = myTIA->width(); - uInt32 height = myTIA->height(); + const uInt32 width = myTIA->width(), height = myTIA->height(); uInt32 pos = 0; uInt32 *outPtr, outPitch; diff --git a/src/emucore/Thumbulator.cxx b/src/emucore/Thumbulator.cxx index a71f2cb5c..47fd6c470 100644 --- a/src/emucore/Thumbulator.cxx +++ b/src/emucore/Thumbulator.cxx @@ -289,7 +289,7 @@ void Thumbulator::dump_regs() uInt32 Thumbulator::fetch16(uInt32 addr) { #ifndef UNSAFE_OPTIMIZATIONS - uInt32 data; + uInt32 data = 0; #ifdef THUMB_CYCLE_COUNT _pipeIdx = (_pipeIdx+1) % 3; @@ -340,6 +340,9 @@ uInt32 Thumbulator::fetch16(uInt32 addr) data = CONV_RAMROM(ram[addr]); DO_DBUG(statusMsg << "fetch16(" << Base::HEX8 << addr << ")=" << Base::HEX4 << data << endl); return data; + + default: // reserved + break; } return fatalError("fetch16", addr, "abort"); #else @@ -471,7 +474,7 @@ void Thumbulator::write32(uInt32 addr, uInt32 data) case 0xE000E010: { - uInt32 old = systick_ctrl; + const uInt32 old = systick_ctrl; systick_ctrl = data & 0x00010007; if(((old & 1) == 0) && (systick_ctrl & 1)) { @@ -552,7 +555,7 @@ bool Thumbulator::isProtected(uInt32 addr) // For CDF variations parts of the driver RAM are reused to hold the // datastream information, so is not protected. // Additionally for CDFJ+ the Fast Fetcher offset is not write protected. - + if (addr < 0x40000000) return false; addr -= 0x40000000; @@ -583,7 +586,7 @@ bool Thumbulator::isProtected(uInt32 addr) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 Thumbulator::read16(uInt32 addr) { - uInt32 data; + uInt32 data = 0; #ifndef UNSAFE_OPTIMIZATIONS if((addr > 0x40007fff) && (addr < 0x50000000)) fatalError("read16", addr, "abort - out of range"); @@ -637,13 +640,13 @@ uInt32 Thumbulator::read32(uInt32 addr) fatalError("read32", addr, "abort - misaligned"); #endif - uInt32 data; + uInt32 data = 0; switch(addr & 0xF0000000) { case 0x00000000: //ROM case 0x40000000: //RAM data = read16(addr+0); - data |= (uInt32(read16(addr+2))) << 16; + data |= (static_cast(read16(addr+2))) << 16; DO_DBUG(statusMsg << "read32(" << Base::HEX8 << addr << ")=" << Base::HEX8 << data << endl); return data; @@ -799,11 +802,9 @@ void Thumbulator::do_cflag(uInt32 a, uInt32 b, uInt32 c) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Thumbulator::do_vflag(uInt32 a, uInt32 b, uInt32 c) { - uInt32 rc, rd; - - rc = (a & 0x7FFFFFFF) + (b & 0x7FFFFFFF) + c; //carry in + uInt32 rc = (a & 0x7FFFFFFF) + (b & 0x7FFFFFFF) + c; //carry in rc >>= 31; //carry in in lsbit - rd = (rc & 1) + ((a >> 31) & 1) + ((b >> 31) & 1); //carry out + uInt32 rd = (rc & 1) + ((a >> 31) & 1) + ((b >> 31) & 1); //carry out rd >>= 1; //carry out in lsbit rc = (rc^rd) & 1; //if carry in != carry out then signed overflow if(rc) @@ -1055,7 +1056,7 @@ int Thumbulator::execute() pc = read_register(15); - uInt32 instructionPtr = pc - 2; + const uInt32 instructionPtr = pc - 2; inst = fetch16(instructionPtr); pc += 2; @@ -3185,8 +3186,7 @@ void Thumbulator::incSCycles(uInt32 addr, AccessType accessType) ++_stats.sCylces; #endif - uInt32 cycles; - + uInt32 cycles = 0; if(addr & 0xC0000000) // RAM, peripherals cycles = 1; @@ -3249,7 +3249,7 @@ void Thumbulator::incNCycles(uInt32 addr, AccessType accessType) ++_stats.nCylces; #endif - uInt32 cycles; + uInt32 cycles = 0; if(addr & 0xC0000000) // RAM, peripherals cycles = 1; diff --git a/src/emucore/TrakBall.hxx b/src/emucore/TrakBall.hxx index 1f6e47947..91e5b10b1 100644 --- a/src/emucore/TrakBall.hxx +++ b/src/emucore/TrakBall.hxx @@ -55,6 +55,13 @@ class TrakBall : public PointingDevice // 50% of Atari and Amiga mouse static constexpr float trackballSensitivity = 0.4F; + + private: + // Following constructors and assignment operators not supported + TrakBall(const TrakBall&) = delete; + TrakBall(TrakBall&&) = delete; + TrakBall& operator=(const TrakBall&) = delete; + TrakBall& operator=(TrakBall&&) = delete; }; #endif // TRAKBALL_HXX diff --git a/src/emucore/exception/EmulationWarning.hxx b/src/emucore/exception/EmulationWarning.hxx index e47ab99b2..3a0c0d185 100644 --- a/src/emucore/exception/EmulationWarning.hxx +++ b/src/emucore/exception/EmulationWarning.hxx @@ -23,7 +23,7 @@ class EmulationWarning : public std::exception { public: - explicit EmulationWarning(const string& message) : myMessage(message) { } + explicit EmulationWarning(const string& message) : myMessage{message} { } const char* what() const noexcept override { return myMessage.c_str(); } diff --git a/src/emucore/exception/FatalEmulationError.hxx b/src/emucore/exception/FatalEmulationError.hxx index e971f56b4..e2a0a4353 100644 --- a/src/emucore/exception/FatalEmulationError.hxx +++ b/src/emucore/exception/FatalEmulationError.hxx @@ -23,7 +23,7 @@ class FatalEmulationError : public std::exception { public: - explicit FatalEmulationError(const string& message) : myMessage(message) { } + explicit FatalEmulationError(const string& message) : myMessage{message} { } const char* what() const noexcept override { return myMessage.c_str(); } diff --git a/src/emucore/tia/AnalogReadout.cxx b/src/emucore/tia/AnalogReadout.cxx index e23f3e003..0cbcd9616 100644 --- a/src/emucore/tia/AnalogReadout.cxx +++ b/src/emucore/tia/AnalogReadout.cxx @@ -42,7 +42,7 @@ void AnalogReadout::vblank(uInt8 value, uInt64 timestamp) { updateCharge(timestamp); - bool oldIsDumped = myIsDumped; + const bool oldIsDumped = myIsDumped; if (value & 0x80) { myIsDumped = true; @@ -58,7 +58,7 @@ uInt8 AnalogReadout::inpt(uInt64 timestamp) { updateCharge(timestamp); - bool state = myIsDumped ? false : myU > myUThresh; + const bool state = myIsDumped ? false : myU > myUThresh; return state ? 0x80 : 0; } @@ -152,7 +152,7 @@ bool AnalogReadout::load(Serializer& in) myConnection.load(in); myTimestamp = in.getLong(); - myConsoleTiming = ConsoleTiming(in.getInt()); + myConsoleTiming = static_cast(in.getInt()); myClockFreq = in.getDouble(); myIsDumped = in.getBool(); @@ -206,7 +206,7 @@ bool AnalogReadout::Connection::load(const Serializer& in) { try { - type = ConnectionType(in.getInt()); + type = static_cast(in.getInt()); resistance = in.getInt(); } catch(...) diff --git a/src/emucore/tia/Audio.cxx b/src/emucore/tia/Audio.cxx index 9de93df09..b96e06584 100644 --- a/src/emucore/tia/Audio.cxx +++ b/src/emucore/tia/Audio.cxx @@ -27,7 +27,8 @@ namespace { Int16 mixingTableEntry(uInt8 v, uInt8 vMax) { return static_cast( - floor(0x7fff * double(v) / double(vMax) * (R_MAX + R * double(vMax)) / (R_MAX + R * double(v))) + floor(0x7fff * static_cast(v) / static_cast(vMax) * + (R_MAX + R * static_cast(vMax)) / (R_MAX + R * static_cast(v))) ); } } @@ -68,13 +69,15 @@ void Audio::tick() case 81: myChannel0.phase0(); myChannel1.phase0(); - break; case 37: case 149: phase1(); break; + + default: + break; } if (++myCounter == 228) myCounter = 0; @@ -83,8 +86,8 @@ void Audio::tick() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Audio::phase1() { - uInt8 sample0 = myChannel0.phase1(); - uInt8 sample1 = myChannel1.phase1(); + const uInt8 sample0 = myChannel0.phase1(); + const uInt8 sample1 = myChannel1.phase1(); addSample(sample0, sample1); #ifdef GUI_SUPPORT @@ -137,7 +140,7 @@ bool Audio::save(Serializer& out) const if (!myChannel0.save(out)) return false; if (!myChannel1.save(out)) return false; #ifdef GUI_SUPPORT - out.putLong(uInt64(mySamples.size())); + out.putLong(static_cast(mySamples.size())); out.putByteArray(mySamples.data(), mySamples.size()); // TODO: check if this improves sound of playback for larger state gaps @@ -166,9 +169,9 @@ bool Audio::load(Serializer& in) if (!myChannel0.load(in)) return false; if (!myChannel1.load(in)) return false; #ifdef GUI_SUPPORT - uInt64 sampleSize = in.getLong(); - unique_ptr samples = make_unique(sampleSize); - in.getByteArray(samples.get(), sampleSize); + const uInt64 sampleSize = in.getLong(); + ByteArray samples(sampleSize); + in.getByteArray(samples.data(), sampleSize); //mySampleIndex = in.getInt(); //in.getShortArray((uInt16*)myCurrentFragment, myAudioQueue->fragmentSize()); @@ -176,9 +179,9 @@ bool Audio::load(Serializer& in) // Feed all loaded samples into the audio queue for(size_t i = 0; i < sampleSize; i++) { - uInt8 sample = samples[i]; - uInt8 sample0 = sample & 0x0f; - uInt8 sample1 = sample >> 4; + const uInt8 sample = samples[i]; + const uInt8 sample0 = sample & 0x0f; + const uInt8 sample1 = sample >> 4; addSample(sample0, sample1); } diff --git a/src/emucore/tia/AudioChannel.cxx b/src/emucore/tia/AudioChannel.cxx index b1143999a..f2d57e402 100644 --- a/src/emucore/tia/AudioChannel.cxx +++ b/src/emucore/tia/AudioChannel.cxx @@ -44,6 +44,9 @@ void AudioChannel::phase0() case 0x03: myPulseCounterHold = !myNoiseCounterBit4; break; + + default: // not possible, but silence the compiler + break; } switch (myAudc & 0x03) { @@ -84,7 +87,6 @@ uInt8 AudioChannel::phase1() (((myPulseCounter & 0x02) ? 1 : 0) ^ (myPulseCounter & 0x01)) && (myPulseCounter != 0x0a) && (myAudc & 0x03); - break; case 0x01: @@ -98,6 +100,9 @@ uInt8 AudioChannel::phase1() case 0x03: pulseFeedback = !((myPulseCounter & 0x02) || !(myPulseCounter & 0x0e)); break; + + default: + break; } myNoiseCounter >>= 1; diff --git a/src/emucore/tia/Ball.cxx b/src/emucore/tia/Ball.cxx index b1addd0ad..8c1cc9eaa 100644 --- a/src/emucore/tia/Ball.cxx +++ b/src/emucore/tia/Ball.cxx @@ -153,7 +153,6 @@ void Ball::setInvertedPhaseClock(bool enable) myUseInvertedPhaseClock = enable; } - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Ball::startMovement() { @@ -163,7 +162,7 @@ void Ball::startMovement() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Ball::nextLine() { - // Reevalute the collision mask in order to properly account for collisions during + // Re-evaluate the collision mask in order to properly account for collisions during // hblank. Usually, this will be taken care off in the next tick, but there is no // next tick before hblank ends. mySignalActive = myIsRendering && myRenderCounter >= 0; diff --git a/src/emucore/tia/DrawCounterDecodes.cxx b/src/emucore/tia/DrawCounterDecodes.cxx index f7ef0b6de..e0b89c7c1 100644 --- a/src/emucore/tia/DrawCounterDecodes.cxx +++ b/src/emucore/tia/DrawCounterDecodes.cxx @@ -40,9 +40,9 @@ DrawCounterDecodes::DrawCounterDecodes() { uInt8 *decodeTables[] = {myDecodes0, myDecodes1, myDecodes2, myDecodes3, myDecodes4, myDecodes6}; - for (uInt8 *decodes : decodeTables) + for (auto decodes: decodeTables) { - memset(decodes, 0, 160); // TJ: magic number 160 = pixel/scanline + std::fill_n(decodes, 160, 0); // TJ: magic number 160 = pixel/scanline decodes[156] = 1; // TJ: set for all copy pattern (first copy) } diff --git a/src/emucore/tia/Player.cxx b/src/emucore/tia/Player.cxx index 312698be9..6b5fabe94 100644 --- a/src/emucore/tia/Player.cxx +++ b/src/emucore/tia/Player.cxx @@ -109,7 +109,7 @@ void Player::nusiz(uInt8 value, bool hblank) // decode and rendering. if (myIsRendering) { - Int8 delta = myRenderCounter - Count::renderCounterOffset; + const Int8 delta = myRenderCounter - Count::renderCounterOffset; switch ((myDivider << 4) | myDividerPending) { case 0x12: diff --git a/src/emucore/tia/Playfield.cxx b/src/emucore/tia/Playfield.cxx index 9b2ca7ea8..41ef06819 100644 --- a/src/emucore/tia/Playfield.cxx +++ b/src/emucore/tia/Playfield.cxx @@ -232,10 +232,10 @@ void Playfield::applyColors() uInt8 Playfield::getColor() const { if (!myDebugEnabled) - return myX < uInt16(TIAConstants::H_PIXEL / 2 - myScoreHaste) ? myColorLeft : myColorRight; + return myX < static_cast(TIAConstants::H_PIXEL / 2 - myScoreHaste) ? myColorLeft : myColorRight; else { - if (myX < uInt16(TIAConstants::H_PIXEL / 2 - myScoreHaste)) + if (myX < static_cast(TIAConstants::H_PIXEL / 2 - myScoreHaste)) { // left side: if(myX < 16) @@ -332,7 +332,7 @@ bool Playfield::load(Serializer& in) myDebugColor = in.getByte(); myDebugEnabled = in.getBool(); - myColorMode = ColorMode(in.getByte()); + myColorMode = static_cast(in.getByte()); myScoreGlitch = in.getBool(); myScoreHaste = myColorMode == ColorMode::score && myScoreGlitch ? 1 : 0; diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 0e2f50674..4d73e85ee 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -209,7 +209,7 @@ void TIA::reset() { for(uInt32 i = 0; i < 0x4000; ++i) { - uInt16 address = mySystem->randGenerator().next() & 0x3F; + const uInt16 address = mySystem->randGenerator().next() & 0x3F; if(address <= 0x2F) { @@ -234,7 +234,7 @@ void TIA::installDelegate(System& system, Device& device) mySystem = &system; // All accesses are to the given device - System::PageAccess access(&device, System::PageAccessType::READWRITE); + const System::PageAccess access(&device, System::PageAccessType::READWRITE); // Map all peek/poke to mirrors of TIA address space to this class // That is, all mirrors of ($00 - $3F) in the lower 4K of the 2600 @@ -348,7 +348,7 @@ bool TIA::load(Serializer& in) if(!myInput0.load(in)) return false; if(!myInput1.load(in)) return false; - myHstate = HState(in.getInt()); + myHstate = static_cast(in.getInt()); myHctr = in.getInt(); myHctrDelta = in.getInt(); @@ -364,7 +364,7 @@ bool TIA::load(Serializer& in) myLinesSinceChange = in.getInt(); - myPriority = Priority(in.getInt()); + myPriority = static_cast(in.getInt()); mySubClock = in.getByte(); myLastCycle = in.getLong(); @@ -565,7 +565,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myAudio.channel0().audv(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::AUD); #endif @@ -577,7 +577,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myAudio.channel1().audv(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::AUD); #endif @@ -589,7 +589,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myAudio.channel0().audf(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::AUD); #endif @@ -601,7 +601,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myAudio.channel1().audf(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::AUD); #endif @@ -613,7 +613,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myAudio.channel0().audc(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::AUD); #endif @@ -625,7 +625,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myAudio.channel1().audc(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::AUD); #endif @@ -647,7 +647,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myShadowRegisters[address] = value; } #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::BCOL); #endif @@ -662,7 +662,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myPlayer0.setColor(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::COL); #endif @@ -677,7 +677,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myPlayer1.setColor(value); myShadowRegisters[address] = value; #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::COL); #endif @@ -706,7 +706,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myShadowRegisters[address] = value; } #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::PCOL); #endif @@ -717,7 +717,7 @@ bool TIA::poke(uInt16 address, uInt8 value) { myDelayQueue.push(PF0, value, myPFBitsDelay); #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::PGFX); #endif @@ -728,7 +728,7 @@ bool TIA::poke(uInt16 address, uInt8 value) { myDelayQueue.push(PF1, value, myPFBitsDelay); #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::PGFX); #endif @@ -739,7 +739,7 @@ bool TIA::poke(uInt16 address, uInt8 value) { myDelayQueue.push(PF2, value, myPFBitsDelay); #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::PGFX); #endif @@ -807,7 +807,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myDelayQueue.push(GRP0, value, Delay::grp); myDelayQueue.push(DummyRegisters::shuffleP1, 0, myPlSwapDelay); #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::GFX); #endif @@ -820,7 +820,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myDelayQueue.push(DummyRegisters::shuffleP0, 0, myPlSwapDelay); myDelayQueue.push(DummyRegisters::shuffleBL, 0, Delay::shuffleBall); #ifdef DEBUGGER_SUPPORT - uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); + const uInt16 dataAddr = mySystem->m6502().lastDataAddressForPoke(); if(dataAddr) mySystem->setAccessFlags(dataAddr, Device::GFX); #endif @@ -1029,7 +1029,7 @@ void TIA::update(uInt64 maxCycles) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::enableColorLoss(bool enabled) { - bool allowColorLoss = myTimingProvider() == ConsoleTiming::pal; + const bool allowColorLoss = myTimingProvider() == ConsoleTiming::pal; if(allowColorLoss && enabled) { @@ -1055,7 +1055,7 @@ bool TIA::enableColorLoss(bool enabled) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::electronBeamPos(uInt32& x, uInt32& y) const { - uInt8 clocks = clocksThisLine(); + const uInt8 clocks = clocksThisLine(); x = (clocks < TIAConstants::H_BLANK_CLOCKS) ? 0 : clocks - TIAConstants::H_BLANK_CLOCKS; y = myFrameManager->getY(); @@ -1066,7 +1066,7 @@ bool TIA::electronBeamPos(uInt32& x, uInt32& y) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::toggleBit(TIABit b, uInt8 mode) { - uInt8 mask; + uInt8 mask = 0; switch (mode) { case 0: @@ -1101,7 +1101,7 @@ bool TIA::toggleBit(TIABit b, uInt8 mode) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::toggleBits(bool toggle) { - toggleBit(TIABit(0xFF), toggle + toggleBit(static_cast(0xFF), toggle ? mySpriteEnabledBits > 0 ? 0 : 1 : mySpriteEnabledBits); @@ -1111,7 +1111,7 @@ bool TIA::toggleBits(bool toggle) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::toggleCollision(TIABit b, uInt8 mode) { - uInt8 mask; + uInt8 mask = 0; switch (mode) { case 0: @@ -1146,7 +1146,7 @@ bool TIA::toggleCollision(TIABit b, uInt8 mode) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::toggleCollisions(bool toggle) { - toggleCollision(TIABit(0xFF), toggle + toggleCollision(static_cast(0xFF), toggle ? myCollisionsEnabledBits > 0 ? 0 : 1 : myCollisionsEnabledBits); @@ -1156,7 +1156,7 @@ bool TIA::toggleCollisions(bool toggle) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIA::enableFixedColors(bool enable) { - int timing = myTimingProvider() == ConsoleTiming::ntsc ? 0 + const int timing = myTimingProvider() == ConsoleTiming::ntsc ? 0 : myTimingProvider() == ConsoleTiming::pal ? 1 : 2; myMissile0.setDebugColor(myFixedColorPalette[timing][FixedObject::M0]); @@ -1227,6 +1227,8 @@ bool TIA::setFixedColorPalette(const string& colors) myFixedColorPalette[2][i] = FixedColor::SECAM_PURPLE; myFixedColorNames[i] = "Purple"; break; + default: + break; } } myFixedColorPalette[0][TIA::BK] = FixedColor::NTSC_GREY; @@ -1299,7 +1301,7 @@ shared_ptr TIA::delayQueueIterator() const TIA& TIA::updateScanline() { // Update frame by one scanline at a time - uInt32 line = scanlines(); + const uInt32 line = scanlines(); while (line == scanlines() && mySystem->m6502().execute(1)); return *this; @@ -1328,7 +1330,8 @@ void TIA::updateEmulation() if (mySubClock > TIAConstants::CYCLE_CLOCKS - 1) throw runtime_error("subclock exceeds range"); - const uInt32 cyclesToRun = TIAConstants::CYCLE_CLOCKS * uInt32(systemCycles - myLastCycle) + mySubClock; + const uInt32 cyclesToRun = TIAConstants::CYCLE_CLOCKS * + static_cast(systemCycles - myLastCycle) + mySubClock; mySubClock = 0; myLastCycle = systemCycles; @@ -1440,7 +1443,7 @@ void TIA::tickMovement() if ((myHctr & 0x03) == 0) { const bool hblank = myHstate == HState::blank; - uInt8 movementCounter = myMovementClock > 15 ? 0 : myMovementClock; + const uInt8 movementCounter = myMovementClock > 15 ? 0 : myMovementClock; myMissile0.movementTick(movementCounter, myHctr, hblank); myMissile1.movementTick(movementCounter, myHctr, hblank); @@ -1476,9 +1479,13 @@ void TIA::tickHblank() case TIAConstants::H_BLANK_CLOCKS + 7: if (myExtendedHblank) myHstate = HState::frame; break; + + default: + break; } - if (myExtendedHblank && myHctr > TIAConstants::H_BLANK_CLOCKS - 1) myPlayfield.tick(myHctr - TIAConstants::H_BLANK_CLOCKS - myHctrDelta); + if (myExtendedHblank && myHctr > TIAConstants::H_BLANK_CLOCKS - 1) + myPlayfield.tick(myHctr - TIAConstants::H_BLANK_CLOCKS - myHctrDelta); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1838,7 +1845,7 @@ void TIA::delayedWrite(uInt8 address, uInt8 value) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::updateAnalogReadout(uInt8 idx) { - AnalogReadout::Connection connection; + AnalogReadout::Connection connection{}; switch (idx) { case 0: connection = myConsole.leftController().read(Controller::AnalogPin::Nine); @@ -2036,7 +2043,7 @@ void TIA::toggleCollBLPF() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::updateDumpPorts(uInt8 value) { - bool newIsDumped = value & 0x80; + const bool newIsDumped = value & 0x80; if(myArePortsDumped != newIsDumped) { diff --git a/src/emucore/tia/frame-manager/AbstractFrameManager.cxx b/src/emucore/tia/frame-manager/AbstractFrameManager.cxx index f6ff7db91..0067a6a40 100644 --- a/src/emucore/tia/frame-manager/AbstractFrameManager.cxx +++ b/src/emucore/tia/frame-manager/AbstractFrameManager.cxx @@ -143,7 +143,7 @@ bool AbstractFrameManager::load(Serializer& in) myCurrentFrameFinalLines = in.getInt(); myPreviousFrameFinalLines = in.getInt(); myTotalFrames = in.getInt(); - myLayout = FrameLayout(in.getInt()); + myLayout = static_cast(in.getInt()); return onLoad(in); } diff --git a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx index 9ead2940a..ac01f0702 100644 --- a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx +++ b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx @@ -105,8 +105,8 @@ void FrameLayoutDetector::finalizeFrame() // Calculate the delta between scanline count and the sweet spot for the respective // frame layouts const uInt32 - deltaNTSC = abs(Int32(myCurrentFrameFinalLines) - Int32(frameLinesNTSC)), - deltaPAL = abs(Int32(myCurrentFrameFinalLines) - Int32(frameLinesPAL)); + deltaNTSC = abs(static_cast(myCurrentFrameFinalLines) - static_cast(frameLinesNTSC)), + deltaPAL = abs(static_cast(myCurrentFrameFinalLines) - static_cast(frameLinesPAL)); // Does the scanline count fall into one of our tolerance windows? -> use it if (std::min(deltaNTSC, deltaPAL) <= Metrics::tvModeDetectionTolerance) diff --git a/src/emucore/tia/frame-manager/FrameManager.cxx b/src/emucore/tia/frame-manager/FrameManager.cxx index 146b7211f..9eb86427a 100644 --- a/src/emucore/tia/frame-manager/FrameManager.cxx +++ b/src/emucore/tia/frame-manager/FrameManager.cxx @@ -44,9 +44,7 @@ void FrameManager::onReset() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameManager::onNextLine() { - Int32 jitter; - - State previousState = myState; + const State previousState = myState; ++myLineInState; switch (myState) @@ -66,11 +64,13 @@ void FrameManager::onNextLine() break; case State::waitForFrameStart: - jitter = + { + const Int32 jitter = (myJitterEnabled && myTotalFrames > Metrics::initialGarbageFrames) ? myJitterEmulation.jitter() : 0; if (myLineInState >= (myYStart + jitter)) setState(State::frame); break; + } case State::frame: if (myLineInState >= myHeight) @@ -192,7 +192,7 @@ bool FrameManager::onLoad(Serializer& in) { if (!myJitterEmulation.load(in)) return false; - myState = State(in.getInt()); + myState = static_cast(in.getInt()); myLineInState = in.getInt(); myVsyncLines = in.getInt(); myY = in.getInt(); @@ -213,8 +213,8 @@ bool FrameManager::onLoad(Serializer& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FrameManager::recalculateMetrics() { - Int32 ystartBase; - Int32 baseHeight; + Int32 ystartBase = 0; + Int32 baseHeight = 0; switch (layout()) { diff --git a/src/emucore/tia/frame-manager/JitterEmulation.cxx b/src/emucore/tia/frame-manager/JitterEmulation.cxx index 376cd8120..c9e08aa28 100644 --- a/src/emucore/tia/frame-manager/JitterEmulation.cxx +++ b/src/emucore/tia/frame-manager/JitterEmulation.cxx @@ -37,7 +37,7 @@ void JitterEmulation::reset() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void JitterEmulation::frameComplete(uInt32 scanlineCount) { - if (Int32(scanlineCount) != myStableFrameFinalLines) { + if (static_cast(scanlineCount) != myStableFrameFinalLines) { if (myDestabilizationCounter++ > Metrics::framesUntilDestabilization) myStableFrameFinalLines = -1; if (scanlineCount == myLastFrameScanlines) { @@ -63,7 +63,7 @@ void JitterEmulation::frameComplete(uInt32 scanlineCount) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void JitterEmulation::updateJitter(Int32 scanlineDifference) { - if (uInt32(abs(scanlineDifference)) < Metrics::minDeltaForJitter) return; + if (static_cast(abs(scanlineDifference)) < Metrics::minDeltaForJitter) return; Int32 jitter = std::min(scanlineDifference, Metrics::maxJitter); jitter = std::max(jitter, -myYStart); diff --git a/src/gui/Command.hxx b/src/gui/Command.hxx index 404449fea..6c81a8827 100644 --- a/src/gui/Command.hxx +++ b/src/gui/Command.hxx @@ -36,10 +36,18 @@ class CommandReceiver friend class CommandSender; public: + CommandReceiver() = default; virtual ~CommandReceiver() = default; protected: virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) { } + + private: + // Following constructors and assignment operators not supported + CommandReceiver(const CommandReceiver&) = delete; + CommandReceiver(CommandReceiver&&) = delete; + CommandReceiver& operator=(const CommandReceiver&) = delete; + CommandReceiver& operator=(CommandReceiver&&) = delete; }; class CommandSender @@ -47,6 +55,7 @@ class CommandSender // TODO - allow for multiple targets, i.e. store targets in a list // and add methods addTarget/removeTarget. public: + CommandSender() = default; explicit CommandSender(CommandReceiver* target) : _target{target} { } @@ -63,6 +72,13 @@ class CommandSender protected: CommandReceiver* _target{nullptr}; + + private: + // Following constructors and assignment operators not supported + CommandSender(const CommandSender&) = delete; + CommandSender(CommandSender&&) = delete; + CommandSender& operator=(const CommandSender&) = delete; + CommandSender& operator=(CommandSender&&) = delete; }; #endif diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index 9bdcbd0d4..255f341de 100755 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -262,7 +262,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -296,7 +296,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -332,7 +332,7 @@ $(IntDir)obj\\windows\%(RelativeDir) stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -368,7 +368,7 @@ $(IntDir)obj\\windows\%(RelativeDir) stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -402,7 +402,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -437,7 +437,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -472,7 +472,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -510,7 +510,7 @@ $(IntDir)obj\\windows\%(RelativeDir) stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -549,7 +549,7 @@ $(IntDir)obj\\windows\%(RelativeDir) stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -588,7 +588,7 @@ $(IntDir)obj\\windows\%(RelativeDir) stdcpp17 true - 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26410;26415;26429;26438;26440;26446;26451;26455;26459;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp All $(IntDir)asm\windows\%(RelativeDir) @@ -2067,6 +2067,8 @@ + + diff --git a/src/windows/Stella.vcxproj.filters b/src/windows/Stella.vcxproj.filters index 5a4a77403..9c57b20a8 100644 --- a/src/windows/Stella.vcxproj.filters +++ b/src/windows/Stella.vcxproj.filters @@ -2336,6 +2336,12 @@ Header Files + + Header Files\emucore + + + Header Files\emucore +