ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Prefs.cpp
Revision: 1.10
Committed: 2010-04-25T09:18:57Z (12 years, 7 months ago) by cebix
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +1 -1 lines
Log Message:
limit speed by default

File Contents

# Content
1 /*
2 * Prefs.cpp - Global preferences
3 *
4 * Frodo Copyright (C) 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 strcpy(DrivePath[0], "64prgs");
54 strcpy(DrivePath[1], "");
55 strcpy(DrivePath[2], "");
56 strcpy(DrivePath[3], "");
57
58 strcpy(ViewPort, "Default");
59 strcpy(DisplayMode, "Default");
60
61 SIDType = SIDTYPE_DIGITAL;
62 REUSize = REU_NONE;
63 DisplayType = DISPTYPE_WINDOW;
64 Joystick1Port = 0;
65 Joystick2Port = 0;
66
67 SpritesOn = true;
68 SpriteCollisions = true;
69 JoystickSwap = false;
70 LimitSpeed = true;
71 FastReset = false;
72 CIAIRQHack = false;
73 MapSlash = true;
74 Emul1541Proc = false;
75 SIDFilters = true;
76 DoubleScan = true;
77 HideCursor = false;
78 DirectSound = true;
79 ExclusiveSound = false;
80 AutoPause = false;
81 PrefsAtStartup = false;
82 SystemMemory = false;
83 AlwaysCopy = false;
84 SystemKeys = true;
85 ShowLEDs = true;
86 }
87
88
89 /*
90 * Check if two Prefs structures are equal
91 */
92
93 bool Prefs::operator==(const Prefs &rhs) const
94 {
95 return (1
96 && NormalCycles == rhs.NormalCycles
97 && BadLineCycles == rhs.BadLineCycles
98 && CIACycles == rhs.CIACycles
99 && FloppyCycles == rhs.FloppyCycles
100 && SkipFrames == rhs.SkipFrames
101 && LatencyMin == rhs.LatencyMin
102 && LatencyMax == rhs.LatencyMax
103 && LatencyAvg == rhs.LatencyAvg
104 && ScalingNumerator == rhs.ScalingNumerator
105 && ScalingDenominator == rhs.ScalingNumerator
106 && strcmp(DrivePath[0], rhs.DrivePath[0]) == 0
107 && strcmp(DrivePath[1], rhs.DrivePath[1]) == 0
108 && strcmp(DrivePath[2], rhs.DrivePath[2]) == 0
109 && strcmp(DrivePath[3], rhs.DrivePath[3]) == 0
110 && strcmp(ViewPort, rhs.ViewPort) == 0
111 && strcmp(DisplayMode, rhs.DisplayMode) == 0
112 && SIDType == rhs.SIDType
113 && REUSize == rhs.REUSize
114 && DisplayType == rhs.DisplayType
115 && SpritesOn == rhs.SpritesOn
116 && SpriteCollisions == rhs.SpriteCollisions
117 && Joystick1Port == rhs.Joystick1Port
118 && Joystick2Port == rhs.Joystick2Port
119 && JoystickSwap == rhs.JoystickSwap
120 && LimitSpeed == rhs.LimitSpeed
121 && FastReset == rhs.FastReset
122 && CIAIRQHack == rhs.CIAIRQHack
123 && MapSlash == rhs.MapSlash
124 && Emul1541Proc == rhs.Emul1541Proc
125 && SIDFilters == rhs.SIDFilters
126 && DoubleScan == rhs.DoubleScan
127 && HideCursor == rhs.HideCursor
128 && DirectSound == rhs.DirectSound
129 && ExclusiveSound == rhs.ExclusiveSound
130 && AutoPause == rhs.AutoPause
131 && PrefsAtStartup == rhs.PrefsAtStartup
132 && SystemMemory == rhs.SystemMemory
133 && AlwaysCopy == rhs.AlwaysCopy
134 && SystemKeys == rhs.SystemKeys
135 && ShowLEDs == rhs.ShowLEDs
136 );
137 }
138
139 bool Prefs::operator!=(const Prefs &rhs) const
140 {
141 return !operator==(rhs);
142 }
143
144
145 /*
146 * Check preferences for validity and correct if necessary
147 */
148
149 void Prefs::Check(void)
150 {
151 if (SkipFrames <= 0) SkipFrames = 1;
152
153 if (SIDType < SIDTYPE_NONE || SIDType > SIDTYPE_SIDCARD)
154 SIDType = SIDTYPE_NONE;
155
156 if (REUSize < REU_NONE || REUSize > REU_512K)
157 REUSize = REU_NONE;
158
159 if (DisplayType < DISPTYPE_WINDOW || DisplayType > DISPTYPE_SCREEN)
160 DisplayType = DISPTYPE_WINDOW;
161 }
162
163
164 /*
165 * Load preferences from file
166 */
167
168 void Prefs::Load(const char *filename)
169 {
170 FILE *file;
171 char line[256], keyword[256], value[256];
172
173 if ((file = fopen(filename, "r")) != NULL) {
174 while(fgets(line, 255, file)) {
175 if (sscanf(line, "%s = %s\n", keyword, value) == 2) {
176 if (!strcmp(keyword, "NormalCycles"))
177 NormalCycles = atoi(value);
178 else if (!strcmp(keyword, "BadLineCycles"))
179 BadLineCycles = atoi(value);
180 else if (!strcmp(keyword, "CIACycles"))
181 CIACycles = atoi(value);
182 else if (!strcmp(keyword, "FloppyCycles"))
183 FloppyCycles = atoi(value);
184 else if (!strcmp(keyword, "SkipFrames"))
185 SkipFrames = atoi(value);
186 else if (!strcmp(keyword, "LatencyMin"))
187 LatencyMin = atoi(value);
188 else if (!strcmp(keyword, "LatencyMax"))
189 LatencyMax = atoi(value);
190 else if (!strcmp(keyword, "LatencyAvg"))
191 LatencyAvg = atoi(value);
192 else if (!strcmp(keyword, "ScalingNumerator"))
193 ScalingNumerator = atoi(value);
194 else if (!strcmp(keyword, "ScalingDenominator"))
195 ScalingDenominator = atoi(value);
196 else if (!strcmp(keyword, "DrivePath8"))
197 strcpy(DrivePath[0], value);
198 else if (!strcmp(keyword, "DrivePath9"))
199 strcpy(DrivePath[1], value);
200 else if (!strcmp(keyword, "DrivePath10"))
201 strcpy(DrivePath[2], value);
202 else if (!strcmp(keyword, "DrivePath11"))
203 strcpy(DrivePath[3], value);
204 else if (!strcmp(keyword, "ViewPort"))
205 strcpy(ViewPort, value);
206 else if (!strcmp(keyword, "DisplayMode"))
207 strcpy(DisplayMode, value);
208 else if (!strcmp(keyword, "SIDType"))
209 if (!strcmp(value, "DIGITAL"))
210 SIDType = SIDTYPE_DIGITAL;
211 else if (!strcmp(value, "SIDCARD"))
212 SIDType = SIDTYPE_SIDCARD;
213 else
214 SIDType = SIDTYPE_NONE;
215 else if (!strcmp(keyword, "REUSize")) {
216 if (!strcmp(value, "128K"))
217 REUSize = REU_128K;
218 else if (!strcmp(value, "256K"))
219 REUSize = REU_256K;
220 else if (!strcmp(value, "512K"))
221 REUSize = REU_512K;
222 else
223 REUSize = REU_NONE;
224 } else if (!strcmp(keyword, "DisplayType"))
225 DisplayType = strcmp(value, "SCREEN") ? DISPTYPE_WINDOW : DISPTYPE_SCREEN;
226 else if (!strcmp(keyword, "Joystick1Port"))
227 Joystick1Port = atoi(value);
228 else if (!strcmp(keyword, "Joystick2Port"))
229 Joystick2Port = atoi(value);
230 else if (!strcmp(keyword, "SpritesOn"))
231 SpritesOn = !strcmp(value, "TRUE");
232 else if (!strcmp(keyword, "SpriteCollisions"))
233 SpriteCollisions = !strcmp(value, "TRUE");
234 else if (!strcmp(keyword, "JoystickSwap"))
235 JoystickSwap = !strcmp(value, "TRUE");
236 else if (!strcmp(keyword, "LimitSpeed"))
237 LimitSpeed = !strcmp(value, "TRUE");
238 else if (!strcmp(keyword, "FastReset"))
239 FastReset = !strcmp(value, "TRUE");
240 else if (!strcmp(keyword, "CIAIRQHack"))
241 CIAIRQHack = !strcmp(value, "TRUE");
242 else if (!strcmp(keyword, "MapSlash"))
243 MapSlash = !strcmp(value, "TRUE");
244 else if (!strcmp(keyword, "Emul1541Proc"))
245 Emul1541Proc = !strcmp(value, "TRUE");
246 else if (!strcmp(keyword, "SIDFilters"))
247 SIDFilters = !strcmp(value, "TRUE");
248 else if (!strcmp(keyword, "DoubleScan"))
249 DoubleScan = !strcmp(value, "TRUE");
250 else if (!strcmp(keyword, "HideCursor"))
251 HideCursor = !strcmp(value, "TRUE");
252 else if (!strcmp(keyword, "DirectSound"))
253 DirectSound = !strcmp(value, "TRUE");
254 else if (!strcmp(keyword, "ExclusiveSound"))
255 ExclusiveSound = !strcmp(value, "TRUE");
256 else if (!strcmp(keyword, "AutoPause"))
257 AutoPause = !strcmp(value, "TRUE");
258 else if (!strcmp(keyword, "PrefsAtStartup"))
259 PrefsAtStartup = !strcmp(value, "TRUE");
260 else if (!strcmp(keyword, "SystemMemory"))
261 SystemMemory = !strcmp(value, "TRUE");
262 else if (!strcmp(keyword, "AlwaysCopy"))
263 AlwaysCopy = !strcmp(value, "TRUE");
264 else if (!strcmp(keyword, "SystemKeys"))
265 SystemKeys = !strcmp(value, "TRUE");
266 else if (!strcmp(keyword, "ShowLEDs"))
267 ShowLEDs = !strcmp(value, "TRUE");
268 }
269 }
270 fclose(file);
271 }
272 Check();
273 ThePrefsOnDisk = *this;
274 }
275
276
277 /*
278 * Save preferences to file
279 * true: success, false: error
280 */
281
282 bool Prefs::Save(const char *filename)
283 {
284 FILE *file;
285
286 Check();
287 if ((file = fopen(filename, "w")) != NULL) {
288 fprintf(file, "NormalCycles = %d\n", NormalCycles);
289 fprintf(file, "BadLineCycles = %d\n", BadLineCycles);
290 fprintf(file, "CIACycles = %d\n", CIACycles);
291 fprintf(file, "FloppyCycles = %d\n", FloppyCycles);
292 fprintf(file, "SkipFrames = %d\n", SkipFrames);
293 fprintf(file, "LatencyMin = %d\n", LatencyMin);
294 fprintf(file, "LatencyMax = %d\n", LatencyMax);
295 fprintf(file, "LatencyAvg = %d\n", LatencyAvg);
296 fprintf(file, "ScalingNumerator = %d\n", ScalingNumerator);
297 fprintf(file, "ScalingDenominator = %d\n", ScalingDenominator);
298 for (int i=0; i<4; i++)
299 fprintf(file, "DrivePath%d = %s\n", i+8, DrivePath[i]);
300 fprintf(file, "ViewPort = %s\n", ViewPort);
301 fprintf(file, "DisplayMode = %s\n", DisplayMode);
302 fprintf(file, "SIDType = ");
303 switch (SIDType) {
304 case SIDTYPE_NONE:
305 fprintf(file, "NONE\n");
306 break;
307 case SIDTYPE_DIGITAL:
308 fprintf(file, "DIGITAL\n");
309 break;
310 case SIDTYPE_SIDCARD:
311 fprintf(file, "SIDCARD\n");
312 break;
313 }
314 fprintf(file, "REUSize = ");
315 switch (REUSize) {
316 case REU_NONE:
317 fprintf(file, "NONE\n");
318 break;
319 case REU_128K:
320 fprintf(file, "128K\n");
321 break;
322 case REU_256K:
323 fprintf(file, "256K\n");
324 break;
325 case REU_512K:
326 fprintf(file, "512K\n");
327 break;
328 };
329 fprintf(file, "DisplayType = %s\n", DisplayType == DISPTYPE_WINDOW ? "WINDOW" : "SCREEN");
330 fprintf(file, "Joystick1Port = %d\n", Joystick1Port);
331 fprintf(file, "Joystick2Port = %d\n", Joystick2Port);
332 fprintf(file, "SpritesOn = %s\n", SpritesOn ? "TRUE" : "FALSE");
333 fprintf(file, "SpriteCollisions = %s\n", SpriteCollisions ? "TRUE" : "FALSE");
334 fprintf(file, "JoystickSwap = %s\n", JoystickSwap ? "TRUE" : "FALSE");
335 fprintf(file, "LimitSpeed = %s\n", LimitSpeed ? "TRUE" : "FALSE");
336 fprintf(file, "FastReset = %s\n", FastReset ? "TRUE" : "FALSE");
337 fprintf(file, "CIAIRQHack = %s\n", CIAIRQHack ? "TRUE" : "FALSE");
338 fprintf(file, "MapSlash = %s\n", MapSlash ? "TRUE" : "FALSE");
339 fprintf(file, "Emul1541Proc = %s\n", Emul1541Proc ? "TRUE" : "FALSE");
340 fprintf(file, "SIDFilters = %s\n", SIDFilters ? "TRUE" : "FALSE");
341 fprintf(file, "DoubleScan = %s\n", DoubleScan ? "TRUE" : "FALSE");
342 fprintf(file, "HideCursor = %s\n", HideCursor ? "TRUE" : "FALSE");
343 fprintf(file, "DirectSound = %s\n", DirectSound ? "TRUE" : "FALSE");
344 fprintf(file, "ExclusiveSound = %s\n", ExclusiveSound ? "TRUE" : "FALSE");
345 fprintf(file, "AutoPause = %s\n", AutoPause ? "TRUE" : "FALSE");
346 fprintf(file, "PrefsAtStartup = %s\n", PrefsAtStartup ? "TRUE" : "FALSE");
347 fprintf(file, "SystemMemory = %s\n", SystemMemory ? "TRUE" : "FALSE");
348 fprintf(file, "AlwaysCopy = %s\n", AlwaysCopy ? "TRUE" : "FALSE");
349 fprintf(file, "SystemKeys = %s\n", SystemKeys ? "TRUE" : "FALSE");
350 fprintf(file, "ShowLEDs = %s\n", ShowLEDs ? "TRUE" : "FALSE");
351 fclose(file);
352 ThePrefsOnDisk = *this;
353 return true;
354 }
355 return false;
356 }
357
358
359 #ifdef __BEOS__
360 #include "Prefs_Be.h"
361 #endif
362
363 #ifdef AMIGA
364 #include "Prefs_Amiga.h"
365 #endif
366
367 #ifdef WIN32
368 #include "Prefs_WIN32.h"
369 #endif
370
371 #ifdef __unix
372 #ifdef HAVE_GLADE
373 #include "Prefs_glade.h"
374 #else
375 #include "Prefs_x.h"
376 #endif
377 #endif