69af03a2 |
1 | /* |
2 | * (C) GraÅžvydas "notaz" Ignotas, 2010 |
3 | * |
4 | * This work is licensed under the terms of any of these licenses |
5 | * (at your option): |
6 | * - GNU GPL, version 2 or later. |
7 | * - GNU LGPL, version 2.1 or later. |
8 | * See the COPYING file in the top-level directory. |
9 | */ |
10 | |
11 | #include <stdio.h> |
12 | #include <string.h> |
3c70c47b |
13 | #include <errno.h> |
69af03a2 |
14 | |
3c70c47b |
15 | #include "menu.h" |
69af03a2 |
16 | #include "config.h" |
17 | #include "plugin_lib.h" |
18 | #include "omap.h" |
19 | #include "common/plat.h" |
3c70c47b |
20 | #include "../gui/Linux.h" |
69af03a2 |
21 | #include "../libpcsxcore/misc.h" |
7eda34c1 |
22 | #include "../libpcsxcore/new_dynarec/new_dynarec.h" |
3c70c47b |
23 | #include "revision.h" |
69af03a2 |
24 | |
25 | #define MENU_X2 1 |
26 | #define array_size(x) (sizeof(x) / sizeof(x[0])) |
27 | |
28 | typedef enum |
29 | { |
30 | MA_NONE = 1, |
31 | MA_MAIN_RESUME_GAME, |
32 | MA_MAIN_SAVE_STATE, |
33 | MA_MAIN_LOAD_STATE, |
34 | MA_MAIN_RESET_GAME, |
35 | MA_MAIN_LOAD_ROM, |
36 | MA_MAIN_CONTROLS, |
37 | MA_MAIN_CREDITS, |
38 | MA_MAIN_EXIT, |
39 | MA_CTRL_PLAYER1, |
40 | MA_CTRL_PLAYER2, |
41 | MA_CTRL_EMU, |
42 | MA_CTRL_DEV_FIRST, |
43 | MA_CTRL_DEV_NEXT, |
44 | MA_CTRL_DONE, |
45 | MA_OPT_SAVECFG, |
46 | MA_OPT_SAVECFG_GAME, |
47 | MA_OPT_CPU_CLOCKS, |
3c70c47b |
48 | MA_OPT_FILTERING, |
69af03a2 |
49 | } menu_id; |
50 | |
3c70c47b |
51 | enum { |
52 | SCALE_1_1, |
53 | SCALE_4_3, |
54 | SCALE_FULLSCREEN, |
55 | SCALE_CUSTOM, |
56 | }; |
69af03a2 |
57 | |
3c70c47b |
58 | extern int ready_to_go; |
59 | static int game_config_loaded, last_psx_w, last_psx_h; |
60 | static int scaling, filter, state_slot, cpu_clock; |
69af03a2 |
61 | static int dummy, state_slot; |
62 | static char rom_fname_reload[MAXPATHLEN]; |
63 | static char last_selected_fname[MAXPATHLEN]; |
64 | |
65 | void emu_make_path(char *buff, const char *end, int size) |
66 | { |
67 | int pos, end_len; |
68 | |
69 | end_len = strlen(end); |
70 | pos = plat_get_root_dir(buff, size); |
71 | strncpy(buff + pos, end, size - pos); |
72 | buff[size - 1] = 0; |
73 | if (pos + end_len > size - 1) |
74 | printf("Warning: path truncated: %s\n", buff); |
75 | } |
76 | |
77 | static int emu_check_save_file(int slot) |
78 | { |
3c70c47b |
79 | char *fname; |
80 | int ret; |
81 | |
82 | fname = get_state_filename(slot); |
83 | if (fname == NULL) |
84 | return 0; |
85 | |
86 | ret = CheckState(fname); |
87 | free(fname); |
88 | return ret == 0 ? 1 : 0; |
69af03a2 |
89 | } |
90 | |
91 | static int emu_save_load_game(int load, int sram) |
92 | { |
3c70c47b |
93 | char *fname; |
94 | int ret; |
95 | |
96 | fname = get_state_filename(state_slot); |
97 | if (fname == NULL) |
98 | return 0; |
99 | |
100 | if (load) |
101 | ret = LoadState(fname); |
102 | else |
103 | ret = SaveState(fname); |
104 | free(fname); |
105 | |
106 | return ret; |
69af03a2 |
107 | } |
108 | |
3c70c47b |
109 | static void draw_savestate_bg(int slot) |
69af03a2 |
110 | { |
69af03a2 |
111 | } |
112 | |
3c70c47b |
113 | static void menu_set_defconfig(void) |
114 | { |
115 | scaling = SCALE_4_3; |
116 | } |
117 | |
118 | static int menu_write_config(int is_game) |
119 | { |
120 | return -1; |
121 | } |
122 | |
123 | static int menu_load_config(int is_game) |
69af03a2 |
124 | { |
3c70c47b |
125 | return 0; |
69af03a2 |
126 | } |
127 | |
3c70c47b |
128 | #define menu_init menu_init_common |
69af03a2 |
129 | #include "common/menu.c" |
3c70c47b |
130 | #undef menu_init |
69af03a2 |
131 | |
3c70c47b |
132 | // ---------- pandora specific ----------- |
133 | |
134 | static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts"; |
135 | static char **pnd_filter_list; |
136 | |
137 | static int get_cpu_clock(void) |
69af03a2 |
138 | { |
3c70c47b |
139 | FILE *f; |
140 | int ret = 0; |
141 | f = fopen("/proc/pandora/cpu_mhz_max", "r"); |
142 | if (f) { |
143 | fscanf(f, "%d", &ret); |
144 | fclose(f); |
145 | } |
146 | return ret; |
147 | } |
148 | |
149 | static void apply_cpu_clock(void) |
150 | { |
151 | char buf[128]; |
152 | |
153 | if (cpu_clock != 0 && cpu_clock != get_cpu_clock()) { |
154 | snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d", |
155 | pnd_script_base, cpu_clock); |
156 | system(buf); |
157 | } |
158 | } |
159 | |
160 | static void apply_filter(int which) |
161 | { |
162 | char buf[128]; |
163 | int i; |
164 | |
165 | if (pnd_filter_list == NULL) |
166 | return; |
167 | |
168 | for (i = 0; i < which; i++) |
169 | if (pnd_filter_list[i] == NULL) |
170 | return; |
171 | |
172 | if (pnd_filter_list[i] == NULL) |
173 | return; |
174 | |
175 | snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]); |
176 | system(buf); |
177 | } |
178 | |
179 | static menu_entry e_menu_gfx_options[]; |
180 | |
181 | static void pnd_menu_init(void) |
182 | { |
183 | struct dirent *ent; |
184 | int i, count = 0; |
185 | char **mfilters; |
186 | char buff[64], *p; |
187 | DIR *dir; |
188 | |
189 | cpu_clock = get_cpu_clock(); |
190 | |
191 | dir = opendir("/etc/pandora/conf/dss_fir"); |
192 | if (dir == NULL) { |
193 | perror("filter opendir"); |
194 | return; |
195 | } |
196 | |
197 | while (1) { |
198 | errno = 0; |
199 | ent = readdir(dir); |
200 | if (ent == NULL) { |
201 | if (errno != 0) |
202 | perror("readdir"); |
203 | break; |
204 | } |
205 | p = strstr(ent->d_name, "_up"); |
206 | if (p != NULL && (p[3] == 0 || !strcmp(p + 3, "_h"))) |
207 | count++; |
208 | } |
209 | |
210 | if (count == 0) |
211 | return; |
212 | |
213 | mfilters = calloc(count + 1, sizeof(mfilters[0])); |
214 | if (mfilters == NULL) |
215 | return; |
216 | |
217 | rewinddir(dir); |
218 | for (i = 0; (ent = readdir(dir)); ) { |
219 | size_t len; |
220 | |
221 | p = strstr(ent->d_name, "_up"); |
222 | if (p == NULL || (p[3] != 0 && strcmp(p + 3, "_h"))) |
223 | continue; |
224 | |
225 | len = p - ent->d_name; |
226 | if (len > sizeof(buff) - 1) |
227 | continue; |
228 | |
229 | strncpy(buff, ent->d_name, len); |
230 | buff[len] = 0; |
231 | mfilters[i] = strdup(buff); |
232 | if (mfilters[i] != NULL) |
233 | i++; |
234 | } |
235 | closedir(dir); |
236 | |
237 | i = me_id2offset(e_menu_gfx_options, MA_OPT_FILTERING); |
238 | e_menu_gfx_options[i].data = (void *)mfilters; |
239 | pnd_filter_list = mfilters; |
69af03a2 |
240 | } |
241 | |
242 | // -------------- key config -------------- |
243 | |
244 | me_bind_action me_ctrl_actions[] = |
245 | { |
246 | { "UP ", 1 << DKEY_UP}, |
247 | { "DOWN ", 1 << DKEY_DOWN }, |
248 | { "LEFT ", 1 << DKEY_LEFT }, |
249 | { "RIGHT ", 1 << DKEY_RIGHT }, |
250 | { "TRIANGLE", 1 << DKEY_TRIANGLE }, |
251 | { "CIRCLE ", 1 << DKEY_SQUARE }, |
252 | { "CROSS ", 1 << DKEY_CROSS }, |
253 | { "SQUARE ", 1 << DKEY_SQUARE }, |
254 | { "L1 ", 1 << DKEY_L1 }, |
255 | { "R1 ", 1 << DKEY_R1 }, |
256 | { "L2 ", 1 << DKEY_L2 }, |
257 | { "R2 ", 1 << DKEY_R2 }, |
258 | { "START ", 1 << DKEY_START }, |
259 | { "SELECT ", 1 << DKEY_SELECT }, |
260 | { NULL, 0 } |
261 | }; |
262 | |
263 | me_bind_action emuctrl_actions[] = |
264 | { |
265 | { "Load State ", PEV_STATE_LOAD }, |
266 | { "Save State ", PEV_STATE_SAVE }, |
267 | { "Prev Save Slot ", PEV_SSLOT_PREV }, |
268 | { "Next Save Slot ", PEV_SSLOT_NEXT }, |
269 | { "Enter Menu ", PEV_MENU }, |
270 | { NULL, 0 } |
271 | }; |
272 | |
273 | static int key_config_loop_wrap(int id, int keys) |
274 | { |
275 | switch (id) { |
276 | case MA_CTRL_PLAYER1: |
277 | key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0); |
278 | break; |
279 | case MA_CTRL_PLAYER2: |
280 | key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1); |
281 | break; |
282 | case MA_CTRL_EMU: |
283 | key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1); |
284 | break; |
285 | default: |
286 | break; |
287 | } |
288 | return 0; |
289 | } |
290 | |
291 | static const char *mgn_dev_name(int id, int *offs) |
292 | { |
293 | const char *name = NULL; |
294 | static int it = 0; |
295 | |
296 | if (id == MA_CTRL_DEV_FIRST) |
297 | it = 0; |
298 | |
299 | for (; it < IN_MAX_DEVS; it++) { |
300 | name = in_get_dev_name(it, 1, 1); |
301 | if (name != NULL) |
302 | break; |
303 | } |
304 | |
305 | it++; |
306 | return name; |
307 | } |
308 | |
309 | static const char *mgn_saveloadcfg(int id, int *offs) |
310 | { |
311 | return ""; |
312 | } |
313 | |
314 | static int mh_saveloadcfg(int id, int keys) |
315 | { |
316 | switch (id) { |
317 | case MA_OPT_SAVECFG: |
318 | case MA_OPT_SAVECFG_GAME: |
3c70c47b |
319 | if (menu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0) == 0) |
69af03a2 |
320 | me_update_msg("config saved"); |
321 | else |
322 | me_update_msg("failed to write config"); |
323 | break; |
324 | default: |
325 | return 0; |
326 | } |
327 | |
328 | return 1; |
329 | } |
330 | |
331 | static menu_entry e_menu_keyconfig[] = |
332 | { |
333 | mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap), |
334 | mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap), |
335 | mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap), |
336 | mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg), |
337 | mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg), |
338 | mee_label (""), |
339 | mee_label ("Input devices:"), |
340 | mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name), |
341 | mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name), |
342 | mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name), |
343 | mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name), |
344 | mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name), |
345 | mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name), |
346 | mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name), |
347 | mee_end, |
348 | }; |
349 | |
350 | static int menu_loop_keyconfig(int id, int keys) |
351 | { |
352 | static int sel = 0; |
353 | |
354 | me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, ready_to_go); |
355 | me_loop(e_menu_keyconfig, &sel, NULL); |
356 | return 0; |
357 | } |
358 | |
359 | // ------------ adv options menu ------------ |
360 | |
361 | static menu_entry e_menu_adv_options[] = |
362 | { |
363 | mee_onoff ("captain placeholder", 0, dummy, 1), |
364 | mee_end, |
365 | }; |
366 | |
367 | static int menu_loop_adv_options(int id, int keys) |
368 | { |
369 | static int sel = 0; |
370 | me_loop(e_menu_adv_options, &sel, NULL); |
371 | return 0; |
372 | } |
373 | |
374 | // ------------ gfx options menu ------------ |
375 | |
3c70c47b |
376 | static const char *men_scaler[] = { "1x1", "scaled 4:3", "fullscreen", "custom", NULL }; |
377 | static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n" |
378 | "using d-pad or move it using R+d-pad"; |
379 | static const char *men_dummy[] = { NULL }; |
380 | |
381 | static int menu_loop_cscaler(int id, int keys) |
382 | { |
383 | unsigned int inp; |
384 | |
385 | scaling = SCALE_CUSTOM; |
386 | |
387 | omap_enable_layer(1); |
388 | //pnd_restore_layer_data(); |
389 | |
390 | for (;;) |
391 | { |
392 | menu_draw_begin(0); |
393 | memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); |
394 | text_out16(2, 480 - 18, "%dx%d | d-pad to resize, R+d-pad to move", g_layer_w, g_layer_h); |
395 | menu_draw_end(); |
396 | |
397 | inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40); |
398 | if (inp & PBTN_UP) g_layer_y--; |
399 | if (inp & PBTN_DOWN) g_layer_y++; |
400 | if (inp & PBTN_LEFT) g_layer_x--; |
401 | if (inp & PBTN_RIGHT) g_layer_x++; |
402 | if (!(inp & PBTN_R)) { |
403 | if (inp & PBTN_UP) g_layer_h += 2; |
404 | if (inp & PBTN_DOWN) g_layer_h -= 2; |
405 | if (inp & PBTN_LEFT) g_layer_w += 2; |
406 | if (inp & PBTN_RIGHT) g_layer_w -= 2; |
407 | } |
408 | if (inp & (PBTN_MOK|PBTN_MBACK)) |
409 | break; |
410 | |
411 | if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) { |
412 | if (g_layer_x < 0) g_layer_x = 0; |
413 | if (g_layer_x > 640) g_layer_x = 640; |
414 | if (g_layer_y < 0) g_layer_y = 0; |
415 | if (g_layer_y > 420) g_layer_y = 420; |
416 | if (g_layer_w < 160) g_layer_w = 160; |
417 | if (g_layer_h < 60) g_layer_h = 60; |
418 | if (g_layer_x + g_layer_w > 800) |
419 | g_layer_w = 800 - g_layer_x; |
420 | if (g_layer_y + g_layer_h > 480) |
421 | g_layer_h = 480 - g_layer_y; |
422 | omap_enable_layer(1); |
423 | } |
424 | } |
425 | |
426 | omap_enable_layer(0); |
427 | |
428 | return 0; |
429 | } |
430 | |
69af03a2 |
431 | static menu_entry e_menu_gfx_options[] = |
432 | { |
3c70c47b |
433 | mee_enum ("Scaler", 0, scaling, men_scaler), |
434 | mee_enum ("Filter", MA_OPT_FILTERING, filter, men_dummy), |
435 | // mee_onoff ("Vsync", 0, vsync, 1), |
436 | mee_cust_h ("Setup custom scaler", 0, menu_loop_cscaler, NULL, h_cscaler), |
69af03a2 |
437 | mee_end, |
438 | }; |
439 | |
440 | static int menu_loop_gfx_options(int id, int keys) |
441 | { |
442 | static int sel = 0; |
443 | |
444 | me_loop(e_menu_gfx_options, &sel, NULL); |
445 | |
446 | return 0; |
447 | } |
448 | |
449 | // ------------ options menu ------------ |
450 | |
69af03a2 |
451 | static int mh_restore_defaults(int id, int keys) |
452 | { |
3c70c47b |
453 | menu_set_defconfig(); |
69af03a2 |
454 | me_update_msg("defaults restored"); |
455 | return 1; |
456 | } |
457 | |
458 | static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL }; |
459 | static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n" |
460 | "loading state or both"; |
461 | |
462 | static menu_entry e_menu_options[] = |
463 | { |
464 | mee_range ("Save slot", 0, state_slot, 0, 9), |
465 | mee_enum_h ("Confirm savestate", 0, dummy, men_confirm_save, h_confirm_save), |
3c70c47b |
466 | mee_range ("CPU clock", MA_OPT_CPU_CLOCKS, cpu_clock, 20, 5000), |
69af03a2 |
467 | mee_handler ("[Display]", menu_loop_gfx_options), |
468 | mee_handler ("[Advanced]", menu_loop_adv_options), |
469 | mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg), |
470 | mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg), |
471 | mee_handler ("Restore defaults", mh_restore_defaults), |
472 | mee_end, |
473 | }; |
474 | |
475 | static int menu_loop_options(int id, int keys) |
476 | { |
477 | static int sel = 0; |
478 | int i; |
479 | |
480 | i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS); |
3c70c47b |
481 | e_menu_options[i].enabled = cpu_clock != 0 ? 1 : 0; |
69af03a2 |
482 | me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, ready_to_go); |
483 | |
484 | me_loop(e_menu_options, &sel, NULL); |
485 | |
486 | return 0; |
487 | } |
488 | |
489 | // ------------ debug menu ------------ |
490 | |
69af03a2 |
491 | static void draw_frame_debug(void) |
492 | { |
3c70c47b |
493 | smalltext_out16(4, 1, "build: "__DATE__ " " __TIME__ " " REV, 0xe7fc); |
69af03a2 |
494 | } |
495 | |
496 | static void debug_menu_loop(void) |
497 | { |
498 | int inp; |
499 | |
500 | while (1) |
501 | { |
502 | menu_draw_begin(1); |
503 | draw_frame_debug(); |
504 | menu_draw_end(); |
505 | |
506 | inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R | |
507 | PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70); |
508 | if (inp & PBTN_MBACK) |
509 | return; |
510 | } |
511 | } |
512 | |
513 | // ------------ main menu ------------ |
514 | |
515 | const char *plat_get_credits(void) |
516 | { |
517 | return "(C) 1999-2003 PCSX Team\n" |
518 | "(C) 2005-2009 PCSX-df Team\n" |
519 | "(C) 2009-2010 PCSX-Reloaded Team\n\n" |
520 | "GPU and SPU code by Pete Bernert\n" |
521 | " and the P.E.Op.S. team\n" |
522 | "ARM recompiler by Ari64\n\n" |
523 | "integration, optimization and\n" |
524 | " frontend by (C) notaz, 2010\n"; |
525 | } |
526 | |
527 | static char *romsel_run(void) |
528 | { |
47bf65ab |
529 | extern void set_cd_image(const char *fname); |
69af03a2 |
530 | char *ret; |
531 | |
532 | ret = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname)); |
533 | if (ret == NULL) |
534 | return NULL; |
535 | |
536 | lprintf("selected file: %s\n", ret); |
537 | ready_to_go = 0; |
538 | |
47bf65ab |
539 | set_cd_image(ret); |
69af03a2 |
540 | LoadPlugins(); |
541 | NetOpened = 0; |
542 | if (OpenPlugins() == -1) { |
543 | me_update_msg("failed to open plugins"); |
544 | return NULL; |
545 | } |
546 | |
547 | SysReset(); |
548 | |
549 | if (CheckCdrom() == -1) { |
550 | // Only check the CD if we are starting the console with a CD |
551 | ClosePlugins(); |
552 | me_update_msg("unsupported/invalid CD image"); |
553 | return NULL; |
554 | } |
555 | |
556 | // Read main executable directly from CDRom and start it |
557 | if (LoadCdrom() == -1) { |
558 | ClosePlugins(); |
559 | me_update_msg("failed to load CD image"); |
560 | return NULL; |
561 | } |
562 | |
3c70c47b |
563 | game_config_loaded = 0; |
69af03a2 |
564 | ready_to_go = 1; |
565 | return ret; |
566 | } |
567 | |
568 | static int main_menu_handler(int id, int keys) |
569 | { |
570 | char *ret_name; |
571 | |
572 | switch (id) |
573 | { |
574 | case MA_MAIN_RESUME_GAME: |
3c70c47b |
575 | if (ready_to_go) |
576 | return 1; |
69af03a2 |
577 | break; |
578 | case MA_MAIN_SAVE_STATE: |
579 | if (ready_to_go) |
580 | return menu_loop_savestate(0); |
581 | break; |
582 | case MA_MAIN_LOAD_STATE: |
583 | if (ready_to_go) |
584 | return menu_loop_savestate(1); |
585 | break; |
586 | case MA_MAIN_RESET_GAME: |
3c70c47b |
587 | if (ready_to_go) { |
588 | OpenPlugins(); |
589 | SysReset(); |
590 | if (CheckCdrom() != -1) { |
591 | LoadCdrom(); |
592 | } |
593 | return 1; |
594 | } |
69af03a2 |
595 | break; |
596 | case MA_MAIN_LOAD_ROM: |
597 | ret_name = romsel_run(); |
598 | if (ret_name != NULL) |
599 | return 1; |
600 | break; |
601 | case MA_MAIN_CREDITS: |
3c70c47b |
602 | draw_menu_credits(draw_frame_debug); |
69af03a2 |
603 | in_menu_wait(PBTN_MOK|PBTN_MBACK, 70); |
604 | break; |
605 | case MA_MAIN_EXIT: |
606 | exit(1); // FIXME |
607 | default: |
608 | lprintf("%s: something unknown selected\n", __FUNCTION__); |
609 | break; |
610 | } |
611 | |
612 | return 0; |
613 | } |
614 | |
615 | static menu_entry e_menu_main[] = |
616 | { |
617 | mee_label (""), |
618 | mee_label (""), |
619 | mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler), |
620 | mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler), |
621 | mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler), |
622 | mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler), |
623 | mee_handler_id("Load CD image", MA_MAIN_LOAD_ROM, main_menu_handler), |
624 | mee_handler ("Options", menu_loop_options), |
625 | mee_handler ("Controls", menu_loop_keyconfig), |
626 | mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler), |
627 | mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler), |
628 | mee_end, |
629 | }; |
630 | |
3c70c47b |
631 | // ---------------------------- |
632 | |
69af03a2 |
633 | void menu_loop(void) |
634 | { |
635 | static int sel = 0; |
636 | |
637 | omap_enable_layer(0); |
638 | |
639 | me_enable(e_menu_main, MA_MAIN_RESUME_GAME, ready_to_go); |
640 | me_enable(e_menu_main, MA_MAIN_SAVE_STATE, ready_to_go); |
641 | me_enable(e_menu_main, MA_MAIN_LOAD_STATE, ready_to_go); |
642 | me_enable(e_menu_main, MA_MAIN_RESET_GAME, ready_to_go); |
643 | |
644 | strcpy(last_selected_fname, "/mnt/ntz/stuff/psx"); |
645 | menu_enter(ready_to_go); |
646 | in_set_config_int(0, IN_CFG_BLOCKING, 1); |
647 | |
648 | do { |
3c70c47b |
649 | me_loop(e_menu_main, &sel, draw_frame_debug); |
69af03a2 |
650 | } while (!ready_to_go); |
651 | |
652 | /* wait until menu, ok, back is released */ |
653 | while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK)) |
654 | ; |
655 | |
656 | in_set_config_int(0, IN_CFG_BLOCKING, 0); |
657 | |
658 | memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); |
659 | menu_draw_end(); |
3c70c47b |
660 | menu_prepare_emu(); |
661 | } |
662 | |
663 | void menu_init(void) |
664 | { |
665 | menu_set_defconfig(); |
666 | menu_load_config(0); |
667 | menu_init_common(); |
668 | pnd_menu_init(); |
669 | last_psx_w = 320; |
670 | last_psx_h = 240; |
671 | } |
672 | |
673 | void menu_notify_mode_change(int w, int h) |
674 | { |
675 | last_psx_w = w; |
676 | last_psx_h = h; |
677 | |
678 | if (scaling == SCALE_1_1) { |
679 | g_layer_x = 800/2 - w/2; g_layer_y = 480/2 - h/2; |
680 | g_layer_w = w; g_layer_h = h; |
681 | omap_enable_layer(1); |
682 | } |
683 | } |
684 | |
685 | void menu_prepare_emu(void) |
686 | { |
687 | if (!game_config_loaded) { |
688 | menu_load_config(1); |
689 | game_config_loaded = 1; |
690 | } |
691 | |
692 | switch (scaling) { |
693 | case SCALE_1_1: |
694 | menu_notify_mode_change(last_psx_w, last_psx_h); |
695 | break; |
696 | case SCALE_4_3: |
697 | g_layer_x = 80; g_layer_y = 0; |
698 | g_layer_w = 640; g_layer_h = 480; |
699 | break; |
700 | case SCALE_FULLSCREEN: |
701 | g_layer_x = 0; g_layer_y = 0; |
702 | g_layer_w = 800; g_layer_h = 480; |
703 | break; |
704 | case SCALE_CUSTOM: |
705 | break; |
706 | } |
69af03a2 |
707 | omap_enable_layer(1); |
3c70c47b |
708 | apply_filter(filter); |
709 | apply_cpu_clock(); |
7eda34c1 |
710 | stop = 0; |
69af03a2 |
711 | } |
712 | |
713 | void me_update_msg(const char *msg) |
714 | { |
715 | strncpy(menu_error_msg, msg, sizeof(menu_error_msg)); |
716 | menu_error_msg[sizeof(menu_error_msg) - 1] = 0; |
717 | |
718 | menu_error_time = plat_get_ticks_ms(); |
719 | lprintf("msg: %s\n", menu_error_msg); |
720 | } |
721 | |