bugfixes, cd/Memory.s
[picodrive.git] / platform / gp2x / menu.c
CommitLineData
cc68a136 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
76276b0b 16#include "fonts.h"\r
cc68a136 17#include "usbjoy.h"\r
18#include "version.h"\r
19\r
b67ef287 20#include <Pico/PicoInt.h>\r
21#include <Pico/Patch.h>\r
22#include <zlib/zlib.h>\r
cc68a136 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
76276b0b 44static void gp2x_text(unsigned char *screen, int x, int y, const char *text, int color)\r
cc68a136 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
76276b0b 68void gp2x_text_out15(int x, int y, const char *text)\r
cc68a136 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
76276b0b 93void gp2x_text_out8(int x, int y, const char *texto, ...)\r
cc68a136 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
e11c5548 102 gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r
cc68a136 103}\r
104\r
105\r
76276b0b 106void gp2x_text_out8_2(int x, int y, const char *texto, int color)\r
cc68a136 107{\r
108 gp2x_text(gp2x_screen, x, y, texto, color);\r
109}\r
110\r
76276b0b 111void gp2x_text_out8_lim(int x, int y, const char *texto, int max)\r
cc68a136 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
e11c5548 120 gp2x_text(gp2x_screen,x,y,buffer,0xf0);\r
cc68a136 121}\r
122\r
76276b0b 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
cc68a136 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
e11c5548 260 //memset(gp2x_screen, 0, 320*240);\r
261 gp2x_pd_clone_buffer2();\r
cc68a136 262\r
263 if(start - 2 >= 0)\r
76276b0b 264 gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);\r
cc68a136 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
76276b0b 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
cc68a136 272 } else {\r
76276b0b 273 gp2x_smalltext8_lim(14, pos*10, namelist[i+1]->d_name, 53-2);\r
cc68a136 274 }\r
275 }\r
276 gp2x_text_out8(5, 120, ">");\r
e11c5548 277 gp2x_video_flip2();\r
cc68a136 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
672ad671 334 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r
cc68a136 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
672ad671 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
cc68a136 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
b67ef287 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
83bd0b76 410 gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6);\r
b67ef287 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
860c6322 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
cc68a136 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
e11c5548 623 //memset(gp2x_screen, 0, 320*240);\r
624 gp2x_pd_clone_buffer2();\r
cc68a136 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
e11c5548 632 gp2x_video_flip2();\r
cc68a136 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
e11c5548 679 //memset(gp2x_screen, 0, 320*240);\r
680 gp2x_pd_clone_buffer2();\r
cc68a136 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
e11c5548 700 gp2x_video_flip2();\r
cc68a136 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
bf098bc5 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
0a051f55 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
bf098bc5 736\r
737 y = tl_y;\r
e11c5548 738 //memset(gp2x_screen, 0, 320*240);\r
739 gp2x_pd_clone_buffer2();\r
740\r
bf098bc5 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
68cba51e 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
4ff2d527 747 gp2x_text_out8(tl_x, (y+=10), "Better sync (slow) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 6\r
0a051f55 748 gp2x_text_out8(tl_x, (y+=10), "ReadAhead buffer %s", ra_buff); // 7\r
bf098bc5 749 gp2x_text_out8(tl_x, (y+=10), "Done");\r
750\r
751 // draw cursor\r
752 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
753\r
754 if ((menu_sel == 0 && strcmp(b_us, "NOT FOUND")) ||\r
755 (menu_sel == 1 && strcmp(b_eu, "NOT FOUND")) ||\r
756 (menu_sel == 2 && strcmp(b_jp, "NOT FOUND")))\r
757 gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");\r
758\r
e11c5548 759 gp2x_video_flip2();\r
bf098bc5 760}\r
761\r
762static void cd_menu_loop_options(void)\r
763{\r
0a051f55 764 int menu_sel = 0, menu_sel_max = 8;\r
bf098bc5 765 unsigned long inp = 0;\r
766 char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;\r
767\r
768 if (find_bios(4, &bios)) { // US\r
769 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
770 strncpy(bios_us, p, 31); bios_us[31] = 0;\r
771 } else strcpy(bios_us, "NOT FOUND");\r
772\r
773 if (find_bios(8, &bios)) { // EU\r
774 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
775 strncpy(bios_eu, p, 31); bios_eu[31] = 0;\r
776 } else strcpy(bios_eu, "NOT FOUND");\r
777\r
778 if (find_bios(1, &bios)) { // JP\r
779 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
780 strncpy(bios_jp, p, 31); bios_jp[31] = 0;\r
781 } else strcpy(bios_jp, "NOT FOUND");\r
782\r
783 for(;;)\r
784 {\r
785 draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp);\r
786 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);\r
787 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
788 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
789 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
790 switch (menu_sel) {\r
68cba51e 791 case 3: currentConfig.EmuOpt ^=0x0400; break;\r
792 case 4: currentConfig.PicoOpt^=0x0800; break;\r
793 case 5: currentConfig.PicoOpt^=0x0400; break;\r
794 case 6: currentConfig.PicoOpt^=0x2000; break;\r
0a051f55 795 case 7:\r
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
805 case 8: return;\r
bf098bc5 806 }\r
807 }\r
808 if(inp & (GP2X_X|GP2X_A)) return;\r
809 if(inp & GP2X_START) { // BIOS testers\r
810 switch (menu_sel) {\r
811 case 0: if (find_bios(4, &bios)) { // test US\r
812 strcpy(romFileName, bios);\r
813 engineState = PGS_ReloadRom;\r
814 return;\r
815 }\r
816 break;\r
817 case 1: if (find_bios(8, &bios)) { // test EU\r
818 strcpy(romFileName, bios);\r
819 engineState = PGS_ReloadRom;\r
820 return;\r
821 }\r
822 break;\r
823 case 2: if (find_bios(1, &bios)) { // test JP\r
824 strcpy(romFileName, bios);\r
825 engineState = PGS_ReloadRom;\r
826 return;\r
827 }\r
828 break;\r
829 }\r
830 }\r
831 }\r
832}\r
833\r
834\r
835// --------- advanced options ----------\r
836\r
cc68a136 837static void draw_amenu_options(int menu_sel)\r
838{\r
839 int tl_x = 25, tl_y = 60, y;\r
840 char *mms = mmuhack_status ? "active) " : "inactive)";\r
841\r
842 y = tl_y;\r
e11c5548 843 //memset(gp2x_screen, 0, 320*240);\r
844 gp2x_pd_clone_buffer2();\r
845\r
51a902ae 846 gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (currentConfig.PicoOpt&0x100)?"ON":"OFF"); // 0\r
847 gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 1\r
848 gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (currentConfig.PicoOpt&0x004)?"ON":"OFF"); // 2\r
849 gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (currentConfig.PicoOpt&0x001)?"ON":"OFF"); // 3\r
850 gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (currentConfig.PicoOpt&0x002)?"ON":"OFF"); // 4\r
851 gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (currentConfig.EmuOpt &0x008)?"ON":"OFF"); // 5\r
852 gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 6\r
cc68a136 853 gp2x_text_out8(tl_x, (y+=10), "needs restart:");\r
51a902ae 854 gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 8\r
855 gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 9\r
cc68a136 856 gp2x_text_out8(tl_x, (y+=10), "Done");\r
857\r
858 // draw cursor\r
859 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
860\r
e11c5548 861 gp2x_video_flip2();\r
cc68a136 862}\r
863\r
864static void amenu_loop_options(void)\r
865{\r
312e9ce1 866 int menu_sel = 0, menu_sel_max = 10;\r
cc68a136 867 unsigned long inp = 0;\r
868\r
869 for(;;)\r
870 {\r
871 draw_amenu_options(menu_sel);\r
872 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
873 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
874 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
875 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
876 switch (menu_sel) {\r
51a902ae 877 case 0: currentConfig.PicoOpt^=0x100; break;\r
878 case 2: currentConfig.PicoOpt^=0x004; break;\r
879 case 3: currentConfig.PicoOpt^=0x001; break;\r
880 case 4: currentConfig.PicoOpt^=0x002; break;\r
881 case 5: currentConfig.EmuOpt ^=0x008; break;\r
882 case 6: currentConfig.EmuOpt ^=0x020; break;\r
883 case 8: currentConfig.EmuOpt ^=0x100; break;\r
884 case 9: currentConfig.EmuOpt ^=0x010; break;\r
cc68a136 885 case 10: return;\r
886 }\r
887 }\r
888 if(inp & (GP2X_X|GP2X_A)) return;\r
889 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
890 switch (menu_sel) {\r
891 case 1:\r
892 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
51a902ae 893 currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;\r
894 if (currentConfig.gamma < 1) currentConfig.gamma = 1;\r
895 if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r
cc68a136 896 draw_amenu_options(menu_sel);\r
897 usleep(18*1000);\r
898 }\r
899 break;\r
900 }\r
901 }\r
902 }\r
903}\r
904\r
905// -------------- options --------------\r
906\r
51a902ae 907static const char *region_name(unsigned int code)\r
cc68a136 908{\r
51a902ae 909 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };\r
910 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r
911 int u, i = 0;\r
912 if (code) {\r
913 code <<= 1;\r
914 while((code >>= 1)) i++;\r
915 if (i > 4) return "unknown";\r
916 return names[i];\r
917 } else {\r
918 static char name[24];\r
919 strcpy(name, "Auto:");\r
920 for (u = 0; u < 3; u++) {\r
921 i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;\r
922 while((code >>= 1)) i++;\r
923 strcat(name, names_short[i]);\r
924 }\r
925 return name;\r
926 }\r
cc68a136 927}\r
928\r
929static void draw_menu_options(int menu_sel)\r
930{\r
931 int tl_x = 25, tl_y = 40, y;\r
932 char monostereo[8], strframeskip[8], *strrend;\r
933\r
51a902ae 934 strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");\r
935 if (currentConfig.Frameskip < 0)\r
cc68a136 936 strcpy(strframeskip, "Auto");\r
51a902ae 937 else sprintf(strframeskip, "%i", currentConfig.Frameskip);\r
938 if (currentConfig.PicoOpt&0x10) {\r
cc68a136 939 strrend = " 8bit fast";\r
51a902ae 940 } else if (currentConfig.EmuOpt&0x80) {\r
cc68a136 941 strrend = "16bit accurate";\r
942 } else {\r
943 strrend = " 8bit accurate";\r
944 }\r
945\r
946 y = tl_y;\r
e11c5548 947 //memset(gp2x_screen, 0, 320*240);\r
948 gp2x_pd_clone_buffer2();\r
949\r
cc68a136 950 gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0\r
51a902ae 951 gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (currentConfig.PicoOpt&0x040)?"ON":"OFF"); // 1\r
952 gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (currentConfig.PicoOpt&0x080)?"ON":"OFF"); // 2\r
953 gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (currentConfig.EmuOpt &0x002)?"ON":"OFF"); // 3\r
cc68a136 954 gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip);\r
51a902ae 955 gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (currentConfig.EmuOpt &0x004)?"ON":"OFF"); // 5\r
956 gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", currentConfig.PsndRate, monostereo);\r
957 gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (currentConfig.PicoOpt&0x200)?"ON":"OFF"); // 7\r
958 gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (currentConfig.PicoOpt&0x020)?"ON":"OFF"); // 8\r
959 gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(currentConfig.PicoRegion));\r
960 gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (currentConfig.EmuOpt &0x001)?"ON":"OFF"); // 10\r
961 gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (currentConfig.EmuOpt &0x200)?"ON":"OFF"); // 11\r
cc68a136 962 gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12\r
51a902ae 963 gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", currentConfig.CPUclock);\r
bf098bc5 964 gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]");\r
965 gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15\r
cc68a136 966 gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");\r
967 if (rom_data)\r
968 gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");\r
969\r
970 // draw cursor\r
971 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
972\r
e11c5548 973 gp2x_video_flip2();\r
cc68a136 974}\r
975\r
976static int sndrate_prevnext(int rate, int dir)\r
977{\r
978 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };\r
979\r
980 for (i = 0; i < 5; i++)\r
981 if (rates[i] == rate) break;\r
982\r
983 i += dir ? 1 : -1;\r
984 if (i > 4) return dir ? 44100 : 22050;\r
985 if (i < 0) return dir ? 11025 : 8000;\r
986 return rates[i];\r
987}\r
988\r
51a902ae 989static void region_prevnext(int right)\r
990{\r
991 // jp_ntsc=1, jp_pal=2, usa=4, eu=8\r
992 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r
993 int i;\r
994 if (right) {\r
995 if (!currentConfig.PicoRegion) {\r
996 for (i = 0; i < 6; i++)\r
997 if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
998 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];\r
999 else currentConfig.PicoRegion=1;\r
1000 }\r
1001 else currentConfig.PicoRegion<<=1;\r
1002 if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;\r
1003 } else {\r
1004 if (!currentConfig.PicoRegion) {\r
1005 for (i = 0; i < 6; i++)\r
1006 if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
1007 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];\r
1008 }\r
1009 else currentConfig.PicoRegion>>=1;\r
1010 }\r
1011}\r
1012\r
cc68a136 1013static void menu_options_save(void)\r
1014{\r
cc68a136 1015 PicoOpt = currentConfig.PicoOpt;\r
1016 PsndRate = currentConfig.PsndRate;\r
1017 PicoRegionOverride = currentConfig.PicoRegion;\r
1018 if (PicoOpt & 0x20) {\r
1019 actionNames[ 8] = "Z"; actionNames[ 9] = "Y";\r
1020 actionNames[10] = "X"; actionNames[11] = "MODE";\r
1021 } else {\r
1022 actionNames[8] = actionNames[9] = actionNames[10] = actionNames[11] = 0;\r
1023 }\r
1024}\r
1025\r
bf098bc5 1026static int menu_loop_options(void)\r
cc68a136 1027{\r
bf098bc5 1028 int menu_sel = 0, menu_sel_max = 16;\r
cc68a136 1029 unsigned long inp = 0;\r
1030\r
1031 if (rom_data) menu_sel_max++;\r
51a902ae 1032 currentConfig.PicoOpt = PicoOpt;\r
1033 currentConfig.PsndRate = PsndRate;\r
1034 currentConfig.PicoRegion = PicoRegionOverride;\r
cc68a136 1035\r
1036 for(;;)\r
1037 {\r
1038 draw_menu_options(menu_sel);\r
1039 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
1040 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
1041 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
1042 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
1043 switch (menu_sel) {\r
51a902ae 1044 case 1: currentConfig.PicoOpt^=0x040; break;\r
1045 case 2: currentConfig.PicoOpt^=0x080; break;\r
1046 case 3: currentConfig.EmuOpt ^=0x002; break;\r
1047 case 5: currentConfig.EmuOpt ^=0x004; break;\r
1048 case 7: currentConfig.PicoOpt^=0x200; break;\r
1049 case 8: currentConfig.PicoOpt^=0x020; break;\r
1050 case 10: currentConfig.EmuOpt ^=0x001; break;\r
1051 case 11: currentConfig.EmuOpt ^=0x200; break;\r
bf098bc5 1052 case 14: cd_menu_loop_options();\r
1053 if (engineState == PGS_ReloadRom)\r
1054 return 0; // test BIOS\r
1055 break;\r
1056 case 15: amenu_loop_options(); break;\r
1057 case 16: // done (update and write)\r
cc68a136 1058 menu_options_save();\r
bf098bc5 1059 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r
1060 else strcpy(menuErrorMsg, "failed to write config");\r
1061 return 1;\r
1062 case 17: // done (update and write for current game)\r
cc68a136 1063 menu_options_save();\r
bf098bc5 1064 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r
1065 else strcpy(menuErrorMsg, "failed to write config");\r
1066 return 1;\r
cc68a136 1067 }\r
1068 }\r
51a902ae 1069 if(inp & (GP2X_X|GP2X_A)) {\r
cc68a136 1070 menu_options_save();\r
bf098bc5 1071 return 0; // done (update, no write)\r
cc68a136 1072 }\r
1073 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
1074 switch (menu_sel) {\r
1075 case 0:\r
1076 if (inp & GP2X_LEFT) {\r
51a902ae 1077 if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r
1078 else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;\r
1079 else if ( currentConfig.EmuOpt &0x80) break;\r
cc68a136 1080 } else {\r
51a902ae 1081 if ( currentConfig.PicoOpt&0x10) break;\r
1082 else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;\r
1083 else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
cc68a136 1084 }\r
1085 break;\r
1086 case 4:\r
51a902ae 1087 currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;\r
1088 if (currentConfig.Frameskip < 0) currentConfig.Frameskip = -1;\r
1089 if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32;\r
cc68a136 1090 break;\r
1091 case 6:\r
51a902ae 1092 if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r
1093 currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;\r
1094 } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r
1095 currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r
1096 } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);\r
cc68a136 1097 break;\r
1098 case 9:\r
51a902ae 1099 region_prevnext(inp & GP2X_RIGHT);\r
cc68a136 1100 break;\r
1101 case 12:\r
1102 if (inp & GP2X_RIGHT) {\r
1103 state_slot++; if (state_slot > 9) state_slot = 0;\r
1104 } else {state_slot--; if (state_slot < 0) state_slot = 9;\r
1105 }\r
1106 break;\r
1107 case 13:\r
1108 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
51a902ae 1109 currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r
1110 if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;\r
cc68a136 1111 draw_menu_options(menu_sel);\r
1112 usleep(50*1000);\r
1113 }\r
1114 break;\r
1115 }\r
1116 }\r
1117 }\r
1118}\r
1119\r
1120// -------------- credits --------------\r
1121\r
1122static void draw_menu_credits(void)\r
1123{\r
1124 int tl_x = 15, tl_y = 70, y;\r
e11c5548 1125 //memset(gp2x_screen, 0, 320*240);\r
1126 gp2x_pd_clone_buffer2();\r
cc68a136 1127\r
672ad671 1128 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r
cc68a136 1129 y = tl_y;\r
1130 gp2x_text_out8(tl_x, y, "Credits:");\r
1131 gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r
1132 gp2x_text_out8(tl_x, (y+=10), " base code of PicoDrive");\r
1133 gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");\r
1134 gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");\r
1135 gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");\r
1136 gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");\r
1137 gp2x_text_out8(tl_x, (y+=10), " opensource Gens");\r
1138 gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");\r
1139 gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");\r
1140 gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");\r
1141 gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");\r
1142 gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");\r
1143 gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");\r
1144\r
e11c5548 1145 gp2x_video_flip2();\r
cc68a136 1146}\r
1147\r
1148\r
1149// -------------- root menu --------------\r
1150\r
1151static void draw_menu_root(int menu_sel)\r
1152{\r
1153 int tl_x = 70, tl_y = 70, y;\r
e11c5548 1154 //memset(gp2x_screen, 0, 320*240);\r
1155 gp2x_pd_clone_buffer2();\r
cc68a136 1156\r
1157 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);\r
1158\r
1159 y = tl_y;\r
1160 if (rom_data) {\r
1161 gp2x_text_out8(tl_x, y, "Resume game");\r
1162 gp2x_text_out8(tl_x, (y+=10), "Save State");\r
1163 gp2x_text_out8(tl_x, (y+=10), "Load State");\r
1164 gp2x_text_out8(tl_x, (y+=10), "Reset game");\r
1165 } else {\r
1166 y += 30;\r
1167 }\r
b837b69b 1168 gp2x_text_out8(tl_x, (y+=10), "Load new ROM/ISO");\r
cc68a136 1169 gp2x_text_out8(tl_x, (y+=10), "Change options");\r
1170 gp2x_text_out8(tl_x, (y+=10), "Configure controls");\r
1171 gp2x_text_out8(tl_x, (y+=10), "Credits");\r
1172 gp2x_text_out8(tl_x, (y+=10), "Exit");\r
b67ef287 1173 if (PicoPatches)\r
1174 gp2x_text_out8(tl_x, (y+=10), "Patches / GameGenie");\r
cc68a136 1175\r
1176 // draw cursor\r
1177 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
1178 // error\r
1179 if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r
e11c5548 1180 gp2x_video_flip2();\r
cc68a136 1181}\r
1182\r
1183\r
1184static void menu_loop_root(void)\r
1185{\r
bf098bc5 1186 int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;\r
cc68a136 1187 unsigned long inp = 0;\r
1188 char curr_path[PATH_MAX], *selfname;\r
1189 FILE *tstf;\r
1190\r
1191 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r
1192 {\r
1193 fclose(tstf);\r
1194 strcpy(curr_path, currentConfig.lastRomFile);\r
1195 }\r
1196 else\r
1197 {\r
1198 getcwd(curr_path, PATH_MAX);\r
1199 }\r
1200\r
1201 if (rom_data) menu_sel = menu_sel_min = 0;\r
b67ef287 1202 if (PicoPatches) menu_sel_max = 9;\r
cc68a136 1203\r
1204 for(;;)\r
1205 {\r
1206 draw_menu_root(menu_sel);\r
1207 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT);\r
1208 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }\r
1209 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }\r
1210 if(inp &(GP2X_SELECT|GP2X_X)){\r
1211 if (rom_data) {\r
1212 while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released\r
1213 engineState = PGS_Running;\r
1214 break;\r
1215 }\r
1216 }\r
1217 if(inp & GP2X_B ) {\r
1218 switch (menu_sel) {\r
1219 case 0: // resume game\r
1220 if (rom_data) { engineState = PGS_Running; return; }\r
1221 break;\r
1222 case 1: // save state\r
1223 if (rom_data) {\r
860c6322 1224 if(savestate_menu_loop(0))\r
cc68a136 1225 continue;\r
cc68a136 1226 engineState = PGS_Running;\r
1227 return;\r
1228 }\r
1229 break;\r
1230 case 2: // load state\r
1231 if (rom_data) {\r
860c6322 1232 if(savestate_menu_loop(1))\r
cc68a136 1233 continue;\r
cc68a136 1234 engineState = PGS_Running;\r
1235 return;\r
1236 }\r
1237 break;\r
1238 case 3: // reset game\r
1239 if (rom_data) {\r
1240 emu_ResetGame();\r
1241 engineState = PGS_Running;\r
1242 return;\r
1243 }\r
1244 break;\r
1245 case 4: // select rom\r
1246 selfname = romsel_loop(curr_path);\r
1247 if (selfname) {\r
1248 printf("selected file: %s\n", selfname);\r
cc68a136 1249 engineState = PGS_ReloadRom;\r
1250 }\r
1251 return;\r
1252 case 5: // options\r
bf098bc5 1253 ret = menu_loop_options();\r
1254 if (ret == 1) continue; // status update\r
1255 if (engineState == PGS_ReloadRom)\r
1256 return; // BIOS test\r
cc68a136 1257 break;\r
1258 case 6: // controls\r
1259 kc_sel_loop();\r
1260 break;\r
1261 case 7: // credits\r
1262 draw_menu_credits();\r
1263 usleep(500*1000);\r
1264 inp = wait_for_input(GP2X_B|GP2X_X);\r
1265 break;\r
1266 case 8: // exit\r
1267 engineState = PGS_Quit;\r
1268 return;\r
b67ef287 1269 case 9: // patches/gg\r
1270 if (rom_data && PicoPatches) {\r
1271 patches_menu_loop();\r
1272 PicoPatchApply();\r
1273 strcpy(menuErrorMsg, "Patches applied");\r
1274 continue;\r
1275 }\r
1276 break;\r
cc68a136 1277 }\r
1278 }\r
1279 menuErrorMsg[0] = 0; // clear error msg\r
1280 }\r
1281}\r
1282\r
1283\r
860c6322 1284static void menu_prepare_bg(void)\r
cc68a136 1285{\r
e11c5548 1286 extern int localPal[0x100];\r
860c6322 1287 int c, i;\r
e11c5548 1288\r
1289 // don't clear old palette just for fun (but make it dark)\r
860c6322 1290 for (i = 0x100-1; i >= 0; i--) {\r
1291 c = localPal[i];\r
1292 localPal[i] = ((c >> 1) & 0x007f7f7f) - ((c >> 3) & 0x001f1f1f);\r
1293 }\r
e11c5548 1294 localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
1295 localPal[0xf0] = 0x00ffffff;\r
cc68a136 1296\r
860c6322 1297 gp2x_video_setpalette(localPal, 0x100);\r
1298}\r
1299\r
1300static void menu_gfx_prepare(void)\r
1301{\r
1302 menu_prepare_bg();\r
1303\r
cc68a136 1304 // switch to 8bpp\r
e11c5548 1305 gp2x_video_changemode2(8);\r
cc68a136 1306 gp2x_video_RGB_setscaling(320, 240);\r
e11c5548 1307 gp2x_video_flip2();\r
1308}\r
1309\r
1310\r
1311void menu_loop(void)\r
1312{\r
1313 menu_gfx_prepare();\r
cc68a136 1314\r
1315 menu_loop_root();\r
1316\r
1317 menuErrorMsg[0] = 0;\r
1318}\r