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>
|
2015-06-29 22:38:10 +00:00
|
|
|
#include <retro_log.h>
|
2015-06-13 17:12:10 +00:00
|
|
|
|
2015-06-22 09:45:00 +00:00
|
|
|
#include <compat/strl.h>
|
2015-06-14 16:46:00 +00:00
|
|
|
|
2015-06-13 17:12:10 +00:00
|
|
|
#include "configuration.h"
|
2014-10-22 02:27:51 +00:00
|
|
|
#include "dynamic.h"
|
2014-10-04 23:31:48 +00:00
|
|
|
#include "performance.h"
|
2015-01-09 16:40:47 +00:00
|
|
|
#include "retroarch.h"
|
2015-01-09 17:40:33 +00:00
|
|
|
#include "runloop.h"
|
2015-03-24 12:45:53 +00:00
|
|
|
#include "runloop_data.h"
|
2015-06-13 17:12:10 +00:00
|
|
|
|
2015-07-01 00:00:39 +00:00
|
|
|
#include "msg_hash.h"
|
|
|
|
|
2015-03-26 03:24:12 +00:00
|
|
|
#include "input/keyboard_line.h"
|
2015-06-13 17:12:10 +00:00
|
|
|
#include "input/input_common.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-05-19 16:58:22 +00:00
|
|
|
static struct runloop *g_runloop = NULL;
|
|
|
|
static struct global *g_extern = NULL;
|
2015-03-21 04:55:31 +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.
|
|
|
|
**/
|
2015-07-12 17:17:57 +00:00
|
|
|
static bool check_pause(driver_t *driver, settings_t *settings,
|
|
|
|
runloop_t *runloop,
|
2015-07-12 17:06:24 +00:00
|
|
|
bool pause_pressed, bool frameadvance_pressed)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
static bool old_focus = true;
|
|
|
|
bool focus = true;
|
2015-04-20 18:00:39 +00:00
|
|
|
enum event_command cmd = EVENT_CMD_NONE;
|
2015-06-30 13:26:14 +00:00
|
|
|
bool old_is_paused = runloop ? runloop->is_paused : false;
|
2015-07-12 09:28:19 +00:00
|
|
|
const video_driver_t *video = driver ? (const video_driver_t*)driver->video :
|
|
|
|
NULL;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
/* FRAMEADVANCE will set us into pause mode. */
|
2015-03-21 07:27:30 +00:00
|
|
|
pause_pressed |= !runloop->is_paused && frameadvance_pressed;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (settings->pause_nonactive)
|
2015-07-12 09:28:19 +00:00
|
|
|
focus = video->focus(driver->video_data);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 07:27:30 +00:00
|
|
|
if (focus && pause_pressed)
|
2015-04-13 08:29:15 +00:00
|
|
|
cmd = EVENT_CMD_PAUSE_TOGGLE;
|
2014-10-04 23:31:48 +00:00
|
|
|
else if (focus && !old_focus)
|
2015-04-13 08:29:15 +00:00
|
|
|
cmd = EVENT_CMD_UNPAUSE;
|
2014-10-04 23:31:48 +00:00
|
|
|
else if (!focus && old_focus)
|
2015-04-13 08:29:15 +00:00
|
|
|
cmd = EVENT_CMD_PAUSE;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2014-10-05 02:10:00 +00:00
|
|
|
old_focus = focus;
|
|
|
|
|
2015-04-13 08:29:15 +00:00
|
|
|
if (cmd != EVENT_CMD_NONE)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(cmd);
|
2014-10-29 04:54:29 +00:00
|
|
|
|
2015-03-20 17:31:09 +00:00
|
|
|
if (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 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.
|
|
|
|
*
|
|
|
|
**/
|
2015-07-12 17:06:24 +00:00
|
|
|
static void check_fast_forward_button(driver_t *driver,
|
|
|
|
bool fastforward_pressed,
|
2014-10-04 23:31:48 +00:00
|
|
|
bool hold_pressed, bool old_hold_pressed)
|
|
|
|
{
|
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.
|
|
|
|
**/
|
2015-07-12 17:06:24 +00:00
|
|
|
static void check_stateslots(settings_t *settings,
|
|
|
|
bool pressed_increase, bool pressed_decrease)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-06-12 15:00:37 +00:00
|
|
|
char msg[PATH_MAX_LENGTH] = {0};
|
2014-10-05 03:50:04 +00:00
|
|
|
|
2014-10-04 23:31:48 +00:00
|
|
|
/* Save state slots */
|
|
|
|
if (pressed_increase)
|
2015-03-20 18:48:23 +00:00
|
|
|
settings->state_slot++;
|
2014-10-05 03:50:04 +00:00
|
|
|
else if (pressed_decrease)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
if (settings->state_slot > 0)
|
|
|
|
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
|
|
|
|
2015-07-01 17:30:34 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%s: %d",
|
|
|
|
msg_hash_to_str(MSG_STATE_SLOT),
|
2015-03-20 18:48:23 +00:00
|
|
|
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-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.
|
|
|
|
**/
|
2015-07-12 17:06:24 +00:00
|
|
|
static void check_rewind(settings_t *settings,
|
|
|
|
global_t *global, runloop_t *runloop, bool pressed)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
static bool first = true;
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->rewind.frame_is_reverse)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_driver_frame_is_reverse();
|
2015-03-21 01:07:46 +00:00
|
|
|
global->rewind.frame_is_reverse = false;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (!global->rewind.state)
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (pressed)
|
|
|
|
{
|
2015-03-22 06:52:14 +00:00
|
|
|
const void *buf = NULL;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (state_manager_pop(global->rewind.state, &buf))
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-21 01:07:46 +00:00
|
|
|
global->rewind.frame_is_reverse = true;
|
2015-05-19 19:18:07 +00:00
|
|
|
audio_driver_setup_rewind();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-01 00:00:39 +00:00
|
|
|
rarch_main_msg_queue_push_new(MSG_REWINDING, 0,
|
2015-03-20 17:31:09 +00:00
|
|
|
runloop->is_paused ? 1 : 30, true);
|
2015-03-21 01:07:46 +00:00
|
|
|
pretro_unserialize(buf, global->rewind.size);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->bsv.movie)
|
|
|
|
bsv_movie_frame_rewind(global->bsv.movie);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
else
|
2015-07-01 00:00:39 +00:00
|
|
|
rarch_main_msg_queue_push_new(MSG_REWIND_REACHED_END,
|
2015-03-15 01:59:38 +00:00
|
|
|
0, 30, true);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-22 06:52:14 +00:00
|
|
|
static unsigned cnt = 0;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
cnt = (cnt + 1) % (settings->rewind_granularity ?
|
|
|
|
settings->rewind_granularity : 1); /* Avoid possible SIGFPE. */
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if ((cnt == 0) || global->bsv.movie)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
void *state = NULL;
|
2015-03-21 01:07:46 +00:00
|
|
|
state_manager_push_where(global->rewind.state, &state);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
RARCH_PERFORMANCE_INIT(rewind_serialize);
|
|
|
|
RARCH_PERFORMANCE_START(rewind_serialize);
|
2015-03-21 01:07:46 +00:00
|
|
|
pretro_serialize(state, global->rewind.size);
|
2014-10-04 23:31:48 +00:00
|
|
|
RARCH_PERFORMANCE_STOP(rewind_serialize);
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
state_manager_push_do(global->rewind.state);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retro_set_rewind_callbacks();
|
|
|
|
}
|
|
|
|
|
2015-01-09 21:24:38 +00:00
|
|
|
/**
|
|
|
|
* check_slowmotion:
|
2015-03-21 07:27:30 +00:00
|
|
|
* @slowmotion_pressed : was slow motion key pressed or held?
|
2015-01-09 21:24:38 +00:00
|
|
|
*
|
|
|
|
* Checks if slowmotion toggle/hold was being pressed and/or held.
|
|
|
|
**/
|
2015-07-12 17:06:24 +00:00
|
|
|
static void check_slowmotion(settings_t *settings, global_t *global,
|
|
|
|
runloop_t *runloop, bool slowmotion_pressed)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-22 06:52:14 +00:00
|
|
|
runloop->is_slowmotion = slowmotion_pressed;
|
2015-03-20 17:31:09 +00:00
|
|
|
|
|
|
|
if (!runloop->is_slowmotion)
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (settings->video.black_frame_insertion)
|
2015-05-20 19:06:44 +00:00
|
|
|
video_driver_cached_frame();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-01 00:00:39 +00:00
|
|
|
if (global->rewind.frame_is_reverse)
|
|
|
|
rarch_main_msg_queue_push_new(MSG_SLOW_MOTION_REWIND, 0, 30, true);
|
|
|
|
else
|
|
|
|
rarch_main_msg_queue_push_new(MSG_SLOW_MOTION, 0, 30, true);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool check_movie_init(void)
|
|
|
|
{
|
2015-06-12 15:00:37 +00:00
|
|
|
char path[PATH_MAX_LENGTH] = {0};
|
|
|
|
char msg[PATH_MAX_LENGTH] = {0};
|
2015-03-22 06:52:14 +00:00
|
|
|
bool ret = true;
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
global_t *global = global_get_ptr();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->bsv.movie)
|
2014-10-04 23:31:48 +00:00
|
|
|
return false;
|
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
settings->rewind_granularity = 1;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (settings->state_slot > 0)
|
2015-06-22 09:45:00 +00:00
|
|
|
snprintf(path, sizeof(path), "%s%d",
|
2015-03-21 01:07:46 +00:00
|
|
|
global->bsv.movie_path, settings->state_slot);
|
2014-10-04 23:31:48 +00:00
|
|
|
else
|
2015-06-22 09:45:00 +00:00
|
|
|
strlcpy(path, global->bsv.movie_path, sizeof(path));
|
|
|
|
strlcat(path, ".bsv", sizeof(path));
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-01 17:30:34 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%s \"%s\".",
|
|
|
|
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
|
|
|
|
path);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
global->bsv.movie = bsv_movie_init(path, RARCH_MOVIE_RECORD);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (!global->bsv.movie)
|
2014-10-04 23:31:48 +00:00
|
|
|
ret = false;
|
|
|
|
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->bsv.movie)
|
2015-07-01 00:00:39 +00:00
|
|
|
{
|
|
|
|
rarch_main_msg_queue_push(msg, 1, 180, true);
|
2015-07-01 17:30:34 +00:00
|
|
|
RARCH_LOG("%s \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
|
|
|
|
path);
|
2015-07-01 00:00:39 +00:00
|
|
|
}
|
2014-10-04 23:31:48 +00:00
|
|
|
else
|
2015-07-01 00:00:39 +00:00
|
|
|
{
|
|
|
|
rarch_main_msg_queue_push_new(
|
|
|
|
MSG_FAILED_TO_START_MOVIE_RECORD,
|
|
|
|
1, 180, true);
|
2015-07-01 17:30:34 +00:00
|
|
|
RARCH_ERR(msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD));
|
2015-07-01 00:00:39 +00:00
|
|
|
}
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
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).
|
|
|
|
**/
|
2015-07-12 17:17:57 +00:00
|
|
|
static bool check_movie_record(global_t *global)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-21 01:07:46 +00:00
|
|
|
if (!global->bsv.movie)
|
2014-10-04 23:31:48 +00:00
|
|
|
return false;
|
|
|
|
|
2015-07-02 16:46:27 +00:00
|
|
|
rarch_main_msg_queue_push_new(
|
|
|
|
MSG_MOVIE_RECORD_STOPPED, 2, 180, true);
|
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED));
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_BSV_MOVIE_DEINIT);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
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).
|
|
|
|
**/
|
2015-07-12 17:17:57 +00:00
|
|
|
static bool check_movie_playback(global_t *global)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-21 01:07:46 +00:00
|
|
|
if (!global->bsv.movie_end)
|
2014-10-04 23:31:48 +00:00
|
|
|
return false;
|
|
|
|
|
2015-07-02 16:46:27 +00:00
|
|
|
rarch_main_msg_queue_push_new(
|
|
|
|
MSG_MOVIE_PLAYBACK_ENDED, 1, 180, false);
|
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED));
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_BSV_MOVIE_DEINIT);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-22 06:52:14 +00:00
|
|
|
global->bsv.movie_end = false;
|
2015-03-21 01:07:46 +00:00
|
|
|
global->bsv.movie_playback = false;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-12 17:17:57 +00:00
|
|
|
static bool check_movie(global_t *global)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->bsv.movie_playback)
|
2015-07-12 17:17:57 +00:00
|
|
|
return check_movie_playback(global);
|
2015-03-21 01:07:46 +00:00
|
|
|
if (!global->bsv.movie)
|
2014-10-04 23:31:48 +00:00
|
|
|
return check_movie_init();
|
2015-07-12 17:17:57 +00:00
|
|
|
return check_movie_record(global);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-14 16:46:00 +00:00
|
|
|
#define SHADER_EXT_GLSL 0x7c976537U
|
|
|
|
#define SHADER_EXT_GLSLP 0x0f840c87U
|
|
|
|
#define SHADER_EXT_CG 0x0059776fU
|
|
|
|
#define SHADER_EXT_CGP 0x0b8865bfU
|
|
|
|
|
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.
|
|
|
|
**/
|
2015-07-12 17:17:57 +00:00
|
|
|
static void check_shader_dir(global_t *global,
|
|
|
|
bool pressed_next, bool pressed_prev)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-06-14 16:46:00 +00:00
|
|
|
uint32_t ext_hash;
|
2015-06-12 15:00:37 +00:00
|
|
|
char msg[PATH_MAX_LENGTH] = {0};
|
|
|
|
const char *shader = NULL;
|
|
|
|
const char *ext = NULL;
|
2014-10-04 23:31:48 +00:00
|
|
|
enum rarch_shader_type type = RARCH_SHADER_NONE;
|
|
|
|
|
2015-06-22 22:01:35 +00:00
|
|
|
if (!global || !global->shader_dir.list)
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (pressed_next)
|
|
|
|
{
|
2015-03-21 01:07:46 +00:00
|
|
|
global->shader_dir.ptr = (global->shader_dir.ptr + 1) %
|
|
|
|
global->shader_dir.list->size;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
else if (pressed_prev)
|
|
|
|
{
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->shader_dir.ptr == 0)
|
|
|
|
global->shader_dir.ptr = global->shader_dir.list->size - 1;
|
2014-10-04 23:31:48 +00:00
|
|
|
else
|
2015-03-21 01:07:46 +00:00
|
|
|
global->shader_dir.ptr--;
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
2014-10-05 03:46:27 +00:00
|
|
|
else
|
2014-10-04 23:31:48 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-22 22:01:35 +00:00
|
|
|
shader = global->shader_dir.list->elems[global->shader_dir.ptr].data;
|
2015-06-14 16:46:00 +00:00
|
|
|
ext = path_get_extension(shader);
|
2015-07-01 22:56:51 +00:00
|
|
|
ext_hash = msg_hash_calculate(ext);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-06-14 16:46:00 +00:00
|
|
|
switch (ext_hash)
|
|
|
|
{
|
|
|
|
case SHADER_EXT_GLSL:
|
|
|
|
case SHADER_EXT_GLSLP:
|
|
|
|
type = RARCH_SHADER_GLSL;
|
|
|
|
break;
|
|
|
|
case SHADER_EXT_CG:
|
|
|
|
case SHADER_EXT_CGP:
|
|
|
|
type = RARCH_SHADER_CG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-01 17:30:34 +00:00
|
|
|
snprintf(msg, sizeof(msg), "%s #%u: \"%s\".",
|
|
|
|
msg_hash_to_str(MSG_SHADER),
|
2015-03-21 01:07:46 +00:00
|
|
|
(unsigned)global->shader_dir.ptr, shader);
|
2015-03-15 01:47:23 +00:00
|
|
|
rarch_main_msg_queue_push(msg, 1, 120, true);
|
2015-07-01 17:30:34 +00:00
|
|
|
RARCH_LOG("%s \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_APPLYING_SHADER),
|
|
|
|
shader);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-02-10 16:20:02 +00:00
|
|
|
if (!video_driver_set_shader(type, shader))
|
2015-07-01 17:30:34 +00:00
|
|
|
RARCH_WARN(msg_hash_to_str(MSG_FAILED_TO_APPLY_SHADER));
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 21:51:03 +00:00
|
|
|
#ifdef HAVE_MENU
|
2015-07-12 17:17:57 +00:00
|
|
|
static void do_state_check_menu_toggle(settings_t *settings, global_t *global)
|
2015-01-10 21:51:03 +00:00
|
|
|
{
|
2015-05-19 18:11:57 +00:00
|
|
|
if (menu_driver_alive())
|
2015-01-10 21:51:03 +00:00
|
|
|
{
|
2015-06-20 21:42:30 +00:00
|
|
|
if (global->main_is_init && (global->core_type != CORE_TYPE_DUMMY))
|
2015-01-10 21:51:03 +00:00
|
|
|
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:
|
|
|
|
*
|
|
|
|
* Checks for state changes in this frame.
|
|
|
|
*
|
|
|
|
* Unlike do_state_checks(), this is performed for both
|
|
|
|
* the menu and the regular loop.
|
|
|
|
*
|
|
|
|
* Returns: 0.
|
|
|
|
**/
|
2015-07-12 17:17:57 +00:00
|
|
|
static int do_pre_state_checks(settings_t *settings,
|
|
|
|
global_t *global, runloop_t *runloop,
|
2015-07-12 17:06:24 +00:00
|
|
|
event_cmd_state_t *cmd)
|
2015-01-10 21:51:03 +00:00
|
|
|
{
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->overlay_next_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_OVERLAY_NEXT);
|
2015-01-10 21:51:03 +00:00
|
|
|
|
2015-05-19 18:11:57 +00:00
|
|
|
if (!runloop->is_paused || menu_driver_alive())
|
2015-01-10 21:51:03 +00:00
|
|
|
{
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->fullscreen_toggle)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
|
2015-01-10 21:51:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->grab_mouse_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_GRAB_MOUSE_TOGGLE);
|
2015-01-10 21:51:03 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
2015-06-20 21:42:30 +00:00
|
|
|
if (cmd->menu_pressed || (global->core_type == CORE_TYPE_DUMMY))
|
2015-07-12 17:17:57 +00:00
|
|
|
do_state_check_menu_toggle(settings, global);
|
2015-01-10 21:51:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-10 18:04:02 +00:00
|
|
|
#ifdef HAVE_NETPLAY
|
|
|
|
static int do_netplay_state_checks(
|
2015-03-24 08:44:18 +00:00
|
|
|
bool netplay_flip_pressed,
|
|
|
|
bool fullscreen_toggle)
|
2015-02-10 18:04:02 +00:00
|
|
|
{
|
2015-03-21 07:41:08 +00:00
|
|
|
if (netplay_flip_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_NETPLAY_FLIP_PLAYERS);
|
2015-02-10 18:04:02 +00:00
|
|
|
|
2015-03-21 07:41:08 +00:00
|
|
|
if (fullscreen_toggle)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
|
2015-02-10 18:04:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-10 18:07:53 +00:00
|
|
|
static int do_pause_state_checks(
|
2015-07-12 17:06:24 +00:00
|
|
|
runloop_t *runloop,
|
2015-03-24 08:44:18 +00:00
|
|
|
bool pause_pressed,
|
|
|
|
bool frameadvance_pressed,
|
|
|
|
bool fullscreen_toggle_pressed,
|
|
|
|
bool rewind_pressed)
|
2015-02-10 18:07:53 +00:00
|
|
|
{
|
2015-04-05 19:37:34 +00:00
|
|
|
bool check_is_oneshot = frameadvance_pressed || rewind_pressed;
|
2015-03-21 07:41:08 +00:00
|
|
|
|
2015-07-12 17:06:24 +00:00
|
|
|
if (!runloop->is_paused)
|
2015-02-10 18:07:53 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-03-21 07:41:08 +00:00
|
|
|
if (fullscreen_toggle_pressed)
|
2015-02-10 18:07:53 +00:00
|
|
|
{
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
|
2015-05-20 19:06:44 +00:00
|
|
|
video_driver_cached_frame();
|
2015-02-10 18:07:53 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 19:37:34 +00:00
|
|
|
if (!check_is_oneshot)
|
2015-02-10 18:07:53 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-07 15:29:46 +00:00
|
|
|
/**
|
|
|
|
* do_state_checks:
|
|
|
|
*
|
|
|
|
* Checks for state changes in this frame.
|
|
|
|
*
|
|
|
|
* Returns: 1 if RetroArch is in pause mode, 0 otherwise.
|
|
|
|
**/
|
2015-07-12 17:06:24 +00:00
|
|
|
static int do_state_checks(driver_t *driver, settings_t *settings,
|
|
|
|
global_t *global, runloop_t *runloop, event_cmd_state_t *cmd)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-20 17:31:09 +00:00
|
|
|
if (runloop->is_idle)
|
2015-03-08 00:48:40 +00:00
|
|
|
return 1;
|
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->screenshot_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_TAKE_SCREENSHOT);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->mute_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_AUDIO_MUTE_TOGGLE);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-26 03:24:12 +00:00
|
|
|
if (cmd->osk_pressed)
|
2015-07-12 17:06:24 +00:00
|
|
|
driver->keyboard_linefeed_enable = !driver->keyboard_linefeed_enable;
|
2015-03-26 03:24:12 +00:00
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->volume_up_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_VOLUME_UP);
|
2015-03-24 09:01:17 +00:00
|
|
|
else if (cmd->volume_down_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_VOLUME_DOWN);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_NETPLAY
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->netplay_data)
|
2015-07-02 03:24:38 +00:00
|
|
|
return do_netplay_state_checks(cmd->netplay_flip_pressed,
|
|
|
|
cmd->fullscreen_toggle);
|
2014-10-04 23:31:48 +00:00
|
|
|
#endif
|
2014-10-08 14:41:08 +00:00
|
|
|
|
2015-07-12 17:17:57 +00:00
|
|
|
check_pause(driver, settings, runloop,
|
2015-07-12 17:06:24 +00:00
|
|
|
cmd->pause_pressed, cmd->frameadvance_pressed);
|
2015-03-24 08:44:18 +00:00
|
|
|
|
|
|
|
if (do_pause_state_checks(
|
2015-07-12 17:06:24 +00:00
|
|
|
runloop,
|
2015-03-24 09:01:17 +00:00
|
|
|
cmd->pause_pressed,
|
|
|
|
cmd->frameadvance_pressed,
|
|
|
|
cmd->fullscreen_toggle,
|
|
|
|
cmd->rewind_pressed))
|
2015-02-10 18:07:53 +00:00
|
|
|
return 1;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-12 17:06:24 +00:00
|
|
|
check_fast_forward_button(driver,
|
|
|
|
cmd->fastforward_pressed,
|
2015-07-02 03:24:38 +00:00
|
|
|
cmd->hold_pressed, cmd->old_hold_pressed);
|
2015-07-12 17:06:24 +00:00
|
|
|
check_stateslots(settings, cmd->state_slot_increase,
|
2015-07-02 03:24:38 +00:00
|
|
|
cmd->state_slot_decrease);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->save_state_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_SAVE_STATE);
|
2015-03-24 09:01:17 +00:00
|
|
|
else if (cmd->load_state_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_LOAD_STATE);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-12 17:06:24 +00:00
|
|
|
check_rewind(settings, global, runloop, cmd->rewind_pressed);
|
|
|
|
check_slowmotion(settings, global, runloop,
|
|
|
|
cmd->slowmotion_pressed);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->movie_record)
|
2015-07-12 17:17:57 +00:00
|
|
|
check_movie(global);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-12 17:17:57 +00:00
|
|
|
check_shader_dir(global, cmd->shader_next_pressed,
|
2015-07-02 03:24:38 +00:00
|
|
|
cmd->shader_prev_pressed);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->disk_eject_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_DISK_EJECT_TOGGLE);
|
2015-03-24 09:01:17 +00:00
|
|
|
else if (cmd->disk_next_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_DISK_NEXT);
|
2015-03-24 09:01:17 +00:00
|
|
|
else if (cmd->disk_prev_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_DISK_PREV);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->reset_pressed)
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_RESET);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->cheat)
|
2015-03-24 08:44:18 +00:00
|
|
|
{
|
2015-03-24 09:01:17 +00:00
|
|
|
if (cmd->cheat_index_plus_pressed)
|
2015-03-24 08:44:18 +00:00
|
|
|
cheat_manager_index_next(global->cheat);
|
2015-03-24 09:01:17 +00:00
|
|
|
else if (cmd->cheat_index_minus_pressed)
|
2015-03-24 08:44:18 +00:00
|
|
|
cheat_manager_index_prev(global->cheat);
|
2015-03-24 09:01:17 +00:00
|
|
|
else if (cmd->cheat_toggle_pressed)
|
2015-03-24 08:44:18 +00:00
|
|
|
cheat_manager_toggle(global->cheat);
|
|
|
|
}
|
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:
|
|
|
|
*
|
|
|
|
* 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-07-12 17:06:24 +00:00
|
|
|
static INLINE int time_to_exit(driver_t *driver, global_t *global,
|
|
|
|
runloop_t *runloop, event_cmd_state_t *cmd)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-07-12 09:28:19 +00:00
|
|
|
const video_driver_t *video = driver ? (const video_driver_t*)driver->video : NULL;
|
2015-06-25 11:06:06 +00:00
|
|
|
rarch_system_info_t *system = rarch_system_info_get_ptr();
|
|
|
|
bool shutdown_pressed = system->shutdown;
|
2015-07-12 09:28:19 +00:00
|
|
|
bool video_alive = video->alive(driver->video_data);
|
2015-03-21 07:54:27 +00:00
|
|
|
bool movie_end = (global->bsv.movie_end && global->bsv.eof_exit);
|
2015-05-09 14:04:12 +00:00
|
|
|
uint64_t frame_count = video_driver_get_frame_count();
|
2015-03-21 07:54:27 +00:00
|
|
|
bool frame_count_end = (runloop->frames.video.max &&
|
2015-05-09 14:04:12 +00:00
|
|
|
frame_count >= runloop->frames.video.max);
|
2015-03-21 07:54:27 +00:00
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
if (shutdown_pressed || cmd->quit_key_pressed || frame_count_end || movie_end
|
2015-03-21 07:54:27 +00:00
|
|
|
|| !video_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-07-12 17:06:24 +00:00
|
|
|
static void rarch_update_frame_time(driver_t *driver, settings_t *settings,
|
|
|
|
runloop_t *runloop)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
retro_time_t curr_time = rarch_get_time_usec();
|
2015-06-25 11:06:06 +00:00
|
|
|
rarch_system_info_t *system = rarch_system_info_get_ptr();
|
|
|
|
retro_time_t delta = curr_time - system->frame_time_last;
|
2015-03-20 18:48:23 +00:00
|
|
|
bool is_locked_fps = runloop->is_paused || driver->nonblock_state;
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
is_locked_fps |= !!driver->recording_data;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-06-25 11:06:06 +00:00
|
|
|
if (!system->frame_time_last || is_locked_fps)
|
|
|
|
delta = system->frame_time.reference;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-20 17:31:09 +00:00
|
|
|
if (!is_locked_fps && runloop->is_slowmotion)
|
2015-03-20 18:48:23 +00:00
|
|
|
delta /= settings->slowmotion_ratio;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-06-25 11:06:06 +00:00
|
|
|
system->frame_time_last = curr_time;
|
2015-01-09 21:24:38 +00:00
|
|
|
|
|
|
|
if (is_locked_fps)
|
2015-06-25 11:06:06 +00:00
|
|
|
system->frame_time_last = 0;
|
2015-01-09 21:24:38 +00:00
|
|
|
|
2015-06-25 11:06:06 +00:00
|
|
|
system->frame_time.callback(delta);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
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-07-12 17:06:24 +00:00
|
|
|
static void rarch_limit_frame_time(settings_t *settings, runloop_t *runloop)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-22 06:52:14 +00:00
|
|
|
retro_time_t target = 0;
|
|
|
|
retro_time_t to_sleep_ms = 0;
|
2015-03-21 08:14:07 +00:00
|
|
|
retro_time_t current = rarch_get_time_usec();
|
2015-05-20 16:57:17 +00:00
|
|
|
struct retro_system_av_info *av_info =
|
|
|
|
video_viewport_get_system_av_info();
|
|
|
|
double effective_fps = av_info->timing.fps * settings->fastforward_ratio;
|
2015-03-21 08:14:07 +00:00
|
|
|
double mft_f = 1000000.0f / effective_fps;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-20 17:31:09 +00:00
|
|
|
runloop->frames.limit.minimum_time = (retro_time_t) roundf(mft_f);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-20 17:31:09 +00:00
|
|
|
target = runloop->frames.limit.last_time +
|
|
|
|
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-20 17:31:09 +00:00
|
|
|
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-20 17:31:09 +00:00
|
|
|
runloop->frames.limit.last_time +=
|
|
|
|
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-07-12 17:06:24 +00:00
|
|
|
static bool check_block_hotkey(driver_t *driver, settings_t *settings,
|
|
|
|
bool enable_hotkey)
|
2014-10-05 00:45:38 +00:00
|
|
|
{
|
|
|
|
bool use_hotkey_enable;
|
2015-03-20 22:22:41 +00:00
|
|
|
const struct retro_keybind *bind =
|
|
|
|
&settings->input.binds[0][RARCH_ENABLE_HOTKEY];
|
|
|
|
const struct retro_keybind *autoconf_bind =
|
|
|
|
&settings->input.autoconf_binds[0][RARCH_ENABLE_HOTKEY];
|
2014-10-05 00:45:38 +00:00
|
|
|
|
|
|
|
/* Don't block the check to RARCH_ENABLE_HOTKEY
|
|
|
|
* unless we're really supposed to. */
|
2015-06-19 01:45:23 +00:00
|
|
|
driver->block_hotkey =
|
|
|
|
input_driver_keyboard_mapping_is_blocked();
|
2014-10-05 00:45:38 +00:00
|
|
|
|
2015-03-22 06:52:14 +00:00
|
|
|
/* If we haven't bound anything to this,
|
|
|
|
* always allow hotkeys. */
|
|
|
|
use_hotkey_enable =
|
|
|
|
bind->key != RETROK_UNKNOWN ||
|
2014-10-05 00:45:38 +00:00
|
|
|
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-06-19 01:45:23 +00:00
|
|
|
driver->block_hotkey =
|
|
|
|
input_driver_keyboard_mapping_is_blocked() ||
|
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-07-12 17:06:24 +00:00
|
|
|
static INLINE retro_input_t input_keys_pressed(driver_t *driver,
|
|
|
|
settings_t *settings, global_t *global)
|
2014-10-05 00:45:38 +00:00
|
|
|
{
|
2015-01-09 16:48:20 +00:00
|
|
|
unsigned i;
|
2015-06-27 13:52:24 +00:00
|
|
|
const struct retro_keybind *binds[MAX_USERS];
|
2015-03-20 18:48:23 +00:00
|
|
|
retro_input_t ret = 0;
|
2015-06-27 13:52:24 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_USERS; i++)
|
|
|
|
binds[i] = settings->input.binds[i];
|
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;
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
global->turbo_count++;
|
2014-10-05 01:02:06 +00:00
|
|
|
|
2015-07-12 17:06:24 +00:00
|
|
|
driver->block_libretro_input = check_block_hotkey(driver,
|
|
|
|
settings, input_driver_key_pressed(RARCH_ENABLE_HOTKEY));
|
2014-10-05 00:45:38 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
for (i = 0; i < settings->input.max_users; i++)
|
2014-10-05 01:02:06 +00:00
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
input_push_analog_dpad(settings->input.binds[i],
|
|
|
|
settings->input.analog_dpad_mode[i]);
|
|
|
|
input_push_analog_dpad(settings->input.autoconf_binds[i],
|
|
|
|
settings->input.analog_dpad_mode[i]);
|
2014-10-05 00:45:38 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
global->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
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
for (i = 0; i < settings->input.max_users; i++)
|
2015-03-23 02:04:05 +00:00
|
|
|
global->turbo_frame_enable[i] = input_driver_state(binds,
|
|
|
|
i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE);
|
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-03-20 18:48:23 +00:00
|
|
|
for (i = 0; i < settings->input.max_users; i++)
|
2015-01-10 21:31:14 +00:00
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
input_pop_analog_dpad(settings->input.binds[i]);
|
|
|
|
input_pop_analog_dpad(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
|
|
|
**/
|
2015-07-12 17:06:24 +00:00
|
|
|
static bool input_flush(runloop_t *runloop, retro_input_t *input)
|
2014-10-05 14:22:15 +00:00
|
|
|
{
|
|
|
|
*input = 0;
|
|
|
|
|
|
|
|
/* If core was paused before entering menu, evoke
|
|
|
|
* pause toggle to wake it up. */
|
2015-03-20 17:31:09 +00:00
|
|
|
if (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.
|
|
|
|
**/
|
2015-07-12 17:17:57 +00:00
|
|
|
static int rarch_main_iterate_quit(settings_t *settings, global_t *global)
|
2015-01-11 16:33:05 +00:00
|
|
|
{
|
2015-07-12 00:20:45 +00:00
|
|
|
rarch_system_info_t *system = rarch_system_info_get_ptr();
|
2015-03-20 18:48:23 +00:00
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->core_shutdown_initiated
|
2015-03-20 18:48:23 +00:00
|
|
|
&& settings->load_dummy_on_core_shutdown)
|
2015-01-11 16:33:05 +00:00
|
|
|
{
|
2015-04-13 09:26:02 +00:00
|
|
|
if (!event_command(EVENT_CMD_PREPARE_DUMMY))
|
2015-01-11 16:33:05 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-07-12 00:20:45 +00:00
|
|
|
system->shutdown = false;
|
2015-03-21 01:07:46 +00:00
|
|
|
global->core_shutdown_initiated = false;
|
2015-01-11 16:33:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-21 06:29:13 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2015-07-12 17:17:57 +00:00
|
|
|
static void rarch_main_iterate_linefeed_overlay(driver_t *driver,
|
|
|
|
settings_t *settings)
|
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
|
|
|
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-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_OVERLAY_DEINIT);
|
2015-02-21 07:42:19 +00:00
|
|
|
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-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_OVERLAY_INIT);
|
2015-02-21 07:42:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-21 07:47:03 +00:00
|
|
|
else if (prev_overlay_restore)
|
|
|
|
{
|
2015-07-09 02:05:59 +00:00
|
|
|
if (!settings->input.overlay_hide_in_menu)
|
|
|
|
event_command(EVENT_CMD_OVERLAY_INIT);
|
2015-02-21 07:47:03 +00:00
|
|
|
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-21 00:59:47 +00:00
|
|
|
global_t *global_get_ptr(void)
|
|
|
|
{
|
2015-03-21 05:17:03 +00:00
|
|
|
return g_extern;
|
2015-03-21 00:59:47 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 05:47:22 +00:00
|
|
|
runloop_t *rarch_main_get_ptr(void)
|
|
|
|
{
|
2015-03-20 18:01:03 +00:00
|
|
|
return g_runloop;
|
|
|
|
}
|
|
|
|
|
2015-03-22 02:41:20 +00:00
|
|
|
void rarch_main_state_free(void)
|
2015-03-20 18:01:03 +00:00
|
|
|
{
|
2015-05-19 16:58:22 +00:00
|
|
|
if (!g_runloop)
|
2015-03-20 18:01:03 +00:00
|
|
|
return;
|
|
|
|
|
2015-05-19 16:58:22 +00:00
|
|
|
free(g_runloop);
|
|
|
|
g_runloop = NULL;
|
2015-03-20 18:01:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 02:41:20 +00:00
|
|
|
void rarch_main_global_free(void)
|
2015-03-21 00:53:14 +00:00
|
|
|
{
|
2015-04-13 09:26:02 +00:00
|
|
|
event_command(EVENT_CMD_TEMPORARY_CONTENT_DEINIT);
|
|
|
|
event_command(EVENT_CMD_SUBSYSTEM_FULLPATHS_DEINIT);
|
|
|
|
event_command(EVENT_CMD_RECORD_DEINIT);
|
|
|
|
event_command(EVENT_CMD_LOG_FILE_DEINIT);
|
2015-03-21 00:53:14 +00:00
|
|
|
|
2015-05-19 17:40:25 +00:00
|
|
|
if (!g_extern)
|
2015-03-21 00:53:14 +00:00
|
|
|
return;
|
|
|
|
|
2015-05-19 17:40:25 +00:00
|
|
|
free(g_extern);
|
|
|
|
g_extern = NULL;
|
2015-03-21 00:53:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 05:02:00 +00:00
|
|
|
bool rarch_main_verbosity(void)
|
|
|
|
{
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
if (!global)
|
|
|
|
return false;
|
|
|
|
return global->verbosity;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *rarch_main_log_file(void)
|
|
|
|
{
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
if (!global)
|
|
|
|
return NULL;
|
|
|
|
return global->log_file;
|
|
|
|
}
|
|
|
|
|
2015-03-22 02:41:20 +00:00
|
|
|
static global_t *rarch_main_global_new(void)
|
2015-03-21 00:53:14 +00:00
|
|
|
{
|
2015-03-21 05:17:03 +00:00
|
|
|
global_t *global = (global_t*)calloc(1, sizeof(global_t));
|
|
|
|
|
|
|
|
if (!global)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return global;
|
2015-03-21 00:53:14 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:01:03 +00:00
|
|
|
static runloop_t *rarch_main_state_init(void)
|
|
|
|
{
|
|
|
|
runloop_t *runloop = (runloop_t*)calloc(1, sizeof(runloop_t));
|
|
|
|
|
|
|
|
if (!runloop)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return runloop;
|
2015-03-18 05:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rarch_main_clear_state(void)
|
|
|
|
{
|
2015-03-22 00:16:57 +00:00
|
|
|
driver_clear_state();
|
|
|
|
|
2015-03-22 02:41:20 +00:00
|
|
|
rarch_main_state_free();
|
2015-03-20 18:01:03 +00:00
|
|
|
g_runloop = rarch_main_state_init();
|
2015-03-21 00:53:14 +00:00
|
|
|
|
2015-03-22 02:41:20 +00:00
|
|
|
rarch_main_global_free();
|
|
|
|
g_extern = rarch_main_global_new();
|
2015-03-18 05:47:22 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 19:48:17 +00:00
|
|
|
bool rarch_main_is_idle(void)
|
|
|
|
{
|
2015-03-20 17:31:09 +00:00
|
|
|
runloop_t *runloop = rarch_main_get_ptr();
|
2015-03-22 06:52:14 +00:00
|
|
|
if (!runloop)
|
|
|
|
return false;
|
2015-03-20 17:31:09 +00:00
|
|
|
return runloop->is_idle;
|
2015-03-18 19:48:17 +00:00
|
|
|
}
|
|
|
|
|
2015-07-09 04:27:17 +00:00
|
|
|
static bool rarch_main_cmd_get_state_menu_toggle_button_combo(
|
|
|
|
retro_input_t input, retro_input_t old_input,
|
|
|
|
retro_input_t trigger_input)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
|
|
|
if (!settings)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (settings->input.menu_toggle_gamepad_combo)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return false;
|
|
|
|
case 1:
|
|
|
|
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_DOWN))
|
|
|
|
return false;
|
|
|
|
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_Y))
|
|
|
|
return false;
|
|
|
|
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_L))
|
|
|
|
return false;
|
|
|
|
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_R))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_L3))
|
|
|
|
return false;
|
|
|
|
if (!BIT64_GET(input, RETRO_DEVICE_ID_JOYPAD_R3))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
driver->flushing_input = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-13 09:41:44 +00:00
|
|
|
static void rarch_main_cmd_get_state(event_cmd_state_t *cmd,
|
2015-03-24 09:01:17 +00:00
|
|
|
retro_input_t input, retro_input_t old_input,
|
|
|
|
retro_input_t trigger_input)
|
|
|
|
{
|
|
|
|
if (!cmd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmd->fullscreen_toggle = BIT64_GET(trigger_input, RARCH_FULLSCREEN_TOGGLE_KEY);
|
|
|
|
cmd->overlay_next_pressed = BIT64_GET(trigger_input, RARCH_OVERLAY_NEXT);
|
|
|
|
cmd->grab_mouse_pressed = BIT64_GET(trigger_input, RARCH_GRAB_MOUSE_TOGGLE);
|
|
|
|
#ifdef HAVE_MENU
|
2015-07-09 04:27:17 +00:00
|
|
|
cmd->menu_pressed = BIT64_GET(trigger_input, RARCH_MENU_TOGGLE) ||
|
|
|
|
rarch_main_cmd_get_state_menu_toggle_button_combo(input,
|
|
|
|
old_input, trigger_input);
|
2015-03-24 09:01:17 +00:00
|
|
|
#endif
|
|
|
|
cmd->quit_key_pressed = BIT64_GET(input, RARCH_QUIT_KEY);
|
|
|
|
cmd->screenshot_pressed = BIT64_GET(trigger_input, RARCH_SCREENSHOT);
|
|
|
|
cmd->mute_pressed = BIT64_GET(trigger_input, RARCH_MUTE);
|
2015-04-27 03:36:41 +00:00
|
|
|
cmd->osk_pressed = BIT64_GET(trigger_input, RARCH_OSK);
|
2015-03-24 09:01:17 +00:00
|
|
|
cmd->volume_up_pressed = BIT64_GET(input, RARCH_VOLUME_UP);
|
|
|
|
cmd->volume_down_pressed = BIT64_GET(input, RARCH_VOLUME_DOWN);
|
|
|
|
cmd->reset_pressed = BIT64_GET(trigger_input, RARCH_RESET);
|
|
|
|
cmd->disk_prev_pressed = BIT64_GET(trigger_input, RARCH_DISK_PREV);
|
|
|
|
cmd->disk_next_pressed = BIT64_GET(trigger_input, RARCH_DISK_NEXT);
|
|
|
|
cmd->disk_eject_pressed = BIT64_GET(trigger_input, RARCH_DISK_EJECT_TOGGLE);
|
|
|
|
cmd->movie_record = BIT64_GET(trigger_input, RARCH_MOVIE_RECORD_TOGGLE);
|
|
|
|
cmd->save_state_pressed = BIT64_GET(trigger_input, RARCH_SAVE_STATE_KEY);
|
|
|
|
cmd->load_state_pressed = BIT64_GET(trigger_input, RARCH_LOAD_STATE_KEY);
|
|
|
|
cmd->slowmotion_pressed = BIT64_GET(input, RARCH_SLOWMOTION);
|
|
|
|
cmd->shader_next_pressed = BIT64_GET(trigger_input, RARCH_SHADER_NEXT);
|
|
|
|
cmd->shader_prev_pressed = BIT64_GET(trigger_input, RARCH_SHADER_PREV);
|
|
|
|
cmd->fastforward_pressed = BIT64_GET(trigger_input, RARCH_FAST_FORWARD_KEY);
|
|
|
|
cmd->hold_pressed = BIT64_GET(input, RARCH_FAST_FORWARD_HOLD_KEY);
|
|
|
|
cmd->old_hold_pressed = BIT64_GET(old_input, RARCH_FAST_FORWARD_HOLD_KEY);
|
|
|
|
cmd->state_slot_increase = BIT64_GET(trigger_input, RARCH_STATE_SLOT_PLUS);
|
|
|
|
cmd->state_slot_decrease = BIT64_GET(trigger_input, RARCH_STATE_SLOT_MINUS);
|
|
|
|
cmd->pause_pressed = BIT64_GET(trigger_input, RARCH_PAUSE_TOGGLE);
|
|
|
|
cmd->frameadvance_pressed = BIT64_GET(trigger_input, RARCH_FRAMEADVANCE);
|
2015-04-05 19:34:53 +00:00
|
|
|
cmd->rewind_pressed = BIT64_GET(input, RARCH_REWIND);
|
2015-03-24 09:01:17 +00:00
|
|
|
cmd->netplay_flip_pressed = BIT64_GET(trigger_input, RARCH_NETPLAY_FLIP);
|
|
|
|
cmd->fullscreen_toggle = BIT64_GET(trigger_input, RARCH_FULLSCREEN_TOGGLE_KEY);
|
|
|
|
cmd->cheat_index_plus_pressed = BIT64_GET(trigger_input,
|
|
|
|
RARCH_CHEAT_INDEX_PLUS);
|
|
|
|
cmd->cheat_index_minus_pressed = BIT64_GET(trigger_input,
|
|
|
|
RARCH_CHEAT_INDEX_MINUS);
|
|
|
|
cmd->cheat_toggle_pressed = BIT64_GET(trigger_input,
|
|
|
|
RARCH_CHEAT_TOGGLE);
|
|
|
|
}
|
|
|
|
|
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;
|
2015-06-26 17:57:40 +00:00
|
|
|
retro_input_t trigger_input, old_input;
|
2015-04-13 09:41:44 +00:00
|
|
|
event_cmd_state_t cmd = {0};
|
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-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-03-20 18:48:23 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-03-21 01:07:46 +00:00
|
|
|
global_t *global = global_get_ptr();
|
2015-07-12 17:06:24 +00:00
|
|
|
runloop_t *runloop = rarch_main_get_ptr();
|
|
|
|
retro_input_t input = input_keys_pressed(driver, settings, global);
|
2015-06-25 11:06:06 +00:00
|
|
|
rarch_system_info_t *system = rarch_system_info_get_ptr();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-06-26 17:57:40 +00:00
|
|
|
old_input = last_input;
|
2015-06-26 17:37:03 +00:00
|
|
|
last_input = input;
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->flushing_input)
|
2015-07-12 17:06:24 +00:00
|
|
|
driver->flushing_input = (input) ? input_flush(runloop, &input) : false;
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
trigger_input = input & ~old_input;
|
|
|
|
|
2015-03-24 09:01:17 +00:00
|
|
|
rarch_main_cmd_get_state(&cmd, input, old_input, trigger_input);
|
2015-03-24 08:44:18 +00:00
|
|
|
|
2015-07-12 17:06:24 +00:00
|
|
|
if (time_to_exit(driver, global, runloop, &cmd))
|
2015-07-12 17:17:57 +00:00
|
|
|
return rarch_main_iterate_quit(settings, global);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-06-25 11:06:06 +00:00
|
|
|
if (system->frame_time.callback)
|
2015-07-12 17:06:24 +00:00
|
|
|
rarch_update_frame_time(driver, settings, runloop);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-07-12 17:17:57 +00:00
|
|
|
do_pre_state_checks(settings, global, runloop, &cmd);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-02-21 06:29:13 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2015-07-12 17:17:57 +00:00
|
|
|
rarch_main_iterate_linefeed_overlay(driver, settings);
|
2015-02-21 06:29:13 +00:00
|
|
|
#endif
|
2015-02-22 06:34:33 +00:00
|
|
|
|
2015-01-10 21:51:03 +00:00
|
|
|
#ifdef HAVE_MENU
|
2015-05-19 18:11:57 +00:00
|
|
|
if (menu_driver_alive())
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-05-15 16:05:52 +00:00
|
|
|
menu_handle_t *menu = menu_driver_get_ptr();
|
|
|
|
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
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (!input && settings->menu.pause_libretro)
|
2015-05-15 16:05:52 +00:00
|
|
|
ret = 1;
|
2014-10-04 23:31:48 +00:00
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->exec)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-21 01:07:46 +00:00
|
|
|
global->exec = false;
|
2015-07-12 17:17:57 +00:00
|
|
|
return rarch_main_iterate_quit(settings, global);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-12 17:06:24 +00:00
|
|
|
if (do_state_checks(driver, settings, global, runloop, &cmd))
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
|
|
|
/* 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
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->bsv.movie)
|
|
|
|
bsv_movie_set_frame_start(global->bsv.movie);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-06-25 11:06:06 +00:00
|
|
|
if (system->camera_callback.caps)
|
2014-10-04 23:31:48 +00:00
|
|
|
driver_camera_poll();
|
|
|
|
|
|
|
|
/* Update binds for analog dpad modes. */
|
2015-03-20 18:48:23 +00:00
|
|
|
for (i = 0; i < settings->input.max_users; i++)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
if (!settings->input.analog_dpad_mode[i])
|
2014-10-04 23:31:48 +00:00
|
|
|
continue;
|
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
input_push_analog_dpad(settings->input.binds[i],
|
|
|
|
settings->input.analog_dpad_mode[i]);
|
|
|
|
input_push_analog_dpad(settings->input.autoconf_binds[i],
|
|
|
|
settings->input.analog_dpad_mode[i]);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if ((settings->video.frame_delay > 0) && !driver->nonblock_state)
|
|
|
|
rarch_sleep(settings->video.frame_delay);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Run libretro for one frame. */
|
2015-02-10 20:18:47 +00:00
|
|
|
pretro_run();
|
2014-10-04 23:31:48 +00:00
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
for (i = 0; i < settings->input.max_users; i++)
|
2014-10-04 23:31:48 +00:00
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
if (!settings->input.analog_dpad_mode[i])
|
2014-10-04 23:31:48 +00:00
|
|
|
continue;
|
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
input_pop_analog_dpad(settings->input.binds[i]);
|
|
|
|
input_pop_analog_dpad(settings->input.autoconf_binds[i]);
|
2014-10-04 23:31:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 01:07:46 +00:00
|
|
|
if (global->bsv.movie)
|
|
|
|
bsv_movie_set_frame_end(global->bsv.movie);
|
2014-10-04 23:31:48 +00:00
|
|
|
|
|
|
|
#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:
|
2015-03-20 18:48:23 +00:00
|
|
|
if (settings->fastforward_ratio_throttle_enable)
|
2015-07-12 17:06:24 +00:00
|
|
|
rarch_limit_frame_time(settings, runloop);
|
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
|
|
|
}
|