2 * (C) GraÅžvydas "notaz" Ignotas, 2010
4 * This work is licensed under the terms of any of these licenses
6 * - GNU GPL, version 2 or later.
7 * - GNU LGPL, version 2.1 or later.
8 * See the COPYING file in the top-level directory.
17 #include "plugin_lib.h"
19 #include "common/plat.h"
20 #include "../gui/Linux.h"
21 #include "../libpcsxcore/misc.h"
22 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
26 #define array_size(x) (sizeof(x) / sizeof(x[0]))
58 extern int ready_to_go;
59 static int game_config_loaded;
60 static int last_psx_w, last_psx_h, last_psx_bpp;
61 static int scaling, filter, state_slot, cpu_clock;
62 static char rom_fname_reload[MAXPATHLEN];
63 static char last_selected_fname[MAXPATHLEN];
66 // from softgpu plugin
67 extern int iUseDither;
68 extern int UseFrameSkip;
69 extern uint32_t dwActFixes;
72 extern int iUseReverb;
73 extern int iUseInterpolation;
75 extern int iSPUIRQWait;
79 static int min(int x, int y) { return x < y ? x : y; }
80 static int max(int x, int y) { return x > y ? x : y; }
82 void emu_make_path(char *buff, const char *end, int size)
86 end_len = strlen(end);
87 pos = plat_get_root_dir(buff, size);
88 strncpy(buff + pos, end, size - pos);
90 if (pos + end_len > size - 1)
91 printf("Warning: path truncated: %s\n", buff);
94 static int emu_check_save_file(int slot)
99 fname = get_state_filename(slot);
103 ret = CheckState(fname);
105 return ret == 0 ? 1 : 0;
108 static int emu_save_load_game(int load, int sram)
113 fname = get_state_filename(state_slot);
118 ret = LoadState(fname);
120 ret = SaveState(fname);
126 static void draw_savestate_bg(int slot)
130 static void menu_set_defconfig(void)
134 Config.Xa = Config.Cdda = Config.Sio =
135 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
137 iUseDither = UseFrameSkip = 0;
141 iUseInterpolation = 1;
142 iXAPitch = iSPUIRQWait = 0;
146 #define CE_CONFIG_STR(val) \
147 { #val, 0, Config.val }
149 #define CE_CONFIG_VAL(val) \
150 { #val, sizeof(Config.val), &Config.val }
152 #define CE_STR(val) \
155 #define CE_INTVAL(val) \
156 { #val, sizeof(val), &val }
158 static const struct {
170 CE_CONFIG_VAL(PsxAuto),
172 CE_CONFIG_VAL(Debug),
173 CE_CONFIG_VAL(PsxOut),
174 CE_CONFIG_VAL(SpuIrq),
175 CE_CONFIG_VAL(RCntFix),
176 CE_CONFIG_VAL(VSyncWA),
178 CE_CONFIG_VAL(PsxType),
181 CE_INTVAL(state_slot),
182 CE_INTVAL(cpu_clock),
184 CE_INTVAL(iUseDither),
185 CE_INTVAL(UseFrameSkip),
186 CE_INTVAL(dwActFixes),
187 CE_INTVAL(iUseReverb),
188 CE_INTVAL(iUseInterpolation),
190 CE_INTVAL(iSPUIRQWait),
191 CE_INTVAL(iUseTimer),
194 static int menu_write_config(int is_game)
196 char cfgfile[MAXPATHLEN];
203 snprintf(cfgfile, sizeof(cfgfile), "." PCSX_DOT_DIR "%s", cfgfile_basename);
204 f = fopen(cfgfile, "w");
206 printf("failed to open: %s\n", cfgfile);
210 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
211 fprintf(f, "%s = ", config_data[i].name);
212 switch (config_data[i].len) {
214 fprintf(f, "%s\n", (char *)config_data[i].val);
217 fprintf(f, "%x\n", *(u8 *)config_data[i].val);
220 fprintf(f, "%x\n", *(u16 *)config_data[i].val);
223 fprintf(f, "%x\n", *(u32 *)config_data[i].val);
226 printf("menu_write_config: unhandled len %d for %s\n",
227 config_data[i].len, config_data[i].name);
233 fprintf(f, "lastcdimg = %s\n", last_selected_fname);
239 static void parse_str_val(char *cval, const char *src)
242 strncpy(cval, src, MAXPATHLEN);
243 cval[MAXPATHLEN - 1] = 0;
244 tmp = strchr(cval, '\n');
246 tmp = strchr(cval, '\r');
251 static int menu_load_config(int is_game)
253 char cfgfile[MAXPATHLEN];
262 snprintf(cfgfile, sizeof(cfgfile), "." PCSX_DOT_DIR "%s", cfgfile_basename);
263 f = fopen(cfgfile, "r");
265 printf("failed to open: %s\n", cfgfile);
269 fseek(f, 0, SEEK_END);
272 printf("bad size %ld: %s\n", size, cfgfile);
276 cfg = malloc(size + 1);
280 fseek(f, 0, SEEK_SET);
281 if (fread(cfg, 1, size, f) != size) {
282 printf("failed to read: %s\n", cfgfile);
287 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
291 tmp = strstr(cfg, config_data[i].name);
294 tmp += strlen(config_data[i].name);
295 if (strncmp(tmp, " = ", 3) != 0)
299 if (config_data[i].len == 0) {
300 parse_str_val(config_data[i].val, tmp);
305 val = strtoul(tmp, &tmp2, 16);
306 if (tmp2 == NULL || tmp == tmp2)
307 continue; // parse failed
309 switch (config_data[i].len) {
311 *(u8 *)config_data[i].val = val;
314 *(u16 *)config_data[i].val = val;
317 *(u32 *)config_data[i].val = val;
320 printf("menu_load_config: unhandled len %d for %s\n",
321 config_data[i].len, config_data[i].name);
327 char *tmp = strstr(cfg, "lastcdimg = ");
330 parse_str_val(last_selected_fname, tmp);
341 // rrrr rggg gggb bbbb
342 static unsigned short fname2color(const char *fname)
344 static const char *cdimg_exts[] = { ".bin", ".img", ".iso", ".z", ".cue" };
345 static const char *other_exts[] = { ".ccd", ".toc", ".mds", ".sub", ".table" };
346 const char *ext = strrchr(fname, '.');
351 for (i = 0; i < array_size(cdimg_exts); i++)
352 if (strcasecmp(ext, cdimg_exts[i]) == 0)
354 for (i = 0; i < array_size(other_exts); i++)
355 if (strcasecmp(ext, other_exts[i]) == 0)
360 #define MENU_ALIGN_LEFT
361 #define menu_init menu_init_common
362 #include "common/menu.c"
365 // ---------- pandora specific -----------
367 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
368 static char **pnd_filter_list;
370 static int get_cpu_clock(void)
374 f = fopen("/proc/pandora/cpu_mhz_max", "r");
376 fscanf(f, "%d", &ret);
382 static void apply_cpu_clock(void)
386 if (cpu_clock != 0 && cpu_clock != get_cpu_clock()) {
387 snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
388 pnd_script_base, cpu_clock);
393 static void apply_filter(int which)
399 if (pnd_filter_list == NULL || which == old)
402 for (i = 0; i < which; i++)
403 if (pnd_filter_list[i] == NULL)
406 if (pnd_filter_list[i] == NULL)
409 snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]);
414 static menu_entry e_menu_gfx_options[];
416 static void pnd_menu_init(void)
424 cpu_clock = get_cpu_clock();
426 dir = opendir("/etc/pandora/conf/dss_fir");
428 perror("filter opendir");
440 p = strstr(ent->d_name, "_up");
441 if (p != NULL && (p[3] == 0 || !strcmp(p + 3, "_h")))
448 mfilters = calloc(count + 1, sizeof(mfilters[0]));
449 if (mfilters == NULL)
453 for (i = 0; (ent = readdir(dir)); ) {
456 p = strstr(ent->d_name, "_up");
457 if (p == NULL || (p[3] != 0 && strcmp(p + 3, "_h")))
460 len = p - ent->d_name;
461 if (len > sizeof(buff) - 1)
464 strncpy(buff, ent->d_name, len);
466 mfilters[i] = strdup(buff);
467 if (mfilters[i] != NULL)
472 i = me_id2offset(e_menu_gfx_options, MA_OPT_FILTERING);
473 e_menu_gfx_options[i].data = (void *)mfilters;
474 pnd_filter_list = mfilters;
477 // -------------- key config --------------
479 me_bind_action me_ctrl_actions[] =
481 { "UP ", 1 << DKEY_UP},
482 { "DOWN ", 1 << DKEY_DOWN },
483 { "LEFT ", 1 << DKEY_LEFT },
484 { "RIGHT ", 1 << DKEY_RIGHT },
485 { "TRIANGLE", 1 << DKEY_TRIANGLE },
486 { "CIRCLE ", 1 << DKEY_SQUARE },
487 { "CROSS ", 1 << DKEY_CROSS },
488 { "SQUARE ", 1 << DKEY_SQUARE },
489 { "L1 ", 1 << DKEY_L1 },
490 { "R1 ", 1 << DKEY_R1 },
491 { "L2 ", 1 << DKEY_L2 },
492 { "R2 ", 1 << DKEY_R2 },
493 { "START ", 1 << DKEY_START },
494 { "SELECT ", 1 << DKEY_SELECT },
498 me_bind_action emuctrl_actions[] =
501 { "Load State ", PEV_STATE_LOAD },
502 { "Save State ", PEV_STATE_SAVE },
503 { "Prev Save Slot ", PEV_SSLOT_PREV },
504 { "Next Save Slot ", PEV_SSLOT_NEXT },
506 { "Enter Menu ", PEV_MENU },
510 static int key_config_loop_wrap(int id, int keys)
513 case MA_CTRL_PLAYER1:
514 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
516 case MA_CTRL_PLAYER2:
517 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
520 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
528 static const char *mgn_dev_name(int id, int *offs)
530 const char *name = NULL;
533 if (id == MA_CTRL_DEV_FIRST)
536 for (; it < IN_MAX_DEVS; it++) {
537 name = in_get_dev_name(it, 1, 1);
546 static const char *mgn_saveloadcfg(int id, int *offs)
551 static int mh_saveloadcfg(int id, int keys)
555 case MA_OPT_SAVECFG_GAME:
556 if (menu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0) == 0)
557 me_update_msg("config saved");
559 me_update_msg("failed to write config");
568 static menu_entry e_menu_keyconfig[] =
570 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
571 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
572 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
573 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
574 // mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
576 mee_label ("Input devices:"),
577 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
578 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
579 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
580 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
581 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
582 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
583 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
587 static int menu_loop_keyconfig(int id, int keys)
591 // me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, ready_to_go);
592 me_loop(e_menu_keyconfig, &sel, NULL);
596 // ------------ gfx options menu ------------
598 static const char *men_scaler[] = { "1x1", "scaled 4:3", "fullscreen", "custom", NULL };
599 static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n"
600 "using d-pad or move it using R+d-pad";
601 static const char *men_dummy[] = { NULL };
603 static int menu_loop_cscaler(int id, int keys)
607 scaling = SCALE_CUSTOM;
609 omap_enable_layer(1);
610 //pnd_restore_layer_data();
615 memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
616 text_out16(2, 480 - 18, "%dx%d | d-pad to resize, R+d-pad to move", g_layer_w, g_layer_h);
619 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40);
620 if (inp & PBTN_UP) g_layer_y--;
621 if (inp & PBTN_DOWN) g_layer_y++;
622 if (inp & PBTN_LEFT) g_layer_x--;
623 if (inp & PBTN_RIGHT) g_layer_x++;
624 if (!(inp & PBTN_R)) {
625 if (inp & PBTN_UP) g_layer_h += 2;
626 if (inp & PBTN_DOWN) g_layer_h -= 2;
627 if (inp & PBTN_LEFT) g_layer_w += 2;
628 if (inp & PBTN_RIGHT) g_layer_w -= 2;
630 if (inp & (PBTN_MOK|PBTN_MBACK))
633 if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
634 if (g_layer_x < 0) g_layer_x = 0;
635 if (g_layer_x > 640) g_layer_x = 640;
636 if (g_layer_y < 0) g_layer_y = 0;
637 if (g_layer_y > 420) g_layer_y = 420;
638 if (g_layer_w < 160) g_layer_w = 160;
639 if (g_layer_h < 60) g_layer_h = 60;
640 if (g_layer_x + g_layer_w > 800)
641 g_layer_w = 800 - g_layer_x;
642 if (g_layer_y + g_layer_h > 480)
643 g_layer_h = 480 - g_layer_y;
644 omap_enable_layer(1);
648 omap_enable_layer(0);
653 static menu_entry e_menu_gfx_options[] =
655 mee_enum ("Scaler", 0, scaling, men_scaler),
656 mee_enum ("Filter", MA_OPT_FILTERING, filter, men_dummy),
657 // mee_onoff ("Vsync", 0, vsync, 1),
658 mee_cust_h ("Setup custom scaler", 0, menu_loop_cscaler, NULL, h_cscaler),
662 static int menu_loop_gfx_options(int id, int keys)
666 me_loop(e_menu_gfx_options, &sel, NULL);
671 // ------------ bios/plugins ------------
673 static const char *men_gpu_dithering[] = { "None", "Game dependant", "Always", NULL };
674 static const char h_gpu[] = "Configure built-in P.E.Op.S. SoftGL Driver V1.17\n"
675 "Coded by Pete Bernert and the P.E.Op.S. team";
676 static const char h_gpu_0[] = "Needed for Chrono Cross";
677 static const char h_gpu_1[] = "Capcom fighting games";
678 static const char h_gpu_2[] = "Black screens in Lunar";
679 static const char h_gpu_3[] = "Compatibility mode";
680 static const char h_gpu_6[] = "Pandemonium 2";
681 static const char h_gpu_7[] = "Skip every second frame";
682 static const char h_gpu_8[] = "Needed by Dark Forces";
683 static const char h_gpu_9[] = "better g-colors, worse textures";
684 static const char h_gpu_10[] = "Toggle busy flags after drawing";
686 static menu_entry e_menu_plugin_gpu[] =
688 mee_enum ("Dithering", 0, iUseDither, men_gpu_dithering),
689 mee_onoff_h ("Odd/even bit hack", 0, dwActFixes, 1<<0, h_gpu_0),
690 mee_onoff_h ("Expand screen width", 0, dwActFixes, 1<<1, h_gpu_1),
691 mee_onoff_h ("Ignore brightness color", 0, dwActFixes, 1<<2, h_gpu_2),
692 mee_onoff_h ("Disable coordinate check", 0, dwActFixes, 1<<3, h_gpu_3),
693 mee_onoff_h ("Lazy screen update", 0, dwActFixes, 1<<6, h_gpu_6),
694 mee_onoff_h ("Old frame skipping", 0, dwActFixes, 1<<7, h_gpu_7),
695 mee_onoff_h ("Repeated flat tex triangles ",0,dwActFixes, 1<<8, h_gpu_8),
696 mee_onoff_h ("Draw quads with triangles", 0, dwActFixes, 1<<9, h_gpu_9),
697 mee_onoff_h ("Fake 'gpu busy' states", 0, dwActFixes, 1<<10, h_gpu_10),
701 static int menu_loop_plugin_gpu(int id, int keys)
704 me_loop(e_menu_plugin_gpu, &sel, NULL);
708 static const char *men_spu_reverb[] = { "Off", "Fake", "On", NULL };
709 static const char *men_spu_interp[] = { "None", "Simple", "Gaussian", "Cubic", NULL };
710 static const char h_spu[] = "Configure built-in P.E.Op.S. Sound Driver V1.7\n"
711 "Coded by Pete Bernert and the P.E.Op.S. team";
712 static const char h_spu_irq_wait[] = "Wait for CPU; only useful for some games, may cause glitches";
713 static const char h_spu_thread[] = "Run sound emulation in separate thread";
715 static menu_entry e_menu_plugin_spu[] =
717 mee_enum ("Reverb", 0, iUseReverb, men_spu_reverb),
718 mee_enum ("Interpolation", 0, iUseInterpolation, men_spu_interp),
719 mee_onoff ("Adjust XA pitch", 0, iXAPitch, 1),
720 mee_onoff_h ("SPU IRQ Wait", 0, iSPUIRQWait, 1, h_spu_irq_wait),
721 mee_onoff_h ("Use sound thread", 0, iUseTimer, 1, h_spu_thread),
725 static int menu_loop_plugin_spu(int id, int keys)
728 me_loop(e_menu_plugin_spu, &sel, NULL);
732 static menu_entry e_menu_plugin_options[] =
734 mee_handler_h ("Configure built-in GPU plugin", menu_loop_plugin_gpu, h_gpu),
735 mee_handler_h ("Configure built-in SPU plugin", menu_loop_plugin_spu, h_spu),
739 static int menu_loop_plugin_options(int id, int keys)
742 me_loop(e_menu_plugin_options, &sel, NULL);
746 // ------------ adv options menu ------------
748 static const char h_cfg_xa[] = "Disables XA sound, which can sometimes improve performance";
749 static const char h_cfg_cdda[] = "Disable CD Audio for a performance boost\n"
750 "(proper .cue/.bin dump is needed otherwise)";
751 static const char h_cfg_sio[] = "This should be enabled for certain memcards/gamepads";
752 static const char h_cfg_spuirq[] = "Compatibility tweak; should probably be left off";
753 static const char h_cfg_rcnt1[] = "Parasite Eve 2, Vandal Hearts 1/2 Fix";
754 static const char h_cfg_rcnt2[] = "InuYasha Sengoku Battle Fix";
756 static menu_entry e_menu_adv_options[] =
758 mee_onoff ("Show CPU load", 0, g_opts, OPT_SHOWCPU),
759 mee_onoff_h ("Disable XA Decoding", 0, Config.Xa, 1, h_cfg_xa),
760 mee_onoff_h ("Disable CD Audio", 0, Config.Cdda, 1, h_cfg_cdda),
761 mee_onoff_h ("SIO IRQ Always Enabled", 0, Config.Sio, 1, h_cfg_sio),
762 mee_onoff_h ("SPU IRQ Always Enabled", 0, Config.SpuIrq, 1, h_cfg_spuirq),
763 mee_onoff_h ("Rootcounter hack", 0, Config.RCntFix, 1, h_cfg_rcnt1),
764 mee_onoff_h ("Rootcounter hack 2", 0, Config.VSyncWA, 1, h_cfg_rcnt2),
768 static int menu_loop_adv_options(int id, int keys)
771 me_loop(e_menu_adv_options, &sel, NULL);
775 // ------------ options menu ------------
777 static int mh_restore_defaults(int id, int keys)
779 menu_set_defconfig();
780 me_update_msg("defaults restored");
784 static const char *men_region[] = { "NTSC", "PAL", NULL };
786 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
787 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
788 "loading state or both";
790 static const char h_restore_def[] = "Switches back to default / recommended\n"
793 static menu_entry e_menu_options[] =
795 // mee_range ("Save slot", 0, state_slot, 0, 9),
796 // mee_enum_h ("Confirm savestate", 0, dummy, men_confirm_save, h_confirm_save),
797 mee_onoff ("Frameskip", 0, UseFrameSkip, 1),
798 mee_onoff ("Show FPS", 0, g_opts, OPT_SHOWFPS),
799 mee_enum ("Region", 0, Config.PsxType, men_region),
800 mee_range ("CPU clock", MA_OPT_CPU_CLOCKS, cpu_clock, 20, 5000),
801 mee_handler ("[Display]", menu_loop_gfx_options),
802 mee_handler ("[BIOS/Plugins]", menu_loop_plugin_options),
803 mee_handler ("[Advanced]", menu_loop_adv_options),
804 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
805 // mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
806 mee_handler_h ("Restore default config", mh_restore_defaults, h_restore_def),
810 static int menu_loop_options(int id, int keys)
815 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
816 e_menu_options[i].enabled = cpu_clock != 0 ? 1 : 0;
817 // me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, ready_to_go);
819 me_loop(e_menu_options, &sel, NULL);
824 // ------------ debug menu ------------
826 static void draw_frame_debug(void)
828 smalltext_out16(4, 1, "build: "__DATE__ " " __TIME__ " " REV, 0xe7fc);
831 static void debug_menu_loop(void)
841 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
842 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
843 if (inp & PBTN_MBACK)
848 // ------------ main menu ------------
852 const char *plat_get_credits(void)
854 return "PCSX-ReARMed\n\n"
855 "(C) 1999-2003 PCSX Team\n"
856 "(C) 2005-2009 PCSX-df Team\n"
857 "(C) 2009-2010 PCSX-Reloaded Team\n\n"
858 "GPU and SPU code by Pete Bernert\n"
859 " and the P.E.Op.S. team\n"
860 "ARM recompiler (C) 2009-2010 Ari64\n\n"
861 "integration, optimization and\n"
862 " frontend (C) 2010 notaz\n";
865 static char *romsel_run(void)
867 extern void set_cd_image(const char *fname);
870 ret = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
874 lprintf("selected file: %s\n", ret);
880 if (OpenPlugins() == -1) {
881 me_update_msg("failed to open plugins");
887 if (CheckCdrom() == -1) {
888 // Only check the CD if we are starting the console with a CD
890 me_update_msg("unsupported/invalid CD image");
894 // Read main executable directly from CDRom and start it
895 if (LoadCdrom() == -1) {
897 me_update_msg("failed to load CD image");
901 strcpy(last_selected_fname, rom_fname_reload);
902 game_config_loaded = 0;
907 static int main_menu_handler(int id, int keys)
913 case MA_MAIN_RESUME_GAME:
917 case MA_MAIN_SAVE_STATE:
919 return menu_loop_savestate(0);
921 case MA_MAIN_LOAD_STATE:
923 return menu_loop_savestate(1);
925 case MA_MAIN_RESET_GAME:
929 if (CheckCdrom() != -1) {
935 case MA_MAIN_LOAD_ROM:
936 ret_name = romsel_run();
937 if (ret_name != NULL)
940 case MA_MAIN_CREDITS:
941 draw_menu_credits(draw_frame_debug);
942 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
948 lprintf("%s: something unknown selected\n", __FUNCTION__);
955 static menu_entry e_menu_main[] =
959 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
960 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
961 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
962 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
963 mee_handler_id("Load CD image", MA_MAIN_LOAD_ROM, main_menu_handler),
964 mee_handler ("Options", menu_loop_options),
965 mee_handler ("Controls", menu_loop_keyconfig),
966 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
967 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
971 // ----------------------------
973 static void menu_leave_emu(void);
981 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, ready_to_go);
982 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, ready_to_go);
983 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, ready_to_go);
984 me_enable(e_menu_main, MA_MAIN_RESET_GAME, ready_to_go);
986 // menu_enter(ready_to_go);
987 in_set_config_int(0, IN_CFG_BLOCKING, 1);
990 me_loop(e_menu_main, &sel, NULL);
991 } while (!ready_to_go);
993 /* wait until menu, ok, back is released */
994 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
997 in_set_config_int(0, IN_CFG_BLOCKING, 0);
999 memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
1004 void menu_init(void)
1006 char buff[MAXPATHLEN];
1008 strcpy(last_selected_fname, "/media");
1013 menu_set_defconfig();
1014 menu_load_config(0);
1019 g_menubg_src_ptr = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
1020 if (g_menubg_src_ptr == NULL)
1022 emu_make_path(buff, "skin/background.png", sizeof(buff));
1023 readpng(g_menubg_src_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h);
1026 void menu_notify_mode_change(int w, int h, int bpp)
1032 if (scaling == SCALE_1_1) {
1033 g_layer_x = 800/2 - w/2; g_layer_y = 480/2 - h/2;
1034 g_layer_w = w; g_layer_h = h;
1035 omap_enable_layer(1);
1039 static void menu_leave_emu(void)
1041 omap_enable_layer(0);
1043 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
1044 if (ready_to_go && last_psx_bpp == 16) {
1045 int x = max(0, g_menuscreen_w - last_psx_w);
1046 int y = max(0, g_menuscreen_h / 2 - last_psx_h / 2);
1047 int w = min(g_menuscreen_w, last_psx_w);
1048 int h = min(g_menuscreen_h, last_psx_h);
1049 u16 *d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
1050 u16 *s = pl_fbdev_buf;
1052 for (; h > 0; h--, d += g_menuscreen_w, s += last_psx_w)
1053 menu_darken_bg(d, s, w, 0);
1057 void menu_prepare_emu(void)
1059 if (!game_config_loaded) {
1060 menu_set_defconfig();
1061 menu_load_config(1);
1062 game_config_loaded = 1;
1067 menu_notify_mode_change(last_psx_w, last_psx_h, last_psx_bpp);
1070 g_layer_x = 80; g_layer_y = 0;
1071 g_layer_w = 640; g_layer_h = 480;
1073 case SCALE_FULLSCREEN:
1074 g_layer_x = 0; g_layer_y = 0;
1075 g_layer_w = 800; g_layer_h = 480;
1080 omap_enable_layer(1);
1081 apply_filter(filter);
1085 // core doesn't care about Config.Cdda changes,
1086 // so handle them manually here
1091 void me_update_msg(const char *msg)
1093 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1094 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1096 menu_error_time = plat_get_ticks_ms();
1097 lprintf("msg: %s\n", menu_error_msg);