Path: blob/master/yabause/src/cocoa/YabausePrefsController.m
2 views
/* Copyright 2010 Lawrence Sebald12This file is part of Yabause.34Yabause is free software; you can redistribute it and/or modify5it under the terms of the GNU General Public License as published by6the Free Software Foundation; either version 2 of the License, or7(at your option) any later version.89Yabause is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with Yabause; if not, write to the Free Software16Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA17*/1819#include <ctype.h>2021#include "YabausePrefsController.h"2223#include "cs0.h"24#include "vidogl.h"25#include "vidsoft.h"26#include "scsp.h"27#include "smpc.h"28#include "sndmac.h"29#include "PerCocoa.h"3031@implementation YabausePrefsController3233- (void)awakeFromNib34{35_cartType = CART_NONE;36_region = REGION_AUTODETECT;37_soundCore = SNDCORE_MAC;38_videoCore = VIDCORE_SOFT;3940_prefs = [[NSUserDefaults standardUserDefaults] retain];4142/* Fill in all the settings. */43if([_prefs objectForKey:@"BIOS Path"]) {44[biosPath setStringValue:[_prefs stringForKey:@"BIOS Path"]];45}46else {47[_prefs setObject:@"" forKey:@"BIOS Path"];48}4950if([_prefs objectForKey:@"Emulate BIOS"]) {51[emulateBios setState:[_prefs boolForKey:@"Emulate BIOS"] ?52NSOnState : NSOffState];53}54else {55[_prefs setBool:YES forKey:@"Emulate BIOS"];56}5758if([_prefs objectForKey:@"MPEG ROM Path"]) {59[mpegPath setStringValue:[_prefs objectForKey:@"MPEG ROM Path"]];60}61else {62[_prefs setObject:@"" forKey:@"MPEG ROM Path"];63}6465if([_prefs objectForKey:@"BRAM Path"]) {66[bramPath setStringValue:[_prefs objectForKey:@"BRAM Path"]];67}68else {69[_prefs setObject:@"" forKey:@"BRAM Path"];70}7172if([_prefs objectForKey:@"Cartridge Path"]) {73[cartPath setStringValue:[_prefs objectForKey:@"Cartridge Path"]];74}75else {76[_prefs setObject:@"" forKey:@"Cartridge Path"];77}7879if([_prefs objectForKey:@"Cartridge Type"]) {80_cartType = [_prefs integerForKey:@"Cartridge Type"];8182if(_cartType != CART_NONE && _cartType != CART_DRAM8MBIT &&83_cartType != CART_DRAM32MBIT) {84[cartPath setEnabled:YES];85[cartBrowse setEnabled:YES];86[[cartPath cell] setPlaceholderString:@"Not Set"];87}8889[cartType selectItemWithTag:_cartType];90}91else {92[_prefs setInteger:CART_NONE forKey:@"Cartridge Type"];93}9495if([_prefs objectForKey:@"Region"]) {96_region = [_prefs integerForKey:@"Region"];97[region selectItemWithTag:_region];98}99else {100[_prefs setInteger:REGION_AUTODETECT forKey:@"Region"];101}102103if([_prefs objectForKey:@"Sound Core"]) {104_soundCore = [_prefs integerForKey:@"Sound Core"];105[soundCore selectItemWithTag:_soundCore];106}107else {108[_prefs setInteger:SNDCORE_MAC forKey:@"Sound Core"];109}110111if([_prefs objectForKey:@"Video Core"]) {112_videoCore = [_prefs integerForKey:@"Video Core"];113[videoCore selectItemWithTag:_videoCore];114}115else {116[_prefs setInteger:VIDCORE_OGL forKey:@"Video Core"];117}118119[_prefs synchronize];120}121122- (void)dealloc123{124[_prefs release];125[super dealloc];126}127128- (void)controlTextDidEndEditing:(NSNotification *)notification129{130id obj = [notification object];131132if(obj == biosPath) {133[_prefs setObject:[biosPath stringValue] forKey:@"BIOS Path"];134}135else if(obj == bramPath) {136[_prefs setObject:[bramPath stringValue] forKey:@"BRAM Path"];137}138else if(obj == mpegPath) {139[_prefs setObject:[mpegPath stringValue] forKey:@"MPEG ROM Path"];140}141else if(obj == cartPath) {142[_prefs setObject:[cartPath stringValue] forKey:@"Cartridge Path"];143}144145[_prefs synchronize];146}147148- (IBAction)cartSelected:(id)sender149{150_cartType = [[sender selectedItem] tag];151152switch(_cartType) {153case CART_NONE:154case CART_DRAM8MBIT:155case CART_DRAM32MBIT:156[cartPath setEnabled:NO];157[cartPath setStringValue:@""];158[cartBrowse setEnabled:NO];159[[cartPath cell] setPlaceholderString:160@"No file required for the selected cartridge"];161break;162163default:164[cartPath setEnabled:YES];165[cartBrowse setEnabled:YES];166[[cartPath cell] setPlaceholderString:@"Not Set"];167break;168}169170/* Update the preferences file. */171[_prefs setObject:[cartPath stringValue] forKey:@"Cartridge Path"];172[_prefs setInteger:_cartType forKey:@"Cartridge Type"];173[_prefs synchronize];174}175176- (IBAction)regionSelected:(id)sender177{178_region = [[sender selectedItem] tag];179180/* Update the preferences file. */181[_prefs setInteger:_region forKey:@"Region"];182[_prefs synchronize];183}184185- (IBAction)soundCoreSelected:(id)sender186{187_soundCore = [[sender selectedItem] tag];188189/* Update the preferences file. */190[_prefs setInteger:_soundCore forKey:@"Sound Core"];191[_prefs synchronize];192}193194- (IBAction)videoCoreSelected:(id)sender195{196_videoCore = [[sender selectedItem] tag];197198/* Update the preferences file. */199[_prefs setInteger:_videoCore forKey:@"Video Core"];200[_prefs synchronize];201}202203- (IBAction)biosBrowse:(id)sender204{205NSOpenPanel *p = [NSOpenPanel openPanel];206207[p setTitle:@"Select a Saturn BIOS ROM"];208209if([p runModal] == NSFileHandlingPanelOKButton) {210[biosPath setStringValue:[[[p URLs] objectAtIndex:0] path]];211212/* Update the preferences file. */213[_prefs setObject:[biosPath stringValue] forKey:@"BIOS Path"];214[_prefs synchronize];215}216}217218- (IBAction)mpegBrowse:(id)sender219{220NSOpenPanel *p = [NSOpenPanel openPanel];221222[p setTitle:@"Select a MPEG ROM"];223224if([p runModal] == NSFileHandlingPanelOKButton) {225[mpegPath setStringValue:[[[p URLs] objectAtIndex:0] path]];226227/* Update the preferences file. */228[_prefs setObject:[mpegPath stringValue] forKey:@"MPEG ROM Path"];229[_prefs synchronize];230}231}232233- (IBAction)bramBrowse:(id)sender234{235NSOpenPanel *p = [NSOpenPanel openPanel];236237[p setTitle:@"Select a BRAM File"];238239if([p runModal] == NSFileHandlingPanelOKButton) {240[bramPath setStringValue:[[[p URLs] objectAtIndex:0] path]];241242/* Update the preferences file. */243[_prefs setObject:[bramPath stringValue] forKey:@"BRAM Path"];244[_prefs synchronize];245}246}247248- (IBAction)cartBrowse:(id)sender249{250NSOpenPanel *p = [NSOpenPanel openPanel];251252[p setTitle:@"Select the Cartridge File"];253254if([p runModal] == NSFileHandlingPanelOKButton) {255[cartPath setStringValue:[[[p URLs] objectAtIndex:0] path]];256257/* Update the preferences file. */258[_prefs setObject:[cartPath stringValue] forKey:@"Cartridge Path"];259[_prefs synchronize];260}261}262263- (IBAction)biosToggle:(id)sender264{265/* Update the preferences file. */266[_prefs setBool:([sender state] == NSOnState) forKey:@"Emulate BIOS"];267[_prefs synchronize];268}269270- (IBAction)buttonSelect:(id)sender271{272NSInteger rv;273NSInteger tag = [sender tag];274int port = tag > 12 ? 1 : 0;275u8 num = tag > 12 ? tag - 13 : tag;276u32 value = PERCocoaGetKey(num, port);277unichar ch;278279/* Fill in current setting from prefs */280if(value != (u32)-1) {281switch(value) {282case '\r':283ch = 0x23CE;284break;285286case '\t':287ch = 0x21E5;288break;289290case 27:291ch = 0x241B;292break;293294case 127:295ch = 0x232B;296break;297298case NSLeftArrowFunctionKey:299ch = 0x2190;300break;301302case NSUpArrowFunctionKey:303ch = 0x2191;304break;305306case NSRightArrowFunctionKey:307ch = 0x2192;308break;309310case NSDownArrowFunctionKey:311ch = 0x2193;312break;313314default:315ch = toupper(((int)value));316}317318[buttonBox setStringValue:[NSString stringWithCharacters:&ch length:1]];319}320else {321[buttonBox setStringValue:@""];322}323324/* Open up the sheet and ask for the user's input */325[NSApp beginSheet:buttonAssignment326modalForWindow:prefsPane327modalDelegate:self328didEndSelector:nil329contextInfo:NULL];330331rv = [NSApp runModalForWindow:buttonAssignment];332[NSApp endSheet:buttonAssignment];333[buttonAssignment orderOut:nil];334335/* Did the user accept what they put in? */336if(rv == NSOKButton) {337NSString *s = [buttonBox stringValue];338u32 val;339340/* This shouldn't happen... */341if([s length] < 1) {342return;343}344345switch([s characterAtIndex:0]) {346case 0x23CE: /* Return */347val = '\r';348break;349350case 0x21E5: /* Tab */351val = '\t';352break;353354case 0x241B: /* Escape */355val = 27;356break;357358case 0x232B: /* Backspace */359val = 127;360break;361362case 0x2190: /* Left */363val = NSLeftArrowFunctionKey;364break;365366case 0x2191: /* Up */367val = NSUpArrowFunctionKey;368break;369370case 0x2192: /* Right */371val = NSRightArrowFunctionKey;372break;373374case 0x2193: /* Down */375val = NSDownArrowFunctionKey;376break;377378default:379val = tolower([s characterAtIndex:0]);380}381382/* Update the key mapping, if we're already running. This will also save383the key to the preferences. */384if(tag > 12) {385PERCocoaSetKey(val, tag - 13, 1);386}387else {388PERCocoaSetKey(val, tag, 0);389}390}391}392393- (IBAction)buttonSetOk:(id)sender394{395[NSApp stopModalWithCode:NSOKButton];396}397398- (IBAction)buttonSetCancel:(id)sender399{400[NSApp stopModalWithCode:NSCancelButton];401}402403- (int)cartType404{405return _cartType;406}407408- (int)region409{410return _region;411}412413- (int)soundCore414{415return _soundCore;416}417418- (int)videoCore419{420return _videoCore;421}422423- (NSString *)biosPath424{425return [biosPath stringValue];426}427428- (BOOL)emulateBios429{430return [emulateBios state] == NSOnState;431}432433- (NSString *)mpegPath434{435return [mpegPath stringValue];436}437438- (NSString *)bramPath439{440return [bramPath stringValue];441}442443- (NSString *)cartPath444{445return [cartPath stringValue];446}447448@end /* @implementation YabausePrefsController */449450451