psp code updated for latest base, black level
[libpicofe.git] / common / config.c
index c117fb9..d4833f6 100644 (file)
@@ -17,11 +17,32 @@ extern menu_entry cdopt_entries[];
 extern const int opt_entry_count;
 extern const int opt2_entry_count;
 extern const int cdopt_entry_count;
+#ifdef PSP
+extern menu_entry opt3_entries[];
+extern const int opt3_entry_count;
+#endif
+
+static menu_entry *cfg_opts[] =
+{
+       opt_entries,
+       opt2_entries,
+       cdopt_entries,
+#ifdef PSP
+       opt3_entries,
+#endif
+};
 
-static menu_entry *cfg_opts[] = { opt_entries, opt2_entries, cdopt_entries };
-static const int *cfg_opt_counts[] = { &opt_entry_count, &opt2_entry_count, &cdopt_entry_count };
+static const int *cfg_opt_counts[] =
+{
+       &opt_entry_count,
+       &opt2_entry_count,
+       &cdopt_entry_count,
+#ifdef PSP
+       &opt3_entry_count,
+#endif
+};
 
-#define NL "\n"
+#define NL "\r\n"
 
 
 static char *mystrip(char *str)
@@ -70,12 +91,20 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def)
        switch (me->id)
        {
                case MA_OPT_RENDERER:
-                       if (no_def && !((defaultConfig.s_PicoOpt^PicoOpt)&0x10) &&
+                       if (no_def && !((defaultConfig.s_PicoOpt^PicoOpt)&POPT_ALT_RENDERER) &&
                                !((defaultConfig.EmuOpt^currentConfig.EmuOpt)&0x80)) return;
-                       if (PicoOpt&0x10)
-                               str = "8bit fast";
+                       if (PicoOpt&POPT_ALT_RENDERER)
+                               str =
+#ifndef PSP
+                               "8bit "
+#endif
+                               "fast";
                        else if (currentConfig.EmuOpt&0x80)
-                               str = "16bit accurate";
+                               str =
+#ifndef PSP
+                               "16bit "
+#endif
+                               "accurate";
                        else
                                str = "8bit accurate";
                        fprintf(f, "Renderer = %s", str);
@@ -83,13 +112,16 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def)
 
                case MA_OPT_SCALING:
                        if (no_def && defaultConfig.scaling == currentConfig.scaling) return;
+#ifdef __GP2X__
                        switch (currentConfig.scaling) {
                                default: str = "OFF"; break;
                                case 1:  str = "hw horizontal";     break;
                                case 2:  str = "hw horiz. + vert."; break;
                                case 3:  str = "sw horizontal";     break;
+                               case 1:  str = "ON";  break;
                        }
                        fprintf(f, "Scaling = %s", str);
+#endif
                        break;
                case MA_OPT_FRAMESKIP:
                        if (no_def && defaultConfig.Frameskip == currentConfig.Frameskip) return;
@@ -99,15 +131,16 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def)
                        fprintf(f, "Frameskip = %s", str24);
                        break;
                case MA_OPT_SOUND_QUALITY:
-                       if (no_def && !((defaultConfig.s_PicoOpt^PicoOpt)&8) &&
+                       if (no_def && !((defaultConfig.s_PicoOpt^PicoOpt)&POPT_EN_STEREO) &&
                                defaultConfig.s_PsndRate == PsndRate) return;
-                       str = (PicoOpt&0x08)?"stereo":"mono";
+                       str = (PicoOpt&POPT_EN_STEREO)?"stereo":"mono";
                        fprintf(f, "Sound Quality = %i %s", PsndRate, str);
                        break;
                case MA_OPT_REGION:
                        if (no_def && defaultConfig.s_PicoRegion == PicoRegionOverride &&
                                defaultConfig.s_PicoAutoRgnOrder == PicoAutoRgnOrder) return;
-                       fprintf(f, "Region = %s", me_region_name(PicoRegionOverride, PicoAutoRgnOrder));
+                       strncpy(str24, me_region_name(PicoRegionOverride, PicoAutoRgnOrder), 23); str24[23] = 0;
+                       fprintf(f, "Region = %s", mystrip(str24));
                        break;
                case MA_OPT_CONFIRM_STATES:
                        if (no_def && !((defaultConfig.EmuOpt^currentConfig.EmuOpt)&(5<<9))) return;
@@ -121,7 +154,11 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def)
                        break;
                case MA_OPT_CPU_CLOCKS:
                        if (no_def && defaultConfig.CPUclock == currentConfig.CPUclock) return;
+#ifdef __GP2X__
                        fprintf(f, "GP2X CPU clocks = %i", currentConfig.CPUclock);
+#elif defined(PSP)
+                       fprintf(f, "PSP CPU clock = %i", currentConfig.CPUclock);
+#endif
                        break;
                case MA_OPT2_GAMMA:
                        if (no_def && defaultConfig.gamma == currentConfig.gamma) return;
@@ -136,6 +173,38 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def)
                        sprintf(str24, "%i", PicoCDBuffers * 2);
                        fprintf(f, "ReadAhead buffer = %s", str24);
                        break;
+               /* PSP */
+               case MA_OPT3_SCALE:
+                       if (no_def && defaultConfig.scale == currentConfig.scale) return;
+                       fprintf(f, "Scale factor = %.2f", currentConfig.scale);
+                       break;
+               case MA_OPT3_HSCALE32:
+                       if (no_def && defaultConfig.hscale32 == currentConfig.hscale32) return;
+                       fprintf(f, "Hor. scale (for low res. games) = %.2f", currentConfig.hscale32);
+                       break;
+               case MA_OPT3_HSCALE40:
+                       if (no_def && defaultConfig.hscale40 == currentConfig.hscale40) return;
+                       fprintf(f, "Hor. scale (for hi res. games) = %.2f", currentConfig.hscale40);
+                       break;
+               case MA_OPT3_FILTERING:
+                       if (no_def && defaultConfig.scaling == currentConfig.scaling) return;
+                       fprintf(f, "Bilinear filtering = %i", currentConfig.scaling);
+                       break;
+               case MA_OPT3_GAMMAA:
+                       if (no_def && defaultConfig.gamma == currentConfig.gamma) return;
+                       fprintf(f, "Gamma adjustment = %i", currentConfig.gamma);
+                       break;
+               case MA_OPT3_BLACKLVL:
+                       if (no_def && defaultConfig.gamma2 == currentConfig.gamma2) return;
+                       fprintf(f, "Black level = %i", currentConfig.gamma2);
+                       break;
+               case MA_OPT3_VSYNC:
+                       if (no_def && (defaultConfig.EmuOpt&0x12000) == (currentConfig.gamma2&0x12000)) return;
+                       strcpy(str24, "never");
+                       if (currentConfig.EmuOpt & 0x2000)
+                               strcpy(str24, (currentConfig.EmuOpt & 0x10000) ? "sometimes" : "always");
+                       fprintf(f, "Wait for vsync = %s", str24);
+                       break;
 
                default:
                        lprintf("unhandled custom_write: %i\n", me->id);
@@ -154,7 +223,7 @@ static const char *joyKeyNames[32] =
 };
 
 static void keys_write(FILE *fn, const char *bind_str, const int binds[32],
-               const int def_binds[32], const char *names[32], int no_defaults)
+               const int def_binds[32], const char * const names[32], int no_defaults)
 {
        int t, i;
        char act[48];
@@ -168,6 +237,11 @@ static void keys_write(FILE *fn, const char *bind_str, const int binds[32],
 #ifdef __GP2X__
                if (strcmp(names[t], "SELECT") == 0) continue;
 #endif
+               if (binds[t] == 0 && def_binds[t] != 0) {
+                       fprintf(fn, "%s %s =" NL, bind_str, names[t]); // no binds
+                       continue;
+               }
+
                for (i = 0; i < sizeof(me_ctrl_actions) / sizeof(me_ctrl_actions[0]); i++) {
                        if (me_ctrl_actions[i].mask & binds[t]) {
                                strncpy(act, me_ctrl_actions[i].name, 31);
@@ -322,6 +396,11 @@ write:
        keys_write(fn, "bind_joy2", currentConfig.JoyBinds[2], defaultConfig.JoyBinds[2], joyKeyNames, 1);
        keys_write(fn, "bind_joy3", currentConfig.JoyBinds[3], defaultConfig.JoyBinds[3], joyKeyNames, 1);
 
+#ifndef PSP
+       if (section == NULL)
+               fprintf(fn, "Sound Volume = %i" NL, currentConfig.volume);
+#endif
+
        fprintf(fn, NL);
 
        if (fo != NULL)
@@ -350,7 +429,7 @@ int config_writelrom(const char *fname)
        int size;
        FILE *f;
 
-       if (strlen(lastRomFile) == 0) return 0;
+       if (strlen(lastRomFile) == 0) return -1;
 
        f = fopen(fname, "r");
        if (f != NULL)
@@ -434,15 +513,15 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
        {
                case MA_OPT_RENDERER:
                        if (strcasecmp(var, "Renderer") != 0) return 0;
-                       if      (strcasecmp(val, "8bit fast") == 0) {
-                               PicoOpt |=  0x10;
+                       if      (strcasecmp(val, "8bit fast") == 0 || strcasecmp(val, "fast") == 0) {
+                               PicoOpt |=  POPT_ALT_RENDERER;
                        }
-                       else if (strcasecmp(val, "16bit accurate") == 0) {
-                               PicoOpt &= ~0x10;
+                       else if (strcasecmp(val, "16bit accurate") == 0 || strcasecmp(val, "accurate") == 0) {
+                               PicoOpt &= ~POPT_ALT_RENDERER;
                                currentConfig.EmuOpt |=  0x80;
                        }
                        else if (strcasecmp(val, "8bit accurate") == 0) {
-                               PicoOpt &= ~0x10;
+                               PicoOpt &= ~POPT_ALT_RENDERER;
                                currentConfig.EmuOpt &= ~0x80;
                        }
                        else
@@ -450,6 +529,7 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
                        return 1;
 
                case MA_OPT_SCALING:
+#ifdef __GP2X__
                        if (strcasecmp(var, "Scaling") != 0) return 0;
                        if        (strcasecmp(val, "OFF") == 0) {
                                currentConfig.scaling = 0;
@@ -462,6 +542,9 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
                        } else
                                return 0;
                        return 1;
+#else
+                       return 0;
+#endif
 
                case MA_OPT_FRAMESKIP:
                        if (strcasecmp(var, "Frameskip") != 0) return 0;
@@ -477,9 +560,9 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
                                PsndRate = 22050;
                        while (*tmp == ' ') tmp++;
                        if        (strcasecmp(tmp, "stereo") == 0) {
-                               PicoOpt |=  8;
+                               PicoOpt |=  POPT_EN_STEREO;
                        } else if (strcasecmp(tmp, "mono") == 0) {
-                               PicoOpt &= ~8;
+                               PicoOpt &= ~POPT_EN_STEREO;
                        } else
                                return 0;
                        return 1;
@@ -537,7 +620,11 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
                        return 1;
 
                case MA_OPT_CPU_CLOCKS:
+#ifdef __GP2X__
                        if (strcasecmp(var, "GP2X CPU clocks") != 0) return 0;
+#elif defined(PSP)
+                       if (strcasecmp(var, "PSP CPU clock") != 0) return 0;
+#endif
                        currentConfig.CPUclock = atoi(val);
                        return 1;
 
@@ -558,6 +645,44 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
                        PicoCDBuffers = atoi(val) / 2;
                        return 1;
 
+               /* PSP */
+               case MA_OPT3_SCALE:
+                       if (strcasecmp(var, "Scale factor") != 0) return 0;
+                       currentConfig.scale = atof(val);
+                       return 1;
+               case MA_OPT3_HSCALE32:
+                       if (strcasecmp(var, "Hor. scale (for low res. games)") != 0) return 0;
+                       currentConfig.hscale32 = atof(val);
+                       return 1;
+               case MA_OPT3_HSCALE40:
+                       if (strcasecmp(var, "Hor. scale (for hi res. games)") != 0) return 0;
+                       currentConfig.hscale40 = atof(val);
+                       return 1;
+               case MA_OPT3_FILTERING:
+                       if (strcasecmp(var, "Bilinear filtering") != 0) return 0;
+                       currentConfig.scaling = atoi(val);
+                       return 1;
+               case MA_OPT3_GAMMAA:
+                       if (strcasecmp(var, "Gamma adjustment") != 0) return 0;
+                       currentConfig.gamma = atoi(val);
+                       return 1;
+               case MA_OPT3_BLACKLVL:
+                       if (strcasecmp(var, "Black level") != 0) return 0;
+                       currentConfig.gamma2 = atoi(val);
+                       return 1;
+               case MA_OPT3_VSYNC:
+                       if (strcasecmp(var, "Wait for vsync") != 0) return 0;
+                       if        (strcasecmp(val, "never") == 0) {
+                               currentConfig.EmuOpt &= ~0x12000;
+                       } else if (strcasecmp(val, "sometimes") == 0) {
+                               currentConfig.EmuOpt |=  0x12000;
+                       } else if (strcasecmp(val, "always") == 0) {
+                               currentConfig.EmuOpt &= ~0x12000;
+                               currentConfig.EmuOpt |=  0x02000;
+                       } else
+                               return 0;
+                       return 1;
+
                default:
                        lprintf("unhandled custom_read: %i\n", me->id);
                        return 0;
@@ -567,7 +692,7 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
 
 static unsigned int keys_encountered = 0;
 
-static void keys_parse(const char *var, const char *val, int binds[32], const char *names[32])
+static void keys_parse(const char *var, const char *val, int binds[32], const char * const names[32])
 {
        int t, i;
        unsigned int player;
@@ -626,6 +751,11 @@ static void parse(const char *var, const char *val)
        if (strcasecmp(var, "LastUsedROM") == 0)
                return; /* handled elsewhere */
 
+       if (strcasecmp(var, "Sound Volume") == 0) {
+               currentConfig.volume = atoi(val);
+               return;
+       }
+
        // key binds
        if (strncasecmp(var, "bind ", 5) == 0) {
                keys_parse(var + 5, val, currentConfig.KeyBinds, keyNames);
@@ -686,7 +816,7 @@ int config_readsect(const char *fname, const char *section)
        FILE *f;
 
        f = fopen(fname, "r");
-       if (f == NULL) return 0;
+       if (f == NULL) return -1;
 
        if (section != NULL)
        {