\r
#include "minimal.h"\r
#include "usbjoy.h"\r
-#include "asmutils.h"\r
+#include "../arm/asmutils.h"\r
#include "menu.h"\r
-#include "main.h"\r
-#include "fonts.h"\r
+#include "../common/main.h"\r
+#include "../libpicofe/fonts.h"\r
#include "gp2x.h"\r
\r
#include "../../input.h"\r
#include "../../state.h"\r
#include "../../palette.h"\r
-#include "readpng.h"\r
+#include "../libpicofe/readpng.h"\r
\r
#ifndef _DIRENT_HAVE_D_TYPE\r
-#error "need d_type for file browser\r
+#error need d_type for file browser\r
#endif\r
\r
extern int GP2X_PORT_REV;\r
\r
char menuErrorMsg[40] = {0, };\r
\r
-static void gp2x_fceu_darken_reset(void)\r
+static void menu_flip(void)\r
+{\r
+ gp2x_video_flush_cache();\r
+ gp2x_video_flip();\r
+}\r
+\r
+static void menu_darken_reset(void)\r
{\r
txt_xmin = 320; txt_xmax = 0;\r
txt_ymin = 240; txt_ymax = 0;\r
if (menu_bg)\r
memcpy(gp2x_screen, menu_bg, 320*240*2);\r
else memset(gp2x_screen, 0, 320*240*2);\r
- gp2x_fceu_darken_reset();\r
+ menu_darken_reset();\r
}\r
\r
-static void gp2x_fceu_darken_text_bg(void)\r
+static void menu_darken_text_bg(void)\r
{\r
int x, y, xmin, xmax, ymax;\r
unsigned short *screen = gp2x_screen;\r
gp2x_text_out15(x,y,buffer);\r
}\r
\r
-static void gp2x_smalltext16(int x, int y, const char *texto)\r
+static void gp2x_smalltext16(int x, int y, const char *texto, unsigned short color)\r
{\r
int i;\r
unsigned char *src;\r
int w = 0x20;\r
while (w)\r
{\r
- if( *src & w ) *dst = 0xffff;\r
+ if( *src & w ) *dst = color;\r
dst++;\r
w>>=1;\r
}\r
}\r
}\r
\r
-static void gp2x_smalltext16_lim(int x, int y, const char *texto, int max)\r
+static void gp2x_smalltext16_lim(int x, int y, const char *texto, unsigned short color, int max)\r
{\r
char buffer[320/6+1];\r
\r
if (max < 0) max = 0;\r
buffer[max] = 0;\r
\r
- gp2x_smalltext16(x, y, buffer);\r
+ gp2x_smalltext16(x, y, buffer, color);\r
}\r
\r
\r
\r
// -------------- ROM selector --------------\r
\r
+// rrrr rggg gggb bbbb\r
+static unsigned short file2color(const char *fname)\r
+{\r
+ const char *ext = fname + strlen(fname) - 3;\r
+ static const char *rom_exts[] = { "zip", "nes", "fds", "unf", "nez", "nif" }; // nif is for unif\r
+ static const char *other_exts[] = { "nsf", "ips", "fcm" };\r
+ int i;\r
+\r
+ if (ext < fname) ext = fname;\r
+ for (i = 0; i < sizeof(rom_exts)/sizeof(rom_exts[0]); i++)\r
+ if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff;\r
+ for (i = 0; i < sizeof(other_exts)/sizeof(other_exts[0]); i++)\r
+ if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;\r
+ return 0xffff;\r
+}\r
+\r
static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
{\r
int start, i, pos;\r
gp2x_fceu_darken_all();\r
\r
if(start - 2 >= 0)\r
- gp2x_smalltext16_lim(14, (start - 2)*10, curdir, 53-2);\r
+ gp2x_smalltext16_lim(14, (start - 2)*10, curdir, 0xffff, 53-2);\r
for (i = 0; i < n; i++) {\r
pos = start + i;\r
if (pos < 0) continue;\r
if (pos > 23) break;\r
if (namelist[i+1]->d_type == DT_DIR) {\r
- gp2x_smalltext16_lim(14, pos*10, "/", 1);\r
- gp2x_smalltext16_lim(14+6, pos*10, namelist[i+1]->d_name, 53-3);\r
+ gp2x_smalltext16_lim(14, pos*10, "/", 0xfff6, 1);\r
+ gp2x_smalltext16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xfff6, 53-3);\r
} else {\r
- gp2x_smalltext16_lim(14, pos*10, namelist[i+1]->d_name, 53-2);\r
+ unsigned short color = file2color(namelist[i+1]->d_name);\r
+ gp2x_smalltext16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2);\r
}\r
}\r
gp2x_text_out15(5, 120, ">");\r
- gp2x_video_flip();\r
+ menu_flip();\r
}\r
\r
static int scandir_cmp(const void *p1, const void *p2)\r
{\r
- struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r
+ const struct dirent **d1 = (const struct dirent **)p1;\r
+ const struct dirent **d2 = (const struct dirent **)p2;\r
if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r
if ((*d1)->d_type == DT_DIR) return -1; // put before\r
if ((*d2)->d_type == DT_DIR) return 1;\r
}\r
\r
static char *filter_exts[] = {\r
- ".gpe", ".png", "ck.o", ".txt"\r
+ ".gpe", ".png", "ck.o", ".txt", ".srm"\r
};\r
\r
static int scandir_filter(const struct dirent *ent)\r
fname = p+1;\r
}\r
\r
- n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+ n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp);\r
if (n < 0) {\r
// try root\r
- n = scandir("/", &namelist, scandir_filter, scandir_cmp);\r
+ n = scandir("/", &namelist, scandir_filter, (void *)scandir_cmp);\r
if (n < 0) {\r
// oops, we failed\r
printf("dir: %s\n", curr_path);\r
if (pos < 0) return 1;\r
if (pos > 23) return 0;\r
\r
- gp2x_smalltext16_lim(14, pos*10, s ? "ON " : "OFF", 3);\r
- gp2x_smalltext16_lim(14+6*4, pos*10, type ? "S" : "R", 1);\r
- gp2x_smalltext16_lim(14+6*6, pos*10, name, 53-8);\r
+ gp2x_smalltext16_lim(14, pos*10, s ? "ON " : "OFF", 0xffff, 3);\r
+ gp2x_smalltext16_lim(14+6*4, pos*10, type ? "S" : "R", 0xffff, 1);\r
+ gp2x_smalltext16_lim(14+6*6, pos*10, name, 0xffff, 53-8);\r
\r
return 1;\r
}\r
FCEUI_ListCheats(clistcallb,0);\r
\r
pos = cheat_start + cheat_pos;\r
- if (pos < 24) gp2x_smalltext16_lim(14, pos*10, "done", 4);\r
+ if (pos < 24) gp2x_smalltext16_lim(14, pos*10, "done", 0xffff, 4);\r
\r
gp2x_text_out15(5, 120, ">");\r
- gp2x_video_flip();\r
+ menu_flip();\r
}\r
\r
void patches_menu_loop(void)\r
// draw cursor\r
gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
\r
- gp2x_video_flip();\r
+ menu_flip();\r
}\r
\r
static int savestate_menu_loop(int is_loading)\r
Settings.JoyBinds[u][i] &= ~action;\r
}\r
\r
-static int count_bound_keys(int action, int is_joy)\r
+static int count_bound_keys(int action, int joy)\r
{\r
- int i, u, keys = 0;\r
+ int i, keys = 0;\r
\r
- if (is_joy)\r
+ if (joy)\r
{\r
- for (u = 0; u < 4; u++)\r
- for (i = 0; i < 32; i++)\r
- if (Settings.JoyBinds[u][i] & action) keys++;\r
+ for (i = 0; i < 32; i++)\r
+ if (Settings.JoyBinds[joy-1][i] & action) keys++;\r
}\r
else\r
{\r
// draw cursor\r
gp2x_text_out15(x - 16, tl_y + sel*10, ">");\r
\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_fceu_darken_reset();\r
+ menu_darken_text_bg();\r
+ menu_darken_reset();\r
\r
if (sel < opt_cnt) {\r
gp2x_text_out15(30, 190, "Press a button to bind/unbind");\r
gp2x_text_out15(30, 210, "to save controls");\r
gp2x_text_out15(30, 220, "Press B or X to exit");\r
}\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_video_flip();\r
+ menu_darken_text_bg();\r
+ menu_flip();\r
}\r
\r
static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)\r
{\r
for (i = 0; i < 32; i++)\r
if (inp & (1 << i)) {\r
- if (count_bound_keys(opts[sel].mask, 1) >= 1) // disallow combos for usbjoy\r
+ if (count_bound_keys(opts[sel].mask, joy) >= 1) // disallow combos for usbjoy\r
Settings.JoyBinds[joy-1][i] &= ~opts[sel].mask;\r
else Settings.JoyBinds[joy-1][i] ^= opts[sel].mask;\r
if (player_idx >= 0) {\r
gp2x_text_out15(tl_x, (y+=10), "none");\r
}\r
\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_video_flip();\r
+ menu_darken_text_bg();\r
+ menu_flip();\r
}\r
\r
// b_turbo,a_turbo RLDU SEBA\r
if(inp & GP2X_B) {\r
switch (menu_sel) {\r
case 0: key_config_loop(ctrl_actions, 10, 0); return;\r
- case 1: key_config_loop(ctrl_actions, 8, 1); return;\r
+ case 1: key_config_loop(ctrl_actions, 10, 1); return;\r
case 2: key_config_loop(emuctrl_actions,\r
sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return;\r
case 3: if (!fceugi) SaveConfig(NULL); return;\r
gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
\r
if (menu_sel == 0) {\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_fceu_darken_reset();\r
+ menu_darken_text_bg();\r
+ menu_darken_reset();\r
\r
gp2x_text_out15(30, 210, "Press B to browse,");\r
gp2x_text_out15(30, 220, "START to use default");\r
}\r
\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_video_flip();\r
+ menu_darken_text_bg();\r
+ menu_flip();\r
}\r
\r
static void fcemenu_loop_options(void)\r
\r
static void draw_menu_options(int menu_sel)\r
{\r
- int tl_x = 25, tl_y = 32, y;\r
+ int tl_x = 25, tl_y = 20, y;\r
char strframeskip[8], *strscaling, *strssconfirm;\r
char *mms = mmuhack_status ? "active) " : "inactive)";\r
\r
gp2x_text_out15(tl_x, y, "Scaling: %s", strscaling); // 0\r
gp2x_text_out15(tl_x, (y+=10), "Show FPS %s", Settings.showfps?"ON":"OFF"); // 1\r
gp2x_text_out15(tl_x, (y+=10), "Frameskip %s", strframeskip); // 2\r
+ gp2x_text_out15(tl_x, (y+=10), "Accurate renderer (slow) %s", Settings.accurate_mode?"ON":"OFF");\r
gp2x_text_out15(tl_x, (y+=10), "Enable sound %s", soundvol?"ON":"OFF");\r
- gp2x_text_out15(tl_x, (y+=10), "Sound Rate: %5iHz", Settings.sound_rate); // 4\r
+ gp2x_text_out15(tl_x, (y+=10), "Sound Rate: %5iHz", Settings.sound_rate); // 5\r
gp2x_text_out15(tl_x, (y+=10), "Force Region: %s",\r
- Settings.region_force == 2 ? "PAL" : Settings.region_force == 1 ? "NTSC" : "OFF"); // 5\r
+ Settings.region_force == 2 ? "PAL" : Settings.region_force == 1 ? "NTSC" : "OFF"); // 6\r
gp2x_text_out15(tl_x, (y+=10), "Turbo rate %iHz", (Settings.turbo_rate_add*60/2) >> 24);\r
- gp2x_text_out15(tl_x, (y+=10), "Confirm savestate %s", strssconfirm); // 7\r
+ gp2x_text_out15(tl_x, (y+=10), "Confirm savestate %s", strssconfirm); // 8\r
gp2x_text_out15(tl_x, (y+=10), "Save slot %i", CurrentState);\r
gp2x_text_out15(tl_x, (y+=10), "Faster RAM timings %s", Settings.ramtimings?"ON":"OFF");\r
- gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s", mms, Settings.mmuhack?"ON":"OFF"); // 10\r
+ gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s", mms, Settings.mmuhack?"ON":"OFF"); // 11\r
gp2x_text_out15(tl_x, (y+=10), "Gamma correction %i.%02i", Settings.gamma / 100, Settings.gamma%100);\r
- gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock %iMhz", Settings.cpuclock); // 12\r
+ gp2x_text_out15(tl_x, (y+=10), "Perfect VSYNC %s", Settings.perfect_vsync?"ON":"OFF");\r
+ gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock %iMhz", Settings.cpuclock); // 14\r
gp2x_text_out15(tl_x, (y+=10), "[FCE Ultra options]");\r
- gp2x_text_out15(tl_x, (y+=10), "Save cfg as default");\r
+ gp2x_text_out15(tl_x, (y+=10), "Save cfg as default"); // 16\r
if (fceugi)\r
gp2x_text_out15(tl_x, (y+=10), "Save cfg for current game only");\r
\r
// draw cursor\r
gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_video_flip();\r
+ if (menu_sel == 3) {\r
+ gp2x_text_out15(tl_x, 210, "ROM reload required for this");\r
+ gp2x_text_out15(tl_x, 220, "setting to take effect");\r
+ } else if (menu_sel == 10 || menu_sel == 11) {\r
+ gp2x_text_out15(tl_x, 210, "Emu restart required for this");\r
+ gp2x_text_out15(tl_x, 220, "setting to take effect");\r
+ }\r
+\r
+ menu_darken_text_bg();\r
+ menu_flip();\r
}\r
\r
static int sndrate_prevnext(int rate, int dir)\r
\r
static void config_commit(void)\r
{\r
- gp2x_cpuclock_gamma_update();\r
if (Settings.region_force)\r
FCEUI_SetVidSystem(Settings.region_force - 1);\r
}\r
static int menu_loop_options(void)\r
{\r
static int menu_sel = 0;\r
- int menu_sel_max = 14;\r
+ int ret, menu_sel_max = 16;\r
unsigned long inp = 0;\r
\r
if (fceugi) menu_sel_max++;\r
if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
switch (menu_sel) {\r
- case 1: Settings.showfps = !Settings.showfps; break;\r
- case 3: soundvol = soundvol ? 0 : 100; break;\r
- case 9: Settings.ramtimings = !Settings.ramtimings; break;\r
- case 10: Settings.mmuhack = !Settings.mmuhack; break;\r
- case 13: fcemenu_loop_options(); break;\r
- case 14: // done (update and write)\r
+ case 1: Settings.showfps = !Settings.showfps; break;\r
+ case 3: Settings.accurate_mode = !Settings.accurate_mode; break;\r
+ case 4: soundvol = soundvol ? 0 : 50; break;\r
+ case 10: Settings.ramtimings = !Settings.ramtimings; break;\r
+ case 11: Settings.mmuhack = !Settings.mmuhack; break;\r
+ case 13: Settings.perfect_vsync = !Settings.perfect_vsync; break;\r
+ case 15: fcemenu_loop_options(); break;\r
+ case 16: // done (update and write)\r
config_commit();\r
- SaveConfig(NULL);\r
+ ret = SaveConfig(NULL);\r
+ strcpy(menuErrorMsg, ret == 0 ? "default config saved" : "config save failed");\r
return 1;\r
- case 15: // done (update and write for current game)\r
- config_commit();\r
+ case 17: // done (update and write for current game)\r
if (lastLoadedGameName[0])\r
- SaveConfig(lastLoadedGameName);\r
+ {\r
+ config_commit();\r
+ ret = SaveConfig(lastLoadedGameName);\r
+ strcpy(menuErrorMsg, ret == 0 ? "game config saved" : "config save failed");\r
+ }\r
return 1;\r
}\r
}\r
switch (menu_sel) {\r
case 0: int_incdec(&Settings.scaling, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;\r
case 2: int_incdec(&Settings.frameskip, (inp & GP2X_LEFT) ? -1 : 1, -1, 32); break;\r
- case 4:\r
+ case 5:\r
Settings.sound_rate = sndrate_prevnext(Settings.sound_rate, inp & GP2X_RIGHT);\r
InitSound();\r
break;\r
- case 5: int_incdec(&Settings.region_force, (inp & GP2X_LEFT) ? -1 : 1, 0, 2); break;\r
- case 6: {\r
+ case 6: int_incdec(&Settings.region_force, (inp & GP2X_LEFT) ? -1 : 1, 0, 2); break;\r
+ case 7: {\r
int hz = Settings.turbo_rate_add*60/2 >> 24;\r
int_incdec(&hz, (inp & GP2X_LEFT) ? -1 : 1, 1, 30);\r
Settings.turbo_rate_add = (hz*2 << 24) / 60 + 1;\r
break;\r
}\r
- case 7: int_incdec(&Settings.sstate_confirm, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;\r
- case 8: int_incdec(&CurrentState, (inp & GP2X_LEFT) ? -1 : 1, 0, 9); break;\r
- case 11: int_incdec(&Settings.gamma, (inp & GP2X_LEFT) ? -1 : 1, 0, 300); break;\r
- case 12:\r
+ case 8: int_incdec(&Settings.sstate_confirm, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break;\r
+ case 9: int_incdec(&CurrentState, (inp & GP2X_LEFT) ? -1 : 1, 0, 9); break;\r
+ case 12: int_incdec(&Settings.gamma, (inp & GP2X_LEFT) ? -1 : 1, 0, 300); break;\r
+ case 14:\r
while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
Settings.cpuclock += (inp & GP2X_LEFT) ? -1 : 1;\r
if (Settings.cpuclock < 0) Settings.cpuclock = 0; // 0 ~ do not change\r
gp2x_text_out15(20, 180, " cpuctrl, gamma libs");\r
gp2x_text_out15(20, 190, "Squidge: squidgehack");\r
\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_video_flip();\r
+ menu_darken_text_bg();\r
+ menu_flip();\r
}\r
\r
\r
// draw cursor\r
gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_fceu_darken_reset();\r
+ menu_darken_text_bg();\r
+ menu_darken_reset();\r
\r
// error / version\r
if (menuErrorMsg[0]) gp2x_text_out15(1, 229, menuErrorMsg);\r
sprintf(vstr, "v" GP2X_PORT_VERSION " r%i", GP2X_PORT_REV);\r
gp2x_text_out15(320-strlen(vstr)*8-1, 228, vstr);\r
}\r
- gp2x_fceu_darken_text_bg();\r
- gp2x_video_flip();\r
+ menu_darken_text_bg();\r
+ menu_flip();\r
}\r
\r
\r
else\r
{\r
memset32((int *)menu_bg, 0, 320*240*2/4);\r
- readpng(menu_bg, "background.png");\r
+ readpng(menu_bg, "background.png", READPNG_BG, 320, 240);\r
}\r
}\r
\r
// switch bpp\r
gp2x_video_changemode(16);\r
gp2x_video_set_offs(0);\r
- gp2x_video_RGB_setscaling(0, 320, 240);\r
- gp2x_video_flip();\r
+ gp2x_video_RGB_setscaling(320, 240);\r
+ menu_flip();\r
}\r
\r
\r