diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 588886760..e6e4cfba2 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -33,7 +33,9 @@ static constexpr char CTRL_DELIM = '^'; PhysicalJoystickHandler::PhysicalJoystickHandler( OSystem& system, EventHandler& handler) : myOSystem(system), - myHandler(handler) + myHandler(handler), + myLeftMode(EventMode::kEmulationMode), + myRightMode(EventMode::kEmulationMode) { Int32 version = myOSystem.settings().getInt("event_ver"); // Load previously saved joystick mapping (if any) from settings diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 245f32abf..aa68a55a2 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -42,7 +42,9 @@ static constexpr int MOD3 = KBDM_ALT; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PhysicalKeyboardHandler::PhysicalKeyboardHandler(OSystem& system, EventHandler& handler) : myOSystem(system), - myHandler(handler) + myHandler(handler), + myLeftMode(EventMode::kEmulationMode), + myRightMode(EventMode::kEmulationMode) #ifdef BSPF_UNIX , myAltKeyCounter(0) #endif diff --git a/src/common/StaggeredLogger.cxx b/src/common/StaggeredLogger.cxx index f72fd1a74..5de05e923 100644 --- a/src/common/StaggeredLogger.cxx +++ b/src/common/StaggeredLogger.cxx @@ -46,8 +46,10 @@ StaggeredLogger::StaggeredLogger(const string& message, Logger::Level level) myCurrentIntervalFactor(1), myCooldownTime(1000), myTimer(new TimerManager()), + myTimerId(0), myTimerCallbackId(0) -{} +{ +} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - StaggeredLogger::~StaggeredLogger() diff --git a/src/common/StaggeredLogger.hxx b/src/common/StaggeredLogger.hxx index 9f59a6f98..2a69e2d82 100644 --- a/src/common/StaggeredLogger.hxx +++ b/src/common/StaggeredLogger.hxx @@ -26,13 +26,15 @@ #include "bspf.hxx" #include "TimerManager.hxx" #include "Logger.hxx" + /** * This class buffers log events and logs them after a certain time window has expired. * The timout increases after every log line by a factor of two until a maximum is reached. * If no events are reported, the window size decreases again. */ -class StaggeredLogger { +class StaggeredLogger +{ public: StaggeredLogger(const string& message, Logger::Level level); diff --git a/src/common/main.cxx b/src/common/main.cxx index 3caca17bb..80e14b182 100644 --- a/src/common/main.cxx +++ b/src/common/main.cxx @@ -167,7 +167,15 @@ int main(int ac, char* av[]) if (isProfilingRun(ac, av)) { ProfilingRunner runner(ac, av); - return runner.run() ? 0 : 1; + try + { + return runner.run() ? 0 : 1; + } + catch(const runtime_error& e) + { + cerr << e.what() << endl; + return 0; + } } unique_ptr theOSystem; diff --git a/src/debugger/gui/TiaZoomWidget.cxx b/src/debugger/gui/TiaZoomWidget.cxx index f38d0365c..db5425ee4 100644 --- a/src/debugger/gui/TiaZoomWidget.cxx +++ b/src/debugger/gui/TiaZoomWidget.cxx @@ -49,7 +49,7 @@ TiaZoomWidget::TiaZoomWidget(GuiObject* boss, const GUI::Font& font, myZoomLevel = 2; myNumCols = (_w - 4) / myZoomLevel; myNumRows = (_h - 4) / myZoomLevel; - myOffX = myOffY = 0; + myOffX = myOffY = myOffXLo = myOffYLo = 0; myMouseMoving = false; myClickX = myClickY = 0; diff --git a/src/emucore/CartCDF.cxx b/src/emucore/CartCDF.cxx index a3b8d92f1..6d8b0dc21 100644 --- a/src/emucore/CartCDF.cxx +++ b/src/emucore/CartCDF.cxx @@ -123,7 +123,8 @@ void CartridgeCDF::setInitialState() myMode = 0xFF; myBankOffset = myLDAimmediateOperandAddress = myJMPoperandAddress = 0; - myFastJumpActive = 0; + myFastJumpActive = myFastJumpStream = 0; + } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartDPC.cxx b/src/emucore/CartDPC.cxx index e25ecf093..759f24324 100644 --- a/src/emucore/CartDPC.cxx +++ b/src/emucore/CartDPC.cxx @@ -26,7 +26,8 @@ CartridgeDPC::CartridgeDPC(const ByteBuffer& image, size_t size, mySize(size), myAudioCycles(0), myFractionalClocks(0.0), - myBankOffset(0) + myBankOffset(0), + myDpcPitch(0.0) { // Make a copy of the entire image std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index ac5a822b9..c45f4644d 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -821,7 +821,7 @@ void Console::setControllers(const string& romMd5) const bool swappedPorts = myProperties.get(PropType::Console_SwapPorts) == "YES"; // Try to detect controllers - if(image != nullptr || size != 0) + if(image != nullptr && size != 0) { leftType = ControllerDetector::detectType(image, size, leftType, !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, myOSystem.settings()); diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index e4f4f9472..333533d4d 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -242,14 +242,14 @@ void EventHandler::poll(uInt64 time) myOSystem.png().updateTime(time); #endif } +#ifdef GUI_SUPPORT else if(myOverlay) { - #ifdef GUI_SUPPORT // Update the current dialog container at regular intervals // Used to implement continuous events myOverlay->updateTime(time); - #endif } +#endif // Turn off all mouse-related items; if they haven't been taken care of // in the previous ::update() methods, they're now invalid @@ -902,7 +902,7 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) } // Otherwise, pass it to the emulation core - if (!repeated) + if(!repeated) myEvent.set(event, value); } @@ -1006,43 +1006,55 @@ bool EventHandler::changeStateByEvent(Event::Type type) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::setActionMappings(EventMode mode) { - int listsize = 0; - ActionList* list = nullptr; - switch(mode) { case EventMode::kEmulationMode: - listsize = EMUL_ACTIONLIST_SIZE; - list = ourEmulActionList; + // Fill the EmulActionList with the current key and joystick mappings + for(auto& item: ourEmulActionList) + { + Event::Type event = item.event; + item.key = "None"; + string key = myPKeyHandler->getMappingDesc(event, mode); + + #ifdef JOYSTICK_SUPPORT + string joydesc = myPJoyHandler->getMappingDesc(event, mode); + if(joydesc != "") + { + if(key != "") + key += ", "; + key += joydesc; + } + #endif + + if(key != "") + item.key = key; + } break; case EventMode::kMenuMode: - listsize = MENU_ACTIONLIST_SIZE; - list = ourMenuActionList; + // Fill the MenuActionList with the current key and joystick mappings + for(auto& item: ourMenuActionList) + { + Event::Type event = item.event; + item.key = "None"; + string key = myPKeyHandler->getMappingDesc(event, mode); + + #ifdef JOYSTICK_SUPPORT + string joydesc = myPJoyHandler->getMappingDesc(event, mode); + if(joydesc != "") + { + if(key != "") + key += ", "; + key += joydesc; + } + #endif + + if(key != "") + item.key = key; + } break; default: return; } - - // Fill the ActionList with the current key and joystick mappings - for(int i = 0; i < listsize; ++i) - { - Event::Type event = list[i].event; - list[i].key = "None"; - string key = myPKeyHandler->getMappingDesc(event, mode); - -#ifdef JOYSTICK_SUPPORT - string joydesc = myPJoyHandler->getMappingDesc(event, mode); - if(joydesc != "") - { - if(key != "") - key += ", "; - key += joydesc; - } -#endif - - if(key != "") - list[i].key = key; - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1222,12 +1234,12 @@ StringList EventHandler::getActionList(EventMode mode) const switch(mode) { case EventMode::kEmulationMode: - for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i) - l.push_back(EventHandler::ourEmulActionList[i].action); + for(const auto& item: ourEmulActionList) + l.push_back(item.action); break; case EventMode::kMenuMode: - for(uInt32 i = 0; i < MENU_ACTIONLIST_SIZE; ++i) - l.push_back(EventHandler::ourMenuActionList[i].action); + for(const auto& item: ourMenuActionList) + l.push_back(item.action); break; default: break; @@ -1288,21 +1300,21 @@ StringList EventHandler::getActionList(const Event::EventSet& events, EventMode switch(mode) { case EventMode::kMenuMode: - for(uInt32 i = 0; i < MENU_ACTIONLIST_SIZE; ++i) + for(const auto& item: ourMenuActionList) for(const auto& event : events) - if(EventHandler::ourMenuActionList[i].event == event) + if(item.event == event) { - l.push_back(EventHandler::ourMenuActionList[i].action); + l.push_back(item.action); break; } break; default: - for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i) + for(const auto& item: ourEmulActionList) for(const auto& event : events) - if(EventHandler::ourEmulActionList[i].event == event) + if(item.event == event) { - l.push_back(EventHandler::ourEmulActionList[i].action); + l.push_back(item.action); break; } } @@ -1317,7 +1329,7 @@ VariantList EventHandler::getComboList(EventMode /**/) const ostringstream buf; VarList::push_back(l, "None", "-1"); - for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i) + for(uInt32 i = 0; i < ourEmulActionList.size(); ++i) { Event::Type event = EventHandler::ourEmulActionList[i].event; // exclude combos events @@ -1342,7 +1354,7 @@ StringList EventHandler::getComboListForEvent(Event::Type event) const for(uInt32 i = 0; i < EVENTS_PER_COMBO; ++i) { Event::Type e = myComboTable[combo][i]; - for(uInt32 j = 0; j < EMUL_ACTIONLIST_SIZE; ++j) + for(uInt32 j = 0; j < ourEmulActionList.size(); ++j) { if(EventHandler::ourEmulActionList[j].event == e) { @@ -1366,10 +1378,10 @@ void EventHandler::setComboListForEvent(Event::Type event, const StringList& eve { assert(events.size() == 8); int combo = event - Event::Combo1; - for(int i = 0; i < 8; ++i) + for(uInt32 i = 0; i < 8; ++i) { - int idx = atoi(events[i].c_str()); - if(idx >= 0 && idx < EMUL_ACTIONLIST_SIZE) + uInt32 idx = atoi(events[i].c_str()); + if(idx < ourEmulActionList.size()) myComboTable[combo][i] = EventHandler::ourEmulActionList[idx].event; else myComboTable[combo][i] = Event::NoType; @@ -1385,7 +1397,7 @@ int EventHandler::getEmulActionListIndex(int idx, const Event::EventSet& events) // ordered by 'ourEmulActionList'! Event::Type event = Event::NoType; - for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i) + for(uInt32 i = 0; i < ourEmulActionList.size(); ++i) { for(const auto& item : events) if(EventHandler::ourEmulActionList[i].event == item) @@ -1399,7 +1411,7 @@ int EventHandler::getEmulActionListIndex(int idx, const Event::EventSet& events) break; } - for(uInt32 i = 0; i < EMUL_ACTIONLIST_SIZE; ++i) + for(uInt32 i = 0; i < ourEmulActionList.size(); ++i) if(EventHandler::ourEmulActionList[i].event == event) return i; @@ -1457,13 +1469,13 @@ Event::Type EventHandler::eventAtIndex(int idx, Event::Group group) const switch(group) { case Event::Group::Menu: - if(index < 0 || index >= MENU_ACTIONLIST_SIZE) + if(index < 0 || index >= int(ourMenuActionList.size())) return Event::NoType; else return ourMenuActionList[index].event; default: - if(index < 0 || index >= EMUL_ACTIONLIST_SIZE) + if(index < 0 || index >= int(ourEmulActionList.size())) return Event::NoType; else return ourEmulActionList[index].event; @@ -1478,13 +1490,13 @@ string EventHandler::actionAtIndex(int idx, Event::Group group) const switch(group) { case Event::Group::Menu: - if(index < 0 || index >= MENU_ACTIONLIST_SIZE) + if(index < 0 || index >= int(ourMenuActionList.size())) return EmptyString; else return ourMenuActionList[index].action; default: - if(index < 0 || index >= EMUL_ACTIONLIST_SIZE) + if(index < 0 || index >= int(ourEmulActionList.size())) return EmptyString; else return ourEmulActionList[index].action; @@ -1499,13 +1511,13 @@ string EventHandler::keyAtIndex(int idx, Event::Group group) const switch(group) { case Event::Group::Menu: - if(index < 0 || index >= MENU_ACTIONLIST_SIZE) + if(index < 0 || index >= int(ourMenuActionList.size())) return EmptyString; else return ourMenuActionList[index].key; default: - if(index < 0 || index >= EMUL_ACTIONLIST_SIZE) + if(index < 0 || index >= int(ourEmulActionList.size())) return EmptyString; else return ourEmulActionList[index].key; @@ -1710,7 +1722,7 @@ void EventHandler::exitEmulation() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = { +EventHandler::EmulActionList EventHandler::ourEmulActionList = { { { Event::Quit, "Quit", "" }, { Event::ReloadConsole, "Reload current ROM/load next game", "" }, { Event::ExitMode, "Exit current Stella menu/mode", "" }, @@ -1887,10 +1899,10 @@ EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = { Event::Combo14, "Combo 14", "" }, { Event::Combo15, "Combo 15", "" }, { Event::Combo16, "Combo 16", "" } -}; +} }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EventHandler::ActionList EventHandler::ourMenuActionList[MENU_ACTIONLIST_SIZE] = { +EventHandler::MenuActionList EventHandler::ourMenuActionList = { { { Event::UIUp, "Move Up", "" }, { Event::UIDown, "Move Down", "" }, { Event::UILeft, "Move Left", "" }, @@ -1913,7 +1925,7 @@ EventHandler::ActionList EventHandler::ourMenuActionList[MENU_ACTIONLIST_SIZE] = { Event::UIPrevDir, "Parent directory", "" }, { Event::ToggleFullScreen, "Toggle fullscreen", "" }, { Event::Quit, "Quit", "" } -}; +} }; // Event groups // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index daf267cc8..f0604f515 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -388,18 +388,6 @@ class EventHandler void removePhysicalJoystick(int index); private: - static constexpr Int32 - COMBO_SIZE = 16, - EVENTS_PER_COMBO = 8, - #ifdef PNG_SUPPORT - PNG_SIZE = 2, - #else - PNG_SIZE = 0, - #endif - EMUL_ACTIONLIST_SIZE = 139 + PNG_SIZE + COMBO_SIZE, - MENU_ACTIONLIST_SIZE = 18 - ; - // Define event groups static const Event::EventSet MiscEvents; static const Event::EventSet AudioVideoEvents; @@ -449,9 +437,6 @@ class EventHandler // all possible controller modes unique_ptr myMouseControl; - // The event(s) assigned to each combination event - Event::Type myComboTable[COMBO_SIZE][EVENTS_PER_COMBO]; - // Indicates the current state of the system (ie, which mode is current) EventHandlerState myState; @@ -469,9 +454,28 @@ class EventHandler // of the 7800 (for now, only the switches are notified) bool myIs7800; + // These constants are not meant to be used elsewhere; they are only used + // here to make it easier for the reader to correctly size the list(s) + static constexpr Int32 + COMBO_SIZE = 16, + EVENTS_PER_COMBO = 8, + #ifdef PNG_SUPPORT + PNG_SIZE = 3, + #else + PNG_SIZE = 0, + #endif + EMUL_ACTIONLIST_SIZE = 138 + PNG_SIZE + COMBO_SIZE, + MENU_ACTIONLIST_SIZE = 18 + ; + + // The event(s) assigned to each combination event + Event::Type myComboTable[COMBO_SIZE][EVENTS_PER_COMBO]; + // Holds static strings for the remap menu (emulation and menu events) - static ActionList ourEmulActionList[EMUL_ACTIONLIST_SIZE]; - static ActionList ourMenuActionList[MENU_ACTIONLIST_SIZE]; + using EmulActionList = std::array; + static EmulActionList ourEmulActionList; + using MenuActionList = std::array; + static MenuActionList ourMenuActionList; // Following constructors and assignment operators not supported EventHandler() = delete; diff --git a/src/emucore/FrameBuffer.cxx b/src/emucore/FrameBuffer.cxx index 32bffafe9..1fcabaff7 100644 --- a/src/emucore/FrameBuffer.cxx +++ b/src/emucore/FrameBuffer.cxx @@ -56,7 +56,8 @@ FrameBuffer::FrameBuffer(OSystem& osystem) myGrabMouse(false), myHiDPIAllowed(false), myHiDPIEnabled(false), - myCurrentModeList(nullptr) + myCurrentModeList(nullptr), + myTIAMaxZoom(1.0) { } diff --git a/src/emucore/ProfilingRunner.cxx b/src/emucore/ProfilingRunner.cxx index a0e8ce7ca..72d68ed30 100644 --- a/src/emucore/ProfilingRunner.cxx +++ b/src/emucore/ProfilingRunner.cxx @@ -178,7 +178,7 @@ bool ProfilingRunner::runOne(const ProfilingRun run) EmulationTiming emulationTiming(frameLayout, consoleTiming); uInt64 cycles = 0; - uInt64 cyclesTarget = run.runtime * emulationTiming.cyclesPerSecond(); + uInt64 cyclesTarget = uInt64(run.runtime) * emulationTiming.cyclesPerSecond(); DispatchResult dispatchResult; dispatchResult.setOk(0); diff --git a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx index bc6173367..b1f1f573e 100644 --- a/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx +++ b/src/emucore/tia/frame-manager/FrameLayoutDetector.cxx @@ -44,7 +44,10 @@ FrameLayout FrameLayoutDetector::detectedLayout() const{ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FrameLayoutDetector::FrameLayoutDetector() - : myState(State::waitForVsyncStart) + : myState(State::waitForVsyncStart), + myNtscFrames(0), + myPalFrames(0), + myLinesWaitingForVsyncToStart(0) { reset(); } diff --git a/src/emucore/tia/frame-manager/YStartDetector.cxx b/src/emucore/tia/frame-manager/YStartDetector.cxx index 5c9e4d60c..bf8d79ab3 100644 --- a/src/emucore/tia/frame-manager/YStartDetector.cxx +++ b/src/emucore/tia/frame-manager/YStartDetector.cxx @@ -50,6 +50,11 @@ enum Metrics: uInt32 { YStartDetector::YStartDetector() : myState(State::waitForVsyncStart), myVblankMode(VblankMode::floating), + myLinesWaitingForVsyncToStart(0), + myCurrentVblankLines(0), + myLastVblankLines(0), + myVblankViolations(0), + myStableVblankFrames(0), myVblankViolated(false) { reset(); diff --git a/src/gui/EventMappingWidget.cxx b/src/gui/EventMappingWidget.cxx index 6ead20b9c..7be04ed0f 100644 --- a/src/gui/EventMappingWidget.cxx +++ b/src/gui/EventMappingWidget.cxx @@ -39,7 +39,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, EventMode mode) : Widget(boss, font, x, y, w, h), - CommandSender(boss), + CommandSender(boss), myFilterPopup(nullptr), myComboDialog(nullptr), myEventMode(mode), @@ -51,6 +51,8 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font, myLastAxis(JoyAxis::NONE), myLastDir(JoyDir::NONE), myLastHatDir(JoyHatDir::CENTER), + myMod(0), + myLastKey(0), myLastButton(JOY_CTRL_NONE), myFirstTime(true) {