1 |
|
/* |
2 |
|
* prefs.cpp - Preferences handling |
3 |
|
* |
4 |
< |
* SIDPlayer (C) Copyright 1996-2000 Christian Bauer |
4 |
> |
* SIDPlayer (C) Copyright 1996-2001 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
28 |
|
#include "prefs.h" |
29 |
|
|
30 |
|
|
31 |
< |
// List of preferences items |
32 |
< |
prefs_desc prefs_items[] = { |
33 |
< |
{"victype", TYPE_STRING, false}, // Type number of VIC-II to emulate ("6569", "6567" or "6567R5") |
34 |
< |
{"sidtype", TYPE_STRING, false}, // Type number of SID to emulate ("6581" or "8580") |
35 |
< |
{"samplerate", TYPE_INT32, false}, // Audio sample rate in Hz |
36 |
< |
{"audio16bit", TYPE_BOOLEAN, false}, // 16-bit audio output? |
37 |
< |
{"stereo", TYPE_BOOLEAN, false}, // Stereo audio output? |
38 |
< |
{"filters", TYPE_BOOLEAN, false}, // Emulate SID filters? |
39 |
< |
{"dualsid", TYPE_BOOLEAN, false}, // Emulate 2 SID chips? |
40 |
< |
{"audioeffect", TYPE_INT32, false}, // Audio effect type (0 = none, 1 = reverb, 2 = spatial) |
41 |
< |
{"revdelay", TYPE_INT32, false}, // Reverb delay in ms |
42 |
< |
{"revfeedback", TYPE_INT32, false}, // Reverb feedback (0..0x100 = 0..100%) |
43 |
< |
{"volume", TYPE_INT32, false}, // Master volume (0..0x100 = 0..100%) |
44 |
< |
{"v1volume", TYPE_INT32, false}, // Volume voice 1 (0..0x100 = 0..100%) |
45 |
< |
{"v2volume", TYPE_INT32, false}, // Volume voice 2 (0..0x100 = 0..100%) |
46 |
< |
{"v3volume", TYPE_INT32, false}, // Volume voice 3 (0..0x100 = 0..100%) |
47 |
< |
{"v4volume", TYPE_INT32, false}, // Volume sampled voice (0..0x100 = 0..100%) |
48 |
< |
{"v1pan", TYPE_INT32, false}, // Panning voice 1 (-0x100..0x100 = left..right) |
49 |
< |
{"v2pan", TYPE_INT32, false}, // Panning voice 2 (-0x100..0x100 = left..right) |
50 |
< |
{"v3pan", TYPE_INT32, false}, // Panning voice 3 (-0x100..0x100 = left..right) |
51 |
< |
{"v4pan", TYPE_INT32, false}, // Panning sampled voice (-0x100..0x100 = left..right) |
52 |
< |
{"dualsep", TYPE_INT32, false}, // Dual-SID stereo separation (0..0x100 = 0..100%) |
53 |
< |
{"replayfreq", TYPE_INT32, false}, // Frequency at which 6510 replay routine is called in Hz |
54 |
< |
{NULL, TYPE_END, false} // End of list |
55 |
< |
}; |
56 |
< |
|
57 |
< |
|
58 |
< |
// Prefs item are stored in a linked list of these nodes |
31 |
> |
// Prefs items are stored in a linked list of these nodes |
32 |
|
struct prefs_node { |
33 |
|
prefs_node *next; |
34 |
|
const char *name; |
38 |
|
}; |
39 |
|
|
40 |
|
// List of prefs nodes |
41 |
< |
static prefs_node *the_prefs; |
41 |
> |
static prefs_node *the_prefs = NULL; |
42 |
> |
|
43 |
> |
// Prototypes |
44 |
> |
static prefs_desc *find_prefs_desc(const char *name); |
45 |
|
|
46 |
|
|
47 |
|
/* |
48 |
|
* Initialize preferences |
49 |
|
*/ |
50 |
|
|
51 |
< |
void PrefsInit(int argc, char **argv) |
51 |
> |
void PrefsInit(int &argc, char **&argv) |
52 |
|
{ |
77 |
– |
// Start with empty list |
78 |
– |
the_prefs = NULL; |
79 |
– |
|
53 |
|
// Set defaults |
54 |
< |
PrefsAddString("victype", "6569"); |
55 |
< |
PrefsAddString("sidtype", "6581"); |
56 |
< |
PrefsAddInt32("samplerate", 44100); |
57 |
< |
PrefsAddBool("audio16bit", true); |
58 |
< |
PrefsAddBool("stereo", true); |
59 |
< |
PrefsAddBool("filters", true); |
60 |
< |
PrefsAddBool("dualsid", false); |
61 |
< |
PrefsAddInt32("audioeffect", 2); |
62 |
< |
PrefsAddInt32("revdelay", 125); |
63 |
< |
PrefsAddInt32("revfeedback", 0x50); |
64 |
< |
PrefsAddInt32("volume", 0x100); |
65 |
< |
PrefsAddInt32("v1volume", 0x100); |
66 |
< |
PrefsAddInt32("v1pan", -0x40); |
67 |
< |
PrefsAddInt32("v2volume", 0x100); |
68 |
< |
PrefsAddInt32("v2pan", 0); |
69 |
< |
PrefsAddInt32("v3volume", 0x100); |
70 |
< |
PrefsAddInt32("v3pan", 0x40); |
71 |
< |
PrefsAddInt32("v4volume", 0x100); |
72 |
< |
PrefsAddInt32("v4pan", 0); |
73 |
< |
PrefsAddInt32("dualsep", 0x80); |
74 |
< |
PrefsAddInt32("replayfreq", 50); |
54 |
> |
AddPrefsDefaults(); |
55 |
> |
|
56 |
> |
// Override prefs with command line options |
57 |
> |
for (int i=1; i<argc; i++) { |
58 |
> |
|
59 |
> |
// Options are of the form '--keyword' |
60 |
> |
const char *option = argv[i]; |
61 |
> |
if (strlen(option) < 3 || option[0] != '-' || option[1] != '-') |
62 |
> |
continue; |
63 |
> |
const char *keyword = option + 2; |
64 |
> |
|
65 |
> |
// Find descriptor for keyword |
66 |
> |
const prefs_desc *d = find_prefs_desc(keyword); |
67 |
> |
if (d == NULL) |
68 |
> |
continue; |
69 |
> |
argv[i] = NULL; |
70 |
> |
|
71 |
> |
// Get value |
72 |
> |
i++; |
73 |
> |
if (i >= argc) { |
74 |
> |
fprintf(stderr, "Option '%s' must be followed by a value\n", option); |
75 |
> |
continue; |
76 |
> |
} |
77 |
> |
const char *value = argv[i]; |
78 |
> |
argv[i] = NULL; |
79 |
> |
|
80 |
> |
// Add/replace prefs item |
81 |
> |
switch (d->type) { |
82 |
> |
case TYPE_STRING: |
83 |
> |
if (d->multiple) |
84 |
> |
PrefsAddString(keyword, value); |
85 |
> |
else |
86 |
> |
PrefsReplaceString(keyword, value); |
87 |
> |
break; |
88 |
> |
|
89 |
> |
case TYPE_BOOLEAN: { |
90 |
> |
if (!strcmp(value, "true") || !strcmp(value, "on") || !strcmp(value, "yes")) |
91 |
> |
PrefsReplaceBool(keyword, true); |
92 |
> |
else if (!strcmp(value, "false") || !strcmp(value, "off") || !strcmp(value, "no")) |
93 |
> |
PrefsReplaceBool(keyword, false); |
94 |
> |
else |
95 |
> |
fprintf(stderr, "Value for option '%s' must be 'true' or 'false'\n", option); |
96 |
> |
break; |
97 |
> |
} |
98 |
> |
|
99 |
> |
case TYPE_INT32: |
100 |
> |
PrefsReplaceInt32(keyword, atoi(value)); |
101 |
> |
break; |
102 |
> |
|
103 |
> |
default: |
104 |
> |
break; |
105 |
> |
} |
106 |
> |
} |
107 |
> |
|
108 |
> |
// Remove processed arguments |
109 |
> |
for (int i=1; i<argc; i++) { |
110 |
> |
int k; |
111 |
> |
for (k=i; k<argc; k++) |
112 |
> |
if (argv[k] != NULL) |
113 |
> |
break; |
114 |
> |
if (k > i) { |
115 |
> |
k -= i; |
116 |
> |
for (int j=i+k; j<argc; j++) |
117 |
> |
argv[j-k] = argv[j]; |
118 |
> |
argc -= k; |
119 |
> |
} |
120 |
> |
} |
121 |
|
} |
122 |
|
|
123 |
|
|
140 |
|
|
141 |
|
|
142 |
|
/* |
143 |
+ |
* Print preferences options help |
144 |
+ |
*/ |
145 |
+ |
|
146 |
+ |
static void print_options(const prefs_desc *list) |
147 |
+ |
{ |
148 |
+ |
while (list->type != TYPE_END) { |
149 |
+ |
if (list->help) { |
150 |
+ |
const char *typestr, *defstr; |
151 |
+ |
char numstr[32]; |
152 |
+ |
switch (list->type) { |
153 |
+ |
case TYPE_STRING: |
154 |
+ |
typestr = "STRING"; |
155 |
+ |
defstr = PrefsFindString(list->name); |
156 |
+ |
if (defstr == NULL) |
157 |
+ |
defstr = "none"; |
158 |
+ |
break; |
159 |
+ |
case TYPE_BOOLEAN: |
160 |
+ |
typestr = "BOOL"; |
161 |
+ |
if (PrefsFindBool(list->name)) |
162 |
+ |
defstr = "true"; |
163 |
+ |
else |
164 |
+ |
defstr = "false"; |
165 |
+ |
break; |
166 |
+ |
case TYPE_INT32: |
167 |
+ |
typestr = "NUMBER"; |
168 |
+ |
sprintf(numstr, "%d", PrefsFindInt32(list->name)); |
169 |
+ |
defstr = numstr; |
170 |
+ |
break; |
171 |
+ |
default: |
172 |
+ |
typestr = "<unknown>"; |
173 |
+ |
defstr = "none"; |
174 |
+ |
break; |
175 |
+ |
} |
176 |
+ |
printf(" --%s %s\n %s [default=%s]\n", list->name, typestr, list->help, defstr); |
177 |
+ |
} |
178 |
+ |
list++; |
179 |
+ |
} |
180 |
+ |
} |
181 |
+ |
|
182 |
+ |
void PrefsPrintUsage(void) |
183 |
+ |
{ |
184 |
+ |
printf("\nGeneral options:\n"); |
185 |
+ |
print_options(common_prefs_items); |
186 |
+ |
printf("\nBoolean options are specified as '--OPTION true|on|yes' or\n'--OPTION false|off|no'.\n"); |
187 |
+ |
} |
188 |
+ |
|
189 |
+ |
|
190 |
+ |
/* |
191 |
|
* Find preferences descriptor by keyword |
192 |
|
*/ |
193 |
|
|
194 |
|
static prefs_desc *find_prefs_desc(const char *name, prefs_desc *list) |
195 |
|
{ |
196 |
< |
while (list->type != TYPE_ANY) { |
196 |
> |
while (list->type != TYPE_END) { |
197 |
|
if (strcmp(list->name, name) == 0) |
198 |
|
return list; |
199 |
|
list++; |
201 |
|
return NULL; |
202 |
|
} |
203 |
|
|
204 |
+ |
static prefs_desc *find_prefs_desc(const char *name) |
205 |
+ |
{ |
206 |
+ |
return find_prefs_desc(name, common_prefs_items); |
207 |
+ |
} |
208 |
+ |
|
209 |
|
|
210 |
|
/* |
211 |
|
* Set prefs items |
222 |
|
p->name = strdup(name); |
223 |
|
p->type = type; |
224 |
|
p->data = d; |
225 |
< |
p->desc = find_prefs_desc(p->name, prefs_items); |
225 |
> |
p->desc = find_prefs_desc(p->name); |
226 |
|
if (the_prefs) { |
227 |
|
prefs_node *prev = the_prefs; |
228 |
|
while (prev->next) |
369 |
|
|
370 |
|
static void set_callback(const char *name, prefs_func f) |
371 |
|
{ |
372 |
< |
prefs_desc *d = find_prefs_desc(name, prefs_items); |
372 |
> |
prefs_desc *d = find_prefs_desc(name); |
373 |
|
if (d == NULL) |
374 |
|
return; |
375 |
|
d->func = f; |