4 |
|
* |
5 |
|
* $Id$ |
6 |
|
* |
7 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
7 |
> |
* Basilisk II (C) 1997-2003 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 |
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]; |
280 |
|
|
281 |
|
- (IBAction) ChangeDisableSound: (NSButton *)sender |
282 |
|
{ |
283 |
< |
PrefsReplaceBool("nosound", [disableSound state]); |
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 |
|
|
301 |
|
edited = YES; |
302 |
|
} |
303 |
|
|
279 |
– |
// Screen/window changing stuff |
304 |
|
|
305 |
< |
// This is called when any of the screen/window, width, height or depth is changed |
305 |
> |
// If we are not using the CGIMAGEREF drawing strategy, |
306 |
> |
// then source bitmaps must be 32bits deep. |
307 |
> |
|
308 |
> |
- (short) testWinDepth: (int) newbpp |
309 |
> |
{ |
310 |
> |
#ifdef CGIMAGEREF |
311 |
> |
return newbpp; |
312 |
> |
#else |
313 |
> |
if ( newbpp != 32 ) |
314 |
> |
WarningSheet(@"Sorry - In windowed mode, depth must be 32", panel); |
315 |
> |
return 32 |
316 |
> |
#endif |
317 |
> |
} |
318 |
> |
|
319 |
> |
// This is called when the screen/window, |
320 |
> |
// width, height or depth is clicked. |
321 |
> |
// |
322 |
> |
// Note that sender may not actually be an NSMatrix. |
323 |
|
|
324 |
|
- (IBAction) ChangeScreen: (NSMatrix *)sender |
325 |
|
{ |
326 |
+ |
NSButton *cell = [sender selectedCell]; |
327 |
+ |
|
328 |
|
short newx = [width intValue]; |
329 |
|
short newy = [height intValue]; |
330 |
|
short newbpp = [depth intValue]; |
331 |
< |
short newtype = DISPLAY_WINDOW; |
331 |
> |
short newtype; |
332 |
|
char str[20]; |
333 |
|
|
334 |
< |
if ( [sender selectedCell] == openGL ) |
292 |
< |
newtype = DISPLAY_OPENGL; |
293 |
< |
if ( [sender selectedCell] == screen ) |
334 |
> |
if ( cell == screen ) |
335 |
|
newtype = DISPLAY_SCREEN; |
336 |
+ |
else if ( cell == window ) |
337 |
+ |
newtype = DISPLAY_WINDOW; |
338 |
+ |
else |
339 |
+ |
newtype = display_type; |
340 |
|
|
341 |
|
// Check that a field actually changed |
342 |
|
if ( newbpp == init_depth && newx == init_width && |
343 |
|
newy == init_height && newtype == display_type ) |
344 |
+ |
{ |
345 |
+ |
D(NSLog(@"No changed GUI items in ChangeScreen")); |
346 |
|
return; |
347 |
< |
|
347 |
> |
} |
348 |
|
|
349 |
|
// If we are changing type, supply some sensible defaults |
350 |
+ |
|
351 |
+ |
short screenx = CGDisplayPixelsWide(kCGDirectMainDisplay), |
352 |
+ |
screeny = CGDisplayPixelsHigh(kCGDirectMainDisplay), |
353 |
+ |
screenb = CGDisplayBitsPerPixel(kCGDirectMainDisplay); |
354 |
+ |
|
355 |
|
if ( newtype != display_type ) |
356 |
|
{ |
357 |
< |
if ( newtype == DISPLAY_SCREEN ) // If changing to full screen |
306 |
< |
{ |
307 |
< |
// supply main screen dimensions as a default |
308 |
< |
NSScreen *s = [NSScreen mainScreen]; |
309 |
< |
NSRect sr = [s frame]; |
310 |
< |
|
311 |
< |
newx = (short) sr.size.width; |
312 |
< |
newy = (short) sr.size.height; |
313 |
< |
// This always returns 24, despite the mode |
314 |
< |
//newbpp = NSBitsPerPixelFromDepth([s depth]); |
315 |
< |
newbpp = CGDisplayBitsPerPixel(kCGDirectMainDisplay); |
316 |
< |
} |
357 |
> |
D(NSLog(@"Changing display type in ChangeScreen")); |
358 |
|
|
359 |
< |
if ( display_type == DISPLAY_SCREEN ) // If changing from full screen |
359 |
> |
// If changing to full screen, supply main screen dimensions as a default |
360 |
> |
if ( newtype == DISPLAY_SCREEN ) |
361 |
> |
newx = screenx, newy = screeny, newbpp = screenb; |
362 |
> |
|
363 |
> |
// If changing from full screen, use minimum screen resolutions |
364 |
> |
if ( display_type == DISPLAY_SCREEN ) |
365 |
> |
{ |
366 |
|
newx = MIN_WIDTH, newy = MIN_HEIGHT; |
367 |
< |
|
368 |
< |
[width setIntValue: newx]; |
322 |
< |
[height setIntValue: newy]; |
323 |
< |
[depth setIntValue: newbpp]; |
367 |
> |
newbpp = [self testWinDepth: newbpp]; |
368 |
> |
} |
369 |
|
} |
370 |
|
else |
371 |
|
{ |
372 |
+ |
newbpp = [self testWinDepth: newbpp]; |
373 |
+ |
|
374 |
|
// Check size is within ranges of MIN_WIDTH ... MAX_WIDTH |
375 |
|
// and MIN_HEIGHT ... MAX_HEIGHT |
376 |
|
// ??? |
377 |
|
} |
378 |
|
|
379 |
+ |
[width setIntValue: newx]; |
380 |
+ |
[height setIntValue: newy]; |
381 |
+ |
[depth setIntValue: newbpp]; |
382 |
+ |
|
383 |
|
|
384 |
|
// Store new prefs |
385 |
|
*str = '\0'; |
391 |
|
else |
392 |
|
sprintf(str, "win/%hd/%hd", newx, newy); |
393 |
|
break; |
343 |
– |
case DISPLAY_OPENGL: |
344 |
– |
if ( newbpp ) |
345 |
– |
sprintf(str, "opengl/%hd/%hd/%hd", newx, newy, newbpp); |
346 |
– |
else |
347 |
– |
sprintf(str, "opengl/%hd/%hd", newx, newy); |
348 |
– |
break; |
394 |
|
case DISPLAY_SCREEN: |
395 |
|
if ( newbpp ) |
396 |
|
sprintf(str, "full/%hd/%hd/%hd", newx, newy, newbpp); |
405 |
|
edited = YES; |
406 |
|
|
407 |
|
if ( display_type != DISPLAY_SCREEN ) |
408 |
+ |
{ |
409 |
+ |
D(NSLog(@"Display type is not SCREEN (%d), resizing window", |
410 |
+ |
display_type)); |
411 |
|
resizeWinTo(newx, newy); |
412 |
+ |
} |
413 |
|
} |
414 |
|
|
415 |
|
- (IBAction) CreateVolume: (id)sender |
434 |
|
NSString *details = [NSString stringWithFormat: |
435 |
|
@"The dd command failed.\nReturn status %d (%s)", |
436 |
|
retVal, strerror(errno)]; |
437 |
< |
WarningSheet(@"Unable to create volume", details, @"OK", panel); |
437 |
> |
WarningSheet(@"Unable to create volume", details, nil, panel); |
438 |
|
} |
439 |
|
else |
440 |
|
{ |
446 |
|
} |
447 |
|
} |
448 |
|
|
449 |
+ |
- (BOOL) fileManager: (NSFileManager *) manager |
450 |
+ |
shouldProceedAfterError: (NSDictionary *) errorDict |
451 |
+ |
{ |
452 |
+ |
NSRunAlertPanel(@"File operation error", |
453 |
+ |
@"%@ %@, toPath %@", |
454 |
+ |
@"Bugger!", nil, nil, |
455 |
+ |
[errorDict objectForKey:@"Error"], |
456 |
+ |
[errorDict objectForKey:@"Path"], |
457 |
+ |
[errorDict objectForKey:@"ToPath"]); |
458 |
+ |
return NO; |
459 |
+ |
} |
460 |
+ |
|
461 |
|
- (IBAction) DeleteVolume: (id)sender |
462 |
|
{ |
463 |
< |
const char *path = [self RemoveVolumeEntry]; |
464 |
< |
if ( unlink(path) == -1 ) |
463 |
> |
// const char *path = [self RemoveVolumeEntry]; |
464 |
> |
// if ( unlink(path) == -1 ) |
465 |
> |
NSString *Path = [self RemoveVolumeEntry]; |
466 |
> |
|
467 |
> |
if ( ! [[NSFileManager defaultManager] removeFileAtPath: Path |
468 |
> |
handler: self] ) |
469 |
|
{ |
470 |
< |
NSLog(@"%s unlink(%s) failed", __PRETTY_FUNCTION__, path, strerror(errno)); |
470 |
> |
WarningSheet(@"Unable to delete volume", panel); |
471 |
> |
// NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, path, strerror(errno)); |
472 |
|
} |
473 |
|
} |
474 |
|
|
493 |
|
int B = (int) [bytes floatValue]; |
494 |
|
float M = B / 1024 / 1024; |
495 |
|
|
496 |
< |
NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B); |
496 |
> |
D(NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B)); |
497 |
|
PrefsReplaceInt32("ramsize", B); |
498 |
|
[MB setFloatValue: M]; |
499 |
|
edited = YES; |
537 |
|
float M = [MB floatValue]; |
538 |
|
int B = (int) (M * 1024 * 1024); |
539 |
|
|
540 |
< |
NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B); |
540 |
> |
D(NSLog(@"%s = %f %d", __PRETTY_FUNCTION__, M, B)); |
541 |
|
PrefsReplaceInt32("ramsize", B); |
542 |
|
[bytes setIntValue: B]; |
543 |
|
edited = YES; |
551 |
|
edited = YES; |
552 |
|
} |
553 |
|
|
488 |
– |
- (IBAction) EditRAMsize: (NSTextField *)sender |
489 |
– |
{ |
490 |
– |
int B = [bytes intValue]; |
491 |
– |
float M = B / (1024.0 * 1024.0); |
492 |
– |
|
493 |
– |
NSLog(@"%s = %d %f", __PRETTY_FUNCTION__, B, M); |
494 |
– |
PrefsReplaceInt32("ramsize", B); |
495 |
– |
[MB setFloatValue: M]; |
496 |
– |
edited = YES; |
497 |
– |
} |
498 |
– |
|
554 |
|
- (IBAction) EditROMpath: (NSTextField *)sender |
555 |
|
{ |
556 |
|
NSString *path = [ROMfile stringValue]; |
571 |
|
PrefsRemoveItem(pref,0); |
572 |
|
} |
573 |
|
|
574 |
< |
- (const char *) RemoveVolumeEntry |
574 |
> |
//- (const char *) RemoveVolumeEntry |
575 |
> |
- (NSString *) RemoveVolumeEntry |
576 |
|
{ |
577 |
|
int row = [diskImages selectedRow]; |
578 |
|
|
579 |
|
if ( row != -1 ) |
580 |
|
{ |
581 |
< |
const char *path = [[volsDS pathAtRow: row] cString], |
581 |
> |
NSString *Path = [volsDS pathAtRow: row]; |
582 |
> |
const char *path = [Path cString], |
583 |
|
*str; |
584 |
|
int tmp = 0; |
585 |
|
|
588 |
|
if ( strcmp(str, path) == 0 ) |
589 |
|
{ |
590 |
|
PrefsRemoveItem("disk", tmp); |
591 |
< |
D(NSLog(@"%s - Deleted prefs entry \"disk\", %d", __PRETTY_FUNCTION__, tmp)); |
591 |
> |
D(NSLog(@"%s - Deleted prefs entry \"disk\", %d", |
592 |
> |
__PRETTY_FUNCTION__, tmp)); |
593 |
|
edited = YES; |
594 |
|
break; |
595 |
|
} |
598 |
|
|
599 |
|
if ( str == NULL ) |
600 |
|
{ |
601 |
< |
NSLog(@"%s - Couldn't find any disk preference to match %s", __PRETTY_FUNCTION__, path); |
601 |
> |
NSLog(@"%s - Couldn't find any disk preference to match %s", |
602 |
> |
__PRETTY_FUNCTION__, path); |
603 |
|
return NULL; |
604 |
|
} |
605 |
|
|
606 |
|
if ( ! [volsDS deleteRow: row] ) |
607 |
|
NSLog (@"%s - RemoveVolume %d failed", __PRETTY_FUNCTION__, tmp); |
608 |
|
[diskImages reloadData]; |
609 |
< |
return path; |
609 |
> |
// return path; |
610 |
> |
return Path; |
611 |
|
} |
612 |
|
else |
613 |
|
{ |
614 |
< |
WarningSheet(@"Please select a volume first", @"", @"OK", panel); |
614 |
> |
WarningSheet(@"Please select a volume first", panel); |
615 |
|
return NULL; |
616 |
|
} |
617 |
|
} |
621 |
|
[self RemoveVolumeEntry]; |
622 |
|
} |
623 |
|
|
624 |
< |
- (IBAction) ResetPrefs: (id)sender |
624 |
> |
- (void) loadPrefs: (int) argc |
625 |
> |
args: (char **) argv |
626 |
|
{ |
566 |
– |
int argc = 0; |
567 |
– |
char **argv = NULL; |
568 |
– |
|
627 |
|
[panel close]; // Temporarily hide preferences panel |
628 |
|
|
629 |
|
PrefsExit(); // Purge all the old pref values |
639 |
|
edited = NO; |
640 |
|
} |
641 |
|
|
642 |
+ |
- (IBAction) LoadPrefs: (id)sender |
643 |
+ |
{ |
644 |
+ |
int argc = 2; |
645 |
+ |
char *argv[2]; |
646 |
+ |
|
647 |
+ |
argv[0] = "--prefs", |
648 |
+ |
argv[1] = (char *) [[prefsFile stringValue] cString]; |
649 |
+ |
|
650 |
+ |
[self loadPrefs: argc |
651 |
+ |
args: argv]; |
652 |
+ |
} |
653 |
+ |
|
654 |
+ |
- (IBAction) ResetPrefs: (id)sender |
655 |
+ |
{ |
656 |
+ |
[self loadPrefs: 0 |
657 |
+ |
args: NULL]; |
658 |
+ |
} |
659 |
+ |
|
660 |
|
- (void) setStringOf: (NSTextField *) field |
661 |
|
fromPref: (const char *) prefName |
662 |
|
{ |
702 |
|
[self setStringOf: printer fromPref: "serialb"]; |
703 |
|
[self setStringOf: ROMfile fromPref: "rom" ]; |
704 |
|
|
705 |
+ |
[prefsFile setStringValue: [NSString stringWithCString: UserPrefsPath.c_str()] ]; |
706 |
+ |
|
707 |
|
|
708 |
|
parse_screen_prefs(PrefsFindString("screen")); |
709 |
|
|
711 |
|
[height setIntValue: init_height]; |
712 |
|
[depth setIntValue: init_depth]; |
713 |
|
|
714 |
< |
[window setState: NO]; |
714 |
> |
[screen setState: NO]; |
715 |
|
switch ( display_type ) |
716 |
|
{ |
717 |
|
case DISPLAY_WINDOW: [window setState: YES]; break; |
640 |
– |
case DISPLAY_OPENGL: [openGL setState: YES]; break; |
718 |
|
case DISPLAY_SCREEN: [screen setState: YES]; break; |
719 |
|
} |
720 |
|
|
736 |
|
// Window already created by NIB file, just display |
737 |
|
[panel makeKeyAndOrderFront:self]; |
738 |
|
WarningSheet(@"Compiled-in memory model does not support 24bit", |
739 |
< |
@"Disabling Mac Classic emulation", @"OK", panel); |
739 |
> |
@"Disabling Mac Classic emulation", nil, panel); |
740 |
|
cpu = [CPU68030 tag]; |
741 |
|
PrefsReplaceInt32("cpu", cpu); |
742 |
|
tmp = [IIci tag]; |