--- SIDPlayer/src/prefs.cpp 2000/07/28 12:42:30 1.1.1.1 +++ SIDPlayer/src/prefs.cpp 2004/01/12 15:15:49 1.8 @@ -1,7 +1,7 @@ /* * prefs.cpp - Preferences handling * - * SIDPlayer (C) Copyright 1996-2000 Christian Bauer + * SIDPlayer (C) Copyright 1996-2004 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,34 +28,7 @@ #include "prefs.h" -// List of preferences items -prefs_desc prefs_items[] = { - {"victype", TYPE_STRING, false}, // Type number of VIC-II to emulate ("6569", "6567" or "6567R5") - {"sidtype", TYPE_STRING, false}, // Type number of SID to emulate ("6581" or "8580") - {"samplerate", TYPE_INT32, false}, // Audio sample rate in Hz - {"audio16bit", TYPE_BOOLEAN, false}, // 16-bit audio output? - {"stereo", TYPE_BOOLEAN, false}, // Stereo audio output? - {"filters", TYPE_BOOLEAN, false}, // Emulate SID filters? - {"dualsid", TYPE_BOOLEAN, false}, // Emulate 2 SID chips? - {"audioeffect", TYPE_INT32, false}, // Audio effect type (0 = none, 1 = reverb, 2 = spatial) - {"revdelay", TYPE_INT32, false}, // Reverb delay in ms - {"revfeedback", TYPE_INT32, false}, // Reverb feedback (0..0x100 = 0..100%) - {"volume", TYPE_INT32, false}, // Master volume (0..0x100 = 0..100%) - {"v1volume", TYPE_INT32, false}, // Volume voice 1 (0..0x100 = 0..100%) - {"v2volume", TYPE_INT32, false}, // Volume voice 2 (0..0x100 = 0..100%) - {"v3volume", TYPE_INT32, false}, // Volume voice 3 (0..0x100 = 0..100%) - {"v4volume", TYPE_INT32, false}, // Volume sampled voice (0..0x100 = 0..100%) - {"v1pan", TYPE_INT32, false}, // Panning voice 1 (-0x100..0x100 = left..right) - {"v2pan", TYPE_INT32, false}, // Panning voice 2 (-0x100..0x100 = left..right) - {"v3pan", TYPE_INT32, false}, // Panning voice 3 (-0x100..0x100 = left..right) - {"v4pan", TYPE_INT32, false}, // Panning sampled voice (-0x100..0x100 = left..right) - {"dualsep", TYPE_INT32, false}, // Dual-SID stereo separation (0..0x100 = 0..100%) - {"replayfreq", TYPE_INT32, false}, // Frequency at which 6510 replay routine is called in Hz - {NULL, TYPE_END, false} // End of list -}; - - -// Prefs item are stored in a linked list of these nodes +// Prefs items are stored in a linked list of these nodes struct prefs_node { prefs_node *next; const char *name; @@ -65,40 +38,86 @@ struct prefs_node { }; // List of prefs nodes -static prefs_node *the_prefs; +static prefs_node *the_prefs = NULL; + +// Prototypes +static prefs_desc *find_prefs_desc(const char *name); /* * Initialize preferences */ -void PrefsInit(int argc, char **argv) +void PrefsInit(int &argc, char **&argv) { - // Start with empty list - the_prefs = NULL; - // Set defaults - PrefsAddString("victype", "6569"); - PrefsAddString("sidtype", "6581"); - PrefsAddInt32("samplerate", 44100); - PrefsAddBool("audio16bit", true); - PrefsAddBool("stereo", true); - PrefsAddBool("filters", true); - PrefsAddBool("dualsid", false); - PrefsAddInt32("audioeffect", 2); - PrefsAddInt32("revdelay", 125); - PrefsAddInt32("revfeedback", 0x50); - PrefsAddInt32("volume", 0x100); - PrefsAddInt32("v1volume", 0x100); - PrefsAddInt32("v1pan", -0x40); - PrefsAddInt32("v2volume", 0x100); - PrefsAddInt32("v2pan", 0); - PrefsAddInt32("v3volume", 0x100); - PrefsAddInt32("v3pan", 0x40); - PrefsAddInt32("v4volume", 0x100); - PrefsAddInt32("v4pan", 0); - PrefsAddInt32("dualsep", 0x80); - PrefsAddInt32("replayfreq", 50); + AddPrefsDefaults(); + + // Override prefs with command line options + for (int i=1; i= argc) { + fprintf(stderr, "Option '%s' must be followed by a value\n", option); + continue; + } + const char *value = argv[i]; + argv[i] = NULL; + + // Add/replace prefs item + switch (d->type) { + case TYPE_STRING: + if (d->multiple) + PrefsAddString(keyword, value); + else + PrefsReplaceString(keyword, value); + break; + + case TYPE_BOOLEAN: { + if (!strcmp(value, "true") || !strcmp(value, "on") || !strcmp(value, "yes")) + PrefsReplaceBool(keyword, true); + else if (!strcmp(value, "false") || !strcmp(value, "off") || !strcmp(value, "no")) + PrefsReplaceBool(keyword, false); + else + fprintf(stderr, "Value for option '%s' must be 'true' or 'false'\n", option); + break; + } + + case TYPE_INT32: + PrefsReplaceInt32(keyword, atoi(value)); + break; + + default: + break; + } + } + + // Remove processed arguments + for (int i=1; i i) { + k -= i; + for (int j=i+k; jtype != TYPE_END) { + if (list->help) { + const char *typestr, *defstr; + char numstr[32]; + switch (list->type) { + case TYPE_STRING: + typestr = "STRING"; + defstr = PrefsFindString(list->name); + if (defstr == NULL) + defstr = "none"; + break; + case TYPE_BOOLEAN: + typestr = "BOOL"; + if (PrefsFindBool(list->name)) + defstr = "true"; + else + defstr = "false"; + break; + case TYPE_INT32: + typestr = "NUMBER"; + sprintf(numstr, "%d", PrefsFindInt32(list->name)); + defstr = numstr; + break; + default: + typestr = ""; + defstr = "none"; + break; + } + printf(" --%s %s\n %s [default=%s]\n", list->name, typestr, list->help, defstr); + } + list++; + } +} + +void PrefsPrintUsage() +{ + printf("\nGeneral options:\n"); + print_options(common_prefs_items); + printf("\nBoolean options are specified as '--OPTION true|on|yes' or\n'--OPTION false|off|no'.\n"); +} + + +/* * Find preferences descriptor by keyword */ static prefs_desc *find_prefs_desc(const char *name, prefs_desc *list) { - while (list->type != TYPE_ANY) { + while (list->type != TYPE_END) { if (strcmp(list->name, name) == 0) return list; list++; @@ -134,6 +201,11 @@ static prefs_desc *find_prefs_desc(const return NULL; } +static prefs_desc *find_prefs_desc(const char *name) +{ + return find_prefs_desc(name, common_prefs_items); +} + /* * Set prefs items @@ -150,7 +222,7 @@ static void add_data(const char *name, p p->name = strdup(name); p->type = type; p->data = d; - p->desc = find_prefs_desc(p->name, prefs_items); + p->desc = find_prefs_desc(p->name); if (the_prefs) { prefs_node *prev = the_prefs; while (prev->next) @@ -297,7 +369,7 @@ void PrefsRemoveItem(const char *name, i static void set_callback(const char *name, prefs_func f) { - prefs_desc *d = find_prefs_desc(name, prefs_items); + prefs_desc *d = find_prefs_desc(name); if (d == NULL) return; d->func = f;