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"
32 #include "3ds/3ds_utils.h"
35 static retro_video_refresh_t video_cb;
36 static retro_input_poll_t input_poll_cb;
37 static retro_input_state_t input_state_cb;
38 static retro_environment_t environ_cb;
39 static retro_audio_sample_batch_t audio_batch_cb;
40 static struct retro_rumble_interface rumble;
42 static void *vout_buf;
43 static int vout_width, vout_height;
44 static int vout_doffs_old, vout_fb_dirty;
45 static bool vout_can_dupe;
46 static bool duping_enable;
48 static int plugins_opened;
49 static int is_pal_mode;
51 /* memory card data */
52 extern char Mcd1Data[MCD_SIZE];
53 extern char McdDisable[2];
55 /* PCSX ReARMed core calls and stuff */
56 int in_type1, in_type2;
57 int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 };
58 int in_a3[2] = { 127, 127 }, in_a4[2] = { 127, 127 };
60 int in_enable_vibration = 1;
62 /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
63 #define VOUT_MAX_WIDTH 1024
64 #define VOUT_MAX_HEIGHT 512
66 static void init_memcard(char *mcd_data)
71 memset(mcd_data, 0, MCD_SIZE);
73 mcd_data[off++] = 'M';
74 mcd_data[off++] = 'C';
76 mcd_data[off++] = 0x0e;
78 for (i = 0; i < 15; i++) {
79 mcd_data[off++] = 0xa0;
81 mcd_data[off++] = 0xff;
82 mcd_data[off++] = 0xff;
84 mcd_data[off++] = 0xa0;
87 for (i = 0; i < 20; i++) {
88 mcd_data[off++] = 0xff;
89 mcd_data[off++] = 0xff;
90 mcd_data[off++] = 0xff;
91 mcd_data[off++] = 0xff;
93 mcd_data[off++] = 0xff;
94 mcd_data[off++] = 0xff;
99 static int vout_open(void)
104 static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
110 #ifndef FRONTEND_SUPPORTS_RGB565
111 static void convert(void *buf, size_t bytes)
113 unsigned int i, v, *p = buf;
115 for (i = 0; i < bytes / 4; i++) {
117 p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0);
122 static void vout_flip(const void *vram, int stride, int bgr24, int w, int h)
124 unsigned short *dest = vout_buf;
125 const unsigned short *src = vram;
126 int dstride = vout_width, h1 = h;
131 memset(vout_buf, 0, dstride * h * 2);
135 doffs = (vout_height - h) * dstride;
136 doffs += (dstride - w) / 2 & ~1;
137 if (doffs != vout_doffs_old) {
139 memset(vout_buf, 0, dstride * h * 2);
140 vout_doffs_old = doffs;
146 // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here?
147 for (; h1-- > 0; dest += dstride, src += stride)
149 bgr888_to_rgb565(dest, src, w * 3);
154 for (; h1-- > 0; dest += dstride, src += stride)
156 bgr555_to_rgb565(dest, src, w * 2);
161 #ifndef FRONTEND_SUPPORTS_RGB565
162 convert(vout_buf, vout_width * vout_height * 2);
165 pl_rearmed_cbs.flip_cnt++;
168 static void vout_close(void)
181 psx_map_t custom_psx_maps[] = {
182 {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000
183 {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
184 {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
185 {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000
186 {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000
189 void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
197 psx_map_t* custom_map = custom_psx_maps;
199 for (; custom_map->size; custom_map++)
201 if ((custom_map->size == size) && (custom_map->tag == tag))
203 uint32_t ptr_aligned, tmp;
205 custom_map->buffer = malloc(size + 0x1000);
206 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
208 if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0)
210 SysPrintf("could not map memory @0x%08X\n", custom_map->target_map);
214 return (void*)custom_map->target_map;
222 void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
228 psx_map_t* custom_map = custom_psx_maps;
230 for (; custom_map->size; custom_map++)
232 if ((custom_map->target_map == (uint32_t)ptr))
234 uint32_t ptr_aligned, tmp;
236 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
238 svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3);
240 free(custom_map->buffer);
241 custom_map->buffer = NULL;
251 static void *pl_mmap(unsigned int size)
253 return psxMap(0, size, 0, MAP_TAG_VRAM);
256 static void pl_munmap(void *ptr, unsigned int size)
258 psxUnmap(ptr, size, MAP_TAG_VRAM);
261 struct rearmed_cbs pl_rearmed_cbs = {
262 .pl_vout_open = vout_open,
263 .pl_vout_set_mode = vout_set_mode,
264 .pl_vout_flip = vout_flip,
265 .pl_vout_close = vout_close,
268 /* from psxcounters */
269 .gpu_hcnt = &hSyncCount,
270 .gpu_frame_count = &frame_counter,
273 void pl_frame_limit(void)
275 /* called once per frame, make psxCpu->Execute() above return */
279 void pl_timing_prepare(int is_pal)
281 is_pal_mode = is_pal;
284 void plat_trigger_vibrate(int pad, int low, int high)
286 rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8);
287 rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0);
290 void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
295 static int snd_init(void)
300 static void snd_finish(void)
304 static int snd_busy(void)
309 static void snd_feed(void *buf, int bytes)
311 if (audio_batch_cb != NULL)
312 audio_batch_cb(buf, bytes / 4);
315 void out_register_libretro(struct out_driver *drv)
317 drv->name = "libretro";
318 drv->init = snd_init;
319 drv->finish = snd_finish;
320 drv->busy = snd_busy;
321 drv->feed = snd_feed;
325 void retro_set_environment(retro_environment_t cb)
327 static const struct retro_variable vars[] = {
328 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
329 { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
330 { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog|negcon" },
331 { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog|negcon" },
333 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
336 { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
337 { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
338 { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
340 { "pcsx_rearmed_duping_enable", "Frame duping; on|off" },
341 { "pcsx_rearmed_spu_reverb", "Sound: Reverb; on|off" },
342 { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" },
343 { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" },
344 { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" },
350 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
353 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
354 void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
355 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
356 void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
357 void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
359 unsigned retro_api_version(void)
361 return RETRO_API_VERSION;
364 void retro_set_controller_port_device(unsigned port, unsigned device)
368 void retro_get_system_info(struct retro_system_info *info)
370 memset(info, 0, sizeof(*info));
371 info->library_name = "PCSX-ReARMed";
372 info->library_version = "r22";
373 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
374 info->need_fullpath = true;
377 void retro_get_system_av_info(struct retro_system_av_info *info)
379 memset(info, 0, sizeof(*info));
380 info->timing.fps = is_pal_mode ? 50 : 60;
381 info->timing.sample_rate = 44100;
382 info->geometry.base_width = 320;
383 info->geometry.base_height = 240;
384 info->geometry.max_width = VOUT_MAX_WIDTH;
385 info->geometry.max_height = VOUT_MAX_HEIGHT;
386 info->geometry.aspect_ratio = 4.0 / 3.0;
390 size_t retro_serialize_size(void)
392 // it's currently 4380651-4397047 bytes,
393 // but have some reserved for future
403 static void *save_open(const char *name, const char *mode)
407 if (name == NULL || mode == NULL)
410 fp = malloc(sizeof(*fp));
414 fp->buf = (char *)name;
416 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
421 static int save_read(void *file, void *buf, u32 len)
423 struct save_fp *fp = file;
424 if (fp == NULL || buf == NULL)
427 memcpy(buf, fp->buf + fp->pos, len);
432 static int save_write(void *file, const void *buf, u32 len)
434 struct save_fp *fp = file;
435 if (fp == NULL || buf == NULL)
438 memcpy(fp->buf + fp->pos, buf, len);
443 static long save_seek(void *file, long offs, int whence)
445 struct save_fp *fp = file;
461 static void save_close(void *file)
463 struct save_fp *fp = file;
464 size_t r_size = retro_serialize_size();
468 if (fp->pos > r_size)
469 SysPrintf("ERROR: save buffer overflow detected\n");
470 else if (fp->is_write && fp->pos < r_size)
471 // make sure we don't save trash in leftover space
472 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
476 bool retro_serialize(void *data, size_t size)
478 int ret = SaveState(data);
479 return ret == 0 ? true : false;
482 bool retro_unserialize(const void *data, size_t size)
484 int ret = LoadState(data);
485 return ret == 0 ? true : false;
489 void retro_cheat_reset(void)
494 void retro_cheat_set(unsigned index, bool enabled, const char *code)
499 // cheat funcs are destructive, need a copy..
500 strncpy(buf, code, sizeof(buf));
501 buf[sizeof(buf) - 1] = 0;
503 if (index < NumCheats)
504 ret = EditCheat(index, "", buf);
506 ret = AddCheat("", buf);
509 SysPrintf("Failed to set cheat %#u\n", index);
510 else if (index < NumCheats)
511 Cheats[index].Enabled = enabled;
514 /* multidisk support */
515 static bool disk_ejected;
516 static unsigned int disk_current_index;
517 static unsigned int disk_count;
518 static struct disks_state {
520 int internal_index; // for multidisk eboots
523 static bool disk_set_eject_state(bool ejected)
526 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
529 disk_ejected = ejected;
533 static bool disk_get_eject_state(void)
535 /* can't be controlled by emulated software */
539 static unsigned int disk_get_image_index(void)
541 return disk_current_index;
544 static bool disk_set_image_index(unsigned int index)
546 if (index >= sizeof(disks) / sizeof(disks[0]))
550 CdromLabel[0] = '\0';
552 if (disks[index].fname == NULL) {
553 SysPrintf("missing disk #%u\n", index);
556 // RetroArch specifies "no disk" with index == count,
557 // so don't fail here..
558 disk_current_index = index;
562 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
563 disks[index].fname, disks[index].internal_index);
565 cdrIsoMultidiskSelect = disks[index].internal_index;
566 set_cd_image(disks[index].fname);
567 if (ReloadCdromPlugin() < 0) {
568 SysPrintf("failed to load cdr plugin\n");
571 if (CDR_open() < 0) {
572 SysPrintf("failed to open cdr plugin\n");
577 SetCdOpenCaseTime(time(NULL) + 2);
581 disk_current_index = index;
585 static unsigned int disk_get_num_images(void)
590 static bool disk_replace_image_index(unsigned index,
591 const struct retro_game_info *info)
596 if (index >= sizeof(disks) / sizeof(disks[0]))
599 old_fname = disks[index].fname;
600 disks[index].fname = NULL;
601 disks[index].internal_index = 0;
604 disks[index].fname = strdup(info->path);
605 if (index == disk_current_index)
606 ret = disk_set_image_index(index);
609 if (old_fname != NULL)
615 static bool disk_add_image_index(void)
624 static struct retro_disk_control_callback disk_control = {
625 .set_eject_state = disk_set_eject_state,
626 .get_eject_state = disk_get_eject_state,
627 .get_image_index = disk_get_image_index,
628 .set_image_index = disk_set_image_index,
629 .get_num_images = disk_get_num_images,
630 .replace_image_index = disk_replace_image_index,
631 .add_image_index = disk_add_image_index,
634 // just in case, maybe a win-rt port in the future?
641 static char base_dir[PATH_MAX];
643 static bool read_m3u(const char *file)
647 FILE *f = fopen(file, "r");
651 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
654 char *carrige_return = strchr(line, '\r');
656 *carrige_return = '\0';
657 char *newline = strchr(line, '\n');
663 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
664 disks[disk_count++].fname = strdup(name);
669 return (disk_count != 0);
672 static void extract_directory(char *buf, const char *path, size_t size)
675 strncpy(buf, path, size - 1);
676 buf[size - 1] = '\0';
678 base = strrchr(buf, '/');
680 base = strrchr(buf, '\\');
691 #if defined(__QNX__) || defined(_WIN32)
692 /* Blackberry QNX doesn't have strcasestr */
695 * Find the first occurrence of find in s, ignore case.
698 strcasestr(const char *s, const char*find)
703 if ((c = *find++) != 0) {
704 c = tolower((unsigned char)c);
708 if ((sc = *s++) == 0)
710 } while ((char)tolower((unsigned char)sc) != c);
711 } while (strncasecmp(s, find, len) != 0);
718 bool retro_load_game(const struct retro_game_info *info)
721 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
723 struct retro_input_descriptor desc[] = {
724 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
725 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
726 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
727 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
728 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
729 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
730 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
731 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
732 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
733 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
734 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
735 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
736 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
737 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
738 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
739 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
740 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
741 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
742 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
743 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
746 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
747 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
748 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
749 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
750 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
751 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
752 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
753 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
754 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
755 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
756 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
757 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
758 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
759 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
760 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
761 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
762 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
763 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
764 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
765 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
767 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
768 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
769 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
770 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
771 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
772 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
773 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
774 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
775 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
776 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
777 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
778 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
779 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
780 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
781 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
782 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
783 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
784 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
785 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
786 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
788 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
789 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
790 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
791 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
792 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
793 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
794 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
795 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
796 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
797 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
798 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
799 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
800 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
801 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
802 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
803 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
804 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
805 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
806 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
807 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
809 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
810 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
811 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
812 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
813 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
814 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
815 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
816 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
817 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
818 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
819 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
820 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
821 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
822 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
823 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
824 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
825 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
826 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
827 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
828 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
830 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
831 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
832 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
833 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
834 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
835 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
836 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
837 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
838 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
839 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
840 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
841 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
842 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
843 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
844 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
845 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
846 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
847 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
848 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
849 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
851 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
852 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
853 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
854 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
855 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
856 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
857 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
858 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
859 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
860 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
861 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
862 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
863 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
864 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
865 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
866 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
867 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
868 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
869 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
870 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
872 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
873 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
874 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
875 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
876 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
877 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
878 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
879 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
880 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
881 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
882 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
883 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
884 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
885 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
886 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
887 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
888 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
889 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
890 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
891 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
896 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
898 #ifdef FRONTEND_SUPPORTS_RGB565
899 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
900 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
901 SysPrintf("RGB565 supported, using it\n");
905 if (info == NULL || info->path == NULL) {
906 SysPrintf("info->path required\n");
910 if (plugins_opened) {
915 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
916 if (disks[i].fname != NULL) {
917 free(disks[i].fname);
918 disks[i].fname = NULL;
920 disks[i].internal_index = 0;
923 disk_current_index = 0;
924 extract_directory(base_dir, info->path, sizeof(base_dir));
927 if (!read_m3u(info->path)) {
928 SysPrintf("failed to read m3u file\n");
933 disks[0].fname = strdup(info->path);
936 set_cd_image(disks[0].fname);
938 /* have to reload after set_cd_image for correct cdr plugin */
939 if (LoadPlugins() == -1) {
940 SysPrintf("failed to load plugins\n");
947 if (OpenPlugins() == -1) {
948 SysPrintf("failed to open plugins\n");
952 plugin_call_rearmed_cbs();
956 if (CheckCdrom() == -1) {
957 SysPrintf("unsupported/invalid CD image: %s\n", info->path);
963 if (LoadCdrom() == -1) {
964 SysPrintf("could not load CD-ROM!\n");
971 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
972 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
973 disks[i].fname = strdup(info->path);
974 disks[i].internal_index = i;
981 bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
986 void retro_unload_game(void)
990 unsigned retro_get_region(void)
992 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
995 void *retro_get_memory_data(unsigned id)
997 if (id == RETRO_MEMORY_SAVE_RAM)
1003 size_t retro_get_memory_size(unsigned id)
1005 if (id == RETRO_MEMORY_SAVE_RAM)
1011 void retro_reset(void)
1016 static const unsigned short retro_psx_map[] = {
1017 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
1018 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
1019 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
1020 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
1021 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
1022 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
1023 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
1024 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
1025 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
1026 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
1027 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
1028 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
1029 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
1030 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
1031 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
1032 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
1034 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
1036 static void update_variables(bool in_flight)
1038 struct retro_variable var;
1041 var.key = "pcsx_rearmed_frameskip";
1043 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1044 pl_rearmed_cbs.frameskip = atoi(var.value);
1047 var.key = "pcsx_rearmed_region";
1049 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1052 if (strcmp(var.value, "Automatic") == 0)
1054 else if (strcmp(var.value, "NTSC") == 0)
1056 else if (strcmp(var.value, "PAL") == 0)
1061 var.key = "pcsx_rearmed_pad1type";
1063 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1065 in_type1 = PSE_PAD_TYPE_STANDARD;
1066 if (strcmp(var.value, "analog") == 0)
1067 in_type1 = PSE_PAD_TYPE_ANALOGPAD;
1068 if (strcmp(var.value, "negcon") == 0)
1069 in_type1 = PSE_PAD_TYPE_NEGCON;
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;
1080 if (strcmp(var.value, "negcon") == 0)
1081 in_type2 = PSE_PAD_TYPE_NEGCON;
1087 var.key = "pcsx_rearmed_neon_interlace_enable";
1089 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1091 if (strcmp(var.value, "disabled") == 0)
1092 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1093 else if (strcmp(var.value, "enabled") == 0)
1094 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1098 var.key = "pcsx_rearmed_neon_enhancement_enable";
1100 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1102 if (strcmp(var.value, "disabled") == 0)
1103 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1104 else if (strcmp(var.value, "enabled") == 0)
1105 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1109 var.key = "pcsx_rearmed_neon_enhancement_no_main";
1111 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1113 if (strcmp(var.value, "disabled") == 0)
1114 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1115 else if (strcmp(var.value, "enabled") == 0)
1116 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1121 var.key = "pcsx_rearmed_duping_enable";
1123 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1125 if (strcmp(var.value, "off") == 0)
1126 duping_enable = false;
1127 else if (strcmp(var.value, "on") == 0)
1128 duping_enable = true;
1133 var.key = "pcsx_rearmed_drc";
1135 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1137 R3000Acpu *prev_cpu = psxCpu;
1141 Config.Cpu = CPU_INTERPRETER;
1144 if (strcmp(var.value, "disabled") == 0)
1145 Config.Cpu = CPU_INTERPRETER;
1146 else if (strcmp(var.value, "enabled") == 0)
1147 Config.Cpu = CPU_DYNAREC;
1149 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1150 if (psxCpu != prev_cpu) {
1151 prev_cpu->Shutdown();
1153 psxCpu->Reset(); // not really a reset..
1159 var.key = "pcsx_rearmed_spu_reverb";
1161 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1163 if (strcmp(var.value, "off") == 0)
1164 spu_config.iUseReverb = false;
1165 else if (strcmp(var.value, "on") == 0)
1166 spu_config.iUseReverb = true;
1170 var.key = "pcsx_rearmed_spu_interpolation";
1172 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1174 if (strcmp(var.value, "simple") == 0)
1175 spu_config.iUseInterpolation = 1;
1176 else if (strcmp(var.value, "gaussian") == 0)
1177 spu_config.iUseInterpolation = 2;
1178 else if (strcmp(var.value, "cubic") == 0)
1179 spu_config.iUseInterpolation = 3;
1180 else if (strcmp(var.value, "off") == 0)
1181 spu_config.iUseInterpolation = 0;
1185 var.key = "pcsx_rearmed_pe2_fix";
1187 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1189 if (strcmp(var.value, "disabled") == 0)
1191 else if (strcmp(var.value, "enabled") == 0)
1196 var.key = "pcsx_rearmed_inuyasha_fix";
1198 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1200 if (strcmp(var.value, "disabled") == 0)
1202 else if (strcmp(var.value, "enabled") == 0)
1207 // inform core things about possible config changes
1208 plugin_call_rearmed_cbs();
1210 if (GPU_open != NULL && GPU_close != NULL) {
1212 GPU_open(&gpuDisp, "PCSX", NULL);
1219 void retro_run(void)
1225 bool updated = false;
1226 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1227 update_variables(true);
1230 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
1231 if (input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, i))
1232 in_keystate |= retro_psx_map[i];
1234 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
1235 if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i))
1236 in_keystate |= retro_psx_map[i];
1239 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD)
1241 in_a1[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1242 in_a1[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1243 in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1244 in_a2[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1247 if (in_type2 == PSE_PAD_TYPE_ANALOGPAD)
1249 in_a3[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1250 in_a3[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1251 in_a4[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1252 in_a4[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1256 if (in_type1 == PSE_PAD_TYPE_NEGCON)
1259 if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, 12))
1265 in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1267 /* thrust and fire */
1268 val = ((input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 127));
1270 in_a1[0] = 256 - val;
1275 if(val >= -2 && val <= 2)
1282 if (in_type2 == PSE_PAD_TYPE_NEGCON)
1285 if(input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, 12))
1291 in_a4[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1293 /* thrust and fire */
1294 val = ((input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 127));
1296 in_a3[0] = 256 - val;
1301 if(val >= -2 && val <= 2)
1312 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf : NULL,
1313 vout_width, vout_height, vout_width * 2);
1317 static bool try_use_bios(const char *path)
1323 f = fopen(path, "rb");
1327 fseek(f, 0, SEEK_END);
1331 if (size != 512 * 1024)
1334 name = strrchr(path, SLASH);
1337 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1342 #include <sys/types.h>
1345 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1351 dir = opendir(dirpath);
1355 while ((ent = readdir(dir))) {
1356 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1359 snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
1360 ret = try_use_bios(path);
1368 #define find_any_bios(...) false
1371 static void check_system_specs(void)
1374 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1377 void retro_init(void)
1379 const char *bios[] = { "scph1001", "scph5501", "scph7001" };
1383 bool found_bios = false;
1386 psxMapHook = pl_3ds_mmap;
1387 psxUnmapHook = pl_3ds_munmap;
1389 ret = emu_core_preinit();
1391 /* emu_core_preinit sets the cpu to dynarec */
1393 Config.Cpu = CPU_INTERPRETER;
1395 ret |= emu_core_init();
1397 SysPrintf("PCSX init failed.\n");
1402 vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
1403 #elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
1404 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1406 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1409 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1411 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
1413 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1414 snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
1415 found_bios = try_use_bios(path);
1421 found_bios = find_any_bios(dir, path, sizeof(path));
1424 SysPrintf("found BIOS file: %s\n", Config.Bios);
1428 SysPrintf("no BIOS files found.\n");
1429 struct retro_message msg =
1431 "no BIOS found, expect bugs!",
1434 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1437 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1438 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1439 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1441 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1442 * we have to do this because cache misses and some IO penalties
1443 * are not emulated. Warning: changing this may break compatibility. */
1444 #if !defined(__arm__) || defined(__ARM_ARCH_7A__)
1445 cycle_multiplier = 175;
1447 cycle_multiplier = 200;
1449 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1450 spu_config.iUseFixedUpdates = 1;
1454 init_memcard(Mcd1Data);
1456 SaveFuncs.open = save_open;
1457 SaveFuncs.read = save_read;
1458 SaveFuncs.write = save_write;
1459 SaveFuncs.seek = save_seek;
1460 SaveFuncs.close = save_close;
1462 update_variables(false);
1463 check_system_specs();
1466 void retro_deinit(void)
1470 linearFree(vout_buf);
1478 #include <psp2/kernel/threadmgr.h>
1479 int usleep (unsigned long us)
1481 sceKernelDelayThread(us);