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