-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPrefs.mm
executable file
·358 lines (316 loc) · 10.1 KB
/
Prefs.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
Frodo, Commodore 64 emulator for the iPhone
Copyright (C) 1994-1997,2002 Christian Bauer
See gpl.txt for license information.
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Prefs.cpp - Global preferences
*
* Frodo (C) 1994-1997,2002 Christian Bauer
*/
#include "sysdeps.h"
#include "Prefs.h"
#include "Display.h"
#include "C64.h"
// These are the active preferences
Prefs ThePrefs;
// These are the preferences on disk
Prefs ThePrefsOnDisk;
/*
* Constructor: Set up preferences with defaults
*/
Prefs::Prefs()
{
NormalCycles = 63;
BadLineCycles = 23;
CIACycles = 63;
FloppyCycles = 64;
SkipFrames = 5;
DriveType = DRVTYPE_DIR;
DrivePath[0]='\0';
LuaScriptPath[0] = NULL;
SIDType = SIDTYPE_DIGITAL;
DisplayType = DISPTYPE_WINDOW;
LatencyMin = 80;
LatencyMax = 250;
SpritesOn = true;
SpriteCollisions = true;
Joystick1On = true;
Joystick2On = false;
JoystickSwap = true;
LimitSpeed = true;
FastReset = false;
CIAIRQHack = false;
Emul1541Proc = false;
AdaptiveFrameSkip = true;
BordersOn = false;
SingleCycleEmulation = false;
SIDOn = true;
SIDFilters = true;
ShowSpeed = false;
AutoBoot = true;
UseCommodoreKeyboard = false;
OptimizeForSpeedAndBattery = true;
}
void Prefs::ChangeRom(NSString *filename) {
[filename getCString:DrivePath maxLength:sizeof(DrivePath) encoding:[NSString defaultCStringEncoding]];
if ([filename rangeOfString:@"d64" options:NSCaseInsensitiveSearch].location == NSNotFound) {
DriveType = DRVTYPE_T64;
} else {
DriveType = DRVTYPE_D64;
}
}
void Prefs::LuaScript(NSString *filename) {
if (filename)
[filename getCString:LuaScriptPath maxLength:sizeof(LuaScriptPath) encoding:[NSString defaultCStringEncoding]];
else {
LuaScriptPath[0] = NULL;
}
}
/*
* Check if two Prefs structures are equal
*/
bool Prefs::operator==(const Prefs &rhs) const
{
return (1
&& NormalCycles == rhs.NormalCycles
&& BadLineCycles == rhs.BadLineCycles
&& CIACycles == rhs.CIACycles
&& FloppyCycles == rhs.FloppyCycles
&& SkipFrames == rhs.SkipFrames
&& DriveType == rhs.DriveType
&& strcmp(DrivePath, rhs.DrivePath) == 0
&& SIDType == rhs.SIDType
&& DisplayType == rhs.DisplayType
&& SpritesOn == rhs.SpritesOn
&& SpriteCollisions == rhs.SpriteCollisions
&& Joystick1On == rhs.Joystick1On
&& Joystick2On == rhs.Joystick2On
&& JoystickSwap == rhs.JoystickSwap
&& LimitSpeed == rhs.LimitSpeed
&& FastReset == rhs.FastReset
&& CIAIRQHack == rhs.CIAIRQHack
&& Emul1541Proc == rhs.Emul1541Proc
&& SIDFilters == rhs.SIDFilters
&& SingleCycleEmulation == rhs.SingleCycleEmulation
&& SIDOn == rhs.SIDOn
&& ShowSpeed == rhs.ShowSpeed
&& AutoBoot == rhs.AutoBoot
&& UseCommodoreKeyboard == rhs.UseCommodoreKeyboard
&& OptimizeForSpeedAndBattery == rhs.OptimizeForSpeedAndBattery
);
}
bool Prefs::operator!=(const Prefs &rhs) const
{
return !operator==(rhs);
}
/*
* Check preferences for validity and correct if necessary
*/
void Prefs::Check(void)
{
if (SkipFrames <= 0) SkipFrames = 1;
if (SIDType < SIDTYPE_NONE || SIDType > SIDTYPE_SIDCARD)
SIDType = SIDTYPE_NONE;
if (DisplayType < DISPTYPE_WINDOW || DisplayType > DISPTYPE_SCREEN)
DisplayType = DISPTYPE_WINDOW;
if (DriveType < DRVTYPE_DIR || DriveType > DRVTYPE_T64)
DriveType = DRVTYPE_DIR;
}
void Prefs::DisableCommodoreKeyboard() {
// for now, Commodore keyboard is always disabled after load
UseCommodoreKeyboard = false;
}
void replacechr(char *path, char find, char repl) {
do {
if (*path == find)
*path = repl;
} while (*path++);
}
void toStore(char *path) {
replacechr(path, ' ', ':');
}
void fromStore(char *path) {
replacechr(path, ':', ' ');
}
/*
* Load preferences from file
*/
void Prefs::Load(const char *filename)
{
FILE *file;
char line[256], keyword[256], value[256];
if ((file = fopen(filename, "r")) != NULL) {
while(fgets(line, 255, file)) {
if (sscanf(line, "%s = %s\n", keyword, value) == 2) {
if (!strcmp(keyword, "NormalCycles"))
NormalCycles = atoi(value);
else if (!strcmp(keyword, "BadLineCycles"))
BadLineCycles = atoi(value);
else if (!strcmp(keyword, "CIACycles"))
CIACycles = atoi(value);
else if (!strcmp(keyword, "FloppyCycles"))
FloppyCycles = atoi(value);
else if (!strcmp(keyword, "SkipFrames"))
SkipFrames = atoi(value);
else if (!strcmp(keyword, "LatencyMin"))
LatencyMin = atoi(value);
else if (!strcmp(keyword, "LatencyMax"))
LatencyMax = atoi(value);
else if (!strcmp(keyword, "DriveType8"))
if (!strcmp(value, "DIR"))
DriveType = DRVTYPE_DIR;
else if (!strcmp(value, "D64"))
DriveType = DRVTYPE_D64;
else
DriveType = DRVTYPE_T64;
else if (!strcmp(keyword, "DrivePath8")) {
fromStore(value);
strcpy(DrivePath, value);
}
else if (!strcmp(keyword, "LuaScriptPath")) {
fromStore(value);
strcpy(LuaScriptPath, value);
}
else if (!strcmp(keyword, "SIDType"))
if (!strcmp(value, "DIGITAL"))
SIDType = SIDTYPE_DIGITAL;
else if (!strcmp(value, "SIDCARD"))
SIDType = SIDTYPE_SIDCARD;
else
SIDType = SIDTYPE_NONE;
else if (!strcmp(keyword, "BordersOn"))
BordersOn = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "SpritesOn"))
SpritesOn = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "SpriteCollisions"))
SpriteCollisions = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "Joystick1On"))
Joystick1On = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "Joystick2On"))
Joystick2On = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "JoystickSwap"))
JoystickSwap = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "LimitSpeed"))
LimitSpeed = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "FastReset"))
FastReset = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "CIAIRQHack"))
CIAIRQHack = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "Emul1541Proc"))
Emul1541Proc = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "SIDFilters"))
SIDFilters = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "SingleCycleEmulation"))
SingleCycleEmulation = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "SIDOn"))
SIDOn = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "ShowSpeed"))
ShowSpeed = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "AutoBoot"))
AutoBoot = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "UseCommodoreKeyboard"))
UseCommodoreKeyboard = !strcmp(value, "TRUE");
else if (!strcmp(keyword, "OptimizeForSpeedAndBattery"))
OptimizeForSpeedAndBattery = !strcmp(value, "TRUE");
}
}
fclose(file);
}
Check();
ConfigureOptimizations();
DisableCommodoreKeyboard();
ThePrefsOnDisk = *this;
}
/*
* Reconfigures the prefs after load or setting properties
*/
void Prefs::ConfigureOptimizations() {
SIDFilters = true;
if (OptimizeForSpeedAndBattery) {
} else {
}
#if defined(_ARM_ARCH_7) || TARGET_IPHONE_SIMULATOR
SkipFrames = 1;
#endif
}
/*
* Save preferences to file
* true: success, false: error
*/
bool Prefs::Save(const char *filename)
{
FILE *file;
Check();
if ((file = fopen(filename, "w")) != NULL) {
fprintf(file, "NormalCycles = %d\n", NormalCycles);
fprintf(file, "BadLineCycles = %d\n", BadLineCycles);
fprintf(file, "CIACycles = %d\n", CIACycles);
fprintf(file, "FloppyCycles = %d\n", FloppyCycles);
fprintf(file, "SkipFrames = %d\n", SkipFrames);
fprintf(file, "LatencyMin = %d\n", LatencyMin);
fprintf(file, "LatencyMax = %d\n", LatencyMax);
fprintf(file, "DriveType%d = ", 8);
switch (DriveType) {
case DRVTYPE_DIR:
fprintf(file, "DIR\n");
break;
case DRVTYPE_D64:
fprintf(file, "D64\n");
break;
case DRVTYPE_T64:
fprintf(file, "T64\n");
break;
}
toStore(DrivePath);
fprintf(file, "DrivePath%d = %s\n", 8, DrivePath);
fromStore(DrivePath);
toStore(LuaScriptPath);
fprintf(file, "LuaScriptPath = %s\n", LuaScriptPath);
fromStore(LuaScriptPath);
fprintf(file, "SIDType = ");
switch (SIDType) {
case SIDTYPE_NONE:
fprintf(file, "NONE\n");
break;
case SIDTYPE_DIGITAL:
fprintf(file, "DIGITAL\n");
break;
case SIDTYPE_SIDCARD:
fprintf(file, "SIDCARD\n");
break;
}
fprintf(file, "BordersOn = %s\n", BordersOn ? "TRUE" : "FALSE");
fprintf(file, "SpritesOn = %s\n", SpritesOn ? "TRUE" : "FALSE");
fprintf(file, "SpriteCollisions = %s\n", SpriteCollisions ? "TRUE" : "FALSE");
fprintf(file, "Joystick1On = %s\n", Joystick1On ? "TRUE" : "FALSE");
fprintf(file, "Joystick2On = %s\n", Joystick2On ? "TRUE" : "FALSE");
fprintf(file, "JoystickSwap = %s\n", JoystickSwap ? "TRUE" : "FALSE");
fprintf(file, "LimitSpeed = %s\n", LimitSpeed ? "TRUE" : "FALSE");
fprintf(file, "FastReset = %s\n", FastReset ? "TRUE" : "FALSE");
fprintf(file, "CIAIRQHack = %s\n", CIAIRQHack ? "TRUE" : "FALSE");
fprintf(file, "Emul1541Proc = %s\n", Emul1541Proc ? "TRUE" : "FALSE");
fprintf(file, "SIDFilters = %s\n", SIDFilters ? "TRUE" : "FALSE");
fprintf(file, "SingleCycleEmulation = %s\n", SingleCycleEmulation ? "TRUE" : "FALSE");
fprintf(file, "SIDOn = %s\n", SIDOn ? "TRUE" : "FALSE");
fprintf(file, "SIDFilters = %s\n", SIDFilters ? "TRUE" : "FALSE");
fprintf(file, "ShowSpeed = %s\n", ShowSpeed ? "TRUE" : "FALSE");
fprintf(file, "AutoBoot = %s\n", AutoBoot ? "TRUE" : "FALSE");
fprintf(file, "UseCommodoreKeyboard = %s\n", UseCommodoreKeyboard ? "TRUE" : "FALSE");
fprintf(file, "OptimizeForSpeedAndBattery = %s\n", OptimizeForSpeedAndBattery ? "TRUE" : "FALSE");
fclose(file);
ThePrefsOnDisk = *this;
return true;
}
return false;
}