Add PSE_PAD_TYPE_NONE
[pcsx_rearmed.git] / frontend / libretro.c
CommitLineData
38c2028e 1/*
003cfc63 2 * (C) notaz, 2012,2014,2015
38c2028e 3 *
4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
6 */
7
805fe9bc 8#define _GNU_SOURCE 1 // strcasestr
38c2028e 9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
74ebc05b 12#include <strings.h>
38c2028e 13
14#include "../libpcsxcore/misc.h"
15#include "../libpcsxcore/psxcounters.h"
87e5b45f 16#include "../libpcsxcore/psxmem_map.h"
38c2028e 17#include "../libpcsxcore/new_dynarec/new_dynarec.h"
23ea11bd 18#include "../libpcsxcore/cdrom.h"
19#include "../libpcsxcore/cdriso.h"
6e921e1d 20#include "../libpcsxcore/cheat.h"
07c13dfd 21#include "../plugins/dfsound/out.h"
01394a7f 22#include "../plugins/dfsound/spu_config.h"
805fe9bc 23#include "../plugins/dfinput/externals.h"
c82f907a 24#include "cspace.h"
38c2028e 25#include "main.h"
26#include "plugin.h"
27#include "plugin_lib.h"
ace14ab3 28#include "arm_features.h"
38c2028e 29#include "revision.h"
30#include "libretro.h"
31
fc99395c 32#ifdef _3DS
fc99395c 33#include "3ds/3ds_utils.h"
fc99395c 34#endif
35
8136cafb
AP
36#define PORTS_NUMBER 8
37
38c2028e 38static retro_video_refresh_t video_cb;
39static retro_input_poll_t input_poll_cb;
40static retro_input_state_t input_state_cb;
41static retro_environment_t environ_cb;
42static retro_audio_sample_batch_t audio_batch_cb;
4e477065 43static struct retro_rumble_interface rumble;
38c2028e 44
45static void *vout_buf;
70d56ca3 46static int vout_width, vout_height;
47static int vout_doffs_old, vout_fb_dirty;
1a6164a1 48static bool vout_can_dupe;
0e5a7b7d 49static bool duping_enable;
70d56ca3 50
38c2028e 51static int plugins_opened;
17f84149 52static int is_pal_mode;
38c2028e 53
f9f60dae
TK
54/* memory card data */
55extern char Mcd1Data[MCD_SIZE];
56extern char McdDisable[2];
38c2028e 57
58/* PCSX ReARMed core calls and stuff */
c663ec74 59int in_type[8] = { PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
60 PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
61 PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD,
62 PSE_PAD_TYPE_STANDARD, PSE_PAD_TYPE_STANDARD };
61c4962a 63int in_analog_left[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
64int in_analog_right[8][2] = {{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 },{ 127, 127 }};
3c0fb554 65unsigned short in_keystate[PORTS_NUMBER];
29f3675b 66int multitap1 = 0;
67int multitap2 = 0;
4e477065 68int in_enable_vibration = 1;
38c2028e 69
805fe9bc 70/* PSX max resolution is 640x512, but with enhancement it's 1024x512 */
71#define VOUT_MAX_WIDTH 1024
72#define VOUT_MAX_HEIGHT 512
73
7df396ea
TK
74static void init_memcard(char *mcd_data)
75{
76 unsigned off = 0;
77 unsigned i;
78
79 memset(mcd_data, 0, MCD_SIZE);
80
81 mcd_data[off++] = 'M';
82 mcd_data[off++] = 'C';
83 off += 0x7d;
84 mcd_data[off++] = 0x0e;
85
86 for (i = 0; i < 15; i++) {
87 mcd_data[off++] = 0xa0;
88 off += 0x07;
89 mcd_data[off++] = 0xff;
90 mcd_data[off++] = 0xff;
91 off += 0x75;
92 mcd_data[off++] = 0xa0;
93 }
94
95 for (i = 0; i < 20; i++) {
96 mcd_data[off++] = 0xff;
97 mcd_data[off++] = 0xff;
98 mcd_data[off++] = 0xff;
99 mcd_data[off++] = 0xff;
100 off += 0x04;
101 mcd_data[off++] = 0xff;
102 mcd_data[off++] = 0xff;
103 off += 0x76;
104 }
105}
106
38c2028e 107static int vout_open(void)
108{
109 return 0;
110}
111
e4c83ca6 112static void vout_set_mode(int w, int h, int raw_w, int raw_h, int bpp)
38c2028e 113{
70d56ca3 114 vout_width = w;
115 vout_height = h;
38c2028e 116}
117
cc4f9b70 118#ifndef FRONTEND_SUPPORTS_RGB565
9c59f120 119static void convert(void *buf, size_t bytes)
38c2028e 120{
121 unsigned int i, v, *p = buf;
122
9c59f120 123 for (i = 0; i < bytes / 4; i++) {
38c2028e 124 v = p[i];
125 p[i] = (v & 0x001f001f) | ((v >> 1) & 0x7fe07fe0);
126 }
127}
46aa5b98 128#endif
38c2028e 129
fa56d360 130static void vout_flip(const void *vram, int stride, int bgr24, int w, int h)
38c2028e 131{
fa56d360 132 unsigned short *dest = vout_buf;
133 const unsigned short *src = vram;
70d56ca3 134 int dstride = vout_width, h1 = h;
135 int doffs;
38c2028e 136
fa56d360 137 if (vram == NULL) {
138 // blanking
cc56203b 139 memset(vout_buf, 0, dstride * h * 2);
fa56d360 140 goto out;
141 }
142
70d56ca3 143 doffs = (vout_height - h) * dstride;
144 doffs += (dstride - w) / 2 & ~1;
145 if (doffs != vout_doffs_old) {
146 // clear borders
147 memset(vout_buf, 0, dstride * h * 2);
148 vout_doffs_old = doffs;
149 }
150 dest += doffs;
151
fa56d360 152 if (bgr24)
153 {
154 // XXX: could we switch to RETRO_PIXEL_FORMAT_XRGB8888 here?
155 for (; h1-- > 0; dest += dstride, src += stride)
156 {
157 bgr888_to_rgb565(dest, src, w * 3);
158 }
159 }
160 else
161 {
162 for (; h1-- > 0; dest += dstride, src += stride)
163 {
164 bgr555_to_rgb565(dest, src, w * 2);
165 }
166 }
38c2028e 167
fa56d360 168out:
46aa5b98 169#ifndef FRONTEND_SUPPORTS_RGB565
70d56ca3 170 convert(vout_buf, vout_width * vout_height * 2);
46aa5b98 171#endif
70d56ca3 172 vout_fb_dirty = 1;
fa56d360 173 pl_rearmed_cbs.flip_cnt++;
38c2028e 174}
175
176static void vout_close(void)
177{
178}
179
fc99395c 180#ifdef _3DS
181typedef struct
182{
183 void* buffer;
184 uint32_t target_map;
185 size_t size;
186 enum psxMapTag tag;
187}psx_map_t;
188
189psx_map_t custom_psx_maps[] = {
190 {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000
191 {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000
192 {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000
193 {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000
194 {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000
195};
196
197void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed,
198 enum psxMapTag tag)
199{
200 (void)is_fixed;
201 (void)addr;
202
f72db18e 203 if (__ctr_svchax)
fc99395c 204 {
205 psx_map_t* custom_map = custom_psx_maps;
206
207 for (; custom_map->size; custom_map++)
208 {
209 if ((custom_map->size == size) && (custom_map->tag == tag))
210 {
211 uint32_t ptr_aligned, tmp;
212
213 custom_map->buffer = malloc(size + 0x1000);
214 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
215
f72db18e 216 if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0)
fc99395c 217 {
218 SysPrintf("could not map memory @0x%08X\n", custom_map->target_map);
219 exit(1);
220 }
221
222 return (void*)custom_map->target_map;
223 }
224 }
225 }
226
227 return malloc(size);
228}
229
230void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag)
cc56203b 231{
fc99395c 232 (void)tag;
233
f72db18e 234 if (__ctr_svchax)
fc99395c 235 {
236 psx_map_t* custom_map = custom_psx_maps;
237
238 for (; custom_map->size; custom_map++)
239 {
240 if ((custom_map->target_map == (uint32_t)ptr))
241 {
242 uint32_t ptr_aligned, tmp;
243
244 ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF;
245
f72db18e 246 svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3);
fc99395c 247
248 free(custom_map->buffer);
249 custom_map->buffer = NULL;
250 return;
251 }
252 }
253 }
254
255 free(ptr);
256}
257#endif
258
259static void *pl_mmap(unsigned int size)
ace14ab3 260{
87e5b45f 261 return psxMap(0, size, 0, MAP_TAG_VRAM);
cc56203b 262}
263
264static void pl_munmap(void *ptr, unsigned int size)
265{
87e5b45f 266 psxUnmap(ptr, size, MAP_TAG_VRAM);
cc56203b 267}
268
38c2028e 269struct rearmed_cbs pl_rearmed_cbs = {
270 .pl_vout_open = vout_open,
271 .pl_vout_set_mode = vout_set_mode,
272 .pl_vout_flip = vout_flip,
273 .pl_vout_close = vout_close,
cc56203b 274 .mmap = pl_mmap,
275 .munmap = pl_munmap,
38c2028e 276 /* from psxcounters */
277 .gpu_hcnt = &hSyncCount,
278 .gpu_frame_count = &frame_counter,
279};
280
281void pl_frame_limit(void)
282{
283 /* called once per frame, make psxCpu->Execute() above return */
284 stop = 1;
285}
286
287void pl_timing_prepare(int is_pal)
288{
17f84149 289 is_pal_mode = is_pal;
38c2028e 290}
291
d71c7095 292void plat_trigger_vibrate(int pad, int low, int high)
38c2028e 293{
4e477065 294 rumble.set_rumble_state(pad, RETRO_RUMBLE_STRONG, high << 8);
295 rumble.set_rumble_state(pad, RETRO_RUMBLE_WEAK, low ? 0xffff : 0x0);
38c2028e 296}
297
e4c83ca6 298void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
38c2028e 299{
300}
301
302/* sound calls */
07c13dfd 303static int snd_init(void)
38c2028e 304{
07c13dfd 305 return 0;
38c2028e 306}
307
07c13dfd 308static void snd_finish(void)
38c2028e 309{
310}
311
07c13dfd 312static int snd_busy(void)
38c2028e 313{
db126209 314 return 0;
38c2028e 315}
316
07c13dfd 317static void snd_feed(void *buf, int bytes)
38c2028e 318{
db126209 319 if (audio_batch_cb != NULL)
320 audio_batch_cb(buf, bytes / 4);
38c2028e 321}
322
07c13dfd 323void out_register_libretro(struct out_driver *drv)
324{
325 drv->name = "libretro";
326 drv->init = snd_init;
327 drv->finish = snd_finish;
328 drv->busy = snd_busy;
329 drv->feed = snd_feed;
330}
331
38c2028e 332/* libretro */
e268a47e 333void retro_set_environment(retro_environment_t cb)
334{
e268a47e 335 static const struct retro_variable vars[] = {
4e477065 336 { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" },
337 { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" },
3c0fb554
AP
338 { "pcsx_rearmed_pad1type", "Pad 1 Type; none|standard|analog|negcon" },
339 { "pcsx_rearmed_pad2type", "Pad 2 Type; none|standard|analog|negcon" },
340 { "pcsx_rearmed_pad3type", "Pad 3 Type; none|standard|analog|negcon" },
341 { "pcsx_rearmed_pad4type", "Pad 4 Type; none|standard|analog|negcon" },
342 { "pcsx_rearmed_pad5type", "Pad 5 Type; none|standard|analog|negcon" },
343 { "pcsx_rearmed_pad6type", "Pad 6 Type; none|standard|analog|negcon" },
344 { "pcsx_rearmed_pad7type", "Pad 7 Type; none|standard|analog|negcon" },
345 { "pcsx_rearmed_pad8type", "Pad 8 Type; none|standard|analog|negcon" },
ace14ab3 346 { "pcsx_rearmed_multitap1", "Multitap 1; disabled|enabled" },
347 { "pcsx_rearmed_multitap2", "Multitap 2; disabled|enabled" },
48f615ba 348#ifndef DRC_DISABLE
4e477065 349 { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" },
48f615ba 350#endif
7d68d030 351#ifdef __ARM_NEON__
55e5626b 352 { "pcsx_rearmed_neon_interlace_enable", "Enable interlacing mode(s); disabled|enabled" },
353 { "pcsx_rearmed_neon_enhancement_enable", "Enhanced resolution (slow); disabled|enabled" },
354 { "pcsx_rearmed_neon_enhancement_no_main", "Enhanced resolution speed hack; disabled|enabled" },
7d68d030 355#endif
0e5a7b7d 356 { "pcsx_rearmed_duping_enable", "Frame duping; on|off" },
01394a7f 357 { "pcsx_rearmed_spu_reverb", "Sound: Reverb; on|off" },
358 { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" },
b3480be8 359 { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" },
360 { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" },
e268a47e 361 { NULL, NULL },
362 };
363
364 environ_cb = cb;
365
366 cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
e268a47e 367}
368
38c2028e 369void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
370void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
371void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
372void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
373void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
374
375unsigned retro_api_version(void)
376{
377 return RETRO_API_VERSION;
378}
379
8136cafb
AP
380static void update_controller_port_device(unsigned port)
381{
382 if (port >= PORTS_NUMBER)
383 return;
384
385 static const char **CONTROLLER_VARIABLE = {
386 "pcsx_rearmed_pad1type", "pcsx_rearmed_pad2type",
387 "pcsx_rearmed_pad3type", "pcsx_rearmed_pad4type",
388 "pcsx_rearmed_pad5type", "pcsx_rearmed_pad6type",
389 "pcsx_rearmed_pad7type", "pcsx_rearmed_pad8type",
390 };
391
392 struct retro_variable var;
393
394 var.value = NULL;
395 var.key = "pcsx_rearmed_pad1type";
396 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
397 {
3c0fb554
AP
398 if (strcmp(var.value, "standard") == 0)
399 in_type[0] = PSE_PAD_TYPE_STANDARD;
400 else if (strcmp(var.value, "analog") == 0)
8136cafb
AP
401 in_type[0] = PSE_PAD_TYPE_ANALOGPAD;
402 else if (strcmp(var.value, "negcon") == 0)
403 in_type[0] = PSE_PAD_TYPE_NEGCON;
3c0fb554
AP
404 else // 'none' case
405 in_type[0] = PSE_PAD_TYPE_NONE;
8136cafb
AP
406 }
407}
408
38c2028e 409void retro_set_controller_port_device(unsigned port, unsigned device)
410{
ace14ab3 411 SysPrintf("port %u device %u",port,device);
38c2028e 412}
413
414void retro_get_system_info(struct retro_system_info *info)
415{
416 memset(info, 0, sizeof(*info));
417 info->library_name = "PCSX-ReARMed";
bf48d3aa 418 info->library_version = "r22";
9fba39a9 419 info->valid_extensions = "bin|cue|img|mdf|pbp|toc|cbn|m3u";
38c2028e 420 info->need_fullpath = true;
421}
422
423void retro_get_system_av_info(struct retro_system_av_info *info)
424{
425 memset(info, 0, sizeof(*info));
17f84149 426 info->timing.fps = is_pal_mode ? 50 : 60;
38c2028e 427 info->timing.sample_rate = 44100;
428 info->geometry.base_width = 320;
429 info->geometry.base_height = 240;
805fe9bc 430 info->geometry.max_width = VOUT_MAX_WIDTH;
431 info->geometry.max_height = VOUT_MAX_HEIGHT;
38c2028e 432 info->geometry.aspect_ratio = 4.0 / 3.0;
433}
434
6e921e1d 435/* savestates */
ace14ab3 436size_t retro_serialize_size(void)
437{
03f55e6b 438 // it's currently 4380651-4397047 bytes,
439 // but have some reserved for future
440 return 0x440000;
6e921e1d 441}
442
443struct save_fp {
444 char *buf;
445 size_t pos;
446 int is_write;
447};
448
449static void *save_open(const char *name, const char *mode)
450{
451 struct save_fp *fp;
452
453 if (name == NULL || mode == NULL)
454 return NULL;
455
456 fp = malloc(sizeof(*fp));
457 if (fp == NULL)
458 return NULL;
459
460 fp->buf = (char *)name;
461 fp->pos = 0;
462 fp->is_write = (mode[0] == 'w' || mode[1] == 'w');
463
464 return fp;
465}
466
467static int save_read(void *file, void *buf, u32 len)
468{
469 struct save_fp *fp = file;
470 if (fp == NULL || buf == NULL)
471 return -1;
472
473 memcpy(buf, fp->buf + fp->pos, len);
474 fp->pos += len;
475 return len;
476}
477
478static int save_write(void *file, const void *buf, u32 len)
479{
480 struct save_fp *fp = file;
481 if (fp == NULL || buf == NULL)
482 return -1;
483
484 memcpy(fp->buf + fp->pos, buf, len);
485 fp->pos += len;
486 return len;
487}
488
489static long save_seek(void *file, long offs, int whence)
490{
491 struct save_fp *fp = file;
492 if (fp == NULL)
493 return -1;
494
495 switch (whence) {
496 case SEEK_CUR:
497 fp->pos += offs;
498 return fp->pos;
499 case SEEK_SET:
500 fp->pos = offs;
501 return fp->pos;
502 default:
503 return -1;
504 }
505}
506
507static void save_close(void *file)
508{
509 struct save_fp *fp = file;
510 size_t r_size = retro_serialize_size();
511 if (fp == NULL)
512 return;
513
514 if (fp->pos > r_size)
515 SysPrintf("ERROR: save buffer overflow detected\n");
516 else if (fp->is_write && fp->pos < r_size)
517 // make sure we don't save trash in leftover space
518 memset(fp->buf + fp->pos, 0, r_size - fp->pos);
519 free(fp);
38c2028e 520}
521
522bool retro_serialize(void *data, size_t size)
ace14ab3 523{
6e921e1d 524 int ret = SaveState(data);
525 return ret == 0 ? true : false;
38c2028e 526}
527
528bool retro_unserialize(const void *data, size_t size)
529{
6e921e1d 530 int ret = LoadState(data);
531 return ret == 0 ? true : false;
38c2028e 532}
533
23ea11bd 534/* cheats */
38c2028e 535void retro_cheat_reset(void)
536{
6e921e1d 537 ClearAllCheats();
38c2028e 538}
539
540void retro_cheat_set(unsigned index, bool enabled, const char *code)
541{
6e921e1d 542 char buf[256];
543 int ret;
544
545 // cheat funcs are destructive, need a copy..
546 strncpy(buf, code, sizeof(buf));
547 buf[sizeof(buf) - 1] = 0;
548
549 if (index < NumCheats)
550 ret = EditCheat(index, "", buf);
551 else
552 ret = AddCheat("", buf);
553
554 if (ret != 0)
555 SysPrintf("Failed to set cheat %#u\n", index);
556 else if (index < NumCheats)
557 Cheats[index].Enabled = enabled;
38c2028e 558}
559
23ea11bd 560/* multidisk support */
561static bool disk_ejected;
562static unsigned int disk_current_index;
51ba7408 563static unsigned int disk_count;
23ea11bd 564static struct disks_state {
565 char *fname;
566 int internal_index; // for multidisk eboots
567} disks[8];
568
569static bool disk_set_eject_state(bool ejected)
570{
571 // weird PCSX API..
572 SetCdOpenCaseTime(ejected ? -1 : (time(NULL) + 2));
573 LidInterrupt();
574
575 disk_ejected = ejected;
576 return true;
577}
578
579static bool disk_get_eject_state(void)
580{
581 /* can't be controlled by emulated software */
582 return disk_ejected;
583}
584
585static unsigned int disk_get_image_index(void)
586{
587 return disk_current_index;
588}
589
590static bool disk_set_image_index(unsigned int index)
591{
592 if (index >= sizeof(disks) / sizeof(disks[0]))
593 return false;
594
595 CdromId[0] = '\0';
596 CdromLabel[0] = '\0';
597
598 if (disks[index].fname == NULL) {
599 SysPrintf("missing disk #%u\n", index);
600 CDR_shutdown();
601
602 // RetroArch specifies "no disk" with index == count,
603 // so don't fail here..
604 disk_current_index = index;
605 return true;
606 }
607
608 SysPrintf("switching to disk %u: \"%s\" #%d\n", index,
609 disks[index].fname, disks[index].internal_index);
610
611 cdrIsoMultidiskSelect = disks[index].internal_index;
612 set_cd_image(disks[index].fname);
613 if (ReloadCdromPlugin() < 0) {
614 SysPrintf("failed to load cdr plugin\n");
615 return false;
616 }
617 if (CDR_open() < 0) {
618 SysPrintf("failed to open cdr plugin\n");
619 return false;
620 }
621
622 if (!disk_ejected) {
623 SetCdOpenCaseTime(time(NULL) + 2);
624 LidInterrupt();
625 }
626
627 disk_current_index = index;
628 return true;
629}
630
631static unsigned int disk_get_num_images(void)
632{
51ba7408 633 return disk_count;
23ea11bd 634}
635
636static bool disk_replace_image_index(unsigned index,
637 const struct retro_game_info *info)
638{
639 char *old_fname;
640 bool ret = true;
641
642 if (index >= sizeof(disks) / sizeof(disks[0]))
643 return false;
644
645 old_fname = disks[index].fname;
646 disks[index].fname = NULL;
647 disks[index].internal_index = 0;
648
649 if (info != NULL) {
650 disks[index].fname = strdup(info->path);
651 if (index == disk_current_index)
652 ret = disk_set_image_index(index);
653 }
654
655 if (old_fname != NULL)
656 free(old_fname);
657
658 return ret;
659}
660
661static bool disk_add_image_index(void)
662{
51ba7408
T
663 if (disk_count >= 8)
664 return false;
665
666 disk_count++;
23ea11bd 667 return true;
668}
669
670static struct retro_disk_control_callback disk_control = {
671 .set_eject_state = disk_set_eject_state,
672 .get_eject_state = disk_get_eject_state,
673 .get_image_index = disk_get_image_index,
674 .set_image_index = disk_set_image_index,
675 .get_num_images = disk_get_num_images,
676 .replace_image_index = disk_replace_image_index,
677 .add_image_index = disk_add_image_index,
678};
679
9fba39a9
T
680// just in case, maybe a win-rt port in the future?
681#ifdef _WIN32
682#define SLASH '\\'
683#else
684#define SLASH '/'
685#endif
686
687static char base_dir[PATH_MAX];
688
689static bool read_m3u(const char *file)
690{
691 char line[PATH_MAX];
692 char name[PATH_MAX];
9fba39a9
T
693 FILE *f = fopen(file, "r");
694 if (!f)
695 return false;
696
51ba7408 697 while (fgets(line, sizeof(line), f) && disk_count < sizeof(disks) / sizeof(disks[0])) {
9fba39a9
T
698 if (line[0] == '#')
699 continue;
700 char *carrige_return = strchr(line, '\r');
701 if (carrige_return)
702 *carrige_return = '\0';
703 char *newline = strchr(line, '\n');
704 if (newline)
705 *newline = '\0';
706
707 if (line[0] != '\0')
708 {
709 snprintf(name, sizeof(name), "%s%c%s", base_dir, SLASH, line);
51ba7408 710 disks[disk_count++].fname = strdup(name);
9fba39a9
T
711 }
712 }
713
714 fclose(f);
51ba7408 715 return (disk_count != 0);
9fba39a9
T
716}
717
718static void extract_directory(char *buf, const char *path, size_t size)
719{
720 char *base;
721 strncpy(buf, path, size - 1);
722 buf[size - 1] = '\0';
723
724 base = strrchr(buf, '/');
725 if (!base)
726 base = strrchr(buf, '\\');
727
728 if (base)
729 *base = '\0';
730 else
731 {
732 buf[0] = '.';
733 buf[1] = '\0';
734 }
735}
736
003cfc63 737#if defined(__QNX__) || defined(_WIN32)
41294f4d 738/* Blackberry QNX doesn't have strcasestr */
739
740/*
741 * Find the first occurrence of find in s, ignore case.
742 */
743char *
744strcasestr(const char *s, const char*find)
745{
746 char c, sc;
747 size_t len;
748
749 if ((c = *find++) != 0) {
750 c = tolower((unsigned char)c);
751 len = strlen(find);
752 do {
753 do {
754 if ((sc = *s++) == 0)
755 return (NULL);
756 } while ((char)tolower((unsigned char)sc) != c);
757 } while (strncasecmp(s, find, len) != 0);
758 s--;
759 }
760 return ((char *)s);
761}
762#endif
763
38c2028e 764bool retro_load_game(const struct retro_game_info *info)
765{
23ea11bd 766 size_t i;
9fba39a9
T
767 bool is_m3u = (strcasestr(info->path, ".m3u") != NULL);
768
e3f8313f 769 struct retro_input_descriptor desc[] = {
770 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
771 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
772 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
773 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
774 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
775 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
776 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
777 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
778 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
779 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
780 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
781 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
782 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
783 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
784 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
785 { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 786 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
787 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
788 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
789 { 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
790
e3f8313f 791
792 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
793 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
794 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
795 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
796 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
797 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
798 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
799 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
800 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
801 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
802 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
803 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
804 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
805 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
806 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
807 { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 808 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
809 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
810 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
811 { 1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
e3f8313f 812
813 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
814 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
815 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
816 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
817 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
818 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
819 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
820 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
821 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
822 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
823 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
824 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
825 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
826 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
827 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
828 { 2, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 829 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
830 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
831 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
832 { 2, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
e3f8313f 833
834 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
835 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
836 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
837 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
838 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
839 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
840 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
841 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
842 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
843 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
844 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
845 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
846 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
847 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
848 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
849 { 3, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 850 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
851 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
852 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
853 { 3, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
e3f8313f 854
855 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
856 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
857 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
858 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
859 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
860 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
861 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
862 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
863 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
864 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
865 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
866 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
867 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
868 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
869 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
870 { 4, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 871 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
872 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
873 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
874 { 4, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
e3f8313f 875
876 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
877 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
878 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
879 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
880 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
881 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
882 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
883 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
884 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
885 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
886 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
887 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
888 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
889 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
890 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
ace14ab3 891 { 5, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 892 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
893 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
894 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
895 { 5, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
e3f8313f 896
897 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
898 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
899 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
900 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
901 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
902 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
903 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
904 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
905 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
906 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
907 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
908 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
909 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
910 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
911 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
ace14ab3 912 { 6, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 913 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
914 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
915 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
916 { 6, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
e3f8313f 917
918 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" },
919 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "D-Pad Up" },
920 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "D-Pad Down" },
921 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "D-Pad Right" },
922 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Cross" },
923 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Circle" },
924 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Triangle" },
925 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Square" },
926 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L1" },
927 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2" },
928 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3" },
929 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R1" },
930 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2" },
931 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3" },
932 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select" },
ace14ab3 933 { 7, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
3e24db84 934 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X" },
935 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y" },
936 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X" },
937 { 7, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" },
e3f8313f 938
939 { 0 },
940 };
941
942 environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
943
46aa5b98 944#ifdef FRONTEND_SUPPORTS_RGB565
c19aba43 945 enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
9f766dbe 946 if (environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
f29fbd53 947 SysPrintf("RGB565 supported, using it\n");
c19aba43 948 }
46aa5b98 949#endif
c19aba43 950
23ea11bd 951 if (info == NULL || info->path == NULL) {
952 SysPrintf("info->path required\n");
953 return false;
954 }
955
38c2028e 956 if (plugins_opened) {
957 ClosePlugins();
958 plugins_opened = 0;
959 }
960
23ea11bd 961 for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
962 if (disks[i].fname != NULL) {
963 free(disks[i].fname);
964 disks[i].fname = NULL;
965 }
966 disks[i].internal_index = 0;
967 }
968
969 disk_current_index = 0;
9fba39a9
T
970 extract_directory(base_dir, info->path, sizeof(base_dir));
971
972 if (is_m3u) {
973 if (!read_m3u(info->path)) {
974 SysPrintf("failed to read m3u file\n");
975 return false;
976 }
51ba7408
T
977 } else {
978 disk_count = 1;
9fba39a9 979 disks[0].fname = strdup(info->path);
51ba7408 980 }
23ea11bd 981
982 set_cd_image(disks[0].fname);
38c2028e 983
984 /* have to reload after set_cd_image for correct cdr plugin */
985 if (LoadPlugins() == -1) {
f29fbd53 986 SysPrintf("failed to load plugins\n");
38c2028e 987 return false;
988 }
989
990 plugins_opened = 1;
991 NetOpened = 0;
992
993 if (OpenPlugins() == -1) {
f29fbd53 994 SysPrintf("failed to open plugins\n");
38c2028e 995 return false;
996 }
997
998 plugin_call_rearmed_cbs();
19a784e6 999 dfinput_activate();
38c2028e 1000
1001 Config.PsxAuto = 1;
1002 if (CheckCdrom() == -1) {
f29fbd53 1003 SysPrintf("unsupported/invalid CD image: %s\n", info->path);
38c2028e 1004 return false;
1005 }
1006
1007 SysReset();
1008
1009 if (LoadCdrom() == -1) {
f29fbd53 1010 SysPrintf("could not load CD-ROM!\n");
38c2028e 1011 return false;
1012 }
79f216e3 1013 emu_on_new_cd(0);
38c2028e 1014
23ea11bd 1015 // multidisk images
9fba39a9 1016 if (!is_m3u) {
51ba7408 1017 disk_count = cdrIsoMultidiskCount < 8 ? cdrIsoMultidiskCount : 8;
9fba39a9
T
1018 for (i = 1; i < sizeof(disks) / sizeof(disks[0]) && i < cdrIsoMultidiskCount; i++) {
1019 disks[i].fname = strdup(info->path);
1020 disks[i].internal_index = i;
1021 }
23ea11bd 1022 }
1023
38c2028e 1024 return true;
1025}
1026
1027bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
1028{
1029 return false;
1030}
1031
ace14ab3 1032void retro_unload_game(void)
38c2028e 1033{
1034}
1035
1036unsigned retro_get_region(void)
1037{
17f84149 1038 return is_pal_mode ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
38c2028e 1039}
1040
1041void *retro_get_memory_data(unsigned id)
1042{
b40a83db
T
1043 if (id == RETRO_MEMORY_SAVE_RAM)
1044 return Mcd1Data;
1045 else
1046 return NULL;
38c2028e 1047}
1048
1049size_t retro_get_memory_size(unsigned id)
1050{
b40a83db
T
1051 if (id == RETRO_MEMORY_SAVE_RAM)
1052 return MCD_SIZE;
1053 else
1054 return 0;
38c2028e 1055}
1056
1057void retro_reset(void)
1058{
1059 SysReset();
1060}
1061
1062static const unsigned short retro_psx_map[] = {
1063 [RETRO_DEVICE_ID_JOYPAD_B] = 1 << DKEY_CROSS,
1064 [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << DKEY_SQUARE,
1065 [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << DKEY_SELECT,
1066 [RETRO_DEVICE_ID_JOYPAD_START] = 1 << DKEY_START,
1067 [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << DKEY_UP,
1068 [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << DKEY_DOWN,
1069 [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << DKEY_LEFT,
1070 [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << DKEY_RIGHT,
1071 [RETRO_DEVICE_ID_JOYPAD_A] = 1 << DKEY_CIRCLE,
1072 [RETRO_DEVICE_ID_JOYPAD_X] = 1 << DKEY_TRIANGLE,
1073 [RETRO_DEVICE_ID_JOYPAD_L] = 1 << DKEY_L1,
1074 [RETRO_DEVICE_ID_JOYPAD_R] = 1 << DKEY_R1,
1075 [RETRO_DEVICE_ID_JOYPAD_L2] = 1 << DKEY_L2,
1076 [RETRO_DEVICE_ID_JOYPAD_R2] = 1 << DKEY_R2,
1077 [RETRO_DEVICE_ID_JOYPAD_L3] = 1 << DKEY_L3,
1078 [RETRO_DEVICE_ID_JOYPAD_R3] = 1 << DKEY_R3,
1079};
1080#define RETRO_PSX_MAP_LEN (sizeof(retro_psx_map) / sizeof(retro_psx_map[0]))
1081
805fe9bc 1082static void update_variables(bool in_flight)
e268a47e 1083{
e268a47e 1084 struct retro_variable var;
ace14ab3 1085
e268a47e 1086 var.value = NULL;
4e477065 1087 var.key = "pcsx_rearmed_frameskip";
7d68d030 1088 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1089 pl_rearmed_cbs.frameskip = atoi(var.value);
9f5a28d9 1090
1091 var.value = NULL;
4e477065 1092 var.key = "pcsx_rearmed_region";
9f5a28d9 1093 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1094 {
1095 Config.PsxAuto = 0;
1096 if (strcmp(var.value, "Automatic") == 0)
1097 Config.PsxAuto = 1;
1098 else if (strcmp(var.value, "NTSC") == 0)
1099 Config.PsxType = 0;
1100 else if (strcmp(var.value, "PAL") == 0)
1101 Config.PsxType = 1;
1102 }
4615b075 1103
8136cafb
AP
1104 for (int i = 0; i < PORTS_NUMBER; i++)
1105 update_controller_port_device(i);
61c4962a 1106
ace14ab3 1107 var.value = NULL;
1108 var.key = "pcsx_rearmed_multitap1";
1109 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1110 {
1111 if (strcmp(var.value, "enabled") == 0)
1112 multitap1 = 1;
1113 else multitap1 = 0;
1114 }
1115
1116 var.value = NULL;
1117 var.key = "pcsx_rearmed_multitap2";
1118 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1119 {
1120 if (strcmp(var.value, "enabled") == 0)
1121 multitap2 = 1;
1122 else multitap2 = 0;
1123 }
61c4962a 1124
7d68d030 1125#ifdef __ARM_NEON__
9f5a28d9 1126 var.value = "NULL";
55e5626b 1127 var.key = "pcsx_rearmed_neon_interlace_enable";
9f5a28d9 1128
1129 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1130 {
1131 if (strcmp(var.value, "disabled") == 0)
1132 pl_rearmed_cbs.gpu_neon.allow_interlace = 0;
1133 else if (strcmp(var.value, "enabled") == 0)
1134 pl_rearmed_cbs.gpu_neon.allow_interlace = 1;
1135 }
1136
7d68d030 1137 var.value = NULL;
55e5626b 1138 var.key = "pcsx_rearmed_neon_enhancement_enable";
7d68d030 1139
1140 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1141 {
1142 if (strcmp(var.value, "disabled") == 0)
1143 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
1144 else if (strcmp(var.value, "enabled") == 0)
1145 pl_rearmed_cbs.gpu_neon.enhancement_enable = 1;
1146 }
354329fa 1147
1148 var.value = NULL;
55e5626b 1149 var.key = "pcsx_rearmed_neon_enhancement_no_main";
354329fa 1150
1151 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1152 {
1153 if (strcmp(var.value, "disabled") == 0)
1154 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
1155 else if (strcmp(var.value, "enabled") == 0)
1156 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 1;
1157 }
094ec204 1158#endif
0e5a7b7d 1159
1160 var.value = "NULL";
1161 var.key = "pcsx_rearmed_duping_enable";
1162
1163 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1164 {
1165 if (strcmp(var.value, "off") == 0)
1166 duping_enable = false;
1167 else if (strcmp(var.value, "on") == 0)
1168 duping_enable = true;
1169 }
1170
48f615ba 1171#ifndef DRC_DISABLE
1172 var.value = NULL;
4e477065 1173 var.key = "pcsx_rearmed_drc";
48f615ba 1174
1175 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1176 {
1177 R3000Acpu *prev_cpu = psxCpu;
1178
fc99395c 1179#ifdef _3DS
f72db18e 1180 if(!__ctr_svchax)
fc99395c 1181 Config.Cpu = CPU_INTERPRETER;
1182 else
1183#endif
48f615ba 1184 if (strcmp(var.value, "disabled") == 0)
1185 Config.Cpu = CPU_INTERPRETER;
1186 else if (strcmp(var.value, "enabled") == 0)
1187 Config.Cpu = CPU_DYNAREC;
1188
1189 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1190 if (psxCpu != prev_cpu) {
1191 prev_cpu->Shutdown();
1192 psxCpu->Init();
1193 psxCpu->Reset(); // not really a reset..
1194 }
1195 }
1196#endif
805fe9bc 1197
01394a7f 1198 var.value = "NULL";
1199 var.key = "pcsx_rearmed_spu_reverb";
1200
1201 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1202 {
1203 if (strcmp(var.value, "off") == 0)
1204 spu_config.iUseReverb = false;
1205 else if (strcmp(var.value, "on") == 0)
1206 spu_config.iUseReverb = true;
1207 }
1208
1209 var.value = "NULL";
1210 var.key = "pcsx_rearmed_spu_interpolation";
1211
1212 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1213 {
1214 if (strcmp(var.value, "simple") == 0)
1215 spu_config.iUseInterpolation = 1;
1216 else if (strcmp(var.value, "gaussian") == 0)
1217 spu_config.iUseInterpolation = 2;
1218 else if (strcmp(var.value, "cubic") == 0)
1219 spu_config.iUseInterpolation = 3;
1220 else if (strcmp(var.value, "off") == 0)
1221 spu_config.iUseInterpolation = 0;
1222 }
1223
b3480be8 1224 var.value = "NULL";
1225 var.key = "pcsx_rearmed_pe2_fix";
1226
1227 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1228 {
1229 if (strcmp(var.value, "disabled") == 0)
1230 Config.RCntFix = 0;
1231 else if (strcmp(var.value, "enabled") == 0)
1232 Config.RCntFix = 1;
1233 }
ace14ab3 1234
b3480be8 1235 var.value = "NULL";
1236 var.key = "pcsx_rearmed_inuyasha_fix";
1237
1238 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value)
1239 {
1240 if (strcmp(var.value, "disabled") == 0)
1241 Config.VSyncWA = 0;
1242 else if (strcmp(var.value, "enabled") == 0)
1243 Config.VSyncWA = 1;
1244 }
1245
32ab9e53
TJ
1246 if (in_flight) {
1247 // inform core things about possible config changes
1248 plugin_call_rearmed_cbs();
805fe9bc 1249
32ab9e53
TJ
1250 if (GPU_open != NULL && GPU_close != NULL) {
1251 GPU_close();
1252 GPU_open(&gpuDisp, "PCSX", NULL);
1253 }
805fe9bc 1254
32ab9e53
TJ
1255 dfinput_activate();
1256 }
e268a47e 1257}
1258
ace14ab3 1259void retro_run(void)
38c2028e 1260{
3b1a5e21 1261 int i;
38c2028e 1262
1263 input_poll_cb();
e268a47e 1264
805fe9bc 1265 bool updated = false;
1266 if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
1267 update_variables(true);
e268a47e 1268
3b1a5e21 1269 // reset all keystate, query libretro for keystate
61c4962a 1270 int j;
3c0fb554 1271 for(i = 0; i < PORTS_NUMBER; i++) {
61c4962a 1272 in_keystate[i] = 0;
3c0fb554
AP
1273
1274 if (in_type[i] == PSE_PAD_TYPE_NONE)
1275 continue;
1276
3b1a5e21 1277 // query libretro for keystate
1278 for (j = 0; j < RETRO_PSX_MAP_LEN; j++)
61c4962a 1279 if (input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, j))
1280 in_keystate[i] |= retro_psx_map[j];
56abf614 1281
1282 if (in_type[i] == PSE_PAD_TYPE_ANALOGPAD)
1283 {
1284 in_analog_left[i][0] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1285 in_analog_left[i][1] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1286 in_analog_right[i][0] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128;
1287 in_analog_right[i][1] = (input_state_cb(i, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128;
1288 }
61c4962a 1289 }
e8d96071 1290
38c2028e 1291 stop = 0;
1292 psxCpu->Execute();
1293
0e5a7b7d 1294 video_cb((vout_fb_dirty || !vout_can_dupe || !duping_enable) ? vout_buf : NULL,
1a6164a1 1295 vout_width, vout_height, vout_width * 2);
70d56ca3 1296 vout_fb_dirty = 0;
38c2028e 1297}
1298
74ebc05b 1299static bool try_use_bios(const char *path)
1300{
1301 FILE *f;
1302 long size;
1303 const char *name;
1304
1305 f = fopen(path, "rb");
1306 if (f == NULL)
1307 return false;
1308
1309 fseek(f, 0, SEEK_END);
1310 size = ftell(f);
1311 fclose(f);
1312
1313 if (size != 512 * 1024)
1314 return false;
1315
1316 name = strrchr(path, SLASH);
1317 if (name++ == NULL)
1318 name = path;
1319 snprintf(Config.Bios, sizeof(Config.Bios), "%s", name);
1320 return true;
1321}
1322
c4052f4d 1323#ifndef VITA
74ebc05b 1324#include <sys/types.h>
1325#include <dirent.h>
1326
1327static bool find_any_bios(const char *dirpath, char *path, size_t path_size)
1328{
1329 DIR *dir;
1330 struct dirent *ent;
1331 bool ret = false;
1332
1333 dir = opendir(dirpath);
1334 if (dir == NULL)
1335 return false;
1336
1337 while ((ent = readdir(dir))) {
1338 if (strncasecmp(ent->d_name, "scph", 4) != 0)
1339 continue;
1340
1341 snprintf(path, path_size, "%s/%s", dirpath, ent->d_name);
1342 ret = try_use_bios(path);
1343 if (ret)
1344 break;
1345 }
1346 closedir(dir);
1347 return ret;
1348}
1349#else
1350#define find_any_bios(...) false
1351#endif
1352
11813b9d 1353static void check_system_specs(void)
1354{
1355 unsigned level = 6;
1356 environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
1357}
1358
38c2028e 1359void retro_init(void)
1360{
1361 const char *bios[] = { "scph1001", "scph5501", "scph7001" };
1362 const char *dir;
1363 char path[256];
1e1cccd9 1364 int i, ret;
74ebc05b 1365 bool found_bios = false;
38c2028e 1366
fc99395c 1367#ifdef _3DS
fc99395c 1368 psxMapHook = pl_3ds_mmap;
1369 psxUnmapHook = pl_3ds_munmap;
1370#endif
38c2028e 1371 ret = emu_core_preinit();
e4d84733 1372#ifdef _3DS
1373 /* emu_core_preinit sets the cpu to dynarec */
f72db18e 1374 if(!__ctr_svchax)
e4d84733 1375 Config.Cpu = CPU_INTERPRETER;
1376#endif
38c2028e 1377 ret |= emu_core_init();
1378 if (ret != 0) {
f29fbd53 1379 SysPrintf("PCSX init failed.\n");
38c2028e 1380 exit(1);
1381 }
1382
0b7f536b 1383#ifdef _3DS
1384 vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80);
1385#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA)
a9579f3b 1386 posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
29122437
TJ
1387#else
1388 vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
1389#endif
38c2028e 1390
1391 if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
1392 {
fc99395c 1393 snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir);
38c2028e 1394
1395 for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) {
1396 snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]);
74ebc05b 1397 found_bios = try_use_bios(path);
1398 if (found_bios)
38c2028e 1399 break;
38c2028e 1400 }
74ebc05b 1401
1402 if (!found_bios)
1403 found_bios = find_any_bios(dir, path, sizeof(path));
38c2028e 1404 }
74ebc05b 1405 if (found_bios) {
f29fbd53 1406 SysPrintf("found BIOS file: %s\n", Config.Bios);
38c2028e 1407 }
1408 else
74ebc05b 1409 {
f29fbd53 1410 SysPrintf("no BIOS files found.\n");
ace14ab3 1411 struct retro_message msg =
74ebc05b 1412 {
1413 "no BIOS found, expect bugs!",
1414 180
1415 };
1416 environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, (void*)&msg);
1417 }
38c2028e 1418
1a6164a1 1419 environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &vout_can_dupe);
23ea11bd 1420 environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
4e477065 1421 environ_cb(RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE, &rumble);
1a6164a1 1422
5ca2ec64 1423 /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times)
1424 * we have to do this because cache misses and some IO penalties
1425 * are not emulated. Warning: changing this may break compatibility. */
5ca2ec64 1426 cycle_multiplier = 175;
ace14ab3 1427#ifdef HAVE_PRE_ARMV7
5ca2ec64 1428 cycle_multiplier = 200;
1429#endif
46b3a2fc 1430 pl_rearmed_cbs.gpu_peops.iUseDither = 1;
1e0eac23 1431 spu_config.iUseFixedUpdates = 1;
5ca2ec64 1432
f9f60dae
TK
1433 McdDisable[0] = 0;
1434 McdDisable[1] = 1;
7df396ea 1435 init_memcard(Mcd1Data);
6e921e1d 1436
1437 SaveFuncs.open = save_open;
1438 SaveFuncs.read = save_read;
1439 SaveFuncs.write = save_write;
1440 SaveFuncs.seek = save_seek;
1441 SaveFuncs.close = save_close;
e268a47e 1442
805fe9bc 1443 update_variables(false);
32ab9e53 1444 check_system_specs();
38c2028e 1445}
1446
1447void retro_deinit(void)
1448{
1449 SysClose();
0b7f536b 1450#ifdef _3DS
1451 linearFree(vout_buf);
1452#else
38c2028e 1453 free(vout_buf);
0b7f536b 1454#endif
38c2028e 1455 vout_buf = NULL;
1456}
c4052f4d 1457
1458#ifdef VITA
1459#include <psp2/kernel/threadmgr.h>
1460int usleep (unsigned long us)
1461{
1462 sceKernelDelayThread(us);
1463}
1464#endif