1 // (c) Copyright 2006,2007 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
13 #include "minimal.h"
\r
15 #include "asmutils.h"
\r
21 #ifndef _DIRENT_HAVE_D_TYPE
\r
22 #error "need d_type for file browser
\r
25 extern char lastLoadedGameName[PATH_MAX];
\r
26 extern int mmuhack_status;
\r
27 //extern int state_slot; // TODO
\r
28 extern uint8 Exit; // exit emu loop flag
\r
30 static char *gp2xKeyNames[] = {
\r
31 "UP", "01???", "LEFT", "03???", "DOWN", "05???", "RIGHT", "07???",
\r
32 "START", "SELECT", "L", "R", "A", "B", "X", "Y",
\r
33 "10???", "11???", "12???","13???", "14???","15???", "VOL DOWN", "VOL UP",
\r
34 "18???", "19???", "1a???","PUSH", "1c???","1d???", "1e???", "1f???"
\r
37 char menuErrorMsg[40] = {0, };
\r
40 void gp2x_fceu_copy_bg(void)
\r
42 memset(gp2x_screen, 0, 320*240*2);
\r
45 // draws white text to current bbp15 screen
\r
46 static void gp2x_text_out15_(int x, int y, const char *text)
\r
49 unsigned short *screen = gp2x_screen;
\r
51 screen = screen + x + y*320;
\r
53 for (i = 0; i < strlen(text); i++)
\r
57 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;
\r
58 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;
\r
59 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;
\r
60 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;
\r
61 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;
\r
62 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;
\r
63 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;
\r
64 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;
\r
70 void gp2x_text_out15(int x, int y, const char *texto, ...)
\r
75 va_start(args,texto);
\r
76 vsprintf(buffer,texto,args);
\r
79 gp2x_text_out15_(x,y,buffer);
\r
83 void gp2x_text_out15_lim(int x, int y, const char *texto, int max)
\r
85 char buffer[320/8+1];
\r
87 strncpy(buffer, texto, 320/8);
\r
88 if (max > 320/8) max = 320/8;
\r
89 if (max < 0) max = 0;
\r
92 gp2x_text_out15(x,y,buffer);
\r
95 static void gp2x_smalltext16(int x, int y, const char *texto)
\r
99 unsigned short *dst;
\r
101 for (i = 0;; i++, x += 6)
\r
103 unsigned char c = (unsigned char) texto[i];
\r
108 src = fontdata6x8[c];
\r
109 dst = (unsigned short *)gp2x_screen + x + y*320;
\r
116 if( *src & w ) *dst = 0xffff;
\r
127 static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)
\r
129 char buffer[320/6+1];
\r
131 strncpy(buffer, texto, 320/6);
\r
132 if (max > 320/6) max = 320/6;
\r
133 if (max < 0) max = 0;
\r
136 gp2x_smalltext16(x, y, buffer);
\r
140 static unsigned long inp_prev = 0;
\r
141 static int inp_prevjoy = 0;
\r
143 static unsigned long wait_for_input(unsigned long interesting)
\r
146 static int repeats = 0, wait = 50*1000;
\r
147 int release = 0, i;
\r
149 if (repeats == 2 || repeats == 4) wait /= 2;
\r
150 if (repeats == 6) wait = 15 * 1000;
\r
152 for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {
\r
153 if (i == 0) repeats++;
\r
154 if (wait >= 30*1000) usleep(wait); // usleep sleeps for ~30ms minimum
\r
155 else spend_cycles(wait * Settings.cpuclock);
\r
158 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
\r
163 if (release || ret != inp_prev) {
\r
170 // we don't need diagonals in menus
\r
171 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
172 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
173 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
174 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
179 static unsigned long input2_read(unsigned long interesting, int *joy)
\r
187 if ((ret = gp2x_joystick_read(0) & interesting)) break;
\r
188 gp2x_usbjoy_update();
\r
189 for (i = 0; i < num_of_joys; i++) {
\r
190 ret = gp2x_usbjoy_check2(i);
\r
191 if (ret) { *joy = i + 1; break; }
\r
200 // similar to wait_for_input(), but returns joy num
\r
201 static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
\r
204 const int wait = 300*1000;
\r
207 if (inp_prevjoy == 0) inp_prev &= interesting;
\r
208 for (i = 0; i < 6; i++) {
\r
209 ret = input2_read(interesting, joy);
\r
210 if (*joy != inp_prevjoy || ret != inp_prev) break;
\r
214 while ( !(ret = input2_read(interesting, joy)) ) {
\r
219 inp_prevjoy = *joy;
\r
226 // -------------- ROM selector --------------
\r
228 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
233 n--; // exclude current dir (".")
\r
235 //memset(gp2x_screen, 0, 320*240);
\r
236 gp2x_fceu_copy_bg();
\r
239 gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);
\r
240 for (i = 0; i < n; i++) {
\r
242 if (pos < 0) continue;
\r
243 if (pos > 23) break;
\r
244 if (namelist[i+1]->d_type == DT_DIR) {
\r
245 gp2x_smalltext8_lim(14, pos*10, "/", 1);
\r
246 gp2x_smalltext8_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);
\r
248 gp2x_smalltext8_lim(14, pos*10, namelist[i+1]->d_name, 53-2);
\r
251 gp2x_text_out15(5, 120, ">");
\r
255 static int scandir_cmp(const void *p1, const void *p2)
\r
257 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
258 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
259 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
260 if ((*d2)->d_type == DT_DIR) return 1;
\r
261 return alphasort(d1, d2);
\r
264 static char *filter_exts[] = {
\r
266 ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
267 ".jpg", ".gpe", ".cue"
\r
270 static int scandir_filter(const struct dirent *ent)
\r
275 if (ent == NULL || ent->d_name == NULL) return 0;
\r
276 if (strlen(ent->d_name) < 5) return 1;
\r
278 p = ent->d_name + strlen(ent->d_name) - 4;
\r
280 for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)
\r
282 if (strcmp(p, filter_exts[i]) == 0) return 0;
\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, scandir_filter, scandir_cmp);
\r
309 n = scandir("/", &namelist, scandir_filter, scandir_cmp);
\r
312 printf("dir: %s\n", curr_path);
\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) { sel-=10; if (sel < 0) sel = 0; }
\r
336 if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; }
\r
337 if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
338 if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
339 if(inp & GP2X_B) { // enter dir/select
\r
341 if (namelist[sel+1]->d_type == DT_REG) {
\r
342 strcpy(lastLoadedGameName, curr_path);
\r
343 strcat(lastLoadedGameName, "/");
\r
344 strcat(lastLoadedGameName, namelist[sel+1]->d_name);
\r
345 ret = lastLoadedGameName;
\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
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
364 ret = romsel_loop(newdir);
\r
368 // unknown file type, happens on NTFS mounts. Try to guess.
\r
369 FILE *tstf; int tmp;
\r
370 strcpy(lastLoadedGameName, curr_path);
\r
371 strcat(lastLoadedGameName, "/");
\r
372 strcat(lastLoadedGameName, namelist[sel+1]->d_name);
\r
373 tstf = fopen(lastLoadedGameName, "rb");
\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
384 if(inp & GP2X_X) break; // cancel
\r
388 while(n--) free(namelist[n]);
\r
395 // ------------ patch/gg menu ------------
\r
398 static void draw_patchlist(int sel)
\r
404 gp2x_fceu_copy_bg();
\r
406 for (i = 0; i < PicoPatchCount; i++) {
\r
408 if (pos < 0) continue;
\r
409 if (pos > 23) break;
\r
410 gp2x_smalltext8_lim(14, pos*10, PicoPatches[i].active ? "ON " : "OFF", 3);
\r
411 gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6);
\r
414 if (pos < 24) gp2x_smalltext8_lim(14, pos*10, "done", 4);
\r
416 gp2x_text_out15(5, 120, ">");
\r
421 void patches_menu_loop(void)
\r
424 unsigned long inp = 0;
\r
428 draw_patchlist(menu_sel);
\r
429 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
430 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
431 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
432 if(inp &(GP2X_LEFT|GP2X_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
433 if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
434 if(inp & GP2X_B) { // action
\r
435 if (menu_sel < PicoPatchCount)
\r
436 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
439 if(inp & GP2X_X) return;
\r
444 // ------------ savestate loader ------------
\r
446 static void menu_prepare_bg(void);
\r
448 static int state_slot_flags = 0;
\r
450 static void state_check_slots(void)
\r
454 state_slot_flags = 0;
\r
456 for (slot = 0; slot < 10; slot++)
\r
458 if (emu_check_save_file(slot))
\r
460 state_slot_flags |= 1 << slot;
\r
465 static void draw_savestate_bg(int slot)
\r
467 struct PicoVideo tmp_pv;
\r
468 unsigned short tmp_cram[0x40];
\r
469 unsigned short tmp_vsram[0x40];
\r
470 void *tmp_vram, *file;
\r
473 fname = emu_GetSaveFName(1, 0, slot);
\r
474 if (!fname) return;
\r
476 tmp_vram = malloc(sizeof(Pico.vram));
\r
477 if (tmp_vram == NULL) return;
\r
479 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
480 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
481 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
482 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
484 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
485 file = gzopen(fname, "rb");
\r
486 emu_set_save_cbs(1);
\r
488 file = fopen(fname, "rb");
\r
489 emu_set_save_cbs(0);
\r
494 PicoCdLoadStateGfx(file);
\r
496 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
497 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
498 areaSeek(file, 0x2000, SEEK_CUR);
\r
499 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
500 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
501 areaSeek(file, 0x221a0, SEEK_SET);
\r
502 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
507 emu_forced_frame();
\r
508 gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);
\r
511 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
512 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
513 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
514 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
518 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
520 int tl_x = 25, tl_y = 60, y, i;
\r
522 if (state_slot_flags & (1 << menu_sel))
\r
523 draw_savestate_bg(menu_sel);
\r
524 gp2x_fceu_copy_bg();
\r
526 gp2x_text_out15(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
528 /* draw all 10 slots */
\r
530 for (i = 0; i < 10; i++, y+=10)
\r
532 gp2x_text_out15(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
534 gp2x_text_out15(tl_x, y, "back");
\r
537 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
542 static int savestate_menu_loop(int is_loading)
\r
544 int menu_sel = 10, menu_sel_max = 10;
\r
545 unsigned long inp = 0;
\r
547 state_check_slots();
\r
551 draw_savestate_menu(menu_sel, is_loading);
\r
552 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
553 if(inp & GP2X_UP ) {
\r
555 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
556 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
558 if(inp & GP2X_DOWN) {
\r
560 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
561 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
563 if(inp & GP2X_B) { // save/load
\r
564 if (menu_sel < 10) {
\r
565 state_slot = menu_sel;
\r
566 if (emu_SaveLoadGame(is_loading, 0)) {
\r
567 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
573 if(inp & GP2X_X) return 1;
\r
577 // -------------- key config --------------
\r
579 static char *usb_joy_key_name(int joy, int num)
\r
581 static char name[16];
\r
584 case 0: sprintf(name, "Joy%i UP", joy); break;
\r
585 case 1: sprintf(name, "Joy%i DOWN", joy); break;
\r
586 case 2: sprintf(name, "Joy%i LEFT", joy); break;
\r
587 case 3: sprintf(name, "Joy%i RIGHT", joy); break;
\r
588 default:sprintf(name, "Joy%i b%i", joy, num-3); break;
\r
593 static void draw_key_config(int curr_act, int is_p2)
\r
595 char strkeys[32*5];
\r
599 for (i = 0; i < 32; i++)
\r
601 if (currentConfig.KeyBinds[i] & (1 << curr_act))
\r
603 if (curr_act < 16 && (currentConfig.KeyBinds[i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
604 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }
\r
605 else strcpy(strkeys, gp2xKeyNames[i]);
\r
608 for (joy = 0; joy < num_of_joys; joy++)
\r
610 for (i = 0; i < 32; i++)
\r
612 if (currentConfig.JoyBinds[joy][i] & (1 << curr_act))
\r
614 if (curr_act < 16 && (currentConfig.JoyBinds[joy][i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
616 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
\r
619 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
\r
624 //memset(gp2x_screen, 0, 320*240);
\r
625 gp2x_fceu_copy_bg();
\r
626 gp2x_text_out15(60, 40, "Action: %s", actionNames[curr_act]);
\r
627 gp2x_text_out15(60, 60, "Keys: %s", strkeys);
\r
629 gp2x_text_out15(30, 180, "Use SELECT to change action");
\r
630 gp2x_text_out15(30, 190, "Press a key to bind/unbind");
\r
631 gp2x_text_out15(30, 200, "Select \"Done\" action and");
\r
632 gp2x_text_out15(30, 210, " press any key to finish");
\r
636 static void key_config_loop(int is_p2)
\r
638 int curr_act = 0, joy = 0, i;
\r
639 unsigned long inp = 0;
\r
643 draw_key_config(curr_act, is_p2);
\r
644 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);
\r
645 // printf("got %08lX from joy %i\n", inp, joy);
\r
647 if (inp & GP2X_SELECT) {
\r
649 while (!actionNames[curr_act] && curr_act < 32) curr_act++;
\r
650 if (curr_act > 31) curr_act = 0;
\r
652 inp &= CONFIGURABLE_KEYS;
\r
653 inp &= ~GP2X_SELECT;
\r
655 if (curr_act == 31 && inp) break;
\r
657 for (i = 0; i < 32; i++)
\r
658 if (inp & (1 << i)) {
\r
659 currentConfig.KeyBinds[i] ^= (1 << curr_act);
\r
660 if (is_p2) currentConfig.KeyBinds[i] |= (1 << 16); // player 2 flag
\r
661 else currentConfig.KeyBinds[i] &= ~(1 << 16);
\r
664 for (i = 0; i < 32; i++)
\r
665 if (inp & (1 << i)) {
\r
666 currentConfig.JoyBinds[joy-1][i] ^= (1 << curr_act);
\r
667 if (is_p2) currentConfig.JoyBinds[joy-1][i] |= (1 << 16);
\r
668 else currentConfig.JoyBinds[joy-1][i] &= ~(1 << 16);
\r
674 static void draw_kc_sel(int menu_sel)
\r
676 int tl_x = 25+40, tl_y = 60, y, i;
\r
680 //memset(gp2x_screen, 0, 320*240);
\r
681 gp2x_fceu_copy_bg();
\r
682 gp2x_text_out15(tl_x, y, "Player 1");
\r
683 gp2x_text_out15(tl_x, (y+=10), "Player 2");
\r
684 gp2x_text_out15(tl_x, (y+=10), "Done");
\r
687 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
690 gp2x_text_out15(tl_x, (y=110), "USB joys detected:");
\r
691 if (num_of_joys > 0) {
\r
692 for (i = 0; i < num_of_joys; i++) {
\r
693 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
\r
694 gp2x_text_out15(tl_x, (y+=10), "%i: %s", i+1, joyname);
\r
697 gp2x_text_out15(tl_x, (y+=10), "none");
\r
704 static void kc_sel_loop(void)
\r
706 int menu_sel = 2, menu_sel_max = 2;
\r
707 unsigned long inp = 0;
\r
711 draw_kc_sel(menu_sel);
\r
712 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
713 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
714 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
716 switch (menu_sel) {
\r
717 case 0: key_config_loop(0); return;
\r
718 case 1: key_config_loop(1); return;
\r
722 if(inp & GP2X_X) return;
\r
729 // --------- advanced options ----------
\r
731 static void draw_amenu_options(int menu_sel)
\r
733 int tl_x = 25, tl_y = 60, y;
\r
734 char *mms = mmuhack_status ? "active) " : "inactive)";
\r
737 //memset(gp2x_screen, 0, 320*240);
\r
738 gp2x_fceu_copy_bg();
\r
740 gp2x_text_out15(tl_x, y, "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 0
\r
741 gp2x_text_out15(tl_x, (y+=10), "Don't save last used ROM %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 5
\r
742 gp2x_text_out15(tl_x, (y+=10), "needs restart:");
\r
743 gp2x_text_out15(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 7
\r
744 gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 8
\r
745 gp2x_text_out15(tl_x, (y+=10), "Done");
\r
748 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
753 static void amenu_loop_options(void)
\r
755 int menu_sel = 0, menu_sel_max = 9;
\r
756 unsigned long inp = 0;
\r
760 draw_amenu_options(menu_sel);
\r
761 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
762 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
763 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
764 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
765 switch (menu_sel) {
\r
770 if(inp & (GP2X_X|GP2X_A)) return;
\r
771 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
772 switch (menu_sel) {
\r
774 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
775 currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;
\r
776 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
777 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
778 draw_amenu_options(menu_sel);
\r
788 // -------------- options --------------
\r
790 static void draw_menu_options(int menu_sel)
\r
792 int tl_x = 25, tl_y = 32, y;
\r
793 char monostereo[8], strframeskip[8], *strscaling, *strssconfirm;
\r
795 //strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");
\r
796 if (Settings.frameskip < 0)
\r
797 strcpy(strframeskip, "Auto");
\r
798 else sprintf(strframeskip, "%i", Settings.frameskip);
\r
799 switch (Settings.scaling) {
\r
800 default: strscaling = " OFF"; break;
\r
801 case 1: strscaling = "hw horizontal"; break;
\r
802 case 2: strscaling = "hw horiz. + vert."; break;
\r
803 case 3: strscaling = "sw horizontal"; break;
\r
805 switch (Settings.sstate_confirm) {
\r
806 default: strssconfirm = "OFF"; break;
\r
807 case 1: strssconfirm = "writes"; break;
\r
808 case 2: strssconfirm = "loads"; break;
\r
809 case 3: strssconfirm = "both"; break;
\r
813 //memset(gp2x_screen, 0, 320*240);
\r
814 gp2x_fceu_copy_bg();
\r
816 gp2x_text_out15(tl_x, (y+=10), "Scaling: %s", strscaling); // 0
\r
817 gp2x_text_out15(tl_x, (y+=10), "Show FPS %s", Settings.showfps?"ON":"OFF"); // 1
\r
818 gp2x_text_out15(tl_x, (y+=10), "Frameskip %s", strframeskip); // 2
\r
819 gp2x_text_out15(tl_x, (y+=10), "Enable sound %s", /*(currentConfig.EmuOpt &0x004)?"ON":*/"OFF"); // 3
\r
820 gp2x_text_out15(tl_x, (y+=10), "Sound Quality: %5iHz %s", 0, "" /*currentConfig.PsndRate, monostereo*/); // 4
\r
821 gp2x_text_out15(tl_x, (y+=10), "Region: %s",
\r
822 Settings.region_force == 2 ? "NTSC" : Settings.region_force == 1 ? "PAL" : "OFF"); // 5
\r
823 gp2x_text_out15(tl_x, (y+=10), "Use SRAM savestates %s", "OFF");
\r
824 gp2x_text_out15(tl_x, (y+=10), "Confirm savestate %s", strssconfirm);
\r
825 gp2x_text_out15(tl_x, (y+=10), "Save slot %i", 0/*state_slot*/); // 8
\r
826 gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock %iMhz", Settings.cpuclock);
\r
827 gp2x_text_out15(tl_x, (y+=10), "[advanced options]"); // 10
\r
828 gp2x_text_out15(tl_x, (y+=10), "Save cfg as default");
\r
830 gp2x_text_out15(tl_x, (y+=10), "Save cfg for current game only");
\r
833 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
839 static int sndrate_prevnext(int rate, int dir)
\r
841 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
843 for (i = 0; i < 5; i++)
\r
844 if (rates[i] == rate) break;
\r
847 if (i > 4) return dir ? 44100 : 22050;
\r
848 if (i < 0) return dir ? 11025 : 8000;
\r
852 static void int_incdec(int *p, int inc, int min, int max)
\r
855 if (*p < min) *p = min;
\r
856 else if (*p > max) *p = max;
\r
859 static int menu_loop_options(void)
\r
861 int menu_sel = 0, menu_sel_max = 11;
\r
862 unsigned long inp = 0;
\r
864 if (fceugi) menu_sel_max++;
\r
868 draw_menu_options(menu_sel);
\r
869 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
870 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
871 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
872 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
873 switch (menu_sel) {
\r
874 case 1: Settings.showfps = !Settings.showfps; break;
\r
875 //case 6: Settings. = !Settings.showfps; break;
\r
876 //case 16: amenu_loop_options(); break;
\r
877 case 17: // done (update and write)
\r
878 //if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
879 //else strcpy(menuErrorMsg, "failed to write config");
\r
881 case 18: // done (update and write for current game)
\r
882 //if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
883 //else strcpy(menuErrorMsg, "failed to write config");
\r
887 if(inp & (GP2X_X|GP2X_A)) {
\r
888 return 0; // done (update, no write)
\r
890 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
891 switch (menu_sel) {
\r
892 case 0: int_incdec(&Settings.scaling, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;
\r
893 case 2: int_incdec(&Settings.frameskip, (inp & GP2X_LEFT) ? -1 : 1, -1, 32); break;
\r
896 if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {
\r
897 currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;
\r
898 } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {
\r
899 currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;
\r
900 } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);
\r
903 case 5: int_incdec(&Settings.region_force, (inp & GP2X_LEFT) ? -1 : 1, 0, 2); break;
\r
904 case 7: int_incdec(&Settings.sstate_confirm, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;
\r
905 //case 8: int_incdec(&Settings., (inp & GP2X_LEFT) ? -1 : 1, 0, 9); break;
\r
907 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
908 Settings.cpuclock += (inp & GP2X_LEFT) ? -1 : 1;
\r
909 if (Settings.cpuclock < 1) Settings.cpuclock = 1;
\r
910 draw_menu_options(menu_sel);
\r
919 // -------------- credits --------------
\r
921 static void draw_menu_credits(void)
\r
923 int tl_x = 15, tl_y = 70, y;
\r
924 //memset(gp2x_screen, 0, 320*240);
\r
925 gp2x_fceu_copy_bg();
\r
933 // -------------- root menu --------------
\r
935 static void draw_menu_root(int menu_sel)
\r
937 int tl_x = 70, tl_y = 70, y;
\r
938 gp2x_fceu_copy_bg();
\r
942 gp2x_text_out15(tl_x, y, "Resume game");
\r
943 gp2x_text_out15(tl_x, (y+=10), "Save State");
\r
944 gp2x_text_out15(tl_x, (y+=10), "Load State");
\r
945 gp2x_text_out15(tl_x, (y+=10), "Reset game");
\r
949 gp2x_text_out15(tl_x, (y+=10), "Load new ROM");
\r
950 gp2x_text_out15(tl_x, (y+=10), "Change options");
\r
951 gp2x_text_out15(tl_x, (y+=10), "Configure controls");
\r
952 gp2x_text_out15(tl_x, (y+=10), "Credits");
\r
953 gp2x_text_out15(tl_x, (y+=10), "Exit");
\r
955 // if (PicoPatches)
\r
956 // gp2x_text_out15(tl_x, (y+=10), "Patches / GameGenie");
\r
959 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
961 if (menuErrorMsg[0]) gp2x_text_out15(5, 226, menuErrorMsg);
\r
966 static int menu_loop_root(void)
\r
968 int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;
\r
969 unsigned long inp = 0;
\r
970 char curr_path[PATH_MAX], *selfname;
\r
973 if ( (tstf = fopen(lastLoadedGameName, "rb")) )
\r
976 strncpy(curr_path, lastLoadedGameName, sizeof(curr_path));
\r
977 curr_path[sizeof(curr_path)-1] = 0;
\r
981 getcwd(curr_path, PATH_MAX);
\r
984 if (fceugi) menu_sel = menu_sel_min = 0;
\r
985 // TODO if (PicoPatches) menu_sel_max = 9;
\r
987 /* make sure action buttons are not pressed on entering menu */
\r
988 draw_menu_root(menu_sel);
\r
989 while (gp2x_joystick_read(1) & (GP2X_B|GP2X_X|GP2X_SELECT)) usleep(50*1000);
\r
993 draw_menu_root(menu_sel);
\r
994 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
995 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }
\r
996 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }
\r
997 if(inp &(GP2X_SELECT|GP2X_X)){
\r
999 while (gp2x_joystick_read(1) & GP2X_X) usleep(50*1000); // wait until X is released
\r
1004 if(inp & GP2X_B ) {
\r
1005 switch (menu_sel) {
\r
1006 case 0: // resume game
\r
1008 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1013 case 1: // save state
\r
1015 /*if(savestate_menu_loop(0))
\r
1020 case 2: // load state
\r
1022 /*if(savestate_menu_loop(1))
\r
1027 case 3: // reset game
\r
1032 case 4: // select rom
\r
1033 selfname = romsel_loop(curr_path);
\r
1035 printf("selected file: %s\n", selfname);
\r
1039 case 5: // options
\r
1040 ret = menu_loop_options();
\r
1041 if (ret == 1) continue; // status update
\r
1043 case 6: // controls
\r
1044 // TODO kc_sel_loop();
\r
1046 case 7: // credits
\r
1047 draw_menu_credits();
\r
1049 inp = wait_for_input(GP2X_B|GP2X_X);
\r
1053 case 9: // patches/gg
\r
1057 menuErrorMsg[0] = 0; // clear error msg
\r
1062 static void menu_prepare_bg(void)
\r
1067 static void menu_gfx_prepare(void)
\r
1069 menu_prepare_bg();
\r
1072 gp2x_video_changemode(16);
\r
1073 gp2x_video_RGB_setscaling(0, 320, 240);
\r
1074 gp2x_video_flip();
\r
1078 int gp2x_menu_do(void)
\r
1082 menu_gfx_prepare();
\r
1084 ret = menu_loop_root();
\r
1086 menuErrorMsg[0] = 0;
\r