1 |
/* |
2 |
* PrefsEditor.m - GUI stuff for Basilisk II preferences |
3 |
* (which is a text file in the user's home directory) |
4 |
* |
5 |
* $Id: PrefsEditor.mm,v 1.14 2004/05/02 11:02:34 nigel Exp $ |
6 |
* |
7 |
* Basilisk II (C) 1997-2005 Christian Bauer |
8 |
* |
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 |
col1 = [NSMutableArray new]; |
34 |
col2 = [NSMutableArray new]; |
35 |
|
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 |
#include <string> |
113 |
using std::string; |
114 |
extern string UserPrefsPath; // from prefs_unix.cpp |
115 |
|
116 |
#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 |
#define DEBUG 0 |
123 |
#import <debug.h> |
124 |
|
125 |
- (PrefsEditor *) init |
126 |
{ |
127 |
self = [super init]; |
128 |
|
129 |
edited = NO; |
130 |
|
131 |
devs = @"/dev"; |
132 |
home = NSHomeDirectory(); |
133 |
volsDS = [TableDS new]; |
134 |
SCSIds = [TableDS new]; |
135 |
|
136 |
lockCell = [NSImageCell new]; |
137 |
if ( lockCell == nil ) |
138 |
NSLog (@"%s - Can't create NSImageCell?", __PRETTY_FUNCTION__); |
139 |
|
140 |
blank = [NSImage new]; |
141 |
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] UTF8String]); |
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] UTF8String]); |
221 |
edited = YES; |
222 |
} |
223 |
} |
224 |
|
225 |
- (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] UTF8String]; |
238 |
} |
239 |
} |
240 |
|
241 |
- (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] UTF8String]); |
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 |
BOOL noSound = [disableSound state]; |
284 |
|
285 |
if ( ! noSound ) |
286 |
WarningSheet(@"Sound is currently unimplemented", panel); |
287 |
|
288 |
PrefsReplaceBool("nosound", noSound); |
289 |
edited = YES; |
290 |
} |
291 |
|
292 |
- (IBAction) ChangeFPU: (NSButton *)sender |
293 |
{ |
294 |
PrefsReplaceBool("fpu", [FPU state]); |
295 |
edited = YES; |
296 |
} |
297 |
|
298 |
- (IBAction) ChangeKeyboard: (NSPopUpButton *)sender |
299 |
{ |
300 |
// Deselest current item |
301 |
int current = [keyboard indexOfItemWithTag: PrefsFindInt32("keyboardtype")]; |
302 |
if ( current != -1 ) |
303 |
[[keyboard itemAtIndex: current] setState: FALSE]; |
304 |
|
305 |
PrefsReplaceInt32("keyboardtype", [[sender selectedItem] tag]); |
306 |
edited = YES; |
307 |
} |
308 |
|
309 |
- (IBAction) ChangeModel: (NSMatrix *)sender |
310 |
{ |
311 |
PrefsReplaceInt32("modelid", [[sender selectedCell] tag]); |
312 |
edited = YES; |
313 |
} |
314 |
|
315 |
|
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 |
// This is called when the screen/window, |
331 |
// width, height or depth is clicked. |
332 |
// |
333 |
// Note that sender may not actually be an NSMatrix. |
334 |
|
335 |
- (IBAction) ChangeScreen: (NSMatrix *)sender |
336 |
{ |
337 |
NSButton *cell = [sender selectedCell]; |
338 |
|
339 |
short newx = [width intValue]; |
340 |
short newy = [height intValue]; |
341 |
short newbpp = [depth intValue]; |
342 |
short newtype; |
343 |
char str[20]; |
344 |
|
345 |
if ( cell == screen ) |
346 |
newtype = DISPLAY_SCREEN; |
347 |
else if ( cell == window ) |
348 |
newtype = DISPLAY_WINDOW; |
349 |
else |
350 |
newtype = display_type; |
351 |
|
352 |
// Check that a field actually changed |
353 |
if ( newbpp == init_depth && newx == init_width && |
354 |
newy == init_height && newtype == display_type ) |
355 |
{ |
356 |
D(NSLog(@"No changed GUI items in ChangeScreen")); |
357 |
return; |
358 |
} |
359 |
|
360 |
// If we are changing type, supply some sensible defaults |
361 |
|
362 |
short screenx = CGDisplayPixelsWide(kCGDirectMainDisplay), |
363 |
screeny = CGDisplayPixelsHigh(kCGDirectMainDisplay), |
364 |
screenb = CGDisplayBitsPerPixel(kCGDirectMainDisplay); |
365 |
|
366 |
if ( newtype != display_type ) |
367 |
{ |
368 |
D(NSLog(@"Changing display type in ChangeScreen")); |
369 |
|
370 |
// 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 |
{ |
377 |
newx = MIN_WIDTH, newy = MIN_HEIGHT; |
378 |
newbpp = [self testWinDepth: newbpp]; |
379 |
} |
380 |
} |
381 |
else |
382 |
{ |
383 |
newbpp = [self testWinDepth: newbpp]; |
384 |
|
385 |
// Check size is within ranges of MIN_WIDTH ... MAX_WIDTH |
386 |
// and MIN_HEIGHT ... MAX_HEIGHT |
387 |
// ??? |
388 |
} |
389 |
|
390 |
[width setIntValue: newx]; |
391 |
[height setIntValue: newy]; |
392 |
[depth setIntValue: newbpp]; |
393 |
|
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 |
{ |
420 |
D(NSLog(@"Display type is not SCREEN (%d), resizing window", |
421 |
display_type)); |
422 |
resizeWinTo(newx, newy); |
423 |
} |
424 |
} |
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] UTF8String]; |
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 |
WarningSheet(@"Unable to create volume", details, nil, panel); |
449 |
} |
450 |
else |
451 |
{ |
452 |
[volsDS addObject: (NSObject *) blank |
453 |
withPath: [sP filename] ]; |
454 |
PrefsAddString("disk", filename); |
455 |
[diskImages reloadData]; |
456 |
} |
457 |
} |
458 |
} |
459 |
|
460 |
- (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 |
- (IBAction) DeleteVolume: (id)sender |
473 |
{ |
474 |
NSString *Path = [self RemoveVolumeEntry]; |
475 |
|
476 |
if ( ! [[NSFileManager defaultManager] removeFileAtPath: Path |
477 |
handler: self] ) |
478 |
{ |
479 |
WarningSheet(@"Unable to delete volume", panel); |
480 |
NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, |
481 |
[Path cString], strerror(errno)); |
482 |
} |
483 |
} |
484 |
|
485 |
- (IBAction) EditDelay: (NSTextField *)sender |
486 |
{ |
487 |
int ticks = [delay intValue]; |
488 |
float freq; |
489 |
|
490 |
if ( ticks ) |
491 |
freq = 60.0 / ticks; |
492 |
else |
493 |
freq = 60.0; |
494 |
|
495 |
[frequency setFloatValue: freq]; |
496 |
[emuFreq setFloatValue: freq]; |
497 |
PrefsReplaceInt32("frameskip", ticks); |
498 |
edited = YES; |
499 |
} |
500 |
|
501 |
- (IBAction) EditBytes: (NSTextField *)sender |
502 |
{ |
503 |
int B = (int) [bytes floatValue]; |
504 |
float M = B / 1024 / 1024; |
505 |
|
506 |
D(NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B)); |
507 |
PrefsReplaceInt32("ramsize", B); |
508 |
[MB setFloatValue: M]; |
509 |
edited = YES; |
510 |
} |
511 |
|
512 |
- (IBAction) EditEtherNetDevice: (NSTextField *)sender |
513 |
{ |
514 |
NSString *path = [etherNet stringValue]; |
515 |
|
516 |
PrefsReplaceString("ether", [path UTF8String]); |
517 |
edited = YES; |
518 |
} |
519 |
|
520 |
- (IBAction) EditExtFS: (NSTextField *)sender |
521 |
{ |
522 |
NSString *path = [extFS stringValue]; |
523 |
|
524 |
PrefsReplaceString("extfs", [path UTF8String]); |
525 |
edited = YES; |
526 |
} |
527 |
|
528 |
- (IBAction) EditFrequency: (NSTextField *)sender |
529 |
{ |
530 |
float freq = [frequency floatValue]; |
531 |
|
532 |
[delay setIntValue: frequencyToTickDelay(freq)]; |
533 |
[emuFreq setFloatValue: freq]; |
534 |
edited = YES; |
535 |
} |
536 |
|
537 |
- (IBAction) EditModemDevice: (NSTextField *)sender |
538 |
{ |
539 |
NSString *path = [modem stringValue]; |
540 |
|
541 |
PrefsReplaceString("seriala", [path UTF8String]); |
542 |
edited = YES; |
543 |
} |
544 |
|
545 |
- (IBAction) EditMB: (NSTextField *)sender |
546 |
{ |
547 |
float M = [MB floatValue]; |
548 |
int B = (int) (M * 1024 * 1024); |
549 |
|
550 |
D(NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B)); |
551 |
PrefsReplaceInt32("ramsize", B); |
552 |
[bytes setIntValue: B]; |
553 |
edited = YES; |
554 |
} |
555 |
|
556 |
- (IBAction) EditPrinterDevice: (NSTextField *)sender |
557 |
{ |
558 |
NSString *path = [printer stringValue]; |
559 |
|
560 |
PrefsReplaceString("serialb", [path UTF8String]); |
561 |
edited = YES; |
562 |
} |
563 |
|
564 |
- (IBAction) EditROMpath: (NSTextField *)sender |
565 |
{ |
566 |
NSString *path = [ROMfile stringValue]; |
567 |
|
568 |
PrefsReplaceString("rom", [path UTF8String]); |
569 |
} |
570 |
|
571 |
- (IBAction) RemoveSCSI: (id)sender |
572 |
{ |
573 |
char pref[6]; |
574 |
int row = [SCSIdisks selectedRow], |
575 |
SCSIid = [SCSIds intAtRow: row]; |
576 |
|
577 |
if ( ! [SCSIds deleteRow: row] ) |
578 |
NSLog (@"%s - [SCSIds deleteRow: %d] failed", __PRETTY_FUNCTION__, row); |
579 |
[SCSIdisks reloadData]; |
580 |
sprintf(pref, "scsi%d", SCSIid); |
581 |
//PrefsRemoveItem(pref,0); |
582 |
PrefsRemoveItem(pref, 1); |
583 |
} |
584 |
|
585 |
//- (const char *) RemoveVolumeEntry |
586 |
- (NSString *) RemoveVolumeEntry |
587 |
{ |
588 |
int row = [diskImages selectedRow]; |
589 |
|
590 |
if ( row != -1 ) |
591 |
{ |
592 |
NSString *Path = [volsDS pathAtRow: row]; |
593 |
const char *path = [Path UTF8String], |
594 |
*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 |
D(NSLog(@"%s - Deleted prefs entry \"disk\", %d", |
603 |
__PRETTY_FUNCTION__, tmp)); |
604 |
edited = YES; |
605 |
break; |
606 |
} |
607 |
++tmp; |
608 |
} |
609 |
|
610 |
if ( str == NULL ) |
611 |
{ |
612 |
NSLog(@"%s - Couldn't find any disk preference to match %s", |
613 |
__PRETTY_FUNCTION__, path); |
614 |
return NULL; |
615 |
} |
616 |
|
617 |
if ( ! [volsDS deleteRow: row] ) |
618 |
NSLog (@"%s - RemoveVolume %d failed", __PRETTY_FUNCTION__, tmp); |
619 |
[diskImages reloadData]; |
620 |
// return path; |
621 |
return Path; |
622 |
} |
623 |
else |
624 |
{ |
625 |
WarningSheet(@"Please select a volume first", panel); |
626 |
return NULL; |
627 |
} |
628 |
} |
629 |
|
630 |
- (IBAction) RemoveVolume: (id)sender |
631 |
{ |
632 |
[self RemoveVolumeEntry]; |
633 |
} |
634 |
|
635 |
- (void) loadPrefs: (int) argc |
636 |
args: (char **) argv |
637 |
{ |
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 |
- (IBAction) LoadPrefs: (id)sender |
654 |
{ |
655 |
int argc = 2; |
656 |
char *argv[2]; |
657 |
|
658 |
argv[0] = "--prefs", |
659 |
argv[1] = (char *) [[prefsFile stringValue] UTF8String]; |
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 |
- (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 stringWithUTF8String: 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 |
int cpu, tmp, val; |
691 |
|
692 |
|
693 |
// Set simple single field items |
694 |
|
695 |
val = PrefsFindInt32("frameskip"); |
696 |
[delay setIntValue: val]; |
697 |
if ( val ) |
698 |
[frequency setFloatValue: 60.0 / val]; |
699 |
else |
700 |
[frequency setFloatValue: 60.0]; |
701 |
|
702 |
val = PrefsFindInt32("ramsize"); |
703 |
[bytes setIntValue: val]; |
704 |
[MB setFloatValue: val / (1024.0 * 1024.0)]; |
705 |
|
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 |
|
716 |
[prefsFile setStringValue: [NSString stringWithUTF8String: UserPrefsPath.c_str()] ]; |
717 |
|
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 |
[screen setState: NO]; |
726 |
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 |
val = PrefsFindInt32("bootdriver"); |
737 |
[bootFromAny setState: val != CDROMRefNum]; |
738 |
[bootFromCD setState: val == CDROMRefNum]; |
739 |
|
740 |
cpu = PrefsFindInt32("cpu"); |
741 |
val = PrefsFindInt32("modelid"); |
742 |
|
743 |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
744 |
puts("Current memory model does not support 24bit addressing"); |
745 |
if ( val == [classic tag] ) |
746 |
{ |
747 |
// Window already created by NIB file, just display |
748 |
[panel makeKeyAndOrderFront:self]; |
749 |
WarningSheet(@"Compiled-in memory model does not support 24bit", |
750 |
@"Disabling Mac Classic emulation", nil, panel); |
751 |
cpu = [CPU68030 tag]; |
752 |
PrefsReplaceInt32("cpu", cpu); |
753 |
val = [IIci tag]; |
754 |
PrefsReplaceInt32("modelid", val); |
755 |
} |
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 |
[classic setState: [classic tag] == val]; |
768 |
[IIci setState: [IIci tag] == val]; |
769 |
[quadra900 setState: [quadra900 tag] == val]; |
770 |
|
771 |
|
772 |
// Lists of thingies: |
773 |
|
774 |
val = PrefsFindInt32("keyboardtype"); |
775 |
tmp = [keyboard indexOfItemWithTag: val]; |
776 |
if ( tmp != -1 ) |
777 |
[keyboard selectItemAtIndex: tmp]; |
778 |
for ( tmp = 0; tmp < [keyboard numberOfItems]; ++tmp ) |
779 |
{ |
780 |
NSMenuItem *type = [keyboard itemAtIndex: tmp]; |
781 |
[type setState: [type tag] == val]; |
782 |
} |
783 |
|
784 |
|
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 stringWithUTF8String: str+1]]; |
810 |
else |
811 |
[volsDS addObject: (NSObject *) blank |
812 |
withPath: [NSString stringWithUTF8String: 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 |