2013-07-27 15:40:21 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2013-11-13 11:43:28 +00:00
|
|
|
* Copyright (C) 2013 - Jason Fetters
|
2013-07-27 15:40:21 +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.
|
2013-07-27 15:45:56 +00:00
|
|
|
* * You should have received a copy of the GNU General Public License along with RetroArch.
|
2013-07-27 15:40:21 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dispatch/dispatch.h>
|
|
|
|
#include <pthread.h>
|
2013-09-05 05:20:56 +00:00
|
|
|
#include "../../apple/common/rarch_wrapper.h"
|
2013-11-22 00:10:35 +00:00
|
|
|
#include "../../apple/common/apple_export.h"
|
2013-07-28 21:01:16 +00:00
|
|
|
|
|
|
|
#include "../frontend_context.h"
|
2013-07-27 15:40:21 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "../../boolean.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static pthread_mutex_t apple_event_queue_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
void (*function)(void*);
|
|
|
|
void* userdata;
|
|
|
|
} apple_event_queue[16];
|
|
|
|
|
|
|
|
static uint32_t apple_event_queue_size;
|
|
|
|
|
|
|
|
void apple_frontend_post_event(void (*fn)(void*), void* userdata)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&apple_event_queue_lock);
|
|
|
|
|
|
|
|
if (apple_event_queue_size < 16)
|
|
|
|
{
|
|
|
|
apple_event_queue[apple_event_queue_size].function = fn;
|
|
|
|
apple_event_queue[apple_event_queue_size].userdata = userdata;
|
|
|
|
apple_event_queue_size ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&apple_event_queue_lock);
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:57:39 +00:00
|
|
|
void apple_event_basic_command(void* userdata)
|
|
|
|
{
|
2013-11-22 00:10:35 +00:00
|
|
|
int action = (int)userdata;
|
|
|
|
switch (action)
|
2013-11-21 23:57:39 +00:00
|
|
|
{
|
|
|
|
case RESET:
|
|
|
|
rarch_game_reset();
|
|
|
|
return;
|
|
|
|
case LOAD_STATE:
|
|
|
|
rarch_load_state();
|
|
|
|
return;
|
|
|
|
case SAVE_STATE:
|
|
|
|
rarch_save_state();
|
|
|
|
return;
|
|
|
|
case QUIT:
|
|
|
|
g_extern.system.shutdown = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void apple_event_set_state_slot(void* userdata)
|
|
|
|
{
|
|
|
|
g_extern.state_slot = (uint32_t)userdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
void apple_event_show_rgui(void* userdata)
|
|
|
|
{
|
|
|
|
const bool in_menu = g_extern.lifecycle_state & (1 << MODE_MENU);
|
|
|
|
g_extern.lifecycle_state &= ~(1ULL << (in_menu ? MODE_MENU : MODE_GAME));
|
|
|
|
g_extern.lifecycle_state |= (1ULL << (in_menu ? MODE_GAME : MODE_MENU));
|
|
|
|
}
|
|
|
|
|
2013-11-22 00:10:35 +00:00
|
|
|
// Little nudge to prevent stale values when reloading the confg file
|
|
|
|
void objc_clear_config_hack(void)
|
|
|
|
{
|
|
|
|
g_extern.block_config_read = false;
|
|
|
|
memset(g_settings.input.overlay, 0, sizeof(g_settings.input.overlay));
|
|
|
|
memset(g_settings.video.shader_path, 0, sizeof(g_settings.video.shader_path));
|
|
|
|
}
|
|
|
|
|
2013-11-21 23:57:39 +00:00
|
|
|
static void event_reload_config(void* userdata)
|
|
|
|
{
|
|
|
|
objc_clear_config_hack();
|
|
|
|
|
|
|
|
uninit_drivers();
|
|
|
|
config_load();
|
|
|
|
init_drivers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void apple_refresh_config()
|
|
|
|
{
|
|
|
|
if (apple_is_running)
|
|
|
|
apple_frontend_post_event(&event_reload_config, 0);
|
|
|
|
else
|
|
|
|
objc_clear_config_hack();
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_t stasis_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
static void event_stasis(void* userdata)
|
|
|
|
{
|
|
|
|
uninit_drivers();
|
|
|
|
pthread_mutex_lock(&stasis_mutex);
|
|
|
|
pthread_mutex_unlock(&stasis_mutex);
|
|
|
|
init_drivers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void apple_enter_stasis()
|
|
|
|
{
|
|
|
|
if (apple_is_running)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&stasis_mutex);
|
|
|
|
apple_frontend_post_event(event_stasis, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void apple_exit_stasis(bool reload_config)
|
|
|
|
{
|
|
|
|
if (reload_config)
|
|
|
|
{
|
|
|
|
objc_clear_config_hack();
|
|
|
|
config_load();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (apple_is_running)
|
|
|
|
pthread_mutex_unlock(&stasis_mutex);
|
|
|
|
}
|
|
|
|
|
2013-11-09 00:51:00 +00:00
|
|
|
static int process_events(void *data)
|
2013-07-27 15:40:21 +00:00
|
|
|
{
|
2013-11-03 15:38:56 +00:00
|
|
|
(void)data;
|
2013-07-27 15:40:21 +00:00
|
|
|
pthread_mutex_lock(&apple_event_queue_lock);
|
|
|
|
|
|
|
|
for (int i = 0; i < apple_event_queue_size; i ++)
|
|
|
|
apple_event_queue[i].function(apple_event_queue[i].userdata);
|
|
|
|
|
|
|
|
apple_event_queue_size = 0;
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&apple_event_queue_lock);
|
2013-11-09 00:51:00 +00:00
|
|
|
return 0;
|
2013-07-27 15:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void system_shutdown(bool force)
|
|
|
|
{
|
|
|
|
/* force set to true makes it display the 'Failed to load game' message. */
|
|
|
|
if (force)
|
|
|
|
dispatch_async_f(dispatch_get_main_queue(), (void*)1, apple_rarch_exited);
|
|
|
|
else
|
|
|
|
dispatch_async_f(dispatch_get_main_queue(), 0, apple_rarch_exited);
|
|
|
|
}
|
|
|
|
|
|
|
|
const frontend_ctx_driver_t frontend_ctx_apple = {
|
2013-08-14 04:48:58 +00:00
|
|
|
NULL, /* environment_get */
|
2013-07-27 15:40:21 +00:00
|
|
|
NULL, /* init */
|
|
|
|
NULL, /* deinit */
|
|
|
|
NULL, /* exitspawn */
|
|
|
|
NULL, /* process_args */
|
|
|
|
process_events, /* process_events */
|
|
|
|
NULL, /* exec */
|
|
|
|
system_shutdown, /* shutdown */
|
|
|
|
"apple",
|
|
|
|
};
|