1 |
asvitkine |
1.1 |
/* |
2 |
|
|
* PrefsEditor.m - Preferences editing in Cocoa on Mac OS X |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2006-2007 Alexei Svitkine |
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 |
|
|
#import "PrefsEditor.h" |
22 |
|
|
|
23 |
|
|
#import "sysdeps.h" |
24 |
|
|
#import "prefs.h" |
25 |
|
|
|
26 |
|
|
const int CDROMRefNum = -62; // RefNum of driver |
27 |
|
|
|
28 |
asvitkine |
1.6 |
#ifdef STANDALONE_PREFS |
29 |
asvitkine |
1.5 |
void prefs_init() |
30 |
|
|
{ |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
void prefs_exit() |
34 |
|
|
{ |
35 |
|
|
} |
36 |
asvitkine |
1.6 |
#endif |
37 |
asvitkine |
1.5 |
|
38 |
asvitkine |
1.1 |
@implementation PrefsEditor |
39 |
|
|
|
40 |
|
|
- (id) init |
41 |
|
|
{ |
42 |
|
|
self = [super init]; |
43 |
|
|
|
44 |
|
|
#ifdef STANDALONE_PREFS |
45 |
asvitkine |
1.3 |
AddPrefsDefaults(); |
46 |
|
|
AddPlatformPrefsDefaults(); |
47 |
asvitkine |
1.1 |
|
48 |
asvitkine |
1.3 |
// Load preferences from settings file |
49 |
asvitkine |
1.5 |
LoadPrefs(NULL); |
50 |
asvitkine |
1.3 |
chdir([[[NSBundle mainBundle] bundlePath] UTF8String]); |
51 |
asvitkine |
1.1 |
chdir(".."); |
52 |
|
|
#endif |
53 |
|
|
|
54 |
|
|
return self; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
- (int)numberOfRowsInTableView:(NSTableView *)aTable |
58 |
|
|
{ |
59 |
|
|
return [diskArray count]; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
- (id)tableView:(NSTableView *)aTable objectValueForTableColumn:(NSTableColumn *)aCol row:(int)aRow |
63 |
|
|
{ |
64 |
|
|
return [diskArray objectAtIndex: aRow]; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
NSString *getStringFromPrefs(const char *key) |
68 |
|
|
{ |
69 |
|
|
const char *value = PrefsFindString(key); |
70 |
|
|
if (value == NULL) |
71 |
|
|
return @""; |
72 |
|
|
return [NSString stringWithCString: value]; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
- (void) awakeFromNib |
76 |
|
|
{ |
77 |
|
|
diskArray = [[NSMutableArray alloc] init]; |
78 |
|
|
|
79 |
|
|
const char *dsk; |
80 |
|
|
int index = 0; |
81 |
|
|
while ((dsk = PrefsFindString("disk", index++)) != NULL) |
82 |
|
|
[diskArray addObject: [NSString stringWithCString: dsk ]]; |
83 |
|
|
|
84 |
|
|
[disks setDataSource: self]; |
85 |
|
|
[disks reloadData]; |
86 |
|
|
|
87 |
asvitkine |
1.3 |
int bootdriver = PrefsFindInt32("bootdriver"), active = 0; |
88 |
|
|
switch (bootdriver) { |
89 |
|
|
case 0: active = 0; break; |
90 |
asvitkine |
1.1 |
case CDROMRefNum: active = 1; break; |
91 |
asvitkine |
1.3 |
} |
92 |
asvitkine |
1.1 |
[bootFrom selectItemAtIndex: active ]; |
93 |
|
|
|
94 |
|
|
[romFile setStringValue: getStringFromPrefs("rom") ]; |
95 |
|
|
[unixRoot setStringValue: getStringFromPrefs("extfs") ]; |
96 |
|
|
[disableCdrom setIntValue: PrefsFindBool("nocdrom") ]; |
97 |
|
|
[ramSize setIntValue: PrefsFindInt32("ramsize") / (1024*1024) ]; |
98 |
|
|
[ramSizeStepper setIntValue: PrefsFindInt32("ramsize") / (1024*1024) ]; |
99 |
|
|
|
100 |
|
|
int display_type = 0; |
101 |
asvitkine |
1.3 |
int dis_width = 640; |
102 |
|
|
int dis_height = 480; |
103 |
asvitkine |
1.1 |
|
104 |
asvitkine |
1.3 |
const char *str = PrefsFindString("screen"); |
105 |
asvitkine |
1.1 |
if (str != NULL) { |
106 |
|
|
if (sscanf(str, "win/%d/%d", &dis_width, &dis_height) == 2) |
107 |
|
|
display_type = 0; |
108 |
|
|
else if (sscanf(str, "dga/%d/%d", &dis_width, &dis_height) == 2) |
109 |
|
|
display_type = 1; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
[videoType selectItemAtIndex: display_type ]; |
113 |
|
|
[width setIntValue: dis_width ]; |
114 |
|
|
[height setIntValue: dis_height ]; |
115 |
|
|
|
116 |
asvitkine |
1.3 |
int frameskip = PrefsFindInt32("frameskip"); |
117 |
|
|
int item = -1; |
118 |
|
|
switch (frameskip) { |
119 |
|
|
case 12: item = 0; break; |
120 |
|
|
case 8: item = 1; break; |
121 |
|
|
case 6: item = 2; break; |
122 |
|
|
case 4: item = 3; break; |
123 |
|
|
case 2: item = 4; break; |
124 |
|
|
case 1: item = 5; break; |
125 |
|
|
case 0: item = 6; break; |
126 |
|
|
} |
127 |
|
|
if (item >= 0) |
128 |
asvitkine |
1.1 |
[refreshRate selectItemAtIndex: item ]; |
129 |
|
|
|
130 |
|
|
[qdAccel setIntValue: PrefsFindBool("gfxaccel") ]; |
131 |
|
|
|
132 |
|
|
[disableSound setIntValue: PrefsFindBool("nosound") ]; |
133 |
|
|
[outDevice setStringValue: getStringFromPrefs("dsp") ]; |
134 |
|
|
[mixDevice setStringValue: getStringFromPrefs("mixer") ]; |
135 |
|
|
|
136 |
|
|
[useRawKeyCodes setIntValue: PrefsFindBool("keycodes") ]; |
137 |
|
|
[rawKeyCodes setStringValue: getStringFromPrefs("keycodefile") ]; |
138 |
|
|
[rawKeyCodes setEnabled:[useRawKeyCodes intValue]]; |
139 |
|
|
|
140 |
|
|
int wheelmode = PrefsFindInt32("mousewheelmode"), wheel = 0; |
141 |
asvitkine |
1.3 |
switch (wheelmode) { |
142 |
|
|
case 0: wheel = 0; break; |
143 |
|
|
case 1: wheel = 1; break; |
144 |
|
|
} |
145 |
asvitkine |
1.1 |
[mouseWheel selectItemAtIndex: wheel ]; |
146 |
|
|
|
147 |
|
|
[scrollLines setIntValue: PrefsFindInt32("mousewheellines") ]; |
148 |
|
|
[scrollLinesStepper setIntValue: PrefsFindInt32("mousewheellines") ]; |
149 |
|
|
|
150 |
|
|
[ignoreIllegalMemoryAccesses setIntValue: PrefsFindBool("ignoresegv") ]; |
151 |
|
|
[dontUseCPUWhenIdle setIntValue: PrefsFindBool("idlewait") ]; |
152 |
|
|
[enableJIT setIntValue: PrefsFindBool("jit") ]; |
153 |
|
|
[enable68kDREmulator setIntValue: PrefsFindBool("jit68k") ]; |
154 |
asvitkine |
1.3 |
|
155 |
asvitkine |
1.1 |
[modemPort setStringValue: getStringFromPrefs("seriala") ]; |
156 |
|
|
[printerPort setStringValue: getStringFromPrefs("serialb") ]; |
157 |
|
|
[ethernetInterface setStringValue: getStringFromPrefs("ether") ]; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
- (IBAction) addDisk:(id)sender |
161 |
|
|
{ |
162 |
|
|
NSOpenPanel *open = [NSOpenPanel openPanel]; |
163 |
|
|
[open setCanChooseDirectories:NO]; |
164 |
|
|
[open setAllowsMultipleSelection:NO]; |
165 |
|
|
[open beginSheetForDirectory: @"" |
166 |
|
|
file: @"Unknown" |
167 |
|
|
modalForWindow: window |
168 |
|
|
modalDelegate: self |
169 |
|
|
didEndSelector: @selector(_addDiskEnd: returnCode: contextInfo:) |
170 |
|
|
contextInfo: nil]; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
- (void) _addDiskEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
174 |
|
|
{ |
175 |
asvitkine |
1.3 |
if (theReturnCode == NSOKButton) { |
176 |
|
|
char cwd[1024], filename[1024]; |
177 |
|
|
int cwdlen; |
178 |
|
|
strlcpy(filename, [[open filename] UTF8String], sizeof(filename)); |
179 |
|
|
getcwd(cwd, sizeof(cwd)); |
180 |
|
|
cwdlen = strlen(cwd); |
181 |
|
|
if (!strncmp(cwd, filename, cwdlen)) { |
182 |
|
|
if (cwdlen >= 0 && cwd[cwdlen-1] != '/') |
183 |
|
|
cwdlen++; |
184 |
|
|
[diskArray addObject: [NSString stringWithCString: filename + cwdlen ]]; |
185 |
|
|
} else { |
186 |
|
|
[diskArray addObject: [open filename]]; |
187 |
asvitkine |
1.1 |
} |
188 |
asvitkine |
1.3 |
[disks reloadData]; |
189 |
|
|
} |
190 |
|
|
[(NSData *)theContextInfo release]; |
191 |
asvitkine |
1.1 |
} |
192 |
|
|
|
193 |
|
|
- (IBAction) removeDisk:(id)sender |
194 |
|
|
{ |
195 |
|
|
int selectedRow = [disks selectedRow]; |
196 |
|
|
if (selectedRow >= 0) { |
197 |
|
|
[diskArray removeObjectAtIndex: selectedRow]; |
198 |
|
|
[disks reloadData]; |
199 |
|
|
} |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
- (IBAction) createDisk:(id)sender |
203 |
|
|
{ |
204 |
|
|
NSSavePanel *save = [NSSavePanel savePanel]; |
205 |
|
|
[save setAccessoryView: diskSaveSize]; |
206 |
|
|
[save beginSheetForDirectory: @"" |
207 |
|
|
file: @"New.dsk" |
208 |
|
|
modalForWindow: window |
209 |
|
|
modalDelegate: self |
210 |
|
|
didEndSelector: @selector(_createDiskEnd: returnCode: contextInfo:) |
211 |
|
|
contextInfo: nil]; |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
- (void) _createDiskEnd: (NSSavePanel *) save returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
215 |
|
|
{ |
216 |
asvitkine |
1.3 |
if (theReturnCode == NSOKButton) { |
217 |
|
|
int size = [diskSaveSizeField intValue]; |
218 |
|
|
if (size >= 0 && size <= 10000) { |
219 |
|
|
char cmd[1024]; |
220 |
|
|
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", [[save filename] UTF8String], [diskSaveSizeField intValue]); |
221 |
|
|
int ret = system(cmd); |
222 |
|
|
if (ret == 0) { |
223 |
|
|
char cwd[1024], filename[1024]; |
224 |
|
|
int cwdlen; |
225 |
|
|
strlcpy(filename, [[save filename] UTF8String], sizeof(filename)); |
226 |
|
|
getcwd(cwd, sizeof(cwd)); |
227 |
|
|
cwdlen = strlen(cwd); |
228 |
|
|
if (!strncmp(cwd, filename, cwdlen)) { |
229 |
|
|
if (cwdlen >= 0 && cwd[cwdlen-1] != '/') |
230 |
|
|
cwdlen++; |
231 |
|
|
[diskArray addObject: [NSString stringWithCString: filename + cwdlen ]]; |
232 |
|
|
} else { |
233 |
|
|
[diskArray addObject: [save filename]]; |
234 |
asvitkine |
1.1 |
} |
235 |
asvitkine |
1.3 |
[disks reloadData]; |
236 |
asvitkine |
1.1 |
} |
237 |
|
|
} |
238 |
asvitkine |
1.3 |
} |
239 |
|
|
[(NSData *)theContextInfo release]; |
240 |
asvitkine |
1.1 |
} |
241 |
|
|
|
242 |
|
|
- (IBAction) useRawKeyCodesClicked:(id)sender |
243 |
|
|
{ |
244 |
|
|
[rawKeyCodes setEnabled:[useRawKeyCodes intValue]]; |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
- (IBAction) browseForROMFileClicked:(id)sender |
248 |
|
|
{ |
249 |
|
|
NSOpenPanel *open = [NSOpenPanel openPanel]; |
250 |
|
|
NSString *dir = @""; |
251 |
|
|
NSString *file = [romFile stringValue]; |
252 |
|
|
[open setCanChooseDirectories:NO]; |
253 |
|
|
[open setAllowsMultipleSelection:NO]; |
254 |
|
|
[open beginSheetForDirectory: dir |
255 |
|
|
file: file |
256 |
|
|
modalForWindow: window |
257 |
|
|
modalDelegate: self |
258 |
|
|
didEndSelector: @selector(_browseForROMFileEnd: returnCode: contextInfo:) |
259 |
|
|
contextInfo: nil]; |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
- (void) _browseForROMFileEnd: (NSOpenPanel *) open returnCode: (int) theReturnCode contextInfo: (void *) theContextInfo |
263 |
|
|
{ |
264 |
asvitkine |
1.3 |
if (theReturnCode == NSOKButton) { |
265 |
|
|
char cwd[1024], filename[1024]; |
266 |
|
|
int cwdlen; |
267 |
|
|
strlcpy(filename, [[open filename] UTF8String], sizeof(filename)); |
268 |
|
|
getcwd(cwd, sizeof(cwd)); |
269 |
|
|
cwdlen = strlen(cwd); |
270 |
|
|
if (!strncmp(cwd, filename, cwdlen)) { |
271 |
|
|
if (cwdlen >= 0 && cwd[cwdlen-1] != '/') |
272 |
|
|
cwdlen++; |
273 |
|
|
[romFile setStringValue: [NSString stringWithCString: filename + cwdlen ]]; |
274 |
|
|
} else { |
275 |
|
|
[romFile setStringValue: [open filename]]; |
276 |
asvitkine |
1.1 |
} |
277 |
asvitkine |
1.3 |
} |
278 |
|
|
[(NSData *)theContextInfo release]; |
279 |
asvitkine |
1.1 |
} |
280 |
|
|
|
281 |
|
|
- (void) windowWillClose: (NSNotification *) aNotification; |
282 |
|
|
{ |
283 |
asvitkine |
1.3 |
while (PrefsFindString("disk")) |
284 |
|
|
PrefsRemoveItem("disk"); |
285 |
asvitkine |
1.1 |
|
286 |
|
|
for (int i = 0; i < [diskArray count]; i++) { |
287 |
asvitkine |
1.3 |
PrefsAddString("disk", [[diskArray objectAtIndex:i] UTF8String]); |
288 |
asvitkine |
1.1 |
} |
289 |
|
|
PrefsReplaceInt32("bootdriver", ([bootFrom indexOfSelectedItem] == 1 ? CDROMRefNum : 0)); |
290 |
asvitkine |
1.3 |
PrefsReplaceString("rom", [[romFile stringValue] UTF8String]); |
291 |
|
|
PrefsReplaceString("extfs", [[unixRoot stringValue] UTF8String]); |
292 |
|
|
PrefsReplaceBool("nocdrom", [disableCdrom intValue]); |
293 |
|
|
PrefsReplaceInt32("ramsize", [ramSize intValue] << 20); |
294 |
asvitkine |
1.1 |
|
295 |
asvitkine |
1.3 |
char pref[256]; |
296 |
asvitkine |
1.1 |
snprintf(pref, sizeof(pref), "%s/%d/%d", [videoType indexOfSelectedItem] == 0 ? "win" : "dga", [width intValue], [height intValue]); |
297 |
|
|
PrefsReplaceString("screen", pref); |
298 |
|
|
|
299 |
|
|
int rate = 8; |
300 |
|
|
switch ([refreshRate indexOfSelectedItem]) { |
301 |
|
|
case 0: rate = 12; break; |
302 |
|
|
case 1: rate = 8; break; |
303 |
|
|
case 2: rate = 6; break; |
304 |
|
|
case 3: rate = 4; break; |
305 |
|
|
case 4: rate = 2; break; |
306 |
|
|
case 5: rate = 1; break; |
307 |
asvitkine |
1.4 |
case 6: rate = 0; break; |
308 |
asvitkine |
1.1 |
} |
309 |
|
|
PrefsReplaceInt32("frameskip", rate); |
310 |
asvitkine |
1.3 |
PrefsReplaceBool("gfxaccel", [qdAccel intValue]); |
311 |
asvitkine |
1.1 |
|
312 |
asvitkine |
1.3 |
PrefsReplaceBool("nosound", [disableSound intValue]); |
313 |
|
|
PrefsReplaceString("dsp", [[outDevice stringValue] UTF8String]); |
314 |
|
|
PrefsReplaceString("mixer", [[mixDevice stringValue] UTF8String]); |
315 |
asvitkine |
1.1 |
|
316 |
asvitkine |
1.3 |
PrefsReplaceBool("keycodes", [useRawKeyCodes intValue]); |
317 |
|
|
PrefsReplaceString("keycodefile", [[rawKeyCodes stringValue] UTF8String]); |
318 |
asvitkine |
1.1 |
|
319 |
|
|
PrefsReplaceInt32("mousewheelmode", [mouseWheel indexOfSelectedItem]); |
320 |
asvitkine |
1.3 |
PrefsReplaceInt32("mousewheellines", [scrollLines intValue]); |
321 |
asvitkine |
1.1 |
|
322 |
asvitkine |
1.3 |
PrefsReplaceBool("ignoresegv", [ignoreIllegalMemoryAccesses intValue]); |
323 |
|
|
PrefsReplaceBool("idlewait", [dontUseCPUWhenIdle intValue]); |
324 |
|
|
PrefsReplaceBool("jit", [enableJIT intValue]); |
325 |
|
|
PrefsReplaceBool("jit68k", [enable68kDREmulator intValue]); |
326 |
|
|
|
327 |
|
|
PrefsReplaceString("seriala", [[modemPort stringValue] UTF8String]); |
328 |
|
|
PrefsReplaceString("serialb", [[printerPort stringValue] UTF8String]); |
329 |
|
|
PrefsReplaceString("ether", [[ethernetInterface stringValue] UTF8String]); |
330 |
asvitkine |
1.1 |
|
331 |
|
|
SavePrefs(); |
332 |
|
|
|
333 |
|
|
#ifdef STANDALONE_PREFS |
334 |
|
|
PrefsExit(); |
335 |
|
|
exit(0); |
336 |
asvitkine |
1.2 |
#else |
337 |
asvitkine |
1.3 |
[NSApp stopModal]; |
338 |
asvitkine |
1.1 |
#endif |
339 |
|
|
} |
340 |
|
|
|
341 |
|
|
- (void) dealloc |
342 |
|
|
{ |
343 |
|
|
[super dealloc]; |
344 |
|
|
} |
345 |
|
|
|
346 |
|
|
@end |
347 |
|
|
|