10 #include <pico/patch.h>
12 // rrrr rggg gggb bbbb
13 static unsigned short fname2color(const char *fname)
15 const char *ext = fname + strlen(fname) - 3;
16 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" };
17 static const char *other_exts[] = { "gmv", "pat" };
20 if (ext < fname) ext = fname;
21 for (i = 0; i < array_size(rom_exts); i++)
22 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
23 for (i = 0; i < array_size(other_exts); i++)
24 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
28 static const char *filter_exts[] = {
29 ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
35 /* platform specific options and handlers */
37 #include "../gp2x/menu.c"
38 #elif defined(PANDORA)
39 #include "../pandora/menu.c"
41 #define MENU_OPTIONS_GFX
42 #define MENU_OPTIONS_ADV
43 #define menu_main_plat_draw NULL
46 static void menu_enter(int is_rom_loaded)
50 // darken the active framebuffer
51 menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1);
57 // should really only happen once, on startup..
58 emu_make_path(buff, "skin/background.png", sizeof(buff));
59 if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0)
60 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
63 plat_video_menu_enter(is_rom_loaded);
66 static void draw_savestate_bg(int slot)
71 fname = emu_get_save_fname(1, 0, slot);
75 tmp_state = PicoTmpStateSave();
77 PicoStateLoadGfx(fname);
79 /* do a frame and fetch menu bg */
80 pemu_forced_frame(0, 0);
82 menu_darken_bg(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 1);
84 PicoTmpStateRestore(tmp_state);
87 // --------- loading ROM screen ----------
89 static int cdload_called = 0;
91 static void load_progress_cb(int percent)
93 int ln, len = percent * g_menuscreen_w / 100;
96 if (len > g_menuscreen_w)
100 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
101 for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
102 memset(dst, 0xff, len * 2);
106 static void cdload_progress_cb(const char *fname, int percent)
108 int ln, len = percent * g_menuscreen_w / 100;
112 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
113 memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
115 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
116 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
117 dst += g_menuscreen_w * me_sfont_h * 3;
119 if (len > g_menuscreen_w)
120 len = g_menuscreen_w;
122 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)
123 memset(dst, 0xff, len * 2);
129 void menu_romload_prepare(const char *rom_name)
131 const char *p = rom_name + strlen(rom_name);
134 while (p > rom_name && *p != '/')
137 /* fill all buffers, callbacks won't update in full */
138 for (i = 0; i < 3; i++) {
140 smalltext_out16(1, 1, "Loading", 0xffff);
141 smalltext_out16(1, me_sfont_h, p, 0xffff);
145 PicoCartLoadProgressCB = load_progress_cb;
146 PicoCDLoadProgressCB = cdload_progress_cb;
150 void menu_romload_end(void)
152 PicoCartLoadProgressCB = NULL;
153 PicoCDLoadProgressCB = NULL;
156 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
157 "Starting emulation...", 0xffff);
161 // ------------ patch/gg menu ------------
163 static void draw_patchlist(int sel)
165 int max_cnt, start, i, pos, active;
167 max_cnt = g_menuscreen_h / me_sfont_h;
168 start = max_cnt / 2 - sel;
172 for (i = 0; i < PicoPatchCount; i++) {
174 if (pos < 0) continue;
175 if (pos >= max_cnt) break;
176 active = PicoPatches[i].active;
177 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
178 smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
182 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
184 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
188 static void menu_loop_patches(void)
190 static int menu_sel = 0;
195 draw_patchlist(menu_sel);
196 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK, 33);
197 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
198 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
199 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
200 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
201 if (inp & PBTN_MOK) { // action
202 if (menu_sel < PicoPatchCount)
203 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
206 if (inp & PBTN_MBACK)
211 // -------------- key config --------------
213 // PicoPad[] format: MXYZ SACB RLDU
214 me_bind_action me_ctrl_actions[] =
219 { "RIGHT ", 0x0008 },
223 { "A turbo", 0x4000 },
224 { "B turbo", 0x1000 },
225 { "C turbo", 0x2000 },
226 { "START ", 0x0080 },
234 me_bind_action emuctrl_actions[] =
236 { "Load State ", PEV_STATE_LOAD },
237 { "Save State ", PEV_STATE_SAVE },
238 { "Prev Save Slot ", PEV_SSLOT_PREV },
239 { "Next Save Slot ", PEV_SSLOT_NEXT },
240 { "Switch Renderer ", PEV_SWITCH_RND },
241 { "Volume Down ", PEV_VOL_DOWN },
242 { "Volume Up ", PEV_VOL_UP },
243 { "Fast forward ", PEV_FF },
244 { "Enter Menu ", PEV_MENU },
245 { "Pico Next page ", PEV_PICO_PNEXT },
246 { "Pico Prev page ", PEV_PICO_PPREV },
247 { "Pico Switch input", PEV_PICO_SWINP },
251 static int key_config_loop_wrap(int id, int keys)
254 case MA_CTRL_PLAYER1:
255 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
257 case MA_CTRL_PLAYER2:
258 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
261 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
269 static const char *mgn_dev_name(int id, int *offs)
271 const char *name = NULL;
274 if (id == MA_CTRL_DEV_FIRST)
277 for (; it < IN_MAX_DEVS; it++) {
278 name = in_get_dev_name(it, 1, 1);
287 static int mh_saveloadcfg(int id, int keys);
288 static const char *mgn_saveloadcfg(int id, int *offs);
290 static menu_entry e_menu_keyconfig[] =
292 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
293 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
294 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
295 mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),
296 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
297 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
298 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
299 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
301 mee_label ("Input devices:"),
302 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
303 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
304 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
305 mee_label_mk (MA_CTRL_DEV_NEXT, 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),
312 static int menu_loop_keyconfig(int id, int keys)
316 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded);
317 me_loop(e_menu_keyconfig, &sel);
321 // ------------ SCD options menu ------------
323 static const char *mgn_cdopt_ra(int id, int *offs)
326 if (PicoCDBuffers <= 0)
328 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
332 static int mh_cdopt_ra(int id, int keys)
334 if (keys & PBTN_LEFT) {
336 if (PicoCDBuffers < 2)
339 if (PicoCDBuffers <= 0)
342 if (PicoCDBuffers > 8*1024)
343 PicoCDBuffers = 8*1024; // 16M
348 static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
349 static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
350 static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
351 static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
352 "most games don't need this";
353 static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
354 "disable to improve performance";
355 static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
356 "disable to improve performance";
358 static menu_entry e_menu_cd_options[] =
360 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
361 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
362 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
363 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
364 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
365 mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
366 mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync),
370 static int menu_loop_cd_options(int id, int keys)
373 me_loop(e_menu_cd_options, &sel);
377 // ------------ 32X options menu ------------
381 // convert from multiplier of VClk
382 static int mh_opt_sh2cycles(int id, int keys)
384 int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier;
386 if (keys & (PBTN_LEFT|PBTN_RIGHT))
387 *mul += (keys & PBTN_LEFT) ? -10 : 10;
388 if (keys & (PBTN_L|PBTN_R))
389 *mul += (keys & PBTN_L) ? -100 : 100;
393 else if (*mul > (10 << SH2_MULTI_SHIFT))
394 *mul = 10 << SH2_MULTI_SHIFT;
399 static const char *mgn_opt_sh2cycles(int id, int *offs)
401 int mul = (id == MA_32XOPT_MSH2_CYCLES) ? p32x_msh2_multiplier : p32x_ssh2_multiplier;
403 sprintf(static_buff, "%d", 7670 * mul >> SH2_MULTI_SHIFT);
407 static const char h_32x_enable[] = "Enable emulation of the 32X addon";
408 static const char h_pwm[] = "Disabling may improve performance, but break sound";
409 static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
410 "lower values speed up emulation but break games\n"
411 "at least 11000 recommended for compatibility";
413 static menu_entry e_menu_32x_options[] =
415 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
416 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
417 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
418 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
419 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
423 static int menu_loop_32x_options(int id, int keys)
427 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
428 me_loop(e_menu_32x_options, &sel);
435 // ------------ adv options menu ------------
437 static menu_entry e_menu_adv_options[] =
439 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
440 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
441 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
442 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
443 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
444 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
445 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
446 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
447 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
452 static int menu_loop_adv_options(int id, int keys)
455 me_loop(e_menu_adv_options, &sel);
459 // ------------ gfx options menu ------------
461 static menu_entry e_menu_gfx_options[] =
463 mee_enum("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
468 static int menu_loop_gfx_options(int id, int keys)
472 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
473 me_loop(e_menu_gfx_options, &sel);
478 // ------------ options menu ------------
480 static menu_entry e_menu_options[];
482 static int sndrate_prevnext(int rate, int dir)
484 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
487 for (i = 0; i < 5; i++)
488 if (rates[i] == rate) break;
492 if (!(PicoOpt & POPT_EN_STEREO)) {
493 PicoOpt |= POPT_EN_STEREO;
499 if (PicoOpt & POPT_EN_STEREO) {
500 PicoOpt &= ~POPT_EN_STEREO;
508 static void region_prevnext(int right)
510 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
511 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
515 if (!PicoRegionOverride) {
516 for (i = 0; i < 6; i++)
517 if (rgn_orders[i] == PicoAutoRgnOrder) break;
518 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
519 else PicoRegionOverride=1;
522 PicoRegionOverride <<= 1;
523 if (PicoRegionOverride > 8)
524 PicoRegionOverride = 8;
526 if (!PicoRegionOverride) {
527 for (i = 0; i < 6; i++)
528 if (rgn_orders[i] == PicoAutoRgnOrder) break;
529 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
532 PicoRegionOverride >>= 1;
536 static int mh_opt_misc(int id, int keys)
539 case MA_OPT_SOUND_QUALITY:
540 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
543 region_prevnext(keys & PBTN_RIGHT);
551 static int mh_saveloadcfg(int id, int keys)
555 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
556 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
557 if (config_slot < 0) config_slot = 9;
558 else if (config_slot > 9) config_slot = 0;
559 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
565 case MA_OPT_SAVECFG_GAME:
566 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
567 me_update_msg("config saved");
569 me_update_msg("failed to write config");
572 ret = emu_read_config(rom_fname_loaded, 1);
573 if (!ret) ret = emu_read_config(NULL, 1);
574 if (ret) me_update_msg("config loaded");
575 else me_update_msg("failed to load config");
584 static int mh_restore_defaults(int id, int keys)
587 me_update_msg("defaults restored");
591 static const char *mgn_opt_fskip(int id, int *offs)
593 if (currentConfig.Frameskip < 0)
595 sprintf(static_buff, "%d", currentConfig.Frameskip);
599 static const char *mgn_opt_sound(int id, int *offs)
603 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
604 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
608 static const char *mgn_opt_region(int id, int *offs)
610 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
611 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
612 int code = PicoRegionOverride;
618 while ((code >>= 1)) i++;
623 strcpy(static_buff, "Auto:");
624 for (u = 0; u < 3; u++) {
625 code = (PicoAutoRgnOrder >> u*4) & 0xf;
626 for (i = 0; code; code >>= 1, i++)
628 strcat(static_buff, names_short[i]);
634 static const char *mgn_saveloadcfg(int id, int *offs)
637 if (config_slot != 0)
638 sprintf(static_buff, "[%i]", config_slot);
642 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
643 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
644 "loading state or both";
646 static menu_entry e_menu_options[] =
648 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
649 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
650 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
651 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
652 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
653 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
654 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
655 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 1200),
656 mee_handler ("[Display options]", menu_loop_gfx_options),
657 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
659 mee_handler ("[32X options]", menu_loop_32x_options),
661 mee_handler ("[Advanced options]", menu_loop_adv_options),
662 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
663 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
664 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
665 mee_handler ("Restore defaults", mh_restore_defaults),
669 static int menu_loop_options(int id, int keys)
674 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
675 e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;
676 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);
677 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
679 me_loop(e_menu_options, &sel);
684 // ------------ debug menu ------------
686 #include <pico/debug.h>
688 extern void SekStepM68k(void);
690 static void mplayer_loop(void)
697 if (in_menu_wait_any(0) & PBTN_MA3)
705 static void draw_text_debug(const char *str, int skip, int from)
713 while (*p && *p != '\n')
715 if (*p == 0 || p[1] == 0)
721 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
723 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
724 while (*p && *p != '\n')
733 #define COMPILER "gcc " __VERSION__
738 static void draw_frame_debug(void)
740 char layer_str[48] = "layers: ";
741 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
742 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
743 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
744 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
745 if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4);
747 pemu_forced_frame(1, 0);
748 memcpy(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
749 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
750 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
753 static void debug_menu_loop(void)
756 int spr_offs = 0, dumped = 0;
764 case 0: tmp = PDebugMain();
766 draw_text_debug(tmp, 0, 0);
768 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
769 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
773 case 1: draw_frame_debug();
775 case 2: pemu_forced_frame(1, 0);
776 menu_darken_bg(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 0);
777 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
778 g_menuscreen_w/2 - 320/2, g_menuscreen_w);
780 case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
781 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
782 PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
783 g_menuscreen_w, spr_offs);
784 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
786 case 4: tmp = PDebug32x();
787 draw_text_debug(tmp, 0, 0);
792 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
793 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
794 if (inp & PBTN_MBACK) return;
795 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
796 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
802 if (inp & PBTN_MA3) {
803 while (inp & PBTN_MA3)
804 inp = in_menu_wait_any(-1);
807 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
808 mkdir("dumps", 0777);
810 while (inp & PBTN_MA2) inp = in_menu_wait_any(-1);
815 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
816 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
817 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
818 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
819 if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON;
820 if (inp & PBTN_MOK) {
821 PsndOut = NULL; // just in case
825 while (inp & PBTN_MOK) inp = in_menu_wait_any(-1);
829 if (inp & PBTN_DOWN) spr_offs++;
830 if (inp & PBTN_UP) spr_offs--;
831 if (spr_offs < 0) spr_offs = 0;
837 // ------------ main menu ------------
839 static const char credits[] =
840 "PicoDrive v" VERSION " (c) notaz, 2006-2011\n\n\n"
842 "fDave: Cyclone 68000 core,\n"
843 " base code of PicoDrive\n"
844 "Reesy & FluBBa: DrZ80 core\n"
845 "MAME devs: YM2612 and SN76496 cores\n"
846 "Inder, ketchupgun: graphics\n"
848 "rlyeh and others: minimal SDK\n"
850 "Dzz: ARM940 sample\n"
853 "special thanks (for docs, ideas):\n"
854 " Charles MacDonald, Haze,\n"
855 " Stephane Dallongeville,\n"
856 " Lordus, Exophase, Rokas,\n"
857 " Nemesis, Tasco Deluxe";
859 static char *romsel_run(void)
861 char *ret, *sel_name;
863 sel_name = malloc(sizeof(rom_fname_loaded));
864 if (sel_name == NULL)
866 strcpy(sel_name, rom_fname_loaded);
868 ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));
873 static int main_menu_handler(int id, int keys)
879 case MA_MAIN_RESUME_GAME:
883 case MA_MAIN_SAVE_STATE:
885 return menu_loop_savestate(0);
887 case MA_MAIN_LOAD_STATE:
889 return menu_loop_savestate(1);
891 case MA_MAIN_RESET_GAME:
897 case MA_MAIN_LOAD_ROM:
898 ret_name = romsel_run();
899 if (ret_name != NULL) {
900 lprintf("selected file: %s\n", ret_name);
901 engineState = PGS_ReloadRom;
905 case MA_MAIN_CREDITS:
906 draw_menu_message(credits, NULL);
907 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
910 engineState = PGS_Quit;
912 case MA_MAIN_PATCHES:
913 if (rom_loaded && PicoPatches) {
916 me_update_msg("Patches applied");
920 lprintf("%s: something unknown selected\n", __FUNCTION__);
927 static menu_entry e_menu_main[] =
929 mee_label ("PicoDrive " VERSION),
933 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
934 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
935 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
936 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
937 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
938 mee_handler ("Change options", menu_loop_options),
939 mee_handler ("Configure controls", menu_loop_keyconfig),
940 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
941 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
942 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
950 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);
951 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, rom_loaded);
952 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, rom_loaded);
953 me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded);
954 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
956 menu_enter(rom_loaded);
957 in_set_config_int(0, IN_CFG_BLOCKING, 1);
958 me_loop_d(e_menu_main, &sel, NULL, menu_main_plat_draw);
961 if (engineState == PGS_Menu)
962 engineState = PGS_Running;
963 /* wait until menu, ok, back is released */
964 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
968 in_set_config_int(0, IN_CFG_BLOCKING, 0);
971 // --------- CD tray close menu ----------
973 static int mh_tray_load_cd(int id, int keys)
977 ret_name = romsel_run();
978 if (ret_name == NULL)
981 engineState = PGS_RestartRun;
982 return emu_swap_cd(ret_name);
985 static int mh_tray_nothing(int id, int keys)
990 static menu_entry e_menu_tray[] =
992 mee_label ("The CD tray has opened."),
995 mee_handler("Load CD image", mh_tray_load_cd),
996 mee_handler("Insert nothing", mh_tray_nothing),
1000 int menu_loop_tray(void)
1002 int ret = 1, sel = 0;
1004 menu_enter(rom_loaded);
1006 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1007 me_loop(e_menu_tray, &sel);
1009 if (engineState != PGS_RestartRun) {
1010 engineState = PGS_RestartRun;
1011 ret = 0; /* no CD inserted */
1014 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
1015 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1020 void me_update_msg(const char *msg)
1022 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1023 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1025 menu_error_time = plat_get_ticks_ms();
1026 lprintf("msg: %s\n", menu_error_msg);
1029 // ------------ util ------------
1031 /* hidden options for config engine only */
1032 static menu_entry e_menu_hidden[] =
1034 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
1038 static menu_entry *e_menu_table[] =
1051 static menu_entry *me_list_table = NULL;
1052 static menu_entry *me_list_i = NULL;
1054 menu_entry *me_list_get_first(void)
1056 me_list_table = me_list_i = e_menu_table[0];
1060 menu_entry *me_list_get_next(void)
1065 if (me_list_i->name != NULL)
1068 for (i = 0; i < array_size(e_menu_table); i++)
1069 if (me_list_table == e_menu_table[i])
1072 if (i + 1 < array_size(e_menu_table))
1073 me_list_table = me_list_i = e_menu_table[i + 1];
1075 me_list_table = me_list_i = NULL;