d524c827 |
1 | // (c) Copyright 2006,2007 notaz, All rights reserved.\r |
cc68a136 |
2 | // Free for non-commercial use.\r |
3 | \r |
4 | // For commercial use, separate licencing terms must be obtained.\r |
5 | \r |
6 | #include <stdio.h>\r |
7 | #include <string.h>\r |
8 | #include <stdlib.h>\r |
9 | #include <stdarg.h>\r |
10 | #include <unistd.h>\r |
11 | #include <dirent.h>\r |
12 | \r |
13 | #include "gp2x.h"\r |
14 | #include "emu.h"\r |
15 | #include "menu.h"\r |
76276b0b |
16 | #include "fonts.h"\r |
cc68a136 |
17 | #include "usbjoy.h"\r |
721cd396 |
18 | #include "asmutils.h"\r |
cc68a136 |
19 | #include "version.h"\r |
20 | \r |
b67ef287 |
21 | #include <Pico/PicoInt.h>\r |
22 | #include <Pico/Patch.h>\r |
23 | #include <zlib/zlib.h>\r |
cc68a136 |
24 | \r |
25 | #ifndef _DIRENT_HAVE_D_TYPE\r |
26 | #error "need d_type for file browser\r |
27 | #endif\r |
28 | \r |
cc68a136 |
29 | extern char romFileName[PATH_MAX];\r |
30 | extern char *rom_data;\r |
31 | extern int mmuhack_status;\r |
32 | extern int state_slot;\r |
4e8a534c |
33 | extern int config_slot, config_slot_current;\r |
cc68a136 |
34 | \r |
35 | static char *gp2xKeyNames[] = {\r |
36 | "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",\r |
37 | "START", "SELECT", "L", "R", "A", "B", "X", "Y",\r |
38 | "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",\r |
39 | "???", "???", "???", "PUSH", "???", "???", "???", "???"\r |
40 | };\r |
41 | \r |
42 | char menuErrorMsg[40] = {0, };\r |
43 | \r |
44 | \r |
76276b0b |
45 | static void gp2x_text(unsigned char *screen, int x, int y, const char *text, int color)\r |
cc68a136 |
46 | {\r |
47 | int i,l;\r |
48 | \r |
49 | screen = screen + x + y*320;\r |
50 | \r |
51 | for (i = 0; i < strlen(text); i++)\r |
52 | {\r |
53 | for (l=0;l<8;l++)\r |
54 | {\r |
55 | if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=color;\r |
56 | if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=color;\r |
57 | if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=color;\r |
58 | if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=color;\r |
59 | if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=color;\r |
60 | if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=color;\r |
61 | if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=color;\r |
62 | if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=color;\r |
63 | }\r |
64 | screen += 8;\r |
65 | }\r |
66 | }\r |
67 | \r |
68 | // draws white text to current bbp15 screen\r |
76276b0b |
69 | void gp2x_text_out15(int x, int y, const char *text)\r |
cc68a136 |
70 | {\r |
71 | int i,l;\r |
72 | unsigned short *screen = gp2x_screen;\r |
73 | \r |
74 | screen = screen + x + y*320;\r |
75 | \r |
76 | for (i = 0; i < strlen(text); i++)\r |
77 | {\r |
78 | for (l=0;l<8;l++)\r |
79 | {\r |
80 | if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;\r |
81 | if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;\r |
82 | if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;\r |
83 | if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;\r |
84 | if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;\r |
85 | if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;\r |
86 | if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;\r |
87 | if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;\r |
88 | }\r |
89 | screen += 8;\r |
90 | }\r |
91 | }\r |
92 | \r |
93 | \r |
76276b0b |
94 | void gp2x_text_out8(int x, int y, const char *texto, ...)\r |
cc68a136 |
95 | {\r |
96 | va_list args;\r |
97 | char buffer[512];\r |
98 | \r |
99 | va_start(args,texto);\r |
100 | vsprintf(buffer,texto,args);\r |
101 | va_end(args);\r |
102 | \r |
e11c5548 |
103 | gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r |
cc68a136 |
104 | }\r |
105 | \r |
106 | \r |
76276b0b |
107 | void gp2x_text_out8_2(int x, int y, const char *texto, int color)\r |
cc68a136 |
108 | {\r |
109 | gp2x_text(gp2x_screen, x, y, texto, color);\r |
110 | }\r |
111 | \r |
76276b0b |
112 | void gp2x_text_out8_lim(int x, int y, const char *texto, int max)\r |
cc68a136 |
113 | {\r |
114 | char buffer[320/8+1];\r |
115 | \r |
116 | strncpy(buffer, texto, 320/8);\r |
117 | if (max > 320/8) max = 320/8;\r |
118 | if (max < 0) max = 0;\r |
119 | buffer[max] = 0;\r |
120 | \r |
e11c5548 |
121 | gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r |
cc68a136 |
122 | }\r |
123 | \r |
76276b0b |
124 | static void gp2x_smalltext8(int x, int y, const char *texto)\r |
125 | {\r |
126 | int i;\r |
127 | unsigned char *src, *dst;\r |
128 | \r |
129 | for (i = 0;; i++, x += 6)\r |
130 | {\r |
131 | unsigned char c = (unsigned char) texto[i];\r |
132 | int h = 8;\r |
133 | \r |
134 | if (!c) break;\r |
135 | \r |
136 | src = fontdata6x8[c];\r |
137 | dst = (unsigned char *)gp2x_screen + x + y*320;\r |
138 | \r |
139 | while (h--)\r |
140 | {\r |
141 | int w = 0x20;\r |
142 | while (w)\r |
143 | {\r |
144 | if( *src & w ) *dst = 0xf0;\r |
145 | dst++;\r |
146 | w>>=1;\r |
147 | }\r |
148 | src++;\r |
149 | \r |
150 | dst += 320-6;\r |
151 | }\r |
152 | }\r |
153 | }\r |
154 | \r |
155 | static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)\r |
156 | {\r |
157 | char buffer[320/6+1];\r |
158 | \r |
159 | strncpy(buffer, texto, 320/6);\r |
160 | if (max > 320/6) max = 320/6;\r |
161 | if (max < 0) max = 0;\r |
162 | buffer[max] = 0;\r |
163 | \r |
164 | gp2x_smalltext8(x, y, buffer);\r |
165 | }\r |
166 | \r |
cc68a136 |
167 | \r |
4e8a534c |
168 | typedef enum\r |
169 | {\r |
170 | MB_NONE = 1, /* no auto processing */\r |
171 | MB_ONOFF, /* ON/OFF setting */\r |
172 | MB_RANGE, /* [min-max] setting */\r |
173 | } menu_behavior;\r |
174 | \r |
175 | typedef enum\r |
176 | {\r |
177 | MA_NONE = 1,\r |
178 | MA_MAIN_RESUME_GAME,\r |
179 | MA_MAIN_SAVE_STATE,\r |
180 | MA_MAIN_LOAD_STATE,\r |
181 | MA_MAIN_RESET_GAME,\r |
182 | MA_MAIN_LOAD_ROM,\r |
183 | MA_MAIN_OPTIONS,\r |
184 | MA_MAIN_CONTROLS,\r |
185 | MA_MAIN_CREDITS,\r |
186 | MA_MAIN_PATCHES,\r |
187 | MA_MAIN_EXIT,\r |
188 | MA_OPT_RENDERER,\r |
189 | MA_OPT_SCALING,\r |
190 | MA_OPT_ACC_TIMING,\r |
191 | MA_OPT_ACC_SPRITES,\r |
192 | MA_OPT_SHOW_FPS,\r |
193 | MA_OPT_FRAMESKIP,\r |
194 | MA_OPT_ENABLE_SOUND,\r |
195 | MA_OPT_SOUND_QUALITY,\r |
196 | MA_OPT_ARM940_SOUND,\r |
197 | MA_OPT_6BUTTON_PAD,\r |
198 | MA_OPT_REGION,\r |
199 | MA_OPT_SRAM_STATES,\r |
200 | MA_OPT_CONFIRM_STATES,\r |
201 | MA_OPT_SAVE_SLOT,\r |
202 | MA_OPT_CPU_CLOCKS,\r |
203 | MA_OPT_SCD_OPTS,\r |
204 | MA_OPT_ADV_OPTS,\r |
205 | MA_OPT_SAVECFG,\r |
206 | MA_OPT_SAVECFG_GAME,\r |
207 | MA_OPT_LOADCFG,\r |
208 | MA_OPT2_GAMMA,\r |
209 | MA_OPT2_A_SN_GAMMA,\r |
210 | MA_OPT2_VSYNC,\r |
211 | MA_OPT2_ENABLE_Z80,\r |
212 | MA_OPT2_ENABLE_YM2612,\r |
213 | MA_OPT2_ENABLE_SN76496,\r |
214 | MA_OPT2_GZIP_STATES,\r |
215 | MA_OPT2_NO_LAST_ROM,\r |
216 | MA_OPT2_RAMTIMINGS,\r |
217 | MA_OPT2_SQUIDGEHACK,\r |
218 | MA_OPT2_DONE,\r |
219 | MA_CDOPT_TESTBIOS_USA,\r |
220 | MA_CDOPT_TESTBIOS_EUR,\r |
221 | MA_CDOPT_TESTBIOS_JAP,\r |
222 | MA_CDOPT_LEDS,\r |
223 | MA_CDOPT_CDDA,\r |
224 | MA_CDOPT_PCM,\r |
225 | MA_CDOPT_READAHEAD,\r |
226 | MA_CDOPT_SAVERAM,\r |
227 | MA_CDOPT_SCALEROT_CHIP,\r |
228 | MA_CDOPT_BETTER_SYNC,\r |
229 | MA_CDOPT_DONE,\r |
230 | } menu_id;\r |
231 | \r |
232 | typedef struct\r |
233 | {\r |
234 | char *name;\r |
235 | menu_behavior beh;\r |
236 | menu_id id;\r |
237 | void *var; /* for on-off settings */\r |
238 | int mask;\r |
239 | signed char min; /* for ranged integer settings, to be sign-extended */\r |
240 | signed char max;\r |
241 | char enabled;\r |
242 | } menu_entry;\r |
243 | \r |
244 | static int me_id2offset(const menu_entry *entries, int count, menu_id id)\r |
245 | {\r |
246 | int i;\r |
247 | for (i = 0; i < count; i++)\r |
248 | {\r |
249 | if (entries[i].id == id) return i;\r |
250 | }\r |
251 | \r |
252 | printf("%s: id %i not found\n", __FUNCTION__, id);\r |
253 | return 0;\r |
254 | }\r |
255 | \r |
256 | static void me_enable(menu_entry *entries, int count, menu_id id, int enable)\r |
257 | {\r |
258 | int i = me_id2offset(entries, count, id);\r |
259 | entries[i].enabled = enable;\r |
260 | }\r |
261 | \r |
262 | static int me_count_enabled(const menu_entry *entries, int count)\r |
263 | {\r |
264 | int i, ret = 0;\r |
265 | \r |
266 | for (i = 0; i < count; i++)\r |
267 | {\r |
268 | if (entries[i].enabled) ret++;\r |
269 | }\r |
270 | \r |
271 | return ret;\r |
272 | }\r |
273 | \r |
274 | static menu_id me_index2id(const menu_entry *entries, int count, int index)\r |
275 | {\r |
276 | int i;\r |
277 | \r |
278 | for (i = 0; i < count; i++)\r |
279 | {\r |
280 | if (entries[i].enabled)\r |
281 | {\r |
282 | if (index == 0) break;\r |
283 | index--;\r |
284 | }\r |
285 | }\r |
286 | if (i >= count) i = count - 1;\r |
287 | return entries[i].id;\r |
288 | }\r |
289 | \r |
290 | typedef void (me_draw_custom_f)(const menu_entry *entry, int x, int y, void *param);\r |
291 | \r |
292 | static void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param)\r |
293 | {\r |
294 | int i, y1 = y;\r |
295 | \r |
296 | for (i = 0; i < count; i++)\r |
297 | {\r |
298 | if (!entries[i].enabled) continue;\r |
299 | if (entries[i].name == NULL)\r |
300 | {\r |
301 | if (cust_draw != NULL)\r |
302 | cust_draw(&entries[i], x, y1, param);\r |
303 | y1 += 10;\r |
304 | continue;\r |
305 | }\r |
306 | gp2x_text_out8(x, y1, entries[i].name);\r |
307 | if (entries[i].beh == MB_ONOFF)\r |
308 | gp2x_text_out8(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF");\r |
309 | else if (entries[i].beh == MB_RANGE)\r |
310 | gp2x_text_out8(x + 27*8, y1, "%i", *(int *)entries[i].var);\r |
311 | y1 += 10;\r |
312 | }\r |
313 | }\r |
314 | \r |
315 | static int me_process(menu_entry *entries, int count, menu_id id, int is_next)\r |
316 | {\r |
317 | int i = me_id2offset(entries, count, id);\r |
318 | menu_entry *entry = &entries[i];\r |
319 | switch (entry->beh)\r |
320 | {\r |
321 | case MB_ONOFF:\r |
322 | *(int *)entry->var ^= entry->mask;\r |
323 | return 1;\r |
324 | case MB_RANGE:\r |
325 | *(int *)entry->var += is_next ? 1 : -1;\r |
326 | if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->min;\r |
327 | if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->max;\r |
328 | return 1;\r |
329 | default:\r |
330 | return 0;\r |
331 | }\r |
332 | }\r |
333 | \r |
334 | \r |
335 | \r |
336 | \r |
cc68a136 |
337 | static unsigned long inp_prev = 0;\r |
338 | static int inp_prevjoy = 0;\r |
339 | \r |
340 | static unsigned long wait_for_input(unsigned long interesting)\r |
341 | {\r |
342 | unsigned long ret;\r |
721cd396 |
343 | static int repeats = 0, wait = 50*1000;\r |
cc68a136 |
344 | int release = 0, i;\r |
345 | \r |
721cd396 |
346 | if (repeats == 2 || repeats == 4) wait /= 2;\r |
347 | if (repeats == 6) wait = 15 * 1000;\r |
cc68a136 |
348 | \r |
349 | for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {\r |
721cd396 |
350 | if (i == 0) repeats++;\r |
351 | if (wait >= 30*1000) usleep(wait); // usleep sleeps for ~30ms minimum\r |
352 | else spend_cycles(wait * currentConfig.CPUclock);\r |
cc68a136 |
353 | }\r |
354 | \r |
355 | while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {\r |
356 | usleep(50000);\r |
357 | release = 1;\r |
358 | }\r |
359 | \r |
360 | if (release || ret != inp_prev) {\r |
361 | repeats = 0;\r |
721cd396 |
362 | wait = 50*1000;\r |
cc68a136 |
363 | }\r |
364 | inp_prev = ret;\r |
365 | inp_prevjoy = 0;\r |
366 | \r |
367 | // we don't need diagonals in menus\r |
368 | if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;\r |
369 | if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;\r |
370 | if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;\r |
371 | if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;\r |
372 | \r |
373 | return ret;\r |
374 | }\r |
375 | \r |
376 | static unsigned long input2_read(unsigned long interesting, int *joy)\r |
377 | {\r |
378 | unsigned long ret;\r |
379 | int i;\r |
380 | \r |
381 | do\r |
382 | {\r |
383 | *joy = 0;\r |
384 | if ((ret = gp2x_joystick_read(0) & interesting)) break;\r |
385 | gp2x_usbjoy_update();\r |
386 | for (i = 0; i < num_of_joys; i++) {\r |
387 | ret = gp2x_usbjoy_check2(i);\r |
388 | if (ret) { *joy = i + 1; break; }\r |
389 | }\r |
390 | if (ret) break;\r |
391 | }\r |
392 | while(0);\r |
393 | \r |
394 | return ret;\r |
395 | }\r |
396 | \r |
397 | // similar to wait_for_input(), but returns joy num\r |
398 | static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)\r |
399 | {\r |
400 | unsigned long ret;\r |
401 | const int wait = 300*1000;\r |
402 | int i;\r |
403 | \r |
404 | if (inp_prevjoy == 0) inp_prev &= interesting;\r |
405 | for (i = 0; i < 6; i++) {\r |
406 | ret = input2_read(interesting, joy);\r |
407 | if (*joy != inp_prevjoy || ret != inp_prev) break;\r |
408 | usleep(wait/6);\r |
409 | }\r |
410 | \r |
411 | while ( !(ret = input2_read(interesting, joy)) ) {\r |
412 | usleep(50000);\r |
413 | }\r |
414 | \r |
415 | inp_prev = ret;\r |
416 | inp_prevjoy = *joy;\r |
417 | \r |
418 | return ret;\r |
419 | }\r |
420 | \r |
421 | \r |
422 | \r |
423 | // -------------- ROM selector --------------\r |
424 | \r |
425 | static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r |
426 | {\r |
427 | int start, i, pos;\r |
428 | \r |
429 | start = 12 - sel;\r |
430 | n--; // exclude current dir (".")\r |
431 | \r |
e11c5548 |
432 | //memset(gp2x_screen, 0, 320*240);\r |
433 | gp2x_pd_clone_buffer2();\r |
cc68a136 |
434 | \r |
435 | if(start - 2 >= 0)\r |
76276b0b |
436 | gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);\r |
cc68a136 |
437 | for (i = 0; i < n; i++) {\r |
438 | pos = start + i;\r |
439 | if (pos < 0) continue;\r |
440 | if (pos > 23) break;\r |
441 | if (namelist[i+1]->d_type == DT_DIR) {\r |
76276b0b |
442 | gp2x_smalltext8_lim(14, pos*10, "/", 1);\r |
443 | gp2x_smalltext8_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);\r |
cc68a136 |
444 | } else {\r |
76276b0b |
445 | gp2x_smalltext8_lim(14, pos*10, namelist[i+1]->d_name, 53-2);\r |
cc68a136 |
446 | }\r |
447 | }\r |
448 | gp2x_text_out8(5, 120, ">");\r |
e11c5548 |
449 | gp2x_video_flip2();\r |
cc68a136 |
450 | }\r |
451 | \r |
452 | static int scandir_cmp(const void *p1, const void *p2)\r |
453 | {\r |
454 | struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r |
455 | if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r |
456 | if ((*d1)->d_type == DT_DIR) return -1; // put before\r |
457 | if ((*d2)->d_type == DT_DIR) return 1;\r |
458 | return alphasort(d1, d2);\r |
459 | }\r |
460 | \r |
2433f409 |
461 | static char *filter_exts[] = {\r |
462 | ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",\r |
463 | ".jpg", ".gpe", ".cue"\r |
464 | };\r |
c008977e |
465 | \r |
466 | static int scandir_filter(const struct dirent *ent)\r |
467 | {\r |
468 | const char *p;\r |
469 | int i;\r |
470 | \r |
471 | if (ent == NULL || ent->d_name == NULL) return 0;\r |
472 | if (strlen(ent->d_name) < 5) return 1;\r |
473 | \r |
474 | p = ent->d_name + strlen(ent->d_name) - 4;\r |
475 | \r |
476 | for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)\r |
477 | {\r |
478 | if (strcmp(p, filter_exts[i]) == 0) return 0;\r |
479 | }\r |
480 | \r |
481 | return 1;\r |
482 | }\r |
cc68a136 |
483 | \r |
484 | static char *romsel_loop(char *curr_path)\r |
485 | {\r |
486 | struct dirent **namelist;\r |
487 | DIR *dir;\r |
488 | int n, sel = 0;\r |
489 | unsigned long inp = 0;\r |
490 | char *ret = NULL, *fname = NULL;\r |
491 | \r |
492 | // is this a dir or a full path?\r |
493 | if ((dir = opendir(curr_path))) {\r |
494 | closedir(dir);\r |
495 | } else {\r |
496 | char *p;\r |
497 | for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);\r |
498 | *p = 0;\r |
499 | fname = p+1;\r |
500 | }\r |
501 | \r |
c008977e |
502 | n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r |
cc68a136 |
503 | if (n < 0) {\r |
504 | // try root\r |
c008977e |
505 | n = scandir("/", &namelist, scandir_filter, scandir_cmp);\r |
cc68a136 |
506 | if (n < 0) {\r |
507 | // oops, we failed\r |
508 | printf("dir: "); printf(curr_path); printf("\n");\r |
509 | perror("scandir");\r |
510 | return NULL;\r |
511 | }\r |
512 | }\r |
513 | \r |
514 | // try to find sel\r |
515 | if (fname != NULL) {\r |
516 | int i;\r |
517 | for (i = 1; i < n; i++) {\r |
518 | if (strcmp(namelist[i]->d_name, fname) == 0) {\r |
519 | sel = i - 1;\r |
520 | break;\r |
521 | }\r |
522 | }\r |
523 | }\r |
524 | \r |
525 | for (;;)\r |
526 | {\r |
527 | draw_dirlist(curr_path, namelist, n, sel);\r |
672ad671 |
528 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r |
cc68a136 |
529 | if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }\r |
530 | if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }\r |
721cd396 |
531 | if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r |
532 | if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; }\r |
533 | if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r |
534 | if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; }\r |
cc68a136 |
535 | if(inp & GP2X_B) { // enter dir/select\r |
536 | again:\r |
537 | if (namelist[sel+1]->d_type == DT_REG) {\r |
538 | strcpy(romFileName, curr_path);\r |
539 | strcat(romFileName, "/");\r |
540 | strcat(romFileName, namelist[sel+1]->d_name);\r |
541 | ret = romFileName;\r |
542 | break;\r |
543 | } else if (namelist[sel+1]->d_type == DT_DIR) {\r |
544 | int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r |
545 | char *p, *newdir = malloc(newlen);\r |
546 | if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r |
547 | char *start = curr_path;\r |
548 | p = start + strlen(start) - 1;\r |
549 | while (*p == '/' && p > start) p--;\r |
550 | while (*p != '/' && p > start) p--;\r |
551 | if (p <= start) strcpy(newdir, "/");\r |
552 | else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }\r |
553 | } else {\r |
554 | strcpy(newdir, curr_path);\r |
555 | p = newdir + strlen(newdir) - 1;\r |
556 | while (*p == '/' && p >= newdir) *p-- = 0;\r |
557 | strcat(newdir, "/");\r |
558 | strcat(newdir, namelist[sel+1]->d_name);\r |
559 | }\r |
560 | ret = romsel_loop(newdir);\r |
561 | free(newdir);\r |
562 | break;\r |
563 | } else {\r |
564 | // unknown file type, happens on NTFS mounts. Try to guess.\r |
565 | FILE *tstf; int tmp;\r |
566 | strcpy(romFileName, curr_path);\r |
567 | strcat(romFileName, "/");\r |
568 | strcat(romFileName, namelist[sel+1]->d_name);\r |
569 | tstf = fopen(romFileName, "rb");\r |
570 | if (tstf != NULL)\r |
571 | {\r |
572 | if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)\r |
573 | namelist[sel+1]->d_type = DT_REG;\r |
574 | else namelist[sel+1]->d_type = DT_DIR;\r |
575 | fclose(tstf);\r |
576 | goto again;\r |
577 | }\r |
578 | }\r |
579 | }\r |
580 | if(inp & GP2X_X) break; // cancel\r |
581 | }\r |
582 | \r |
583 | if (n > 0) {\r |
584 | while(n--) free(namelist[n]);\r |
585 | free(namelist);\r |
586 | }\r |
587 | \r |
588 | return ret;\r |
589 | }\r |
590 | \r |
0af33fe0 |
591 | // ------------ debug menu ------------\r |
592 | \r |
593 | char *debugString(void);\r |
594 | \r |
595 | static void draw_debug(void)\r |
596 | {\r |
597 | char *p, *str = debugString();\r |
598 | int len, line;\r |
599 | \r |
600 | gp2x_pd_clone_buffer2();\r |
601 | \r |
602 | p = str;\r |
603 | for (line = 0; line < 24; line++)\r |
604 | {\r |
605 | while (*p && *p != '\n') p++;\r |
606 | len = p - str;\r |
607 | if (len > 55) len = 55;\r |
608 | gp2x_smalltext8_lim(1, line*10, str, len);\r |
609 | if (*p == 0) break;\r |
610 | p++; str = p;\r |
611 | }\r |
612 | gp2x_video_flip2();\r |
613 | }\r |
614 | \r |
615 | static void debug_menu_loop(void)\r |
616 | {\r |
617 | draw_debug();\r |
618 | wait_for_input(GP2X_B|GP2X_X);\r |
619 | }\r |
620 | \r |
b67ef287 |
621 | // ------------ patch/gg menu ------------\r |
622 | \r |
623 | static void draw_patchlist(int sel)\r |
624 | {\r |
625 | int start, i, pos;\r |
626 | \r |
627 | start = 12 - sel;\r |
628 | \r |
629 | gp2x_pd_clone_buffer2();\r |
630 | \r |
631 | for (i = 0; i < PicoPatchCount; i++) {\r |
632 | pos = start + i;\r |
633 | if (pos < 0) continue;\r |
634 | if (pos > 23) break;\r |
635 | gp2x_smalltext8_lim(14, pos*10, PicoPatches[i].active ? "ON " : "OFF", 3);\r |
83bd0b76 |
636 | gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6);\r |
b67ef287 |
637 | }\r |
638 | pos = start + i;\r |
639 | if (pos < 24) gp2x_smalltext8_lim(14, pos*10, "done", 4);\r |
640 | \r |
641 | gp2x_text_out8(5, 120, ">");\r |
642 | gp2x_video_flip2();\r |
643 | }\r |
644 | \r |
645 | \r |
0af33fe0 |
646 | static void patches_menu_loop(void)\r |
b67ef287 |
647 | {\r |
648 | int menu_sel = 0;\r |
649 | unsigned long inp = 0;\r |
650 | \r |
651 | for(;;)\r |
652 | {\r |
653 | draw_patchlist(menu_sel);\r |
654 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r |
655 | if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r |
656 | if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r |
657 | if(inp &(GP2X_LEFT|GP2X_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r |
658 | if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r |
659 | if(inp & GP2X_B) { // action\r |
660 | if (menu_sel < PicoPatchCount)\r |
661 | PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r |
662 | else return;\r |
663 | }\r |
664 | if(inp & GP2X_X) return;\r |
665 | }\r |
666 | \r |
667 | }\r |
668 | \r |
860c6322 |
669 | // ------------ savestate loader ------------\r |
670 | \r |
671 | static void menu_prepare_bg(void);\r |
672 | \r |
673 | static int state_slot_flags = 0;\r |
674 | \r |
675 | static void state_check_slots(void)\r |
676 | {\r |
677 | int slot;\r |
678 | \r |
679 | state_slot_flags = 0;\r |
680 | \r |
681 | for (slot = 0; slot < 10; slot++)\r |
682 | {\r |
683 | if (emu_check_save_file(slot))\r |
684 | {\r |
685 | state_slot_flags |= 1 << slot;\r |
686 | }\r |
687 | }\r |
688 | }\r |
689 | \r |
690 | static void draw_savestate_bg(int slot)\r |
691 | {\r |
692 | struct PicoVideo tmp_pv;\r |
693 | unsigned short tmp_cram[0x40];\r |
694 | unsigned short tmp_vsram[0x40];\r |
695 | void *tmp_vram, *file;\r |
696 | char *fname;\r |
697 | \r |
698 | fname = emu_GetSaveFName(1, 0, slot);\r |
699 | if (!fname) return;\r |
700 | \r |
701 | tmp_vram = malloc(sizeof(Pico.vram));\r |
702 | if (tmp_vram == NULL) return;\r |
703 | \r |
704 | memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));\r |
705 | memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));\r |
706 | memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));\r |
707 | memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));\r |
708 | \r |
709 | if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r |
710 | file = gzopen(fname, "rb");\r |
711 | emu_set_save_cbs(1);\r |
712 | } else {\r |
713 | file = fopen(fname, "rb");\r |
714 | emu_set_save_cbs(0);\r |
715 | }\r |
716 | \r |
717 | if (file) {\r |
718 | if (PicoMCD & 1) {\r |
719 | PicoCdLoadStateGfx(file);\r |
720 | } else {\r |
721 | areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file\r |
722 | areaRead(Pico.vram, 1, sizeof(Pico.vram), file);\r |
723 | areaSeek(file, 0x2000, SEEK_CUR);\r |
724 | areaRead(Pico.cram, 1, sizeof(Pico.cram), file);\r |
725 | areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);\r |
726 | areaSeek(file, 0x221a0, SEEK_SET);\r |
727 | areaRead(&Pico.video, 1, sizeof(Pico.video), file);\r |
728 | }\r |
729 | areaClose(file);\r |
730 | }\r |
731 | \r |
732 | emu_forced_frame();\r |
733 | gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);\r |
734 | menu_prepare_bg();\r |
735 | \r |
736 | memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r |
737 | memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));\r |
738 | memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));\r |
739 | memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));\r |
740 | free(tmp_vram);\r |
741 | }\r |
742 | \r |
743 | static void draw_savestate_menu(int menu_sel, int is_loading)\r |
744 | {\r |
745 | int tl_x = 25, tl_y = 60, y, i;\r |
746 | \r |
747 | if (state_slot_flags & (1 << menu_sel))\r |
748 | draw_savestate_bg(menu_sel);\r |
749 | gp2x_pd_clone_buffer2();\r |
750 | \r |
751 | gp2x_text_out8(tl_x, 30, is_loading ? "Load state" : "Save state");\r |
752 | \r |
753 | /* draw all 10 slots */\r |
754 | y = tl_y;\r |
755 | for (i = 0; i < 10; i++, y+=10)\r |
756 | {\r |
757 | gp2x_text_out8(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r |
758 | }\r |
759 | gp2x_text_out8(tl_x, y, "back");\r |
760 | \r |
761 | // draw cursor\r |
762 | gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r |
763 | \r |
764 | gp2x_video_flip2();\r |
765 | }\r |
766 | \r |
767 | static int savestate_menu_loop(int is_loading)\r |
768 | {\r |
aae35e84 |
769 | static int menu_sel = 10;\r |
770 | int menu_sel_max = 10;\r |
860c6322 |
771 | unsigned long inp = 0;\r |
772 | \r |
773 | state_check_slots();\r |
774 | \r |
775 | for(;;)\r |
776 | {\r |
777 | draw_savestate_menu(menu_sel, is_loading);\r |
778 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);\r |
779 | if(inp & GP2X_UP ) {\r |
780 | do {\r |
781 | menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;\r |
782 | } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r |
783 | }\r |
784 | if(inp & GP2X_DOWN) {\r |
785 | do {\r |
786 | menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;\r |
787 | } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r |
788 | }\r |
789 | if(inp & GP2X_B) { // save/load\r |
790 | if (menu_sel < 10) {\r |
791 | state_slot = menu_sel;\r |
792 | if (emu_SaveLoadGame(is_loading, 0)) {\r |
793 | strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");\r |
794 | return 1;\r |
795 | }\r |
796 | return 0;\r |
797 | } else return 1;\r |
798 | }\r |
799 | if(inp & GP2X_X) return 1;\r |
800 | }\r |
801 | }\r |
802 | \r |
cc68a136 |
803 | // -------------- key config --------------\r |
804 | \r |
805 | static char *usb_joy_key_name(int joy, int num)\r |
806 | {\r |
807 | static char name[16];\r |
808 | switch (num)\r |
809 | {\r |
810 | case 0: sprintf(name, "Joy%i UP", joy); break;\r |
811 | case 1: sprintf(name, "Joy%i DOWN", joy); break;\r |
812 | case 2: sprintf(name, "Joy%i LEFT", joy); break;\r |
813 | case 3: sprintf(name, "Joy%i RIGHT", joy); break;\r |
814 | default:sprintf(name, "Joy%i b%i", joy, num-3); break;\r |
815 | }\r |
816 | return name;\r |
817 | }\r |
818 | \r |
d524c827 |
819 | static char *action_binds(int player_idx, int action_mask)\r |
cc68a136 |
820 | {\r |
d524c827 |
821 | static char strkeys[32*5];\r |
cc68a136 |
822 | int joy, i;\r |
823 | \r |
824 | strkeys[0] = 0;\r |
d524c827 |
825 | for (i = 0; i < 32; i++) // i is key index\r |
cc68a136 |
826 | {\r |
d524c827 |
827 | if (currentConfig.KeyBinds[i] & action_mask)\r |
cc68a136 |
828 | {\r |
d524c827 |
829 | if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;\r |
cc68a136 |
830 | if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }\r |
831 | else strcpy(strkeys, gp2xKeyNames[i]);\r |
832 | }\r |
833 | }\r |
834 | for (joy = 0; joy < num_of_joys; joy++)\r |
835 | {\r |
836 | for (i = 0; i < 32; i++)\r |
837 | {\r |
d524c827 |
838 | if (currentConfig.JoyBinds[joy][i] & action_mask)\r |
cc68a136 |
839 | {\r |
d524c827 |
840 | if (player_idx >= 0 && ((currentConfig.JoyBinds[joy][i] >> 16) & 3) != player_idx) continue;\r |
cc68a136 |
841 | if (strkeys[0]) {\r |
842 | strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));\r |
843 | break;\r |
844 | }\r |
845 | else strcpy(strkeys, usb_joy_key_name(joy + 1, i));\r |
846 | }\r |
847 | }\r |
848 | }\r |
849 | \r |
d524c827 |
850 | return strkeys;\r |
851 | }\r |
852 | \r |
853 | static void unbind_action(int action)\r |
854 | {\r |
855 | int i, u;\r |
856 | \r |
857 | for (i = 0; i < 32; i++)\r |
858 | currentConfig.KeyBinds[i] &= ~action;\r |
859 | for (u = 0; u < 4; u++)\r |
860 | for (i = 0; i < 32; i++)\r |
861 | currentConfig.JoyBinds[u][i] &= ~action;\r |
862 | }\r |
863 | \r |
864 | static int count_bound_keys(int action, int joy)\r |
865 | {\r |
866 | int i, keys = 0;\r |
867 | \r |
868 | if (joy)\r |
869 | {\r |
870 | for (i = 0; i < 32; i++)\r |
871 | if (currentConfig.JoyBinds[joy-1][i] & action) keys++;\r |
872 | }\r |
873 | else\r |
874 | {\r |
875 | for (i = 0; i < 32; i++)\r |
876 | if (currentConfig.KeyBinds[i] & action) keys++;\r |
877 | }\r |
878 | return keys;\r |
879 | }\r |
880 | \r |
881 | typedef struct { char *name; int mask; } bind_action_t;\r |
882 | \r |
883 | static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel)\r |
884 | {\r |
885 | int x, y, tl_y = 40, i;\r |
886 | \r |
e11c5548 |
887 | gp2x_pd_clone_buffer2();\r |
d524c827 |
888 | if (player_idx >= 0) {\r |
889 | gp2x_text_out8(80, 20, "Player %i controls", player_idx + 1);\r |
890 | x = 100;\r |
891 | } else {\r |
892 | gp2x_text_out8(80, 20, "Emulator controls");\r |
893 | x = 40;\r |
894 | }\r |
895 | \r |
896 | y = tl_y;\r |
897 | for (i = 0; i < opt_cnt; i++, y+=10)\r |
898 | gp2x_text_out8(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));\r |
899 | \r |
900 | gp2x_text_out8(x, y, "Done");\r |
cc68a136 |
901 | \r |
d524c827 |
902 | // draw cursor\r |
903 | gp2x_text_out8(x - 16, tl_y + sel*10, ">");\r |
904 | \r |
905 | if (sel < opt_cnt) {\r |
906 | gp2x_text_out8(30, 190, "Press a button to bind/unbind");\r |
907 | gp2x_text_out8(30, 200, "Use SELECT to clear");\r |
908 | gp2x_text_out8(30, 210, "To bind UP/DOWN, hold SELECT");\r |
909 | gp2x_text_out8(30, 220, "Select \"Done\" to exit");\r |
910 | } else {\r |
911 | gp2x_text_out8(30, 200, "Use Options -> Save cfg");\r |
912 | gp2x_text_out8(30, 210, "to save controls");\r |
913 | gp2x_text_out8(30, 220, "Press B or X to exit");\r |
914 | }\r |
e11c5548 |
915 | gp2x_video_flip2();\r |
cc68a136 |
916 | }\r |
917 | \r |
d524c827 |
918 | static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)\r |
cc68a136 |
919 | {\r |
d524c827 |
920 | int joy = 0, sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;\r |
cc68a136 |
921 | unsigned long inp = 0;\r |
922 | \r |
923 | for (;;)\r |
924 | {\r |
d524c827 |
925 | draw_key_config(opts, opt_cnt, player_idx, sel);\r |
cc68a136 |
926 | inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);\r |
927 | // printf("got %08lX from joy %i\n", inp, joy);\r |
928 | if (joy == 0) {\r |
d524c827 |
929 | if (!(inp & GP2X_SELECT)) {\r |
930 | prev_select = 0;\r |
931 | if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }\r |
932 | if(inp & GP2X_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }\r |
cc68a136 |
933 | }\r |
d524c827 |
934 | if (sel >= opt_cnt) {\r |
935 | if (inp & (GP2X_B|GP2X_X)) break;\r |
936 | else continue;\r |
937 | }\r |
938 | // if we are here, we want to bind/unbind something\r |
939 | if ((inp & GP2X_SELECT) && !prev_select)\r |
940 | unbind_action(opts[sel].mask);\r |
941 | prev_select = inp & GP2X_SELECT;\r |
cc68a136 |
942 | inp &= CONFIGURABLE_KEYS;\r |
943 | inp &= ~GP2X_SELECT;\r |
cc68a136 |
944 | for (i = 0; i < 32; i++)\r |
945 | if (inp & (1 << i)) {\r |
d524c827 |
946 | if (count_bound_keys(opts[sel].mask, 0) >= 2)\r |
947 | currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only\r |
948 | else currentConfig.KeyBinds[i] ^= opts[sel].mask;\r |
949 | if (player_idx >= 0) {\r |
950 | currentConfig.KeyBinds[i] &= ~(3 << 16);\r |
951 | currentConfig.KeyBinds[i] |= player_idx << 16;\r |
952 | }\r |
cc68a136 |
953 | }\r |
d524c827 |
954 | }\r |
955 | else if (sel < opt_cnt)\r |
956 | {\r |
cc68a136 |
957 | for (i = 0; i < 32; i++)\r |
958 | if (inp & (1 << i)) {\r |
d524c827 |
959 | if (count_bound_keys(opts[sel].mask, joy) >= 1) // disallow combos for usbjoy\r |
960 | currentConfig.JoyBinds[joy-1][i] &= ~opts[sel].mask;\r |
961 | else currentConfig.JoyBinds[joy-1][i] ^= opts[sel].mask;\r |
962 | if (player_idx >= 0) {\r |
963 | currentConfig.JoyBinds[joy-1][i] &= ~(3 << 16);\r |
964 | currentConfig.JoyBinds[joy-1][i] |= player_idx << 16;\r |
965 | }\r |
cc68a136 |
966 | }\r |
967 | }\r |
968 | }\r |
969 | }\r |
970 | \r |
971 | static void draw_kc_sel(int menu_sel)\r |
972 | {\r |
973 | int tl_x = 25+40, tl_y = 60, y, i;\r |
974 | char joyname[36];\r |
975 | \r |
976 | y = tl_y;\r |
e11c5548 |
977 | gp2x_pd_clone_buffer2();\r |
cc68a136 |
978 | gp2x_text_out8(tl_x, y, "Player 1");\r |
979 | gp2x_text_out8(tl_x, (y+=10), "Player 2");\r |
d524c827 |
980 | gp2x_text_out8(tl_x, (y+=10), "Emulator controls");\r |
cc68a136 |
981 | gp2x_text_out8(tl_x, (y+=10), "Done");\r |
982 | \r |
983 | // draw cursor\r |
984 | gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r |
985 | \r |
986 | tl_x = 25;\r |
987 | gp2x_text_out8(tl_x, (y=110), "USB joys detected:");\r |
988 | if (num_of_joys > 0) {\r |
989 | for (i = 0; i < num_of_joys; i++) {\r |
990 | strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;\r |
991 | gp2x_text_out8(tl_x, (y+=10), "%i: %s", i+1, joyname);\r |
992 | }\r |
993 | } else {\r |
994 | gp2x_text_out8(tl_x, (y+=10), "none");\r |
995 | }\r |
996 | \r |
e11c5548 |
997 | gp2x_video_flip2();\r |
cc68a136 |
998 | }\r |
999 | \r |
d524c827 |
1000 | \r |
1001 | // PicoPad[] format: MXYZ SACB RLDU\r |
1002 | static bind_action_t ctrl_actions[] =\r |
1003 | {\r |
1004 | { "UP ", 0x001 },\r |
1005 | { "DOWN ", 0x002 },\r |
1006 | { "LEFT ", 0x004 },\r |
1007 | { "RIGHT ", 0x008 },\r |
1008 | { "A ", 0x040 },\r |
1009 | { "B ", 0x010 },\r |
1010 | { "C ", 0x020 },\r |
1011 | { "START ", 0x080 },\r |
1012 | { "MODE ", 0x800 },\r |
1013 | { "X ", 0x400 },\r |
1014 | { "Y ", 0x200 },\r |
1015 | { "Z ", 0x100 },\r |
1016 | };\r |
1017 | \r |
1018 | // player2_flag, ?, ?, ?, ?, ?, ?, menu\r |
1019 | // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",\r |
1020 | // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r |
1021 | static bind_action_t emuctrl_actions[] =\r |
1022 | {\r |
1023 | { "Volume Down ", 1<<30 },\r |
1024 | { "Volume Up ", 1<<29 },\r |
1025 | { "Load State ", 1<<28 },\r |
1026 | { "Save State ", 1<<27 },\r |
1027 | { "Switch Renderer", 1<<26 },\r |
1028 | { "Prev Save Slot ", 1<<25 },\r |
1029 | { "Next Save Slot ", 1<<24 },\r |
1030 | { "Enter Menu ", 1<<23 },\r |
1031 | };\r |
1032 | \r |
cc68a136 |
1033 | static void kc_sel_loop(void)\r |
1034 | {\r |
d524c827 |
1035 | int menu_sel = 3, menu_sel_max = 3;\r |
cc68a136 |
1036 | unsigned long inp = 0;\r |
d524c827 |
1037 | int is_6button = currentConfig.PicoOpt & 0x020;\r |
cc68a136 |
1038 | \r |
d524c827 |
1039 | while (1)\r |
cc68a136 |
1040 | {\r |
1041 | draw_kc_sel(menu_sel);\r |
1042 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);\r |
d524c827 |
1043 | if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
1044 | if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
1045 | if (inp & GP2X_B) {\r |
cc68a136 |
1046 | switch (menu_sel) {\r |
d524c827 |
1047 | case 0: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 0); return;\r |
1048 | case 1: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 1); return;\r |
1049 | case 2: key_config_loop(emuctrl_actions,\r |
1050 | sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return;\r |
1051 | case 3: if (rom_data == NULL) emu_WriteConfig(0); return;\r |
cc68a136 |
1052 | default: return;\r |
1053 | }\r |
1054 | }\r |
d524c827 |
1055 | if (inp & GP2X_X) return;\r |
cc68a136 |
1056 | }\r |
1057 | }\r |
1058 | \r |
1059 | \r |
bf098bc5 |
1060 | // --------- sega/mega cd options ----------\r |
1061 | \r |
4e8a534c |
1062 | menu_entry cdopt_entries[] =\r |
bf098bc5 |
1063 | {\r |
4e8a534c |
1064 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 },\r |
1065 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 },\r |
1066 | { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 },\r |
1067 | { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1 },\r |
1068 | { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, ¤tConfig.PicoOpt, 0x0800, 0, 0, 1 },\r |
1069 | { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, ¤tConfig.PicoOpt, 0x0400, 0, 0, 1 },\r |
1070 | { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1 },\r |
1071 | { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, ¤tConfig.PicoOpt, 0x8000, 0, 0, 1 },\r |
1072 | { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,¤tConfig.PicoOpt, 0x1000, 0, 0, 1 },\r |
1073 | { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, ¤tConfig.PicoOpt, 0x2000, 0, 0, 1 },\r |
1074 | { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1 },\r |
1075 | };\r |
1076 | \r |
1077 | #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))\r |
1078 | \r |
1079 | \r |
1080 | struct bios_names_t\r |
1081 | {\r |
1082 | char us[32], eu[32], jp[32];\r |
1083 | };\r |
1084 | \r |
1085 | static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)\r |
1086 | {\r |
1087 | struct bios_names_t *bios_names = param;\r |
1088 | char ra_buff[16];\r |
1089 | \r |
1090 | switch (entry->id)\r |
1091 | {\r |
1092 | case MA_CDOPT_TESTBIOS_USA: gp2x_text_out8(x, y, "USA BIOS: %s", bios_names->us); break;\r |
1093 | case MA_CDOPT_TESTBIOS_EUR: gp2x_text_out8(x, y, "EUR BIOS: %s", bios_names->eu); break;\r |
1094 | case MA_CDOPT_TESTBIOS_JAP: gp2x_text_out8(x, y, "JAP BIOS: %s", bios_names->jp); break;\r |
1095 | case MA_CDOPT_READAHEAD:\r |
1096 | if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r |
1097 | else strcpy(ra_buff, " OFF");\r |
1098 | gp2x_text_out8(x, y, "ReadAhead buffer %s", ra_buff);\r |
1099 | break;\r |
1100 | default:break;\r |
1101 | }\r |
1102 | }\r |
1103 | \r |
1104 | static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)\r |
1105 | {\r |
1106 | int tl_x = 25, tl_y = 60;\r |
1107 | menu_id selected_id;\r |
0a051f55 |
1108 | char ra_buff[16];\r |
1109 | \r |
1110 | if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r |
1111 | else strcpy(ra_buff, " OFF");\r |
bf098bc5 |
1112 | \r |
e11c5548 |
1113 | gp2x_pd_clone_buffer2();\r |
1114 | \r |
4e8a534c |
1115 | me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);\r |
bf098bc5 |
1116 | \r |
1117 | // draw cursor\r |
1118 | gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r |
1119 | \r |
4e8a534c |
1120 | selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r |
1121 | if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||\r |
1122 | (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||\r |
1123 | (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))\r |
bf098bc5 |
1124 | gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");\r |
1125 | \r |
e11c5548 |
1126 | gp2x_video_flip2();\r |
bf098bc5 |
1127 | }\r |
1128 | \r |
1129 | static void cd_menu_loop_options(void)\r |
1130 | {\r |
aae35e84 |
1131 | static int menu_sel = 0;\r |
1132 | int menu_sel_max = 10;\r |
bf098bc5 |
1133 | unsigned long inp = 0;\r |
4e8a534c |
1134 | struct bios_names_t bios_names;\r |
1135 | menu_id selected_id;\r |
1136 | char *bios, *p;\r |
bf098bc5 |
1137 | \r |
1138 | if (find_bios(4, &bios)) { // US\r |
1139 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r |
4e8a534c |
1140 | strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;\r |
1141 | } else strcpy(bios_names.us, "NOT FOUND");\r |
bf098bc5 |
1142 | \r |
1143 | if (find_bios(8, &bios)) { // EU\r |
1144 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r |
4e8a534c |
1145 | strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;\r |
1146 | } else strcpy(bios_names.eu, "NOT FOUND");\r |
bf098bc5 |
1147 | \r |
1148 | if (find_bios(1, &bios)) { // JP\r |
1149 | for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r |
4e8a534c |
1150 | strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;\r |
1151 | } else strcpy(bios_names.jp, "NOT FOUND");\r |
bf098bc5 |
1152 | \r |
1153 | for(;;)\r |
1154 | {\r |
4e8a534c |
1155 | draw_cd_menu_options(menu_sel, &bios_names);\r |
bf098bc5 |
1156 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);\r |
4e8a534c |
1157 | if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
1158 | if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
1159 | selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r |
1160 | if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r |
1161 | if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&\r |
1162 | selected_id == MA_CDOPT_READAHEAD) {\r |
1163 | if (inp & GP2X_LEFT) {\r |
1164 | PicoCDBuffers >>= 1;\r |
1165 | if (PicoCDBuffers < 64) PicoCDBuffers = 0;\r |
1166 | } else {\r |
1167 | if (PicoCDBuffers < 64) PicoCDBuffers = 64;\r |
1168 | else PicoCDBuffers <<= 1;\r |
1169 | if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M\r |
1170 | }\r |
bf098bc5 |
1171 | }\r |
1172 | }\r |
4e8a534c |
1173 | if (inp & GP2X_B) { // toggleable options\r |
1174 | if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&\r |
1175 | selected_id == MA_CDOPT_DONE) {\r |
1176 | return;\r |
1177 | }\r |
1178 | }\r |
1179 | if (inp & GP2X_START) { // BIOS testers\r |
1180 | switch (selected_id) {\r |
1181 | case MA_CDOPT_TESTBIOS_USA:\r |
1182 | if (find_bios(4, &bios)) { // test US\r |
bf098bc5 |
1183 | strcpy(romFileName, bios);\r |
1184 | engineState = PGS_ReloadRom;\r |
1185 | return;\r |
1186 | }\r |
1187 | break;\r |
4e8a534c |
1188 | case MA_CDOPT_TESTBIOS_EUR:\r |
1189 | if (find_bios(8, &bios)) { // test EU\r |
bf098bc5 |
1190 | strcpy(romFileName, bios);\r |
1191 | engineState = PGS_ReloadRom;\r |
1192 | return;\r |
1193 | }\r |
1194 | break;\r |
4e8a534c |
1195 | case MA_CDOPT_TESTBIOS_JAP:\r |
1196 | if (find_bios(1, &bios)) { // test JP\r |
bf098bc5 |
1197 | strcpy(romFileName, bios);\r |
1198 | engineState = PGS_ReloadRom;\r |
1199 | return;\r |
1200 | }\r |
1201 | break;\r |
4e8a534c |
1202 | default:\r |
1203 | break;\r |
bf098bc5 |
1204 | }\r |
1205 | }\r |
4e8a534c |
1206 | if (inp & (GP2X_X|GP2X_A)) return;\r |
bf098bc5 |
1207 | }\r |
1208 | }\r |
1209 | \r |
1210 | \r |
1211 | // --------- advanced options ----------\r |
1212 | \r |
4e8a534c |
1213 | menu_entry opt2_entries[] =\r |
1214 | {\r |
1215 | { NULL, MB_NONE, MA_OPT2_GAMMA, NULL, 0, 0, 0, 1 },\r |
1216 | { "A_SN's gamma curve", MB_ONOFF, MA_OPT2_A_SN_GAMMA, ¤tConfig.EmuOpt, 0x1000, 0, 0, 1 },\r |
1217 | { "Perfecf vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 },\r |
1218 | { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 },\r |
1219 | { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 },\r |
1220 | { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 },\r |
1221 | { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 },\r |
1222 | { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 },\r |
1223 | { "needs restart:", MB_NONE, MA_NONE, NULL, 0, 0, 0, 1 },\r |
1224 | { "craigix's RAM timings", MB_ONOFF, MA_OPT2_RAMTIMINGS, ¤tConfig.EmuOpt, 0x0100, 0, 0, 1 },\r |
1225 | { NULL, MB_ONOFF, MA_OPT2_SQUIDGEHACK, ¤tConfig.EmuOpt, 0x0010, 0, 0, 1 },\r |
1226 | { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 },\r |
1227 | };\r |
1228 | \r |
1229 | #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))\r |
1230 | \r |
1231 | static void menu_opt2_cust_draw(const menu_entry *entry, int x, int y, void *param)\r |
1232 | {\r |
1233 | if (entry->id == MA_OPT2_GAMMA)\r |
1234 | gp2x_text_out8(x, y, "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);\r |
1235 | else if (entry->id == MA_OPT2_SQUIDGEHACK)\r |
1236 | gp2x_text_out8(x, y, "squidgehack (now %s %s", mmuhack_status ? "active) " : "inactive)",\r |
1237 | (currentConfig.EmuOpt&0x0010)?"ON":"OFF");\r |
1238 | }\r |
1239 | \r |
1240 | \r |
cc68a136 |
1241 | static void draw_amenu_options(int menu_sel)\r |
1242 | {\r |
4e8a534c |
1243 | int tl_x = 25, tl_y = 50;\r |
cc68a136 |
1244 | \r |
e11c5548 |
1245 | gp2x_pd_clone_buffer2();\r |
1246 | \r |
4e8a534c |
1247 | me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL);\r |
cc68a136 |
1248 | \r |
1249 | // draw cursor\r |
1250 | gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r |
1251 | \r |
e11c5548 |
1252 | gp2x_video_flip2();\r |
cc68a136 |
1253 | }\r |
1254 | \r |
1255 | static void amenu_loop_options(void)\r |
1256 | {\r |
aae35e84 |
1257 | static int menu_sel = 0;\r |
4e8a534c |
1258 | int menu_sel_max;\r |
cc68a136 |
1259 | unsigned long inp = 0;\r |
4e8a534c |
1260 | menu_id selected_id;\r |
1261 | \r |
1262 | menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;\r |
cc68a136 |
1263 | \r |
1264 | for(;;)\r |
1265 | {\r |
1266 | draw_amenu_options(menu_sel);\r |
1267 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r |
4e8a534c |
1268 | if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
1269 | if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
1270 | selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);\r |
1271 | if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r |
1272 | if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&\r |
1273 | selected_id == MA_OPT2_GAMMA) {\r |
1274 | while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r |
1275 | currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;\r |
1276 | if (currentConfig.gamma < 1) currentConfig.gamma = 1;\r |
1277 | if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r |
1278 | draw_amenu_options(menu_sel);\r |
1279 | usleep(18*1000);\r |
1280 | }\r |
cc68a136 |
1281 | }\r |
1282 | }\r |
4e8a534c |
1283 | if (inp & GP2X_B) { // toggleable options\r |
1284 | if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&\r |
1285 | selected_id == MA_OPT2_DONE) {\r |
1286 | return;\r |
cc68a136 |
1287 | }\r |
1288 | }\r |
4e8a534c |
1289 | if (inp & (GP2X_X|GP2X_A)) return;\r |
cc68a136 |
1290 | }\r |
1291 | }\r |
1292 | \r |
1293 | // -------------- options --------------\r |
1294 | \r |
4e8a534c |
1295 | \r |
1296 | menu_entry opt_entries[] =\r |
1297 | {\r |
1298 | { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1 },\r |
1299 | { NULL, MB_RANGE, MA_OPT_SCALING, ¤tConfig.scaling, 0, 0, 3, 1 },\r |
1300 | { "Accurate timing (slower)", MB_ONOFF, MA_OPT_ACC_TIMING, ¤tConfig.PicoOpt, 0x040, 0, 0, 1 },\r |
1301 | { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES, ¤tConfig.PicoOpt, 0x080, 0, 0, 1 },\r |
1302 | { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x002, 0, 0, 1 },\r |
1303 | { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1 },\r |
1304 | { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x004, 0, 0, 1 },\r |
1305 | { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 },\r |
1306 | { "Use ARM940 core for sound", MB_ONOFF, MA_OPT_ARM940_SOUND, ¤tConfig.PicoOpt, 0x200, 0, 0, 1 },\r |
1307 | { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, ¤tConfig.PicoOpt, 0x020, 0, 0, 1 },\r |
1308 | { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1 },\r |
1309 | { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x001, 0, 0, 1 },\r |
1310 | { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 },\r |
1311 | { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1 },\r |
1312 | { NULL, MB_NONE, MA_OPT_CPU_CLOCKS, NULL, 0, 0, 0, 1 },\r |
1313 | { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1 },\r |
1314 | { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1 },\r |
1315 | { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1 },\r |
1316 | { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 },\r |
1317 | { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1 },\r |
1318 | };\r |
1319 | \r |
1320 | #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))\r |
1321 | \r |
1322 | \r |
51a902ae |
1323 | static const char *region_name(unsigned int code)\r |
cc68a136 |
1324 | {\r |
51a902ae |
1325 | static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };\r |
1326 | static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r |
1327 | int u, i = 0;\r |
1328 | if (code) {\r |
1329 | code <<= 1;\r |
1330 | while((code >>= 1)) i++;\r |
1331 | if (i > 4) return "unknown";\r |
1332 | return names[i];\r |
1333 | } else {\r |
1334 | static char name[24];\r |
1335 | strcpy(name, "Auto:");\r |
1336 | for (u = 0; u < 3; u++) {\r |
1337 | i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;\r |
1338 | while((code >>= 1)) i++;\r |
1339 | strcat(name, names_short[i]);\r |
1340 | }\r |
1341 | return name;\r |
1342 | }\r |
cc68a136 |
1343 | }\r |
1344 | \r |
4e8a534c |
1345 | \r |
1346 | static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)\r |
cc68a136 |
1347 | {\r |
4e8a534c |
1348 | char *str, str24[24];\r |
1349 | \r |
1350 | switch (entry->id)\r |
1351 | {\r |
1352 | case MA_OPT_RENDERER:\r |
1353 | if (currentConfig.PicoOpt&0x10)\r |
1354 | str = " 8bit fast";\r |
1355 | else if (currentConfig.EmuOpt&0x80)\r |
1356 | str = "16bit accurate";\r |
1357 | else\r |
1358 | str = " 8bit accurate";\r |
1359 | gp2x_text_out8(x, y, "Renderer: %s", str);\r |
1360 | break;\r |
1361 | case MA_OPT_SCALING:\r |
1362 | switch (currentConfig.scaling) {\r |
1363 | default: str = " OFF"; break;\r |
1364 | case 1: str = "hw horizontal"; break;\r |
1365 | case 2: str = "hw horiz. + vert."; break;\r |
1366 | case 3: str = "sw horizontal"; break;\r |
1367 | }\r |
1368 | gp2x_text_out8(x, y, "Scaling: %s", str);\r |
1369 | break;\r |
1370 | case MA_OPT_FRAMESKIP:\r |
1371 | if (currentConfig.Frameskip < 0)\r |
1372 | strcpy(str24, "Auto");\r |
1373 | else sprintf(str24, "%i", currentConfig.Frameskip);\r |
1374 | gp2x_text_out8(x, y, "Frameskip %s", str24);\r |
1375 | break;\r |
1376 | case MA_OPT_SOUND_QUALITY:\r |
1377 | str = (currentConfig.PicoOpt&0x08)?"stereo":"mono";\r |
1378 | gp2x_text_out8(x, y, "Sound Quality: %5iHz %s", currentConfig.PsndRate, str);\r |
1379 | break;\r |
1380 | case MA_OPT_REGION:\r |
1381 | gp2x_text_out8(x, y, "Region: %s", region_name(currentConfig.PicoRegion));\r |
1382 | break;\r |
1383 | case MA_OPT_CONFIRM_STATES:\r |
1384 | switch ((currentConfig.EmuOpt >> 9) & 5) {\r |
1385 | default: str = "OFF"; break;\r |
1386 | case 1: str = "writes"; break;\r |
1387 | case 4: str = "loads"; break;\r |
1388 | case 5: str = "both"; break;\r |
1389 | }\r |
1390 | gp2x_text_out8(x, y, "Confirm savestate %s", str);\r |
1391 | break;\r |
1392 | case MA_OPT_CPU_CLOCKS:\r |
1393 | gp2x_text_out8(x, y, "GP2X CPU clocks %iMhz", currentConfig.CPUclock);\r |
1394 | break;\r |
1395 | case MA_OPT_SAVECFG:\r |
1396 | str24[0] = 0;\r |
1397 | if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);\r |
1398 | gp2x_text_out8(x, y, "Save cfg as default%s", str24);\r |
1399 | break;\r |
1400 | case MA_OPT_LOADCFG:\r |
1401 | gp2x_text_out8(x, y, "Load cfg from profile %i", config_slot);\r |
1402 | break;\r |
1403 | default:\r |
1404 | printf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);\r |
1405 | break;\r |
46969540 |
1406 | }\r |
4e8a534c |
1407 | }\r |
1408 | \r |
1409 | \r |
1410 | \r |
1411 | static void draw_menu_options(int menu_sel)\r |
1412 | {\r |
1413 | int tl_x = 25, tl_y = 32;\r |
cc68a136 |
1414 | \r |
e11c5548 |
1415 | gp2x_pd_clone_buffer2();\r |
1416 | \r |
4e8a534c |
1417 | me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);\r |
cc68a136 |
1418 | \r |
1419 | // draw cursor\r |
1420 | gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r |
1421 | \r |
e11c5548 |
1422 | gp2x_video_flip2();\r |
cc68a136 |
1423 | }\r |
1424 | \r |
1425 | static int sndrate_prevnext(int rate, int dir)\r |
1426 | {\r |
1427 | int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };\r |
1428 | \r |
1429 | for (i = 0; i < 5; i++)\r |
1430 | if (rates[i] == rate) break;\r |
1431 | \r |
1432 | i += dir ? 1 : -1;\r |
1433 | if (i > 4) return dir ? 44100 : 22050;\r |
1434 | if (i < 0) return dir ? 11025 : 8000;\r |
1435 | return rates[i];\r |
1436 | }\r |
1437 | \r |
51a902ae |
1438 | static void region_prevnext(int right)\r |
1439 | {\r |
1440 | // jp_ntsc=1, jp_pal=2, usa=4, eu=8\r |
1441 | static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r |
1442 | int i;\r |
1443 | if (right) {\r |
1444 | if (!currentConfig.PicoRegion) {\r |
1445 | for (i = 0; i < 6; i++)\r |
1446 | if (rgn_orders[i] == PicoAutoRgnOrder) break;\r |
1447 | if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];\r |
1448 | else currentConfig.PicoRegion=1;\r |
1449 | }\r |
1450 | else currentConfig.PicoRegion<<=1;\r |
1451 | if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;\r |
1452 | } else {\r |
1453 | if (!currentConfig.PicoRegion) {\r |
1454 | for (i = 0; i < 6; i++)\r |
1455 | if (rgn_orders[i] == PicoAutoRgnOrder) break;\r |
1456 | if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];\r |
1457 | }\r |
1458 | else currentConfig.PicoRegion>>=1;\r |
1459 | }\r |
1460 | }\r |
1461 | \r |
cc68a136 |
1462 | static void menu_options_save(void)\r |
1463 | {\r |
cc68a136 |
1464 | PicoOpt = currentConfig.PicoOpt;\r |
1465 | PsndRate = currentConfig.PsndRate;\r |
1466 | PicoRegionOverride = currentConfig.PicoRegion;\r |
d524c827 |
1467 | if (!(PicoOpt & 0x20)) {\r |
1468 | // unbind XYZ MODE, just in case\r |
1469 | unbind_action(0xf00);\r |
cc68a136 |
1470 | }\r |
2433f409 |
1471 | scaling_update();\r |
cc68a136 |
1472 | }\r |
1473 | \r |
bf098bc5 |
1474 | static int menu_loop_options(void)\r |
cc68a136 |
1475 | {\r |
aae35e84 |
1476 | static int menu_sel = 0;\r |
4e8a534c |
1477 | int menu_sel_max, ret;\r |
cc68a136 |
1478 | unsigned long inp = 0;\r |
4e8a534c |
1479 | menu_id selected_id;\r |
cc68a136 |
1480 | \r |
51a902ae |
1481 | currentConfig.PicoOpt = PicoOpt;\r |
1482 | currentConfig.PsndRate = PsndRate;\r |
1483 | currentConfig.PicoRegion = PicoRegionOverride;\r |
cc68a136 |
1484 | \r |
4e8a534c |
1485 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL);\r |
1486 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r |
1487 | menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;\r |
d524c827 |
1488 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r |
4e8a534c |
1489 | \r |
1490 | while (1)\r |
cc68a136 |
1491 | {\r |
1492 | draw_menu_options(menu_sel);\r |
1493 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r |
4e8a534c |
1494 | if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
1495 | if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
1496 | selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);\r |
1497 | if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r |
1498 | if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0)) {\r |
1499 | switch (selected_id) {\r |
1500 | case MA_OPT_RENDERER:\r |
1501 | if (inp & GP2X_LEFT) {\r |
1502 | if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r |
1503 | else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;\r |
1504 | else if ( currentConfig.EmuOpt &0x80) break;\r |
1505 | } else {\r |
1506 | if ( currentConfig.PicoOpt&0x10) break;\r |
1507 | else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;\r |
1508 | else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r |
1509 | }\r |
1510 | break;\r |
1511 | case MA_OPT_SOUND_QUALITY:\r |
1512 | if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r |
1513 | currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;\r |
1514 | } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r |
1515 | currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r |
1516 | } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);\r |
1517 | break;\r |
1518 | case MA_OPT_REGION:\r |
1519 | region_prevnext(inp & GP2X_RIGHT);\r |
1520 | break;\r |
1521 | case MA_OPT_CONFIRM_STATES: {\r |
1522 | int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);\r |
1523 | n += (inp & GP2X_LEFT) ? -1 : 1;\r |
1524 | if (n < 0) n = 0; else if (n > 3) n = 3;\r |
1525 | n |= n << 1; n &= ~2;\r |
1526 | currentConfig.EmuOpt &= ~0xa00;\r |
1527 | currentConfig.EmuOpt |= n << 9;\r |
1528 | break;\r |
1529 | }\r |
1530 | case MA_OPT_SAVE_SLOT:\r |
1531 | if (inp & GP2X_RIGHT) {\r |
1532 | state_slot++; if (state_slot > 9) state_slot = 0;\r |
1533 | } else {state_slot--; if (state_slot < 0) state_slot = 9;\r |
1534 | }\r |
1535 | break;\r |
1536 | case MA_OPT_CPU_CLOCKS:\r |
1537 | while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r |
1538 | currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r |
1539 | if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;\r |
1540 | draw_menu_options(menu_sel);\r |
1541 | usleep(50*1000);\r |
1542 | }\r |
1543 | break;\r |
1544 | case MA_OPT_SAVECFG:\r |
1545 | case MA_OPT_SAVECFG_GAME:\r |
1546 | case MA_OPT_LOADCFG:\r |
1547 | config_slot += (inp&GP2X_RIGHT) ? 1 : -1;\r |
1548 | if (config_slot > 9) config_slot = 0;\r |
1549 | if (config_slot < 0) config_slot = 9;\r |
1550 | me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r |
1551 | menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;\r |
1552 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r |
1553 | break;\r |
1554 | default:\r |
1555 | //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);\r |
1556 | break;\r |
1557 | }\r |
1558 | }\r |
1559 | }\r |
1560 | if (inp & GP2X_B) {\r |
1561 | if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))\r |
1562 | {\r |
1563 | switch (selected_id)\r |
1564 | {\r |
1565 | case MA_OPT_SCD_OPTS:\r |
1566 | cd_menu_loop_options();\r |
1567 | if (engineState == PGS_ReloadRom)\r |
1568 | return 0; // test BIOS\r |
1569 | break;\r |
1570 | case MA_OPT_ADV_OPTS:\r |
1571 | amenu_loop_options();\r |
1572 | break;\r |
1573 | case MA_OPT_SAVECFG: // done (update and write)\r |
1574 | menu_options_save();\r |
1575 | if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r |
1576 | else strcpy(menuErrorMsg, "failed to write config");\r |
1577 | return 1;\r |
1578 | case MA_OPT_SAVECFG_GAME: // done (update and write for current game)\r |
1579 | menu_options_save();\r |
1580 | if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r |
1581 | else strcpy(menuErrorMsg, "failed to write config");\r |
1582 | return 1;\r |
1583 | case MA_OPT_LOADCFG:\r |
d524c827 |
1584 | ret = emu_ReadConfig(1, 1);\r |
1585 | if (!ret) ret = emu_ReadConfig(0, 1);\r |
1586 | if (ret) strcpy(menuErrorMsg, "config loaded");\r |
4e8a534c |
1587 | else strcpy(menuErrorMsg, "failed to load config");\r |
1588 | return 1;\r |
1589 | default:\r |
1590 | //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);\r |
1591 | break;\r |
1592 | }\r |
cc68a136 |
1593 | }\r |
1594 | }\r |
51a902ae |
1595 | if(inp & (GP2X_X|GP2X_A)) {\r |
cc68a136 |
1596 | menu_options_save();\r |
bf098bc5 |
1597 | return 0; // done (update, no write)\r |
cc68a136 |
1598 | }\r |
cc68a136 |
1599 | }\r |
1600 | }\r |
1601 | \r |
1602 | // -------------- credits --------------\r |
1603 | \r |
1604 | static void draw_menu_credits(void)\r |
1605 | {\r |
1606 | int tl_x = 15, tl_y = 70, y;\r |
e11c5548 |
1607 | //memset(gp2x_screen, 0, 320*240);\r |
1608 | gp2x_pd_clone_buffer2();\r |
cc68a136 |
1609 | \r |
672ad671 |
1610 | gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r |
cc68a136 |
1611 | y = tl_y;\r |
1612 | gp2x_text_out8(tl_x, y, "Credits:");\r |
1613 | gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r |
1614 | gp2x_text_out8(tl_x, (y+=10), " base code of PicoDrive");\r |
1615 | gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");\r |
1616 | gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");\r |
1617 | gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");\r |
1618 | gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");\r |
1619 | gp2x_text_out8(tl_x, (y+=10), " opensource Gens");\r |
1620 | gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");\r |
1621 | gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");\r |
1622 | gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");\r |
1623 | gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");\r |
1624 | gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");\r |
1625 | gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");\r |
1626 | \r |
e11c5548 |
1627 | gp2x_video_flip2();\r |
cc68a136 |
1628 | }\r |
1629 | \r |
1630 | \r |
1631 | // -------------- root menu --------------\r |
1632 | \r |
4e8a534c |
1633 | menu_entry main_entries[] =\r |
1634 | {\r |
1635 | { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 },\r |
1636 | { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 },\r |
1637 | { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 },\r |
1638 | { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 },\r |
1639 | { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 },\r |
1640 | { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 },\r |
1641 | { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 },\r |
1642 | { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 },\r |
1643 | { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 },\r |
1644 | { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 }\r |
1645 | };\r |
1646 | \r |
1647 | #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))\r |
1648 | \r |
cc68a136 |
1649 | static void draw_menu_root(int menu_sel)\r |
1650 | {\r |
4e8a534c |
1651 | const int tl_x = 70, tl_y = 70;\r |
1652 | \r |
e11c5548 |
1653 | gp2x_pd_clone_buffer2();\r |
cc68a136 |
1654 | \r |
1655 | gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);\r |
1656 | \r |
4e8a534c |
1657 | me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);\r |
cc68a136 |
1658 | \r |
1659 | // draw cursor\r |
1660 | gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r |
1661 | // error\r |
1662 | if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r |
e11c5548 |
1663 | gp2x_video_flip2();\r |
cc68a136 |
1664 | }\r |
1665 | \r |
1666 | \r |
1667 | static void menu_loop_root(void)\r |
1668 | {\r |
4e8a534c |
1669 | static int menu_sel = 0;\r |
1670 | int ret, menu_sel_max;\r |
cc68a136 |
1671 | unsigned long inp = 0;\r |
1672 | char curr_path[PATH_MAX], *selfname;\r |
1673 | FILE *tstf;\r |
1674 | \r |
1675 | if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r |
1676 | {\r |
1677 | fclose(tstf);\r |
1678 | strcpy(curr_path, currentConfig.lastRomFile);\r |
1679 | }\r |
1680 | else\r |
1681 | {\r |
1682 | getcwd(curr_path, PATH_MAX);\r |
1683 | }\r |
1684 | \r |
4e8a534c |
1685 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL);\r |
1686 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_data != NULL);\r |
1687 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_data != NULL);\r |
1688 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_data != NULL);\r |
1689 | me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL);\r |
1690 | \r |
1691 | menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;\r |
d524c827 |
1692 | if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r |
cc68a136 |
1693 | \r |
2433f409 |
1694 | /* make sure action buttons are not pressed on entering menu */\r |
1695 | draw_menu_root(menu_sel);\r |
1696 | while (gp2x_joystick_read(1) & (GP2X_B|GP2X_X|GP2X_SELECT)) usleep(50*1000);\r |
1697 | \r |
1698 | for (;;)\r |
cc68a136 |
1699 | {\r |
1700 | draw_menu_root(menu_sel);\r |
0af33fe0 |
1701 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT|GP2X_L|GP2X_R);\r |
4e8a534c |
1702 | if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
1703 | if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
0af33fe0 |
1704 | if((inp & (GP2X_L|GP2X_R)) == (GP2X_L|GP2X_R)) debug_menu_loop();\r |
cc68a136 |
1705 | if(inp &(GP2X_SELECT|GP2X_X)){\r |
1706 | if (rom_data) {\r |
1707 | while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released\r |
1708 | engineState = PGS_Running;\r |
1709 | break;\r |
1710 | }\r |
1711 | }\r |
4e8a534c |
1712 | if(inp & GP2X_B) {\r |
1713 | switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))\r |
1714 | {\r |
1715 | case MA_MAIN_RESUME_GAME:\r |
721cd396 |
1716 | if (rom_data) {\r |
1717 | while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r |
1718 | engineState = PGS_Running;\r |
1719 | return;\r |
1720 | }\r |
cc68a136 |
1721 | break;\r |
4e8a534c |
1722 | case MA_MAIN_SAVE_STATE:\r |
cc68a136 |
1723 | if (rom_data) {\r |
860c6322 |
1724 | if(savestate_menu_loop(0))\r |
cc68a136 |
1725 | continue;\r |
cc68a136 |
1726 | engineState = PGS_Running;\r |
1727 | return;\r |
1728 | }\r |
1729 | break;\r |
4e8a534c |
1730 | case MA_MAIN_LOAD_STATE:\r |
cc68a136 |
1731 | if (rom_data) {\r |
860c6322 |
1732 | if(savestate_menu_loop(1))\r |
cc68a136 |
1733 | continue;\r |
cc68a136 |
1734 | engineState = PGS_Running;\r |
1735 | return;\r |
1736 | }\r |
1737 | break;\r |
4e8a534c |
1738 | case MA_MAIN_RESET_GAME:\r |
cc68a136 |
1739 | if (rom_data) {\r |
1740 | emu_ResetGame();\r |
1741 | engineState = PGS_Running;\r |
1742 | return;\r |
1743 | }\r |
1744 | break;\r |
4e8a534c |
1745 | case MA_MAIN_LOAD_ROM:\r |
cc68a136 |
1746 | selfname = romsel_loop(curr_path);\r |
1747 | if (selfname) {\r |
1748 | printf("selected file: %s\n", selfname);\r |
cc68a136 |
1749 | engineState = PGS_ReloadRom;\r |
1750 | }\r |
1751 | return;\r |
4e8a534c |
1752 | case MA_MAIN_OPTIONS:\r |
bf098bc5 |
1753 | ret = menu_loop_options();\r |
1754 | if (ret == 1) continue; // status update\r |
1755 | if (engineState == PGS_ReloadRom)\r |
1756 | return; // BIOS test\r |
cc68a136 |
1757 | break;\r |
4e8a534c |
1758 | case MA_MAIN_CONTROLS:\r |
cc68a136 |
1759 | kc_sel_loop();\r |
1760 | break;\r |
4e8a534c |
1761 | case MA_MAIN_CREDITS:\r |
cc68a136 |
1762 | draw_menu_credits();\r |
1763 | usleep(500*1000);\r |
1764 | inp = wait_for_input(GP2X_B|GP2X_X);\r |
1765 | break;\r |
4e8a534c |
1766 | case MA_MAIN_EXIT:\r |
cc68a136 |
1767 | engineState = PGS_Quit;\r |
1768 | return;\r |
4e8a534c |
1769 | case MA_MAIN_PATCHES:\r |
b67ef287 |
1770 | if (rom_data && PicoPatches) {\r |
1771 | patches_menu_loop();\r |
1772 | PicoPatchApply();\r |
1773 | strcpy(menuErrorMsg, "Patches applied");\r |
1774 | continue;\r |
1775 | }\r |
1776 | break;\r |
4e8a534c |
1777 | default:\r |
1778 | printf("%s: something unknown selected\n", __FUNCTION__);\r |
1779 | break;\r |
cc68a136 |
1780 | }\r |
1781 | }\r |
1782 | menuErrorMsg[0] = 0; // clear error msg\r |
1783 | }\r |
1784 | }\r |
1785 | \r |
1786 | \r |
860c6322 |
1787 | static void menu_prepare_bg(void)\r |
cc68a136 |
1788 | {\r |
e11c5548 |
1789 | extern int localPal[0x100];\r |
860c6322 |
1790 | int c, i;\r |
e11c5548 |
1791 | \r |
1792 | // don't clear old palette just for fun (but make it dark)\r |
860c6322 |
1793 | for (i = 0x100-1; i >= 0; i--) {\r |
1794 | c = localPal[i];\r |
1795 | localPal[i] = ((c >> 1) & 0x007f7f7f) - ((c >> 3) & 0x001f1f1f);\r |
1796 | }\r |
e11c5548 |
1797 | localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r |
1798 | localPal[0xf0] = 0x00ffffff;\r |
cc68a136 |
1799 | \r |
860c6322 |
1800 | gp2x_video_setpalette(localPal, 0x100);\r |
1801 | }\r |
1802 | \r |
1803 | static void menu_gfx_prepare(void)\r |
1804 | {\r |
1805 | menu_prepare_bg();\r |
1806 | \r |
cc68a136 |
1807 | // switch to 8bpp\r |
e11c5548 |
1808 | gp2x_video_changemode2(8);\r |
2433f409 |
1809 | gp2x_video_RGB_setscaling(0, 320, 240);\r |
e11c5548 |
1810 | gp2x_video_flip2();\r |
1811 | }\r |
1812 | \r |
1813 | \r |
1814 | void menu_loop(void)\r |
1815 | {\r |
1816 | menu_gfx_prepare();\r |
cc68a136 |
1817 | \r |
1818 | menu_loop_root();\r |
1819 | \r |
1820 | menuErrorMsg[0] = 0;\r |
1821 | }\r |
721cd396 |
1822 | \r |
1823 | \r |
1824 | // --------- CD tray close menu ----------\r |
1825 | \r |
1826 | static void draw_menu_tray(int menu_sel)\r |
1827 | {\r |
1828 | int tl_x = 70, tl_y = 90, y;\r |
1829 | memset(gp2x_screen, 0xe0, 320*240);\r |
1830 | \r |
1831 | gp2x_text_out8(tl_x, 20, "The unit is about to");\r |
1832 | gp2x_text_out8(tl_x, 30, "close the CD tray.");\r |
1833 | \r |
1834 | y = tl_y;\r |
1835 | gp2x_text_out8(tl_x, y, "Load new CD image");\r |
1836 | gp2x_text_out8(tl_x, (y+=10), "Insert nothing");\r |
1837 | \r |
1838 | // draw cursor\r |
1839 | gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r |
1840 | // error\r |
1841 | if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r |
1842 | gp2x_video_flip2();\r |
1843 | }\r |
1844 | \r |
1845 | \r |
1846 | int menu_loop_tray(void)\r |
1847 | {\r |
1848 | int menu_sel = 0, menu_sel_max = 1;\r |
1849 | unsigned long inp = 0;\r |
1850 | char curr_path[PATH_MAX], *selfname;\r |
1851 | FILE *tstf;\r |
1852 | \r |
1853 | gp2x_memset_all_buffers(0, 0xe0, 320*240);\r |
1854 | menu_gfx_prepare();\r |
1855 | \r |
1856 | if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r |
1857 | {\r |
1858 | fclose(tstf);\r |
1859 | strcpy(curr_path, currentConfig.lastRomFile);\r |
1860 | }\r |
1861 | else\r |
1862 | {\r |
1863 | getcwd(curr_path, PATH_MAX);\r |
1864 | }\r |
1865 | \r |
1866 | /* make sure action buttons are not pressed on entering menu */\r |
1867 | draw_menu_tray(menu_sel);\r |
1868 | while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r |
1869 | \r |
1870 | for (;;)\r |
1871 | {\r |
1872 | draw_menu_tray(menu_sel);\r |
1873 | inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B);\r |
1874 | if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r |
1875 | if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r |
1876 | if(inp & GP2X_B ) {\r |
1877 | switch (menu_sel) {\r |
1878 | case 0: // select image\r |
1879 | selfname = romsel_loop(curr_path);\r |
1880 | if (selfname) {\r |
1881 | int ret = -1, cd_type;\r |
1882 | cd_type = emu_cd_check(NULL);\r |
1883 | if (cd_type > 0)\r |
1884 | ret = Insert_CD(romFileName, cd_type == 2);\r |
1885 | if (ret != 0) {\r |
1886 | sprintf(menuErrorMsg, "Load failed, invalid CD image?");\r |
1887 | printf("%s\n", menuErrorMsg);\r |
1888 | continue;\r |
1889 | }\r |
1890 | engineState = PGS_RestartRun;\r |
1891 | return 1;\r |
1892 | }\r |
1893 | break;\r |
1894 | case 1: // insert nothing\r |
1895 | engineState = PGS_RestartRun;\r |
1896 | return 0;\r |
1897 | }\r |
1898 | }\r |
1899 | menuErrorMsg[0] = 0; // clear error msg\r |
1900 | }\r |
1901 | }\r |
1902 | \r |
1903 | \r |