1 // (c) Copyright 2006 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
18 #include "version.h"
\r
20 #include "Pico/PicoInt.h"
\r
22 #ifndef _DIRENT_HAVE_D_TYPE
\r
23 #error "need d_type for file browser
\r
26 extern char *actionNames[];
\r
27 extern char romFileName[PATH_MAX];
\r
28 extern char *rom_data;
\r
29 extern int mmuhack_status;
\r
30 extern int state_slot;
\r
32 static char *gp2xKeyNames[] = {
\r
33 "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",
\r
34 "START", "SELECT", "L", "R", "A", "B", "X", "Y",
\r
35 "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",
\r
36 "???", "???", "???", "PUSH", "???", "???", "???", "???"
\r
39 char menuErrorMsg[40] = {0, };
\r
42 static void gp2x_text(unsigned char *screen, int x, int y, const char *text, int color)
\r
46 screen = screen + x + y*320;
\r
48 for (i = 0; i < strlen(text); i++)
\r
52 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=color;
\r
53 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=color;
\r
54 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=color;
\r
55 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=color;
\r
56 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=color;
\r
57 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=color;
\r
58 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=color;
\r
59 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=color;
\r
65 // draws white text to current bbp15 screen
\r
66 void gp2x_text_out15(int x, int y, const char *text)
\r
69 unsigned short *screen = gp2x_screen;
\r
71 screen = screen + x + y*320;
\r
73 for (i = 0; i < strlen(text); i++)
\r
77 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;
\r
78 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;
\r
79 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;
\r
80 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;
\r
81 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;
\r
82 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;
\r
83 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;
\r
84 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;
\r
91 void gp2x_text_out8(int x, int y, const char *texto, ...)
\r
96 va_start(args,texto);
\r
97 vsprintf(buffer,texto,args);
\r
100 gp2x_text(gp2x_screen,x,y,buffer,0xf0);
\r
104 void gp2x_text_out8_2(int x, int y, const char *texto, int color)
\r
106 gp2x_text(gp2x_screen, x, y, texto, color);
\r
109 void gp2x_text_out8_lim(int x, int y, const char *texto, int max)
\r
111 char buffer[320/8+1];
\r
113 strncpy(buffer, texto, 320/8);
\r
114 if (max > 320/8) max = 320/8;
\r
115 if (max < 0) max = 0;
\r
118 gp2x_text(gp2x_screen,x,y,buffer,0xf0);
\r
121 static void gp2x_smalltext8(int x, int y, const char *texto)
\r
124 unsigned char *src, *dst;
\r
126 for (i = 0;; i++, x += 6)
\r
128 unsigned char c = (unsigned char) texto[i];
\r
133 src = fontdata6x8[c];
\r
134 dst = (unsigned char *)gp2x_screen + x + y*320;
\r
141 if( *src & w ) *dst = 0xf0;
\r
152 static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)
\r
154 char buffer[320/6+1];
\r
156 strncpy(buffer, texto, 320/6);
\r
157 if (max > 320/6) max = 320/6;
\r
158 if (max < 0) max = 0;
\r
161 gp2x_smalltext8(x, y, buffer);
\r
165 static unsigned long inp_prev = 0;
\r
166 static int inp_prevjoy = 0;
\r
168 static unsigned long wait_for_input(unsigned long interesting)
\r
171 static int repeats = 0, wait = 300*1000;
\r
172 int release = 0, i;
\r
174 if (repeats == 5 || repeats == 15 || repeats == 30) wait /= 2;
\r
176 for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {
\r
177 if(i == 0) repeats++;
\r
181 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
\r
186 if (release || ret != inp_prev) {
\r
193 // we don't need diagonals in menus
\r
194 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
195 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
196 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
197 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
202 static unsigned long input2_read(unsigned long interesting, int *joy)
\r
210 if ((ret = gp2x_joystick_read(0) & interesting)) break;
\r
211 gp2x_usbjoy_update();
\r
212 for (i = 0; i < num_of_joys; i++) {
\r
213 ret = gp2x_usbjoy_check2(i);
\r
214 if (ret) { *joy = i + 1; break; }
\r
223 // similar to wait_for_input(), but returns joy num
\r
224 static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
\r
227 const int wait = 300*1000;
\r
230 if (inp_prevjoy == 0) inp_prev &= interesting;
\r
231 for (i = 0; i < 6; i++) {
\r
232 ret = input2_read(interesting, joy);
\r
233 if (*joy != inp_prevjoy || ret != inp_prev) break;
\r
237 while ( !(ret = input2_read(interesting, joy)) ) {
\r
242 inp_prevjoy = *joy;
\r
249 // -------------- ROM selector --------------
\r
251 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
256 n--; // exclude current dir (".")
\r
258 //memset(gp2x_screen, 0, 320*240);
\r
259 gp2x_pd_clone_buffer2();
\r
262 gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);
\r
263 for (i = 0; i < n; i++) {
\r
265 if (pos < 0) continue;
\r
266 if (pos > 23) break;
\r
267 if (namelist[i+1]->d_type == DT_DIR) {
\r
268 gp2x_smalltext8_lim(14, pos*10, "/", 1);
\r
269 gp2x_smalltext8_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);
\r
271 gp2x_smalltext8_lim(14, pos*10, namelist[i+1]->d_name, 53-2);
\r
274 gp2x_text_out8(5, 120, ">");
\r
275 gp2x_video_flip2();
\r
278 static int scandir_cmp(const void *p1, const void *p2)
\r
280 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
281 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
282 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
283 if ((*d2)->d_type == DT_DIR) return 1;
\r
284 return alphasort(d1, d2);
\r
288 static char *romsel_loop(char *curr_path)
\r
290 struct dirent **namelist;
\r
293 unsigned long inp = 0;
\r
294 char *ret = NULL, *fname = NULL;
\r
296 // is this a dir or a full path?
\r
297 if ((dir = opendir(curr_path))) {
\r
301 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
306 n = scandir(curr_path, &namelist, 0, scandir_cmp);
\r
309 n = scandir(curr_path, &namelist, 0, scandir_cmp);
\r
312 printf("dir: "); printf(curr_path); printf("\n");
\r
319 if (fname != NULL) {
\r
321 for (i = 1; i < n; i++) {
\r
322 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
331 draw_dirlist(curr_path, namelist, n, sel);
\r
332 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
333 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
334 if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
335 if(inp &(GP2X_LEFT|GP2X_L)) { sel-=10; if (sel < 0) sel = 0; }
\r
336 if(inp &(GP2X_RIGHT|GP2X_R)) { sel+=10; if (sel > n-2) sel = n-2; }
\r
337 if(inp & GP2X_B) { // enter dir/select
\r
339 if (namelist[sel+1]->d_type == DT_REG) {
\r
340 strcpy(romFileName, curr_path);
\r
341 strcat(romFileName, "/");
\r
342 strcat(romFileName, namelist[sel+1]->d_name);
\r
345 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
346 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
347 char *p, *newdir = malloc(newlen);
\r
348 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
349 char *start = curr_path;
\r
350 p = start + strlen(start) - 1;
\r
351 while (*p == '/' && p > start) p--;
\r
352 while (*p != '/' && p > start) p--;
\r
353 if (p <= start) strcpy(newdir, "/");
\r
354 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
356 strcpy(newdir, curr_path);
\r
357 p = newdir + strlen(newdir) - 1;
\r
358 while (*p == '/' && p >= newdir) *p-- = 0;
\r
359 strcat(newdir, "/");
\r
360 strcat(newdir, namelist[sel+1]->d_name);
\r
362 ret = romsel_loop(newdir);
\r
366 // unknown file type, happens on NTFS mounts. Try to guess.
\r
367 FILE *tstf; int tmp;
\r
368 strcpy(romFileName, curr_path);
\r
369 strcat(romFileName, "/");
\r
370 strcat(romFileName, namelist[sel+1]->d_name);
\r
371 tstf = fopen(romFileName, "rb");
\r
374 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
375 namelist[sel+1]->d_type = DT_REG;
\r
376 else namelist[sel+1]->d_type = DT_DIR;
\r
382 if(inp & GP2X_X) break; // cancel
\r
386 while(n--) free(namelist[n]);
\r
393 // -------------- key config --------------
\r
395 static char *usb_joy_key_name(int joy, int num)
\r
397 static char name[16];
\r
400 case 0: sprintf(name, "Joy%i UP", joy); break;
\r
401 case 1: sprintf(name, "Joy%i DOWN", joy); break;
\r
402 case 2: sprintf(name, "Joy%i LEFT", joy); break;
\r
403 case 3: sprintf(name, "Joy%i RIGHT", joy); break;
\r
404 default:sprintf(name, "Joy%i b%i", joy, num-3); break;
\r
409 static void draw_key_config(int curr_act, int is_p2)
\r
411 char strkeys[32*5];
\r
415 for (i = 0; i < 32; i++)
\r
417 if (currentConfig.KeyBinds[i] & (1 << curr_act))
\r
419 if (curr_act < 16 && (currentConfig.KeyBinds[i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
420 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }
\r
421 else strcpy(strkeys, gp2xKeyNames[i]);
\r
424 for (joy = 0; joy < num_of_joys; joy++)
\r
426 for (i = 0; i < 32; i++)
\r
428 if (currentConfig.JoyBinds[joy][i] & (1 << curr_act))
\r
430 if (curr_act < 16 && (currentConfig.JoyBinds[joy][i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
432 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
\r
435 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
\r
440 //memset(gp2x_screen, 0, 320*240);
\r
441 gp2x_pd_clone_buffer2();
\r
442 gp2x_text_out8(60, 40, "Action: %s", actionNames[curr_act]);
\r
443 gp2x_text_out8(60, 60, "Keys: %s", strkeys);
\r
445 gp2x_text_out8(30, 180, "Use SELECT to change action");
\r
446 gp2x_text_out8(30, 190, "Press a key to bind/unbind");
\r
447 gp2x_text_out8(30, 200, "Select \"Done\" action and");
\r
448 gp2x_text_out8(30, 210, " press any key to finish");
\r
449 gp2x_video_flip2();
\r
452 static void key_config_loop(int is_p2)
\r
454 int curr_act = 0, joy = 0, i;
\r
455 unsigned long inp = 0;
\r
459 draw_key_config(curr_act, is_p2);
\r
460 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);
\r
461 // printf("got %08lX from joy %i\n", inp, joy);
\r
463 if (inp & GP2X_SELECT) {
\r
465 while (!actionNames[curr_act] && curr_act < 32) curr_act++;
\r
466 if (curr_act > 31) curr_act = 0;
\r
468 inp &= CONFIGURABLE_KEYS;
\r
469 inp &= ~GP2X_SELECT;
\r
471 if (curr_act == 31 && inp) break;
\r
473 for (i = 0; i < 32; i++)
\r
474 if (inp & (1 << i)) {
\r
475 currentConfig.KeyBinds[i] ^= (1 << curr_act);
\r
476 if (is_p2) currentConfig.KeyBinds[i] |= (1 << 16); // player 2 flag
\r
477 else currentConfig.KeyBinds[i] &= ~(1 << 16);
\r
480 for (i = 0; i < 32; i++)
\r
481 if (inp & (1 << i)) {
\r
482 currentConfig.JoyBinds[joy-1][i] ^= (1 << curr_act);
\r
483 if (is_p2) currentConfig.JoyBinds[joy-1][i] |= (1 << 16);
\r
484 else currentConfig.JoyBinds[joy-1][i] &= ~(1 << 16);
\r
490 static void draw_kc_sel(int menu_sel)
\r
492 int tl_x = 25+40, tl_y = 60, y, i;
\r
496 //memset(gp2x_screen, 0, 320*240);
\r
497 gp2x_pd_clone_buffer2();
\r
498 gp2x_text_out8(tl_x, y, "Player 1");
\r
499 gp2x_text_out8(tl_x, (y+=10), "Player 2");
\r
500 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
503 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
506 gp2x_text_out8(tl_x, (y=110), "USB joys detected:");
\r
507 if (num_of_joys > 0) {
\r
508 for (i = 0; i < num_of_joys; i++) {
\r
509 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
\r
510 gp2x_text_out8(tl_x, (y+=10), "%i: %s", i+1, joyname);
\r
513 gp2x_text_out8(tl_x, (y+=10), "none");
\r
517 gp2x_video_flip2();
\r
520 static void kc_sel_loop(void)
\r
522 int menu_sel = 2, menu_sel_max = 2;
\r
523 unsigned long inp = 0;
\r
527 draw_kc_sel(menu_sel);
\r
528 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
529 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
530 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
532 switch (menu_sel) {
\r
533 case 0: key_config_loop(0); return;
\r
534 case 1: key_config_loop(1); return;
\r
538 if(inp & GP2X_X) return;
\r
544 // --------- sega/mega cd options ----------
\r
546 static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp)
\r
548 int tl_x = 25, tl_y = 60, y;
\r
551 //memset(gp2x_screen, 0, 320*240);
\r
552 gp2x_pd_clone_buffer2();
\r
554 gp2x_text_out8(tl_x, y, "USA BIOS: %s", b_us); // 0
\r
555 gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1
\r
556 gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2
\r
557 gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x400)?"ON":"OFF"); // 3
\r
558 gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x800)?"ON":"OFF"); // 4
\r
559 gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x400)?"ON":"OFF"); // 5
\r
560 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
563 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
565 if ((menu_sel == 0 && strcmp(b_us, "NOT FOUND")) ||
\r
566 (menu_sel == 1 && strcmp(b_eu, "NOT FOUND")) ||
\r
567 (menu_sel == 2 && strcmp(b_jp, "NOT FOUND")))
\r
568 gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");
\r
570 gp2x_video_flip2();
\r
573 static void cd_menu_loop_options(void)
\r
575 int menu_sel = 0, menu_sel_max = 6;
\r
576 unsigned long inp = 0;
\r
577 char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;
\r
579 if (find_bios(4, &bios)) { // US
\r
580 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
581 strncpy(bios_us, p, 31); bios_us[31] = 0;
\r
582 } else strcpy(bios_us, "NOT FOUND");
\r
584 if (find_bios(8, &bios)) { // EU
\r
585 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
586 strncpy(bios_eu, p, 31); bios_eu[31] = 0;
\r
587 } else strcpy(bios_eu, "NOT FOUND");
\r
589 if (find_bios(1, &bios)) { // JP
\r
590 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
591 strncpy(bios_jp, p, 31); bios_jp[31] = 0;
\r
592 } else strcpy(bios_jp, "NOT FOUND");
\r
596 draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp);
\r
597 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);
\r
598 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
599 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
600 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
601 switch (menu_sel) {
\r
602 case 3: currentConfig.EmuOpt ^=0x400; break;
\r
603 case 4: currentConfig.PicoOpt^=0x800; break;
\r
604 case 5: currentConfig.PicoOpt^=0x400; break;
\r
608 if(inp & (GP2X_X|GP2X_A)) return;
\r
609 if(inp & GP2X_START) { // BIOS testers
\r
610 switch (menu_sel) {
\r
611 case 0: if (find_bios(4, &bios)) { // test US
\r
612 strcpy(romFileName, bios);
\r
613 engineState = PGS_ReloadRom;
\r
617 case 1: if (find_bios(8, &bios)) { // test EU
\r
618 strcpy(romFileName, bios);
\r
619 engineState = PGS_ReloadRom;
\r
623 case 2: if (find_bios(1, &bios)) { // test JP
\r
624 strcpy(romFileName, bios);
\r
625 engineState = PGS_ReloadRom;
\r
635 // --------- advanced options ----------
\r
637 static void draw_amenu_options(int menu_sel)
\r
639 int tl_x = 25, tl_y = 60, y;
\r
640 char *mms = mmuhack_status ? "active) " : "inactive)";
\r
643 //memset(gp2x_screen, 0, 320*240);
\r
644 gp2x_pd_clone_buffer2();
\r
646 gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (currentConfig.PicoOpt&0x100)?"ON":"OFF"); // 0
\r
647 gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 1
\r
648 gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (currentConfig.PicoOpt&0x004)?"ON":"OFF"); // 2
\r
649 gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (currentConfig.PicoOpt&0x001)?"ON":"OFF"); // 3
\r
650 gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (currentConfig.PicoOpt&0x002)?"ON":"OFF"); // 4
\r
651 gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (currentConfig.EmuOpt &0x008)?"ON":"OFF"); // 5
\r
652 gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 6
\r
653 gp2x_text_out8(tl_x, (y+=10), "needs restart:");
\r
654 gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 8
\r
655 gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 9
\r
656 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
659 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
661 gp2x_video_flip2();
\r
664 static void amenu_loop_options(void)
\r
666 int menu_sel = 0, menu_sel_max = 10;
\r
667 unsigned long inp = 0;
\r
671 draw_amenu_options(menu_sel);
\r
672 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
673 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
674 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
675 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
676 switch (menu_sel) {
\r
677 case 0: currentConfig.PicoOpt^=0x100; break;
\r
678 case 2: currentConfig.PicoOpt^=0x004; break;
\r
679 case 3: currentConfig.PicoOpt^=0x001; break;
\r
680 case 4: currentConfig.PicoOpt^=0x002; break;
\r
681 case 5: currentConfig.EmuOpt ^=0x008; break;
\r
682 case 6: currentConfig.EmuOpt ^=0x020; break;
\r
683 case 8: currentConfig.EmuOpt ^=0x100; break;
\r
684 case 9: currentConfig.EmuOpt ^=0x010; break;
\r
688 if(inp & (GP2X_X|GP2X_A)) return;
\r
689 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
690 switch (menu_sel) {
\r
692 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
693 currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;
\r
694 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
695 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
696 draw_amenu_options(menu_sel);
\r
705 // -------------- options --------------
\r
707 static const char *region_name(unsigned int code)
\r
709 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
\r
710 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
\r
714 while((code >>= 1)) i++;
\r
715 if (i > 4) return "unknown";
\r
718 static char name[24];
\r
719 strcpy(name, "Auto:");
\r
720 for (u = 0; u < 3; u++) {
\r
721 i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;
\r
722 while((code >>= 1)) i++;
\r
723 strcat(name, names_short[i]);
\r
729 static void draw_menu_options(int menu_sel)
\r
731 int tl_x = 25, tl_y = 40, y;
\r
732 char monostereo[8], strframeskip[8], *strrend;
\r
734 strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");
\r
735 if (currentConfig.Frameskip < 0)
\r
736 strcpy(strframeskip, "Auto");
\r
737 else sprintf(strframeskip, "%i", currentConfig.Frameskip);
\r
738 if (currentConfig.PicoOpt&0x10) {
\r
739 strrend = " 8bit fast";
\r
740 } else if (currentConfig.EmuOpt&0x80) {
\r
741 strrend = "16bit accurate";
\r
743 strrend = " 8bit accurate";
\r
747 //memset(gp2x_screen, 0, 320*240);
\r
748 gp2x_pd_clone_buffer2();
\r
750 gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0
\r
751 gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (currentConfig.PicoOpt&0x040)?"ON":"OFF"); // 1
\r
752 gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (currentConfig.PicoOpt&0x080)?"ON":"OFF"); // 2
\r
753 gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (currentConfig.EmuOpt &0x002)?"ON":"OFF"); // 3
\r
754 gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip);
\r
755 gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (currentConfig.EmuOpt &0x004)?"ON":"OFF"); // 5
\r
756 gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", currentConfig.PsndRate, monostereo);
\r
757 gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (currentConfig.PicoOpt&0x200)?"ON":"OFF"); // 7
\r
758 gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (currentConfig.PicoOpt&0x020)?"ON":"OFF"); // 8
\r
759 gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(currentConfig.PicoRegion));
\r
760 gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (currentConfig.EmuOpt &0x001)?"ON":"OFF"); // 10
\r
761 gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (currentConfig.EmuOpt &0x200)?"ON":"OFF"); // 11
\r
762 gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12
\r
763 gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", currentConfig.CPUclock);
\r
764 gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]");
\r
765 gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15
\r
766 gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");
\r
768 gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");
\r
771 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
773 gp2x_video_flip2();
\r
776 static int sndrate_prevnext(int rate, int dir)
\r
778 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
780 for (i = 0; i < 5; i++)
\r
781 if (rates[i] == rate) break;
\r
784 if (i > 4) return dir ? 44100 : 22050;
\r
785 if (i < 0) return dir ? 11025 : 8000;
\r
789 static void region_prevnext(int right)
\r
791 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
792 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
795 if (!currentConfig.PicoRegion) {
\r
796 for (i = 0; i < 6; i++)
\r
797 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
798 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
799 else currentConfig.PicoRegion=1;
\r
801 else currentConfig.PicoRegion<<=1;
\r
802 if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;
\r
804 if (!currentConfig.PicoRegion) {
\r
805 for (i = 0; i < 6; i++)
\r
806 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
807 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
809 else currentConfig.PicoRegion>>=1;
\r
813 static void menu_options_save(void)
\r
815 PicoOpt = currentConfig.PicoOpt;
\r
816 PsndRate = currentConfig.PsndRate;
\r
817 PicoRegionOverride = currentConfig.PicoRegion;
\r
818 if (PicoOpt & 0x20) {
\r
819 actionNames[ 8] = "Z"; actionNames[ 9] = "Y";
\r
820 actionNames[10] = "X"; actionNames[11] = "MODE";
\r
822 actionNames[8] = actionNames[9] = actionNames[10] = actionNames[11] = 0;
\r
826 static int menu_loop_options(void)
\r
828 int menu_sel = 0, menu_sel_max = 16;
\r
829 unsigned long inp = 0;
\r
831 if (rom_data) menu_sel_max++;
\r
832 currentConfig.PicoOpt = PicoOpt;
\r
833 currentConfig.PsndRate = PsndRate;
\r
834 currentConfig.PicoRegion = PicoRegionOverride;
\r
838 draw_menu_options(menu_sel);
\r
839 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
840 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
841 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
842 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
843 switch (menu_sel) {
\r
844 case 1: currentConfig.PicoOpt^=0x040; break;
\r
845 case 2: currentConfig.PicoOpt^=0x080; break;
\r
846 case 3: currentConfig.EmuOpt ^=0x002; break;
\r
847 case 5: currentConfig.EmuOpt ^=0x004; break;
\r
848 case 7: currentConfig.PicoOpt^=0x200; break;
\r
849 case 8: currentConfig.PicoOpt^=0x020; break;
\r
850 case 10: currentConfig.EmuOpt ^=0x001; break;
\r
851 case 11: currentConfig.EmuOpt ^=0x200; break;
\r
852 case 14: cd_menu_loop_options();
\r
853 if (engineState == PGS_ReloadRom)
\r
854 return 0; // test BIOS
\r
856 case 15: amenu_loop_options(); break;
\r
857 case 16: // done (update and write)
\r
858 menu_options_save();
\r
859 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
860 else strcpy(menuErrorMsg, "failed to write config");
\r
862 case 17: // done (update and write for current game)
\r
863 menu_options_save();
\r
864 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
865 else strcpy(menuErrorMsg, "failed to write config");
\r
869 if(inp & (GP2X_X|GP2X_A)) {
\r
870 menu_options_save();
\r
871 return 0; // done (update, no write)
\r
873 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
874 switch (menu_sel) {
\r
876 if (inp & GP2X_LEFT) {
\r
877 if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;
\r
878 else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;
\r
879 else if ( currentConfig.EmuOpt &0x80) break;
\r
881 if ( currentConfig.PicoOpt&0x10) break;
\r
882 else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;
\r
883 else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;
\r
887 currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;
\r
888 if (currentConfig.Frameskip < 0) currentConfig.Frameskip = -1;
\r
889 if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32;
\r
892 if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {
\r
893 currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;
\r
894 } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {
\r
895 currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;
\r
896 } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);
\r
899 region_prevnext(inp & GP2X_RIGHT);
\r
902 if (inp & GP2X_RIGHT) {
\r
903 state_slot++; if (state_slot > 9) state_slot = 0;
\r
904 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
908 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
909 currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;
\r
910 if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;
\r
911 draw_menu_options(menu_sel);
\r
920 // -------------- credits --------------
\r
922 static void draw_menu_credits(void)
\r
924 int tl_x = 15, tl_y = 70, y;
\r
925 //memset(gp2x_screen, 0, 320*240);
\r
926 gp2x_pd_clone_buffer2();
\r
928 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");
\r
930 gp2x_text_out8(tl_x, y, "Credits:");
\r
931 gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");
\r
932 gp2x_text_out8(tl_x, (y+=10), " base code of PicoDrive");
\r
933 gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
934 gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
935 gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
\r
936 gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");
\r
937 gp2x_text_out8(tl_x, (y+=10), " opensource Gens");
\r
938 gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");
\r
939 gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");
\r
940 gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");
\r
941 gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");
\r
942 gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");
\r
943 gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");
\r
945 gp2x_video_flip2();
\r
949 // -------------- root menu --------------
\r
951 static void draw_menu_root(int menu_sel)
\r
953 int tl_x = 70, tl_y = 70, y;
\r
954 //memset(gp2x_screen, 0, 320*240);
\r
955 gp2x_pd_clone_buffer2();
\r
957 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);
\r
961 gp2x_text_out8(tl_x, y, "Resume game");
\r
962 gp2x_text_out8(tl_x, (y+=10), "Save State");
\r
963 gp2x_text_out8(tl_x, (y+=10), "Load State");
\r
964 gp2x_text_out8(tl_x, (y+=10), "Reset game");
\r
968 gp2x_text_out8(tl_x, (y+=10), "Load new ROM/ISO");
\r
969 gp2x_text_out8(tl_x, (y+=10), "Change options");
\r
970 gp2x_text_out8(tl_x, (y+=10), "Configure controls");
\r
971 gp2x_text_out8(tl_x, (y+=10), "Credits");
\r
972 gp2x_text_out8(tl_x, (y+=10), "Exit");
\r
975 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
977 if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);
\r
978 gp2x_video_flip2();
\r
982 static void menu_loop_root(void)
\r
984 int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;
\r
985 unsigned long inp = 0;
\r
986 char curr_path[PATH_MAX], *selfname;
\r
989 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
992 strcpy(curr_path, currentConfig.lastRomFile);
\r
996 getcwd(curr_path, PATH_MAX);
\r
999 if (rom_data) menu_sel = menu_sel_min = 0;
\r
1003 draw_menu_root(menu_sel);
\r
1004 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT);
\r
1005 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }
\r
1006 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }
\r
1007 if(inp &(GP2X_SELECT|GP2X_X)){
\r
1009 while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released
\r
1010 engineState = PGS_Running;
\r
1014 if(inp & GP2X_B ) {
\r
1015 switch (menu_sel) {
\r
1016 case 0: // resume game
\r
1017 if (rom_data) { engineState = PGS_Running; return; }
\r
1019 case 1: // save state
\r
1021 if(emu_SaveLoadGame(0, 0)) {
\r
1022 strcpy(menuErrorMsg, "save failed");
\r
1025 engineState = PGS_Running;
\r
1029 case 2: // load state
\r
1031 if(emu_SaveLoadGame(1, 0)) {
\r
1032 strcpy(menuErrorMsg, "load failed");
\r
1035 engineState = PGS_Running;
\r
1039 case 3: // reset game
\r
1042 engineState = PGS_Running;
\r
1046 case 4: // select rom
\r
1047 selfname = romsel_loop(curr_path);
\r
1049 printf("selected file: %s\n", selfname);
\r
1050 engineState = PGS_ReloadRom;
\r
1053 case 5: // options
\r
1054 ret = menu_loop_options();
\r
1055 if (ret == 1) continue; // status update
\r
1056 if (engineState == PGS_ReloadRom)
\r
1057 return; // BIOS test
\r
1059 case 6: // controls
\r
1062 case 7: // credits
\r
1063 draw_menu_credits();
\r
1065 inp = wait_for_input(GP2X_B|GP2X_X);
\r
1068 engineState = PGS_Quit;
\r
1072 menuErrorMsg[0] = 0; // clear error msg
\r
1077 static void menu_gfx_prepare(void)
\r
1079 extern int localPal[0x100];
\r
1082 // don't clear old palette just for fun (but make it dark)
\r
1083 for (i = 0x100-1; i >= 0; i--)
\r
1084 localPal[i] = (localPal[i] >> 2) & 0x003f3f3f;
\r
1085 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
1086 localPal[0xf0] = 0x00ffffff;
\r
1089 gp2x_video_changemode2(8);
\r
1090 gp2x_video_RGB_setscaling(320, 240);
\r
1091 gp2x_video_setpalette(localPal, 0x100);
\r
1092 gp2x_video_flip2();
\r
1096 void menu_loop(void)
\r
1098 menu_gfx_prepare();
\r
1102 menuErrorMsg[0] = 0;
\r