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
17 #include "../common/emu.h"
\r
18 #include "../common/menu.h"
\r
19 #include "../common/arm_utils.h"
\r
20 #include "../common/readpng.h"
\r
21 #include "version.h"
\r
23 #include <Pico/PicoInt.h>
\r
24 #include <Pico/Patch.h>
\r
25 #include <zlib/zlib.h>
\r
27 #ifndef _DIRENT_HAVE_D_TYPE
\r
28 #error "need d_type for file browser
\r
31 extern int mmuhack_status;
\r
33 const char * const keyNames[] = {
\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 static void menu_darken_bg(void *dst, int pixels, int darker);
\r
41 static void menu_prepare_bg(int use_game_bg);
\r
43 static unsigned long inp_prev = 0;
\r
44 static int inp_prevjoy = 0;
\r
46 static unsigned long wait_for_input(unsigned long interesting)
\r
49 static int repeats = 0, wait = 20;
\r
52 if (repeats == 2) wait = 3;
\r
53 else if (repeats == 4) wait = 2;
\r
54 else if (repeats == 6) wait = 1;
\r
56 for (i = 0; i < wait && inp_prev == gp2x_joystick_read(1); i++) {
\r
57 if (i == 0) repeats++;
\r
61 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
\r
66 if (release || ret != inp_prev) {
\r
70 if (wait > 6 && (ret&(GP2X_UP|GP2X_LEFT|GP2X_DOWN|GP2X_RIGHT)))
\r
75 // we don't need diagonals in menus
\r
76 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
77 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
78 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
79 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
84 static unsigned long input2_read(unsigned long interesting, int *joy)
\r
92 if ((ret = gp2x_joystick_read(0) & interesting)) break;
\r
93 gp2x_usbjoy_update();
\r
94 for (i = 0; i < num_of_joys; i++) {
\r
95 ret = gp2x_usbjoy_check2(i);
\r
96 if (ret) { *joy = i + 1; break; }
\r
105 // similar to wait_for_input(), but returns joy num
\r
106 static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
\r
109 const int wait = 300*1000;
\r
112 if (inp_prevjoy == 0) inp_prev &= interesting;
\r
113 for (i = 0; i < 6; i++) {
\r
114 ret = input2_read(interesting, joy);
\r
115 if (*joy != inp_prevjoy || ret != inp_prev) break;
\r
119 while ( !(ret = input2_read(interesting, joy)) ) {
\r
124 inp_prevjoy = *joy;
\r
126 // handle only 1 event at a time
\r
127 for (i = 1; i != 0; i <<= 1)
\r
128 if (ret & i) { ret &= i; break; }
\r
129 // ... but allow select
\r
130 ret |= inp_prev & GP2X_SELECT;
\r
135 static void menu_flip(void)
\r
137 gp2x_video_flush_cache();
\r
138 gp2x_video_flip2();
\r
142 // --------- loading ROM screen ----------
\r
144 static int cdload_called = 0;
\r
146 static void load_progress_cb(int percent)
\r
148 int ln, len = percent * 320 / 100;
\r
149 unsigned short *dst = (unsigned short *)gp2x_screen + 320*20;
\r
151 if (len > 320) len = 320;
\r
152 for (ln = 8; ln > 0; ln--, dst += 320)
\r
153 memset(dst, 0xff, len*2);
\r
157 static void cdload_progress_cb(int percent)
\r
159 int ln, len = percent * 320 / 100;
\r
160 unsigned short *dst = (unsigned short *)gp2x_screen + 320*20;
\r
162 memset(dst, 0xff, 320*2*8);
\r
164 smalltext_out16(1, 3*10, "Processing CD image / MP3s", 0xffff);
\r
165 smalltext_out16_lim(1, 4*10, romFileName, 0xffff, 80);
\r
168 if (len > 320) len = 320;
\r
169 for (ln = 8; ln > 0; ln--, dst += 320)
\r
170 memset(dst, 0xff, len*2);
\r
175 void menu_romload_prepare(const char *rom_name)
\r
177 const char *p = rom_name + strlen(rom_name);
\r
178 while (p > rom_name && *p != '/') p--;
\r
180 if (rom_loaded) gp2x_pd_clone_buffer2();
\r
181 else memset(gp2x_screen, 0, 320*240*2);
\r
183 smalltext_out16(1, 1, "Loading", 0xffff);
\r
184 smalltext_out16_lim(1, 10, p, 0xffff, 53);
\r
185 gp2x_memcpy_buffers(3, gp2x_screen, 0, 320*240*2);
\r
187 PicoCartLoadProgressCB = load_progress_cb;
\r
188 PicoCDLoadProgressCB = cdload_progress_cb;
\r
192 void menu_romload_end(void)
\r
194 PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL;
\r
195 smalltext_out16(1, cdload_called ? 60 : 30, "Starting emulation...", 0xffff);
\r
199 // -------------- ROM selector --------------
\r
201 // rrrr rggg gggb bbbb
\r
202 static unsigned short file2color(const char *fname)
\r
204 const char *ext = fname + strlen(fname) - 3;
\r
205 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso", "cso", "cue" };
\r
206 static const char *other_exts[] = { "gmv", "pat" };
\r
209 if (ext < fname) ext = fname;
\r
210 for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)
\r
211 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;
\r
212 for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)
\r
213 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
\r
217 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
222 n--; // exclude current dir (".")
\r
224 gp2x_pd_clone_buffer2();
\r
227 menu_darken_bg(gp2x_screen, 320*240, 0);
\r
230 menu_darken_bg((char *)gp2x_screen + 320*120*2, 320*8, 0);
\r
233 smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);
\r
234 for (i = 0; i < n; i++) {
\r
236 if (pos < 0) continue;
\r
237 if (pos > 23) break;
\r
238 if (namelist[i+1]->d_type == DT_DIR) {
\r
239 smalltext_out16_lim(14, pos*10, "/", 0xfff6, 1);
\r
240 smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);
\r
242 unsigned short color = file2color(namelist[i+1]->d_name);
\r
243 smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2);
\r
246 text_out16(5, 120, ">");
\r
250 static int scandir_cmp(const void *p1, const void *p2)
\r
252 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
253 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
254 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
255 if ((*d2)->d_type == DT_DIR) return 1;
\r
256 return alphasort(d1, d2);
\r
259 static char *filter_exts[] = {
\r
260 ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
264 static int scandir_filter(const struct dirent *ent)
\r
269 if (ent == NULL || ent->d_name == NULL) return 0;
\r
270 if (strlen(ent->d_name) < 5) return 1;
\r
272 p = ent->d_name + strlen(ent->d_name) - 4;
\r
274 for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)
\r
276 if (strcmp(p, filter_exts[i]) == 0) return 0;
\r
282 static void do_delete(const char *fpath, const char *fname)
\r
286 gp2x_pd_clone_buffer2();
\r
289 menu_darken_bg(gp2x_screen, 320*240, 0);
\r
291 len = strlen(fname);
\r
292 if (len > 320/6) len = 320/6;
\r
294 text_out16(320/2 - 15*8/2, 80, "About to delete");
\r
295 smalltext_out16_lim(320/2 - len*6/2, 95, fname, 0xbdff, len);
\r
296 text_out16(320/2 - 13*8/2, 110, "Are you sure?");
\r
297 text_out16(320/2 - 25*8/2, 120, "(Y - confirm, X - cancel)");
\r
301 while (gp2x_joystick_read(1) & (GP2X_A|GP2X_SELECT)) usleep(50*1000);
\r
302 inp = wait_for_input(GP2X_Y|GP2X_X);
\r
307 static char *romsel_loop(char *curr_path)
\r
309 struct dirent **namelist;
\r
312 unsigned long inp = 0;
\r
313 char *ret = NULL, *fname = NULL;
\r
316 // is this a dir or a full path?
\r
317 if ((dir = opendir(curr_path))) {
\r
321 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
326 n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
329 n = scandir("/", &namelist, scandir_filter, scandir_cmp);
\r
332 printf("dir: "); printf(curr_path); printf("\n");
\r
339 if (fname != NULL) {
\r
341 for (i = 1; i < n; i++) {
\r
342 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
351 draw_dirlist(curr_path, namelist, n, sel);
\r
352 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_A|GP2X_B|GP2X_X|GP2X_SELECT);
\r
353 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
354 if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
355 if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
356 if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; }
\r
357 if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
358 if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
359 if ((inp & GP2X_B) || (inp & (GP2X_SELECT|GP2X_A)) == (GP2X_SELECT|GP2X_A)) // enter dir/select || delete
\r
362 if (namelist[sel+1]->d_type == DT_REG)
\r
364 strcpy(romFileName, curr_path);
\r
365 strcat(romFileName, "/");
\r
366 strcat(romFileName, namelist[sel+1]->d_name);
\r
367 if (inp & GP2X_B) { // return sel
\r
371 do_delete(romFileName, namelist[sel+1]->d_name);
\r
373 while (n--) free(namelist[n]);
\r
378 else if (namelist[sel+1]->d_type == DT_DIR)
\r
382 if (!(inp & GP2X_B)) continue;
\r
383 newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
384 newdir = malloc(newlen);
\r
385 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
386 char *start = curr_path;
\r
387 p = start + strlen(start) - 1;
\r
388 while (*p == '/' && p > start) p--;
\r
389 while (*p != '/' && p > start) p--;
\r
390 if (p <= start) strcpy(newdir, "/");
\r
391 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
393 strcpy(newdir, curr_path);
\r
394 p = newdir + strlen(newdir) - 1;
\r
395 while (*p == '/' && p >= newdir) *p-- = 0;
\r
396 strcat(newdir, "/");
\r
397 strcat(newdir, namelist[sel+1]->d_name);
\r
399 ret = romsel_loop(newdir);
\r
405 // unknown file type, happens on NTFS mounts. Try to guess.
\r
406 FILE *tstf; int tmp;
\r
407 strcpy(romFileName, curr_path);
\r
408 strcat(romFileName, "/");
\r
409 strcat(romFileName, namelist[sel+1]->d_name);
\r
410 tstf = fopen(romFileName, "rb");
\r
413 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
414 namelist[sel+1]->d_type = DT_REG;
\r
415 else namelist[sel+1]->d_type = DT_DIR;
\r
421 if(inp & GP2X_X) break; // cancel
\r
425 while (n--) free(namelist[n]);
\r
432 // ------------ debug menu ------------
\r
434 char *debugString(void);
\r
436 static void draw_debug(void)
\r
438 char *p, *str = debugString();
\r
441 gp2x_pd_clone_buffer2();
\r
444 for (line = 0; line < 24; line++)
\r
446 while (*p && *p != '\n') p++;
\r
448 if (len > 55) len = 55;
\r
449 smalltext_out16_lim(1, line*10, str, 0xffff, len);
\r
450 if (*p == 0) break;
\r
456 static void debug_menu_loop(void)
\r
459 wait_for_input(GP2X_B|GP2X_X);
\r
462 // ------------ patch/gg menu ------------
\r
464 static void draw_patchlist(int sel)
\r
466 int start, i, pos, active;
\r
470 gp2x_pd_clone_buffer2();
\r
472 for (i = 0; i < PicoPatchCount; i++) {
\r
474 if (pos < 0) continue;
\r
475 if (pos > 23) break;
\r
476 active = PicoPatches[i].active;
\r
477 smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3);
\r
478 smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6);
\r
481 if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4);
\r
483 text_out16(5, 120, ">");
\r
488 static void patches_menu_loop(void)
\r
491 unsigned long inp = 0;
\r
495 draw_patchlist(menu_sel);
\r
496 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
497 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
498 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
499 if(inp &(GP2X_LEFT|GP2X_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
500 if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
501 if(inp & GP2X_B) { // action
\r
502 if (menu_sel < PicoPatchCount)
\r
503 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
506 if(inp & GP2X_X) return;
\r
511 // ------------ savestate loader ------------
\r
513 static int state_slot_flags = 0;
\r
515 static void state_check_slots(void)
\r
519 state_slot_flags = 0;
\r
521 for (slot = 0; slot < 10; slot++)
\r
523 if (emu_checkSaveFile(slot))
\r
525 state_slot_flags |= 1 << slot;
\r
530 static void draw_savestate_bg(int slot)
\r
532 struct PicoVideo tmp_pv;
\r
533 unsigned short tmp_cram[0x40];
\r
534 unsigned short tmp_vsram[0x40];
\r
535 void *tmp_vram, *file;
\r
538 fname = emu_GetSaveFName(1, 0, slot);
\r
539 if (!fname) return;
\r
541 tmp_vram = malloc(sizeof(Pico.vram));
\r
542 if (tmp_vram == NULL) return;
\r
544 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
545 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
546 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
547 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
549 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
550 file = gzopen(fname, "rb");
\r
551 emu_setSaveStateCbs(1);
\r
553 file = fopen(fname, "rb");
\r
554 emu_setSaveStateCbs(0);
\r
558 if (PicoAHW & PAHW_MCD) {
\r
559 PicoCdLoadStateGfx(file);
\r
561 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
562 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
563 areaSeek(file, 0x2000, SEEK_CUR);
\r
564 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
565 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
566 areaSeek(file, 0x221a0, SEEK_SET);
\r
567 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
573 menu_prepare_bg(1);
\r
575 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
576 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
577 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
578 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
582 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
584 int tl_x = 25, tl_y = 60, y, i;
\r
586 if (state_slot_flags & (1 << menu_sel))
\r
587 draw_savestate_bg(menu_sel);
\r
588 gp2x_pd_clone_buffer2();
\r
590 text_out16(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
592 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);
\r
594 /* draw all 10 slots */
\r
596 for (i = 0; i < 10; i++, y+=10)
\r
598 text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
600 text_out16(tl_x, y, "back");
\r
605 static int savestate_menu_loop(int is_loading)
\r
607 static int menu_sel = 10;
\r
608 int menu_sel_max = 10;
\r
609 unsigned long inp = 0;
\r
611 state_check_slots();
\r
615 draw_savestate_menu(menu_sel, is_loading);
\r
616 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
617 if(inp & GP2X_UP ) {
\r
619 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
620 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
622 if(inp & GP2X_DOWN) {
\r
624 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
625 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
627 if(inp & GP2X_B) { // save/load
\r
628 if (menu_sel < 10) {
\r
629 state_slot = menu_sel;
\r
630 if (emu_SaveLoadGame(is_loading, 0)) {
\r
631 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
637 if(inp & GP2X_X) return 1;
\r
641 // -------------- key config --------------
\r
643 static char *usb_joy_key_name(int joy, int num)
\r
645 static char name[16];
\r
648 case 0: sprintf(name, "Joy%i UP", joy); break;
\r
649 case 1: sprintf(name, "Joy%i DOWN", joy); break;
\r
650 case 2: sprintf(name, "Joy%i LEFT", joy); break;
\r
651 case 3: sprintf(name, "Joy%i RIGHT", joy); break;
\r
652 default:sprintf(name, "Joy%i b%i", joy, num-3); break;
\r
657 static char *action_binds(int player_idx, int action_mask)
\r
659 static char strkeys[32*5];
\r
663 for (i = 0; i < 32; i++) // i is key index
\r
665 if (currentConfig.KeyBinds[i] & action_mask)
\r
667 if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;
\r
668 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, keyNames[i]); break; }
\r
669 else strcpy(strkeys, keyNames[i]);
\r
672 for (joy = 0; joy < num_of_joys; joy++)
\r
674 for (i = 0; i < 32; i++)
\r
676 if (currentConfig.JoyBinds[joy][i] & action_mask)
\r
678 if (player_idx >= 0 && ((currentConfig.JoyBinds[joy][i] >> 16) & 3) != player_idx) continue;
\r
680 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
\r
683 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
\r
694 static void unbind_action(int action, int pl_idx, int joy)
\r
700 for (i = 0; i < 32; i++) {
\r
701 if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue;
\r
702 currentConfig.KeyBinds[i] &= ~action;
\r
707 for (u = 0; u < 4; u++)
\r
708 for (i = 0; i < 32; i++) {
\r
709 if (pl_idx >= 0 && (currentConfig.JoyBinds[u][i]&0x30000) != (pl_idx<<16)) continue;
\r
710 currentConfig.JoyBinds[u][i] &= ~action;
\r
715 for (i = 0; i < 32; i++) {
\r
716 if (pl_idx >= 0 && (currentConfig.JoyBinds[joy-1][i]&0x30000) != (pl_idx<<16)) continue;
\r
717 currentConfig.JoyBinds[joy-1][i] &= ~action;
\r
722 static int count_bound_keys(int action, int pl_idx, int joy)
\r
728 for (i = 0; i < 32; i++) {
\r
729 if (pl_idx >= 0 && (currentConfig.JoyBinds[joy-1][i]&0x30000) != (pl_idx<<16)) continue;
\r
730 if (currentConfig.JoyBinds[joy-1][i] & action) keys++;
\r
735 for (i = 0; i < 32; i++) {
\r
736 if (pl_idx >= 0 && (currentConfig.KeyBinds[i]&0x30000) != (pl_idx<<16)) continue;
\r
737 if (currentConfig.KeyBinds[i] & action) keys++;
\r
743 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel)
\r
745 int x, y, tl_y = 40, i;
\r
747 gp2x_pd_clone_buffer2();
\r
748 if (player_idx >= 0) {
\r
749 text_out16(80, 20, "Player %i controls", player_idx + 1);
\r
752 text_out16(80, 20, "Emulator controls");
\r
756 menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 140);
\r
759 for (i = 0; i < opt_cnt; i++, y+=10)
\r
760 text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));
\r
762 text_out16(x, y, "Done");
\r
764 if (sel < opt_cnt) {
\r
765 text_out16(30, 180, "Press a button to bind/unbind");
\r
766 text_out16(30, 190, "Use SELECT to clear");
\r
767 text_out16(30, 200, "To bind UP/DOWN, hold SELECT");
\r
768 text_out16(30, 210, "Select \"Done\" to exit");
\r
770 text_out16(30, 190, "Use Options -> Save cfg");
\r
771 text_out16(30, 200, "to save controls");
\r
772 text_out16(30, 210, "Press B or X to exit");
\r
777 static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)
\r
779 int joy = 0, sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;
\r
780 unsigned long inp = 0;
\r
784 draw_key_config(opts, opt_cnt, player_idx, sel);
\r
785 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);
\r
786 // printf("got %08lX from joy %i\n", inp, joy);
\r
789 if (!(inp & GP2X_SELECT)) {
\r
791 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }
\r
792 if(inp & GP2X_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }
\r
794 if (sel >= opt_cnt) {
\r
795 if (inp & (GP2X_B|GP2X_X)) break;
\r
798 // if we are here, we want to bind/unbind something
\r
799 if ((inp & GP2X_SELECT) && !prev_select)
\r
800 unbind_action(opts[sel].mask, player_idx, -1);
\r
801 prev_select = inp & GP2X_SELECT;
\r
802 inp &= CONFIGURABLE_KEYS;
\r
803 inp &= ~GP2X_SELECT;
\r
804 for (i = 0; i < 32; i++)
\r
805 if (inp & (1 << i)) {
\r
806 if (count_bound_keys(opts[sel].mask, player_idx, 0) >= 2)
\r
807 currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only
\r
808 else currentConfig.KeyBinds[i] ^= opts[sel].mask;
\r
809 if (player_idx >= 0 && (currentConfig.KeyBinds[i] & opts[sel].mask)) {
\r
810 currentConfig.KeyBinds[i] &= ~(3 << 16);
\r
811 currentConfig.KeyBinds[i] |= player_idx << 16;
\r
815 else if (sel < opt_cnt)
\r
817 for (i = 0; i < 32; i++)
\r
818 if (inp & (1 << i)) {
\r
819 int *bind = ¤tConfig.JoyBinds[joy-1][i];
\r
820 if ((*bind & opts[sel].mask) && (player_idx < 0 || player_idx == ((*bind>>16)&3)))
\r
821 *bind &= ~opts[sel].mask;
\r
824 unbind_action(opts[sel].mask, player_idx, joy);
\r
825 *bind = opts[sel].mask;
\r
826 if (player_idx > 0) *bind |= player_idx << 16;
\r
833 static void draw_kc_sel(int menu_sel)
\r
835 int tl_x = 25+40, tl_y = 60, y, i;
\r
839 gp2x_pd_clone_buffer2();
\r
840 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);
\r
842 text_out16(tl_x, y, "Player 1");
\r
843 text_out16(tl_x, (y+=10), "Player 2");
\r
844 text_out16(tl_x, (y+=10), "Emulator controls");
\r
845 text_out16(tl_x, (y+=10), "Done");
\r
848 text_out16(tl_x, (y=110), "USB joys detected:");
\r
849 if (num_of_joys > 0) {
\r
850 for (i = 0; i < num_of_joys; i++) {
\r
851 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
\r
852 text_out16(tl_x, (y+=10), "%i: %s", i+1, joyname);
\r
855 text_out16(tl_x, (y+=10), "none");
\r
862 // player2_flag, reserved, ?, ?,
\r
863 // ?, ?, fast forward, menu
\r
864 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",
\r
865 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"
\r
866 me_bind_action emuctrl_actions[] =
\r
868 { "Load State ", 1<<28 },
\r
869 { "Save State ", 1<<27 },
\r
870 { "Prev Save Slot ", 1<<25 },
\r
871 { "Next Save Slot ", 1<<24 },
\r
872 { "Switch Renderer ", 1<<26 },
\r
873 { "Volume Down ", 1<<30 },
\r
874 { "Volume Up ", 1<<29 },
\r
875 { "Fast forward ", 1<<22 },
\r
876 { "Enter Menu ", 1<<23 },
\r
877 { "Pico Next page ", 1<<21 },
\r
878 { "Pico Prev page ", 1<<20 },
\r
879 { "Pico Switch input", 1<<19 },
\r
883 static void kc_sel_loop(void)
\r
885 int menu_sel = 3, menu_sel_max = 3;
\r
886 unsigned long inp = 0;
\r
887 int is_6button = PicoOpt & POPT_6BTN_PAD;
\r
891 draw_kc_sel(menu_sel);
\r
892 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
893 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
894 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
895 if (inp & GP2X_B) {
\r
896 switch (menu_sel) {
\r
897 case 0: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 0); return;
\r
898 case 1: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 1); return;
\r
899 case 2: key_config_loop(emuctrl_actions,
\r
900 sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return;
\r
901 case 3: if (!rom_loaded) emu_WriteConfig(0); return;
\r
905 if (inp & GP2X_X) return;
\r
910 // --------- sega/mega cd options ----------
\r
912 menu_entry cdopt_entries[] =
\r
914 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1, 0 },
\r
915 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1, 0 },
\r
916 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1, 0 },
\r
917 { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1, 1 },
\r
918 { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, &PicoOpt, 0x0800, 0, 0, 1, 1 },
\r
919 { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, &PicoOpt, 0x0400, 0, 0, 1, 1 },
\r
920 { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1, 1 },
\r
921 { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, &PicoOpt, 0x8000, 0, 0, 1, 1 },
\r
922 { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,&PicoOpt, 0x1000, 0, 0, 1, 1 },
\r
923 { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, &PicoOpt, 0x2000, 0, 0, 1, 1 },
\r
924 { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1, 0 },
\r
927 #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))
\r
928 const int cdopt_entry_count = CDOPT_ENTRY_COUNT;
\r
931 struct bios_names_t
\r
933 char us[32], eu[32], jp[32];
\r
936 static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
938 struct bios_names_t *bios_names = param;
\r
943 case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break;
\r
944 case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break;
\r
945 case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break;
\r
946 case MA_CDOPT_READAHEAD:
\r
947 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
948 else strcpy(ra_buff, " OFF");
\r
949 text_out16(x, y, "ReadAhead buffer %s", ra_buff);
\r
955 static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)
\r
957 int tl_x = 25, tl_y = 60;
\r
958 menu_id selected_id;
\r
961 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
962 else strcpy(ra_buff, " OFF");
\r
964 gp2x_pd_clone_buffer2();
\r
966 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);
\r
968 me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);
\r
970 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
971 if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||
\r
972 (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||
\r
973 (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))
\r
974 text_out16(tl_x, 210, "Press start to test selected BIOS");
\r
979 static void cd_menu_loop_options(void)
\r
981 static int menu_sel = 0;
\r
982 int menu_sel_max = 10;
\r
983 unsigned long inp = 0;
\r
984 struct bios_names_t bios_names;
\r
985 menu_id selected_id;
\r
988 if (emu_findBios(4, &bios)) { // US
\r
989 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
990 strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;
\r
991 } else strcpy(bios_names.us, "NOT FOUND");
\r
993 if (emu_findBios(8, &bios)) { // EU
\r
994 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
995 strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;
\r
996 } else strcpy(bios_names.eu, "NOT FOUND");
\r
998 if (emu_findBios(1, &bios)) { // JP
\r
999 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
1000 strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;
\r
1001 } else strcpy(bios_names.jp, "NOT FOUND");
\r
1005 draw_cd_menu_options(menu_sel, &bios_names);
\r
1006 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);
\r
1007 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1008 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1009 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
1010 if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
1011 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&
\r
1012 selected_id == MA_CDOPT_READAHEAD) {
\r
1013 if (inp & GP2X_LEFT) {
\r
1014 PicoCDBuffers >>= 1;
\r
1015 if (PicoCDBuffers < 2) PicoCDBuffers = 0;
\r
1017 if (PicoCDBuffers < 2) PicoCDBuffers = 2;
\r
1018 else PicoCDBuffers <<= 1;
\r
1019 if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M
\r
1023 if (inp & GP2X_B) { // toggleable options
\r
1024 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&
\r
1025 selected_id == MA_CDOPT_DONE) {
\r
1029 if (inp & GP2X_START) { // BIOS testers
\r
1030 switch (selected_id) {
\r
1031 case MA_CDOPT_TESTBIOS_USA:
\r
1032 if (emu_findBios(4, &bios)) { // test US
\r
1033 strcpy(romFileName, bios);
\r
1034 engineState = PGS_ReloadRom;
\r
1038 case MA_CDOPT_TESTBIOS_EUR:
\r
1039 if (emu_findBios(8, &bios)) { // test EU
\r
1040 strcpy(romFileName, bios);
\r
1041 engineState = PGS_ReloadRom;
\r
1045 case MA_CDOPT_TESTBIOS_JAP:
\r
1046 if (emu_findBios(1, &bios)) { // test JP
\r
1047 strcpy(romFileName, bios);
\r
1048 engineState = PGS_ReloadRom;
\r
1056 if (inp & (GP2X_X|GP2X_A)) return;
\r
1061 // --------- advanced options ----------
\r
1063 menu_entry opt2_entries[] =
\r
1065 { NULL, MB_NONE, MA_OPT2_GAMMA, NULL, 0, 0, 0, 1, 1 },
\r
1066 { "A_SN's gamma curve", MB_ONOFF, MA_OPT2_A_SN_GAMMA, ¤tConfig.EmuOpt, 0x1000, 0, 0, 1, 1 },
\r
1067 { "Perfect vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1, 1 },
\r
1068 { "Disable sprite limit", MB_ONOFF, MA_OPT2_NO_SPRITE_LIM, &PicoOpt, 0x40000, 0, 0, 1, 1 },
\r
1069 { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, &PicoOpt, 0x00004, 0, 0, 1, 1 },
\r
1070 { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, &PicoOpt, 0x00001, 0, 0, 1, 1 },
\r
1071 { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,&PicoOpt, 0x00002, 0, 0, 1, 1 },
\r
1072 { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1, 1 },
\r
1073 { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1, 1 },
\r
1074 { "needs restart:", MB_NONE, MA_NONE, NULL, 0, 0, 0, 1, 0 },
\r
1075 { "craigix's RAM timings", MB_ONOFF, MA_OPT2_RAMTIMINGS, ¤tConfig.EmuOpt, 0x0100, 0, 0, 1, 1 },
\r
1076 { NULL, MB_ONOFF, MA_OPT2_SQUIDGEHACK, ¤tConfig.EmuOpt, 0x0010, 0, 0, 1, 1 },
\r
1077 { "SVP dynarec", MB_ONOFF, MA_OPT2_SVP_DYNAREC, &PicoOpt, 0x20000, 0, 0, 1, 1 },
\r
1078 { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1, 0 },
\r
1081 #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))
\r
1082 const int opt2_entry_count = OPT2_ENTRY_COUNT;
\r
1084 static void menu_opt2_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
1086 if (entry->id == MA_OPT2_GAMMA)
\r
1087 text_out16(x, y, "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);
\r
1088 else if (entry->id == MA_OPT2_SQUIDGEHACK)
\r
1089 text_out16(x, y, "Squidgehack (now %s %s", mmuhack_status ? "active) " : "inactive)",
\r
1090 (currentConfig.EmuOpt&0x0010)?"ON":"OFF");
\r
1094 static void draw_amenu_options(int menu_sel)
\r
1096 int tl_x = 25, tl_y = 50;
\r
1098 gp2x_pd_clone_buffer2();
\r
1100 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);
\r
1102 me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL);
\r
1107 static void amenu_loop_options(void)
\r
1109 static int menu_sel = 0;
\r
1111 unsigned long inp = 0;
\r
1112 menu_id selected_id;
\r
1114 menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;
\r
1118 draw_amenu_options(menu_sel);
\r
1119 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
1120 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1121 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1122 selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);
\r
1123 if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
1124 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&
\r
1125 selected_id == MA_OPT2_GAMMA) {
\r
1126 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
1127 currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;
\r
1128 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
1129 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
1130 draw_amenu_options(menu_sel);
\r
1135 if (inp & GP2X_B) { // toggleable options
\r
1136 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&
\r
1137 selected_id == MA_OPT2_DONE) {
\r
1141 if (inp & (GP2X_X|GP2X_A)) return;
\r
1145 // -------------- options --------------
\r
1148 menu_entry opt_entries[] =
\r
1150 { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1, 1 },
\r
1151 { NULL, MB_RANGE, MA_OPT_SCALING, ¤tConfig.scaling, 0, 0, 3, 1, 1 },
\r
1152 { "Accurate timing (slower)", MB_ONOFF, MA_OPT_ACC_TIMING, &PicoOpt, 0x040, 0, 0, 1, 1 },
\r
1153 { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES, &PicoOpt, 0x080, 0, 0, 1, 1 },
\r
1154 { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x002, 0, 0, 1, 1 },
\r
1155 { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1, 1 },
\r
1156 { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x004, 0, 0, 1, 1 },
\r
1157 { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1, 1 },
\r
1158 { "Use ARM940 core for sound", MB_ONOFF, MA_OPT_ARM940_SOUND, &PicoOpt, 0x200, 0, 0, 1, 1 },
\r
1159 { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, &PicoOpt, 0x020, 0, 0, 1, 1 },
\r
1160 { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1, 1 },
\r
1161 { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x001, 0, 0, 1, 1 },
\r
1162 { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1, 1 },
\r
1163 { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1, 1 },
\r
1164 { NULL, MB_NONE, MA_OPT_CPU_CLOCKS, NULL, 0, 0, 0, 1, 1 },
\r
1165 { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1, 0 },
\r
1166 { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1, 0 },
\r
1167 { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1, 0 },
\r
1168 { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1, 0 },
\r
1169 { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1, 0 },
\r
1172 #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))
\r
1173 const int opt_entry_count = OPT_ENTRY_COUNT;
\r
1176 static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
1178 char *str, str24[24];
\r
1180 switch (entry->id)
\r
1182 case MA_OPT_RENDERER:
\r
1183 if (PicoOpt & POPT_ALT_RENDERER)
\r
1184 str = " 8bit fast";
\r
1185 else if (currentConfig.EmuOpt&0x80)
\r
1186 str = "16bit accurate";
\r
1188 str = " 8bit accurate";
\r
1189 text_out16(x, y, "Renderer: %s", str);
\r
1191 case MA_OPT_SCALING:
\r
1192 switch (currentConfig.scaling) {
\r
1193 default: str = " OFF"; break;
\r
1194 case 1: str = "hw horizontal"; break;
\r
1195 case 2: str = "hw horiz. + vert."; break;
\r
1196 case 3: str = "sw horizontal"; break;
\r
1198 text_out16(x, y, "Scaling: %s", str);
\r
1200 case MA_OPT_FRAMESKIP:
\r
1201 if (currentConfig.Frameskip < 0)
\r
1202 strcpy(str24, "Auto");
\r
1203 else sprintf(str24, "%i", currentConfig.Frameskip);
\r
1204 text_out16(x, y, "Frameskip %s", str24);
\r
1206 case MA_OPT_SOUND_QUALITY:
\r
1207 str = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";
\r
1208 text_out16(x, y, "Sound Quality: %5iHz %s", PsndRate, str);
\r
1210 case MA_OPT_REGION:
\r
1211 text_out16(x, y, "Region: %s", me_region_name(PicoRegionOverride, PicoAutoRgnOrder));
\r
1213 case MA_OPT_CONFIRM_STATES:
\r
1214 switch ((currentConfig.EmuOpt >> 9) & 5) {
\r
1215 default: str = "OFF"; break;
\r
1216 case 1: str = "writes"; break;
\r
1217 case 4: str = "loads"; break;
\r
1218 case 5: str = "both"; break;
\r
1220 text_out16(x, y, "Confirm savestate %s", str);
\r
1222 case MA_OPT_CPU_CLOCKS:
\r
1223 text_out16(x, y, "GP2X CPU clocks %iMhz", currentConfig.CPUclock);
\r
1225 case MA_OPT_SAVECFG:
\r
1227 if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);
\r
1228 text_out16(x, y, "Save cfg as default%s", str24);
\r
1230 case MA_OPT_LOADCFG:
\r
1231 text_out16(x, y, "Load cfg from profile %i", config_slot);
\r
1234 printf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);
\r
1241 static void draw_menu_options(int menu_sel)
\r
1243 int tl_x = 25, tl_y = 24;
\r
1245 gp2x_pd_clone_buffer2();
\r
1247 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);
\r
1249 me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);
\r
1254 static int sndrate_prevnext(int rate, int dir)
\r
1256 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
1258 for (i = 0; i < 5; i++)
\r
1259 if (rates[i] == rate) break;
\r
1261 i += dir ? 1 : -1;
\r
1262 if (i > 4) return dir ? 44100 : 22050;
\r
1263 if (i < 0) return dir ? 11025 : 8000;
\r
1267 static void region_prevnext(int right)
\r
1269 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
1270 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
1273 if (!PicoRegionOverride) {
\r
1274 for (i = 0; i < 6; i++)
\r
1275 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1276 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
1277 else PicoRegionOverride=1;
\r
1279 else PicoRegionOverride<<=1;
\r
1280 if (PicoRegionOverride > 8) PicoRegionOverride = 8;
\r
1282 if (!PicoRegionOverride) {
\r
1283 for (i = 0; i < 6; i++)
\r
1284 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1285 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
1287 else PicoRegionOverride>>=1;
\r
1291 static void menu_options_save(void)
\r
1293 if (PicoRegionOverride) {
\r
1294 // force setting possibly changed..
\r
1295 Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;
\r
1297 if (!(PicoOpt & POPT_6BTN_PAD)) {
\r
1298 // unbind XYZ MODE, just in case
\r
1299 unbind_action(0xf00, -1, -1);
\r
1303 static int menu_loop_options(void)
\r
1305 static int menu_sel = 0;
\r
1306 int menu_sel_max, ret;
\r
1307 unsigned long inp = 0;
\r
1308 menu_id selected_id;
\r
1310 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_loaded);
\r
1311 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1312 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1313 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1317 draw_menu_options(menu_sel);
\r
1318 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
1319 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1320 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1321 selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);
\r
1322 if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choice
\r
1323 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0)) {
\r
1324 switch (selected_id) {
\r
1325 case MA_OPT_RENDERER:
\r
1326 if (inp & GP2X_LEFT) {
\r
1327 if (PicoOpt&0x10) PicoOpt&= ~0x10;
\r
1328 else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;
\r
1329 else if ( currentConfig.EmuOpt &0x80) break;
\r
1331 if (PicoOpt&0x10) break;
\r
1332 else if (!(currentConfig.EmuOpt &0x80))PicoOpt|= 0x10;
\r
1333 else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;
\r
1336 case MA_OPT_SOUND_QUALITY:
\r
1337 if ((inp & GP2X_RIGHT) && PsndRate == 44100 && !(PicoOpt&0x08)) {
\r
1338 PsndRate = 8000; PicoOpt|= 0x08;
\r
1339 } else if ((inp & GP2X_LEFT) && PsndRate == 8000 && (PicoOpt&0x08)) {
\r
1340 PsndRate = 44100; PicoOpt&=~0x08;
\r
1341 } else PsndRate = sndrate_prevnext(PsndRate, inp & GP2X_RIGHT);
\r
1343 case MA_OPT_REGION:
\r
1344 region_prevnext(inp & GP2X_RIGHT);
\r
1346 case MA_OPT_CONFIRM_STATES: {
\r
1347 int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);
\r
1348 n += (inp & GP2X_LEFT) ? -1 : 1;
\r
1349 if (n < 0) n = 0; else if (n > 3) n = 3;
\r
1350 n |= n << 1; n &= ~2;
\r
1351 currentConfig.EmuOpt &= ~0xa00;
\r
1352 currentConfig.EmuOpt |= n << 9;
\r
1355 case MA_OPT_SAVE_SLOT:
\r
1356 if (inp & GP2X_RIGHT) {
\r
1357 state_slot++; if (state_slot > 9) state_slot = 0;
\r
1358 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
1361 case MA_OPT_CPU_CLOCKS:
\r
1362 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
1363 currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;
\r
1364 if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;
\r
1365 draw_menu_options(menu_sel);
\r
1369 case MA_OPT_SAVECFG:
\r
1370 case MA_OPT_SAVECFG_GAME:
\r
1371 case MA_OPT_LOADCFG:
\r
1372 config_slot += (inp&GP2X_RIGHT) ? 1 : -1;
\r
1373 if (config_slot > 9) config_slot = 0;
\r
1374 if (config_slot < 0) config_slot = 9;
\r
1375 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1376 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1377 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1380 //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1385 if (inp & GP2X_B) {
\r
1386 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))
\r
1388 switch (selected_id)
\r
1390 case MA_OPT_SCD_OPTS:
\r
1391 cd_menu_loop_options();
\r
1392 if (engineState == PGS_ReloadRom)
\r
1393 return 0; // test BIOS
\r
1395 case MA_OPT_ADV_OPTS:
\r
1396 amenu_loop_options();
\r
1398 case MA_OPT_SAVECFG: // done (update and write)
\r
1399 menu_options_save();
\r
1400 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
1401 else strcpy(menuErrorMsg, "failed to write config");
\r
1403 case MA_OPT_SAVECFG_GAME: // done (update and write for current game)
\r
1404 menu_options_save();
\r
1405 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
1406 else strcpy(menuErrorMsg, "failed to write config");
\r
1408 case MA_OPT_LOADCFG:
\r
1409 ret = emu_ReadConfig(1, 1);
\r
1410 if (!ret) ret = emu_ReadConfig(0, 1);
\r
1411 if (ret) strcpy(menuErrorMsg, "config loaded");
\r
1412 else strcpy(menuErrorMsg, "failed to load config");
\r
1415 //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1420 if(inp & (GP2X_X|GP2X_A)) {
\r
1421 menu_options_save();
\r
1422 return 0; // done (update, no write)
\r
1427 // -------------- credits --------------
\r
1429 static void draw_menu_credits(void)
\r
1431 int tl_x = 15, tl_y = 64, y;
\r
1432 gp2x_pd_clone_buffer2();
\r
1434 text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006-2008");
\r
1436 text_out16(tl_x, y, "Credits:");
\r
1437 text_out16(tl_x, (y+=10), "fDave: Cyclone 68000 core,");
\r
1438 text_out16(tl_x, (y+=10), " base code of PicoDrive");
\r
1439 text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
1440 text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
1441 text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
\r
1442 text_out16(tl_x, (y+=10), "Stephane Dallongeville:");
\r
1443 text_out16(tl_x, (y+=10), " opensource Gens");
\r
1444 text_out16(tl_x, (y+=10), "Haze: Genesis hw info");
\r
1445 text_out16(tl_x, (y+=10), "rlyeh and others: minimal SDK");
\r
1446 text_out16(tl_x, (y+=10), "Squidge: squidgehack");
\r
1447 text_out16(tl_x, (y+=10), "Dzz: ARM940 sample");
\r
1448 text_out16(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");
\r
1449 text_out16(tl_x, (y+=10), "craigix: GP2X hardware");
\r
1450 text_out16(tl_x, (y+=10), "ketchupgun: skin design");
\r
1456 // -------------- root menu --------------
\r
1458 menu_entry main_entries[] =
\r
1460 { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0, 0 },
\r
1461 { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0, 0 },
\r
1462 { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0, 0 },
\r
1463 { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0, 0 },
\r
1464 { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1, 0 },
\r
1465 { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1, 0 },
\r
1466 { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1, 0 },
\r
1467 { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1, 0 },
\r
1468 { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0, 0 },
\r
1469 { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1, 0 }
\r
1472 #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))
\r
1474 static void draw_menu_root(int menu_sel)
\r
1476 const int tl_x = 70, tl_y = 70;
\r
1478 gp2x_pd_clone_buffer2();
\r
1480 text_out16(tl_x, 20, "PicoDrive v" VERSION);
\r
1482 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);
\r
1484 me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
1487 if (menuErrorMsg[0]) {
\r
1488 memset((char *)gp2x_screen + 320*224*2, 0, 320*16*2);
\r
1489 text_out16(5, 226, menuErrorMsg);
\r
1495 static void menu_loop_root(void)
\r
1497 static int menu_sel = 0;
\r
1498 int ret, menu_sel_max;
\r
1499 unsigned long inp = 0;
\r
1501 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_loaded);
\r
1502 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_loaded);
\r
1503 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_loaded);
\r
1504 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_loaded);
\r
1505 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL);
\r
1507 menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;
\r
1508 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1510 /* make sure action buttons are not pressed on entering menu */
\r
1511 draw_menu_root(menu_sel);
\r
1512 while (gp2x_joystick_read(1) & (GP2X_B|GP2X_X|GP2X_SELECT)) usleep(50*1000);
\r
1516 draw_menu_root(menu_sel);
\r
1517 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT|GP2X_L|GP2X_R);
\r
1518 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1519 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1520 if((inp & (GP2X_L|GP2X_R)) == (GP2X_L|GP2X_R)) debug_menu_loop();
\r
1521 if(inp &(GP2X_SELECT|GP2X_X)){
\r
1523 while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released
\r
1524 engineState = PGS_Running;
\r
1528 if(inp & GP2X_B) {
\r
1529 switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))
\r
1531 case MA_MAIN_RESUME_GAME:
\r
1533 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1534 engineState = PGS_Running;
\r
1538 case MA_MAIN_SAVE_STATE:
\r
1540 if(savestate_menu_loop(0))
\r
1542 engineState = PGS_Running;
\r
1546 case MA_MAIN_LOAD_STATE:
\r
1548 if(savestate_menu_loop(1))
\r
1550 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1551 engineState = PGS_Running;
\r
1555 case MA_MAIN_RESET_GAME:
\r
1558 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1559 engineState = PGS_Running;
\r
1563 case MA_MAIN_LOAD_ROM:
\r
1565 char curr_path[PATH_MAX], *selfname;
\r
1567 if ( (tstf = fopen(lastRomFile, "rb")) )
\r
1570 strcpy(curr_path, lastRomFile);
\r
1573 getcwd(curr_path, PATH_MAX);
\r
1574 selfname = romsel_loop(curr_path);
\r
1576 printf("selected file: %s\n", selfname);
\r
1577 engineState = PGS_ReloadRom;
\r
1582 case MA_MAIN_OPTIONS:
\r
1583 ret = menu_loop_options();
\r
1584 if (ret == 1) continue; // status update
\r
1585 if (engineState == PGS_ReloadRom)
\r
1586 return; // BIOS test
\r
1588 case MA_MAIN_CONTROLS:
\r
1591 case MA_MAIN_CREDITS:
\r
1592 draw_menu_credits();
\r
1594 inp = wait_for_input(GP2X_B|GP2X_X);
\r
1596 case MA_MAIN_EXIT:
\r
1597 engineState = PGS_Quit;
\r
1599 case MA_MAIN_PATCHES:
\r
1600 if (rom_loaded && PicoPatches) {
\r
1601 patches_menu_loop();
\r
1603 strcpy(menuErrorMsg, "Patches applied");
\r
1608 printf("%s: something unknown selected\n", __FUNCTION__);
\r
1612 menuErrorMsg[0] = 0; // clear error msg
\r
1616 static void menu_darken_bg(void *dst, int pixels, int darker)
\r
1618 unsigned int *screen = dst;
\r
1624 unsigned int p = *screen;
\r
1625 *screen++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);
\r
1632 unsigned int p = *screen;
\r
1633 *screen++ = (p&0xf79ef79e)>>1;
\r
1638 static void menu_prepare_bg(int use_game_bg)
\r
1642 // darken the active framebuffer
\r
1643 memset(gp2x_screen, 0, 320*8*2);
\r
1644 menu_darken_bg((char *)gp2x_screen + 320*8*2, 320*224, 1);
\r
1645 memset((char *)gp2x_screen + 320*232*2, 0, 320*8*2);
\r
1649 // should really only happen once, on startup..
\r
1650 readpng(gp2x_screen, "skin/background.png", READPNG_BG);
\r
1653 // copy to buffer2
\r
1654 gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);
\r
1657 static void menu_gfx_prepare(void)
\r
1659 menu_prepare_bg(rom_loaded);
\r
1661 // switch to 16bpp
\r
1662 gp2x_video_changemode2(16);
\r
1663 gp2x_video_RGB_setscaling(0, 320, 240);
\r
1668 void menu_loop(void)
\r
1670 menu_gfx_prepare();
\r
1674 menuErrorMsg[0] = 0;
\r
1678 // --------- CD tray close menu ----------
\r
1680 static void draw_menu_tray(int menu_sel)
\r
1682 int tl_x = 70, tl_y = 90, y;
\r
1683 memset(gp2x_screen, 0, 320*240*2);
\r
1685 text_out16(tl_x, 20, "The unit is about to");
\r
1686 text_out16(tl_x, 30, "close the CD tray.");
\r
1689 text_out16(tl_x, y, "Load new CD image");
\r
1690 text_out16(tl_x, (y+=10), "Insert nothing");
\r
1693 text_out16(tl_x - 16, tl_y + menu_sel*10, ">");
\r
1695 if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg);
\r
1700 int menu_loop_tray(void)
\r
1702 int menu_sel = 0, menu_sel_max = 1;
\r
1703 unsigned long inp = 0;
\r
1704 char curr_path[PATH_MAX], *selfname;
\r
1707 gp2x_memset_all_buffers(0, 0, 320*240*2);
\r
1708 menu_gfx_prepare();
\r
1710 if ( (tstf = fopen(lastRomFile, "rb")) )
\r
1713 strcpy(curr_path, lastRomFile);
\r
1717 getcwd(curr_path, PATH_MAX);
\r
1720 /* make sure action buttons are not pressed on entering menu */
\r
1721 draw_menu_tray(menu_sel);
\r
1722 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1726 draw_menu_tray(menu_sel);
\r
1727 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B);
\r
1728 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1729 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1730 if(inp & GP2X_B ) {
\r
1731 switch (menu_sel) {
\r
1732 case 0: // select image
\r
1733 selfname = romsel_loop(curr_path);
\r
1736 cd_img_type cd_type;
\r
1737 cd_type = emu_cdCheck(NULL);
\r
1738 if (cd_type != CIT_NOT_CD)
\r
1739 ret = Insert_CD(romFileName, cd_type);
\r
1741 sprintf(menuErrorMsg, "Load failed, invalid CD image?");
\r
1742 printf("%s\n", menuErrorMsg);
\r
1745 engineState = PGS_RestartRun;
\r
1749 case 1: // insert nothing
\r
1750 engineState = PGS_RestartRun;
\r
1754 menuErrorMsg[0] = 0; // clear error msg
\r