forked from libretro/RetroArch
/
runloop.c
1157 lines (967 loc) · 32 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-2015 - 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 <file/file_path.h>
#include <retro_inline.h>
#include <retro_log.h>
#include <compat/strl.h>
#include "configuration.h"
#include "dynamic.h"
#include "performance.h"
#include "retroarch.h"
#include "runloop.h"
#include "runloop_data.h"
#include "msg_hash.h"
#include "input/keyboard_line.h"
#include "input/input_common.h"
#ifdef HAVE_MENU
#include "menu/menu.h"
#include "menu/menu_input.h"
#endif
#ifdef HAVE_NETPLAY
#include "netplay.h"
#endif
static struct global g_extern;
static bool main_is_idle;
static bool main_is_paused;
static bool main_is_slowmotion;
static unsigned main_max_frames;
static retro_time_t frame_limit_last_time;
static retro_time_t frame_limit_minimum_time;
/**
* 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 check_pause(driver_t *driver, settings_t *settings,
bool pause_pressed, bool frameadvance_pressed)
{
static bool old_focus = true;
bool focus = true;
enum event_command cmd = EVENT_CMD_NONE;
bool old_is_paused = main_is_paused;
const video_driver_t *video = driver ? (const video_driver_t*)driver->video :
NULL;
/* FRAMEADVANCE will set us into pause mode. */
pause_pressed |= !main_is_paused && frameadvance_pressed;
if (settings->pause_nonactive)
focus = video->focus(driver->video_data);
if (focus && pause_pressed)
cmd = EVENT_CMD_PAUSE_TOGGLE;
else if (focus && !old_focus)
cmd = EVENT_CMD_UNPAUSE;
else if (!focus && old_focus)
cmd = EVENT_CMD_PAUSE;
old_focus = focus;
if (cmd != EVENT_CMD_NONE)
event_command(cmd);
if (main_is_paused == old_is_paused)
return false;
return true;
}
/**
* 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 check_fast_forward_button(driver_t *driver,
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)
driver->nonblock_state = !driver->nonblock_state;
else if (old_hold_pressed != hold_pressed)
driver->nonblock_state = hold_pressed;
else
return;
driver_set_nonblock_state(driver->nonblock_state);
}
/**
* 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 check_stateslots(settings_t *settings,
bool pressed_increase, bool pressed_decrease)
{
char msg[PATH_MAX_LENGTH];
/* 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);
rarch_main_msg_queue_push(msg, 1, 180, true);
RARCH_LOG("%s\n", msg);
}
/**
* check_rewind:
* @pressed : was rewind key pressed or held?
*
* Checks if rewind toggle/hold was being pressed and/or held.
**/
static void check_rewind(settings_t *settings,
global_t *global, bool pressed)
{
static bool first = true;
if (global->rewind.frame_is_reverse)
{
audio_driver_frame_is_reverse();
global->rewind.frame_is_reverse = false;
}
if (first)
{
first = false;
return;
}
if (!global->rewind.state)
return;
if (pressed)
{
const void *buf = NULL;
if (state_manager_pop(global->rewind.state, &buf))
{
global->rewind.frame_is_reverse = true;
audio_driver_setup_rewind();
rarch_main_msg_queue_push_new(MSG_REWINDING, 0,
main_is_paused ? 1 : 30, true);
pretro_unserialize(buf, global->rewind.size);
if (global->bsv.movie)
bsv_movie_frame_rewind(global->bsv.movie);
}
else
rarch_main_msg_queue_push_new(MSG_REWIND_REACHED_END,
0, 30, true);
}
else
{
static unsigned cnt = 0;
cnt = (cnt + 1) % (settings->rewind_granularity ?
settings->rewind_granularity : 1); /* Avoid possible SIGFPE. */
if ((cnt == 0) || global->bsv.movie)
{
void *state = NULL;
state_manager_push_where(global->rewind.state, &state);
RARCH_PERFORMANCE_INIT(rewind_serialize);
RARCH_PERFORMANCE_START(rewind_serialize);
pretro_serialize(state, global->rewind.size);
RARCH_PERFORMANCE_STOP(rewind_serialize);
state_manager_push_do(global->rewind.state);
}
}
retro_set_rewind_callbacks();
}
/**
* check_slowmotion:
* @slowmotion_pressed : was slow motion key pressed or held?
*
* Checks if slowmotion toggle/hold was being pressed and/or held.
**/
static void check_slowmotion(settings_t *settings, global_t *global,
bool slowmotion_pressed)
{
main_is_slowmotion = slowmotion_pressed;
if (!main_is_slowmotion)
return;
if (settings->video.black_frame_insertion)
video_driver_cached_frame();
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);
}
static bool check_movie_init(global_t *global)
{
char path[PATH_MAX_LENGTH];
char msg[PATH_MAX_LENGTH];
bool ret = true;
settings_t *settings = config_get_ptr();
if (global->bsv.movie)
return false;
settings->rewind_granularity = 1;
if (settings->state_slot > 0)
snprintf(path, sizeof(path), "%s%d",
global->bsv.movie_path, settings->state_slot);
else
strlcpy(path, global->bsv.movie_path, sizeof(path));
strlcat(path, ".bsv", sizeof(path));
snprintf(msg, sizeof(msg), "%s \"%s\".",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
global->bsv.movie = bsv_movie_init(path, RARCH_MOVIE_RECORD);
if (!global->bsv.movie)
ret = false;
if (global->bsv.movie)
{
rarch_main_msg_queue_push(msg, 1, 180, true);
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO),
path);
}
else
{
rarch_main_msg_queue_push_new(
MSG_FAILED_TO_START_MOVIE_RECORD,
1, 180, true);
RARCH_ERR("%s\n", msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD));
}
return ret;
}
/**
* check_movie_record:
*
* Checks if movie is being recorded.
*
* Returns: true (1) if movie is being recorded, otherwise false (0).
**/
static bool check_movie_record(global_t *global)
{
if (!global->bsv.movie)
return false;
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));
event_command(EVENT_CMD_BSV_MOVIE_DEINIT);
return true;
}
/**
* check_movie_playback:
*
* Checks if movie is being played.
*
* Returns: true (1) if movie is being played, otherwise false (0).
**/
static bool check_movie_playback(global_t *global)
{
if (!global->bsv.movie_end)
return false;
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));
event_command(EVENT_CMD_BSV_MOVIE_DEINIT);
global->bsv.movie_end = false;
global->bsv.movie_playback = false;
return true;
}
static bool check_movie(global_t *global)
{
if (global->bsv.movie_playback)
return check_movie_playback(global);
if (!global->bsv.movie)
return check_movie_init(global);
return check_movie_record(global);
}
#define SHADER_EXT_GLSL 0x7c976537U
#define SHADER_EXT_GLSLP 0x0f840c87U
#define SHADER_EXT_CG 0x0059776fU
#define SHADER_EXT_CGP 0x0b8865bfU
/**
* 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 check_shader_dir(global_t *global,
bool pressed_next, bool pressed_prev)
{
uint32_t ext_hash;
char msg[PATH_MAX_LENGTH];
const char *shader = NULL;
const char *ext = NULL;
enum rarch_shader_type type = RARCH_SHADER_NONE;
if (!global || !global->shader_dir.list)
return;
if (pressed_next)
{
global->shader_dir.ptr = (global->shader_dir.ptr + 1) %
global->shader_dir.list->size;
}
else if (pressed_prev)
{
if (global->shader_dir.ptr == 0)
global->shader_dir.ptr = global->shader_dir.list->size - 1;
else
global->shader_dir.ptr--;
}
else
return;
shader = global->shader_dir.list->elems[global->shader_dir.ptr].data;
ext = path_get_extension(shader);
ext_hash = msg_hash_calculate(ext);
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;
}
snprintf(msg, sizeof(msg), "%s #%u: \"%s\".",
msg_hash_to_str(MSG_SHADER),
(unsigned)global->shader_dir.ptr, shader);
rarch_main_msg_queue_push(msg, 1, 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));
}
#ifdef HAVE_MENU
static void do_state_check_menu_toggle(settings_t *settings, global_t *global)
{
if (menu_driver_alive())
{
if (global->inited.main && (global->inited.core.type != CORE_TYPE_DUMMY))
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.
**/
static int do_pre_state_checks(settings_t *settings,
global_t *global, event_cmd_state_t *cmd)
{
if (cmd->overlay_next_pressed)
event_command(EVENT_CMD_OVERLAY_NEXT);
if (!main_is_paused || menu_driver_alive())
{
if (cmd->fullscreen_toggle)
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
}
if (cmd->grab_mouse_pressed)
event_command(EVENT_CMD_GRAB_MOUSE_TOGGLE);
#ifdef HAVE_MENU
if (cmd->menu_pressed || (global->inited.core.type == CORE_TYPE_DUMMY))
do_state_check_menu_toggle(settings, global);
#endif
return 0;
}
#ifdef HAVE_NETPLAY
static int do_netplay_state_checks(
bool netplay_flip_pressed,
bool fullscreen_toggle)
{
if (netplay_flip_pressed)
event_command(EVENT_CMD_NETPLAY_FLIP_PLAYERS);
if (fullscreen_toggle)
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
return 0;
}
#endif
static int do_pause_state_checks(
bool frameadvance_pressed,
bool fullscreen_toggle_pressed,
bool rewind_pressed)
{
bool check_is_oneshot = frameadvance_pressed || rewind_pressed;
if (!main_is_paused)
return 0;
if (fullscreen_toggle_pressed)
{
event_command(EVENT_CMD_FULLSCREEN_TOGGLE);
video_driver_cached_frame();
}
if (!check_is_oneshot)
return 1;
return 0;
}
/**
* do_state_checks:
*
* Checks for state changes in this frame.
*
* Returns: 1 if RetroArch is in pause mode, 0 otherwise.
**/
static int do_state_checks(driver_t *driver, settings_t *settings,
global_t *global, event_cmd_state_t *cmd)
{
if (main_is_idle)
return 1;
if (cmd->screenshot_pressed)
event_command(EVENT_CMD_TAKE_SCREENSHOT);
if (cmd->mute_pressed)
event_command(EVENT_CMD_AUDIO_MUTE_TOGGLE);
if (cmd->osk_pressed)
driver->keyboard_linefeed_enable = !driver->keyboard_linefeed_enable;
if (cmd->volume_up_pressed)
event_command(EVENT_CMD_VOLUME_UP);
else if (cmd->volume_down_pressed)
event_command(EVENT_CMD_VOLUME_DOWN);
#ifdef HAVE_NETPLAY
if (driver->netplay_data)
return do_netplay_state_checks(cmd->netplay_flip_pressed,
cmd->fullscreen_toggle);
#endif
check_pause(driver, settings,
cmd->pause_pressed, cmd->frameadvance_pressed);
if (do_pause_state_checks(
cmd->frameadvance_pressed,
cmd->fullscreen_toggle,
cmd->rewind_pressed))
return 1;
check_fast_forward_button(driver,
cmd->fastforward_pressed,
cmd->hold_pressed, cmd->old_hold_pressed);
check_stateslots(settings, cmd->state_slot_increase,
cmd->state_slot_decrease);
if (cmd->save_state_pressed)
event_command(EVENT_CMD_SAVE_STATE);
else if (cmd->load_state_pressed)
event_command(EVENT_CMD_LOAD_STATE);
check_rewind(settings, global, cmd->rewind_pressed);
check_slowmotion(settings, global, cmd->slowmotion_pressed);
if (cmd->movie_record)
check_movie(global);
check_shader_dir(global, cmd->shader_next_pressed,
cmd->shader_prev_pressed);
if (cmd->disk_eject_pressed)
event_command(EVENT_CMD_DISK_EJECT_TOGGLE);
else if (cmd->disk_next_pressed)
event_command(EVENT_CMD_DISK_NEXT);
else if (cmd->disk_prev_pressed)
event_command(EVENT_CMD_DISK_PREV);
if (cmd->reset_pressed)
event_command(EVENT_CMD_RESET);
if (global->cheat)
{
if (cmd->cheat_index_plus_pressed)
cheat_manager_index_next(global->cheat);
else if (cmd->cheat_index_minus_pressed)
cheat_manager_index_prev(global->cheat);
else if (cmd->cheat_toggle_pressed)
cheat_manager_toggle(global->cheat);
}
return 0;
}
/**
* 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.
**/
static INLINE int time_to_exit(driver_t *driver, global_t *global,
rarch_system_info_t *system,
event_cmd_state_t *cmd)
{
const video_driver_t *video = driver ? (const video_driver_t*)driver->video : NULL;
bool shutdown_pressed = (system && system->shutdown) || cmd->quit_key_pressed;
bool video_alive = video && video->alive(driver->video_data);
bool movie_end = (global->bsv.movie_end && global->bsv.eof_exit);
uint64_t *frame_count = video_driver_get_frame_count();
bool frame_count_end = main_max_frames && (*frame_count >= main_max_frames);
if (shutdown_pressed || frame_count_end || movie_end || !video_alive)
return 1;
return 0;
}
/**
* rarch_update_frame_time:
*
* Updates frame timing if frame timing callback is in use by the core.
* Limits frame time if fast forward ratio throttle is enabled.
**/
static void rarch_update_frame_time(driver_t *driver, float slowmotion_ratio,
rarch_system_info_t *system)
{
retro_time_t current = rarch_get_time_usec();
retro_time_t delta = current - system->frame_time_last;
bool is_locked_fps = (main_is_paused || driver->nonblock_state) |
!!driver->recording_data;
if (!system->frame_time_last || is_locked_fps)
delta = system->frame_time.reference;
if (!is_locked_fps && main_is_slowmotion)
delta /= slowmotion_ratio;
system->frame_time_last = current;
if (is_locked_fps)
system->frame_time_last = 0;
system->frame_time.callback(delta);
}
static int rarch_limit_frame_time(float fastforward_ratio, unsigned *sleep_ms)
{
retro_time_t current, target, to_sleep_ms;
if (!fastforward_ratio)
return 0;
current = rarch_get_time_usec();
target = frame_limit_last_time + frame_limit_minimum_time;
to_sleep_ms = (target - current) / 1000;
if (to_sleep_ms > 0)
{
*sleep_ms = (unsigned)to_sleep_ms;
/* Combat jitter a bit. */
frame_limit_last_time += frame_limit_minimum_time;
return 1;
}
else
frame_limit_last_time = rarch_get_time_usec();
return 0;
}
/**
* check_block_hotkey:
* @enable_hotkey : Is hotkey enable key enabled?
*
* Checks if 'hotkey enable' key is pressed.
**/
static bool check_block_hotkey(driver_t *driver, settings_t *settings,
bool enable_hotkey)
{
bool use_hotkey_enable;
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];
/* Don't block the check to RARCH_ENABLE_HOTKEY
* unless we're really supposed to. */
driver->block_hotkey =
input_driver_keyboard_mapping_is_blocked();
/* If we haven't bound anything to this,
* always allow hotkeys. */
use_hotkey_enable =
bind->key != RETROK_UNKNOWN ||
bind->joykey != NO_BTN ||
bind->joyaxis != AXIS_NONE ||
autoconf_bind->key != RETROK_UNKNOWN ||
autoconf_bind->joykey != NO_BTN ||
autoconf_bind->joyaxis != AXIS_NONE;
driver->block_hotkey =
input_driver_keyboard_mapping_is_blocked() ||
(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. */
return (use_hotkey_enable && enable_hotkey);
}
/**
* input_keys_pressed:
*
* Grab an input sample for this frame.
*
* 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.
*
* Returns: Input sample containg a mask of all pressed keys.
*/
static INLINE retro_input_t input_keys_pressed(driver_t *driver,
settings_t *settings, global_t *global)
{
unsigned i;
const struct retro_keybind *binds[MAX_USERS];
retro_input_t ret = 0;
for (i = 0; i < MAX_USERS; i++)
binds[i] = settings->input.binds[i];
if (!driver->input || !driver->input_data)
return 0;
global->turbo.count++;
driver->block_libretro_input = check_block_hotkey(driver,
settings, driver->input->key_pressed(
driver->input_data, RARCH_ENABLE_HOTKEY));
for (i = 0; i < settings->input.max_users; i++)
{
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]);
global->turbo.frame_enable[i] = 0;
}
if (!driver->block_libretro_input)
{
for (i = 0; i < settings->input.max_users; i++)
global->turbo.frame_enable[i] = input_driver_state(binds,
i, RETRO_DEVICE_JOYPAD, 0, RARCH_TURBO_ENABLE);
}
ret = input_driver_keys_pressed();
for (i = 0; i < settings->input.max_users; i++)
{
input_pop_analog_dpad(settings->input.binds[i]);
input_pop_analog_dpad(settings->input.autoconf_binds[i]);
}
return ret;
}
/**
* 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.
**/
#ifdef HAVE_OVERLAY
static void rarch_main_iterate_linefeed_overlay(driver_t *driver,
settings_t *settings)
{
static char prev_overlay_restore = false;
if (driver->osk_enable && !driver->keyboard_linefeed_enable)
{
driver->osk_enable = false;
prev_overlay_restore = true;
event_command(EVENT_CMD_OVERLAY_DEINIT);
return;
}
else if (!driver->osk_enable && driver->keyboard_linefeed_enable)
{
driver->osk_enable = true;
prev_overlay_restore = false;
event_command(EVENT_CMD_OVERLAY_INIT);
return;
}
else if (prev_overlay_restore)
{
if (!settings->input.overlay_hide_in_menu)
event_command(EVENT_CMD_OVERLAY_INIT);
prev_overlay_restore = false;
}
}
#endif
global_t *global_get_ptr(void)
{
return &g_extern;
}
void rarch_main_state_free(void)
{
main_is_idle = false;
main_is_paused = false;
main_is_slowmotion = false;
frame_limit_last_time = 0.0;
main_max_frames = 0;
}
void rarch_main_set_frame_limit_last_time(void)
{
settings_t *settings = config_get_ptr();
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
float fastforward_ratio = settings->fastforward_ratio;
if (fastforward_ratio == 0.0f)
fastforward_ratio = 1.0f;
frame_limit_last_time = rarch_get_time_usec();
frame_limit_minimum_time = (retro_time_t)roundf(1000000.0f / (av_info->timing.fps * fastforward_ratio));
}
void rarch_main_global_free(void)
{
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);
memset(&g_extern, 0, sizeof(g_extern));
}
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;
}
void rarch_main_clear_state(void)
{
driver_clear_state();
rarch_main_state_free();
rarch_main_global_free();
}
void rarch_main_set_slowmotion(unsigned enable)
{
main_is_slowmotion = enable;
}
void rarch_main_set_max_frames(unsigned val)
{
main_max_frames = val;
}
void rarch_main_set_pause(unsigned enable)
{
main_is_paused = enable;
}
void rarch_main_set_idle(unsigned enable)
{
main_is_idle = enable;
}
bool rarch_main_is_paused(void)
{
return main_is_paused;
}
bool rarch_main_is_idle(void)
{
return main_is_idle;
}
bool rarch_main_is_slowmotion(void)
{
return main_is_slowmotion;
}
static bool rarch_main_cmd_get_state_menu_toggle_button_combo(
driver_t *driver, 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, 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;
}
static void rarch_main_cmd_get_state(driver_t *driver,
settings_t *settings, event_cmd_state_t *cmd,
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
cmd->menu_pressed = BIT64_GET(trigger_input, RARCH_MENU_TOGGLE) ||
rarch_main_cmd_get_state_menu_toggle_button_combo(driver,
settings, input,
old_input, trigger_input);
#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);
cmd->osk_pressed = BIT64_GET(trigger_input, RARCH_OSK);
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);
cmd->rewind_pressed = BIT64_GET(input, RARCH_REWIND);
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);
}
/**
* rarch_main_iterate:
*
* Run Libretro core in RetroArch for one frame.