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
14 #include "../libpcsxcore/misc.h"
15 #include "../libpcsxcore/psxcounters.h"
16 #include "../libpcsxcore/psxmem_map.h"
17 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
18 #include "../libpcsxcore/cdrom.h"
19 #include "../libpcsxcore/cdriso.h"
20 #include "../libpcsxcore/cheat.h"
21 #include "../plugins/dfsound/out.h"
22 #include "../plugins/dfsound/spu_config.h"
23 #include "../plugins/dfinput/externals.h"
27 #include "plugin_lib.h"
28 #include "arm_features.h"
33 #include "3ds/3ds_utils.h"
36 #define PORTS_NUMBER 8
38 static retro_video_refresh_t video_cb;
39 static retro_input_poll_t input_poll_cb;
40 static retro_input_state_t input_state_cb;
41 static retro_environment_t environ_cb;
42 static retro_audio_sample_batch_t audio_batch_cb;
43 static struct retro_rumble_interface rumble;
45 static void *vout_buf;
46 static int vout_width, vout_height;
47 static int vout_doffs_old, vout_fb_dirty;
48 static bool vout_can_dupe;
49 static bool duping_enable;
51 static int plugins_opened;
52 static int is_pal_mode;
54 /* memory card data */
55 extern char Mcd1Data[MCD_SIZE];
56 extern char McdDisable[2];
58 /* PCSX ReARMed core calls and stuff */
59 int in_type[8] = { PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
60 PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
61 PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
62 PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD };
63 int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
64 int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
65 unsigned short in_keystate[PORTS_NUMBER];
68 int in_enable_vibration = 1;
70 /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
71 #define VOUT_MAX_WIDTH 1024
72 #define VOUT_MAX_HEIGHT 512
74 static void init_memcard(char *mcd_data)
79 memset(mcd_data, 0, MCD_SIZE);
81 mcd_data[off++] = 'M';
82 mcd_data[off++] = 'C';
84 mcd_data[off++] = 0x0e;
86 for (i = 0; i < 15; i++) {
87 mcd_data[off++] = 0xa0;
89 mcd_data[off++] = 0xff;
90 mcd_data[off++] = 0xff;
92 mcd_data[off++] = 0xa0;
95 for (i = 0; i < 20; i++) {
96 mcd_data[off++] = 0xff;
97 mcd_data[off++] = 0xff;
98 mcd_data[off++] = 0xff;
99 mcd_data[off++] = 0xff;
101 mcd_data[off++] = 0xff;
102 mcd_data[off++] = 0xff;
107 static int vout_open(void)
112 static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
118 #ifndef FRONTEND_SUPPORTS_RGB565
119 static void convert(void *buf, size_t bytes)
121 unsigned int i, v, *p = buf;
123 for (i = 0; i < bytes / 4; i++) {
125 p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0);
130 static void vout_flip(const void *vram, int stride, int bgr24, int w, int h)
132 unsigned short *dest = vout_buf;
133 const unsigned short *src = vram;
134 int dstride = vout_width, h1 = h;
139 memset(vout_buf, 0, dstride * h * 2);
143 doffs = (vout_height - h) * dstride;
144 doffs += (dstride - w) / 2 & ~1;
145 if (doffs != vout_doffs_old) {
147 memset(vout_buf, 0, dstride * h * 2);
148 vout_doffs_old = doffs;
154 // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here?
155 for (; h1-- > 0; dest += dstride, src += stride)
157 bgr888_to_rgb565(dest, src, w * 3);
162 for (; h1-- > 0; dest += dstride, src += stride)
164 bgr555_to_rgb565(dest, src, w * 2);
169 #ifndef FRONTEND_SUPPORTS_RGB565
170 convert(vout_buf, vout_width * vout_height * 2);
173 pl_rearmed_cbs.flip_cnt++;
176 static void vout_close(void)
189 psx_map_t custom_psx_maps[] = {
190 {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000
191 {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
192 {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
193 {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000
194 {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000
197 void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
205 psx_map_t* custom_map = custom_psx_maps;
207 for (; custom_map->size; custom_map++)
209 if ((custom_map->size == size) && (custom_map->tag == tag))
211 uint32_t ptr_aligned, tmp;
213 custom_map->buffer = malloc(size + 0x1000);
214 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
216 if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0)
218 SysPrintf("could not map memory @0x%08X\n", custom_map->target_map);
222 return (void*)custom_map->target_map;
230 void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
236 psx_map_t* custom_map = custom_psx_maps;
238 for (; custom_map->size; custom_map++)
240 if ((custom_map->target_map == (uint32_t)ptr))
242 uint32_t ptr_aligned, tmp;
244 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
246 svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3);
248 free(custom_map->buffer);
249 custom_map->buffer = NULL;
259 static void *pl_mmap(unsigned int size)
261 return psxMap(0, size, 0, MAP_TAG_VRAM);
264 static void pl_munmap(void *ptr, unsigned int size)
266 psxUnmap(ptr, size, MAP_TAG_VRAM);
269 struct rearmed_cbs pl_rearmed_cbs = {
270 .pl_vout_open = vout_open,
271 .pl_vout_set_mode = vout_set_mode,
272 .pl_vout_flip = vout_flip,
273 .pl_vout_close = vout_close,
276 /* from psxcounters */
277 .gpu_hcnt = &hSyncCount,
278 .gpu_frame_count = &frame_counter,
281 void pl_frame_limit(void)
283 /* called once per frame, make psxCpu->Execute() above return */
287 void pl_timing_prepare(int is_pal)
289 is_pal_mode = is_pal;
292 void plat_trigger_vibrate(int pad, int low, int high)
294 rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8);
295 rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0);
298 void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
303 static int snd_init(void)
308 static void snd_finish(void)
312 static int snd_busy(void)
317 static void snd_feed(void *buf, int bytes)
319 if (audio_batch_cb != NULL)
320 audio_batch_cb(buf, bytes / 4);
323 void out_register_libretro(struct out_driver *drv)
325 drv->name = "libretro";
326 drv->init = snd_init;
327 drv->finish = snd_finish;
328 drv->busy = snd_busy;
329 drv->feed = snd_feed;
333 void retro_set_environment(retro_environment_t cb)
335 static const struct retro_variable vars[] = {
336 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
337 { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
338 { "pcsx_rearmed_pad1type", "Pad 1 Type; default|none|standard|analog|negcon" },
339 { "pcsx_rearmed_pad2type", "Pad 2 Type; default|none|standard|analog|negcon" },
340 { "pcsx_rearmed_pad3type", "Pad 3 Type; default|none|standard|analog|negcon" },
341 { "pcsx_rearmed_pad4type", "Pad 4 Type; default|none|standard|analog|negcon" },
342 { "pcsx_rearmed_pad5type", "Pad 5 Type; default|none|standard|analog|negcon" },
343 { "pcsx_rearmed_pad6type", "Pad 6 Type; default|none|standard|analog|negcon" },
344 { "pcsx_rearmed_pad7type", "Pad 7 Type; default|none|standard|analog|negcon" },
345 { "pcsx_rearmed_pad8type", "Pad 8 Type; default|none|standard|analog|negcon" },
346 { "pcsx_rearmed_multitap1", "Multitap 1; auto|disabled|enabled" },
347 { "pcsx_rearmed_multitap2", "Multitap 2; auto|disabled|enabled" },
349 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
352 { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
353 { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
354 { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
356 { "pcsx_rearmed_duping_enable", "Frame duping; on|off" },
357 { "pcsx_rearmed_spu_reverb", "Sound: Reverb; on|off" },
358 { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" },
359 { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" },
360 { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" },
366 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
369 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
370 void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
371 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
372 void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
373 void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
375 unsigned retro_api_version(void)
377 return RETRO_API_VERSION;
380 static void update_controller_port_device(unsigned port, unsigned device)
382 if (port >= PORTS_NUMBER)
385 struct retro_variable var;
386 int default_case = 0;
391 var.key = "pcsx_rearmed_pad1type";
394 var.key = "pcsx_rearmed_pad2type";
397 var.key = "pcsx_rearmed_pad3type";
400 var.key = "pcsx_rearmed_pad4type";
403 var.key = "pcsx_rearmed_pad5type";
406 var.key = "pcsx_rearmed_pad6type";
409 var.key = "pcsx_rearmed_pad7type";
412 var.key = "pcsx_rearmed_pad8type";
416 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
418 if (strcmp(var.value, "standard") == 0)
419 in_type[0] = PSE_PAD_TYPE_STANDARD;
420 else if (strcmp(var.value, "analog") == 0)
421 in_type[0] = PSE_PAD_TYPE_ANALOGPAD;
422 else if (strcmp(var.value, "negcon") == 0)
423 in_type[0] = PSE_PAD_TYPE_NEGCON;
424 else if (strcmp(var.value, "none") == 0)
425 in_type[0] = PSE_PAD_TYPE_NONE;
426 else // 'default' case
435 case RETRO_DEVICE_JOYPAD:
436 in_type[port] = PSE_PAD_TYPE_STANDARD;
438 case RETRO_DEVICE_ANALOG:
439 in_type[port] = PSE_PAD_TYPE_ANALOGPAD;
441 case RETRO_DEVICE_MOUSE:
442 in_type[port] = PSE_PAD_TYPE_MOUSE;
444 case RETRO_DEVICE_LIGHTGUN:
445 in_type[port] = PSE_PAD_TYPE_GUN;
447 case RETRO_DEVICE_NONE:
449 in_type[port] = PSE_PAD_TYPE_NONE;
453 static void update_multitap()
455 struct retro_variable var;
459 var.key = "pcsx_rearmed_multitap1";
461 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
463 if (strcmp(var.value, "enabled") == 0)
465 else if (strcmp(var.value, "disabled") == 0)
475 // If a gamepad is plugged after port 2, we need a first multitap.
477 for (int port = 2; port < PORTS_NUMBER; port++)
478 multitap1 |= in_type[port] != PSE_PAD_TYPE_NONE;
482 var.key = "pcsx_rearmed_multitap2";
484 if (environ_cb && (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value))
486 if (strcmp(var.value, "enabled") == 0)
488 else if (strcmp(var.value, "disabled") == 0)
498 // If a gamepad is plugged after port 4, we need a second multitap.
500 for (int port = 4; port < PORTS_NUMBER; port++)
501 multitap2 |= in_type[port] != PSE_PAD_TYPE_NONE;
505 void retro_set_controller_port_device(unsigned port, unsigned device)
507 SysPrintf("port %u device %u",port,device);
509 if (port >= PORTS_NUMBER)
512 update_controller_port_device(port, device);
516 void retro_get_system_info(struct retro_system_info *info)
518 memset(info, 0, sizeof(*info));
519 info->library_name = "PCSX-ReARMed";
520 info->library_version = "r22";
521 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
522 info->need_fullpath = true;
525 void retro_get_system_av_info(struct retro_system_av_info *info)
527 memset(info, 0, sizeof(*info));
528 info->timing.fps = is_pal_mode ? 50 : 60;
529 info->timing.sample_rate = 44100;
530 info->geometry.base_width = 320;
531 info->geometry.base_height = 240;
532 info->geometry.max_width = VOUT_MAX_WIDTH;
533 info->geometry.max_height = VOUT_MAX_HEIGHT;
534 info->geometry.aspect_ratio = 4.0 / 3.0;
538 size_t retro_serialize_size(void)
540 // it's currently 4380651-4397047 bytes,
541 // but have some reserved for future
551 static void *save_open(const char *name, const char *mode)
555 if (name == NULL || mode == NULL)
558 fp = malloc(sizeof(*fp));
562 fp->buf = (char *)name;
564 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
569 static int save_read(void *file, void *buf, u32 len)
571 struct save_fp *fp = file;
572 if (fp == NULL || buf == NULL)
575 memcpy(buf, fp->buf + fp->pos, len);
580 static int save_write(void *file, const void *buf, u32 len)
582 struct save_fp *fp = file;
583 if (fp == NULL || buf == NULL)
586 memcpy(fp->buf + fp->pos, buf, len);
591 static long save_seek(void *file, long offs, int whence)
593 struct save_fp *fp = file;
609 static void save_close(void *file)
611 struct save_fp *fp = file;
612 size_t r_size = retro_serialize_size();
616 if (fp->pos > r_size)
617 SysPrintf("ERROR: save buffer overflow detected\n");
618 else if (fp->is_write && fp->pos < r_size)
619 // make sure we don't save trash in leftover space
620 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
624 bool retro_serialize(void *data, size_t size)
626 int ret = SaveState(data);
627 return ret == 0 ? true : false;
630 bool retro_unserialize(const void *data, size_t size)
632 int ret = LoadState(data);
633 return ret == 0 ? true : false;
637 void retro_cheat_reset(void)
642 void retro_cheat_set(unsigned index, bool enabled, const char *code)
647 // cheat funcs are destructive, need a copy..
648 strncpy(buf, code, sizeof(buf));
649 buf[sizeof(buf) - 1] = 0;
651 if (index < NumCheats)
652 ret = EditCheat(index, "", buf);
654 ret = AddCheat("", buf);
657 SysPrintf("Failed to set cheat %#u\n", index);
658 else if (index < NumCheats)
659 Cheats[index].Enabled = enabled;
662 /* multidisk support */
663 static bool disk_ejected;
664 static unsigned int disk_current_index;
665 static unsigned int disk_count;
666 static struct disks_state {
668 int internal_index; // for multidisk eboots
671 static bool disk_set_eject_state(bool ejected)
674 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
677 disk_ejected = ejected;
681 static bool disk_get_eject_state(void)
683 /* can't be controlled by emulated software */
687 static unsigned int disk_get_image_index(void)
689 return disk_current_index;
692 static bool disk_set_image_index(unsigned int index)
694 if (index >= sizeof(disks) / sizeof(disks[0]))
698 CdromLabel[0] = '\0';
700 if (disks[index].fname == NULL) {
701 SysPrintf("missing disk #%u\n", index);
704 // RetroArch specifies "no disk" with index == count,
705 // so don't fail here..
706 disk_current_index = index;
710 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
711 disks[index].fname, disks[index].internal_index);
713 cdrIsoMultidiskSelect = disks[index].internal_index;
714 set_cd_image(disks[index].fname);
715 if (ReloadCdromPlugin() < 0) {
716 SysPrintf("failed to load cdr plugin\n");
719 if (CDR_open() < 0) {
720 SysPrintf("failed to open cdr plugin\n");
725 SetCdOpenCaseTime(time(NULL) + 2);
729 disk_current_index = index;
733 static unsigned int disk_get_num_images(void)
738 static bool disk_replace_image_index(unsigned index,
739 const struct retro_game_info *info)
744 if (index >= sizeof(disks) / sizeof(disks[0]))
747 old_fname = disks[index].fname;
748 disks[index].fname = NULL;
749 disks[index].internal_index = 0;
752 disks[index].fname = strdup(info->path);
753 if (index == disk_current_index)
754 ret = disk_set_image_index(index);
757 if (old_fname != NULL)
763 static bool disk_add_image_index(void)
772 static struct retro_disk_control_callback disk_control = {
773 .set_eject_state = disk_set_eject_state,
774 .get_eject_state = disk_get_eject_state,
775 .get_image_index = disk_get_image_index,
776 .set_image_index = disk_set_image_index,
777 .get_num_images = disk_get_num_images,
778 .replace_image_index = disk_replace_image_index,
779 .add_image_index = disk_add_image_index,
782 // just in case, maybe a win-rt port in the future?
789 static char base_dir[PATH_MAX];
791 static bool read_m3u(const char *file)
795 FILE *f = fopen(file, "r");
799 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
802 char *carrige_return = strchr(line, '\r');
804 *carrige_return = '\0';
805 char *newline = strchr(line, '\n');
811 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
812 disks[disk_count++].fname = strdup(name);
817 return (disk_count != 0);
820 static void extract_directory(char *buf, const char *path, size_t size)
823 strncpy(buf, path, size - 1);
824 buf[size - 1] = '\0';
826 base = strrchr(buf, '/');
828 base = strrchr(buf, '\\');
839 #if defined(__QNX__) || defined(_WIN32)
840 /* Blackberry QNX doesn't have strcasestr */
843 * Find the first occurrence of find in s, ignore case.
846 strcasestr(const char *s, const char*find)
851 if ((c = *find++) != 0) {
852 c = tolower((unsigned char)c);
856 if ((sc = *s++) == 0)
858 } while ((char)tolower((unsigned char)sc) != c);
859 } while (strncasecmp(s, find, len) != 0);
866 bool retro_load_game(const struct retro_game_info *info)
869 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
871 struct retro_input_descriptor desc[] = {
872 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
873 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
874 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
875 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
876 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
877 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
878 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
879 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
880 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
881 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
882 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
883 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
884 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
885 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
886 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
887 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
888 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
889 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
890 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
891 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
894 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
895 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
896 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
897 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
898 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
899 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
900 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
901 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
902 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
903 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
904 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
905 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
906 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
907 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
908 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
909 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
910 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
911 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
912 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
913 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
915 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
916 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
917 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
918 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
919 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
920 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
921 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
922 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
923 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
924 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
925 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
926 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
927 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
928 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
929 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
930 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
931 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
932 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
933 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
934 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
936 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
937 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
938 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
939 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
940 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
941 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
942 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
943 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
944 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
945 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
946 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
947 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
948 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
949 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
950 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
951 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
952 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
953 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
954 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
955 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
957 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
958 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
959 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
960 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
961 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
962 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
963 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
964 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
965 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
966 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
967 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
968 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
969 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
970 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
971 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
972 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
973 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
974 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
975 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
976 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
978 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
979 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
980 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
981 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
982 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
983 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
984 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
985 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
986 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
987 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
988 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
989 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
990 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
991 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
992 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
993 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
994 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
995 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
996 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
997 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
999 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1000 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1001 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1002 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1003 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1004 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1005 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1006 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1007 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1008 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1009 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1010 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1011 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1012 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1013 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1014 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1015 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1016 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1017 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1018 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1020 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
1021 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
1022 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
1023 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
1024 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
1025 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
1026 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
1027 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
1028 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
1029 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
1030 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
1031 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
1032 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
1033 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
1034 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
1035 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
1036 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
1037 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
1038 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
1039 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
1044 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
1046 #ifdef FRONTEND_SUPPORTS_RGB565
1047 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
1048 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
1049 SysPrintf("RGB565 supported, using it\n");
1053 if (info == NULL || info->path == NULL) {
1054 SysPrintf("info->path required\n");
1058 if (plugins_opened) {
1063 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
1064 if (disks[i].fname != NULL) {
1065 free(disks[i].fname);
1066 disks[i].fname = NULL;
1068 disks[i].internal_index = 0;
1071 disk_current_index = 0;
1072 extract_directory(base_dir, info->path, sizeof(base_dir));
1075 if (!read_m3u(info->path)) {
1076 SysPrintf("failed to read m3u file\n");
1081 disks[0].fname = strdup(info->path);
1084 set_cd_image(disks[0].fname);
1086 /* have to reload after set_cd_image for correct cdr plugin */
1087 if (LoadPlugins() == -1) {
1088 SysPrintf("failed to load plugins\n");
1095 if (OpenPlugins() == -1) {
1096 SysPrintf("failed to open plugins\n");
1100 plugin_call_rearmed_cbs();
1104 if (CheckCdrom() == -1) {
1105 SysPrintf("unsupported/invalid CD image: %s\n", info->path);
1111 if (LoadCdrom() == -1) {
1112 SysPrintf("could not load CD-ROM!\n");
1119 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
1120 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
1121 disks[i].fname = strdup(info->path);
1122 disks[i].internal_index = i;
1129 bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
1134 void retro_unload_game(void)
1138 unsigned retro_get_region(void)
1140 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
1143 void *retro_get_memory_data(unsigned id)
1145 if (id == RETRO_MEMORY_SAVE_RAM)
1151 size_t retro_get_memory_size(unsigned id)
1153 if (id == RETRO_MEMORY_SAVE_RAM)
1159 void retro_reset(void)
1164 static const unsigned short retro_psx_map[] = {
1165 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
1166 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
1167 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
1168 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
1169 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
1170 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
1171 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
1172 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
1173 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
1174 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
1175 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
1176 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
1177 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
1178 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
1179 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
1180 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
1182 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
1184 static void update_variables(bool in_flight)
1186 struct retro_variable var;
1189 var.key = "pcsx_rearmed_frameskip";
1190 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1191 pl_rearmed_cbs.frameskip = atoi(var.value);
1194 var.key = "pcsx_rearmed_region";
1195 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1198 if (strcmp(var.value, "Automatic") == 0)
1200 else if (strcmp(var.value, "NTSC") == 0)
1202 else if (strcmp(var.value, "PAL") == 0)
1206 for (int i = 0; i < PORTS_NUMBER; i++)
1207 update_controller_port_device(i, RETRO_DEVICE_NONE);
1213 var.key = "pcsx_rearmed_neon_interlace_enable";
1215 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1217 if (strcmp(var.value, "disabled") == 0)
1218 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1219 else if (strcmp(var.value, "enabled") == 0)
1220 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1224 var.key = "pcsx_rearmed_neon_enhancement_enable";
1226 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1228 if (strcmp(var.value, "disabled") == 0)
1229 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1230 else if (strcmp(var.value, "enabled") == 0)
1231 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1235 var.key = "pcsx_rearmed_neon_enhancement_no_main";
1237 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1239 if (strcmp(var.value, "disabled") == 0)
1240 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1241 else if (strcmp(var.value, "enabled") == 0)
1242 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1247 var.key = "pcsx_rearmed_duping_enable";
1249 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1251 if (strcmp(var.value, "off") == 0)
1252 duping_enable = false;
1253 else if (strcmp(var.value, "on") == 0)
1254 duping_enable = true;
1259 var.key = "pcsx_rearmed_drc";
1261 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1263 R3000Acpu *prev_cpu = psxCpu;
1267 Config.Cpu = CPU_INTERPRETER;
1270 if (strcmp(var.value, "disabled") == 0)
1271 Config.Cpu = CPU_INTERPRETER;
1272 else if (strcmp(var.value, "enabled") == 0)
1273 Config.Cpu = CPU_DYNAREC;
1275 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1276 if (psxCpu != prev_cpu) {
1277 prev_cpu->Shutdown();
1279 psxCpu->Reset(); // not really a reset..
1285 var.key = "pcsx_rearmed_spu_reverb";
1287 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1289 if (strcmp(var.value, "off") == 0)
1290 spu_config.iUseReverb = false;
1291 else if (strcmp(var.value, "on") == 0)
1292 spu_config.iUseReverb = true;
1296 var.key = "pcsx_rearmed_spu_interpolation";
1298 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1300 if (strcmp(var.value, "simple") == 0)
1301 spu_config.iUseInterpolation = 1;
1302 else if (strcmp(var.value, "gaussian") == 0)
1303 spu_config.iUseInterpolation = 2;
1304 else if (strcmp(var.value, "cubic") == 0)
1305 spu_config.iUseInterpolation = 3;
1306 else if (strcmp(var.value, "off") == 0)
1307 spu_config.iUseInterpolation = 0;
1311 var.key = "pcsx_rearmed_pe2_fix";
1313 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1315 if (strcmp(var.value, "disabled") == 0)
1317 else if (strcmp(var.value, "enabled") == 0)
1322 var.key = "pcsx_rearmed_inuyasha_fix";
1324 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1326 if (strcmp(var.value, "disabled") == 0)
1328 else if (strcmp(var.value, "enabled") == 0)
1333 // inform core things about possible config changes
1334 plugin_call_rearmed_cbs();
1336 if (GPU_open != NULL && GPU_close != NULL) {
1338 GPU_open(&gpuDisp, "PCSX", NULL);
1345 void retro_run(void)
1351 bool updated = false;
1352 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1353 update_variables(true);
1355 // reset all keystate, query libretro for keystate
1357 for(i = 0; i < PORTS_NUMBER; i++) {
1360 if (in_type[i] == PSE_PAD_TYPE_NONE)
1363 // query libretro for keystate
1364 for (j = 0; j < RETRO_PSX_MAP_LEN; j++)
1365 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j))
1366 in_keystate[i] |= retro_psx_map[j];
1368 if (in_type[i] == PSE_PAD_TYPE_ANALOGPAD)
1370 in_analog_left[i][0] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1371 in_analog_left[i][1] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1372 in_analog_right[i][0] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1373 in_analog_right[i][1] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1380 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf : NULL,
1381 vout_width, vout_height, vout_width * 2);
1385 static bool try_use_bios(const char *path)
1391 f = fopen(path, "rb");
1395 fseek(f, 0, SEEK_END);
1399 if (size != 512 * 1024)
1402 name = strrchr(path, SLASH);
1405 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1410 #include <sys/types.h>
1413 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1419 dir = opendir(dirpath);
1423 while ((ent = readdir(dir))) {
1424 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1427 snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
1428 ret = try_use_bios(path);
1436 #define find_any_bios(...) false
1439 static void check_system_specs(void)
1442 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1445 void retro_init(void)
1447 const char *bios[] = { "scph1001", "scph5501", "scph7001" };
1451 bool found_bios = false;
1454 psxMapHook = pl_3ds_mmap;
1455 psxUnmapHook = pl_3ds_munmap;
1457 ret = emu_core_preinit();
1459 /* emu_core_preinit sets the cpu to dynarec */
1461 Config.Cpu = CPU_INTERPRETER;
1463 ret |= emu_core_init();
1465 SysPrintf("PCSX init failed.\n");
1470 vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
1471 #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
1472 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1474 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1477 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1479 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
1481 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1482 snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
1483 found_bios = try_use_bios(path);
1489 found_bios = find_any_bios(dir, path, sizeof(path));
1492 SysPrintf("found BIOS file: %s\n", Config.Bios);
1496 SysPrintf("no BIOS files found.\n");
1497 struct retro_message msg =
1499 "no BIOS found, expect bugs!",
1502 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1505 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1506 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1507 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1509 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1510 * we have to do this because cache misses and some IO penalties
1511 * are not emulated. Warning: changing this may break compatibility. */
1512 cycle_multiplier = 175;
1513 #ifdef HAVE_PRE_ARMV7
1514 cycle_multiplier = 200;
1516 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1517 spu_config.iUseFixedUpdates = 1;
1521 init_memcard(Mcd1Data);
1523 SaveFuncs.open = save_open;
1524 SaveFuncs.read = save_read;
1525 SaveFuncs.write = save_write;
1526 SaveFuncs.seek = save_seek;
1527 SaveFuncs.close = save_close;
1529 update_variables(false);
1530 check_system_specs();
1533 void retro_deinit(void)
1537 linearFree(vout_buf);
1545 #include <psp2/kernel/threadmgr.h>
1546 int usleep (unsigned long us)
1548 sceKernelDelayThread(us);