libretro.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * libretro core glue for PicoDrive
  3. * (C) notaz, 2013
  4. *
  5. * This work is licensed under the terms of MAME license.
  6. * See COPYING file in the top-level directory.
  7. */
  8. #define _GNU_SOURCE 1 // mremap
  9. #include <stdio.h>
  10. #include <stdarg.h>
  11. #include <string.h>
  12. #include <sys/mman.h>
  13. #include <errno.h>
  14. #ifdef __MACH__
  15. #include <libkern/OSCacheControl.h>
  16. #endif
  17. #include <pico/pico_int.h>
  18. #include <pico/state.h>
  19. #include "common/input_pico.h"
  20. #include "common/version.h"
  21. #include "libretro.h"
  22. #ifndef MAP_ANONYMOUS
  23. #define MAP_ANONYMOUS MAP_ANON
  24. #endif
  25. static retro_video_refresh_t video_cb;
  26. static retro_input_poll_t input_poll_cb;
  27. static retro_input_state_t input_state_cb;
  28. static retro_environment_t environ_cb;
  29. static retro_audio_sample_batch_t audio_batch_cb;
  30. static FILE *emu_log;
  31. #define VOUT_MAX_WIDTH 320
  32. #define VOUT_MAX_HEIGHT 240
  33. static void *vout_buf;
  34. static int vout_width, vout_height;
  35. static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
  36. static void snd_write(int len);
  37. #ifdef _WIN32
  38. #define SLASH '\\'
  39. #else
  40. #define SLASH '/'
  41. #endif
  42. /* functions called by the core */
  43. void cache_flush_d_inval_i(void *start, void *end)
  44. {
  45. #ifdef __arm__
  46. #if defined(__BLACKBERRY_QNX__)
  47. msync(start, end - start, MS_SYNC | MS_CACHE_ONLY | MS_INVALIDATE_ICACHE);
  48. #elif defined(__MACH__)
  49. size_t len = (char *)end - (char *)start;
  50. sys_dcache_flush(start, len);
  51. sys_icache_invalidate(start, len);
  52. #else
  53. __clear_cache(start, end);
  54. #endif
  55. #endif
  56. }
  57. void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
  58. {
  59. int flags = MAP_PRIVATE | MAP_ANONYMOUS;
  60. void *req, *ret;
  61. req = (void *)addr;
  62. ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0);
  63. if (ret == MAP_FAILED) {
  64. lprintf("mmap(%08lx, %zd) failed: %d\n", addr, size, errno);
  65. return NULL;
  66. }
  67. if (addr != 0 && ret != (void *)addr) {
  68. lprintf("warning: wanted to map @%08lx, got %p\n",
  69. addr, ret);
  70. if (is_fixed) {
  71. munmap(ret, size);
  72. return NULL;
  73. }
  74. }
  75. return ret;
  76. }
  77. void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
  78. {
  79. #ifdef __linux__
  80. void *ret = mremap(ptr, oldsize, newsize, 0);
  81. if (ret == MAP_FAILED)
  82. return NULL;
  83. return ret;
  84. #else
  85. void *tmp, *ret;
  86. size_t preserve_size;
  87. preserve_size = oldsize;
  88. if (preserve_size > newsize)
  89. preserve_size = newsize;
  90. tmp = malloc(preserve_size);
  91. if (tmp == NULL)
  92. return NULL;
  93. memcpy(tmp, ptr, preserve_size);
  94. munmap(ptr, oldsize);
  95. ret = mmap(ptr, newsize, PROT_READ | PROT_WRITE,
  96. MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  97. if (ret == MAP_FAILED) {
  98. free(tmp);
  99. return NULL;
  100. }
  101. memcpy(ret, tmp, preserve_size);
  102. free(tmp);
  103. return ret;
  104. #endif
  105. }
  106. void plat_munmap(void *ptr, size_t size)
  107. {
  108. if (ptr != NULL)
  109. munmap(ptr, size);
  110. }
  111. int plat_mem_set_exec(void *ptr, size_t size)
  112. {
  113. int ret = mprotect(ptr, size, PROT_READ | PROT_WRITE | PROT_EXEC);
  114. if (ret != 0)
  115. lprintf("mprotect(%p, %zd) failed: %d\n", ptr, size, errno);
  116. return ret;
  117. }
  118. void emu_video_mode_change(int start_line, int line_count, int is_32cols)
  119. {
  120. memset(vout_buf, 0, 320 * 240 * 2);
  121. vout_width = is_32cols ? 256 : 320;
  122. PicoDrawSetOutBuf(vout_buf, vout_width * 2);
  123. }
  124. void emu_32x_startup(void)
  125. {
  126. }
  127. #ifndef ANDROID
  128. void lprintf(const char *fmt, ...)
  129. {
  130. va_list list;
  131. va_start(list, fmt);
  132. fprintf(emu_log, "PicoDrive: ");
  133. vfprintf(emu_log, fmt, list);
  134. va_end(list);
  135. fflush(emu_log);
  136. }
  137. #else
  138. #include <android/log.h>
  139. void lprintf(const char *fmt, ...)
  140. {
  141. va_list list;
  142. va_start(list, fmt);
  143. __android_log_vprint(ANDROID_LOG_INFO, "PicoDrive", fmt, list);
  144. va_end(list);
  145. }
  146. #endif
  147. /* libretro */
  148. void retro_set_environment(retro_environment_t cb)
  149. {
  150. static const struct retro_variable vars[] = {
  151. //{ "region", "Region; Auto|NTSC|PAL" },
  152. { "picodrive_input1", "Input device 1; 3 button pad|6 button pad|None" },
  153. { "picodrive_input2", "Input device 2; 3 button pad|6 button pad|None" },
  154. #ifdef DRC_SH2
  155. { "picodrive_drc", "Dynamic recompilers; enabled|disabled" },
  156. #endif
  157. { NULL, NULL },
  158. };
  159. environ_cb = cb;
  160. cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *)vars);
  161. }
  162. void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
  163. void retro_set_audio_sample(retro_audio_sample_t cb) { (void)cb; }
  164. void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
  165. void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
  166. void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
  167. unsigned retro_api_version(void)
  168. {
  169. return RETRO_API_VERSION;
  170. }
  171. void retro_set_controller_port_device(unsigned port, unsigned device)
  172. {
  173. }
  174. void retro_get_system_info(struct retro_system_info *info)
  175. {
  176. memset(info, 0, sizeof(*info));
  177. info->library_name = "PicoDrive";
  178. info->library_version = VERSION;
  179. info->valid_extensions = "bin|gen|smd|md|32x|cue|iso|sms";
  180. info->need_fullpath = true;
  181. }
  182. void retro_get_system_av_info(struct retro_system_av_info *info)
  183. {
  184. memset(info, 0, sizeof(*info));
  185. info->timing.fps = Pico.m.pal ? 50 : 60;
  186. info->timing.sample_rate = 44100;
  187. info->geometry.base_width = 320;
  188. info->geometry.base_height = 240;
  189. info->geometry.max_width = VOUT_MAX_WIDTH;
  190. info->geometry.max_height = VOUT_MAX_HEIGHT;
  191. info->geometry.aspect_ratio = 4.0 / 3.0;
  192. }
  193. /* savestates */
  194. struct savestate_state {
  195. const char *load_buf;
  196. char *save_buf;
  197. size_t size;
  198. size_t pos;
  199. };
  200. size_t state_read(void *p, size_t size, size_t nmemb, void *file)
  201. {
  202. struct savestate_state *state = file;
  203. size_t bsize = size * nmemb;
  204. if (state->pos + bsize > state->size) {
  205. lprintf("savestate error: %u/%u\n",
  206. state->pos + bsize, state->size);
  207. bsize = state->size - state->pos;
  208. if ((int)bsize <= 0)
  209. return 0;
  210. }
  211. memcpy(p, state->load_buf + state->pos, bsize);
  212. state->pos += bsize;
  213. return bsize;
  214. }
  215. size_t state_write(void *p, size_t size, size_t nmemb, void *file)
  216. {
  217. struct savestate_state *state = file;
  218. size_t bsize = size * nmemb;
  219. if (state->pos + bsize > state->size) {
  220. lprintf("savestate error: %u/%u\n",
  221. state->pos + bsize, state->size);
  222. bsize = state->size - state->pos;
  223. if ((int)bsize <= 0)
  224. return 0;
  225. }
  226. memcpy(state->save_buf + state->pos, p, bsize);
  227. state->pos += bsize;
  228. return bsize;
  229. }
  230. size_t state_skip(void *p, size_t size, size_t nmemb, void *file)
  231. {
  232. struct savestate_state *state = file;
  233. size_t bsize = size * nmemb;
  234. state->pos += bsize;
  235. return bsize;
  236. }
  237. size_t state_eof(void *file)
  238. {
  239. struct savestate_state *state = file;
  240. return state->pos >= state->size;
  241. }
  242. int state_fseek(void *file, long offset, int whence)
  243. {
  244. struct savestate_state *state = file;
  245. switch (whence) {
  246. case SEEK_SET:
  247. state->pos = offset;
  248. break;
  249. case SEEK_CUR:
  250. state->pos += offset;
  251. break;
  252. case SEEK_END:
  253. state->pos = state->size + offset;
  254. break;
  255. }
  256. return (int)state->pos;
  257. }
  258. /* savestate sizes vary wildly depending if cd/32x or
  259. * carthw is active, so run the whole thing to get size */
  260. size_t retro_serialize_size(void)
  261. {
  262. struct savestate_state state = { 0, };
  263. int ret;
  264. ret = PicoStateFP(&state, 1, NULL, state_skip, NULL, state_fseek);
  265. if (ret != 0)
  266. return 0;
  267. return state.pos;
  268. }
  269. bool retro_serialize(void *data, size_t size)
  270. {
  271. struct savestate_state state = { 0, };
  272. int ret;
  273. state.save_buf = data;
  274. state.size = size;
  275. state.pos = 0;
  276. ret = PicoStateFP(&state, 1, NULL, state_write,
  277. NULL, state_fseek);
  278. return ret == 0;
  279. }
  280. bool retro_unserialize(const void *data, size_t size)
  281. {
  282. struct savestate_state state = { 0, };
  283. int ret;
  284. state.load_buf = data;
  285. state.size = size;
  286. state.pos = 0;
  287. ret = PicoStateFP(&state, 0, state_read, NULL,
  288. state_eof, state_fseek);
  289. return ret == 0;
  290. }
  291. /* cheats - TODO */
  292. void retro_cheat_reset(void)
  293. {
  294. }
  295. void retro_cheat_set(unsigned index, bool enabled, const char *code)
  296. {
  297. }
  298. /* multidisk support */
  299. static bool disk_ejected;
  300. static unsigned int disk_current_index;
  301. static unsigned int disk_count;
  302. static struct disks_state {
  303. char *fname;
  304. } disks[8];
  305. static bool disk_set_eject_state(bool ejected)
  306. {
  307. // TODO?
  308. disk_ejected = ejected;
  309. return true;
  310. }
  311. static bool disk_get_eject_state(void)
  312. {
  313. return disk_ejected;
  314. }
  315. static unsigned int disk_get_image_index(void)
  316. {
  317. return disk_current_index;
  318. }
  319. static bool disk_set_image_index(unsigned int index)
  320. {
  321. cd_img_type cd_type;
  322. int ret;
  323. if (index >= sizeof(disks) / sizeof(disks[0]))
  324. return false;
  325. if (disks[index].fname == NULL) {
  326. lprintf("missing disk #%u\n", index);
  327. // RetroArch specifies "no disk" with index == count,
  328. // so don't fail here..
  329. disk_current_index = index;
  330. return true;
  331. }
  332. lprintf("switching to disk %u: \"%s\"\n", index,
  333. disks[index].fname);
  334. ret = -1;
  335. cd_type = PicoCdCheck(disks[index].fname, NULL);
  336. if (cd_type != CIT_NOT_CD)
  337. ret = Insert_CD(disks[index].fname, cd_type);
  338. if (ret != 0) {
  339. lprintf("Load failed, invalid CD image?\n");
  340. return 0;
  341. }
  342. disk_current_index = index;
  343. return true;
  344. }
  345. static unsigned int disk_get_num_images(void)
  346. {
  347. return disk_count;
  348. }
  349. static bool disk_replace_image_index(unsigned index,
  350. const struct retro_game_info *info)
  351. {
  352. bool ret = true;
  353. if (index >= sizeof(disks) / sizeof(disks[0]))
  354. return false;
  355. if (disks[index].fname != NULL)
  356. free(disks[index].fname);
  357. disks[index].fname = NULL;
  358. if (info != NULL) {
  359. disks[index].fname = strdup(info->path);
  360. if (index == disk_current_index)
  361. ret = disk_set_image_index(index);
  362. }
  363. return ret;
  364. }
  365. static bool disk_add_image_index(void)
  366. {
  367. if (disk_count >= sizeof(disks) / sizeof(disks[0]))
  368. return false;
  369. disk_count++;
  370. return true;
  371. }
  372. static struct retro_disk_control_callback disk_control = {
  373. .set_eject_state = disk_set_eject_state,
  374. .get_eject_state = disk_get_eject_state,
  375. .get_image_index = disk_get_image_index,
  376. .set_image_index = disk_set_image_index,
  377. .get_num_images = disk_get_num_images,
  378. .replace_image_index = disk_replace_image_index,
  379. .add_image_index = disk_add_image_index,
  380. };
  381. static void disk_tray_open(void)
  382. {
  383. lprintf("cd tray open\n");
  384. disk_ejected = 1;
  385. }
  386. static void disk_tray_close(void)
  387. {
  388. lprintf("cd tray close\n");
  389. disk_ejected = 0;
  390. }
  391. static const char * const biosfiles_us[] = {
  392. "us_scd1_9210", "us_scd2_9306", "SegaCDBIOS9303", "bios_CD_U"
  393. };
  394. static const char * const biosfiles_eu[] = {
  395. "eu_mcd1_9210", "eu_mcd2_9306", "eu_mcd2_9303", "bios_CD_E"
  396. };
  397. static const char * const biosfiles_jp[] = {
  398. "jp_mcd1_9112", "jp_mcd1_9111", "bios_CD_J"
  399. };
  400. static void make_system_path(char *buf, size_t buf_size,
  401. const char *name, const char *ext)
  402. {
  403. const char *dir = NULL;
  404. if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) {
  405. snprintf(buf, buf_size, "%s%c%s%s", dir, SLASH, name, ext);
  406. }
  407. else {
  408. snprintf(buf, buf_size, "%s%s", name, ext);
  409. }
  410. }
  411. static const char *find_bios(int *region, const char *cd_fname)
  412. {
  413. const char * const *files;
  414. static char path[256];
  415. int i, count;
  416. FILE *f = NULL;
  417. if (*region == 4) { // US
  418. files = biosfiles_us;
  419. count = sizeof(biosfiles_us) / sizeof(char *);
  420. } else if (*region == 8) { // EU
  421. files = biosfiles_eu;
  422. count = sizeof(biosfiles_eu) / sizeof(char *);
  423. } else if (*region == 1 || *region == 2) {
  424. files = biosfiles_jp;
  425. count = sizeof(biosfiles_jp) / sizeof(char *);
  426. } else {
  427. return NULL;
  428. }
  429. for (i = 0; i < count; i++)
  430. {
  431. make_system_path(path, sizeof(path), files[i], ".bin");
  432. f = fopen(path, "rb");
  433. if (f != NULL)
  434. break;
  435. make_system_path(path, sizeof(path), files[i], ".zip");
  436. f = fopen(path, "rb");
  437. if (f != NULL)
  438. break;
  439. }
  440. if (f != NULL) {
  441. lprintf("using bios: %s\n", path);
  442. fclose(f);
  443. return path;
  444. }
  445. return NULL;
  446. }
  447. bool retro_load_game(const struct retro_game_info *info)
  448. {
  449. enum media_type_e media_type;
  450. static char carthw_path[256];
  451. size_t i;
  452. enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
  453. if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) {
  454. lprintf("RGB565 support required, sorry\n");
  455. return false;
  456. }
  457. if (info == NULL || info->path == NULL) {
  458. lprintf("info->path required\n");
  459. return false;
  460. }
  461. for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) {
  462. if (disks[i].fname != NULL) {
  463. free(disks[i].fname);
  464. disks[i].fname = NULL;
  465. }
  466. }
  467. disk_current_index = 0;
  468. disk_count = 1;
  469. disks[0].fname = strdup(info->path);
  470. make_system_path(carthw_path, sizeof(carthw_path), "carthw", ".cfg");
  471. media_type = PicoLoadMedia(info->path, carthw_path,
  472. find_bios, NULL);
  473. switch (media_type) {
  474. case PM_BAD_DETECT:
  475. lprintf("Failed to detect ROM/CD image type.\n");
  476. return false;
  477. case PM_BAD_CD:
  478. lprintf("Invalid CD image\n");
  479. return false;
  480. case PM_BAD_CD_NO_BIOS:
  481. lprintf("Missing BIOS\n");
  482. return false;
  483. case PM_ERROR:
  484. lprintf("Load error\n");
  485. return false;
  486. default:
  487. break;
  488. }
  489. PicoLoopPrepare();
  490. PicoWriteSound = snd_write;
  491. memset(sndBuffer, 0, sizeof(sndBuffer));
  492. PsndOut = sndBuffer;
  493. PsndRerate(1);
  494. return true;
  495. }
  496. bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info)
  497. {
  498. return false;
  499. }
  500. void retro_unload_game(void)
  501. {
  502. }
  503. unsigned retro_get_region(void)
  504. {
  505. return Pico.m.pal ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
  506. }
  507. void *retro_get_memory_data(unsigned id)
  508. {
  509. if (id != RETRO_MEMORY_SAVE_RAM)
  510. return NULL;
  511. if (PicoAHW & PAHW_MCD)
  512. return Pico_mcd->bram;
  513. else
  514. return SRam.data;
  515. }
  516. size_t retro_get_memory_size(unsigned id)
  517. {
  518. if (id != RETRO_MEMORY_SAVE_RAM)
  519. return 0;
  520. if (PicoAHW & PAHW_MCD)
  521. // bram
  522. return 0x2000;
  523. else
  524. return SRam.size;
  525. }
  526. void retro_reset(void)
  527. {
  528. PicoReset();
  529. }
  530. static const unsigned short retro_pico_map[] = {
  531. [RETRO_DEVICE_ID_JOYPAD_B] = 1 << GBTN_B,
  532. [RETRO_DEVICE_ID_JOYPAD_Y] = 1 << GBTN_A,
  533. [RETRO_DEVICE_ID_JOYPAD_SELECT] = 1 << GBTN_MODE,
  534. [RETRO_DEVICE_ID_JOYPAD_START] = 1 << GBTN_START,
  535. [RETRO_DEVICE_ID_JOYPAD_UP] = 1 << GBTN_UP,
  536. [RETRO_DEVICE_ID_JOYPAD_DOWN] = 1 << GBTN_DOWN,
  537. [RETRO_DEVICE_ID_JOYPAD_LEFT] = 1 << GBTN_LEFT,
  538. [RETRO_DEVICE_ID_JOYPAD_RIGHT] = 1 << GBTN_RIGHT,
  539. [RETRO_DEVICE_ID_JOYPAD_A] = 1 << GBTN_C,
  540. [RETRO_DEVICE_ID_JOYPAD_X] = 1 << GBTN_Y,
  541. [RETRO_DEVICE_ID_JOYPAD_L] = 1 << GBTN_X,
  542. [RETRO_DEVICE_ID_JOYPAD_R] = 1 << GBTN_Z,
  543. };
  544. #define RETRO_PICO_MAP_LEN (sizeof(retro_pico_map) / sizeof(retro_pico_map[0]))
  545. static void snd_write(int len)
  546. {
  547. audio_batch_cb(PsndOut, len / 4);
  548. }
  549. static enum input_device input_name_to_val(const char *name)
  550. {
  551. if (strcmp(name, "3 button pad") == 0)
  552. return PICO_INPUT_PAD_3BTN;
  553. if (strcmp(name, "6 button pad") == 0)
  554. return PICO_INPUT_PAD_6BTN;
  555. if (strcmp(name, "None") == 0)
  556. return PICO_INPUT_NOTHING;
  557. lprintf("invalid picodrive_input: '%s'\n", name);
  558. return PICO_INPUT_PAD_3BTN;
  559. }
  560. static void update_variables(void)
  561. {
  562. struct retro_variable var;
  563. var.value = NULL;
  564. var.key = "picodrive_input1";
  565. if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
  566. PicoSetInputDevice(0, input_name_to_val(var.value));
  567. var.value = NULL;
  568. var.key = "picodrive_input2";
  569. if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
  570. PicoSetInputDevice(1, input_name_to_val(var.value));
  571. #ifdef DRC_SH2
  572. var.value = NULL;
  573. var.key = "picodrive_drc";
  574. if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
  575. if (strcmp(var.value, "enabled") == 0)
  576. PicoOpt |= POPT_EN_DRC;
  577. else
  578. PicoOpt &= ~POPT_EN_DRC;
  579. }
  580. #endif
  581. }
  582. void retro_run(void)
  583. {
  584. bool updated = false;
  585. int pad, i;
  586. if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
  587. update_variables();
  588. input_poll_cb();
  589. PicoPad[0] = PicoPad[1] = 0;
  590. for (pad = 0; pad < 2; pad++)
  591. for (i = 0; i < RETRO_PICO_MAP_LEN; i++)
  592. if (input_state_cb(pad, RETRO_DEVICE_JOYPAD, 0, i))
  593. PicoPad[pad] |= retro_pico_map[i];
  594. PicoFrame();
  595. video_cb(vout_buf, vout_width, vout_height, vout_width * 2);
  596. }
  597. void retro_init(void)
  598. {
  599. int level;
  600. #ifdef IOS
  601. emu_log = fopen("/User/Documents/PicoDrive.log", "w");
  602. if (emu_log == NULL)
  603. emu_log = fopen("PicoDrive.log", "w");
  604. if (emu_log == NULL)
  605. #endif
  606. emu_log = stdout;
  607. level = 0;
  608. environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level);
  609. environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control);
  610. PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80
  611. | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX
  612. | POPT_EN_32X|POPT_EN_PWM
  613. | POPT_ACC_SPRITES|POPT_DIS_32C_BORDER;
  614. #ifdef __arm__
  615. PicoOpt |= POPT_EN_SVP_DRC;
  616. #endif
  617. PsndRate = 44100;
  618. PicoAutoRgnOrder = 0x184; // US, EU, JP
  619. PicoCDBuffers = 0;
  620. vout_width = 320;
  621. vout_height = 240;
  622. vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2);
  623. PicoInit();
  624. PicoDrawSetOutFormat(PDF_RGB555, 0);
  625. PicoDrawSetOutBuf(vout_buf, vout_width * 2);
  626. //PicoMessage = plat_status_msg_busy_next;
  627. PicoMCDopenTray = disk_tray_open;
  628. PicoMCDcloseTray = disk_tray_close;
  629. update_variables();
  630. }
  631. void retro_deinit(void)
  632. {
  633. PicoExit();
  634. }