work on 'vblank on line start' problem, var changes, mask defines
[libpicofe.git] / common / config.c
index c117fb9..f4d2546 100644 (file)
@@ -21,7 +21,7 @@ extern const int cdopt_entry_count;
 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 };
 
-#define NL "\n"
+#define NL "\r\n"
 
 
 static char *mystrip(char *str)
@@ -70,9 +70,9 @@ 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)
+                       if (PicoOpt&POPT_ALT_RENDERER)
                                str = "8bit fast";
                        else if (currentConfig.EmuOpt&0x80)
                                str = "16bit accurate";
@@ -99,9 +99,9 @@ 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:
@@ -322,6 +322,9 @@ 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);
 
+       if (section == NULL)
+               fprintf(fn, "Sound Volume = %i" NL, currentConfig.volume);
+
        fprintf(fn, NL);
 
        if (fo != NULL)
@@ -350,7 +353,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)
@@ -435,14 +438,14 @@ 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;
+                               PicoOpt |=  POPT_ALT_RENDERER;
                        }
                        else if (strcasecmp(val, "16bit accurate") == 0) {
-                               PicoOpt &= ~0x10;
+                               PicoOpt &= ~POPT_ALT_RENDERER;
                                currentConfig.EmuOpt |=  0x80;
                        }
                        else if (strcasecmp(val, "8bit accurate") == 0) {
-                               PicoOpt &= ~0x10;
+                               PicoOpt &= ~POPT_ALT_RENDERER;
                                currentConfig.EmuOpt &= ~0x80;
                        }
                        else
@@ -477,9 +480,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;
@@ -626,6 +629,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 +694,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)
        {