1 |
/* |
2 |
* Prefs.cpp - Global preferences |
3 |
* |
4 |
* Frodo (C) 1994-1997,2002-2003 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 |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include "sysdeps.h" |
22 |
|
23 |
#include "Prefs.h" |
24 |
#include "Display.h" |
25 |
#include "C64.h" |
26 |
#include "main.h" |
27 |
|
28 |
|
29 |
// These are the active preferences |
30 |
Prefs ThePrefs; |
31 |
|
32 |
// These are the preferences on disk |
33 |
Prefs ThePrefsOnDisk; |
34 |
|
35 |
|
36 |
/* |
37 |
* Constructor: Set up preferences with defaults |
38 |
*/ |
39 |
|
40 |
Prefs::Prefs() |
41 |
{ |
42 |
NormalCycles = 63; |
43 |
BadLineCycles = 23; |
44 |
CIACycles = 63; |
45 |
FloppyCycles = 64; |
46 |
SkipFrames = 1; |
47 |
LatencyMin = 80; |
48 |
LatencyMax = 120; |
49 |
LatencyAvg = 280; |
50 |
ScalingNumerator = 2; |
51 |
ScalingDenominator = 2; |
52 |
|
53 |
for (int i=0; i<4; i++) |
54 |
DriveType[i] = DRVTYPE_DIR; |
55 |
|
56 |
strcpy(DrivePath[0], "64prgs"); |
57 |
strcpy(DrivePath[1], ""); |
58 |
strcpy(DrivePath[2], ""); |
59 |
strcpy(DrivePath[3], ""); |
60 |
|
61 |
strcpy(ViewPort, "Default"); |
62 |
strcpy(DisplayMode, "Default"); |
63 |
|
64 |
SIDType = SIDTYPE_DIGITAL; |
65 |
REUSize = REU_NONE; |
66 |
DisplayType = DISPTYPE_WINDOW; |
67 |
Joystick1Port = 0; |
68 |
Joystick2Port = 0; |
69 |
|
70 |
SpritesOn = true; |
71 |
SpriteCollisions = true; |
72 |
JoystickSwap = false; |
73 |
LimitSpeed = false; |
74 |
FastReset = false; |
75 |
CIAIRQHack = false; |
76 |
MapSlash = true; |
77 |
Emul1541Proc = false; |
78 |
SIDFilters = true; |
79 |
DoubleScan = true; |
80 |
HideCursor = false; |
81 |
DirectSound = true; |
82 |
ExclusiveSound = false; |
83 |
AutoPause = false; |
84 |
PrefsAtStartup = false; |
85 |
SystemMemory = false; |
86 |
AlwaysCopy = false; |
87 |
SystemKeys = true; |
88 |
ShowLEDs = true; |
89 |
} |
90 |
|
91 |
|
92 |
/* |
93 |
* Check if two Prefs structures are equal |
94 |
*/ |
95 |
|
96 |
bool Prefs::operator==(const Prefs &rhs) const |
97 |
{ |
98 |
return (1 |
99 |
&& NormalCycles == rhs.NormalCycles |
100 |
&& BadLineCycles == rhs.BadLineCycles |
101 |
&& CIACycles == rhs.CIACycles |
102 |
&& FloppyCycles == rhs.FloppyCycles |
103 |
&& SkipFrames == rhs.SkipFrames |
104 |
&& LatencyMin == rhs.LatencyMin |
105 |
&& LatencyMax == rhs.LatencyMax |
106 |
&& LatencyAvg == rhs.LatencyAvg |
107 |
&& ScalingNumerator == rhs.ScalingNumerator |
108 |
&& ScalingDenominator == rhs.ScalingNumerator |
109 |
&& DriveType[0] == rhs.DriveType[0] |
110 |
&& DriveType[1] == rhs.DriveType[1] |
111 |
&& DriveType[2] == rhs.DriveType[2] |
112 |
&& DriveType[3] == rhs.DriveType[3] |
113 |
&& strcmp(DrivePath[0], rhs.DrivePath[0]) == 0 |
114 |
&& strcmp(DrivePath[1], rhs.DrivePath[1]) == 0 |
115 |
&& strcmp(DrivePath[2], rhs.DrivePath[2]) == 0 |
116 |
&& strcmp(DrivePath[3], rhs.DrivePath[3]) == 0 |
117 |
&& strcmp(ViewPort, rhs.ViewPort) == 0 |
118 |
&& strcmp(DisplayMode, rhs.DisplayMode) == 0 |
119 |
&& SIDType == rhs.SIDType |
120 |
&& REUSize == rhs.REUSize |
121 |
&& DisplayType == rhs.DisplayType |
122 |
&& SpritesOn == rhs.SpritesOn |
123 |
&& SpriteCollisions == rhs.SpriteCollisions |
124 |
&& Joystick1Port == rhs.Joystick1Port |
125 |
&& Joystick2Port == rhs.Joystick2Port |
126 |
&& JoystickSwap == rhs.JoystickSwap |
127 |
&& LimitSpeed == rhs.LimitSpeed |
128 |
&& FastReset == rhs.FastReset |
129 |
&& CIAIRQHack == rhs.CIAIRQHack |
130 |
&& MapSlash == rhs.MapSlash |
131 |
&& Emul1541Proc == rhs.Emul1541Proc |
132 |
&& SIDFilters == rhs.SIDFilters |
133 |
&& DoubleScan == rhs.DoubleScan |
134 |
&& HideCursor == rhs.HideCursor |
135 |
&& DirectSound == rhs.DirectSound |
136 |
&& ExclusiveSound == rhs.ExclusiveSound |
137 |
&& AutoPause == rhs.AutoPause |
138 |
&& PrefsAtStartup == rhs.PrefsAtStartup |
139 |
&& SystemMemory == rhs.SystemMemory |
140 |
&& AlwaysCopy == rhs.AlwaysCopy |
141 |
&& SystemKeys == rhs.SystemKeys |
142 |
&& ShowLEDs == rhs.ShowLEDs |
143 |
); |
144 |
} |
145 |
|
146 |
bool Prefs::operator!=(const Prefs &rhs) const |
147 |
{ |
148 |
return !operator==(rhs); |
149 |
} |
150 |
|
151 |
|
152 |
/* |
153 |
* Check preferences for validity and correct if necessary |
154 |
*/ |
155 |
|
156 |
void Prefs::Check(void) |
157 |
{ |
158 |
if (SkipFrames <= 0) SkipFrames = 1; |
159 |
|
160 |
if (SIDType < SIDTYPE_NONE || SIDType > SIDTYPE_SIDCARD) |
161 |
SIDType = SIDTYPE_NONE; |
162 |
|
163 |
if (REUSize < REU_NONE || REUSize > REU_512K) |
164 |
REUSize = REU_NONE; |
165 |
|
166 |
if (DisplayType < DISPTYPE_WINDOW || DisplayType > DISPTYPE_SCREEN) |
167 |
DisplayType = DISPTYPE_WINDOW; |
168 |
|
169 |
for (int i=0; i<4; i++) |
170 |
if (DriveType[i] < DRVTYPE_DIR || DriveType[i] > DRVTYPE_T64) |
171 |
DriveType[i] = DRVTYPE_DIR; |
172 |
} |
173 |
|
174 |
|
175 |
/* |
176 |
* Load preferences from file |
177 |
*/ |
178 |
|
179 |
void Prefs::Load(char *filename) |
180 |
{ |
181 |
FILE *file; |
182 |
char line[256], keyword[256], value[256]; |
183 |
|
184 |
if ((file = fopen(filename, "r")) != NULL) { |
185 |
while(fgets(line, 255, file)) { |
186 |
if (sscanf(line, "%s = %s\n", keyword, value) == 2) { |
187 |
if (!strcmp(keyword, "NormalCycles")) |
188 |
NormalCycles = atoi(value); |
189 |
else if (!strcmp(keyword, "BadLineCycles")) |
190 |
BadLineCycles = atoi(value); |
191 |
else if (!strcmp(keyword, "CIACycles")) |
192 |
CIACycles = atoi(value); |
193 |
else if (!strcmp(keyword, "FloppyCycles")) |
194 |
FloppyCycles = atoi(value); |
195 |
else if (!strcmp(keyword, "SkipFrames")) |
196 |
SkipFrames = atoi(value); |
197 |
else if (!strcmp(keyword, "LatencyMin")) |
198 |
LatencyMin = atoi(value); |
199 |
else if (!strcmp(keyword, "LatencyMax")) |
200 |
LatencyMax = atoi(value); |
201 |
else if (!strcmp(keyword, "LatencyAvg")) |
202 |
LatencyAvg = atoi(value); |
203 |
else if (!strcmp(keyword, "ScalingNumerator")) |
204 |
ScalingNumerator = atoi(value); |
205 |
else if (!strcmp(keyword, "ScalingDenominator")) |
206 |
ScalingDenominator = atoi(value); |
207 |
else if (!strcmp(keyword, "DriveType8")) |
208 |
if (!strcmp(value, "DIR")) |
209 |
DriveType[0] = DRVTYPE_DIR; |
210 |
else if (!strcmp(value, "D64")) |
211 |
DriveType[0] = DRVTYPE_D64; |
212 |
else |
213 |
DriveType[0] = DRVTYPE_T64; |
214 |
else if (!strcmp(keyword, "DriveType9")) |
215 |
if (!strcmp(value, "DIR")) |
216 |
DriveType[1] = DRVTYPE_DIR; |
217 |
else if (!strcmp(value, "D64")) |
218 |
DriveType[1] = DRVTYPE_D64; |
219 |
else |
220 |
DriveType[1] = DRVTYPE_T64; |
221 |
else if (!strcmp(keyword, "DriveType10")) |
222 |
if (!strcmp(value, "DIR")) |
223 |
DriveType[2] = DRVTYPE_DIR; |
224 |
else if (!strcmp(value, "D64")) |
225 |
DriveType[2] = DRVTYPE_D64; |
226 |
else |
227 |
DriveType[2] = DRVTYPE_T64; |
228 |
else if (!strcmp(keyword, "DriveType11")) |
229 |
if (!strcmp(value, "DIR")) |
230 |
DriveType[3] = DRVTYPE_DIR; |
231 |
else if (!strcmp(value, "D64")) |
232 |
DriveType[3] = DRVTYPE_D64; |
233 |
else |
234 |
DriveType[3] = DRVTYPE_T64; |
235 |
else if (!strcmp(keyword, "DrivePath8")) |
236 |
strcpy(DrivePath[0], value); |
237 |
else if (!strcmp(keyword, "DrivePath9")) |
238 |
strcpy(DrivePath[1], value); |
239 |
else if (!strcmp(keyword, "DrivePath10")) |
240 |
strcpy(DrivePath[2], value); |
241 |
else if (!strcmp(keyword, "DrivePath11")) |
242 |
strcpy(DrivePath[3], value); |
243 |
else if (!strcmp(keyword, "ViewPort")) |
244 |
strcpy(ViewPort, value); |
245 |
else if (!strcmp(keyword, "DisplayMode")) |
246 |
strcpy(DisplayMode, value); |
247 |
else if (!strcmp(keyword, "SIDType")) |
248 |
if (!strcmp(value, "DIGITAL")) |
249 |
SIDType = SIDTYPE_DIGITAL; |
250 |
else if (!strcmp(value, "SIDCARD")) |
251 |
SIDType = SIDTYPE_SIDCARD; |
252 |
else |
253 |
SIDType = SIDTYPE_NONE; |
254 |
else if (!strcmp(keyword, "REUSize")) { |
255 |
if (!strcmp(value, "128K")) |
256 |
REUSize = REU_128K; |
257 |
else if (!strcmp(value, "256K")) |
258 |
REUSize = REU_256K; |
259 |
else if (!strcmp(value, "512K")) |
260 |
REUSize = REU_512K; |
261 |
else |
262 |
REUSize = REU_NONE; |
263 |
} else if (!strcmp(keyword, "DisplayType")) |
264 |
DisplayType = strcmp(value, "SCREEN") ? DISPTYPE_WINDOW : DISPTYPE_SCREEN; |
265 |
else if (!strcmp(keyword, "Joystick1Port")) |
266 |
Joystick1Port = atoi(value); |
267 |
else if (!strcmp(keyword, "Joystick2Port")) |
268 |
Joystick2Port = atoi(value); |
269 |
else if (!strcmp(keyword, "SpritesOn")) |
270 |
SpritesOn = !strcmp(value, "TRUE"); |
271 |
else if (!strcmp(keyword, "SpriteCollisions")) |
272 |
SpriteCollisions = !strcmp(value, "TRUE"); |
273 |
else if (!strcmp(keyword, "JoystickSwap")) |
274 |
JoystickSwap = !strcmp(value, "TRUE"); |
275 |
else if (!strcmp(keyword, "LimitSpeed")) |
276 |
LimitSpeed = !strcmp(value, "TRUE"); |
277 |
else if (!strcmp(keyword, "FastReset")) |
278 |
FastReset = !strcmp(value, "TRUE"); |
279 |
else if (!strcmp(keyword, "CIAIRQHack")) |
280 |
CIAIRQHack = !strcmp(value, "TRUE"); |
281 |
else if (!strcmp(keyword, "MapSlash")) |
282 |
MapSlash = !strcmp(value, "TRUE"); |
283 |
else if (!strcmp(keyword, "Emul1541Proc")) |
284 |
Emul1541Proc = !strcmp(value, "TRUE"); |
285 |
else if (!strcmp(keyword, "SIDFilters")) |
286 |
SIDFilters = !strcmp(value, "TRUE"); |
287 |
else if (!strcmp(keyword, "DoubleScan")) |
288 |
DoubleScan = !strcmp(value, "TRUE"); |
289 |
else if (!strcmp(keyword, "HideCursor")) |
290 |
HideCursor = !strcmp(value, "TRUE"); |
291 |
else if (!strcmp(keyword, "DirectSound")) |
292 |
DirectSound = !strcmp(value, "TRUE"); |
293 |
else if (!strcmp(keyword, "ExclusiveSound")) |
294 |
ExclusiveSound = !strcmp(value, "TRUE"); |
295 |
else if (!strcmp(keyword, "AutoPause")) |
296 |
AutoPause = !strcmp(value, "TRUE"); |
297 |
else if (!strcmp(keyword, "PrefsAtStartup")) |
298 |
PrefsAtStartup = !strcmp(value, "TRUE"); |
299 |
else if (!strcmp(keyword, "SystemMemory")) |
300 |
SystemMemory = !strcmp(value, "TRUE"); |
301 |
else if (!strcmp(keyword, "AlwaysCopy")) |
302 |
AlwaysCopy = !strcmp(value, "TRUE"); |
303 |
else if (!strcmp(keyword, "SystemKeys")) |
304 |
SystemKeys = !strcmp(value, "TRUE"); |
305 |
else if (!strcmp(keyword, "ShowLEDs")) |
306 |
ShowLEDs = !strcmp(value, "TRUE"); |
307 |
} |
308 |
} |
309 |
fclose(file); |
310 |
} |
311 |
Check(); |
312 |
ThePrefsOnDisk = *this; |
313 |
} |
314 |
|
315 |
|
316 |
/* |
317 |
* Save preferences to file |
318 |
* true: success, false: error |
319 |
*/ |
320 |
|
321 |
bool Prefs::Save(char *filename) |
322 |
{ |
323 |
FILE *file; |
324 |
|
325 |
Check(); |
326 |
if ((file = fopen(filename, "w")) != NULL) { |
327 |
fprintf(file, "NormalCycles = %d\n", NormalCycles); |
328 |
fprintf(file, "BadLineCycles = %d\n", BadLineCycles); |
329 |
fprintf(file, "CIACycles = %d\n", CIACycles); |
330 |
fprintf(file, "FloppyCycles = %d\n", FloppyCycles); |
331 |
fprintf(file, "SkipFrames = %d\n", SkipFrames); |
332 |
fprintf(file, "LatencyMin = %d\n", LatencyMin); |
333 |
fprintf(file, "LatencyMax = %d\n", LatencyMax); |
334 |
fprintf(file, "LatencyAvg = %d\n", LatencyAvg); |
335 |
fprintf(file, "ScalingNumerator = %d\n", ScalingNumerator); |
336 |
fprintf(file, "ScalingDenominator = %d\n", ScalingDenominator); |
337 |
for (int i=0; i<4; i++) { |
338 |
fprintf(file, "DriveType%d = ", i+8); |
339 |
switch (DriveType[i]) { |
340 |
case DRVTYPE_DIR: |
341 |
fprintf(file, "DIR\n"); |
342 |
break; |
343 |
case DRVTYPE_D64: |
344 |
fprintf(file, "D64\n"); |
345 |
break; |
346 |
case DRVTYPE_T64: |
347 |
fprintf(file, "T64\n"); |
348 |
break; |
349 |
} |
350 |
fprintf(file, "DrivePath%d = %s\n", i+8, DrivePath[i]); |
351 |
} |
352 |
fprintf(file, "ViewPort = %s\n", ViewPort); |
353 |
fprintf(file, "DisplayMode = %s\n", DisplayMode); |
354 |
fprintf(file, "SIDType = "); |
355 |
switch (SIDType) { |
356 |
case SIDTYPE_NONE: |
357 |
fprintf(file, "NONE\n"); |
358 |
break; |
359 |
case SIDTYPE_DIGITAL: |
360 |
fprintf(file, "DIGITAL\n"); |
361 |
break; |
362 |
case SIDTYPE_SIDCARD: |
363 |
fprintf(file, "SIDCARD\n"); |
364 |
break; |
365 |
} |
366 |
fprintf(file, "REUSize = "); |
367 |
switch (REUSize) { |
368 |
case REU_NONE: |
369 |
fprintf(file, "NONE\n"); |
370 |
break; |
371 |
case REU_128K: |
372 |
fprintf(file, "128K\n"); |
373 |
break; |
374 |
case REU_256K: |
375 |
fprintf(file, "256K\n"); |
376 |
break; |
377 |
case REU_512K: |
378 |
fprintf(file, "512K\n"); |
379 |
break; |
380 |
}; |
381 |
fprintf(file, "DisplayType = %s\n", DisplayType == DISPTYPE_WINDOW ? "WINDOW" : "SCREEN"); |
382 |
fprintf(file, "Joystick1Port = %d\n", Joystick1Port); |
383 |
fprintf(file, "Joystick2Port = %d\n", Joystick2Port); |
384 |
fprintf(file, "SpritesOn = %s\n", SpritesOn ? "TRUE" : "FALSE"); |
385 |
fprintf(file, "SpriteCollisions = %s\n", SpriteCollisions ? "TRUE" : "FALSE"); |
386 |
fprintf(file, "JoystickSwap = %s\n", JoystickSwap ? "TRUE" : "FALSE"); |
387 |
fprintf(file, "LimitSpeed = %s\n", LimitSpeed ? "TRUE" : "FALSE"); |
388 |
fprintf(file, "FastReset = %s\n", FastReset ? "TRUE" : "FALSE"); |
389 |
fprintf(file, "CIAIRQHack = %s\n", CIAIRQHack ? "TRUE" : "FALSE"); |
390 |
fprintf(file, "MapSlash = %s\n", MapSlash ? "TRUE" : "FALSE"); |
391 |
fprintf(file, "Emul1541Proc = %s\n", Emul1541Proc ? "TRUE" : "FALSE"); |
392 |
fprintf(file, "SIDFilters = %s\n", SIDFilters ? "TRUE" : "FALSE"); |
393 |
fprintf(file, "DoubleScan = %s\n", DoubleScan ? "TRUE" : "FALSE"); |
394 |
fprintf(file, "HideCursor = %s\n", HideCursor ? "TRUE" : "FALSE"); |
395 |
fprintf(file, "DirectSound = %s\n", DirectSound ? "TRUE" : "FALSE"); |
396 |
fprintf(file, "ExclusiveSound = %s\n", ExclusiveSound ? "TRUE" : "FALSE"); |
397 |
fprintf(file, "AutoPause = %s\n", AutoPause ? "TRUE" : "FALSE"); |
398 |
fprintf(file, "PrefsAtStartup = %s\n", PrefsAtStartup ? "TRUE" : "FALSE"); |
399 |
fprintf(file, "SystemMemory = %s\n", SystemMemory ? "TRUE" : "FALSE"); |
400 |
fprintf(file, "AlwaysCopy = %s\n", AlwaysCopy ? "TRUE" : "FALSE"); |
401 |
fprintf(file, "SystemKeys = %s\n", SystemKeys ? "TRUE" : "FALSE"); |
402 |
fprintf(file, "ShowLEDs = %s\n", ShowLEDs ? "TRUE" : "FALSE"); |
403 |
fclose(file); |
404 |
ThePrefsOnDisk = *this; |
405 |
return true; |
406 |
} |
407 |
return false; |
408 |
} |
409 |
|
410 |
|
411 |
#ifdef __BEOS__ |
412 |
#include "Prefs_Be.h" |
413 |
#endif |
414 |
|
415 |
#ifdef AMIGA |
416 |
#include "Prefs_Amiga.h" |
417 |
#endif |
418 |
|
419 |
#ifdef WIN32 |
420 |
#include "Prefs_WIN32.h" |
421 |
#endif |