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
21 #include "zlib/zlib.h"
\r
23 #ifndef _DIRENT_HAVE_D_TYPE
\r
24 #error "need d_type for file browser
\r
27 extern char *actionNames[];
\r
28 extern char romFileName[PATH_MAX];
\r
29 extern char *rom_data;
\r
30 extern int mmuhack_status;
\r
31 extern int state_slot;
\r
33 static char *gp2xKeyNames[] = {
\r
34 "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",
\r
35 "START", "SELECT", "L", "R", "A", "B", "X", "Y",
\r
36 "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",
\r
37 "???", "???", "???", "PUSH", "???", "???", "???", "???"
\r
40 char menuErrorMsg[40] = {0, };
\r
43 static void gp2x_text(unsigned char *screen, int x, int y, const char *text, int color)
\r
47 screen = screen + x + y*320;
\r
49 for (i = 0; i < strlen(text); i++)
\r
53 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=color;
\r
54 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=color;
\r
55 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=color;
\r
56 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=color;
\r
57 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=color;
\r
58 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=color;
\r
59 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=color;
\r
60 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=color;
\r
66 // draws white text to current bbp15 screen
\r
67 void gp2x_text_out15(int x, int y, const char *text)
\r
70 unsigned short *screen = gp2x_screen;
\r
72 screen = screen + x + y*320;
\r
74 for (i = 0; i < strlen(text); i++)
\r
78 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;
\r
79 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;
\r
80 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;
\r
81 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;
\r
82 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;
\r
83 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;
\r
84 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;
\r
85 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;
\r
92 void gp2x_text_out8(int x, int y, const char *texto, ...)
\r
97 va_start(args,texto);
\r
98 vsprintf(buffer,texto,args);
\r
101 gp2x_text(gp2x_screen,x,y,buffer,0xf0);
\r
105 void gp2x_text_out8_2(int x, int y, const char *texto, int color)
\r
107 gp2x_text(gp2x_screen, x, y, texto, color);
\r
110 void gp2x_text_out8_lim(int x, int y, const char *texto, int max)
\r
112 char buffer[320/8+1];
\r
114 strncpy(buffer, texto, 320/8);
\r
115 if (max > 320/8) max = 320/8;
\r
116 if (max < 0) max = 0;
\r
119 gp2x_text(gp2x_screen,x,y,buffer,0xf0);
\r
122 static void gp2x_smalltext8(int x, int y, const char *texto)
\r
125 unsigned char *src, *dst;
\r
127 for (i = 0;; i++, x += 6)
\r
129 unsigned char c = (unsigned char) texto[i];
\r
134 src = fontdata6x8[c];
\r
135 dst = (unsigned char *)gp2x_screen + x + y*320;
\r
142 if( *src & w ) *dst = 0xf0;
\r
153 static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)
\r
155 char buffer[320/6+1];
\r
157 strncpy(buffer, texto, 320/6);
\r
158 if (max > 320/6) max = 320/6;
\r
159 if (max < 0) max = 0;
\r
162 gp2x_smalltext8(x, y, buffer);
\r
166 static unsigned long inp_prev = 0;
\r
167 static int inp_prevjoy = 0;
\r
169 static unsigned long wait_for_input(unsigned long interesting)
\r
172 static int repeats = 0, wait = 300*1000;
\r
173 int release = 0, i;
\r
175 if (repeats == 5 || repeats == 15 || repeats == 30) wait /= 2;
\r
177 for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {
\r
178 if(i == 0) repeats++;
\r
182 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
\r
187 if (release || ret != inp_prev) {
\r
194 // we don't need diagonals in menus
\r
195 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
196 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
197 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
198 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
203 static unsigned long input2_read(unsigned long interesting, int *joy)
\r
211 if ((ret = gp2x_joystick_read(0) & interesting)) break;
\r
212 gp2x_usbjoy_update();
\r
213 for (i = 0; i < num_of_joys; i++) {
\r
214 ret = gp2x_usbjoy_check2(i);
\r
215 if (ret) { *joy = i + 1; break; }
\r
224 // similar to wait_for_input(), but returns joy num
\r
225 static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
\r
228 const int wait = 300*1000;
\r
231 if (inp_prevjoy == 0) inp_prev &= interesting;
\r
232 for (i = 0; i < 6; i++) {
\r
233 ret = input2_read(interesting, joy);
\r
234 if (*joy != inp_prevjoy || ret != inp_prev) break;
\r
238 while ( !(ret = input2_read(interesting, joy)) ) {
\r
243 inp_prevjoy = *joy;
\r
250 // -------------- ROM selector --------------
\r
252 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
257 n--; // exclude current dir (".")
\r
259 //memset(gp2x_screen, 0, 320*240);
\r
260 gp2x_pd_clone_buffer2();
\r
263 gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);
\r
264 for (i = 0; i < n; i++) {
\r
266 if (pos < 0) continue;
\r
267 if (pos > 23) break;
\r
268 if (namelist[i+1]->d_type == DT_DIR) {
\r
269 gp2x_smalltext8_lim(14, pos*10, "/", 1);
\r
270 gp2x_smalltext8_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);
\r
272 gp2x_smalltext8_lim(14, pos*10, namelist[i+1]->d_name, 53-2);
\r
275 gp2x_text_out8(5, 120, ">");
\r
276 gp2x_video_flip2();
\r
279 static int scandir_cmp(const void *p1, const void *p2)
\r
281 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
282 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
283 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
284 if ((*d2)->d_type == DT_DIR) return 1;
\r
285 return alphasort(d1, d2);
\r
289 static char *romsel_loop(char *curr_path)
\r
291 struct dirent **namelist;
\r
294 unsigned long inp = 0;
\r
295 char *ret = NULL, *fname = NULL;
\r
297 // is this a dir or a full path?
\r
298 if ((dir = opendir(curr_path))) {
\r
302 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
307 n = scandir(curr_path, &namelist, 0, scandir_cmp);
\r
310 n = scandir(curr_path, &namelist, 0, scandir_cmp);
\r
313 printf("dir: "); printf(curr_path); printf("\n");
\r
320 if (fname != NULL) {
\r
322 for (i = 1; i < n; i++) {
\r
323 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
332 draw_dirlist(curr_path, namelist, n, sel);
\r
333 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
334 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
335 if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
336 if(inp &(GP2X_LEFT|GP2X_L)) { sel-=10; if (sel < 0) sel = 0; }
\r
337 if(inp &(GP2X_RIGHT|GP2X_R)) { sel+=10; if (sel > n-2) sel = n-2; }
\r
338 if(inp & GP2X_B) { // enter dir/select
\r
340 if (namelist[sel+1]->d_type == DT_REG) {
\r
341 strcpy(romFileName, curr_path);
\r
342 strcat(romFileName, "/");
\r
343 strcat(romFileName, namelist[sel+1]->d_name);
\r
346 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
347 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
348 char *p, *newdir = malloc(newlen);
\r
349 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
350 char *start = curr_path;
\r
351 p = start + strlen(start) - 1;
\r
352 while (*p == '/' && p > start) p--;
\r
353 while (*p != '/' && p > start) p--;
\r
354 if (p <= start) strcpy(newdir, "/");
\r
355 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
357 strcpy(newdir, curr_path);
\r
358 p = newdir + strlen(newdir) - 1;
\r
359 while (*p == '/' && p >= newdir) *p-- = 0;
\r
360 strcat(newdir, "/");
\r
361 strcat(newdir, namelist[sel+1]->d_name);
\r
363 ret = romsel_loop(newdir);
\r
367 // unknown file type, happens on NTFS mounts. Try to guess.
\r
368 FILE *tstf; int tmp;
\r
369 strcpy(romFileName, curr_path);
\r
370 strcat(romFileName, "/");
\r
371 strcat(romFileName, namelist[sel+1]->d_name);
\r
372 tstf = fopen(romFileName, "rb");
\r
375 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
376 namelist[sel+1]->d_type = DT_REG;
\r
377 else namelist[sel+1]->d_type = DT_DIR;
\r
383 if(inp & GP2X_X) break; // cancel
\r
387 while(n--) free(namelist[n]);
\r
394 // ------------ savestate loader ------------
\r
396 static void menu_prepare_bg(void);
\r
398 static int state_slot_flags = 0;
\r
400 static void state_check_slots(void)
\r
404 state_slot_flags = 0;
\r
406 for (slot = 0; slot < 10; slot++)
\r
408 if (emu_check_save_file(slot))
\r
410 state_slot_flags |= 1 << slot;
\r
415 static void draw_savestate_bg(int slot)
\r
417 struct PicoVideo tmp_pv;
\r
418 unsigned short tmp_cram[0x40];
\r
419 unsigned short tmp_vsram[0x40];
\r
420 void *tmp_vram, *file;
\r
423 fname = emu_GetSaveFName(1, 0, slot);
\r
424 if (!fname) return;
\r
426 tmp_vram = malloc(sizeof(Pico.vram));
\r
427 if (tmp_vram == NULL) return;
\r
429 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
430 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
431 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
432 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
434 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
435 file = gzopen(fname, "rb");
\r
436 emu_set_save_cbs(1);
\r
438 file = fopen(fname, "rb");
\r
439 emu_set_save_cbs(0);
\r
444 PicoCdLoadStateGfx(file);
\r
446 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
447 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
448 areaSeek(file, 0x2000, SEEK_CUR);
\r
449 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
450 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
451 areaSeek(file, 0x221a0, SEEK_SET);
\r
452 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
457 emu_forced_frame();
\r
458 gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);
\r
461 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
462 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
463 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
464 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
468 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
470 int tl_x = 25, tl_y = 60, y, i;
\r
472 if (state_slot_flags & (1 << menu_sel))
\r
473 draw_savestate_bg(menu_sel);
\r
474 gp2x_pd_clone_buffer2();
\r
476 gp2x_text_out8(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
478 /* draw all 10 slots */
\r
480 for (i = 0; i < 10; i++, y+=10)
\r
482 gp2x_text_out8(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
484 gp2x_text_out8(tl_x, y, "back");
\r
487 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
489 gp2x_video_flip2();
\r
492 static int savestate_menu_loop(int is_loading)
\r
494 int menu_sel = 10, menu_sel_max = 10;
\r
495 unsigned long inp = 0;
\r
497 state_check_slots();
\r
501 draw_savestate_menu(menu_sel, is_loading);
\r
502 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
503 if(inp & GP2X_UP ) {
\r
505 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
506 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
508 if(inp & GP2X_DOWN) {
\r
510 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
511 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
513 if(inp & GP2X_B) { // save/load
\r
514 if (menu_sel < 10) {
\r
515 state_slot = menu_sel;
\r
516 if (emu_SaveLoadGame(is_loading, 0)) {
\r
517 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
523 if(inp & GP2X_X) return 1;
\r
527 // -------------- key config --------------
\r
529 static char *usb_joy_key_name(int joy, int num)
\r
531 static char name[16];
\r
534 case 0: sprintf(name, "Joy%i UP", joy); break;
\r
535 case 1: sprintf(name, "Joy%i DOWN", joy); break;
\r
536 case 2: sprintf(name, "Joy%i LEFT", joy); break;
\r
537 case 3: sprintf(name, "Joy%i RIGHT", joy); break;
\r
538 default:sprintf(name, "Joy%i b%i", joy, num-3); break;
\r
543 static void draw_key_config(int curr_act, int is_p2)
\r
545 char strkeys[32*5];
\r
549 for (i = 0; i < 32; i++)
\r
551 if (currentConfig.KeyBinds[i] & (1 << curr_act))
\r
553 if (curr_act < 16 && (currentConfig.KeyBinds[i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
554 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }
\r
555 else strcpy(strkeys, gp2xKeyNames[i]);
\r
558 for (joy = 0; joy < num_of_joys; joy++)
\r
560 for (i = 0; i < 32; i++)
\r
562 if (currentConfig.JoyBinds[joy][i] & (1 << curr_act))
\r
564 if (curr_act < 16 && (currentConfig.JoyBinds[joy][i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
566 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
\r
569 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
\r
574 //memset(gp2x_screen, 0, 320*240);
\r
575 gp2x_pd_clone_buffer2();
\r
576 gp2x_text_out8(60, 40, "Action: %s", actionNames[curr_act]);
\r
577 gp2x_text_out8(60, 60, "Keys: %s", strkeys);
\r
579 gp2x_text_out8(30, 180, "Use SELECT to change action");
\r
580 gp2x_text_out8(30, 190, "Press a key to bind/unbind");
\r
581 gp2x_text_out8(30, 200, "Select \"Done\" action and");
\r
582 gp2x_text_out8(30, 210, " press any key to finish");
\r
583 gp2x_video_flip2();
\r
586 static void key_config_loop(int is_p2)
\r
588 int curr_act = 0, joy = 0, i;
\r
589 unsigned long inp = 0;
\r
593 draw_key_config(curr_act, is_p2);
\r
594 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);
\r
595 // printf("got %08lX from joy %i\n", inp, joy);
\r
597 if (inp & GP2X_SELECT) {
\r
599 while (!actionNames[curr_act] && curr_act < 32) curr_act++;
\r
600 if (curr_act > 31) curr_act = 0;
\r
602 inp &= CONFIGURABLE_KEYS;
\r
603 inp &= ~GP2X_SELECT;
\r
605 if (curr_act == 31 && inp) break;
\r
607 for (i = 0; i < 32; i++)
\r
608 if (inp & (1 << i)) {
\r
609 currentConfig.KeyBinds[i] ^= (1 << curr_act);
\r
610 if (is_p2) currentConfig.KeyBinds[i] |= (1 << 16); // player 2 flag
\r
611 else currentConfig.KeyBinds[i] &= ~(1 << 16);
\r
614 for (i = 0; i < 32; i++)
\r
615 if (inp & (1 << i)) {
\r
616 currentConfig.JoyBinds[joy-1][i] ^= (1 << curr_act);
\r
617 if (is_p2) currentConfig.JoyBinds[joy-1][i] |= (1 << 16);
\r
618 else currentConfig.JoyBinds[joy-1][i] &= ~(1 << 16);
\r
624 static void draw_kc_sel(int menu_sel)
\r
626 int tl_x = 25+40, tl_y = 60, y, i;
\r
630 //memset(gp2x_screen, 0, 320*240);
\r
631 gp2x_pd_clone_buffer2();
\r
632 gp2x_text_out8(tl_x, y, "Player 1");
\r
633 gp2x_text_out8(tl_x, (y+=10), "Player 2");
\r
634 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
637 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
640 gp2x_text_out8(tl_x, (y=110), "USB joys detected:");
\r
641 if (num_of_joys > 0) {
\r
642 for (i = 0; i < num_of_joys; i++) {
\r
643 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
\r
644 gp2x_text_out8(tl_x, (y+=10), "%i: %s", i+1, joyname);
\r
647 gp2x_text_out8(tl_x, (y+=10), "none");
\r
651 gp2x_video_flip2();
\r
654 static void kc_sel_loop(void)
\r
656 int menu_sel = 2, menu_sel_max = 2;
\r
657 unsigned long inp = 0;
\r
661 draw_kc_sel(menu_sel);
\r
662 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
663 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
664 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
666 switch (menu_sel) {
\r
667 case 0: key_config_loop(0); return;
\r
668 case 1: key_config_loop(1); return;
\r
672 if(inp & GP2X_X) return;
\r
678 // --------- sega/mega cd options ----------
\r
680 static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp)
\r
682 int tl_x = 25, tl_y = 60, y;
\r
685 //memset(gp2x_screen, 0, 320*240);
\r
686 gp2x_pd_clone_buffer2();
\r
688 gp2x_text_out8(tl_x, y, "USA BIOS: %s", b_us); // 0
\r
689 gp2x_text_out8(tl_x, (y+=10), "EUR BIOS: %s", b_eu); // 1
\r
690 gp2x_text_out8(tl_x, (y+=10), "JAP BIOS: %s", b_jp); // 2
\r
691 gp2x_text_out8(tl_x, (y+=10), "CD LEDs %s", (currentConfig.EmuOpt &0x0400)?"ON":"OFF"); // 3
\r
692 gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s) %s", (currentConfig.PicoOpt&0x0800)?"ON":"OFF"); // 4
\r
693 gp2x_text_out8(tl_x, (y+=10), "PCM audio %s", (currentConfig.PicoOpt&0x0400)?"ON":"OFF"); // 5
\r
694 gp2x_text_out8(tl_x, (y+=10), "Better sync (very slow) %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 6
\r
695 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
698 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
700 if ((menu_sel == 0 && strcmp(b_us, "NOT FOUND")) ||
\r
701 (menu_sel == 1 && strcmp(b_eu, "NOT FOUND")) ||
\r
702 (menu_sel == 2 && strcmp(b_jp, "NOT FOUND")))
\r
703 gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");
\r
705 gp2x_video_flip2();
\r
708 static void cd_menu_loop_options(void)
\r
710 int menu_sel = 0, menu_sel_max = 7;
\r
711 unsigned long inp = 0;
\r
712 char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;
\r
714 if (find_bios(4, &bios)) { // US
\r
715 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
716 strncpy(bios_us, p, 31); bios_us[31] = 0;
\r
717 } else strcpy(bios_us, "NOT FOUND");
\r
719 if (find_bios(8, &bios)) { // EU
\r
720 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
721 strncpy(bios_eu, p, 31); bios_eu[31] = 0;
\r
722 } else strcpy(bios_eu, "NOT FOUND");
\r
724 if (find_bios(1, &bios)) { // JP
\r
725 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
726 strncpy(bios_jp, p, 31); bios_jp[31] = 0;
\r
727 } else strcpy(bios_jp, "NOT FOUND");
\r
731 draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp);
\r
732 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);
\r
733 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
734 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
735 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
736 switch (menu_sel) {
\r
737 case 3: currentConfig.EmuOpt ^=0x0400; break;
\r
738 case 4: currentConfig.PicoOpt^=0x0800; break;
\r
739 case 5: currentConfig.PicoOpt^=0x0400; break;
\r
740 case 6: currentConfig.PicoOpt^=0x2000; break;
\r
744 if(inp & (GP2X_X|GP2X_A)) return;
\r
745 if(inp & GP2X_START) { // BIOS testers
\r
746 switch (menu_sel) {
\r
747 case 0: if (find_bios(4, &bios)) { // test US
\r
748 strcpy(romFileName, bios);
\r
749 engineState = PGS_ReloadRom;
\r
753 case 1: if (find_bios(8, &bios)) { // test EU
\r
754 strcpy(romFileName, bios);
\r
755 engineState = PGS_ReloadRom;
\r
759 case 2: if (find_bios(1, &bios)) { // test JP
\r
760 strcpy(romFileName, bios);
\r
761 engineState = PGS_ReloadRom;
\r
771 // --------- advanced options ----------
\r
773 static void draw_amenu_options(int menu_sel)
\r
775 int tl_x = 25, tl_y = 60, y;
\r
776 char *mms = mmuhack_status ? "active) " : "inactive)";
\r
779 //memset(gp2x_screen, 0, 320*240);
\r
780 gp2x_pd_clone_buffer2();
\r
782 gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (currentConfig.PicoOpt&0x100)?"ON":"OFF"); // 0
\r
783 gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 1
\r
784 gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (currentConfig.PicoOpt&0x004)?"ON":"OFF"); // 2
\r
785 gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (currentConfig.PicoOpt&0x001)?"ON":"OFF"); // 3
\r
786 gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (currentConfig.PicoOpt&0x002)?"ON":"OFF"); // 4
\r
787 gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (currentConfig.EmuOpt &0x008)?"ON":"OFF"); // 5
\r
788 gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 6
\r
789 gp2x_text_out8(tl_x, (y+=10), "needs restart:");
\r
790 gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 8
\r
791 gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 9
\r
792 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
795 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
797 gp2x_video_flip2();
\r
800 static void amenu_loop_options(void)
\r
802 int menu_sel = 0, menu_sel_max = 10;
\r
803 unsigned long inp = 0;
\r
807 draw_amenu_options(menu_sel);
\r
808 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
809 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
810 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
811 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
812 switch (menu_sel) {
\r
813 case 0: currentConfig.PicoOpt^=0x100; break;
\r
814 case 2: currentConfig.PicoOpt^=0x004; break;
\r
815 case 3: currentConfig.PicoOpt^=0x001; break;
\r
816 case 4: currentConfig.PicoOpt^=0x002; break;
\r
817 case 5: currentConfig.EmuOpt ^=0x008; break;
\r
818 case 6: currentConfig.EmuOpt ^=0x020; break;
\r
819 case 8: currentConfig.EmuOpt ^=0x100; break;
\r
820 case 9: currentConfig.EmuOpt ^=0x010; break;
\r
824 if(inp & (GP2X_X|GP2X_A)) return;
\r
825 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
826 switch (menu_sel) {
\r
828 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
829 currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;
\r
830 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
831 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
832 draw_amenu_options(menu_sel);
\r
841 // -------------- options --------------
\r
843 static const char *region_name(unsigned int code)
\r
845 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
\r
846 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
\r
850 while((code >>= 1)) i++;
\r
851 if (i > 4) return "unknown";
\r
854 static char name[24];
\r
855 strcpy(name, "Auto:");
\r
856 for (u = 0; u < 3; u++) {
\r
857 i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;
\r
858 while((code >>= 1)) i++;
\r
859 strcat(name, names_short[i]);
\r
865 static void draw_menu_options(int menu_sel)
\r
867 int tl_x = 25, tl_y = 40, y;
\r
868 char monostereo[8], strframeskip[8], *strrend;
\r
870 strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");
\r
871 if (currentConfig.Frameskip < 0)
\r
872 strcpy(strframeskip, "Auto");
\r
873 else sprintf(strframeskip, "%i", currentConfig.Frameskip);
\r
874 if (currentConfig.PicoOpt&0x10) {
\r
875 strrend = " 8bit fast";
\r
876 } else if (currentConfig.EmuOpt&0x80) {
\r
877 strrend = "16bit accurate";
\r
879 strrend = " 8bit accurate";
\r
883 //memset(gp2x_screen, 0, 320*240);
\r
884 gp2x_pd_clone_buffer2();
\r
886 gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0
\r
887 gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (currentConfig.PicoOpt&0x040)?"ON":"OFF"); // 1
\r
888 gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (currentConfig.PicoOpt&0x080)?"ON":"OFF"); // 2
\r
889 gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (currentConfig.EmuOpt &0x002)?"ON":"OFF"); // 3
\r
890 gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip);
\r
891 gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (currentConfig.EmuOpt &0x004)?"ON":"OFF"); // 5
\r
892 gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", currentConfig.PsndRate, monostereo);
\r
893 gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (currentConfig.PicoOpt&0x200)?"ON":"OFF"); // 7
\r
894 gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (currentConfig.PicoOpt&0x020)?"ON":"OFF"); // 8
\r
895 gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(currentConfig.PicoRegion));
\r
896 gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates %s", (currentConfig.EmuOpt &0x001)?"ON":"OFF"); // 10
\r
897 gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (currentConfig.EmuOpt &0x200)?"ON":"OFF"); // 11
\r
898 gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12
\r
899 gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", currentConfig.CPUclock);
\r
900 gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]");
\r
901 gp2x_text_out8(tl_x, (y+=10), "[advanced options]"); // 15
\r
902 gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");
\r
904 gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");
\r
907 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
909 gp2x_video_flip2();
\r
912 static int sndrate_prevnext(int rate, int dir)
\r
914 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
916 for (i = 0; i < 5; i++)
\r
917 if (rates[i] == rate) break;
\r
920 if (i > 4) return dir ? 44100 : 22050;
\r
921 if (i < 0) return dir ? 11025 : 8000;
\r
925 static void region_prevnext(int right)
\r
927 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
928 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
931 if (!currentConfig.PicoRegion) {
\r
932 for (i = 0; i < 6; i++)
\r
933 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
934 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
935 else currentConfig.PicoRegion=1;
\r
937 else currentConfig.PicoRegion<<=1;
\r
938 if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;
\r
940 if (!currentConfig.PicoRegion) {
\r
941 for (i = 0; i < 6; i++)
\r
942 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
943 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
945 else currentConfig.PicoRegion>>=1;
\r
949 static void menu_options_save(void)
\r
951 PicoOpt = currentConfig.PicoOpt;
\r
952 PsndRate = currentConfig.PsndRate;
\r
953 PicoRegionOverride = currentConfig.PicoRegion;
\r
954 if (PicoOpt & 0x20) {
\r
955 actionNames[ 8] = "Z"; actionNames[ 9] = "Y";
\r
956 actionNames[10] = "X"; actionNames[11] = "MODE";
\r
958 actionNames[8] = actionNames[9] = actionNames[10] = actionNames[11] = 0;
\r
962 static int menu_loop_options(void)
\r
964 int menu_sel = 0, menu_sel_max = 16;
\r
965 unsigned long inp = 0;
\r
967 if (rom_data) menu_sel_max++;
\r
968 currentConfig.PicoOpt = PicoOpt;
\r
969 currentConfig.PsndRate = PsndRate;
\r
970 currentConfig.PicoRegion = PicoRegionOverride;
\r
974 draw_menu_options(menu_sel);
\r
975 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
976 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
977 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
978 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
979 switch (menu_sel) {
\r
980 case 1: currentConfig.PicoOpt^=0x040; break;
\r
981 case 2: currentConfig.PicoOpt^=0x080; break;
\r
982 case 3: currentConfig.EmuOpt ^=0x002; break;
\r
983 case 5: currentConfig.EmuOpt ^=0x004; break;
\r
984 case 7: currentConfig.PicoOpt^=0x200; break;
\r
985 case 8: currentConfig.PicoOpt^=0x020; break;
\r
986 case 10: currentConfig.EmuOpt ^=0x001; break;
\r
987 case 11: currentConfig.EmuOpt ^=0x200; break;
\r
988 case 14: cd_menu_loop_options();
\r
989 if (engineState == PGS_ReloadRom)
\r
990 return 0; // test BIOS
\r
992 case 15: amenu_loop_options(); break;
\r
993 case 16: // done (update and write)
\r
994 menu_options_save();
\r
995 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
996 else strcpy(menuErrorMsg, "failed to write config");
\r
998 case 17: // done (update and write for current game)
\r
999 menu_options_save();
\r
1000 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
1001 else strcpy(menuErrorMsg, "failed to write config");
\r
1005 if(inp & (GP2X_X|GP2X_A)) {
\r
1006 menu_options_save();
\r
1007 return 0; // done (update, no write)
\r
1009 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
1010 switch (menu_sel) {
\r
1012 if (inp & GP2X_LEFT) {
\r
1013 if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;
\r
1014 else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;
\r
1015 else if ( currentConfig.EmuOpt &0x80) break;
\r
1017 if ( currentConfig.PicoOpt&0x10) break;
\r
1018 else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;
\r
1019 else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;
\r
1023 currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;
\r
1024 if (currentConfig.Frameskip < 0) currentConfig.Frameskip = -1;
\r
1025 if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32;
\r
1028 if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {
\r
1029 currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;
\r
1030 } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {
\r
1031 currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;
\r
1032 } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);
\r
1035 region_prevnext(inp & GP2X_RIGHT);
\r
1038 if (inp & GP2X_RIGHT) {
\r
1039 state_slot++; if (state_slot > 9) state_slot = 0;
\r
1040 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
1044 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
1045 currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;
\r
1046 if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;
\r
1047 draw_menu_options(menu_sel);
\r
1056 // -------------- credits --------------
\r
1058 static void draw_menu_credits(void)
\r
1060 int tl_x = 15, tl_y = 70, y;
\r
1061 //memset(gp2x_screen, 0, 320*240);
\r
1062 gp2x_pd_clone_buffer2();
\r
1064 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");
\r
1066 gp2x_text_out8(tl_x, y, "Credits:");
\r
1067 gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");
\r
1068 gp2x_text_out8(tl_x, (y+=10), " base code of PicoDrive");
\r
1069 gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
1070 gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
1071 gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
\r
1072 gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");
\r
1073 gp2x_text_out8(tl_x, (y+=10), " opensource Gens");
\r
1074 gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");
\r
1075 gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");
\r
1076 gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");
\r
1077 gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");
\r
1078 gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");
\r
1079 gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");
\r
1081 gp2x_video_flip2();
\r
1085 // -------------- root menu --------------
\r
1087 static void draw_menu_root(int menu_sel)
\r
1089 int tl_x = 70, tl_y = 70, y;
\r
1090 //memset(gp2x_screen, 0, 320*240);
\r
1091 gp2x_pd_clone_buffer2();
\r
1093 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);
\r
1097 gp2x_text_out8(tl_x, y, "Resume game");
\r
1098 gp2x_text_out8(tl_x, (y+=10), "Save State");
\r
1099 gp2x_text_out8(tl_x, (y+=10), "Load State");
\r
1100 gp2x_text_out8(tl_x, (y+=10), "Reset game");
\r
1104 gp2x_text_out8(tl_x, (y+=10), "Load new ROM/ISO");
\r
1105 gp2x_text_out8(tl_x, (y+=10), "Change options");
\r
1106 gp2x_text_out8(tl_x, (y+=10), "Configure controls");
\r
1107 gp2x_text_out8(tl_x, (y+=10), "Credits");
\r
1108 gp2x_text_out8(tl_x, (y+=10), "Exit");
\r
1111 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
1113 if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);
\r
1114 gp2x_video_flip2();
\r
1118 static void menu_loop_root(void)
\r
1120 int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;
\r
1121 unsigned long inp = 0;
\r
1122 char curr_path[PATH_MAX], *selfname;
\r
1125 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
1128 strcpy(curr_path, currentConfig.lastRomFile);
\r
1132 getcwd(curr_path, PATH_MAX);
\r
1135 if (rom_data) menu_sel = menu_sel_min = 0;
\r
1139 draw_menu_root(menu_sel);
\r
1140 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT);
\r
1141 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }
\r
1142 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }
\r
1143 if(inp &(GP2X_SELECT|GP2X_X)){
\r
1145 while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released
\r
1146 engineState = PGS_Running;
\r
1150 if(inp & GP2X_B ) {
\r
1151 switch (menu_sel) {
\r
1152 case 0: // resume game
\r
1153 if (rom_data) { engineState = PGS_Running; return; }
\r
1155 case 1: // save state
\r
1157 if(savestate_menu_loop(0))
\r
1159 engineState = PGS_Running;
\r
1163 case 2: // load state
\r
1165 if(savestate_menu_loop(1))
\r
1167 engineState = PGS_Running;
\r
1171 case 3: // reset game
\r
1174 engineState = PGS_Running;
\r
1178 case 4: // select rom
\r
1179 selfname = romsel_loop(curr_path);
\r
1181 printf("selected file: %s\n", selfname);
\r
1182 engineState = PGS_ReloadRom;
\r
1185 case 5: // options
\r
1186 ret = menu_loop_options();
\r
1187 if (ret == 1) continue; // status update
\r
1188 if (engineState == PGS_ReloadRom)
\r
1189 return; // BIOS test
\r
1191 case 6: // controls
\r
1194 case 7: // credits
\r
1195 draw_menu_credits();
\r
1197 inp = wait_for_input(GP2X_B|GP2X_X);
\r
1200 engineState = PGS_Quit;
\r
1204 menuErrorMsg[0] = 0; // clear error msg
\r
1209 static void menu_prepare_bg(void)
\r
1211 extern int localPal[0x100];
\r
1214 // don't clear old palette just for fun (but make it dark)
\r
1215 for (i = 0x100-1; i >= 0; i--) {
\r
1217 localPal[i] = ((c >> 1) & 0x007f7f7f) - ((c >> 3) & 0x001f1f1f);
\r
1219 localPal[0xe0] = 0x00000000; // reserved pixels for OSD
\r
1220 localPal[0xf0] = 0x00ffffff;
\r
1222 gp2x_video_setpalette(localPal, 0x100);
\r
1225 static void menu_gfx_prepare(void)
\r
1227 menu_prepare_bg();
\r
1230 gp2x_video_changemode2(8);
\r
1231 gp2x_video_RGB_setscaling(320, 240);
\r
1232 gp2x_video_flip2();
\r
1236 void menu_loop(void)
\r
1238 menu_gfx_prepare();
\r
1242 menuErrorMsg[0] = 0;
\r