menu_pico.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * PicoDrive
  3. * (C) notaz, 2010,2011
  4. *
  5. * This work is licensed under the terms of MAME license.
  6. * See COPYING file in the top-level directory.
  7. */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <time.h>
  11. #include "emu.h"
  12. #include "menu_pico.h"
  13. #include "input_pico.h"
  14. #include "version.h"
  15. #include <pico/pico.h>
  16. #include <pico/patch.h>
  17. #ifdef PANDORA
  18. #define MENU_X2 1
  19. #else
  20. #define MENU_X2 0
  21. #endif
  22. // FIXME
  23. #define REVISION "0"
  24. static const char *rom_exts[] = {
  25. "zip",
  26. "bin", "smd", "gen", "md",
  27. "iso", "cso", "cue",
  28. "32x",
  29. "sms",
  30. NULL
  31. };
  32. // rrrr rggg gggb bbbb
  33. static unsigned short fname2color(const char *fname)
  34. {
  35. static const char *other_exts[] = { "gmv", "pat" };
  36. const char *ext;
  37. int i;
  38. ext = strrchr(fname, '.');
  39. if (ext++ == NULL) {
  40. ext = fname + strlen(fname) - 3;
  41. if (ext < fname) ext = fname;
  42. }
  43. for (i = 0; rom_exts[i] != NULL; i++)
  44. if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
  45. for (i = 0; i < array_size(other_exts); i++)
  46. if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
  47. return 0xffff;
  48. }
  49. #include "../libpicofe/menu.c"
  50. static const char *men_dummy[] = { NULL };
  51. /* platform specific options and handlers */
  52. #if defined(__GP2X__)
  53. #include "../gp2x/menu.c"
  54. #elif defined(PANDORA)
  55. #include "../pandora/menu.c"
  56. #else
  57. #define MENU_OPTIONS_GFX
  58. #define MENU_OPTIONS_ADV
  59. #endif
  60. static void make_bg(int no_scale)
  61. {
  62. unsigned short *src = (void *)g_menubg_src_ptr;
  63. int w = g_screen_width, h = g_screen_height;
  64. short *dst;
  65. int x, y;
  66. if (src == NULL) {
  67. memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
  68. return;
  69. }
  70. if (!no_scale && g_menuscreen_w / w >= 2 && g_menuscreen_h / h >= 2)
  71. {
  72. unsigned int t, *d = g_menubg_ptr;
  73. d += (g_menuscreen_h / 2 - h * 2 / 2)
  74. * g_menuscreen_w / 2;
  75. d += (g_menuscreen_w / 2 - w * 2 / 2) / 2;
  76. for (y = 0; y < h; y++, src += w, d += g_menuscreen_w*2/2) {
  77. for (x = 0; x < w; x++) {
  78. t = src[x];
  79. t = ((t & 0xf79e)>>1) - ((t & 0xc618)>>3);
  80. t |= t << 16;
  81. d[x] = d[x + g_menuscreen_w / 2] = t;
  82. }
  83. }
  84. return;
  85. }
  86. if (w > g_menuscreen_w)
  87. w = g_menuscreen_w;
  88. if (h > g_menuscreen_h)
  89. h = g_menuscreen_h;
  90. dst = (short *)g_menubg_ptr +
  91. (g_menuscreen_h / 2 - h / 2) * g_menuscreen_w +
  92. (g_menuscreen_w / 2 - w / 2);
  93. // darken the active framebuffer
  94. for (; h > 0; dst += g_menuscreen_w, src += g_screen_width, h--)
  95. menu_darken_bg(dst, src, w, 1);
  96. }
  97. static void menu_enter(int is_rom_loaded)
  98. {
  99. if (is_rom_loaded)
  100. {
  101. make_bg(0);
  102. }
  103. else
  104. {
  105. char buff[256];
  106. // should really only happen once, on startup..
  107. emu_make_path(buff, "skin/background.png", sizeof(buff));
  108. if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0)
  109. memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
  110. }
  111. plat_video_menu_enter(is_rom_loaded);
  112. }
  113. static void draw_savestate_bg(int slot)
  114. {
  115. const char *fname;
  116. void *tmp_state;
  117. fname = emu_get_save_fname(1, 0, slot);
  118. if (!fname)
  119. return;
  120. tmp_state = PicoTmpStateSave();
  121. PicoStateLoadGfx(fname);
  122. /* do a frame and fetch menu bg */
  123. pemu_forced_frame(0, 0);
  124. make_bg(0);
  125. PicoTmpStateRestore(tmp_state);
  126. }
  127. // --------- loading ROM screen ----------
  128. static int cdload_called = 0;
  129. static void load_progress_cb(int percent)
  130. {
  131. int ln, len = percent * g_menuscreen_w / 100;
  132. unsigned short *dst;
  133. if (len > g_menuscreen_w)
  134. len = g_menuscreen_w;
  135. menu_draw_begin(0, 1);
  136. dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
  137. for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
  138. memset(dst, 0xff, len * 2);
  139. menu_draw_end();
  140. }
  141. static void cdload_progress_cb(const char *fname, int percent)
  142. {
  143. int ln, len = percent * g_menuscreen_w / 100;
  144. unsigned short *dst;
  145. menu_draw_begin(0, 1);
  146. dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
  147. memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
  148. smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
  149. smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
  150. dst += g_menuscreen_w * me_sfont_h * 3;
  151. if (len > g_menuscreen_w)
  152. len = g_menuscreen_w;
  153. for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)
  154. memset(dst, 0xff, len * 2);
  155. menu_draw_end();
  156. cdload_called = 1;
  157. }
  158. void menu_romload_prepare(const char *rom_name)
  159. {
  160. const char *p = rom_name + strlen(rom_name);
  161. int i;
  162. while (p > rom_name && *p != '/')
  163. p--;
  164. /* fill all buffers, callbacks won't update in full */
  165. for (i = 0; i < 3; i++) {
  166. menu_draw_begin(1, 1);
  167. smalltext_out16(1, 1, "Loading", 0xffff);
  168. smalltext_out16(1, me_sfont_h, p, 0xffff);
  169. menu_draw_end();
  170. }
  171. PicoCartLoadProgressCB = load_progress_cb;
  172. PicoCDLoadProgressCB = cdload_progress_cb;
  173. cdload_called = 0;
  174. }
  175. void menu_romload_end(void)
  176. {
  177. PicoCartLoadProgressCB = NULL;
  178. PicoCDLoadProgressCB = NULL;
  179. menu_draw_begin(0, 1);
  180. smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
  181. "Starting emulation...", 0xffff);
  182. menu_draw_end();
  183. }
  184. // ------------ patch/gg menu ------------
  185. static void draw_patchlist(int sel)
  186. {
  187. int max_cnt, start, i, pos, active;
  188. max_cnt = g_menuscreen_h / me_sfont_h;
  189. start = max_cnt / 2 - sel;
  190. menu_draw_begin(1, 0);
  191. for (i = 0; i < PicoPatchCount; i++) {
  192. pos = start + i;
  193. if (pos < 0) continue;
  194. if (pos >= max_cnt) break;
  195. active = PicoPatches[i].active;
  196. smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
  197. smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
  198. }
  199. pos = start + i;
  200. if (pos < max_cnt)
  201. smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
  202. text_out16(5, max_cnt / 2 * me_sfont_h, ">");
  203. menu_draw_end();
  204. }
  205. static void menu_loop_patches(void)
  206. {
  207. static int menu_sel = 0;
  208. int inp;
  209. for (;;)
  210. {
  211. draw_patchlist(menu_sel);
  212. inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
  213. |PBTN_MOK|PBTN_MBACK, NULL, 33);
  214. if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
  215. if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
  216. if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
  217. if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
  218. if (inp & PBTN_MOK) { // action
  219. if (menu_sel < PicoPatchCount)
  220. PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
  221. else break;
  222. }
  223. if (inp & PBTN_MBACK)
  224. break;
  225. }
  226. }
  227. // -------------- key config --------------
  228. // PicoPad[] format: MXYZ SACB RLDU
  229. me_bind_action me_ctrl_actions[] =
  230. {
  231. { "UP ", 0x0001 },
  232. { "DOWN ", 0x0002 },
  233. { "LEFT ", 0x0004 },
  234. { "RIGHT ", 0x0008 },
  235. { "A ", 0x0040 },
  236. { "B ", 0x0010 },
  237. { "C ", 0x0020 },
  238. { "A turbo", 0x4000 },
  239. { "B turbo", 0x1000 },
  240. { "C turbo", 0x2000 },
  241. { "START ", 0x0080 },
  242. { "MODE ", 0x0800 },
  243. { "X ", 0x0400 },
  244. { "Y ", 0x0200 },
  245. { "Z ", 0x0100 },
  246. { NULL, 0 },
  247. };
  248. me_bind_action emuctrl_actions[] =
  249. {
  250. { "Load State ", PEV_STATE_LOAD },
  251. { "Save State ", PEV_STATE_SAVE },
  252. { "Prev Save Slot ", PEV_SSLOT_PREV },
  253. { "Next Save Slot ", PEV_SSLOT_NEXT },
  254. { "Switch Renderer ", PEV_SWITCH_RND },
  255. { "Volume Down ", PEV_VOL_DOWN },
  256. { "Volume Up ", PEV_VOL_UP },
  257. { "Fast forward ", PEV_FF },
  258. { "Enter Menu ", PEV_MENU },
  259. { "Pico Next page ", PEV_PICO_PNEXT },
  260. { "Pico Prev page ", PEV_PICO_PPREV },
  261. { "Pico Switch input", PEV_PICO_SWINP },
  262. { NULL, 0 }
  263. };
  264. static int key_config_loop_wrap(int id, int keys)
  265. {
  266. switch (id) {
  267. case MA_CTRL_PLAYER1:
  268. key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
  269. break;
  270. case MA_CTRL_PLAYER2:
  271. key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
  272. break;
  273. case MA_CTRL_EMU:
  274. key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
  275. break;
  276. default:
  277. break;
  278. }
  279. return 0;
  280. }
  281. static const char *mgn_dev_name(int id, int *offs)
  282. {
  283. const char *name = NULL;
  284. static int it = 0;
  285. if (id == MA_CTRL_DEV_FIRST)
  286. it = 0;
  287. for (; it < IN_MAX_DEVS; it++) {
  288. name = in_get_dev_name(it, 1, 1);
  289. if (name != NULL)
  290. break;
  291. }
  292. it++;
  293. return name;
  294. }
  295. static int mh_saveloadcfg(int id, int keys);
  296. static const char *mgn_saveloadcfg(int id, int *offs);
  297. const char *indev_names[] = { "none", "3 button pad", "6 button pad", NULL };
  298. static menu_entry e_menu_keyconfig[] =
  299. {
  300. mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
  301. mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
  302. mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
  303. mee_enum ("Input device 1", MA_OPT_INPUT_DEV0, currentConfig.input_dev0, indev_names),
  304. mee_enum ("Input device 2", MA_OPT_INPUT_DEV1, currentConfig.input_dev1, indev_names),
  305. mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
  306. mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
  307. mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
  308. mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
  309. mee_label (""),
  310. mee_label ("Input devices:"),
  311. mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
  312. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  313. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  314. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  315. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  316. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  317. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  318. mee_end,
  319. };
  320. static int menu_loop_keyconfig(int id, int keys)
  321. {
  322. static int sel = 0;
  323. me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
  324. me_loop(e_menu_keyconfig, &sel);
  325. PicoSetInputDevice(0, currentConfig.input_dev0);
  326. PicoSetInputDevice(1, currentConfig.input_dev1);
  327. return 0;
  328. }
  329. // ------------ SCD options menu ------------
  330. static const char *mgn_cdopt_ra(int id, int *offs)
  331. {
  332. *offs = -5;
  333. if (PicoCDBuffers <= 0)
  334. return " OFF";
  335. sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
  336. return static_buff;
  337. }
  338. static int mh_cdopt_ra(int id, int keys)
  339. {
  340. if (keys & PBTN_LEFT) {
  341. PicoCDBuffers >>= 1;
  342. if (PicoCDBuffers < 2)
  343. PicoCDBuffers = 0;
  344. } else {
  345. if (PicoCDBuffers <= 0)
  346. PicoCDBuffers = 1;
  347. PicoCDBuffers <<= 1;
  348. if (PicoCDBuffers > 8*1024)
  349. PicoCDBuffers = 8*1024; // 16M
  350. }
  351. return 0;
  352. }
  353. static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
  354. static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
  355. static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
  356. static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
  357. "most games don't need this";
  358. static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
  359. "disable to improve performance";
  360. static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
  361. "disable to improve performance";
  362. static menu_entry e_menu_cd_options[] =
  363. {
  364. mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
  365. mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
  366. mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
  367. mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
  368. mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
  369. mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
  370. mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync),
  371. mee_end,
  372. };
  373. static int menu_loop_cd_options(int id, int keys)
  374. {
  375. static int sel = 0;
  376. me_loop(e_menu_cd_options, &sel);
  377. return 0;
  378. }
  379. // ------------ 32X options menu ------------
  380. #ifndef NO_32X
  381. // convert from multiplier of VClk
  382. static int mh_opt_sh2cycles(int id, int keys)
  383. {
  384. int *khz = (id == MA_32XOPT_MSH2_CYCLES) ?
  385. &currentConfig.msh2_khz : &currentConfig.ssh2_khz;
  386. if (keys & (PBTN_LEFT|PBTN_RIGHT))
  387. *khz += (keys & PBTN_LEFT) ? -50 : 50;
  388. if (keys & (PBTN_L|PBTN_R))
  389. *khz += (keys & PBTN_L) ? -500 : 500;
  390. if (*khz < 1)
  391. *khz = 1;
  392. else if (*khz > 0x7fffffff / 1000)
  393. *khz = 0x7fffffff / 1000;
  394. return 0;
  395. }
  396. static const char *mgn_opt_sh2cycles(int id, int *offs)
  397. {
  398. int khz = (id == MA_32XOPT_MSH2_CYCLES) ?
  399. currentConfig.msh2_khz : currentConfig.ssh2_khz;
  400. sprintf(static_buff, "%d", khz);
  401. return static_buff;
  402. }
  403. static const char h_32x_enable[] = "Enable emulation of the 32X addon";
  404. static const char h_pwm[] = "Disabling may improve performance, but break sound";
  405. static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
  406. "lower values speed up emulation but break games\n"
  407. "at least 11000 recommended for compatibility";
  408. static menu_entry e_menu_32x_options[] =
  409. {
  410. mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
  411. mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
  412. mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
  413. mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
  414. mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
  415. mee_end,
  416. };
  417. static int menu_loop_32x_options(int id, int keys)
  418. {
  419. static int sel = 0;
  420. me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
  421. me_loop(e_menu_32x_options, &sel);
  422. Pico32xSetClocks(currentConfig.msh2_khz * 1000, currentConfig.msh2_khz * 1000);
  423. return 0;
  424. }
  425. #endif
  426. // ------------ adv options menu ------------
  427. static menu_entry e_menu_adv_options[] =
  428. {
  429. mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
  430. mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
  431. mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
  432. mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
  433. mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
  434. mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
  435. mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
  436. mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
  437. mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
  438. mee_onoff ("Enable dynarecs", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC),
  439. mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC),
  440. MENU_OPTIONS_ADV
  441. mee_end,
  442. };
  443. static int menu_loop_adv_options(int id, int keys)
  444. {
  445. static int sel = 0;
  446. me_loop(e_menu_adv_options, &sel);
  447. return 0;
  448. }
  449. // ------------ gfx options menu ------------
  450. static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)";
  451. static const char *mgn_aopt_gamma(int id, int *offs)
  452. {
  453. sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
  454. return static_buff;
  455. }
  456. static menu_entry e_menu_gfx_options[] =
  457. {
  458. mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
  459. mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
  460. mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
  461. mee_range_cust_h("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma, h_gamma),
  462. MENU_OPTIONS_GFX
  463. mee_end,
  464. };
  465. static int menu_loop_gfx_options(int id, int keys)
  466. {
  467. static int sel = 0;
  468. me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
  469. me_loop(e_menu_gfx_options, &sel);
  470. return 0;
  471. }
  472. // ------------ options menu ------------
  473. static menu_entry e_menu_options[];
  474. static int sndrate_prevnext(int rate, int dir)
  475. {
  476. static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
  477. int i;
  478. for (i = 0; i < 5; i++)
  479. if (rates[i] == rate) break;
  480. i += dir ? 1 : -1;
  481. if (i > 4) {
  482. if (!(PicoOpt & POPT_EN_STEREO)) {
  483. PicoOpt |= POPT_EN_STEREO;
  484. return rates[0];
  485. }
  486. return rates[4];
  487. }
  488. if (i < 0) {
  489. if (PicoOpt & POPT_EN_STEREO) {
  490. PicoOpt &= ~POPT_EN_STEREO;
  491. return rates[4];
  492. }
  493. return rates[0];
  494. }
  495. return rates[i];
  496. }
  497. static void region_prevnext(int right)
  498. {
  499. // jp_ntsc=1, jp_pal=2, usa=4, eu=8
  500. static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
  501. int i;
  502. if (right) {
  503. if (!PicoRegionOverride) {
  504. for (i = 0; i < 6; i++)
  505. if (rgn_orders[i] == PicoAutoRgnOrder) break;
  506. if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
  507. else PicoRegionOverride=1;
  508. }
  509. else
  510. PicoRegionOverride <<= 1;
  511. if (PicoRegionOverride > 8)
  512. PicoRegionOverride = 8;
  513. } else {
  514. if (!PicoRegionOverride) {
  515. for (i = 0; i < 6; i++)
  516. if (rgn_orders[i] == PicoAutoRgnOrder) break;
  517. if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
  518. }
  519. else
  520. PicoRegionOverride >>= 1;
  521. }
  522. }
  523. static int mh_opt_misc(int id, int keys)
  524. {
  525. switch (id) {
  526. case MA_OPT_SOUND_QUALITY:
  527. PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
  528. break;
  529. case MA_OPT_REGION:
  530. region_prevnext(keys & PBTN_RIGHT);
  531. break;
  532. default:
  533. break;
  534. }
  535. return 0;
  536. }
  537. static int mh_saveloadcfg(int id, int keys)
  538. {
  539. int ret;
  540. if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
  541. config_slot += (keys & PBTN_LEFT) ? -1 : 1;
  542. if (config_slot < 0) config_slot = 9;
  543. else if (config_slot > 9) config_slot = 0;
  544. me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
  545. return 0;
  546. }
  547. switch (id) {
  548. case MA_OPT_SAVECFG:
  549. case MA_OPT_SAVECFG_GAME:
  550. if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
  551. menu_update_msg("config saved");
  552. else
  553. menu_update_msg("failed to write config");
  554. break;
  555. case MA_OPT_LOADCFG:
  556. ret = emu_read_config(rom_fname_loaded, 1);
  557. if (!ret) ret = emu_read_config(NULL, 1);
  558. if (ret) menu_update_msg("config loaded");
  559. else menu_update_msg("failed to load config");
  560. break;
  561. default:
  562. return 0;
  563. }
  564. return 1;
  565. }
  566. static int mh_restore_defaults(int id, int keys)
  567. {
  568. emu_set_defconfig();
  569. menu_update_msg("defaults restored");
  570. return 1;
  571. }
  572. static const char *mgn_opt_fskip(int id, int *offs)
  573. {
  574. if (currentConfig.Frameskip < 0)
  575. return "Auto";
  576. sprintf(static_buff, "%d", currentConfig.Frameskip);
  577. return static_buff;
  578. }
  579. static const char *mgn_opt_sound(int id, int *offs)
  580. {
  581. const char *str2;
  582. *offs = -8;
  583. str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
  584. sprintf(static_buff, "%5iHz %s", PsndRate, str2);
  585. return static_buff;
  586. }
  587. static const char *mgn_opt_region(int id, int *offs)
  588. {
  589. static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
  590. static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
  591. int code = PicoRegionOverride;
  592. int u, i = 0;
  593. *offs = -6;
  594. if (code) {
  595. code <<= 1;
  596. while ((code >>= 1)) i++;
  597. if (i > 4)
  598. return "unknown";
  599. return names[i];
  600. } else {
  601. strcpy(static_buff, "Auto:");
  602. for (u = 0; u < 3; u++) {
  603. code = (PicoAutoRgnOrder >> u*4) & 0xf;
  604. for (i = 0; code; code >>= 1, i++)
  605. ;
  606. strcat(static_buff, names_short[i]);
  607. }
  608. return static_buff;
  609. }
  610. }
  611. static const char *mgn_saveloadcfg(int id, int *offs)
  612. {
  613. static_buff[0] = 0;
  614. if (config_slot != 0)
  615. sprintf(static_buff, "[%i]", config_slot);
  616. return static_buff;
  617. }
  618. static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
  619. static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
  620. "loading state or both";
  621. static menu_entry e_menu_options[] =
  622. {
  623. mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
  624. mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
  625. mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
  626. mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
  627. mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
  628. mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
  629. mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
  630. mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 1200),
  631. mee_handler ("[Display options]", menu_loop_gfx_options),
  632. mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
  633. #ifndef NO_32X
  634. mee_handler ("[32X options]", menu_loop_32x_options),
  635. #endif
  636. mee_handler ("[Advanced options]", menu_loop_adv_options),
  637. mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
  638. mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
  639. mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
  640. mee_handler ("Restore defaults", mh_restore_defaults),
  641. mee_end,
  642. };
  643. static int menu_loop_options(int id, int keys)
  644. {
  645. static int sel = 0;
  646. me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
  647. me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
  648. me_loop(e_menu_options, &sel);
  649. return 0;
  650. }
  651. // ------------ debug menu ------------
  652. #include <pico/debug.h>
  653. extern void SekStepM68k(void);
  654. static void mplayer_loop(void)
  655. {
  656. pemu_sound_start();
  657. while (1)
  658. {
  659. PDebugZ80Frame();
  660. if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
  661. break;
  662. emu_sound_wait();
  663. }
  664. emu_sound_stop();
  665. }
  666. static void draw_text_debug(const char *str, int skip, int from)
  667. {
  668. const char *p;
  669. int line;
  670. p = str;
  671. while (skip-- > 0)
  672. {
  673. while (*p && *p != '\n')
  674. p++;
  675. if (*p == 0 || p[1] == 0)
  676. return;
  677. p++;
  678. }
  679. str = p;
  680. for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
  681. {
  682. smalltext_out16(1, line * me_sfont_h, str, 0xffff);
  683. while (*p && *p != '\n')
  684. p++;
  685. if (*p == 0)
  686. break;
  687. p++; str = p;
  688. }
  689. }
  690. #ifdef __GNUC__
  691. #define COMPILER "gcc " __VERSION__
  692. #else
  693. #define COMPILER
  694. #endif
  695. static void draw_frame_debug(void)
  696. {
  697. char layer_str[48] = "layers: ";
  698. if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
  699. if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
  700. if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
  701. if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
  702. if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4);
  703. pemu_forced_frame(1, 0);
  704. make_bg(1);
  705. smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
  706. smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
  707. }
  708. static void debug_menu_loop(void)
  709. {
  710. int inp, mode = 0;
  711. int spr_offs = 0, dumped = 0;
  712. char *tmp;
  713. while (1)
  714. {
  715. menu_draw_begin(1, 0);
  716. switch (mode)
  717. {
  718. case 0: tmp = PDebugMain();
  719. plat_debug_cat(tmp);
  720. draw_text_debug(tmp, 0, 0);
  721. if (dumped) {
  722. smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
  723. g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
  724. dumped = 0;
  725. }
  726. break;
  727. case 1: draw_frame_debug();
  728. break;
  729. case 2: pemu_forced_frame(1, 0);
  730. make_bg(1);
  731. PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
  732. g_menuscreen_w/2 - 320/2, g_menuscreen_w);
  733. break;
  734. case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
  735. PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
  736. PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
  737. g_menuscreen_w, spr_offs);
  738. draw_text_debug(PDebugSpriteList(), spr_offs, 6);
  739. break;
  740. case 4: tmp = PDebug32x();
  741. draw_text_debug(tmp, 0, 0);
  742. break;
  743. }
  744. menu_draw_end();
  745. inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
  746. PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
  747. if (inp & PBTN_MBACK) return;
  748. if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
  749. if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
  750. switch (mode)
  751. {
  752. case 0:
  753. if (inp & PBTN_MOK)
  754. PDebugCPUStep();
  755. if (inp & PBTN_MA3) {
  756. while (inp & PBTN_MA3)
  757. inp = in_menu_wait_any(NULL, -1);
  758. mplayer_loop();
  759. }
  760. if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
  761. mkdir("dumps", 0777);
  762. PDebugDumpMem();
  763. while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
  764. dumped = 1;
  765. }
  766. break;
  767. case 1:
  768. if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
  769. if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
  770. if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
  771. if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
  772. if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON;
  773. if (inp & PBTN_MOK) {
  774. PsndOut = NULL; // just in case
  775. PicoSkipFrame = 1;
  776. PicoFrame();
  777. PicoSkipFrame = 0;
  778. while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
  779. }
  780. break;
  781. case 3:
  782. if (inp & PBTN_DOWN) spr_offs++;
  783. if (inp & PBTN_UP) spr_offs--;
  784. if (spr_offs < 0) spr_offs = 0;
  785. break;
  786. }
  787. }
  788. }
  789. // ------------ main menu ------------
  790. static const char credits[] =
  791. "PicoDrive v" VERSION " (c) notaz, 2006-2011\n\n\n"
  792. "Credits:\n"
  793. "fDave: Cyclone 68000 core,\n"
  794. " base code of PicoDrive\n"
  795. "Reesy & FluBBa: DrZ80 core\n"
  796. "MAME devs: YM2612 and SN76496 cores\n"
  797. "Inder, ketchupgun: graphics\n"
  798. #ifdef __GP2X__
  799. "rlyeh and others: minimal SDK\n"
  800. "Squidge: mmuhack\n"
  801. "Dzz: ARM940 sample\n"
  802. #endif
  803. "\n"
  804. "special thanks (for docs, ideas):\n"
  805. " Charles MacDonald, Haze,\n"
  806. " Stephane Dallongeville,\n"
  807. " Lordus, Exophase, Rokas,\n"
  808. " Nemesis, Tasco Deluxe";
  809. static void menu_main_draw_status(void)
  810. {
  811. static time_t last_bat_read = 0;
  812. static int last_bat_val = -1;
  813. unsigned short *bp = g_screen_ptr;
  814. int bat_h = me_mfont_h * 2 / 3;
  815. int i, u, w, wfill, batt_val;
  816. struct tm *tmp;
  817. time_t ltime;
  818. char time_s[16];
  819. if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
  820. return;
  821. ltime = time(NULL);
  822. tmp = gmtime(&ltime);
  823. strftime(time_s, sizeof(time_s), "%H:%M", tmp);
  824. text_out16(g_screen_width - me_mfont_w * 6, me_mfont_h + 2, time_s);
  825. if (ltime - last_bat_read > 10) {
  826. last_bat_read = ltime;
  827. last_bat_val = batt_val = plat_target_bat_capacity_get();
  828. }
  829. else
  830. batt_val = last_bat_val;
  831. if (batt_val < 0 || batt_val > 100)
  832. return;
  833. /* battery info */
  834. bp += (me_mfont_h * 2 + 2) * g_screen_width + g_screen_width - me_mfont_w * 3 - 3;
  835. for (i = 0; i < me_mfont_w * 2; i++)
  836. bp[i] = menu_text_color;
  837. for (i = 0; i < me_mfont_w * 2; i++)
  838. bp[i + g_screen_width * bat_h] = menu_text_color;
  839. for (i = 0; i <= bat_h; i++)
  840. bp[i * g_screen_width] =
  841. bp[i * g_screen_width + me_mfont_w * 2] = menu_text_color;
  842. for (i = 2; i < bat_h - 1; i++)
  843. bp[i * g_screen_width - 1] =
  844. bp[i * g_screen_width - 2] = menu_text_color;
  845. w = me_mfont_w * 2 - 1;
  846. wfill = batt_val * w / 100;
  847. for (u = 1; u < bat_h; u++)
  848. for (i = 0; i < wfill; i++)
  849. bp[(w - i) + g_screen_width * u] = menu_text_color;
  850. }
  851. static int main_menu_handler(int id, int keys)
  852. {
  853. const char *ret_name;
  854. switch (id)
  855. {
  856. case MA_MAIN_RESUME_GAME:
  857. if (PicoGameLoaded)
  858. return 1;
  859. break;
  860. case MA_MAIN_SAVE_STATE:
  861. if (PicoGameLoaded)
  862. return menu_loop_savestate(0);
  863. break;
  864. case MA_MAIN_LOAD_STATE:
  865. if (PicoGameLoaded)
  866. return menu_loop_savestate(1);
  867. break;
  868. case MA_MAIN_RESET_GAME:
  869. if (PicoGameLoaded) {
  870. emu_reset_game();
  871. return 1;
  872. }
  873. break;
  874. case MA_MAIN_LOAD_ROM:
  875. rom_fname_reload = NULL;
  876. ret_name = menu_loop_romsel(rom_fname_loaded,
  877. sizeof(rom_fname_loaded), rom_exts, NULL);
  878. if (ret_name != NULL) {
  879. lprintf("selected file: %s\n", ret_name);
  880. rom_fname_reload = ret_name;
  881. engineState = PGS_ReloadRom;
  882. return 1;
  883. }
  884. break;
  885. case MA_MAIN_CREDITS:
  886. draw_menu_message(credits, NULL);
  887. in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
  888. break;
  889. case MA_MAIN_EXIT:
  890. engineState = PGS_Quit;
  891. return 1;
  892. case MA_MAIN_PATCHES:
  893. if (PicoGameLoaded && PicoPatches) {
  894. menu_loop_patches();
  895. PicoPatchApply();
  896. menu_update_msg("Patches applied");
  897. }
  898. break;
  899. default:
  900. lprintf("%s: something unknown selected\n", __FUNCTION__);
  901. break;
  902. }
  903. return 0;
  904. }
  905. static menu_entry e_menu_main[] =
  906. {
  907. mee_label ("PicoDrive " VERSION),
  908. mee_label (""),
  909. mee_label (""),
  910. mee_label (""),
  911. mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
  912. mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
  913. mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
  914. mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
  915. mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
  916. mee_handler ("Change options", menu_loop_options),
  917. mee_handler ("Configure controls", menu_loop_keyconfig),
  918. mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
  919. mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
  920. mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
  921. mee_end,
  922. };
  923. void menu_loop(void)
  924. {
  925. static int sel = 0;
  926. me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
  927. me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
  928. me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
  929. me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
  930. me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
  931. menu_enter(PicoGameLoaded);
  932. in_set_config_int(0, IN_CFG_BLOCKING, 1);
  933. me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
  934. if (PicoGameLoaded) {
  935. if (engineState == PGS_Menu)
  936. engineState = PGS_Running;
  937. /* wait until menu, ok, back is released */
  938. while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
  939. ;
  940. }
  941. in_set_config_int(0, IN_CFG_BLOCKING, 0);
  942. plat_video_menu_leave();
  943. }
  944. // --------- CD tray close menu ----------
  945. static int mh_tray_load_cd(int id, int keys)
  946. {
  947. const char *ret_name;
  948. rom_fname_reload = NULL;
  949. ret_name = menu_loop_romsel(rom_fname_loaded,
  950. sizeof(rom_fname_loaded), rom_exts, NULL);
  951. if (ret_name == NULL)
  952. return 0;
  953. rom_fname_reload = ret_name;
  954. engineState = PGS_RestartRun;
  955. return emu_swap_cd(ret_name);
  956. }
  957. static int mh_tray_nothing(int id, int keys)
  958. {
  959. return 1;
  960. }
  961. static menu_entry e_menu_tray[] =
  962. {
  963. mee_label ("The CD tray has opened."),
  964. mee_label (""),
  965. mee_label (""),
  966. mee_handler("Load CD image", mh_tray_load_cd),
  967. mee_handler("Insert nothing", mh_tray_nothing),
  968. mee_end,
  969. };
  970. int menu_loop_tray(void)
  971. {
  972. int ret = 1, sel = 0;
  973. menu_enter(PicoGameLoaded);
  974. in_set_config_int(0, IN_CFG_BLOCKING, 1);
  975. me_loop(e_menu_tray, &sel);
  976. if (engineState != PGS_RestartRun) {
  977. engineState = PGS_RestartRun;
  978. ret = 0; /* no CD inserted */
  979. }
  980. while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
  981. ;
  982. in_set_config_int(0, IN_CFG_BLOCKING, 0);
  983. plat_video_menu_leave();
  984. return ret;
  985. }
  986. void menu_update_msg(const char *msg)
  987. {
  988. strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
  989. menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
  990. menu_error_time = plat_get_ticks_ms();
  991. lprintf("msg: %s\n", menu_error_msg);
  992. }
  993. // ------------ util ------------
  994. /* hidden options for config engine only */
  995. static menu_entry e_menu_hidden[] =
  996. {
  997. mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
  998. mee_end,
  999. };
  1000. static menu_entry *e_menu_table[] =
  1001. {
  1002. e_menu_options,
  1003. e_menu_gfx_options,
  1004. e_menu_adv_options,
  1005. e_menu_cd_options,
  1006. #ifndef NO_32X
  1007. e_menu_32x_options,
  1008. #endif
  1009. e_menu_keyconfig,
  1010. e_menu_hidden,
  1011. };
  1012. static menu_entry *me_list_table = NULL;
  1013. static menu_entry *me_list_i = NULL;
  1014. menu_entry *me_list_get_first(void)
  1015. {
  1016. me_list_table = me_list_i = e_menu_table[0];
  1017. return me_list_i;
  1018. }
  1019. menu_entry *me_list_get_next(void)
  1020. {
  1021. int i;
  1022. me_list_i++;
  1023. if (me_list_i->name != NULL)
  1024. return me_list_i;
  1025. for (i = 0; i < array_size(e_menu_table); i++)
  1026. if (me_list_table == e_menu_table[i])
  1027. break;
  1028. if (i + 1 < array_size(e_menu_table))
  1029. me_list_table = me_list_i = e_menu_table[i + 1];
  1030. else
  1031. me_list_table = me_list_i = NULL;
  1032. return me_list_i;
  1033. }
  1034. void menu_init(void)
  1035. {
  1036. int i;
  1037. menu_init_base();
  1038. i = 0;
  1039. #if defined(_SVP_DRC) || defined(DRC_SH2)
  1040. i = 1;
  1041. #endif
  1042. me_enable(e_menu_adv_options, MA_OPT2_SVP_DYNAREC, i);
  1043. i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
  1044. e_menu_gfx_options[i].data = plat_target.vout_methods;
  1045. me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
  1046. plat_target.vout_methods != NULL);
  1047. i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
  1048. e_menu_gfx_options[i].data = plat_target.hwfilters;
  1049. me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
  1050. plat_target.hwfilters != NULL);
  1051. me_enable(e_menu_gfx_options, MA_OPT2_GAMMA,
  1052. plat_target.gamma_set != NULL);
  1053. i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
  1054. e_menu_options[i].enabled = 0;
  1055. if (plat_target.cpu_clock_set != NULL) {
  1056. e_menu_options[i].name = "CPU clock";
  1057. e_menu_options[i].enabled = 1;
  1058. }
  1059. }