2014-09-23 01:03:56 +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
|
2014-09-23 01:03:56 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2015-06-29 22:38:10 +00:00
|
|
|
|
|
|
|
#include <retro_inline.h>
|
|
|
|
#include <retro_log.h>
|
|
|
|
#include <boolean.h>
|
|
|
|
|
|
|
|
#include "libretro.h"
|
2014-09-23 01:03:56 +00:00
|
|
|
#include "general.h"
|
2015-03-15 01:47:23 +00:00
|
|
|
#include "runloop.h"
|
2015-04-10 23:17:26 +00:00
|
|
|
#include "runloop_data.h"
|
2015-01-09 16:40:47 +00:00
|
|
|
#include "retroarch.h"
|
2015-09-16 09:14:43 +00:00
|
|
|
#include "rewind.h"
|
2014-09-23 01:03:56 +00:00
|
|
|
#include "performance.h"
|
2015-04-10 01:10:01 +00:00
|
|
|
#include "input/input_remapping.h"
|
2015-02-10 20:09:41 +00:00
|
|
|
#include "record/record_driver.h"
|
2015-06-25 08:15:26 +00:00
|
|
|
#include "gfx/video_pixel_converter.h"
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2014-10-20 19:32:53 +00:00
|
|
|
#ifdef HAVE_NETPLAY
|
|
|
|
#include "netplay.h"
|
|
|
|
#endif
|
|
|
|
|
2015-01-07 16:02:47 +00:00
|
|
|
/**
|
|
|
|
* video_frame:
|
|
|
|
* @data : pointer to data of the video frame.
|
|
|
|
* @width : width of the video frame.
|
|
|
|
* @height : height of the video frame.
|
|
|
|
* @pitch : pitch of the video frame.
|
|
|
|
*
|
|
|
|
* Video frame render callback function.
|
|
|
|
**/
|
2014-09-23 01:03:56 +00:00
|
|
|
static void video_frame(const void *data, unsigned width,
|
|
|
|
unsigned height, size_t pitch)
|
|
|
|
{
|
2015-08-03 21:01:07 +00:00
|
|
|
uint64_t *frame_count = NULL;
|
2015-07-08 15:22:35 +00:00
|
|
|
unsigned output_width = 0;
|
|
|
|
unsigned output_height = 0;
|
|
|
|
unsigned output_pitch = 0;
|
|
|
|
const char *msg = NULL;
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-07-12 09:14:41 +00:00
|
|
|
const video_driver_t *video =
|
|
|
|
driver ? (const video_driver_t*)driver->video : NULL;
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->video_active)
|
2014-09-23 01:03:56 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-25 08:15:26 +00:00
|
|
|
if (video_pixel_frame_scale(data, width, height, pitch))
|
2015-02-19 15:07:11 +00:00
|
|
|
{
|
2015-06-25 08:37:10 +00:00
|
|
|
video_pixel_scaler_t *scaler = scaler_get_ptr();
|
|
|
|
|
|
|
|
data = scaler->scaler_out;
|
|
|
|
pitch = scaler->scaler->out_stride;
|
2015-02-19 15:07:11 +00:00
|
|
|
}
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2015-06-17 14:32:08 +00:00
|
|
|
video_driver_cached_frame_set(data, width, height, pitch);
|
|
|
|
|
2014-09-23 01:03:56 +00:00
|
|
|
/* Slightly messy code,
|
|
|
|
* but we really need to do processing before blocking on VSync
|
|
|
|
* for best possible scheduling.
|
|
|
|
*/
|
2015-05-20 18:49:52 +00:00
|
|
|
if ((!video_driver_frame_filter_alive()
|
2015-03-20 18:48:23 +00:00
|
|
|
|| !settings->video.post_filter_record || !data
|
2015-03-21 03:43:18 +00:00
|
|
|
|| global->record.gpu_buffer)
|
2014-09-23 01:03:56 +00:00
|
|
|
)
|
2015-02-10 20:09:41 +00:00
|
|
|
recording_dump_frame(data, width, height, pitch);
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2015-03-15 01:47:23 +00:00
|
|
|
msg = rarch_main_msg_queue_pull();
|
2015-04-10 23:17:26 +00:00
|
|
|
|
2015-06-09 20:02:28 +00:00
|
|
|
*driver->current_msg = 0;
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
strlcpy(driver->current_msg, msg, sizeof(driver->current_msg));
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2015-05-20 18:49:52 +00:00
|
|
|
if (video_driver_frame_filter(data, width, height, pitch,
|
2015-02-15 17:32:19 +00:00
|
|
|
&output_width, &output_height, &output_pitch))
|
|
|
|
{
|
2015-05-20 18:49:52 +00:00
|
|
|
data = video_driver_frame_filter_get_buf_ptr();
|
2015-02-15 17:32:19 +00:00
|
|
|
width = output_width;
|
|
|
|
height = output_height;
|
|
|
|
pitch = output_pitch;
|
|
|
|
}
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2015-08-03 21:01:07 +00:00
|
|
|
frame_count = video_driver_get_frame_count();
|
|
|
|
|
|
|
|
if (!video->frame(driver->video_data, data, width, height, *frame_count,
|
|
|
|
pitch, driver->current_msg))
|
2015-03-24 12:27:38 +00:00
|
|
|
driver->video_active = false;
|
2015-08-03 21:01:07 +00:00
|
|
|
|
|
|
|
*frame_count = *frame_count + 1;
|
2014-09-23 01:03:56 +00:00
|
|
|
}
|
|
|
|
|
2015-01-07 16:02:47 +00:00
|
|
|
/**
|
|
|
|
* input_state:
|
|
|
|
* @port : user number.
|
|
|
|
* @device : device identifier of user.
|
|
|
|
* @idx : index value of user.
|
|
|
|
* @id : identifier of key pressed by user.
|
|
|
|
*
|
|
|
|
* Input state callback function.
|
|
|
|
*
|
|
|
|
* Returns: Non-zero if the given key (identified by @id) was pressed by the user
|
|
|
|
* (assigned to @port).
|
|
|
|
**/
|
2014-09-23 01:03:56 +00:00
|
|
|
static int16_t input_state(unsigned port, unsigned device,
|
2014-10-20 21:24:01 +00:00
|
|
|
unsigned idx, unsigned id)
|
2014-09-23 01:03:56 +00:00
|
|
|
{
|
2015-06-27 13:36:53 +00:00
|
|
|
size_t i;
|
|
|
|
const struct retro_keybind *libretro_input_binds[MAX_USERS];
|
2015-07-08 23:10:30 +00:00
|
|
|
int16_t res = 0;
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
global_t *global = global_get_ptr();
|
2015-07-12 09:14:41 +00:00
|
|
|
const input_driver_t *input = driver ?
|
|
|
|
(const input_driver_t*)driver->input : NULL;
|
2015-06-27 13:36:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_USERS; i++)
|
|
|
|
libretro_input_binds[i] = settings->input.binds[i];
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2015-01-05 21:53:21 +00:00
|
|
|
device &= RETRO_DEVICE_MASK;
|
|
|
|
|
2015-03-21 03:43:18 +00:00
|
|
|
if (global->bsv.movie && global->bsv.movie_playback)
|
2015-01-05 21:53:21 +00:00
|
|
|
{
|
|
|
|
int16_t ret;
|
2015-03-21 03:43:18 +00:00
|
|
|
if (bsv_movie_get_input(global->bsv.movie, &ret))
|
2015-01-05 21:53:21 +00:00
|
|
|
return ret;
|
|
|
|
|
2015-03-21 03:43:18 +00:00
|
|
|
global->bsv.movie_end = true;
|
2015-01-05 21:53:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:48:23 +00:00
|
|
|
if (settings->input.remap_binds_enable)
|
2015-04-10 01:10:01 +00:00
|
|
|
input_remapping_state(port, &device, &idx, &id);
|
2015-04-10 00:46:10 +00:00
|
|
|
|
2015-08-06 01:10:52 +00:00
|
|
|
if (!driver->flushing_input && !driver->block_libretro_input)
|
2014-12-28 04:57:17 +00:00
|
|
|
{
|
|
|
|
if (((id < RARCH_FIRST_META_KEY) || (device == RETRO_DEVICE_KEYBOARD)))
|
2015-07-12 09:14:41 +00:00
|
|
|
res = input->input_state(driver->input_data, libretro_input_binds, port, device, idx, id);
|
2014-09-23 01:03:56 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
2015-07-12 04:47:39 +00:00
|
|
|
input_state_overlay(&res, port, device, idx, id);
|
2014-09-23 01:03:56 +00:00
|
|
|
#endif
|
2014-12-28 14:20:01 +00:00
|
|
|
}
|
2014-09-23 01:03:56 +00:00
|
|
|
|
|
|
|
/* Don't allow turbo for D-pad. */
|
|
|
|
if (device == RETRO_DEVICE_JOYPAD && (id < RETRO_DEVICE_ID_JOYPAD_UP ||
|
|
|
|
id > RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
2015-08-03 21:28:34 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Apply turbo button if activated.
|
|
|
|
*
|
|
|
|
* If turbo button is held, all buttons pressed except
|
|
|
|
* for D-pad will go into a turbo mode. Until the button is
|
|
|
|
* released again, the input state will be modulated by a
|
|
|
|
* periodic pulse defined by the configured duty cycle.
|
|
|
|
*/
|
|
|
|
if (res && global->turbo.frame_enable[port])
|
2015-08-03 21:40:01 +00:00
|
|
|
global->turbo.enable[port] |= (1 << id);
|
2015-08-03 21:28:34 +00:00
|
|
|
else if (!res)
|
2015-08-03 21:40:01 +00:00
|
|
|
global->turbo.enable[port] &= ~(1 << id);
|
2015-08-03 21:28:34 +00:00
|
|
|
|
2015-08-03 21:40:01 +00:00
|
|
|
if (global->turbo.enable[port] & (1 << id))
|
2015-08-03 21:28:34 +00:00
|
|
|
{
|
|
|
|
/* if turbo button is enabled for this key ID */
|
|
|
|
res = res && ((global->turbo.count % settings->input.turbo_period)
|
|
|
|
< settings->input.turbo_duty_cycle);
|
|
|
|
}
|
|
|
|
}
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2015-03-21 03:43:18 +00:00
|
|
|
if (global->bsv.movie && !global->bsv.movie_playback)
|
|
|
|
bsv_movie_set_input(global->bsv.movie, res);
|
2014-09-23 01:03:56 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-01-08 17:39:17 +00:00
|
|
|
/**
|
|
|
|
* input_poll:
|
|
|
|
*
|
|
|
|
* Input polling callback function.
|
|
|
|
**/
|
2014-09-24 07:52:01 +00:00
|
|
|
static void input_poll(void)
|
|
|
|
{
|
2015-03-20 18:48:23 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-07-12 09:14:41 +00:00
|
|
|
const input_driver_t *input = driver ?
|
|
|
|
(const input_driver_t*)driver->input : NULL;
|
2015-03-18 18:40:00 +00:00
|
|
|
|
2015-08-30 21:19:45 +00:00
|
|
|
(void)settings;
|
|
|
|
|
2015-07-12 09:14:41 +00:00
|
|
|
input->poll(driver->input_data);
|
2014-09-24 07:52:01 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_OVERLAY
|
2015-07-12 04:47:39 +00:00
|
|
|
input_poll_overlay(settings->input.overlay_opacity);
|
2014-09-24 07:52:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_COMMAND
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->command)
|
|
|
|
rarch_cmd_poll(driver->command);
|
2014-09-24 07:52:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-01-08 17:39:17 +00:00
|
|
|
/**
|
|
|
|
* retro_set_default_callbacks:
|
|
|
|
* @data : pointer to retro_callbacks object
|
|
|
|
*
|
|
|
|
* Binds the libretro callbacks to default callback functions.
|
|
|
|
**/
|
2014-09-23 02:42:49 +00:00
|
|
|
void retro_set_default_callbacks(void *data)
|
2014-09-23 01:55:19 +00:00
|
|
|
{
|
2014-09-23 02:42:49 +00:00
|
|
|
struct retro_callbacks *cbs = (struct retro_callbacks*)data;
|
|
|
|
|
|
|
|
if (!cbs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cbs->frame_cb = video_frame;
|
2015-05-19 19:18:07 +00:00
|
|
|
cbs->sample_cb = audio_driver_sample;
|
|
|
|
cbs->sample_batch_cb = audio_driver_sample_batch;
|
2014-09-23 02:42:49 +00:00
|
|
|
cbs->state_cb = input_state;
|
2014-09-24 07:52:01 +00:00
|
|
|
cbs->poll_cb = input_poll;
|
2014-09-23 01:55:19 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 17:39:17 +00:00
|
|
|
/**
|
2015-01-08 17:42:27 +00:00
|
|
|
* retro_init_libretro_cbs:
|
2015-01-08 17:39:17 +00:00
|
|
|
* @data : pointer to retro_callbacks object
|
|
|
|
*
|
|
|
|
* Initializes libretro callbacks, and binds the libretro callbacks
|
|
|
|
* to default callback functions.
|
|
|
|
**/
|
2014-09-23 02:42:49 +00:00
|
|
|
void retro_init_libretro_cbs(void *data)
|
2014-09-23 01:03:56 +00:00
|
|
|
{
|
2014-09-23 02:42:49 +00:00
|
|
|
struct retro_callbacks *cbs = (struct retro_callbacks*)data;
|
2015-07-08 15:22:35 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
global_t *global = global_get_ptr();
|
2014-09-23 02:42:49 +00:00
|
|
|
|
|
|
|
if (!cbs)
|
|
|
|
return;
|
|
|
|
|
2015-03-18 19:31:01 +00:00
|
|
|
(void)driver;
|
2015-03-21 05:55:34 +00:00
|
|
|
(void)global;
|
2015-03-18 19:31:01 +00:00
|
|
|
|
2015-10-06 17:34:09 +00:00
|
|
|
core.retro_set_video_refresh(video_frame);
|
|
|
|
core.retro_set_audio_sample(audio_driver_sample);
|
|
|
|
core.retro_set_audio_sample_batch(audio_driver_sample_batch);
|
|
|
|
core.retro_set_input_state(input_state);
|
|
|
|
core.retro_set_input_poll(input_poll);
|
2014-09-23 01:03:56 +00:00
|
|
|
|
2014-09-23 01:55:19 +00:00
|
|
|
retro_set_default_callbacks(cbs);
|
|
|
|
|
2014-09-23 01:03:56 +00:00
|
|
|
#ifdef HAVE_NETPLAY
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->netplay_data)
|
2014-09-23 01:03:56 +00:00
|
|
|
return;
|
|
|
|
|
2015-07-27 15:18:10 +00:00
|
|
|
if (global->netplay.is_spectate)
|
2014-09-23 01:03:56 +00:00
|
|
|
{
|
2015-10-06 17:34:09 +00:00
|
|
|
core.retro_set_input_state(
|
2015-07-27 15:18:10 +00:00
|
|
|
(global->netplay.is_client ?
|
2014-09-23 01:03:56 +00:00
|
|
|
input_state_spectate_client : input_state_spectate)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-06 17:34:09 +00:00
|
|
|
core.retro_set_video_refresh(video_frame_net);
|
|
|
|
core.retro_set_audio_sample(audio_sample_net);
|
|
|
|
core.retro_set_audio_sample_batch(audio_sample_batch_net);
|
|
|
|
core.retro_set_input_state(input_state_net);
|
2014-09-23 01:03:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-01-08 17:39:17 +00:00
|
|
|
/**
|
|
|
|
* retro_set_rewind_callbacks:
|
|
|
|
*
|
|
|
|
* Sets the audio sampling callbacks based on whether or not
|
|
|
|
* rewinding is currently activated.
|
|
|
|
**/
|
2014-09-23 01:03:56 +00:00
|
|
|
void retro_set_rewind_callbacks(void)
|
|
|
|
{
|
2015-09-16 09:14:43 +00:00
|
|
|
if (state_manager_frame_is_reversed())
|
2014-09-23 01:03:56 +00:00
|
|
|
{
|
2015-10-06 17:34:09 +00:00
|
|
|
core.retro_set_audio_sample(audio_driver_sample_rewind);
|
|
|
|
core.retro_set_audio_sample_batch(audio_driver_sample_batch_rewind);
|
2014-09-23 01:03:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-06 17:34:09 +00:00
|
|
|
core.retro_set_audio_sample(audio_driver_sample);
|
|
|
|
core.retro_set_audio_sample_batch(audio_driver_sample_batch);
|
2014-09-23 01:03:56 +00:00
|
|
|
}
|
|
|
|
}
|