menu_pico.c 34 KB

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