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/dfinput/externals.h"
26 #include "plugin_lib.h"
30 static retro_video_refresh_t video_cb;
31 static retro_input_poll_t input_poll_cb;
32 static retro_input_state_t input_state_cb;
33 static retro_environment_t environ_cb;
34 static retro_audio_sample_batch_t audio_batch_cb;
35 static struct retro_rumble_interface rumble;
37 static void *vout_buf;
38 static int vout_width, vout_height;
39 static int vout_doffs_old, vout_fb_dirty;
40 static bool vout_can_dupe;
41 static bool duping_enable;
43 static int samples_sent, samples_to_send;
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, uint32_t low, uint32_t 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)
222 if (samples_to_send > samples_sent)
223 return 0; /* give more samples */
228 static void snd_feed(void *buf, int bytes)
230 audio_batch_cb(buf, bytes / 4);
231 samples_sent += bytes / 4;
234 void out_register_libretro(struct out_driver *drv)
236 drv->name = "libretro";
237 drv->init = snd_init;
238 drv->finish = snd_finish;
239 drv->busy = snd_busy;
240 drv->feed = snd_feed;
244 void retro_set_environment(retro_environment_t cb)
246 static const struct retro_variable vars[] = {
247 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
248 { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
249 { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog" },
250 { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog" },
252 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
254 #if defined(__ARM_NEON__) || defined(NEON_PC)
255 { "neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
256 { "neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
257 { "neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
259 { "pcsx_rearmed_duping_enable", "Frame duping; on|off" },
265 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
268 void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
269 void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
270 void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
271 void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
272 void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
274 unsigned retro_api_version(void)
276 return RETRO_API_VERSION;
279 void retro_set_controller_port_device(unsigned port, unsigned device)
283 void retro_get_system_info(struct retro_system_info *info)
285 memset(info, 0, sizeof(*info));
286 info->library_name = "PCSX-ReARMed";
287 info->library_version = "r19";
288 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
289 info->need_fullpath = true;
292 void retro_get_system_av_info(struct retro_system_av_info *info)
294 memset(info, 0, sizeof(*info));
295 info->timing.fps = is_pal_mode ? 50 : 60;
296 info->timing.sample_rate = 44100;
297 info->geometry.base_width = 320;
298 info->geometry.base_height = 240;
299 info->geometry.max_width = VOUT_MAX_WIDTH;
300 info->geometry.max_height = VOUT_MAX_HEIGHT;
301 info->geometry.aspect_ratio = 4.0 / 3.0;
305 size_t retro_serialize_size(void)
307 // it's currently 4380651 bytes, 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, '\\');
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 #ifdef FRONTEND_SUPPORTS_RGB565
638 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
639 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
640 SysPrintf("RGB565 supported, using it\n");
644 if (info == NULL || info->path == NULL) {
645 SysPrintf("info->path required\n");
649 if (plugins_opened) {
654 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
655 if (disks[i].fname != NULL) {
656 free(disks[i].fname);
657 disks[i].fname = NULL;
659 disks[i].internal_index = 0;
662 disk_current_index = 0;
663 extract_directory(base_dir, info->path, sizeof(base_dir));
666 if (!read_m3u(info->path)) {
667 SysPrintf("failed to read m3u file\n");
672 disks[0].fname = strdup(info->path);
675 set_cd_image(disks[0].fname);
677 /* have to reload after set_cd_image for correct cdr plugin */
678 if (LoadPlugins() == -1) {
679 SysPrintf("failed to load plugins\n");
686 if (OpenPlugins() == -1) {
687 SysPrintf("failed to open plugins\n");
691 plugin_call_rearmed_cbs();
695 if (CheckCdrom() == -1) {
696 SysPrintf("unsupported/invalid CD image: %s\n", info->path);
702 if (LoadCdrom() == -1) {
703 SysPrintf("could not load CD-ROM!\n");
710 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
711 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
712 disks[i].fname = strdup(info->path);
713 disks[i].internal_index = i;
720 bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
725 void retro_unload_game(void)
729 unsigned retro_get_region(void)
731 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
734 void *retro_get_memory_data(unsigned id)
736 if (id == RETRO_MEMORY_SAVE_RAM)
742 size_t retro_get_memory_size(unsigned id)
744 if (id == RETRO_MEMORY_SAVE_RAM)
750 void retro_reset(void)
755 static const unsigned short retro_psx_map[] = {
756 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
757 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
758 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
759 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
760 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
761 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
762 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
763 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
764 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
765 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
766 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
767 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
768 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
769 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
770 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
771 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
773 #define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
775 static void update_variables(bool in_flight)
777 struct retro_variable var;
780 var.key = "pcsx_rearmed_frameskip";
782 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
783 pl_rearmed_cbs.frameskip = atoi(var.value);
786 var.key = "pcsx_rearmed_region";
788 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
791 if (strcmp(var.value, "Automatic") == 0)
793 else if (strcmp(var.value, "NTSC") == 0)
795 else if (strcmp(var.value, "PAL") == 0)
800 var.key = "pcsx_rearmed_pad1type";
802 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
804 in_type1 = PSE_PAD_TYPE_STANDARD;
805 if (strcmp(var.value, "analog") == 0)
806 in_type1 = PSE_PAD_TYPE_ANALOGPAD;
810 var.key = "pcsx_rearmed_pad2type";
812 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
814 in_type2 = PSE_PAD_TYPE_STANDARD;
815 if (strcmp(var.value, "analog") == 0)
816 in_type2 = PSE_PAD_TYPE_ANALOGPAD;
819 #if defined(__ARM_NEON__) || defined(NEON_PC)
821 var.key = "neon_interlace_enable";
823 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
825 if (strcmp(var.value, "disabled") == 0)
826 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
827 else if (strcmp(var.value, "enabled") == 0)
828 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
832 var.key = "neon_enhancement_enable";
834 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
836 if (strcmp(var.value, "disabled") == 0)
837 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
838 else if (strcmp(var.value, "enabled") == 0)
839 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
843 var.key = "neon_enhancement_no_main";
845 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
847 if (strcmp(var.value, "disabled") == 0)
848 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
849 else if (strcmp(var.value, "enabled") == 0)
850 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
855 var.key = "pcsx_rearmed_duping_enable";
857 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
859 if (strcmp(var.value, "off") == 0)
860 duping_enable = false;
861 else if (strcmp(var.value, "on") == 0)
862 duping_enable = true;
867 var.key = "pcsx_rearmed_drc";
869 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
871 R3000Acpu *prev_cpu = psxCpu;
873 if (strcmp(var.value, "disabled") == 0)
874 Config.Cpu = CPU_INTERPRETER;
875 else if (strcmp(var.value, "enabled") == 0)
876 Config.Cpu = CPU_DYNAREC;
878 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
879 if (psxCpu != prev_cpu) {
880 prev_cpu->Shutdown();
882 psxCpu->Reset(); // not really a reset..
888 // inform core things about possible config changes
889 plugin_call_rearmed_cbs();
891 if (GPU_open != NULL && GPU_close != NULL) {
893 GPU_open(&gpuDisp, "PCSX", NULL);
906 bool updated = false;
907 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
908 update_variables(true);
911 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
912 if (input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, i))
913 in_keystate |= retro_psx_map[i];
915 for (i = 0; i < RETRO_PSX_MAP_LEN; i++)
916 if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i))
917 in_keystate |= retro_psx_map[i];
919 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD)
921 in_a1[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
922 in_a1[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
923 in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
924 in_a2[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
930 samples_to_send += is_pal_mode ? 44100 / 50 : 44100 / 60;
932 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf : NULL,
933 vout_width, vout_height, vout_width * 2);
937 static bool try_use_bios(const char *path)
943 f = fopen(path, "rb");
947 fseek(f, 0, SEEK_END);
951 if (size != 512 * 1024)
954 name = strrchr(path, SLASH);
957 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
962 #include <sys/types.h>
965 static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
971 dir = opendir(dirpath);
975 while ((ent = readdir(dir))) {
976 if (strncasecmp(ent->d_name, "scph", 4) != 0)
979 snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
980 ret = try_use_bios(path);
988 #define find_any_bios(...) false
991 static void check_system_specs(void)
994 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
997 void retro_init(void)
999 const char *bios[] = { "scph1001", "scph5501", "scph7001" };
1003 bool found_bios = false;
1005 ret = emu_core_preinit();
1006 ret |= emu_core_init();
1008 SysPrintf("PCSX init failed.\n");
1012 #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)
1013 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1015 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1018 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1020 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s/", dir);
1022 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1023 snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
1024 found_bios = try_use_bios(path);
1030 found_bios = find_any_bios(dir, path, sizeof(path));
1033 SysPrintf("found BIOS file: %s\n", Config.Bios);
1037 SysPrintf("no BIOS files found.\n");
1038 struct retro_message msg =
1040 "no BIOS found, expect bugs!",
1043 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1047 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1049 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
1050 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
1051 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1053 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1054 * we have to do this because cache misses and some IO penalties
1055 * are not emulated. Warning: changing this may break compatibility. */
1056 #ifdef __ARM_ARCH_7A__
1057 cycle_multiplier = 175;
1059 cycle_multiplier = 200;
1064 init_memcard(Mcd1Data);
1066 SaveFuncs.open = save_open;
1067 SaveFuncs.read = save_read;
1068 SaveFuncs.write = save_write;
1069 SaveFuncs.seek = save_seek;
1070 SaveFuncs.close = save_close;
1072 update_variables(false);
1073 check_system_specs();
1076 void retro_deinit(void)