2014-09-23 03:03:56 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-03-22 03:09:18 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2015-01-07 17:46:50 +01:00
|
|
|
* Copyright (C) 2012-2015 - Michael Lelli
|
2019-02-22 16:31:54 -05:00
|
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
2014-09-23 03:03:56 +02: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-30 00:38:10 +02:00
|
|
|
|
|
|
|
#include <boolean.h>
|
2016-03-20 14:53:54 +01:00
|
|
|
#include <lists/string_list.h>
|
2017-01-24 16:08:25 +01:00
|
|
|
#include <string/stdstring.h>
|
2016-05-10 19:03:53 +02:00
|
|
|
#include <libretro.h>
|
2015-06-30 00:38:10 +02:00
|
|
|
|
2016-09-06 23:53:44 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-09-29 21:07:10 +02:00
|
|
|
#ifdef HAVE_NETWORKING
|
2016-09-08 06:07:43 +02:00
|
|
|
#include "network/netplay/netplay.h"
|
|
|
|
#endif
|
|
|
|
|
2017-01-23 16:17:57 +01:00
|
|
|
#include "core.h"
|
2017-01-25 00:34:58 +01:00
|
|
|
#include "content.h"
|
2016-03-22 02:56:06 +01:00
|
|
|
#include "dynamic.h"
|
2016-01-27 08:13:54 +01:00
|
|
|
#include "msg_hash.h"
|
2016-05-09 18:20:52 +02:00
|
|
|
#include "managers/state_manager.h"
|
2016-09-01 05:36:52 +02:00
|
|
|
#include "verbosity.h"
|
2015-11-24 01:26:59 +01:00
|
|
|
#include "gfx/video_driver.h"
|
2015-11-23 19:40:09 +01:00
|
|
|
#include "audio/audio_driver.h"
|
2018-09-07 19:09:56 -04:00
|
|
|
#include "tasks/tasks_internal.h"
|
2014-09-23 03:03:56 +02:00
|
|
|
|
2018-03-29 15:38:22 +02:00
|
|
|
#ifdef HAVE_RUNAHEAD
|
2018-03-28 14:22:07 -05:00
|
|
|
#include "runahead/copy_load_info.h"
|
|
|
|
#include "runahead/secondary_core.h"
|
2018-03-29 15:38:22 +02:00
|
|
|
#endif
|
2018-03-28 14:22:07 -05:00
|
|
|
|
2017-05-21 09:30:32 +02:00
|
|
|
struct retro_callbacks retro_ctx;
|
2017-05-21 09:07:19 +02:00
|
|
|
struct retro_core_t current_core;
|
2016-01-27 01:16:53 +01:00
|
|
|
|
2017-05-21 09:30:32 +02:00
|
|
|
static void retro_run_null(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void retro_frame_null(const void *data, unsigned width,
|
|
|
|
unsigned height, size_t pitch)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void retro_input_poll_null(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-08 00:31:21 +02:00
|
|
|
static void core_input_state_poll_maybe(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
if (current_core.poll_type == POLL_TYPE_NORMAL)
|
2016-05-08 00:31:21 +02:00
|
|
|
input_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int16_t core_input_state_poll(unsigned port,
|
2016-01-27 01:16:53 +01:00
|
|
|
unsigned device, unsigned idx, unsigned id)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
if (current_core.poll_type == POLL_TYPE_LATE)
|
2016-01-27 01:16:53 +01:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
if (!current_core.input_polled)
|
2016-01-27 01:16:53 +01:00
|
|
|
input_poll();
|
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.input_polled = true;
|
2016-01-27 01:16:53 +01:00
|
|
|
}
|
|
|
|
return input_state(port, device, idx, id);
|
|
|
|
}
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
void core_set_input_state(retro_ctx_input_state_info_t *info)
|
2015-12-05 16:54:03 +01:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_input_state(info->cb);
|
2015-12-05 16:54:03 +01:00
|
|
|
}
|
|
|
|
|
2015-01-08 18:39:17 +01:00
|
|
|
/**
|
2016-05-08 00:31:21 +02:00
|
|
|
* core_init_libretro_cbs:
|
2015-01-08 18:39:17 +01:00
|
|
|
* @data : pointer to retro_callbacks object
|
|
|
|
*
|
2016-11-04 19:56:31 +00:00
|
|
|
* Initializes libretro callbacks, and binds the libretro callbacks
|
2015-01-08 18:39:17 +01:00
|
|
|
* to default callback functions.
|
|
|
|
**/
|
2017-05-21 10:31:25 +02:00
|
|
|
static bool core_init_libretro_cbs(struct retro_callbacks *cbs)
|
2014-09-23 03:03:56 +02:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_video_refresh(video_driver_frame);
|
|
|
|
current_core.retro_set_audio_sample(audio_driver_sample);
|
|
|
|
current_core.retro_set_audio_sample_batch(audio_driver_sample_batch);
|
|
|
|
current_core.retro_set_input_state(core_input_state_poll);
|
|
|
|
current_core.retro_set_input_poll(core_input_state_poll_maybe);
|
2014-09-23 03:03:56 +02:00
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
core_set_default_callbacks(cbs);
|
2014-09-23 03:55:19 +02:00
|
|
|
|
2016-09-29 21:07:10 +02:00
|
|
|
#ifdef HAVE_NETWORKING
|
2015-12-05 16:38:24 +01:00
|
|
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
2016-01-27 03:14:36 +01:00
|
|
|
return true;
|
2014-09-23 03:03:56 +02:00
|
|
|
|
2016-09-28 22:45:31 -04:00
|
|
|
core_set_netplay_callbacks();
|
2014-09-23 03:03:56 +02:00
|
|
|
#endif
|
2016-01-27 03:14:36 +01:00
|
|
|
|
|
|
|
return true;
|
2014-09-23 03:03:56 +02:00
|
|
|
}
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
/**
|
|
|
|
* core_set_default_callbacks:
|
|
|
|
* @data : pointer to retro_callbacks object
|
|
|
|
*
|
|
|
|
* Binds the libretro callbacks to default callback functions.
|
|
|
|
**/
|
2017-05-21 10:34:50 +02:00
|
|
|
bool core_set_default_callbacks(struct retro_callbacks *cbs)
|
2016-05-08 01:33:57 +02:00
|
|
|
{
|
|
|
|
cbs->frame_cb = video_driver_frame;
|
|
|
|
cbs->sample_cb = audio_driver_sample;
|
|
|
|
cbs->sample_batch_cb = audio_driver_sample_batch;
|
|
|
|
cbs->state_cb = core_input_state_poll;
|
|
|
|
cbs->poll_cb = input_poll;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_deinit(void *data)
|
|
|
|
{
|
|
|
|
struct retro_callbacks *cbs = (struct retro_callbacks*)data;
|
|
|
|
|
|
|
|
if (!cbs)
|
|
|
|
return false;
|
|
|
|
|
2017-05-21 09:30:32 +02:00
|
|
|
cbs->frame_cb = retro_frame_null;
|
2016-05-08 01:33:57 +02:00
|
|
|
cbs->sample_cb = NULL;
|
|
|
|
cbs->sample_batch_cb = NULL;
|
|
|
|
cbs->state_cb = NULL;
|
2017-05-21 09:30:32 +02:00
|
|
|
cbs->poll_cb = retro_input_poll_null;
|
2016-05-08 01:33:57 +02:00
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.inited = false;
|
2016-09-06 03:52:29 +02:00
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_uninit_libretro_callbacks(void)
|
|
|
|
{
|
|
|
|
return core_deinit(&retro_ctx);
|
|
|
|
}
|
|
|
|
|
2015-01-08 18:39:17 +01:00
|
|
|
/**
|
2016-05-08 00:31:21 +02:00
|
|
|
* core_set_rewind_callbacks:
|
2015-01-08 18:39:17 +01:00
|
|
|
*
|
|
|
|
* Sets the audio sampling callbacks based on whether or not
|
|
|
|
* rewinding is currently activated.
|
|
|
|
**/
|
2016-05-08 01:33:57 +02:00
|
|
|
bool core_set_rewind_callbacks(void)
|
2014-09-23 03:03:56 +02:00
|
|
|
{
|
2015-09-16 11:14:43 +02:00
|
|
|
if (state_manager_frame_is_reversed())
|
2014-09-23 03:03:56 +02:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_audio_sample(audio_driver_sample_rewind);
|
|
|
|
current_core.retro_set_audio_sample_batch(audio_driver_sample_batch_rewind);
|
2014-09-23 03:03:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_audio_sample(audio_driver_sample);
|
|
|
|
current_core.retro_set_audio_sample_batch(audio_driver_sample_batch);
|
2014-09-23 03:03:56 +02:00
|
|
|
}
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-29 22:10:21 +01:00
|
|
|
#ifdef HAVE_NETWORKING
|
2016-09-28 22:45:31 -04:00
|
|
|
/**
|
|
|
|
* core_set_netplay_callbacks:
|
|
|
|
*
|
|
|
|
* Set the I/O callbacks to use netplay's interceding callback system. Should
|
2016-12-17 23:08:59 -05:00
|
|
|
* only be called while initializing netplay.
|
2016-09-28 22:45:31 -04:00
|
|
|
**/
|
|
|
|
bool core_set_netplay_callbacks(void)
|
|
|
|
{
|
|
|
|
/* Force normal poll type for netplay. */
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.poll_type = POLL_TYPE_NORMAL;
|
2016-09-28 22:45:31 -04:00
|
|
|
|
|
|
|
/* And use netplay's interceding callbacks */
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_video_refresh(video_frame_net);
|
|
|
|
current_core.retro_set_audio_sample(audio_sample_net);
|
|
|
|
current_core.retro_set_audio_sample_batch(audio_sample_batch_net);
|
|
|
|
current_core.retro_set_input_state(input_state_net);
|
2016-09-28 22:45:31 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-17 23:08:59 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* core_unset_netplay_callbacks
|
|
|
|
*
|
|
|
|
* Unset the I/O callbacks from having used netplay's interceding callback
|
|
|
|
* system. Should only be called while uninitializing netplay.
|
|
|
|
*/
|
|
|
|
bool core_unset_netplay_callbacks(void)
|
|
|
|
{
|
|
|
|
struct retro_callbacks cbs;
|
|
|
|
if (!core_set_default_callbacks(&cbs))
|
|
|
|
return false;
|
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_video_refresh(cbs.frame_cb);
|
|
|
|
current_core.retro_set_audio_sample(cbs.sample_cb);
|
|
|
|
current_core.retro_set_audio_sample_batch(cbs.sample_batch_cb);
|
|
|
|
current_core.retro_set_input_state(cbs.state_cb);
|
2016-12-17 23:08:59 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-29 22:10:21 +01:00
|
|
|
#endif
|
2016-09-28 22:45:31 -04:00
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
bool core_set_cheat(retro_ctx_cheat_info_t *info)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_cheat_set(info->index, info->enabled, info->code);
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
2014-09-23 03:03:56 +02:00
|
|
|
}
|
2016-01-27 03:08:49 +01:00
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
bool core_reset_cheat(void)
|
2016-01-27 03:08:49 +01:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_cheat_reset();
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-01-27 04:54:22 +01:00
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
bool core_api_version(retro_ctx_api_info_t *api)
|
|
|
|
{
|
|
|
|
if (!api)
|
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
api->version = current_core.retro_api_version();
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_set_poll_type(unsigned *type)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.poll_type = *type;
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-23 07:06:32 +02:00
|
|
|
void core_uninit_symbols(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
uninit_libretro_sym(¤t_core);
|
|
|
|
current_core.symbols_inited = false;
|
|
|
|
}
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
bool core_init_symbols(enum rarch_core_type *type)
|
|
|
|
{
|
2017-05-21 10:34:50 +02:00
|
|
|
if (!type || !init_libretro_sym(*type, ¤t_core))
|
2016-10-11 20:28:36 -04:00
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
|
|
|
|
if (!current_core.retro_run)
|
|
|
|
current_core.retro_run = retro_run_null;
|
|
|
|
current_core.symbols_inited = true;
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_set_controller_port_device(retro_ctx_controller_info_t *pad)
|
|
|
|
{
|
|
|
|
if (!pad)
|
|
|
|
return false;
|
2018-03-28 14:22:07 -05:00
|
|
|
|
2018-03-29 15:38:22 +02:00
|
|
|
#ifdef HAVE_RUNAHEAD
|
2018-03-28 14:22:07 -05:00
|
|
|
remember_controller_port_device(pad->port, pad->device);
|
2018-03-29 15:38:22 +02:00
|
|
|
#endif
|
2018-03-28 14:22:07 -05:00
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_controller_port_device(pad->port, pad->device);
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_get_memory(retro_ctx_memory_info_t *info)
|
|
|
|
{
|
|
|
|
if (!info)
|
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
info->size = current_core.retro_get_memory_size(info->id);
|
|
|
|
info->data = current_core.retro_get_memory_data(info->id);
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_load_game(retro_ctx_load_content_info_t *load_info)
|
|
|
|
{
|
2017-01-25 15:44:21 +01:00
|
|
|
bool contentless = false;
|
2017-01-25 15:51:57 +01:00
|
|
|
bool is_inited = false;
|
2017-01-25 15:44:21 +01:00
|
|
|
|
2018-07-06 09:53:31 -05:00
|
|
|
video_driver_set_cached_frame_ptr(NULL);
|
|
|
|
|
2018-03-29 15:38:22 +02:00
|
|
|
#ifdef HAVE_RUNAHEAD
|
2018-03-29 15:15:47 +02:00
|
|
|
set_load_content_info(load_info);
|
2018-03-31 12:15:14 -05:00
|
|
|
clear_controller_port_map();
|
2018-03-29 15:38:22 +02:00
|
|
|
#endif
|
2018-03-29 15:15:47 +02:00
|
|
|
|
2017-01-25 15:51:57 +01:00
|
|
|
content_get_status(&contentless, &is_inited);
|
2018-09-07 19:09:56 -04:00
|
|
|
set_save_state_in_background(false);
|
2017-01-25 15:44:21 +01:00
|
|
|
|
2016-09-11 19:46:13 +02:00
|
|
|
if (load_info && load_info->special)
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.game_loaded = current_core.retro_load_game_special(
|
2016-09-29 20:35:26 +02:00
|
|
|
load_info->special->id, load_info->info, load_info->content->size);
|
2017-01-24 16:08:25 +01:00
|
|
|
else if (load_info && !string_is_empty(load_info->content->elems[0].data))
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.game_loaded = current_core.retro_load_game(load_info->info);
|
2017-01-25 15:44:21 +01:00
|
|
|
else if (contentless)
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.game_loaded = current_core.retro_load_game(NULL);
|
2017-01-25 00:34:58 +01:00
|
|
|
else
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.game_loaded = false;
|
2016-09-03 17:50:04 +01:00
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
return current_core.game_loaded;
|
2016-05-08 01:33:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool core_get_system_info(struct retro_system_info *system)
|
|
|
|
{
|
|
|
|
if (!system)
|
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_get_system_info(system);
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_unserialize(retro_ctx_serialize_info_t *info)
|
|
|
|
{
|
2017-05-21 09:30:32 +02:00
|
|
|
if (!info || !current_core.retro_unserialize(info->data_const, info->size))
|
2016-05-08 01:33:57 +02:00
|
|
|
return false;
|
2016-10-04 13:44:35 -04:00
|
|
|
|
|
|
|
#if HAVE_NETWORKING
|
|
|
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_LOAD_SAVESTATE, info);
|
|
|
|
#endif
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_serialize(retro_ctx_serialize_info_t *info)
|
|
|
|
{
|
2017-05-21 09:30:32 +02:00
|
|
|
if (!info || !current_core.retro_serialize(info->data, info->size))
|
2016-05-08 01:33:57 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_serialize_size(retro_ctx_size_info_t *info)
|
|
|
|
{
|
|
|
|
if (!info)
|
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
info->size = current_core.retro_serialize_size();
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:37:02 -04:00
|
|
|
uint64_t core_serialization_quirks(void)
|
2016-09-30 14:51:05 -04:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
return current_core.serialization_quirks_v;
|
2016-09-30 14:51:05 -04:00
|
|
|
}
|
|
|
|
|
2016-09-30 15:37:02 -04:00
|
|
|
void core_set_serialization_quirks(uint64_t quirks)
|
2016-09-30 14:51:05 -04:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.serialization_quirks_v = quirks;
|
2016-09-30 14:51:05 -04:00
|
|
|
}
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
bool core_set_environment(retro_ctx_environ_info_t *info)
|
|
|
|
{
|
|
|
|
if (!info)
|
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_set_environment(info->env);
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_get_system_av_info(struct retro_system_av_info *av_info)
|
|
|
|
{
|
|
|
|
if (!av_info)
|
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_get_system_av_info(av_info);
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_reset(void)
|
|
|
|
{
|
2018-07-06 09:53:31 -05:00
|
|
|
video_driver_set_cached_frame_ptr(NULL);
|
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_reset();
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_init(void)
|
|
|
|
{
|
2018-07-06 09:53:31 -05:00
|
|
|
video_driver_set_cached_frame_ptr(NULL);
|
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_init();
|
|
|
|
current_core.inited = true;
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_unload(void)
|
|
|
|
{
|
2018-07-06 09:53:31 -05:00
|
|
|
video_driver_set_cached_frame_ptr(NULL);
|
|
|
|
|
2018-10-12 23:12:06 +02:00
|
|
|
if (current_core.inited)
|
|
|
|
current_core.retro_deinit();
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_unload_game(void)
|
|
|
|
{
|
2017-01-25 15:22:12 +01:00
|
|
|
video_driver_free_hw_context();
|
2017-05-28 17:21:57 +02:00
|
|
|
|
2018-07-06 09:53:31 -05:00
|
|
|
video_driver_set_cached_frame_ptr(NULL);
|
|
|
|
|
2018-10-12 23:12:06 +02:00
|
|
|
if (current_core.game_loaded)
|
|
|
|
{
|
|
|
|
current_core.retro_unload_game();
|
|
|
|
current_core.game_loaded = false;
|
|
|
|
}
|
2018-07-06 09:53:31 -05:00
|
|
|
|
2018-08-14 00:16:08 +02:00
|
|
|
audio_driver_stop();
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool core_run(void)
|
|
|
|
{
|
2016-10-04 13:40:07 -04:00
|
|
|
#ifdef HAVE_NETWORKING
|
|
|
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_PRE_FRAME, NULL))
|
|
|
|
{
|
2016-12-16 10:13:44 -05:00
|
|
|
/* Paused due to netplay. We must poll and display something so that a
|
|
|
|
* netplay peer pausing doesn't just hang. */
|
|
|
|
input_poll();
|
|
|
|
video_driver_cached_frame();
|
2016-10-04 13:40:07 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
switch (current_core.poll_type)
|
2016-01-27 03:08:49 +01:00
|
|
|
{
|
2016-05-08 01:33:57 +02:00
|
|
|
case POLL_TYPE_EARLY:
|
|
|
|
input_poll();
|
2016-04-06 00:20:14 +02:00
|
|
|
break;
|
2016-05-08 01:33:57 +02:00
|
|
|
case POLL_TYPE_LATE:
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.input_polled = false;
|
2016-01-27 03:08:49 +01:00
|
|
|
break;
|
2016-09-29 20:35:26 +02:00
|
|
|
default:
|
|
|
|
break;
|
2016-01-27 03:08:49 +01:00
|
|
|
}
|
2016-09-29 20:35:26 +02:00
|
|
|
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.retro_run();
|
|
|
|
|
|
|
|
if (current_core.poll_type == POLL_TYPE_LATE && !current_core.input_polled)
|
2016-05-08 01:33:57 +02:00
|
|
|
input_poll();
|
2016-10-04 13:40:07 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_NETWORKING
|
|
|
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_POST_FRAME, NULL);
|
|
|
|
#endif
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:22:07 -05:00
|
|
|
bool core_run_no_input_polling(void)
|
|
|
|
{
|
|
|
|
current_core.retro_run();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-23 14:50:00 +01:00
|
|
|
bool core_load(unsigned poll_type_behavior)
|
2016-05-08 01:33:57 +02:00
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.poll_type = poll_type_behavior;
|
2016-05-08 01:33:57 +02:00
|
|
|
|
|
|
|
if (!core_verify_api_version())
|
|
|
|
return false;
|
|
|
|
if (!core_init_libretro_cbs(&retro_ctx))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
core_get_system_av_info(video_viewport_get_system_av_info());
|
2016-01-27 03:08:49 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-08 01:33:57 +02:00
|
|
|
|
|
|
|
bool core_verify_api_version(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
unsigned api_version = current_core.retro_api_version();
|
2016-11-04 19:56:31 +00:00
|
|
|
RARCH_LOG("%s: %u\n",
|
2016-06-20 04:23:00 +02:00
|
|
|
msg_hash_to_str(MSG_VERSION_OF_LIBRETRO_API),
|
|
|
|
api_version);
|
2016-11-04 19:56:31 +00:00
|
|
|
RARCH_LOG("%s: %u\n",
|
2016-06-20 04:23:00 +02:00
|
|
|
msg_hash_to_str(MSG_COMPILED_AGAINST_API),
|
|
|
|
RETRO_API_VERSION);
|
2016-05-08 01:33:57 +02:00
|
|
|
|
|
|
|
if (api_version != RETRO_API_VERSION)
|
|
|
|
{
|
|
|
|
RARCH_WARN("%s\n", msg_hash_to_str(MSG_LIBRETRO_ABI_BREAK));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-03 17:50:04 +01:00
|
|
|
bool core_get_region(retro_ctx_region_info_t *info)
|
|
|
|
{
|
|
|
|
if (!info)
|
|
|
|
return false;
|
2017-05-21 09:07:19 +02:00
|
|
|
info->region = current_core.retro_get_region();
|
2016-09-03 17:50:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-08 01:33:57 +02:00
|
|
|
bool core_has_set_input_descriptor(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
return current_core.has_set_input_descriptors;
|
2016-05-08 01:33:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void core_set_input_descriptors(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.has_set_input_descriptors = true;
|
2016-05-08 01:33:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void core_unset_input_descriptors(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
current_core.has_set_input_descriptors = false;
|
2016-05-08 01:33:57 +02:00
|
|
|
}
|
2016-09-03 17:50:04 +01:00
|
|
|
|
2016-09-06 03:52:29 +02:00
|
|
|
bool core_is_inited(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
return current_core.inited;
|
2016-09-06 03:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool core_is_symbols_inited(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
return current_core.symbols_inited;
|
2016-09-06 03:52:29 +02:00
|
|
|
}
|
|
|
|
|
2016-09-03 17:50:04 +01:00
|
|
|
bool core_is_game_loaded(void)
|
|
|
|
{
|
2017-05-21 09:07:19 +02:00
|
|
|
return current_core.game_loaded;
|
2016-09-03 17:50:04 +01:00
|
|
|
}
|