1 // (c) Copyright 2006 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
17 #include "version.h"
\r
19 #include "Pico/PicoInt.h"
\r
21 #ifndef _DIRENT_HAVE_D_TYPE
\r
22 #error "need d_type for file browser
\r
25 extern char *actionNames[];
\r
26 extern char romFileName[PATH_MAX];
\r
27 extern char *rom_data;
\r
28 extern int mmuhack_status;
\r
29 extern int state_slot;
\r
31 static char *gp2xKeyNames[] = {
\r
32 "UP", "???", "LEFT", "???", "DOWN", "???", "RIGHT", "???",
\r
33 "START", "SELECT", "L", "R", "A", "B", "X", "Y",
\r
34 "???", "???", "???", "???", "???", "???", "VOL DOWN", "VOL UP",
\r
35 "???", "???", "???", "PUSH", "???", "???", "???", "???"
\r
38 char menuErrorMsg[40] = {0, };
\r
41 static unsigned char fontdata8x8[] =
\r
43 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
\r
44 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
\r
45 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
\r
46 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
\r
47 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
\r
48 0x3C,0x42,0x99,0xBD,0xBD,0x99,0x42,0x3C,0x3C,0x42,0x81,0x81,0x81,0x81,0x42,0x3C,
\r
49 0xFE,0x82,0x8A,0xD2,0xA2,0x82,0xFE,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,
\r
50 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00,
\r
51 0x80,0xC0,0xF0,0xFC,0xF0,0xC0,0x80,0x00,0x01,0x03,0x0F,0x3F,0x0F,0x03,0x01,0x00,
\r
52 0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0x00,0xEE,0xEE,0xEE,0xCC,0x00,0xCC,0xCC,0x00,
\r
53 0x00,0x00,0x30,0x68,0x78,0x30,0x00,0x00,0x00,0x38,0x64,0x74,0x7C,0x38,0x00,0x00,
\r
54 0x3C,0x66,0x7A,0x7A,0x7E,0x7E,0x3C,0x00,0x0E,0x3E,0x3A,0x22,0x26,0x6E,0xE4,0x40,
\r
55 0x18,0x3C,0x7E,0x3C,0x3C,0x3C,0x3C,0x00,0x3C,0x3C,0x3C,0x3C,0x7E,0x3C,0x18,0x00,
\r
56 0x08,0x7C,0x7E,0x7E,0x7C,0x08,0x00,0x00,0x10,0x3E,0x7E,0x7E,0x3E,0x10,0x00,0x00,
\r
57 0x58,0x2A,0xDC,0xC8,0xDC,0x2A,0x58,0x00,0x24,0x66,0xFF,0xFF,0x66,0x24,0x00,0x00,
\r
58 0x00,0x10,0x10,0x38,0x38,0x7C,0xFE,0x00,0xFE,0x7C,0x38,0x38,0x10,0x10,0x00,0x00,
\r
59 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x1C,0x18,0x00,0x18,0x18,0x00,
\r
60 0x6C,0x6C,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00,
\r
61 0x10,0x38,0x60,0x38,0x0C,0x78,0x10,0x00,0x40,0xA4,0x48,0x10,0x24,0x4A,0x04,0x00,
\r
62 0x18,0x34,0x18,0x3A,0x6C,0x66,0x3A,0x00,0x18,0x18,0x20,0x00,0x00,0x00,0x00,0x00,
\r
63 0x30,0x60,0x60,0x60,0x60,0x60,0x30,0x00,0x0C,0x06,0x06,0x06,0x06,0x06,0x0C,0x00,
\r
64 0x10,0x54,0x38,0x7C,0x38,0x54,0x10,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,
\r
65 0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,
\r
66 0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x04,0x08,0x10,0x20,0x40,0x00,0x00,
\r
67 0x38,0x4C,0xC6,0xC6,0xC6,0x64,0x38,0x00,0x18,0x38,0x18,0x18,0x18,0x18,0x7E,0x00,
\r
68 0x7C,0xC6,0x0E,0x3C,0x78,0xE0,0xFE,0x00,0x7E,0x0C,0x18,0x3C,0x06,0xC6,0x7C,0x00,
\r
69 0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x0C,0x00,0xFC,0xC0,0xFC,0x06,0x06,0xC6,0x7C,0x00,
\r
70 0x3C,0x60,0xC0,0xFC,0xC6,0xC6,0x7C,0x00,0xFE,0xC6,0x0C,0x18,0x30,0x30,0x30,0x00,
\r
71 0x78,0xC4,0xE4,0x78,0x86,0x86,0x7C,0x00,0x7C,0xC6,0xC6,0x7E,0x06,0x0C,0x78,0x00,
\r
72 0x00,0x00,0x18,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x18,0x18,0x30,
\r
73 0x1C,0x38,0x70,0xE0,0x70,0x38,0x1C,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00,
\r
74 0x70,0x38,0x1C,0x0E,0x1C,0x38,0x70,0x00,0x7C,0xC6,0xC6,0x1C,0x18,0x00,0x18,0x00,
\r
75 0x3C,0x42,0x99,0xA1,0xA5,0x99,0x42,0x3C,0x38,0x6C,0xC6,0xC6,0xFE,0xC6,0xC6,0x00,
\r
76 0xFC,0xC6,0xC6,0xFC,0xC6,0xC6,0xFC,0x00,0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00,
\r
77 0xF8,0xCC,0xC6,0xC6,0xC6,0xCC,0xF8,0x00,0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xFE,0x00,
\r
78 0xFE,0xC0,0xC0,0xFC,0xC0,0xC0,0xC0,0x00,0x3E,0x60,0xC0,0xCE,0xC6,0x66,0x3E,0x00,
\r
79 0xC6,0xC6,0xC6,0xFE,0xC6,0xC6,0xC6,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,
\r
80 0x06,0x06,0x06,0x06,0xC6,0xC6,0x7C,0x00,0xC6,0xCC,0xD8,0xF0,0xF8,0xDC,0xCE,0x00,
\r
81 0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00,
\r
82 0xC6,0xE6,0xF6,0xFE,0xDE,0xCE,0xC6,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00,
\r
83 0xFC,0xC6,0xC6,0xC6,0xFC,0xC0,0xC0,0x00,0x7C,0xC6,0xC6,0xC6,0xDE,0xCC,0x7A,0x00,
\r
84 0xFC,0xC6,0xC6,0xCE,0xF8,0xDC,0xCE,0x00,0x78,0xCC,0xC0,0x7C,0x06,0xC6,0x7C,0x00,
\r
85 0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x7C,0x00,
\r
86 0xC6,0xC6,0xC6,0xEE,0x7C,0x38,0x10,0x00,0xC6,0xC6,0xD6,0xFE,0xFE,0xEE,0xC6,0x00,
\r
87 0xC6,0xEE,0x3C,0x38,0x7C,0xEE,0xC6,0x00,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x00,
\r
88 0xFE,0x0E,0x1C,0x38,0x70,0xE0,0xFE,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,
\r
89 0x60,0x60,0x30,0x18,0x0C,0x06,0x06,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,
\r
90 0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
\r
91 0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x66,0x3C,0x00,
\r
92 0x60,0x7C,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x3C,0x66,0x60,0x60,0x66,0x3C,0x00,
\r
93 0x06,0x3E,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x3C,0x00,
\r
94 0x1C,0x30,0x78,0x30,0x30,0x30,0x30,0x00,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x3C,
\r
95 0x60,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x00,
\r
96 0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x38,0x60,0x60,0x66,0x6C,0x78,0x6C,0x66,0x00,
\r
97 0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0xEC,0xFE,0xFE,0xFE,0xD6,0xC6,0x00,
\r
98 0x00,0x7C,0x76,0x66,0x66,0x66,0x66,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3C,0x00,
\r
99 0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x00,0x3E,0x66,0x66,0x66,0x3E,0x06,0x06,
\r
100 0x00,0x7E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x3C,0x60,0x3C,0x06,0x66,0x3C,0x00,
\r
101 0x30,0x78,0x30,0x30,0x30,0x30,0x1C,0x00,0x00,0x66,0x66,0x66,0x66,0x6E,0x3E,0x00,
\r
102 0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0xC6,0xD6,0xFE,0xFE,0x7C,0x6C,0x00,
\r
103 0x00,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x66,0x66,0x66,0x66,0x3E,0x06,0x3C,
\r
104 0x00,0x7E,0x0C,0x18,0x30,0x60,0x7E,0x00,0x0E,0x18,0x0C,0x38,0x0C,0x18,0x0E,0x00,
\r
105 0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x70,0x18,0x30,0x1C,0x30,0x18,0x70,0x00,
\r
106 0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00,0x10,0x28,0x10,0x54,0xAA,0x44,0x00,0x00,
\r
109 static void gp2x_text(unsigned char *screen, int x, int y, char *text, int color)
\r
113 screen = screen + x + y*320;
\r
115 for (i = 0; i < strlen(text); i++)
\r
119 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=color;
\r
120 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=color;
\r
121 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=color;
\r
122 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=color;
\r
123 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=color;
\r
124 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=color;
\r
125 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=color;
\r
126 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=color;
\r
132 // draws white text to current bbp15 screen
\r
133 void gp2x_text_out15(int x, int y, char *text)
\r
136 unsigned short *screen = gp2x_screen;
\r
138 screen = screen + x + y*320;
\r
140 for (i = 0; i < strlen(text); i++)
\r
144 if(fontdata8x8[((text[i])*8)+l]&0x80) screen[l*320+0]=0xffff;
\r
145 if(fontdata8x8[((text[i])*8)+l]&0x40) screen[l*320+1]=0xffff;
\r
146 if(fontdata8x8[((text[i])*8)+l]&0x20) screen[l*320+2]=0xffff;
\r
147 if(fontdata8x8[((text[i])*8)+l]&0x10) screen[l*320+3]=0xffff;
\r
148 if(fontdata8x8[((text[i])*8)+l]&0x08) screen[l*320+4]=0xffff;
\r
149 if(fontdata8x8[((text[i])*8)+l]&0x04) screen[l*320+5]=0xffff;
\r
150 if(fontdata8x8[((text[i])*8)+l]&0x02) screen[l*320+6]=0xffff;
\r
151 if(fontdata8x8[((text[i])*8)+l]&0x01) screen[l*320+7]=0xffff;
\r
158 void gp2x_text_out8(int x, int y, char *texto, ...)
\r
163 va_start(args,texto);
\r
164 vsprintf(buffer,texto,args);
\r
167 gp2x_text(gp2x_screen,x,y,buffer,1);
\r
171 void gp2x_text_out8_2(int x, int y, char *texto, int color)
\r
173 gp2x_text(gp2x_screen, x, y, texto, color);
\r
176 void gp2x_text_out8_lim(int x, int y, char *texto, int max)
\r
178 char buffer[320/8+1];
\r
180 strncpy(buffer, texto, 320/8);
\r
181 if (max > 320/8) max = 320/8;
\r
182 if (max < 0) max = 0;
\r
185 gp2x_text(gp2x_screen,x,y,buffer,1);
\r
189 static unsigned long inp_prev = 0;
\r
190 static int inp_prevjoy = 0;
\r
192 static unsigned long wait_for_input(unsigned long interesting)
\r
195 static int repeats = 0, wait = 300*1000;
\r
196 int release = 0, i;
\r
198 if (repeats == 5 || repeats == 15 || repeats == 30) wait /= 2;
\r
200 for (i = 0; i < 6 && inp_prev == gp2x_joystick_read(1); i++) {
\r
201 if(i == 0) repeats++;
\r
205 while ( !((ret = gp2x_joystick_read(1)) & interesting) ) {
\r
210 if (release || ret != inp_prev) {
\r
217 // we don't need diagonals in menus
\r
218 if ((ret&GP2X_UP) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
219 if ((ret&GP2X_UP) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
220 if ((ret&GP2X_DOWN) && (ret&GP2X_LEFT)) ret &= ~GP2X_LEFT;
\r
221 if ((ret&GP2X_DOWN) && (ret&GP2X_RIGHT)) ret &= ~GP2X_RIGHT;
\r
226 static unsigned long input2_read(unsigned long interesting, int *joy)
\r
234 if ((ret = gp2x_joystick_read(0) & interesting)) break;
\r
235 gp2x_usbjoy_update();
\r
236 for (i = 0; i < num_of_joys; i++) {
\r
237 ret = gp2x_usbjoy_check2(i);
\r
238 if (ret) { *joy = i + 1; break; }
\r
247 // similar to wait_for_input(), but returns joy num
\r
248 static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy)
\r
251 const int wait = 300*1000;
\r
254 if (inp_prevjoy == 0) inp_prev &= interesting;
\r
255 for (i = 0; i < 6; i++) {
\r
256 ret = input2_read(interesting, joy);
\r
257 if (*joy != inp_prevjoy || ret != inp_prev) break;
\r
261 while ( !(ret = input2_read(interesting, joy)) ) {
\r
266 inp_prevjoy = *joy;
\r
273 // -------------- ROM selector --------------
\r
275 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
\r
280 n--; // exclude current dir (".")
\r
282 memset(gp2x_screen, 0, 320*240);
\r
285 gp2x_text_out8_lim(14, (start - 2)*10, curdir, 38);
\r
286 for (i = 0; i < n; i++) {
\r
288 if (pos < 0) continue;
\r
289 if (pos > 23) break;
\r
290 if (namelist[i+1]->d_type == DT_DIR) {
\r
291 gp2x_text_out8_lim(14, pos*10, "/", 1);
\r
292 gp2x_text_out8_lim(14+8, pos*10, namelist[i+1]->d_name, 37);
\r
294 gp2x_text_out8_lim(14, pos*10, namelist[i+1]->d_name, 38);
\r
297 gp2x_text_out8(5, 120, ">");
\r
301 static int scandir_cmp(const void *p1, const void *p2)
\r
303 struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;
\r
304 if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);
\r
305 if ((*d1)->d_type == DT_DIR) return -1; // put before
\r
306 if ((*d2)->d_type == DT_DIR) return 1;
\r
307 return alphasort(d1, d2);
\r
311 static char *romsel_loop(char *curr_path)
\r
313 struct dirent **namelist;
\r
316 unsigned long inp = 0;
\r
317 char *ret = NULL, *fname = NULL;
\r
319 // is this a dir or a full path?
\r
320 if ((dir = opendir(curr_path))) {
\r
324 for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
\r
329 n = scandir(curr_path, &namelist, 0, scandir_cmp);
\r
332 n = scandir(curr_path, &namelist, 0, scandir_cmp);
\r
335 printf("dir: "); printf(curr_path); printf("\n");
\r
342 if (fname != NULL) {
\r
344 for (i = 1; i < n; i++) {
\r
345 if (strcmp(namelist[i]->d_name, fname) == 0) {
\r
354 draw_dirlist(curr_path, namelist, n, sel);
\r
355 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X);
\r
356 if(inp & GP2X_UP ) { sel--; if (sel < 0) sel = n-2; }
\r
357 if(inp & GP2X_DOWN) { sel++; if (sel > n-2) sel = 0; }
\r
358 if(inp & GP2X_LEFT) { sel-=10; if (sel < 0) sel = 0; }
\r
359 if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
\r
360 if(inp & GP2X_B) { // enter dir/select
\r
362 if (namelist[sel+1]->d_type == DT_REG) {
\r
363 strcpy(romFileName, curr_path);
\r
364 strcat(romFileName, "/");
\r
365 strcat(romFileName, namelist[sel+1]->d_name);
\r
368 } else if (namelist[sel+1]->d_type == DT_DIR) {
\r
369 int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
\r
370 char *p, *newdir = malloc(newlen);
\r
371 if (strcmp(namelist[sel+1]->d_name, "..") == 0) {
\r
372 char *start = curr_path;
\r
373 p = start + strlen(start) - 1;
\r
374 while (*p == '/' && p > start) p--;
\r
375 while (*p != '/' && p > start) p--;
\r
376 if (p <= start) strcpy(newdir, "/");
\r
377 else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
\r
379 strcpy(newdir, curr_path);
\r
380 p = newdir + strlen(newdir) - 1;
\r
381 while (*p == '/' && p >= newdir) *p-- = 0;
\r
382 strcat(newdir, "/");
\r
383 strcat(newdir, namelist[sel+1]->d_name);
\r
385 ret = romsel_loop(newdir);
\r
389 // unknown file type, happens on NTFS mounts. Try to guess.
\r
390 FILE *tstf; int tmp;
\r
391 strcpy(romFileName, curr_path);
\r
392 strcat(romFileName, "/");
\r
393 strcat(romFileName, namelist[sel+1]->d_name);
\r
394 tstf = fopen(romFileName, "rb");
\r
397 if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)
\r
398 namelist[sel+1]->d_type = DT_REG;
\r
399 else namelist[sel+1]->d_type = DT_DIR;
\r
405 if(inp & GP2X_X) break; // cancel
\r
409 while(n--) free(namelist[n]);
\r
416 // -------------- key config --------------
\r
418 static char *usb_joy_key_name(int joy, int num)
\r
420 static char name[16];
\r
423 case 0: sprintf(name, "Joy%i UP", joy); break;
\r
424 case 1: sprintf(name, "Joy%i DOWN", joy); break;
\r
425 case 2: sprintf(name, "Joy%i LEFT", joy); break;
\r
426 case 3: sprintf(name, "Joy%i RIGHT", joy); break;
\r
427 default:sprintf(name, "Joy%i b%i", joy, num-3); break;
\r
432 static void draw_key_config(int curr_act, int is_p2)
\r
434 char strkeys[32*5];
\r
438 for (i = 0; i < 32; i++)
\r
440 if (currentConfig.KeyBinds[i] & (1 << curr_act))
\r
442 if (curr_act < 16 && (currentConfig.KeyBinds[i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
443 if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }
\r
444 else strcpy(strkeys, gp2xKeyNames[i]);
\r
447 for (joy = 0; joy < num_of_joys; joy++)
\r
449 for (i = 0; i < 32; i++)
\r
451 if (currentConfig.JoyBinds[joy][i] & (1 << curr_act))
\r
453 if (curr_act < 16 && (currentConfig.JoyBinds[joy][i] & (1 << 16)) != (is_p2 << 16)) continue;
\r
455 strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));
\r
458 else strcpy(strkeys, usb_joy_key_name(joy + 1, i));
\r
463 memset(gp2x_screen, 0, 320*240);
\r
464 gp2x_text_out8(60, 40, "Action: %s", actionNames[curr_act]);
\r
465 gp2x_text_out8(60, 60, "Keys: %s", strkeys);
\r
467 gp2x_text_out8(30, 180, "Use SELECT to change action");
\r
468 gp2x_text_out8(30, 190, "Press a key to bind/unbind");
\r
469 gp2x_text_out8(30, 200, "Select \"Done\" action and");
\r
470 gp2x_text_out8(30, 210, " press any key to finish");
\r
474 static void key_config_loop(int is_p2)
\r
476 int curr_act = 0, joy = 0, i;
\r
477 unsigned long inp = 0;
\r
481 draw_key_config(curr_act, is_p2);
\r
482 inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);
\r
483 // printf("got %08lX from joy %i\n", inp, joy);
\r
485 if (inp & GP2X_SELECT) {
\r
487 while (!actionNames[curr_act] && curr_act < 32) curr_act++;
\r
488 if (curr_act > 31) curr_act = 0;
\r
490 inp &= CONFIGURABLE_KEYS;
\r
491 inp &= ~GP2X_SELECT;
\r
493 if (curr_act == 31 && inp) break;
\r
495 for (i = 0; i < 32; i++)
\r
496 if (inp & (1 << i)) {
\r
497 currentConfig.KeyBinds[i] ^= (1 << curr_act);
\r
498 if (is_p2) currentConfig.KeyBinds[i] |= (1 << 16); // player 2 flag
\r
499 else currentConfig.KeyBinds[i] &= ~(1 << 16);
\r
502 for (i = 0; i < 32; i++)
\r
503 if (inp & (1 << i)) {
\r
504 currentConfig.JoyBinds[joy-1][i] ^= (1 << curr_act);
\r
505 if (is_p2) currentConfig.JoyBinds[joy-1][i] |= (1 << 16);
\r
506 else currentConfig.JoyBinds[joy-1][i] &= ~(1 << 16);
\r
512 static void draw_kc_sel(int menu_sel)
\r
514 int tl_x = 25+40, tl_y = 60, y, i;
\r
518 memset(gp2x_screen, 0, 320*240);
\r
519 gp2x_text_out8(tl_x, y, "Player 1");
\r
520 gp2x_text_out8(tl_x, (y+=10), "Player 2");
\r
521 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
524 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
527 gp2x_text_out8(tl_x, (y=110), "USB joys detected:");
\r
528 if (num_of_joys > 0) {
\r
529 for (i = 0; i < num_of_joys; i++) {
\r
530 strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;
\r
531 gp2x_text_out8(tl_x, (y+=10), "%i: %s", i+1, joyname);
\r
534 gp2x_text_out8(tl_x, (y+=10), "none");
\r
541 static void kc_sel_loop(void)
\r
543 int menu_sel = 2, menu_sel_max = 2;
\r
544 unsigned long inp = 0;
\r
548 draw_kc_sel(menu_sel);
\r
549 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);
\r
550 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
551 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
553 switch (menu_sel) {
\r
554 case 0: key_config_loop(0); return;
\r
555 case 1: key_config_loop(1); return;
\r
559 if(inp & GP2X_X) return;
\r
566 // --------- advanced options ----------
\r
568 // order must match that of currentConfig_t
\r
579 static void draw_amenu_options(int menu_sel)
\r
581 int tl_x = 25, tl_y = 60, y;
\r
582 char *mms = mmuhack_status ? "active) " : "inactive)";
\r
585 memset(gp2x_screen, 0, 320*240);
\r
586 gp2x_text_out8(tl_x, y, "Scale 32 column mode %s", (tmp_opts.PicoOpt&0x100)?"ON":"OFF"); // 0
\r
587 gp2x_text_out8(tl_x, (y+=10), "Gamma correction %i.%02i", tmp_gamma / 100, tmp_gamma%100); // 1
\r
588 gp2x_text_out8(tl_x, (y+=10), "Emulate Z80 %s", (tmp_opts.PicoOpt&0x004)?"ON":"OFF"); // 2
\r
589 gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM) %s", (tmp_opts.PicoOpt&0x001)?"ON":"OFF"); // 3
\r
590 gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG) %s", (tmp_opts.PicoOpt&0x002)?"ON":"OFF"); // 4
\r
591 gp2x_text_out8(tl_x, (y+=10), "gzip savestates %s", (tmp_opts.EmuOpt &0x008)?"ON":"OFF"); // 5
\r
592 gp2x_text_out8(tl_x, (y+=10), "Don't save config on exit %s", (tmp_opts.EmuOpt &0x020)?"ON":"OFF"); // 6
\r
593 gp2x_text_out8(tl_x, (y+=10), "needs restart:");
\r
594 gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings %s", (tmp_opts.EmuOpt &0x100)?"ON":"OFF"); // 8
\r
595 gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s", mms, (tmp_opts.EmuOpt &0x010)?"ON":"OFF"); // 9
\r
596 gp2x_text_out8(tl_x, (y+=10), "Done");
\r
599 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
604 static void amenu_loop_options(void)
\r
606 int menu_sel = 0, menu_sel_max = 10;
\r
607 unsigned long inp = 0;
\r
611 draw_amenu_options(menu_sel);
\r
612 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
613 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
614 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
615 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
616 switch (menu_sel) {
\r
617 case 0: tmp_opts.PicoOpt^=0x100; break;
\r
618 case 2: tmp_opts.PicoOpt^=0x004; break;
\r
619 case 3: tmp_opts.PicoOpt^=0x001; break;
\r
620 case 4: tmp_opts.PicoOpt^=0x002; break;
\r
621 case 5: tmp_opts.EmuOpt ^=0x008; break;
\r
622 case 6: tmp_opts.EmuOpt ^=0x020; break;
\r
623 case 8: tmp_opts.EmuOpt ^=0x100; break;
\r
624 case 9: tmp_opts.EmuOpt ^=0x010; break;
\r
628 if(inp & (GP2X_X|GP2X_A)) return;
\r
629 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
630 switch (menu_sel) {
\r
632 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
633 tmp_gamma += (inp & GP2X_LEFT) ? -1 : 1;
\r
634 if (tmp_gamma < 1) tmp_gamma = 1;
\r
635 if (tmp_gamma > 300) tmp_gamma = 300;
\r
636 draw_amenu_options(menu_sel);
\r
645 // -------------- options --------------
\r
647 static char *region_name(unsigned int code)
\r
649 char *names[] = { "Auto", "Japan NTSC", "Japan PAL", "USA", "Europe" };
\r
652 while((code >>=1)) i++;
\r
653 if (i > 4) return "unknown";
\r
657 static void draw_menu_options(int menu_sel)
\r
659 int tl_x = 25, tl_y = 40, y;
\r
660 char monostereo[8], strframeskip[8], *strrend;
\r
662 strcpy(monostereo, (tmp_opts.PicoOpt&0x08)?"stereo":"mono");
\r
663 if (tmp_opts.Frameskip < 0)
\r
664 strcpy(strframeskip, "Auto");
\r
665 else sprintf(strframeskip, "%i", tmp_opts.Frameskip);
\r
666 if (tmp_opts.PicoOpt&0x10) {
\r
667 strrend = " 8bit fast";
\r
668 } else if (tmp_opts.EmuOpt&0x80) {
\r
669 strrend = "16bit accurate";
\r
671 strrend = " 8bit accurate";
\r
675 memset(gp2x_screen, 0, 320*240);
\r
676 gp2x_text_out8(tl_x, y, "Renderer: %s", strrend); // 0
\r
677 gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower) %s", (tmp_opts.PicoOpt&0x040)?"ON":"OFF"); // 1
\r
678 gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower) %s", (tmp_opts.PicoOpt&0x080)?"ON":"OFF"); // 2
\r
679 gp2x_text_out8(tl_x, (y+=10), "Show FPS %s", (tmp_opts.EmuOpt &0x002)?"ON":"OFF"); // 3
\r
680 gp2x_text_out8(tl_x, (y+=10), "Frameskip %s", strframeskip);
\r
681 gp2x_text_out8(tl_x, (y+=10), "Enable sound %s", (tmp_opts.EmuOpt &0x004)?"ON":"OFF"); // 5
\r
682 gp2x_text_out8(tl_x, (y+=10), "Sound Quality: %5iHz %s", tmp_opts.PsndRate, monostereo);
\r
683 gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound %s", (tmp_opts.PicoOpt&0x200)?"ON":"OFF"); // 7
\r
684 gp2x_text_out8(tl_x, (y+=10), "6 button pad %s", (tmp_opts.PicoOpt&0x020)?"ON":"OFF"); // 8
\r
685 gp2x_text_out8(tl_x, (y+=10), "Genesis Region: %s", region_name(tmp_opts.PicoRegion));
\r
686 gp2x_text_out8(tl_x, (y+=10), "Use SRAM savestates %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10
\r
687 gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites %s", (tmp_opts.EmuOpt &0x200)?"ON":"OFF"); // 11
\r
688 gp2x_text_out8(tl_x, (y+=10), "Save slot %i", state_slot); // 12
\r
689 gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks %iMhz", tmp_opts.CPUclock);
\r
690 gp2x_text_out8(tl_x, (y+=10), "[advanced options]");
\r
691 gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");
\r
693 gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");
\r
696 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
701 static int sndrate_prevnext(int rate, int dir)
\r
703 int i, rates[] = { 8000, 11025, 16000, 22050, 44100 };
\r
705 for (i = 0; i < 5; i++)
\r
706 if (rates[i] == rate) break;
\r
709 if (i > 4) return dir ? 44100 : 22050;
\r
710 if (i < 0) return dir ? 11025 : 8000;
\r
714 static void menu_options_save(void)
\r
716 memcpy(¤tConfig.EmuOpt, &tmp_opts.EmuOpt, sizeof(tmp_opts));
\r
717 currentConfig.gamma = tmp_gamma;
\r
718 PicoOpt = currentConfig.PicoOpt;
\r
719 PsndRate = currentConfig.PsndRate;
\r
720 PicoRegionOverride = currentConfig.PicoRegion;
\r
721 if (PicoOpt & 0x20) {
\r
722 actionNames[ 8] = "Z"; actionNames[ 9] = "Y";
\r
723 actionNames[10] = "X"; actionNames[11] = "MODE";
\r
725 actionNames[8] = actionNames[9] = actionNames[10] = actionNames[11] = 0;
\r
729 static void menu_loop_options(void)
\r
731 int menu_sel = 0, menu_sel_max = 15;
\r
732 unsigned long inp = 0;
\r
734 if (rom_data) menu_sel_max++;
\r
735 memcpy(&tmp_opts.EmuOpt, ¤tConfig.EmuOpt, sizeof(tmp_opts));
\r
736 tmp_gamma = currentConfig.gamma;
\r
737 tmp_opts.PicoOpt = PicoOpt;
\r
738 tmp_opts.PsndRate = PsndRate;
\r
739 tmp_opts.PicoRegion = PicoRegionOverride;
\r
743 draw_menu_options(menu_sel);
\r
744 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);
\r
745 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
\r
746 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
\r
747 if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options
\r
748 switch (menu_sel) {
\r
749 case 1: tmp_opts.PicoOpt^=0x040; break;
\r
750 case 2: tmp_opts.PicoOpt^=0x080; break;
\r
751 case 3: tmp_opts.EmuOpt ^=0x002; break;
\r
752 case 5: tmp_opts.EmuOpt ^=0x004; break;
\r
753 case 7: tmp_opts.PicoOpt^=0x200; break;
\r
754 case 8: tmp_opts.PicoOpt^=0x020; break;
\r
755 case 10: tmp_opts.EmuOpt ^=0x001; break;
\r
756 case 11: tmp_opts.EmuOpt ^=0x200; break;
\r
757 case 14: amenu_loop_options(); break;
\r
758 case 15: // done (save)
\r
759 menu_options_save();
\r
760 emu_WriteConfig(0);
\r
762 case 16: // done (save for current game)
\r
763 menu_options_save();
\r
764 emu_WriteConfig(1);
\r
768 if(inp & GP2X_X) return; // done (no save)
\r
770 menu_options_save();
\r
771 return; // done (save)
\r
773 if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise
\r
774 switch (menu_sel) {
\r
776 if (inp & GP2X_LEFT) {
\r
777 if ( tmp_opts.PicoOpt&0x10) tmp_opts.PicoOpt&= ~0x10;
\r
778 else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.EmuOpt |= 0x80;
\r
779 else if ( tmp_opts.EmuOpt &0x80) break;
\r
781 if ( tmp_opts.PicoOpt&0x10) break;
\r
782 else if (!(tmp_opts.EmuOpt &0x80))tmp_opts.PicoOpt|= 0x10;
\r
783 else if ( tmp_opts.EmuOpt &0x80) tmp_opts.EmuOpt &= ~0x80;
\r
787 tmp_opts.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;
\r
788 if (tmp_opts.Frameskip < 0) tmp_opts.Frameskip = -1;
\r
789 if (tmp_opts.Frameskip > 32) tmp_opts.Frameskip = 32;
\r
792 if ((inp & GP2X_RIGHT) && tmp_opts.PsndRate == 44100 && !(tmp_opts.PicoOpt&0x08)) {
\r
793 tmp_opts.PsndRate = 8000; tmp_opts.PicoOpt|= 0x08;
\r
794 } else if ((inp & GP2X_LEFT) && tmp_opts.PsndRate == 8000 && (tmp_opts.PicoOpt&0x08)) {
\r
795 tmp_opts.PsndRate = 44100; tmp_opts.PicoOpt&=~0x08;
\r
796 } else tmp_opts.PsndRate = sndrate_prevnext(tmp_opts.PsndRate, inp & GP2X_RIGHT);
\r
799 if (inp & GP2X_RIGHT) {
\r
800 if (tmp_opts.PicoRegion) tmp_opts.PicoRegion<<=1; else tmp_opts.PicoRegion=1;
\r
801 if (tmp_opts.PicoRegion > 8) tmp_opts.PicoRegion = 8;
\r
802 } else tmp_opts.PicoRegion>>=1;
\r
805 if (inp & GP2X_RIGHT) {
\r
806 state_slot++; if (state_slot > 9) state_slot = 0;
\r
807 } else {state_slot--; if (state_slot < 0) state_slot = 9;
\r
811 while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {
\r
812 tmp_opts.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;
\r
813 if (tmp_opts.CPUclock < 1) tmp_opts.CPUclock = 1;
\r
814 draw_menu_options(menu_sel);
\r
823 // -------------- credits --------------
\r
825 static void draw_menu_credits(void)
\r
827 int tl_x = 15, tl_y = 70, y;
\r
828 memset(gp2x_screen, 0, 320*240);
\r
830 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006");
\r
832 gp2x_text_out8(tl_x, y, "Credits:");
\r
833 gp2x_text_out8(tl_x, (y+=10), "Dave: Cyclone 68000 core,");
\r
834 gp2x_text_out8(tl_x, (y+=10), " base code of PicoDrive");
\r
835 gp2x_text_out8(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");
\r
836 gp2x_text_out8(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");
\r
837 gp2x_text_out8(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");
\r
838 gp2x_text_out8(tl_x, (y+=10), "Stephane Dallongeville:");
\r
839 gp2x_text_out8(tl_x, (y+=10), " opensource Gens");
\r
840 gp2x_text_out8(tl_x, (y+=10), "Haze: Genesis hw info");
\r
841 gp2x_text_out8(tl_x, (y+=10), "rlyeh and others: minimal SDK");
\r
842 gp2x_text_out8(tl_x, (y+=10), "Squidge: squidgehack");
\r
843 gp2x_text_out8(tl_x, (y+=10), "Dzz: ARM940 sample");
\r
844 gp2x_text_out8(tl_x, (y+=10), "GnoStiC / Puck2099: USB joystick");
\r
845 gp2x_text_out8(tl_x, (y+=10), "craigix: GP2X hardware");
\r
851 // -------------- root menu --------------
\r
853 static void draw_menu_root(int menu_sel)
\r
855 int tl_x = 70, tl_y = 70, y;
\r
856 memset(gp2x_screen, 0, 320*240);
\r
858 gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);
\r
862 gp2x_text_out8(tl_x, y, "Resume game");
\r
863 gp2x_text_out8(tl_x, (y+=10), "Save State");
\r
864 gp2x_text_out8(tl_x, (y+=10), "Load State");
\r
865 gp2x_text_out8(tl_x, (y+=10), "Reset game");
\r
869 gp2x_text_out8(tl_x, (y+=10), "Load new ROM");
\r
870 gp2x_text_out8(tl_x, (y+=10), "Change options");
\r
871 gp2x_text_out8(tl_x, (y+=10), "Configure controls");
\r
872 gp2x_text_out8(tl_x, (y+=10), "Credits");
\r
873 gp2x_text_out8(tl_x, (y+=10), "Exit");
\r
876 gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");
\r
878 if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);
\r
883 static void menu_loop_root(void)
\r
885 int menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;
\r
886 unsigned long inp = 0;
\r
887 char curr_path[PATH_MAX], *selfname;
\r
890 if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )
\r
893 strcpy(curr_path, currentConfig.lastRomFile);
\r
897 getcwd(curr_path, PATH_MAX);
\r
900 if (rom_data) menu_sel = menu_sel_min = 0;
\r
904 draw_menu_root(menu_sel);
\r
905 inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT);
\r
906 if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }
\r
907 if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }
\r
908 if(inp &(GP2X_SELECT|GP2X_X)){
\r
910 while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released
\r
911 engineState = PGS_Running;
\r
915 if(inp & GP2X_B ) {
\r
916 switch (menu_sel) {
\r
917 case 0: // resume game
\r
918 if (rom_data) { engineState = PGS_Running; return; }
\r
920 case 1: // save state
\r
922 if(emu_SaveLoadGame(0, 0)) {
\r
923 strcpy(menuErrorMsg, "save failed");
\r
926 engineState = PGS_Running;
\r
930 case 2: // load state
\r
932 if(emu_SaveLoadGame(1, 0)) {
\r
933 strcpy(menuErrorMsg, "load failed");
\r
936 engineState = PGS_Running;
\r
940 case 3: // reset game
\r
943 engineState = PGS_Running;
\r
947 case 4: // select rom
\r
948 selfname = romsel_loop(curr_path);
\r
950 printf("selected file: %s\n", selfname);
\r
951 strncpy(currentConfig.lastRomFile, selfname, sizeof(currentConfig.lastRomFile)-1);
\r
952 currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;
\r
953 engineState = PGS_ReloadRom;
\r
957 menu_loop_options();
\r
959 case 6: // controls
\r
963 draw_menu_credits();
\r
965 inp = wait_for_input(GP2X_B|GP2X_X);
\r
968 engineState = PGS_Quit;
\r
972 menuErrorMsg[0] = 0; // clear error msg
\r
977 void menu_loop(void)
\r
982 gp2x_video_changemode(8);
\r
983 gp2x_video_RGB_setscaling(320, 240);
\r
986 pal[1] = 0x00ffffff;
\r
987 gp2x_video_setpalette(pal, 2);
\r
991 menuErrorMsg[0] = 0;
\r