From 842a29b0aedd2e5db59128f3b25b06d803d27386 Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Sun, 28 Aug 2016 00:20:03 -0400 Subject: [PATCH 1/6] Add Frame Advance --- Common/KeyMap.cpp | 50 +++++++++++++++++++++++++------------------- Common/KeyMap.h | 1 + Core/HLE/sceCtrl.cpp | 10 ++++----- UI/EmuScreen.cpp | 33 +++++++++++++++++++++++++---- 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 1b9ef81d4b18..7ebe1676e4cc 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -74,6 +74,7 @@ static const DefMappingStruct defaultQwertyKeyboardKeyMap[] = { {VIRTKEY_UNTHROTTLE, NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, + {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_REWIND , NKCODE_DEL}, {VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT}, }; @@ -103,6 +104,7 @@ static const DefMappingStruct defaultAzertyKeyboardKeyMap[] = { {VIRTKEY_RAPID_FIRE, NKCODE_SHIFT_LEFT}, {VIRTKEY_UNTHROTTLE, NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, + {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, {VIRTKEY_REWIND , NKCODE_DEL}, {VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT}, @@ -133,6 +135,7 @@ static const DefMappingStruct defaultQwertzKeyboardKeyMap[] = { {VIRTKEY_RAPID_FIRE, NKCODE_SHIFT_LEFT}, {VIRTKEY_UNTHROTTLE, NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, + {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, {VIRTKEY_REWIND , NKCODE_DEL}, {VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT}, @@ -204,6 +207,7 @@ static const DefMappingStruct defaultBlackberryQWERTYKeyMap[] = { {VIRTKEY_UNTHROTTLE , NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, + {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_REWIND , NKCODE_DEL}, }; @@ -218,34 +222,34 @@ static const DefMappingStruct defaultPadMap[] = { {CTRL_RIGHT , JOYSTICK_AXIS_HAT_X, +1}, {CTRL_UP , JOYSTICK_AXIS_HAT_Y, -1}, {CTRL_DOWN , JOYSTICK_AXIS_HAT_Y, +1}, - {CTRL_START , NKCODE_BUTTON_START}, + {CTRL_START , NKCODE_BUTTON_START}, {CTRL_SELECT , NKCODE_BUTTON_SELECT}, - {CTRL_LTRIGGER , NKCODE_BUTTON_L1}, - {CTRL_RTRIGGER , NKCODE_BUTTON_R1}, - {VIRTKEY_UNTHROTTLE , NKCODE_BUTTON_R2}, + {CTRL_LTRIGGER , NKCODE_BUTTON_L1}, + {CTRL_RTRIGGER , NKCODE_BUTTON_R1}, + {VIRTKEY_UNTHROTTLE , NKCODE_BUTTON_R2}, {VIRTKEY_PAUSE , NKCODE_BUTTON_THUMBR}, - {VIRTKEY_SPEED_TOGGLE, NKCODE_BUTTON_L2}, - {VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1}, - {VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1}, - {VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1}, - {VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1}, + {VIRTKEY_SPEED_TOGGLE, NKCODE_BUTTON_L2}, + {VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1}, + {VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1}, + {VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1}, + {VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1}, #else - {CTRL_CROSS , NKCODE_BUTTON_2}, - {CTRL_CIRCLE , NKCODE_BUTTON_3}, - {CTRL_SQUARE , NKCODE_BUTTON_4}, - {CTRL_TRIANGLE , NKCODE_BUTTON_1}, + {CTRL_CROSS , NKCODE_BUTTON_2}, + {CTRL_CIRCLE , NKCODE_BUTTON_3}, + {CTRL_SQUARE , NKCODE_BUTTON_4}, + {CTRL_TRIANGLE , NKCODE_BUTTON_1}, {CTRL_UP , NKCODE_DPAD_UP}, {CTRL_RIGHT , NKCODE_DPAD_RIGHT}, {CTRL_DOWN , NKCODE_DPAD_DOWN}, {CTRL_LEFT , NKCODE_DPAD_LEFT}, {CTRL_START , NKCODE_BUTTON_10}, - {CTRL_SELECT , NKCODE_BUTTON_9}, - {CTRL_LTRIGGER , NKCODE_BUTTON_7}, - {CTRL_RTRIGGER , NKCODE_BUTTON_8}, - {VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1}, - {VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1}, - {VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1}, - {VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1}, + {CTRL_SELECT , NKCODE_BUTTON_9}, + {CTRL_LTRIGGER , NKCODE_BUTTON_7}, + {CTRL_RTRIGGER , NKCODE_BUTTON_8}, + {VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1}, + {VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1}, + {VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1}, + {VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1}, #endif }; @@ -583,7 +587,7 @@ const KeyMap_IntStrPair key_names[] = { {NKCODE_NUMPAD_7, "Num7"}, {NKCODE_NUMPAD_8, "Num8"}, {NKCODE_NUMPAD_9, "Num9"}, - + {NKCODE_LANGUAGE_SWITCH, "Language"}, {NKCODE_MANNER_MODE, "Manner"}, {NKCODE_3D_MODE, "3D Mode"}, @@ -607,7 +611,7 @@ const KeyMap_IntStrPair key_names[] = { {NKCODE_EXT_MOUSEWHEEL_UP, "MWheelU"}, {NKCODE_EXT_MOUSEWHEEL_DOWN, "MWheelD"}, - {NKCODE_START_QUESTION, "¿"}, + {NKCODE_START_QUESTION, "¿"}, {NKCODE_LEFTBRACE, "{"}, {NKCODE_RIGHTBRACE, "}"}, }; @@ -672,6 +676,7 @@ const KeyMap_IntStrPair psp_button_names[] = { {VIRTKEY_UNTHROTTLE, "Unthrottle"}, {VIRTKEY_SPEED_TOGGLE, "SpeedToggle"}, {VIRTKEY_PAUSE, "Pause"}, + {VIRTKEY_FRAME_ADVANCE, "Frame Advance"}, #ifndef MOBILE_DEVICE {VIRTKEY_REWIND, "Rewind"}, #endif @@ -980,6 +985,7 @@ void AutoConfForPad(const std::string &name) { // Add a couple of convenient keyboard mappings by default, too. g_controllerMap[VIRTKEY_PAUSE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE)); g_controllerMap[VIRTKEY_UNTHROTTLE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_TAB)); + g_controllerMap[VIRTKEY_FRAME_ADVANCE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_F)); #endif } diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 6adcd03b3632..4f21dfcb3e44 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -50,6 +50,7 @@ enum { VIRTKEY_ANALOG_LIGHTLY = 0x10011, VIRTKEY_AXIS_SWAP = 0x10012, VIRTKEY_DEVMENU = 0x10013, + VIRTKEY_FRAME_ADVANCE = 0x10014, VIRTKEY_LAST, VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST }; diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 298ada31a7e4..95d41e9e8c95 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -102,7 +102,7 @@ const u32 CTRL_EMU_RAPIDFIRE_MASK = CTRL_UP | CTRL_DOWN | CTRL_LEFT | CTRL_RIGHT static void __CtrlUpdateLatch() { lock_guard guard(ctrlMutex); - + // Copy in the current data to the current buffer. ctrlBufs[ctrlBuf] = ctrlCurrent; u32 buttons = ctrlCurrent.buttons; @@ -119,7 +119,7 @@ static void __CtrlUpdateLatch() latch.btnRelease |= ~buttons; dialogBtnMake |= buttons & changed; ctrlLatchBufs++; - + ctrlOldButtons = buttons; ctrlBufs[ctrlBuf].frame = (u32) CoreTiming::GetGlobalTimeUs(); @@ -327,7 +327,7 @@ void __CtrlInit() void __CtrlDoState(PointerWrap &p) { lock_guard guard(ctrlMutex); - + auto s = p.Section("sceCtrl", 1, 3); if (!s) return; @@ -519,7 +519,7 @@ static u32 sceCtrlReadLatch(u32 latchDataPtr) return __CtrlResetLatch(); } -static const HLEFunction sceCtrl[] = +static const HLEFunction sceCtrl[] = { {0X3E65A0EA, nullptr, "sceCtrlInit", '?', "" }, //(int unknown), init with 0 {0X1F4011E6, &WrapU_U, "sceCtrlSetSamplingMode", 'x', "x" }, @@ -538,7 +538,7 @@ static const HLEFunction sceCtrl[] = {0X6841BE1A, nullptr, "sceCtrlSetRapidFire", '?', "" }, {0XA7144800, &WrapI_II, "sceCtrlSetIdleCancelThreshold", 'i', "ii"}, {0X687660FA, &WrapI_UU, "sceCtrlGetIdleCancelThreshold", 'i', "xx"}, -}; +}; void Register_sceCtrl() { diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 3e2bcc1a2b1c..7abfbaae243f 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -70,10 +70,22 @@ #include "Windows/MainWindow.h" #endif +bool frameStep_; + +static void __EmuScreenVblank() +{ + if (frameStep_) + { + frameStep_ = false; + Core_EnableStepping(true); + } +} + EmuScreen::EmuScreen(const std::string &filename) : bootPending_(true), gamePath_(filename), invalid_(true), quit_(false), pauseTrigger_(false), saveStatePreviewShownTime_(0.0), saveStatePreview_(nullptr) { memset(axisState_, 0, sizeof(axisState_)); saveStateSlot_ = SaveState::GetCurrentSlot(); + __DisplayListenVblank(__EmuScreenVblank); } void EmuScreen::bootGame(const std::string &filename) { @@ -174,7 +186,7 @@ void EmuScreen::bootComplete() { NOTICE_LOG(BOOT, "Loading %s...", PSP_CoreParameter().fileToStart.c_str()); autoLoad(); - I18NCategory *sc = GetI18NCategory("Screen"); + I18NCategory *sc = GetI18NCategory("Screen"); #ifndef MOBILE_DEVICE if (g_Config.bFirstRun) { @@ -341,7 +353,7 @@ bool EmuScreen::touch(const TouchInput &touch) { } void EmuScreen::onVKeyDown(int virtualKeyCode) { - I18NCategory *sc = GetI18NCategory("Screen"); + I18NCategory *sc = GetI18NCategory("Screen"); switch (virtualKeyCode) { case VIRTKEY_UNTHROTTLE: @@ -363,6 +375,19 @@ void EmuScreen::onVKeyDown(int virtualKeyCode) { pauseTrigger_ = true; break; + case VIRTKEY_FRAME_ADVANCE: + // If game is running, pause emulation immediately. Otherwise, advance a single frame. + if (Core_IsStepping()) + { + frameStep_ = true; + Core_EnableStepping(false); + } + else if (!frameStep_) + { + Core_EnableStepping(true); + } + break; + case VIRTKEY_AXIS_SWAP: KeyMap::SwapAxis(); break; @@ -778,7 +803,7 @@ void EmuScreen::update(InputState &input) { } float delta_y = tiltInputCurve(normalized_input_y * 2.0 * (g_Config.iTiltSensitivityY)) ; - + if (g_Config.bInvertTiltY) { delta_y *= -1; } @@ -787,7 +812,7 @@ void EmuScreen::update(InputState &input) { leftstick_x += clamp1(delta_x); __CtrlSetAnalogX(clamp1(leftstick_x), CTRL_STICK_LEFT); - + leftstick_y += clamp1(delta_y); __CtrlSetAnalogY(clamp1(leftstick_y), CTRL_STICK_LEFT); } From e208eff8abf11bb2a4b47e4ba1b5326961f620de Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Sun, 28 Aug 2016 18:18:44 -0400 Subject: [PATCH 2/6] Set frameStep_ to false on EmuScreen start --- UI/EmuScreen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 7abfbaae243f..02d9bb108c73 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -86,6 +86,7 @@ EmuScreen::EmuScreen(const std::string &filename) memset(axisState_, 0, sizeof(axisState_)); saveStateSlot_ = SaveState::GetCurrentSlot(); __DisplayListenVblank(__EmuScreenVblank); + frameStep_ = false; } void EmuScreen::bootGame(const std::string &filename) { From 4ab71eb936c20568e1e1b7ca89649a51729f7e30 Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Mon, 29 Aug 2016 15:34:00 -0400 Subject: [PATCH 3/6] Add check for numFlips to advance per drawn frame --- UI/EmuScreen.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 02d9bb108c73..967f7d7f6b3e 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -71,13 +71,15 @@ #endif bool frameStep_; +int lastNumFlips; static void __EmuScreenVblank() { - if (frameStep_) + if (frameStep_ && lastNumFlips != gpuStats.numFlips) { frameStep_ = false; Core_EnableStepping(true); + lastNumFlips = gpuStats.numFlips; } } @@ -87,6 +89,7 @@ EmuScreen::EmuScreen(const std::string &filename) saveStateSlot_ = SaveState::GetCurrentSlot(); __DisplayListenVblank(__EmuScreenVblank); frameStep_ = false; + lastNumFlips = gpuStats.numFlips; } void EmuScreen::bootGame(const std::string &filename) { From c726691aba001a3236d0edc08677d985565c5dc0 Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Mon, 29 Aug 2016 16:39:16 -0400 Subject: [PATCH 4/6] Remove all default bindings for Frame Advance --- Common/KeyMap.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 7ebe1676e4cc..a321ec63f404 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -74,7 +74,6 @@ static const DefMappingStruct defaultQwertyKeyboardKeyMap[] = { {VIRTKEY_UNTHROTTLE, NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, - {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_REWIND , NKCODE_DEL}, {VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT}, }; @@ -104,7 +103,6 @@ static const DefMappingStruct defaultAzertyKeyboardKeyMap[] = { {VIRTKEY_RAPID_FIRE, NKCODE_SHIFT_LEFT}, {VIRTKEY_UNTHROTTLE, NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, - {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, {VIRTKEY_REWIND , NKCODE_DEL}, {VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT}, @@ -135,7 +133,6 @@ static const DefMappingStruct defaultQwertzKeyboardKeyMap[] = { {VIRTKEY_RAPID_FIRE, NKCODE_SHIFT_LEFT}, {VIRTKEY_UNTHROTTLE, NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, - {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, {VIRTKEY_REWIND , NKCODE_DEL}, {VIRTKEY_ANALOG_LIGHTLY, NKCODE_SHIFT_RIGHT}, @@ -207,7 +204,6 @@ static const DefMappingStruct defaultBlackberryQWERTYKeyMap[] = { {VIRTKEY_UNTHROTTLE , NKCODE_TAB}, {VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE}, {VIRTKEY_PAUSE , NKCODE_ESCAPE}, - {VIRTKEY_FRAME_ADVANCE, NKCODE_F}, {VIRTKEY_REWIND , NKCODE_DEL}, }; @@ -985,7 +981,6 @@ void AutoConfForPad(const std::string &name) { // Add a couple of convenient keyboard mappings by default, too. g_controllerMap[VIRTKEY_PAUSE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE)); g_controllerMap[VIRTKEY_UNTHROTTLE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_TAB)); - g_controllerMap[VIRTKEY_FRAME_ADVANCE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_F)); #endif } From f090551c2a062d82d2847beacf8c995d0ad5f72d Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Tue, 30 Aug 2016 09:09:38 -0400 Subject: [PATCH 5/6] Make variables static --- UI/EmuScreen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 967f7d7f6b3e..0122b945332d 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -70,8 +70,8 @@ #include "Windows/MainWindow.h" #endif -bool frameStep_; -int lastNumFlips; +static bool frameStep_; +static int lastNumFlips; static void __EmuScreenVblank() { From 8c96e921999c920f37eb915c0a084f71d7f7a32e Mon Sep 17 00:00:00 2001 From: Chris Burgener Date: Tue, 30 Aug 2016 10:03:16 -0400 Subject: [PATCH 6/6] Hide Frame Advance from mobile devices --- Common/KeyMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index a321ec63f404..c1a0a4d932d5 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -672,8 +672,8 @@ const KeyMap_IntStrPair psp_button_names[] = { {VIRTKEY_UNTHROTTLE, "Unthrottle"}, {VIRTKEY_SPEED_TOGGLE, "SpeedToggle"}, {VIRTKEY_PAUSE, "Pause"}, - {VIRTKEY_FRAME_ADVANCE, "Frame Advance"}, #ifndef MOBILE_DEVICE + {VIRTKEY_FRAME_ADVANCE, "Frame Advance"}, {VIRTKEY_REWIND, "Rewind"}, #endif {VIRTKEY_SAVE_STATE, "Save State"},