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/arm_utils.h"
\r
18 #include "../common/menu.h"
\r
19 #include "../common/readpng.h"
\r
20 #include "version.h"
\r
22 #include <Pico/PicoInt.h>
\r
23 #include <Pico/Patch.h>
\r
24 #include <zlib/zlib.h>
\r
26 #ifndef _DIRENT_HAVE_D_TYPE
\r
27 #error "need d_type for file browser
\r
30 extern char romFileName[PATH_MAX];
\r
31 extern char *rom_data;
\r
32 extern int mmuhack_status;
\r
33 extern int state_slot;
\r
34 extern int config_slot, config_slot_current;
\r
36 static const char *gp2xKeyNames[] = {
\r
37 "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",
\r
38 "START", "SELECT", "L", "R", "A", "B", "X", "Y",
\r
39 "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",
\r
40 "???", "???", "???", "PUSH", "???", "???", "???", "???"
\r
43 char menuErrorMsg[40] = {0, };
\r
45 static void menu_darken_bg(void *dst, int pixels, int darker);
\r
46 static void menu_prepare_bg(int use_game_bg);
\r
48 static unsigned long inp_prev = 0;
\r
49 static int inp_prevjoy = 0;
\r
51 static unsigned long wait_for_input(unsigned long interesting)
\r
54 static int repeats = 0, wait = 50*1000;
\r
57 if (repeats == 2 || repeats == 4) wait /= 2;
\r
58 if (repeats == 6) wait = 15 * 1000;
\r
60 for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {
\r
61 if (i == 0) repeats++;
\r
62 if (wait >= 30*1000) usleep(wait); // usleep sleeps for ~30ms minimum
\r
63 else spend_cycles(wait * currentConfig.CPUclock);
\r
66 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
\r
71 if (release || ret != inp_prev) {
\r
78 // we don't need diagonals in menus
\r
79 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
80 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
81 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
82 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
87 static unsigned long input2_read(unsigned long interesting, int *joy)
\r
95 if ((ret = gp2x_joystick_read(0) & interesting)) break;
\r
96 gp2x_usbjoy_update();
\r
97 for (i = 0; i < num_of_joys; i++) {
\r
98 ret = gp2x_usbjoy_check2(i);
\r
99 if (ret) { *joy = i + 1; break; }
\r
108 // similar to wait_for_input(), but returns joy num
\r
109 static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
\r
112 const int wait = 300*1000;
\r
115 if (inp_prevjoy == 0) inp_prev &= interesting;
\r
116 for (i = 0; i < 6; i++) {
\r
117 ret = input2_read(interesting, joy);
\r
118 if (*joy != inp_prevjoy || ret != inp_prev) break;
\r
122 while ( !(ret = input2_read(interesting, joy)) ) {
\r
127 inp_prevjoy = *joy;
\r
132 static void menu_flip(void)
\r
134 gp2x_video_flush_cache();
\r
135 gp2x_video_flip2();
\r
139 // --------- loading ROM screen ----------
\r
141 static void load_progress_cb(int percent)
\r
143 int ln, len = percent * 320 / 100;
\r
144 unsigned short *dst = (unsigned short *)gp2x_screen + 320*20;
\r
146 if (len > 320) len = 320;
\r
147 for (ln = 10; ln > 0; ln--, dst += 320)
\r
148 memset(dst, 0xff, len*2);
\r
152 void menu_romload_prepare(const char *rom_name)
\r
154 const char *p = rom_name + strlen(rom_name);
\r
155 while (p > rom_name && *p != '/') p--;
\r
157 if (rom_data) gp2x_pd_clone_buffer2();
\r
158 else memset(gp2x_screen, 0, 320*240*2);
\r
160 smalltext_out16(1, 1, "Loading", 0xffff);
\r
161 smalltext_out16_lim(1, 10, p, 0xffff, 53);
\r
162 gp2x_memcpy_buffers(3, gp2x_screen, 0, 320*240*2);
\r
164 PicoCartLoadProgressCB = load_progress_cb;
\r
167 void menu_romload_end(void)
\r
169 PicoCartLoadProgressCB = NULL;
\r
170 smalltext_out16(1, 30, "Starting emulation...", 0xffff);
\r
174 // -------------- ROM selector --------------
\r
176 // rrrr rggg gggb bbbb
\r
177 static unsigned short file2color(const char *fname)
\r
179 const char *ext = fname + strlen(fname) - 3;
\r
180 static const char *rom_exts[] = { "zip", "bin", "smd", "gen", "iso" };
\r
181 static const char *other_exts[] = { "gmv", "pat" };
\r
184 if (ext < fname) ext = fname;
\r
185 for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)
\r
186 if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;
\r
187 for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)
\r
188 if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;
\r
192 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
197 n--; // exclude current dir (".")
\r
199 gp2x_pd_clone_buffer2();
\r
201 if (rom_data == NULL) {
\r
202 menu_darken_bg(gp2x_screen, 320*240, 0);
\r
205 menu_darken_bg((char *)gp2x_screen + 320*120*2, 320*8, 0);
\r
208 smalltext_out16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);
\r
209 for (i = 0; i < n; i++) {
\r
211 if (pos < 0) continue;
\r
212 if (pos > 23) break;
\r
213 if (namelist[i+1]->d_type == DT_DIR) {
\r
214 smalltext_out16_lim(14, pos*10, "/", 0xfff6, 1);
\r
215 smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);
\r
217 unsigned short color = file2color(namelist[i+1]->d_name);
\r
218 smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2);
\r
221 text_out16(5, 120, ">");
\r
225 static int scandir_cmp(const void *p1, const void *p2)
\r
227 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
228 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
229 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
230 if ((*d2)->d_type == DT_DIR) return 1;
\r
231 return alphasort(d1, d2);
\r
234 static char *filter_exts[] = {
\r
235 ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",
\r
236 ".jpg", ".gpe", ".cue"
\r
239 static int scandir_filter(const struct dirent *ent)
\r
244 if (ent == NULL || ent->d_name == NULL) return 0;
\r
245 if (strlen(ent->d_name) < 5) return 1;
\r
247 p = ent->d_name + strlen(ent->d_name) - 4;
\r
249 for (i = 0; i < sizeof(filter_exts)/sizeof(filter_exts[0]); i++)
\r
251 if (strcmp(p, filter_exts[i]) == 0) return 0;
\r
257 static char *romsel_loop(char *curr_path)
\r
259 struct dirent **namelist;
\r
262 unsigned long inp = 0;
\r
263 char *ret = NULL, *fname = NULL;
\r
265 // is this a dir or a full path?
\r
266 if ((dir = opendir(curr_path))) {
\r
270 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
275 n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
\r
278 n = scandir("/", &namelist, scandir_filter, scandir_cmp);
\r
281 printf("dir: "); printf(curr_path); printf("\n");
\r
288 if (fname != NULL) {
\r
290 for (i = 1; i < n; i++) {
\r
291 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
300 draw_dirlist(curr_path, namelist, n, sel);
\r
301 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
302 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
303 if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
304 if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
305 if(inp & GP2X_L) { sel-=24; if (sel < 0) sel = 0; }
\r
306 if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
307 if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; }
\r
308 if(inp & GP2X_B) { // enter dir/select
\r
310 if (namelist[sel+1]->d_type == DT_REG) {
\r
311 strcpy(romFileName, curr_path);
\r
312 strcat(romFileName, "/");
\r
313 strcat(romFileName, namelist[sel+1]->d_name);
\r
316 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
317 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
318 char *p, *newdir = malloc(newlen);
\r
319 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
320 char *start = curr_path;
\r
321 p = start + strlen(start) - 1;
\r
322 while (*p == '/' && p > start) p--;
\r
323 while (*p != '/' && p > start) p--;
\r
324 if (p <= start) strcpy(newdir, "/");
\r
325 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
327 strcpy(newdir, curr_path);
\r
328 p = newdir + strlen(newdir) - 1;
\r
329 while (*p == '/' && p >= newdir) *p-- = 0;
\r
330 strcat(newdir, "/");
\r
331 strcat(newdir, namelist[sel+1]->d_name);
\r
333 ret = romsel_loop(newdir);
\r
337 // unknown file type, happens on NTFS mounts. Try to guess.
\r
338 FILE *tstf; int tmp;
\r
339 strcpy(romFileName, curr_path);
\r
340 strcat(romFileName, "/");
\r
341 strcat(romFileName, namelist[sel+1]->d_name);
\r
342 tstf = fopen(romFileName, "rb");
\r
345 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
346 namelist[sel+1]->d_type = DT_REG;
\r
347 else namelist[sel+1]->d_type = DT_DIR;
\r
353 if(inp & GP2X_X) break; // cancel
\r
357 while(n--) free(namelist[n]);
\r
364 // ------------ debug menu ------------
\r
366 char *debugString(void);
\r
368 static void draw_debug(void)
\r
370 char *p, *str = debugString();
\r
373 gp2x_pd_clone_buffer2();
\r
376 for (line = 0; line < 24; line++)
\r
378 while (*p && *p != '\n') p++;
\r
380 if (len > 55) len = 55;
\r
381 smalltext_out16_lim(1, line*10, str, 0xffff, len);
\r
382 if (*p == 0) break;
\r
388 static void debug_menu_loop(void)
\r
391 wait_for_input(GP2X_B|GP2X_X);
\r
394 // ------------ patch/gg menu ------------
\r
396 static void draw_patchlist(int sel)
\r
398 int start, i, pos, active;
\r
402 gp2x_pd_clone_buffer2();
\r
404 for (i = 0; i < PicoPatchCount; i++) {
\r
406 if (pos < 0) continue;
\r
407 if (pos > 23) break;
\r
408 active = PicoPatches[i].active;
\r
409 smalltext_out16_lim(14, pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff, 3);
\r
410 smalltext_out16_lim(14+6*4, pos*10, PicoPatches[i].name, active ? 0xfff6 : 0xffff, 53-6);
\r
413 if (pos < 24) smalltext_out16_lim(14, pos*10, "done", 0xffff, 4);
\r
415 text_out16(5, 120, ">");
\r
420 static void patches_menu_loop(void)
\r
423 unsigned long inp = 0;
\r
427 draw_patchlist(menu_sel);
\r
428 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);
\r
429 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
\r
430 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
\r
431 if(inp &(GP2X_LEFT|GP2X_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
\r
432 if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
\r
433 if(inp & GP2X_B) { // action
\r
434 if (menu_sel < PicoPatchCount)
\r
435 PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
\r
438 if(inp & GP2X_X) return;
\r
443 // ------------ savestate loader ------------
\r
445 static int state_slot_flags = 0;
\r
447 static void state_check_slots(void)
\r
451 state_slot_flags = 0;
\r
453 for (slot = 0; slot < 10; slot++)
\r
455 if (emu_check_save_file(slot))
\r
457 state_slot_flags |= 1 << slot;
\r
462 static void draw_savestate_bg(int slot)
\r
464 struct PicoVideo tmp_pv;
\r
465 unsigned short tmp_cram[0x40];
\r
466 unsigned short tmp_vsram[0x40];
\r
467 void *tmp_vram, *file;
\r
470 fname = emu_GetSaveFName(1, 0, slot);
\r
471 if (!fname) return;
\r
473 tmp_vram = malloc(sizeof(Pico.vram));
\r
474 if (tmp_vram == NULL) return;
\r
476 memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));
\r
477 memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));
\r
478 memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));
\r
479 memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));
\r
481 if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {
\r
482 file = gzopen(fname, "rb");
\r
483 emu_set_save_cbs(1);
\r
485 file = fopen(fname, "rb");
\r
486 emu_set_save_cbs(0);
\r
491 PicoCdLoadStateGfx(file);
\r
493 areaSeek(file, 0x10020, SEEK_SET); // skip header and RAM in state file
\r
494 areaRead(Pico.vram, 1, sizeof(Pico.vram), file);
\r
495 areaSeek(file, 0x2000, SEEK_CUR);
\r
496 areaRead(Pico.cram, 1, sizeof(Pico.cram), file);
\r
497 areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);
\r
498 areaSeek(file, 0x221a0, SEEK_SET);
\r
499 areaRead(&Pico.video, 1, sizeof(Pico.video), file);
\r
504 emu_forced_frame();
\r
505 menu_prepare_bg(1);
\r
507 memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));
\r
508 memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));
\r
509 memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));
\r
510 memcpy(&Pico.video, &tmp_pv, sizeof(Pico.video));
\r
514 static void draw_savestate_menu(int menu_sel, int is_loading)
\r
516 int tl_x = 25, tl_y = 60, y, i;
\r
518 if (state_slot_flags & (1 << menu_sel))
\r
519 draw_savestate_bg(menu_sel);
\r
520 gp2x_pd_clone_buffer2();
\r
522 text_out16(tl_x, 30, is_loading ? "Load state" : "Save state");
\r
524 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 108);
\r
526 /* draw all 10 slots */
\r
528 for (i = 0; i < 10; i++, y+=10)
\r
530 text_out16(tl_x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");
\r
532 text_out16(tl_x, y, "back");
\r
537 static int savestate_menu_loop(int is_loading)
\r
539 static int menu_sel = 10;
\r
540 int menu_sel_max = 10;
\r
541 unsigned long inp = 0;
\r
543 state_check_slots();
\r
547 draw_savestate_menu(menu_sel, is_loading);
\r
548 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
549 if(inp & GP2X_UP ) {
\r
551 menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
\r
552 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
554 if(inp & GP2X_DOWN) {
\r
556 menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;
\r
557 } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);
\r
559 if(inp & GP2X_B) { // save/load
\r
560 if (menu_sel < 10) {
\r
561 state_slot = menu_sel;
\r
562 if (emu_SaveLoadGame(is_loading, 0)) {
\r
563 strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");
\r
569 if(inp & GP2X_X) return 1;
\r
573 // -------------- key config --------------
\r
575 static char *usb_joy_key_name(int joy, int num)
\r
577 static char name[16];
\r
580 case 0: sprintf(name, "Joy%i UP", joy); break;
\r
581 case 1: sprintf(name, "Joy%i DOWN", joy); break;
\r
582 case 2: sprintf(name, "Joy%i LEFT", joy); break;
\r
583 case 3: sprintf(name, "Joy%i RIGHT", joy); break;
\r
584 default:sprintf(name, "Joy%i b%i", joy, num-3); break;
\r
589 static char *action_binds(int player_idx, int action_mask)
\r
591 static char strkeys[32*5];
\r
595 for (i = 0; i < 32; i++) // i is key index
\r
597 if (currentConfig.KeyBinds[i] & action_mask)
\r
599 if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;
\r
600 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }
\r
601 else strcpy(strkeys, gp2xKeyNames[i]);
\r
604 for (joy = 0; joy < num_of_joys; joy++)
\r
606 for (i = 0; i < 32; i++)
\r
608 if (currentConfig.JoyBinds[joy][i] & action_mask)
\r
610 if (player_idx >= 0 && ((currentConfig.JoyBinds[joy][i] >> 16) & 3) != player_idx) continue;
\r
612 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
\r
615 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
\r
623 static void unbind_action(int action)
\r
627 for (i = 0; i < 32; i++)
\r
628 currentConfig.KeyBinds[i] &= ~action;
\r
629 for (u = 0; u < 4; u++)
\r
630 for (i = 0; i < 32; i++)
\r
631 currentConfig.JoyBinds[u][i] &= ~action;
\r
634 static int count_bound_keys(int action, int joy)
\r
640 for (i = 0; i < 32; i++)
\r
641 if (currentConfig.JoyBinds[joy-1][i] & action) keys++;
\r
645 for (i = 0; i < 32; i++)
\r
646 if (currentConfig.KeyBinds[i] & action) keys++;
\r
651 typedef struct { char *name; int mask; } bind_action_t;
\r
653 static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel)
\r
655 int x, y, tl_y = 40, i;
\r
657 gp2x_pd_clone_buffer2();
\r
658 if (player_idx >= 0) {
\r
659 text_out16(80, 20, "Player %i controls", player_idx + 1);
\r
662 text_out16(80, 20, "Emulator controls");
\r
666 menu_draw_selection(x - 16, tl_y + sel*10, (player_idx >= 0) ? 66 : 130);
\r
669 for (i = 0; i < opt_cnt; i++, y+=10)
\r
670 text_out16(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));
\r
672 text_out16(x, y, "Done");
\r
674 if (sel < opt_cnt) {
\r
675 text_out16(30, 180, "Press a button to bind/unbind");
\r
676 text_out16(30, 190, "Use SELECT to clear");
\r
677 text_out16(30, 200, "To bind UP/DOWN, hold SELECT");
\r
678 text_out16(30, 210, "Select \"Done\" to exit");
\r
680 text_out16(30, 190, "Use Options -> Save cfg");
\r
681 text_out16(30, 200, "to save controls");
\r
682 text_out16(30, 210, "Press B or X to exit");
\r
687 static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)
\r
689 int joy = 0, sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;
\r
690 unsigned long inp = 0;
\r
694 draw_key_config(opts, opt_cnt, player_idx, sel);
\r
695 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);
\r
696 // printf("got %08lX from joy %i\n", inp, joy);
\r
698 if (!(inp & GP2X_SELECT)) {
\r
700 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }
\r
701 if(inp & GP2X_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }
\r
703 if (sel >= opt_cnt) {
\r
704 if (inp & (GP2X_B|GP2X_X)) break;
\r
707 // if we are here, we want to bind/unbind something
\r
708 if ((inp & GP2X_SELECT) && !prev_select)
\r
709 unbind_action(opts[sel].mask);
\r
710 prev_select = inp & GP2X_SELECT;
\r
711 inp &= CONFIGURABLE_KEYS;
\r
712 inp &= ~GP2X_SELECT;
\r
713 for (i = 0; i < 32; i++)
\r
714 if (inp & (1 << i)) {
\r
715 if (count_bound_keys(opts[sel].mask, 0) >= 2)
\r
716 currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only
\r
717 else currentConfig.KeyBinds[i] ^= opts[sel].mask;
\r
718 if (player_idx >= 0) {
\r
719 currentConfig.KeyBinds[i] &= ~(3 << 16);
\r
720 currentConfig.KeyBinds[i] |= player_idx << 16;
\r
724 else if (sel < opt_cnt)
\r
726 for (i = 0; i < 32; i++)
\r
727 if (inp & (1 << i)) {
\r
728 if (count_bound_keys(opts[sel].mask, joy) >= 1) // disallow combos for usbjoy
\r
729 currentConfig.JoyBinds[joy-1][i] &= ~opts[sel].mask;
\r
730 else currentConfig.JoyBinds[joy-1][i] ^= opts[sel].mask;
\r
731 if (player_idx >= 0) {
\r
732 currentConfig.JoyBinds[joy-1][i] &= ~(3 << 16);
\r
733 currentConfig.JoyBinds[joy-1][i] |= player_idx << 16;
\r
740 static void draw_kc_sel(int menu_sel)
\r
742 int tl_x = 25+40, tl_y = 60, y, i;
\r
746 gp2x_pd_clone_buffer2();
\r
747 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 138);
\r
749 text_out16(tl_x, y, "Player 1");
\r
750 text_out16(tl_x, (y+=10), "Player 2");
\r
751 text_out16(tl_x, (y+=10), "Emulator controls");
\r
752 text_out16(tl_x, (y+=10), "Done");
\r
755 text_out16(tl_x, (y=110), "USB joys detected:");
\r
756 if (num_of_joys > 0) {
\r
757 for (i = 0; i < num_of_joys; i++) {
\r
758 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
\r
759 text_out16(tl_x, (y+=10), "%i: %s", i+1, joyname);
\r
762 text_out16(tl_x, (y+=10), "none");
\r
769 // PicoPad[] format: MXYZ SACB RLDU
\r
770 static bind_action_t ctrl_actions[] =
\r
773 { "DOWN ", 0x002 },
\r
774 { "LEFT ", 0x004 },
\r
775 { "RIGHT ", 0x008 },
\r
779 { "START ", 0x080 },
\r
780 { "MODE ", 0x800 },
\r
786 // player2_flag, ?, ?, ?, ?, ?, ?, menu
\r
787 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",
\r
788 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"
\r
789 static bind_action_t emuctrl_actions[] =
\r
791 { "Load State ", 1<<28 },
\r
792 { "Save State ", 1<<27 },
\r
793 { "Prev Save Slot ", 1<<25 },
\r
794 { "Next Save Slot ", 1<<24 },
\r
795 { "Switch Renderer", 1<<26 },
\r
796 { "Volume Down ", 1<<30 },
\r
797 { "Volume Up ", 1<<29 },
\r
798 { "Enter Menu ", 1<<23 },
\r
801 static void kc_sel_loop(void)
\r
803 int menu_sel = 3, menu_sel_max = 3;
\r
804 unsigned long inp = 0;
\r
805 int is_6button = currentConfig.PicoOpt & 0x020;
\r
809 draw_kc_sel(menu_sel);
\r
810 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
811 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
812 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
813 if (inp & GP2X_B) {
\r
814 switch (menu_sel) {
\r
815 case 0: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 0); return;
\r
816 case 1: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 1); return;
\r
817 case 2: key_config_loop(emuctrl_actions,
\r
818 sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return;
\r
819 case 3: if (rom_data == NULL) emu_WriteConfig(0); return;
\r
823 if (inp & GP2X_X) return;
\r
828 // --------- sega/mega cd options ----------
\r
830 menu_entry cdopt_entries[] =
\r
832 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 },
\r
833 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 },
\r
834 { NULL, MB_NONE, MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 },
\r
835 { "CD LEDs", MB_ONOFF, MA_CDOPT_LEDS, ¤tConfig.EmuOpt, 0x0400, 0, 0, 1 },
\r
836 { "CDDA audio (using mp3s)", MB_ONOFF, MA_CDOPT_CDDA, ¤tConfig.PicoOpt, 0x0800, 0, 0, 1 },
\r
837 { "PCM audio", MB_ONOFF, MA_CDOPT_PCM, ¤tConfig.PicoOpt, 0x0400, 0, 0, 1 },
\r
838 { NULL, MB_NONE, MA_CDOPT_READAHEAD, NULL, 0, 0, 0, 1 },
\r
839 { "SaveRAM cart", MB_ONOFF, MA_CDOPT_SAVERAM, ¤tConfig.PicoOpt, 0x8000, 0, 0, 1 },
\r
840 { "Scale/Rot. fx (slow)", MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,¤tConfig.PicoOpt, 0x1000, 0, 0, 1 },
\r
841 { "Better sync (slow)", MB_ONOFF, MA_CDOPT_BETTER_SYNC, ¤tConfig.PicoOpt, 0x2000, 0, 0, 1 },
\r
842 { "done", MB_NONE, MA_CDOPT_DONE, NULL, 0, 0, 0, 1 },
\r
845 #define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))
\r
848 struct bios_names_t
\r
850 char us[32], eu[32], jp[32];
\r
853 static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
855 struct bios_names_t *bios_names = param;
\r
860 case MA_CDOPT_TESTBIOS_USA: text_out16(x, y, "USA BIOS: %s", bios_names->us); break;
\r
861 case MA_CDOPT_TESTBIOS_EUR: text_out16(x, y, "EUR BIOS: %s", bios_names->eu); break;
\r
862 case MA_CDOPT_TESTBIOS_JAP: text_out16(x, y, "JAP BIOS: %s", bios_names->jp); break;
\r
863 case MA_CDOPT_READAHEAD:
\r
864 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
865 else strcpy(ra_buff, " OFF");
\r
866 text_out16(x, y, "ReadAhead buffer %s", ra_buff);
\r
872 static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)
\r
874 int tl_x = 25, tl_y = 60;
\r
875 menu_id selected_id;
\r
878 if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);
\r
879 else strcpy(ra_buff, " OFF");
\r
881 gp2x_pd_clone_buffer2();
\r
883 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 246);
\r
885 me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);
\r
887 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
888 if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||
\r
889 (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||
\r
890 (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))
\r
891 text_out16(tl_x, 210, "Press start to test selected BIOS");
\r
896 static void cd_menu_loop_options(void)
\r
898 static int menu_sel = 0;
\r
899 int menu_sel_max = 10;
\r
900 unsigned long inp = 0;
\r
901 struct bios_names_t bios_names;
\r
902 menu_id selected_id;
\r
905 if (find_bios(4, &bios)) { // US
\r
906 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
907 strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;
\r
908 } else strcpy(bios_names.us, "NOT FOUND");
\r
910 if (find_bios(8, &bios)) { // EU
\r
911 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
912 strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;
\r
913 } else strcpy(bios_names.eu, "NOT FOUND");
\r
915 if (find_bios(1, &bios)) { // JP
\r
916 for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;
\r
917 strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;
\r
918 } else strcpy(bios_names.jp, "NOT FOUND");
\r
922 draw_cd_menu_options(menu_sel, &bios_names);
\r
923 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);
\r
924 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
925 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
926 selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
\r
927 if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
928 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&
\r
929 selected_id == MA_CDOPT_READAHEAD) {
\r
930 if (inp & GP2X_LEFT) {
\r
931 PicoCDBuffers >>= 1;
\r
932 if (PicoCDBuffers < 64) PicoCDBuffers = 0;
\r
934 if (PicoCDBuffers < 64) PicoCDBuffers = 64;
\r
935 else PicoCDBuffers <<= 1;
\r
936 if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M
\r
940 if (inp & GP2X_B) { // toggleable options
\r
941 if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&
\r
942 selected_id == MA_CDOPT_DONE) {
\r
946 if (inp & GP2X_START) { // BIOS testers
\r
947 switch (selected_id) {
\r
948 case MA_CDOPT_TESTBIOS_USA:
\r
949 if (find_bios(4, &bios)) { // test US
\r
950 strcpy(romFileName, bios);
\r
951 engineState = PGS_ReloadRom;
\r
955 case MA_CDOPT_TESTBIOS_EUR:
\r
956 if (find_bios(8, &bios)) { // test EU
\r
957 strcpy(romFileName, bios);
\r
958 engineState = PGS_ReloadRom;
\r
962 case MA_CDOPT_TESTBIOS_JAP:
\r
963 if (find_bios(1, &bios)) { // test JP
\r
964 strcpy(romFileName, bios);
\r
965 engineState = PGS_ReloadRom;
\r
973 if (inp & (GP2X_X|GP2X_A)) return;
\r
978 // --------- advanced options ----------
\r
980 menu_entry opt2_entries[] =
\r
982 { NULL, MB_NONE, MA_OPT2_GAMMA, NULL, 0, 0, 0, 1 },
\r
983 { "A_SN's gamma curve", MB_ONOFF, MA_OPT2_A_SN_GAMMA, ¤tConfig.EmuOpt, 0x1000, 0, 0, 1 },
\r
984 { "Perfect vsync", MB_ONOFF, MA_OPT2_VSYNC, ¤tConfig.EmuOpt, 0x2000, 0, 0, 1 },
\r
985 { "Emulate Z80", MB_ONOFF, MA_OPT2_ENABLE_Z80, ¤tConfig.PicoOpt,0x0004, 0, 0, 1 },
\r
986 { "Emulate YM2612 (FM)", MB_ONOFF, MA_OPT2_ENABLE_YM2612, ¤tConfig.PicoOpt,0x0001, 0, 0, 1 },
\r
987 { "Emulate SN76496 (PSG)", MB_ONOFF, MA_OPT2_ENABLE_SN76496,¤tConfig.PicoOpt,0x0002, 0, 0, 1 },
\r
988 { "gzip savestates", MB_ONOFF, MA_OPT2_GZIP_STATES, ¤tConfig.EmuOpt, 0x0008, 0, 0, 1 },
\r
989 { "Don't save last used ROM", MB_ONOFF, MA_OPT2_NO_LAST_ROM, ¤tConfig.EmuOpt, 0x0020, 0, 0, 1 },
\r
990 { "needs restart:", MB_NONE, MA_NONE, NULL, 0, 0, 0, 1 },
\r
991 { "craigix's RAM timings", MB_ONOFF, MA_OPT2_RAMTIMINGS, ¤tConfig.EmuOpt, 0x0100, 0, 0, 1 },
\r
992 { NULL, MB_ONOFF, MA_OPT2_SQUIDGEHACK, ¤tConfig.EmuOpt, 0x0010, 0, 0, 1 },
\r
993 { "done", MB_NONE, MA_OPT2_DONE, NULL, 0, 0, 0, 1 },
\r
996 #define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))
\r
998 static void menu_opt2_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
1000 if (entry->id == MA_OPT2_GAMMA)
\r
1001 text_out16(x, y, "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);
\r
1002 else if (entry->id == MA_OPT2_SQUIDGEHACK)
\r
1003 text_out16(x, y, "squidgehack (now %s %s", mmuhack_status ? "active) " : "inactive)",
\r
1004 (currentConfig.EmuOpt&0x0010)?"ON":"OFF");
\r
1008 static void draw_amenu_options(int menu_sel)
\r
1010 int tl_x = 25, tl_y = 50;
\r
1012 gp2x_pd_clone_buffer2();
\r
1014 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 252);
\r
1016 me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL);
\r
1021 static void amenu_loop_options(void)
\r
1023 static int menu_sel = 0;
\r
1025 unsigned long inp = 0;
\r
1026 menu_id selected_id;
\r
1028 menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;
\r
1032 draw_amenu_options(menu_sel);
\r
1033 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
1034 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1035 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1036 selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);
\r
1037 if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
1038 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&
\r
1039 selected_id == MA_OPT2_GAMMA) {
\r
1040 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
1041 currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;
\r
1042 if (currentConfig.gamma < 1) currentConfig.gamma = 1;
\r
1043 if (currentConfig.gamma > 300) currentConfig.gamma = 300;
\r
1044 draw_amenu_options(menu_sel);
\r
1049 if (inp & GP2X_B) { // toggleable options
\r
1050 if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&
\r
1051 selected_id == MA_OPT2_DONE) {
\r
1055 if (inp & (GP2X_X|GP2X_A)) return;
\r
1059 // -------------- options --------------
\r
1062 menu_entry opt_entries[] =
\r
1064 { NULL, MB_NONE, MA_OPT_RENDERER, NULL, 0, 0, 0, 1 },
\r
1065 { NULL, MB_RANGE, MA_OPT_SCALING, ¤tConfig.scaling, 0, 0, 3, 1 },
\r
1066 { "Accurate timing (slower)", MB_ONOFF, MA_OPT_ACC_TIMING, ¤tConfig.PicoOpt, 0x040, 0, 0, 1 },
\r
1067 { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES, ¤tConfig.PicoOpt, 0x080, 0, 0, 1 },
\r
1068 { "Show FPS", MB_ONOFF, MA_OPT_SHOW_FPS, ¤tConfig.EmuOpt, 0x002, 0, 0, 1 },
\r
1069 { NULL, MB_RANGE, MA_OPT_FRAMESKIP, ¤tConfig.Frameskip, 0, -1, 16, 1 },
\r
1070 { "Enable sound", MB_ONOFF, MA_OPT_ENABLE_SOUND, ¤tConfig.EmuOpt, 0x004, 0, 0, 1 },
\r
1071 { NULL, MB_NONE, MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 },
\r
1072 { "Use ARM940 core for sound", MB_ONOFF, MA_OPT_ARM940_SOUND, ¤tConfig.PicoOpt, 0x200, 0, 0, 1 },
\r
1073 { "6 button pad", MB_ONOFF, MA_OPT_6BUTTON_PAD, ¤tConfig.PicoOpt, 0x020, 0, 0, 1 },
\r
1074 { NULL, MB_NONE, MA_OPT_REGION, NULL, 0, 0, 0, 1 },
\r
1075 { "Use SRAM/BRAM savestates", MB_ONOFF, MA_OPT_SRAM_STATES, ¤tConfig.EmuOpt, 0x001, 0, 0, 1 },
\r
1076 { NULL, MB_NONE, MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 },
\r
1077 { "Save slot", MB_RANGE, MA_OPT_SAVE_SLOT, &state_slot, 0, 0, 9, 1 },
\r
1078 { NULL, MB_NONE, MA_OPT_CPU_CLOCKS, NULL, 0, 0, 0, 1 },
\r
1079 { "[Sega/Mega CD options]", MB_NONE, MA_OPT_SCD_OPTS, NULL, 0, 0, 0, 1 },
\r
1080 { "[advanced options]", MB_NONE, MA_OPT_ADV_OPTS, NULL, 0, 0, 0, 1 },
\r
1081 { NULL, MB_NONE, MA_OPT_SAVECFG, NULL, 0, 0, 0, 1 },
\r
1082 { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 },
\r
1083 { NULL, MB_NONE, MA_OPT_LOADCFG, NULL, 0, 0, 0, 1 },
\r
1086 #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))
\r
1089 static const char *region_name(unsigned int code)
\r
1091 static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
\r
1092 static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
\r
1096 while((code >>= 1)) i++;
\r
1097 if (i > 4) return "unknown";
\r
1100 static char name[24];
\r
1101 strcpy(name, "Auto:");
\r
1102 for (u = 0; u < 3; u++) {
\r
1103 i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;
\r
1104 while((code >>= 1)) i++;
\r
1105 strcat(name, names_short[i]);
\r
1112 static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)
\r
1114 char *str, str24[24];
\r
1116 switch (entry->id)
\r
1118 case MA_OPT_RENDERER:
\r
1119 if (currentConfig.PicoOpt&0x10)
\r
1120 str = " 8bit fast";
\r
1121 else if (currentConfig.EmuOpt&0x80)
\r
1122 str = "16bit accurate";
\r
1124 str = " 8bit accurate";
\r
1125 text_out16(x, y, "Renderer: %s", str);
\r
1127 case MA_OPT_SCALING:
\r
1128 switch (currentConfig.scaling) {
\r
1129 default: str = " OFF"; break;
\r
1130 case 1: str = "hw horizontal"; break;
\r
1131 case 2: str = "hw horiz. + vert."; break;
\r
1132 case 3: str = "sw horizontal"; break;
\r
1134 text_out16(x, y, "Scaling: %s", str);
\r
1136 case MA_OPT_FRAMESKIP:
\r
1137 if (currentConfig.Frameskip < 0)
\r
1138 strcpy(str24, "Auto");
\r
1139 else sprintf(str24, "%i", currentConfig.Frameskip);
\r
1140 text_out16(x, y, "Frameskip %s", str24);
\r
1142 case MA_OPT_SOUND_QUALITY:
\r
1143 str = (currentConfig.PicoOpt&0x08)?"stereo":"mono";
\r
1144 text_out16(x, y, "Sound Quality: %5iHz %s", currentConfig.PsndRate, str);
\r
1146 case MA_OPT_REGION:
\r
1147 text_out16(x, y, "Region: %s", region_name(currentConfig.PicoRegion));
\r
1149 case MA_OPT_CONFIRM_STATES:
\r
1150 switch ((currentConfig.EmuOpt >> 9) & 5) {
\r
1151 default: str = "OFF"; break;
\r
1152 case 1: str = "writes"; break;
\r
1153 case 4: str = "loads"; break;
\r
1154 case 5: str = "both"; break;
\r
1156 text_out16(x, y, "Confirm savestate %s", str);
\r
1158 case MA_OPT_CPU_CLOCKS:
\r
1159 text_out16(x, y, "GP2X CPU clocks %iMhz", currentConfig.CPUclock);
\r
1161 case MA_OPT_SAVECFG:
\r
1163 if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);
\r
1164 text_out16(x, y, "Save cfg as default%s", str24);
\r
1166 case MA_OPT_LOADCFG:
\r
1167 text_out16(x, y, "Load cfg from profile %i", config_slot);
\r
1170 printf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);
\r
1177 static void draw_menu_options(int menu_sel)
\r
1179 int tl_x = 25, tl_y = 24;
\r
1181 gp2x_pd_clone_buffer2();
\r
1183 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 284);
\r
1185 me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);
\r
1190 static int sndrate_prevnext(int rate, int dir)
\r
1192 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
1194 for (i = 0; i < 5; i++)
\r
1195 if (rates[i] == rate) break;
\r
1197 i += dir ? 1 : -1;
\r
1198 if (i > 4) return dir ? 44100 : 22050;
\r
1199 if (i < 0) return dir ? 11025 : 8000;
\r
1203 static void region_prevnext(int right)
\r
1205 // jp_ntsc=1, jp_pal=2, usa=4, eu=8
\r
1206 static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
\r
1209 if (!currentConfig.PicoRegion) {
\r
1210 for (i = 0; i < 6; i++)
\r
1211 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1212 if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];
\r
1213 else currentConfig.PicoRegion=1;
\r
1215 else currentConfig.PicoRegion<<=1;
\r
1216 if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;
\r
1218 if (!currentConfig.PicoRegion) {
\r
1219 for (i = 0; i < 6; i++)
\r
1220 if (rgn_orders[i] == PicoAutoRgnOrder) break;
\r
1221 if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];
\r
1223 else currentConfig.PicoRegion>>=1;
\r
1227 static void menu_options_save(void)
\r
1229 PicoOpt = currentConfig.PicoOpt;
\r
1230 PsndRate = currentConfig.PsndRate;
\r
1231 PicoRegionOverride = currentConfig.PicoRegion;
\r
1232 if (!(PicoOpt & 0x20)) {
\r
1233 // unbind XYZ MODE, just in case
\r
1234 unbind_action(0xf00);
\r
1239 static int menu_loop_options(void)
\r
1241 static int menu_sel = 0;
\r
1242 int menu_sel_max, ret;
\r
1243 unsigned long inp = 0;
\r
1244 menu_id selected_id;
\r
1246 currentConfig.PicoOpt = PicoOpt;
\r
1247 currentConfig.PsndRate = PsndRate;
\r
1248 currentConfig.PicoRegion = PicoRegionOverride;
\r
1250 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL);
\r
1251 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1252 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1253 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1257 draw_menu_options(menu_sel);
\r
1258 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
1259 if (inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1260 if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1261 selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);
\r
1262 if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
1263 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0)) {
\r
1264 switch (selected_id) {
\r
1265 case MA_OPT_RENDERER:
\r
1266 if (inp & GP2X_LEFT) {
\r
1267 if ( currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;
\r
1268 else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |= 0x80;
\r
1269 else if ( currentConfig.EmuOpt &0x80) break;
\r
1271 if ( currentConfig.PicoOpt&0x10) break;
\r
1272 else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|= 0x10;
\r
1273 else if ( currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;
\r
1276 case MA_OPT_SOUND_QUALITY:
\r
1277 if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {
\r
1278 currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08;
\r
1279 } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {
\r
1280 currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;
\r
1281 } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);
\r
1283 case MA_OPT_REGION:
\r
1284 region_prevnext(inp & GP2X_RIGHT);
\r
1286 case MA_OPT_CONFIRM_STATES: {
\r
1287 int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);
\r
1288 n += (inp & GP2X_LEFT) ? -1 : 1;
\r
1289 if (n < 0) n = 0; else if (n > 3) n = 3;
\r
1290 n |= n << 1; n &= ~2;
\r
1291 currentConfig.EmuOpt &= ~0xa00;
\r
1292 currentConfig.EmuOpt |= n << 9;
\r
1295 case MA_OPT_SAVE_SLOT:
\r
1296 if (inp & GP2X_RIGHT) {
\r
1297 state_slot++; if (state_slot > 9) state_slot = 0;
\r
1298 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
1301 case MA_OPT_CPU_CLOCKS:
\r
1302 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
1303 currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;
\r
1304 if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;
\r
1305 draw_menu_options(menu_sel);
\r
1309 case MA_OPT_SAVECFG:
\r
1310 case MA_OPT_SAVECFG_GAME:
\r
1311 case MA_OPT_LOADCFG:
\r
1312 config_slot += (inp&GP2X_RIGHT) ? 1 : -1;
\r
1313 if (config_slot > 9) config_slot = 0;
\r
1314 if (config_slot < 0) config_slot = 9;
\r
1315 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);
\r
1316 menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;
\r
1317 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1320 //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1325 if (inp & GP2X_B) {
\r
1326 if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))
\r
1328 switch (selected_id)
\r
1330 case MA_OPT_SCD_OPTS:
\r
1331 cd_menu_loop_options();
\r
1332 if (engineState == PGS_ReloadRom)
\r
1333 return 0; // test BIOS
\r
1335 case MA_OPT_ADV_OPTS:
\r
1336 amenu_loop_options();
\r
1338 case MA_OPT_SAVECFG: // done (update and write)
\r
1339 menu_options_save();
\r
1340 if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");
\r
1341 else strcpy(menuErrorMsg, "failed to write config");
\r
1343 case MA_OPT_SAVECFG_GAME: // done (update and write for current game)
\r
1344 menu_options_save();
\r
1345 if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");
\r
1346 else strcpy(menuErrorMsg, "failed to write config");
\r
1348 case MA_OPT_LOADCFG:
\r
1349 ret = emu_ReadConfig(1, 1);
\r
1350 if (!ret) ret = emu_ReadConfig(0, 1);
\r
1351 if (ret) strcpy(menuErrorMsg, "config loaded");
\r
1352 else strcpy(menuErrorMsg, "failed to load config");
\r
1355 //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);
\r
1360 if(inp & (GP2X_X|GP2X_A)) {
\r
1361 menu_options_save();
\r
1362 return 0; // done (update, no write)
\r
1367 // -------------- credits --------------
\r
1369 static void draw_menu_credits(void)
\r
1371 int tl_x = 15, tl_y = 64, y;
\r
1372 gp2x_pd_clone_buffer2();
\r
1374 text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");
\r
1376 text_out16(tl_x, y, "Credits:");
\r
1377 text_out16(tl_x, (y+=10), "Dave: Cyclone 68000 core,");
\r
1378 text_out16(tl_x, (y+=10), " base code of PicoDrive");
\r
1379 text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
1380 text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
1381 text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
\r
1382 text_out16(tl_x, (y+=10), "Stephane Dallongeville:");
\r
1383 text_out16(tl_x, (y+=10), " opensource Gens");
\r
1384 text_out16(tl_x, (y+=10), "Haze: Genesis hw info");
\r
1385 text_out16(tl_x, (y+=10), "rlyeh and others: minimal SDK");
\r
1386 text_out16(tl_x, (y+=10), "Squidge: squidgehack");
\r
1387 text_out16(tl_x, (y+=10), "Dzz: ARM940 sample");
\r
1388 text_out16(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");
\r
1389 text_out16(tl_x, (y+=10), "craigix: GP2X hardware");
\r
1390 text_out16(tl_x, (y+=10), "ketchupgun: skin design");
\r
1396 // -------------- root menu --------------
\r
1398 menu_entry main_entries[] =
\r
1400 { "Resume game", MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 },
\r
1401 { "Save State", MB_NONE, MA_MAIN_SAVE_STATE, NULL, 0, 0, 0, 0 },
\r
1402 { "Load State", MB_NONE, MA_MAIN_LOAD_STATE, NULL, 0, 0, 0, 0 },
\r
1403 { "Reset game", MB_NONE, MA_MAIN_RESET_GAME, NULL, 0, 0, 0, 0 },
\r
1404 { "Load new ROM/ISO", MB_NONE, MA_MAIN_LOAD_ROM, NULL, 0, 0, 0, 1 },
\r
1405 { "Change options", MB_NONE, MA_MAIN_OPTIONS, NULL, 0, 0, 0, 1 },
\r
1406 { "Configure controls", MB_NONE, MA_MAIN_CONTROLS, NULL, 0, 0, 0, 1 },
\r
1407 { "Credits", MB_NONE, MA_MAIN_CREDITS, NULL, 0, 0, 0, 1 },
\r
1408 { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES, NULL, 0, 0, 0, 0 },
\r
1409 { "Exit", MB_NONE, MA_MAIN_EXIT, NULL, 0, 0, 0, 1 }
\r
1412 #define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))
\r
1414 static void draw_menu_root(int menu_sel)
\r
1416 const int tl_x = 70, tl_y = 70;
\r
1418 gp2x_pd_clone_buffer2();
\r
1420 text_out16(tl_x, 20, "PicoDrive v" VERSION);
\r
1422 menu_draw_selection(tl_x - 16, tl_y + menu_sel*10, 146);
\r
1424 me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);
\r
1427 if (menuErrorMsg[0]) {
\r
1428 memset((char *)gp2x_screen + 320*224*2, 0, 320*16*2);
\r
1429 text_out16(5, 226, menuErrorMsg);
\r
1435 static void menu_loop_root(void)
\r
1437 static int menu_sel = 0;
\r
1438 int ret, menu_sel_max;
\r
1439 unsigned long inp = 0;
\r
1441 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL);
\r
1442 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE, rom_data != NULL);
\r
1443 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE, rom_data != NULL);
\r
1444 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME, rom_data != NULL);
\r
1445 me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES, PicoPatches != NULL);
\r
1447 menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;
\r
1448 if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;
\r
1450 /* make sure action buttons are not pressed on entering menu */
\r
1451 draw_menu_root(menu_sel);
\r
1452 while (gp2x_joystick_read(1) & (GP2X_B|GP2X_X|GP2X_SELECT)) usleep(50*1000);
\r
1456 draw_menu_root(menu_sel);
\r
1457 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT|GP2X_L|GP2X_R);
\r
1458 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1459 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1460 if((inp & (GP2X_L|GP2X_R)) == (GP2X_L|GP2X_R)) debug_menu_loop();
\r
1461 if(inp &(GP2X_SELECT|GP2X_X)){
\r
1463 while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released
\r
1464 engineState = PGS_Running;
\r
1468 if(inp & GP2X_B) {
\r
1469 switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))
\r
1471 case MA_MAIN_RESUME_GAME:
\r
1473 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1474 engineState = PGS_Running;
\r
1478 case MA_MAIN_SAVE_STATE:
\r
1480 if(savestate_menu_loop(0))
\r
1482 engineState = PGS_Running;
\r
1486 case MA_MAIN_LOAD_STATE:
\r
1488 if(savestate_menu_loop(1))
\r
1490 engineState = PGS_Running;
\r
1494 case MA_MAIN_RESET_GAME:
\r
1497 engineState = PGS_Running;
\r
1501 case MA_MAIN_LOAD_ROM:
\r
1503 char curr_path[PATH_MAX], *selfname;
\r
1505 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
1508 strcpy(curr_path, currentConfig.lastRomFile);
\r
1511 getcwd(curr_path, PATH_MAX);
\r
1512 selfname = romsel_loop(curr_path);
\r
1514 printf("selected file: %s\n", selfname);
\r
1515 engineState = PGS_ReloadRom;
\r
1520 case MA_MAIN_OPTIONS:
\r
1521 ret = menu_loop_options();
\r
1522 if (ret == 1) continue; // status update
\r
1523 if (engineState == PGS_ReloadRom)
\r
1524 return; // BIOS test
\r
1526 case MA_MAIN_CONTROLS:
\r
1529 case MA_MAIN_CREDITS:
\r
1530 draw_menu_credits();
\r
1532 inp = wait_for_input(GP2X_B|GP2X_X);
\r
1534 case MA_MAIN_EXIT:
\r
1535 engineState = PGS_Quit;
\r
1537 case MA_MAIN_PATCHES:
\r
1538 if (rom_data && PicoPatches) {
\r
1539 patches_menu_loop();
\r
1541 strcpy(menuErrorMsg, "Patches applied");
\r
1546 printf("%s: something unknown selected\n", __FUNCTION__);
\r
1550 menuErrorMsg[0] = 0; // clear error msg
\r
1554 static void menu_darken_bg(void *dst, int pixels, int darker)
\r
1556 unsigned int *screen = dst;
\r
1562 unsigned int p = *screen;
\r
1563 *screen++ = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);
\r
1570 unsigned int p = *screen;
\r
1571 *screen++ = (p&0xf79ef79e)>>1;
\r
1576 static void menu_prepare_bg(int use_game_bg)
\r
1580 // darken the active framebuffer
\r
1581 memset(gp2x_screen, 0, 320*8*2);
\r
1582 menu_darken_bg((char *)gp2x_screen + 320*8*2, 320*224, 1);
\r
1583 memset((char *)gp2x_screen + 320*232*2, 0, 320*8*2);
\r
1587 // should really only happen once, on startup..
\r
1588 readpng(gp2x_screen, "skin/background.png", READPNG_BG);
\r
1591 // copy to buffer2
\r
1592 gp2x_memcpy_buffers((1<<2), gp2x_screen, 0, 320*240*2);
\r
1595 static void menu_gfx_prepare(void)
\r
1597 menu_prepare_bg(rom_data != NULL);
\r
1599 // switch to 16bpp
\r
1600 gp2x_video_changemode2(16);
\r
1601 gp2x_video_RGB_setscaling(0, 320, 240);
\r
1606 void menu_loop(void)
\r
1608 menu_gfx_prepare();
\r
1612 menuErrorMsg[0] = 0;
\r
1616 // --------- CD tray close menu ----------
\r
1618 static void draw_menu_tray(int menu_sel)
\r
1620 int tl_x = 70, tl_y = 90, y;
\r
1621 memset(gp2x_screen, 0, 320*240*2);
\r
1623 text_out16(tl_x, 20, "The unit is about to");
\r
1624 text_out16(tl_x, 30, "close the CD tray.");
\r
1627 text_out16(tl_x, y, "Load new CD image");
\r
1628 text_out16(tl_x, (y+=10), "Insert nothing");
\r
1631 text_out16(tl_x - 16, tl_y + menu_sel*10, ">");
\r
1633 if (menuErrorMsg[0]) text_out16(5, 226, menuErrorMsg);
\r
1638 int menu_loop_tray(void)
\r
1640 int menu_sel = 0, menu_sel_max = 1;
\r
1641 unsigned long inp = 0;
\r
1642 char curr_path[PATH_MAX], *selfname;
\r
1645 gp2x_memset_all_buffers(0, 0, 320*240*2);
\r
1646 menu_gfx_prepare();
\r
1648 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
1651 strcpy(curr_path, currentConfig.lastRomFile);
\r
1655 getcwd(curr_path, PATH_MAX);
\r
1658 /* make sure action buttons are not pressed on entering menu */
\r
1659 draw_menu_tray(menu_sel);
\r
1660 while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);
\r
1664 draw_menu_tray(menu_sel);
\r
1665 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B);
\r
1666 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
1667 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
1668 if(inp & GP2X_B ) {
\r
1669 switch (menu_sel) {
\r
1670 case 0: // select image
\r
1671 selfname = romsel_loop(curr_path);
\r
1673 int ret = -1, cd_type;
\r
1674 cd_type = emu_cd_check(NULL);
\r
1676 ret = Insert_CD(romFileName, cd_type == 2);
\r
1678 sprintf(menuErrorMsg, "Load failed, invalid CD image?");
\r
1679 printf("%s\n", menuErrorMsg);
\r
1682 engineState = PGS_RestartRun;
\r
1686 case 1: // insert nothing
\r
1687 engineState = PGS_RestartRun;
\r
1691 menuErrorMsg[0] = 0; // clear error msg
\r