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;
79 if (!no_scale && g_menuscreen_w / w >= 2 && g_menuscreen_h / h >= 2)
81 unsigned int t, *d = g_menubg_ptr;
82 d += (g_menuscreen_h / 2 - h * 2 / 2)
84 d += (g_menuscreen_w / 2 - w * 2 / 2) / 2;
85 for (y = 0; y < h; y++, src += w, d += g_menuscreen_w*2/2) {
86 for (x = 0; x < w; x++) {
88 t = ((t & 0xf79e)>>1) - ((t & 0xc618)>>3);
90 d[x] = d[x + g_menuscreen_w / 2] = t;
96 if (w > g_menuscreen_w)
98 if (h > g_menuscreen_h)
100 dst = (short *)g_menubg_ptr +
101 (g_menuscreen_h / 2 - h / 2) * g_menuscreen_w +
102 (g_menuscreen_w / 2 - w / 2);
104 // darken the active framebuffer
105 for (; h > 0; dst += g_menuscreen_w, src += g_screen_width, h--)
106 menu_darken_bg(dst, src, w, 1);
109 static void menu_enter(int is_rom_loaded)
119 // should really only happen once, on startup..
120 emu_make_path(buff, "skin/background.png", sizeof(buff));
121 if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0)
122 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
125 plat_video_menu_enter(is_rom_loaded);
128 static void draw_savestate_bg(int slot)
133 fname = emu_get_save_fname(1, 0, slot);
137 tmp_state = PicoTmpStateSave();
139 PicoStateLoadGfx(fname);
141 /* do a frame and fetch menu bg */
142 pemu_forced_frame(0, 0);
146 PicoTmpStateRestore(tmp_state);
149 // --------- loading ROM screen ----------
151 static int cdload_called = 0;
153 static void load_progress_cb(int percent)
155 int ln, len = percent * g_menuscreen_w / 100;
158 if (len > g_menuscreen_w)
159 len = g_menuscreen_w;
161 menu_draw_begin(0, 1);
162 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
163 for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
164 memset(dst, 0xff, len * 2);
168 static void cdload_progress_cb(const char *fname, int percent)
170 int ln, len = percent * g_menuscreen_w / 100;
173 menu_draw_begin(0, 1);
174 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
175 memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
177 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
178 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
179 dst += g_menuscreen_w * me_sfont_h * 3;
181 if (len > g_menuscreen_w)
182 len = g_menuscreen_w;
184 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)
185 memset(dst, 0xff, len * 2);
191 void menu_romload_prepare(const char *rom_name)
193 const char *p = rom_name + strlen(rom_name);
196 while (p > rom_name && *p != '/')
199 /* fill all buffers, callbacks won't update in full */
200 for (i = 0; i < 3; i++) {
201 menu_draw_begin(1, 1);
202 smalltext_out16(1, 1, "Loading", 0xffff);
203 smalltext_out16(1, me_sfont_h, p, 0xffff);
207 PicoCartLoadProgressCB = load_progress_cb;
208 PicoCDLoadProgressCB = cdload_progress_cb;
212 void menu_romload_end(void)
214 PicoCartLoadProgressCB = NULL;
215 PicoCDLoadProgressCB = NULL;
217 menu_draw_begin(0, 1);
218 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
219 "Starting emulation...", 0xffff);
223 // ------------ patch/gg menu ------------
225 static void draw_patchlist(int sel)
227 int max_cnt, start, i, pos, active;
229 max_cnt = g_menuscreen_h / me_sfont_h;
230 start = max_cnt / 2 - sel;
232 menu_draw_begin(1, 0);
234 for (i = 0; i < PicoPatchCount; i++) {
236 if (pos < 0) continue;
237 if (pos >= max_cnt) break;
238 active = PicoPatches[i].active;
239 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
240 smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
244 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
246 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
250 static void menu_loop_patches(void)
252 static int menu_sel = 0;
257 draw_patchlist(menu_sel);
258 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
259 |PBTN_MOK|PBTN_MBACK, NULL, 33);
260 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
261 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
262 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
263 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
264 if (inp & PBTN_MOK) { // action
265 if (menu_sel < PicoPatchCount)
266 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
269 if (inp & PBTN_MBACK)
274 // -------------- key config --------------
276 // PicoPad[] format: MXYZ SACB RLDU
277 me_bind_action me_ctrl_actions[] =
282 { "RIGHT ", 0x0008 },
286 { "A turbo", 0x4000 },
287 { "B turbo", 0x1000 },
288 { "C turbo", 0x2000 },
289 { "START ", 0x0080 },
297 me_bind_action emuctrl_actions[] =
299 { "Load State ", PEV_STATE_LOAD },
300 { "Save State ", PEV_STATE_SAVE },
301 { "Prev Save Slot ", PEV_SSLOT_PREV },
302 { "Next Save Slot ", PEV_SSLOT_NEXT },
303 { "Switch Renderer ", PEV_SWITCH_RND },
304 { "Volume Down ", PEV_VOL_DOWN },
305 { "Volume Up ", PEV_VOL_UP },
306 { "Fast forward ", PEV_FF },
307 { "Enter Menu ", PEV_MENU },
308 { "Pico Next page ", PEV_PICO_PNEXT },
309 { "Pico Prev page ", PEV_PICO_PPREV },
310 { "Pico Switch input", PEV_PICO_SWINP },
314 static int key_config_loop_wrap(int id, int keys)
317 case MA_CTRL_PLAYER1:
318 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
320 case MA_CTRL_PLAYER2:
321 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
324 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
332 static const char *mgn_dev_name(int id, int *offs)
334 const char *name = NULL;
337 if (id == MA_CTRL_DEV_FIRST)
340 for (; it < IN_MAX_DEVS; it++) {
341 name = in_get_dev_name(it, 1, 1);
350 static int mh_saveloadcfg(int id, int keys);
351 static const char *mgn_saveloadcfg(int id, int *offs);
353 static menu_entry e_menu_keyconfig[] =
355 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
356 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
357 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
358 mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),
359 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
360 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
361 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
362 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
364 mee_label ("Input devices:"),
365 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
366 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
367 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
368 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
369 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
370 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
371 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
375 static int menu_loop_keyconfig(int id, int keys)
379 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
380 me_loop(e_menu_keyconfig, &sel);
384 // ------------ SCD options menu ------------
386 static const char *mgn_cdopt_ra(int id, int *offs)
389 if (PicoCDBuffers <= 0)
391 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
395 static int mh_cdopt_ra(int id, int keys)
397 if (keys & PBTN_LEFT) {
399 if (PicoCDBuffers < 2)
402 if (PicoCDBuffers <= 0)
405 if (PicoCDBuffers > 8*1024)
406 PicoCDBuffers = 8*1024; // 16M
411 static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
412 static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
413 static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
414 static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
415 "most games don't need this";
416 static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
417 "disable to improve performance";
418 static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
419 "disable to improve performance";
421 static menu_entry e_menu_cd_options[] =
423 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
424 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
425 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
426 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
427 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
428 mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
429 mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync),
433 static int menu_loop_cd_options(int id, int keys)
436 me_loop(e_menu_cd_options, &sel);
440 // ------------ 32X options menu ------------
444 // convert from multiplier of VClk
445 static int mh_opt_sh2cycles(int id, int keys)
447 int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier;
449 if (keys & (PBTN_LEFT|PBTN_RIGHT))
450 *mul += (keys & PBTN_LEFT) ? -10 : 10;
451 if (keys & (PBTN_L|PBTN_R))
452 *mul += (keys & PBTN_L) ? -100 : 100;
456 else if (*mul > (10 << SH2_MULTI_SHIFT))
457 *mul = 10 << SH2_MULTI_SHIFT;
462 static const char *mgn_opt_sh2cycles(int id, int *offs)
464 int mul = (id == MA_32XOPT_MSH2_CYCLES) ? p32x_msh2_multiplier : p32x_ssh2_multiplier;
466 sprintf(static_buff, "%d", 7670 * mul >> SH2_MULTI_SHIFT);
470 static const char h_32x_enable[] = "Enable emulation of the 32X addon";
471 static const char h_pwm[] = "Disabling may improve performance, but break sound";
472 static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
473 "lower values speed up emulation but break games\n"
474 "at least 11000 recommended for compatibility";
476 static menu_entry e_menu_32x_options[] =
478 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
479 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
480 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
481 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
482 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
486 static int menu_loop_32x_options(int id, int keys)
490 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
491 me_loop(e_menu_32x_options, &sel);
498 // ------------ adv options menu ------------
500 static menu_entry e_menu_adv_options[] =
502 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
503 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
504 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
505 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
506 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
507 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
508 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
509 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
510 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
515 static int menu_loop_adv_options(int id, int keys)
518 me_loop(e_menu_adv_options, &sel);
522 // ------------ gfx options menu ------------
524 static const char h_gamma[] = "Gamma/brightness adjustment (default 100)";
526 static menu_entry e_menu_gfx_options[] =
528 mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
529 mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
530 mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
531 mee_range_h("Gamma adjustment", MA_OPT3_GAMMA, currentConfig.gamma, 1, 200, h_gamma),
536 static int menu_loop_gfx_options(int id, int keys)
540 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
541 me_loop(e_menu_gfx_options, &sel);
546 // ------------ options menu ------------
548 static menu_entry e_menu_options[];
550 static int sndrate_prevnext(int rate, int dir)
552 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
555 for (i = 0; i < 5; i++)
556 if (rates[i] == rate) break;
560 if (!(PicoOpt & POPT_EN_STEREO)) {
561 PicoOpt |= POPT_EN_STEREO;
567 if (PicoOpt & POPT_EN_STEREO) {
568 PicoOpt &= ~POPT_EN_STEREO;
576 static void region_prevnext(int right)
578 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
579 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
583 if (!PicoRegionOverride) {
584 for (i = 0; i < 6; i++)
585 if (rgn_orders[i] == PicoAutoRgnOrder) break;
586 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
587 else PicoRegionOverride=1;
590 PicoRegionOverride <<= 1;
591 if (PicoRegionOverride > 8)
592 PicoRegionOverride = 8;
594 if (!PicoRegionOverride) {
595 for (i = 0; i < 6; i++)
596 if (rgn_orders[i] == PicoAutoRgnOrder) break;
597 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
600 PicoRegionOverride >>= 1;
604 static int mh_opt_misc(int id, int keys)
607 case MA_OPT_SOUND_QUALITY:
608 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
611 region_prevnext(keys & PBTN_RIGHT);
619 static int mh_saveloadcfg(int id, int keys)
623 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
624 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
625 if (config_slot < 0) config_slot = 9;
626 else if (config_slot > 9) config_slot = 0;
627 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
633 case MA_OPT_SAVECFG_GAME:
634 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
635 menu_update_msg("config saved");
637 menu_update_msg("failed to write config");
640 ret = emu_read_config(rom_fname_loaded, 1);
641 if (!ret) ret = emu_read_config(NULL, 1);
642 if (ret) menu_update_msg("config loaded");
643 else menu_update_msg("failed to load config");
652 static int mh_restore_defaults(int id, int keys)
655 menu_update_msg("defaults restored");
659 static const char *mgn_opt_fskip(int id, int *offs)
661 if (currentConfig.Frameskip < 0)
663 sprintf(static_buff, "%d", currentConfig.Frameskip);
667 static const char *mgn_opt_sound(int id, int *offs)
671 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
672 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
676 static const char *mgn_opt_region(int id, int *offs)
678 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
679 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
680 int code = PicoRegionOverride;
686 while ((code >>= 1)) i++;
691 strcpy(static_buff, "Auto:");
692 for (u = 0; u < 3; u++) {
693 code = (PicoAutoRgnOrder >> u*4) & 0xf;
694 for (i = 0; code; code >>= 1, i++)
696 strcat(static_buff, names_short[i]);
702 static const char *mgn_saveloadcfg(int id, int *offs)
705 if (config_slot != 0)
706 sprintf(static_buff, "[%i]", config_slot);
710 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
711 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
712 "loading state or both";
714 static menu_entry e_menu_options[] =
716 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
717 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
718 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
719 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
720 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
721 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
722 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
723 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 1200),
724 mee_handler ("[Display options]", menu_loop_gfx_options),
725 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
727 mee_handler ("[32X options]", menu_loop_32x_options),
729 mee_handler ("[Advanced options]", menu_loop_adv_options),
730 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
731 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
732 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
733 mee_handler ("Restore defaults", mh_restore_defaults),
737 static int menu_loop_options(int id, int keys)
742 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
743 e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;
744 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
745 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
747 me_loop(e_menu_options, &sel);
752 // ------------ debug menu ------------
754 #include <pico/debug.h>
756 extern void SekStepM68k(void);
758 static void mplayer_loop(void)
765 if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
773 static void draw_text_debug(const char *str, int skip, int from)
781 while (*p && *p != '\n')
783 if (*p == 0 || p[1] == 0)
789 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
791 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
792 while (*p && *p != '\n')
801 #define COMPILER "gcc " __VERSION__
806 static void draw_frame_debug(void)
808 char layer_str[48] = "layers: ";
809 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
810 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
811 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
812 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
813 if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4);
815 pemu_forced_frame(1, 0);
818 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
819 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
822 static void debug_menu_loop(void)
825 int spr_offs = 0, dumped = 0;
830 menu_draw_begin(1, 0);
833 case 0: tmp = PDebugMain();
835 draw_text_debug(tmp, 0, 0);
837 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
838 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
842 case 1: draw_frame_debug();
844 case 2: pemu_forced_frame(1, 0);
846 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
847 g_menuscreen_w/2 - 320/2, g_menuscreen_w);
849 case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
850 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
851 PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
852 g_menuscreen_w, spr_offs);
853 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
855 case 4: tmp = PDebug32x();
856 draw_text_debug(tmp, 0, 0);
861 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
862 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
863 if (inp & PBTN_MBACK) return;
864 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
865 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
871 if (inp & PBTN_MA3) {
872 while (inp & PBTN_MA3)
873 inp = in_menu_wait_any(NULL, -1);
876 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
877 mkdir("dumps", 0777);
879 while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
884 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
885 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
886 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
887 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
888 if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON;
889 if (inp & PBTN_MOK) {
890 PsndOut = NULL; // just in case
894 while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
898 if (inp & PBTN_DOWN) spr_offs++;
899 if (inp & PBTN_UP) spr_offs--;
900 if (spr_offs < 0) spr_offs = 0;
906 // ------------ main menu ------------
908 static const char credits[] =
909 "PicoDrive v" VERSION " (c) notaz, 2006-2011\n\n\n"
911 "fDave: Cyclone 68000 core,\n"
912 " base code of PicoDrive\n"
913 "Reesy & FluBBa: DrZ80 core\n"
914 "MAME devs: YM2612 and SN76496 cores\n"
915 "Inder, ketchupgun: graphics\n"
917 "rlyeh and others: minimal SDK\n"
919 "Dzz: ARM940 sample\n"
922 "special thanks (for docs, ideas):\n"
923 " Charles MacDonald, Haze,\n"
924 " Stephane Dallongeville,\n"
925 " Lordus, Exophase, Rokas,\n"
926 " Nemesis, Tasco Deluxe";
928 static int main_menu_handler(int id, int keys)
930 const char *ret_name;
934 case MA_MAIN_RESUME_GAME:
938 case MA_MAIN_SAVE_STATE:
940 return menu_loop_savestate(0);
942 case MA_MAIN_LOAD_STATE:
944 return menu_loop_savestate(1);
946 case MA_MAIN_RESET_GAME:
947 if (PicoGameLoaded) {
952 case MA_MAIN_LOAD_ROM:
953 rom_fname_reload = NULL;
954 ret_name = menu_loop_romsel(rom_fname_loaded,
955 sizeof(rom_fname_loaded), rom_exts, NULL);
956 if (ret_name != NULL) {
957 lprintf("selected file: %s\n", ret_name);
958 rom_fname_reload = ret_name;
959 engineState = PGS_ReloadRom;
963 case MA_MAIN_CREDITS:
964 draw_menu_message(credits, NULL);
965 in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
968 engineState = PGS_Quit;
970 case MA_MAIN_PATCHES:
971 if (PicoGameLoaded && PicoPatches) {
974 menu_update_msg("Patches applied");
978 lprintf("%s: something unknown selected\n", __FUNCTION__);
985 static menu_entry e_menu_main[] =
987 mee_label ("PicoDrive " VERSION),
991 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
992 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
993 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
994 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
995 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
996 mee_handler ("Change options", menu_loop_options),
997 mee_handler ("Configure controls", menu_loop_keyconfig),
998 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
999 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
1000 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
1004 void menu_loop(void)
1008 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
1009 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
1010 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
1011 me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
1012 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
1014 menu_enter(PicoGameLoaded);
1015 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1016 me_loop_d(e_menu_main, &sel, NULL, menu_main_plat_draw);
1018 if (PicoGameLoaded) {
1019 if (engineState == PGS_Menu)
1020 engineState = PGS_Running;
1021 /* wait until menu, ok, back is released */
1022 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1026 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1027 plat_video_menu_leave();
1030 // --------- CD tray close menu ----------
1032 static int mh_tray_load_cd(int id, int keys)
1034 const char *ret_name;
1036 rom_fname_reload = NULL;
1037 ret_name = menu_loop_romsel(rom_fname_loaded,
1038 sizeof(rom_fname_loaded), rom_exts, NULL);
1039 if (ret_name == NULL)
1042 rom_fname_reload = ret_name;
1043 engineState = PGS_RestartRun;
1044 return emu_swap_cd(ret_name);
1047 static int mh_tray_nothing(int id, int keys)
1052 static menu_entry e_menu_tray[] =
1054 mee_label ("The CD tray has opened."),
1057 mee_handler("Load CD image", mh_tray_load_cd),
1058 mee_handler("Insert nothing", mh_tray_nothing),
1062 int menu_loop_tray(void)
1064 int ret = 1, sel = 0;
1066 menu_enter(PicoGameLoaded);
1068 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1069 me_loop(e_menu_tray, &sel);
1071 if (engineState != PGS_RestartRun) {
1072 engineState = PGS_RestartRun;
1073 ret = 0; /* no CD inserted */
1076 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
1077 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1078 plat_video_menu_leave();
1083 void menu_update_msg(const char *msg)
1085 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1086 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1088 menu_error_time = plat_get_ticks_ms();
1089 lprintf("msg: %s\n", menu_error_msg);
1092 // ------------ util ------------
1094 /* hidden options for config engine only */
1095 static menu_entry e_menu_hidden[] =
1097 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
1101 static menu_entry *e_menu_table[] =
1114 static menu_entry *me_list_table = NULL;
1115 static menu_entry *me_list_i = NULL;
1117 menu_entry *me_list_get_first(void)
1119 me_list_table = me_list_i = e_menu_table[0];
1123 menu_entry *me_list_get_next(void)
1128 if (me_list_i->name != NULL)
1131 for (i = 0; i < array_size(e_menu_table); i++)
1132 if (me_list_table == e_menu_table[i])
1135 if (i + 1 < array_size(e_menu_table))
1136 me_list_table = me_list_i = e_menu_table[i + 1];
1138 me_list_table = me_list_i = NULL;
1143 void menu_init(void)
1149 i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
1150 e_menu_gfx_options[i].data = plat_target.vout_methods;
1151 me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
1152 plat_target.vout_methods != NULL);
1154 i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
1155 e_menu_gfx_options[i].data = plat_target.hwfilters;
1156 me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
1157 plat_target.hwfilters != NULL);
1159 me_enable(e_menu_gfx_options, MA_OPT3_GAMMA,
1160 plat_target.gamma_set != NULL);