7 #include <pico/patch.h>
11 /* platform specific options and handlers */
13 #include "../gp2x/menu.c"
14 #elif defined(PANDORA)
15 #include "../pandora/menu.c"
17 #define MENU_OPTIONS_GFX
18 #define MENU_OPTIONS_ADV
19 #define menu_main_plat_draw NULL
22 static void draw_savestate_bg(int slot)
27 fname = emu_get_save_fname(1, 0, slot);
31 tmp_state = PicoTmpStateSave();
33 PicoStateLoadGfx(fname);
35 /* do a frame and fetch menu bg */
36 pemu_forced_frame(0, 0);
38 menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1);
40 PicoTmpStateRestore(tmp_state);
43 // --------- loading ROM screen ----------
45 static int cdload_called = 0;
47 static void load_progress_cb(int percent)
49 int ln, len = percent * g_menuscreen_w / 100;
52 if (len > g_menuscreen_w)
56 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
57 for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
58 memset(dst, 0xff, len * 2);
62 static void cdload_progress_cb(const char *fname, int percent)
64 int ln, len = percent * g_menuscreen_w / 100;
68 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
69 memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
71 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
72 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
73 dst += g_menuscreen_w * me_sfont_h * 3;
75 if (len > g_menuscreen_w)
78 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)
79 memset(dst, 0xff, len * 2);
85 void menu_romload_prepare(const char *rom_name)
87 const char *p = rom_name + strlen(rom_name);
90 while (p > rom_name && *p != '/')
93 /* fill all buffers, callbacks won't update in full */
94 for (i = 0; i < 3; i++) {
96 smalltext_out16(1, 1, "Loading", 0xffff);
97 smalltext_out16(1, me_sfont_h, p, 0xffff);
101 PicoCartLoadProgressCB = load_progress_cb;
102 PicoCDLoadProgressCB = cdload_progress_cb;
106 void menu_romload_end(void)
108 PicoCartLoadProgressCB = NULL;
109 PicoCDLoadProgressCB = NULL;
112 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
113 "Starting emulation...", 0xffff);
117 // ------------ patch/gg menu ------------
119 static void draw_patchlist(int sel)
121 int max_cnt, start, i, pos, active;
123 max_cnt = g_menuscreen_h / me_sfont_h;
124 start = max_cnt / 2 - sel;
128 for (i = 0; i < PicoPatchCount; i++) {
130 if (pos < 0) continue;
131 if (pos >= max_cnt) break;
132 active = PicoPatches[i].active;
133 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
134 smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
138 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
140 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
144 static void menu_loop_patches(void)
146 static int menu_sel = 0;
151 draw_patchlist(menu_sel);
152 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK, 33);
153 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
154 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
155 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
156 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
157 if (inp & PBTN_MOK) { // action
158 if (menu_sel < PicoPatchCount)
159 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
162 if (inp & PBTN_MBACK)
167 // -------------- key config --------------
169 // PicoPad[] format: MXYZ SACB RLDU
170 me_bind_action me_ctrl_actions[] =
175 { "RIGHT ", 0x0008 },
179 { "A turbo", 0x4000 },
180 { "B turbo", 0x1000 },
181 { "C turbo", 0x2000 },
182 { "START ", 0x0080 },
190 me_bind_action emuctrl_actions[] =
192 { "Load State ", PEV_STATE_LOAD },
193 { "Save State ", PEV_STATE_SAVE },
194 { "Prev Save Slot ", PEV_SSLOT_PREV },
195 { "Next Save Slot ", PEV_SSLOT_NEXT },
196 { "Switch Renderer ", PEV_SWITCH_RND },
197 { "Volume Down ", PEV_VOL_DOWN },
198 { "Volume Up ", PEV_VOL_UP },
199 { "Fast forward ", PEV_FF },
200 { "Enter Menu ", PEV_MENU },
201 { "Pico Next page ", PEV_PICO_PNEXT },
202 { "Pico Prev page ", PEV_PICO_PPREV },
203 { "Pico Switch input", PEV_PICO_SWINP },
207 static int key_config_loop_wrap(int id, int keys)
210 case MA_CTRL_PLAYER1:
211 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
213 case MA_CTRL_PLAYER2:
214 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
217 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
225 static const char *mgn_dev_name(int id, int *offs)
227 const char *name = NULL;
230 if (id == MA_CTRL_DEV_FIRST)
233 for (; it < IN_MAX_DEVS; it++) {
234 name = in_get_dev_name(it, 1, 1);
243 static int mh_saveloadcfg(int id, int keys);
244 static const char *mgn_saveloadcfg(int id, int *offs);
246 static menu_entry e_menu_keyconfig[] =
248 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
249 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
250 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
251 mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),
252 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
253 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
254 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
255 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
257 mee_label ("Input devices:"),
258 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
259 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
260 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
261 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
262 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
263 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
264 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
268 static int menu_loop_keyconfig(int id, int keys)
272 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded);
273 me_loop(e_menu_keyconfig, &sel, NULL);
277 // ------------ SCD options menu ------------
279 static const char *mgn_cdopt_ra(int id, int *offs)
282 if (PicoCDBuffers <= 0)
284 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
288 static int mh_cdopt_ra(int id, int keys)
290 if (keys & PBTN_LEFT) {
292 if (PicoCDBuffers < 2)
295 if (PicoCDBuffers <= 0)
298 if (PicoCDBuffers > 8*1024)
299 PicoCDBuffers = 8*1024; // 16M
304 static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
305 static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
306 static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
307 static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
308 "most games don't need this";
309 static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
310 "disable to improve performance";
311 static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
312 "disable to improve performance";
314 static menu_entry e_menu_cd_options[] =
316 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
317 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
318 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
319 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
320 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
321 mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
322 mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync),
326 static int menu_loop_cd_options(int id, int keys)
329 me_loop(e_menu_cd_options, &sel, NULL);
333 // ------------ 32X options menu ------------
337 // convert from multiplier of VClk
338 static int mh_opt_sh2cycles(int id, int keys)
340 int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier;
342 if (keys & (PBTN_LEFT|PBTN_RIGHT))
343 *mul += (keys & PBTN_LEFT) ? -10 : 10;
344 if (keys & (PBTN_L|PBTN_R))
345 *mul += (keys & PBTN_L) ? -100 : 100;
349 else if (*mul > (10 << SH2_MULTI_SHIFT))
350 *mul = 10 << SH2_MULTI_SHIFT;
355 static const char *mgn_opt_sh2cycles(int id, int *offs)
357 int mul = (id == MA_32XOPT_MSH2_CYCLES) ? p32x_msh2_multiplier : p32x_ssh2_multiplier;
359 sprintf(static_buff, "%d", 7670 * mul >> SH2_MULTI_SHIFT);
363 static const char h_32x_enable[] = "Enable emulation of the 32X addon";
364 static const char h_pwm[] = "Disabling may improve performance, but break sound";
365 static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
366 "lower values speed up emulation but break games\n"
367 "at least 11000 recommended for compatibility";
369 static menu_entry e_menu_32x_options[] =
371 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
372 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
373 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
374 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
375 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
379 static int menu_loop_32x_options(int id, int keys)
383 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
384 me_loop(e_menu_32x_options, &sel, NULL);
391 // ------------ adv options menu ------------
393 static menu_entry e_menu_adv_options[] =
395 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
396 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
397 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
398 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
399 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
400 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
401 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
402 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
403 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
408 static int menu_loop_adv_options(int id, int keys)
411 me_loop(e_menu_adv_options, &sel, NULL);
415 // ------------ gfx options menu ------------
417 static menu_entry e_menu_gfx_options[] =
419 mee_enum("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
424 static int menu_loop_gfx_options(int id, int keys)
428 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
429 me_loop(e_menu_gfx_options, &sel, NULL);
434 // ------------ options menu ------------
436 static menu_entry e_menu_options[];
438 static int sndrate_prevnext(int rate, int dir)
440 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
443 for (i = 0; i < 5; i++)
444 if (rates[i] == rate) break;
448 if (!(PicoOpt & POPT_EN_STEREO)) {
449 PicoOpt |= POPT_EN_STEREO;
455 if (PicoOpt & POPT_EN_STEREO) {
456 PicoOpt &= ~POPT_EN_STEREO;
464 static void region_prevnext(int right)
466 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
467 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
471 if (!PicoRegionOverride) {
472 for (i = 0; i < 6; i++)
473 if (rgn_orders[i] == PicoAutoRgnOrder) break;
474 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
475 else PicoRegionOverride=1;
478 PicoRegionOverride <<= 1;
479 if (PicoRegionOverride > 8)
480 PicoRegionOverride = 8;
482 if (!PicoRegionOverride) {
483 for (i = 0; i < 6; i++)
484 if (rgn_orders[i] == PicoAutoRgnOrder) break;
485 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
488 PicoRegionOverride >>= 1;
492 static int mh_opt_misc(int id, int keys)
495 case MA_OPT_SOUND_QUALITY:
496 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
499 region_prevnext(keys & PBTN_RIGHT);
507 static int mh_saveloadcfg(int id, int keys)
511 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
512 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
513 if (config_slot < 0) config_slot = 9;
514 else if (config_slot > 9) config_slot = 0;
515 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
521 case MA_OPT_SAVECFG_GAME:
522 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
523 me_update_msg("config saved");
525 me_update_msg("failed to write config");
528 ret = emu_read_config(rom_fname_loaded, 1);
529 if (!ret) ret = emu_read_config(NULL, 1);
530 if (ret) me_update_msg("config loaded");
531 else me_update_msg("failed to load config");
540 static int mh_restore_defaults(int id, int keys)
543 me_update_msg("defaults restored");
547 static const char *mgn_opt_fskip(int id, int *offs)
549 if (currentConfig.Frameskip < 0)
551 sprintf(static_buff, "%d", currentConfig.Frameskip);
555 static const char *mgn_opt_sound(int id, int *offs)
559 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
560 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
564 static const char *mgn_opt_region(int id, int *offs)
566 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
567 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
568 int code = PicoRegionOverride;
574 while ((code >>= 1)) i++;
579 strcpy(static_buff, "Auto:");
580 for (u = 0; u < 3; u++) {
581 code = (PicoAutoRgnOrder >> u*4) & 0xf;
582 for (i = 0; code; code >>= 1, i++)
584 strcat(static_buff, names_short[i]);
590 static const char *mgn_saveloadcfg(int id, int *offs)
593 if (config_slot != 0)
594 sprintf(static_buff, "[%i]", config_slot);
598 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
599 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
600 "loading state or both";
602 static menu_entry e_menu_options[] =
604 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
605 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
606 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
607 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
608 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
609 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
610 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
611 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 1200),
612 mee_handler ("[Display options]", menu_loop_gfx_options),
613 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
615 mee_handler ("[32X options]", menu_loop_32x_options),
617 mee_handler ("[Advanced options]", menu_loop_adv_options),
618 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
619 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
620 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
621 mee_handler ("Restore defaults", mh_restore_defaults),
625 static int menu_loop_options(int id, int keys)
630 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
631 e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;
632 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);
633 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
635 me_loop(e_menu_options, &sel, NULL);
640 // ------------ debug menu ------------
642 #include <pico/debug.h>
644 extern void SekStepM68k(void);
646 static void mplayer_loop(void)
653 if (in_menu_wait_any(0) & PBTN_MA3)
661 static void draw_text_debug(const char *str, int skip, int from)
669 while (*p && *p != '\n')
671 if (*p == 0 || p[1] == 0)
677 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
679 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
680 while (*p && *p != '\n')
689 #define COMPILER "gcc " __VERSION__
694 static void draw_frame_debug(void)
696 char layer_str[48] = "layers: ";
697 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
698 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
699 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
700 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
701 if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4);
703 pemu_forced_frame(1, 0);
704 memcpy(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
705 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
706 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
709 static void debug_menu_loop(void)
712 int spr_offs = 0, dumped = 0;
720 case 0: tmp = PDebugMain();
722 draw_text_debug(tmp, 0, 0);
724 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
725 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
729 case 1: draw_frame_debug();
731 case 2: pemu_forced_frame(1, 0);
732 menu_darken_bg(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 0);
733 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
734 g_menuscreen_w/2 - 320/2, g_menuscreen_w);
736 case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
737 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
738 PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
739 g_menuscreen_w, spr_offs);
740 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
742 case 4: tmp = PDebug32x();
743 draw_text_debug(tmp, 0, 0);
748 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
749 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
750 if (inp & PBTN_MBACK) return;
751 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
752 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
758 if (inp & PBTN_MA3) {
759 while (inp & PBTN_MA3)
760 inp = in_menu_wait_any(-1);
763 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
764 mkdir("dumps", 0777);
766 while (inp & PBTN_MA2) inp = in_menu_wait_any(-1);
771 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
772 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
773 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
774 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
775 if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON;
776 if (inp & PBTN_MOK) {
777 PsndOut = NULL; // just in case
781 while (inp & PBTN_MOK) inp = in_menu_wait_any(-1);
785 if (inp & PBTN_DOWN) spr_offs++;
786 if (inp & PBTN_UP) spr_offs--;
787 if (spr_offs < 0) spr_offs = 0;
793 // ------------ main menu ------------
795 static char *romsel_run(void)
797 char *ret, *sel_name;
799 sel_name = malloc(sizeof(rom_fname_loaded));
800 if (sel_name == NULL)
802 strcpy(sel_name, rom_fname_loaded);
804 ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));
809 static int main_menu_handler(int id, int keys)
815 case MA_MAIN_RESUME_GAME:
819 case MA_MAIN_SAVE_STATE:
821 return menu_loop_savestate(0);
823 case MA_MAIN_LOAD_STATE:
825 return menu_loop_savestate(1);
827 case MA_MAIN_RESET_GAME:
833 case MA_MAIN_LOAD_ROM:
834 ret_name = romsel_run();
835 if (ret_name != NULL) {
836 lprintf("selected file: %s\n", ret_name);
837 engineState = PGS_ReloadRom;
841 case MA_MAIN_CREDITS:
843 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
846 engineState = PGS_Quit;
848 case MA_MAIN_PATCHES:
849 if (rom_loaded && PicoPatches) {
852 me_update_msg("Patches applied");
856 lprintf("%s: something unknown selected\n", __FUNCTION__);
863 static menu_entry e_menu_main[] =
865 mee_label ("PicoDrive " VERSION),
869 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
870 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
871 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
872 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
873 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
874 mee_handler ("Change options", menu_loop_options),
875 mee_handler ("Configure controls", menu_loop_keyconfig),
876 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
877 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
878 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
886 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);
887 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, rom_loaded);
888 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, rom_loaded);
889 me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded);
890 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
892 menu_enter(rom_loaded);
893 in_set_config_int(0, IN_CFG_BLOCKING, 1);
894 me_loop(e_menu_main, &sel, menu_main_plat_draw);
897 if (engineState == PGS_Menu)
898 engineState = PGS_Running;
899 /* wait until menu, ok, back is released */
900 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
904 in_set_config_int(0, IN_CFG_BLOCKING, 0);
907 // --------- CD tray close menu ----------
909 static int mh_tray_load_cd(int id, int keys)
913 ret_name = romsel_run();
914 if (ret_name == NULL)
917 engineState = PGS_RestartRun;
918 return emu_swap_cd(ret_name);
921 static int mh_tray_nothing(int id, int keys)
926 static menu_entry e_menu_tray[] =
928 mee_label ("The CD tray has opened."),
931 mee_handler("Load CD image", mh_tray_load_cd),
932 mee_handler("Insert nothing", mh_tray_nothing),
936 int menu_loop_tray(void)
938 int ret = 1, sel = 0;
940 menu_enter(rom_loaded);
942 in_set_config_int(0, IN_CFG_BLOCKING, 1);
943 me_loop(e_menu_tray, &sel, NULL);
945 if (engineState != PGS_RestartRun) {
946 engineState = PGS_RestartRun;
947 ret = 0; /* no CD inserted */
950 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
951 in_set_config_int(0, IN_CFG_BLOCKING, 0);
956 void me_update_msg(const char *msg)
958 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
959 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
961 menu_error_time = plat_get_ticks_ms();
962 lprintf("msg: %s\n", menu_error_msg);
965 // ------------ util ------------
967 /* hidden options for config engine only */
968 static menu_entry e_menu_hidden[] =
970 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
974 static menu_entry *e_menu_table[] =
987 static menu_entry *me_list_table = NULL;
988 static menu_entry *me_list_i = NULL;
990 menu_entry *me_list_get_first(void)
992 me_list_table = me_list_i = e_menu_table[0];
996 menu_entry *me_list_get_next(void)
1001 if (me_list_i->name != NULL)
1004 for (i = 0; i < array_size(e_menu_table); i++)
1005 if (me_list_table == e_menu_table[i])
1008 if (i + 1 < array_size(e_menu_table))
1009 me_list_table = me_list_i = e_menu_table[i + 1];
1011 me_list_table = me_list_i = NULL;