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