ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/PrefsEditor.mm
Revision: 1.20
Committed: 2008-01-01T09:40:32Z (16 years, 5 months ago) by gbeauche
Branch: MAIN
Changes since 1.19: +2 -2 lines
Log Message:
Happy New Year!

File Contents

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