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/new_dynarec/new_dynarec.h"
29 #define array_size(x) (sizeof(x) / sizeof(x[0]))
61 static int last_psx_w, last_psx_h, last_psx_bpp;
62 static int scaling, filter, state_slot, cpu_clock, cpu_clock_st;
63 static char rom_fname_reload[MAXPATHLEN];
64 static char last_selected_fname[MAXPATHLEN];
67 // from softgpu plugin
68 extern int iUseDither;
69 extern int UseFrameSkip;
70 extern int UseFrameLimit;
71 extern uint32_t dwActFixes;
72 extern float fFrameRateHz;
73 extern int dwFrameRateTicks;
76 extern int iUseReverb;
77 extern int iUseInterpolation;
79 extern int iSPUIRQWait;
82 static const char *bioses[24];
83 static const char *gpu_plugins[16];
84 static const char *spu_plugins[16];
85 static int bios_sel, gpu_plugsel, spu_plugsel;
88 static int min(int x, int y) { return x < y ? x : y; }
89 static int max(int x, int y) { return x > y ? x : y; }
91 void emu_make_path(char *buff, const char *end, int size)
95 end_len = strlen(end);
96 pos = plat_get_root_dir(buff, size);
97 strncpy(buff + pos, end, size - pos);
99 if (pos + end_len > size - 1)
100 printf("Warning: path truncated: %s\n", buff);
103 static int emu_check_save_file(int slot)
105 char fname[MAXPATHLEN];
108 ret = get_state_filename(fname, sizeof(fname), slot);
112 ret = CheckState(fname);
113 return ret == 0 ? 1 : 0;
116 static int emu_save_load_game(int load, int sram)
118 char fname[MAXPATHLEN];
121 ret = get_state_filename(fname, sizeof(fname), state_slot);
126 ret = LoadState(fname);
128 ret = SaveState(fname);
133 static void menu_set_defconfig(void)
137 Config.Xa = Config.Cdda = Config.Sio =
138 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
140 iUseDither = UseFrameSkip = 0;
145 iUseInterpolation = 1;
146 iXAPitch = iSPUIRQWait = 0;
150 #define CE_CONFIG_STR(val) \
151 { #val, 0, Config.val }
153 #define CE_CONFIG_VAL(val) \
154 { #val, sizeof(Config.val), &Config.val }
156 #define CE_STR(val) \
159 #define CE_INTVAL(val) \
160 { #val, sizeof(val), &val }
162 static const struct {
174 CE_CONFIG_VAL(PsxAuto),
176 CE_CONFIG_VAL(Debug),
177 CE_CONFIG_VAL(PsxOut),
178 CE_CONFIG_VAL(SpuIrq),
179 CE_CONFIG_VAL(RCntFix),
180 CE_CONFIG_VAL(VSyncWA),
182 CE_CONFIG_VAL(PsxType),
184 CE_INTVAL(g_layer_x),
185 CE_INTVAL(g_layer_y),
186 CE_INTVAL(g_layer_w),
187 CE_INTVAL(g_layer_h),
189 CE_INTVAL(state_slot),
190 CE_INTVAL(cpu_clock),
192 CE_INTVAL(iUseDither),
193 CE_INTVAL(UseFrameSkip),
194 CE_INTVAL(UseFrameLimit),
195 CE_INTVAL(dwActFixes),
196 CE_INTVAL(iUseReverb),
197 CE_INTVAL(iUseInterpolation),
199 CE_INTVAL(iSPUIRQWait),
200 CE_INTVAL(iUseTimer),
203 static void make_cfg_fname(char *buf, size_t size, int is_game)
208 strncpy(trimlabel, CdromLabel, 32);
210 for (j = 31; j >= 0; j--)
211 if (trimlabel[j] == ' ')
215 snprintf(buf, size, "." PCSX_DOT_DIR "cfg/%.32s-%.9s.cfg", trimlabel, CdromId);
217 snprintf(buf, size, "." PCSX_DOT_DIR "%s", cfgfile_basename);
220 static int menu_write_config(int is_game)
222 char cfgfile[MAXPATHLEN];
226 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
227 f = fopen(cfgfile, "w");
229 printf("menu_write_config: failed to open: %s\n", cfgfile);
233 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
234 fprintf(f, "%s = ", config_data[i].name);
235 switch (config_data[i].len) {
237 fprintf(f, "%s\n", (char *)config_data[i].val);
240 fprintf(f, "%x\n", *(u8 *)config_data[i].val);
243 fprintf(f, "%x\n", *(u16 *)config_data[i].val);
246 fprintf(f, "%x\n", *(u32 *)config_data[i].val);
249 printf("menu_write_config: unhandled len %d for %s\n",
250 config_data[i].len, config_data[i].name);
256 fprintf(f, "lastcdimg = %s\n", last_selected_fname);
262 static void parse_str_val(char *cval, const char *src)
265 strncpy(cval, src, MAXPATHLEN);
266 cval[MAXPATHLEN - 1] = 0;
267 tmp = strchr(cval, '\n');
269 tmp = strchr(cval, '\r');
274 static int menu_load_config(int is_game)
276 char cfgfile[MAXPATHLEN];
282 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
283 f = fopen(cfgfile, "r");
285 printf("menu_load_config: failed to open: %s\n", cfgfile);
289 fseek(f, 0, SEEK_END);
292 printf("bad size %ld: %s\n", size, cfgfile);
296 cfg = malloc(size + 1);
300 fseek(f, 0, SEEK_SET);
301 if (fread(cfg, 1, size, f) != size) {
302 printf("failed to read: %s\n", cfgfile);
307 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
311 tmp = strstr(cfg, config_data[i].name);
314 tmp += strlen(config_data[i].name);
315 if (strncmp(tmp, " = ", 3) != 0)
319 if (config_data[i].len == 0) {
320 parse_str_val(config_data[i].val, tmp);
325 val = strtoul(tmp, &tmp2, 16);
326 if (tmp2 == NULL || tmp == tmp2)
327 continue; // parse failed
329 switch (config_data[i].len) {
331 *(u8 *)config_data[i].val = val;
334 *(u16 *)config_data[i].val = val;
337 *(u32 *)config_data[i].val = val;
340 printf("menu_load_config: unhandled len %d for %s\n",
341 config_data[i].len, config_data[i].name);
347 char *tmp = strstr(cfg, "lastcdimg = ");
350 parse_str_val(last_selected_fname, tmp);
355 for (i = bios_sel = 0; bioses[i] != NULL; i++)
356 if (strcmp(Config.Bios, bioses[i]) == 0)
357 { bios_sel = i; break; }
359 for (i = gpu_plugsel = 0; gpu_plugins[i] != NULL; i++)
360 if (strcmp(Config.Gpu, gpu_plugins[i]) == 0)
361 { gpu_plugsel = i; break; }
363 for (i = spu_plugsel = 0; spu_plugins[i] != NULL; i++)
364 if (strcmp(Config.Spu, spu_plugins[i]) == 0)
365 { spu_plugsel = i; break; }
375 // rrrr rggg gggb bbbb
376 static unsigned short fname2color(const char *fname)
378 static const char *cdimg_exts[] = { ".bin", ".img", ".iso", ".z", ".cue" };
379 static const char *other_exts[] = { ".ccd", ".toc", ".mds", ".sub", ".table" };
380 const char *ext = strrchr(fname, '.');
385 for (i = 0; i < array_size(cdimg_exts); i++)
386 if (strcasecmp(ext, cdimg_exts[i]) == 0)
388 for (i = 0; i < array_size(other_exts); i++)
389 if (strcasecmp(ext, other_exts[i]) == 0)
394 static void draw_savestate_bg(int slot);
396 #define MENU_ALIGN_LEFT
397 #define menu_init menu_init_common
398 #include "common/menu.c"
401 // a bit of black magic here
402 static void draw_savestate_bg(int slot)
404 extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
405 static const int psx_widths[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
407 char fname[MAXPATHLEN];
414 ret = get_state_filename(fname, sizeof(fname), slot);
418 f = gzopen(fname, "rb");
422 if (gzseek(f, 0x29933d, SEEK_SET) != 0x29933d) {
423 fprintf(stderr, "gzseek failed\n");
428 gpu = malloc(sizeof(*gpu));
434 ret = gzread(f, gpu, sizeof(*gpu));
436 if (ret != sizeof(*gpu)) {
437 fprintf(stderr, "gzread failed\n");
441 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
443 if ((gpu->ulStatus & 0x800000) || (gpu->ulStatus & 0x200000))
444 goto out; // disabled || 24bpp (NYET)
446 x = gpu->ulControl[5] & 0x3ff;
447 y = (gpu->ulControl[5] >> 10) & 0x1ff;
448 s = (u16 *)gpu->psxVRam + y * 1024 + (x & ~3);
449 w = psx_widths[(gpu->ulStatus >> 16) & 7];
450 tmp = gpu->ulControl[7];
451 h = ((tmp >> 10) & 0x3ff) - (tmp & 0x3ff);
452 if (gpu->ulStatus & 0x80000) // doubleheight
455 x = max(0, g_menuscreen_w - w) & ~3;
456 y = max(0, g_menuscreen_h / 2 - h / 2);
457 w = min(g_menuscreen_w, w);
458 h = min(g_menuscreen_h, h);
459 d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
461 for (; h > 0; h--, d += g_menuscreen_w, s += 1024)
462 bgr555_to_rgb565(d, s, w * 2);
468 // ---------- pandora specific -----------
470 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
471 static char **pnd_filter_list;
473 static int get_cpu_clock(void)
477 f = fopen("/proc/pandora/cpu_mhz_max", "r");
479 fscanf(f, "%d", &ret);
485 static void apply_cpu_clock(void)
489 if (cpu_clock != 0 && cpu_clock != get_cpu_clock()) {
490 snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
491 pnd_script_base, cpu_clock);
496 static void apply_filter(int which)
502 if (pnd_filter_list == NULL || which == old)
505 for (i = 0; i < which; i++)
506 if (pnd_filter_list[i] == NULL)
509 if (pnd_filter_list[i] == NULL)
512 snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]);
517 static menu_entry e_menu_gfx_options[];
519 static void pnd_menu_init(void)
527 cpu_clock_st = cpu_clock = get_cpu_clock();
529 dir = opendir("/etc/pandora/conf/dss_fir");
531 perror("filter opendir");
543 p = strstr(ent->d_name, "_up");
544 if (p != NULL && (p[3] == 0 || !strcmp(p + 3, "_h")))
551 mfilters = calloc(count + 1, sizeof(mfilters[0]));
552 if (mfilters == NULL)
556 for (i = 0; (ent = readdir(dir)); ) {
559 p = strstr(ent->d_name, "_up");
560 if (p == NULL || (p[3] != 0 && strcmp(p + 3, "_h")))
563 len = p - ent->d_name;
564 if (len > sizeof(buff) - 1)
567 strncpy(buff, ent->d_name, len);
569 mfilters[i] = strdup(buff);
570 if (mfilters[i] != NULL)
575 i = me_id2offset(e_menu_gfx_options, MA_OPT_FILTERING);
576 e_menu_gfx_options[i].data = (void *)mfilters;
577 pnd_filter_list = mfilters;
580 void menu_finish(void)
582 cpu_clock = cpu_clock_st;
586 // -------------- key config --------------
588 me_bind_action me_ctrl_actions[] =
590 { "UP ", 1 << DKEY_UP},
591 { "DOWN ", 1 << DKEY_DOWN },
592 { "LEFT ", 1 << DKEY_LEFT },
593 { "RIGHT ", 1 << DKEY_RIGHT },
594 { "TRIANGLE", 1 << DKEY_TRIANGLE },
595 { "CIRCLE ", 1 << DKEY_CIRCLE },
596 { "CROSS ", 1 << DKEY_CROSS },
597 { "SQUARE ", 1 << DKEY_SQUARE },
598 { "L1 ", 1 << DKEY_L1 },
599 { "R1 ", 1 << DKEY_R1 },
600 { "L2 ", 1 << DKEY_L2 },
601 { "R2 ", 1 << DKEY_R2 },
602 { "START ", 1 << DKEY_START },
603 { "SELECT ", 1 << DKEY_SELECT },
607 me_bind_action emuctrl_actions[] =
610 { "Load State ", PEV_STATE_LOAD },
611 { "Save State ", PEV_STATE_SAVE },
612 { "Prev Save Slot ", PEV_SSLOT_PREV },
613 { "Next Save Slot ", PEV_SSLOT_NEXT },
615 { "Enter Menu ", PEV_MENU },
619 static int key_config_loop_wrap(int id, int keys)
622 case MA_CTRL_PLAYER1:
623 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
625 case MA_CTRL_PLAYER2:
626 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
629 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
637 static const char *mgn_dev_name(int id, int *offs)
639 const char *name = NULL;
642 if (id == MA_CTRL_DEV_FIRST)
645 for (; it < IN_MAX_DEVS; it++) {
646 name = in_get_dev_name(it, 1, 1);
655 static const char *mgn_saveloadcfg(int id, int *offs)
660 static int mh_savecfg(int id, int keys)
662 if (menu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0) == 0)
663 me_update_msg("config saved");
665 me_update_msg("failed to write config");
670 static menu_entry e_menu_keyconfig[] =
672 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
673 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
674 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
675 // mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
676 // mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
678 mee_label ("Input devices:"),
679 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
680 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
681 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
682 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
683 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
684 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
685 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
689 static int menu_loop_keyconfig(int id, int keys)
693 // me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, ready_to_go);
694 me_loop(e_menu_keyconfig, &sel, NULL);
698 // ------------ gfx options menu ------------
700 static const char *men_scaler[] = { "1x1", "scaled 4:3", "fullscreen", "custom", NULL };
701 static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n"
702 "using d-pad or move it using R+d-pad";
703 static const char *men_dummy[] = { NULL };
705 static int menu_loop_cscaler(int id, int keys)
709 scaling = SCALE_CUSTOM;
711 omap_enable_layer(1);
716 memset(g_menuscreen_ptr, 4, g_menuscreen_w * g_menuscreen_h * 2);
717 text_out16(2, 2, "%d,%d", g_layer_x, g_layer_y);
718 text_out16(2, 480 - 18, "%dx%d | d-pad: resize, R+d-pad: move", g_layer_w, g_layer_h);
721 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40);
722 if (inp & PBTN_UP) g_layer_y--;
723 if (inp & PBTN_DOWN) g_layer_y++;
724 if (inp & PBTN_LEFT) g_layer_x--;
725 if (inp & PBTN_RIGHT) g_layer_x++;
726 if (!(inp & PBTN_R)) {
727 if (inp & PBTN_UP) g_layer_h += 2;
728 if (inp & PBTN_DOWN) g_layer_h -= 2;
729 if (inp & PBTN_LEFT) g_layer_w += 2;
730 if (inp & PBTN_RIGHT) g_layer_w -= 2;
732 if (inp & (PBTN_MOK|PBTN_MBACK))
735 if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
736 if (g_layer_x < 0) g_layer_x = 0;
737 if (g_layer_x > 640) g_layer_x = 640;
738 if (g_layer_y < 0) g_layer_y = 0;
739 if (g_layer_y > 420) g_layer_y = 420;
740 if (g_layer_w < 160) g_layer_w = 160;
741 if (g_layer_h < 60) g_layer_h = 60;
742 if (g_layer_x + g_layer_w > 800)
743 g_layer_w = 800 - g_layer_x;
744 if (g_layer_y + g_layer_h > 480)
745 g_layer_h = 480 - g_layer_y;
746 omap_enable_layer(1);
750 omap_enable_layer(0);
755 static menu_entry e_menu_gfx_options[] =
757 mee_enum ("Scaler", 0, scaling, men_scaler),
758 mee_enum ("Filter", MA_OPT_FILTERING, filter, men_dummy),
759 // mee_onoff ("Vsync", 0, vsync, 1),
760 mee_cust_h ("Setup custom scaler", 0, menu_loop_cscaler, NULL, h_cscaler),
764 static int menu_loop_gfx_options(int id, int keys)
768 me_loop(e_menu_gfx_options, &sel, NULL);
773 // ------------ bios/plugins ------------
775 static const char *men_gpu_dithering[] = { "None", "Game dependant", "Always", NULL };
776 static const char h_gpu_0[] = "Needed for Chrono Cross";
777 static const char h_gpu_1[] = "Capcom fighting games";
778 static const char h_gpu_2[] = "Black screens in Lunar";
779 static const char h_gpu_3[] = "Compatibility mode";
780 static const char h_gpu_6[] = "Pandemonium 2";
781 static const char h_gpu_7[] = "Skip every second frame";
782 static const char h_gpu_8[] = "Needed by Dark Forces";
783 static const char h_gpu_9[] = "better g-colors, worse textures";
784 static const char h_gpu_10[] = "Toggle busy flags after drawing";
786 static menu_entry e_menu_plugin_gpu[] =
788 mee_enum ("Dithering", 0, iUseDither, men_gpu_dithering),
789 mee_onoff_h ("Odd/even bit hack", 0, dwActFixes, 1<<0, h_gpu_0),
790 mee_onoff_h ("Expand screen width", 0, dwActFixes, 1<<1, h_gpu_1),
791 mee_onoff_h ("Ignore brightness color", 0, dwActFixes, 1<<2, h_gpu_2),
792 mee_onoff_h ("Disable coordinate check", 0, dwActFixes, 1<<3, h_gpu_3),
793 mee_onoff_h ("Lazy screen update", 0, dwActFixes, 1<<6, h_gpu_6),
794 mee_onoff_h ("Old frame skipping", 0, dwActFixes, 1<<7, h_gpu_7),
795 mee_onoff_h ("Repeated flat tex triangles ",0,dwActFixes, 1<<8, h_gpu_8),
796 mee_onoff_h ("Draw quads with triangles", 0, dwActFixes, 1<<9, h_gpu_9),
797 mee_onoff_h ("Fake 'gpu busy' states", 0, dwActFixes, 1<<10, h_gpu_10),
801 static int menu_loop_plugin_gpu(int id, int keys)
804 me_loop(e_menu_plugin_gpu, &sel, NULL);
808 static const char *men_spu_reverb[] = { "Off", "Fake", "On", NULL };
809 static const char *men_spu_interp[] = { "None", "Simple", "Gaussian", "Cubic", NULL };
810 static const char h_spu_irq_wait[] = "Wait for CPU; only useful for some games, may cause glitches";
811 static const char h_spu_thread[] = "Run sound emulation in separate thread";
813 static menu_entry e_menu_plugin_spu[] =
815 mee_enum ("Reverb", 0, iUseReverb, men_spu_reverb),
816 mee_enum ("Interpolation", 0, iUseInterpolation, men_spu_interp),
817 mee_onoff ("Adjust XA pitch", 0, iXAPitch, 1),
818 mee_onoff_h ("SPU IRQ Wait", 0, iSPUIRQWait, 1, h_spu_irq_wait),
819 mee_onoff_h ("Use sound thread", 0, iUseTimer, 1, h_spu_thread),
823 static int menu_loop_plugin_spu(int id, int keys)
826 me_loop(e_menu_plugin_spu, &sel, NULL);
830 static const char h_bios[] = "HLE is simulated BIOS. BIOS is saved in savestates.\n"
831 "Must save config and reload the game\n"
832 "for change to take effect";
833 static const char h_plugin_xpu[] = "Must save config and reload the game\n"
834 "for plugin change to take effect";
835 static const char h_gpu[] = "Configure built-in P.E.Op.S. SoftGL Driver V1.17";
836 static const char h_spu[] = "Configure built-in P.E.Op.S. Sound Driver V1.7";
838 static menu_entry e_menu_plugin_options[] =
840 mee_enum_h ("BIOS", 0, bios_sel, bioses, h_bios),
841 mee_enum_h ("GPU plugin", 0, gpu_plugsel, gpu_plugins, h_plugin_xpu),
842 mee_enum_h ("SPU plugin", 0, spu_plugsel, spu_plugins, h_plugin_xpu),
843 mee_handler_h ("Configure built-in GPU plugin", menu_loop_plugin_gpu, h_gpu),
844 mee_handler_h ("Configure built-in SPU plugin", menu_loop_plugin_spu, h_spu),
848 static int menu_loop_plugin_options(int id, int keys)
851 me_loop(e_menu_plugin_options, &sel, NULL);
854 snprintf(Config.Bios, sizeof(Config.Bios), "%s", bioses[bios_sel]);
855 snprintf(Config.Gpu, sizeof(Config.Gpu), "%s", gpu_plugins[gpu_plugsel]);
856 snprintf(Config.Spu, sizeof(Config.Spu), "%s", spu_plugins[spu_plugsel]);
861 // ------------ adv options menu ------------
863 static const char h_cfg_cpul[] = "Shows CPU usage in %%";
864 static const char h_cfg_fl[] = "Keeps the game from running too fast";
865 static const char h_cfg_xa[] = "Disables XA sound, which can sometimes improve performance";
866 static const char h_cfg_cdda[] = "Disable CD Audio for a performance boost\n"
867 "(proper .cue/.bin dump is needed otherwise)";
868 static const char h_cfg_sio[] = "This should be enabled for certain memcards/gamepads";
869 static const char h_cfg_spuirq[] = "Compatibility tweak; should probably be left off";
870 static const char h_cfg_rcnt1[] = "Parasite Eve 2, Vandal Hearts 1/2 Fix";
871 static const char h_cfg_rcnt2[] = "InuYasha Sengoku Battle Fix";
873 static menu_entry e_menu_adv_options[] =
875 mee_onoff_h ("Show CPU load", 0, g_opts, OPT_SHOWCPU, h_cfg_cpul),
876 mee_onoff_h ("Frame Limiter", 0, UseFrameLimit, 1, h_cfg_fl),
877 mee_onoff_h ("Disable XA Decoding", 0, Config.Xa, 1, h_cfg_xa),
878 mee_onoff_h ("Disable CD Audio", 0, Config.Cdda, 1, h_cfg_cdda),
879 mee_onoff_h ("SIO IRQ Always Enabled", 0, Config.Sio, 1, h_cfg_sio),
880 mee_onoff_h ("SPU IRQ Always Enabled", 0, Config.SpuIrq, 1, h_cfg_spuirq),
881 mee_onoff_h ("Rootcounter hack", 0, Config.RCntFix, 1, h_cfg_rcnt1),
882 mee_onoff_h ("Rootcounter hack 2", 0, Config.VSyncWA, 1, h_cfg_rcnt2),
886 static int menu_loop_adv_options(int id, int keys)
889 me_loop(e_menu_adv_options, &sel, NULL);
893 // ------------ options menu ------------
895 static int mh_restore_defaults(int id, int keys)
897 menu_set_defconfig();
898 me_update_msg("defaults restored");
902 static const char *men_region[] = { "NTSC", "PAL", NULL };
904 static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
905 static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
906 "loading state or both";
908 static const char h_restore_def[] = "Switches back to default / recommended\n"
911 static menu_entry e_menu_options[] =
913 // mee_range ("Save slot", 0, state_slot, 0, 9),
914 // mee_enum_h ("Confirm savestate", 0, dummy, men_confirm_save, h_confirm_save),
915 mee_onoff ("Frameskip", 0, UseFrameSkip, 1),
916 mee_onoff ("Show FPS", 0, g_opts, OPT_SHOWFPS),
917 mee_enum ("Region", 0, Config.PsxType, men_region),
918 mee_range ("CPU clock", MA_OPT_CPU_CLOCKS, cpu_clock, 20, 5000),
919 mee_handler ("[Display]", menu_loop_gfx_options),
920 mee_handler ("[BIOS/Plugins]", menu_loop_plugin_options),
921 mee_handler ("[Advanced]", menu_loop_adv_options),
922 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
923 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
924 mee_handler_h ("Restore default config", mh_restore_defaults, h_restore_def),
928 static int menu_loop_options(int id, int keys)
933 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
934 e_menu_options[i].enabled = cpu_clock != 0 ? 1 : 0;
935 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, ready_to_go);
937 me_loop(e_menu_options, &sel, NULL);
942 // ------------ debug menu ------------
944 static void draw_frame_debug(void)
946 smalltext_out16(4, 1, "build: "__DATE__ " " __TIME__ " " REV, 0xe7fc);
949 static void debug_menu_loop(void)
959 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
960 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
961 if (inp & PBTN_MBACK)
966 // ------------ main menu ------------
970 const char *plat_get_credits(void)
972 return "PCSX-ReARMed\n\n"
973 "(C) 1999-2003 PCSX Team\n"
974 "(C) 2005-2009 PCSX-df Team\n"
975 "(C) 2009-2010 PCSX-Reloaded Team\n\n"
976 "GPU and SPU code by Pete Bernert\n"
977 " and the P.E.Op.S. team\n"
978 "ARM recompiler (C) 2009-2010 Ari64\n"
979 "PCSX4ALL plugins by PCSX4ALL team\n"
980 " Chui, Franxis, Unai\n\n"
981 "integration, optimization and\n"
982 " frontend (C) 2010-2011 notaz\n";
985 static int run_cd_image(const char *fname)
987 extern void set_cd_image(const char *fname);
995 if (OpenPlugins() == -1) {
996 me_update_msg("failed to open plugins");
999 plugin_call_rearmed_cbs();
1001 if (CheckCdrom() == -1) {
1002 // Only check the CD if we are starting the console with a CD
1004 me_update_msg("unsupported/invalid CD image");
1010 // Read main executable directly from CDRom and start it
1011 if (LoadCdrom() == -1) {
1013 me_update_msg("failed to load CD image");
1021 static int romsel_run(void)
1023 int prev_gpu, prev_spu;
1026 fname = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
1030 printf("selected file: %s\n", fname);
1032 if (run_cd_image(fname) != 0)
1035 prev_gpu = gpu_plugsel;
1036 prev_spu = spu_plugsel;
1037 if (menu_load_config(1) != 0)
1038 menu_load_config(0);
1040 // check for plugin changes, have to repeat
1041 // loading if game config changed plugins to reload them
1042 if (prev_gpu != gpu_plugsel || prev_spu != spu_plugsel) {
1043 printf("plugin change detected, reloading plugins..\n");
1044 if (run_cd_image(fname) != 0)
1048 strcpy(last_selected_fname, rom_fname_reload);
1052 static int main_menu_handler(int id, int keys)
1056 case MA_MAIN_RESUME_GAME:
1060 case MA_MAIN_SAVE_STATE:
1062 return menu_loop_savestate(0);
1064 case MA_MAIN_LOAD_STATE:
1066 return menu_loop_savestate(1);
1068 case MA_MAIN_RESET_GAME:
1073 if (CheckCdrom() != -1) {
1079 case MA_MAIN_LOAD_ROM:
1080 if (romsel_run() == 0)
1083 case MA_MAIN_CREDITS:
1084 draw_menu_credits(draw_frame_debug);
1085 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
1091 lprintf("%s: something unknown selected\n", __FUNCTION__);
1098 static menu_entry e_menu_main[] =
1102 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
1103 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
1104 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
1105 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
1106 mee_handler_id("Load CD image", MA_MAIN_LOAD_ROM, main_menu_handler),
1107 mee_handler ("Options", menu_loop_options),
1108 mee_handler ("Controls", menu_loop_keyconfig),
1109 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
1110 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
1114 // ----------------------------
1116 static void menu_leave_emu(void);
1118 void menu_loop(void)
1124 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, ready_to_go);
1125 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, ready_to_go);
1126 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, ready_to_go);
1127 me_enable(e_menu_main, MA_MAIN_RESET_GAME, ready_to_go);
1129 // menu_enter(ready_to_go);
1130 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1133 me_loop(e_menu_main, &sel, NULL);
1134 } while (!ready_to_go);
1136 /* wait until menu, ok, back is released */
1137 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1140 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1145 static void scan_bios_plugins(void)
1147 char fname[MAXPATHLEN];
1149 int bios_i, gpu_i, spu_i;
1154 gpu_plugins[0] = "builtin_gpu";
1155 spu_plugins[0] = "builtin_spu";
1156 bios_i = gpu_i = spu_i = 1;
1158 snprintf(fname, sizeof(fname), "%s/", Config.BiosDir);
1159 dir = opendir(fname);
1161 perror("scan_bios_plugins bios opendir");
1176 if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
1179 snprintf(fname, sizeof(fname), "%s/%s", Config.BiosDir, ent->d_name);
1180 if (stat(fname, &st) != 0 || st.st_size != 512*1024) {
1181 printf("bad BIOS file: %s\n", ent->d_name);
1185 if (bios_i < ARRAY_SIZE(bioses) - 1) {
1186 bioses[bios_i++] = strdup(ent->d_name);
1190 printf("too many BIOSes, dropping \"%s\"\n", ent->d_name);
1196 snprintf(fname, sizeof(fname), "%s/", Config.PluginsDir);
1197 dir = opendir(fname);
1199 perror("scan_bios_plugins opendir");
1213 p = strstr(ent->d_name, ".so");
1217 snprintf(fname, sizeof(fname), "%s/%s", Config.PluginsDir, ent->d_name);
1218 h = dlopen(fname, RTLD_LAZY | RTLD_LOCAL);
1220 fprintf(stderr, "%s\n", dlerror());
1224 // now what do we have here?
1225 tmp = dlsym(h, "GPUinit");
1228 if (gpu_i < ARRAY_SIZE(gpu_plugins) - 1)
1229 gpu_plugins[gpu_i++] = strdup(ent->d_name);
1233 tmp = dlsym(h, "SPUinit");
1236 if (spu_i < ARRAY_SIZE(spu_plugins) - 1)
1237 spu_plugins[spu_i++] = strdup(ent->d_name);
1241 fprintf(stderr, "ignoring unidentified plugin: %s\n", fname);
1248 void menu_init(void)
1250 char buff[MAXPATHLEN];
1252 strcpy(last_selected_fname, "/media");
1254 scan_bios_plugins();
1258 menu_set_defconfig();
1259 menu_load_config(0);
1264 g_menubg_src_ptr = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
1265 if (g_menubg_src_ptr == NULL)
1267 emu_make_path(buff, "skin/background.png", sizeof(buff));
1268 readpng(g_menubg_src_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h);
1271 void menu_notify_mode_change(int w, int h, int bpp)
1277 if (scaling == SCALE_1_1) {
1278 g_layer_x = 800/2 - w/2; g_layer_y = 480/2 - h/2;
1279 g_layer_w = w; g_layer_h = h;
1283 static void menu_leave_emu(void)
1285 if (GPU_close != NULL) {
1286 int ret = GPU_close();
1288 fprintf(stderr, "Warning: GPU_close returned %d\n", ret);
1291 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
1292 if (pl_fbdev_buf != NULL && ready_to_go && last_psx_bpp == 16) {
1293 int x = max(0, g_menuscreen_w - last_psx_w);
1294 int y = max(0, g_menuscreen_h / 2 - last_psx_h / 2);
1295 int w = min(g_menuscreen_w, last_psx_w);
1296 int h = min(g_menuscreen_h, last_psx_h);
1297 u16 *d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
1298 u16 *s = pl_fbdev_buf;
1300 for (; h > 0; h--, d += g_menuscreen_w, s += last_psx_w)
1301 menu_darken_bg(d, s, w, 0);
1304 plat_video_menu_enter(ready_to_go);
1307 void menu_prepare_emu(void)
1309 plat_video_menu_leave();
1313 menu_notify_mode_change(last_psx_w, last_psx_h, last_psx_bpp);
1316 g_layer_x = 80; g_layer_y = 0;
1317 g_layer_w = 640; g_layer_h = 480;
1319 case SCALE_FULLSCREEN:
1320 g_layer_x = 0; g_layer_y = 0;
1321 g_layer_w = 800; g_layer_h = 480;
1326 apply_filter(filter);
1330 // core doesn't care about Config.Cdda changes,
1331 // so handle them manually here
1335 // HACK to set up the frame limiter if softgpu is not used..
1336 if (gpu_plugsel != 0) {
1337 fFrameRateHz = Config.PsxType ? 50.0f : 59.94f;
1338 dwFrameRateTicks = (100000*100 / (unsigned long)(fFrameRateHz*100));
1341 if (GPU_open != NULL) {
1342 int ret = GPU_open(&gpuDisp, "PCSX", NULL);
1344 fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
1348 void me_update_msg(const char *msg)
1350 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1351 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1353 menu_error_time = plat_get_ticks_ms();
1354 lprintf("msg: %s\n", menu_error_msg);