forked from libretro/RetroArch
/
runloop.c
1601 lines (1379 loc) · 47.6 KB
/
runloop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - Daniel De Matteis
* Copyright (C) 2012-2015 - Michael Lelli
* Copyright (C) 2014-2015 - Jay McCarthy
*
* 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 <stdarg.h>
#include <math.h>
#include <lists/dir_list.h>
#include <file/file_path.h>
#include <retro_inline.h>
#include <retro_assert.h>
#include <queues/message_queue.h>
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#endif
#include <queues/task_queue.h>
#include <string/stdstring.h>
#include <features/features_cpu.h>
#include <compat/strl.h>
#ifdef HAVE_CHEEVOS
#include "cheevos.h"
#endif
#include "autosave.h"
#include "core_info.h"
#include "configuration.h"
#include "movie.h"
#include "retroarch.h"
#include "runloop.h"
#include "file_path_special.h"
#include "managers/core_option_manager.h"
#include "managers/cheat_manager.h"
#include "managers/state_manager.h"
#include "system.h"
#include "list_special.h"
#include "audio/audio_driver.h"
#include "camera/camera_driver.h"
#include "record/record_driver.h"
#include "input/input_driver.h"
#include "ui/ui_companion_driver.h"
#include "core.h"
#include "msg_hash.h"
#include "input/input_keyboard.h"
#include "tasks/tasks_internal.h"
#ifdef HAVE_MENU
#include "menu/menu_driver.h"
#endif
#ifdef HAVE_NETPLAY
#include "network/netplay/netplay.h"
#endif
#if defined(HAVE_HTTPSERVER) && defined(HAVE_ZLIB)
#include "httpserver/httpserver.h"
#endif
#include "verbosity.h"
#ifdef HAVE_ZLIB
#define DEFAULT_EXT "zip"
#else
#define DEFAULT_EXT ""
#endif
#define runloop_cmd_triggered(cmd, id) BIT64_GET(cmd->state[2].state, id)
#define runloop_cmd_press(cmd, id) BIT64_GET(cmd->state[0].state, id)
#define runloop_cmd_pressed(cmd, id) BIT64_GET(cmd->state[1].state, id)
#ifdef HAVE_MENU
#define runloop_cmd_menu_press(cmd) (BIT64_GET(cmd->state[2].state, RARCH_MENU_TOGGLE) || \
runloop_cmd_get_state_menu_toggle_button_combo( \
settings, cmd->state[0], \
cmd->state[1], cmd->state[2]))
#endif
struct rarch_dir_list
{
struct string_list *list;
size_t ptr;
};
typedef struct event_cmd_state
{
retro_input_t state[3];
} event_cmd_state_t;
static rarch_dir_list_t runloop_shader_dir;
static char runloop_fullpath[PATH_MAX_LENGTH];
static char runloop_default_shader_preset[PATH_MAX_LENGTH];
static rarch_system_info_t runloop_system;
static unsigned runloop_pending_windowed_scale;
static struct retro_frame_time_callback runloop_frame_time;
static retro_keyboard_event_t runloop_key_event = NULL;
static retro_keyboard_event_t runloop_frontend_key_event = NULL;
static retro_usec_t runloop_frame_time_last = 0;
static unsigned runloop_max_frames = false;
static bool runloop_force_nonblock = false;
static bool runloop_frame_time_last_enable = false;
static bool runloop_set_frame_limit = false;
static bool runloop_paused = false;
static bool runloop_idle = false;
static bool runloop_exec = false;
static bool runloop_slowmotion = false;
static bool runloop_shutdown_initiated = false;
static bool runloop_core_shutdown_initiated = false;
static bool runloop_perfcnt_enable = false;
static bool runloop_overrides_active = false;
static bool runloop_game_options_active = false;
static core_option_manager_t *runloop_core_options = NULL;
#ifdef HAVE_THREADS
static slock_t *_runloop_msg_queue_lock = NULL;
#endif
static msg_queue_t *runloop_msg_queue = NULL;
global_t *global_get_ptr(void)
{
static struct global g_extern;
return &g_extern;
}
static void runloop_msg_queue_lock(void)
{
#ifdef HAVE_THREADS
slock_lock(_runloop_msg_queue_lock);
#endif
}
static void runloop_msg_queue_unlock(void)
{
#ifdef HAVE_THREADS
slock_unlock(_runloop_msg_queue_lock);
#endif
}
static bool runloop_msg_queue_push_internal(runloop_ctx_msg_info_t *msg_info)
{
if (!msg_info || !runloop_msg_queue)
return false;
msg_queue_push(runloop_msg_queue, msg_info->msg,
msg_info->prio, msg_info->duration);
if (ui_companion_is_on_foreground())
{
const ui_companion_driver_t *ui = ui_companion_get_ptr();
if (ui->msg_queue_push)
ui->msg_queue_push(msg_info->msg,
msg_info->prio, msg_info->duration, msg_info->flush);
}
return true;
}
void runloop_msg_queue_push(const char *msg,
unsigned prio, unsigned duration,
bool flush)
{
runloop_ctx_msg_info_t msg_info;
settings_t *settings = config_get_ptr();
if(!settings->video.font_enable)
return;
runloop_msg_queue_lock();
if (flush)
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_CLEAR, NULL);
msg_info.msg = msg;
msg_info.prio = prio;
msg_info.duration = duration;
msg_info.flush = flush;
runloop_msg_queue_push_internal(&msg_info);
runloop_msg_queue_unlock();
}
char* runloop_msg_queue_pull(void)
{
runloop_ctx_msg_info_t msg_info;
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_PULL, &msg_info);
return strdup(msg_info.msg);
}
/* Checks if movie is being played back. */
static bool runloop_check_movie_playback(void)
{
if (!bsv_movie_ctl(BSV_MOVIE_CTL_END, NULL))
return false;
runloop_msg_queue_push(
msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED), 2, 180, false);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_PLAYBACK_ENDED));
command_event(CMD_EVENT_BSV_MOVIE_DEINIT, NULL);
bsv_movie_ctl(BSV_MOVIE_CTL_UNSET_END, NULL);
bsv_movie_ctl(BSV_MOVIE_CTL_UNSET_PLAYBACK, NULL);
return true;
}
/* Checks if movie is being recorded. */
static bool runloop_check_movie_record(void)
{
if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return false;
runloop_msg_queue_push(
msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED), 2, 180, true);
RARCH_LOG("%s\n", msg_hash_to_str(MSG_MOVIE_RECORD_STOPPED));
command_event(CMD_EVENT_BSV_MOVIE_DEINIT, NULL);
return true;
}
static bool runloop_check_movie_init(void)
{
char msg[128] = {0};
char path[PATH_MAX_LENGTH] = {0};
settings_t *settings = config_get_ptr();
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return false;
settings->rewind_granularity = 1;
if (settings->state_slot > 0)
snprintf(path, sizeof(path), "%s%d",
bsv_movie_get_path(), settings->state_slot);
else
strlcpy(path, bsv_movie_get_path(), sizeof(path));
strlcat(path,
file_path_str(FILE_PATH_BSV_EXTENSION),
sizeof(path));
snprintf(msg, sizeof(msg), "%s \"%s\".",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
bsv_movie_init_handle(path, RARCH_MOVIE_RECORD);
if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return false;
if (bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
{
runloop_msg_queue_push(msg, 2, 180, true);
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
}
else
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD),
2, 180, true);
RARCH_ERR("%s\n",
msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD));
}
return true;
}
static bool runloop_check_movie(void)
{
if (bsv_movie_ctl(BSV_MOVIE_CTL_PLAYBACK_ON, NULL))
return runloop_check_movie_playback();
if (!bsv_movie_ctl(BSV_MOVIE_CTL_IS_INITED, NULL))
return runloop_check_movie_init();
return runloop_check_movie_record();
}
/* Checks if slowmotion toggle/hold was being pressed and/or held. */
static bool runloop_check_slowmotion(bool *ptr)
{
settings_t *settings = config_get_ptr();
if (!ptr)
return false;
runloop_slowmotion = *ptr;
if (!runloop_slowmotion)
return false;
if (settings->video.black_frame_insertion)
video_driver_cached_frame_render();
if (state_manager_frame_is_reversed())
runloop_msg_queue_push(msg_hash_to_str(MSG_SLOW_MOTION_REWIND), 2, 30, true);
else
runloop_msg_queue_push(msg_hash_to_str(MSG_SLOW_MOTION), 2, 30, true);
return true;
}
#ifdef HAVE_MENU
static bool runloop_cmd_get_state_menu_toggle_button_combo(
settings_t *settings,
retro_input_t input, retro_input_t old_input,
retro_input_t trigger_input)
{
switch (settings->input.menu_toggle_gamepad_combo)
{
case 0:
return false;
case 1:
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_DOWN))
return false;
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_Y))
return false;
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_L))
return false;
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_R))
return false;
break;
case 2:
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_L3))
return false;
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_R3))
return false;
break;
case 3:
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_START))
return false;
if (!BIT64_GET(input.state, RETRO_DEVICE_ID_JOYPAD_SELECT))
return false;
break;
}
input_driver_set_flushing_input();
return true;
}
#endif
/**
* runloop_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.
**/
static bool runloop_check_pause(settings_t *settings,
bool focus, bool pause_pressed,
bool frameadvance_pressed)
{
static bool old_focus = true;
enum event_command cmd = CMD_EVENT_NONE;
bool old_is_paused = runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL);
/* FRAMEADVANCE will set us into pause mode. */
pause_pressed |= !old_is_paused && frameadvance_pressed;
if (focus && pause_pressed)
cmd = CMD_EVENT_PAUSE_TOGGLE;
else if (focus && !old_focus)
cmd = CMD_EVENT_UNPAUSE;
else if (!focus && old_focus)
cmd = CMD_EVENT_PAUSE;
old_focus = focus;
if (cmd != CMD_EVENT_NONE)
command_event(cmd, NULL);
if (runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL) == old_is_paused)
return false;
return true;
}
/**
* runloop_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.
*
**/
static void runloop_check_fast_forward_button(bool fastforward_pressed,
bool hold_pressed, bool old_hold_pressed)
{
/* 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.
*/
if (fastforward_pressed)
{
if (input_driver_is_nonblock_state())
input_driver_unset_nonblock_state();
else
input_driver_set_nonblock_state();
}
else if (old_hold_pressed != hold_pressed)
{
if (hold_pressed)
input_driver_set_nonblock_state();
else
input_driver_unset_nonblock_state();
}
else
return;
driver_ctl(RARCH_DRIVER_CTL_SET_NONBLOCK_STATE, NULL);
}
/**
* runloop_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.
**/
static void runloop_check_stateslots(settings_t *settings,
bool pressed_increase, bool pressed_decrease)
{
char msg[128] = {0};
/* Save state slots */
if (pressed_increase)
settings->state_slot++;
else if (pressed_decrease)
{
if (settings->state_slot > 0)
settings->state_slot--;
}
else
return;
snprintf(msg, sizeof(msg), "%s: %d",
msg_hash_to_str(MSG_STATE_SLOT),
settings->state_slot);
runloop_msg_queue_push(msg, 2, 180, true);
RARCH_LOG("%s\n", msg);
}
static void shader_dir_free(rarch_dir_list_t *dir_list)
{
if (!dir_list)
return;
dir_list_free(dir_list->list);
dir_list->list = NULL;
dir_list->ptr = 0;
}
static bool shader_dir_init(rarch_dir_list_t *dir_list)
{
unsigned i;
settings_t *settings = config_get_ptr();
if (!*settings->directory.video_shader)
return false;
dir_list->list = dir_list_new_special(settings->directory.video_shader, DIR_LIST_SHADERS, NULL);
if (!dir_list->list || dir_list->list->size == 0)
{
command_event(CMD_EVENT_SHADER_DIR_DEINIT, NULL);
return false;
}
dir_list->ptr = 0;
dir_list_sort(dir_list->list, false);
for (i = 0; i < dir_list->list->size; i++)
RARCH_LOG("%s \"%s\"\n",
msg_hash_to_str(MSG_FOUND_SHADER),
dir_list->list->elems[i].data);
return true;
}
/**
* runloop_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.
**/
static void runloop_check_shader_dir(rarch_dir_list_t *dir_list,
bool pressed_next, bool pressed_prev)
{
char msg[128] = {0};
const char *shader = NULL;
enum rarch_shader_type type = RARCH_SHADER_NONE;
RARCH_LOG("SWITCH \n");
if (!dir_list || !dir_list->list)
return;
if (pressed_next)
{
dir_list->ptr = (dir_list->ptr + 1) %
dir_list->list->size;
}
else if (pressed_prev)
{
if (dir_list->ptr == 0)
dir_list->ptr = dir_list->list->size - 1;
else
dir_list->ptr--;
}
else
return;
shader = dir_list->list->elems[dir_list->ptr].data;
RARCH_LOG("SWITCH %s,\n", shader);
switch (msg_hash_to_file_type(msg_hash_calculate(path_get_extension(shader))))
{
case FILE_TYPE_SHADER_GLSL:
case FILE_TYPE_SHADER_PRESET_GLSLP:
type = RARCH_SHADER_GLSL;
break;
case FILE_TYPE_SHADER_SLANG:
case FILE_TYPE_SHADER_PRESET_SLANGP:
type = RARCH_SHADER_SLANG;
break;
case FILE_TYPE_SHADER_CG:
case FILE_TYPE_SHADER_PRESET_CGP:
type = RARCH_SHADER_CG;
break;
default:
return;
}
snprintf(msg, sizeof(msg), "%s #%u: \"%s\".",
msg_hash_to_str(MSG_SHADER),
(unsigned)dir_list->ptr, shader);
runloop_msg_queue_push(msg, 2, 120, true);
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_APPLYING_SHADER),
shader);
if (!video_driver_set_shader(type, shader))
RARCH_WARN("%s\n", msg_hash_to_str(MSG_FAILED_TO_APPLY_SHADER));
}
/**
* rarch_game_specific_options:
*
* Returns: true (1) if a game specific core
* options path has been found,
* otherwise false (0).
**/
static bool rarch_game_specific_options(char **output)
{
char game_path[PATH_MAX_LENGTH] = {0};
config_file_t *option_file = NULL;
if (!retroarch_validate_game_options(game_path,
sizeof(game_path), false))
return false;
option_file = config_file_new(game_path);
if (!option_file)
return false;
config_file_free(option_file);
RARCH_LOG("%s %s\n",
msg_hash_to_str(MSG_GAME_SPECIFIC_CORE_OPTIONS_FOUND_AT),
game_path);
*output = strdup(game_path);
return true;
}
static bool runloop_is_focused(void)
{
settings_t *settings = config_get_ptr();
if (settings->pause_nonactive)
return video_driver_is_focused();
return true;
}
static bool runloop_check_pause_state(event_cmd_state_t *cmd)
{
bool check_is_oneshot = false;
if (!cmd)
return false;
check_is_oneshot = runloop_cmd_triggered(cmd,
RARCH_FRAMEADVANCE)
|| runloop_cmd_press(cmd, RARCH_REWIND);
if (!runloop_ctl(RUNLOOP_CTL_IS_PAUSED, NULL))
return true;
if (runloop_cmd_triggered(cmd, RARCH_FULLSCREEN_TOGGLE_KEY))
{
command_event(CMD_EVENT_FULLSCREEN_TOGGLE, NULL);
video_driver_cached_frame_render();
}
if (!check_is_oneshot)
return false;
return true;
}
static bool runloop_check_idle_state(event_cmd_state_t *cmd)
{
settings_t *settings = config_get_ptr();
bool focused = runloop_is_focused();
runloop_check_pause(settings, focused,
runloop_cmd_triggered(cmd, RARCH_PAUSE_TOGGLE),
runloop_cmd_triggered(cmd, RARCH_FRAMEADVANCE));
if (!runloop_check_pause_state(cmd) || !focused)
return false;
return true;
}
static bool runloop_check_state(event_cmd_state_t *cmd,
rarch_dir_list_t *shader_dir)
{
bool tmp = false;
settings_t *settings = config_get_ptr();
if (!cmd || runloop_ctl(RUNLOOP_CTL_IS_IDLE, NULL))
return false;
if (runloop_cmd_triggered(cmd, RARCH_SCREENSHOT))
command_event(CMD_EVENT_TAKE_SCREENSHOT, NULL);
if (runloop_cmd_triggered(cmd, RARCH_MUTE))
command_event(CMD_EVENT_AUDIO_MUTE_TOGGLE, NULL);
if (runloop_cmd_triggered(cmd, RARCH_OSK))
{
if (input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED, NULL))
input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_UNSET_LINEFEED_ENABLED, NULL);
else
input_keyboard_ctl(
RARCH_INPUT_KEYBOARD_CTL_SET_LINEFEED_ENABLED, NULL);
}
if (runloop_cmd_press(cmd, RARCH_VOLUME_UP))
command_event(CMD_EVENT_VOLUME_UP, NULL);
else if (runloop_cmd_press(cmd, RARCH_VOLUME_DOWN))
command_event(CMD_EVENT_VOLUME_DOWN, NULL);
#ifdef HAVE_NETPLAY
tmp = runloop_cmd_triggered(cmd, RARCH_NETPLAY_FLIP);
netplay_driver_ctl(RARCH_NETPLAY_CTL_FLIP_PLAYERS, &tmp);
tmp = runloop_cmd_triggered(cmd, RARCH_FULLSCREEN_TOGGLE_KEY);
netplay_driver_ctl(RARCH_NETPLAY_CTL_FULLSCREEN_TOGGLE, &tmp);
#endif
if (!runloop_check_idle_state(cmd))
return false;
runloop_check_fast_forward_button(
runloop_cmd_triggered(cmd, RARCH_FAST_FORWARD_KEY),
runloop_cmd_press (cmd, RARCH_FAST_FORWARD_HOLD_KEY),
runloop_cmd_pressed (cmd, RARCH_FAST_FORWARD_HOLD_KEY));
runloop_check_stateslots(settings,
runloop_cmd_triggered(cmd, RARCH_STATE_SLOT_PLUS),
runloop_cmd_triggered(cmd, RARCH_STATE_SLOT_MINUS)
);
if (runloop_cmd_triggered(cmd, RARCH_SAVE_STATE_KEY))
command_event(CMD_EVENT_SAVE_STATE, NULL);
else if (runloop_cmd_triggered(cmd, RARCH_LOAD_STATE_KEY))
command_event(CMD_EVENT_LOAD_STATE, NULL);
#ifdef HAVE_CHEEVOS
if(!settings->cheevos.hardcore_mode_enable)
#endif
state_manager_check_rewind(runloop_cmd_press(cmd, RARCH_REWIND));
tmp = runloop_cmd_press(cmd, RARCH_SLOWMOTION);
runloop_check_slowmotion(&tmp);
if (runloop_cmd_triggered(cmd, RARCH_MOVIE_RECORD_TOGGLE))
runloop_check_movie();
if (runloop_cmd_triggered(cmd, RARCH_SHADER_NEXT) ||
runloop_cmd_triggered(cmd, RARCH_SHADER_PREV))
{
runloop_check_shader_dir(shader_dir,
runloop_cmd_triggered(cmd, RARCH_SHADER_NEXT),
runloop_cmd_triggered(cmd, RARCH_SHADER_PREV));
}
if (runloop_cmd_triggered(cmd, RARCH_DISK_EJECT_TOGGLE))
command_event(CMD_EVENT_DISK_EJECT_TOGGLE, NULL);
else if (runloop_cmd_triggered(cmd, RARCH_DISK_NEXT))
command_event(CMD_EVENT_DISK_NEXT, NULL);
else if (runloop_cmd_triggered(cmd, RARCH_DISK_PREV))
command_event(CMD_EVENT_DISK_PREV, NULL);
if (runloop_cmd_triggered(cmd, RARCH_RESET))
command_event(CMD_EVENT_RESET, NULL);
cheat_manager_state_checks(
runloop_cmd_triggered(cmd, RARCH_CHEAT_INDEX_PLUS),
runloop_cmd_triggered(cmd, RARCH_CHEAT_INDEX_MINUS),
runloop_cmd_triggered(cmd, RARCH_CHEAT_TOGGLE));
return true;
}
static bool runloop_is_frame_count_end(void)
{
uint64_t *frame_count =
video_driver_get_frame_count_ptr();
return runloop_max_frames && (*frame_count >= runloop_max_frames);
}
bool runloop_ctl(enum runloop_ctl_state state, void *data)
{
switch (state)
{
case RUNLOOP_CTL_SHADER_DIR_DEINIT:
shader_dir_free(&runloop_shader_dir);
break;
case RUNLOOP_CTL_SHADER_DIR_INIT:
return shader_dir_init(&runloop_shader_dir);
case RUNLOOP_CTL_SYSTEM_INFO_INIT:
core_get_system_info(&runloop_system.info);
if (!runloop_system.info.library_name)
runloop_system.info.library_name = msg_hash_to_str(MSG_UNKNOWN);
if (!runloop_system.info.library_version)
runloop_system.info.library_version = "v0";
video_driver_set_title_buf();
strlcpy(runloop_system.valid_extensions,
runloop_system.info.valid_extensions ?
runloop_system.info.valid_extensions : DEFAULT_EXT,
sizeof(runloop_system.valid_extensions));
break;
case RUNLOOP_CTL_GET_CORE_OPTION_SIZE:
{
unsigned *idx = (unsigned*)data;
if (!idx)
return false;
*idx = core_option_manager_size(runloop_core_options);
}
break;
case RUNLOOP_CTL_HAS_CORE_OPTIONS:
return runloop_core_options;
case RUNLOOP_CTL_CORE_OPTIONS_LIST_GET:
{
core_option_manager_t **coreopts = (core_option_manager_t**)data;
if (!coreopts)
return false;
*coreopts = runloop_core_options;
}
break;
case RUNLOOP_CTL_SYSTEM_INFO_GET:
{
rarch_system_info_t **system = (rarch_system_info_t**)data;
if (!system)
return false;
*system = &runloop_system;
}
break;
case RUNLOOP_CTL_SYSTEM_INFO_FREE:
/* No longer valid. */
if (runloop_system.subsystem.data)
free(runloop_system.subsystem.data);
runloop_system.subsystem.data = NULL;
runloop_system.subsystem.size = 0;
if (runloop_system.ports.data)
free(runloop_system.ports.data);
runloop_system.ports.data = NULL;
runloop_system.ports.size = 0;
if (runloop_system.mmaps.descriptors)
free((void *)runloop_system.mmaps.descriptors);
runloop_system.mmaps.descriptors = NULL;
runloop_system.mmaps.num_descriptors = 0;
runloop_key_event = NULL;
runloop_frontend_key_event = NULL;
audio_driver_unset_callback();
memset(&runloop_system, 0, sizeof(rarch_system_info_t));
break;
case RUNLOOP_CTL_SET_FRAME_TIME_LAST:
runloop_frame_time_last_enable = true;
break;
case RUNLOOP_CTL_UNSET_FRAME_TIME_LAST:
if (!runloop_ctl(RUNLOOP_CTL_IS_FRAME_TIME_LAST, NULL))
return false;
runloop_frame_time_last = 0;
runloop_frame_time_last_enable = false;
break;
case RUNLOOP_CTL_SET_OVERRIDES_ACTIVE:
runloop_overrides_active = true;
break;
case RUNLOOP_CTL_UNSET_OVERRIDES_ACTIVE:
runloop_overrides_active = false;
break;
case RUNLOOP_CTL_IS_OVERRIDES_ACTIVE:
return runloop_overrides_active;
case RUNLOOP_CTL_SET_GAME_OPTIONS_ACTIVE:
runloop_game_options_active = true;
break;
case RUNLOOP_CTL_UNSET_GAME_OPTIONS_ACTIVE:
runloop_game_options_active = false;
break;
case RUNLOOP_CTL_IS_GAME_OPTIONS_ACTIVE:
return runloop_game_options_active;
case RUNLOOP_CTL_IS_FRAME_TIME_LAST:
return runloop_frame_time_last_enable;
case RUNLOOP_CTL_SET_FRAME_LIMIT:
runloop_set_frame_limit = true;
break;
case RUNLOOP_CTL_UNSET_FRAME_LIMIT:
runloop_set_frame_limit = false;
break;
case RUNLOOP_CTL_SHOULD_SET_FRAME_LIMIT:
return runloop_set_frame_limit;
case RUNLOOP_CTL_GET_PERFCNT:
{
bool **perfcnt = (bool**)data;
if (!perfcnt)
return false;
*perfcnt = &runloop_perfcnt_enable;
}
break;
case RUNLOOP_CTL_SET_PERFCNT_ENABLE:
runloop_perfcnt_enable = true;
break;
case RUNLOOP_CTL_UNSET_PERFCNT_ENABLE:
runloop_perfcnt_enable = false;
break;
case RUNLOOP_CTL_IS_PERFCNT_ENABLE:
return runloop_perfcnt_enable;
case RUNLOOP_CTL_SET_NONBLOCK_FORCED:
runloop_force_nonblock = true;
break;
case RUNLOOP_CTL_UNSET_NONBLOCK_FORCED:
runloop_force_nonblock = false;
break;
case RUNLOOP_CTL_IS_NONBLOCK_FORCED:
return runloop_force_nonblock;
case RUNLOOP_CTL_SET_FRAME_TIME:
{
const struct retro_frame_time_callback *info =
(const struct retro_frame_time_callback*)data;
#ifdef HAVE_NETPLAY
global_t *global = global_get_ptr();
/* retro_run() will be called in very strange and
* mysterious ways, have to disable it. */
if (global->netplay.enable)
return false;
#endif
runloop_frame_time = *info;
}
break;
case RUNLOOP_CTL_GET_WINDOWED_SCALE:
{
unsigned **scale = (unsigned**)data;
if (!scale)
return false;
*scale = (unsigned*)&runloop_pending_windowed_scale;
}
break;
case RUNLOOP_CTL_SET_WINDOWED_SCALE:
{
unsigned *idx = (unsigned*)data;
if (!idx)
return false;
runloop_pending_windowed_scale = *idx;
}
break;
case RUNLOOP_CTL_SET_LIBRETRO_PATH:
{
const char *fullpath = (const char*)data;
if (!fullpath)
return false;
config_set_active_core_path(fullpath);
}
break;
case RUNLOOP_CTL_CLEAR_CONTENT_PATH:
*runloop_fullpath = '\0';
break;
case RUNLOOP_CTL_GET_CONTENT_PATH:
{
char **fullpath = (char**)data;
if (!fullpath)
return false;
*fullpath = (char*)runloop_fullpath;
}
break;
case RUNLOOP_CTL_SET_CONTENT_PATH:
{
const char *fullpath = (const char*)data;
if (!fullpath)
return false;
strlcpy(runloop_fullpath, fullpath, sizeof(runloop_fullpath));
}
break;
case RUNLOOP_CTL_CLEAR_DEFAULT_SHADER_PRESET:
*runloop_default_shader_preset = '\0';
break;
case RUNLOOP_CTL_GET_DEFAULT_SHADER_PRESET:
{
char **preset = (char**)data;
if (!preset)
return false;
*preset = (char*)runloop_default_shader_preset;
}
break;
case RUNLOOP_CTL_SET_DEFAULT_SHADER_PRESET:
{
const char *preset = (const char*)data;
if (!preset)
return false;
strlcpy(runloop_default_shader_preset, preset,
sizeof(runloop_default_shader_preset));
}
break;
case RUNLOOP_CTL_FRAME_TIME_FREE:
memset(&runloop_frame_time, 0, sizeof(struct retro_frame_time_callback));
runloop_frame_time_last = 0;
runloop_max_frames = 0;
break;
case RUNLOOP_CTL_STATE_FREE:
runloop_perfcnt_enable = false;
runloop_idle = false;
runloop_paused = false;
runloop_slowmotion = false;
runloop_frame_time_last_enable = false;
runloop_set_frame_limit = false;
runloop_overrides_active = false;
runloop_ctl(RUNLOOP_CTL_FRAME_TIME_FREE, NULL);
break;
case RUNLOOP_CTL_GLOBAL_FREE:
{
global_t *global = NULL;
command_event(CMD_EVENT_TEMPORARY_CONTENT_DEINIT, NULL);
command_event(CMD_EVENT_SUBSYSTEM_FULLPATHS_DEINIT, NULL);
command_event(CMD_EVENT_RECORD_DEINIT, NULL);
command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL);
rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL);
runloop_ctl(RUNLOOP_CTL_CLEAR_CONTENT_PATH, NULL);
runloop_overrides_active = false;
core_unset_input_descriptors();
global = global_get_ptr();
memset(global, 0, sizeof(struct global));
config_free_state();
}
break;
case RUNLOOP_CTL_CLEAR_STATE:
driver_ctl(RARCH_DRIVER_CTL_DEINIT, NULL);
runloop_ctl(RUNLOOP_CTL_STATE_FREE, NULL);
runloop_ctl(RUNLOOP_CTL_GLOBAL_FREE, NULL);
break;
case RUNLOOP_CTL_SET_MAX_FRAMES:
{
unsigned *ptr = (unsigned*)data;