menu_pico.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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 ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoIn.opt, POPT_EN_PSG),
  414. mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
  415. mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
  416. mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoIn.opt, POPT_DIS_IDLE_DET),
  417. mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
  418. mee_onoff ("Enable dynarecs", MA_OPT2_DYNARECS, PicoIn.opt, POPT_EN_DRC),
  419. mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC),
  420. mee_range ("Max auto frameskip", MA_OPT2_MAX_FRAMESKIP, currentConfig.max_skip, 1, 10),
  421. mee_onoff ("PWM IRQ optimization", MA_OPT2_PWM_IRQ_OPT, PicoIn.opt, POPT_PWM_IRQ_OPT),
  422. MENU_OPTIONS_ADV
  423. mee_end,
  424. };
  425. static int menu_loop_adv_options(int id, int keys)
  426. {
  427. static int sel = 0;
  428. me_loop(e_menu_adv_options, &sel);
  429. PicoIn.overclockM68k = currentConfig.overclock_68k; // int vs short
  430. return 0;
  431. }
  432. // ------------ gfx options menu ------------
  433. static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)";
  434. static const char *mgn_aopt_gamma(int id, int *offs)
  435. {
  436. sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
  437. return static_buff;
  438. }
  439. static menu_entry e_menu_gfx_options[] =
  440. {
  441. mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
  442. mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
  443. mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
  444. mee_range_cust_h("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma, h_gamma),
  445. MENU_OPTIONS_GFX
  446. mee_end,
  447. };
  448. static int menu_loop_gfx_options(int id, int keys)
  449. {
  450. static int sel = 0;
  451. me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
  452. me_loop(e_menu_gfx_options, &sel);
  453. return 0;
  454. }
  455. // ------------ options menu ------------
  456. static menu_entry e_menu_options[];
  457. static int sndrate_prevnext(int rate, int dir)
  458. {
  459. static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
  460. int i;
  461. for (i = 0; i < 5; i++)
  462. if (rates[i] == rate) break;
  463. i += dir ? 1 : -1;
  464. if (i > 4) {
  465. if (!(PicoIn.opt & POPT_EN_STEREO)) {
  466. PicoIn.opt |= POPT_EN_STEREO;
  467. return rates[0];
  468. }
  469. return rates[4];
  470. }
  471. if (i < 0) {
  472. if (PicoIn.opt & POPT_EN_STEREO) {
  473. PicoIn.opt &= ~POPT_EN_STEREO;
  474. return rates[4];
  475. }
  476. return rates[0];
  477. }
  478. return rates[i];
  479. }
  480. static void region_prevnext(int right)
  481. {
  482. // jp_ntsc=1, jp_pal=2, usa=4, eu=8
  483. static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
  484. int i;
  485. if (right) {
  486. if (!PicoIn.regionOverride) {
  487. for (i = 0; i < 6; i++)
  488. if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
  489. if (i < 5) PicoIn.autoRgnOrder = rgn_orders[i+1];
  490. else PicoIn.regionOverride=1;
  491. }
  492. else
  493. PicoIn.regionOverride <<= 1;
  494. if (PicoIn.regionOverride > 8)
  495. PicoIn.regionOverride = 8;
  496. } else {
  497. if (!PicoIn.regionOverride) {
  498. for (i = 0; i < 6; i++)
  499. if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
  500. if (i > 0) PicoIn.autoRgnOrder = rgn_orders[i-1];
  501. }
  502. else
  503. PicoIn.regionOverride >>= 1;
  504. }
  505. }
  506. static int mh_opt_misc(int id, int keys)
  507. {
  508. switch (id) {
  509. case MA_OPT_SOUND_QUALITY:
  510. PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, keys & PBTN_RIGHT);
  511. break;
  512. case MA_OPT_REGION:
  513. region_prevnext(keys & PBTN_RIGHT);
  514. break;
  515. default:
  516. break;
  517. }
  518. return 0;
  519. }
  520. static int mh_saveloadcfg(int id, int keys)
  521. {
  522. int ret;
  523. if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
  524. config_slot += (keys & PBTN_LEFT) ? -1 : 1;
  525. if (config_slot < 0) config_slot = 9;
  526. else if (config_slot > 9) config_slot = 0;
  527. me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
  528. return 0;
  529. }
  530. switch (id) {
  531. case MA_OPT_SAVECFG:
  532. case MA_OPT_SAVECFG_GAME:
  533. if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
  534. menu_update_msg("config saved");
  535. else
  536. menu_update_msg("failed to write config");
  537. break;
  538. case MA_OPT_LOADCFG:
  539. ret = emu_read_config(rom_fname_loaded, 1);
  540. if (!ret) ret = emu_read_config(NULL, 1);
  541. if (ret) menu_update_msg("config loaded");
  542. else menu_update_msg("failed to load config");
  543. break;
  544. default:
  545. return 0;
  546. }
  547. return 1;
  548. }
  549. static int mh_restore_defaults(int id, int keys)
  550. {
  551. emu_set_defconfig();
  552. menu_update_msg("defaults restored");
  553. return 1;
  554. }
  555. static const char *mgn_opt_fskip(int id, int *offs)
  556. {
  557. if (currentConfig.Frameskip < 0)
  558. return "Auto";
  559. sprintf(static_buff, "%d", currentConfig.Frameskip);
  560. return static_buff;
  561. }
  562. static const char *mgn_opt_sound(int id, int *offs)
  563. {
  564. const char *str2;
  565. *offs = -8;
  566. str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono";
  567. sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2);
  568. return static_buff;
  569. }
  570. static const char *mgn_opt_region(int id, int *offs)
  571. {
  572. static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
  573. static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
  574. int code = PicoIn.regionOverride;
  575. int u, i = 0;
  576. *offs = -6;
  577. if (code) {
  578. code <<= 1;
  579. while ((code >>= 1)) i++;
  580. if (i > 4)
  581. return "unknown";
  582. return names[i];
  583. } else {
  584. strcpy(static_buff, "Auto:");
  585. for (u = 0; u < 3; u++) {
  586. code = (PicoIn.autoRgnOrder >> u*4) & 0xf;
  587. for (i = 0; code; code >>= 1, i++)
  588. ;
  589. strcat(static_buff, names_short[i]);
  590. }
  591. return static_buff;
  592. }
  593. }
  594. static const char *mgn_saveloadcfg(int id, int *offs)
  595. {
  596. static_buff[0] = 0;
  597. if (config_slot != 0)
  598. sprintf(static_buff, "[%i]", config_slot);
  599. return static_buff;
  600. }
  601. static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
  602. static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
  603. "loading state or both";
  604. static menu_entry e_menu_options[] =
  605. {
  606. mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
  607. mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
  608. mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
  609. mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
  610. mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
  611. mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
  612. mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
  613. mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 3200),
  614. mee_handler ("[Display options]", menu_loop_gfx_options),
  615. mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
  616. #ifndef NO_32X
  617. mee_handler ("[32X options]", menu_loop_32x_options),
  618. #endif
  619. mee_handler ("[Advanced options]", menu_loop_adv_options),
  620. mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
  621. mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
  622. mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
  623. mee_handler ("Restore defaults", mh_restore_defaults),
  624. mee_end,
  625. };
  626. static int menu_loop_options(int id, int keys)
  627. {
  628. static int sel = 0;
  629. me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
  630. me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
  631. me_loop(e_menu_options, &sel);
  632. return 0;
  633. }
  634. // ------------ debug menu ------------
  635. #include <pico/debug.h>
  636. extern void SekStepM68k(void);
  637. static void mplayer_loop(void)
  638. {
  639. pemu_sound_start();
  640. while (1)
  641. {
  642. PDebugZ80Frame();
  643. if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
  644. break;
  645. emu_sound_wait();
  646. }
  647. emu_sound_stop();
  648. }
  649. static void draw_text_debug(const char *str, int skip, int from)
  650. {
  651. const char *p;
  652. int line;
  653. p = str;
  654. while (skip-- > 0)
  655. {
  656. while (*p && *p != '\n')
  657. p++;
  658. if (*p == 0 || p[1] == 0)
  659. return;
  660. p++;
  661. }
  662. str = p;
  663. for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
  664. {
  665. smalltext_out16(1, line * me_sfont_h, str, 0xffff);
  666. while (*p && *p != '\n')
  667. p++;
  668. if (*p == 0)
  669. break;
  670. p++; str = p;
  671. }
  672. }
  673. #ifdef __GNUC__
  674. #define COMPILER "gcc " __VERSION__
  675. #else
  676. #define COMPILER
  677. #endif
  678. static void draw_frame_debug(void)
  679. {
  680. char layer_str[48] = "layers: ";
  681. struct PicoVideo *pv = &Pico.video;
  682. if (!(pv->debug_p & PVD_KILL_B)) memcpy(layer_str + 8, "B", 1);
  683. if (!(pv->debug_p & PVD_KILL_A)) memcpy(layer_str + 10, "A", 1);
  684. if (!(pv->debug_p & PVD_KILL_S_LO)) memcpy(layer_str + 12, "spr_lo", 6);
  685. if (!(pv->debug_p & PVD_KILL_S_HI)) memcpy(layer_str + 19, "spr_hi", 6);
  686. if (!(pv->debug_p & PVD_KILL_32X)) memcpy(layer_str + 26, "32x", 4);
  687. pemu_forced_frame(1, 0);
  688. make_bg(1);
  689. smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
  690. smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
  691. }
  692. static void debug_menu_loop(void)
  693. {
  694. struct PicoVideo *pv = &Pico.video;
  695. int inp, mode = 0;
  696. int spr_offs = 0, dumped = 0;
  697. char *tmp;
  698. while (1)
  699. {
  700. menu_draw_begin(1, 0);
  701. switch (mode)
  702. {
  703. case 0: tmp = PDebugMain();
  704. plat_debug_cat(tmp);
  705. draw_text_debug(tmp, 0, 0);
  706. if (dumped) {
  707. smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
  708. g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
  709. dumped = 0;
  710. }
  711. break;
  712. case 1: draw_frame_debug();
  713. break;
  714. case 2: pemu_forced_frame(1, 0);
  715. make_bg(1);
  716. PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr
  717. + (g_menuscreen_h/2 - 240/2) * g_menuscreen_pp
  718. + g_menuscreen_w/2 - 320/2, g_menuscreen_pp);
  719. break;
  720. case 3: menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
  721. PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_pp);
  722. PDebugShowSprite((unsigned short *)g_menuscreen_ptr
  723. + g_menuscreen_pp * 120 + g_menuscreen_w / 2 + 16,
  724. g_menuscreen_pp, spr_offs);
  725. draw_text_debug(PDebugSpriteList(), spr_offs, 6);
  726. break;
  727. case 4: tmp = PDebug32x();
  728. draw_text_debug(tmp, 0, 0);
  729. break;
  730. }
  731. menu_draw_end();
  732. inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
  733. PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
  734. if (inp & PBTN_MBACK) return;
  735. if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
  736. if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
  737. switch (mode)
  738. {
  739. case 0:
  740. if (inp & PBTN_MOK)
  741. PDebugCPUStep();
  742. if (inp & PBTN_MA3) {
  743. while (inp & PBTN_MA3)
  744. inp = in_menu_wait_any(NULL, -1);
  745. mplayer_loop();
  746. }
  747. if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
  748. mkdir("dumps", 0777);
  749. PDebugDumpMem();
  750. while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
  751. dumped = 1;
  752. }
  753. break;
  754. case 1:
  755. if (inp & PBTN_LEFT) pv->debug_p ^= PVD_KILL_B;
  756. if (inp & PBTN_RIGHT) pv->debug_p ^= PVD_KILL_A;
  757. if (inp & PBTN_DOWN) pv->debug_p ^= PVD_KILL_S_LO;
  758. if (inp & PBTN_UP) pv->debug_p ^= PVD_KILL_S_HI;
  759. if (inp & PBTN_MA2) pv->debug_p ^= PVD_KILL_32X;
  760. if (inp & PBTN_MOK) {
  761. PicoIn.sndOut = NULL; // just in case
  762. PicoIn.skipFrame = 1;
  763. PicoFrame();
  764. PicoIn.skipFrame = 0;
  765. while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
  766. }
  767. break;
  768. case 3:
  769. if (inp & PBTN_DOWN) spr_offs++;
  770. if (inp & PBTN_UP) spr_offs--;
  771. if (spr_offs < 0) spr_offs = 0;
  772. break;
  773. }
  774. }
  775. }
  776. // ------------ main menu ------------
  777. static void draw_frame_credits(void)
  778. {
  779. smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xe7fc);
  780. }
  781. static const char credits[] =
  782. "PicoDrive v" VERSION " (c) notaz, 2006-2013\n\n\n"
  783. "Credits:\n"
  784. "fDave: initial code\n"
  785. #ifdef EMU_C68K
  786. " Cyclone 68000 core\n"
  787. #else
  788. "Stef, Chui: FAME/C 68k core\n"
  789. #endif
  790. #ifdef _USE_DRZ80
  791. "Reesy & FluBBa: DrZ80 core\n"
  792. #else
  793. "Stef, NJ: CZ80 core\n"
  794. #endif
  795. "MAME devs: SH2, YM2612 and SN76496 cores\n"
  796. "Eke, Stef: some Sega CD code\n"
  797. "Inder, ketchupgun: graphics\n"
  798. "Irixxxx: SH2 drc improvements\n"
  799. #ifdef __GP2X__
  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. " Eke, 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_ppitch + 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_ppitch * bat_h] = menu_text_color;
  839. for (i = 0; i <= bat_h; i++)
  840. bp[i * g_screen_ppitch] =
  841. bp[i * g_screen_ppitch + me_mfont_w * 2] = menu_text_color;
  842. for (i = 2; i < bat_h - 1; i++)
  843. bp[i * g_screen_ppitch - 1] =
  844. bp[i * g_screen_ppitch - 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_ppitch * 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_CHANGE_CD:
  886. if (PicoIn.AHW & PAHW_MCD) {
  887. // if cd is loaded, cdd_unload() triggers eject and
  888. // returns 1, else we'll select and load new CD here
  889. if (!cdd_unload())
  890. menu_loop_tray();
  891. return 1;
  892. }
  893. break;
  894. case MA_MAIN_CREDITS:
  895. draw_menu_message(credits, draw_frame_credits);
  896. in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
  897. break;
  898. case MA_MAIN_EXIT:
  899. engineState = PGS_Quit;
  900. return 1;
  901. case MA_MAIN_PATCHES:
  902. if (PicoGameLoaded && PicoPatches) {
  903. menu_loop_patches();
  904. PicoPatchApply();
  905. menu_update_msg("Patches applied");
  906. }
  907. break;
  908. default:
  909. lprintf("%s: something unknown selected\n", __FUNCTION__);
  910. break;
  911. }
  912. return 0;
  913. }
  914. static menu_entry e_menu_main[] =
  915. {
  916. mee_label ("PicoDrive " VERSION),
  917. mee_label (""),
  918. mee_label (""),
  919. mee_label (""),
  920. mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
  921. mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
  922. mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
  923. mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
  924. mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
  925. mee_handler_id("Change CD/ISO", MA_MAIN_CHANGE_CD, main_menu_handler),
  926. mee_handler ("Change options", menu_loop_options),
  927. mee_handler ("Configure controls", menu_loop_keyconfig),
  928. mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
  929. mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
  930. mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
  931. mee_end,
  932. };
  933. void menu_loop(void)
  934. {
  935. static int sel = 0;
  936. me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
  937. me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
  938. me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
  939. me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
  940. me_enable(e_menu_main, MA_MAIN_CHANGE_CD, PicoIn.AHW & PAHW_MCD);
  941. me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
  942. menu_enter(PicoGameLoaded);
  943. in_set_config_int(0, IN_CFG_BLOCKING, 1);
  944. me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
  945. if (PicoGameLoaded) {
  946. if (engineState == PGS_Menu)
  947. engineState = PGS_Running;
  948. /* wait until menu, ok, back is released */
  949. while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
  950. ;
  951. }
  952. in_set_config_int(0, IN_CFG_BLOCKING, 0);
  953. plat_video_menu_leave();
  954. }
  955. // --------- CD tray close menu ----------
  956. static int mh_tray_load_cd(int id, int keys)
  957. {
  958. const char *ret_name;
  959. rom_fname_reload = NULL;
  960. ret_name = menu_loop_romsel(rom_fname_loaded,
  961. sizeof(rom_fname_loaded), rom_exts, NULL);
  962. if (ret_name == NULL)
  963. return 0;
  964. rom_fname_reload = ret_name;
  965. engineState = PGS_RestartRun;
  966. return emu_swap_cd(ret_name);
  967. }
  968. static int mh_tray_nothing(int id, int keys)
  969. {
  970. return 1;
  971. }
  972. static menu_entry e_menu_tray[] =
  973. {
  974. mee_label ("The CD tray has opened."),
  975. mee_label (""),
  976. mee_label (""),
  977. mee_handler("Load CD image", mh_tray_load_cd),
  978. mee_handler("Insert nothing", mh_tray_nothing),
  979. mee_end,
  980. };
  981. int menu_loop_tray(void)
  982. {
  983. int ret = 1, sel = 0;
  984. menu_enter(PicoGameLoaded);
  985. in_set_config_int(0, IN_CFG_BLOCKING, 1);
  986. me_loop(e_menu_tray, &sel);
  987. if (engineState != PGS_RestartRun) {
  988. engineState = PGS_RestartRun;
  989. ret = 0; /* no CD inserted */
  990. }
  991. while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
  992. ;
  993. in_set_config_int(0, IN_CFG_BLOCKING, 0);
  994. plat_video_menu_leave();
  995. return ret;
  996. }
  997. void menu_update_msg(const char *msg)
  998. {
  999. strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
  1000. menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
  1001. menu_error_time = plat_get_ticks_ms();
  1002. lprintf("msg: %s\n", menu_error_msg);
  1003. }
  1004. // ------------ util ------------
  1005. /* hidden options for config engine only */
  1006. static menu_entry e_menu_hidden[] =
  1007. {
  1008. mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoIn.opt, 0x080),
  1009. mee_onoff("autoload savestates", MA_OPT_AUTOLOAD_SAVE, g_autostateld_opt, 1),
  1010. mee_end,
  1011. };
  1012. static menu_entry *e_menu_table[] =
  1013. {
  1014. e_menu_options,
  1015. e_menu_gfx_options,
  1016. e_menu_adv_options,
  1017. e_menu_cd_options,
  1018. #ifndef NO_32X
  1019. e_menu_32x_options,
  1020. #endif
  1021. e_menu_keyconfig,
  1022. e_menu_hidden,
  1023. };
  1024. static menu_entry *me_list_table = NULL;
  1025. static menu_entry *me_list_i = NULL;
  1026. menu_entry *me_list_get_first(void)
  1027. {
  1028. me_list_table = me_list_i = e_menu_table[0];
  1029. return me_list_i;
  1030. }
  1031. menu_entry *me_list_get_next(void)
  1032. {
  1033. int i;
  1034. me_list_i++;
  1035. if (me_list_i->name != NULL)
  1036. return me_list_i;
  1037. for (i = 0; i < array_size(e_menu_table); i++)
  1038. if (me_list_table == e_menu_table[i])
  1039. break;
  1040. if (i + 1 < array_size(e_menu_table))
  1041. me_list_table = me_list_i = e_menu_table[i + 1];
  1042. else
  1043. me_list_table = me_list_i = NULL;
  1044. return me_list_i;
  1045. }
  1046. void menu_init(void)
  1047. {
  1048. int i;
  1049. menu_init_base();
  1050. i = 0;
  1051. #if defined(_SVP_DRC) || defined(DRC_SH2)
  1052. i = 1;
  1053. #endif
  1054. me_enable(e_menu_adv_options, MA_OPT2_DYNARECS, i);
  1055. i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
  1056. e_menu_gfx_options[i].data = plat_target.vout_methods;
  1057. me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
  1058. plat_target.vout_methods != NULL);
  1059. i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
  1060. e_menu_gfx_options[i].data = plat_target.hwfilters;
  1061. me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
  1062. plat_target.hwfilters != NULL);
  1063. me_enable(e_menu_gfx_options, MA_OPT2_GAMMA,
  1064. plat_target.gamma_set != NULL);
  1065. i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
  1066. e_menu_options[i].enabled = 0;
  1067. if (plat_target.cpu_clock_set != NULL) {
  1068. e_menu_options[i].name = "CPU clock";
  1069. e_menu_options[i].enabled = 1;
  1070. }
  1071. }