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"
33 #include "3ds/3ds_utils.h"
34 int ctr_svchack_init_success = 0;
37 static retro_video_refresh_t video_cb;
38 static retro_input_poll_t input_poll_cb;
39 static retro_input_state_t input_state_cb;
40 static retro_environment_t environ_cb;
41 static retro_audio_sample_batch_t audio_batch_cb;
42 static struct retro_rumble_interface rumble;
44 static void *vout_buf;
45 static int vout_width, vout_height;
46 static int vout_doffs_old, vout_fb_dirty;
47 static bool vout_can_dupe;
48 static bool duping_enable;
50 static int plugins_opened;
51 static int is_pal_mode;
53 /* memory card data */
54 extern char Mcd1Data[MCD_SIZE];
55 extern char McdDisable[2];
57 /* PCSX ReARMed core calls and stuff */
58 int in_type1, in_type2;
59 int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 };
60 int in_a3[2] = { 127, 127 }, in_a4[2] = { 127, 127 };
62 int in_enable_vibration = 1;
64 /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
65 #define VOUT_MAX_WIDTH 1024
66 #define VOUT_MAX_HEIGHT 512
68 static void init_memcard(char *mcd_data)
73 memset(mcd_data, 0, MCD_SIZE);
75 mcd_data[off++] = 'M';
76 mcd_data[off++] = 'C';
78 mcd_data[off++] = 0x0e;
80 for (i = 0; i < 15; i++) {
81 mcd_data[off++] = 0xa0;
83 mcd_data[off++] = 0xff;
84 mcd_data[off++] = 0xff;
86 mcd_data[off++] = 0xa0;
89 for (i = 0; i < 20; i++) {
90 mcd_data[off++] = 0xff;
91 mcd_data[off++] = 0xff;
92 mcd_data[off++] = 0xff;
93 mcd_data[off++] = 0xff;
95 mcd_data[off++] = 0xff;
96 mcd_data[off++] = 0xff;
101 static int vout_open(void)
106 static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
112 #ifndef FRONTEND_SUPPORTS_RGB565
113 static void convert(void *buf, size_t bytes)
115 unsigned int i, v, *p = buf;
117 for (i = 0; i < bytes / 4; i++) {
119 p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0);
124 static void vout_flip(const void *vram, int stride, int bgr24, int w, int h)
126 unsigned short *dest = vout_buf;
127 const unsigned short *src = vram;
128 int dstride = vout_width, h1 = h;
133 memset(vout_buf, 0, dstride * h * 2);
137 doffs = (vout_height - h) * dstride;
138 doffs += (dstride - w) / 2 & ~1;
139 if (doffs != vout_doffs_old) {
141 memset(vout_buf, 0, dstride * h * 2);
142 vout_doffs_old = doffs;
148 // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here?
149 for (; h1-- > 0; dest += dstride, src += stride)
151 bgr888_to_rgb565(dest, src, w * 3);
156 for (; h1-- > 0; dest += dstride, src += stride)
158 bgr555_to_rgb565(dest, src, w * 2);
163 #ifndef FRONTEND_SUPPORTS_RGB565
164 convert(vout_buf, vout_width * vout_height * 2);
167 pl_rearmed_cbs.flip_cnt++;
170 static void vout_close(void)
183 psx_map_t custom_psx_maps[] = {
184 {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000
185 {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
186 {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
187 {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000
188 {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000
191 void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
197 if (ctr_svchack_init_success)
199 psx_map_t* custom_map = custom_psx_maps;
201 for (; custom_map->size; custom_map++)
203 if ((custom_map->size == size) && (custom_map->tag == tag))
205 uint32_t ptr_aligned, tmp;
207 custom_map->buffer = malloc(size + 0x1000);
208 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
210 if(svcControlMemory(&tmp, custom_map->target_map, ptr_aligned, size, MEMOP_MAP, 0x3) < 0)
212 SysPrintf("could not map memory @0x%08X\n", custom_map->target_map);
216 return (void*)custom_map->target_map;
224 void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
228 if (ctr_svchack_init_success)
230 psx_map_t* custom_map = custom_psx_maps;
232 for (; custom_map->size; custom_map++)
234 if ((custom_map->target_map == (uint32_t)ptr))
236 uint32_t ptr_aligned, tmp;
238 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
240 svcControlMemory(&tmp, custom_map->target_map, ptr_aligned, size, MEMOP_UNMAP, 0x3);
242 free(custom_map->buffer);
243 custom_map->buffer = NULL;
253 static void *pl_mmap(unsigned int size)
255 return psxMap(0, size, 0, MAP_TAG_VRAM);
258 static void pl_munmap(void *ptr, unsigned int size)
260 psxUnmap(ptr, size, MAP_TAG_VRAM);
263 struct rearmed_cbs pl_rearmed_cbs = {
264 .pl_vout_open = vout_open,
265 .pl_vout_set_mode = vout_set_mode,
266 .pl_vout_flip = vout_flip,
267 .pl_vout_close = vout_close,
270 /* from psxcounters */
271 .gpu_hcnt = &hSyncCount,
272 .gpu_frame_count = &frame_counter,
275 void pl_frame_limit(void)
277 /* called once per frame, make psxCpu->Execute() above return */
281 void pl_timing_prepare(int is_pal)
283 is_pal_mode = is_pal;
286 void plat_trigger_vibrate(int pad, int low, int high)
288 rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8);
289 rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0);
292 void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
297 static int snd_init(void)
302 static void snd_finish(void)
306 static int snd_busy(void)
311 static void snd_feed(void *buf, int bytes)
313 if (audio_batch_cb != NULL)
314 audio_batch_cb(buf, bytes / 4);
317 void out_register_libretro(struct out_driver *drv)
319 drv->name = "libretro";
320 drv->init = snd_init;
321 drv->finish = snd_finish;
322 drv->busy = snd_busy;
323 drv->feed = snd_feed;
327 void retro_set_environment(retro_environment_t cb)
329 static const struct retro_variable vars[] = {
330 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
331 { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
332 { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog" },
333 { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog" },
335 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
338 { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
339 { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
340 { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
342 { "pcsx_rearmed_duping_enable", "Frame duping; on|off" },
343 { "pcsx_rearmed_spu_reverb", "Sound: Reverb; on|off" },
344 { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" },
345 { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" },
346 { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" },
352 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
355 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
356 void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
357 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
358 void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
359 void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
361 unsigned retro_api_version(void)
363 return RETRO_API_VERSION;
366 void retro_set_controller_port_device(unsigned port, unsigned device)
370 void retro_get_system_info(struct retro_system_info *info)
372 memset(info, 0, sizeof(*info));
373 info->library_name = "PCSX-ReARMed";
374 info->library_version = "r22";
375 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
376 info->need_fullpath = true;
379 void retro_get_system_av_info(struct retro_system_av_info *info)
381 memset(info, 0, sizeof(*info));
382 info->timing.fps = is_pal_mode ? 50 : 60;
383 info->timing.sample_rate = 44100;
384 info->geometry.base_width = 320;
385 info->geometry.base_height = 240;
386 info->geometry.max_width = VOUT_MAX_WIDTH;
387 info->geometry.max_height = VOUT_MAX_HEIGHT;
388 info->geometry.aspect_ratio = 4.0 / 3.0;
392 size_t retro_serialize_size(void)
394 // it's currently 4380651-4397047 bytes,
395 // but have some reserved for future
405 static void *save_open(const char *name, const char *mode)
409 if (name == NULL || mode == NULL)
412 fp = malloc(sizeof(*fp));
416 fp->buf = (char *)name;
418 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
423 static int save_read(void *file, void *buf, u32 len)
425 struct save_fp *fp = file;
426 if (fp == NULL || buf == NULL)
429 memcpy(buf, fp->buf + fp->pos, len);
434 static int save_write(void *file, const void *buf, u32 len)
436 struct save_fp *fp = file;
437 if (fp == NULL || buf == NULL)
440 memcpy(fp->buf + fp->pos, buf, len);
445 static long save_seek(void *file, long offs, int whence)
447 struct save_fp *fp = file;
463 static void save_close(void *file)
465 struct save_fp *fp = file;
466 size_t r_size = retro_serialize_size();
470 if (fp->pos > r_size)
471 SysPrintf("ERROR: save buffer overflow detected\n");
472 else if (fp->is_write && fp->pos < r_size)
473 // make sure we don't save trash in leftover space
474 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
478 bool retro_serialize(void *data, size_t size)
480 int ret = SaveState(data);
481 return ret == 0 ? true : false;
484 bool retro_unserialize(const void *data, size_t size)
486 int ret = LoadState(data);
487 return ret == 0 ? true : false;
491 void retro_cheat_reset(void)
496 void retro_cheat_set(unsigned index, bool enabled, const char *code)
501 // cheat funcs are destructive, need a copy..
502 strncpy(buf, code, sizeof(buf));
503 buf[sizeof(buf) - 1] = 0;
505 if (index < NumCheats)
506 ret = EditCheat(index, "", buf);
508 ret = AddCheat("", buf);
511 SysPrintf("Failed to set cheat %#u\n", index);
512 else if (index < NumCheats)
513 Cheats[index].Enabled = enabled;
516 /* multidisk support */
517 static bool disk_ejected;
518 static unsigned int disk_current_index;
519 static unsigned int disk_count;
520 static struct disks_state {
522 int internal_index; // for multidisk eboots
525 static bool disk_set_eject_state(bool ejected)
528 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
531 disk_ejected = ejected;
535 static bool disk_get_eject_state(void)
537 /* can't be controlled by emulated software */
541 static unsigned int disk_get_image_index(void)
543 return disk_current_index;
546 static bool disk_set_image_index(unsigned int index)
548 if (index >= sizeof(disks) / sizeof(disks[0]))
552 CdromLabel[0] = '\0';
554 if (disks[index].fname == NULL) {
555 SysPrintf("missing disk #%u\n", index);
558 // RetroArch specifies "no disk" with index == count,
559 // so don't fail here..
560 disk_current_index = index;
564 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
565 disks[index].fname, disks[index].internal_index);
567 cdrIsoMultidiskSelect = disks[index].internal_index;
568 set_cd_image(disks[index].fname);
569 if (ReloadCdromPlugin() < 0) {
570 SysPrintf("failed to load cdr plugin\n");
573 if (CDR_open() < 0) {
574 SysPrintf("failed to open cdr plugin\n");
579 SetCdOpenCaseTime(time(NULL) + 2);
583 disk_current_index = index;
587 static unsigned int disk_get_num_images(void)
592 static bool disk_replace_image_index(unsigned index,
593 const struct retro_game_info *info)
598 if (index >= sizeof(disks) / sizeof(disks[0]))
601 old_fname = disks[index].fname;
602 disks[index].fname = NULL;
603 disks[index].internal_index = 0;
606 disks[index].fname = strdup(info->path);
607 if (index == disk_current_index)
608 ret = disk_set_image_index(index);
611 if (old_fname != NULL)
617 static bool disk_add_image_index(void)
626 static struct retro_disk_control_callback disk_control = {
627 .set_eject_state = disk_set_eject_state,
628 .get_eject_state = disk_get_eject_state,
629 .get_image_index = disk_get_image_index,
630 .set_image_index = disk_set_image_index,
631 .get_num_images = disk_get_num_images,
632 .replace_image_index = disk_replace_image_index,
633 .add_image_index = disk_add_image_index,
636 // just in case, maybe a win-rt port in the future?
643 static char base_dir[PATH_MAX];
645 static bool read_m3u(const char *file)
649 FILE *f = fopen(file, "r");
653 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
656 char *carrige_return = strchr(line, '\r');
658 *carrige_return = '\0';
659 char *newline = strchr(line, '\n');
665 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
666 disks[disk_count++].fname = strdup(name);
671 return (disk_count != 0);
674 static void extract_directory(char *buf, const char *path, size_t size)
677 strncpy(buf, path, size - 1);
678 buf[size - 1] = '\0';
680 base = strrchr(buf, '/');
682 base = strrchr(buf, '\\');
693 #if defined(__QNX__) || defined(_WIN32)
694 /* Blackberry QNX doesn't have strcasestr */
697 * Find the first occurrence of find in s, ignore case.
700 strcasestr(const char *s, const char*find)
705 if ((c = *find++) != 0) {
706 c = tolower((unsigned char)c);
710 if ((sc = *s++) == 0)
712 } while ((char)tolower((unsigned char)sc) != c);
713 } while (strncasecmp(s, find, len) != 0);
720 bool retro_load_game(const struct retro_game_info *info)
723 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
725 struct retro_input_descriptor desc[] = {
726 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
727 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
728 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
729 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
730 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
731 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
732 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
733 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
734 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
735 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
736 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
737 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
738 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
739 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
740 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
741 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
742 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
743 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
744 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
745 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
748 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
749 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
750 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
751 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
752 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
753 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
754 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
755 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
756 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
757 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
758 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
759 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
760 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
761 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
762 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
763 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
764 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
765 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
766 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
767 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
769 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
770 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
771 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
772 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
773 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
774 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
775 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
776 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
777 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
778 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
779 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
780 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
781 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
782 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
783 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
784 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
785 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
786 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
787 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
788 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
790 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
791 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
792 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
793 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
794 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
795 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
796 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
797 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
798 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
799 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
800 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
801 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
802 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
803 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
804 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
805 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
806 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
807 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
808 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
809 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
811 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
812 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
813 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
814 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
815 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
816 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
817 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
818 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
819 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
820 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
821 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
822 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
823 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
824 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
825 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
826 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
827 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
828 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
829 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
830 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
832 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
833 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
834 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
835 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
836 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
837 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
838 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
839 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
840 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
841 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
842 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
843 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
844 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
845 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
846 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
847 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
848 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
849 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
850 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
851 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
853 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
854 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
855 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
856 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
857 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
858 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
859 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
860 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
861 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
862 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
863 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
864 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
865 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
866 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
867 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
868 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
869 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
870 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
871 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
872 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
874 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
875 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
876 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
877 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
878 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
879 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
880 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
881 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
882 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
883 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
884 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
885 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
886 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
887 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
888 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
889 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
890 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
891 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
892 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
893 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
898 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
900 #ifdef FRONTEND_SUPPORTS_RGB565
901 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
902 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
903 SysPrintf("RGB565 supported, using it\n");
907 if (info == NULL || info->path == NULL) {
908 SysPrintf("info->path required\n");
912 if (plugins_opened) {
917 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
918 if (disks[i].fname != NULL) {
919 free(disks[i].fname);
920 disks[i].fname = NULL;
922 disks[i].internal_index = 0;
925 disk_current_index = 0;
926 extract_directory(base_dir, info->path, sizeof(base_dir));
929 if (!read_m3u(info->path)) {
930 SysPrintf("failed to read m3u file\n");
935 disks[0].fname = strdup(info->path);
938 set_cd_image(disks[0].fname);
940 /* have to reload after set_cd_image for correct cdr plugin */
941 if (LoadPlugins() == -1) {
942 SysPrintf("failed to load plugins\n");
949 if (OpenPlugins() == -1) {
950 SysPrintf("failed to open plugins\n");
954 plugin_call_rearmed_cbs();
958 if (CheckCdrom() == -1) {
959 SysPrintf("unsupported/invalid CD image: %s\n", info->path);
965 if (LoadCdrom() == -1) {
966 SysPrintf("could not load CD-ROM!\n");
973 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
974 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
975 disks[i].fname = strdup(info->path);
976 disks[i].internal_index = i;
983 bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
988 void retro_unload_game(void)
992 unsigned retro_get_region(void)
994 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
997 void *retro_get_memory_data(unsigned id)
999 if (id == RETRO_MEMORY_SAVE_RAM)
1005 size_t retro_get_memory_size(unsigned id)
1007 if (id == RETRO_MEMORY_SAVE_RAM)
1013 void retro_reset(void)
1018 static const unsigned short retro_psx_map[] = {
1019 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
1020 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
1021 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
1022 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
1023 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
1024 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
1025 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
1026 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
1027 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
1028 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
1029 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
1030 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
1031 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
1032 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
1033 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
1034 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
1036 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
1038 static void update_variables(bool in_flight)
1040 struct retro_variable var;
1043 var.key = "pcsx_rearmed_frameskip";
1045 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1046 pl_rearmed_cbs.frameskip = atoi(var.value);
1049 var.key = "pcsx_rearmed_region";
1051 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1054 if (strcmp(var.value, "Automatic") == 0)
1056 else if (strcmp(var.value, "NTSC") == 0)
1058 else if (strcmp(var.value, "PAL") == 0)
1063 var.key = "pcsx_rearmed_pad1type";
1065 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1067 in_type1 = PSE_PAD_TYPE_STANDARD;
1068 if (strcmp(var.value, "analog") == 0)
1069 in_type1 = PSE_PAD_TYPE_ANALOGPAD;
1073 var.key = "pcsx_rearmed_pad2type";
1075 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1077 in_type2 = PSE_PAD_TYPE_STANDARD;
1078 if (strcmp(var.value, "analog") == 0)
1079 in_type2 = PSE_PAD_TYPE_ANALOGPAD;
1084 var.key = "pcsx_rearmed_neon_interlace_enable";
1086 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1088 if (strcmp(var.value, "disabled") == 0)
1089 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1090 else if (strcmp(var.value, "enabled") == 0)
1091 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1095 var.key = "pcsx_rearmed_neon_enhancement_enable";
1097 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1099 if (strcmp(var.value, "disabled") == 0)
1100 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1101 else if (strcmp(var.value, "enabled") == 0)
1102 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1106 var.key = "pcsx_rearmed_neon_enhancement_no_main";
1108 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1110 if (strcmp(var.value, "disabled") == 0)
1111 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1112 else if (strcmp(var.value, "enabled") == 0)
1113 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1118 var.key = "pcsx_rearmed_duping_enable";
1120 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1122 if (strcmp(var.value, "off") == 0)
1123 duping_enable = false;
1124 else if (strcmp(var.value, "on") == 0)
1125 duping_enable = true;
1130 var.key = "pcsx_rearmed_drc";
1132 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1134 R3000Acpu *prev_cpu = psxCpu;
1137 if(!ctr_svchack_init_success)
1138 Config.Cpu = CPU_INTERPRETER;
1141 if (strcmp(var.value, "disabled") == 0)
1142 Config.Cpu = CPU_INTERPRETER;
1143 else if (strcmp(var.value, "enabled") == 0)
1144 Config.Cpu = CPU_DYNAREC;
1146 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1147 if (psxCpu != prev_cpu) {
1148 prev_cpu->Shutdown();
1150 psxCpu->Reset(); // not really a reset..
1156 var.key = "pcsx_rearmed_spu_reverb";
1158 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1160 if (strcmp(var.value, "off") == 0)
1161 spu_config.iUseReverb = false;
1162 else if (strcmp(var.value, "on") == 0)
1163 spu_config.iUseReverb = true;
1167 var.key = "pcsx_rearmed_spu_interpolation";
1169 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1171 if (strcmp(var.value, "simple") == 0)
1172 spu_config.iUseInterpolation = 1;
1173 else if (strcmp(var.value, "gaussian") == 0)
1174 spu_config.iUseInterpolation = 2;
1175 else if (strcmp(var.value, "cubic") == 0)
1176 spu_config.iUseInterpolation = 3;
1177 else if (strcmp(var.value, "off") == 0)
1178 spu_config.iUseInterpolation = 0;
1182 var.key = "pcsx_rearmed_pe2_fix";
1184 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1186 if (strcmp(var.value, "disabled") == 0)
1188 else if (strcmp(var.value, "enabled") == 0)
1193 var.key = "pcsx_rearmed_inuyasha_fix";
1195 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1197 if (strcmp(var.value, "disabled") == 0)
1199 else if (strcmp(var.value, "enabled") == 0)
1204 // inform core things about possible config changes
1205 plugin_call_rearmed_cbs();
1207 if (GPU_open != NULL && GPU_close != NULL) {
1209 GPU_open(&gpuDisp, "PCSX", NULL);
1216 void retro_run(void)
1222 bool updated = false;
1223 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1224 update_variables(true);
1227 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
1228 if (input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, i))
1229 in_keystate |= retro_psx_map[i];
1231 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
1232 if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i))
1233 in_keystate |= retro_psx_map[i];
1235 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD)
1237 in_a1[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1238 in_a1[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1239 in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1240 in_a2[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1243 if (in_type2 == PSE_PAD_TYPE_ANALOGPAD)
1245 in_a3[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1246 in_a3[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1247 in_a4[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1248 in_a4[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1254 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf : NULL,
1255 vout_width, vout_height, vout_width * 2);
1259 static bool try_use_bios(const char *path)
1265 f = fopen(path, "rb");
1269 fseek(f, 0, SEEK_END);
1273 if (size != 512 * 1024)
1276 name = strrchr(path, SLASH);
1279 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1284 #include <sys/types.h>
1287 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1293 dir = opendir(dirpath);
1297 while ((ent = readdir(dir))) {
1298 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1301 snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
1302 ret = try_use_bios(path);
1310 #define find_any_bios(...) false
1313 static void check_system_specs(void)
1316 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1319 void retro_init(void)
1321 const char *bios[] = { "scph1001", "scph5501", "scph7001" };
1325 bool found_bios = false;
1328 ctr_svchack_init_success = ctr_svchack_init();
1329 psxMapHook = pl_3ds_mmap;
1330 psxUnmapHook = pl_3ds_munmap;
1332 ret = emu_core_preinit();
1334 /* emu_core_preinit sets the cpu to dynarec */
1335 if(!ctr_svchack_init_success)
1336 Config.Cpu = CPU_INTERPRETER;
1338 ret |= emu_core_init();
1340 SysPrintf("PCSX init failed.\n");
1344 #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
1345 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1347 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1350 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1352 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
1354 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1355 snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
1356 found_bios = try_use_bios(path);
1362 found_bios = find_any_bios(dir, path, sizeof(path));
1365 SysPrintf("found BIOS file: %s\n", Config.Bios);
1369 SysPrintf("no BIOS files found.\n");
1370 struct retro_message msg =
1372 "no BIOS found, expect bugs!",
1375 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1378 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1379 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1380 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1382 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1383 * we have to do this because cache misses and some IO penalties
1384 * are not emulated. Warning: changing this may break compatibility. */
1385 #if !defined(__arm__) || defined(__ARM_ARCH_7A__)
1386 cycle_multiplier = 175;
1388 cycle_multiplier = 200;
1390 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1391 spu_config.iUseFixedUpdates = 1;
1395 init_memcard(Mcd1Data);
1397 SaveFuncs.open = save_open;
1398 SaveFuncs.read = save_read;
1399 SaveFuncs.write = save_write;
1400 SaveFuncs.seek = save_seek;
1401 SaveFuncs.close = save_close;
1403 update_variables(false);
1404 check_system_specs();
1407 void retro_deinit(void)
1415 #include <psp2/kernel/threadmgr.h>
1416 int usleep (unsigned long us)
1418 sceKernelDelayThread(us);