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),
180 CE_INTVAL(g_layer_x),
181 CE_INTVAL(g_layer_y),
182 CE_INTVAL(g_layer_w),
183 CE_INTVAL(g_layer_h),
185 CE_INTVAL(state_slot),
186 CE_INTVAL(cpu_clock),
188 CE_INTVAL(iUseDither),
189 CE_INTVAL(UseFrameSkip),
190 CE_INTVAL(dwActFixes),
191 CE_INTVAL(iUseReverb),
192 CE_INTVAL(iUseInterpolation),
194 CE_INTVAL(iSPUIRQWait),
195 CE_INTVAL(iUseTimer),
198 static void make_cfg_fname(char *buf, size_t size, int is_game)
203 strncpy(trimlabel, CdromLabel, 32);
205 for (j = 31; j >= 0; j--)
206 if (trimlabel[j] == ' ')
210 snprintf(cfgfile, sizeof(cfgfile), "." PCSX_DOT_DIR "cfg/%.32s-%.9s.cfg", trimlabel, CdromId);
212 snprintf(cfgfile, sizeof(cfgfile), "." PCSX_DOT_DIR "%s", cfgfile_basename);
215 static int menu_write_config(int is_game)
217 char cfgfile[MAXPATHLEN];
221 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
222 f = fopen(cfgfile, "w");
224 printf("failed to open: %s\n", cfgfile);
228 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
229 fprintf(f, "%s = ", config_data[i].name);
230 switch (config_data[i].len) {
232 fprintf(f, "%s\n", (char *)config_data[i].val);
235 fprintf(f, "%x\n", *(u8 *)config_data[i].val);
238 fprintf(f, "%x\n", *(u16 *)config_data[i].val);
241 fprintf(f, "%x\n", *(u32 *)config_data[i].val);
244 printf("menu_write_config: unhandled len %d for %s\n",
245 config_data[i].len, config_data[i].name);
251 fprintf(f, "lastcdimg = %s\n", last_selected_fname);
257 static void parse_str_val(char *cval, const char *src)
260 strncpy(cval, src, MAXPATHLEN);
261 cval[MAXPATHLEN - 1] = 0;
262 tmp = strchr(cval, '\n');
264 tmp = strchr(cval, '\r');
269 static int menu_load_config(int is_game)
271 char cfgfile[MAXPATHLEN];
277 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
278 f = fopen(cfgfile, "r");
280 printf("failed to open: %s\n", cfgfile);
284 fseek(f, 0, SEEK_END);
287 printf("bad size %ld: %s\n", size, cfgfile);
291 cfg = malloc(size + 1);
295 fseek(f, 0, SEEK_SET);
296 if (fread(cfg, 1, size, f) != size) {
297 printf("failed to read: %s\n", cfgfile);
302 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
306 tmp = strstr(cfg, config_data[i].name);
309 tmp += strlen(config_data[i].name);
310 if (strncmp(tmp, " = ", 3) != 0)
314 if (config_data[i].len == 0) {
315 parse_str_val(config_data[i].val, tmp);
320 val = strtoul(tmp, &tmp2, 16);
321 if (tmp2 == NULL || tmp == tmp2)
322 continue; // parse failed
324 switch (config_data[i].len) {
326 *(u8 *)config_data[i].val = val;
329 *(u16 *)config_data[i].val = val;
332 *(u32 *)config_data[i].val = val;
335 printf("menu_load_config: unhandled len %d for %s\n",
336 config_data[i].len, config_data[i].name);
342 char *tmp = strstr(cfg, "lastcdimg = ");
345 parse_str_val(last_selected_fname, tmp);
356 // rrrr rggg gggb bbbb
357 static unsigned short fname2color(const char *fname)
359 static const char *cdimg_exts[] = { ".bin", ".img", ".iso", ".z", ".cue" };
360 static const char *other_exts[] = { ".ccd", ".toc", ".mds", ".sub", ".table" };
361 const char *ext = strrchr(fname, '.');
366 for (i = 0; i < array_size(cdimg_exts); i++)
367 if (strcasecmp(ext, cdimg_exts[i]) == 0)
369 for (i = 0; i < array_size(other_exts); i++)
370 if (strcasecmp(ext, other_exts[i]) == 0)
375 #define MENU_ALIGN_LEFT
376 #define menu_init menu_init_common
377 #include "common/menu.c"
380 // ---------- pandora specific -----------
382 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
383 static char **pnd_filter_list;
385 static int get_cpu_clock(void)
389 f = fopen("/proc/pandora/cpu_mhz_max", "r");
391 fscanf(f, "%d", &ret);
397 static void apply_cpu_clock(void)
401 if (cpu_clock != 0 && cpu_clock != get_cpu_clock()) {
402 snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
403 pnd_script_base, cpu_clock);
408 static void apply_filter(int which)
414 if (pnd_filter_list == NULL || which == old)
417 for (i = 0; i < which; i++)
418 if (pnd_filter_list[i] == NULL)
421 if (pnd_filter_list[i] == NULL)
424 snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]);
429 static menu_entry e_menu_gfx_options[];
431 static void pnd_menu_init(void)
439 cpu_clock = get_cpu_clock();
441 dir = opendir("/etc/pandora/conf/dss_fir");
443 perror("filter opendir");
455 p = strstr(ent->d_name, "_up");
456 if (p != NULL && (p[3] == 0 || !strcmp(p + 3, "_h")))
463 mfilters = calloc(count + 1, sizeof(mfilters[0]));
464 if (mfilters == NULL)
468 for (i = 0; (ent = readdir(dir)); ) {
471 p = strstr(ent->d_name, "_up");
472 if (p == NULL || (p[3] != 0 && strcmp(p + 3, "_h")))
475 len = p - ent->d_name;
476 if (len > sizeof(buff) - 1)
479 strncpy(buff, ent->d_name, len);
481 mfilters[i] = strdup(buff);
482 if (mfilters[i] != NULL)
487 i = me_id2offset(e_menu_gfx_options, MA_OPT_FILTERING);
488 e_menu_gfx_options[i].data = (void *)mfilters;
489 pnd_filter_list = mfilters;
492 // -------------- key config --------------
494 me_bind_action me_ctrl_actions[] =
496 { "UP ", 1 << DKEY_UP},
497 { "DOWN ", 1 << DKEY_DOWN },
498 { "LEFT ", 1 << DKEY_LEFT },
499 { "RIGHT ", 1 << DKEY_RIGHT },
500 { "TRIANGLE", 1 << DKEY_TRIANGLE },
501 { "CIRCLE ", 1 << DKEY_CIRCLE },
502 { "CROSS ", 1 << DKEY_CROSS },
503 { "SQUARE ", 1 << DKEY_SQUARE },
504 { "L1 ", 1 << DKEY_L1 },
505 { "R1 ", 1 << DKEY_R1 },
506 { "L2 ", 1 << DKEY_L2 },
507 { "R2 ", 1 << DKEY_R2 },
508 { "START ", 1 << DKEY_START },
509 { "SELECT ", 1 << DKEY_SELECT },
513 me_bind_action emuctrl_actions[] =
516 { "Load State ", PEV_STATE_LOAD },
517 { "Save State ", PEV_STATE_SAVE },
518 { "Prev Save Slot ", PEV_SSLOT_PREV },
519 { "Next Save Slot ", PEV_SSLOT_NEXT },
521 { "Enter Menu ", PEV_MENU },
525 static int key_config_loop_wrap(int id, int keys)
528 case MA_CTRL_PLAYER1:
529 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
531 case MA_CTRL_PLAYER2:
532 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
535 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
543 static const char *mgn_dev_name(int id, int *offs)
545 const char *name = NULL;
548 if (id == MA_CTRL_DEV_FIRST)
551 for (; it < IN_MAX_DEVS; it++) {
552 name = in_get_dev_name(it, 1, 1);
561 static const char *mgn_saveloadcfg(int id, int *offs)
566 static int mh_savecfg(int id, int keys)
568 if (menu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0) == 0)
569 me_update_msg("config saved");
571 me_update_msg("failed to write config");
576 static menu_entry e_menu_keyconfig[] =
578 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
579 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
580 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
581 // mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
582 // mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
584 mee_label ("Input devices:"),
585 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
586 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
587 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
588 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
589 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
590 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
591 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
595 static int menu_loop_keyconfig(int id, int keys)
599 // me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, ready_to_go);
600 me_loop(e_menu_keyconfig, &sel, NULL);
604 // ------------ gfx options menu ------------
606 static const char *men_scaler[] = { "1x1", "scaled 4:3", "fullscreen", "custom", NULL };
607 static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n"
608 "using d-pad or move it using R+d-pad";
609 static const char *men_dummy[] = { NULL };
611 static int menu_loop_cscaler(int id, int keys)
615 scaling = SCALE_CUSTOM;
617 omap_enable_layer(1);
618 //pnd_restore_layer_data();
623 memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
624 text_out16(2, 480 - 18, "%dx%d | d-pad to resize, R+d-pad to move", g_layer_w, g_layer_h);
627 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40);
628 if (inp & PBTN_UP) g_layer_y--;
629 if (inp & PBTN_DOWN) g_layer_y++;
630 if (inp & PBTN_LEFT) g_layer_x--;
631 if (inp & PBTN_RIGHT) g_layer_x++;
632 if (!(inp & PBTN_R)) {
633 if (inp & PBTN_UP) g_layer_h += 2;
634 if (inp & PBTN_DOWN) g_layer_h -= 2;
635 if (inp & PBTN_LEFT) g_layer_w += 2;
636 if (inp & PBTN_RIGHT) g_layer_w -= 2;
638 if (inp & (PBTN_MOK|PBTN_MBACK))
641 if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
642 if (g_layer_x < 0) g_layer_x = 0;
643 if (g_layer_x > 640) g_layer_x = 640;
644 if (g_layer_y < 0) g_layer_y = 0;
645 if (g_layer_y > 420) g_layer_y = 420;
646 if (g_layer_w < 160) g_layer_w = 160;
647 if (g_layer_h < 60) g_layer_h = 60;
648 if (g_layer_x + g_layer_w > 800)
649 g_layer_w = 800 - g_layer_x;
650 if (g_layer_y + g_layer_h > 480)
651 g_layer_h = 480 - g_layer_y;
652 omap_enable_layer(1);
656 omap_enable_layer(0);
661 static menu_entry e_menu_gfx_options[] =
663 mee_enum ("Scaler", 0, scaling, men_scaler),
664 mee_enum ("Filter", MA_OPT_FILTERING, filter, men_dummy),
665 // mee_onoff ("Vsync", 0, vsync, 1),
666 mee_cust_h ("Setup custom scaler", 0, menu_loop_cscaler, NULL, h_cscaler),
670 static int menu_loop_gfx_options(int id, int keys)
674 me_loop(e_menu_gfx_options, &sel, NULL);
679 // ------------ bios/plugins ------------
681 static const char *men_gpu_dithering[] = { "None", "Game dependant", "Always", NULL };
682 static const char h_gpu[] = "Configure built-in P.E.Op.S. SoftGL Driver V1.17\n"
683 "Coded by Pete Bernert and the P.E.Op.S. team";
684 static const char h_gpu_0[] = "Needed for Chrono Cross";
685 static const char h_gpu_1[] = "Capcom fighting games";
686 static const char h_gpu_2[] = "Black screens in Lunar";
687 static const char h_gpu_3[] = "Compatibility mode";
688 static const char h_gpu_6[] = "Pandemonium 2";
689 static const char h_gpu_7[] = "Skip every second frame";
690 static const char h_gpu_8[] = "Needed by Dark Forces";
691 static const char h_gpu_9[] = "better g-colors, worse textures";
692 static const char h_gpu_10[] = "Toggle busy flags after drawing";
694 static menu_entry e_menu_plugin_gpu[] =
696 mee_enum ("Dithering", 0, iUseDither, men_gpu_dithering),
697 mee_onoff_h ("Odd/even bit hack", 0, dwActFixes, 1<<0, h_gpu_0),
698 mee_onoff_h ("Expand screen width", 0, dwActFixes, 1<<1, h_gpu_1),
699 mee_onoff_h ("Ignore brightness color", 0, dwActFixes, 1<<2, h_gpu_2),
700 mee_onoff_h ("Disable coordinate check", 0, dwActFixes, 1<<3, h_gpu_3),
701 mee_onoff_h ("Lazy screen update", 0, dwActFixes, 1<<6, h_gpu_6),
702 mee_onoff_h ("Old frame skipping", 0, dwActFixes, 1<<7, h_gpu_7),
703 mee_onoff_h ("Repeated flat tex triangles ",0,dwActFixes, 1<<8, h_gpu_8),
704 mee_onoff_h ("Draw quads with triangles", 0, dwActFixes, 1<<9, h_gpu_9),
705 mee_onoff_h ("Fake 'gpu busy' states", 0, dwActFixes, 1<<10, h_gpu_10),
709 static int menu_loop_plugin_gpu(int id, int keys)
712 me_loop(e_menu_plugin_gpu, &sel, NULL);
716 static const char *men_spu_reverb[] = { "Off", "Fake", "On", NULL };
717 static const char *men_spu_interp[] = { "None", "Simple", "Gaussian", "Cubic", NULL };
718 static const char h_spu[] = "Configure built-in P.E.Op.S. Sound Driver V1.7\n"
719 "Coded by Pete Bernert and the P.E.Op.S. team";
720 static const char h_spu_irq_wait[] = "Wait for CPU; only useful for some games, may cause glitches";
721 static const char h_spu_thread[] = "Run sound emulation in separate thread";
723 static menu_entry e_menu_plugin_spu[] =
725 mee_enum ("Reverb", 0, iUseReverb, men_spu_reverb),
726 mee_enum ("Interpolation", 0, iUseInterpolation, men_spu_interp),
727 mee_onoff ("Adjust XA pitch", 0, iXAPitch, 1),
728 mee_onoff_h ("SPU IRQ Wait", 0, iSPUIRQWait, 1, h_spu_irq_wait),
729 mee_onoff_h ("Use sound thread", 0, iUseTimer, 1, h_spu_thread),
733 static int menu_loop_plugin_spu(int id, int keys)
736 me_loop(e_menu_plugin_spu, &sel, NULL);
740 static menu_entry e_menu_plugin_options[] =
742 mee_handler_h ("Configure built-in GPU plugin", menu_loop_plugin_gpu, h_gpu),
743 mee_handler_h ("Configure built-in SPU plugin", menu_loop_plugin_spu, h_spu),
747 static int menu_loop_plugin_options(int id, int keys)
750 me_loop(e_menu_plugin_options, &sel, NULL);
754 // ------------ adv options menu ------------
756 static const char h_cfg_xa[] = "Disables XA sound, which can sometimes improve performance";
757 static const char h_cfg_cdda[] = "Disable CD Audio for a performance boost\n"
758 "(proper .cue/.bin dump is needed otherwise)";
759 static const char h_cfg_sio[] = "This should be enabled for certain memcards/gamepads";
760 static const char h_cfg_spuirq[] = "Compatibility tweak; should probably be left off";
761 static const char h_cfg_rcnt1[] = "Parasite Eve 2, Vandal Hearts 1/2 Fix";
762 static const char h_cfg_rcnt2[] = "InuYasha Sengoku Battle Fix";
764 static menu_entry e_menu_adv_options[] =
766 mee_onoff ("Show CPU load", 0, g_opts, OPT_SHOWCPU),
767 mee_onoff_h ("Disable XA Decoding", 0, Config.Xa, 1, h_cfg_xa),
768 mee_onoff_h ("Disable CD Audio", 0, Config.Cdda, 1, h_cfg_cdda),
769 mee_onoff_h ("SIO IRQ Always Enabled", 0, Config.Sio, 1, h_cfg_sio),
770 mee_onoff_h ("SPU IRQ Always Enabled", 0, Config.SpuIrq, 1, h_cfg_spuirq),
771 mee_onoff_h ("Rootcounter hack", 0, Config.RCntFix, 1, h_cfg_rcnt1),
772 mee_onoff_h ("Rootcounter hack 2", 0, Config.VSyncWA, 1, h_cfg_rcnt2),
776 static int menu_loop_adv_options(int id, int keys)
779 me_loop(e_menu_adv_options, &sel, NULL);
783 // ------------ options menu ------------
785 static int mh_restore_defaults(int id, int keys)
787 menu_set_defconfig();
788 me_update_msg("defaults restored");
792 static const char *men_region[] = { "NTSC", "PAL", NULL };
794 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
795 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
796 "loading state or both";
798 static const char h_restore_def[] = "Switches back to default / recommended\n"
801 static menu_entry e_menu_options[] =
803 // mee_range ("Save slot", 0, state_slot, 0, 9),
804 // mee_enum_h ("Confirm savestate", 0, dummy, men_confirm_save, h_confirm_save),
805 mee_onoff ("Frameskip", 0, UseFrameSkip, 1),
806 mee_onoff ("Show FPS", 0, g_opts, OPT_SHOWFPS),
807 mee_enum ("Region", 0, Config.PsxType, men_region),
808 mee_range ("CPU clock", MA_OPT_CPU_CLOCKS, cpu_clock, 20, 5000),
809 mee_handler ("[Display]", menu_loop_gfx_options),
810 mee_handler ("[BIOS/Plugins]", menu_loop_plugin_options),
811 mee_handler ("[Advanced]", menu_loop_adv_options),
812 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
813 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
814 mee_handler_h ("Restore default config", mh_restore_defaults, h_restore_def),
818 static int menu_loop_options(int id, int keys)
823 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
824 e_menu_options[i].enabled = cpu_clock != 0 ? 1 : 0;
825 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, ready_to_go);
827 me_loop(e_menu_options, &sel, NULL);
832 // ------------ debug menu ------------
834 static void draw_frame_debug(void)
836 smalltext_out16(4, 1, "build: "__DATE__ " " __TIME__ " " REV, 0xe7fc);
839 static void debug_menu_loop(void)
849 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
850 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
851 if (inp & PBTN_MBACK)
856 // ------------ main menu ------------
860 const char *plat_get_credits(void)
862 return "PCSX-ReARMed\n\n"
863 "(C) 1999-2003 PCSX Team\n"
864 "(C) 2005-2009 PCSX-df Team\n"
865 "(C) 2009-2010 PCSX-Reloaded Team\n\n"
866 "GPU and SPU code by Pete Bernert\n"
867 " and the P.E.Op.S. team\n"
868 "ARM recompiler (C) 2009-2010 Ari64\n\n"
869 "integration, optimization and\n"
870 " frontend (C) 2010 notaz\n";
873 static char *romsel_run(void)
875 extern void set_cd_image(const char *fname);
878 ret = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
882 lprintf("selected file: %s\n", ret);
888 if (OpenPlugins() == -1) {
889 me_update_msg("failed to open plugins");
895 if (CheckCdrom() == -1) {
896 // Only check the CD if we are starting the console with a CD
898 me_update_msg("unsupported/invalid CD image");
902 // Read main executable directly from CDRom and start it
903 if (LoadCdrom() == -1) {
905 me_update_msg("failed to load CD image");
909 strcpy(last_selected_fname, rom_fname_reload);
910 game_config_loaded = 0;
915 static int main_menu_handler(int id, int keys)
921 case MA_MAIN_RESUME_GAME:
925 case MA_MAIN_SAVE_STATE:
927 return menu_loop_savestate(0);
929 case MA_MAIN_LOAD_STATE:
931 return menu_loop_savestate(1);
933 case MA_MAIN_RESET_GAME:
937 if (CheckCdrom() != -1) {
943 case MA_MAIN_LOAD_ROM:
944 ret_name = romsel_run();
945 if (ret_name != NULL)
948 case MA_MAIN_CREDITS:
949 draw_menu_credits(draw_frame_debug);
950 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
956 lprintf("%s: something unknown selected\n", __FUNCTION__);
963 static menu_entry e_menu_main[] =
967 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
968 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
969 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
970 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
971 mee_handler_id("Load CD image", MA_MAIN_LOAD_ROM, main_menu_handler),
972 mee_handler ("Options", menu_loop_options),
973 mee_handler ("Controls", menu_loop_keyconfig),
974 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
975 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
979 // ----------------------------
981 static void menu_leave_emu(void);
989 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, ready_to_go);
990 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, ready_to_go);
991 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, ready_to_go);
992 me_enable(e_menu_main, MA_MAIN_RESET_GAME, ready_to_go);
994 // menu_enter(ready_to_go);
995 in_set_config_int(0, IN_CFG_BLOCKING, 1);
998 me_loop(e_menu_main, &sel, NULL);
999 } while (!ready_to_go);
1001 /* wait until menu, ok, back is released */
1002 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1005 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1007 memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
1012 void menu_init(void)
1014 char buff[MAXPATHLEN];
1016 strcpy(last_selected_fname, "/media");
1021 menu_set_defconfig();
1022 menu_load_config(0);
1027 g_menubg_src_ptr = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
1028 if (g_menubg_src_ptr == NULL)
1030 emu_make_path(buff, "skin/background.png", sizeof(buff));
1031 readpng(g_menubg_src_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h);
1034 void menu_notify_mode_change(int w, int h, int bpp)
1040 if (scaling == SCALE_1_1) {
1041 g_layer_x = 800/2 - w/2; g_layer_y = 480/2 - h/2;
1042 g_layer_w = w; g_layer_h = h;
1046 static void menu_leave_emu(void)
1048 if (GPU_close != NULL) {
1049 int ret = GPU_close();
1051 fprintf(stderr, "Warning: GPU_close returned %d\n", ret);
1054 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
1055 if (ready_to_go && last_psx_bpp == 16) {
1056 int x = max(0, g_menuscreen_w - last_psx_w);
1057 int y = max(0, g_menuscreen_h / 2 - last_psx_h / 2);
1058 int w = min(g_menuscreen_w, last_psx_w);
1059 int h = min(g_menuscreen_h, last_psx_h);
1060 u16 *d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
1061 u16 *s = pl_fbdev_buf;
1063 for (; h > 0; h--, d += g_menuscreen_w, s += last_psx_w)
1064 menu_darken_bg(d, s, w, 0);
1068 void menu_prepare_emu(void)
1070 if (!game_config_loaded) {
1071 menu_set_defconfig();
1072 menu_load_config(1);
1073 game_config_loaded = 1;
1078 menu_notify_mode_change(last_psx_w, last_psx_h, last_psx_bpp);
1081 g_layer_x = 80; g_layer_y = 0;
1082 g_layer_w = 640; g_layer_h = 480;
1084 case SCALE_FULLSCREEN:
1085 g_layer_x = 0; g_layer_y = 0;
1086 g_layer_w = 800; g_layer_h = 480;
1091 apply_filter(filter);
1095 // core doesn't care about Config.Cdda changes,
1096 // so handle them manually here
1100 if (GPU_open != NULL) {
1101 extern unsigned long gpuDisp;
1102 int ret = GPU_open(&gpuDisp, "PCSX", NULL);
1104 fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
1108 void me_update_msg(const char *msg)
1110 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1111 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1113 menu_error_time = plat_get_ticks_ms();
1114 lprintf("msg: %s\n", menu_error_msg);