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