1 |
nigel |
1.1 |
/* |
2 |
|
|
* PrefsEditor.m - GUI stuff for Basilisk II preferences |
3 |
|
|
* (which is a text file in the user's home directory) |
4 |
|
|
* |
5 |
nigel |
1.12 |
* $Id: PrefsEditor.mm,v 1.11 2003/08/16 02:51:46 nigel Exp $ |
6 |
nigel |
1.1 |
* |
7 |
nigel |
1.7 |
* Basilisk II (C) 1997-2003 Christian Bauer |
8 |
nigel |
1.1 |
* |
9 |
|
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU General Public License as published by |
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
12 |
|
|
* (at your option) any later version. |
13 |
|
|
* |
14 |
|
|
* This program is distributed in the hope that it will be useful, |
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
|
|
* GNU General Public License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU General Public License |
20 |
|
|
* along with this program; if not, write to the Free Software |
21 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#import "PrefsEditor.h" |
25 |
|
|
|
26 |
|
|
@implementation TableDS |
27 |
|
|
|
28 |
|
|
- (TableDS *) init |
29 |
|
|
{ |
30 |
|
|
self = [super init]; |
31 |
|
|
|
32 |
|
|
numItems = 0; |
33 |
nigel |
1.5 |
col1 = [NSMutableArray new]; |
34 |
|
|
col2 = [NSMutableArray new]; |
35 |
nigel |
1.1 |
|
36 |
|
|
return self; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
- (void) dealloc |
40 |
|
|
{ |
41 |
|
|
[col1 dealloc]; |
42 |
|
|
[col2 dealloc]; |
43 |
|
|
[super dealloc]; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
- (void) addInt: (int)target |
47 |
|
|
withPath: (NSString *)path |
48 |
|
|
{ |
49 |
|
|
[col1 addObject: [NSNumber numberWithInt: target]]; |
50 |
|
|
[col2 addObject: path]; |
51 |
|
|
++numItems; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
- (void) addObject: (NSObject *)obj |
55 |
|
|
withPath: (NSString *)path |
56 |
|
|
{ |
57 |
|
|
[col1 addObject: obj]; |
58 |
|
|
[col2 addObject: path]; |
59 |
|
|
++numItems; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
- (void) deleteAll |
63 |
|
|
{ |
64 |
|
|
numItems = 0; |
65 |
|
|
[col1 removeAllObjects]; |
66 |
|
|
[col2 removeAllObjects]; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
- (BOOL) deleteRow: (int)row |
70 |
|
|
{ |
71 |
|
|
if ( row > numItems ) |
72 |
|
|
return NO; |
73 |
|
|
|
74 |
|
|
[col1 removeObjectAtIndex: row]; |
75 |
|
|
[col2 removeObjectAtIndex: row]; |
76 |
|
|
-- numItems; |
77 |
|
|
|
78 |
|
|
return YES; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
- (int)intAtRow: (int)row |
82 |
|
|
{ |
83 |
|
|
return [[col1 objectAtIndex: row] intValue]; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
- (int) numberOfRowsInTableView: (NSTableView *)tView |
87 |
|
|
{ |
88 |
|
|
return numItems; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
- (NSString *)pathAtRow: (int)row |
92 |
|
|
{ |
93 |
|
|
return (NSString *) [col2 objectAtIndex: row]; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
- (id) tableView: (NSTableView *)tView |
97 |
|
|
objectValueForTableColumn: (NSTableColumn *)tColumn |
98 |
|
|
row: (int)row |
99 |
|
|
{ |
100 |
|
|
if ( [[tColumn identifier] isEqualToString:@"path"] ) |
101 |
|
|
return [col2 objectAtIndex: row]; |
102 |
|
|
else |
103 |
|
|
return [col1 objectAtIndex: row]; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
@end |
107 |
|
|
|
108 |
|
|
@implementation PrefsEditor |
109 |
|
|
|
110 |
|
|
#import <AppKit/NSImage.h> // For [NSBundle pathForImageResource:] proto |
111 |
|
|
|
112 |
nigel |
1.10 |
#include <string> |
113 |
|
|
using std::string; |
114 |
|
|
extern string UserPrefsPath; // from prefs_unix.cpp |
115 |
|
|
|
116 |
nigel |
1.1 |
#import "sysdeps.h" // Types used in Basilisk C++ code |
117 |
|
|
#import "video_macosx.h" // some items that we edit here |
118 |
|
|
#import "misc_macosx.h" // WarningSheet() prototype |
119 |
|
|
|
120 |
|
|
#import <prefs.h> |
121 |
|
|
|
122 |
nigel |
1.3 |
#define DEBUG 0 |
123 |
nigel |
1.1 |
#import <debug.h> |
124 |
|
|
|
125 |
|
|
- (PrefsEditor *) init |
126 |
|
|
{ |
127 |
|
|
self = [super init]; |
128 |
|
|
|
129 |
|
|
edited = NO; |
130 |
|
|
|
131 |
|
|
devs = @"/dev"; |
132 |
|
|
home = NSHomeDirectory(); |
133 |
nigel |
1.5 |
volsDS = [TableDS new]; |
134 |
|
|
SCSIds = [TableDS new]; |
135 |
nigel |
1.1 |
|
136 |
nigel |
1.5 |
lockCell = [NSImageCell new]; |
137 |
nigel |
1.1 |
if ( lockCell == nil ) |
138 |
|
|
NSLog (@"%s - Can't create NSImageCell?", __PRETTY_FUNCTION__); |
139 |
|
|
|
140 |
nigel |
1.5 |
blank = [NSImage new]; |
141 |
nigel |
1.1 |
locked = [NSImage alloc]; |
142 |
|
|
if ( [locked initWithContentsOfFile: |
143 |
|
|
[[NSBundle mainBundle] |
144 |
|
|
pathForImageResource: @"nowrite.icns"]] == nil ) |
145 |
|
|
NSLog(@"%s - Couldn't open write protection image", __PRETTY_FUNCTION__); |
146 |
|
|
|
147 |
|
|
return self; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
- (void) dealloc |
151 |
|
|
{ |
152 |
|
|
[volsDS dealloc]; |
153 |
|
|
[SCSIds dealloc]; |
154 |
|
|
[lockCell dealloc]; |
155 |
|
|
[locked dealloc]; |
156 |
|
|
[blank dealloc]; |
157 |
|
|
[super dealloc]; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
- (void) awakeFromNib |
161 |
|
|
{ |
162 |
|
|
emuFreq = [theEmulator speed]; |
163 |
|
|
#if DEBUG |
164 |
|
|
[self ShowPrefs: self]; // For testing |
165 |
|
|
#endif |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
- (BOOL) hasEdited |
169 |
|
|
{ |
170 |
|
|
return edited; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
- (NSWindow *) window |
174 |
|
|
{ |
175 |
|
|
return panel; |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
- (IBAction) AddSCSI: (id)sender |
179 |
|
|
{ |
180 |
|
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
181 |
|
|
|
182 |
|
|
if ( [oP runModalForDirectory:home file:nil types:nil] == NSOKButton ) |
183 |
|
|
{ |
184 |
|
|
[SCSIds addInt: -1 |
185 |
|
|
withPath: [oP filename] ]; |
186 |
|
|
[SCSIdisks reloadData]; |
187 |
|
|
edited = YES; |
188 |
|
|
} |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
- (IBAction) AddVolume: (id)sender |
192 |
|
|
{ |
193 |
|
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
194 |
|
|
|
195 |
|
|
if ( [oP runModalForDirectory:home file:nil types:nil] == NSOKButton ) |
196 |
|
|
{ |
197 |
|
|
[volsDS addObject: (NSObject *) locked |
198 |
|
|
withPath: [oP filename] ]; |
199 |
|
|
PrefsAddString("disk", [[oP filename] cString]); |
200 |
|
|
[diskImages reloadData]; |
201 |
|
|
edited = YES; |
202 |
|
|
} |
203 |
|
|
} |
204 |
|
|
|
205 |
|
|
- (IBAction) BrowseExtFS: (id)sender |
206 |
|
|
{ |
207 |
|
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
208 |
|
|
|
209 |
|
|
[oP setCanChooseDirectories: YES]; |
210 |
|
|
[oP setCanChooseFiles: NO]; |
211 |
|
|
[oP setPrompt: @"Select"]; |
212 |
|
|
[oP setTitle: @"Select a directory to mount"]; |
213 |
|
|
D(NSLog(@"%s - home = %@, [extFS stringValue] = %@", |
214 |
|
|
__PRETTY_FUNCTION__, home, [extFS stringValue])); |
215 |
|
|
if ( [oP runModalForDirectory: ([extFS stringValue] ? [extFS stringValue] : home) |
216 |
|
|
file:nil |
217 |
|
|
types:nil] == NSOKButton ) |
218 |
|
|
{ |
219 |
|
|
[extFS setStringValue: [oP directory] ]; |
220 |
|
|
PrefsReplaceString("extfs", [[oP directory] cString]); |
221 |
|
|
edited = YES; |
222 |
|
|
} |
223 |
|
|
} |
224 |
|
|
|
225 |
nigel |
1.10 |
- (IBAction) BrowsePrefs: (id)sender |
226 |
|
|
{ |
227 |
|
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
228 |
|
|
|
229 |
|
|
[oP setCanChooseFiles: YES]; |
230 |
|
|
[oP setTitle: @"Select a Preferences file"]; |
231 |
|
|
D(NSLog(@"%s - home = %@", __PRETTY_FUNCTION__, home)); |
232 |
|
|
if ( [oP runModalForDirectory: ([prefsFile stringValue] ? [prefsFile stringValue] : home) |
233 |
|
|
file:nil |
234 |
|
|
types:nil] == NSOKButton ) |
235 |
|
|
{ |
236 |
|
|
[prefsFile setStringValue: [oP filename] ]; |
237 |
|
|
UserPrefsPath = [[oP filename] cString]; |
238 |
|
|
} |
239 |
|
|
} |
240 |
|
|
|
241 |
nigel |
1.1 |
- (IBAction) BrowseROM: (id)sender |
242 |
|
|
{ |
243 |
|
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
244 |
|
|
|
245 |
|
|
[oP setCanChooseFiles: YES]; |
246 |
|
|
[oP setTitle: @"Open a ROM file"]; |
247 |
|
|
D(NSLog(@"%s - home = %@", __PRETTY_FUNCTION__, home)); |
248 |
|
|
if ( [oP runModalForDirectory: ([ROMfile stringValue] ? [ROMfile stringValue] : home) |
249 |
|
|
file:nil |
250 |
|
|
types:nil] == NSOKButton ) |
251 |
|
|
{ |
252 |
|
|
[ROMfile setStringValue: [oP filename] ]; |
253 |
|
|
PrefsReplaceString("rom", [[oP filename] cString]); |
254 |
|
|
edited = YES; |
255 |
|
|
} |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
#include <cdrom.h> // for CDROMRefNum |
259 |
|
|
|
260 |
|
|
- (IBAction) ChangeBootFrom: (NSMatrix *)sender |
261 |
|
|
{ |
262 |
|
|
if ( [sender selectedCell] == bootFromCD ) |
263 |
|
|
PrefsReplaceInt32("bootdriver", CDROMRefNum); |
264 |
|
|
else |
265 |
|
|
PrefsReplaceInt32("bootdriver", 0); |
266 |
|
|
edited = YES; |
267 |
|
|
} |
268 |
|
|
|
269 |
|
|
- (IBAction) ChangeCPU: (NSMatrix *)sender |
270 |
|
|
{ |
271 |
|
|
PrefsReplaceInt32("cpu", [[sender selectedCell] tag]); |
272 |
|
|
edited = YES; |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
- (IBAction) ChangeDisableCD: (NSButton *)sender |
276 |
|
|
{ |
277 |
|
|
PrefsReplaceBool("nocdrom", [disableCD state]); |
278 |
|
|
edited = YES; |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
- (IBAction) ChangeDisableSound: (NSButton *)sender |
282 |
|
|
{ |
283 |
nigel |
1.2 |
BOOL noSound = [disableSound state]; |
284 |
|
|
|
285 |
|
|
if ( ! noSound ) |
286 |
|
|
WarningSheet(@"Sound is currently unimplemented", panel); |
287 |
|
|
|
288 |
|
|
PrefsReplaceBool("nosound", noSound); |
289 |
nigel |
1.1 |
edited = YES; |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
- (IBAction) ChangeFPU: (NSButton *)sender |
293 |
|
|
{ |
294 |
|
|
PrefsReplaceBool("fpu", [FPU state]); |
295 |
|
|
edited = YES; |
296 |
|
|
} |
297 |
|
|
|
298 |
nigel |
1.11 |
- (IBAction) ChangeKeyboard: (NSPopUpButton *)sender |
299 |
|
|
{ |
300 |
|
|
// Deselest current item |
301 |
nigel |
1.12 |
int current = [keyboard indexOfItemWithTag: PrefsFindInt32("keyboardtype")]; |
302 |
|
|
if ( current != -1 ) |
303 |
nigel |
1.11 |
[[keyboard itemAtIndex: current] setState: FALSE]; |
304 |
|
|
|
305 |
|
|
PrefsReplaceInt32("keyboardtype", [[sender selectedItem] tag]); |
306 |
|
|
edited = YES; |
307 |
|
|
} |
308 |
|
|
|
309 |
nigel |
1.1 |
- (IBAction) ChangeModel: (NSMatrix *)sender |
310 |
|
|
{ |
311 |
|
|
PrefsReplaceInt32("modelid", [[sender selectedCell] tag]); |
312 |
|
|
edited = YES; |
313 |
|
|
} |
314 |
|
|
|
315 |
nigel |
1.7 |
|
316 |
|
|
// If we are not using the CGIMAGEREF drawing strategy, |
317 |
|
|
// then source bitmaps must be 32bits deep. |
318 |
|
|
|
319 |
|
|
- (short) testWinDepth: (int) newbpp |
320 |
|
|
{ |
321 |
|
|
#ifdef CGIMAGEREF |
322 |
|
|
return newbpp; |
323 |
|
|
#else |
324 |
|
|
if ( newbpp != 32 ) |
325 |
|
|
WarningSheet(@"Sorry - In windowed mode, depth must be 32", panel); |
326 |
|
|
return 32 |
327 |
|
|
#endif |
328 |
|
|
} |
329 |
|
|
|
330 |
nigel |
1.8 |
// This is called when the screen/window, |
331 |
nigel |
1.3 |
// width, height or depth is clicked. |
332 |
|
|
// |
333 |
|
|
// Note that sender may not actually be an NSMatrix. |
334 |
nigel |
1.1 |
|
335 |
nigel |
1.3 |
- (IBAction) ChangeScreen: (NSMatrix *)sender |
336 |
|
|
{ |
337 |
|
|
NSButton *cell = [sender selectedCell]; |
338 |
nigel |
1.1 |
|
339 |
|
|
short newx = [width intValue]; |
340 |
|
|
short newy = [height intValue]; |
341 |
|
|
short newbpp = [depth intValue]; |
342 |
nigel |
1.2 |
short newtype; |
343 |
nigel |
1.1 |
char str[20]; |
344 |
|
|
|
345 |
nigel |
1.8 |
if ( cell == screen ) |
346 |
nigel |
1.1 |
newtype = DISPLAY_SCREEN; |
347 |
nigel |
1.3 |
else if ( cell == window ) |
348 |
nigel |
1.2 |
newtype = DISPLAY_WINDOW; |
349 |
|
|
else |
350 |
|
|
newtype = display_type; |
351 |
nigel |
1.1 |
|
352 |
|
|
// Check that a field actually changed |
353 |
|
|
if ( newbpp == init_depth && newx == init_width && |
354 |
|
|
newy == init_height && newtype == display_type ) |
355 |
nigel |
1.2 |
{ |
356 |
nigel |
1.4 |
D(NSLog(@"No changed GUI items in ChangeScreen")); |
357 |
nigel |
1.1 |
return; |
358 |
nigel |
1.2 |
} |
359 |
nigel |
1.1 |
|
360 |
|
|
// If we are changing type, supply some sensible defaults |
361 |
nigel |
1.7 |
|
362 |
|
|
short screenx = CGDisplayPixelsWide(kCGDirectMainDisplay), |
363 |
|
|
screeny = CGDisplayPixelsHigh(kCGDirectMainDisplay), |
364 |
|
|
screenb = CGDisplayBitsPerPixel(kCGDirectMainDisplay); |
365 |
|
|
|
366 |
nigel |
1.1 |
if ( newtype != display_type ) |
367 |
|
|
{ |
368 |
nigel |
1.4 |
D(NSLog(@"Changing display type in ChangeScreen")); |
369 |
nigel |
1.1 |
|
370 |
nigel |
1.7 |
// If changing to full screen, supply main screen dimensions as a default |
371 |
|
|
if ( newtype == DISPLAY_SCREEN ) |
372 |
|
|
newx = screenx, newy = screeny, newbpp = screenb; |
373 |
|
|
|
374 |
|
|
// If changing from full screen, use minimum screen resolutions |
375 |
|
|
if ( display_type == DISPLAY_SCREEN ) |
376 |
nigel |
1.6 |
{ |
377 |
nigel |
1.1 |
newx = MIN_WIDTH, newy = MIN_HEIGHT; |
378 |
nigel |
1.7 |
newbpp = [self testWinDepth: newbpp]; |
379 |
nigel |
1.6 |
} |
380 |
nigel |
1.1 |
} |
381 |
|
|
else |
382 |
|
|
{ |
383 |
nigel |
1.7 |
newbpp = [self testWinDepth: newbpp]; |
384 |
nigel |
1.6 |
|
385 |
nigel |
1.1 |
// Check size is within ranges of MIN_WIDTH ... MAX_WIDTH |
386 |
|
|
// and MIN_HEIGHT ... MAX_HEIGHT |
387 |
|
|
// ??? |
388 |
|
|
} |
389 |
nigel |
1.7 |
|
390 |
|
|
[width setIntValue: newx]; |
391 |
|
|
[height setIntValue: newy]; |
392 |
|
|
[depth setIntValue: newbpp]; |
393 |
nigel |
1.1 |
|
394 |
|
|
|
395 |
|
|
// Store new prefs |
396 |
|
|
*str = '\0'; |
397 |
|
|
switch ( newtype ) |
398 |
|
|
{ |
399 |
|
|
case DISPLAY_WINDOW: |
400 |
|
|
if ( newbpp ) |
401 |
|
|
sprintf(str, "win/%hd/%hd/%hd", newx, newy, newbpp); |
402 |
|
|
else |
403 |
|
|
sprintf(str, "win/%hd/%hd", newx, newy); |
404 |
|
|
break; |
405 |
|
|
case DISPLAY_SCREEN: |
406 |
|
|
if ( newbpp ) |
407 |
|
|
sprintf(str, "full/%hd/%hd/%hd", newx, newy, newbpp); |
408 |
|
|
else |
409 |
|
|
sprintf(str, "full/%hd/%hd", newx, newy); |
410 |
|
|
break; |
411 |
|
|
}; |
412 |
|
|
PrefsReplaceString("screen", str); |
413 |
|
|
|
414 |
|
|
parse_screen_prefs(str); |
415 |
|
|
|
416 |
|
|
edited = YES; |
417 |
|
|
|
418 |
|
|
if ( display_type != DISPLAY_SCREEN ) |
419 |
nigel |
1.2 |
{ |
420 |
nigel |
1.4 |
D(NSLog(@"Display type is not SCREEN (%d), resizing window", |
421 |
|
|
display_type)); |
422 |
nigel |
1.1 |
resizeWinTo(newx, newy); |
423 |
nigel |
1.2 |
} |
424 |
nigel |
1.1 |
} |
425 |
|
|
|
426 |
|
|
- (IBAction) CreateVolume: (id)sender |
427 |
|
|
{ |
428 |
|
|
NSSavePanel *sP = [NSSavePanel savePanel]; |
429 |
|
|
|
430 |
|
|
[sP setAccessoryView: newVolumeView]; |
431 |
|
|
[sP setPrompt: @"Create"]; |
432 |
|
|
[sP setTitle: @"Create new volume as"]; |
433 |
|
|
|
434 |
|
|
if ( [sP runModalForDirectory:NSHomeDirectory() file:@"basilisk-II.vol"] == NSOKButton ) |
435 |
|
|
{ |
436 |
|
|
char cmd[1024]; |
437 |
|
|
const char *filename = [[sP filename] cString]; |
438 |
|
|
int retVal, |
439 |
|
|
size = [newVolumeSize intValue]; |
440 |
|
|
|
441 |
|
|
sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", filename, size); |
442 |
|
|
retVal = system(cmd); |
443 |
|
|
if (retVal != 0) |
444 |
|
|
{ |
445 |
|
|
NSString *details = [NSString stringWithFormat: |
446 |
|
|
@"The dd command failed.\nReturn status %d (%s)", |
447 |
|
|
retVal, strerror(errno)]; |
448 |
nigel |
1.2 |
WarningSheet(@"Unable to create volume", details, nil, panel); |
449 |
nigel |
1.1 |
} |
450 |
|
|
else |
451 |
|
|
{ |
452 |
|
|
[volsDS addObject: (NSObject *) blank |
453 |
|
|
withPath: [sP filename] ]; |
454 |
|
|
PrefsAddString("disk", filename); |
455 |
|
|
[diskImages reloadData]; |
456 |
|
|
} |
457 |
|
|
} |
458 |
|
|
} |
459 |
|
|
|
460 |
nigel |
1.5 |
- (BOOL) fileManager: (NSFileManager *) manager |
461 |
|
|
shouldProceedAfterError: (NSDictionary *) errorDict |
462 |
|
|
{ |
463 |
|
|
NSRunAlertPanel(@"File operation error", |
464 |
|
|
@"%@ %@, toPath %@", |
465 |
|
|
@"Bugger!", nil, nil, |
466 |
|
|
[errorDict objectForKey:@"Error"], |
467 |
|
|
[errorDict objectForKey:@"Path"], |
468 |
|
|
[errorDict objectForKey:@"ToPath"]); |
469 |
|
|
return NO; |
470 |
|
|
} |
471 |
|
|
|
472 |
nigel |
1.1 |
- (IBAction) DeleteVolume: (id)sender |
473 |
|
|
{ |
474 |
nigel |
1.5 |
// const char *path = [self RemoveVolumeEntry]; |
475 |
|
|
// if ( unlink(path) == -1 ) |
476 |
|
|
NSString *Path = [self RemoveVolumeEntry]; |
477 |
|
|
|
478 |
|
|
if ( ! [[NSFileManager defaultManager] removeFileAtPath: Path |
479 |
|
|
handler: self] ) |
480 |
nigel |
1.1 |
{ |
481 |
nigel |
1.5 |
WarningSheet(@"Unable to delete volume", panel); |
482 |
|
|
// NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, path, strerror(errno)); |
483 |
nigel |
1.1 |
} |
484 |
|
|
} |
485 |
|
|
|
486 |
|
|
- (IBAction) EditDelay: (NSTextField *)sender |
487 |
|
|
{ |
488 |
|
|
int ticks = [delay intValue]; |
489 |
|
|
float freq; |
490 |
|
|
|
491 |
|
|
if ( ticks ) |
492 |
|
|
freq = 60.0 / ticks; |
493 |
|
|
else |
494 |
|
|
freq = 60.0; |
495 |
|
|
|
496 |
|
|
[frequency setFloatValue: freq]; |
497 |
|
|
[emuFreq setFloatValue: freq]; |
498 |
|
|
PrefsReplaceInt32("frameskip", ticks); |
499 |
|
|
edited = YES; |
500 |
|
|
} |
501 |
|
|
|
502 |
|
|
- (IBAction) EditBytes: (NSTextField *)sender |
503 |
|
|
{ |
504 |
|
|
int B = (int) [bytes floatValue]; |
505 |
|
|
float M = B / 1024 / 1024; |
506 |
|
|
|
507 |
nigel |
1.2 |
D(NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B)); |
508 |
nigel |
1.1 |
PrefsReplaceInt32("ramsize", B); |
509 |
|
|
[MB setFloatValue: M]; |
510 |
|
|
edited = YES; |
511 |
|
|
} |
512 |
|
|
|
513 |
|
|
- (IBAction) EditEtherNetDevice: (NSTextField *)sender |
514 |
|
|
{ |
515 |
|
|
NSString *path = [etherNet stringValue]; |
516 |
|
|
|
517 |
|
|
PrefsReplaceString("ether", [path cString]); |
518 |
|
|
edited = YES; |
519 |
|
|
} |
520 |
|
|
|
521 |
|
|
- (IBAction) EditExtFS: (NSTextField *)sender |
522 |
|
|
{ |
523 |
|
|
NSString *path = [extFS stringValue]; |
524 |
|
|
|
525 |
|
|
PrefsReplaceString("extfs", [path cString]); |
526 |
|
|
edited = YES; |
527 |
|
|
} |
528 |
|
|
|
529 |
|
|
- (IBAction) EditFrequency: (NSTextField *)sender |
530 |
|
|
{ |
531 |
|
|
float freq = [frequency floatValue]; |
532 |
|
|
|
533 |
|
|
[delay setIntValue: frequencyToTickDelay(freq)]; |
534 |
|
|
[emuFreq setFloatValue: freq]; |
535 |
|
|
edited = YES; |
536 |
|
|
} |
537 |
|
|
|
538 |
|
|
- (IBAction) EditModemDevice: (NSTextField *)sender |
539 |
|
|
{ |
540 |
|
|
NSString *path = [modem stringValue]; |
541 |
|
|
|
542 |
|
|
PrefsReplaceString("seriala", [path cString]); |
543 |
|
|
edited = YES; |
544 |
|
|
} |
545 |
|
|
|
546 |
|
|
- (IBAction) EditMB: (NSTextField *)sender |
547 |
|
|
{ |
548 |
|
|
float M = [MB floatValue]; |
549 |
|
|
int B = (int) (M * 1024 * 1024); |
550 |
|
|
|
551 |
nigel |
1.2 |
D(NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B)); |
552 |
nigel |
1.1 |
PrefsReplaceInt32("ramsize", B); |
553 |
|
|
[bytes setIntValue: B]; |
554 |
|
|
edited = YES; |
555 |
|
|
} |
556 |
|
|
|
557 |
|
|
- (IBAction) EditPrinterDevice: (NSTextField *)sender |
558 |
|
|
{ |
559 |
|
|
NSString *path = [printer stringValue]; |
560 |
|
|
|
561 |
|
|
PrefsReplaceString("serialb", [path cString]); |
562 |
|
|
edited = YES; |
563 |
|
|
} |
564 |
|
|
|
565 |
|
|
- (IBAction) EditROMpath: (NSTextField *)sender |
566 |
|
|
{ |
567 |
|
|
NSString *path = [ROMfile stringValue]; |
568 |
|
|
|
569 |
|
|
PrefsReplaceString("rom", [path cString]); |
570 |
|
|
} |
571 |
|
|
|
572 |
|
|
- (IBAction) RemoveSCSI: (id)sender |
573 |
|
|
{ |
574 |
|
|
char pref[6]; |
575 |
|
|
int row = [SCSIdisks selectedRow], |
576 |
|
|
SCSIid = [SCSIds intAtRow: row]; |
577 |
|
|
|
578 |
|
|
if ( ! [SCSIds deleteRow: row] ) |
579 |
|
|
NSLog (@"%s - [SCSIds deleteRow: %d] failed", __PRETTY_FUNCTION__, row); |
580 |
|
|
[SCSIdisks reloadData]; |
581 |
|
|
sprintf(pref, "scsi%d", SCSIid); |
582 |
|
|
PrefsRemoveItem(pref,0); |
583 |
|
|
} |
584 |
|
|
|
585 |
nigel |
1.5 |
//- (const char *) RemoveVolumeEntry |
586 |
|
|
- (NSString *) RemoveVolumeEntry |
587 |
nigel |
1.1 |
{ |
588 |
|
|
int row = [diskImages selectedRow]; |
589 |
|
|
|
590 |
|
|
if ( row != -1 ) |
591 |
|
|
{ |
592 |
nigel |
1.5 |
NSString *Path = [volsDS pathAtRow: row]; |
593 |
|
|
const char *path = [Path cString], |
594 |
nigel |
1.1 |
*str; |
595 |
|
|
int tmp = 0; |
596 |
|
|
|
597 |
|
|
while ( (str = PrefsFindString("disk", tmp) ) != NULL ) |
598 |
|
|
{ |
599 |
|
|
if ( strcmp(str, path) == 0 ) |
600 |
|
|
{ |
601 |
|
|
PrefsRemoveItem("disk", tmp); |
602 |
nigel |
1.4 |
D(NSLog(@"%s - Deleted prefs entry \"disk\", %d", |
603 |
|
|
__PRETTY_FUNCTION__, tmp)); |
604 |
nigel |
1.1 |
edited = YES; |
605 |
|
|
break; |
606 |
|
|
} |
607 |
|
|
++tmp; |
608 |
|
|
} |
609 |
|
|
|
610 |
|
|
if ( str == NULL ) |
611 |
|
|
{ |
612 |
nigel |
1.4 |
NSLog(@"%s - Couldn't find any disk preference to match %s", |
613 |
|
|
__PRETTY_FUNCTION__, path); |
614 |
nigel |
1.1 |
return NULL; |
615 |
|
|
} |
616 |
|
|
|
617 |
|
|
if ( ! [volsDS deleteRow: row] ) |
618 |
|
|
NSLog (@"%s - RemoveVolume %d failed", __PRETTY_FUNCTION__, tmp); |
619 |
|
|
[diskImages reloadData]; |
620 |
nigel |
1.5 |
// return path; |
621 |
|
|
return Path; |
622 |
nigel |
1.1 |
} |
623 |
|
|
else |
624 |
|
|
{ |
625 |
nigel |
1.2 |
WarningSheet(@"Please select a volume first", panel); |
626 |
nigel |
1.1 |
return NULL; |
627 |
|
|
} |
628 |
|
|
} |
629 |
|
|
|
630 |
|
|
- (IBAction) RemoveVolume: (id)sender |
631 |
|
|
{ |
632 |
|
|
[self RemoveVolumeEntry]; |
633 |
|
|
} |
634 |
|
|
|
635 |
nigel |
1.10 |
- (void) loadPrefs: (int) argc |
636 |
|
|
args: (char **) argv |
637 |
nigel |
1.1 |
{ |
638 |
|
|
[panel close]; // Temporarily hide preferences panel |
639 |
|
|
|
640 |
|
|
PrefsExit(); // Purge all the old pref values |
641 |
|
|
|
642 |
|
|
PrefsInit(argc, argv); |
643 |
|
|
AddPrefsDefaults(); |
644 |
|
|
AddPlatformPrefsDefaults(); // and only create basic ones |
645 |
|
|
|
646 |
|
|
[SCSIds deleteAll]; // Clear out datasources for the tables |
647 |
|
|
[volsDS deleteAll]; |
648 |
|
|
|
649 |
|
|
[self ShowPrefs: self]; // Reset items in panel, and redisplay |
650 |
|
|
edited = NO; |
651 |
|
|
} |
652 |
|
|
|
653 |
nigel |
1.10 |
- (IBAction) LoadPrefs: (id)sender |
654 |
|
|
{ |
655 |
|
|
int argc = 2; |
656 |
|
|
char *argv[2]; |
657 |
|
|
|
658 |
|
|
argv[0] = "--prefs", |
659 |
|
|
argv[1] = (char *) [[prefsFile stringValue] cString]; |
660 |
|
|
|
661 |
|
|
[self loadPrefs: argc |
662 |
|
|
args: argv]; |
663 |
|
|
} |
664 |
|
|
|
665 |
|
|
- (IBAction) ResetPrefs: (id)sender |
666 |
|
|
{ |
667 |
|
|
[self loadPrefs: 0 |
668 |
|
|
args: NULL]; |
669 |
|
|
} |
670 |
|
|
|
671 |
nigel |
1.1 |
- (void) setStringOf: (NSTextField *) field |
672 |
|
|
fromPref: (const char *) prefName |
673 |
|
|
{ |
674 |
|
|
const char *value = PrefsFindString(prefName, 0); |
675 |
|
|
|
676 |
|
|
if ( value ) |
677 |
|
|
[field setStringValue: [NSString stringWithCString: value] ]; |
678 |
|
|
} |
679 |
|
|
|
680 |
|
|
- (IBAction) SavePrefs: (id)sender |
681 |
|
|
{ |
682 |
|
|
SavePrefs(); |
683 |
|
|
edited = NO; |
684 |
|
|
} |
685 |
|
|
|
686 |
|
|
- (IBAction) ShowPrefs: (id)sender |
687 |
|
|
{ |
688 |
|
|
NSTableColumn *locks; |
689 |
|
|
const char *str; |
690 |
nigel |
1.11 |
int cpu, tmp, val; |
691 |
nigel |
1.1 |
|
692 |
|
|
|
693 |
|
|
// Set simple single field items |
694 |
|
|
|
695 |
nigel |
1.11 |
val = PrefsFindInt32("frameskip"); |
696 |
|
|
[delay setIntValue: val]; |
697 |
|
|
if ( val ) |
698 |
|
|
[frequency setFloatValue: 60.0 / val]; |
699 |
nigel |
1.1 |
else |
700 |
|
|
[frequency setFloatValue: 60.0]; |
701 |
|
|
|
702 |
nigel |
1.11 |
val = PrefsFindInt32("ramsize"); |
703 |
|
|
[bytes setIntValue: val]; |
704 |
|
|
[MB setFloatValue: val / (1024.0 * 1024.0)]; |
705 |
nigel |
1.1 |
|
706 |
|
|
[disableCD setState: PrefsFindBool("nocdrom")]; |
707 |
|
|
[disableSound setState: PrefsFindBool("nosound")]; |
708 |
|
|
[FPU setState: PrefsFindBool("fpu") ]; |
709 |
|
|
|
710 |
|
|
[self setStringOf: etherNet fromPref: "ether" ]; |
711 |
|
|
[self setStringOf: extFS fromPref: "extfs" ]; |
712 |
|
|
[self setStringOf: modem fromPref: "seriala"]; |
713 |
|
|
[self setStringOf: printer fromPref: "serialb"]; |
714 |
|
|
[self setStringOf: ROMfile fromPref: "rom" ]; |
715 |
nigel |
1.10 |
|
716 |
|
|
[prefsFile setStringValue: [NSString stringWithCString: UserPrefsPath.c_str()] ]; |
717 |
nigel |
1.1 |
|
718 |
|
|
|
719 |
|
|
parse_screen_prefs(PrefsFindString("screen")); |
720 |
|
|
|
721 |
|
|
[width setIntValue: init_width]; |
722 |
|
|
[height setIntValue: init_height]; |
723 |
|
|
[depth setIntValue: init_depth]; |
724 |
|
|
|
725 |
nigel |
1.9 |
[screen setState: NO]; |
726 |
nigel |
1.1 |
switch ( display_type ) |
727 |
|
|
{ |
728 |
|
|
case DISPLAY_WINDOW: [window setState: YES]; break; |
729 |
|
|
case DISPLAY_SCREEN: [screen setState: YES]; break; |
730 |
|
|
} |
731 |
|
|
|
732 |
|
|
[newVolumeSize setIntValue: 10]; |
733 |
|
|
|
734 |
|
|
// Radio button groups: |
735 |
|
|
|
736 |
nigel |
1.11 |
val = PrefsFindInt32("bootdriver"); |
737 |
|
|
[bootFromAny setState: val != CDROMRefNum]; |
738 |
|
|
[bootFromCD setState: val == CDROMRefNum]; |
739 |
nigel |
1.1 |
|
740 |
|
|
cpu = PrefsFindInt32("cpu"); |
741 |
nigel |
1.11 |
val = PrefsFindInt32("modelid"); |
742 |
nigel |
1.1 |
|
743 |
|
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
744 |
|
|
puts("Current memory model does not support 24bit addressing"); |
745 |
nigel |
1.11 |
if ( val == [classic tag] ) |
746 |
nigel |
1.1 |
{ |
747 |
|
|
// Window already created by NIB file, just display |
748 |
|
|
[panel makeKeyAndOrderFront:self]; |
749 |
|
|
WarningSheet(@"Compiled-in memory model does not support 24bit", |
750 |
nigel |
1.2 |
@"Disabling Mac Classic emulation", nil, panel); |
751 |
nigel |
1.1 |
cpu = [CPU68030 tag]; |
752 |
|
|
PrefsReplaceInt32("cpu", cpu); |
753 |
nigel |
1.11 |
val = [IIci tag]; |
754 |
|
|
PrefsReplaceInt32("modelid", val); |
755 |
nigel |
1.1 |
} |
756 |
|
|
|
757 |
|
|
puts("Disabling 68000 & Mac Classic buttons"); |
758 |
|
|
[CPU68000 setEnabled:FALSE]; |
759 |
|
|
[classic setEnabled:FALSE]; |
760 |
|
|
#endif |
761 |
|
|
|
762 |
|
|
[CPU68000 setState: [CPU68000 tag] == cpu]; |
763 |
|
|
[CPU68020 setState: [CPU68020 tag] == cpu]; |
764 |
|
|
[CPU68030 setState: [CPU68030 tag] == cpu]; |
765 |
|
|
[CPU68040 setState: [CPU68040 tag] == cpu]; |
766 |
|
|
|
767 |
nigel |
1.11 |
[classic setState: [classic tag] == val]; |
768 |
|
|
[IIci setState: [IIci tag] == val]; |
769 |
|
|
[quadra900 setState: [quadra900 tag] == val]; |
770 |
nigel |
1.1 |
|
771 |
|
|
|
772 |
|
|
// Lists of thingies: |
773 |
nigel |
1.11 |
|
774 |
|
|
val = PrefsFindInt32("keyboardtype"); |
775 |
nigel |
1.12 |
tmp = [keyboard indexOfItemWithTag: val]; |
776 |
|
|
if ( tmp != -1 ) |
777 |
|
|
[keyboard selectItemAtIndex: tmp]; |
778 |
nigel |
1.11 |
for ( tmp = 0; tmp < [keyboard numberOfItems]; ++tmp ) |
779 |
|
|
{ |
780 |
|
|
NSMenuItem *type = [keyboard itemAtIndex: tmp]; |
781 |
|
|
[type setState: [type tag] == val]; |
782 |
|
|
} |
783 |
|
|
|
784 |
nigel |
1.1 |
|
785 |
|
|
for ( tmp = 0; tmp < 7; ++tmp) |
786 |
|
|
{ |
787 |
|
|
char pref[6]; |
788 |
|
|
|
789 |
|
|
pref[0] = '\0'; |
790 |
|
|
|
791 |
|
|
sprintf (pref, "scsi%d", tmp); |
792 |
|
|
if ( (str = PrefsFindString(pref, 0) ) ) |
793 |
|
|
[SCSIds addInt: tmp |
794 |
|
|
withPath: [NSString stringWithCString: str] ]; |
795 |
|
|
} |
796 |
|
|
|
797 |
|
|
[SCSIdisks setDataSource: SCSIds]; |
798 |
|
|
|
799 |
|
|
locks = [diskImages tableColumnWithIdentifier: @"locked"]; |
800 |
|
|
if ( locks == nil ) |
801 |
|
|
NSLog (@"%s - Can't find column for lock images", __PRETTY_FUNCTION__); |
802 |
|
|
[locks setDataCell: lockCell]; |
803 |
|
|
|
804 |
|
|
tmp = 0; |
805 |
|
|
while ( (str = PrefsFindString("disk", tmp++) ) != NULL ) |
806 |
|
|
{ |
807 |
|
|
if ( *str == '*' ) |
808 |
|
|
[volsDS addObject: (NSObject *) locked |
809 |
|
|
withPath: [NSString stringWithCString: str+1]]; |
810 |
|
|
else |
811 |
|
|
[volsDS addObject: (NSObject *) blank |
812 |
|
|
withPath: [NSString stringWithCString: str]]; |
813 |
|
|
} |
814 |
|
|
|
815 |
|
|
[diskImages setDataSource: volsDS]; |
816 |
|
|
|
817 |
|
|
|
818 |
|
|
[panel makeKeyAndOrderFront:self]; // Window already created by NIB file, just display |
819 |
|
|
} |
820 |
|
|
|
821 |
|
|
@end |