menu: add reset hotkey
[picodrive.git] / platform / common / menu_pico.c
CommitLineData
cff531af 1/*
2 * PicoDrive
3 * (C) notaz, 2010,2011
4 *
5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
7 */
d4d62665 8#include <stdio.h>
21ebcfd3 9#include <string.h>
75a30842 10#include <time.h>
21ebcfd3 11
d2fd8a7a 12#include "emu.h"
21ebcfd3 13#include "menu_pico.h"
e743be20 14#include "input_pico.h"
c6f91b0e 15#include "version.h"
d2fd8a7a 16
e0bcb7a9 17#include <pico/pico_int.h>
d2fd8a7a 18#include <pico/patch.h>
19
d4d62665 20#ifdef PANDORA
21#define MENU_X2 1
22#else
23#define MENU_X2 0
24#endif
25
e743be20 26// FIXME
27#define REVISION "0"
28
29static const char *rom_exts[] = {
636d5f25 30 "zip",
53b2e51c 31 "bin", "smd", "gen", "md",
636d5f25 32 "iso", "cso", "cue",
33 "32x",
34 "sms",
35 NULL
e743be20 36};
37
5d1672cb 38// rrrr rggg gggb bbbb
39static unsigned short fname2color(const char *fname)
40{
5d1672cb 41 static const char *other_exts[] = { "gmv", "pat" };
53b2e51c 42 const char *ext;
5d1672cb 43 int i;
44
53b2e51c 45 ext = strrchr(fname, '.');
46 if (ext++ == NULL) {
47 ext = fname + strlen(fname) - 3;
48 if (ext < fname) ext = fname;
49 }
50
e743be20 51 for (i = 0; rom_exts[i] != NULL; i++)
5d1672cb 52 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines
53 for (i = 0; i < array_size(other_exts); i++)
54 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
55 return 0xffff;
56}
57
e743be20 58#include "../libpicofe/menu.c"
d2fd8a7a 59
d4d62665 60static const char *men_dummy[] = { NULL };
61
d2fd8a7a 62/* platform specific options and handlers */
63#if defined(__GP2X__)
64#include "../gp2x/menu.c"
65#elif defined(PANDORA)
66#include "../pandora/menu.c"
67#else
68#define MENU_OPTIONS_GFX
69#define MENU_OPTIONS_ADV
d2fd8a7a 70#endif
71
d4d62665 72static void make_bg(int no_scale)
73{
74 unsigned short *src = (void *)g_menubg_src_ptr;
75 int w = g_screen_width, h = g_screen_height;
76 short *dst;
77 int x, y;
78
d438a8dd 79 if (src == NULL) {
80 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
81 return;
82 }
83
d4d62665 84 if (!no_scale && g_menuscreen_w / w >= 2 && g_menuscreen_h / h >= 2)
85 {
86 unsigned int t, *d = g_menubg_ptr;
87 d += (g_menuscreen_h / 2 - h * 2 / 2)
88 * g_menuscreen_w / 2;
89 d += (g_menuscreen_w / 2 - w * 2 / 2) / 2;
90 for (y = 0; y < h; y++, src += w, d += g_menuscreen_w*2/2) {
91 for (x = 0; x < w; x++) {
92 t = src[x];
93 t = ((t & 0xf79e)>>1) - ((t & 0xc618)>>3);
94 t |= t << 16;
95 d[x] = d[x + g_menuscreen_w / 2] = t;
96 }
97 }
98 return;
99 }
100
101 if (w > g_menuscreen_w)
102 w = g_menuscreen_w;
103 if (h > g_menuscreen_h)
104 h = g_menuscreen_h;
105 dst = (short *)g_menubg_ptr +
106 (g_menuscreen_h / 2 - h / 2) * g_menuscreen_w +
107 (g_menuscreen_w / 2 - w / 2);
108
109 // darken the active framebuffer
110 for (; h > 0; dst += g_menuscreen_w, src += g_screen_width, h--)
111 menu_darken_bg(dst, src, w, 1);
112}
113
5d1672cb 114static void menu_enter(int is_rom_loaded)
115{
116 if (is_rom_loaded)
117 {
d4d62665 118 make_bg(0);
5d1672cb 119 }
120 else
121 {
28653a49 122 int pos;
5d1672cb 123 char buff[256];
28653a49
PC
124 pos = plat_get_skin_dir(buff, 256);
125 strcpy(buff + pos, "background.png");
5d1672cb 126
127 // should really only happen once, on startup..
28653a49
PC
128 if (readpng(g_menubg_ptr, buff, READPNG_BG,
129 g_menuscreen_w, g_menuscreen_h) < 0)
5d1672cb 130 memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
131 }
132
133 plat_video_menu_enter(is_rom_loaded);
134}
135
d2fd8a7a 136static void draw_savestate_bg(int slot)
137{
138 const char *fname;
139 void *tmp_state;
140
c7074ddb 141 fname = emu_get_save_fname(1, 0, slot, NULL);
d2fd8a7a 142 if (!fname)
143 return;
144
145 tmp_state = PicoTmpStateSave();
146
147 PicoStateLoadGfx(fname);
148
149 /* do a frame and fetch menu bg */
150 pemu_forced_frame(0, 0);
151
d4d62665 152 make_bg(0);
d2fd8a7a 153
154 PicoTmpStateRestore(tmp_state);
155}
156
157// --------- loading ROM screen ----------
158
159static int cdload_called = 0;
160
161static void load_progress_cb(int percent)
162{
163 int ln, len = percent * g_menuscreen_w / 100;
164 unsigned short *dst;
165
166 if (len > g_menuscreen_w)
167 len = g_menuscreen_w;
168
e743be20 169 menu_draw_begin(0, 1);
d2fd8a7a 170 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
171 for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w)
172 memset(dst, 0xff, len * 2);
173 menu_draw_end();
174}
175
176static void cdload_progress_cb(const char *fname, int percent)
177{
178 int ln, len = percent * g_menuscreen_w / 100;
179 unsigned short *dst;
180
e743be20 181 menu_draw_begin(0, 1);
d2fd8a7a 182 dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2;
183 memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2);
184
185 smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
186 smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
187 dst += g_menuscreen_w * me_sfont_h * 3;
188
189 if (len > g_menuscreen_w)
190 len = g_menuscreen_w;
191
192 for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w)
193 memset(dst, 0xff, len * 2);
194 menu_draw_end();
195
196 cdload_called = 1;
197}
198
199void menu_romload_prepare(const char *rom_name)
200{
201 const char *p = rom_name + strlen(rom_name);
202 int i;
203
204 while (p > rom_name && *p != '/')
205 p--;
206
207 /* fill all buffers, callbacks won't update in full */
208 for (i = 0; i < 3; i++) {
e743be20 209 menu_draw_begin(1, 1);
d2fd8a7a 210 smalltext_out16(1, 1, "Loading", 0xffff);
211 smalltext_out16(1, me_sfont_h, p, 0xffff);
212 menu_draw_end();
213 }
214
215 PicoCartLoadProgressCB = load_progress_cb;
216 PicoCDLoadProgressCB = cdload_progress_cb;
217 cdload_called = 0;
218}
219
220void menu_romload_end(void)
221{
222 PicoCartLoadProgressCB = NULL;
223 PicoCDLoadProgressCB = NULL;
224
e743be20 225 menu_draw_begin(0, 1);
d2fd8a7a 226 smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
227 "Starting emulation...", 0xffff);
228 menu_draw_end();
229}
230
231// ------------ patch/gg menu ------------
232
233static void draw_patchlist(int sel)
234{
235 int max_cnt, start, i, pos, active;
236
237 max_cnt = g_menuscreen_h / me_sfont_h;
238 start = max_cnt / 2 - sel;
239
e743be20 240 menu_draw_begin(1, 0);
d2fd8a7a 241
242 for (i = 0; i < PicoPatchCount; i++) {
243 pos = start + i;
244 if (pos < 0) continue;
245 if (pos >= max_cnt) break;
246 active = PicoPatches[i].active;
247 smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
248 smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
249 }
250 pos = start + i;
251 if (pos < max_cnt)
252 smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
253
254 text_out16(5, max_cnt / 2 * me_sfont_h, ">");
255 menu_draw_end();
256}
257
258static void menu_loop_patches(void)
259{
260 static int menu_sel = 0;
261 int inp;
262
263 for (;;)
264 {
265 draw_patchlist(menu_sel);
13450307 266 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
267 |PBTN_MOK|PBTN_MBACK, NULL, 33);
d2fd8a7a 268 if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
269 if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
270 if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
271 if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
272 if (inp & PBTN_MOK) { // action
273 if (menu_sel < PicoPatchCount)
274 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
275 else break;
276 }
277 if (inp & PBTN_MBACK)
278 break;
279 }
280}
281
282// -------------- key config --------------
283
284// PicoPad[] format: MXYZ SACB RLDU
285me_bind_action me_ctrl_actions[] =
286{
287 { "UP ", 0x0001 },
288 { "DOWN ", 0x0002 },
289 { "LEFT ", 0x0004 },
290 { "RIGHT ", 0x0008 },
291 { "A ", 0x0040 },
292 { "B ", 0x0010 },
293 { "C ", 0x0020 },
294 { "A turbo", 0x4000 },
295 { "B turbo", 0x1000 },
296 { "C turbo", 0x2000 },
297 { "START ", 0x0080 },
298 { "MODE ", 0x0800 },
299 { "X ", 0x0400 },
300 { "Y ", 0x0200 },
301 { "Z ", 0x0100 },
302 { NULL, 0 },
303};
304
305me_bind_action emuctrl_actions[] =
306{
307 { "Load State ", PEV_STATE_LOAD },
308 { "Save State ", PEV_STATE_SAVE },
309 { "Prev Save Slot ", PEV_SSLOT_PREV },
310 { "Next Save Slot ", PEV_SSLOT_NEXT },
311 { "Switch Renderer ", PEV_SWITCH_RND },
312 { "Volume Down ", PEV_VOL_DOWN },
313 { "Volume Up ", PEV_VOL_UP },
314 { "Fast forward ", PEV_FF },
9db6a544 315 { "Reset Game ", PEV_RESET },
d2fd8a7a 316 { "Enter Menu ", PEV_MENU },
317 { "Pico Next page ", PEV_PICO_PNEXT },
318 { "Pico Prev page ", PEV_PICO_PPREV },
319 { "Pico Switch input", PEV_PICO_SWINP },
320 { NULL, 0 }
321};
322
323static int key_config_loop_wrap(int id, int keys)
324{
325 switch (id) {
326 case MA_CTRL_PLAYER1:
327 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
328 break;
329 case MA_CTRL_PLAYER2:
330 key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
331 break;
332 case MA_CTRL_EMU:
333 key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
334 break;
335 default:
336 break;
337 }
338 return 0;
339}
340
341static const char *mgn_dev_name(int id, int *offs)
342{
343 const char *name = NULL;
344 static int it = 0;
345
346 if (id == MA_CTRL_DEV_FIRST)
347 it = 0;
348
349 for (; it < IN_MAX_DEVS; it++) {
350 name = in_get_dev_name(it, 1, 1);
351 if (name != NULL)
352 break;
353 }
354
355 it++;
356 return name;
357}
358
359static int mh_saveloadcfg(int id, int keys);
360static const char *mgn_saveloadcfg(int id, int *offs);
361
531a8f38 362const char *indev_names[] = { "none", "3 button pad", "6 button pad", NULL };
363
d2fd8a7a 364static menu_entry e_menu_keyconfig[] =
365{
366 mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
367 mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
368 mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
531a8f38 369 mee_enum ("Input device 1", MA_OPT_INPUT_DEV0, currentConfig.input_dev0, indev_names),
370 mee_enum ("Input device 2", MA_OPT_INPUT_DEV1, currentConfig.input_dev1, indev_names),
d2fd8a7a 371 mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
372 mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
373 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
374 mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
375 mee_label (""),
376 mee_label ("Input devices:"),
377 mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
378 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
379 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
380 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
381 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
382 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
383 mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
384 mee_end,
385};
386
387static int menu_loop_keyconfig(int id, int keys)
388{
389 static int sel = 0;
390
4c2e3554 391 me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
10250ad2 392 me_loop(e_menu_keyconfig, &sel);
531a8f38 393
394 PicoSetInputDevice(0, currentConfig.input_dev0);
395 PicoSetInputDevice(1, currentConfig.input_dev1);
396
d2fd8a7a 397 return 0;
398}
399
400// ------------ SCD options menu ------------
401
d2fd8a7a 402static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
403static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
404static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
405static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
406 "most games don't need this";
407static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
408 "disable to improve performance";
409static const char h_bsync[] = "More accurate mode for CPUs (needed for some games)\n"
410 "disable to improve performance";
411
412static menu_entry e_menu_cd_options[] =
413{
414 mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
415 mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoOpt, POPT_EN_MCD_CDDA, h_cdda),
416 mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoOpt, POPT_EN_MCD_PCM, h_cdpcm),
d2fd8a7a 417 mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoOpt, POPT_EN_MCD_RAMCART, h_srcart),
74e770b1 418 mee_onoff_h("Scale/Rot. fx", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX, h_scfx),
d2fd8a7a 419 mee_end,
420};
421
422static int menu_loop_cd_options(int id, int keys)
423{
424 static int sel = 0;
10250ad2 425 me_loop(e_menu_cd_options, &sel);
d2fd8a7a 426 return 0;
427}
428
429// ------------ 32X options menu ------------
430
431#ifndef NO_32X
432
433// convert from multiplier of VClk
434static int mh_opt_sh2cycles(int id, int keys)
435{
ed4402a7 436 int *khz = (id == MA_32XOPT_MSH2_CYCLES) ?
437 &currentConfig.msh2_khz : &currentConfig.ssh2_khz;
d2fd8a7a 438
439 if (keys & (PBTN_LEFT|PBTN_RIGHT))
ed4402a7 440 *khz += (keys & PBTN_LEFT) ? -50 : 50;
d2fd8a7a 441 if (keys & (PBTN_L|PBTN_R))
ed4402a7 442 *khz += (keys & PBTN_L) ? -500 : 500;
d2fd8a7a 443
ed4402a7 444 if (*khz < 1)
445 *khz = 1;
446 else if (*khz > 0x7fffffff / 1000)
447 *khz = 0x7fffffff / 1000;
d2fd8a7a 448
449 return 0;
450}
451
452static const char *mgn_opt_sh2cycles(int id, int *offs)
453{
ed4402a7 454 int khz = (id == MA_32XOPT_MSH2_CYCLES) ?
455 currentConfig.msh2_khz : currentConfig.ssh2_khz;
456
457 sprintf(static_buff, "%d", khz);
d2fd8a7a 458 return static_buff;
459}
460
461static const char h_32x_enable[] = "Enable emulation of the 32X addon";
462static const char h_pwm[] = "Disabling may improve performance, but break sound";
463static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
21ebcfd3 464 "lower values speed up emulation but break games\n"
465 "at least 11000 recommended for compatibility";
d2fd8a7a 466
467static menu_entry e_menu_32x_options[] =
468{
469 mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X, h_32x_enable),
470 mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
471 mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM, h_pwm),
472 mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
473 mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
474 mee_end,
475};
476
477static int menu_loop_32x_options(int id, int keys)
478{
479 static int sel = 0;
480
481 me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
10250ad2 482 me_loop(e_menu_32x_options, &sel);
d2fd8a7a 483
ed4402a7 484 Pico32xSetClocks(currentConfig.msh2_khz * 1000, currentConfig.msh2_khz * 1000);
485
d2fd8a7a 486 return 0;
487}
488
489#endif
490
491// ------------ adv options menu ------------
492
493static menu_entry e_menu_adv_options[] =
494{
495 mee_onoff ("SRAM/BRAM saves", MA_OPT_SRAM_STATES, currentConfig.EmuOpt, EOPT_EN_SRAM),
496 mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),
497 mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoOpt, POPT_EN_Z80),
498 mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),
499 mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),
500 mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES),
501 mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
502 mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
503 mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
92dfd9af 504 mee_onoff ("Enable dynarecs", MA_OPT2_DYNARECS, PicoOpt, POPT_EN_DRC),
75a30842 505 mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC),
d2fd8a7a 506 MENU_OPTIONS_ADV
507 mee_end,
508};
509
510static int menu_loop_adv_options(int id, int keys)
511{
512 static int sel = 0;
10250ad2 513 me_loop(e_menu_adv_options, &sel);
d2fd8a7a 514 return 0;
515}
516
517// ------------ gfx options menu ------------
518
75a30842 519static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)";
520
521static const char *mgn_aopt_gamma(int id, int *offs)
522{
523 sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
524 return static_buff;
525}
636d5f25 526
d2fd8a7a 527static menu_entry e_menu_gfx_options[] =
528{
d4d62665 529 mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
530 mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
531 mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
75a30842 532 mee_range_cust_h("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma, h_gamma),
d2fd8a7a 533 MENU_OPTIONS_GFX
534 mee_end,
535};
536
537static int menu_loop_gfx_options(int id, int keys)
538{
539 static int sel = 0;
540
541 me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
10250ad2 542 me_loop(e_menu_gfx_options, &sel);
d2fd8a7a 543
544 return 0;
545}
546
547// ------------ options menu ------------
548
549static menu_entry e_menu_options[];
550
551static int sndrate_prevnext(int rate, int dir)
552{
553 static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
554 int i;
555
556 for (i = 0; i < 5; i++)
557 if (rates[i] == rate) break;
558
559 i += dir ? 1 : -1;
560 if (i > 4) {
561 if (!(PicoOpt & POPT_EN_STEREO)) {
562 PicoOpt |= POPT_EN_STEREO;
563 return rates[0];
564 }
565 return rates[4];
566 }
567 if (i < 0) {
568 if (PicoOpt & POPT_EN_STEREO) {
569 PicoOpt &= ~POPT_EN_STEREO;
570 return rates[4];
571 }
572 return rates[0];
573 }
574 return rates[i];
575}
576
577static void region_prevnext(int right)
578{
579 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
580 static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
581 int i;
582
583 if (right) {
584 if (!PicoRegionOverride) {
585 for (i = 0; i < 6; i++)
586 if (rgn_orders[i] == PicoAutoRgnOrder) break;
587 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
588 else PicoRegionOverride=1;
589 }
590 else
591 PicoRegionOverride <<= 1;
592 if (PicoRegionOverride > 8)
593 PicoRegionOverride = 8;
594 } else {
595 if (!PicoRegionOverride) {
596 for (i = 0; i < 6; i++)
597 if (rgn_orders[i] == PicoAutoRgnOrder) break;
598 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
599 }
600 else
601 PicoRegionOverride >>= 1;
602 }
603}
604
605static int mh_opt_misc(int id, int keys)
606{
607 switch (id) {
608 case MA_OPT_SOUND_QUALITY:
609 PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
610 break;
611 case MA_OPT_REGION:
612 region_prevnext(keys & PBTN_RIGHT);
613 break;
614 default:
615 break;
616 }
617 return 0;
618}
619
620static int mh_saveloadcfg(int id, int keys)
621{
622 int ret;
623
624 if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
625 config_slot += (keys & PBTN_LEFT) ? -1 : 1;
626 if (config_slot < 0) config_slot = 9;
627 else if (config_slot > 9) config_slot = 0;
628 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
629 return 0;
630 }
631
632 switch (id) {
633 case MA_OPT_SAVECFG:
634 case MA_OPT_SAVECFG_GAME:
635 if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
e743be20 636 menu_update_msg("config saved");
d2fd8a7a 637 else
e743be20 638 menu_update_msg("failed to write config");
d2fd8a7a 639 break;
640 case MA_OPT_LOADCFG:
641 ret = emu_read_config(rom_fname_loaded, 1);
642 if (!ret) ret = emu_read_config(NULL, 1);
e743be20 643 if (ret) menu_update_msg("config loaded");
644 else menu_update_msg("failed to load config");
d2fd8a7a 645 break;
646 default:
647 return 0;
648 }
649
650 return 1;
651}
652
653static int mh_restore_defaults(int id, int keys)
654{
655 emu_set_defconfig();
e743be20 656 menu_update_msg("defaults restored");
d2fd8a7a 657 return 1;
658}
659
660static const char *mgn_opt_fskip(int id, int *offs)
661{
662 if (currentConfig.Frameskip < 0)
663 return "Auto";
664 sprintf(static_buff, "%d", currentConfig.Frameskip);
665 return static_buff;
666}
667
668static const char *mgn_opt_sound(int id, int *offs)
669{
670 const char *str2;
671 *offs = -8;
672 str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
673 sprintf(static_buff, "%5iHz %s", PsndRate, str2);
674 return static_buff;
675}
676
677static const char *mgn_opt_region(int id, int *offs)
678{
679 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
680 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
681 int code = PicoRegionOverride;
682 int u, i = 0;
683
684 *offs = -6;
685 if (code) {
686 code <<= 1;
687 while ((code >>= 1)) i++;
688 if (i > 4)
689 return "unknown";
690 return names[i];
691 } else {
692 strcpy(static_buff, "Auto:");
693 for (u = 0; u < 3; u++) {
694 code = (PicoAutoRgnOrder >> u*4) & 0xf;
695 for (i = 0; code; code >>= 1, i++)
696 ;
697 strcat(static_buff, names_short[i]);
698 }
699 return static_buff;
700 }
701}
702
703static const char *mgn_saveloadcfg(int id, int *offs)
704{
705 static_buff[0] = 0;
706 if (config_slot != 0)
707 sprintf(static_buff, "[%i]", config_slot);
708 return static_buff;
709}
710
711static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
712static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
713 "loading state or both";
714
715static menu_entry e_menu_options[] =
716{
717 mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
718 mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
719 mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
720 mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
721 mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
722 mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),
723 mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES,currentConfig.confirm_save, men_confirm_save, h_confirm_save),
68af34fe 724 mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 3200),
d2fd8a7a 725 mee_handler ("[Display options]", menu_loop_gfx_options),
726 mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
727#ifndef NO_32X
728 mee_handler ("[32X options]", menu_loop_32x_options),
729#endif
730 mee_handler ("[Advanced options]", menu_loop_adv_options),
731 mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
732 mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
733 mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
734 mee_handler ("Restore defaults", mh_restore_defaults),
735 mee_end,
736};
737
738static int menu_loop_options(int id, int keys)
739{
740 static int sel = 0;
d2fd8a7a 741
4c2e3554 742 me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
d2fd8a7a 743 me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
744
10250ad2 745 me_loop(e_menu_options, &sel);
d2fd8a7a 746
747 return 0;
748}
749
750// ------------ debug menu ------------
751
752#include <pico/debug.h>
753
754extern void SekStepM68k(void);
755
756static void mplayer_loop(void)
757{
758 pemu_sound_start();
759
760 while (1)
761 {
762 PDebugZ80Frame();
13450307 763 if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
d2fd8a7a 764 break;
df92fbd1 765 emu_sound_wait();
d2fd8a7a 766 }
767
df92fbd1 768 emu_sound_stop();
d2fd8a7a 769}
770
771static void draw_text_debug(const char *str, int skip, int from)
772{
773 const char *p;
774 int line;
775
776 p = str;
777 while (skip-- > 0)
778 {
779 while (*p && *p != '\n')
780 p++;
781 if (*p == 0 || p[1] == 0)
782 return;
783 p++;
784 }
785
786 str = p;
787 for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
788 {
789 smalltext_out16(1, line * me_sfont_h, str, 0xffff);
790 while (*p && *p != '\n')
791 p++;
792 if (*p == 0)
793 break;
794 p++; str = p;
795 }
796}
797
798#ifdef __GNUC__
799#define COMPILER "gcc " __VERSION__
800#else
801#define COMPILER
802#endif
803
804static void draw_frame_debug(void)
805{
806 char layer_str[48] = "layers: ";
e0bcb7a9 807 struct PicoVideo *pv = &Pico.video;
808
809 if (!(pv->debug_p & PVD_KILL_B)) memcpy(layer_str + 8, "B", 1);
810 if (!(pv->debug_p & PVD_KILL_A)) memcpy(layer_str + 10, "A", 1);
811 if (!(pv->debug_p & PVD_KILL_S_LO)) memcpy(layer_str + 12, "spr_lo", 6);
812 if (!(pv->debug_p & PVD_KILL_S_HI)) memcpy(layer_str + 19, "spr_hi", 6);
813 if (!(pv->debug_p & PVD_KILL_32X)) memcpy(layer_str + 26, "32x", 4);
d2fd8a7a 814
815 pemu_forced_frame(1, 0);
d4d62665 816 make_bg(1);
817
d2fd8a7a 818 smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
819 smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
820}
821
822static void debug_menu_loop(void)
823{
e0bcb7a9 824 struct PicoVideo *pv = &Pico.video;
d2fd8a7a 825 int inp, mode = 0;
826 int spr_offs = 0, dumped = 0;
827 char *tmp;
828
829 while (1)
830 {
e743be20 831 menu_draw_begin(1, 0);
d2fd8a7a 832 switch (mode)
833 {
834 case 0: tmp = PDebugMain();
835 plat_debug_cat(tmp);
836 draw_text_debug(tmp, 0, 0);
837 if (dumped) {
838 smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
839 g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
840 dumped = 0;
841 }
842 break;
843 case 1: draw_frame_debug();
844 break;
845 case 2: pemu_forced_frame(1, 0);
d4d62665 846 make_bg(1);
d2fd8a7a 847 PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w +
848 g_menuscreen_w/2 - 320/2, g_menuscreen_w);
849 break;
850 case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
851 PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w);
852 PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16,
853 g_menuscreen_w, spr_offs);
854 draw_text_debug(PDebugSpriteList(), spr_offs, 6);
855 break;
856 case 4: tmp = PDebug32x();
857 draw_text_debug(tmp, 0, 0);
858 break;
859 }
860 menu_draw_end();
861
862 inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
13450307 863 PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
d2fd8a7a 864 if (inp & PBTN_MBACK) return;
865 if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
866 if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
867 switch (mode)
868 {
869 case 0:
870 if (inp & PBTN_MOK)
871 PDebugCPUStep();
872 if (inp & PBTN_MA3) {
873 while (inp & PBTN_MA3)
13450307 874 inp = in_menu_wait_any(NULL, -1);
d2fd8a7a 875 mplayer_loop();
876 }
877 if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
878 mkdir("dumps", 0777);
879 PDebugDumpMem();
13450307 880 while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
d2fd8a7a 881 dumped = 1;
882 }
883 break;
884 case 1:
e0bcb7a9 885 if (inp & PBTN_LEFT) pv->debug_p ^= PVD_KILL_B;
886 if (inp & PBTN_RIGHT) pv->debug_p ^= PVD_KILL_A;
887 if (inp & PBTN_DOWN) pv->debug_p ^= PVD_KILL_S_LO;
888 if (inp & PBTN_UP) pv->debug_p ^= PVD_KILL_S_HI;
889 if (inp & PBTN_MA2) pv->debug_p ^= PVD_KILL_32X;
d2fd8a7a 890 if (inp & PBTN_MOK) {
891 PsndOut = NULL; // just in case
892 PicoSkipFrame = 1;
893 PicoFrame();
894 PicoSkipFrame = 0;
13450307 895 while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
d2fd8a7a 896 }
897 break;
898 case 3:
899 if (inp & PBTN_DOWN) spr_offs++;
900 if (inp & PBTN_UP) spr_offs--;
901 if (spr_offs < 0) spr_offs = 0;
902 break;
903 }
904 }
905}
906
907// ------------ main menu ------------
908
33afcf94 909static void draw_frame_credits(void)
910{
911 smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xe7fc);
912}
913
21ebcfd3 914static const char credits[] =
b59172e3 915 "PicoDrive v" VERSION " (c) notaz, 2006-2013\n\n\n"
21ebcfd3 916 "Credits:\n"
33afcf94 917 "fDave: initial code\n"
918#ifdef EMU_C68K
919 " Cyclone 68000 core\n"
920#else
921 "Stef, Chui: FAME/C 68k core\n"
922#endif
923#ifdef _USE_DRZ80
21ebcfd3 924 "Reesy & FluBBa: DrZ80 core\n"
33afcf94 925#else
926 "Stef, NJ: CZ80 core\n"
927#endif
928 "MAME devs: SH2, YM2612 and SN76496 cores\n"
929 "Eke, Stef: some Sega CD code\n"
21ebcfd3 930 "Inder, ketchupgun: graphics\n"
931#ifdef __GP2X__
21ebcfd3 932 "Squidge: mmuhack\n"
933 "Dzz: ARM940 sample\n"
934#endif
935 "\n"
936 "special thanks (for docs, ideas):\n"
937 " Charles MacDonald, Haze,\n"
938 " Stephane Dallongeville,\n"
939 " Lordus, Exophase, Rokas,\n"
b59172e3 940 " Eke, Nemesis, Tasco Deluxe";
21ebcfd3 941
75a30842 942static void menu_main_draw_status(void)
943{
944 static time_t last_bat_read = 0;
945 static int last_bat_val = -1;
946 unsigned short *bp = g_screen_ptr;
947 int bat_h = me_mfont_h * 2 / 3;
948 int i, u, w, wfill, batt_val;
949 struct tm *tmp;
950 time_t ltime;
951 char time_s[16];
952
953 if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
954 return;
955
956 ltime = time(NULL);
957 tmp = gmtime(&ltime);
958 strftime(time_s, sizeof(time_s), "%H:%M", tmp);
959
960 text_out16(g_screen_width - me_mfont_w * 6, me_mfont_h + 2, time_s);
961
962 if (ltime - last_bat_read > 10) {
963 last_bat_read = ltime;
964 last_bat_val = batt_val = plat_target_bat_capacity_get();
965 }
966 else
967 batt_val = last_bat_val;
968
969 if (batt_val < 0 || batt_val > 100)
970 return;
971
972 /* battery info */
973 bp += (me_mfont_h * 2 + 2) * g_screen_width + g_screen_width - me_mfont_w * 3 - 3;
974 for (i = 0; i < me_mfont_w * 2; i++)
975 bp[i] = menu_text_color;
976 for (i = 0; i < me_mfont_w * 2; i++)
977 bp[i + g_screen_width * bat_h] = menu_text_color;
978 for (i = 0; i <= bat_h; i++)
979 bp[i * g_screen_width] =
980 bp[i * g_screen_width + me_mfont_w * 2] = menu_text_color;
981 for (i = 2; i < bat_h - 1; i++)
982 bp[i * g_screen_width - 1] =
983 bp[i * g_screen_width - 2] = menu_text_color;
984
985 w = me_mfont_w * 2 - 1;
986 wfill = batt_val * w / 100;
987 for (u = 1; u < bat_h; u++)
988 for (i = 0; i < wfill; i++)
989 bp[(w - i) + g_screen_width * u] = menu_text_color;
990}
991
d2fd8a7a 992static int main_menu_handler(int id, int keys)
993{
e743be20 994 const char *ret_name;
d2fd8a7a 995
996 switch (id)
997 {
998 case MA_MAIN_RESUME_GAME:
4c2e3554 999 if (PicoGameLoaded)
d2fd8a7a 1000 return 1;
1001 break;
1002 case MA_MAIN_SAVE_STATE:
4c2e3554 1003 if (PicoGameLoaded)
d2fd8a7a 1004 return menu_loop_savestate(0);
1005 break;
1006 case MA_MAIN_LOAD_STATE:
4c2e3554 1007 if (PicoGameLoaded)
d2fd8a7a 1008 return menu_loop_savestate(1);
1009 break;
1010 case MA_MAIN_RESET_GAME:
4c2e3554 1011 if (PicoGameLoaded) {
d2fd8a7a 1012 emu_reset_game();
1013 return 1;
1014 }
1015 break;
1016 case MA_MAIN_LOAD_ROM:
636d5f25 1017 rom_fname_reload = NULL;
1018 ret_name = menu_loop_romsel(rom_fname_loaded,
1019 sizeof(rom_fname_loaded), rom_exts, NULL);
d2fd8a7a 1020 if (ret_name != NULL) {
1021 lprintf("selected file: %s\n", ret_name);
636d5f25 1022 rom_fname_reload = ret_name;
d2fd8a7a 1023 engineState = PGS_ReloadRom;
1024 return 1;
1025 }
1026 break;
d0132772 1027 case MA_MAIN_CHANGE_CD:
1028 if (PicoAHW & PAHW_MCD) {
7b3ddc11 1029 // if cd is loaded, cdd_unload() triggers eject and
1030 // returns 1, else we'll select and load new CD here
274fcc35 1031 if (!cdd_unload())
d0132772 1032 menu_loop_tray();
1033 return 1;
1034 }
1035 break;
d2fd8a7a 1036 case MA_MAIN_CREDITS:
33afcf94 1037 draw_menu_message(credits, draw_frame_credits);
13450307 1038 in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
d2fd8a7a 1039 break;
1040 case MA_MAIN_EXIT:
1041 engineState = PGS_Quit;
1042 return 1;
1043 case MA_MAIN_PATCHES:
4c2e3554 1044 if (PicoGameLoaded && PicoPatches) {
d2fd8a7a 1045 menu_loop_patches();
1046 PicoPatchApply();
e743be20 1047 menu_update_msg("Patches applied");
d2fd8a7a 1048 }
1049 break;
1050 default:
1051 lprintf("%s: something unknown selected\n", __FUNCTION__);
1052 break;
1053 }
1054
1055 return 0;
1056}
1057
1058static menu_entry e_menu_main[] =
1059{
1060 mee_label ("PicoDrive " VERSION),
1061 mee_label (""),
1062 mee_label (""),
1063 mee_label (""),
1064 mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
1065 mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
1066 mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
1067 mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
1068 mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
d0132772 1069 mee_handler_id("Change CD/ISO", MA_MAIN_CHANGE_CD, main_menu_handler),
d2fd8a7a 1070 mee_handler ("Change options", menu_loop_options),
1071 mee_handler ("Configure controls", menu_loop_keyconfig),
1072 mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
1073 mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
1074 mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
1075 mee_end,
1076};
1077
1078void menu_loop(void)
1079{
1080 static int sel = 0;
1081
4c2e3554 1082 me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
1083 me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
1084 me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
1085 me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
d0132772 1086 me_enable(e_menu_main, MA_MAIN_CHANGE_CD, PicoAHW & PAHW_MCD);
d2fd8a7a 1087 me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
1088
4c2e3554 1089 menu_enter(PicoGameLoaded);
d2fd8a7a 1090 in_set_config_int(0, IN_CFG_BLOCKING, 1);
75a30842 1091 me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
d2fd8a7a 1092
4c2e3554 1093 if (PicoGameLoaded) {
d2fd8a7a 1094 if (engineState == PGS_Menu)
1095 engineState = PGS_Running;
1096 /* wait until menu, ok, back is released */
13450307 1097 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
d2fd8a7a 1098 ;
1099 }
1100
1101 in_set_config_int(0, IN_CFG_BLOCKING, 0);
636d5f25 1102 plat_video_menu_leave();
d2fd8a7a 1103}
1104
1105// --------- CD tray close menu ----------
1106
1107static int mh_tray_load_cd(int id, int keys)
1108{
e743be20 1109 const char *ret_name;
d2fd8a7a 1110
636d5f25 1111 rom_fname_reload = NULL;
1112 ret_name = menu_loop_romsel(rom_fname_loaded,
1113 sizeof(rom_fname_loaded), rom_exts, NULL);
d2fd8a7a 1114 if (ret_name == NULL)
1115 return 0;
1116
636d5f25 1117 rom_fname_reload = ret_name;
d2fd8a7a 1118 engineState = PGS_RestartRun;
1119 return emu_swap_cd(ret_name);
1120}
1121
1122static int mh_tray_nothing(int id, int keys)
1123{
1124 return 1;
1125}
1126
1127static menu_entry e_menu_tray[] =
1128{
1129 mee_label ("The CD tray has opened."),
1130 mee_label (""),
1131 mee_label (""),
1132 mee_handler("Load CD image", mh_tray_load_cd),
1133 mee_handler("Insert nothing", mh_tray_nothing),
1134 mee_end,
1135};
1136
1137int menu_loop_tray(void)
1138{
1139 int ret = 1, sel = 0;
1140
4c2e3554 1141 menu_enter(PicoGameLoaded);
d2fd8a7a 1142
1143 in_set_config_int(0, IN_CFG_BLOCKING, 1);
10250ad2 1144 me_loop(e_menu_tray, &sel);
d2fd8a7a 1145
1146 if (engineState != PGS_RestartRun) {
1147 engineState = PGS_RestartRun;
1148 ret = 0; /* no CD inserted */
1149 }
1150
da77daa9 1151 while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
1152 ;
d2fd8a7a 1153 in_set_config_int(0, IN_CFG_BLOCKING, 0);
636d5f25 1154 plat_video_menu_leave();
d2fd8a7a 1155
1156 return ret;
1157}
1158
e743be20 1159void menu_update_msg(const char *msg)
d2fd8a7a 1160{
1161 strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
1162 menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
1163
1164 menu_error_time = plat_get_ticks_ms();
1165 lprintf("msg: %s\n", menu_error_msg);
1166}
1167
1168// ------------ util ------------
1169
1170/* hidden options for config engine only */
1171static menu_entry e_menu_hidden[] =
1172{
1173 mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),
c7074ddb 1174 mee_onoff("autoload savestates", MA_OPT_AUTOLOAD_SAVE, g_autostateld_opt, 1),
d2fd8a7a 1175 mee_end,
1176};
1177
1178static menu_entry *e_menu_table[] =
1179{
1180 e_menu_options,
1181 e_menu_gfx_options,
1182 e_menu_adv_options,
1183 e_menu_cd_options,
1184#ifndef NO_32X
1185 e_menu_32x_options,
1186#endif
1187 e_menu_keyconfig,
1188 e_menu_hidden,
1189};
1190
1191static menu_entry *me_list_table = NULL;
1192static menu_entry *me_list_i = NULL;
1193
1194menu_entry *me_list_get_first(void)
1195{
1196 me_list_table = me_list_i = e_menu_table[0];
1197 return me_list_i;
1198}
1199
1200menu_entry *me_list_get_next(void)
1201{
1202 int i;
1203
1204 me_list_i++;
1205 if (me_list_i->name != NULL)
1206 return me_list_i;
1207
1208 for (i = 0; i < array_size(e_menu_table); i++)
1209 if (me_list_table == e_menu_table[i])
1210 break;
1211
1212 if (i + 1 < array_size(e_menu_table))
1213 me_list_table = me_list_i = e_menu_table[i + 1];
1214 else
1215 me_list_table = me_list_i = NULL;
1216
1217 return me_list_i;
1218}
1219
e743be20 1220void menu_init(void)
1221{
636d5f25 1222 int i;
1223
e743be20 1224 menu_init_base();
636d5f25 1225
75a30842 1226 i = 0;
1227#if defined(_SVP_DRC) || defined(DRC_SH2)
1228 i = 1;
1229#endif
92dfd9af 1230 me_enable(e_menu_adv_options, MA_OPT2_DYNARECS, i);
75a30842 1231
636d5f25 1232 i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
1233 e_menu_gfx_options[i].data = plat_target.vout_methods;
1234 me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
1235 plat_target.vout_methods != NULL);
d4d62665 1236
1237 i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
1238 e_menu_gfx_options[i].data = plat_target.hwfilters;
1239 me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
1240 plat_target.hwfilters != NULL);
1241
75a30842 1242 me_enable(e_menu_gfx_options, MA_OPT2_GAMMA,
d4d62665 1243 plat_target.gamma_set != NULL);
75a30842 1244
1245 i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
1246 e_menu_options[i].enabled = 0;
1247 if (plat_target.cpu_clock_set != NULL) {
1248 e_menu_options[i].name = "CPU clock";
1249 e_menu_options[i].enabled = 1;
1250 }
e743be20 1251}