4 |
|
* |
5 |
|
* $Id$ |
6 |
|
* |
7 |
< |
* Basilisk II (C) 1997-2003 Christian Bauer |
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 |
105 |
|
|
106 |
|
@end |
107 |
|
|
108 |
– |
@implementation PrefsEditor |
109 |
– |
|
108 |
|
#import <AppKit/NSImage.h> // For [NSBundle pathForImageResource:] proto |
109 |
|
|
110 |
+ |
#include <string> |
111 |
+ |
using std::string; |
112 |
+ |
extern string UserPrefsPath; // from prefs_unix.cpp |
113 |
+ |
|
114 |
|
#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 |
+ |
#import "main_macosx.h" // ChoiceAlert() prototype |
118 |
+ |
|
119 |
|
|
120 |
|
#import <prefs.h> |
121 |
|
|
122 |
|
#define DEBUG 0 |
123 |
|
#import <debug.h> |
124 |
|
|
125 |
+ |
@implementation PrefsEditor |
126 |
+ |
|
127 |
|
- (PrefsEditor *) init |
128 |
|
{ |
129 |
|
self = [super init]; |
198 |
|
{ |
199 |
|
[volsDS addObject: (NSObject *) locked |
200 |
|
withPath: [oP filename] ]; |
201 |
< |
PrefsAddString("disk", [[oP filename] cString]); |
201 |
> |
PrefsAddString("disk", [[oP filename] UTF8String]); |
202 |
|
[diskImages reloadData]; |
203 |
|
edited = YES; |
204 |
|
} |
219 |
|
types:nil] == NSOKButton ) |
220 |
|
{ |
221 |
|
[extFS setStringValue: [oP directory] ]; |
222 |
< |
PrefsReplaceString("extfs", [[oP directory] cString]); |
222 |
> |
PrefsReplaceString("extfs", [[oP directory] UTF8String]); |
223 |
|
edited = YES; |
224 |
|
} |
225 |
|
} |
226 |
|
|
227 |
+ |
- (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 |
+ |
UserPrefsPath = [[oP filename] UTF8String]; |
240 |
+ |
} |
241 |
+ |
} |
242 |
+ |
|
243 |
|
- (IBAction) BrowseROM: (id)sender |
244 |
|
{ |
245 |
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
252 |
|
types:nil] == NSOKButton ) |
253 |
|
{ |
254 |
|
[ROMfile setStringValue: [oP filename] ]; |
255 |
< |
PrefsReplaceString("rom", [[oP filename] cString]); |
255 |
> |
PrefsReplaceString("rom", [[oP filename] UTF8String]); |
256 |
|
edited = YES; |
257 |
|
} |
258 |
|
} |
261 |
|
|
262 |
|
- (IBAction) ChangeBootFrom: (NSMatrix *)sender |
263 |
|
{ |
264 |
< |
if ( [sender selectedCell] == bootFromCD ) |
264 |
> |
if ( [sender selectedCell] == (id)bootFromCD ) |
265 |
|
PrefsReplaceInt32("bootdriver", CDROMRefNum); |
266 |
|
else |
267 |
|
PrefsReplaceInt32("bootdriver", 0); |
297 |
|
edited = YES; |
298 |
|
} |
299 |
|
|
300 |
+ |
- (IBAction) ChangeKeyboard: (NSPopUpButton *)sender |
301 |
+ |
{ |
302 |
+ |
// Deselest current item |
303 |
+ |
int current = [keyboard indexOfItemWithTag: PrefsFindInt32("keyboardtype")]; |
304 |
+ |
if ( current != -1 ) |
305 |
+ |
[[keyboard itemAtIndex: current] setState: FALSE]; |
306 |
+ |
|
307 |
+ |
PrefsReplaceInt32("keyboardtype", [[sender selectedItem] tag]); |
308 |
+ |
edited = YES; |
309 |
+ |
} |
310 |
+ |
|
311 |
|
- (IBAction) ChangeModel: (NSMatrix *)sender |
312 |
|
{ |
313 |
|
PrefsReplaceInt32("modelid", [[sender selectedCell] tag]); |
329 |
|
#endif |
330 |
|
} |
331 |
|
|
332 |
< |
// This is called when any of the screen/openGL/window, |
332 |
> |
// This is called when the screen/window, |
333 |
|
// width, height or depth is clicked. |
334 |
|
// |
335 |
|
// Note that sender may not actually be an NSMatrix. |
344 |
|
short newtype; |
345 |
|
char str[20]; |
346 |
|
|
347 |
< |
if ( cell == openGL ) |
315 |
< |
newtype = DISPLAY_OPENGL; |
316 |
< |
else if ( cell == screen ) |
347 |
> |
if ( cell == screen ) |
348 |
|
newtype = DISPLAY_SCREEN; |
349 |
|
else if ( cell == window ) |
350 |
|
newtype = DISPLAY_WINDOW; |
404 |
|
else |
405 |
|
sprintf(str, "win/%hd/%hd", newx, newy); |
406 |
|
break; |
376 |
– |
case DISPLAY_OPENGL: |
377 |
– |
if ( newbpp ) |
378 |
– |
sprintf(str, "opengl/%hd/%hd/%hd", newx, newy, newbpp); |
379 |
– |
else |
380 |
– |
sprintf(str, "opengl/%hd/%hd", newx, newy); |
381 |
– |
break; |
407 |
|
case DISPLAY_SCREEN: |
408 |
|
if ( newbpp ) |
409 |
|
sprintf(str, "full/%hd/%hd/%hd", newx, newy, newbpp); |
436 |
|
if ( [sP runModalForDirectory:NSHomeDirectory() file:@"basilisk-II.vol"] == NSOKButton ) |
437 |
|
{ |
438 |
|
char cmd[1024]; |
439 |
< |
const char *filename = [[sP filename] cString]; |
439 |
> |
const char *filename = [[sP filename] UTF8String]; |
440 |
|
int retVal, |
441 |
|
size = [newVolumeSize intValue]; |
442 |
|
|
443 |
|
sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", filename, size); |
444 |
+ |
|
445 |
|
retVal = system(cmd); |
446 |
|
if (retVal != 0) |
447 |
|
{ |
474 |
|
|
475 |
|
- (IBAction) DeleteVolume: (id)sender |
476 |
|
{ |
451 |
– |
// const char *path = [self RemoveVolumeEntry]; |
452 |
– |
// if ( unlink(path) == -1 ) |
477 |
|
NSString *Path = [self RemoveVolumeEntry]; |
478 |
|
|
479 |
+ |
if ( ! Path ) |
480 |
+ |
return; |
481 |
+ |
|
482 |
|
if ( ! [[NSFileManager defaultManager] removeFileAtPath: Path |
483 |
|
handler: self] ) |
484 |
|
{ |
485 |
|
WarningSheet(@"Unable to delete volume", panel); |
486 |
< |
// NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, path, strerror(errno)); |
486 |
> |
NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, |
487 |
> |
[Path cString], strerror(errno)); |
488 |
|
} |
489 |
|
} |
490 |
|
|
519 |
|
{ |
520 |
|
NSString *path = [etherNet stringValue]; |
521 |
|
|
522 |
< |
PrefsReplaceString("ether", [path cString]); |
522 |
> |
PrefsReplaceString("ether", [path UTF8String]); |
523 |
|
edited = YES; |
524 |
|
} |
525 |
|
|
527 |
|
{ |
528 |
|
NSString *path = [extFS stringValue]; |
529 |
|
|
530 |
< |
PrefsReplaceString("extfs", [path cString]); |
530 |
> |
PrefsReplaceString("extfs", [path UTF8String]); |
531 |
|
edited = YES; |
532 |
|
} |
533 |
|
|
544 |
|
{ |
545 |
|
NSString *path = [modem stringValue]; |
546 |
|
|
547 |
< |
PrefsReplaceString("seriala", [path cString]); |
547 |
> |
PrefsReplaceString("seriala", [path UTF8String]); |
548 |
|
edited = YES; |
549 |
|
} |
550 |
|
|
563 |
|
{ |
564 |
|
NSString *path = [printer stringValue]; |
565 |
|
|
566 |
< |
PrefsReplaceString("serialb", [path cString]); |
566 |
> |
PrefsReplaceString("serialb", [path UTF8String]); |
567 |
|
edited = YES; |
568 |
|
} |
569 |
|
|
571 |
|
{ |
572 |
|
NSString *path = [ROMfile stringValue]; |
573 |
|
|
574 |
< |
PrefsReplaceString("rom", [path cString]); |
574 |
> |
PrefsReplaceString("rom", [path UTF8String]); |
575 |
|
} |
576 |
|
|
577 |
|
- (IBAction) RemoveSCSI: (id)sender |
584 |
|
NSLog (@"%s - [SCSIds deleteRow: %d] failed", __PRETTY_FUNCTION__, row); |
585 |
|
[SCSIdisks reloadData]; |
586 |
|
sprintf(pref, "scsi%d", SCSIid); |
587 |
< |
PrefsRemoveItem(pref,0); |
587 |
> |
//PrefsRemoveItem(pref,0); |
588 |
> |
PrefsRemoveItem(pref, 1); |
589 |
|
} |
590 |
|
|
562 |
– |
//- (const char *) RemoveVolumeEntry |
591 |
|
- (NSString *) RemoveVolumeEntry |
592 |
|
{ |
593 |
|
int row = [diskImages selectedRow]; |
595 |
|
if ( row != -1 ) |
596 |
|
{ |
597 |
|
NSString *Path = [volsDS pathAtRow: row]; |
598 |
< |
const char *path = [Path cString], |
598 |
> |
const char *path = [Path UTF8String], |
599 |
|
*str; |
600 |
|
int tmp = 0; |
601 |
|
|
602 |
+ |
NSString *prompt = [NSString stringWithFormat: @"%s\n%s", |
603 |
+ |
"Are you sure you want to delete the file", |
604 |
+ |
path]; |
605 |
+ |
|
606 |
+ |
if ( ! ChoiceAlert([prompt cString], "Delete", "Cancel") ) |
607 |
+ |
return NULL; |
608 |
+ |
|
609 |
|
while ( (str = PrefsFindString("disk", tmp) ) != NULL ) |
610 |
|
{ |
611 |
|
if ( strcmp(str, path) == 0 ) |
644 |
|
[self RemoveVolumeEntry]; |
645 |
|
} |
646 |
|
|
647 |
< |
- (IBAction) ResetPrefs: (id)sender |
647 |
> |
- (void) loadPrefs: (int) argc |
648 |
> |
args: (char **) argv |
649 |
|
{ |
614 |
– |
int argc = 0; |
615 |
– |
char **argv = NULL; |
616 |
– |
|
650 |
|
[panel close]; // Temporarily hide preferences panel |
651 |
|
|
652 |
|
PrefsExit(); // Purge all the old pref values |
662 |
|
edited = NO; |
663 |
|
} |
664 |
|
|
665 |
+ |
- (IBAction) LoadPrefs: (id)sender |
666 |
+ |
{ |
667 |
+ |
int argc = 2; |
668 |
+ |
char *argv[2]; |
669 |
+ |
|
670 |
+ |
argv[0] = "--prefs", |
671 |
+ |
argv[1] = (char *) [[prefsFile stringValue] UTF8String]; |
672 |
+ |
|
673 |
+ |
[self loadPrefs: argc |
674 |
+ |
args: argv]; |
675 |
+ |
} |
676 |
+ |
|
677 |
+ |
- (IBAction) ResetPrefs: (id)sender |
678 |
+ |
{ |
679 |
+ |
[self loadPrefs: 0 |
680 |
+ |
args: NULL]; |
681 |
+ |
} |
682 |
+ |
|
683 |
|
- (void) setStringOf: (NSTextField *) field |
684 |
< |
fromPref: (const char *) prefName |
684 |
> |
fromPref: (const char *) prefName |
685 |
|
{ |
686 |
|
const char *value = PrefsFindString(prefName, 0); |
687 |
|
|
688 |
|
if ( value ) |
689 |
< |
[field setStringValue: [NSString stringWithCString: value] ]; |
689 |
> |
[field setStringValue: [NSString stringWithUTF8String: value] ]; |
690 |
|
} |
691 |
|
|
692 |
|
- (IBAction) SavePrefs: (id)sender |
699 |
|
{ |
700 |
|
NSTableColumn *locks; |
701 |
|
const char *str; |
702 |
< |
int cpu, tmp; |
702 |
> |
int cpu, tmp, val; |
703 |
|
|
704 |
|
|
705 |
|
// Set simple single field items |
706 |
|
|
707 |
< |
tmp = PrefsFindInt32("frameskip"); |
708 |
< |
[delay setIntValue: tmp]; |
709 |
< |
if ( tmp ) |
710 |
< |
[frequency setFloatValue: 60.0 / tmp]; |
707 |
> |
val = PrefsFindInt32("frameskip"); |
708 |
> |
[delay setIntValue: val]; |
709 |
> |
if ( val ) |
710 |
> |
[frequency setFloatValue: 60.0 / val]; |
711 |
|
else |
712 |
|
[frequency setFloatValue: 60.0]; |
713 |
|
|
714 |
< |
tmp = PrefsFindInt32("ramsize"); |
715 |
< |
[bytes setIntValue: tmp]; |
716 |
< |
[MB setFloatValue: tmp / (1024.0 * 1024.0)]; |
714 |
> |
val = PrefsFindInt32("ramsize"); |
715 |
> |
[bytes setIntValue: val]; |
716 |
> |
[MB setFloatValue: val / (1024.0 * 1024.0)]; |
717 |
|
|
718 |
|
[disableCD setState: PrefsFindBool("nocdrom")]; |
719 |
|
[disableSound setState: PrefsFindBool("nosound")]; |
723 |
|
[self setStringOf: extFS fromPref: "extfs" ]; |
724 |
|
[self setStringOf: modem fromPref: "seriala"]; |
725 |
|
[self setStringOf: printer fromPref: "serialb"]; |
726 |
< |
[self setStringOf: ROMfile fromPref: "rom" ]; |
726 |
> |
[self setStringOf: ROMfile fromPref: "rom"]; |
727 |
> |
|
728 |
> |
[prefsFile setStringValue: [NSString stringWithUTF8String: UserPrefsPath.c_str()] ]; |
729 |
|
|
730 |
|
|
731 |
|
parse_screen_prefs(PrefsFindString("screen")); |
734 |
|
[height setIntValue: init_height]; |
735 |
|
[depth setIntValue: init_depth]; |
736 |
|
|
737 |
< |
[window setState: NO]; |
737 |
> |
[screen setState: NO]; |
738 |
|
switch ( display_type ) |
739 |
|
{ |
740 |
|
case DISPLAY_WINDOW: [window setState: YES]; break; |
688 |
– |
case DISPLAY_OPENGL: [openGL setState: YES]; break; |
741 |
|
case DISPLAY_SCREEN: [screen setState: YES]; break; |
742 |
|
} |
743 |
|
|
745 |
|
|
746 |
|
// Radio button groups: |
747 |
|
|
748 |
< |
tmp = PrefsFindInt32("bootdriver"); |
749 |
< |
[bootFromAny setState: tmp != CDROMRefNum]; |
750 |
< |
[bootFromCD setState: tmp == CDROMRefNum]; |
748 |
> |
val = PrefsFindInt32("bootdriver"); |
749 |
> |
[bootFromAny setState: val != CDROMRefNum]; |
750 |
> |
[bootFromCD setState: val == CDROMRefNum]; |
751 |
|
|
752 |
|
cpu = PrefsFindInt32("cpu"); |
753 |
< |
tmp = PrefsFindInt32("modelid"); |
753 |
> |
val = PrefsFindInt32("modelid"); |
754 |
|
|
755 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
756 |
|
puts("Current memory model does not support 24bit addressing"); |
757 |
< |
if ( tmp == [classic tag] ) |
757 |
> |
if ( val == [classic tag] ) |
758 |
|
{ |
759 |
|
// Window already created by NIB file, just display |
760 |
|
[panel makeKeyAndOrderFront:self]; |
762 |
|
@"Disabling Mac Classic emulation", nil, panel); |
763 |
|
cpu = [CPU68030 tag]; |
764 |
|
PrefsReplaceInt32("cpu", cpu); |
765 |
< |
tmp = [IIci tag]; |
766 |
< |
PrefsReplaceInt32("modelid", tmp); |
765 |
> |
val = [IIci tag]; |
766 |
> |
PrefsReplaceInt32("modelid", val); |
767 |
|
} |
768 |
|
|
769 |
|
puts("Disabling 68000 & Mac Classic buttons"); |
776 |
|
[CPU68030 setState: [CPU68030 tag] == cpu]; |
777 |
|
[CPU68040 setState: [CPU68040 tag] == cpu]; |
778 |
|
|
779 |
< |
[classic setState: [classic tag] == tmp]; |
780 |
< |
[IIci setState: [IIci tag] == tmp]; |
781 |
< |
[quadra900 setState: [quadra900 tag] == tmp]; |
779 |
> |
[classic setState: [classic tag] == val]; |
780 |
> |
[IIci setState: [IIci tag] == val]; |
781 |
> |
[quadra900 setState: [quadra900 tag] == val]; |
782 |
|
|
783 |
|
|
784 |
|
// Lists of thingies: |
785 |
|
|
786 |
+ |
val = PrefsFindInt32("keyboardtype"); |
787 |
+ |
tmp = [keyboard indexOfItemWithTag: val]; |
788 |
+ |
if ( tmp != -1 ) |
789 |
+ |
[keyboard selectItemAtIndex: tmp]; |
790 |
+ |
for ( tmp = 0; tmp < [keyboard numberOfItems]; ++tmp ) |
791 |
+ |
{ |
792 |
+ |
NSMenuItem *type = [keyboard itemAtIndex: tmp]; |
793 |
+ |
[type setState: [type tag] == val]; |
794 |
+ |
} |
795 |
+ |
|
796 |
+ |
|
797 |
|
for ( tmp = 0; tmp < 7; ++tmp) |
798 |
|
{ |
799 |
|
char pref[6]; |
818 |
|
{ |
819 |
|
if ( *str == '*' ) |
820 |
|
[volsDS addObject: (NSObject *) locked |
821 |
< |
withPath: [NSString stringWithCString: str+1]]; |
821 |
> |
withPath: [NSString stringWithUTF8String: str+1]]; |
822 |
|
else |
823 |
|
[volsDS addObject: (NSObject *) blank |
824 |
< |
withPath: [NSString stringWithCString: str]]; |
824 |
> |
withPath: [NSString stringWithUTF8String: str]]; |
825 |
|
} |
826 |
|
|
827 |
|
[diskImages setDataSource: volsDS]; |