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
197 |PBTN_MOK|PBTN_MBACK, NULL, 33);
198 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
199 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
200 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
201 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
202 if (inp & PBTN_MOK) { // action
203 if (menu_sel < PicoPatchCount)
204 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
207 if (inp & PBTN_MBACK)
212 // -------------- key config --------------
214 // PicoPad[] format: MXYZ SACB RLDU
215 me_bind_action me_ctrl_actions[] =
220 { "RIGHT ", 0x0008 },
224 { "A turbo", 0x4000 },
225 { "B turbo", 0x1000 },
226 { "C turbo", 0x2000 },
227 { "START ", 0x0080 },
235 me_bind_action emuctrl_actions[] =
237 { "Load State ", PEV_STATE_LOAD },
238 { "Save State ", PEV_STATE_SAVE },
239 { "Prev Save Slot ", PEV_SSLOT_PREV },
240 { "Next Save Slot ", PEV_SSLOT_NEXT },
241 { "Switch Renderer ", PEV_SWITCH_RND },
242 { "Volume Down ", PEV_VOL_DOWN },
243 { "Volume Up ", PEV_VOL_UP },
244 { "Fast forward ", PEV_FF },
245 { "Enter Menu ", PEV_MENU },
246 { "Pico Next page ", PEV_PICO_PNEXT },
247 { "Pico Prev page ", PEV_PICO_PPREV },
248 { "Pico Switch input", PEV_PICO_SWINP },
252 static int key_config_loop_wrap(int id, int keys)
255 case MA_CTRL_PLAYER1:
256 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
258 case MA_CTRL_PLAYER2:
259 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
262 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
270 static const char *mgn_dev_name(int id, int *offs)
272 const char *name = NULL;
275 if (id == MA_CTRL_DEV_FIRST)
278 for (; it < IN_MAX_DEVS; it++) {
279 name = in_get_dev_name(it, 1, 1);
288 static int mh_saveloadcfg(int id, int keys);
289 static const char *mgn_saveloadcfg(int id, int *offs);
291 static menu_entry e_menu_keyconfig[] =
293 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
294 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
295 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
296 mee_onoff ("6 button pad", MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),
297 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
298 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
299 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
300 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
302 mee_label ("Input devices:"),
303 mee_label_mk (MA_CTRL_DEV_FIRST, 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),
309 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
313 static int menu_loop_keyconfig(int id, int keys)
317 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded);
318 me_loop(e_menu_keyconfig, &sel);
322 // ------------ SCD options menu ------------
324 static const char *mgn_cdopt_ra(int id, int *offs)
327 if (PicoCDBuffers <= 0)
329 sprintf(static_buff, "%5iK", PicoCDBuffers * 2);
333 static int mh_cdopt_ra(int id, int keys)
335 if (keys & PBTN_LEFT) {
337 if (PicoCDBuffers < 2)
340 if (PicoCDBuffers <= 0)
343 if (PicoCDBuffers > 8*1024)
344 PicoCDBuffers = 8*1024; // 16M
349 static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
350 static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
351 static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
352 static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
353 "most games don't need this";
354 static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
355 "disable to improve performance";
356 static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
357 "disable to improve performance";
359 static menu_entry e_menu_cd_options[] =
361 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
362 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
363 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
364 mee_cust ("ReadAhead buffer", MA_CDOPT_READAHEAD, mh_cdopt_ra, mgn_cdopt_ra),
365 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
366 mee_onoff_h("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
367 mee_onoff_h("Better sync (slow)", MA_CDOPT_BETTER_SYNC, PicoOpt, POPT_EN_MCD_PSYNC, h_bsync),
371 static int menu_loop_cd_options(int id, int keys)
374 me_loop(e_menu_cd_options, &sel);
378 // ------------ 32X options menu ------------
382 // convert from multiplier of VClk
383 static int mh_opt_sh2cycles(int id, int keys)
385 int *mul = (id == MA_32XOPT_MSH2_CYCLES) ? &p32x_msh2_multiplier : &p32x_ssh2_multiplier;
387 if (keys & (PBTN_LEFT|PBTN_RIGHT))
388 *mul += (keys & PBTN_LEFT) ? -10 : 10;
389 if (keys & (PBTN_L|PBTN_R))
390 *mul += (keys & PBTN_L) ? -100 : 100;
394 else if (*mul > (10 << SH2_MULTI_SHIFT))
395 *mul = 10 << SH2_MULTI_SHIFT;
400 static const char *mgn_opt_sh2cycles(int id, int *offs)
402 int mul = (id == MA_32XOPT_MSH2_CYCLES) ? p32x_msh2_multiplier : p32x_ssh2_multiplier;
404 sprintf(static_buff, "%d", 7670 * mul >> SH2_MULTI_SHIFT);
408 static const char h_32x_enable[] = "Enable emulation of the 32X addon";
409 static const char h_pwm[] = "Disabling may improve performance, but break sound";
410 static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
411 "lower values speed up emulation but break games\n"
412 "at least 11000 recommended for compatibility";
414 static menu_entry e_menu_32x_options[] =
416 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
417 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
418 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
419 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
420 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
424 static int menu_loop_32x_options(int id, int keys)
428 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
429 me_loop(e_menu_32x_options, &sel);
436 // ------------ adv options menu ------------
438 static menu_entry e_menu_adv_options[] =
440 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
441 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
442 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
443 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
444 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
445 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
446 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
447 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
448 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
453 static int menu_loop_adv_options(int id, int keys)
456 me_loop(e_menu_adv_options, &sel);
460 // ------------ gfx options menu ------------
462 static menu_entry e_menu_gfx_options[] =
464 mee_enum("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
469 static int menu_loop_gfx_options(int id, int keys)
473 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
474 me_loop(e_menu_gfx_options, &sel);
479 // ------------ options menu ------------
481 static menu_entry e_menu_options[];
483 static int sndrate_prevnext(int rate, int dir)
485 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
488 for (i = 0; i < 5; i++)
489 if (rates[i] == rate) break;
493 if (!(PicoOpt & POPT_EN_STEREO)) {
494 PicoOpt |= POPT_EN_STEREO;
500 if (PicoOpt & POPT_EN_STEREO) {
501 PicoOpt &= ~POPT_EN_STEREO;
509 static void region_prevnext(int right)
511 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
512 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
516 if (!PicoRegionOverride) {
517 for (i = 0; i < 6; i++)
518 if (rgn_orders[i] == PicoAutoRgnOrder) break;
519 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
520 else PicoRegionOverride=1;
523 PicoRegionOverride <<= 1;
524 if (PicoRegionOverride > 8)
525 PicoRegionOverride = 8;
527 if (!PicoRegionOverride) {
528 for (i = 0; i < 6; i++)
529 if (rgn_orders[i] == PicoAutoRgnOrder) break;
530 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
533 PicoRegionOverride >>= 1;
537 static int mh_opt_misc(int id, int keys)
540 case MA_OPT_SOUND_QUALITY:
541 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
544 region_prevnext(keys & PBTN_RIGHT);
552 static int mh_saveloadcfg(int id, int keys)
556 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
557 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
558 if (config_slot < 0) config_slot = 9;
559 else if (config_slot > 9) config_slot = 0;
560 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
566 case MA_OPT_SAVECFG_GAME:
567 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
568 me_update_msg("config saved");
570 me_update_msg("failed to write config");
573 ret = emu_read_config(rom_fname_loaded, 1);
574 if (!ret) ret = emu_read_config(NULL, 1);
575 if (ret) me_update_msg("config loaded");
576 else me_update_msg("failed to load config");
585 static int mh_restore_defaults(int id, int keys)
588 me_update_msg("defaults restored");
592 static const char *mgn_opt_fskip(int id, int *offs)
594 if (currentConfig.Frameskip < 0)
596 sprintf(static_buff, "%d", currentConfig.Frameskip);
600 static const char *mgn_opt_sound(int id, int *offs)
604 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
605 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
609 static const char *mgn_opt_region(int id, int *offs)
611 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
612 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
613 int code = PicoRegionOverride;
619 while ((code >>= 1)) i++;
624 strcpy(static_buff, "Auto:");
625 for (u = 0; u < 3; u++) {
626 code = (PicoAutoRgnOrder >> u*4) & 0xf;
627 for (i = 0; code; code >>= 1, i++)
629 strcat(static_buff, names_short[i]);
635 static const char *mgn_saveloadcfg(int id, int *offs)
638 if (config_slot != 0)
639 sprintf(static_buff, "[%i]", config_slot);
643 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
644 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
645 "loading state or both";
647 static menu_entry e_menu_options[] =
649 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
650 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
651 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
652 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
653 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
654 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
655 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
656 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 1200),
657 mee_handler ("[Display options]", menu_loop_gfx_options),
658 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
660 mee_handler ("[32X options]", menu_loop_32x_options),
662 mee_handler ("[Advanced options]", menu_loop_adv_options),
663 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
664 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
665 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
666 mee_handler ("Restore defaults", mh_restore_defaults),
670 static int menu_loop_options(int id, int keys)
675 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
676 e_menu_options[i].enabled = e_menu_options[i].name[0] ? 1 : 0;
677 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);
678 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
680 me_loop(e_menu_options, &sel);
685 // ------------ debug menu ------------
687 #include <pico/debug.h>
689 extern void SekStepM68k(void);
691 static void mplayer_loop(void)
698 if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
706 static void draw_text_debug(const char *str, int skip, int from)
714 while (*p && *p != '\n')
716 if (*p == 0 || p[1] == 0)
722 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
724 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
725 while (*p && *p != '\n')
734 #define COMPILER "gcc " __VERSION__
739 static void draw_frame_debug(void)
741 char layer_str[48] = "layers: ";
742 if (PicoDrawMask & PDRAW_LAYERB_ON) memcpy(layer_str + 8, "B", 1);
743 if (PicoDrawMask & PDRAW_LAYERA_ON) memcpy(layer_str + 10, "A", 1);
744 if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);
745 if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6);
746 if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4);
748 pemu_forced_frame(1, 0);
749 memcpy(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
750 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
751 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
754 static void debug_menu_loop(void)
757 int spr_offs = 0, dumped = 0;
765 case 0: tmp = PDebugMain();
767 draw_text_debug(tmp, 0, 0);
769 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
770 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
774 case 1: draw_frame_debug();
776 case 2: pemu_forced_frame(1, 0);
777 menu_darken_bg(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h, 0);
778 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
779 g_menuscreen_w/2 - 320/2, g_menuscreen_w);
781 case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
782 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
783 PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
784 g_menuscreen_w, spr_offs);
785 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
787 case 4: tmp = PDebug32x();
788 draw_text_debug(tmp, 0, 0);
793 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
794 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
795 if (inp & PBTN_MBACK) return;
796 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
797 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
803 if (inp & PBTN_MA3) {
804 while (inp & PBTN_MA3)
805 inp = in_menu_wait_any(NULL, -1);
808 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
809 mkdir("dumps", 0777);
811 while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
816 if (inp & PBTN_LEFT) PicoDrawMask ^= PDRAW_LAYERB_ON;
817 if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;
818 if (inp & PBTN_DOWN) PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;
819 if (inp & PBTN_UP) PicoDrawMask ^= PDRAW_SPRITES_HI_ON;
820 if (inp & PBTN_MA2) PicoDrawMask ^= PDRAW_32X_ON;
821 if (inp & PBTN_MOK) {
822 PsndOut = NULL; // just in case
826 while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
830 if (inp & PBTN_DOWN) spr_offs++;
831 if (inp & PBTN_UP) spr_offs--;
832 if (spr_offs < 0) spr_offs = 0;
838 // ------------ main menu ------------
840 static const char credits[] =
841 "PicoDrive v" VERSION " (c) notaz, 2006-2011\n\n\n"
843 "fDave: Cyclone 68000 core,\n"
844 " base code of PicoDrive\n"
845 "Reesy & FluBBa: DrZ80 core\n"
846 "MAME devs: YM2612 and SN76496 cores\n"
847 "Inder, ketchupgun: graphics\n"
849 "rlyeh and others: minimal SDK\n"
851 "Dzz: ARM940 sample\n"
854 "special thanks (for docs, ideas):\n"
855 " Charles MacDonald, Haze,\n"
856 " Stephane Dallongeville,\n"
857 " Lordus, Exophase, Rokas,\n"
858 " Nemesis, Tasco Deluxe";
860 static char *romsel_run(void)
862 char *ret, *sel_name;
864 sel_name = malloc(sizeof(rom_fname_loaded));
865 if (sel_name == NULL)
867 strcpy(sel_name, rom_fname_loaded);
869 ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));
874 static int main_menu_handler(int id, int keys)
880 case MA_MAIN_RESUME_GAME:
884 case MA_MAIN_SAVE_STATE:
886 return menu_loop_savestate(0);
888 case MA_MAIN_LOAD_STATE:
890 return menu_loop_savestate(1);
892 case MA_MAIN_RESET_GAME:
898 case MA_MAIN_LOAD_ROM:
899 ret_name = romsel_run();
900 if (ret_name != NULL) {
901 lprintf("selected file: %s\n", ret_name);
902 engineState = PGS_ReloadRom;
906 case MA_MAIN_CREDITS:
907 draw_menu_message(credits, NULL);
908 in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
911 engineState = PGS_Quit;
913 case MA_MAIN_PATCHES:
914 if (rom_loaded && PicoPatches) {
917 me_update_msg("Patches applied");
921 lprintf("%s: something unknown selected\n", __FUNCTION__);
928 static menu_entry e_menu_main[] =
930 mee_label ("PicoDrive " VERSION),
934 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
935 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
936 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
937 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
938 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
939 mee_handler ("Change options", menu_loop_options),
940 mee_handler ("Configure controls", menu_loop_keyconfig),
941 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
942 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
943 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
951 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);
952 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, rom_loaded);
953 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, rom_loaded);
954 me_enable(e_menu_main, MA_MAIN_RESET_GAME, rom_loaded);
955 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
957 menu_enter(rom_loaded);
958 in_set_config_int(0, IN_CFG_BLOCKING, 1);
959 me_loop_d(e_menu_main, &sel, NULL, menu_main_plat_draw);
962 if (engineState == PGS_Menu)
963 engineState = PGS_Running;
964 /* wait until menu, ok, back is released */
965 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
969 in_set_config_int(0, IN_CFG_BLOCKING, 0);
972 // --------- CD tray close menu ----------
974 static int mh_tray_load_cd(int id, int keys)
978 ret_name = romsel_run();
979 if (ret_name == NULL)
982 engineState = PGS_RestartRun;
983 return emu_swap_cd(ret_name);
986 static int mh_tray_nothing(int id, int keys)
991 static menu_entry e_menu_tray[] =
993 mee_label ("The CD tray has opened."),
996 mee_handler("Load CD image", mh_tray_load_cd),
997 mee_handler("Insert nothing", mh_tray_nothing),
1001 int menu_loop_tray(void)
1003 int ret = 1, sel = 0;
1005 menu_enter(rom_loaded);
1007 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1008 me_loop(e_menu_tray, &sel);
1010 if (engineState != PGS_RestartRun) {
1011 engineState = PGS_RestartRun;
1012 ret = 0; /* no CD inserted */
1015 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
1016 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1021 void me_update_msg(const char *msg)
1023 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1024 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1026 menu_error_time = plat_get_ticks_ms();
1027 lprintf("msg: %s\n", menu_error_msg);
1030 // ------------ util ------------
1032 /* hidden options for config engine only */
1033 static menu_entry e_menu_hidden[] =
1035 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
1039 static menu_entry *e_menu_table[] =
1052 static menu_entry *me_list_table = NULL;
1053 static menu_entry *me_list_i = NULL;
1055 menu_entry *me_list_get_first(void)
1057 me_list_table = me_list_i = e_menu_table[0];
1061 menu_entry *me_list_get_next(void)
1066 if (me_list_i->name != NULL)
1069 for (i = 0; i < array_size(e_menu_table); i++)
1070 if (me_list_table == e_menu_table[i])
1073 if (i + 1 < array_size(e_menu_table))
1074 me_list_table = me_list_i = e_menu_table[i + 1];
1076 me_list_table = me_list_i = NULL;