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