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))
47 #define MAX(a, b) ((a) > (b) ? (a) : (b))
50 #define ISHEXDEC ((buf[cursor]>='0') && (buf[cursor]<='9')) || ((buf[cursor]>='a') && (buf[cursor]<='f')) || ((buf[cursor]>='A') && (buf[cursor]<='F'))
52 //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key
53 static int rebootemu = 0;
55 static retro_video_refresh_t video_cb;
56 static retro_input_poll_t input_poll_cb;
57 static retro_input_state_t input_state_cb;
58 static retro_environment_t environ_cb;
59 static retro_audio_sample_batch_t audio_batch_cb;
60 static struct retro_rumble_interface rumble;
61 static struct retro_log_callback logging;
62 static retro_log_printf_t log_cb;
64 static void *vout_buf;
65 static void * vout_buf_ptr;
66 static int vout_width, vout_height;
67 static int vout_doffs_old, vout_fb_dirty;
68 static bool vout_can_dupe;
69 static bool duping_enable;
70 static bool found_bios;
72 static int plugins_opened;
73 static int is_pal_mode;
75 /* memory card data */
76 extern char Mcd1Data[MCD_SIZE];
77 extern char Mcd2Data[MCD_SIZE];
78 extern char McdDisable[2];
80 /* PCSX ReARMed core calls and stuff */
81 int in_type[8] = { PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
82 PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
83 PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE,
84 PSE_PAD_TYPE_NONE, PSE_PAD_TYPE_NONE };
85 int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
86 int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
87 unsigned short in_keystate[PORTS_NUMBER];
90 int in_enable_vibration = 1;
92 // NegCon adjustment parameters
93 // > The NegCon 'twist' action is somewhat awkward when mapped
94 // to a standard analog stick -> user should be able to tweak
95 // response/deadzone for comfort
96 // > When response is linear, 'additional' deadzone (set here)
97 // may be left at zero, since this is normally handled via in-game
99 // > When response is non-linear, deadzone should be set to match the
100 // controller being used (otherwise precision may be lost)
101 // > negcon_linearity:
102 // - 1: Response is linear - recommended when using racing wheel
103 // peripherals, not recommended for standard gamepads
104 // - 2: Response is quadratic - optimal setting for gamepads
105 // - 3: Response is cubic - enables precise fine control, but
106 // difficult to use...
107 #define NEGCON_RANGE 0x7FFF
108 static int negcon_deadzone = 0;
109 static int negcon_linearity = 1;
111 /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
112 #define VOUT_MAX_WIDTH 1024
113 #define VOUT_MAX_HEIGHT 512
116 bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info){return false;}
117 void retro_unload_game(void){}
118 static int vout_open(void){return 0;}
119 static void vout_close(void){}
120 static int snd_init(void){return 0;}
121 static void snd_finish(void){}
122 static int snd_busy(void){return 0;}
124 static void init_memcard(char *mcd_data)
129 memset(mcd_data, 0, MCD_SIZE);
131 mcd_data[off++] = 'M';
132 mcd_data[off++] = 'C';
134 mcd_data[off++] = 0x0e;
136 for (i = 0; i < 15; i++) {
137 mcd_data[off++] = 0xa0;
139 mcd_data[off++] = 0xff;
140 mcd_data[off++] = 0xff;
142 mcd_data[off++] = 0xa0;
145 for (i = 0; i < 20; i++) {
146 mcd_data[off++] = 0xff;
147 mcd_data[off++] = 0xff;
148 mcd_data[off++] = 0xff;
149 mcd_data[off++] = 0xff;
151 mcd_data[off++] = 0xff;
152 mcd_data[off++] = 0xff;
157 static void set_vout_fb()
159 struct retro_framebuffer fb = {0};
161 fb.width = vout_width;
162 fb.height = vout_height;
163 fb.access_flags = RETRO_MEMORY_ACCESS_WRITE;
165 if (environ_cb(RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER, &fb) && fb.format == RETRO_PIXEL_FORMAT_RGB565)
166 vout_buf_ptr = (uint16_t*)fb.data;
168 vout_buf_ptr = vout_buf;
171 static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
179 #ifndef FRONTEND_SUPPORTS_RGB565
180 static void convert(void *buf, size_t bytes)
182 unsigned int i, v, *p = buf;
184 for (i = 0; i < bytes / 4; i++) {
186 p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0);
191 static void vout_flip(const void *vram, int stride, int bgr24, int w, int h)
193 unsigned short *dest = vout_buf_ptr;
194 const unsigned short *src = vram;
195 int dstride = vout_width, h1 = h;
200 memset(vout_buf_ptr, 0, dstride * h * 2);
204 doffs = (vout_height - h) * dstride;
205 doffs += (dstride - w) / 2 & ~1;
206 if (doffs != vout_doffs_old) {
208 memset(vout_buf_ptr, 0, dstride * h * 2);
209 vout_doffs_old = doffs;
215 // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here?
216 for (; h1-- > 0; dest += dstride, src += stride)
218 bgr888_to_rgb565(dest, src, w * 3);
223 for (; h1-- > 0; dest += dstride, src += stride)
225 bgr555_to_rgb565(dest, src, w * 2);
230 #ifndef FRONTEND_SUPPORTS_RGB565
231 convert(vout_buf_ptr, vout_width * vout_height * 2);
234 pl_rearmed_cbs.flip_cnt++;
246 psx_map_t custom_psx_maps[] = {
247 {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000
248 {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
249 {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
250 {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000
251 {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000
254 void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
262 psx_map_t* custom_map = custom_psx_maps;
264 for (; custom_map->size; custom_map++)
266 if ((custom_map->size == size) && (custom_map->tag == tag))
268 uint32_t ptr_aligned, tmp;
270 custom_map->buffer = malloc(size + 0x1000);
271 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
273 if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0)
275 SysPrintf("could not map memory @0x%08X\n", custom_map->target_map);
279 return (void*)custom_map->target_map;
287 void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
293 psx_map_t* custom_map = custom_psx_maps;
295 for (; custom_map->size; custom_map++)
297 if ((custom_map->target_map == (uint32_t)ptr))
299 uint32_t ptr_aligned, tmp;
301 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
303 svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3);
305 free(custom_map->buffer);
306 custom_map->buffer = NULL;
327 psx_map_t custom_psx_maps[] = {
328 {NULL, NULL, 0x210000, MAP_TAG_RAM}, // 0x80000000
329 {NULL, NULL, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
330 {NULL, NULL, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
331 {NULL, NULL, 0x800000, MAP_TAG_LUTS}, // 0x08000000
332 {NULL, NULL, 0x200000, MAP_TAG_VRAM}, // 0x00000000
335 int init_vita_mmap(){
338 addr = malloc(64*1024*1024);
341 tmpaddr = ((u32)(addr+0xFFFFFF))&~0xFFFFFF;
342 custom_psx_maps[0].buffer=tmpaddr+0x2000000;
343 custom_psx_maps[1].buffer=tmpaddr+0x1800000;
344 custom_psx_maps[2].buffer=tmpaddr+0x1c00000;
345 custom_psx_maps[3].buffer=tmpaddr+0x0000000;
346 custom_psx_maps[4].buffer=tmpaddr+0x1000000;
348 for(n = 0; n < 5; n++){
349 sceClibPrintf("addr reserved %x\n",custom_psx_maps[n].buffer);
355 void deinit_vita_mmap(){
359 void* pl_vita_mmap(unsigned long addr, size_t size, int is_fixed,
366 psx_map_t* custom_map = custom_psx_maps;
368 for (; custom_map->size; custom_map++)
370 if ((custom_map->size == size) && (custom_map->tag == tag))
372 return custom_map->buffer;
380 void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag)
384 psx_map_t* custom_map = custom_psx_maps;
386 for (; custom_map->size; custom_map++)
388 if ((custom_map->buffer == ptr))
398 static void *pl_mmap(unsigned int size)
400 return psxMap(0, size, 0, MAP_TAG_VRAM);
403 static void pl_munmap(void *ptr, unsigned int size)
405 psxUnmap(ptr, size, MAP_TAG_VRAM);
408 struct rearmed_cbs pl_rearmed_cbs = {
409 .pl_vout_open = vout_open,
410 .pl_vout_set_mode = vout_set_mode,
411 .pl_vout_flip = vout_flip,
412 .pl_vout_close = vout_close,
415 /* from psxcounters */
416 .gpu_hcnt = &hSyncCount,
417 .gpu_frame_count = &frame_counter,
420 void pl_frame_limit(void)
422 /* called once per frame, make psxCpu->Execute() above return */
426 void pl_timing_prepare(int is_pal)
428 is_pal_mode = is_pal;
431 void plat_trigger_vibrate(int pad, int low, int high)
433 if(in_enable_vibration)
435 rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8);
436 rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0);
440 void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
445 static void snd_feed(void *buf, int bytes)
447 if (audio_batch_cb != NULL)
448 audio_batch_cb(buf, bytes / 4);
451 void out_register_libretro(struct out_driver *drv)
453 drv->name = "libretro";
454 drv->init = snd_init;
455 drv->finish = snd_finish;
456 drv->busy = snd_busy;
457 drv->feed = snd_feed;
461 void retro_set_environment(retro_environment_t cb)
463 static const struct retro_variable vars[] = {
464 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
465 { "pcsx_rearmed_region", "Region; auto|NTSC|PAL" },
466 { "pcsx_rearmed_memcard2", "Enable second memory card; disabled|enabled" },
467 { "pcsx_rearmed_pad1type", "Pad 1 Type; default|none|standard|analog|negcon" },
468 { "pcsx_rearmed_pad2type", "Pad 2 Type; default|none|standard|analog|negcon" },
469 { "pcsx_rearmed_pad3type", "Pad 3 Type; default|none|standard|analog|negcon" },
470 { "pcsx_rearmed_pad4type", "Pad 4 Type; default|none|standard|analog|negcon" },
471 { "pcsx_rearmed_pad5type", "Pad 5 Type; default|none|standard|analog|negcon" },
472 { "pcsx_rearmed_pad6type", "Pad 6 Type; default|none|standard|analog|negcon" },
473 { "pcsx_rearmed_pad7type", "Pad 7 Type; default|none|standard|analog|negcon" },
474 { "pcsx_rearmed_pad8type", "Pad 8 Type; default|none|standard|analog|negcon" },
475 { "pcsx_rearmed_multitap1", "Multitap 1; auto|disabled|enabled" },
476 { "pcsx_rearmed_multitap2", "Multitap 2; auto|disabled|enabled" },
477 { "pcsx_rearmed_negcon_deadzone", "NegCon Twist Deadzone (percent); 0|5|10|15|20|25|30" },
478 { "pcsx_rearmed_negcon_response", "NegCon Twist Response; linear|quadratic|cubic" },
479 { "pcsx_rearmed_vibration", "Enable Vibration; enabled|disabled" },
480 { "pcsx_rearmed_dithering", "Enable Dithering; enabled|disabled" },
482 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
485 { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
486 { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
487 { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
489 { "pcsx_rearmed_duping_enable", "Frame duping; enabled|disabled" },
490 { "pcsx_rearmed_show_bios_bootlogo", "Show Bios Bootlogo(Breaks some games); disabled|enabled" },
491 { "pcsx_rearmed_spu_reverb", "Sound: Reverb; enabled|disabled" },
492 { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" },
493 { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" },
494 { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" },
498 if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
499 log_cb = logging.log;
503 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
506 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
507 void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
508 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
509 void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
510 void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
512 unsigned retro_api_version(void)
514 return RETRO_API_VERSION;
517 static int controller_port_variable(unsigned port, struct retro_variable *var)
519 if (port >= PORTS_NUMBER)
528 var->key = "pcsx_rearmed_pad1type";
531 var->key = "pcsx_rearmed_pad2type";
534 var->key = "pcsx_rearmed_pad3type";
537 var->key = "pcsx_rearmed_pad4type";
540 var->key = "pcsx_rearmed_pad5type";
543 var->key = "pcsx_rearmed_pad6type";
546 var->key = "pcsx_rearmed_pad7type";
549 var->key = "pcsx_rearmed_pad8type";
553 return environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, var) || var->value;
556 static void update_controller_port_variable(unsigned port)
558 if (port >= PORTS_NUMBER)
561 struct retro_variable var;
563 if (controller_port_variable(port, &var))
565 if (strcmp(var.value, "standard") == 0)
566 in_type[port] = PSE_PAD_TYPE_STANDARD;
567 else if (strcmp(var.value, "analog") == 0)
568 in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
569 else if (strcmp(var.value, "negcon") == 0)
570 in_type[port] = PSE_PAD_TYPE_NEGCON;
571 else if (strcmp(var.value, "none") == 0)
572 in_type[port] = PSE_PAD_TYPE_NONE;
573 // else 'default' case, do nothing
577 static void update_controller_port_device(unsigned port, unsigned device)
579 if (port >= PORTS_NUMBER)
582 struct retro_variable var;
584 if (!controller_port_variable(port, &var))
587 if (strcmp(var.value, "default") != 0)
592 case RETRO_DEVICE_JOYPAD:
593 in_type[port] = PSE_PAD_TYPE_STANDARD;
595 case RETRO_DEVICE_ANALOG:
596 in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
598 case RETRO_DEVICE_MOUSE:
599 in_type[port] = PSE_PAD_TYPE_MOUSE;
601 case RETRO_DEVICE_LIGHTGUN:
602 in_type[port] = PSE_PAD_TYPE_GUN;
604 case RETRO_DEVICE_NONE:
606 in_type[port] = PSE_PAD_TYPE_NONE;
610 static void update_multitap()
612 struct retro_variable var;
616 var.key = "pcsx_rearmed_multitap1";
618 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
620 if (strcmp(var.value, "enabled") == 0)
622 else if (strcmp(var.value, "disabled") == 0)
632 // If a gamepad is plugged after port 2, we need a first multitap.
634 for (port = 2; port < PORTS_NUMBER; port++)
635 multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE;
639 var.key = "pcsx_rearmed_multitap2";
641 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
643 if (strcmp(var.value, "enabled") == 0)
645 else if (strcmp(var.value, "disabled") == 0)
655 // If a gamepad is plugged after port 4, we need a second multitap.
657 for (port = 4; port < PORTS_NUMBER; port++)
658 multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE;
662 void retro_set_controller_port_device(unsigned port, unsigned device)
664 SysPrintf("port %u device %u",port,device);
666 if (port >= PORTS_NUMBER)
669 update_controller_port_device(port, device);
673 void retro_get_system_info(struct retro_system_info *info)
675 memset(info, 0, sizeof(*info));
676 info->library_name = "PCSX-ReARMed";
678 #define GIT_VERSION ""
680 info->library_version = "r22" GIT_VERSION;
681 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
682 info->need_fullpath = true;
685 void retro_get_system_av_info(struct retro_system_av_info *info)
687 memset(info, 0, sizeof(*info));
688 info->timing.fps = is_pal_mode ? 50 : 60;
689 info->timing.sample_rate = 44100;
690 info->geometry.base_width = 320;
691 info->geometry.base_height = 240;
692 info->geometry.max_width = VOUT_MAX_WIDTH;
693 info->geometry.max_height = VOUT_MAX_HEIGHT;
694 info->geometry.aspect_ratio = 4.0 / 3.0;
698 size_t retro_serialize_size(void)
700 // it's currently 4380651-4397047 bytes,
701 // but have some reserved for future
711 static void *save_open(const char *name, const char *mode)
715 if (name == NULL || mode == NULL)
718 fp = malloc(sizeof(*fp));
722 fp->buf = (char *)name;
724 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
729 static int save_read(void *file, void *buf, u32 len)
731 struct save_fp *fp = file;
732 if (fp == NULL || buf == NULL)
735 memcpy(buf, fp->buf + fp->pos, len);
740 static int save_write(void *file, const void *buf, u32 len)
742 struct save_fp *fp = file;
743 if (fp == NULL || buf == NULL)
746 memcpy(fp->buf + fp->pos, buf, len);
751 static long save_seek(void *file, long offs, int whence)
753 struct save_fp *fp = file;
769 static void save_close(void *file)
771 struct save_fp *fp = file;
772 size_t r_size = retro_serialize_size();
776 if (fp->pos > r_size)
777 SysPrintf("ERROR: save buffer overflow detected\n");
778 else if (fp->is_write && fp->pos < r_size)
779 // make sure we don't save trash in leftover space
780 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
784 bool retro_serialize(void *data, size_t size)
786 int ret = SaveState(data);
787 return ret == 0 ? true : false;
790 bool retro_unserialize(const void *data, size_t size)
792 int ret = LoadState(data);
793 return ret == 0 ? true : false;
797 void retro_cheat_reset(void)
802 void retro_cheat_set(unsigned index, bool enabled, const char *code)
807 // cheat funcs are destructive, need a copy..
808 strncpy(buf, code, sizeof(buf));
809 buf[sizeof(buf) - 1] = 0;
811 //Prepare buffered cheat for PCSX's AddCheat fucntion.
826 if (index < NumCheats)
827 ret = EditCheat(index, "", buf);
829 ret = AddCheat("", buf);
832 SysPrintf("Failed to set cheat %#u\n", index);
833 else if (index < NumCheats)
834 Cheats[index].Enabled = enabled;
837 /* multidisk support */
838 static bool disk_ejected;
839 static unsigned int disk_current_index;
840 static unsigned int disk_count;
841 static struct disks_state {
843 int internal_index; // for multidisk eboots
846 static bool disk_set_eject_state(bool ejected)
849 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
852 disk_ejected = ejected;
856 static bool disk_get_eject_state(void)
858 /* can't be controlled by emulated software */
862 static unsigned int disk_get_image_index(void)
864 return disk_current_index;
867 static bool disk_set_image_index(unsigned int index)
869 if (index >= sizeof(disks) / sizeof(disks[0]))
873 CdromLabel[0] = '\0';
875 if (disks[index].fname == NULL) {
876 SysPrintf("missing disk #%u\n", index);
879 // RetroArch specifies "no disk" with index == count,
880 // so don't fail here..
881 disk_current_index = index;
885 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
886 disks[index].fname, disks[index].internal_index);
888 cdrIsoMultidiskSelect = disks[index].internal_index;
889 set_cd_image(disks[index].fname);
890 if (ReloadCdromPlugin() < 0) {
891 SysPrintf("failed to load cdr plugin\n");
894 if (CDR_open() < 0) {
895 SysPrintf("failed to open cdr plugin\n");
900 SetCdOpenCaseTime(time(NULL) + 2);
904 disk_current_index = index;
908 static unsigned int disk_get_num_images(void)
913 static bool disk_replace_image_index(unsigned index,
914 const struct retro_game_info *info)
919 if (index >= sizeof(disks) / sizeof(disks[0]))
922 old_fname = disks[index].fname;
923 disks[index].fname = NULL;
924 disks[index].internal_index = 0;
927 disks[index].fname = strdup(info->path);
928 if (index == disk_current_index)
929 ret = disk_set_image_index(index);
932 if (old_fname != NULL)
938 static bool disk_add_image_index(void)
947 static struct retro_disk_control_callback disk_control = {
948 .set_eject_state = disk_set_eject_state,
949 .get_eject_state = disk_get_eject_state,
950 .get_image_index = disk_get_image_index,
951 .set_image_index = disk_set_image_index,
952 .get_num_images = disk_get_num_images,
953 .replace_image_index = disk_replace_image_index,
954 .add_image_index = disk_add_image_index,
957 // just in case, maybe a win-rt port in the future?
965 #define PATH_MAX 4096
968 static char base_dir[PATH_MAX];
970 static bool read_m3u(const char *file)
974 FILE *f = fopen(file, "r");
978 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
981 char *carrige_return = strchr(line, '\r');
983 *carrige_return = '\0';
984 char *newline = strchr(line, '\n');
990 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
991 disks[disk_count++].fname = strdup(name);
996 return (disk_count != 0);
999 static void extract_directory(char *buf, const char *path, size_t size)
1002 strncpy(buf, path, size - 1);
1003 buf[size - 1] = '\0';
1005 base = strrchr(buf, '/');
1007 base = strrchr(buf, '\\');
1018 #if defined(__QNX__) || defined(_WIN32)
1019 /* Blackberry QNX doesn't have strcasestr */
1022 * Find the first occurrence of find in s, ignore case.
1025 strcasestr(const char *s, const char*find)
1030 if ((c = *find++) != 0) {
1031 c = tolower((unsigned char)c);
1035 if ((sc = *s++) == 0)
1037 } while ((char)tolower((unsigned char)sc) != c);
1038 } while (strncasecmp(s, find, len) != 0);
1045 bool retro_load_game(const struct retro_game_info *info)
1048 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
1050 struct retro_input_descriptor desc[] = {
1051 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1052 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1053 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1054 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1055 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1056 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1057 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1058 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1059 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1060 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1061 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1062 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1063 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1064 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1065 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1066 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1067 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1068 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1069 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1070 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1073 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1074 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1075 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1076 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1077 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1078 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1079 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1080 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1081 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1082 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1083 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1084 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1085 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1086 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1087 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1088 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1089 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1090 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1091 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1092 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1094 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1095 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1096 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1097 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1098 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1099 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1100 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1101 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1102 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1103 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1104 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1105 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1106 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1107 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1108 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1109 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1110 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1111 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1112 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1113 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1115 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1116 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1117 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1118 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1119 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1120 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1121 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1122 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1123 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1124 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1125 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1126 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1127 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1128 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1129 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1130 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1131 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1132 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1133 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1134 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1136 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1137 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1138 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1139 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1140 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1141 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1142 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1143 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1144 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1145 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1146 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1147 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1148 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1149 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1150 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1151 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1152 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1153 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1154 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1155 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1157 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1158 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1159 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1160 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1161 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1162 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1163 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1164 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1165 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1166 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1167 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1168 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1169 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1170 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1171 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1172 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1173 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1174 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1175 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1176 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1178 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1179 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1180 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1181 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1182 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1183 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1184 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1185 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1186 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1187 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1188 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1189 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1190 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1191 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1192 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1193 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1194 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1195 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1196 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1197 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1199 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1200 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1201 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1202 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1203 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1204 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1205 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1206 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1207 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1208 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1209 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1210 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1211 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1212 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1213 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1214 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1215 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1216 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1217 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1218 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1223 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
1225 #ifdef FRONTEND_SUPPORTS_RGB565
1226 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
1227 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
1228 SysPrintf("RGB565 supported, using it\n");
1232 if (info == NULL || info->path == NULL) {
1233 SysPrintf("info->path required\n");
1237 if (plugins_opened) {
1242 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
1243 if (disks[i].fname != NULL) {
1244 free(disks[i].fname);
1245 disks[i].fname = NULL;
1247 disks[i].internal_index = 0;
1250 disk_current_index = 0;
1251 extract_directory(base_dir, info->path, sizeof(base_dir));
1254 if (!read_m3u(info->path)) {
1255 log_cb(RETRO_LOG_INFO, "failed to read m3u file\n");
1260 disks[0].fname = strdup(info->path);
1263 set_cd_image(disks[0].fname);
1265 /* have to reload after set_cd_image for correct cdr plugin */
1266 if (LoadPlugins() == -1) {
1267 log_cb(RETRO_LOG_INFO, "failed to load plugins\n");
1274 if (OpenPlugins() == -1) {
1275 log_cb(RETRO_LOG_INFO, "failed to open plugins\n");
1279 plugin_call_rearmed_cbs();
1282 if (CheckCdrom() == -1) {
1283 log_cb(RETRO_LOG_INFO, "unsupported/invalid CD image: %s\n", info->path);
1289 if (LoadCdrom() == -1) {
1290 log_cb(RETRO_LOG_INFO, "could not load CD\n");
1297 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
1298 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
1299 disks[i].fname = strdup(info->path);
1300 disks[i].internal_index = i;
1307 unsigned retro_get_region(void)
1309 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
1312 void *retro_get_memory_data(unsigned id)
1314 if (id == RETRO_MEMORY_SAVE_RAM)
1320 size_t retro_get_memory_size(unsigned id)
1322 if (id == RETRO_MEMORY_SAVE_RAM)
1328 void retro_reset(void)
1330 //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key
1335 static const unsigned short retro_psx_map[] = {
1336 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
1337 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
1338 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
1339 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
1340 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
1341 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
1342 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
1343 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
1344 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
1345 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
1346 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
1347 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
1348 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
1349 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
1350 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
1351 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
1353 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
1355 static void update_variables(bool in_flight)
1357 struct retro_variable var;
1361 var.key = "pcsx_rearmed_frameskip";
1362 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1363 pl_rearmed_cbs.frameskip = atoi(var.value);
1366 var.key = "pcsx_rearmed_region";
1367 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1370 if (strcmp(var.value, "auto") == 0)
1372 else if (strcmp(var.value, "NTSC") == 0)
1374 else if (strcmp(var.value, "PAL") == 0)
1378 for (i = 0; i < PORTS_NUMBER; i++)
1379 update_controller_port_variable(i);
1384 var.key = "pcsx_rearmed_negcon_deadzone";
1385 negcon_deadzone = 0;
1386 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1388 negcon_deadzone = (int)(atoi(var.value) * 0.01f * NEGCON_RANGE);
1392 var.key = "pcsx_rearmed_negcon_response";
1393 negcon_linearity = 1;
1394 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1396 if (strcmp(var.value, "quadratic") == 0){
1397 negcon_linearity = 2;
1398 } else if (strcmp(var.value, "cubic") == 0){
1399 negcon_linearity = 3;
1404 var.key = "pcsx_rearmed_vibration";
1406 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1408 if (strcmp(var.value, "disabled") == 0)
1409 in_enable_vibration = 0;
1410 else if (strcmp(var.value, "enabled") == 0)
1411 in_enable_vibration = 1;
1415 var.key = "pcsx_rearmed_dithering";
1417 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1419 if (strcmp(var.value, "disabled") == 0) {
1420 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
1421 pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 0;
1423 pl_rearmed_cbs.gpu_neon.allow_dithering = 0;
1426 else if (strcmp(var.value, "enabled") == 0) {
1427 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1428 pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1;
1430 pl_rearmed_cbs.gpu_neon.allow_dithering = 1;
1437 var.key = "pcsx_rearmed_neon_interlace_enable";
1439 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1441 if (strcmp(var.value, "disabled") == 0)
1442 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1443 else if (strcmp(var.value, "enabled") == 0)
1444 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1448 var.key = "pcsx_rearmed_neon_enhancement_enable";
1450 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1452 if (strcmp(var.value, "disabled") == 0)
1453 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1454 else if (strcmp(var.value, "enabled") == 0)
1455 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1459 var.key = "pcsx_rearmed_neon_enhancement_no_main";
1461 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1463 if (strcmp(var.value, "disabled") == 0)
1464 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1465 else if (strcmp(var.value, "enabled") == 0)
1466 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1471 var.key = "pcsx_rearmed_duping_enable";
1473 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1475 if (strcmp(var.value, "disabled") == 0)
1476 duping_enable = false;
1477 else if (strcmp(var.value, "enabled") == 0)
1478 duping_enable = true;
1483 var.key = "pcsx_rearmed_drc";
1485 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1487 R3000Acpu *prev_cpu = psxCpu;
1491 Config.Cpu = CPU_INTERPRETER;
1494 if (strcmp(var.value, "disabled") == 0)
1495 Config.Cpu = CPU_INTERPRETER;
1496 else if (strcmp(var.value, "enabled") == 0)
1497 Config.Cpu = CPU_DYNAREC;
1499 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1500 if (psxCpu != prev_cpu) {
1501 prev_cpu->Shutdown();
1503 psxCpu->Reset(); // not really a reset..
1509 var.key = "pcsx_rearmed_spu_reverb";
1511 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1513 if (strcmp(var.value, "disabled") == 0)
1514 spu_config.iUseReverb = false;
1515 else if (strcmp(var.value, "enabled") == 0)
1516 spu_config.iUseReverb = true;
1520 var.key = "pcsx_rearmed_spu_interpolation";
1522 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1524 if (strcmp(var.value, "simple") == 0)
1525 spu_config.iUseInterpolation = 1;
1526 else if (strcmp(var.value, "gaussian") == 0)
1527 spu_config.iUseInterpolation = 2;
1528 else if (strcmp(var.value, "cubic") == 0)
1529 spu_config.iUseInterpolation = 3;
1530 else if (strcmp(var.value, "off") == 0)
1531 spu_config.iUseInterpolation = 0;
1535 var.key = "pcsx_rearmed_pe2_fix";
1537 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1539 if (strcmp(var.value, "disabled") == 0)
1541 else if (strcmp(var.value, "enabled") == 0)
1546 var.key = "pcsx_rearmed_inuyasha_fix";
1548 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1550 if (strcmp(var.value, "disabled") == 0)
1552 else if (strcmp(var.value, "enabled") == 0)
1557 // inform core things about possible config changes
1558 plugin_call_rearmed_cbs();
1560 if (GPU_open != NULL && GPU_close != NULL) {
1562 GPU_open(&gpuDisp, "PCSX", NULL);
1570 //bootlogo display hack
1573 var.key = "pcsx_rearmed_show_bios_bootlogo";
1574 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1576 if (strcmp(var.value, "enabled") == 0)
1583 // Taken from beetle-psx-libretro
1584 static uint16_t get_analog_button(retro_input_state_t input_state_cb, int player_index, int id)
1588 // NOTE: Analog buttons were added Nov 2017. Not all front-ends support this
1589 // feature (or pre-date it) so we need to handle this in a graceful way.
1591 // First, try and get an analog value using the new libretro API constant
1592 button = input_state_cb(player_index,
1593 RETRO_DEVICE_ANALOG,
1594 RETRO_DEVICE_INDEX_ANALOG_BUTTON,
1596 button = MIN(button / 128, 255);
1600 // If we got exactly zero, we're either not pressing the button, or the front-end
1601 // is not reporting analog values. We need to do a second check using the classic
1602 // digital API method, to at least get some response - better than nothing.
1604 // NOTE: If we're really just not holding the button, we're still going to get zero.
1606 button = input_state_cb(player_index,
1607 RETRO_DEVICE_JOYPAD,
1615 void retro_run(void)
1618 //SysReset must be run while core is running,Not in menu (Locks up Retroarch)
1626 bool updated = false;
1627 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1628 update_variables(true);
1630 // reset all keystate, query libretro for keystate
1633 float negcon_twist_amplitude;
1634 for(i = 0; i < PORTS_NUMBER; i++) {
1637 if (in_type[i] == PSE_PAD_TYPE_NONE)
1640 if (in_type[i] == PSE_PAD_TYPE_NEGCON)
1642 // Query digital inputs
1645 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP)){
1646 in_keystate[i] |= (1 << DKEY_UP);
1649 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT)){
1650 in_keystate[i] |= (1 << DKEY_RIGHT);
1653 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN)){
1654 in_keystate[i] |= (1 << DKEY_DOWN);
1657 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT)){
1658 in_keystate[i] |= (1 << DKEY_LEFT);
1661 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START)){
1662 in_keystate[i] |= (1 << DKEY_START);
1665 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A)){
1666 in_keystate[i] |= (1 << DKEY_CIRCLE);
1669 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X)){
1670 in_keystate[i] |= (1 << DKEY_TRIANGLE);
1672 // > neGcon R shoulder (digital)
1673 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R)){
1674 in_keystate[i] |= (1 << DKEY_R1);
1676 // Query analog inputs
1678 // From studying 'libpcsxcore/plugins.c' and 'frontend/plugin.c':
1679 // >> pad->leftJoyX == in_analog_left[i][0] == NeGcon II
1680 // >> pad->leftJoyY == in_analog_left[i][1] == NeGcon L
1681 // >> pad->rightJoyX == in_analog_right[i][0] == NeGcon twist
1682 // >> pad->rightJoyY == in_analog_right[i][1] == NeGcon I
1683 // So we just have to map in_analog_left/right to more
1684 // appropriate inputs...
1687 // >> Get raw analog stick value and account for deadzone
1688 lsx = input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
1689 if (lsx > negcon_deadzone){
1690 lsx = lsx - negcon_deadzone;
1691 } else if (lsx < -negcon_deadzone){
1692 lsx = lsx + negcon_deadzone;
1696 // >> Convert to an 'amplitude' [-1.0,1.0] and adjust response
1697 negcon_twist_amplitude = (float)lsx / (float)(NEGCON_RANGE - negcon_deadzone);
1698 if (negcon_linearity == 2){
1699 if (negcon_twist_amplitude < 0.0){
1700 negcon_twist_amplitude = -(negcon_twist_amplitude * negcon_twist_amplitude);
1702 negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude;
1704 } else if (negcon_linearity == 3){
1705 negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude * negcon_twist_amplitude;
1707 // >> Convert to final 'in_analog' integer value [0,255]
1708 in_analog_right[i][0] = MAX(MIN((int)(negcon_twist_amplitude * 128.0f) + 128, 255), 0);
1710 in_analog_right[i][1] = MAX(
1711 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_R2),
1712 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_B)
1715 in_analog_left[i][0] = MAX(
1716 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_L2),
1717 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_Y)
1720 in_analog_left[i][1] = get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_L);
1724 // Query digital inputs
1725 for (j = 0; j < RETRO_PSX_MAP_LEN; j++){
1726 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j)){
1727 in_keystate[i] |= retro_psx_map[j];
1730 // Query analog inputs
1731 if (in_type[i] == PSE_PAD_TYPE_ANALOGPAD)
1733 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);
1734 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);
1735 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);
1736 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);
1744 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf_ptr : NULL,
1745 vout_width, vout_height, vout_width * 2);
1751 static bool try_use_bios(const char *path)
1757 f = fopen(path, "rb");
1761 fseek(f, 0, SEEK_END);
1765 if (size != 512 * 1024)
1768 name = strrchr(path, SLASH);
1771 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1776 #include <sys/types.h>
1779 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1785 dir = opendir(dirpath);
1789 while ((ent = readdir(dir))) {
1790 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1793 snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name);
1794 ret = try_use_bios(path);
1802 #define find_any_bios(...) false
1805 static void check_system_specs(void)
1808 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1811 static int init_memcards(void)
1815 struct retro_variable var = { .key="pcsx_rearmed_memcard2", .value=NULL };
1816 static const char CARD2_FILE[] = "pcsx-card2.mcd";
1819 // Disable memcard 2 by default
1821 init_memcard(Mcd1Data);
1822 // Memcard 2 is managed by the emulator on the filesystem,
1823 // There is no need to initialize Mcd2Data like Mcd1Data.
1825 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
1826 SysPrintf("Memcard 2: %s\n", var.value);
1827 if (memcmp(var.value, "enabled", 7) == 0) {
1828 if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) {
1829 if (strlen(dir) + strlen(CARD2_FILE) + 2 > sizeof(Config.Mcd2)) {
1830 SysPrintf("Path '%s' is too long. Cannot use memcard 2. Use a shorter path.\n", dir);
1834 snprintf(Config.Mcd2, sizeof(Config.Mcd2), "%s/%s", dir, CARD2_FILE);
1835 SysPrintf("Use memcard 2: %s\n", Config.Mcd2);
1838 SysPrintf("Could not get save directory! Could not create memcard 2.");
1846 void retro_init(void)
1848 const char *bios[] = {
1849 "SCPH101", "SCPH7001", "SCPH5501", "SCPH1001",
1850 "scph101", "scph7001", "scph5501", "scph1001"
1859 // magic sauce to make the dynarec work on iOS
1860 syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0);
1864 psxMapHook = pl_3ds_mmap;
1865 psxUnmapHook = pl_3ds_munmap;
1868 if(init_vita_mmap()<0)
1870 psxMapHook = pl_vita_mmap;
1871 psxUnmapHook = pl_vita_munmap;
1873 ret = emu_core_preinit();
1875 /* emu_core_preinit sets the cpu to dynarec */
1877 Config.Cpu = CPU_INTERPRETER;
1879 ret |= init_memcards();
1881 ret |= emu_core_init();
1883 SysPrintf("PCSX init failed.\n");
1888 vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
1889 #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
1890 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1892 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1895 vout_buf_ptr = vout_buf;
1897 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1899 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
1901 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1902 snprintf(path, sizeof(path), "%s%c%s.bin", dir, SLASH, bios[i]);
1903 found_bios = try_use_bios(path);
1909 found_bios = find_any_bios(dir, path, sizeof(path));
1912 SysPrintf("found BIOS file: %s\n", Config.Bios);
1916 SysPrintf("no BIOS files found.\n");
1917 struct retro_message msg =
1919 "No PlayStation BIOS file found - add for better compatibility",
1922 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1925 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1926 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1927 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1929 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1930 * we have to do this because cache misses and some IO penalties
1931 * are not emulated. Warning: changing this may break compatibility. */
1932 cycle_multiplier = 175;
1933 #ifdef HAVE_PRE_ARMV7
1934 cycle_multiplier = 200;
1936 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1937 spu_config.iUseFixedUpdates = 1;
1939 SaveFuncs.open = save_open;
1940 SaveFuncs.read = save_read;
1941 SaveFuncs.write = save_write;
1942 SaveFuncs.seek = save_seek;
1943 SaveFuncs.close = save_close;
1945 update_variables(false);
1946 check_system_specs();
1949 void retro_deinit(void)
1953 linearFree(vout_buf);
1965 #include <psp2/kernel/threadmgr.h>
1966 int usleep (unsigned long us)
1968 sceKernelDelayThread(us);