2014-10-04 23:31:48 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2012-2015 - Michael Lelli
|
|
|
|
* Copyright (C) 2014-2015 - Jay McCarthy
|
2014-10-04 23:31:48 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-21 22:23:06 +00:00
|
|
|
#include <file/file_path.h>
|
2015-03-15 03:30:46 +00:00
|
|
|
#include <retro_inline.h>
|
2014-10-22 02:27:51 +00:00
|
|
|
#include "dynamic.h"
|
2014-10-04 23:31:48 +00:00
|
|
|
#include "performance.h"
|
2014-10-21 17:11:32 +00:00
|
|
|
#include "retroarch_logger.h"
|
2014-10-04 23:31:48 +00:00
|
|
|
#include "intl/intl.h"
|
2015-01-09 16:40:47 +00:00
|
|
|
#include "retroarch.h"
|
2015-01-09 17:40:33 +00:00
|
|
|
#include "runloop.h"
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
2015-01-10 03:53:37 +00:00
|
|
|
#include "menu/menu.h"
|
2014-10-04 23:31:48 +00:00
|
|
|
#endif
|
|
|
|
|
2014-10-20 19:32:53 +00:00
|
|
|
#ifdef HAVE_NETPLAY
|
|
|
|
#include "netplay.h"
|
|
|
|
#endif
|
|
|
|
|
2015-03-15 02:21:58 +00:00
|
|
|
struct runloop g_runloop;
|
|
|
|
|
2015-01-10 03:18:54 +00:00
|
|
|
/* Convenience macros. */
|
|
|
|
#define check_oneshot_func(trigger_input) (check_is_oneshot(BIT64_GET(trigger_input, RARCH_FRAMEADVANCE), BIT64_GET(trigger_input, RARCH_REWIND)))
|
|
|
|
#define check_slowmotion_func(input) (check_slowmotion(BIT64_GET(input, RARCH_SLOWMOTION)))
|
|
|
|
#define check_quit_key_func(input) (BIT64_GET(input, RARCH_QUIT_KEY))
|
|
|
|
#define check_pause_func(input) (check_pause(BIT64_GET(input, RARCH_PAUSE_TOGGLE), BIT64_GET(input, RARCH_FRAMEADVANCE)))
|
|
|
|
#define check_stateslots_func(trigger_input) (check_stateslots(BIT64_GET(trigger_input, RARCH_STATE_SLOT_PLUS), BIT64_GET(trigger_input, RARCH_STATE_SLOT_MINUS)))
|
|
|
|
#define check_rewind_func(input) (check_rewind(BIT64_GET(input, RARCH_REWIND)))
|
|
|
|
#define check_fast_forward_button_func(input, old_input, trigger_input) (check_fast_forward_button(BIT64_GET(trigger_input, RARCH_FAST_FORWARD_KEY), BIT64_GET(input, RARCH_FAST_FORWARD_HOLD_KEY), BIT64_GET(old_input, RARCH_FAST_FORWARD_HOLD_KEY)))
|
|
|
|
#define check_enter_menu_func(input) (BIT64_GET(input, RARCH_MENU_TOGGLE))
|
|
|
|
#define check_shader_dir_func(trigger_input) (check_shader_dir(BIT64_GET(trigger_input, RARCH_SHADER_NEXT), BIT64_GET(trigger_input, RARCH_SHADER_PREV)))
|
|
|
|
|
2015-01-07 02:53:36 +00:00
|
|
|
/**
|
|
|
|
* set_volume:
|
|
|
|
* @gain : amount of gain to be applied to current volume level.
|
|
|
|
*
|
|
|
|
* Adjusts the current audio volume level.
|
|
|
|
*
|
|
|
|
**/
|
2014-10-05 04:10:23 +00:00
|
|
|
static void set_volume(float gain)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-01-07 19:42:36 +00:00
|
|
|
char msg[PATH_MAX_LENGTH];
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-07 04:39:22 +00:00
|
|
|
g_settings.audio.volume += gain;
|
|
|
|
g_settings.audio.volume = max(g_settings.audio.volume, -80.0f);
|
|
|
|
g_settings.audio.volume = min(g_settings.audio.volume, 12.0f);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-07 04:39:22 +00:00
|
|
|
snprintf(msg, sizeof(msg), "Volume: %.1f dB", g_settings.audio.volume);
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(msg, 1, 180, true);
|
2014-10-04 23:31:48 +00:00
|
|
|
RARCH_LOG("%s\n", msg);
|
|
|
|
|
2014-10-07 04:39:22 +00:00
|
|
|
g_extern.audio_data.volume_gain = db_to_gain(g_settings.audio.volume);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 02:53:36 +00:00
|
|
|
/**
|
|
|
|
* check_pause:
|
|
|
|
* @pressed : was libretro pause key pressed?
|
|
|
|
* @frameadvance_pressed : was frameadvance key pressed?
|
|
|
|
*
|
|
|
|
* Check if libretro pause key was pressed. If so, pause or
|
|
|
|
* unpause the libretro core.
|
|
|
|
*
|
|
|
|
* Returns: true if libretro pause key was toggled, otherwise false.
|
|
|
|
**/
|
2014-10-08 14:12:00 +00:00
|
|
|
static bool check_pause(bool pressed, bool frameadvance_pressed)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
static bool old_focus = true;
|
|
|
|
bool focus = true;
|
2015-03-07 11:36:50 +00:00
|
|
|
bool old_is_paused = g_runloop.is_paused;
|
2014-10-29 04:54:29 +00:00
|
|
|
unsigned cmd = RARCH_CMD_NONE;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
/* FRAMEADVANCE will set us into pause mode. */
|
2015-03-07 11:36:50 +00:00
|
|
|
pressed |= !g_runloop.is_paused && frameadvance_pressed;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
if (g_settings.pause_nonactive)
|
2015-02-10 16:14:40 +00:00
|
|
|
focus = video_driver_has_focus();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
if (focus && pressed)
|
2014-10-29 04:54:29 +00:00
|
|
|
cmd = RARCH_CMD_PAUSE_TOGGLE;
|
2014-10-04 23:31:48 +00:00
|
|
|
else if (focus && !old_focus)
|
2014-10-29 04:54:29 +00:00
|
|
|
cmd = RARCH_CMD_UNPAUSE;
|
2014-10-04 23:31:48 +00:00
|
|
|
else if (!focus && old_focus)
|
2014-10-29 04:54:29 +00:00
|
|
|
cmd = RARCH_CMD_PAUSE;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-05 02:10:00 +00:00
|
|
|
old_focus = focus;
|
|
|
|
|
2014-10-29 04:54:29 +00:00
|
|
|
if (cmd != RARCH_CMD_NONE)
|
|
|
|
rarch_main_command(cmd);
|
|
|
|
|
2015-03-07 11:36:50 +00:00
|
|
|
if (g_runloop.is_paused == old_is_paused)
|
2014-10-08 14:12:00 +00:00
|
|
|
return false;
|
2014-10-29 04:54:29 +00:00
|
|
|
|
2014-10-08 14:12:00 +00:00
|
|
|
return true;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 02:53:36 +00:00
|
|
|
/**
|
|
|
|
* check_is_oneshot:
|
|
|
|
* @oneshot_pressed : is this a oneshot frame?
|
|
|
|
* @rewind_pressed : was rewind key pressed?
|
|
|
|
*
|
|
|
|
* Checks if the current frame is one-shot frame type.
|
|
|
|
*
|
2015-01-09 21:03:33 +00:00
|
|
|
* Rewind buttons works like FRAMEREWIND when paused.
|
|
|
|
* We will one-shot in that case.
|
|
|
|
*
|
2015-01-07 02:53:36 +00:00
|
|
|
* Returns: true if libretro frame is one-shot, otherwise false..
|
|
|
|
*
|
|
|
|
**/
|
2015-03-15 03:30:46 +00:00
|
|
|
static INLINE bool check_is_oneshot(bool oneshot_pressed, bool rewind_pressed)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2014-10-05 03:18:46 +00:00
|
|
|
return (oneshot_pressed | rewind_pressed);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 15:29:46 +00:00
|
|
|
/**
|
|
|
|
* check_fast_forward_button:
|
|
|
|
* @fastforward_pressed : is fastforward key pressed?
|
|
|
|
* @hold_pressed : is fastforward key pressed and held?
|
|
|
|
* @old_hold_pressed : was fastforward key pressed and held the last frame?
|
|
|
|
*
|
|
|
|
* Checks if the fast forward key has been pressed for this frame.
|
|
|
|
*
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static void check_fast_forward_button(bool fastforward_pressed,
|
|
|
|
bool hold_pressed, bool old_hold_pressed)
|
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
|
2015-01-07 02:53:36 +00:00
|
|
|
/* To avoid continous switching if we hold the button down, we require
|
|
|
|
* that the button must go from pressed to unpressed back to pressed
|
|
|
|
* to be able to toggle between then.
|
|
|
|
*/
|
2014-10-04 23:31:48 +00:00
|
|
|
if (fastforward_pressed)
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->nonblock_state = !driver->nonblock_state;
|
2014-10-04 23:31:48 +00:00
|
|
|
else if (old_hold_pressed != hold_pressed)
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->nonblock_state = hold_pressed;
|
2014-10-05 03:39:50 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_set_nonblock_state(driver->nonblock_state);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 15:29:46 +00:00
|
|
|
/**
|
|
|
|
* check_stateslots:
|
|
|
|
* @pressed_increase : is state slot increase key pressed?
|
|
|
|
* @pressed_decrease : is state slot decrease key pressed?
|
|
|
|
*
|
|
|
|
* Checks if the state increase/decrease keys have been pressed
|
|
|
|
* for this frame.
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static void check_stateslots(bool pressed_increase, bool pressed_decrease)
|
|
|
|
{
|
2015-01-07 19:42:36 +00:00
|
|
|
char msg[PATH_MAX_LENGTH];
|
2014-10-05 03:50:04 +00:00
|
|
|
|
2014-10-04 23:31:48 +00:00
|
|
|
/* Save state slots */
|
|
|
|
if (pressed_increase)
|
|
|
|
g_settings.state_slot++;
|
2014-10-05 03:50:04 +00:00
|
|
|
else if (pressed_decrease)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
if (g_settings.state_slot > 0)
|
|
|
|
g_settings.state_slot--;
|
2014-10-04 23:59:15 +00:00
|
|
|
}
|
2014-10-05 03:50:04 +00:00
|
|
|
else
|
|
|
|
return;
|
2014-10-04 23:59:15 +00:00
|
|
|
|
2014-10-05 03:50:04 +00:00
|
|
|
snprintf(msg, sizeof(msg), "State slot: %d",
|
|
|
|
g_settings.state_slot);
|
2014-10-04 23:59:15 +00:00
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(msg, 1, 180, true);
|
2014-10-04 23:59:15 +00:00
|
|
|
|
2014-10-05 03:50:04 +00:00
|
|
|
RARCH_LOG("%s\n", msg);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 03:30:46 +00:00
|
|
|
static INLINE void setup_rewind_audio(void)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* Push audio ready to be played. */
|
|
|
|
g_extern.audio_data.rewind_ptr = g_extern.audio_data.rewind_size;
|
|
|
|
|
|
|
|
for (i = 0; i < g_extern.audio_data.data_ptr; i += 2)
|
|
|
|
{
|
|
|
|
g_extern.audio_data.rewind_buf[--g_extern.audio_data.rewind_ptr] =
|
|
|
|
g_extern.audio_data.conv_outsamples[i + 1];
|
|
|
|
|
|
|
|
g_extern.audio_data.rewind_buf[--g_extern.audio_data.rewind_ptr] =
|
|
|
|
g_extern.audio_data.conv_outsamples[i + 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
g_extern.audio_data.data_ptr = 0;
|
|
|
|
}
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
/**
|
|
|
|
* check_rewind:
|
|
|
|
* @pressed : was rewind key pressed or held?
|
|
|
|
*
|
|
|
|
* Checks if rewind toggle/hold was being pressed and/or held.
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static void check_rewind(bool pressed)
|
|
|
|
{
|
|
|
|
static bool first = true;
|
|
|
|
|
2015-02-16 17:09:00 +00:00
|
|
|
if (g_extern.rewind.frame_is_reverse)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
/* We just rewound. Flush rewind audio buffer. */
|
|
|
|
retro_flush_audio(g_extern.audio_data.rewind_buf
|
|
|
|
+ g_extern.audio_data.rewind_ptr,
|
|
|
|
g_extern.audio_data.rewind_size - g_extern.audio_data.rewind_ptr);
|
|
|
|
|
2015-02-16 17:09:00 +00:00
|
|
|
g_extern.rewind.frame_is_reverse = false;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-16 17:09:00 +00:00
|
|
|
if (!g_extern.rewind.state)
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (pressed)
|
|
|
|
{
|
|
|
|
const void *buf = NULL;
|
|
|
|
|
2015-02-16 17:09:00 +00:00
|
|
|
if (state_manager_pop(g_extern.rewind.state, &buf))
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-02-16 17:09:00 +00:00
|
|
|
g_extern.rewind.frame_is_reverse = true;
|
2014-10-04 23:31:48 +00:00
|
|
|
setup_rewind_audio();
|
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(RETRO_MSG_REWINDING, 0,
|
2015-03-15 01:59:38 +00:00
|
|
|
g_runloop.is_paused ? 1 : 30, true);
|
2015-02-16 17:09:00 +00:00
|
|
|
pretro_unserialize(buf, g_extern.rewind.size);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
if (g_extern.bsv.movie)
|
|
|
|
bsv_movie_frame_rewind(g_extern.bsv.movie);
|
|
|
|
}
|
|
|
|
else
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(RETRO_MSG_REWIND_REACHED_END,
|
2015-03-15 01:59:38 +00:00
|
|
|
0, 30, true);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static unsigned cnt = 0;
|
|
|
|
|
|
|
|
cnt = (cnt + 1) % (g_settings.rewind_granularity ?
|
|
|
|
g_settings.rewind_granularity : 1); /* Avoid possible SIGFPE. */
|
|
|
|
|
|
|
|
if ((cnt == 0) || g_extern.bsv.movie)
|
|
|
|
{
|
|
|
|
void *state = NULL;
|
2015-02-16 17:09:00 +00:00
|
|
|
state_manager_push_where(g_extern.rewind.state, &state);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
RARCH_PERFORMANCE_INIT(rewind_serialize);
|
|
|
|
RARCH_PERFORMANCE_START(rewind_serialize);
|
2015-02-16 17:09:00 +00:00
|
|
|
pretro_serialize(state, g_extern.rewind.size);
|
2014-10-04 23:31:48 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(rewind_serialize);
|
|
|
|
|
2015-02-16 17:09:00 +00:00
|
|
|
state_manager_push_do(g_extern.rewind.state);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retro_set_rewind_callbacks();
|
|
|
|
}
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
/**
|
|
|
|
* check_slowmotion:
|
|
|
|
* @pressed : was slow motion key pressed or held?
|
|
|
|
*
|
|
|
|
* Checks if slowmotion toggle/hold was being pressed and/or held.
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static void check_slowmotion(bool pressed)
|
|
|
|
{
|
2015-03-07 11:36:50 +00:00
|
|
|
g_runloop.is_slowmotion = pressed;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-07 11:36:50 +00:00
|
|
|
if (!g_runloop.is_slowmotion)
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_settings.video.black_frame_insertion)
|
|
|
|
rarch_render_cached_frame();
|
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(g_extern.rewind.frame_is_reverse ?
|
|
|
|
"Slow motion rewind." : "Slow motion.", 0, 30, true);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_movie_init(void)
|
|
|
|
{
|
2015-01-07 19:42:36 +00:00
|
|
|
char path[PATH_MAX_LENGTH], msg[PATH_MAX_LENGTH];
|
2014-10-04 23:31:48 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
if (g_extern.bsv.movie)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
g_settings.rewind_granularity = 1;
|
|
|
|
|
|
|
|
if (g_settings.state_slot > 0)
|
|
|
|
{
|
|
|
|
snprintf(path, sizeof(path), "%s%d.bsv",
|
|
|
|
g_extern.bsv.movie_path, g_settings.state_slot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(path, sizeof(path), "%s.bsv",
|
|
|
|
g_extern.bsv.movie_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(msg, sizeof(msg), "Starting movie record to \"%s\".", path);
|
|
|
|
|
|
|
|
g_extern.bsv.movie = bsv_movie_init(path, RARCH_MOVIE_RECORD);
|
|
|
|
|
|
|
|
if (!g_extern.bsv.movie)
|
|
|
|
ret = false;
|
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(g_extern.bsv.movie ?
|
|
|
|
msg : "Failed to start movie record.", 1, 180, true);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
if (g_extern.bsv.movie)
|
|
|
|
RARCH_LOG("Starting movie record to \"%s\".\n", path);
|
|
|
|
else
|
|
|
|
RARCH_ERR("Failed to start movie record.\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
/**
|
|
|
|
* check_movie_record:
|
|
|
|
*
|
|
|
|
* Checks if movie is being recorded.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if movie is being recorded, otherwise false (0).
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static bool check_movie_record(void)
|
|
|
|
{
|
|
|
|
if (!g_extern.bsv.movie)
|
|
|
|
return false;
|
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(
|
|
|
|
RETRO_MSG_MOVIE_RECORD_STOPPING, 2, 180, true);
|
2014-10-04 23:31:48 +00:00
|
|
|
RARCH_LOG(RETRO_LOG_MOVIE_RECORD_STOPPING);
|
|
|
|
|
|
|
|
rarch_main_command(RARCH_CMD_BSV_MOVIE_DEINIT);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
/**
|
|
|
|
* check_movie_playback:
|
|
|
|
*
|
|
|
|
* Checks if movie is being played.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if movie is being played, otherwise false (0).
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static bool check_movie_playback(void)
|
|
|
|
{
|
|
|
|
if (!g_extern.bsv.movie_end)
|
|
|
|
return false;
|
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(
|
|
|
|
RETRO_MSG_MOVIE_PLAYBACK_ENDED, 1, 180, false);
|
2014-10-04 23:31:48 +00:00
|
|
|
RARCH_LOG(RETRO_LOG_MOVIE_PLAYBACK_ENDED);
|
|
|
|
|
|
|
|
rarch_main_command(RARCH_CMD_BSV_MOVIE_DEINIT);
|
|
|
|
|
|
|
|
g_extern.bsv.movie_end = false;
|
|
|
|
g_extern.bsv.movie_playback = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_movie(void)
|
|
|
|
{
|
|
|
|
if (g_extern.bsv.movie_playback)
|
|
|
|
return check_movie_playback();
|
|
|
|
if (!g_extern.bsv.movie)
|
|
|
|
return check_movie_init();
|
|
|
|
return check_movie_record();
|
|
|
|
}
|
|
|
|
|
2015-01-10 20:47:30 +00:00
|
|
|
/**
|
|
|
|
* check_shader_dir:
|
|
|
|
* @pressed_next : was next shader key pressed?
|
|
|
|
* @pressed_previous : was previous shader key pressed?
|
|
|
|
*
|
|
|
|
* Checks if any one of the shader keys has been pressed for this frame:
|
|
|
|
* a) Next shader index.
|
|
|
|
* b) Previous shader index.
|
|
|
|
*
|
|
|
|
* Will also immediately apply the shader.
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static void check_shader_dir(bool pressed_next, bool pressed_prev)
|
|
|
|
{
|
2015-01-07 19:42:36 +00:00
|
|
|
char msg[PATH_MAX_LENGTH];
|
2014-10-04 23:31:48 +00:00
|
|
|
const char *shader = NULL, *ext = NULL;
|
|
|
|
enum rarch_shader_type type = RARCH_SHADER_NONE;
|
|
|
|
|
2015-02-10 16:20:02 +00:00
|
|
|
if (!g_extern.shader_dir.list)
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (pressed_next)
|
|
|
|
{
|
|
|
|
g_extern.shader_dir.ptr = (g_extern.shader_dir.ptr + 1) %
|
|
|
|
g_extern.shader_dir.list->size;
|
|
|
|
}
|
|
|
|
else if (pressed_prev)
|
|
|
|
{
|
|
|
|
if (g_extern.shader_dir.ptr == 0)
|
|
|
|
g_extern.shader_dir.ptr = g_extern.shader_dir.list->size - 1;
|
|
|
|
else
|
|
|
|
g_extern.shader_dir.ptr--;
|
|
|
|
}
|
2014-10-05 03:46:27 +00:00
|
|
|
else
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
2014-10-05 03:46:27 +00:00
|
|
|
shader = g_extern.shader_dir.list->elems[g_extern.shader_dir.ptr].data;
|
|
|
|
ext = path_get_extension(shader);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-05 03:46:27 +00:00
|
|
|
if (strcmp(ext, "glsl") == 0 || strcmp(ext, "glslp") == 0)
|
|
|
|
type = RARCH_SHADER_GLSL;
|
|
|
|
else if (strcmp(ext, "cg") == 0 || strcmp(ext, "cgp") == 0)
|
|
|
|
type = RARCH_SHADER_CG;
|
2014-10-05 03:50:04 +00:00
|
|
|
else
|
2014-10-05 03:46:27 +00:00
|
|
|
return;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-05 03:46:27 +00:00
|
|
|
snprintf(msg, sizeof(msg), "Shader #%u: \"%s\".",
|
|
|
|
(unsigned)g_extern.shader_dir.ptr, shader);
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(msg, 1, 120, true);
|
2014-10-05 03:46:27 +00:00
|
|
|
RARCH_LOG("Applying shader \"%s\".\n", shader);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-02-10 16:20:02 +00:00
|
|
|
if (!video_driver_set_shader(type, shader))
|
2014-10-05 03:46:27 +00:00
|
|
|
RARCH_WARN("Failed to apply shader.\n");
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
/**
|
|
|
|
* check_cheats:
|
|
|
|
* @trigger_input : difference' input sample - difference
|
|
|
|
*
|
|
|
|
* Checks if any one of the cheat keys has been pressed for this frame:
|
|
|
|
* a) Next cheat index.
|
|
|
|
* b) Previous cheat index.
|
|
|
|
* c) Toggle on/off of current cheat index.
|
|
|
|
**/
|
2014-12-15 18:16:54 +00:00
|
|
|
static void check_cheats(retro_input_t trigger_input)
|
|
|
|
{
|
|
|
|
if (BIT64_GET(trigger_input, RARCH_CHEAT_INDEX_PLUS))
|
|
|
|
cheat_manager_index_next(g_extern.cheat);
|
|
|
|
else if (BIT64_GET(trigger_input, RARCH_CHEAT_INDEX_MINUS))
|
|
|
|
cheat_manager_index_prev(g_extern.cheat);
|
|
|
|
else if (BIT64_GET(trigger_input, RARCH_CHEAT_TOGGLE))
|
|
|
|
cheat_manager_toggle(g_extern.cheat);
|
|
|
|
}
|
|
|
|
|
2015-01-10 21:51:03 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
static void do_state_check_menu_toggle(void)
|
|
|
|
{
|
2015-03-07 11:36:50 +00:00
|
|
|
if (g_runloop.is_menu)
|
2015-01-10 21:51:03 +00:00
|
|
|
{
|
|
|
|
if (g_extern.main_is_init && !g_extern.libretro_dummy)
|
|
|
|
rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* do_pre_state_checks:
|
|
|
|
* @input : input sample for this frame
|
|
|
|
* @old_input : input sample of the previous frame
|
|
|
|
* @trigger_input : difference' input sample - difference
|
|
|
|
* between 'input' and 'old_input'
|
|
|
|
*
|
|
|
|
* Checks for state changes in this frame.
|
|
|
|
*
|
|
|
|
* Unlike do_state_checks(), this is performed for both
|
|
|
|
* the menu and the regular loop.
|
|
|
|
*
|
|
|
|
* Returns: 0.
|
|
|
|
**/
|
|
|
|
static int do_pre_state_checks(
|
|
|
|
retro_input_t input, retro_input_t old_input,
|
|
|
|
retro_input_t trigger_input)
|
|
|
|
{
|
|
|
|
if (BIT64_GET(trigger_input, RARCH_OVERLAY_NEXT))
|
|
|
|
rarch_main_command(RARCH_CMD_OVERLAY_NEXT);
|
|
|
|
|
2015-03-07 11:36:50 +00:00
|
|
|
if (!g_runloop.is_paused || g_runloop.is_menu)
|
2015-01-10 21:51:03 +00:00
|
|
|
{
|
|
|
|
if (BIT64_GET(trigger_input, RARCH_FULLSCREEN_TOGGLE_KEY))
|
|
|
|
rarch_main_command(RARCH_CMD_FULLSCREEN_TOGGLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BIT64_GET(trigger_input, RARCH_GRAB_MOUSE_TOGGLE))
|
|
|
|
rarch_main_command(RARCH_CMD_GRAB_MOUSE_TOGGLE);
|
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
if (check_enter_menu_func(trigger_input) || (g_extern.libretro_dummy))
|
|
|
|
do_state_check_menu_toggle();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-10 18:04:02 +00:00
|
|
|
#ifdef HAVE_NETPLAY
|
|
|
|
static int do_netplay_state_checks(
|
|
|
|
retro_input_t input, retro_input_t old_input,
|
|
|
|
retro_input_t trigger_input)
|
|
|
|
{
|
|
|
|
if (BIT64_GET(trigger_input, RARCH_NETPLAY_FLIP))
|
|
|
|
rarch_main_command(RARCH_CMD_NETPLAY_FLIP_PLAYERS);
|
|
|
|
|
|
|
|
if (BIT64_GET(trigger_input, RARCH_FULLSCREEN_TOGGLE_KEY))
|
|
|
|
rarch_main_command(RARCH_CMD_FULLSCREEN_TOGGLE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-10 18:07:53 +00:00
|
|
|
static int do_pause_state_checks(
|
|
|
|
retro_input_t input, retro_input_t old_input,
|
|
|
|
retro_input_t trigger_input)
|
|
|
|
{
|
|
|
|
check_pause_func(trigger_input);
|
|
|
|
|
2015-03-07 11:36:50 +00:00
|
|
|
if (!g_runloop.is_paused)
|
2015-02-10 18:07:53 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (BIT64_GET(trigger_input, RARCH_FULLSCREEN_TOGGLE_KEY))
|
|
|
|
{
|
|
|
|
rarch_main_command(RARCH_CMD_FULLSCREEN_TOGGLE);
|
|
|
|
rarch_render_cached_frame();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!check_oneshot_func(trigger_input))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-07 15:29:46 +00:00
|
|
|
/**
|
|
|
|
* do_state_checks:
|
|
|
|
* @input : input sample for this frame
|
|
|
|
* @old_input : input sample of the previous frame
|
|
|
|
* @trigger_input : difference' input sample - difference
|
|
|
|
* between 'input' and 'old_input'
|
|
|
|
*
|
|
|
|
* Checks for state changes in this frame.
|
|
|
|
*
|
|
|
|
* Returns: 1 if RetroArch is in pause mode, 0 otherwise.
|
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
static int do_state_checks(
|
|
|
|
retro_input_t input, retro_input_t old_input,
|
|
|
|
retro_input_t trigger_input)
|
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
|
2015-03-08 00:48:40 +00:00
|
|
|
if (g_runloop.is_idle)
|
|
|
|
return 1;
|
|
|
|
|
2014-10-05 13:48:06 +00:00
|
|
|
if (BIT64_GET(trigger_input, RARCH_SCREENSHOT))
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_main_command(RARCH_CMD_TAKE_SCREENSHOT);
|
|
|
|
|
2014-10-05 13:48:06 +00:00
|
|
|
if (BIT64_GET(trigger_input, RARCH_MUTE))
|
2014-10-08 14:07:19 +00:00
|
|
|
rarch_main_command(RARCH_CMD_AUDIO_MUTE_TOGGLE);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-05 13:48:06 +00:00
|
|
|
if (BIT64_GET(input, RARCH_VOLUME_UP))
|
2014-10-05 04:10:23 +00:00
|
|
|
set_volume(0.5f);
|
2014-10-05 13:48:06 +00:00
|
|
|
else if (BIT64_GET(input, RARCH_VOLUME_DOWN))
|
2014-10-05 04:10:23 +00:00
|
|
|
set_volume(-0.5f);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_NETPLAY
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->netplay_data)
|
2015-02-10 18:04:02 +00:00
|
|
|
return do_netplay_state_checks(input,
|
|
|
|
old_input, trigger_input);
|
2014-10-04 23:31:48 +00:00
|
|
|
#endif
|
2014-10-08 14:41:08 +00:00
|
|
|
|
2015-02-10 18:07:53 +00:00
|
|
|
if (do_pause_state_checks(input, old_input,
|
|
|
|
trigger_input))
|
|
|
|
return 1;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
check_fast_forward_button_func(input, old_input, trigger_input);
|
|
|
|
|
|
|
|
check_stateslots_func(trigger_input);
|
|
|
|
|
2014-10-05 13:48:06 +00:00
|
|
|
if (BIT64_GET(trigger_input, RARCH_SAVE_STATE_KEY))
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_main_command(RARCH_CMD_SAVE_STATE);
|
2014-10-05 13:48:06 +00:00
|
|
|
else if (BIT64_GET(trigger_input, RARCH_LOAD_STATE_KEY))
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_main_command(RARCH_CMD_LOAD_STATE);
|
|
|
|
|
|
|
|
check_rewind_func(input);
|
|
|
|
|
|
|
|
check_slowmotion_func(input);
|
|
|
|
|
2014-10-05 13:48:06 +00:00
|
|
|
if (BIT64_GET(trigger_input, RARCH_MOVIE_RECORD_TOGGLE))
|
2014-10-04 23:31:48 +00:00
|
|
|
check_movie();
|
|
|
|
|
|
|
|
check_shader_dir_func(trigger_input);
|
|
|
|
|
2014-10-05 13:48:06 +00:00
|
|
|
if (BIT64_GET(trigger_input, RARCH_DISK_EJECT_TOGGLE))
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_main_command(RARCH_CMD_DISK_EJECT_TOGGLE);
|
2014-10-05 13:48:06 +00:00
|
|
|
else if (BIT64_GET(trigger_input, RARCH_DISK_NEXT))
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_main_command(RARCH_CMD_DISK_NEXT);
|
2014-10-08 01:19:12 +00:00
|
|
|
else if (BIT64_GET(trigger_input, RARCH_DISK_PREV))
|
|
|
|
rarch_main_command(RARCH_CMD_DISK_PREV);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-05 13:48:06 +00:00
|
|
|
if (BIT64_GET(trigger_input, RARCH_RESET))
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_main_command(RARCH_CMD_RESET);
|
|
|
|
|
2014-12-15 18:16:54 +00:00
|
|
|
if (g_extern.cheat)
|
|
|
|
check_cheats(trigger_input);
|
2014-12-15 05:57:38 +00:00
|
|
|
|
2014-10-04 23:31:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
/**
|
|
|
|
* time_to_exit:
|
|
|
|
* @input : input sample for this frame
|
|
|
|
*
|
|
|
|
* rarch_main_iterate() checks this to see if it's time to
|
|
|
|
* exit out of the main loop.
|
|
|
|
*
|
|
|
|
* Reasons for exiting:
|
|
|
|
* a) Shutdown environment callback was invoked.
|
|
|
|
* b) Quit key was pressed.
|
|
|
|
* c) Frame count exceeds or equals maximum amount of frames to run.
|
|
|
|
* d) Video driver no longer alive.
|
|
|
|
* e) End of BSV movie and BSV EOF exit is true. (TODO/FIXME - explain better)
|
|
|
|
*
|
|
|
|
* Returns: 1 if any of the above conditions are true, otherwise 0.
|
|
|
|
**/
|
2015-03-15 03:30:46 +00:00
|
|
|
static INLINE int time_to_exit(retro_input_t input)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
if (
|
|
|
|
g_extern.system.shutdown
|
|
|
|
|| check_quit_key_func(input)
|
2015-03-07 12:14:04 +00:00
|
|
|
|| (g_runloop.frames.video.max &&
|
|
|
|
g_runloop.frames.video.count >= g_runloop.frames.video.max)
|
2014-10-04 23:31:48 +00:00
|
|
|
|| (g_extern.bsv.movie_end && g_extern.bsv.eof_exit)
|
2015-02-10 15:54:08 +00:00
|
|
|
|| !video_driver_is_alive()
|
2014-10-04 23:31:48 +00:00
|
|
|
)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-10 20:47:30 +00:00
|
|
|
/**
|
2015-03-08 11:30:15 +00:00
|
|
|
* rarch_update_frame_time:
|
2015-01-10 20:47:30 +00:00
|
|
|
*
|
|
|
|
* Updates frame timing if frame timing callback is in use by the core.
|
|
|
|
**/
|
2015-03-08 11:30:15 +00:00
|
|
|
static void rarch_update_frame_time(void)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2014-10-21 00:18:38 +00:00
|
|
|
retro_time_t curr_time = rarch_get_time_usec();
|
2015-01-09 21:24:38 +00:00
|
|
|
retro_time_t delta = curr_time - g_extern.system.frame_time_last;
|
2015-03-18 18:40:00 +00:00
|
|
|
bool is_locked_fps = g_runloop.is_paused || driver->nonblock_state;
|
|
|
|
is_locked_fps |= !!driver->recording_data;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
if (!g_extern.system.frame_time_last || is_locked_fps)
|
|
|
|
delta = g_extern.system.frame_time.reference;
|
|
|
|
|
2015-03-07 11:36:50 +00:00
|
|
|
if (!is_locked_fps && g_runloop.is_slowmotion)
|
2014-10-04 23:31:48 +00:00
|
|
|
delta /= g_settings.slowmotion_ratio;
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
g_extern.system.frame_time_last = curr_time;
|
|
|
|
|
|
|
|
if (is_locked_fps)
|
|
|
|
g_extern.system.frame_time_last = 0;
|
|
|
|
|
2014-10-04 23:31:48 +00:00
|
|
|
g_extern.system.frame_time.callback(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-10 20:47:30 +00:00
|
|
|
/**
|
2015-03-08 11:30:15 +00:00
|
|
|
* rarch_limit_frame_time:
|
2015-01-10 20:47:30 +00:00
|
|
|
*
|
|
|
|
* Limit frame time if fast forward ratio throttle is enabled.
|
|
|
|
**/
|
2015-03-08 11:30:15 +00:00
|
|
|
static void rarch_limit_frame_time(void)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-01-10 20:47:30 +00:00
|
|
|
double effective_fps, mft_f;
|
|
|
|
retro_time_t current, target = 0, to_sleep_ms = 0;
|
|
|
|
|
|
|
|
current = rarch_get_time_usec();
|
|
|
|
effective_fps = g_extern.system.av_info.timing.fps
|
2014-10-04 23:31:48 +00:00
|
|
|
* g_settings.fastforward_ratio;
|
2015-01-10 20:47:30 +00:00
|
|
|
mft_f = 1000000.0f / effective_fps;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-07 12:43:31 +00:00
|
|
|
g_runloop.frames.limit.minimum_time = (retro_time_t) roundf(mft_f);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-07 12:43:31 +00:00
|
|
|
target = g_runloop.frames.limit.last_time +
|
|
|
|
g_runloop.frames.limit.minimum_time;
|
2015-01-10 20:47:30 +00:00
|
|
|
to_sleep_ms = (target - current) / 1000;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-01-10 20:47:30 +00:00
|
|
|
if (to_sleep_ms <= 0)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-07 12:43:31 +00:00
|
|
|
g_runloop.frames.limit.last_time = rarch_get_time_usec();
|
2015-01-10 20:47:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rarch_sleep((unsigned int)to_sleep_ms);
|
|
|
|
|
|
|
|
/* Combat jitter a bit. */
|
2015-03-07 12:43:31 +00:00
|
|
|
g_runloop.frames.limit.last_time +=
|
|
|
|
g_runloop.frames.limit.minimum_time;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 08:25:48 +00:00
|
|
|
/**
|
|
|
|
* check_block_hotkey:
|
|
|
|
* @enable_hotkey : Is hotkey enable key enabled?
|
|
|
|
*
|
|
|
|
* Checks if 'hotkey enable' key is pressed.
|
|
|
|
**/
|
2015-02-15 00:03:19 +00:00
|
|
|
static bool check_block_hotkey(bool enable_hotkey)
|
2014-10-05 00:45:38 +00:00
|
|
|
{
|
|
|
|
bool use_hotkey_enable;
|
|
|
|
static const struct retro_keybind *bind =
|
|
|
|
&g_settings.input.binds[0][RARCH_ENABLE_HOTKEY];
|
2015-01-03 20:26:02 +00:00
|
|
|
static const struct retro_keybind *autoconf_bind =
|
|
|
|
&g_settings.input.autoconf_binds[0][RARCH_ENABLE_HOTKEY];
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2014-10-05 00:45:38 +00:00
|
|
|
|
|
|
|
/* Don't block the check to RARCH_ENABLE_HOTKEY
|
|
|
|
* unless we're really supposed to. */
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->block_hotkey = driver->block_input;
|
2014-10-05 00:45:38 +00:00
|
|
|
|
|
|
|
// If we haven't bound anything to this, always allow hotkeys.
|
|
|
|
use_hotkey_enable = bind->key != RETROK_UNKNOWN ||
|
|
|
|
bind->joykey != NO_BTN ||
|
2015-01-03 20:26:02 +00:00
|
|
|
bind->joyaxis != AXIS_NONE ||
|
|
|
|
autoconf_bind->key != RETROK_UNKNOWN ||
|
|
|
|
autoconf_bind->joykey != NO_BTN ||
|
2015-02-10 21:28:08 +00:00
|
|
|
autoconf_bind->joyaxis != AXIS_NONE;
|
2014-10-05 00:45:38 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->block_hotkey = driver->block_input ||
|
2014-10-05 00:45:38 +00:00
|
|
|
(use_hotkey_enable && !enable_hotkey);
|
|
|
|
|
|
|
|
/* If we hold ENABLE_HOTKEY button, block all libretro input to allow
|
|
|
|
* hotkeys to be bound to same keys as RetroPad. */
|
2015-02-15 00:03:19 +00:00
|
|
|
return (use_hotkey_enable && enable_hotkey);
|
2014-10-05 00:45:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 15:29:46 +00:00
|
|
|
/**
|
|
|
|
* input_keys_pressed:
|
|
|
|
*
|
|
|
|
* Grab an input sample for this frame.
|
2014-10-05 00:45:38 +00:00
|
|
|
*
|
|
|
|
* TODO: In case RARCH_BIND_LIST_END starts exceeding 64,
|
|
|
|
* and you need a bitmask of more than 64 entries, reimplement
|
|
|
|
* it to use something like rarch_bits_t.
|
2015-01-07 15:29:46 +00:00
|
|
|
*
|
|
|
|
* Returns: Input sample containg a mask of all pressed keys.
|
2014-10-05 00:45:38 +00:00
|
|
|
*/
|
2015-03-15 03:30:46 +00:00
|
|
|
static INLINE retro_input_t input_keys_pressed(void)
|
2014-10-05 00:45:38 +00:00
|
|
|
{
|
2015-01-09 16:48:20 +00:00
|
|
|
unsigned i;
|
2015-01-05 00:58:00 +00:00
|
|
|
static const struct retro_keybind *binds[MAX_USERS] = {
|
2014-10-05 01:02:06 +00:00
|
|
|
g_settings.input.binds[0],
|
|
|
|
g_settings.input.binds[1],
|
|
|
|
g_settings.input.binds[2],
|
|
|
|
g_settings.input.binds[3],
|
|
|
|
g_settings.input.binds[4],
|
|
|
|
g_settings.input.binds[5],
|
|
|
|
g_settings.input.binds[6],
|
|
|
|
g_settings.input.binds[7],
|
|
|
|
g_settings.input.binds[8],
|
|
|
|
g_settings.input.binds[9],
|
|
|
|
g_settings.input.binds[10],
|
|
|
|
g_settings.input.binds[11],
|
|
|
|
g_settings.input.binds[12],
|
|
|
|
g_settings.input.binds[13],
|
|
|
|
g_settings.input.binds[14],
|
|
|
|
g_settings.input.binds[15],
|
|
|
|
};
|
2014-10-05 00:45:38 +00:00
|
|
|
retro_input_t ret = 0;
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2014-10-05 00:45:38 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->input || !driver->input_data)
|
2015-02-10 15:38:47 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-10-05 01:02:06 +00:00
|
|
|
g_extern.turbo_count++;
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->block_libretro_input = check_block_hotkey(
|
|
|
|
driver->input->key_pressed(driver->input_data,
|
2014-10-05 00:45:38 +00:00
|
|
|
RARCH_ENABLE_HOTKEY));
|
|
|
|
|
2015-01-05 00:45:57 +00:00
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
2014-10-05 01:02:06 +00:00
|
|
|
{
|
2015-01-10 21:31:14 +00:00
|
|
|
input_push_analog_dpad(g_settings.input.binds[i],
|
|
|
|
g_settings.input.analog_dpad_mode[i]);
|
2014-10-05 00:45:38 +00:00
|
|
|
input_push_analog_dpad(g_settings.input.autoconf_binds[i],
|
|
|
|
g_settings.input.analog_dpad_mode[i]);
|
|
|
|
|
2015-02-14 23:27:33 +00:00
|
|
|
g_extern.turbo_frame_enable[i] = 0;
|
2015-02-14 23:34:14 +00:00
|
|
|
}
|
2015-02-14 23:27:33 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->block_libretro_input)
|
2015-02-14 23:34:14 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
|
|
|
{
|
2014-12-28 04:57:17 +00:00
|
|
|
g_extern.turbo_frame_enable[i] =
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->input->input_state(driver->input_data, binds, i,
|
2015-01-10 21:31:14 +00:00
|
|
|
RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE);
|
2015-02-14 23:34:14 +00:00
|
|
|
}
|
2014-10-05 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-15 00:19:06 +00:00
|
|
|
ret = input_driver_keys_pressed();
|
2014-10-05 00:45:38 +00:00
|
|
|
|
2015-01-05 00:45:57 +00:00
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
2015-01-10 21:31:14 +00:00
|
|
|
{
|
|
|
|
input_pop_analog_dpad(g_settings.input.binds[i]);
|
2014-10-05 00:45:38 +00:00
|
|
|
input_pop_analog_dpad(g_settings.input.autoconf_binds[i]);
|
2015-01-10 21:31:14 +00:00
|
|
|
}
|
2014-10-05 00:45:38 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-07 15:29:46 +00:00
|
|
|
/**
|
|
|
|
* input_flush:
|
|
|
|
* @input : input sample for this frame
|
|
|
|
*
|
|
|
|
* Resets input sample.
|
|
|
|
*
|
|
|
|
* Returns: always true (1).
|
2015-01-18 08:25:48 +00:00
|
|
|
**/
|
2014-10-05 14:22:15 +00:00
|
|
|
static bool input_flush(retro_input_t *input)
|
|
|
|
{
|
|
|
|
*input = 0;
|
|
|
|
|
|
|
|
/* If core was paused before entering menu, evoke
|
|
|
|
* pause toggle to wake it up. */
|
2015-03-07 11:36:50 +00:00
|
|
|
if (g_runloop.is_paused)
|
2014-10-05 14:22:15 +00:00
|
|
|
BIT64_SET(*input, RARCH_PAUSE_TOGGLE);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-11 16:33:05 +00:00
|
|
|
/**
|
|
|
|
* rarch_main_load_dummy_core:
|
|
|
|
*
|
|
|
|
* Quits out of RetroArch main loop.
|
|
|
|
*
|
|
|
|
* On special case, loads dummy core
|
|
|
|
* instead of exiting RetroArch completely.
|
|
|
|
* Aborts core shutdown if invoked.
|
|
|
|
*
|
|
|
|
* Returns: -1 if we are about to quit, otherwise 0.
|
|
|
|
**/
|
|
|
|
static int rarch_main_iterate_quit(void)
|
|
|
|
{
|
|
|
|
if (g_extern.core_shutdown_initiated
|
|
|
|
&& g_settings.load_dummy_on_core_shutdown)
|
|
|
|
{
|
|
|
|
if (!rarch_main_command(RARCH_CMD_PREPARE_DUMMY))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
g_extern.core_shutdown_initiated = false;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-21 06:29:13 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2015-02-21 07:52:29 +00:00
|
|
|
static void rarch_main_iterate_linefeed_overlay(void)
|
2015-02-21 07:42:19 +00:00
|
|
|
{
|
2015-02-21 07:47:03 +00:00
|
|
|
static char prev_overlay_restore = false;
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-02-21 07:47:03 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->osk_enable && !driver->keyboard_linefeed_enable)
|
2015-02-21 07:42:19 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->osk_enable = false;
|
|
|
|
prev_overlay_restore = true;
|
2015-02-21 07:42:19 +00:00
|
|
|
rarch_main_command(RARCH_CMD_OVERLAY_DEINIT);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-18 18:40:00 +00:00
|
|
|
else if (!driver->osk_enable && driver->keyboard_linefeed_enable)
|
2015-02-21 07:42:19 +00:00
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->osk_enable = true;
|
|
|
|
prev_overlay_restore = false;
|
2015-02-21 07:42:19 +00:00
|
|
|
rarch_main_command(RARCH_CMD_OVERLAY_INIT);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-21 07:47:03 +00:00
|
|
|
else if (prev_overlay_restore)
|
|
|
|
{
|
|
|
|
rarch_main_command(RARCH_CMD_OVERLAY_INIT);
|
|
|
|
prev_overlay_restore = false;
|
|
|
|
}
|
2015-02-21 07:42:19 +00:00
|
|
|
}
|
2015-02-21 07:52:29 +00:00
|
|
|
#endif
|
2015-02-21 07:42:19 +00:00
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
const char *rarch_main_msg_queue_pull(void)
|
|
|
|
{
|
|
|
|
return msg_queue_pull(g_runloop.msg_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rarch_main_msg_queue_push(const char *msg, unsigned prio, unsigned duration,
|
|
|
|
bool flush)
|
|
|
|
{
|
|
|
|
if (!g_runloop.msg_queue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (flush)
|
|
|
|
msg_queue_clear(g_runloop.msg_queue);
|
2015-03-15 02:03:33 +00:00
|
|
|
msg_queue_push(g_runloop.msg_queue, msg, prio, duration);
|
2015-03-15 01:47:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 02:10:45 +00:00
|
|
|
void rarch_main_msg_queue_free(void)
|
|
|
|
{
|
|
|
|
if (g_runloop.msg_queue)
|
|
|
|
msg_queue_free(g_runloop.msg_queue);
|
|
|
|
g_runloop.msg_queue = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rarch_main_msg_queue_init(void)
|
|
|
|
{
|
|
|
|
if (!g_runloop.msg_queue)
|
|
|
|
rarch_assert(g_runloop.msg_queue = msg_queue_new(8));
|
|
|
|
}
|
|
|
|
|
2015-03-18 05:47:22 +00:00
|
|
|
runloop_t *rarch_main_get_ptr(void)
|
|
|
|
{
|
|
|
|
return &g_runloop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rarch_main_clear_state(void)
|
|
|
|
{
|
|
|
|
memset(&g_runloop, 0, sizeof(g_runloop));
|
|
|
|
}
|
|
|
|
|
2015-01-07 02:53:36 +00:00
|
|
|
/**
|
|
|
|
* rarch_main_iterate:
|
2014-10-04 23:31:48 +00:00
|
|
|
*
|
2015-01-09 21:24:38 +00:00
|
|
|
* Run Libretro core in RetroArch for one frame.
|
2015-01-07 02:53:36 +00:00
|
|
|
*
|
2015-01-11 16:33:05 +00:00
|
|
|
* Returns: 0 on success, 1 if we have to wait until button input in order
|
2015-01-09 21:24:38 +00:00
|
|
|
* to wake up the loop, -1 if we forcibly quit out of the RetroArch iteration loop.
|
2015-01-07 02:53:36 +00:00
|
|
|
**/
|
2014-10-04 23:31:48 +00:00
|
|
|
int rarch_main_iterate(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
retro_input_t trigger_input;
|
2015-01-09 21:24:38 +00:00
|
|
|
int ret = 0;
|
2014-10-04 23:31:48 +00:00
|
|
|
static retro_input_t last_input = 0;
|
2015-01-09 21:24:38 +00:00
|
|
|
retro_input_t old_input = last_input;
|
|
|
|
retro_input_t input = input_keys_pressed();
|
|
|
|
last_input = input;
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->flushing_input)
|
|
|
|
driver->flushing_input = (input) ? input_flush(&input) : false;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
trigger_input = input & ~old_input;
|
|
|
|
|
|
|
|
if (time_to_exit(input))
|
2015-01-11 17:04:42 +00:00
|
|
|
return rarch_main_iterate_quit();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
if (g_extern.system.frame_time.callback)
|
2015-03-08 11:30:15 +00:00
|
|
|
rarch_update_frame_time();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-01-10 21:51:03 +00:00
|
|
|
do_pre_state_checks(input, old_input, trigger_input);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-02-21 06:29:13 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2015-02-21 07:52:29 +00:00
|
|
|
rarch_main_iterate_linefeed_overlay();
|
2015-02-21 06:29:13 +00:00
|
|
|
#endif
|
2015-02-22 06:34:33 +00:00
|
|
|
|
2015-03-14 14:50:34 +00:00
|
|
|
rarch_main_data_iterate();
|
2015-01-23 19:23:12 +00:00
|
|
|
|
2015-01-10 21:51:03 +00:00
|
|
|
#ifdef HAVE_MENU
|
2015-03-07 11:36:50 +00:00
|
|
|
if (g_runloop.is_menu)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-02-13 22:41:34 +00:00
|
|
|
menu_handle_t *menu = menu_driver_resolve();
|
|
|
|
if (menu)
|
2015-01-27 00:29:33 +00:00
|
|
|
if (menu_iterate(input, old_input, trigger_input) == -1)
|
|
|
|
rarch_main_set_state(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
if (!input && g_settings.menu.pause_libretro)
|
|
|
|
ret = 1;
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (g_extern.exec)
|
|
|
|
{
|
|
|
|
g_extern.exec = false;
|
2015-01-11 17:04:42 +00:00
|
|
|
return rarch_main_iterate_quit();
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (do_state_checks(input, old_input, trigger_input))
|
|
|
|
{
|
|
|
|
/* RetroArch has been paused */
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->retro_ctx.poll_cb();
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_sleep(10);
|
|
|
|
|
2015-01-11 17:04:42 +00:00
|
|
|
return 1;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_THREADS)
|
|
|
|
lock_autosave();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETPLAY
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->netplay_data)
|
|
|
|
netplay_pre_frame((netplay_t*)driver->netplay_data);
|
2014-10-04 23:31:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (g_extern.bsv.movie)
|
|
|
|
bsv_movie_set_frame_start(g_extern.bsv.movie);
|
|
|
|
|
|
|
|
if (g_extern.system.camera_callback.caps)
|
|
|
|
driver_camera_poll();
|
|
|
|
|
|
|
|
/* Update binds for analog dpad modes. */
|
2015-01-05 00:45:57 +00:00
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
if (!g_settings.input.analog_dpad_mode[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
input_push_analog_dpad(g_settings.input.binds[i],
|
|
|
|
g_settings.input.analog_dpad_mode[i]);
|
|
|
|
input_push_analog_dpad(g_settings.input.autoconf_binds[i],
|
|
|
|
g_settings.input.analog_dpad_mode[i]);
|
|
|
|
}
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if ((g_settings.video.frame_delay > 0) && !driver->nonblock_state)
|
2014-10-04 23:31:48 +00:00
|
|
|
rarch_sleep(g_settings.video.frame_delay);
|
|
|
|
|
|
|
|
|
|
|
|
/* Run libretro for one frame. */
|
2015-02-10 20:18:47 +00:00
|
|
|
pretro_run();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-01-05 00:45:57 +00:00
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
if (!g_settings.input.analog_dpad_mode[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
input_pop_analog_dpad(g_settings.input.binds[i]);
|
|
|
|
input_pop_analog_dpad(g_settings.input.autoconf_binds[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_extern.bsv.movie)
|
|
|
|
bsv_movie_set_frame_end(g_extern.bsv.movie);
|
|
|
|
|
|
|
|
#ifdef HAVE_NETPLAY
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->netplay_data)
|
|
|
|
netplay_post_frame((netplay_t*)driver->netplay_data);
|
2014-10-04 23:31:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_THREADS)
|
|
|
|
unlock_autosave();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
success:
|
|
|
|
if (g_settings.fastforward_ratio_throttle_enable)
|
2015-03-08 11:30:15 +00:00
|
|
|
rarch_limit_frame_time();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-01-11 17:04:42 +00:00
|
|
|
return ret;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|