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"
31 static retro_video_refresh_t video_cb;
32 static retro_input_poll_t input_poll_cb;
33 static retro_input_state_t input_state_cb;
34 static retro_environment_t environ_cb;
35 static retro_audio_sample_batch_t audio_batch_cb;
36 static struct retro_rumble_interface rumble;
38 static void *vout_buf;
39 static int vout_width, vout_height;
40 static int vout_doffs_old, vout_fb_dirty;
41 static bool vout_can_dupe;
42 static bool duping_enable;
44 static int plugins_opened;
45 static int is_pal_mode;
47 /* memory card data */
48 extern char Mcd1Data[MCD_SIZE];
49 extern char McdDisable[2];
51 /* PCSX ReARMed core calls and stuff */
52 int in_type1, in_type2;
53 int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 };
55 int in_enable_vibration = 1;
57 /* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
58 #define VOUT_MAX_WIDTH 1024
59 #define VOUT_MAX_HEIGHT 512
61 static void init_memcard(char *mcd_data)
66 memset(mcd_data, 0, MCD_SIZE);
68 mcd_data[off++] = 'M';
69 mcd_data[off++] = 'C';
71 mcd_data[off++] = 0x0e;
73 for (i = 0; i < 15; i++) {
74 mcd_data[off++] = 0xa0;
76 mcd_data[off++] = 0xff;
77 mcd_data[off++] = 0xff;
79 mcd_data[off++] = 0xa0;
82 for (i = 0; i < 20; i++) {
83 mcd_data[off++] = 0xff;
84 mcd_data[off++] = 0xff;
85 mcd_data[off++] = 0xff;
86 mcd_data[off++] = 0xff;
88 mcd_data[off++] = 0xff;
89 mcd_data[off++] = 0xff;
94 static int vout_open(void)
99 static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
105 #ifndef FRONTEND_SUPPORTS_RGB565
106 static void convert(void *buf, size_t bytes)
108 unsigned int i, v, *p = buf;
110 for (i = 0; i < bytes / 4; i++) {
112 p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0);
117 static void vout_flip(const void *vram, int stride, int bgr24, int w, int h)
119 unsigned short *dest = vout_buf;
120 const unsigned short *src = vram;
121 int dstride = vout_width, h1 = h;
126 memset(vout_buf, 0, dstride * h * 2);
130 doffs = (vout_height - h) * dstride;
131 doffs += (dstride - w) / 2 & ~1;
132 if (doffs != vout_doffs_old) {
134 memset(vout_buf, 0, dstride * h * 2);
135 vout_doffs_old = doffs;
141 // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here?
142 for (; h1-- > 0; dest += dstride, src += stride)
144 bgr888_to_rgb565(dest, src, w * 3);
149 for (; h1-- > 0; dest += dstride, src += stride)
151 bgr555_to_rgb565(dest, src, w * 2);
156 #ifndef FRONTEND_SUPPORTS_RGB565
157 convert(vout_buf, vout_width * vout_height * 2);
160 pl_rearmed_cbs.flip_cnt++;
163 static void vout_close(void)
167 static void *pl_mmap(unsigned int size)
169 return psxMap(0, size, 0, MAP_TAG_VRAM);
172 static void pl_munmap(void *ptr, unsigned int size)
174 psxUnmap(ptr, size, MAP_TAG_VRAM);
177 struct rearmed_cbs pl_rearmed_cbs = {
178 .pl_vout_open = vout_open,
179 .pl_vout_set_mode = vout_set_mode,
180 .pl_vout_flip = vout_flip,
181 .pl_vout_close = vout_close,
184 /* from psxcounters */
185 .gpu_hcnt = &hSyncCount,
186 .gpu_frame_count = &frame_counter,
189 void pl_frame_limit(void)
191 /* called once per frame, make psxCpu->Execute() above return */
195 void pl_timing_prepare(int is_pal)
197 is_pal_mode = is_pal;
200 void plat_trigger_vibrate(int pad, int low, int high)
202 rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8);
203 rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0);
206 void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
211 static int snd_init(void)
216 static void snd_finish(void)
220 static int snd_busy(void)
225 static void snd_feed(void *buf, int bytes)
227 if (audio_batch_cb != NULL)
228 audio_batch_cb(buf, bytes / 4);
231 void out_register_libretro(struct out_driver *drv)
233 drv->name = "libretro";
234 drv->init = snd_init;
235 drv->finish = snd_finish;
236 drv->busy = snd_busy;
237 drv->feed = snd_feed;
241 void retro_set_environment(retro_environment_t cb)
243 static const struct retro_variable vars[] = {
244 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
245 { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
246 { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog" },
247 { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog" },
249 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
252 { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
253 { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
254 { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
256 { "pcsx_rearmed_duping_enable", "Frame duping; on|off" },
257 { "pcsx_rearmed_spu_reverb", "Sound: Reverb; on|off" },
258 { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" },
264 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
267 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
268 void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
269 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
270 void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
271 void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
273 unsigned retro_api_version(void)
275 return RETRO_API_VERSION;
278 void retro_set_controller_port_device(unsigned port, unsigned device)
282 void retro_get_system_info(struct retro_system_info *info)
284 memset(info, 0, sizeof(*info));
285 info->library_name = "PCSX-ReARMed";
286 info->library_version = "r21";
287 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
288 info->need_fullpath = true;
291 void retro_get_system_av_info(struct retro_system_av_info *info)
293 memset(info, 0, sizeof(*info));
294 info->timing.fps = is_pal_mode ? 50 : 60;
295 info->timing.sample_rate = 44100;
296 info->geometry.base_width = 320;
297 info->geometry.base_height = 240;
298 info->geometry.max_width = VOUT_MAX_WIDTH;
299 info->geometry.max_height = VOUT_MAX_HEIGHT;
300 info->geometry.aspect_ratio = 4.0 / 3.0;
304 size_t retro_serialize_size(void)
306 // it's currently 4380651-4397047 bytes,
307 // but have some reserved for future
317 static void *save_open(const char *name, const char *mode)
321 if (name == NULL || mode == NULL)
324 fp = malloc(sizeof(*fp));
328 fp->buf = (char *)name;
330 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
335 static int save_read(void *file, void *buf, u32 len)
337 struct save_fp *fp = file;
338 if (fp == NULL || buf == NULL)
341 memcpy(buf, fp->buf + fp->pos, len);
346 static int save_write(void *file, const void *buf, u32 len)
348 struct save_fp *fp = file;
349 if (fp == NULL || buf == NULL)
352 memcpy(fp->buf + fp->pos, buf, len);
357 static long save_seek(void *file, long offs, int whence)
359 struct save_fp *fp = file;
375 static void save_close(void *file)
377 struct save_fp *fp = file;
378 size_t r_size = retro_serialize_size();
382 if (fp->pos > r_size)
383 SysPrintf("ERROR: save buffer overflow detected\n");
384 else if (fp->is_write && fp->pos < r_size)
385 // make sure we don't save trash in leftover space
386 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
390 bool retro_serialize(void *data, size_t size)
392 int ret = SaveState(data);
393 return ret == 0 ? true : false;
396 bool retro_unserialize(const void *data, size_t size)
398 int ret = LoadState(data);
399 return ret == 0 ? true : false;
403 void retro_cheat_reset(void)
408 void retro_cheat_set(unsigned index, bool enabled, const char *code)
413 // cheat funcs are destructive, need a copy..
414 strncpy(buf, code, sizeof(buf));
415 buf[sizeof(buf) - 1] = 0;
417 if (index < NumCheats)
418 ret = EditCheat(index, "", buf);
420 ret = AddCheat("", buf);
423 SysPrintf("Failed to set cheat %#u\n", index);
424 else if (index < NumCheats)
425 Cheats[index].Enabled = enabled;
428 /* multidisk support */
429 static bool disk_ejected;
430 static unsigned int disk_current_index;
431 static unsigned int disk_count;
432 static struct disks_state {
434 int internal_index; // for multidisk eboots
437 static bool disk_set_eject_state(bool ejected)
440 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
443 disk_ejected = ejected;
447 static bool disk_get_eject_state(void)
449 /* can't be controlled by emulated software */
453 static unsigned int disk_get_image_index(void)
455 return disk_current_index;
458 static bool disk_set_image_index(unsigned int index)
460 if (index >= sizeof(disks) / sizeof(disks[0]))
464 CdromLabel[0] = '\0';
466 if (disks[index].fname == NULL) {
467 SysPrintf("missing disk #%u\n", index);
470 // RetroArch specifies "no disk" with index == count,
471 // so don't fail here..
472 disk_current_index = index;
476 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
477 disks[index].fname, disks[index].internal_index);
479 cdrIsoMultidiskSelect = disks[index].internal_index;
480 set_cd_image(disks[index].fname);
481 if (ReloadCdromPlugin() < 0) {
482 SysPrintf("failed to load cdr plugin\n");
485 if (CDR_open() < 0) {
486 SysPrintf("failed to open cdr plugin\n");
491 SetCdOpenCaseTime(time(NULL) + 2);
495 disk_current_index = index;
499 static unsigned int disk_get_num_images(void)
504 static bool disk_replace_image_index(unsigned index,
505 const struct retro_game_info *info)
510 if (index >= sizeof(disks) / sizeof(disks[0]))
513 old_fname = disks[index].fname;
514 disks[index].fname = NULL;
515 disks[index].internal_index = 0;
518 disks[index].fname = strdup(info->path);
519 if (index == disk_current_index)
520 ret = disk_set_image_index(index);
523 if (old_fname != NULL)
529 static bool disk_add_image_index(void)
538 static struct retro_disk_control_callback disk_control = {
539 .set_eject_state = disk_set_eject_state,
540 .get_eject_state = disk_get_eject_state,
541 .get_image_index = disk_get_image_index,
542 .set_image_index = disk_set_image_index,
543 .get_num_images = disk_get_num_images,
544 .replace_image_index = disk_replace_image_index,
545 .add_image_index = disk_add_image_index,
548 // just in case, maybe a win-rt port in the future?
555 static char base_dir[PATH_MAX];
557 static bool read_m3u(const char *file)
561 FILE *f = fopen(file, "r");
565 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
568 char *carrige_return = strchr(line, '\r');
570 *carrige_return = '\0';
571 char *newline = strchr(line, '\n');
577 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
578 disks[disk_count++].fname = strdup(name);
583 return (disk_count != 0);
586 static void extract_directory(char *buf, const char *path, size_t size)
589 strncpy(buf, path, size - 1);
590 buf[size - 1] = '\0';
592 base = strrchr(buf, '/');
594 base = strrchr(buf, '\\');
605 #if defined(__QNX__) || defined(_WIN32)
606 /* Blackberry QNX doesn't have strcasestr */
609 * Find the first occurrence of find in s, ignore case.
612 strcasestr(const char *s, const char*find)
617 if ((c = *find++) != 0) {
618 c = tolower((unsigned char)c);
622 if ((sc = *s++) == 0)
624 } while ((char)tolower((unsigned char)sc) != c);
625 } while (strncasecmp(s, find, len) != 0);
632 bool retro_load_game(const struct retro_game_info *info)
635 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
637 struct retro_input_descriptor desc[] = {
638 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
639 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
640 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
641 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
642 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
643 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
644 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
645 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
646 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
647 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
648 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
649 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
650 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
651 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
652 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
653 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
654 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
655 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
656 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
657 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
660 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
661 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
662 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
663 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
664 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
665 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
666 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
667 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
668 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
669 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
670 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
671 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
672 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
673 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
674 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
675 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
676 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
677 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
678 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
679 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
681 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
682 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
683 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
684 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
685 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
686 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
687 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
688 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
689 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
690 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
691 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
692 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
693 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
694 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
695 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
696 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
697 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
698 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
699 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
700 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
702 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
703 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
704 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
705 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
706 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
707 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
708 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
709 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
710 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
711 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
712 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
713 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
714 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
715 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
716 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
717 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
718 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
719 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
720 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
721 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
723 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
724 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
725 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
726 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
727 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
728 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
729 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
730 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
731 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
732 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
733 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
734 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
735 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
736 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
737 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
738 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
739 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
740 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
741 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
742 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
744 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
745 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
746 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
747 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
748 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
749 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
750 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
751 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
752 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
753 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
754 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
755 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
756 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
757 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
758 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
759 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
760 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
761 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
762 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
763 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
765 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
766 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
767 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
768 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
769 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
770 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
771 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
772 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
773 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
774 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
775 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
776 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
777 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
778 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
779 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
780 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
781 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
782 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
783 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
784 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
786 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
787 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
788 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
789 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
790 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
791 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
792 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
793 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
794 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
795 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
796 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
797 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
798 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
799 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
800 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
801 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
802 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
803 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
804 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
805 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
810 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
812 #ifdef FRONTEND_SUPPORTS_RGB565
813 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
814 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
815 SysPrintf("RGB565 supported, using it\n");
819 if (info == NULL || info->path == NULL) {
820 SysPrintf("info->path required\n");
824 if (plugins_opened) {
829 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
830 if (disks[i].fname != NULL) {
831 free(disks[i].fname);
832 disks[i].fname = NULL;
834 disks[i].internal_index = 0;
837 disk_current_index = 0;
838 extract_directory(base_dir, info->path, sizeof(base_dir));
841 if (!read_m3u(info->path)) {
842 SysPrintf("failed to read m3u file\n");
847 disks[0].fname = strdup(info->path);
850 set_cd_image(disks[0].fname);
852 /* have to reload after set_cd_image for correct cdr plugin */
853 if (LoadPlugins() == -1) {
854 SysPrintf("failed to load plugins\n");
861 if (OpenPlugins() == -1) {
862 SysPrintf("failed to open plugins\n");
866 plugin_call_rearmed_cbs();
870 if (CheckCdrom() == -1) {
871 SysPrintf("unsupported/invalid CD image: %s\n", info->path);
877 if (LoadCdrom() == -1) {
878 SysPrintf("could not load CD-ROM!\n");
885 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
886 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
887 disks[i].fname = strdup(info->path);
888 disks[i].internal_index = i;
895 bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
900 void retro_unload_game(void)
904 unsigned retro_get_region(void)
906 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
909 void *retro_get_memory_data(unsigned id)
911 if (id == RETRO_MEMORY_SAVE_RAM)
917 size_t retro_get_memory_size(unsigned id)
919 if (id == RETRO_MEMORY_SAVE_RAM)
925 void retro_reset(void)
930 static const unsigned short retro_psx_map[] = {
931 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
932 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
933 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
934 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
935 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
936 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
937 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
938 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
939 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
940 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
941 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
942 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
943 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
944 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
945 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
946 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
948 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
950 static void update_variables(bool in_flight)
952 struct retro_variable var;
955 var.key = "pcsx_rearmed_frameskip";
957 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
958 pl_rearmed_cbs.frameskip = atoi(var.value);
961 var.key = "pcsx_rearmed_region";
963 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
966 if (strcmp(var.value, "Automatic") == 0)
968 else if (strcmp(var.value, "NTSC") == 0)
970 else if (strcmp(var.value, "PAL") == 0)
975 var.key = "pcsx_rearmed_pad1type";
977 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
979 in_type1 = PSE_PAD_TYPE_STANDARD;
980 if (strcmp(var.value, "analog") == 0)
981 in_type1 = PSE_PAD_TYPE_ANALOGPAD;
985 var.key = "pcsx_rearmed_pad2type";
987 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
989 in_type2 = PSE_PAD_TYPE_STANDARD;
990 if (strcmp(var.value, "analog") == 0)
991 in_type2 = PSE_PAD_TYPE_ANALOGPAD;
996 var.key = "pcsx_rearmed_neon_interlace_enable";
998 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1000 if (strcmp(var.value, "disabled") == 0)
1001 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1002 else if (strcmp(var.value, "enabled") == 0)
1003 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1007 var.key = "pcsx_rearmed_neon_enhancement_enable";
1009 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1011 if (strcmp(var.value, "disabled") == 0)
1012 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1013 else if (strcmp(var.value, "enabled") == 0)
1014 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1018 var.key = "pcsx_rearmed_neon_enhancement_no_main";
1020 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1022 if (strcmp(var.value, "disabled") == 0)
1023 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1024 else if (strcmp(var.value, "enabled") == 0)
1025 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1030 var.key = "pcsx_rearmed_duping_enable";
1032 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1034 if (strcmp(var.value, "off") == 0)
1035 duping_enable = false;
1036 else if (strcmp(var.value, "on") == 0)
1037 duping_enable = true;
1042 var.key = "pcsx_rearmed_drc";
1044 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1046 R3000Acpu *prev_cpu = psxCpu;
1048 if (strcmp(var.value, "disabled") == 0)
1049 Config.Cpu = CPU_INTERPRETER;
1050 else if (strcmp(var.value, "enabled") == 0)
1051 Config.Cpu = CPU_DYNAREC;
1053 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1054 if (psxCpu != prev_cpu) {
1055 prev_cpu->Shutdown();
1057 psxCpu->Reset(); // not really a reset..
1063 var.key = "pcsx_rearmed_spu_reverb";
1065 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1067 if (strcmp(var.value, "off") == 0)
1068 spu_config.iUseReverb = false;
1069 else if (strcmp(var.value, "on") == 0)
1070 spu_config.iUseReverb = true;
1074 var.key = "pcsx_rearmed_spu_interpolation";
1076 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1078 if (strcmp(var.value, "simple") == 0)
1079 spu_config.iUseInterpolation = 1;
1080 else if (strcmp(var.value, "gaussian") == 0)
1081 spu_config.iUseInterpolation = 2;
1082 else if (strcmp(var.value, "cubic") == 0)
1083 spu_config.iUseInterpolation = 3;
1084 else if (strcmp(var.value, "off") == 0)
1085 spu_config.iUseInterpolation = 0;
1089 // inform core things about possible config changes
1090 plugin_call_rearmed_cbs();
1092 if (GPU_open != NULL && GPU_close != NULL) {
1094 GPU_open(&gpuDisp, "PCSX", NULL);
1101 void retro_run(void)
1107 bool updated = false;
1108 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1109 update_variables(true);
1112 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
1113 if (input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, i))
1114 in_keystate |= retro_psx_map[i];
1116 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
1117 if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i))
1118 in_keystate |= retro_psx_map[i];
1120 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD)
1122 in_a1[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1123 in_a1[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1124 in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1125 in_a2[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1131 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf : NULL,
1132 vout_width, vout_height, vout_width * 2);
1136 static bool try_use_bios(const char *path)
1142 f = fopen(path, "rb");
1146 fseek(f, 0, SEEK_END);
1150 if (size != 512 * 1024)
1153 name = strrchr(path, SLASH);
1156 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1161 #include <sys/types.h>
1164 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1170 dir = opendir(dirpath);
1174 while ((ent = readdir(dir))) {
1175 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1178 snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
1179 ret = try_use_bios(path);
1187 #define find_any_bios(...) false
1190 static void check_system_specs(void)
1193 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1196 void retro_init(void)
1198 const char *bios[] = { "scph1001", "scph5501", "scph7001" };
1202 bool found_bios = false;
1204 ret = emu_core_preinit();
1205 ret |= emu_core_init();
1207 SysPrintf("PCSX init failed.\n");
1211 #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)
1212 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1214 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1217 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1219 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s/", dir);
1221 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1222 snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
1223 found_bios = try_use_bios(path);
1229 found_bios = find_any_bios(dir, path, sizeof(path));
1232 SysPrintf("found BIOS file: %s\n", Config.Bios);
1236 SysPrintf("no BIOS files found.\n");
1237 struct retro_message msg =
1239 "no BIOS found, expect bugs!",
1242 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1245 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1246 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1247 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1249 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1250 * we have to do this because cache misses and some IO penalties
1251 * are not emulated. Warning: changing this may break compatibility. */
1252 #if !defined(__arm__) || defined(__ARM_ARCH_7A__)
1253 cycle_multiplier = 175;
1255 cycle_multiplier = 200;
1257 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1261 init_memcard(Mcd1Data);
1263 SaveFuncs.open = save_open;
1264 SaveFuncs.read = save_read;
1265 SaveFuncs.write = save_write;
1266 SaveFuncs.seek = save_seek;
1267 SaveFuncs.close = save_close;
1269 update_variables(false);
1270 check_system_specs();
1273 void retro_deinit(void)