X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=fceu.git;a=blobdiff_plain;f=drivers%2Fgp2x%2Fmenu.c;h=86aff2386293a950ef2393afb1b8c5263c03ee23;hp=6f0a9d58bf83423d5ae77587bd3141111cbd23a6;hb=03497cf8eeda7f6d0ad91286819ed613e8d8f648;hpb=b547bda76671cf9c99973dd3faad97804949ced3 diff --git a/drivers/gp2x/menu.c b/drivers/gp2x/menu.c index 6f0a9d5..86aff23 100644 --- a/drivers/gp2x/menu.c +++ b/drivers/gp2x/menu.c @@ -20,19 +20,19 @@ #include "../../input.h" #include "../../state.h" +#include "../../palette.h" +#include "readpng.h" #ifndef _DIRENT_HAVE_D_TYPE #error "need d_type for file browser #endif -static int GP2X_PORT_REV = -#include "rev.h" -; - +extern int GP2X_PORT_REV; extern char lastLoadedGameName[PATH_MAX]; -extern int mmuhack_status; -//extern int state_slot; // TODO +extern int mmuhack_status; +extern int soundvol; extern uint8 Exit; // exit emu loop flag +extern int InitSound(void); #define CONFIGURABLE_KEYS (GP2X_UP|GP2X_LEFT|GP2X_DOWN|GP2X_RIGHT|GP2X_START|GP2X_SELECT|GP2X_L|GP2X_R|GP2X_A|GP2X_B|GP2X_X|GP2X_Y|GP2X_PUSH) @@ -43,12 +43,69 @@ static char *gp2xKeyNames[] = { "18???", "19???", "1a???","PUSH", "1c???","1d???", "1e???", "1f???" }; + +static char path_buffer[PATH_MAX]; +static unsigned short *menu_bg = 0; +static int txt_xmin, txt_xmax, txt_ymin, txt_ymax; + char menuErrorMsg[40] = {0, }; -// TODO -void gp2x_fceu_copy_bg(void) +static void gp2x_fceu_darken_reset(void) { - memset(gp2x_screen, 0, 320*240*2); + txt_xmin = 320; txt_xmax = 0; + txt_ymin = 240; txt_ymax = 0; +} + +static void gp2x_fceu_copy_bg(void) +{ + if (menu_bg) + memcpy(gp2x_screen, menu_bg, 320*240*2); + else memset(gp2x_screen, 0, 320*240*2); + gp2x_fceu_darken_reset(); +} + +static void gp2x_fceu_darken_text_bg(void) +{ + int x, y, xmin, xmax, ymax; + unsigned short *screen = gp2x_screen; + + xmin = txt_xmin - 3; + if (xmin < 0) xmin = 0; + xmax = txt_xmax + 2; + if (xmax > 319) xmax = 319; + + y = txt_ymin - 3; + if (y < 0) y = 0; + ymax = txt_ymax + 2; + if (ymax > 239) ymax = 239; + + for (x = xmin; x <= xmax; x++) + screen[y*320+x] = 0xa514; + for (y++; y < ymax; y++) + { + screen[y*320+xmin] = 0xffff; + for (x = xmin+1; x < xmax; x++) + { + unsigned int p = screen[y*320+x]; + if (p != 0xffff) + screen[y*320+x] = ((p&0xf79e)>>1) - ((p&0xc618)>>3); + } + screen[y*320+xmax] = 0xffff; + } + for (x = xmin; x <= xmax; x++) + screen[y*320+x] = 0xffff; +} + +static void gp2x_fceu_darken_all(void) +{ + unsigned int *screen = gp2x_screen; + int count = 320*240/2; + + while (count--) + { + unsigned int p = screen[count]; + screen[count] = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3); + } } // draws white text to current bbp15 screen @@ -74,6 +131,10 @@ static void gp2x_text_out15_(int x, int y, const char *text) } screen += 8; } + if (x < txt_xmin) txt_xmin = x; + if (x+i*8 > txt_xmax) txt_xmax = x+i*8; + if (y < txt_ymin) txt_ymin = y; + if (y+8 > txt_ymax) txt_ymax = y+8; } void gp2x_text_out15(int x, int y, const char *texto, ...) @@ -241,8 +302,8 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) start = 12 - sel; n--; // exclude current dir (".") - //memset(gp2x_screen, 0, 320*240); gp2x_fceu_copy_bg(); + gp2x_fceu_darken_all(); if(start - 2 >= 0) gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2); @@ -292,11 +353,11 @@ static int scandir_filter(const struct dirent *ent) return 1; } -static char *romsel_loop(char *curr_path) +static char *filesel_loop(char *curr_path, char *final_dest) { struct dirent **namelist; DIR *dir; - int n, sel = 0; + int n, newlen, sel = 0; unsigned long inp = 0; char *ret = NULL, *fname = NULL; @@ -345,15 +406,18 @@ static char *romsel_loop(char *curr_path) if(inp & GP2X_R) { sel+=24; if (sel > n-2) sel = n-2; } if(inp & GP2X_B) { // enter dir/select again: - if (namelist[sel+1]->d_type == DT_REG) { - strcpy(lastLoadedGameName, curr_path); - strcat(lastLoadedGameName, "/"); - strcat(lastLoadedGameName, namelist[sel+1]->d_name); - ret = lastLoadedGameName; + newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; + if (namelist[sel+1]->d_type == DT_REG) { // file selected + if (final_dest == NULL) final_dest = malloc(newlen); + if (final_dest == NULL) break; + strcpy(final_dest, curr_path); + strcat(final_dest, "/"); + strcat(final_dest, namelist[sel+1]->d_name); + ret = final_dest; break; } else if (namelist[sel+1]->d_type == DT_DIR) { - int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2; char *p, *newdir = malloc(newlen); + if (newdir == NULL) break; if (strcmp(namelist[sel+1]->d_name, "..") == 0) { char *start = curr_path; p = start + strlen(start) - 1; @@ -364,20 +428,23 @@ static char *romsel_loop(char *curr_path) } else { strcpy(newdir, curr_path); p = newdir + strlen(newdir) - 1; - while (*p == '/' && p >= newdir) *p-- = 0; + while (p >= newdir && *p == '/') *p-- = 0; strcat(newdir, "/"); strcat(newdir, namelist[sel+1]->d_name); } - ret = romsel_loop(newdir); + ret = filesel_loop(newdir, final_dest); free(newdir); break; } else { // unknown file type, happens on NTFS mounts. Try to guess. - FILE *tstf; int tmp; - strcpy(lastLoadedGameName, curr_path); - strcat(lastLoadedGameName, "/"); - strcat(lastLoadedGameName, namelist[sel+1]->d_name); - tstf = fopen(lastLoadedGameName, "rb"); + char *tstfn; FILE *tstf; int tmp; + tstfn = malloc(newlen); + if (tstfn == NULL) break; + strcpy(tstfn, curr_path); + strcat(tstfn, "/"); + strcat(tstfn, namelist[sel+1]->d_name); + tstf = fopen(tstfn, "rb"); + free(tstfn); if (tstf != NULL) { if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0) @@ -619,7 +686,7 @@ static char *action_binds(int player_idx, int action_mask) { if (Settings.JoyBinds[joy][i] & action_mask) { - if (player_idx >= 0 && ((Settings.KeyBinds[i] >> 16) & 3) != player_idx) continue; + if (player_idx >= 0 && ((Settings.JoyBinds[joy][i] >> 16) & 3) != player_idx) continue; if (strkeys[0]) { strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i)); break; @@ -663,27 +730,14 @@ static int count_bound_keys(int action, int is_joy) typedef struct { char *name; int mask; } bind_action_t; -// b_turbo,a_turbo RLDU SEBA -static bind_action_t ctrl_actions[] = -{ - { "UP ", 0x010 }, - { "DOWN ", 0x020 }, - { "LEFT ", 0x040 }, - { "RIGHT ", 0x080 }, - { "A ", 0x001 }, - { "B ", 0x002 }, - { "A TURBO", 0x100 }, - { "B TURBO", 0x200 }, - { "START ", 0x008 }, - { "SELECT ", 0x004 }, -}; - static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel) { int x, y, tl_y = 40, i; gp2x_fceu_copy_bg(); - gp2x_text_out15(80, 20, "Player %i controls", player_idx + 1); + if (player_idx >= 0) + gp2x_text_out15(80, 20, "Player %i controls", player_idx + 1); + else gp2x_text_out15(80, 20, "Emulator controls"); x = 40; y = tl_y; for (i = 0; i < opt_cnt; i++, y+=10) @@ -694,14 +748,20 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i // draw cursor gp2x_text_out15(x - 16, tl_y + sel*10, ">"); - if (sel < 10) { + gp2x_fceu_darken_text_bg(); + gp2x_fceu_darken_reset(); + + if (sel < opt_cnt) { gp2x_text_out15(30, 190, "Press a button to bind/unbind"); gp2x_text_out15(30, 200, "Use VOL+ to clear"); gp2x_text_out15(30, 210, "To bind UP/DOWN, hold VOL-"); gp2x_text_out15(30, 220, "Select \"Done\" to exit"); } else { + gp2x_text_out15(30, 200, "Use Options -> Save cfg"); + gp2x_text_out15(30, 210, "to save controls"); gp2x_text_out15(30, 220, "Press B or X to exit"); } + gp2x_fceu_darken_text_bg(); gp2x_video_flip(); } @@ -733,17 +793,23 @@ static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_i if (count_bound_keys(opts[sel].mask, 0) >= 2) Settings.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only else Settings.KeyBinds[i] ^= opts[sel].mask; - Settings.KeyBinds[i] &= ~(3 << 16); - Settings.KeyBinds[i] |= player_idx << 16; + if (player_idx >= 0) { + Settings.KeyBinds[i] &= ~(3 << 16); + Settings.KeyBinds[i] |= player_idx << 16; + } } - } else if (sel < opt_cnt) { + } + else if (sel < opt_cnt) + { for (i = 0; i < 32; i++) if (inp & (1 << i)) { if (count_bound_keys(opts[sel].mask, 1) >= 1) // disallow combos for usbjoy Settings.JoyBinds[joy-1][i] &= ~opts[sel].mask; else Settings.JoyBinds[joy-1][i] ^= opts[sel].mask; - Settings.JoyBinds[joy-1][i] &= ~(3 << 16); - Settings.JoyBinds[joy-1][i] |= player_idx << 16; + if (player_idx >= 0) { + Settings.JoyBinds[joy-1][i] &= ~(3 << 16); + Settings.JoyBinds[joy-1][i] |= player_idx << 16; + } } } } @@ -775,9 +841,36 @@ static void draw_kc_sel(int menu_sel) gp2x_text_out15(tl_x, (y+=10), "none"); } + gp2x_fceu_darken_text_bg(); gp2x_video_flip(); } +// b_turbo,a_turbo RLDU SEBA +static bind_action_t ctrl_actions[] = +{ + { "UP ", 0x010 }, + { "DOWN ", 0x020 }, + { "LEFT ", 0x040 }, + { "RIGHT ", 0x080 }, + { "A ", 0x001 }, + { "B ", 0x002 }, + { "A TURBO", 0x100 }, + { "B TURBO", 0x200 }, + { "START ", 0x008 }, + { "SELECT ", 0x004 }, +}; + +static bind_action_t emuctrl_actions[] = +{ + { "Save State ", 1<<31 }, + { "Load State ", 1<<30 }, + { "Next State Slot ", 1<<29 }, + { "Prev State Slot ", 1<<28 }, + { "FDS Insert/Eject ", 1<<27 }, + { "FDS Select Disk ", 1<<26 }, + { "VSUni Insert Coin", 1<<25 }, +}; + static void kc_sel_loop(void) { int menu_sel = 3, menu_sel_max = 3; @@ -793,6 +886,9 @@ static void kc_sel_loop(void) switch (menu_sel) { case 0: key_config_loop(ctrl_actions, 10, 0); return; case 1: key_config_loop(ctrl_actions, 8, 1); return; + case 2: key_config_loop(emuctrl_actions, + sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return; + case 3: if (!fceugi) SaveConfig(NULL); return; default: return; } } @@ -801,74 +897,142 @@ static void kc_sel_loop(void) } +// --------- FCEU options ---------- + +extern int ntsccol,ntschue,ntsctint; +extern int srendlinev[2]; +extern int erendlinev[2]; +extern int eoptions; +extern char *cpalette; +extern void LoadCPalette(void); + + +static void int_incdec(int *p, int inc, int min, int max) +{ + *p += inc; + if (*p < min) *p = min; + else if (*p > max) *p = max; +} -// --------- advanced options ---------- -#if 0 -static void draw_amenu_options(int menu_sel) +static void draw_fcemenu_options(int menu_sel) { int tl_x = 25, tl_y = 60, y; - char *mms = mmuhack_status ? "active) " : "inactive)"; + char cpal[32]; + + if (cpalette != NULL) + { + char *p = cpalette + strlen(cpalette) - 1; + while (*p != '/' && p > cpalette) p--; + if (*p == '/') p++; + strncpy(cpal, p, 16); + cpal[16] = 0; + } + else strcpy(cpal, " OFF"); y = tl_y; - //memset(gp2x_screen, 0, 320*240); gp2x_fceu_copy_bg(); - gp2x_text_out15(tl_x, y, "Gamma correction %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 0 - gp2x_text_out15(tl_x, (y+=10), "Don't save last used ROM %s", (currentConfig.EmuOpt &0x020)?"ON":"OFF"); // 5 - gp2x_text_out15(tl_x, (y+=10), "needs restart:"); - gp2x_text_out15(tl_x, (y+=10), "craigix's RAM timings %s", (currentConfig.EmuOpt &0x100)?"ON":"OFF"); // 7 - gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s", mms, (currentConfig.EmuOpt &0x010)?"ON":"OFF"); // 8 - gp2x_text_out15(tl_x, (y+=10), "Done"); + gp2x_text_out15(tl_x, y, "Custom palette: %s", cpal); // 0 + gp2x_text_out15(tl_x, (y+=10), "NTSC Color Emulation %s", ntsccol?"ON":"OFF"); + gp2x_text_out15(tl_x, (y+=10), " Tint (default: 56) %i", ntsctint); + gp2x_text_out15(tl_x, (y+=10), " Hue (default: 72) %i", ntschue); + gp2x_text_out15(tl_x, (y+=10), "First visible line (NTSC) %i", srendlinev[0]); + gp2x_text_out15(tl_x, (y+=10), "Last visible line (NTSC) %i", erendlinev[0]); // 5 + gp2x_text_out15(tl_x, (y+=10), "First visible line (PAL) %i", srendlinev[1]); + gp2x_text_out15(tl_x, (y+=10), "Last visible line (PAL) %i", erendlinev[1]); + gp2x_text_out15(tl_x, (y+=10), "Clip 8 left/right columns %s", (eoptions&EO_CLIPSIDES)?"ON":"OFF"); + gp2x_text_out15(tl_x, (y+=10), "Disable 8 sprite limit %s", (eoptions&EO_NO8LIM)?"ON":"OFF"); + gp2x_text_out15(tl_x, (y+=10), "Done"); // 10 // draw cursor gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">"); + if (menu_sel == 0) { + gp2x_fceu_darken_text_bg(); + gp2x_fceu_darken_reset(); + + gp2x_text_out15(30, 210, "Press B to browse,"); + gp2x_text_out15(30, 220, "START to use default"); + } + + gp2x_fceu_darken_text_bg(); gp2x_video_flip(); } -static void amenu_loop_options(void) +static void fcemenu_loop_options(void) { - int menu_sel = 0, menu_sel_max = 9; + int menu_sel = 0, menu_sel_max = 10, i; unsigned long inp = 0; + FCEUI_GetNTSCTH(&ntsctint, &ntschue); + for(;;) { - draw_amenu_options(menu_sel); - inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A); + draw_fcemenu_options(menu_sel); + inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START); if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; } if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { - case 1: break; - case 9: return; + case 1: ntsccol = !ntsccol; break; + case 8: eoptions^=EO_CLIPSIDES; break; + case 9: eoptions^=EO_NO8LIM; break; + case 10: return; } } - if(inp & (GP2X_X|GP2X_A)) return; + if(inp & (GP2X_X|GP2X_A)) { + for(i=0;i<2;i++) + { + if(srendlinev[i]<0 || srendlinev[i]>239) srendlinev[i]=0; + if(erendlinev[i]239) erendlinev[i]=239; + } + FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); + FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); + FCEUI_DisableSpriteLimitation(eoptions&EO_NO8LIM); + if (cpalette) LoadCPalette(); + else FCEUI_SetPaletteArray(0); // set to default + FCEU_ResetPalette(); + return; + } if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise switch (menu_sel) { - case 0: - while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) { - currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1; - if (currentConfig.gamma < 1) currentConfig.gamma = 1; - if (currentConfig.gamma > 300) currentConfig.gamma = 300; - draw_amenu_options(menu_sel); - usleep(18*1000); - } - break; + case 2: int_incdec(&ntsctint, (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break; + case 3: int_incdec(&ntschue, (inp & GP2X_LEFT) ? -1 : 1, 0, 128); break; + case 4: int_incdec(&srendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; + case 5: int_incdec(&erendlinev[0], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; + case 6: int_incdec(&srendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; + case 7: int_incdec(&erendlinev[1], (inp & GP2X_LEFT) ? -1 : 1, 0, 239); break; + } + } + if(menu_sel == 0 && (inp & (GP2X_START|GP2X_B))) { // custom palette + if ((inp & GP2X_START) && cpalette) { + free(cpalette); + cpalette=NULL; + } + else if (inp & GP2X_B) { + char *selfname; + if (cpalette) strncpy(path_buffer, cpalette, sizeof(path_buffer)); + else getcwd(path_buffer, PATH_MAX); + path_buffer[sizeof(path_buffer)-1] = 0; + + selfname = filesel_loop(path_buffer, NULL); + if (selfname) { + if (cpalette) free(cpalette); + cpalette = selfname; + } } } } } -#endif // -------------- options -------------- static void draw_menu_options(int menu_sel) { int tl_x = 25, tl_y = 32, y; - char /*monostereo[8],*/ strframeskip[8], *strscaling, *strssconfirm; + char strframeskip[8], *strscaling, *strssconfirm; + char *mms = mmuhack_status ? "active) " : "inactive)"; - //strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono"); if (Settings.frameskip < 0) strcpy(strframeskip, "Auto"); else sprintf(strframeskip, "%i", Settings.frameskip); @@ -886,21 +1050,23 @@ static void draw_menu_options(int menu_sel) } y = tl_y; - //memset(gp2x_screen, 0, 320*240); gp2x_fceu_copy_bg(); gp2x_text_out15(tl_x, y, "Scaling: %s", strscaling); // 0 gp2x_text_out15(tl_x, (y+=10), "Show FPS %s", Settings.showfps?"ON":"OFF"); // 1 gp2x_text_out15(tl_x, (y+=10), "Frameskip %s", strframeskip); // 2 - gp2x_text_out15(tl_x, (y+=10), "Enable sound %s", /*(currentConfig.EmuOpt &0x004)?"ON":*/"OFF"); // 3 - gp2x_text_out15(tl_x, (y+=10), "Sound Quality: %5iHz %s", 0, "" /*currentConfig.PsndRate, monostereo*/); // 4 - gp2x_text_out15(tl_x, (y+=10), "Region: %s", - Settings.region_force == 2 ? "NTSC" : Settings.region_force == 1 ? "PAL" : "OFF"); // 5 - gp2x_text_out15(tl_x, (y+=10), "Use SRAM savestates %s", "OFF"); - gp2x_text_out15(tl_x, (y+=10), "Confirm savestate %s", strssconfirm); - gp2x_text_out15(tl_x, (y+=10), "Save slot %i", 0/*state_slot*/); // 8 - gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock %iMhz", Settings.cpuclock); - gp2x_text_out15(tl_x, (y+=10), "[advanced options]"); // 10 + gp2x_text_out15(tl_x, (y+=10), "Enable sound %s", soundvol?"ON":"OFF"); + gp2x_text_out15(tl_x, (y+=10), "Sound Rate: %5iHz", Settings.sound_rate); // 4 + gp2x_text_out15(tl_x, (y+=10), "Force Region: %s", + Settings.region_force == 2 ? "PAL" : Settings.region_force == 1 ? "NTSC" : "OFF"); // 5 + gp2x_text_out15(tl_x, (y+=10), "Turbo rate %iHz", (Settings.turbo_rate_add*60/2) >> 24); + gp2x_text_out15(tl_x, (y+=10), "Confirm savestate %s", strssconfirm); // 7 + gp2x_text_out15(tl_x, (y+=10), "Save slot %i", CurrentState); + gp2x_text_out15(tl_x, (y+=10), "Faster RAM timings %s", Settings.ramtimings?"ON":"OFF"); + gp2x_text_out15(tl_x, (y+=10), "squidgehack (now %s %s", mms, Settings.mmuhack?"ON":"OFF"); // 10 + gp2x_text_out15(tl_x, (y+=10), "Gamma correction %i.%02i", Settings.gamma / 100, Settings.gamma%100); + gp2x_text_out15(tl_x, (y+=10), "GP2X CPU clock %iMhz", Settings.cpuclock); // 12 + gp2x_text_out15(tl_x, (y+=10), "[FCE Ultra options]"); gp2x_text_out15(tl_x, (y+=10), "Save cfg as default"); if (fceugi) gp2x_text_out15(tl_x, (y+=10), "Save cfg for current game only"); @@ -908,10 +1074,10 @@ static void draw_menu_options(int menu_sel) // draw cursor gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">"); + gp2x_fceu_darken_text_bg(); gp2x_video_flip(); } -/* static int sndrate_prevnext(int rate, int dir) { int i, rates[] = { 8000, 11025, 16000, 22050, 44100 }; @@ -924,17 +1090,18 @@ static int sndrate_prevnext(int rate, int dir) if (i < 0) return dir ? 11025 : 8000; return rates[i]; } -*/ -static void int_incdec(int *p, int inc, int min, int max) + +static void config_commit(void) { - *p += inc; - if (*p < min) *p = min; - else if (*p > max) *p = max; + gp2x_cpuclock_gamma_update(); + if (Settings.region_force) + FCEUI_SetVidSystem(Settings.region_force - 1); } static int menu_loop_options(void) { - int menu_sel = 0, menu_sel_max = 11; + static int menu_sel = 0; + int menu_sel_max = 14; unsigned long inp = 0; if (fceugi) menu_sel_max++; @@ -947,41 +1114,45 @@ static int menu_loop_options(void) if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; } if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options switch (menu_sel) { - case 1: Settings.showfps = !Settings.showfps; break; - //case 6: Settings. = !Settings.showfps; break; - //case 10: amenu_loop_options(); break; - case 11: // done (update and write) - gp2x_cpuclock_update(); + case 1: Settings.showfps = !Settings.showfps; break; + case 3: soundvol = soundvol ? 0 : 100; break; + case 9: Settings.ramtimings = !Settings.ramtimings; break; + case 10: Settings.mmuhack = !Settings.mmuhack; break; + case 13: fcemenu_loop_options(); break; + case 14: // done (update and write) + config_commit(); SaveConfig(NULL); return 1; - case 12: // done (update and write for current game) - gp2x_cpuclock_update(); + case 15: // done (update and write for current game) + config_commit(); if (lastLoadedGameName[0]) SaveConfig(lastLoadedGameName); return 1; } } if(inp & (GP2X_X|GP2X_A)) { - gp2x_cpuclock_update(); + config_commit(); return 0; // done (update, no write) } if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise switch (menu_sel) { case 0: int_incdec(&Settings.scaling, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break; case 2: int_incdec(&Settings.frameskip, (inp & GP2X_LEFT) ? -1 : 1, -1, 32); break; -/* case 4: - if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) { - currentConfig.PsndRate = 8000; currentConfig.PicoOpt|= 0x08; - } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) { - currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08; - } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT); + Settings.sound_rate = sndrate_prevnext(Settings.sound_rate, inp & GP2X_RIGHT); + InitSound(); break; -*/ case 5: int_incdec(&Settings.region_force, (inp & GP2X_LEFT) ? -1 : 1, 0, 2); break; + case 6: { + int hz = Settings.turbo_rate_add*60/2 >> 24; + int_incdec(&hz, (inp & GP2X_LEFT) ? -1 : 1, 1, 30); + Settings.turbo_rate_add = (hz*2 << 24) / 60 + 1; + break; + } case 7: int_incdec(&Settings.sstate_confirm, (inp & GP2X_LEFT) ? -1 : 1, 0, 3); break; case 8: int_incdec(&CurrentState, (inp & GP2X_LEFT) ? -1 : 1, 0, 9); break; - case 9: + case 11: int_incdec(&Settings.gamma, (inp & GP2X_LEFT) ? -1 : 1, 0, 300); break; + case 12: while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) { Settings.cpuclock += (inp & GP2X_LEFT) ? -1 : 1; if (Settings.cpuclock < 0) Settings.cpuclock = 0; // 0 ~ do not change @@ -998,11 +1169,28 @@ static int menu_loop_options(void) static void draw_menu_credits(void) { + char vstr[32]; + //int tl_x = 15, tl_y = 70; gp2x_fceu_copy_bg(); - // TODO + sprintf(vstr, "GPFCE v" GP2X_PORT_VERSION " rev%i", GP2X_PORT_REV); + gp2x_text_out15(20, 30, vstr); + gp2x_text_out15(20, 40, "(c) notaz, 2007"); + gp2x_text_out15(20, 70, "Based on FCE Ultra versions"); + gp2x_text_out15(20, 80, "0.81 and 0.98.1x"); + + gp2x_text_out15(20, 110, " - Credits - "); + gp2x_text_out15(20, 130, "Bero: FCE"); + gp2x_text_out15(20, 140, "Xodnizel: FCE Ultra"); + gp2x_text_out15(20, 150, "zzhu8192: original port"); + gp2x_text_out15(20, 160, "rlyeh: minimal lib"); + gp2x_text_out15(20, 170, "Hermes, theoddbot, god_at_hell:"); + gp2x_text_out15(20, 180, " cpuctrl, gamma libs"); + gp2x_text_out15(20, 190, "Squidge: squidgehack"); + + gp2x_fceu_darken_text_bg(); gp2x_video_flip(); } @@ -1034,13 +1222,18 @@ static void draw_menu_root(int menu_sel) // draw cursor gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">"); - // error - if (menuErrorMsg[0]) gp2x_text_out15(1, 230, menuErrorMsg); + + gp2x_fceu_darken_text_bg(); + gp2x_fceu_darken_reset(); + + // error / version + if (menuErrorMsg[0]) gp2x_text_out15(1, 229, menuErrorMsg); else { char vstr[16]; sprintf(vstr, "v" GP2X_PORT_VERSION " r%i", GP2X_PORT_REV); - gp2x_text_out15(320-strlen(vstr)*8-1, 230, vstr); + gp2x_text_out15(320-strlen(vstr)*8-1, 229, vstr); } + gp2x_fceu_darken_text_bg(); gp2x_video_flip(); } @@ -1050,19 +1243,6 @@ static int menu_loop_root(void) int ret, menu_sel_max = 8, menu_sel_min = 4; static int menu_sel = 4; unsigned long inp = 0; - char curr_path[PATH_MAX], *selfname; - FILE *tstf; - - if ( (tstf = fopen(lastLoadedGameName, "rb")) ) - { - fclose(tstf); - strncpy(curr_path, lastLoadedGameName, sizeof(curr_path)); - curr_path[sizeof(curr_path)-1] = 0; - } - else - { - getcwd(curr_path, PATH_MAX); - } if (fceugi) menu_sel_min = 0; // TODO if (PicoPatches) menu_sel_max = 9; @@ -1100,6 +1280,8 @@ static int menu_loop_root(void) /*if(savestate_menu_loop(0)) continue;*/ FCEUI_SaveState(); + Exit = 0; + while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000); return 0; } break; @@ -1108,6 +1290,8 @@ static int menu_loop_root(void) /*if(savestate_menu_loop(1)) continue;*/ FCEUI_LoadState(); + Exit = 0; + while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000); return 0; } break; @@ -1119,12 +1303,29 @@ static int menu_loop_root(void) } break; case 4: // select rom - selfname = romsel_loop(curr_path); + { + FILE *tstf; + char *selfname; + + if ( (tstf = fopen(lastLoadedGameName, "rb")) ) + { + fclose(tstf); + strncpy(path_buffer, lastLoadedGameName, sizeof(path_buffer)); + path_buffer[sizeof(path_buffer)-1] = 0; + } + else + { + getcwd(path_buffer, PATH_MAX); + } + + selfname = filesel_loop(path_buffer, lastLoadedGameName); if (selfname) { printf("selected file: %s\n", selfname); + while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000); return 2; } break; + } case 5: // options ret = menu_loop_options(); if (ret == 1) continue; // status update @@ -1148,9 +1349,26 @@ static int menu_loop_root(void) } +extern unsigned short gp2x_palette16[256]; + static void menu_prepare_bg(void) { - // TODO... + menu_bg = malloc(320*240*2); + if (menu_bg == NULL) return; + + if (fceugi) + { + /* raw emu frame should now be at gp2x_screen */ + soft_scale((char *)gp2x_screen + 32, gp2x_palette16, srendline, erendline-srendline); + if (srendline) + memset32((int *)((char *)gp2x_screen + 32), 0, srendline*320*2/4); + memcpy(menu_bg, gp2x_screen + 32, 320*240*2); + } + else + { + memset32((int *)menu_bg, 0, 320*240*2/4); + readpng(menu_bg, "background.png"); + } } static void menu_gfx_prepare(void) @@ -1159,6 +1377,7 @@ static void menu_gfx_prepare(void) // switch bpp gp2x_video_changemode(16); + gp2x_video_set_offs(0); gp2x_video_RGB_setscaling(0, 320, 240); gp2x_video_flip(); } @@ -1172,6 +1391,8 @@ int gp2x_menu_do(void) ret = menu_loop_root(); + if (menu_bg) free(menu_bg); + menu_bg = NULL; menuErrorMsg[0] = 0; return ret;