buggy port of gfx/cd, silpheed started working?
[libpicofe.git] / gp2x / menu.c
CommitLineData
720ee7f6 1// (c) Copyright 2006 notaz, All rights reserved.\r
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
0805b5b4 16#include "fonts.h"\r
720ee7f6 17#include "usbjoy.h"\r
18#include "version.h"\r
19\r
70d2ecc5 20#include <Pico/PicoInt.h>\r
21#include <Pico/Patch.h>\r
22#include <zlib/zlib.h>\r
720ee7f6 23\r
24#ifndef _DIRENT_HAVE_D_TYPE\r
25#error "need d_type for file browser\r
26#endif\r
27\r
28extern char *actionNames[];\r
29extern char romFileName[PATH_MAX];\r
30extern char *rom_data;\r
31extern int mmuhack_status;\r
32extern int state_slot;\r
33\r
34static char *gp2xKeyNames[] = {\r
35 "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",\r
36 "START", "SELECT", "L", "R", "A", "B", "X", "Y",\r
37 "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",\r
38 "???", "???", "???", "PUSH", "???", "???", "???", "???"\r
39};\r
40\r
41char menuErrorMsg[40] = {0, };\r
42\r
43\r
0805b5b4 44static void gp2x_text(unsigned char *screen, int x, int y, const char *text, int color)\r
720ee7f6 45{\r
46 int i,l;\r
47\r
48 screen = screen + x + y*320;\r
49\r
50 for (i = 0; i < strlen(text); i++)\r
51 {\r
52 for (l=0;l<8;l++)\r
53 {\r
54 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=color;\r
55 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=color;\r
56 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=color;\r
57 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=color;\r
58 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=color;\r
59 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=color;\r
60 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=color;\r
61 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=color;\r
62 }\r
63 screen += 8;\r
64 }\r
65}\r
66\r
67// draws white text to current bbp15 screen\r
0805b5b4 68void gp2x_text_out15(int x, int y, const char *text)\r
720ee7f6 69{\r
70 int i,l;\r
71 unsigned short *screen = gp2x_screen;\r
72\r
73 screen = screen + x + y*320;\r
74\r
75 for (i = 0; i < strlen(text); i++)\r
76 {\r
77 for (l=0;l<8;l++)\r
78 {\r
79 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;\r
80 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;\r
81 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;\r
82 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;\r
83 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;\r
84 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;\r
85 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;\r
86 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;\r
87 }\r
88 screen += 8;\r
89 }\r
90}\r
91\r
92\r
0805b5b4 93void gp2x_text_out8(int x, int y, const char *texto, ...)\r
720ee7f6 94{\r
95 va_list args;\r
96 char buffer[512];\r
97\r
98 va_start(args,texto);\r
99 vsprintf(buffer,texto,args);\r
100 va_end(args);\r
101\r
e5d315a5 102 gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r
720ee7f6 103}\r
104\r
105\r
0805b5b4 106void gp2x_text_out8_2(int x, int y, const char *texto, int color)\r
720ee7f6 107{\r
108 gp2x_text(gp2x_screen, x, y, texto, color);\r
109}\r
110\r
0805b5b4 111void gp2x_text_out8_lim(int x, int y, const char *texto, int max)\r
720ee7f6 112{\r
113 char buffer[320/8+1];\r
114\r
115 strncpy(buffer, texto, 320/8);\r
116 if (max > 320/8) max = 320/8;\r
117 if (max < 0) max = 0;\r
118 buffer[max] = 0;\r
119\r
e5d315a5 120 gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r
720ee7f6 121}\r
122\r
0805b5b4 123static void gp2x_smalltext8(int x, int y, const char *texto)\r
124{\r
125 int i;\r
126 unsigned char *src, *dst;\r
127\r
128 for (i = 0;; i++, x += 6)\r
129 {\r
130 unsigned char c = (unsigned char) texto[i];\r
131 int h = 8;\r
132\r
133 if (!c) break;\r
134\r
135 src = fontdata6x8[c];\r
136 dst = (unsigned char *)gp2x_screen + x + y*320;\r
137\r
138 while (h--)\r
139 {\r
140 int w = 0x20;\r
141 while (w)\r
142 {\r
143 if( *src & w ) *dst = 0xf0;\r
144 dst++;\r
145 w>>=1;\r
146 }\r
147 src++;\r
148\r
149 dst += 320-6;\r
150 }\r
151 }\r
152}\r
153\r
154static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)\r
155{\r
156 char buffer[320/6+1];\r
157\r
158 strncpy(buffer, texto, 320/6);\r
159 if (max > 320/6) max = 320/6;\r
160 if (max < 0) max = 0;\r
161 buffer[max] = 0;\r
162\r
163 gp2x_smalltext8(x, y, buffer);\r
164}\r
165\r
720ee7f6 166\r
167static unsigned long inp_prev = 0;\r
168static int inp_prevjoy = 0;\r
169\r
170static unsigned long wait_for_input(unsigned long interesting)\r
171{\r
172 unsigned long ret;\r
173 static int repeats = 0, wait = 300*1000;\r
174 int release = 0, i;\r
175\r
176 if (repeats == 5 || repeats == 15 || repeats == 30) wait /= 2;\r
177\r
178 for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {\r
179 if(i == 0) repeats++;\r
180 usleep(wait/6);\r
181 }\r
182\r
183 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {\r
184 usleep(50000);\r
185 release = 1;\r
186 }\r
187\r
188 if (release || ret != inp_prev) {\r
189 repeats = 0;\r
190 wait = 300*1000;\r
191 }\r
192 inp_prev = ret;\r
193 inp_prevjoy = 0;\r
194\r
195 // we don't need diagonals in menus\r
196 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;\r
197 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;\r
198 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;\r
199 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;\r
200\r
201 return ret;\r
202}\r
203\r
204static unsigned long input2_read(unsigned long interesting, int *joy)\r
205{\r
206 unsigned long ret;\r
207 int i;\r
208\r
209 do\r
210 {\r
211 *joy = 0;\r
212 if ((ret = gp2x_joystick_read(0) & interesting)) break;\r
213 gp2x_usbjoy_update();\r
214 for (i = 0; i < num_of_joys; i++) {\r
215 ret = gp2x_usbjoy_check2(i);\r
216 if (ret) { *joy = i + 1; break; }\r
217 }\r
218 if (ret) break;\r
219 }\r
220 while(0);\r
221\r
222 return ret;\r
223}\r
224\r
225// similar to wait_for_input(), but returns joy num\r
226static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)\r
227{\r
228 unsigned long ret;\r
229 const int wait = 300*1000;\r
230 int i;\r
231\r
232 if (inp_prevjoy == 0) inp_prev &= interesting;\r
233 for (i = 0; i < 6; i++) {\r
234 ret = input2_read(interesting, joy);\r
235 if (*joy != inp_prevjoy || ret != inp_prev) break;\r
236 usleep(wait/6);\r
237 }\r
238\r
239 while ( !(ret = input2_read(interesting, joy)) ) {\r
240 usleep(50000);\r
241 }\r
242\r
243 inp_prev = ret;\r
244 inp_prevjoy = *joy;\r
245\r
246 return ret;\r
247}\r
248\r
249\r
250\r
251// -------------- ROM selector --------------\r
252\r
253static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
254{\r
255 int start, i, pos;\r
256\r
257 start = 12 - sel;\r
258 n--; // exclude current dir (".")\r
259\r
e5d315a5 260 //memset(gp2x_screen, 0, 320*240);\r
261 gp2x_pd_clone_buffer2();\r
720ee7f6 262\r
263 if(start - 2 >= 0)\r
0805b5b4 264 gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);\r
720ee7f6 265 for (i = 0; i < n; i++) {\r
266 pos = start + i;\r
267 if (pos < 0) continue;\r
268 if (pos > 23) break;\r
269 if (namelist[i+1]->d_type == DT_DIR) {\r
0805b5b4 270 gp2x_smalltext8_lim(14, pos*10, "/", 1);\r
271 gp2x_smalltext8_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);\r
720ee7f6 272 } else {\r
0805b5b4 273 gp2x_smalltext8_lim(14, pos*10, namelist[i+1]->d_name, 53-2);\r
720ee7f6 274 }\r
275 }\r
276 gp2x_text_out8(5, 120, ">");\r
e5d315a5 277 gp2x_video_flip2();\r
720ee7f6 278}\r
279\r
280static int scandir_cmp(const void *p1, const void *p2)\r
281{\r
282 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r
283 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r
284 if ((*d1)->d_type == DT_DIR) return -1; // put before\r
285 if ((*d2)->d_type == DT_DIR) return 1;\r
286 return alphasort(d1, d2);\r
287}\r
288\r
289\r
290static char *romsel_loop(char *curr_path)\r
291{\r
292 struct dirent **namelist;\r
293 DIR *dir;\r
294 int n, sel = 0;\r
295 unsigned long inp = 0;\r
296 char *ret = NULL, *fname = NULL;\r
297\r
298 // is this a dir or a full path?\r
299 if ((dir = opendir(curr_path))) {\r
300 closedir(dir);\r
301 } else {\r
302 char *p;\r
303 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);\r
304 *p = 0;\r
305 fname = p+1;\r
306 }\r
307\r
308 n = scandir(curr_path, &namelist, 0, scandir_cmp);\r
309 if (n < 0) {\r
310 // try root\r
311 n = scandir(curr_path, &namelist, 0, scandir_cmp);\r
312 if (n < 0) {\r
313 // oops, we failed\r
314 printf("dir: "); printf(curr_path); printf("\n");\r
315 perror("scandir");\r
316 return NULL;\r
317 }\r
318 }\r
319\r
320 // try to find sel\r
321 if (fname != NULL) {\r
322 int i;\r
323 for (i = 1; i < n; i++) {\r
324 if (strcmp(namelist[i]->d_name, fname) == 0) {\r
325 sel = i - 1;\r
326 break;\r
327 }\r
328 }\r
329 }\r
330\r
331 for (;;)\r
332 {\r
333 draw_dirlist(curr_path, namelist, n, sel);\r
5111820c 334 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r
720ee7f6 335 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }\r
336 if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }\r
5111820c 337 if(inp &(GP2X_LEFT|GP2X_L)) { sel-=10; if (sel < 0) sel = 0; }\r
338 if(inp &(GP2X_RIGHT|GP2X_R)) { sel+=10; if (sel > n-2) sel = n-2; }\r
720ee7f6 339 if(inp & GP2X_B) { // enter dir/select\r
340 again:\r
341 if (namelist[sel+1]->d_type == DT_REG) {\r
342 strcpy(romFileName, curr_path);\r
343 strcat(romFileName, "/");\r
344 strcat(romFileName, namelist[sel+1]->d_name);\r
345 ret = romFileName;\r
346 break;\r
347 } else if (namelist[sel+1]->d_type == DT_DIR) {\r
348 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
349 char *p, *newdir = malloc(newlen);\r
350 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r
351 char *start = curr_path;\r
352 p = start + strlen(start) - 1;\r
353 while (*p == '/' && p > start) p--;\r
354 while (*p != '/' && p > start) p--;\r
355 if (p <= start) strcpy(newdir, "/");\r
356 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }\r
357 } else {\r
358 strcpy(newdir, curr_path);\r
359 p = newdir + strlen(newdir) - 1;\r
360 while (*p == '/' && p >= newdir) *p-- = 0;\r
361 strcat(newdir, "/");\r
362 strcat(newdir, namelist[sel+1]->d_name);\r
363 }\r
364 ret = romsel_loop(newdir);\r
365 free(newdir);\r
366 break;\r
367 } else {\r
368 // unknown file type, happens on NTFS mounts. Try to guess.\r
369 FILE *tstf; int tmp;\r
370 strcpy(romFileName, curr_path);\r
371 strcat(romFileName, "/");\r
372 strcat(romFileName, namelist[sel+1]->d_name);\r
373 tstf = fopen(romFileName, "rb");\r
374 if (tstf != NULL)\r
375 {\r
376 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)\r
377 namelist[sel+1]->d_type = DT_REG;\r
378 else namelist[sel+1]->d_type = DT_DIR;\r
379 fclose(tstf);\r
380 goto again;\r
381 }\r
382 }\r
383 }\r
384 if(inp & GP2X_X) break; // cancel\r
385 }\r
386\r
387 if (n > 0) {\r
388 while(n--) free(namelist[n]);\r
389 free(namelist);\r
390 }\r
391\r
392 return ret;\r
393}\r
394\r
70d2ecc5 395// ------------ patch/gg menu ------------\r
396\r
397static void draw_patchlist(int sel)\r
398{\r
399 int start, i, pos;\r
400\r
401 start = 12 - sel;\r
402\r
403 gp2x_pd_clone_buffer2();\r
404\r
405 for (i = 0; i < PicoPatchCount; i++) {\r
406 pos = start + i;\r
407 if (pos < 0) continue;\r
408 if (pos > 23) break;\r
409 gp2x_smalltext8_lim(14, pos*10, PicoPatches[i].active ? "ON " : "OFF", 3);\r
af6e9c49 410 gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6);\r
70d2ecc5 411 }\r
412 pos = start + i;\r
413 if (pos < 24) gp2x_smalltext8_lim(14, pos*10, "done", 4);\r
414\r
415 gp2x_text_out8(5, 120, ">");\r
416 gp2x_video_flip2();\r
417}\r
418\r
419\r
420void patches_menu_loop(void)\r
421{\r
422 int menu_sel = 0;\r
423 unsigned long inp = 0;\r
424\r
425 for(;;)\r
426 {\r
427 draw_patchlist(menu_sel);\r
428 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r
429 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r
430 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r
431 if(inp &(GP2X_LEFT|GP2X_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r
432 if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r
433 if(inp & GP2X_B) { // action\r
434 if (menu_sel < PicoPatchCount)\r
435 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r
436 else return;\r
437 }\r
438 if(inp & GP2X_X) return;\r
439 }\r
440\r
441}\r
442\r
4ffd2858 443// ------------ savestate loader ------------\r
444\r
445static void menu_prepare_bg(void);\r
446\r
447static int state_slot_flags = 0;\r
448\r
449static void state_check_slots(void)\r
450{\r
451 int slot;\r
452\r
453 state_slot_flags = 0;\r
454\r
455 for (slot = 0; slot < 10; slot++)\r
456 {\r
457 if (emu_check_save_file(slot))\r
458 {\r
459 state_slot_flags |= 1 << slot;\r
460 }\r
461 }\r
462}\r
463\r
464static void draw_savestate_bg(int slot)\r
465{\r
466 struct PicoVideo tmp_pv;\r
467 unsigned short tmp_cram[0x40];\r
468 unsigned short tmp_vsram[0x40];\r
469 void *tmp_vram, *file;\r
470 char *fname;\r
471\r
472 fname = emu_GetSaveFName(1, 0, slot);\r
473 if (!fname) return;\r
474\r
475 tmp_vram = malloc(sizeof(Pico.vram));\r
476 if (tmp_vram == NULL) return;\r
477\r
478 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));\r
479 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));\r
480 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));\r
481 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));\r
482\r
483 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r
484 file = gzopen(fname, "rb");\r
485 emu_set_save_cbs(1);\r
486 } else {\r
487 file = fopen(fname, "rb");\r
488 emu_set_save_cbs(0);\r
489 }\r
490\r
491 if (file) {\r
492 if (PicoMCD & 1) {\r
493 PicoCdLoadStateGfx(file);\r
494 } else {\r
495 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file\r
496 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);\r
497 areaSeek(file, 0x2000, SEEK_CUR);\r
498 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);\r
499 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);\r
500 areaSeek(file, 0x221a0, SEEK_SET);\r
501 areaRead(&Pico.video, 1, sizeof(Pico.video), file);\r
502 }\r
503 areaClose(file);\r
504 }\r
505\r
506 emu_forced_frame();\r
507 gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);\r
508 menu_prepare_bg();\r
509\r
510 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
511 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));\r
512 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));\r
513 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));\r
514 free(tmp_vram);\r
515}\r
516\r
517static void draw_savestate_menu(int menu_sel, int is_loading)\r
518{\r
519 int tl_x = 25, tl_y = 60, y, i;\r
520\r
521 if (state_slot_flags & (1 << menu_sel))\r
522 draw_savestate_bg(menu_sel);\r
523 gp2x_pd_clone_buffer2();\r
524\r
525 gp2x_text_out8(tl_x, 30, is_loading ? "Load state" : "Save state");\r
526\r
527 /* draw all 10 slots */\r
528 y = tl_y;\r
529 for (i = 0; i < 10; i++, y+=10)\r
530 {\r
531 gp2x_text_out8(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r
532 }\r
533 gp2x_text_out8(tl_x, y, "back");\r
534\r
535 // draw cursor\r
536 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
537\r
538 gp2x_video_flip2();\r
539}\r
540\r
541static int savestate_menu_loop(int is_loading)\r
542{\r
543 int menu_sel = 10, menu_sel_max = 10;\r
544 unsigned long inp = 0;\r
545\r
546 state_check_slots();\r
547\r
548 for(;;)\r
549 {\r
550 draw_savestate_menu(menu_sel, is_loading);\r
551 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);\r
552 if(inp & GP2X_UP ) {\r
553 do {\r
554 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;\r
555 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
556 }\r
557 if(inp & GP2X_DOWN) {\r
558 do {\r
559 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;\r
560 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
561 }\r
562 if(inp & GP2X_B) { // save/load\r
563 if (menu_sel < 10) {\r
564 state_slot = menu_sel;\r
565 if (emu_SaveLoadGame(is_loading, 0)) {\r
566 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");\r
567 return 1;\r
568 }\r
569 return 0;\r
570 } else return 1;\r
571 }\r
572 if(inp & GP2X_X) return 1;\r
573 }\r
574}\r
575\r
720ee7f6 576// -------------- key config --------------\r
577\r
578static char *usb_joy_key_name(int joy, int num)\r
579{\r
580 static char name[16];\r
581 switch (num)\r
582 {\r
583 case 0: sprintf(name, "Joy%i UP", joy); break;\r
584 case 1: sprintf(name, "Joy%i DOWN", joy); break;\r
585 case 2: sprintf(name, "Joy%i LEFT", joy); break;\r
586 case 3: sprintf(name, "Joy%i RIGHT", joy); break;\r
587 default:sprintf(name, "Joy%i b%i", joy, num-3); break;\r
588 }\r
589 return name;\r
590}\r
591\r
592static void draw_key_config(int curr_act, int is_p2)\r
593{\r
594 char strkeys[32*5];\r
595 int joy, i;\r
596\r
597 strkeys[0] = 0;\r
598 for (i = 0; i < 32; i++)\r
599 {\r
600 if (currentConfig.KeyBinds[i] & (1 << curr_act))\r
601 {\r
602 if (curr_act < 16 && (currentConfig.KeyBinds[i] & (1 << 16)) != (is_p2 << 16)) continue;\r
603 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }\r
604 else strcpy(strkeys, gp2xKeyNames[i]);\r
605 }\r
606 }\r
607 for (joy = 0; joy < num_of_joys; joy++)\r
608 {\r
609 for (i = 0; i < 32; i++)\r
610 {\r
611 if (currentConfig.JoyBinds[joy][i] & (1 << curr_act))\r
612 {\r
613 if (curr_act < 16 && (currentConfig.JoyBinds[joy][i] & (1 << 16)) != (is_p2 << 16)) continue;\r
614 if (strkeys[0]) {\r
615 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));\r
616 break;\r
617 }\r
618 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));\r
619 }\r
620 }\r
621 }\r
622\r
e5d315a5 623 //memset(gp2x_screen, 0, 320*240);\r
624 gp2x_pd_clone_buffer2();\r
720ee7f6 625 gp2x_text_out8(60, 40, "Action: %s", actionNames[curr_act]);\r
626 gp2x_text_out8(60, 60, "Keys: %s", strkeys);\r
627\r
628 gp2x_text_out8(30, 180, "Use SELECT to change action");\r
629 gp2x_text_out8(30, 190, "Press a key to bind/unbind");\r
630 gp2x_text_out8(30, 200, "Select \"Done\" action and");\r
631 gp2x_text_out8(30, 210, " press any key to finish");\r
e5d315a5 632 gp2x_video_flip2();\r
720ee7f6 633}\r
634\r
635static void key_config_loop(int is_p2)\r
636{\r
637 int curr_act = 0, joy = 0, i;\r
638 unsigned long inp = 0;\r
639\r
640 for (;;)\r
641 {\r
642 draw_key_config(curr_act, is_p2);\r
643 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);\r
644 // printf("got %08lX from joy %i\n", inp, joy);\r
645 if (joy == 0) {\r
646 if (inp & GP2X_SELECT) {\r
647 curr_act++;\r
648 while (!actionNames[curr_act] && curr_act < 32) curr_act++;\r
649 if (curr_act > 31) curr_act = 0;\r
650 }\r
651 inp &= CONFIGURABLE_KEYS;\r
652 inp &= ~GP2X_SELECT;\r
653 }\r
654 if (curr_act == 31 && inp) break;\r
655 if (joy == 0) {\r
656 for (i = 0; i < 32; i++)\r
657 if (inp & (1 << i)) {\r
658 currentConfig.KeyBinds[i] ^= (1 << curr_act);\r
659 if (is_p2) currentConfig.KeyBinds[i] |= (1 << 16); // player 2 flag\r
660 else currentConfig.KeyBinds[i] &= ~(1 << 16);\r
661 }\r
662 } else {\r
663 for (i = 0; i < 32; i++)\r
664 if (inp & (1 << i)) {\r
665 currentConfig.JoyBinds[joy-1][i] ^= (1 << curr_act);\r
666 if (is_p2) currentConfig.JoyBinds[joy-1][i] |= (1 << 16);\r
667 else currentConfig.JoyBinds[joy-1][i] &= ~(1 << 16);\r
668 }\r
669 }\r
670 }\r
671}\r
672\r
673static void draw_kc_sel(int menu_sel)\r
674{\r
675 int tl_x = 25+40, tl_y = 60, y, i;\r
676 char joyname[36];\r
677\r
678 y = tl_y;\r
e5d315a5 679 //memset(gp2x_screen, 0, 320*240);\r
680 gp2x_pd_clone_buffer2();\r
720ee7f6 681 gp2x_text_out8(tl_x, y, "Player 1");\r
682 gp2x_text_out8(tl_x, (y+=10), "Player 2");\r
683 gp2x_text_out8(tl_x, (y+=10), "Done");\r
684\r
685 // draw cursor\r
686 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
687\r
688 tl_x = 25;\r
689 gp2x_text_out8(tl_x, (y=110), "USB joys detected:");\r
690 if (num_of_joys > 0) {\r
691 for (i = 0; i < num_of_joys; i++) {\r
692 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;\r
693 gp2x_text_out8(tl_x, (y+=10), "%i: %s", i+1, joyname);\r
694 }\r
695 } else {\r
696 gp2x_text_out8(tl_x, (y+=10), "none");\r
697 }\r
698\r
699\r
e5d315a5 700 gp2x_video_flip2();\r
720ee7f6 701}\r
702\r
703static void kc_sel_loop(void)\r
704{\r
705 int menu_sel = 2, menu_sel_max = 2;\r
706 unsigned long inp = 0;\r
707\r
708 for(;;)\r
709 {\r
710 draw_kc_sel(menu_sel);\r
711 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);\r
712 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
713 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
714 if(inp & GP2X_B) {\r
715 switch (menu_sel) {\r
716 case 0: key_config_loop(0); return;\r
717 case 1: key_config_loop(1); return;\r
718 default: return;\r
719 }\r
720 }\r
721 if(inp & GP2X_X) return;\r
722 }\r
723}\r
724\r
725\r
726\r
daf91588 727// --------- sega/mega cd options ----------\r
728\r
729static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp)\r
730{\r
731 int tl_x = 25, tl_y = 60, y;\r
5f9922e6 732 char ra_buff[16];\r
733\r
734 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r
735 else strcpy(ra_buff, " OFF");\r
daf91588 736\r
737 y = tl_y;\r
e5d315a5 738 //memset(gp2x_screen, 0, 320*240);\r
739 gp2x_pd_clone_buffer2();\r
740\r
daf91588 741 gp2x_text_out8(tl_x, y, "USA BIOS: %s", b_us); // 0\r
742 gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1\r
743 gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2\r
dccc2bd0 744 gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x0400)?"ON":"OFF"); // 3\r
745 gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x0800)?"ON":"OFF"); // 4\r
746 gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x0400)?"ON":"OFF"); // 5\r
7789349f 747 gp2x_text_out8(tl_x, (y+=10), "ReadAhead buffer %s", ra_buff); // 6\r
748 gp2x_text_out8(tl_x, (y+=10), "Scale/Rot. fx (buggy,slow) %s", (currentConfig.PicoOpt&0x1000)?"ON":"OFF"); // 7\r
749 gp2x_text_out8(tl_x, (y+=10), "Better sync (slow) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 8\r
daf91588 750 gp2x_text_out8(tl_x, (y+=10), "Done");\r
751\r
752 // draw cursor\r
753 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
754\r
755 if ((menu_sel == 0 && strcmp(b_us, "NOT FOUND")) ||\r
756 (menu_sel == 1 && strcmp(b_eu, "NOT FOUND")) ||\r
757 (menu_sel == 2 && strcmp(b_jp, "NOT FOUND")))\r
758 gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");\r
759\r
e5d315a5 760 gp2x_video_flip2();\r
daf91588 761}\r
762\r
763static void cd_menu_loop_options(void)\r
764{\r
7789349f 765 int menu_sel = 0, menu_sel_max = 9;\r
daf91588 766 unsigned long inp = 0;\r
767 char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;\r
768\r
769 if (find_bios(4, &bios)) { // US\r
770 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
771 strncpy(bios_us, p, 31); bios_us[31] = 0;\r
772 } else strcpy(bios_us, "NOT FOUND");\r
773\r
774 if (find_bios(8, &bios)) { // EU\r
775 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
776 strncpy(bios_eu, p, 31); bios_eu[31] = 0;\r
777 } else strcpy(bios_eu, "NOT FOUND");\r
778\r
779 if (find_bios(1, &bios)) { // JP\r
780 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
781 strncpy(bios_jp, p, 31); bios_jp[31] = 0;\r
782 } else strcpy(bios_jp, "NOT FOUND");\r
783\r
784 for(;;)\r
785 {\r
786 draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp);\r
787 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);\r
788 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
789 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
790 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
791 switch (menu_sel) {\r
dccc2bd0 792 case 3: currentConfig.EmuOpt ^=0x0400; break;\r
793 case 4: currentConfig.PicoOpt^=0x0800; break;\r
794 case 5: currentConfig.PicoOpt^=0x0400; break;\r
7789349f 795 case 6:\r
5f9922e6 796 if (inp & GP2X_LEFT) {\r
797 PicoCDBuffers >>= 1;\r
798 if (PicoCDBuffers < 64) PicoCDBuffers = 0;\r
799 } else {\r
800 if (PicoCDBuffers < 64) PicoCDBuffers = 64;\r
801 else PicoCDBuffers <<= 1;\r
802 if (PicoCDBuffers > 4096) PicoCDBuffers = 4096;\r
803 }\r
804 break;\r
7789349f 805 case 7: currentConfig.PicoOpt^=0x1000; break;\r
806 case 8: currentConfig.PicoOpt^=0x2000; break;\r
807 case 9: return;\r
daf91588 808 }\r
809 }\r
810 if(inp & (GP2X_X|GP2X_A)) return;\r
811 if(inp & GP2X_START) { // BIOS testers\r
812 switch (menu_sel) {\r
813 case 0: if (find_bios(4, &bios)) { // test US\r
814 strcpy(romFileName, bios);\r
815 engineState = PGS_ReloadRom;\r
816 return;\r
817 }\r
818 break;\r
819 case 1: if (find_bios(8, &bios)) { // test EU\r
820 strcpy(romFileName, bios);\r
821 engineState = PGS_ReloadRom;\r
822 return;\r
823 }\r
824 break;\r
825 case 2: if (find_bios(1, &bios)) { // test JP\r
826 strcpy(romFileName, bios);\r
827 engineState = PGS_ReloadRom;\r
828 return;\r
829 }\r
830 break;\r
831 }\r
832 }\r
833 }\r
834}\r
835\r
836\r
837// --------- advanced options ----------\r
838\r
720ee7f6 839static void draw_amenu_options(int menu_sel)\r
840{\r
841 int tl_x = 25, tl_y = 60, y;\r
842 char *mms = mmuhack_status ? "active) " : "inactive)";\r
843\r
844 y = tl_y;\r
e5d315a5 845 //memset(gp2x_screen, 0, 320*240);\r
846 gp2x_pd_clone_buffer2();\r
847\r
979ba09f 848 gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (currentConfig.PicoOpt&0x100)?"ON":"OFF"); // 0\r
849 gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 1\r
850 gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (currentConfig.PicoOpt&0x004)?"ON":"OFF"); // 2\r
851 gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (currentConfig.PicoOpt&0x001)?"ON":"OFF"); // 3\r
852 gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (currentConfig.PicoOpt&0x002)?"ON":"OFF"); // 4\r
853 gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (currentConfig.EmuOpt &0x008)?"ON":"OFF"); // 5\r
854 gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 6\r
720ee7f6 855 gp2x_text_out8(tl_x, (y+=10), "needs restart:");\r
979ba09f 856 gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 8\r
857 gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 9\r
720ee7f6 858 gp2x_text_out8(tl_x, (y+=10), "Done");\r
859\r
860 // draw cursor\r
861 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
862\r
e5d315a5 863 gp2x_video_flip2();\r
720ee7f6 864}\r
865\r
866static void amenu_loop_options(void)\r
867{\r
47f22a1f 868 int menu_sel = 0, menu_sel_max = 10;\r
720ee7f6 869 unsigned long inp = 0;\r
870\r
871 for(;;)\r
872 {\r
873 draw_amenu_options(menu_sel);\r
874 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
875 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
876 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
877 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
878 switch (menu_sel) {\r
979ba09f 879 case 0: currentConfig.PicoOpt^=0x100; break;\r
880 case 2: currentConfig.PicoOpt^=0x004; break;\r
881 case 3: currentConfig.PicoOpt^=0x001; break;\r
882 case 4: currentConfig.PicoOpt^=0x002; break;\r
883 case 5: currentConfig.EmuOpt ^=0x008; break;\r
884 case 6: currentConfig.EmuOpt ^=0x020; break;\r
885 case 8: currentConfig.EmuOpt ^=0x100; break;\r
886 case 9: currentConfig.EmuOpt ^=0x010; break;\r
720ee7f6 887 case 10: return;\r
888 }\r
889 }\r
890 if(inp & (GP2X_X|GP2X_A)) return;\r
891 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
892 switch (menu_sel) {\r
893 case 1:\r
894 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
979ba09f 895 currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;\r
896 if (currentConfig.gamma < 1) currentConfig.gamma = 1;\r
897 if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r
720ee7f6 898 draw_amenu_options(menu_sel);\r
899 usleep(18*1000);\r
900 }\r
901 break;\r
902 }\r
903 }\r
904 }\r
905}\r
906\r
907// -------------- options --------------\r
908\r
979ba09f 909static const char *region_name(unsigned int code)\r
720ee7f6 910{\r
979ba09f 911 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };\r
912 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r
913 int u, i = 0;\r
914 if (code) {\r
915 code <<= 1;\r
916 while((code >>= 1)) i++;\r
917 if (i > 4) return "unknown";\r
918 return names[i];\r
919 } else {\r
920 static char name[24];\r
921 strcpy(name, "Auto:");\r
922 for (u = 0; u < 3; u++) {\r
923 i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;\r
924 while((code >>= 1)) i++;\r
925 strcat(name, names_short[i]);\r
926 }\r
927 return name;\r
928 }\r
720ee7f6 929}\r
930\r
931static void draw_menu_options(int menu_sel)\r
932{\r
933 int tl_x = 25, tl_y = 40, y;\r
934 char monostereo[8], strframeskip[8], *strrend;\r
935\r
979ba09f 936 strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");\r
937 if (currentConfig.Frameskip < 0)\r
720ee7f6 938 strcpy(strframeskip, "Auto");\r
979ba09f 939 else sprintf(strframeskip, "%i", currentConfig.Frameskip);\r
940 if (currentConfig.PicoOpt&0x10) {\r
720ee7f6 941 strrend = " 8bit fast";\r
979ba09f 942 } else if (currentConfig.EmuOpt&0x80) {\r
720ee7f6 943 strrend = "16bit accurate";\r
944 } else {\r
945 strrend = " 8bit accurate";\r
946 }\r
947\r
948 y = tl_y;\r
e5d315a5 949 //memset(gp2x_screen, 0, 320*240);\r
950 gp2x_pd_clone_buffer2();\r
951\r
720ee7f6 952 gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0\r
979ba09f 953 gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (currentConfig.PicoOpt&0x040)?"ON":"OFF"); // 1\r
954 gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (currentConfig.PicoOpt&0x080)?"ON":"OFF"); // 2\r
955 gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (currentConfig.EmuOpt &0x002)?"ON":"OFF"); // 3\r
720ee7f6 956 gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip);\r
979ba09f 957 gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (currentConfig.EmuOpt &0x004)?"ON":"OFF"); // 5\r
958 gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", currentConfig.PsndRate, monostereo);\r
959 gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (currentConfig.PicoOpt&0x200)?"ON":"OFF"); // 7\r
960 gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (currentConfig.PicoOpt&0x020)?"ON":"OFF"); // 8\r
961 gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(currentConfig.PicoRegion));\r
962 gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (currentConfig.EmuOpt &0x001)?"ON":"OFF"); // 10\r
963 gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (currentConfig.EmuOpt &0x200)?"ON":"OFF"); // 11\r
720ee7f6 964 gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12\r
979ba09f 965 gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", currentConfig.CPUclock);\r
daf91588 966 gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]");\r
967 gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15\r
720ee7f6 968 gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");\r
969 if (rom_data)\r
970 gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");\r
971\r
972 // draw cursor\r
973 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
974\r
e5d315a5 975 gp2x_video_flip2();\r
720ee7f6 976}\r
977\r
978static int sndrate_prevnext(int rate, int dir)\r
979{\r
980 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };\r
981\r
982 for (i = 0; i < 5; i++)\r
983 if (rates[i] == rate) break;\r
984\r
985 i += dir ? 1 : -1;\r
986 if (i > 4) return dir ? 44100 : 22050;\r
987 if (i < 0) return dir ? 11025 : 8000;\r
988 return rates[i];\r
989}\r
990\r
979ba09f 991static void region_prevnext(int right)\r
992{\r
993 // jp_ntsc=1, jp_pal=2, usa=4, eu=8\r
994 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r
995 int i;\r
996 if (right) {\r
997 if (!currentConfig.PicoRegion) {\r
998 for (i = 0; i < 6; i++)\r
999 if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
1000 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];\r
1001 else currentConfig.PicoRegion=1;\r
1002 }\r
1003 else currentConfig.PicoRegion<<=1;\r
1004 if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;\r
1005 } else {\r
1006 if (!currentConfig.PicoRegion) {\r
1007 for (i = 0; i < 6; i++)\r
1008 if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
1009 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];\r
1010 }\r
1011 else currentConfig.PicoRegion>>=1;\r
1012 }\r
1013}\r
1014\r
720ee7f6 1015static void menu_options_save(void)\r
1016{\r
720ee7f6 1017 PicoOpt = currentConfig.PicoOpt;\r
1018 PsndRate = currentConfig.PsndRate;\r
1019 PicoRegionOverride = currentConfig.PicoRegion;\r
1020 if (PicoOpt & 0x20) {\r
1021 actionNames[ 8] = "Z"; actionNames[ 9] = "Y";\r
1022 actionNames[10] = "X"; actionNames[11] = "MODE";\r
1023 } else {\r
1024 actionNames[8] = actionNames[9] = actionNames[10] = actionNames[11] = 0;\r
1025 }\r
1026}\r
1027\r
daf91588 1028static int menu_loop_options(void)\r
720ee7f6 1029{\r
daf91588 1030 int menu_sel = 0, menu_sel_max = 16;\r
720ee7f6 1031 unsigned long inp = 0;\r
1032\r
1033 if (rom_data) menu_sel_max++;\r
979ba09f 1034 currentConfig.PicoOpt = PicoOpt;\r
1035 currentConfig.PsndRate = PsndRate;\r
1036 currentConfig.PicoRegion = PicoRegionOverride;\r
720ee7f6 1037\r
1038 for(;;)\r
1039 {\r
1040 draw_menu_options(menu_sel);\r
1041 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
1042 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
1043 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
1044 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
1045 switch (menu_sel) {\r
979ba09f 1046 case 1: currentConfig.PicoOpt^=0x040; break;\r
1047 case 2: currentConfig.PicoOpt^=0x080; break;\r
1048 case 3: currentConfig.EmuOpt ^=0x002; break;\r
1049 case 5: currentConfig.EmuOpt ^=0x004; break;\r
1050 case 7: currentConfig.PicoOpt^=0x200; break;\r
1051 case 8: currentConfig.PicoOpt^=0x020; break;\r
1052 case 10: currentConfig.EmuOpt ^=0x001; break;\r
1053 case 11: currentConfig.EmuOpt ^=0x200; break;\r
daf91588 1054 case 14: cd_menu_loop_options();\r
1055 if (engineState == PGS_ReloadRom)\r
1056 return 0; // test BIOS\r
1057 break;\r
1058 case 15: amenu_loop_options(); break;\r
1059 case 16: // done (update and write)\r
720ee7f6 1060 menu_options_save();\r
daf91588 1061 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r
1062 else strcpy(menuErrorMsg, "failed to write config");\r
1063 return 1;\r
1064 case 17: // done (update and write for current game)\r
720ee7f6 1065 menu_options_save();\r
daf91588 1066 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r
1067 else strcpy(menuErrorMsg, "failed to write config");\r
1068 return 1;\r
720ee7f6 1069 }\r
1070 }\r
979ba09f 1071 if(inp & (GP2X_X|GP2X_A)) {\r
720ee7f6 1072 menu_options_save();\r
daf91588 1073 return 0; // done (update, no write)\r
720ee7f6 1074 }\r
1075 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
1076 switch (menu_sel) {\r
1077 case 0:\r
1078 if (inp & GP2X_LEFT) {\r
979ba09f 1079 if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r
1080 else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;\r
1081 else if ( currentConfig.EmuOpt &0x80) break;\r
720ee7f6 1082 } else {\r
979ba09f 1083 if ( currentConfig.PicoOpt&0x10) break;\r
1084 else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;\r
1085 else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
720ee7f6 1086 }\r
1087 break;\r
1088 case 4:\r
979ba09f 1089 currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;\r
1090 if (currentConfig.Frameskip < 0) currentConfig.Frameskip = -1;\r
1091 if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32;\r
720ee7f6 1092 break;\r
1093 case 6:\r
979ba09f 1094 if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r
1095 currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;\r
1096 } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r
1097 currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r
1098 } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);\r
720ee7f6 1099 break;\r
1100 case 9:\r
979ba09f 1101 region_prevnext(inp & GP2X_RIGHT);\r
720ee7f6 1102 break;\r
1103 case 12:\r
1104 if (inp & GP2X_RIGHT) {\r
1105 state_slot++; if (state_slot > 9) state_slot = 0;\r
1106 } else {state_slot--; if (state_slot < 0) state_slot = 9;\r
1107 }\r
1108 break;\r
1109 case 13:\r
1110 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
979ba09f 1111 currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r
1112 if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;\r
720ee7f6 1113 draw_menu_options(menu_sel);\r
1114 usleep(50*1000);\r
1115 }\r
1116 break;\r
1117 }\r
1118 }\r
1119 }\r
1120}\r
1121\r
1122// -------------- credits --------------\r
1123\r
1124static void draw_menu_credits(void)\r
1125{\r
1126 int tl_x = 15, tl_y = 70, y;\r
e5d315a5 1127 //memset(gp2x_screen, 0, 320*240);\r
1128 gp2x_pd_clone_buffer2();\r
720ee7f6 1129\r
5111820c 1130 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r
720ee7f6 1131 y = tl_y;\r
1132 gp2x_text_out8(tl_x, y, "Credits:");\r
1133 gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r
1134 gp2x_text_out8(tl_x, (y+=10), " base code of PicoDrive");\r
1135 gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");\r
1136 gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");\r
1137 gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");\r
1138 gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");\r
1139 gp2x_text_out8(tl_x, (y+=10), " opensource Gens");\r
1140 gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");\r
1141 gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");\r
1142 gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");\r
1143 gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");\r
1144 gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");\r
1145 gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");\r
1146\r
e5d315a5 1147 gp2x_video_flip2();\r
720ee7f6 1148}\r
1149\r
1150\r
1151// -------------- root menu --------------\r
1152\r
1153static void draw_menu_root(int menu_sel)\r
1154{\r
1155 int tl_x = 70, tl_y = 70, y;\r
e5d315a5 1156 //memset(gp2x_screen, 0, 320*240);\r
1157 gp2x_pd_clone_buffer2();\r
720ee7f6 1158\r
1159 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);\r
1160\r
1161 y = tl_y;\r
1162 if (rom_data) {\r
1163 gp2x_text_out8(tl_x, y, "Resume game");\r
1164 gp2x_text_out8(tl_x, (y+=10), "Save State");\r
1165 gp2x_text_out8(tl_x, (y+=10), "Load State");\r
1166 gp2x_text_out8(tl_x, (y+=10), "Reset game");\r
1167 } else {\r
1168 y += 30;\r
1169 }\r
8dfb9fd5 1170 gp2x_text_out8(tl_x, (y+=10), "Load new ROM/ISO");\r
720ee7f6 1171 gp2x_text_out8(tl_x, (y+=10), "Change options");\r
1172 gp2x_text_out8(tl_x, (y+=10), "Configure controls");\r
1173 gp2x_text_out8(tl_x, (y+=10), "Credits");\r
1174 gp2x_text_out8(tl_x, (y+=10), "Exit");\r
70d2ecc5 1175 if (PicoPatches)\r
1176 gp2x_text_out8(tl_x, (y+=10), "Patches / GameGenie");\r
720ee7f6 1177\r
1178 // draw cursor\r
1179 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
1180 // error\r
1181 if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r
e5d315a5 1182 gp2x_video_flip2();\r
720ee7f6 1183}\r
1184\r
1185\r
1186static void menu_loop_root(void)\r
1187{\r
daf91588 1188 int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;\r
720ee7f6 1189 unsigned long inp = 0;\r
1190 char curr_path[PATH_MAX], *selfname;\r
1191 FILE *tstf;\r
1192\r
1193 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r
1194 {\r
1195 fclose(tstf);\r
1196 strcpy(curr_path, currentConfig.lastRomFile);\r
1197 }\r
1198 else\r
1199 {\r
1200 getcwd(curr_path, PATH_MAX);\r
1201 }\r
1202\r
1203 if (rom_data) menu_sel = menu_sel_min = 0;\r
70d2ecc5 1204 if (PicoPatches) menu_sel_max = 9;\r
720ee7f6 1205\r
1206 for(;;)\r
1207 {\r
1208 draw_menu_root(menu_sel);\r
1209 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT);\r
1210 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }\r
1211 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }\r
1212 if(inp &(GP2X_SELECT|GP2X_X)){\r
1213 if (rom_data) {\r
1214 while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released\r
1215 engineState = PGS_Running;\r
1216 break;\r
1217 }\r
1218 }\r
1219 if(inp & GP2X_B ) {\r
1220 switch (menu_sel) {\r
1221 case 0: // resume game\r
1222 if (rom_data) { engineState = PGS_Running; return; }\r
1223 break;\r
1224 case 1: // save state\r
1225 if (rom_data) {\r
4ffd2858 1226 if(savestate_menu_loop(0))\r
720ee7f6 1227 continue;\r
720ee7f6 1228 engineState = PGS_Running;\r
1229 return;\r
1230 }\r
1231 break;\r
1232 case 2: // load state\r
1233 if (rom_data) {\r
4ffd2858 1234 if(savestate_menu_loop(1))\r
720ee7f6 1235 continue;\r
720ee7f6 1236 engineState = PGS_Running;\r
1237 return;\r
1238 }\r
1239 break;\r
1240 case 3: // reset game\r
1241 if (rom_data) {\r
1242 emu_ResetGame();\r
1243 engineState = PGS_Running;\r
1244 return;\r
1245 }\r
1246 break;\r
1247 case 4: // select rom\r
1248 selfname = romsel_loop(curr_path);\r
1249 if (selfname) {\r
1250 printf("selected file: %s\n", selfname);\r
720ee7f6 1251 engineState = PGS_ReloadRom;\r
1252 }\r
1253 return;\r
1254 case 5: // options\r
daf91588 1255 ret = menu_loop_options();\r
1256 if (ret == 1) continue; // status update\r
1257 if (engineState == PGS_ReloadRom)\r
1258 return; // BIOS test\r
720ee7f6 1259 break;\r
1260 case 6: // controls\r
1261 kc_sel_loop();\r
1262 break;\r
1263 case 7: // credits\r
1264 draw_menu_credits();\r
1265 usleep(500*1000);\r
1266 inp = wait_for_input(GP2X_B|GP2X_X);\r
1267 break;\r
1268 case 8: // exit\r
1269 engineState = PGS_Quit;\r
1270 return;\r
70d2ecc5 1271 case 9: // patches/gg\r
1272 if (rom_data && PicoPatches) {\r
1273 patches_menu_loop();\r
1274 PicoPatchApply();\r
1275 strcpy(menuErrorMsg, "Patches applied");\r
1276 continue;\r
1277 }\r
1278 break;\r
720ee7f6 1279 }\r
1280 }\r
1281 menuErrorMsg[0] = 0; // clear error msg\r
1282 }\r
1283}\r
1284\r
1285\r
4ffd2858 1286static void menu_prepare_bg(void)\r
720ee7f6 1287{\r
e5d315a5 1288 extern int localPal[0x100];\r
4ffd2858 1289 int c, i;\r
e5d315a5 1290\r
1291 // don't clear old palette just for fun (but make it dark)\r
4ffd2858 1292 for (i = 0x100-1; i >= 0; i--) {\r
1293 c = localPal[i];\r
1294 localPal[i] = ((c >> 1) & 0x007f7f7f) - ((c >> 3) & 0x001f1f1f);\r
1295 }\r
e5d315a5 1296 localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
1297 localPal[0xf0] = 0x00ffffff;\r
720ee7f6 1298\r
4ffd2858 1299 gp2x_video_setpalette(localPal, 0x100);\r
1300}\r
1301\r
1302static void menu_gfx_prepare(void)\r
1303{\r
1304 menu_prepare_bg();\r
1305\r
720ee7f6 1306 // switch to 8bpp\r
e5d315a5 1307 gp2x_video_changemode2(8);\r
720ee7f6 1308 gp2x_video_RGB_setscaling(320, 240);\r
e5d315a5 1309 gp2x_video_flip2();\r
1310}\r
1311\r
1312\r
1313void menu_loop(void)\r
1314{\r
1315 menu_gfx_prepare();\r
720ee7f6 1316\r
1317 menu_loop_root();\r
1318\r
1319 menuErrorMsg[0] = 0;\r
1320}\r