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 #include "../../input.h"
\r
22 #include "../../state.h"
\r
24 #ifndef _DIRENT_HAVE_D_TYPE
\r
25 #error "need d_type for file browser
\r
28 extern int GP2X_PORT_REV;
\r
29 extern char lastLoadedGameName[PATH_MAX];
\r
30 extern int mmuhack_status;
\r
31 extern int soundvol;
\r
32 extern uint8 Exit; // exit emu loop flag
\r
33 extern int InitSound(void);
\r
35 #define CONFIGURABLE_KEYS (GP2X_UP|GP2X_LEFT|GP2X_DOWN|GP2X_RIGHT|GP2X_START|GP2X_SELECT|GP2X_L|GP2X_R|GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_PUSH)
\r
37 static char *gp2xKeyNames[] = {
\r
38 "UP", "01???", "LEFT", "03???", "DOWN", "05???", "RIGHT", "07???",
\r
39 "START", "SELECT", "L", "R", "A", "B", "X", "Y",
\r
40 "10???", "11???", "12???","13???", "14???","15???", "VOL DOWN", "VOL UP",
\r
41 "18???", "19???", "1a???","PUSH", "1c???","1d???", "1e???", "1f???"
\r
44 char menuErrorMsg[40] = {0, };
\r
47 void gp2x_fceu_copy_bg(void)
\r
49 memset(gp2x_screen, 0, 320*240*2);
\r
52 // draws white text to current bbp15 screen
\r
53 static void gp2x_text_out15_(int x, int y, const char *text)
\r
56 unsigned short *screen = gp2x_screen;
\r
58 screen = screen + x + y*320;
\r
60 for (i = 0; i < strlen(text); i++)
\r
64 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;
\r
65 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;
\r
66 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;
\r
67 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;
\r
68 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;
\r
69 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;
\r
70 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;
\r
71 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;
\r
77 void gp2x_text_out15(int x, int y, const char *texto, ...)
\r
82 va_start(args,texto);
\r
83 vsprintf(buffer,texto,args);
\r
86 gp2x_text_out15_(x,y,buffer);
\r
90 void gp2x_text_out15_lim(int x, int y, const char *texto, int max)
\r
92 char buffer[320/8+1];
\r
94 strncpy(buffer, texto, 320/8);
\r
95 if (max > 320/8) max = 320/8;
\r
96 if (max < 0) max = 0;
\r
99 gp2x_text_out15(x,y,buffer);
\r
102 static void gp2x_smalltext16(int x, int y, const char *texto)
\r
105 unsigned char *src;
\r
106 unsigned short *dst;
\r
108 for (i = 0;; i++, x += 6)
\r
110 unsigned char c = (unsigned char) texto[i];
\r
115 src = fontdata6x8[c];
\r
116 dst = (unsigned short *)gp2x_screen + x + y*320;
\r
123 if( *src & w ) *dst = 0xffff;
\r
134 static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)
\r
136 char buffer[320/6+1];
\r
138 strncpy(buffer, texto, 320/6);
\r
139 if (max > 320/6) max = 320/6;
\r
140 if (max < 0) max = 0;
\r
143 gp2x_smalltext16(x, y, buffer);
\r
147 static unsigned long inp_prev = 0;
\r
148 static int inp_prevjoy = 0;
\r
150 static unsigned long wait_for_input(unsigned long interesting)
\r
153 static int repeats = 0, wait = 50*1000;
\r
154 int release = 0, i;
\r
156 if (repeats == 2 || repeats == 4) wait /= 2;
\r
157 if (repeats == 6) wait = 15 * 1000;
\r
159 for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {
\r
160 if (i == 0) repeats++;
\r
161 if (wait >= 30*1000) usleep(wait); // usleep sleeps for ~30ms minimum
\r
162 else spend_cycles(wait * Settings.cpuclock);
\r
165 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
\r
170 if (release || ret != inp_prev) {
\r
177 // we don't need diagonals in menus
\r
178 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
179 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
180 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
181 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
186 static unsigned long input2_read(unsigned long interesting, int *joy)
\r
194 if ((ret = gp2x_joystick_read(0) & interesting)) break;
\r
195 gp2x_usbjoy_update();
\r
196 for (i = 0; i < num_of_joys; i++) {
\r
197 ret = gp2x_usbjoy_check2(i);
\r
198 if (ret) { *joy = i + 1; break; }
\r
207 // similar to wait_for_input(), but returns joy num
\r
208 static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
\r
211 const int wait = 300*1000;
\r
214 if (inp_prevjoy == 0) inp_prev &= interesting;
\r
215 for (i = 0; i < 6; i++) {
\r
216 ret = input2_read(interesting, joy);
\r
217 if (*joy != inp_prevjoy || ret != inp_prev) break;
\r
221 while ( !(ret = input2_read(interesting, joy)) ) {
\r
226 inp_prevjoy = *joy;
\r
233 // -------------- ROM selector --------------
\r
235 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
240 n--; // exclude current dir (".")
\r
242 //memset(gp2x_screen, 0, 320*240);
\r
243 gp2x_fceu_copy_bg();
\r
246 gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);
\r
247 for (i = 0; i < n; i++) {
\r
249 if (pos < 0) continue;
\r
250 if (pos > 23) break;
\r
251 if (namelist[i+1]->d_type == DT_DIR) {
\r
252 gp2x_smalltext8_lim(14, pos*10, "/", 1);
\r
253 gp2x_smalltext8_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);
\r
255 gp2x_smalltext8_lim(14, pos*10, namelist[i+1]->d_name, 53-2);
\r
258 gp2x_text_out15(5, 120, ">");
\r
262 static int scandir_cmp(const void *p1, const void *p2)
\r
264 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
265 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
266 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
267 if ((*d2)->d_type == DT_DIR) return 1;
\r
268 return alphasort(d1, d2);
\r
271 static char *filter_exts[] = {
\r
272 ".gpe", ".png", "ck.o", ".txt"
\r
275 static int scandir_filter(const struct dirent *ent)
\r
280 if (ent == NULL || ent->d_name == NULL) return 0;
\r
281 if (strlen(ent->d_name) < 5) return 1;
\r
283 p = ent->d_name + strlen(ent->d_name) - 4;
\r
285 for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)
\r
287 if (strcmp(p, filter_exts[i]) == 0) return 0;
\r
293 static char *romsel_loop(char *curr_path)
\r
295 struct dirent **namelist;
\r
298 unsigned long inp = 0;
\r
299 char *ret = NULL, *fname = NULL;
\r
301 // is this a dir or a full path?
\r
302 if ((dir = opendir(curr_path))) {
\r
306 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
311 n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
314 n = scandir("/", &namelist, scandir_filter, scandir_cmp);
\r
317 printf("dir: %s\n", curr_path);
\r
324 if (fname != NULL) {
\r
326 for (i = 1; i < n; i++) {
\r
327 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
336 draw_dirlist(curr_path, namelist, n, sel);
\r
337 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
338 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
339 if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
340 if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
341 if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; }
\r
342 if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
343 if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
344 if(inp & GP2X_B) { // enter dir/select
\r
346 if (namelist[sel+1]->d_type == DT_REG) {
\r
347 strcpy(lastLoadedGameName, curr_path);
\r
348 strcat(lastLoadedGameName, "/");
\r
349 strcat(lastLoadedGameName, namelist[sel+1]->d_name);
\r
350 ret = lastLoadedGameName;
\r
352 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
353 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
354 char *p, *newdir = malloc(newlen);
\r
355 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
356 char *start = curr_path;
\r
357 p = start + strlen(start) - 1;
\r
358 while (*p == '/' && p > start) p--;
\r
359 while (*p != '/' && p > start) p--;
\r
360 if (p <= start) strcpy(newdir, "/");
\r
361 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
363 strcpy(newdir, curr_path);
\r
364 p = newdir + strlen(newdir) - 1;
\r
365 while (*p == '/' && p >= newdir) *p-- = 0;
\r
366 strcat(newdir, "/");
\r
367 strcat(newdir, namelist[sel+1]->d_name);
\r
369 ret = romsel_loop(newdir);
\r
373 // unknown file type, happens on NTFS mounts. Try to guess.
\r
374 FILE *tstf; int tmp;
\r
375 strcpy(lastLoadedGameName, curr_path);
\r
376 strcat(lastLoadedGameName, "/");
\r
377 strcat(lastLoadedGameName, namelist[sel+1]->d_name);
\r
378 tstf = fopen(lastLoadedGameName, "rb");
\r
381 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
382 namelist[sel+1]->d_type = DT_REG;
\r
383 else namelist[sel+1]->d_type = DT_DIR;
\r
389 if(inp & GP2X_X) break; // cancel
\r
393 while(n--) free(namelist[n]);
\r
400 // ------------ patch/gg menu ------------
\r
403 static void draw_patchlist(int sel)
\r
409 gp2x_fceu_copy_bg();
\r
411 for (i = 0; i < PicoPatchCount; i++) {
\r
413 if (pos < 0) continue;
\r
414 if (pos > 23) break;
\r
415 gp2x_smalltext8_lim(14, pos*10, PicoPatches[i].active ? "ON " : "OFF", 3);
\r
416 gp2x_smalltext8_lim(14+6*4, pos*10, PicoPatches[i].name, 53-6);
\r
419 if (pos < 24) gp2x_smalltext8_lim(14, pos*10, "done", 4);
\r
421 gp2x_text_out15(5, 120, ">");
\r
426 void patches_menu_loop(void)
\r
429 unsigned long inp = 0;
\r
433 draw_patchlist(menu_sel);
\r
434 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
435 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
436 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
437 if(inp &(GP2X_LEFT|GP2X_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
438 if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
439 if(inp & GP2X_B) { // action
\r
440 if (menu_sel < PicoPatchCount)
\r
441 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
444 if(inp & GP2X_X) return;
\r
449 // ------------ savestate loader ------------
\r
451 static void menu_prepare_bg(void);
\r
453 static int state_slot_flags = 0;
\r
455 static void state_check_slots(void)
\r
459 state_slot_flags = 0;
\r
461 for (slot = 0; slot < 10; slot++)
\r
463 if (emu_check_save_file(slot))
\r
465 state_slot_flags |= 1 << slot;
\r
470 static void draw_savestate_bg(int slot)
\r
472 struct PicoVideo tmp_pv;
\r
473 unsigned short tmp_cram[0x40];
\r
474 unsigned short tmp_vsram[0x40];
\r
475 void *tmp_vram, *file;
\r
478 fname = emu_GetSaveFName(1, 0, slot);
\r
479 if (!fname) return;
\r
481 tmp_vram = malloc(sizeof(Pico.vram));
\r
482 if (tmp_vram == NULL) return;
\r
484 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
485 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
486 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
487 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
489 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
490 file = gzopen(fname, "rb");
\r
491 emu_set_save_cbs(1);
\r
493 file = fopen(fname, "rb");
\r
494 emu_set_save_cbs(0);
\r
499 PicoCdLoadStateGfx(file);
\r
501 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
502 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
503 areaSeek(file, 0x2000, SEEK_CUR);
\r
504 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
505 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
506 areaSeek(file, 0x221a0, SEEK_SET);
\r
507 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
512 emu_forced_frame();
\r
513 gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);
\r
516 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
517 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
518 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
519 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
523 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
525 int tl_x = 25, tl_y = 60, y, i;
\r
527 if (state_slot_flags & (1 << menu_sel))
\r
528 draw_savestate_bg(menu_sel);
\r
529 gp2x_fceu_copy_bg();
\r
531 gp2x_text_out15(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
533 /* draw all 10 slots */
\r
535 for (i = 0; i < 10; i++, y+=10)
\r
537 gp2x_text_out15(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
539 gp2x_text_out15(tl_x, y, "back");
\r
542 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
547 static int savestate_menu_loop(int is_loading)
\r
549 int menu_sel = 10, menu_sel_max = 10;
\r
550 unsigned long inp = 0;
\r
552 state_check_slots();
\r
556 draw_savestate_menu(menu_sel, is_loading);
\r
557 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
558 if(inp & GP2X_UP ) {
\r
560 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
561 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
563 if(inp & GP2X_DOWN) {
\r
565 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
566 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
568 if(inp & GP2X_B) { // save/load
\r
569 if (menu_sel < 10) {
\r
570 state_slot = menu_sel;
\r
571 if (emu_SaveLoadGame(is_loading, 0)) {
\r
572 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
578 if(inp & GP2X_X) return 1;
\r
583 // -------------- key config --------------
\r
585 static char *usb_joy_key_name(int joy, int num)
\r
587 static char name[16];
\r
590 case 0: sprintf(name, "Joy%i UP", joy); break;
\r
591 case 1: sprintf(name, "Joy%i DOWN", joy); break;
\r
592 case 2: sprintf(name, "Joy%i LEFT", joy); break;
\r
593 case 3: sprintf(name, "Joy%i RIGHT", joy); break;
\r
594 default:sprintf(name, "Joy%i b%i", joy, num-3); break;
\r
599 static char *action_binds(int player_idx, int action_mask)
\r
601 static char strkeys[32*5];
\r
605 for (i = 0; i < 32; i++) // i is key index
\r
607 if (Settings.KeyBinds[i] & action_mask)
\r
609 if (player_idx >= 0 && ((Settings.KeyBinds[i] >> 16) & 3) != player_idx) continue;
\r
610 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }
\r
611 else strcpy(strkeys, gp2xKeyNames[i]);
\r
614 for (joy = 0; joy < num_of_joys; joy++)
\r
616 for (i = 0; i < 32; i++)
\r
618 if (Settings.JoyBinds[joy][i] & action_mask)
\r
620 if (player_idx >= 0 && ((Settings.KeyBinds[i] >> 16) & 3) != player_idx) continue;
\r
622 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
\r
625 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
\r
633 static void unbind_action(int action)
\r
637 for (i = 0; i < 32; i++)
\r
638 Settings.KeyBinds[i] &= ~action;
\r
639 for (u = 0; u < 4; u++)
\r
640 for (i = 0; i < 32; i++)
\r
641 Settings.JoyBinds[u][i] &= ~action;
\r
644 static int count_bound_keys(int action, int is_joy)
\r
646 int i, u, keys = 0;
\r
650 for (u = 0; u < 4; u++)
\r
651 for (i = 0; i < 32; i++)
\r
652 if (Settings.JoyBinds[u][i] & action) keys++;
\r
656 for (i = 0; i < 32; i++)
\r
657 if (Settings.KeyBinds[i] & action) keys++;
\r
662 typedef struct { char *name; int mask; } bind_action_t;
\r
664 static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel)
\r
666 int x, y, tl_y = 40, i;
\r
668 gp2x_fceu_copy_bg();
\r
669 if (player_idx >= 0)
\r
670 gp2x_text_out15(80, 20, "Player %i controls", player_idx + 1);
\r
671 else gp2x_text_out15(80, 20, "Emulator controls");
\r
674 for (i = 0; i < opt_cnt; i++, y+=10)
\r
675 gp2x_text_out15(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));
\r
677 gp2x_text_out15(x, y, "Done");
\r
680 gp2x_text_out15(x - 16, tl_y + sel*10, ">");
\r
682 if (sel < opt_cnt) {
\r
683 gp2x_text_out15(30, 190, "Press a button to bind/unbind");
\r
684 gp2x_text_out15(30, 200, "Use VOL+ to clear");
\r
685 gp2x_text_out15(30, 210, "To bind UP/DOWN, hold VOL-");
\r
686 gp2x_text_out15(30, 220, "Select \"Done\" to exit");
\r
688 gp2x_text_out15(30, 220, "Press B or X to exit");
\r
693 static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)
\r
695 int joy = 0, sel = 0, menu_sel_max = opt_cnt, i;
\r
696 unsigned long inp = 0;
\r
700 draw_key_config(opts, opt_cnt, player_idx, sel);
\r
701 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS|GP2X_VOL_DOWN|GP2X_VOL_UP, &joy);
\r
702 // printf("got %08lX from joy %i\n", inp, joy);
\r
704 if (!(inp & GP2X_VOL_DOWN)) {
\r
705 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }
\r
706 if(inp & GP2X_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }
\r
708 if (sel >= opt_cnt) {
\r
709 if (inp & (GP2X_B|GP2X_X)) break;
\r
712 // if we are here, we want to bind/unbind something
\r
713 if (inp & GP2X_VOL_UP)
\r
714 unbind_action(opts[sel].mask);
\r
715 inp &= CONFIGURABLE_KEYS;
\r
716 for (i = 0; i < 32; i++)
\r
717 if (inp & (1 << i)) {
\r
718 if (count_bound_keys(opts[sel].mask, 0) >= 2)
\r
719 Settings.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only
\r
720 else Settings.KeyBinds[i] ^= opts[sel].mask;
\r
721 if (player_idx >= 0) {
\r
722 Settings.KeyBinds[i] &= ~(3 << 16);
\r
723 Settings.KeyBinds[i] |= player_idx << 16;
\r
726 } else if (sel < opt_cnt) {
\r
727 for (i = 0; i < 32; i++)
\r
728 if (inp & (1 << i)) {
\r
729 if (count_bound_keys(opts[sel].mask, 1) >= 1) // disallow combos for usbjoy
\r
730 Settings.JoyBinds[joy-1][i] &= ~opts[sel].mask;
\r
731 else Settings.JoyBinds[joy-1][i] ^= opts[sel].mask;
\r
732 if (player_idx >= 0) {
\r
733 Settings.JoyBinds[joy-1][i] &= ~(3 << 16);
\r
734 Settings.JoyBinds[joy-1][i] |= player_idx << 16;
\r
741 static void draw_kc_sel(int menu_sel)
\r
743 int tl_x = 25+40, tl_y = 60, y, i;
\r
747 gp2x_fceu_copy_bg();
\r
748 gp2x_text_out15(tl_x, y, "Player 1");
\r
749 gp2x_text_out15(tl_x, (y+=10), "Player 2");
\r
750 gp2x_text_out15(tl_x, (y+=10), "Emulator controls");
\r
751 gp2x_text_out15(tl_x, (y+=10), "Done");
\r
754 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
757 gp2x_text_out15(tl_x, (y=110), "USB joys detected:");
\r
758 if (num_of_joys > 0) {
\r
759 for (i = 0; i < num_of_joys; i++) {
\r
760 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
\r
761 gp2x_text_out15(tl_x, (y+=10), "%i: %s", i+1, joyname);
\r
764 gp2x_text_out15(tl_x, (y+=10), "none");
\r
770 // b_turbo,a_turbo RLDU SEBA
\r
771 static bind_action_t ctrl_actions[] =
\r
774 { "DOWN ", 0x020 },
\r
775 { "LEFT ", 0x040 },
\r
776 { "RIGHT ", 0x080 },
\r
779 { "A TURBO", 0x100 },
\r
780 { "B TURBO", 0x200 },
\r
781 { "START ", 0x008 },
\r
782 { "SELECT ", 0x004 },
\r
785 static bind_action_t emuctrl_actions[] =
\r
787 { "Save State ", 1<<31 },
\r
788 { "Load State ", 1<<30 },
\r
789 { "Next State Slot ", 1<<29 },
\r
790 { "Prev State Slot ", 1<<28 },
\r
791 { "FDS Insert/Eject ", 1<<27 },
\r
792 { "FDS Select Disk ", 1<<26 },
\r
793 { "VSUni Insert Coin", 1<<25 },
\r
796 static void kc_sel_loop(void)
\r
798 int menu_sel = 3, menu_sel_max = 3;
\r
799 unsigned long inp = 0;
\r
803 draw_kc_sel(menu_sel);
\r
804 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
805 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
806 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
808 switch (menu_sel) {
\r
809 case 0: key_config_loop(ctrl_actions, 10, 0); return;
\r
810 case 1: key_config_loop(ctrl_actions, 8, 1); return;
\r
811 case 2: key_config_loop(emuctrl_actions,
\r
812 sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return;
\r
816 if(inp & GP2X_X) return;
\r
821 // --------- FCEU options ----------
\r
823 extern int ntsccol,ntschue,ntsctint;
\r
824 extern int srendlinev[2];
\r
825 extern int erendlinev[2];
\r
826 extern int eoptions;
\r
829 static void int_incdec(int *p, int inc, int min, int max)
\r
832 if (*p < min) *p = min;
\r
833 else if (*p > max) *p = max;
\r
836 static void draw_fcemenu_options(int menu_sel)
\r
838 int tl_x = 25, tl_y = 60, y;
\r
841 gp2x_fceu_copy_bg();
\r
843 gp2x_text_out15(tl_x, y, "NTSC Color Emulation %s", ntsccol?"ON":"OFF"); // 0
\r
844 gp2x_text_out15(tl_x, (y+=10), " Tint (default: 56) %i", ntsctint);
\r
845 gp2x_text_out15(tl_x, (y+=10), " Hue (default: 72) %i", ntschue);
\r
846 gp2x_text_out15(tl_x, (y+=10), "First visible line (NTSC) %i", srendlinev[0]);
\r
847 gp2x_text_out15(tl_x, (y+=10), "Last visible line (NTSC) %i", erendlinev[0]);
\r
848 gp2x_text_out15(tl_x, (y+=10), "First visible line (PAL) %i", srendlinev[1]); // 5
\r
849 gp2x_text_out15(tl_x, (y+=10), "Last visible line (PAL) %i", erendlinev[1]);
\r
850 gp2x_text_out15(tl_x, (y+=10), "Clip 8 left/right columns %s", (eoptions&EO_CLIPSIDES)?"ON":"OFF");
\r
851 gp2x_text_out15(tl_x, (y+=10), "Disable 8 sprite limit %s", "TODO");
\r
852 gp2x_text_out15(tl_x, (y+=10), "Done"); // 9
\r
855 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
860 static void fcemenu_loop_options(void)
\r
862 int menu_sel = 0, menu_sel_max = 9, i;
\r
863 unsigned long inp = 0;
\r
865 FCEUI_GetNTSCTH(&ntsctint, &ntschue);
\r
869 draw_fcemenu_options(menu_sel);
\r
870 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
871 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
872 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
873 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
874 switch (menu_sel) {
\r
875 case 0: ntsccol = !ntsccol; break;
\r
876 case 7: eoptions^=EO_CLIPSIDES; break;
\r
880 if(inp & (GP2X_X|GP2X_A)) {
\r
883 if(srendlinev[i]<0 || srendlinev[i]>239) srendlinev[i]=0;
\r
884 if(erendlinev[i]<srendlinev[i] || erendlinev[i]>239) erendlinev[i]=239;
\r
886 FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
\r
887 FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
\r
890 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
891 switch (menu_sel) {
\r
892 case 1: int_incdec(&ntsctint, (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break;
\r
893 case 2: int_incdec(&ntschue, (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break;
\r
894 case 3: int_incdec(&srendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;
\r
895 case 4: int_incdec(&erendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;
\r
896 case 5: int_incdec(&srendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;
\r
897 case 6: int_incdec(&erendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break;
\r
903 // -------------- options --------------
\r
905 static void draw_menu_options(int menu_sel)
\r
907 int tl_x = 25, tl_y = 32, y;
\r
908 char strframeskip[8], *strscaling, *strssconfirm;
\r
909 char *mms = mmuhack_status ? "active) " : "inactive)";
\r
911 if (Settings.frameskip < 0)
\r
912 strcpy(strframeskip, "Auto");
\r
913 else sprintf(strframeskip, "%i", Settings.frameskip);
\r
914 switch (Settings.scaling) {
\r
915 default: strscaling = " OFF"; break;
\r
916 case 1: strscaling = "hw horizontal"; break;
\r
917 case 2: strscaling = "hw horiz. + vert."; break;
\r
918 case 3: strscaling = "sw horizontal"; break;
\r
920 switch (Settings.sstate_confirm) {
\r
921 default: strssconfirm = "OFF"; break;
\r
922 case 1: strssconfirm = "writes"; break;
\r
923 case 2: strssconfirm = "loads"; break;
\r
924 case 3: strssconfirm = "both"; break;
\r
928 gp2x_fceu_copy_bg();
\r
930 gp2x_text_out15(tl_x, y, "Scaling: %s", strscaling); // 0
\r
931 gp2x_text_out15(tl_x, (y+=10), "Show FPS %s", Settings.showfps?"ON":"OFF"); // 1
\r
932 gp2x_text_out15(tl_x, (y+=10), "Frameskip %s", strframeskip); // 2
\r
933 gp2x_text_out15(tl_x, (y+=10), "Enable sound %s", soundvol?"ON":"OFF");
\r
934 gp2x_text_out15(tl_x, (y+=10), "Sound Rate: %5iHz", Settings.sound_rate); // 4
\r
935 gp2x_text_out15(tl_x, (y+=10), "Force Region: %s",
\r
936 Settings.region_force == 2 ? "PAL" : Settings.region_force == 1 ? "NTSC" : "OFF"); // 5
\r
937 gp2x_text_out15(tl_x, (y+=10), "Use SRAM savestates %s", "OFF");
\r
938 gp2x_text_out15(tl_x, (y+=10), "Turbo rate %iHz", (Settings.turbo_rate_add*60/2) >> 24);
\r
939 gp2x_text_out15(tl_x, (y+=10), "Confirm savestate %s", strssconfirm); // 8
\r
940 gp2x_text_out15(tl_x, (y+=10), "Save slot %i", CurrentState);
\r
941 gp2x_text_out15(tl_x, (y+=10), "Faster RAM timings %s", Settings.ramtimings?"ON":"OFF");
\r
942 gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s", mms, Settings.mmuhack?"ON":"OFF"); // 11
\r
943 gp2x_text_out15(tl_x, (y+=10), "Gamma correction %i.%02i", Settings.gamma / 100, Settings.gamma%100);
\r
944 gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock %iMhz", Settings.cpuclock); // 13
\r
945 gp2x_text_out15(tl_x, (y+=10), "[FCE Ultra options]");
\r
946 gp2x_text_out15(tl_x, (y+=10), "Save cfg as default");
\r
948 gp2x_text_out15(tl_x, (y+=10), "Save cfg for current game only");
\r
951 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
956 static int sndrate_prevnext(int rate, int dir)
\r
958 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
960 for (i = 0; i < 5; i++)
\r
961 if (rates[i] == rate) break;
\r
964 if (i > 4) return dir ? 44100 : 22050;
\r
965 if (i < 0) return dir ? 11025 : 8000;
\r
969 static void config_commit(void)
\r
971 gp2x_cpuclock_gamma_update();
\r
972 if (Settings.region_force)
\r
973 FCEUI_SetVidSystem(Settings.region_force - 1);
\r
976 static int menu_loop_options(void)
\r
978 static int menu_sel = 0;
\r
979 int menu_sel_max = 15;
\r
980 unsigned long inp = 0;
\r
982 if (fceugi) menu_sel_max++;
\r
986 draw_menu_options(menu_sel);
\r
987 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
988 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
989 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
990 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
991 switch (menu_sel) {
\r
992 case 1: Settings.showfps = !Settings.showfps; break;
\r
993 case 3: soundvol = soundvol ? 0 : 100; break;
\r
994 case 10: Settings.ramtimings = !Settings.ramtimings; break;
\r
995 case 11: Settings.mmuhack = !Settings.mmuhack; break;
\r
996 case 14: fcemenu_loop_options(); break;
\r
997 case 15: // done (update and write)
\r
1001 case 16: // done (update and write for current game)
\r
1003 if (lastLoadedGameName[0])
\r
1004 SaveConfig(lastLoadedGameName);
\r
1008 if(inp & (GP2X_X|GP2X_A)) {
\r
1010 return 0; // done (update, no write)
\r
1012 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
1013 switch (menu_sel) {
\r
1014 case 0: int_incdec(&Settings.scaling, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;
\r
1015 case 2: int_incdec(&Settings.frameskip, (inp & GP2X_LEFT) ? -1 : 1, -1, 32); break;
\r
1017 Settings.sound_rate = sndrate_prevnext(Settings.sound_rate, inp & GP2X_RIGHT);
\r
1020 case 5: int_incdec(&Settings.region_force, (inp & GP2X_LEFT) ? -1 : 1, 0, 2); break;
\r
1022 int hz = Settings.turbo_rate_add*60/2 >> 24;
\r
1023 int_incdec(&hz, (inp & GP2X_LEFT) ? -1 : 1, 1, 30);
\r
1024 Settings.turbo_rate_add = (hz*2 << 24) / 60 + 1;
\r
1027 case 8: int_incdec(&Settings.sstate_confirm, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;
\r
1028 case 9: int_incdec(&CurrentState, (inp & GP2X_LEFT) ? -1 : 1, 0, 9); break;
\r
1029 case 12: int_incdec(&Settings.gamma, (inp & GP2X_LEFT) ? -1 : 1, 0, 300); break;
\r
1031 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
1032 Settings.cpuclock += (inp & GP2X_LEFT) ? -1 : 1;
\r
1033 if (Settings.cpuclock < 0) Settings.cpuclock = 0; // 0 ~ do not change
\r
1034 draw_menu_options(menu_sel);
\r
1043 // -------------- credits --------------
\r
1045 static void draw_menu_credits(void)
\r
1049 //int tl_x = 15, tl_y = 70;
\r
1050 gp2x_fceu_copy_bg();
\r
1052 sprintf(vstr, "GPFCE v" GP2X_PORT_VERSION " rev%i", GP2X_PORT_REV);
\r
1053 gp2x_text_out15(20, 30, vstr);
\r
1054 gp2x_text_out15(20, 40, "(c) notaz, 2007");
\r
1056 gp2x_text_out15(20, 70, "Based on FCE Ultra versions");
\r
1057 gp2x_text_out15(20, 80, "0.81 and 0.98.1x");
\r
1059 gp2x_text_out15(20, 110, " - Credits - ");
\r
1060 gp2x_text_out15(20, 130, "Bero: FCE");
\r
1061 gp2x_text_out15(20, 140, "Xodnizel: FCE Ultra");
\r
1062 gp2x_text_out15(20, 150, "zzhu8192: original port");
\r
1063 gp2x_text_out15(20, 160, "rlyeh: minimal lib");
\r
1064 gp2x_text_out15(20, 170, "Hermes, theoddbot, god_at_hell:");
\r
1065 gp2x_text_out15(20, 180, " cpuctrl, gamma libs");
\r
1066 gp2x_text_out15(20, 190, "Squidge: squidgehack");
\r
1068 gp2x_video_flip();
\r
1072 // -------------- root menu --------------
\r
1074 static void draw_menu_root(int menu_sel)
\r
1076 int tl_x = 30, tl_y = 128, y;
\r
1077 gp2x_fceu_copy_bg();
\r
1081 gp2x_text_out15(tl_x, y, "Resume game");
\r
1082 gp2x_text_out15(tl_x, (y+=10), "Save State");
\r
1083 gp2x_text_out15(tl_x, (y+=10), "Load State");
\r
1084 gp2x_text_out15(tl_x, (y+=10), "Reset game");
\r
1088 gp2x_text_out15(tl_x, (y+=10), "Load new ROM");
\r
1089 gp2x_text_out15(tl_x, (y+=10), "Options");
\r
1090 gp2x_text_out15(tl_x, (y+=10), "Controls");
\r
1091 gp2x_text_out15(tl_x, (y+=10), "Credits");
\r
1092 gp2x_text_out15(tl_x, (y+=10), "Exit");
\r
1094 // if (PicoPatches)
\r
1095 // gp2x_text_out15(tl_x, (y+=10), "Patches / GameGenie");
\r
1098 gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");
\r
1100 if (menuErrorMsg[0]) gp2x_text_out15(1, 230, menuErrorMsg);
\r
1103 sprintf(vstr, "v" GP2X_PORT_VERSION " r%i", GP2X_PORT_REV);
\r
1104 gp2x_text_out15(320-strlen(vstr)*8-1, 230, vstr);
\r
1106 gp2x_video_flip();
\r
1110 static int menu_loop_root(void)
\r
1112 int ret, menu_sel_max = 8, menu_sel_min = 4;
\r
1113 static int menu_sel = 4;
\r
1114 unsigned long inp = 0;
\r
1115 char curr_path[PATH_MAX], *selfname;
\r
1118 if ( (tstf = fopen(lastLoadedGameName, "rb")) )
\r
1121 strncpy(curr_path, lastLoadedGameName, sizeof(curr_path));
\r
1122 curr_path[sizeof(curr_path)-1] = 0;
\r
1126 getcwd(curr_path, PATH_MAX);
\r
1129 if (fceugi) menu_sel_min = 0;
\r
1130 // TODO if (PicoPatches) menu_sel_max = 9;
\r
1131 if (menu_sel < menu_sel_min || menu_sel > menu_sel_max)
\r
1132 menu_sel = menu_sel_min;
\r
1134 /* make sure action buttons are not pressed on entering menu */
\r
1135 draw_menu_root(menu_sel);
\r
1136 while (gp2x_joystick_read(1) & (GP2X_B|GP2X_X|GP2X_SELECT)) usleep(50*1000);
\r
1140 draw_menu_root(menu_sel);
\r
1141 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
1142 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }
\r
1143 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }
\r
1144 if(inp &(GP2X_SELECT|GP2X_X)){
\r
1146 while (gp2x_joystick_read(1) & GP2X_X) usleep(50*1000); // wait until X is released
\r
1151 if(inp & GP2X_B ) {
\r
1152 switch (menu_sel) {
\r
1153 case 0: // resume game
\r
1155 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1160 case 1: // save state
\r
1162 /*if(savestate_menu_loop(0))
\r
1164 FCEUI_SaveState();
\r
1166 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1170 case 2: // load state
\r
1172 /*if(savestate_menu_loop(1))
\r
1174 FCEUI_LoadState();
\r
1176 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1180 case 3: // reset game
\r
1182 FCEU_DoSimpleCommand(FCEUNPCMD_RESET);
\r
1187 case 4: // select rom
\r
1188 selfname = romsel_loop(curr_path);
\r
1190 printf("selected file: %s\n", selfname);
\r
1191 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1195 case 5: // options
\r
1196 ret = menu_loop_options();
\r
1197 if (ret == 1) continue; // status update
\r
1199 case 6: // controls
\r
1202 case 7: // credits
\r
1203 draw_menu_credits();
\r
1205 inp = wait_for_input(GP2X_B|GP2X_X);
\r
1209 case 9: // patches/gg
\r
1213 menuErrorMsg[0] = 0; // clear error msg
\r
1218 static void menu_prepare_bg(void)
\r
1223 static void menu_gfx_prepare(void)
\r
1225 menu_prepare_bg();
\r
1228 gp2x_video_changemode(16);
\r
1229 gp2x_video_set_offs(0);
\r
1230 gp2x_video_RGB_setscaling(0, 320, 240);
\r
1231 gp2x_video_flip();
\r
1235 int gp2x_menu_do(void)
\r
1239 menu_gfx_prepare();
\r
1241 ret = menu_loop_root();
\r
1243 menuErrorMsg[0] = 0;
\r