From debec039001fba760f5412ccb85544ba1e832f2e Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Fri, 20 Dec 2024 19:24:20 -0330 Subject: [PATCH] More const fixes, this time from suggestions from VS code analyzer. --- src/common/FBBackendSDL2.cxx | 10 ++--- src/common/HighScoresManager.hxx | 2 +- src/common/SoundSDL2.cxx | 2 +- src/common/StellaKeys.hxx | 2 +- src/common/bspf.hxx | 4 +- src/common/main.cxx | 4 +- src/debugger/CartDebug.cxx | 4 +- src/debugger/DebuggerParser.cxx | 6 +-- src/debugger/TimerMap.cxx | 2 +- src/debugger/gui/AudioWidget.cxx | 5 ++- src/debugger/gui/BoosterWidget.cxx | 9 +++-- src/debugger/gui/Cart3EPlusWidget.cxx | 2 +- src/debugger/gui/Cart3EWidget.cxx | 2 +- src/debugger/gui/CartELFStateWidget.cxx | 3 +- src/debugger/gui/CartFA2Widget.cxx | 7 ++-- src/debugger/gui/GenesisWidget.cxx | 7 ++-- src/debugger/gui/Joy2BPlusWidget.cxx | 9 +++-- src/debugger/gui/KeyboardWidget.cxx | 5 ++- src/debugger/gui/PaddleWidget.cxx | 7 ++-- src/debugger/gui/RomWidget.cxx | 4 +- src/emucore/CartELF.cxx | 8 ++-- src/emucore/CartELF.hxx | 2 +- src/emucore/Console.cxx | 2 +- src/emucore/Control.cxx | 53 +++---------------------- src/emucore/Control.hxx | 33 +++++++++++---- src/emucore/CortexM0.cxx | 2 +- src/emucore/CortexM0.hxx | 2 +- src/emucore/PlusROM.cxx | 4 +- src/emucore/TIASurface.cxx | 2 +- src/emucore/elf/BusTransactionQueue.cxx | 14 +++---- src/emucore/elf/BusTransactionQueue.hxx | 6 +-- src/emucore/elf/ElfEnvironment.cxx | 4 +- src/emucore/elf/ElfParser.cxx | 2 +- src/gui/EventMappingWidget.cxx | 2 +- src/gui/FavoritesManager.cxx | 2 +- src/gui/FileListWidget.cxx | 2 +- src/gui/HighScoresDialog.cxx | 2 +- src/gui/JoystickDialog.cxx | 2 +- src/gui/QuadTariDialog.cxx | 4 +- src/gui/UndoHandler.cxx | 15 ------- src/gui/UndoHandler.hxx | 13 +++++- src/gui/VideoAudioDialog.cxx | 2 +- src/os/windows/FSNodeWINDOWS.cxx | 6 +-- src/os/windows/SerialPortWINDOWS.cxx | 2 +- 44 files changed, 130 insertions(+), 152 deletions(-) diff --git a/src/common/FBBackendSDL2.cxx b/src/common/FBBackendSDL2.cxx index b9c3f396f..32ec510bf 100644 --- a/src/common/FBBackendSDL2.cxx +++ b/src/common/FBBackendSDL2.cxx @@ -83,7 +83,7 @@ void FBBackendSDL2::queryHardware(vector& fullscreenRes, myNumDisplays = SDL_GetNumVideoDisplays(); // First get the maximum fullscreen desktop resolution - SDL_DisplayMode display; + SDL_DisplayMode display{}; for(int i = 0; i < myNumDisplays; ++i) { SDL_GetDesktopDisplayMode(i, &display); @@ -133,7 +133,7 @@ void FBBackendSDL2::queryHardware(vector& fullscreenRes, SDL_DestroyWindow(tmpWindow); } - SDL_Rect r; + SDL_Rect r{}; for(int i = 0; i < myNumDisplays; ++i) { // Display bounds minus dock @@ -261,7 +261,7 @@ bool FBBackendSDL2::setVideoMode(const VideoModeHandler::Mode& mode, } #ifdef ADAPTABLE_REFRESH_SUPPORT - SDL_DisplayMode adaptedSdlMode; + SDL_DisplayMode adaptedSdlMode{}; const int gameRefreshRate = myOSystem.hasConsole() ? myOSystem.console().gameRefreshRate() : 0; const bool shouldAdapt = fullScreen @@ -374,7 +374,7 @@ bool FBBackendSDL2::adaptRefreshRate(Int32 displayIndex, // Check for integer factors 1 (60/50 Hz) and 2 (120/100 Hz) for(int m = 1; m <= 2; ++m) { - SDL_DisplayMode closestSdlMode; + SDL_DisplayMode closestSdlMode{}; sdlMode.refresh_rate = wantedRefreshRate * m; if(SDL_GetClosestDisplayMode(displayIndex, &sdlMode, &closestSdlMode) == nullptr) @@ -416,7 +416,7 @@ bool FBBackendSDL2::createRenderer() bool recreate = myRenderer == nullptr; uInt32 renderFlags = SDL_RENDERER_ACCELERATED; const string& video = myOSystem.settings().getString("video"); // Render hint - SDL_RendererInfo renderInfo; + SDL_RendererInfo renderInfo{}; if(myOSystem.settings().getBool("vsync") && !myOSystem.settings().getBool("turbo")) // V'synced blits option diff --git a/src/common/HighScoresManager.hxx b/src/common/HighScoresManager.hxx index 10896ba73..8570688ba 100644 --- a/src/common/HighScoresManager.hxx +++ b/src/common/HighScoresManager.hxx @@ -132,7 +132,7 @@ class HighScoresManager @return The number of score address bytes */ - static uInt32 numAddrBytes(Int32 digits, Int32 trailing) { + static constexpr uInt32 numAddrBytes(Int32 digits, Int32 trailing) { return (digits - trailing + 1) / 2; } diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index 582e2b6a2..c04bda535 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -367,7 +367,7 @@ void SoundSDL2::initResampler() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SoundSDL2::callback(void* object, uInt8* stream, int len) { - auto* self = static_cast(object); + const auto* self = static_cast(object); if(self->myAudioQueue && self->myResampler) { diff --git a/src/common/StellaKeys.hxx b/src/common/StellaKeys.hxx index 3b6693be5..642561394 100644 --- a/src/common/StellaKeys.hxx +++ b/src/common/StellaKeys.hxx @@ -442,7 +442,7 @@ namespace StellaKeyName inline string_view forKey(StellaKey key) { #ifdef SDL_SUPPORT - return SDL_GetScancodeName(SDL_Scancode(key)); + return SDL_GetScancodeName(static_cast(key)); #else return string_view{}; #endif diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index 64d97f50c..180fd97f3 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -206,7 +206,7 @@ namespace BSPF try { int i{}; s = s.substr(s.find_first_not_of(' ')); - auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE); + const auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE); return result.ec == std::errc() ? i : defaultValue; } catch(...) { return defaultValue; } @@ -262,7 +262,7 @@ namespace BSPF } // Test whether the first string contains the second one (case insensitive) - inline constexpr bool containsIgnoreCase(string_view s1, string_view s2) + constexpr bool containsIgnoreCase(string_view s1, string_view s2) { return findIgnoreCase(s1, s2) != string::npos; } diff --git a/src/common/main.cxx b/src/common/main.cxx index 372d61162..84ed7f592 100644 --- a/src/common/main.cxx +++ b/src/common/main.cxx @@ -124,7 +124,7 @@ void checkForCustomBaseDir(Settings::Options& options) OSystem::overrideBaseDirWithApp(); else { - auto it = options.find("basedir"); + const auto it = options.find("basedir"); if(it != options.end()) OSystem::overrideBaseDir(it->second.toString()); } @@ -161,7 +161,7 @@ void attachConsole() CONSOLE_SCREEN_BUFFER_INFO csbi; if(GetConsoleScreenBufferInfo(hConsole, &csbi)) { - COORD pos = {0, csbi.dwCursorPosition.Y}; + const COORD pos = {0, csbi.dwCursorPosition.Y}; SetConsoleCursorPosition(hConsole, pos); cout << std::setw(160) << ""; // this clears the extra prompt display SetConsoleCursorPosition(hConsole, pos); diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 33a9fa777..52df0d3ba 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -378,7 +378,7 @@ bool CartDebug::fillDisassemblyList(BankInfo& info, Disassembly& disassembly, disassembly.fieldwidth = 24 + myLabelLength; // line offset must be set before calling DiStella! - auto lineOfs = static_cast(myDisassembly.list.size()); + const auto lineOfs = static_cast(myDisassembly.list.size()); const DiStella distella(*this, disassembly.list, info, DiStella::settings, myDisLabels, myDisDirectives, myReserved); @@ -1209,7 +1209,7 @@ string CartDebug::saveDisassembly(string path) cart.lockHotspots(); // Some boilerplate, similar to what DiStella adds - auto timeinfo = BSPF::localTime(); + const auto timeinfo = BSPF::localTime(); stringstream out; out << "; Disassembly of " << myOSystem.romFile().getShortPath() << "\n" << "; Disassembled " << std::put_time(&timeinfo, "%c\n") diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index 636506a27..dd552dbdd 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -2170,7 +2170,7 @@ void DebuggerParser::executeSaveRom() void DebuggerParser::executeSaveSes() { ostringstream filename; // NOLINT (filename is not a const) - auto timeinfo = BSPF::localTime(); + const auto timeinfo = BSPF::localTime(); filename << std::put_time(&timeinfo, "session_%F_%H-%M-%S.txt"); if(argCount && argStrings[0] == "?") @@ -2356,8 +2356,8 @@ void DebuggerParser::executeTimer() } uInt32 numAddrs = 0, numBanks = 0; - uInt16 addr[2]; - uInt8 bank[2]; + uInt16 addr[2]{}; + uInt8 bank[2]{}; // set defaults: addr[0] = debugger.cpuDebug().pc() ; diff --git a/src/debugger/TimerMap.cxx b/src/debugger/TimerMap.cxx index 946a59f67..0c478ffc4 100644 --- a/src/debugger/TimerMap.cxx +++ b/src/debugger/TimerMap.cxx @@ -94,7 +94,7 @@ uInt32 TimerMap::add(uInt16 addr, uInt8 bank, bool mirrors, bool anyBank) // update tp key in myFromMap for new mirrors & anyBank settings // 1. find map entry using OLD tp key settings: toKey(tpFrom, oldMirrors, oldAnyBank); - auto from = myFromMap.equal_range(tpFrom); + const auto from = myFromMap.equal_range(tpFrom); for(auto it = from.first; it != from.second; ++it) if(it->second == &tmPartial) { diff --git a/src/debugger/gui/AudioWidget.cxx b/src/debugger/gui/AudioWidget.cxx index 3e2c2795d..b348d77ca 100644 --- a/src/debugger/gui/AudioWidget.cxx +++ b/src/debugger/gui/AudioWidget.cxx @@ -35,8 +35,9 @@ AudioWidget::AudioWidget(GuiObject* boss, const GUI::Font& lfont, { const int fontWidth = lfont.getMaxCharWidth(), fontHeight = lfont.getFontHeight(), - lineHeight = lfont.getLineHeight(); - int xpos = 10, ypos = 25, lwidth = lfont.getStringWidth("AUDW "); + lineHeight = lfont.getLineHeight(), + lwidth = lfont.getStringWidth("AUDW "); + int xpos = 10, ypos = 25; // AudF registers new StaticTextWidget(boss, lfont, xpos, ypos+2, diff --git a/src/debugger/gui/BoosterWidget.cxx b/src/debugger/gui/BoosterWidget.cxx index ac5d0539b..4d7ccc58a 100644 --- a/src/debugger/gui/BoosterWidget.cxx +++ b/src/debugger/gui/BoosterWidget.cxx @@ -24,10 +24,11 @@ BoosterWidget::BoosterWidget(GuiObject* boss, const GUI::Font& font, { const string& label = isLeftPort() ? "Left (Booster)" : "Right (Booster)"; - const int fontHeight = font.getFontHeight(); - int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Booster)"); - auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, - fontHeight, label, TextAlign::Left); + const int fontHeight = font.getFontHeight(), + lwidth = font.getStringWidth("Right (Booster)"); + int xpos = x, ypos = y; + const auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, + fontHeight, label, TextAlign::Left); xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 10; myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "", CheckboxWidget::kCheckActionCmd); diff --git a/src/debugger/gui/Cart3EPlusWidget.cxx b/src/debugger/gui/Cart3EPlusWidget.cxx index e46ed2180..e26c440a6 100644 --- a/src/debugger/gui/Cart3EPlusWidget.cxx +++ b/src/debugger/gui/Cart3EPlusWidget.cxx @@ -120,7 +120,7 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos) label.str(""); label << "$" << Common::Base::HEX4 << addr1 << "-$" << Common::Base::HEX4 << (addr1 + 0x1FF); - auto* t = new StaticTextWidget(_boss, _font, xpos_s, ypos_s + 2, label.view()); + const auto* t = new StaticTextWidget(_boss, _font, xpos_s, ypos_s + 2, label.view()); const int xoffset = t->getRight() + _font.getMaxCharWidth(); const size_t bank_off = static_cast(seg) * 2; diff --git a/src/debugger/gui/Cart3EWidget.cxx b/src/debugger/gui/Cart3EWidget.cxx index e794bb9af..3715b3da2 100644 --- a/src/debugger/gui/Cart3EWidget.cxx +++ b/src/debugger/gui/Cart3EWidget.cxx @@ -84,7 +84,7 @@ void Cartridge3EWidget::bankSelect(int& ypos) myBankWidgets[0]->setID(0); addFocusWidget(myBankWidgets[0]); - auto* t = new StaticTextWidget(_boss, _font, + const auto* t = new StaticTextWidget(_boss, _font, myBankWidgets[0]->getRight(), ypos - 1, " (ROM)"); xpos = t->getRight() + 20; diff --git a/src/debugger/gui/CartELFStateWidget.cxx b/src/debugger/gui/CartELFStateWidget.cxx index cb5868ed1..6b3c77c6b 100644 --- a/src/debugger/gui/CartELFStateWidget.cxx +++ b/src/debugger/gui/CartELFStateWidget.cxx @@ -156,7 +156,8 @@ void CartridgeELFStateWidget::loadConfig() s << myCart.myTransactionQueue.size(); myQueueSize->setText(s.str()); - BusTransactionQueue::Transaction* nextTransaction = myCart.myTransactionQueue.peekNextTransaction(); + const BusTransactionQueue::Transaction* nextTransaction = + myCart.myTransactionQueue.peekNextTransaction(); myNextTransaction->setLabel(nextTransaction ? describeTransaction( nextTransaction->address, diff --git a/src/debugger/gui/CartFA2Widget.cxx b/src/debugger/gui/CartFA2Widget.cxx index 097880a5b..ea8e496ab 100644 --- a/src/debugger/gui/CartFA2Widget.cxx +++ b/src/debugger/gui/CartFA2Widget.cxx @@ -26,11 +26,10 @@ CartridgeFA2Widget::CartridgeFA2Widget( myCartFA2{cart} { int xpos = 2; - const int ypos = initialize() + 12; + const int ypos = initialize() + 12, + bwidth = _font.getStringWidth("Erase") + 20; - const int bwidth = _font.getStringWidth("Erase") + 20; - - auto* t = new StaticTextWidget(boss, _font, xpos, ypos, + const auto* t = new StaticTextWidget(boss, _font, xpos, ypos, _font.getStringWidth("Harmony flash memory "), myFontHeight, "Harmony flash memory ", TextAlign::Left); diff --git a/src/debugger/gui/GenesisWidget.cxx b/src/debugger/gui/GenesisWidget.cxx index 6dab3cbe8..562d290ee 100644 --- a/src/debugger/gui/GenesisWidget.cxx +++ b/src/debugger/gui/GenesisWidget.cxx @@ -24,11 +24,12 @@ GenesisWidget::GenesisWidget(GuiObject* boss, const GUI::Font& font, { const string& label = getHeader(); - const int fontHeight = font.getFontHeight(); - int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Genesis)"); + const int fontHeight = font.getFontHeight(), + lwidth = font.getStringWidth("Right (Genesis)"); + int xpos = x, ypos = y; const StaticTextWidget* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, - fontHeight, label, TextAlign::Left); + fontHeight, label, TextAlign::Left); xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 20; myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "", CheckboxWidget::kCheckActionCmd); diff --git a/src/debugger/gui/Joy2BPlusWidget.cxx b/src/debugger/gui/Joy2BPlusWidget.cxx index 41e5093f6..4b23663e2 100644 --- a/src/debugger/gui/Joy2BPlusWidget.cxx +++ b/src/debugger/gui/Joy2BPlusWidget.cxx @@ -24,10 +24,11 @@ Joy2BPlusWidget::Joy2BPlusWidget(GuiObject* boss, const GUI::Font& font, { const string& label = isLeftPort() ? "Left (Joy 2B+)" : "Right (Joy 2B+)"; - const int fontHeight = font.getFontHeight(); - int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Joy 2B+)"); - auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, - fontHeight, label, TextAlign::Left); + const int fontHeight = font.getFontHeight(), + lwidth = font.getStringWidth("Right (Joy 2B+)"); + int xpos = x, ypos = y; + const auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, + fontHeight, label, TextAlign::Left); xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 10; myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "", CheckboxWidget::kCheckActionCmd); diff --git a/src/debugger/gui/KeyboardWidget.cxx b/src/debugger/gui/KeyboardWidget.cxx index 4bcbae7c3..6adb7d1a9 100644 --- a/src/debugger/gui/KeyboardWidget.cxx +++ b/src/debugger/gui/KeyboardWidget.cxx @@ -26,8 +26,9 @@ KeyboardWidget::KeyboardWidget(GuiObject* boss, const GUI::Font& font, const bool leftport = isLeftPort(); const string& label = leftport ? "Left (Keyboard)" : "Right (Keyboard)"; - const int fontHeight = font.getFontHeight(); - int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Keyboard)"); + const int fontHeight = font.getFontHeight(), + lwidth = font.getStringWidth("Right (Keyboard)"); + int xpos = x, ypos = y; const StaticTextWidget* t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, fontHeight, label, TextAlign::Left); diff --git a/src/debugger/gui/PaddleWidget.cxx b/src/debugger/gui/PaddleWidget.cxx index 6362fde98..c1a819a88 100644 --- a/src/debugger/gui/PaddleWidget.cxx +++ b/src/debugger/gui/PaddleWidget.cxx @@ -25,10 +25,9 @@ PaddleWidget::PaddleWidget(GuiObject* boss, const GUI::Font& font, int x, int y, { const bool leftport = isLeftPort(); const string& label = getHeader(); - const int fontHeight = font.getFontHeight(); - - int xpos = x, ypos = y, - lwidth = font.getStringWidth("Right (Paddles)"); + const int fontHeight = font.getFontHeight(), + lwidth = font.getStringWidth("Right (Paddles)"); + int xpos = x, ypos = y; if(!embedded) { diff --git a/src/debugger/gui/RomWidget.cxx b/src/debugger/gui/RomWidget.cxx index ee1d0bd91..2501b302e 100644 --- a/src/debugger/gui/RomWidget.cxx +++ b/src/debugger/gui/RomWidget.cxx @@ -36,7 +36,7 @@ RomWidget::RomWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n { // Show current bank state int xpos = x, ypos = y + 7; - auto* t = new StaticTextWidget(boss, lfont, xpos, ypos, "Info "); + const auto* t = new StaticTextWidget(boss, lfont, xpos, ypos, "Info "); xpos += t->getRight(); myBank = new EditTextWidget(boss, nfont, xpos, ypos-2, @@ -90,7 +90,7 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) case RomListWidget::kRomChangedCmd: // 'data' is the line in the disassemblylist to be accessed // 'id' is the base to use for the data to be changed - patchROM(data, myRomList->getText(), Common::Base::Fmt(id)); + patchROM(data, myRomList->getText(), static_cast(id)); break; case RomListWidget::kSetPCCmd: diff --git a/src/emucore/CartELF.cxx b/src/emucore/CartELF.cxx index 2ee2e0d53..feba01324 100644 --- a/src/emucore/CartELF.cxx +++ b/src/emucore/CartELF.cxx @@ -412,7 +412,7 @@ string CartridgeELF::getDebugLog() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::pair, size_t> CartridgeELF::getArmImage() const { - const size_t imageSize = ADDR_TABLES_BASE + TABLES_SIZE; + constexpr size_t imageSize = ADDR_TABLES_BASE + TABLES_SIZE; unique_ptr image = make_unique(imageSize); memset(image.get(), 0, imageSize); @@ -430,7 +430,7 @@ std::pair, size_t> CartridgeELF::getArmImage() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inline uInt8 CartridgeELF::driveBus(uInt16 address, uInt8 value) { - auto* nextTransaction = myTransactionQueue.getNextTransaction(address, + const auto* nextTransaction = myTransactionQueue.getNextTransaction(address, mySystem->cycles() * myArmCyclesPer6502Cycle - myArmCyclesOffset); if (nextTransaction) { nextTransaction->setBusState(myIsBusDriven, myDriveBusValue); @@ -459,7 +459,7 @@ void CartridgeELF::parseAndLinkElf() try { myElfParser.parse(myImage.get(), myImageSize); - } catch (ElfParser::ElfParseError& e) { + } catch (const ElfParser::ElfParseError& e) { throw runtime_error("failed to initialize ELF: " + string(e.what())); } @@ -695,7 +695,7 @@ void CartridgeELF::BusFallbackDelegate::setErrorsAreFatal(bool fatal) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CortexM0::err_t CartridgeELF::BusFallbackDelegate::handleError( - string_view accessType, uInt32 address, CortexM0::err_t err, CortexM0& cortex + string_view accessType, uInt32 address, CortexM0::err_t err, const CortexM0& cortex ) const { if (myErrorsAreFatal) return CortexM0::errIntrinsic(err, address); diff --git a/src/emucore/CartELF.hxx b/src/emucore/CartELF.hxx index f455a9e5d..e0c543160 100644 --- a/src/emucore/CartELF.hxx +++ b/src/emucore/CartELF.hxx @@ -113,7 +113,7 @@ class CartridgeELF: public Cartridge { private: CortexM0::err_t handleError( - string_view accessType, uInt32 address, CortexM0::err_t err, CortexM0& cortex + string_view accessType, uInt32 address, CortexM0::err_t err, const CortexM0& cortex ) const; private: diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index bcc9d7d8c..3aa436a03 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -775,7 +775,7 @@ FBInitStatus Console::initializeVideo(bool full) if(full) { - auto size = myOSystem.settings().getBool("tia.correct_aspect") ? + const auto size = myOSystem.settings().getBool("tia.correct_aspect") ? Common::Size(TIAConstants::viewableWidth, TIAConstants::viewableHeight) : Common::Size(2 * myTIA->width(), myTIA->height()); diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 75c789a1b..46141d632 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -15,8 +15,6 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -#include - #include "System.hxx" #include "Control.hxx" @@ -148,51 +146,12 @@ Controller::Type Controller::getType(string_view propName) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Controller::setDigitalDeadZone(int deadZone) -{ - DIGITAL_DEAD_ZONE = digitalDeadZoneValue(deadZone); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int Controller::digitalDeadZoneValue(int deadZone) -{ - deadZone = BSPF::clamp(deadZone, MIN_DIGITAL_DEADZONE, MAX_DIGITAL_DEADZONE); - - return 3200 + deadZone * 1000; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Controller::setAnalogDeadZone(int deadZone) -{ - ANALOG_DEAD_ZONE = analogDeadZoneValue(deadZone); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int Controller::analogDeadZoneValue(int deadZone) -{ - deadZone = BSPF::clamp(deadZone, MIN_ANALOG_DEADZONE, MAX_ANALOG_DEADZONE); - - return deadZone * std::round(32768 / 2. / MAX_DIGITAL_DEADZONE); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Controller::setMouseSensitivity(int sensitivity) -{ - MOUSE_SENSITIVITY = BSPF::clamp(sensitivity, MIN_MOUSE_SENSE, MAX_MOUSE_SENSE); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Controller::setAutoFire(bool enable) -{ - AUTO_FIRE = enable; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Controller::setAutoFireRate(int rate, bool isNTSC) -{ - rate = BSPF::clamp(rate, 0, isNTSC ? 30 : 25); - AUTO_FIRE_RATE = 32 * 1024 * rate / (isNTSC ? 60 : 50); -} +// int Controller::analogDeadZoneValue(int deadZone) +// { +// deadZone = BSPF::clamp(deadZone, MIN_ANALOG_DEADZONE, MAX_ANALOG_DEADZONE); +// +// return deadZone * std::round(32768 / 2. / MAX_DIGITAL_DEADZONE); +// } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int Controller::DIGITAL_DEAD_ZONE = 3200; diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index 77f4ee8f1..88567152c 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -23,6 +23,7 @@ class ControllerLowLevel; class Event; class System; +#include #include #include "bspf.hxx" @@ -286,24 +287,35 @@ class Controller : public Serializable @param deadZone Value from 0 to 29 */ - static void setDigitalDeadZone(int deadZone); + static void setDigitalDeadZone(int deadZone) { + DIGITAL_DEAD_ZONE = digitalDeadZoneValue(deadZone); + } /** Sets the dead zone for analog paddles. @param deadZone Value from 0 to 29 */ - static void setAnalogDeadZone(int deadZone); + static void setAnalogDeadZone(int deadZone) { + ANALOG_DEAD_ZONE = analogDeadZoneValue(deadZone); + } /** Retrieves the effective digital dead zone value */ - static int digitalDeadZoneValue(int deadZone); + static constexpr int digitalDeadZoneValue(int deadZone) { + deadZone = BSPF::clamp(deadZone, MIN_DIGITAL_DEADZONE, MAX_DIGITAL_DEADZONE); + return 3200 + deadZone * 1000; + } /** Retrieves the effective analog dead zone value + TODO: std::round not constexpr until C++23 */ - static int analogDeadZoneValue(int deadZone); + static /*constexpr*/ int analogDeadZoneValue(int deadZone) { + deadZone = BSPF::clamp(deadZone, MIN_ANALOG_DEADZONE, MAX_ANALOG_DEADZONE); + return deadZone * std::round(32768 / 2. / MAX_DIGITAL_DEADZONE); + } static int digitalDeadZone() { return DIGITAL_DEAD_ZONE; } static int analogDeadZone() { return ANALOG_DEAD_ZONE; } @@ -315,14 +327,18 @@ class Controller : public Serializable @param sensitivity Value from 1 to MAX_MOUSE_SENSE, with larger values causing more movement */ - static void setMouseSensitivity(int sensitivity); + static void setMouseSensitivity(int sensitivity) { + MOUSE_SENSITIVITY = BSPF::clamp(sensitivity, MIN_MOUSE_SENSE, MAX_MOUSE_SENSE); + } /** Set auto fire state. @param enable The new autofire state */ - static void setAutoFire(bool enable); + static void setAutoFire(bool enable) { + AUTO_FIRE = enable; + } /** Sets the auto fire rate. 0 disables auto fire. @@ -330,7 +346,10 @@ class Controller : public Serializable @param rate Auto fire rate (0..30/25) in Hz @param isNTSC NTSC or PAL frame rate */ - static void setAutoFireRate(int rate, bool isNTSC = true); + static void setAutoFireRate(int rate, bool isNTSC = true) { + rate = BSPF::clamp(rate, 0, isNTSC ? 30 : 25); + AUTO_FIRE_RATE = 32 * 1024 * rate / (isNTSC ? 60 : 50); + } protected: /** diff --git a/src/emucore/CortexM0.cxx b/src/emucore/CortexM0.cxx index a7f2826a2..ef210b8e1 100644 --- a/src/emucore/CortexM0.cxx +++ b/src/emucore/CortexM0.cxx @@ -591,7 +591,7 @@ void CortexM0::MemoryRegion::saveDirtyBits(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CortexM0::MemoryRegion::loadDirtyBits(Serializer& in) +void CortexM0::MemoryRegion::loadDirtyBits(const Serializer& in) { if (type != MemoryRegionType::directCode && type != MemoryRegionType::directData) return; diff --git a/src/emucore/CortexM0.hxx b/src/emucore/CortexM0.hxx index b3c86c802..96db55408 100644 --- a/src/emucore/CortexM0.hxx +++ b/src/emucore/CortexM0.hxx @@ -191,7 +191,7 @@ class CortexM0: public Serializable void reset(); void saveDirtyBits(Serializer& out) const; - void loadDirtyBits(Serializer& in); + void loadDirtyBits(const Serializer& in); private: MemoryRegion(const MemoryRegion&) = delete; diff --git a/src/emucore/PlusROM.cxx b/src/emucore/PlusROM.cxx index db3e70fdc..e2fe29f1d 100644 --- a/src/emucore/PlusROM.cxx +++ b/src/emucore/PlusROM.cxx @@ -499,7 +499,7 @@ void PlusROM::receive() ByteArray PlusROM::getSend() const { ByteArray arr; - uInt8 txPos = myTxPos != 0 ? myTxPos : myLastTxPos; + const uInt8 txPos = myTxPos != 0 ? myTxPos : myLastTxPos; for(int i = 0; i < txPos; ++i) arr.push_back(myTxBuffer[i]); @@ -511,7 +511,7 @@ ByteArray PlusROM::getSend() const ByteArray PlusROM::getReceive() const { ByteArray arr; - uInt8 txReadPos = myRxReadPos != myRxWritePos ? myRxReadPos : myLastRxReadPos; + const uInt8 txReadPos = myRxReadPos != myRxWritePos ? myRxReadPos : myLastRxReadPos; for(uInt8 i = txReadPos; i != myRxWritePos; ++i) arr.push_back(myRxBuffer[i]); diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 678265278..6008812fe 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -264,7 +264,7 @@ TIASurface::ScanlineMask TIASurface::scanlineMaskType(int direction) int i = 0; const string& name = myOSystem.settings().getString("tv.scanmask"); - for(const auto& mask: Masks) + for(const auto mask: Masks) { if(mask == name) { diff --git a/src/emucore/elf/BusTransactionQueue.cxx b/src/emucore/elf/BusTransactionQueue.cxx index c00c32dfe..08de0da6f 100644 --- a/src/emucore/elf/BusTransactionQueue.cxx +++ b/src/emucore/elf/BusTransactionQueue.cxx @@ -21,17 +21,17 @@ #include "exception/FatalEmulationError.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -BusTransactionQueue::Transaction BusTransactionQueue::Transaction::transactionYield( - uInt16 address, uInt64 timestamp, uInt16 mask -) { +constexpr BusTransactionQueue::Transaction BusTransactionQueue::Transaction::transactionYield( + uInt16 address, uInt64 timestamp, uInt16 mask) +{ address &= 0x1fff; return {.address = address, .mask = mask, .value = 0, .timestamp = timestamp, .yield = true}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -BusTransactionQueue::Transaction BusTransactionQueue::Transaction::transactionDrive( - uInt16 address, uInt8 value, uInt64 timestamp -) { +constexpr BusTransactionQueue::Transaction BusTransactionQueue::Transaction::transactionDrive( + uInt16 address, uInt8 value, uInt64 timestamp) +{ address &= 0x1fff; return {.address = address, .mask = 0xffff, .value = value, .timestamp = timestamp, .yield = false}; } @@ -118,7 +118,7 @@ void BusTransactionQueue::Transaction::serialize(Serializer& out) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void BusTransactionQueue::Transaction::deserialize(Serializer& in) +void BusTransactionQueue::Transaction::deserialize(const Serializer& in) { address = in.getShort(); mask = in.getShort(); diff --git a/src/emucore/elf/BusTransactionQueue.hxx b/src/emucore/elf/BusTransactionQueue.hxx index 82226f3a5..314c91702 100644 --- a/src/emucore/elf/BusTransactionQueue.hxx +++ b/src/emucore/elf/BusTransactionQueue.hxx @@ -26,8 +26,8 @@ class Serializer; class BusTransactionQueue: public Serializable { public: struct Transaction { - static Transaction transactionYield(uInt16 address, uInt64 timestamp, uInt16 mask); - static Transaction transactionDrive(uInt16 address, uInt8 value, uInt64 timestamp); + static constexpr Transaction transactionYield(uInt16 address, uInt64 timestamp, uInt16 mask); + static constexpr Transaction transactionDrive(uInt16 address, uInt8 value, uInt64 timestamp); void setBusState(bool& drive, uInt8& value) const; @@ -38,7 +38,7 @@ class BusTransactionQueue: public Serializable { bool yield{false}; void serialize(Serializer& out) const; - void deserialize(Serializer& in); + void deserialize(const Serializer& in); }; public: diff --git a/src/emucore/elf/ElfEnvironment.cxx b/src/emucore/elf/ElfEnvironment.cxx index 9963c049a..a2d8df488 100644 --- a/src/emucore/elf/ElfEnvironment.cxx +++ b/src/emucore/elf/ElfEnvironment.cxx @@ -18,7 +18,7 @@ #include "ElfEnvironment.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const uInt8 elfEnvironment::OVERBLANK_PROGRAM[] = { +constexpr uInt8 elfEnvironment::OVERBLANK_PROGRAM[] = { 0xa0,0x00, // ldy #0 0xa5,0xe0, // lda $e0 // OverblankLoop: @@ -53,7 +53,7 @@ const uInt8 elfEnvironment::OVERBLANK_PROGRAM[] = { }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const uInt32 elfEnvironment::OVERBLANK_PROGRAM_SIZE = sizeof(elfEnvironment::OVERBLANK_PROGRAM); +constexpr uInt32 elfEnvironment::OVERBLANK_PROGRAM_SIZE = sizeof(elfEnvironment::OVERBLANK_PROGRAM); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const uInt8 elfEnvironment::LOOKUP_TABLES[3 * 256] = { diff --git a/src/emucore/elf/ElfParser.cxx b/src/emucore/elf/ElfParser.cxx index b3541c525..f9cb2ddec 100644 --- a/src/emucore/elf/ElfParser.cxx +++ b/src/emucore/elf/ElfParser.cxx @@ -254,7 +254,7 @@ const char* ElfParser::getName(const Section& section, uInt32 offset) const if (offset >= section.size) ElfParseError::raise("name out of bounds"); const uInt32 imageOffset = offset + section.offset; - const char *name = reinterpret_cast(myData + imageOffset); + const char* name = reinterpret_cast(myData + imageOffset); if (myData[imageOffset + strnlen(name, section.size - offset)] != '\0') ElfParseError::raise("unterminated section name"); diff --git a/src/gui/EventMappingWidget.cxx b/src/gui/EventMappingWidget.cxx index 19c860816..b0070cb4b 100644 --- a/src/gui/EventMappingWidget.cxx +++ b/src/gui/EventMappingWidget.cxx @@ -124,7 +124,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, // Show message for currently selected event xpos = HBORDER; ypos = myActionsList->getBottom() + VGAP * 2; - auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, "Action"); + const auto* t = new StaticTextWidget(boss, font, xpos, ypos+2, "Action"); myKeyMapping = new EditTextWidget(boss, font, xpos + t->getWidth() + fontWidth, ypos, _w - xpos - t->getWidth() - fontWidth - HBORDER + 2, diff --git a/src/gui/FavoritesManager.cxx b/src/gui/FavoritesManager.cxx index 352cbd0ad..358946979 100644 --- a/src/gui/FavoritesManager.cxx +++ b/src/gui/FavoritesManager.cxx @@ -220,7 +220,7 @@ void FavoritesManager::addRecent(string_view path) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool FavoritesManager::removeRecent(string_view path) { - auto it = std::ranges::find(myRecentList, path); + const auto it = std::ranges::find(myRecentList, path); if(it != myRecentList.end()) myRecentList.erase(it); diff --git a/src/gui/FileListWidget.cxx b/src/gui/FileListWidget.cxx index 3fcaaa5ab..51caf2149 100644 --- a/src/gui/FileListWidget.cxx +++ b/src/gui/FileListWidget.cxx @@ -685,7 +685,7 @@ const FileListWidget::Icon* FileListWidget::getIcon(int i) const 0b11111111111'11111111110, 0b11111111111'11111111110 }; - const int idx = static_cast(IconType::numTypes); + constexpr int idx = static_cast(IconType::numTypes); static const Icon* const small_icons[idx] = { &unknown_small, &rom_small, &directory_small, &zip_small, &up_small }; diff --git a/src/gui/HighScoresDialog.cxx b/src/gui/HighScoresDialog.cxx index 2a6dd05ea..0ffbc44c7 100644 --- a/src/gui/HighScoresDialog.cxx +++ b/src/gui/HighScoresDialog.cxx @@ -132,7 +132,7 @@ HighScoresDialog::HighScoresDialog(OSystem& osystem, DialogContainer& parent, int ypos = VBORDER + _th; ypos += lineHeight + VGAP * 2; // space for game name - auto* s = new StaticTextWidget(this, _font, xpos, ypos + 1, "Variation "); + const auto* s = new StaticTextWidget(this, _font, xpos, ypos + 1, "Variation "); myVariationPopup = new PopUpWidget(this, _font, s->getRight(), ypos, _font.getStringWidth("256"), lineHeight, items, "", 0, kVariationChanged); wid.push_back(myVariationPopup); diff --git a/src/gui/JoystickDialog.cxx b/src/gui/JoystickDialog.cxx index 18acdf66d..584109110 100644 --- a/src/gui/JoystickDialog.cxx +++ b/src/gui/JoystickDialog.cxx @@ -48,7 +48,7 @@ JoystickDialog::JoystickDialog(GuiObject* boss, const GUI::Font& font, // Joystick ID ypos = _h - VBORDER - (buttonHeight + lineHeight) / 2; - auto* t = new StaticTextWidget(this, font, xpos, ypos, "Controller ID "); + const auto* t = new StaticTextWidget(this, font, xpos, ypos, "Controller ID "); xpos += t->getWidth(); myJoyText = new EditTextWidget(this, font, xpos, ypos - 2, font.getStringWidth("Unplugged "), lineHeight, ""); diff --git a/src/gui/QuadTariDialog.cxx b/src/gui/QuadTariDialog.cxx index 7d164a32a..693e40da4 100644 --- a/src/gui/QuadTariDialog.cxx +++ b/src/gui/QuadTariDialog.cxx @@ -177,13 +177,13 @@ void QuadTariDialog::defineController(const Properties& props, PropType key, { if(instance().hasConsole()) { - Controller& controller = (jack == Controller::Jack::Left + const Controller& controller = (jack == Controller::Jack::Left ? instance().console().leftController() : instance().console().rightController()); if(BSPF::startsWithIgnoreCase(controller.name(), "QT")) { - const QuadTari* qt = static_cast(&controller); + const auto* qt = static_cast(&controller); label = (first ? qt->firstController().name() : qt->secondController().name()) diff --git a/src/gui/UndoHandler.cxx b/src/gui/UndoHandler.cxx index 1e6ccf529..63c26d026 100644 --- a/src/gui/UndoHandler.cxx +++ b/src/gui/UndoHandler.cxx @@ -89,18 +89,3 @@ bool UndoHandler::redo(string& text) } return false; } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 UndoHandler::lastDiff(string_view text, string_view oldText) -{ - auto pos = static_cast(text.size()); - - for(auto itn = text.crbegin(), ito = oldText.crbegin(); - itn != text.crend() && ito != oldText.crend(); ++itn, ++ito) - { - if(*itn != *ito) - break; - pos--; - } - return pos; -} diff --git a/src/gui/UndoHandler.hxx b/src/gui/UndoHandler.hxx index 3cfb9931b..620031326 100644 --- a/src/gui/UndoHandler.hxx +++ b/src/gui/UndoHandler.hxx @@ -48,7 +48,18 @@ class UndoHandler bool endChars(string_view text); // Get index into text of last different character - static uInt32 lastDiff(string_view text, string_view oldText); + static constexpr uInt32 lastDiff(string_view text, string_view oldText) { + auto pos = static_cast(text.size()); + + for (auto itn = text.crbegin(), ito = oldText.crbegin(); + itn != text.crend() && ito != oldText.crend(); ++itn, ++ito) + { + if (*itn != *ito) + break; + pos--; + } + return pos; + } private: std::deque myBuffer; diff --git a/src/gui/VideoAudioDialog.cxx b/src/gui/VideoAudioDialog.cxx index 32dc0dede..065de45d5 100644 --- a/src/gui/VideoAudioDialog.cxx +++ b/src/gui/VideoAudioDialog.cxx @@ -315,7 +315,7 @@ void VideoAudioDialog::addPaletteTab() CREATE_CUSTOM_SLIDERS(Gamma, "Gamma ", kPaletteUpdated) ypos += VGAP; - auto* s = new StaticTextWidget(myTab, _font, xpos, ypos + 1, "Autodetection"); + const auto* s = new StaticTextWidget(myTab, _font, xpos, ypos + 1, "Autodetection"); myDetectPal60 = new CheckboxWidget(myTab, _font, s->getRight() + fontWidth * 2, ypos + 1, "PAL-60"); myDetectPal60 ->setToolTip("Enable autodetection of PAL-60 based on colors used."); diff --git a/src/os/windows/FSNodeWINDOWS.cxx b/src/os/windows/FSNodeWINDOWS.cxx index 7549a528d..d68f5d508 100644 --- a/src/os/windows/FSNodeWINDOWS.cxx +++ b/src/os/windows/FSNodeWINDOWS.cxx @@ -40,9 +40,9 @@ FSNodeWINDOWS::FSNodeWINDOWS(string_view p) bool FSNodeWINDOWS::setFlags() { // Get absolute path - static TCHAR buf[MAX_PATH]; - if (GetFullPathName(_path.c_str(), MAX_PATH - 1, buf, NULL)) - _path = buf; + static std::array buf; + if (GetFullPathName(_path.c_str(), MAX_PATH - 1, buf.data(), NULL)) + _path = buf.data(); _displayName = lastPathComponent(_path); diff --git a/src/os/windows/SerialPortWINDOWS.cxx b/src/os/windows/SerialPortWINDOWS.cxx index fdbbd4854..2342466de 100644 --- a/src/os/windows/SerialPortWINDOWS.cxx +++ b/src/os/windows/SerialPortWINDOWS.cxx @@ -116,7 +116,7 @@ StringList SerialPortWINDOWS::portNames() L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &hKey); if (result == ERROR_SUCCESS) { - TCHAR deviceName[2048], friendlyName[32]; + TCHAR deviceName[2048]{}, friendlyName[32]{}; DWORD numValues = 0; result = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,