menu_pico.c 34 KB

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