5 #include "input_pico.h"
10 #include <pico/patch.h>
15 static const char *rom_exts[] = {
16 "zip", "bin", "smd", "gen",
17 "iso", "cso", "cue", NULL
20 // rrrr rggg gggb bbbb
21 static unsigned short fname2color(const char *fname)
23 const char *ext = fname + strlen(fname) - 3;
24 static const char *other_exts[] = { "gmv", "pat" };
27 if (ext < fname) ext = fname;
28 for (i = 0; rom_exts[i] != NULL; i++)
29 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
30 for (i = 0; i < array_size(other_exts); i++)
31 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
35 #include "../libpicofe/menu.c"
37 /* platform specific options and handlers */
39 #include "../gp2x/menu.c"
40 #elif defined(PANDORA)
41 #include "../pandora/menu.c"
43 #define MENU_OPTIONS_GFX
44 #define MENU_OPTIONS_ADV
45 #define menu_main_plat_draw NULL
48 static void menu_enter(int is_rom_loaded)
52 // darken the active framebuffer
53 menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1);
59 // should really only happen once, on startup..
60 emu_make_path(buff, "skin/background.png", sizeof(buff));
61 if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0)
62 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
65 plat_video_menu_enter(is_rom_loaded);
68 static void draw_savestate_bg(int slot)
73 fname = emu_get_save_fname(1, 0, slot);
77 tmp_state = PicoTmpStateSave();
79 PicoStateLoadGfx(fname);
81 /* do a frame and fetch menu bg */
82 pemu_forced_frame(0, 0);
84 menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1);
86 PicoTmpStateRestore(tmp_state);
89 // --------- loading ROM screen ----------
91 static int cdload_called = 0;
93 static void load_progress_cb(int percent)
95 int ln, len = percent * g_menuscreen_w / 100;
98 if (len > g_menuscreen_w)
101 menu_draw_begin(0, 1);
102 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
103 for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
104 memset(dst, 0xff, len * 2);
108 static void cdload_progress_cb(const char *fname, int percent)
110 int ln, len = percent * g_menuscreen_w / 100;
113 menu_draw_begin(0, 1);
114 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
115 memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
117 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
118 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
119 dst += g_menuscreen_w * me_sfont_h * 3;
121 if (len > g_menuscreen_w)
122 len = g_menuscreen_w;
124 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)
125 memset(dst, 0xff, len * 2);
131 void menu_romload_prepare(const char *rom_name)
133 const char *p = rom_name + strlen(rom_name);
136 while (p > rom_name && *p != '/')
139 /* fill all buffers, callbacks won't update in full */
140 for (i = 0; i < 3; i++) {
141 menu_draw_begin(1, 1);
142 smalltext_out16(1, 1, "Loading", 0xffff);
143 smalltext_out16(1, me_sfont_h, p, 0xffff);
147 PicoCartLoadProgressCB = load_progress_cb;
148 PicoCDLoadProgressCB = cdload_progress_cb;
152 void menu_romload_end(void)
154 PicoCartLoadProgressCB = NULL;
155 PicoCDLoadProgressCB = NULL;
157 menu_draw_begin(0, 1);
158 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
159 "Starting emulation...", 0xffff);
163 // ------------ patch/gg menu ------------
165 static void draw_patchlist(int sel)
167 int max_cnt, start, i, pos, active;
169 max_cnt = g_menuscreen_h / me_sfont_h;
170 start = max_cnt / 2 - sel;
172 menu_draw_begin(1, 0);
174 for (i = 0; i < PicoPatchCount; i++) {
176 if (pos < 0) continue;
177 if (pos >= max_cnt) break;
178 active = PicoPatches[i].active;
179 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
180 smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
184 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
186 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
190 static void menu_loop_patches(void)
192 static int menu_sel = 0;
197 draw_patchlist(menu_sel);
198 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
199 |PBTN_MOK|PBTN_MBACK, NULL, 33);
200 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
201 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
202 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
203 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
204 if (inp & PBTN_MOK) { // action
205 if (menu_sel < PicoPatchCount)
206 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
209 if (inp & PBTN_MBACK)
214 // -------------- key config --------------
216 // PicoPad[] format: MXYZ SACB RLDU
217 me_bind_action me_ctrl_actions[] =
222 { "RIGHT ", 0x0008 },
226 { "A turbo", 0x4000 },
227 { "B turbo", 0x1000 },
228 { "C turbo", 0x2000 },
229 { "START ", 0x0080 },
237 me_bind_action emuctrl_actions[] =
239 { "Load State ", PEV_STATE_LOAD },
240 { "Save State ", PEV_STATE_SAVE },
241 { "Prev Save Slot ", PEV_SSLOT_PREV },
242 { "Next Save Slot ", PEV_SSLOT_NEXT },
243 { "Switch Renderer ", PEV_SWITCH_RND },
244 { "Volume Down ", PEV_VOL_DOWN },
245 { "Volume Up ", PEV_VOL_UP },
246 { "Fast forward ", PEV_FF },
247 { "Enter Menu ", PEV_MENU },
248 { "Pico Next page ", PEV_PICO_PNEXT },
249 { "Pico Prev page ", PEV_PICO_PPREV },
250 { "Pico Switch input", PEV_PICO_SWINP },
254 static int key_config_loop_wrap(int id, int keys)
257 case MA_CTRL_PLAYER1:
258 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
260 case MA_CTRL_PLAYER2:
261 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
264 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
272 static const char *mgn_dev_name(int id, int *offs)
274 const char *name = NULL;
277 if (id == MA_CTRL_DEV_FIRST)
280 for (; it < IN_MAX_DEVS; it++) {
281 name = in_get_dev_name(it, 1, 1);
290 static int mh_saveloadcfg(int id, int keys);
291 static const char *mgn_saveloadcfg(int id, int *offs);
293 static menu_entry e_menu_keyconfig[] =
295 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
296 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
297 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
298 mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),
299 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
300 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
301 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
302 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
304 mee_label ("Input devices:"),
305 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
306 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
307 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
308 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
309 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
310 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
311 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
315 static int menu_loop_keyconfig(int id, int keys)
319 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded);
320 me_loop(e_menu_keyconfig, &sel);
324 // ------------ SCD options menu ------------
326 static const char *mgn_cdopt_ra(int id, int *offs)
329 if (PicoCDBuffers <= 0)
331 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
335 static int mh_cdopt_ra(int id, int keys)
337 if (keys & PBTN_LEFT) {
339 if (PicoCDBuffers < 2)
342 if (PicoCDBuffers <= 0)
345 if (PicoCDBuffers > 8*1024)
346 PicoCDBuffers = 8*1024; // 16M
351 static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
352 static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
353 static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
354 static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
355 "most games don't need this";
356 static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
357 "disable to improve performance";
358 static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
359 "disable to improve performance";
361 static menu_entry e_menu_cd_options[] =
363 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
364 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
365 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
366 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
367 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
368 mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
369 mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync),
373 static int menu_loop_cd_options(int id, int keys)
376 me_loop(e_menu_cd_options, &sel);
380 // ------------ 32X options menu ------------
384 // convert from multiplier of VClk
385 static int mh_opt_sh2cycles(int id, int keys)
387 int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier;
389 if (keys & (PBTN_LEFT|PBTN_RIGHT))
390 *mul += (keys & PBTN_LEFT) ? -10 : 10;
391 if (keys & (PBTN_L|PBTN_R))
392 *mul += (keys & PBTN_L) ? -100 : 100;
396 else if (*mul > (10 << SH2_MULTI_SHIFT))
397 *mul = 10 << SH2_MULTI_SHIFT;
402 static const char *mgn_opt_sh2cycles(int id, int *offs)
404 int mul = (id == MA_32XOPT_MSH2_CYCLES) ? p32x_msh2_multiplier : p32x_ssh2_multiplier;
406 sprintf(static_buff, "%d", 7670 * mul >> SH2_MULTI_SHIFT);
410 static const char h_32x_enable[] = "Enable emulation of the 32X addon";
411 static const char h_pwm[] = "Disabling may improve performance, but break sound";
412 static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
413 "lower values speed up emulation but break games\n"
414 "at least 11000 recommended for compatibility";
416 static menu_entry e_menu_32x_options[] =
418 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
419 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
420 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
421 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
422 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
426 static int menu_loop_32x_options(int id, int keys)
430 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
431 me_loop(e_menu_32x_options, &sel);
438 // ------------ adv options menu ------------
440 static menu_entry e_menu_adv_options[] =
442 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
443 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
444 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
445 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
446 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
447 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
448 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
449 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
450 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
455 static int menu_loop_adv_options(int id, int keys)
458 me_loop(e_menu_adv_options, &sel);
462 // ------------ gfx options menu ------------
464 static menu_entry e_menu_gfx_options[] =
466 mee_enum("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
471 static int menu_loop_gfx_options(int id, int keys)
475 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
476 me_loop(e_menu_gfx_options, &sel);
481 // ------------ options menu ------------
483 static menu_entry e_menu_options[];
485 static int sndrate_prevnext(int rate, int dir)
487 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
490 for (i = 0; i < 5; i++)
491 if (rates[i] == rate) break;
495 if (!(PicoOpt & POPT_EN_STEREO)) {
496 PicoOpt |= POPT_EN_STEREO;
502 if (PicoOpt & POPT_EN_STEREO) {
503 PicoOpt &= ~POPT_EN_STEREO;
511 static void region_prevnext(int right)
513 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
514 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
518 if (!PicoRegionOverride) {
519 for (i = 0; i < 6; i++)
520 if (rgn_orders[i] == PicoAutoRgnOrder) break;
521 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
522 else PicoRegionOverride=1;
525 PicoRegionOverride <<= 1;
526 if (PicoRegionOverride > 8)
527 PicoRegionOverride = 8;
529 if (!PicoRegionOverride) {
530 for (i = 0; i < 6; i++)
531 if (rgn_orders[i] == PicoAutoRgnOrder) break;
532 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
535 PicoRegionOverride >>= 1;
539 static int mh_opt_misc(int id, int keys)
542 case MA_OPT_SOUND_QUALITY:
543 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
546 region_prevnext(keys & PBTN_RIGHT);
554 static int mh_saveloadcfg(int id, int keys)
558 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
559 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
560 if (config_slot < 0) config_slot = 9;
561 else if (config_slot > 9) config_slot = 0;
562 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
568 case MA_OPT_SAVECFG_GAME:
569 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
570 menu_update_msg("config saved");
572 menu_update_msg("failed to write config");
575 ret = emu_read_config(rom_fname_loaded, 1);
576 if (!ret) ret = emu_read_config(NULL, 1);
577 if (ret) menu_update_msg("config loaded");
578 else menu_update_msg("failed to load config");
587 static int mh_restore_defaults(int id, int keys)
590 menu_update_msg("defaults restored");
594 static const char *mgn_opt_fskip(int id, int *offs)
596 if (currentConfig.Frameskip < 0)
598 sprintf(static_buff, "%d", currentConfig.Frameskip);
602 static const char *mgn_opt_sound(int id, int *offs)
606 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
607 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
611 static const char *mgn_opt_region(int id, int *offs)
613 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
614 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
615 int code = PicoRegionOverride;
621 while ((code >>= 1)) i++;
626 strcpy(static_buff, "Auto:");
627 for (u = 0; u < 3; u++) {
628 code = (PicoAutoRgnOrder >> u*4) & 0xf;
629 for (i = 0; code; code >>= 1, i++)
631 strcat(static_buff, names_short[i]);
637 static const char *mgn_saveloadcfg(int id, int *offs)
640 if (config_slot != 0)
641 sprintf(static_buff, "[%i]", config_slot);
645 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
646 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
647 "loading state or both";
649 static menu_entry e_menu_options[] =
651 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
652 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
653 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
654 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
655 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
656 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
657 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
658 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 1200),
659 mee_handler ("[Display options]", menu_loop_gfx_options),
660 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
662 mee_handler ("[32X options]", menu_loop_32x_options),
664 mee_handler ("[Advanced options]", menu_loop_adv_options),
665 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
666 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
667 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
668 mee_handler ("Restore defaults", mh_restore_defaults),
672 static int menu_loop_options(int id, int keys)
677 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
678 e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;
679 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);
680 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
682 me_loop(e_menu_options, &sel);
687 // ------------ debug menu ------------
689 #include <pico/debug.h>
691 extern void SekStepM68k(void);
693 static void mplayer_loop(void)
700 if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
708 static void draw_text_debug(const char *str, int skip, int from)
716 while (*p && *p != '\n')
718 if (*p == 0 || p[1] == 0)
724 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
726 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
727 while (*p && *p != '\n')
736 #define COMPILER "gcc " __VERSION__
741 static void draw_frame_debug(void)
743 char layer_str[48] = "layers: ";
744 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
745 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
746 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
747 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
748 if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4);
750 pemu_forced_frame(1, 0);
751 memcpy(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
752 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
753 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
756 static void debug_menu_loop(void)
759 int spr_offs = 0, dumped = 0;
764 menu_draw_begin(1, 0);
767 case 0: tmp = PDebugMain();
769 draw_text_debug(tmp, 0, 0);
771 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
772 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
776 case 1: draw_frame_debug();
778 case 2: pemu_forced_frame(1, 0);
779 menu_darken_bg(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 0);
780 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
781 g_menuscreen_w/2 - 320/2, g_menuscreen_w);
783 case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
784 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
785 PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
786 g_menuscreen_w, spr_offs);
787 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
789 case 4: tmp = PDebug32x();
790 draw_text_debug(tmp, 0, 0);
795 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
796 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
797 if (inp & PBTN_MBACK) return;
798 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
799 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
805 if (inp & PBTN_MA3) {
806 while (inp & PBTN_MA3)
807 inp = in_menu_wait_any(NULL, -1);
810 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
811 mkdir("dumps", 0777);
813 while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
818 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
819 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
820 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
821 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
822 if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON;
823 if (inp & PBTN_MOK) {
824 PsndOut = NULL; // just in case
828 while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
832 if (inp & PBTN_DOWN) spr_offs++;
833 if (inp & PBTN_UP) spr_offs--;
834 if (spr_offs < 0) spr_offs = 0;
840 // ------------ main menu ------------
842 static const char credits[] =
843 "PicoDrive v" VERSION " (c) notaz, 2006-2011\n\n\n"
845 "fDave: Cyclone 68000 core,\n"
846 " base code of PicoDrive\n"
847 "Reesy & FluBBa: DrZ80 core\n"
848 "MAME devs: YM2612 and SN76496 cores\n"
849 "Inder, ketchupgun: graphics\n"
851 "rlyeh and others: minimal SDK\n"
853 "Dzz: ARM940 sample\n"
856 "special thanks (for docs, ideas):\n"
857 " Charles MacDonald, Haze,\n"
858 " Stephane Dallongeville,\n"
859 " Lordus, Exophase, Rokas,\n"
860 " Nemesis, Tasco Deluxe";
862 static const char *romsel_run(void)
867 sel_name = malloc(sizeof(rom_fname_loaded));
868 if (sel_name == NULL)
870 strcpy(sel_name, rom_fname_loaded);
872 ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded), rom_exts, NULL);
877 static int main_menu_handler(int id, int keys)
879 const char *ret_name;
883 case MA_MAIN_RESUME_GAME:
887 case MA_MAIN_SAVE_STATE:
889 return menu_loop_savestate(0);
891 case MA_MAIN_LOAD_STATE:
893 return menu_loop_savestate(1);
895 case MA_MAIN_RESET_GAME:
901 case MA_MAIN_LOAD_ROM:
902 ret_name = romsel_run();
903 if (ret_name != NULL) {
904 lprintf("selected file: %s\n", ret_name);
905 engineState = PGS_ReloadRom;
909 case MA_MAIN_CREDITS:
910 draw_menu_message(credits, NULL);
911 in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
914 engineState = PGS_Quit;
916 case MA_MAIN_PATCHES:
917 if (rom_loaded && PicoPatches) {
920 menu_update_msg("Patches applied");
924 lprintf("%s: something unknown selected\n", __FUNCTION__);
931 static menu_entry e_menu_main[] =
933 mee_label ("PicoDrive " VERSION),
937 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
938 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
939 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
940 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
941 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
942 mee_handler ("Change options", menu_loop_options),
943 mee_handler ("Configure controls", menu_loop_keyconfig),
944 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
945 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
946 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
954 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);
955 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, rom_loaded);
956 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, rom_loaded);
957 me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded);
958 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
960 menu_enter(rom_loaded);
961 in_set_config_int(0, IN_CFG_BLOCKING, 1);
962 me_loop_d(e_menu_main, &sel, NULL, menu_main_plat_draw);
965 if (engineState == PGS_Menu)
966 engineState = PGS_Running;
967 /* wait until menu, ok, back is released */
968 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
972 in_set_config_int(0, IN_CFG_BLOCKING, 0);
975 // --------- CD tray close menu ----------
977 static int mh_tray_load_cd(int id, int keys)
979 const char *ret_name;
981 ret_name = romsel_run();
982 if (ret_name == NULL)
985 engineState = PGS_RestartRun;
986 return emu_swap_cd(ret_name);
989 static int mh_tray_nothing(int id, int keys)
994 static menu_entry e_menu_tray[] =
996 mee_label ("The CD tray has opened."),
999 mee_handler("Load CD image", mh_tray_load_cd),
1000 mee_handler("Insert nothing", mh_tray_nothing),
1004 int menu_loop_tray(void)
1006 int ret = 1, sel = 0;
1008 menu_enter(rom_loaded);
1010 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1011 me_loop(e_menu_tray, &sel);
1013 if (engineState != PGS_RestartRun) {
1014 engineState = PGS_RestartRun;
1015 ret = 0; /* no CD inserted */
1018 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
1019 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1024 void menu_update_msg(const char *msg)
1026 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1027 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1029 menu_error_time = plat_get_ticks_ms();
1030 lprintf("msg: %s\n", menu_error_msg);
1033 // ------------ util ------------
1035 /* hidden options for config engine only */
1036 static menu_entry e_menu_hidden[] =
1038 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
1042 static menu_entry *e_menu_table[] =
1055 static menu_entry *me_list_table = NULL;
1056 static menu_entry *me_list_i = NULL;
1058 menu_entry *me_list_get_first(void)
1060 me_list_table = me_list_i = e_menu_table[0];
1064 menu_entry *me_list_get_next(void)
1069 if (me_list_i->name != NULL)
1072 for (i = 0; i < array_size(e_menu_table); i++)
1073 if (me_list_table == e_menu_table[i])
1076 if (i + 1 < array_size(e_menu_table))
1077 me_list_table = me_list_i = e_menu_table[i + 1];
1079 me_list_table = me_list_i = NULL;
1084 void menu_init(void)