5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
12 #include "menu_pico.h"
13 #include "input_pico.h"
16 #include <pico/pico.h>
17 #include <pico/patch.h>
28 static const char *rom_exts[] = {
30 "bin", "smd", "gen", "md",
37 // rrrr rggg gggb bbbb
38 static unsigned short fname2color(const char *fname)
40 static const char *other_exts[] = { "gmv", "pat" };
44 ext = strrchr(fname, '.');
46 ext = fname + strlen(fname) - 3;
47 if (ext < fname) ext = fname;
50 for (i = 0; rom_exts[i] != NULL; i++)
51 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
52 for (i = 0; i < array_size(other_exts); i++)
53 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
57 #include "../libpicofe/menu.c"
59 static const char *men_dummy[] = { NULL };
61 /* platform specific options and handlers */
63 #include "../gp2x/menu.c"
64 #elif defined(PANDORA)
65 #include "../pandora/menu.c"
67 #define MENU_OPTIONS_GFX
68 #define MENU_OPTIONS_ADV
69 #define menu_main_plat_draw NULL
72 static void make_bg(int no_scale)
74 unsigned short *src = (void *)g_menubg_src_ptr;
75 int w = g_screen_width, h = g_screen_height;
80 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
84 if (!no_scale && g_menuscreen_w / w >= 2 && g_menuscreen_h / h >= 2)
86 unsigned int t, *d = g_menubg_ptr;
87 d += (g_menuscreen_h / 2 - h * 2 / 2)
89 d += (g_menuscreen_w / 2 - w * 2 / 2) / 2;
90 for (y = 0; y < h; y++, src += w, d += g_menuscreen_w*2/2) {
91 for (x = 0; x < w; x++) {
93 t = ((t & 0xf79e)>>1) - ((t & 0xc618)>>3);
95 d[x] = d[x + g_menuscreen_w / 2] = t;
101 if (w > g_menuscreen_w)
103 if (h > g_menuscreen_h)
105 dst = (short *)g_menubg_ptr +
106 (g_menuscreen_h / 2 - h / 2) * g_menuscreen_w +
107 (g_menuscreen_w / 2 - w / 2);
109 // darken the active framebuffer
110 for (; h > 0; dst += g_menuscreen_w, src += g_screen_width, h--)
111 menu_darken_bg(dst, src, w, 1);
114 static void menu_enter(int is_rom_loaded)
124 // should really only happen once, on startup..
125 emu_make_path(buff, "skin/background.png", sizeof(buff));
126 if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0)
127 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
130 plat_video_menu_enter(is_rom_loaded);
133 static void draw_savestate_bg(int slot)
138 fname = emu_get_save_fname(1, 0, slot);
142 tmp_state = PicoTmpStateSave();
144 PicoStateLoadGfx(fname);
146 /* do a frame and fetch menu bg */
147 pemu_forced_frame(0, 0);
151 PicoTmpStateRestore(tmp_state);
154 // --------- loading ROM screen ----------
156 static int cdload_called = 0;
158 static void load_progress_cb(int percent)
160 int ln, len = percent * g_menuscreen_w / 100;
163 if (len > g_menuscreen_w)
164 len = g_menuscreen_w;
166 menu_draw_begin(0, 1);
167 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
168 for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
169 memset(dst, 0xff, len * 2);
173 static void cdload_progress_cb(const char *fname, int percent)
175 int ln, len = percent * g_menuscreen_w / 100;
178 menu_draw_begin(0, 1);
179 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
180 memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
182 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
183 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
184 dst += g_menuscreen_w * me_sfont_h * 3;
186 if (len > g_menuscreen_w)
187 len = g_menuscreen_w;
189 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)
190 memset(dst, 0xff, len * 2);
196 void menu_romload_prepare(const char *rom_name)
198 const char *p = rom_name + strlen(rom_name);
201 while (p > rom_name && *p != '/')
204 /* fill all buffers, callbacks won't update in full */
205 for (i = 0; i < 3; i++) {
206 menu_draw_begin(1, 1);
207 smalltext_out16(1, 1, "Loading", 0xffff);
208 smalltext_out16(1, me_sfont_h, p, 0xffff);
212 PicoCartLoadProgressCB = load_progress_cb;
213 PicoCDLoadProgressCB = cdload_progress_cb;
217 void menu_romload_end(void)
219 PicoCartLoadProgressCB = NULL;
220 PicoCDLoadProgressCB = NULL;
222 menu_draw_begin(0, 1);
223 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
224 "Starting emulation...", 0xffff);
228 // ------------ patch/gg menu ------------
230 static void draw_patchlist(int sel)
232 int max_cnt, start, i, pos, active;
234 max_cnt = g_menuscreen_h / me_sfont_h;
235 start = max_cnt / 2 - sel;
237 menu_draw_begin(1, 0);
239 for (i = 0; i < PicoPatchCount; i++) {
241 if (pos < 0) continue;
242 if (pos >= max_cnt) break;
243 active = PicoPatches[i].active;
244 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
245 smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
249 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
251 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
255 static void menu_loop_patches(void)
257 static int menu_sel = 0;
262 draw_patchlist(menu_sel);
263 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
264 |PBTN_MOK|PBTN_MBACK, NULL, 33);
265 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
266 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
267 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
268 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
269 if (inp & PBTN_MOK) { // action
270 if (menu_sel < PicoPatchCount)
271 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
274 if (inp & PBTN_MBACK)
279 // -------------- key config --------------
281 // PicoPad[] format: MXYZ SACB RLDU
282 me_bind_action me_ctrl_actions[] =
287 { "RIGHT ", 0x0008 },
291 { "A turbo", 0x4000 },
292 { "B turbo", 0x1000 },
293 { "C turbo", 0x2000 },
294 { "START ", 0x0080 },
302 me_bind_action emuctrl_actions[] =
304 { "Load State ", PEV_STATE_LOAD },
305 { "Save State ", PEV_STATE_SAVE },
306 { "Prev Save Slot ", PEV_SSLOT_PREV },
307 { "Next Save Slot ", PEV_SSLOT_NEXT },
308 { "Switch Renderer ", PEV_SWITCH_RND },
309 { "Volume Down ", PEV_VOL_DOWN },
310 { "Volume Up ", PEV_VOL_UP },
311 { "Fast forward ", PEV_FF },
312 { "Enter Menu ", PEV_MENU },
313 { "Pico Next page ", PEV_PICO_PNEXT },
314 { "Pico Prev page ", PEV_PICO_PPREV },
315 { "Pico Switch input", PEV_PICO_SWINP },
319 static int key_config_loop_wrap(int id, int keys)
322 case MA_CTRL_PLAYER1:
323 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
325 case MA_CTRL_PLAYER2:
326 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
329 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
337 static const char *mgn_dev_name(int id, int *offs)
339 const char *name = NULL;
342 if (id == MA_CTRL_DEV_FIRST)
345 for (; it < IN_MAX_DEVS; it++) {
346 name = in_get_dev_name(it, 1, 1);
355 static int mh_saveloadcfg(int id, int keys);
356 static const char *mgn_saveloadcfg(int id, int *offs);
358 const char *indev_names[] = { "none", "3 button pad", "6 button pad", NULL };
360 static menu_entry e_menu_keyconfig[] =
362 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
363 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
364 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
365 mee_enum ("Input device 1", MA_OPT_INPUT_DEV0, currentConfig.input_dev0, indev_names),
366 mee_enum ("Input device 2", MA_OPT_INPUT_DEV1, currentConfig.input_dev1, indev_names),
367 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
368 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
369 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
370 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
372 mee_label ("Input devices:"),
373 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
374 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
375 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
376 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
377 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
378 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
379 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
383 static int menu_loop_keyconfig(int id, int keys)
387 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
388 me_loop(e_menu_keyconfig, &sel);
390 PicoSetInputDevice(0, currentConfig.input_dev0);
391 PicoSetInputDevice(1, currentConfig.input_dev1);
396 // ------------ SCD options menu ------------
398 static const char *mgn_cdopt_ra(int id, int *offs)
401 if (PicoCDBuffers <= 0)
403 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
407 static int mh_cdopt_ra(int id, int keys)
409 if (keys & PBTN_LEFT) {
411 if (PicoCDBuffers < 2)
414 if (PicoCDBuffers <= 0)
417 if (PicoCDBuffers > 8*1024)
418 PicoCDBuffers = 8*1024; // 16M
423 static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
424 static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
425 static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
426 static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
427 "most games don't need this";
428 static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
429 "disable to improve performance";
430 static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
431 "disable to improve performance";
433 static menu_entry e_menu_cd_options[] =
435 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
436 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
437 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
438 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
439 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
440 mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
441 mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync),
445 static int menu_loop_cd_options(int id, int keys)
448 me_loop(e_menu_cd_options, &sel);
452 // ------------ 32X options menu ------------
456 // convert from multiplier of VClk
457 static int mh_opt_sh2cycles(int id, int keys)
459 int *khz = (id == MA_32XOPT_MSH2_CYCLES) ?
460 ¤tConfig.msh2_khz : ¤tConfig.ssh2_khz;
462 if (keys & (PBTN_LEFT|PBTN_RIGHT))
463 *khz += (keys & PBTN_LEFT) ? -50 : 50;
464 if (keys & (PBTN_L|PBTN_R))
465 *khz += (keys & PBTN_L) ? -500 : 500;
469 else if (*khz > 0x7fffffff / 1000)
470 *khz = 0x7fffffff / 1000;
475 static const char *mgn_opt_sh2cycles(int id, int *offs)
477 int khz = (id == MA_32XOPT_MSH2_CYCLES) ?
478 currentConfig.msh2_khz : currentConfig.ssh2_khz;
480 sprintf(static_buff, "%d", khz);
484 static const char h_32x_enable[] = "Enable emulation of the 32X addon";
485 static const char h_pwm[] = "Disabling may improve performance, but break sound";
486 static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
487 "lower values speed up emulation but break games\n"
488 "at least 11000 recommended for compatibility";
490 static menu_entry e_menu_32x_options[] =
492 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
493 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
494 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
495 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
496 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
500 static int menu_loop_32x_options(int id, int keys)
504 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
505 me_loop(e_menu_32x_options, &sel);
507 Pico32xSetClocks(currentConfig.msh2_khz * 1000, currentConfig.msh2_khz * 1000);
514 // ------------ adv options menu ------------
516 static menu_entry e_menu_adv_options[] =
518 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
519 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
520 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
521 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
522 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
523 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
524 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
525 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
526 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
531 static int menu_loop_adv_options(int id, int keys)
534 me_loop(e_menu_adv_options, &sel);
538 // ------------ gfx options menu ------------
540 static const char h_gamma[] = "Gamma/brightness adjustment (default 100)";
542 static menu_entry e_menu_gfx_options[] =
544 mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
545 mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
546 mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
547 mee_range_h("Gamma adjustment", MA_OPT3_GAMMA, currentConfig.gamma, 1, 200, h_gamma),
552 static int menu_loop_gfx_options(int id, int keys)
556 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
557 me_loop(e_menu_gfx_options, &sel);
562 // ------------ options menu ------------
564 static menu_entry e_menu_options[];
566 static int sndrate_prevnext(int rate, int dir)
568 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
571 for (i = 0; i < 5; i++)
572 if (rates[i] == rate) break;
576 if (!(PicoOpt & POPT_EN_STEREO)) {
577 PicoOpt |= POPT_EN_STEREO;
583 if (PicoOpt & POPT_EN_STEREO) {
584 PicoOpt &= ~POPT_EN_STEREO;
592 static void region_prevnext(int right)
594 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
595 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
599 if (!PicoRegionOverride) {
600 for (i = 0; i < 6; i++)
601 if (rgn_orders[i] == PicoAutoRgnOrder) break;
602 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
603 else PicoRegionOverride=1;
606 PicoRegionOverride <<= 1;
607 if (PicoRegionOverride > 8)
608 PicoRegionOverride = 8;
610 if (!PicoRegionOverride) {
611 for (i = 0; i < 6; i++)
612 if (rgn_orders[i] == PicoAutoRgnOrder) break;
613 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
616 PicoRegionOverride >>= 1;
620 static int mh_opt_misc(int id, int keys)
623 case MA_OPT_SOUND_QUALITY:
624 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
627 region_prevnext(keys & PBTN_RIGHT);
635 static int mh_saveloadcfg(int id, int keys)
639 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
640 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
641 if (config_slot < 0) config_slot = 9;
642 else if (config_slot > 9) config_slot = 0;
643 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
649 case MA_OPT_SAVECFG_GAME:
650 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
651 menu_update_msg("config saved");
653 menu_update_msg("failed to write config");
656 ret = emu_read_config(rom_fname_loaded, 1);
657 if (!ret) ret = emu_read_config(NULL, 1);
658 if (ret) menu_update_msg("config loaded");
659 else menu_update_msg("failed to load config");
668 static int mh_restore_defaults(int id, int keys)
671 menu_update_msg("defaults restored");
675 static const char *mgn_opt_fskip(int id, int *offs)
677 if (currentConfig.Frameskip < 0)
679 sprintf(static_buff, "%d", currentConfig.Frameskip);
683 static const char *mgn_opt_sound(int id, int *offs)
687 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
688 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
692 static const char *mgn_opt_region(int id, int *offs)
694 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
695 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
696 int code = PicoRegionOverride;
702 while ((code >>= 1)) i++;
707 strcpy(static_buff, "Auto:");
708 for (u = 0; u < 3; u++) {
709 code = (PicoAutoRgnOrder >> u*4) & 0xf;
710 for (i = 0; code; code >>= 1, i++)
712 strcat(static_buff, names_short[i]);
718 static const char *mgn_saveloadcfg(int id, int *offs)
721 if (config_slot != 0)
722 sprintf(static_buff, "[%i]", config_slot);
726 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
727 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
728 "loading state or both";
730 static menu_entry e_menu_options[] =
732 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
733 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
734 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
735 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
736 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
737 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
738 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
739 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 1200),
740 mee_handler ("[Display options]", menu_loop_gfx_options),
741 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
743 mee_handler ("[32X options]", menu_loop_32x_options),
745 mee_handler ("[Advanced options]", menu_loop_adv_options),
746 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
747 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
748 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
749 mee_handler ("Restore defaults", mh_restore_defaults),
753 static int menu_loop_options(int id, int keys)
758 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
759 e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;
760 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
761 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
763 me_loop(e_menu_options, &sel);
768 // ------------ debug menu ------------
770 #include <pico/debug.h>
772 extern void SekStepM68k(void);
774 static void mplayer_loop(void)
781 if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
789 static void draw_text_debug(const char *str, int skip, int from)
797 while (*p && *p != '\n')
799 if (*p == 0 || p[1] == 0)
805 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
807 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
808 while (*p && *p != '\n')
817 #define COMPILER "gcc " __VERSION__
822 static void draw_frame_debug(void)
824 char layer_str[48] = "layers: ";
825 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
826 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
827 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
828 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
829 if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4);
831 pemu_forced_frame(1, 0);
834 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
835 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
838 static void debug_menu_loop(void)
841 int spr_offs = 0, dumped = 0;
846 menu_draw_begin(1, 0);
849 case 0: tmp = PDebugMain();
851 draw_text_debug(tmp, 0, 0);
853 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
854 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
858 case 1: draw_frame_debug();
860 case 2: pemu_forced_frame(1, 0);
862 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
863 g_menuscreen_w/2 - 320/2, g_menuscreen_w);
865 case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
866 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
867 PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
868 g_menuscreen_w, spr_offs);
869 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
871 case 4: tmp = PDebug32x();
872 draw_text_debug(tmp, 0, 0);
877 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
878 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
879 if (inp & PBTN_MBACK) return;
880 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
881 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
887 if (inp & PBTN_MA3) {
888 while (inp & PBTN_MA3)
889 inp = in_menu_wait_any(NULL, -1);
892 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
893 mkdir("dumps", 0777);
895 while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
900 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
901 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
902 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
903 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
904 if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON;
905 if (inp & PBTN_MOK) {
906 PsndOut = NULL; // just in case
910 while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
914 if (inp & PBTN_DOWN) spr_offs++;
915 if (inp & PBTN_UP) spr_offs--;
916 if (spr_offs < 0) spr_offs = 0;
922 // ------------ main menu ------------
924 static const char credits[] =
925 "PicoDrive v" VERSION " (c) notaz, 2006-2011\n\n\n"
927 "fDave: Cyclone 68000 core,\n"
928 " base code of PicoDrive\n"
929 "Reesy & FluBBa: DrZ80 core\n"
930 "MAME devs: YM2612 and SN76496 cores\n"
931 "Inder, ketchupgun: graphics\n"
933 "rlyeh and others: minimal SDK\n"
935 "Dzz: ARM940 sample\n"
938 "special thanks (for docs, ideas):\n"
939 " Charles MacDonald, Haze,\n"
940 " Stephane Dallongeville,\n"
941 " Lordus, Exophase, Rokas,\n"
942 " Nemesis, Tasco Deluxe";
944 static int main_menu_handler(int id, int keys)
946 const char *ret_name;
950 case MA_MAIN_RESUME_GAME:
954 case MA_MAIN_SAVE_STATE:
956 return menu_loop_savestate(0);
958 case MA_MAIN_LOAD_STATE:
960 return menu_loop_savestate(1);
962 case MA_MAIN_RESET_GAME:
963 if (PicoGameLoaded) {
968 case MA_MAIN_LOAD_ROM:
969 rom_fname_reload = NULL;
970 ret_name = menu_loop_romsel(rom_fname_loaded,
971 sizeof(rom_fname_loaded), rom_exts, NULL);
972 if (ret_name != NULL) {
973 lprintf("selected file: %s\n", ret_name);
974 rom_fname_reload = ret_name;
975 engineState = PGS_ReloadRom;
979 case MA_MAIN_CREDITS:
980 draw_menu_message(credits, NULL);
981 in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
984 engineState = PGS_Quit;
986 case MA_MAIN_PATCHES:
987 if (PicoGameLoaded && PicoPatches) {
990 menu_update_msg("Patches applied");
994 lprintf("%s: something unknown selected\n", __FUNCTION__);
1001 static menu_entry e_menu_main[] =
1003 mee_label ("PicoDrive " VERSION),
1007 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
1008 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
1009 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
1010 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
1011 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
1012 mee_handler ("Change options", menu_loop_options),
1013 mee_handler ("Configure controls", menu_loop_keyconfig),
1014 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
1015 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
1016 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
1020 void menu_loop(void)
1024 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
1025 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
1026 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
1027 me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
1028 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
1030 menu_enter(PicoGameLoaded);
1031 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1032 me_loop_d(e_menu_main, &sel, NULL, menu_main_plat_draw);
1034 if (PicoGameLoaded) {
1035 if (engineState == PGS_Menu)
1036 engineState = PGS_Running;
1037 /* wait until menu, ok, back is released */
1038 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1042 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1043 plat_video_menu_leave();
1046 // --------- CD tray close menu ----------
1048 static int mh_tray_load_cd(int id, int keys)
1050 const char *ret_name;
1052 rom_fname_reload = NULL;
1053 ret_name = menu_loop_romsel(rom_fname_loaded,
1054 sizeof(rom_fname_loaded), rom_exts, NULL);
1055 if (ret_name == NULL)
1058 rom_fname_reload = ret_name;
1059 engineState = PGS_RestartRun;
1060 return emu_swap_cd(ret_name);
1063 static int mh_tray_nothing(int id, int keys)
1068 static menu_entry e_menu_tray[] =
1070 mee_label ("The CD tray has opened."),
1073 mee_handler("Load CD image", mh_tray_load_cd),
1074 mee_handler("Insert nothing", mh_tray_nothing),
1078 int menu_loop_tray(void)
1080 int ret = 1, sel = 0;
1082 menu_enter(PicoGameLoaded);
1084 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1085 me_loop(e_menu_tray, &sel);
1087 if (engineState != PGS_RestartRun) {
1088 engineState = PGS_RestartRun;
1089 ret = 0; /* no CD inserted */
1092 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1094 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1095 plat_video_menu_leave();
1100 void menu_update_msg(const char *msg)
1102 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1103 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1105 menu_error_time = plat_get_ticks_ms();
1106 lprintf("msg: %s\n", menu_error_msg);
1109 // ------------ util ------------
1111 /* hidden options for config engine only */
1112 static menu_entry e_menu_hidden[] =
1114 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
1118 static menu_entry *e_menu_table[] =
1131 static menu_entry *me_list_table = NULL;
1132 static menu_entry *me_list_i = NULL;
1134 menu_entry *me_list_get_first(void)
1136 me_list_table = me_list_i = e_menu_table[0];
1140 menu_entry *me_list_get_next(void)
1145 if (me_list_i->name != NULL)
1148 for (i = 0; i < array_size(e_menu_table); i++)
1149 if (me_list_table == e_menu_table[i])
1152 if (i + 1 < array_size(e_menu_table))
1153 me_list_table = me_list_i = e_menu_table[i + 1];
1155 me_list_table = me_list_i = NULL;
1160 void menu_init(void)
1166 i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
1167 e_menu_gfx_options[i].data = plat_target.vout_methods;
1168 me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
1169 plat_target.vout_methods != NULL);
1171 i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
1172 e_menu_gfx_options[i].data = plat_target.hwfilters;
1173 me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
1174 plat_target.hwfilters != NULL);
1176 me_enable(e_menu_gfx_options, MA_OPT3_GAMMA,
1177 plat_target.gamma_set != NULL);