4 |
|
* |
5 |
|
* $Id$ |
6 |
|
* |
7 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
7 |
> |
* Basilisk II (C) 1997-2004 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 |
30 |
|
self = [super init]; |
31 |
|
|
32 |
|
numItems = 0; |
33 |
< |
col1 = [[NSMutableArray alloc] init]; |
34 |
< |
col2 = [[NSMutableArray alloc] init]; |
33 |
> |
col1 = [NSMutableArray new]; |
34 |
> |
col2 = [NSMutableArray new]; |
35 |
|
|
36 |
|
return self; |
37 |
|
} |
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 1 |
122 |
> |
#define DEBUG 0 |
123 |
|
#import <debug.h> |
124 |
|
|
125 |
|
- (PrefsEditor *) init |
130 |
|
|
131 |
|
devs = @"/dev"; |
132 |
|
home = NSHomeDirectory(); |
133 |
< |
volsDS = [[TableDS alloc] init]; |
134 |
< |
SCSIds = [[TableDS alloc] init]; |
133 |
> |
volsDS = [TableDS new]; |
134 |
> |
SCSIds = [TableDS new]; |
135 |
|
|
136 |
< |
lockCell = [[NSImageCell alloc] init]; |
136 |
> |
lockCell = [NSImageCell new]; |
137 |
|
if ( lockCell == nil ) |
138 |
|
NSLog (@"%s - Can't create NSImageCell?", __PRETTY_FUNCTION__); |
139 |
|
|
140 |
< |
blank = [[NSImage alloc] init]; |
140 |
> |
blank = [NSImage new]; |
141 |
|
locked = [NSImage alloc]; |
142 |
|
if ( [locked initWithContentsOfFile: |
143 |
|
[[NSBundle mainBundle] |
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] cString]; |
238 |
+ |
} |
239 |
+ |
} |
240 |
+ |
|
241 |
|
- (IBAction) BrowseROM: (id)sender |
242 |
|
{ |
243 |
|
NSOpenPanel *oP = [NSOpenPanel openPanel]; |
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 |
|
|
284 |
– |
// Screen/window changing stuff |
315 |
|
|
316 |
< |
// This is called when any of the screen/window, width, height or depth is changed |
316 |
> |
// If we are not using the CGIMAGEREF drawing strategy, |
317 |
> |
// then source bitmaps must be 32bits deep. |
318 |
|
|
319 |
< |
- (IBAction) ChangeScreen: (id)sender |
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 ( [openGL state] ) |
297 |
< |
newtype = DISPLAY_OPENGL; |
298 |
< |
else if ( [screen state] ) |
345 |
> |
if ( cell == screen ) |
346 |
|
newtype = DISPLAY_SCREEN; |
347 |
< |
else if ( [window state] ) |
347 |
> |
else if ( cell == window ) |
348 |
|
newtype = DISPLAY_WINDOW; |
349 |
|
else |
350 |
|
newtype = display_type; |
353 |
|
if ( newbpp == init_depth && newx == init_width && |
354 |
|
newy == init_height && newtype == display_type ) |
355 |
|
{ |
356 |
< |
NSLog(@"No changed GUI items in ChangeScreen"); |
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 |
< |
NSLog(@"Changing disylay type in ChangeScreen"); |
317 |
< |
if ( newtype == DISPLAY_SCREEN ) // If changing to full screen |
318 |
< |
{ |
319 |
< |
// supply main screen dimensions as a default |
320 |
< |
NSScreen *s = [NSScreen mainScreen]; |
321 |
< |
NSRect sr = [s frame]; |
322 |
< |
|
323 |
< |
newx = (short) sr.size.width; |
324 |
< |
newy = (short) sr.size.height; |
325 |
< |
// This always returns 24, despite the mode |
326 |
< |
//newbpp = NSBitsPerPixelFromDepth([s depth]); |
327 |
< |
newbpp = CGDisplayBitsPerPixel(kCGDirectMainDisplay); |
328 |
< |
} |
368 |
> |
D(NSLog(@"Changing display type in ChangeScreen")); |
369 |
|
|
370 |
< |
if ( display_type == DISPLAY_SCREEN ) // If changing from full screen |
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 |
< |
|
379 |
< |
[width setIntValue: newx]; |
334 |
< |
[height setIntValue: newy]; |
335 |
< |
[depth setIntValue: newbpp]; |
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'; |
402 |
|
else |
403 |
|
sprintf(str, "win/%hd/%hd", newx, newy); |
404 |
|
break; |
355 |
– |
case DISPLAY_OPENGL: |
356 |
– |
if ( newbpp ) |
357 |
– |
sprintf(str, "opengl/%hd/%hd/%hd", newx, newy, newbpp); |
358 |
– |
else |
359 |
– |
sprintf(str, "opengl/%hd/%hd", newx, newy); |
360 |
– |
break; |
405 |
|
case DISPLAY_SCREEN: |
406 |
|
if ( newbpp ) |
407 |
|
sprintf(str, "full/%hd/%hd/%hd", newx, newy, newbpp); |
417 |
|
|
418 |
|
if ( display_type != DISPLAY_SCREEN ) |
419 |
|
{ |
420 |
< |
NSLog(@"Display type is not SCREEN (%d), resizing window", display_type); |
420 |
> |
D(NSLog(@"Display type is not SCREEN (%d), resizing window", |
421 |
> |
display_type)); |
422 |
|
resizeWinTo(newx, newy); |
423 |
|
} |
424 |
|
} |
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 |
< |
const char *path = [self RemoveVolumeEntry]; |
475 |
< |
if ( unlink(path) == -1 ) |
474 |
> |
// 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 |
|
{ |
481 |
< |
NSLog(@"%s unlink(%s) failed", __PRETTY_FUNCTION__, path, strerror(errno)); |
481 |
> |
WarningSheet(@"Unable to delete volume", panel); |
482 |
> |
// NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, path, strerror(errno)); |
483 |
|
} |
484 |
|
} |
485 |
|
|
582 |
|
PrefsRemoveItem(pref,0); |
583 |
|
} |
584 |
|
|
585 |
< |
- (const char *) RemoveVolumeEntry |
585 |
> |
//- (const char *) RemoveVolumeEntry |
586 |
> |
- (NSString *) RemoveVolumeEntry |
587 |
|
{ |
588 |
|
int row = [diskImages selectedRow]; |
589 |
|
|
590 |
|
if ( row != -1 ) |
591 |
|
{ |
592 |
< |
const char *path = [[volsDS pathAtRow: row] cString], |
592 |
> |
NSString *Path = [volsDS pathAtRow: row]; |
593 |
> |
const char *path = [Path cString], |
594 |
|
*str; |
595 |
|
int tmp = 0; |
596 |
|
|
599 |
|
if ( strcmp(str, path) == 0 ) |
600 |
|
{ |
601 |
|
PrefsRemoveItem("disk", tmp); |
602 |
< |
D(NSLog(@"%s - Deleted prefs entry \"disk\", %d", __PRETTY_FUNCTION__, tmp)); |
602 |
> |
D(NSLog(@"%s - Deleted prefs entry \"disk\", %d", |
603 |
> |
__PRETTY_FUNCTION__, tmp)); |
604 |
|
edited = YES; |
605 |
|
break; |
606 |
|
} |
609 |
|
|
610 |
|
if ( str == NULL ) |
611 |
|
{ |
612 |
< |
NSLog(@"%s - Couldn't find any disk preference to match %s", __PRETTY_FUNCTION__, path); |
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; |
620 |
> |
// return path; |
621 |
> |
return Path; |
622 |
|
} |
623 |
|
else |
624 |
|
{ |
632 |
|
[self RemoveVolumeEntry]; |
633 |
|
} |
634 |
|
|
635 |
< |
- (IBAction) ResetPrefs: (id)sender |
635 |
> |
- (void) loadPrefs: (int) argc |
636 |
> |
args: (char **) argv |
637 |
|
{ |
570 |
– |
int argc = 0; |
571 |
– |
char **argv = NULL; |
572 |
– |
|
638 |
|
[panel close]; // Temporarily hide preferences panel |
639 |
|
|
640 |
|
PrefsExit(); // Purge all the old pref values |
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] 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 |
|
- (void) setStringOf: (NSTextField *) field |
672 |
|
fromPref: (const char *) prefName |
673 |
|
{ |
687 |
|
{ |
688 |
|
NSTableColumn *locks; |
689 |
|
const char *str; |
690 |
< |
int cpu, tmp; |
690 |
> |
int cpu, tmp, val; |
691 |
|
|
692 |
|
|
693 |
|
// Set simple single field items |
694 |
|
|
695 |
< |
tmp = PrefsFindInt32("frameskip"); |
696 |
< |
[delay setIntValue: tmp]; |
697 |
< |
if ( tmp ) |
698 |
< |
[frequency setFloatValue: 60.0 / tmp]; |
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 |
< |
tmp = PrefsFindInt32("ramsize"); |
703 |
< |
[bytes setIntValue: tmp]; |
704 |
< |
[MB setFloatValue: tmp / (1024.0 * 1024.0)]; |
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")]; |
713 |
|
[self setStringOf: printer fromPref: "serialb"]; |
714 |
|
[self setStringOf: ROMfile fromPref: "rom" ]; |
715 |
|
|
716 |
+ |
[prefsFile setStringValue: [NSString stringWithCString: UserPrefsPath.c_str()] ]; |
717 |
+ |
|
718 |
|
|
719 |
|
parse_screen_prefs(PrefsFindString("screen")); |
720 |
|
|
722 |
|
[height setIntValue: init_height]; |
723 |
|
[depth setIntValue: init_depth]; |
724 |
|
|
725 |
< |
[window setState: NO]; |
725 |
> |
[screen setState: NO]; |
726 |
|
switch ( display_type ) |
727 |
|
{ |
728 |
|
case DISPLAY_WINDOW: [window setState: YES]; break; |
644 |
– |
case DISPLAY_OPENGL: [openGL setState: YES]; break; |
729 |
|
case DISPLAY_SCREEN: [screen setState: YES]; break; |
730 |
|
} |
731 |
|
|
733 |
|
|
734 |
|
// Radio button groups: |
735 |
|
|
736 |
< |
tmp = PrefsFindInt32("bootdriver"); |
737 |
< |
[bootFromAny setState: tmp != CDROMRefNum]; |
738 |
< |
[bootFromCD setState: tmp == CDROMRefNum]; |
736 |
> |
val = PrefsFindInt32("bootdriver"); |
737 |
> |
[bootFromAny setState: val != CDROMRefNum]; |
738 |
> |
[bootFromCD setState: val == CDROMRefNum]; |
739 |
|
|
740 |
|
cpu = PrefsFindInt32("cpu"); |
741 |
< |
tmp = PrefsFindInt32("modelid"); |
741 |
> |
val = PrefsFindInt32("modelid"); |
742 |
|
|
743 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
744 |
|
puts("Current memory model does not support 24bit addressing"); |
745 |
< |
if ( tmp == [classic tag] ) |
745 |
> |
if ( val == [classic tag] ) |
746 |
|
{ |
747 |
|
// Window already created by NIB file, just display |
748 |
|
[panel makeKeyAndOrderFront:self]; |
750 |
|
@"Disabling Mac Classic emulation", nil, panel); |
751 |
|
cpu = [CPU68030 tag]; |
752 |
|
PrefsReplaceInt32("cpu", cpu); |
753 |
< |
tmp = [IIci tag]; |
754 |
< |
PrefsReplaceInt32("modelid", tmp); |
753 |
> |
val = [IIci tag]; |
754 |
> |
PrefsReplaceInt32("modelid", val); |
755 |
|
} |
756 |
|
|
757 |
|
puts("Disabling 68000 & Mac Classic buttons"); |
764 |
|
[CPU68030 setState: [CPU68030 tag] == cpu]; |
765 |
|
[CPU68040 setState: [CPU68040 tag] == cpu]; |
766 |
|
|
767 |
< |
[classic setState: [classic tag] == tmp]; |
768 |
< |
[IIci setState: [IIci tag] == tmp]; |
769 |
< |
[quadra900 setState: [quadra900 tag] == tmp]; |
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]; |