diff --git a/Cocoa/Document.m b/Cocoa/Document.m
index f4abb5b..f79e141 100644
--- a/Cocoa/Document.m
+++ b/Cocoa/Document.m
@@ -141,12 +141,27 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
return self;
}
+- (NSString *)bootROMPathForName:(NSString *)name
+{
+ NSURL *url = [[NSUserDefaults standardUserDefaults] URLForKey:@"GBBootROMsFolder"];
+ if (url) {
+ NSString *path = [url path];
+ path = [path stringByAppendingPathComponent:name];
+ path = [path stringByAppendingPathExtension:@"bin"];
+ if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
+ return path;
+ }
+ }
+
+ return [[NSBundle mainBundle] pathForResource:name ofType:@"bin"];
+}
+
/* Todo: Unify the 3 init functions */
- (void) initDMG
{
current_model = MODEL_DMG;
GB_init(&gb, cocoa_to_internal_model[current_model]);
- GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:@"dmg_boot" ofType:@"bin"] UTF8String]);
+ GB_load_boot_rom(&gb, [[self bootROMPathForName:@"dmg_boot"] UTF8String]);
[self initCommon];
}
@@ -155,12 +170,12 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EmulateAGB"]) {
current_model = MODEL_AGB;
GB_init(&gb, cocoa_to_internal_model[current_model]);
- GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:@"agb_boot" ofType:@"bin"] UTF8String]);
+ GB_load_boot_rom(&gb, [[self bootROMPathForName:@"agb_boot"] UTF8String]);
}
else {
current_model = MODEL_CGB;
GB_init(&gb, cocoa_to_internal_model[current_model]);
- GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:@"cgb_boot" ofType:@"bin"] UTF8String]);
+ GB_load_boot_rom(&gb, [[self bootROMPathForName:@"cgb_boot"] UTF8String]);
}
[self initCommon];
}
@@ -254,14 +269,18 @@ static void printImage(GB_gameboy_t *gb, uint32_t *image, uint8_t height,
{
[self stop];
+ if ([sender tag] != MODEL_NONE) {
+ current_model = (enum model)[sender tag];
+ }
+
+ static NSString * const boot_names[] = {@"dmg_boot", @"cgb_boot", @"agb_boot"};
+ GB_load_boot_rom(&gb, [[self bootROMPathForName:boot_names[current_model - 1]] UTF8String]);
+
if ([sender tag] == MODEL_NONE) {
GB_reset(&gb);
}
else {
- current_model = (enum model)[sender tag];
GB_switch_model_and_reset(&gb, cocoa_to_internal_model[current_model]);
- static NSString * const boot_names[] = {@"dmg_boot", @"cgb_boot", @"agb_boot"};
- GB_load_boot_rom(&gb, [[[NSBundle mainBundle] pathForResource:boot_names[current_model - 1] ofType:@"bin"] UTF8String]);
}
if ([sender tag] != 0) {
diff --git a/Cocoa/GBPreferencesWindow.h b/Cocoa/GBPreferencesWindow.h
index 1334d48..14d3a33 100644
--- a/Cocoa/GBPreferencesWindow.h
+++ b/Cocoa/GBPreferencesWindow.h
@@ -10,4 +10,6 @@
@property (strong) IBOutlet NSPopUpButton *rewindPopupButton;
@property (strong) IBOutlet NSButton *configureJoypadButton;
@property (strong) IBOutlet NSButton *skipButton;
+@property (strong) IBOutlet NSMenuItem *bootROMsFolderItem;
+@property (strong) IBOutlet NSPopUpButtonCell *bootROMsButton;
@end
diff --git a/Cocoa/GBPreferencesWindow.m b/Cocoa/GBPreferencesWindow.m
index 051ac2f..73406d6 100644
--- a/Cocoa/GBPreferencesWindow.m
+++ b/Cocoa/GBPreferencesWindow.m
@@ -308,6 +308,7 @@
- (void)awakeFromNib
{
[super awakeFromNib];
+ [self updateBootROMFolderButton];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self.controlsTableView selector:@selector(reloadData) name:(NSString*)kTISNotifySelectedKeyboardInputSourceChanged object:nil];
}
@@ -316,4 +317,48 @@
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self.controlsTableView];
}
+- (IBAction)selectOtherBootROMFolder:(id)sender
+{
+ NSOpenPanel *panel = [[NSOpenPanel alloc] init];
+ [panel setCanChooseDirectories:YES];
+ [panel setCanChooseFiles:NO];
+ [panel setPrompt:@"Select"];
+ [panel setDirectoryURL:[[NSUserDefaults standardUserDefaults] URLForKey:@"GBBootROMsFolder"]];
+ [panel beginSheetModalForWindow:self completionHandler:^(NSModalResponse result) {
+ if (result == NSModalResponseOK) {
+ NSURL *url = [[panel URLs] firstObject];
+ [[NSUserDefaults standardUserDefaults] setURL:url forKey:@"GBBootROMsFolder"];
+ }
+ [self updateBootROMFolderButton];
+ }];
+
+}
+
+- (void) updateBootROMFolderButton
+{
+ NSURL *url = [[NSUserDefaults standardUserDefaults] URLForKey:@"GBBootROMsFolder"];
+ BOOL is_dir = false;
+ [[NSFileManager defaultManager] fileExistsAtPath:[url path] isDirectory:&is_dir];
+ if (!is_dir) url = nil;
+
+ if (url) {
+ [self.bootROMsFolderItem setTitle:[url lastPathComponent]];
+ NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[url path]];
+ [icon setSize:NSMakeSize(16, 16)];
+ [self.bootROMsFolderItem setHidden:NO];
+ [self.bootROMsFolderItem setImage:icon];
+ [self.bootROMsButton selectItemAtIndex:1];
+ }
+ else {
+ [self.bootROMsFolderItem setHidden:YES];
+ [self.bootROMsButton selectItemAtIndex:0];
+ }
+}
+
+- (IBAction)useBuiltinBootROMs:(id)sender
+{
+ [[NSUserDefaults standardUserDefaults] setURL:nil forKey:@"GBBootROMsFolder"];
+ [self updateBootROMFolderButton];
+}
+
@end
diff --git a/Cocoa/Preferences.xib b/Cocoa/Preferences.xib
index da85324..747a682 100644
--- a/Cocoa/Preferences.xib
+++ b/Cocoa/Preferences.xib
@@ -17,14 +17,14 @@
-
+
-
+
-
+
@@ -33,14 +33,14 @@
-
+
-
+
-
+
@@ -77,7 +77,7 @@
-
+
@@ -98,7 +98,7 @@
-
+
@@ -118,7 +118,7 @@
-
+
@@ -142,7 +142,7 @@
+
+
@@ -272,7 +307,7 @@
-
+