| 1 | #import "ConfigurationController.h" |
| 2 | #import "PcsxController.h" |
| 3 | #import "PluginList.h" |
| 4 | #import "PcsxPlugin.h" |
| 5 | #include "psxcommon.h" |
| 6 | #include "plugins.h" |
| 7 | |
| 8 | @implementation ConfigurationController |
| 9 | |
| 10 | - (IBAction)setCheckbox:(id)sender |
| 11 | { |
| 12 | if ([sender isKindOfClass:[NSMatrix class]]) { |
| 13 | sender = [sender selectedCell]; |
| 14 | } |
| 15 | |
| 16 | NSString *key = [self keyForSender:sender]; |
| 17 | if (key) { |
| 18 | [[NSUserDefaults standardUserDefaults] setInteger:[sender intValue] forKey:key]; |
| 19 | [PcsxController setConfigFromDefaults]; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | - (IBAction)setCheckboxInverse:(id)sender |
| 24 | { |
| 25 | if ([sender isKindOfClass:[NSMatrix class]]) { |
| 26 | sender = [sender selectedCell]; |
| 27 | } |
| 28 | |
| 29 | NSString *key = [self keyForSender:sender]; |
| 30 | if (key) { |
| 31 | [[NSUserDefaults standardUserDefaults] setInteger:![sender intValue] forKey:key]; |
| 32 | [PcsxController setConfigFromDefaults]; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | - (IBAction)mcdChangeClicked:(id)sender |
| 37 | { |
| 38 | int tag = [sender tag]; |
| 39 | char *mcd; |
| 40 | NSTextField *label; |
| 41 | NSOpenPanel *openDlg = [NSOpenPanel openPanel]; |
| 42 | NSString *path; |
| 43 | |
| 44 | if (tag == 1) { mcd = Config.Mcd1; label = mcd1Label; } |
| 45 | else { mcd = Config.Mcd2; label = mcd2Label; } |
| 46 | |
| 47 | [openDlg setCanChooseFiles:YES]; |
| 48 | [openDlg setCanChooseDirectories:NO]; |
| 49 | |
| 50 | path = [NSString stringWithCString:mcd]; |
| 51 | |
| 52 | if ([openDlg runModalForDirectory:[path stringByDeletingLastPathComponent] file:[path lastPathComponent]] == NSOKButton) { |
| 53 | NSArray* files = [openDlg filenames]; |
| 54 | strcpy(mcd, (const char *)[[files objectAtIndex:0] fileSystemRepresentation]); |
| 55 | |
| 56 | [label setTitleWithMnemonic:[NSString stringWithCString:mcd]]; |
| 57 | |
| 58 | if (tag == 1) |
| 59 | [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithCString:mcd] forKey:@"Mcd1"]; |
| 60 | else |
| 61 | [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithCString:mcd] forKey:@"Mcd2"]; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | - (IBAction)mcdNewClicked:(id)sender |
| 66 | { |
| 67 | int tag = [sender tag]; |
| 68 | char *mcd; |
| 69 | NSTextField *label; |
| 70 | NSSavePanel *openDlg = [NSSavePanel savePanel]; |
| 71 | NSString *path; |
| 72 | |
| 73 | if (tag == 1) { mcd = Config.Mcd1; label = mcd1Label; } |
| 74 | else { mcd = Config.Mcd2; label = mcd2Label; } |
| 75 | |
| 76 | path = [NSString stringWithCString:mcd]; |
| 77 | |
| 78 | if ([openDlg runModalForDirectory:[path stringByDeletingLastPathComponent] file:@"New Memory Card File.mcr"] == NSOKButton) { |
| 79 | strcpy(mcd, (const char *)[[openDlg filename] fileSystemRepresentation]); |
| 80 | |
| 81 | [label setTitleWithMnemonic:[NSString stringWithCString:mcd]]; |
| 82 | |
| 83 | if (tag == 1) |
| 84 | [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithCString:mcd] forKey:@"Mcd1"]; |
| 85 | else |
| 86 | [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithCString:mcd] forKey:@"Mcd2"]; |
| 87 | |
| 88 | CreateMcd(mcd); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | - (IBAction)setVideoType:(id)sender |
| 93 | { |
| 94 | int tag = [[sender selectedItem] tag]; |
| 95 | |
| 96 | if (3 == tag) { |
| 97 | [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"AutoDetectVideoType"]; |
| 98 | } else if (1 == tag || 2 == tag) { |
| 99 | [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"AutoDetectVideoType"]; |
| 100 | [[NSUserDefaults standardUserDefaults] setBool:tag==2 forKey:@"VideoTypePAL"]; |
| 101 | } else { |
| 102 | return; |
| 103 | } |
| 104 | [PcsxController setConfigFromDefaults]; |
| 105 | |
| 106 | if ([sender pullsDown]) { |
| 107 | NSArray *items = [sender itemArray]; |
| 108 | int i; |
| 109 | |
| 110 | for (i=0; i<[items count]; i++) |
| 111 | [[items objectAtIndex:i] setState:NSOffState]; |
| 112 | |
| 113 | [[sender selectedItem] setState:NSOnState]; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | - (void)awakeFromNib |
| 118 | { |
| 119 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
| 120 | |
| 121 | [[self window] center]; |
| 122 | |
| 123 | // setup checkboxes |
| 124 | checkBoxDefaults = [[NSMutableDictionary alloc] init]; |
| 125 | |
| 126 | // check that the outlets are active before adding them |
| 127 | if (noXaAudioCell) [checkBoxDefaults setObject:noXaAudioCell forKey:@"NoXaAudio"]; |
| 128 | if (sioIrqAlwaysCell) [checkBoxDefaults setObject:sioIrqAlwaysCell forKey:@"SioIrqAlways"]; |
| 129 | if (bwMdecCell) [checkBoxDefaults setObject:bwMdecCell forKey:@"BlackAndWhiteMDECVideo"]; |
| 130 | if (autoVTypeCell) [checkBoxDefaults setObject:autoVTypeCell forKey:@"AutoDetectVideoType"]; |
| 131 | if (vTypePALCell) [checkBoxDefaults setObject:vTypePALCell forKey:@"VideoTypePAL"]; |
| 132 | if (noCDAudioCell) [checkBoxDefaults setObject:noCDAudioCell forKey:@"NoCDAudio"]; |
| 133 | if (usesHleCell) [checkBoxDefaults setObject:usesHleCell forKey:@"UseHLE"]; |
| 134 | if (usesDynarecCell) [checkBoxDefaults setObject:usesDynarecCell forKey:@"NoDynarec"]; |
| 135 | if (consoleOutputCell) [checkBoxDefaults setObject:consoleOutputCell forKey:@"ConsoleOutput"]; |
| 136 | if (spuIrqAlwaysCell) [checkBoxDefaults setObject:spuIrqAlwaysCell forKey:@"SpuIrqAlways"]; |
| 137 | if (rCountFixCell) [checkBoxDefaults setObject:rCountFixCell forKey:@"RootCounterFix"]; |
| 138 | if (vSyncWAFixCell) [checkBoxDefaults setObject:vSyncWAFixCell forKey:@"VideoSyncWAFix"]; |
| 139 | if (noFastBootCell) [checkBoxDefaults setObject:noFastBootCell forKey:@"NoFastBoot"]; |
| 140 | |
| 141 | // make the visuals match the defaults |
| 142 | NSEnumerator *enumerator= [checkBoxDefaults keyEnumerator]; |
| 143 | id key; |
| 144 | while ((key = [enumerator nextObject])) { |
| 145 | if ([defaults integerForKey:key]) { |
| 146 | [[checkBoxDefaults objectForKey:key] setNextState]; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // special cases |
| 151 | if (![PcsxController biosAvailable]) { |
| 152 | // no bios means always use HLE |
| 153 | [usesHleCell setState:NSOnState]; |
| 154 | [usesHleCell setEnabled:NO]; |
| 155 | } |
| 156 | |
| 157 | // setup labels |
| 158 | [mcd1Label setTitleWithMnemonic:[NSString stringWithCString:Config.Mcd1]]; |
| 159 | [mcd2Label setTitleWithMnemonic:[NSString stringWithCString:Config.Mcd2]]; |
| 160 | |
| 161 | int tag = [defaults integerForKey:@"AutoDetectVideoType"]; |
| 162 | if (tag) |
| 163 | tag = 3; |
| 164 | else { |
| 165 | tag = [defaults integerForKey:@"VideoTypePAL"]+1; |
| 166 | } |
| 167 | [vTypePALCell setAutoenablesItems:NO]; |
| 168 | if ([vTypePALCell pullsDown]) { |
| 169 | [[vTypePALCell itemAtIndex:[vTypePALCell indexOfItemWithTag:tag]] setState:NSOnState]; |
| 170 | } else { |
| 171 | [vTypePALCell selectItemAtIndex:[vTypePALCell indexOfItemWithTag:tag]]; |
| 172 | } |
| 173 | |
| 174 | // setup plugin lists |
| 175 | PluginList *list = [PluginList list]; |
| 176 | |
| 177 | [list refreshPlugins]; |
| 178 | [graphicsPlugin setPluginsTo:[list pluginsForType:PSE_LT_GPU] withType: PSE_LT_GPU]; |
| 179 | [soundPlugin setPluginsTo:[list pluginsForType:PSE_LT_SPU] withType: PSE_LT_SPU]; |
| 180 | [padPlugin setPluginsTo:[list pluginsForType:PSE_LT_PAD] withType: PSE_LT_PAD]; |
| 181 | [cdromPlugin setPluginsTo:[list pluginsForType:PSE_LT_CDR] withType: PSE_LT_CDR]; |
| 182 | } |
| 183 | |
| 184 | - (void)dealloc |
| 185 | { |
| 186 | [checkBoxDefaults release]; |
| 187 | [super dealloc]; |
| 188 | } |
| 189 | |
| 190 | - (NSString *)keyForSender:(id)sender |
| 191 | { |
| 192 | NSEnumerator *enumerator= [checkBoxDefaults keyEnumerator]; |
| 193 | id key; |
| 194 | while ((key = [enumerator nextObject])) { |
| 195 | id object = [checkBoxDefaults objectForKey:key]; |
| 196 | if ([object isEqual:sender]) |
| 197 | return key; |
| 198 | } |
| 199 | |
| 200 | return nil; |
| 201 | } |
| 202 | |
| 203 | @end |