5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
13 #include "menu_pico.h"
14 #include "input_pico.h"
17 #include <pico/pico_int.h>
18 #include <pico/patch.h>
29 static const char *rom_exts[] = {
31 "bin", "smd", "gen", "md",
38 // rrrr rggg gggb bbbb
39 static unsigned short fname2color(const char *fname)
41 static const char *other_exts[] = { "gmv", "pat" };
45 ext = strrchr(fname, '.');
47 ext = fname + strlen(fname) - 3;
48 if (ext < fname) ext = fname;
51 for (i = 0; rom_exts[i] != NULL; i++)
52 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
53 for (i = 0; i < array_size(other_exts); i++)
54 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
58 #include "../libpicofe/menu.c"
60 static const char *men_dummy[] = { NULL };
62 /* platform specific options and handlers */
64 #include "../gp2x/menu.c"
65 #elif defined(PANDORA)
66 #include "../pandora/menu.c"
68 #define MENU_OPTIONS_GFX
69 #define MENU_OPTIONS_ADV
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_ppitch, h--)
111 menu_darken_bg(dst, src, w, 1);
114 static void menu_enter(int is_rom_loaded)
124 pos = plat_get_skin_dir(buff, 256);
125 strcpy(buff + pos, "background.png");
127 // should really only happen once, on startup..
128 if (readpng(g_menubg_ptr, buff, READPNG_BG,
129 g_menuscreen_w, g_menuscreen_h) < 0)
130 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
133 plat_video_menu_enter(is_rom_loaded);
136 static void draw_savestate_bg(int slot)
141 fname = emu_get_save_fname(1, 0, slot, NULL);
145 tmp_state = PicoTmpStateSave();
147 PicoStateLoadGfx(fname);
149 /* do a frame and fetch menu bg */
150 pemu_forced_frame(0, 0);
154 PicoTmpStateRestore(tmp_state);
157 // --------- loading ROM screen ----------
159 static int cdload_called = 0;
161 static void load_progress_cb(int percent)
163 int ln, len = percent * g_menuscreen_w / 100;
166 if (len > g_menuscreen_w)
167 len = g_menuscreen_w;
169 menu_draw_begin(0, 1);
170 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
171 for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_pp)
172 memset(dst, 0xff, len * 2);
176 static void cdload_progress_cb(const char *fname, int percent)
178 int ln, len = percent * g_menuscreen_w / 100;
181 menu_draw_begin(0, 1);
182 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
184 menuscreen_memset_lines(dst, 0xff, me_sfont_h - 2);
186 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
187 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
188 dst += g_menuscreen_pp * me_sfont_h * 3;
190 if (len > g_menuscreen_w)
191 len = g_menuscreen_w;
193 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_pp)
194 memset(dst, 0xff, len * 2);
200 void menu_romload_prepare(const char *rom_name)
202 const char *p = rom_name + strlen(rom_name);
205 while (p > rom_name && *p != '/')
208 /* fill all buffers, callbacks won't update in full */
209 for (i = 0; i < 3; i++) {
210 menu_draw_begin(1, 1);
211 smalltext_out16(1, 1, "Loading", 0xffff);
212 smalltext_out16(1, me_sfont_h, p, 0xffff);
216 PicoCartLoadProgressCB = load_progress_cb;
217 PicoCDLoadProgressCB = cdload_progress_cb;
221 void menu_romload_end(void)
223 PicoCartLoadProgressCB = NULL;
224 PicoCDLoadProgressCB = NULL;
226 menu_draw_begin(0, 1);
227 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
228 "Starting emulation...", 0xffff);
232 // ------------ patch/gg menu ------------
234 static void draw_patchlist(int sel)
236 int max_cnt, start, i, pos, active;
238 max_cnt = g_menuscreen_h / me_sfont_h;
239 start = max_cnt / 2 - sel;
241 menu_draw_begin(1, 0);
243 for (i = 0; i < PicoPatchCount; i++) {
245 if (pos < 0) continue;
246 if (pos >= max_cnt) break;
247 active = PicoPatches[i].active;
248 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
249 smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
253 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
255 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
259 static void menu_loop_patches(void)
261 static int menu_sel = 0;
266 draw_patchlist(menu_sel);
267 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
268 |PBTN_MOK|PBTN_MBACK, NULL, 33);
269 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
270 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
271 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
272 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
273 if (inp & PBTN_MOK) { // action
274 if (menu_sel < PicoPatchCount)
275 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
278 if (inp & PBTN_MBACK)
283 // -------------- key config --------------
285 // PicoIn.pad[] format: MXYZ SACB RLDU
286 me_bind_action me_ctrl_actions[] =
291 { "RIGHT ", 0x0008 },
295 { "A turbo", 0x4000 },
296 { "B turbo", 0x1000 },
297 { "C turbo", 0x2000 },
298 { "START ", 0x0080 },
306 me_bind_action emuctrl_actions[] =
308 { "Load State ", PEV_STATE_LOAD },
309 { "Save State ", PEV_STATE_SAVE },
310 { "Prev Save Slot ", PEV_SSLOT_PREV },
311 { "Next Save Slot ", PEV_SSLOT_NEXT },
312 { "Switch Renderer ", PEV_SWITCH_RND },
313 { "Volume Down ", PEV_VOL_DOWN },
314 { "Volume Up ", PEV_VOL_UP },
315 { "Fast forward ", PEV_FF },
316 { "Reset Game ", PEV_RESET },
317 { "Enter Menu ", PEV_MENU },
318 { "Pico Next page ", PEV_PICO_PNEXT },
319 { "Pico Prev page ", PEV_PICO_PPREV },
320 { "Pico Switch input", PEV_PICO_SWINP },
324 static int key_config_loop_wrap(int id, int keys)
327 case MA_CTRL_PLAYER1:
328 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
330 case MA_CTRL_PLAYER2:
331 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
334 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
342 static const char *mgn_dev_name(int id, int *offs)
344 const char *name = NULL;
347 if (id == MA_CTRL_DEV_FIRST)
350 for (; it < IN_MAX_DEVS; it++) {
351 name = in_get_dev_name(it, 1, 1);
360 static int mh_saveloadcfg(int id, int keys);
361 static const char *mgn_saveloadcfg(int id, int *offs);
363 const char *indev_names[] = { "none", "3 button pad", "6 button pad", NULL };
365 static menu_entry e_menu_keyconfig[] =
367 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
368 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
369 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
370 mee_enum ("Input device 1", MA_OPT_INPUT_DEV0, currentConfig.input_dev0, indev_names),
371 mee_enum ("Input device 2", MA_OPT_INPUT_DEV1, currentConfig.input_dev1, indev_names),
372 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
373 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
374 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
375 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
377 mee_label ("Input devices:"),
378 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
379 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
380 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
381 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
382 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
383 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
384 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
388 static int menu_loop_keyconfig(int id, int keys)
392 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
393 me_loop(e_menu_keyconfig, &sel);
395 PicoSetInputDevice(0, currentConfig.input_dev0);
396 PicoSetInputDevice(1, currentConfig.input_dev1);
401 // ------------ SCD options menu ------------
403 static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
404 static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
405 static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
406 static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
407 "most games don't need this";
408 static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
409 "disable to improve performance";
411 static menu_entry e_menu_cd_options[] =
413 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
414 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoIn.opt, POPT_EN_MCD_CDDA, h_cdda),
415 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoIn.opt, POPT_EN_MCD_PCM, h_cdpcm),
416 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoIn.opt, POPT_EN_MCD_RAMCART, h_srcart),
417 mee_onoff_h("Scale/Rot. fx", MA_CDOPT_SCALEROT_CHIP, PicoIn.opt, POPT_EN_MCD_GFX, h_scfx),
421 static int menu_loop_cd_options(int id, int keys)
424 me_loop(e_menu_cd_options, &sel);
428 // ------------ 32X options menu ------------
432 // convert from multiplier of VClk
433 static int mh_opt_sh2cycles(int id, int keys)
435 int *khz = (id == MA_32XOPT_MSH2_CYCLES) ?
436 ¤tConfig.msh2_khz : ¤tConfig.ssh2_khz;
438 if (keys & (PBTN_LEFT|PBTN_RIGHT))
439 *khz += (keys & PBTN_LEFT) ? -50 : 50;
440 if (keys & (PBTN_L|PBTN_R))
441 *khz += (keys & PBTN_L) ? -500 : 500;
445 else if (*khz > 0x7fffffff / 1000)
446 *khz = 0x7fffffff / 1000;
451 static const char *mgn_opt_sh2cycles(int id, int *offs)
453 int khz = (id == MA_32XOPT_MSH2_CYCLES) ?
454 currentConfig.msh2_khz : currentConfig.ssh2_khz;
456 sprintf(static_buff, "%d", khz);
460 static const char h_32x_enable[] = "Enable emulation of the 32X addon";
461 static const char h_pwm[] = "Disabling may improve performance, but break sound";
462 static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
463 "lower values speed up emulation but break games\n"
464 "at least 11000 recommended for compatibility";
466 static menu_entry e_menu_32x_options[] =
468 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoIn.opt, POPT_EN_32X, h_32x_enable),
469 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
470 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoIn.opt, POPT_EN_PWM, h_pwm),
471 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
472 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
476 static int menu_loop_32x_options(int id, int keys)
480 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
481 me_loop(e_menu_32x_options, &sel);
483 Pico32xSetClocks(currentConfig.msh2_khz * 1000, currentConfig.msh2_khz * 1000);
490 // ------------ adv options menu ------------
492 static const char h_ovrclk[] = "Will break some games, keep at 0";
494 static menu_entry e_menu_adv_options[] =
496 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
497 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoIn.opt, POPT_DIS_SPRITE_LIM),
498 mee_range_h ("Overclock M68k (%)", MA_OPT2_OVERCLOCK_M68K,currentConfig.overclock_68k, 0, 1000, h_ovrclk),
499 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoIn.opt, POPT_EN_Z80),
500 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoIn.opt, POPT_EN_FM),
501 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoIn.opt, POPT_EN_PSG),
502 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
503 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
504 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoIn.opt, POPT_DIS_IDLE_DET),
505 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
506 mee_onoff ("Enable dynarecs", MA_OPT2_DYNARECS, PicoIn.opt, POPT_EN_DRC),
507 mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC),
512 static int menu_loop_adv_options(int id, int keys)
516 me_loop(e_menu_adv_options, &sel);
517 PicoIn.overclockM68k = currentConfig.overclock_68k; // int vs short
522 // ------------ gfx options menu ------------
524 static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)";
526 static const char *mgn_aopt_gamma(int id, int *offs)
528 sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
532 static menu_entry e_menu_gfx_options[] =
534 mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
535 mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
536 mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
537 mee_range_cust_h("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma, h_gamma),
542 static int menu_loop_gfx_options(int id, int keys)
546 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
547 me_loop(e_menu_gfx_options, &sel);
552 // ------------ options menu ------------
554 static menu_entry e_menu_options[];
556 static int sndrate_prevnext(int rate, int dir)
558 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
561 for (i = 0; i < 5; i++)
562 if (rates[i] == rate) break;
566 if (!(PicoIn.opt & POPT_EN_STEREO)) {
567 PicoIn.opt |= POPT_EN_STEREO;
573 if (PicoIn.opt & POPT_EN_STEREO) {
574 PicoIn.opt &= ~POPT_EN_STEREO;
582 static void region_prevnext(int right)
584 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
585 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
589 if (!PicoIn.regionOverride) {
590 for (i = 0; i < 6; i++)
591 if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
592 if (i < 5) PicoIn.autoRgnOrder = rgn_orders[i+1];
593 else PicoIn.regionOverride=1;
596 PicoIn.regionOverride <<= 1;
597 if (PicoIn.regionOverride > 8)
598 PicoIn.regionOverride = 8;
600 if (!PicoIn.regionOverride) {
601 for (i = 0; i < 6; i++)
602 if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
603 if (i > 0) PicoIn.autoRgnOrder = rgn_orders[i-1];
606 PicoIn.regionOverride >>= 1;
610 static int mh_opt_misc(int id, int keys)
613 case MA_OPT_SOUND_QUALITY:
614 PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, keys & PBTN_RIGHT);
617 region_prevnext(keys & PBTN_RIGHT);
625 static int mh_saveloadcfg(int id, int keys)
629 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
630 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
631 if (config_slot < 0) config_slot = 9;
632 else if (config_slot > 9) config_slot = 0;
633 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
639 case MA_OPT_SAVECFG_GAME:
640 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
641 menu_update_msg("config saved");
643 menu_update_msg("failed to write config");
646 ret = emu_read_config(rom_fname_loaded, 1);
647 if (!ret) ret = emu_read_config(NULL, 1);
648 if (ret) menu_update_msg("config loaded");
649 else menu_update_msg("failed to load config");
658 static int mh_restore_defaults(int id, int keys)
661 menu_update_msg("defaults restored");
665 static const char *mgn_opt_fskip(int id, int *offs)
667 if (currentConfig.Frameskip < 0)
669 sprintf(static_buff, "%d", currentConfig.Frameskip);
673 static const char *mgn_opt_sound(int id, int *offs)
677 str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono";
678 sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2);
682 static const char *mgn_opt_region(int id, int *offs)
684 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
685 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
686 int code = PicoIn.regionOverride;
692 while ((code >>= 1)) i++;
697 strcpy(static_buff, "Auto:");
698 for (u = 0; u < 3; u++) {
699 code = (PicoIn.autoRgnOrder >> u*4) & 0xf;
700 for (i = 0; code; code >>= 1, i++)
702 strcat(static_buff, names_short[i]);
708 static const char *mgn_saveloadcfg(int id, int *offs)
711 if (config_slot != 0)
712 sprintf(static_buff, "[%i]", config_slot);
716 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
717 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
718 "loading state or both";
720 static menu_entry e_menu_options[] =
722 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
723 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
724 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
725 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
726 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
727 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
728 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
729 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 3200),
730 mee_handler ("[Display options]", menu_loop_gfx_options),
731 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
733 mee_handler ("[32X options]", menu_loop_32x_options),
735 mee_handler ("[Advanced options]", menu_loop_adv_options),
736 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
737 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
738 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
739 mee_handler ("Restore defaults", mh_restore_defaults),
743 static int menu_loop_options(int id, int keys)
747 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
748 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
750 me_loop(e_menu_options, &sel);
755 // ------------ debug menu ------------
757 #include <pico/debug.h>
759 extern void SekStepM68k(void);
761 static void mplayer_loop(void)
768 if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
776 static void draw_text_debug(const char *str, int skip, int from)
784 while (*p && *p != '\n')
786 if (*p == 0 || p[1] == 0)
792 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
794 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
795 while (*p && *p != '\n')
804 #define COMPILER "gcc " __VERSION__
809 static void draw_frame_debug(void)
811 char layer_str[48] = "layers: ";
812 struct PicoVideo *pv = &Pico.video;
814 if (!(pv->debug_p & PVD_KILL_B)) memcpy(layer_str + 8, "B", 1);
815 if (!(pv->debug_p & PVD_KILL_A)) memcpy(layer_str + 10, "A", 1);
816 if (!(pv->debug_p & PVD_KILL_S_LO)) memcpy(layer_str + 12, "spr_lo", 6);
817 if (!(pv->debug_p & PVD_KILL_S_HI)) memcpy(layer_str + 19, "spr_hi", 6);
818 if (!(pv->debug_p & PVD_KILL_32X)) memcpy(layer_str + 26, "32x", 4);
820 pemu_forced_frame(1, 0);
823 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
824 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
827 static void debug_menu_loop(void)
829 struct PicoVideo *pv = &Pico.video;
831 int spr_offs = 0, dumped = 0;
836 menu_draw_begin(1, 0);
839 case 0: tmp = PDebugMain();
841 draw_text_debug(tmp, 0, 0);
843 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
844 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
848 case 1: draw_frame_debug();
850 case 2: pemu_forced_frame(1, 0);
852 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr
853 + (g_menuscreen_h/2 - 240/2) * g_menuscreen_pp
854 + g_menuscreen_w/2 - 320/2, g_menuscreen_pp);
856 case 3: menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
857 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_pp);
858 PDebugShowSprite((unsigned short *)g_menuscreen_ptr
859 + g_menuscreen_pp * 120 + g_menuscreen_w / 2 + 16,
860 g_menuscreen_pp, spr_offs);
861 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
863 case 4: tmp = PDebug32x();
864 draw_text_debug(tmp, 0, 0);
869 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
870 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
871 if (inp & PBTN_MBACK) return;
872 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
873 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
879 if (inp & PBTN_MA3) {
880 while (inp & PBTN_MA3)
881 inp = in_menu_wait_any(NULL, -1);
884 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
885 mkdir("dumps", 0777);
887 while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
892 if (inp & PBTN_LEFT) pv->debug_p ^= PVD_KILL_B;
893 if (inp & PBTN_RIGHT) pv->debug_p ^= PVD_KILL_A;
894 if (inp & PBTN_DOWN) pv->debug_p ^= PVD_KILL_S_LO;
895 if (inp & PBTN_UP) pv->debug_p ^= PVD_KILL_S_HI;
896 if (inp & PBTN_MA2) pv->debug_p ^= PVD_KILL_32X;
897 if (inp & PBTN_MOK) {
898 PicoIn.sndOut = NULL; // just in case
899 PicoIn.skipFrame = 1;
901 PicoIn.skipFrame = 0;
902 while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
906 if (inp & PBTN_DOWN) spr_offs++;
907 if (inp & PBTN_UP) spr_offs--;
908 if (spr_offs < 0) spr_offs = 0;
914 // ------------ main menu ------------
916 static void draw_frame_credits(void)
918 smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xe7fc);
921 static const char credits[] =
922 "PicoDrive v" VERSION " (c) notaz, 2006-2013\n\n\n"
924 "fDave: initial code\n"
926 " Cyclone 68000 core\n"
928 "Stef, Chui: FAME/C 68k core\n"
931 "Reesy & FluBBa: DrZ80 core\n"
933 "Stef, NJ: CZ80 core\n"
935 "MAME devs: SH2, YM2612 and SN76496 cores\n"
936 "Eke, Stef: some Sega CD code\n"
937 "Inder, ketchupgun: graphics\n"
940 "Dzz: ARM940 sample\n"
943 "special thanks (for docs, ideas):\n"
944 " Charles MacDonald, Haze,\n"
945 " Stephane Dallongeville,\n"
946 " Lordus, Exophase, Rokas,\n"
947 " Eke, Nemesis, Tasco Deluxe";
949 static void menu_main_draw_status(void)
951 static time_t last_bat_read = 0;
952 static int last_bat_val = -1;
953 unsigned short *bp = g_screen_ptr;
954 int bat_h = me_mfont_h * 2 / 3;
955 int i, u, w, wfill, batt_val;
960 if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
964 tmp = gmtime(<ime);
965 strftime(time_s, sizeof(time_s), "%H:%M", tmp);
967 text_out16(g_screen_width - me_mfont_w * 6, me_mfont_h + 2, time_s);
969 if (ltime - last_bat_read > 10) {
970 last_bat_read = ltime;
971 last_bat_val = batt_val = plat_target_bat_capacity_get();
974 batt_val = last_bat_val;
976 if (batt_val < 0 || batt_val > 100)
980 bp += (me_mfont_h * 2 + 2) * g_screen_ppitch + g_screen_width - me_mfont_w * 3 - 3;
981 for (i = 0; i < me_mfont_w * 2; i++)
982 bp[i] = menu_text_color;
983 for (i = 0; i < me_mfont_w * 2; i++)
984 bp[i + g_screen_ppitch * bat_h] = menu_text_color;
985 for (i = 0; i <= bat_h; i++)
986 bp[i * g_screen_ppitch] =
987 bp[i * g_screen_ppitch + me_mfont_w * 2] = menu_text_color;
988 for (i = 2; i < bat_h - 1; i++)
989 bp[i * g_screen_ppitch - 1] =
990 bp[i * g_screen_ppitch - 2] = menu_text_color;
992 w = me_mfont_w * 2 - 1;
993 wfill = batt_val * w / 100;
994 for (u = 1; u < bat_h; u++)
995 for (i = 0; i < wfill; i++)
996 bp[(w - i) + g_screen_ppitch * u] = menu_text_color;
999 static int main_menu_handler(int id, int keys)
1001 const char *ret_name;
1005 case MA_MAIN_RESUME_GAME:
1009 case MA_MAIN_SAVE_STATE:
1011 return menu_loop_savestate(0);
1013 case MA_MAIN_LOAD_STATE:
1015 return menu_loop_savestate(1);
1017 case MA_MAIN_RESET_GAME:
1018 if (PicoGameLoaded) {
1023 case MA_MAIN_LOAD_ROM:
1024 rom_fname_reload = NULL;
1025 ret_name = menu_loop_romsel(rom_fname_loaded,
1026 sizeof(rom_fname_loaded), rom_exts, NULL);
1027 if (ret_name != NULL) {
1028 lprintf("selected file: %s\n", ret_name);
1029 rom_fname_reload = ret_name;
1030 engineState = PGS_ReloadRom;
1034 case MA_MAIN_CHANGE_CD:
1035 if (PicoIn.AHW & PAHW_MCD) {
1036 // if cd is loaded, cdd_unload() triggers eject and
1037 // returns 1, else we'll select and load new CD here
1043 case MA_MAIN_CREDITS:
1044 draw_menu_message(credits, draw_frame_credits);
1045 in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
1048 engineState = PGS_Quit;
1050 case MA_MAIN_PATCHES:
1051 if (PicoGameLoaded && PicoPatches) {
1052 menu_loop_patches();
1054 menu_update_msg("Patches applied");
1058 lprintf("%s: something unknown selected\n", __FUNCTION__);
1065 static menu_entry e_menu_main[] =
1067 mee_label ("PicoDrive " VERSION),
1071 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
1072 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
1073 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
1074 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
1075 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
1076 mee_handler_id("Change CD/ISO", MA_MAIN_CHANGE_CD, main_menu_handler),
1077 mee_handler ("Change options", menu_loop_options),
1078 mee_handler ("Configure controls", menu_loop_keyconfig),
1079 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
1080 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
1081 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
1085 void menu_loop(void)
1089 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
1090 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
1091 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
1092 me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
1093 me_enable(e_menu_main, MA_MAIN_CHANGE_CD, PicoIn.AHW & PAHW_MCD);
1094 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
1096 menu_enter(PicoGameLoaded);
1097 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1098 me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
1100 if (PicoGameLoaded) {
1101 if (engineState == PGS_Menu)
1102 engineState = PGS_Running;
1103 /* wait until menu, ok, back is released */
1104 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1108 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1109 plat_video_menu_leave();
1112 // --------- CD tray close menu ----------
1114 static int mh_tray_load_cd(int id, int keys)
1116 const char *ret_name;
1118 rom_fname_reload = NULL;
1119 ret_name = menu_loop_romsel(rom_fname_loaded,
1120 sizeof(rom_fname_loaded), rom_exts, NULL);
1121 if (ret_name == NULL)
1124 rom_fname_reload = ret_name;
1125 engineState = PGS_RestartRun;
1126 return emu_swap_cd(ret_name);
1129 static int mh_tray_nothing(int id, int keys)
1134 static menu_entry e_menu_tray[] =
1136 mee_label ("The CD tray has opened."),
1139 mee_handler("Load CD image", mh_tray_load_cd),
1140 mee_handler("Insert nothing", mh_tray_nothing),
1144 int menu_loop_tray(void)
1146 int ret = 1, sel = 0;
1148 menu_enter(PicoGameLoaded);
1150 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1151 me_loop(e_menu_tray, &sel);
1153 if (engineState != PGS_RestartRun) {
1154 engineState = PGS_RestartRun;
1155 ret = 0; /* no CD inserted */
1158 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1160 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1161 plat_video_menu_leave();
1166 void menu_update_msg(const char *msg)
1168 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1169 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1171 menu_error_time = plat_get_ticks_ms();
1172 lprintf("msg: %s\n", menu_error_msg);
1175 // ------------ util ------------
1177 /* hidden options for config engine only */
1178 static menu_entry e_menu_hidden[] =
1180 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoIn.opt, 0x080),
1181 mee_onoff("autoload savestates", MA_OPT_AUTOLOAD_SAVE, g_autostateld_opt, 1),
1185 static menu_entry *e_menu_table[] =
1198 static menu_entry *me_list_table = NULL;
1199 static menu_entry *me_list_i = NULL;
1201 menu_entry *me_list_get_first(void)
1203 me_list_table = me_list_i = e_menu_table[0];
1207 menu_entry *me_list_get_next(void)
1212 if (me_list_i->name != NULL)
1215 for (i = 0; i < array_size(e_menu_table); i++)
1216 if (me_list_table == e_menu_table[i])
1219 if (i + 1 < array_size(e_menu_table))
1220 me_list_table = me_list_i = e_menu_table[i + 1];
1222 me_list_table = me_list_i = NULL;
1227 void menu_init(void)
1234 #if defined(_SVP_DRC) || defined(DRC_SH2)
1237 me_enable(e_menu_adv_options, MA_OPT2_DYNARECS, i);
1239 i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
1240 e_menu_gfx_options[i].data = plat_target.vout_methods;
1241 me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
1242 plat_target.vout_methods != NULL);
1244 i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
1245 e_menu_gfx_options[i].data = plat_target.hwfilters;
1246 me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
1247 plat_target.hwfilters != NULL);
1249 me_enable(e_menu_gfx_options, MA_OPT2_GAMMA,
1250 plat_target.gamma_set != NULL);
1252 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
1253 e_menu_options[i].enabled = 0;
1254 if (plat_target.cpu_clock_set != NULL) {
1255 e_menu_options[i].name = "CPU clock";
1256 e_menu_options[i].enabled = 1;