From 4155da3ad9d881d341fac3fffae73d5e3786ac7a Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Tue, 23 Nov 2021 09:37:40 +0100 Subject: [PATCH] added option for toggling autofire --- Changes.txt | 10 +++++-- src/common/PKeyboardHandler.cxx | 1 + src/common/jsonDefinitions.hxx | 3 +- src/emucore/Console.cxx | 20 ++++++++++++++ src/emucore/Console.hxx | 10 +++---- src/emucore/Control.cxx | 7 +++++ src/emucore/Control.hxx | 18 +++++++++--- src/emucore/Event.hxx | 2 +- src/emucore/EventHandler.cxx | 12 +++++++- src/emucore/EventHandler.hxx | 2 +- src/emucore/Settings.cxx | 2 ++ src/gui/InputDialog.cxx | 49 ++++++++++++++++++++++----------- src/gui/InputDialog.hxx | 2 ++ 13 files changed, 105 insertions(+), 33 deletions(-) diff --git a/Changes.txt b/Changes.txt index ae79aabc2..4b2b4451a 100644 --- a/Changes.txt +++ b/Changes.txt @@ -12,6 +12,13 @@ Release History =========================================================================== +6.6 to 6.? + + * Added option to toggle autofire mode. (TODO: doc) + +-Have fun! + + 6.5.3 to 6.6 (November 16, 2021) * Added preliminary PlusROM support for saving high scores. @@ -43,9 +50,6 @@ * Debugger: added Thumb cycle counting. --Have fun! - - 6.5.2 to 6.5.3 (April 20, 2021) * Added context-sensitive help. diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 828291d37..50f4945db 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -700,6 +700,7 @@ PhysicalKeyboardHandler::DefaultCommonMapping = { { Event::IncDejtterReaction, KBDK_F4, KBDM_CTRL }, { Event::DecDigitalSense, KBDK_F5, KBDM_CTRL | KBDM_SHIFT }, { Event::IncDigitalSense, KBDK_F5, KBDM_CTRL }, + { Event::ToggleAutoFire, KBDK_A, MOD3 }, { Event::DecreaseAutoFire, KBDK_A, KBDM_CTRL | KBDM_SHIFT }, { Event::IncreaseAutoFire, KBDK_A, KBDM_CTRL }, { Event::ToggleFourDirections, KBDK_F6, KBDM_CTRL }, diff --git a/src/common/jsonDefinitions.hxx b/src/common/jsonDefinitions.hxx index 26ab8359d..fcdcefdd9 100644 --- a/src/common/jsonDefinitions.hxx +++ b/src/common/jsonDefinitions.hxx @@ -211,8 +211,6 @@ NLOHMANN_JSON_SERIALIZE_ENUM(Event::Type, { {Event::IncDejtterReaction, "IncDejtterReaction"}, {Event::DecDigitalSense, "DecDigitalSense"}, {Event::IncDigitalSense, "IncDigitalSense"}, - {Event::DecreaseAutoFire, "DecreaseAutoFire"}, - {Event::IncreaseAutoFire, "IncreaseAutoFire"}, {Event::ToggleFourDirections, "ToggleFourDirections"}, {Event::ToggleKeyCombos, "ToggleKeyCombos"}, {Event::ToggleSAPortOrder, "ToggleSAPortOrder"}, @@ -386,6 +384,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(Event::Type, { {Event::PreviousSettingGroup, "PreviousSettingGroup"}, {Event::NextSettingGroup, "NextSettingGroup"}, {Event::TogglePlayBackMode, "TogglePlayBackMode"}, + {Event::ToggleAutoFire, "ToggleAutoFire"}, {Event::DecreaseAutoFire, "DecreaseAutoFire"}, {Event::IncreaseAutoFire, "IncreaseAutoFire"}, {Event::DecreaseSpeed, "DecreaseSpeed"}, diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 52098f912..ab6de7a34 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -1110,6 +1110,22 @@ void Console::changePaddleAxesRange(int direction) myOSystem.frameBuffer().showGaugeMessage("Mouse axes range", val.str(), range); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Console::toggleAutoFire(bool toggle) +{ + bool enabled = myOSystem.settings().getBool("autofire"); + + if(toggle) + { + myOSystem.settings().setValue("autofire", !enabled); + Controller::setAutoFire(!enabled); + } + + ostringstream ss; + ss << "Autofire " << (!enabled ? "enabled" : "disabled"); + myOSystem.frameBuffer().showTextMessage(ss.str()); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::changeAutoFireRate(int direction) { @@ -1126,7 +1142,11 @@ void Console::changeAutoFireRate(int direction) ostringstream val; if(rate) + { + myOSystem.settings().setValue("autofire", true); + Controller::setAutoFire(true); val << rate << " Hz"; + } else val << "Off"; diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx index 9481026b5..346046a3e 100644 --- a/src/emucore/Console.hxx +++ b/src/emucore/Console.hxx @@ -187,11 +187,6 @@ class Console : public Serializable, public ConsoleIO */ EmulationTiming& emulationTiming() { return myEmulationTiming; } - /** - Retrieve the current game's refresh rate, or 0 if no game. - */ - int refreshRate() const; - /** Toggle left and right controller ports swapping */ @@ -378,6 +373,11 @@ class Console : public Serializable, public ConsoleIO */ void setTIAProperties(); + /** + Toggle autofire for all controllers + */ + void toggleAutoFire(bool toggle = true); + /** Change the autofire speed for all controllers */ diff --git a/src/emucore/Control.cxx b/src/emucore/Control.cxx index 0b8d99dcc..facc43956 100644 --- a/src/emucore/Control.cxx +++ b/src/emucore/Control.cxx @@ -184,6 +184,12 @@ void Controller::setMouseSensitivity(int sensitivity) MOUSE_SENSITIVITY = BSPF::clamp(sensitivity, MIN_MOUSE_SENSE, MAX_MOUSE_SENSE); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Controller::setAutoFire(bool enable) +{ + AUTO_FIRE = enable; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Controller::setAutoFireRate(int rate, bool isNTSC) { @@ -195,4 +201,5 @@ void Controller::setAutoFireRate(int rate, bool isNTSC) int Controller::DIGITAL_DEAD_ZONE = 3200; int Controller::ANALOG_DEAD_ZONE = 0; int Controller::MOUSE_SENSITIVITY = -1; +bool Controller::AUTO_FIRE = false; int Controller::AUTO_FIRE_RATE = 0; diff --git a/src/emucore/Control.hxx b/src/emucore/Control.hxx index 88ccde736..1fd5197d6 100644 --- a/src/emucore/Control.hxx +++ b/src/emucore/Control.hxx @@ -317,6 +317,13 @@ class Controller : public Serializable */ static void setMouseSensitivity(int sensitivity); + /** + Set auto fire state. + + @param enable The new autofire state + */ + static void setAutoFire(bool enable); + /** Sets the auto fire rate. 0 disables auto fire. @@ -359,12 +366,12 @@ class Controller : public Serializable /** Checks for the next auto fire event. - @param pressed True if the fire button is current pressed + @param pressed True if the fire button is currently pressed @return The result of the auto fire event check */ inline bool getAutoFireState(bool pressed) { - if(AUTO_FIRE_RATE && pressed) + if(AUTO_FIRE && AUTO_FIRE_RATE && pressed) { myFireDelay -= AUTO_FIRE_RATE; if(myFireDelay <= 0) @@ -383,7 +390,7 @@ class Controller : public Serializable */ inline bool getAutoFireStateP1(bool pressed) { - if(AUTO_FIRE_RATE && pressed) + if(AUTO_FIRE && AUTO_FIRE_RATE && pressed) { myFireDelayP1 -= AUTO_FIRE_RATE; if(myFireDelayP1 <= 0) @@ -418,7 +425,10 @@ class Controller : public Serializable static int MOUSE_SENSITIVITY; - /// Defines the speed of the auto fire + /// Defines the state of auto fire + static bool AUTO_FIRE; + + /// Defines the speed of auto fire static int AUTO_FIRE_RATE; /// Delay[frames] until the next fire event diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx index 17c652e29..f48325c66 100644 --- a/src/emucore/Event.hxx +++ b/src/emucore/Event.hxx @@ -128,7 +128,7 @@ class Event // add new (after Version 4) events from here to avoid that user remapped events get overwritten PreviousSettingGroup, NextSettingGroup, TogglePlayBackMode, - DecreaseAutoFire, IncreaseAutoFire, + ToggleAutoFire, DecreaseAutoFire, IncreaseAutoFire, DecreaseSpeed, IncreaseSpeed, QTJoystickThreeUp, QTJoystickThreeDown, QTJoystickThreeLeft, QTJoystickThreeRight, diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 2b1c03ef0..8232a4b50 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -113,6 +113,7 @@ void EventHandler::initialize() Controller::setMouseSensitivity(myOSystem.settings().getInt("msense")); PointingDevice::setSensitivity(myOSystem.settings().getInt("tsense")); Driving::setSensitivity(myOSystem.settings().getInt("dcsense")); + Controller::setAutoFire(myOSystem.settings().getBool("autofire")); Controller::setAutoFireRate(myOSystem.settings().getInt("autofirerate")); #ifdef GUI_SUPPORT @@ -1100,6 +1101,14 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) } return; + case Event::ToggleAutoFire: + if(pressed && !repeated) + { + myOSystem.console().toggleAutoFire(); + myGlobalKeyHandler->setSetting(GlobalKeyHandler::Setting::AUTO_FIRE); + } + return; + case Event::DecreaseAutoFire: if(pressed) { @@ -2929,6 +2938,7 @@ EventHandler::EmulActionList EventHandler::ourEmulActionList = { { { Event::IncDejtterReaction, "Increase paddle dejitter reaction", "" }, { Event::DecDigitalSense, "Decrease digital paddle sensitivity", "" }, { Event::IncDigitalSense, "Increase digital paddle sensitivity", "" }, + { Event::ToggleAutoFire, "Toggle auto fire", "" }, { Event::DecreaseAutoFire, "Decrease auto fire speed", "" }, { Event::IncreaseAutoFire, "Increase auto fire speed", "" }, { Event::ToggleFourDirections, "Toggle allow four joystick directions", "" }, @@ -3142,7 +3152,7 @@ const Event::EventSet EventHandler::DevicesEvents = { Event::DecDejtterAveraging, Event::IncDejtterAveraging, Event::DecDejtterReaction, Event::IncDejtterReaction, Event::DecDigitalSense, Event::IncDigitalSense, - Event::DecreaseAutoFire, Event::IncreaseAutoFire, + Event::ToggleAutoFire, Event::DecreaseAutoFire, Event::IncreaseAutoFire, Event::ToggleFourDirections, Event::ToggleKeyCombos, Event::ToggleSAPortOrder, Event::PrevMouseAsController, Event::NextMouseAsController, Event::DecMousePaddleSense, Event::IncMousePaddleSense, diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 5a668629c..aac604590 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -522,7 +522,7 @@ class EventHandler #else REFRESH_SIZE = 0, #endif - EMUL_ACTIONLIST_SIZE = 221 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE, + EMUL_ACTIONLIST_SIZE = 222 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE, MENU_ACTIONLIST_SIZE = 19 ; diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 53f91359c..f740b4b51 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -113,6 +113,7 @@ Settings::Settings() setPermanent("combomap", ""); setPermanent("joydeadzone", "13"); setPermanent("joyallow4", "false"); + setPermanent("autofire", "0"); setPermanent("autofirerate", "0"); setPermanent("usemouse", "analog"); setPermanent("grabmouse", "true"); @@ -549,6 +550,7 @@ void Settings::usage() const << " -tsense <1-20> Sensitivity of mouse emulated trackball movement\n" << " -dcsense <1-20> Sensitivity of digital emulated driving controller\n" << " movement\n" + << " -autofire <1|0> Enable fire button autofire\n" << " -autofirerate <0-30> Set fire button's autofire rate (0 means off)\n" << " -saport How to assign virtual ports to multiple\n" << " Stelladaptor/2600-daptors\n" diff --git a/src/gui/InputDialog.cxx b/src/gui/InputDialog.cxx index 40ae3f8f9..70ec571a4 100644 --- a/src/gui/InputDialog.cxx +++ b/src/gui/InputDialog.cxx @@ -106,6 +106,7 @@ void InputDialog::addDevicePortTab() VBORDER = Dialog::vBorder(), HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(); + const int swidth = 13 * fontWidth; int xpos, ypos, lwidth, tabID; WidgetArray wid; @@ -116,7 +117,7 @@ void InputDialog::addDevicePortTab() lwidth = _font.getStringWidth("Digital paddle sensitivity "); // Add digital dead zone setting - myDigitalDeadzone = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myDigitalDeadzone = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Digital dead zone size ", lwidth, kDDeadzoneChanged, 3 * fontWidth, "%"); myDigitalDeadzone->setMinValue(Controller::MIN_DIGITAL_DEADZONE); @@ -127,7 +128,7 @@ void InputDialog::addDevicePortTab() // Add analog dead zone ypos += lineHeight + VGAP; - myAnalogDeadzone = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myAnalogDeadzone = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Analog dead zone size", lwidth, kADeadzoneChanged, 3 * fontWidth, "%"); myAnalogDeadzone->setMinValue(Controller::MIN_ANALOG_DEADZONE); @@ -142,7 +143,7 @@ void InputDialog::addDevicePortTab() // Add analog paddle sensitivity ypos += lineHeight; - myPaddleSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myPaddleSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Sensitivity", lwidth - fontWidth * 2, kPSpeedChanged, 4 * fontWidth, "%"); myPaddleSpeed->setMinValue(0); @@ -152,7 +153,7 @@ void InputDialog::addDevicePortTab() // Add analog paddle linearity ypos += lineHeight + VGAP; - myPaddleLinearity = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myPaddleLinearity = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Linearity", lwidth - fontWidth * 2, 0, 4 * fontWidth, "%"); myPaddleLinearity->setMinValue(Paddles::MIN_ANALOG_LINEARITY); myPaddleLinearity->setMaxValue(Paddles::MAX_ANALOG_LINEARITY); @@ -163,7 +164,7 @@ void InputDialog::addDevicePortTab() // Add dejitter (analog paddles) ypos += lineHeight + VGAP; - myDejitterBase = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myDejitterBase = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Dejitter averaging", lwidth - fontWidth * 2, kDejitterAvChanged, 3 * fontWidth); myDejitterBase->setMinValue(Paddles::MIN_DEJITTER); @@ -175,7 +176,7 @@ void InputDialog::addDevicePortTab() wid.push_back(myDejitterBase); ypos += lineHeight + VGAP; - myDejitterDiff = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myDejitterDiff = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Dejitter reaction", lwidth - fontWidth * 2, kDejitterReChanged, 3 * fontWidth); myDejitterDiff->setMinValue(Paddles::MIN_DEJITTER); @@ -186,7 +187,7 @@ void InputDialog::addDevicePortTab() // Add paddle speed (digital emulation) ypos += lineHeight + VGAP * (3 - 2); - myDPaddleSpeed = new SliderWidget(myTab, _font, HBORDER, ypos - 1, 13 * fontWidth, lineHeight, + myDPaddleSpeed = new SliderWidget(myTab, _font, HBORDER, ypos - 1, swidth, lineHeight, "Digital paddle sensitivity", lwidth, kDPSpeedChanged, 4 * fontWidth, "%"); myDPaddleSpeed->setMinValue(1); myDPaddleSpeed->setMaxValue(20); @@ -194,9 +195,11 @@ void InputDialog::addDevicePortTab() wid.push_back(myDPaddleSpeed); ypos += lineHeight + VGAP * (3 - 2); - myAutoFireRate = new SliderWidget(myTab, _font, HBORDER, ypos - 1, 13 * fontWidth, lineHeight, - "Autofire rate", - lwidth, kAutoFireChanged, 5 * fontWidth, "Hz"); + myAutoFire = new CheckboxWidget(myTab, _font, HBORDER, ypos + 1, "Autofire", kAutoFireChanged); + wid.push_back(myAutoFire); + + myAutoFireRate = new SliderWidget(myTab, _font, HBORDER + lwidth - fontWidth * 5, + ypos - 1, swidth, lineHeight, "Rate ", 0, kAutoFireRate, 5 * fontWidth, "Hz"); myAutoFireRate->setMinValue(0); myAutoFireRate->setMaxValue(30); myAutoFireRate->setTickmarkIntervals(6); wid.push_back(myAutoFireRate); @@ -204,13 +207,13 @@ void InputDialog::addDevicePortTab() // Add 'allow all 4 directions' for joystick ypos += lineHeight + VGAP * (4 - 2); myAllowAll4 = new CheckboxWidget(myTab, _font, HBORDER, ypos, - "Allow all 4 directions on joystick"); + "Allow all 4 directions on joystick"); wid.push_back(myAllowAll4); // Enable/disable modifier key-combos ypos += lineHeight + VGAP; myModCombo = new CheckboxWidget(myTab, _font, HBORDER, ypos, - "Use modifier key combos"); + "Use modifier key combos"); wid.push_back(myModCombo); ypos += lineHeight + VGAP; @@ -264,6 +267,7 @@ void InputDialog::addMouseTab() HBORDER = Dialog::hBorder(), VGAP = Dialog::vGap(), INDENT = Dialog::indent(); + const int swidth = 13 * fontWidth; int xpos = HBORDER, ypos, lwidth, pwidth, tabID; WidgetArray wid; VariantList items; @@ -289,7 +293,7 @@ void InputDialog::addMouseTab() // Add paddle speed (mouse emulation) xpos += INDENT; ypos += lineHeight + VGAP; lwidth -= INDENT; - myMPaddleSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myMPaddleSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Paddle", lwidth, kMPSpeedChanged, 4 * fontWidth, "%"); myMPaddleSpeed->setMinValue(1); myMPaddleSpeed->setMaxValue(20); @@ -298,7 +302,7 @@ void InputDialog::addMouseTab() // Add trackball speed ypos += lineHeight + VGAP; - myTrackBallSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myTrackBallSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Trackball", lwidth, kTBSpeedChanged, 4 * fontWidth, "%"); myTrackBallSpeed->setMinValue(1); myTrackBallSpeed->setMaxValue(20); @@ -307,7 +311,7 @@ void InputDialog::addMouseTab() // Add driving controller speed ypos += lineHeight + VGAP; - myDrivingSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, 13 * fontWidth, lineHeight, + myDrivingSpeed = new SliderWidget(myTab, _font, xpos, ypos - 1, swidth, lineHeight, "Driving controller", lwidth, kDCSpeedChanged, 4 * fontWidth, "%"); myDrivingSpeed->setMinValue(1); myDrivingSpeed->setMaxValue(20); @@ -384,6 +388,9 @@ void InputDialog::loadConfig() // Driving controller speed myDrivingSpeed->setValue(settings.getInt("dcsense")); + // Autofire + myAutoFire->setState(settings.getBool("autofire")); + // Autofire rate myAutoFireRate->setValue(settings.getInt("autofirerate")); @@ -462,7 +469,11 @@ void InputDialog::saveConfig() settings.setValue("dsense", sensitivity); Paddles::setDigitalSensitivity(sensitivity); - // Autofire rate + // Autofire mode & rate + bool enabled = myAutoFire->getState(); + settings.setValue("autofire", enabled); + Controller::setAutoFire(enabled); + int rate = myAutoFireRate->getValue(); settings.setValue("autofirerate", rate); Controller::setAutoFireRate(rate); @@ -550,6 +561,9 @@ void InputDialog::setDefaults() // Paddle speed (digital) myDPaddleSpeed->setValue(10); + // Autofire + myAutoFire->setState(false); + // Autofire rate myAutoFireRate->setValue(0); @@ -733,6 +747,7 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd, break; case kAutoFireChanged: + case kAutoFireRate: updateAutoFireRate(); break; @@ -806,8 +821,10 @@ void InputDialog::updateDejitterReaction() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::updateAutoFireRate() { + bool enable = myAutoFire->getState(); int rate = myAutoFireRate->getValue(); + myAutoFireRate->setEnabled(enable); myAutoFireRate->setValueLabel(rate ? std::to_string(rate) : "Off"); myAutoFireRate->setValueUnit(rate ? " Hz" : ""); } diff --git a/src/gui/InputDialog.hxx b/src/gui/InputDialog.hxx index e5a2d1ced..2ba335b13 100644 --- a/src/gui/InputDialog.hxx +++ b/src/gui/InputDialog.hxx @@ -78,6 +78,7 @@ class InputDialog : public Dialog kDejitterReChanged = 'JRch', kDPSpeedChanged = 'DSch', kAutoFireChanged = 'AFch', + kAutoFireRate = 'AFra', kTBSpeedChanged = 'TBch', kDCSpeedChanged = 'DCch', kDBButtonPressed = 'DBbp', @@ -104,6 +105,7 @@ class InputDialog : public Dialog SliderWidget* myDejitterBase{nullptr}; SliderWidget* myDejitterDiff{nullptr}; SliderWidget* myDPaddleSpeed{nullptr}; + CheckboxWidget* myAutoFire{nullptr}; SliderWidget* myAutoFireRate{nullptr}; CheckboxWidget* myAllowAll4{nullptr}; CheckboxWidget* myModCombo{nullptr};