2 * (C) notaz, 2012,2014,2015
4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
8 #define _GNU_SOURCE 1 // strcasestr
15 #include <sys/syscall.h>
18 #include "../libpcsxcore/misc.h"
19 #include "../libpcsxcore/psxcounters.h"
20 #include "../libpcsxcore/psxmem_map.h"
21 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
22 #include "../libpcsxcore/cdrom.h"
23 #include "../libpcsxcore/cdriso.h"
24 #include "../libpcsxcore/cheat.h"
25 #include "../plugins/dfsound/out.h"
26 #include "../plugins/dfsound/spu_config.h"
27 #include "../plugins/dfinput/externals.h"
31 #include "plugin_lib.h"
32 #include "arm_features.h"
37 #include "3ds/3ds_utils.h"
40 #define PORTS_NUMBER 8
43 #define MIN(a, b) ((a) < (b) ? (a) : (b))
46 #define ISHEXDEC ((buf[cursor]>='0') && (buf[cursor]<='9')) || ((buf[cursor]>='a') && (buf[cursor]<='f')) || ((buf[cursor]>='A') && (buf[cursor]<='F'))
48 //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key
49 static int rebootemu = 0;
51 static retro_video_refresh_t video_cb;
52 static retro_input_poll_t input_poll_cb;
53 static retro_input_state_t input_state_cb;
54 static retro_environment_t environ_cb;
55 static retro_audio_sample_batch_t audio_batch_cb;
56 static struct retro_rumble_interface rumble;
58 static void *vout_buf;
59 static void * vout_buf_ptr;
60 static int vout_width, vout_height;
61 static int vout_doffs_old, vout_fb_dirty;
62 static bool vout_can_dupe;
63 static bool duping_enable;
64 static bool found_bios;
66 static int plugins_opened;
67 static int is_pal_mode;
69 /* memory card data */
70 extern char Mcd1Data[MCD_SIZE];
71 extern char Mcd2Data[MCD_SIZE];
72 extern char McdDisable[2];
74 /* PCSX ReARMed core calls and stuff */
75 int in_type[8] = { PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
76 PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
77 PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
78 PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE };
79 int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
80 int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
81 unsigned short in_keystate[PORTS_NUMBER];
84 int in_enable_vibration = 1;
86 /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
87 #define VOUT_MAX_WIDTH 1024
88 #define VOUT_MAX_HEIGHT 512
91 bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info){return false;}
92 void retro_unload_game(void){}
93 static int vout_open(void){return 0;}
94 static void vout_close(void){}
95 static int snd_init(void){return 0;}
96 static void snd_finish(void){}
97 static int snd_busy(void){return 0;}
99 static void init_memcard(char *mcd_data)
104 memset(mcd_data, 0, MCD_SIZE);
106 mcd_data[off++] = 'M';
107 mcd_data[off++] = 'C';
109 mcd_data[off++] = 0x0e;
111 for (i = 0; i < 15; i++) {
112 mcd_data[off++] = 0xa0;
114 mcd_data[off++] = 0xff;
115 mcd_data[off++] = 0xff;
117 mcd_data[off++] = 0xa0;
120 for (i = 0; i < 20; i++) {
121 mcd_data[off++] = 0xff;
122 mcd_data[off++] = 0xff;
123 mcd_data[off++] = 0xff;
124 mcd_data[off++] = 0xff;
126 mcd_data[off++] = 0xff;
127 mcd_data[off++] = 0xff;
132 static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
137 struct retro_framebuffer fb = {0};
139 fb.width = vout_width;
140 fb.height = vout_height;
141 fb.access_flags = RETRO_MEMORY_ACCESS_WRITE;
143 vout_buf_ptr = vout_buf;
145 if (environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &fb) && fb.format == RETRO_PIXEL_FORMAT_RGB565)
147 vout_buf_ptr = (uint16_t*)fb.data;
152 #ifndef FRONTEND_SUPPORTS_RGB565
153 static void convert(void *buf, size_t bytes)
155 unsigned int i, v, *p = buf;
157 for (i = 0; i < bytes / 4; i++) {
159 p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0);
164 static void vout_flip(const void *vram, int stride, int bgr24, int w, int h)
166 unsigned short *dest = vout_buf_ptr;
167 const unsigned short *src = vram;
168 int dstride = vout_width, h1 = h;
173 memset(vout_buf_ptr, 0, dstride * h * 2);
177 doffs = (vout_height - h) * dstride;
178 doffs += (dstride - w) / 2 & ~1;
179 if (doffs != vout_doffs_old) {
181 memset(vout_buf_ptr, 0, dstride * h * 2);
182 vout_doffs_old = doffs;
188 // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here?
189 for (; h1-- > 0; dest += dstride, src += stride)
191 bgr888_to_rgb565(dest, src, w * 3);
196 for (; h1-- > 0; dest += dstride, src += stride)
198 bgr555_to_rgb565(dest, src, w * 2);
203 #ifndef FRONTEND_SUPPORTS_RGB565
204 convert(vout_buf_ptr, vout_width * vout_height * 2);
207 pl_rearmed_cbs.flip_cnt++;
219 psx_map_t custom_psx_maps[] = {
220 {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000
221 {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
222 {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
223 {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000
224 {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000
227 void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
235 psx_map_t* custom_map = custom_psx_maps;
237 for (; custom_map->size; custom_map++)
239 if ((custom_map->size == size) && (custom_map->tag == tag))
241 uint32_t ptr_aligned, tmp;
243 custom_map->buffer = malloc(size + 0x1000);
244 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
246 if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0)
248 SysPrintf("could not map memory @0x%08X\n", custom_map->target_map);
252 return (void*)custom_map->target_map;
260 void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
266 psx_map_t* custom_map = custom_psx_maps;
268 for (; custom_map->size; custom_map++)
270 if ((custom_map->target_map == (uint32_t)ptr))
272 uint32_t ptr_aligned, tmp;
274 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
276 svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3);
278 free(custom_map->buffer);
279 custom_map->buffer = NULL;
300 psx_map_t custom_psx_maps[] = {
301 {NULL, NULL, 0x210000, MAP_TAG_RAM}, // 0x80000000
302 {NULL, NULL, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
303 {NULL, NULL, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
304 {NULL, NULL, 0x800000, MAP_TAG_LUTS}, // 0x08000000
305 {NULL, NULL, 0x200000, MAP_TAG_VRAM}, // 0x00000000
308 int init_vita_mmap(){
311 addr = malloc(64*1024*1024);
314 tmpaddr = ((u32)(addr+0xFFFFFF))&~0xFFFFFF;
315 custom_psx_maps[0].buffer=tmpaddr+0x2000000;
316 custom_psx_maps[1].buffer=tmpaddr+0x1800000;
317 custom_psx_maps[2].buffer=tmpaddr+0x1c00000;
318 custom_psx_maps[3].buffer=tmpaddr+0x0000000;
319 custom_psx_maps[4].buffer=tmpaddr+0x1000000;
321 for(n = 0; n < 5; n++){
322 sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer);
328 void deinit_vita_mmap(){
332 void* pl_vita_mmap(unsigned long addr, size_t size, int is_fixed,
339 psx_map_t* custom_map = custom_psx_maps;
341 for (; custom_map->size; custom_map++)
343 if ((custom_map->size == size) && (custom_map->tag == tag))
345 return custom_map->buffer;
353 void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag)
357 psx_map_t* custom_map = custom_psx_maps;
359 for (; custom_map->size; custom_map++)
361 if ((custom_map->buffer == ptr))
371 static void *pl_mmap(unsigned int size)
373 return psxMap(0, size, 0, MAP_TAG_VRAM);
376 static void pl_munmap(void *ptr, unsigned int size)
378 psxUnmap(ptr, size, MAP_TAG_VRAM);
381 struct rearmed_cbs pl_rearmed_cbs = {
382 .pl_vout_open = vout_open,
383 .pl_vout_set_mode = vout_set_mode,
384 .pl_vout_flip = vout_flip,
385 .pl_vout_close = vout_close,
388 /* from psxcounters */
389 .gpu_hcnt = &hSyncCount,
390 .gpu_frame_count = &frame_counter,
393 void pl_frame_limit(void)
395 /* called once per frame, make psxCpu->Execute() above return */
399 void pl_timing_prepare(int is_pal)
401 is_pal_mode = is_pal;
404 void plat_trigger_vibrate(int pad, int low, int high)
406 if(in_enable_vibration)
408 rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8);
409 rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0);
413 void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
418 static void snd_feed(void *buf, int bytes)
420 if (audio_batch_cb != NULL)
421 audio_batch_cb(buf, bytes / 4);
424 void out_register_libretro(struct out_driver *drv)
426 drv->name = "libretro";
427 drv->init = snd_init;
428 drv->finish = snd_finish;
429 drv->busy = snd_busy;
430 drv->feed = snd_feed;
434 void retro_set_environment(retro_environment_t cb)
436 static const struct retro_variable vars[] = {
437 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
438 { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
439 { "pcsx_rearmed_pad1type", "Pad 1 Type; default|none|standard|analog|negcon" },
440 { "pcsx_rearmed_pad2type", "Pad 2 Type; default|none|standard|analog|negcon" },
441 { "pcsx_rearmed_pad3type", "Pad 3 Type; default|none|standard|analog|negcon" },
442 { "pcsx_rearmed_pad4type", "Pad 4 Type; default|none|standard|analog|negcon" },
443 { "pcsx_rearmed_pad5type", "Pad 5 Type; default|none|standard|analog|negcon" },
444 { "pcsx_rearmed_pad6type", "Pad 6 Type; default|none|standard|analog|negcon" },
445 { "pcsx_rearmed_pad7type", "Pad 7 Type; default|none|standard|analog|negcon" },
446 { "pcsx_rearmed_pad8type", "Pad 8 Type; default|none|standard|analog|negcon" },
447 { "pcsx_rearmed_multitap1", "Multitap 1; auto|disabled|enabled" },
448 { "pcsx_rearmed_multitap2", "Multitap 2; auto|disabled|enabled" },
449 { "pcsx_rearmed_vibration", "Enable Vibration; enabled|disabled" },
450 { "pcsx_rearmed_dithering", "Enable Dithering; enabled|disabled" },
452 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
455 { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
456 { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
457 { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
459 { "pcsx_rearmed_duping_enable", "Frame duping; enabled|disabled" },
460 { "pcsx_rearmed_show_bios_bootlogo", "Show Bios Bootlogo(Breaks some games); disabled|enabled" },
461 { "pcsx_rearmed_spu_reverb", "Sound: Reverb; enabled|disabled" },
462 { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" },
463 { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" },
464 { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" },
470 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
473 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
474 void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
475 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
476 void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
477 void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
479 unsigned retro_api_version(void)
481 return RETRO_API_VERSION;
484 static int controller_port_variable(unsigned port, struct retro_variable *var)
486 if (port >= PORTS_NUMBER)
495 var->key = "pcsx_rearmed_pad1type";
498 var->key = "pcsx_rearmed_pad2type";
501 var->key = "pcsx_rearmed_pad3type";
504 var->key = "pcsx_rearmed_pad4type";
507 var->key = "pcsx_rearmed_pad5type";
510 var->key = "pcsx_rearmed_pad6type";
513 var->key = "pcsx_rearmed_pad7type";
516 var->key = "pcsx_rearmed_pad8type";
520 return environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, var) || var->value;
523 static void update_controller_port_variable(unsigned port)
525 if (port >= PORTS_NUMBER)
528 struct retro_variable var;
530 if (controller_port_variable(port, &var))
532 if (strcmp(var.value, "standard") == 0)
533 in_type[port] = PSE_PAD_TYPE_STANDARD;
534 else if (strcmp(var.value, "analog") == 0)
535 in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
536 else if (strcmp(var.value, "negcon") == 0)
537 in_type[port] = PSE_PAD_TYPE_NEGCON;
538 else if (strcmp(var.value, "none") == 0)
539 in_type[port] = PSE_PAD_TYPE_NONE;
540 // else 'default' case, do nothing
544 static void update_controller_port_device(unsigned port, unsigned device)
546 if (port >= PORTS_NUMBER)
549 struct retro_variable var;
551 if (!controller_port_variable(port, &var))
554 if (strcmp(var.value, "default") != 0)
559 case RETRO_DEVICE_JOYPAD:
560 in_type[port] = PSE_PAD_TYPE_STANDARD;
562 case RETRO_DEVICE_ANALOG:
563 in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
565 case RETRO_DEVICE_MOUSE:
566 in_type[port] = PSE_PAD_TYPE_MOUSE;
568 case RETRO_DEVICE_LIGHTGUN:
569 in_type[port] = PSE_PAD_TYPE_GUN;
571 case RETRO_DEVICE_NONE:
573 in_type[port] = PSE_PAD_TYPE_NONE;
577 static void update_multitap()
579 struct retro_variable var;
583 var.key = "pcsx_rearmed_multitap1";
585 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
587 if (strcmp(var.value, "enabled") == 0)
589 else if (strcmp(var.value, "disabled") == 0)
599 // If a gamepad is plugged after port 2, we need a first multitap.
601 for (port = 2; port < PORTS_NUMBER; port++)
602 multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE;
606 var.key = "pcsx_rearmed_multitap2";
608 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
610 if (strcmp(var.value, "enabled") == 0)
612 else if (strcmp(var.value, "disabled") == 0)
622 // If a gamepad is plugged after port 4, we need a second multitap.
624 for (port = 4; port < PORTS_NUMBER; port++)
625 multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE;
629 void retro_set_controller_port_device(unsigned port, unsigned device)
631 SysPrintf("port %u device %u",port,device);
633 if (port >= PORTS_NUMBER)
636 update_controller_port_device(port, device);
640 void retro_get_system_info(struct retro_system_info *info)
642 memset(info, 0, sizeof(*info));
643 info->library_name = "PCSX-ReARMed";
645 #define GIT_VERSION ""
647 info->library_version = "r22" GIT_VERSION;
648 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
649 info->need_fullpath = true;
652 void retro_get_system_av_info(struct retro_system_av_info *info)
654 memset(info, 0, sizeof(*info));
655 info->timing.fps = is_pal_mode ? 50 : 60;
656 info->timing.sample_rate = 44100;
657 info->geometry.base_width = 320;
658 info->geometry.base_height = 240;
659 info->geometry.max_width = VOUT_MAX_WIDTH;
660 info->geometry.max_height = VOUT_MAX_HEIGHT;
661 info->geometry.aspect_ratio = 4.0 / 3.0;
665 size_t retro_serialize_size(void)
667 // it's currently 4380651-4397047 bytes,
668 // but have some reserved for future
678 static void *save_open(const char *name, const char *mode)
682 if (name == NULL || mode == NULL)
685 fp = malloc(sizeof(*fp));
689 fp->buf = (char *)name;
691 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
696 static int save_read(void *file, void *buf, u32 len)
698 struct save_fp *fp = file;
699 if (fp == NULL || buf == NULL)
702 memcpy(buf, fp->buf + fp->pos, len);
707 static int save_write(void *file, const void *buf, u32 len)
709 struct save_fp *fp = file;
710 if (fp == NULL || buf == NULL)
713 memcpy(fp->buf + fp->pos, buf, len);
718 static long save_seek(void *file, long offs, int whence)
720 struct save_fp *fp = file;
736 static void save_close(void *file)
738 struct save_fp *fp = file;
739 size_t r_size = retro_serialize_size();
743 if (fp->pos > r_size)
744 SysPrintf("ERROR: save buffer overflow detected\n");
745 else if (fp->is_write && fp->pos < r_size)
746 // make sure we don't save trash in leftover space
747 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
751 bool retro_serialize(void *data, size_t size)
753 int ret = SaveState(data);
754 return ret == 0 ? true : false;
757 bool retro_unserialize(const void *data, size_t size)
759 int ret = LoadState(data);
760 return ret == 0 ? true : false;
764 void retro_cheat_reset(void)
769 void retro_cheat_set(unsigned index, bool enabled, const char *code)
774 // cheat funcs are destructive, need a copy..
775 strncpy(buf, code, sizeof(buf));
776 buf[sizeof(buf) - 1] = 0;
778 //Prepare buffered cheat for PCSX's AddCheat fucntion.
793 if (index < NumCheats)
794 ret = EditCheat(index, "", buf);
796 ret = AddCheat("", buf);
799 SysPrintf("Failed to set cheat %#u\n", index);
800 else if (index < NumCheats)
801 Cheats[index].Enabled = enabled;
804 /* multidisk support */
805 static bool disk_ejected;
806 static unsigned int disk_current_index;
807 static unsigned int disk_count;
808 static struct disks_state {
810 int internal_index; // for multidisk eboots
813 static bool disk_set_eject_state(bool ejected)
816 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
819 disk_ejected = ejected;
823 static bool disk_get_eject_state(void)
825 /* can't be controlled by emulated software */
829 static unsigned int disk_get_image_index(void)
831 return disk_current_index;
834 static bool disk_set_image_index(unsigned int index)
836 if (index >= sizeof(disks) / sizeof(disks[0]))
840 CdromLabel[0] = '\0';
842 if (disks[index].fname == NULL) {
843 SysPrintf("missing disk #%u\n", index);
846 // RetroArch specifies "no disk" with index == count,
847 // so don't fail here..
848 disk_current_index = index;
852 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
853 disks[index].fname, disks[index].internal_index);
855 cdrIsoMultidiskSelect = disks[index].internal_index;
856 set_cd_image(disks[index].fname);
857 if (ReloadCdromPlugin() < 0) {
858 SysPrintf("failed to load cdr plugin\n");
861 if (CDR_open() < 0) {
862 SysPrintf("failed to open cdr plugin\n");
867 SetCdOpenCaseTime(time(NULL) + 2);
871 disk_current_index = index;
875 static unsigned int disk_get_num_images(void)
880 static bool disk_replace_image_index(unsigned index,
881 const struct retro_game_info *info)
886 if (index >= sizeof(disks) / sizeof(disks[0]))
889 old_fname = disks[index].fname;
890 disks[index].fname = NULL;
891 disks[index].internal_index = 0;
894 disks[index].fname = strdup(info->path);
895 if (index == disk_current_index)
896 ret = disk_set_image_index(index);
899 if (old_fname != NULL)
905 static bool disk_add_image_index(void)
914 static struct retro_disk_control_callback disk_control = {
915 .set_eject_state = disk_set_eject_state,
916 .get_eject_state = disk_get_eject_state,
917 .get_image_index = disk_get_image_index,
918 .set_image_index = disk_set_image_index,
919 .get_num_images = disk_get_num_images,
920 .replace_image_index = disk_replace_image_index,
921 .add_image_index = disk_add_image_index,
924 // just in case, maybe a win-rt port in the future?
932 #define PATH_MAX 4096
935 static char base_dir[PATH_MAX];
937 static bool read_m3u(const char *file)
941 FILE *f = fopen(file, "r");
945 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
948 char *carrige_return = strchr(line, '\r');
950 *carrige_return = '\0';
951 char *newline = strchr(line, '\n');
957 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
958 disks[disk_count++].fname = strdup(name);
963 return (disk_count != 0);
966 static void extract_directory(char *buf, const char *path, size_t size)
969 strncpy(buf, path, size - 1);
970 buf[size - 1] = '\0';
972 base = strrchr(buf, '/');
974 base = strrchr(buf, '\\');
985 #if defined(__QNX__) || defined(_WIN32)
986 /* Blackberry QNX doesn't have strcasestr */
989 * Find the first occurrence of find in s, ignore case.
992 strcasestr(const char *s, const char*find)
997 if ((c = *find++) != 0) {
998 c = tolower((unsigned char)c);
1002 if ((sc = *s++) == 0)
1004 } while ((char)tolower((unsigned char)sc) != c);
1005 } while (strncasecmp(s, find, len) != 0);
1012 bool retro_load_game(const struct retro_game_info *info)
1015 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
1017 struct retro_input_descriptor desc[] = {
1018 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1019 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1020 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1021 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1022 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1023 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1024 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1025 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1026 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1027 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1028 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1029 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1030 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1031 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1032 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1033 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1034 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1035 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1036 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1037 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1040 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1041 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1042 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1043 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1044 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1045 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1046 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1047 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1048 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1049 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1050 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1051 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1052 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1053 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1054 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1055 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1056 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1057 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1058 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1059 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1061 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1062 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1063 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1064 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1065 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1066 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1067 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1068 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1069 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1070 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1071 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1072 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1073 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1074 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1075 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1076 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1077 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1078 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1079 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1080 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1082 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1083 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1084 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1085 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1086 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1087 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1088 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1089 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1090 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1091 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1092 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1093 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1094 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1095 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1096 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1097 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1098 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1099 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1100 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1101 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1103 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1104 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1105 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1106 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1107 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1108 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1109 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1110 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1111 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1112 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1113 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1114 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1115 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1116 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1117 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1118 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1119 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1120 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1121 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1122 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1124 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1125 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1126 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1127 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1128 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1129 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1130 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1131 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1132 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1133 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1134 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1135 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1136 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1137 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1138 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1139 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1140 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1141 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1142 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1143 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1145 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1146 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1147 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1148 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1149 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1150 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1151 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1152 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1153 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1154 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1155 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1156 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1157 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1158 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1159 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1160 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1161 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1162 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1163 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1164 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1166 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1167 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1168 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1169 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1170 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1171 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1172 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1173 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1174 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1175 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1176 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1177 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1178 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1179 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1180 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1181 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1182 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1183 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1184 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1185 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1190 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
1192 #ifdef FRONTEND_SUPPORTS_RGB565
1193 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
1194 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
1195 SysPrintf("RGB565 supported, using it\n");
1199 if (info == NULL || info->path == NULL) {
1200 SysPrintf("info->path required\n");
1204 if (plugins_opened) {
1209 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
1210 if (disks[i].fname != NULL) {
1211 free(disks[i].fname);
1212 disks[i].fname = NULL;
1214 disks[i].internal_index = 0;
1217 disk_current_index = 0;
1218 extract_directory(base_dir, info->path, sizeof(base_dir));
1221 if (!read_m3u(info->path)) {
1222 SysPrintf("failed to read m3u file\n");
1227 disks[0].fname = strdup(info->path);
1230 set_cd_image(disks[0].fname);
1232 /* have to reload after set_cd_image for correct cdr plugin */
1233 if (LoadPlugins() == -1) {
1234 SysPrintf("failed to load plugins\n");
1241 if (OpenPlugins() == -1) {
1242 SysPrintf("failed to open plugins\n");
1246 plugin_call_rearmed_cbs();
1250 if (CheckCdrom() == -1) {
1251 SysPrintf("unsupported/invalid CD image: %s\n", info->path);
1257 if (LoadCdrom() == -1) {
1258 SysPrintf("could not load CD-ROM!\n");
1265 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
1266 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
1267 disks[i].fname = strdup(info->path);
1268 disks[i].internal_index = i;
1275 unsigned retro_get_region(void)
1277 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
1280 void *retro_get_memory_data(unsigned id)
1282 if (id == RETRO_MEMORY_SAVE_RAM)
1288 size_t retro_get_memory_size(unsigned id)
1290 if (id == RETRO_MEMORY_SAVE_RAM)
1296 void retro_reset(void)
1298 //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key
1303 static const unsigned short retro_psx_map[] = {
1304 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
1305 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
1306 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
1307 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
1308 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
1309 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
1310 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
1311 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
1312 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
1313 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
1314 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
1315 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
1316 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
1317 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
1318 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
1319 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
1321 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
1323 static void update_variables(bool in_flight)
1325 struct retro_variable var;
1329 var.key = "pcsx_rearmed_frameskip";
1330 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1331 pl_rearmed_cbs.frameskip = atoi(var.value);
1334 var.key = "pcsx_rearmed_region";
1335 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1338 if (strcmp(var.value, "Automatic") == 0)
1340 else if (strcmp(var.value, "NTSC") == 0)
1342 else if (strcmp(var.value, "PAL") == 0)
1346 for (i = 0; i < PORTS_NUMBER; i++)
1347 update_controller_port_variable(i);
1352 var.key = "pcsx_rearmed_vibration";
1354 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1356 if (strcmp(var.value, "disabled") == 0)
1357 in_enable_vibration = 0;
1358 else if (strcmp(var.value, "enabled") == 0)
1359 in_enable_vibration = 1;
1363 var.key = "pcsx_rearmed_dithering";
1365 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1367 if (strcmp(var.value, "disabled") == 0) {
1368 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
1369 pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 0;
1371 pl_rearmed_cbs.gpu_neon.allow_dithering = 0;
1374 else if (strcmp(var.value, "enabled") == 0) {
1375 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1376 pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1;
1378 pl_rearmed_cbs.gpu_neon.allow_dithering = 1;
1385 var.key = "pcsx_rearmed_neon_interlace_enable";
1387 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1389 if (strcmp(var.value, "disabled") == 0)
1390 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1391 else if (strcmp(var.value, "enabled") == 0)
1392 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1396 var.key = "pcsx_rearmed_neon_enhancement_enable";
1398 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1400 if (strcmp(var.value, "disabled") == 0)
1401 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1402 else if (strcmp(var.value, "enabled") == 0)
1403 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1407 var.key = "pcsx_rearmed_neon_enhancement_no_main";
1409 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1411 if (strcmp(var.value, "disabled") == 0)
1412 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1413 else if (strcmp(var.value, "enabled") == 0)
1414 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1419 var.key = "pcsx_rearmed_duping_enable";
1421 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1423 if (strcmp(var.value, "disabled") == 0)
1424 duping_enable = false;
1425 else if (strcmp(var.value, "enabled") == 0)
1426 duping_enable = true;
1431 var.key = "pcsx_rearmed_drc";
1433 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1435 R3000Acpu *prev_cpu = psxCpu;
1439 Config.Cpu = CPU_INTERPRETER;
1442 if (strcmp(var.value, "disabled") == 0)
1443 Config.Cpu = CPU_INTERPRETER;
1444 else if (strcmp(var.value, "enabled") == 0)
1445 Config.Cpu = CPU_DYNAREC;
1447 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1448 if (psxCpu != prev_cpu) {
1449 prev_cpu->Shutdown();
1451 psxCpu->Reset(); // not really a reset..
1457 var.key = "pcsx_rearmed_spu_reverb";
1459 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1461 if (strcmp(var.value, "disabled") == 0)
1462 spu_config.iUseReverb = false;
1463 else if (strcmp(var.value, "enabled") == 0)
1464 spu_config.iUseReverb = true;
1468 var.key = "pcsx_rearmed_spu_interpolation";
1470 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1472 if (strcmp(var.value, "simple") == 0)
1473 spu_config.iUseInterpolation = 1;
1474 else if (strcmp(var.value, "gaussian") == 0)
1475 spu_config.iUseInterpolation = 2;
1476 else if (strcmp(var.value, "cubic") == 0)
1477 spu_config.iUseInterpolation = 3;
1478 else if (strcmp(var.value, "off") == 0)
1479 spu_config.iUseInterpolation = 0;
1483 var.key = "pcsx_rearmed_pe2_fix";
1485 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1487 if (strcmp(var.value, "disabled") == 0)
1489 else if (strcmp(var.value, "enabled") == 0)
1494 var.key = "pcsx_rearmed_inuyasha_fix";
1496 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1498 if (strcmp(var.value, "disabled") == 0)
1500 else if (strcmp(var.value, "enabled") == 0)
1505 // inform core things about possible config changes
1506 plugin_call_rearmed_cbs();
1508 if (GPU_open != NULL && GPU_close != NULL) {
1510 GPU_open(&gpuDisp, "PCSX", NULL);
1518 //bootlogo display hack
1521 var.key = "pcsx_rearmed_show_bios_bootlogo";
1522 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1524 if (strcmp(var.value, "enabled") == 0)
1531 void retro_run(void)
1534 //SysReset must be run while core is running,Not in menu (Locks up Retroarch)
1542 bool updated = false;
1543 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1544 update_variables(true);
1546 // reset all keystate, query libretro for keystate
1548 for(i = 0; i < PORTS_NUMBER; i++) {
1551 if (in_type[i] == PSE_PAD_TYPE_NONE)
1554 // query libretro for keystate
1555 for (j = 0; j < RETRO_PSX_MAP_LEN; j++)
1556 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j))
1557 in_keystate[i] |= retro_psx_map[j];
1559 if (in_type[i] == PSE_PAD_TYPE_ANALOGPAD)
1561 in_analog_left[i][0] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 255) + 128, 255);
1562 in_analog_left[i][1] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 255) + 128, 255);
1563 in_analog_right[i][0] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 255) + 128, 255);
1564 in_analog_right[i][1] = MIN((input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 255) + 128, 255);
1571 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf_ptr : NULL,
1572 vout_width, vout_height, vout_width * 2);
1576 static bool try_use_bios(const char *path)
1582 f = fopen(path, "rb");
1586 fseek(f, 0, SEEK_END);
1590 if (size != 512 * 1024)
1593 name = strrchr(path, SLASH);
1596 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1601 #include <sys/types.h>
1604 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1610 dir = opendir(dirpath);
1614 while ((ent = readdir(dir))) {
1615 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1618 snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
1619 ret = try_use_bios(path);
1627 #define find_any_bios(...) false
1630 static void check_system_specs(void)
1633 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1636 void retro_init(void)
1638 const char *bios[] = { "SCPH101", "SCPH7001", "SCPH5501", "SCPH1001" };
1646 // magic sauce to make the dynarec work on iOS
1647 syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0);
1651 psxMapHook = pl_3ds_mmap;
1652 psxUnmapHook = pl_3ds_munmap;
1655 if(init_vita_mmap()<0)
1657 psxMapHook = pl_vita_mmap;
1658 psxUnmapHook = pl_vita_munmap;
1660 ret = emu_core_preinit();
1662 /* emu_core_preinit sets the cpu to dynarec */
1664 Config.Cpu = CPU_INTERPRETER;
1667 ret |= emu_core_init();
1669 SysPrintf("PCSX init failed.\n");
1674 vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
1675 #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
1676 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1678 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1681 vout_buf_ptr = vout_buf;
1683 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1685 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
1687 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1688 snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
1689 found_bios = try_use_bios(path);
1695 found_bios = find_any_bios(dir, path, sizeof(path));
1698 SysPrintf("found BIOS file: %s\n", Config.Bios);
1702 SysPrintf("no BIOS files found.\n");
1703 struct retro_message msg =
1705 "No PlayStation BIOS file found - add for better compatibility",
1708 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1711 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1712 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1713 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1715 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1716 * we have to do this because cache misses and some IO penalties
1717 * are not emulated. Warning: changing this may break compatibility. */
1718 cycle_multiplier = 175;
1719 #ifdef HAVE_PRE_ARMV7
1720 cycle_multiplier = 200;
1722 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1723 spu_config.iUseFixedUpdates = 1;
1727 init_memcard(Mcd1Data);
1728 init_memcard(Mcd2Data);
1730 SaveFuncs.open = save_open;
1731 SaveFuncs.read = save_read;
1732 SaveFuncs.write = save_write;
1733 SaveFuncs.seek = save_seek;
1734 SaveFuncs.close = save_close;
1736 update_variables(false);
1737 check_system_specs();
1740 void retro_deinit(void)
1744 linearFree(vout_buf);
1756 #include <psp2/kernel/threadmgr.h>
1757 int usleep (unsigned long us)
1759 sceKernelDelayThread(us);