-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathraylib-libretro.h
More file actions
4923 lines (4475 loc) · 199 KB
/
Copy pathraylib-libretro.h
File metadata and controls
4923 lines (4475 loc) · 199 KB
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
/**********************************************************************************************
*
* raylib-libretro - raylib extension to interact with libretro cores.
*
* DEPENDENCIES:
* - raylib
* - dl: dylib_proc(), dylib_error()
* - libretro-common
* - dynamic/dylib.h
* - features/features_cpu.h
* - libretro.h
*
* LICENSE: zlib/libpng
*
* raylib-libretro is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software:
*
* Copyright (c) 2026 Rob Loach (@RobLoach)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose, including commercial
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not claim that you
* wrote the original software. If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
* as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
**********************************************************************************************/
#ifndef RAYLIB_LIBRETRO_RLIBRETRO_H
#define RAYLIB_LIBRETRO_RLIBRETRO_H
#include <string.h>
#include "raylib.h"
#include "libretro.h"
#if defined(__cplusplus)
extern "C" {
#endif
//------------------------------------------------------------------------------------
// Libretro Raylib Integration (Module: raylib-libretro)
//------------------------------------------------------------------------------------
static bool InitLibretro(const char* core);
static bool PeekLibretroCoreInfo(const char* core);
static bool LoadLibretroGame(const char* gameFile);
static bool IsLibretroReady(void);
static bool IsLibretroGameReady(void);
static void UpdateLibretro(void);
static void UpdateLibretroEx(bool onlyTick);
static bool LibretroShouldClose(void);
static void DrawLibretro(void);
static void DrawLibretroTint(Color tint);
static void DrawLibretroEx(Vector2 position, float rotation, float scale, Color tint);
static void DrawLibretroV(Vector2 position, Color tint);
static void DrawLibretroTexture(int posX, int posY, Color tint);
static void DrawLibretroPro(Rectangle destRec, Color tint);
static double GetLibretroFPS(void);
static float GetLibretroAspectRatio(void);
static const char* GetLibretroName(void);
static const char* GetLibretroContentName(void);
static const char* GetLibretroVersion(void);
static unsigned GetLibretroWidth(void);
static unsigned GetLibretroHeight(void);
static int GetLibretroRotation(void);
static Texture2D GetLibretroTexture(void);
static bool ResetLibretroVideo(void);
static Image LoadImageFromLibretro();
static bool IsLibretroGameRequired(void);
static bool ResetLibretro(void);
static bool SetLibretroCheat(unsigned index, bool enabled, const char* code);
static bool ResetLibretroCheats(void);
static void UnloadLibretroGame(void);
static void CloseLibretro(void);
static void SetLibretroVolume(float volume);
static float GetLibretroVolume(void);
static void SetLibretroSpeed(float speed);
static float GetLibretroSpeed(void);
static bool SetLibretroCoreOption(const char* key, const char* value);
static const char* GetLibretroCoreOption(const char* key);
static bool ResetLibretroCoreOption(const char* key);
static void ResetAllLibretroCoreOptions(void);
static void* GetLibretroSerializedData(unsigned int* size);
static unsigned int GetLibretroSerializedSize(void);
static bool SetLibretroSerializedData(void* data, unsigned int size);
static void* GetLibretroSRAMData(size_t* size);
static bool SetLibretroSRAMData(const void* data, size_t size);
static void SetLibretroMessage(const char* msg, double duration);
static void SetLibretroMessageEx(const struct retro_message_ext *message);
static bool DrawLibretroMessage(void);
static const char* GetLibretroDirectory(int directory);
static const struct retro_input_descriptor* GetLibretroInputDescriptors(unsigned *count);
static const struct retro_controller_info* GetLibretroControllerInfo(unsigned *count);
static const struct retro_subsystem_info* GetLibretroSubsystemInfo(unsigned *count);
static bool SetLibretroMemoryMaps(const struct retro_memory_map *map);
static void UnloadLibretroMemoryMaps(void);
static const struct retro_memory_descriptor* GetLibretroMemoryMaps(unsigned *count);
static const char* GetLibretroValidExtensions(void);
static bool IsLibretroBlockExtract(void);
static bool GetLibretroNeedFullpath(const char* path, bool* persistent);
static void GetLibretroFileExtensionPattern(const char* exts, char* pattern, size_t patternSize);
static bool LoadLibretroGameFromMemoryEx(unsigned char* fileData, int dataSize,
const char* contentPath, bool persistent);
static void SetLibretroDynamicRateControl(bool enabled);
static bool IsLibretroDynamicRateControlEnabled(void);
static bool SetLibretroPortDevice(unsigned port, unsigned device);
static unsigned GetLibretroPortDevice(unsigned port);
static bool IsLibretroDiskControlActive(void);
static unsigned GetLibretroDiskImageCount(void);
static unsigned GetLibretroDiskImageIndex(void);
static bool GetLibretroDiskEjectState(void);
static bool SetLibretroDiskEjectState(bool ejected);
static bool SetLibretroDiskImageIndex(unsigned index);
static bool GetLibretroDiskImageLabel(unsigned index, char* label, size_t len);
static bool SwapLibretroDisk(unsigned index);
static void LibretroPixelFormatARGB1555ToRGB565(void *output_, const void *input_,
int width, int height,
int out_stride, int in_stride);
static void LibretroMapPixelFormatARGB8888ToRGBA8888(void *output_, const void *input_,
int width, int height,
int out_stride, int in_stride);
static int LibretroRetroPixelFormatToPixelFormat(int pixelFormat);
static int LibretroRetroJoypadButtonToGamepadButton(int button);
static int LibretroRetroJoypadButtontoRetroKey(int button);
static bool LibretroAnalogToDpadPressed(int port, int btn);
static int LibretroRetroKeyToKeyboardKey(int key);
static int LibretroMapRetroLogLevelToTraceLogType(int level);
#if defined(__cplusplus)
}
#endif
#include "raylib-libretro-vfs.h"
#ifdef RAYLIB_LIBRETRO_IMPLEMENTATION
#ifndef RAYLIB_LIBRETRO_IMPLEMENTATION_ONCE
#define RAYLIB_LIBRETRO_IMPLEMENTATION_ONCE
// System dependencies
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "rlgl.h"
// libretro-common
#include <dynamic/dylib.h>
#include <features/features_cpu.h>
#define RAYLIB_LIBRETRO_VFS_IMPLEMENTATION
#include "raylib-libretro-vfs.h"
// Audio ring buffer size in stereo frames
#define LIBRETRO_AUDIO_RING_BUFFER_SIZE 8192
// Single-sample accumulation buffer size (stereo frames)
#define LIBRETRO_AUDIO_SINGLE_SAMPLE_BUFFER_SIZE 512
// Per-extension content info overrides (RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE).
#define LIBRETRO_MAX_CONTENT_INFO_OVERRIDES 16
#define LIBRETRO_CONTENT_INFO_OVERRIDE_EXTS_LEN 256
// Core options/variables storage limits
#define LIBRETRO_MAX_CORE_VARIABLES 512
#define LIBRETRO_CORE_VARIABLE_KEY_LEN 512
#define LIBRETRO_CORE_VARIABLE_VALUE_LEN 512
#define LIBRETRO_CORE_VARIABLE_LABEL_LEN 512
#define LIBRETRO_CORE_VARIABLE_VALUES_LEN 512
#define LIBRETRO_CORE_VARIABLE_TOOLTIP_LEN 256
#define LIBRETRO_MAX_CORE_CATEGORIES 64
#define LIBRETRO_MAX_PERF_COUNTERS 1024
#define LIBRETRO_CORE_CATEGORY_KEY_LEN 64
/**
* The amount of controller ports with rumble support.
*/
#define RAYLIB_LIBRETRO_RUMBLE_PORTS 4
// Four joypads multiplexed through one port; index (0-3) selects the sub-controller.
#ifndef RETRO_DEVICE_JOYPAD_MULTITAP
#define RETRO_DEVICE_JOYPAD_MULTITAP RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1)
#endif
/**
* Load a symbol from the libretro handle.
*/
#define LoadLibretroMethodHandle(V, S) do {\
function_t func = dylib_proc(LIBRETRO.core.symbols.handle, #S); \
memcpy(&V, &func, sizeof(func)); \
if (!func) { \
TraceLog(LOG_ERROR, "LIBRETRO: Failed to load symbol '" #S "' ", dylib_error()); \
return false; \
}\
} while (0)
/**
* Loads a method from the libretro core handle.
*/
#define LoadLibretroMethod(S) LoadLibretroMethodHandle(LIBRETRO.core.symbols.S, S)
/**
* Dynamic library handle plus the function pointers resolved from it.
*/
typedef struct LibretroCoreSymbols {
void *handle; /** The dynamic linked library handle. */
void (*retro_init)(void);
void (*retro_deinit)(void);
unsigned (*retro_api_version)(void);
void (*retro_set_environment)(retro_environment_t);
void (*retro_set_video_refresh)(retro_video_refresh_t);
void (*retro_set_audio_sample)(retro_audio_sample_t);
void (*retro_set_audio_sample_batch)(retro_audio_sample_batch_t);
void (*retro_set_input_poll)(retro_input_poll_t);
void (*retro_set_input_state)(retro_input_state_t);
void (*retro_get_system_info)(struct retro_system_info *);
void (*retro_get_system_av_info)(struct retro_system_av_info *);
void (*retro_set_controller_port_device)(unsigned port, unsigned device);
void (*retro_reset)(void);
void (*retro_run)(void);
size_t (*retro_serialize_size)(void);
bool (*retro_serialize)(void *, size_t);
bool (*retro_unserialize)(const void *, size_t);
void (*retro_cheat_reset)(void);
void (*retro_cheat_set)(unsigned index, bool enabled, const char *code);
bool (*retro_load_game)(const struct retro_game_info *);
bool (*retro_load_game_special)(unsigned, const struct retro_game_info*, size_t);
void (*retro_unload_game)(void);
unsigned (*retro_get_region)(void);
void* (*retro_get_memory_data)(unsigned);
size_t (*retro_get_memory_size)(unsigned);
} LibretroCoreSymbols;
/**
* Dynamic library symbols for a libretro core.
*/
typedef struct LibretroCoreData {
LibretroCoreSymbols symbols;
// System Information.
bool shutdown; /** Indicates whether or not the core requested to shutdown. */
unsigned width, height;
double fps; /** Core's target frame rate from retro_system_timing (e.g. 59.94), kept fractional for accurate pacing. */
double sampleRate;
float aspectRatio;
char corePath[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char libraryName[200];
char libraryVersion[200];
char validExtensions[200];
bool needFullpath;
bool blockExtract;
bool supportNoGame;
unsigned apiVersion;
enum retro_pixel_format pixelFormat;
unsigned performanceLevel;
bool loaded;
uint64_t serializationQuirks; /** Bitmask from RETRO_ENVIRONMENT_SET_SERIALIZATION_QUIRKS. */
struct retro_perf_counter** perf_counters;
unsigned perf_counter_count;
struct retro_frame_time_callback runloop_frame_time;
retro_usec_t runloop_frame_time_last;
struct retro_audio_callback audio_callback;
// Game data.
Vector2 inputLastMousePosition;
Vector2 inputMousePosition;
// Raylib objects used to play the libretro core.
Texture texture;
bool textureRebuild;
// Pre-allocated frame conversion buffer (avoids per-frame MemAlloc).
void *frameBuffer;
size_t frameBufferSize;
// Audio
AudioStream audioStream;
float *audioRingBuffer;
size_t audioRingBufferSize;
size_t audioRingWritePos;
size_t audioRingAvailable;
unsigned minimumAudioLatencyMs; // RETRO_ENVIRONMENT_SET_MINIMUM_AUDIO_LATENCY
struct retro_audio_buffer_status_callback audio_buffer_status_callback; // RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK
float drcAdjustment; // DRC pitch multiplier, clamped to [0.995, 1.005]
bool drcEnabled; // Whether Dynamic Rate Control is active
// Callbacks
retro_keyboard_event_t keyboard_event;
retro_core_options_update_display_callback_t options_update_display_callback;
struct retro_vfs_interface vfs_interface;
// Input descriptors (RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS)
struct retro_input_descriptor *inputDescriptors;
unsigned inputDescriptorCount;
// Controller info (RETRO_ENVIRONMENT_SET_CONTROLLER_INFO)
struct retro_controller_info *controllerInfo;
unsigned controllerPortCount;
// Subsystem info (RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO)
struct retro_subsystem_info *subsystemInfo;
unsigned subsystemCount;
// Core variables/options
// TODO: Switch these to MemAlloc'ed strings.
char variableKeys[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_KEY_LEN];
char variableValues[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_VALUE_LEN];
char variableDefaults[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_VALUE_LEN];
char variableLabels[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_LABEL_LEN];
char variableValuesList[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_VALUES_LEN];
char variableDisplayList[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_VALUES_LEN];
char variableTooltips[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_TOOLTIP_LEN];
char variableCategoryKeys[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_CATEGORY_KEY_LEN];
bool variableVisible[LIBRETRO_MAX_CORE_VARIABLES];
unsigned variableCount;
char categoryKeys[LIBRETRO_MAX_CORE_CATEGORIES][LIBRETRO_CORE_CATEGORY_KEY_LEN];
char categoryLabels[LIBRETRO_MAX_CORE_CATEGORIES][LIBRETRO_CORE_VARIABLE_LABEL_LEN];
unsigned categoryCount;
unsigned variableOptionsVersion; // 0=legacy SET_VARIABLES, 1=SET_CORE_OPTIONS, 2=SET_CORE_OPTIONS_V2
bool variablesDirty; // Whether or not the variables have been changed since last RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE call.
bool variablesVisibilityDirty; // Whether option visibility changed and the menu should rebuild.
// Screen rotation: 0=0°, 1=90°, 2=180°, 3=270°
int rotation;
// Single-sample audio accumulation buffer (avoids static locals).
int16_t singleSampleBuffer[LIBRETRO_AUDIO_SINGLE_SAMPLE_BUFFER_SIZE * 2];
size_t singleSampleCount;
int audioDropWarnCount;
// Accumulated in-game time in nanoseconds (does not advance while menu is open).
retro_perf_tick_t gameTimeNSEC;
// Loaded content path (empty if no content loaded).
char contentPath[RAYLIB_LIBRETRO_VFS_MAX_PATH];
// Temp file written for needFullpath cores when loading from memory (empty if none).
char tempGamePath[RAYLIB_LIBRETRO_VFS_MAX_PATH];
// Backing storage and struct for RETRO_ENVIRONMENT_GET_GAME_INFO_EXT.
// Pointers in gameInfoExt reference these buffers (or are NULL).
char contentDir[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char contentName[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char contentExt[16];
struct retro_game_info_ext gameInfoExt;
bool gameInfoExtValid;
float rumbleStrong[RAYLIB_LIBRETRO_RUMBLE_PORTS];
float rumbleWeak[RAYLIB_LIBRETRO_RUMBLE_PORTS];
// Per-extension content info overrides from
// RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE.
char contentInfoOverrideExts[LIBRETRO_MAX_CONTENT_INFO_OVERRIDES][LIBRETRO_CONTENT_INFO_OVERRIDE_EXTS_LEN];
bool contentInfoOverrideNeedFullpath[LIBRETRO_MAX_CONTENT_INFO_OVERRIDES];
bool contentInfoOverridePersistent[LIBRETRO_MAX_CONTENT_INFO_OVERRIDES];
unsigned contentInfoOverrideCount;
// Persistent ROM buffer kept alive when an override sets persistent_data=true.
unsigned char* persistentGameData;
int persistentGameDataSize;
// Virtual joypad state injected by touch controls (port 0 only).
bool virtualJoypadState[16];
// Per-port device type; default RETRO_DEVICE_JOYPAD. Set via SetLibretroPortDevice().
unsigned portDeviceMap[16];
// Memory map from RETRO_ENVIRONMENT_SET_MEMORY_MAPS (owned copy).
struct retro_memory_descriptor *memoryMapDescriptors;
unsigned memoryMapDescriptorCount;
// Disk control interface (RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE / _EXT).
// Multi-disc cores (PlayStation, SegaCD, etc.) register this so the frontend can
// eject and swap disk images at runtime. The ext callback is a superset of the
// basic one, so it serves as the canonical store: the legacy interface fills the
// shared fields and leaves the ext-only function pointers NULL.
struct retro_disk_control_ext_callback disk_control;
bool diskControlActive; // A core has registered a disk control interface.
unsigned diskControlVersion; // 0 = basic interface, 1 = extended interface.
struct {
bool enabled; // SET_HW_RENDER accepted
bool active; // context_reset fired; FBO + core GL resources live
bool fboUsedThisFrame; // get_current_framebuffer was called; core rendered to our FBO
struct retro_hw_render_callback cb; // verbatim copy from the core
RenderTexture2D target; // FBO + color attachment
unsigned fboWidth, fboHeight; // allocated FBO size (max geometry)
unsigned frameWidth, frameHeight; // last valid sub-region from RETRO_HW_FRAME_BUFFER_VALID
} hwRender;
} LibretroCoreData;
typedef struct LibretroData {
// Persistent settings that survive core loads.
float volume;
float speed;
double speedAccumulator;
int textureFilter; // TextureFilter
bool integerScaling;
int analogToDpadIndex; // 0=None, 1=Left Analog, 2=Right Analog
int keyboardPlayer1[RETRO_DEVICE_ID_JOYPAD_R3 + 1];
char coreDirectory[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char saveDirectory[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char coreAssetsDirectory[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char systemDirectory[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char playlistsDirectory[RAYLIB_LIBRETRO_VFS_MAX_PATH];
char fileBrowserStartDirectory[RAYLIB_LIBRETRO_VFS_MAX_PATH];
/**
* The username for the libretro cores.
*
* @see RETRO_ENVIRONMENT_GET_USERNAME
*/
char username[128];
// OSD message (RETRO_ENVIRONMENT_SET_MESSAGE / SET_MESSAGE_EXT).
// Lives here rather than in `core` so a core-exit error message survives the
// core/content unload, as the libretro spec requires. osd holds the active
// message's metadata (type/priority/progress/level/target); osd.msg always
// points at our owned osdMessage buffer rather than the core's transient
// string. osdEndTime is the absolute GetTime() expiry.
char osdMessage[256];
double osdEndTime;
struct retro_message_ext osd;
// Per-core state (reset with memset(0) on core unload).
LibretroCoreData core;
} LibretroData;
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The global libretro core object.
*
* TODO: Figure out a way to have LIBRETRO not be a static global?
*/
static LibretroData LIBRETRO = {
.volume = 1.0f,
.speed = 1.0f,
.username = "raylib",
.keyboardPlayer1 = {
[RETRO_DEVICE_ID_JOYPAD_B] = KEY_Z,
[RETRO_DEVICE_ID_JOYPAD_Y] = KEY_A,
[RETRO_DEVICE_ID_JOYPAD_SELECT] = KEY_RIGHT_SHIFT,
[RETRO_DEVICE_ID_JOYPAD_START] = KEY_ENTER,
[RETRO_DEVICE_ID_JOYPAD_UP] = KEY_UP,
[RETRO_DEVICE_ID_JOYPAD_DOWN] = KEY_DOWN,
[RETRO_DEVICE_ID_JOYPAD_LEFT] = KEY_LEFT,
[RETRO_DEVICE_ID_JOYPAD_RIGHT] = KEY_RIGHT,
[RETRO_DEVICE_ID_JOYPAD_A] = KEY_X,
[RETRO_DEVICE_ID_JOYPAD_X] = KEY_S,
[RETRO_DEVICE_ID_JOYPAD_L] = KEY_Q,
[RETRO_DEVICE_ID_JOYPAD_R] = KEY_W,
[RETRO_DEVICE_ID_JOYPAD_L2] = KEY_E,
[RETRO_DEVICE_ID_JOYPAD_R2] = KEY_R,
[RETRO_DEVICE_ID_JOYPAD_L3] = KEY_D,
[RETRO_DEVICE_ID_JOYPAD_R3] = KEY_F,
}
};
static void LibretroInitCoreVariable(const char *key, const char *defaultValue,
const char *label, const char *valuesList, const char *displayList,
const char *tooltip, const char *categoryKey) {
for (unsigned i = 0; i < LIBRETRO.core.variableCount; i++) {
if (TextIsEqual(LIBRETRO.core.variableKeys[i], key)) {
return; // Already registered; don't overwrite user-set value.
}
}
if (LIBRETRO.core.variableCount >= LIBRETRO_MAX_CORE_VARIABLES) {
TraceLog(LOG_WARNING, "LIBRETRO: Core variable limit reached, ignoring: %s", key);
return;
}
unsigned n = LIBRETRO.core.variableCount;
TextCopy(LIBRETRO.core.variableKeys[n], key);
TextCopy(LIBRETRO.core.variableValues[n], defaultValue ? defaultValue : "");
TextCopy(LIBRETRO.core.variableDefaults[n], defaultValue ? defaultValue : "");
TextCopy(LIBRETRO.core.variableLabels[n], label ? label : "");
TextCopy(LIBRETRO.core.variableValuesList[n], valuesList ? valuesList : "");
TextCopy(LIBRETRO.core.variableDisplayList[n], displayList ? displayList : "");
TextCopy(LIBRETRO.core.variableTooltips[n], tooltip ? tooltip : "");
TextCopy(LIBRETRO.core.variableCategoryKeys[n], categoryKey ? categoryKey : "");
LIBRETRO.core.variableVisible[n] = true;
LIBRETRO.core.variableCount++;
// A new option appeared: cores that register variables after the menu has
// been built (e.g. mgba registering GB model options during its deferred
// setup on first retro_run) need the Core Options section to refresh.
LIBRETRO.core.variablesVisibilityDirty = true;
}
static const char *LibretroGetCoreVariable(const char *key) {
for (unsigned i = 0; i < LIBRETRO.core.variableCount; i++) {
if (TextIsEqual(LIBRETRO.core.variableKeys[i], key)) {
return LIBRETRO.core.variableValues[i];
}
}
return NULL;
}
/**
* Set a core option by key.
* @param key Option key as reported by the core via RETRO_ENVIRONMENT_SET_VARIABLES.
* @param value New value for the option.
* @return true if the key was found and the value applied; false if the key is unknown. */
static bool SetLibretroCoreOption(const char *key, const char *value) {
for (unsigned i = 0; i < LIBRETRO.core.variableCount; i++) {
if (TextIsEqual(LIBRETRO.core.variableKeys[i], key)) {
snprintf(LIBRETRO.core.variableValues[i], LIBRETRO_CORE_VARIABLE_VALUE_LEN, "%s", value);
LIBRETRO.core.variablesDirty = true;
return true;
}
}
return false;
}
/**
* Get a core option value by key.
* @param key Option key to look up.
* @return Current value string, or NULL if the key is not found. */
static const char *GetLibretroCoreOption(const char *key) {
return LibretroGetCoreVariable(key);
}
/**
* Reset a single core option to its default value.
* @param key Option key to reset.
* @return true if the key was found and reset; false if unknown. */
static bool ResetLibretroCoreOption(const char *key) {
for (unsigned i = 0; i < LIBRETRO.core.variableCount; i++) {
if (TextIsEqual(LIBRETRO.core.variableKeys[i], key)) {
snprintf(LIBRETRO.core.variableValues[i], LIBRETRO_CORE_VARIABLE_VALUE_LEN,
"%s", LIBRETRO.core.variableDefaults[i]);
LIBRETRO.core.variablesDirty = true;
return true;
}
}
return false;
}
/**
* Reset all core options to their default values. */
static void ResetAllLibretroCoreOptions(void) {
for (unsigned i = 0; i < LIBRETRO.core.variableCount; i++) {
snprintf(LIBRETRO.core.variableValues[i], LIBRETRO_CORE_VARIABLE_VALUE_LEN,
"%s", LIBRETRO.core.variableDefaults[i]);
}
LIBRETRO.core.variablesDirty = true;
}
/**
* Retrieves the directory that is configured as a libretro directory.
*
* @param directory The key of which directory to retrieve. Can be...
* - RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY
* - RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY
* - RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY
* - RETRO_ENVIRONMENT_GET_PLAYLIST_DIRECTORY
* - RETRO_ENVIRONMENT_GET_FILE_BROWSER_START_DIRECTORY
* - RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY
*
* @return The directory that's currently configured for the libretro directory. The application directory by default, or NULL if it's an incorrect directory.
*/
static const char* GetLibretroDirectory(int directory) {
// Rotating buffer pool so multiple calls in one expression don't clobber each other.
#define RAYLIB_LIBRETRO_DIR_BUFFERS 4
static char buffers[RAYLIB_LIBRETRO_DIR_BUFFERS][RAYLIB_LIBRETRO_VFS_MAX_PATH];
static int bufferIndex = 0;
char* output = NULL;
switch (directory) {
case RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY: output = LIBRETRO.saveDirectory; break;
case RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY: output = LIBRETRO.coreAssetsDirectory; break; // RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY
case RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY: output = LIBRETRO.systemDirectory; break;
case RETRO_ENVIRONMENT_GET_PLAYLIST_DIRECTORY: output = LIBRETRO.playlistsDirectory; break;
case RETRO_ENVIRONMENT_GET_FILE_BROWSER_START_DIRECTORY: output = LIBRETRO.fileBrowserStartDirectory; break;
default: return NULL;
}
const char* result = (output == NULL || output[0] == '\0') ? GetApplicationDirectory() : output;
char* cleaned = buffers[bufferIndex];
bufferIndex = (bufferIndex + 1) % RAYLIB_LIBRETRO_DIR_BUFFERS;
// Strip trailing slash to prevent double slashes when building file paths.
TextCopy(cleaned, result);
int len = (int)TextLength(cleaned);
while (len > 1 && (cleaned[len - 1] == '/' || cleaned[len - 1] == '\\')) {
cleaned[--len] = '\0';
}
return cleaned;
}
/**
* Get the input descriptors reported by the loaded core.
* @param count Output parameter filled with the number of descriptors.
* @return Pointer to the descriptor array, or NULL if none were set. */
static const struct retro_input_descriptor* GetLibretroInputDescriptors(unsigned *count) {
if (count != NULL) *count = LIBRETRO.core.inputDescriptorCount;
return LIBRETRO.core.inputDescriptors;
}
/**
* Get the controller port info reported by the loaded core.
* @param count Output parameter filled with the number of ports.
* @return Pointer to the controller info array, or NULL if none were set. */
static const struct retro_controller_info* GetLibretroControllerInfo(unsigned *count) {
if (count != NULL) *count = LIBRETRO.core.controllerPortCount;
return LIBRETRO.core.controllerInfo;
}
static const struct retro_subsystem_info* GetLibretroSubsystemInfo(unsigned *count) {
if (count != NULL) *count = LIBRETRO.core.subsystemCount;
return LIBRETRO.core.subsystemInfo;
}
/**
* Free the stored memory map descriptors. */
static void UnloadLibretroMemoryMaps(void) {
if (LIBRETRO.core.memoryMapDescriptors) {
for (unsigned i = 0; i < LIBRETRO.core.memoryMapDescriptorCount; i++) {
if (LIBRETRO.core.memoryMapDescriptors[i].addrspace) {
MemFree((void*)LIBRETRO.core.memoryMapDescriptors[i].addrspace);
}
}
MemFree(LIBRETRO.core.memoryMapDescriptors);
LIBRETRO.core.memoryMapDescriptors = NULL;
LIBRETRO.core.memoryMapDescriptorCount = 0;
}
}
/**
* Store an owned deep-copy of the core's memory map descriptors.
* @param map Pointer to the retro_memory_map provided by the core.
* @return true on success. */
static bool SetLibretroMemoryMaps(const struct retro_memory_map *map) {
UnloadLibretroMemoryMaps();
if (!map || !map->descriptors || map->num_descriptors == 0) {
return map != NULL;
}
size_t sz = sizeof(struct retro_memory_descriptor) * map->num_descriptors;
LIBRETRO.core.memoryMapDescriptors = (struct retro_memory_descriptor*)MemAlloc((unsigned int)sz);
if (!LIBRETRO.core.memoryMapDescriptors) {
return false;
}
memcpy(LIBRETRO.core.memoryMapDescriptors, map->descriptors, sz);
LIBRETRO.core.memoryMapDescriptorCount = map->num_descriptors;
for (unsigned i = 0; i < map->num_descriptors; i++) {
if (map->descriptors[i].addrspace) {
size_t len = strlen(map->descriptors[i].addrspace) + 1;
char *copy = (char*)MemAlloc((unsigned int)len);
if (copy) memcpy(copy, map->descriptors[i].addrspace, len);
LIBRETRO.core.memoryMapDescriptors[i].addrspace = copy;
}
}
TraceLog(LOG_INFO, "LIBRETRO: Memory map stored (%u descriptor(s))", map->num_descriptors);
return true;
}
/**
* Get the stored memory map descriptors.
* @param count Output parameter filled with the number of descriptors.
* @return Pointer to the descriptor array, or NULL if none are stored. */
static const struct retro_memory_descriptor* GetLibretroMemoryMaps(unsigned *count) {
if (count != NULL) *count = LIBRETRO.core.memoryMapDescriptorCount;
return LIBRETRO.core.memoryMapDescriptors;
}
// Returns an absolute path for `path`. The result is either the input pointer
// (already absolute) or a pointer into a non-reentrant static buffer; copy it
// before calling again if you need to keep both values.
static const char* LibretroResolveAbsoluteDirectory(const char* path) {
if (!path || path[0] == '\0') return path;
if (path[0] == '/' || path[0] == '\\') return path;
#if defined(_WIN32)
if (path[1] == ':') return path;
#endif
static char absPath[RAYLIB_LIBRETRO_VFS_MAX_PATH];
#if defined(_WIN32)
const char sep = '\\';
#else
const char sep = '/';
#endif
int n = snprintf(absPath, sizeof(absPath), "%s%c%s", GetWorkingDirectory(), sep, path);
if (n < 0 || (size_t)n >= sizeof(absPath)) return path;
return absPath;
}
static void LibretroLogger(enum retro_log_level level, const char *fmt, ...) {
int type = LibretroMapRetroLogLevelToTraceLogType(level);
va_list va;
va_start(va, fmt);
char message[1024];
vsnprintf(message, sizeof(message), fmt, va);
va_end(va);
// Strip trailing newlines/carriage returns.
int len = (int)strlen(message);
while (len > 0 && (message[len - 1] == '\n' || message[len - 1] == '\r')) {
message[--len] = '\0';
}
if (len > 0) {
TraceLog(type, "LIBRETRO: %s", message);
}
}
static void InitLibretroAudio(void); // Forward declaration.
static bool InitLibretroVideo(void); // Forward declaration.
static size_t UpdateLibretroAudioSampleBatch(const int16_t *data, size_t frames); // Forward declaration.
static uintptr_t LibretroHwGetCurrentFramebuffer(void) {
LIBRETRO.core.hwRender.fboUsedThisFrame = true;
return (uintptr_t)LIBRETRO.core.hwRender.target.id;
}
static retro_proc_address_t LibretroHwGetProcAddress(const char *sym) {
return (retro_proc_address_t)rlGetProcAddress(sym);
}
static void CloseLibretroVideo(void) {
if (LIBRETRO.core.hwRender.enabled) {
if (IsRenderTextureValid(LIBRETRO.core.hwRender.target)) {
UnloadRenderTexture(LIBRETRO.core.hwRender.target);
memset(&LIBRETRO.core.hwRender.target, 0, sizeof(LIBRETRO.core.hwRender.target));
}
memset(&LIBRETRO.core.texture, 0, sizeof(LIBRETRO.core.texture));
} else {
if (IsTextureValid(LIBRETRO.core.texture)) {
UnloadTexture(LIBRETRO.core.texture);
memset(&LIBRETRO.core.texture, 0, sizeof(LIBRETRO.core.texture));
}
if (LIBRETRO.core.frameBuffer != NULL) {
MemFree(LIBRETRO.core.frameBuffer);
}
LIBRETRO.core.frameBuffer = NULL;
LIBRETRO.core.frameBufferSize = 0;
}
LIBRETRO.core.textureRebuild = false;
}
static bool hw_InitLibretroVideo(void) {
struct retro_system_av_info av;
LIBRETRO.core.symbols.retro_get_system_av_info(&av);
unsigned fboW = av.geometry.max_width > 0 ? av.geometry.max_width : LIBRETRO.core.width;
unsigned fboH = av.geometry.max_height > 0 ? av.geometry.max_height : LIBRETRO.core.height;
LIBRETRO.core.hwRender.fboWidth = fboW;
LIBRETRO.core.hwRender.fboHeight = fboH;
LIBRETRO.core.hwRender.frameWidth = LIBRETRO.core.width;
LIBRETRO.core.hwRender.frameHeight = LIBRETRO.core.height;
// Build the FBO with raylib's render texture (color + depth). raylib/rlgl owns the
// GL objects, so teardown is a plain UnloadRenderTexture and the depth attachment is
// chosen to fit whichever GRAPHICS_API_* config raylib was compiled against. A stencil
// buffer is not provided; cores that request one fall back to depth-only, which keeps
// the FBO complete across every supported GL/GLES configuration.
LIBRETRO.core.hwRender.target = LoadRenderTexture((int)fboW, (int)fboH);
if (!IsRenderTextureValid(LIBRETRO.core.hwRender.target)) {
TraceLog(LOG_ERROR, "LIBRETRO HW: Failed to load render texture");
return false;
}
if (LIBRETRO.core.hwRender.cb.stencil) {
TraceLog(LOG_WARNING, "LIBRETRO HW: core requested a stencil buffer; providing depth only");
}
LIBRETRO.core.texture = LIBRETRO.core.hwRender.target.texture;
SetTextureFilter(LIBRETRO.core.texture, LIBRETRO.textureFilter);
LIBRETRO.core.textureRebuild = false;
TraceLog(LOG_INFO, "LIBRETRO HW: FBO %ux%u created (id=%u)", fboW, fboH, LIBRETRO.core.hwRender.target.id);
return true;
}
// Fire the core's context_reset with our FBO bound, then restore the previously-bound
// target. Cores commonly query get_current_framebuffer and build GL objects against the
// FBO here, so it must be current. No-op (and leaves active=false) when the core supplied
// no context_reset, matching the contract that such a core never enters the HW path.
static void hw_FireContextReset(void) {
if (!LIBRETRO.core.hwRender.enabled || LIBRETRO.core.hwRender.cb.context_reset == NULL) {
return;
}
rlDrawRenderBatchActive();
unsigned savedFbo = rlGetActiveFramebuffer();
rlEnableFramebuffer(LIBRETRO.core.hwRender.target.id);
LIBRETRO.core.hwRender.cb.context_reset();
if (savedFbo != 0)
rlEnableFramebuffer(savedFbo);
else
rlDisableFramebuffer();
LIBRETRO.core.hwRender.active = true;
TraceLog(LOG_INFO, "LIBRETRO HW: context_reset fired");
}
// Fire the core's context_destroy with our FBO bound so it can release the GL resources
// it created in context_reset. No-op when the HW context is not currently live.
static void hw_FireContextDestroy(void) {
if (!LIBRETRO.core.hwRender.active) {
return;
}
if (LIBRETRO.core.hwRender.cb.context_destroy != NULL) {
rlDrawRenderBatchActive();
rlEnableFramebuffer(LIBRETRO.core.hwRender.target.id);
LIBRETRO.core.hwRender.cb.context_destroy();
rlDisableFramebuffer();
}
LIBRETRO.core.hwRender.active = false;
}
// Recreate the HW render FBO while the GL context itself is unchanged (e.g. the core's
// max geometry grew, or the platform recreated the context). The core's GL resources are
// torn down (context_destroy) and re-established (context_reset) around the rebuild so it
// rebinds to the new framebuffer instead of the destroyed one. Returns false on failure,
// leaving the HW context inactive.
static bool hw_RebuildLibretroVideo(void) {
if (!LIBRETRO.core.hwRender.enabled) {
return false;
}
bool wasActive = LIBRETRO.core.hwRender.active;
hw_FireContextDestroy(); // no-op when not active
CloseLibretroVideo(); // unload the old FBO + color attachment
if (!hw_InitLibretroVideo()) {
TraceLog(LOG_ERROR, "LIBRETRO HW: FBO rebuild failed");
return false;
}
if (wasActive) {
hw_FireContextReset(); // re-create the core's GL resources on the new FBO
}
return true;
}
/**
* Rebuild the video pipeline after the platform recreated the GL context.
*
* For HW-rendered cores this tears down and re-establishes the core's GL resources
* (context_destroy -> new FBO -> context_reset); for software cores it rebuilds the
* upload texture. Call this ONLY when the GL context was genuinely recreated.
*
* Note: raylib preserves the GL context across a normal Android pause/resume (the EGL
* context is detached and re-attached, not destroyed), so this is not needed there and
* calling it would force the core to needlessly reinitialize. There is currently no
* portable raylib signal for a true context re-creation, so this is exposed for platform
* glue that can detect one (e.g. a confirmed GL context loss).
*
* @return true on success.
*/
static bool ResetLibretroVideo(void) {
if (LIBRETRO.core.hwRender.enabled) {
return hw_RebuildLibretroVideo();
}
return InitLibretroVideo();
}
static bool InitLibretroVideo(void) {
CloseLibretroVideo();
if (LIBRETRO.core.width == 0 || LIBRETRO.core.height == 0) {
return false;
}
if (LIBRETRO.core.hwRender.enabled) {
return hw_InitLibretroVideo();
}
// Software path: build an upload texture + conversion buffer.
Image image = GenImageColor(LIBRETRO.core.width, LIBRETRO.core.height, BLACK);
if (!IsImageValid(image)) {
return false;
}
ImageFormat(&image, LibretroRetroPixelFormatToPixelFormat(LIBRETRO.core.pixelFormat));
LIBRETRO.core.texture = LoadTextureFromImage(image);
UnloadImage(image);
if (!IsTextureValid(LIBRETRO.core.texture)) {
return false;
}
SetTextureFilter(LIBRETRO.core.texture, LIBRETRO.textureFilter);
// (Re-)allocate the frame conversion buffer sized for XRGB8888→RGBA8888 (worst case).
size_t needed = (size_t)GetPixelDataSize(LIBRETRO.core.width, LIBRETRO.core.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
if (needed == 0) {
CloseLibretroVideo();
return false;
}
LIBRETRO.core.frameBuffer = MemAlloc(needed);
LIBRETRO.core.frameBufferSize = needed;
LIBRETRO.core.textureRebuild = false;
return true;
}
/**
* Retrieve the current in-game time in microseconds.
*
* @return retro_time_t The current in-game time in microseconds.
*/
static retro_time_t GetLibretroTimeUSEC(void) {
return (retro_time_t)(LIBRETRO.core.gameTimeNSEC / (retro_perf_tick_t)1000);
}
/**
* Get the CPU Features.
*
* @see retro_get_cpu_features_t
* @return uint64_t Returns a bit-mask of detected CPU features (RETRO_SIMD_*).
*/
static uint64_t GetLibretroCPUFeatures(void) {
return cpu_features_get();
}
/**
* A simple counter. Usually nanoseconds, but can also be CPU cycles.
*
* @see retro_perf_get_counter_t
* @return retro_perf_tick_t The current value of the high resolution counter.
*/
static retro_perf_tick_t GetLibretroPerfCounter(void) {
return LIBRETRO.core.gameTimeNSEC;
}
/**
* Register a performance counter.
*
* @see retro_perf_register_t
*/
static void SetLibretroPerformanceCounter(struct retro_perf_counter* counter) {
// Ignore counters already in the array, otherwise a core that registers the
// same counter twice would get two slots pointing at it.
if (counter == NULL || counter->registered) {
return;
}
if (LIBRETRO.core.perf_counter_count >= LIBRETRO_MAX_PERF_COUNTERS) {
TraceLog(LOG_WARNING, "LIBRETRO: Perf counter limit reached (%d)", LIBRETRO_MAX_PERF_COUNTERS);
return;
}
LIBRETRO.core.perf_counters = (struct retro_perf_counter**)MemRealloc(
LIBRETRO.core.perf_counters,
(LIBRETRO.core.perf_counter_count + 1) * sizeof(struct retro_perf_counter*));
LIBRETRO.core.perf_counters[LIBRETRO.core.perf_counter_count++] = counter;
counter->registered = true;
}
/**
* Starts a registered counter.
*
* @see retro_perf_start_t
*/
static void StartLibretroPerformanceCounter(struct retro_perf_counter* counter) {
if (counter == NULL) {
return;
}
if (counter->registered) {
counter->start = GetLibretroPerfCounter();
counter->call_cnt++;
}
}
/**
* Stops a registered counter.
*
* @see retro_perf_stop_t
*/
static void StopLibretroPerformanceCounter(struct retro_perf_counter* counter) {
if (counter == NULL) {
return;
}
// Accumulate across every start/stop pair; total is the sum of all measured
// intervals, not just the most recent one.
counter->total += GetLibretroPerfCounter() - counter->start;
}
/**
* Log and display the state of performance counters.
*
* @see retro_perf_log_t
*/
static void LogLibretroPerformanceCounter(void) {
for (unsigned i = 0; i < LIBRETRO.core.perf_counter_count; i++) {
struct retro_perf_counter* c = LIBRETRO.core.perf_counters[i];
TraceLog(LOG_INFO, "LIBRETRO: Timer #%d %s: %llu ticks across %llu calls",
i + 1,
c->ident != NULL ? c->ident : "",
(unsigned long long)c->total,
(unsigned long long)c->call_cnt);
}
}
static bool SetLibretroRumbleState(unsigned port, enum retro_rumble_effect effect, uint16_t strength) {
if (port >= RAYLIB_LIBRETRO_RUMBLE_PORTS) {