diff --git a/src/cheat/BankRomCheat.cxx b/src/cheat/BankRomCheat.cxx index 1af74b696..360c3f47d 100644 --- a/src/cheat/BankRomCheat.cxx +++ b/src/cheat/BankRomCheat.cxx @@ -29,8 +29,8 @@ BankRomCheat::BankRomCheat(OSystem& os, const string& name, const string& code) bank = unhex(myCode.substr(0, 2)); address = 0xf000 + unhex(myCode.substr(2, 3)); - value = uInt8(unhex(myCode.substr(5, 2))); - count = uInt8(unhex(myCode.substr(7, 1)) + 1); + value = static_cast(unhex(myCode.substr(5, 2))); + count = static_cast(unhex(myCode.substr(7, 1)) + 1); // Back up original data; we need this if the cheat is ever disabled for(int i = 0; i < count; ++i) @@ -47,7 +47,7 @@ bool BankRomCheat::enable() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool BankRomCheat::disable() { - int oldBank = myOSystem.console().cartridge().getBank(address); + const int oldBank = myOSystem.console().cartridge().getBank(address); myOSystem.console().cartridge().bank(bank); for(int i = 0; i < count; ++i) @@ -63,7 +63,7 @@ void BankRomCheat::evaluate() { if(!myEnabled) { - int oldBank = myOSystem.console().cartridge().getBank(address); + const int oldBank = myOSystem.console().cartridge().getBank(address); myOSystem.console().cartridge().bank(bank); for(int i = 0; i < count; ++i) diff --git a/src/cheat/Cheat.hxx b/src/cheat/Cheat.hxx index 59811541c..23dd757c5 100644 --- a/src/cheat/Cheat.hxx +++ b/src/cheat/Cheat.hxx @@ -44,7 +44,7 @@ class Cheat static uInt16 unhex(const string& hex) { int ret = 0; - for(char c: hex) + for(const auto c: hex) { ret *= 16; if(c >= '0' && c <= '9') diff --git a/src/cheat/CheatCodeDialog.cxx b/src/cheat/CheatCodeDialog.cxx index ddb3ebbea..4434bfb5d 100644 --- a/src/cheat/CheatCodeDialog.cxx +++ b/src/cheat/CheatCodeDialog.cxx @@ -43,7 +43,6 @@ CheatCodeDialog::CheatCodeDialog(OSystem& osystem, DialogContainer& parent, VGAP = Dialog::vGap(), VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(); - int xpos, ypos; WidgetArray wid; ButtonWidget* b; @@ -52,7 +51,7 @@ CheatCodeDialog::CheatCodeDialog(OSystem& osystem, DialogContainer& parent, _h = _th + 11 * (lineHeight + 4) + VBORDER * 2; // List of cheats, with checkboxes to enable/disable - xpos = HBORDER; ypos = _th + VBORDER; + int xpos = HBORDER, ypos = _th + VBORDER; myCheatList = new CheckListWidget(this, font, xpos, ypos, _w - buttonWidth - HBORDER * 2 - fontWidth, _h - _th - buttonHeight - VBORDER * 3); @@ -136,7 +135,7 @@ void CheatCodeDialog::loadConfig() // Redraw the list, auto-selecting the first item if possible myCheatList->setSelected(l.size() > 0 ? 0 : -1); - bool enabled = (list.size() > 0); + const bool enabled = (list.size() > 0); myEditButton->setEnabled(enabled); myRemoveButton->setEnabled(enabled); } @@ -169,7 +168,7 @@ void CheatCodeDialog::addCheat() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CheatCodeDialog::editCheat() { - int idx = myCheatList->getSelected(); + const int idx = myCheatList->getSelected(); if(idx < 0) return; @@ -249,8 +248,8 @@ void CheatCodeDialog::handleCommand(CommandSender* sender, int cmd, { const string& name = myCheatInput->getResult(0); const string& code = myCheatInput->getResult(1); - bool enable = myCheatList->getSelectedState(); - int idx = myCheatList->getSelected(); + const bool enable = myCheatList->getSelectedState(); + const int idx = myCheatList->getSelected(); if(instance().cheat().isValidCode(code)) { myCheatInput->close(); diff --git a/src/cheat/CheatManager.cxx b/src/cheat/CheatManager.cxx index 49c5c72de..d4aedb440 100644 --- a/src/cheat/CheatManager.cxx +++ b/src/cheat/CheatManager.cxx @@ -68,7 +68,7 @@ bool CheatManager::add(const string& name, const string& code, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CheatManager::remove(int idx) { - if(uInt32(idx) < myCheatList.size()) + if(static_cast(idx) < myCheatList.size()) { // This will also remove it from the per-frame list (if applicable) myCheatList[idx]->disable(); @@ -186,6 +186,9 @@ void CheatManager::parse(const string& cheats) code = s[1]; add(name, code, s[2] == "1"); break; + + default: + break; } s.clear(); @@ -218,7 +221,6 @@ void CheatManager::loadCheatDatabase() catch(...) { return; } string line, md5, cheat; - string::size_type one, two, three, four; // Loop reading cheats while(getline(in, line)) @@ -226,10 +228,10 @@ void CheatManager::loadCheatDatabase() if(line.length() == 0) continue; - one = line.find('\"', 0); - two = line.find('\"', one + 1); - three = line.find('\"', two + 1); - four = line.find('\"', three + 1); + const string::size_type one = line.find('\"', 0); + const string::size_type two = line.find('\"', one + 1); + const string::size_type three = line.find('\"', two + 1); + const string::size_type four = line.find('\"', three + 1); // Invalid line if it doesn't contain 4 quotes if((one == string::npos) || (two == string::npos) || @@ -302,7 +304,7 @@ void CheatManager::saveCheats(const string& md5sum) // Only update the list if absolutely necessary if(changed) { - auto iter = myCheatMap.find(md5sum); + const auto iter = myCheatMap.find(md5sum); // Erase old entry and add a new one only if it's changed if(iter != myCheatMap.end()) @@ -322,10 +324,10 @@ void CheatManager::saveCheats(const string& md5sum) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CheatManager::isValidCode(const string& code) const { - for(char c: code) + for(const auto c: code) if(!isxdigit(c)) return false; - uInt32 length = uInt32(code.length()); + const size_t length = code.length(); return (length == 4 || length == 6 || length == 7 || length == 8); } diff --git a/src/cheat/CheetahCheat.cxx b/src/cheat/CheetahCheat.cxx index c95384159..36d706a95 100644 --- a/src/cheat/CheetahCheat.cxx +++ b/src/cheat/CheetahCheat.cxx @@ -23,9 +23,9 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CheetahCheat::CheetahCheat(OSystem& os, const string& name, const string& code) : Cheat(os, name, code), - address{uInt16(0xf000 + unhex(code.substr(0, 3)))}, - value{uInt8(unhex(code.substr(3, 2)))}, - count{uInt8(unhex(code.substr(5, 1)) + 1)} + address{static_cast(0xf000 + unhex(code.substr(0, 3)))}, + value{static_cast(unhex(code.substr(3, 2)))}, + count{static_cast(unhex(code.substr(5, 1)) + 1)} { // Back up original data; we need this if the cheat is ever disabled for(int i = 0; i < count; ++i) diff --git a/src/cheat/RamCheat.cxx b/src/cheat/RamCheat.cxx index 98a605068..51fd412b6 100644 --- a/src/cheat/RamCheat.cxx +++ b/src/cheat/RamCheat.cxx @@ -25,8 +25,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RamCheat::RamCheat(OSystem& os, const string& name, const string& code) : Cheat(os, name, code), - address{uInt16(unhex(myCode.substr(0, 2)))}, - value{uInt8(unhex(myCode.substr(2, 2)))} + address{static_cast(unhex(myCode.substr(0, 2)))}, + value{static_cast(unhex(myCode.substr(2, 2)))} { } diff --git a/src/common/AudioQueue.cxx b/src/common/AudioQueue.cxx index ec19a7d8d..68afe1864 100644 --- a/src/common/AudioQueue.cxx +++ b/src/common/AudioQueue.cxx @@ -44,7 +44,7 @@ AudioQueue::AudioQueue(uInt32 fragmentSize, uInt32 capacity, bool isStereo) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 AudioQueue::capacity() const { - return uInt32(myFragmentQueue.size()); + return static_cast(myFragmentQueue.size()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -72,7 +72,7 @@ Int16* AudioQueue::enqueue(Int16* fragment) { lock_guard guard(myMutex); - Int16* newFragment; + Int16* newFragment = nullptr; if (!fragment) { if (!myFirstFragmentForEnqueue) throw runtime_error("enqueue called empty"); @@ -83,7 +83,7 @@ Int16* AudioQueue::enqueue(Int16* fragment) return newFragment; } - const uInt8 capacity = uInt8(myFragmentQueue.size()); + const uInt8 capacity = static_cast(myFragmentQueue.size()); const uInt8 fragmentIndex = (myNextFragment + mySize) % capacity; newFragment = myFragmentQueue.at(fragmentIndex); diff --git a/src/common/AudioSettings.cxx b/src/common/AudioSettings.cxx index 6a5844213..c0f7eb961 100644 --- a/src/common/AudioSettings.cxx +++ b/src/common/AudioSettings.cxx @@ -19,12 +19,12 @@ #include "Settings.hxx" namespace { - uInt32 lboundInt(int x, int defaultValue) + constexpr uInt32 lboundInt(int x, int defaultValue) { return x <= 0 ? defaultValue : x; } - AudioSettings::Preset normalizedPreset(int numericPreset) + constexpr AudioSettings::Preset normalizedPreset(int numericPreset) { return ( numericPreset >= static_cast(AudioSettings::Preset::custom) && @@ -32,7 +32,7 @@ namespace { ) ? static_cast(numericPreset) : AudioSettings::DEFAULT_PRESET; } - AudioSettings::ResamplingQuality normalizeResamplingQuality(int numericResamplingQuality) + constexpr AudioSettings::ResamplingQuality normalizeResamplingQuality(int numericResamplingQuality) { return ( numericResamplingQuality >= static_cast(AudioSettings::ResamplingQuality::nearestNeightbour) && @@ -52,7 +52,7 @@ AudioSettings::AudioSettings(Settings& settings) void AudioSettings::normalize(Settings& settings) { int settingPreset = settings.getInt(SETTING_PRESET); - Preset preset = normalizedPreset(settingPreset); + const Preset preset = normalizedPreset(settingPreset); if (static_cast(preset) != settingPreset) settings.setValue(SETTING_PRESET, static_cast(DEFAULT_PRESET)); switch (settings.getInt(SETTING_SAMPLE_RATE)) { @@ -87,7 +87,7 @@ void AudioSettings::normalize(Settings& settings) if (settingHeadroom < 0 || settingHeadroom > MAX_HEADROOM) settings.setValue(SETTING_HEADROOM, DEFAULT_HEADROOM); int settingResamplingQuality = settings.getInt(SETTING_RESAMPLING_QUALITY); - ResamplingQuality resamplingQuality = normalizeResamplingQuality(settingResamplingQuality); + const ResamplingQuality resamplingQuality = normalizeResamplingQuality(settingResamplingQuality); if (static_cast(resamplingQuality) != settingResamplingQuality) settings.setValue(SETTING_RESAMPLING_QUALITY, static_cast(DEFAULT_RESAMPLING_QUALITY)); diff --git a/src/common/DevSettingsHandler.cxx b/src/common/DevSettingsHandler.cxx index 7018e557e..2b90144f3 100644 --- a/src/common/DevSettingsHandler.cxx +++ b/src/common/DevSettingsHandler.cxx @@ -28,14 +28,14 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DevSettingsHandler::DevSettingsHandler(OSystem& osystem) - : myOSystem(osystem) + : myOSystem{osystem} { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DevSettingsHandler::loadSettings(SettingsSet set) { - bool devSettings = set == SettingsSet::developer; + const bool devSettings = set == SettingsSet::developer; const string& prefix = devSettings ? "dev." : "plr."; const Settings& settings = myOSystem.settings(); @@ -91,7 +91,7 @@ void DevSettingsHandler::loadSettings(SettingsSet set) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DevSettingsHandler::saveSettings(SettingsSet set) { - bool devSettings = set == SettingsSet::developer; + const bool devSettings = set == SettingsSet::developer; const string& prefix = devSettings ? "dev." : "plr."; Settings& settings = myOSystem.settings(); @@ -220,7 +220,7 @@ void DevSettingsHandler::handleEnableDebugColors(bool enable) { if(myOSystem.hasConsole()) { - bool fixed = myOSystem.console().tia().usingFixedColors(); + const bool fixed = myOSystem.console().tia().usingFixedColors(); if(fixed != enable) myOSystem.console().tia().toggleFixedColors(); } diff --git a/src/common/EventHandlerSDL2.cxx b/src/common/EventHandlerSDL2.cxx index 212b1315a..db160a01d 100644 --- a/src/common/EventHandlerSDL2.cxx +++ b/src/common/EventHandlerSDL2.cxx @@ -30,7 +30,7 @@ EventHandlerSDL2::EventHandlerSDL2(OSystem& osystem) #ifdef GUI_SUPPORT { ostringstream buf; - myQwertz = int('y') == int(SDL_GetKeyFromScancode(SDL_Scancode(KBDK_Z))); + myQwertz = int{'y'} == static_cast(SDL_GetKeyFromScancode(SDL_Scancode(KBDK_Z))); buf << "Keyboard: " << (myQwertz ? "QWERTZ" : "QWERTY"); Logger::debug(buf.str()); } @@ -133,6 +133,8 @@ void EventHandlerSDL2::pollEvent() handleMouseButtonEvent(MouseButton::RIGHT, myEvent.button.type == SDL_MOUSEBUTTONDOWN, myEvent.button.x, myEvent.button.y); break; + default: + break; } break; } @@ -166,7 +168,8 @@ void EventHandlerSDL2::pollEvent() case SDL_JOYHATMOTION: { - int v = myEvent.jhat.value, value = 0; + int value = 0; + const int v = myEvent.jhat.value; if(v == SDL_HAT_CENTERED) value = EVENT_HATCENTER_M; else @@ -240,8 +243,13 @@ void EventHandlerSDL2::pollEvent() case SDL_WINDOWEVENT_FOCUS_LOST: handleSystemEvent(SystemEvent::WINDOW_FOCUS_LOST); break; + default: + break; } break; // SDL_WINDOWEVENT + + default: + break; } } } diff --git a/src/common/EventHandlerSDL2.hxx b/src/common/EventHandlerSDL2.hxx index bf4d27da5..e9ac999d4 100644 --- a/src/common/EventHandlerSDL2.hxx +++ b/src/common/EventHandlerSDL2.hxx @@ -56,7 +56,7 @@ class EventHandlerSDL2 : public EventHandler void pollEvent() override; private: - SDL_Event myEvent; + SDL_Event myEvent{0}; // A thin wrapper around a basic PhysicalJoystick, holding the pointer to // the underlying SDL joystick device. diff --git a/src/common/FBBackendSDL2.cxx b/src/common/FBBackendSDL2.cxx index 2b694c87a..ef35405e7 100644 --- a/src/common/FBBackendSDL2.cxx +++ b/src/common/FBBackendSDL2.cxx @@ -91,7 +91,7 @@ void FBBackendSDL2::queryHardware(vector& fullscreenRes, fullscreenRes.emplace_back(display.w, display.h); // evaluate fullscreen display modes (debug only for now) - int numModes = SDL_GetNumDisplayModes(i); + const int numModes = SDL_GetNumDisplayModes(i); ostringstream s; s << "Supported video modes (" << numModes << ") for display " << i @@ -166,7 +166,7 @@ void FBBackendSDL2::queryHardware(vector& fullscreenRes, { "software", "Software" } }}; - int numDrivers = SDL_GetNumRenderDrivers(); + const int numDrivers = SDL_GetNumRenderDrivers(); for(int i = 0; i < numDrivers; ++i) { SDL_RendererInfo info; @@ -229,9 +229,9 @@ bool FBBackendSDL2::setVideoMode(const VideoModeHandler::Mode& mode, return false; const bool fullScreen = mode.fsIndex != -1; - Int32 displayIndex = std::min(myNumDisplays - 1, winIdx); + const Int32 displayIndex = std::min(myNumDisplays - 1, winIdx); - int posX, posY; + int posX = 0, posY = 0; myCenter = myOSystem.settings().getBool("center"); if(myCenter) @@ -256,7 +256,7 @@ bool FBBackendSDL2::setVideoMode(const VideoModeHandler::Mode& mode, y1 = std::max(y1, rect.y + rect.h); } } - posX = BSPF::clamp(posX, x0 - Int32(mode.screenS.w) + 50, x1 - 50); + posX = BSPF::clamp(posX, x0 - static_cast(mode.screenS.w) + 50, x1 - 50); posY = BSPF::clamp(posY, y0 + 50, y1 - 50); } @@ -287,8 +287,8 @@ bool FBBackendSDL2::setVideoMode(const VideoModeHandler::Mode& mode, int w, h; SDL_GetWindowSize(myWindow, &w, &h); - if(d != displayIndex || uInt32(w) != mode.screenS.w || - uInt32(h) != mode.screenS.h || adaptRefresh) + if(d != displayIndex || static_cast(w) != mode.screenS.w || + static_cast(h) != mode.screenS.h || adaptRefresh) { // Renderer has to be destroyed *before* the window gets destroyed to avoid memory leaks SDL_DestroyRenderer(myRenderer); @@ -617,7 +617,7 @@ bool FBBackendSDL2::detectRenderTargetSupport() if(!tex) return false; - int sdlError = SDL_SetRenderTarget(myRenderer, tex); + const int sdlError = SDL_SetRenderTarget(myRenderer, tex); SDL_SetRenderTarget(myRenderer, nullptr); SDL_DestroyTexture(tex); diff --git a/src/common/FBSurfaceSDL2.cxx b/src/common/FBSurfaceSDL2.cxx index cf1c965f1..89a98df95 100644 --- a/src/common/FBSurfaceSDL2.cxx +++ b/src/common/FBSurfaceSDL2.cxx @@ -243,7 +243,7 @@ void FBSurfaceSDL2::createSurface(uInt32 width, uInt32 height, //////////////////////////////////////////////////// // These *must* be set for the parent class - myPixels = reinterpret_cast(mySurface->pixels); + myPixels = static_cast(mySurface->pixels); myPitch = mySurface->pitch / pf.BytesPerPixel; //////////////////////////////////////////////////// diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index aea856799..ad7a0cf4c 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -29,7 +29,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) { // Extract ZIP file and virtual file (if specified) - size_t pos = BSPF::findIgnoreCase(p, ".zip"); + const size_t pos = BSPF::findIgnoreCase(p, ".zip"); if(pos == string::npos) return; @@ -185,7 +185,7 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode) const // First strip off the leading directory const string& curr = next.substr(_virtualPath == "" ? 0 : _virtualPath.size()+1); // Only add sub-directory entries once - auto pos = curr.find_first_of("/\\"); + const auto pos = curr.find_first_of("/\\"); if(pos != string::npos) dirs.emplace(curr.substr(0, pos)); else @@ -228,7 +228,7 @@ size_t FilesystemNodeZIP::read(stringstream& image) const // For now, we just read into a buffer and store in the stream // TODO: maybe there's a more efficient way to do this? ByteBuffer buffer; - size_t size = read(buffer, 0); + const size_t size = read(buffer, 0); if(size > 0) image.write(reinterpret_cast(buffer.get()), size); diff --git a/src/common/FpsMeter.cxx b/src/common/FpsMeter.cxx index 4732a49a8..49688a315 100644 --- a/src/common/FpsMeter.cxx +++ b/src/common/FpsMeter.cxx @@ -45,7 +45,7 @@ void FpsMeter::render(uInt32 frameCount) return; } - size_t queueSize = myQueue.capacity(); + const size_t queueSize = myQueue.capacity(); entry first, last; last.frames = frameCount; @@ -64,7 +64,7 @@ void FpsMeter::render(uInt32 frameCount) first = myQueue.at(myQueueOffset); } - float myTimeInterval = + const float myTimeInterval = duration_cast>(last.timestamp - first.timestamp).count(); if (myTimeInterval > 0) myFps = (myFrameCount - first.frames) / myTimeInterval; diff --git a/src/common/HighScoresManager.cxx b/src/common/HighScoresManager.cxx index 72cfa7e1e..d1bad0b7d 100644 --- a/src/common/HighScoresManager.cxx +++ b/src/common/HighScoresManager.cxx @@ -181,7 +181,7 @@ void HighScoresManager::set(Properties& props, uInt32 numVariations, if(info.scoreInvert != DEFAULT_SCORE_REVERSED) jprops[SCORE_INVERTED] = info.scoreInvert; - uInt32 addrBytes = numAddrBytes(info.numDigits, info.trailingZeroes); + const uInt32 addrBytes = numAddrBytes(info.numDigits, info.trailingZeroes); json addresses = json::array(); for(uInt32 a = 0; a < addrBytes; ++a) @@ -312,7 +312,7 @@ Int32 HighScoresManager::variation(uInt16 addr, bool varBCD, bool zeroBased, if (!myOSystem.hasConsole()) return DEFAULT_VARIATION; - Int32 var = peek(addr); + const Int32 var = peek(addr); return convert(var, numVariations, varBCD, zeroBased); } @@ -344,11 +344,10 @@ Int32 HighScoresManager::score(uInt32 numAddrBytes, uInt32 trailingZeroes, for (uInt32 b = 0; b < numAddrBytes; ++b) { - uInt16 addr = scoreAddr[b]; - Int32 score; + const uInt16 addr = scoreAddr[b]; totalScore *= isBCD ? 100 : 256; - score = peek(addr); + Int32 score = peek(addr); if (isBCD) { score = fromBCD(score); @@ -373,7 +372,7 @@ Int32 HighScoresManager::score() const uInt32 numBytes = numAddrBytes(properties(jprops)); const ScoreAddresses scoreAddr = getPropScoreAddr(jprops); - if(uInt32(scoreAddr.size()) < numBytes) + if(static_cast(scoreAddr.size()) < numBytes) return NO_VALUE; return score(numBytes, trailingZeroes(jprops), scoreBCD(jprops), scoreAddr); } @@ -412,7 +411,7 @@ string HighScoresManager::md5Props() const buf << varAddress(jprops) << numVariations() << varBCD(jprops) << varZeroBased(jprops); - uInt32 addrBytes = numAddrBytes(jprops); + const uInt32 addrBytes = numAddrBytes(jprops); HSM::ScoreAddresses addr = getPropScoreAddr(jprops); for(uInt32 a = 0; a < addrBytes; ++a) buf << addr[a]; @@ -467,7 +466,7 @@ Int32 HighScoresManager::convert(Int32 val, uInt32 maxVal, bool isBCD, bool zero { //maxVal += zeroBased ? 0 : 1; maxVal -= zeroBased ? 1 : 0; - Int32 bits = isBCD + const Int32 bits = isBCD ? ceil(log(maxVal) / log(10) * 4) : ceil(log(maxVal) / log(2)); @@ -548,7 +547,7 @@ uInt16 HighScoresManager::fromHexStr(const string& addr) const { string naked = addr; - if(int pos = naked.find("0x") != std::string::npos) + if(const int pos = naked.find("0x") != std::string::npos) naked = naked.substr(pos + 1); return stringToIntBase16(naked); diff --git a/src/common/HighScoresManager.hxx b/src/common/HighScoresManager.hxx index 127a5f069..813ecc73a 100644 --- a/src/common/HighScoresManager.hxx +++ b/src/common/HighScoresManager.hxx @@ -50,7 +50,7 @@ namespace HSM { using ScoreAddresses = array; - static const uInt32 NUM_RANKS = 10; + static constexpr uInt32 NUM_RANKS = 10; struct ScoresProps { // Formats diff --git a/src/common/JoyMap.cxx b/src/common/JoyMap.cxx index 125c1208e..cecb5df9c 100644 --- a/src/common/JoyMap.cxx +++ b/src/common/JoyMap.cxx @@ -98,7 +98,7 @@ Event::Type JoyMap::get(const EventMode mode, const int button, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool JoyMap::check(const JoyMapping& mapping) const { - auto find = myMap.find(mapping); + const auto find = myMap.find(mapping); return (find != myMap.end()); } @@ -129,7 +129,7 @@ string JoyMap::getDesc(const Event::Type event, const JoyMapping& mapping) const case JoyAxis::X: buf << "X"; break; case JoyAxis::Y: buf << "Y"; break; case JoyAxis::Z: buf << "Z"; break; - default: buf << int(mapping.axis); break; + default: buf << static_cast(mapping.axis); break; } if(Event::isAnalog(event)) @@ -290,7 +290,7 @@ json JoyMap::convertLegacyMapping(string list) std::replace(list.begin(), list.end(), ',', ' '); istringstream buf(list); - int event, button, axis, adir, hat, hdir; + int event = 0, button = 0, axis = 0, adir = 0, hat = 0, hdir = 0; while(buf >> event && buf >> button && buf >> axis && buf >> adir @@ -302,7 +302,7 @@ json JoyMap::convertLegacyMapping(string list) if(button != JOY_CTRL_NONE) eventMapping["button"] = button; - if(JoyAxis(axis) != JoyAxis::NONE) { + if(static_cast(axis) != JoyAxis::NONE) { eventMapping["axis"] = JoyAxis(axis); eventMapping["axisDirection"] = JoyDir(adir); } @@ -323,7 +323,7 @@ void JoyMap::eraseMode(const EventMode mode) { for(auto item = myMap.begin(); item != myMap.end();) if(item->first.mode == mode) { - auto _item = item++; + const auto _item = item++; erase(_item->first); } else item++; @@ -334,7 +334,7 @@ void JoyMap::eraseEvent(const Event::Type event, const EventMode mode) { for(auto item = myMap.begin(); item != myMap.end();) if(item->second == event && item->first.mode == mode) { - auto _item = item++; + const auto _item = item++; erase(_item->first); } else item++; diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index c52d1425a..ea4f5927f 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -99,15 +99,15 @@ Event::Type KeyMap::get(const Mapping& mapping) const if(myModEnabled) { - auto find = myMap.find(m); + const auto find = myMap.find(m); if(find != myMap.end()) return find->second; } // mapping not found, try without modifiers - m.mod = StellaMod(0); + m.mod = static_cast(0); - auto find = myMap.find(m); + const auto find = myMap.find(m); if(find != myMap.end()) return find->second; @@ -123,7 +123,7 @@ Event::Type KeyMap::get(const EventMode mode, const int key, const int mod) cons // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool KeyMap::check(const Mapping& mapping) const { - auto find = myMap.find(convertMod(mapping)); + const auto find = myMap.find(convertMod(mapping)); return (find != myMap.end()); } @@ -139,23 +139,23 @@ string KeyMap::getDesc(const Mapping& mapping) const { ostringstream buf; #if defined(BSPF_MACOS) || defined(MACOS_KEYS) - string mod2 = "Option"; - int MOD2 = KBDM_ALT; - int LMOD2 = KBDM_LALT; - int RMOD2 = KBDM_RALT; - string mod3 = "Cmd"; - int MOD3 = KBDM_GUI; - int LMOD3 = KBDM_LGUI; - int RMOD3 = KBDM_RGUI; + const string mod2 = "Option"; + constexpr int MOD2 = KBDM_ALT; + constexpr int LMOD2 = KBDM_LALT; + constexpr int RMOD2 = KBDM_RALT; + const string mod3 = "Cmd"; + constexpr int MOD3 = KBDM_GUI; + constexpr int LMOD3 = KBDM_LGUI; + constexpr int RMOD3 = KBDM_RGUI; #else - string mod2 = "Windows"; - int MOD2 = KBDM_GUI; - int LMOD2 = KBDM_LGUI; - int RMOD2 = KBDM_RGUI; - string mod3 = "Alt"; - int MOD3 = KBDM_ALT; - int LMOD3 = KBDM_LALT; - int RMOD3 = KBDM_RALT; + const string mod2 = "Windows"; + constexpr int MOD2 = KBDM_GUI; + constexpr int LMOD2 = KBDM_LGUI; + constexpr int RMOD2 = KBDM_RGUI; + const string mod3 = "Alt"; + constexpr int MOD3 = KBDM_ALT; + constexpr int LMOD3 = KBDM_LALT; + constexpr int RMOD3 = KBDM_RALT; #endif if((mapping.mod & KBDM_CTRL) == KBDM_CTRL) buf << "Ctrl"; @@ -295,7 +295,7 @@ json KeyMap::convertLegacyMapping(string list) std::replace(list.begin(), list.end(), ':', ' '); std::replace(list.begin(), list.end(), ',', ' '); istringstream buf(list); - int event, key, mod; + int event = 0, key = 0, mod = 0; while(buf >> event && buf >> key && buf >> mod) { @@ -318,7 +318,7 @@ void KeyMap::eraseMode(const EventMode mode) { for(auto item = myMap.begin(); item != myMap.end();) if(item->first.mode == mode) { - auto _item = item++; + const auto _item = item++; erase(_item->first); } else item++; @@ -329,7 +329,7 @@ void KeyMap::eraseEvent(const Event::Type event, const EventMode mode) { for(auto item = myMap.begin(); item != myMap.end();) if(item->second == event && item->first.mode == mode) { - auto _item = item++; + const auto _item = item++; erase(_item->first); } else item++; @@ -346,7 +346,7 @@ KeyMap::Mapping KeyMap::convertMod(const Mapping& mapping) const else { // limit to modifiers we want to support - m.mod = StellaMod(m.mod & (KBDM_SHIFT | KBDM_CTRL | KBDM_ALT | KBDM_GUI)); + m.mod = static_cast(m.mod & (KBDM_SHIFT | KBDM_CTRL | KBDM_ALT | KBDM_GUI)); } return m; diff --git a/src/common/KeyMap.hxx b/src/common/KeyMap.hxx index 52f452683..a6fef3d5f 100644 --- a/src/common/KeyMap.hxx +++ b/src/common/KeyMap.hxx @@ -41,7 +41,7 @@ class KeyMap explicit Mapping(EventMode c_mode, StellaKey c_key, StellaMod c_mod) : mode{c_mode}, key{c_key}, mod{c_mod} { } explicit Mapping(EventMode c_mode, int c_key, int c_mod) - : mode{c_mode}, key{StellaKey(c_key)}, mod{StellaMod(c_mod)} { } + : mode{c_mode}, key{static_cast(c_key)}, mod{static_cast(c_mod)} { } Mapping(const Mapping&) = default; Mapping& operator=(const Mapping&) = default; Mapping(Mapping&&) = default; diff --git a/src/common/LinkedObjectPool.hxx b/src/common/LinkedObjectPool.hxx index a74c9f737..e2c9629db 100644 --- a/src/common/LinkedObjectPool.hxx +++ b/src/common/LinkedObjectPool.hxx @@ -256,9 +256,9 @@ class LinkedObjectPool uInt32 capacity() const { return myCapacity; } - uInt32 size() const { return uInt32(myList.size()); } - bool empty() const { return size() == 0; } - bool full() const { return size() >= capacity(); } + uInt32 size() const { return static_cast(myList.size()); } + bool empty() const { return size() == 0; } + bool full() const { return size() >= capacity(); } friend ostream& operator<<(ostream& os, const LinkedObjectPool& p) { for(const auto& i: p.myList) diff --git a/src/common/MouseControl.cxx b/src/common/MouseControl.cxx index 2b5213156..73e06313b 100644 --- a/src/common/MouseControl.cxx +++ b/src/common/MouseControl.cxx @@ -41,14 +41,14 @@ MouseControl::MouseControl(Console& console, const string& mode) m_mode[0] >= '0' && m_mode[0] <= '8' && m_mode[1] >= '0' && m_mode[1] <= '8') { - MouseControl::Type xaxis = MouseControl::Type(int(m_mode[0]) - '0'); - MouseControl::Type yaxis = MouseControl::Type(int(m_mode[1]) - '0'); + const MouseControl::Type xaxis = static_cast(static_cast(m_mode[0]) - '0'); + const MouseControl::Type yaxis = static_cast(static_cast(m_mode[1]) - '0'); ostringstream msg; Controller::Type xtype = Controller::Type::Joystick, ytype = Controller::Type::Joystick; int xid = -1, yid = -1; - auto MControlToController = [&msg](MouseControl::Type axis, - Controller::Type& type, int& id) { + const auto MControlToController = [&msg](MouseControl::Type axis, + Controller::Type& type, int& id) { switch(axis) { case MouseControl::Type::NoControl: @@ -107,7 +107,7 @@ MouseControl::MouseControl(Console& console, const string& mode) // Now consider the possible modes for the mouse based on the left // and right controllers - bool noswap = BSPF::equalsIgnoreCase(myProps.get(PropType::Console_SwapPorts), "NO"); + const bool noswap = BSPF::equalsIgnoreCase(myProps.get(PropType::Console_SwapPorts), "NO"); if(noswap) { addLeftControllerModes(noswap); @@ -139,12 +139,13 @@ MouseControl::MouseControl(Console& console, const string& mode) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& MouseControl::change(int direction) { - myCurrentModeNum = BSPF::clampw(myCurrentModeNum + direction, 0, int(myModeList.size() - 1)); + myCurrentModeNum = BSPF::clampw(myCurrentModeNum + direction, 0, + static_cast(myModeList.size() - 1)); const MouseMode& mode = myModeList[myCurrentModeNum]; - bool leftControl = + const bool leftControl = myLeftController.setMouseControl(mode.xtype, mode.xid, mode.ytype, mode.yid); - bool rightControl = + const bool rightControl = myRightController.setMouseControl(mode.xtype, mode.xid, mode.ytype, mode.yid); myHasMouseControl = leftControl || rightControl; @@ -197,14 +198,14 @@ void MouseControl::addRightControllerModes(bool noswap) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void MouseControl::addPaddleModes(int lport, int rport, int lname, int rname) { - Controller::Type type = Controller::Type::Paddles; + const Controller::Type type = Controller::Type::Paddles; ostringstream msg; msg << "Mouse is Paddle " << lname << " controller"; - MouseMode mode0(type, lport, type, lport, msg.str()); + const MouseMode mode0(type, lport, type, lport, msg.str()); msg.str(""); msg << "Mouse is Paddle " << rname << " controller"; - MouseMode mode1(type, rport, type, rport, msg.str()); + const MouseMode mode1(type, rport, type, rport, msg.str()); if(BSPF::equalsIgnoreCase(myProps.get(PropType::Controller_SwapPaddles), "NO")) { diff --git a/src/common/MouseControl.hxx b/src/common/MouseControl.hxx index 61bf3d7fe..203c5e404 100644 --- a/src/common/MouseControl.hxx +++ b/src/common/MouseControl.hxx @@ -85,20 +85,16 @@ class MouseControl int xid{-1}, yid{-1}; string message; - explicit MouseMode(const string& msg = "") : message(msg) { } + explicit MouseMode(const string& msg = "") : message{msg} { } MouseMode(Controller::Type xt, int xi, Controller::Type yt, int yi, const string& msg) - : xtype(xt), - ytype(yt), - xid(xi), - yid(yi), - message(msg) { } + : xtype{xt}, ytype{yt}, xid{xi}, yid{yi}, message{msg} { } friend ostream& operator<<(ostream& os, const MouseMode& mm) { - os << "xtype=" << int(mm.xtype) << ", xid=" << mm.xid - << ", ytype=" << int(mm.ytype) << ", yid=" << mm.yid + os << "xtype=" << static_cast(mm.xtype) << ", xid=" << mm.xid + << ", ytype=" << static_cast(mm.ytype) << ", yid=" << mm.yid << ", msg=" << mm.message; return os; } diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 173a7482d..6873bed78 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -138,7 +138,7 @@ int PhysicalJoystickHandler::add(const PhysicalJoystickPtr& stick) if(erased) // We have to add all Stelladaptors again, because they have changed // name due to being reordered when mapping them - for(auto& [_id, _stick] : mySticks) + for(const auto& [_id, _stick] : mySticks) { if(_stick->name.find(" (emulates ") != std::string::npos) addToDatabase(_stick); @@ -162,7 +162,7 @@ int PhysicalJoystickHandler::add(const PhysicalJoystickPtr& stick) void PhysicalJoystickHandler::addToDatabase(const PhysicalJoystickPtr& stick) { // Add stick to database - auto it = myDatabase.find(stick->name); + const auto it = myDatabase.find(stick->name); if(it != myDatabase.end()) // already present { it->second.joy = stick; @@ -195,7 +195,7 @@ bool PhysicalJoystickHandler::remove(int id) { PhysicalJoystickPtr stick = mySticks.at(id); - auto it = myDatabase.find(stick->name); + const auto it = myDatabase.find(stick->name); if(it != myDatabase.end() && it->second.joy == stick) { ostringstream buf; @@ -222,7 +222,7 @@ bool PhysicalJoystickHandler::remove(int id) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool PhysicalJoystickHandler::remove(const string& name) { - auto it = myDatabase.find(name); + const auto it = myDatabase.find(name); if(it != myDatabase.end() && it->second.joy == nullptr) { myDatabase.erase(it); @@ -248,10 +248,10 @@ bool PhysicalJoystickHandler::mapStelladaptors(const string& saport, int ID) saOrder[0] = 2; saOrder[1] = 1; } - for(auto& [_id, _stick]: mySticks) + for(const auto& [_id, _stick]: mySticks) { bool found = false; - size_t pos = _stick->name.find(" (emulates "); + const size_t pos = _stick->name.find(" (emulates "); if(pos != std::string::npos && ID != -1 && ID < _stick->ID) { @@ -303,7 +303,7 @@ bool PhysicalJoystickHandler::hasStelladaptors() const for(auto& [_id, _joyptr] : mySticks) { // remove previously added emulated ports - size_t pos = _joyptr->name.find(" (emulates "); + const size_t pos = _joyptr->name.find(" (emulates "); if(pos != std::string::npos) _joyptr->name.erase(pos); @@ -328,7 +328,7 @@ void PhysicalJoystickHandler::setDefaultAction(int stick, // If event is 'NoType', erase and reset all mappings // Otherwise, only reset the given event - bool eraseAll = !updateDefaults && (event == Event::NoType); + const bool eraseAll = !updateDefaults && (event == Event::NoType); if(updateDefaults) { @@ -395,9 +395,9 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even } #if defined(RETRON77) - const bool retron77 = true; + constexpr bool retron77 = true; #else - const bool retron77 = false; + constexpr bool retron77 = false; #endif // Regular joysticks can only be used by one player at a time, @@ -588,7 +588,7 @@ void PhysicalJoystickHandler::enableCommonMappings() { for (int i = Event::NoType + 1; i < Event::LastType; i++) { - Event::Type event = static_cast(i); + const Event::Type event = static_cast(i); if(isCommonEvent(event)) enableMapping(event, EventMode::kCommonMode); @@ -683,7 +683,7 @@ void PhysicalJoystickHandler::eraseMapping(Event::Type event, EventMode mode) // Otherwise, only reset the given event if(event == Event::NoType) { - for (auto& [_id, _joyptr]: mySticks) + for (const auto& [_id, _joyptr]: mySticks) { _joyptr->eraseMap(mode); // erase all events if(mode == EventMode::kEmulationMode) @@ -698,7 +698,7 @@ void PhysicalJoystickHandler::eraseMapping(Event::Type event, EventMode mode) } else { - for (auto& [_id, _joyptr]: mySticks) + for (const auto& [_id, _joyptr]: mySticks) { _joyptr->eraseEvent(event, mode); // only reset the specific event _joyptr->eraseEvent(event, getEventMode(event, mode)); @@ -727,7 +727,7 @@ void PhysicalJoystickHandler::saveMapping() string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode) const { ostringstream buf; - EventMode evMode = getEventMode(event, mode); + const EventMode evMode = getEventMode(event, mode); for(const auto& [_id, _joyptr]: mySticks) { @@ -753,9 +753,9 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i if(j && event < Event::LastType && button >= JOY_CTRL_NONE && button < j->numButtons && - axis >= JoyAxis::NONE && int(axis) < j->numAxes) + axis >= JoyAxis::NONE && static_cast(axis) < j->numAxes) { - EventMode evMode = getEventMode(event, mode); + const EventMode evMode = getEventMode(event, mode); // This confusing code is because each axis has two associated values, // but analog events only affect one of the axis. @@ -796,7 +796,7 @@ bool PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode button >= JOY_CTRL_NONE && button < j->numButtons && hat >= 0 && hat < j->numHats && hdir != JoyHatDir::CENTER) { - EventMode evMode = getEventMode(event, mode); + const EventMode evMode = getEventMode(event, mode); // avoid double mapping in common and controller modes if (evMode == EventMode::kCommonMode) @@ -825,7 +825,7 @@ bool PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) { - const PhysicalJoystickPtr j = joy(stick); + const PhysicalJoystickPtr& j = joy(stick); if(j) { @@ -869,19 +869,20 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr j, +void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr& j, int stick, int axis, int value) { - int button = j->buttonLast[stick]; + const int button = j->buttonLast[stick]; if(myHandler.state() == EventHandlerState::EMULATION) { - Event::Type eventAxisAnalog; + Event::Type eventAxisAnalog{}; // Check for analog events, which are handled differently // A value change lower than ~90% indicates analog input if((abs(j->axisLastValue[axis] - value) < 30000) - && (eventAxisAnalog = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::ANALOG)) != Event::Type::NoType) + && (eventAxisAnalog = j->joyMap.get(EventMode::kEmulationMode, button, + static_cast(axis), JoyDir::ANALOG)) != Event::Type::NoType) { myHandler.handleEvent(eventAxisAnalog, value); } @@ -889,8 +890,10 @@ void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr j { // Otherwise, we assume the event is digital // Every axis event has two associated values, negative and positive - Event::Type eventAxisNeg = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::NEG); - Event::Type eventAxisPos = j->joyMap.get(EventMode::kEmulationMode, button, JoyAxis(axis), JoyDir::POS); + const Event::Type eventAxisNeg = j->joyMap.get(EventMode::kEmulationMode, button, + static_cast(axis), JoyDir::NEG); + const Event::Type eventAxisPos = j->joyMap.get(EventMode::kEmulationMode, button, + static_cast(axis), JoyDir::POS); if(value > Controller::digitalDeadZone()) myHandler.handleEvent(eventAxisPos); @@ -932,10 +935,11 @@ void PhysicalJoystickHandler::handleRegularAxisEvent(const PhysicalJoystickPtr j // Now filter out consecutive, similar values // (only pass on the event if the state has changed) if(value != j->axisLastValue[axis]) - myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), convertAxisValue(value), button); + myHandler.overlay().handleJoyAxisEvent(stick, static_cast(axis), + convertAxisValue(value), button); } else - myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), JoyDir::NONE, button); + myHandler.overlay().handleJoyAxisEvent(stick, static_cast(axis), JoyDir::NONE, button); j->axisLastValue[axis] = value; } #endif diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index 7a609b08c..e32f87fac 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -95,15 +95,15 @@ class PhysicalJoystickHandler void handleHatEvent(int stick, int hat, int value); Event::Type eventForAxis(EventMode mode, int stick, JoyAxis axis, JoyDir adir, int button) const { - const PhysicalJoystickPtr j = joy(stick); + const PhysicalJoystickPtr& j = joy(stick); return j->joyMap.get(mode, button, axis, adir); } Event::Type eventForButton(EventMode mode, int stick, int button) const { - const PhysicalJoystickPtr j = joy(stick); + const PhysicalJoystickPtr& j = joy(stick); return j->joyMap.get(mode, button); } Event::Type eventForHat(EventMode mode, int stick, int hat, JoyHatDir hatDir, int button) const { - const PhysicalJoystickPtr j = joy(stick); + const PhysicalJoystickPtr& j = joy(stick); return j->joyMap.get(mode, button, hat, hatDir); } @@ -156,7 +156,7 @@ class PhysicalJoystickHandler } // Handle regular axis events (besides special Stelladaptor handling) - void handleRegularAxisEvent(const PhysicalJoystickPtr j, + void handleRegularAxisEvent(const PhysicalJoystickPtr& j, int stick, int axis, int value); // Structures used for action menu items diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index f835dc9b4..a1ed83659 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -128,7 +128,7 @@ void PhysicalKeyboardHandler::setDefaultKey(EventMapping map, Event::Type event, { // If event is 'NoType', erase and reset all mappings // Otherwise, only reset the given event - bool eraseAll = !updateDefaults && (event == Event::NoType); + const bool eraseAll = !updateDefaults && (event == Event::NoType); #ifdef GUI_SUPPORT // Swap Y and Z for QWERTZ keyboards @@ -148,13 +148,13 @@ void PhysicalKeyboardHandler::setDefaultKey(EventMapping map, Event::Type event, if (myKeyMap.getEventMapping(map.event, mode).size() == 0 && !isMappingUsed(mode, map)) { - addMapping(map.event, mode, map.key, StellaMod(map.mod)); + addMapping(map.event, mode, map.key, static_cast(map.mod)); } } else if (eraseAll || map.event == event) { //myKeyMap.eraseEvent(map.event, mode); - addMapping(map.event, mode, map.key, StellaMod(map.mod)); + addMapping(map.event, mode, map.key, static_cast(map.mod)); } } @@ -239,7 +239,7 @@ void PhysicalKeyboardHandler::defineControllerMappings( default: { - EventMode mode = getMode(type); + const EventMode mode = getMode(type); if(port == Controller::Jack::Left) myLeftMode = mode; @@ -377,7 +377,7 @@ void PhysicalKeyboardHandler::enableCommonMappings() { for (int i = Event::NoType + 1; i < Event::LastType; i++) { - Event::Type event = static_cast(i); + const Event::Type event = static_cast(i); if (isCommonEvent(event)) enableMapping(event, EventMode::kCommonMode); @@ -495,7 +495,7 @@ bool PhysicalKeyboardHandler::addMapping(Event::Type event, EventMode mode, return false; else { - EventMode evMode = getEventMode(event, mode); + const EventMode evMode = getEventMode(event, mode); // avoid double mapping in common and controller modes if (evMode == EventMode::kCommonMode) @@ -543,13 +543,13 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, } #endif - EventHandlerState estate = myHandler.state(); + const EventHandlerState estate = myHandler.state(); // special handling for CompuMate in emulation modes if ((estate == EventHandlerState::EMULATION || estate == EventHandlerState::PAUSE) && myOSystem.console().leftController().type() == Controller::Type::CompuMate) { - Event::Type event = myKeyMap.get(EventMode::kCompuMateMode, key, mod); + const Event::Type event = myKeyMap.get(EventMode::kCompuMateMode, key, mod); // (potential) CompuMate events are handled directly. if (myKeyMap.get(EventMode::kEmulationMode, key, mod) != Event::ExitMode && diff --git a/src/common/PNGLibrary.cxx b/src/common/PNGLibrary.cxx index 688effad3..1bbe09e4d 100644 --- a/src/common/PNGLibrary.cxx +++ b/src/common/PNGLibrary.cxx @@ -40,12 +40,12 @@ PNGLibrary::PNGLibrary(OSystem& osystem) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PNGLibrary::loadImage(const string& filename, FBSurface& surface) { - png_structp png_ptr = nullptr; - png_infop info_ptr = nullptr; - png_uint_32 iwidth, iheight; - int bit_depth, color_type, interlace_type; + png_structp png_ptr{nullptr}; + png_infop info_ptr{nullptr}; + png_uint_32 iwidth{0}, iheight{0}; + int bit_depth{0}, color_type{0}, interlace_type{0}; - auto loadImageERROR = [&](const char* s) { + const auto loadImageERROR = [&](const char* s) { if(png_ptr) png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : nullptr, nullptr); if(s) @@ -106,7 +106,7 @@ void PNGLibrary::loadImage(const string& filename, FBSurface& surface) // The PNG read function expects an array of rows, not a single 1-D array for(uInt32 irow = 0, offset = 0; irow < ReadInfo.height; ++irow, offset += ReadInfo.pitch) - ReadInfo.row_pointers[irow] = static_cast(ReadInfo.buffer.data() + offset); + ReadInfo.row_pointers[irow] = ReadInfo.buffer.data() + offset; // Read the entire image in one go png_read_image(png_ptr, ReadInfo.row_pointers.data()); @@ -137,7 +137,7 @@ void PNGLibrary::saveImage(const string& filename, const VariantList& comments) fb.scaleX(rectUnscaled.w()), fb.scaleY(rectUnscaled.h()) ); - png_uint_32 width = rect.w(), height = rect.h(); + const png_uint_32 width = rect.w(), height = rect.h(); // Get framebuffer pixel data (we get ABGR format) vector buffer(width * height * 4); @@ -146,7 +146,7 @@ void PNGLibrary::saveImage(const string& filename, const VariantList& comments) // Set up pointers into "buffer" byte array vector rows(height); for(png_uint_32 k = 0; k < height; ++k) - rows[k] = static_cast(buffer.data() + k*width*4); + rows[k] = buffer.data() + k*width*4; // And save the image saveImageToDisk(out, rows, width, height, comments); @@ -175,7 +175,7 @@ void PNGLibrary::saveImage(const string& filename, const FBSurface& surface, // Set up pointers into "buffer" byte array vector rows(height); for(png_uint_32 k = 0; k < height; ++k) - rows[k] = static_cast(buffer.data() + k*width*4); + rows[k] = buffer.data() + k*width*4; // And save the image saveImageToDisk(out, rows, width, height, comments); @@ -188,7 +188,7 @@ void PNGLibrary::saveImageToDisk(std::ofstream& out, const vector& ro png_structp png_ptr = nullptr; png_infop info_ptr = nullptr; - auto saveImageERROR = [&](const char* s) { + const auto saveImageERROR = [&](const char* s) { if(png_ptr) png_destroy_write_struct(&png_ptr, &info_ptr); if(s) @@ -247,7 +247,7 @@ void PNGLibrary::saveImageToDisk(std::ofstream& out, const vector& ro void PNGLibrary::updateTime(uInt64 time) { if(++mySnapCounter % mySnapInterval == 0) - takeSnapshot(uInt32(time) >> 10); // not quite milliseconds, but close enough + takeSnapshot(static_cast(time) >> 10); // not quite milliseconds, but close enough } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -265,7 +265,7 @@ void PNGLibrary::toggleContinuousSnapshots(bool perFrame) else { buf << "Enabling snapshots in " << interval << " second intervals"; - interval *= uInt32(myOSystem.frameRate()); + interval *= static_cast(myOSystem.frameRate()); } myOSystem.frameBuffer().showTextMessage(buf.str()); setContinuousSnapInterval(interval); @@ -385,11 +385,11 @@ void PNGLibrary::takeSnapshot(uInt32 number) bool PNGLibrary::allocateStorage(png_uint_32 w, png_uint_32 h) { // Create space for the entire image (3 bytes per pixel in RGB format) - size_t req_buffer_size = w * h * 3; + const size_t req_buffer_size = w * h * 3; if(req_buffer_size > ReadInfo.buffer.size()) ReadInfo.buffer.resize(req_buffer_size); - size_t req_row_size = h; + const size_t req_row_size = h; if(req_row_size > ReadInfo.row_pointers.size()) ReadInfo.row_pointers.resize(req_row_size); @@ -404,7 +404,7 @@ bool PNGLibrary::allocateStorage(png_uint_32 w, png_uint_32 h) void PNGLibrary::loadImagetoSurface(FBSurface& surface) { // First determine if we need to resize the surface - uInt32 iw = ReadInfo.width, ih = ReadInfo.height; + const uInt32 iw = ReadInfo.width, ih = ReadInfo.height; if(iw > surface.width() || ih > surface.height()) surface.resize(iw, ih); @@ -430,10 +430,10 @@ void PNGLibrary::loadImagetoSurface(FBSurface& surface) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PNGLibrary::writeComments(png_structp png_ptr, png_infop info_ptr, +void PNGLibrary::writeComments(const png_structp png_ptr, png_infop info_ptr, const VariantList& comments) { - uInt32 numComments = uInt32(comments.size()); + const uInt32 numComments = static_cast(comments.size()); if(numComments == 0) return; @@ -449,33 +449,33 @@ void PNGLibrary::writeComments(png_structp png_ptr, png_infop info_ptr, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PNGLibrary::png_read_data(png_structp ctx, png_bytep area, png_size_t size) +void PNGLibrary::png_read_data(const png_structp ctx, png_bytep area, png_size_t size) { (static_cast(png_get_io_ptr(ctx)))->read( reinterpret_cast(area), size); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PNGLibrary::png_write_data(png_structp ctx, png_bytep area, png_size_t size) +void PNGLibrary::png_write_data(const png_structp ctx, png_bytep area, png_size_t size) { (static_cast(png_get_io_ptr(ctx)))->write( reinterpret_cast(area), size); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PNGLibrary::png_io_flush(png_structp ctx) +void PNGLibrary::png_io_flush(const png_structp ctx) { (static_cast(png_get_io_ptr(ctx)))->flush(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PNGLibrary::png_user_warn(png_structp ctx, png_const_charp str) +void PNGLibrary::png_user_warn(const png_structp ctx, png_const_charp str) { throw runtime_error(string("PNGLibrary warning: ") + str); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PNGLibrary::png_user_error(png_structp ctx, png_const_charp str) +void PNGLibrary::png_user_error(const png_structp ctx, png_const_charp str) { throw runtime_error(string("PNGLibrary error: ") + str); } diff --git a/src/common/PNGLibrary.hxx b/src/common/PNGLibrary.hxx index 12b415269..814c20a49 100644 --- a/src/common/PNGLibrary.hxx +++ b/src/common/PNGLibrary.hxx @@ -180,15 +180,15 @@ class PNGLibrary /** Write PNG tEXt chunks to the image. */ - void writeComments(png_structp png_ptr, png_infop info_ptr, + void writeComments(const png_structp png_ptr, png_infop info_ptr, const VariantList& comments); /** PNG library callback functions */ - static void png_read_data(png_structp ctx, png_bytep area, png_size_t size); - static void png_write_data(png_structp ctx, png_bytep area, png_size_t size); - static void png_io_flush(png_structp ctx); - [[noreturn]] static void png_user_warn(png_structp ctx, png_const_charp str); - [[noreturn]] static void png_user_error(png_structp ctx, png_const_charp str); + static void png_read_data(const png_structp ctx, png_bytep area, png_size_t size); + static void png_write_data(const png_structp ctx, png_bytep area, png_size_t size); + static void png_io_flush(const png_structp ctx); + [[noreturn]] static void png_user_warn(const png_structp ctx, png_const_charp str); + [[noreturn]] static void png_user_error(const png_structp ctx, png_const_charp str); private: // Following constructors and assignment operators not supported diff --git a/src/common/PaletteHandler.cxx b/src/common/PaletteHandler.cxx index 628e69734..25781e00c 100644 --- a/src/common/PaletteHandler.cxx +++ b/src/common/PaletteHandler.cxx @@ -62,10 +62,11 @@ void PaletteHandler::cyclePalette(int direction) int type = toPaletteType(myOSystem.settings().getString("palette")); do { - type = BSPF::clampw(type + direction, int(PaletteType::MinType), int(PaletteType::MaxType)); + type = BSPF::clampw(type + direction, + static_cast(PaletteType::MinType), static_cast(PaletteType::MaxType)); } while(type == PaletteType::User && !myUserPaletteDefined); - const string palette = toPaletteName(PaletteType(type)); + const string palette = toPaletteName(static_cast(type)); const string message = MESSAGES[type] + " palette"; myOSystem.frameBuffer().showTextMessage(message); @@ -139,10 +140,11 @@ void PaletteHandler::showAdjustableMessage() void PaletteHandler::cycleAdjustable(int direction) { const bool isCustomPalette = SETTING_CUSTOM == myOSystem.settings().getString("palette"); - bool isCustomAdj; + bool isCustomAdj = false; do { - myCurrentAdjustable = BSPF::clampw(int(myCurrentAdjustable + direction), 0, NUM_ADJUSTABLES - 1); + myCurrentAdjustable = BSPF::clampw(static_cast(myCurrentAdjustable + direction), 0, + NUM_ADJUSTABLES - 1); isCustomAdj = isCustomAdjustable(); // skip phase shift when 'Custom' palette is not selected if(!direction && isCustomAdj && !isCustomPalette) @@ -330,7 +332,7 @@ void PaletteHandler::setPalette() const ConsoleTiming timing = myOSystem.console().timing(); const PaletteType paletteType = toPaletteType(name); // Now consider the current display format - const PaletteArray* palette = palettes[paletteType][int(timing)]; + const PaletteArray* palette = palettes[paletteType][static_cast(timing)]; if(paletteType == PaletteType::Custom) generateCustomPalette(timing); @@ -342,7 +344,7 @@ void PaletteHandler::setPalette() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PaletteArray PaletteHandler::adjustedPalette(const PaletteArray& palette) { - PaletteArray destPalette; + PaletteArray destPalette{0}; // Constants for saturation and gray scale calculation constexpr float PR = .2989F; constexpr float PG = .5870F; @@ -358,7 +360,7 @@ PaletteArray PaletteHandler::adjustedPalette(const PaletteArray& palette) const float gamma = 1.1333F - myGamma * 0.5F; /* match common PC's 2.2 gamma to TV's 2.65 gamma */ constexpr float toFloat = 1.F / (ADJUST_SIZE - 1); - std::array adjust; + std::array adjust{0}; for(int i = 0; i < ADJUST_SIZE; i++) adjust[i] = powf(i * toFloat, gamma) * contrast + brightness; @@ -408,19 +410,25 @@ void PaletteHandler::loadUserPalette() uInt8* pixbuf = in.get(); for(int i = 0; i < 128; i++, pixbuf += 3) // NTSC palette { - const uInt32 pixel = (int(pixbuf[0]) << 16) + (int(pixbuf[1]) << 8) + int(pixbuf[2]); + const uInt32 pixel = (static_cast(pixbuf[0]) << 16) + + (static_cast(pixbuf[1]) << 8) + + static_cast(pixbuf[2]); ourUserNTSCPalette[(i<<1)] = pixel; } for(int i = 0; i < 128; i++, pixbuf += 3) // PAL palette { - const uInt32 pixel = (int(pixbuf[0]) << 16) + (int(pixbuf[1]) << 8) + int(pixbuf[2]); + const uInt32 pixel = (static_cast(pixbuf[0]) << 16) + + (static_cast(pixbuf[1]) << 8) + + static_cast(pixbuf[2]); ourUserPALPalette[(i<<1)] = pixel; } - std::array secam; // All 8 24-bit pixels, plus 8 colorloss pixels + std::array secam{0}; // All 8 24-bit pixels, plus 8 colorloss pixels for(int i = 0; i < 8; i++, pixbuf += 3) // SECAM palette { - const uInt32 pixel = (int(pixbuf[0]) << 16) + (int(pixbuf[1]) << 8) + int(pixbuf[2]); + const uInt32 pixel = (static_cast(pixbuf[0]) << 16) + + (static_cast(pixbuf[1]) << 8) + + static_cast(pixbuf[2]); secam[(i<<1)] = pixel; secam[(i<<1)+1] = 0; } diff --git a/src/common/PaletteHandler.hxx b/src/common/PaletteHandler.hxx index 3acc346d2..aa04536e0 100644 --- a/src/common/PaletteHandler.hxx +++ b/src/common/PaletteHandler.hxx @@ -146,19 +146,19 @@ class PaletteHandler Convert RGB adjustables from/to 100% scale */ static constexpr float scaleRGBFrom100(float x) { return x / 50.F; } - static constexpr uInt32 scaleRGBTo100(float x) { return uInt32(50.0001F * (x - 0.F)); } + static constexpr uInt32 scaleRGBTo100(float x) { return static_cast(50.0001F * (x - 0.F)); } /** Convert angles */ static constexpr float scaleFromAngles(float x) { return x / 10.F; } - static constexpr Int32 scaleToAngles(float x) { return uInt32(10.F * x); } + static constexpr Int32 scaleToAngles(float x) { return static_cast(10.F * x); } /** Convert adjustables from/to 100% scale */ static constexpr float scaleFrom100(float x) { return (x / 50.F) - 1.F; } - static constexpr uInt32 scaleTo100(float x) { return uInt32(50.0001F * (x + 1.F)); } + static constexpr uInt32 scaleTo100(float x) { return static_cast(50.0001F * (x + 1.F)); } /** Check for 'Custom' palette only adjustables diff --git a/src/common/PhosphorHandler.cxx b/src/common/PhosphorHandler.cxx index 70d3be82d..93dd19e47 100644 --- a/src/common/PhosphorHandler.cxx +++ b/src/common/PhosphorHandler.cxx @@ -28,7 +28,7 @@ bool PhosphorHandler::initialize(bool enable, int blend) myPhosphorPercent = blend / 100.F; // Used to calculate an averaged color for the 'phosphor' effect - auto getPhosphor = [&] (const uInt8 c1, uInt8 c2) -> uInt8 { + const auto getPhosphor = [&] (const uInt8 c1, uInt8 c2) -> uInt8 { // Use maximum of current and decayed previous values c2 = static_cast(c2 * myPhosphorPercent); if(c1 > c2) return c1; // raise (assumed immediate) @@ -40,7 +40,7 @@ bool PhosphorHandler::initialize(bool enable, int blend) { for(int c = 255; c >= 0; --c) for(int p = 255; p >= 0; --p) - ourPhosphorLUT[c][p] = getPhosphor(uInt8(c), uInt8(p)); + ourPhosphorLUT[c][p] = getPhosphor(static_cast(c), static_cast(p)); } return true; } diff --git a/src/common/PhysicalJoystick.cxx b/src/common/PhysicalJoystick.cxx index 6b48de214..db35c5257 100644 --- a/src/common/PhysicalJoystick.cxx +++ b/src/common/PhysicalJoystick.cxx @@ -84,7 +84,7 @@ bool PhysicalJoystick::setMap(const json& map) { int i = 0; - for (auto& entry: map.items()) { + for (const auto& entry: map.items()) { if (entry.key() == "name") continue; try { @@ -130,9 +130,9 @@ json PhysicalJoystick::convertLegacyMapping(const string& mapping, const string& // Remove leading "|" string map.erase(0, 2); - json mappingForMode = JoyMap::convertLegacyMapping(map); + const json mappingForMode = JoyMap::convertLegacyMapping(map); - convertedMapping[jsonName(EventMode(mode))] = mappingForMode; + convertedMapping[jsonName(static_cast(mode))] = mappingForMode; } convertedMapping["name"] = name; diff --git a/src/common/RewindManager.cxx b/src/common/RewindManager.cxx index cfda75065..e6a739799 100644 --- a/src/common/RewindManager.cxx +++ b/src/common/RewindManager.cxx @@ -63,7 +63,7 @@ void RewindManager::setup() // calc interval growth factor for compression // this factor defines the backward horizon - const double MAX_FACTOR = 1E8; + constexpr double MAX_FACTOR = 1E8; double minFactor = 0, maxFactor = MAX_FACTOR; myFactor = 1; @@ -82,7 +82,7 @@ void RewindManager::setup() interval *= myFactor; cycleSum += interval; } - double diff = cycleSum - myHorizon; + const double diff = cycleSum - myHorizon; // exit loop if result is close enough if(std::abs(diff) < myHorizon * 1E-5) @@ -102,7 +102,7 @@ bool RewindManager::addState(const string& message, bool timeMachine) if(timeMachine && myStateList.currentIsValid()) { // check if the current state has the right interval from the last state - RewindState& lastState = myStateList.current(); + const RewindState& lastState = myStateList.current(); uInt32 interval = myInterval; // adjust frame timed intervals to actual scanlines (vs 262) @@ -145,7 +145,7 @@ bool RewindManager::addState(const string& message, bool timeMachine) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 RewindManager::rewindStates(uInt32 numStates) { - uInt64 startCycles = myOSystem.console().tia().cycles(); + const uInt64 startCycles = myOSystem.console().tia().cycles(); uInt32 i; string message; @@ -185,7 +185,7 @@ uInt32 RewindManager::rewindStates(uInt32 numStates) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 RewindManager::unwindStates(uInt32 numStates) { - uInt64 startCycles = myOSystem.console().tia().cycles(); + const uInt64 startCycles = myOSystem.console().tia().cycles(); uInt32 i; string message; @@ -243,9 +243,9 @@ string RewindManager::saveAllStates() if (!out) return "Can't save to all states file"; - uInt32 curIdx = getCurrentIdx(); + const uInt32 curIdx = getCurrentIdx(); rewindStates(MAX_BUF_SIZE); - uInt32 numStates = uInt32(cyclesList().size()); + uInt32 numStates = static_cast(cyclesList().size()); // Save header buf.str(""); @@ -256,8 +256,7 @@ string RewindManager::saveAllStates() { RewindState& state = myStateList.current(); Serializer& s = state.data; - uInt32 stateSize = uInt32(s.size()); - unique_ptr buffer = make_unique(stateSize); + const uInt32 stateSize = static_cast(s.size()); out.putInt(stateSize); @@ -265,8 +264,9 @@ string RewindManager::saveAllStates() s.rewind(); // Save state - s.getByteArray(buffer.get(), stateSize); - out.putByteArray(buffer.get(), stateSize); + ByteArray buffer(stateSize); + s.getByteArray(buffer.data(), stateSize); + out.putByteArray(buffer.data(), stateSize); out.putString(state.message); out.putLong(state.cycles); @@ -301,7 +301,7 @@ string RewindManager::loadAllStates() return "Can't load from all states file"; clear(); - uInt32 numStates; + uInt32 numStates = 0; // Load header buf.str(""); @@ -315,8 +315,7 @@ string RewindManager::loadAllStates() if (myStateList.full()) compressStates(); - uInt32 stateSize = in.getInt(); - unique_ptr buffer = make_unique(stateSize); + const uInt32 stateSize = in.getInt(); // Add new state at the end of the list (queue adds at end) // This updates the 'current' iterator inside the list @@ -328,8 +327,9 @@ string RewindManager::loadAllStates() s.rewind(); // Fill new state with saved values - in.getByteArray(buffer.get(), stateSize); - s.putByteArray(buffer.get(), stateSize); + ByteArray buffer(stateSize); + in.getByteArray(buffer.data(), stateSize); + s.putByteArray(buffer.data(), stateSize); state.message = in.getString(); state.cycles = in.getLong(); } @@ -366,9 +366,9 @@ void RewindManager::compressStates() { expectedCycles *= myFactor; - uInt64 prevCycles = myStateList.previous(it)->cycles; - uInt64 nextCycles = myStateList.next(it)->cycles; - double error = expectedCycles / (nextCycles - prevCycles); + const uInt64 prevCycles = myStateList.previous(it)->cycles; + const uInt64 nextCycles = myStateList.next(it)->cycles; + const double error = expectedCycles / (nextCycles - prevCycles); if(error > maxError) { @@ -390,7 +390,7 @@ string RewindManager::loadState(Int64 startCycles, uInt32 numStates) myStateManager.loadState(s); myOSystem.console().tia().loadDisplay(s); - Int64 diff = startCycles - state.cycles; + const Int64 diff = startCycles - state.cycles; stringstream message; message << (diff >= 0 ? "Rewind" : "Unwind") << " " << getUnitString(diff); @@ -418,11 +418,11 @@ string RewindManager::getUnitString(Int64 cycles) "cycle", "scanline", "frame", "second", "minute" }; const std::array UNIT_CYCLES = { - 1, 76, 76 * scanlines, freq, freq * 60, Int64(1) << 62 + 1, 76, 76 * scanlines, freq, freq * 60, Int64{1} << 62 }; stringstream result; - Int32 i; + Int32 i = 0; cycles = std::abs(cycles); @@ -433,7 +433,7 @@ string RewindManager::getUnitString(Int64 cycles) if(cycles == 0 || (cycles < UNIT_CYCLES[i + 1] * 2 && cycles % UNIT_CYCLES[i + 1] != 0)) break; } - result << cycles / UNIT_CYCLES[i] << " " << UNIT_NAMES[i]; + result << (cycles / UNIT_CYCLES[i]) << " " << UNIT_NAMES[i]; if(cycles / UNIT_CYCLES[i] != 1) result << "s"; @@ -466,7 +466,7 @@ IntArray RewindManager::cyclesList() const { IntArray arr; - uInt64 firstCycle = getFirstCycles(); + const uInt64 firstCycle = getFirstCycles(); for(auto it = myStateList.cbegin(); it != myStateList.cend(); ++it) arr.push_back(uInt32(it->cycles - firstCycle)); diff --git a/src/common/RewindManager.hxx b/src/common/RewindManager.hxx index c0ccb4a6e..200b9b818 100644 --- a/src/common/RewindManager.hxx +++ b/src/common/RewindManager.hxx @@ -81,8 +81,8 @@ class RewindManager 76 * 262 * 60 * 60, 76 * 262 * 60 * 60 * 3, 76 * 262 * 60 * 60 * 10, - uInt64(76) * 262 * 60 * 60 * 30, - uInt64(76) * 262 * 60 * 60 * 60 + uInt64{76} *262 * 60 * 60 * 30, + uInt64{76} *262 * 60 * 60 * 60 }; // settings values for the horzions const std::array HOR_SETTINGS = { @@ -185,8 +185,11 @@ class RewindManager // We do nothing on object instantiation or copy // The goal of LinkedObjectPool is to not do any allocations at all RewindState() = default; + ~RewindState() = default; RewindState(const RewindState& rs) : cycles(rs.cycles) { } RewindState& operator= (const RewindState& rs) { cycles = rs.cycles; return *this; } + RewindState(RewindState&&) = default; + RewindState& operator=(RewindState&&) = default; // Output object info; used for debugging only friend ostream& operator<<(ostream& os, const RewindState& s) { diff --git a/src/common/SoundSDL2.cxx b/src/common/SoundSDL2.cxx index 5f1a32595..4213b121a 100644 --- a/src/common/SoundSDL2.cxx +++ b/src/common/SoundSDL2.cxx @@ -83,7 +83,7 @@ void SoundSDL2::queryHardware(VariantList& devices) { ASSERT_MAIN_THREAD; - int numDevices = SDL_GetNumAudioDevices(0); + const int numDevices = SDL_GetNumAudioDevices(0); // log the available audio devices ostringstream s; @@ -112,12 +112,12 @@ bool SoundSDL2::openDevice() desired.channels = 2; desired.samples = static_cast(myAudioSettings.fragmentSize()); desired.callback = callback; - desired.userdata = static_cast(this); + desired.userdata = this; if(myIsInitializedFlag) SDL_CloseAudioDevice(myDevice); - myDeviceId = BSPF::clamp(myAudioSettings.device(), 0U, uInt32(myDevices.size() - 1)); + myDeviceId = BSPF::clamp(myAudioSettings.device(), 0U, static_cast(myDevices.size() - 1)); const char* device = myDeviceId ? myDevices.at(myDeviceId).first.c_str() : nullptr; myDevice = SDL_OpenAudioDevice(device, 0, &desired, &myHardwareSpec, @@ -154,8 +154,8 @@ void SoundSDL2::open(shared_ptr audioQueue, // Do we need to re-open the sound device? // Only do this when absolutely necessary - if(myAudioSettings.sampleRate() != uInt32(myHardwareSpec.freq) || - myAudioSettings.fragmentSize() != uInt32(myHardwareSpec.samples) || + if(myAudioSettings.sampleRate() != static_cast(myHardwareSpec.freq) || + myAudioSettings.fragmentSize() != static_cast(myHardwareSpec.samples) || myAudioSettings.device() != myDeviceId) openDevice(); @@ -206,7 +206,7 @@ void SoundSDL2::close() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool SoundSDL2::mute(bool state) { - bool oldstate = SDL_GetAudioDeviceStatus(myDevice) == SDL_AUDIO_PAUSED; + const bool oldstate = SDL_GetAudioDeviceStatus(myDevice) == SDL_AUDIO_PAUSED; if(myIsInitializedFlag) SDL_PauseAudioDevice(myDevice, state ? 1 : 0); @@ -216,7 +216,7 @@ bool SoundSDL2::mute(bool state) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool SoundSDL2::toggleMute() { - bool enabled = !myAudioSettings.enabled(); + const bool enabled = !myAudioSettings.enabled(); setEnabled(enabled); myOSystem.console().initializeAudio(); @@ -269,7 +269,7 @@ void SoundSDL2::adjustVolume(int direction) setVolume(percent); // Enable audio if it is currently disabled - bool enabled = myAudioSettings.enabled(); + const bool enabled = myAudioSettings.enabled(); if(percent > 0 && !enabled) { @@ -292,7 +292,7 @@ string SoundSDL2::about() const buf << "Sound enabled:" << endl << " Volume: " << myVolume << "%" << endl << " Device: " << myDevices.at(myDeviceId).first << endl - << " Channels: " << uInt32(myHardwareSpec.channels) + << " Channels: " << static_cast(myHardwareSpec.channels) << (myAudioQueue->isStereo() ? " (Stereo)" : " (Mono)") << endl << " Preset: "; switch (myAudioSettings.preset()) { @@ -312,8 +312,8 @@ string SoundSDL2::about() const buf << "Ultra quality, minimal lag" << endl; break; } - buf << " Fragment size: " << uInt32(myHardwareSpec.samples) << " bytes" << endl - << " Sample rate: " << uInt32(myHardwareSpec.freq) << " Hz" << endl; + buf << " Fragment size: " << static_cast(myHardwareSpec.samples) << " bytes" << endl + << " Sample rate: " << static_cast(myHardwareSpec.freq) << " Hz" << endl; buf << " Resampling: "; switch(myAudioSettings.resamplingQuality()) { diff --git a/src/common/StaggeredLogger.cxx b/src/common/StaggeredLogger.cxx index 2fc57e76f..c7fb63c0b 100644 --- a/src/common/StaggeredLogger.cxx +++ b/src/common/StaggeredLogger.cxx @@ -73,8 +73,8 @@ void StaggeredLogger::_log() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void StaggeredLogger::logLine() { - high_resolution_clock::time_point now = high_resolution_clock::now(); - Int64 millisecondsSinceIntervalStart = + const high_resolution_clock::time_point now = high_resolution_clock::now(); + const Int64 millisecondsSinceIntervalStart = duration_cast>(now - myLastIntervalStartTimestamp).count(); stringstream ss; @@ -113,7 +113,7 @@ void StaggeredLogger::startInterval() myIsCurrentlyCollecting = true; - high_resolution_clock::time_point now = high_resolution_clock::now(); + const high_resolution_clock::time_point now = high_resolution_clock::now(); Int64 msecSinceLastIntervalEnd = duration_cast>(now - myLastIntervalEndTimestamp).count(); diff --git a/src/common/StateManager.cxx b/src/common/StateManager.cxx index 73a31216e..03cf74514 100644 --- a/src/common/StateManager.cxx +++ b/src/common/StateManager.cxx @@ -128,7 +128,7 @@ void StateManager::toggleRecordMode() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void StateManager::toggleTimeMachine() { - bool devSettings = myOSystem.settings().getBool("dev.settings"); + const bool devSettings = myOSystem.settings().getBool("dev.settings"); myActiveMode = myActiveMode == Mode::TimeMachine ? Mode::Off : Mode::TimeMachine; if(myActiveMode == Mode::TimeMachine) diff --git a/src/common/StringParser.hxx b/src/common/StringParser.hxx index ca9bab3c2..b39daed9d 100644 --- a/src/common/StringParser.hxx +++ b/src/common/StringParser.hxx @@ -57,7 +57,8 @@ class StringParser while(std::getline(buf, line, '\n')) { - size_t len = maxlen, size = line.size(); + size_t len = maxlen; + const size_t size = line.size(); if(size <= len) myStringList.push_back(line); @@ -66,7 +67,7 @@ class StringParser size_t beg = 0; while((beg + maxlen) < size) { - size_t spos = line.find_last_of(' ', beg + len); + const size_t spos = line.find_last_of(' ', beg + len); if(spos != string::npos && spos > beg) len = spos - beg; diff --git a/src/common/TimerManager.cxx b/src/common/TimerManager.cxx index 0db3434eb..9836ff38e 100644 --- a/src/common/TimerManager.cxx +++ b/src/common/TimerManager.cxx @@ -62,15 +62,15 @@ TimerManager::TimerId TimerManager::addTimer( // Assign an ID and insert it into function storage auto id = nextId++; - auto iter = active.emplace(id, Timer(id, Clock::now() + Duration(msDelay), + const auto iter = active.emplace(id, Timer(id, Clock::now() + Duration(msDelay), Duration(msPeriod), func)); // Insert a reference to the Timer into ordering queue - Queue::iterator place = queue.emplace(iter.first->second); + const Queue::iterator place = queue.emplace(iter.first->second); // We need to notify the timer thread only if we inserted // this timer into the front of the timer queue - bool needNotify = (place == queue.begin()); + const bool needNotify = (place == queue.begin()); lock.unlock(); @@ -84,7 +84,7 @@ TimerManager::TimerId TimerManager::addTimer( bool TimerManager::clear(TimerId id) { ScopedLock lock(sync); - auto i = active.find(id); + const auto i = active.find(id); return destroy_impl(lock, i, true); } @@ -131,9 +131,9 @@ void TimerManager::timerThreadWorker() continue; } - auto queueHead = queue.begin(); + const auto queueHead = queue.begin(); Timer& timer = *queueHead; - auto now = Clock::now(); + const auto now = Clock::now(); if (now >= timer.next) { queue.erase(queueHead); @@ -181,8 +181,7 @@ void TimerManager::timerThreadWorker() else { // Wait until the timer is ready or a timer creation notifies - Timestamp next = timer.next; - wakeUp.wait_until(lock, next); + wakeUp.wait_until(lock, timer.next); } } } @@ -232,20 +231,20 @@ bool TimerManager::destroy_impl(ScopedLock& lock, TimerMap::iterator i, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TimerManager::Timer::Timer(Timer&& r) noexcept - : id(r.id), - next(r.next), - period(r.period), - handler(std::move(r.handler)), - running(r.running) + : id{r.id}, + next{r.next}, + period{r.period}, + handler{std::move(r.handler)}, + running{r.running} { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TimerManager::Timer::Timer(TimerId tid, Timestamp tnext, Duration tperiod, const TFunction& func) noexcept - : id(tid), - next(tnext), - period(tperiod), - handler(func) + : id{tid }, + next{tnext}, + period{tperiod}, + handler{func} { } diff --git a/src/common/TimerManager.hxx b/src/common/TimerManager.hxx index 6303f9571..d2ecd4dcc 100644 --- a/src/common/TimerManager.hxx +++ b/src/common/TimerManager.hxx @@ -158,7 +158,7 @@ class TimerManager TimerId id{0}; Timestamp next; - Duration period; + Duration period{0}; TFunction handler; // You must be holding the 'sync' lock to assign waitCond diff --git a/src/common/VideoModeHandler.cxx b/src/common/VideoModeHandler.cxx index b6006d9b3..9a72346ad 100644 --- a/src/common/VideoModeHandler.cxx +++ b/src/common/VideoModeHandler.cxx @@ -56,8 +56,8 @@ VideoModeHandler::buildMode(const Settings& settings, bool inTIAMode) const float overscan = 1 - settings.getInt("tia.fs_overscan") / 100.0; // First calculate maximum zoom that keeps aspect ratio - const float scaleX = float(myImage.w) / myDisplay.w, - scaleY = float(myImage.h) / myDisplay.h; + const float scaleX = static_cast(myImage.w) / myDisplay.w, + scaleY = static_cast(myImage.h) / myDisplay.h; float zoom = 1.F / std::max(scaleX, scaleY); // When aspect ratio correction is off, we want pixel-exact images, diff --git a/src/common/audio/ConvolutionBuffer.cxx b/src/common/audio/ConvolutionBuffer.cxx index 094674934..1627ab4a7 100644 --- a/src/common/audio/ConvolutionBuffer.cxx +++ b/src/common/audio/ConvolutionBuffer.cxx @@ -33,7 +33,7 @@ void ConvolutionBuffer::shift(float nextValue) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -float ConvolutionBuffer::convoluteWith(float* kernel) const +float ConvolutionBuffer::convoluteWith(const float* const kernel) const { float result = 0.F; diff --git a/src/common/audio/ConvolutionBuffer.hxx b/src/common/audio/ConvolutionBuffer.hxx index cadc275fe..6ead3f9c6 100644 --- a/src/common/audio/ConvolutionBuffer.hxx +++ b/src/common/audio/ConvolutionBuffer.hxx @@ -28,7 +28,7 @@ class ConvolutionBuffer void shift(float nextValue); - float convoluteWith(float* kernel) const; + float convoluteWith(const float* const kernel) const; private: diff --git a/src/common/audio/HighPass.cxx b/src/common/audio/HighPass.cxx index c25751da8..3eedf9323 100644 --- a/src/common/audio/HighPass.cxx +++ b/src/common/audio/HighPass.cxx @@ -27,7 +27,7 @@ HighPass::HighPass(float cutOffFrequency, float frequency) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - float HighPass::apply(float valueIn) { - float valueOut = myAlpha * (myLastValueOut + valueIn - myLastValueIn); + const float valueOut = myAlpha * (myLastValueOut + valueIn - myLastValueIn); myLastValueIn = valueIn; myLastValueOut = valueOut; diff --git a/src/common/audio/LanczosResampler.cxx b/src/common/audio/LanczosResampler.cxx index 5a010d13b..02c73a62f 100644 --- a/src/common/audio/LanczosResampler.cxx +++ b/src/common/audio/LanczosResampler.cxx @@ -24,7 +24,7 @@ namespace { constexpr float CLIPPING_FACTOR = 0.75; constexpr float HIGH_PASS_CUT_OFF = 10; - uInt32 reducedDenominator(uInt32 n, uInt32 d) + constexpr uInt32 reducedDenominator(uInt32 n, uInt32 d) { for (uInt32 i = std::min(n ,d); i > 1; --i) { if ((n % i == 0) && (d % i == 0)) { @@ -98,7 +98,7 @@ void LanczosResampler::precomputeKernels() for (uInt32 i = 0; i < myPrecomputedKernelCount; ++i) { float* kernel = myPrecomputedKernels.get() + myKernelSize * i; // The kernel is normalized such to be evaluate on time * formatFrom.sampleRate - float center = + const float center = static_cast(timeIndex) / static_cast(myFormatTo.sampleRate); for (uInt32 j = 0; j < 2 * myKernelParameter; ++j) { @@ -143,12 +143,12 @@ void LanczosResampler::fillFragment(float* fragment, uInt32 length) const uInt32 outputSamples = myFormatTo.stereo ? (length >> 1) : length; for (uInt32 i = 0; i < outputSamples; ++i) { - float* kernel = myPrecomputedKernels.get() + (myCurrentKernelIndex * myKernelSize); + const float* kernel = myPrecomputedKernels.get() + (myCurrentKernelIndex * myKernelSize); myCurrentKernelIndex = (myCurrentKernelIndex + 1) % myPrecomputedKernelCount; if (myFormatFrom.stereo) { - float sampleL = myBufferL->convoluteWith(kernel); - float sampleR = myBufferR->convoluteWith(kernel); + const float sampleL = myBufferL->convoluteWith(kernel); + const float sampleR = myBufferR->convoluteWith(kernel); if (myFormatTo.stereo) { fragment[2*i] = sampleL; @@ -157,7 +157,7 @@ void LanczosResampler::fillFragment(float* fragment, uInt32 length) else fragment[i] = (sampleL + sampleR) / 2.F; } else { - float sample = myBuffer->convoluteWith(kernel); + const float sample = myBuffer->convoluteWith(kernel); if (myFormatTo.stereo) fragment[2*i] = fragment[2*i + 1] = sample; @@ -167,7 +167,7 @@ void LanczosResampler::fillFragment(float* fragment, uInt32 length) myTimeIndex += myFormatFrom.sampleRate; - uInt32 samplesToShift = myTimeIndex / myFormatTo.sampleRate; + const uInt32 samplesToShift = myTimeIndex / myFormatTo.sampleRate; if (samplesToShift == 0) continue; myTimeIndex %= myFormatTo.sampleRate; diff --git a/src/common/audio/SimpleResampler.cxx b/src/common/audio/SimpleResampler.cxx index 379eb1e43..476e71589 100644 --- a/src/common/audio/SimpleResampler.cxx +++ b/src/common/audio/SimpleResampler.cxx @@ -49,8 +49,8 @@ void SimpleResampler::fillFragment(float* fragment, uInt32 length) // For the following math, remember that myTimeIndex = time * myFormatFrom.sampleRate * myFormatTo.sampleRate for (uInt32 i = 0; i < outputSamples; ++i) { if (myFormatFrom.stereo) { - float sampleL = static_cast(myCurrentFragment[2*myFragmentIndex]) / static_cast(0x7fff); - float sampleR = static_cast(myCurrentFragment[2*myFragmentIndex + 1]) / static_cast(0x7fff); + const float sampleL = static_cast(myCurrentFragment[2*myFragmentIndex]) / static_cast(0x7fff); + const float sampleR = static_cast(myCurrentFragment[2*myFragmentIndex + 1]) / static_cast(0x7fff); if (myFormatTo.stereo) { fragment[2*i] = sampleL; @@ -59,7 +59,7 @@ void SimpleResampler::fillFragment(float* fragment, uInt32 length) else fragment[i] = (sampleL + sampleR) / 2.F; } else { - float sample = static_cast(myCurrentFragment[myFragmentIndex] / static_cast(0x7fff)); + const float sample = static_cast(myCurrentFragment[myFragmentIndex] / static_cast(0x7fff)); if (myFormatTo.stereo) fragment[2*i] = fragment[2*i + 1] = sample; diff --git a/src/common/main.cxx b/src/common/main.cxx index cb9ceab28..9e7cb4da1 100644 --- a/src/common/main.cxx +++ b/src/common/main.cxx @@ -180,7 +180,7 @@ int main(int ac, char* av[]) unique_ptr theOSystem; - auto Cleanup = [&theOSystem]() { + const auto Cleanup = [&theOSystem]() { if(theOSystem) { Logger::debug("Cleanup from main"); diff --git a/src/common/repository/KeyValueRepositoryNoop.hxx b/src/common/repository/KeyValueRepositoryNoop.hxx index 3a2e83eb7..1ec8f3001 100644 --- a/src/common/repository/KeyValueRepositoryNoop.hxx +++ b/src/common/repository/KeyValueRepositoryNoop.hxx @@ -24,7 +24,7 @@ class KeyValueRepositoryNoop : public KeyValueRepositoryAtomic { public: - virtual std::map load() override { + std::map load() override { return std::map(); } diff --git a/src/common/sdl_blitter/BilinearBlitter.cxx b/src/common/sdl_blitter/BilinearBlitter.cxx index 098fe9845..4434e8b81 100644 --- a/src/common/sdl_blitter/BilinearBlitter.cxx +++ b/src/common/sdl_blitter/BilinearBlitter.cxx @@ -110,7 +110,7 @@ void BilinearBlitter::recreateTexturesIfNecessary() free(); } - SDL_TextureAccess texAccess = myStaticData == nullptr ? SDL_TEXTUREACCESS_STREAMING : SDL_TEXTUREACCESS_STATIC; + const SDL_TextureAccess texAccess = myStaticData == nullptr ? SDL_TEXTUREACCESS_STREAMING : SDL_TEXTUREACCESS_STATIC; SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, myInterpolate ? "1" : "0"); @@ -126,7 +126,7 @@ void BilinearBlitter::recreateTexturesIfNecessary() } if (myAttributes.blending) { - uInt8 blendAlpha = uInt8(myAttributes.blendalpha * 2.55); + const uInt8 blendAlpha = static_cast(myAttributes.blendalpha * 2.55); std::array textures = { myTexture, mySecondaryTexture }; for (SDL_Texture* texture: textures) { diff --git a/src/common/sdl_blitter/BilinearBlitter.hxx b/src/common/sdl_blitter/BilinearBlitter.hxx index 52d8af3ba..8c8c80380 100644 --- a/src/common/sdl_blitter/BilinearBlitter.hxx +++ b/src/common/sdl_blitter/BilinearBlitter.hxx @@ -31,14 +31,14 @@ class BilinearBlitter : public Blitter { ~BilinearBlitter() override; - virtual void reinitialize( + void reinitialize( SDL_Rect srcRect, SDL_Rect destRect, FBSurface::Attributes attributes, SDL_Surface* staticData = nullptr ) override; - virtual void blit(SDL_Surface& surface) override; + void blit(SDL_Surface& surface) override; private: FBBackendSDL2& myFB; diff --git a/src/common/sdl_blitter/QisBlitter.cxx b/src/common/sdl_blitter/QisBlitter.cxx index 1ffaac923..7a1dbd635 100644 --- a/src/common/sdl_blitter/QisBlitter.cxx +++ b/src/common/sdl_blitter/QisBlitter.cxx @@ -145,7 +145,8 @@ void QisBlitter::recreateTexturesIfNecessary() free(); } - SDL_TextureAccess texAccess = myStaticData == nullptr ? SDL_TEXTUREACCESS_STREAMING : SDL_TEXTUREACCESS_STATIC; + const SDL_TextureAccess texAccess = + myStaticData == nullptr ? SDL_TEXTUREACCESS_STREAMING : SDL_TEXTUREACCESS_STATIC; myIntermediateRect.w = (myDstRect.w / mySrcRect.w) * mySrcRect.w; myIntermediateRect.h = (myDstRect.h / mySrcRect.h) * mySrcRect.h; @@ -180,7 +181,7 @@ void QisBlitter::recreateTexturesIfNecessary() } if (myAttributes.blending) { - uInt8 blendAlpha = uInt8(myAttributes.blendalpha * 2.55); + const uInt8 blendAlpha = static_cast(myAttributes.blendalpha * 2.55); std::array textures = { mySrcTexture, myIntermediateTexture, mySecondaryIntermedateTexture diff --git a/src/common/sdl_blitter/QisBlitter.hxx b/src/common/sdl_blitter/QisBlitter.hxx index 8d59f2c52..92e31f139 100644 --- a/src/common/sdl_blitter/QisBlitter.hxx +++ b/src/common/sdl_blitter/QisBlitter.hxx @@ -33,14 +33,14 @@ class QisBlitter : public Blitter { ~QisBlitter() override; - virtual void reinitialize( + void reinitialize( SDL_Rect srcRect, SDL_Rect destRect, FBSurface::Attributes attributes, SDL_Surface* staticData = nullptr ) override; - virtual void blit(SDL_Surface& surface) override; + void blit(SDL_Surface& surface) override; private: diff --git a/src/common/smartmod.hxx b/src/common/smartmod.hxx index 46d4de632..6a89ef3b4 100644 --- a/src/common/smartmod.hxx +++ b/src/common/smartmod.hxx @@ -22,63 +22,63 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -uInt8 smartmod(uInt8 x) +constexpr uInt8 smartmod(uInt8 x) { return x % base; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<2>(uInt8 x) +inline constexpr uInt8 smartmod<2>(uInt8 x) { return x & 0x01; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<4>(uInt8 x) +inline constexpr uInt8 smartmod<4>(uInt8 x) { return x & 0x03; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<8>(uInt8 x) +inline constexpr uInt8 smartmod<8>(uInt8 x) { return x & 0x07; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<16>(uInt8 x) +inline constexpr uInt8 smartmod<16>(uInt8 x) { return x & 0x0F; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<32>(uInt8 x) +inline constexpr uInt8 smartmod<32>(uInt8 x) { return x & 0x1F; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<64>(uInt8 x) +inline constexpr uInt8 smartmod<64>(uInt8 x) { return x & 0x3F; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<128>(uInt8 x) +inline constexpr uInt8 smartmod<128>(uInt8 x) { return x & 0x7F; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template<> -inline uInt8 smartmod<256>(uInt8 x) +inline constexpr uInt8 smartmod<256>(uInt8 x) { return x & 0xFF; } diff --git a/src/common/tv_filters/AtariNTSC.cxx b/src/common/tv_filters/AtariNTSC.cxx index 03d4f34a1..aab7c3adc 100644 --- a/src/common/tv_filters/AtariNTSC.cxx +++ b/src/common/tv_filters/AtariNTSC.cxx @@ -57,21 +57,21 @@ void AtariNTSC::generateKernels() const uInt8* ptr = myRGBPalette.data(); for(size_t entry = 0; entry < myRGBPalette.size() / 3; ++entry) { - float r = (*ptr++) / 255.F * rgb_unit + rgb_offset, - g = (*ptr++) / 255.F * rgb_unit + rgb_offset, - b = (*ptr++) / 255.F * rgb_unit + rgb_offset; + const float r = (*ptr++) / 255.F * rgb_unit + rgb_offset, + g = (*ptr++) / 255.F * rgb_unit + rgb_offset, + b = (*ptr++) / 255.F * rgb_unit + rgb_offset; float y, i, q; RGB_TO_YIQ( r, g, b, y, i, q ); // Generate kernel int ir, ig, ib; YIQ_TO_RGB( y, i, q, myImpl.to_rgb.data(), ir, ig, ib ); - uInt32 rgb = PACK_RGB( ir, ig, ib ); + const uInt32 rgb = PACK_RGB( ir, ig, ib ); uInt32* kernel = myColorTable[entry].data(); genKernel(myImpl, y, i, q, kernel); for ( uInt32 c = 0; c < rgb_kernel_size / 2; ++c ) { - uInt32 error = rgb - + const uInt32 error = rgb - kernel [c ] - kernel [(c+10)%14+14] - kernel [c + 7] - kernel [c + 3 +14]; kernel [c + 3 + 14] += error; @@ -208,7 +208,7 @@ void AtariNTSC::renderWithPhosphorThread(const uInt8* atari_in, const uInt32 in_ const uInt32 yStart = in_height * threadNum / numThreads; const uInt32 yEnd = in_height * (threadNum + 1) / numThreads; uInt32 bufofs = AtariNTSC::outWidth(in_width) * yStart; - uInt32* out = static_cast(rgb_out); + const uInt32* out = static_cast(rgb_out); atari_in += in_width * yStart; rgb_out = static_cast(rgb_out) + out_pitch * yStart; @@ -361,7 +361,7 @@ void AtariNTSC::init(init_t& impl, const Setup& setup) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AtariNTSC::initFilters(init_t& impl, const Setup& setup) { - std::array kernels; + std::array kernels{0}; /* generate luma (y) filter using sinc kernel */ { @@ -369,7 +369,7 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) float const rolloff = 1 + setup.sharpness * 0.032F; constexpr float maxh = 32; float const pow_a_n = powf( rolloff, maxh ); - float sum; + /* quadratic mapping to reduce negative (blurring) range */ float to_angle = setup.resolution + 1; to_angle = BSPF::PI_f / maxh * luma_cutoff * (to_angle * to_angle + 1.F); @@ -377,26 +377,26 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) kernels [kernel_size * 3 / 2] = maxh; /* default center value */ for ( int i = 0; i < kernel_half * 2 + 1; i++ ) { - int x = i - kernel_half; - float angle = x * to_angle; + const int x = i - kernel_half; + const float angle = x * to_angle; /* instability occurs at center point with rolloff very close to 1.0 */ if ( x || pow_a_n > 1.056F || pow_a_n < 0.981F ) { - float rolloff_cos_a = rolloff * cosf( angle ); - float num = 1 - rolloff_cos_a - + const float rolloff_cos_a = rolloff * cosf( angle ); + const float num = 1 - rolloff_cos_a - pow_a_n * cosf( maxh * angle ) + pow_a_n * rolloff * cosf( (maxh - 1) * angle ); - float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff; + const float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff; float dsf = num / den; kernels [kernel_size * 3 / 2 - kernel_half + i] = dsf - 0.5F; } } /* apply blackman window and find sum */ - sum = 0; + float sum = 0; for ( int i = 0; i < kernel_half * 2 + 1; i++ ) { - float x = BSPF::PI_f * 2 / (kernel_half * 2) * i; + const float x = BSPF::PI_f * 2 / (kernel_half * 2) * i; float blackman = 0.42F - 0.5F * cosf( x ) + 0.08F * cosf( x * 2 ); sum += (kernels [kernel_size * 3 / 2 - kernel_half + i] *= blackman); } @@ -405,7 +405,7 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) sum = 1.0F / sum; for ( int i = 0; i < kernel_half * 2 + 1; i++ ) { - int x = kernel_size * 3 / 2 - kernel_half + i; + const int x = kernel_size * 3 / 2 - kernel_half + i; kernels [x] *= sum; } } @@ -454,7 +454,7 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) weight -= 1.0F / rescale_in; for ( int i = 0; i < kernel_size * 2; i++ ) { - float cur = kernels [i]; + const float cur = kernels [i]; float m = cur * weight; *out++ = m + remain; remain = cur - m; @@ -498,13 +498,12 @@ void AtariNTSC::genKernel(init_t& impl, float y, float i, float q, uInt32* out) float const yc3 = (y - qq) * pixel->kernel [3]; float const* k = &impl.kernel [pixel->offset]; - int n; ++pixel; - for ( n = rgb_kernel_size; n; --n ) + for ( int n = rgb_kernel_size; n; --n ) { - float fi = k[0]*ic0 + k[2]*ic2; - float fq = k[1]*qc1 + k[3]*qc3; - float fy = k[kernel_size+0]*yc0 + k[kernel_size+1]*yc1 + + const float fi = k[0]*ic0 + k[2]*ic2; + const float fq = k[1]*qc1 + k[3]*qc3; + const float fy = k[kernel_size+0]*yc0 + k[kernel_size+1]*yc1 + k[kernel_size+2]*yc2 + k[kernel_size+3]*yc3 + rgb_offset; if ( k < &impl.kernel [kernel_size * 2 * (rescale_out - 1)] ) k += kernel_size * 2 - 1; diff --git a/src/common/tv_filters/AtariNTSC.hxx b/src/common/tv_filters/AtariNTSC.hxx index 2d188d39e..b617c64b4 100644 --- a/src/common/tv_filters/AtariNTSC.hxx +++ b/src/common/tv_filters/AtariNTSC.hxx @@ -185,7 +185,7 @@ class AtariNTSC // Begins outputting row and starts two pixels. First pixel will be cut // off a bit. Use atari_ntsc_black for unused pixels. #define ATARI_NTSC_BEGIN_ROW( pixel0, pixel1 ) \ - unsigned const atari_ntsc_pixel0_ = (pixel0);\ + constexpr unsigned atari_ntsc_pixel0_ = (pixel0);\ uInt32 const* kernel0 = myColorTable[atari_ntsc_pixel0_].data();\ unsigned const atari_ntsc_pixel1_ = (pixel1);\ uInt32 const* kernel1 = myColorTable[atari_ntsc_pixel1_].data();\ @@ -211,7 +211,7 @@ class AtariNTSC // Common ntsc macros static constexpr void ATARI_NTSC_CLAMP( uInt32& io, uInt32 shift ) { - uInt32 sub = io >> (9-(shift)) & atari_ntsc_clamp_mask; + const uInt32 sub = io >> (9-(shift)) & atari_ntsc_clamp_mask; uInt32 clamp = atari_ntsc_clamp_add - sub; io |= clamp; clamp -= sub; diff --git a/src/common/tv_filters/NTSCFilter.cxx b/src/common/tv_filters/NTSCFilter.cxx index ac6d3a91a..d6daf8a0d 100644 --- a/src/common/tv_filters/NTSCFilter.cxx +++ b/src/common/tv_filters/NTSCFilter.cxx @@ -21,7 +21,7 @@ #include "NTSCFilter.hxx" constexpr float scaleFrom100(float x) { return (x / 50.F) - 1.F; } -constexpr uInt32 scaleTo100(float x) { return uInt32(50.0001F * (x + 1.F)); } +constexpr uInt32 scaleTo100(float x) { return static_cast(50.0001F * (x + 1.F)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string NTSCFilter::setPreset(Preset preset) diff --git a/src/debugger/BreakpointMap.cxx b/src/debugger/BreakpointMap.cxx index ee12d6c24..ad59d314b 100644 --- a/src/debugger/BreakpointMap.cxx +++ b/src/debugger/BreakpointMap.cxx @@ -21,7 +21,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void BreakpointMap::add(const Breakpoint& breakpoint, const uInt32 flags) { - Breakpoint bp = convertBreakpoint(breakpoint); + const Breakpoint bp = convertBreakpoint(breakpoint); myInitialized = true; myMap[bp] = flags; @@ -40,7 +40,7 @@ void BreakpointMap::erase(const Breakpoint& breakpoint) if(!myMap.erase(breakpoint)) { // 13 bit breakpoint - Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); + const Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); myMap.erase(bp13); } @@ -61,7 +61,7 @@ uInt32 BreakpointMap::get(const Breakpoint& breakpoint) const return find->second; // 13 bit breakpoint - Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); + const Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); find = myMap.find(bp13); if(find != myMap.end()) @@ -85,7 +85,7 @@ bool BreakpointMap::check(const Breakpoint& breakpoint) const return true; // 13 bit breakpoint - Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); + const Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); find = myMap.find(bp13); return (find != myMap.end()); @@ -103,7 +103,7 @@ BreakpointMap::BreakpointList BreakpointMap::getBreakpoints() const BreakpointList map; std::map ordered(myMap.begin(), myMap.end()); - for(auto item : ordered) + for(const auto& item : ordered) map.push_back(item.first); return map; diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 6fe5a22de..0db637fba 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -190,7 +190,7 @@ int CartDebug::lastWriteBaseAddress() string CartDebug::toString() { ostringstream buf; - uInt32 bytesPerLine; + uInt32 bytesPerLine = 0; switch(Base::format()) { @@ -245,7 +245,7 @@ string CartDebug::toString() bool CartDebug::disassembleAddr(uInt16 address, bool force) { // ROM/RAM bank or ZP-RAM? - int bank = (address & 0x1000) ? getBank(address) : int(myBankInfo.size()) - 1; + const int bank = (address & 0x1000) ? getBank(address) : int(myBankInfo.size()) - 1; return disassemble(bank, address, force); } @@ -271,15 +271,15 @@ bool CartDebug::disassemble(int bank, uInt16 PC, bool force) { // Test current disassembly; don't re-disassemble if it hasn't changed // Also check if the current PC is in the current list - bool bankChanged = myConsole.cartridge().bankChanged(); - int pcline = addressToLine(PC); - bool pcfound = (pcline != -1) && (uInt32(pcline) < myDisassembly.list.size()) && - (myDisassembly.list[pcline].disasm[0] != '.'); - bool pagedirty = (PC & 0x1000) ? mySystem.isPageDirty(0x1000, 0x1FFF) : - mySystem.isPageDirty(0x80, 0xFF); + const bool bankChanged = myConsole.cartridge().bankChanged(); + const int pcline = addressToLine(PC); + const bool pcfound = (pcline != -1) && (static_cast(pcline) < myDisassembly.list.size()) && + (myDisassembly.list[pcline].disasm[0] != '.'); + const bool pagedirty = (PC & 0x1000) ? mySystem.isPageDirty(0x1000, 0x1FFF) : + mySystem.isPageDirty(0x80, 0xFF); - bool changed = !mySystem.autodetectMode() && - (force || bankChanged || !pcfound || pagedirty); + const bool changed = !mySystem.autodetectMode() && + (force || bankChanged || !pcfound || pagedirty); if(changed) { // Are we disassembling from ROM or ZP RAM? @@ -316,7 +316,7 @@ bool CartDebug::disassemble(int bank, uInt16 PC, bool force) // Always attempt to resolve code sections unless it's been // specifically disabled - bool found = fillDisassemblyList(info, PC); + const bool found = fillDisassemblyList(info, PC); if(!found && DiStella::settings.resolveCode) { // Temporarily turn off code resolution @@ -385,8 +385,8 @@ string CartDebug::disassembleLines(uInt16 start, uInt16 lines) const ostringstream buffer; // First find the lines in the range, and determine the longest string - uInt32 list_size = uInt32(myDisassembly.list.size()); - uInt32 begin = list_size, end = 0, length = 0; + const size_t list_size = myDisassembly.list.size(); + size_t begin = list_size, end = 0, length = 0; for(end = 0; end < list_size && lines > 0; ++end) { const CartDebug::DisassemblyTag& tag = myDisassembly.list[end]; @@ -394,14 +394,14 @@ string CartDebug::disassembleLines(uInt16 start, uInt16 lines) const { if(begin == list_size) begin = end; if(tag.type != Device::ROW) - length = std::max(length, uInt32(tag.disasm.length())); + length = std::max(length, tag.disasm.length()); --lines; } } // Now output the disassembly, using as little space as possible - for(uInt32 i = begin; i < end; ++i) + for(size_t i = begin; i < end; ++i) { const CartDebug::DisassemblyTag& tag = myDisassembly.list[i]; if(tag.type == Device::NONE) @@ -412,7 +412,7 @@ string CartDebug::disassembleLines(uInt16 start, uInt16 lines) const else buffer << " "; - buffer << tag.disasm << std::setw(int(length - tag.disasm.length() + 2)) + buffer << tag.disasm << std::setw(static_cast(length - tag.disasm.length() + 2)) << std::setfill(' ') << " " << std::setw(4) << std::left << tag.ccount << " " << tag.bytes << endl; } @@ -618,7 +618,7 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, { if(isRead) { - uInt16 a = addr & 0x0F, offset = addr & 0xFFF0; + const uInt16 a = addr & 0x0F, offset = addr & 0xFFF0; if(ourTIAMnemonicR[a]) { buf << ourTIAMnemonicR[a]; @@ -630,7 +630,7 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, } else { - uInt16 a = addr & 0x3F, offset = addr & 0xFFC0; + const uInt16 a = addr & 0x3F, offset = addr & 0xFFC0; if(ourTIAMnemonicW[a]) { buf << ourTIAMnemonicW[a]; @@ -645,7 +645,7 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, case AddrType::IO: { - uInt16 a = addr & 0xFF, offset = addr & 0xFD00; + const uInt16 a = addr & 0xFF, offset = addr & 0xFD00; if(a <= 0x9F) { if(ourIOMnemonic[a - 0x80]) @@ -668,7 +668,7 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, // RAM can use user-defined labels; otherwise we default to // standard mnemonics AddrToLabel::const_iterator iter; - uInt16 a = addr & 0xFF, offset = addr & 0xFF00; + const uInt16 a = addr & 0xFF, offset = addr & 0xFF00; bool found = false; // Search for nearest label @@ -798,7 +798,7 @@ string CartDebug::loadListFile() if(addr_s.length() == 0) continue; const char* p = addr_s[0] == 'U' ? addr_s.c_str() + 1 : addr_s.c_str(); - addr = int(strtoul(p, nullptr, 16)); + addr = static_cast(strtoul(p, nullptr, 16)); // For now, completely ignore ROM addresses if(!(addr & 0x1000)) @@ -1063,8 +1063,8 @@ string CartDebug::saveDisassembly(string path) "BLACK", "BLUE", "RED", "PURPLE", "GREEN", "CYAN", "YELLOW", "WHITE" }; - bool isNTSC = myConsole.timing() == ConsoleTiming::ntsc; - bool isPAL = myConsole.timing() == ConsoleTiming::pal; + const bool isNTSC = myConsole.timing() == ConsoleTiming::ntsc; + const bool isPAL = myConsole.timing() == ConsoleTiming::pal; #define ALIGN(x) setfill(' ') << left << setw(x) @@ -1086,8 +1086,8 @@ string CartDebug::saveDisassembly(string path) Disassembly disasm; disasm.list.reserve(2048); - uInt16 romBankCount = myConsole.cartridge().romBankCount(); - uInt16 oldBank = myConsole.cartridge().getBank(); + const uInt16 romBankCount = myConsole.cartridge().romBankCount(); + const uInt16 oldBank = myConsole.cartridge().getBank(); // prepare for switching banks myConsole.cartridge().unlockHotspots(); @@ -1129,7 +1129,7 @@ string CartDebug::saveDisassembly(string path) else buf << " ORG $" << Base::HEX4 << origin << "\n" << " RORG $" << Base::HEX4 << info.offset << "\n\n"; - origin += uInt32(info.size); + origin += static_cast(info.size); // Format in 'distella' style for(uInt32 i = 0; i < disasm.list.size(); ++i) @@ -1298,9 +1298,9 @@ string CartDebug::saveDisassembly(string path) << ";-----------------------------------------------------------\n\n"; for (uInt16 addr = 0x80; addr <= 0xFF; ++addr) { - bool ramUsed = (mySystem.getAccessFlags(addr) & (Device::DATA | Device::WRITE)); - bool codeUsed = (mySystem.getAccessFlags(addr) & Device::CODE); - bool stackUsed = (mySystem.getAccessFlags(addr|0x100) & (Device::DATA | Device::WRITE)); + const bool ramUsed = (mySystem.getAccessFlags(addr) & (Device::DATA | Device::WRITE)); + const bool codeUsed = (mySystem.getAccessFlags(addr) & Device::CODE); + const bool stackUsed = (mySystem.getAccessFlags(addr|0x100) & (Device::DATA | Device::WRITE)); if (myReserved.ZPRAM[addr - 0x80] && myUserLabels.find(addr) == myUserLabels.end()) { @@ -1534,6 +1534,8 @@ CartDebug::AddrType CartDebug::addressType(uInt16 addr) const case 0x200: case 0x300: case 0x600: case 0x700: case 0xa00: case 0xb00: case 0xe00: case 0xf00: return AddrType::IO; + default: + break; } } } @@ -1551,7 +1553,7 @@ void CartDebug::getBankDirectives(ostream& buf, const BankInfo& info) const Device::AccessType prevType = accessTypeAbsolute(mySystem.getAccessFlags(prev)); for( ; addr < info.offset + info.size; ++addr) { - Device::AccessType currType = accessTypeAbsolute(mySystem.getAccessFlags(addr)); + const Device::AccessType currType = accessTypeAbsolute(mySystem.getAccessFlags(addr)); // Have we changed to a new type? if(currType != prevType) @@ -1581,9 +1583,9 @@ void CartDebug::accessTypeAsString(ostream& buf, uInt16 addr) const return; } - uInt8 directive = myDisDirectives[addr & 0xFFF] & 0xFC, - debugger = myDebugger.getAccessFlags(addr) & 0xFC, - label = myDisLabels[addr & 0xFFF]; + const uInt8 directive = myDisDirectives[addr & 0xFFF] & 0xFC, + debugger = myDebugger.getAccessFlags(addr) & 0xFC, + label = myDisLabels[addr & 0xFFF]; buf << endl << "directive: " << Base::toString(directive, Base::Fmt::_2_8) << " "; AccessTypeAsString(buf, directive); diff --git a/src/debugger/CartDebug.hxx b/src/debugger/CartDebug.hxx index 068e8d706..1346cfb83 100644 --- a/src/debugger/CartDebug.hxx +++ b/src/debugger/CartDebug.hxx @@ -301,7 +301,7 @@ class CartDebug : public DebuggerSystem std::array TIAWrite; std::array IOReadWrite; std::array ZPRAM; - AddrToLabel Label; + AddrToLabel Label{}; bool breakFound{false}; }; ReservedEquates myReserved; diff --git a/src/debugger/CpuDebug.cxx b/src/debugger/CpuDebug.cxx index cc6c3bc38..f2641b4a7 100644 --- a/src/debugger/CpuDebug.cxx +++ b/src/debugger/CpuDebug.cxx @@ -152,13 +152,13 @@ int CpuDebug::icycles() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CpuDebug::setPC(int pc) { - my6502.PC = uInt16(pc); + my6502.PC = static_cast(pc); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CpuDebug::setSP(int sp) { - my6502.SP = uInt8(sp); + my6502.SP = static_cast(sp); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -170,19 +170,19 @@ void CpuDebug::setPS(int ps) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CpuDebug::setA(int a) { - my6502.A = uInt8(a); + my6502.A = static_cast(a); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CpuDebug::setX(int x) { - my6502.X = uInt8(x); + my6502.X = static_cast(x); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CpuDebug::setY(int y) { - my6502.Y = uInt8(y); + my6502.Y = static_cast(y); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index af4c088c5..7561200cf 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -96,8 +96,8 @@ void Debugger::initialize() // The debugger dialog is resizable, within certain bounds // We check those bounds now - mySize.clamp(uInt32(DebuggerDialog::kSmallFontMinW), d.w, - uInt32(DebuggerDialog::kSmallFontMinH), d.h); + mySize.clamp(static_cast(DebuggerDialog::kSmallFontMinW), d.w, + static_cast(DebuggerDialog::kSmallFontMinH), d.h); myOSystem.settings().setValue("dbg.res", mySize); @@ -190,7 +190,7 @@ string Debugger::autoExec(StringList* history) for(const auto& func: ourBuiltinFunctions) { // TODO - check this for memory leaks - int res = YaccParser::parse(func.defn); + const int res = YaccParser::parse(func.defn); if(res == 0) addFunction(func.name, func.defn, YaccParser::getResult(), true); else @@ -228,7 +228,7 @@ const string Debugger::invIfChanged(int reg, int oldReg) { string ret; - bool changed = reg != oldReg; + const bool changed = reg != oldReg; if(changed) ret += "\177"; ret += Common::Base::toString(reg, Common::Base::Fmt::_16_2); if(changed) ret += "\177"; @@ -252,9 +252,9 @@ string Debugger::setRAM(IntArray& args) { ostringstream buf; - int count = int(args.size()); + const size_t count = args.size(); int address = args[0]; - for(int i = 1; i < count; ++i) + for(size_t i = 1; i < count; ++i) mySystem.poke(address++, args[i]); buf << "changed " << (count-1) << " location"; @@ -309,7 +309,7 @@ int Debugger::step(bool save) if(save) saveOldState(); - uInt64 startCycle = mySystem.cycles(); + const uInt64 startCycle = mySystem.cycles(); unlockSystem(); myOSystem.console().tia().updateScanlineByStep().flushLineCache(); @@ -317,7 +317,7 @@ int Debugger::step(bool save) if(save) addState("step"); - return int(mySystem.cycles() - startCycle); + return static_cast(mySystem.cycles() - startCycle); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -337,11 +337,11 @@ int Debugger::trace() { saveOldState(); - uInt64 startCycle = mySystem.cycles(); - int targetPC = myCpuDebug->pc() + 3; // return address + const uInt64 startCycle = mySystem.cycles(); + const int targetPC = myCpuDebug->pc() + 3; // return address // set temporary breakpoint at target PC (if not existing already) - Int8 bank = myCartDebug->getBank(targetPC); + const Int8 bank = myCartDebug->getBank(targetPC); if(!checkBreakPoint(targetPC, bank)) { // add temporary breakpoint and remove later @@ -354,7 +354,7 @@ int Debugger::trace() lockSystem(); addState("trace"); - return int(mySystem.cycles() - startCycle); + return static_cast(mySystem.cycles() - startCycle); } else return step(); @@ -363,9 +363,7 @@ int Debugger::trace() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Debugger::setBreakPoint(uInt16 addr, uInt8 bank, uInt32 flags) { - bool exists = checkBreakPoint(addr, bank); - - if(exists) + if(checkBreakPoint(addr, bank)) return false; breakPoints().add(addr, bank, flags); @@ -375,9 +373,7 @@ bool Debugger::setBreakPoint(uInt16 addr, uInt8 bank, uInt32 flags) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Debugger::clearBreakPoint(uInt16 addr, uInt8 bank) { - bool exists = checkBreakPoint(addr, bank); - - if(!exists) + if(!checkBreakPoint(addr, bank)) return false; breakPoints().erase(addr, bank); @@ -457,7 +453,7 @@ bool Debugger::writeTrap(uInt16 t) void Debugger::log(const string& triggerMsg) { const CartDebug::Disassembly& disasm = myCartDebug->disassembly(); - int pc = myCpuDebug->pc(); + const int pc = myCpuDebug->pc(); if(myFirstLog) { @@ -477,9 +473,9 @@ void Debugger::log(const string& triggerMsg) } // First find the lines in the range, and determine the longest string - uInt16 start = pc & 0xFFF; - uInt32 list_size = uInt32(disasm.list.size()); - uInt32 pos; + const uInt16 start = pc & 0xFFF; + const size_t list_size = disasm.list.size(); + size_t pos = 0; for(pos = 0; pos < list_size; ++pos) { @@ -538,7 +534,8 @@ uInt8 Debugger::peek(uInt16 addr, Device::AccessFlags flags) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt16 Debugger::dpeek(uInt16 addr, Device::AccessFlags flags) { - return uInt16(mySystem.peek(addr, flags) | (mySystem.peek(addr+1, flags) << 8)); + return static_cast(mySystem.peek(addr, flags) | + (mySystem.peek(addr+1, flags) << 8)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -556,14 +553,14 @@ M6502& Debugger::m6502() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int Debugger::peekAsInt(int addr, Device::AccessFlags flags) { - return mySystem.peek(uInt16(addr), flags); + return mySystem.peek(static_cast(addr), flags); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int Debugger::dpeekAsInt(int addr, Device::AccessFlags flags) { - return mySystem.peek(uInt16(addr), flags) | - (mySystem.peek(uInt16(addr+1), flags) << 8); + return mySystem.peek(static_cast(addr), flags) | + (mySystem.peek(static_cast(addr+1), flags) << 8); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -680,8 +677,8 @@ uInt16 Debugger::windStates(uInt16 numStates, bool unwind, string& message) unlockSystem(); - uInt64 startCycles = myOSystem.console().tia().cycles(); - uInt16 winds = r.windStates(numStates, unwind); + const uInt64 startCycles = myOSystem.console().tia().cycles(); + const uInt16 winds = r.windStates(numStates, unwind); message = r.getUnitString(myOSystem.console().tia().cycles() - startCycles); lockSystem(); @@ -852,23 +849,23 @@ const Debugger::FunctionDefMap Debugger::getFunctionDefMap() const string Debugger::builtinHelp() const { ostringstream buf; - uInt32 len, c_maxlen = 0, i_maxlen = 0; + size_t len = 0, c_maxlen = 0, i_maxlen = 0; // Get column widths for aligned output (functions) for(const auto& func: ourBuiltinFunctions) { - len = uInt32(func.name.size()); + len = func.name.size(); if(len > c_maxlen) c_maxlen = len; - len = uInt32(func.defn.size()); + len = func.defn.size(); if(len > i_maxlen) i_maxlen = len; } buf << std::setfill(' ') << endl << "Built-in functions:" << endl; for(const auto& func: ourBuiltinFunctions) { - buf << std::setw(c_maxlen) << std::left << func.name + buf << std::setw(static_cast(c_maxlen)) << std::left << func.name << std::setw(2) << std::right << "{" - << std::setw(i_maxlen) << std::left << func.defn + << std::setw(static_cast(i_maxlen)) << std::left << func.defn << std::setw(4) << "}" << func.help << endl; @@ -878,16 +875,16 @@ string Debugger::builtinHelp() const c_maxlen = 0; for(const auto& reg: ourPseudoRegisters) { - len = uInt32(reg.name.size()); + len = reg.name.size(); if(len > c_maxlen) c_maxlen = len; } buf << endl << "Pseudo-registers:" << endl; for(const auto& reg: ourPseudoRegisters) { - buf << std::setw(c_maxlen) << std::left << reg.name + buf << std::setw(static_cast(c_maxlen)) << std::left << reg.name << std::setw(2) << " " - << std::setw(i_maxlen) << std::left << reg.help + << std::setw(static_cast(i_maxlen)) << std::left << reg.help << endl; } diff --git a/src/debugger/Debugger.hxx b/src/debugger/Debugger.hxx index 44171d173..a2301986e 100644 --- a/src/debugger/Debugger.hxx +++ b/src/debugger/Debugger.hxx @@ -210,9 +210,9 @@ class Debugger : public DialogContainer static uInt8 set_bit(uInt8 input, uInt8 bit, bool on) { if(on) - return uInt8(input | (1 << bit)); + return static_cast(input | (1 << bit)); else - return uInt8(input & ~(1 << bit)); + return static_cast(input & ~(1 << bit)); } static void set_bits(uInt8 reg, BoolArray& bits) { diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index 111dba762..6dfa63dfa 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -109,7 +109,7 @@ string DebuggerParser::run(const string& command) getArgs(command, verb); commandResult.str(""); - for(int i = 0; i < int(commands.size()); ++i) + for(int i = 0; i < static_cast(commands.size()); ++i) { if(BSPF::equalsIgnoreCase(verb, commands[i].cmdString)) { @@ -193,10 +193,9 @@ void DebuggerParser::getCompletions(const char* in, StringList& completions) con int DebuggerParser::decipher_arg(const string& str) { bool derefByte=false, derefWord=false, lobyte=false, hibyte=false, bin=false, dec=false; - int result; string arg = str; - Base::Fmt defaultBase = Base::format(); + const Base::Fmt defaultBase = Base::format(); if(defaultBase == Base::Fmt::_2) { bin=true; dec=false; @@ -238,6 +237,7 @@ int DebuggerParser::decipher_arg(const string& str) // Special cases (registers): const CpuState& state = static_cast(debugger.cpuDebug().getState()); + int result = 0; if(arg == "a" && str != "$a") result = state.A; else if(arg == "x") result = state.X; else if(arg == "y") result = state.Y; @@ -268,7 +268,7 @@ int DebuggerParser::decipher_arg(const string& str) } else if(dec) { result = 0; while(*a != '\0') { - int digit = (*a++) - '0'; + const int digit = (*a++) - '0'; if(digit < 0 || digit > 9) return -1; @@ -278,7 +278,7 @@ int DebuggerParser::decipher_arg(const string& str) result = 0; while(*a != '\0') { int hex = -1; - char d = *a++; + const char d = *a++; if(d >= '0' && d <= '9') hex = d - '0'; else if(d >= 'a' && d <= 'f') hex = d - 'a' + 10; else if(d >= 'A' && d <= 'F') hex = d - 'A' + 10; @@ -333,7 +333,8 @@ string DebuggerParser::showWatches() bool DebuggerParser::getArgs(const string& command, string& verb) { ParseState state = ParseState::IN_COMMAND; - uInt32 i = 0, length = uInt32(command.length()); + size_t i = 0; + const size_t length = command.length(); string curArg = ""; verb = ""; @@ -346,7 +347,7 @@ bool DebuggerParser::getArgs(const string& command, string& verb) // The first token is the command verb, the rest go in an array do { - char c = command[i++]; + const char c = command[i++]; switch(state) { case ParseState::IN_COMMAND: @@ -390,7 +391,7 @@ bool DebuggerParser::getArgs(const string& command, string& verb) if(curArg != "") argStrings.push_back(curArg); - argCount = uInt32(argStrings.size()); + argCount = static_cast(argStrings.size()); for(uInt32 arg = 0; arg < argCount; ++arg) { @@ -410,7 +411,7 @@ bool DebuggerParser::getArgs(const string& command, string& verb) bool DebuggerParser::validateArgs(int cmd) { // cerr << "entering validateArgs(" << cmd << ")" << endl; - bool required = commands[cmd].parmsRequired; + const bool required = commands[cmd].parmsRequired; Parameters* p = commands[cmd].parms.data(); if(argCount == 0) @@ -444,8 +445,8 @@ bool DebuggerParser::validateArgs(int cmd) if(curCount >= argCount) break; - uInt32 curArgInt = args[curCount]; - string& curArgStr = argStrings[curCount]; + const uInt32 curArgInt = args[curCount]; + const string& curArgStr = argStrings[curCount]; switch(*p) { @@ -540,8 +541,8 @@ string DebuggerParser::eval() { string rlabel = debugger.cartDebug().getLabel(args[i], true); string wlabel = debugger.cartDebug().getLabel(args[i], false); - bool validR = rlabel != "" && rlabel[0] != '$', - validW = wlabel != "" && wlabel[0] != '$'; + const bool validR = rlabel != "" && rlabel[0] != '$', + validW = wlabel != "" && wlabel[0] != '$'; if(validR && validW) { if(rlabel == wlabel) @@ -582,7 +583,7 @@ void DebuggerParser::listTraps(bool listCond) commandResult << (listCond ? "trapifs:" : "traps:") << endl; for(uInt32 i = 0; i < names.size(); ++i) { - bool hasCond = names[i] != ""; + const bool hasCond = names[i] != ""; if(hasCond == listCond) { commandResult << Base::toString(i) << ": "; @@ -662,9 +663,9 @@ string DebuggerParser::saveScriptFile(string file) StringList names = debugger.m6502().getCondTrapNames(); for(uInt32 i = 0; i < myTraps.size(); ++i) { - bool read = myTraps[i]->read; - bool write = myTraps[i]->write; - bool hasCond = names[i] != ""; + const bool read = myTraps[i]->read, + write = myTraps[i]->write, + hasCond = names[i] != ""; if(read && write) out << "trap"; @@ -736,7 +737,7 @@ void DebuggerParser::executeDirective(Device::AccessType type) return; } - bool result = debugger.cartDebug().addDirective(type, args[0], args[1]); + const bool result = debugger.cartDebug().addDirective(type, args[0], args[1]); commandResult << (result ? "added " : "removed "); debugger.cartDebug().AccessTypeAsString(commandResult, type); @@ -815,14 +816,9 @@ void DebuggerParser::executeBCol() // "break" void DebuggerParser::executeBreak() { - uInt16 addr; - uInt8 bank; - uInt32 romBankCount = debugger.cartDebug().romBankCount(); - - if(argCount == 0) - addr = debugger.cpuDebug().pc(); - else - addr = args[0]; + const uInt32 romBankCount = debugger.cartDebug().romBankCount(); + const uInt16 addr = (argCount == 0) ? debugger.cpuDebug().pc() : args[0]; + uInt8 bank = 0; if(argCount < 2) bank = debugger.cartDebug().getBank(addr); @@ -837,7 +833,7 @@ void DebuggerParser::executeBreak() } if(bank != 0xff) { - bool set = debugger.toggleBreakPoint(addr, bank); + const bool set = debugger.toggleBreakPoint(addr, bank); if(set) commandResult << "set"; @@ -846,13 +842,13 @@ void DebuggerParser::executeBreak() commandResult << " breakpoint at $" << Base::HEX4 << addr << " + mirrors"; if(romBankCount > 1) - commandResult << " in bank #" << std::dec << int(bank); + commandResult << " in bank #" << std::dec << static_cast(bank); } else { for(int i = 0; i < debugger.cartDebug().romBankCount(); ++i) { - bool set = debugger.toggleBreakPoint(addr, i); + const bool set = debugger.toggleBreakPoint(addr, i); if(i) commandResult << endl; @@ -864,7 +860,7 @@ void DebuggerParser::executeBreak() commandResult << " breakpoint at $" << Base::HEX4 << addr << " + mirrors"; if(romBankCount > 1) - commandResult << " in bank #" << std::dec << int(bank); + commandResult << " in bank #" << std::dec << static_cast(bank); } } } @@ -886,8 +882,8 @@ void DebuggerParser::executeBreakIf() return; } } - uInt32 ret = debugger.m6502().addCondBreak( - YaccParser::getResult(), argStrings[0]); + const uInt32 ret = debugger.m6502().addCondBreak( + YaccParser::getResult(), argStrings[0]); commandResult << "added breakIf " << Base::toString(ret); } else @@ -898,14 +894,8 @@ void DebuggerParser::executeBreakIf() // "breakLabel" void DebuggerParser::executeBreakLabel() { - uInt16 addr; - - if(argCount == 0) - addr = debugger.cpuDebug().pc(); - else - addr = args[0]; - - bool set = debugger.toggleBreakPoint(addr, BreakpointMap::ANY_BANK); + const uInt16 addr = (argCount == 0) ? debugger.cpuDebug().pc() : args[0]; + const bool set = debugger.toggleBreakPoint(addr, BreakpointMap::ANY_BANK); commandResult << (set ? "set" : "cleared"); commandResult << " breakpoint at $" << Base::HEX4 << addr << " (no mirrors)"; @@ -1026,7 +1016,7 @@ void DebuggerParser::executeCol() void DebuggerParser::executeColorTest() { commandResult << "test color: " - << char((args[0]>>1) | 0x80) + << static_cast((args[0]>>1) | 0x80) << inverse(" "); } @@ -1097,7 +1087,7 @@ void DebuggerParser::executeDelSaveStateIf() // "delTrap" void DebuggerParser::executeDelTrap() { - int index = args[0]; + const int index = args[0]; if(debugger.m6502().delCondTrap(index)) { @@ -1115,8 +1105,8 @@ void DebuggerParser::executeDelTrap() // "delWatch" void DebuggerParser::executeDelWatch() { - int which = args[0] - 1; - if(which >= 0 && which < int(myWatches.size())) + const int which = args[0] - 1; + if(which >= 0 && which < static_cast(myWatches.size())) { Vec::removeAt(myWatches, which); commandResult << "removed watch"; @@ -1129,7 +1119,7 @@ void DebuggerParser::executeDelWatch() // "disAsm" void DebuggerParser::executeDisAsm() { - int start, lines = 20; + int start = 0, lines = 20; if(argCount == 0) { start = debugger.cpuDebug().pc(); @@ -1150,7 +1140,7 @@ void DebuggerParser::executeDisAsm() // "dump" void DebuggerParser::executeDump() { - auto dump = [&](ostream& os, int start, int end) + const auto dump = [&](ostream& os, int start, int end) { for(int i = start; i <= end; i += 16) { @@ -1201,7 +1191,7 @@ void DebuggerParser::executeDump() path << execPrefix; else path << std::hex << std::setw(8) << std::setfill('0') - << uInt32(TimerManager::getTicks() / 1000); + << static_cast(TimerManager::getTicks() / 1000); path << ".dump"; commandResult << "dumped "; @@ -1218,7 +1208,7 @@ void DebuggerParser::executeDump() if((args[2] & 0x02) != 0) { // dump CPU state - CpuDebug& cpu = debugger.cpuDebug(); + const CpuDebug& cpu = debugger.cpuDebug(); out << " PC SP A X Y - - N V B D I Z C -\n"; out << "XC: " << Base::toString(cpu.pc() & 0xff) << " " // PC lsb @@ -1318,7 +1308,7 @@ void DebuggerParser::executeExec() else { ostringstream prefix; prefix << std::hex << std::setw(8) << std::setfill('0') - << uInt32(TimerManager::getTicks()/1000); + << static_cast(TimerManager::getTicks()/1000); execPrefix = prefix.str(); } @@ -1329,7 +1319,7 @@ void DebuggerParser::executeExec() commandResult << exec(node, &history); --execDepth; - for(const auto& item : history) + for(const auto& item: history) debugger.prompt().addToHistory(item.c_str()); } @@ -1384,16 +1374,16 @@ void DebuggerParser::executeHelp() if(argCount == 0) // normal help, show all commands { // Find length of longest command - uInt32 clen = 0; + size_t clen = 0; for(const auto& c: commands) { - uInt32 len = uInt32(c.cmdString.length()); + const size_t len = c.cmdString.length(); if(len > clen) clen = len; } commandResult << setfill(' '); for(const auto& c: commands) - commandResult << setw(clen) << right << c.cmdString + commandResult << setw(static_cast(clen)) << right << c.cmdString << " - " << c.description << endl; commandResult << debugger.builtinHelp(); @@ -1549,9 +1539,9 @@ void DebuggerParser::executeListBreaks() { stringstream buf; int count = 0; - uInt32 romBankCount = debugger.cartDebug().romBankCount(); + const uInt32 romBankCount = debugger.cartDebug().romBankCount(); - for(const auto& bp : debugger.breakPoints().getBreakpoints()) + for(const auto& bp: debugger.breakPoints().getBreakpoints()) { if(romBankCount == 1) { @@ -1564,7 +1554,7 @@ void DebuggerParser::executeListBreaks() buf << ", "; buf << debugger.cartDebug().getLabel(bp.addr, true, 4); if(bp.bank != 255) - buf << " #" << int(bp.bank); + buf << " #" << static_cast(bp.bank); else buf << " *"; if(!(++count % 6)) buf << endl; @@ -1692,7 +1682,7 @@ void DebuggerParser::executeLoadState() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DebuggerParser::executeLogBreaks() { - bool enable = !debugger.mySystem.m6502().getLogBreaks(); + const bool enable = !debugger.mySystem.m6502().getLogBreaks(); debugger.mySystem.m6502().setLogBreaks(enable); settings.setValue("dbg.logbreaks", enable); @@ -1832,7 +1822,8 @@ void DebuggerParser::executeRunTo() debugger.saveOldState(); - uInt32 count = 0, max_iterations = uInt32(list.size()); + size_t count = 0; + const size_t max_iterations = list.size(); // Create a progress dialog box to show the progress searching through the // disassembly, since this may be a time-consuming operation @@ -1842,7 +1833,7 @@ void DebuggerParser::executeRunTo() buf << "runTo searching through " << max_iterations << " disassembled instructions" << progress.ELLIPSIS; progress.setMessage(buf.str()); - progress.setRange(0, max_iterations, 5); + progress.setRange(0, static_cast(max_iterations), 5); progress.open(); bool done = false; @@ -1850,7 +1841,7 @@ void DebuggerParser::executeRunTo() debugger.step(false); // Update romlist to point to current PC - int pcline = cartdbg.addressToLine(debugger.cpuDebug().pc()); + const int pcline = cartdbg.addressToLine(debugger.cpuDebug().pc()); if(pcline >= 0) { const string& next = list[pcline].disasm; @@ -1897,7 +1888,7 @@ void DebuggerParser::executeRunToPc() debugger.step(false); // Update romlist to point to current PC - int pcline = cartdbg.addressToLine(debugger.cpuDebug().pc()); + const int pcline = cartdbg.addressToLine(debugger.cpuDebug().pc()); done = (pcline >= 0) && (list[pcline].address == args[0]); progress.incProgress(); ++count; @@ -2107,7 +2098,7 @@ void DebuggerParser::executeSaveStateIf() return; } } - uInt32 ret = debugger.m6502().addCondSaveState( + const uInt32 ret = debugger.m6502().addCondSaveState( YaccParser::getResult(), argStrings[0]); commandResult << "added saveStateIf " << Base::toString(ret); } @@ -2142,7 +2133,7 @@ void DebuggerParser::executeStepWhile() commandResult << red("invalid expression"); return; } - Expression* expr = YaccParser::getResult(); + const Expression* expr = YaccParser::getResult(); int ncycles = 0; uInt32 count = 0; @@ -2229,7 +2220,7 @@ void DebuggerParser::executeTrapWriteIf() void DebuggerParser::executeTraps(bool read, bool write, const string& command, bool hasCond) { - uInt32 ofs = hasCond ? 1 : 0; + const uInt32 ofs = hasCond ? 1 : 0; uInt32 begin = args[ofs]; uInt32 end = argCount == 2 + ofs ? args[1 + ofs] : begin; @@ -2255,10 +2246,10 @@ void DebuggerParser::executeTraps(bool read, bool write, const string& command, } // base addresses of mirrors - uInt32 beginRead = debugger.getBaseAddress(begin, true); - uInt32 endRead = debugger.getBaseAddress(end, true); - uInt32 beginWrite = debugger.getBaseAddress(begin, false); - uInt32 endWrite = debugger.getBaseAddress(end, false); + const uInt32 beginRead = debugger.getBaseAddress(begin, true); + const uInt32 endRead = debugger.getBaseAddress(end, true); + const uInt32 beginWrite = debugger.getBaseAddress(begin, false); + const uInt32 endWrite = debugger.getBaseAddress(end, false); stringstream conditionBuf; // parenthesize provided and address range condition(s) (begin) @@ -2418,7 +2409,7 @@ void DebuggerParser::executeType() // "uHex" void DebuggerParser::executeUHex() { - bool enable = !Base::hexUppercase(); + const bool enable = !Base::hexUppercase(); Base::setHexUppercase(enable); settings.setValue("dbg.uHex", enable); @@ -2469,16 +2460,12 @@ void DebuggerParser::executeWatch() // wrapper function for rewind/unwind commands void DebuggerParser::executeWinds(bool unwind) { - uInt16 states; + const uInt16 states = (argCount == 0) ? 1 : args[0]; string type = unwind ? "unwind" : "rewind"; string message; - if(argCount == 0) - states = 1; - else - states = args[0]; - - uInt16 winds = unwind ? debugger.unwindStates(states, message) : debugger.rewindStates(states, message); + const uInt16 winds = unwind ? debugger.unwindStates(states, message) + : debugger.rewindStates(states, message); if(winds > 0) { debugger.rom().invalidate(); diff --git a/src/debugger/DiStella.cxx b/src/debugger/DiStella.cxx index c37b006b5..d751b6284 100644 --- a/src/debugger/DiStella.cxx +++ b/src/debugger/DiStella.cxx @@ -35,8 +35,8 @@ DiStella::DiStella(const CartDebug& dbg, CartDebug::DisassemblyList& list, myDirectives{directives} { bool resolve_code = mySettings.resolveCode; - CartDebug::AddressList& debuggerAddresses = info.addressList; - uInt16 start = *debuggerAddresses.cbegin(); + const CartDebug::AddressList& debuggerAddresses = info.addressList; + const uInt16 start = *debuggerAddresses.cbegin(); myOffset = info.offset; if (start & 0x1000) { @@ -104,10 +104,10 @@ void DiStella::disasm(uInt32 distart, int pass) #define LABEL_A12_HIGH(address) labelA12High(nextLine, opcode, address, labelFound) #define LABEL_A12_LOW(address) labelA12Low(nextLine, opcode, address, labelFound) - uInt8 opcode, d1; - uInt16 ad; + uInt8 opcode = 0, d1 = 0; + uInt16 ad = 0; Int32 cycles = 0; - AddressingMode addrMode; + AddressingMode addrMode{}; AddressType labelFound = AddressType::INVALID; stringstream nextLine, nextLineBytes; @@ -209,7 +209,7 @@ void DiStella::disasm(uInt32 distart, int pass) // detect labels inside instructions (e.g. BIT masks) labelFound = AddressType::INVALID; - for(Uint8 i = 0; i < ourLookup[opcode].bytes - 1; i++) { + for(uInt8 i = 0; i < ourLookup[opcode].bytes - 1; i++) { if(checkBit(myPC + i, Device::REFERENCED)) { labelFound = AddressType::ROM; break; @@ -220,15 +220,16 @@ void DiStella::disasm(uInt32 distart, int pass) // the opcode's operand address matches a label address if(pass == 3) { // output the byte of the opcode incl. cycles - Uint8 nextOpcode = Debugger::debugger().peek(myPC + myOffset); + const uInt8 nextOpcode = Debugger::debugger().peek(myPC + myOffset); - cycles += int(ourLookup[opcode].cycles) - int(ourLookup[nextOpcode].cycles); - nextLine << ".byte $" << Base::HEX2 << int(opcode) << " ;"; + cycles += static_cast(ourLookup[opcode].cycles) - + static_cast(ourLookup[nextOpcode].cycles); + nextLine << ".byte $" << Base::HEX2 << static_cast(opcode) << " ;"; nextLine << ourLookup[opcode].mnemonic; myDisasmBuf << nextLine.str() << "'" << ";" - << std::dec << int(ourLookup[opcode].cycles) << "-" - << std::dec << int(ourLookup[nextOpcode].cycles) << " " + << std::dec << static_cast(ourLookup[opcode].cycles) << "-" + << std::dec << static_cast(ourLookup[nextOpcode].cycles) << " " << "'= " << std::setw(3) << std::setfill(' ') << std::dec << cycles; nextLine.str(""); @@ -248,12 +249,12 @@ void DiStella::disasm(uInt32 distart, int pass) // Undefined opcodes start with a '.' // These are undefined wrt DASM if(ourLookup[opcode].mnemonic[0] == '.' && pass == 3) { - nextLine << ".byte $" << Base::HEX2 << int(opcode) << " ;"; + nextLine << ".byte $" << Base::HEX2 << static_cast(opcode) << " ;"; } if(pass == 3) { nextLine << ourLookup[opcode].mnemonic; - nextLineBytes << Base::HEX2 << int(opcode) << " "; + nextLineBytes << Base::HEX2 << static_cast(opcode) << " "; } // Add operand(s) for PC values outside the app data range @@ -270,9 +271,9 @@ void DiStella::disasm(uInt32 distart, int pass) /* Line information is already printed; append .byte since last instruction will put recompilable object larger that original binary file */ - myDisasmBuf << ".byte $" << Base::HEX2 << int(opcode) << " $" + myDisasmBuf << ".byte $" << Base::HEX2 << static_cast(opcode) << " $" << Base::HEX4 << myPC + myOffset << "'" - << Base::HEX2 << int(opcode); + << Base::HEX2 << static_cast(opcode); addEntry(Device::DATA); if(myPC == myAppData.end) { @@ -282,9 +283,9 @@ void DiStella::disasm(uInt32 distart, int pass) myDisasmBuf << Base::HEX4 << myPC + myOffset << "' '"; opcode = Debugger::debugger().peek(myPC + myOffset); ++myPC; - myDisasmBuf << ".byte $" << Base::HEX2 << int(opcode) << " $" + myDisasmBuf << ".byte $" << Base::HEX2 << static_cast(opcode) << " $" << Base::HEX4 << myPC + myOffset << "'" - << Base::HEX2 << int(opcode); + << Base::HEX2 << static_cast(opcode); addEntry(Device::DATA); } } @@ -301,7 +302,7 @@ void DiStella::disasm(uInt32 distart, int pass) if(pass == 3) { /* Line information is already printed, but we can remove the Instruction (i.e. BMI) by simply clearing the buffer to print */ - myDisasmBuf << ".byte $" << Base::HEX2 << int(opcode); + myDisasmBuf << ".byte $" << Base::HEX2 << static_cast(opcode); addEntry(Device::ROW); nextLine.str(""); nextLineBytes.str(""); @@ -339,22 +340,26 @@ void DiStella::disasm(uInt32 distart, int pass) if(labelFound == AddressType::ROM) { LABEL_A12_HIGH(ad); - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } else if(labelFound == AddressType::ROM_MIRROR) { if(mySettings.rFlag) { - int tmp = (ad & myAppData.end) + myOffset; + const int tmp = (ad & myAppData.end) + myOffset; LABEL_A12_HIGH(tmp); - nextLineBytes << Base::HEX2 << int(tmp & 0xff) << " " << Base::HEX2 << int(tmp >> 8); + nextLineBytes << Base::HEX2 << static_cast(tmp & 0xff) << " " + << Base::HEX2 << static_cast(tmp >> 8); } else { nextLine << "$" << Base::HEX4 << ad; - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } } else { LABEL_A12_LOW(ad); - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } } break; @@ -367,7 +372,7 @@ void DiStella::disasm(uInt32 distart, int pass) if(pass == 3) { nextLine << " "; LABEL_A12_LOW(int(d1)); - nextLineBytes << Base::HEX2 << int(d1); + nextLineBytes << Base::HEX2 << static_cast(d1); } break; } @@ -376,8 +381,8 @@ void DiStella::disasm(uInt32 distart, int pass) { d1 = Debugger::debugger().peek(myPC + myOffset); ++myPC; if(pass == 3) { - nextLine << " #$" << Base::HEX2 << int(d1) << " "; - nextLineBytes << Base::HEX2 << int(d1); + nextLine << " #$" << Base::HEX2 << static_cast(d1) << " "; + nextLineBytes << Base::HEX2 << static_cast(d1); } break; } @@ -402,24 +407,28 @@ void DiStella::disasm(uInt32 distart, int pass) if(labelFound == AddressType::ROM) { LABEL_A12_HIGH(ad); nextLine << ",x"; - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } else if(labelFound == AddressType::ROM_MIRROR) { if(mySettings.rFlag) { - int tmp = (ad & myAppData.end) + myOffset; + const int tmp = (ad & myAppData.end) + myOffset; LABEL_A12_HIGH(tmp); nextLine << ",x"; - nextLineBytes << Base::HEX2 << int(tmp & 0xff) << " " << Base::HEX2 << int(tmp >> 8); + nextLineBytes << Base::HEX2 << static_cast(tmp & 0xff) << " " + << Base::HEX2 << static_cast(tmp >> 8); } else { nextLine << "$" << Base::HEX4 << ad << ",x"; - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } } else { LABEL_A12_LOW(ad); nextLine << ",x"; - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } } break; @@ -445,24 +454,28 @@ void DiStella::disasm(uInt32 distart, int pass) if(labelFound == AddressType::ROM) { LABEL_A12_HIGH(ad); nextLine << ",y"; - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } else if(labelFound == AddressType::ROM_MIRROR) { if(mySettings.rFlag) { - int tmp = (ad & myAppData.end) + myOffset; + const int tmp = (ad & myAppData.end) + myOffset; LABEL_A12_HIGH(tmp); nextLine << ",y"; - nextLineBytes << Base::HEX2 << int(tmp & 0xff) << " " << Base::HEX2 << int(tmp >> 8); + nextLineBytes << Base::HEX2 << static_cast(tmp & 0xff) << " " + << Base::HEX2 << static_cast(tmp >> 8); } else { nextLine << "$" << Base::HEX4 << ad << ",y"; - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } } else { LABEL_A12_LOW(ad); nextLine << ",y"; - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); } } break; @@ -476,7 +489,7 @@ void DiStella::disasm(uInt32 distart, int pass) nextLine << " ("; LABEL_A12_LOW(d1); nextLine << ",x)"; - nextLineBytes << Base::HEX2 << int(d1); + nextLineBytes << Base::HEX2 << static_cast(d1); } break; } @@ -489,7 +502,7 @@ void DiStella::disasm(uInt32 distart, int pass) nextLine << " ("; LABEL_A12_LOW(d1); nextLine << "),y"; - nextLineBytes << Base::HEX2 << int(d1); + nextLineBytes << Base::HEX2 << static_cast(d1); } break; } @@ -503,7 +516,7 @@ void DiStella::disasm(uInt32 distart, int pass) LABEL_A12_LOW(d1); nextLine << ",x"; } - nextLineBytes << Base::HEX2 << int(d1); + nextLineBytes << Base::HEX2 << static_cast(d1); break; } @@ -516,7 +529,7 @@ void DiStella::disasm(uInt32 distart, int pass) LABEL_A12_LOW(d1); nextLine << ",y"; } - nextLineBytes << Base::HEX2 << int(d1); + nextLineBytes << Base::HEX2 << static_cast(d1); break; } @@ -526,7 +539,7 @@ void DiStella::disasm(uInt32 distart, int pass) // where wraparound occurred on a 32-bit int, and subsequent // indexing into the labels array caused a crash d1 = Debugger::debugger().peek(myPC + myOffset); ++myPC; - ad = ((myPC + Int8(d1)) & 0xfff) + myOffset; + ad = ((myPC + static_cast(d1)) & 0xfff) + myOffset; labelFound = mark(ad, Device::REFERENCED); if(pass == 3) { @@ -537,7 +550,7 @@ void DiStella::disasm(uInt32 distart, int pass) else nextLine << " $" << Base::HEX4 << ad; - nextLineBytes << Base::HEX2 << int(d1); + nextLineBytes << Base::HEX2 << static_cast(d1); } break; } @@ -567,7 +580,7 @@ void DiStella::disasm(uInt32 distart, int pass) else if(labelFound == AddressType::ROM_MIRROR) { nextLine << "("; if(mySettings.rFlag) { - int tmp = (ad & myAppData.end) + myOffset; + const int tmp = (ad & myAppData.end) + myOffset; LABEL_A12_HIGH(tmp); } else { @@ -581,7 +594,8 @@ void DiStella::disasm(uInt32 distart, int pass) nextLine << ")"; } - nextLineBytes << Base::HEX2 << int(ad & 0xff) << " " << Base::HEX2 << int(ad >> 8); + nextLineBytes << Base::HEX2 << static_cast(ad & 0xff) << " " + << Base::HEX2 << static_cast(ad >> 8); break; } @@ -590,10 +604,10 @@ void DiStella::disasm(uInt32 distart, int pass) } // end switch if(pass == 3) { - cycles += int(ourLookup[opcode].cycles); + cycles += static_cast(ourLookup[opcode].cycles); // A complete line of disassembly (text, cycle count, and bytes) myDisasmBuf << nextLine.str() << "'" - << ";" << std::dec << int(ourLookup[opcode].cycles) + << ";" << std::dec << static_cast(ourLookup[opcode].cycles) << (addrMode == AddressingMode::RELATIVE ? (ad & 0xf00) != ((myPC + myOffset) & 0xf00) ? "/3!" : "/3 " : " "); if((opcode == 0x40 || opcode == 0x60 || opcode == 0x4c || opcode == 0x00 // code block end || checkBit(myPC, Device::REFERENCED) // referenced address @@ -629,7 +643,7 @@ void DiStella::disasm(uInt32 distart, int pass) void DiStella::disasmPass1(CartDebug::AddressList& debuggerAddresses) { auto it = debuggerAddresses.cbegin(); - uInt16 start = *it++; + const uInt16 start = *it++; // After we've disassembled from all addresses in the address list, // use all access points determined by Stella during emulation @@ -647,7 +661,7 @@ void DiStella::disasmPass1(CartDebug::AddressList& debuggerAddresses) myAddressQueue.push(start); while (!(myAddressQueue.empty() || duplicateFound)) { - uInt16 pcBeg = myPC = lastPC = myAddressQueue.front(); + const uInt16 pcBeg = myPC = lastPC = myAddressQueue.front(); myAddressQueue.pop(); disasmFromAddress(myPC); @@ -691,7 +705,7 @@ void DiStella::disasmPass1(CartDebug::AddressList& debuggerAddresses) // the ::disasm method // All of these have to be exhausted before considering a new address while (myAddressQueue.empty() && it != debuggerAddresses.end()) { - uInt16 addr = *it; + const uInt16 addr = *it; if (!checkBit(addr - myOffset, Device::CODE)) { myAddressQueue.push(addr); @@ -733,9 +747,9 @@ void DiStella::disasmPass1(CartDebug::AddressList& debuggerAddresses) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DiStella::disasmFromAddress(uInt32 distart) { - uInt8 opcode, d1; - uInt16 ad; - AddressingMode addrMode; + uInt8 opcode = 0, d1 = 0; + uInt16 ad = 0; + AddressingMode addrMode{}; myPC = distart - myOffset; @@ -843,7 +857,7 @@ void DiStella::disasmFromAddress(uInt32 distart) // where wraparound occurred on a 32-bit int, and subsequent // indexing into the labels array caused a crash d1 = Debugger::debugger().peek(myPC + myOffset); ++myPC; - ad = ((myPC + Int8(d1)) & 0xfff) + myOffset; + ad = ((myPC + static_cast(d1)) & 0xfff) + myOffset; mark(ad, Device::REFERENCED); // do NOT use flags set by debugger, else known CODE will not analyzed statically. if (!checkBit(ad - myOffset, Device::CODE, false)) { @@ -933,7 +947,7 @@ DiStella::AddressType DiStella::mark(uInt32 address, uInt16 mask, bool directive // Check for equates before ROM/ZP-RAM accesses, because the original logic // of Distella assumed either equates or ROM; it didn't take ZP-RAM into account - CartDebug::AddrType type = myDbg.addressType(address); + const CartDebug::AddrType type = myDbg.addressType(address); if(type == CartDebug::AddrType::TIA) { return AddressType::TIA; } @@ -943,7 +957,8 @@ DiStella::AddressType DiStella::mark(uInt32 address, uInt16 mask, bool directive else if(type == CartDebug::AddrType::ZPRAM && myOffset != 0) { return AddressType::ZP_RAM; } - else if(address >= uInt32(myOffset) && address <= uInt32(myAppData.end + myOffset)) { + else if(address >= static_cast(myOffset) && + address <= static_cast(myAppData.end + myOffset)) { myLabels[address - myOffset] = myLabels[address - myOffset] | mask; if(directive) myDirectives[address - myOffset] = mask; @@ -968,7 +983,7 @@ bool DiStella::checkBit(uInt16 address, uInt16 mask, bool useDebugger) const // an address // Since they're set only in the labels array (as the lower two bits), // they must be included in the other bitfields - uInt16 label = myLabels[address & myAppData.end], + const uInt16 label = myLabels[address & myAppData.end], lastbits = label & (Device::REFERENCED | Device::VALID_ENTRY), directive = myDirectives[address & myAppData.end] & ~(Device::REFERENCED | Device::VALID_ENTRY), debugger = Debugger::debugger().getAccessFlags(address | myOffset) & ~(Device::REFERENCED | Device::VALID_ENTRY); @@ -1097,9 +1112,9 @@ DONE_WITH_ADD: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DiStella::outputGraphics() { - bool isPGfx = checkBit(myPC, Device::PGFX); + const bool isPGfx = checkBit(myPC, Device::PGFX); const string& bitString = isPGfx ? "\x1f" : "\x1e"; - uInt8 byte = Debugger::debugger().peek(myPC + myOffset); + const uInt8 byte = Debugger::debugger().peek(myPC + myOffset); // add extra spacing line when switching from non-graphics to graphics if (mySegType != Device::GFX && mySegType != Device::NONE) { @@ -1112,14 +1127,14 @@ void DiStella::outputGraphics() myDisasmBuf << Base::HEX4 << myPC + myOffset << "'L" << Base::HEX4 << myPC + myOffset << "'"; else myDisasmBuf << Base::HEX4 << myPC + myOffset << "' '"; - myDisasmBuf << ".byte $" << Base::HEX2 << int(byte) << " |"; + myDisasmBuf << ".byte $" << Base::HEX2 << static_cast(byte) << " |"; for (uInt8 i = 0, c = byte; i < 8; ++i, c <<= 1) myDisasmBuf << ((c > 127) ? bitString : " "); myDisasmBuf << "| $" << Base::HEX4 << myPC + myOffset << "'"; if (mySettings.gfxFormat == Base::Fmt::_2) myDisasmBuf << Base::toString(byte, Base::Fmt::_2_8); else - myDisasmBuf << Base::HEX2 << int(byte); + myDisasmBuf << Base::HEX2 << static_cast(byte); addEntry(isPGfx ? Device::PGFX : Device::GFX); } @@ -1144,7 +1159,7 @@ void DiStella::outputColors() "GREEN", "CYAN", "YELLOW", "WHITE" }; - uInt8 byte = Debugger::debugger().peek(myPC + myOffset); + const uInt8 byte = Debugger::debugger().peek(myPC + myOffset); // add extra spacing line when switching from non-colors to colors if(mySegType != Device::COL && mySegType != Device::NONE) @@ -1179,14 +1194,14 @@ void DiStella::outputColors() color = SECAM_COLOR[(byte >> 1) & 0x7]; myDisasmBuf << "$" << Base::HEX1 << (byte >> 4) << "|" << color; } - myDisasmBuf << std::setw(int(16 - color.length())) << std::setfill(' '); + myDisasmBuf << std::setw(static_cast(16 - color.length())) << std::setfill(' '); // output address myDisasmBuf << "; $" << Base::HEX4 << myPC + myOffset << " " << (checkBit(myPC, Device::COL) ? "(Px)" : checkBit(myPC, Device::PCOL) ? "(PF)" : "(BK)"); // output color value - myDisasmBuf << "'" << Base::HEX2 << int(byte); + myDisasmBuf << "'" << Base::HEX2 << static_cast(byte); addEntry(checkBit(myPC, Device::COL) ? Device::COL : checkBit(myPC, Device::PCOL) ? Device::PCOL : Device::BCOL); @@ -1215,14 +1230,14 @@ void DiStella::outputBytes(Device::AccessType type) myDisasmBuf << Base::HEX4 << myPC + myOffset << "'L" << Base::HEX4 << myPC + myOffset << "'.byte " << "$" << Base::HEX2 - << int(Debugger::debugger().peek(myPC + myOffset)); + << static_cast(Debugger::debugger().peek(myPC + myOffset)); ++myPC; numBytes = 1; lineEmpty = false; } else if (lineEmpty) { // start a new line without a label myDisasmBuf << Base::HEX4 << myPC + myOffset << "' '" - << ".byte $" << Base::HEX2 << int(Debugger::debugger().peek(myPC + myOffset)); + << ".byte $" << Base::HEX2 << static_cast(Debugger::debugger().peek(myPC + myOffset)); ++myPC; numBytes = 1; lineEmpty = false; @@ -1232,7 +1247,7 @@ void DiStella::outputBytes(Device::AccessType type) addEntry(type); lineEmpty = true; } else { - myDisasmBuf << ",$" << Base::HEX2 << int(Debugger::debugger().peek(myPC + myOffset)); + myDisasmBuf << ",$" << Base::HEX2 << static_cast(Debugger::debugger().peek(myPC + myOffset)); ++myPC; } isType = checkBits(myPC, type, diff --git a/src/debugger/RiotDebug.cxx b/src/debugger/RiotDebug.cxx index 3672c2100..c8087d6f8 100644 --- a/src/debugger/RiotDebug.cxx +++ b/src/debugger/RiotDebug.cxx @@ -310,7 +310,7 @@ bool RiotDebug::reset(int newVal) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string RiotDebug::dirP0String() { - uInt8 reg = swcha(); + const uInt8 reg = swcha(); ostringstream buf; buf << ((reg & 0x80) ? "" : "right ") << ((reg & 0x40) ? "" : "left ") @@ -323,7 +323,7 @@ string RiotDebug::dirP0String() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string RiotDebug::dirP1String() { - uInt8 reg = swcha(); + const uInt8 reg = swcha(); ostringstream buf; buf << ((reg & 0x08) ? "" : "right ") << ((reg & 0x04) ? "" : "left ") diff --git a/src/debugger/RiotDebug.hxx b/src/debugger/RiotDebug.hxx index eec3ed4a5..2aa43bf84 100644 --- a/src/debugger/RiotDebug.hxx +++ b/src/debugger/RiotDebug.hxx @@ -85,8 +85,8 @@ class RiotDebug : public DebuggerSystem int timWrappedOnWrite() const; int timReadCycles() const; - int timintAsInt() const { return int(timint()); } // so we can use _timInt pseudo-register - int intimAsInt() const { return int(intim()); } // so we can use _inTim pseudo-register + int timintAsInt() const { return static_cast(timint()); } // so we can use _timInt pseudo-register + int intimAsInt() const { return static_cast(intim()); } // so we can use _inTim pseudo-register /* Console switches */ bool diffP0(int newVal = -1); diff --git a/src/debugger/TIADebug.cxx b/src/debugger/TIADebug.cxx index 8a61e196d..b2e56e458 100644 --- a/src/debugger/TIADebug.cxx +++ b/src/debugger/TIADebug.cxx @@ -42,7 +42,7 @@ const DebuggerState& TIADebug::getState() myState.coluRegs.push_back(coluBK()); // Debug Colors - int timing = myConsole.timing() == ConsoleTiming::ntsc ? 0 + const int timing = myConsole.timing() == ConsoleTiming::ntsc ? 0 : myConsole.timing() == ConsoleTiming::pal ? 1 : 2; myState.fixedCols.clear(); @@ -925,13 +925,13 @@ int TIADebug::frameWsyncCycles() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int TIADebug::cyclesLo() const { - return int(myTIA.cycles()); + return static_cast(myTIA.cycles()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int TIADebug::cyclesHi() const { - return int(myTIA.cycles() >> 32); + return static_cast(myTIA.cycles() >> 32); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -999,7 +999,7 @@ string TIADebug::colorSwatch(uInt8 c) const { string ret; - ret += char((c >> 1) | 0x80); + ret += static_cast((c >> 1) | 0x80); ret += "\177 "; ret += "\177\001 "; @@ -1021,7 +1021,7 @@ string TIADebug::audFreq1() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string TIADebug::audFreq(uInt8 dist, uInt8 div) { - uInt16 dist_div[16] = { + constexpr uInt16 dist_div[16] = { 1, 15, 465, 465, 2, 2, 31, 31, 511, 31, 31, 1, 6, 6, 93, 93 }; @@ -1044,7 +1044,8 @@ string TIADebug::stringOnly(string value, bool changed) buf << value; if(changed) - return char(kDbgColorRed & 0xff) + buf.str() + char(kTextColor & 0xff); + return static_cast(kDbgColorRed & 0xff) + buf.str() + + static_cast(kTextColor & 0xff); else return buf.str(); } @@ -1060,7 +1061,8 @@ string TIADebug::decWithLabel(string label, uInt16 value, bool changed, uInt16 w buf << "#" << std::setw(width) << std::dec << std::left << value; if(changed) - return char(kDbgColorRed & 0xff) + buf.str() + char(kTextColor & 0xff); + return static_cast(kDbgColorRed & 0xff) + buf.str() + + static_cast(kTextColor & 0xff); else return buf.str(); } @@ -1076,7 +1078,8 @@ string TIADebug::hexWithLabel(string label, uInt16 value, bool changed, uInt16 w buf << "$" << (width == 1 ? Common::Base::HEX1 : Common::Base::HEX2) << value; if(changed) - return char(kDbgColorRed & 0xff) + buf.str() + char(kTextColor & 0xff); + return static_cast(kDbgColorRed & 0xff) + buf.str() + + static_cast(kTextColor & 0xff); else return buf.str(); } @@ -1092,7 +1095,8 @@ string TIADebug::binWithLabel(string label, uInt16 value, bool changed) buf << "%" << Common::Base::toString(value, Common::Base::Fmt::_2_8); if(changed) - return char(kDbgColorRed & 0xff) + buf.str() + char(kTextColor & 0xff); + return static_cast(kDbgColorRed & 0xff) + buf.str() + + static_cast(kTextColor & 0xff); else return buf.str(); } @@ -1110,7 +1114,8 @@ string TIADebug::boolWithLabel(string label, bool value, bool changed) //return "-" + BSPF::toLowerCase(label); if(changed) - return char(kDbgColorRed & 0xff) + buf.str() + char(kTextColor & 0xff); + return static_cast(kDbgColorRed & 0xff) + buf.str() + + static_cast(kTextColor & 0xff); else return buf.str(); } @@ -1120,7 +1125,7 @@ string TIADebug::debugColors() const { ostringstream buf; - int timing = myConsole.timing() == ConsoleTiming::ntsc ? 0 + const int timing = myConsole.timing() == ConsoleTiming::ntsc ? 0 : myConsole.timing() == ConsoleTiming::pal ? 1 : 2; buf << " " << myTIA.myFixedColorNames[TIA::P0] << " " << colorSwatch(myTIA.myFixedColorPalette[timing][TIA::P0]) @@ -1313,27 +1318,27 @@ string TIADebug::toString() riotState.INPTDump != oldRiotState.INPTDump) << endl << "AUDF0: " - << hexWithLabel("", int(audF0()), + << hexWithLabel("", static_cast(audF0()), state.aud[0] != oldState.aud[0]) << "/" << std::setw(9) << std::right << stringOnly(audFreq0(), state.aud[0] != oldState.aud[0]) << " " << "AUDC0: " - << hexWithLabel("", int(audC0()), + << hexWithLabel("", static_cast(audC0()), state.aud[2] != oldState.aud[2], 1) << " " << "AUDV0: " - << hexWithLabel("", int(audV0()), + << hexWithLabel("", static_cast(audV0()), state.aud[4] != oldState.aud[4], 1) << endl << "AUDF1: " - << hexWithLabel("", int(audF1()), + << hexWithLabel("", static_cast(audF1()), state.aud[1] != oldState.aud[1]) << "/" << std::setw(9) << std::right << stringOnly(audFreq1(), state.aud[1] != oldState.aud[1]) << " " << "AUDC1: " - << hexWithLabel("", int(audC1()), + << hexWithLabel("", static_cast(audC1()), state.aud[3] != oldState.aud[3], 1) << " " << "AUDV1: " - << hexWithLabel("", int(audV1()), + << hexWithLabel("", static_cast(audV1()), state.aud[5] != oldState.aud[5], 1); // note: last line should not contain \n, caller will add. return buf.str(); diff --git a/src/debugger/TIADebug.hxx b/src/debugger/TIADebug.hxx index 6e37c9cbd..8e9aa3b4b 100644 --- a/src/debugger/TIADebug.hxx +++ b/src/debugger/TIADebug.hxx @@ -178,8 +178,8 @@ class TIADebug : public DebuggerSystem int cyclesThisLine() const; bool vsync() const; bool vblank() const; - int vsyncAsInt() const { return int(vsync()); } // so we can use _vsync pseudo-register - int vblankAsInt() const { return int(vblank()); } // so we can use _vblank pseudo-register + int vsyncAsInt() const { return static_cast(vsync()); } // so we can use _vsync pseudo-register + int vblankAsInt() const { return static_cast(vblank()); } // so we can use _vblank pseudo-register shared_ptr delayQueueIterator() const; diff --git a/src/debugger/gui/AudioWidget.cxx b/src/debugger/gui/AudioWidget.cxx index bb78fc03a..2e305d9ca 100644 --- a/src/debugger/gui/AudioWidget.cxx +++ b/src/debugger/gui/AudioWidget.cxx @@ -58,7 +58,8 @@ AudioWidget::AudioWidget(GuiObject* boss, const GUI::Font& lfont, for(int col = 0; col < 2; ++col) { - new StaticTextWidget(boss, lfont, xpos + col * myAudF->colWidth() + int(myAudF->colWidth() / 2.75), + new StaticTextWidget(boss, lfont, xpos + col * myAudF->colWidth() + + static_cast(myAudF->colWidth() / 2.75), ypos - lineHeight, fontWidth, fontHeight, Common::Base::toString(col, Common::Base::Fmt::_16_1), TextAlign::Left); @@ -68,7 +69,7 @@ AudioWidget::AudioWidget(GuiObject* boss, const GUI::Font& lfont, new StaticTextWidget(boss, lfont, xpos, ypos+2, lwidth, fontHeight, "AUDC", TextAlign::Left); xpos += lwidth; - myAudC = new DataGridWidget(boss, nfont, xpos + int(myAudF->colWidth() / 2.75), ypos, + myAudC = new DataGridWidget(boss, nfont, xpos + static_cast(myAudF->colWidth() / 2.75), ypos, 2, 1, 1, 4, Common::Base::Fmt::_16_1); myAudC->setTarget(this); myAudC->setID(kAUDCID); @@ -79,7 +80,7 @@ AudioWidget::AudioWidget(GuiObject* boss, const GUI::Font& lfont, new StaticTextWidget(boss, lfont, xpos, ypos+2, lwidth, fontHeight, "AUDV", TextAlign::Left); xpos += lwidth; - myAudV = new DataGridWidget(boss, nfont, xpos + int(myAudF->colWidth() / 2.75), ypos, + myAudV = new DataGridWidget(boss, nfont, xpos + static_cast(myAudF->colWidth() / 2.75), ypos, 2, 1, 1, 4, Common::Base::Fmt::_16_1); myAudV->setTarget(this); myAudV->setID(kAUDVID); @@ -184,8 +185,8 @@ void AudioWidget::handleCommand(CommandSender* sender, int cmd, int data, int id // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AudioWidget::changeFrequencyRegs() { - int addr = myAudF->getSelectedAddr(); - int value = myAudF->getSelectedValue(); + const int addr = myAudF->getSelectedAddr(); + const int value = myAudF->getSelectedValue(); switch(addr) { @@ -206,8 +207,8 @@ void AudioWidget::changeFrequencyRegs() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AudioWidget::changeControlRegs() { - int addr = myAudC->getSelectedAddr(); - int value = myAudC->getSelectedValue(); + const int addr = myAudC->getSelectedAddr(); + const int value = myAudC->getSelectedValue(); switch(addr) { @@ -229,8 +230,8 @@ void AudioWidget::changeControlRegs() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AudioWidget::changeVolumeRegs() { - int addr = myAudV->getSelectedAddr(); - int value = myAudV->getSelectedValue(); + const int addr = myAudV->getSelectedAddr(); + const int value = myAudV->getSelectedValue(); switch(addr) { diff --git a/src/debugger/gui/Cart0840Widget.cxx b/src/debugger/gui/Cart0840Widget.cxx index cd8bacd16..2d16d1999 100644 --- a/src/debugger/gui/Cart0840Widget.cxx +++ b/src/debugger/gui/Cart0840Widget.cxx @@ -33,8 +33,8 @@ string Cartridge0840Widget::description() { ostringstream info; - info << "0840 ECONObanking, two 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "0840 ECONObanking, two 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/Cart3EPlusWidget.cxx b/src/debugger/gui/Cart3EPlusWidget.cxx index 616625bfc..ca06fdb6f 100644 --- a/src/debugger/gui/Cart3EPlusWidget.cxx +++ b/src/debugger/gui/Cart3EPlusWidget.cxx @@ -36,8 +36,8 @@ string Cartridge3EPlusWidget::description() ostringstream info; size_t size; const ByteBuffer& image = myCart.getImage(size); - uInt16 numRomBanks = myCart.romBankCount(); - uInt16 numRamBanks = myCart.ramBankCount(); + const uInt16 numRomBanks = myCart.romBankCount(); + const uInt16 numRamBanks = myCart.ramBankCount(); info << "3E+ cartridge - (4" << ELLIPSIS << "64K ROM + RAM)\n" << " " << numRomBanks << " 1K ROM banks + " << numRamBanks << " 512b RAM banks\n" @@ -73,7 +73,7 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos) for(uInt32 seg = 0; seg < bankSegs(); ++seg) { - int xpos = 2, xpos_s, ypos_s = ypos + 1, width; + int xpos = 2, ypos_s = ypos + 1, width = 0; ostringstream label; VariantList items; @@ -111,18 +111,17 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos) myBankCommit[seg]->setTarget(this); addFocusWidget(myBankCommit[seg]); - xpos_s = myBankCommit[seg]->getRight() + _font.getMaxCharWidth() * 2; + const int xpos_s = myBankCommit[seg]->getRight() + _font.getMaxCharWidth() * 2; - StaticTextWidget* t; uInt16 start = (image[0x400 - 3] << 8) | image[0x400 - 4]; start -= start % 0x1000; - int addr1 = start + (seg * 0x400), addr2 = addr1 + 0x200; + const int addr1 = start + (seg * 0x400), addr2 = addr1 + 0x200; label.str(""); label << "$" << Common::Base::HEX4 << addr1 << "-$" << Common::Base::HEX4 << (addr1 + 0x1FF); - t = new StaticTextWidget(_boss, _font, xpos_s, ypos_s + 2, label.str()); + StaticTextWidget* t = new StaticTextWidget(_boss, _font, xpos_s, ypos_s + 2, label.str()); - int xoffset = t->getRight() + _font.getMaxCharWidth(); + const int xoffset = t->getRight() + _font.getMaxCharWidth(); myBankState[2 * seg] = new EditTextWidget(_boss, _font, xoffset, ypos_s, _w - xoffset - 10, myLineHeight, ""); myBankState[2 * seg]->setEditable(false, true); @@ -159,7 +158,7 @@ void Cartridge3EPlusWidget::handleCommand(CommandSender* sender, case kRomRamChanged: { const bool isROM = myBankType[segment]->getSelectedTag() == "ROM"; - int bank = myBankWidgets[segment]->getSelected(); + const int bank = myBankWidgets[segment]->getSelected(); myBankCommit[segment]->setEnabled((isROM && bank < myCart.romBankCount()) || (!isROM && bank < myCart.ramBankCount())); @@ -172,7 +171,7 @@ void Cartridge3EPlusWidget::handleCommand(CommandSender* sender, myBankType[segment]->getSelected() < 0) return; - uInt8 bank = myBankWidgets[segment]->getSelected(); + const uInt8 bank = myBankWidgets[segment]->getSelected(); myCart.unlockHotspots(); @@ -198,12 +197,12 @@ void Cartridge3EPlusWidget::updateUIState() // Set contents for actual banks number and type (@ each even index) for(int seg = 0; seg < myCart3EP.myBankSegs; ++seg) { - uInt16 bank = myCart.getSegmentBank(seg); + const uInt16 bank = myCart.getSegmentBank(seg); ostringstream buf; if(bank >= myCart.romBankCount()) // was RAM mapped here? { - uInt16 ramBank = bank - myCart.romBankCount(); + const uInt16 ramBank = bank - myCart.romBankCount(); buf << "RAM @ $" << Common::Base::HEX4 << (ramBank << myCart3EP.myBankShift) << " (R)"; diff --git a/src/debugger/gui/Cart3EWidget.cxx b/src/debugger/gui/Cart3EWidget.cxx index 2189217f6..8d4fa8b3c 100644 --- a/src/debugger/gui/Cart3EWidget.cxx +++ b/src/debugger/gui/Cart3EWidget.cxx @@ -34,9 +34,8 @@ string Cartridge3EWidget::description() ostringstream info; size_t size; const ByteBuffer& image = myCart.getImage(size); - uInt16 numRomBanks = myCart.romBankCount(); - uInt16 numRamBanks = myCart.ramBankCount(); - + const uInt16 numRomBanks = myCart.romBankCount(); + const uInt16 numRamBanks = myCart.ramBankCount(); info << "3E cartridge (3F + RAM),\n" << " " << numRomBanks << " 2K ROM banks, " << numRamBanks << " 1K RAM banks\n" @@ -103,8 +102,8 @@ void Cartridge3EWidget::bankSelect(int& ypos) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge3EWidget::loadConfig() { - uInt16 oldBank = myOldState.banks[0]; - uInt16 bank = myCart.getBank(); + const uInt16 oldBank = myOldState.banks[0]; + const uInt16 bank = myCart.getBank(); if(myCart.getBank() < myCart.romBankCount()) { @@ -161,7 +160,7 @@ void Cartridge3EWidget::handleCommand(CommandSender* sender, int cmd, int data, string Cartridge3EWidget::bankState() { ostringstream& buf = buffer(); - uInt16 bank = myCart.getBank(); + const uInt16 bank = myCart.getBank(); if(bank < myCart.romBankCount()) buf << "ROM bank #" << std::dec << bank % myCart.romBankCount() << ", RAM inactive"; diff --git a/src/debugger/gui/Cart3FWidget.cxx b/src/debugger/gui/Cart3FWidget.cxx index 878046045..b35e5a140 100644 --- a/src/debugger/gui/Cart3FWidget.cxx +++ b/src/debugger/gui/Cart3FWidget.cxx @@ -32,7 +32,7 @@ Cartridge3FWidget::Cartridge3FWidget( string Cartridge3FWidget::description() { ostringstream info; - size_t size; + size_t size = 0; const ByteBuffer& image = myCart.getImage(size); info << "Tigervision 3F cartridge, 2 - 256 2K banks\n" diff --git a/src/debugger/gui/Cart4KWidget.cxx b/src/debugger/gui/Cart4KWidget.cxx index 6f85b2e28..59e0ce06a 100644 --- a/src/debugger/gui/Cart4KWidget.cxx +++ b/src/debugger/gui/Cart4KWidget.cxx @@ -42,8 +42,8 @@ string Cartridge4KWidget::description() { ostringstream info; - info << "Standard 4K cartridge, non-bankswitched\n"; - info << CartridgeEnhancedWidget::description(); + info << "Standard 4K cartridge, non-bankswitched\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartARMWidget.cxx b/src/debugger/gui/CartARMWidget.cxx index 335020179..fbcacd7bd 100644 --- a/src/debugger/gui/CartARMWidget.cxx +++ b/src/debugger/gui/CartARMWidget.cxx @@ -35,8 +35,7 @@ CartridgeARMWidget::CartridgeARMWidget( // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeARMWidget::addCycleWidgets(int xpos, int ypos) { - const int INDENT = 20; - const int VGAP = 4; + constexpr int INDENT = 20, VGAP = 4; VariantList items; new StaticTextWidget(_boss, _font, xpos, ypos + 1, "ARM emulation cycles:"); @@ -142,17 +141,16 @@ void CartridgeARMWidget::saveOldState() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeARMWidget::loadConfig() { - bool isChanged; bool devSettings = instance().settings().getBool("dev.settings"); IntArray alist; IntArray vlist; BoolArray changed; myChipType->setSelectedIndex(static_cast(instance().settings().getInt("dev.thumb.chiptype") - - int(Thumbulator::ChipType::AUTO))); + - static_cast(Thumbulator::ChipType::AUTO))); handleChipType(); - isChanged = static_cast(myCart.mamMode()) != myOldState.mamMode; + const bool isChanged = static_cast(myCart.mamMode()) != myOldState.mamMode; myMamMode->setSelectedIndex(static_cast(myCart.mamMode()), isChanged); myMamMode->setEnabled(devSettings && myLockMamMode->getState()); myLockMamMode->setEnabled(devSettings); @@ -245,7 +243,7 @@ void CartridgeARMWidget::handleChipType() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeARMWidget::handleMamLock() { - bool checked = myLockMamMode->getState(); + const bool checked = myLockMamMode->getState(); myMamMode->setEnabled(checked); myCart.lockMamMode(checked); @@ -255,7 +253,7 @@ void CartridgeARMWidget::handleMamLock() void CartridgeARMWidget::handleMamMode() { // override MAM mode set by ROM - Int32 mode = myMamMode->getSelected(); + const Int32 mode = myMamMode->getSelected(); string name = myMamMode->getSelectedName(); myMamMode->setSelectedName(name + "XXX"); @@ -268,9 +266,9 @@ void CartridgeARMWidget::handleMamMode() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeARMWidget::handleArmCycles() { - bool devSettings = instance().settings().getBool("dev.settings"); - bool enable = myIncCycles->getState(); - double factor = static_cast(myCycleFactor->getValue()) / 100.0; + const bool devSettings = instance().settings().getBool("dev.settings"); + const bool enable = myIncCycles->getState(); + const double factor = static_cast(myCycleFactor->getValue()) / 100.0; if(devSettings) { diff --git a/src/debugger/gui/CartARWidget.cxx b/src/debugger/gui/CartARWidget.cxx index 2c3863949..28272c0bf 100644 --- a/src/debugger/gui/CartARWidget.cxx +++ b/src/debugger/gui/CartARWidget.cxx @@ -29,14 +29,14 @@ CartridgeARWidget::CartridgeARWidget( : CartDebugWidget(boss, lfont, nfont, x, y, w, h), myCart{cart} { - size_t size = myCart.mySize; + const size_t size = myCart.mySize; string info = "Supercharger cartridge, four 2K slices (3 RAM, 1 ROM)\n" "\nTHIS SCHEME IS NOT FULLY IMPLEMENTED OR TESTED\n"; - int xpos = 2, - ypos = addBaseInformation(size, "Starpath", info) + myLineHeight; + constexpr int xpos = 2; + const int ypos = addBaseInformation(size, "Starpath", info) + myLineHeight; VariantList items; VarList::push_back(items, " 0"); diff --git a/src/debugger/gui/CartBFSCWidget.cxx b/src/debugger/gui/CartBFSCWidget.cxx index a89a5b34c..b70347a0d 100644 --- a/src/debugger/gui/CartBFSCWidget.cxx +++ b/src/debugger/gui/CartBFSCWidget.cxx @@ -32,8 +32,8 @@ string CartridgeBFSCWidget::description() { ostringstream info; - info << "256K BFSC + RAM, 64 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "256K BFSC + RAM, 64 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartBFWidget.cxx b/src/debugger/gui/CartBFWidget.cxx index c6b06f97e..3d336ea9f 100644 --- a/src/debugger/gui/CartBFWidget.cxx +++ b/src/debugger/gui/CartBFWidget.cxx @@ -32,8 +32,8 @@ string CartridgeBFWidget::description() { ostringstream info; - info << "256K BF cartridge, 64 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "256K BF cartridge, 64 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartBUSWidget.cxx b/src/debugger/gui/CartBUSWidget.cxx index 3866764b7..365f32bb9 100644 --- a/src/debugger/gui/CartBUSWidget.cxx +++ b/src/debugger/gui/CartBUSWidget.cxx @@ -28,7 +28,7 @@ CartridgeBUSWidget::CartridgeBUSWidget( : CartridgeARMWidget(boss, lfont, nfont, x, y, w, h, cart), myCart{cart} { - uInt16 size = 8 * 4096; + constexpr uInt16 size = 8 * 4096; ostringstream info; info << "BUS Stuffing cartridge (EXPERIMENTAL)\n" @@ -155,8 +155,8 @@ CartridgeBUSWidget::CartridgeBUSWidget( myMusicWaveforms->setTarget(this); myMusicWaveforms->setEditable(false); - int xpossp = xpos + myMusicWaveforms->getWidth() + 20; - int lwidth2 = _font.getStringWidth("Sample Pointer "); + const int xpossp = xpos + myMusicWaveforms->getWidth() + 20; + const int lwidth2 = _font.getStringWidth("Sample Pointer "); new StaticTextWidget(boss, _font, xpossp, ypos, lwidth2, myFontHeight, "Sample Pointer ", TextAlign::Left); @@ -270,7 +270,7 @@ void CartridgeBUSWidget::loadConfig() // I = Increment // F = Fractional - Int32 pointervalue = myCart.getDatastreamPointer(i) >> 12; + const Int32 pointervalue = myCart.getDatastreamPointer(i) >> 12; alist.push_back(0); vlist.push_back(pointervalue); changed.push_back(pointervalue != myOldState.datastreampointers[i]); } @@ -279,7 +279,7 @@ void CartridgeBUSWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 16; i < 18; ++i) { - Int32 pointervalue = myCart.getDatastreamPointer(i) >> 12; + const Int32 pointervalue = myCart.getDatastreamPointer(i) >> 12; alist.push_back(0); vlist.push_back(pointervalue); changed.push_back(pointervalue != myOldState.datastreampointers[i]); } @@ -288,7 +288,7 @@ void CartridgeBUSWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 0; i < 16; ++i) { - Int32 incrementvalue = myCart.getDatastreamIncrement(i); + const Int32 incrementvalue = myCart.getDatastreamIncrement(i); alist.push_back(0); vlist.push_back(incrementvalue); changed.push_back(incrementvalue != myOldState.datastreamincrements[i]); } @@ -297,7 +297,7 @@ void CartridgeBUSWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 16; i < 18; ++i) { - Int32 incrementvalue = 0x100; + constexpr Int32 incrementvalue = 0x100; alist.push_back(0); vlist.push_back(incrementvalue); changed.push_back(incrementvalue != myOldState.datastreamincrements[i]); } @@ -306,13 +306,13 @@ void CartridgeBUSWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 0; i < 37; ++i) // only 37 map values { - Int32 mapvalue = myCart.getAddressMap(i); + const Int32 mapvalue = myCart.getAddressMap(i); alist.push_back(0); vlist.push_back(mapvalue); changed.push_back(mapvalue != myOldState.addressmaps[i]); } for(int i = 37; i < 40; ++i) // but need 40 for the grid { - Int32 mapvalue = 0; + constexpr Int32 mapvalue = 0; alist.push_back(0); vlist.push_back(mapvalue); changed.push_back(mapvalue != myOldState.addressmaps[i]); } diff --git a/src/debugger/gui/CartCDFInfoWidget.cxx b/src/debugger/gui/CartCDFInfoWidget.cxx index 3a897c370..be0b946b2 100644 --- a/src/debugger/gui/CartCDFInfoWidget.cxx +++ b/src/debugger/gui/CartCDFInfoWidget.cxx @@ -24,24 +24,24 @@ CartridgeCDFInfoWidget::CartridgeCDFInfoWidget( : CartDebugWidget(boss, lfont, nfont, x, y, w, h) { ostringstream info; - + info << describeCDFVersion(cart.myCDFSubtype) << " cartridge\n" - << (cart.romSize() / 1024) << "K ROM\n" - << (cart.ramSize() / 1024) << "K RAM\n" - << "Seven 4K banks are available to 2600\n" - << "Functions accessible @ $FFF0 - $FFF3\n" - << (cart.isCDFJplus() ? "Banks accessible @ $FFF4 to $FFFA\n" : "Banks accessible @ $FFF5 to $FFFB\n") - << "Startup bank = " << cart.startBank() << "\n" - << "Fast Fetcher(s): LDA #"; - + << (cart.romSize() / 1024) << "K ROM\n" + << (cart.ramSize() / 1024) << "K RAM\n" + << "Seven 4K banks are available to 2600\n" + << "Functions accessible @ $FFF0 - $FFF3\n" + << (cart.isCDFJplus() ? "Banks accessible @ $FFF4 to $FFFA\n" : "Banks accessible @ $FFF5 to $FFFB\n") + << "Startup bank = " << cart.startBank() << "\n" + << "Fast Fetcher(s): LDA #"; + if (cart.myLDXenabled) info << ", LDX #"; - + if (cart.myLDYenabled) info << ", LDY #"; - + info << "\n"; - + #if 0 // Eventually, we should query this from the debugger/disassembler for(uInt32 i = 0, offset = 0xFFC, spot = 0xFF5; i < 7; ++i, offset += 0x1000) diff --git a/src/debugger/gui/CartCDFWidget.cxx b/src/debugger/gui/CartCDFWidget.cxx index 6dddb9277..91112fe96 100644 --- a/src/debugger/gui/CartCDFWidget.cxx +++ b/src/debugger/gui/CartCDFWidget.cxx @@ -28,10 +28,10 @@ CartridgeCDFWidget::CartridgeCDFWidget( : CartridgeARMWidget(boss, lfont, nfont, x, y, w, h, cart), myCart{cart} { - const int VBORDER = 8; - const int HBORDER = 2; - const int INDENT = 20; - const int VGAP = 4; + constexpr int VBORDER = 8, + HBORDER = 2, + INDENT = 20, + VGAP = 4; int xpos = HBORDER, ypos = VBORDER; @@ -64,14 +64,14 @@ CartridgeCDFWidget::CartridgeCDFWidget( "Fast Fetcher enabled"); myFastFetch->setTarget(this); myFastFetch->setEditable(false); - - int lwidth; + + int lwidth = 0; // Fast Fetch Offset if (isCDFJplus()) { ypos += myLineHeight + VGAP; - + new StaticTextWidget(_boss, _font, myFastFetch->getLeft(), ypos, "Fast Fetch Offset: "); lwidth = _font.getStringWidth("Fast Fetch Offset: "); @@ -223,8 +223,6 @@ CartridgeCDFWidget::CartridgeCDFWidget( // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCDFWidget::saveOldState() { - Int32 ds_shift = isCDFJplus() ? 8 : 12; - myOldState.fastfetchoffset.clear(); myOldState.datastreampointers.clear(); myOldState.datastreamincrements.clear(); @@ -235,8 +233,7 @@ void CartridgeCDFWidget::saveOldState() myOldState.mwavesizes.clear(); myOldState.internalram.clear(); myOldState.samplepointer.clear(); - - + if (isCDFJplus()) myOldState.fastfetchoffset.push_back(myCart.myRAM[myCart.myFastFetcherOffset]); @@ -252,7 +249,7 @@ void CartridgeCDFWidget::saveOldState() // I = Increment // F = Fractional - myOldState.datastreampointers.push_back(myCart.getDatastreamPointer(i)>>ds_shift); + myOldState.datastreampointers.push_back(myCart.getDatastreamPointer(i)>>(isCDFJplus() ? 8 : 12)); myOldState.datastreamincrements.push_back(myCart.getDatastreamIncrement(i)); } @@ -277,15 +274,14 @@ void CartridgeCDFWidget::saveOldState() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeCDFWidget::loadConfig() { - Int32 ds_shift = isCDFJplus() ? 8 : 12; + const Int32 ds_shift = isCDFJplus() ? 8 : 12; myBank->setSelectedIndex(myCart.getBank()); // Get registers, using change tracking IntArray alist; IntArray vlist; BoolArray changed; - - + if (isCDFJplus()) { alist.clear(); vlist.clear(); changed.clear(); @@ -308,7 +304,7 @@ void CartridgeCDFWidget::loadConfig() // I = Increment // F = Fractional - Int32 pointervalue = myCart.getDatastreamPointer(i) >> ds_shift; + const Int32 pointervalue = myCart.getDatastreamPointer(i) >> ds_shift; alist.push_back(0); vlist.push_back(pointervalue); changed.push_back(pointervalue != myOldState.datastreampointers[i]); } @@ -317,7 +313,7 @@ void CartridgeCDFWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 32; i < 34; ++i) { - Int32 pointervalue = myCart.getDatastreamPointer(i) >> ds_shift; + const Int32 pointervalue = myCart.getDatastreamPointer(i) >> ds_shift; alist.push_back(0); vlist.push_back(pointervalue); changed.push_back(pointervalue != myOldState.datastreampointers[i]); } @@ -331,7 +327,7 @@ void CartridgeCDFWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 0; i < ((isCDFJ() || isCDFJplus()) ? 2 : 1); ++i) { - Int32 pointervalue = myCart.getDatastreamPointer(0x21 + i) >> ds_shift; + const Int32 pointervalue = myCart.getDatastreamPointer(0x21 + i) >> ds_shift; alist.push_back(0); vlist.push_back(pointervalue); changed.push_back(pointervalue != myOldState.datastreampointers[0x21 + i]); } @@ -340,7 +336,7 @@ void CartridgeCDFWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 0; i < 32; ++i) { - Int32 incrementvalue = myCart.getDatastreamIncrement(i); + const Int32 incrementvalue = myCart.getDatastreamIncrement(i); alist.push_back(0); vlist.push_back(incrementvalue); changed.push_back(incrementvalue != myOldState.datastreamincrements[i]); } @@ -355,7 +351,7 @@ void CartridgeCDFWidget::loadConfig() alist.clear(); vlist.clear(); changed.clear(); for(int i = 0; i < ((isCDFJ() || isCDFJplus()) ? 2 : 1); ++i) { - Int32 pointervalue = myCart.getDatastreamIncrement(0x21 + i) >> ds_shift; + const Int32 pointervalue = myCart.getDatastreamIncrement(0x21 + i) >> ds_shift; alist.push_back(0); vlist.push_back(pointervalue); changed.push_back(pointervalue != myOldState.datastreamincrements[0x21 + i]); } diff --git a/src/debugger/gui/CartCMWidget.cxx b/src/debugger/gui/CartCMWidget.cxx index f2c272b8d..36ebf9a62 100644 --- a/src/debugger/gui/CartCMWidget.cxx +++ b/src/debugger/gui/CartCMWidget.cxx @@ -33,7 +33,7 @@ CartridgeCMWidget::CartridgeCMWidget( : CartDebugWidget(boss, lfont, nfont, x, y, w, h), myCart{cart} { - uInt16 size = 4 * 4096; + constexpr uInt16 size = 4 * 4096; string info = "CM cartridge, four 4K banks + 2K RAM\n" @@ -87,7 +87,7 @@ CartridgeCMWidget::CartridgeCMWidget( myIncrease->setTarget(this); myIncrease->setEditable(false); - int orig_ypos = ypos; // save for when we go to the next column + const int orig_ypos = ypos; // save for when we go to the next column // D5 (column part) ypos += myLineHeight + 4; @@ -168,7 +168,7 @@ void CartridgeCMWidget::loadConfig() RiotDebug& riot = Debugger::debugger().riotDebug(); const RiotState& state = static_cast(riot.getState()); - uInt8 swcha = myCart.mySWCHA; + const uInt8 swcha = myCart.mySWCHA; // SWCHA BoolArray oldbits, newbits, changed; diff --git a/src/debugger/gui/CartCTYWidget.cxx b/src/debugger/gui/CartCTYWidget.cxx index 0869e605a..251ca209a 100644 --- a/src/debugger/gui/CartCTYWidget.cxx +++ b/src/debugger/gui/CartCTYWidget.cxx @@ -29,7 +29,7 @@ CartridgeCTYWidget::CartridgeCTYWidget( : CartDebugWidget(boss, lfont, nfont, x, y, w, h), myCart{cart} { - uInt16 size = 8 * 4096; + constexpr uInt16 size = 8 * 4096; string info = "Chetiry cartridge, eight 4K banks (bank 0 is ARM code and is ignored)\n" @@ -37,8 +37,8 @@ CartridgeCTYWidget::CartridgeCTYWidget( " $F040 - $F07F (R), $F000 - $F03F (W)\n" "\nTHIS SCHEME IS NOT FULLY IMPLEMENTED OR TESTED\n"; - int xpos = 2, - ypos = addBaseInformation(size, "Chris D. Walton", info) + myLineHeight; + constexpr int xpos = 2; + const int ypos = addBaseInformation(size, "Chris D. Walton", info) + myLineHeight; VariantList items; VarList::push_back(items, "1 ($FFF5)"); @@ -96,7 +96,7 @@ string CartridgeCTYWidget::bankState() static constexpr std::array spot = { "", "$FFF5", "$FFF6", "$FFF7", "$FFF8", "$FFF9", "$FFFA", "$FFFB" }; - uInt16 bank = myCart.getBank(); + const uInt16 bank = myCart.getBank(); buf << "Bank = " << std::dec << bank << ", hotspot = " << spot[bank]; return buf.str(); diff --git a/src/debugger/gui/CartCVWidget.cxx b/src/debugger/gui/CartCVWidget.cxx index 5e4e8a9c4..bdd45ab04 100644 --- a/src/debugger/gui/CartCVWidget.cxx +++ b/src/debugger/gui/CartCVWidget.cxx @@ -34,8 +34,8 @@ string CartridgeCVWidget::description() { ostringstream info; - info << "CV 2K ROM + 1K RAM, non-bankswitched\n"; - info << CartridgeEnhancedWidget::description(); + info << "CV 2K ROM + 1K RAM, non-bankswitched\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartDFSCWidget.cxx b/src/debugger/gui/CartDFSCWidget.cxx index ef4282717..f7e5a819e 100644 --- a/src/debugger/gui/CartDFSCWidget.cxx +++ b/src/debugger/gui/CartDFSCWidget.cxx @@ -32,8 +32,8 @@ string CartridgeDFSCWidget::description() { ostringstream info; - info << "128K DFSC + RAM, 32 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "128K DFSC + RAM, 32 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartDFWidget.cxx b/src/debugger/gui/CartDFWidget.cxx index bfdff8282..2d3f674d2 100644 --- a/src/debugger/gui/CartDFWidget.cxx +++ b/src/debugger/gui/CartDFWidget.cxx @@ -32,8 +32,8 @@ string CartridgeDFWidget::description() { ostringstream info; - info << "128K DF, 32 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "128K DF, 32 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartDPCPlusWidget.cxx b/src/debugger/gui/CartDPCPlusWidget.cxx index afd40e81a..424558aff 100644 --- a/src/debugger/gui/CartDPCPlusWidget.cxx +++ b/src/debugger/gui/CartDPCPlusWidget.cxx @@ -28,7 +28,7 @@ CartridgeDPCPlusWidget::CartridgeDPCPlusWidget( : CartridgeARMWidget(boss, lfont, nfont, x, y, w, h, cart), myCart{cart} { - size_t size = cart.mySize; + const size_t size = cart.mySize; ostringstream info; info << "Extended DPC cartridge, six 4K banks, 4K display bank, 1K frequency table, " diff --git a/src/debugger/gui/CartDPCWidget.cxx b/src/debugger/gui/CartDPCWidget.cxx index 7946baad7..0d2dd913a 100644 --- a/src/debugger/gui/CartDPCWidget.cxx +++ b/src/debugger/gui/CartDPCWidget.cxx @@ -27,8 +27,8 @@ CartridgeDPCWidget::CartridgeDPCWidget( : CartDebugWidget(boss, lfont, nfont, x, y, w, h), myCart{cart} { - const int V_GAP = 4; - size_t size = cart.mySize; + constexpr int V_GAP = 4; + const size_t size = cart.mySize; ostringstream info; info << "DPC cartridge, two 4K banks + 2K display bank\n" @@ -38,7 +38,8 @@ CartridgeDPCWidget::CartridgeDPCWidget( << "Startup bank = " << cart.startBank() << " or undetermined\n"; // Eventually, we should query this from the debugger/disassembler - for(uInt32 i = 0, offset = 0xFFC, spot = 0xFF8; i < 2; ++i, offset += 0x1000) + constexpr uInt32 spot = 0xFF8; + for(uInt32 i = 0, offset = 0xFFC; i < 2; ++i, offset += 0x1000) { uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset]; start -= start % 0x1000; diff --git a/src/debugger/gui/CartDebugWidget.cxx b/src/debugger/gui/CartDebugWidget.cxx index 3161f9928..f00aa693f 100644 --- a/src/debugger/gui/CartDebugWidget.cxx +++ b/src/debugger/gui/CartDebugWidget.cxx @@ -46,7 +46,8 @@ int CartDebugWidget::addBaseInformation(size_t bytes, const string& manufacturer EditTextWidget* w = nullptr; ostringstream buf; - int x = 2, y = 8; + constexpr int x = 2; + int y = 8; // Add ROM size, manufacturer and bankswitch info new StaticTextWidget(_boss, _font, x, y + 1, "ROM size "); @@ -67,7 +68,7 @@ int CartDebugWidget::addBaseInformation(size_t bytes, const string& manufacturer StringParser bs(desc, (fwidth - ScrollBarWidget::scrollBarWidth(_font)) / myFontWidth - 4); const StringList& sl = bs.stringList(); - uInt32 lines = uInt32(sl.size()); + size_t lines = sl.size(); if(lines < 3) lines = 3; bool useScrollbar = false; if(lines > maxlines) @@ -78,7 +79,8 @@ int CartDebugWidget::addBaseInformation(size_t bytes, const string& manufacturer new StaticTextWidget(_boss, _font, x, y + 1, "Description "); myDesc = new StringListWidget(_boss, _nfont, x+lwidth, y - 1, - fwidth, lines * myLineHeight, false, useScrollbar); + fwidth, static_cast(lines) * myLineHeight, + false, useScrollbar); myDesc->setEditable(false); myDesc->setEnabled(false); myDesc->setList(sl); diff --git a/src/debugger/gui/CartDebugWidget.hxx b/src/debugger/gui/CartDebugWidget.hxx index 6361c875d..3046dd5d6 100644 --- a/src/debugger/gui/CartDebugWidget.hxx +++ b/src/debugger/gui/CartDebugWidget.hxx @@ -48,8 +48,8 @@ class CartDebugWidget : public Widget, public CommandSender // implement change tracking; most carts probably won't do anything here virtual void saveOldState() { } - virtual void loadConfig() override; - virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) override { } + void loadConfig() override; + void handleCommand(CommandSender* sender, int cmd, int data, int id) override { } // Query internal state of the cart (usually just bankswitching info) virtual string bankState() { return "0 (non-bankswitched)"; } diff --git a/src/debugger/gui/CartE0Widget.cxx b/src/debugger/gui/CartE0Widget.cxx index e88fe9746..3f8d7a9ec 100644 --- a/src/debugger/gui/CartE0Widget.cxx +++ b/src/debugger/gui/CartE0Widget.cxx @@ -32,8 +32,8 @@ string CartridgeE0Widget::description() { ostringstream info; - info << "E0 cartridge,\n eight 1K banks mapped into four segments\n"; - info << CartridgeEnhancedWidget::description(); + info << "E0 cartridge,\n eight 1K banks mapped into four segments\n" + << CartridgeEnhancedWidget::description(); return info.str(); } @@ -45,7 +45,7 @@ string CartridgeE0Widget::romDescription() for(int seg = 0; seg < 4; ++seg) { - uInt16 segmentOffset = seg << 10; // myCart.myBankShift; + const uInt16 segmentOffset = seg << 10; // myCart.myBankShift; info << "Segment #" << seg << " accessible @ $" << Common::Base::HEX4 << (ADDR_BASE | segmentOffset) @@ -64,11 +64,11 @@ string CartridgeE0Widget::romDescription() string CartridgeE0Widget::hotspotStr(int bank, int segment, bool noBrackets) { ostringstream info; - uInt16 hotspot = myCart.hotspot(); + const uInt16 hotspot = myCart.hotspot(); - info << (noBrackets ? "" : "("); - info << "$" << Common::Base::HEX1 << (hotspot + bank + segment * 8); - info << (noBrackets ? "" : ")"); + info << (noBrackets ? "" : "(") + << "$" << Common::Base::HEX1 << (hotspot + bank + segment * 8) + << (noBrackets ? "" : ")"); return info.str(); } diff --git a/src/debugger/gui/CartE7Widget.cxx b/src/debugger/gui/CartE7Widget.cxx index 5d6bd8d65..48ef9d333 100644 --- a/src/debugger/gui/CartE7Widget.cxx +++ b/src/debugger/gui/CartE7Widget.cxx @@ -63,11 +63,10 @@ CartridgeE7Widget::CartridgeE7Widget( void CartridgeE7Widget::initialize(GuiObject* boss, CartridgeE7& cart, ostringstream& info) { - uInt32 size = cart.romBankCount() * cart.BANK_SIZE; + const uInt32 size = cart.romBankCount() * cart.BANK_SIZE; - int xpos = 2, - ypos = addBaseInformation(size, "M Network", info.str(), 15) + - myLineHeight; + constexpr int xpos = 2; + int ypos = addBaseInformation(size, "M Network", info.str(), 15) + myLineHeight; VariantList items0, items1; for(int i = 0; i < cart.romBankCount(); ++i) diff --git a/src/debugger/gui/CartEFSCWidget.cxx b/src/debugger/gui/CartEFSCWidget.cxx index 25420af4a..f4e346e45 100644 --- a/src/debugger/gui/CartEFSCWidget.cxx +++ b/src/debugger/gui/CartEFSCWidget.cxx @@ -32,8 +32,8 @@ string CartridgeEFSCWidget::description() { ostringstream info; - info << "64K H. Runner EFSC + RAM, 16 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "64K H. Runner EFSC + RAM, 16 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartEFWidget.cxx b/src/debugger/gui/CartEFWidget.cxx index f2c929022..18940411d 100644 --- a/src/debugger/gui/CartEFWidget.cxx +++ b/src/debugger/gui/CartEFWidget.cxx @@ -32,8 +32,8 @@ string CartridgeEFWidget::description() { ostringstream info; - info << "64K H. Runner EF cartridge, 16 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "64K H. Runner EF cartridge, 16 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartEnhancedWidget.cxx b/src/debugger/gui/CartEnhancedWidget.cxx index 2cb9d4a9b..06fe8ba9b 100644 --- a/src/debugger/gui/CartEnhancedWidget.cxx +++ b/src/debugger/gui/CartEnhancedWidget.cxx @@ -123,31 +123,28 @@ string CartridgeEnhancedWidget::romDescription() else { uInt16 start = (image[myCart.mySize - 3] << 8) | image[myCart.mySize - 4]; - uInt16 end; - start -= start % std::min(int(size), 0x1000); - end = start + uInt16(myCart.mySize) - 1; + const uInt16 end = start + static_cast(myCart.mySize) - 1; // special check for ROMs where the extra RAM is not included in the image (e.g. CV). if((start & 0xFFFU) < size) { start += myCart.myRomOffset; } info << "ROM accessible @ $" - << Common::Base::HEX4 << start << " - $" - << Common::Base::HEX4 << end; + << Common::Base::HEX4 << start << " - $" + << Common::Base::HEX4 << end; } return info.str(); } - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeEnhancedWidget::plusROMInfo(int& ypos) { if(myCart.isPlusROM()) { - const int xpos = 2, - lwidth = _font.getStringWidth("Manufacturer "), + constexpr int xpos = 2; + const int lwidth = _font.getStringWidth("Manufacturer "), fwidth = _w - lwidth - 12; new StaticTextWidget(_boss, _font, xpos, ypos + 1, "PlusROM:"); @@ -201,7 +198,7 @@ void CartridgeEnhancedWidget::bankSelect(int& ypos) { if(myCart.romBankCount() > 1) { - int xpos = 2; + constexpr int xpos = 2; myBankWidgets = make_unique(bankSegs()); @@ -240,8 +237,8 @@ string CartridgeEnhancedWidget::bankState() if(myCart.romBankCount() > 1) { ostringstream& buf = buffer(); - uInt16 hotspot = myCart.hotspot(); - bool hasRamBanks = myCart.myRamBankCount > 0; + const uInt16 hotspot = myCart.hotspot(); + const bool hasRamBanks = myCart.myRamBankCount > 0; if(bankSegs() > 1) { @@ -249,8 +246,8 @@ string CartridgeEnhancedWidget::bankState() for(int seg = 0; seg < bankSegs(); ++seg) { - int bank = myCart.getSegmentBank(seg); - bool isRamBank = (bank >= myCart.romBankCount()); + const int bank = myCart.getSegmentBank(seg); + const bool isRamBank = (bank >= myCart.romBankCount()); if(seg > 0) @@ -371,7 +368,7 @@ void CartridgeEnhancedWidget::handleCommand(CommandSender* sender, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt32 CartridgeEnhancedWidget::internalRamSize() { - return uInt32(myCart.myRamSize); + return static_cast(myCart.myRamSize); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/gui/CartF0Widget.cxx b/src/debugger/gui/CartF0Widget.cxx index 378f72bd0..e806c77cf 100644 --- a/src/debugger/gui/CartF0Widget.cxx +++ b/src/debugger/gui/CartF0Widget.cxx @@ -34,8 +34,8 @@ string CartridgeF0Widget::description() ostringstream info; info << "Megaboy F0 cartridge, 16 4K banks\n" - << "Startup bank = #" << myCart.startBank() << " or undetermined\n" - << "Bankswitch triggered by accessing $" << Common::Base::HEX4 << 0xFFF0 << "\n"; + << "Startup bank = #" << myCart.startBank() << " or undetermined\n" + << "Bankswitch triggered by accessing $" << Common::Base::HEX4 << 0xFFF0 << "\n"; return info.str(); } @@ -46,7 +46,7 @@ string CartridgeF0Widget::bankState() ostringstream& buf = buffer(); buf << "Bank #" << std::dec << myCart.getBank() - << " (hotspot $" << Common::Base::HEX4 << 0xFFF0 << ")"; + << " (hotspot $" << Common::Base::HEX4 << 0xFFF0 << ")"; return buf.str(); } diff --git a/src/debugger/gui/CartF4SCWidget.cxx b/src/debugger/gui/CartF4SCWidget.cxx index e2bc91acb..3c449f366 100644 --- a/src/debugger/gui/CartF4SCWidget.cxx +++ b/src/debugger/gui/CartF4SCWidget.cxx @@ -32,8 +32,8 @@ string CartridgeF4SCWidget::description() { ostringstream info; - info << "Standard F4SC cartridge, eight 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "Standard F4SC cartridge, eight 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartF4Widget.cxx b/src/debugger/gui/CartF4Widget.cxx index c747908a1..3cfd6b83d 100644 --- a/src/debugger/gui/CartF4Widget.cxx +++ b/src/debugger/gui/CartF4Widget.cxx @@ -32,8 +32,8 @@ string CartridgeF4Widget::description() { ostringstream info; - info << "Standard F4 cartridge, eight 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "Standard F4 cartridge, eight 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartF6SCWidget.cxx b/src/debugger/gui/CartF6SCWidget.cxx index 21d2d29ce..71ae64f80 100644 --- a/src/debugger/gui/CartF6SCWidget.cxx +++ b/src/debugger/gui/CartF6SCWidget.cxx @@ -32,8 +32,8 @@ string CartridgeF6SCWidget::description() { ostringstream info; - info << "Standard F6SC cartridge, four 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "Standard F6SC cartridge, four 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartF6Widget.cxx b/src/debugger/gui/CartF6Widget.cxx index 64da287cc..7ebd67312 100644 --- a/src/debugger/gui/CartF6Widget.cxx +++ b/src/debugger/gui/CartF6Widget.cxx @@ -32,8 +32,8 @@ string CartridgeF6Widget::description() { ostringstream info; - info << "Standard F6 cartridge, four 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "Standard F6 cartridge, four 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartF8SCWidget.cxx b/src/debugger/gui/CartF8SCWidget.cxx index 891664787..456fe7488 100644 --- a/src/debugger/gui/CartF8SCWidget.cxx +++ b/src/debugger/gui/CartF8SCWidget.cxx @@ -32,8 +32,8 @@ string CartridgeF8SCWidget::description() { ostringstream info; - info << "Standard F8SC cartridge, two 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "Standard F8SC cartridge, two 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartF8Widget.cxx b/src/debugger/gui/CartF8Widget.cxx index d390a85ee..f15cf027d 100644 --- a/src/debugger/gui/CartF8Widget.cxx +++ b/src/debugger/gui/CartF8Widget.cxx @@ -32,8 +32,8 @@ string CartridgeF8Widget::description() { ostringstream info; - info << "Standard F8 cartridge, two 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "Standard F8 cartridge, two 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartFA2Widget.cxx b/src/debugger/gui/CartFA2Widget.cxx index d68bd18d0..92ce9a12b 100644 --- a/src/debugger/gui/CartFA2Widget.cxx +++ b/src/debugger/gui/CartFA2Widget.cxx @@ -25,10 +25,8 @@ CartridgeFA2Widget::CartridgeFA2Widget( : CartridgeEnhancedWidget(boss, lfont, nfont, x, y, w, h, cart), myCartFA2{cart} { - int xpos = 2, - ypos = initialize(); - - ypos += 12; + int xpos = 2; + const int ypos = initialize() + 12; const int bwidth = _font.getStringWidth("Erase") + 20; @@ -63,10 +61,10 @@ string CartridgeFA2Widget::description() { ostringstream info; - info << "Modified FA RAM+, six or seven 4K banks\n"; - info << "RAM+ can be loaded/saved to Harmony flash memory by accessing $" - << Common::Base::HEX4 << 0xFFF4 << "\n"; - info << CartridgeEnhancedWidget::description(); + info << "Modified FA RAM+, six or seven 4K banks\n" + << "RAM+ can be loaded/saved to Harmony flash memory by accessing $" + << Common::Base::HEX4 << 0xFFF4 << "\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartFAWidget.cxx b/src/debugger/gui/CartFAWidget.cxx index ff7c3f491..f86211ecb 100644 --- a/src/debugger/gui/CartFAWidget.cxx +++ b/src/debugger/gui/CartFAWidget.cxx @@ -32,8 +32,8 @@ string CartridgeFAWidget::description() { ostringstream info; - info << "CBS RAM+ FA cartridge, three 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "CBS RAM+ FA cartridge, three 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartFCWidget.cxx b/src/debugger/gui/CartFCWidget.cxx index 6105f3f39..bcd51b20f 100644 --- a/src/debugger/gui/CartFCWidget.cxx +++ b/src/debugger/gui/CartFCWidget.cxx @@ -31,15 +31,14 @@ CartridgeFCWidget::CartridgeFCWidget( string CartridgeFCWidget::description() { ostringstream info; - uInt16 hotspot = myCart.hotspot() | ADDR_BASE; + const uInt16 hotspot = myCart.hotspot() | ADDR_BASE; - info << "FC cartridge, up to eight 4K banks\n"; - info << "Bank selected by hotspots\n" - << " $" << Common::Base::HEX4 << hotspot << " (defines low 2 bits)\n" - << " $" << Common::Base::HEX4 << (hotspot + 1) << " (defines high bits)\n" - << " $" << Common::Base::HEX4 << (hotspot + 4) << " (triggers bank switch)\n"; - - info << CartridgeEnhancedWidget::description(); + info << "FC cartridge, up to eight 4K banks\n" + << "Bank selected by hotspots\n" + << " $" << Common::Base::HEX4 << hotspot << " (defines low 2 bits)\n" + << " $" << Common::Base::HEX4 << (hotspot + 1) << " (defines high bits)\n" + << " $" << Common::Base::HEX4 << (hotspot + 4) << " (triggers bank switch)\n" + << CartridgeEnhancedWidget::description(); return info.str(); } @@ -48,12 +47,12 @@ string CartridgeFCWidget::description() string CartridgeFCWidget::hotspotStr(int bank, int, bool prefix) { ostringstream info; - uInt16 hotspot = myCart.hotspot() | ADDR_BASE; + const uInt16 hotspot = myCart.hotspot() | ADDR_BASE; - info << "(" << (prefix ? "hotspots " : ""); - info << "$" << Common::Base::HEX4 << hotspot << " = " << (bank & 0b11); - info << ", $" << Common::Base::HEX4 << (hotspot + 1) << " = " << (bank >> 2); - info << ")"; + info << "(" << (prefix ? "hotspots " : "") + << "$" << Common::Base::HEX4 << hotspot << " = " << (bank & 0b11) + << ", $" << Common::Base::HEX4 << (hotspot + 1) << " = " << (bank >> 2) + << ")"; return info.str(); } diff --git a/src/debugger/gui/CartFEWidget.cxx b/src/debugger/gui/CartFEWidget.cxx index aa48b2938..60c12e284 100644 --- a/src/debugger/gui/CartFEWidget.cxx +++ b/src/debugger/gui/CartFEWidget.cxx @@ -33,9 +33,9 @@ string CartridgeFEWidget::description() ostringstream info; info << "FE (aka SCABS) cartridge, two 4K banks\n" - << "Monitors access to hotspot $01FE, and uses " - << "upper 3 bits of databus for bank number:\n"; - info << CartridgeEnhancedWidget::description(); + << "Monitors access to hotspot $01FE, and uses " + << "upper 3 bits of databus for bank number:\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartMDMWidget.cxx b/src/debugger/gui/CartMDMWidget.cxx index 17fbdc4f3..8eebfaafb 100644 --- a/src/debugger/gui/CartMDMWidget.cxx +++ b/src/debugger/gui/CartMDMWidget.cxx @@ -36,8 +36,8 @@ string CartridgeMDMWidget::description() info << "Menu Driven Megacart, " << myCart.romBankCount() << " 4K banks\n" << "Banks are selected by reading from $800 - $" << Common::Base::HEX1 << 0xBFF - << ", where the lower byte determines the 4K bank to use.\n"; - info << CartridgeEnhancedWidget::description(); + << ", where the lower byte determines the 4K bank to use.\n" + << CartridgeEnhancedWidget::description(); return info.str(); } @@ -48,7 +48,7 @@ void CartridgeMDMWidget::bankSelect(int& ypos) CartridgeEnhancedWidget::bankSelect(ypos); if(myCart.romBankCount() > 1) { - int xpos = myBankWidgets[0]->getRight() + 20; + const int xpos = myBankWidgets[0]->getRight() + 20; ypos = myBankWidgets[0]->getTop(); myBankDisabled = new CheckboxWidget(_boss, _font, xpos, ypos + 1, diff --git a/src/debugger/gui/CartRamWidget.cxx b/src/debugger/gui/CartRamWidget.cxx index 60797903c..b50ce6624 100644 --- a/src/debugger/gui/CartRamWidget.cxx +++ b/src/debugger/gui/CartRamWidget.cxx @@ -39,17 +39,18 @@ CartRamWidget::CartRamWidget( myLineHeight{lfont.getLineHeight()}, myButtonHeight{myLineHeight + 4} { - int lwidth = lfont.getStringWidth("Description "), - fwidth = w - lwidth - 20; + int lwidth = lfont.getStringWidth("Description "); + const int fwidth = w - lwidth - 20; EditTextWidget* etw = nullptr; ostringstream buf; - int xpos = 2, ypos = 8; + constexpr int xpos = 2; + int ypos = 8; // Add RAM size new StaticTextWidget(_boss, _font, xpos, ypos + 1, "RAM size "); - uInt32 ramsize = cartDebug.internalRamSize(); + const uInt32 ramsize = cartDebug.internalRamSize(); buf << ramsize << " bytes"; if(ramsize >= 1024) buf << " / " << (ramsize/1024) << "KB"; @@ -61,10 +62,10 @@ CartRamWidget::CartRamWidget( // Add Description const string& desc = cartDebug.internalRamDescription(); - const uInt16 maxlines = 6; - StringParser bs(desc, (fwidth - ScrollBarWidget::scrollBarWidth(_font)) / myFontWidth); + constexpr uInt16 maxlines = 6; + const StringParser bs(desc, (fwidth - ScrollBarWidget::scrollBarWidth(_font)) / myFontWidth); const StringList& sl = bs.stringList(); - uInt32 lines = uInt32(sl.size()); + uInt32 lines = static_cast(sl.size()); bool useScrollbar = false; if(lines < 2) lines = 2; diff --git a/src/debugger/gui/CartSBWidget.cxx b/src/debugger/gui/CartSBWidget.cxx index 52b740b3f..7870729bb 100644 --- a/src/debugger/gui/CartSBWidget.cxx +++ b/src/debugger/gui/CartSBWidget.cxx @@ -33,10 +33,10 @@ string CartridgeSBWidget::description() ostringstream info; info << "SB SUPERbanking, " << myCart.romBankCount() << " 4K banks\n" - << "Hotspots are from $800 to $" - << Common::Base::HEX2 << (0x800 + myCart.romBankCount() - 1) << ", including\n" - << "mirrors ($900, $" << 0xA00 << ", $" << 0xB00 << ", ...)\n"; - info << CartridgeEnhancedWidget::description(); + << "Hotspots are from $800 to $" + << Common::Base::HEX2 << (0x800 + myCart.romBankCount() - 1) << ", including\n" + << "mirrors ($900, $" << 0xA00 << ", $" << 0xB00 << ", ...)\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/CartTVBoyWidget.cxx b/src/debugger/gui/CartTVBoyWidget.cxx index 3b3ee18cd..02c426510 100644 --- a/src/debugger/gui/CartTVBoyWidget.cxx +++ b/src/debugger/gui/CartTVBoyWidget.cxx @@ -35,9 +35,9 @@ string CartridgeTVBoyWidget::description() ostringstream info; info << "TV Boy, " << myCart.romBankCount() << " 4K banks\n" - << "Hotspots are from $" << Common::Base::HEX2 << 0xf800 << " to $" - << Common::Base::HEX2 << (0xf800 + myCart.romBankCount() - 1) << "\n"; - info << CartridgeEnhancedWidget::description(); + << "Hotspots are from $" << Common::Base::HEX2 << 0xf800 << " to $" + << Common::Base::HEX2 << (0xf800 + myCart.romBankCount() - 1) << "\n" + << CartridgeEnhancedWidget::description(); return info.str(); } @@ -48,7 +48,7 @@ void CartridgeTVBoyWidget::bankSelect(int& ypos) CartridgeEnhancedWidget::bankSelect(ypos); if(myCart.romBankCount() > 1) { - int xpos = myBankWidgets[0]->getRight() + _font.getMaxCharWidth() * 4; + const int xpos = myBankWidgets[0]->getRight() + _font.getMaxCharWidth() * 4; ypos = myBankWidgets[0]->getTop(); myBankLocked = new CheckboxWidget(_boss, _font, xpos, ypos + 1, diff --git a/src/debugger/gui/CartUAWidget.cxx b/src/debugger/gui/CartUAWidget.cxx index 3196fc0e4..2d775f7a4 100644 --- a/src/debugger/gui/CartUAWidget.cxx +++ b/src/debugger/gui/CartUAWidget.cxx @@ -34,8 +34,9 @@ string CartridgeUAWidget::description() { ostringstream info; - info << "8K UA cartridge" << (mySwappedHotspots ? " (swapped banks)" : "") << ", two 4K banks\n"; - info << CartridgeEnhancedWidget::description(); + info << "8K UA cartridge" << (mySwappedHotspots ? " (swapped banks)" : "") + << ", two 4K banks\n" + << CartridgeEnhancedWidget::description(); return info.str(); } @@ -44,11 +45,11 @@ string CartridgeUAWidget::description() string CartridgeUAWidget::hotspotStr(int bank, int, bool prefix) { ostringstream info; - uInt16 hotspot = myCart.hotspot() + (bank ^ (mySwappedHotspots ? 1 : 0)) * myHotspotDelta; + const uInt16 hotspot = myCart.hotspot() + (bank ^ (mySwappedHotspots ? 1 : 0)) * myHotspotDelta; - info << "(" << (prefix ? "hotspot " : ""); - info << "$" << Common::Base::HEX1 << hotspot << ", $" << (hotspot | 0x80) << ", $" << (hotspot | 0xf80); - info << ")"; + info << "(" << (prefix ? "hotspot " : "") + << "$" << Common::Base::HEX1 << hotspot << ", $" << (hotspot | 0x80) + << ", $" << (hotspot | 0xf80) << ")"; return info.str(); } diff --git a/src/debugger/gui/CartWDWidget.cxx b/src/debugger/gui/CartWDWidget.cxx index 791da1b03..f877f21e9 100644 --- a/src/debugger/gui/CartWDWidget.cxx +++ b/src/debugger/gui/CartWDWidget.cxx @@ -34,10 +34,10 @@ string CartridgeWDWidget::description() ostringstream info; info << "8K + RAM Wickstead Design cartridge, \n" - << " eight 1K banks, mapped into four segments\n" - << "Hotspots $" << Common::Base::HEX1 << myCart.hotspot() << " - $" << (myCart.hotspot() + 7) << ", " - << "each hotspot selects a [predefined bank mapping]\n"; - info << ramDescription(); + << " eight 1K banks, mapped into four segments\n" + << "Hotspots $" << Common::Base::HEX1 << myCart.hotspot() << " - $" << (myCart.hotspot() + 7) << ", " + << "each hotspot selects a [predefined bank mapping]\n" + << ramDescription(); return info.str(); } @@ -46,14 +46,14 @@ string CartridgeWDWidget::description() string CartridgeWDWidget::hotspotStr(int bank, int segment, bool prefix) { ostringstream info; - CartridgeWD::BankOrg banks = myCartWD.ourBankOrg[bank]; + const CartridgeWD::BankOrg banks = myCartWD.ourBankOrg[bank]; info << "(" << (prefix ? "hotspot " : "") - << "$" << Common::Base::HEX1 << (myCart.hotspot() + bank) << ") [" - << uInt16(banks.zero) << ", " - << uInt16(banks.one) << ", " - << uInt16(banks.two) << ", " - << uInt16(banks.three) << "]"; + << "$" << Common::Base::HEX1 << (myCart.hotspot() + bank) << ") [" + << static_cast(banks.zero) << ", " + << static_cast(banks.one) << ", " + << static_cast(banks.two) << ", " + << static_cast(banks.three) << "]"; return info.str(); } diff --git a/src/debugger/gui/CartX07Widget.cxx b/src/debugger/gui/CartX07Widget.cxx index 42d193dde..b950ee373 100644 --- a/src/debugger/gui/CartX07Widget.cxx +++ b/src/debugger/gui/CartX07Widget.cxx @@ -34,8 +34,8 @@ string CartridgeX07Widget::description() info << "64K X07 cartridge, 16 4K banks\n" << "Multiple hotspots, all below $1000\n" - << "See documentation for further details\n"; - info << CartridgeEnhancedWidget::description(); + << "See documentation for further details\n" + << CartridgeEnhancedWidget::description(); return info.str(); } diff --git a/src/debugger/gui/ControllerWidget.hxx b/src/debugger/gui/ControllerWidget.hxx index 61db71545..f629934c7 100644 --- a/src/debugger/gui/ControllerWidget.hxx +++ b/src/debugger/gui/ControllerWidget.hxx @@ -42,12 +42,12 @@ class ControllerWidget : public Widget, public CommandSender, public ControllerL } ~ControllerWidget() override = default; - virtual void loadConfig() override { } + void loadConfig() override { } protected: bool isLeftPort() { - bool swappedPorts = + const bool swappedPorts = instance().console().properties().get(PropType::Console_SwapPorts) == "YES"; return (controller().jack() == Controller::Jack::Left) ^ swappedPorts; } @@ -58,7 +58,7 @@ class ControllerWidget : public Widget, public CommandSender, public ControllerL } private: - virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) override { } + void handleCommand(CommandSender* sender, int cmd, int data, int id) override { } // Following constructors and assignment operators not supported ControllerWidget() = delete; diff --git a/src/debugger/gui/CpuWidget.cxx b/src/debugger/gui/CpuWidget.cxx index e57f99d8a..f785daf83 100644 --- a/src/debugger/gui/CpuWidget.cxx +++ b/src/debugger/gui/CpuWidget.cxx @@ -39,11 +39,11 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n const int fontWidth = lfont.getMaxCharWidth(), fontHeight = lfont.getFontHeight(), lineHeight = lfont.getLineHeight(); - const int VGAP = 2; - int xpos, ypos, lwidth; + constexpr int VGAP = 2; + const int lwidth = 4 * fontWidth; // Create a 1x1 grid with label for the PC register - xpos = x; ypos = y; lwidth = 4 * fontWidth; + int xpos = x, ypos = y; new StaticTextWidget(boss, lfont, xpos, ypos + 2, lwidth-2, fontHeight, "PC ", TextAlign::Left); myPCGrid = @@ -91,8 +91,8 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n // Create labels showing the source of data for SP/A/X/Y registers const std::array labels = { "SP", "A", "X", "Y" }; xpos += myCpuGridBinValue->getWidth() + 20; - int src_y = ypos, src_w = (max_w - xpos + x) - 10; - for(int i = 0; i < 4; ++i) + const int src_w = (max_w - xpos + x) - 10; + for(int i = 0, src_y = ypos; i < 4; ++i) { myCpuDataSrc[i] = new EditTextWidget(boss, nfont, xpos, src_y, src_w, fontHeight + 1); myCpuDataSrc[i]->setToolTip("Source label of last read for " + labels[i] + "."); @@ -244,7 +244,7 @@ void CpuWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) case ToggleWidget::kItemDataChangedCmd: { - bool state = myPSRegister->getSelectedState(); + const bool state = myPSRegister->getSelectedState(); switch(data) { diff --git a/src/debugger/gui/DataGridOpsWidget.cxx b/src/debugger/gui/DataGridOpsWidget.cxx index 928447c0d..06b137bcc 100644 --- a/src/debugger/gui/DataGridOpsWidget.cxx +++ b/src/debugger/gui/DataGridOpsWidget.cxx @@ -24,13 +24,12 @@ DataGridOpsWidget::DataGridOpsWidget(GuiObject* boss, const GUI::Font& font, : Widget(boss, font, x, y, 16, 16), CommandSender(boss) { - const int bwidth = _font.getMaxCharWidth() * 4+2, - bheight = _font.getFontHeight() + 3, - space = 4; - int xpos, ypos; + const int bwidth = _font.getMaxCharWidth() * 4 + 2, + bheight = _font.getFontHeight() + 3; + constexpr int space = 4; // Create operations buttons - xpos = x; ypos = y; + int xpos = x; int ypos = y; _zeroButton = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, "0", kDGZeroCmd); _zeroButton->setToolTip("Zero currently selected value"); diff --git a/src/debugger/gui/DataGridWidget.cxx b/src/debugger/gui/DataGridWidget.cxx index ee69e0961..a18171674 100644 --- a/src/debugger/gui/DataGridWidget.cxx +++ b/src/debugger/gui/DataGridWidget.cxx @@ -115,10 +115,9 @@ void DataGridWidget::setList(const IntArray& alist, const IntArray& vlist, << ", changed.size() = " << changed.size() << ", _rows*_cols = " << _rows * _cols << endl << endl; */ - int size = int(vlist.size()); // assume the alist is the same size - assert(size == _rows * _cols); + const size_t size = vlist.size(); // assume the alist is the same size - bool dirty = _editMode + const bool dirty = _editMode || !std::equal(_valueList.begin(), _valueList.end(), vlist.begin(), vlist.end()) || !std::equal(_changedList.begin(), _changedList.end(), @@ -135,7 +134,7 @@ void DataGridWidget::setList(const IntArray& alist, const IntArray& vlist, // An efficiency thing string temp; - for(int i = 0; i < size; ++i) + for(size_t i = 0; i < size; ++i) _valueStringList.push_back(Common::Base::toString(_valueList[i], _base)); /* @@ -177,7 +176,7 @@ void DataGridWidget::setList(int a, int v) alist.push_back(a); vlist.push_back(v); - bool diff = _addrList.size() == 1 ? getSelectedValue() != v : false; + const bool diff = _addrList.size() == 1 ? getSelectedValue() != v : false; changed.push_back(diff); setList(alist, vlist, changed); @@ -229,7 +228,7 @@ void DataGridWidget::setValueInternal(int position, int value, bool changed) void DataGridWidget::setValue(int position, int value, bool changed, bool emitSignal) { - if(position >= 0 && uInt32(position) < _valueList.size()) + if(position >= 0 && position < static_cast(_valueList.size())) { // Correctly format the data for viewing editString() = Common::Base::toString(value, _base); @@ -262,7 +261,7 @@ void DataGridWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount // First check whether the selection changed int newSelectedItem; newSelectedItem = findItem(x, y); - if (newSelectedItem > int(_valueList.size()) - 1) + if (newSelectedItem > static_cast(_valueList.size()) - 1) newSelectedItem = -1; if (_selectedItem != newSelectedItem) @@ -497,7 +496,7 @@ bool DataGridWidget::handleKeyDown(StellaKey key, StellaMod mod) if (dirty) { - int oldItem = _selectedItem; + const int oldItem = _selectedItem; _selectedItem = _currentRow*_cols + _currentCol; if(_selectedItem != oldItem) @@ -641,27 +640,26 @@ bool DataGridWidget::changedToolTip(const Common::Point& oldPos, void DataGridWidget::drawWidget(bool hilite) { FBSurface& s = _boss->dialog().surface(); - int row, col; s.fillRect(_x, _y, _w, _h, hilite && isEnabled() && isEditable() ? _bgcolorhi : _bgcolor); // Draw the internal grid and labels - int linewidth = _cols * _colWidth; + const int linewidth = _cols * _colWidth; s.frameRect(_x, _y, _w, _h, hilite && isEnabled() && isEditable() ? kWidColorHi : kColor); - for(row = 1; row <= _rows-1; row++) + for(int row = 1; row <= _rows-1; row++) s.hLine(_x+1, _y + (row * _rowHeight), _x + linewidth-1, kBGColorLo); - int lineheight = _rows * _rowHeight; - for(col = 1; col <= _cols-1; col++) + const int lineheight = _rows * _rowHeight; + for(int col = 1; col <= _cols-1; col++) s.vLine(_x + (col * _colWidth), _y+1, _y + lineheight-1, kBGColorLo); // Draw the list items - for (row = 0; row < _rows; row++) + for(int row = 0; row < _rows; row++) { - for (col = 0; col < _cols; col++) + for(int col = 0; col < _cols; col++) { - int x = _x + 4 + (col * _colWidth); - int y = _y + 2 + (row * _rowHeight); - int pos = row*_cols + col; + const int x = _x + 4 + (col * _colWidth); + const int y = _y + 2 + (row * _rowHeight); + const int pos = row*_cols + col; ColorId textColor = kTextColor; // Draw the selected item inverted, on a highlighted background. @@ -785,7 +783,7 @@ void DataGridWidget::endEditMode() break; } } - int value = instance().debugger().stringToValue(editString()); + const int value = instance().debugger().stringToValue(editString()); if(value < _lowerBound || value >= _upperBound) { abortEditMode(); @@ -811,7 +809,7 @@ void DataGridWidget::abortEditMode() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DataGridWidget::negateCell() { - int mask = (1 << _bits) - 1; + const int mask = (1 << _bits) - 1; int value = getSelectedValue(); if(mask != _upperBound - 1) // ignore when values aren't byte-aligned return; @@ -823,7 +821,7 @@ void DataGridWidget::negateCell() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DataGridWidget::invertCell() { - int mask = (1 << _bits) - 1; + const int mask = (1 << _bits) - 1; int value = getSelectedValue(); if(mask != _upperBound - 1) // ignore when values aren't byte-aligned return; @@ -835,7 +833,7 @@ void DataGridWidget::invertCell() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DataGridWidget::decrementCell() { - int mask = (1 << _bits) - 1; + const int mask = (1 << _bits) - 1; int value = getSelectedValue(); if(value <= _lowerBound) // take care of wrap-around value = _upperBound; @@ -847,7 +845,7 @@ void DataGridWidget::decrementCell() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DataGridWidget::incrementCell() { - int mask = (1 << _bits) - 1; + const int mask = (1 << _bits) - 1; int value = getSelectedValue(); if(value >= _upperBound - 1) // take care of wrap-around value = _lowerBound - 1; @@ -859,7 +857,7 @@ void DataGridWidget::incrementCell() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DataGridWidget::lshiftCell() { - int mask = (1 << _bits) - 1; + const int mask = (1 << _bits) - 1; int value = getSelectedValue(); if(mask != _upperBound - 1) // ignore when values aren't byte-aligned return; @@ -871,7 +869,7 @@ void DataGridWidget::lshiftCell() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DataGridWidget::rshiftCell() { - int mask = (1 << _bits) - 1; + const int mask = (1 << _bits) - 1; int value = getSelectedValue(); if(mask != _upperBound - 1) // ignore when values aren't byte-aligned return; diff --git a/src/debugger/gui/DebuggerDialog.cxx b/src/debugger/gui/DebuggerDialog.cxx index a6f2fbc30..c5160ee99 100644 --- a/src/debugger/gui/DebuggerDialog.cxx +++ b/src/debugger/gui/DebuggerDialog.cxx @@ -138,7 +138,7 @@ void DebuggerDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated) } // handle emulation keys second (can be remapped) - Event::Type event = instance().eventHandler().eventForKey(EventMode::kEmulationMode, key, mod); + const Event::Type event = instance().eventHandler().eventForKey(EventMode::kEmulationMode, key, mod); switch (event) { case Event::ExitMode: @@ -453,7 +453,7 @@ void DebuggerDialog::addTiaArea() void DebuggerDialog::addTabArea() { const Common::Rect& r = getTabBounds(); - const int vBorder = 4; + constexpr int vBorder = 4; // The tab widget // Since there are two tab widgets in this dialog, we specifically @@ -465,10 +465,9 @@ void DebuggerDialog::addTabArea() const int widWidth = r.w() - vBorder; const int widHeight = r.h() - myTab->getTabHeight() - vBorder - 4; - int tabID; // The Prompt/console tab - tabID = myTab->addTab("Prompt"); + int tabID = myTab->addTab("Prompt"); myPrompt = new PromptWidget(myTab, *myNFont, 2, 2, widWidth - 4, widHeight); myTab->setParentWidget(tabID, myPrompt); @@ -503,11 +502,11 @@ void DebuggerDialog::addStatusArea() { const int lineHeight = myLFont->getLineHeight(); const Common::Rect& r = getStatusBounds(); - const int HBORDER = 10; + constexpr int HBORDER = 10; const int VGAP = lineHeight / 3; - int xpos, ypos; - xpos = r.x() + HBORDER; ypos = r.y(); + const int xpos = r.x() + HBORDER; + int ypos = r.y(); myTiaInfo = new TiaInfoWidget(this, *myLFont, *myNFont, xpos, ypos, r.w() - HBORDER); ypos = myTiaInfo->getBottom() + VGAP; @@ -554,9 +553,9 @@ void DebuggerDialog::addRomArea() }; const Common::Rect& r = getRomBounds(); - const int VBORDER = 4; + constexpr int VBORDER = 4; WidgetArray wid1, wid2; - ButtonWidget* b; + ButtonWidget* b = nullptr; int bwidth = myLFont->getStringWidth("Frame +1 "), bheight = myLFont->getLineHeight() + 2; @@ -620,7 +619,7 @@ void DebuggerDialog::addRomArea() DataGridOpsWidget* ops = new DataGridOpsWidget(this, *myLFont, xpos, ypos); - int max_w = xpos - r.x() - 10; + const int max_w = xpos - r.x() - 10; xpos = r.x() + 10; ypos = 5; myCpu = new CpuWidget(this, *myLFont, *myNFont, xpos, ypos, max_w); addToFocusList(myCpu->getFocusList()); @@ -644,7 +643,6 @@ void DebuggerDialog::addRomArea() xpos = r.x() + VBORDER; ypos += myRam->getHeight() + 5; const int tabWidth = r.w() - VBORDER - 1; const int tabHeight = r.h() - ypos - 1; - int tabID; // Since there are two tab widgets in this dialog, we specifically // assign an ID of 1 @@ -654,7 +652,7 @@ void DebuggerDialog::addRomArea() addTabWidget(myRomTab); // The main disassembly tab - tabID = myRomTab->addTab(" Disassembly ", TabWidget::AUTO_WIDTH); + int tabID = myRomTab->addTab(" Disassembly ", TabWidget::AUTO_WIDTH); myRom = new RomWidget(myRomTab, *myLFont, *myNFont, 2, 2, tabWidth - 1, tabHeight - myRomTab->getTabHeight() - 2); myRom->setHelpAnchor("Disassembly", true); @@ -708,7 +706,8 @@ void DebuggerDialog::addRomArea() Common::Rect DebuggerDialog::getTiaBounds() const { // The area showing the TIA image (NTSC and PAL supported, up to 274 lines without scaling) - return Common::Rect(0, 0, 320, std::max(int(FrameManager::Metrics::baseHeightPAL), int(_h * 0.35))); + return Common::Rect(0, 0, 320, std::max(static_cast(FrameManager::Metrics::baseHeightPAL), + static_cast(_h * 0.35))); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -727,12 +726,11 @@ Common::Rect DebuggerDialog::getStatusBounds() const // 30% of any space above 1030 pixels will be allocated to this area const Common::Rect& tia = getTiaBounds(); - int x1 = tia.x() + tia.w() + 1; - int y1 = 0; - int x2 = tia.x() + tia.w() + 225 + (_w > 1030 ? int(0.35 * (_w - 1030)) : 0); - int y2 = tia.y() + tia.h(); - - return Common::Rect(x1, y1, x2, y2); + return Common::Rect( + tia.x() + tia.w() + 1, + 0, + tia.x() + tia.w() + 225 + (_w > 1030 ? int(0.35 * (_w - 1030)) : 0), + tia.y() + tia.h()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/gui/DelayQueueWidget.cxx b/src/debugger/gui/DelayQueueWidget.cxx index eb29b1ab8..e871f99cf 100644 --- a/src/debugger/gui/DelayQueueWidget.cxx +++ b/src/debugger/gui/DelayQueueWidget.cxx @@ -101,8 +101,8 @@ void DelayQueueWidget::drawWidget(bool hilite) int y = _y, x = _x, - w = _w, - lineHeight = _font.getLineHeight(); + w = _w; + const int lineHeight = _font.getLineHeight(); surface.frameRect(x, y, w, _h, kColor); diff --git a/src/debugger/gui/FlashWidget.cxx b/src/debugger/gui/FlashWidget.cxx index 4430aea18..90ee71dd6 100644 --- a/src/debugger/gui/FlashWidget.cxx +++ b/src/debugger/gui/FlashWidget.cxx @@ -59,7 +59,7 @@ void FlashWidget::init(GuiObject* boss, const GUI::Font& font, xpos -= 8; ypos += 2; myEEPROMEraseCurrent = new ButtonWidget(boss, font, xpos, ypos, - embedded ? "Erase" : "Erase used pages", + embedded ? "Erase" : "Erase used pages", kEEPROMEraseCurrent); myEEPROMEraseCurrent->setTarget(this); @@ -90,8 +90,8 @@ void FlashWidget::loadConfig() { if(startPage != -1) { - int from = startPage * MT24LC256::PAGE_SIZE; - int to = page * MT24LC256::PAGE_SIZE - 1; + const int from = startPage * MT24LC256::PAGE_SIZE; + const int to = page * MT24LC256::PAGE_SIZE - 1; ostringstream label; label.str(""); @@ -99,7 +99,7 @@ void FlashWidget::loadConfig() if(!myEmbedded) { - if(int(page) - 1 != startPage) + if(static_cast(page) - 1 != startPage) label << "-" << Common::Base::HEX3 << page - 1; else label << " "; diff --git a/src/debugger/gui/KeyboardWidget.cxx b/src/debugger/gui/KeyboardWidget.cxx index 201b9e57a..f3166316d 100644 --- a/src/debugger/gui/KeyboardWidget.cxx +++ b/src/debugger/gui/KeyboardWidget.cxx @@ -23,7 +23,7 @@ KeyboardWidget::KeyboardWidget(GuiObject* boss, const GUI::Font& font, int x, int y, Controller& controller) : ControllerWidget(boss, font, x, y, controller) { - bool leftport = isLeftPort(); + const bool leftport = isLeftPort(); const string& label = leftport ? "Left (Keyboard)" : "Right (Keyboard)"; const int fontHeight = font.getFontHeight(); diff --git a/src/debugger/gui/PaddleWidget.cxx b/src/debugger/gui/PaddleWidget.cxx index f2d0d0f00..19bf4b247 100644 --- a/src/debugger/gui/PaddleWidget.cxx +++ b/src/debugger/gui/PaddleWidget.cxx @@ -23,7 +23,7 @@ PaddleWidget::PaddleWidget(GuiObject* boss, const GUI::Font& font, int x, int y, Controller& controller, bool embedded, bool second) : ControllerWidget(boss, font, x, y, controller) { - bool leftport = isLeftPort(); + const bool leftport = isLeftPort(); const string& label = getHeader(); const int fontHeight = font.getFontHeight(); @@ -86,15 +86,15 @@ PaddleWidget::PaddleWidget(GuiObject* boss, const GUI::Font& font, int x, int y, "Fire", kP1Fire); } myP0Resistance->setMinValue(0); - myP0Resistance->setMaxValue(uInt32(Paddles::MAX_RESISTANCE)); - myP0Resistance->setStepValue(uInt32(Paddles::MAX_RESISTANCE/100)); + myP0Resistance->setMaxValue(uInt32{Paddles::MAX_RESISTANCE}); + myP0Resistance->setStepValue(uInt32{Paddles::MAX_RESISTANCE / 100}); myP0Resistance->setTarget(this); myP0Fire->setTarget(this); myP1Resistance->setMinValue(0); - myP1Resistance->setMaxValue(uInt32(Paddles::MAX_RESISTANCE)); - myP1Resistance->setStepValue(uInt32(Paddles::MAX_RESISTANCE/100)); + myP1Resistance->setMaxValue(uInt32{Paddles::MAX_RESISTANCE}); + myP1Resistance->setStepValue(uInt32{Paddles::MAX_RESISTANCE / 100}); myP1Resistance->setTarget(this); myP1Fire->setTarget(this); @@ -108,9 +108,9 @@ PaddleWidget::PaddleWidget(GuiObject* boss, const GUI::Font& font, int x, int y, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PaddleWidget::loadConfig() { - myP0Resistance->setValue(Int32(Paddles::MAX_RESISTANCE - + myP0Resistance->setValue(static_cast(Paddles::MAX_RESISTANCE - getPin(Controller::AnalogPin::Nine).resistance)); - myP1Resistance->setValue(Int32(Paddles::MAX_RESISTANCE - + myP1Resistance->setValue(static_cast(Paddles::MAX_RESISTANCE - getPin(Controller::AnalogPin::Five).resistance)); myP0Fire->setState(!getPin(Controller::DigitalPin::Four)); myP1Fire->setState(!getPin(Controller::DigitalPin::Three)); diff --git a/src/debugger/gui/PointingDeviceWidget.cxx b/src/debugger/gui/PointingDeviceWidget.cxx index 5e39719cc..ca06d777f 100644 --- a/src/debugger/gui/PointingDeviceWidget.cxx +++ b/src/debugger/gui/PointingDeviceWidget.cxx @@ -19,15 +19,16 @@ #include "DataGridWidget.hxx" #include "PointingDeviceWidget.hxx" +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PointingDeviceWidget::PointingDeviceWidget(GuiObject* boss, const GUI::Font& font, int x, int y, Controller& controller) : ControllerWidget(boss, font, x, y, controller) { int ypos = y; - int xLeft = x + 10; - int xMid = xLeft + 30; - int xRight = xLeft + 60; - int xValue = xLeft + 87; + const int xLeft = x + 10, + xMid = xLeft + 30, + xRight = xLeft + 60, + xValue = xLeft + 87; StaticTextWidget* t; t = new StaticTextWidget(boss, font, x, y + 2, getHeader()); @@ -142,7 +143,7 @@ void PointingDeviceWidget::setGrayCodeV() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PointingDeviceWidget::setValue(DataGridWidget* grayValue, const int index, const int direction) { - uInt8 grayCode = getGrayCodeTable(index, direction); + const uInt8 grayCode = getGrayCodeTable(index, direction); // FIXME * 8 = a nasty hack, because the DataGridWidget does not support 2 digit binary output grayValue->setList(0, (grayCode & 0b01) + (grayCode & 0b10) * 8); diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index 1edeb8e2e..ea5897160 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -72,27 +72,27 @@ PromptWidget::PromptWidget(GuiObject* boss, const GUI::Font& font, void PromptWidget::drawWidget(bool hilite) { //cerr << "PromptWidget::drawWidget\n"; - ColorId fgcolor, bgcolor; + ColorId fgcolor{}, bgcolor{}; FBSurface& s = _boss->dialog().surface(); // Draw text - int start = _scrollLine - _linesPerPage + 1; + const int start = _scrollLine - _linesPerPage + 1; int y = _y + 2; for (int line = 0; line < _linesPerPage; ++line) { int x = _x + 1; for (int column = 0; column < _lineWidth; ++column) { - int c = buffer((start + line) * _lineWidth + column); + const int c = buffer((start + line) * _lineWidth + column); if(c & (1 << 17)) // inverse video flag { fgcolor = _bgcolor; - bgcolor = ColorId((c & 0x1ffff) >> 8); + bgcolor = static_cast((c & 0x1ffff) >> 8); s.fillRect(x, y, _kConsoleCharWidth, _kConsoleCharHeight, bgcolor); } else - fgcolor = ColorId(c >> 8); + fgcolor = static_cast(c >> 8); s.drawChar(_font, c & 0x7f, x, y, fgcolor); x += _kConsoleCharWidth; @@ -356,7 +356,7 @@ void PromptWidget::handleCommand(CommandSender* sender, int cmd, { if(cmd == GuiObject::kSetPositionCmd) { - int newPos = int(data) + _linesPerPage - 1 + _firstLineInBuffer; + const int newPos = data + _linesPerPage - 1 + _firstLineInBuffer; if (newPos != _scrollLine) { _scrollLine = newPos; @@ -461,7 +461,7 @@ void PromptWidget::killLine(int direction) { if(direction == -1) // erase from current position to beginning of line { - int count = _currentPos - _promptStartPos; + const int count = _currentPos - _promptStartPos; if(count > 0) for (int i = 0; i < count; i++) killChar(-1); @@ -564,9 +564,9 @@ int PromptWidget::historyDir(int& index, int direction) { index += direction; if(index < 0) - index += int(_history.size()); + index += static_cast(_history.size()); else - index %= int(_history.size()); + index %= static_cast(_history.size()); return index; } @@ -574,7 +574,7 @@ int PromptWidget::historyDir(int& index, int direction) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PromptWidget::historyAdd(const string& entry) { - if(_historyIndex >= int(_history.size())) + if(_historyIndex >= static_cast(_history.size())) _history.push_back(entry); else _history[_historyIndex] = entry; @@ -587,7 +587,7 @@ void PromptWidget::addToHistory(const char* str) if(_history.size()) { int i = _historyIndex; - int historyEnd = _historyIndex % _history.size(); + const int historyEnd = _historyIndex % _history.size(); do { @@ -632,8 +632,8 @@ bool PromptWidget::historyScroll(int direction) // Search the history using the original input do { - int idx = _historyLine - ? (_historyIndex - _historyLine + _history.size()) % int(_history.size()) + const int idx = _historyLine + ? (_historyIndex - _historyLine + _history.size()) % static_cast(_history.size()) : _historyIndex; if(BSPF::startsWithIgnoreCase(_history[idx], _history[_historyIndex])) @@ -652,8 +652,8 @@ bool PromptWidget::historyScroll(int direction) scrollToCurrent(); // Print the text from the history - int idx = _historyLine - ? (_historyIndex - _historyLine + _history.size()) % int(_history.size()) + const int idx = _historyLine + ? (_historyIndex - _historyLine + _history.size()) % static_cast(_history.size()) : _historyIndex; for(int i = 0; i < kLineBufferSize && _history[idx][i] != '\0'; i++) @@ -672,7 +672,7 @@ bool PromptWidget::execute() nextLine(); assert(_promptEndPos >= _promptStartPos); - int len = _promptEndPos - _promptStartPos; + const int len = _promptEndPos - _promptStartPos; if(len > 0) { @@ -716,7 +716,7 @@ bool PromptWidget::autoComplete(int direction) int len = _promptEndPos - _promptStartPos; if(_tabCount != -1) - len = int(strlen(_inputStr)); + len = static_cast(strlen(_inputStr)); if(len > kLineBufferSize - 1) len = kLineBufferSize - 1; @@ -745,7 +745,7 @@ bool PromptWidget::autoComplete(int direction) instance().debugger().parser().getCompletions(_inputStr, list); else { - size_t strLen = len - lastDelimPos - 1; + const size_t strLen = len - lastDelimPos - 1; // do not show ALL commands/labels without any filter as it makes no sense if(strLen > 0) { @@ -770,7 +770,7 @@ bool PromptWidget::autoComplete(int direction) if(direction < 0) { if(--_tabCount < 0) - _tabCount = int(list.size()) - 1; + _tabCount = static_cast(list.size()) - 1; } else _tabCount = (_tabCount + 1) % list.size(); @@ -800,7 +800,7 @@ void PromptWidget::nextLine() _textcolor = kTextColor; _inverse = false; - int line = _currentPos / _lineWidth; + const int line = _currentPos / _lineWidth; if (line == _scrollLine) _scrollLine++; @@ -813,10 +813,10 @@ void PromptWidget::nextLine() // Call this (at least) when the current line changes or when a new line is added void PromptWidget::updateScrollBuffer() { - int lastchar = std::max(_promptEndPos, _currentPos); - int line = lastchar / _lineWidth; - int numlines = (line < _linesInBuffer) ? line + 1 : _linesInBuffer; - int firstline = line - numlines + 1; + const int lastchar = std::max(_promptEndPos, _currentPos), + line = lastchar / _lineWidth, + numlines = (line < _linesInBuffer) ? line + 1 : _linesInBuffer, + firstline = line - numlines + 1; if (firstline > _firstLineInBuffer) { @@ -840,7 +840,7 @@ int PromptWidget::printf(const char* format, ...) // NOLINT va_list argptr; va_start(argptr, format); - int count = this->vprintf(format, argptr); + const int count = this->vprintf(format, argptr); va_end (argptr); return count; } @@ -849,7 +849,7 @@ int PromptWidget::printf(const char* format, ...) // NOLINT int PromptWidget::vprintf(const char* format, va_list argptr) { char buf[2048]; // NOLINT (will be rewritten soon) - int count = std::vsnprintf(buf, sizeof(buf), format, argptr); + const int count = std::vsnprintf(buf, sizeof(buf), format, argptr); print(buf); return count; @@ -862,11 +862,11 @@ void PromptWidget::putcharIntern(int c) nextLine(); else if(c & 0x80) { // set foreground color to TIA color // don't print or advance cursor - _textcolor = ColorId((c & 0x7f) << 1); + _textcolor = static_cast((c & 0x7f) << 1); } else if(c && c < 0x1e) { // first actual character is large dash // More colors (the regular GUI ones) - _textcolor = ColorId(c + 0x100); + _textcolor = static_cast(c + 0x100); } else if(c == 0x7f) { // toggle inverse video (DEL char) _inverse = !_inverse; @@ -887,7 +887,7 @@ void PromptWidget::putcharIntern(int c) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PromptWidget::print(const string& str) { - for(char c: str) + for(const auto c: str) putcharIntern(c); } @@ -896,17 +896,17 @@ void PromptWidget::drawCaret() { //cerr << "PromptWidget::drawCaret()\n"; FBSurface& s = _boss->dialog().surface(); - int line = _currentPos / _lineWidth; + const int line = _currentPos / _lineWidth; // Don't draw the cursor if it's not in the current view if(_scrollLine < line) return; - int displayLine = line - _scrollLine + _linesPerPage - 1; - int x = _x + 1 + (_currentPos % _lineWidth) * _kConsoleCharWidth; - int y = _y + displayLine * _kConsoleLineHeight; + const int displayLine = line - _scrollLine + _linesPerPage - 1, + x = _x + 1 + (_currentPos % _lineWidth) * _kConsoleCharWidth, + y = _y + displayLine * _kConsoleLineHeight; - char c = buffer(_currentPos); //FIXME: int to char?? + const char c = buffer(_currentPos); //FIXME: int to char?? s.fillRect(x, y, _kConsoleCharWidth, _kConsoleLineHeight, kTextColor); s.drawChar(_font, c, x, y + 2, kBGColor); } @@ -914,7 +914,7 @@ void PromptWidget::drawCaret() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PromptWidget::scrollToCurrent() { - int line = _promptEndPos / _lineWidth; + const int line = _promptEndPos / _lineWidth; if (line + _linesPerPage <= _scrollLine) { @@ -936,13 +936,13 @@ string PromptWidget::saveBuffer(const FilesystemNode& file) int end = start + _lineWidth - 1; // Look for first non-space, printing char from end of line - while( char(_buffer[end] & 0xff) <= ' ' && end >= start) + while(static_cast(_buffer[end] & 0xff) <= ' ' && end >= start) end--; // Spit out the line minus its trailing junk // Strip off any color/inverse bits for(int j = start; j <= end; ++j) - out << char(_buffer[j] & 0xff); + out << static_cast(_buffer[j] & 0xff); // add a \n out << endl; diff --git a/src/debugger/gui/QuadTariWidget.cxx b/src/debugger/gui/QuadTariWidget.cxx index 8892f21e8..4c4b0f78a 100644 --- a/src/debugger/gui/QuadTariWidget.cxx +++ b/src/debugger/gui/QuadTariWidget.cxx @@ -34,8 +34,8 @@ QuadTariWidget::QuadTariWidget(GuiObject* boss, const GUI::Font& font, : ControllerWidget(boss, font, x, y, controller) { string label = (isLeftPort() ? "Left" : "Right") + string(" (QuadTari)"); - StaticTextWidget* t = new StaticTextWidget(boss, font, x, y + 2, label); - QuadTari& qt = static_cast(controller); + const StaticTextWidget* t = new StaticTextWidget(boss, font, x, y + 2, label); + const QuadTari& qt = static_cast(controller); y = t->getBottom() + _lineHeight; addController(boss, x, y, *qt.myFirstController, false); @@ -49,7 +49,7 @@ QuadTariWidget::QuadTariWidget(GuiObject* boss, const GUI::Font& font, void QuadTariWidget::addController(GuiObject* boss, int x, int y, Controller& controller, bool second) { - ControllerWidget* widget; + ControllerWidget* widget = nullptr; x += second ? _fontWidth * 10 : 0; switch(controller.type()) @@ -87,7 +87,7 @@ void QuadTariWidget::addController(GuiObject* boss, int x, int y, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void QuadTariWidget::loadConfig() { - bool first = !(instance().console().tia().registerValue(VBLANK) & 0x80); + const bool first = !(instance().console().tia().registerValue(VBLANK) & 0x80); myPointer->setLabel(first ? "<-" : "->"); } diff --git a/src/debugger/gui/RamWidget.cxx b/src/debugger/gui/RamWidget.cxx index c91acf5b2..15ef6f314 100644 --- a/src/debugger/gui/RamWidget.cxx +++ b/src/debugger/gui/RamWidget.cxx @@ -47,14 +47,14 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n bheight = myLineHeight + 2; //const int VGAP = 4; const int VGAP = myFontHeight / 4; - StaticTextWidget* s; + StaticTextWidget* s = nullptr; WidgetArray wid; int ypos = y + myLineHeight; // Add RAM grid (with scrollbar) int xpos = x + _font.getStringWidth("xxxx"); - bool useScrollbar = ramsize / numrows > 16; + const bool useScrollbar = ramsize / numrows > 16; myRamGrid = new DataGridRamWidget(_boss, *this, _nfont, xpos, ypos, 16, myNumRows, 2, 8, Common::Base::Fmt::_16, useScrollbar); myRamGrid->setHelpAnchor(helpAnchor, true); @@ -63,7 +63,7 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n addFocusWidget(myRamGrid); // Create actions buttons to the left of the RAM grid - int bx = xpos + myRamGrid->getWidth() + 4; + const int bx = xpos + myRamGrid->getWidth() + 4; int by = ypos; myUndoButton = new ButtonWidget(boss, lfont, bx, by, bwidth, bheight, @@ -168,7 +168,7 @@ RamWidget::RamWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n addFocusWidget(myBinValue); // Add Label of selected RAM cell - int xpos_r = xpos - myFontWidth * 1.5; + const int xpos_r = xpos - myFontWidth * 1.5; xpos = x; s = new StaticTextWidget(boss, lfont, xpos, ypos, "Label"); xpos = s->getRight() + myFontWidth / 2; @@ -232,7 +232,7 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) break; } - uInt8 oldval = getValue(addr); + const uInt8 oldval = getValue(addr); setValue(addr, value); myUndoAddress = addr; @@ -252,7 +252,7 @@ void RamWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) { addr = myRamGrid->getSelectedAddr(); value = myRamGrid->getSelectedValue(); - bool changed = myRamGrid->getSelectedChanged(); + const bool changed = myRamGrid->getSelectedChanged(); myLabel->setText(getLabel(addr)); myHexValue->setValueInternal(0, value, changed); @@ -330,8 +330,8 @@ void RamWidget::loadConfig() { fillGrid(true); - int value = myRamGrid->getSelectedValue(); - bool changed = myRamGrid->getSelectedChanged(); + const int value = myRamGrid->getSelectedValue(); + const bool changed = myRamGrid->getSelectedChanged(); myHexValue->setValueInternal(0, value, changed); myDecValue->setValueInternal(0, value, changed); @@ -345,7 +345,7 @@ void RamWidget::fillGrid(bool updateOld) IntArray vlist; BoolArray changed; - uInt32 start = myCurrentRamBank * myPageSize; + const uInt32 start = myCurrentRamBank * myPageSize; fillList(start, myPageSize, alist, vlist, changed); if(updateOld) @@ -360,7 +360,8 @@ void RamWidget::fillGrid(bool updateOld) } // Update RAM labels - uInt32 rport = readPort(start), page = rport & 0xf0; + const uInt32 rport = readPort(start); + int page = rport & 0xf0; string label = Common::Base::toString(rport, Common::Base::Fmt::_16_4); label[2] = label[3] = 'x'; @@ -373,8 +374,8 @@ void RamWidget::fillGrid(bool updateOld) void RamWidget::showInputBox(int cmd) { // Add inputbox in the middle of the RAM widget - uInt32 x = getAbsX() + ((getWidth() - myInputBox->getWidth()) >> 1); - uInt32 y = getAbsY() + ((getHeight() - myInputBox->getHeight()) >> 1); + const uInt32 x = getAbsX() + ((getWidth() - myInputBox->getWidth()) >> 1); + const uInt32 y = getAbsY() + ((getHeight() - myInputBox->getHeight()) >> 1); myInputBox->show(x, y, dialog().surface().dstRect()); myInputBox->setText(""); @@ -403,7 +404,7 @@ string RamWidget::doSearch(const string& str) return "Invalid input +|-"; } - int searchVal = instance().debugger().stringToValue(str); + const int searchVal = instance().debugger().stringToValue(str); // Clear the search array of previous items mySearchAddr.clear(); @@ -416,7 +417,7 @@ string RamWidget::doSearch(const string& str) bool hitfound = false; for(uInt32 addr = 0; addr < ram.size(); ++addr) { - int value = ram[addr]; + const int value = ram[addr]; if(comparisonSearch && searchVal != value) { mySearchState.push_back(false); @@ -454,7 +455,7 @@ string RamWidget::doCompare(const string& str) return "Enter an absolute or comparative value"; // Do some pre-processing on the string - string::size_type pos = str.find_first_of("+-", 0); + const string::size_type pos = str.find_first_of("+-", 0); if(pos > 0 && pos != string::npos) { // Only accept '+' or '-' at the start of the string @@ -496,7 +497,7 @@ string RamWidget::doCompare(const string& str) continue; } - int addr = mySearchAddr[i]; + const int addr = mySearchAddr[i]; if(ram[addr] == searchVal) { tempAddrList.push_back(addr); @@ -541,7 +542,7 @@ void RamWidget::showSearchResults() { // Only update the search results for the bank currently being shown BoolArray temp; - uInt32 start = myCurrentRamBank * myPageSize; + const uInt32 start = myCurrentRamBank * myPageSize; if(mySearchState.size() == 0 || start > mySearchState.size()) { for(uInt32 i = 0; i < myPageSize; ++i) diff --git a/src/debugger/gui/RiotWidget.cxx b/src/debugger/gui/RiotWidget.cxx index 0cea94899..9dfa26c0a 100644 --- a/src/debugger/gui/RiotWidget.cxx +++ b/src/debugger/gui/RiotWidget.cxx @@ -54,7 +54,7 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, fontHeight = lfont.getFontHeight(), lineHeight = lfont.getLineHeight(); int xpos = 10, ypos = 25, lwidth = 8 * fontWidth, col = 0; - StaticTextWidget* t; + StaticTextWidget* t = nullptr; VariantList items; // Set the strings to be used in the various bit registers @@ -221,7 +221,7 @@ RiotWidget::RiotWidget(GuiObject* boss, const GUI::Font& lfont, int pwidth = lfont.getStringWidth("B/easy"); lwidth = lfont.getStringWidth("Right Diff "); xpos = col; ypos += 2 * lineHeight; - int col2_ypos = ypos; + const int col2_ypos = ypos; items.clear(); VarList::push_back(items, "B/easy", "b"); VarList::push_back(items, "A/hard", "a"); diff --git a/src/debugger/gui/RomListSettings.cxx b/src/debugger/gui/RomListSettings.cxx index 626e5a4c5..f2db82980 100644 --- a/src/debugger/gui/RomListSettings.cxx +++ b/src/debugger/gui/RomListSettings.cxx @@ -92,7 +92,7 @@ RomListSettings::RomListSettings(GuiObject* boss, const GUI::Font& font) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RomListSettings::show(uInt32 x, uInt32 y, const Common::Rect& bossRect, int data) { - uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); + const uInt32 scale = instance().frameBuffer().hidpiScaleFactor(); _xorig = bossRect.x() + x * scale; _yorig = bossRect.y() + y * scale; diff --git a/src/debugger/gui/RomListWidget.cxx b/src/debugger/gui/RomListWidget.cxx index ac27421b0..b045868fe 100644 --- a/src/debugger/gui/RomListWidget.cxx +++ b/src/debugger/gui/RomListWidget.cxx @@ -127,8 +127,8 @@ void RomListWidget::setList(const CartDebug::Disassembly& disasm) myCheckList[i]->setFlags(Widget::FLAG_ENABLED); // Then turn off any extras - if(int(myDisasm->list.size()) < _rows) - for(int i = int(myDisasm->list.size()); i < _rows; ++i) + if(static_cast(myDisasm->list.size()) < _rows) + for(int i = static_cast(myDisasm->list.size()); i < _rows; ++i) myCheckList[i]->clearFlags(Widget::FLAG_ENABLED); recalc(); @@ -137,7 +137,7 @@ void RomListWidget::setList(const CartDebug::Disassembly& disasm) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RomListWidget::setSelected(int item) { - if(item < -1 || item >= int(myDisasm->list.size())) + if(item < -1 || item >= static_cast(myDisasm->list.size())) return; if(isEnabled()) @@ -153,7 +153,7 @@ void RomListWidget::setSelected(int item) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RomListWidget::setHighlighted(int item) { - if(item < -1 || item >= int(myDisasm->list.size())) + if(item < -1 || item >= static_cast(myDisasm->list.size())) return; if(isEnabled()) @@ -186,7 +186,7 @@ int RomListWidget::findItem(int x, int y) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void RomListWidget::recalc() { - int size = int(myDisasm->list.size()); + const int size = static_cast(myDisasm->list.size()); if (_currentPos >= size) _currentPos = size - 1; @@ -198,7 +198,7 @@ void RomListWidget::recalc() _editMode = false; - myScrollBar->_numEntries = int(myDisasm->list.size()); + myScrollBar->_numEntries = static_cast(myDisasm->list.size()); myScrollBar->_entriesPerPage = _rows; // Reset to normal data entry @@ -222,7 +222,7 @@ void RomListWidget::scrollToCurrent(int item) _currentPos = item - _rows + 1; } - int size = int(myDisasm->list.size()); + const int size = static_cast(myDisasm->list.size()); if (_currentPos < 0 || _rows > size) _currentPos = 0; else if (_currentPos + _rows > size) @@ -256,7 +256,7 @@ void RomListWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) // First check whether the selection changed int newSelectedItem; newSelectedItem = findItem(x, y); - if (newSelectedItem > int(myDisasm->list.size()) - 1) + if (newSelectedItem > static_cast(myDisasm->list.size()) - 1) newSelectedItem = -1; if (_selectedItem != newSelectedItem) @@ -307,7 +307,7 @@ bool RomListWidget::handleKeyDown(StellaKey key, StellaMod mod) return false; bool handled = true; - int oldSelectedItem = _selectedItem; + const int oldSelectedItem = _selectedItem; if (_editMode) { @@ -357,7 +357,7 @@ bool RomListWidget::handleEvent(Event::Type e) return false; bool handled = true; - int oldSelectedItem = _selectedItem; + const int oldSelectedItem = _selectedItem; switch(e) { @@ -375,7 +375,7 @@ bool RomListWidget::handleEvent(Event::Type e) break; case Event::UIDown: - if (_selectedItem < int(myDisasm->list.size()) - 1) + if (_selectedItem < static_cast(myDisasm->list.size()) - 1) _selectedItem++; break; @@ -387,8 +387,8 @@ bool RomListWidget::handleEvent(Event::Type e) case Event::UIPgDown: _selectedItem += _rows - 1; - if (_selectedItem >= int(myDisasm->list.size())) - _selectedItem = int(myDisasm->list.size()) - 1; + if (_selectedItem >= static_cast(myDisasm->list.size())) + _selectedItem = static_cast(myDisasm->list.size()) - 1; break; case Event::UIHome: @@ -396,7 +396,7 @@ bool RomListWidget::handleEvent(Event::Type e) break; case Event::UIEnd: - _selectedItem = int(myDisasm->list.size()) - 1; + _selectedItem = static_cast(myDisasm->list.size()) - 1; break; default: @@ -454,7 +454,7 @@ Common::Point RomListWidget::getToolTipIndex(const Common::Point& pos) const const int row = (pos.y - getAbsY()) / _lineHeight; if(col < 0 || col >= 8 - || row < 0 || row + _currentPos >= int(myDisasm->list.size())) + || row < 0 || row + _currentPos >= static_cast(myDisasm->list.size())) return Common::Point(-1, -1); else return Common::Point(col, row + _currentPos); @@ -473,7 +473,7 @@ string RomListWidget::getToolTip(const Common::Point& pos) const if(static_cast(bytes.length()) < idx.x + 1) return EmptyString; - Int32 val; + Int32 val = 0; if(bytes.length() == 8 && bytes[2] != ' ') { // Binary value @@ -524,8 +524,7 @@ void RomListWidget::drawWidget(bool hilite) { FBSurface& s = _boss->dialog().surface(); const CartDebug::DisassemblyList& dlist = myDisasm->list; - int i, pos, xpos, ypos, len = int(dlist.size()); - ColorId textColor = kTextColor; + constexpr ColorId textColor = kTextColor; const Common::Rect& r = getEditRect(); const Common::Rect& l = getLineRect(); @@ -535,16 +534,16 @@ void RomListWidget::drawWidget(bool hilite) s.vLine(_x + CheckboxWidget::boxSize(_font) + 5, _y, _y + _h - 1, kColor); // Draw the list items - int cycleCountW = _fontWidth * 8, + const int cycleCountW = _fontWidth * 8, noTypeDisasmW = _w - l.x() - _labelWidth, noCodeDisasmW = noTypeDisasmW - r.w(), - codeDisasmW = noCodeDisasmW - cycleCountW, - actualWidth = myDisasm->fieldwidth * _fontWidth; - if(actualWidth < codeDisasmW) - codeDisasmW = actualWidth; + actualWidth = myDisasm->fieldwidth * _fontWidth, + codeDisasmW = std::min(actualWidth, noCodeDisasmW - cycleCountW); - xpos = _x + CheckboxWidget::boxSize(_font) + 10; ypos = _y + 2; - for(i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++, ypos += _lineHeight) + const int len = static_cast(dlist.size()); + const int xpos = _x + CheckboxWidget::boxSize(_font) + 10; + int ypos = _y + 2; + for(int i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++, ypos += _lineHeight) { ColorId bytesColor = textColor; diff --git a/src/debugger/gui/RomWidget.cxx b/src/debugger/gui/RomWidget.cxx index 1d8248257..8d4a74433 100644 --- a/src/debugger/gui/RomWidget.cxx +++ b/src/debugger/gui/RomWidget.cxx @@ -36,13 +36,11 @@ RomWidget::RomWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n : Widget(boss, lfont, x, y, w, h), CommandSender(boss) { - int xpos, ypos; - StaticTextWidget* t; WidgetArray wid; // Show current bank state - xpos = x; ypos = y + 7; - t = new StaticTextWidget(boss, lfont, xpos, ypos, "Info "); + int xpos = x, ypos = y + 7; + StaticTextWidget* t = new StaticTextWidget(boss, lfont, xpos, ypos, "Info "); xpos += t->getRight(); myBank = new EditTextWidget(boss, nfont, xpos, ypos-2, @@ -74,7 +72,7 @@ void RomWidget::loadConfig() } // Update romlist to point to current PC (if it has changed) - int pcline = cart.addressToLine(dbg.cpuDebug().pc()); + const int pcline = cart.addressToLine(dbg.cpuDebug().pc()); if(pcline >= 0 && pcline != myRomList->getHighlighted()) myRomList->setHighlighted(pcline); @@ -96,7 +94,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(), Common::Base::Fmt{id}); break; case RomListWidget::kSetPCCmd: @@ -195,7 +193,7 @@ void RomWidget::runtoPC(int disasm_line) { ostringstream command; command << "runtopc #" << address; - string msg = instance().debugger().run(command.str()); + const string& msg = instance().debugger().run(command.str()); instance().frameBuffer().showTextMessage(msg); } } @@ -227,7 +225,7 @@ void RomWidget::patchROM(int disasm_line, const string& bytes, // Temporarily set to correct base, so we don't have to prefix each byte // with the type of data - Common::Base::Fmt oldbase = Common::Base::format(); + const Common::Base::Fmt oldbase = Common::Base::format(); Common::Base::setFormat(base); command << "rom #" << address << " " << bytes; @@ -244,7 +242,7 @@ uInt16 RomWidget::getAddress(int disasm_line) const CartDebug::DisassemblyList& list = instance().debugger().cartDebug().disassembly().list; - if (disasm_line < int(list.size()) && list[disasm_line].address != 0) + if (disasm_line < static_cast(list.size()) && list[disasm_line].address != 0) return list[disasm_line].address; else return 0; diff --git a/src/debugger/gui/TiaInfoWidget.cxx b/src/debugger/gui/TiaInfoWidget.cxx index f8decb984..56aef049b 100644 --- a/src/debugger/gui/TiaInfoWidget.cxx +++ b/src/debugger/gui/TiaInfoWidget.cxx @@ -36,7 +36,7 @@ TiaInfoWidget::TiaInfoWidget(GuiObject* boss, const GUI::Font& lfont, CommandSender(boss) { const int VGAP = lfont.getLineHeight() / 4; - const int VBORDER = 5 + 1; + constexpr int VBORDER = 5 + 1; const int COLUMN_GAP = _fontWidth * 1.25; bool longstr = lfont.getStringWidth("Frame Cycls12345") + _fontWidth * 0.5 + COLUMN_GAP + lfont.getStringWidth("Scanline262262") @@ -167,17 +167,19 @@ void TiaInfoWidget::loadConfig() myFrameCycles->setText(Common::Base::toString(tia.frameCycles(), Common::Base::Fmt::_10_5), tia.frameCycles() != oldTia.info[1]); - uInt64 total = tia.cyclesLo() + (uInt64(tia.cyclesHi()) << 32); - uInt64 totalOld = oldTia.info[2] + (uInt64(oldTia.info[3]) << 32); - myTotalCycles->setText(Common::Base::toString(uInt32(total) / 1000000, Common::Base::Fmt::_10_6) + "e6", + const uInt64 total = tia.cyclesLo() + (static_cast(tia.cyclesHi()) << 32); + const uInt64 totalOld = oldTia.info[2] + (static_cast(oldTia.info[3]) << 32); + myTotalCycles->setText(Common::Base::toString(static_cast(total) / 1000000, + Common::Base::Fmt::_10_6) + "e6", total / 1000000 != totalOld / 1000000); myTotalCycles->setToolTip("Total CPU cycles (E notation) executed for this session (" + std::to_string(total) + ")."); - uInt64 delta = total - totalOld; - myDeltaCycles->setText(Common::Base::toString(uInt32(delta), Common::Base::Fmt::_10_8)); // no coloring + const uInt64 delta = total - totalOld; + myDeltaCycles->setText(Common::Base::toString(static_cast(delta), + Common::Base::Fmt::_10_8)); // no coloring - int clk = tia.clocksThisLine(); + const int clk = tia.clocksThisLine(); myScanlineCount->setText(Common::Base::toString(tia.scanlines(), Common::Base::Fmt::_10_3), tia.scanlines() != oldTia.info[4]); myScanlineCountLast->setText( diff --git a/src/debugger/gui/TiaOutputWidget.cxx b/src/debugger/gui/TiaOutputWidget.cxx index c135ed4f9..5ac422166 100644 --- a/src/debugger/gui/TiaOutputWidget.cxx +++ b/src/debugger/gui/TiaOutputWidget.cxx @@ -77,15 +77,15 @@ void TiaOutputWidget::saveSnapshot(int execDepth, const string& execPrefix) sspath << execPrefix << "_"; } sspath << std::hex << std::setw(8) << std::setfill('0') - << uInt32(TimerManager::getTicks()/1000) << ".png"; + << static_cast(TimerManager::getTicks()/1000) << ".png"; const uInt32 width = instance().console().tia().width(), height = instance().console().tia().height(); - FBSurface& s = dialog().surface(); + const FBSurface& s = dialog().surface(); // to skip borders, add 1 to origin - int x = _x + 1, y = _y + 1; - Common::Rect rect(x, y, x + width*2, y + height); + const int x = _x + 1, y = _y + 1; + const Common::Rect rect(x, y, x + width*2, y + height); string message = "Snapshot saved"; try { @@ -122,7 +122,7 @@ void TiaOutputWidget::handleMouseDown(int x, int y, MouseButton b, int clickCoun // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TiaOutputWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) { - uInt32 startLine = instance().console().tia().startLine(); + const uInt32 startLine = instance().console().tia().startLine(); if(cmd == ContextMenu::kItemSelectedCmd) { @@ -145,9 +145,9 @@ void TiaOutputWidget::handleCommand(CommandSender* sender, int cmd, int data, in else if(rmb == "bp") { ostringstream command; - int scanline = myClickY + startLine; + const int scanline = myClickY + startLine; command << "breakIf _scan==#" << scanline; - string message = instance().debugger().parser().run(command.str()); + const string& message = instance().debugger().parser().run(command.str()); instance().frameBuffer().showTextMessage(message); } else if(rmb == "zoom") @@ -190,7 +190,7 @@ string TiaOutputWidget::getToolTip(const Common::Point& pos) const const uInt32 yStart = height <= FrameManager::Metrics::baseHeightPAL ? 0 : (height - FrameManager::Metrics::baseHeightPAL) >> 1; const Int32 i = idx.x + (yStart + idx.y) * instance().console().tia().width(); - uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer(); + const uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer(); ostringstream buf; buf << _toolTipText @@ -215,8 +215,9 @@ void TiaOutputWidget::drawWidget(bool hilite) const uInt32 width = instance().console().tia().width(); uInt32 height = instance().console().tia().height(); // limit to 274 lines (PAL default without scaling) - uInt32 yStart = height <= FrameManager::Metrics::baseHeightPAL ? 0 : (height - FrameManager::Metrics::baseHeightPAL) / 2; - height = std::min(height, uInt32(FrameManager::Metrics::baseHeightPAL)); + const uInt32 yStart = height <= FrameManager::Metrics::baseHeightPAL ? 0 : + (height - FrameManager::Metrics::baseHeightPAL) / 2; + height = std::min(height, FrameManager::Metrics::baseHeightPAL); FBSurface& s = dialog().surface(); s.vLine(_x + _w + 1, _y, height, kColor); @@ -225,10 +226,10 @@ void TiaOutputWidget::drawWidget(bool hilite) // Get current scanline position // This determines where the frame greying should start, and where a // scanline 'pointer' should be drawn - uInt32 scanx, scany, scanoffset; - bool visible = instance().console().tia().electronBeamPos(scanx, scany); - scanoffset = width * scany + scanx; - uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer(); + uInt32 scanx = 0, scany = 0; + const bool visible = instance().console().tia().electronBeamPos(scanx, scany); + const uInt32 scanoffset = width * scany + scanx; + const uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer(); const TIASurface& tiaSurface = instance().frameBuffer().tiaSurface(); for(uInt32 y = 0, i = yStart * width; y < height; ++y) @@ -236,7 +237,7 @@ void TiaOutputWidget::drawWidget(bool hilite) uInt32* line_ptr = myLineBuffer.data(); for(uInt32 x = 0; x < width; ++x, ++i) { - uInt8 shift = i >= scanoffset ? 1 : 0; + const uInt8 shift = i >= scanoffset ? 1 : 0; uInt32 pixel = tiaSurface.mapIndexedPixel(tiaOutputBuffer[i], shift); *line_ptr++ = pixel; *line_ptr++ = pixel; diff --git a/src/debugger/gui/TiaWidget.cxx b/src/debugger/gui/TiaWidget.cxx index 1c767557d..782d67065 100644 --- a/src/debugger/gui/TiaWidget.cxx +++ b/src/debugger/gui/TiaWidget.cxx @@ -81,22 +81,22 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, xpos += myColorRegs->colWidth() + 5; myCOLUP0Color = new ColorWidget(boss, nfont, xpos, ypos+2, - uInt32(1.5*lineHeight), lineHeight - 4); + static_cast(1.5*lineHeight), lineHeight - 4); myCOLUP0Color->setTarget(this); ypos += lineHeight; myCOLUP1Color = new ColorWidget(boss, nfont, xpos, ypos+2, - uInt32(1.5*lineHeight), lineHeight - 4); + static_cast(1.5*lineHeight), lineHeight - 4); myCOLUP1Color->setTarget(this); ypos += lineHeight; myCOLUPFColor = new ColorWidget(boss, nfont, xpos, ypos+2, - uInt32(1.5*lineHeight), lineHeight - 4); + static_cast(1.5*lineHeight), lineHeight - 4); myCOLUPFColor->setTarget(this); ypos += lineHeight; myCOLUBKColor = new ColorWidget(boss, nfont, xpos, ypos+2, - uInt32(1.5*lineHeight), lineHeight - 4); + static_cast(1.5*lineHeight), lineHeight - 4); myCOLUBKColor->setTarget(this); // Fixed debug colors @@ -139,7 +139,8 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, xpos -= 2*fontWidth + 5; ypos += lineHeight; static constexpr std::array rowLabel = { "P0", "P1", "M0", "M1", "BL" }; static constexpr std::array colLabel = { "PF", "BL", "M1", "M0", "P1" }; - uInt32 lwidth = 2*fontWidth, collX = xpos + lwidth + 5, collY = ypos, idx = 0; + const uInt32 lwidth = 2 * fontWidth; + int collX = xpos + lwidth + 5, collY = ypos, idx = 0; for(uInt32 row = 0; row < 5; ++row) { // Add vertical label @@ -160,7 +161,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, // Add horizontal label uInt32 labelx = collX; - if(lwidth > uInt32(myCollision[idx]->getWidth())) + if(lwidth > static_cast(myCollision[idx]->getWidth())) labelx -= (lwidth - myCollision[idx]->getWidth()) / 2; else labelx += (myCollision[idx]->getWidth() - lwidth) / 2; @@ -583,10 +584,10 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont, addFocusWidget(myPF[2]); // PFx bit labels - auto start = [&](int sw) { return (sw - sfWidth) / 2; }; - int colw = myPF[0]->getWidth() / 4; + const auto start = [&](int sw) { return (sw - sfWidth) / 2; }; + const int colw = myPF[0]->getWidth() / 4; xpos = 10 + 2*fontWidth + 5 + start(colw); - int _ypos = ypos - sfHeight; + const int _ypos = ypos - sfHeight; for(int i = 4; i <= 7; ++i) { new StaticTextWidget(boss, sf, xpos, _ypos, sfWidth, sfHeight, @@ -989,7 +990,7 @@ void TiaWidget::loadConfig() } myColorRegs->setList(alist, vlist, changed); - bool fixed = tia.tia().usingFixedColors(); + const bool fixed = tia.tia().usingFixedColors(); myCOLUP0Color->setColor(state.coluRegs[0]); myCOLUP1Color->setColor(state.coluRegs[1]); @@ -1059,7 +1060,7 @@ void TiaWidget::loadConfig() myDelP0->setState(tia.vdelP0(), state.vdel[TiaState::P0] != oldstate.vdel[TiaState::P0]); // NUSIZ0 (player portion) - bool nusiz0changed = state.size[TiaState::P0] != oldstate.size[TiaState::P0]; + const bool nusiz0changed = state.size[TiaState::P0] != oldstate.size[TiaState::P0]; myNusizP0->setList(0, state.size[TiaState::P0], nusiz0changed); myNusizP0Text->setText(tia.nusizP0String(), nusiz0changed); @@ -1095,7 +1096,7 @@ void TiaWidget::loadConfig() myDelP1->setState(tia.vdelP1(), state.vdel[TiaState::P1] != oldstate.vdel[TiaState::P1]); // NUSIZ1 (player portion) - bool nusiz1changed = state.size[TiaState::P1] != oldstate.size[TiaState::P1]; + const bool nusiz1changed = state.size[TiaState::P1] != oldstate.size[TiaState::P1]; myNusizP1->setList(0, state.size[TiaState::P1], nusiz1changed); myNusizP1Text->setText(tia.nusizP1String(), nusiz1changed); @@ -1210,8 +1211,8 @@ void TiaWidget::loadConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TiaWidget::changeColorRegs() { - int addr = myColorRegs->getSelectedAddr(); - int value = myColorRegs->getSelectedValue(); + const int addr = myColorRegs->getSelectedAddr(); + const int value = myColorRegs->getSelectedValue(); switch(addr) { diff --git a/src/debugger/gui/TiaZoomWidget.cxx b/src/debugger/gui/TiaZoomWidget.cxx index a888d79a6..ff9f75d27 100644 --- a/src/debugger/gui/TiaZoomWidget.cxx +++ b/src/debugger/gui/TiaZoomWidget.cxx @@ -44,7 +44,7 @@ TiaZoomWidget::TiaZoomWidget(GuiObject* boss, const GUI::Font& font, // Use all available space, up to the maximum bounds of the TIA image _w = std::min(w, 320); - _h = std::min(h, int(FrameManager::Metrics::maxHeight)); + _h = std::min(h, static_cast(FrameManager::Metrics::maxHeight)); addFocusWidget(this); @@ -169,8 +169,8 @@ void TiaZoomWidget::handleMouseMoved(int x, int y) if(myMouseMoving) { y--; - int diffx = x + myOffXLo - myClickX; - int diffy = y + myOffYLo - myClickY; + const int diffx = x + myOffXLo - myClickX; + const int diffy = y + myOffYLo - myClickY; myClickX = x; myClickY = y; @@ -247,7 +247,7 @@ void TiaZoomWidget::handleCommand(CommandSender* sender, int cmd, int data, int { if(cmd == ContextMenu::kItemSelectedCmd) { - uInt32 startLine = instance().console().tia().startLine(); + const uInt32 startLine = instance().console().tia().startLine(); const string& rmb = myMenu->getSelectedTag().toString(); if(rmb == "scanline") @@ -267,14 +267,14 @@ void TiaZoomWidget::handleCommand(CommandSender* sender, int cmd, int data, int else if(rmb == "bp") { ostringstream command; - int scanline = myClickY / myZoomLevel + myOffY + startLine; + const int scanline = myClickY / myZoomLevel + myOffY + startLine; command << "breakif _scan==#" << scanline; - string message = instance().debugger().parser().run(command.str()); + const string& message = instance().debugger().parser().run(command.str()); instance().frameBuffer().showTextMessage(message); } else { - int level = myMenu->getSelectedTag().toInt(); + const int level = myMenu->getSelectedTag().toInt(); if(level > 0) zoom(level); } @@ -305,7 +305,7 @@ string TiaZoomWidget::getToolTip(const Common::Point& pos) const const Int32 i = idx.x + idx.y * instance().console().tia().width(); const uInt32 startLine = instance().console().tia().startLine(); - uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer(); + const uInt8* tiaOutputBuffer = instance().console().tia().outputBuffer(); ostringstream buf; buf << _toolTipText @@ -342,17 +342,16 @@ void TiaZoomWidget::drawWidget(bool hilite) // Get current scanline position // This determines where the frame greying should start - uInt32 scanx, scany, scanoffset; + uInt32 scanx = 0, scany = 0; instance().console().tia().electronBeamPos(scanx, scany); - scanoffset = width * scany + scanx; + const uInt32 scanoffset = width * scany + scanx; - int x, y, col, row; - for(y = myOffY, row = 0; y < myNumRows+myOffY; ++y, row += hzoom) + for(int y = myOffY, row = 0; y < myNumRows+myOffY; ++y, row += hzoom) { - for(x = myOffX >> 1, col = 0; x < (myNumCols+myOffX) >> 1; ++x, col += wzoom) + for(int x = myOffX >> 1, col = 0; x < (myNumCols+myOffX) >> 1; ++x, col += wzoom) { - uInt32 idx = y*width + x; - ColorId color = ColorId(currentFrame[idx] | (idx > scanoffset ? 1 : 0)); + const uInt32 idx = y*width + x; + const ColorId color = static_cast(currentFrame[idx] | (idx > scanoffset ? 1 : 0)); s.fillRect(_x + col + 1, _y + row + 1, wzoom, hzoom, color); } } diff --git a/src/debugger/gui/ToggleBitWidget.cxx b/src/debugger/gui/ToggleBitWidget.cxx index 48779ee7c..cb4d6a8ca 100644 --- a/src/debugger/gui/ToggleBitWidget.cxx +++ b/src/debugger/gui/ToggleBitWidget.cxx @@ -106,29 +106,29 @@ void ToggleBitWidget::drawWidget(bool hilite) { //cerr << "ToggleBitWidget::drawWidget\n"; FBSurface& s = dialog().surface(); - int row, col; string buffer; s.frameRect(_x, _y, _w, _h, hilite && isEnabled() && isEditable() ? kWidColorHi : kColor); + const int linewidth = _cols * _colWidth, + lineheight = _rows * _rowHeight; + // Draw the internal grid and labels - int linewidth = _cols * _colWidth; - for(row = 1; row <= _rows - 1; row++) + for(int row = 1; row <= _rows - 1; row++) s.hLine(_x + 1, _y + (row * _rowHeight), _x + linewidth - 1, kBGColorLo); - int lineheight = _rows * _rowHeight; - for(col = 1; col <= _cols - 1; col++) + for(int col = 1; col <= _cols - 1; col++) s.vLine(_x + (col * _colWidth), _y + 1, _y + lineheight - 1, kBGColorLo); // Draw the list items - for (row = 0; row < _rows; row++) + for(int row = 0; row < _rows; row++) { - for (col = 0; col < _cols; col++) + for(int col = 0; col < _cols; col++) { ColorId textColor = kTextColor; - int x = _x + 4 + (col * _colWidth); - int y = _y + 2 + (row * _rowHeight); - int pos = row*_cols + col; + const int x = _x + 4 + (col * _colWidth), + y = _y + 2 + (row * _rowHeight), + pos = row*_cols + col; // Draw the selected item inverted, on a highlighted background. if(_currentRow == row && _currentCol == col && _hasFocus) diff --git a/src/debugger/gui/TogglePixelWidget.cxx b/src/debugger/gui/TogglePixelWidget.cxx index 39a32677c..bc66f44a1 100644 --- a/src/debugger/gui/TogglePixelWidget.cxx +++ b/src/debugger/gui/TogglePixelWidget.cxx @@ -35,10 +35,10 @@ TogglePixelWidget::TogglePixelWidget(GuiObject* boss, const GUI::Font& font, _h = _rowHeight * rows + 1; // Changed state isn't used, but we still need to fill it - while(int(_changedList.size()) < rows * cols) + while(static_cast(_changedList.size()) < rows * cols) _changedList.push_back(false); // prepare _stateList for change tracking - while(int(_stateList.size()) < rows * cols) + while(static_cast(_stateList.size()) < rows * cols) _stateList.push_back(false); } @@ -50,8 +50,8 @@ void TogglePixelWidget::setState(const BoolArray& state) { for(int col = 0; col < _cols; col++) { - int pos = row * _cols + col; - bool changed = _stateList[pos] != state[pos]; + const int pos = row * _cols + col; + const bool changed = _stateList[pos] != state[pos]; if(_changedList[pos] != changed) { @@ -68,7 +68,7 @@ void TogglePixelWidget::setState(const BoolArray& state) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TogglePixelWidget::setIntState(int value, bool swap) { - uInt32 size = _rows * _cols; + const uInt32 size = _rows * _cols; _swapBits = swap; // Create array of required size @@ -86,7 +86,7 @@ void TogglePixelWidget::setIntState(int value, bool swap) // confusing. for(uInt32 i = 0; i < size; ++i) { - bool bitIsSet = value & (1 << i); + const bool bitIsSet = value & (1 << i); if(_swapBits) b[i] = bitIsSet; else @@ -100,9 +100,10 @@ void TogglePixelWidget::setIntState(int value, bool swap) int TogglePixelWidget::getIntState() { // Construct int based on current state and swap - uInt32 value = 0, size = int(_stateList.size()); + uInt32 value = 0; + const int size = static_cast(_stateList.size()); - for(uInt32 i = 0; i < size; ++i) + for(int i = 0; i < size; ++i) { if(_stateList[i]) { @@ -131,26 +132,26 @@ void TogglePixelWidget::drawWidget(bool hilite) { //cerr << "TogglePixelWidget::drawWidget\n"; FBSurface& s = dialog().surface(); - int row, col; s.frameRect(_x, _y, _w, _h, hilite && isEnabled() && isEditable() ? kWidColorHi : kColor); + const int linewidth = _cols * _colWidth; + const int lineheight = _rows * _rowHeight; + // Draw the internal grid and labels - int linewidth = _cols * _colWidth; - for (row = 1; row <= _rows - 1; row++) + for(int row = 1; row <= _rows - 1; row++) s.hLine(_x, _y + (row * _rowHeight), _x + linewidth, kColor); - int lineheight = _rows * _rowHeight; - for (col = 1; col <= _cols - 1; col++) + for(int col = 1; col <= _cols - 1; col++) s.vLine(_x + (col * _colWidth), _y, _y + lineheight, kColor); // Draw the pixels - for (row = 0; row < _rows; row++) + for(int row = 0; row < _rows; row++) { - for (col = 0; col < _cols; col++) + for(int col = 0; col < _cols; col++) { - int x = _x + 4 + (col * _colWidth); - int y = _y + 2 + (row * _rowHeight); - int pos = row*_cols + col; + const int x = _x + 4 + (col * _colWidth), + y = _y + 2 + (row * _rowHeight), + pos = row*_cols + col; // Draw the selected item inverted, on a highlighted background. if (_currentRow == row && _currentCol == col && _hasFocus) @@ -167,9 +168,9 @@ void TogglePixelWidget::drawWidget(bool hilite) // Cross out the bits? if(_crossBits) { - for(col = 0; col < _cols; ++col) + for(int col = 0; col < _cols; ++col) { - int x = _x + col * _colWidth; + const int x = _x + col * _colWidth; s.line(x + 1, _y + 1, x + _colWidth - 1, _y + lineheight - 1, kColor); s.line(x + _colWidth - 1, _y + 1, x + 1, _y + lineheight - 1, kColor); diff --git a/src/debugger/gui/ToggleWidget.cxx b/src/debugger/gui/ToggleWidget.cxx index 6556c846d..8dd37c7f1 100644 --- a/src/debugger/gui/ToggleWidget.cxx +++ b/src/debugger/gui/ToggleWidget.cxx @@ -45,7 +45,7 @@ void ToggleWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) // First check whether the selection changed int newSelectedItem; newSelectedItem = findItem(x, y); - if (newSelectedItem > int(_stateList.size()) - 1) + if (newSelectedItem > static_cast(_stateList.size()) - 1) newSelectedItem = -1; if (_selectedItem != newSelectedItem) diff --git a/src/emucore/CartBUS.hxx b/src/emucore/CartBUS.hxx index b30609b94..917b105b9 100644 --- a/src/emucore/CartBUS.hxx +++ b/src/emucore/CartBUS.hxx @@ -146,7 +146,7 @@ class CartridgeBUS : public CartridgeARM @return The internal RAM size */ - uInt32 internalRamSize() const override { return uInt32(myRAM.size()); } + uInt32 internalRamSize() const override { return static_cast(myRAM.size()); } /** Read a byte from cart internal RAM. diff --git a/src/emucore/CartCDF.hxx b/src/emucore/CartCDF.hxx index 98c67adb8..c4aa0c367 100644 --- a/src/emucore/CartCDF.hxx +++ b/src/emucore/CartCDF.hxx @@ -172,7 +172,7 @@ class CartridgeCDF : public CartridgeARM @return The internal RAM size */ - uInt32 internalRamSize() const override { return uInt32(myRAM.size()); } + uInt32 internalRamSize() const override { return static_cast(myRAM.size()); } /** Read a byte from cart internal RAM. diff --git a/src/emucore/CartDPCPlus.hxx b/src/emucore/CartDPCPlus.hxx index 9de833232..e54596419 100644 --- a/src/emucore/CartDPCPlus.hxx +++ b/src/emucore/CartDPCPlus.hxx @@ -140,7 +140,7 @@ class CartridgeDPCPlus : public CartridgeARM @return The internal RAM size */ - uInt32 internalRamSize() const override { return uInt32(myDPCRAM.size()); } + uInt32 internalRamSize() const override { return static_cast(myDPCRAM.size()); } /** Read a byte from cart internal RAM. diff --git a/src/emucore/M6502.hxx b/src/emucore/M6502.hxx index 66a3e89c4..e396316e1 100644 --- a/src/emucore/M6502.hxx +++ b/src/emucore/M6502.hxx @@ -418,7 +418,7 @@ class M6502 : public Serializable #ifdef DEBUGGER_SUPPORT Int32 evalCondBreaks() { - for(Int32 i = Int32(myCondBreaks.size()) - 1; i >= 0; --i) + for(Int32 i = static_cast(myCondBreaks.size()) - 1; i >= 0; --i) if(myCondBreaks[i]->evaluate()) return i; @@ -427,7 +427,7 @@ class M6502 : public Serializable Int32 evalCondSaveStates() { - for(Int32 i = Int32(myCondSaveStates.size()) - 1; i >= 0; --i) + for(Int32 i = static_cast(myCondSaveStates.size()) - 1; i >= 0; --i) if(myCondSaveStates[i]->evaluate()) return i; @@ -436,7 +436,7 @@ class M6502 : public Serializable Int32 evalCondTraps() { - for(Int32 i = Int32(myTrapConds.size()) - 1; i >= 0; --i) + for(Int32 i = static_cast(myTrapConds.size()) - 1; i >= 0; --i) if(myTrapConds[i]->evaluate()) return i; diff --git a/src/emucore/tia/Ball.hxx b/src/emucore/tia/Ball.hxx index 67c52b3dd..822e6f104 100644 --- a/src/emucore/tia/Ball.hxx +++ b/src/emucore/tia/Ball.hxx @@ -380,7 +380,7 @@ void Ball::tick(bool isReceivingRegularClock) collision = (mySignalActive && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; // Regular clock pulse during movement -> starfield mode - bool starfieldEffect = isMoving && isReceivingRegularClock; + const bool starfieldEffect = isMoving && isReceivingRegularClock; // Decode value that triggers rendering if (myCounter == 156) { @@ -388,7 +388,7 @@ void Ball::tick(bool isReceivingRegularClock) myRenderCounter = renderCounterOffset; // What follows is an effective description of ball width in starfield mode. - uInt8 starfieldDelta = (myCounter + TIAConstants::H_PIXEL - myLastMovementTick) % 4; + const uInt8 starfieldDelta = (myCounter + TIAConstants::H_PIXEL - myLastMovementTick) % 4; if (starfieldEffect && starfieldDelta == 3 && myWidth < 4) ++myRenderCounter; switch (starfieldDelta) { diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 3f53926b4..3959ea62f 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -326,7 +326,7 @@ class TIA : public Device /** Answers the total system cycles from the start of the emulation. */ - uInt64 cycles() const { return uInt64(mySystem->cycles()); } + uInt64 cycles() const { return mySystem->cycles(); } #ifdef DEBUGGER_SUPPORT /** @@ -338,7 +338,7 @@ class TIA : public Device Answers the system cycles from the start of the current frame. */ uInt32 frameCycles() const { - return uInt32(mySystem->cycles() - myCyclesAtFrameStart); + return static_cast(mySystem->cycles() - myCyclesAtFrameStart); } /** @@ -526,7 +526,7 @@ class TIA : public Device Get the current x value. */ uInt8 getPosition() const { - uInt8 realHctr = myHctr - myHctrDelta; + const uInt8 realHctr = myHctr - myHctrDelta; return (realHctr < TIAConstants::H_BLANK_CLOCKS) ? 0 : (realHctr - TIAConstants::H_BLANK_CLOCKS); } diff --git a/src/gui/EditTextWidget.hxx b/src/gui/EditTextWidget.hxx index 0af606076..f566394b2 100644 --- a/src/gui/EditTextWidget.hxx +++ b/src/gui/EditTextWidget.hxx @@ -40,7 +40,7 @@ class EditTextWidget : public EditableWidget // Get total width of widget static int calcWidth(const GUI::Font& font, const string& str) { - return calcWidth(font, int(str.length())); + return calcWidth(font, static_cast(str.length())); } protected: diff --git a/src/gui/GuiObject.hxx b/src/gui/GuiObject.hxx index 38552246c..21a05844b 100644 --- a/src/gui/GuiObject.hxx +++ b/src/gui/GuiObject.hxx @@ -108,7 +108,7 @@ class GuiObject : public CommandReceiver void setFlags(uInt32 flags, bool updateDirty = true) { - uInt32 oldFlags = _flags; + const uInt32 oldFlags = _flags; _flags |= flags; if(updateDirty && oldFlags != _flags) @@ -116,7 +116,7 @@ class GuiObject : public CommandReceiver } void clearFlags(uInt32 flags, bool updateDirty = true) { - uInt32 oldFlags = _flags; + const uInt32 oldFlags = _flags; _flags &= ~flags; if(updateDirty && oldFlags != _flags) diff --git a/src/gui/ListWidget.hxx b/src/gui/ListWidget.hxx index f00249f3a..38674e2c7 100644 --- a/src/gui/ListWidget.hxx +++ b/src/gui/ListWidget.hxx @@ -60,7 +60,7 @@ class ListWidget : public EditableWidget const string& getSelectedString() const; void scrollTo(int item); - void scrollToEnd() { scrollToCurrent(int(_list.size())); } + void scrollToEnd() { scrollToCurrent(static_cast(_list.size())); } // Account for the extra width of embedded scrollbar int getWidth() const override; diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index 3301f80df..d9053d9a6 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -48,8 +48,8 @@ class Widget : public GuiObject Widget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h); ~Widget() override; - virtual int getAbsX() const override { return _x + _boss->getChildX(); } - virtual int getAbsY() const override { return _y + _boss->getChildY(); } + int getAbsX() const override { return _x + _boss->getChildX(); } + int getAbsY() const override { return _y + _boss->getChildY(); } virtual int getLeft() const { return _x; } virtual int getTop() const { return _y; } virtual int getRight() const { return _x + getWidth(); } diff --git a/src/windows/FSNodeWINDOWS.cxx b/src/windows/FSNodeWINDOWS.cxx index d7135c8f2..10f63e01c 100644 --- a/src/windows/FSNodeWINDOWS.cxx +++ b/src/windows/FSNodeWINDOWS.cxx @@ -68,7 +68,7 @@ void FilesystemNodeWINDOWS::setFlags() _displayName = lastPathComponent(_path); // Check whether it is a directory, and whether the file actually exists - DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str())); + const DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str())); if(fileAttribs == INVALID_FILE_ATTRIBUTES) { @@ -92,8 +92,8 @@ void FilesystemNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode, const char* base, WIN32_FIND_DATA* find_data) { FilesystemNodeWINDOWS entry; - char* asciiName = toAscii(find_data->cFileName); - bool isDirectory, isFile; + const char* const asciiName = toAscii(find_data->cFileName); + bool isDirectory = false, isFile = false; // Skip local directory (.) and parent (..) if(!strncmp(asciiName, ".", 1) || !strncmp(asciiName, "..", 2)) @@ -123,7 +123,7 @@ void FilesystemNodeWINDOWS::addFile(AbstractFSList& list, ListMode mode, char* FilesystemNodeWINDOWS::toAscii(TCHAR* str) { #ifndef UNICODE - return (char*)str; + return str; #else static char asciiString[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, str, _tcslen(str) + 1, asciiString, sizeof(asciiString), NULL, NULL); @@ -135,7 +135,7 @@ char* FilesystemNodeWINDOWS::toAscii(TCHAR* str) const TCHAR* FilesystemNodeWINDOWS::toUnicode(const char* str) { #ifndef UNICODE - return (const TCHAR *)str; + return str; #else static TCHAR unicodeString[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, str, strlen(str) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR)); @@ -263,7 +263,7 @@ AbstractFSNodePtr FilesystemNodeWINDOWS::getParent() const const char* start = _path.c_str(); const char* end = lastPathComponent(_path); - return make_shared(string(start, size_t(end - start))); + return make_shared(string(start, static_cast(end - start))); } else return make_shared(); diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index 880ade69f..9bdcbd0d4 100755 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -262,7 +262,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -296,7 +296,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;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;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;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;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -402,7 +402,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -437,7 +437,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp NoListing $(IntDir)asm\windows\%(RelativeDir) @@ -472,7 +472,7 @@ StreamingSIMDExtensions stdcpp17 true - 4100;4127;4146;4244;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;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;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;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;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;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;26440;26446;26472;26455;%(DisableSpecificWarnings) + 4100;4127;4146;4244;26400;26409;26429;26438;26440;26446;26451;26455;26467;26472;26481;26482;26485;26492;%(DisableSpecificWarnings) CompileAsCpp All $(IntDir)asm\windows\%(RelativeDir) diff --git a/src/yacc/YaccParser.cxx b/src/yacc/YaccParser.cxx index 08ddfb40c..ea75c720e 100644 --- a/src/yacc/YaccParser.cxx +++ b/src/yacc/YaccParser.cxx @@ -82,12 +82,12 @@ int parse(const string& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // hand-rolled lexer. Hopefully faster than flex... -inline bool is_base_prefix(char x) +inline constexpr bool is_base_prefix(char x) { return ( (x=='\\' || x=='$' || x=='#') ); } -inline bool is_identifier(char x) +inline constexpr bool is_identifier(char x) { return ( (x>='0' && x<='9') || (x>='a' && x<='z') || @@ -95,7 +95,7 @@ inline bool is_identifier(char x) x=='.' || x=='_' ); } -inline bool is_operator(char x) +inline constexpr bool is_operator(char x) { return ( (x=='+' || x=='-' || x=='*' || x=='/' || x=='<' || x=='>' ||