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|dualshock|negcon" },
468 { "pcsx_rearmed_pad2type", "Pad 2 Type; default|none|standard|analog|dualshock|negcon" },
469 { "pcsx_rearmed_pad3type", "Pad 3 Type; default|none|standard|analog|dualshock|negcon" },
470 { "pcsx_rearmed_pad4type", "Pad 4 Type; default|none|standard|analog|dualshock|negcon" },
471 { "pcsx_rearmed_pad5type", "Pad 5 Type; default|none|standard|analog|dualshock|negcon" },
472 { "pcsx_rearmed_pad6type", "Pad 6 Type; default|none|standard|analog|dualshock|negcon" },
473 { "pcsx_rearmed_pad7type", "Pad 7 Type; default|none|standard|analog|dualshock|negcon" },
474 { "pcsx_rearmed_pad8type", "Pad 8 Type; default|none|standard|analog|dualshock|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_ANALOGJOY;
569 else if (strcmp(var.value, "dualshock") == 0)
570 in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
571 else if (strcmp(var.value, "negcon") == 0)
572 in_type[port] = PSE_PAD_TYPE_NEGCON;
573 else if (strcmp(var.value, "none") == 0)
574 in_type[port] = PSE_PAD_TYPE_NONE;
575 // else 'default' case, do nothing
579 static void update_controller_port_device(unsigned port, unsigned device)
581 if (port >= PORTS_NUMBER)
584 struct retro_variable var;
586 if (!controller_port_variable(port, &var))
589 if (strcmp(var.value, "default") != 0)
594 case RETRO_DEVICE_JOYPAD:
595 in_type[port] = PSE_PAD_TYPE_STANDARD;
597 case RETRO_DEVICE_ANALOG:
598 in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
600 case RETRO_DEVICE_MOUSE:
601 in_type[port] = PSE_PAD_TYPE_MOUSE;
603 case RETRO_DEVICE_LIGHTGUN:
604 in_type[port] = PSE_PAD_TYPE_GUN;
606 case RETRO_DEVICE_NONE:
608 in_type[port] = PSE_PAD_TYPE_NONE;
612 static void update_multitap()
614 struct retro_variable var;
618 var.key = "pcsx_rearmed_multitap1";
620 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
622 if (strcmp(var.value, "enabled") == 0)
624 else if (strcmp(var.value, "disabled") == 0)
634 // If a gamepad is plugged after port 2, we need a first multitap.
636 for (port = 2; port < PORTS_NUMBER; port++)
637 multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE;
641 var.key = "pcsx_rearmed_multitap2";
643 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
645 if (strcmp(var.value, "enabled") == 0)
647 else if (strcmp(var.value, "disabled") == 0)
657 // If a gamepad is plugged after port 4, we need a second multitap.
659 for (port = 4; port < PORTS_NUMBER; port++)
660 multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE;
664 void retro_set_controller_port_device(unsigned port, unsigned device)
666 SysPrintf("port %u device %u",port,device);
668 if (port >= PORTS_NUMBER)
671 update_controller_port_device(port, device);
675 void retro_get_system_info(struct retro_system_info *info)
677 memset(info, 0, sizeof(*info));
678 info->library_name = "PCSX-ReARMed";
680 #define GIT_VERSION ""
682 info->library_version = "r22" GIT_VERSION;
683 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
684 info->need_fullpath = true;
687 void retro_get_system_av_info(struct retro_system_av_info *info)
689 memset(info, 0, sizeof(*info));
690 info->timing.fps = is_pal_mode ? 50 : 60;
691 info->timing.sample_rate = 44100;
692 info->geometry.base_width = 320;
693 info->geometry.base_height = 240;
694 info->geometry.max_width = VOUT_MAX_WIDTH;
695 info->geometry.max_height = VOUT_MAX_HEIGHT;
696 info->geometry.aspect_ratio = 4.0 / 3.0;
700 size_t retro_serialize_size(void)
702 // it's currently 4380651-4397047 bytes,
703 // but have some reserved for future
713 static void *save_open(const char *name, const char *mode)
717 if (name == NULL || mode == NULL)
720 fp = malloc(sizeof(*fp));
724 fp->buf = (char *)name;
726 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
731 static int save_read(void *file, void *buf, u32 len)
733 struct save_fp *fp = file;
734 if (fp == NULL || buf == NULL)
737 memcpy(buf, fp->buf + fp->pos, len);
742 static int save_write(void *file, const void *buf, u32 len)
744 struct save_fp *fp = file;
745 if (fp == NULL || buf == NULL)
748 memcpy(fp->buf + fp->pos, buf, len);
753 static long save_seek(void *file, long offs, int whence)
755 struct save_fp *fp = file;
771 static void save_close(void *file)
773 struct save_fp *fp = file;
774 size_t r_size = retro_serialize_size();
778 if (fp->pos > r_size)
779 SysPrintf("ERROR: save buffer overflow detected\n");
780 else if (fp->is_write && fp->pos < r_size)
781 // make sure we don't save trash in leftover space
782 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
786 bool retro_serialize(void *data, size_t size)
788 int ret = SaveState(data);
789 return ret == 0 ? true : false;
792 bool retro_unserialize(const void *data, size_t size)
794 int ret = LoadState(data);
795 return ret == 0 ? true : false;
799 void retro_cheat_reset(void)
804 void retro_cheat_set(unsigned index, bool enabled, const char *code)
809 // cheat funcs are destructive, need a copy..
810 strncpy(buf, code, sizeof(buf));
811 buf[sizeof(buf) - 1] = 0;
813 //Prepare buffered cheat for PCSX's AddCheat fucntion.
828 if (index < NumCheats)
829 ret = EditCheat(index, "", buf);
831 ret = AddCheat("", buf);
834 SysPrintf("Failed to set cheat %#u\n", index);
835 else if (index < NumCheats)
836 Cheats[index].Enabled = enabled;
839 /* multidisk support */
840 static bool disk_ejected;
841 static unsigned int disk_current_index;
842 static unsigned int disk_count;
843 static struct disks_state {
845 int internal_index; // for multidisk eboots
848 static bool disk_set_eject_state(bool ejected)
851 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
854 disk_ejected = ejected;
858 static bool disk_get_eject_state(void)
860 /* can't be controlled by emulated software */
864 static unsigned int disk_get_image_index(void)
866 return disk_current_index;
869 static bool disk_set_image_index(unsigned int index)
871 if (index >= sizeof(disks) / sizeof(disks[0]))
875 CdromLabel[0] = '\0';
877 if (disks[index].fname == NULL) {
878 SysPrintf("missing disk #%u\n", index);
881 // RetroArch specifies "no disk" with index == count,
882 // so don't fail here..
883 disk_current_index = index;
887 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
888 disks[index].fname, disks[index].internal_index);
890 cdrIsoMultidiskSelect = disks[index].internal_index;
891 set_cd_image(disks[index].fname);
892 if (ReloadCdromPlugin() < 0) {
893 SysPrintf("failed to load cdr plugin\n");
896 if (CDR_open() < 0) {
897 SysPrintf("failed to open cdr plugin\n");
902 SetCdOpenCaseTime(time(NULL) + 2);
906 disk_current_index = index;
910 static unsigned int disk_get_num_images(void)
915 static bool disk_replace_image_index(unsigned index,
916 const struct retro_game_info *info)
921 if (index >= sizeof(disks) / sizeof(disks[0]))
924 old_fname = disks[index].fname;
925 disks[index].fname = NULL;
926 disks[index].internal_index = 0;
929 disks[index].fname = strdup(info->path);
930 if (index == disk_current_index)
931 ret = disk_set_image_index(index);
934 if (old_fname != NULL)
940 static bool disk_add_image_index(void)
949 static struct retro_disk_control_callback disk_control = {
950 .set_eject_state = disk_set_eject_state,
951 .get_eject_state = disk_get_eject_state,
952 .get_image_index = disk_get_image_index,
953 .set_image_index = disk_set_image_index,
954 .get_num_images = disk_get_num_images,
955 .replace_image_index = disk_replace_image_index,
956 .add_image_index = disk_add_image_index,
959 // just in case, maybe a win-rt port in the future?
967 #define PATH_MAX 4096
970 static char base_dir[PATH_MAX];
972 static bool read_m3u(const char *file)
976 FILE *f = fopen(file, "r");
980 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
983 char *carrige_return = strchr(line, '\r');
985 *carrige_return = '\0';
986 char *newline = strchr(line, '\n');
992 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
993 disks[disk_count++].fname = strdup(name);
998 return (disk_count != 0);
1001 static void extract_directory(char *buf, const char *path, size_t size)
1004 strncpy(buf, path, size - 1);
1005 buf[size - 1] = '\0';
1007 base = strrchr(buf, '/');
1009 base = strrchr(buf, '\\');
1020 #if defined(__QNX__) || defined(_WIN32)
1021 /* Blackberry QNX doesn't have strcasestr */
1024 * Find the first occurrence of find in s, ignore case.
1027 strcasestr(const char *s, const char*find)
1032 if ((c = *find++) != 0) {
1033 c = tolower((unsigned char)c);
1037 if ((sc = *s++) == 0)
1039 } while ((char)tolower((unsigned char)sc) != c);
1040 } while (strncasecmp(s, find, len) != 0);
1047 bool retro_load_game(const struct retro_game_info *info)
1050 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
1052 struct retro_input_descriptor desc[] = {
1053 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1054 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1055 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1056 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1057 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1058 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1059 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1060 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1061 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1062 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1063 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1064 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1065 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1066 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1067 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1068 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1069 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1070 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1071 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1072 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1075 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1076 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1077 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1078 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1079 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1080 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1081 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1082 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1083 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1084 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1085 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1086 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1087 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1088 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1089 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1090 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1091 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1092 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1093 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1094 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1096 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1097 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1098 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1099 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1100 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1101 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1102 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1103 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1104 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1105 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1106 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1107 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1108 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1109 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1110 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1111 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1112 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1113 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1114 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1115 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1117 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1118 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1119 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1120 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1121 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1122 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1123 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1124 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1125 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1126 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1127 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1128 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1129 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1130 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1131 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1132 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1133 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1134 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1135 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1136 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1138 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1139 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1140 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1141 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1142 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1143 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1144 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1145 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1146 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1147 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1148 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1149 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1150 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1151 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1152 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1153 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1154 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1155 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1156 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1157 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1159 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1160 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1161 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1162 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1163 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1164 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1165 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1166 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1167 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1168 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1169 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1170 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1171 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1172 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1173 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1174 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1175 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1176 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1177 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1178 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1180 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1181 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1182 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1183 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1184 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1185 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1186 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1187 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1188 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1189 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1190 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1191 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1192 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1193 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1194 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1195 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1196 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1197 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1198 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1199 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1201 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1202 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1203 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1204 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1205 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1206 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1207 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1208 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1209 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1210 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1211 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1212 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1213 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1214 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1215 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1216 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1217 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1218 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1219 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1220 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1225 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
1227 #ifdef FRONTEND_SUPPORTS_RGB565
1228 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
1229 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
1230 SysPrintf("RGB565 supported, using it\n");
1234 if (info == NULL || info->path == NULL) {
1235 SysPrintf("info->path required\n");
1239 if (plugins_opened) {
1244 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
1245 if (disks[i].fname != NULL) {
1246 free(disks[i].fname);
1247 disks[i].fname = NULL;
1249 disks[i].internal_index = 0;
1252 disk_current_index = 0;
1253 extract_directory(base_dir, info->path, sizeof(base_dir));
1256 if (!read_m3u(info->path)) {
1257 log_cb(RETRO_LOG_INFO, "failed to read m3u file\n");
1262 disks[0].fname = strdup(info->path);
1265 set_cd_image(disks[0].fname);
1267 /* have to reload after set_cd_image for correct cdr plugin */
1268 if (LoadPlugins() == -1) {
1269 log_cb(RETRO_LOG_INFO, "failed to load plugins\n");
1276 if (OpenPlugins() == -1) {
1277 log_cb(RETRO_LOG_INFO, "failed to open plugins\n");
1281 plugin_call_rearmed_cbs();
1284 if (CheckCdrom() == -1) {
1285 log_cb(RETRO_LOG_INFO, "unsupported/invalid CD image: %s\n", info->path);
1291 if (LoadCdrom() == -1) {
1292 log_cb(RETRO_LOG_INFO, "could not load CD\n");
1299 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
1300 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
1301 disks[i].fname = strdup(info->path);
1302 disks[i].internal_index = i;
1309 unsigned retro_get_region(void)
1311 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
1314 void *retro_get_memory_data(unsigned id)
1316 if (id == RETRO_MEMORY_SAVE_RAM)
1322 size_t retro_get_memory_size(unsigned id)
1324 if (id == RETRO_MEMORY_SAVE_RAM)
1330 void retro_reset(void)
1332 //hack to prevent retroarch freezing when reseting in the menu but not while running with the hot key
1337 static const unsigned short retro_psx_map[] = {
1338 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
1339 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
1340 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
1341 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
1342 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
1343 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
1344 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
1345 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
1346 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
1347 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
1348 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
1349 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
1350 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
1351 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
1352 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
1353 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
1355 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
1357 static void update_variables(bool in_flight)
1359 struct retro_variable var;
1363 var.key = "pcsx_rearmed_frameskip";
1364 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1365 pl_rearmed_cbs.frameskip = atoi(var.value);
1368 var.key = "pcsx_rearmed_region";
1369 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1372 if (strcmp(var.value, "auto") == 0)
1374 else if (strcmp(var.value, "NTSC") == 0)
1376 else if (strcmp(var.value, "PAL") == 0)
1380 for (i = 0; i < PORTS_NUMBER; i++)
1381 update_controller_port_variable(i);
1386 var.key = "pcsx_rearmed_negcon_deadzone";
1387 negcon_deadzone = 0;
1388 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1390 negcon_deadzone = (int)(atoi(var.value) * 0.01f * NEGCON_RANGE);
1394 var.key = "pcsx_rearmed_negcon_response";
1395 negcon_linearity = 1;
1396 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1398 if (strcmp(var.value, "quadratic") == 0){
1399 negcon_linearity = 2;
1400 } else if (strcmp(var.value, "cubic") == 0){
1401 negcon_linearity = 3;
1406 var.key = "pcsx_rearmed_vibration";
1408 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1410 if (strcmp(var.value, "disabled") == 0)
1411 in_enable_vibration = 0;
1412 else if (strcmp(var.value, "enabled") == 0)
1413 in_enable_vibration = 1;
1417 var.key = "pcsx_rearmed_dithering";
1419 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1421 if (strcmp(var.value, "disabled") == 0) {
1422 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
1423 pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 0;
1425 pl_rearmed_cbs.gpu_neon.allow_dithering = 0;
1428 else if (strcmp(var.value, "enabled") == 0) {
1429 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1430 pl_rearmed_cbs.gpu_peopsgl.bDrawDither = 1;
1432 pl_rearmed_cbs.gpu_neon.allow_dithering = 1;
1439 var.key = "pcsx_rearmed_neon_interlace_enable";
1441 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1443 if (strcmp(var.value, "disabled") == 0)
1444 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1445 else if (strcmp(var.value, "enabled") == 0)
1446 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1450 var.key = "pcsx_rearmed_neon_enhancement_enable";
1452 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1454 if (strcmp(var.value, "disabled") == 0)
1455 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1456 else if (strcmp(var.value, "enabled") == 0)
1457 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1461 var.key = "pcsx_rearmed_neon_enhancement_no_main";
1463 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1465 if (strcmp(var.value, "disabled") == 0)
1466 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1467 else if (strcmp(var.value, "enabled") == 0)
1468 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1473 var.key = "pcsx_rearmed_duping_enable";
1475 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1477 if (strcmp(var.value, "disabled") == 0)
1478 duping_enable = false;
1479 else if (strcmp(var.value, "enabled") == 0)
1480 duping_enable = true;
1485 var.key = "pcsx_rearmed_drc";
1487 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1489 R3000Acpu *prev_cpu = psxCpu;
1493 Config.Cpu = CPU_INTERPRETER;
1496 if (strcmp(var.value, "disabled") == 0)
1497 Config.Cpu = CPU_INTERPRETER;
1498 else if (strcmp(var.value, "enabled") == 0)
1499 Config.Cpu = CPU_DYNAREC;
1501 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1502 if (psxCpu != prev_cpu) {
1503 prev_cpu->Shutdown();
1505 psxCpu->Reset(); // not really a reset..
1511 var.key = "pcsx_rearmed_spu_reverb";
1513 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1515 if (strcmp(var.value, "disabled") == 0)
1516 spu_config.iUseReverb = false;
1517 else if (strcmp(var.value, "enabled") == 0)
1518 spu_config.iUseReverb = true;
1522 var.key = "pcsx_rearmed_spu_interpolation";
1524 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1526 if (strcmp(var.value, "simple") == 0)
1527 spu_config.iUseInterpolation = 1;
1528 else if (strcmp(var.value, "gaussian") == 0)
1529 spu_config.iUseInterpolation = 2;
1530 else if (strcmp(var.value, "cubic") == 0)
1531 spu_config.iUseInterpolation = 3;
1532 else if (strcmp(var.value, "off") == 0)
1533 spu_config.iUseInterpolation = 0;
1537 var.key = "pcsx_rearmed_pe2_fix";
1539 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1541 if (strcmp(var.value, "disabled") == 0)
1543 else if (strcmp(var.value, "enabled") == 0)
1548 var.key = "pcsx_rearmed_inuyasha_fix";
1550 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1552 if (strcmp(var.value, "disabled") == 0)
1554 else if (strcmp(var.value, "enabled") == 0)
1559 // inform core things about possible config changes
1560 plugin_call_rearmed_cbs();
1562 if (GPU_open != NULL && GPU_close != NULL) {
1564 GPU_open(&gpuDisp, "PCSX", NULL);
1572 //bootlogo display hack
1575 var.key = "pcsx_rearmed_show_bios_bootlogo";
1576 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1578 if (strcmp(var.value, "enabled") == 0)
1585 // Taken from beetle-psx-libretro
1586 static uint16_t get_analog_button(retro_input_state_t input_state_cb, int player_index, int id)
1590 // NOTE: Analog buttons were added Nov 2017. Not all front-ends support this
1591 // feature (or pre-date it) so we need to handle this in a graceful way.
1593 // First, try and get an analog value using the new libretro API constant
1594 button = input_state_cb(player_index,
1595 RETRO_DEVICE_ANALOG,
1596 RETRO_DEVICE_INDEX_ANALOG_BUTTON,
1598 button = MIN(button / 128, 255);
1602 // If we got exactly zero, we're either not pressing the button, or the front-end
1603 // is not reporting analog values. We need to do a second check using the classic
1604 // digital API method, to at least get some response - better than nothing.
1606 // NOTE: If we're really just not holding the button, we're still going to get zero.
1608 button = input_state_cb(player_index,
1609 RETRO_DEVICE_JOYPAD,
1617 void retro_run(void)
1620 //SysReset must be run while core is running,Not in menu (Locks up Retroarch)
1628 bool updated = false;
1629 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1630 update_variables(true);
1632 // reset all keystate, query libretro for keystate
1636 float negcon_twist_amplitude;
1639 for(i = 0; i < PORTS_NUMBER; i++) {
1642 if (in_type[i] == PSE_PAD_TYPE_NONE)
1645 if (in_type[i] == PSE_PAD_TYPE_NEGCON)
1647 // Query digital inputs
1650 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP)){
1651 in_keystate[i] |= (1 << DKEY_UP);
1654 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT)){
1655 in_keystate[i] |= (1 << DKEY_RIGHT);
1658 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN)){
1659 in_keystate[i] |= (1 << DKEY_DOWN);
1662 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT)){
1663 in_keystate[i] |= (1 << DKEY_LEFT);
1666 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START)){
1667 in_keystate[i] |= (1 << DKEY_START);
1670 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A)){
1671 in_keystate[i] |= (1 << DKEY_CIRCLE);
1674 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X)){
1675 in_keystate[i] |= (1 << DKEY_TRIANGLE);
1677 // > neGcon R shoulder (digital)
1678 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R)){
1679 in_keystate[i] |= (1 << DKEY_R1);
1681 // Query analog inputs
1683 // From studying 'libpcsxcore/plugins.c' and 'frontend/plugin.c':
1684 // >> pad->leftJoyX == in_analog_left[i][0] == NeGcon II
1685 // >> pad->leftJoyY == in_analog_left[i][1] == NeGcon L
1686 // >> pad->rightJoyX == in_analog_right[i][0] == NeGcon twist
1687 // >> pad->rightJoyY == in_analog_right[i][1] == NeGcon I
1688 // So we just have to map in_analog_left/right to more
1689 // appropriate inputs...
1692 // >> Get raw analog stick value and account for deadzone
1693 lsx = input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X);
1694 if (lsx > negcon_deadzone){
1695 lsx = lsx - negcon_deadzone;
1696 } else if (lsx < -negcon_deadzone){
1697 lsx = lsx + negcon_deadzone;
1701 // >> Convert to an 'amplitude' [-1.0,1.0] and adjust response
1702 negcon_twist_amplitude = (float)lsx / (float)(NEGCON_RANGE - negcon_deadzone);
1703 if (negcon_linearity == 2){
1704 if (negcon_twist_amplitude < 0.0){
1705 negcon_twist_amplitude = -(negcon_twist_amplitude * negcon_twist_amplitude);
1707 negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude;
1709 } else if (negcon_linearity == 3){
1710 negcon_twist_amplitude = negcon_twist_amplitude * negcon_twist_amplitude * negcon_twist_amplitude;
1712 // >> Convert to final 'in_analog' integer value [0,255]
1713 in_analog_right[i][0] = MAX(MIN((int)(negcon_twist_amplitude * 128.0f) + 128, 255), 0);
1715 // >> Handle right analog stick vertical axis mapping...
1716 // - Up (-Y) == accelerate == neGcon I
1717 // - Down (+Y) == brake == neGcon II
1720 rsy = input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y);
1722 // Account for deadzone
1723 // (Note: have never encountered a gamepad with significant differences
1724 // in deadzone between left/right analog sticks, so use the regular 'twist'
1726 if (rsy > negcon_deadzone){
1727 rsy = rsy - negcon_deadzone;
1731 // Convert to 'in_analog' integer value [0,255]
1732 negcon_ii_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255);
1734 if (rsy < -negcon_deadzone){
1735 rsy = -1 * (rsy + negcon_deadzone);
1739 negcon_i_rs = MIN((int)(((float)rsy / (float)(NEGCON_RANGE - negcon_deadzone)) * 255.0f), 255);
1742 in_analog_right[i][1] = MAX(
1744 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_R2),
1745 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_B)
1750 in_analog_left[i][0] = MAX(
1752 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_L2),
1753 get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_Y)
1758 in_analog_left[i][1] = get_analog_button(input_state_cb, i, RETRO_DEVICE_ID_JOYPAD_L);
1762 // Query digital inputs
1763 for (j = 0; j < RETRO_PSX_MAP_LEN; j++){
1764 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j)){
1765 in_keystate[i] |= retro_psx_map[j];
1768 // Query analog inputs
1769 if (in_type[i] == PSE_PAD_TYPE_ANALOGJOY || in_type[i] == PSE_PAD_TYPE_ANALOGPAD)
1771 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);
1772 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);
1773 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);
1774 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);
1782 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf_ptr : NULL,
1783 vout_width, vout_height, vout_width * 2);
1789 static bool try_use_bios(const char *path)
1795 f = fopen(path, "rb");
1799 fseek(f, 0, SEEK_END);
1803 if (size != 512 * 1024)
1806 name = strrchr(path, SLASH);
1809 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1814 #include <sys/types.h>
1817 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1823 dir = opendir(dirpath);
1827 while ((ent = readdir(dir))) {
1828 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1831 snprintf(path, path_size, "%s%c%s", dirpath, SLASH, ent->d_name);
1832 ret = try_use_bios(path);
1840 #define find_any_bios(...) false
1843 static void check_system_specs(void)
1846 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1849 static int init_memcards(void)
1853 struct retro_variable var = { .key="pcsx_rearmed_memcard2", .value=NULL };
1854 static const char CARD2_FILE[] = "pcsx-card2.mcd";
1857 // Disable memcard 2 by default
1859 init_memcard(Mcd1Data);
1860 // Memcard 2 is managed by the emulator on the filesystem,
1861 // There is no need to initialize Mcd2Data like Mcd1Data.
1863 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
1864 SysPrintf("Memcard 2: %s\n", var.value);
1865 if (memcmp(var.value, "enabled", 7) == 0) {
1866 if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) {
1867 if (strlen(dir) + strlen(CARD2_FILE) + 2 > sizeof(Config.Mcd2)) {
1868 SysPrintf("Path '%s' is too long. Cannot use memcard 2. Use a shorter path.\n", dir);
1872 snprintf(Config.Mcd2, sizeof(Config.Mcd2), "%s/%s", dir, CARD2_FILE);
1873 SysPrintf("Use memcard 2: %s\n", Config.Mcd2);
1876 SysPrintf("Could not get save directory! Could not create memcard 2.");
1884 void retro_init(void)
1886 const char *bios[] = {
1887 "SCPH101", "SCPH7001", "SCPH5501", "SCPH1001",
1888 "scph101", "scph7001", "scph5501", "scph1001"
1897 // magic sauce to make the dynarec work on iOS
1898 syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0);
1902 psxMapHook = pl_3ds_mmap;
1903 psxUnmapHook = pl_3ds_munmap;
1906 if(init_vita_mmap()<0)
1908 psxMapHook = pl_vita_mmap;
1909 psxUnmapHook = pl_vita_munmap;
1911 ret = emu_core_preinit();
1913 /* emu_core_preinit sets the cpu to dynarec */
1915 Config.Cpu = CPU_INTERPRETER;
1917 ret |= init_memcards();
1919 ret |= emu_core_init();
1921 SysPrintf("PCSX init failed.\n");
1926 vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
1927 #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
1928 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1930 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1933 vout_buf_ptr = vout_buf;
1935 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1937 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
1939 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1940 snprintf(path, sizeof(path), "%s%c%s.bin", dir, SLASH, bios[i]);
1941 found_bios = try_use_bios(path);
1947 found_bios = find_any_bios(dir, path, sizeof(path));
1950 SysPrintf("found BIOS file: %s\n", Config.Bios);
1954 SysPrintf("no BIOS files found.\n");
1955 struct retro_message msg =
1957 "No PlayStation BIOS file found - add for better compatibility",
1960 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1963 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1964 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1965 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1967 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1968 * we have to do this because cache misses and some IO penalties
1969 * are not emulated. Warning: changing this may break compatibility. */
1970 cycle_multiplier = 175;
1971 #ifdef HAVE_PRE_ARMV7
1972 cycle_multiplier = 200;
1974 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1975 spu_config.iUseFixedUpdates = 1;
1977 SaveFuncs.open = save_open;
1978 SaveFuncs.read = save_read;
1979 SaveFuncs.write = save_write;
1980 SaveFuncs.seek = save_seek;
1981 SaveFuncs.close = save_close;
1983 update_variables(false);
1984 check_system_specs();
1987 void retro_deinit(void)
1991 linearFree(vout_buf);
2003 #include <psp2/kernel/threadmgr.h>
2004 int usleep (unsigned long us)
2006 sceKernelDelayThread(us);