Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/cocoa/YabausePrefsController.m
2 views
1
/* Copyright 2010 Lawrence Sebald
2
3
This file is part of Yabause.
4
5
Yabause is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
9
10
Yabause is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with Yabause; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
#include <ctype.h>
21
22
#include "YabausePrefsController.h"
23
24
#include "cs0.h"
25
#include "vidogl.h"
26
#include "vidsoft.h"
27
#include "scsp.h"
28
#include "smpc.h"
29
#include "sndmac.h"
30
#include "PerCocoa.h"
31
32
@implementation YabausePrefsController
33
34
- (void)awakeFromNib
35
{
36
_cartType = CART_NONE;
37
_region = REGION_AUTODETECT;
38
_soundCore = SNDCORE_MAC;
39
_videoCore = VIDCORE_SOFT;
40
41
_prefs = [[NSUserDefaults standardUserDefaults] retain];
42
43
/* Fill in all the settings. */
44
if([_prefs objectForKey:@"BIOS Path"]) {
45
[biosPath setStringValue:[_prefs stringForKey:@"BIOS Path"]];
46
}
47
else {
48
[_prefs setObject:@"" forKey:@"BIOS Path"];
49
}
50
51
if([_prefs objectForKey:@"Emulate BIOS"]) {
52
[emulateBios setState:[_prefs boolForKey:@"Emulate BIOS"] ?
53
NSOnState : NSOffState];
54
}
55
else {
56
[_prefs setBool:YES forKey:@"Emulate BIOS"];
57
}
58
59
if([_prefs objectForKey:@"MPEG ROM Path"]) {
60
[mpegPath setStringValue:[_prefs objectForKey:@"MPEG ROM Path"]];
61
}
62
else {
63
[_prefs setObject:@"" forKey:@"MPEG ROM Path"];
64
}
65
66
if([_prefs objectForKey:@"BRAM Path"]) {
67
[bramPath setStringValue:[_prefs objectForKey:@"BRAM Path"]];
68
}
69
else {
70
[_prefs setObject:@"" forKey:@"BRAM Path"];
71
}
72
73
if([_prefs objectForKey:@"Cartridge Path"]) {
74
[cartPath setStringValue:[_prefs objectForKey:@"Cartridge Path"]];
75
}
76
else {
77
[_prefs setObject:@"" forKey:@"Cartridge Path"];
78
}
79
80
if([_prefs objectForKey:@"Cartridge Type"]) {
81
_cartType = [_prefs integerForKey:@"Cartridge Type"];
82
83
if(_cartType != CART_NONE && _cartType != CART_DRAM8MBIT &&
84
_cartType != CART_DRAM32MBIT) {
85
[cartPath setEnabled:YES];
86
[cartBrowse setEnabled:YES];
87
[[cartPath cell] setPlaceholderString:@"Not Set"];
88
}
89
90
[cartType selectItemWithTag:_cartType];
91
}
92
else {
93
[_prefs setInteger:CART_NONE forKey:@"Cartridge Type"];
94
}
95
96
if([_prefs objectForKey:@"Region"]) {
97
_region = [_prefs integerForKey:@"Region"];
98
[region selectItemWithTag:_region];
99
}
100
else {
101
[_prefs setInteger:REGION_AUTODETECT forKey:@"Region"];
102
}
103
104
if([_prefs objectForKey:@"Sound Core"]) {
105
_soundCore = [_prefs integerForKey:@"Sound Core"];
106
[soundCore selectItemWithTag:_soundCore];
107
}
108
else {
109
[_prefs setInteger:SNDCORE_MAC forKey:@"Sound Core"];
110
}
111
112
if([_prefs objectForKey:@"Video Core"]) {
113
_videoCore = [_prefs integerForKey:@"Video Core"];
114
[videoCore selectItemWithTag:_videoCore];
115
}
116
else {
117
[_prefs setInteger:VIDCORE_OGL forKey:@"Video Core"];
118
}
119
120
[_prefs synchronize];
121
}
122
123
- (void)dealloc
124
{
125
[_prefs release];
126
[super dealloc];
127
}
128
129
- (void)controlTextDidEndEditing:(NSNotification *)notification
130
{
131
id obj = [notification object];
132
133
if(obj == biosPath) {
134
[_prefs setObject:[biosPath stringValue] forKey:@"BIOS Path"];
135
}
136
else if(obj == bramPath) {
137
[_prefs setObject:[bramPath stringValue] forKey:@"BRAM Path"];
138
}
139
else if(obj == mpegPath) {
140
[_prefs setObject:[mpegPath stringValue] forKey:@"MPEG ROM Path"];
141
}
142
else if(obj == cartPath) {
143
[_prefs setObject:[cartPath stringValue] forKey:@"Cartridge Path"];
144
}
145
146
[_prefs synchronize];
147
}
148
149
- (IBAction)cartSelected:(id)sender
150
{
151
_cartType = [[sender selectedItem] tag];
152
153
switch(_cartType) {
154
case CART_NONE:
155
case CART_DRAM8MBIT:
156
case CART_DRAM32MBIT:
157
[cartPath setEnabled:NO];
158
[cartPath setStringValue:@""];
159
[cartBrowse setEnabled:NO];
160
[[cartPath cell] setPlaceholderString:
161
@"No file required for the selected cartridge"];
162
break;
163
164
default:
165
[cartPath setEnabled:YES];
166
[cartBrowse setEnabled:YES];
167
[[cartPath cell] setPlaceholderString:@"Not Set"];
168
break;
169
}
170
171
/* Update the preferences file. */
172
[_prefs setObject:[cartPath stringValue] forKey:@"Cartridge Path"];
173
[_prefs setInteger:_cartType forKey:@"Cartridge Type"];
174
[_prefs synchronize];
175
}
176
177
- (IBAction)regionSelected:(id)sender
178
{
179
_region = [[sender selectedItem] tag];
180
181
/* Update the preferences file. */
182
[_prefs setInteger:_region forKey:@"Region"];
183
[_prefs synchronize];
184
}
185
186
- (IBAction)soundCoreSelected:(id)sender
187
{
188
_soundCore = [[sender selectedItem] tag];
189
190
/* Update the preferences file. */
191
[_prefs setInteger:_soundCore forKey:@"Sound Core"];
192
[_prefs synchronize];
193
}
194
195
- (IBAction)videoCoreSelected:(id)sender
196
{
197
_videoCore = [[sender selectedItem] tag];
198
199
/* Update the preferences file. */
200
[_prefs setInteger:_videoCore forKey:@"Video Core"];
201
[_prefs synchronize];
202
}
203
204
- (IBAction)biosBrowse:(id)sender
205
{
206
NSOpenPanel *p = [NSOpenPanel openPanel];
207
208
[p setTitle:@"Select a Saturn BIOS ROM"];
209
210
if([p runModal] == NSFileHandlingPanelOKButton) {
211
[biosPath setStringValue:[[[p URLs] objectAtIndex:0] path]];
212
213
/* Update the preferences file. */
214
[_prefs setObject:[biosPath stringValue] forKey:@"BIOS Path"];
215
[_prefs synchronize];
216
}
217
}
218
219
- (IBAction)mpegBrowse:(id)sender
220
{
221
NSOpenPanel *p = [NSOpenPanel openPanel];
222
223
[p setTitle:@"Select a MPEG ROM"];
224
225
if([p runModal] == NSFileHandlingPanelOKButton) {
226
[mpegPath setStringValue:[[[p URLs] objectAtIndex:0] path]];
227
228
/* Update the preferences file. */
229
[_prefs setObject:[mpegPath stringValue] forKey:@"MPEG ROM Path"];
230
[_prefs synchronize];
231
}
232
}
233
234
- (IBAction)bramBrowse:(id)sender
235
{
236
NSOpenPanel *p = [NSOpenPanel openPanel];
237
238
[p setTitle:@"Select a BRAM File"];
239
240
if([p runModal] == NSFileHandlingPanelOKButton) {
241
[bramPath setStringValue:[[[p URLs] objectAtIndex:0] path]];
242
243
/* Update the preferences file. */
244
[_prefs setObject:[bramPath stringValue] forKey:@"BRAM Path"];
245
[_prefs synchronize];
246
}
247
}
248
249
- (IBAction)cartBrowse:(id)sender
250
{
251
NSOpenPanel *p = [NSOpenPanel openPanel];
252
253
[p setTitle:@"Select the Cartridge File"];
254
255
if([p runModal] == NSFileHandlingPanelOKButton) {
256
[cartPath setStringValue:[[[p URLs] objectAtIndex:0] path]];
257
258
/* Update the preferences file. */
259
[_prefs setObject:[cartPath stringValue] forKey:@"Cartridge Path"];
260
[_prefs synchronize];
261
}
262
}
263
264
- (IBAction)biosToggle:(id)sender
265
{
266
/* Update the preferences file. */
267
[_prefs setBool:([sender state] == NSOnState) forKey:@"Emulate BIOS"];
268
[_prefs synchronize];
269
}
270
271
- (IBAction)buttonSelect:(id)sender
272
{
273
NSInteger rv;
274
NSInteger tag = [sender tag];
275
int port = tag > 12 ? 1 : 0;
276
u8 num = tag > 12 ? tag - 13 : tag;
277
u32 value = PERCocoaGetKey(num, port);
278
unichar ch;
279
280
/* Fill in current setting from prefs */
281
if(value != (u32)-1) {
282
switch(value) {
283
case '\r':
284
ch = 0x23CE;
285
break;
286
287
case '\t':
288
ch = 0x21E5;
289
break;
290
291
case 27:
292
ch = 0x241B;
293
break;
294
295
case 127:
296
ch = 0x232B;
297
break;
298
299
case NSLeftArrowFunctionKey:
300
ch = 0x2190;
301
break;
302
303
case NSUpArrowFunctionKey:
304
ch = 0x2191;
305
break;
306
307
case NSRightArrowFunctionKey:
308
ch = 0x2192;
309
break;
310
311
case NSDownArrowFunctionKey:
312
ch = 0x2193;
313
break;
314
315
default:
316
ch = toupper(((int)value));
317
}
318
319
[buttonBox setStringValue:[NSString stringWithCharacters:&ch length:1]];
320
}
321
else {
322
[buttonBox setStringValue:@""];
323
}
324
325
/* Open up the sheet and ask for the user's input */
326
[NSApp beginSheet:buttonAssignment
327
modalForWindow:prefsPane
328
modalDelegate:self
329
didEndSelector:nil
330
contextInfo:NULL];
331
332
rv = [NSApp runModalForWindow:buttonAssignment];
333
[NSApp endSheet:buttonAssignment];
334
[buttonAssignment orderOut:nil];
335
336
/* Did the user accept what they put in? */
337
if(rv == NSOKButton) {
338
NSString *s = [buttonBox stringValue];
339
u32 val;
340
341
/* This shouldn't happen... */
342
if([s length] < 1) {
343
return;
344
}
345
346
switch([s characterAtIndex:0]) {
347
case 0x23CE: /* Return */
348
val = '\r';
349
break;
350
351
case 0x21E5: /* Tab */
352
val = '\t';
353
break;
354
355
case 0x241B: /* Escape */
356
val = 27;
357
break;
358
359
case 0x232B: /* Backspace */
360
val = 127;
361
break;
362
363
case 0x2190: /* Left */
364
val = NSLeftArrowFunctionKey;
365
break;
366
367
case 0x2191: /* Up */
368
val = NSUpArrowFunctionKey;
369
break;
370
371
case 0x2192: /* Right */
372
val = NSRightArrowFunctionKey;
373
break;
374
375
case 0x2193: /* Down */
376
val = NSDownArrowFunctionKey;
377
break;
378
379
default:
380
val = tolower([s characterAtIndex:0]);
381
}
382
383
/* Update the key mapping, if we're already running. This will also save
384
the key to the preferences. */
385
if(tag > 12) {
386
PERCocoaSetKey(val, tag - 13, 1);
387
}
388
else {
389
PERCocoaSetKey(val, tag, 0);
390
}
391
}
392
}
393
394
- (IBAction)buttonSetOk:(id)sender
395
{
396
[NSApp stopModalWithCode:NSOKButton];
397
}
398
399
- (IBAction)buttonSetCancel:(id)sender
400
{
401
[NSApp stopModalWithCode:NSCancelButton];
402
}
403
404
- (int)cartType
405
{
406
return _cartType;
407
}
408
409
- (int)region
410
{
411
return _region;
412
}
413
414
- (int)soundCore
415
{
416
return _soundCore;
417
}
418
419
- (int)videoCore
420
{
421
return _videoCore;
422
}
423
424
- (NSString *)biosPath
425
{
426
return [biosPath stringValue];
427
}
428
429
- (BOOL)emulateBios
430
{
431
return [emulateBios state] == NSOnState;
432
}
433
434
- (NSString *)mpegPath
435
{
436
return [mpegPath stringValue];
437
}
438
439
- (NSString *)bramPath
440
{
441
return [bramPath stringValue];
442
}
443
444
- (NSString *)cartPath
445
{
446
return [cartPath stringValue];
447
}
448
449
@end /* @implementation YabausePrefsController */
450
451