try to ensure fbdev buffer is valid
[pcsx_rearmed.git] / frontend / menu.c
CommitLineData
69af03a2 1/*
201c21e2 2 * (C) GraÅžvydas "notaz" Ignotas, 2010-2011
69af03a2 3 *
4 * This work is licensed under the terms of any of these licenses
5 * (at your option):
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.
9 */
10
11#include <stdio.h>
12#include <string.h>
3c70c47b 13#include <errno.h>
bbd837c6 14#include <dlfcn.h>
61363062 15#include <zlib.h>
69af03a2 16
c5061935 17#include "main.h"
3c70c47b 18#include "menu.h"
69af03a2 19#include "config.h"
201c21e2 20#include "plugin.h"
69af03a2 21#include "plugin_lib.h"
22#include "omap.h"
23#include "common/plat.h"
24#include "../libpcsxcore/misc.h"
7eda34c1 25#include "../libpcsxcore/new_dynarec/new_dynarec.h"
3c70c47b 26#include "revision.h"
69af03a2 27
28#define MENU_X2 1
29#define array_size(x) (sizeof(x) / sizeof(x[0]))
30
31typedef enum
32{
33 MA_NONE = 1,
34 MA_MAIN_RESUME_GAME,
35 MA_MAIN_SAVE_STATE,
36 MA_MAIN_LOAD_STATE,
37 MA_MAIN_RESET_GAME,
38 MA_MAIN_LOAD_ROM,
39 MA_MAIN_CONTROLS,
40 MA_MAIN_CREDITS,
41 MA_MAIN_EXIT,
42 MA_CTRL_PLAYER1,
43 MA_CTRL_PLAYER2,
44 MA_CTRL_EMU,
45 MA_CTRL_DEV_FIRST,
46 MA_CTRL_DEV_NEXT,
47 MA_CTRL_DONE,
48 MA_OPT_SAVECFG,
49 MA_OPT_SAVECFG_GAME,
50 MA_OPT_CPU_CLOCKS,
3c70c47b 51 MA_OPT_FILTERING,
69af03a2 52} menu_id;
53
3c70c47b 54enum {
55 SCALE_1_1,
56 SCALE_4_3,
57 SCALE_FULLSCREEN,
58 SCALE_CUSTOM,
59};
69af03a2 60
bd6267e6 61static int last_psx_w, last_psx_h, last_psx_bpp;
201c21e2 62static int scaling, filter, state_slot, cpu_clock, cpu_clock_st;
69af03a2 63static char rom_fname_reload[MAXPATHLEN];
64static char last_selected_fname[MAXPATHLEN];
bd6267e6 65int g_opts;
66
67// from softgpu plugin
68extern int iUseDither;
69extern int UseFrameSkip;
fba06457 70extern int UseFrameLimit;
bd6267e6 71extern uint32_t dwActFixes;
fba06457 72extern float fFrameRateHz;
73extern int dwFrameRateTicks;
bd6267e6 74
75// sound plugin
76extern int iUseReverb;
77extern int iUseInterpolation;
78extern int iXAPitch;
79extern int iSPUIRQWait;
80extern int iUseTimer;
81
bbd837c6 82static const char *gpu_plugins[16];
83static const char *spu_plugins[16];
84static int gpu_plugsel, spu_plugsel;
85
bd6267e6 86
87static int min(int x, int y) { return x < y ? x : y; }
88static int max(int x, int y) { return x > y ? x : y; }
69af03a2 89
90void emu_make_path(char *buff, const char *end, int size)
91{
92 int pos, end_len;
93
94 end_len = strlen(end);
95 pos = plat_get_root_dir(buff, size);
96 strncpy(buff + pos, end, size - pos);
97 buff[size - 1] = 0;
98 if (pos + end_len > size - 1)
99 printf("Warning: path truncated: %s\n", buff);
100}
101
102static int emu_check_save_file(int slot)
103{
c5061935 104 char fname[MAXPATHLEN];
3c70c47b 105 int ret;
106
c5061935 107 ret = get_state_filename(fname, sizeof(fname), slot);
108 if (ret != 0)
3c70c47b 109 return 0;
110
111 ret = CheckState(fname);
3c70c47b 112 return ret == 0 ? 1 : 0;
69af03a2 113}
114
115static int emu_save_load_game(int load, int sram)
116{
c5061935 117 char fname[MAXPATHLEN];
3c70c47b 118 int ret;
119
c5061935 120 ret = get_state_filename(fname, sizeof(fname), state_slot);
121 if (ret != 0)
3c70c47b 122 return 0;
123
124 if (load)
125 ret = LoadState(fname);
126 else
127 ret = SaveState(fname);
3c70c47b 128
129 return ret;
69af03a2 130}
131
3c70c47b 132static void menu_set_defconfig(void)
133{
134 scaling = SCALE_4_3;
bd6267e6 135
136 Config.Xa = Config.Cdda = Config.Sio =
137 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
138
139 iUseDither = UseFrameSkip = 0;
fba06457 140 UseFrameLimit = 1;
bd6267e6 141 dwActFixes = 1<<7;
142
143 iUseReverb = 2;
144 iUseInterpolation = 1;
145 iXAPitch = iSPUIRQWait = 0;
146 iUseTimer = 2;
3c70c47b 147}
148
4f3639fa 149#define CE_CONFIG_STR(val) \
150 { #val, 0, Config.val }
151
152#define CE_CONFIG_VAL(val) \
153 { #val, sizeof(Config.val), &Config.val }
154
155#define CE_STR(val) \
156 { #val, 0, val }
157
158#define CE_INTVAL(val) \
159 { #val, sizeof(val), &val }
160
161static const struct {
162 const char *name;
163 size_t len;
164 void *val;
165} config_data[] = {
166 CE_CONFIG_STR(Bios),
167 CE_CONFIG_STR(Gpu),
168 CE_CONFIG_STR(Spu),
169 CE_CONFIG_STR(Cdr),
170 CE_CONFIG_VAL(Xa),
171 CE_CONFIG_VAL(Sio),
172 CE_CONFIG_VAL(Mdec),
173 CE_CONFIG_VAL(PsxAuto),
174 CE_CONFIG_VAL(Cdda),
175 CE_CONFIG_VAL(Debug),
176 CE_CONFIG_VAL(PsxOut),
177 CE_CONFIG_VAL(SpuIrq),
178 CE_CONFIG_VAL(RCntFix),
179 CE_CONFIG_VAL(VSyncWA),
180 CE_CONFIG_VAL(Cpu),
181 CE_CONFIG_VAL(PsxType),
182 CE_INTVAL(scaling),
cd6e8d0f 183 CE_INTVAL(g_layer_x),
184 CE_INTVAL(g_layer_y),
185 CE_INTVAL(g_layer_w),
186 CE_INTVAL(g_layer_h),
4f3639fa 187 CE_INTVAL(filter),
188 CE_INTVAL(state_slot),
189 CE_INTVAL(cpu_clock),
190 CE_INTVAL(g_opts),
191 CE_INTVAL(iUseDither),
192 CE_INTVAL(UseFrameSkip),
fba06457 193 CE_INTVAL(UseFrameLimit),
4f3639fa 194 CE_INTVAL(dwActFixes),
195 CE_INTVAL(iUseReverb),
196 CE_INTVAL(iUseInterpolation),
197 CE_INTVAL(iXAPitch),
198 CE_INTVAL(iSPUIRQWait),
199 CE_INTVAL(iUseTimer),
200};
201
cd6e8d0f 202static void make_cfg_fname(char *buf, size_t size, int is_game)
203{
204 char trimlabel[33];
205 int j;
206
207 strncpy(trimlabel, CdromLabel, 32);
208 trimlabel[32] = 0;
209 for (j = 31; j >= 0; j--)
210 if (trimlabel[j] == ' ')
211 trimlabel[j] = 0;
212
213 if (is_game)
bbd837c6 214 snprintf(buf, size, "." PCSX_DOT_DIR "cfg/%.32s-%.9s.cfg", trimlabel, CdromId);
cd6e8d0f 215 else
bbd837c6 216 snprintf(buf, size, "." PCSX_DOT_DIR "%s", cfgfile_basename);
cd6e8d0f 217}
218
3c70c47b 219static int menu_write_config(int is_game)
220{
4f3639fa 221 char cfgfile[MAXPATHLEN];
222 FILE *f;
223 int i;
224
cd6e8d0f 225 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
4f3639fa 226 f = fopen(cfgfile, "w");
227 if (f == NULL) {
bbd837c6 228 printf("menu_write_config: failed to open: %s\n", cfgfile);
4f3639fa 229 return -1;
230 }
231
232 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
233 fprintf(f, "%s = ", config_data[i].name);
234 switch (config_data[i].len) {
235 case 0:
236 fprintf(f, "%s\n", (char *)config_data[i].val);
237 break;
238 case 1:
239 fprintf(f, "%x\n", *(u8 *)config_data[i].val);
240 break;
241 case 2:
242 fprintf(f, "%x\n", *(u16 *)config_data[i].val);
243 break;
244 case 4:
245 fprintf(f, "%x\n", *(u32 *)config_data[i].val);
246 break;
247 default:
248 printf("menu_write_config: unhandled len %d for %s\n",
249 config_data[i].len, config_data[i].name);
250 break;
251 }
252 }
253
254 if (!is_game)
255 fprintf(f, "lastcdimg = %s\n", last_selected_fname);
256
257 fclose(f);
258 return 0;
259}
260
261static void parse_str_val(char *cval, const char *src)
262{
263 char *tmp;
264 strncpy(cval, src, MAXPATHLEN);
265 cval[MAXPATHLEN - 1] = 0;
266 tmp = strchr(cval, '\n');
267 if (tmp == NULL)
268 tmp = strchr(cval, '\r');
269 if (tmp != NULL)
270 *tmp = 0;
3c70c47b 271}
272
273static int menu_load_config(int is_game)
69af03a2 274{
4f3639fa 275 char cfgfile[MAXPATHLEN];
276 int i, ret = -1;
277 long size;
278 char *cfg;
279 FILE *f;
280
cd6e8d0f 281 make_cfg_fname(cfgfile, sizeof(cfgfile), is_game);
4f3639fa 282 f = fopen(cfgfile, "r");
283 if (f == NULL) {
bbd837c6 284 printf("menu_load_config: failed to open: %s\n", cfgfile);
4f3639fa 285 return -1;
286 }
287
288 fseek(f, 0, SEEK_END);
289 size = ftell(f);
290 if (size <= 0) {
291 printf("bad size %ld: %s\n", size, cfgfile);
292 goto fail;
293 }
294
295 cfg = malloc(size + 1);
296 if (cfg == NULL)
297 goto fail;
298
299 fseek(f, 0, SEEK_SET);
300 if (fread(cfg, 1, size, f) != size) {
301 printf("failed to read: %s\n", cfgfile);
302 goto fail_read;
303 }
304 cfg[size] = 0;
305
306 for (i = 0; i < ARRAY_SIZE(config_data); i++) {
307 char *tmp, *tmp2;
308 u32 val;
309
310 tmp = strstr(cfg, config_data[i].name);
311 if (tmp == NULL)
312 continue;
313 tmp += strlen(config_data[i].name);
314 if (strncmp(tmp, " = ", 3) != 0)
315 continue;
316 tmp += 3;
317
318 if (config_data[i].len == 0) {
319 parse_str_val(config_data[i].val, tmp);
320 continue;
321 }
322
323 tmp2 = NULL;
324 val = strtoul(tmp, &tmp2, 16);
325 if (tmp2 == NULL || tmp == tmp2)
326 continue; // parse failed
327
328 switch (config_data[i].len) {
329 case 1:
330 *(u8 *)config_data[i].val = val;
331 break;
332 case 2:
333 *(u16 *)config_data[i].val = val;
334 break;
335 case 4:
336 *(u32 *)config_data[i].val = val;
337 break;
338 default:
339 printf("menu_load_config: unhandled len %d for %s\n",
340 config_data[i].len, config_data[i].name);
341 break;
342 }
343 }
344
345 if (!is_game) {
346 char *tmp = strstr(cfg, "lastcdimg = ");
347 if (tmp != NULL) {
348 tmp += 12;
349 parse_str_val(last_selected_fname, tmp);
350 }
351 }
352
bbd837c6 353 // sync plugins
354 for (i = gpu_plugsel = 0; gpu_plugins[i] != NULL; i++)
355 if (strcmp(Config.Gpu, gpu_plugins[i]) == 0)
356 { gpu_plugsel = i; break; }
357
358 for (i = spu_plugsel = 0; spu_plugins[i] != NULL; i++)
359 if (strcmp(Config.Spu, spu_plugins[i]) == 0)
360 { spu_plugsel = i; break; }
361
362 ret = 0;
4f3639fa 363fail_read:
364 free(cfg);
365fail:
366 fclose(f);
367 return ret;
69af03a2 368}
369
9564e73d 370// rrrr rggg gggb bbbb
371static unsigned short fname2color(const char *fname)
372{
87c06e51 373 static const char *cdimg_exts[] = { ".bin", ".img", ".iso", ".z", ".cue" };
374 static const char *other_exts[] = { ".ccd", ".toc", ".mds", ".sub", ".table" };
9564e73d 375 const char *ext = strrchr(fname, '.');
376 int i;
377
378 if (ext == NULL)
379 return 0xffff;
380 for (i = 0; i < array_size(cdimg_exts); i++)
381 if (strcasecmp(ext, cdimg_exts[i]) == 0)
382 return 0x7bff;
383 for (i = 0; i < array_size(other_exts); i++)
384 if (strcasecmp(ext, other_exts[i]) == 0)
385 return 0xa514;
386 return 0xffff;
387}
388
61363062 389static void draw_savestate_bg(int slot);
390
bd6267e6 391#define MENU_ALIGN_LEFT
3c70c47b 392#define menu_init menu_init_common
69af03a2 393#include "common/menu.c"
3c70c47b 394#undef menu_init
69af03a2 395
61363062 396// a bit of black magic here
397static void draw_savestate_bg(int slot)
398{
399 extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
400 static const int psx_widths[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
401 int x, y, w, h;
402 char fname[MAXPATHLEN];
403 GPUFreeze_t *gpu;
404 u16 *s, *d;
405 gzFile f;
406 int ret;
407 u32 tmp;
408
409 ret = get_state_filename(fname, sizeof(fname), slot);
410 if (ret != 0)
411 return;
412
413 f = gzopen(fname, "rb");
414 if (f == NULL)
415 return;
416
417 if (gzseek(f, 0x29933d, SEEK_SET) != 0x29933d) {
418 fprintf(stderr, "gzseek failed\n");
419 gzclose(f);
420 return;
421 }
422
423 gpu = malloc(sizeof(*gpu));
424 if (gpu == NULL) {
425 gzclose(f);
426 return;
427 }
428
429 ret = gzread(f, gpu, sizeof(*gpu));
430 gzclose(f);
431 if (ret != sizeof(*gpu)) {
432 fprintf(stderr, "gzread failed\n");
433 goto out;
434 }
435
436 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
437
438 if ((gpu->ulStatus & 0x800000) || (gpu->ulStatus & 0x200000))
439 goto out; // disabled || 24bpp (NYET)
440
441 x = gpu->ulControl[5] & 0x3ff;
442 y = (gpu->ulControl[5] >> 10) & 0x1ff;
443 s = (u16 *)gpu->psxVRam + y * 1024 + (x & ~3);
444 w = psx_widths[(gpu->ulStatus >> 16) & 7];
445 tmp = gpu->ulControl[7];
446 h = ((tmp >> 10) & 0x3ff) - (tmp & 0x3ff);
447 if (gpu->ulStatus & 0x80000) // doubleheight
448 h *= 2;
449
450 x = max(0, g_menuscreen_w - w) & ~3;
451 y = max(0, g_menuscreen_h / 2 - h / 2);
452 w = min(g_menuscreen_w, w);
453 h = min(g_menuscreen_h, h);
454 d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
455
456 for (; h > 0; h--, d += g_menuscreen_w, s += 1024)
457 bgr555_to_rgb565(d, s, w * 2);
458
459out:
460 free(gpu);
461}
462
3c70c47b 463// ---------- pandora specific -----------
464
465static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";
466static char **pnd_filter_list;
467
468static int get_cpu_clock(void)
69af03a2 469{
3c70c47b 470 FILE *f;
471 int ret = 0;
472 f = fopen("/proc/pandora/cpu_mhz_max", "r");
473 if (f) {
474 fscanf(f, "%d", &ret);
475 fclose(f);
476 }
477 return ret;
478}
479
480static void apply_cpu_clock(void)
481{
482 char buf[128];
483
484 if (cpu_clock != 0 && cpu_clock != get_cpu_clock()) {
485 snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",
486 pnd_script_base, cpu_clock);
487 system(buf);
488 }
489}
490
491static void apply_filter(int which)
492{
4f3639fa 493 static int old = -1;
3c70c47b 494 char buf[128];
495 int i;
496
4f3639fa 497 if (pnd_filter_list == NULL || which == old)
3c70c47b 498 return;
499
500 for (i = 0; i < which; i++)
501 if (pnd_filter_list[i] == NULL)
502 return;
503
504 if (pnd_filter_list[i] == NULL)
505 return;
506
507 snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]);
508 system(buf);
4f3639fa 509 old = which;
3c70c47b 510}
511
512static menu_entry e_menu_gfx_options[];
513
514static void pnd_menu_init(void)
515{
516 struct dirent *ent;
517 int i, count = 0;
518 char **mfilters;
519 char buff[64], *p;
520 DIR *dir;
521
201c21e2 522 cpu_clock_st = cpu_clock = get_cpu_clock();
3c70c47b 523
524 dir = opendir("/etc/pandora/conf/dss_fir");
525 if (dir == NULL) {
526 perror("filter opendir");
527 return;
528 }
529
530 while (1) {
531 errno = 0;
532 ent = readdir(dir);
533 if (ent == NULL) {
534 if (errno != 0)
535 perror("readdir");
536 break;
537 }
538 p = strstr(ent->d_name, "_up");
539 if (p != NULL && (p[3] == 0 || !strcmp(p + 3, "_h")))
540 count++;
541 }
542
543 if (count == 0)
544 return;
545
546 mfilters = calloc(count + 1, sizeof(mfilters[0]));
547 if (mfilters == NULL)
548 return;
549
550 rewinddir(dir);
551 for (i = 0; (ent = readdir(dir)); ) {
552 size_t len;
553
554 p = strstr(ent->d_name, "_up");
555 if (p == NULL || (p[3] != 0 && strcmp(p + 3, "_h")))
556 continue;
557
558 len = p - ent->d_name;
559 if (len > sizeof(buff) - 1)
560 continue;
561
562 strncpy(buff, ent->d_name, len);
563 buff[len] = 0;
564 mfilters[i] = strdup(buff);
565 if (mfilters[i] != NULL)
566 i++;
567 }
568 closedir(dir);
569
570 i = me_id2offset(e_menu_gfx_options, MA_OPT_FILTERING);
571 e_menu_gfx_options[i].data = (void *)mfilters;
572 pnd_filter_list = mfilters;
69af03a2 573}
574
201c21e2 575void menu_finish(void)
576{
577 cpu_clock = cpu_clock_st;
578 apply_cpu_clock();
579}
580
69af03a2 581// -------------- key config --------------
582
583me_bind_action me_ctrl_actions[] =
584{
585 { "UP ", 1 << DKEY_UP},
586 { "DOWN ", 1 << DKEY_DOWN },
587 { "LEFT ", 1 << DKEY_LEFT },
588 { "RIGHT ", 1 << DKEY_RIGHT },
589 { "TRIANGLE", 1 << DKEY_TRIANGLE },
22a8a805 590 { "CIRCLE ", 1 << DKEY_CIRCLE },
69af03a2 591 { "CROSS ", 1 << DKEY_CROSS },
592 { "SQUARE ", 1 << DKEY_SQUARE },
593 { "L1 ", 1 << DKEY_L1 },
594 { "R1 ", 1 << DKEY_R1 },
595 { "L2 ", 1 << DKEY_L2 },
596 { "R2 ", 1 << DKEY_R2 },
597 { "START ", 1 << DKEY_START },
598 { "SELECT ", 1 << DKEY_SELECT },
599 { NULL, 0 }
600};
601
602me_bind_action emuctrl_actions[] =
603{
bd6267e6 604/*
69af03a2 605 { "Load State ", PEV_STATE_LOAD },
606 { "Save State ", PEV_STATE_SAVE },
607 { "Prev Save Slot ", PEV_SSLOT_PREV },
608 { "Next Save Slot ", PEV_SSLOT_NEXT },
bd6267e6 609*/
69af03a2 610 { "Enter Menu ", PEV_MENU },
611 { NULL, 0 }
612};
613
614static int key_config_loop_wrap(int id, int keys)
615{
616 switch (id) {
617 case MA_CTRL_PLAYER1:
618 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
619 break;
620 case MA_CTRL_PLAYER2:
621 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
622 break;
623 case MA_CTRL_EMU:
624 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
625 break;
626 default:
627 break;
628 }
629 return 0;
630}
631
632static const char *mgn_dev_name(int id, int *offs)
633{
634 const char *name = NULL;
635 static int it = 0;
636
637 if (id == MA_CTRL_DEV_FIRST)
638 it = 0;
639
640 for (; it < IN_MAX_DEVS; it++) {
641 name = in_get_dev_name(it, 1, 1);
642 if (name != NULL)
643 break;
644 }
645
646 it++;
647 return name;
648}
649
650static const char *mgn_saveloadcfg(int id, int *offs)
651{
652 return "";
653}
654
cd6e8d0f 655static int mh_savecfg(int id, int keys)
69af03a2 656{
cd6e8d0f 657 if (menu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0) == 0)
658 me_update_msg("config saved");
659 else
660 me_update_msg("failed to write config");
69af03a2 661
662 return 1;
663}
664
665static menu_entry e_menu_keyconfig[] =
666{
667 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
668 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
669 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
cd6e8d0f 670// mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
671// mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
69af03a2 672 mee_label (""),
673 mee_label ("Input devices:"),
674 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
675 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
676 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
677 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
678 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
679 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
680 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
681 mee_end,
682};
683
684static int menu_loop_keyconfig(int id, int keys)
685{
686 static int sel = 0;
687
4f3639fa 688// me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, ready_to_go);
69af03a2 689 me_loop(e_menu_keyconfig, &sel, NULL);
690 return 0;
691}
692
69af03a2 693// ------------ gfx options menu ------------
694
3c70c47b 695static const char *men_scaler[] = { "1x1", "scaled 4:3", "fullscreen", "custom", NULL };
696static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n"
697 "using d-pad or move it using R+d-pad";
698static const char *men_dummy[] = { NULL };
699
700static int menu_loop_cscaler(int id, int keys)
701{
702 unsigned int inp;
703
704 scaling = SCALE_CUSTOM;
705
706 omap_enable_layer(1);
3c70c47b 707
708 for (;;)
709 {
710 menu_draw_begin(0);
201c21e2 711 memset(g_menuscreen_ptr, 4, g_menuscreen_w * g_menuscreen_h * 2);
712 text_out16(2, 2, "%d,%d", g_layer_x, g_layer_y);
713 text_out16(2, 480 - 18, "%dx%d | d-pad: resize, R+d-pad: move", g_layer_w, g_layer_h);
3c70c47b 714 menu_draw_end();
715
716 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40);
717 if (inp & PBTN_UP) g_layer_y--;
718 if (inp & PBTN_DOWN) g_layer_y++;
719 if (inp & PBTN_LEFT) g_layer_x--;
720 if (inp & PBTN_RIGHT) g_layer_x++;
721 if (!(inp & PBTN_R)) {
722 if (inp & PBTN_UP) g_layer_h += 2;
723 if (inp & PBTN_DOWN) g_layer_h -= 2;
724 if (inp & PBTN_LEFT) g_layer_w += 2;
725 if (inp & PBTN_RIGHT) g_layer_w -= 2;
726 }
727 if (inp & (PBTN_MOK|PBTN_MBACK))
728 break;
729
730 if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
731 if (g_layer_x < 0) g_layer_x = 0;
732 if (g_layer_x > 640) g_layer_x = 640;
733 if (g_layer_y < 0) g_layer_y = 0;
734 if (g_layer_y > 420) g_layer_y = 420;
735 if (g_layer_w < 160) g_layer_w = 160;
736 if (g_layer_h < 60) g_layer_h = 60;
737 if (g_layer_x + g_layer_w > 800)
738 g_layer_w = 800 - g_layer_x;
739 if (g_layer_y + g_layer_h > 480)
740 g_layer_h = 480 - g_layer_y;
741 omap_enable_layer(1);
742 }
743 }
744
745 omap_enable_layer(0);
746
747 return 0;
748}
749
69af03a2 750static menu_entry e_menu_gfx_options[] =
751{
3c70c47b 752 mee_enum ("Scaler", 0, scaling, men_scaler),
753 mee_enum ("Filter", MA_OPT_FILTERING, filter, men_dummy),
754// mee_onoff ("Vsync", 0, vsync, 1),
755 mee_cust_h ("Setup custom scaler", 0, menu_loop_cscaler, NULL, h_cscaler),
69af03a2 756 mee_end,
757};
758
759static int menu_loop_gfx_options(int id, int keys)
760{
761 static int sel = 0;
762
763 me_loop(e_menu_gfx_options, &sel, NULL);
764
765 return 0;
766}
767
bd6267e6 768// ------------ bios/plugins ------------
769
770static const char *men_gpu_dithering[] = { "None", "Game dependant", "Always", NULL };
bd6267e6 771static const char h_gpu_0[] = "Needed for Chrono Cross";
772static const char h_gpu_1[] = "Capcom fighting games";
773static const char h_gpu_2[] = "Black screens in Lunar";
774static const char h_gpu_3[] = "Compatibility mode";
775static const char h_gpu_6[] = "Pandemonium 2";
776static const char h_gpu_7[] = "Skip every second frame";
777static const char h_gpu_8[] = "Needed by Dark Forces";
778static const char h_gpu_9[] = "better g-colors, worse textures";
779static const char h_gpu_10[] = "Toggle busy flags after drawing";
780
781static menu_entry e_menu_plugin_gpu[] =
782{
783 mee_enum ("Dithering", 0, iUseDither, men_gpu_dithering),
784 mee_onoff_h ("Odd/even bit hack", 0, dwActFixes, 1<<0, h_gpu_0),
785 mee_onoff_h ("Expand screen width", 0, dwActFixes, 1<<1, h_gpu_1),
786 mee_onoff_h ("Ignore brightness color", 0, dwActFixes, 1<<2, h_gpu_2),
787 mee_onoff_h ("Disable coordinate check", 0, dwActFixes, 1<<3, h_gpu_3),
788 mee_onoff_h ("Lazy screen update", 0, dwActFixes, 1<<6, h_gpu_6),
789 mee_onoff_h ("Old frame skipping", 0, dwActFixes, 1<<7, h_gpu_7),
790 mee_onoff_h ("Repeated flat tex triangles ",0,dwActFixes, 1<<8, h_gpu_8),
791 mee_onoff_h ("Draw quads with triangles", 0, dwActFixes, 1<<9, h_gpu_9),
792 mee_onoff_h ("Fake 'gpu busy' states", 0, dwActFixes, 1<<10, h_gpu_10),
793 mee_end,
794};
795
796static int menu_loop_plugin_gpu(int id, int keys)
797{
798 static int sel = 0;
799 me_loop(e_menu_plugin_gpu, &sel, NULL);
800 return 0;
801}
802
803static const char *men_spu_reverb[] = { "Off", "Fake", "On", NULL };
804static const char *men_spu_interp[] = { "None", "Simple", "Gaussian", "Cubic", NULL };
bd6267e6 805static const char h_spu_irq_wait[] = "Wait for CPU; only useful for some games, may cause glitches";
806static const char h_spu_thread[] = "Run sound emulation in separate thread";
807
808static menu_entry e_menu_plugin_spu[] =
809{
810 mee_enum ("Reverb", 0, iUseReverb, men_spu_reverb),
811 mee_enum ("Interpolation", 0, iUseInterpolation, men_spu_interp),
812 mee_onoff ("Adjust XA pitch", 0, iXAPitch, 1),
813 mee_onoff_h ("SPU IRQ Wait", 0, iSPUIRQWait, 1, h_spu_irq_wait),
814 mee_onoff_h ("Use sound thread", 0, iUseTimer, 1, h_spu_thread),
815 mee_end,
816};
817
818static int menu_loop_plugin_spu(int id, int keys)
819{
820 static int sel = 0;
821 me_loop(e_menu_plugin_spu, &sel, NULL);
822 return 0;
823}
824
bbd837c6 825static const char h_gpu[] = "Configure built-in P.E.Op.S. SoftGL Driver V1.17";
826static const char h_spu[] = "Configure built-in P.E.Op.S. Sound Driver V1.7";
827static const char h_plugin_xpu[] = "Must save config and reload the game\n"
828 "for plugin change to take effect";
829
bd6267e6 830static menu_entry e_menu_plugin_options[] =
831{
bbd837c6 832 mee_enum_h ("GPU plugin", 0, gpu_plugsel, gpu_plugins, h_plugin_xpu),
833 mee_enum_h ("SPU plugin", 0, spu_plugsel, spu_plugins, h_plugin_xpu),
bd6267e6 834 mee_handler_h ("Configure built-in GPU plugin", menu_loop_plugin_gpu, h_gpu),
835 mee_handler_h ("Configure built-in SPU plugin", menu_loop_plugin_spu, h_spu),
836 mee_end,
837};
838
839static int menu_loop_plugin_options(int id, int keys)
840{
841 static int sel = 0;
842 me_loop(e_menu_plugin_options, &sel, NULL);
bbd837c6 843
844 // sync plugins
845 snprintf(Config.Gpu, sizeof(Config.Gpu), "%s", gpu_plugins[gpu_plugsel]);
846 snprintf(Config.Spu, sizeof(Config.Spu), "%s", spu_plugins[spu_plugsel]);
847
bd6267e6 848 return 0;
849}
850
851// ------------ adv options menu ------------
852
fba06457 853static const char h_cfg_cpul[] = "Shows CPU usage in %%";
854static const char h_cfg_fl[] = "Keeps the game from running too fast";
bd6267e6 855static const char h_cfg_xa[] = "Disables XA sound, which can sometimes improve performance";
856static const char h_cfg_cdda[] = "Disable CD Audio for a performance boost\n"
857 "(proper .cue/.bin dump is needed otherwise)";
858static const char h_cfg_sio[] = "This should be enabled for certain memcards/gamepads";
859static const char h_cfg_spuirq[] = "Compatibility tweak; should probably be left off";
860static const char h_cfg_rcnt1[] = "Parasite Eve 2, Vandal Hearts 1/2 Fix";
861static const char h_cfg_rcnt2[] = "InuYasha Sengoku Battle Fix";
862
863static menu_entry e_menu_adv_options[] =
864{
fba06457 865 mee_onoff_h ("Show CPU load", 0, g_opts, OPT_SHOWCPU, h_cfg_cpul),
866 mee_onoff_h ("Frame Limiter", 0, UseFrameLimit, 1, h_cfg_fl),
bd6267e6 867 mee_onoff_h ("Disable XA Decoding", 0, Config.Xa, 1, h_cfg_xa),
868 mee_onoff_h ("Disable CD Audio", 0, Config.Cdda, 1, h_cfg_cdda),
869 mee_onoff_h ("SIO IRQ Always Enabled", 0, Config.Sio, 1, h_cfg_sio),
870 mee_onoff_h ("SPU IRQ Always Enabled", 0, Config.SpuIrq, 1, h_cfg_spuirq),
871 mee_onoff_h ("Rootcounter hack", 0, Config.RCntFix, 1, h_cfg_rcnt1),
872 mee_onoff_h ("Rootcounter hack 2", 0, Config.VSyncWA, 1, h_cfg_rcnt2),
873 mee_end,
874};
875
876static int menu_loop_adv_options(int id, int keys)
877{
878 static int sel = 0;
879 me_loop(e_menu_adv_options, &sel, NULL);
880 return 0;
881}
882
69af03a2 883// ------------ options menu ------------
884
69af03a2 885static int mh_restore_defaults(int id, int keys)
886{
3c70c47b 887 menu_set_defconfig();
69af03a2 888 me_update_msg("defaults restored");
889 return 1;
890}
891
bd6267e6 892static const char *men_region[] = { "NTSC", "PAL", NULL };
893/*
69af03a2 894static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
895static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
896 "loading state or both";
bd6267e6 897*/
898static const char h_restore_def[] = "Switches back to default / recommended\n"
899 "configuration";
69af03a2 900
901static menu_entry e_menu_options[] =
902{
bd6267e6 903// mee_range ("Save slot", 0, state_slot, 0, 9),
904// mee_enum_h ("Confirm savestate", 0, dummy, men_confirm_save, h_confirm_save),
905 mee_onoff ("Frameskip", 0, UseFrameSkip, 1),
906 mee_onoff ("Show FPS", 0, g_opts, OPT_SHOWFPS),
907 mee_enum ("Region", 0, Config.PsxType, men_region),
3c70c47b 908 mee_range ("CPU clock", MA_OPT_CPU_CLOCKS, cpu_clock, 20, 5000),
69af03a2 909 mee_handler ("[Display]", menu_loop_gfx_options),
bd6267e6 910 mee_handler ("[BIOS/Plugins]", menu_loop_plugin_options),
69af03a2 911 mee_handler ("[Advanced]", menu_loop_adv_options),
cd6e8d0f 912 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg),
913 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg),
bd6267e6 914 mee_handler_h ("Restore default config", mh_restore_defaults, h_restore_def),
69af03a2 915 mee_end,
916};
917
918static int menu_loop_options(int id, int keys)
919{
920 static int sel = 0;
921 int i;
922
923 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
3c70c47b 924 e_menu_options[i].enabled = cpu_clock != 0 ? 1 : 0;
cd6e8d0f 925 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, ready_to_go);
69af03a2 926
927 me_loop(e_menu_options, &sel, NULL);
928
929 return 0;
930}
931
932// ------------ debug menu ------------
933
69af03a2 934static void draw_frame_debug(void)
935{
3c70c47b 936 smalltext_out16(4, 1, "build: "__DATE__ " " __TIME__ " " REV, 0xe7fc);
69af03a2 937}
938
939static void debug_menu_loop(void)
940{
941 int inp;
942
943 while (1)
944 {
945 menu_draw_begin(1);
946 draw_frame_debug();
947 menu_draw_end();
948
949 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
950 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
951 if (inp & PBTN_MBACK)
952 return;
953 }
954}
955
956// ------------ main menu ------------
957
bd6267e6 958void OnFile_Exit();
959
69af03a2 960const char *plat_get_credits(void)
961{
bd6267e6 962 return "PCSX-ReARMed\n\n"
963 "(C) 1999-2003 PCSX Team\n"
69af03a2 964 "(C) 2005-2009 PCSX-df Team\n"
965 "(C) 2009-2010 PCSX-Reloaded Team\n\n"
966 "GPU and SPU code by Pete Bernert\n"
967 " and the P.E.Op.S. team\n"
bd6267e6 968 "ARM recompiler (C) 2009-2010 Ari64\n\n"
69af03a2 969 "integration, optimization and\n"
201c21e2 970 " frontend (C) 2010-2011 notaz\n";
69af03a2 971}
972
bbd837c6 973static int run_cd_image(const char *fname)
69af03a2 974{
47bf65ab 975 extern void set_cd_image(const char *fname);
69af03a2 976 ready_to_go = 0;
fba06457 977 pl_fbdev_buf = NULL;
69af03a2 978
fba06457 979 ClosePlugins();
bbd837c6 980 set_cd_image(fname);
69af03a2 981 LoadPlugins();
982 NetOpened = 0;
983 if (OpenPlugins() == -1) {
984 me_update_msg("failed to open plugins");
bbd837c6 985 return -1;
69af03a2 986 }
201c21e2 987 plugin_call_rearmed_cbs();
69af03a2 988
69af03a2 989 if (CheckCdrom() == -1) {
990 // Only check the CD if we are starting the console with a CD
991 ClosePlugins();
992 me_update_msg("unsupported/invalid CD image");
bbd837c6 993 return -1;
69af03a2 994 }
995
bbd837c6 996 SysReset();
997
69af03a2 998 // Read main executable directly from CDRom and start it
999 if (LoadCdrom() == -1) {
1000 ClosePlugins();
1001 me_update_msg("failed to load CD image");
bbd837c6 1002 return -1;
69af03a2 1003 }
1004
1005 ready_to_go = 1;
bbd837c6 1006 return 0;
69af03a2 1007}
1008
bbd837c6 1009static int romsel_run(void)
69af03a2 1010{
bbd837c6 1011 int prev_gpu, prev_spu;
1012 char *fname;
1013
1014 fname = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
1015 if (fname == NULL)
1016 return -1;
69af03a2 1017
bbd837c6 1018 printf("selected file: %s\n", fname);
1019
1020 if (run_cd_image(fname) != 0)
1021 return -1;
1022
1023 prev_gpu = gpu_plugsel;
1024 prev_spu = spu_plugsel;
1025 if (menu_load_config(1) != 0)
1026 menu_load_config(0);
1027
1028 // check for plugin changes, have to repeat
1029 // loading if game config changed plugins to reload them
1030 if (prev_gpu != gpu_plugsel || prev_spu != spu_plugsel) {
1031 printf("plugin change detected, reloading plugins..\n");
1032 if (run_cd_image(fname) != 0)
1033 return -1;
1034 }
1035
1036 strcpy(last_selected_fname, rom_fname_reload);
1037 return 0;
1038}
1039
1040static int main_menu_handler(int id, int keys)
1041{
69af03a2 1042 switch (id)
1043 {
1044 case MA_MAIN_RESUME_GAME:
3c70c47b 1045 if (ready_to_go)
1046 return 1;
69af03a2 1047 break;
1048 case MA_MAIN_SAVE_STATE:
1049 if (ready_to_go)
1050 return menu_loop_savestate(0);
1051 break;
1052 case MA_MAIN_LOAD_STATE:
1053 if (ready_to_go)
1054 return menu_loop_savestate(1);
1055 break;
1056 case MA_MAIN_RESET_GAME:
3c70c47b 1057 if (ready_to_go) {
fba06457 1058 ClosePlugins();
3c70c47b 1059 OpenPlugins();
1060 SysReset();
1061 if (CheckCdrom() != -1) {
1062 LoadCdrom();
1063 }
1064 return 1;
1065 }
69af03a2 1066 break;
1067 case MA_MAIN_LOAD_ROM:
bbd837c6 1068 if (romsel_run() == 0)
69af03a2 1069 return 1;
1070 break;
1071 case MA_MAIN_CREDITS:
3c70c47b 1072 draw_menu_credits(draw_frame_debug);
69af03a2 1073 in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
1074 break;
1075 case MA_MAIN_EXIT:
bd6267e6 1076 OnFile_Exit();
1077 break;
69af03a2 1078 default:
1079 lprintf("%s: something unknown selected\n", __FUNCTION__);
1080 break;
1081 }
1082
1083 return 0;
1084}
1085
1086static menu_entry e_menu_main[] =
1087{
1088 mee_label (""),
1089 mee_label (""),
1090 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
1091 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
1092 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
1093 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
1094 mee_handler_id("Load CD image", MA_MAIN_LOAD_ROM, main_menu_handler),
1095 mee_handler ("Options", menu_loop_options),
1096 mee_handler ("Controls", menu_loop_keyconfig),
1097 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
1098 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
1099 mee_end,
1100};
1101
3c70c47b 1102// ----------------------------
1103
bd6267e6 1104static void menu_leave_emu(void);
1105
69af03a2 1106void menu_loop(void)
1107{
1108 static int sel = 0;
1109
bd6267e6 1110 menu_leave_emu();
69af03a2 1111
1112 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, ready_to_go);
1113 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, ready_to_go);
1114 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, ready_to_go);
1115 me_enable(e_menu_main, MA_MAIN_RESET_GAME, ready_to_go);
1116
4f3639fa 1117// menu_enter(ready_to_go);
69af03a2 1118 in_set_config_int(0, IN_CFG_BLOCKING, 1);
1119
1120 do {
bd6267e6 1121 me_loop(e_menu_main, &sel, NULL);
69af03a2 1122 } while (!ready_to_go);
1123
1124 /* wait until menu, ok, back is released */
1125 while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1126 ;
1127
1128 in_set_config_int(0, IN_CFG_BLOCKING, 0);
1129
3c70c47b 1130 menu_prepare_emu();
1131}
1132
bbd837c6 1133static void scan_plugins(void)
1134{
1135 char fname[MAXPATHLEN];
1136 struct dirent *ent;
1137 int gpu_i, spu_i;
1138 char *p;
1139 DIR *dir;
1140
1141 gpu_plugins[0] = "builtin_gpu";
1142 spu_plugins[0] = "builtin_spu";
1143 gpu_i = spu_i = 1;
1144
1145 snprintf(fname, sizeof(fname), "%s/", Config.PluginsDir);
1146 dir = opendir(fname);
1147 if (dir == NULL) {
1148 perror("scan_plugins opendir");
1149 return;
1150 }
1151
1152 while (1) {
1153 void *h, *tmp;
1154
1155 errno = 0;
1156 ent = readdir(dir);
1157 if (ent == NULL) {
1158 if (errno != 0)
1159 perror("readdir");
1160 break;
1161 }
1162 p = strstr(ent->d_name, ".so");
1163 if (p == NULL)
1164 continue;
1165
1166 snprintf(fname, sizeof(fname), "%s/%s", Config.PluginsDir, ent->d_name);
1167 h = dlopen(fname, RTLD_LAZY | RTLD_LOCAL);
1168 if (h == NULL) {
1169 fprintf(stderr, "%s\n", dlerror());
1170 continue;
1171 }
1172
1173 // now what do we have here?
1174 tmp = dlsym(h, "GPUinit");
1175 if (tmp) {
1176 dlclose(h);
1177 if (gpu_i < ARRAY_SIZE(gpu_plugins) - 1)
1178 gpu_plugins[gpu_i++] = strdup(ent->d_name);
1179 continue;
1180 }
1181
1182 tmp = dlsym(h, "SPUinit");
1183 if (tmp) {
1184 dlclose(h);
1185 if (spu_i < ARRAY_SIZE(spu_plugins) - 1)
1186 spu_plugins[spu_i++] = strdup(ent->d_name);
1187 continue;
1188 }
1189
1190 fprintf(stderr, "ignoring unidentified plugin: %s\n", fname);
1191 dlclose(h);
1192 }
1193
1194 closedir(dir);
1195}
1196
3c70c47b 1197void menu_init(void)
1198{
4f3639fa 1199 char buff[MAXPATHLEN];
1200
1201 strcpy(last_selected_fname, "/media");
1202
bbd837c6 1203 scan_plugins();
4f3639fa 1204 pnd_menu_init();
1205 menu_init_common();
1206
3c70c47b 1207 menu_set_defconfig();
1208 menu_load_config(0);
3c70c47b 1209 last_psx_w = 320;
1210 last_psx_h = 240;
bd6267e6 1211 last_psx_bpp = 16;
1212
4f3639fa 1213 g_menubg_src_ptr = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1);
1214 if (g_menubg_src_ptr == NULL)
1215 exit(1);
1216 emu_make_path(buff, "skin/background.png", sizeof(buff));
1217 readpng(g_menubg_src_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h);
3c70c47b 1218}
1219
bd6267e6 1220void menu_notify_mode_change(int w, int h, int bpp)
3c70c47b 1221{
1222 last_psx_w = w;
1223 last_psx_h = h;
bd6267e6 1224 last_psx_bpp = bpp;
3c70c47b 1225
1226 if (scaling == SCALE_1_1) {
1227 g_layer_x = 800/2 - w/2; g_layer_y = 480/2 - h/2;
1228 g_layer_w = w; g_layer_h = h;
3c70c47b 1229 }
1230}
1231
bd6267e6 1232static void menu_leave_emu(void)
1233{
6d1a1ac2 1234 if (GPU_close != NULL) {
1235 int ret = GPU_close();
1236 if (ret)
1237 fprintf(stderr, "Warning: GPU_close returned %d\n", ret);
1238 }
bd6267e6 1239
4f3639fa 1240 memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
fba06457 1241 if (pl_fbdev_buf != NULL && ready_to_go && last_psx_bpp == 16) {
bd6267e6 1242 int x = max(0, g_menuscreen_w - last_psx_w);
1243 int y = max(0, g_menuscreen_h / 2 - last_psx_h / 2);
1244 int w = min(g_menuscreen_w, last_psx_w);
1245 int h = min(g_menuscreen_h, last_psx_h);
4f3639fa 1246 u16 *d = (u16 *)g_menubg_ptr + g_menuscreen_w * y + x;
bd6267e6 1247 u16 *s = pl_fbdev_buf;
1248
1249 for (; h > 0; h--, d += g_menuscreen_w, s += last_psx_w)
4f3639fa 1250 menu_darken_bg(d, s, w, 0);
bd6267e6 1251 }
fba06457 1252
1253 plat_video_menu_enter(ready_to_go);
bd6267e6 1254}
1255
3c70c47b 1256void menu_prepare_emu(void)
1257{
fba06457 1258 plat_video_menu_leave();
1259
3c70c47b 1260 switch (scaling) {
1261 case SCALE_1_1:
bd6267e6 1262 menu_notify_mode_change(last_psx_w, last_psx_h, last_psx_bpp);
3c70c47b 1263 break;
1264 case SCALE_4_3:
1265 g_layer_x = 80; g_layer_y = 0;
1266 g_layer_w = 640; g_layer_h = 480;
1267 break;
1268 case SCALE_FULLSCREEN:
1269 g_layer_x = 0; g_layer_y = 0;
1270 g_layer_w = 800; g_layer_h = 480;
1271 break;
1272 case SCALE_CUSTOM:
1273 break;
1274 }
3c70c47b 1275 apply_filter(filter);
1276 apply_cpu_clock();
7eda34c1 1277 stop = 0;
bd6267e6 1278
1279 // core doesn't care about Config.Cdda changes,
1280 // so handle them manually here
1281 if (Config.Cdda)
1282 CDR_stop();
6d1a1ac2 1283
fba06457 1284 // HACK to set up the frame limiter if softgpu is not used..
1285 if (gpu_plugsel != 0) {
1286 fFrameRateHz = Config.PsxType ? 50.0f : 59.94f;
1287 dwFrameRateTicks = (100000*100 / (unsigned long)(fFrameRateHz*100));
1288 }
1289
6d1a1ac2 1290 if (GPU_open != NULL) {
6d1a1ac2 1291 int ret = GPU_open(&gpuDisp, "PCSX", NULL);
1292 if (ret)
1293 fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
1294 }
69af03a2 1295}
1296
1297void me_update_msg(const char *msg)
1298{
1299 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1300 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1301
1302 menu_error_time = plat_get_ticks_ms();
1303 lprintf("msg: %s\n", menu_error_msg);
1304}
1305