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