2 * (C) GraÅžvydas "notaz" Ignotas, 2010-2011
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.
21 #include "plugin_lib.h"
23 #include "common/plat.h"
24 #include "../libpcsxcore/misc.h"
25 #include "../libpcsxcore/cdrom.h"
26 #include "../libpcsxcore/psemu_plugin_defs.h"
30 #define array_size(x) (sizeof(x) / sizeof(x[0]))
64 static int last_psx_w, last_psx_h, last_psx_bpp;
65 static int scaling, filter, cpu_clock, cpu_clock_st;
66 static char rom_fname_reload[MAXPATHLEN];
67 static char last_selected_fname[MAXPATHLEN];
68 static int region, in_type_sel;
71 // from softgpu plugin
72 extern int iUseDither;
73 extern int UseFrameSkip;
74 extern uint32_t dwActFixes;
75 extern float fFrameRateHz;
76 extern int dwFrameRateTicks;
79 extern int iUseReverb;
80 extern int iUseInterpolation;
82 extern int iSPUIRQWait;
85 static const char *bioses[24];
86 static const char *gpu_plugins[16];
87 static const char *spu_plugins[16];
88 static int bios_sel, gpu_plugsel, spu_plugsel;
91 static int min(int x, int y) { return x < y ? x : y; }
92 static int max(int x, int y) { return x > y ? x : y; }
94 void emu_make_path(char *buff, const char *end, int size)
98 end_len = strlen(end);
99 pos = plat_get_root_dir(buff, size);
100 strncpy(buff + pos, end, size - pos);
102 if (pos + end_len > size - 1)
103 printf("Warning: path truncated: %s\n", buff);
106 static int emu_check_save_file(int slot)
108 int ret = emu_check_state(slot);
109 return ret == 0 ? 1 : 0;
112 static int emu_save_load_game(int load, int unused)
117 ret = emu_load_state(state_slot);
119 // reflect hle/bios mode from savestate
122 else if (bios_sel == 0 && bioses[1] != NULL)
123 // XXX: maybe find the right bios instead
127 ret = emu_save_state(state_slot);
132 // propagate menu settings to the emu vars
133 static void menu_sync_config(void)
138 Config.PsxType = region - 1;
140 in_type = in_type_sel ? PSE_PAD_TYPE_ANALOGPAD : PSE_PAD_TYPE_STANDARD;
142 pl_frame_interval = Config.PsxType ? 20000 : 16667;
143 // used by P.E.Op.S. frameskip code
144 fFrameRateHz = Config.PsxType ? 50.0f : 59.94f;
145 dwFrameRateTicks = (100000*100 / (unsigned long)(fFrameRateHz*100));
148 static void menu_set_defconfig(void)
155 Config.Xa = Config.Cdda = Config.Sio =
156 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
163 iUseInterpolation = 1;
171 #define CE_CONFIG_STR(val) \
172 { #val, 0, Config.val }
174 #define CE_CONFIG_VAL(val) \
175 { #val, sizeof(Config.val), &Config.val }
177 #define CE_STR(val) \
180 #define CE_INTVAL(val) \
181 { #val, sizeof(val), &val }
183 // 'versioned' var, used when defaults change
184 #define CE_INTVAL_V(val, ver) \
185 { #val #ver, sizeof(val), &val }
187 static const struct {
195 // CE_CONFIG_STR(Cdr),
200 CE_CONFIG_VAL(Debug),
201 CE_CONFIG_VAL(PsxOut),
202 CE_CONFIG_VAL(SpuIrq),
203 CE_CONFIG_VAL(RCntFix),
204 CE_CONFIG_VAL(VSyncWA),
208 CE_INTVAL(g_layer_x),
209 CE_INTVAL(g_layer_y),
210 CE_INTVAL(g_layer_w),
211 CE_INTVAL(g_layer_h),
213 CE_INTVAL(state_slot),
214 CE_INTVAL(cpu_clock),
216 CE_INTVAL(in_type_sel),
217 CE_INTVAL(iUseDither),
218 CE_INTVAL(UseFrameSkip),
219 CE_INTVAL(dwActFixes),
220 CE_INTVAL(iUseReverb),
222 CE_INTVAL_V(iUseInterpolation, 2),
223 CE_INTVAL_V(iSPUIRQWait, 2),
224 CE_INTVAL(iUseTimer),
227 static char *get_cd_label(void)
229 static char trimlabel[33];
232 strncpy(trimlabel, CdromLabel, 32);
234 for (j = 31; j >= 0; j--)
235 if (trimlabel[j] == ' ')
241 static void make_cfg_fname(char *buf, size_t size, int is_game)
244 snprintf(buf, size, "." PCSX_DOT_DIR "cfg/%.32s-%.9s.cfg", get_cd_label(), CdromId);
246 snprintf(buf, size, "." PCSX_DOT_DIR "%s", cfgfile_basename);
249 static void keys_write_all(FILE *f);
251 static int menu_write_config(int is_game)
253 char cfgfile[MAXPATHLEN];
257 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
258 f = fopen(cfgfile, "w");
260 printf("menu_write_config: failed to open: %s\n", cfgfile);
264 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
265 fprintf(f, "%s = ", config_data[i].name);
266 switch (config_data[i].len) {
268 fprintf(f, "%s\n", (char *)config_data[i].val);
271 fprintf(f, "%x\n", *(u8 *)config_data[i].val);
274 fprintf(f, "%x\n", *(u16 *)config_data[i].val);
277 fprintf(f, "%x\n", *(u32 *)config_data[i].val);
280 printf("menu_write_config: unhandled len %d for %s\n",
281 config_data[i].len, config_data[i].name);
287 fprintf(f, "lastcdimg = %s\n", last_selected_fname);
295 static void parse_str_val(char *cval, const char *src)
298 strncpy(cval, src, MAXPATHLEN);
299 cval[MAXPATHLEN - 1] = 0;
300 tmp = strchr(cval, '\n');
302 tmp = strchr(cval, '\r');
307 static void keys_load_all(const char *cfg);
309 static int menu_load_config(int is_game)
311 char cfgfile[MAXPATHLEN];
317 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
318 f = fopen(cfgfile, "r");
320 printf("menu_load_config: failed to open: %s\n", cfgfile);
324 fseek(f, 0, SEEK_END);
327 printf("bad size %ld: %s\n", size, cfgfile);
331 cfg = malloc(size + 1);
335 fseek(f, 0, SEEK_SET);
336 if (fread(cfg, 1, size, f) != size) {
337 printf("failed to read: %s\n", cfgfile);
342 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
346 tmp = strstr(cfg, config_data[i].name);
349 tmp += strlen(config_data[i].name);
350 if (strncmp(tmp, " = ", 3) != 0)
354 if (config_data[i].len == 0) {
355 parse_str_val(config_data[i].val, tmp);
360 val = strtoul(tmp, &tmp2, 16);
361 if (tmp2 == NULL || tmp == tmp2)
362 continue; // parse failed
364 switch (config_data[i].len) {
366 *(u8 *)config_data[i].val = val;
369 *(u16 *)config_data[i].val = val;
372 *(u32 *)config_data[i].val = val;
375 printf("menu_load_config: unhandled len %d for %s\n",
376 config_data[i].len, config_data[i].name);
382 char *tmp = strstr(cfg, "lastcdimg = ");
385 parse_str_val(last_selected_fname, tmp);
392 for (i = bios_sel = 0; bioses[i] != NULL; i++)
393 if (strcmp(Config.Bios, bioses[i]) == 0)
394 { bios_sel = i; break; }
396 for (i = gpu_plugsel = 0; gpu_plugins[i] != NULL; i++)
397 if (strcmp(Config.Gpu, gpu_plugins[i]) == 0)
398 { gpu_plugsel = i; break; }
400 for (i = spu_plugsel = 0; spu_plugins[i] != NULL; i++)
401 if (strcmp(Config.Spu, spu_plugins[i]) == 0)
402 { spu_plugsel = i; break; }
413 // rrrr rggg gggb bbbb
414 static unsigned short fname2color(const char *fname)
416 static const char *cdimg_exts[] = { ".bin", ".img", ".iso", ".cue", ".z", ".bz", ".znx", ".pbp" };
417 static const char *other_exts[] = { ".ccd", ".toc", ".mds", ".sub", ".table", ".index" };
418 const char *ext = strrchr(fname, '.');
423 for (i = 0; i < array_size(cdimg_exts); i++)
424 if (strcasecmp(ext, cdimg_exts[i]) == 0)
426 for (i = 0; i < array_size(other_exts); i++)
427 if (strcasecmp(ext, other_exts[i]) == 0)
432 static void draw_savestate_bg(int slot);
434 #define MENU_ALIGN_LEFT
435 #define menu_init menu_init_common
436 #include "common/menu.c"
439 // a bit of black magic here
440 static void draw_savestate_bg(int slot)
442 extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
443 static const int psx_widths[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
445 char fname[MAXPATHLEN];
452 ret = get_state_filename(fname, sizeof(fname), slot);
456 f = gzopen(fname, "rb");
460 if (gzseek(f, 0x29933d, SEEK_SET) != 0x29933d) {
461 fprintf(stderr, "gzseek failed\n");
466 gpu = malloc(sizeof(*gpu));
472 ret = gzread(f, gpu, sizeof(*gpu));
474 if (ret != sizeof(*gpu)) {
475 fprintf(stderr, "gzread failed\n");
479 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
481 if ((gpu->ulStatus & 0x800000) || (gpu->ulStatus & 0x200000))
482 goto out; // disabled || 24bpp (NYET)
484 x = gpu->ulControl[5] & 0x3ff;
485 y = (gpu->ulControl[5] >> 10) & 0x1ff;
486 s = (u16 *)gpu->psxVRam + y * 1024 + (x & ~3);
487 w = psx_widths[(gpu->ulStatus >> 16) & 7];
488 tmp = gpu->ulControl[7];
489 h = ((tmp >> 10) & 0x3ff) - (tmp & 0x3ff);
490 if (gpu->ulStatus & 0x80000) // doubleheight
493 x = max(0, g_menuscreen_w - w) & ~3;
494 y = max(0, g_menuscreen_h / 2 - h / 2);
495 w = min(g_menuscreen_w, w);
496 h = min(g_menuscreen_h, h);
497 d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
499 for (; h > 0; h--, d += g_menuscreen_w, s += 1024)
500 bgr555_to_rgb565(d, s, w * 2);
506 // ---------- pandora specific -----------
508 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
509 static char **pnd_filter_list;
511 static int get_cpu_clock(void)
515 f = fopen("/proc/pandora/cpu_mhz_max", "r");
517 fscanf(f, "%d", &ret);
523 static void apply_cpu_clock(void)
527 if (cpu_clock != 0 && cpu_clock != get_cpu_clock()) {
528 snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
529 pnd_script_base, cpu_clock);
534 static void apply_filter(int which)
540 if (pnd_filter_list == NULL || which == old)
543 for (i = 0; i < which; i++)
544 if (pnd_filter_list[i] == NULL)
547 if (pnd_filter_list[i] == NULL)
550 snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]);
555 static menu_entry e_menu_gfx_options[];
557 static void pnd_menu_init(void)
565 cpu_clock_st = cpu_clock = get_cpu_clock();
567 dir = opendir("/etc/pandora/conf/dss_fir");
569 perror("filter opendir");
582 if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
591 mfilters = calloc(count + 1, sizeof(mfilters[0]));
592 if (mfilters == NULL)
596 for (i = 0; (ent = readdir(dir)); ) {
599 if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
602 len = strlen(ent->d_name);
604 // skip pre-HF5 extra files
605 if (len >= 3 && strcmp(ent->d_name + len - 3, "_v3") == 0)
607 if (len >= 3 && strcmp(ent->d_name + len - 3, "_v5") == 0)
610 // have to cut "_up_h" for pre-HF5
611 if (len > 5 && strcmp(ent->d_name + len - 5, "_up_h") == 0)
614 if (len > sizeof(buff) - 1)
617 strncpy(buff, ent->d_name, len);
619 mfilters[i] = strdup(buff);
620 if (mfilters[i] != NULL)
625 i = me_id2offset(e_menu_gfx_options, MA_OPT_FILTERING);
626 e_menu_gfx_options[i].data = (void *)mfilters;
627 pnd_filter_list = mfilters;
630 void menu_finish(void)
632 cpu_clock = cpu_clock_st;
636 // -------------- key config --------------
638 me_bind_action me_ctrl_actions[] =
640 { "UP ", 1 << DKEY_UP},
641 { "DOWN ", 1 << DKEY_DOWN },
642 { "LEFT ", 1 << DKEY_LEFT },
643 { "RIGHT ", 1 << DKEY_RIGHT },
644 { "TRIANGLE", 1 << DKEY_TRIANGLE },
645 { "CIRCLE ", 1 << DKEY_CIRCLE },
646 { "CROSS ", 1 << DKEY_CROSS },
647 { "SQUARE ", 1 << DKEY_SQUARE },
648 { "L1 ", 1 << DKEY_L1 },
649 { "R1 ", 1 << DKEY_R1 },
650 { "L2 ", 1 << DKEY_L2 },
651 { "R2 ", 1 << DKEY_R2 },
652 { "L3 ", 1 << DKEY_L3 },
653 { "R3 ", 1 << DKEY_R3 },
654 { "START ", 1 << DKEY_START },
655 { "SELECT ", 1 << DKEY_SELECT },
659 me_bind_action emuctrl_actions[] =
661 { "Save State ", 1 << SACTION_SAVE_STATE },
662 { "Load State ", 1 << SACTION_LOAD_STATE },
663 { "Prev Save Slot ", 1 << SACTION_PREV_SSLOT },
664 { "Next Save Slot ", 1 << SACTION_NEXT_SSLOT },
665 { "Toggle Frameskip ", 1 << SACTION_TOGGLE_FSKIP },
666 { "Enter Menu ", 1 << SACTION_ENTER_MENU },
670 static char *mystrip(char *str)
675 for (i = 0; i < len; i++)
676 if (str[i] != ' ') break;
677 if (i > 0) memmove(str, str + i, len - i + 1);
680 for (i = len - 1; i >= 0; i--)
681 if (str[i] != ' ') break;
687 static void get_line(char *d, size_t size, const char *s)
692 for (pe = s; *pe != '\r' && *pe != '\n' && *pe != 0; pe++)
703 static void keys_write_all(FILE *f)
707 for (d = 0; d < IN_MAX_DEVS; d++)
709 const int *binds = in_get_dev_binds(d);
710 const char *name = in_get_dev_name(d, 0, 0);
713 if (binds == NULL || name == NULL)
716 fprintf(f, "binddev = %s\n", name);
717 in_get_config(d, IN_CFG_BIND_COUNT, &count);
719 for (k = 0; k < count; k++)
724 act[0] = act[31] = 0;
725 name = in_get_key_name(d, k);
727 kbinds = binds[IN_BIND_OFFS(k, IN_BINDTYPE_PLAYER12)];
728 for (i = 0; kbinds && i < ARRAY_SIZE(me_ctrl_actions) - 1; i++) {
729 mask = me_ctrl_actions[i].mask;
731 strncpy(act, me_ctrl_actions[i].name, 31);
732 fprintf(f, "bind %s = player1 %s\n", name, mystrip(act));
735 mask = me_ctrl_actions[i].mask << 16;
737 strncpy(act, me_ctrl_actions[i].name, 31);
738 fprintf(f, "bind %s = player2 %s\n", name, mystrip(act));
743 kbinds = binds[IN_BIND_OFFS(k, IN_BINDTYPE_EMU)];
744 for (i = 0; kbinds && i < ARRAY_SIZE(emuctrl_actions) - 1; i++) {
745 mask = emuctrl_actions[i].mask;
747 strncpy(act, emuctrl_actions[i].name, 31);
748 fprintf(f, "bind %s = %s\n", name, mystrip(act));
756 static int parse_bind_val(const char *val, int *type)
760 *type = IN_BINDTYPE_NONE;
764 if (strncasecmp(val, "player", 6) == 0)
766 int player, shift = 0;
767 player = atoi(val + 6) - 1;
769 if ((unsigned int)player > 1)
774 *type = IN_BINDTYPE_PLAYER12;
775 for (i = 0; me_ctrl_actions[i].name != NULL; i++) {
776 if (strncasecmp(me_ctrl_actions[i].name, val + 8, strlen(val + 8)) == 0)
777 return me_ctrl_actions[i].mask << shift;
780 for (i = 0; emuctrl_actions[i].name != NULL; i++) {
781 if (strncasecmp(emuctrl_actions[i].name, val, strlen(val)) == 0) {
782 *type = IN_BINDTYPE_EMU;
783 return emuctrl_actions[i].mask;
790 static void keys_load_all(const char *cfg)
792 char dev[256], key[128], *act;
798 while (p != NULL && (p = strstr(p, "binddev = ")) != NULL) {
801 get_line(dev, sizeof(dev), p);
802 dev_id = in_config_parse_dev(dev);
804 printf("input: can't handle dev: %s\n", dev);
808 in_unbind_all(dev_id, -1, -1);
809 while ((p = strstr(p, "bind"))) {
810 if (strncmp(p, "binddev = ", 10) == 0)
815 printf("input: parse error: %16s..\n", p);
819 get_line(key, sizeof(key), p);
820 act = strchr(key, '=');
822 printf("parse failed: %16s..\n", p);
830 bind = parse_bind_val(act, &bindtype);
831 if (bind != -1 && bind != 0) {
832 //printf("bind #%d '%s' %08x (%s)\n", dev_id, key, bind, act);
833 in_config_bind_key(dev_id, key, bind, bindtype);
836 lprintf("config: unhandled action \"%s\"\n", act);
841 static int key_config_loop_wrap(int id, int keys)
844 case MA_CTRL_PLAYER1:
845 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
847 case MA_CTRL_PLAYER2:
848 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
851 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
859 static const char *mgn_dev_name(int id, int *offs)
861 const char *name = NULL;
864 if (id == MA_CTRL_DEV_FIRST)
867 for (; it < IN_MAX_DEVS; it++) {
868 name = in_get_dev_name(it, 1, 1);
877 static const char *mgn_saveloadcfg(int id, int *offs)
882 static int mh_savecfg(int id, int keys)
884 if (menu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0) == 0)
885 me_update_msg("config saved");
887 me_update_msg("failed to write config");
892 static const char *men_in_type_sel[] = { "Standard (SCPH-1080)", "Analog (SCPH-1150)", NULL };
894 static menu_entry e_menu_keyconfig[] =
896 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
897 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
898 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
900 mee_enum ("Controller", 0, in_type_sel, men_in_type_sel),
901 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
902 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
904 mee_label ("Input devices:"),
905 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
906 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
907 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
908 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
909 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
910 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
911 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
915 static int menu_loop_keyconfig(int id, int keys)
919 // me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, ready_to_go && CdromId[0]);
920 me_loop(e_menu_keyconfig, &sel, NULL);
924 // ------------ gfx options menu ------------
926 static const char *men_scaler[] = { "1x1", "scaled 4:3", "fullscreen", "custom", NULL };
927 static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n"
928 "using d-pad or move it using R+d-pad";
929 static const char *men_dummy[] = { NULL };
931 static int menu_loop_cscaler(int id, int keys)
935 scaling = SCALE_CUSTOM;
937 omap_enable_layer(1);
942 memset(g_menuscreen_ptr, 4, g_menuscreen_w * g_menuscreen_h * 2);
943 text_out16(2, 2, "%d,%d", g_layer_x, g_layer_y);
944 text_out16(2, 480 - 18, "%dx%d | d-pad: resize, R+d-pad: move", g_layer_w, g_layer_h);
947 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40);
948 if (inp & PBTN_UP) g_layer_y--;
949 if (inp & PBTN_DOWN) g_layer_y++;
950 if (inp & PBTN_LEFT) g_layer_x--;
951 if (inp & PBTN_RIGHT) g_layer_x++;
952 if (!(inp & PBTN_R)) {
953 if (inp & PBTN_UP) g_layer_h += 2;
954 if (inp & PBTN_DOWN) g_layer_h -= 2;
955 if (inp & PBTN_LEFT) g_layer_w += 2;
956 if (inp & PBTN_RIGHT) g_layer_w -= 2;
958 if (inp & (PBTN_MOK|PBTN_MBACK))
961 if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
962 if (g_layer_x < 0) g_layer_x = 0;
963 if (g_layer_x > 640) g_layer_x = 640;
964 if (g_layer_y < 0) g_layer_y = 0;
965 if (g_layer_y > 420) g_layer_y = 420;
966 if (g_layer_w < 160) g_layer_w = 160;
967 if (g_layer_h < 60) g_layer_h = 60;
968 if (g_layer_x + g_layer_w > 800)
969 g_layer_w = 800 - g_layer_x;
970 if (g_layer_y + g_layer_h > 480)
971 g_layer_h = 480 - g_layer_y;
972 omap_enable_layer(1);
976 omap_enable_layer(0);
981 static menu_entry e_menu_gfx_options[] =
983 mee_enum ("Scaler", 0, scaling, men_scaler),
984 mee_enum ("Filter", MA_OPT_FILTERING, filter, men_dummy),
985 // mee_onoff ("Vsync", 0, vsync, 1),
986 mee_cust_h ("Setup custom scaler", 0, menu_loop_cscaler, NULL, h_cscaler),
990 static int menu_loop_gfx_options(int id, int keys)
994 me_loop(e_menu_gfx_options, &sel, NULL);
999 // ------------ bios/plugins ------------
1001 static const char *men_gpu_dithering[] = { "None", "Game dependant", "Always", NULL };
1002 static const char h_gpu_0[] = "Needed for Chrono Cross";
1003 static const char h_gpu_1[] = "Capcom fighting games";
1004 static const char h_gpu_2[] = "Black screens in Lunar";
1005 static const char h_gpu_3[] = "Compatibility mode";
1006 static const char h_gpu_6[] = "Pandemonium 2";
1007 static const char h_gpu_7[] = "Skip every second frame";
1008 static const char h_gpu_8[] = "Needed by Dark Forces";
1009 static const char h_gpu_9[] = "better g-colors, worse textures";
1010 static const char h_gpu_10[] = "Toggle busy flags after drawing";
1012 static menu_entry e_menu_plugin_gpu[] =
1014 mee_enum ("Dithering", 0, iUseDither, men_gpu_dithering),
1015 mee_onoff_h ("Odd/even bit hack", 0, dwActFixes, 1<<0, h_gpu_0),
1016 mee_onoff_h ("Expand screen width", 0, dwActFixes, 1<<1, h_gpu_1),
1017 mee_onoff_h ("Ignore brightness color", 0, dwActFixes, 1<<2, h_gpu_2),
1018 mee_onoff_h ("Disable coordinate check", 0, dwActFixes, 1<<3, h_gpu_3),
1019 mee_onoff_h ("Lazy screen update", 0, dwActFixes, 1<<6, h_gpu_6),
1020 mee_onoff_h ("Old frame skipping", 0, dwActFixes, 1<<7, h_gpu_7),
1021 mee_onoff_h ("Repeated flat tex triangles ",0,dwActFixes, 1<<8, h_gpu_8),
1022 mee_onoff_h ("Draw quads with triangles", 0, dwActFixes, 1<<9, h_gpu_9),
1023 mee_onoff_h ("Fake 'gpu busy' states", 0, dwActFixes, 1<<10, h_gpu_10),
1027 static int menu_loop_plugin_gpu(int id, int keys)
1030 me_loop(e_menu_plugin_gpu, &sel, NULL);
1034 static const char *men_spu_reverb[] = { "Off", "Fake", "On", NULL };
1035 static const char *men_spu_interp[] = { "None", "Simple", "Gaussian", "Cubic", NULL };
1036 static const char h_spu_irq_wait[] = "Wait for CPU (recommended set to ON)";
1037 static const char h_spu_thread[] = "Run sound emulation in main thread (recommended)";
1039 static menu_entry e_menu_plugin_spu[] =
1041 mee_enum ("Reverb", 0, iUseReverb, men_spu_reverb),
1042 mee_enum ("Interpolation", 0, iUseInterpolation, men_spu_interp),
1043 mee_onoff ("Adjust XA pitch", 0, iXAPitch, 1),
1044 mee_onoff_h ("SPU IRQ Wait", 0, iSPUIRQWait, 1, h_spu_irq_wait),
1045 mee_onoff_h ("Sound in main thread", 0, iUseTimer, 2, h_spu_thread),
1049 static int menu_loop_plugin_spu(int id, int keys)
1052 me_loop(e_menu_plugin_spu, &sel, NULL);
1056 static const char h_bios[] = "HLE is simulated BIOS. BIOS is saved in savestates.\n"
1057 "Must save config and reload the game\n"
1058 "for change to take effect";
1059 static const char h_plugin_xpu[] = "Must save config and reload the game\n"
1060 "for plugin change to take effect";
1061 static const char h_gpu[] = "Configure built-in P.E.Op.S. SoftGL Driver V1.17";
1062 static const char h_spu[] = "Configure built-in P.E.Op.S. Sound Driver V1.7";
1064 static menu_entry e_menu_plugin_options[] =
1066 mee_enum_h ("BIOS", 0, bios_sel, bioses, h_bios),
1067 mee_enum_h ("GPU plugin", 0, gpu_plugsel, gpu_plugins, h_plugin_xpu),
1068 mee_enum_h ("SPU plugin", 0, spu_plugsel, spu_plugins, h_plugin_xpu),
1069 mee_handler_h ("Configure built-in GPU plugin", menu_loop_plugin_gpu, h_gpu),
1070 mee_handler_h ("Configure built-in SPU plugin", menu_loop_plugin_spu, h_spu),
1074 static menu_entry e_menu_main[];
1076 static int menu_loop_plugin_options(int id, int keys)
1079 me_loop(e_menu_plugin_options, &sel, NULL);
1081 // sync BIOS/plugins
1082 snprintf(Config.Bios, sizeof(Config.Bios), "%s", bioses[bios_sel]);
1083 snprintf(Config.Gpu, sizeof(Config.Gpu), "%s", gpu_plugins[gpu_plugsel]);
1084 snprintf(Config.Spu, sizeof(Config.Spu), "%s", spu_plugins[spu_plugsel]);
1085 me_enable(e_menu_main, MA_MAIN_RUN_BIOS, bios_sel != 0);
1090 // ------------ adv options menu ------------
1092 static const char h_cfg_cpul[] = "Shows CPU usage in %";
1093 static const char h_cfg_fl[] = "Frame Limiter keeps the game from running too fast";
1094 static const char h_cfg_xa[] = "Disables XA sound, which can sometimes improve performance";
1095 static const char h_cfg_cdda[] = "Disable CD Audio for a performance boost\n"
1096 "(proper .cue/.bin dump is needed otherwise)";
1097 static const char h_cfg_sio[] = "This should be enabled for certain memcards/gamepads";
1098 static const char h_cfg_spuirq[] = "Compatibility tweak; should probably be left off";
1099 static const char h_cfg_rcnt1[] = "Parasite Eve 2, Vandal Hearts 1/2 Fix";
1100 static const char h_cfg_rcnt2[] = "InuYasha Sengoku Battle Fix";
1101 static const char h_cfg_nodrc[] = "Disable dynamic recompiler and use interpreter\n"
1102 "Might be useful to overcome some dynarec bugs";
1104 static menu_entry e_menu_adv_options[] =
1106 mee_onoff_h ("Show CPU load", 0, g_opts, OPT_SHOWCPU, h_cfg_cpul),
1107 mee_onoff_h ("Disable Frame Limiter", 0, g_opts, OPT_NO_FRAMELIM, h_cfg_fl),
1108 mee_onoff_h ("Disable XA Decoding", 0, Config.Xa, 1, h_cfg_xa),
1109 mee_onoff_h ("Disable CD Audio", 0, Config.Cdda, 1, h_cfg_cdda),
1110 mee_onoff_h ("SIO IRQ Always Enabled", 0, Config.Sio, 1, h_cfg_sio),
1111 mee_onoff_h ("SPU IRQ Always Enabled", 0, Config.SpuIrq, 1, h_cfg_spuirq),
1112 mee_onoff_h ("Rootcounter hack", 0, Config.RCntFix, 1, h_cfg_rcnt1),
1113 mee_onoff_h ("Rootcounter hack 2", 0, Config.VSyncWA, 1, h_cfg_rcnt2),
1114 mee_onoff_h ("Disable dynarec (slow!)",0, Config.Cpu, 1, h_cfg_nodrc),
1118 static int menu_loop_adv_options(int id, int keys)
1121 me_loop(e_menu_adv_options, &sel, NULL);
1125 // ------------ options menu ------------
1127 static int mh_restore_defaults(int id, int keys)
1129 menu_set_defconfig();
1130 me_update_msg("defaults restored");
1134 static const char *men_region[] = { "Auto", "NTSC", "PAL", NULL };
1136 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
1137 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
1138 "loading state or both";
1140 static const char h_restore_def[] = "Switches back to default / recommended\n"
1143 static menu_entry e_menu_options[] =
1145 // mee_range ("Save slot", 0, state_slot, 0, 9),
1146 // mee_enum_h ("Confirm savestate", 0, dummy, men_confirm_save, h_confirm_save),
1147 mee_onoff ("Frameskip", 0, UseFrameSkip, 1),
1148 mee_onoff ("Show FPS", 0, g_opts, OPT_SHOWFPS),
1149 mee_enum ("Region", 0, region, men_region),
1150 mee_range ("CPU clock", MA_OPT_CPU_CLOCKS, cpu_clock, 20, 5000),
1151 mee_handler ("[Display]", menu_loop_gfx_options),
1152 mee_handler ("[BIOS/Plugins]", menu_loop_plugin_options),
1153 mee_handler ("[Advanced]", menu_loop_adv_options),
1154 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
1155 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
1156 mee_handler_h ("Restore default config", mh_restore_defaults, h_restore_def),
1160 static int menu_loop_options(int id, int keys)
1165 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
1166 e_menu_options[i].enabled = cpu_clock != 0 ? 1 : 0;
1167 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, ready_to_go && CdromId[0]);
1169 me_loop(e_menu_options, &sel, NULL);
1174 // ------------ debug menu ------------
1176 static void draw_frame_debug(void)
1178 smalltext_out16(4, 1, "build: "__DATE__ " " __TIME__ " " REV, 0xe7fc);
1181 static void debug_menu_loop(void)
1191 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
1192 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
1193 if (inp & PBTN_MBACK)
1198 // ------------ main menu ------------
1202 static void draw_frame_main(void)
1204 if (CdromId[0] != 0) {
1206 snprintf(buff, sizeof(buff), "%.32s/%.9s (running as %s)",
1207 get_cd_label(), CdromId, Config.PsxType ? "PAL" : "NTSC");
1208 smalltext_out16(4, 1, buff, 0x105f);
1212 static void draw_frame_credits(void)
1214 smalltext_out16(4, 1, "build: "__DATE__ " " __TIME__ " " REV, 0xe7fc);
1217 const char *plat_get_credits(void)
1219 return "PCSX-ReARMed\n\n"
1220 "(C) 1999-2003 PCSX Team\n"
1221 "(C) 2005-2009 PCSX-df Team\n"
1222 "(C) 2009-2011 PCSX-Reloaded Team\n\n"
1223 "GPU and SPU code by Pete Bernert\n"
1224 " and the P.E.Op.S. team\n"
1225 "ARM recompiler (C) 2009-2011 Ari64\n"
1226 "PCSX4ALL plugins by PCSX4ALL team\n"
1227 " Chui, Franxis, Unai\n\n"
1228 "integration, optimization and\n"
1229 " frontend (C) 2010-2011 notaz\n";
1232 static int reset_game(void)
1235 if (bios_sel == 0 && !Config.HLE)
1241 if (CheckCdrom() != -1) {
1247 static int run_bios(void)
1253 pl_fbdev_buf = NULL;
1259 if (OpenPlugins() == -1) {
1260 me_update_msg("failed to open plugins");
1263 plugin_call_rearmed_cbs();
1266 CdromLabel[0] = '\0';
1274 static int run_cd_image(const char *fname)
1277 pl_fbdev_buf = NULL;
1280 set_cd_image(fname);
1283 if (OpenPlugins() == -1) {
1284 me_update_msg("failed to open plugins");
1287 plugin_call_rearmed_cbs();
1289 if (CheckCdrom() == -1) {
1290 // Only check the CD if we are starting the console with a CD
1292 me_update_msg("unsupported/invalid CD image");
1298 // Read main executable directly from CDRom and start it
1299 if (LoadCdrom() == -1) {
1301 me_update_msg("failed to load CD image");
1309 static int romsel_run(void)
1311 int prev_gpu, prev_spu;
1314 fname = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
1318 printf("selected file: %s\n", fname);
1320 if (run_cd_image(fname) != 0)
1323 prev_gpu = gpu_plugsel;
1324 prev_spu = spu_plugsel;
1325 if (menu_load_config(1) != 0)
1326 menu_load_config(0);
1328 // check for plugin changes, have to repeat
1329 // loading if game config changed plugins to reload them
1330 if (prev_gpu != gpu_plugsel || prev_spu != spu_plugsel) {
1331 printf("plugin change detected, reloading plugins..\n");
1332 if (run_cd_image(fname) != 0)
1336 strcpy(last_selected_fname, rom_fname_reload);
1340 static int swap_cd_image(void)
1344 fname = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
1348 printf("selected file: %s\n", fname);
1351 CdromLabel[0] = '\0';
1353 set_cd_image(fname);
1354 if (ReloadCdromPlugin() < 0) {
1355 me_update_msg("failed to load cdr plugin");
1358 if (CDR_open() < 0) {
1359 me_update_msg("failed to open cdr plugin");
1363 SetCdOpenCaseTime(time(NULL) + 2);
1366 strcpy(last_selected_fname, rom_fname_reload);
1370 static int main_menu_handler(int id, int keys)
1374 case MA_MAIN_RESUME_GAME:
1378 case MA_MAIN_SAVE_STATE:
1380 return menu_loop_savestate(0);
1382 case MA_MAIN_LOAD_STATE:
1384 return menu_loop_savestate(1);
1386 case MA_MAIN_RESET_GAME:
1387 if (ready_to_go && reset_game() == 0)
1390 case MA_MAIN_LOAD_ROM:
1391 if (romsel_run() == 0)
1394 case MA_MAIN_SWAP_CD:
1395 if (swap_cd_image() == 0)
1398 case MA_MAIN_RUN_BIOS:
1399 if (run_bios() == 0)
1402 case MA_MAIN_CREDITS:
1403 draw_menu_credits(draw_frame_credits);
1404 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
1410 lprintf("%s: something unknown selected\n", __FUNCTION__);
1417 static menu_entry e_menu_main[] =
1421 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
1422 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
1423 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
1424 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
1425 mee_handler_id("Load CD image", MA_MAIN_LOAD_ROM, main_menu_handler),
1426 mee_handler_id("Change CD image", MA_MAIN_SWAP_CD, main_menu_handler),
1427 mee_handler_id("Run BIOS", MA_MAIN_RUN_BIOS, main_menu_handler),
1428 mee_handler ("Options", menu_loop_options),
1429 mee_handler ("Controls", menu_loop_keyconfig),
1430 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
1431 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
1435 // ----------------------------
1437 static void menu_leave_emu(void);
1439 void menu_loop(void)
1445 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, ready_to_go);
1446 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, ready_to_go && CdromId[0]);
1447 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, ready_to_go && CdromId[0]);
1448 me_enable(e_menu_main, MA_MAIN_RESET_GAME, ready_to_go);
1449 me_enable(e_menu_main, MA_MAIN_SWAP_CD, ready_to_go);
1450 me_enable(e_menu_main, MA_MAIN_RUN_BIOS, bios_sel != 0);
1452 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1455 me_loop(e_menu_main, &sel, draw_frame_main);
1456 } while (!ready_to_go);
1458 /* wait until menu, ok, back is released */
1459 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1462 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1467 static void scan_bios_plugins(void)
1469 char fname[MAXPATHLEN];
1471 int bios_i, gpu_i, spu_i;
1476 gpu_plugins[0] = "builtin_gpu";
1477 spu_plugins[0] = "builtin_spu";
1478 bios_i = gpu_i = spu_i = 1;
1480 snprintf(fname, sizeof(fname), "%s/", Config.BiosDir);
1481 dir = opendir(fname);
1483 perror("scan_bios_plugins bios opendir");
1498 if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
1501 snprintf(fname, sizeof(fname), "%s/%s", Config.BiosDir, ent->d_name);
1502 if (stat(fname, &st) != 0 || st.st_size != 512*1024) {
1503 printf("bad BIOS file: %s\n", ent->d_name);
1507 if (bios_i < ARRAY_SIZE(bioses) - 1) {
1508 bioses[bios_i++] = strdup(ent->d_name);
1512 printf("too many BIOSes, dropping \"%s\"\n", ent->d_name);
1518 snprintf(fname, sizeof(fname), "%s/", Config.PluginsDir);
1519 dir = opendir(fname);
1521 perror("scan_bios_plugins opendir");
1535 p = strstr(ent->d_name, ".so");
1539 snprintf(fname, sizeof(fname), "%s/%s", Config.PluginsDir, ent->d_name);
1540 h = dlopen(fname, RTLD_LAZY | RTLD_LOCAL);
1542 fprintf(stderr, "%s\n", dlerror());
1546 // now what do we have here?
1547 tmp = dlsym(h, "GPUinit");
1550 if (gpu_i < ARRAY_SIZE(gpu_plugins) - 1)
1551 gpu_plugins[gpu_i++] = strdup(ent->d_name);
1555 tmp = dlsym(h, "SPUinit");
1558 if (spu_i < ARRAY_SIZE(spu_plugins) - 1)
1559 spu_plugins[spu_i++] = strdup(ent->d_name);
1563 fprintf(stderr, "ignoring unidentified plugin: %s\n", fname);
1570 void menu_init(void)
1572 char buff[MAXPATHLEN];
1574 strcpy(last_selected_fname, "/media");
1576 scan_bios_plugins();
1580 menu_set_defconfig();
1581 menu_load_config(0);
1586 g_menubg_src_ptr = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
1587 if (g_menubg_src_ptr == NULL)
1589 emu_make_path(buff, "skin/background.png", sizeof(buff));
1590 readpng(g_menubg_src_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h);
1593 void menu_notify_mode_change(int w, int h, int bpp)
1599 if (scaling == SCALE_1_1) {
1600 g_layer_x = 800/2 - w/2; g_layer_y = 480/2 - h/2;
1601 g_layer_w = w; g_layer_h = h;
1605 static void menu_leave_emu(void)
1607 if (GPU_close != NULL) {
1608 int ret = GPU_close();
1610 fprintf(stderr, "Warning: GPU_close returned %d\n", ret);
1613 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
1614 if (pl_fbdev_buf != NULL && ready_to_go && last_psx_bpp == 16) {
1615 int x = max(0, g_menuscreen_w - last_psx_w);
1616 int y = max(0, g_menuscreen_h / 2 - last_psx_h / 2);
1617 int w = min(g_menuscreen_w, last_psx_w);
1618 int h = min(g_menuscreen_h, last_psx_h);
1619 u16 *d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
1620 u16 *s = pl_fbdev_buf;
1622 for (; h > 0; h--, d += g_menuscreen_w, s += last_psx_w)
1623 menu_darken_bg(d, s, w, 0);
1627 cpu_clock = get_cpu_clock();
1629 plat_video_menu_enter(ready_to_go);
1632 void menu_prepare_emu(void)
1634 R3000Acpu *prev_cpu = psxCpu;
1636 plat_video_menu_leave();
1640 menu_notify_mode_change(last_psx_w, last_psx_h, last_psx_bpp);
1643 g_layer_x = 80; g_layer_y = 0;
1644 g_layer_w = 640; g_layer_h = 480;
1646 case SCALE_FULLSCREEN:
1647 g_layer_x = 0; g_layer_y = 0;
1648 g_layer_w = 800; g_layer_h = 480;
1653 apply_filter(filter);
1656 psxCpu = (Config.Cpu == CPU_INTERPRETER) ? &psxInt : &psxRec;
1657 if (psxCpu != prev_cpu)
1658 // note that this does not really reset, just clears drc caches
1661 // core doesn't care about Config.Cdda changes,
1662 // so handle them manually here
1668 if (GPU_open != NULL) {
1669 int ret = GPU_open(&gpuDisp, "PCSX", NULL);
1671 fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
1675 void me_update_msg(const char *msg)
1677 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1678 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1680 menu_error_time = plat_get_ticks_ms();
1681 lprintf("msg: %s\n", menu_error_msg);